[Pkg-shadow-commits] r2428 - in upstream/trunk: . src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sat Sep 20 19:44:14 UTC 2008


Author: nekral-guest
Date: 2008-09-20 19:44:12 +0000 (Sat, 20 Sep 2008)
New Revision: 2428

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/login.c
Log:
	* src/login.c: Use a dynamic buffer for usernames.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-09-20 16:23:04 UTC (rev 2427)
+++ upstream/trunk/ChangeLog	2008-09-20 19:44:12 UTC (rev 2428)
@@ -1,5 +1,9 @@
 2008-09-20  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/login.c: Use a dynamic buffer for usernames.
+
+2008-09-20  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/login.c: Existence of pam_user was already checked. pwd was
 	already copied to pwent. Remove duplicated code.
 

Modified: upstream/trunk/src/login.c
===================================================================
--- upstream/trunk/src/login.c	2008-09-20 16:23:04 UTC (rev 2427)
+++ upstream/trunk/src/login.c	2008-09-20 19:44:12 UTC (rev 2428)
@@ -81,7 +81,7 @@
 char *Prog;
 
 static const char *hostname = "";
-static char username[32];
+static char *username = NULL;
 static int reason = PW_LOGIN;
 
 static struct passwd pwent;
@@ -248,8 +248,6 @@
 	int arg;
 	int flag;
 
-	username[0] = '\0';
-
 	/*
 	 * Check the flags for proper form. Every argument starting with
 	 * "-" must be exactly two characters long. This closes all the
@@ -286,7 +284,7 @@
 			}
 			fflg = true;
 			if (optarg) {
-				STRFCPY (username, optarg);
+				username = xstrdup (optarg);
 			}
 			break;
 		case 'h':
@@ -332,11 +330,11 @@
 	 *  Get the user name.
 	 */
 	if (optind < argc) {
-		if (rflg || (fflg && ('\0' != username[0]))) {
+		if (rflg || (fflg && (NULL != username))) {
 			usage ();
 		}
 
-		STRFCPY (username, argv[optind]);
+		username = xstrdup (argv[optind]);
 		strzero (argv[optind]);
 		++optind;
 	}
@@ -529,10 +527,14 @@
 		reason = PW_RLOGIN;
 	}
 #ifdef RLOGIN
-	if (   rflg
-	    && do_rlogin (hostname, username, sizeof username,
-	                  term, sizeof term)) {
-		preauth_flag = true;
+	if (rflg) {
+		username = malloc (32 * sizeof char);
+		if (do_rlogin (hostname, username, 32, term, sizeof term)) {
+			preauth_flag = true;
+		} else {
+			free (username);
+			username = NULL;
+		}
 	}
 #endif
 
@@ -813,15 +815,21 @@
 #else				/* ! USE_PAM */
 	while (true) {	/* repeatedly get login/password pairs */
 		failed = false;	/* haven't failed authentication yet */
-		if ('\0' == username[0]) {	/* need to get a login id */
+		if (NULL == username) {	/* need to get a login id */
 			if (subroot) {
 				closelog ();
 				exit (1);
 			}
 			preauth_flag = false;
-			login_prompt (_("\n%s login: "), username,
-			              sizeof username);
-			continue;
+			username = malloc (32);
+			login_prompt (_("\n%s login: "), username, 32);
+
+			if ('\0' == username) {
+				/* Prompt for a new login */
+				free (username);
+				username = NULL;
+				continue;
+			}
 		}
 
 		pwd = xgetpwnam (username);
@@ -953,7 +961,8 @@
 			failent.ut_type = USER_PROCESS;
 			failtmp (&failent);
 		}
-		memzero (username, sizeof username);
+		free (username);
+		username = NULL;
 
 		retries--;
 		if (retries <= 0) {




More information about the Pkg-shadow-commits mailing list