1 # acl.m4 - check for access control list (ACL) primitives
4 # Copyright (C) 2002, 2004-2018 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 # Written by Paul Eggert and Jim Meyering.
11 AC_DEFUN([gl_FUNC_ACL_ARG],
15 AS_HELP_STRING([--disable-acl], [do not support ACLs]),
20 AC_DEFUN([gl_FUNC_ACL],
22 AC_REQUIRE([gl_FUNC_ACL_ARG])
23 AC_CHECK_FUNCS_ONCE([fchmod])
26 if test "$enable_acl" != no; then
27 dnl On all platforms, the ACL related API is declared in <sys/acl.h>.
28 AC_CHECK_HEADERS([sys/acl.h])
29 if test $ac_cv_header_sys_acl_h = yes; then
32 dnl Test for POSIX-draft-like API (GNU/Linux, FreeBSD, Mac OS X,
33 dnl IRIX, Tru64). -lacl is needed on GNU/Linux, -lpacl on OSF/1.
34 if test $use_acl = 0; then
35 AC_SEARCH_LIBS([acl_get_file], [acl pacl],
36 [if test "$ac_cv_search_acl_get_file" != "none required"; then
37 LIB_ACL=$ac_cv_search_acl_get_file
40 [acl_get_file acl_get_fd acl_set_file acl_set_fd \
41 acl_free acl_from_mode acl_from_text \
42 acl_delete_def_file acl_extended_file \
43 acl_delete_fd_np acl_delete_file_np \
44 acl_copy_ext_native acl_create_entry_np \
45 acl_to_short_text acl_free_text])
46 # If the acl_get_file bug is detected, don't enable the ACL support.
47 gl_ACL_GET_FILE([use_acl=1], [])
48 if test $use_acl = 1; then
49 dnl On GNU/Linux, an additional API is declared in <acl/libacl.h>.
50 AC_CHECK_HEADERS([acl/libacl.h])
51 AC_REPLACE_FUNCS([acl_entries])
52 AC_CACHE_CHECK([for ACL_FIRST_ENTRY],
53 [gl_cv_acl_ACL_FIRST_ENTRY],
54 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
55 [[#include <sys/types.h>
57 int type = ACL_FIRST_ENTRY;]])],
58 [gl_cv_acl_ACL_FIRST_ENTRY=yes],
59 [gl_cv_acl_ACL_FIRST_ENTRY=no])])
60 if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then
61 AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1],
62 [Define to 1 if the constant ACL_FIRST_ENTRY exists.])
64 dnl On Mac OS X, other types of ACLs are supported.
65 AC_CACHE_CHECK([for ACL_TYPE_EXTENDED],
66 [gl_cv_acl_ACL_TYPE_EXTENDED],
67 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
68 [[#include <sys/types.h>
70 int type = ACL_TYPE_EXTENDED;]])],
71 [gl_cv_acl_ACL_TYPE_EXTENDED=yes],
72 [gl_cv_acl_ACL_TYPE_EXTENDED=no])])
73 if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then
74 AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1],
75 [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.])
83 dnl Test for Solaris API (Solaris, Cygwin).
84 if test $use_acl = 0; then
85 AC_CHECK_FUNCS([facl])
86 if test $ac_cv_func_facl = yes; then
87 AC_SEARCH_LIBS([acl_trivial], [sec],
88 [if test "$ac_cv_search_acl_trivial" != "none required"; then
89 LIB_ACL=$ac_cv_search_acl_trivial
92 AC_CHECK_FUNCS([acl_trivial])
97 dnl Test for HP-UX API.
98 if test $use_acl = 0; then
99 AC_CHECK_FUNCS([getacl])
100 if test $ac_cv_func_getacl = yes; then
103 dnl Test for HP-UX 11.11 API.
104 AC_CHECK_HEADERS([aclv.h], [], [], [#include <sys/types.h>])
107 dnl Test for AIX API (AIX 5.3 or newer).
108 if test $use_acl = 0; then
109 AC_CHECK_FUNCS([aclx_get])
110 if test $ac_cv_func_aclx_get = yes; then
115 dnl Test for older AIX API.
116 if test $use_acl = 0 || test "$ac_cv_func_aclx_get" = yes; then
117 AC_CHECK_FUNCS([statacl])
118 if test $ac_cv_func_statacl = yes; then
123 dnl Test for NonStop Kernel API.
124 if test $use_acl = 0; then
125 AC_CHECK_FUNCS([aclsort])
126 if test $ac_cv_func_aclsort = yes; then
134 if test "$enable_acl$use_acl" = yes0; then
135 AC_MSG_ERROR([ACLs enabled but support not detected])
136 elif test "$enable_acl$use_acl" = auto0; then
137 AC_MSG_WARN([libacl development library was not found or not usable.])
138 AC_MSG_WARN([AC_PACKAGE_NAME will be built without ACL support.])
141 test $gl_need_lib_has_acl && LIB_HAS_ACL=$LIB_ACL
143 AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
144 [Define to nonzero if you want access control list support.])
149 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
150 # ---------------------------------
151 # If 'acl_get_file' works (does not have a particular bug),
152 # run IF-WORKS, otherwise, IF-NOT.
153 # When building natively, test for a Darwin 8.7.0 bug, whereby acl_get_file
154 # returns NULL, but sets errno = ENOENT for an existing file or directory.
155 # When cross-compiling, assume that this old bug no longer applies.
156 AC_DEFUN([gl_ACL_GET_FILE],
158 AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file],
159 [gl_cv_func_working_acl_get_file=no
162 [[#include <sys/types.h>
166 [[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS);
167 return acl ? acl_free (acl) != 0 : errno == ENOENT;
169 [if test $cross_compiling = yes; then
170 gl_cv_func_working_acl_get_file="guessing yes"
171 elif ./conftest$ac_exeext; then
172 gl_cv_func_working_acl_get_file=yes
174 AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2])
177 # On GNU/Linux, testing if a file has an acl can be done with the getxattr
178 # syscall which doesn't require linking against additional libraries.
179 AC_DEFUN([gl_FILE_HAS_ACL],
181 AC_REQUIRE([gl_FUNC_ACL_ARG])
182 if test "$enable_acl" != no; then
183 AC_CACHE_CHECK([for getxattr with XATTR_NAME_POSIX_ACL macros],
184 [gl_cv_getxattr_with_posix_acls],
185 [gl_cv_getxattr_with_posix_acls=no
188 [[#include <sys/types.h>
189 #include <sys/xattr.h>
190 #include <linux/xattr.h>
192 [[ssize_t a = getxattr (".", XATTR_NAME_POSIX_ACL_ACCESS, 0, 0);
193 ssize_t b = getxattr (".", XATTR_NAME_POSIX_ACL_DEFAULT, 0, 0);
194 return a < 0 || b < 0;
196 [gl_cv_getxattr_with_posix_acls=yes])])
198 if test "$gl_cv_getxattr_with_posix_acls" = yes; then
200 AC_DEFINE([GETXATTR_WITH_POSIX_ACLS], 1,
201 [Define to 1 if getxattr works with XATTR_NAME_POSIX_ACL_ACCESS
202 and XATTR_NAME_POSIX_ACL_DEFAULT.])
204 dnl Set gl_need_lib_has_acl to a nonempty value, so that any
205 dnl later gl_FUNC_ACL call will set LIB_HAS_ACL=$LIB_ACL.
206 gl_need_lib_has_acl=1
209 AC_SUBST([LIB_HAS_ACL])