cgi-bozo.c revision 1.37.4.2 1 /* $NetBSD: cgi-bozo.c,v 1.37.4.2 2018/11/24 17:13:51 martin Exp $ */
2
3 /* $eterna: cgi-bozo.c,v 1.40 2011/11/18 09:21:15 mrg Exp $ */
4
5 /*
6 * Copyright (c) 1997-2018 Matthew R. Green
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided
17 * with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33 /* this code implements CGI/1.2 for bozohttpd */
34
35 #ifndef NO_CGIBIN_SUPPORT
36
37 #include <sys/param.h>
38 #include <sys/socket.h>
39
40 #include <ctype.h>
41 #include <errno.h>
42 #include <paths.h>
43 #include <signal.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <syslog.h>
47 #include <unistd.h>
48 #include <assert.h>
49
50 #include <netinet/in.h>
51
52 #include "bozohttpd.h"
53
54 #define CGIBIN_PREFIX "cgi-bin/"
55 #define CGIBIN_PREFIX_LEN (sizeof(CGIBIN_PREFIX)-1)
56
57 #ifndef USE_ARG
58 #define USE_ARG(x) /*LINTED*/(void)&(x)
59 #endif
60
61 /*
62 * given the file name, return a CGI interpreter
63 */
64 static const char *
65 content_cgihandler(bozohttpd_t *httpd, bozo_httpreq_t *request,
66 const char *file)
67 {
68 bozo_content_map_t *map;
69
70 USE_ARG(request);
71 debug((httpd, DEBUG_FAT, "content_cgihandler: trying file %s", file));
72 map = bozo_match_content_map(httpd, file, 0);
73 if (map)
74 return map->cgihandler;
75 return NULL;
76 }
77
78 static int
79 parse_header(bozo_httpreq_t *request, const char *str, ssize_t len,
80 char **hdr_str, char **hdr_val)
81 {
82 struct bozohttpd_t *httpd = request->hr_httpd;
83 char *name, *value;
84
85 /* if the string passed is zero-length bail out */
86 if (*str == '\0')
87 return -1;
88
89 value = bozostrdup(httpd, request, str);
90
91 /* locate the ':' separator in the header/value */
92 name = bozostrnsep(&value, ":", &len);
93
94 if (NULL == name || -1 == len) {
95 free(value);
96 return -1;
97 }
98
99 /* skip leading space/tab */
100 while (*value == ' ' || *value == '\t')
101 len--, value++;
102
103 *hdr_str = name;
104 *hdr_val = value;
105
106 return 0;
107 }
108
109 /*
110 * handle parsing a CGI header output, transposing a Status: header
111 * into the HTTP reply (ie, instead of "200 OK").
112 */
113 static void
114 finish_cgi_output(bozohttpd_t *httpd, bozo_httpreq_t *request, int in, int nph)
115 {
116 char buf[BOZO_WRSZ];
117 char *str;
118 ssize_t len;
119 ssize_t rbytes;
120 SIMPLEQ_HEAD(, bozoheaders) headers;
121 bozoheaders_t *hdr, *nhdr;
122 int write_header, nheaders = 0;
123
124 /* much of this code is like bozo_read_request()'s header loop. */
125 SIMPLEQ_INIT(&headers);
126 write_header = nph == 0;
127 while (nph == 0 &&
128 (str = bozodgetln(httpd, in, &len, bozo_read)) != NULL) {
129 char *hdr_name, *hdr_value;
130
131 if (parse_header(request, str, len, &hdr_name, &hdr_value))
132 break;
133
134 /*
135 * The CGI 1.{1,2} spec both say that if the cgi program
136 * returns a `Status:' header field then the server MUST
137 * return it in the response. If the cgi program does
138 * not return any `Status:' header then the server should
139 * respond with 200 OK.
140 * XXX The CGI 1.1 and 1.2 specification differ slightly on
141 * this in that v1.2 says that the script MUST NOT return a
142 * `Status:' header if it is returning a `Location:' header.
143 * For compatibility we are going with the CGI 1.1 behavior.
144 */
145 if (strcasecmp(hdr_name, "status") == 0) {
146 debug((httpd, DEBUG_OBESE,
147 "%s: writing HTTP header "
148 "from status %s ..", __func__, hdr_value));
149 bozo_printf(httpd, "%s %s\r\n", request->hr_proto,
150 hdr_value);
151 bozo_flush(httpd, stdout);
152 write_header = 0;
153 free(hdr_name);
154 break;
155 }
156
157 hdr = bozomalloc(httpd, sizeof *hdr);
158 hdr->h_header = hdr_name;
159 hdr->h_value = hdr_value;
160 SIMPLEQ_INSERT_TAIL(&headers, hdr, h_next);
161 nheaders++;
162 }
163
164 if (write_header) {
165 debug((httpd, DEBUG_OBESE,
166 "%s: writing HTTP header ..", __func__));
167 bozo_printf(httpd,
168 "%s 200 OK\r\n", request->hr_proto);
169 bozo_flush(httpd, stdout);
170 }
171
172 if (nheaders) {
173 debug((httpd, DEBUG_OBESE,
174 "%s: writing delayed HTTP headers ..", __func__));
175 SIMPLEQ_FOREACH_SAFE(hdr, &headers, h_next, nhdr) {
176 bozo_printf(httpd, "%s: %s\r\n", hdr->h_header,
177 hdr->h_value);
178 free(hdr->h_header);
179 free(hdr);
180 }
181 bozo_printf(httpd, "\r\n");
182 bozo_flush(httpd, stdout);
183 }
184
185 /* XXX we should have some goo that times us out
186 */
187 while ((rbytes = read(in, buf, sizeof buf)) > 0) {
188 ssize_t wbytes;
189 char *bp = buf;
190
191 while (rbytes) {
192 wbytes = bozo_write(httpd, STDOUT_FILENO, buf,
193 (size_t)rbytes);
194 if (wbytes > 0) {
195 rbytes -= wbytes;
196 bp += wbytes;
197 } else
198 bozoerr(httpd, 1,
199 "cgi output write failed: %s",
200 strerror(errno));
201 }
202 }
203 }
204
205 static void
206 append_index_html(bozohttpd_t *httpd, char **url)
207 {
208 *url = bozorealloc(httpd, *url,
209 strlen(*url) + strlen(httpd->index_html) + 1);
210 strcat(*url, httpd->index_html);
211 debug((httpd, DEBUG_NORMAL,
212 "append_index_html: url adjusted to `%s'", *url));
213 }
214
215 /* This function parse search-string according to section 4.4 of RFC3875 */
216 static char **
217 parse_search_string(bozo_httpreq_t *request, const char *query, size_t *args_len)
218 {
219 struct bozohttpd_t *httpd = request->hr_httpd;
220 size_t i;
221 char *s, *str, **args;
222
223 *args_len = 0;
224
225 /* URI MUST not contain any unencoded '=' - RFC3875, section 4.4 */
226 if (strchr(query, '='))
227 return NULL;
228
229 str = bozostrdup(httpd, request, query);
230
231 /*
232 * there's no more arguments than '+' chars in the query string as it's
233 * the separator
234 */
235 *args_len = 1;
236 /* count '+' in str */
237 for (s = str; (s = strchr(s, '+')); (*args_len)++)
238 s++;
239
240 args = bozomalloc(httpd, sizeof(*args) * (*args_len + 1));
241
242 args[0] = str;
243 args[*args_len] = NULL;
244 for (s = str, i = 0; (s = strchr(s, '+'));) {
245 *s = '\0';
246 s++;
247 args[i++] = s;
248 }
249
250 /*
251 * check if search-strings are valid:
252 *
253 * RFC3875, section 4.4:
254 *
255 * search-string = search-word *( "+" search-word )
256 * search-word = 1*schar
257 * schar = unreserved | escaped | xreserved
258 * xreserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "," |
259 * "$"
260 *
261 * section 2.3:
262 *
263 * hex = digit | "A" | "B" | "C" | "D" | "E" | "F" | "a" |
264 * "b" | "c" | "d" | "e" | "f"
265 * escaped = "%" hex hex
266 * unreserved = alpha | digit | mark
267 * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
268 *
269 * section 2.2:
270 *
271 * alpha = lowalpha | hialpha
272 * lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
273 * "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
274 * "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
275 * "y" | "z"
276 * hialpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
277 * "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
278 * "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
279 * "Y" | "Z"
280 * digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
281 * "8" | "9"
282 */
283 #define UNRESERVED_CHAR "-_.!~*'()"
284 #define XRESERVED_CHAR ";/?:@&=,$"
285
286 for (i = 0; i < *args_len; i++) {
287 s = args[i];
288 /* search-word MUST have at least one schar */
289 if (*s == '\0')
290 goto parse_err;
291 while (*s) {
292 /* check if it's unreserved */
293 if (isalpha((int)*s) || isdigit((int)*s) ||
294 strchr(UNRESERVED_CHAR, *s)) {
295 s++;
296 continue;
297 }
298
299 /* check if it's escaped */
300 if (*s == '%') {
301 if (s[1] == '\0' || s[2] == '\0')
302 goto parse_err;
303 if (!isxdigit((int)s[1]) ||
304 !isxdigit((int)s[2]))
305 goto parse_err;
306 s += 3;
307 continue;
308 }
309
310 /* check if it's xreserved */
311
312 if (strchr(XRESERVED_CHAR, *s)) {
313 s++;
314 continue;
315 }
316
317 goto parse_err;
318 }
319 }
320
321 /* decode percent encoding */
322 for (i = 0; i < *args_len; i++) {
323 if (bozo_decode_url_percent(request, args[i]))
324 goto parse_err;
325 }
326
327 /* allocate each arg separately */
328 for (i = 0; i < *args_len; i++)
329 args[i] = bozostrdup(httpd, request, args[i]);
330 free(str);
331
332 return args;
333
334 parse_err:
335
336 free (str);
337 free (*args);
338 free(args);
339 *args_len = 0;
340
341 return NULL;
342
343 }
344
345 void
346 bozo_cgi_setbin(bozohttpd_t *httpd, const char *path)
347 {
348 httpd->cgibin = bozostrdup(httpd, NULL, path);
349 debug((httpd, DEBUG_OBESE, "cgibin (cgi-bin directory) is %s",
350 httpd->cgibin));
351 }
352
353 /* help build up the environ pointer */
354 void
355 bozo_setenv(bozohttpd_t *httpd, const char *env, const char *val,
356 char **envp)
357 {
358 char *s1 = bozomalloc(httpd, strlen(env) + strlen(val) + 2);
359
360 strcpy(s1, env);
361 strcat(s1, "=");
362 strcat(s1, val);
363 debug((httpd, DEBUG_OBESE, "bozo_setenv: %s", s1));
364 *envp = s1;
365 }
366
367 /*
368 * Checks if the request has asked for a cgi-bin. Should only be called if
369 * cgibin is set. If it starts CGIBIN_PREFIX or has a ncontent handler,
370 * process the cgi, otherwise just return. Returns 0 if it did not handle
371 * the request.
372 */
373 int
374 bozo_process_cgi(bozo_httpreq_t *request)
375 {
376 bozohttpd_t *httpd = request->hr_httpd;
377 char buf[BOZO_WRSZ];
378 char date[40];
379 bozoheaders_t *headp;
380 const char *type, *clen, *info, *cgihandler;
381 char *query, *s, *t, *path, *env, *command, *file, *url;
382 char **envp, **curenvp, **argv, **search_string_argv = NULL;
383 char **lastenvp;
384 char *uri;
385 size_t i, len, search_string_argc = 0;
386 ssize_t rbytes;
387 pid_t pid;
388 int envpsize, ix, nph;
389 int sv[2];
390
391 if (!httpd->cgibin && !httpd->process_cgi)
392 return 0;
393
394 #ifndef NO_USER_SUPPORT
395 if (request->hr_user && !httpd->enable_cgi_users)
396 return 0;
397 #endif /* !NO_USER_SUPPORT */
398
399 if (request->hr_oldfile && strcmp(request->hr_oldfile, "/") != 0)
400 uri = request->hr_oldfile;
401 else
402 uri = request->hr_file;
403
404 if (uri[0] == '/')
405 file = bozostrdup(httpd, request, uri);
406 else
407 bozoasprintf(httpd, &file, "/%s", uri);
408
409 if (request->hr_query && strlen(request->hr_query))
410 query = bozostrdup(httpd, request, request->hr_query);
411 else
412 query = NULL;
413
414 bozoasprintf(httpd, &url, "%s%s%s",
415 file,
416 query ? "?" : "",
417 query ? query : "");
418 debug((httpd, DEBUG_NORMAL, "%s: url `%s'", __func__, url));
419
420 path = NULL;
421 envp = NULL;
422 cgihandler = NULL;
423 command = NULL;
424 info = NULL;
425
426 len = strlen(url);
427
428 if (bozo_auth_check(request, url + 1))
429 goto out;
430
431 if (!httpd->cgibin ||
432 strncmp(url + 1, CGIBIN_PREFIX, CGIBIN_PREFIX_LEN) != 0) {
433 cgihandler = content_cgihandler(httpd, request, file + 1);
434 if (cgihandler == NULL) {
435 debug((httpd, DEBUG_FAT,
436 "%s: no handler, returning", __func__));
437 goto out;
438 }
439 if (len == 0 || file[len - 1] == '/')
440 append_index_html(httpd, &file);
441 debug((httpd, DEBUG_NORMAL, "%s: cgihandler `%s'",
442 __func__, cgihandler));
443 } else if (len - 1 == CGIBIN_PREFIX_LEN) /* url is "/cgi-bin/" */
444 append_index_html(httpd, &file);
445
446 /* RFC3875 sect. 4.4. - search-string support */
447 if (query != NULL) {
448 search_string_argv = parse_search_string(request, query,
449 &search_string_argc);
450 }
451
452 debug((httpd, DEBUG_NORMAL, "parse_search_string args no: %zu",
453 search_string_argc));
454 for (i = 0; i < search_string_argc; i++) {
455 debug((httpd, DEBUG_FAT,
456 "search_string[%zu]: `%s'", i, search_string_argv[i]));
457 }
458
459 argv = bozomalloc(httpd, sizeof(*argv) * (3 + search_string_argc));
460
461 ix = 0;
462 if (cgihandler) {
463 command = file + 1;
464 path = bozostrdup(httpd, request, cgihandler);
465 } else {
466 command = file + CGIBIN_PREFIX_LEN + 1;
467 if ((s = strchr(command, '/')) != NULL) {
468 info = bozostrdup(httpd, request, s);
469 *s = '\0';
470 }
471 path = bozomalloc(httpd,
472 strlen(httpd->cgibin) + 1 + strlen(command) + 1);
473 strcpy(path, httpd->cgibin);
474 strcat(path, "/");
475 strcat(path, command);
476 }
477
478 argv[ix++] = path;
479
480 /* copy search-string args */
481 for (i = 0; i < search_string_argc; i++)
482 argv[ix++] = search_string_argv[i];
483
484 argv[ix++] = NULL;
485 nph = strncmp(command, "nph-", 4) == 0;
486
487 type = request->hr_content_type;
488 clen = request->hr_content_length;
489
490 envpsize = 13 + request->hr_nheaders +
491 (info && *info ? 1 : 0) +
492 (query && *query ? 1 : 0) +
493 (type && *type ? 1 : 0) +
494 (clen && *clen ? 1 : 0) +
495 (request->hr_remotehost && *request->hr_remotehost ? 1 : 0) +
496 (request->hr_remoteaddr && *request->hr_remoteaddr ? 1 : 0) +
497 bozo_auth_cgi_count(request) +
498 (request->hr_serverport && *request->hr_serverport ? 1 : 0);
499
500 debug((httpd, DEBUG_FAT,
501 "%s: path `%s', cmd `%s', info `%s', "
502 "query `%s', nph `%d', envpsize `%d'", __func__,
503 path, command, strornull(info),
504 strornull(query), nph, envpsize));
505
506 envp = bozomalloc(httpd, sizeof(*envp) * envpsize);
507 for (ix = 0; ix < envpsize; ix++)
508 envp[ix] = NULL;
509 curenvp = envp;
510 lastenvp = envp + envpsize;
511
512 SIMPLEQ_FOREACH(headp, &request->hr_headers, h_next) {
513 const char *s2;
514 env = bozomalloc(httpd, 6 + strlen(headp->h_header) + 1 +
515 strlen(headp->h_value));
516
517 t = env;
518 strcpy(t, "HTTP_");
519 t += strlen(t);
520 for (s2 = headp->h_header; *s2; t++, s2++)
521 if (islower((unsigned)*s2))
522 *t = toupper((unsigned)*s2);
523 else if (*s2 == '-')
524 *t = '_';
525 else
526 *t = *s2;
527 *t = '\0';
528 debug((httpd, DEBUG_OBESE, "setting header %s as %s = %s",
529 headp->h_header, env, headp->h_value));
530 bozo_setenv(httpd, env, headp->h_value, curenvp++);
531 free(env);
532 }
533
534 #ifndef _PATH_DEFPATH
535 #define _PATH_DEFPATH "/usr/bin:/bin"
536 #endif
537
538 bozo_setenv(httpd, "PATH", _PATH_DEFPATH, curenvp++);
539 bozo_setenv(httpd, "IFS", " \t\n", curenvp++);
540 bozo_setenv(httpd, "SERVER_NAME", BOZOHOST(httpd,request), curenvp++);
541 bozo_setenv(httpd, "GATEWAY_INTERFACE", "CGI/1.1", curenvp++);
542 bozo_setenv(httpd, "SERVER_PROTOCOL", request->hr_proto, curenvp++);
543 bozo_setenv(httpd, "REQUEST_METHOD", request->hr_methodstr, curenvp++);
544 bozo_setenv(httpd, "SCRIPT_NAME", file, curenvp++);
545 bozo_setenv(httpd, "SCRIPT_FILENAME", file + 1, curenvp++);
546 bozo_setenv(httpd, "SERVER_SOFTWARE", httpd->server_software,
547 curenvp++);
548 bozo_setenv(httpd, "REQUEST_URI", uri, curenvp++);
549 bozo_setenv(httpd, "DATE_GMT", bozo_http_date(date, sizeof(date)),
550 curenvp++);
551 /* RFC3875 section 4.1.7 says that QUERY_STRING MUST be defined. */
552 if (query && *query)
553 bozo_setenv(httpd, "QUERY_STRING", query, curenvp++);
554 else
555 bozo_setenv(httpd, "QUERY_STRING", "", curenvp++);
556 if (info && *info)
557 bozo_setenv(httpd, "PATH_INFO", info, curenvp++);
558 if (type && *type)
559 bozo_setenv(httpd, "CONTENT_TYPE", type, curenvp++);
560 if (clen && *clen)
561 bozo_setenv(httpd, "CONTENT_LENGTH", clen, curenvp++);
562 if (request->hr_serverport && *request->hr_serverport)
563 bozo_setenv(httpd, "SERVER_PORT", request->hr_serverport,
564 curenvp++);
565 if (request->hr_remotehost && *request->hr_remotehost)
566 bozo_setenv(httpd, "REMOTE_HOST", request->hr_remotehost,
567 curenvp++);
568 if (request->hr_remoteaddr && *request->hr_remoteaddr)
569 bozo_setenv(httpd, "REMOTE_ADDR", request->hr_remoteaddr,
570 curenvp++);
571 /*
572 * Apache does this when invoking content handlers, and PHP
573 * 5.3 requires it as a "security" measure.
574 */
575 if (cgihandler)
576 bozo_setenv(httpd, "REDIRECT_STATUS", "200", curenvp++);
577 bozo_auth_cgi_setenv(request, &curenvp);
578
579 debug((httpd, DEBUG_FAT, "%s: going exec %s with args:", __func__,
580 path));
581
582 for (i = 0; argv[i] != NULL; i++) {
583 debug((httpd, DEBUG_FAT, "%s: argv[%zu] = `%s'", __func__,
584 i, argv[i]));
585 }
586
587 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sv) == -1)
588 bozoerr(httpd, 1, "child socketpair failed: %s",
589 strerror(errno));
590
591 *curenvp = 0;
592 assert(lastenvp > curenvp);
593
594 /*
595 * We create 2 procs: one to become the CGI, one read from
596 * the CGI and output to the network, and this parent will
597 * continue reading from the network and writing to the
598 * CGI procsss.
599 */
600 switch (fork()) {
601 case -1: /* eep, failure */
602 bozoerr(httpd, 1, "child fork failed: %s", strerror(errno));
603 /*NOTREACHED*/
604 case 0:
605 close(sv[0]);
606 dup2(sv[1], STDIN_FILENO);
607 dup2(sv[1], STDOUT_FILENO);
608 close(2);
609 close(sv[1]);
610 closelog();
611 bozo_daemon_closefds(httpd);
612
613 if (-1 == execve(path, argv, envp))
614 bozoerr(httpd, 1, "child exec failed: %s: %s",
615 path, strerror(errno));
616 /* NOT REACHED */
617 bozoerr(httpd, 1, "child execve returned?!");
618 }
619
620 free(query);
621 free(file);
622 free(url);
623 for (i = 0; i < search_string_argc; i++)
624 free(search_string_argv[i]);
625 free(search_string_argv);
626
627 close(sv[1]);
628
629 /* parent: read from stdin (bozo_read()) write to sv[0] */
630 /* child: read from sv[0] (bozo_write()) write to stdout */
631 pid = fork();
632 if (pid == -1)
633 bozoerr(httpd, 1, "io child fork failed: %s", strerror(errno));
634 else if (pid == 0) {
635 /* child reader/writer */
636 close(STDIN_FILENO);
637 finish_cgi_output(httpd, request, sv[0], nph);
638 /* if we're done output, our parent is useless... */
639 kill(getppid(), SIGKILL);
640 debug((httpd, DEBUG_FAT, "done processing cgi output"));
641 _exit(0);
642 }
643 close(STDOUT_FILENO);
644
645 /* XXX we should have some goo that times us out
646 */
647 while ((rbytes = bozo_read(httpd, STDIN_FILENO, buf, sizeof buf)) > 0) {
648 ssize_t wbytes;
649 char *bp = buf;
650
651 while (rbytes) {
652 wbytes = write(sv[0], buf, (size_t)rbytes);
653 if (wbytes > 0) {
654 rbytes -= wbytes;
655 bp += wbytes;
656 } else
657 bozoerr(httpd, 1, "write failed: %s",
658 strerror(errno));
659 }
660 }
661 debug((httpd, DEBUG_FAT, "done processing cgi input"));
662 exit(0);
663
664 out:
665
666 for (i = 0; i < search_string_argc; i++)
667 free(search_string_argv[i]);
668 free(search_string_argv);
669 free(query);
670 free(file);
671 free(url);
672 return 0;
673 }
674
675 #ifndef NO_DYNAMIC_CONTENT
676 /* cgi maps are simple ".postfix /path/to/prog" */
677 void
678 bozo_add_content_map_cgi(bozohttpd_t *httpd, const char *arg,
679 const char *cgihandler)
680 {
681 bozo_content_map_t *map;
682
683 debug((httpd, DEBUG_NORMAL, "bozo_add_content_map_cgi: name %s cgi %s",
684 arg, cgihandler));
685
686 httpd->process_cgi = 1;
687
688 map = bozo_get_content_map(httpd, arg);
689 map->name = arg;
690 map->type = map->encoding = map->encoding11 = NULL;
691 map->cgihandler = cgihandler;
692 }
693 #endif /* NO_DYNAMIC_CONTENT */
694
695 #endif /* NO_CGIBIN_SUPPORT */
696