aboutsummaryrefslogtreecommitdiff
path: root/loginutils/cryptpw.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-05-13 03:19:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-05-13 03:19:01 +0200
commit12a432715f066cf9d677316a39c9e0ebc6d72404 (patch)
tree14a33cdedbd6ba7739449cc3dec968b55a01efad /loginutils/cryptpw.c
parent0806e401d6747c391fa0427e0ccba9951f9a1c3d (diff)
downloadbusybox-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/cryptpw.c')
-rw-r--r--loginutils/cryptpw.c27
1 files changed, 5 insertions, 22 deletions
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c
index bbaa858da..b25a39ac9 100644
--- a/loginutils/cryptpw.c
+++ b/loginutils/cryptpw.c
@@ -19,7 +19,7 @@
19//usage: IF_LONG_OPTS( 19//usage: IF_LONG_OPTS(
20//usage: "\n -P,--password-fd=N Read password from fd N" 20//usage: "\n -P,--password-fd=N Read password from fd N"
21/* //usage: "\n -s,--stdin Use stdin; like -P0" */ 21/* //usage: "\n -s,--stdin Use stdin; like -P0" */
22//usage: "\n -m,--method=TYPE Encryption method TYPE" 22//usage: "\n -m,--method=TYPE Encryption method"
23//usage: "\n -S,--salt=SALT" 23//usage: "\n -S,--salt=SALT"
24//usage: ) 24//usage: )
25//usage: IF_NOT_LONG_OPTS( 25//usage: IF_NOT_LONG_OPTS(
@@ -39,7 +39,7 @@
39//usage: IF_LONG_OPTS( 39//usage: IF_LONG_OPTS(
40//usage: "\n -P,--password-fd=N Read password from fd N" 40//usage: "\n -P,--password-fd=N Read password from fd N"
41/* //usage: "\n -s,--stdin Use stdin; like -P0" */ 41/* //usage: "\n -s,--stdin Use stdin; like -P0" */
42//usage: "\n -m,--method=TYPE Encryption method TYPE" 42//usage: "\n -m,--method=TYPE Encryption method"
43//usage: "\n -S,--salt=SALT" 43//usage: "\n -S,--salt=SALT"
44//usage: ) 44//usage: )
45//usage: IF_NOT_LONG_OPTS( 45//usage: IF_NOT_LONG_OPTS(
@@ -92,11 +92,9 @@ to cryptpw. -a option (alias for -m) came from cryptpw.
92int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 92int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
93int cryptpw_main(int argc UNUSED_PARAM, char **argv) 93int cryptpw_main(int argc UNUSED_PARAM, char **argv)
94{ 94{
95 /* $N$ + sha_salt_16_bytes + NUL */ 95 char salt[MAX_PW_SALT_LEN];
96 char salt[3 + 16 + 1];
97 char *salt_ptr; 96 char *salt_ptr;
98 const char *opt_m, *opt_S; 97 const char *opt_m, *opt_S;
99 int len;
100 int fd; 98 int fd;
101 99
102#if ENABLE_LONG_OPTS 100#if ENABLE_LONG_OPTS
@@ -121,24 +119,9 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
121 if (argv[0] && !opt_S) 119 if (argv[0] && !opt_S)
122 opt_S = argv[1]; 120 opt_S = argv[1];
123 121
124 len = 2/2; 122 salt_ptr = crypt_make_pw_salt(salt, opt_m);
125 salt_ptr = salt;
126 if (opt_m[0] != 'd') { /* not des */
127 len = 8/2; /* so far assuming md5 */
128 *salt_ptr++ = '$';
129 *salt_ptr++ = '1';
130 *salt_ptr++ = '$';
131#if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
132 if (opt_m[0] == 's') { /* sha */
133 salt[1] = '5' + (strcmp(opt_m, "sha512") == 0);
134 len = 16/2;
135 }
136#endif
137 }
138 if (opt_S) 123 if (opt_S)
139 safe_strncpy(salt_ptr, opt_S, sizeof(salt) - 3); 124 safe_strncpy(salt_ptr, opt_S, sizeof(salt) - (sizeof("$N$")-1));
140 else
141 crypt_make_salt(salt_ptr, len, 0);
142 125
143 xmove_fd(fd, STDIN_FILENO); 126 xmove_fd(fd, STDIN_FILENO);
144 127