diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-06-26 09:05:32 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-06-26 09:05:32 +0000 |
commit | a3bb3e6e0b80c5c905e8088b44be9b850c876b88 (patch) | |
tree | a3bff17bd1a15becbd989f510127bae6c895fb2c | |
parent | fd10c70521203bfbb5d87a2e66048ffab1f13c4c (diff) | |
download | busybox-w32-a3bb3e6e0b80c5c905e8088b44be9b850c876b88.tar.gz busybox-w32-a3bb3e6e0b80c5c905e8088b44be9b850c876b88.tar.bz2 busybox-w32-a3bb3e6e0b80c5c905e8088b44be9b850c876b88.zip |
Geir Thomassen wrote, regarding networking/httpd.c line 1358
Hello, I think the test for an unconfigured httpd is wrong in
the CVS (busybox-unstable-20030620.tar.bz2)
flg_deny_all is default 0
vodz then wrote:
Oops. You are right.
Also, this mistake haved from two place.
Last patch rewroted to my new get_ularg() function for overcompensate size
from this error found ;-)
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/login.c | 2 | ||||
-rw-r--r-- | libbb/xgetlarg.c | 2 | ||||
-rw-r--r-- | networking/httpd.c | 142 |
4 files changed, 73 insertions, 76 deletions
diff --git a/include/libbb.h b/include/libbb.h index 6f8a5040c..7b3ac4b85 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -131,7 +131,7 @@ extern int recursive_action(const char *fileName, int recurse, | |||
131 | void* userData); | 131 | void* userData); |
132 | 132 | ||
133 | extern int bb_parse_mode( const char* s, mode_t* theMode); | 133 | extern int bb_parse_mode( const char* s, mode_t* theMode); |
134 | extern long bb_xgetlarg(char *arg, int base, long lower, long upper); | 134 | extern long bb_xgetlarg(const char *arg, int base, long lower, long upper); |
135 | 135 | ||
136 | extern unsigned long bb_baud_to_value(speed_t speed); | 136 | extern unsigned long bb_baud_to_value(speed_t speed); |
137 | extern speed_t bb_value_to_baud(unsigned long value); | 137 | extern speed_t bb_value_to_baud(unsigned long value); |
@@ -162,6 +162,7 @@ extern void bb_fflush_stdout_and_exit(int retval) __attribute__ ((noreturn)); | |||
162 | extern const char *bb_opt_complementaly; | 162 | extern const char *bb_opt_complementaly; |
163 | extern const struct option *bb_applet_long_options; | 163 | extern const struct option *bb_applet_long_options; |
164 | extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...); | 164 | extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...); |
165 | |||
165 | //#warning rename? | 166 | //#warning rename? |
166 | extern FILE *bb_wfopen_input(const char *filename); | 167 | extern FILE *bb_wfopen_input(const char *filename); |
167 | 168 | ||
diff --git a/libbb/login.c b/libbb/login.c index 67636e6b5..3f67a819a 100644 --- a/libbb/login.c +++ b/libbb/login.c | |||
@@ -45,7 +45,7 @@ void print_login_issue(const char *issue_file, const char *tty) | |||
45 | time(&t); | 45 | time(&t); |
46 | uname(&uts); | 46 | uname(&uts); |
47 | 47 | ||
48 | puts(""); /* start a new line */ | 48 | puts("\r"); /* start a new line */ |
49 | 49 | ||
50 | if ((fd = fopen(issue_file, "r"))) { | 50 | if ((fd = fopen(issue_file, "r"))) { |
51 | while ((c = fgetc(fd)) != EOF) { | 51 | while ((c = fgetc(fd)) != EOF) { |
diff --git a/libbb/xgetlarg.c b/libbb/xgetlarg.c index 06e776dc9..c1bfa277a 100644 --- a/libbb/xgetlarg.c +++ b/libbb/xgetlarg.c | |||
@@ -13,7 +13,7 @@ | |||
13 | 13 | ||
14 | #include "busybox.h" | 14 | #include "busybox.h" |
15 | 15 | ||
16 | extern long bb_xgetlarg(char *arg, int base, long lower, long upper) | 16 | extern long bb_xgetlarg(const char *arg, int base, long lower, long upper) |
17 | { | 17 | { |
18 | long result; | 18 | long result; |
19 | char *endptr; | 19 | char *endptr; |
diff --git a/networking/httpd.c b/networking/httpd.c index 43b489fac..d3d88fcb6 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -122,7 +122,7 @@ | |||
122 | #include "busybox.h" | 122 | #include "busybox.h" |
123 | 123 | ||
124 | 124 | ||
125 | static const char httpdVersion[] = "busybox httpd/1.27 25-May-2003"; | 125 | static const char httpdVersion[] = "busybox httpd/1.28 22-Jun-2003"; |
126 | static const char default_path_httpd_conf[] = "/etc"; | 126 | static const char default_path_httpd_conf[] = "/etc"; |
127 | static const char httpd_conf[] = "httpd.conf"; | 127 | static const char httpd_conf[] = "httpd.conf"; |
128 | static const char home[] = "./"; | 128 | static const char home[] = "./"; |
@@ -647,11 +647,12 @@ static char *encodeString(const char *string) | |||
647 | * $Errors: None | 647 | * $Errors: None |
648 | * | 648 | * |
649 | ****************************************************************************/ | 649 | ****************************************************************************/ |
650 | static char *decodeString(char *string, int flag_plus_to_space) | 650 | static char *decodeString(char *orig, int flag_plus_to_space) |
651 | { | 651 | { |
652 | /* note that decoded string is always shorter than original */ | 652 | /* note that decoded string is always shorter than original */ |
653 | char *orig = string; | 653 | char *string = orig; |
654 | char *ptr = string; | 654 | char *ptr = string; |
655 | |||
655 | while (*ptr) | 656 | while (*ptr) |
656 | { | 657 | { |
657 | if (*ptr == '+' && flag_plus_to_space) { *string++ = ' '; ptr++; } | 658 | if (*ptr == '+' && flag_plus_to_space) { *string++ = ' '; ptr++; } |
@@ -706,6 +707,7 @@ static void addEnv(const char *name_before_underline, | |||
706 | } | 707 | } |
707 | } | 708 | } |
708 | 709 | ||
710 | #if defined(CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV) || !defined(CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY) | ||
709 | /* set environs SERVER_PORT and REMOTE_PORT */ | 711 | /* set environs SERVER_PORT and REMOTE_PORT */ |
710 | static void addEnvPort(const char *port_name) | 712 | static void addEnvPort(const char *port_name) |
711 | { | 713 | { |
@@ -714,6 +716,7 @@ static void addEnvPort(const char *port_name) | |||
714 | sprintf(buf, "%u", config->port); | 716 | sprintf(buf, "%u", config->port); |
715 | addEnv(port_name, "PORT", buf); | 717 | addEnv(port_name, "PORT", buf); |
716 | } | 718 | } |
719 | #endif | ||
717 | #endif /* CONFIG_FEATURE_HTTPD_CGI */ | 720 | #endif /* CONFIG_FEATURE_HTTPD_CGI */ |
718 | 721 | ||
719 | #ifdef CONFIG_FEATURE_HTTPD_SET_CGI_VARS_TO_ENV | 722 | #ifdef CONFIG_FEATURE_HTTPD_SET_CGI_VARS_TO_ENV |
@@ -1332,7 +1335,7 @@ static int checkPerm(const char *path, const char *request) | |||
1332 | } /* for */ | 1335 | } /* for */ |
1333 | 1336 | ||
1334 | if(ipaddr) | 1337 | if(ipaddr) |
1335 | return config->flg_deny_all; | 1338 | return !config->flg_deny_all; |
1336 | return prev == NULL; | 1339 | return prev == NULL; |
1337 | } | 1340 | } |
1338 | 1341 | ||
@@ -1355,7 +1358,7 @@ static int checkPermIP(const char *request) | |||
1355 | } | 1358 | } |
1356 | 1359 | ||
1357 | /* if uncofigured, return 1 - access from all */ | 1360 | /* if uncofigured, return 1 - access from all */ |
1358 | return config->flg_deny_all; | 1361 | return !config->flg_deny_all; |
1359 | } | 1362 | } |
1360 | #define checkPerm(null, request) checkPermIP(request) | 1363 | #define checkPerm(null, request) checkPermIP(request) |
1361 | #endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */ | 1364 | #endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */ |
@@ -1675,9 +1678,6 @@ static int miniHttpd(int server) | |||
1675 | exit(0); | 1678 | exit(0); |
1676 | } | 1679 | } |
1677 | close(s); | 1680 | close(s); |
1678 | #ifdef TEST | ||
1679 | return 0; // exit after processing one request | ||
1680 | #endif | ||
1681 | } | 1681 | } |
1682 | } | 1682 | } |
1683 | } // while (1) | 1683 | } // while (1) |
@@ -1721,16 +1721,52 @@ static void sighup_handler(int sig) | |||
1721 | } | 1721 | } |
1722 | #endif | 1722 | #endif |
1723 | 1723 | ||
1724 | |||
1725 | static const char httpd_opts[]="c:d:h:" | ||
1726 | #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR | ||
1727 | "e:" | ||
1728 | #define OPT_INC_1 1 | ||
1729 | #else | ||
1730 | #define OPT_INC_1 0 | ||
1731 | #endif | ||
1732 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH | ||
1733 | "r:" | ||
1734 | #define OPT_INC_2 1 | ||
1735 | #else | ||
1736 | #define OPT_INC_2 0 | ||
1737 | #endif | ||
1738 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | ||
1739 | "p:v" | ||
1740 | #ifdef CONFIG_FEATURE_HTTPD_SETUID | ||
1741 | "u:" | ||
1742 | #endif | ||
1743 | #endif | ||
1744 | ; | ||
1745 | |||
1746 | #define OPT_CONFIG_FILE (1<<0) | ||
1747 | #define OPT_DECODE_URL (1<<1) | ||
1748 | #define OPT_HOME_HTTPD (1<<2) | ||
1749 | #define OPT_ENCODE_URL (1<<(2+OPT_INC_1)) | ||
1750 | #define OPT_REALM (1<<(2+OPT_INC_1+OPT_INC_2)) | ||
1751 | #define OPT_PORT (1<<(3+OPT_INC_1+OPT_INC_2)) | ||
1752 | #define OPT_DEBUG (1<<(4+OPT_INC_1+OPT_INC_2)) | ||
1753 | #define OPT_SETUID (1<<(5+OPT_INC_1+OPT_INC_2)) | ||
1754 | |||
1755 | |||
1724 | #ifdef HTTPD_STANDALONE | 1756 | #ifdef HTTPD_STANDALONE |
1725 | int main(int argc, char *argv[]) | 1757 | int main(int argc, char *argv[]) |
1726 | #else | 1758 | #else |
1727 | int httpd_main(int argc, char *argv[]) | 1759 | int httpd_main(int argc, char *argv[]) |
1728 | #endif | 1760 | #endif |
1729 | { | 1761 | { |
1762 | unsigned long opt; | ||
1730 | const char *home_httpd = home; | 1763 | const char *home_httpd = home; |
1731 | #ifdef TEST | 1764 | char *url_for_decode; |
1732 | const char *testArgs[5]; | 1765 | #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR |
1733 | int numTestArgs=0; | 1766 | const char *url_for_encode; |
1767 | #endif | ||
1768 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | ||
1769 | const char *s_port; | ||
1734 | #endif | 1770 | #endif |
1735 | 1771 | ||
1736 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | 1772 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY |
@@ -1738,6 +1774,7 @@ int httpd_main(int argc, char *argv[]) | |||
1738 | #endif | 1774 | #endif |
1739 | 1775 | ||
1740 | #ifdef CONFIG_FEATURE_HTTPD_SETUID | 1776 | #ifdef CONFIG_FEATURE_HTTPD_SETUID |
1777 | const char *s_uid; | ||
1741 | long uid = -1; | 1778 | long uid = -1; |
1742 | #endif | 1779 | #endif |
1743 | 1780 | ||
@@ -1752,77 +1789,48 @@ int httpd_main(int argc, char *argv[]) | |||
1752 | 1789 | ||
1753 | config->ContentLength = -1; | 1790 | config->ContentLength = -1; |
1754 | 1791 | ||
1755 | /* check if user supplied a port number */ | 1792 | opt = bb_getopt_ulflags(argc, argv, httpd_opts, |
1756 | for (;;) { | 1793 | &(config->configFile), &url_for_decode, &home_httpd |
1757 | int c = getopt( argc, argv, "c:d:h:" | ||
1758 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | ||
1759 | "p:v" | ||
1760 | #endif | ||
1761 | #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR | 1794 | #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR |
1762 | "e:" | 1795 | , &url_for_encode |
1763 | #endif | 1796 | #endif |
1764 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH | 1797 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH |
1765 | "r:" | 1798 | , &(config->realm) |
1766 | #endif | 1799 | #endif |
1800 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | ||
1801 | , &s_port | ||
1767 | #ifdef CONFIG_FEATURE_HTTPD_SETUID | 1802 | #ifdef CONFIG_FEATURE_HTTPD_SETUID |
1768 | "u:" | 1803 | , &s_uid |
1769 | #endif | 1804 | #endif |
1770 | #ifdef TEST | ||
1771 | "t:" | ||
1772 | #endif | 1805 | #endif |
1773 | ); | 1806 | ); |
1774 | if (c == EOF) break; | 1807 | |
1775 | switch (c) { | 1808 | if(opt & OPT_DECODE_URL) { |
1776 | case 'c': | 1809 | printf("%s", decodeString(url_for_decode, 1)); |
1777 | config->configFile = optarg; | ||
1778 | break; | ||
1779 | case 'h': | ||
1780 | home_httpd = optarg; | ||
1781 | break; | ||
1782 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | ||
1783 | case 'v': | ||
1784 | config->debugHttpd = 1; | ||
1785 | break; | ||
1786 | case 'p': | ||
1787 | config->port = bb_xgetlarg(optarg, 10, 1, 0xffff); | ||
1788 | break; | ||
1789 | #endif | ||
1790 | case 'd': | ||
1791 | printf("%s", decodeString(optarg, 1)); | ||
1792 | return 0; | 1810 | return 0; |
1811 | } | ||
1793 | #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR | 1812 | #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR |
1794 | case 'e': | 1813 | if(opt & OPT_ENCODE_URL) { |
1795 | printf("%s", encodeString(optarg)); | 1814 | printf("%s", encodeString(url_for_encode)); |
1796 | return 0; | 1815 | return 0; |
1816 | } | ||
1797 | #endif | 1817 | #endif |
1798 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH | 1818 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY |
1799 | case 'r': | 1819 | if(opt & OPT_PORT) |
1800 | config->realm = optarg; | 1820 | config->port = bb_xgetlarg(s_port, 10, 1, 0xffff); |
1801 | break; | 1821 | config->debugHttpd = opt & OPT_DEBUG; |
1802 | #endif | ||
1803 | #ifdef CONFIG_FEATURE_HTTPD_SETUID | 1822 | #ifdef CONFIG_FEATURE_HTTPD_SETUID |
1804 | case 'u': | 1823 | if(opt & OPT_SETUID) { |
1805 | { | ||
1806 | char *e; | 1824 | char *e; |
1807 | 1825 | ||
1808 | uid = strtol(optarg, &e, 0); | 1826 | uid = strtol(s_uid, &e, 0); |
1809 | if(*e != '\0') { | 1827 | if(*e != '\0') { |
1810 | /* not integer */ | 1828 | /* not integer */ |
1811 | uid = my_getpwnam(optarg); | 1829 | uid = my_getpwnam(s_uid); |
1812 | } | 1830 | } |
1813 | } | 1831 | } |
1814 | break; | ||
1815 | #endif | 1832 | #endif |
1816 | #ifdef TEST | ||
1817 | case 't': | ||
1818 | testArgs[numTestArgs++]=optarg; | ||
1819 | break; | ||
1820 | #endif | 1833 | #endif |
1821 | default: | ||
1822 | bb_error_msg("%s", httpdVersion); | ||
1823 | bb_show_usage(); | ||
1824 | } | ||
1825 | } | ||
1826 | 1834 | ||
1827 | if(chdir(home_httpd)) { | 1835 | if(chdir(home_httpd)) { |
1828 | bb_perror_msg_and_die("can`t chdir to %s", home_httpd); | 1836 | bb_perror_msg_and_die("can`t chdir to %s", home_httpd); |
@@ -1845,18 +1853,6 @@ int httpd_main(int argc, char *argv[]) | |||
1845 | parse_conf(default_path_httpd_conf, FIRST_PARSE); | 1853 | parse_conf(default_path_httpd_conf, FIRST_PARSE); |
1846 | #endif | 1854 | #endif |
1847 | 1855 | ||
1848 | #ifdef TEST | ||
1849 | if (numTestArgs) | ||
1850 | { | ||
1851 | int result; | ||
1852 | if (strcmp(testArgs[0], "ip") == 0) testArgs[0] = 0; | ||
1853 | if (numTestArgs > 2) | ||
1854 | parse_conf(testArgs[2], SUBDIR_PARSE); | ||
1855 | result = printf("%d\n", checkPerm(testArgs[0], testArgs[1])); | ||
1856 | return result; | ||
1857 | } | ||
1858 | #endif | ||
1859 | |||
1860 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | 1856 | #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY |
1861 | if (!config->debugHttpd) { | 1857 | if (!config->debugHttpd) { |
1862 | if (daemon(1, 0) < 0) /* don`t change curent directory */ | 1858 | if (daemon(1, 0) < 0) /* don`t change curent directory */ |