diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-10 22:48:56 +0100 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-10 22:48:56 +0100 |
| commit | 866c76a6bd60a1dabdfe593339030a09324e8aa2 (patch) | |
| tree | 4a2101c60eabef6d43e70a8f73df94cb27703d75 /database/sqlite | |
| parent | 762fc375f6316407c7d3489d53de336146fc1960 (diff) | |
| download | eurephia-866c76a6bd60a1dabdfe593339030a09324e8aa2.tar.gz eurephia-866c76a6bd60a1dabdfe593339030a09324e8aa2.tar.xz eurephia-866c76a6bd60a1dabdfe593339030a09324e8aa2.zip | |
Updated eDBadminGetUserInfo(...) to take filtering parameter
Diffstat (limited to 'database/sqlite')
| -rw-r--r-- | database/sqlite/administration.c | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index d44d9a0..042bf8e 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -39,6 +39,11 @@ #include <eurephiadb_mapping.h> #include <passwd.h> +#ifndef DRIVER_MODE +#define DRIVER_MODE +#endif +#include <eurephiadb_driver.h> + #include "sqlite.h" #include "fieldmapping.h" @@ -406,7 +411,7 @@ eurephiaUSERLIST *eDBadminGetUserList(eurephiaCTX *ctx, const char *sortkeys) { // This function will read out all info from eurephiaINFO *user which is not NULL and create a query based // on these values. If a user is found, the *user struct will be updated with the user found. On success // the function returns 1. -int eDBadminGetUserInfo(eurephiaCTX *ctx, eurephiaUSERINFO *user) { +int eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, eurephiaUSERINFO *user) { dbresult *uinf = NULL, *certinf = NULL; eDBfieldMap *uinfo_map = NULL; @@ -430,44 +435,52 @@ int eDBadminGetUserInfo(eurephiaCTX *ctx, eurephiaUSERINFO *user) { case 1: free_nullsafe(user->username); - free_nullsafe(user->password); - free_nullsafe(user->activated); - free_nullsafe(user->deactivated); - free_nullsafe(user->last_accessed); - user->username = strdup_nullsafe(sqlite_get_value(uinf, 0, 0)); - user->activated = strdup_nullsafe(sqlite_get_value(uinf, 0, 1)); - user->deactivated = strdup_nullsafe(sqlite_get_value(uinf, 0, 2)); - user->last_accessed = strdup_nullsafe(sqlite_get_value(uinf, 0, 3)); user->uid = atoi_nullsafe(sqlite_get_value(uinf, 0, 4)); - sqlite_free_results(uinf); - // Extract certificate info --- FIXME: Come up with clever idea to also add access profile - certinf = sqlite_query(ctx, - "SELECT depth, digest, common_name, organisation, email, c.registered, " - " c.certid" //, access_descr" - " FROM openvpn_certificates c" - " LEFT JOIN openvpn_usercerts uc ON (c.certid = uc.certid)" - // " LEFT JOIN openvpn_accesses a ON (uc.accessprofile = a.accessprofile)" - " WHERE uid = %i ORDER BY c.certid DESC", user->uid); - if( (certinf != NULL) && (sqlite_get_numtuples(certinf) > 0) ) { - eurephiaCERTINFO *rec = NULL; - int i; - - user->certlist = eAdminCreateCERTLIST(); - - for( i = 0; i < sqlite_get_numtuples(certinf); i++ ) { - rec = eAdminPopulateCERTINFO( - atoi_nullsafe(sqlite_get_value(certinf, i, 6)), - atoi_nullsafe(sqlite_get_value(certinf, i, 0)), - sqlite_get_value(certinf, i, 1), - sqlite_get_value(certinf, i, 2), - sqlite_get_value(certinf, i, 3), - sqlite_get_value(certinf, i, 4), - sqlite_get_value(certinf, i, 5)); - eAdminInsertCERTINFO(user->certlist, rec); + if( (getInfo & USERINFO_user) == USERINFO_user ) { + free_nullsafe(user->password); + free_nullsafe(user->activated); + free_nullsafe(user->deactivated); + free_nullsafe(user->last_accessed); + + user->activated = strdup_nullsafe(sqlite_get_value(uinf, 0, 1)); + user->deactivated = strdup_nullsafe(sqlite_get_value(uinf, 0, 2)); + user->last_accessed = strdup_nullsafe(sqlite_get_value(uinf, 0, 3)); + sqlite_free_results(uinf); + } + + if( (getInfo & USERINFO_certs) == USERINFO_certs ) { + // Extract certificate info + certinf = sqlite_query(ctx, + "SELECT depth, digest, common_name, organisation, email, " + " c.registered, c.certid, access_descr" + " FROM openvpn_certificates c" + " LEFT JOIN openvpn_usercerts uc ON (c.certid = uc.certid)" + " LEFT JOIN openvpn_accesses a " + " ON (uc.accessprofile = a.accessprofile)" + " WHERE uid = %i ORDER BY c.certid DESC", user->uid); + if( (certinf != NULL) && (sqlite_get_numtuples(certinf) > 0) ) { + eurephiaCERTINFO *rec = NULL; + int i; + + user->certlist = eAdminCreateCERTLIST(); + + for( i = 0; i < sqlite_get_numtuples(certinf); i++ ) { + rec = eAdminPopulateCERTINFO( + atoi_nullsafe(sqlite_get_value(certinf, i, 6)), + atoi_nullsafe(sqlite_get_value(certinf, i, 0)), + sqlite_get_value(certinf, i, 1), + sqlite_get_value(certinf, i, 2), + sqlite_get_value(certinf, i, 3), + sqlite_get_value(certinf, i, 4), + sqlite_get_value(certinf, i, 5)); + eAdminInsertCERTINFO(user->certlist, rec); + } + sqlite_free_results(certinf); + } else { + user->certlist = NULL; } - sqlite_free_results(certinf); } else { user->certlist = NULL; } |
