From 661e7e3aae7fdfed9df624c061f49b96efe7d9ac Mon Sep 17 00:00:00 2001 From: g-rden <94605617+g-rden@users.noreply.github.com> Date: Sat, 2 Mar 2024 20:03:13 +0000 Subject: [PATCH] check why dir failed to open and send correct reply --- darkhttpd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/darkhttpd.c b/darkhttpd.c index 5ea3702..468b03e 100644 --- a/darkhttpd.c +++ b/darkhttpd.c @@ -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; }