summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
Diffstat (limited to 'database')
-rw-r--r--database/eurephiadb.c125
-rw-r--r--database/eurephiadb.h32
-rw-r--r--database/eurephiadb_driver.h87
-rw-r--r--database/sqlite/CMakeLists.txt14
4 files changed, 252 insertions, 6 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;
+}
+
diff --git a/database/eurephiadb.h b/database/eurephiadb.h
new file mode 100644
index 0000000..2e0ab29
--- /dev/null
+++ b/database/eurephiadb.h
@@ -0,0 +1,32 @@
+/* eurephiadb.h -- Database driver setup
+ *
+ * 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 <eurephia_struct.h>
+#include <eurephiadb_driver.h>
+#include <eurephiadb_session.h>
+#include <eurephia_log.h>
+
+#ifndef EUREPHIADB_H_
+# define EUREPHIADB_H_
+
+int eDBlink_init(eurephiaCTX *, const char *);
+int eDBlink_close(eurephiaCTX *);
+
+#endif
diff --git a/database/eurephiadb_driver.h b/database/eurephiadb_driver.h
new file mode 100644
index 0000000..6f78ce7
--- /dev/null
+++ b/database/eurephiadb_driver.h
@@ -0,0 +1,87 @@
+/* eurephiadb_driver.h -- API provided by 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 <eurephia_struct.h>
+
+#ifndef EUREPHIADB_DRIVER_H_
+#define EUREPHIADB_DRIVER_H_
+
+#define attempt_IPADDR 1
+#define attempt_CERTIFICATE 2
+#define attempt_USERNAME 3
+
+#define ATTEMPT_RESET 0x0A
+#define ATTEMPT_REGISTER 0x0B
+
+#ifndef EUREPHIADB_DRIVER
+
+/* Functions needed by all drivers */
+const char *(*eDB_DriverVersion) (void);
+int (*eDB_DriverAPIVersion) (void);
+
+
+/*
+ * functions which needs to exists in the eurephiaDB (eDB) module - API Version 1
+ */
+int (*eDBconnect) (eurephiaCTX *ctx, const int argc, const char **argv);
+
+void (*eDBdisconnect) (eurephiaCTX *ctx);
+
+int (*eDBauth_TLS) (eurephiaCTX *ctx, const char *org, const char *cname, const char *email,
+ const char *digest, const char *depth);
+
+int (*eDBauth_user) (eurephiaCTX *ctx, const int certid, const char *username, const char *passwd);
+
+int (*eDBget_uid) (eurephiaCTX *ctx, const int certid, const char *username);
+
+int (*eDBblacklist_check) (eurephiaCTX *ctx, const int type, const char *val);
+
+void (*eDBregister_attempt) (eurephiaCTX *ctx, int type, int mode, const char *value);
+
+
+int (*eDBregister_login) (eurephiaCTX *ctx, eurephiaSESSION *skey, const int certid, const int uid,
+ const char *proto, const char *remipaddr, const char *remport,
+ const char *vpnipaddr, const char *vpnipmask);
+
+int (*eDBregister_vpnmacaddr) (eurephiaCTX *ctx, eurephiaSESSION *skey, const char *macaddr);
+
+int (*eDBregister_logout) (eurephiaCTX *ctx, eurephiaSESSION *skey,
+ const char *bytes_sent, const char *bytes_received, const char *duration);
+
+/* firewall functions */
+char *(*eDBget_firewall_profile) (eurephiaCTX *ctx, eurephiaSESSION *session);
+
+
+/* The following functions is also declared in eurephia_session_values.c - for local internal usage. */
+char *(*eDBget_sessionkey_seed) (eurephiaCTX *ctx, const char *sessionseed);
+char *(*eDBget_sessionkey_macaddr) (eurephiaCTX *ctx, const char *macaddr);
+int (*eDBcheck_sessionkey_uniqueness) (eurephiaCTX *ctx, const char *seskey);
+
+int (*eDBregister_sessionkey) (eurephiaCTX *ctx, const char *seed, const char *seskey);
+
+eurephiaVALUES *(*eDBload_sessiondata) (eurephiaCTX *ctx, const char *sesskey);
+
+int (*eDBdestroy_session) (eurephiaCTX *ctx, eurephiaSESSION *session);
+
+int (*eDBstore_session_value) (eurephiaCTX *ctx, eurephiaSESSION *skey, int mode,
+ const char *key, const char *val);
+
+#endif /* !EUREPHIADB_DRIVER */
+
+#endif /* !EUREPHIADB_DRIVER_H_ */
diff --git a/database/sqlite/CMakeLists.txt b/database/sqlite/CMakeLists.txt
index db23189..6bdd5e0 100644
--- a/database/sqlite/CMakeLists.txt
+++ b/database/sqlite/CMakeLists.txt
@@ -5,11 +5,11 @@ SET(eurephiadb_sqlite_SRC
eurephiadb-sqlite.c
)
SET(COMMON
- ../../eurephia_log.c
- ../../eurephiadb_session.c
- ../..//eurephia_values.c
- ../../passwd.c
- ../../sha512.c
+ ../../common/eurephia_log.c
+ ../../plugin/eurephiadb_session.c
+ ../../common/eurephia_values.c
+ ../../common/passwd.c
+ ../../common/sha512.c
)
INCLUDE(CheckIncludeFile)
@@ -26,12 +26,14 @@ IF(NOT SQLITE3BIN)
MESSAGE(STATUS "sqlite3 binary was not found. You will need to generate the database file on your own")
ENDIF(NOT SQLITE3BIN)
-INCLUDE_DIRECTORIES(BEFORE ../..)
+INCLUDE_DIRECTORIES(BEFORE ../../common/ ../../plugin/ ../)
ADD_LIBRARY(eurephiadb-sqlite SHARED ${eurephiadb_sqlite_SRC} ${COMMON})
IF(SQLITE3BIN)
ADD_CUSTOM_COMMAND(TARGET eurephiadb-sqlite POST_BUILD COMMAND ${SQLITE3BIN} eurephiadb < sql-schema.sql COMMENT "Creating template database: eurephiadb")
ENDIF(SQLITE3BIN)
+
+
TARGET_LINK_LIBRARIES(eurephiadb-sqlite sqlite3)
SET_TARGET_PROPERTIES(eurephiadb-sqlite PROPERTIES OUTPUT_NAME eurephiadb-sqlite PREFIX "")
SET_SOURCE_FILES_PROPERTIES(${common_files_SRC} PROPERTIES GENERATED true)