From 2a2ca935309bfacbc7f87de752f869a89748052c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 19 Mar 2021 00:27:44 +0100 Subject: [PATCH] login: implement LOGIN_TIMEOUT function old new delta packed_usage 33559 33598 +39 login_main 953 986 +33 .rodata 103161 103175 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 86/0) Total: 86 bytes Signed-off-by: Denys Vlasenko --- loginutils/login.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/loginutils/login.c b/loginutils/login.c index 21c32fc25..66ac7cf4c 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -60,6 +60,11 @@ //usage: "\n -f Don't authenticate (user already authenticated)" //usage: "\n -h HOST Host user came from (for network logins)" //usage: "\n -p Preserve environment" +//usage: "\n" +//usage: "\n$LOGIN_TIMEOUT Seconds (default 60, 0 - disable)" +//usage: IF_LOGIN_SCRIPTS( +//usage: "\n$LOGIN_PRE_SUID_SCRIPT Execute before user ID change" +//usage: ) #include "libbb.h" #include "common_bufsiz.h" @@ -130,7 +135,6 @@ static const struct pam_conv conv = { #endif enum { - TIMEOUT = 60, EMPTY_USERNAME_COUNT = 10, /* Some users found 32 chars limit to be too low: */ USERNAME_SIZE = 64, @@ -139,6 +143,7 @@ enum { struct globals { struct termios tty_attrs; + int timeout; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { setup_common_bufsiz(); } while (0) @@ -302,7 +307,7 @@ static void alarm_handler(int sig UNUSED_PARAM) * when you are back at shell prompt, echo will be still off. */ tcsetattr_stdin_TCSANOW(&G.tty_attrs); - printf("\r\nLogin timed out after %u seconds\r\n", TIMEOUT); + printf("\r\nLogin timed out after %u seconds\r\n", G.timeout); fflush_all(); /* unix API is brain damaged regarding O_NONBLOCK, * we should undo it, or else we can affect other processes */ @@ -345,6 +350,8 @@ int login_main(int argc UNUSED_PARAM, char **argv) INIT_G(); + G.timeout = xatoi_positive(getenv("LOGIN_TIMEOUT") ? : "60"); + /* More of suid paranoia if called by non-root: */ /* Clear dangerous stuff, set PATH */ run_by_root = !sanitize_env_if_suid(); @@ -376,7 +383,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) /* We install timeout handler only _after_ we saved G.tty_attrs */ signal(SIGALRM, alarm_handler); - alarm(TIMEOUT); + alarm(G.timeout); /* Find out and memorize our tty name */ full_tty = xmalloc_ttyname(STDIN_FILENO);