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
This commit is contained in:
parent
037576d77b
commit
e5387a0574
@ -25,33 +25,34 @@ char *bb_askpass(int timeout, const char * prompt)
|
|||||||
|
|
||||||
char *ret;
|
char *ret;
|
||||||
int i;
|
int i;
|
||||||
struct sigaction sa;
|
struct sigaction sa, oldsa;
|
||||||
struct termios old, new;
|
struct termios tio, oldtio;
|
||||||
|
|
||||||
if (!passwd)
|
if (!passwd)
|
||||||
passwd = xmalloc(sizeof_passwd);
|
passwd = xmalloc(sizeof_passwd);
|
||||||
memset(passwd, 0, sizeof_passwd);
|
memset(passwd, 0, sizeof_passwd);
|
||||||
|
|
||||||
tcgetattr(STDIN_FILENO, &old);
|
tcgetattr(STDIN_FILENO, &oldtio);
|
||||||
tcflush(STDIN_FILENO, TCIFLUSH);
|
tcflush(STDIN_FILENO, TCIFLUSH);
|
||||||
|
tio = oldtio;
|
||||||
|
tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
|
||||||
|
tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
|
||||||
|
|
||||||
fputs(prompt, stdout);
|
memset(&sa, 0, sizeof(sa));
|
||||||
fflush(stdout);
|
/* sa.sa_flags = 0; - no SA_RESTART! */
|
||||||
|
/* SIGINT and SIGALRM will interrupt read below */
|
||||||
tcgetattr(STDIN_FILENO, &new);
|
|
||||||
new.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
|
|
||||||
new.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &new);
|
|
||||||
|
|
||||||
if (timeout) {
|
|
||||||
sa.sa_flags = 0;
|
|
||||||
sa.sa_handler = askpass_timeout;
|
sa.sa_handler = askpass_timeout;
|
||||||
|
sigaction(SIGINT, &sa, &oldsa);
|
||||||
|
if (timeout) {
|
||||||
sigaction(SIGALRM, &sa, NULL);
|
sigaction(SIGALRM, &sa, NULL);
|
||||||
alarm(timeout);
|
alarm(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fputs(prompt, stdout);
|
||||||
|
fflush(stdout);
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
/* On timeout, read will hopefully be interrupted by SIGALRM,
|
/* On timeout or Ctrl-C, read will hopefully be interrupted,
|
||||||
* and we return NULL */
|
* and we return NULL */
|
||||||
if (read(STDIN_FILENO, passwd, sizeof_passwd - 1) > 0) {
|
if (read(STDIN_FILENO, passwd, sizeof_passwd - 1) > 0) {
|
||||||
ret = passwd;
|
ret = passwd;
|
||||||
@ -67,8 +68,9 @@ char *bb_askpass(int timeout, const char * prompt)
|
|||||||
if (timeout) {
|
if (timeout) {
|
||||||
alarm(0);
|
alarm(0);
|
||||||
}
|
}
|
||||||
|
sigaction(SIGINT, &oldsa, NULL);
|
||||||
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &old);
|
tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -9,29 +9,26 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
static const char *const forbid[] = {
|
static const char forbid[] ALIGN1 =
|
||||||
"ENV",
|
"ENV" "\0"
|
||||||
"BASH_ENV",
|
"BASH_ENV" "\0"
|
||||||
"HOME",
|
"HOME" "\0"
|
||||||
"IFS",
|
"IFS" "\0"
|
||||||
"PATH",
|
"PATH" "\0"
|
||||||
"SHELL",
|
"SHELL" "\0"
|
||||||
"LD_LIBRARY_PATH",
|
"LD_LIBRARY_PATH" "\0"
|
||||||
"LD_PRELOAD",
|
"LD_PRELOAD" "\0"
|
||||||
"LD_TRACE_LOADED_OBJECTS",
|
"LD_TRACE_LOADED_OBJECTS" "\0"
|
||||||
"LD_BIND_NOW",
|
"LD_BIND_NOW" "\0"
|
||||||
"LD_AOUT_LIBRARY_PATH",
|
"LD_AOUT_LIBRARY_PATH" "\0"
|
||||||
"LD_AOUT_PRELOAD",
|
"LD_AOUT_PRELOAD" "\0"
|
||||||
"LD_NOWARN",
|
"LD_NOWARN" "\0"
|
||||||
"LD_KEEPDIR",
|
"LD_KEEPDIR" "\0";
|
||||||
(char *) 0
|
|
||||||
};
|
|
||||||
|
|
||||||
|
//static void catchalarm(int ATTRIBUTE_UNUSED junk)
|
||||||
static void catchalarm(int ATTRIBUTE_UNUSED junk)
|
//{
|
||||||
{
|
// exit(EXIT_FAILURE);
|
||||||
exit(EXIT_FAILURE);
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
@ -40,7 +37,7 @@ int sulogin_main(int argc, char **argv)
|
|||||||
char *cp;
|
char *cp;
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
char *timeout_arg;
|
char *timeout_arg;
|
||||||
const char *const *p;
|
const char *p;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
const char *shell;
|
const char *shell;
|
||||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
#if ENABLE_FEATURE_SHADOWPASSWDS
|
||||||
@ -71,10 +68,14 @@ int sulogin_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clear out anything dangerous from the environment */
|
/* Clear out anything dangerous from the environment */
|
||||||
for (p = forbid; *p; p++)
|
p = forbid;
|
||||||
unsetenv(*p);
|
do {
|
||||||
|
unsetenv(p);
|
||||||
|
p += strlen(p) + 1;
|
||||||
|
} while (*p);
|
||||||
|
|
||||||
signal(SIGALRM, catchalarm);
|
// bb_askpass() already handles this
|
||||||
|
// signal(SIGALRM, catchalarm);
|
||||||
|
|
||||||
pwd = getpwuid(0);
|
pwd = getpwuid(0);
|
||||||
if (!pwd) {
|
if (!pwd) {
|
||||||
@ -105,7 +106,7 @@ int sulogin_main(int argc, char **argv)
|
|||||||
bb_error_msg("login incorrect");
|
bb_error_msg("login incorrect");
|
||||||
}
|
}
|
||||||
memset(cp, 0, strlen(cp));
|
memset(cp, 0, strlen(cp));
|
||||||
signal(SIGALRM, SIG_DFL);
|
// signal(SIGALRM, SIG_DFL);
|
||||||
|
|
||||||
bb_info_msg("System Maintenance Mode");
|
bb_info_msg("System Maintenance Mode");
|
||||||
|
|
||||||
@ -123,5 +124,5 @@ int sulogin_main(int argc, char **argv)
|
|||||||
run_shell(shell, 1, NULL, NULL);
|
run_shell(shell, 1, NULL, NULL);
|
||||||
|
|
||||||
auth_error:
|
auth_error:
|
||||||
bb_error_msg_and_die("no password entry for 'root'");
|
bb_error_msg_and_die("no password entry for root");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user