1 /* vlock-current.c -- locking routine for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
22 #include <sys/types.h>
28 /* Lock the current terminal until proper authentication is received. */
32 struct termios term
, term_bak
;
35 /* get the user name from the environment */
36 char *envuser
= getenv("USER");
38 /* ignore some signals */
39 signal(SIGINT
, SIG_IGN
);
40 signal(SIGHUP
, SIG_IGN
);
41 signal(SIGQUIT
, SIG_IGN
);
42 signal(SIGTSTP
, SIG_IGN
);
44 if (uid
> 0 || envuser
== NULL
) {
45 /* get the password entry */
46 struct passwd
*pw
= getpwuid(uid
);
50 perror("vlock-current: getpwuid() failed");
52 fprintf(stderr
, "vlock-current: getpwuid() failed\n");
57 /* copy the username */
58 strncpy(user
, pw
->pw_name
, sizeof user
- 1);
59 user
[sizeof user
- 1] = '\0';
61 /* copy the username */
62 strncpy(user
, envuser
, sizeof user
- 1);
63 user
[sizeof user
- 1] = '\0';
66 /* get the vlock message from the environment */
67 vlock_message
= getenv("VLOCK_MESSAGE");
69 /* disable terminal echoing and signals */
70 if (tcgetattr(STDIN_FILENO
, &term
) == 0) {
72 term
.c_lflag
&= ~(ECHO
|ISIG
);
73 (void) tcsetattr(STDIN_FILENO
, TCSANOW
, &term
);
77 /* clear the screen */
78 fprintf(stderr
, CLEAR_SCREEN
);
81 /* print vlock message */
82 fprintf(stderr
, "%s\n", vlock_message
);
84 /* wait for enter to be pressed */
85 fprintf(stderr
, "Please press [ENTER] to unlock.\n");
86 while (fgetc(stdin
) != '\n');
101 /* restore the terminal */
102 (void) tcsetattr(STDIN_FILENO
, TCSANOW
, &term_bak
);