Adds a -u option to prevent dropping to user none Logs 404 requests Notes: Wed Jan 20 15:52:01 EST 2010 geoff auth/none in auth(8) will let you kill an httpd running as none. Reference: /n/sources/patch/sorry/httpd-none Date: Wed Jan 20 19:55:10 CET 2010 Signed-off-by: matt@proweb.co.uk Reviewed-by: geoff --- /sys/src/cmd/ip/httpd/httpd.c Wed Jan 20 19:45:07 2010 +++ /sys/src/cmd/ip/httpd/httpd.c Wed Jan 20 19:44:33 2010 @@ -38,8 +38,7 @@ void usage(void) { - fprint(2, "usage: httpd [-c certificate] [-C CAchain] [-a srvaddress] " - "[-d domain] [-n namespace] [-w webroot]\n"); + fprint(2, "usage: httpd [-N] [-c certificate] [-C CAchain] [-a srvaddress] [-d domain] [-n namespace] [-w webroot] \n"); exits("usage"); } @@ -47,6 +46,7 @@ main(int argc, char **argv) { char *address; + int gonone = 1; namespace = nil; address = nil; @@ -66,6 +66,9 @@ if (certchain == nil) sysfatal("reading certificate chain: %r"); break; + case 'u' : + gonone = 0; + break; case 'n': namespace = EARGF(usage()); break; @@ -122,7 +125,8 @@ urlinit(); statsinit(); - becomenone(namespace); + if(gonone) + becomenone(namespace); dolisten(netmkaddr(address, "tcp", certificate == nil ? "http" : "https")); exits(nil); } @@ -324,7 +328,7 @@ newuri = nil; }else newuri = redirect(c, origuri, &flags); - + if(newuri != nil){ if(flags & Redirsilent) { c->req.uri = uri = newuri; @@ -398,10 +402,8 @@ char *w, *w2, *p, *masque; int fd, fd1, n, force301, ok; -/* if(c->req.search) return hfail(c, HNoSearch, c->req.uri); - */ if(strcmp(c->req.meth, "GET") != 0 && strcmp(c->req.meth, "HEAD") != 0) return hunallowed(c, "GET, HEAD"); if(c->head.expectother || c->head.expectcont) @@ -448,8 +450,12 @@ strcat(w, c->req.uri); fd = open(w, OREAD); } - if(fd < 0) + + if(fd < 0) { // tell someone what we didn't find + syslog(0, HTTPLOG, "%r: %s", w); return notfound(c, c->req.uri); + } + dir = dirfstat(fd); if(dir == nil){ close(fd); --- /sys/man/8/httpd Wed Jan 20 19:45:47 2010 +++ /sys/man/8/httpd Wed Jan 20 19:45:19 2010 @@ -3,6 +3,7 @@ httpd, mirror, save, imagemap, man2html, webls \- HTTP server .SH SYNOPSIS .B ip/httpd/httpd +.RB [ -u ] .RB [ -a .IR srvaddr ] .RB [ -c @@ -95,7 +96,10 @@ .I srvaddr (default .BR tcp!*!http ), -and listens for incoming calls. +and listens for incoming calls as user none unless +.B -u +is specified on the command line in which case it as +as the current user. If an X.509 certificate is supplied with the .B -c option, then the service is instead