diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-13 02:18:57 +0100 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-13 02:18:57 +0100 |
| commit | b140ce52fd1f705f4acd7b91347eb2f584c45460 (patch) | |
| tree | 36e3e0e66ec7c1038902ae7e4891a032fc90aa91 /database/sqlite | |
| parent | 4942d5a229dca435488aa959d99638c774a0eea7 (diff) | |
| download | eurephia-b140ce52fd1f705f4acd7b91347eb2f584c45460.tar.gz eurephia-b140ce52fd1f705f4acd7b91347eb2f584c45460.tar.xz eurephia-b140ce52fd1f705f4acd7b91347eb2f584c45460.zip | |
Began porting eDBadminGetUserInfo(...) over to XML
Diffstat (limited to 'database/sqlite')
| -rw-r--r-- | database/sqlite/administration.c | 115 |
1 files changed, 65 insertions, 50 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index 61980c0..ab6cdd3 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -23,6 +23,9 @@ #include <string.h> #include <assert.h> +#include <libxml/parser.h> +#include <libxml/tree.h> + #ifndef DRIVERAPIVERSION # define DRIVERAPIVERSION 2 #endif @@ -408,12 +411,23 @@ eurephiaUSERLIST *eDBadminGetUserList(eurephiaCTX *ctx, const char *sortkeys) { return ret; } +inline int xml_set_flag(xmlNodePtr node, char *flagname, int flagged) { + if( flagged ) { + xmlNewChild(node, NULL, (xmlChar *) "flag", (xmlChar *) flagname); + } + return flagged; +} + // 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, int getInfo, eurephiaUSERINFO *user) { dbresult *uinf = NULL, *certinf = NULL; eDBfieldMap *uinfo_map = NULL; + int flag = 0, uid = 0; + + xmlDocPtr doc = NULL; + xmlNodePtr root_n = NULL, info_n = NULL; uinfo_map = eDBmkMapping_USERINFO(ctx, tbl_sqlite_users, "u", user); @@ -448,38 +462,44 @@ int eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, eurephiaUSERINFO *user) { return 0; // No user found case 1: - free_nullsafe(user->username); - user->username = strdup_nullsafe(sqlite_get_value(uinf, 0, 0)); - user->uid = atoi_nullsafe(sqlite_get_value(uinf, 0, 4)); + uid = atoi_nullsafe(sqlite_get_value(uinf, 0, 4)); + doc = xmlNewDoc((xmlChar *) "1.0"); + root_n = xmlNewNode(NULL, (xmlChar *) "user"); + sqlite_xml_value(root_n, XML_ATTR, "uid", uinf, 0, 4); + sqlite_xml_value(root_n, XML_NODE, "username", uinf, 0, 0); + xmlDocSetRootElement(doc, root_n); + + info_n = xmlNewChild(root_n, NULL, (xmlChar *) "flags", NULL); // set DEACTIVATED flag, if deactivated field is not NULL - user->account_flags = ((sqlite_get_value(uinf, 0, 2) != NULL) ? ACCFLAG_DEACTIVATED : 0); + xml_set_flag(info_n, "DEACTIVATED", (sqlite_get_value(uinf, 0, 2) != NULL)); + // set BLACKLISTED flag, if username is found in blacklist table - user->account_flags|= ((atoi_nullsafe(sqlite_get_value(uinf, 0, 5))==1) ? ACCFLAG_BLACKLISTED : 0); + xml_set_flag(info_n, "BLACKLISTED", (atoi_nullsafe(sqlite_get_value(uinf, 0, 5))==1)); + // set OPENSESSION flag, if user has a lastlog entry with sessionstatus == 2 - user->account_flags|= ((atoi_nullsafe(sqlite_get_value(uinf, 0, 6))==1) ? ACCFLAG_OPENSESSION : 0); + xml_set_flag(info_n, "OPENSESSION", (atoi_nullsafe(sqlite_get_value(uinf, 0, 6))==1)); + // set ERRATTEMPT flag, if user has an entry in attempts log with attemtps > 0 - user->account_flags|= ((atoi_nullsafe(sqlite_get_value(uinf, 0, 8))==1) ? ACCFLAG_ERRATTEMPT : 0); + xml_set_flag(info_n, "ERRATTEMPT", (atoi_nullsafe(sqlite_get_value(uinf, 0, 8))==1)); + // set NEVERUSED flag, if login count == 0 and last_accessed == NULL - user->account_flags|= (((atoi_nullsafe(sqlite_get_value(uinf,0, 7))==0) - && (sqlite_get_value(uinf, 0, 3) == NULL)) ? ACCFLAG_NEVERUSED : 0); + flag = xml_set_flag(info_n, "NEVERUSED", ((atoi_nullsafe(sqlite_get_value(uinf,0, 7))==0) + && (sqlite_get_value(uinf, 0, 3) == NULL))); + // set RSETLASTUSED flag, if login count == 0 and last_accessed == NULL - user->account_flags|= ((((user->account_flags & ACCFLAG_NEVERUSED) == 0) - && (sqlite_get_value(uinf,0,3)) == NULL) ? ACCFLAG_RSETLASTUSED: 0); + xml_set_flag(info_n, "RSETLASTUSED", !flag && (sqlite_get_value(uinf,0,3)) == NULL); + // set RSETLOGINCNT flag, if login count == 0 and last_accessed != NULL - user->account_flags|= (((atoi_nullsafe(sqlite_get_value(uinf,0, 7))==0) - && (sqlite_get_value(uinf,0,3)) != NULL) ? ACCFLAG_RSETLOGINCNT: 0); + xml_set_flag(info_n, "RSETLOGINCNT", ((atoi_nullsafe(sqlite_get_value(uinf,0, 7))==0) + && (sqlite_get_value(uinf,0,3)) != NULL)); 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)); - user->logincount = atoi_nullsafe(sqlite_get_value(uinf, 0, 7)); + sqlite_xml_value(root_n, XML_NODE, "activated", uinf, 0, 1); + sqlite_xml_value(root_n, XML_NODE, "deactivated", uinf, 0, 2); + info_n = sqlite_xml_value(root_n, XML_NODE, "last_accessed", uinf, 0, 3); + sqlite_xml_value(info_n, XML_ATTR, "logincount", uinf, 0, 7); + sqlite_free_results(uinf); } @@ -493,44 +513,39 @@ int eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, eurephiaUSERINFO *user) { " 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); + " WHERE uid = %i ORDER BY c.certid DESC", uid); + + info_n = xmlNewChild(root_n, NULL, (xmlChar *) "certificates", NULL); if( (certinf != NULL) && (sqlite_get_numtuples(certinf) > 0) ) { - eurephiaCERTINFO *rec = NULL; int i; -#ifdef FIREWALL - eurephiaACCESSLIST *aclst = NULL; - int acid = 0; + xmlNodePtr cert, acpr; - aclst = eAdminCreateACCESSLIST(); -#endif - 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)); -#ifdef FIREWALL - acid = atoi_nullsafe(sqlite_get_value(certinf, i, 7)); - rec->access = eAdminRegisterACCESSINFO(aclst, acid, - sqlite_get_value(certinf, i, 9), - sqlite_get_value(certinf, i, 8)); -#endif - eAdminInsertCERTINFO(user->certlist, rec); + cert = xmlNewChild(info_n, NULL, (xmlChar *) "certificate", NULL); + + sqlite_xml_value(cert, XML_ATTR, "certid", certinf, 0, 6); + sqlite_xml_value(cert, XML_ATTR, "depth", certinf, 0, 0); + sqlite_xml_value(cert, XML_ATTR, "registered", certinf, 0, 5); + sqlite_xml_value(cert, XML_NODE, "digest", certinf, 0, 1); + sqlite_xml_value(cert, XML_NODE, "common_name", certinf, 0, 2); + sqlite_xml_value(cert, XML_NODE, "organisation", certinf, 0, 3); + sqlite_xml_value(cert, XML_NODE, "email", certinf, 0, 4); + + acpr = sqlite_xml_value(cert, XML_NODE, "access_profile", certinf, 0, 8); + sqlite_xml_value(acpr, XML_ATTR, "accessprofile", certinf, 0, 7); + sqlite_xml_value(acpr, XML_ATTR, "fwdestination", certinf, 0, 9); } - } else { - user->certlist = NULL; } + if( certinf != NULL ) { sqlite_free_results(certinf); } - } else { - user->certlist = NULL; } + + // Just for debug purpose, until everything is ported over to XML + xmlSaveFormatFileEnc("-", doc, "UTF-8", 1); + xmlFreeDoc(doc); + xmlCleanupParser(); return 1; default: |
