setup_environment(): eliminate one parameter

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2010-02-26 09:52:45 +01:00
parent 99709ab033
commit fd686a262f
5 changed files with 16 additions and 11 deletions

View 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

View 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.

View 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();

View 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 */

View 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");