Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/loginutils/sulogin.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/loginutils/sulogin.c
r1765 r2725 3 3 * Mini sulogin implementation for busybox 4 4 * 5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.5 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 6 */ 7 7 8 #include "libbb.h" 8 9 #include <syslog.h> 9 10 10 #include "libbb.h" 11 12 static const char *const forbid[] = { 13 "ENV", 14 "BASH_ENV", 15 "HOME", 16 "IFS", 17 "PATH", 18 "SHELL", 19 "LD_LIBRARY_PATH", 20 "LD_PRELOAD", 21 "LD_TRACE_LOADED_OBJECTS", 22 "LD_BIND_NOW", 23 "LD_AOUT_LIBRARY_PATH", 24 "LD_AOUT_PRELOAD", 25 "LD_NOWARN", 26 "LD_KEEPDIR", 27 (char *) 0 28 }; 11 //static void catchalarm(int UNUSED_PARAM junk) 12 //{ 13 // exit(EXIT_FAILURE); 14 //} 29 15 30 16 31 static void catchalarm(int ATTRIBUTE_UNUSED junk) 32 { 33 exit(EXIT_FAILURE); 34 } 35 36 37 int sulogin_main(int argc, char **argv); 38 int sulogin_main(int argc, char **argv) 17 int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 18 int sulogin_main(int argc UNUSED_PARAM, char **argv) 39 19 { 40 20 char *cp; 41 21 int timeout = 0; 42 char *timeout_arg;43 const char *const *p;44 22 struct passwd *pwd; 45 23 const char *shell; … … 48 26 char buffer[256]; 49 27 struct spwd spw; 50 struct spwd *result;51 28 #endif 52 29 … … 54 31 openlog(applet_name, 0, LOG_AUTH); 55 32 56 if (getopt32(argv, "t:", &timeout_arg)) {57 timeout = xatoi_u(timeout_arg);58 }33 opt_complementary = "t+"; /* -t N */ 34 getopt32(argv, "t:", &timeout); 35 argv += optind; 59 36 60 if (argv[ optind]) {37 if (argv[0]) { 61 38 close(0); 62 39 close(1); 63 dup(xopen(argv[ optind], O_RDWR));40 dup(xopen(argv[0], O_RDWR)); 64 41 close(2); 65 42 dup(0); 66 43 } 67 44 45 /* Malicious use like "sulogin /dev/sda"? */ 68 46 if (!isatty(0) || !isatty(1) || !isatty(2)) { 69 47 logmode = LOGMODE_SYSLOG; … … 71 49 } 72 50 73 /* Clear out anything dangerous from the environment */ 74 for (p = forbid; *p; p++) 75 unsetenv(*p); 76 77 signal(SIGALRM, catchalarm); 51 /* Clear dangerous stuff, set PATH */ 52 sanitize_env_if_suid(); 78 53 79 54 pwd = getpwuid(0); … … 83 58 84 59 #if ENABLE_FEATURE_SHADOWPASSWDS 85 if (getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result)) { 86 goto auth_error; 60 { 61 /* getspnam_r may return 0 yet set result to NULL. 62 * At least glibc 2.4 does this. Be extra paranoid here. */ 63 struct spwd *result = NULL; 64 int r = getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result); 65 if (r || !result) { 66 goto auth_error; 67 } 68 pwd->pw_passwd = result->sp_pwdp; 87 69 } 88 pwd->pw_passwd = spw.sp_pwdp;89 70 #endif 90 71 91 72 while (1) { 73 char *encrypted; 74 int r; 75 92 76 /* cp points to a static buffer that is zeroed every time */ 93 cp = bb_ask pass(timeout,77 cp = bb_ask(STDIN_FILENO, timeout, 94 78 "Give root password for system maintenance\n" 95 79 "(or type Control-D for normal startup):"); … … 99 83 return 0; 100 84 } 101 if (strcmp(pw_encrypt(cp, pwd->pw_passwd), pwd->pw_passwd) == 0) { 85 encrypted = pw_encrypt(cp, pwd->pw_passwd, 1); 86 r = strcmp(encrypted, pwd->pw_passwd); 87 free(encrypted); 88 if (r == 0) { 102 89 break; 103 90 } … … 106 93 } 107 94 memset(cp, 0, strlen(cp)); 108 signal(SIGALRM, SIG_DFL);95 // signal(SIGALRM, SIG_DFL); 109 96 110 97 bb_info_msg("System Maintenance Mode"); 111 98 112 USE_SELINUX(renew_current_security_context());99 IF_SELINUX(renew_current_security_context()); 113 100 114 101 shell = getenv("SUSHELL"); 115 if (!shell) shell = getenv("sushell"); 116 if (!shell) { 117 shell = "/bin/sh"; 118 if (pwd->pw_shell[0]) 119 shell = pwd->pw_shell; 120 } 121 run_shell(shell, 1, 0, 0); 122 /* never returns */ 102 if (!shell) 103 shell = getenv("sushell"); 104 if (!shell) 105 shell = pwd->pw_shell; 123 106 124 auth_error: 125 bb_error_msg_and_die("no password entry for 'root'"); 107 /* Exec login shell with no additional parameters. Never returns. */ 108 run_shell(shell, 1, NULL, NULL); 109 110 auth_error: 111 bb_error_msg_and_die("no password entry for root"); 126 112 }
Note:
See TracChangeset
for help on using the changeset viewer.