diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2012-12-25 22:08:53 +0100 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2012-12-26 01:32:20 +0100 |
| commit | 40e66aed101e5a448fe012f24abe33d15a68cee9 (patch) | |
| tree | 0ba4005d5d55740015c079e03d03fd033708d7e2 /database/sqlite/edb-sqlite.c | |
| parent | 242ba8893bef1fe05d71959afc5273af021b8537 (diff) | |
| download | eurephia-40e66aed101e5a448fe012f24abe33d15a68cee9.tar.gz eurephia-40e66aed101e5a448fe012f24abe33d15a68cee9.tar.xz eurephia-40e66aed101e5a448fe012f24abe33d15a68cee9.zip | |
Added a new eDBregister_login2() to replace eDBregister_login() database function
This will save the access profile in the lastlog table. However, it will not save
the VPN IP address and netmask any more. This should be saved in the vpnaddr_history
table, using the eDBregister_vpnclientaddr() function.
eDBregister_login() is now just a wrapper around the eDBregister_login2(), ignoring
the access profile id and VPN addresses. This exists purely as a compatibility layer
if the updated driver is used against an older eurephia-auth.so plug-in.
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Diffstat (limited to 'database/sqlite/edb-sqlite.c')
| -rw-r--r-- | database/sqlite/edb-sqlite.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/database/sqlite/edb-sqlite.c b/database/sqlite/edb-sqlite.c index bd0d905..85b27d9 100644 --- a/database/sqlite/edb-sqlite.c +++ b/database/sqlite/edb-sqlite.c @@ -37,9 +37,9 @@ #include <unistd.h> #include <assert.h> -#define DRIVERVERSION "1.3" /**< Defines the software version of this driver */ +#define DRIVERVERSION "1.4" /**< Defines the software version of this driver */ #ifndef DRIVERAPIVERSION -# define DRIVERAPIVERSION 3 /**< Sets the API version level of this driver */ +# define DRIVERAPIVERSION 4 /**< Sets the API version level of this driver */ #endif #include <sqlite3.h> @@ -599,19 +599,18 @@ void eDBregister_attempt(eurephiaCTX *ctx, int type, int mode, const char *value free_nullsafe(ctx, blid); } - /** - * @copydoc eDBregister_login() + * @copydoc eDBregister_login2() */ -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_login2(eurephiaCTX *ctx, eurephiaSESSION *skey, + const int certid, const int uid, const int accessprofile, + const char *proto, const char *remipaddr, const char *remport) { dbresult *res = NULL; int ret = 0; - DEBUG(ctx, 20, "Function call: eDBregister_login(ctx, '%s', %i, %i, '%s','%s','%s','%s','%s')", - skey->sessionkey, certid, uid, proto, remipaddr, remport, vpnipaddr, vpnipmask); + DEBUG(ctx, 20, "Function call: eDBregister_login2(ctx, '%s', %i, %i, '%s','%s','%s')", + skey->sessionkey, certid, uid, proto, remipaddr, remport); if( skey->sessionstatus != SESSION_NEW ) { eurephia_log(ctx, LOG_ERROR, 5, "Not a new session, will not register it again"); @@ -619,16 +618,17 @@ int eDBregister_login(eurephiaCTX *ctx, eurephiaSESSION *skey, const int certid, } res = sqlite_query(ctx, - "INSERT INTO openvpn_lastlog (uid, certid, " + "INSERT INTO openvpn_lastlog (uid, certid, accessprofile," " protocol, remotehost, remoteport," - " vpnipaddr, vpnipmask," " sessionstatus, sessionkey, login) " - "VALUES (%i, %i, '%q','%q','%q','%q','%q', 1,'%q', CURRENT_TIMESTAMP)", - uid, certid, proto, remipaddr, remport, vpnipaddr, vpnipmask, skey->sessionkey); + "VALUES (%i,%i,%i,'%q','%q','%q',1,'%q',CURRENT_TIMESTAMP)", + uid, certid, accessprofile, + proto, remipaddr, remport, + skey->sessionkey); if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not insert new session into openvpn_lastlog"); sqlite_log_error(ctx, res); - ret = 0; + ret = 1; } else { skey->sessionstatus = SESSION_REGISTERED; ret = 1; @@ -639,6 +639,22 @@ int eDBregister_login(eurephiaCTX *ctx, eurephiaSESSION *skey, const int certid, } /** + * @copydoc eDBregister_login() + * Just a function wrapper to support both the old and the newer eDBregister_login2() functions. + */ +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) +{ + DEBUG(ctx, 20, "Function call: eDBregister_login(ctx, '%s', %i, %i, '%s','%s','%s','%s','%s')", + skey->sessionkey, certid, uid, proto, remipaddr, remport, vpnipaddr, vpnipmask); + eurephia_log(ctx, LOG_WARNING, 1, + "Using deprecated eDBregister_login() call, please update the eurephia-auth.so plug-in. " + "VPN IP address/mask will not be saved."); + return eDBregister_login2(ctx, skey, certid, uid, -1, proto, remipaddr, remport); +} + +/** * @copydoc eDBregister_vpnmacaddr() */ int eDBregister_vpnmacaddr(eurephiaCTX *ctx, eurephiaSESSION *session, const char *macaddr) @@ -721,11 +737,10 @@ int eDBregister_vpnclientaddr(eurephiaCTX *ctx, eurephiaSESSION *session, const } sqlite_free_results(res); - // Update lastlog to reflect last used MAC address for the session + // Update lastlog with a "connection open" status res = sqlite_query(ctx, - "UPDATE openvpn_lastlog SET sessionstatus = 2, macaddr = '%q', vpnipaddr = '%q', vpnipv6addr = '%q' " + "UPDATE openvpn_lastlog SET sessionstatus = 2 " " 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 @@ -736,7 +751,7 @@ int eDBregister_vpnclientaddr(eurephiaCTX *ctx, eurephiaSESSION *session, const ret = 1; } } else { - eurephia_log(ctx, LOG_FATAL, 0, "Could not update lastlog with new VPN client addresses for session"); + eurephia_log(ctx, LOG_FATAL, 0, "Could not update the session status in the lastlog"); sqlite_log_error(ctx, res); ret = 0; } |
