From 610b0299af2a7ddce350ea227353c8e7fd7dd3f0 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sun, 4 Apr 1999 04:36:50 +0000 Subject: [PATCH] Add an 'al' (autologin username) capability to getty/gettytab. This is a damn useful thing for using with serial consoles in clusters etc or secure console locations. Using a custom gettytab entry for console with an entry like 'al=root' means that there is *always* a root login ready on the console. This should replace hacks like those which go with conserver etc. (This is a loaded gun, watch out for those feet!) Submitted by: "Andrew J. Korty" --- libexec/getty/gettytab.5 | 3 ++- libexec/getty/gettytab.h | 3 ++- libexec/getty/init.c | 3 ++- libexec/getty/main.c | 25 +++++++++++++++++++++---- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libexec/getty/gettytab.5 b/libexec/getty/gettytab.5 index ca95f6bc705c..1a09d4359a6c 100644 --- a/libexec/getty/gettytab.5 +++ b/libexec/getty/gettytab.5 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)gettytab.5 8.4 (Berkeley) 4/19/94 -.\" $Id: gettytab.5,v 1.17 1998/05/04 02:37:24 steve Exp $ +.\" $Id: gettytab.5,v 1.18 1998/06/10 12:34:25 phk Exp $ .\" " .Dd April 19, 1994 .Dt GETTYTAB 5 @@ -79,6 +79,7 @@ table. .Bl -column Namexx /usr/bin/login Default .It Sy Name Type Default Description .It "ac str unused expect-send chat script for modem answer" +.It "al str unused user to auto-login instead of prompting" .It "ap bool false terminal uses any parity" .It "bk str 0377 alternate end of line character (input break)" .It "c0 num unused tty control flags to write messages" diff --git a/libexec/getty/gettytab.h b/libexec/getty/gettytab.h index 1321ad19e9c6..1323f67e0d3e 100644 --- a/libexec/getty/gettytab.h +++ b/libexec/getty/gettytab.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)gettytab.h 8.2 (Berkeley) 3/30/94 - * $Id$ + * $Id: gettytab.h,v 1.8 1997/02/22 14:21:38 peter Exp $ */ /* @@ -90,6 +90,7 @@ struct gettyflags { #define IF gettystrs[26].value #define IC gettystrs[27].value #define AC gettystrs[28].value +#define AL gettystrs[29].value /* * Numeric definitions. diff --git a/libexec/getty/init.c b/libexec/getty/init.c index 31c62a287653..3f279fac6c9c 100644 --- a/libexec/getty/init.c +++ b/libexec/getty/init.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)from: init.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id$"; + "$Id: init.c,v 1.9 1997/11/21 07:43:49 charnier Exp $"; #endif /* not lint */ /* @@ -83,6 +83,7 @@ struct gettystrs gettystrs[] = { { "if" }, /* sysv-like 'issue' filename */ { "ic" }, /* modem init-chat */ { "ac" }, /* modem answer-chat */ + { "al" }, /* user to auto-login */ { 0 } }; diff --git a/libexec/getty/main.c b/libexec/getty/main.c index 55fa1b6cec70..0047f593f12d 100644 --- a/libexec/getty/main.c +++ b/libexec/getty/main.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)from: main.c 8.1 (Berkeley) 6/20/93"; #endif static const char rcsid[] = - "$Id: main.c,v 1.23 1998/10/08 23:14:02 jkh Exp $"; + "$Id: main.c,v 1.24 1999/03/09 22:04:44 brian Exp $"; #endif /* not lint */ #include @@ -348,7 +348,23 @@ main(argc, argv) signal(SIGALRM, dingdong); alarm(TO); } - if ((rval = getname()) == 2) { + if (AL) { + const char *p = AL; + char *q = name; + int n = sizeof name; + + while (*p && q < &name[sizeof name - 1]) { + if (isupper(*p)) + upper = 1; + else if (islower(*p)) + lower = 1; + else if (isdigit(*p)) + digit++; + *q++ = *p++; + } + } else + rval = getname(); + if (rval == 2) { oflush(); alarm(0); limit.rlim_max = RLIM_INFINITY; @@ -357,7 +373,7 @@ main(argc, argv) execle(PP, "ppplogin", ttyn, (char *) 0, env); syslog(LOG_ERR, "%s: %m", PP); exit(1); - } else if (rval) { + } else if (rval || AL) { register int i; oflush(); @@ -392,7 +408,8 @@ main(argc, argv) limit.rlim_max = RLIM_INFINITY; limit.rlim_cur = RLIM_INFINITY; (void)setrlimit(RLIMIT_CPU, &limit); - execle(LO, "login", "-p", name, (char *) 0, env); + execle(LO, "login", AL ? "-fp" : "-p", name, + (char *) 0, env); syslog(LOG_ERR, "%s: %m", LO); exit(1); }