aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-16 18:04:43 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-16 18:04:43 +0000
commitb3a071543d777b1f6f7f31a326fefd17f1cf4951 (patch)
treee1b5c0ba10134c67db5051de3b36c4d2c9bf3189
parentd4f3d1a4bd17dbcebf229ee72133e713d7632284 (diff)
downloadbusybox-w32-b3a071543d777b1f6f7f31a326fefd17f1cf4951.tar.gz
busybox-w32-b3a071543d777b1f6f7f31a326fefd17f1cf4951.tar.bz2
busybox-w32-b3a071543d777b1f6f7f31a326fefd17f1cf4951.zip
httpd: reduce ifdef forest. comment out redundant PATH setting
-rw-r--r--include/usage.h2
-rw-r--r--networking/httpd.c162
2 files changed, 77 insertions, 87 deletions
diff --git a/include/usage.h b/include/usage.h
index ef3fb63d3..f1b4b351a 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1196,7 +1196,7 @@ USE_FEATURE_DATE_ISOFMT( \
1196 "Options:\n" \ 1196 "Options:\n" \
1197 "\t-c FILE\t\tSpecifies configuration file. (default httpd.conf)\n" \ 1197 "\t-c FILE\t\tSpecifies configuration file. (default httpd.conf)\n" \
1198 "\t-p PORT\t\tServer port (default 80)\n" \ 1198 "\t-p PORT\t\tServer port (default 80)\n" \
1199 "\t-i\t\tAssume that we are started frim inetd\n" \ 1199 "\t-i\t\tAssume that we are started from inetd\n" \
1200 "\t-f\t\tDo not daemonize\n" \ 1200 "\t-f\t\tDo not daemonize\n" \
1201 USE_FEATURE_HTTPD_SETUID("\t-u USER[:GRP]\tSet uid/gid after binding to port\n") \ 1201 USE_FEATURE_HTTPD_SETUID("\t-u USER[:GRP]\tSet uid/gid after binding to port\n") \
1202 USE_FEATURE_HTTPD_BASIC_AUTH("\t-r REALM\tAuthentication Realm for Basic Authentication\n") \ 1202 USE_FEATURE_HTTPD_BASIC_AUTH("\t-r REALM\tAuthentication Realm for Basic Authentication\n") \
diff --git a/networking/httpd.c b/networking/httpd.c
index c0b740f6f..3cfbdb979 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -652,7 +652,7 @@ static char *encodeString(const char *string)
652 *p = 0; 652 *p = 0;
653 return out; 653 return out;
654} 654}
655#endif /* CONFIG_FEATURE_HTTPD_ENCODE_URL_STR */ 655#endif /* FEATURE_HTTPD_ENCODE_URL_STR */
656 656
657/**************************************************************************** 657/****************************************************************************
658 * 658 *
@@ -1018,7 +1018,7 @@ static int sendCgi(const char *url,
1018 *script = '/'; /* is directory, find next '/' */ 1018 *script = '/'; /* is directory, find next '/' */
1019 } 1019 }
1020 setenv1("PATH_INFO", script); /* set /PATH_INFO or "" */ 1020 setenv1("PATH_INFO", script); /* set /PATH_INFO or "" */
1021 setenv1("PATH", getenv("PATH")); /* Huh?? */ 1021 /* setenv1("PATH", getenv("PATH")); redundant */
1022 setenv1("REQUEST_METHOD", request); 1022 setenv1("REQUEST_METHOD", request);
1023 if (config->query) { 1023 if (config->query) {
1024 char *uri = alloca(strlen(purl) + 2 + strlen(config->query)); 1024 char *uri = alloca(strlen(purl) + 2 + strlen(config->query));
@@ -1145,12 +1145,10 @@ static int sendCgi(const char *url,
1145 if (nfound <= 0) { 1145 if (nfound <= 0) {
1146 if (waitpid(pid, &status, WNOHANG) > 0) { 1146 if (waitpid(pid, &status, WNOHANG) > 0) {
1147 close(inFd); 1147 close(inFd);
1148#if DEBUG 1148 if (DEBUG && WIFEXITED(status))
1149 if (WIFEXITED(status))
1150 bb_error_msg("piped has exited with status=%d", WEXITSTATUS(status)); 1149 bb_error_msg("piped has exited with status=%d", WEXITSTATUS(status));
1151 if (WIFSIGNALED(status)) 1150 if (DEBUG && WIFSIGNALED(status))
1152 bb_error_msg("piped has exited with signal=%d", WTERMSIG(status)); 1151 bb_error_msg("piped has exited with signal=%d", WTERMSIG(status));
1153#endif
1154 break; 1152 break;
1155 } 1153 }
1156 } else if (post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) { 1154 } else if (post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) {
@@ -1205,16 +1203,15 @@ static int sendCgi(const char *url,
1205 if (full_write(s, rbuf, count) != count) 1203 if (full_write(s, rbuf, count) != count)
1206 break; 1204 break;
1207 1205
1208#if DEBUG 1206 if (DEBUG)
1209 fprintf(stderr, "cgi read %d bytes\n", count); 1207 fprintf(stderr, "cgi read %d bytes\n", count);
1210#endif
1211 } 1208 }
1212 } 1209 }
1213 } 1210 }
1214 } 1211 }
1215 return 0; 1212 return 0;
1216} 1213}
1217#endif /* CONFIG_FEATURE_HTTPD_CGI */ 1214#endif /* FEATURE_HTTPD_CGI */
1218 1215
1219/**************************************************************************** 1216/****************************************************************************
1220 * 1217 *
@@ -1256,12 +1253,11 @@ static int sendFile(const char *url)
1256 } 1253 }
1257 } 1254 }
1258 } 1255 }
1259#endif /* CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES */ 1256#endif /* FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES */
1260 1257
1261#if DEBUG 1258 if (DEBUG)
1262 fprintf(stderr, "sending file '%s' content-type: %s\n", 1259 fprintf(stderr, "sending file '%s' content-type: %s\n",
1263 url, config->found_mime_type); 1260 url, config->found_mime_type);
1264#endif
1265 1261
1266 f = open(url, O_RDONLY); 1262 f = open(url, O_RDONLY);
1267 if (f >= 0) { 1263 if (f >= 0) {
@@ -1269,15 +1265,15 @@ static int sendFile(const char *url)
1269 char *buf = config->buf; 1265 char *buf = config->buf;
1270 1266
1271 sendHeaders(HTTP_OK); 1267 sendHeaders(HTTP_OK);
1268 /* TODO: sendfile() */
1272 while ((count = full_read(f, buf, MAX_MEMORY_BUFF)) > 0) { 1269 while ((count = full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
1273 if (full_write(config->accepted_socket, buf, count) != count) 1270 if (full_write(config->accepted_socket, buf, count) != count)
1274 break; 1271 break;
1275 } 1272 }
1276 close(f); 1273 close(f);
1277 } else { 1274 } else {
1278#if DEBUG 1275 if (DEBUG)
1279 bb_perror_msg("cannot open '%s'", url); 1276 bb_perror_msg("cannot open '%s'", url);
1280#endif
1281 sendHeaders(HTTP_NOT_FOUND); 1277 sendHeaders(HTTP_NOT_FOUND);
1282 } 1278 }
1283 1279
@@ -1290,18 +1286,18 @@ static int checkPermIP(void)
1290 1286
1291 /* This could stand some work */ 1287 /* This could stand some work */
1292 for (cur = config->ip_a_d; cur; cur = cur->next) { 1288 for (cur = config->ip_a_d; cur; cur = cur->next) {
1293#if DEBUG 1289 if (DEBUG)
1294 fprintf(stderr, "checkPermIP: '%s' ? ", config->rmt_ip_str); 1290 fprintf(stderr, "checkPermIP: '%s' ? ", config->rmt_ip_str);
1295 fprintf(stderr, "'%u.%u.%u.%u/%u.%u.%u.%u'\n", 1291 if (DEBUG)
1292 fprintf(stderr, "'%u.%u.%u.%u/%u.%u.%u.%u'\n",
1296 (unsigned char)(cur->ip >> 24), 1293 (unsigned char)(cur->ip >> 24),
1297 (unsigned char)(cur->ip >> 16), 1294 (unsigned char)(cur->ip >> 16),
1298 (unsigned char)(cur->ip >> 8), 1295 (unsigned char)(cur->ip >> 8),
1299 cur->ip & 0xff, 1296 cur->ip & 0xff,
1300 (unsigned char)(cur->mask >> 24), 1297 (unsigned char)(cur->mask >> 24),
1301 (unsigned char)(cur->mask >> 16), 1298 (unsigned char)(cur->mask >> 16),
1302 (unsigned char)(cur->mask >> 8), 1299 (unsigned char)(cur->mask >> 8),
1303 cur->mask & 0xff); 1300 cur->mask & 0xff);
1304#endif
1305 if ((config->rmt_ip & cur->mask) == cur->ip) 1301 if ((config->rmt_ip & cur->mask) == cur->ip)
1306 return cur->allow_deny == 'A'; /* Allow/Deny */ 1302 return cur->allow_deny == 'A'; /* Allow/Deny */
1307 } 1303 }
@@ -1338,67 +1334,64 @@ static int checkPerm(const char *path, const char *request)
1338 1334
1339 /* This could stand some work */ 1335 /* This could stand some work */
1340 for (cur = config->auth; cur; cur = cur->next) { 1336 for (cur = config->auth; cur; cur = cur->next) {
1337 size_t l;
1338
1341 p0 = cur->before_colon; 1339 p0 = cur->before_colon;
1342 if (prev != NULL && strcmp(prev, p0) != 0) 1340 if (prev != NULL && strcmp(prev, p0) != 0)
1343 continue; /* find next identical */ 1341 continue; /* find next identical */
1344 p = cur->after_colon; 1342 p = cur->after_colon;
1345#if DEBUG 1343 if (DEBUG)
1346 fprintf(stderr, "checkPerm: '%s' ? '%s'\n", p0, request); 1344 fprintf(stderr, "checkPerm: '%s' ? '%s'\n", p0, request);
1347#endif 1345
1348 { 1346 l = strlen(p0);
1349 size_t l = strlen(p0); 1347 if (strncmp(p0, path, l) == 0
1350 1348 && (l == 1 || path[l] == '/' || path[l] == '\0')
1351 if (strncmp(p0, path, l) == 0 && 1349 ) {
1352 (l == 1 || path[l] == '/' || path[l] == 0)) { 1350 char *u;
1353 char *u; 1351 /* path match found. Check request */
1354 /* path match found. Check request */ 1352 /* for check next /path:user:password */
1355 /* for check next /path:user:password */ 1353 prev = p0;
1356 prev = p0; 1354 u = strchr(request, ':');
1357 u = strchr(request, ':'); 1355 if (u == NULL) {
1358 if (u == NULL) { 1356 /* bad request, ':' required */
1359 /* bad request, ':' required */ 1357 break;
1360 break; 1358 }
1361 }
1362 1359
1363#if ENABLE_FEATURE_HTTPD_AUTH_MD5 1360 if (ENABLE_FEATURE_HTTPD_AUTH_MD5) {
1364 { 1361 char *cipher;
1365 char *cipher; 1362 char *pp;
1366 char *pp;
1367 1363
1368 if (strncmp(p, request, u-request) != 0) { 1364 if (strncmp(p, request, u-request) != 0) {
1369 /* user uncompared */ 1365 /* user uncompared */
1370 continue; 1366 continue;
1371 }
1372 pp = strchr(p, ':');
1373 if (pp && pp[1] == '$' && pp[2] == '1' &&
1374 pp[3] == '$' && pp[4]) {
1375 pp++;
1376 cipher = pw_encrypt(u+1, pp);
1377 if (strcmp(cipher, pp) == 0)
1378 goto set_remoteuser_var; /* Ok */
1379 /* unauthorized */
1380 continue;
1381 }
1382 } 1367 }
1383#endif 1368 pp = strchr(p, ':');
1384 if (strcmp(p, request) == 0) { 1369 if (pp && pp[1] == '$' && pp[2] == '1' &&
1385#if ENABLE_FEATURE_HTTPD_AUTH_MD5 1370 pp[3] == '$' && pp[4]) {
1386set_remoteuser_var: 1371 pp++;
1387#endif 1372 cipher = pw_encrypt(u+1, pp);
1388 config->remoteuser = strdup(request); 1373 if (strcmp(cipher, pp) == 0)
1389 if (config->remoteuser) 1374 goto set_remoteuser_var; /* Ok */
1390 config->remoteuser[(u - request)] = 0; 1375 /* unauthorized */
1391 return 1; /* Ok */ 1376 continue;
1392 } 1377 }
1393 /* unauthorized */
1394 } 1378 }
1379
1380 if (strcmp(p, request) == 0) {
1381set_remoteuser_var:
1382 config->remoteuser = strdup(request);
1383 if (config->remoteuser)
1384 config->remoteuser[(u - request)] = 0;
1385 return 1; /* Ok */
1386 }
1387 /* unauthorized */
1395 } 1388 }
1396 } /* for */ 1389 } /* for */
1397 1390
1398 return prev == NULL; 1391 return prev == NULL;
1399} 1392}
1400 1393
1401#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */ 1394#endif /* FEATURE_HTTPD_BASIC_AUTH */
1402 1395
1403/**************************************************************************** 1396/****************************************************************************
1404 * 1397 *
@@ -1539,9 +1532,8 @@ BAD_REQUEST:
1539 config->found_moved_temporarily = url; 1532 config->found_moved_temporarily = url;
1540 } 1533 }
1541 } 1534 }
1542#if DEBUG 1535 if (DEBUG)
1543 fprintf(stderr, "url='%s', args=%s\n", url, config->query); 1536 fprintf(stderr, "url='%s', args=%s\n", url, config->query);
1544#endif
1545 1537
1546 test = url; 1538 test = url;
1547 ip_allowed = checkPermIP(); 1539 ip_allowed = checkPermIP();
@@ -1563,9 +1555,8 @@ BAD_REQUEST:
1563 if (count <= 0) 1555 if (count <= 0)
1564 break; 1556 break;
1565 1557
1566#if DEBUG 1558 if (DEBUG)
1567 fprintf(stderr, "Header: '%s'\n", buf); 1559 fprintf(stderr, "header: '%s'\n", buf);
1568#endif
1569 1560
1570#if ENABLE_FEATURE_HTTPD_CGI 1561#if ENABLE_FEATURE_HTTPD_CGI
1571 /* try and do our best to parse more lines */ 1562 /* try and do our best to parse more lines */
@@ -1602,7 +1593,7 @@ BAD_REQUEST:
1602 decodeBase64(test); 1593 decodeBase64(test);
1603 credentials = checkPerm(url, test); 1594 credentials = checkPerm(url, test);
1604 } 1595 }
1605#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */ 1596#endif /* FEATURE_HTTPD_BASIC_AUTH */
1606 1597
1607 } /* while extra header reading */ 1598 } /* while extra header reading */
1608 } 1599 }
@@ -1611,9 +1602,9 @@ BAD_REQUEST:
1611 break; 1602 break;
1612 1603
1613 if (strcmp(strrchr(url, '/') + 1, httpd_conf) == 0 || ip_allowed == 0) { 1604 if (strcmp(strrchr(url, '/') + 1, httpd_conf) == 0 || ip_allowed == 0) {
1614 /* protect listing [/path]/httpd_conf or IP deny */ 1605 /* protect listing [/path]/httpd_conf or IP deny */
1615#if ENABLE_FEATURE_HTTPD_CGI 1606#if ENABLE_FEATURE_HTTPD_CGI
1616FORBIDDEN: /* protect listing /cgi-bin */ 1607FORBIDDEN: /* protect listing /cgi-bin */
1617#endif 1608#endif
1618 sendHeaders(HTTP_FORBIDDEN); 1609 sendHeaders(HTTP_FORBIDDEN);
1619 break; 1610 break;
@@ -1648,7 +1639,7 @@ FORBIDDEN: /* protect listing /cgi-bin */
1648 if (prequest != request_GET) 1639 if (prequest != request_GET)
1649 sendHeaders(HTTP_NOT_IMPLEMENTED); 1640 sendHeaders(HTTP_NOT_IMPLEMENTED);
1650 else { 1641 else {
1651#endif /* CONFIG_FEATURE_HTTPD_CGI */ 1642#endif /* FEATURE_HTTPD_CGI */
1652 if (purl[-1] == '/') 1643 if (purl[-1] == '/')
1653 strcpy(purl, "index.html"); 1644 strcpy(purl, "index.html");
1654 if (stat(test, &sb) == 0) { 1645 if (stat(test, &sb) == 0) {
@@ -1663,17 +1654,16 @@ FORBIDDEN: /* protect listing /cgi-bin */
1663#endif 1654#endif
1664 } while (0); 1655 } while (0);
1665 1656
1666# if DEBUG 1657 if (DEBUG)
1667 fprintf(stderr, "closing socket\n\n"); 1658 fprintf(stderr, "closing socket\n\n");
1668# endif 1659#if ENABLE_FEATURE_HTTPD_CGI
1669# if ENABLE_FEATURE_HTTPD_CGI
1670 free(cookie); 1660 free(cookie);
1671 free(content_type); 1661 free(content_type);
1672 free(config->referer); config->referer = NULL; 1662 free(config->referer); config->referer = NULL;
1673# if ENABLE_FEATURE_HTTPD_BASIC_AUTH 1663# if ENABLE_FEATURE_HTTPD_BASIC_AUTH
1674 free(config->remoteuser); config->remoteuser = NULL; 1664 free(config->remoteuser); config->remoteuser = NULL;
1675# endif
1676# endif 1665# endif
1666#endif
1677 shutdown(config->accepted_socket, SHUT_WR); 1667 shutdown(config->accepted_socket, SHUT_WR);
1678 1668
1679 /* Properly wait for remote to closed */ 1669 /* Properly wait for remote to closed */
@@ -1742,7 +1732,7 @@ static int miniHttpd(int server)
1742 bb_error_msg("connection from IP=%s, port %u", 1732 bb_error_msg("connection from IP=%s, port %u",
1743 config->rmt_ip_str, config->port); 1733 config->rmt_ip_str, config->port);
1744#endif 1734#endif
1745#endif /* CONFIG_FEATURE_HTTPD_CGI */ 1735#endif /* FEATURE_HTTPD_CGI */
1746 1736
1747 /* set the KEEPALIVE option to cull dead connections */ 1737 /* set the KEEPALIVE option to cull dead connections */
1748 on = 1; 1738 on = 1;
@@ -1779,7 +1769,7 @@ static int miniHttpd_inetd(void)
1779 (unsigned char)(config->rmt_ip >> 24), 1769 (unsigned char)(config->rmt_ip >> 24),
1780 (unsigned char)(config->rmt_ip >> 16), 1770 (unsigned char)(config->rmt_ip >> 16),
1781 (unsigned char)(config->rmt_ip >> 8), 1771 (unsigned char)(config->rmt_ip >> 8),
1782 config->rmt_ip & 0xff); 1772 config->rmt_ip & 0xff);
1783#endif 1773#endif
1784 config->port = ntohs(fromAddrLen.sin_port); 1774 config->port = ntohs(fromAddrLen.sin_port);
1785 handleIncoming(); 1775 handleIncoming();