1 /* vi: set sw=4 ts=4: */
3 * Mini sulogin implementation for busybox
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 static const char * const forbid[] = {
21 "LD_TRACE_LOADED_OBJECTS",
23 "LD_AOUT_LIBRARY_PATH",
31 static void catchalarm(int ATTRIBUTE_UNUSED junk)
37 int sulogin_main(int argc, char **argv);
38 int sulogin_main(int argc, char **argv)
43 const char * const *p;
46 #if ENABLE_FEATURE_SHADOWPASSWDS
47 /* Using _r function to avoid pulling in static buffers */
53 logmode = LOGMODE_BOTH;
54 openlog(applet_name, 0, LOG_AUTH);
56 if (getopt32(argc, argv, "t:", &timeout_arg)) {
57 timeout = xatoi_u(timeout_arg);
63 dup(xopen(argv[optind], O_RDWR));
68 if (!isatty(0) || !isatty(1) || !isatty(2)) {
69 logmode = LOGMODE_SYSLOG;
70 bb_error_msg_and_die("not a tty");
73 /* Clear out anything dangerous from the environment */
74 for (p = forbid; *p; p++)
77 signal(SIGALRM, catchalarm);
84 #if ENABLE_FEATURE_SHADOWPASSWDS
85 if (getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result)) {
88 pwd->pw_passwd = spw.sp_pwdp;
92 /* cp points to a static buffer that is zeroed every time */
93 cp = bb_askpass(timeout,
94 "Give root password for system maintenance\n"
95 "(or type Control-D for normal startup):");
98 bb_info_msg("Normal startup");
101 if (strcmp(pw_encrypt(cp, pwd->pw_passwd), pwd->pw_passwd) == 0) {
104 bb_do_delay(FAIL_DELAY);
105 bb_error_msg("login incorrect");
107 memset(cp, 0, strlen(cp));
108 signal(SIGALRM, SIG_DFL);
110 bb_info_msg("System Maintenance Mode");
112 USE_SELINUX(renew_current_security_context());
114 shell = getenv("SUSHELL");
115 if (!shell) shell = getenv("sushell");
118 if (pwd->pw_shell[0])
119 shell = pwd->pw_shell;
121 run_shell(shell, 1, 0, 0);
125 bb_error_msg_and_die("no password entry for 'root'");