diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-13 22:34:15 +0200 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-13 22:34:15 +0200 |
| commit | 28b87c5c91033d551a3c954aa3d591ca06e523fe (patch) | |
| tree | 5fdadc272ad3e934b531505a38ce20c0ab41c205 /database/sqlite/administration | |
| parent | 6c9f69863b10de14e7a1e2f6d2a448978299414a (diff) | |
| download | eurephia-28b87c5c91033d551a3c954aa3d591ca06e523fe.tar.gz eurephia-28b87c5c91033d551a3c954aa3d591ca06e523fe.tar.xz eurephia-28b87c5c91033d551a3c954aa3d591ca06e523fe.zip | |
Moved eDBadminGetAdminAccess() into sqlite/administration/useraccount.c
Diffstat (limited to 'database/sqlite/administration')
| -rw-r--r-- | database/sqlite/administration/useraccount.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/database/sqlite/administration/useraccount.c b/database/sqlite/administration/useraccount.c index 15ca660..e867615 100644 --- a/database/sqlite/administration/useraccount.c +++ b/database/sqlite/administration/useraccount.c @@ -53,6 +53,7 @@ #include "../sqlite.h" #define FMAP_USERS /**< fieldmapping.h: Include declaration of tbl_sqlite_users */ +#define FMAP_ADMINACCESS /**< fieldmapping.h: Include declaration of tbl_sqlite_eurephiaadmacc */ #include "../fieldmapping.h" @@ -552,3 +553,62 @@ int eDBadminDeleteUser(eurephiaCTX *ctx, const int uid, xmlDoc *userinfo) { sqlite_free_results(res); return rc; } + + +/** + * @copydoc eDBadminGetAdminAccess() + */ +xmlDoc *eDBadminGetAdminAccess(eurephiaCTX *ctx, xmlDoc *srch_xml) { + dbresult *res = NULL; + eDBfieldMap *fmap = NULL; + int last_uid = -1, i = 0; + + xmlDoc *doc = NULL; + xmlNode *root_n = NULL, *fieldmap_n = NULL, *rec_n = NULL, *acl_n = NULL, *tmp_n; + + DEBUG(ctx, 20, "Function call: eDBadminGetAdminAccess(ctx, {xmlDoc})"); + assert( (ctx != NULL) && (srch_xml != NULL) ); + + if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) { + eurephia_log(ctx, LOG_CRITICAL, 0, + "eurephia admin function call attempted with wrong context type"); + return 0; + } + + tmp_n = eurephiaXML_getRoot(ctx, srch_xml, "admin_access", 1); + fieldmap_n = xmlFindNode(tmp_n, "fieldMapping"); + fmap = eDBxmlMapping(ctx, tbl_sqlite_eurephiaadmacc, "eac", fieldmap_n); + + // Query the database, find the user defined in the user map + res = sqlite_query_mapped(ctx, SQL_SELECT, + "SELECT eac.uid, username, interface, access" + " FROM eurephia_adminaccess eac" + " LEFT JOIN openvpn_users USING(uid)", + NULL, fmap, "uid, interface, access"); + if( res == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Error querying the database for a access levels"); + return 0; + } + eDBfreeMapping(fmap); + + eurephiaXML_CreateDoc(ctx, 1, "admin_access_list", &doc, &root_n); + + for( i = 0; i < sqlite_get_numtuples(res); i++ ) { + if( last_uid != atoi_nullsafe(sqlite_get_value(res, i, 0)) ) { + // Create a new block element when we get a new uid + rec_n = xmlNewChild(root_n, NULL, (xmlChar *) "user_access", NULL); + last_uid = atoi_nullsafe(sqlite_get_value(res, i, 0)); + + tmp_n = sqlite_xml_value(rec_n, XML_NODE, "username", res, i, 1); + sqlite_xml_value(tmp_n, XML_ATTR, "uid", res, i, 0); + + acl_n = xmlNewChild(rec_n, NULL, (xmlChar *) "access_levels", NULL); + } + + tmp_n = sqlite_xml_value(acl_n, XML_NODE, "access", res, i, 3); + sqlite_xml_value(tmp_n, XML_ATTR, "interface", res, i, 2); + } + + sqlite_free_results(res); + return doc; +} |
