Home | History | Annotate | Line # | Download | only in ftpd
extern.h revision 1.27
      1 /*	$NetBSD: extern.h,v 1.27 2000/06/14 13:44:22 lukem 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-2000 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 void	blkfree(char **);
    104 char   *conffilename(const char *);
    105 char  **copyblk(char **);
    106 void	count_users(void);
    107 void	cwd(const char *);
    108 FILE   *dataconn(const char *, off_t, const char *);
    109 void	delete(const char *);
    110 char  **do_conversion(const char *);
    111 void	dologout(int);
    112 void	fatal(const char *);
    113 void	feat(void);
    114 int	format_file(const char *, int);
    115 int	ftpd_pclose(FILE *);
    116 FILE   *ftpd_popen(char *[], const char *, int);
    117 char   *getline(char *, int, FILE *);
    118 void	init_curclass(void);
    119 void	logcmd(const char *, off_t, const char *, const char *,
    120 	    const struct timeval *, const char *);
    121 void	logwtmp(const char *, const char *, const char *);
    122 struct tab *lookup(struct tab *, const char *);
    123 void	lreply(int, const char *, ...);
    124 void	makedir(const char *);
    125 void	mlsd(const char *);
    126 void	mlst(const char *);
    127 void	opts(const char *);
    128 void	parse_conf(const char *);
    129 void	pass(const char *);
    130 void	passive(void);
    131 void	long_passive(char *, int);
    132 void	perror_reply(int, const char *);
    133 void	pwd(void);
    134 void	removedir(const char *);
    135 void	renamecmd(const char *, const char *);
    136 char   *renamefrom(const char *);
    137 void	reply(int, const char *, ...);
    138 void	retrieve(char *[], const char *);
    139 void	send_file_list(const char *);
    140 void	show_chdir_messages(int);
    141 void	sizecmd(const char *);
    142 void	statcmd(void);
    143 void	statfilecmd(const char *);
    144 void	store(const char *, const char *, int);
    145 int	strsuftoi(const char *);
    146 void	user(const char *);
    147 char   *xstrdup(const char *);
    148 void	yyerror(char *);
    149 
    150 typedef long long qdfmt_t;
    151 typedef unsigned long long qufmt_t;
    152 
    153 typedef enum {
    154 	CLASS_GUEST,
    155 	CLASS_CHROOT,
    156 	CLASS_REAL
    157 } class_ft;
    158 
    159 struct tab {
    160 	char	*name;
    161 	short	 token;
    162 	short	 state;
    163 	short	 flags;	/* 1 if command implemented, 2 if has options */
    164 	char	*help;
    165 	char	*options;
    166 };
    167 
    168 struct ftpconv {
    169 	struct ftpconv	*next;
    170 	char		*suffix;	/* Suffix of requested name */
    171 	char		*types;		/* Valid file types */
    172 	char		*disable;	/* File to disable conversions */
    173 	char		*command;	/* Command to do the conversion */
    174 };
    175 
    176 struct ftpclass {
    177 	int		 checkportcmd;	/* Check PORT commands are valid */
    178 	char		*classname;	/* Current class */
    179 	struct ftpconv	*conversions;	/* List of conversions */
    180 	char		*display;	/* Files to display upon chdir */
    181 	int	 	 limit;		/* Max connections (-1 = unlimited) */
    182 	char		*limitfile;	/* File to display if limit reached */
    183 	int		 maxrateget;	/* Maximum get transfer rate throttle */
    184 	int		 maxrateput;	/* Maximum put transfer rate throttle */
    185 	unsigned int	 maxtimeout;	/* Maximum permitted timeout */
    186 	int		 modify;	/* Allow CHMOD, DELE, MKD, RMD, RNFR,
    187 					   UMASK */
    188 	char		*motd;		/* MotD file to display after login */
    189 	char		*notify;	/* Files to notify about upon chdir */
    190 	int		 passive;	/* Allow PASV mode */
    191 	int		 portmin;	/* Minumum port for passive mode */
    192 	int		 portmax;	/* Maximum port for passive mode */
    193 	int		 rateget;	/* Get (RETR) transfer rate throttle */
    194 	int		 rateput;	/* Put (STOR) transfer rate throttle */
    195 	unsigned int	 timeout;	/* Default timeout */
    196 	class_ft	 type;		/* Class type */
    197 	mode_t		 umask;		/* Umask to use */
    198 	int		 upload;	/* As per modify, but also allow
    199 					   APPE, STOR, STOU */
    200 };
    201 
    202 #include <netinet/in.h>
    203 
    204 union sockunion {
    205 	struct sockinet {
    206 		u_char si_len;
    207 		u_char si_family;
    208 		u_short si_port;
    209 	} su_si;
    210 	struct sockaddr_in  su_sin;
    211 	struct sockaddr_in6 su_sin6;
    212 };
    213 #define su_len		su_si.si_len
    214 #define su_family	su_si.si_family
    215 #define su_port		su_si.si_port
    216 
    217 extern  int		yyparse(void);
    218 
    219 #ifndef	GLOBAL
    220 #define	GLOBAL	extern
    221 #endif
    222 
    223 
    224 GLOBAL	union sockunion	ctrl_addr;
    225 GLOBAL	union sockunion	data_dest;
    226 GLOBAL	union sockunion	data_source;
    227 GLOBAL	union sockunion	his_addr;
    228 GLOBAL	union sockunion	pasv_addr;
    229 GLOBAL	int		connections;
    230 GLOBAL	struct ftpclass	curclass;
    231 GLOBAL	int		debug;
    232 GLOBAL	jmp_buf		errcatch;
    233 GLOBAL	int		form;
    234 GLOBAL	int		hasyyerrored;
    235 GLOBAL	char		hostname[MAXHOSTNAMELEN+1];
    236 #ifdef KERBEROS5
    237 GLOBAL	krb5_context	kcontext;
    238 #endif
    239 GLOBAL	int		logged_in;
    240 GLOBAL	int		logging;
    241 GLOBAL	int		pdata;			/* for passive mode */
    242 #ifdef HASSETPROCTITLE
    243 GLOBAL	char		proctitle[BUFSIZ];	/* initial part of title */
    244 #endif
    245 GLOBAL	struct passwd  *pw;
    246 GLOBAL	int		quietmessages;
    247 GLOBAL	char		remotehost[MAXHOSTNAMELEN+1];
    248 GLOBAL	off_t		restart_point;
    249 GLOBAL	char		tmpline[7];
    250 GLOBAL	sig_atomic_t	transflag;
    251 GLOBAL	int		type;
    252 GLOBAL	int		usedefault;		/* for data transfers */
    253 
    254 						/* total file data bytes */
    255 GLOBAL	off_t		total_data_in,  total_data_out,  total_data;
    256 						/* total number of data files */
    257 GLOBAL	off_t		total_files_in, total_files_out, total_files;
    258 						/* total bytes */
    259 GLOBAL	off_t		total_bytes_in, total_bytes_out, total_bytes;
    260 						/* total number of xfers */
    261 GLOBAL	off_t		total_xfers_in, total_xfers_out, total_xfers;
    262 
    263 extern	struct tab	cmdtab[];
    264 
    265 #define	INTERNAL_LS	"/bin/ls"
    266 
    267 
    268 #define CMD_IMPLEMENTED(x)	((x)->flags != 0)
    269 #define CMD_HAS_OPTIONS(x)	((x)->flags == 2)
    270 
    271 #define CURCLASSTYPE	curclass.type == CLASS_GUEST  ? "GUEST"  : \
    272 		    	curclass.type == CLASS_CHROOT ? "CHROOT" : \
    273 		    	curclass.type == CLASS_REAL   ? "REAL"   : \
    274 			"<unknown>"
    275 
    276 #define ISDOTDIR(x)	(x[0] == '.' && x[1] == '\0')
    277 #define ISDOTDOTDIR(x)	(x[0] == '.' && x[1] == '.' && x[2] == '\0')
    278 
    279 #define EMPTYSTR(p)	((p) == NULL || *(p) == '\0')
    280 #define NEXTWORD(P, W)	do { \
    281 				(W) = strsep(&(P), " \t"); \
    282 			} while ((W) != NULL && *(W) == '\0')
    283 #define PLURAL(s)	((s) == 1 ? "" : "s")
    284 #define REASSIGN(X,Y)	do { if (X) free(X); (X)=(Y); } while (/*CONSTCOND*/0)
    285