xref: /titanic_51/usr/src/cmd/cmd-inet/usr.bin/ftp/ftp_var.h (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  *	Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	All Rights Reserved  	*/
29 
30 /*
31  *	University Copyright- Copyright (c) 1982, 1986, 1988
32  *	The Regents of the University of California
33  *	All Rights Reserved
34  *
35  *	University Acknowledgment- Portions of this document are derived from
36  *	software developed by the University of California, Berkeley, and its
37  *	contributors.
38  */
39 
40 #ifndef	_FTP_VAR_H
41 #define	_FTP_VAR_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 #include <sys/param.h>
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <sys/ioctl.h>
53 #include <sys/stat.h>
54 #include <sys/wait.h>
55 #include <sys/resource.h>
56 #include <sys/ttold.h>
57 #include <sys/stropts.h>
58 #include <sys/time.h>
59 #include <netinet/in.h>
60 #include <netinet/tcp.h>
61 #include <arpa/ftp.h>
62 #include <arpa/telnet.h>
63 #include <arpa/inet.h>
64 #include <setjmp.h>
65 #include <libintl.h>
66 #include <string.h>
67 #include <fcntl.h>
68 #include <stdlib.h>
69 #include <stdio.h>
70 #include <widec.h>
71 #include <signal.h>
72 #include <netdb.h>
73 #include <pwd.h>
74 #include <locale.h>
75 #include <limits.h>
76 #include <fnmatch.h>
77 #include <dirent.h>
78 #include <termios.h>
79 #include <stdarg.h>
80 #include <unistd.h>
81 #include <malloc.h>
82 #include <strings.h>
83 #include <errno.h>
84 #include <ctype.h>
85 #include <gssapi/gssapi.h>
86 #include <gssapi/gssapi_ext.h>
87 
88 #define	signal(s, f)	sigset(s, f)
89 #define	setjmp(e)	sigsetjmp(e, 1)
90 #define	longjmp(e, v)	siglongjmp(e, v)
91 #define	jmp_buf		sigjmp_buf
92 
93 /*
94  * FTP global variables.
95  */
96 #ifndef	EXTERN
97 #define	EXTERN	extern
98 #endif
99 
100 #define	DEFAULTFTPFILE	"/etc/default/ftp"
101 
102 /*
103  * Options and other state info.
104  */
105 EXTERN int	trace;		/* trace packets exchanged */
106 EXTERN int	hash;		/* print # for each buffer transferred */
107 EXTERN int	sendport;	/* use PORT cmd for each data connection */
108 EXTERN int	verbose;	/* print messages coming back from server */
109 EXTERN int	connected;	/* connected to server */
110 EXTERN int	fromatty;	/* input is from a terminal */
111 EXTERN int	interactive;	/* interactively prompt on m* cmds */
112 EXTERN int	debug;		/* debugging level */
113 EXTERN int	bell;		/* ring bell on cmd completion */
114 EXTERN int	doglob;		/* glob local file names */
115 EXTERN int	autologin;	/* establish user account on connection */
116 EXTERN int	proxy;		/* proxy server connection active */
117 EXTERN int	proxflag;	/* proxy connection exists */
118 EXTERN int	sunique;	/* store files on server with unique name */
119 EXTERN int	runique;	/* store local files with unique name */
120 EXTERN int	mcase;		/* map upper to lower case for mget names */
121 EXTERN int	ntflag;		/* use ntin ntout tables for name translation */
122 EXTERN int	mapflag;	/* use mapin mapout templates on file names */
123 EXTERN int	code;		/* return/reply code for ftp command */
124 EXTERN int	crflag;		/* if 1, strip car. rets. on ascii gets */
125 EXTERN char	pasv[64];	/* passive port for proxy data connection */
126 EXTERN char	*altarg;	/* argv[1] with no shell-like preprocessing  */
127 EXTERN char	ntin[17];	/* input translation table */
128 EXTERN char	ntout[17];	/* output translation table */
129 EXTERN char	mapin[MAXPATHLEN]; /* input map template */
130 EXTERN char	mapout[MAXPATHLEN]; /* output map template */
131 EXTERN char	typename[32];	/* name of file transfer type */
132 EXTERN int	type;		/* file transfer type */
133 EXTERN char	structname[32];	/* name of file transfer structure */
134 EXTERN int	stru;		/* file transfer structure */
135 EXTERN char	formname[32];	/* name of file transfer format */
136 EXTERN int	form;		/* file transfer format */
137 EXTERN char	modename[32];	/* name of file transfer mode */
138 EXTERN int	mode;		/* file transfer mode */
139 EXTERN char	bytename[32];	/* local byte size in ascii */
140 EXTERN int	bytesize;	/* local byte size in binary */
141 EXTERN int	passivemode;	/* passive transfer mode toggle */
142 EXTERN off_t	restart_point;	/* transfer restart offset */
143 EXTERN int	tcpwindowsize;	/* TCP window size for the data connection */
144 
145 EXTERN boolean_t	ls_invokes_NLST;	/* behaviour of 'ls' */
146 EXTERN char		*hostname;		/* name of host connected to */
147 EXTERN char		*home;
148 EXTERN char		*globerr;
149 
150 EXTERN struct	sockaddr_in6 myctladdr;		/* for channel bindings */
151 EXTERN struct	sockaddr_in6 remctladdr;	/* for channel bindings */
152 
153 EXTERN int	clevel;		/* command channel protection level */
154 EXTERN int	dlevel;		/* data channel protection level */
155 
156 EXTERN int	autoauth;	/* do authentication on connect */
157 EXTERN int	auth_type;	/* authentication type */
158 EXTERN int	auth_error;	/* one error code for all auth types */
159 EXTERN int	autoencrypt;	/* do encryption on connect */
160 EXTERN int	fflag;		/* forward credentials */
161 EXTERN boolean_t goteof;
162 
163 EXTERN uchar_t	*ucbuf;		/* clear text buffer */
164 
165 #define	MECH_SZ		40
166 #define	FTP_DEF_MECH	"kerberos_v5"
167 EXTERN char	mechstr[MECH_SZ];	/* mechanism type */
168 
169 EXTERN gss_OID	mechoid;	/* corresponding mechanism oid type */
170 EXTERN gss_ctx_id_t gcontext;	/* gss security context */
171 
172 #define	FTPBUFSIZ	BUFSIZ*16
173 #define	HASHSIZ		BUFSIZ*8
174 
175 EXTERN char *buf;		/* buffer for binary sends and gets */
176 
177 EXTERN jmp_buf toplevel;	/* non-local goto stuff for cmd scanner */
178 
179 /*
180  * BUFSIZE includes
181  *	- (MAXPATHLEN)*2 to  accomodate 2 paths (remote and local file names).
182  *	- MAXCMDLEN to accomodate the longest command listed in cmdtab[]
183  *	  (defined in cmdtab.c) as this is stuffed into the buffer along
184  *	  with the remote and local file names.
185  *	- The 4 bytes are for the 2 blank separators, a carriage-return
186  *	  and a NULL terminator.
187  *
188  * NOTE : The arguments may not be always pathnames (they can be commands
189  *	  too). But, here we have considered the worst case of two pathnames.
190  */
191 #define	MAXCMDLEN	10	/* The length of longest command in cmdtab[] */
192 #define	BUFSIZE	((MAXPATHLEN)*2+MAXCMDLEN+4)
193 
194 EXTERN char	line[BUFSIZE];	/* input line buffer */
195 EXTERN char	*stringbase;	/* current scan point in line buffer */
196 EXTERN char	argbuf[BUFSIZE]; /* argument storage buffer */
197 EXTERN char	*argbase;	/* current storage point in arg buffer */
198 EXTERN int	margc;		/* count of arguments on input line */
199 EXTERN char	**margv;	/* args parsed from input line */
200 EXTERN int	cpend;		/* flag: if != 0, then pending server reply */
201 EXTERN int	mflag;		/* flag: if != 0, then active multi command */
202 EXTERN FILE	*tmp_nlst;	/* tmp file; holds NLST results for mget, etc */
203 
204 EXTERN char	*reply_parse;	/* for parsing replies to the ADAT command */
205 EXTERN char	reply_buf[FTPBUFSIZ];
206 EXTERN char	*reply_ptr;
207 
208 EXTERN int	options;	/* used during socket creation */
209 
210 EXTERN int	timeout;	/* connection timeout */
211 EXTERN int	timeoutms;	/* connection timeout in msec */
212 EXTERN jmp_buf	timeralarm;	/* to recover from global timeout */
213 
214 
215 /*
216  * Format of command table.
217  */
218 struct cmd {
219 	char	*c_name;	/* name of command */
220 	char	*c_help;	/* help string */
221 	char	c_bell;		/* give bell when command completes */
222 	char	c_conn;		/* must be connected to use command */
223 	char	c_proxy;	/* proxy server may execute */
224 	void	(*c_handler)(int argc, char *argv[]); /* function to call */
225 };
226 
227 struct macel {
228 	char mac_name[9];	/* macro name */
229 	char *mac_start;	/* start of macro in macbuf */
230 	char *mac_end;		/* end of macro in macbuf */
231 };
232 
233 EXTERN int macnum;			/* number of defined macros */
234 EXTERN struct macel macros[16];
235 EXTERN char macbuf[4096];
236 
237 extern void macdef(int argc, char *argv[]);
238 extern void doproxy(int argc, char *argv[]);
239 extern void setpeer(int argc, char *argv[]);
240 extern void rmthelp(int argc, char *argv[]);
241 extern void settype(int argc, char *argv[]);
242 extern void setbinary(int argc, char *argv[]);
243 extern void setascii(int argc, char *argv[]);
244 extern void settenex(int argc, char *argv[]);
245 extern void setebcdic(int argc, char *argv[]);
246 extern void setmode(int argc, char *argv[]);
247 extern void setform(int argc, char *argv[]);
248 extern void setstruct(int argc, char *argv[]);
249 extern void put(int argc, char *argv[]);
250 extern void mput(int argc, char *argv[]);
251 extern void get(int argc, char *argv[]);
252 extern void mget(int argc, char *argv[]);
253 extern void status(int argc, char *argv[]);
254 extern void setbell(int argc, char *argv[]);
255 extern void settrace(int argc, char *argv[]);
256 extern void sethash(int argc, char *argv[]);
257 extern void setverbose(int argc, char *argv[]);
258 extern void setport(int argc, char *argv[]);
259 extern void setprompt(int argc, char *argv[]);
260 extern void setglob(int argc, char *argv[]);
261 extern void setdebug(int argc, char *argv[]);
262 extern void cd(int argc, char *argv[]);
263 extern void lcd(int argc, char *argv[]);
264 extern void delete(int argc, char *argv[]);
265 extern void mdelete(int argc, char *argv[]);
266 extern void renamefile(int argc, char *argv[]);
267 extern void ls(int argc, char *argv[]);
268 extern void mls(int argc, char *argv[]);
269 extern void shell(int argc, char *argv[]);
270 extern void user(int argc, char *argv[]);
271 extern void pwd(int argc, char *argv[]);
272 extern void makedir(int argc, char *argv[]);
273 extern void removedir(int argc, char *argv[]);
274 extern void quote(int argc, char *argv[]);
275 extern void rmthelp(int argc, char *argv[]);
276 extern void quit(int argc, char *argv[]);
277 extern void disconnect(int argc, char *argv[]);
278 extern void account(int argc, char *argv[]);
279 extern void setcase(int argc, char *argv[]);
280 extern void setcr(int argc, char *argv[]);
281 extern void setntrans(int argc, char *argv[]);
282 extern void setnmap(int argc, char *argv[]);
283 extern void setsunique(int argc, char *argv[]);
284 extern void setrunique(int argc, char *argv[]);
285 extern void cdup(int argc, char *argv[]);
286 extern void domacro(int argc, char *argv[]);
287 extern void help(int argc, char *argv[]);
288 extern void reset(int argc, char *argv[]);
289 extern void reget(int argc, char *argv[]);
290 extern void restart(int argc, char *argv[]);
291 extern void setpassive(int argc, char *argv[]);
292 extern void settcpwindow(int argc, char *argv[]);
293 extern void site(int argc, char *argv[]);
294 
295 extern void ccc(int argc, char *argv[]);
296 extern void setclear(int argc, char *argv[]);
297 extern void setclevel(int argc, char *argv[]);
298 extern void setdlevel(int argc, char *argv[]);
299 extern void setsafe(int argc, char *argv[]);
300 extern void setmech(int argc, char *argv[]);
301 
302 extern int do_auth(void);
303 extern void setpbsz(uint_t size);
304 extern char *radix_error(int);
305 extern int radix_encode(uchar_t *, uchar_t *, size_t, int *, int);
306 extern void user_gss_error(OM_uint32 maj_stat, OM_uint32 min_stat,
307 	char *errstr);
308 extern void setprivate(int argc, char *argv[]);
309 
310 extern int secure_flush(int);
311 extern int secure_getc(FILE *);
312 extern int secure_putc(int, FILE *);
313 extern ssize_t secure_read(int, void *, size_t);
314 extern ssize_t secure_write(int, const void *, size_t);
315 
316 extern void fatal(char *msg);
317 extern int getreply(int expecteof);
318 extern void call(void (*routine)(int argc, char *argv[]), ...);
319 extern void sendrequest(char *cmd, char *local, char *remote, int allowpipe);
320 extern void recvrequest(char *cmd, char *local, char *remote, char *mode,
321     int allowpipe);
322 extern void makeargv(void);
323 extern int login(char *host);
324 extern int command(char *fmt, ...);
325 extern char **glob(char *v);
326 extern void blkfree(char **);
327 extern void pswitch(int flag);
328 
329 extern char *hookup(char *host, char *);
330 extern char *mygetpass(char *prompt);
331 extern void lostpeer(int sig);
332 extern int ruserpass(char *host, char **aname, char **apass, char **aacct);
333 extern FILE *mypopen(char *cmd, char *mode);
334 extern int mypclose(FILE *ptr);
335 extern struct cmd *getcmd(char *name);
336 
337 extern void stop_timer(void);
338 extern void reset_timer(void);
339 extern int getpagesize(void);
340 
341 #define	ENCODELEN(l)	(((4 * (l)) / 3) + 4)
342 #define	DECODELEN(l)	(((3 * (l)) / 4) + 4)
343 
344 #ifdef	__cplusplus
345 }
346 #endif
347 
348 #endif	/* _FTP_VAR_H */
349