summaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-12 16:55:59 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-12 16:55:59 +0000
commit4ea83bf562c44a6792e7c77e7d87cba91f86f763 (patch)
tree64dba9163b29724e282c1e94027001a11978e74b /loginutils
parent9de462205542547694299e9fe2bc321088ab79aa (diff)
downloadbusybox-w32-4ea83bf562c44a6792e7c77e7d87cba91f86f763.tar.gz
busybox-w32-4ea83bf562c44a6792e7c77e7d87cba91f86f763.tar.bz2
busybox-w32-4ea83bf562c44a6792e7c77e7d87cba91f86f763.zip
uclibc insists on having 70k static buffer for crypt.
For bbox it's not acceptable. Roll our own des and md5 crypt implementation. Against older uclibc: text data bss dec hex filename 759945 604 6684 767233 bb501 busybox_old 759766 604 6684 767054 bb44e busybox_unstripped so, we still save on code size.
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/chpasswd.c2
-rw-r--r--loginutils/cryptpw.c32
-rw-r--r--loginutils/passwd.c4
-rw-r--r--loginutils/sulogin.c2
4 files changed, 35 insertions, 5 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c
index 5dc7a9bf0..230ab0fc9 100644
--- a/loginutils/chpasswd.c
+++ b/loginutils/chpasswd.c
@@ -47,7 +47,7 @@ int chpasswd_main(int argc ATTRIBUTE_UNUSED, char **argv)
47 strcpy(salt, "$1$"); 47 strcpy(salt, "$1$");
48 rnd = crypt_make_salt(salt + 3, 4, rnd); 48 rnd = crypt_make_salt(salt + 3, 4, rnd);
49 } 49 }
50 pass = pw_encrypt(pass, salt); 50 pass = pw_encrypt(pass, salt, 0);
51 } 51 }
52 52
53 /* This is rather complex: if user is not found in /etc/shadow, 53 /* This is rather complex: if user is not found in /etc/shadow,
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c
index 68f5e8074..1acbc6db0 100644
--- a/loginutils/cryptpw.c
+++ b/loginutils/cryptpw.c
@@ -7,6 +7,30 @@
7 7
8#include "libbb.h" 8#include "libbb.h"
9 9
10#define TESTING 0
11
12/*
13set TESTING to 1 and pipe some file through this script
14if you played with bbox's crypt implementation.
15
16while read line; do
17 n=`./busybox cryptpw -a des -- "$line"`
18 o=`./busybox_old cryptpw -a des -- "$line"`
19 test "$n" != "$o" && {
20 echo n="$n"
21 echo o="$o"
22 exit
23 }
24 n=`./busybox cryptpw -- "$line"`
25 o=`./busybox_old cryptpw -- "$line"`
26 test "$n" != "$o" && {
27 echo n="$n"
28 echo o="$o"
29 exit
30 }
31done
32 */
33
10int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 34int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
11int cryptpw_main(int argc ATTRIBUTE_UNUSED, char **argv) 35int cryptpw_main(int argc ATTRIBUTE_UNUSED, char **argv)
12{ 36{
@@ -18,11 +42,17 @@ int cryptpw_main(int argc ATTRIBUTE_UNUSED, char **argv)
18 //((uint32_t*)&salt)[0] = '$' + '1'*0x100 + '$'*0x10000; 42 //((uint32_t*)&salt)[0] = '$' + '1'*0x100 + '$'*0x10000;
19 /* Hope one day gcc will do it itself (inlining strcpy) */ 43 /* Hope one day gcc will do it itself (inlining strcpy) */
20 crypt_make_salt(salt + 3, 4, 0); /* md5 */ 44 crypt_make_salt(salt + 3, 4, 0); /* md5 */
45#if TESTING
46 strcpy(salt + 3, "ajg./bcf");
47#endif
21 } else { 48 } else {
22 crypt_make_salt(salt, 1, 0); /* des */ 49 crypt_make_salt(salt, 1, 0); /* des */
50#if TESTING
51 strcpy(salt, "a.");
52#endif
23 } 53 }
24 54
25 puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_fgetline(stdin), salt)); 55 puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_fgetline(stdin), salt, 1));
26 56
27 return 0; 57 return 0;
28} 58}
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index 3353db1fa..fad226c00 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -24,7 +24,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, int algo)
24 orig = bb_askpass(0, "Old password:"); /* returns ptr to static */ 24 orig = bb_askpass(0, "Old password:"); /* returns ptr to static */
25 if (!orig) 25 if (!orig)
26 goto err_ret; 26 goto err_ret;
27 cipher = pw_encrypt(orig, pw->pw_passwd); /* returns ptr to static */ 27 cipher = pw_encrypt(orig, pw->pw_passwd, 1); /* returns ptr to static */
28 if (strcmp(cipher, pw->pw_passwd) != 0) { 28 if (strcmp(cipher, pw->pw_passwd) != 0) {
29 syslog(LOG_WARNING, "incorrect password for '%s'", 29 syslog(LOG_WARNING, "incorrect password for '%s'",
30 pw->pw_name); 30 pw->pw_name);
@@ -56,7 +56,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, int algo)
56 crypt_make_salt(salt + 3, 4, 0); 56 crypt_make_salt(salt + 3, 4, 0);
57 } 57 }
58 /* pw_encrypt returns ptr to static */ 58 /* pw_encrypt returns ptr to static */
59 ret = xstrdup(pw_encrypt(newp, salt)); 59 ret = xstrdup(pw_encrypt(newp, salt, 1));
60 /* whee, success! */ 60 /* whee, success! */
61 61
62 err_ret: 62 err_ret:
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 17bb15efa..f52ce8a95 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -81,7 +81,7 @@ int sulogin_main(int argc ATTRIBUTE_UNUSED, char **argv)
81 bb_info_msg("Normal startup"); 81 bb_info_msg("Normal startup");
82 return 0; 82 return 0;
83 } 83 }
84 if (strcmp(pw_encrypt(cp, pwd->pw_passwd), pwd->pw_passwd) == 0) { 84 if (strcmp(pw_encrypt(cp, pwd->pw_passwd, 1), pwd->pw_passwd) == 0) {
85 break; 85 break;
86 } 86 }
87 bb_do_delay(FAIL_DELAY); 87 bb_do_delay(FAIL_DELAY);