diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-06 01:32:39 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-06 01:32:39 +0100 |
commit | b67f22e540526b115e84dcc52f37606ac78b238f (patch) | |
tree | 55ab5e95e7f4736a5404fe6852b17732522cd5cf | |
parent | 6c8d48c8bee1983c6a8fe6a2bfeba3488e28c334 (diff) | |
download | eurephia-b67f22e540526b115e84dcc52f37606ac78b238f.tar.gz eurephia-b67f22e540526b115e84dcc52f37606ac78b238f.tar.xz eurephia-b67f22e540526b115e84dcc52f37606ac78b238f.zip |
Added admin function to give a list of users
-rw-r--r-- | common/eurephia_admin_common.c | 38 | ||||
-rw-r--r-- | database/sqlite/CMakeLists.txt | 1 | ||||
-rw-r--r-- | database/sqlite/administration.c | 44 |
3 files changed, 81 insertions, 2 deletions
diff --git a/common/eurephia_admin_common.c b/common/eurephia_admin_common.c index 7333408..c49c1a3 100644 --- a/common/eurephia_admin_common.c +++ b/common/eurephia_admin_common.c @@ -24,7 +24,9 @@ #include <assert.h> #include <eurephia_nullsafe.h> +#include <passwd.h> +#define EUREPHIA_ADMIN_COMMON_C #include "eurephia_admin_common.h" eFieldMap *eAdminGetTableMap(int table) { @@ -57,7 +59,6 @@ eFieldMap *eAdminGetTableMap(int table) { char *eAdminConvertSortKeys(eFieldMap *tfmap, const char *skeys_str) { eFieldMap *sk_map = NULL; - long sortmap = 0; int i, j; char *cp = NULL, *tok = NULL, *delims = ","; static char sortkeys[8194]; @@ -92,3 +93,38 @@ char *eAdminConvertSortKeys(eFieldMap *tfmap, const char *skeys_str) { sortkeys[strlen(sortkeys)-1] = '\0'; return sortkeys; } + +eurephiaUSERINFO *eAdminPopulateUSERINFO(int uid, const char *uname, const char *pwd, + const char *activated, const char *deactivd, const char *lastacc) +{ + eurephiaUSERINFO *newrec = NULL; + + newrec = (eurephiaUSERINFO *) malloc(sizeof(eurephiaUSERINFO)+2); + assert( newrec != NULL ); + memset(newrec, 0, sizeof(eurephiaUSERINFO)+2); + + newrec->uid = uid; + newrec->username = strdup(uname); + newrec->password = (pwd == NULL ? NULL : passwdhash(pwd)); + newrec->activated = strdup(activated); + newrec->deactivated = strdup(deactivd); + newrec->last_accessed = strdup(lastacc); + newrec->next = NULL; + + return newrec; +} + + +void _eAdminFreeUSERINFO_func(eurephiaUSERINFO *p) { + if( p == NULL ) { + return; + } + eAdminFreeUSERINFO(p->next); + free_nullsafe(p->username); + free_nullsafe(p->password); + free_nullsafe(p->activated); + free_nullsafe(p->deactivated); + free_nullsafe(p->last_accessed); + p->next = NULL; + free_nullsafe(p); +} diff --git a/database/sqlite/CMakeLists.txt b/database/sqlite/CMakeLists.txt index bed0559..f1d5fef 100644 --- a/database/sqlite/CMakeLists.txt +++ b/database/sqlite/CMakeLists.txt @@ -11,6 +11,7 @@ SET(COMMON ../../common/eurephia_log.c ../../common/eurephiadb_session_common.c ../../common/eurephia_values.c + ../../common/eurephia_admin_common.c ../../common/passwd.c ../../common/sha512.c ) diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index 29face8..7612c6d 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -12,6 +12,7 @@ #include <eurephia_nullsafe.h> #include <eurephia_context.h> #include <eurephia_admin_struct.h> +#include <eurephia_admin_common.h> #include <eurephia_log.h> #include <eurephia_values.h> #include <eurephiadb_session_struct.h> @@ -327,7 +328,48 @@ int eDBadminConfigDelete(eurephiaCTX *ctx, const char *key) { } eurephiaUSERLIST *eDBadminGetUserList(eurephiaCTX *ctx, const char *sortkeys) { - return NULL; + eurephiaUSERINFO *list = NULL, *rec = NULL, *last = NULL; + eurephiaUSERLIST *ret = NULL; + dbresult *res = NULL; + int i = 0; + + assert((ctx != NULL) && (ctx->dbc != 0)); + + res = sqlite_query(ctx, + "SELECT username, activated, deactivated, last_accessed, uid" + " FROM openvpn_users" + "%s", (sortkeys != NULL ? sortkeys : "")); + if( res == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Error querying the user database"); + return NULL; + } + + ret = (eurephiaUSERLIST *) malloc(sizeof(eurephiaUSERLIST)+2); + assert(ret != NULL); + memset(ret, 0, sizeof(eurephiaUSERLIST)+2); + + ret->num_users = sqlite_get_numtuples(res); + + for( i = 0; i < ret->num_users; i++ ) { + rec = eAdminPopulateUSERINFO( + atoi_nullsafe(sqlite_get_value(res, i, 4)), // uid + sqlite_get_value(res, i, 0), // username + NULL, // passwd + sqlite_get_value(res, i, 1), // activated + sqlite_get_value(res, i, 2), // deactivated + sqlite_get_value(res, i, 3) // last accessed + ); + if( list == NULL ) { + list = rec; + last = list; + } else { + last->next = rec; + last = rec; + } + } + sqlite_free_results(res); + + return ret; } eurephiaUSERINFO *eDBadminGetUserInfo(eurephiaCTX *ctx, eurephiaUSERINFO *srchkey) { |