summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2012-11-02 17:58:09 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2012-11-02 18:06:12 +0100
commit02b70ff6c325dce3983abe6b88e4fb7348de830f (patch)
tree72d2ebd21414823e911f64054479664aa84ce8d3 /database
parent69c35c113c15a76becd819e671b24bb1222de710 (diff)
downloadeurephia-02b70ff6c325dce3983abe6b88e4fb7348de830f.tar.gz
eurephia-02b70ff6c325dce3983abe6b88e4fb7348de830f.tar.xz
eurephia-02b70ff6c325dce3983abe6b88e4fb7348de830f.zip
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 <dazo@users.sourceforge.net>
Diffstat (limited to 'database')
-rw-r--r--database/eurephiadb_driver.h2
-rw-r--r--database/sqlite/edb-sqlite.c21
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 ) {