Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/httpd many clean ups:



details:   https://anonhg.NetBSD.org/src/rev/c0bf91b0f075
branches:  trunk
changeset: 446074:c0bf91b0f075
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Nov 22 08:54:08 2018 +0000

description:
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

diffstat:

 libexec/httpd/auth-bozo.c        |    3 +-
 libexec/httpd/bozohttpd.c        |  177 ++++++++++++++++++--------------------
 libexec/httpd/bozohttpd.h        |   15 ++-
 libexec/httpd/cgi-bozo.c         |    5 +-
 libexec/httpd/daemon-bozo.c      |    7 +-
 libexec/httpd/dir-index-bozo.c   |   13 +-
 libexec/httpd/main.c             |  135 +++++++++++++----------------
 libexec/httpd/ssl-bozo.c         |    6 +-
 libexec/httpd/tilde-luzah-bozo.c |   13 +-
 9 files changed, 180 insertions(+), 194 deletions(-)

diffs (truncated from 988 to 300 lines):

diff -r 1e680ead39e6 -r c0bf91b0f075 libexec/httpd/auth-bozo.c
--- a/libexec/httpd/auth-bozo.c Thu Nov 22 08:30:58 2018 +0000
+++ b/libexec/httpd/auth-bozo.c Thu Nov 22 08:54:08 2018 +0000
@@ -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 @@
 {
        request->hr_authuser = NULL;
        request->hr_authpass = NULL;
+       request->hr_authrealm = NULL;
 }
 
 void
diff -r 1e680ead39e6 -r c0bf91b0f075 libexec/httpd/bozohttpd.c
--- a/libexec/httpd/bozohttpd.c Thu Nov 22 08:30:58 2018 +0000
+++ b/libexec/httpd/bozohttpd.c Thu Nov 22 08:54:08 2018 +0000
@@ -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 @@
        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 @@
                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 @@
                        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 @@
                        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 @@
                                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 @@
                        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 @@
                        }
                        /* 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 @@
        /* 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 @@
        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 @@
  * \ 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 @@
        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 @@
                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 @@
        /*
         * 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 @@
                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 @@
        }
 
        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 @@
                                /* fix Host: again, if we truncated it */
                                *s = ':';
                }
-
                goto use_slashdir;
        }
        
@@ -1375,7 +1376,7 @@
            "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 @@
                                    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 @@
        /*
         * is there a mapping for this request?
         */
-       check_mapping(request);
+       check_remap(request);
 
        return 0;
 }
@@ -1449,9 +1450,10 @@
         * 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 @@
        } else if (basename == NULL) {
                strcpy(path, ".");
                strcpy(dir, "");
-               basename = request->hr_file + 1;
+               basename = dir;
        } else {



Home | Main Index | Thread Index | Old Index