Skip to content

Commit 3d16c36

Browse files
committed
feat: Support for SUDO_UID as fallback for ownership check on unix.
1 parent efa1423 commit 3d16c36

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

git-sec/src/identity.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,19 @@ mod impl_ {
3434
let uid = unsafe { libc::geteuid() };
3535
Ok(uid)
3636
}
37-
38-
Ok(owner_from_path(path)? == owner_of_current_process()?)
37+
use std::str::FromStr;
38+
39+
let owner_of_path = owner_from_path(path)?;
40+
let owner_of_process = owner_of_current_process()?;
41+
if owner_of_path == owner_of_process {
42+
Ok(true)
43+
} else if let Some(sudo_uid) =
44+
std::env::var_os("SUDO_UID").and_then(|val| val.to_str().and_then(|val_str| u32::from_str(val_str).ok()))
45+
{
46+
Ok(owner_of_path == sudo_uid)
47+
} else {
48+
Ok(false)
49+
}
3950
}
4051
}
4152

0 commit comments

Comments
 (0)