|
|
a3e2b5 |
From bbe9ac11d8d4a8511214605509a593fb9f04ffaa Mon Sep 17 00:00:00 2001
|
|
|
a3e2b5 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
a3e2b5 |
Date: Fri, 19 Oct 2018 11:28:40 +0200
|
|
|
a3e2b5 |
Subject: [PATCH] chown-recursive: also drop ACLs when recursively chown()ing
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
Let's better be safe than sorry and also drop ACLs.
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
(cherry-picked from commit f89bc84f3242449cbc308892c87573b131f121df)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
Related: #1643368
|
|
|
a3e2b5 |
---
|
|
|
a3e2b5 |
src/core/chown-recursive.c | 16 ++++++++++++----
|
|
|
a3e2b5 |
1 file changed, 12 insertions(+), 4 deletions(-)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
diff --git a/src/core/chown-recursive.c b/src/core/chown-recursive.c
|
|
|
a3e2b5 |
index 27c64489b5..447b771267 100644
|
|
|
a3e2b5 |
--- a/src/core/chown-recursive.c
|
|
|
a3e2b5 |
+++ b/src/core/chown-recursive.c
|
|
|
a3e2b5 |
@@ -3,6 +3,7 @@
|
|
|
a3e2b5 |
#include <fcntl.h>
|
|
|
a3e2b5 |
#include <sys/stat.h>
|
|
|
a3e2b5 |
#include <sys/types.h>
|
|
|
a3e2b5 |
+#include <sys/xattr.h>
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
#include "chown-recursive.h"
|
|
|
a3e2b5 |
#include "dirent-util.h"
|
|
|
a3e2b5 |
@@ -14,6 +15,7 @@
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
static int chown_one(int fd, const struct stat *st, uid_t uid, gid_t gid) {
|
|
|
a3e2b5 |
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
|
|
|
a3e2b5 |
+ const char *n;
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
assert(fd >= 0);
|
|
|
a3e2b5 |
assert(st);
|
|
|
a3e2b5 |
@@ -26,13 +28,19 @@ static int chown_one(int fd, const struct stat *st, uid_t uid, gid_t gid) {
|
|
|
a3e2b5 |
* O_PATH. (Note: fchown() and fchmod() do not work with O_PATH, the kernel refuses that. */
|
|
|
a3e2b5 |
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
+ /* Drop any ACL if there is one */
|
|
|
a3e2b5 |
+ FOREACH_STRING(n, "system.posix_acl_access", "system.posix_acl_default")
|
|
|
a3e2b5 |
+ if (removexattr(procfs_path, n) < 0)
|
|
|
a3e2b5 |
+ if (!IN_SET(errno, ENODATA, EOPNOTSUPP, ENOSYS, ENOTTY))
|
|
|
a3e2b5 |
+ return -errno;
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
if (chown(procfs_path, uid, gid) < 0)
|
|
|
a3e2b5 |
return -errno;
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
- /* The linux kernel alters the mode in some cases of chown(). Let's undo this. We do this only for non-symlinks
|
|
|
a3e2b5 |
- * however. That's because for symlinks the access mode is ignored anyway and because on some kernels/file
|
|
|
a3e2b5 |
- * systems trying to change the access mode will succeed but has no effect while on others it actively
|
|
|
a3e2b5 |
- * fails. */
|
|
|
a3e2b5 |
+ /* The linux kernel alters the mode in some cases of chown(), as well when we change ACLs. Let's undo this. We
|
|
|
a3e2b5 |
+ * do this only for non-symlinks however. That's because for symlinks the access mode is ignored anyway and
|
|
|
a3e2b5 |
+ * because on some kernels/file systems trying to change the access mode will succeed but has no effect while
|
|
|
a3e2b5 |
+ * on others it actively fails. */
|
|
|
a3e2b5 |
if (!S_ISLNK(st->st_mode))
|
|
|
a3e2b5 |
if (chmod(procfs_path, st->st_mode & 07777) < 0)
|
|
|
a3e2b5 |
return -errno;
|