diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-30 20:41:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-30 20:41:28 +0000 |
commit | 002526481eecee09222cc400ac728ee209b01336 (patch) | |
tree | be484f9a6c26894de89ba2ad84147d651197b3cb | |
parent | ab24e18c7a32ee1637be19f239e9dd9d7c7f6534 (diff) | |
download | busybox-w32-002526481eecee09222cc400ac728ee209b01336.tar.gz busybox-w32-002526481eecee09222cc400ac728ee209b01336.tar.bz2 busybox-w32-002526481eecee09222cc400ac728ee209b01336.zip |
passwd: small size optimization. salt generation improved
(really generated different salts even if called back-to-back).
-rw-r--r-- | Makefile.custom | 4 | ||||
-rw-r--r-- | libbb/pw_encrypt.c | 1 | ||||
-rw-r--r-- | loginutils/passwd.c | 50 |
3 files changed, 32 insertions, 23 deletions
diff --git a/Makefile.custom b/Makefile.custom index ce808196a..254279178 100644 --- a/Makefile.custom +++ b/Makefile.custom | |||
@@ -63,6 +63,10 @@ baseline: busybox_unstripped | |||
63 | objsizes: busybox_unstripped | 63 | objsizes: busybox_unstripped |
64 | $(srctree)/scripts/objsizes | 64 | $(srctree)/scripts/objsizes |
65 | 65 | ||
66 | .PHONY: bigdata | ||
67 | bigdata: busybox_unstripped | ||
68 | nm --size-sort busybox_unstripped | grep -vi ' [tr] ' | tail -20 | ||
69 | |||
66 | # Documentation Targets | 70 | # Documentation Targets |
67 | .PHONY: doc | 71 | .PHONY: doc |
68 | doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html | 72 | doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html |
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index f6085f3d2..d546bc883 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c | |||
@@ -8,7 +8,6 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include <string.h> | ||
12 | #include <crypt.h> | 11 | #include <crypt.h> |
13 | 12 | ||
14 | char *pw_encrypt(const char *clear, const char *salt) | 13 | char *pw_encrypt(const char *clear, const char *salt) |
diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 41033e51a..83c3a2d73 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c | |||
@@ -5,6 +5,7 @@ | |||
5 | 5 | ||
6 | #include "busybox.h" | 6 | #include "busybox.h" |
7 | #include <syslog.h> | 7 | #include <syslog.h> |
8 | #include <sys/times.h> /* times() */ | ||
8 | 9 | ||
9 | 10 | ||
10 | static void nuke_str(char *str) | 11 | static void nuke_str(char *str) |
@@ -19,28 +20,35 @@ static int i64c(int i) | |||
19 | return '.'; | 20 | return '.'; |
20 | if (i == 1) | 21 | if (i == 1) |
21 | return '/'; | 22 | return '/'; |
22 | if (i >= 2 && i < 12) | 23 | if (i < 12) |
23 | return ('0' - 2 + i); | 24 | return ('0' - 2 + i); |
24 | if (i >= 12 && i < 38) | 25 | if (i < 38) |
25 | return ('A' - 12 + i); | 26 | return ('A' - 12 + i); |
26 | if (i >= 38 && i < 63) | 27 | return ('a' - 38 + i); |
27 | return ('a' - 38 + i); | ||
28 | return 'z'; | ||
29 | } | 28 | } |
30 | 29 | ||
31 | 30 | ||
32 | static char *crypt_make_salt(void) | 31 | static void crypt_make_salt(char *p, int cnt) |
33 | { | 32 | { |
34 | time_t now; | 33 | #if !defined(__GLIBC__) |
35 | static unsigned long x; | 34 | struct tms t; |
36 | static char result[3]; | 35 | #define TIMES times(&t) |
37 | 36 | #else | |
38 | time(&now); | 37 | /* glibc allows for times(NULL) a-la time() */ |
39 | x += now + getpid() + clock(); | 38 | #define TIMES times(NULL) |
40 | result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077); | 39 | #endif |
41 | result[1] = i64c(((x >> 12) ^ x) & 077); | 40 | unsigned long x = x; /* it's pointless to initialize it anyway :) */ |
42 | result[2] = '\0'; | 41 | |
43 | return result; | 42 | x += getpid(); |
43 | do { | ||
44 | /* clock() and times() variability is different between systems */ | ||
45 | /* hopefully at least one is good enough */ | ||
46 | x += time(NULL) + clock() + TIMES; | ||
47 | *p++ = i64c(((x >> 18) ^ (x >> 6)) & 0x3f); | ||
48 | *p++ = i64c(((x >> 12) ^ x) & 0x3f); | ||
49 | usleep(100); /* or else time() etc won't change */ | ||
50 | } while (--cnt); | ||
51 | *p = '\0'; | ||
44 | } | 52 | } |
45 | 53 | ||
46 | 54 | ||
@@ -88,14 +96,12 @@ static char* new_password(const struct passwd *pw, const char *old_crypted, | |||
88 | goto err_ret; | 96 | goto err_ret; |
89 | } | 97 | } |
90 | 98 | ||
91 | memset(salt, 0, sizeof(salt)); | 99 | /*memset(salt, 0, sizeof(salt)); - why?*/ |
92 | if (algo == 1) { /* MD5 */ | 100 | crypt_make_salt(salt, 1); /* des */ |
101 | if (algo) { /* MD5 */ | ||
93 | strcpy(salt, "$1$"); | 102 | strcpy(salt, "$1$"); |
94 | strcat(salt, crypt_make_salt()); | 103 | crypt_make_salt(salt + 3, 4); |
95 | strcat(salt, crypt_make_salt()); | ||
96 | strcat(salt, crypt_make_salt()); | ||
97 | } | 104 | } |
98 | strcat(salt, crypt_make_salt()); | ||
99 | ret = xstrdup(pw_encrypt(newp, salt)); /* returns ptr to static */ | 105 | ret = xstrdup(pw_encrypt(newp, salt)); /* returns ptr to static */ |
100 | /* whee, success! */ | 106 | /* whee, success! */ |
101 | 107 | ||