[hackers] [ubase] Ensure getty prompts for the username || sin

From: <git_AT_suckless.org>
Date: Mon, 10 Feb 2014 16:50:09 +0100

commit cb904446ec7bc35a476fe1b71bd10f3a780857b7
Author: sin <sin_AT_2f30.org>
Date: Mon Feb 10 15:04:24 2014 +0000

    Ensure getty prompts for the username
    
    As Eckehard Berns reported:
    
    "On Slackware /bin/login times out after 60 seconds which will
    clutter the vt after a couple of minutes with timeout messages and login
    prompts. So it seems that getty should ask for the username first even
    if login could do it as well."

diff --git a/getty.c b/getty.c
index 8a80808..fd84673 100644
--- a/getty.c
+++ b/getty.c
_AT_@ -3,6 +3,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
_AT_@ -23,7 +24,9 @@ main(int argc, char *argv[])
 {
         int fd;
         struct sigaction sa;
- char term[128];
+ char term[128], logname[128], c;
+ int i = 0;
+ ssize_t n;
 
         ARGBEGIN {
         default:
_AT_@ -76,5 +79,27 @@ main(int argc, char *argv[])
         sigaction(SIGHUP, &sa, NULL);
 
         putchar('
');
- return execvp("/bin/login", (char *[]){ "login", NULL });
+ printf("Login: ");
+ fflush(stdout);
+
+ /* Flush pending input */
+ ioctl(STDIN_FILENO, TCFLSH, (void *)0);
+ memset(logname, 0, sizeof(logname));
+ while (1) {
+ n = read(STDIN_FILENO, &c, 1);
+ if (n < 0)
+ eprintf("read:");
+ if (n == 0)
+ return EXIT_FAILURE;
+ if (i >= sizeof(logname) - 1)
+ eprintf("login name too long
");
+ if (c == '
' || c == ' ')
+ break;
+ logname[i++] = c;
+ }
+ if (logname[0] == '-')
+ eprintf("login name cannot start with '-'
");
+ if (logname[0] == '
Received on Mon Feb 10 2014 - 16:50:09 CET

This archive was generated by hypermail 2.3.0 : Mon Feb 10 2014 - 17:00:20 CET