mirror of
https://github.com/falk-werner/webfused
synced 2026-03-02 04:09:19 +00:00
added implementation of file_authenticator
This commit is contained in:
@@ -6,3 +6,13 @@ wfd_authenticator_dispose(
|
||||
{
|
||||
authenticator.vtable->dispose(authenticator.data);
|
||||
}
|
||||
|
||||
extern bool
|
||||
wfd_authenticator_authenticate(
|
||||
struct wfd_authenticator authenticator,
|
||||
struct wf_credentials * credentials)
|
||||
{
|
||||
return authenticator.vtable->authenticate(
|
||||
credentials, authenticator.data);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ extern void
|
||||
wfd_authenticator_dispose(
|
||||
struct wfd_authenticator authenticator);
|
||||
|
||||
extern bool
|
||||
wfd_authenticator_authenticate(
|
||||
struct wfd_authenticator authenticator,
|
||||
struct wf_credentials * credentials);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,9 +1,77 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
static struct wfd_authenticator_vtable
|
||||
wfd_file_authenticator_vtable =
|
||||
{
|
||||
.dispose = &wfd_file_authenticator_dispose,
|
||||
.authenticate = &wfd_file_authenticator_authenticate
|
||||
};
|
||||
|
||||
bool
|
||||
wfd_file_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator)
|
||||
{
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user