aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-15 21:48:31 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-15 21:48:31 +0100
commit6c73aaff38819533c55aecc53487d53521915e91 (patch)
tree0d2c0f0893420f61101d9501303c6e0e0165113c
parent16e7f697f8064a4e5fc2f8e181fe6a7b9602b1b3 (diff)
downloadbusybox-w32-6c73aaff38819533c55aecc53487d53521915e91.tar.gz
busybox-w32-6c73aaff38819533c55aecc53487d53521915e91.tar.bz2
busybox-w32-6c73aaff38819533c55aecc53487d53521915e91.zip
cryptpw: support "rounds=NNNNNNN$" thing in salts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--loginutils/cryptpw.c6
-rwxr-xr-xtestsuite/cryptpw.tests28
2 files changed, 32 insertions, 2 deletions
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c
index 9f5f40686..d630231c6 100644
--- a/loginutils/cryptpw.c
+++ b/loginutils/cryptpw.c
@@ -35,7 +35,7 @@
35//usage: "[OPTIONS] [PASSWORD] [SALT]" 35//usage: "[OPTIONS] [PASSWORD] [SALT]"
36/* We do support -s, we just don't mention it */ 36/* We do support -s, we just don't mention it */
37//usage:#define cryptpw_full_usage "\n\n" 37//usage:#define cryptpw_full_usage "\n\n"
38//usage: "Crypt PASSWORD using crypt(3)\n" 38//usage: "Print crypt(3) hashed PASSWORD\n"
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" */
@@ -92,7 +92,8 @@ 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 char salt[MAX_PW_SALT_LEN]; 95 /* Supports: cryptpw -m sha256 PASS 'rounds=999999999$SALT' */
96 char salt[MAX_PW_SALT_LEN + sizeof("rounds=999999999$")];
96 char *salt_ptr; 97 char *salt_ptr;
97 char *password; 98 char *password;
98 const char *opt_m, *opt_S; 99 const char *opt_m, *opt_S;
@@ -122,6 +123,7 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
122 123
123 salt_ptr = crypt_make_pw_salt(salt, opt_m); 124 salt_ptr = crypt_make_pw_salt(salt, opt_m);
124 if (opt_S) 125 if (opt_S)
126 /* put user's data after the "$N$" prefix */
125 safe_strncpy(salt_ptr, opt_S, sizeof(salt) - (sizeof("$N$")-1)); 127 safe_strncpy(salt_ptr, opt_S, sizeof(salt) - (sizeof("$N$")-1));
126 128
127 xmove_fd(fd, STDIN_FILENO); 129 xmove_fd(fd, STDIN_FILENO);
diff --git a/testsuite/cryptpw.tests b/testsuite/cryptpw.tests
new file mode 100755
index 000000000..8ec476c9f
--- /dev/null
+++ b/testsuite/cryptpw.tests
@@ -0,0 +1,28 @@
1#!/bin/sh
2
3# Copyright 2017 by Denys Vlasenko <vda.linux@googlemail.com>
4# Licensed under GPLv2, see file LICENSE in this source tree.
5
6. ./testing.sh
7
8# testing "description" "command" "result" "infile" "stdin"
9
10optional USE_BB_CRYPT_SHA
11testing "cryptpw sha256" \
12 "cryptpw -m sha256 QWErty '123456789012345678901234567890'" \
13 '$5$1234567890123456$5DxfOCmU4vRhtzfsbdK.6wSGMwwVbac7ZkWwusb8Si7\n' "" ""
14
15testing "cryptpw sha256 rounds=99999" \
16 "cryptpw -m sha256 QWErty 'rounds=99999\$123456789012345678901234567890'" \
17 '$5$rounds=99999$1234567890123456$aYellycJGZM6AKyVzaQsSrDBdTixubtMnM6J.MN0xM8\n' "" ""
18
19testing "cryptpw sha512" \
20 "cryptpw -m sha512 QWErty '123456789012345678901234567890'" \
21 '$6$1234567890123456$KB7QqxFyqmJSWyQYcCuGeFukgz1bPQoipWZf7.9L7z3k8UNTXa6UikbKcUGDc2ANn7DOGmDaroxDgpK16w/RE0\n' "" ""
22
23testing "cryptpw sha512 rounds=99999" \
24 "cryptpw -m sha512 QWErty 'rounds=99999\$123456789012345678901234567890'" \
25 '$6$rounds=99999$1234567890123456$BfF6gD6ZjUmwawH5QaAglYAxtU./yvsz0fcQ464l49aMI2DZW3j5ri28CrxK7riPWNpLuUpfaIdY751SBYKUH.\n' "" ""
26SKIP=
27
28exit $FAILCOUNT