From: Eric Andersen Date: Thu, 26 Jun 2003 09:05:32 +0000 (-0000) Subject: Geir Thomassen wrote, regarding networking/httpd.c line 1358 X-Git-Tag: 1_00_pre1~43 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a3bb3e6e0b80c5c905e8088b44be9b850c876b88;p=oweals%2Fbusybox.git 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 ;-) --- 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, void* userData); extern int bb_parse_mode( const char* s, mode_t* theMode); -extern long bb_xgetlarg(char *arg, int base, long lower, long upper); +extern long bb_xgetlarg(const char *arg, int base, long lower, long upper); extern unsigned long bb_baud_to_value(speed_t speed); 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)); extern const char *bb_opt_complementaly; extern const struct option *bb_applet_long_options; extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...); + //#warning rename? extern FILE *bb_wfopen_input(const char *filename); 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) time(&t); uname(&uts); - puts(""); /* start a new line */ + puts("\r"); /* start a new line */ if ((fd = fopen(issue_file, "r"))) { 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 @@ #include "busybox.h" -extern long bb_xgetlarg(char *arg, int base, long lower, long upper) +extern long bb_xgetlarg(const char *arg, int base, long lower, long upper) { long result; 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 @@ #include "busybox.h" -static const char httpdVersion[] = "busybox httpd/1.27 25-May-2003"; +static const char httpdVersion[] = "busybox httpd/1.28 22-Jun-2003"; static const char default_path_httpd_conf[] = "/etc"; static const char httpd_conf[] = "httpd.conf"; static const char home[] = "./"; @@ -647,11 +647,12 @@ static char *encodeString(const char *string) * $Errors: None * ****************************************************************************/ -static char *decodeString(char *string, int flag_plus_to_space) +static char *decodeString(char *orig, int flag_plus_to_space) { /* note that decoded string is always shorter than original */ - char *orig = string; + char *string = orig; char *ptr = string; + while (*ptr) { if (*ptr == '+' && flag_plus_to_space) { *string++ = ' '; ptr++; } @@ -706,6 +707,7 @@ static void addEnv(const char *name_before_underline, } } +#if defined(CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV) || !defined(CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY) /* set environs SERVER_PORT and REMOTE_PORT */ static void addEnvPort(const char *port_name) { @@ -714,6 +716,7 @@ static void addEnvPort(const char *port_name) sprintf(buf, "%u", config->port); addEnv(port_name, "PORT", buf); } +#endif #endif /* CONFIG_FEATURE_HTTPD_CGI */ #ifdef CONFIG_FEATURE_HTTPD_SET_CGI_VARS_TO_ENV @@ -1332,7 +1335,7 @@ static int checkPerm(const char *path, const char *request) } /* for */ if(ipaddr) - return config->flg_deny_all; + return !config->flg_deny_all; return prev == NULL; } @@ -1355,7 +1358,7 @@ static int checkPermIP(const char *request) } /* if uncofigured, return 1 - access from all */ - return config->flg_deny_all; + return !config->flg_deny_all; } #define checkPerm(null, request) checkPermIP(request) #endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */ @@ -1675,9 +1678,6 @@ static int miniHttpd(int server) exit(0); } close(s); -#ifdef TEST - return 0; // exit after processing one request -#endif } } } // while (1) @@ -1721,16 +1721,52 @@ static void sighup_handler(int sig) } #endif + +static const char httpd_opts[]="c:d:h:" +#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR + "e:" +#define OPT_INC_1 1 +#else +#define OPT_INC_1 0 +#endif +#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH + "r:" +#define OPT_INC_2 1 +#else +#define OPT_INC_2 0 +#endif +#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY + "p:v" +#ifdef CONFIG_FEATURE_HTTPD_SETUID + "u:" +#endif +#endif + ; + +#define OPT_CONFIG_FILE (1<<0) +#define OPT_DECODE_URL (1<<1) +#define OPT_HOME_HTTPD (1<<2) +#define OPT_ENCODE_URL (1<<(2+OPT_INC_1)) +#define OPT_REALM (1<<(2+OPT_INC_1+OPT_INC_2)) +#define OPT_PORT (1<<(3+OPT_INC_1+OPT_INC_2)) +#define OPT_DEBUG (1<<(4+OPT_INC_1+OPT_INC_2)) +#define OPT_SETUID (1<<(5+OPT_INC_1+OPT_INC_2)) + + #ifdef HTTPD_STANDALONE int main(int argc, char *argv[]) #else int httpd_main(int argc, char *argv[]) #endif { + unsigned long opt; const char *home_httpd = home; -#ifdef TEST - const char *testArgs[5]; - int numTestArgs=0; + char *url_for_decode; +#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR + const char *url_for_encode; +#endif +#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY + const char *s_port; #endif #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY @@ -1738,6 +1774,7 @@ int httpd_main(int argc, char *argv[]) #endif #ifdef CONFIG_FEATURE_HTTPD_SETUID + const char *s_uid; long uid = -1; #endif @@ -1752,77 +1789,48 @@ int httpd_main(int argc, char *argv[]) config->ContentLength = -1; - /* check if user supplied a port number */ - for (;;) { - int c = getopt( argc, argv, "c:d:h:" -#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY - "p:v" -#endif + opt = bb_getopt_ulflags(argc, argv, httpd_opts, + &(config->configFile), &url_for_decode, &home_httpd #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR - "e:" + , &url_for_encode #endif #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH - "r:" + , &(config->realm) #endif +#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY + , &s_port #ifdef CONFIG_FEATURE_HTTPD_SETUID - "u:" + , &s_uid #endif -#ifdef TEST - "t:" #endif ); - if (c == EOF) break; - switch (c) { - case 'c': - config->configFile = optarg; - break; - case 'h': - home_httpd = optarg; - break; -#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY - case 'v': - config->debugHttpd = 1; - break; - case 'p': - config->port = bb_xgetlarg(optarg, 10, 1, 0xffff); - break; -#endif - case 'd': - printf("%s", decodeString(optarg, 1)); + + if(opt & OPT_DECODE_URL) { + printf("%s", decodeString(url_for_decode, 1)); return 0; + } #ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR - case 'e': - printf("%s", encodeString(optarg)); + if(opt & OPT_ENCODE_URL) { + printf("%s", encodeString(url_for_encode)); return 0; + } #endif -#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH - case 'r': - config->realm = optarg; - break; -#endif +#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY + if(opt & OPT_PORT) + config->port = bb_xgetlarg(s_port, 10, 1, 0xffff); + config->debugHttpd = opt & OPT_DEBUG; #ifdef CONFIG_FEATURE_HTTPD_SETUID - case 'u': - { + if(opt & OPT_SETUID) { char *e; - uid = strtol(optarg, &e, 0); + uid = strtol(s_uid, &e, 0); if(*e != '\0') { /* not integer */ - uid = my_getpwnam(optarg); + uid = my_getpwnam(s_uid); } } - break; #endif -#ifdef TEST - case 't': - testArgs[numTestArgs++]=optarg; - break; #endif - default: - bb_error_msg("%s", httpdVersion); - bb_show_usage(); - } - } if(chdir(home_httpd)) { bb_perror_msg_and_die("can`t chdir to %s", home_httpd); @@ -1845,18 +1853,6 @@ int httpd_main(int argc, char *argv[]) parse_conf(default_path_httpd_conf, FIRST_PARSE); #endif -#ifdef TEST - if (numTestArgs) - { - int result; - if (strcmp(testArgs[0], "ip") == 0) testArgs[0] = 0; - if (numTestArgs > 2) - parse_conf(testArgs[2], SUBDIR_PARSE); - result = printf("%d\n", checkPerm(testArgs[0], testArgs[1])); - return result; - } -#endif - #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY if (!config->debugHttpd) { if (daemon(1, 0) < 0) /* don`t change curent directory */