Sat Apr 18 21:22:03 2009 UTC ()
merge bozohttpd 20090418.  remove a couple of minor do-nothing local
changes that don't need to cause conflicts.


(mrg)
diff -r1.3 -r1.4 src/libexec/httpd/CHANGES
diff -r1.6 -r1.7 src/libexec/httpd/auth-bozo.c
diff -r1.12 -r1.13 src/libexec/httpd/bozohttpd.8
diff -r1.12 -r1.13 src/libexec/httpd/bozohttpd.c
diff -r1.12 -r1.13 src/libexec/httpd/cgi-bozo.c
diff -r1.9 -r1.10 src/libexec/httpd/bozohttpd.h
diff -r1.5 -r1.6 src/libexec/httpd/daemon-bozo.c

cvs diff -r1.3 -r1.4 src/libexec/httpd/CHANGES (expand / switch to unified diff)

--- src/libexec/httpd/CHANGES 2009/04/18 07:48:02 1.3
+++ src/libexec/httpd/CHANGES 2009/04/18 21:22:03 1.4
@@ -1,14 +1,20 @@ @@ -1,14 +1,20 @@
1$eterna: CHANGES,v 1.65 2009/04/18 05:36:04 mrg Exp $ 1$eterna: CHANGES,v 1.67 2009/04/18 11:42:39 mrg Exp $
 2
 3changes since bozohttpd 20090417:
 4 o avoid dying in daemon mode for some uncommon, but recoverable, errors
 5 o close leaking file descriptors for CGI and daemon mode
 6 o handle poll errors properly
 7 o don't try to handle more than one request per process yet
2 8
3changes since bozohttpd 20080303: 9changes since bozohttpd 20080303:
4 o make bozohttpd internally more modular, preparing the way 10 o make bozohttpd internally more modular, preparing the way
5 to handle more than one request per process 11 to handle more than one request per process
6 o fix http-auth, set $REMOTE_USER not $REMOTEUSER. also fix 12 o fix http-auth, set $REMOTE_USER not $REMOTEUSER. also fix
7 cgi-bin with cvsweb, from Holger Weiss <holger@CIS.FU-Berlin.DE> 13 cgi-bin with cvsweb, from Holger Weiss <holger@CIS.FU-Berlin.DE>
8 o fix an uninitialised variable use in daemon mode 14 o fix an uninitialised variable use in daemon mode
9 o fix ssl mode with newer OpenSSL 15 o fix ssl mode with newer OpenSSL
10 o mmap large files in manageable sizes so we can serve any size file 16 o mmap large files in manageable sizes so we can serve any size file
11 o refactor url processing to handle query strings correctly for CGI 17 o refactor url processing to handle query strings correctly for CGI
12 from Sergey Katsev at Coyote Point 18 from Sergey Katsev at Coyote Point
13 o add If-Modified-Since support, from Joerg Sonnenberger 19 o add If-Modified-Since support, from Joerg Sonnenberger
14 <joerg@netbsd.org> 20 <joerg@netbsd.org>

cvs diff -r1.6 -r1.7 src/libexec/httpd/auth-bozo.c (expand / switch to unified diff)

--- src/libexec/httpd/auth-bozo.c 2009/04/18 07:38:40 1.6
+++ src/libexec/httpd/auth-bozo.c 2009/04/18 21:22:03 1.7
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: auth-bozo.c,v 1.6 2009/04/18 07:38:40 mrg Exp $ */ 1/* $NetBSD: auth-bozo.c,v 1.7 2009/04/18 21:22:03 mrg Exp $ */
2 2
3/* $eterna: auth-bozo.c,v 1.12 2009/04/17 22:52:19 mrg Exp $ */ 3/* $eterna: auth-bozo.c,v 1.13 2009/04/18 07:38:56 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2009 Matthew R. Green 6 * Copyright (c) 1997-2009 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and 15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided 16 * dedication in the documentation and/or other materials provided

cvs diff -r1.12 -r1.13 src/libexec/httpd/bozohttpd.8 (expand / switch to unified diff)

--- src/libexec/httpd/bozohttpd.8 2009/04/18 12:35:51 1.12
+++ src/libexec/httpd/bozohttpd.8 2009/04/18 21:22:03 1.13
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1.\" $NetBSD: bozohttpd.8,v 1.12 2009/04/18 12:35:51 wiz Exp $ 1.\" $NetBSD: bozohttpd.8,v 1.13 2009/04/18 21:22:03 mrg Exp $
2.\" 2.\"
3.\" $eterna: bozohttpd.8,v 1.84 2009/04/18 01:48:18 mrg Exp $ 3.\" $eterna: bozohttpd.8,v 1.87 2009/04/18 20:53:58 mrg Exp $
4.\" 4.\"
5.\" Copyright (c) 1997-2009 Matthew R. Green 5.\" Copyright (c) 1997-2009 Matthew R. Green
6.\" All rights reserved. 6.\" All rights reserved.
7.\" 7.\"
8.\" Redistribution and use in source and binary forms, with or without 8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions 9.\" modification, are permitted provided that the following conditions
10.\" are met: 10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright 11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer. 12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution. 15.\" documentation and/or other materials provided with the distribution.
16.\" 16.\"
@@ -131,26 +131,29 @@ The default is the @@ -131,26 +131,29 @@ The default is the
131.Dq http 131.Dq http
132port. 132port.
133.It Fl i Ar address 133.It Fl i Ar address
134This option is only valid with the 134This option is only valid with the
135.Fl b 135.Fl b
136option. 136option.
137It causes 137It causes
138.Ar address 138.Ar address
139to use used as the address to bind daemon mode. 139to use used as the address to bind daemon mode.
140If otherwise unspecified, the address used to bind is derived from the 140If otherwise unspecified, the address used to bind is derived from the
141.Ar myname , 141.Ar myname ,
142which defaults to the name returned by 142which defaults to the name returned by
143.Xr gethostname 3 . 143.Xr gethostname 3 .
 144Only the last
 145.Fl i
 146option is used.
144.It Fl M Ar suffix type encoding encoding11 147.It Fl M Ar suffix type encoding encoding11
145This option adds a new entry to the table that converts file suffixes to 148This option adds a new entry to the table that converts file suffixes to
146content type and encoding. 149content type and encoding.
147This option takes four additional arguments containing 150This option takes four additional arguments containing
148the file prefix, its 151the file prefix, its
149.Dq Content-Type , 152.Dq Content-Type ,
150.Dq Content-Encoding , 153.Dq Content-Encoding ,
151and 154and
152.Dq Content-Encoding 155.Dq Content-Encoding
153for HTTP/1.1 connections, respectively. 156for HTTP/1.1 connections, respectively.
154If any of these are a single dash 157If any of these are a single dash
155.Pq Dq - , 158.Pq Dq - ,
156the empty string is used instead. 159the empty string is used instead.
@@ -440,27 +443,27 @@ program is actually called @@ -440,27 +443,27 @@ program is actually called
440.Dq bozohttpd . 443.Dq bozohttpd .
441It was first written in perl, based on another perl http server 444It was first written in perl, based on another perl http server
442called 445called
443.Dq tinyhttpd . 446.Dq tinyhttpd .
444It was then rewritten from scratch in perl, and then once again in C. 447It was then rewritten from scratch in perl, and then once again in C.
445From 448From
446.Dq bozohttpd 449.Dq bozohttpd
447version 20060517, it has been integrated into 450version 20060517, it has been integrated into
448.Nx . 451.Nx .
449The focus has always been simplicity and security, with minimal features 452The focus has always been simplicity and security, with minimal features
450and regular code audits. 453and regular code audits.
451This manual documents 454This manual documents
452.Nm 455.Nm
453version 20090417. 456version 20090418.
454.Sh AUTHORS 457.Sh AUTHORS
455.Nm 458.Nm
456was written by Matthew R. Green 459was written by Matthew R. Green
457.Aq mrg@eterna.com.au . 460.Aq mrg@eterna.com.au .
458.Pp 461.Pp
459The large list of contributors includes: 462The large list of contributors includes:
460.Bl -dash 463.Bl -dash
461.It 464.It
462Arnaud Lacombe 465Arnaud Lacombe
463.Aq alc@netbsd.org 466.Aq alc@netbsd.org
464provided some clean up for memory leaks 467provided some clean up for memory leaks
465.It 468.It
466Christoph Badura 469Christoph Badura

cvs diff -r1.12 -r1.13 src/libexec/httpd/bozohttpd.c (expand / switch to unified diff)

--- src/libexec/httpd/bozohttpd.c 2009/04/18 07:28:24 1.12
+++ src/libexec/httpd/bozohttpd.c 2009/04/18 21:22:03 1.13
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: bozohttpd.c,v 1.12 2009/04/18 07:28:24 mrg Exp $ */ 1/* $NetBSD: bozohttpd.c,v 1.13 2009/04/18 21:22:03 mrg Exp $ */
2 2
3/* $eterna: bozohttpd.c,v 1.152 2009/04/18 05:36:04 mrg Exp $ */ 3/* $eterna: bozohttpd.c,v 1.155 2009/04/18 20:53:58 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2009 Matthew R. Green 6 * Copyright (c) 1997-2009 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and 15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided 16 * dedication in the documentation and/or other materials provided
@@ -99,27 +99,27 @@ @@ -99,27 +99,27 @@
99 * - 14.9: we aren't a cache. 99 * - 14.9: we aren't a cache.
100 * 100 *
101 * - 14.15: content-md5 would be nice... 101 * - 14.15: content-md5 would be nice...
102 *  102 *
103 * - 14.24/14.26/14.27: be nice to support this... 103 * - 14.24/14.26/14.27: be nice to support this...
104 * 104 *
105 * - 14.44: not sure about this Vary: header. ignore it for now. 105 * - 14.44: not sure about this Vary: header. ignore it for now.
106 */ 106 */
107 107
108#ifndef INDEX_HTML 108#ifndef INDEX_HTML
109#define INDEX_HTML "index.html" 109#define INDEX_HTML "index.html"
110#endif 110#endif
111#ifndef SERVER_SOFTWARE 111#ifndef SERVER_SOFTWARE
112#define SERVER_SOFTWARE "bozohttpd/20090417" 112#define SERVER_SOFTWARE "bozohttpd/20090418"
113#endif 113#endif
114#ifndef DIRECT_ACCESS_FILE 114#ifndef DIRECT_ACCESS_FILE
115#define DIRECT_ACCESS_FILE ".bzdirect" 115#define DIRECT_ACCESS_FILE ".bzdirect"
116#endif 116#endif
117#ifndef REDIRECT_FILE 117#ifndef REDIRECT_FILE
118#define REDIRECT_FILE ".bzredirect" 118#define REDIRECT_FILE ".bzredirect"
119#endif 119#endif
120#ifndef ABSREDIRECT_FILE 120#ifndef ABSREDIRECT_FILE
121#define ABSREDIRECT_FILE ".bzabsredirect" 121#define ABSREDIRECT_FILE ".bzabsredirect"
122#endif 122#endif
123 123
124/* 124/*
125 * And so it begins .. 125 * And so it begins ..
@@ -522,27 +522,27 @@ main(int argc, char **argv) @@ -522,27 +522,27 @@ main(int argc, char **argv)
522 if (chdir("/") == -1) 522 if (chdir("/") == -1)
523 error(1, "chdir /: %s", strerror(errno)); 523 error(1, "chdir /: %s", strerror(errno));
524 524
525 /* 525 /*
526 * read and process the HTTP request. 526 * read and process the HTTP request.
527 */ 527 */
528 do { 528 do {
529 request = read_request(); 529 request = read_request();
530 if (request) { 530 if (request) {
531 process_request(request); 531 process_request(request);
532 clean_request(request); 532 clean_request(request);
533 return (0); 533 return (0);
534 } 534 }
535 } while (bflag); 535 } while (bflag && 0);
536 536
537 return (0); 537 return (0);
538} 538}
539 539
540char * 540char *
541http_date(void) 541http_date(void)
542{ 542{
543 static char date[40]; 543 static char date[40];
544 struct tm *tm; 544 struct tm *tm;
545 time_t now; 545 time_t now;
546 546
547 /* Sun, 06 Nov 1994 08:49:37 GMT */ 547 /* Sun, 06 Nov 1994 08:49:37 GMT */
548 now = time(NULL); 548 now = time(NULL);
@@ -1444,28 +1444,30 @@ transform_request(http_req *request, int @@ -1444,28 +1444,30 @@ transform_request(http_req *request, int
1444 * 1444 *
1445 * XXX true security only comes from our parent using chroot(2) 1445 * XXX true security only comes from our parent using chroot(2)
1446 * before execve(2)'ing us. or our own built in chroot(2) support. 1446 * before execve(2)'ing us. or our own built in chroot(2) support.
1447 */ 1447 */
1448 if (*newfile == '/' || strcmp(newfile, "..") == 0 || 1448 if (*newfile == '/' || strcmp(newfile, "..") == 0 ||
1449 strstr(newfile, "/..") || strstr(newfile, "../")) { 1449 strstr(newfile, "/..") || strstr(newfile, "../")) {
1450 (void)http_error(403, request, "illegal request"); 1450 (void)http_error(403, request, "illegal request");
1451 goto bad_done; 1451 goto bad_done;
1452 } 1452 }
1453 1453
1454 if (auth_check(request, newfile)) 1454 if (auth_check(request, newfile))
1455 goto bad_done; 1455 goto bad_done;
1456 1456
1457 if (strlen(newfile)) 1457 if (strlen(newfile)) {
 1458 free(request->hr_file);
1458 request->hr_file = newfile; 1459 request->hr_file = newfile;
 1460 }
1459 1461
1460 if (process_cgi(request)) 1462 if (process_cgi(request))
1461 return 0; 1463 return 0;
1462 1464
1463 debug((DEBUG_FAT, "transform_request set: %s", newfile)); 1465 debug((DEBUG_FAT, "transform_request set: %s", newfile));
1464 return 1; 1466 return 1;
1465bad_done: 1467bad_done:
1466 debug((DEBUG_FAT, "transform_request returning: 0")); 1468 debug((DEBUG_FAT, "transform_request returning: 0"));
1467 if (newfile) 1469 if (newfile)
1468 free(newfile); 1470 free(newfile);
1469 return 0; 1471 return 0;
1470} 1472}
1471 1473

cvs diff -r1.12 -r1.13 src/libexec/httpd/cgi-bozo.c (expand / switch to unified diff)

--- src/libexec/httpd/cgi-bozo.c 2009/04/18 07:28:24 1.12
+++ src/libexec/httpd/cgi-bozo.c 2009/04/18 21:22:03 1.13
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: cgi-bozo.c,v 1.12 2009/04/18 07:28:24 mrg Exp $ */ 1/* $NetBSD: cgi-bozo.c,v 1.13 2009/04/18 21:22:03 mrg Exp $ */
2 2
3/* $eterna: cgi-bozo.c,v 1.28 2009/04/18 05:36:04 mrg Exp $ */ 3/* $eterna: cgi-bozo.c,v 1.30 2009/04/18 12:39:28 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2009 Matthew R. Green 6 * Copyright (c) 1997-2009 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and 15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided 16 * dedication in the documentation and/or other materials provided
@@ -33,26 +33,27 @@ @@ -33,26 +33,27 @@
33/* this code implements CGI/1.2 for bozohttpd */ 33/* this code implements CGI/1.2 for bozohttpd */
34 34
35#ifndef NO_CGIBIN_SUPPORT 35#ifndef NO_CGIBIN_SUPPORT
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/socket.h> 38#include <sys/socket.h>
39 39
40#include <ctype.h> 40#include <ctype.h>
41#include <errno.h> 41#include <errno.h>
42#include <paths.h> 42#include <paths.h>
43#include <signal.h> 43#include <signal.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
 46#include <syslog.h>
46#include <unistd.h> 47#include <unistd.h>
47 48
48#include <netinet/in.h> 49#include <netinet/in.h>
49 50
50#include "bozohttpd.h" 51#include "bozohttpd.h"
51 52
52#define CGIBIN_PREFIX "cgi-bin/" 53#define CGIBIN_PREFIX "cgi-bin/"
53#define CGIBIN_PREFIX_LEN (sizeof(CGIBIN_PREFIX)-1) 54#define CGIBIN_PREFIX_LEN (sizeof(CGIBIN_PREFIX)-1)
54 55
55static char *cgibin; /* cgi-bin directory */ 56static char *cgibin; /* cgi-bin directory */
56static int Cflag; /* added a cgi handler, always process_cgi() */ 57static int Cflag; /* added a cgi handler, always process_cgi() */
57 58
58static const char * content_cgihandler(http_req *, const char *); 59static const char * content_cgihandler(http_req *, const char *);
@@ -111,26 +112,27 @@ process_cgi(http_req *request) @@ -111,26 +112,27 @@ process_cgi(http_req *request)
111 else 112 else
112 query = NULL; 113 query = NULL;
113 114
114 asprintf(&url, "%s%s%s", file, query ? "?" : "", query ? query : ""); 115 asprintf(&url, "%s%s%s", file, query ? "?" : "", query ? query : "");
115 if (url == NULL) 116 if (url == NULL)
116 goto out; 117 goto out;
117 debug((DEBUG_NORMAL, "process_cgi: url `%s'", url)); 118 debug((DEBUG_NORMAL, "process_cgi: url `%s'", url));
118 119
119 path = NULL; 120 path = NULL;
120 envp = NULL; 121 envp = NULL;
121 cgihandler = NULL; 122 cgihandler = NULL;
122 command = NULL; 123 command = NULL;
123 info = NULL; 124 info = NULL;
 125
124 len = strlen(url); 126 len = strlen(url);
125 127
126 if (auth_check(request, url + 1)) 128 if (auth_check(request, url + 1))
127 goto out; 129 goto out;
128 130
129 if (!cgibin || strncmp(url + 1, CGIBIN_PREFIX, CGIBIN_PREFIX_LEN) != 0) { 131 if (!cgibin || strncmp(url + 1, CGIBIN_PREFIX, CGIBIN_PREFIX_LEN) != 0) {
130 cgihandler = content_cgihandler(request, file + 1); 132 cgihandler = content_cgihandler(request, file + 1);
131 if (cgihandler == NULL) { 133 if (cgihandler == NULL) {
132 debug((DEBUG_FAT, "process_cgi: no handler, returning")); 134 debug((DEBUG_FAT, "process_cgi: no handler, returning"));
133 goto out; 135 goto out;
134 } 136 }
135 if (len == 0 || file[len - 1] == '/') 137 if (len == 0 || file[len - 1] == '/')
136 append_index_html(&file); 138 append_index_html(&file);
@@ -170,56 +172,53 @@ process_cgi(http_req *request) @@ -170,56 +172,53 @@ process_cgi(http_req *request)
170 type = request->hr_content_type; 172 type = request->hr_content_type;
171 clen = request->hr_content_length; 173 clen = request->hr_content_length;
172 174
173 envpsize = 13 + request->hr_nheaders +  175 envpsize = 13 + request->hr_nheaders +
174 (info && *info ? 1 : 0) + 176 (info && *info ? 1 : 0) +
175 (query && *query ? 1 : 0) + 177 (query && *query ? 1 : 0) +
176 (type && *type ? 1 : 0) + 178 (type && *type ? 1 : 0) +
177 (clen && *clen ? 1 : 0) + 179 (clen && *clen ? 1 : 0) +
178 (request->hr_remotehost && *request->hr_remotehost ? 1 : 0) + 180 (request->hr_remotehost && *request->hr_remotehost ? 1 : 0) +
179 (request->hr_remoteaddr && *request->hr_remoteaddr ? 1 : 0) + 181 (request->hr_remoteaddr && *request->hr_remoteaddr ? 1 : 0) +
180 auth_cgi_count(request) + 182 auth_cgi_count(request) +
181 (request->hr_serverport && *request->hr_serverport ? 1 : 0); 183 (request->hr_serverport && *request->hr_serverport ? 1 : 0);
182 184
183 debug((DEBUG_FAT, 
184 "process_cgi: envpsize `%d'", envpsize)); 
185 
186 envp = bozomalloc(sizeof(*envp) * envpsize); 185 envp = bozomalloc(sizeof(*envp) * envpsize);
187 for (ix = 0; ix < envpsize; ix++) 186 for (ix = 0; ix < envpsize; ix++)
188 envp[ix] = NULL; 187 envp[ix] = NULL;
189 curenvp = envp; 188 curenvp = envp;
190 189
191 SIMPLEQ_FOREACH(headp, &request->hr_headers, h_next) { 190 SIMPLEQ_FOREACH(headp, &request->hr_headers, h_next) {
192 const char *s2; 191 const char *s2;
193 env = bozomalloc(6 + strlen(headp->h_header) + 1 + 192 env = bozomalloc(6 + strlen(headp->h_header) + 1 +
194 strlen(headp->h_value)); 193 strlen(headp->h_value));
195 194
196 t = env; 195 t = env;
197 strcpy(t, "HTTP_"); 196 strcpy(t, "HTTP_");
198 t += strlen(t); 197 t += strlen(t);
199 for (s2 = headp->h_header; *s2; t++, s2++) 198 for (s2 = headp->h_header; *s2; t++, s2++)
200 if (islower((u_int)*s2)) 199 if (islower((u_int)*s2))
201 *t = toupper((u_int)*s2); 200 *t = toupper((u_int)*s2);
202 else if (*s2 == '-') 201 else if (*s2 == '-')
203 *t = '_'; 202 *t = '_';
204 else 203 else
205 *t = *s2; 204 *t = *s2;
206 *t = '\0'; 205 *t = '\0';
207 debug((DEBUG_OBESE, "setting header %s as %s = %s", 206 debug((DEBUG_OBESE, "setting header %s as %s = %s",
208 headp->h_header, env, headp->h_value)); 207 headp->h_header, env, headp->h_value));
209 spsetenv(env, headp->h_value, curenvp++); 208 spsetenv(env, headp->h_value, curenvp++);
210 free(env); 209 free(env);
211 } 210 }
212 211
213#ifndef _PATH_DEFPATH 212#ifndef _PATH_DEFPATH
214#define _PATH_DEFPATH "/usr/bin:/bin" 213#define _PATH_DEFPATH "/usr/bin:/bin"
215#endif 214#endif
216 215
217 spsetenv("PATH", _PATH_DEFPATH, curenvp++); 216 spsetenv("PATH", _PATH_DEFPATH, curenvp++);
218 spsetenv("IFS", " \t\n", curenvp++); 217 spsetenv("IFS", " \t\n", curenvp++);
219 spsetenv("SERVER_NAME", myname, curenvp++); 218 spsetenv("SERVER_NAME", myname, curenvp++);
220 spsetenv("GATEWAY_INTERFACE", "CGI/1.1", curenvp++); 219 spsetenv("GATEWAY_INTERFACE", "CGI/1.1", curenvp++);
221 spsetenv("SERVER_PROTOCOL", request->hr_proto, curenvp++); 220 spsetenv("SERVER_PROTOCOL", request->hr_proto, curenvp++);
222 spsetenv("REQUEST_METHOD", request->hr_methodstr, curenvp++); 221 spsetenv("REQUEST_METHOD", request->hr_methodstr, curenvp++);
223 spsetenv("SCRIPT_NAME", file, curenvp++); 222 spsetenv("SCRIPT_NAME", file, curenvp++);
224 spsetenv("SCRIPT_FILENAME", file + 1, curenvp++); 223 spsetenv("SCRIPT_FILENAME", file + 1, curenvp++);
225 spsetenv("SERVER_SOFTWARE", server_software, curenvp++); 224 spsetenv("SERVER_SOFTWARE", server_software, curenvp++);
@@ -253,32 +252,33 @@ process_cgi(http_req *request) @@ -253,32 +252,33 @@ process_cgi(http_req *request)
253 /* 252 /*
254 * We create 2 procs: one to become the CGI, one read from 253 * We create 2 procs: one to become the CGI, one read from
255 * the CGI and output to the network, and this parent will 254 * the CGI and output to the network, and this parent will
256 * continue reading from the network and writing to the 255 * continue reading from the network and writing to the
257 * CGI procsss. 256 * CGI procsss.
258 */ 257 */
259 switch (fork()) { 258 switch (fork()) {
260 case -1: /* eep, failure */ 259 case -1: /* eep, failure */
261 error(1, "child fork failed: %s", strerror(errno)); 260 error(1, "child fork failed: %s", strerror(errno));
262 case 0: 261 case 0:
263 close(sv[0]); 262 close(sv[0]);
264 dup2(sv[1], STDIN_FILENO); 263 dup2(sv[1], STDIN_FILENO);
265 dup2(sv[1], STDOUT_FILENO); 264 dup2(sv[1], STDOUT_FILENO);
266 265 close(2);
267 debug((DEBUG_FAT, "process_cgi: going exec %s, %s %s %s", 266 close(sv[1]);
268 path, argv[0], strornull(argv[1]), strornull(argv[2]))); 267 closelog();
269 268
270 if (-1 == execve(path, argv, envp)) 269 if (-1 == execve(path, argv, envp))
271 error(1, "child exec failed: %s", path); 270 error(1, "child exec failed: %s: %s",
 271 path, strerror(errno));
272 /* NOT REACHED */ 272 /* NOT REACHED */
273 error(1, "child execve returned?!"); 273 error(1, "child execve returned?!");
274 } 274 }
275 275
276 close(sv[1]); 276 close(sv[1]);
277 277
278 /* parent: read from stdin (bozoread()) write to sv[0] */ 278 /* parent: read from stdin (bozoread()) write to sv[0] */
279 /* child: read from sv[0] (bozowrite()) write to stdout */ 279 /* child: read from sv[0] (bozowrite()) write to stdout */
280 pid = fork(); 280 pid = fork();
281 if (pid == -1) 281 if (pid == -1)
282 error(1, "io child fork failed: %s", strerror(errno)); 282 error(1, "io child fork failed: %s", strerror(errno));
283 else if (pid == 0) { 283 else if (pid == 0) {
284 /* child reader/writer */ 284 /* child reader/writer */

cvs diff -r1.9 -r1.10 src/libexec/httpd/bozohttpd.h (expand / switch to unified diff)

--- src/libexec/httpd/bozohttpd.h 2009/04/18 07:37:08 1.9
+++ src/libexec/httpd/bozohttpd.h 2009/04/18 21:22:03 1.10
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: bozohttpd.h,v 1.9 2009/04/18 07:37:08 mrg Exp $ */ 1/* $NetBSD: bozohttpd.h,v 1.10 2009/04/18 21:22:03 mrg Exp $ */
2 2
3/* $eterna: bozohttpd.h,v 1.25 2009/04/18 05:36:04 mrg Exp $ */ 3/* $eterna: bozohttpd.h,v 1.26 2009/04/18 07:38:56 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2009 Matthew R. Green 6 * Copyright (c) 1997-2009 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and 15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided 16 * dedication in the documentation and/or other materials provided

cvs diff -r1.5 -r1.6 src/libexec/httpd/daemon-bozo.c (expand / switch to unified diff)

--- src/libexec/httpd/daemon-bozo.c 2009/04/18 07:28:24 1.5
+++ src/libexec/httpd/daemon-bozo.c 2009/04/18 21:22:03 1.6
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: daemon-bozo.c,v 1.5 2009/04/18 07:28:24 mrg Exp $ */ 1/* $NetBSD: daemon-bozo.c,v 1.6 2009/04/18 21:22:03 mrg Exp $ */
2 2
3/* $eterna: daemon-bozo.c,v 1.13 2009/04/17 22:52:20 mrg Exp $ */ 3/* $eterna: daemon-bozo.c,v 1.16 2009/04/18 13:06:45 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2009 Matthew R. Green 6 * Copyright (c) 1997-2009 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and 15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided 16 * dedication in the documentation and/or other materials provided
@@ -110,92 +110,129 @@ daemon_init() @@ -110,92 +110,129 @@ daemon_init()
110 freeaddrinfo(r0); 110 freeaddrinfo(r0);
111 111
112 signal(SIGCHLD, sigchild); 112 signal(SIGCHLD, sigchild);
113} 113}
114 114
115/* 115/*
116 * the parent never returns from this function, only children that 116 * the parent never returns from this function, only children that
117 * are ready to run... XXXMRG - still true in fork-lesser bozo? 117 * are ready to run... XXXMRG - still true in fork-lesser bozo?
118 */ 118 */
119void 119void
120daemon_fork() 120daemon_fork()
121{ 121{
122 struct pollfd *fds = NULL; 122 struct pollfd *fds = NULL;
123 123 int i, j;
124 while (bflag) { 
125 struct sockaddr_storage ss; 
126 socklen_t slen; 
127 int fd; 
128 int i; 
129 124
130#ifndef POLLRDNORM 125#ifndef POLLRDNORM
131#define POLLRDNORM 0 126#define POLLRDNORM 0
132#endif 127#endif
133#ifndef POLLRDBAND 128#ifndef POLLRDBAND
134#define POLLRDBAND 0 129#define POLLRDBAND 0
135#endif 130#endif
136#ifndef INFTIM 131#ifndef INFTIM
137#define INFTIM -1 132#define INFTIM -1
138#endif 133#endif
139 if (fds == NULL) { 134
140 fds = bozomalloc(nsock * sizeof *fds); 135 fds = bozomalloc(nsock * sizeof *fds);
141 for (i = 0; i < nsock; i++) { 136 for (i = 0; i < nsock; i++) {
142 fds[i].events = POLLIN | POLLPRI | POLLRDNORM | 137 if (sock[i] == -1)
143 POLLRDBAND | POLLERR; 138 continue;
144 fds[i].fd = sock[i]; 139 fds[i].events = POLLIN | POLLPRI | POLLRDNORM |
145 } 140 POLLRDBAND | POLLERR;
146 } 141 fds[i].fd = sock[i];
 142 }
 143
 144 while (bflag) {
 145 struct sockaddr_storage ss;
 146 socklen_t slen;
 147 int fd;
 148
 149 if (nsock == 0)
 150 exit(0);
147 151
148 /* 152 /*
149 * wait for a connection, then fork() and return NULL in 153 * wait for a connection, then fork() and return NULL in
150 * the parent, who will come back here waiting for another 154 * the parent, who will come back here waiting for another
151 * connection. read the request in in the child, and return 155 * connection. read the request in in the child, and return
152 * it, for processing. 156 * it, for processing.
153 */ 157 */
154again: 158again:
155 if (poll(fds, nsock, INFTIM) == -1) { 159 if (poll(fds, nsock, INFTIM) == -1) {
156 if (errno != EINTR) 160 /* fail on programmer errors */
 161 if (errno == EFAULT ||
 162 errno == EINVAL)
157 error(1, "poll: %s", strerror(errno)); 163 error(1, "poll: %s", strerror(errno));
 164
 165 /* sleep on some temporary kernel failures */
 166 if (errno == ENOMEM ||
 167 errno == EAGAIN)
 168 sleep(1);
 169
158 goto again; 170 goto again;
159 } 171 }
160 172
161 for (i = 0; i < nsock; i++) { 173 for (i = 0; i < nsock; i++) {
162 if (fds[i].revents & (POLLNVAL|POLLERR|POLLHUP)) { 174 if (fds[i].revents & (POLLNVAL|POLLERR|POLLHUP)) {
163 warning("poll on fd %d: %s", fds[i].fd, 175 warning("poll on fd %d pid %d revents %d: %s",
164 strerror(errno)); 176 fds[i].fd, getpid(), fds[i].revents, strerror(errno));
165 continue; 177 warning("nsock = %d", nsock);
 178 close(sock[i]);
 179 nsock--;
 180 warning("nsock now = %d", nsock);
 181 /* no sockets left */
 182 if (nsock == 0)
 183 exit(0);
 184 /* last socket; easy case */
 185 if (nsock == i)
 186 break;
 187 memmove(&fds[i], &fds[i+i],
 188 (nsock - i) * sizeof(*fds));
 189 memmove(&sock[i], &sock[i+i],
 190 (nsock - i) * sizeof(*sock));
 191 break;
166 } 192 }
167 if (fds[i].revents == 0) 193 if (fds[i].revents == 0)
168 continue; 194 continue;
169 195
170 slen = sizeof(ss); 196 slen = sizeof(ss);
171 fd = accept(sock[i], (struct sockaddr *)&ss, &slen); 197 fd = accept(fds[i].fd, (struct sockaddr *)&ss, &slen);
172 if (fd == -1) { 198 if (fd == -1) {
173 if (errno != EAGAIN) 199 if (errno == EFAULT ||
 200 errno == EINVAL)
174 error(1, "accept: %s", strerror(errno)); 201 error(1, "accept: %s", strerror(errno));
 202
 203 if (errno == ENOMEM ||
 204 errno == EAGAIN)
 205 sleep(1);
 206
175 continue; 207 continue;
176 } 208 }
177 switch (fork()) { 209 switch (fork()) {
178 case -1: /* eep, failure */ 210 case -1: /* eep, failure */
179 warning("fork() failed, sleeping for 10 seconds: %s", 211 warning("fork() failed, sleeping for 10 seconds: %s",
180 strerror(errno)); 212 strerror(errno));
181 close(fd); 213 close(fd);
182 sleep(10); 214 sleep(10);
183 continue; 215 continue;
184 216
185 case 0: /* child */ 217 case 0: /* child */
186 /* setup stdin/stdout/stderr */ 218 /* setup stdin/stdout/stderr */
187 dup2(fd, 0); 219 dup2(fd, 0);
188 dup2(fd, 1); 220 dup2(fd, 1);
189 /*dup2(fd, 2);*/ 221 /*dup2(fd, 2);*/
 222 free(fds);
 223 free(sock);
190 close(fd); 224 close(fd);
 225 for (j = 0; j < nsock; j++)
 226 close(sock[j]);
191 return; 227 return;
192 228
193 default: /* parent */ 229 default: /* parent */
194 close(fd); 230 close(fd);
195 continue; 231 continue;
196 } 232 }
197 } 233 }
198 } 234 }
 235 free(fds);
199} 236}
200 237
201#endif /* NO_DAEMON_MODE */ 238#endif /* NO_DAEMON_MODE */