From b59da37365460f720d66ea1c02d746a2a2e0f336 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Thu, 2 Jan 2025 19:06:49 -0500 Subject: [PATCH] chroot: make Options.groups into an Option type Change the type of `Options.groups` to be `Option>` 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. --- src/uu/chroot/src/chroot.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index cad30552e..3da4e52d1 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -43,7 +43,7 @@ struct Options { /// Whether to change to the new root directory. skip_chdir: bool, /// List of groups under which the command will be run. - groups: Vec, + groups: Option>, /// The user and group (each optional) under which the command will be run. userspec: Option, } @@ -133,12 +133,12 @@ impl Options { None => return Err(ChrootError::MissingNewRoot.into()), }; let groups = match matches.get_one::(options::GROUPS) { - None => vec![], + None => None, Some(s) => { if s.is_empty() { - vec![] + Some(vec![]) } 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<()> { 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 { None | Some(UserSpec::NeitherGroupNorUser) => {} Some(UserSpec::UserOnly(user)) => set_user(user)?,