setup_environment(): eliminate one parameter
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 26 Feb 2010 08:52:45 +0000 (09:52 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 26 Feb 2010 08:52:45 +0000 (09:52 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/libbb.h
libbb/setup_environment.c
loginutils/login.c
loginutils/su.c
miscutils/crontab.c

index 9d99b0d1afa8d281a89bf87dab72d2f984e1720d..98080e841ecf15f40591c6a2ab60bdeb423953b8 100644 (file)
@@ -1156,9 +1156,10 @@ extern int restricted_shell(const char *shell) FAST_FUNC;
  *   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
index f0802f0e5e23cfb2ecaca443602d71f74c01bd1e..13e60d8e422d05bc2095c493a8f39498107c8f90 100644 (file)
@@ -30,7 +30,7 @@
 
 #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 */
@@ -39,7 +39,7 @@ void FAST_FUNC setup_environment(const char *shell, int clear_env, int flags, co
                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.
index 974125d8832bd6b52e6f5b706af555ac0c150cad..b5e348b662fea3aa5d1a26a77a7d6cc4fc88bcb8 100644 (file)
@@ -477,8 +477,9 @@ int login_main(int argc UNUSED_PARAM, char **argv)
        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();
 
index a3f7ed8a08a24f7e883376e4ae381edae870a6ae..6356631b8f8cb0d16426a09aefaab4530f9fa7cd 100644 (file)
@@ -102,8 +102,10 @@ int su_main(int argc UNUSED_PARAM, char **argv)
                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 */
index 7d5709521ed94a5e29b663144b5443edc21dc3ea..5557bc491e0f000013207253d093f73b1d95fd0c 100644 (file)
@@ -32,8 +32,9 @@ static void edit_file(const struct passwd *pas, const char *file)
        /* 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");