Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

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

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/loginutils/sulogin.c

    r3232 r3621  
    55 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    66 */
     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).
     14
     15//applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP))
     16
     17//kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o
    718
    819//usage:#define sulogin_trivial_usage
     
    1526#include <syslog.h>
    1627
    17 //static void catchalarm(int UNUSED_PARAM junk)
    18 //{
    19 //  exit(EXIT_FAILURE);
    20 //}
    21 
    22 
    2328int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    2429int sulogin_main(int argc UNUSED_PARAM, char **argv)
    2530{
    26     char *cp;
    2731    int timeout = 0;
    2832    struct passwd *pwd;
    2933    const char *shell;
    30 #if ENABLE_FEATURE_SHADOWPASSWDS
    31     /* Using _r function to avoid pulling in static buffers */
    32     char buffer[256];
    33     struct spwd spw;
    34 #endif
     34
     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     */
    3542
    3643    logmode = LOGMODE_BOTH;
     
    4956    }
    5057
    51     /* Malicious use like "sulogin /dev/sda"? */
    52     if (!isatty(0) || !isatty(1) || !isatty(2)) {
    53         logmode = LOGMODE_SYSLOG;
    54         bb_error_msg_and_die("not a tty");
     58    pwd = getpwuid(0);
     59    if (!pwd) {
     60        bb_error_msg_and_die("no password entry for root");
    5561    }
    5662
    57     /* Clear dangerous stuff, set PATH */
    58     sanitize_env_if_suid();
    59 
    60     pwd = getpwuid(0);
    61     if (!pwd) {
    62         goto auth_error;
    63     }
    64 
    65 #if ENABLE_FEATURE_SHADOWPASSWDS
    66     {
    67         /* getspnam_r may return 0 yet set result to NULL.
    68          * At least glibc 2.4 does this. Be extra paranoid here. */
    69         struct spwd *result = NULL;
    70         int r = getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result);
    71         if (r || !result) {
    72             goto auth_error;
    73         }
    74         pwd->pw_passwd = result->sp_pwdp;
    75     }
    76 #endif
    77 
    7863    while (1) {
    79         char *encrypted;
    8064        int r;
    8165
    82         /* cp points to a static buffer that is zeroed every time */
    83         cp = bb_ask(STDIN_FILENO, timeout,
    84                 "Give root password for system maintenance\n"
    85                 "(or type Control-D for normal startup):");
    86 
    87         if (!cp || !*cp) {
    88             bb_info_msg("Normal startup");
     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");
    8973            return 0;
    9074        }
    91         encrypted = pw_encrypt(cp, pwd->pw_passwd, 1);
    92         r = strcmp(encrypted, pwd->pw_passwd);
    93         free(encrypted);
    94         if (r == 0) {
     75        if (r > 0) {
    9576            break;
    9677        }
    9778        bb_do_delay(LOGIN_FAIL_DELAY);
    98         bb_info_msg("Login incorrect");
     79        bb_error_msg("Login incorrect");
    9980    }
    100     memset(cp, 0, strlen(cp));
    101 //  signal(SIGALRM, SIG_DFL);
    10281
    103     bb_info_msg("System Maintenance Mode");
     82    bb_error_msg("starting shell for system maintenance");
    10483
    10584    IF_SELINUX(renew_current_security_context());
     
    11392    /* Exec login shell with no additional parameters. Never returns. */
    11493    run_shell(shell, 1, NULL, NULL);
    115 
    116  auth_error:
    117     bb_error_msg_and_die("no password entry for root");
    11894}
Note: See TracChangeset for help on using the changeset viewer.