diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-28 20:38:17 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-28 20:38:17 +0100 |
commit | a24aaf691132c26658f1706fff8f050338d73c97 (patch) | |
tree | ff6738cea78aebabb5e9848538eba3bbd3000176 | |
parent | 927b6469a9ead439290ae4d884178c61d95f3be2 (diff) | |
download | eurephia-a24aaf691132c26658f1706fff8f050338d73c97.tar.gz eurephia-a24aaf691132c26658f1706fff8f050338d73c97.tar.xz eurephia-a24aaf691132c26658f1706fff8f050338d73c97.zip |
Added db driver function: eDBadminGetUserCertsList(...) - to get user account/certs links
-rw-r--r-- | database/eurephiadb.c | 2 | ||||
-rw-r--r-- | database/eurephiadb_driver.h | 1 | ||||
-rw-r--r-- | database/sqlite/administration.c | 71 |
3 files changed, 74 insertions, 0 deletions
diff --git a/database/eurephiadb.c b/database/eurephiadb.c index a5bb048..63dded4 100644 --- a/database/eurephiadb.c +++ b/database/eurephiadb.c @@ -110,6 +110,8 @@ int eDBlink_init(eurephiaCTX *ctx, const char *dbl, const int minver) eDBadminGetCertificateInfo = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetCertificateInfo"); eDBadminAddCertificate = eGetSym(ctx, ctx->eurephia_driver, "eDBadminAddCertificate"); eDBadminDeleteCertificate = eGetSym(ctx, ctx->eurephia_driver, "eDBadminDeleteCertificate"); + + eDBadminGetUserCertsList = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetUserCertsList"); eDBadminUpdateUserCertLink = eGetSym(ctx, ctx->eurephia_driver, "eDBadminUpdateUserCertLink"); eDBadminGetLastlog = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetLastlog"); diff --git a/database/eurephiadb_driver.h b/database/eurephiadb_driver.h index 6b61b13..459f513 100644 --- a/database/eurephiadb_driver.h +++ b/database/eurephiadb_driver.h @@ -116,6 +116,7 @@ xmlDoc *(*eDBadminGetCertificateInfo) (eurephiaCTX *ctx, xmlDoc *searchkey, cons int (*eDBadminAddCertificate) (eurephiaCTX *ctx, xmlDoc *certinfo); int (*eDBadminDeleteCertificate) (eurephiaCTX *ctx, xmlDoc *certinfo); +xmlDoc *(*eDBadminGetUserCertsList) (eurephiaCTX *ctx, const char *sortkeys); int (*eDBadminUpdateUserCertLink) (eurephiaCTX *ctx, xmlDoc *usrcrt_xml); xmlDoc *(*eDBadminGetLastlog) (eurephiaCTX *ctx, xmlDoc *usersrch, xmlDoc *certsrch, const char *sortkeys); diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index 034e66d..57bc4e4 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -1081,6 +1081,77 @@ int eDBadminDeleteCertificate(eurephiaCTX *ctx, xmlDoc *certxml) { return rc; } + +xmlDoc *eDBadminGetUserCertsList(eurephiaCTX *ctx, const char *sortkeys) { + xmlDoc *list_xml = NULL; + xmlNode *link_root_n = NULL, *link_n = NULL, *tmp_n = NULL; + dbresult *res = NULL; + xmlChar tmp[2050]; + char *dbsort = NULL; + int i; + + DEBUG(ctx, 20, "Function call: eDBadminGetUserCertsList(ctx, '%s')", sortkeys); + assert( ctx != NULL ); + + if( sortkeys != NULL ) { + dbsort = eDBmkSortKeyString(tbl_sqlite_usercerts, sortkeys); + } + + res = sqlite_query(ctx, + "SELECT uicid, ucs.uid AS uid, certid, ucs.registered AS registered," + " ucs.accessprofile AS accessprofile, access_descr," + " username, " + " common_name, organisation, email, digest, depth " + " FROM openvpn_usercerts ucs" + " LEFT JOIN openvpn_certificates USING(certid)" + " LEFT JOIN openvpn_accesses acc ON(ucs.accessprofile = acc.accessprofile)" + " LEFT JOIN openvpn_users u ON(u.uid = ucs.uid)%s%s", + (dbsort != NULL ? " ORDER BY ":""), + (dbsort != NULL ? dbsort : "")); + + if( res == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Could not query the certificate table"); + return NULL; + } + + memset(&tmp, 0, 2050); + eurephiaXML_CreateDoc(ctx, 1, "usercerts_links", &list_xml, &link_root_n); + xmlStrPrintf(tmp, 64, (xmlChar *) "%i", sqlite_get_numtuples(res)); + xmlNewProp(link_root_n, (xmlChar *) "link_count", (xmlChar *) tmp); + + for( i = 0; i < sqlite_get_numtuples(res); i++ ) { + link_n = xmlNewChild(link_root_n, NULL, (xmlChar *) "usercert_link", NULL); + + sqlite_xml_value(link_n, XML_ATTR, "uicid", res, i, 0); + sqlite_xml_value(link_n, XML_ATTR, "registered", res, i, 3); + + tmp_n = sqlite_xml_value(link_n, XML_NODE, "username", res, i, 6); + sqlite_xml_value(tmp_n, XML_ATTR, "uid", res, i, 1); + + tmp_n = xmlNewChild(link_n, NULL, (xmlChar *) "certificate", NULL); + sqlite_xml_value(tmp_n, XML_ATTR, "certid", res, i, 2); + sqlite_xml_value(tmp_n, XML_ATTR, "depth", res, i, 11); + + xmlStrPrintf(tmp, 2048, (xmlChar *) "%.2048s", sqlite_get_value(res, i, 7)); + xmlReplaceChars(tmp, '_', ' '); + xmlNewChild(tmp_n, NULL, (xmlChar *) "common_name", tmp); + + xmlStrPrintf(tmp, 2048, (xmlChar *) "%.2048s", sqlite_get_value(res, i, 8)); + xmlReplaceChars(tmp, '_', ' '); + xmlNewChild(tmp_n, NULL, (xmlChar *) "organisation", tmp); + + sqlite_xml_value(tmp_n, XML_NODE, "email", res, i, 9); + sqlite_xml_value(tmp_n, XML_NODE, "digest", res, i, 10); + + tmp_n = sqlite_xml_value(link_n, XML_NODE, "access_profile", res, i, 5); + sqlite_xml_value(tmp_n, XML_ATTR, "accessprofile", res, i, 4); + } + sqlite_free_results(res); + + return list_xml; +} + + int eDBadminUpdateUserCertLink(eurephiaCTX *ctx, xmlDoc *usrcrt_xml) { dbresult *res = NULL; xmlNode *usrcrt_n = NULL, *fmap_n = NULL; |