From acid@stalker.stu.cn.ua  Fri Dec 24 03:00:18 1999
Return-Path: <acid@stalker.stu.cn.ua>
Received: from stalker.stu.cn.ua (cinet-gw.stu.cn.ua [212.86.102.3])
	by hub.freebsd.org (Postfix) with ESMTP id 2894A1506A
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 24 Dec 1999 03:00:07 -0800 (PST)
	(envelope-from acid@stalker.stu.cn.ua)
Received: (from acid@localhost)
	by stalker.stu.cn.ua (8.9.3/8.9.3) id MAA22301;
	Fri, 24 Dec 1999 12:59:56 +0200 (EET)
Message-Id: <199912241059.MAA22301@stalker.stu.cn.ua>
Date: Fri, 24 Dec 1999 12:59:56 +0200 (EET)
From: acid@stu.cn.ua
Sender: acid@stalker.stu.cn.ua
To: FreeBSD-gnats-submit@freebsd.org
Subject: patch for lock (1) adding capability to lock all ttys
X-Send-Pr-Version: 3.2

>Number:         15663
>Category:       bin
>Synopsis:       patch for lock (1) adding capability to lock all ttys
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yokota
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 24 03:10:01 PST 1999
>Closed-Date:    Tue Mar 25 03:50:15 PST 2003
>Last-Modified:  Tue Mar 25 03:50:15 PST 2003
>Originator:     Michael Vasilenko
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
Chernigiv State Technological University
>Environment:


>Description:

		lock (1) is unable to lock all ttys like Linux's vlock.
		This patch adds this capability to lock (1)

>How-To-Repeat:


>Fix:
	
diff -c -r lock.orig/lock.1 lock/lock.1
*** lock.orig/lock.1	Sat Sep 14 12:00:48 1996
--- lock/lock.1	Fri Dec 24 12:58:32 1999
***************
*** 54,59 ****
--- 54,63 ----
  Options:
  .Pp
  .Bl -tag -width Fl
+ .It Fl a
+ Lock all ttys. To use this feature, you must be root or
+ .Nm lock
+ must be installed setuid to root.
  .It Fl n
  Don't use a timeout value.  Terminal will be locked forever.
  .It Fl p
diff -c -r lock.orig/lock.c lock/lock.c
*** lock.orig/lock.c	Sun Aug 29 18:29:56 1999
--- lock/lock.c	Fri Dec 24 12:15:44 1999
***************
*** 68,84 ****
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
  
  #define	TIMEOUT	15
  
! void quit(), bye(), hi();
  static void usage __P((void));
  
  struct timeval	timeout;
  struct timeval	zerotime;
  struct sgttyb	tty, ntty;
  long	nexttime;			/* keep the timeout time */
! int            no_timeout;                     /* lock terminal forever */
  
  /*ARGSUSED*/
  int
--- 68,88 ----
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
+ #include <machine/console.h>
  
  #define	TIMEOUT	15
  
! void quit(), bye(), hi(), release(), acquire();
  static void usage __P((void));
  
  struct timeval	timeout;
  struct timeval	zerotime;
  struct sgttyb	tty, ntty;
  long	nexttime;			/* keep the timeout time */
! int	no_timeout,                     /* lock terminal forever */
! 	fd,
! 	lock_all;			/* lock all ttys */       
! 
  
  /*ARGSUSED*/
  int
***************
*** 86,91 ****
--- 90,96 ----
  	int argc;
  	char **argv;
  {
+ 	struct vt_mode mode;                                                  
  	struct passwd *pw;
  	struct timeval timval;
  	time_t timval_sec;
***************
*** 100,106 ****
  	mypw = NULL;
  	usemine = 0;
         no_timeout = 0;
!        while ((ch = getopt(argc, argv, "npt:")) != -1)
  		switch((char)ch) {
  		case 't':
  			if ((sectimeout = atoi(optarg)) <= 0)
--- 105,113 ----
  	mypw = NULL;
  	usemine = 0;
         no_timeout = 0;
!        lock_all = 0;
! 	fd = fileno(stdin);
!        while ((ch = getopt(argc, argv, "anpt:")) != -1)
  		switch((char)ch) {
  		case 't':
  			if ((sectimeout = atoi(optarg)) <= 0)
***************
*** 115,121 ****
                 case 'n':
                         no_timeout = 1;
                         break;
! 		case '?':
  		default:
  			usage();
  	}
--- 122,131 ----
                 case 'n':
                         no_timeout = 1;
                         break;
!                case 'a':
!                        lock_all = 1; 
! 		       break;
!                case '?':
  		default:
  			usage();
  	}
***************
*** 167,172 ****
--- 177,193 ----
  	(void)signal(SIGQUIT, hi);
  	(void)signal(SIGTSTP, hi);
  	(void)signal(SIGALRM, bye);
+ 	if (lock_all) 
+ 	 {
+ 	        (void)signal(SIGUSR1, release);
+ 		(void)signal(SIGUSR2, acquire);
+ 	                    
+ 		mode.mode = VT_PROCESS;
+ 		mode.relsig = SIGUSR1;
+ 		mode.acqsig = SIGUSR2;
+ 		mode.frsig = SIGUSR1;   /* not used */
+ 		ioctl(fd, VT_SETMODE, &mode);
+ 	  }                                                                    
  
  	ntimer.it_interval = zerotime;
  	ntimer.it_value = timeout;
***************
*** 198,205 ****
  			break;
  		(void)printf("\07\n");
  		if (ioctl(0, TIOCGETP, &ntty))
! 			exit(1);
! 	}
  	quit();
  	return(0); /* not reached */
  }
--- 219,232 ----
  			break;
  		(void)printf("\07\n");
  		if (ioctl(0, TIOCGETP, &ntty))
! 			exit(1); }
! 		if (lock_all) { 
!     	      /* clean up before quiting */
!                mode.mode = VT_AUTO;
!                ioctl(fd, VT_SETMODE, &mode);
! 		
! 	
!         }                      
  	quit();
  	return(0); /* not reached */
  }
***************
*** 208,214 ****
  static void
  usage()
  {
! 	(void)fprintf(stderr, "usage: lock [-n] [-p] [-t timeout]\n");
  	exit(1);
  }
  
--- 235,241 ----
  static void
  usage()
  {
! 	(void)fprintf(stderr, "usage: lock [-a] [-n] [-p] [-t timeout]\n");
  	exit(1);
  }
  
***************
*** 246,248 ****
--- 273,287 ----
                 exit(1);
         }
  }
+ void  
+ release(int arg)
+   {
+           /* always refuse to release our vty */
+           ioctl(fd, VT_RELDISP, VT_FALSE);
+   }
+ 
+ void  
+ acquire(int arg)
+   {
+           ioctl(fd, VT_RELDISP, VT_ACKACQ);
+   }

>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: acid@stu.cn.ua
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/15663: patch for lock (1) adding capability to lock all ttys 
Date: Tue, 28 Dec 1999 17:40:39 +0200

 On Fri, 24 Dec 1999 12:59:56 +0200, acid@stu.cn.ua wrote:
 
 >   .Bl -tag -width Fl
 > + .It Fl a
 > + Lock all ttys. To use this feature, you must be root or
 > + .Nm lock
 > + must be installed setuid to root.
 
 What I'd _really_ like to see as the lock_all feature with slightly
 different (and more useful) semantics:
 
 -a	Lock all terminals for which the user has appropriate
 	permissions.  For the superuser, this means all terminals.
 
 I see no reason to allow a single user to lock all the terminals
 (including psuedo-terminals, no?) but I _do_ see a reason to allow a
 single user to lock all the terminals which that user owns.
 
 Wotcha think?
 
 Ciao,
 Sheldon.
 
Responsible-Changed-From-To: freebsd-bugs->yokota 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Dec 29 00:39:45 PST 1999 
Responsible-Changed-Why:  
Perhaps the syscons maintainer has already thought about this? 
Any comments? :-) 
State-Changed-From-To: open->closed 
State-Changed-By: tjr 
State-Changed-When: Tue Mar 25 03:49:36 PST 2003 
State-Changed-Why:  
This feature was recented implemented as the -v option. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15663 
>Unformatted:
