/* * FTP/HTTP daemon * fhttpd.h Copyright (C) 1995, 96, 97 Alex Belits * * This source/code is public free; you can distribute it and/or modify * it under terms of the GNU General Public License (published by the * Free Software Foundation) either version two of this License, or any * later version. * */ #ifndef INCLUDED_FHTTPD_H #define INCLUDED_FHTTPD_H 1 #include #ifdef AIX4 #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef NEED_SELECT_H #include #endif #ifdef IRIX #include "irix-fix.h" #endif #include "configargs.h" #include "wildmat.h" #include "sockobj.h" #include "lists.h" #include "process.h" #include "fhttpd-decls.h" enum{/* FTP ->*/ USER,PASS,ACCT,REIN,QUIT,PORT,PASV,TYPE,STRU,MODE,RETR,STOR,APPE, MLFL,MAIL,MSND,MSOM,MSAM,MRSQ,MRCP,ALLO,REST,RNFR,RNTO,ABOR,DELE,CWD, XCWD,LIST,NLST,SITE,CMD_STAT,HELP,NOOP,MKD,XMKD,RMD,XRMD,PWD,XPWD,CDUP, XCUP,STOU,SYST,/*<- FTP / HTTP ->*/ GET,POST,HEAD,PUT,/*<- HTTP / Internals ->*/ CLIK,GET_CLIK,GETH,XGTH,XGET,XPST,XHED,NCOMMANDS}; enum{PROC_USER,PROC_PASS,PROC_APPLICATION,PROC_LOGAPPLICATION,PROC_QUIT,NPROCESSCOMMANDS}; char *strupr(char *s); int swrite(int h,char *s); signed char char64value(signed char c); unsigned long un64(char *s); void unescape(char *s); char *linefromtime(char *s,time_t t); time_t timefromline(char *s); int filenamecmp(char *s1,char *s2,int *noslashflag); int hastrailingslash(char *s1); int trailingslashcmp(char *s1,char *s2); class AddressRoot:public Item{ public: __s32 address; char *hostname; char *rootdir; AddressRoot(__s32 xaddress,char *xhostname,char *xrootdir); virtual ~AddressRoot(void); }; class User:public Item{ public: char *username; char *passwd; char *realname; char *homedir; char *shell; int userid; int groupid; User(char *xusername=NULL,char *xpasswd=NULL,int xuserid=-1,int xgroupid=-1, char *xrealname="???",char *xhomedir=NULL,char *xshell=NULL); virtual ~User(void); }; class AccessRealm:public Item{ public: char *realmname; char *filename; List users; AccessRealm(char *realmname,char *filename); int readfile(void); User *FindUser(char *name); int CheckPassword(char *username,char *password); virtual ~AccessRealm(void); }; class AccessRights:public Item{ public: char *pattern; AccessRealm *realm; char *user; AccessRights(char *pattern,AccessRealm *realm,char *user); virtual ~AccessRights(void); }; class LoadedFile:public Item{ public: char *path; char *realname; char *buffer; int headerwithoutkeepalivesize; int keepalivesize; int prefixbufferlength; long size; time_t filetime; __s32 address; LoadedFile(char *xpath,char *xrealname,__s32 xaddress); virtual ~LoadedFile(void); }; class ModeArgs:public ConfigArgs{ public: int mode; ModeArgs(int argc,char **args,int xmode=0600,int abs=0); }; class DataFTPServer:public ServerSocket{ public: DataFTPServer(char *xname,int xport,__s32 xlocaladdr=0); }; class ControlFTPServerApp:public ServerConnectionApp{ public: time_t timestamp; char resolvedname[256]; char portstring[40]; char username[129]; char basedir[257]; char cwd[257]; char rnfr[257]; char buffer[2049]; char type; int map_uid; int userid; int gid; int auth; int boffset; int bufflen; char lastchar; int trailingslash; int trailingslashmismatch; int lastruleapplied1; int lastruleapplied2; int lastruleapplied3; char localhostname[256]; int reading_http_req; int method; int nparam; char dstbuffer[2048]; char translatedbuf[MAXPATHLEN+2+MAXNAMLEN]; char urlbuffer[2048]; char srcbuffer[2048]; char currbasedir[255]; char currcwd[255]; char auth_user_buffer[81]; char auth_password_buffer[81]; char http_accept_buffer[256]; char http_user_agent_buffer[256]; int content_length; int http_data_left; time_t ifmodifiedsince; char query_type_buffer[256]; int keepalive; LoadedFile *currloadedfile; Application *currapplication; ApplicationRequest *appreq; List requestptrs; char *execenv[256]; int nexecenv; __s32 preassigned_id; ControlFTPServerApp(ServerConnection *c); ~ControlFTPServerApp(void); void initanonymous(void); void process_get_line(char *inoutline); void cleanexecenv(void); int setexecenv_noalloc(char *namevalue); int setexecenv(const char *namevalue); int setexecenv(const char *name,const char *value); }; class ControlFTPServer:public ServerSocket{ public: int servertype; ControlFTPServer(char *xname,int xport,int xmaxclients,__s32 xlocaladdr=0); int chdir_u_g(ServerConnection *client); char *translatename(ServerConnection *client,char *dst,char *src,int *map_uid=NULL); ConfigArgs *findwildargs(ServerConnection *client,List *list,char *string); ConfigArgs *findwildargsreal(ServerConnection *client,List *list,char *string); AccessRealm *findrealm(ServerConnection *client,List *list,char *string); int isrestricted(ServerConnection *client,List *rightslist,char *string); int checkrights(ServerConnection *client,List *rightslist,char *string,char *user,char *password,char *realm,int realmlen); int translatechdir(ServerConnection *client,char *path); char *translategetcwd(ServerConnection *client,char *buf,size_t size); DIR *translateopendir(ServerConnection *client,char *name); int translateopen(ServerConnection *client,char *pathname,int flags,mode_t mode=0); int translateunlink(ServerConnection *client,char *path); int translatemkdir(ServerConnection *client,char *pathname,mode_t mode); int translatermdir(ServerConnection *client,char *pathname); int translatestat(ServerConnection *client,char *pathname,struct stat *buf); virtual void emptyfn(ServerConnection *client); virtual void connectfn(ServerConnection *client); /* virtual void disconnectfn(ServerConnection *client); */ virtual void splitfn(ServerConnection *client,ServerProcess *process); /* virtual void splitparentfn(ServerConnection *client,ServerProcess *process); virtual void unsplitfn(ServerConnection *client,ServerProcess *process); virtual void afterunsplitfn(ServerConnection *client,ServerProcess *process); */ virtual int prioritydatafn(ServerConnection *client); virtual int datafn(ServerConnection *client); virtual int pipedatafn(ServerConnection *client,ServerProcess *process); virtual int pipeprioritydatafn(ServerConnection *client,ServerProcess *process); void response(ServerConnection *client,char *fmt,...); void hugeresponse(ServerConnection *client,char *buffer,unsigned long size); void setexitafterresponse(ServerConnection *client,int closeonexit); int getexitafterresponse(ServerConnection *client); void emptyresponse(ServerConnection *client); void suspendpollforresponse(ServerConnection *client,int startpollonexit); void answer_to_list(char *buffer,int i,int *syncexpected, ServerConnection *client,ServerProcess *process, ClientConnection *dataconnection=NULL); }; int mycompar0(const void *a,const void *b); int htmlencode(char *dst,const char *src);//may increase the size up to 5 times! int urlencode(char *dst,const char *src,char except);//may increase the size up to 3 times! void unconfig(void); int readconfig(char *name); void sigfn1(SIGACTARGS); void sighupfn(SIGACTARGS); extern char *configcommands[NCONFIGCOMMANDS]; extern char *commands[NCOMMANDS]; extern char *commands4[NCOMMANDS]; extern char *processcommands[NPROCESSCOMMANDS]; extern char *processcommands4[NPROCESSCOMMANDS]; extern struct hostsstruct{ char *hostname; __s32 hostaddr; }hosts[256]; extern int nhosts; extern int phosts; extern time_t global_time; extern int honorkeepalive; extern int global_resolve_hostnames; extern struct passwd *globalhttppw; extern char *diroverride,*original_rootdir; extern int http_server_port,ftp_server_port,process_server_port; extern __s32 http_server_addr,ftp_server_addr,process_server_addr; extern int max_content_length; extern int max_message_size; extern int max_totalsize; extern int max_totallogmessagessize; extern int map_username; extern int global_umask; extern int fhttpd_nconnections; extern int fhttpd_npipes; extern char *default_header,*default_footer,*userhomedir; extern List inbounds,pipeinexec,pipeoutexec,pipeinpermanent,pipeoutpermanent,pipeinsession,pipeoutsession,getrules, types,dirtypes,executables,specialexecutables,accessrealms,accessrights,loadedfiles,addressroots, stor_modelist,mkd_modelist,applist,logapplications; extern char *monthnames[12]; extern char *weekdaynames[7]; extern char *headerwithoutkeepalive; extern char *headerkeepalive; #endif