mirror of
https://github.com/falk-werner/webfused
synced 2026-03-02 04:09:19 +00:00
parse authentication settings
This commit is contained in:
8
src/webfused/auth/authenticator.c
Normal file
8
src/webfused/auth/authenticator.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "webfused/auth/authenticator.h"
|
||||
|
||||
void
|
||||
wfd_authenticator_dispose(
|
||||
struct wfd_authenticator authenticator)
|
||||
{
|
||||
authenticator.vtable->dispose(authenticator.data);
|
||||
}
|
||||
36
src/webfused/auth/authenticator.h
Normal file
36
src/webfused/auth/authenticator.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef WFD_AUTH_AUTHENTICATOR_H
|
||||
#define WFD_AUTH_AUTHENTICATOR_H
|
||||
|
||||
#include "webfuse/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void
|
||||
wfd_authenticator_dispose_fn(
|
||||
void * data);
|
||||
|
||||
struct wfd_authenticator_vtable
|
||||
{
|
||||
wfd_authenticator_dispose_fn * dispose;
|
||||
wf_authenticate_fn * authenticate;
|
||||
};
|
||||
|
||||
struct wfd_authenticator
|
||||
{
|
||||
struct wfd_authenticator_vtable const * vtable;
|
||||
void * data;
|
||||
};
|
||||
|
||||
extern void
|
||||
wfd_authenticator_dispose(
|
||||
struct wfd_authenticator authenticator);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
25
src/webfused/auth/factory.c
Normal file
25
src/webfused/auth/factory.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "webfused/auth/factory.h"
|
||||
#include "webfused/auth/settings.h"
|
||||
#include "webfused/auth/file_authenticator.h"
|
||||
#include "webfused/log/log.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
bool
|
||||
wfd_authenticator_create(
|
||||
struct wfd_auth_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))
|
||||
{
|
||||
result = wfd_file_authenticator_create(settings, authenticator);
|
||||
}
|
||||
else
|
||||
{
|
||||
WFD_ERROR("failed to create authenticator: unknown type \"%s\"", provider_name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
25
src/webfused/auth/factory.h
Normal file
25
src/webfused/auth/factory.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef WFD_AUTHENTICATION_FACTORY_H
|
||||
#define WFD_AUTHENTICATION_FACTORY_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_authenticator;
|
||||
struct wfd_auth_settings;
|
||||
|
||||
extern bool
|
||||
wfd_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
9
src/webfused/auth/file_authenticator.c
Normal file
9
src/webfused/auth/file_authenticator.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "webfused/auth/file_authenticator.h"
|
||||
|
||||
bool
|
||||
wfd_file_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
26
src/webfused/auth/file_authenticator.h
Normal file
26
src/webfused/auth/file_authenticator.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef WFD_AUTH_FILE_AUTHENTICATOR_H
|
||||
#define WFD_AUTH_FILE_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_authenticator;
|
||||
struct wfd_auth_settings;
|
||||
|
||||
extern bool
|
||||
wfd_file_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
#ifndef WFD_AUTH_SETTINGS_BUILDER_H
|
||||
#define WFD_AUTH_SETTINGS_BUILDER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#endif
|
||||
|
||||
extern struct wfd_auth_settings *
|
||||
wfd_auth_settings_create(void);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_dispose(
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_set_provider(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * provider);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_add(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key,
|
||||
char const * value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#endif
|
||||
|
||||
#endif
|
||||
51
src/webfused/config/auth_settings.c
Normal file
51
src/webfused/config/auth_settings.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
25
src/webfused/config/auth_settings.h
Normal file
25
src/webfused/config/auth_settings.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#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
|
||||
@@ -40,3 +40,12 @@ wfd_config_builder_set_server_document_root(
|
||||
builder.vtable->set_server_document_root(builder.data, document_root);
|
||||
}
|
||||
|
||||
bool
|
||||
wfd_config_builder_add_auth_provider(
|
||||
struct wfd_config_builder builder,
|
||||
struct wfd_auth_settings * settings)
|
||||
{
|
||||
return builder.vtable->add_auth_provider(builder.data, settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
#ifndef WFD_CONFIG_BUILDER_H
|
||||
#define WFD_CONFIG_BUILDER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_auth_settings;
|
||||
|
||||
typedef void
|
||||
wfd_config_builder_set_server_vhostname_fn(
|
||||
void * data,
|
||||
@@ -31,6 +37,11 @@ wfd_config_builder_set_server_document_root_fn(
|
||||
void * data,
|
||||
char const * document_root);
|
||||
|
||||
typedef bool
|
||||
wfd_config_builder_add_auth_provider_fn(
|
||||
void * data,
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
struct wfd_config_builder_vtable
|
||||
{
|
||||
wfd_config_builder_set_server_vhostname_fn * set_server_vhostname;
|
||||
@@ -38,6 +49,7 @@ struct wfd_config_builder_vtable
|
||||
wfd_config_builder_set_server_key_fn * set_server_key;
|
||||
wfd_config_builder_set_server_cert_fn * set_server_cert;
|
||||
wfd_config_builder_set_server_document_root_fn * set_server_document_root;
|
||||
wfd_config_builder_add_auth_provider_fn * add_auth_provider;
|
||||
};
|
||||
|
||||
struct wfd_config_builder
|
||||
@@ -71,6 +83,11 @@ wfd_config_builder_set_server_document_root(
|
||||
struct wfd_config_builder builder,
|
||||
char const * document_root);
|
||||
|
||||
extern bool
|
||||
wfd_config_builder_add_auth_provider(
|
||||
struct wfd_config_builder builder,
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/config/auth_settings.h"
|
||||
#include "webfused/log/log.h"
|
||||
|
||||
#include <libconfig.h>
|
||||
@@ -97,6 +98,51 @@ wfd_config_read_server(
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
wfd_config_read_authentication(
|
||||
config_t * config,
|
||||
struct wfd_config_builder builder)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
bool hasAuthentication = (NULL != config_lookup(config, "authentication"));
|
||||
if (hasAuthentication)
|
||||
{
|
||||
char const * provider_name = NULL;
|
||||
{
|
||||
int rc = config_lookup_string(config, "authentication.provider", &provider_name);
|
||||
if (CONFIG_TRUE != rc)
|
||||
{
|
||||
WFD_ERROR("missing authentication provider");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
struct config_setting_t * settings = NULL;
|
||||
if (result)
|
||||
{
|
||||
settings = config_lookup(config, "authentication.settings");
|
||||
if (NULL == settings)
|
||||
{
|
||||
WFD_ERROR("missing authentication settings");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
struct wfd_auth_settings * auth_settings = wfd_auth_settings_create(
|
||||
provider_name, settings);
|
||||
|
||||
result = wfd_config_builder_add_auth_provider(builder, auth_settings);
|
||||
wfd_auth_settings_dispose(auth_settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool
|
||||
wfd_config_load(
|
||||
struct wfd_config_builder builder,
|
||||
@@ -105,6 +151,7 @@ wfd_config_load(
|
||||
|
||||
bool result = wfd_config_check_version(config)
|
||||
&& wfd_config_read_server(config, builder)
|
||||
&& wfd_config_read_authentication(config, builder)
|
||||
;
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user