1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "libbb.h"
26#include <syslog.h>
27
28int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29int sulogin_main(int argc UNUSED_PARAM, char **argv)
30{
31 int timeout = 0;
32 struct passwd *pwd;
33 const char *shell;
34
35
36
37
38
39
40
41
42
43 logmode = LOGMODE_BOTH;
44 openlog(applet_name, 0, LOG_AUTH);
45
46 getopt32(argv, "t:+", &timeout);
47 argv += optind;
48
49 if (argv[0]) {
50 close(0);
51 close(1);
52 dup(xopen(argv[0], O_RDWR));
53 close(2);
54 dup(0);
55 }
56
57 pwd = getpwuid(0);
58 if (!pwd) {
59 bb_error_msg_and_die("no password entry for root");
60 }
61
62 while (1) {
63 int r;
64
65 r = ask_and_check_password_extended(pwd, timeout,
66 "Give root password for system maintenance\n"
67 "(or type Control-D for normal startup):"
68 );
69 if (r < 0) {
70
71 bb_info_msg("normal startup");
72 return 0;
73 }
74 if (r > 0) {
75 break;
76 }
77 bb_do_delay(LOGIN_FAIL_DELAY);
78 bb_info_msg("Login incorrect");
79 }
80
81 bb_info_msg("starting shell for system maintenance");
82
83 IF_SELINUX(renew_current_security_context());
84
85 shell = getenv("SUSHELL");
86 if (!shell)
87 shell = getenv("sushell");
88 if (!shell)
89 shell = pwd->pw_shell;
90
91
92 run_shell(shell, 1, NULL);
93}
94