2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/authenticator.h"
|
2019-03-23 21:53:14 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/credentials.h"
|
2019-03-23 21:53:14 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wf_impl_authenticator * wf_impl_authenticator_create(
|
2019-03-23 21:53:14 +00:00
|
|
|
char const * type,
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_authenticate_fn * authenticate,
|
2019-03-23 21:53:14 +00:00
|
|
|
void * user_data)
|
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
|
2019-03-23 21:53:14 +00:00
|
|
|
if (NULL != authenticator)
|
|
|
|
{
|
|
|
|
authenticator->type = strdup(type);
|
|
|
|
authenticator->authenticate = authenticate;
|
|
|
|
authenticator->user_data = user_data;
|
|
|
|
authenticator->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return authenticator;
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wf_impl_authenticator_dispose(
|
|
|
|
struct wf_impl_authenticator * authenticator)
|
2019-03-23 21:53:14 +00:00
|
|
|
{
|
|
|
|
free(authenticator->type);
|
|
|
|
free(authenticator);
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
bool wf_impl_authenticator_autenticate(
|
|
|
|
struct wf_impl_authenticator * authenticator,
|
|
|
|
struct wf_credentials * credentials)
|
2019-03-23 21:53:14 +00:00
|
|
|
{
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
if (0 == strcmp(authenticator->type, credentials->type))
|
|
|
|
{
|
|
|
|
result = authenticator->authenticate(credentials, authenticator->user_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|