summaryrefslogtreecommitdiffstats
path: root/eurephiadm
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-18 01:32:07 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-18 01:32:07 +0100
commit0a8ea6be0a48353ee81641f6553c59f9e1728162 (patch)
treee9054a76b7c704d8ac2fc73bcdaa2267d02e312b /eurephiadm
parent98cb5d203fa6a0cfde0c56e840d693526ba219cf (diff)
downloadeurephia-0a8ea6be0a48353ee81641f6553c59f9e1728162.tar.gz
eurephia-0a8ea6be0a48353ee81641f6553c59f9e1728162.tar.xz
eurephia-0a8ea6be0a48353ee81641f6553c59f9e1728162.zip
users command: updated activation/deactivation of users
Changed it to work with the new XML model instead of the eurephiaUSERINFO structure.
Diffstat (limited to 'eurephiadm')
-rw-r--r--eurephiadm/commands/users.c102
1 files changed, 61 insertions, 41 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c
index 1b2caa8..cb876a3 100644
--- a/eurephiadm/commands/users.c
+++ b/eurephiadm/commands/users.c
@@ -416,9 +416,10 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
// This function handles activation and deactivation of an account
int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
- eurephiaUSERINFO *user = NULL;
- char *uname = NULL;
- int i, uid = 0, actmode = 0, rc = 0;
+ xmlDoc *user_xml = NULL, *update_xml = NULL, *srch_xml = NULL;
+ xmlNode *user_n = NULL, *update_n = NULL, *srch_root = NULL, *tmp = NULL;
+ char *uid_str = NULL, *activated = NULL, *deactivated = NULL;
+ int i, actmode = 0, rc = 0, crit_set;
e_options activargs[] = {
{"--uid", "-i", 1},
@@ -438,22 +439,28 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *
return 1;
}
+ eurephiaXML_CreateDoc(ctx, 1, "fieldMapping", &srch_xml, &srch_root);
+ xmlNewProp(srch_root, (xmlChar *) "table", (xmlChar *)"users");
+
+ crit_set = 0;
for( i = 1; i < argc; i++ ) {
switch( eurephia_getopt(&i, argc, argv, activargs) ) {
case 'i':
- uid = atoi_nullsafe(optargs[0]);
- if( uid == 0 ) {
+ if( atoi_nullsafe(optargs[0]) == 0 ) {
fprintf(stderr, "%s: Invalid user id\n", MODULE);
return 1;
}
+ xmlNewChild(srch_root, NULL, (xmlChar *)"uid", (xmlChar *) optargs[0]);
+ crit_set++;
break;
case 'u':
- uname = strdup_nullsafe(optargs[0]);
- if( strlen_nullsafe(uname) < 3 ) {
+ if( strlen_nullsafe(optargs[0]) < 3 ) {
fprintf(stderr, "%s: User name too short\n", MODULE);
return 1;
}
+ xmlNewChild(srch_root, NULL, (xmlChar *)"username", (xmlChar *)optargs[0]);
+ crit_set++;
break;
case 'h':
@@ -464,74 +471,87 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *
return 1;
}
}
- if( (uid == 0) && (uname == NULL) ){
+
+ if( crit_set == 0 ) {
fprintf(stderr,
"%s: Missing required parameter. You must provide either user id or user name\n",
MODULE);
+ xmlFreeDoc(srch_xml);
return 1;
}
- if( (uid > 0) && (uname != NULL) ) {
+ if( crit_set > 1 ) {
fprintf(stderr,
- "%s: You cannot use both user id and user name, only one of them.\n",
- MODULE);
+ "%s: You cannot have several search criterias (-i | -u)\n", MODULE);
+ xmlFreeDoc(srch_xml);
return 1;
}
- user = eAdminPopulateUSERINFO(uid, uname, NULL, NULL, NULL, NULL);
- assert(user != NULL);
- if( eDBadminGetUserInfo(ctx, USERINFO_user, user) == 0 ) {
+ // Search and find the user which was requested
+ if( (user_xml = eDBadminGetUserInfo(ctx, USERINFO_user, srch_xml)) == NULL ) {
fprintf(stderr, "%s: User not found\n", MODULE);
return 1;
}
+ xmlFreeDoc(srch_xml);
+
+ user_n = eurephiaXML_getRoot(ctx, user_xml, "user", 1);
+ if( user_n == NULL ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not find user node in the XML document");
+ xmlFreeDoc(user_xml);
+ return 1;
+ }
+
+ uid_str = xmlGetAttrValue(user_n->properties, "uid");
+ activated = defaultValue(xmlGetNodeContent(user_n, "activated"), NULL);
+ deactivated = defaultValue(xmlGetNodeContent(user_n, "deactivated"), NULL);
+
+ eurephiaXML_CreateDoc(ctx, 1, "update_user", &update_xml, &update_n);
+ assert( (update_xml != NULL) && (update_n != NULL) );
+ xmlNewProp(update_n, (xmlChar *) "uid", (xmlChar *) uid_str);
+ update_n = xmlNewChild(update_n, NULL, (xmlChar *) "fieldMapping", NULL);
+ xmlNewProp(update_n, (xmlChar *) "table", (xmlChar *) "users");
switch( actmode ) {
case 'a': // Activate a user account
- if( (user->activated != NULL) && (user->deactivated == NULL) ) {
+ if( (activated != NULL) && (deactivated == NULL) ) {
printf("User account is already active\n");
+ goto exit;
} else {
// Set activated field to now()
- free_nullsafe(user->activated);
- user->activated = strdup("CURRENT_TIMESTAMP");
+ xmlNewChild(update_n, NULL,
+ (xmlChar *) "activated", (xmlChar *) "CURRENT_TIMESTAMP");
// Remove deactivated flag
- free_nullsafe(user->deactivated);
- user->setnull_flags = FIELD_DEACTIVATED;
-
- // Update the user record
- rc = eDBadminUpdateUser(ctx, user->uid, user);
- if( rc == 1 ) {
- printf("User account is activated\n");
- } else {
- fprintf(stderr, "%s: Activating user account failed\n", MODULE);
- }
+ tmp = xmlNewChild(update_n, NULL,(xmlChar *) "deactivated", NULL);
+ xmlNewProp(tmp, (xmlChar *) "setnull", (xmlChar *) "1");
}
break;
case 'd': // Deactivate a user account
- if( (user->activated != NULL) && (user->deactivated != NULL) ) {
+ if( (activated != NULL) && (deactivated != NULL) ) {
printf("User account is already deactived\n");
- } else if( (user->activated != NULL) ) {
+ goto exit;
+ } else if( (activated != NULL) ) {
// Set deactivated to now()
- free_nullsafe(user->deactivated);
- user->deactivated = strdup("CURRENT_TIMESTAMP");
-
- // Update the user record
- rc = eDBadminUpdateUser(ctx, user->uid, user);
- if( rc == 1 ) {
- printf("User account is deactivated\n");
- } else {
- fprintf(stderr, "%s: Deactivating the user account failed\n", MODULE);
- }
+ xmlNewChild(update_n, NULL,
+ (xmlChar *) "deactivated", (xmlChar *) "CURRENT_TIMESTAMP");
+
} else {
fprintf(stderr, "%s: User account is not activated yet\n", MODULE);
}
break;
}
- eAdminFreeUSERINFO(user);
- free_nullsafe(uname);
+ // Update the user record
+ rc = eDBadminUpdateUser(ctx, atoi_nullsafe(uid_str), update_xml);
+ if( rc == 1 ) {
+ printf("User account is %s\n", (actmode == 'd' ? "deactivated" : "activated"));
+ } else {
+ fprintf(stderr, "%s: Deactivating the user account failed\n", MODULE);
+ }
+ exit:
+ xmlFreeDoc(user_xml);
return 0;
}