diff --git a/include/libbb.h b/include/libbb.h index a0ffbef62..780e9ae7d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1726,7 +1726,7 @@ extern void selinux_or_die(void) FAST_FUNC; /* setup_environment: - * if !SETUP_ENV_NO_CHDIR: + * if SETUP_ENV_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) @@ -1734,7 +1734,7 @@ extern void selinux_or_die(void) FAST_FUNC; * PATH=bb_default_[root_]path * HOME=pw->pw_dir * SHELL=shell - * else if SETUP_ENV_CHANGEENV: + * else if SETUP_ENV_CHANGEENV | SETUP_ENV_CHANGEENV_LOGNAME: * 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 @@ -1748,7 +1748,7 @@ extern void selinux_or_die(void) FAST_FUNC; #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) +#define SETUP_ENV_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 diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index df2983958..37777204e 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -36,7 +36,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass /* Change the current working directory to be the home directory * of the user */ - if (!(flags & SETUP_ENV_NO_CHDIR)) { + if (flags & SETUP_ENV_CHDIR) { if (chdir(pw->pw_dir) != 0) { bb_error_msg("can't change directory to '%s'", pw->pw_dir); xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); @@ -59,7 +59,8 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass //xsetenv("LOGNAME", pw->pw_name); //xsetenv("HOME", pw->pw_dir); //xsetenv("SHELL", shell); - } else if (flags & SETUP_ENV_CHANGEENV) { + } else + if (flags & (SETUP_ENV_CHANGEENV|SETUP_ENV_CHANGEENV_LOGNAME)) { /* Set HOME, SHELL, and if not becoming a super-user * or if SETUP_ENV_CHANGEENV_LOGNAME, USER and LOGNAME. */ if ((flags & SETUP_ENV_CHANGEENV_LOGNAME) || pw->pw_uid != 0) { diff --git a/loginutils/login.c b/loginutils/login.c index cac4349b2..332238181 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -564,7 +564,9 @@ int login_main(int argc UNUSED_PARAM, char **argv) change_identity(pw); setup_environment(pw->pw_shell, - (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV, + (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + + SETUP_ENV_CHANGEENV + + SETUP_ENV_CHDIR, pw); #if ENABLE_PAM diff --git a/loginutils/su.c b/loginutils/su.c index e1db7590f..6efe1981a 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -176,10 +176,9 @@ int su_main(int argc UNUSED_PARAM, char **argv) change_identity(pw); setup_environment(opt_shell, - ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) - + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV) - + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR), - pw); + ((flags & SU_OPT_l) ? (SETUP_ENV_CLEARENV + SETUP_ENV_CHDIR) : 0) + + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV), + pw); IF_SELINUX(set_current_security_context(NULL);) if (opt_command) { diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index c9817960c..681022acb 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -94,10 +94,13 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) shell = pwd->pw_shell; /* util-linux 2.36.1 compat: cd to root's HOME, set a few envvars */ - setup_environment(shell, SETUP_ENV_CHANGEENV | SETUP_ENV_CHANGEENV_LOGNAME, pwd); + setup_environment(shell, 0 + + SETUP_ENV_CHANGEENV_LOGNAME + + SETUP_ENV_CHDIR + , pwd); // no SETUP_ENV_CLEARENV - // SETUP_ENV_CHANGEENV[+LOGNAME] - set HOME, SHELL, USER,and LOGNAME - // no SETUP_ENV_NO_CHDIR - IOW: cd to $HOME + // SETUP_ENV_CHANGEENV_LOGNAME - set HOME, SHELL, USER,and LOGNAME + // SETUP_ENV_CHDIR - cd to $HOME /* util-linux 2.36.1 compat: steal ctty if we don't have it yet * (yes, util-linux uses force=1) */ diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 411a18a50..1111f4d54 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -55,8 +55,8 @@ static void edit_file(const struct passwd *pas, const char *file) /* initgroups, setgid, setuid */ change_identity(pas); setup_environment(pas->pw_shell, - SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, - pas); + SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP | SETUP_ENV_CHDIR, + pas); ptr = getenv("VISUAL"); if (!ptr) { ptr = getenv("EDITOR"); diff --git a/shell/ash.c b/shell/ash.c index 12b2db3a9..ca5c755b6 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10791,7 +10791,7 @@ preadfd(void) write(STDOUT_FILENO, "^C", 2); raise(SIGINT); /* raise(SIGINT) did not work! (e.g. if SIGINT - * is SIG_INGed on startup, it stays SIG_IGNed) + * is SIG_IGNed on startup, it stays SIG_IGNed) */ if (trap[SIGINT]) { buf[0] = '\n'; diff --git a/shell/hush.c b/shell/hush.c index 982fc356a..7d0dc67e4 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -10361,7 +10361,7 @@ int hush_main(int argc, char **argv) //it ignores TERM: // bash -i -c 'kill $$; echo ALIVE' // ALIVE -//it resets SIG_INGed HUP to SIG_DFL: +//it resets SIG_IGNed HUP to SIG_DFL: // trap '' hup; bash -i -c 'kill -hup $$; echo ALIVE' // Hangup [the message is not printed by bash, it's the shell which started it] //is talkative about jobs and exiting: