mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
add option to deny directory listing
Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
parent
4e726692f4
commit
03f4c1f390
11
darkhttpd.c
11
darkhttpd.c
@ -272,6 +272,7 @@ static in_addr_t bindaddr = INADDR_ANY;
|
|||||||
static uint16_t bindport = 8080; /* or 80 if running as root */
|
static uint16_t bindport = 8080; /* or 80 if running as root */
|
||||||
static int max_connections = -1; /* kern.ipc.somaxconn */
|
static int max_connections = -1; /* kern.ipc.somaxconn */
|
||||||
static const char *index_name = "index.html";
|
static const char *index_name = "index.html";
|
||||||
|
static int no_listing = 0;
|
||||||
|
|
||||||
static int sockin = -1; /* socket to accept connections from */
|
static int sockin = -1; /* socket to accept connections from */
|
||||||
static char *wwwroot = NULL; /* a path name */
|
static char *wwwroot = NULL; /* a path name */
|
||||||
@ -886,6 +887,8 @@ static void usage(const char *argv0) {
|
|||||||
printf("\t--index filename (default: %s)\n"
|
printf("\t--index filename (default: %s)\n"
|
||||||
"\t\tDefault file to serve when a directory is requested.\n\n",
|
"\t\tDefault file to serve when a directory is requested.\n\n",
|
||||||
index_name);
|
index_name);
|
||||||
|
printf("\t--no-listing\n"
|
||||||
|
"\t\tDo not serve listing if directory is requested.\n\n");
|
||||||
printf("\t--mimetypes filename (optional)\n"
|
printf("\t--mimetypes filename (optional)\n"
|
||||||
"\t\tParses specified file for extension-MIME associations.\n\n");
|
"\t\tParses specified file for extension-MIME associations.\n\n");
|
||||||
printf("\t--uid uid/uname, --gid gid/gname (default: don't privdrop)\n"
|
printf("\t--uid uid/uname, --gid gid/gname (default: don't privdrop)\n"
|
||||||
@ -994,6 +997,9 @@ static void parse_commandline(const int argc, char *argv[]) {
|
|||||||
errx(1, "missing filename after --index");
|
errx(1, "missing filename after --index");
|
||||||
index_name = argv[i];
|
index_name = argv[i];
|
||||||
}
|
}
|
||||||
|
else if (strcmp(argv[i], "--no-listing") == 0) {
|
||||||
|
no_listing = 1;
|
||||||
|
}
|
||||||
else if (strcmp(argv[i], "--mimetypes") == 0) {
|
else if (strcmp(argv[i], "--mimetypes") == 0) {
|
||||||
if (++i >= argc)
|
if (++i >= argc)
|
||||||
errx(1, "missing filename after --mimetypes");
|
errx(1, "missing filename after --mimetypes");
|
||||||
@ -1827,6 +1833,11 @@ static void process_get(struct connection *conn) {
|
|||||||
xasprintf(&target, "%s%s%s", wwwroot, decoded_url, index_name);
|
xasprintf(&target, "%s%s%s", wwwroot, decoded_url, index_name);
|
||||||
if (!file_exists(target)) {
|
if (!file_exists(target)) {
|
||||||
free(target);
|
free(target);
|
||||||
|
if (no_listing) {
|
||||||
|
default_reply(conn, 404, "Not Found",
|
||||||
|
"The URL you requested (%s) was not found.", conn->url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
xasprintf(&target, "%s%s", wwwroot, decoded_url);
|
xasprintf(&target, "%s%s", wwwroot, decoded_url);
|
||||||
generate_dir_listing(conn, target);
|
generate_dir_listing(conn, target);
|
||||||
free(target);
|
free(target);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user