]> Savannah Git Hosting - gnulib.git/commitdiff
acl: On Linux, check for acls without libacl
authorAndreas Gruenbacher <andreas.gruenbacher@gmail.com>
Sun, 12 Apr 2015 14:36:37 +0000 (16:36 +0200)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Apr 2015 22:41:39 +0000 (23:41 +0100)
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.

ChangeLog
NEWS
lib/file-has-acl.c
m4/acl.m4
modules/acl

index 95d49ec19669dc6aebac871f738e57ebb1640ffd..de8cc66625a9276e17813b73deb751148b455fd3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2015-04-15  Andreas Gruenbacher   <andreas.gruenbacher@gmail.com>
+
+       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.
+       * 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().
+
 2015-04-14  Ángel González  <keisial@gmail.com>
 
        tempname: avoid unused parameter warnings (trivial)
diff --git a/NEWS b/NEWS
index ef397ef21273856cd0f4f1127da73f06e72161b0..fd159992515637fd1b61022850d3e5b96fd20d61 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,11 @@ Important notes
 
 Date        Modules         Changes
 
+2015-04-15  acl             If your project only uses the file_has_acl()
+                            detection routine, then the requirements are
+                            potentially reduced by using $LIB_HAS_ACL rather
+                            than $LIB_ACL.
+
 2013-04-24  gettext         If your project uses 'gettextize --intl' it is now
                             your responsibility to put -I$(top_builddir)/intl
                             into the Makefile.am for gnulib.
index de89a75918c58abc270ff0161dea39a94570059f..5dfe9a8510041ddf54b1e319b6cda2a77ec56526 100644 (file)
 
 #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 */
index c77f0edd0e7d66f2974d07a26e6bd62f50fd8f11..a6c2a0d2f66bc2ff1f372d5ddb48f835ffa8220d 100644 (file)
--- a/m4/acl.m4
+++ b/m4/acl.m4
@@ -16,6 +16,7 @@ AC_DEFUN([gl_FUNC_ACL],
 
   AC_CHECK_FUNCS_ONCE([fchmod])
   LIB_ACL=
+  LIB_HAS_ACL=
   use_acl=0
   if test "x$enable_acl" != "xno"; then
     dnl On all platforms, the ACL related API is declared in <sys/acl.h>.
@@ -124,6 +125,21 @@ int type = ACL_TYPE_EXTENDED;]])],
 
       LIBS=$ac_save_LIBS
     fi
+
+    dnl On Linux, testing if a file has an acl can be done with the getxattr
+    dnl syscall which doesn't require linking against additional libraries.
+    use_xattrs=0
+    AC_CHECK_HEADERS([sys/xattr.h linux/xattr.h])
+    if test $ac_cv_header_sys_xattr_h = yes && test $ac_cv_header_linux_xattr_h = yes; then
+      AC_CHECK_FUNCS([getxattr])
+      if test $ac_cv_func_getxattr = yes; then
+       use_xattrs=1
+      fi
+    fi
+    if test use_xattrs = 0; then
+      LIB_HAS_ACL=$LIB_ACL
+    fi
+
     if test "x$enable_acl$use_acl" = "xyes0"; then
       AC_MSG_ERROR([ACLs enabled but support not detected])
     elif test "x$enable_acl$use_acl" = "xauto0"; then
@@ -132,6 +148,7 @@ int type = ACL_TYPE_EXTENDED;]])],
     fi
   fi
   AC_SUBST([LIB_ACL])
+  AC_SUBST([LIB_HAS_ACL])
   AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
     [Define to nonzero if you want access control list support.])
   USE_ACL=$use_acl
index fdb0d72025cdcb163a6a1a6af7135891334fee3c..7faec171632cc34bf94cc1d9e8cd7d56fc33d431 100644 (file)
@@ -11,6 +11,7 @@ error
 gettext-h
 qacl
 quote
+stdbool
 
 configure.ac:
 
@@ -22,6 +23,7 @@ Include:
 
 Link:
 $(LIB_ACL)
+$(LIB_HAS_ACL)
 
 License:
 GPL