8d0e4d
From ce137aaf4b0d62b3e4c88816485a3ab0f5c4b3f3 Mon Sep 17 00:00:00 2001
8d0e4d
From: Kamil Dudka <kdudka@redhat.com>
8d0e4d
Date: Thu, 6 Dec 2018 13:14:00 +0100
8d0e4d
Subject: [PATCH] cp --preserve=xattr: preserve NFSv4 ACL extended attributes
8d0e4d
8d0e4d
... that cannot be preserved by other means
8d0e4d
---
8d0e4d
 src/copy.c | 22 +++++++++++++++++-----
8d0e4d
 1 file changed, 17 insertions(+), 5 deletions(-)
8d0e4d
8d0e4d
diff --git a/src/copy.c b/src/copy.c
8d0e4d
index 1a9cdd1..d227e3e 100644
8d0e4d
--- a/src/copy.c
8d0e4d
+++ b/src/copy.c
8d0e4d
@@ -640,6 +640,17 @@ copy_attr_free (struct error_context *ctx _GL_UNUSED,
8d0e4d
 {
8d0e4d
 }
8d0e4d
 
8d0e4d
+/* Include NFSv4 ACL extended attributes that cannot be preserved by
8d0e4d
+   other means.  Otherwise honor attributes configured for exclusion
8d0e4d
+   in /etc/xattr.conf.  Return zero to skip.  */
8d0e4d
+static int
8d0e4d
+check_not_nfs4_acl (const char *name, struct error_context *ctx)
8d0e4d
+{
8d0e4d
+  return attr_copy_check_permissions(name, ctx)
8d0e4d
+         || !STRNCMP_LIT (name, "system.nfs4_acl")
8d0e4d
+         || !STRNCMP_LIT (name, "system.nfs4acl");
8d0e4d
+}
8d0e4d
+
8d0e4d
 /* Exclude SELinux extended attributes that are otherwise handled,
8d0e4d
    and are problematic to copy again.  Also honor attributes
8d0e4d
    configured for exclusion in /etc/xattr.conf.
8d0e4d
@@ -649,7 +660,7 @@ static int
8d0e4d
 check_selinux_attr (const char *name, struct error_context *ctx)
8d0e4d
 {
8d0e4d
   return STRNCMP_LIT (name, "security.selinux")
8d0e4d
-         && attr_copy_check_permissions (name, ctx);
8d0e4d
+         && check_not_nfs4_acl (name, ctx);
8d0e4d
 }
8d0e4d
 
8d0e4d
 /* If positive SRC_FD and DST_FD descriptors are passed,
8d0e4d
@@ -663,6 +674,9 @@ copy_attr (char const *src_path, int src_fd,
8d0e4d
   bool all_errors = (!x->data_copy_required || x->require_preserve_xattr);
8d0e4d
   bool some_errors = (!all_errors && !x->reduce_diagnostics);
8d0e4d
   bool selinux_done = (x->preserve_security_context || x->set_security_context);
8d0e4d
+  int (*check) (const char *, struct error_context *) = (selinux_done)
8d0e4d
+    ? check_selinux_attr
8d0e4d
+    : check_not_nfs4_acl;
8d0e4d
   struct error_context ctx =
8d0e4d
   {
8d0e4d
     .error = all_errors ? copy_attr_allerror : copy_attr_error,
8d0e4d
@@ -670,12 +684,10 @@ copy_attr (char const *src_path, int src_fd,
8d0e4d
     .quote_free = copy_attr_free
8d0e4d
   };
8d0e4d
   if (0 <= src_fd && 0 <= dst_fd)
8d0e4d
-    ret = attr_copy_fd (src_path, src_fd, dst_path, dst_fd,
8d0e4d
-                        selinux_done ? check_selinux_attr : NULL,
8d0e4d
+    ret = attr_copy_fd (src_path, src_fd, dst_path, dst_fd, check,
8d0e4d
                         (all_errors || some_errors ? &ctx : NULL));
8d0e4d
   else
8d0e4d
-    ret = attr_copy_file (src_path, dst_path,
8d0e4d
-                          selinux_done ? check_selinux_attr : NULL,
8d0e4d
+    ret = attr_copy_file (src_path, dst_path, check,
8d0e4d
                           (all_errors || some_errors ? &ctx : NULL));
8d0e4d
 
8d0e4d
   return ret == 0;
8d0e4d
-- 
8d0e4d
2.17.2
8d0e4d