chpasswd: fixes for shadow password handling

This commit is contained in:
Denis Vlasenko 2007-07-21 13:54:26 +00:00
parent 091965768d
commit e8feca085d

View File

@ -26,13 +26,13 @@ int chpasswd_main(int argc, char **argv)
{ {
char *name, *pass; char *name, *pass;
char salt[sizeof("$N$XXXXXXXX")]; char salt[sizeof("$N$XXXXXXXX")];
int opt; int opt, rc;
int rnd = rnd; /* we *want* it to be non-initialized! */ int rnd = rnd; /* we *want* it to be non-initialized! */
if (getuid()) if (getuid())
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 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;) USE_GETOPT_LONG(applet_long_options = chpasswd_opts;)
opt = getopt32(argc, argv, "em"); opt = getopt32(argc, argv, "em");
@ -53,17 +53,19 @@ int chpasswd_main(int argc, char **argv)
pass = pw_encrypt(pass, salt); 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; logmode = LOGMODE_BOTH;
if (rc < 0)
if ((ENABLE_FEATURE_SHADOWPASSWDS
&& !update_passwd(bb_path_shadow_file, name, pass))
|| !update_passwd(bb_path_passwd_file, name, pass)
) {
bb_error_msg_and_die("an error occurred updating password for %s", name); bb_error_msg_and_die("an error occurred updating password for %s", name);
} else { if (rc)
bb_info_msg("Password for '%s' changed", name); bb_info_msg("Password for '%s' changed", name);
}
logmode = LOGMODE_STDIO; logmode = LOGMODE_STDIO;
free(name); free(name);
} }