1 /*
   2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /****************************************************************************    
   6   Copyright (c) 1999,2000 WU-FTPD Development Group.  
   7   All rights reserved.
   8    
   9   Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994  
  10     The Regents of the University of California. 
  11   Portions Copyright (c) 1993, 1994 Washington University in Saint Louis.  
  12   Portions Copyright (c) 1996, 1998 Berkeley Software Design, Inc.  
  13   Portions Copyright (c) 1989 Massachusetts Institute of Technology.  
  14   Portions Copyright (c) 1998 Sendmail, Inc.  
  15   Portions Copyright (c) 1983, 1995, 1996, 1997 Eric P.  Allman.  
  16   Portions Copyright (c) 1997 by Stan Barber.  
  17   Portions Copyright (c) 1997 by Kent Landfield.  
  18   Portions Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997  
  19     Free Software Foundation, Inc.    
  20    
  21   Use and distribution of this software and its source code are governed   
  22   by the terms and conditions of the WU-FTPD Software License ("LICENSE").  
  23    
  24   If you did not receive a copy of the license, it may be obtained online  
  25   at http://www.wu-ftpd.org/license.html.  
  26    
  27   $Id: proto.h,v 1.10 2000/07/01 18:17:39 wuftpd Exp $  
  28    
  29 ****************************************************************************/
  30 #include <sys/types.h>
  31 #include <sys/stat.h>
  32 #include <sys/socket.h>
  33 #include <ctype.h>
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <signal.h>
  37 #include <pwd.h>
  38 #include <grp.h>
  39 #include <setjmp.h>
  40 #include <netdb.h>
  41 #include <errno.h>
  42 #include <string.h>
  43 #include <stdarg.h>
  44 #include <netinet/in.h>
  45 
  46 /*
  47    ** access.c
  48  */
  49 int parsetime(char *);
  50 int validtime(char *);
  51 int hostmatch(char *, char *, char *);
  52 int acl_guestgroup(struct passwd *);
  53 int acl_realgroup(struct passwd *);
  54 void acl_autogroup(struct passwd *);
  55 void acl_setfunctions(void);
  56 int acl_getclass(char *);
  57 int acl_getlimit(char *, char *);
  58 int acl_getnice(char *);
  59 void acl_getdefumask(char *);
  60 void acl_tcpwindow(char *);
  61 void acl_filelimit(char *);
  62 void acl_datalimit(char *);
  63 int acl_deny(char *);
  64 int acl_countusers(char *);
  65 int acl_join(char *, int);
  66 void acl_remove(void);
  67 void pr_mesg(int, char *);
  68 void access_init(void);
  69 int access_ok(int);
  70 
  71 /*
  72    ** acl.c
  73  */
  74 struct aclmember *getaclentry(char *, struct aclmember **);
  75 void parseacl(void);
  76 int readacl(char *);
  77 
  78 /*
  79    ** auth.c
  80  */
  81 #ifdef  BSD_AUTH
  82 char *start_auth(char *, char *, struct passwd *);
  83 #endif
  84 char *check_auth(char *, char *);
  85 
  86 /*
  87    ** authenticate.c
  88  */
  89 int wu_authenticate(void);
  90 
  91 /*
  92    ** conversions.c
  93  */
  94 void conv_init(void);
  95 
  96 /*
  97    ** domain.c
  98  */
  99 int check_rhost_reverse(void);
 100 int check_rhost_matches(void);
 101 int rhostlookup(char *);
 102 void set_res_options(void);
 103 
 104 /*
 105    ** extensions.c
 106  */
 107 #ifdef SITE_NEWER
 108 int check_newer(const char *, const struct stat *, int);
 109 void newer(char *date, char *path, int showlots);
 110 #endif
 111 long getSize(char *);
 112 void msg_massage(const char *, char *, size_t);
 113 int cwd_beenhere(int);
 114 void show_banner(int);
 115 void show_message(int, int);
 116 void show_readme(int, int);
 117 int deny_badasciixfer(int, char *);
 118 int is_shutdown(int, int);
 119 int type_match(char *typelist);
 120 int path_compare(char *p1, char *p2);
 121 void expand_id(void);
 122 int fn_check(char *name);
 123 int dir_check(char *name, uid_t * uid, gid_t * gid, int *d_mode, int *valid);
 124 int upl_check(char *name, uid_t * uid, gid_t * gid, int *f_mode, int *valid);
 125 int del_check(char *name);
 126 int regexmatch(char *name, char *rgexp);
 127 int checknoretrieve(char *name);
 128 int path_to_device(char *pathname, char *result);
 129 void get_quota(char *fs, int uid);
 130 char *time_quota(long curstate, long softlimit, long timelimit, char *timeleft);
 131 void fmttime(char *buf, register long time);
 132 int file_compare(char *patterns, char *file);
 133 int remote_compare(char *patterns);
 134 void throughput_calc(char *name, int *bps, double *bpsmult);
 135 void throughput_adjust(char *name);
 136 void SetCheckMethod(const char *method);
 137 void ShowCheckMethod(void);
 138 void CheckSum(char *pathname);
 139 void CheckSumLastFile(void);
 140 
 141 /*
 142    ** ftpcmd.c
 143  */
 144 char *wu_getline(char *s, int n, register FILE *iop);
 145 int yyparse(void);
 146 void upper(char *s);
 147 char *copy(char *s);
 148 void sizecmd(char *filename);
 149 void site_exec(char *cmd);
 150 void alias(char *s);
 151 void cdpath(void);
 152 void print_groups(void);
 153 
 154 /*
 155    ** ftpd.c
 156  */
 157 
 158 SIGNAL_TYPE randomsig(int sig);
 159 SIGNAL_TYPE lostconn(int sig);
 160 char *mapping_getwd(char *path);
 161 void do_elem(char *dir);
 162 int mapping_chdir(char *orig_path);
 163 char *sgetsave(char *s);
 164 struct passwd *sgetpwnam(char *name);
 165 char *skey_challenge(char *name, struct passwd *pwd, int pwok);
 166 void user(char *name);
 167 int checkuser(char *name);
 168 int uid_match(char *keyword, uid_t uid);
 169 int gid_match(char *keyword, gid_t gid, char *username);
 170 int denieduid(uid_t uid);
 171 int alloweduid(uid_t uid);
 172 int deniedgid(gid_t gid);
 173 int allowedgid(gid_t gid);
 174 void end_login(void);
 175 int validate_eaddr(char *eaddr);
 176 void pass(char *passwd);
 177 int restricteduid(uid_t uid);
 178 int unrestricteduid(uid_t uid);
 179 int restrictedgid(gid_t gid);
 180 int unrestrictedgid(gid_t gid);
 181 char *opt_string(int options);
 182 void retrieve(char *cmd, char *name);
 183 void store(char *name, char *mode, int unique);
 184 FILE *getdatasock(char *mode);
 185 FILE *dataconn(char *name, off_t size, char *mode);
 186 #ifdef THROUGHPUT
 187 int send_data(char *name, FILE *instr, FILE *outstr, size_t blksize);
 188 #else
 189 int send_data(FILE *instr, FILE *outstr, size_t blksize);
 190 #endif
 191 int receive_data(FILE *instr, FILE *outstr);
 192 void statfilecmd(char *filename);
 193 void statcmd(void);
 194 void fatal(char *s);
 195 void vreply(long flags, int n, char *fmt, va_list ap);
 196 void reply(int, char *fmt,...);
 197 void lreply(int, char *fmt,...);
 198 void ack(char *s);
 199 void nack(char *s);
 200 void yyerror(char *s);
 201 void delete(char *name);
 202 void cwd(char *path);
 203 void makedir(char *name);
 204 void removedir(char *name);
 205 void pwd(void);
 206 char *renamefrom(char *name);
 207 void renamecmd(char *from, char *to);
 208 void dologout(int status);
 209 SIGNAL_TYPE myoob(int sig);
 210 void passive(int passive_mode, int proto);
 211 char *gunique(char *local);
 212 void perror_reply(int code, char *string);
 213 void send_file_list(char *whichfiles);
 214 void initsetproctitle(int argc, char **argv, char **envp);
 215 void setproctitle(const char *fmt,...);
 216 void init_krb(void);
 217 void end_krb(void);
 218 
 219 #ifdef INTERNAL_LS
 220 char *rpad(char *s, unsigned int len);
 221 char *ls_file(const char *file, int nameonly, char remove_path, char classify);
 222 void ls_dir(char *d, char ls_a, char ls_F, char ls_l, char ls_R, char omit_total, FILE *out);
 223 void ls(char *file, char nlst);
 224 #endif
 225 
 226 void fixpath(char *path);
 227 
 228 /*
 229    ** glob.c
 230  */
 231 void blkfree(char **);
 232 char **ftpglob(register char *, boolean_t check_ncargs);
 233 char *strspl(register char *, register char *);
 234 char **copyblk(register char **);
 235 
 236 /*
 237    ** hostacc.c
 238  */
 239 int rhost_ok(char *pcRuser, char *pcRhost, char *pcRaddr);
 240 
 241 /*
 242    ** loadavg.c
 243  */
 244 /*
 245    ** logwtmp.c
 246  */
 247 void wu_logwtmp(char *line, char *name, char *host, int login);
 248 
 249 /*
 250    ** paths.c
 251  */
 252 void setup_paths(void);
 253 
 254 /*
 255    ** popen.c
 256  */
 257 FILE *ftpd_popen(char *program, char *type, int closestderr);
 258 int ftpd_pclose(FILE *iop);
 259 void closefds(int startfd);
 260 
 261 /*
 262    ** private.c
 263  */
 264 #ifndef NO_PRIVATE
 265 void priv_setup(char *path);
 266 void priv_group(char *group);
 267 void priv_gpass(char *gpass);
 268 #endif
 269 
 270 /*
 271    ** rdservers.c
 272  */
 273 #ifdef VIRTUAL
 274 int read_servers_line(FILE *, char *, size_t, char *, size_t);
 275 #endif
 276 
 277 /*
 278    ** realpath.c
 279  */
 280 char *fb_realpath(const char *path, char *resolved);
 281 char *wu_realpath(const char *path, char *resolved_path, char *chroot_path);
 282 
 283 /*
 284    ** restrict.c
 285  */
 286 int restrict_check(char *name);
 287 int test_restriction(char *name);
 288 int restrict_list_check(char *name);
 289 
 290 /*
 291    ** routevector.c
 292  */
 293 int routevector(void);
 294 
 295 /*
 296    ** timeout.c
 297  */
 298 void load_timeouts(void);
 299 
 300 /*
 301    ** inet.c
 302  */
 303 char *inet_htop(const char *hostname);
 304 char *inet_stop(struct SOCKSTORAGE *ss);
 305 char *wu_gethostbyname(const char *hostname);
 306 int wu_gethostbyaddr(struct SOCKSTORAGE *ss, char *hostname, int hostlen);
 307 int sock_cmp_inaddr(struct SOCKSTORAGE *ss, struct in_addr addr);
 308 #ifdef INET6
 309 void sock_set_inaddr(struct SOCKSTORAGE *ss, struct in_addr addr);
 310 int sock_cmp_addr(struct SOCKSTORAGE *ss1, struct SOCKSTORAGE *ss2);
 311 void sock_set_scope(struct SOCKSTORAGE *dst, struct SOCKSTORAGE *src);
 312 int inet_pton6(char *str, struct in6_addr *addr);
 313 const char *inet_ntop_native(int af, const void *addr, char *dst, size_t size);
 314 #endif
 315 
 316 /*
 317    ** xferlog.c
 318  */
 319 void get_xferlog_format(void);
 320 
 321 /*
 322    ** privs.c
 323  */
 324 void init_privs(const char *);
 325 void port_priv_on(uid_t);
 326 void port_priv_off(uid_t);
 327 void access_priv_on(uid_t);
 328 void access_priv_off(uid_t);
 329 void setid_priv_on(uid_t);
 330 void setid_priv_off(uid_t);
 331 void chown_priv_on(uid_t);
 332 void chown_priv_off(uid_t);
 333 
 334 /*
 335    ** support/getusershell.c
 336  */
 337 char *getusershell(void);
 338 void endusershell(void);