diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-10-15 00:39:53 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-10-15 00:39:53 +0200 |
commit | 0ea1a3e2e6a10300388e01ac89504abe3624ae56 (patch) | |
tree | fff59c70d4db431c2114e89d0819af8921aff463 /database/eurephiadb.c | |
parent | b65b0802ead5e863ca8cb41fff77528735a1466c (diff) | |
download | eurephia-0ea1a3e2e6a10300388e01ac89504abe3624ae56.tar.gz eurephia-0ea1a3e2e6a10300388e01ac89504abe3624ae56.tar.xz eurephia-0ea1a3e2e6a10300388e01ac89504abe3624ae56.zip |
Reorganised the source code
Moved all OpenVPN plug-in related things into ./plugins, including firewall
Moved all shared code into ./common and moved the generic part of the
database files into ./database
Updated all CMakeLists.txt files and created a new one for the root directory
Diffstat (limited to 'database/eurephiadb.c')
-rw-r--r-- | database/eurephiadb.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/database/eurephiadb.c b/database/eurephiadb.c new file mode 100644 index 0000000..bd83fa4 --- /dev/null +++ b/database/eurephiadb.c @@ -0,0 +1,125 @@ +/* eurephiadb.c -- Loads and initialises the database driver + * + * GPLv2 - Copyright (C) 2008 David Sommerseth <dazo@users.sourceforge.net> + * + * 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; version 2 + * of the License. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <stdarg.h> + +#include "eurephia_nullsafe.h" +#include "eurephiadb_driver.h" +#include "eurephia_log.h" +#include "eurephiadb_session.h" +#include "eurephia_getsym.h" + +#ifdef MEMWATCH +#include <memwatch.h> +#endif + + +int eDBlink_close(eurephiaCTX *ctx) +{ + if( ctx == NULL ) { + return 1; + } + + eurephia_log(ctx, LOG_INFO, 3, "Unloading eurephiaDB driver"); + if( ctx->eurephia_driver != NULL ) { + dlclose(ctx->eurephia_driver); + ctx->eurephia_driver = NULL; + } + return 1; +} + + +int eDBlink_init(eurephiaCTX *ctx, const char *dbl) +{ +#ifdef MEMWATCH + mwStatistics(3); +#endif + + if( dbl == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "No eurephia eDBlink driver given. " + "eurephia authentication will not be available"); + return 0; + } + eurephia_log(ctx, LOG_INFO, 2, "Loading eurephiaDB driver: %s", dbl); + + ctx->eurephia_driver = dlopen(dbl, RTLD_NOW); + if( ctx->eurephia_driver == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not open the eurephia eDBlink driver (%s)", dbl); + eurephia_log(ctx, LOG_FATAL, 1, "dlopen error: %s", dlerror()); + return 0; + } + + // Find mandatory functions containing driver information + eDB_DriverVersion = eGetSym(ctx, ctx->eurephia_driver, "eDB_DriverVersion"); + eDB_DriverAPIVersion = eGetSym(ctx, ctx->eurephia_driver, "eDB_DriverAPIVersion"); + + eurephia_log(ctx, LOG_INFO, 1, "Driver loaded: %s (API version %i)", + eDB_DriverVersion(), eDB_DriverAPIVersion()); + + // Configure functions contained in the driver, defined by API version + switch( eDB_DriverAPIVersion() ) { + default: + eurephia_log(ctx, LOG_WARNING, 0, + "eurephiaDB driver API is newer than the running eurephia version. Consider " + "to upgrade eurphia to take advantage of newer features in the eurephiaDB driver.q"); + + case 1: + // Setup eDBlink functions + eDBconnect = eGetSym(ctx, ctx->eurephia_driver, "eDBconnect"); + eDBdisconnect = eGetSym(ctx, ctx->eurephia_driver, "eDBdisconnect"); + + eDBauth_TLS = eGetSym(ctx, ctx->eurephia_driver, "eDBauth_TLS"); + + eDBauth_user = eGetSym(ctx, ctx->eurephia_driver, "eDBauth_user"); + eDBget_uid = eGetSym(ctx, ctx->eurephia_driver, "eDBget_uid"); + + eDBblacklist_check = eGetSym(ctx, ctx->eurephia_driver, "eDBblacklist_check"); + eDBregister_attempt = eGetSym(ctx, ctx->eurephia_driver, "eDBregister_attempt"); + + eDBregister_login = eGetSym(ctx, ctx->eurephia_driver, "eDBregister_login"); + eDBregister_vpnmacaddr = eGetSym(ctx, ctx->eurephia_driver, "eDBregister_vpnmacaddr"); + eDBregister_logout = eGetSym(ctx, ctx->eurephia_driver, "eDBregister_logout"); + + eDBget_firewall_profile = eGetSym(ctx, ctx->eurephia_driver, "eDBget_firewall_profile"); + + eDBget_sessionkey_seed = eGetSym(ctx, ctx->eurephia_driver, "eDBget_sessionkey_seed"); + eDBget_sessionkey_macaddr = eGetSym(ctx, ctx->eurephia_driver, "eDBget_sessionkey_macaddr"); + eDBcheck_sessionkey_uniqueness = eGetSym(ctx, ctx->eurephia_driver, + "eDBcheck_sessionkey_uniqueness"); + + eDBregister_sessionkey = eGetSym(ctx, ctx->eurephia_driver, "eDBregister_sessionkey"); + eDBload_sessiondata = eGetSym(ctx, ctx->eurephia_driver, "eDBload_sessiondata"); + eDBstore_session_value = eGetSym(ctx, ctx->eurephia_driver, "eDBstore_session_value"); + eDBdestroy_session = eGetSym(ctx, ctx->eurephia_driver, "eDBdestroy_session"); + break; + } + if( ctx->fatal_error > 0 ) { + eurephia_log(ctx, LOG_FATAL, 0, "eurephia eDBlink is not correctly initialised. " + "eurephia authentication will not be available"); + eDBlink_close(ctx); + return 0; + } + return 1; +} + |