Repository navigation
userdel: keep a mail spool the user does not own - #401
pierre-warnier wants to merge 5 commits into
Conversation
1ae392c to
7783c18
Compare
52a474b to
f603a28
Compare
|
|
||
| if spool_kept { | ||
| // Already said above, in its place before anything about the home. | ||
| return Err(shadow_core::cli::AlreadyPrinted(exit_codes::CANT_REMOVE_HOME).into()); |
There was a problem hiding this comment.
this early return skips the selinux remove_login, the nscd invalidation and the audit log in uumain, while the account is already gone.
could the 12 be returned only after those, no?
please add a test too
There was a problem hiding this comment.
Fixed in 5310d60: the 12 is now returned after the SELinux mapping, the nscd invalidation and the audit record have run, as Ubuntu 26.04 also logs the deletion in this case. The new test checks the exit 12, that the account is gone, and that the DEL_USER audit line is written; it fails on the previous code (79671f9 moves the /dev/log listener into the shared test helpers for it).
| /// Remove the mail spool at `mail` unless it belongs to someone other than | ||
| /// `uid` and `force` is not given. | ||
| /// | ||
| /// Ownership is that of the file the entry leads to: Ubuntu 26.04's `userdel |
There was a problem hiding this comment.
please make it shorter, the PR description already has the Ubuntu table
| if !force && target.st_uid != uid { | ||
| return Spool::NotOwned; | ||
| } | ||
| // A failed unlink has never been reported here; that is not this check's to change. |
There was a problem hiding this comment.
not sure this comment helps, could you please drop it or just say why we ignore the error?
There was a problem hiding this comment.
Reduced to one line in 6ddbe39: the error was already ignored before this PR, while upstream warns and exits 12, which is a separate fix.
| /// `kind` is `"file"` for a regular spool, or `"link"` for a spool that is a | ||
| /// symlink to a file outside /var/mail; that file, or the spool itself, is | ||
| /// owned by `owner`. | ||
| fn spool_case(kind: &str, owner: u32) -> SpoolCase { |
There was a problem hiding this comment.
could kind be a bool or a small enum instead of a string?
There was a problem hiding this comment.
It is a bool now, as there are only two cases (83115ec).
7783c18 to
f87bf97
Compare
f603a28 to
83115ec
Compare
f87bf97 to
678d679
Compare
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
usermod's audit test had it to itself. A second test that listens would find the socket taken by the first and skip without a word, so the listener moves to the common helpers and takes a lock that keeps the next test waiting until the socket is gone.
The account is already removed when -r gets to the spool and the home, so returning there skipped the SELinux login mapping, the nscd invalidation and the audit record, all of which concern the account. What is kept is now said where it was, and exit 12 is returned once those have run. Ubuntu 26.04's userdel logs the deletion in this case as well.
83115ec to
0befa85
Compare
Fixes #400
Stacked on #396, which changes the same code. The base is
fix-392-userdel-missingfor now; it will be retargeted tomainonce #396 lands.Ubuntu 26.04 behaviour
Probed in
ubuntu:26.04withpasswd1:4.17.4-2ubuntu3, each case with a home the user owns:/var/mail/LOGIN-ruserdel: /var/mail/LOGIN not owned by LOGIN, not removing-r -f-r-r -f-rand-r -fNothing 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_spoolopens 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.