aboutsummaryrefslogtreecommitdiff
path: root/networking/httpd.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-05-26 14:07:50 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-05-26 14:07:50 +0000
commit393183dccc4d100366972bdbbdc6e03a77839120 (patch)
treed2e94dac0f1f5da5cb3ecb927b78c4c2a02f4ea6 /networking/httpd.c
parentddfe18df75c15be4a2aadddb241c3b86b1e2968a (diff)
downloadbusybox-w32-393183dccc4d100366972bdbbdc6e03a77839120.tar.gz
busybox-w32-393183dccc4d100366972bdbbdc6e03a77839120.tar.bz2
busybox-w32-393183dccc4d100366972bdbbdc6e03a77839120.zip
Vodz, last_patch_86
Diffstat (limited to 'networking/httpd.c')
-rw-r--r--networking/httpd.c68
1 files changed, 31 insertions, 37 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index e9f4c15bc..ef8263b99 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -60,8 +60,7 @@
60 * .au:audio/basic # additional mime type for audio.au files 60 * .au:audio/basic # additional mime type for audio.au files
61 * 61 *
62 * A/D may be as a/d or allow/deny - first char case unsensitive 62 * A/D may be as a/d or allow/deny - first char case unsensitive
63 * Deny IP rules take precedence over allow rules. Any IP rules after D:* are 63 * Deny IP rules take precedence over allow rules.
64 * ignored.
65 * 64 *
66 * 65 *
67 * The Deny/Allow IP logic: 66 * The Deny/Allow IP logic:
@@ -123,7 +122,7 @@
123#include "busybox.h" 122#include "busybox.h"
124 123
125 124
126static const char httpdVersion[] = "busybox httpd/1.26 18-May-2003"; 125static const char httpdVersion[] = "busybox httpd/1.27 25-May-2003";
127static const char default_path_httpd_conf[] = "/etc"; 126static const char default_path_httpd_conf[] = "/etc";
128static const char httpd_conf[] = "httpd.conf"; 127static const char httpd_conf[] = "httpd.conf";
129static const char home[] = "./"; 128static const char home[] = "./";
@@ -234,6 +233,7 @@ typedef struct
234 time_t last_mod; 233 time_t last_mod;
235 234
236 Htaccess *ip_a_d; /* config allow/deny lines */ 235 Htaccess *ip_a_d; /* config allow/deny lines */
236 int flg_deny_all;
237#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH 237#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
238 Htaccess *auth; /* config user:password lines */ 238 Htaccess *auth; /* config user:password lines */
239#endif 239#endif
@@ -452,16 +452,21 @@ static void parse_conf(const char *path, int flag)
452 /* test for empty or strange line */ 452 /* test for empty or strange line */
453 if (c == NULL || *c == 0) 453 if (c == NULL || *c == 0)
454 continue; 454 continue;
455 if(*c == '*')
456 *c = 0; /* Allow all */
457 p0 = buf; 455 p0 = buf;
458 if((*p0 == 'i') || (*p0 == 'I'))
459 *p0 = 'A'; // version 1.1/1.2 compatibility for ip:
460 if(*p0 == 'a')
461 *p0 = 'A';
462 if(*p0 == 'd') 456 if(*p0 == 'd')
463 *p0 = 'D'; 457 *p0 = 'D';
464 if(*p0 != 'A' && *p0 != 'D' 458 if(*c == '*') {
459 if(*p0 == 'D') {
460 /* memorize deny all */
461 config->flg_deny_all++;
462 }
463 /* skip default other "word:*" config lines */
464 continue;
465 }
466
467 if(*p0 == 'a')
468 *p0 = 'A';
469 else if(*p0 != 'D'
465#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH 470#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
466 && *p0 != '/' 471 && *p0 != '/'
467#endif 472#endif
@@ -471,17 +476,8 @@ static void parse_conf(const char *path, int flag)
471 ) 476 )
472 continue; 477 continue;
473 478
474 if(*p0 == 'A' && *c == 0) {
475 /* skip default A:* */
476 continue;
477 }
478 p0 = buf;
479#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH 479#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
480 if(*p0 == '/') { 480 if(*p0 == '/') {
481 if(*c == 0) {
482 /* skip /path:* */
483 continue;
484 }
485 /* make full path from httpd root / curent_path / config_line_path */ 481 /* make full path from httpd root / curent_path / config_line_path */
486 cf = flag == SUBDIR_PARSE ? path : ""; 482 cf = flag == SUBDIR_PARSE ? path : "";
487 p0 = malloc(strlen(cf) + (c - buf) + 2 + strlen(c)); 483 p0 = malloc(strlen(cf) + (c - buf) + 2 + strlen(c));
@@ -532,12 +528,12 @@ static void parse_conf(const char *path, int flag)
532 free(p0); 528 free(p0);
533#endif 529#endif
534 if(*cf == 'A' || *cf == 'D') { 530 if(*cf == 'A' || *cf == 'D') {
535 if(*cf == 'D' && *c) { 531 if(*cf == 'D') {
536 /* Deny:form_IP move top */ 532 /* Deny:form_IP move top */
537 cur->next = config->ip_a_d; 533 cur->next = config->ip_a_d;
538 config->ip_a_d = cur; 534 config->ip_a_d = cur;
539 } else { 535 } else {
540 /* add to bottom current IP config line */ 536 /* add to bottom A:form_IP config line */
541 Htaccess *prev_IP = config->ip_a_d; 537 Htaccess *prev_IP = config->ip_a_d;
542 538
543 if(prev_IP == NULL) { 539 if(prev_IP == NULL) {
@@ -573,12 +569,11 @@ static void parse_conf(const char *path, int flag)
573 cur->next = hti; 569 cur->next = hti;
574 if(prev_hti != hti) { 570 if(prev_hti != hti) {
575 prev_hti->next = cur; 571 prev_hti->next = cur;
576 break;
577 } else { 572 } else {
578 /* insert as top */ 573 /* insert as top */
579 config->auth = cur; 574 config->auth = cur;
580 break;
581 } 575 }
576 break;
582 } 577 }
583 if(prev_hti != hti) 578 if(prev_hti != hti)
584 prev_hti = prev_hti->next; 579 prev_hti = prev_hti->next;
@@ -695,18 +690,16 @@ static void addEnv(const char *name_before_underline,
695 const char *name_after_underline, const char *value) 690 const char *name_after_underline, const char *value)
696{ 691{
697 char *s; 692 char *s;
693 const char *underline;
698 694
699 if (config->envCount >= ENVSIZE) 695 if (config->envCount >= ENVSIZE)
700 return; 696 return;
701 if (!value) 697 if (!value)
702 value = ""; 698 value = "";
703 s = malloc(strlen(name_before_underline) + strlen(name_after_underline) + 699 underline = *name_after_underline ? "_" : "";
704 strlen(value) + 3); 700 asprintf(&s, "%s%s%s=%s", name_before_underline, underline,
705 if (s) {
706 const char *underline = *name_after_underline ? "_" : "";
707
708 sprintf(s,"%s%s%s=%s", name_before_underline, underline,
709 name_after_underline, value); 701 name_after_underline, value);
702 if(s) {
710 config->envp[config->envCount++] = s; 703 config->envp[config->envCount++] = s;
711 config->envp[config->envCount] = 0; 704 config->envp[config->envCount] = 0;
712 } 705 }
@@ -764,11 +757,11 @@ static void addEnvCgi(const char *pargs)
764 *args++ = 0; 757 *args++ = 0;
765 addEnv("CGI", name, decodeString(value, 1)); 758 addEnv("CGI", name, decodeString(value, 1));
766 if (*namelist) strcat(namelist, " "); 759 if (*namelist) strcat(namelist, " ");
767 strcat(namelist,name); 760 strcat(namelist, name);
768 } 761 }
769 free(memargs); 762 free(memargs);
770 if (namelist) { 763 if (namelist) {
771 addEnv("CGI","ARGLIST_",namelist); 764 addEnv("CGI", "ARGLIST_", namelist);
772 free(namelist); 765 free(namelist);
773 } 766 }
774} 767}
@@ -1337,6 +1330,8 @@ static int checkPerm(const char *path, const char *request)
1337 } 1330 }
1338 } /* for */ 1331 } /* for */
1339 1332
1333 if(ipaddr)
1334 return config->flg_deny_all;
1340 return prev == NULL; 1335 return prev == NULL;
1341} 1336}
1342 1337
@@ -1359,7 +1354,7 @@ static int checkPermIP(const char *request)
1359 } 1354 }
1360 1355
1361 /* if uncofigured, return 1 - access from all */ 1356 /* if uncofigured, return 1 - access from all */
1362 return 1; 1357 return config->flg_deny_all;
1363} 1358}
1364#define checkPerm(null, request) checkPermIP(request) 1359#define checkPerm(null, request) checkPermIP(request)
1365#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */ 1360#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */
@@ -1788,9 +1783,7 @@ int httpd_main(int argc, char *argv[])
1788 config->debugHttpd = 1; 1783 config->debugHttpd = 1;
1789 break; 1784 break;
1790 case 'p': 1785 case 'p':
1791 config->port = atoi(optarg); 1786 config->port = bb_xgetlarg(optarg, 10, 1, 0xffff);
1792 if(config->port <= 0 || config->port > 0xffff)
1793 bb_error_msg_and_die("invalid %s for -p", optarg);
1794 break; 1787 break;
1795#endif 1788#endif
1796 case 'd': 1789 case 'd':
@@ -1854,10 +1847,11 @@ int httpd_main(int argc, char *argv[])
1854#ifdef TEST 1847#ifdef TEST
1855 if (numTestArgs) 1848 if (numTestArgs)
1856 { 1849 {
1857 if (strcmp(testArgs[0],"ip") == 0) testArgs[0] = 0; 1850 int result;
1851 if (strcmp(testArgs[0], "ip") == 0) testArgs[0] = 0;
1858 if (numTestArgs > 2) 1852 if (numTestArgs > 2)
1859 parse_conf(testArgs[2], SUBDIR_PARSE); 1853 parse_conf(testArgs[2], SUBDIR_PARSE);
1860 int result = printf("%d\n",checkPerm(testArgs[0],testArgs[1])); 1854 result = printf("%d\n", checkPerm(testArgs[0], testArgs[1]));
1861 return result; 1855 return result;
1862 } 1856 }
1863#endif 1857#endif