Skip to content

add SUDO_HOME (fixes #928) #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sudo/env/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn add_extra_env(
context.current_user.gid.to_string().into(),
);
environment.insert("SUDO_USER".into(), context.current_user.name.clone().into());
environment.insert("SUDO_HOME".into(), context.current_user.home.clone().into());
// target user
environment
.entry("MAIL".into())
Expand Down
2 changes: 2 additions & 0 deletions src/sudo/env/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const TESTS: &str = "
SUDO_GID=1000
SUDO_UID=1000
SUDO_USER=test
SUDO_HOME=/home/test
HOME=/root
LOGNAME=root
USER=root
Expand All @@ -52,6 +53,7 @@ const TESTS: &str = "
SUDO_GID=1000
SUDO_UID=1000
SUDO_USER=test
SUDO_HOME=/home/test
HOME=/home/test
LOGNAME=test
USER=test
Expand Down
2 changes: 2 additions & 0 deletions test-framework/sudo-compliance-tests/src/sudo/env_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn some_vars_are_preserved() {
let term = "some-term";
let sudo_command = "some-sudo-command";
let sudo_user = "some-sudo-user";
let sudo_home = "some-sudo-home";
let sudo_uid = "some-sudo-uid";
let sudo_gid = "some-sudo-gid";
let stdout = Command::new("env")
Expand All @@ -189,6 +190,7 @@ fn some_vars_are_preserved() {
&format!("TERM={term}"),
&format!("SUDO_COMMAND={sudo_command}"),
&format!("SUDO_USER={sudo_user}"),
&format!("SUDO_HOME={sudo_home}"),
&format!("SUDO_UID={sudo_uid}"),
&format!("SUDO_GID={sudo_gid}"),
&sudo_abs_path,
Expand Down
7 changes: 6 additions & 1 deletion test-framework/sudo-compliance-tests/src/sudo/sudoers/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ fn vars_with_target_user_specific_values(env_list: EnvList) {
fn sudo_env_vars(env_list: EnvList) {
let env = Env([
SUDOERS_ALL_ALL_NOPASSWD,
&format!("Defaults {env_list} = \"SUDO_COMMAND SUDO_GID SUDO_UID SUDO_USER\""),
&format!("Defaults {env_list} = \"SUDO_COMMAND SUDO_GID SUDO_UID SUDO_USER SUDO_HOME\""),
])
.build();

Expand All @@ -320,6 +320,7 @@ fn sudo_env_vars(env_list: EnvList) {
.arg("SUDO_GID=gid")
.arg("SUDO_UID=uid")
.arg("SUDO_USER=user")
.arg("SUDO_HOME=sudo_home")
.args(["sudo", "env"])
.output(&env)
.stdout();
Expand All @@ -329,6 +330,10 @@ fn sudo_env_vars(env_list: EnvList) {
assert_eq!(Some("0"), sudo_env.get("SUDO_GID").copied());
assert_eq!(Some("0"), sudo_env.get("SUDO_UID").copied());
assert_eq!(Some("root"), sudo_env.get("SUDO_USER").copied());

if let Some(val) = sudo_env.get("SUDO_HOME").copied() {
assert_eq!("/root", val);
}
}

fn user_set_to_preserved_logname_value(env_list: EnvList) {
Expand Down
Loading