start_stop_daemon: NOMMU fixes, round 2 by Alex Landau <landau_alex@yahoo.com>
[oweals/busybox.git] / networking / httpd.c
index 8c0a83e52da5640f14365aab699aa67c7a410d64..7c91bd597f4cb86a7aec10d0a5504ad22010e0f1 100644 (file)
@@ -145,6 +145,7 @@ struct globals {
        USE_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;)
        USE_FEATURE_HTTPD_BASIC_AUTH(char *remoteuser;)
        USE_FEATURE_HTTPD_CGI(char *referer;)
+       USE_FEATURE_HTTPD_CGI(char *user_agent;)
 
 #if ENABLE_FEATURE_HTTPD_CGI || DEBUG
        char *rmt_ip_str;        /* for set env REMOTE_ADDR */
@@ -179,6 +180,7 @@ struct globals {
 #define g_realm         (G.g_realm        )
 #define remoteuser      (G.remoteuser     )
 #define referer         (G.referer        )
+#define user_agent      (G.user_agent     )
 #if ENABLE_FEATURE_HTTPD_CGI || DEBUG
 #define rmt_ip_str      (G.rmt_ip_str     )
 #endif
@@ -878,11 +880,8 @@ static int sendHeaders(HttpResponseNum responseNum)
        time_t timer = time(0);
        char timeStr[80];
        int len;
-       enum {
-               numNames = sizeof(httpResponseNames) / sizeof(httpResponseNames[0])
-       };
 
-       for (i = 0; i < numNames; i++) {
+       for (i = 0; i < ARRAY_SIZE(httpResponseNames); i++) {
                if (httpResponseNames[i].type == responseNum) {
                        responseString = httpResponseNames[i].name;
                        infoString = httpResponseNames[i].info;
@@ -1109,6 +1108,7 @@ static int sendCgi(const char *url,
                        setenv1("REMOTE_ADDR", p);
                        if (cp) *cp = ':';
                }
+               setenv1("HTTP_USER_AGENT", user_agent);
 #if ENABLE_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV
                setenv_long("REMOTE_PORT", tcp_port);
 #endif
@@ -1128,7 +1128,7 @@ static int sendCgi(const char *url,
                        setenv1("HTTP_REFERER", referer);
 
                /* set execve argp[0] without path */
-               argp[0] = strrchr(purl, '/') + 1;
+               argp[0] = (char*)bb_basename(purl);
                /* but script argp[0] must have absolute path and chdiring to this */
                script = strrchr(fullpath, '/');
                if (!script)
@@ -1685,12 +1685,14 @@ static void handleIncoming(void)
                                                if (test[0] || errno || length > INT_MAX)
                                                        goto bail_out;
                                        }
-                               } else if ((STRNCASECMP(buf, "Cookie:") == 0)) {
+                               } else if (STRNCASECMP(buf, "Cookie:") == 0) {
                                        cookie = strdup(skip_whitespace(buf + sizeof("Cookie:")-1));
-                               } else if ((STRNCASECMP(buf, "Content-Type:") == 0)) {
+                               } else if (STRNCASECMP(buf, "Content-Type:") == 0) {
                                        content_type = strdup(skip_whitespace(buf + sizeof("Content-Type:")-1));
-                               } else if ((STRNCASECMP(buf, "Referer:") == 0)) {
+                               } else if (STRNCASECMP(buf, "Referer:") == 0) {
                                        referer = strdup(skip_whitespace(buf + sizeof("Referer:")-1));
+                               } else if (STRNCASECMP(buf, "User-Agent:") == 0) {
+                                       user_agent = strdup(skip_whitespace(buf + sizeof("User-Agent:")-1));
                                }
 #endif
 
@@ -1716,7 +1718,7 @@ static void handleIncoming(void)
                if (alarm_signaled)
                        break;
 
-               if (strcmp(strrchr(url, '/') + 1, httpd_conf) == 0 || ip_allowed == 0) {
+               if (strcmp(bb_basename(url), httpd_conf) == 0 || ip_allowed == 0) {
                        /* protect listing [/path]/httpd_conf or IP deny */
 #if ENABLE_FEATURE_HTTPD_CGI
  FORBIDDEN:            /* protect listing /cgi-bin */