mirror of
https://github.com/sheumann/hush.git
synced 2025-01-11 23:29:51 +00:00
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 ;-)
This commit is contained in:
parent
fd10c70521
commit
a3bb3e6e0b
@ -131,7 +131,7 @@ extern int recursive_action(const char *fileName, int recurse,
|
|||||||
void* userData);
|
void* userData);
|
||||||
|
|
||||||
extern int bb_parse_mode( const char* s, mode_t* theMode);
|
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 unsigned long bb_baud_to_value(speed_t speed);
|
||||||
extern speed_t bb_value_to_baud(unsigned long value);
|
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 char *bb_opt_complementaly;
|
||||||
extern const struct option *bb_applet_long_options;
|
extern const struct option *bb_applet_long_options;
|
||||||
extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...);
|
extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...);
|
||||||
|
|
||||||
//#warning rename?
|
//#warning rename?
|
||||||
extern FILE *bb_wfopen_input(const char *filename);
|
extern FILE *bb_wfopen_input(const char *filename);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ void print_login_issue(const char *issue_file, const char *tty)
|
|||||||
time(&t);
|
time(&t);
|
||||||
uname(&uts);
|
uname(&uts);
|
||||||
|
|
||||||
puts(""); /* start a new line */
|
puts("\r"); /* start a new line */
|
||||||
|
|
||||||
if ((fd = fopen(issue_file, "r"))) {
|
if ((fd = fopen(issue_file, "r"))) {
|
||||||
while ((c = fgetc(fd)) != EOF) {
|
while ((c = fgetc(fd)) != EOF) {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#include "busybox.h"
|
#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;
|
long result;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
@ -122,7 +122,7 @@
|
|||||||
#include "busybox.h"
|
#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 default_path_httpd_conf[] = "/etc";
|
||||||
static const char httpd_conf[] = "httpd.conf";
|
static const char httpd_conf[] = "httpd.conf";
|
||||||
static const char home[] = "./";
|
static const char home[] = "./";
|
||||||
@ -647,11 +647,12 @@ static char *encodeString(const char *string)
|
|||||||
* $Errors: None
|
* $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 */
|
/* note that decoded string is always shorter than original */
|
||||||
char *orig = string;
|
char *string = orig;
|
||||||
char *ptr = string;
|
char *ptr = string;
|
||||||
|
|
||||||
while (*ptr)
|
while (*ptr)
|
||||||
{
|
{
|
||||||
if (*ptr == '+' && flag_plus_to_space) { *string++ = ' '; 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 */
|
/* set environs SERVER_PORT and REMOTE_PORT */
|
||||||
static void addEnvPort(const char *port_name)
|
static void addEnvPort(const char *port_name)
|
||||||
{
|
{
|
||||||
@ -714,6 +716,7 @@ static void addEnvPort(const char *port_name)
|
|||||||
sprintf(buf, "%u", config->port);
|
sprintf(buf, "%u", config->port);
|
||||||
addEnv(port_name, "PORT", buf);
|
addEnv(port_name, "PORT", buf);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_CGI */
|
#endif /* CONFIG_FEATURE_HTTPD_CGI */
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_SET_CGI_VARS_TO_ENV
|
#ifdef CONFIG_FEATURE_HTTPD_SET_CGI_VARS_TO_ENV
|
||||||
@ -1332,7 +1335,7 @@ static int checkPerm(const char *path, const char *request)
|
|||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
if(ipaddr)
|
if(ipaddr)
|
||||||
return config->flg_deny_all;
|
return !config->flg_deny_all;
|
||||||
return prev == NULL;
|
return prev == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1355,7 +1358,7 @@ static int checkPermIP(const char *request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if uncofigured, return 1 - access from all */
|
/* if uncofigured, return 1 - access from all */
|
||||||
return config->flg_deny_all;
|
return !config->flg_deny_all;
|
||||||
}
|
}
|
||||||
#define checkPerm(null, request) checkPermIP(request)
|
#define checkPerm(null, request) checkPermIP(request)
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */
|
#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */
|
||||||
@ -1675,9 +1678,6 @@ static int miniHttpd(int server)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
close(s);
|
close(s);
|
||||||
#ifdef TEST
|
|
||||||
return 0; // exit after processing one request
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // while (1)
|
} // while (1)
|
||||||
@ -1721,16 +1721,52 @@ static void sighup_handler(int sig)
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef HTTPD_STANDALONE
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
#else
|
#else
|
||||||
int httpd_main(int argc, char *argv[])
|
int httpd_main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
unsigned long opt;
|
||||||
const char *home_httpd = home;
|
const char *home_httpd = home;
|
||||||
#ifdef TEST
|
char *url_for_decode;
|
||||||
const char *testArgs[5];
|
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
|
||||||
int numTestArgs=0;
|
const char *url_for_encode;
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
||||||
|
const char *s_port;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
||||||
@ -1738,6 +1774,7 @@ int httpd_main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_SETUID
|
#ifdef CONFIG_FEATURE_HTTPD_SETUID
|
||||||
|
const char *s_uid;
|
||||||
long uid = -1;
|
long uid = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1752,77 +1789,48 @@ int httpd_main(int argc, char *argv[])
|
|||||||
|
|
||||||
config->ContentLength = -1;
|
config->ContentLength = -1;
|
||||||
|
|
||||||
/* check if user supplied a port number */
|
opt = bb_getopt_ulflags(argc, argv, httpd_opts,
|
||||||
for (;;) {
|
&(config->configFile), &url_for_decode, &home_httpd
|
||||||
int c = getopt( argc, argv, "c:d:h:"
|
|
||||||
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
|
||||||
"p:v"
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
|
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
|
||||||
"e:"
|
, &url_for_encode
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
|
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
|
||||||
"r:"
|
, &(config->realm)
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
||||||
|
, &s_port
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_SETUID
|
#ifdef CONFIG_FEATURE_HTTPD_SETUID
|
||||||
"u:"
|
, &s_uid
|
||||||
#endif
|
#endif
|
||||||
#ifdef TEST
|
|
||||||
"t:"
|
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if (c == EOF) break;
|
|
||||||
switch (c) {
|
if(opt & OPT_DECODE_URL) {
|
||||||
case 'c':
|
printf("%s", decodeString(url_for_decode, 1));
|
||||||
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));
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
|
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
|
||||||
case 'e':
|
if(opt & OPT_ENCODE_URL) {
|
||||||
printf("%s", encodeString(optarg));
|
printf("%s", encodeString(url_for_encode));
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
|
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
||||||
case 'r':
|
if(opt & OPT_PORT)
|
||||||
config->realm = optarg;
|
config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
|
||||||
break;
|
config->debugHttpd = opt & OPT_DEBUG;
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FEATURE_HTTPD_SETUID
|
#ifdef CONFIG_FEATURE_HTTPD_SETUID
|
||||||
case 'u':
|
if(opt & OPT_SETUID) {
|
||||||
{
|
|
||||||
char *e;
|
char *e;
|
||||||
|
|
||||||
uid = strtol(optarg, &e, 0);
|
uid = strtol(s_uid, &e, 0);
|
||||||
if(*e != '\0') {
|
if(*e != '\0') {
|
||||||
/* not integer */
|
/* not integer */
|
||||||
uid = my_getpwnam(optarg);
|
uid = my_getpwnam(s_uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef TEST
|
|
||||||
case 't':
|
|
||||||
testArgs[numTestArgs++]=optarg;
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
default:
|
|
||||||
bb_error_msg("%s", httpdVersion);
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chdir(home_httpd)) {
|
if(chdir(home_httpd)) {
|
||||||
bb_perror_msg_and_die("can`t chdir to %s", 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);
|
parse_conf(default_path_httpd_conf, FIRST_PARSE);
|
||||||
#endif
|
#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
|
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
||||||
if (!config->debugHttpd) {
|
if (!config->debugHttpd) {
|
||||||
if (daemon(1, 0) < 0) /* don`t change curent directory */
|
if (daemon(1, 0) < 0) /* don`t change curent directory */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user