aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-20 19:20:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-20 19:20:22 +0000
commite5387a0574a4da88411753c4df959a03629063c9 (patch)
treede01aa892793e9fa1857551256500670280a8daf
parent037576d77b62186551ad07b10eb46a73144b9f84 (diff)
downloadbusybox-w32-e5387a0574a4da88411753c4df959a03629063c9.tar.gz
busybox-w32-e5387a0574a4da88411753c4df959a03629063c9.tar.bz2
busybox-w32-e5387a0574a4da88411753c4df959a03629063c9.zip
bb_askpass: handle Ctrl-C, restore termoios on Ctrl-C.
sulogin: remove alarm handling, as it is redundant there. code shrink. After all differences cancel out: text data bss dec hex filename 777543 1000 9532 788075 c066b busybox_old 777543 1000 9532 788075 c066b busybox_unstripped
-rw-r--r--libbb/bb_askpass.c36
-rw-r--r--loginutils/sulogin.c61
2 files changed, 50 insertions, 47 deletions
diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c
index 435314ea0..fd12f92dc 100644
--- a/libbb/bb_askpass.c
+++ b/libbb/bb_askpass.c
@@ -17,7 +17,7 @@ static void askpass_timeout(int ATTRIBUTE_UNUSED ignore)
17{ 17{
18} 18}
19 19
20char *bb_askpass(int timeout, const char * prompt) 20char *bb_askpass(int timeout, const char *prompt)
21{ 21{
22 /* Was static char[BIGNUM] */ 22 /* Was static char[BIGNUM] */
23 enum { sizeof_passwd = 128 }; 23 enum { sizeof_passwd = 128 };
@@ -25,35 +25,36 @@ char *bb_askpass(int timeout, const char * prompt)
25 25
26 char *ret; 26 char *ret;
27 int i; 27 int i;
28 struct sigaction sa; 28 struct sigaction sa, oldsa;
29 struct termios old, new; 29 struct termios tio, oldtio;
30 30
31 if (!passwd) 31 if (!passwd)
32 passwd = xmalloc(sizeof_passwd); 32 passwd = xmalloc(sizeof_passwd);
33 memset(passwd, 0, sizeof_passwd); 33 memset(passwd, 0, sizeof_passwd);
34 34
35 tcgetattr(STDIN_FILENO, &old); 35 tcgetattr(STDIN_FILENO, &oldtio);
36 tcflush(STDIN_FILENO, TCIFLUSH); 36 tcflush(STDIN_FILENO, TCIFLUSH);
37 tio = oldtio;
38 tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
39 tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
40 tcsetattr(STDIN_FILENO, TCSANOW, &tio);
37 41
38 fputs(prompt, stdout); 42 memset(&sa, 0, sizeof(sa));
39 fflush(stdout); 43 /* sa.sa_flags = 0; - no SA_RESTART! */
40 44 /* SIGINT and SIGALRM will interrupt read below */
41 tcgetattr(STDIN_FILENO, &new); 45 sa.sa_handler = askpass_timeout;
42 new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); 46 sigaction(SIGINT, &sa, &oldsa);
43 new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
44 tcsetattr(STDIN_FILENO, TCSANOW, &new);
45
46 if (timeout) { 47 if (timeout) {
47 sa.sa_flags = 0;
48 sa.sa_handler = askpass_timeout;
49 sigaction(SIGALRM, &sa, NULL); 48 sigaction(SIGALRM, &sa, NULL);
50 alarm(timeout); 49 alarm(timeout);
51 } 50 }
52 51
52 fputs(prompt, stdout);
53 fflush(stdout);
53 ret = NULL; 54 ret = NULL;
54 /* On timeout, read will hopefully be interrupted by SIGALRM, 55 /* On timeout or Ctrl-C, read will hopefully be interrupted,
55 * and we return NULL */ 56 * and we return NULL */
56 if (read(STDIN_FILENO, passwd, sizeof_passwd-1) > 0) { 57 if (read(STDIN_FILENO, passwd, sizeof_passwd - 1) > 0) {
57 ret = passwd; 58 ret = passwd;
58 i = 0; 59 i = 0;
59 /* Last byte is guaranteed to be 0 60 /* Last byte is guaranteed to be 0
@@ -67,8 +68,9 @@ char *bb_askpass(int timeout, const char * prompt)
67 if (timeout) { 68 if (timeout) {
68 alarm(0); 69 alarm(0);
69 } 70 }
71 sigaction(SIGINT, &oldsa, NULL);
70 72
71 tcsetattr(STDIN_FILENO, TCSANOW, &old); 73 tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
72 bb_putchar('\n'); 74 bb_putchar('\n');
73 fflush(stdout); 75 fflush(stdout);
74 return ret; 76 return ret;
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 7f100a162..f633fbbf1 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -9,29 +9,26 @@
9 9
10#include "libbb.h" 10#include "libbb.h"
11 11
12static const char *const forbid[] = { 12static const char forbid[] ALIGN1 =
13 "ENV", 13 "ENV" "\0"
14 "BASH_ENV", 14 "BASH_ENV" "\0"
15 "HOME", 15 "HOME" "\0"
16 "IFS", 16 "IFS" "\0"
17 "PATH", 17 "PATH" "\0"
18 "SHELL", 18 "SHELL" "\0"
19 "LD_LIBRARY_PATH", 19 "LD_LIBRARY_PATH" "\0"
20 "LD_PRELOAD", 20 "LD_PRELOAD" "\0"
21 "LD_TRACE_LOADED_OBJECTS", 21 "LD_TRACE_LOADED_OBJECTS" "\0"
22 "LD_BIND_NOW", 22 "LD_BIND_NOW" "\0"
23 "LD_AOUT_LIBRARY_PATH", 23 "LD_AOUT_LIBRARY_PATH" "\0"
24 "LD_AOUT_PRELOAD", 24 "LD_AOUT_PRELOAD" "\0"
25 "LD_NOWARN", 25 "LD_NOWARN" "\0"
26 "LD_KEEPDIR", 26 "LD_KEEPDIR" "\0";
27 (char *) 0 27
28}; 28//static void catchalarm(int ATTRIBUTE_UNUSED junk)
29 29//{
30 30// exit(EXIT_FAILURE);
31static void catchalarm(int ATTRIBUTE_UNUSED junk) 31//}
32{
33 exit(EXIT_FAILURE);
34}
35 32
36 33
37int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 34int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -40,7 +37,7 @@ int sulogin_main(int argc, char **argv)
40 char *cp; 37 char *cp;
41 int timeout = 0; 38 int timeout = 0;
42 char *timeout_arg; 39 char *timeout_arg;
43 const char *const *p; 40 const char *p;
44 struct passwd *pwd; 41 struct passwd *pwd;
45 const char *shell; 42 const char *shell;
46#if ENABLE_FEATURE_SHADOWPASSWDS 43#if ENABLE_FEATURE_SHADOWPASSWDS
@@ -71,10 +68,14 @@ int sulogin_main(int argc, char **argv)
71 } 68 }
72 69
73 /* Clear out anything dangerous from the environment */ 70 /* Clear out anything dangerous from the environment */
74 for (p = forbid; *p; p++) 71 p = forbid;
75 unsetenv(*p); 72 do {
73 unsetenv(p);
74 p += strlen(p) + 1;
75 } while (*p);
76 76
77 signal(SIGALRM, catchalarm); 77// bb_askpass() already handles this
78// signal(SIGALRM, catchalarm);
78 79
79 pwd = getpwuid(0); 80 pwd = getpwuid(0);
80 if (!pwd) { 81 if (!pwd) {
@@ -105,7 +106,7 @@ int sulogin_main(int argc, char **argv)
105 bb_error_msg("login incorrect"); 106 bb_error_msg("login incorrect");
106 } 107 }
107 memset(cp, 0, strlen(cp)); 108 memset(cp, 0, strlen(cp));
108 signal(SIGALRM, SIG_DFL); 109// signal(SIGALRM, SIG_DFL);
109 110
110 bb_info_msg("System Maintenance Mode"); 111 bb_info_msg("System Maintenance Mode");
111 112
@@ -122,6 +123,6 @@ int sulogin_main(int argc, char **argv)
122 /* Exec login shell with no additional parameters. Never returns. */ 123 /* Exec login shell with no additional parameters. Never returns. */
123 run_shell(shell, 1, NULL, NULL); 124 run_shell(shell, 1, NULL, NULL);
124 125
125auth_error: 126 auth_error:
126 bb_error_msg_and_die("no password entry for 'root'"); 127 bb_error_msg_and_die("no password entry for root");
127} 128}