Module Name: src Committed By: mrg Date: Thu Nov 22 08:54:08 UTC 2018
Modified Files: src/libexec/httpd: auth-bozo.c bozohttpd.c bozohttpd.h cgi-bozo.c daemon-bozo.c dir-index-bozo.c main.c ssl-bozo.c tilde-luzah-bozo.c Log Message: many clean ups: - keep a list of special files and their human names - remove (void) casts on bozo_http_error() - fix a few more misuses of bozo_http_error() - rename check_mapping() to check_remap() and perform some CSE - switch away from ``%s'' to '%s' - remove a bunch of #ifdef using new have_feature defines To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/libexec/httpd/auth-bozo.c cvs rdiff -u -r1.92 -r1.93 src/libexec/httpd/bozohttpd.c cvs rdiff -u -r1.55 -r1.56 src/libexec/httpd/bozohttpd.h cvs rdiff -u -r1.41 -r1.42 src/libexec/httpd/cgi-bozo.c cvs rdiff -u -r1.18 -r1.19 src/libexec/httpd/daemon-bozo.c \ src/libexec/httpd/main.c cvs rdiff -u -r1.27 -r1.28 src/libexec/httpd/dir-index-bozo.c cvs rdiff -u -r1.24 -r1.25 src/libexec/httpd/ssl-bozo.c cvs rdiff -u -r1.15 -r1.16 src/libexec/httpd/tilde-luzah-bozo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/libexec/httpd/auth-bozo.c diff -u src/libexec/httpd/auth-bozo.c:1.21 src/libexec/httpd/auth-bozo.c:1.22 --- src/libexec/httpd/auth-bozo.c:1.21 Wed Nov 21 09:37:02 2018 +++ src/libexec/httpd/auth-bozo.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: auth-bozo.c,v 1.21 2018/11/21 09:37:02 mrg Exp $ */ +/* $NetBSD: auth-bozo.c,v 1.22 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: auth-bozo.c,v 1.17 2011/11/18 09:21:15 mrg Exp $ */ @@ -117,6 +117,7 @@ bozo_auth_init(bozo_httpreq_t *request) { request->hr_authuser = NULL; request->hr_authpass = NULL; + request->hr_authrealm = NULL; } void Index: src/libexec/httpd/bozohttpd.c diff -u src/libexec/httpd/bozohttpd.c:1.92 src/libexec/httpd/bozohttpd.c:1.93 --- src/libexec/httpd/bozohttpd.c:1.92 Wed Nov 21 17:39:19 2018 +++ src/libexec/httpd/bozohttpd.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.c,v 1.92 2018/11/21 17:39:19 mrg Exp $ */ +/* $NetBSD: bozohttpd.c,v 1.93 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */ @@ -109,7 +109,7 @@ #define INDEX_HTML "index.html" #endif #ifndef SERVER_SOFTWARE -#define SERVER_SOFTWARE "bozohttpd/20181121" +#define SERVER_SOFTWARE "bozohttpd/20181122" #endif #ifndef PUBLIC_HTML @@ -169,6 +169,21 @@ #define LOG_FTP LOG_DAEMON #endif +/* + * List of special file that we should never serve. + */ +struct { + const char *file; + const char *name; +} specials[] = { + { DIRECT_ACCESS_FILE, "rejected direct access request" }, + { REDIRECT_FILE, "rejected redirect request" }, + { ABSREDIRECT_FILE, "rejected absredirect request" }, + { REMAP_FILE, "rejected remap request" }, + { AUTH_FILE, "rejected authfile request" }, + { NULL, NULL }, +}; + volatile sig_atomic_t timeout_hit; /* @@ -680,8 +695,7 @@ bozo_read_request(bozohttpd_t *httpd) sigaction(SIGALRM, &sa, NULL); if (clock_gettime(CLOCK_MONOTONIC, &ots) != 0) { - (void)bozo_http_error(httpd, 500, NULL, - "clock_gettime failed"); + bozo_http_error(httpd, 500, NULL, "clock_gettime failed"); goto cleanup; } @@ -690,8 +704,7 @@ bozo_read_request(bozohttpd_t *httpd) alarm(0); if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { - (void)bozo_http_error(httpd, 500, NULL, - "clock_gettime failed"); + bozo_http_error(httpd, 500, NULL, "clock_gettime failed"); goto cleanup; } /* @@ -711,16 +724,14 @@ bozo_read_request(bozohttpd_t *httpd) timeout_hit = 1; if (timeout_hit) { - (void)bozo_http_error(httpd, 408, NULL, - "request timed out"); + bozo_http_error(httpd, 408, NULL, "request timed out"); goto cleanup; } line++; if (line == 1) { if (len < 1) { - (void)bozo_http_error(httpd, 404, NULL, - "null method"); + bozo_http_error(httpd, 404, NULL, "null method"); goto cleanup; } bozowarn(httpd, @@ -734,13 +745,11 @@ bozo_read_request(bozohttpd_t *httpd) request->hr_file = file; request->hr_query = query; if (method == NULL) { - (void)bozo_http_error(httpd, 404, NULL, - "null method"); + bozo_http_error(httpd, 404, NULL, "null method"); goto cleanup; } if (file == NULL) { - (void)bozo_http_error(httpd, 404, NULL, - "null file"); + bozo_http_error(httpd, 404, NULL, "null file"); goto cleanup; } @@ -768,12 +777,10 @@ bozo_read_request(bozohttpd_t *httpd) break; val = bozostrnsep(&str, ":", &len); - debug((httpd, DEBUG_EXPLODING, - "read_req2: after bozostrnsep: str ``%s'' val ``%s''", - str, val)); + debug((httpd, DEBUG_EXPLODING, "read_req2: after " + "bozostrnsep: str `%s' val `%s'", str, val)); if (val == NULL || len == -1) { - (void)bozo_http_error(httpd, 404, request, - "no header"); + bozo_http_error(httpd, 404, request, "no header"); goto cleanup; } while (*str == ' ' || *str == '\t') @@ -796,7 +803,7 @@ bozo_read_request(bozohttpd_t *httpd) else if (strcasecmp(hdr->h_header, "host") == 0) { if (request->hr_host) { /* RFC 7230 (HTTP/1.1): 5.4 */ - (void)bozo_http_error(httpd, 400, request, + bozo_http_error(httpd, 400, request, "Only allow one Host: header"); goto cleanup; } @@ -805,7 +812,7 @@ bozo_read_request(bozohttpd_t *httpd) } /* RFC 2616 (HTTP/1.1): 14.20 */ else if (strcasecmp(hdr->h_header, "expect") == 0) { - (void)bozo_http_error(httpd, 417, request, + bozo_http_error(httpd, 417, request, "we don't support Expect:"); goto cleanup; } @@ -835,8 +842,7 @@ next_header: /* RFC1945, 8.3 */ if (request->hr_method == HTTP_POST && request->hr_content_length == NULL) { - (void)bozo_http_error(httpd, 400, request, - "missing content length"); + bozo_http_error(httpd, 400, request, "missing content length"); goto cleanup; } @@ -844,8 +850,7 @@ next_header: if (request->hr_proto == httpd->consts.http_11 && /*(strncasecmp(request->hr_file, "http://", 7) != 0) &&*/ request->hr_host == NULL) { - (void)bozo_http_error(httpd, 400, request, - "missing Host header"); + bozo_http_error(httpd, 400, request, "missing Host header"); goto cleanup; } @@ -1182,7 +1187,7 @@ esccmp(const char *s_plain, const char * * \ to encode a path containig a : character. */ static void -check_mapping(bozo_httpreq_t *request) +check_remap(bozo_httpreq_t *request) { bozohttpd_t *httpd = request->hr_httpd; char *file = request->hr_file, *newfile; @@ -1200,16 +1205,14 @@ check_mapping(bozo_httpreq_t *request) if (fstat(mapfile, &st) == -1) { bozowarn(httpd, "could not stat " REMAP_FILE ", errno: %d", errno); - close(mapfile); - return; + goto out; } fmap = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, mapfile, 0); if (fmap == NULL) { bozowarn(httpd, "could not mmap " REMAP_FILE ", error %d", errno); - close(mapfile); - return; + goto out; } reqlen = strlen(file); for (p = fmap, avail = st.st_size; avail; ) { @@ -1287,13 +1290,14 @@ check_mapping(bozo_httpreq_t *request) newfile = bozomalloc(httpd, strlen(file) + rlen - len + 1); memcpy(newfile, map_to, rlen); strcpy(newfile+rlen, file + len); - debug((httpd, DEBUG_NORMAL, "remapping found ``%s'' ", + debug((httpd, DEBUG_NORMAL, "remapping found '%s'", newfile)); free(request->hr_file); request->hr_file = newfile; } munmap(fmap, st.st_size); +out: close(mapfile); } @@ -1314,8 +1318,8 @@ check_virtual(bozo_httpreq_t *request) /* * convert http://virtual.host/ to request->hr_host */ - debug((httpd, DEBUG_OBESE, "checking for http:// virtual host in ``%s''", - file)); + debug((httpd, DEBUG_OBESE, + "checking for http:// virtual host in '%s'", file)); if (strncasecmp(file, "http://", 7) == 0) { /* we would do virtual hosting here? */ file += 7; @@ -1327,7 +1331,7 @@ check_virtual(bozo_httpreq_t *request) s = strchr(file, '/'); free(request->hr_file); request->hr_file = bozostrdup(httpd, request, s ? s : "/"); - debug((httpd, DEBUG_OBESE, "got host ``%s'' file is now ``%s''", + debug((httpd, DEBUG_OBESE, "got host '%s' file is now '%s'", request->hr_host, request->hr_file)); } else if (!request->hr_host) goto use_slashdir; @@ -1342,13 +1346,11 @@ check_virtual(bozo_httpreq_t *request) } if (!httpd->virtbase) { - /* * if we don't use vhost support, then set virthostname if * user supplied Host header. It will be used for possible * redirections */ - if (request->hr_host) { s = strrchr(request->hr_host, ':'); if (s != NULL) @@ -1360,7 +1362,6 @@ check_virtual(bozo_httpreq_t *request) /* fix Host: again, if we truncated it */ *s = ':'; } - goto use_slashdir; } @@ -1375,7 +1376,7 @@ check_virtual(bozo_httpreq_t *request) "for file `%s'", request->hr_host, httpd->virtbase, request->hr_file)); if (strncasecmp(httpd->virthostname, request->hr_host, len) != 0) { - s = 0; + s = NULL; DIR *dirp; struct dirent *d; @@ -1385,7 +1386,7 @@ check_virtual(bozo_httpreq_t *request) strcmp(d->d_name, "..") == 0) { continue; } - debug((httpd, DEBUG_OBESE, "looking at dir``%s''", + debug((httpd, DEBUG_OBESE, "looking at dir '%s'", d->d_name)); if (strcmp(d->d_name, request->hr_host) == 0) { /* found it, punch it */ @@ -1424,7 +1425,7 @@ use_slashdir: /* * is there a mapping for this request? */ - check_mapping(request); + check_remap(request); return 0; } @@ -1449,9 +1450,10 @@ check_bzredirect(bozo_httpreq_t *request * use it as the directory to look for the redir file. */ if ((size_t)snprintf(dir, sizeof(dir), "%s", request->hr_file + 1) >= - sizeof(dir)) - return bozo_http_error(httpd, 404, request, - "file path too long"); + sizeof(dir)) { + bozo_http_error(httpd, 404, request, "file path too long"); + return -1; + } debug((httpd, DEBUG_FAT, "check_bzredirect: dir %s", dir)); basename = strrchr(dir, '/'); @@ -1462,7 +1464,7 @@ check_bzredirect(bozo_httpreq_t *request } else if (basename == NULL) { strcpy(path, "."); strcpy(dir, ""); - basename = request->hr_file + 1; + basename = dir; } else { *basename++ = '\0'; strcpy(path, dir); @@ -1473,7 +1475,7 @@ check_bzredirect(bozo_httpreq_t *request debug((httpd, DEBUG_FAT, "check_bzredirect: path %s", path)); if ((size_t)snprintf(redir, sizeof(redir), "%s/%s", path, - REDIRECT_FILE) >= sizeof(redir)) { + REDIRECT_FILE) >= sizeof(redir)) { return bozo_http_error(httpd, 404, request, "redirectfile path too long"); return -1; @@ -1483,10 +1485,11 @@ check_bzredirect(bozo_httpreq_t *request return 0; absolute = 0; } else { - if((size_t)snprintf(redir, sizeof(redir), "%s/%s", path, - ABSREDIRECT_FILE) >= sizeof(redir)) { - return bozo_http_error(httpd, 404, request, - "redirectfile path too long"); + if ((size_t)snprintf(redir, sizeof(redir), "%s/%s", path, + ABSREDIRECT_FILE) >= sizeof(redir)) { + bozo_http_error(httpd, 404, request, + "redirectfile path too long"); + return -1; } if (lstat(redir, &sb) < 0 || !S_ISLNK(sb.st_mode)) return 0; @@ -1510,8 +1513,9 @@ check_bzredirect(bozo_httpreq_t *request if (!absolute && redirpath[0] != '/') { if ((size_t)snprintf(finalredir = redir, sizeof(redir), "%s%s/%s", (strlen(dir) > 0 ? "/" : ""), dir, redirpath) >= sizeof(redir)) { - return bozo_http_error(httpd, 404, request, - "redirect path too long"); + bozo_http_error(httpd, 404, request, + "redirect path too long"); + return -1; } } else finalredir = redirpath; @@ -1607,16 +1611,15 @@ transform_request(bozo_httpreq_t *reques file = NULL; *isindex = 0; debug((httpd, DEBUG_FAT, "tf_req: file %s", request->hr_file)); - if (bozo_decode_url_percent(request, request->hr_file)) { - goto bad_done; - } - if (check_virtual(request)) { + + if (bozo_decode_url_percent(request, request->hr_file) || + check_virtual(request)) goto bad_done; - } + file = request->hr_file; if (file[0] != '/') { - (void)bozo_http_error(httpd, 404, request, "unknown URL"); + bozo_http_error(httpd, 404, request, "unknown URL"); goto bad_done; } @@ -1633,12 +1636,13 @@ transform_request(bozo_httpreq_t *reques /* first of all expand user path */ if (len > 1 && httpd->enable_users && file[1] == '~') { if (file[2] == '\0') { - (void)bozo_http_error(httpd, 404, request, - "missing username"); + bozo_http_error(httpd, 404, request, + "missing username"); goto bad_done; } if (strchr(file + 2, '/') == NULL) { char *userredirecturl; + bozoasprintf(httpd, &userredirecturl, "%s/", file); handle_redirect(request, userredirecturl, 0); free(userredirecturl); @@ -1680,13 +1684,12 @@ transform_request(bozo_httpreq_t *reques newfile = bozostrdup(httpd, request, httpd->index_html); *isindex = 1; } else { /* len == 0 ? */ - (void)bozo_http_error(httpd, 500, request, - "request->hr_file is nul?"); + bozo_http_error(httpd, 500, request, "request->hr_file is nul"); goto bad_done; } if (newfile == NULL) { - (void)bozo_http_error(httpd, 500, request, "internal failure"); + bozo_http_error(httpd, 500, request, "internal failure"); goto bad_done; } @@ -1701,7 +1704,7 @@ transform_request(bozo_httpreq_t *reques if (*newfile == '/' || strcmp(newfile, "..") == 0 || strstr(newfile, "/..") || strstr(newfile, "../")) { - (void)bozo_http_error(httpd, 403, request, "illegal request"); + bozo_http_error(httpd, 403, request, "illegal request"); goto bad_done; } @@ -1713,14 +1716,13 @@ transform_request(bozo_httpreq_t *reques request->hr_file = newfile; } - if (bozo_process_cgi(request)) - return 0; - - if (bozo_process_lua(request)) + if (bozo_process_cgi(request) || + bozo_process_lua(request)) return 0; debug((httpd, DEBUG_FAT, "transform_request set: %s", newfile)); return 1; + bad_done: debug((httpd, DEBUG_FAT, "transform_request returning: 0")); free(newfile); @@ -1819,23 +1821,22 @@ bozo_process_request(bozo_httpreq_t *req switch (errno) { case EPERM: case EACCES: - (void)bozo_http_error(httpd, 403, request, - "no permission to open file"); + bozo_http_error(httpd, 403, request, + "no permission to open file"); break; case ENAMETOOLONG: /*FALLTHROUGH*/ case ENOENT: if (!bozo_dir_index(request, file, isindex)) - (void)bozo_http_error(httpd, 404, request, - "no file"); + bozo_http_error(httpd, 404, request, "no file"); break; default: - (void)bozo_http_error(httpd, 500, request, "open file"); + bozo_http_error(httpd, 500, request, "open file"); } goto cleanup_nofd; } if (fstat(fd, &sb) < 0) { - (void)bozo_http_error(httpd, 500, request, "can't fstat"); + bozo_http_error(httpd, 500, request, "can't fstat"); goto cleanup; } if (S_ISDIR(sb.st_mode)) { @@ -1925,22 +1926,10 @@ bozo_check_special_files(bozo_httpreq_t { bozohttpd_t *httpd = request->hr_httpd; - /* ensure basename(name) != special files */ - if (strcmp(name, DIRECT_ACCESS_FILE) == 0) - return bozo_http_error(httpd, 403, request, - "no permission to open direct access file"); - if (strcmp(name, REDIRECT_FILE) == 0) - return bozo_http_error(httpd, 403, request, - "no permission to open redirect file"); - if (strcmp(name, ABSREDIRECT_FILE) == 0) - return bozo_http_error(httpd, 403, request, - "no permission to open redirect file"); - if (strcmp(name, REMAP_FILE) == 0) - return bozo_http_error(httpd, 403, request, - "no permission to open redirect file"); - if (strcmp(name, AUTH_FILE) == 0) - return bozo_http_error(httpd, 403, request, - "no permission to open authfile"); + for (size_t i = 0; specials[i].file; i++) + if (strcmp(name, specials[i].file) == 0) + return bozo_http_error(httpd, 403, request, + specials[i].name); return 0; } @@ -2377,7 +2366,7 @@ bozodgetln(bozohttpd_t *httpd, int fd, s } httpd->getln_buffer[len] = '\0'; - debug((httpd, DEBUG_OBESE, "bozodgetln returns: ``%s'' with len %zd", + debug((httpd, DEBUG_OBESE, "bozodgetln returns: '%s' with len %zd", httpd->getln_buffer, len)); *lenp = len; return httpd->getln_buffer; @@ -2392,7 +2381,7 @@ bozorealloc(bozohttpd_t *httpd, void *pt if (p) return p; - (void)bozo_http_error(httpd, 500, NULL, "memory allocation failure"); + bozo_http_error(httpd, 500, NULL, "memory allocation failure"); exit(EXIT_FAILURE); } @@ -2405,7 +2394,7 @@ bozomalloc(bozohttpd_t *httpd, size_t si if (p) return p; - (void)bozo_http_error(httpd, 500, NULL, "memory allocation failure"); + bozo_http_error(httpd, 500, NULL, "memory allocation failure"); exit(EXIT_FAILURE); } @@ -2421,7 +2410,7 @@ bozostrdup(bozohttpd_t *httpd, bozo_http if (!request) bozoerr(httpd, EXIT_FAILURE, "strdup"); - (void)bozo_http_error(httpd, 500, request, "memory allocation failure"); + bozo_http_error(httpd, 500, request, "memory allocation failure"); exit(EXIT_FAILURE); } @@ -2443,7 +2432,7 @@ bozo_init_httpd(bozohttpd_t *httpd) /* error buffer for bozo_http_error() */ if ((httpd->errorbuf = malloc(BUFSIZ)) == NULL) { - (void) fprintf(stderr, + fprintf(stderr, "bozohttpd: memory_allocation failure\n"); return 0; } Index: src/libexec/httpd/bozohttpd.h diff -u src/libexec/httpd/bozohttpd.h:1.55 src/libexec/httpd/bozohttpd.h:1.56 --- src/libexec/httpd/bozohttpd.h:1.55 Wed Nov 21 09:37:02 2018 +++ src/libexec/httpd/bozohttpd.h Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.h,v 1.55 2018/11/21 09:37:02 mrg Exp $ */ +/* $NetBSD: bozohttpd.h,v 1.56 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */ @@ -289,7 +289,7 @@ char *bozostrdup(bozohttpd_t *, bozo_htt /* ssl-bozo.c */ #ifdef NO_SSL_SUPPORT #define bozo_ssl_set_opts(w, x, y) bozo_noop -#define bozo_ssl_set_ciphers(w, x, y) bozo_noop +#define bozo_ssl_set_ciphers(w, x) bozo_noop #define bozo_ssl_init(x) bozo_noop #define bozo_ssl_accept(x) (0) #define bozo_ssl_destroy(x) bozo_noop @@ -326,13 +326,13 @@ int bozo_auth_cgi_count(bozo_httpreq_t * /* cgi-bozo.c */ #ifdef NO_CGIBIN_SUPPORT +#define bozo_cgi_setbin(h,s) bozo_noop #define bozo_process_cgi(h) (0) #define have_cgibin (0) #else void bozo_cgi_setbin(bozohttpd_t *, const char *); void bozo_setenv(bozohttpd_t *, const char *, const char *, char **); int bozo_process_cgi(bozo_httpreq_t *); -void bozo_add_content_map_cgi(bozohttpd_t *, const char *, const char *); #define have_cgibin (1) #endif /* NO_CGIBIN_SUPPORT */ @@ -340,6 +340,7 @@ void bozo_add_content_map_cgi(bozohttpd_ /* lua-bozo.c */ #ifdef NO_LUA_SUPPORT #define bozo_process_lua(h) (0) +#define bozo_add_lua_map(h,s,t) bozo_noop #define have_lua (0) #else void bozo_add_lua_map(bozohttpd_t *, const char *, const char *); @@ -390,6 +391,7 @@ const char *bozo_content_encoding(bozo_h bozo_content_map_t *bozo_match_content_map(bozohttpd_t *, const char *, int); bozo_content_map_t *bozo_get_content_map(bozohttpd_t *, const char *); #ifdef NO_DYNAMIC_CONTENT +#define bozo_add_content_map_mime(h,s,t,u,v) bozo_noop #define have_dynamic_content (0) #else void bozo_add_content_map_mime(bozohttpd_t *, const char *, const char *, @@ -397,6 +399,13 @@ void bozo_add_content_map_mime(bozohttpd #define have_dynamic_content (1) #endif +/* additional cgi-bozo.c */ +#if have_cgibin && have_dynamic_content +void bozo_add_content_map_cgi(bozohttpd_t *, const char *, const char *); +#else +#define bozo_add_content_map_cgi(h,s,t) +#endif + /* I/O */ int bozo_printf(bozohttpd_t *, const char *, ...) BOZO_PRINTFLIKE(2, 3);; ssize_t bozo_read(bozohttpd_t *, int, void *, size_t); Index: src/libexec/httpd/cgi-bozo.c diff -u src/libexec/httpd/cgi-bozo.c:1.41 src/libexec/httpd/cgi-bozo.c:1.42 --- src/libexec/httpd/cgi-bozo.c:1.41 Tue Nov 20 01:06:46 2018 +++ src/libexec/httpd/cgi-bozo.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: cgi-bozo.c,v 1.41 2018/11/20 01:06:46 mrg Exp $ */ +/* $NetBSD: cgi-bozo.c,v 1.42 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: cgi-bozo.c,v 1.40 2011/11/18 09:21:15 mrg Exp $ */ @@ -62,7 +62,7 @@ */ static const char * content_cgihandler(bozohttpd_t *httpd, bozo_httpreq_t *request, - const char *file) + const char *file) { bozo_content_map_t *map; @@ -123,7 +123,6 @@ finish_cgi_output(bozohttpd_t *httpd, bo /* much of this code is like bozo_read_request()'s header loop. */ SIMPLEQ_INIT(&headers); write_header = nph == 0; - /* was read(2) here - XXX - agc */ while (nph == 0 && (str = bozodgetln(httpd, in, &len, bozo_read)) != NULL) { char *hdr_name, *hdr_value; Index: src/libexec/httpd/daemon-bozo.c diff -u src/libexec/httpd/daemon-bozo.c:1.18 src/libexec/httpd/daemon-bozo.c:1.19 --- src/libexec/httpd/daemon-bozo.c:1.18 Tue Nov 20 01:06:46 2018 +++ src/libexec/httpd/daemon-bozo.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: daemon-bozo.c,v 1.18 2018/11/20 01:06:46 mrg Exp $ */ +/* $NetBSD: daemon-bozo.c,v 1.19 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: daemon-bozo.c,v 1.24 2011/11/18 09:21:15 mrg Exp $ */ @@ -70,8 +70,9 @@ static pid_t pidfile_pid = 0; static void sigchild(int signo) { - while (waitpid(-1, NULL, WNOHANG) > 0) { - } + + while (waitpid(-1, NULL, WNOHANG) > 0) + /* nothing */; } /* Signal handler to exit in a controlled manner. This ensures that Index: src/libexec/httpd/main.c diff -u src/libexec/httpd/main.c:1.18 src/libexec/httpd/main.c:1.19 --- src/libexec/httpd/main.c:1.18 Tue Nov 20 01:15:50 2018 +++ src/libexec/httpd/main.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.18 2018/11/20 01:15:50 mrg Exp $ */ +/* $NetBSD: main.c,v 1.19 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $ */ /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ @@ -140,9 +140,7 @@ main(int argc, char **argv) bozohttpd_t httpd; bozoprefs_t prefs; char *progname; -#ifndef NO_DAEMON_MODE const char *val; -#endif int c; (void) memset(&httpd, 0x0, sizeof(httpd)); @@ -166,24 +164,20 @@ main(int argc, char **argv) switch (c) { case 'L': -#ifdef NO_LUA_SUPPORT - bozoerr(&httpd, 1, - "Lua support is not enabled"); - /* NOTREACHED */ -#else + if (!have_lua) + bozoerr(&httpd, 1, "Lua support not enabled"); + /* make sure there's two argument */ if (argc - optind < 1) usage(&httpd, progname); bozo_add_lua_map(&httpd, optarg, argv[optind]); optind++; break; -#endif /* NO_LUA_SUPPORT */ case 'M': -#ifdef NO_DYNAMIC_CONTENT - bozoerr(&httpd, 1, - "dynamic mime content support is not enabled"); - /* NOTREACHED */ -#else + if (!have_dynamic_content) + bozoerr(&httpd, 1, + "dynamic mime content support not enabled"); + /* make sure there're four arguments */ if (argc - optind < 3) usage(&httpd, progname); @@ -191,7 +185,6 @@ main(int argc, char **argv) argv[optind+1], argv[optind+2]); optind += 3; break; -#endif /* NO_DYNAMIC_CONTENT */ case 'n': bozo_set_pref(&httpd, &prefs, "numeric", "true"); @@ -206,25 +199,22 @@ main(int argc, char **argv) optarg); break; case 'Z': -#ifdef NO_SSL_SUPPORT - bozoerr(&httpd, 1, "ssl support is not enabled"); - /* NOT REACHED */ -#else + if (!have_ssl) + no_ssl: + bozoerr(&httpd, 1, "ssl support not enabled"); + /* make sure there's two arguments */ if (argc - optind < 1) usage(&httpd, progname); bozo_ssl_set_opts(&httpd, optarg, argv[optind++]); break; -#endif /* NO_SSL_SUPPORT */ case 'z': -#ifdef NO_SSL_SUPPORT - bozoerr(&httpd, 1, "ssl support is not enabled"); - /* NOT REACHED */ -#else + if (!have_ssl) + goto no_ssl; + bozo_ssl_set_ciphers(&httpd, optarg); break; -#endif /* NO_SSL_SUPPORT */ case 'U': bozo_set_pref(&httpd, &prefs, "username", optarg); @@ -246,16 +236,11 @@ main(int argc, char **argv) bozo_set_pref(&httpd, &prefs, "port number", optarg); break; -#ifdef NO_DAEMON_MODE - case 'b': - case 'e': - case 'f': - case 'i': - case 'P': - bozoerr(&httpd, 1, "Daemon mode is not enabled"); - /* NOTREACHED */ -#else case 'b': + if (!have_daemon_mode) + no_daemon_mode: + bozoerr(&httpd, 1, "Daemon mode not enabled"); + /* * test suite support - undocumented * background == 2 (aka, -b -b) means to @@ -267,104 +252,104 @@ main(int argc, char **argv) break; case 'e': + if (!have_daemon_mode) + goto no_daemon_mode; + bozo_set_pref(&httpd, &prefs, "dirty environment", "true"); break; case 'f': + if (!have_daemon_mode) + goto no_daemon_mode; + bozo_set_pref(&httpd, &prefs, "foreground", "true"); break; case 'i': + if (!have_daemon_mode) + goto no_daemon_mode; + bozo_set_pref(&httpd, &prefs, "bind address", optarg); break; case 'P': + if (!have_daemon_mode) + goto no_daemon_mode; + bozo_set_pref(&httpd, &prefs, "pid file", optarg); break; -#endif /* NO_DAEMON_MODE */ -#ifdef NO_CGIBIN_SUPPORT - case 'c': - case 'C': - bozoerr(&httpd, 1, "CGI is not enabled"); - /* NOTREACHED */ -#else case 'c': + if (!have_cgibin) + bozoerr(&httpd, 1, "CGI not enabled"); + bozo_cgi_setbin(&httpd, optarg); break; case 'C': -# ifdef NO_DYNAMIC_CONTENT - bozoerr(&httpd, 1, - "dynamic CGI handler support is not enabled"); - /* NOTREACHED */ -# else + if (!have_dynamic_content && !have_cgibin) + bozoerr(&httpd, 1, + "dynamic CGI handler support not enabled"); + /* make sure there's two arguments */ if (argc - optind < 1) usage(&httpd, progname); bozo_add_content_map_cgi(&httpd, optarg, argv[optind++]); break; -# endif /* NO_DYNAMIC_CONTENT */ -#endif /* NO_CGIBIN_SUPPORT */ case 'd': + if (!have_debug) + bozowarn(&httpd, "Debugging not enabled"); httpd.debug++; -#ifdef NO_DEBUG - if (httpd.debug == 1) - bozowarn(&httpd, "Debugging is not enabled"); -#endif /* NO_DEBUG */ break; case 't': bozo_set_pref(&httpd, &prefs, "chroot dir", optarg); break; -#ifdef NO_USER_SUPPORT - case 'p': - case 'u': - case 'E': - bozoerr(&httpd, 1, "User support is not enabled"); - /* NOTREACHED */ -#else case 'p': + if (!have_user) + no_user_support: + bozoerr(&httpd, 1, "User support not enabled"); + bozo_set_pref(&httpd, &prefs, "public_html", optarg); break; case 'u': + if (!have_user) + goto no_user_support; + bozo_set_pref(&httpd, &prefs, "enable users", "true"); break; -#ifndef NO_CGIBIN_SUPPORT + case 'E': + if (have_user && + have_cgibin) + bozoerr(&httpd, 1, "CGI not enabled"); + bozo_set_pref(&httpd, &prefs, "enable user cgibin", "true"); break; -#else - case 'E': - bozoerr(&httpd, 1, "CGI is not enabled"); - /* NOTREACHED */ -#endif /* NO_CGIBIN_SPPORT */ -#endif /* NO_USER_SUPPORT */ -#ifdef NO_DIRINDEX_SUPPORT - case 'H': - case 'X': - bozoerr(&httpd, 1, - "directory indexing is not enabled"); - /* NOTREACHED */ -#else case 'H': + if (!have_dirindex) + no_dirindex_support: + bozoerr(&httpd, 1, + "directory indexing not enabled"); + bozo_set_pref(&httpd, &prefs, "hide dots", "true"); break; case 'X': + if (!have_dirindex) + goto no_dirindex_support; + bozo_set_pref(&httpd, &prefs, "directory indexing", "true"); break; -#endif /* NO_DIRINDEX_SUPPORT */ - case 'G': { char version[128]; Index: src/libexec/httpd/dir-index-bozo.c diff -u src/libexec/httpd/dir-index-bozo.c:1.27 src/libexec/httpd/dir-index-bozo.c:1.28 --- src/libexec/httpd/dir-index-bozo.c:1.27 Wed Nov 21 10:25:17 2018 +++ src/libexec/httpd/dir-index-bozo.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: dir-index-bozo.c,v 1.27 2018/11/21 10:25:17 mrg Exp $ */ +/* $NetBSD: dir-index-bozo.c,v 1.28 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */ @@ -80,17 +80,16 @@ bozo_dir_index(bozo_httpreq_t *request, file[strlen(file) - strlen(httpd->index_html)] = '\0'; dirpath = file; } - debug((httpd, DEBUG_FAT, "bozo_dir_index: dirpath ``%s''", dirpath)); + debug((httpd, DEBUG_FAT, "bozo_dir_index: dirpath '%s'", dirpath)); if (stat(dirpath, &sb) < 0 || (dp = opendir(dirpath)) == NULL) { if (errno == EPERM) - (void)bozo_http_error(httpd, 403, request, - "no permission to open directory"); + bozo_http_error(httpd, 403, request, + "no permission to open directory"); else if (errno == ENOENT) - (void)bozo_http_error(httpd, 404, request, "no file"); + bozo_http_error(httpd, 404, request, "no file"); else - (void)bozo_http_error(httpd, 500, request, - "open directory"); + bozo_http_error(httpd, 500, request, "open directory"); goto done; /* NOTREACHED */ } Index: src/libexec/httpd/ssl-bozo.c diff -u src/libexec/httpd/ssl-bozo.c:1.24 src/libexec/httpd/ssl-bozo.c:1.25 --- src/libexec/httpd/ssl-bozo.c:1.24 Tue Nov 20 01:06:46 2018 +++ src/libexec/httpd/ssl-bozo.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ssl-bozo.c,v 1.24 2018/11/20 01:06:46 mrg Exp $ */ +/* $NetBSD: ssl-bozo.c,v 1.25 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: ssl-bozo.c,v 1.15 2011/11/18 09:21:15 mrg Exp $ */ @@ -323,6 +323,10 @@ bozo_ssl_set_ciphers(bozohttpd_t *httpd, #endif /* NO_SSL_SUPPORT */ +/* + * These functions are always present, so that caller code can simply + * use bozo_*() for IO, regardless of SSL. + */ int bozo_printf(bozohttpd_t *httpd, const char *fmt, ...) { Index: src/libexec/httpd/tilde-luzah-bozo.c diff -u src/libexec/httpd/tilde-luzah-bozo.c:1.15 src/libexec/httpd/tilde-luzah-bozo.c:1.16 --- src/libexec/httpd/tilde-luzah-bozo.c:1.15 Tue Nov 20 01:06:46 2018 +++ src/libexec/httpd/tilde-luzah-bozo.c Thu Nov 22 08:54:08 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tilde-luzah-bozo.c,v 1.15 2018/11/20 01:06:46 mrg Exp $ */ +/* $NetBSD: tilde-luzah-bozo.c,v 1.16 2018/11/22 08:54:08 mrg Exp $ */ /* $eterna: tilde-luzah-bozo.c,v 1.16 2011/11/18 09:21:15 mrg Exp $ */ @@ -53,7 +53,7 @@ * ala transform_request(). * * transform_request() is supposed to check that we have user support - * enabled. + * enabled. returns 0 if handled/error, 1 if continue. */ int bozo_user_transform(bozo_httpreq_t *request) @@ -90,7 +90,7 @@ bozo_user_transform(bozo_httpreq_t *requ if (pw == NULL) { free(request->hr_user); request->hr_user = NULL; - (void)bozo_http_error(httpd, 404, request, "no such user"); + bozo_http_error(httpd, 404, request, "no such user"); return 0; } @@ -101,15 +101,14 @@ bozo_user_transform(bozo_httpreq_t *requ if (chdir(pw->pw_dir) < 0) { bozowarn(httpd, "chdir1 error: %s: %s", pw->pw_dir, strerror(errno)); - (void)bozo_http_error(httpd, 404, request, - "can't chdir to homedir"); + bozo_http_error(httpd, 404, request, "can't chdir to homedir"); return 0; } if (chdir(httpd->public_html) < 0) { bozowarn(httpd, "chdir2 error: %s: %s", httpd->public_html, strerror(errno)); - (void)bozo_http_error(httpd, 404, request, - "can't chdir to public_html"); + bozo_http_error(httpd, 404, request, + "can't chdir to public_html"); return 0; } if (s == NULL || *s == '\0') {