extern.h revision 108746
1/* $NetBSD: extern.h,v 1.44 2002/05/30 00:24:47 enami Exp $ */ 2 3/*- 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)extern.h 8.2 (Berkeley) 4/4/94 36 */ 37 38/*- 39 * Copyright (c) 1997-2001 The NetBSD Foundation, Inc. 40 * All rights reserved. 41 * 42 * This code is derived from software contributed to The NetBSD Foundation 43 * by Luke Mewburn. 44 * 45 * Redistribution and use in source and binary forms, with or without 46 * modification, are permitted provided that the following conditions 47 * are met: 48 * 1. Redistributions of source code must retain the above copyright 49 * notice, this list of conditions and the following disclaimer. 50 * 2. Redistributions in binary form must reproduce the above copyright 51 * notice, this list of conditions and the following disclaimer in the 52 * documentation and/or other materials provided with the distribution. 53 * 3. All advertising materials mentioning features or use of this software 54 * must display the following acknowledgement: 55 * This product includes software developed by the NetBSD 56 * Foundation, Inc. and its contributors. 57 * 4. Neither the name of The NetBSD Foundation nor the names of its 58 * contributors may be used to endorse or promote products derived 59 * from this software without specific prior written permission. 60 * 61 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 62 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 63 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 64 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 65 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 66 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 67 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 68 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 69 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 70 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 71 * POSSIBILITY OF SUCH DAMAGE. 72 */ 73 74/* 75 * Copyright (C) 1997 and 1998 WIDE Project. 76 * All rights reserved. 77 * 78 * Redistribution and use in source and binary forms, with or without 79 * modification, are permitted provided that the following conditions 80 * are met: 81 * 1. Redistributions of source code must retain the above copyright 82 * notice, this list of conditions and the following disclaimer. 83 * 2. Redistributions in binary form must reproduce the above copyright 84 * notice, this list of conditions and the following disclaimer in the 85 * documentation and/or other materials provided with the distribution. 86 * 3. Neither the name of the project nor the names of its contributors 87 * may be used to endorse or promote products derived from this software 88 * without specific prior written permission. 89 * 90 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 93 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 100 * SUCH DAMAGE. 101 */ 102 103#ifdef NO_LONG_LONG 104# define LLF "%ld" 105# define LLFP(x) "%" x "ld" 106# define LLT long 107# define ULLF "%lu" 108# define ULLFP(x) "%" x "lu" 109# define ULLT unsigned long 110# define STRTOLL(x,y,z) strtol(x,y,z) 111# define LLTMIN LONG_MIN 112# define LLTMAX LONG_MAX 113#else 114# define LLF "%lld" 115# define LLFP(x) "%" x "lld" 116# define LLT long long 117# define ULLF "%llu" 118# define ULLFP(x) "%" x "llu" 119# define ULLT unsigned long long 120# define STRTOLL(x,y,z) strtoll(x,y,z) 121# define LLTMIN LLONG_MIN 122# define LLTMAX LLONG_MAX 123#endif 124 125#define FTP_BUFLEN 512 126 127void abor(void); 128void blkfree(char **); 129void closedataconn(FILE *); 130char *conffilename(const char *); 131char **copyblk(char **); 132void count_users(void); 133void cprintf(FILE *, const char *, ...) 134 __attribute__((__format__(__printf__, 2, 3))); 135void cwd(const char *); 136FILE *dataconn(const char *, off_t, const char *); 137void delete(const char *); 138int display_file(const char *, int); 139char **do_conversion(const char *); 140void dologout(int); 141void fatal(const char *); 142void feat(void); 143void format_path(char *, const char *); 144int ftpd_pclose(FILE *); 145FILE *ftpd_popen(char *[], const char *, int); 146char *getline(char *, int, FILE *); 147void init_curclass(void); 148void logxfer(const char *, off_t, const char *, const char *, 149 const struct timeval *, const char *); 150#if 0 151void logwtmp(const char *, const char *, const char *); 152#endif 153struct tab *lookup(struct tab *, const char *); 154void makedir(const char *); 155void mlsd(const char *); 156void mlst(const char *); 157void opts(const char *); 158void parse_conf(const char *); 159void pass(const char *); 160void passive(void); 161int lpsvproto2af(int); 162int af2lpsvproto(int); 163int epsvproto2af(int); 164int af2epsvproto(int); 165void long_passive(char *, int); 166int extended_port(const char *); 167void epsv_protounsupp(const char *); 168void perror_reply(int, const char *); 169void pwd(void); 170void removedir(const char *); 171void renamecmd(const char *, const char *); 172char *renamefrom(const char *); 173void reply(int, const char *, ...) 174 __attribute__((__format__(__printf__, 2, 3))); 175void retrieve(char *[], const char *); 176void send_file_list(const char *); 177void show_chdir_messages(int); 178void sizecmd(const char *); 179void statcmd(void); 180void statfilecmd(const char *); 181void statxfer(void); 182void store(const char *, const char *, int); 183void user(const char *); 184char *xstrdup(const char *); 185void yyerror(char *); 186 187#include <netinet/in.h> 188 189#if defined(__NetBSD__) 190# define HAVE_SETPROCTITLE 1 191# define HAVE_SOCKADDR_SA_LEN 1 192#endif 193 194struct sockinet { 195 union sockunion { 196 struct sockaddr_in su_sin; 197#ifdef INET6 198 struct sockaddr_in6 su_sin6; 199#endif 200 } si_su; 201#if !HAVE_SOCKADDR_SA_LEN 202 int si_len; 203#endif 204}; 205 206#if !HAVE_SOCKADDR_SA_LEN 207# define su_len si_len 208#else 209# define su_len si_su.su_sin.sin_len 210#endif 211#define su_addr si_su.su_sin.sin_addr 212#define su_family si_su.su_sin.sin_family 213#define su_port si_su.su_sin.sin_port 214#ifdef INET6 215# define su_6addr si_su.su_sin6.sin6_addr 216# define su_scope_id si_su.su_sin6.sin6_scope_id 217#endif 218 219struct tab { 220 char *name; 221 short token; 222 short state; 223 short flags; /* 1 if command implemented, 2 if has options, 224 4 if can occur OOB */ 225 char *help; 226 char *options; 227}; 228 229struct ftpconv { 230 struct ftpconv *next; 231 char *suffix; /* Suffix of requested name */ 232 char *types; /* Valid file types */ 233 char *disable; /* File to disable conversions */ 234 char *command; /* Command to do the conversion */ 235}; 236 237typedef enum { 238 CLASS_GUEST, 239 CLASS_CHROOT, 240 CLASS_REAL 241} class_ft; 242 243typedef enum { 244 FLAG_checkportcmd = 1<<0, /* Check port commands */ 245 FLAG_denyquick = 1<<1, /* Check ftpusers(5) before PASS */ 246 FLAG_modify = 1<<2, /* Allow CHMOD, DELE, MKD, RMD, RNFR, 247 UMASK */ 248 FLAG_passive = 1<<3, /* Allow PASV mode */ 249 FLAG_private = 1<<4, /* Don't publish class info in STAT */ 250 FLAG_sanenames = 1<<5, /* Restrict names of uploaded files */ 251 FLAG_upload = 1<<6, /* As per modify, but also allow 252 APPE, STOR, STOU */ 253} classflag_t; 254 255#define CURCLASS_FLAGS_SET(x) (curclass.flags |= (FLAG_ ## x)) 256#define CURCLASS_FLAGS_CLR(x) (curclass.flags &= ~(FLAG_ ## x)) 257#define CURCLASS_FLAGS_ISSET(x) (curclass.flags & (FLAG_ ## x)) 258 259struct ftpclass { 260 struct sockinet advertise; /* PASV address to advertise as */ 261 char *chroot; /* Directory to chroot(2) to at login */ 262 char *classname; /* Current class */ 263 struct ftpconv *conversions; /* List of conversions */ 264 char *display; /* File to display upon chdir */ 265 char *homedir; /* Directory to chdir(2) to at login */ 266 classflag_t flags; /* Flags; see classflag_t above */ 267 LLT limit; /* Max connections (-1 = unlimited) */ 268 char *limitfile; /* File to display if limit reached */ 269 LLT maxfilesize; /* Maximum file size of uploads */ 270 LLT maxrateget; /* Maximum get transfer rate throttle */ 271 LLT maxrateput; /* Maximum put transfer rate throttle */ 272 LLT maxtimeout; /* Maximum permitted timeout */ 273 char *motd; /* MotD file to display after login */ 274 char *notify; /* Files to notify about upon chdir */ 275 LLT portmin; /* Minumum port for passive mode */ 276 LLT portmax; /* Maximum port for passive mode */ 277 LLT rateget; /* Get (RETR) transfer rate throttle */ 278 LLT rateput; /* Put (STOR) transfer rate throttle */ 279 LLT timeout; /* Default timeout */ 280 class_ft type; /* Class type */ 281 mode_t umask; /* Umask to use */ 282 LLT mmapsize; /* mmap window size */ 283 LLT readsize; /* data read size */ 284 LLT writesize; /* data write size */ 285 LLT sendbufsize; /* SO_SNDBUF size */ 286 LLT sendlowat; /* SO_SNDLOWAT size */ 287}; 288 289extern void ftp_loop(void) __attribute__ ((noreturn)); 290extern void ftp_handle_line(char *); 291 292#ifndef GLOBAL 293#define GLOBAL extern 294#endif 295 296 297GLOBAL struct sockinet ctrl_addr; 298GLOBAL struct sockinet data_dest; 299GLOBAL struct sockinet data_source; 300GLOBAL struct sockinet his_addr; 301GLOBAL struct sockinet pasv_addr; 302GLOBAL int connections; 303GLOBAL struct ftpclass curclass; 304GLOBAL int debug; 305GLOBAL jmp_buf errcatch; 306GLOBAL char *emailaddr; 307GLOBAL int form; 308GLOBAL int gidcount; /* number of entries in gidlist[] */ 309GLOBAL gid_t gidlist[NGROUPS_MAX]; 310GLOBAL int hasyyerrored; 311GLOBAL char hostname[MAXHOSTNAMELEN+1]; 312GLOBAL char homedir[MAXPATHLEN]; 313#ifdef KERBEROS5 314GLOBAL krb5_context kcontext; 315#endif 316GLOBAL int logged_in; 317GLOBAL int logging; 318GLOBAL int pdata; /* for passive mode */ 319#if HAVE_SETPROCTITLE 320GLOBAL char proctitle[BUFSIZ]; /* initial part of title */ 321#endif 322GLOBAL struct passwd *pw; 323GLOBAL int quietmessages; 324GLOBAL char remotehost[MAXHOSTNAMELEN+1]; 325GLOBAL off_t restart_point; 326GLOBAL char tmpline[FTP_BUFLEN]; 327GLOBAL sig_atomic_t transflag; 328GLOBAL int type; 329GLOBAL int usedefault; /* for data transfers */ 330GLOBAL const char *version; 331GLOBAL int is_oob; 332 333 /* total file data bytes */ 334GLOBAL off_t total_data_in, total_data_out, total_data; 335 /* total number of data files */ 336GLOBAL off_t total_files_in, total_files_out, total_files; 337 /* total bytes */ 338GLOBAL off_t total_bytes_in, total_bytes_out, total_bytes; 339 /* total number of xfers */ 340GLOBAL off_t total_xfers_in, total_xfers_out, total_xfers; 341 342extern struct tab cmdtab[]; 343 344#define INTERNAL_LS "/bin/ls" 345 346 347#define CMD_IMPLEMENTED(x) ((x)->flags != 0) 348#define CMD_HAS_OPTIONS(x) ((x)->flags & 0x2) 349#define CMD_OOB(x) ((x)->flags & 0x4) 350 351#define CPUTC(c, f) do { \ 352 putc(c, f); total_bytes++; total_bytes_out++; \ 353 } while (0); 354 355#define CURCLASSTYPE curclass.type == CLASS_GUEST ? "GUEST" : \ 356 curclass.type == CLASS_CHROOT ? "CHROOT" : \ 357 curclass.type == CLASS_REAL ? "REAL" : \ 358 "<unknown>" 359 360#define ISDOTDIR(x) (x[0] == '.' && x[1] == '\0') 361#define ISDOTDOTDIR(x) (x[0] == '.' && x[1] == '.' && x[2] == '\0') 362 363#define EMPTYSTR(p) ((p) == NULL || *(p) == '\0') 364#define NEXTWORD(P, W) do { \ 365 (W) = strsep(&(P), " \t"); \ 366 } while ((W) != NULL && *(W) == '\0') 367#define PLURAL(s) ((s) == 1 ? "" : "s") 368#define REASSIGN(X,Y) do { if (X) free(X); (X)=(Y); } while (/*CONSTCOND*/0) 369 370#ifndef IPPORT_ANONMAX 371# define IPPORT_ANONMAX 65535 372#endif 373