Skip to content

shadow-core: take the account names upstream takes - #395

Merged
pierre-warnier merged 4 commits into
mainfrom
fix-391-account-names
Dec 5, 2026
Merged

pierre-warnier merged 4 commits into
mainfrom
fix-391-account-names

Conversation

@pierre-warnier

@pierre-warnier pierre-warnier commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #391

Split out of #393, as asked there. Based on #394, which reverts #393.

useradd, usermod -l, groupadd, groupmod -n and newusers now take the names upstream takes: a name may start with a digit or a dot and end with a dot; a name that reads as a number (123, 0x1a, 0o7), a leading -, . and .. stay refused. A user name runs to 255 characters, a group name to 32. Each tool prints upstream's message for a refused name, and groupmod -n -x is exit 3 instead of a usage error.

A user name over 32 characters when a group is created for it

To answer the question on #393, I checked upstream on Ubuntu 26.04, passwd 1:4.17.4-2ubuntu3, on 2026-11-03:

  • useradd -U with a 33-character name creates both the user and a 33-character group, exit 0.
  • newusers refuses that group with invalid group name, exit 1, and creates nothing.
  • groupadd refuses the 33-character name, exit 3.
  • A 32-character name is accepted by useradd -U.

So upstream is not consistent between the tools, and this PR matches each one. Our build, run in the Debian container:

32 characters 33 characters
useradd -U exit 0, user and group exit 0, user and 33-character group
newusers exit 0, user and group exit 1, invalid group name, nothing created
groupadd exit 0 exit 3, not a valid group name

Checks

In the Debian container: cargo test --workspace (1059 passed, 0 failed), cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --all --check.

Reviews welcome. Without objection, this will be merged after 7 days.

Comment thread docs/man/groupmod.8.md Outdated

## GROUP NAMES

The new name given with **-n** follows the rule of **groupadd**(8). A group name is

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.

it says it follows groupadd(8), then repeats the whole rule anyway
could we keep only the pointer? same for usermod.8.md and newusers.8.md

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in adfe171: groupmod.8, usermod.8 and newusers.8 now only point to groupadd(8) or useradd(8), and keep what differs per tool (exit status, -b/--badname). groupadd.8 and useradd.8 hold the full rule.

/// a leading `-` (an option), `.` and `..` (paths), and anything outside the
/// portable set. A user name may run to 255 characters.
#[test]
fn test_user_names_follow_upstream() {

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.

the PR description says useradd -U with a 33 chars name creates a 33 chars group
could you please add a test for that too? :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added in 02cc14f: test_user_group_takes_a_33_character_name runs useradd -U with a 33-character name and checks exit 0, the user and the 33-character group. The description also says newusers refuses that group, so e290674 adds test_refuses_a_33_character_group: exit 1, invalid group name, passwd, shadow and group unchanged.

@pierre-warnier
pierre-warnier changed the base branch from revert-393 to main November 4, 2026 09:32
@sylvestre

Copy link
Copy Markdown
Collaborator

sorry but it needs to be rebased

@pierre-warnier

Copy link
Copy Markdown
Collaborator Author

Rebased on main. New head: f536348

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
groupmod.8, usermod.8 and newusers.8 said the name follows groupadd(8)
or useradd(8), then repeated the whole rule. Keep the pointer and what
differs per tool, the exit status and the bypass option.
useradd -U with a name one character over the group limit creates the
user and a group of the same name, exit 0, as upstream does.
The name useradd -U takes is refused by newusers for the group it would
create: exit 1, invalid group name, and passwd, shadow and group are left
as they were.
@pierre-warnier
pierre-warnier merged commit 111498c into main Dec 5, 2026
13 checks passed
@pierre-warnier
pierre-warnier deleted the fix-391-account-names branch December 5, 2026 10:49
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.

usermod -l rejects a name starting with a digit

2 participants