Repository navigation
shadow-core: allocate system IDs from the top of the range - #344
jayhemnani9910 wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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.
| //! returning the lowest unused value in the configured range. Range | ||
| //! Finds the next available UID or GID by scanning existing entries: one past | ||
| //! the highest in use for regular accounts, one below the lowest in use for | ||
| //! system accounts. Range |
There was a problem hiding this comment.
please reflow this paragraph, "Range" alone at the end of the line looks odd
| let directory = |id: u32| id == 1001 || id == 1002; | ||
| assert_eq!(next_free_checked(&used, 1000, 1005, &directory), Some(1003)); | ||
| assert_eq!( | ||
| next_free_checked(&used, 1000, 1005, false, &directory), |
There was a problem hiding this comment.
could you please add the same case with system = true? (directory holds 999 and 998, expect 997)
| // reallocating would orphan every file the account owns. | ||
| ("", Some(i)) => passwd.entries()[i].uid, | ||
| ("", None) => uid_alloc::next_uid(passwd.entries(), uid_min, uid_max, scope) | ||
| ("", None) => uid_alloc::next_uid(passwd.entries(), uid_min, uid_max, system, scope) |
There was a problem hiding this comment.
please add a test for newusers -r in tests/by-util/test_newusers.rs too
Fixes #342
next_uidandnext_gidtake asystemflag. For system accounts the next ID is one below the lowest system ID in use, starting atSYS_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 -randnewusers -rpass their flag through.test_uid_allocation_systemexpected 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 --workspacerun as root in an Ubuntu 26.04 container: 947 passed (943 on main, plus the four new).cargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningsare clean; thepamconfigurations 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.