Source-Changes-HG archive

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

[src/trunk]: src/libexec/httpd Redo previous (fixing a memory leak introduced...



details:   https://anonhg.NetBSD.org/src/rev/23913a4ae529
branches:  trunk
changeset: 787635:23913a4ae529
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Jun 27 10:01:31 2013 +0000

description:
Redo previous (fixing a memory leak introduced), and while there rework
virtual server support - in daemonized mode mixed virtual and "main"
server usage would alter the virtual hostname depending on order of
requests.
To fix, move the effective virtual hostname into the request structure
and leave the httpd server description static.

diffstat:

 libexec/httpd/bozohttpd.c |  32 +++++++++++++++++++-------------
 libexec/httpd/bozohttpd.h |   9 ++++++++-
 libexec/httpd/cgi-bozo.c  |   4 ++--
 3 files changed, 29 insertions(+), 16 deletions(-)

diffs (178 lines):

diff -r 682f17dd86f6 -r 23913a4ae529 libexec/httpd/bozohttpd.c
--- a/libexec/httpd/bozohttpd.c Thu Jun 27 09:57:49 2013 +0000
+++ b/libexec/httpd/bozohttpd.c Thu Jun 27 10:01:31 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bozohttpd.c,v 1.34 2013/06/23 20:32:55 martin Exp $    */
+/*     $NetBSD: bozohttpd.c,v 1.35 2013/06/27 10:01:31 martin Exp $    */
 
 /*     $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $      */
 
@@ -337,6 +337,7 @@
        MF(hr_remotehost);
        MF(hr_remoteaddr);
        MF(hr_serverport);
+       MF(hr_virthostname);
        MF(hr_file);
        MF(hr_oldfile);
        MF(hr_query);
@@ -539,6 +540,7 @@
        request->hr_range = NULL;
        request->hr_last_byte_pos = -1;
        request->hr_if_modified_since = NULL;
+       request->hr_virthostname = NULL;
        request->hr_file = NULL;
        request->hr_oldfile = NULL;
 
@@ -954,6 +956,7 @@
        bozohttpd_t *httpd = request->hr_httpd;
        char *urlbuf;
        char portbuf[20];
+       const char *hostname = BOZOHOST(httpd, request);
        int query = 0;
        
        if (url == NULL) {
@@ -972,7 +975,7 @@
                    request->hr_serverport);
        else
                portbuf[0] = '\0';
-       bozo_warn(httpd, "redirecting %s%s%s", httpd->virthostname, portbuf, url);
+       bozo_warn(httpd, "redirecting %s%s%s", hostname, portbuf, url);
        debug((httpd, DEBUG_FAT, "redirecting %s", url));
        bozo_printf(httpd, "%s 301 Document Moved\r\n", request->hr_proto);
        if (request->hr_proto != httpd->consts.http_09) 
@@ -980,7 +983,7 @@
        if (request->hr_proto != httpd->consts.http_09) {
                bozo_printf(httpd, "Location: http://";);
                if (absolute == 0)
-                       bozo_printf(httpd, "%s%s", httpd->virthostname, portbuf);
+                       bozo_printf(httpd, "%s%s", hostname, portbuf);
                if (query) {
                        bozo_printf(httpd, "%s?%s\r\n", url, request->hr_query);
                } else {
@@ -997,13 +1000,13 @@
                if (absolute)
                        bozo_printf(httpd, "%s?%s", url, request->hr_query);
                else
-                       bozo_printf(httpd, "%s%s%s?%s", httpd->virthostname,
+                       bozo_printf(httpd, "%s%s%s?%s", hostname,
                                    portbuf, url, request->hr_query);
        } else {
                if (absolute)
                        bozo_printf(httpd, "%s", url);
                else
-                       bozo_printf(httpd, "%s%s%s", httpd->virthostname,
+                       bozo_printf(httpd, "%s%s%s", hostname,
                                    portbuf, url);
        }
        bozo_printf(httpd, "\">here</a>\n");
@@ -1076,9 +1079,10 @@
                                    len) == 0) {
                                        /* found it, punch it */
                                        debug((httpd, DEBUG_OBESE, "found it punch it"));
-                                       httpd->virthostname = strdup(d->d_name);
+                                       request->hr_virthostname =
+                                           bozostrdup(httpd,d->d_name);
                                        if (asprintf(&s, "%s/%s", httpd->virtbase,
-                                           httpd->virthostname) < 0)
+                                           request->hr_virthostname) < 0)
                                                bozo_err(httpd, 1, "asprintf");
                                        break;
                                }
@@ -1268,6 +1272,7 @@
        bozohttpd_t *httpd = request->hr_httpd;
        char    *file, *newfile = NULL;
        size_t  len;
+       const char *hostname = BOZOHOST(httpd, request);
 
        file = NULL;
        *isindex = 0;
@@ -1306,10 +1311,10 @@
 
                        debug((httpd, DEBUG_FAT,
                                "checking referrer \"%s\" vs virthostname %s",
-                               r, httpd->virthostname));
+                               r, hostname));
                        if (strncmp(r, "http://";, 7) != 0 ||
-                           (strncasecmp(r + 7, httpd->virthostname,
-                                        strlen(httpd->virthostname)) != 0 &&
+                           (strncasecmp(r + 7, hostname,
+                                        strlen(hostname)) != 0 &&
                             !TOP_PAGE(file)))
                                to_indexhtml = 1;
                } else {
@@ -1318,8 +1323,8 @@
                        debug((httpd, DEBUG_FAT, "url has no referrer at all"));
                        /* if there's no referrer, let / or /index.html past */
                        if (!TOP_PAGE(file) ||
-                           (h && strncasecmp(h, httpd->virthostname,
-                                       strlen(httpd->virthostname)) != 0))
+                           (h && strncasecmp(h, hostname,
+                                       strlen(hostname)) != 0))
                                to_indexhtml = 1;
                }
 
@@ -1829,6 +1834,7 @@
        const char *reason = http_errors_long(code);
        const char *proto = (request && request->hr_proto) ?
                                request->hr_proto : httpd->consts.http_11;
+       const char *hostname = BOZOHOST(httpd, request);
        int     size;
 
        debug((httpd, DEBUG_FAT, "bozo_http_error %d: %s", code, msg));
@@ -1855,7 +1861,7 @@
                    "<hr><address><a href=\"http://%s%s/\";>%s%s</a></address>\n"
                    "</body></html>\n",
                    header, header, request->hr_file, reason,
-                   httpd->virthostname, portbuf, httpd->virthostname, portbuf);
+                   hostname, portbuf, hostname, portbuf);
                if (size >= (int)BUFSIZ) {
                        bozo_warn(httpd,
                                "bozo_http_error buffer too small, truncated");
diff -r 682f17dd86f6 -r 23913a4ae529 libexec/httpd/bozohttpd.h
--- a/libexec/httpd/bozohttpd.h Thu Jun 27 09:57:49 2013 +0000
+++ b/libexec/httpd/bozohttpd.h Thu Jun 27 10:01:31 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bozohttpd.h,v 1.23 2012/07/19 09:53:06 mrg Exp $       */
+/*     $NetBSD: bozohttpd.h,v 1.24 2013/06/27 10:01:31 martin Exp $    */
 
 /*     $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $       */
 
@@ -117,6 +117,8 @@
 #define HTTP_TRACE     0x07    /* not supported */
 #define HTTP_CONNECT   0x08    /* not supported */
        const char *hr_methodstr;
+       char    *hr_virthostname;       /* server name (if not identical
+                                          to hr_httpd->virthostname) */
        char    *hr_file;
        char    *hr_oldfile;    /* if we added an index_html */
        char    *hr_query;  
@@ -144,6 +146,11 @@
        int     hr_nheaders;
 } bozo_httpreq_t;
 
+/* helper to access the "active" host name from a httpd/request pair */
+#define        BOZOHOST(HTTPD,REQUEST) ((REQUEST)->hr_virthostname ?           \
+                                       (REQUEST)->hr_virthostname :    \
+                                       (HTTPD)->virthostname)
+
 /* structure to hold string based (name, value) pairs with preferences */
 typedef struct bozoprefs_t {
        unsigned          size;         /* size of the two arrays */
diff -r 682f17dd86f6 -r 23913a4ae529 libexec/httpd/cgi-bozo.c
--- a/libexec/httpd/cgi-bozo.c  Thu Jun 27 09:57:49 2013 +0000
+++ b/libexec/httpd/cgi-bozo.c  Thu Jun 27 10:01:31 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cgi-bozo.c,v 1.20 2011/11/18 09:51:31 mrg Exp $        */
+/*     $NetBSD: cgi-bozo.c,v 1.21 2013/06/27 10:01:31 martin Exp $     */
 
 /*     $eterna: cgi-bozo.c,v 1.40 2011/11/18 09:21:15 mrg Exp $        */
 
@@ -380,7 +380,7 @@
 
        bozo_setenv(httpd, "PATH", _PATH_DEFPATH, curenvp++);
        bozo_setenv(httpd, "IFS", " \t\n", curenvp++);
-       bozo_setenv(httpd, "SERVER_NAME", httpd->virthostname, curenvp++);
+       bozo_setenv(httpd, "SERVER_NAME", BOZOHOST(httpd,request), curenvp++);
        bozo_setenv(httpd, "GATEWAY_INTERFACE", "CGI/1.1", curenvp++);
        bozo_setenv(httpd, "SERVER_PROTOCOL", request->hr_proto, curenvp++);
        bozo_setenv(httpd, "REQUEST_METHOD", request->hr_methodstr, curenvp++);



Home | Main Index | Thread Index | Old Index