coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] acl-permissions: Fix on FreeBSD


From: Andreas Gruenbacher
Subject: [PATCH 1/2] acl-permissions: Fix on FreeBSD
Date: Sun, 5 Jul 2015 22:49:49 +0200

When a directory doesn't have an ACL_TYPE_DEFAULT acl, acl_get_file will return
an empty acl, but when trying to set that acl, FreeBSD's acl_set_file will fail
with errno == EINVAL.  Instead, FreeBSD expects acl_delete_def_file to be used.
* lib/acl-internal.c (acl_default_nontrivial): Recognize empty default acls.
* lib/set-permissions.c (set_acls): Avoid calling acl_set_file for empty
ACL_TYPE_DEFAULT acls.
---
 lib/acl-internal.c    | 7 +++++++
 lib/acl-internal.h    | 6 ++++++
 lib/set-permissions.c | 3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/acl-internal.c b/lib/acl-internal.c
index 1a2f8c4..1eaa671 100644
--- a/lib/acl-internal.c
+++ b/lib/acl-internal.c
@@ -115,6 +115,13 @@ acl_access_nontrivial (acl_t acl)
 #  endif
 }
 
+int
+acl_default_nontrivial (acl_t acl)
+{
+  /* acl is non-trivial if it is non-empty.  */
+  return (acl_entries (acl) > 0);
+}
+
 # endif
 
 #elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
diff --git a/lib/acl-internal.h b/lib/acl-internal.h
index 4f042ad..38a4ab2 100644
--- a/lib/acl-internal.h
+++ b/lib/acl-internal.h
@@ -155,6 +155,12 @@ extern int acl_extended_nontrivial (acl_t);
    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
    Return -1 and set errno upon failure to determine it.  */
 extern int acl_access_nontrivial (acl_t);
+
+/* ACL is an ACL, from a file, stored as type ACL_TYPE_DEFAULT.
+   Return 1 if the given ACL is non-trivial.
+   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
+   Return -1 and set errno upon failure to determine it.  */
+extern int acl_default_nontrivial (acl_t);
 #  endif
 
 # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
diff --git a/lib/set-permissions.c b/lib/set-permissions.c
index 25c463d..c40d03f 100644
--- a/lib/set-permissions.c
+++ b/lib/set-permissions.c
@@ -530,7 +530,8 @@ set_acls (struct permission_context *ctx, const char *name, 
int desc,
              *acls_set = true;
              if (S_ISDIR(ctx->mode))
                {
-                 if (! from_mode && ctx->default_acl)
+                 if (! from_mode && ctx->default_acl &&
+                     acl_default_nontrivial (ctx->default_acl))
                    ret = acl_set_file (name, ACL_TYPE_DEFAULT,
                                        ctx->default_acl);
                  else
-- 
2.4.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]