Browse Source

created an authentication container. This could initialize the needed authentications and then be injected as a single object into the application class

v0.1.8
Georg Hopp 12 years ago
parent
commit
a8e31f8995
  1. 29
      include/auth/auth.h
  2. 2
      src/auth/Makefile.am
  3. 84
      src/auth/auth.c
  4. 62
      src/auth/create.c

29
include/auth/auth.h

@ -1,5 +1,20 @@
/**
* \file
* Container for authentication modules.
*
* This is a single point of authentication no matter how much
* authentication modules are in place. Thus it prevents adding
* more and more authentication modules to the application.
* This is an auth module itself but this one returns 0 if
* the authentication has failed otherwise the id of the
* successfull auth module. Thus we can identify by what method
* the user has been authenticated.
*
* This can't authenticate by its own. It has to be initialized
* with other auth modules by calling authCreate at least once.
*
* origin intend ... never implemented (but maybe a good idea)
*
* Authenticatio module factory
*
* A factory to get a specific authentication module.
@ -28,17 +43,23 @@
#define __AUTH_AUTH_H__
#include "class.h"
#include "auth/ldap.h"
#include "uuid.h"
#include "auth.h"
#include "auth/credential.h"
typedef enum e_AuthModule {
AUTH_LDAP = 0
AUTH_LDAP = 1,
AUTH_STORAGE = 2
} AuthModule;
#define MAX_AUTH AUTH_STORAGE
CLASS(Auth) {
void * auth[MAX_AUTH + 1];
};
void * authCreateById(Auth, int);
AuthLdap authCreateLdap(Auth);
int authCreate(Auth, AuthModule, ...);
#endif // __AUTH_AUTH_H__

2
src/auth/Makefile.am

@ -3,6 +3,8 @@ AUTOMAKE_OPTIONS = subdir-objects
AUTH = interface/auth.c \
credential.c \
auth.c \
create.c \
ldap.c \
storage/storage.c \
storage/hash_pw.c

84
src/auth/auth.c

@ -0,0 +1,84 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ldap.h>
#include "class.h"
#include "uuid.h"
#include "utils/memory.h"
#include "commons.h"
#include "auth.h"
#include "auth/credential.h"
#include "auth/interface/auth.h"
static
int
authCtor(void * _this, va_list * params)
{
Auth this = _this;
int i;
for (i=0; i<=MAX_AUTH; i++) {
this->auth[i] = NULL;
}
return 0;
}
static
void
authDtor(void * _this)
{
Auth this = _this;
int i;
for (i=1; i<=MAX_AUTH; i++) {
delete(this->auth[i]);
}
}
static
int
authAuthenticate(void * _this, Credential cred, Uuid user_index)
{
Auth this = _this;
int i;
for (i=1; i<=MAX_AUTH; i++) {
if (authenticate(this->auth[i], cred, user_index)) {
return i;
}
}
return FALSE;
}
INIT_IFACE(Class, authCtor, authDtor, NULL);
INIT_IFACE(Auth, authAuthenticate);
CREATE_CLASS(Auth, NULL, IFACE(Class), IFACE(Auth));
// vim: set ts=4 sw=4:

62
src/auth/create.c

@ -0,0 +1,62 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <sys/types.h>
#include "class.h"
#include "auth.h"
#include "auth/ldap.h"
#include "auth/storage.h"
#include "commons.h"
int
authCreate(Auth this, AuthModule module, ...)
{
va_list params;
if (NULL != this->auth[module]) {
delete(this->auth[module]);
}
va_start(params, module);
switch (module) {
case AUTH_LDAP:
this->auth[module] = newParams(AuthLdap, &params);
break;
case AUTH_STORAGE:
this->auth[module] = newParams(AuthStorage, &params);
break;
}
va_end(params);
if (NULL == this->auth[module]) {
return FALSE;
}
return module;
}
// vim: set ts=4 sw=4:
Loading…
Cancel
Save