summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2020-03-23 08:23:22 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2020-03-23 08:23:22 +0000
commit3920ec2f846f7ebb004929a0bccbef481f867f11 (patch)
tree42c8604815a605669cfc1f78cd73733fd8b84313
parentb5b471acbfe024ca832aa18f73f49b3fbc3f14b9 (diff)
downloadpw-darwin-3920ec2f846f7ebb004929a0bccbef481f867f11.tar.gz
pw-darwin-3920ec2f846f7ebb004929a0bccbef481f867f11.tar.zst
pw-darwin-3920ec2f846f7ebb004929a0bccbef481f867f11.zip
pw: do not removed home directories if not owned
When deleting a user, if its home directory does not belong to it, it should not be removed. This is the promise that the manpage makes, the tool should ensure that it respects that promise. Add a regression test about it PR: 244967 Submitted by: Eric Hanneken <eric@erichanneken.com> MFC after: 3 days
-rw-r--r--pw/rm_r.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/pw/rm_r.c b/pw/rm_r.c
index 940266d..66298a2 100644
--- a/pw/rm_r.c
+++ b/pw/rm_r.c
@@ -71,5 +71,8 @@ rm_r(int rootfd, const char *path, uid_t uid)
closedir(d);
if (fstatat(rootfd, path, &st, AT_SYMLINK_NOFOLLOW) != 0)
return;
- unlinkat(rootfd, path, S_ISDIR(st.st_mode) ? AT_REMOVEDIR : 0);
+ if (S_ISLNK(st.st_mode))
+ unlinkat(rootfd, path, 0);
+ else if (st.st_uid == uid)
+ unlinkat(rootfd, path, AT_REMOVEDIR);
}