mirror of
https://github.com/sheumann/hush.git
synced 2024-12-21 23:29:34 +00:00
chpasswd: fixes for shadow password handling
This commit is contained in:
parent
091965768d
commit
e8feca085d
@ -26,13 +26,13 @@ int chpasswd_main(int argc, char **argv)
|
||||
{
|
||||
char *name, *pass;
|
||||
char salt[sizeof("$N$XXXXXXXX")];
|
||||
int opt;
|
||||
int opt, rc;
|
||||
int rnd = rnd; /* we *want* it to be non-initialized! */
|
||||
|
||||
if (getuid())
|
||||
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
|
||||
|
||||
opt_complementary = "?m--e:e--m";
|
||||
opt_complementary = "m--e:e--m";
|
||||
USE_GETOPT_LONG(applet_long_options = chpasswd_opts;)
|
||||
opt = getopt32(argc, argv, "em");
|
||||
|
||||
@ -53,17 +53,19 @@ int chpasswd_main(int argc, char **argv)
|
||||
pass = pw_encrypt(pass, salt);
|
||||
}
|
||||
|
||||
/* LOGMODE_BOTH logs to syslog */
|
||||
/* This is rather complex: if user is not found in /etc/shadow,
|
||||
* we try to find & change his passwd in /etc/passwd */
|
||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
||||
rc = update_passwd(bb_path_shadow_file, name, pass);
|
||||
if (rc == 0) /* no lines updated, no errors detected */
|
||||
#endif
|
||||
rc = update_passwd(bb_path_passwd_file, name, pass);
|
||||
/* LOGMODE_BOTH logs to syslog also */
|
||||
logmode = LOGMODE_BOTH;
|
||||
|
||||
if ((ENABLE_FEATURE_SHADOWPASSWDS
|
||||
&& !update_passwd(bb_path_shadow_file, name, pass))
|
||||
|| !update_passwd(bb_path_passwd_file, name, pass)
|
||||
) {
|
||||
if (rc < 0)
|
||||
bb_error_msg_and_die("an error occurred updating password for %s", name);
|
||||
} else {
|
||||
if (rc)
|
||||
bb_info_msg("Password for '%s' changed", name);
|
||||
}
|
||||
logmode = LOGMODE_STDIO;
|
||||
free(name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user