diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-25 23:29:23 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-25 23:29:23 +0200 |
commit | 926a89915cc942fb6ade8b06c7ceac1a2ed202d6 (patch) | |
tree | 50ca48e2234639659309ba6df6dfc52b8ec7d22e /eurephiadm | |
parent | 4bc3e2523774ab9f6dfea7a00f683aba49b6424b (diff) | |
download | eurephia-926a89915cc942fb6ade8b06c7ceac1a2ed202d6.tar.gz eurephia-926a89915cc942fb6ade8b06c7ceac1a2ed202d6.tar.xz eurephia-926a89915cc942fb6ade8b06c7ceac1a2ed202d6.zip |
Rewrote eurephiadm usres --add to work with the new eDBadminUserAccount() API
Diffstat (limited to 'eurephiadm')
-rw-r--r-- | eurephiadm/commands/users.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c index 657a6f2..e2e1df7 100644 --- a/eurephiadm/commands/users.c +++ b/eurephiadm/commands/users.c @@ -67,9 +67,7 @@ static int eDBadminUpdateUser(eurephiaCTX *ctx, int uid, xmlDoc *update_xml) { static int eDBadminDeleteUser(eurephiaCTX *ctx, int uid, xmlDoc *update_xml) { return 0; } -static int eDBadminAddUser(eurephiaCTX *ctx, xmlDoc *user_xml) { - return -1; -} + /** * Forward declaration of a function already found in certificates.c @@ -698,8 +696,9 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * * @return returns 0 on success, otherwise 1. */ int add_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { - xmlDoc *user_xml = NULL; + xmlDoc *user_xml = NULL, *resxml = NULL; xmlNode *node = NULL, *node2 = NULL; + eurephiaRESULT *res = NULL; struct stat cert_stat; int i = 0, certid = 0, uid = 0, certfile_format = CERTFILE_PEM; char *uname = NULL, *passwd = NULL, *certfile = NULL, *digest = NULL; @@ -824,9 +823,10 @@ int add_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a free_nullsafe(ctx, chkpwd); } - // Prepare add user XML document with fieldMapping - eurephiaXML_CreateDoc(ctx, 1, "add_user", &user_xml, &node); + eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &user_xml, &node); + xmlNewProp(node, (xmlChar *) "mode", (xmlChar *) "add"); + node = xmlNewChild(node, NULL, (xmlChar *) "fieldMapping", NULL); xmlNewProp(node, (xmlChar *) "table", (xmlChar *) "users"); @@ -835,15 +835,38 @@ int add_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int a xmlNewProp(node2, (xmlChar *) "pwhash", (xmlChar *) "none"); // Add the user - uid = eDBadminAddUser(ctx, user_xml); - if( uid > 0 ) { - fprintf(stdout, "%s: User registered successfully (user id %i)\n", MODULE, uid); - } else { - fprintf(stderr, "%s: Failed to register user\n", MODULE); - } + resxml = eDBadminUserAccount(ctx, user_xml); + xmlFreeDoc(user_xml); memset(passwd, 0, strlen_nullsafe(passwd)); free_nullsafe(ctx, passwd); - xmlFreeDoc(user_xml); + if( (resxml == NULL) || !eurephiaXML_IsResultMsg(ctx, resxml) ) { + fprintf(stderr, "%s: Failed to register the user. Unknown failure.\n", MODULE); + return 1; + } + + res = eurephiaXML_ParseResultMsg(ctx, resxml); + if( res == NULL ) { + fprintf(stderr, "%s: Failed to register the user. No results returned.\n", MODULE); + xmlFreeDoc(resxml); + return 1; + } else if( res->resultType == exmlERROR ) { + fprintf(stderr, "%s: %s\n", MODULE, res->message); + xmlFreeDoc(resxml); + free_nullsafe(ctx, res); + return 1; + } + + if( xmlStrcmp(res->details->children->name, (xmlChar *) "UserAccount") != 0 ) { + fprintf(stderr, "%s: Invalid result value. User account might be registered\n", MODULE); + xmlFreeDoc(resxml); + free_nullsafe(ctx, res); + return 1; + } + + fprintf(stdout, "%s: %s\n", MODULE, res->message); + uid = atoi_nullsafe(xmlGetAttrValue(res->details->properties, "uid")); + xmlFreeDoc(resxml); + free_nullsafe(ctx, res); if( (digest != NULL) || (certfile != NULL) ) { if( digest != NULL ) { |