From owner-freebsd-hackers Thu Apr 1 10:25:22 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from poynting.physics.purdue.edu (poynting.physics.purdue.edu [128.210.146.58]) by hub.freebsd.org (Postfix) with ESMTP id 1797A14D03 for ; Thu, 1 Apr 1999 10:25:00 -0800 (PST) (envelope-from ajk@physics.purdue.edu) Received: from physics.purdue.edu (localhost [127.0.0.1]) by poynting.physics.purdue.edu (8.9.1/8.9.1) with ESMTP id NAA28557 for ; Thu, 1 Apr 1999 13:24:42 -0500 (EST) (envelope-from ajk@physics.purdue.edu) Message-Id: <199904011824.NAA28557@poynting.physics.purdue.edu> To: hackers@freebsd.org Subject: [PATCH] Auto-login support for getty From: "Andrew J. Korty" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <28550.922991081.0@physics.purdue.edu> Date: Thu, 01 Apr 1999 13:24:41 -0500 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28550.922991081.1@physics.purdue.edu> We run a localism called "autologin" that does nothing more than keep a shell up on the console. It runs on all our servers, whose consoles are connected to our console server. Autologin is run from /etc/ttys, so when the shell exits, another one pops up. This way, we're almost guaranteed to have a root shell. (Physical and network access to the console server is controlled, of course.) When porting autologin to FreeBSD, we noticed that it has to replicate much code that already exists in getty. My colleague remarked that we ought to just add an option to getty to do what we want. So I did, and I'm presenting the results here because I think it would be a worthwhile commit. (I don't have privs.) This patch adds a string capability ("al") to getty. Setting it to a username gives you a persistent shell without prompting for login or password. The code is very simple; it just passes the -f option to the login program. These are against 3.1-RELEASE; if newer diffs are needed, I can do that. One more upshot: if you have an operations staff, they can be root on console without having to know the root password. When a crisis occurs, you can call the op center and talk them through. Andrew J. Korty, Director http://www.physics.purdue.edu/~ajk/ Physics Computer Network 85 73 1F 04 63 D9 9D 65 Purdue University 65 2E 7A A8 81 8C 45 75 ------- =_aaaaaaaaaa0 Content-Type: application/x-patch Content-ID: <28550.922991081.2@physics.purdue.edu> Content-Description: Auto-login support for getty ? autologin.diff Index: gettytab.5 =================================================================== RCS file: /project/cvs/PCN/freebsd/src/libexec/getty/gettytab.5,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- gettytab.5 1998/12/03 15:38:11 1.1.1.1 +++ gettytab.5 1999/04/01 13:18:50 1.2 @@ -79,6 +79,7 @@ .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" Index: gettytab.h =================================================================== RCS file: /project/cvs/PCN/freebsd/src/libexec/getty/gettytab.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- gettytab.h 1998/12/03 15:38:11 1.1.1.1 +++ gettytab.h 1999/04/01 13:18:50 1.2 @@ -90,6 +90,7 @@ #define IF gettystrs[26].value #define IC gettystrs[27].value #define AC gettystrs[28].value +#define AL gettystrs[29].value /* * Numeric definitions. Index: init.c =================================================================== RCS file: /project/cvs/PCN/freebsd/src/libexec/getty/init.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- init.c 1998/12/03 15:38:11 1.1.1.1 +++ init.c 1999/04/01 13:18:50 1.2 @@ -83,6 +83,7 @@ { "if" }, /* sysv-like 'issue' filename */ { "ic" }, /* modem init-chat */ { "ac" }, /* modem answer-chat */ + { "al" }, /* user to auto-login */ { 0 } }; Index: main.c =================================================================== RCS file: /project/cvs/PCN/freebsd/src/libexec/getty/main.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- main.c 1998/12/03 15:38:11 1.1.1.1 +++ main.c 1999/04/01 13:18:51 1.2 @@ -348,13 +348,29 @@ 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); 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(); @@ -389,7 +405,8 @@ 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); } ------- =_aaaaaaaaaa0-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message