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