Skip to content

shadow-core: allocate system IDs from the top of the range - #344

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:fix/342-system-ids-top-down
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:fix/342-system-ids-top-down

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Fixes #342

next_uid and next_gid take a system flag. For system accounts the next ID is one below the lowest system ID in use, starting at SYS_UID_MAX / SYS_GID_MAX, and once that reaches the bottom of the range, the highest free ID. Regular accounts keep the current rule. useradd -r, groupadd -r and newusers -r pass their flag through.

test_uid_allocation_system expected 101 (the lowest ID); it now expects 999, which is what GNU gives on an empty range.

Tests: unit tests for the countdown and the gap fallback, and root tests creating two system users and two system groups (999, then 998). All fail before, pass after. cargo test --workspace run as root in an Ubuntu 26.04 container: 947 passed (943 on main, plus the four 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, 12 command sequences (useradd -r, groupadd -r, -u 500, an existing 998, a deleted system user, -U, -N, and regular users) now give the same files and exit codes.

AI tools assisted with this contribution.

useradd -r, groupadd -r and newusers -r took the lowest free ID in SYS_UID_MIN..SYS_UID_MAX (101, 102, ...). shadow-utils counts down from SYS_UID_MAX instead (999, 998, ...), going one below the lowest system ID in use so a deleted account's ID is not handed out again, and only then filling the highest gap.
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.

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, groupadd: system IDs allocated from the bottom of the range

2 participants