Skip to content

userdel: keep a mail spool the user does not own - #401

Open
pierre-warnier wants to merge 1 commit into
fix-392-userdel-missingfrom
fix-400-userdel-spool-owner
Open

pierre-warnier wants to merge 1 commit into
fix-392-userdel-missingfrom
fix-400-userdel-spool-owner

Conversation

@pierre-warnier

Copy link
Copy Markdown
Collaborator

Fixes #400

Stacked on #396, which changes the same code. The base is fix-392-userdel-missing for now; it will be retargeted to main once #396 lands.

Ubuntu 26.04 behaviour

Probed in ubuntu:26.04 with passwd 1:4.17.4-2ubuntu3, each case with a home the user owns:

/var/mail/LOGIN flags exit stderr spool account, home
regular file owned by root -r 12 userdel: /var/mail/LOGIN not owned by LOGIN, not removing kept removed
regular file owned by root -r -f 0 none removed removed
symlink to a root-owned file -r 12 same message link and file kept removed
symlink to a root-owned file -r -f 0 none link removed, file kept removed
symlink to a file LOGIN owns -r and -r -f 0 none link removed, file kept removed

Nothing goes to stdout. Ownership is that of the file the link points to (the links were root's own in every case), and only the link is ever unlinked.

Change

remove_mail_spool opens a descriptor on the spool's directory, stats the entry through it (following a link, so a dangling one is still "not found", as in #396), and unlinks through that same descriptor. Without -f, a spool owned by another uid is kept and said on stderr; the home is still removed and the exit status is 12. The same probe run against this build gives the same table.

Tests: five new cases in tests/by-util/test_userdel.rs; the two refusal cases fail before the fix (exit 0 instead of 12). The man page and CHANGELOG are updated.

Reviews welcome. Without objection, this will be merged after 7 days.

With -r, a mail spool that the user does not own is now kept, as
upstream does: "SPOOL not owned by LOGIN, not removing" on stderr, the
home still removed, exit 12. -f removes it. A spool that is a symlink is
judged by the file it points to, and only the link is ever removed.

The spool is looked up once through a descriptor on /var/mail, and the
unlink goes through that same descriptor.

Fixes #400
@pierre-warnier
pierre-warnier force-pushed the fix-392-userdel-missing branch from 1ae392c to 7783c18 Compare November 8, 2026 16:33
@pierre-warnier
pierre-warnier force-pushed the fix-400-userdel-spool-owner branch from 52a474b to f603a28 Compare November 8, 2026 16:33
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.

1 participant