Skip to content

userdel: say when -r finds no mail spool or home - #396

Open
pierre-warnier wants to merge 3 commits into
mainfrom
fix-392-userdel-missing
Open

pierre-warnier wants to merge 3 commits into
mainfrom
fix-392-userdel-missing

Conversation

@pierre-warnier

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

Copy link
Copy Markdown
Collaborator

Fixes #392

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

userdel -r said nothing when the user's mail spool or home directory did not exist. Ubuntu 26.04's userdel prints LOGIN mail spool (PATH) not found and LOGIN home directory (PATH) not found on standard error, mail spool first, and still exits 0; an empty home field is reported as (). This does the same, handling the spool before the home as upstream does.

Checks

In the Debian container: cargo test --workspace (1066 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.

/// `userdel -r` says so when the mail spool or the home is not there, mail
/// spool first, on standard error and with exit 0, as Ubuntu 26.04's does.
#[test]
fn test_remove_reports_a_missing_mail_spool_and_home() {

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.

could you please split this into 4 tests? easier to see which case fails

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.

Split in 5586d94 into test_remove_reports_a_missing_mail_spool_and_home, test_remove_reports_a_missing_home, test_remove_reports_a_missing_mail_spool and test_remove_reports_an_empty_home_field.

@pierre-warnier
pierre-warnier changed the base branch from revert-393 to main November 4, 2026 09:33
@pierre-warnier
pierre-warnier force-pushed the fix-392-userdel-missing branch from 7826e86 to 5586d94 Compare November 4, 2026 09:33
shared_by_other: bool,
) -> Result<(), UserdelError> {
let mail = root.resolve(&format!("/var/mail/{login}"));
if mail.exists() {

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.

exists() follows symlinks: a dangling /var/mail/login link is reported as not found and left behind.
should we use symlink_metadata here?

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.

I checked Ubuntu 26.04 (passwd 1:4.17.4-2ubuntu3). userdel -r follows the link too. With a dangling /var/mail/LOGIN link it prints LOGIN mail spool (/var/mail/LOGIN) not found, exits 0 and leaves the link in place. A dangling home link gets LOGIN home directory (/home/LOGIN) not found, exit 0, and is also left in place. So exists() already matches it, and symlink_metadata would remove a link that Ubuntu keeps. 1ae392c adds a comment saying this and tests for both cases. I checked that both tests fail with symlink_metadata. When a link is removed it is never followed: the spool goes through remove_file, which unlinks it, and safe_remove_home refuses a symlinked home.

@sylvestre

Copy link
Copy Markdown
Collaborator

sorry but it needs to be rebased

`userdel -r` was silent when the user's mail spool or home directory did
not exist. Ubuntu 26.04's userdel prints `LOGIN mail spool (PATH) not
found` and `LOGIN home directory (PATH) not found` on standard error,
mail spool first, and still exits 0; an empty home field is reported as
`()`. Do the same, handling the spool before the home as upstream does.

Fixes #392
One test per case, so a failure names the case: both missing, only the
home missing, only the spool missing, and an empty home field.
Ubuntu 26.04's userdel -r follows the link: a dangling /var/mail/LOGIN
or home link is reported as not found, with exit 0, and left in place.
exists() follows it the same way; say so, and test both cases.
@pierre-warnier
pierre-warnier force-pushed the fix-392-userdel-missing branch from 1ae392c to 7783c18 Compare November 8, 2026 16:33
@pierre-warnier

Copy link
Copy Markdown
Collaborator Author

Rebased on main. New head: 7783c18

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.

userdel -r prints nothing when the mail spool or home is missing

2 participants