diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-21 13:25:28 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-21 13:25:28 +0000 |
| commit | 557fb713e0f943ac9b87c9f3804ba24e73d55bb0 (patch) | |
| tree | eda14f3179f0bddf125c2b8e8549cd6e35fa7242 /loginutils | |
| parent | 1ec5eaecba0a0323f214825b83fabcc18a41884d (diff) | |
| download | busybox-w32-557fb713e0f943ac9b87c9f3804ba24e73d55bb0.tar.gz busybox-w32-557fb713e0f943ac9b87c9f3804ba24e73d55bb0.tar.bz2 busybox-w32-557fb713e0f943ac9b87c9f3804ba24e73d55bb0.zip | |
chpasswd: fixes and code shrink
update_passwd 732 734 +2
chpasswd_main 318 292 -26
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-26) Total: -24 bytes
text data bss dec hex filename
781564 1168 11900 794632 c2008 busybox_old
781548 1168 11900 794616 c1ff8 busybox_unstripped
Diffstat (limited to 'loginutils')
| -rw-r--r-- | loginutils/chpasswd.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 124fc86e2..d5de424f0 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
| @@ -26,19 +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, rc; | 29 | int opt; |
| 30 | int rnd = rnd; /* we *want* it to be non-initialized! */ | 30 | int rnd = rnd; /* we *want* it to be non-initialized! */ |
| 31 | const char *pwfile = bb_path_passwd_file; | ||
| 32 | 31 | ||
| 33 | if (getuid() != 0) | 32 | if (getuid()) |
| 34 | 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); |
| 35 | 34 | ||
| 36 | #if ENABLE_FEATURE_SHADOWPASSWDS | 35 | opt_complementary = "?m--e:e--m"; |
| 37 | if (access(bb_path_shadow_file, F_OK) == 0) | ||
| 38 | pwfile = bb_path_shadow_file; | ||
| 39 | #endif | ||
| 40 | |||
| 41 | opt_complementary = "m--e"; | ||
| 42 | USE_GETOPT_LONG(applet_long_options = chpasswd_opts;) | 36 | USE_GETOPT_LONG(applet_long_options = chpasswd_opts;) |
| 43 | opt = getopt32(argc, argv, "em"); | 37 | opt = getopt32(argc, argv, "em"); |
| 44 | 38 | ||
| @@ -48,8 +42,7 @@ int chpasswd_main(int argc, char **argv) | |||
| 48 | bb_error_msg_and_die("missing new password"); | 42 | bb_error_msg_and_die("missing new password"); |
| 49 | *pass++ = '\0'; | 43 | *pass++ = '\0'; |
| 50 | 44 | ||
| 51 | //if (!getpwnam(name)) | 45 | xuname2uid(name); /* dies if there is no such user */ |
| 52 | // bb_error_msg_and_die("unknown user %s", name); | ||
| 53 | 46 | ||
| 54 | if (!(opt & OPT_ENC)) { | 47 | if (!(opt & OPT_ENC)) { |
| 55 | rnd = crypt_make_salt(salt, 1, rnd); | 48 | rnd = crypt_make_salt(salt, 1, rnd); |
| @@ -60,15 +53,17 @@ int chpasswd_main(int argc, char **argv) | |||
| 60 | pass = pw_encrypt(pass, salt); | 53 | pass = pw_encrypt(pass, salt); |
| 61 | } | 54 | } |
| 62 | 55 | ||
| 63 | rc = update_passwd(pwfile, name, pass); | ||
| 64 | /* LOGMODE_BOTH logs to syslog */ | 56 | /* LOGMODE_BOTH logs to syslog */ |
| 65 | logmode = LOGMODE_BOTH; | 57 | logmode = LOGMODE_BOTH; |
| 66 | if (rc < 0) | 58 | |
| 67 | bb_error_msg_and_die("an error occurred updating %s", pwfile); | 59 | if ((ENABLE_FEATURE_SHADOWPASSWDS |
| 68 | if (rc > 0) | 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); | ||
| 64 | } else { | ||
| 69 | bb_info_msg("Password for '%s' changed", name); | 65 | bb_info_msg("Password for '%s' changed", name); |
| 70 | else | 66 | } |
| 71 | bb_info_msg("User '%s' not found", name); | ||
| 72 | logmode = LOGMODE_STDIO; | 67 | logmode = LOGMODE_STDIO; |
| 73 | free(name); | 68 | free(name); |
| 74 | } | 69 | } |
