1
0
mirror of https://github.com/falk-werner/webfused synced 2024-09-30 01:50:46 +00:00
falk-werner_webfused/src/webfused/auth/file_authenticator.c

87 lines
1.9 KiB
C
Raw Normal View History

2020-03-16 20:50:31 +00:00
#include "webfused/auth/file_authenticator.h"
#include "webfused/auth/settings.h"
#include "webfused/auth/authenticator.h"
#include "webfuse/adapter/credentials.h"
#include "userdb/userdb.h"
#include <stdlib.h>
#include <string.h>
struct wfd_file_authenticator
{
char * filename;
};
static void
wfd_file_authenticator_dispose(
void * data)
{
struct wfd_file_authenticator * authenticator = data;
free(authenticator->filename);
free(authenticator);
}
static bool
wfd_file_authenticator_authenticate(
struct wf_credentials * credentials,
void * user_data)
{
bool result = false;
struct wfd_file_authenticator * authenticator = user_data;
char const * username = wf_credentials_get(credentials, "username");
char const * password = wf_credentials_get(credentials, "password");
if ((NULL != username) && (NULL != password))
{
struct userdb * db = userdb_create("");
result = userdb_load(db, authenticator->filename);
if (result)
{
result = userdb_check(db, username, password);
}
userdb_dispose(db);
}
return result;
}
2020-03-17 15:49:17 +00:00
static char const *
wfd_file_authenticator_get_type(
void * data)
{
(void) data;
return "username";
}
static struct wfd_authenticator_vtable
wfd_file_authenticator_vtable =
{
.dispose = &wfd_file_authenticator_dispose,
2020-03-17 15:49:17 +00:00
.authenticate = &wfd_file_authenticator_authenticate,
.get_type = &wfd_file_authenticator_get_type
};
2020-03-16 20:50:31 +00:00
bool
wfd_file_authenticator_create(
struct wfd_auth_settings * settings,
struct wfd_authenticator * authenticator)
{
bool result = false;
char const * filename = wfd_auth_settings_get(settings, "file");
if (NULL != filename)
{
struct wfd_file_authenticator * data = malloc(sizeof(struct wfd_file_authenticator));
data->filename = strdup(filename);
authenticator->vtable = &wfd_file_authenticator_vtable;
authenticator->data = data;
result = true;
}
return result;
2020-03-16 20:50:31 +00:00
}