Skip to content

Commit b7e037f

Browse files
committed
install: do not call chown when called as root
- `pseudo` is a tool which simulates being root by intercepting calls to e.g. `geteuid` and `chown` (by using the `LD_PRELOAD` mechanism). This is used e.g. to build filesystems for embedded devices without running as root on the build machine. - the `chown` call getting removed in this commit does not work when running with `pseudo` and using `PSEUDO_IGNORE_PATHS`: in this case, the call to `geteuid()` gets intercepted by `libpseudo.so` and returns 0, however the call to `chown()` isn't intercepted by `libpseudo.so` in case it is in a path from `PSEUDO_IGNORE_PATHS`, and will thus fail since the process is not really root - the call to `chown()` was added in #5735 with the intent of making the test `install-C-root.sh` pass, however it isn't required (GNU coreutils also does not call `chown` just because `install` was called as root) Fixes #9116 Signed-off-by: Etienne Cordonnier <[email protected]>
1 parent 876ac06 commit b7e037f

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/uu/install/src/install.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,9 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR
711711
Ok(())
712712
}
713713

714-
/// Handle incomplete user/group parings for chown.
714+
/// Handle ownership changes when -o/--owner or -g/--group flags are used.
715715
///
716716
/// Returns a Result type with the Err variant containing the error message.
717-
/// If the user is root, revert the uid & gid
718717
///
719718
/// # Parameters
720719
///
@@ -735,11 +734,8 @@ fn chown_optional_user_group(path: &Path, b: &Behavior) -> UResult<()> {
735734
// Determine the owner and group IDs to be used for chown.
736735
let (owner_id, group_id) = if b.owner_id.is_some() || b.group_id.is_some() {
737736
(b.owner_id, b.group_id)
738-
} else if geteuid() == 0 {
739-
// Special case for root user.
740-
(Some(0), Some(0))
741737
} else {
742-
// No chown operation needed.
738+
// No chown operation needed - file ownership comes from process naturally.
743739
return Ok(());
744740
};
745741

0 commit comments

Comments
 (0)