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