diff --git a/src/opds_handler.c b/src/opds_handler.c index 50f7162..30ba040 100644 --- a/src/opds_handler.c +++ b/src/opds_handler.c @@ -48,7 +48,7 @@ static Noh_String create_feed_response(Library_Entry self_path, SV url, Library_ static enum MHD_Result handle_opds(struct MHD_Connection *connection, SV url, Settings settings, SV username) { noh_arena_save(&temp); - Noh_String fs_path = build_path(false, &settings.base_path, &username, &url); + Noh_String fs_path = build_path(false, false, &settings.base_path, &username, &url); Noh_String fs_path_cstr = fs_path; noh_string_append_null(&fs_path_cstr); diff --git a/src/server.c b/src/server.c index e0611d8..0a9a77e 100644 --- a/src/server.c +++ b/src/server.c @@ -29,6 +29,7 @@ static bool authorize_user(struct MHD_Connection *connection, SV *username, Sett #ifdef NO_AUTH (void)connection; + noh_log(NOH_INFO, "Authorized as demo."); *username = sv("demo"); return false; #else @@ -43,7 +44,7 @@ static bool authorize_user(struct MHD_Connection *connection, SV *username, Sett // Read the users file. noh_arena_save(&temp); Noh_String_View file_name = noh_sv_from_cstr("users.conf"); - Noh_String users_file_path = build_path(false, &settings->base_path, &file_name); + Noh_String users_file_path = build_path(false, false, &settings->base_path, &file_name); noh_string_append_null(&users_file_path); Noh_String hashed = {0}; @@ -60,15 +61,22 @@ static bool authorize_user(struct MHD_Connection *connection, SV *username, Sett if (noh_sv_eq(provided_username, user->username)) found_user = true; } - if (!found_user) noh_return_defer(false); + if (!found_user) { + noh_log(NOH_INFO, "User "Nsv_Fmt" does not exist.", Nsv_Arg(provided_username)); + noh_return_defer(false); + } // Hash the provided password. hashed = hash_password(provided_username, provided_password); // Check the hash. - if (!noh_sv_eq(noh_sv_from_string(hashed), user->hash)) noh_return_defer(false); + if (!noh_sv_eq(noh_sv_from_string(hashed), user->hash)) { + noh_log(NOH_INFO, "Incorrect password."); + noh_return_defer(false); + } *username = provided_username; + noh_log(NOH_INFO, "Authorized as "Nsv_Fmt".", Nsv_Arg(*username)); defer: noh_string_free(&hashed); diff --git a/src/users.c b/src/users.c index aae8e07..51f94f1 100644 --- a/src/users.c +++ b/src/users.c @@ -42,7 +42,10 @@ Noh_String hash_password(Noh_String_View username, Noh_String_View password) { bool read_users_file(char *file_path, Noh_String *users_file, Users *users) { noh_log(NOH_INFO, "Reading users file: %s", file_path); if (!noh_file_exists(file_path)) return true; - if (!noh_string_read_file(users_file, file_path)) return false; + if (!noh_string_read_file(users_file, file_path)) { + noh_log(NOH_ERROR, "Could not read users file."); + return false; + } Noh_String_View users_file_sv = noh_sv_from_string(*users_file); Noh_String_View line = {0};