HardenedBSD src tree https://hardenedbsd.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

358 lines
14 KiB

  1. /* $NetBSD: ftp_var.h,v 1.10 2009/05/20 12:53:47 lukem Exp $ */
  2. /* from NetBSD: ftp_var.h,v 1.81 2009/04/12 10:18:52 lukem Exp */
  3. /*-
  4. * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Luke Mewburn.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  23. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /*
  32. * Copyright (c) 1985, 1989, 1993, 1994
  33. * The Regents of the University of California. All rights reserved.
  34. *
  35. * Redistribution and use in source and binary forms, with or without
  36. * modification, are permitted provided that the following conditions
  37. * are met:
  38. * 1. Redistributions of source code must retain the above copyright
  39. * notice, this list of conditions and the following disclaimer.
  40. * 2. Redistributions in binary form must reproduce the above copyright
  41. * notice, this list of conditions and the following disclaimer in the
  42. * documentation and/or other materials provided with the distribution.
  43. * 3. Neither the name of the University nor the names of its contributors
  44. * may be used to endorse or promote products derived from this software
  45. * without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  48. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  51. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  52. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  53. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  54. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  56. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  57. * SUCH DAMAGE.
  58. *
  59. * @(#)ftp_var.h 8.4 (Berkeley) 10/9/94
  60. */
  61. /*
  62. * Copyright (C) 1997 and 1998 WIDE Project.
  63. * All rights reserved.
  64. *
  65. * Redistribution and use in source and binary forms, with or without
  66. * modification, are permitted provided that the following conditions
  67. * are met:
  68. * 1. Redistributions of source code must retain the above copyright
  69. * notice, this list of conditions and the following disclaimer.
  70. * 2. Redistributions in binary form must reproduce the above copyright
  71. * notice, this list of conditions and the following disclaimer in the
  72. * documentation and/or other materials provided with the distribution.
  73. * 3. Neither the name of the project nor the names of its contributors
  74. * may be used to endorse or promote products derived from this software
  75. * without specific prior written permission.
  76. *
  77. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  78. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  80. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  81. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  82. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  83. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  84. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  86. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  87. * SUCH DAMAGE.
  88. */
  89. /*
  90. * FTP global variables.
  91. */
  92. #ifdef SMALL
  93. #undef NO_EDITCOMPLETE
  94. #define NO_EDITCOMPLETE
  95. #undef NO_PROGRESS
  96. #define NO_PROGRESS
  97. #endif
  98. #if 0 /* tnftp */
  99. #include <sys/param.h>
  100. #include <netinet/in.h>
  101. #include <arpa/inet.h>
  102. #include <poll.h>
  103. #include <setjmp.h>
  104. #include <stringlist.h>
  105. #endif /* tnftp */
  106. #ifndef NO_EDITCOMPLETE
  107. #include <histedit.h>
  108. #endif /* !NO_EDITCOMPLETE */
  109. #include "extern.h"
  110. #include "progressbar.h"
  111. /*
  112. * Format of command table.
  113. */
  114. struct cmd {
  115. const char *c_name; /* name of command */
  116. const char *c_help; /* help string */
  117. char c_bell; /* give bell when command completes */
  118. char c_conn; /* must be connected to use command */
  119. char c_proxy; /* proxy server may execute */
  120. #ifndef NO_EDITCOMPLETE
  121. const char *c_complete; /* context sensitive completion list */
  122. #endif /* !NO_EDITCOMPLETE */
  123. void (*c_handler)(int, char **); /* function to call */
  124. };
  125. #define MAX_C_NAME 12 /* maximum length of cmd.c_name */
  126. /*
  127. * Format of macro table
  128. */
  129. struct macel {
  130. char mac_name[9]; /* macro name */
  131. char *mac_start; /* start of macro in macbuf */
  132. char *mac_end; /* end of macro in macbuf */
  133. };
  134. /*
  135. * Format of option table
  136. */
  137. struct option {
  138. const char *name;
  139. char *value;
  140. };
  141. /*
  142. * Indices to features[]; an array containing status of remote server
  143. * features; -1 not known (FEAT failed), 0 absent, 1 present.
  144. */
  145. enum {
  146. FEAT_FEAT = 0, /* FEAT, OPTS */
  147. FEAT_MDTM, /* MDTM */
  148. FEAT_MLST, /* MLSD, MLST */
  149. FEAT_REST_STREAM, /* RESTart STREAM */
  150. FEAT_SIZE, /* SIZE */
  151. FEAT_TVFS, /* TVFS (not used) */
  152. FEAT_max
  153. };
  154. /*
  155. * Global defines
  156. */
  157. #define FTPBUFLEN MAXPATHLEN + 200
  158. #define MAX_IN_PORT_T 0xffffU
  159. #define HASHBYTES 1024 /* default mark for `hash' command */
  160. #define DEFAULTINCR 1024 /* default increment for `rate' command */
  161. #define FTP_PORT 21 /* default if ! getservbyname("ftp/tcp") */
  162. #define HTTP_PORT 80 /* default if ! getservbyname("http/tcp") */
  163. #ifndef GATE_PORT
  164. #define GATE_PORT 21 /* default if ! getservbyname("ftpgate/tcp") */
  165. #endif
  166. #ifndef GATE_SERVER
  167. #define GATE_SERVER "" /* default server */
  168. #endif
  169. #define DEFAULTPAGER "less" /* default pager if $PAGER isn't set */
  170. #define DEFAULTPROMPT "ftp> " /* default prompt if `set prompt' is empty */
  171. #define DEFAULTRPROMPT "" /* default rprompt if `set rprompt' is empty */
  172. #define TMPFILE "ftpXXXXXXXXXX"
  173. #ifndef GLOBAL
  174. #define GLOBAL extern
  175. #endif
  176. /*
  177. * Options and other state info.
  178. */
  179. GLOBAL int trace; /* trace packets exchanged */
  180. GLOBAL int hash; /* print # for each buffer transferred */
  181. GLOBAL int mark; /* number of bytes between hashes */
  182. GLOBAL int sendport; /* use PORT/LPRT cmd for each data connection */
  183. GLOBAL int connected; /* 1 = connected to server, -1 = logged in */
  184. GLOBAL int interactive; /* interactively prompt on m* cmds */
  185. GLOBAL int confirmrest; /* confirm rest of current m* cmd */
  186. GLOBAL int ftp_debug; /* debugging level */
  187. GLOBAL int bell; /* ring bell on cmd completion */
  188. GLOBAL int doglob; /* glob local file names */
  189. GLOBAL int autologin; /* establish user account on connection */
  190. GLOBAL int proxy; /* proxy server connection active */
  191. GLOBAL int proxflag; /* proxy connection exists */
  192. GLOBAL int gatemode; /* use gate-ftp */
  193. GLOBAL const char *gateserver; /* server to use for gate-ftp */
  194. GLOBAL int sunique; /* store files on server with unique name */
  195. GLOBAL int runique; /* store local files with unique name */
  196. GLOBAL int mcase; /* map upper to lower case for mget names */
  197. GLOBAL int ntflag; /* use ntin ntout tables for name translation */
  198. GLOBAL int mapflag; /* use mapin mapout templates on file names */
  199. GLOBAL int preserve; /* preserve modification time on files */
  200. GLOBAL int code; /* return/reply code for ftp command */
  201. GLOBAL int crflag; /* if 1, strip car. rets. on ascii gets */
  202. GLOBAL int passivemode; /* passive mode enabled */
  203. GLOBAL int activefallback; /* fall back to active mode if passive fails */
  204. GLOBAL char *altarg; /* argv[1] with no shell-like preprocessing */
  205. GLOBAL char ntin[17]; /* input translation table */
  206. GLOBAL char ntout[17]; /* output translation table */
  207. GLOBAL char mapin[MAXPATHLEN]; /* input map template */
  208. GLOBAL char mapout[MAXPATHLEN]; /* output map template */
  209. GLOBAL char typename[32]; /* name of file transfer type */
  210. GLOBAL int type; /* requested file transfer type */
  211. GLOBAL int curtype; /* current file transfer type */
  212. GLOBAL char structname[32]; /* name of file transfer structure */
  213. GLOBAL int stru; /* file transfer structure */
  214. GLOBAL char formname[32]; /* name of file transfer format */
  215. GLOBAL int form; /* file transfer format */
  216. GLOBAL char modename[32]; /* name of file transfer mode */
  217. GLOBAL int mode; /* file transfer mode */
  218. GLOBAL char bytename[32]; /* local byte size in ascii */
  219. GLOBAL int bytesize; /* local byte size in binary */
  220. GLOBAL int anonftp; /* automatic anonymous login */
  221. GLOBAL int dirchange; /* remote directory changed by cd command */
  222. GLOBAL int flushcache; /* set HTTP cache flush headers with request */
  223. GLOBAL int rate_get; /* maximum get xfer rate */
  224. GLOBAL int rate_get_incr; /* increment for get xfer rate */
  225. GLOBAL int rate_put; /* maximum put xfer rate */
  226. GLOBAL int rate_put_incr; /* increment for put xfer rate */
  227. GLOBAL int retry_connect; /* seconds between retrying connection */
  228. GLOBAL const char *tmpdir; /* temporary directory */
  229. GLOBAL int epsv4; /* use EPSV/EPRT on IPv4 connections */
  230. GLOBAL int epsv4bad; /* EPSV doesn't work on the current server */
  231. GLOBAL int epsv6; /* use EPSV/EPRT on IPv6 connections */
  232. GLOBAL int epsv6bad; /* EPSV doesn't work on the current server */
  233. GLOBAL int editing; /* command line editing enabled */
  234. GLOBAL int features[FEAT_max]; /* remote FEATures supported */
  235. #ifndef NO_EDITCOMPLETE
  236. GLOBAL EditLine *el; /* editline(3) status structure */
  237. GLOBAL History *hist; /* editline(3) history structure */
  238. GLOBAL char *cursor_pos; /* cursor position we're looking for */
  239. GLOBAL size_t cursor_argc; /* location of cursor in margv */
  240. GLOBAL size_t cursor_argo; /* offset of cursor in margv[cursor_argc] */
  241. #endif /* !NO_EDITCOMPLETE */
  242. GLOBAL char *hostname; /* name of host connected to */
  243. GLOBAL int unix_server; /* server is unix, can use binary for ascii */
  244. GLOBAL int unix_proxy; /* proxy is unix, can use binary for ascii */
  245. GLOBAL char localcwd[MAXPATHLEN]; /* local dir */
  246. GLOBAL char remotecwd[MAXPATHLEN]; /* remote dir */
  247. GLOBAL char *username; /* name of user logged in as. (dynamic) */
  248. GLOBAL sa_family_t family; /* address family to use for connections */
  249. GLOBAL const char *ftpport; /* port number to use for FTP connections */
  250. GLOBAL const char *httpport; /* port number to use for HTTP connections */
  251. GLOBAL const char *gateport; /* port number to use for gateftp connections */
  252. GLOBAL struct addrinfo *bindai; /* local address to bind as */
  253. GLOBAL char *outfile; /* filename to output URLs to */
  254. GLOBAL int restartautofetch; /* restart auto-fetch */
  255. GLOBAL char line[FTPBUFLEN]; /* input line buffer */
  256. GLOBAL char *stringbase; /* current scan point in line buffer */
  257. GLOBAL char argbuf[FTPBUFLEN]; /* argument storage buffer */
  258. GLOBAL char *argbase; /* current storage point in arg buffer */
  259. GLOBAL StringList *marg_sl; /* stringlist containing margv */
  260. GLOBAL int margc; /* count of arguments on input line */
  261. #define margv (marg_sl->sl_str) /* args parsed from input line */
  262. GLOBAL int cpend; /* flag: if != 0, then pending server reply */
  263. GLOBAL int mflag; /* flag: if != 0, then active multi command */
  264. GLOBAL int options; /* used during socket creation */
  265. GLOBAL int sndbuf_size; /* socket send buffer size */
  266. GLOBAL int rcvbuf_size; /* socket receive buffer size */
  267. GLOBAL int auto_sndbuf; /* flag: if != 0 then use auto sndbuf size */
  268. GLOBAL int auto_rcvbuf; /* flag: if != 0 then use auto rcvbuf size */
  269. GLOBAL int macnum; /* number of defined macros */
  270. GLOBAL struct macel macros[16];
  271. GLOBAL char macbuf[4096];
  272. GLOBAL char *localhome; /* local home directory */
  273. GLOBAL char *localname; /* local user name */
  274. GLOBAL char netrc[MAXPATHLEN]; /* path to .netrc file */
  275. GLOBAL char reply_string[BUFSIZ]; /* first line of previous reply */
  276. GLOBAL void (*reply_callback)(const char *);
  277. /*
  278. * function to call for each line in
  279. * the server's reply except for the
  280. * first (`xxx-') and last (`xxx ')
  281. */
  282. GLOBAL volatile sig_atomic_t sigint_raised;
  283. GLOBAL FILE *cin;
  284. GLOBAL FILE *cout;
  285. GLOBAL int data;
  286. extern struct cmd cmdtab[];
  287. extern struct option optiontab[];
  288. #define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
  289. #define FREEPTR(x) if ((x) != NULL) { free(x); (x) = NULL; }
  290. #ifdef BSD4_4
  291. # define HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 1
  292. #endif
  293. #ifdef NO_LONG_LONG
  294. # define STRTOLL(x,y,z) strtol(x,y,z)
  295. #else
  296. # define STRTOLL(x,y,z) strtoll(x,y,z)
  297. #endif
  298. #ifdef NO_DEBUG
  299. #define DPRINTF(...)
  300. #define DWARN(...)
  301. #else
  302. #define DPRINTF(...) if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__)
  303. #define DWARN(...) if (ftp_debug) warn(__VA_ARGS__)
  304. #endif
  305. #define STRorNULL(s) ((s) ? (s) : "<null>")
  306. #ifdef NO_USAGE
  307. void xusage(void);
  308. #define UPRINTF(...) xusage()
  309. #else
  310. #define UPRINTF(...) (void)fprintf(ttyout, __VA_ARGS__)
  311. #endif