Repository navigation
shadow-core: take the account names upstream takes - #395
Conversation
|
|
||
| ## GROUP NAMES | ||
|
|
||
| The new name given with **-n** follows the rule of **groupadd**(8). A group name is |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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.
57b01fb to
e290674
Compare
|
sorry but it needs to be rebased |
e290674 to
f536348
Compare
|
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.
f536348 to
387982c
Compare
Fixes #391
Split out of #393, as asked there. Based on #394, which reverts #393.
useradd,usermod -l,groupadd,groupmod -nandnewusersnow 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, andgroupmod -n -xis 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,
passwd1:4.17.4-2ubuntu3, on 2026-11-03:useradd -Uwith a 33-character name creates both the user and a 33-character group, exit 0.newusersrefuses that group withinvalid group name, exit 1, and creates nothing.groupaddrefuses the 33-character name, exit 3.useradd -U.So upstream is not consistent between the tools, and this PR matches each one. Our build, run in the Debian container:
useradd -Unewusersinvalid group name, nothing createdgroupaddChecks
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.