1 /* vi: set sw=4 ts=4: */
3 * Mini sulogin implementation for busybox
5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7 //config:config SULOGIN
8 //config: bool "sulogin (17 kb)"
10 //config: select FEATURE_SYSLOG
12 //config: sulogin is invoked when the system goes into single user
13 //config: mode (this is done through an entry in inittab).
15 //applet:IF_SULOGIN(APPLET_NOEXEC(sulogin, sulogin, BB_DIR_SBIN, BB_SUID_DROP, sulogin))
17 //kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o
19 //usage:#define sulogin_trivial_usage
20 //usage: "[-t N] [TTY]"
21 //usage:#define sulogin_full_usage "\n\n"
22 //usage: "Single user login\n"
23 //usage: "\n -t N Timeout"
28 int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29 int sulogin_main(int argc UNUSED_PARAM, char **argv)
35 /* Note: sulogin is not a suid app. It is meant to be run by init
36 * for single user / emergency mode. init starts it as root.
37 * Normal users (potentially malicious ones) can only run it under
38 * their UID, therefore no paranoia here is warranted:
39 * $LD_LIBRARY_PATH in env, TTY = /dev/sda
40 * are no more dangerous here than in e.g. cp applet.
43 logmode = LOGMODE_BOTH;
44 openlog(applet_name, 0, LOG_AUTH);
46 getopt32(argv, "t:+", &timeout);
52 dup(xopen(argv[0], O_RDWR));
59 bb_error_msg_and_die("no password entry for root");
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):"
70 /* ^D, ^C, timeout, or read error */
71 bb_error_msg("normal startup");
77 bb_do_delay(LOGIN_FAIL_DELAY);
78 bb_error_msg("Login incorrect");
81 bb_error_msg("starting shell for system maintenance");
83 IF_SELINUX(renew_current_security_context());
85 shell = getenv("SUSHELL");
87 shell = getenv("sushell");
89 shell = pwd->pw_shell;
91 /* Exec login shell with no additional parameters. Never returns. */
92 run_shell(shell, 1, NULL);