Blame SOURCES/tar-1.26-default-acls.patch

9d3903
From e3a7b9c8f26ca3b5a9aedd4c1d596a4a8504c812 Mon Sep 17 00:00:00 2001
9d3903
From: Pavel Raiskup <praiskup@redhat.com>
9d3903
Date: Thu, 4 Jun 2015 09:30:38 +0200
9d3903
Subject: [PATCH] acls: don't mistakenly set default ACLs
9d3903
9d3903
Upstream commits
9d3903
efbf4cce0b93e8c5a5fc93335b917bbeae2f67cb
9d3903
9df17e6005e7a333399e3dc21a7afec75565c767
9d3903
7fe7adcbb985e78aaf9f78051fa26167779be1f6
9d3903
---
9d3903
 configure.ac       |   2 +
9d3903
 src/xattrs.c       |  37 ++++++++++++---
9d3903
 tests/Makefile.am  |   1 +
9d3903
 tests/acls03.at    | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++
9d3903
 tests/testsuite.at |   1 +
9d3903
 5 files changed, 165 insertions(+), 7 deletions(-)
9d3903
 create mode 100644 tests/acls03.at
9d3903
9d3903
diff --git a/configure.ac b/configure.ac
9d3903
index 9b3e0c8..7ccb579 100644
9d3903
--- a/configure.ac
9d3903
+++ b/configure.ac
9d3903
@@ -85,6 +85,8 @@ if test "x$with_posix_acls" != "xno"; then
9d3903
   AC_SEARCH_LIBS([acl_set_fd],    [acl pacl],, [with_posix_acl=no])
9d3903
   AC_SEARCH_LIBS([acl_to_text],   [acl pacl],, [with_posix_acl=no])
9d3903
   AC_SEARCH_LIBS([acl_from_text], [acl pacl],, [with_posix_acl=no])
9d3903
+  AC_SEARCH_LIBS([acl_delete_def_file], [acl pacl],, [with_posix_acl=no])
9d3903
+  AC_SEARCH_LIBS([acl_free], [acl pacl],, [with_posix_acl=no])
9d3903
   if test "x$with_posix_acls" != xno; then
9d3903
     AC_DEFINE(HAVE_POSIX_ACLS,,[Define when we have working POSIX acls])
9d3903
   fi
9d3903
diff --git a/src/xattrs.c b/src/xattrs.c
9d3903
index bdf6ba0..5bd4b02 100644
9d3903
--- a/src/xattrs.c
9d3903
+++ b/src/xattrs.c
9d3903
@@ -61,6 +61,7 @@ static struct
9d3903
 acl_t acl_get_file_at (int dirfd, const char *file, acl_type_t type);
9d3903
 int acl_set_file_at (int dirfd, const char *file, acl_type_t type, acl_t acl);
9d3903
 int file_has_acl_at (int dirfd, char const *, struct stat const *);
9d3903
+int acl_delete_def_file_at (int, char const *);
9d3903
 
9d3903
 /* acl_get_file_at */
9d3903
 #define AT_FUNC_NAME acl_get_file_at
9d3903
@@ -88,6 +89,17 @@ int file_has_acl_at (int dirfd, char const *, struct stat const *);
9d3903
 #undef AT_FUNC_POST_FILE_PARAM_DECLS
9d3903
 #undef AT_FUNC_POST_FILE_ARGS
9d3903
 
9d3903
+/* acl_delete_def_file_at */
9d3903
+#define AT_FUNC_NAME acl_delete_def_file_at
9d3903
+#define AT_FUNC_F1 acl_delete_def_file
9d3903
+#define AT_FUNC_POST_FILE_PARAM_DECLS
9d3903
+#define AT_FUNC_POST_FILE_ARGS
9d3903
+#include "at-func.c"
9d3903
+#undef AT_FUNC_NAME
9d3903
+#undef AT_FUNC_F1
9d3903
+#undef AT_FUNC_POST_FILE_PARAM_DECLS
9d3903
+#undef AT_FUNC_POST_FILE_ARGS
9d3903
+
9d3903
 /* gnulib file_has_acl_at */
9d3903
 #define AT_FUNC_NAME file_has_acl_at
9d3903
 #define AT_FUNC_F1 file_has_acl
9d3903
@@ -187,7 +199,8 @@ fixup_extra_acl_fields (char *ptr)
9d3903
   return ptr;
9d3903
 }
9d3903
 
9d3903
-/* "system.posix_acl_access" */
9d3903
+/* Set the "system.posix_acl_access/system.posix_acl_default" extended
9d3903
+   attribute.  Called only when acls_option > 0. */
9d3903
 static void
9d3903
 xattrs__acls_set (struct tar_stat_info const *st,
9d3903
                   char const *file_name, int type,
9d3903
@@ -199,15 +212,25 @@ xattrs__acls_set (struct tar_stat_info const *st,
9d3903
     {
9d3903
       /* assert (strlen (ptr) == len); */
9d3903
       ptr = fixup_extra_acl_fields (ptr);
9d3903
-
9d3903
       acl = acl_from_text (ptr);
9d3903
-      acls_option = 1;
9d3903
     }
9d3903
-  else if (acls_option > 0)
9d3903
+  else if (def)
9d3903
+    {
9d3903
+      /* No "default" IEEE 1003.1e ACL set for directory.  At this moment,
9d3903
+         FILE_NAME may already have inherited default acls from parent
9d3903
+         directory;  clean them up. */
9d3903
+      if (acl_delete_def_file_at (chdir_fd, file_name))
9d3903
+        WARNOPT (WARN_XATTR_WRITE,
9d3903
+                (0, errno,
9d3903
+                 _("acl_delete_def_file_at: Cannot drop default POSIX ACLs "
9d3903
+                   "for file '%s'"),
9d3903
+                 file_name));
9d3903
+      return;
9d3903
+    }
9d3903
+  else
9d3903
+    /* There is nothing like "acl_delete_def_file" for non-default acls, we
9d3903
+       need to re-set ACLs based on permission bits */
9d3903
     acl = perms2acl (st->stat.st_mode);
9d3903
-  else
9d3903
-    return;  /* don't call acl functions unless we first hit an ACL, or
9d3903
-		--acls was passed explicitly */
9d3903
 
9d3903
   if (!acl)
9d3903
     {
9d3903
diff --git a/tests/Makefile.am b/tests/Makefile.am
9d3903
index b0da439..228e936 100644
9d3903
--- a/tests/Makefile.am
9d3903
+++ b/tests/Makefile.am
9d3903
@@ -179,6 +179,7 @@ TESTSUITE_AT = \
9d3903
  xattr05.at\
9d3903
  acls01.at\
9d3903
  acls02.at\
9d3903
+ acls03.at\
9d3903
  selnx01.at\
9d3903
  selacl01.at\
9d3903
  capabs_raw01.at
9d3903
diff --git a/tests/acls03.at b/tests/acls03.at
9d3903
new file mode 100644
9d3903
index 0000000..83c5bdc
9d3903
--- /dev/null
9d3903
+++ b/tests/acls03.at
9d3903
@@ -0,0 +1,131 @@
9d3903
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
9d3903
+#
9d3903
+# Test suite for GNU tar.
9d3903
+# Copyright 2013, 2014 Free Software Foundation, Inc.
9d3903
+
9d3903
+# This file is part of GNU tar.
9d3903
+
9d3903
+# GNU tar is free software; you can redistribute it and/or modify
9d3903
+# it under the terms of the GNU General Public License as published by
9d3903
+# the Free Software Foundation; either version 3 of the License, or
9d3903
+# (at your option) any later version.
9d3903
+
9d3903
+# GNU tar is distributed in the hope that it will be useful,
9d3903
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
9d3903
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9d3903
+# GNU General Public License for more details.
9d3903
+
9d3903
+# You should have received a copy of the GNU General Public License
9d3903
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9d3903
+#
9d3903
+# Test description:
9d3903
+#
9d3903
+# Check the storing/restoring with/without default ACLs.  When --acls is passed,
9d3903
+# restored directory tree should always match archive contents (even when the
9d3903
+# archive does not contain any ACLs).
9d3903
+#
9d3903
+# References:
9d3903
+# http://www.mail-archive.com/bug-tar@gnu.org/msg04355.html
9d3903
+
9d3903
+AT_SETUP([acls: default ACLs])
9d3903
+AT_KEYWORDS([xattrs acls acls03])
9d3903
+
9d3903
+m4_define([ACL_LISTDIR], [
9d3903
+    cd $1
9d3903
+    $1="$(find d1 | sort | xargs -n 1 getfacl)"
9d3903
+    cd ..
9d3903
+])
9d3903
+
9d3903
+m4_define([ACL_ASSERT], [
9d3903
+    echo "$$1" > $1.log
9d3903
+    echo "$$2" > $2.log
9d3903
+    if test ! "$$1" "$3" "$$2"; then
9d3903
+        echo "bad '$1' against '$2' output"
9d3903
+    fi
9d3903
+])
9d3903
+
9d3903
+AT_TAR_CHECK([
9d3903
+AT_XATTRS_UTILS_PREREQ
9d3903
+AT_ACLS_PREREQ
9d3903
+AT_SORT_PREREQ
9d3903
+
9d3903
+MYNAME=$( id -un )
9d3903
+MYGROUP=$( id -gn )
9d3903
+
9d3903
+# Prepare directory structure with default ACLs
9d3903
+mkdir -p pure/d1/d2
9d3903
+genfile --file pure/d1/f2a
9d3903
+genfile --file pure/d1/f2b
9d3903
+genfile --file pure/d1/d2/f3a
9d3903
+genfile --file pure/d1/d2/f3b
9d3903
+setfacl    -m g:$MYGROUP:r-x pure/d1
9d3903
+setfacl -d -m g:$MYGROUP:rwx pure/d1
9d3903
+setfacl -d -m u:$MYNAME:rwx  pure/d1
9d3903
+# "*a" files have "some" additional ACLs
9d3903
+setfacl    -m u:$MYNAME:--- pure/d1/d2/f3a
9d3903
+setfacl    -m u:$MYNAME:--- pure/d1/f2a
9d3903
+
9d3903
+# use default format (no acls stored)
9d3903
+tar -cf noacl.tar -C pure d1
9d3903
+
9d3903
+# use posix format, acls stored
9d3903
+tar --acls -cf acl.tar -C pure d1
9d3903
+
9d3903
+# Directory names are chosen based on "how the files were extracted from
9d3903
+# archive".  Equivalent no* tags are used also:
9d3903
+#   ^sacl_    — extracted archive has stored ACLs
9d3903
+#   _def_     — target directory (-C) has default ACLs
9d3903
+#   _optacl$  — extraction was done with --acls option
9d3903
+
9d3903
+mkdir sacl_def_optacl
9d3903
+mkdir sacl_def_optnoacl
9d3903
+mkdir sacl_nodef_optacl
9d3903
+mkdir sacl_nodef_optnoacl
9d3903
+mkdir nosacl_def_optacl
9d3903
+mkdir nosacl_def_optnoacl
9d3903
+mkdir nosacl_nodef_optacl
9d3903
+mkdir nosacl_nodef_optnoacl
9d3903
+
9d3903
+setfacl -d -m u:$MYNAME:---  nosacl_def_optnoacl sacl_def_optnoacl sacl_def_optacl nosacl_def_optacl
9d3903
+setfacl -d -m g:$MYGROUP:--- nosacl_def_optnoacl sacl_def_optnoacl sacl_def_optacl nosacl_def_optacl
9d3903
+
9d3903
+tar -xf acl.tar -C sacl_nodef_optnoacl
9d3903
+tar --acls -xf acl.tar -C sacl_nodef_optacl
9d3903
+tar -xf acl.tar -C sacl_def_optnoacl
9d3903
+tar --acls -xf acl.tar -C sacl_def_optacl
9d3903
+tar -xf noacl.tar -C nosacl_def_optnoacl
9d3903
+# _NO_ ACLs in output
9d3903
+tar -xf noacl.tar -C nosacl_nodef_optnoacl
9d3903
+tar -xf noacl.tar -C nosacl_nodef_optacl
9d3903
+tar -cf noacl_repackaged.tar -C nosacl_nodef_optnoacl d1
9d3903
+# _NO_ ACLs in output (even when default ACLs exist)
9d3903
+tar --acls -xf noacl_repackaged.tar -C nosacl_def_optacl
9d3903
+
9d3903
+ACL_LISTDIR(pure)
9d3903
+
9d3903
+ACL_LISTDIR(sacl_def_optacl)
9d3903
+ACL_LISTDIR(sacl_def_optnoacl)
9d3903
+ACL_LISTDIR(sacl_nodef_optacl)
9d3903
+ACL_LISTDIR(sacl_nodef_optnoacl)
9d3903
+ACL_LISTDIR(nosacl_def_optacl)
9d3903
+ACL_LISTDIR(nosacl_def_optnoacl)
9d3903
+ACL_LISTDIR(nosacl_nodef_optacl)
9d3903
+ACL_LISTDIR(nosacl_nodef_optnoacl)
9d3903
+
9d3903
+ACL_ASSERT(pure, sacl_def_optacl, =)
9d3903
+
9d3903
+ACL_ASSERT(sacl_def_optacl,     sacl_nodef_optacl,      =)
9d3903
+ACL_ASSERT(sacl_def_optnoacl,   nosacl_def_optnoacl,    =)
9d3903
+ACL_ASSERT(sacl_nodef_optnoacl, nosacl_nodef_optnoacl,  =)
9d3903
+ACL_ASSERT(nosacl_def_optacl,   nosacl_nodef_optacl,    =)
9d3903
+ACL_ASSERT(nosacl_def_optacl,   nosacl_nodef_optnoacl,  =)
9d3903
+
9d3903
+ACL_ASSERT(sacl_def_optacl,     sacl_def_optnoacl,      !=)
9d3903
+ACL_ASSERT(sacl_def_optacl,     nosacl_def_optnoacl,    !=)
9d3903
+ACL_ASSERT(nosacl_def_optnoacl, nosacl_nodef_optnoacl,  !=)
9d3903
+],
9d3903
+[0],
9d3903
+[],
9d3903
+[])
9d3903
+
9d3903
+AT_CLEANUP
9d3903
diff --git a/tests/testsuite.at b/tests/testsuite.at
9d3903
index d5925b3..10cf26a 100644
9d3903
--- a/tests/testsuite.at
9d3903
+++ b/tests/testsuite.at
9d3903
@@ -341,6 +341,7 @@ m4_include([xattr05.at])
9d3903
 
9d3903
 m4_include([acls01.at])
9d3903
 m4_include([acls02.at])
9d3903
+m4_include([acls03.at])
9d3903
 
9d3903
 m4_include([selnx01.at])
9d3903
 m4_include([selacl01.at])
9d3903
-- 
9d3903
2.1.0
9d3903