Skip to content

usermod: add -m/--move-home - #350

Open
jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:fix/348-usermod-move-home
Open

jayhemnani9910 wants to merge 1 commit into
uutils:mainfrom
jayhemnani9910:fix/348-usermod-move-home

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #348

Builds on #349: the first commit here is that PR. I will rebase once it merges.

-m needs -d (clap, exit 2). After the account files are written, the old home is renamed to the new path; across filesystems it is copied, keeping owners, modes, times, hard links, symlinks and fifos, then the old tree is removed. A failed copy removes the partial new tree and leaves the old one. Like GNU: new path exists, exit 12; move fails, exit 12 with /etc/passwd already updated; old home missing, a warning and exit 0; old tree not fully removable after a copy, a warning and exit 0. With -u or -g the home is re-owned at its new path.

The user owns the tree being copied and can swap entries while it runs, so the copy walks it through directory fds (openat with O_NOFOLLOW) and copies the attributes of what it actually opened. The new tree stays root-owned 0700 until the end. Not copied: xattrs and ACLs; sparse files are written out in full.

Tests: a unit test for the copy (hard link, symlink, fifo, mode, mtime), root tests for a move and for a move onto an existing directory (exit 12), and -m without -d. cargo test --workspace run as root in an Ubuntu 26.04 container: 950 passed (946 with the -g PR, plus the four new). cargo fmt --check and cargo clippy --workspace --all-targets -- -D warnings are clean. Against GNU shadow 4.17.4 in the same container (old home on the overlay, new home on overlay or tmpfs), moves with -u, -g, -l, a foreign-owned file, a setuid file, a hard link, a symlink and a fifo give the same tree, ownership, times and exit codes.

AI tools assisted with this contribution.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 07:19

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 insufficient remaining quota.

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.

@jayhemnani9910
jayhemnani9910 force-pushed the fix/348-usermod-move-home branch from 2853a4b to a7fe69b Compare October 24, 2026 18:57
Copilot AI balanced review requested due to automatic review settings October 24, 2026 18:57

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 insufficient remaining quota.

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.

@jayhemnani9910
jayhemnani9910 force-pushed the fix/348-usermod-move-home branch from a7fe69b to 62b7459 Compare October 25, 2026 14:51
Copilot AI balanced review requested due to automatic review settings October 25, 2026 14:51

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 insufficient remaining quota.

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.

usermod: -m/--move-home is not implemented

2 participants