Skip to content

Take upstream's account names, report a missing spool or home in userdel -r - #393

Merged
pierre-warnier merged 2 commits into
mainfrom
fix-391-392
Nov 3, 2026
Merged

pierre-warnier merged 2 commits into
mainfrom
fix-391-392

Conversation

@pierre-warnier

Copy link
Copy Markdown
Collaborator

Two parity fixes, each probed against Ubuntu 26.04's passwd 1:4.17.4-2ubuntu3 in ubuntu:26.04.

Account names (#391)

The shared check for a new name wanted a letter or _ first, no trailing dot and at most 32 characters, so usermod -l 0abc was exit 3. A batch probe of useradd, usermod -l, groupadd, groupmod -n and newusers over 40 names shows all five apply the rule pwck and grpck already follow here, plus a refused leading -:

name upstream (all five) before
0abc, 1e5, .abc, a., ..., 123$, 0xg, 1.5 accepted refused
123, 0, 00, 0x1a, 0o7 (reads as an ID) refused refused
-x, ., .., $, a$b, a@b, é refused refused
33 to 255 characters user: accepted; group: refused refused

So a leading digit is fine, and an all-numeric name stays refused everywhere: 123 is taken for a UID.

  • shadow-core: validate_username is replaced by is_valid_user_name (255) and is_valid_group_name (32), built on is_valid_account_name. pwck and grpck share the two length constants.
  • Each tool prints upstream's message and exit code for a refused name: useradd 19, usermod 3, groupadd 3 ('X' is not a valid group name), groupmod 3, newusers 1 (the fault, then line N: can't create user).
  • newusers checks the group it creates for a line against the group rule, as upstream does. This matters now that a user name can be longer than a group name.
  • groupmod -n -x takes -x as the name, as usermod -l already does, so it is exit 3 and not a usage error.
  • chfn and chsh only look up an existing account. They do not judge names: chsh/chfn on 0abc succeed upstream.

userdel -r (#392)

Upstream prints LOGIN mail spool (PATH) not found and LOGIN home directory (PATH) not found on stderr, mail spool first, and exits 0. For an empty home field it prints (). userdel -r now does the same and handles the spool before the home.

Tests

Each commit adds tests that fail on main: 5 per-tool integration tests for #391, plus probe tables in validate.rs, and one for #392 covering both missing, either one missing, and an empty home field. cargo test --workspace (1060 passed), clippy -D warnings (default, pam, all features) and cargo fmt --check are clean in the debian image. Man pages and CHANGELOG are updated.

Fixes #391
Fixes #392

The shared check for a new name allowed only a letter or `_` first, no
trailing dot, and 32 characters, so `usermod -l 0abc` was exit 3 where
upstream renames the account. Probing Ubuntu 26.04's useradd, usermod -l,
groupadd, groupmod -n and newusers shows they all apply the rule pwck and
grpck already follow here, plus a refused leading `-`: a name may start
with a digit or a dot and end with a dot; what is refused is a name that
reads as a number (`123`, `0x1a`, `0o7`), `.`, `..`, and anything outside
the portable set. A user name runs to 255 characters, a group name to 32.

validate_username is replaced by is_valid_user_name and
is_valid_group_name on top of is_valid_account_name, and each tool now
prints upstream's message for a refused name. newusers checks the group
it creates for a line against the group rule, which upstream does and
which matters now that a user name can be longer than a group name.
groupmod -n takes a value starting with `-` as the name, as usermod -l
does, so `groupmod -n -x` is exit 3 rather than a usage error.

Fixes #391
`userdel -r` was silent when the user's mail spool or home directory did
not exist. Ubuntu 26.04's userdel prints `LOGIN mail spool (PATH) not
found` and `LOGIN home directory (PATH) not found` on standard error,
mail spool first, and still exits 0; an empty home field is reported as
`()`. Do the same, handling the spool before the home as upstream does.

Fixes #392
@pierre-warnier
pierre-warnier merged commit d3ddb11 into main Nov 3, 2026
13 checks passed
@pierre-warnier
pierre-warnier deleted the fix-391-392 branch November 3, 2026 10:41
@sylvestre

Copy link
Copy Markdown
Collaborator

thanks for working on this!
Before this can land, please confirm with upstream what useradd does with a user name over 32 characters when it also creates the user group. newusers refuses that group, but useradd creates it here.
Also, please split this into two PRs, one per issue.

@pierre-warnier

Copy link
Copy Markdown
Collaborator Author

Sorry, this was merged before CI and before your review. That was my mistake, and I've stopped using auto-merge here.

Following your comment:

On the 32-character question, against Ubuntu 26.04's passwd 1:4.17.4-2ubuntu3:

  • useradd -U with a 33-character name creates the user and a 33-character group (exit 0);
  • newusers refuses that group (invalid group name, exit 1, nothing created);
  • groupadd refuses the 33-character name (exit 3).

Upstream is inconsistent there, and our build gives the same result for each tool, at both 32 and 33 characters. The details are in #395.

sylvestre pushed a commit that referenced this pull request Nov 3, 2026
… in userdel -r (#393)"

This reverts commit d3ddb11. It was merged before CI finished and
before review. The work will come back as two pull requests, one for
#391 (account names) and one for #392 (userdel -r with a missing mail
spool or home).
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.

userdel -r prints nothing when the mail spool or home is missing usermod -l rejects a name starting with a digit

2 participants