summaryrefslogtreecommitdiff
path: root/loginutils/chpasswd.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-07-21 13:25:28 +0000
committerDenis Vlasenko2007-07-21 13:25:28 +0000
commit557fb713e0f943ac9b87c9f3804ba24e73d55bb0 (patch)
treeeda14f3179f0bddf125c2b8e8549cd6e35fa7242 /loginutils/chpasswd.c
parent1ec5eaecba0a0323f214825b83fabcc18a41884d (diff)
downloadbusybox-557fb713e0f943ac9b87c9f3804ba24e73d55bb0.zip
busybox-557fb713e0f943ac9b87c9f3804ba24e73d55bb0.tar.gz
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/chpasswd.c')
-rw-r--r--loginutils/chpasswd.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c
index 124fc86..d5de424 100644
--- a/loginutils/chpasswd.c
+++ b/loginutils/chpasswd.c
@@ -26,19 +26,13 @@ int chpasswd_main(int argc, char **argv)
{
char *name, *pass;
char salt[sizeof("$N$XXXXXXXX")];
- int opt, rc;
+ int opt;
int rnd = rnd; /* we *want* it to be non-initialized! */
- const char *pwfile = bb_path_passwd_file;
- if (getuid() != 0)
+ if (getuid())
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
-#if ENABLE_FEATURE_SHADOWPASSWDS
- if (access(bb_path_shadow_file, F_OK) == 0)
- pwfile = bb_path_shadow_file;
-#endif
-
- opt_complementary = "m--e";
+ opt_complementary = "?m--e:e--m";
USE_GETOPT_LONG(applet_long_options = chpasswd_opts;)
opt = getopt32(argc, argv, "em");
@@ -48,8 +42,7 @@ int chpasswd_main(int argc, char **argv)
bb_error_msg_and_die("missing new password");
*pass++ = '\0';
- //if (!getpwnam(name))
- // bb_error_msg_and_die("unknown user %s", name);
+ xuname2uid(name); /* dies if there is no such user */
if (!(opt & OPT_ENC)) {
rnd = crypt_make_salt(salt, 1, rnd);
@@ -60,15 +53,17 @@ int chpasswd_main(int argc, char **argv)
pass = pw_encrypt(pass, salt);
}
- rc = update_passwd(pwfile, name, pass);
/* LOGMODE_BOTH logs to syslog */
logmode = LOGMODE_BOTH;
- if (rc < 0)
- bb_error_msg_and_die("an error occurred updating %s", pwfile);
- 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);
+ } else {
bb_info_msg("Password for '%s' changed", name);
- else
- bb_info_msg("User '%s' not found", name);
+ }
logmode = LOGMODE_STDIO;
free(name);
}