1 /* vi: set sw=4 ts=4: */
3 * vlock implementation for busybox
5 * Copyright (C) 2000 by spoon <spoon@ix.netcom.com>
6 * Written by spoon <spon@ix.netcom.com>
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 /* Shoutz to Michael K. Johnson <johnsonm@redhat.com>, author of the
12 * original vlock. I snagged a bunch of his code to write this
15 /* Fixed by Erik Andersen to do passwords the tinylogin way...
16 * It now works with md5, sha1, etc passwords. */
21 static void release_vt(int signo UNUSED_PARAM)
23 /* If -a, param is 0, which means:
24 * "no, kernel, we don't allow console switch away from us!" */
25 ioctl(STDIN_FILENO, VT_RELDISP, (unsigned long) !option_mask32);
28 static void acquire_vt(int signo UNUSED_PARAM)
30 /* ACK to kernel that switch to console is successful */
31 ioctl(STDIN_FILENO, VT_RELDISP, VT_ACKACQ);
34 int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
35 int vlock_main(int argc UNUSED_PARAM, char **argv)
47 bb_error_msg_and_die("unknown uid %d", (int)uid);
49 opt_complementary = "=0"; /* no params! */
52 /* Ignore some signals so that we don't get killed by them */
58 + (1 << SIGCHLD) /* paranoia :) */
63 /* We will use SIGUSRx for console switch control: */
65 signal_SA_RESTART_empty_mask(SIGUSR1, release_vt);
66 signal_SA_RESTART_empty_mask(SIGUSR2, acquire_vt);
71 /* Revert stdin/out to our controlling tty
72 * (or die if we have none) */
73 xmove_fd(xopen(CURRENT_TTY, O_RDWR), STDIN_FILENO);
74 xdup2(STDIN_FILENO, STDOUT_FILENO);
76 xioctl(STDIN_FILENO, VT_GETMODE, &vtm);
78 /* "console switches are controlled by us, not kernel!" */
79 vtm.mode = VT_PROCESS;
82 ioctl(STDIN_FILENO, VT_SETMODE, &vtm);
84 tcgetattr(STDIN_FILENO, &oterm);
86 term.c_iflag &= ~BRKINT;
87 term.c_iflag |= IGNBRK;
88 term.c_lflag &= ~ISIG;
89 term.c_lflag &= ~(ECHO | ECHOCTL);
90 tcsetattr(STDIN_FILENO, TCSANOW, &term);
93 printf("Virtual console%s locked by %s.\n",
94 option_mask32 /*o_lock_all*/ ? "s" : "",
96 if (correct_password(pw)) {
99 bb_do_delay(FAIL_DELAY);
100 puts("Password incorrect");
103 ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);
104 tcsetattr(STDIN_FILENO, TCSANOW, &oterm);
105 fflush_stdout_and_exit(EXIT_SUCCESS);