From d162a7b978a98b910e410dc10a40d5de12db0419 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 12 Jan 2022 23:19:11 +0100 Subject: sulogin: increase util-linux compatibility Change to root's HOME. Set some envvars. Steal ctty if necessary and possible. function old new delta sulogin_main 240 340 +100 setup_environment 225 233 +8 su_main 479 474 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 108/-5) Total: 103 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'include/libbb.h') diff --git a/include/libbb.h b/include/libbb.h index daa3107..a0ffbef 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1726,15 +1726,16 @@ extern void selinux_or_die(void) FAST_FUNC; /* setup_environment: - * if chdir pw->pw_dir: ok: else if to_tmp == 1: goto /tmp else: goto / or die - * if clear_env = 1: cd(pw->pw_dir), clear environment, then set + * if !SETUP_ENV_NO_CHDIR: + * if cd(pw->pw_dir): ok: else if SETUP_ENV_TO_TMP: cd(/tmp) else: cd(/) or die + * if SETUP_ENV_CLEARENV: cd(pw->pw_dir), clear environment, then set * TERM=(old value) * USER=pw->pw_name, LOGNAME=pw->pw_name * PATH=bb_default_[root_]path * HOME=pw->pw_dir * SHELL=shell - * else if change_env = 1: - * if not root (if pw->pw_uid != 0): + * else if SETUP_ENV_CHANGEENV: + * if not root (if pw->pw_uid != 0) or if SETUP_ENV_CHANGEENV_LOGNAME: * USER=pw->pw_name, LOGNAME=pw->pw_name * HOME=pw->pw_dir * SHELL=shell @@ -1743,10 +1744,11 @@ extern void selinux_or_die(void) FAST_FUNC; * NB: CHANGEENV and CLEARENV use setenv() - this leaks memory! * If setup_environment() is used is vforked child, this leaks memory _in parent too_! */ -#define SETUP_ENV_CHANGEENV (1 << 0) -#define SETUP_ENV_CLEARENV (1 << 1) -#define SETUP_ENV_TO_TMP (1 << 2) -#define SETUP_ENV_NO_CHDIR (1 << 4) +#define SETUP_ENV_CHANGEENV (1 << 0) +#define SETUP_ENV_CHANGEENV_LOGNAME (1 << 1) +#define SETUP_ENV_CLEARENV (1 << 2) +#define SETUP_ENV_TO_TMP (1 << 3) +#define SETUP_ENV_NO_CHDIR (1 << 4) void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; void nuke_str(char *str) FAST_FUNC; #if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM -- cgit v1.1