diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-19 19:28:09 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-19 19:28:09 +0000 |
commit | 921799da4ec72eb353240e315b456171d2581d46 (patch) | |
tree | 1e1442fe8413337b1ee2118896326797abde4cd0 | |
parent | 37c3316fd7175f73f6a4f1d9cd29a7bada93d678 (diff) | |
download | busybox-w32-921799da4ec72eb353240e315b456171d2581d46.tar.gz busybox-w32-921799da4ec72eb353240e315b456171d2581d46.tar.bz2 busybox-w32-921799da4ec72eb353240e315b456171d2581d46.zip |
httpd: reinstate (much lighter) paranoid connection close code
allegedly needed for some versions of IE. +45 bytes.
-rw-r--r-- | networking/httpd.c | 79 |
1 files changed, 25 insertions, 54 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 560d1f8ee..a7473ede9 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -104,7 +104,7 @@ | |||
104 | # define PIPE_BUF 4096 | 104 | # define PIPE_BUF 4096 |
105 | #endif | 105 | #endif |
106 | 106 | ||
107 | #define MAX_MEMORY_BUF 8192 /* IO buffer */ | 107 | #define IOBUF_SIZE 8192 /* IO buffer */ |
108 | 108 | ||
109 | #define HEADER_READ_TIMEOUT 60 | 109 | #define HEADER_READ_TIMEOUT 60 |
110 | 110 | ||
@@ -163,7 +163,7 @@ struct globals { | |||
163 | #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR | 163 | #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR |
164 | Htaccess *script_i; /* config script interpreters */ | 164 | Htaccess *script_i; /* config script interpreters */ |
165 | #endif | 165 | #endif |
166 | char *iobuf; /* [MAX_MEMORY_BUF] */ | 166 | char *iobuf; /* [IOBUF_SIZE] */ |
167 | #define hdr_buf bb_common_bufsiz1 | 167 | #define hdr_buf bb_common_bufsiz1 |
168 | char *hdr_ptr; | 168 | char *hdr_ptr; |
169 | int hdr_cnt; | 169 | int hdr_cnt; |
@@ -717,19 +717,6 @@ static char *decodeString(char *orig, int option_d) | |||
717 | return orig; | 717 | return orig; |
718 | } | 718 | } |
719 | 719 | ||
720 | |||
721 | #if ENABLE_FEATURE_HTTPD_CGI | ||
722 | /* | ||
723 | * setenv helpers | ||
724 | */ | ||
725 | static void setenv1(const char *name, const char *value) | ||
726 | { | ||
727 | if (!value) | ||
728 | value = ""; | ||
729 | setenv(name, value, 1); | ||
730 | } | ||
731 | #endif | ||
732 | |||
733 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH | 720 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH |
734 | /* | 721 | /* |
735 | * Decode a base64 data stream as per rfc1521. | 722 | * Decode a base64 data stream as per rfc1521. |
@@ -797,6 +784,13 @@ static int openServer(void) | |||
797 | static void log_and_exit(void) ATTRIBUTE_NORETURN; | 784 | static void log_and_exit(void) ATTRIBUTE_NORETURN; |
798 | static void log_and_exit(void) | 785 | static void log_and_exit(void) |
799 | { | 786 | { |
787 | /* Paranoia. IE said to be buggy. It may send some extra data | ||
788 | * or be confused by us just exiting without SHUT_WR. Oh well. */ | ||
789 | shutdown(1, SHUT_WR); | ||
790 | ndelay_on(0); | ||
791 | while (read(0, iobuf, IOBUF_SIZE) > 0) | ||
792 | continue; | ||
793 | |||
800 | if (verbose > 2) | 794 | if (verbose > 2) |
801 | bb_error_msg("closed"); | 795 | bb_error_msg("closed"); |
802 | _exit(xfunc_error_retval); | 796 | _exit(xfunc_error_retval); |
@@ -915,13 +909,18 @@ static int get_line(void) | |||
915 | iobuf[count] = '\0'; | 909 | iobuf[count] = '\0'; |
916 | return count; | 910 | return count; |
917 | } | 911 | } |
918 | if (count < (MAX_MEMORY_BUF - 1)) /* check overflow */ | 912 | if (count < (IOBUF_SIZE - 1)) /* check overflow */ |
919 | count++; | 913 | count++; |
920 | } | 914 | } |
921 | return count; | 915 | return count; |
922 | } | 916 | } |
923 | 917 | ||
924 | #if ENABLE_FEATURE_HTTPD_CGI | 918 | #if ENABLE_FEATURE_HTTPD_CGI |
919 | static void setenv1(const char *name, const char *value) | ||
920 | { | ||
921 | setenv(name, value ? value : "", 1); | ||
922 | } | ||
923 | |||
925 | /* | 924 | /* |
926 | * Spawn CGI script, forward CGI's stdin/out <=> network | 925 | * Spawn CGI script, forward CGI's stdin/out <=> network |
927 | * | 926 | * |
@@ -1192,8 +1191,8 @@ static void send_cgi_and_exit( | |||
1192 | } | 1191 | } |
1193 | 1192 | ||
1194 | #define PIPESIZE PIPE_BUF | 1193 | #define PIPESIZE PIPE_BUF |
1195 | #if PIPESIZE >= MAX_MEMORY_BUF | 1194 | #if PIPESIZE >= IOBUF_SIZE |
1196 | # error "PIPESIZE >= MAX_MEMORY_BUF" | 1195 | # error "PIPESIZE >= IOBUF_SIZE" |
1197 | #endif | 1196 | #endif |
1198 | if (FD_ISSET(fromCgi.rd, &readSet)) { | 1197 | if (FD_ISSET(fromCgi.rd, &readSet)) { |
1199 | /* There is something to read from CGI */ | 1198 | /* There is something to read from CGI */ |
@@ -1363,7 +1362,7 @@ static void send_file_and_exit(const char *url) | |||
1363 | 1362 | ||
1364 | fallback: | 1363 | fallback: |
1365 | #endif | 1364 | #endif |
1366 | while ((count = safe_read(f, iobuf, MAX_MEMORY_BUF)) > 0) { | 1365 | while ((count = safe_read(f, iobuf, IOBUF_SIZE)) > 0) { |
1367 | ssize_t n = count; | 1366 | ssize_t n = count; |
1368 | count = full_write(1, iobuf, count); | 1367 | count = full_write(1, iobuf, count); |
1369 | if (count != n) | 1368 | if (count != n) |
@@ -1455,12 +1454,13 @@ static int checkPerm(const char *path, const char *request) | |||
1455 | char *pp; | 1454 | char *pp; |
1456 | 1455 | ||
1457 | if (strncmp(p, request, u - request) != 0) { | 1456 | if (strncmp(p, request, u - request) != 0) { |
1458 | /* user uncompared */ | 1457 | /* user doesn't match */ |
1459 | continue; | 1458 | continue; |
1460 | } | 1459 | } |
1461 | pp = strchr(p, ':'); | 1460 | pp = strchr(p, ':'); |
1462 | if (pp && pp[1] == '$' && pp[2] == '1' && | 1461 | if (pp && pp[1] == '$' && pp[2] == '1' |
1463 | pp[3] == '$' && pp[4]) { | 1462 | && pp[3] == '$' && pp[4] |
1463 | ) { | ||
1464 | pp++; | 1464 | pp++; |
1465 | cipher = pw_encrypt(u+1, pp); | 1465 | cipher = pw_encrypt(u+1, pp); |
1466 | if (strcmp(cipher, pp) == 0) | 1466 | if (strcmp(cipher, pp) == 0) |
@@ -1474,7 +1474,7 @@ static int checkPerm(const char *path, const char *request) | |||
1474 | set_remoteuser_var: | 1474 | set_remoteuser_var: |
1475 | remoteuser = strdup(request); | 1475 | remoteuser = strdup(request); |
1476 | if (remoteuser) | 1476 | if (remoteuser) |
1477 | remoteuser[(u - request)] = '\0'; | 1477 | remoteuser[u - request] = '\0'; |
1478 | return 1; /* Ok */ | 1478 | return 1; /* Ok */ |
1479 | } | 1479 | } |
1480 | /* unauthorized */ | 1480 | /* unauthorized */ |
@@ -1521,7 +1521,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
1521 | 1521 | ||
1522 | /* Allocation of iobuf is postponed until now | 1522 | /* Allocation of iobuf is postponed until now |
1523 | * (IOW, server process doesn't need to waste 8k) */ | 1523 | * (IOW, server process doesn't need to waste 8k) */ |
1524 | iobuf = xmalloc(MAX_MEMORY_BUF); | 1524 | iobuf = xmalloc(IOBUF_SIZE); |
1525 | 1525 | ||
1526 | rmt_ip = 0; | 1526 | rmt_ip = 0; |
1527 | if (fromAddr->sa.sa_family == AF_INET) { | 1527 | if (fromAddr->sa.sa_family == AF_INET) { |
@@ -1779,35 +1779,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
1779 | */ | 1779 | */ |
1780 | 1780 | ||
1781 | send_file_and_exit(tptr); | 1781 | send_file_and_exit(tptr); |
1782 | |||
1783 | #if 0 /* Is this needed? Why? */ | ||
1784 | if (DEBUG) | ||
1785 | fprintf(stderr, "closing socket\n"); | ||
1786 | #if ENABLE_FEATURE_HTTPD_CGI | ||
1787 | free(cookie); | ||
1788 | free(content_type); | ||
1789 | free(referer); | ||
1790 | referer = NULL; | ||
1791 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH | ||
1792 | free(remoteuser); | ||
1793 | remoteuser = NULL; | ||
1794 | #endif | ||
1795 | #endif | ||
1796 | /* Properly wait for remote to closed */ | ||
1797 | int retval; | ||
1798 | shutdown(1, SHUT_WR); | ||
1799 | do { | ||
1800 | fd_set s_fd; | ||
1801 | struct timeval tv; | ||
1802 | FD_ZERO(&s_fd); | ||
1803 | FD_SET(0, &s_fd); | ||
1804 | tv.tv_sec = 2; | ||
1805 | tv.tv_usec = 0; | ||
1806 | retval = select(1, &s_fd, NULL, NULL, &tv); | ||
1807 | } while (retval > 0 && read(0, iobuf, sizeof(iobuf) > 0)); | ||
1808 | shutdown(0, SHUT_RD); | ||
1809 | log_and_exit(); | ||
1810 | #endif | ||
1811 | } | 1782 | } |
1812 | 1783 | ||
1813 | /* | 1784 | /* |
@@ -1896,7 +1867,7 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv) | |||
1896 | /* Run a copy of ourself in inetd mode */ | 1867 | /* Run a copy of ourself in inetd mode */ |
1897 | re_exec(argv_copy); | 1868 | re_exec(argv_copy); |
1898 | } | 1869 | } |
1899 | /* parent, or fork failed */ | 1870 | /* parent, or vfork failed */ |
1900 | close(n); | 1871 | close(n); |
1901 | } /* while (1) */ | 1872 | } /* while (1) */ |
1902 | /* never reached */ | 1873 | /* never reached */ |