From 02b70ff6c325dce3983abe6b88e4fb7348de830f Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 2 Nov 2012 17:58:09 +0100 Subject: Extended eDBget_uid() to also to UID lookup when certid is not available By passing '0' as certid, the lookup will only be done against the user table. Any other values will consider the user-certification links as well. Signed-off-by: David Sommerseth --- database/sqlite/edb-sqlite.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'database/sqlite/edb-sqlite.c') 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 ) { -- cgit