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