* SHELL=shell
* else does nothing
*/
-#define SETUP_ENV_CHANGEENV (1<<0)
-#define SETUP_ENV_TO_TMP (1<<1)
-extern void setup_environment(const char *shell, int clear_env, int flags, const struct passwd *pw) FAST_FUNC;
+#define SETUP_ENV_CHANGEENV (1 << 0)
+#define SETUP_ENV_CLEARENV (1 << 1)
+#define SETUP_ENV_TO_TMP (1 << 2)
+extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
extern int correct_password(const struct passwd *pw) FAST_FUNC;
/* Returns a malloced string */
#if !ENABLE_USE_BB_CRYPT
#include "libbb.h"
-void FAST_FUNC setup_environment(const char *shell, int clear_env, int flags, const struct passwd *pw)
+void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw)
{
/* Change the current working directory to be the home directory
* of the user */
bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
}
- if (clear_env) {
+ if (flags & SETUP_ENV_CLEARENV) {
const char *term;
/* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
tmp = pw->pw_shell;
if (!tmp || !*tmp)
tmp = DEFAULT_SHELL;
- /* setup_environment params: shell, clear_env, change_env, pw */
- setup_environment(tmp, !(opt & LOGIN_OPT_p), SETUP_ENV_CHANGEENV, pw);
+ setup_environment(tmp,
+ (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV,
+ pw);
motd();
opt_shell = pw->pw_shell;
change_identity(pw);
- /* setup_environment params: shell, clear_env, change_env, pw */
- setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw);
+ setup_environment(opt_shell,
+ ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV)
+ + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV),
+ pw);
IF_SELINUX(set_current_security_context(NULL);)
/* Never returns */
/* CHILD - change user and run editor */
/* initgroups, setgid, setuid */
change_identity(pas);
- setup_environment(DEFAULT_SHELL, 0,
- SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, pas);
+ setup_environment(DEFAULT_SHELL,
+ SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP,
+ pas);
ptr = getenv("VISUAL");
if (!ptr) {
ptr = getenv("EDITOR");