All,

In attach a patch which make the entire things actually smaller ;), login.c used a function to read a password which was virtually identical to a more globally defined function in lib/password.c, so I removed the one in login.c and made use of the function defined elsewhere.

Some comments not in this patch here, but these a trivial whitespace fixes.
- lib/password.c needs a spaces to tab fix.
- lib/password.c has a wrong filename in the header comment.
- lib/passwd.c also needs a spaces to tab fix.

gr
E.
--
Elie De Brauwer

# HG changeset patch
# User Elie De Brauwer <[email protected]>
# Date 1342766564 -7200
# Node ID 98bde84a888c8b4136921b2ee21b0227d818f2f1
# Parent  6cafecf3472844cf471083bcdb3aff977c77f0e3
toys/login.c: make use of the read_passwd function offered by the passwd library.

diff -r 6cafecf34728 -r 98bde84a888c toys/login.c
--- a/toys/login.c	Wed Jul 18 21:10:57 2012 -0500
+++ b/toys/login.c	Fri Jul 20 08:42:44 2012 +0200
@@ -67,49 +67,11 @@
 	} while (*p);
 }
 
-int read_password(char * buff, int buflen)
-{
-	int i = 0;
-	struct termios termio, oldtermio;
-	tcgetattr(0, &oldtermio);
-	tcflush(0, TCIFLUSH);
-	termio = oldtermio;
-
-	termio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
-	termio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
-	tcsetattr(0, TCSANOW, &termio);
-
-	fputs("Password: ", stdout);
-	fflush(stdout);
-
-	while (1) {
-		int ret = read(0, &buff[i], 1);
-		if ( ret < 0 )
-		{
-			buff[0] = 0;
-			tcsetattr(0, TCSANOW, &oldtermio);
-			return 1;
-		}
-		else if ( ret == 0 || buff[i] == '\n' ||
-				  buff[i] == '\r' || buflen == i+1)
-		{
-			buff[i] = '\0';
-			break;
-		}
-		i++;
-	}
-
-	tcsetattr(0, TCSANOW, &oldtermio);
-	puts("\n");
-	fflush(stdout);
-	return 0;
-}
-
 int verify_password(char * pwd)
 {
 	char * pass;
 
-	if (read_password(toybuf, sizeof(toybuf)))
+	if (read_passwd(toybuf, sizeof(toybuf), "Password: "))
 		return 1;
 	if (!pwd)
 		return 1;
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to