Add logging and fix incorrect get_path calls
This commit is contained in:
14
src/server.c
14
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);
|
||||
|
||||
Reference in New Issue
Block a user