1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/lib/webfuse/impl/authenticators.c

101 lines
2.7 KiB
C
Raw Normal View History

2020-06-28 13:51:34 +00:00
#include "webfuse/impl/authenticators.h"
2019-03-26 22:04:53 +00:00
#include <stddef.h>
#include <string.h>
2020-06-28 13:51:34 +00:00
#include "webfuse/impl/authenticator.h"
#include "webfuse/impl/credentials.h"
2019-03-26 22:04:53 +00:00
static struct wf_impl_authenticator * wf_impl_authenticators_find(
struct wf_impl_authenticators * authenticators,
char const * type)
{
struct wf_impl_authenticator * result = NULL;
struct wf_impl_authenticator * actual = authenticators->first;
while ((NULL == result) && (NULL != actual))
{
struct wf_impl_authenticator * next = actual->next;
if (0 == strcmp(type, actual->type))
{
result = actual;
}
actual = next;
}
return result;
}
void wf_impl_authenticators_init(
struct wf_impl_authenticators * authenticators)
{
authenticators->first = NULL;
}
void wf_impl_authenticators_cleanup(
struct wf_impl_authenticators * authenticators)
{
struct wf_impl_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wf_impl_authenticator * next = actual->next;
wf_impl_authenticator_dispose(actual);
actual = next;
}
authenticators->first = NULL;
}
void wf_impl_authenticators_clone(
struct wf_impl_authenticators * authenticators,
struct wf_impl_authenticators * other)
{
wf_impl_authenticators_init(other);
struct wf_impl_authenticator * actual = authenticators->first;
while (NULL != actual)
{
struct wf_impl_authenticator * next = actual->next;
wf_impl_authenticators_add(other,
actual->type, actual->authenticate, actual->user_data);
actual = next;
}
}
extern void wf_impl_authenticators_move(
struct wf_impl_authenticators * authenticators,
struct wf_impl_authenticators * other)
{
other->first = authenticators->first;
authenticators->first = NULL;
}
void wf_impl_authenticators_add(
struct wf_impl_authenticators * authenticators,
char const * type,
wf_authenticate_fn * authenticate,
void * user_data)
{
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(type, authenticate, user_data);
authenticator->next = authenticators->first;
authenticators->first = authenticator;
}
bool wf_impl_authenticators_authenticate(
struct wf_impl_authenticators * authenticators,
struct wf_credentials * credentials)
{
bool result = (NULL == authenticators->first);
if (NULL != credentials)
{
struct wf_impl_authenticator * authenticator = wf_impl_authenticators_find(authenticators, credentials->type);
if (NULL != authenticator)
{
result = wf_impl_authenticator_autenticate(authenticator, credentials);
}
}
return result;
}