aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 00:08:39 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-21 00:08:39 +0000
commit6c85ddc8509e4b72ca5b4e47ca5085101a02f07c (patch)
tree319b4dc2de4e7bce9ce374db14394020088a484f
parenta3ee69fa6ccf83c9f3506b6ccbdc9e253df77077 (diff)
downloadbusybox-w32-6c85ddc8509e4b72ca5b4e47ca5085101a02f07c.tar.gz
busybox-w32-6c85ddc8509e4b72ca5b4e47ca5085101a02f07c.tar.bz2
busybox-w32-6c85ddc8509e4b72ca5b4e47ca5085101a02f07c.zip
httpd: add support for directory indexer (cgi-bin/index.cgi)
-rw-r--r--networking/httpd.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 40f37ba07..afcd089b0 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -893,9 +893,8 @@ static int sendHeaders(HttpResponseNum responseNum)
893 responseNum, responseString, 893 responseNum, responseString,
894 responseNum, responseString, infoString); 894 responseNum, responseString, infoString);
895 } 895 }
896#if DEBUG 896 if (DEBUG)
897 fprintf(stderr, "headers: '%s'\n", buf); 897 fprintf(stderr, "headers: '%s'\n", buf);
898#endif
899 return full_write(config->accepted_socket, buf, len); 898 return full_write(config->accepted_socket, buf, len);
900} 899}
901 900
@@ -984,7 +983,7 @@ static int sendCgi(const char *url,
984 if (purl == NULL) 983 if (purl == NULL)
985 _exit(242); 984 _exit(242);
986 985
987 inFd = toCgi[0]; 986 inFd = toCgi[0];
988 outFd = fromCgi[1]; 987 outFd = fromCgi[1];
989 988
990 dup2(inFd, 0); // replace stdin with the pipe 989 dup2(inFd, 0); // replace stdin with the pipe
@@ -1028,7 +1027,7 @@ static int sendCgi(const char *url,
1028 setenv1("REQUEST_URI", purl); 1027 setenv1("REQUEST_URI", purl);
1029 } 1028 }
1030 if (script != NULL) 1029 if (script != NULL)
1031 *script = '\0'; /* reduce /PATH_INFO */ 1030 *script = '\0'; /* cut off /PATH_INFO */
1032 /* SCRIPT_FILENAME required by PHP in CGI mode */ 1031 /* SCRIPT_FILENAME required by PHP in CGI mode */
1033 if (!realpath(purl + 1, realpath_buff)) 1032 if (!realpath(purl + 1, realpath_buff))
1034 goto error_execing_cgi; 1033 goto error_execing_cgi;
@@ -1546,7 +1545,7 @@ static void handleIncoming(void)
1546 *test = '/'; 1545 *test = '/';
1547 } 1546 }
1548 if (blank >= 0) { 1547 if (blank >= 0) {
1549 // read until blank line for HTTP version specified, else parse immediate 1548 /* read until blank line for HTTP version specified, else parse immediate */
1550 while (1) { 1549 while (1) {
1551 alarm(TIMEOUT); 1550 alarm(TIMEOUT);
1552 count = getLine(); 1551 count = getLine();
@@ -1568,7 +1567,7 @@ static void handleIncoming(void)
1568 length = strtol(test, &test, 10); 1567 length = strtol(test, &test, 10);
1569 /* length is "ulong", but we need to pass it to int later */ 1568 /* length is "ulong", but we need to pass it to int later */
1570 /* so we check for negative or too large values in one go: */ 1569 /* so we check for negative or too large values in one go: */
1571 /* (long -> ulong conv will cause negatives to be seen as > INT_MAX) */ 1570 /* (long -> ulong conv caused negatives to be seen as > INT_MAX) */
1572 if (test[0] || errno || length > INT_MAX) 1571 if (test[0] || errno || length > INT_MAX)
1573 goto bail_out; 1572 goto bail_out;
1574 } 1573 }
@@ -1599,14 +1598,14 @@ static void handleIncoming(void)
1599 1598
1600 } /* while extra header reading */ 1599 } /* while extra header reading */
1601 } 1600 }
1602 (void) alarm(0); 1601 alarm(0);
1603 if (config->alarm_signaled) 1602 if (config->alarm_signaled)
1604 break; 1603 break;
1605 1604
1606 if (strcmp(strrchr(url, '/') + 1, httpd_conf) == 0 || ip_allowed == 0) { 1605 if (strcmp(strrchr(url, '/') + 1, httpd_conf) == 0 || ip_allowed == 0) {
1607 /* protect listing [/path]/httpd_conf or IP deny */ 1606 /* protect listing [/path]/httpd_conf or IP deny */
1608#if ENABLE_FEATURE_HTTPD_CGI 1607#if ENABLE_FEATURE_HTTPD_CGI
1609FORBIDDEN: /* protect listing /cgi-bin */ 1608 FORBIDDEN: /* protect listing /cgi-bin */
1610#endif 1609#endif
1611 sendHeaders(HTTP_FORBIDDEN); 1610 sendHeaders(HTTP_FORBIDDEN);
1612 break; 1611 break;
@@ -1631,25 +1630,30 @@ FORBIDDEN: /* protect listing /cgi-bin */
1631#if ENABLE_FEATURE_HTTPD_CGI 1630#if ENABLE_FEATURE_HTTPD_CGI
1632 if (strncmp(test, "cgi-bin", 7) == 0) { 1631 if (strncmp(test, "cgi-bin", 7) == 0) {
1633 if (test[7] == '/' && test[8] == 0) 1632 if (test[7] == '/' && test[8] == 0)
1634 goto FORBIDDEN; // protect listing cgi-bin/ 1633 goto FORBIDDEN; /* protect listing cgi-bin/ */
1635 sendCgi(url, prequest, length, cookie, content_type); 1634 sendCgi(url, prequest, length, cookie, content_type);
1636 } else { 1635 break;
1637 if (prequest != request_GET) 1636 }
1638 sendHeaders(HTTP_NOT_IMPLEMENTED); 1637 if (prequest != request_GET) {
1639 else { 1638 sendHeaders(HTTP_NOT_IMPLEMENTED);
1640#endif /* FEATURE_HTTPD_CGI */ 1639 break;
1641 if (purl[-1] == '/') 1640 }
1642 strcpy(purl, "index.html"); 1641 if (purl[-1] == '/') {
1643 if (stat(test, &sb) == 0) { 1642 if (access("cgi-bin/index.cgi", X_OK) == 0) {
1644 config->ContentLength = sb.st_size; 1643 config->query = url;
1645 config->last_mod = sb.st_mtime; 1644 sendCgi("/cgi-bin/index.cgi", prequest, length, cookie, content_type);
1646 } 1645 break;
1647 sendFile(test);
1648 config->ContentLength = -1;
1649#if ENABLE_FEATURE_HTTPD_CGI
1650 } 1646 }
1651 } 1647 }
1652#endif 1648#endif /* FEATURE_HTTPD_CGI */
1649 if (purl[-1] == '/')
1650 strcpy(purl, "index.html");
1651 if (stat(test, &sb) == 0) {
1652 config->ContentLength = sb.st_size;
1653 config->last_mod = sb.st_mtime;
1654 }
1655 sendFile(test);
1656 config->ContentLength = -1;
1653 } while (0); 1657 } while (0);
1654 1658
1655 bail_out: 1659 bail_out: