Skip to content

useradd, usermod: accept -1 for -f and -e - #339

Merged
sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:fix/338-negative-one-inactive-expiredate
Oct 22, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
jayhemnani9910:fix/338-negative-one-inactive-expiredate

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #338

-f -1 and -e -1 are documented in useradd(8) and usermod(8), and the value handling already turns -1 into an empty field, but clap rejected -1 as an unknown argument. The four arguments now set allow_hyphen_values, as chage does for the same options.

Tests: parse tests for -f -1 -e -1 in useradd and usermod (fail before, pass after). cargo test --workspace run as root in an Ubuntu 26.04 container: 941 passed (939 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, useradd -f -1, useradd -e -1, usermod -f -1 and usermod -e -1 now give the same files and exit codes.

AI tools assisted with this contribution.

useradd(8) and usermod(8) document -1 for --inactive and --expiredate, and
the value handling already maps it to an empty field, but clap rejected -1 as
an unknown argument. chage already allows hyphen values for these options.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:29

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.

}

#[test]
fn test_negative_one_inactive_and_expiredate() {

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 also add a test in tests/by-util/test_usermod.rs checking that -e -1 / -f -1 blank the shadow fields? thanks

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.

Added test_negative_one_blanks_inactive_and_expiredate in 9de8fb5: it starts from a shadow line with inactive 30 and expire 19782, runs usermod -e -1 -f -1, and checks both fields come out empty. It fails on main.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 13:20

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.

@sylvestre
sylvestre merged commit 2e1032a into uutils:main Oct 22, 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, usermod: -f -1 and -e -1 rejected as unknown arguments

3 participants