diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-25 23:15:20 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-25 23:15:20 +0100 |
commit | 45d438f2951bc574482a13f83fe290a9a053ed22 (patch) | |
tree | 2c4cac1a6a5be69cd2d8458936c353cfdfeda6b0 | |
parent | 17ba7983b9decd13931012153af4c193c9437231 (diff) | |
download | eurephia-45d438f2951bc574482a13f83fe290a9a053ed22.tar.gz eurephia-45d438f2951bc574482a13f83fe290a9a053ed22.tar.xz eurephia-45d438f2951bc574482a13f83fe290a9a053ed22.zip |
users command: Added registering and deregistering certificates when adding/deleting users
-rw-r--r-- | eurephiadm/commands/users.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c index ee4e384..694f55e 100644 --- a/eurephiadm/commands/users.c +++ b/eurephiadm/commands/users.c @@ -31,6 +31,7 @@ #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xpath.h> +#include <libxml/xmlstring.h> #endif #define MODULE "eurephia::Users" @@ -703,9 +704,24 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * xmlFreeDoc(update_xml); // We need another XML doc to delete users eurephiaXML_CreateDoc(ctx, 1, "delete_user", &update_xml, &update_n); + assert( (update_xml != NULL) && (update_n != NULL) ); xmlNewProp(update_n, (xmlChar *) "uid", (xmlChar *) uid_str); rc = eDBadminDeleteUser(ctx, atoi_nullsafe(uid_str), update_xml); + + // Delete links between certificates associated to this user account + xmlFreeDoc(update_xml); + eurephiaXML_CreateDoc(ctx, 1, "usercerts_link", &update_xml, &update_n); + assert( (update_xml != NULL) && (update_n != NULL) ); + + xmlNewProp(update_n, (xmlChar *) "mode", (xmlChar *) "remove"); + update_n = xmlNewChild(update_n, NULL, (xmlChar *) "fieldMapping", NULL); + xmlNewProp(update_n, (xmlChar *) "table", (xmlChar *) "usercerts"); + xmlNewChild(update_n, NULL, (xmlChar *) "uid", (xmlChar *) uid_str); + + if( eDBadminUpdateUserCertLink(ctx, update_xml) != 1 ) { + fprintf(stderr, "%s: Failed to deregister user <-> certificate link\n", MODULE); + } break; } @@ -944,8 +960,27 @@ int add_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a } // If we have a certificate id, register a certificate link to the user account - if( certid > 0 ) { - // FIXME: Implement this feature when available in db driver API + if( (certid > 0) && (uid > 0) ) { + xmlDoc *usercert_xml = NULL; + xmlNode *usercert_n = NULL; + xmlChar tmp[66]; + + memset(&tmp, 0, 66); + eurephiaXML_CreateDoc(ctx, 1, "usercerts_link", &usercert_xml, &usercert_n); + assert( (usercert_xml != NULL) && (usercert_n != NULL) ); + + xmlNewProp(usercert_n, (xmlChar *) "mode", (xmlChar *) "register"); + usercert_n = xmlNewChild(usercert_n, NULL, (xmlChar *) "fieldMapping", NULL); + xmlNewProp(usercert_n, (xmlChar *) "table", (xmlChar *) "usercerts"); + + xmlStrPrintf(tmp, 64, (xmlChar *) "%i%c", uid, '\0'); + xmlNewChild(usercert_n, NULL, (xmlChar *) "uid", tmp); + xmlStrPrintf(tmp, 64, (xmlChar *) "%i%c", certid, '\0'); + xmlNewChild(usercert_n, NULL, (xmlChar *) "certid", tmp); + + if( eDBadminUpdateUserCertLink(ctx, usercert_xml) < 1 ) { + fprintf(stderr, "%s: Failed to register user <-> certificate link\n", MODULE); + } } exit: return (uid > 0); |