1 /**	$MirOS: src/usr.bin/ftp/ftp_var.h,v 1.5 2007/07/15 20:01:08 tg Exp $ */
2 /*	$OpenBSD: ftp_var.h,v 1.24 2007/06/13 13:52:26 pyr Exp $	*/
3 /*	$NetBSD: ftp_var.h,v 1.18 1997/08/18 10:20:25 lukem Exp $	*/
4 
5 /*
6  * Copyright (C) 1997 and 1998 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1985, 1989, 1993, 1994
36  *	The Regents of the University of California.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  *	@(#)ftp_var.h	8.4 (Berkeley) 10/9/94
63  */
64 
65 /*
66  * FTP global variables.
67  */
68 
69 #include <sys/param.h>
70 #include <setjmp.h>
71 
72 #ifndef SMALL
73 #include <histedit.h>
74 #endif /* !SMALL */
75 
76 #ifdef SOCKS
77 #include <socks.h>
78 int fclose(FILE *);
79 #endif
80 
81 #include "stringlist.h"
82 #include "extern.h"
83 
84 #define HASHBYTES	1024
85 #define FTPBUFLEN	MAXPATHLEN + 200
86 
87 #define STALLTIME	5	/* # of seconds of no xfer before "stalling" */
88 
89 #define	FTP_PORT	21	/* default if ! getservbyname("ftp/tcp") */
90 #define	HTTP_PORT	80	/* default if ! getservbyname("http/tcp") */
91 #define	HTTPS_PORT	443	/* default if ! getservbyname("https/tcp") */
92 			/* User-Agent string sent to web server */
93 #define	HTTP_USER_AGENT	"User-Agent: MirOS ftp(1), http://mirbsd.de/"
94 #ifndef	GATE_PORT
95 #define	GATE_PORT	21	/* default if ! getservbyname("ftpgate/tcp") */
96 #endif
97 #ifndef	GATE_SERVER
98 #define	GATE_SERVER	""	/* default server */
99 #endif
100 
101 #define PAGER		"more"	/* default pager if $PAGER isn't set */
102 
103 /*
104  * Options and other state info.
105  */
106 int	trace;			/* trace packets exchanged */
107 int	hash;			/* print # for each buffer transferred */
108 int	mark;			/* number of bytes between hashes */
109 int	sendport;		/* use PORT/LPRT cmd for each data connection */
110 int	verbose;		/* print messages coming back from server */
111 int	connected;		/* 1 = connected to server, -1 = logged in */
112 int	fromatty;		/* input is from a terminal */
113 int	interactive;		/* interactively prompt on m* cmds */
114 int	confirmrest;		/* confirm rest of current m* cmd */
115 int	debug;			/* debugging level */
116 int	bell;			/* ring bell on cmd completion */
117 int	doglob;			/* glob local file names */
118 int	autologin;		/* establish user account on connection */
119 int	proxy;			/* proxy server connection active */
120 int	proxflag;		/* proxy connection exists */
121 int	gatemode;		/* use gate-ftp */
122 char   *gateserver;		/* server to use for gate-ftp */
123 int	sunique;		/* store files on server with unique name */
124 int	runique;		/* store local files with unique name */
125 int	mcase;			/* map upper to lower case for mget names */
126 int	ntflag;			/* use ntin ntout tables for name translation */
127 int	mapflag;		/* use mapin mapout templates on file names */
128 int	preserve;		/* preserve modification time on files */
129 int	progress;		/* display transfer progress bar */
130 int	code;			/* return/reply code for ftp command */
131 int	crflag;			/* if 1, strip car. rets. on ascii gets */
132 char	pasv[BUFSIZ];		/* passive port for proxy data connection */
133 int	passivemode;		/* passive mode enabled */
134 int	activefallback;		/* fall back to active mode if passive fails */
135 char   *altarg;			/* argv[1] with no shell-like preprocessing  */
136 char	ntin[17];		/* input translation table */
137 char	ntout[17];		/* output translation table */
138 char	mapin[MAXPATHLEN];	/* input map template */
139 char	mapout[MAXPATHLEN];	/* output map template */
140 char	typename[32];		/* name of file transfer type */
141 int	type;			/* requested file transfer type */
142 int	curtype;		/* current file transfer type */
143 char	structname[32];		/* name of file transfer structure */
144 int	stru;			/* file transfer structure */
145 char	formname[32];		/* name of file transfer format */
146 int	form;			/* file transfer format */
147 char	modename[32];		/* name of file transfer mode */
148 int	mode;			/* file transfer mode */
149 char	bytename[32];		/* local byte size in ascii */
150 int	bytesize;		/* local byte size in binary */
151 int	anonftp;		/* automatic anonymous login */
152 int	dirchange;		/* remote directory changed by cd command */
153 unsigned int retry_connect;	/* retry connect if failed */
154 int	ttywidth;		/* width of tty */
155 int	epsv4;			/* use EPSV/EPRT on IPv4 connections */
156 int	epsv4bad;		/* EPSV doesn't work on the current server */
157 
158 #ifndef SMALL
159 int	  editing;		/* command line editing enabled */
160 EditLine *el;			/* editline(3) status structure */
161 History  *hist;			/* editline(3) history structure */
162 char	 *cursor_pos;		/* cursor position we're looking for */
163 size_t	  cursor_argc;		/* location of cursor in margv */
164 size_t	  cursor_argo;		/* offset of cursor in margv[cursor_argc] */
165 char	 *cookiefile;		/* cookie jar to use */
166 #endif /* !SMALL */
167 
168 off_t	bytes;			/* current # of bytes read */
169 off_t	filesize;		/* size of file being transferred */
170 char   *direction;		/* direction transfer is occurring */
171 
172 char   *hostname;		/* name of host connected to */
173 int	unix_server;		/* server is unix, can use binary for ascii */
174 int	unix_proxy;		/* proxy is unix, can use binary for ascii */
175 
176 char *ftpport;			/* port number to use for ftp connections */
177 char *httpport;			/* port number to use for http connections */
178 #ifndef SMALL
179 char *httpsport;		/* port number to use for https connections */
180 #endif
181 char *gateport;			/* port number to use for gateftp connections */
182 
183 jmp_buf	toplevel;		/* non-local goto stuff for cmd scanner */
184 
185 char	line[FTPBUFLEN];	/* input line buffer */
186 char	*stringbase;		/* current scan point in line buffer */
187 char	argbuf[FTPBUFLEN];	/* argument storage buffer */
188 char	*argbase;		/* current storage point in arg buffer */
189 StringList *marg_sl;		/* stringlist containing margv */
190 int	margc;			/* count of arguments on input line */
191 #define margv (marg_sl->sl_str)	/* args parsed from input line */
192 int     cpend;                  /* flag: if != 0, then pending server reply */
193 int	mflag;			/* flag: if != 0, then active multi command */
194 
195 int	options;		/* used during socket creation */
196 
197 /*
198  * Format of command table.
199  */
200 struct cmd {
201 	char	*c_name;	/* name of command */
202 	char	*c_help;	/* help string */
203 	char	 c_bell;	/* give bell when command completes */
204 	char	 c_conn;	/* must be connected to use command */
205 	char	 c_proxy;	/* proxy server may execute */
206 #ifndef SMALL
207 	char	*c_complete;	/* context sensitive completion list */
208 #endif /* !SMALL */
209 	void	(*c_handler)(int, char **); /* function to call */
210 };
211 
212 struct macel {
213 	char mac_name[9];	/* macro name */
214 	char *mac_start;	/* start of macro in macbuf */
215 	char *mac_end;		/* end of macro in macbuf */
216 };
217 
218 int macnum;			/* number of defined macros */
219 struct macel macros[16];
220 char macbuf[4096];
221 
222 FILE	*ttyout;		/* stdout or stderr, depending on interactive */
223