diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-19 23:34:55 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-19 23:34:55 +0100 |
commit | 4dbdbd2f2039cec7ba1475bea4a4dd4021bdb9db (patch) | |
tree | fd20b5042e2ddfb87876b694a400769b09129e9d /eurephiadm | |
parent | 25d26c56970d9ff18b3b9c33f7130052e4dec23a (diff) | |
download | eurephia-4dbdbd2f2039cec7ba1475bea4a4dd4021bdb9db.tar.gz eurephia-4dbdbd2f2039cec7ba1475bea4a4dd4021bdb9db.tar.xz eurephia-4dbdbd2f2039cec7ba1475bea4a4dd4021bdb9db.zip |
users command: Added support for --password, to change a users password
Diffstat (limited to 'eurephiadm')
-rw-r--r-- | eurephiadm/commands/users.c | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c index 50f9790..38d84db 100644 --- a/eurephiadm/commands/users.c +++ b/eurephiadm/commands/users.c @@ -563,12 +563,13 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int 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, *actmode_str = NULL; + char *uid_str = NULL, *activated = NULL, *deactivated = NULL, *actmode_str = NULL, *newpwd = NULL; int i, actmode = 0, rc = 0, crit_set = 0; e_options activargs[] = { {"--uid", "-i", 1}, {"--username", "-u", 1}, + {"--new-password", "-P", 1}, {"--help", "-h", 0}, {NULL, NULL, 0} }; @@ -584,6 +585,9 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * } else if( (strcmp(argv[0], "--delete") == 0) || (strcmp(argv[0], "-D") == 0) ) { actmode = 'D'; actmode_str = "deleted"; + } else if( (strcmp(argv[0], "--password") == 0) || (strcmp(argv[0], "-p") == 0) ) { + actmode = 'p'; + actmode_str = "updated with new password"; } else { fprintf(stderr, "%s: System error - illegal users mode'%s'\n", MODULE, argv[0]); return 1; @@ -619,6 +623,10 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * display_users_help(actmode); return 0; + case 'P': + newpwd = strdup_nullsafe(optargs[0]); + break; + default: return 1; } @@ -706,6 +714,46 @@ int account_activation(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES * rc = eDBadminUpdateUser(ctx, atoi_nullsafe(uid_str), update_xml); break; + case 'p': // Change password for a user + + // If we do not have a password .... ask for password via console + if( newpwd == NULL ) { + char *chkpwd = NULL; + + newpwd = (char *) malloc(66); + assert(newpwd != NULL); + memset(newpwd, 0, 66); + + chkpwd = (char *) malloc(66); + assert(chkpwd != NULL); + memset(chkpwd, 0, 66); + + get_console_input(newpwd, 64, "Password for user:", 1); + if( strlen_nullsafe(newpwd) < 4 ) { + free_nullsafe(newpwd); + free_nullsafe(chkpwd); + fprintf(stderr, "%s: Password is too short\n", MODULE); + goto exit; + } + + get_console_input(chkpwd, 64, "Verify password for user:", 1); + if( strcmp(newpwd, chkpwd) != 0 ) { + free_nullsafe(newpwd); + free_nullsafe(chkpwd); + fprintf(stderr, "%s: Passwords didn't match\n", MODULE); + goto exit; + } + free_nullsafe(chkpwd); + } + + // Update with new password + tmp = xmlNewChild(update_n, NULL, (xmlChar *) "password", (xmlChar *)newpwd); + xmlNewProp(tmp, (xmlChar *) "pwhash", (xmlChar *) "none"); + rc = eDBadminUpdateUser(ctx, atoi_nullsafe(uid_str), update_xml); + + free_nullsafe(newpwd); + break; + case 'D': // Delete user account xmlFreeDoc(update_xml); // We need another XML doc to delete users @@ -921,6 +969,11 @@ int cmd_Users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int case 'D': mode_fnc = account_activation; break; + + case 'p': + mode_fnc = account_activation; + break; + default: break; } |