source: MondoRescue/branches/2.2.9/mindi-busybox/loginutils/vlock.c@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 2.7 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * vlock implementation for busybox
4 *
5 * Copyright (C) 2000 by spoon <spoon@ix.netcom.com>
6 * Written by spoon <spon@ix.netcom.com>
7 *
[2725]8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]9 */
10
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
13 * minimalistic vlock.
14 */
15/* Fixed by Erik Andersen to do passwords the tinylogin way...
16 * It now works with md5, sha1, etc passwords. */
17
[1765]18#include "libbb.h"
[2725]19
20#ifdef __linux__
[821]21#include <sys/vt.h>
22
[2725]23static void release_vt(int signo UNUSED_PARAM)
[821]24{
[2725]25 /* If -a, param is 0, which means:
26 * "no, kernel, we don't allow console switch away from us!" */
27 ioctl(STDIN_FILENO, VT_RELDISP, (unsigned long) !option_mask32);
[821]28}
29
[2725]30static void acquire_vt(int signo UNUSED_PARAM)
[821]31{
[2725]32 /* ACK to kernel that switch to console is successful */
33 ioctl(STDIN_FILENO, VT_RELDISP, VT_ACKACQ);
[821]34}
[2725]35#endif
[821]36
[2725]37int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38int vlock_main(int argc UNUSED_PARAM, char **argv)
[821]39{
[2725]40#ifdef __linux__
[821]41 struct vt_mode vtm;
[2725]42 struct vt_mode ovtm;
43#endif
[821]44 struct termios term;
[2725]45 struct termios oterm;
46 struct passwd *pw;
[821]47
[2725]48 pw = xgetpwuid(getuid());
49 opt_complementary = "=0"; /* no params! */
50 getopt32(argv, "a");
[1765]51
[2725]52 /* Ignore some signals so that we don't get killed by them */
53 bb_signals(0
54 + (1 << SIGTSTP)
55 + (1 << SIGTTIN)
56 + (1 << SIGTTOU)
57 + (1 << SIGHUP )
58 + (1 << SIGCHLD) /* paranoia :) */
59 + (1 << SIGQUIT)
60 + (1 << SIGINT )
61 , SIG_IGN);
[821]62
[2725]63#ifdef __linux__
64 /* We will use SIGUSRx for console switch control: */
65 /* 1: set handlers */
66 signal_SA_RESTART_empty_mask(SIGUSR1, release_vt);
67 signal_SA_RESTART_empty_mask(SIGUSR2, acquire_vt);
68 /* 2: unmask them */
69 sig_unblock(SIGUSR1);
70 sig_unblock(SIGUSR2);
71#endif
[821]72
[2725]73 /* Revert stdin/out to our controlling tty
74 * (or die if we have none) */
75 xmove_fd(xopen(CURRENT_TTY, O_RDWR), STDIN_FILENO);
76 xdup2(STDIN_FILENO, STDOUT_FILENO);
[821]77
[2725]78#ifdef __linux__
79 xioctl(STDIN_FILENO, VT_GETMODE, &vtm);
[821]80 ovtm = vtm;
[2725]81 /* "console switches are controlled by us, not kernel!" */
[821]82 vtm.mode = VT_PROCESS;
83 vtm.relsig = SIGUSR1;
84 vtm.acqsig = SIGUSR2;
[2725]85 ioctl(STDIN_FILENO, VT_SETMODE, &vtm);
86#endif
[821]87
88 tcgetattr(STDIN_FILENO, &oterm);
89 term = oterm;
90 term.c_iflag &= ~BRKINT;
91 term.c_iflag |= IGNBRK;
92 term.c_lflag &= ~ISIG;
93 term.c_lflag &= ~(ECHO | ECHOCTL);
[2725]94 tcsetattr_stdin_TCSANOW(&term);
[821]95
96 do {
[2725]97 printf("Virtual console%s locked by %s.\n",
98 option_mask32 /*o_lock_all*/ ? "s" : "",
99 pw->pw_name);
[1765]100 if (correct_password(pw)) {
[821]101 break;
102 }
103 bb_do_delay(FAIL_DELAY);
[1765]104 puts("Password incorrect");
[821]105 } while (1);
[2725]106
107#ifdef __linux__
108 ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);
109#endif
110 tcsetattr_stdin_TCSANOW(&oterm);
111 fflush_stdout_and_exit(EXIT_SUCCESS);
[821]112}
Note: See TracBrowser for help on using the repository browser.