In -i mode always set new environment based on the runas user's passwd entry.

This commit is contained in:
Todd C. Miller
2004-01-19 01:17:00 +00:00
parent 1b7cf30c7b
commit 3001e7f296
2 changed files with 23 additions and 16 deletions

18
env.c
View File

@@ -307,9 +307,9 @@ insert_env(str, dupcheck)
* Also adds sudo-specific variables (SUDO_*). * Also adds sudo-specific variables (SUDO_*).
*/ */
char ** char **
rebuild_env(envp, reset_home, noexec) rebuild_env(envp, sudo_mode, noexec)
char **envp; char **envp;
int reset_home; int sudo_mode;
int noexec; int noexec;
{ {
char **ep, *cp, *ps1; char **ep, *cp, *ps1;
@@ -383,9 +383,16 @@ rebuild_env(envp, reset_home, noexec)
} }
/* /*
* Add in defaults unless they were preserved from the * Add in defaults. In -i mode these come from the runas user,
* user's environment. * otherwise they may be from the user's environment (depends
* on sudoers options).
*/ */
if (sudo_mode & MODE_LOGIN_SHELL) {
insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), 0);
insert_env(format_env("SHELL", runas_pw->pw_shell, VNULL), 0);
insert_env(format_env("LOGNAME", runas_pw->pw_name, VNULL), 0);
insert_env(format_env("USER", runas_pw->pw_name, VNULL), 0);
} else {
if (!(didvar & DID_HOME)) if (!(didvar & DID_HOME))
insert_env(format_env("HOME", user_dir, VNULL), 0); insert_env(format_env("HOME", user_dir, VNULL), 0);
if (!(didvar & DID_SHELL)) if (!(didvar & DID_SHELL))
@@ -394,6 +401,7 @@ rebuild_env(envp, reset_home, noexec)
insert_env(format_env("LOGNAME", user_name, VNULL), 0); insert_env(format_env("LOGNAME", user_name, VNULL), 0);
if (!(didvar & DID_USER)) if (!(didvar & DID_USER))
insert_env(format_env("USER", user_name, VNULL), 0); insert_env(format_env("USER", user_name, VNULL), 0);
}
} else { } else {
/* /*
* Copy envp entries as long as they don't match env_delete or * Copy envp entries as long as they don't match env_delete or
@@ -462,7 +470,7 @@ rebuild_env(envp, reset_home, noexec)
} }
/* Set $HOME for `sudo -H'. Only valid at PERM_FULL_RUNAS. */ /* Set $HOME for `sudo -H'. Only valid at PERM_FULL_RUNAS. */
if (reset_home && runas_pw->pw_dir) if ((sudo_mode & MODE_RESET_HOME) && runas_pw->pw_dir)
insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), 1); insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), 1);
/* /*

5
sudo.c
View File

@@ -132,7 +132,7 @@ extern struct passwd *sudo_pwdup __P((const struct passwd *));
* Globals * Globals
*/ */
int Argc, NewArgc; int Argc, NewArgc;
int sudo_mode; static int sudo_mode;
char **Argv, **NewArgv; char **Argv, **NewArgv;
struct sudo_user sudo_user; struct sudo_user sudo_user;
struct passwd *auth_pw; struct passwd *auth_pw;
@@ -344,8 +344,7 @@ main(argc, argv, envp)
check_user(validated & FLAG_CHECK_USER); check_user(validated & FLAG_CHECK_USER);
/* Build up custom environment that avoids any nasty bits. */ /* Build up custom environment that avoids any nasty bits. */
new_environ = rebuild_env(envp, (sudo_mode & MODE_RESET_HOME), new_environ = rebuild_env(envp, sudo_mode, (validated & FLAG_NOEXEC));
(validated & FLAG_NOEXEC));
if (validated & VALIDATE_OK) { if (validated & VALIDATE_OK) {
/* Finally tell the user if the command did not exist. */ /* Finally tell the user if the command did not exist. */