Closes PR bin/1567
/usr/bin/lock can be used to lock a terminal much like xlock does for your X-windows session. Problem is, /usr/bin/lock cannot lock your terminal indefinately. Rather you must specify a timeout value, after which, your terminal is unlocked and become unsecured. I have added a ``-n'' no timeout option to /usr/bin/lock Currently the only way to get this functionality is to use a huge timeout value and hope it is long enought (in time). This method also requires you to know the maxium number of minutes you are allowed to specify. Submitted by: David E. O'Brien <obrien@Nuxi.cs.ucdavis.edu>
This commit is contained in:
parent
2e82980a4c
commit
2280509ca1
@ -39,6 +39,7 @@
|
|||||||
.Nd reserve a terminal
|
.Nd reserve a terminal
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm lock
|
.Nm lock
|
||||||
|
.Op Fl n
|
||||||
.Op Fl p
|
.Op Fl p
|
||||||
.Op Fl t Ar timeout
|
.Op Fl t Ar timeout
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -53,6 +54,8 @@ with the appropriate permission.
|
|||||||
Options:
|
Options:
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width Fl
|
.Bl -tag -width Fl
|
||||||
|
.It Fl n
|
||||||
|
Don't use a timeout value. Terminal will be locked forever.
|
||||||
.It Fl p
|
.It Fl p
|
||||||
A password is not requested, instead the user's current login password
|
A password is not requested, instead the user's current login password
|
||||||
is used.
|
is used.
|
||||||
|
@ -70,6 +70,7 @@ struct timeval timeout;
|
|||||||
struct timeval zerotime;
|
struct timeval zerotime;
|
||||||
struct sgttyb tty, ntty;
|
struct sgttyb tty, ntty;
|
||||||
long nexttime; /* keep the timeout time */
|
long nexttime; /* keep the timeout time */
|
||||||
|
int no_timeout; /* lock terminal forever */
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
@ -90,7 +91,8 @@ main(argc, argv)
|
|||||||
sectimeout = TIMEOUT;
|
sectimeout = TIMEOUT;
|
||||||
mypw = NULL;
|
mypw = NULL;
|
||||||
usemine = 0;
|
usemine = 0;
|
||||||
while ((ch = getopt(argc, argv, "pt:")) != EOF)
|
no_timeout = 0;
|
||||||
|
while ((ch = getopt(argc, argv, "npt:")) != EOF)
|
||||||
switch((char)ch) {
|
switch((char)ch) {
|
||||||
case 't':
|
case 't':
|
||||||
if ((sectimeout = atoi(optarg)) <= 0) {
|
if ((sectimeout = atoi(optarg)) <= 0) {
|
||||||
@ -108,10 +110,13 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
mypw = strdup(pw->pw_passwd);
|
mypw = strdup(pw->pw_passwd);
|
||||||
break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
no_timeout = 1;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage: lock [-p] [-t timeout]\n");
|
"usage: lock [-n] [-p] [-t timeout]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
timeout.tv_sec = sectimeout * 60;
|
timeout.tv_sec = sectimeout * 60;
|
||||||
@ -169,11 +174,17 @@ main(argc, argv)
|
|||||||
|
|
||||||
ntimer.it_interval = zerotime;
|
ntimer.it_interval = zerotime;
|
||||||
ntimer.it_value = timeout;
|
ntimer.it_value = timeout;
|
||||||
setitimer(ITIMER_REAL, &ntimer, &otimer);
|
if (!no_timeout)
|
||||||
|
setitimer(ITIMER_REAL, &ntimer, &otimer);
|
||||||
|
|
||||||
/* header info */
|
/* header info */
|
||||||
|
if (no_timeout) {
|
||||||
|
(void)printf("lock: %s on %s. no timeout\ntime now is %.20s%s%s",
|
||||||
|
ttynam, hostname, ap, tzn, ap + 19);
|
||||||
|
} else {
|
||||||
(void)printf("lock: %s on %s. timeout in %d minutes\ntime now is %.20s%s%s",
|
(void)printf("lock: %s on %s. timeout in %d minutes\ntime now is %.20s%s%s",
|
||||||
ttynam, hostname, sectimeout, ap, tzn, ap + 19);
|
ttynam, hostname, sectimeout, ap, tzn, ap + 19);
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
(void)printf("Key: ");
|
(void)printf("Key: ");
|
||||||
@ -201,9 +212,16 @@ hi()
|
|||||||
{
|
{
|
||||||
struct timeval timval;
|
struct timeval timval;
|
||||||
|
|
||||||
if (!gettimeofday(&timval, (struct timezone *)NULL))
|
if (!gettimeofday(&timval, (struct timezone *)NULL)) {
|
||||||
(void)printf("lock: type in the unlock key. timeout in %ld:%ld minutes\n",
|
(void)printf("lock: type in the unlock key. ");
|
||||||
(nexttime - timval.tv_sec) / 60, (nexttime - timval.tv_sec) % 60);
|
if (no_timeout) {
|
||||||
|
(void)putchar('\n');
|
||||||
|
} else {
|
||||||
|
(void)printf("timeout in %ld:%ld minutes\n",
|
||||||
|
(nexttime - timval.tv_sec) / 60,
|
||||||
|
(nexttime - timval.tv_sec) % 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -217,7 +235,9 @@ quit()
|
|||||||
void
|
void
|
||||||
bye()
|
bye()
|
||||||
{
|
{
|
||||||
(void)ioctl(0, TIOCSETP, &tty);
|
if (!no_timeout) {
|
||||||
(void)printf("lock: timeout\n");
|
(void)ioctl(0, TIOCSETP, &tty);
|
||||||
exit(1);
|
(void)printf("lock: timeout\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user