Subject: bin/7816: lock might unlock before i want it to
To: None <gnats-bugs@gnats.netbsd.org>
From: TheMan <andrew@untraceable.net>
List: netbsd-bugs
Date: 06/19/1999 12:22:47
>Number:         7816
>Category:       bin
>Synopsis:       lock might unlock before i get back, exposing my terminal to nasty people
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 19 12:05:01 1999
>Last-Modified:
>Originator:     TheMan
>Organization:
i and i
>Release:        1.3.3 and -current
>Environment:
System: NetBSD noc 1.3.3 NetBSD 1.3.3 (LINGAM) #1: Tue Apr 13 12:33:49 EDT 1999 andrew@noc:/usr/src/sys/arch/i386/compile/LINGAM i386

>Description:

lock has the remarkable ability to unlock a locked terminal whenever
the timeout expires, regardless of whether or not the user is actually
back, thereby almost completely defeating the idea of locking it in
the first place.

>How-To-Repeat:

lock your terminal with a timeout of 60 minutes.  expect to be back.
get held up in traffic (or in a bank, etc.).  return to your terminal
much later than you expected, only to find that nasty poeple have used
your terminal to do all sorts of naughty distasteful things.  jump up
and down in frustration.

>Fix:

--- lock.c-orig	Sun Dec 20 07:17:48 1998
+++ lock.c	Sat Jun 19 14:48:00 1999
@@ -88,6 +88,7 @@
 struct timeval	timeout;
 struct timeval	zerotime;
 struct termios	tty, ntty;
+int	notimeout;			/* no timeout at all */
 long	nexttime;			/* keep the timeout time */
 
 int
@@ -111,12 +112,16 @@
 
 	setuid(getuid());		/* discard privs */
 
+	notimeout = 0;
 	sectimeout = TIMEOUT;
 	mypw = NULL;
 	usemine = 0;
 
-	while ((ch = getopt(argc, argv, "pt:")) != -1)
+	while ((ch = getopt(argc, argv, "npt:")) != -1)
 		switch ((char)ch) {
+		case 'n':
+			notimeout = 1;
+			break;
 		case 't':
 			if ((sectimeout = atoi(optarg)) <= 0)
 				errx(1, "illegal timeout value: %s", optarg);
@@ -181,15 +186,23 @@
 	(void)signal(SIGINT, hi);
 	(void)signal(SIGQUIT, hi);
 	(void)signal(SIGTSTP, hi);
-	(void)signal(SIGALRM, bye);
 
-	ntimer.it_interval = zerotime;
-	ntimer.it_value = timeout;
-	setitimer(ITIMER_REAL, &ntimer, &otimer);
+	if (notimeout) {
+		(void)signal(SIGALRM, hi);
+	(void)printf("lock: %s on %s.  no timeout.\ntime now is %.20s%s%s",
+		    ttynam, hostname, ap, tzn, ap + 19);
+	}
+	else {
+		(void)signal(SIGALRM, bye);
+
+		ntimer.it_interval = zerotime;
+		ntimer.it_value = timeout;
+		setitimer(ITIMER_REAL, &ntimer, &otimer);
 
-	/* header info */
+		/* header info */
 (void)printf("lock: %s on %s. timeout in %d minutes\ntime now is %.20s%s%s",
 	    ttynam, hostname, sectimeout, ap, tzn, ap + 19);
+	}
 
 	for (;;) {
 		(void)printf("Key: ");
@@ -254,7 +267,9 @@
 {
 	struct timeval timval;
 
-	if (!gettimeofday(&timval, (struct timezone *)NULL))
+	if (notimeout)
+		(void)printf("lock: type in the unlock key.\n");
+	else if (!gettimeofday(&timval, (struct timezone *)NULL))
 (void)printf("lock: type in the unlock key. timeout in %ld:%ld minutes\n",
 	    (nexttime - timval.tv_sec) / 60, (nexttime - timval.tv_sec) % 60);
 }
--- lock.1-orig	Sun Oct 19 10:20:42 1997
+++ lock.1	Sat Jun 19 14:52:13 1999
@@ -41,7 +41,7 @@
 .Nd reserve a terminal
 .Sh SYNOPSIS
 .Nm
-.Op Fl p
+.Op Fl np
 .Op Fl t Ar timeout
 .Sh DESCRIPTION
 .Nm
@@ -55,6 +55,9 @@
 Options:
 .Pp
 .Bl -tag -width Fl
+.It Fl n
+No timeout is used.  The terminal will be locked indefinitely or until
+current challenge is met.
 .It Fl p
 A password is not requested, instead the user's current login password
 is used.
>Audit-Trail:
>Unformatted: