diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-21 13:54:26 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-21 13:54:26 +0000 |
commit | e8feca085dbcd0fb97aa5af1a8e751affb88df48 (patch) | |
tree | b49bcdbc7af63d6437e503133f97d8261dcbba82 /loginutils/chpasswd.c | |
parent | 091965768da4175d3763e61db56bba058d68ae3b (diff) | |
download | busybox-w32-e8feca085dbcd0fb97aa5af1a8e751affb88df48.tar.gz busybox-w32-e8feca085dbcd0fb97aa5af1a8e751affb88df48.tar.bz2 busybox-w32-e8feca085dbcd0fb97aa5af1a8e751affb88df48.zip |
chpasswd: fixes for shadow password handling
Diffstat (limited to 'loginutils/chpasswd.c')
-rw-r--r-- | loginutils/chpasswd.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index d5de424f0..1f823179f 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
@@ -26,13 +26,13 @@ int chpasswd_main(int argc, char **argv) | |||
26 | { | 26 | { |
27 | char *name, *pass; | 27 | char *name, *pass; |
28 | char salt[sizeof("$N$XXXXXXXX")]; | 28 | char salt[sizeof("$N$XXXXXXXX")]; |
29 | int opt; | 29 | int opt, rc; |
30 | int rnd = rnd; /* we *want* it to be non-initialized! */ | 30 | int rnd = rnd; /* we *want* it to be non-initialized! */ |
31 | 31 | ||
32 | if (getuid()) | 32 | if (getuid()) |
33 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 33 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
34 | 34 | ||
35 | opt_complementary = "?m--e:e--m"; | 35 | opt_complementary = "m--e:e--m"; |
36 | USE_GETOPT_LONG(applet_long_options = chpasswd_opts;) | 36 | USE_GETOPT_LONG(applet_long_options = chpasswd_opts;) |
37 | opt = getopt32(argc, argv, "em"); | 37 | opt = getopt32(argc, argv, "em"); |
38 | 38 | ||
@@ -53,17 +53,19 @@ int chpasswd_main(int argc, char **argv) | |||
53 | pass = pw_encrypt(pass, salt); | 53 | pass = pw_encrypt(pass, salt); |
54 | } | 54 | } |
55 | 55 | ||
56 | /* LOGMODE_BOTH logs to syslog */ | 56 | /* This is rather complex: if user is not found in /etc/shadow, |
57 | * we try to find & change his passwd in /etc/passwd */ | ||
58 | #if ENABLE_FEATURE_SHADOWPASSWDS | ||
59 | rc = update_passwd(bb_path_shadow_file, name, pass); | ||
60 | if (rc == 0) /* no lines updated, no errors detected */ | ||
61 | #endif | ||
62 | rc = update_passwd(bb_path_passwd_file, name, pass); | ||
63 | /* LOGMODE_BOTH logs to syslog also */ | ||
57 | logmode = LOGMODE_BOTH; | 64 | logmode = LOGMODE_BOTH; |
58 | 65 | if (rc < 0) | |
59 | if ((ENABLE_FEATURE_SHADOWPASSWDS | ||
60 | && !update_passwd(bb_path_shadow_file, name, pass)) | ||
61 | || !update_passwd(bb_path_passwd_file, name, pass) | ||
62 | ) { | ||
63 | bb_error_msg_and_die("an error occurred updating password for %s", name); | 66 | bb_error_msg_and_die("an error occurred updating password for %s", name); |
64 | } else { | 67 | if (rc) |
65 | bb_info_msg("Password for '%s' changed", name); | 68 | bb_info_msg("Password for '%s' changed", name); |
66 | } | ||
67 | logmode = LOGMODE_STDIO; | 69 | logmode = LOGMODE_STDIO; |
68 | free(name); | 70 | free(name); |
69 | } | 71 | } |