Index: head/www/thttpd/Makefile =================================================================== --- head/www/thttpd/Makefile (revision 377326) +++ head/www/thttpd/Makefile (revision 377327) @@ -1,55 +1,48 @@ # Created by: Anders Nordby # $FreeBSD$ PORTNAME= thttpd -PORTVERSION= 2.25b -PORTREVISION= 6 +PORTVERSION= 2.26 CATEGORIES= www ipv6 -MASTER_SITES= http://www.acme.com/software/thttpd/ \ - http://atreides.freenix.no/~anders/ +MASTER_SITES= http://www.acme.com/software/thttpd/ MAINTAINER= danfe@FreeBSD.org COMMENT= Tiny/turbo/throttling HTTP server with CGI support +LICENSE= BSD2CLAUSE + USES= gmake # parallel builds (-jX) are broken with BSD make(1) GNU_CONFIGURE= yes +MAKE_ARGS= WEBDIR=${WWWDIR} USE_RC_SUBR= ${PORTNAME} SUB_FILES= pkg-message thttpd.conf.sample SUB_LIST= WWWOWN=${WWWOWN} WWWGRP=${WWWGRP} -OPTIONS_DEFINE= SENDFILE IPREAL -OPTIONS_DEFAULT= SENDFILE +OPTIONS_DEFINE= SENDFILE IPREAL INDEXES +OPTIONS_DEFAULT= SENDFILE IPREAL + SENDFILE_DESC= Use sendfile(2) to serve files IPREAL_DESC= Respect (pass on) "X-Forwarded-For" header +INDEXES_DESC= Generate index pages for directories SENDFILE_EXTRA_PATCHES= ${FILESDIR}/extra-patch-config.h IPREAL_EXTRA_PATCHES= ${FILESDIR}/extra-patch-ip_real +.include + post-patch: -.for f in extras/htpasswd.1 extras/htpasswd.c thttpd.8 extras/Makefile.in - @${REINPLACE_CMD} -e '/\.htpasswd/!s|htpasswd|thttpdpasswd|g' \ - ${WRKSRC}/${f} +# To avoid conflict with other ports that also install htpasswd(1) +.for f in extras/htpasswd.1 extras/htpasswd.c thttpd.8 + @${REINPLACE_CMD} -e '/\.htpasswd/!s|htpasswd|t&|g' ${WRKSRC}/${f} .endfor @${REINPLACE_CMD} -e 's|/var/www|${WWWDIR}|' \ ${WRKSRC}/extras/makeweb.1 - @${MV} ${WRKSRC}/extras/htpasswd.1 ${WRKSRC}/extras/thttpdpasswd.1 - @${MV} ${WRKSRC}/extras/htpasswd.c ${WRKSRC}/extras/thttpdpasswd.c +.if ! ${PORT_OPTIONS:MINDEXES} + @${REINPLACE_CMD} -e '/GENERATE_INDEXES/s|.*|/* & */|' \ + ${WRKSRC}/config.h +.endif -do-install: - ${INSTALL_PROGRAM} ${WRKSRC}/thttpd ${STAGEDIR}${PREFIX}/sbin - ${INSTALL_PROGRAM} ${WRKSRC}/extras/makeweb \ - ${WRKSRC}/extras/thttpdpasswd ${STAGEDIR}${PREFIX}/bin - ${INSTALL_SCRIPT} ${WRKSRC}/extras/syslogtocern \ - ${STAGEDIR}${PREFIX}/bin - @${MKDIR} ${STAGEDIR}${PREFIX}/www/data \ - ${STAGEDIR}${PREFIX}/www/cgi-bin - ${INSTALL_PROGRAM} ${WRKSRC}/cgi-src/redirect ${WRKSRC}/cgi-src/ssi \ - ${WRKSRC}/cgi-src/phf ${STAGEDIR}${PREFIX}/www/cgi-bin - ${INSTALL_MAN} ${WRKSRC}/extras/makeweb.1 \ - ${WRKSRC}/extras/thttpdpasswd.1 ${STAGEDIR}${PREFIX}/man/man1 - ${INSTALL_MAN} ${WRKSRC}/thttpd.8 ${WRKSRC}/cgi-src/redirect.8 \ - ${WRKSRC}/cgi-src/ssi.8 ${WRKSRC}/extras/syslogtocern.8 \ - ${STAGEDIR}${PREFIX}/man/man8 +post-install: ${INSTALL_DATA} ${WRKDIR}/thttpd.conf.sample ${STAGEDIR}${PREFIX}/etc .include Index: head/www/thttpd/distinfo =================================================================== --- head/www/thttpd/distinfo (revision 377326) +++ head/www/thttpd/distinfo (revision 377327) @@ -1,2 +1,2 @@ -SHA256 (thttpd-2.25b.tar.gz) = 07719b08b1cff6a21c08697a7bcb4395425b07ee753106262fb62a03a7d32360 -SIZE (thttpd-2.25b.tar.gz) = 132275 +SHA256 (thttpd-2.26.tar.gz) = 15b3f6c60f854061e333227e9ea9ff789d34a092c9365690a8c0d3ecfc85cbb7 +SIZE (thttpd-2.26.tar.gz) = 132950 Index: head/www/thttpd/files/patch-Makefile.in =================================================================== --- head/www/thttpd/files/patch-Makefile.in (revision 377326) +++ head/www/thttpd/files/patch-Makefile.in (revision 377327) @@ -1,52 +1,62 @@ --- Makefile.in.orig Tue Apr 24 19:21:06 2001 +++ Makefile.in Tue Apr 24 19:21:33 2001 @@ -47,7 +47,7 @@ CGIBINDIR = $(WEBDIR)/cgi-bin # You shouldn't need to edit anything below here. CC = @CC@ -CCOPT = @V_CCOPT@ +CCOPT = @CFLAGS@ DEFS = @DEFS@ INCLS = -I. CFLAGS = $(CCOPT) $(DEFS) $(INCLS) @@ -96,9 +96,7 @@ mime_types.h: mime_types.txt subdirs: for i in $(SUBDIRS) ; do ( \ - cd $$i ; \ - pwd ; \ - $(MAKE) $(MFLAGS) \ + $(MAKE) -C $$i $(MFLAGS) \ WEBDIR=$(WEBDIR) \ CGIBINDIR=$(CGIBINDIR) \ MANDIR=$(MANDIR) \ -@@ -118,9 +116,7 @@ install-man: +@@ -110,17 +108,15 @@ install: installthis install-man install + + installthis: + -mkdir -p $(DESTDIR)$(BINDIR) +- $(INSTALL) -m 555 -o bin -g bin thttpd $(DESTDIR)$(BINDIR) ++ $(INSTALL) -m 555 thttpd $(DESTDIR)$(BINDIR) + + install-man: + -mkdir -p $(DESTDIR)$(MANDIR)/man8 +- $(INSTALL) -m 444 -o bin -g bin thttpd.8 $(DESTDIR)$(MANDIR)/man8 ++ $(INSTALL) -m 444 thttpd.8 $(DESTDIR)$(MANDIR)/man8 installsubdirs: for i in $(SUBDIRS) ; do ( \ - cd $$i ; \ - pwd ; \ - $(MAKE) $(MFLAGS) \ + $(MAKE) -C $$i $(MFLAGS) \ WEBDIR=$(WEBDIR) \ CGIBINDIR=$(CGIBINDIR) \ MANDIR=$(MANDIR) \ @@ -137,16 +133,12 @@ distclean: distcleansubdirs cleansubdirs: for i in $(SUBDIRS) ; do ( \ - cd $$i ; \ - pwd ; \ - $(MAKE) $(MFLAGS) clean \ + $(MAKE) -C $$i $(MFLAGS) clean \ ) ; done distcleansubdirs: for i in $(SUBDIRS) ; do ( \ - cd $$i ; \ - pwd ; \ - $(MAKE) $(MFLAGS) distclean \ + $(MAKE) -C $$i $(MFLAGS) distclean \ ) ; done tags: Index: head/www/thttpd/files/patch-cgi-src_Makefile.in =================================================================== --- head/www/thttpd/files/patch-cgi-src_Makefile.in (revision 377326) +++ head/www/thttpd/files/patch-cgi-src_Makefile.in (revision 377327) @@ -1,11 +1,40 @@ --- cgi-src/Makefile.in.orig Tue Apr 24 19:44:12 2001 +++ cgi-src/Makefile.in Tue Apr 24 19:44:25 2001 @@ -31,7 +31,7 @@ MANDIR = @mandir@ CC = @CC@ -CCOPT = @V_CCOPT@ +CCOPT = @CFLAGS@ DEFS = @DEFS@ INCLS = -I.. CFLAGS = $(CCOPT) $(DEFS) $(INCLS) +@@ -67,17 +67,17 @@ + cd .. ; $(MAKE) $(MFLAGS) strerror.o + + install: all +- -mkdir -p $(CGIBINDIR) +- rm -f $(CGIBINDIR)/redirect +- cp redirect $(CGIBINDIR)/redirect +- rm -f $(MANDIR)/man8/redirect.8 +- cp redirect.8 $(MANDIR)/man8/redirect.8 +- rm -f $(CGIBINDIR)/ssi +- cp ssi $(CGIBINDIR)/ssi +- rm -f $(MANDIR)/man8/ssi.8 +- cp ssi.8 $(MANDIR)/man8/ssi.8 +- rm -f $(CGIBINDIR)/phf +- cp phf $(CGIBINDIR)/phf ++ -mkdir -p $(DESTDIR)$(CGIBINDIR) ++ rm -f $(DESTDIR)$(CGIBINDIR)/redirect ++ cp redirect $(DESTDIR)$(CGIBINDIR)/redirect ++ rm -f $(DESTDIR)$(MANDIR)/man8/redirect.8 ++ cp redirect.8 $(DESTDIR)$(MANDIR)/man8/redirect.8 ++ rm -f $(DESTDIR)$(CGIBINDIR)/ssi ++ cp ssi $(DESTDIR)$(CGIBINDIR)/ssi ++ rm -f $(DESTDIR)$(MANDIR)/man8/ssi.8 ++ cp ssi.8 $(DESTDIR)$(MANDIR)/man8/ssi.8 ++ rm -f $(DESTDIR)$(CGIBINDIR)/phf ++ cp phf $(DESTDIR)$(CGIBINDIR)/phf + + clean: + rm -f $(CLEANFILES) Index: head/www/thttpd/files/patch-extras_Makefile.in =================================================================== --- head/www/thttpd/files/patch-extras_Makefile.in (revision 377326) +++ head/www/thttpd/files/patch-extras_Makefile.in (revision 377327) @@ -1,11 +1,40 @@ --- extras/Makefile.in.orig Tue Apr 24 19:46:03 2001 +++ extras/Makefile.in Tue Apr 24 19:46:13 2001 @@ -32,7 +32,7 @@ MANDIR = @mandir@ CC = @CC@ -CCOPT = @V_CCOPT@ +CCOPT = @CFLAGS@ DEFS = @DEFS@ INCLS = -I.. CFLAGS = $(CCOPT) $(DEFS) $(INCLS) +@@ -66,18 +66,16 @@ + + + install: all +- rm -f $(BINDIR)/makeweb $(BINDIR)/htpasswd $(BINDIR)/syslogtocern +- cp makeweb $(BINDIR)/makeweb +- chgrp $(WEBGROUP) $(BINDIR)/makeweb +- chmod 2755 $(BINDIR)/makeweb +- cp htpasswd $(BINDIR)/htpasswd +- cp syslogtocern $(BINDIR)/syslogtocern +- rm -f $(MANDIR)/man1/makeweb.1 +- cp makeweb.1 $(MANDIR)/man1/makeweb.1 +- rm -f $(MANDIR)/man1/htpasswd.1 +- cp htpasswd.1 $(MANDIR)/man1/htpasswd.1 +- rm -f $(MANDIR)/man8/syslogtocern.8 +- cp syslogtocern.8 $(MANDIR)/man8/syslogtocern.8 ++ rm -f $(DESTDIR)$(BINDIR)/makeweb $(DESTDIR)$(BINDIR)/thtpasswd $(DESTDIR)$(BINDIR)/syslogtocern ++ cp makeweb $(DESTDIR)$(BINDIR)/makeweb ++ cp htpasswd $(DESTDIR)$(BINDIR)/thtpasswd ++ cp syslogtocern $(DESTDIR)$(BINDIR)/syslogtocern ++ rm -f $(DESTDIR)$(MANDIR)/man1/makeweb.1 ++ cp makeweb.1 $(DESTDIR)$(MANDIR)/man1/makeweb.1 ++ rm -f $(DESTDIR)$(MANDIR)/man1/thtpasswd.1 ++ cp htpasswd.1 $(DESTDIR)$(MANDIR)/man1/thtpasswd.1 ++ rm -f $(DESTDIR)$(MANDIR)/man8/syslogtocern.8 ++ cp syslogtocern.8 $(DESTDIR)$(MANDIR)/man8/syslogtocern.8 + + clean: + rm -f $(CLEANFILES) Index: head/www/thttpd/files/patch-extras_htpasswd.c =================================================================== --- head/www/thttpd/files/patch-extras_htpasswd.c (revision 377326) +++ head/www/thttpd/files/patch-extras_htpasswd.c (revision 377327) @@ -1,201 +1,201 @@ --- extras/htpasswd.c.orig 2001-12-19 00:08:08 UTC +++ extras/htpasswd.c @@ -21,7 +21,12 @@ extern char *crypt(const char *key, cons #define LF 10 #define CR 13 +#define CPW_LEN 13 + +/* ie 'string' + '\0' */ #define MAX_STRING_LEN 256 +/* ie 'maxstring' + ':' + cpassword */ +#define MAX_LINE_LEN MAX_STRING_LEN+1+CPW_LEN int tfd; char temp_template[] = "/tmp/htp.XXXXXX"; @@ -137,8 +142,9 @@ add_password( char* user, FILE* f ) } static void usage(void) { - fprintf(stderr,"Usage: htpasswd [-c] passwordfile username\n"); - fprintf(stderr,"The -c flag creates a new file.\n"); + fprintf(stderr,"Usage: htpasswd [-c] passwordfile username\n" + "The -c flag creates a new file.\n" + "Will prompt for password, unless given on stdin.\n"); exit(1); } @@ -151,51 +157,131 @@ void interrupted(int signo) { int main(int argc, char *argv[]) { FILE *tfp,*f; char user[MAX_STRING_LEN]; - char line[MAX_STRING_LEN]; - char l[MAX_STRING_LEN]; + char pwfilename[MAX_STRING_LEN]; + char line[MAX_LINE_LEN]; + char l[MAX_LINE_LEN]; char w[MAX_STRING_LEN]; char command[MAX_STRING_LEN]; - int found; + int found,u; tfd = -1; + u = 2; /* argv[u] is username, unless... */ signal(SIGINT,(void (*)(int))interrupted); if(argc == 4) { + u = 3; if(strcmp(argv[1],"-c")) usage(); + if((f=fopen(argv[2],"r")) != NULL) { + fclose(f); + fprintf(stderr, + "Password file %s already exists.\n" + "Delete it first, if you really want to overwrite it.\n", + argv[2]); + exit(1); + } + } else if(argc != 3) usage(); + /* check uname length; underlying system will take care of pwdfile + name too long */ + if (strlen(argv[u]) >= MAX_STRING_LEN) { + fprintf(stderr,"Username too long (max %i): %s\n", + MAX_STRING_LEN-1, argv[u]); + exit(1); + } + + if(argc == 4) { if(!(tfp = fopen(argv[2],"w"))) { fprintf(stderr,"Could not open passwd file %s for writing.\n", argv[2]); perror("fopen"); exit(1); } + if (strlen(argv[2]) > (sizeof(pwfilename) - 1)) { + fprintf(stderr, "%s: filename is too long\n", argv[0]); + exit(1); + } + if (((strchr(argv[2], ';')) != NULL) || ((strchr(argv[2], '>')) != NULL)) { + fprintf(stderr, "%s: filename contains an illegal character\n", + argv[0]); + exit(1); + } + if (strlen(argv[3]) > (sizeof(user) - 1)) { + fprintf(stderr, "%s: username is too long\n", argv[0], + sizeof(user) - 1); + exit(1); + } + if ((strchr(argv[3], ':')) != NULL) { + fprintf(stderr, "%s: username contains an illegal character\n", + argv[0]); + exit(1); + } printf("Adding password for %s.\n",argv[3]); add_password(argv[3],tfp); fclose(tfp); exit(0); - } else if(argc != 3) usage(); + } - tfd = mkstemp(temp_template); - if(!(tfp = fdopen(tfd,"w"))) { - fprintf(stderr,"Could not open temp file.\n"); + if (strlen(argv[1]) > (sizeof(pwfilename) - 1)) { + fprintf(stderr, "%s: filename is too long\n", argv[0]); + exit(1); + } + if (((strchr(argv[1], ';')) != NULL) || ((strchr(argv[1], '>')) != NULL)) { + fprintf(stderr, "%s: filename contains an illegal character\n", + argv[0]); + exit(1); + } + if (strlen(argv[2]) > (sizeof(user) - 1)) { + fprintf(stderr, "%s: username is too long\n", argv[0], + sizeof(user) - 1); + exit(1); + } + if ((strchr(argv[2], ':')) != NULL) { + fprintf(stderr, "%s: username contains an illegal character\n", + argv[0]); exit(1); } - if(!(f = fopen(argv[1],"r"))) { fprintf(stderr, "Could not open passwd file %s for reading.\n",argv[1]); fprintf(stderr,"Use -c option to create new one.\n"); exit(1); } + if(freopen(argv[1],"a",f) == NULL) { + fprintf(stderr, + "Could not open passwd file %s for writing!.\n" + "Changes would be lost.\n",argv[1]); + exit(1); + } + f = freopen(argv[1],"r",f); + + /* pwdfile is there, go on with tempfile now ... */ + tfd = mkstemp(temp_template); + if(!(tfp = fdopen(tfd,"w"))) { + fprintf(stderr,"Could not open temp file.\n"); + exit(1); + } + /* already checked for boflw ... */ strcpy(user,argv[2]); found = 0; -- while(!(getline(line,MAX_STRING_LEN,f))) { +- while(!(my_getline(line,MAX_STRING_LEN,f))) { + /* line we get is username:pwd, or possibly any other cruft */ -+ while(!(getline(line,MAX_LINE_LEN,f))) { ++ while(!(my_getline(line,MAX_LINE_LEN,f))) { + char *i; + if(found || (line[0] == '#') || (!line[0])) { putline(tfp,line); continue; } - strcpy(l,line); - getword(w,l,':'); + i = index(line,':'); + w[0] = '\0'; + /* actually, cpw is CPW_LEN chars and never null, hence ':' should + always be at line[strlen(line)-CPW_LEN-1] in a valid user:cpw line + Here though we may allow for pre-hancrafted pwdfile (!)... + But still need to check for length limits. + */ + if (i != 0 && i-line <= MAX_STRING_LEN-1) { + strcpy(l,line); + getword(w,l,':'); + } if(strcmp(user,w)) { putline(tfp,line); continue; @@ -210,10 +296,28 @@ int main(int argc, char *argv[]) { printf("Adding user %s\n",user); add_password(user,tfp); } + /* close, rewind & copy */ + fclose(f); + fclose(tfp); + f = fopen(argv[1],"w"); + if(f==NULL) { + fprintf(stderr,"Failed re-opening %s!?\n",argv[1]); + exit(1); + } + tfp = fopen(temp_template,"r"); + if(tfp==NULL) { + fprintf(stderr,"Failed re-opening tempfile!?\n"); + exit(1); + } + { + int c; + while((c=fgetc(tfp))!=EOF && !feof(tfp)) { + fputc(c,f); + /* fputc(c,stderr); */ + } + } fclose(f); fclose(tfp); - sprintf(command,"cp %s %s",temp_template,argv[1]); - system(command); unlink(temp_template); exit(0); } Index: head/www/thttpd/files/patch-libhttpd.c =================================================================== --- head/www/thttpd/files/patch-libhttpd.c (revision 377326) +++ head/www/thttpd/files/patch-libhttpd.c (revision 377327) @@ -1,30 +1,62 @@ --- libhttpd.c.orig Mon May 27 01:22:26 2002 +++ libhttpd.c Sun Oct 20 23:49:58 2002 @@ -1483,7 +1483,7 @@ httpd_realloc_str( &checked, &maxchecked, checkedlen ); (void) strcpy( checked, path ); /* Trim trailing slashes. */ - while ( checked[checkedlen - 1] == '/' ) + while ( checkedlen && checked[checkedlen - 1] == '/' ) { checked[checkedlen - 1] = '\0'; --checkedlen; @@ -1502,7 +1502,7 @@ restlen = strlen( path ); httpd_realloc_str( &rest, &maxrest, restlen ); (void) strcpy( rest, path ); - if ( rest[restlen - 1] == '/' ) + if ( restlen && rest[restlen - 1] == '/' ) rest[--restlen] = '\0'; /* trim trailing slash */ if ( ! tildemapped ) /* Remove any leading slashes. */ -@@ -3889,6 +3889,9 @@ +@@ -2348,8 +2348,11 @@ + { + int i; + i = strlen( hc->origfilename ) - strlen( hc->pathinfo ); +- if ( i > 0 && strcmp( &hc->origfilename[i], hc->pathinfo ) == 0 ) +- hc->origfilename[i - 1] = '\0'; ++ if ( strcmp( &hc->origfilename[i], hc->pathinfo ) == 0 ) ++ { ++ if ( i == 0 ) hc->origfilename[0] = '\0'; ++ else hc->origfilename[i - 1] = '\0'; ++ } + } + + /* If the expanded filename is an absolute path, check that it's still +@@ -2571,7 +2574,7 @@ + size_t ext_len, encodings_len; + int i, top, bot, mid; + int r; +- char* default_type = "text/plain; charset=%s"; ++ char* default_type = "application/octet-stream"; + + /* Peel off encoding extensions until there aren't any more. */ + n_me_indexes = 0; +@@ -3312,7 +3315,7 @@ + cp += strcspn( cp, " \t" ); + status = atoi( cp ); + } +- if ( ( cp = strstr( headers, "Location:" ) ) != (char*) 0 && ++ else if ( ( cp = strstr( headers, "Location:" ) ) != (char*) 0 && + cp < br && + ( cp == headers || *(cp-1) == '\012' ) ) + status = 302; +@@ -3889,6 +3892,9 @@ httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl ); return -1; } +#ifdef USE_SENDFILE + hc->file_fd = *((int *) hc->file_address); +#endif send_mime( hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size, hc->sb.st_mtime ); Index: head/www/thttpd/files/patch-thttpd.c =================================================================== --- head/www/thttpd/files/patch-thttpd.c (revision 377326) +++ head/www/thttpd/files/patch-thttpd.c (revision 377327) @@ -1,105 +1,105 @@ --- thttpd.c.orig Wed Jun 29 19:50:59 2005 +++ thttpd.c Sun Jun 17 21:30:11 2007 @@ -331,6 +331,7 @@ re_open_logfile( void ) { FILE* logfp; + int retchmod; if ( no_log || hs == (httpd_server*) 0 ) return; @@ -340,7 +341,8 @@ { syslog( LOG_NOTICE, "re-opening logfile" ); logfp = fopen( logfile, "a" ); - if ( logfp == (FILE*) 0 ) -+ retchmod = chmod( logfile, S_IRUSR|S_IWUSR ); ++ retchmod = chmod( logfile, S_IRUSR|S_IWUSR|S_IRGRP ); + if ( logfp == (FILE*) 0 || retchmod != 0 ) { syslog( LOG_CRIT, "re-opening %.80s - %m", logfile ); return; @@ -360,6 +362,7 @@ gid_t gid = 32767; char cwd[MAXPATHLEN+1]; FILE* logfp; + int retchmod; int num_ready; int cnum; connecttab* c; @@ -429,7 +432,8 @@ else { logfp = fopen( logfile, "a" ); - if ( logfp == (FILE*) 0 ) + retchmod = chmod( logfile, S_IRUSR|S_IWUSR|S_IRGRP ); + if ( logfp == (FILE*) 0 || retchmod != 0 ) { syslog( LOG_CRIT, "%.80s - %m", logfile ); perror( logfile ); @@ -1714,12 +1718,45 @@ if ( hc->responselen == 0 ) { /* No, just write the file. */ +#ifdef USE_SENDFILE + off_t sbytes; + + sz = sendfile( + hc->file_fd, hc->conn_fd, c->next_byte_index, + MIN( c->end_byte_index - c->next_byte_index, max_bytes ), + NULL, &sbytes, 0 ); + if (sz == -1 && errno == EAGAIN) + sz = sbytes > 0 ? sbytes : -1; + else if (sz == 0) + sz = sbytes; +#else sz = write( hc->conn_fd, &(hc->file_address[c->next_byte_index]), MIN( c->end_byte_index - c->next_byte_index, max_bytes ) ); +#endif } else { +#ifdef USE_SENDFILE + struct sf_hdtr sf; + struct iovec iv; + off_t sbytes; + + iv.iov_base = hc->response; + iv.iov_len = hc->responselen; + sf.headers = &iv; + sf.hdr_cnt = 1; + sf.trailers = NULL; + sf.trl_cnt = 0; + sz = sendfile( + hc->file_fd, hc->conn_fd, c->next_byte_index, + MIN( c->end_byte_index - c->next_byte_index, max_bytes ), + &sf, &sbytes, 0 ); + if (sz == -1 && errno == EAGAIN) + sz = sbytes > 0 ? sbytes : -1; + else if (sz == 0) + sz = sbytes; +#else /* Yes. We'll combine headers and file into a single writev(), ** hoping that this generates a single packet. */ @@ -1730,6 +1767,7 @@ iv[1].iov_base = &(hc->file_address[c->next_byte_index]); iv[1].iov_len = MIN( c->end_byte_index - c->next_byte_index, max_bytes ); sz = writev( hc->conn_fd, iv, 2 ); +#endif } if ( sz < 0 && errno == EINTR ) @@ -1777,7 +1815,11 @@ ** ** And ECONNRESET isn't interesting either. */ - if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET ) + if ( errno != EPIPE && errno != EINVAL && errno != ECONNRESET +#ifdef USE_SENDFILE + && errno != ENOTCONN +#endif + ) syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl ); clear_connection( c, tvP ); return; Index: head/www/thttpd/files/pkg-message.in =================================================================== --- head/www/thttpd/files/pkg-message.in (revision 377326) +++ head/www/thttpd/files/pkg-message.in (revision 377327) @@ -1,12 +1,12 @@ ----------------------------------------------------------------- If you want users to be able to create their own Web subdirectories off of the main web directory, you need to: 1. Add a group for www admins (e.g., "%%WWWGRP%%") - 2. chgrp thatgroup %%PREFIX%%/bin/makeweb %%PREFIX%%/www + 2. chgrp thatgroup %%PREFIX%%/bin/makeweb %%WWWDIR%% 3. chmod 2755 %%PREFIX%%/bin/makeweb 4. Tell users about makeweb(1) See http://www.acme.com/software/thttpd/notes.html for more detailed instructions. ----------------------------------------------------------------- Index: head/www/thttpd/files/thttpd.conf.sample.in =================================================================== --- head/www/thttpd/files/thttpd.conf.sample.in (revision 377326) +++ head/www/thttpd/files/thttpd.conf.sample.in (revision 377327) @@ -1,6 +1,6 @@ user=%%WWWOWN%% -dir=%%PREFIX%%/www/data +dir=%%WWWDIR%% chroot -cgipat=*.cgi +cgipat=/cgi-bin/* logfile=/var/log/thttpd.log pidfile=/var/run/thttpd.pid Index: head/www/thttpd/pkg-plist =================================================================== --- head/www/thttpd/pkg-plist (revision 377326) +++ head/www/thttpd/pkg-plist (revision 377327) @@ -1,16 +1,14 @@ -bin/thttpdpasswd -bin/makeweb -bin/syslogtocern @sample etc/thttpd.conf.sample man/man1/makeweb.1.gz -man/man1/thttpdpasswd.1.gz +man/man1/thtpasswd.1.gz man/man8/redirect.8.gz man/man8/ssi.8.gz man/man8/syslogtocern.8.gz man/man8/thttpd.8.gz +sbin/makeweb +sbin/syslogtocern sbin/thttpd -www/cgi-bin/phf -www/cgi-bin/redirect -www/cgi-bin/ssi -@dirrmtry www/cgi-bin -@dirrmtry www/data +sbin/thtpasswd +%%WWWDIR%%/cgi-bin/phf +%%WWWDIR%%/cgi-bin/redirect +%%WWWDIR%%/cgi-bin/ssi