1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

chroot: make Options.groups into an Option type

Change the type of `Options.groups` to be `Option<Vec<String>>` so that
the absence of the `--groups` option is meaningfully distinguished from
an empty list of groups. This is important because `chroot --groups=''`
is used specifically to disable supplementary group lookup.
This commit is contained in:
Jeffrey Finkelstein 2025-01-02 19:06:49 -05:00
parent 52c05e2fd6
commit b59da37365

View file

@ -43,7 +43,7 @@ struct Options {
/// Whether to change to the new root directory. /// Whether to change to the new root directory.
skip_chdir: bool, skip_chdir: bool,
/// List of groups under which the command will be run. /// List of groups under which the command will be run.
groups: Vec<String>, groups: Option<Vec<String>>,
/// The user and group (each optional) under which the command will be run. /// The user and group (each optional) under which the command will be run.
userspec: Option<UserSpec>, userspec: Option<UserSpec>,
} }
@ -133,12 +133,12 @@ impl Options {
None => return Err(ChrootError::MissingNewRoot.into()), None => return Err(ChrootError::MissingNewRoot.into()),
}; };
let groups = match matches.get_one::<String>(options::GROUPS) { let groups = match matches.get_one::<String>(options::GROUPS) {
None => vec![], None => None,
Some(s) => { Some(s) => {
if s.is_empty() { if s.is_empty() {
vec![] Some(vec![])
} else { } else {
parse_group_list(s)? Some(parse_group_list(s)?)
} }
} }
}; };
@ -288,7 +288,9 @@ pub fn uu_app() -> Command {
fn set_context(options: &Options) -> UResult<()> { fn set_context(options: &Options) -> UResult<()> {
enter_chroot(&options.newroot, options.skip_chdir)?; enter_chroot(&options.newroot, options.skip_chdir)?;
set_groups_from_str(&options.groups)?; if let Some(groups) = &options.groups {
set_groups_from_str(groups)?;
}
match &options.userspec { match &options.userspec {
None | Some(UserSpec::NeitherGroupNorUser) => {} None | Some(UserSpec::NeitherGroupNorUser) => {}
Some(UserSpec::UserOnly(user)) => set_user(user)?, Some(UserSpec::UserOnly(user)) => set_user(user)?,