source: MondoRescue/branches/3.3/mindi-busybox/loginutils/sulogin.c

Last change on this file was 3621, checked in by Bruno Cornec, 7 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

File size: 2.3 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
[1765]2/*
3 * Mini sulogin implementation for busybox
4 *
[2725]5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[1765]6 */
[3621]7//config:config SULOGIN
8//config: bool "sulogin"
9//config: default y
10//config: select FEATURE_SYSLOG
11//config: help
12//config: sulogin is invoked when the system goes into single user
13//config: mode (this is done through an entry in inittab).
[1765]14
[3621]15//applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP))
16
17//kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o
18
[3232]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"
24
[2725]25#include "libbb.h"
[821]26#include <syslog.h>
27
[2725]28int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29int sulogin_main(int argc UNUSED_PARAM, char **argv)
[821]30{
31 int timeout = 0;
32 struct passwd *pwd;
[1765]33 const char *shell;
[821]34
[3621]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 malisious 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.
41 */
42
[1765]43 logmode = LOGMODE_BOTH;
44 openlog(applet_name, 0, LOG_AUTH);
45
[2725]46 opt_complementary = "t+"; /* -t N */
47 getopt32(argv, "t:", &timeout);
48 argv += optind;
[1765]49
[2725]50 if (argv[0]) {
[1765]51 close(0);
52 close(1);
[2725]53 dup(xopen(argv[0], O_RDWR));
[1765]54 close(2);
55 dup(0);
[821]56 }
[1765]57
58 pwd = getpwuid(0);
59 if (!pwd) {
[3621]60 bb_error_msg_and_die("no password entry for root");
[821]61 }
[1765]62
[821]63 while (1) {
[2725]64 int r;
65
[3621]66 r = ask_and_check_password_extended(pwd, timeout,
67 "Give root password for system maintenance\n"
68 "(or type Control-D for normal startup):"
69 );
70 if (r < 0) {
71 /* ^D, ^C, timeout, or read error */
72 bb_error_msg("normal startup");
[1765]73 return 0;
[821]74 }
[3621]75 if (r > 0) {
[821]76 break;
77 }
[3232]78 bb_do_delay(LOGIN_FAIL_DELAY);
[3621]79 bb_error_msg("Login incorrect");
[821]80 }
81
[3621]82 bb_error_msg("starting shell for system maintenance");
[821]83
[2725]84 IF_SELINUX(renew_current_security_context());
[821]85
[1765]86 shell = getenv("SUSHELL");
[2725]87 if (!shell)
88 shell = getenv("sushell");
89 if (!shell)
90 shell = pwd->pw_shell;
[1765]91
[2725]92 /* Exec login shell with no additional parameters. Never returns. */
93 run_shell(shell, 1, NULL, NULL);
[821]94}
Note: See TracBrowser for help on using the repository browser.