summaryrefslogtreecommitdiffstats
path: root/database/sqlite/administration.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-08-29 09:54:06 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-08-29 09:54:06 +0200
commit2fcbada9a862ee19a77ee0505452ebed1f3926b1 (patch)
tree88550102739b169fd7b5f1f7198dc1556faad8be /database/sqlite/administration.c
parentc22206b7038390e0fe6b14f1ecb1d7012b0ed86d (diff)
downloadeurephia-2fcbada9a862ee19a77ee0505452ebed1f3926b1.tar.gz
eurephia-2fcbada9a862ee19a77ee0505452ebed1f3926b1.tar.xz
eurephia-2fcbada9a862ee19a77ee0505452ebed1f3926b1.zip
Moved usercerts related functions into its own file
Diffstat (limited to 'database/sqlite/administration.c')
-rw-r--r--database/sqlite/administration.c130
1 files changed, 0 insertions, 130 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c
index 6bd46a8..d681415 100644
--- a/database/sqlite/administration.c
+++ b/database/sqlite/administration.c
@@ -50,7 +50,6 @@
#define FMAP_USERS
#define FMAP_CERTS
-#define FMAP_USERCERTS
#define FMAP_ADMINACCESS
#define FMAP_LASTLOG
#define FMAP_OVPNATTEMPTS
@@ -1190,135 +1189,6 @@ int eDBadminDeleteCertificate(eurephiaCTX *ctx, xmlDoc *certxml) {
}
-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( (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 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;
- eDBfieldMap *usrcrt_m = NULL;
- char *mode = NULL;
- int rc = 0;
-
- DEBUG(ctx, 20, "Function call: eDBadminUpdateUserCertLink(ctx, xmlDoc)");
- assert( (ctx != NULL) && (usrcrt_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;
- }
-
- usrcrt_n = eurephiaXML_getRoot(ctx, usrcrt_xml, "usercerts_link", 1);
- if( usrcrt_n == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Could not find a valid XML for the user-certs link request");
- return 0;
- }
- mode = xmlGetAttrValue(usrcrt_n->properties, "mode");
- if( mode == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Invalid user-cert link request (1).");
- return 0;
- }
-
- fmap_n = xmlFindNode(usrcrt_n, "fieldMapping");
- if( fmap_n == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Invalid user-cert link request (2).");
- return 0;
- }
- usrcrt_m = eDBxmlMapping(ctx, tbl_sqlite_usercerts, NULL, fmap_n);
- assert(usrcrt_m != NULL);
-
- if( strcmp(mode, "register") == 0 ) {
- res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_usercerts", usrcrt_m, NULL, NULL);
- rc = res->last_insert_id;
- } else if( strcmp(mode, "remove") == 0 ) {
- res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_usercerts", NULL, usrcrt_m, NULL);
- rc = 1;
- }
-
- if( res == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Failed to register user account / certificate");
- rc = -1;
- } else {
- sqlite_free_results(res);
- }
-
- eDBfreeMapping(usrcrt_m);
- return rc;
-}
// The search XML document format is: