diff options
Diffstat (limited to 'database')
-rw-r--r-- | database/eurephiadb_driver.h | 2 | ||||
-rw-r--r-- | database/sqlite/edb-sqlite.c | 21 |
2 files changed, 16 insertions, 7 deletions
diff --git a/database/eurephiadb_driver.h b/database/eurephiadb_driver.h index abdcd77..8384ad2 100644 --- a/database/eurephiadb_driver.h +++ b/database/eurephiadb_driver.h @@ -134,7 +134,7 @@ int EUREPHIA_DRIVERAPI_FUNC(eDBauth_user)(eurephiaCTX *ctx, const int certid, * * @version API version level 1 * @param ctx eurephiaCTX - * @param certid Certificate ID of the user + * @param certid Certificate ID of the user. Optional. If set to 0, lookup will only happen against user table * @param username username of the user * * @return Returns uid of user on success, 0 if user account is not found, otherwise -1 on errors. diff --git a/database/sqlite/edb-sqlite.c b/database/sqlite/edb-sqlite.c index 724e095..bd0d905 100644 --- a/database/sqlite/edb-sqlite.c +++ b/database/sqlite/edb-sqlite.c @@ -390,12 +390,21 @@ int eDBget_uid(eurephiaCTX *ctx, const int certid, const char *username) DEBUG(ctx, 20, "Function call: eDBget_uid(ctx, %i, '%s')", certid, username); - res = sqlite_query(ctx, - "SELECT uid " - " FROM openvpn_usercerts " - " JOIN openvpn_users USING (uid) " - " WHERE certid = '%i' AND username = '%q'", - certid, username); + if( certid == 0 ) { + res = sqlite_query(ctx, + "SELECT uid " + " FROM openvpn_users " + " WHERE username = '%q'", + username); + } else { + res = sqlite_query(ctx, + "SELECT uid " + " FROM openvpn_usercerts " + " JOIN openvpn_users USING (uid) " + " WHERE certid = '%i' AND username = '%q'", + certid, username); + } + if( (sqlite_query_status(res) != dbSUCCESS) || (sqlite_get_numtuples(res) != 1) ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not lookup userid for user '%s'", username); if( sqlite_query_status(res) == dbERROR ) { |