Skip to content

Commit

Permalink
check why dir failed to open and send correct reply
Browse files Browse the repository at this point in the history
  • Loading branch information
g-rden authored Mar 2, 2024
1 parent 2f99f29 commit 661e7e3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions darkhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,16 @@ static void generate_dir_listing(struct connection *conn, const char *path,

listsize = make_sorted_dirlist(path, &list);
if (listsize == -1) {
default_reply(conn, 500, "Internal Server Error",
"Couldn't list directory: %s", strerror(errno));
/* opendir() failed */
if (errno == EACCES)
default_reply(conn, 403, "Forbidden",
"You don't have permission to access this URL.");
else if (errno == ENOENT)
default_reply(conn, 404, "Not Found",
"The URL you requested was not found.");
else
default_reply(conn, 500, "Internal Server Error",
"Couldn't list directory: %s", strerror(errno));
return;
}

Expand Down

0 comments on commit 661e7e3

Please sign in to comment.