diff options
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; } |
