1 /* vlock.c -- main routine for vlock, the VT locking program for linux
3 * This program is copyright (C) 1994 Michael K. Johnson, and is free
4 * software which is freely distributable under the terms of the
5 * GNU public license, included as the file COPYING in this
6 * distribution. It is NOT public domain software, and any
7 * redistribution not permitted by the GNU Public License is
8 * expressly forbidden without prior written permission from
15 * Revision 1.11 1994/07/03 12:41:43 johnsonm
16 * Removed emacs variables.
18 * Revision 1.10 1994/07/03 12:15:22 johnsonm
19 * *** empty log message ***
21 * Revision 1.9 1994/03/23 17:00:47 johnsonm
22 * Removed appendages for patterns.
23 * Added support for non-VT ttys.
25 * Revision 1.8 1994/03/20 11:21:20 johnsonm
26 * Now check /dev/console after opening it to make sure the call succeeded
28 * Revision 1.7 1994/03/19 17:54:42 johnsonm
29 * Moved printing the lock message to get_password. Added a return
32 * Revision 1.6 1994/03/19 14:36:08 johnsonm
33 * Made a better explanation for when the --all or -a flag is chosen.
35 * Revision 1.5 1994/03/19 14:25:16 johnsonm
36 * Removed silly two-process model. Must have been half asleep when
37 * I came up with that idea. vlock works now.
39 * Revision 1.4 1994/03/16 20:14:06 johnsonm
40 * Cleaned up, putting most real work into child functions, which
41 * cleaned up the interface. The whole program is almost all
44 * Revision 1.3 1994/03/15 18:27:33 johnsonm
45 * Moved terminal handling stuff into terminal.c, and changed the
46 * end to support a two-process model for async I/O.
48 * Revision 1.2 1994/03/13 17:28:56 johnsonm
49 * Now using SIGUSR{1,2} correctly to announce VC switches. Fixed a few
52 * Revision 1.1 1994/03/13 16:28:16 johnsonm
66 #include <sys/ioctl.h>
71 static char rcsid
[] = "$Id: vlock.c,v 1.12 1996/05/17 02:52:03 johnsonm Exp $";
74 /* This determines whether the default behavior is to lock only the */
75 /* current VT or all of them. 0 means current, 1 means all. */
84 int main(int argc
, char **argv
) {
86 static struct option long_options
[] = { /* For parsing long arguments */
87 {"current", 0, &o_lock_all
, 0},
88 {"all", 0, &o_lock_all
, 1},
89 {"version", no_argument
, 0, O_VERSION
},
90 {"help", no_argument
, 0, O_HELP
},
93 int option_index
; /* Unused */
97 /* First we parse all the command line arguments */
98 while ((c
= getopt_long(argc
, argv
, "acvh",
99 long_options
, &option_index
)) != -1) {
109 fprintf(stderr
, VERSION
);
122 /* Now we have parsed the options, and can get on with life */
124 /* Get the user's and root's encrypted passwords. This needs
125 to run as root when using shadow passwords, but will drop
126 root privileges as soon as they are no longer needed. */
129 if ((vfd
= open("/dev/tty", O_RDWR
)) < 0) {
130 perror("vlock: could not open /dev/tty");
134 /* First we will set process control of VC switching; if this fails, */
135 /* then we know that we aren't on a VC, and will print a warning message */
136 /* If it doesn't fail, it gets the current VT status... */
137 c
= ioctl(vfd
, VT_GETMODE
, &vtm
);
139 fprintf(stderr
, " *** This tty is not a VC (virtual console). ***\n"
140 " *** It may not be securely locked. ***\n\n");
147 /* Now set the signals so we can't be summarily executed or stopped, */
148 /* and handle SIGUSR{1,2} and SIGCHLD */
152 ovtm
= vtm
; /* Keep a copy around to restore at appropriate times */
153 vtm
.mode
= VT_PROCESS
;
154 vtm
.relsig
= SIGUSR1
; /* handled by release_vt() */
155 vtm
.acqsig
= SIGUSR2
; /* handled by acquire_vt() */
156 ioctl(vfd
, VT_SETMODE
, &vtm
);
159 /* get_password() sets the terminal characteristics and does not */
160 /* return until the correct password has been read. */
163 /* vt status was restored in restore_terminal() already... */
165 /* we should really return something... */