1
0
mirror of https://github.com/falk-werner/webfuse synced 2025-06-06 09:24:17 +00:00

adds userdb for authentication purposes

This commit is contained in:
Falk Werner 2019-03-31 21:31:37 +02:00
parent 81fb090537
commit 9c5e56368f
2 changed files with 9 additions and 17 deletions

View File

@ -213,9 +213,9 @@ add_executable(webfused
example/daemon/main.c example/daemon/main.c
) )
target_link_libraries(webfused PUBLIC webfuse-adapter ${EXTRA_LIBS}) target_link_libraries(webfused PUBLIC webfuse-adapter userdb ${OPENSSL_LIBRARIES} ${EXTRA_LIBS})
target_include_directories(webfused PUBLIC ${EXTRA_INCLUDE_DIRS}) target_include_directories(webfused PUBLIC ${EXTRA_INCLUDE_DIRS})
target_compile_options(webfused PUBLIC ${EXTRA_CFLAGS}) target_compile_options(webfused PUBLIC ${C_WARNINGS} ${OPENSSL_CFLAGS_OTHER} ${EXTRA_CFLAGS})
# provider # provider

View File

@ -7,9 +7,9 @@
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
#include <jansson.h>
#include <webfuse_adapter.h> #include <webfuse_adapter.h>
#include <userdb.h>
struct args struct args
@ -50,20 +50,12 @@ static bool authenticate(struct wf_credentials * creds, void * user_data)
char const * password = wf_credentials_get(creds, "password"); char const * password = wf_credentials_get(creds, "password");
if ((NULL != username) && (NULL != password)) if ((NULL != username) && (NULL != password))
{ {
json_t * passwd = json_load_file(args->passwd_path, 0, NULL); struct userdb * db = userdb_create("<pepper>");
if (NULL != passwd) result = userdb_load(db, args->passwd_path);
if (result)
{ {
json_t * user = json_object_get(passwd, username); result = userdb_check(db, username, password);
if (json_is_object(user)) userdb_dispose(db);
{
json_t * password_holder = json_object_get(user, "password");
if (json_is_string(password_holder))
{
result = (0 == strcmp(password, json_string_value(password_holder)));
}
}
json_decref(passwd);
} }
} }