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