summaryrefslogtreecommitdiff
path: root/lib/file-has-acl.c
diff options
context:
space:
mode:
authorAndreas Gruenbacher <andreas.gruenbacher@gmail.com>2015-04-12 16:36:37 +0200
committerPádraig Brady <P@draigBrady.com>2015-04-15 23:41:39 +0100
commitda6ebc941e966141e83591408545224274d0cf0f (patch)
treed1c12ba3b30d647b9d837378afe5fc7955aeb4e1 /lib/file-has-acl.c
parenta09a0344e3282d8b4a927916cf117ba5c1472bdd (diff)
downloadgnulib-da6ebc941e966141e83591408545224274d0cf0f.tar.gz
acl: On Linux, check for acls without libacl
On Linux, use the getxattr syscall instead of the acl_extended_file libacl library function to check for the presence of acls, avoiding a library dependency. * lib/file-has-acl.c: Include xattr headers if we have them. (file_has_acl): On Linux, use getxattr(). * m4/acl.m4 (gl_FUNC_ACL): Define LIB_HAS_ACL as the libraries to link with for file_has_acl(). Check for xattr headers and getxattr(). * modules/acl: Add a dep on the stdbool module which was already needed. Add the new reduced dependency LIB_HAS_ACL reference.
Diffstat (limited to 'lib/file-has-acl.c')
-rw-r--r--lib/file-has-acl.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index de89a75918..5dfe9a8510 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -29,6 +29,13 @@
#include "acl-internal.h"
+#if HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#endif
+
+#if HAVE_LINUX_XATTR_H
+# include <linux/xattr.h>
+#endif
/* Return 1 if NAME has a nontrivial access control list, 0 if NAME
only has no or a base access control list, and -1 (setting errno)
@@ -41,7 +48,33 @@ file_has_acl (char const *name, struct stat const *sb)
#if USE_ACL
if (! S_ISLNK (sb->st_mode))
{
-# if HAVE_ACL_GET_FILE
+
+# if HAVE_GETXATTR && defined XATTR_NAME_POSIX_ACL_ACCESS && defined XATTR_NAME_POSIX_ACL_DEFAULT
+
+ ssize_t ret;
+
+ ret = getxattr (name, XATTR_NAME_POSIX_ACL_ACCESS, NULL, 0);
+ if (ret < 0)
+ {
+ if (errno != ENODATA)
+ return -1;
+ }
+ else if (ret > 0)
+ return 1;
+ if (S_ISDIR (sb->st_mode))
+ {
+ ret = getxattr (name, XATTR_NAME_POSIX_ACL_DEFAULT, NULL, 0);
+ if (ret < 0)
+ {
+ if (errno != ENODATA)
+ return -1;
+ }
+ else if (ret > 0)
+ return 1;
+ }
+ return 0;
+
+# elif HAVE_ACL_GET_FILE
/* POSIX 1003.1e (draft 17 -- abandoned) specific version. */
/* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */