-.\" Copyright (c) 1980 Regents of the University of California.
-.\" All rights reserved. The Berkeley software License Agreement
-.\" specifies the terms and conditions for redistribution.
+.\" Copyright (c) 1987 The Regents of the University of California.
+.\" All rights reserved.
.\"
-.\" @(#)lock.1 6.3 (Berkeley) %G%
+.\" Redistribution and use in source and binary forms are permitted
+.\" provided that the above copyright notice and this paragraph are
+.\" duplicated in all such forms and that any documentation,
+.\" advertising materials, and other materials related to such
+.\" distribution and use acknowledge that the software was developed
+.\" by the University of California, Berkeley. The name of the
+.\" University may not be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+.\"
+.\" @(#)lock.1 6.4 (Berkeley) %G%
.\"
.TH LOCK 1 ""
.UC
[
.B -p
] [
-.B -number
+.B -t timeout
]
.br
.SH DESCRIPTION
accepts the password for root as an alternative to the one given by the
user, it will timeout after some interval of time, and it may be killed by
somebody with the appropriate permission. The default time limit is 15 minutes
-but it may be changed with the \fI-number\fP option where \fInumber\fP is the
+but it may be changed with the \fI-t\fP option where \fItimeout\fP is the
time limit in minutes. The \fI-p\fP option has \fIlock\fP use the user's
standard password instead of requesting another one.
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)lock.c 5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)lock.c 5.7 (Berkeley) %G%";
#endif /* not lint */
/*
#include <ctype.h>
#define TIMEOUT 15
-#define YES 1
-#define NO 0
int quit(), bye(), hi();
/*ARGSUSED*/
main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char **argv;
{
- struct passwd *root_pwd, *my_pwd;
- struct timeval timval;
- struct itimerval ntimer, otimer;
- struct tm *timp;
- int sectimeout = TIMEOUT,
- use_mine;
- char *ttynam, *ap, *tzn,
- hostname[MAXHOSTNAMELEN], s[BUFSIZ], s1[BUFSIZ],
- *crypt(), *index(), *ttyname();
-
- use_mine = NO;
- for (++argv; *argv; ++argv) {
- if (argv[0][0] != '-')
- usage();
- if (argv[0][1] == 'p')
- use_mine = YES;
- else if (!isdigit(argv[0][1])) {
- fprintf(stderr, "lock: illegal option -- %c\n", argv[0][1]);
- usage();
- }
- else if ((sectimeout = atoi(*argv + 1)) <= 0)
- usage();
+ extern char *optarg;
+ extern int optind;
+ struct passwd *root_pwd, *my_pwd;
+ struct timeval timval;
+ struct itimerval ntimer, otimer;
+ struct tm *timp;
+ int ch, sectimeout, use_mine;
+ char *ttynam, *ap, *tzn;
+ char hostname[MAXHOSTNAMELEN], s[BUFSIZ], s1[BUFSIZ];
+ char *crypt(), *index(), *ttyname();
+
+ use_mine = 0;
+ sectimeout = TIMEOUT;
+ while ((ch = getopt(argc, argv, "pt:")) != EOF)
+ switch((char)ch) {
+ case 't':
+ if ((sectimeout = atoi(optarg)) <= 0)
+ exit(0);
+ break;
+ case 'p':
+ use_mine = 1;
+ break;
+ case '?':
+ default:
+ fputs("usage: lock [-p] [-t timeout]\n", stderr);
+ exit(1);
}
timeout.tv_sec = sectimeout * 60;
static
hi()
{
- struct timeval timval;
+ struct timeval timval;
if (!gettimeofday(&timval, (struct timezone *)NULL))
printf("lock: type in the unlock key. timeout in %ld:%ld minutes\n",
puts("lock: timeout");
exit(1);
}
-
-static
-usage()
-{
- fputs("usage: lock [-p] [-timeout]\n", stderr);
- exit(1);
-}