summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
Diffstat (limited to 'database')
-rw-r--r--database/eurephiadb-driver_template.c40
-rw-r--r--database/sqlite/eurephiadb-sqlite.c18
-rw-r--r--database/sqlite/sql-schema.sql3
3 files changed, 45 insertions, 16 deletions
diff --git a/database/eurephiadb-driver_template.c b/database/eurephiadb-driver_template.c
index 5bcea91..005afc7 100644
--- a/database/eurephiadb-driver_template.c
+++ b/database/eurephiadb-driver_template.c
@@ -105,13 +105,26 @@ int eDBconnect(eurephiaCTX *ctx, const int argc, const char **argv)
eDBconn *dbc = NULL;
int rc;
- DEBUG(ctx, 10, "Function call: eDBconnect(ctx, %i, '%s')", argc, argv[1]);
-
- if( (argc != 1) || (argv[0] == NULL) || (strlen(argv[0]) < 1) ) {
- eurephia_log(ctx, LOG_PANIC, 0,
- "Wrong parameters to eurephia-auth (eDBconnect). Cannot open database.");
- return 0;
- }
+ /* WORK TO DO -- Parse arguments
+ *
+ * use what ever suitable approach to parse arguments sent to the database module.
+ *
+ * The arguments being recieved is everything after the '--' (double dash)
+ * in the 'plugin' configuration line for OpenVPN.
+ *
+ * plugin eurephia-auth.so "-i my_db_module.so -L 3 -- myparam1 myparam2 myparam3"
+ *
+ * In this example the following parameters will be available here:
+ *
+ * argc = 3
+ * argv[0] = myparam1
+ * argv[1] = myparam2
+ * argv[2] = myparam3
+ *
+ * You are free to use whatever parameter syntax you would like to use.
+ */
+
+ DEBUG(ctx, 10, "Function call: eDBconnect(ctx, %i, '...')", argc, dbame);
// Connect to the database
dbc = (eDBconn *) malloc(sizeof(eDBconn)+2);
@@ -641,8 +654,12 @@ char *eDBget_sessionkey_seed(eurephiaCTX *ctx, const char *sessionseed) {
}
/* WORK TO DO -- DO SQL:
- "SELECT sessionkey FROM openvpn_sessionkeys WHERE sessionseed = '%q'",
- sessionseed
+ "SELECT sessionkey "
+ " FROM openvpn_sessionkeys "
+ " JOIN openvpn_lastlog USING (sessionkey)"
+ " WHERE sessionstatus IN (1,2)"
+ " AND sessionseed = '%q'",
+ sessionseed
*/
if( /* IF SQL QUERY FAILED */ ) {
eurephia_log(ctx, LOG_CRITICAL, 0,"Could not retrieve sessionkey from openvpn_sessionkeys (%s)",
@@ -665,7 +682,10 @@ char *eDBget_sessionkey_macaddr(eurephiaCTX *ctx, const char *macaddr) {
/* WORK TO DO -- DO SQL:
"SELECT sessionkey "
" FROM openvpn_sessions "
- " WHERE datakey = 'macaddr' AND dataval = '%q'",
+ " JOIN openvpn_lastlog USING (sessionkey)"
+ " WHERE sessionstatus = 3 "
+ " AND datakey = 'macaddr' "
+ " AND dataval = '%q'",
macaddr
*/
if( /* IF SQL QUERY FAILED */ ) {
diff --git a/database/sqlite/eurephiadb-sqlite.c b/database/sqlite/eurephiadb-sqlite.c
index 04ee569..4fc7c5d 100644
--- a/database/sqlite/eurephiadb-sqlite.c
+++ b/database/sqlite/eurephiadb-sqlite.c
@@ -106,7 +106,7 @@ int eDBconnect(eurephiaCTX *ctx, const int argc, const char **argv)
mwStatistics(3);
#endif
- DEBUG(ctx, 10, "Function call: eDBconnect(ctx, %i, '%s')", argc, argv[1]);
+ DEBUG(ctx, 10, "Function call: eDBconnect(ctx, %i, '%s')", argc, argv[0]);
if( (argc != 1) || (argv[0] == NULL) || (strlen(argv[0]) < 1) ) {
eurephia_log(ctx, LOG_PANIC, 0, "Wrong parameters to dblink-sqlite. Cannot open database.");
@@ -116,11 +116,11 @@ int eDBconnect(eurephiaCTX *ctx, const int argc, const char **argv)
// Connect to the database
dbc = (eDBconn *) malloc(sizeof(eDBconn)+2);
memset(dbc, 1, sizeof(eDBconn)+2);
- dbc->dbname = strdup(argv[1]);
+ dbc->dbname = strdup(argv[0]);
eurephia_log(ctx, LOG_INFO, 1, "Opening database '%s'", dbc->dbname);
- rc = sqlite3_open(argv[1], (void *) &dbc->dbhandle);
+ rc = sqlite3_open(argv[0], (void *) &dbc->dbhandle);
if( rc ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not open database '%s'", dbc->dbname);
free_nullsafe(dbc->dbname);
@@ -615,7 +615,12 @@ char *eDBget_sessionkey_seed(eurephiaCTX *ctx, const char *sessionseed) {
"eDBget_sessionkey: No session seed given - cannot locate sessionkey");
return NULL;
}
- res = sqlite_query(ctx, "SELECT sessionkey FROM openvpn_sessionkeys WHERE sessionseed = '%q'",
+ res = sqlite_query(ctx,
+ "SELECT sessionkey "
+ " FROM openvpn_sessionkeys "
+ " JOIN openvpn_lastlog USING (sessionkey)"
+ " WHERE sessionstatus IN (1,2)"
+ " AND sessionseed = '%q'",
sessionseed);
if( res == NULL ) {
eurephia_log(ctx, LOG_CRITICAL, 0,"Could not retrieve sessionkey from openvpn_sessionkeys (%s)",
@@ -639,7 +644,10 @@ char *eDBget_sessionkey_macaddr(eurephiaCTX *ctx, const char *macaddr) {
res = sqlite_query(ctx,
"SELECT sessionkey "
" FROM openvpn_sessions "
- " WHERE datakey = 'macaddr' AND dataval = '%q'", macaddr);
+ " JOIN openvpn_lastlog USING (sessionkey)"
+ " WHERE sessionstatus = 3 "
+ " AND datakey = 'macaddr' "
+ " AND dataval = '%q'", macaddr);
if( res == NULL ) {
eurephia_log(ctx, LOG_CRITICAL, 0,
"Could not remove session from database (MAC addr: %s)", macaddr);
diff --git a/database/sqlite/sql-schema.sql b/database/sqlite/sql-schema.sql
index b677554..81d7ea4 100644
--- a/database/sqlite/sql-schema.sql
+++ b/database/sqlite/sql-schema.sql
@@ -103,8 +103,9 @@ CREATE UNIQUE INDEX openvpn_attempts_remoteip ON openvpn_attempts(remoteip);
CREATE TABLE openvpn_sessionkeys (
sessionseed varchar(128) NOT NULL,
sessionkey varchar(128) NOT NULL,
- PRIMARY KEY(sessionseed)
+ PRIMARY KEY(sessionkey)
);
+CREATE INDEX opevpn_sessionkeys_seed ON openvpn_sessionkeys(sessionseed);
CREATE TABLE openvpn_config (
datakey varchar(64) NOT NULL,