diff options
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/httpd/CHANGES | 8 | ||||
| -rw-r--r-- | libexec/httpd/auth-bozo.c | 4 | ||||
| -rw-r--r-- | libexec/httpd/bozohttpd.8 | 9 | ||||
| -rw-r--r-- | libexec/httpd/bozohttpd.c | 12 | ||||
| -rw-r--r-- | libexec/httpd/bozohttpd.h | 4 | ||||
| -rw-r--r-- | libexec/httpd/cgi-bozo.c | 20 | ||||
| -rw-r--r-- | libexec/httpd/daemon-bozo.c | 81 |
7 files changed, 93 insertions, 45 deletions
diff --git a/libexec/httpd/CHANGES b/libexec/httpd/CHANGES index 8fc3172a5ae..fccb33fc0fa 100644 --- a/libexec/httpd/CHANGES +++ b/libexec/httpd/CHANGES @@ -1,4 +1,10 @@ -$eterna: CHANGES,v 1.65 2009/04/18 05:36:04 mrg Exp $ +$eterna: CHANGES,v 1.67 2009/04/18 11:42:39 mrg Exp $ + +changes since bozohttpd 20090417: + o avoid dying in daemon mode for some uncommon, but recoverable, errors + o close leaking file descriptors for CGI and daemon mode + o handle poll errors properly + o don't try to handle more than one request per process yet changes since bozohttpd 20080303: o make bozohttpd internally more modular, preparing the way diff --git a/libexec/httpd/auth-bozo.c b/libexec/httpd/auth-bozo.c index dc908452eac..6296d41a17d 100644 --- a/libexec/httpd/auth-bozo.c +++ b/libexec/httpd/auth-bozo.c @@ -1,6 +1,6 @@ -/* $NetBSD: auth-bozo.c,v 1.6 2009/04/18 07:38:40 mrg Exp $ */ +/* $NetBSD: auth-bozo.c,v 1.7 2009/04/18 21:22:03 mrg Exp $ */ -/* $eterna: auth-bozo.c,v 1.12 2009/04/17 22:52:19 mrg Exp $ */ +/* $eterna: auth-bozo.c,v 1.13 2009/04/18 07:38:56 mrg Exp $ */ /* * Copyright (c) 1997-2009 Matthew R. Green diff --git a/libexec/httpd/bozohttpd.8 b/libexec/httpd/bozohttpd.8 index cf2ea08a636..b55c8f20a9c 100644 --- a/libexec/httpd/bozohttpd.8 +++ b/libexec/httpd/bozohttpd.8 @@ -1,6 +1,6 @@ -.\" $NetBSD: bozohttpd.8,v 1.12 2009/04/18 12:35:51 wiz Exp $ +.\" $NetBSD: bozohttpd.8,v 1.13 2009/04/18 21:22:03 mrg Exp $ .\" -.\" $eterna: bozohttpd.8,v 1.84 2009/04/18 01:48:18 mrg Exp $ +.\" $eterna: bozohttpd.8,v 1.87 2009/04/18 20:53:58 mrg Exp $ .\" .\" Copyright (c) 1997-2009 Matthew R. Green .\" All rights reserved. @@ -141,6 +141,9 @@ If otherwise unspecified, the address used to bind is derived from the .Ar myname , which defaults to the name returned by .Xr gethostname 3 . +Only the last +.Fl i +option is used. .It Fl M Ar suffix type encoding encoding11 This option adds a new entry to the table that converts file suffixes to content type and encoding. @@ -450,7 +453,7 @@ The focus has always been simplicity and security, with minimal features and regular code audits. This manual documents .Nm -version 20090417. +version 20090418. .Sh AUTHORS .Nm was written by Matthew R. Green diff --git a/libexec/httpd/bozohttpd.c b/libexec/httpd/bozohttpd.c index bb32e781f53..334b2fa9435 100644 --- a/libexec/httpd/bozohttpd.c +++ b/libexec/httpd/bozohttpd.c @@ -1,6 +1,6 @@ -/* $NetBSD: bozohttpd.c,v 1.12 2009/04/18 07:28:24 mrg Exp $ */ +/* $NetBSD: bozohttpd.c,v 1.13 2009/04/18 21:22:03 mrg Exp $ */ -/* $eterna: bozohttpd.c,v 1.152 2009/04/18 05:36:04 mrg Exp $ */ +/* $eterna: bozohttpd.c,v 1.155 2009/04/18 20:53:58 mrg Exp $ */ /* * Copyright (c) 1997-2009 Matthew R. Green @@ -109,7 +109,7 @@ #define INDEX_HTML "index.html" #endif #ifndef SERVER_SOFTWARE -#define SERVER_SOFTWARE "bozohttpd/20090417" +#define SERVER_SOFTWARE "bozohttpd/20090418" #endif #ifndef DIRECT_ACCESS_FILE #define DIRECT_ACCESS_FILE ".bzdirect" @@ -532,7 +532,7 @@ main(int argc, char **argv) clean_request(request); return (0); } - } while (bflag); + } while (bflag && 0); return (0); } @@ -1454,8 +1454,10 @@ transform_request(http_req *request, int *isindex) if (auth_check(request, newfile)) goto bad_done; - if (strlen(newfile)) + if (strlen(newfile)) { + free(request->hr_file); request->hr_file = newfile; + } if (process_cgi(request)) return 0; diff --git a/libexec/httpd/bozohttpd.h b/libexec/httpd/bozohttpd.h index 03cdbdf6c6f..6f6fefdda32 100644 --- a/libexec/httpd/bozohttpd.h +++ b/libexec/httpd/bozohttpd.h @@ -1,6 +1,6 @@ -/* $NetBSD: bozohttpd.h,v 1.9 2009/04/18 07:37:08 mrg Exp $ */ +/* $NetBSD: bozohttpd.h,v 1.10 2009/04/18 21:22:03 mrg Exp $ */ -/* $eterna: bozohttpd.h,v 1.25 2009/04/18 05:36:04 mrg Exp $ */ +/* $eterna: bozohttpd.h,v 1.26 2009/04/18 07:38:56 mrg Exp $ */ /* * Copyright (c) 1997-2009 Matthew R. Green diff --git a/libexec/httpd/cgi-bozo.c b/libexec/httpd/cgi-bozo.c index fc281f7efa3..e333a61fe2c 100644 --- a/libexec/httpd/cgi-bozo.c +++ b/libexec/httpd/cgi-bozo.c @@ -1,6 +1,6 @@ -/* $NetBSD: cgi-bozo.c,v 1.12 2009/04/18 07:28:24 mrg Exp $ */ +/* $NetBSD: cgi-bozo.c,v 1.13 2009/04/18 21:22:03 mrg Exp $ */ -/* $eterna: cgi-bozo.c,v 1.28 2009/04/18 05:36:04 mrg Exp $ */ +/* $eterna: cgi-bozo.c,v 1.30 2009/04/18 12:39:28 mrg Exp $ */ /* * Copyright (c) 1997-2009 Matthew R. Green @@ -43,6 +43,7 @@ #include <signal.h> #include <stdlib.h> #include <string.h> +#include <syslog.h> #include <unistd.h> #include <netinet/in.h> @@ -121,6 +122,7 @@ process_cgi(http_req *request) cgihandler = NULL; command = NULL; info = NULL; + len = strlen(url); if (auth_check(request, url + 1)) @@ -180,9 +182,6 @@ process_cgi(http_req *request) auth_cgi_count(request) + (request->hr_serverport && *request->hr_serverport ? 1 : 0); - debug((DEBUG_FAT, - "process_cgi: envpsize `%d'", envpsize)); - envp = bozomalloc(sizeof(*envp) * envpsize); for (ix = 0; ix < envpsize; ix++) envp[ix] = NULL; @@ -209,7 +208,7 @@ process_cgi(http_req *request) spsetenv(env, headp->h_value, curenvp++); free(env); } - + #ifndef _PATH_DEFPATH #define _PATH_DEFPATH "/usr/bin:/bin" #endif @@ -263,12 +262,13 @@ process_cgi(http_req *request) close(sv[0]); dup2(sv[1], STDIN_FILENO); dup2(sv[1], STDOUT_FILENO); - - debug((DEBUG_FAT, "process_cgi: going exec %s, %s %s %s", - path, argv[0], strornull(argv[1]), strornull(argv[2]))); + close(2); + close(sv[1]); + closelog(); if (-1 == execve(path, argv, envp)) - error(1, "child exec failed: %s", path); + error(1, "child exec failed: %s: %s", + path, strerror(errno)); /* NOT REACHED */ error(1, "child execve returned?!"); } diff --git a/libexec/httpd/daemon-bozo.c b/libexec/httpd/daemon-bozo.c index 20ac69c4dfa..d3636c045b8 100644 --- a/libexec/httpd/daemon-bozo.c +++ b/libexec/httpd/daemon-bozo.c @@ -1,6 +1,6 @@ -/* $NetBSD: daemon-bozo.c,v 1.5 2009/04/18 07:28:24 mrg Exp $ */ +/* $NetBSD: daemon-bozo.c,v 1.6 2009/04/18 21:22:03 mrg Exp $ */ -/* $eterna: daemon-bozo.c,v 1.13 2009/04/17 22:52:20 mrg Exp $ */ +/* $eterna: daemon-bozo.c,v 1.16 2009/04/18 13:06:45 mrg Exp $ */ /* * Copyright (c) 1997-2009 Matthew R. Green @@ -120,12 +120,7 @@ void daemon_fork() { struct pollfd *fds = NULL; - - while (bflag) { - struct sockaddr_storage ss; - socklen_t slen; - int fd; - int i; + int i, j; #ifndef POLLRDNORM #define POLLRDNORM 0 @@ -136,14 +131,23 @@ daemon_fork() #ifndef INFTIM #define INFTIM -1 #endif - if (fds == NULL) { - fds = bozomalloc(nsock * sizeof *fds); - for (i = 0; i < nsock; i++) { - fds[i].events = POLLIN | POLLPRI | POLLRDNORM | - POLLRDBAND | POLLERR; - fds[i].fd = sock[i]; - } - } + + fds = bozomalloc(nsock * sizeof *fds); + for (i = 0; i < nsock; i++) { + if (sock[i] == -1) + continue; + fds[i].events = POLLIN | POLLPRI | POLLRDNORM | + POLLRDBAND | POLLERR; + fds[i].fd = sock[i]; + } + + while (bflag) { + struct sockaddr_storage ss; + socklen_t slen; + int fd; + + if (nsock == 0) + exit(0); /* * wait for a connection, then fork() and return NULL in @@ -153,25 +157,53 @@ daemon_fork() */ again: if (poll(fds, nsock, INFTIM) == -1) { - if (errno != EINTR) + /* fail on programmer errors */ + if (errno == EFAULT || + errno == EINVAL) error(1, "poll: %s", strerror(errno)); + + /* sleep on some temporary kernel failures */ + if (errno == ENOMEM || + errno == EAGAIN) + sleep(1); + goto again; } for (i = 0; i < nsock; i++) { if (fds[i].revents & (POLLNVAL|POLLERR|POLLHUP)) { - warning("poll on fd %d: %s", fds[i].fd, - strerror(errno)); - continue; + warning("poll on fd %d pid %d revents %d: %s", + fds[i].fd, getpid(), fds[i].revents, strerror(errno)); + warning("nsock = %d", nsock); + close(sock[i]); + nsock--; + warning("nsock now = %d", nsock); + /* no sockets left */ + if (nsock == 0) + exit(0); + /* last socket; easy case */ + if (nsock == i) + break; + memmove(&fds[i], &fds[i+i], + (nsock - i) * sizeof(*fds)); + memmove(&sock[i], &sock[i+i], + (nsock - i) * sizeof(*sock)); + break; } if (fds[i].revents == 0) continue; slen = sizeof(ss); - fd = accept(sock[i], (struct sockaddr *)&ss, &slen); + fd = accept(fds[i].fd, (struct sockaddr *)&ss, &slen); if (fd == -1) { - if (errno != EAGAIN) + if (errno == EFAULT || + errno == EINVAL) error(1, "accept: %s", strerror(errno)); + + if (errno == ENOMEM || + errno == EAGAIN) + sleep(1); + continue; } switch (fork()) { @@ -187,7 +219,11 @@ again: dup2(fd, 0); dup2(fd, 1); /*dup2(fd, 2);*/ + free(fds); + free(sock); close(fd); + for (j = 0; j < nsock; j++) + close(sock[j]); return; default: /* parent */ @@ -196,6 +232,7 @@ again: } } } + free(fds); } #endif /* NO_DAEMON_MODE */ |
