httpd: reduce ifdef forest. comment out redundant PATH setting
This commit is contained in:
parent
d4f3d1a4bd
commit
b3a071543d
@ -1196,7 +1196,7 @@ USE_FEATURE_DATE_ISOFMT( \
|
|||||||
"Options:\n" \
|
"Options:\n" \
|
||||||
"\t-c FILE\t\tSpecifies configuration file. (default httpd.conf)\n" \
|
"\t-c FILE\t\tSpecifies configuration file. (default httpd.conf)\n" \
|
||||||
"\t-p PORT\t\tServer port (default 80)\n" \
|
"\t-p PORT\t\tServer port (default 80)\n" \
|
||||||
"\t-i\t\tAssume that we are started frim inetd\n" \
|
"\t-i\t\tAssume that we are started from inetd\n" \
|
||||||
"\t-f\t\tDo not daemonize\n" \
|
"\t-f\t\tDo not daemonize\n" \
|
||||||
USE_FEATURE_HTTPD_SETUID("\t-u USER[:GRP]\tSet uid/gid after binding to port\n") \
|
USE_FEATURE_HTTPD_SETUID("\t-u USER[:GRP]\tSet uid/gid after binding to port\n") \
|
||||||
USE_FEATURE_HTTPD_BASIC_AUTH("\t-r REALM\tAuthentication Realm for Basic Authentication\n") \
|
USE_FEATURE_HTTPD_BASIC_AUTH("\t-r REALM\tAuthentication Realm for Basic Authentication\n") \
|
||||||
|
@ -652,7 +652,7 @@ static char *encodeString(const char *string)
|
|||||||
*p = 0;
|
*p = 0;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_ENCODE_URL_STR */
|
#endif /* FEATURE_HTTPD_ENCODE_URL_STR */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
@ -1018,7 +1018,7 @@ static int sendCgi(const char *url,
|
|||||||
*script = '/'; /* is directory, find next '/' */
|
*script = '/'; /* is directory, find next '/' */
|
||||||
}
|
}
|
||||||
setenv1("PATH_INFO", script); /* set /PATH_INFO or "" */
|
setenv1("PATH_INFO", script); /* set /PATH_INFO or "" */
|
||||||
setenv1("PATH", getenv("PATH")); /* Huh?? */
|
/* setenv1("PATH", getenv("PATH")); redundant */
|
||||||
setenv1("REQUEST_METHOD", request);
|
setenv1("REQUEST_METHOD", request);
|
||||||
if (config->query) {
|
if (config->query) {
|
||||||
char *uri = alloca(strlen(purl) + 2 + strlen(config->query));
|
char *uri = alloca(strlen(purl) + 2 + strlen(config->query));
|
||||||
@ -1145,12 +1145,10 @@ static int sendCgi(const char *url,
|
|||||||
if (nfound <= 0) {
|
if (nfound <= 0) {
|
||||||
if (waitpid(pid, &status, WNOHANG) > 0) {
|
if (waitpid(pid, &status, WNOHANG) > 0) {
|
||||||
close(inFd);
|
close(inFd);
|
||||||
#if DEBUG
|
if (DEBUG && WIFEXITED(status))
|
||||||
if (WIFEXITED(status))
|
|
||||||
bb_error_msg("piped has exited with status=%d", WEXITSTATUS(status));
|
bb_error_msg("piped has exited with status=%d", WEXITSTATUS(status));
|
||||||
if (WIFSIGNALED(status))
|
if (DEBUG && WIFSIGNALED(status))
|
||||||
bb_error_msg("piped has exited with signal=%d", WTERMSIG(status));
|
bb_error_msg("piped has exited with signal=%d", WTERMSIG(status));
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) {
|
} else if (post_readed_size > 0 && FD_ISSET(outFd, &writeSet)) {
|
||||||
@ -1205,16 +1203,15 @@ static int sendCgi(const char *url,
|
|||||||
if (full_write(s, rbuf, count) != count)
|
if (full_write(s, rbuf, count) != count)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "cgi read %d bytes\n", count);
|
fprintf(stderr, "cgi read %d bytes\n", count);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_CGI */
|
#endif /* FEATURE_HTTPD_CGI */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
@ -1256,12 +1253,11 @@ static int sendFile(const char *url)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES */
|
#endif /* FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES */
|
||||||
|
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "sending file '%s' content-type: %s\n",
|
fprintf(stderr, "sending file '%s' content-type: %s\n",
|
||||||
url, config->found_mime_type);
|
url, config->found_mime_type);
|
||||||
#endif
|
|
||||||
|
|
||||||
f = open(url, O_RDONLY);
|
f = open(url, O_RDONLY);
|
||||||
if (f >= 0) {
|
if (f >= 0) {
|
||||||
@ -1269,15 +1265,15 @@ static int sendFile(const char *url)
|
|||||||
char *buf = config->buf;
|
char *buf = config->buf;
|
||||||
|
|
||||||
sendHeaders(HTTP_OK);
|
sendHeaders(HTTP_OK);
|
||||||
|
/* TODO: sendfile() */
|
||||||
while ((count = full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
|
while ((count = full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
|
||||||
if (full_write(config->accepted_socket, buf, count) != count)
|
if (full_write(config->accepted_socket, buf, count) != count)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
close(f);
|
close(f);
|
||||||
} else {
|
} else {
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
bb_perror_msg("cannot open '%s'", url);
|
bb_perror_msg("cannot open '%s'", url);
|
||||||
#endif
|
|
||||||
sendHeaders(HTTP_NOT_FOUND);
|
sendHeaders(HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1290,8 +1286,9 @@ static int checkPermIP(void)
|
|||||||
|
|
||||||
/* This could stand some work */
|
/* This could stand some work */
|
||||||
for (cur = config->ip_a_d; cur; cur = cur->next) {
|
for (cur = config->ip_a_d; cur; cur = cur->next) {
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "checkPermIP: '%s' ? ", config->rmt_ip_str);
|
fprintf(stderr, "checkPermIP: '%s' ? ", config->rmt_ip_str);
|
||||||
|
if (DEBUG)
|
||||||
fprintf(stderr, "'%u.%u.%u.%u/%u.%u.%u.%u'\n",
|
fprintf(stderr, "'%u.%u.%u.%u/%u.%u.%u.%u'\n",
|
||||||
(unsigned char)(cur->ip >> 24),
|
(unsigned char)(cur->ip >> 24),
|
||||||
(unsigned char)(cur->ip >> 16),
|
(unsigned char)(cur->ip >> 16),
|
||||||
@ -1301,7 +1298,6 @@ static int checkPermIP(void)
|
|||||||
(unsigned char)(cur->mask >> 16),
|
(unsigned char)(cur->mask >> 16),
|
||||||
(unsigned char)(cur->mask >> 8),
|
(unsigned char)(cur->mask >> 8),
|
||||||
cur->mask & 0xff);
|
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 */
|
return cur->allow_deny == 'A'; /* Allow/Deny */
|
||||||
}
|
}
|
||||||
@ -1338,18 +1334,19 @@ static int checkPerm(const char *path, const char *request)
|
|||||||
|
|
||||||
/* This could stand some work */
|
/* This could stand some work */
|
||||||
for (cur = config->auth; cur; cur = cur->next) {
|
for (cur = config->auth; cur; cur = cur->next) {
|
||||||
|
size_t l;
|
||||||
|
|
||||||
p0 = cur->before_colon;
|
p0 = cur->before_colon;
|
||||||
if (prev != NULL && strcmp(prev, p0) != 0)
|
if (prev != NULL && strcmp(prev, p0) != 0)
|
||||||
continue; /* find next identical */
|
continue; /* find next identical */
|
||||||
p = cur->after_colon;
|
p = cur->after_colon;
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "checkPerm: '%s' ? '%s'\n", p0, request);
|
fprintf(stderr, "checkPerm: '%s' ? '%s'\n", p0, request);
|
||||||
#endif
|
|
||||||
{
|
|
||||||
size_t l = strlen(p0);
|
|
||||||
|
|
||||||
if (strncmp(p0, path, l) == 0 &&
|
l = strlen(p0);
|
||||||
(l == 1 || path[l] == '/' || path[l] == 0)) {
|
if (strncmp(p0, path, l) == 0
|
||||||
|
&& (l == 1 || path[l] == '/' || path[l] == '\0')
|
||||||
|
) {
|
||||||
char *u;
|
char *u;
|
||||||
/* path match found. Check request */
|
/* path match found. Check request */
|
||||||
/* for check next /path:user:password */
|
/* for check next /path:user:password */
|
||||||
@ -1360,8 +1357,7 @@ static int checkPerm(const char *path, const char *request)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_FEATURE_HTTPD_AUTH_MD5
|
if (ENABLE_FEATURE_HTTPD_AUTH_MD5) {
|
||||||
{
|
|
||||||
char *cipher;
|
char *cipher;
|
||||||
char *pp;
|
char *pp;
|
||||||
|
|
||||||
@ -1380,11 +1376,9 @@ static int checkPerm(const char *path, const char *request)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (strcmp(p, request) == 0) {
|
if (strcmp(p, request) == 0) {
|
||||||
#if ENABLE_FEATURE_HTTPD_AUTH_MD5
|
|
||||||
set_remoteuser_var:
|
set_remoteuser_var:
|
||||||
#endif
|
|
||||||
config->remoteuser = strdup(request);
|
config->remoteuser = strdup(request);
|
||||||
if (config->remoteuser)
|
if (config->remoteuser)
|
||||||
config->remoteuser[(u - request)] = 0;
|
config->remoteuser[(u - request)] = 0;
|
||||||
@ -1392,13 +1386,12 @@ set_remoteuser_var:
|
|||||||
}
|
}
|
||||||
/* unauthorized */
|
/* unauthorized */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
return prev == NULL;
|
return prev == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */
|
#endif /* FEATURE_HTTPD_BASIC_AUTH */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
@ -1539,9 +1532,8 @@ BAD_REQUEST:
|
|||||||
config->found_moved_temporarily = url;
|
config->found_moved_temporarily = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "url='%s', args=%s\n", url, config->query);
|
fprintf(stderr, "url='%s', args=%s\n", url, config->query);
|
||||||
#endif
|
|
||||||
|
|
||||||
test = url;
|
test = url;
|
||||||
ip_allowed = checkPermIP();
|
ip_allowed = checkPermIP();
|
||||||
@ -1563,9 +1555,8 @@ BAD_REQUEST:
|
|||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "Header: '%s'\n", buf);
|
fprintf(stderr, "header: '%s'\n", buf);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_HTTPD_CGI
|
#if ENABLE_FEATURE_HTTPD_CGI
|
||||||
/* try and do our best to parse more lines */
|
/* try and do our best to parse more lines */
|
||||||
@ -1602,7 +1593,7 @@ BAD_REQUEST:
|
|||||||
decodeBase64(test);
|
decodeBase64(test);
|
||||||
credentials = checkPerm(url, test);
|
credentials = checkPerm(url, test);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_BASIC_AUTH */
|
#endif /* FEATURE_HTTPD_BASIC_AUTH */
|
||||||
|
|
||||||
} /* while extra header reading */
|
} /* while extra header reading */
|
||||||
}
|
}
|
||||||
@ -1648,7 +1639,7 @@ FORBIDDEN: /* protect listing /cgi-bin */
|
|||||||
if (prequest != request_GET)
|
if (prequest != request_GET)
|
||||||
sendHeaders(HTTP_NOT_IMPLEMENTED);
|
sendHeaders(HTTP_NOT_IMPLEMENTED);
|
||||||
else {
|
else {
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_CGI */
|
#endif /* FEATURE_HTTPD_CGI */
|
||||||
if (purl[-1] == '/')
|
if (purl[-1] == '/')
|
||||||
strcpy(purl, "index.html");
|
strcpy(purl, "index.html");
|
||||||
if (stat(test, &sb) == 0) {
|
if (stat(test, &sb) == 0) {
|
||||||
@ -1663,9 +1654,8 @@ FORBIDDEN: /* protect listing /cgi-bin */
|
|||||||
#endif
|
#endif
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
# if DEBUG
|
if (DEBUG)
|
||||||
fprintf(stderr, "closing socket\n\n");
|
fprintf(stderr, "closing socket\n\n");
|
||||||
# endif
|
|
||||||
#if ENABLE_FEATURE_HTTPD_CGI
|
#if ENABLE_FEATURE_HTTPD_CGI
|
||||||
free(cookie);
|
free(cookie);
|
||||||
free(content_type);
|
free(content_type);
|
||||||
@ -1742,7 +1732,7 @@ static int miniHttpd(int server)
|
|||||||
bb_error_msg("connection from IP=%s, port %u",
|
bb_error_msg("connection from IP=%s, port %u",
|
||||||
config->rmt_ip_str, config->port);
|
config->rmt_ip_str, config->port);
|
||||||
#endif
|
#endif
|
||||||
#endif /* CONFIG_FEATURE_HTTPD_CGI */
|
#endif /* FEATURE_HTTPD_CGI */
|
||||||
|
|
||||||
/* set the KEEPALIVE option to cull dead connections */
|
/* set the KEEPALIVE option to cull dead connections */
|
||||||
on = 1;
|
on = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user