Date: Fri, 24 Dec 1999 12:59:56 +0200 (EET) From: acid@stu.cn.ua To: FreeBSD-gnats-submit@freebsd.org Subject: bin/15663: patch for lock (1) adding capability to lock all ttys Message-ID: <199912241059.MAA22301@stalker.stu.cn.ua>
index | next in thread | raw e-mail
>Number: 15663
>Category: bin
>Synopsis: none
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Fri Dec 24 03:10:01 PST 1999
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199912241059.MAA22301>
