Add logging and fix incorrect get_path calls
This commit is contained in:
@@ -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) {
|
static enum MHD_Result handle_opds(struct MHD_Connection *connection, SV url, Settings settings, SV username) {
|
||||||
noh_arena_save(&temp);
|
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 fs_path_cstr = fs_path;
|
||||||
noh_string_append_null(&fs_path_cstr);
|
noh_string_append_null(&fs_path_cstr);
|
||||||
|
|
||||||
|
|||||||
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
|
#ifdef NO_AUTH
|
||||||
(void)connection;
|
(void)connection;
|
||||||
|
|
||||||
|
noh_log(NOH_INFO, "Authorized as demo.");
|
||||||
*username = sv("demo");
|
*username = sv("demo");
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
@@ -43,7 +44,7 @@ static bool authorize_user(struct MHD_Connection *connection, SV *username, Sett
|
|||||||
// Read the users file.
|
// Read the users file.
|
||||||
noh_arena_save(&temp);
|
noh_arena_save(&temp);
|
||||||
Noh_String_View file_name = noh_sv_from_cstr("users.conf");
|
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_append_null(&users_file_path);
|
||||||
|
|
||||||
Noh_String hashed = {0};
|
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 (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.
|
// Hash the provided password.
|
||||||
hashed = hash_password(provided_username, provided_password);
|
hashed = hash_password(provided_username, provided_password);
|
||||||
|
|
||||||
// Check the hash.
|
// 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;
|
*username = provided_username;
|
||||||
|
noh_log(NOH_INFO, "Authorized as "Nsv_Fmt".", Nsv_Arg(*username));
|
||||||
|
|
||||||
defer:
|
defer:
|
||||||
noh_string_free(&hashed);
|
noh_string_free(&hashed);
|
||||||
|
|||||||
@@ -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) {
|
bool read_users_file(char *file_path, Noh_String *users_file, Users *users) {
|
||||||
noh_log(NOH_INFO, "Reading users file: %s", file_path);
|
noh_log(NOH_INFO, "Reading users file: %s", file_path);
|
||||||
if (!noh_file_exists(file_path)) return true;
|
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 users_file_sv = noh_sv_from_string(*users_file);
|
||||||
|
|
||||||
Noh_String_View line = {0};
|
Noh_String_View line = {0};
|
||||||
|
|||||||
Reference in New Issue
Block a user