mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
chroot: resolve all ids before chroot
This commit is contained in:
committed by
Sylvestre Ledru
parent
968f938484
commit
f33bfb9321
@@ -390,17 +390,18 @@ fn set_supplemental_gids_with_strategy(
|
||||
|
||||
/// Change the root, set the user ID, and set the group IDs for this process.
|
||||
fn set_context(options: &Options) -> UResult<()> {
|
||||
enter_chroot(&options.newroot, options.skip_chdir)?;
|
||||
match &options.userspec {
|
||||
None | Some(UserSpec::NeitherGroupNorUser) => {
|
||||
let strategy = Strategy::Nothing;
|
||||
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||
enter_chroot(&options.newroot, options.skip_chdir)?;
|
||||
}
|
||||
Some(UserSpec::UserOnly(user)) => {
|
||||
let uid = name_to_uid(user)?;
|
||||
let gid = usr2gid(user).map_err(|_| ChrootError::NoGroupSpecified(uid))?;
|
||||
let strategy = Strategy::FromUID(uid, false);
|
||||
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||
enter_chroot(&options.newroot, options.skip_chdir)?;
|
||||
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(user.to_owned(), e))?;
|
||||
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_owned(), e))?;
|
||||
}
|
||||
@@ -408,6 +409,7 @@ fn set_context(options: &Options) -> UResult<()> {
|
||||
let gid = name_to_gid(group)?;
|
||||
let strategy = Strategy::Nothing;
|
||||
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||
enter_chroot(&options.newroot, options.skip_chdir)?;
|
||||
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_owned(), e))?;
|
||||
}
|
||||
Some(UserSpec::UserAndGroup(user, group)) => {
|
||||
@@ -415,6 +417,7 @@ fn set_context(options: &Options) -> UResult<()> {
|
||||
let gid = name_to_gid(group)?;
|
||||
let strategy = Strategy::FromUID(uid, true);
|
||||
set_supplemental_gids_with_strategy(strategy, options.groups.as_ref())?;
|
||||
enter_chroot(&options.newroot, options.skip_chdir)?;
|
||||
set_gid(gid).map_err(|e| ChrootError::SetGidFailed(group.to_owned(), e))?;
|
||||
set_uid(uid).map_err(|e| ChrootError::SetUserFailed(user.to_owned(), e))?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user