summaryrefslogtreecommitdiffstats
path: root/database/sqlite/edb-sqlite.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2012-09-13 17:56:45 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2012-09-13 17:56:45 +0200
commit2ebf7e3a91fee5663ead92474ec6fca7908cb78d (patch)
tree49d58c7de130ac46e349883e9bda2a3cadbd5863 /database/sqlite/edb-sqlite.c
parent4ed91be8670a0d0760bbaf23f7b5a6a16eac30ad (diff)
downloadeurephia-2ebf7e3a91fee5663ead92474ec6fca7908cb78d.tar.gz
eurephia-2ebf7e3a91fee5663ead92474ec6fca7908cb78d.tar.xz
eurephia-2ebf7e3a91fee5663ead92474ec6fca7908cb78d.zip
sqlite3: Implement eDBregister_vpnclientaddr()
This commit implements the eDBregister_vpnclientaddr() needed by the newer eurephia-auth plug-in. This is needed to improve the tun support in eurephia. In addition, this also updates the SQL schema to include IPv4 and in the future IPv6 addresses in the lastlog and VPN address history (openvpn_vpnaddr_history). The old openvpn_macaddr_history table is deprecated. Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Diffstat (limited to 'database/sqlite/edb-sqlite.c')
-rw-r--r--database/sqlite/edb-sqlite.c67
1 files changed, 63 insertions, 4 deletions
diff --git a/database/sqlite/edb-sqlite.c b/database/sqlite/edb-sqlite.c
index d9d4af6..4c15a5a 100644
--- a/database/sqlite/edb-sqlite.c
+++ b/database/sqlite/edb-sqlite.c
@@ -1,7 +1,7 @@
/* edb-sqlite.c -- Main driver for eurephia authentication plugin for OpenVPN
* This is the SQLite database driver
*
- * GPLv2 only - Copyright (C) 2008 - 2011
+ * GPLv2 only - Copyright (C) 2008 - 2012
* David Sommerseth <dazo@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or
@@ -37,9 +37,9 @@
#include <unistd.h>
#include <assert.h>
-#define DRIVERVERSION "1.2" /**< Defines the software version of this driver */
+#define DRIVERVERSION "1.3" /**< Defines the software version of this driver */
#ifndef DRIVERAPIVERSION
-# define DRIVERAPIVERSION 2 /**< Sets the API version level of this driver */
+# define DRIVERAPIVERSION 3 /**< Sets the API version level of this driver */
#endif
#include <sqlite3.h>
@@ -86,7 +86,7 @@ static const eDBattempt_types_t eDBattempt_types[] = {
* @copydoc eDB_DriverVersion()
*/
const char *eDB_DriverVersion(void) {
- return "edb-sqlite (v"DRIVERVERSION") David Sommerseth 2008-2011 (C) GPLv2";
+ return "edb-sqlite (v"DRIVERVERSION") David Sommerseth 2008-2012 (C) GPLv2";
}
@@ -674,6 +674,65 @@ int eDBregister_vpnmacaddr(eurephiaCTX *ctx, eurephiaSESSION *session, const cha
/**
+ * @copydoc eDBregister_vpnclientaddr()
+ */
+int eDBregister_vpnclientaddr(eurephiaCTX *ctx, eurephiaSESSION *session, const char *macaddr,
+ const char *vpnip4addr, const char *vpnip6addr)
+{
+ dbresult *res = NULL;
+ int ret = 0;
+
+ DEBUG(ctx, 20, "Function call: eDBregister_vpnclientaddr(ctx, '%s', '%s', '%s', '%s')",
+ session->sessionkey, macaddr, vpnip4addr, vpnip6addr);
+
+ if( (macaddr == NULL) && (strlen_nullsafe(macaddr) > 18) ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "Invalid MAC address");
+ return 0;
+ }
+
+ // Register client addresses into history table
+ res = sqlite_query(ctx,
+ "INSERT INTO openvpn_vpnaddr_history (sessionkey, macaddr, ip4addr, ip6addr) "
+ "VALUES ('%q','%q','%q','%q')",
+ session->sessionkey,
+ (ctx->tuntype == tuntype_TAP ? macaddr : ""),
+ (vpnip4addr ? vpnip4addr : ""), (vpnip6addr ? vpnip6addr : ""));
+ if( sqlite_query_status(res) != dbSUCCESS ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "Failed to log new VPN client addresses for session");
+ sqlite_log_error(ctx, res);
+ ret = 0;
+ goto exit;
+ }
+ sqlite_free_results(res);
+
+ // Update lastlog to reflect last used MAC address for the session
+ res = sqlite_query(ctx,
+ "UPDATE openvpn_lastlog SET sessionstatus = 2, macaddr = '%q', vpnipaddr = '%q', vpnipv6addr = '%q' "
+ " WHERE sessionkey = '%q' AND sessionstatus = 1",
+ (macaddr ? macaddr : ""), (vpnip4addr ? vpnip4addr : ""), (vpnip6addr ? vpnip6addr : ""),
+ session->sessionkey);
+ if( sqlite_query_status(res) == dbSUCCESS ) {
+ // TAP mode: Save the MAC address in the session values register - needed for the destroy session
+ if( (ctx->tuntype == tuntype_TAP) && eDBset_session_value(ctx, session, "macaddr", macaddr) == 0 ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "Could not save MAC address into session variables");
+ ret = 0;
+ } else {
+ ret = 1;
+ }
+ } else {
+ eurephia_log(ctx, LOG_FATAL, 0, "Could not update lastlog with new VPN client addresses for session");
+ sqlite_log_error(ctx, res);
+ ret = 0;
+ }
+
+ exit:
+ sqlite_free_results(res);
+ return ret;
+}
+
+
+
+/**
* @copydoc eDBregister_logout()
*/
int eDBregister_logout(eurephiaCTX *ctx, eurephiaSESSION *skey,