1 /* vi: set sw=4 ts=4: */
4 * vlock implementation for busybox
6 * Copyright (C) 2000 by spoon <spoon@ix.netcom.com>
7 * Written by spoon <spon@ix.netcom.com>
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 /* Shoutz to Michael K. Johnson <johnsonm@redhat.com>, author of the
13 * original vlock. I snagged a bunch of his code to write this
16 /* Fixed by Erik Andersen to do passwords the tinylogin way...
17 * It now works with md5, sha1, etc passwords. */
24 /* static unsigned long o_lock_all; */
26 static void release_vt(int signo)
28 ioctl(vfd, VT_RELDISP, (unsigned long) !option_mask32 /*!o_lock_all*/);
31 static void acquire_vt(int signo)
33 ioctl(vfd, VT_RELDISP, VT_ACKACQ);
36 int vlock_main(int argc, char **argv);
37 int vlock_main(int argc, char **argv)
51 bb_error_msg_and_die("unknown uid %d", uid);
57 /*o_lock_all = */getopt32(argv, "a");
59 /* Avoid using statics - use constant fd */
60 xmove_fd(xopen(CURRENT_TTY, O_RDWR), vfd);
61 xioctl(vfd, VT_GETMODE, &vtm);
63 /* mask a bunch of signals */
64 sigprocmask(SIG_SETMASK, NULL, &sig);
65 sigdelset(&sig, SIGUSR1);
66 sigdelset(&sig, SIGUSR2);
67 sigaddset(&sig, SIGTSTP);
68 sigaddset(&sig, SIGTTIN);
69 sigaddset(&sig, SIGTTOU);
70 sigaddset(&sig, SIGHUP);
71 sigaddset(&sig, SIGCHLD);
72 sigaddset(&sig, SIGQUIT);
73 sigaddset(&sig, SIGINT);
75 sigemptyset(&(sa.sa_mask));
76 sa.sa_flags = SA_RESTART;
77 sa.sa_handler = release_vt;
78 sigaction(SIGUSR1, &sa, NULL);
79 sa.sa_handler = acquire_vt;
80 sigaction(SIGUSR2, &sa, NULL);
82 /* need to handle some signals so that we don't get killed by them */
83 sa.sa_handler = SIG_IGN;
84 sigaction(SIGHUP, &sa, NULL);
85 sigaction(SIGQUIT, &sa, NULL);
86 sigaction(SIGINT, &sa, NULL);
87 sigaction(SIGTSTP, &sa, NULL);
90 vtm.mode = VT_PROCESS;
93 ioctl(vfd, VT_SETMODE, &vtm);
95 tcgetattr(STDIN_FILENO, &oterm);
97 term.c_iflag &= ~BRKINT;
98 term.c_iflag |= IGNBRK;
99 term.c_lflag &= ~ISIG;
100 term.c_lflag &= ~(ECHO | ECHOCTL);
101 tcsetattr(STDIN_FILENO, TCSANOW, &term);
104 printf("Virtual console%s locked by %s.\n",
105 option_mask32 /*o_lock_all*/ ? "s" : "",
107 if (correct_password(pw)) {
110 bb_do_delay(FAIL_DELAY);
111 puts("Password incorrect");
114 ioctl(vfd, VT_SETMODE, &ovtm);
115 tcsetattr(STDIN_FILENO, TCSANOW, &oterm);
116 fflush_stdout_and_exit(0);