aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-11-19 13:36:45 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-11-19 13:36:45 +0100
commit8b59b2c13ededb2c82e36193b6d6e969df36531c (patch)
tree7b5065279d3c5a6c8bd0ca90584d49bb73aac01c
parent6ef77291122d231754e7292630681dc67c109d60 (diff)
downloadbusybox-w32-8b59b2c13ededb2c82e36193b6d6e969df36531c.tar.gz
busybox-w32-8b59b2c13ededb2c82e36193b6d6e969df36531c.tar.bz2
busybox-w32-8b59b2c13ededb2c82e36193b6d6e969df36531c.zip
libbb: move nuke_str() from passwd into libbb
function old new delta nuke_str - 15 +15 ask_and_check_password_extended 215 206 -9 init_main 781 771 -10 nuke_str 27 - -27 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 15/-46) Total: -31 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h7
-rw-r--r--init/init.c2
-rw-r--r--libbb/correct_password.c11
-rw-r--r--loginutils/passwd.c5
4 files changed, 15 insertions, 10 deletions
diff --git a/include/libbb.h b/include/libbb.h
index e99bb928f..64167bba3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1300,9 +1300,10 @@ int sd_listen_fds(void);
1300#define SETUP_ENV_CLEARENV (1 << 1) 1300#define SETUP_ENV_CLEARENV (1 << 1)
1301#define SETUP_ENV_TO_TMP (1 << 2) 1301#define SETUP_ENV_TO_TMP (1 << 2)
1302#define SETUP_ENV_NO_CHDIR (1 << 4) 1302#define SETUP_ENV_NO_CHDIR (1 << 4)
1303extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1303void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
1304extern int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; 1304void nuke_str(char *str) FAST_FUNC;
1305extern int ask_and_check_password(const struct passwd *pw) FAST_FUNC; 1305int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
1306int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
1306/* Returns a malloced string */ 1307/* Returns a malloced string */
1307#if !ENABLE_USE_BB_CRYPT 1308#if !ENABLE_USE_BB_CRYPT
1308#define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt) 1309#define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt)
diff --git a/init/init.c b/init/init.c
index 2dcdfd471..c63bba1ff 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1128,7 +1128,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
1128 strncpy(argv[0], "init", strlen(argv[0])); 1128 strncpy(argv[0], "init", strlen(argv[0]));
1129 /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ 1129 /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
1130 while (*++argv) 1130 while (*++argv)
1131 memset(*argv, 0, strlen(*argv)); 1131 nuke_str(*argv);
1132 1132
1133 /* Set up signal handlers */ 1133 /* Set up signal handlers */
1134 if (!DEBUG_INIT) { 1134 if (!DEBUG_INIT) {
diff --git a/libbb/correct_password.c b/libbb/correct_password.c
index d39a5839c..5727c65fb 100644
--- a/libbb/correct_password.c
+++ b/libbb/correct_password.c
@@ -30,6 +30,15 @@
30 30
31#include "libbb.h" 31#include "libbb.h"
32 32
33void FAST_FUNC nuke_str(char *str)
34{
35 if (str) {
36 while (*str)
37 *str++ = 0;
38 /* or: memset(str, 0, strlen(str)); - not as small as above */
39 }
40}
41
33/* Ask the user for a password. 42/* Ask the user for a password.
34 * Return 1 without asking if PW has an empty password. 43 * Return 1 without asking if PW has an empty password.
35 * Return -1 on EOF, error while reading input, or timeout. 44 * Return -1 on EOF, error while reading input, or timeout.
@@ -76,7 +85,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw,
76 encrypted = pw_encrypt(unencrypted, correct, 1); 85 encrypted = pw_encrypt(unencrypted, correct, 1);
77 r = (strcmp(encrypted, correct) == 0); 86 r = (strcmp(encrypted, correct) == 0);
78 free(encrypted); 87 free(encrypted);
79 memset(unencrypted, 0, strlen(unencrypted)); 88 nuke_str(unencrypted);
80 return r; 89 return r;
81} 90}
82 91
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index a7006f054..150908932 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -17,11 +17,6 @@
17#include <syslog.h> 17#include <syslog.h>
18#include <sys/resource.h> /* setrlimit */ 18#include <sys/resource.h> /* setrlimit */
19 19
20static void nuke_str(char *str)
21{
22 if (str) memset(str, 0, strlen(str));
23}
24
25static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo) 20static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo)
26{ 21{
27 char salt[MAX_PW_SALT_LEN]; 22 char salt[MAX_PW_SALT_LEN];