diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-13 03:19:01 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-13 03:19:01 +0200 |
commit | 12a432715f066cf9d677316a39c9e0ebc6d72404 (patch) | |
tree | 14a33cdedbd6ba7739449cc3dec968b55a01efad /loginutils/chpasswd.c | |
parent | 0806e401d6747c391fa0427e0ccba9951f9a1c3d (diff) | |
download | busybox-w32-12a432715f066cf9d677316a39c9e0ebc6d72404.tar.gz busybox-w32-12a432715f066cf9d677316a39c9e0ebc6d72404.tar.bz2 busybox-w32-12a432715f066cf9d677316a39c9e0ebc6d72404.zip |
adduser: safe username passing to passwd/addgroup
passwd: support creating SHA passwords
random code shrink
function old new delta
crypt_make_pw_salt - 87 +87
adduser_main 883 904 +21
...
crypt_make_salt 99 89 -10
chpasswd_main 329 312 -17
packed_usage 28731 28691 -40
passwd_main 1070 1000 -70
cryptpw_main 310 224 -86
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/12 up/down: 154/-288) Total: -134 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'loginutils/chpasswd.c')
-rw-r--r-- | loginutils/chpasswd.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 6c4296faa..f4718c829 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
@@ -37,9 +37,8 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
37 | char *name, *pass; | 37 | char *name, *pass; |
38 | char salt[sizeof("$N$XXXXXXXX")]; | 38 | char salt[sizeof("$N$XXXXXXXX")]; |
39 | int opt, rc; | 39 | int opt, rc; |
40 | int rnd = rnd; /* we *want* it to be non-initialized! */ | ||
41 | 40 | ||
42 | if (getuid()) | 41 | if (getuid() != 0) |
43 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 42 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
44 | 43 | ||
45 | opt_complementary = "m--e:e--m"; | 44 | opt_complementary = "m--e:e--m"; |
@@ -55,10 +54,12 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
55 | xuname2uid(name); /* dies if there is no such user */ | 54 | xuname2uid(name); /* dies if there is no such user */ |
56 | 55 | ||
57 | if (!(opt & OPT_ENC)) { | 56 | if (!(opt & OPT_ENC)) { |
58 | rnd = crypt_make_salt(salt, 1, rnd); | 57 | crypt_make_salt(salt, 1); |
59 | if (opt & OPT_MD5) { | 58 | if (opt & OPT_MD5) { |
60 | strcpy(salt, "$1$"); | 59 | salt[0] = '$'; |
61 | rnd = crypt_make_salt(salt + 3, 4, rnd); | 60 | salt[1] = '1'; |
61 | salt[2] = '$'; | ||
62 | crypt_make_salt(salt + 3, 4); | ||
62 | } | 63 | } |
63 | pass = pw_encrypt(pass, salt, 0); | 64 | pass = pw_encrypt(pass, salt, 0); |
64 | } | 65 | } |