Repository navigation
useradd: honor -U when USERGROUPS_ENAB is no, reject -U with -g - #345
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
USERGROUPS_ENAB only sets the default. With it set to no, -U was ignored and the user got the default group. -U with -g was accepted and quietly created a new group instead of using the one given; GNU rejects the pair.
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
sylvestre
reviewed
Oct 24, 2026
| #[test] | ||
| fn test_clap_user_group_conflicts_with_gid() { | ||
| let result = uu_app().try_get_matches_from(["useradd", "-U", "-g", "100", "user"]); | ||
| assert!(result.is_err()); |
Collaborator
There was a problem hiding this comment.
could you please check err().kind() == ErrorKind::ArgumentConflict instead of just is_err()?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #343
An explicit
-Unow always creates the user group;USERGROUPS_ENABonly decides when neither-Unor-Nis given.-Uconflicts with-gin clap, the same way it already conflicts with-N, so the pair exits 2 like GNU. The message is clap's (the argument '--user-group' cannot be used with '--gid <GROUP>'), as for-U -Ntoday.Tests: a clap test for
-U -g, and a root test where-UwithUSERGROUPS_ENAB nocreates the group. Both fail before, pass after.cargo test --workspacerun as root in an Ubuntu 26.04 container: 945 passed (943 on main, plus the two new).cargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningsare clean; thepamconfigurations were not run locally. Against GNU shadow 4.17.4 in the same container,USERGROUPS_ENAByes/no with no flag,-U,-N,-g usersand-U -g usersgive the same files and exit codes.AI tools assisted with this contribution.