eurephia database driver for the SQLite3 database. This file is the main API for the driver. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <assert.h>#include <sqlite3.h>#include <eurephiadb_driver.h>#include <eurephia_nullsafe.h>#include <eurephia_log.h>#include <eurephia_values.h>#include <eurephiadb_session_common.h>#include <eurephiadb_session_struct.h>#include <passwd.h>#include "sqlite.h"
Include dependency graph for edb-sqlite.c:Go to the source code of this file.
Data Structures | |
| struct | eDBattempt_types_t |
Defines | |
| #define | DRIVERVERSION "1.1" |
| #define | DRIVERAPIVERSION 2 |
Functions | |
| const char * | eDB_DriverVersion (void) |
| int | eDB_DriverAPIVersion () |
| void | update_attempts (eurephiaCTX *ctx, const char *blid) |
| int | eDBconnect (eurephiaCTX *ctx, const int argc, const char **argv) |
| void | eDBdisconnect (eurephiaCTX *ctx) |
| int | eDBauth_TLS (eurephiaCTX *ctx, const char *org, const char *cname, const char *email, const char *digest, const unsigned int depth) |
| int | eDBauth_user (eurephiaCTX *ctx, const int certid, const char *username, const char *passwd) |
| int | eDBget_uid (eurephiaCTX *ctx, const int certid, const char *username) |
| int | eDBblacklist_check (eurephiaCTX *ctx, const int type, const char *val) |
| void | eDBregister_attempt (eurephiaCTX *ctx, int type, int mode, const char *value) |
| 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_vpnmacaddr (eurephiaCTX *ctx, eurephiaSESSION *session, const char *macaddr) |
| int | eDBregister_logout (eurephiaCTX *ctx, eurephiaSESSION *skey, const char *bytes_sent, const char *bytes_received, const char *duration) |
| char * | eDBget_sessionkey_seed (eurephiaCTX *ctx, sessionType type, const char *sessionseed) |
| char * | eDBget_sessionkey_macaddr (eurephiaCTX *ctx, const char *macaddr) |
| int | eDBcheck_sessionkey_uniqueness (eurephiaCTX *ctx, const char *seskey) |
| int | eDBregister_sessionkey (eurephiaCTX *ctx, const char *seed, const char *seskey) |
| int | eDBremove_sessionkey (eurephiaCTX *ctx, const char *seskey) |
| eurephiaVALUES * | eDBload_sessiondata (eurephiaCTX *ctx, const char *sesskey) |
| int | eDBstore_session_value (eurephiaCTX *ctx, eurephiaSESSION *session, int mode, const char *key, const char *val) |
| int | eDBdestroy_session (eurephiaCTX *ctx, eurephiaSESSION *session) |
| char * | eDBget_firewall_profile (eurephiaCTX *ctx, eurephiaSESSION *session) |
| eurephiaVALUES * | eDBget_blacklisted_ip (eurephiaCTX *ctx) |
Variables | |
| static const eDBattempt_types_t | eDBattempt_types [] |
eurephia database driver for the SQLite3 database. This file is the main API for the driver.
Definition in file edb-sqlite.c.
| #define DRIVERAPIVERSION 2 |
Sets the API version level of this driver
Definition at line 42 of file edb-sqlite.c.
| #define DRIVERVERSION "1.1" |
Defines the software version of this driver
Definition at line 40 of file edb-sqlite.c.
| int eDB_DriverAPIVersion | ( | ) |
Mandatory function. Retrieves driver API level
< Sets the API version level of this driver
Definition at line 96 of file edb-sqlite.c.
| const char* eDB_DriverVersion | ( | void | ) |
Mandatory function. Retrieves driver version information
< Defines the software version of this driver
Definition at line 88 of file edb-sqlite.c.
| int eDBauth_TLS | ( | eurephiaCTX * | ctx, | |
| const char * | org, | |||
| const char * | cname, | |||
| const char * | email, | |||
| const char * | digest, | |||
| const unsigned int | depth | |||
| ) |
Authenticates a certificate against the database.
| ctx | eurephiaCTX | |
| org | X.509 organisation field (O) | |
| cname | X.509 common name field (CN) | |
| X.509 email field (emailAddress) | ||
| digest | Certificate SHA1 fingerprint (digest) | |
| depth | Certificate depth. 0 is for user certificates. 1 and higher is for CA certificates, according to the certificates position in the certificate chain. |
< Messages intended when debugging. Only for log level > 10
< Input data or processing revealed unexpected data. Log level never > 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Messages intended when debugging. Only for log level > 10
Definition at line 221 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBauth_user | ( | eurephiaCTX * | ctx, | |
| const int | certid, | |||
| const char * | username, | |||
| const char * | passwd | |||
| ) |
Authenticates a client against the database, with users certificate ID, username and password.
| ctx | eurephiaCTX | |
| certid | certificate ID to the user being authenticated | |
| username | username to be authenticated | |
| passwd | password provided by the user |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Input data or processing revealed unexpected data. Log level never > 2
< Input data or processing revealed unexpected data. Log level never > 2
< Input data or processing revealed unexpected data. Log level never > 2
< Input data or processing revealed unexpected data. Log level never > 2
< Input data or processing revealed unexpected data. Log level never > 2
< Input data or processing revealed unexpected data. Log level never > 2
< Alias for LOG_ERROR, in case it is not defined
< API errors but not sever, program can continue to run
< Input data or processing revealed unexpected data. Log level never > 2
< Messages intended when debugging. Only for log level > 10
Definition at line 268 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBblacklist_check | ( | eurephiaCTX * | ctx, | |
| const int | type, | |||
| const char * | val | |||
| ) |
Checks if a user account (attempt_USERNAME), certificate (attempt_CERTIFICATE) or IP address (attempt_IPADDR) is blacklisted.
| ctx | eurephiaCTX | |
| type | Must be one of the constants: attempt_USERNAME, attempt_CERTIFICATE or attempt_IPADDR | |
| val | Value to be checked against the blacklist. |
< Messages intended when debugging. Only for log level > 10
< Input data or processing revealed unexpected data. Log level never > 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Input data or processing revealed unexpected data. Log level never > 2
< Alias for LOG_CRITICAL
< Operation failed and might have been aborted. Log level always 0
< Alias for LOG_CRITICAL
< Operation failed and might have been aborted. Log level always 0
< Messages intended when debugging. Only for log level > 10
Definition at line 401 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBcheck_sessionkey_uniqueness | ( | eurephiaCTX * | ctx, | |
| const char * | seskey | |||
| ) |
Check if a session key is unique. In other words, it will check the given session key against the database to see if it is found there or not. If not, it is unique.
| ctx | eurephiaCTX | |
| seskey | String containing the session key |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< The context should not have any privileges at all
< The context is used via the eurephiadm console utility
< The context is used via a web based utility
< The context is used in a openvpn plug-in setting
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 768 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBconnect | ( | eurephiaCTX * | ctx, | |
| const int | argc, | |||
| const char ** | argv | |||
| ) |
Connect to a database
| ctx | eurephiaCTX - context to which the database connection will be established against. | |
| argc | number of arguments sent in the argument vector | |
| argv | char** argument vector with driver specific argument for establishing a database connection |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_PANIC
< Action failed an program could not continue to run. Log level always 0
< Informational messages. Log level should be < 5
< Alias for LOG_PANIC
< Action failed an program could not continue to run. Log level always 0
< Informational messages. Log level should be < 5
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 136 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBdestroy_session | ( | eurephiaCTX * | ctx, | |
| eurephiaSESSION * | session | |||
| ) |
Destroys a session. It will remove all stored session variables and mark the session as closed in the lastlog. It will also remove the session seed/session key reference.
| ctx | eurephiaCTX | |
| session | eurephiaSESSION pointer to session to be destroyed |
< Messages intended when debugging. Only for log level > 10
< Input data or processing revealed unexpected data. Log level never > 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 963 of file edb-sqlite.c.
Here is the call graph for this function:| void eDBdisconnect | ( | eurephiaCTX * | ctx | ) |
Disconnects from a database
| ctx | eurephiaCTX - context with the database connection to disconnect from. |
< Messages intended when debugging. Only for log level > 10
< Input data or processing revealed unexpected data. Log level never > 2
< Informational messages. Log level should be < 5
Definition at line 192 of file edb-sqlite.c.
| eurephiaVALUES* eDBget_blacklisted_ip | ( | eurephiaCTX * | ctx | ) |
Retrieve a list of IP addresses found in the IP address blacklist table.
| ctx | eurephiaCTX |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 1035 of file edb-sqlite.c.
Here is the call graph for this function:| char* eDBget_firewall_profile | ( | eurephiaCTX * | ctx, | |
| eurephiaSESSION * | session | |||
| ) |
Retrieves the name of the firewall profile the user access (user account + certificate) for the user session
| ctx | eurephiaCTX | |
| session | eurephiaSESSION |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 1007 of file edb-sqlite.c.
Here is the call graph for this function:| char* eDBget_sessionkey_macaddr | ( | eurephiaCTX * | ctx, | |
| const char * | macaddr | |||
| ) |
Retrieve a unique session key based on a connections MAC address. This is called when OpenVPN is removing the MAC address of the client as a known connection.
| ctx | eurephiaCTX | |
| macaddr | String (char *) containing the MAC address of the client |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 739 of file edb-sqlite.c.
Here is the call graph for this function:| char* eDBget_sessionkey_seed | ( | eurephiaCTX * | ctx, | |
| sessionType | type, | |||
| const char * | sessionseed | |||
| ) |
Retrieve a unique session key based on a session seed.
| ctx | eurephiaCTX | |
| type | Must be either stSESSION for a normal session or stAUTHENTICATION for an authentication session (before the user is really logged in) | |
| sessionseed | session seed of the current connection |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_ERROR, in case it is not defined
< API errors but not sever, program can continue to run
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 683 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBget_uid | ( | eurephiaCTX * | ctx, | |
| const int | certid, | |||
| const char * | username | |||
| ) |
Retrieve the user ID (uid) for a given user and certificate.
| ctx | eurephiaCTX | |
| certid | Certificate ID of the user | |
| username | username of the user |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 373 of file edb-sqlite.c.
Here is the call graph for this function:| eurephiaVALUES* eDBload_sessiondata | ( | eurephiaCTX * | ctx, | |
| const char * | sesskey | |||
| ) |
Loads all session variables for a specified session key. This is key/value pairs which are unique for each connection.
| ctx | eurephiaCTX | |
| sesskey | String (char *) containing a session key |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_CRITICAL
< Operation failed and might have been aborted. Log level always 0
Definition at line 868 of file edb-sqlite.c.
Here is the call graph for this function:| void eDBregister_attempt | ( | eurephiaCTX * | ctx, | |
| int | type, | |||
| int | mode, | |||
| const char * | value | |||
| ) |
Registers an attempt in the attempts log. If the number of attempts exceeds the configured attempts limit, it will also be blacklisted immediately.
| ctx | eurephiaCTX | |
| type | Must be one of the constants: attempt_USERNAME, attempt_CERTIFICATE or attempt_IPADDR | |
| mode | Must be one of the constants: ATTEMPT_RESET to reset the attempts count or ATTEMPT_REGISTER to register an attempt. | |
| value | Value of the what to be registered. |
< Messages intended when debugging. Only for log level > 10
< mode code for resetting attempts count
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< mode code for resetting attempts count
< mode code for registering a new attempt
< mode code for resetting attempts count
< Alias for LOG_CRITICAL
< Operation failed and might have been aborted. Log level always 0
< mode code for registering a new attempt
< Input data or processing revealed unexpected data. Log level never > 2
< Alias for LOG_CRITICAL
< Operation failed and might have been aborted. Log level always 0
Definition at line 481 of file edb-sqlite.c.
Here is the call graph for this function:| 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 | |||
| ) |
Registers a client login. This happens after the client has been authenticated successfully, when OpenVPN does the OPENVPN_PLUGIN_CLIENT_CONNECT call to the eurephia-auth plug-in.
| ctx | eurephiaCTX | |
| skey | eurephiaSESSION. A login must be connected to an opened eurephia session. | |
| certid | Certificate ID of the clients user certificate | |
| uid | User id of the client | |
| proto | String containing protocol used for the connection (udp, tcp) | |
| remipaddr | Clients remote IP address | |
| remport | The port the client is connecting from | |
| vpnipaddr | The IP address openvpn assigned to the user | |
| vpnipmask | The VPN networks netmask for the VPN connection. |
< Messages intended when debugging. Only for log level > 10
< The session is newly created
< Alias for LOG_ERROR, in case it is not defined
< API errors but not sever, program can continue to run
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< The session is registered as logged in
Definition at line 576 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBregister_logout | ( | eurephiaCTX * | ctx, | |
| eurephiaSESSION * | skey, | |||
| const char * | bytes_sent, | |||
| const char * | bytes_received, | |||
| const char * | duration | |||
| ) |
Registers when a user logged out. It will then add some information about the session to the eurephia lastlog.
| ctx | eurephiaCTX | |
| skey | eurephiaSESSOIN of the user | |
| bytes_sent | Amount of bytes the OpenVPN server sent to the client | |
| bytes_received | Amount of bytes the OpenVPN server received from the client | |
| duration | How long the session lasted (in seconds) |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< The user logged out and the session is closed
Definition at line 654 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBregister_sessionkey | ( | eurephiaCTX * | ctx, | |
| const char * | seed, | |||
| const char * | seskey | |||
| ) |
Registers a new session key against a short-term session seed.
| ctx | eurephiaCTX | |
| seed | A string (char *) containing the short-term session seed | |
| seskey | A string (char *) containing the new unique session key |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 814 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBregister_vpnmacaddr | ( | eurephiaCTX * | ctx, | |
| eurephiaSESSION * | session, | |||
| const char * | macaddr | |||
| ) |
Registers the MAC address of the clients TAP interface. This function is called when OpenVPN does the OPENVPN_PLUGIN_LEARN_ADDRESS call to the eurephia-auth plug-in.
| ctx | eurephiaCTX | |
| session | eurephiaSESSION of the user | |
| macaddr | String (char *) containing the MAC address of the clients interface. |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 609 of file edb-sqlite.c.
Here is the call graph for this function:| int eDBremove_sessionkey | ( | eurephiaCTX * | ctx, | |
| const char * | seskey | |||
| ) |
Removes a session key reference to a short time session seed conversion table
| ctx | eurephiaCTX | |
| seskey | String containing the session key reference to remove |
< Messages intended when debugging. Only for log level > 10
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 845 of file edb-sqlite.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int eDBstore_session_value | ( | eurephiaCTX * | ctx, | |
| eurephiaSESSION * | session, | |||
| int | mode, | |||
| const char * | key, | |||
| const char * | val | |||
| ) |
Add, update or remove a session variable from the database. This operation is only affecting the given session. This function will only update the database itself.
| ctx | eurephiaCTX | |
| session | eurephiaSESSION to which the variable will be added, modified or deleted | |
| mode | Must be one of the constants: SESSVAL_NEW, SESSVAL_UPDATE, SESSVAL_DELETE | |
| key | Key name for the value to be stored | |
| val | Value to be stored |
< Messages intended when debugging. Only for log level > 10
< Messages intended when debugging. Only for log level > 10
< Save a new session value in the database
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Update an existing session value in the database
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Delete a session value
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
< Alias for LOG_FATAL
< Operation failed and cannot continue. Log level always < 2
Definition at line 901 of file edb-sqlite.c.
Here is the call graph for this function:| void update_attempts | ( | eurephiaCTX * | ctx, | |
| const char * | blid | |||
| ) |
Internal driver function for simplifying update of openvpn_blacklist. It will simply just update the 'last_accessed' field in the blacklist table.
| ctx | eurephiaCTX | |
| blid | Blacklist ID, integer value corresponding to the record in the database |
< Alias for LOG_CRITICAL
< Operation failed and might have been aborted. Log level always 0
Definition at line 113 of file edb-sqlite.c.
Here is the call graph for this function:
Here is the caller graph for this function:const eDBattempt_types_t eDBattempt_types[] [static] |
{
{NULL, NULL, NULL, NULL},
{"remoteip\0", "remoteip\0", "allow_ipaddr_attempts\0", "IP Address\0", "10\0", NULL},
{"digest\0", "lower(digest)\0", "allow_cert_attempts\0", "Certificate\0", "5\0", "lower\0"},
{"username\0", "username\0", "allow_username_attempts\0", "Username\0", "5\0", NULL},
{NULL, NULL, NULL, NULL}
}
Static mapping table with the needed values. Uses the eDBattempt_types_t struct.
Definition at line 76 of file edb-sqlite.c.
1.7.1