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
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
4 changed files with 173 additions and 4 deletions
@ -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: |
|||
@ -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, ¶ms); |
|||
break; |
|||
|
|||
case AUTH_STORAGE: |
|||
this->auth[module] = newParams(AuthStorage, ¶ms); |
|||
break; |
|||
} |
|||
|
|||
va_end(params); |
|||
|
|||
if (NULL == this->auth[module]) { |
|||
return FALSE; |
|||
} |
|||
|
|||
return module; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue