Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/loginutils/sulogin.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/loginutils/sulogin.c
r3232 r3621 5 5 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 6 */ 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 7 18 8 19 //usage:#define sulogin_trivial_usage … … 15 26 #include <syslog.h> 16 27 17 //static void catchalarm(int UNUSED_PARAM junk)18 //{19 // exit(EXIT_FAILURE);20 //}21 22 23 28 int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 24 29 int sulogin_main(int argc UNUSED_PARAM, char **argv) 25 30 { 26 char *cp;27 31 int timeout = 0; 28 32 struct passwd *pwd; 29 33 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 */ 35 42 36 43 logmode = LOGMODE_BOTH; … … 49 56 } 50 57 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"); 55 61 } 56 62 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_SHADOWPASSWDS66 {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 #endif77 78 63 while (1) { 79 char *encrypted;80 64 int r; 81 65 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"); 89 73 return 0; 90 74 } 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) { 95 76 break; 96 77 } 97 78 bb_do_delay(LOGIN_FAIL_DELAY); 98 bb_ info_msg("Login incorrect");79 bb_error_msg("Login incorrect"); 99 80 } 100 memset(cp, 0, strlen(cp));101 // signal(SIGALRM, SIG_DFL);102 81 103 bb_ info_msg("System Maintenance Mode");82 bb_error_msg("starting shell for system maintenance"); 104 83 105 84 IF_SELINUX(renew_current_security_context()); … … 113 92 /* Exec login shell with no additional parameters. Never returns. */ 114 93 run_shell(shell, 1, NULL, NULL); 115 116 auth_error:117 bb_error_msg_and_die("no password entry for root");118 94 }
Note:
See TracChangeset
for help on using the changeset viewer.