diff options
Diffstat (limited to 'plugin/eurephiadb_session.c')
-rw-r--r-- | plugin/eurephiadb_session.c | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/plugin/eurephiadb_session.c b/plugin/eurephiadb_session.c index f8fb97a..f6c7faa 100644 --- a/plugin/eurephiadb_session.c +++ b/plugin/eurephiadb_session.c @@ -242,37 +242,34 @@ eurephiaSESSION *eDBopen_session_seed(eurephiaCTX *ctx, const char *digest, /** - * Open an existing eurephia session based on a MAC address. This function is only used - * when there is not enough information to generate a session seed and when the MAC address - * is available. Usually this only happens when the client has disconnected and the session - * is about to be marked as closed. + * Load a session based on a known session key * - * @param ctx eurephiaCTX - * @param macaddr MAC address of the client + * @param ctx eurephiaCTX + * @param sesskey A string containing the session key + * @param sesstype What kind of type the session data should be opend as (sessionType) * - * @return returns a eurephiaSESSION pointer on success, otherwise NULL. + * @return Returns a pointer to the corresponding eurephiaSESSION struct on success, otherwise NULL. */ -eurephiaSESSION *eDBopen_session_macaddr(eurephiaCTX *ctx, const char *macaddr) { + +eurephiaSESSION *eDBsession_load(eurephiaCTX *ctx, const char *sesskey, sessionType sesstype) { eurephiaSESSION *new_session = NULL; - DEBUG(ctx, 12, "Function call: eDBopen_session_mac(ctx, '%s')", macaddr); + DEBUG(ctx, 12, "Function call: eDBsession_load(ctx, '%s')", sesskey); new_session = (eurephiaSESSION *) malloc_nullsafe(ctx, sizeof(eurephiaSESSION) + 2); if( new_session == NULL ) { return NULL; } - - new_session->type = stSESSION; // When we have macaddr - this is a stSESSION type of session + new_session->type = sesstype; // Get the sessionkey from the database - new_session->sessionkey = eDBget_sessionkey_macaddr(ctx, macaddr); + new_session->sessionkey = strdup_nullsafe(sesskey); if( new_session->sessionkey == NULL ) { - eurephia_log(ctx, LOG_CRITICAL, 0, "Could not find an active session for MAC address '%s'", - macaddr); + eurephia_log(ctx, LOG_CRITICAL, 0, "Failed to set the session key to '%s'", + sesskey); free_nullsafe(ctx, new_session); return NULL; } - DEBUG(ctx, 13, "Session seed found, using sessionkey '%s'", new_session->sessionkey); // Load session values from the database new_session->sessvals = eDBload_sessiondata(ctx, new_session->sessionkey); @@ -280,3 +277,33 @@ eurephiaSESSION *eDBopen_session_macaddr(eurephiaCTX *ctx, const char *macaddr) // Return struct which contains the current session return new_session; } + + +/** + * Open an existing eurephia session based on a MAC address. This function is only used + * when there is not enough information to generate a session seed and when the MAC address + * is available. Usually this only happens when the client has disconnected and the session + * is about to be marked as closed. + * + * @param ctx eurephiaCTX + * @param macaddr MAC address of the client + * + * @return returns a eurephiaSESSION pointer on success, otherwise NULL. + */ +eurephiaSESSION *eDBopen_session_macaddr(eurephiaCTX *ctx, const char *macaddr) { + char *sesskey = NULL; + + DEBUG(ctx, 12, "Function call: eDBopen_session_mac(ctx, '%s')", macaddr); + + // Get the sessionkey from the database + sesskey = eDBget_sessionkey_macaddr(ctx, macaddr); + if( sesskey == NULL ) { + eurephia_log(ctx, LOG_CRITICAL, 0, "Could not find an active session for MAC address '%s'", + macaddr); + return NULL; + } + DEBUG(ctx, 13, "Session seed found, using sessionkey '%s'", sesskey); + + // Open and load the session from the database + return eDBsession_load(ctx, sesskey, stSESSION); +} |