svn commit: trunk/busybox: include libbb loginutils networking

vda at busybox.net vda at busybox.net
Thu Jun 12 16:56:53 UTC 2008


Author: vda
Date: 2008-06-12 09:56:52 -0700 (Thu, 12 Jun 2008)
New Revision: 22308

Log:
make pw_encrypt() return malloc'ed string.

   text    data     bss     dec     hex filename
 759802     604    6684  767090   bb472 busybox_old
 759804     604    6676  767084   bb46c busybox_unstripped



Modified:
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/correct_password.c
   trunk/busybox/libbb/pw_encrypt.c
   trunk/busybox/loginutils/chpasswd.c
   trunk/busybox/loginutils/passwd.c
   trunk/busybox/loginutils/sulogin.c
   trunk/busybox/networking/httpd.c


Changeset:
Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/include/libbb.h	2008-06-12 16:56:52 UTC (rev 22308)
@@ -1031,7 +1031,7 @@
  */
 extern void setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw);
 extern int correct_password(const struct passwd *pw);
-/* Returns a ptr to static storage */
+/* Returns a malloced string */
 extern char *pw_encrypt(const char *clear, const char *salt, int cleanup);
 extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
 /* rnd is additional random input. New one is returned.

Modified: trunk/busybox/libbb/correct_password.c
===================================================================
--- trunk/busybox/libbb/correct_password.c	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/libbb/correct_password.c	2008-06-12 16:56:52 UTC (rev 22308)
@@ -40,6 +40,7 @@
 {
 	char *unencrypted, *encrypted;
 	const char *correct;
+	int r;
 #if ENABLE_FEATURE_SHADOWPASSWDS
 	/* Using _r function to avoid pulling in static buffers */
 	struct spwd spw;
@@ -72,6 +73,8 @@
 		return 0;
 	}
 	encrypted = pw_encrypt(unencrypted, correct, 1);
+	r = (strcmp(encrypted, correct) == 0);
+	free(encrypted);
 	memset(unencrypted, 0, strlen(unencrypted));
-	return strcmp(encrypted, correct) == 0;
+	return r;
 }

Modified: trunk/busybox/libbb/pw_encrypt.c
===================================================================
--- trunk/busybox/libbb/pw_encrypt.c	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/libbb/pw_encrypt.c	2008-06-12 16:56:52 UTC (rev 22308)
@@ -54,7 +54,7 @@
 
 char *pw_encrypt(const char *clear, const char *salt, int cleanup)
 {
-	static char *cipher;
+	char *encrypted;
 
 #if 0 /* was CONFIG_FEATURE_SHA1_PASSWORDS, but there is no such thing??? */
 	if (strncmp(salt, "$2$", 3) == 0) {
@@ -62,11 +62,10 @@
 	}
 #endif
 
-	free(cipher);
-	cipher = my_crypt(clear, salt);
+	encrypted = my_crypt(clear, salt);
 
 	if (cleanup)
 		my_crypt_cleanup();
 
-	return cipher;
+	return encrypted;
 }

Modified: trunk/busybox/loginutils/chpasswd.c
===================================================================
--- trunk/busybox/loginutils/chpasswd.c	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/loginutils/chpasswd.c	2008-06-12 16:56:52 UTC (rev 22308)
@@ -65,6 +65,7 @@
 			bb_info_msg("Password for '%s' changed", name);
 		logmode = LOGMODE_STDIO;
 		free(name);
+		free(pass);
 	}
 
 	return 0;

Modified: trunk/busybox/loginutils/passwd.c
===================================================================
--- trunk/busybox/loginutils/passwd.c	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/loginutils/passwd.c	2008-06-12 16:56:52 UTC (rev 22308)
@@ -16,22 +16,24 @@
 	char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */
 	char *orig = (char*)"";
 	char *newp = NULL;
-	char *cipher = NULL;
 	char *cp = NULL;
 	char *ret = NULL; /* failure so far */
 
 	if (myuid && pw->pw_passwd[0]) {
+		char *encrypted;
+
 		orig = bb_askpass(0, "Old password:"); /* returns ptr to static */
 		if (!orig)
 			goto err_ret;
-		cipher = pw_encrypt(orig, pw->pw_passwd, 1); /* returns ptr to static */
-		if (strcmp(cipher, pw->pw_passwd) != 0) {
+		encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */
+		if (strcmp(encrypted, pw->pw_passwd) != 0) {
 			syslog(LOG_WARNING, "incorrect password for '%s'",
 				pw->pw_name);
 			bb_do_delay(FAIL_DELAY);
 			puts("Incorrect password");
 			goto err_ret;
 		}
+		if (ENABLE_FEATURE_CLEAN_UP) free(encrypted);
 	}
 	orig = xstrdup(orig); /* or else bb_askpass() will destroy it */
 	newp = bb_askpass(0, "New password:"); /* returns ptr to static */
@@ -55,8 +57,8 @@
 		strcpy(salt, "$1$");
 		crypt_make_salt(salt + 3, 4, 0);
 	}
-	/* pw_encrypt returns ptr to static */
-	ret = xstrdup(pw_encrypt(newp, salt, 1));
+	/* pw_encrypt returns malloced str */
+	ret = pw_encrypt(newp, salt, 1);
 	/* whee, success! */
 
  err_ret:
@@ -64,7 +66,6 @@
 	if (ENABLE_FEATURE_CLEAN_UP) free(orig);
 	nuke_str(newp);
 	if (ENABLE_FEATURE_CLEAN_UP) free(newp);
-	nuke_str(cipher);
 	nuke_str(cp);
 	return ret;
 }

Modified: trunk/busybox/loginutils/sulogin.c
===================================================================
--- trunk/busybox/loginutils/sulogin.c	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/loginutils/sulogin.c	2008-06-12 16:56:52 UTC (rev 22308)
@@ -72,6 +72,9 @@
 #endif
 
 	while (1) {
+		char *encrypted;
+		int r;
+
 		/* cp points to a static buffer that is zeroed every time */
 		cp = bb_askpass(timeout,
 				"Give root password for system maintenance\n"
@@ -81,7 +84,10 @@
 			bb_info_msg("Normal startup");
 			return 0;
 		}
-		if (strcmp(pw_encrypt(cp, pwd->pw_passwd, 1), pwd->pw_passwd) == 0) {
+		encrypted = pw_encrypt(cp, pwd->pw_passwd, 1);
+		r = strcmp(encrypted, pwd->pw_passwd);
+		free(encrypted);
+		if (r == 0) {
 			break;
 		}
 		bb_do_delay(FAIL_DELAY);

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2008-06-12 16:55:59 UTC (rev 22307)
+++ trunk/busybox/networking/httpd.c	2008-06-12 16:56:52 UTC (rev 22308)
@@ -1721,7 +1721,6 @@
 			}
 
 			if (ENABLE_FEATURE_HTTPD_AUTH_MD5) {
-				char *cipher;
 				char *pp;
 
 				if (strncmp(p, request, u - request) != 0) {
@@ -1732,9 +1731,10 @@
 				if (pp && pp[1] == '$' && pp[2] == '1'
 				 && pp[3] == '$' && pp[4]
 				) {
-					pp++;
-					cipher = pw_encrypt(u+1, pp, 1);
-					if (strcmp(cipher, pp) == 0)
+					char *encrypted = pw_encrypt(u+1, ++pp, 1);
+					int r = strcmp(encrypted, pp);
+					free(encrypted);
+					if (r == 0)
 						goto set_remoteuser_var;   /* Ok */
 					/* unauthorized */
 					continue;




More information about the busybox-cvs mailing list