Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/loginutils/vlock.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (hide annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2796 byte(s)
-updated to busybox-1.13.4
1 niro 532 /* 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     *
8     * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
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    
18     #include <sys/vt.h>
19 niro 816 #include "libbb.h"
20 niro 532
21 niro 816 static void release_vt(int signo UNUSED_PARAM)
22 niro 532 {
23 niro 816 /* 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);
26 niro 532 }
27    
28 niro 816 static void acquire_vt(int signo UNUSED_PARAM)
29 niro 532 {
30 niro 816 /* ACK to kernel that switch to console is successful */
31     ioctl(STDIN_FILENO, VT_RELDISP, VT_ACKACQ);
32 niro 532 }
33    
34 niro 816 int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
35     int vlock_main(int argc UNUSED_PARAM, char **argv)
36 niro 532 {
37     struct vt_mode vtm;
38     struct termios term;
39 niro 816 struct termios oterm;
40     struct vt_mode ovtm;
41     uid_t uid;
42     struct passwd *pw;
43     /* XXX: xgetpwuid */
44     uid = getuid();
45 niro 532 pw = getpwuid(uid);
46     if (pw == NULL)
47 niro 816 bb_error_msg_and_die("unknown uid %d", (int)uid);
48 niro 532
49 niro 816 opt_complementary = "=0"; /* no params! */
50     getopt32(argv, "a");
51 niro 532
52 niro 816 /* 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);
62 niro 532
63 niro 816 /* We will use SIGUSRx for console switch control: */
64     /* 1: set handlers */
65     signal_SA_RESTART_empty_mask(SIGUSR1, release_vt);
66     signal_SA_RESTART_empty_mask(SIGUSR2, acquire_vt);
67     /* 2: unmask them */
68     sig_unblock(SIGUSR1);
69     sig_unblock(SIGUSR2);
70 niro 532
71 niro 816 /* 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);
75 niro 532
76 niro 816 xioctl(STDIN_FILENO, VT_GETMODE, &vtm);
77 niro 532 ovtm = vtm;
78 niro 816 /* "console switches are controlled by us, not kernel!" */
79 niro 532 vtm.mode = VT_PROCESS;
80     vtm.relsig = SIGUSR1;
81     vtm.acqsig = SIGUSR2;
82 niro 816 ioctl(STDIN_FILENO, VT_SETMODE, &vtm);
83 niro 532
84     tcgetattr(STDIN_FILENO, &oterm);
85     term = oterm;
86     term.c_iflag &= ~BRKINT;
87     term.c_iflag |= IGNBRK;
88     term.c_lflag &= ~ISIG;
89     term.c_lflag &= ~(ECHO | ECHOCTL);
90 niro 816 tcsetattr_stdin_TCSANOW(&term);
91 niro 532
92     do {
93 niro 816 printf("Virtual console%s locked by %s.\n",
94     option_mask32 /*o_lock_all*/ ? "s" : "",
95     pw->pw_name);
96 niro 532 if (correct_password(pw)) {
97     break;
98     }
99     bb_do_delay(FAIL_DELAY);
100     puts("Password incorrect");
101     } while (1);
102 niro 816
103     ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);
104     tcsetattr_stdin_TCSANOW(&oterm);
105     fflush_stdout_and_exit(EXIT_SUCCESS);
106 niro 532 }