aboutsummaryrefslogtreecommitdiff
path: root/networking/httpd.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-16 16:12:09 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-16 16:12:09 +0000
commite867b7ce868ecd721a871b686a4a017cd15e2fb2 (patch)
tree9fc63be7364e37de169ee61378b287e586d81a7f /networking/httpd.c
parent83ea643d8dc9b6f53706ba30bc4b53338f4f7994 (diff)
downloadbusybox-w32-e867b7ce868ecd721a871b686a4a017cd15e2fb2.tar.gz
busybox-w32-e867b7ce868ecd721a871b686a4a017cd15e2fb2.tar.bz2
busybox-w32-e867b7ce868ecd721a871b686a4a017cd15e2fb2.zip
httpd: stop being silly with setenv
Diffstat (limited to 'networking/httpd.c')
-rw-r--r--networking/httpd.c89
1 files changed, 28 insertions, 61 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index a64fcb138..737b030a7 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -716,51 +716,21 @@ static char *decodeString(char *orig, int flag_plus_to_space)
716 716
717#if ENABLE_FEATURE_HTTPD_CGI 717#if ENABLE_FEATURE_HTTPD_CGI
718/**************************************************************************** 718/****************************************************************************
719 * 719 * setenv helpers
720 > $Function: addEnv()
721 *
722 * $Description: Add an environment variable setting to the global list.
723 * A NAME=VALUE string is allocated, filled, and added to the list of
724 * environment settings passed to the cgi execution script.
725 *
726 * $Parameters:
727 * (char *) name_before_underline - The first part environment variable name.
728 * (char *) name_after_underline - The second part environment variable name.
729 * (char *) value . . The value to which the env variable is set.
730 *
731 * $Return: (void)
732 *
733 * $Errors: Silently returns if the env runs out of space to hold the new item
734 *
735 ****************************************************************************/ 720 ****************************************************************************/
736static void addEnv(const char *name_before_underline, 721static void setenv1(const char *name, const char *value)
737 const char *name_after_underline, const char *value)
738{ 722{
739 char *s = NULL;
740 const char *underline;
741
742 if (!value) 723 if (!value)
743 value = ""; 724 value = "";
744 underline = *name_after_underline ? "_" : ""; 725 setenv(name, value, 1);
745 asprintf(&s, "%s%s%s=%s", name_before_underline, underline,
746 name_after_underline, value);
747 if (s) {
748 putenv(s);
749 }
750} 726}
751 727static void setenv_long(const char *name, long value)
752#if ENABLE_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV || ENABLE_FEATURE_HTTPD_WITHOUT_INETD
753/* set environs SERVER_PORT and REMOTE_PORT */
754static void addEnvPort(const char *port_name)
755{ 728{
756 char buf[16]; 729 char buf[sizeof(value)*3 + 1];
757 730 sprintf(buf, "%ld", value);
758 sprintf(buf, "%u", config->port); 731 setenv(name, buf, 1);
759 addEnv(port_name, "PORT", buf);
760} 732}
761#endif 733#endif
762#endif /* CONFIG_FEATURE_HTTPD_CGI */
763
764 734
765#if ENABLE_FEATURE_HTTPD_BASIC_AUTH 735#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
766/**************************************************************************** 736/****************************************************************************
@@ -1058,52 +1028,49 @@ static int sendCgi(const char *url,
1058 } 1028 }
1059 *script = '/'; /* is directory, find next '/' */ 1029 *script = '/'; /* is directory, find next '/' */
1060 } 1030 }
1061 addEnv("PATH", "INFO", script); /* set /PATH_INFO or NULL */ 1031 setenv1("PATH_INFO", script); /* set /PATH_INFO or "" */
1062 addEnv("PATH", "", getenv("PATH")); 1032 setenv1("PATH", getenv("PATH")); /* Huh?? */
1063 addEnv("REQUEST", "METHOD", request); 1033 setenv1("REQUEST_METHOD", request);
1064 if (config->query) { 1034 if (config->query) {
1065 char *uri = alloca(strlen(purl) + 2 + strlen(config->query)); 1035 char *uri = alloca(strlen(purl) + 2 + strlen(config->query));
1066 if (uri) 1036 if (uri)
1067 sprintf(uri, "%s?%s", purl, config->query); 1037 sprintf(uri, "%s?%s", purl, config->query);
1068 addEnv("REQUEST", "URI", uri); 1038 setenv1("REQUEST_URI", uri);
1069 } else { 1039 } else {
1070 addEnv("REQUEST", "URI", purl); 1040 setenv1("REQUEST_URI", purl);
1071 } 1041 }
1072 if (script != NULL) 1042 if (script != NULL)
1073 *script = '\0'; /* reduce /PATH_INFO */ 1043 *script = '\0'; /* reduce /PATH_INFO */
1074 /* SCRIPT_FILENAME required by PHP in CGI mode */ 1044 /* SCRIPT_FILENAME required by PHP in CGI mode */
1075 if (realpath(purl + 1, realpath_buff)) 1045 if (realpath(purl + 1, realpath_buff))
1076 addEnv("SCRIPT", "FILENAME", realpath_buff); 1046 setenv1("SCRIPT_FILENAME", realpath_buff);
1077 else 1047 else
1078 *realpath_buff = 0; 1048 *realpath_buff = '\0';
1079 /* set SCRIPT_NAME as full path: /cgi-bin/dirs/script.cgi */ 1049 /* set SCRIPT_NAME as full path: /cgi-bin/dirs/script.cgi */
1080 addEnv("SCRIPT_NAME", "", purl); 1050 setenv1("SCRIPT_NAME", purl);
1081 addEnv("QUERY_STRING", "", config->query); 1051 setenv1("QUERY_STRING", config->query);
1082 addEnv("SERVER", "SOFTWARE", httpdVersion); 1052 setenv1("SERVER_SOFTWARE", httpdVersion);
1083 addEnv("SERVER", "PROTOCOL", "HTTP/1.0"); 1053 putenv("SERVER_PROTOCOL=HTTP/1.0");
1084 addEnv("GATEWAY_INTERFACE", "", "CGI/1.1"); 1054 putenv("GATEWAY_INTERFACE=CGI/1.1");
1085 addEnv("REMOTE", "ADDR", config->rmt_ip_str); 1055 setenv1("REMOTE_ADDR", config->rmt_ip_str);
1086#if ENABLE_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV 1056#if ENABLE_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV
1087 addEnvPort("REMOTE"); 1057 setenv_long("REMOTE_PORT", config->port);
1088#endif 1058#endif
1089 if (bodyLen) { 1059 if (bodyLen) {
1090 char sbl[32]; 1060 setenv_long("CONTENT_LENGTH", bodyLen);
1091
1092 sprintf(sbl, "%d", bodyLen);
1093 addEnv("CONTENT", "LENGTH", sbl);
1094 } 1061 }
1095 if (cookie) 1062 if (cookie)
1096 addEnv("HTTP", "COOKIE", cookie); 1063 setenv1("HTTP_COOKIE", cookie);
1097 if (content_type) 1064 if (content_type)
1098 addEnv("CONTENT", "TYPE", content_type); 1065 setenv1("CONTENT_TYPE", content_type);
1099#if ENABLE_FEATURE_HTTPD_BASIC_AUTH 1066#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
1100 if (config->remoteuser) { 1067 if (config->remoteuser) {
1101 addEnv("REMOTE", "USER", config->remoteuser); 1068 setenv1("REMOTE_USER", config->remoteuser);
1102 addEnv("AUTH_TYPE", "", "Basic"); 1069 putenv("AUTH_TYPE=Basic");
1103 } 1070 }
1104#endif 1071#endif
1105 if (config->referer) 1072 if (config->referer)
1106 addEnv("HTTP", "REFERER", config->referer); 1073 setenv1("HTTP_REFERER", config->referer);
1107 1074
1108 /* set execve argp[0] without path */ 1075 /* set execve argp[0] without path */
1109 argp[0] = strrchr(purl, '/') + 1; 1076 argp[0] = strrchr(purl, '/') + 1;
@@ -1985,7 +1952,7 @@ int httpd_main(int argc, char *argv[])
1985 if (p) 1952 if (p)
1986 setenv("PATH", p, 1); 1953 setenv("PATH", p, 1);
1987# if ENABLE_FEATURE_HTTPD_WITHOUT_INETD 1954# if ENABLE_FEATURE_HTTPD_WITHOUT_INETD
1988 addEnvPort("SERVER"); 1955 setenv_long("SERVER_PORT", config->port);
1989# endif 1956# endif
1990 } 1957 }
1991#endif 1958#endif