Add logging and fix incorrect get_path calls

This commit is contained in:
2026-06-17 17:34:07 +02:00
parent d349d77085
commit 0ab6904c11
3 changed files with 16 additions and 5 deletions

View File

@@ -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);