diff options
Diffstat (limited to 'database/sqlite/edb-sqlite.c')
| -rw-r--r-- | database/sqlite/edb-sqlite.c | 21 |
1 files changed, 15 insertions, 6 deletions
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 ) { |
