diff -urN thttpd-2.21-2/libhttpd.c thttpd-2.21-3/libhttpd.c --- thttpd-2.21-2/libhttpd.c Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-3/libhttpd.c Thu Nov 22 14:43:09 2001 @@ -78,55 +78,59 @@ #endif #ifdef VHOST_MYSQL #include "vhostconf.h" + extern struct node *vh_list; extern struct banner *bn_list; extern int vh_list_len, bn_list_len; int numreq=0; -// KURRR!!!! GOLQM PRI TOVA -static char* tempfilename; -static int maxtempfilename = 0; - static char* header; - static int maxheader = 0; - static char* authpath; - static int maxauthpath = 0; - static char* prevauthpath; - static int maxprevauthpath = 0; - static char* prevuser; - static int maxprevuser = 0; - static char* prevcryp; - static int maxprevcryp = 0; - static char* location; - static char* header; - static int maxlocation = 0; - static char* temp; - static int maxtemp = 0; - static char* checked; - static char* rest; - static int maxchecked = 0, maxrest = 0; - static int maxnames = 0; - - static char* names; - static char** nameptrs; - static char* name; - static int maxname = 0; - static char* rname; - static int maxrname = 0; - static char* encrname; - static int maxencrname = 0; - static char* buf; - static int maxbuf = 0; - static char* indexname; - static int maxindexname = 0; +#endif +/* + Global variables + static stuff doesn't really work as planned, so they all are here + */ +char* tempfilename; +int maxtempfilename = 0; +char* header; +int maxheader = 0; +char* authpath; +int maxauthpath = 0; +char* prevauthpath; +int maxprevauthpath = 0; +char* prevuser; +int maxprevuser = 0; +char* prevcryp; +int maxprevcryp = 0; +char* location; +char* header; +int maxlocation = 0; +char* temp; +int maxtemp = 0; +char* checked; +char* rest; +int maxchecked = 0, maxrest = 0; +int maxnames = 0; +char* names; +char** nameptrs; +char* name; +int maxname = 0; +char* rname; +int maxrname = 0; +char* encrname; +int maxencrname = 0; +char* buf; +int maxbuf = 0; +char* indexname; +int maxindexname = 0; #ifdef AUTH_FILE - static char* dirname; - static int maxdirname = 0; -#endif /* AUTH_FILE */ - static char* refhost = (char*) 0; - static int refhost_size = 0; - +char* dirname; +int maxdirname = 0; #endif +char* refhost = (char*) 0; +int refhost_size = 0; + + #ifdef ADVCOUNTER #include extern int UDSfd; @@ -229,15 +233,6 @@ static int reap_time; -void *rllc(void *ptr, size_t size) -{ - void *t; - t=(void *) malloc(size); - memcpy(t, ptr,sizeof(ptr)); - free(ptr); - return t; - -} static void @@ -1347,16 +1342,6 @@ { httpd_sockaddr sa; int sz; - /* - XXX this does not work as planned - make them global or sth like that, so they don't get fscked - up and allocated every time - shit - */ -#ifndef VHOST_MYSQL - static char* tempfilename; - static int maxtempfilename = 0; -#endif char* cp1; int len; #ifdef VHOST_DIRLEVELS @@ -1427,6 +1412,11 @@ if (tmp==-1) { /* not found , fall back to default method*/ + + /* XXX may be error404 shoud be sent instead of that? + it shoudn't mind in real life, because it shoudn't be found + if it's something more than a mere index.html + */ httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, strlen( hc->hostname ) ); (void) strcpy( hc->hostdir, hc->hostname ); @@ -1435,31 +1425,23 @@ { httpd_realloc_str(&hc->hostdir,&hc->maxhostdir,strlen(vh_list[tmp].path)); (void) strcpy (hc->hostdir,vh_list[tmp].path); - // shit, check if file is html!!! + ext=rindex(hc->origfilename,'.'); if ( ext==NULL) ext=hc->origfilename; else ext++; - // check if the extension is valid - if (! ((strcasecmp(ext,"html")==0) || - (strcasecmp(ext,"htm")==0) || - (strcasecmp(ext,"js")==0) || - (strcasecmp(ext,"jpg")==0) || - (strcasecmp(ext,"jpeg")==0) || - (strcasecmp(ext,"gif")==0) || - (strcasecmp(ext,"css")==0) || - (strcasecmp(ext,"png")==0) || - (strcasecmp(ext,"txt")==0) || - (strcasecmp(ext,"ico")==0) || - (strcasecmp(ext,"xml")==0) || - (strcasecmp(ext,"bmp")==0) )) - { - //deny the request - - return 0; - } - if ( ( hc->origfilename[strlen(hc->origfilename)-1]=='/') || (strcasecmp(ext,"htm")==0) - || (strcasecmp(ext,"html")==0) ) + /* + XXX this looks bad + there should be some way to make it look right + */ + + /* + Rules: If it ends with / (e.g. dirindex, if exists), .htm or .html, it should have + banners put. + */ + if ( ( hc->origfilename[strlen(hc->origfilename)-1]=='/') || + (strcasecmp(ext,"htm")==0) || + (strcasecmp(ext,"html")==0) ) { for (j=0;j maxbuf ) httpd_realloc_str( &buf, &maxbuf, size ); @@ -3490,15 +3456,9 @@ really_start_request( httpd_conn* hc, struct timeval* nowP ) { static const char* index_names[] = { INDEX_NAMES }; - int i; -#ifndef VHOST_MYSQL - static char* indexname; - static int maxindexname = 0; - -#ifdef AUTH_FILE - static char* dirname; - static int maxdirname = 0; -#endif /* AUTH_FILE */ + int i; +#ifdef VHOST_MYSQL + char *ext; #endif int expnlen, indxlen; char* cp; @@ -3510,7 +3470,8 @@ hc->method != METHOD_POST ) { httpd_send_err( - hc, 501, err501title, "", err501form, httpd_method_str( hc->method ) ); + hc, 501, err501title, "", err501form, httpd_method_str( hc->method ) ); + return -1; } @@ -3721,12 +3682,42 @@ hc->encodedurl ); return -1; } +#ifdef VHOST_MYSQL + + ext=rindex(hc->origfilename,'.'); + if ( ext==NULL) ext=hc->origfilename; + else ext++; + // check if the extension is valid + if (! ((strcasecmp(ext,"html")==0) || + (strcasecmp(ext,"htm")==0) || + (strcasecmp(ext,"js")==0) || + (strcasecmp(ext,"jpg")==0) || + (strcasecmp(ext,"jpeg")==0) || + (strcasecmp(ext,"gif")==0) || + (strcasecmp(ext,"css")==0) || + (strcasecmp(ext,"png")==0) || + (strcasecmp(ext,"txt")==0) || + (strcasecmp(ext,"ico")==0) || + (strcasecmp(ext,"xml")==0) || + (strcasecmp(ext,"bmp")==0) || + (hc->origfilename[strlen(hc->origfilename)-1]=='/'))) + { + //deny the request + httpd_send_err( + hc, 403, err403title, "", + ERROR_FORM( err403form, "The requested URL '%.80s' is forbidden.\n" ), + hc->encodedurl ); + return -1; + } + +#endif /* Fill in end_byte_loc, if necessary. */ if ( hc->got_range && ( hc->end_byte_loc == -1 || hc->end_byte_loc >= hc->sb.st_size ) ) hc->end_byte_loc = hc->sb.st_size - 1; + figure_mime( hc ); if ( hc->method == METHOD_HEAD ) @@ -3866,7 +3857,10 @@ hc->status, bytes, hc->referer, hc->useragent ); #else - char log_outp[512]; + /* + Let's not make the compiler to allocate memory every time for this buffer + */ + static char log_outp[512]; /* generate packet to be sent to the counter @@ -3877,7 +3871,10 @@ { if (connect(UDSfd, (struct sockaddr *) &UDSaddr, sizeof(UDSaddr)) < 0) { - log_errors++; + log_errors++; + /* + XXX should this be tuneable ? + */ if(log_errors==50000) { syslog(LOG_ERR,"Reconnection to counter failed, %s",strerror(errno)); @@ -3926,10 +3923,6 @@ char* cp1; char* cp2; char* cp3; -#ifndef VHOST_MYSQL - static char* refhost = (char*) 0; - static int refhost_size = 0; -#endif char *lp; hs = hc->hs; diff -urN thttpd-2.21-2/libhttpd.h thttpd-2.21-3/libhttpd.h --- thttpd-2.21-2/libhttpd.h Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-3/libhttpd.h Thu Nov 22 14:43:09 2001 @@ -46,8 +46,8 @@ #define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif #define NEW(t,n) ((t*) malloc( sizeof(t) * (n) )) -//#define RENEW(o,t,n) ((t*) realloc( (void*) o, sizeof(t) * (n) )) -#define RENEW(o,t,n) ((t*) rllc( (void*) o, sizeof(t) * (n) )) +#define RENEW(o,t,n) ((t*) realloc( (void*) o, sizeof(t) * (n) )) + @@ -138,9 +138,16 @@ int should_linger; struct stat sb; int conn_fd; + /* + XXX ? + Little modification to the standart way thttpd server files + We use file prt and file position, so we can serve it easily, + I haven't found any other convinietnt way with writev() .... + (Don't want to think what it would be without writev() + */ char* file_address; - char* banner, *banner_under; /* MYSQL_VHOST banners */ - off_t ban,ban_u; /* banner sizes... shit... */ + char* banner, *banner_under; + off_t ban,ban_u; off_t fsize; off_t fpos,bpos,bpos_u; } httpd_conn; @@ -181,7 +188,6 @@ /* Call to shut down. */ extern void httpd_terminate( httpd_server* hs ); -void *rllc(void *ptr, size_t sz); /* When a listen fd is ready to read, call this. It does the accept() and @@ -268,4 +274,3 @@ extern void httpd_logstats( long secs ); #endif /* _LIBHTTPD_H_ */ - diff -urN thttpd-2.21-2/thttpd.c thttpd-2.21-3/thttpd.c --- thttpd-2.21-2/thttpd.c Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-3/thttpd.c Thu Nov 22 14:43:09 2001 @@ -441,8 +441,7 @@ if (connect(UDSfd, (struct sockaddr *) &UDSaddr, sizeof(UDSaddr)) < 0) { - (void) fprintf( stderr, "error connecting to %s, %s\n",UDSPATH,strerror(errno)); -// exit( 1 ); + (void) fprintf( stderr, "error connecting to %s, %s\n",UDSPATH,strerror(errno)); } @@ -1473,9 +1472,10 @@ /* - fucked a lot by maniax - this really sucks ass, should be a bit rewriten and beautyfied - what bit... damn + XXX + In reallity, this works + it doesn't make it any prettier, and it should be rewriten , IMO + volunteers?:) */ static void @@ -1486,6 +1486,10 @@ time_t elapsed; httpd_conn* hc = c->hc; + /* XXX + REALLY fucked ifdefs + e.g. "Don't do this at home" + */ /* Do we need to write the headers first? */ #ifndef VHOST_MYSQL if ( hc->responselen == 0 ) @@ -1503,10 +1507,8 @@ */ /* - XXX - kur - po nqkkakuv nachin tuk trqbva da vkaram server-vaneto na bannerite - majko mila..... + XXX + watch the fun... */ #ifndef VHOST_MYSQL struct iovec iv[2]; @@ -1609,9 +1611,16 @@ c->hc->bytes_sent += sz; #ifdef VHOST_MYSQL + /* + That's the only good thing here + logic: use sz to find where we are in the writing - move the relevant positions, + and if we're finished with some file, don't fsck with it any mode. + sz=0 is needed for the next if's to go through. It shoud be simplier with goto, but + no, not today. + */ if ( (sz>=(hc->ban-hc->bpos)) || (hc->bpos==hc->ban)) { - // first banner served, no fscking with the pos + /* first banner served, no fscking with the pos */ sz -= (hc->ban-hc->bpos); hc->bpos=hc->ban; @@ -1620,7 +1629,7 @@ hc->bpos+=sz; sz=0; } - if ( (sz>=(hc->fsize-hc->fpos)) || (hc->fsize==hc->fpos)) // file is served already + if ( (sz>=(hc->fsize-hc->fpos)) || (hc->fsize==hc->fpos)) /* file is served already */ { sz-=(hc->fsize-hc->fpos); hc->fpos=hc->fsize; @@ -1630,7 +1639,7 @@ hc->fpos+=sz; sz=0; } - if ( (sz>=(hc->ban_u-hc->bpos_u)) || (hc->ban_u==hc->bpos_u)) // file is served already + if ( (sz>=(hc->ban_u-hc->bpos_u)) || (hc->ban_u==hc->bpos_u)) /* second banner is served already */ { sz-=(hc->ban_u-hc->bpos_u); hc->bpos_u=hc->ban_u; diff -urN thttpd-2.21-2/vhostconf.h thttpd-2.21-3/vhostconf.h --- thttpd-2.21-2/vhostconf.h Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-3/vhostconf.h Thu Nov 22 14:43:09 2001 @@ -45,10 +45,3 @@ struct node *vh_init_struct(int *n); struct banner *init_banners_list(int *n); int bin_search(struct node *tbl, int n,char *tosrch); - - - - - - -