diff lib/file-has-acl.c @ 10172:50e666f281ef

Add support for MacOS X ACLs.
author Bruno Haible <bruno@clisp.org>
date Sun, 08 Jun 2008 05:06:19 +0200
parents 73042342e7f6
children 33543159ba5b
line wrap: on
line diff
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -127,9 +127,29 @@
       int ret;
 
       if (HAVE_ACL_EXTENDED_FILE)
-	ret = acl_extended_file (name);
+	{
+	  /* On Linux, acl_extended_file is an optimized function: It only
+	     makes two calls to getxattr(), one for ACL_TYPE_ACCESS, one for
+	     ACL_TYPE_DEFAULT.  */
+	  ret = acl_extended_file (name);
+	}
       else
 	{
+#  if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
+	  /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS)
+	     and acl_get_file (name, ACL_TYPE_DEFAULT)
+	     always return NULL / EINVAL.  There is no point in making
+	     these two useless calls.  The real ACL is retrieved through
+	     acl_get_file (name, ACL_TYPE_EXTENDED).  */
+	  acl_t acl = acl_get_file (name, ACL_TYPE_EXTENDED);
+	  if (acl)
+	    {
+	      ret = (0 < acl_entries (acl));
+	      acl_free (acl);
+	    }
+	  else
+	    ret = -1;
+#  else /* FreeBSD, IRIX, Tru64 */
 	  acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS);
 	  if (acl)
 	    {
@@ -153,6 +173,7 @@
 	    }
 	  else
 	    ret = -1;
+#  endif
 	}
       if (ret < 0)
 	return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1;
@@ -179,7 +200,7 @@
     }
 #endif
 
-  /* FIXME: Add support for AIX, Irix, and Tru64.  Please see Samba's
+  /* FIXME: Add support for AIX.  Please see Samba's
      source/lib/sysacls.c file for fix-related ideas.  */
 
   return 0;