diff options
-rw-r--r-- | eurephiadm/commands/users.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c index 03e23e9..6853507 100644 --- a/eurephiadm/commands/users.c +++ b/eurephiadm/commands/users.c @@ -438,11 +438,11 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int } -// This function handles activation and deactivation of an account +// This function handles activation, deactivation and deletion of an account int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { 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; + char *uid_str = NULL, *activated = NULL, *deactivated = NULL, *actmode_str = NULL; int i, actmode = 0, rc = 0, crit_set = 0; e_options activargs[] = { @@ -456,8 +456,13 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * if( (strcmp(argv[0], "--activate") == 0) || (strcmp(argv[0], "-a") == 0) ) { actmode = 'a'; + actmode_str = "activated"; } else if( (strcmp(argv[0], "--deactivate") == 0) || (strcmp(argv[0], "-d") == 0) ) { actmode = 'd'; + actmode_str = "deactivated"; + } else if( (strcmp(argv[0], "--delete") == 0) || (strcmp(argv[0], "-D") == 0) ) { + actmode = 'D'; + actmode_str = "deleted"; } else { fprintf(stderr, "%s: System error - illegal users mode'%s'\n", MODULE, argv[0]); return 1; @@ -556,6 +561,9 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * tmp = xmlNewChild(update_n, NULL,(xmlChar *) "deactivated", NULL); xmlNewProp(tmp, (xmlChar *) "setnull", (xmlChar *) "1"); } + + // Do the update of the user account + rc = eDBadminUpdateUser(ctx, atoi_nullsafe(uid_str), update_xml); break; case 'd': // Deactivate a user account @@ -571,15 +579,25 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * fprintf(stderr, "%s: User account is not activated yet\n", MODULE); goto exit; } + + // Do the update of the user account + rc = eDBadminUpdateUser(ctx, atoi_nullsafe(uid_str), update_xml); + break; + + case 'D': // Delete user account + xmlFreeDoc(update_xml); // We need another XML doc to delete users + + eurephiaXML_CreateDoc(ctx, 1, "delete_user", &update_xml, &update_n); + xmlNewProp(update_n, (xmlChar *) "uid", (xmlChar *) uid_str); + + rc = eDBadminDeleteUser(ctx, atoi_nullsafe(uid_str), update_xml); break; } - // Do the update of the user account - rc = eDBadminUpdateUser(ctx, atoi_nullsafe(uid_str), update_xml); if( rc == 1 ) { - printf("User account is %s\n", (actmode == 'd' ? "deactivated" : "activated")); + printf("User account is %s\n", actmode_str); } else { - fprintf(stderr, "%s: Deactivating the user account failed\n", MODULE); + fprintf(stderr, "%s: Operation failed\n", MODULE); } exit: @@ -778,7 +796,7 @@ int cmd_Users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int break; case 'D': - // mode_fnc = delete_user; + mode_fnc = account_activation; break; default: break; |