aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-09 14:00:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-09 14:00:58 +0000
commit9852d5a1e65d23dece9bdfa2483409dda258748f (patch)
tree311f3b43614b9fcf0e3adf508b944ac458b8e18d
parent8fafacd7ec2ea70cb46b28e59c4c9b7473c44ca9 (diff)
downloadbusybox-w32-9852d5a1e65d23dece9bdfa2483409dda258748f.tar.gz
busybox-w32-9852d5a1e65d23dece9bdfa2483409dda258748f.tar.bz2
busybox-w32-9852d5a1e65d23dece9bdfa2483409dda258748f.zip
sulogin: minor cleanup.
-rw-r--r--loginutils/sulogin.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 15f3fb260..fef3760e9 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -9,10 +9,6 @@
9 9
10#include "busybox.h" 10#include "busybox.h"
11 11
12
13#define SULOGIN_PROMPT "Give root password for system maintenance\n" \
14 "(or type Control-D for normal startup):"
15
16static const char * const forbid[] = { 12static const char * const forbid[] = {
17 "ENV", 13 "ENV",
18 "BASH_ENV", 14 "BASH_ENV",
@@ -32,7 +28,6 @@ static const char * const forbid[] = {
32}; 28};
33 29
34 30
35
36static void catchalarm(int ATTRIBUTE_UNUSED junk) 31static void catchalarm(int ATTRIBUTE_UNUSED junk)
37{ 32{
38 exit(EXIT_FAILURE); 33 exit(EXIT_FAILURE);
@@ -48,10 +43,8 @@ int sulogin_main(int argc, char **argv)
48 struct passwd *pwd; 43 struct passwd *pwd;
49 struct spwd *spwd; 44 struct spwd *spwd;
50 45
51 if (ENABLE_FEATURE_SYSLOG) { 46 logmode = LOGMODE_BOTH;
52 logmode = LOGMODE_BOTH; 47 openlog(bb_applet_name, 0, LOG_AUTH);
53 openlog(bb_applet_name, LOG_CONS | LOG_NOWAIT, LOG_AUTH);
54 }
55 48
56 if (bb_getopt_ulflags (argc, argv, "t:", &timeout_arg)) { 49 if (bb_getopt_ulflags (argc, argv, "t:", &timeout_arg)) {
57 if (safe_strtoi(timeout_arg, &timeout)) { 50 if (safe_strtoi(timeout_arg, &timeout)) {
@@ -68,7 +61,8 @@ int sulogin_main(int argc, char **argv)
68 } 61 }
69 62
70 if (!isatty(0) || !isatty(1) || !isatty(2)) { 63 if (!isatty(0) || !isatty(1) || !isatty(2)) {
71 bb_error_msg_and_die("Not a tty"); 64 logmode = LOGMODE_SYSLOG;
65 bb_error_msg_and_die("not a tty");
72 } 66 }
73 67
74 /* Clear out anything dangerous from the environment */ 68 /* Clear out anything dangerous from the environment */
@@ -78,28 +72,31 @@ int sulogin_main(int argc, char **argv)
78 signal(SIGALRM, catchalarm); 72 signal(SIGALRM, catchalarm);
79 73
80 if (!(pwd = getpwuid(0))) { 74 if (!(pwd = getpwuid(0))) {
81 goto AUTH_ERROR; 75 goto auth_error;
82 } 76 }
83 77
84 if (ENABLE_FEATURE_SHADOWPASSWDS) { 78 if (ENABLE_FEATURE_SHADOWPASSWDS) {
85 if (!(spwd = getspnam(pwd->pw_name))) { 79 if (!(spwd = getspnam(pwd->pw_name))) {
86 goto AUTH_ERROR; 80 goto auth_error;
87 } 81 }
88 pwd->pw_passwd = spwd->sp_pwdp; 82 pwd->pw_passwd = spwd->sp_pwdp;
89 } 83 }
90 84
91 while (1) { 85 while (1) {
92 /* cp points to a static buffer that is zeroed every time */ 86 /* cp points to a static buffer that is zeroed every time */
93 cp = bb_askpass(timeout, SULOGIN_PROMPT); 87 cp = bb_askpass(timeout,
88 "Give root password for system maintenance\n"
89 "(or type Control-D for normal startup):");
90
94 if (!cp || !*cp) { 91 if (!cp || !*cp) {
95 bb_info_msg("Normal startup"); 92 bb_info_msg("Normal startup");
96 exit(EXIT_SUCCESS); 93 return 0;
97 } 94 }
98 if (strcmp(pw_encrypt(cp, pwd->pw_passwd), pwd->pw_passwd) == 0) { 95 if (strcmp(pw_encrypt(cp, pwd->pw_passwd), pwd->pw_passwd) == 0) {
99 break; 96 break;
100 } 97 }
101 bb_do_delay(FAIL_DELAY); 98 bb_do_delay(FAIL_DELAY);
102 bb_error_msg("Login incorrect"); 99 bb_error_msg("login incorrect");
103 } 100 }
104 memset(cp, 0, strlen(cp)); 101 memset(cp, 0, strlen(cp));
105 signal(SIGALRM, SIG_DFL); 102 signal(SIGALRM, SIG_DFL);
@@ -110,6 +107,7 @@ int sulogin_main(int argc, char **argv)
110 107
111 run_shell(pwd->pw_shell, 1, 0, 0); 108 run_shell(pwd->pw_shell, 1, 0, 0);
112 /* never returns */ 109 /* never returns */
113AUTH_ERROR: 110
114 bb_error_msg_and_die("No password entry for `root'"); 111auth_error:
112 bb_error_msg_and_die("no password entry for `root'");
115} 113}