From ajk@poynting.physics.purdue.edu Sat Apr  3 09:45:05 1999
Return-Path: <ajk@poynting.physics.purdue.edu>
Received: from poynting.physics.purdue.edu (poynting.physics.purdue.edu [128.210.146.58])
	by hub.freebsd.org (Postfix) with ESMTP id 5656814C90
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  3 Apr 1999 09:44:59 -0800 (PST)
	(envelope-from ajk@poynting.physics.purdue.edu)
Received: (from ajk@localhost)
	by poynting.physics.purdue.edu (8.9.1/8.9.1) id MAA05825;
	Sat, 3 Apr 1999 12:43:04 -0500 (EST)
	(envelope-from ajk)
Message-Id: <199904031743.MAA05825@poynting.physics.purdue.edu>
Date: Sat, 3 Apr 1999 12:43:04 -0500 (EST)
From: ajk@purdue.edu
Sender: ajk@poynting.physics.purdue.edu
Reply-To: ajk@purdue.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] Auto-login support for getty
X-Send-Pr-Version: 3.2

>Number:         10930
>Category:       bin
>Synopsis:       [PATCH] Auto-login support for getty
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr  3 12:50:01 PST 1999
>Closed-Date:    Wed Jun 2 20:04:56 PDT 1999
>Last-Modified:  Wed Jun  2 20:08:51 PDT 1999
>Originator:     Andrew J. Korty
>Release:        FreeBSD 3.0-RELEASE i386
>Organization:
Physics Computer Network, Purdue University
>Environment:

FreeBSD galileo.physics.purdue.edu 3.1-PCN FreeBSD 3.1-PCN #6:
Thu Mar 25 11:01:38 EST 1999
csg@tesla.physics.purdue.edu:/usr/src/sys/compile/PCN-GALILEO  i386

>Description:

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.

>How-To-Repeat:

Apply this patch in /usr/src, add "al=username" to the desired entry
in /etc/gettytab, and kill -HUP 1.

>Fix:

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);
 		}

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ghelmer 
State-Changed-When: Wed Jun 2 20:04:56 PDT 1999 
State-Changed-Why:  
Committed to -current and -stable by peter. 
gettytab.5 revs 1.19 and 1.18.2.1 
gettytab.h revs 1.9 and 1.8.2.1 
init.c revs 1.10 and 1.9.2.1 
main.c revs 1.25 and 1.23.2.1 

Thanks for the patch! 

>Unformatted:
