httpd: sanitize indentation

This commit is contained in:
Denis Vlasenko 2006-09-26 10:07:41 +00:00
parent a552eeb498
commit 8b8c75e6ab

View File

@ -133,8 +133,7 @@ typedef struct HT_ACCESS_IP {
struct HT_ACCESS_IP *next;
} Htaccess_IP;
typedef struct
{
typedef struct {
char buf[MAX_MEMORY_BUFF];
USE_FEATURE_HTTPD_BASIC_AUTH(const char *realm;)
@ -208,7 +207,7 @@ static const char* const suffixTable [] = {
".vrml.wrl", "model/vrml",
#endif
0, "application/octet-stream" /* default */
};
};
typedef enum
{
@ -234,7 +233,7 @@ typedef enum
HTTP_PAYMENT_REQUIRED = 402,
HTTP_BAD_GATEWAY = 502,
HTTP_SERVICE_UNAVAILABLE = 503, /* overload, maintenance */
HTTP_RESPONSE_SETSIZE=0xffffffff
HTTP_RESPONSE_SETSIZE = 0xffffffff
#endif
} HttpResponseNum;
@ -309,7 +308,7 @@ scan_ip (const char **ep, unsigned int *ip, unsigned char endc)
if (*p != endc)
return -auto_mask;
p++;
if(*p == 0)
if (*p == 0)
return -auto_mask;
}
*ep = p;
@ -323,9 +322,9 @@ scan_ip_mask (const char *ipm, unsigned int *ip, unsigned int *mask)
unsigned int msk;
i = scan_ip(&ipm, ip, '/');
if(i < 0)
if (i < 0)
return i;
if(*ipm) {
if (*ipm) {
const char *p = ipm;
i = 0;
@ -359,7 +358,7 @@ static void free_config_lines(Htaccess **pprev)
{
Htaccess *prev = *pprev;
while( prev ) {
while (prev) {
Htaccess *cur = prev;
prev = cur->next;
@ -416,7 +415,7 @@ static void parse_conf(const char *path, int flag)
/* free previous ip setup if present */
Htaccess_IP *pip = config->ip_a_d;
while( pip ) {
while (pip) {
Htaccess_IP *cur_ipl = pip;
pip = cur_ipl->next;
@ -428,7 +427,7 @@ static void parse_conf(const char *path, int flag)
#if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR)
/* retain previous auth and mime config only for subdir parse */
if(flag != SUBDIR_PARSE) {
if (flag != SUBDIR_PARSE) {
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
free_config_lines(&config->auth);
#endif
@ -441,22 +440,22 @@ static void parse_conf(const char *path, int flag)
}
#endif
if(flag == SUBDIR_PARSE || cf == NULL) {
if (flag == SUBDIR_PARSE || cf == NULL) {
cf = alloca(strlen(path) + sizeof(httpd_conf) + 2);
if(cf == NULL) {
if(flag == FIRST_PARSE)
if (cf == NULL) {
if (flag == FIRST_PARSE)
bb_error_msg_and_die(bb_msg_memory_exhausted);
return;
}
sprintf((char *)cf, "%s/%s", path, httpd_conf);
}
while((f = fopen(cf, "r")) == NULL) {
if(flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) {
while ((f = fopen(cf, "r")) == NULL) {
if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) {
/* config file not found, no changes to config */
return;
}
if(config->configFile && flag == FIRST_PARSE) /* if -c option given */
if (config->configFile && flag == FIRST_PARSE) /* if -c option given */
bb_perror_msg_and_die("%s", cf);
flag = FIND_FROM_HTTPD_ROOT;
cf = httpd_conf;
@ -468,10 +467,10 @@ static void parse_conf(const char *path, int flag)
/* This could stand some work */
while ( (p0 = fgets(buf, sizeof(buf), f)) != NULL) {
c = NULL;
for(p = p0; *p0 != 0 && *p0 != '#'; p0++) {
if(!isspace(*p0)) {
for (p = p0; *p0 != 0 && *p0 != '#'; p0++) {
if (!isspace(*p0)) {
*p++ = *p0;
if(*p0 == ':' && c == NULL)
if (*p0 == ':' && c == NULL)
c = p;
}
}
@ -481,10 +480,10 @@ static void parse_conf(const char *path, int flag)
if (c == NULL || *c == 0)
continue;
p0 = buf;
if(*p0 == 'd')
if (*p0 == 'd')
*p0 = 'D';
if(*c == '*') {
if(*p0 == 'D') {
if (*c == '*') {
if (*p0 == 'D') {
/* memorize deny all */
config->flg_deny_all++;
}
@ -492,9 +491,9 @@ static void parse_conf(const char *path, int flag)
continue;
}
if(*p0 == 'a')
if (*p0 == 'a')
*p0 = 'A';
else if(*p0 != 'D' && *p0 != 'A'
else if (*p0 != 'D' && *p0 != 'A'
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
&& *p0 != '/'
#endif
@ -506,17 +505,17 @@ static void parse_conf(const char *path, int flag)
#endif
)
continue;
if(*p0 == 'A' || *p0 == 'D') {
if (*p0 == 'A' || *p0 == 'D') {
/* storing current config IP line */
pip = calloc(1, sizeof(Htaccess_IP));
if(pip) {
if(scan_ip_mask (c, &(pip->ip), &(pip->mask))) {
if (pip) {
if (scan_ip_mask (c, &(pip->ip), &(pip->mask))) {
/* syntax IP{/mask} error detected, protect all */
*p0 = 'D';
pip->mask = 0;
}
pip->allow_deny = *p0;
if(*p0 == 'D') {
if (*p0 == 'D') {
/* Deny:form_IP move top */
pip->next = config->ip_a_d;
config->ip_a_d = pip;
@ -524,10 +523,10 @@ static void parse_conf(const char *path, int flag)
/* add to bottom A:form_IP config line */
Htaccess_IP *prev_IP = config->ip_a_d;
if(prev_IP == NULL) {
if (prev_IP == NULL) {
config->ip_a_d = pip;
} else {
while(prev_IP->next)
while (prev_IP->next)
prev_IP = prev_IP->next;
prev_IP->next = pip;
}
@ -536,11 +535,11 @@ static void parse_conf(const char *path, int flag)
continue;
}
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
if(*p0 == '/') {
if (*p0 == '/') {
/* make full path from httpd root / curent_path / config_line_path */
cf = flag == SUBDIR_PARSE ? path : "";
p0 = malloc(strlen(cf) + (c - buf) + 2 + strlen(c));
if(p0 == NULL)
if (p0 == NULL)
continue;
c[-1] = 0;
sprintf(p0, "/%s%s", cf, buf);
@ -578,13 +577,13 @@ static void parse_conf(const char *path, int flag)
#if defined(CONFIG_FEATURE_HTTPD_BASIC_AUTH) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES) || defined(CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR)
/* storing current config line */
cur = calloc(1, sizeof(Htaccess) + strlen(p0));
if(cur) {
if (cur) {
cf = strcpy(cur->before_colon, p0);
c = strchr(cf, ':');
*c++ = 0;
cur->after_colon = c;
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES
if(*cf == '.') {
if (*cf == '.') {
/* config .mime line move top for overwrite previous */
cur->next = config->mime_a;
config->mime_a = cur;
@ -592,7 +591,7 @@ static void parse_conf(const char *path, int flag)
}
#endif
#ifdef CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
if(*cf == '*' && cf[1] == '.') {
if (*cf == '*' && cf[1] == '.') {
/* config script interpreter line move top for overwrite previous */
cur->next = config->script_i;
config->script_i = cur;
@ -601,7 +600,7 @@ static void parse_conf(const char *path, int flag)
#endif
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
free(p0);
if(prev == NULL) {
if (prev == NULL) {
/* first line */
config->auth = prev = cur;
} else {
@ -610,11 +609,11 @@ static void parse_conf(const char *path, int flag)
size_t l = strlen(cf);
Htaccess *hti;
for(hti = prev_hti; hti; hti = hti->next) {
if(l >= strlen(hti->before_colon)) {
for (hti = prev_hti; hti; hti = hti->next) {
if (l >= strlen(hti->before_colon)) {
/* insert before hti */
cur->next = hti;
if(prev_hti != hti) {
if (prev_hti != hti) {
prev_hti->next = cur;
} else {
/* insert as top */
@ -622,10 +621,10 @@ static void parse_conf(const char *path, int flag)
}
break;
}
if(prev_hti != hti)
if (prev_hti != hti)
prev_hti = prev_hti->next;
}
if(!hti) { /* not inserted, add to bottom */
if (!hti) { /* not inserted, add to bottom */
prev->next = cur;
prev = cur;
}
@ -661,7 +660,7 @@ static char *encodeString(const char *string)
/* could possibly scan once to get length. */
int len = strlen(string);
char *out = malloc(len * 6 + 1);
char *p=out;
char *p = out;
char ch;
if (!out) return "";
@ -670,7 +669,7 @@ static char *encodeString(const char *string)
if (isalnum(ch)) *p++ = ch;
else p += sprintf(p, "&#%d;", (unsigned char) ch);
}
*p=0;
*p = 0;
return out;
}
#endif /* CONFIG_FEATURE_HTTPD_ENCODE_URL_STR */
@ -700,22 +699,21 @@ static char *decodeString(char *orig, int flag_plus_to_space)
char *string = orig;
char *ptr = string;
while (*ptr)
{
while (*ptr) {
if (*ptr == '+' && flag_plus_to_space) { *string++ = ' '; ptr++; }
else if (*ptr != '%') *string++ = *ptr++;
else {
unsigned int value1, value2;
ptr++;
if(sscanf(ptr, "%1X", &value1) != 1 ||
if (sscanf(ptr, "%1X", &value1) != 1 ||
sscanf(ptr+1, "%1X", &value2) != 1) {
if(!flag_plus_to_space)
if (!flag_plus_to_space)
return NULL;
*string++ = '%';
} else {
value1 = value1 * 16 + value2;
if(value1 == '/' || value1 == 0)
if (value1 == '/' || value1 == 0)
return orig+1;
*string++ = value1;
ptr += 2;
@ -757,7 +755,7 @@ static void addEnv(const char *name_before_underline,
underline = *name_after_underline ? "_" : "";
asprintf(&s, "%s%s%s=%s", name_before_underline, underline,
name_after_underline, value);
if(s) {
if (s) {
putenv(s);
}
}
@ -805,17 +803,17 @@ static void decodeBase64(char *Data)
while (*in) {
int t = *in++;
if(t >= '0' && t <= '9')
if (t >= '0' && t <= '9')
t = t - '0' + 52;
else if(t >= 'A' && t <= 'Z')
else if (t >= 'A' && t <= 'Z')
t = t - 'A';
else if(t >= 'a' && t <= 'z')
else if (t >= 'a' && t <= 'z')
t = t - 'a' + 26;
else if(t == '+')
else if (t == '+')
t = 62;
else if(t == '/')
else if (t == '/')
t = 63;
else if(t == '=')
else if (t == '=')
t = 0;
else
continue;
@ -924,7 +922,7 @@ static int sendHeaders(HttpResponseNum responseNum)
config->realm);
}
#endif
if(responseNum == HTTP_MOVED_TEMPORARILY) {
if (responseNum == HTTP_MOVED_TEMPORARILY) {
len += sprintf(buf+len, "Location: %s/%s%s\r\n",
config->httpd_found.found_moved_temporarily,
(config->query ? "?" : ""),
@ -973,7 +971,7 @@ static int getLine(void)
buf[count] = 0;
return count;
}
if(count < (MAX_MEMORY_BUFF-1)) /* check owerflow */
if (count < (MAX_MEMORY_BUFF-1)) /* check owerflow */
count++;
}
if (count) return count;
@ -1033,10 +1031,10 @@ static int sendCgi(const char *url,
if (!pid) {
/* child process */
char *script;
char *purl = strdup( url );
char *purl = strdup(url);
char realpath_buff[MAXPATHLEN];
if(purl == NULL)
if (purl == NULL)
_exit(242);
inFd = toCgi[0];
@ -1044,7 +1042,7 @@ static int sendCgi(const char *url,
dup2(inFd, 0); // replace stdin with the pipe
dup2(outFd, 1); // replace stdout with the pipe
if(!DEBUG)
if (!DEBUG)
dup2(outFd, 2); // replace stderr with the pipe
close(toCgi[0]);
@ -1056,12 +1054,12 @@ static int sendCgi(const char *url,
* Find PATH_INFO.
*/
script = purl;
while((script = strchr( script + 1, '/' )) != NULL) {
while ((script = strchr(script + 1, '/')) != NULL) {
/* have script.cgi/PATH_INFO or dirs/script.cgi[/PATH_INFO] */
struct stat sb;
*script = '\0';
if(is_directory(purl + 1, 1, &sb) == 0) {
if (is_directory(purl + 1, 1, &sb) == 0) {
/* not directory, found script.cgi/PATH_INFO */
*script = '/';
break;
@ -1071,18 +1069,18 @@ static int sendCgi(const char *url,
addEnv("PATH", "INFO", script); /* set /PATH_INFO or NULL */
addEnv("PATH", "", getenv("PATH"));
addEnv("REQUEST", "METHOD", request);
if(config->query) {
if (config->query) {
char *uri = alloca(strlen(purl) + 2 + strlen(config->query));
if(uri)
if (uri)
sprintf(uri, "%s?%s", purl, config->query);
addEnv("REQUEST", "URI", uri);
} else {
addEnv("REQUEST", "URI", purl);
}
if(script != NULL)
if (script != NULL)
*script = '\0'; /* reduce /PATH_INFO */
/* SCRIPT_FILENAME required by PHP in CGI mode */
if(realpath(purl + 1, realpath_buff))
if (realpath(purl + 1, realpath_buff))
addEnv("SCRIPT", "FILENAME", realpath_buff);
else
*realpath_buff = 0;
@ -1096,33 +1094,33 @@ static int sendCgi(const char *url,
#ifdef CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV
addEnvPort("REMOTE");
#endif
if(bodyLen) {
if (bodyLen) {
char sbl[32];
sprintf(sbl, "%d", bodyLen);
addEnv("CONTENT", "LENGTH", sbl);
}
if(cookie)
if (cookie)
addEnv("HTTP", "COOKIE", cookie);
if(content_type)
if (content_type)
addEnv("CONTENT", "TYPE", content_type);
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
if(config->remoteuser) {
if (config->remoteuser) {
addEnv("REMOTE", "USER", config->remoteuser);
addEnv("AUTH_TYPE", "", "Basic");
}
#endif
if(config->referer)
if (config->referer)
addEnv("HTTP", "REFERER", config->referer);
/* set execve argp[0] without path */
argp[0] = strrchr( purl, '/' ) + 1;
argp[0] = strrchr(purl, '/') + 1;
/* but script argp[0] must have absolute path and chdiring to this */
if(*realpath_buff) {
if (*realpath_buff) {
script = strrchr(realpath_buff, '/');
if(script) {
if (script) {
*script = '\0';
if(chdir(realpath_buff) == 0) {
if (chdir(realpath_buff) == 0) {
// now run the program. If it fails,
// use _exit() so no destructors
// get called and make a mess.
@ -1130,10 +1128,10 @@ static int sendCgi(const char *url,
char *interpr = NULL;
char *suffix = strrchr(purl, '.');
if(suffix) {
if (suffix) {
Htaccess * cur;
for (cur = config->script_i; cur; cur = cur->next)
if(strcmp(cur->before_colon + 1, suffix) == 0) {
if (strcmp(cur->before_colon + 1, suffix) == 0) {
interpr = cur->after_colon;
break;
}
@ -1179,18 +1177,18 @@ static int sendCgi(const char *url,
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
FD_SET(inFd, &readSet);
if(bodyLen > 0 || post_readed_size > 0) {
if (bodyLen > 0 || post_readed_size > 0) {
FD_SET(outFd, &writeSet);
nfound = outFd > inFd ? outFd : inFd;
if(post_readed_size == 0) {
if (post_readed_size == 0) {
FD_SET(a_c_r, &readSet);
if(nfound < a_c_r)
if (nfound < a_c_r)
nfound = a_c_r;
}
/* Now wait on the set of sockets! */
nfound = select(nfound + 1, &readSet, &writeSet, 0, NULL);
} else {
if(!bodyLen) {
if (!bodyLen) {
close(outFd);
bodyLen = -1;
}
@ -1208,27 +1206,27 @@ static int sendCgi(const char *url,
#endif
break;
}
} else if(post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) {
} else if (post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) {
count = full_write(outFd, wbuf + post_readed_idx, post_readed_size);
if(count > 0) {
if (count > 0) {
post_readed_size -= count;
post_readed_idx += count;
if(post_readed_size == 0)
if (post_readed_size == 0)
post_readed_idx = 0;
} else {
post_readed_size = post_readed_idx = bodyLen = 0; /* broken pipe to CGI */
}
} else if(bodyLen > 0 && post_readed_size == 0 && FD_ISSET(a_c_r, &readSet)) {
} else if (bodyLen > 0 && post_readed_size == 0 && FD_ISSET(a_c_r, &readSet)) {
count = bodyLen > (int)sizeof(wbuf) ? (int)sizeof(wbuf) : bodyLen;
count = safe_read(a_c_r, wbuf, count);
if(count > 0) {
if (count > 0) {
post_readed_size += count;
bodyLen -= count;
} else {
bodyLen = 0; /* closed */
}
}
if(FD_ISSET(inFd, &readSet)) {
if (FD_ISSET(inFd, &readSet)) {
int s = a_c_w;
char *rbuf = config->buf;
@ -1249,7 +1247,7 @@ static int sendCgi(const char *url,
if (firstLine) {
rbuf[count] = 0;
/* check to see if the user script added headers */
if(strncmp(rbuf, "HTTP/1.0 200 OK\r\n", 4) != 0) {
if (strncmp(rbuf, "HTTP/1.0 200 OK\r\n", 4) != 0) {
full_write(s, "HTTP/1.0 200 OK\r\n", 17);
}
if (strstr(rbuf, "ontent-") == 0) {
@ -1293,9 +1291,9 @@ static int sendFile(const char *url)
suffix = strrchr(url, '.');
for (table = suffixTable; *table; table += 2)
if(suffix != NULL && (try_suffix = strstr(*table, suffix)) != 0) {
if (suffix != NULL && (try_suffix = strstr(*table, suffix)) != 0) {
try_suffix += strlen(suffix);
if(*try_suffix == 0 || *try_suffix == '.')
if (*try_suffix == 0 || *try_suffix == '.')
break;
}
/* also, if not found, set default as "application/octet-stream"; */
@ -1305,7 +1303,7 @@ static int sendFile(const char *url)
Htaccess * cur;
for (cur = config->mime_a; cur; cur = cur->next) {
if(strcmp(cur->before_colon, suffix) == 0) {
if (strcmp(cur->before_colon, suffix) == 0) {
config->httpd_found.found_mime_type = cur->after_colon;
break;
}
@ -1357,7 +1355,7 @@ static int checkPermIP(void)
(unsigned char)(cur->mask >> 8),
cur->mask & 0xff);
#endif
if((config->rmt_ip & cur->mask) == cur->ip)
if ((config->rmt_ip & cur->mask) == cur->ip)
return cur->allow_deny == 'A'; /* Allow/Deny */
}
@ -1394,7 +1392,7 @@ static int checkPerm(const char *path, const char *request)
/* This could stand some work */
for (cur = config->auth; cur; cur = cur->next) {
p0 = cur->before_colon;
if(prev != NULL && strcmp(prev, p0) != 0)
if (prev != NULL && strcmp(prev, p0) != 0)
continue; /* find next identical */
p = cur->after_colon;
#if DEBUG
@ -1403,14 +1401,14 @@ static int checkPerm(const char *path, const char *request)
{
size_t l = strlen(p0);
if(strncmp(p0, path, l) == 0 &&
if (strncmp(p0, path, l) == 0 &&
(l == 1 || path[l] == '/' || path[l] == 0)) {
char *u;
/* path match found. Check request */
/* for check next /path:user:password */
prev = p0;
u = strchr(request, ':');
if(u == NULL) {
if (u == NULL) {
/* bad request, ':' required */
break;
}
@ -1420,12 +1418,12 @@ static int checkPerm(const char *path, const char *request)
char *cipher;
char *pp;
if(strncmp(p, request, u-request) != 0) {
if (strncmp(p, request, u-request) != 0) {
/* user uncompared */
continue;
}
pp = strchr(p, ':');
if(pp && pp[1] == '$' && pp[2] == '1' &&
if (pp && pp[1] == '$' && pp[2] == '1' &&
pp[3] == '$' && pp[4]) {
pp++;
cipher = pw_encrypt(u+1, pp);
@ -1441,7 +1439,7 @@ static int checkPerm(const char *path, const char *request)
set_remoteuser_var:
#endif
config->remoteuser = strdup(request);
if(config->remoteuser)
if (config->remoteuser)
config->remoteuser[(u - request)] = 0;
return 1; /* Ok */
}
@ -1463,8 +1461,7 @@ set_remoteuser_var:
*
****************************************************************************/
static void
handle_sigalrm( int sig )
static void handle_sigalrm(int sig)
{
sendHeaders(HTTP_REQUEST_TIMEOUT);
config->alarm_signaled = sig;
@ -1509,27 +1506,27 @@ static void handleIncoming(void)
do {
int count;
(void) alarm( TIMEOUT );
(void) alarm(TIMEOUT);
if (getLine() <= 0)
break; /* closed */
purl = strpbrk(buf, " \t");
if(purl == NULL) {
if (purl == NULL) {
BAD_REQUEST:
sendHeaders(HTTP_BAD_REQUEST);
break;
}
*purl = 0;
#ifdef CONFIG_FEATURE_HTTPD_CGI
if(strcasecmp(buf, prequest) != 0) {
if (strcasecmp(buf, prequest) != 0) {
prequest = "POST";
if(strcasecmp(buf, prequest) != 0) {
if (strcasecmp(buf, prequest) != 0) {
sendHeaders(HTTP_NOT_IMPLEMENTED);
break;
}
}
#else
if(strcasecmp(buf, request_GET) != 0) {
if (strcasecmp(buf, request_GET) != 0) {
sendHeaders(HTTP_NOT_IMPLEMENTED);
break;
}
@ -1542,7 +1539,7 @@ BAD_REQUEST:
goto BAD_REQUEST;
}
url = alloca(strlen(buf) + 12); /* + sizeof("/index.html\0") */
if(url == NULL) {
if (url == NULL) {
sendHeaders(HTTP_INTERNAL_SERVER_ERROR);
break;
}
@ -1555,9 +1552,9 @@ BAD_REQUEST:
}
test = decodeString(url, 0);
if(test == NULL)
if (test == NULL)
goto BAD_REQUEST;
if(test == (buf+1)) {
if (test == (buf+1)) {
sendHeaders(HTTP_NOT_FOUND);
break;
}
@ -1590,8 +1587,8 @@ BAD_REQUEST:
test = purl; /* end ptr */
/* If URL is directory, adding '/' */
if(test[-1] != '/') {
if ( is_directory(url + 1, 1, &sb) ) {
if (test[-1] != '/') {
if (is_directory(url + 1, 1, &sb)) {
config->httpd_found.found_moved_temporarily = url;
}
}
@ -1601,22 +1598,22 @@ BAD_REQUEST:
test = url;
ip_allowed = checkPermIP();
while(ip_allowed && (test = strchr( test + 1, '/' )) != NULL) {
while (ip_allowed && (test = strchr(test + 1, '/')) != NULL) {
/* have path1/path2 */
*test = '\0';
if( is_directory(url + 1, 1, &sb) ) {
if (is_directory(url + 1, 1, &sb)) {
/* may be having subdir config */
parse_conf(url + 1, SUBDIR_PARSE);
ip_allowed = checkPermIP();
}
*test = '/';
}
if(blank >= 0) {
if (blank >= 0) {
// read until blank line for HTTP version specified, else parse immediate
while(1) {
while (1) {
alarm(TIMEOUT);
count = getLine();
if(count <= 0)
if (count <= 0)
break;
#if DEBUG
@ -1626,18 +1623,18 @@ BAD_REQUEST:
#ifdef CONFIG_FEATURE_HTTPD_CGI
/* try and do our best to parse more lines */
if ((strncasecmp(buf, Content_length, 15) == 0)) {
if(prequest != request_GET)
if (prequest != request_GET)
length = strtol(buf + 15, 0, 0); // extra read only for POST
} else if ((strncasecmp(buf, "Cookie:", 7) == 0)) {
for(test = buf + 7; isspace(*test); test++)
for (test = buf + 7; isspace(*test); test++)
;
cookie = strdup(test);
} else if ((strncasecmp(buf, "Content-Type:", 13) == 0)) {
for(test = buf + 13; isspace(*test); test++)
for (test = buf + 13; isspace(*test); test++)
;
content_type = strdup(test);
} else if ((strncasecmp(buf, "Referer:", 8) == 0)) {
for(test = buf + 8; isspace(*test); test++)
for (test = buf + 8; isspace(*test); test++)
;
config->referer = strdup(test);
}
@ -1649,7 +1646,7 @@ BAD_REQUEST:
* It shows up as "Authorization: Basic <userid:password>" where
* the userid:password is base64 encoded.
*/
for(test = buf + 14; isspace(*test); test++)
for (test = buf + 14; isspace(*test); test++)
;
if (strncasecmp(test, "Basic", 5) != 0)
continue;
@ -1662,8 +1659,8 @@ BAD_REQUEST:
} /* while extra header reading */
}
(void) alarm( 0 );
if(config->alarm_signaled)
(void) alarm(0);
if (config->alarm_signaled)
break;
if (strcmp(strrchr(url, '/') + 1, httpd_conf) == 0 || ip_allowed == 0) {
@ -1682,7 +1679,7 @@ FORBIDDEN: /* protect listing /cgi-bin */
}
#endif
if(config->httpd_found.found_moved_temporarily) {
if (config->httpd_found.found_moved_temporarily) {
sendHeaders(HTTP_MOVED_TEMPORARILY);
#if DEBUG
/* clear unforked memory flag */
@ -1699,7 +1696,7 @@ FORBIDDEN: /* protect listing /cgi-bin */
break;
if (strncmp(test, "cgi-bin", 7) == 0) {
if(test[7] == '/' && test[8] == 0)
if (test[7] == '/' && test[8] == 0)
goto FORBIDDEN; // protect listing cgi-bin/
sendCgi(url, prequest, length, cookie, content_type);
} else {
@ -1707,9 +1704,9 @@ FORBIDDEN: /* protect listing /cgi-bin */
sendHeaders(HTTP_NOT_IMPLEMENTED);
else {
#endif /* CONFIG_FEATURE_HTTPD_CGI */
if(purl[-1] == '/')
if (purl[-1] == '/')
strcpy(purl, "index.html");
if ( stat(test, &sb ) == 0 ) {
if (stat(test, &sb) == 0) {
config->ContentLength = sb.st_size;
config->last_mod = sb.st_mtime;
}
@ -1868,8 +1865,7 @@ static void sighup_handler(int sig)
/* set and reset */
struct sigaction sa;
parse_conf(default_path_httpd_conf,
sig == SIGHUP ? SIGNALED_PARSE : FIRST_PARSE);
parse_conf(default_path_httpd_conf, sig == SIGHUP ? SIGNALED_PARSE : FIRST_PARSE);
sa.sa_handler = sighup_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
@ -1949,31 +1945,31 @@ int httpd_main(int argc, char *argv[])
USE_FEATURE_HTTPD_WITHOUT_INETD(, &s_port)
);
if(opt & OPT_DECODE_URL) {
if (opt & OPT_DECODE_URL) {
printf("%s", decodeString(url_for_decode, 1));
return 0;
}
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
if(opt & OPT_ENCODE_URL) {
if (opt & OPT_ENCODE_URL) {
printf("%s", encodeString(url_for_encode));
return 0;
}
#endif
#ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5
if(opt & OPT_MD5) {
if (opt & OPT_MD5) {
printf("%s\n", pw_encrypt(pass, "$1$"));
return 0;
}
#endif
#ifdef CONFIG_FEATURE_HTTPD_WITHOUT_INETD
if(opt & OPT_PORT)
if (opt & OPT_PORT)
config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
#ifdef CONFIG_FEATURE_HTTPD_SETUID
if(opt & OPT_SETUID) {
if (opt & OPT_SETUID) {
char *e;
uid = strtol(s_uid, &e, 0);
if(*e != '\0') {
if (*e != '\0') {
/* not integer */
uid = bb_xgetpwnam(s_uid);
}
@ -1986,7 +1982,7 @@ int httpd_main(int argc, char *argv[])
server = openServer();
# ifdef CONFIG_FEATURE_HTTPD_SETUID
/* drop privileges */
if(uid > 0)
if (uid > 0)
xsetuid(uid);
# endif
#endif
@ -1994,11 +1990,11 @@ int httpd_main(int argc, char *argv[])
#ifdef CONFIG_FEATURE_HTTPD_CGI
{
char *p = getenv("PATH");
if(p) {
if (p) {
p = xstrdup(p);
}
clearenv();
if(p)
if (p)
setenv("PATH", p, 1);
# ifdef CONFIG_FEATURE_HTTPD_WITHOUT_INETD
addEnvPort("SERVER");