1
0
mirror of https://github.com/falk-werner/webfused synced 2026-03-02 04:09:19 +00:00

refactor: generalize auth_settings

This commit is contained in:
Falk Werner
2020-03-18 10:17:17 +01:00
parent 609fbee24f
commit 1625869696
28 changed files with 272 additions and 315 deletions

View File

@@ -1,24 +1,24 @@
#include "webfused/auth/factory.h"
#include "webfused/auth/settings.h"
#include "webfused/auth/file_authenticator.h"
#include "webfused/config/settings.h"
#include "webfused/log/log.h"
#include <string.h>
bool
wfd_authenticator_create(
struct wfd_auth_settings * settings,
char const * provider,
struct wfd_settings * settings,
struct wfd_authenticator * authenticator)
{
bool result = false;
char const * provider_name = wfd_auth_settings_get_provider(settings);
if (0 == strcmp("file", provider_name))
if (0 == strcmp("file", provider))
{
result = wfd_file_authenticator_create(settings, authenticator);
}
else
{
WFD_ERROR("failed to create authenticator: unknown type \"%s\"", provider_name);
WFD_ERROR("failed to create authenticator: unknown type \"%s\"", provider);
}
return result;

View File

@@ -11,11 +11,12 @@ extern "C"
#endif
struct wfd_authenticator;
struct wfd_auth_settings;
struct wfd_settings;
extern bool
wfd_authenticator_create(
struct wfd_auth_settings * settings,
char const * provider,
struct wfd_settings * settings,
struct wfd_authenticator * authenticator);
#ifdef __cplusplus

View File

@@ -1,11 +1,11 @@
#include "webfused/auth/file_authenticator.h"
#include "webfused/auth/settings.h"
#include "webfused/auth/authenticator.h"
#include "webfuse/adapter/credentials.h"
#include "webfused/config/settings.h"
#include "userdb/userdb.h"
#include "webfused/log/log.h"
#include <webfuse/adapter/credentials.h>
#include <stdlib.h>
#include <string.h>
@@ -71,12 +71,12 @@ wfd_file_authenticator_vtable =
bool
wfd_file_authenticator_create(
struct wfd_auth_settings * settings,
struct wfd_settings * settings,
struct wfd_authenticator * authenticator)
{
bool result = false;
char const * filename = wfd_auth_settings_get(settings, "file");
char const * filename = wfd_settings_get(settings, "file");
if (NULL != filename)
{
struct wfd_file_authenticator * data = malloc(sizeof(struct wfd_file_authenticator));

View File

@@ -12,11 +12,11 @@ extern "C"
#endif
struct wfd_authenticator;
struct wfd_auth_settings;
struct wfd_settings;
extern bool
wfd_file_authenticator_create(
struct wfd_auth_settings * settings,
struct wfd_settings * settings,
struct wfd_authenticator * authenticator);
#ifdef __cplusplus

View File

@@ -1,30 +0,0 @@
#ifndef WFD_AUTH_SETTINGS_H
#define WFD_AUTH_SETTINGS_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_auth_settings;
extern char const *
wfd_auth_settings_get_provider(
struct wfd_auth_settings * settings);
extern char const *
wfd_auth_settings_get(
struct wfd_auth_settings * settings,
char const * key);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,51 +0,0 @@
#include "webfused/auth/settings.h"
#include "webfused/config/auth_settings.h"
#include <libconfig.h>
#include <stdlib.h>
#include <string.h>
struct wfd_auth_settings
{
char * provider_name;
struct config_setting_t * settings;
};
struct wfd_auth_settings *
wfd_auth_settings_create(
char const * provider_name,
struct config_setting_t * settings)
{
struct wfd_auth_settings * auth_settings = malloc(sizeof(struct wfd_auth_settings));
auth_settings->provider_name = strdup(provider_name);
auth_settings->settings = settings;
return auth_settings;
}
void
wfd_auth_settings_dispose(
struct wfd_auth_settings * settings)
{
free(settings->provider_name);
free(settings);
}
char const *
wfd_auth_settings_get_provider(
struct wfd_auth_settings * settings)
{
return settings->provider_name;
}
char const *
wfd_auth_settings_get(
struct wfd_auth_settings * settings,
char const * key)
{
char const * result;
int rc = config_setting_lookup_string(settings->settings, key, &result);
return (CONFIG_TRUE == rc) ? result : NULL;
}

View File

@@ -1,25 +0,0 @@
#ifndef WFD_CONFIG_AUTH_SETTINGS_H
#define WFD_CONFIG_AUTH_SETTINGS_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_auth_settings;
struct config_setting_t;
extern struct wfd_auth_settings *
wfd_auth_settings_create(
char const * provider_name,
struct config_setting_t * settings);
extern void
wfd_auth_settings_dispose(
struct wfd_auth_settings * settings);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -43,9 +43,10 @@ wfd_config_builder_set_server_document_root(
bool
wfd_config_builder_add_auth_provider(
struct wfd_config_builder builder,
struct wfd_auth_settings * settings)
char const * provider,
struct wfd_settings * settings)
{
return builder.vtable->add_auth_provider(builder.data, settings);
return builder.vtable->add_auth_provider(builder.data, provider, settings);
}
bool

View File

@@ -10,7 +10,7 @@ extern "C"
{
#endif
struct wfd_auth_settings;
struct wfd_settings;
typedef void
wfd_config_builder_set_server_vhostname_fn(
@@ -40,7 +40,8 @@ wfd_config_builder_set_server_document_root_fn(
typedef bool
wfd_config_builder_add_auth_provider_fn(
void * data,
struct wfd_auth_settings * settings);
char const * provider,
struct wfd_settings * settings);
typedef bool
wfd_config_builder_add_filesystem_fn(
@@ -93,7 +94,8 @@ wfd_config_builder_set_server_document_root(
extern bool
wfd_config_builder_add_auth_provider(
struct wfd_config_builder builder,
struct wfd_auth_settings * settings);
char const * provider,
struct wfd_settings * settings);
extern bool
wfd_config_builder_add_filesystem(

View File

@@ -65,14 +65,15 @@ wfd_config_set_server_document_root(
static bool
wfd_config_add_auth_provider(
void * data,
struct wfd_auth_settings * settings)
char const * provider,
struct wfd_settings * settings)
{
bool result = false;
struct wfd_config * config = data;
if (!config->has_authenticator)
{
result = wfd_authenticator_create(settings, &config->authenticator);
result = wfd_authenticator_create(provider, settings, &config->authenticator);
if (result)
{
wf_server_config_add_authenticator(

View File

@@ -1,5 +1,5 @@
#include "webfused/config/factory.h"
#include "webfused/config/auth_settings.h"
#include "webfused/config/settings_intern.h"
#include "webfused/log/log.h"
#include <libconfig.h>
@@ -131,13 +131,12 @@ wfd_config_read_authentication(
if (result)
{
struct wfd_auth_settings * auth_settings = wfd_auth_settings_create(
provider_name, settings);
struct wfd_settings auth_settings;
wfd_settings_init(&auth_settings, settings);
result = wfd_config_builder_add_auth_provider(builder, auth_settings);
wfd_auth_settings_dispose(auth_settings);
result = wfd_config_builder_add_auth_provider(builder, provider_name, &auth_settings);
wfd_settings_cleanup(&auth_settings);
}
}
return result;

View File

@@ -0,0 +1,32 @@
#include "webfused/config/settings.h"
#include "webfused/config/settings_intern.h"
#include <libconfig.h>
#include <stddef.h>
void
wfd_settings_init(
struct wfd_settings * settings,
struct config_setting_t * setting)
{
settings->setting = setting;
}
void
wfd_settings_cleanup(
struct wfd_settings * settings)
{
settings->setting = NULL;
}
char const *
wfd_settings_get(
struct wfd_settings * settings,
char const * key)
{
char const * result;
int rc = config_setting_lookup_string(settings->setting, key, &result);
return (CONFIG_TRUE == rc) ? result : NULL;
}

View File

@@ -0,0 +1,22 @@
#ifndef WFD_CONFIG_SETTINGS_H
#define WFD_CONFIG_SETTINGS_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_settings;
extern char const *
wfd_settings_get(
struct wfd_settings * settings,
char const * key);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,30 @@
#ifndef WFD_CONFIG_SETTINGS_INTERN_H
#define WFD_CONFIG_SETTINGS_INTERN_H
#ifdef __cplusplus
extern "C"
{
#endif
struct config_setting_t;
struct wfd_settings
{
struct config_setting_t * setting;
};
extern void
wfd_settings_init(
struct wfd_settings * settings,
struct config_setting_t * setting);
extern void
wfd_settings_cleanup(
struct wfd_settings * settings);
#ifdef __cplusplus
}
#endif
#endif