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