Skip to content

useradd: honor -U when USERGROUPS_ENAB is no, reject -U with -g - #345

Merged
sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:fix/343-useradd-user-group
Oct 25, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:fix/343-useradd-user-group

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Fixes #343

An explicit -U now always creates the user group; USERGROUPS_ENAB only decides when neither -U nor -N is given. -U conflicts with -g in 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 -N today.

Tests: a clap test for -U -g, and a root test where -U with USERGROUPS_ENAB no creates the group. Both fail before, pass after. cargo test --workspace run as root in an Ubuntu 26.04 container: 945 passed (943 on main, plus the two new). cargo fmt --check and cargo clippy --workspace --all-targets -- -D warnings are clean; the pam configurations were not run locally. Against GNU shadow 4.17.4 in the same container, USERGROUPS_ENAB yes/no with no flag, -U, -N, -g users and -U -g users give the same files and exit codes.

AI tools assisted with this contribution.

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.
Copilot AI balanced review requested due to automatic review settings October 23, 2026 06:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/uu/useradd/src/useradd.rs Outdated
#[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());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please check err().kind() == ErrorKind::ArgumentConflict instead of just is_err()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2545a28, it now asserts ErrorKind::ArgumentConflict.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

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
sylvestre merged commit 34855b6 into uutils:main Oct 25, 2026
13 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useradd: -U ignored when USERGROUPS_ENAB is no, accepted with -g

3 participants