Subject: bin/4647: ttyaction on logout for network logins
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tsarna@endicor.com>
List: netbsd-bugs
Date: 12/07/1997 01:48:28
>Number:         4647
>Category:       bin
>Synopsis:       ttyaction on logout for network logins
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec  6 23:50:00 1997
>Last-Modified:
>Originator:     Ty Sarna
>Organization:
	Endicor Technologies, Inc., San Antonio, Texas
>Release:        any recent
>Environment:

System: NetBSD zoo-of-death.endicor.com 1.3_BETA-971202 NetBSD 1.3_BETA-971202 (ZOO-OF-DEATH) #6: Tue Dec 2 15:59:45 CST 1997 tsarna@zoo-of-death.endicor.com:/bbs/usr.src/sys/arch/i386/compile/ZOO-OF-DEATH i386


>Description:
	The ttyaction system works well for lines using getty, but not
	optimally for network logins.

	For logins, login does ttyaction(tty, "login", user);
	On getty lines, when the login terminates, getty runs
	and calls ttyaction(tty, "getty", "root").

	This accomplished the stated goal of running site-specific
	commands when a login session begins and ends.

	However in the telnetd/rlogind case, there is no way to execute
	site-specific commands on termination of the connection.
>How-To-Repeat:
	Install a script to be run when people log in our out. Test by
	telnet to localhost, and wonder why it doesn't get run on
	logout.
>Fix:
	Patches to be applied from /usr/src.

	Also, I noticed that login(1) and getty(8) don't mention
	ttyaction. They probably should, and rlogind(8)/telnetd(8)
	should as well in that case. However, I haven't included
	any such changes below.

--- libexec/telnetd/sys_term.c.orig	Sun Dec  7 00:46:13 1997
+++ libexec/telnetd/sys_term.c	Sun Dec  7 01:18:00 1997
@@ -1880,16 +1880,19 @@
 {
 #ifndef	PARENT_DOES_UTMP
 # if (BSD > 43) || defined(convex)
-	char *p;
+	char *p, c;
 
 	p = line + sizeof("/dev/") - 1;
 	if (logout(p))
 		logwtmp(p, "", "");
 	(void)chmod(line, 0666);
 	(void)chown(line, 0, 0);
-	*p = 'p';
+	c = *p; *p = 'p';
 	(void)chmod(line, 0666);
 	(void)chown(line, 0, 0);
+	*p = c;
+	if (ttyaction(line, "telnetd", "root"))
+		syslog(LOG_ERR, "%s: ttyaction failed", line);
 	(void) shutdown(net, 2);
 	exit(1);
 # else
--- libexec/rlogind/rlogind.c.orig	Wed Oct  8 06:19:50 1997
+++ libexec/rlogind/rlogind.c	Sun Dec  7 01:19:57 1997
@@ -493,16 +493,19 @@
 cleanup(signo)
 	int signo;
 {
-	char *p;
+	char *p, c;
 
 	p = line + sizeof(_PATH_DEV) - 1;
 	if (logout(p))
 		logwtmp(p, "", "");
 	(void)chmod(line, 0666);
 	(void)chown(line, 0, 0);
-	*p = 'p';
+	c = *p; *p = 'p';
 	(void)chmod(line, 0666);
 	(void)chown(line, 0, 0);
+	*p = c;
+	if (ttyaction(line, "rlogind", "root"))
+		syslog(LOG_ERR, "%s: ttyaction failed", line);
 	shutdown(netf, 2);
 	exit(1);
 }
--- lib/libutil/ttyaction.3.orig	Sun Dec  7 01:34:43 1997
+++ lib/libutil/ttyaction.3	Sun Dec  7 01:35:52 1997
@@ -48,9 +48,11 @@
 The
 .Fn ttyaction
 function is used by
-.Nm login
+.Nm login ,
+.Nm getty ,
+.Nm telnetd
 and
-.Nm getty
+.Nm rlogind
 to execute site-specific commands
 when a login session begins and ends.
 .Pp
--- share/man/man5/ttyaction.5.orig	Sun Dec  7 01:38:43 1997
+++ share/man/man5/ttyaction.5	Sun Dec  7 01:43:47 1997
@@ -58,10 +58,11 @@
 file.
 .It action
 Name of the action for which this line should apply.
-The action names currently defined are "login" and "getty"
+The action names currently defined are "login", "getty",
+"telnetd" and "rlogind"
 which indicate which program is processing this file.
-(Note that "login" begins a login session, and "getty" is
-run after a login session ends.)
+(Note that "login" begins a login session, while the other
+three are run after a login session ends.)
 .It command
 What command to run if this record matches.
 .El
>Audit-Trail:
>Unformatted: