1 # acl.m4 - check for access control list (ACL) primitives
4 # Copyright (C) 2002, 2004-2020 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, Cygwin >= 2.5).
34 dnl -lacl is needed on GNU/Linux, -lpacl on OSF/1.
35 if test $use_acl = 0; then
36 AC_SEARCH_LIBS([acl_get_file], [acl pacl],
37 [if test "$ac_cv_search_acl_get_file" != "none required"; then
38 LIB_ACL=$ac_cv_search_acl_get_file
41 [acl_get_file acl_get_fd acl_set_file acl_set_fd \
42 acl_free acl_from_mode acl_from_text \
43 acl_delete_def_file acl_extended_file \
44 acl_delete_fd_np acl_delete_file_np \
45 acl_copy_ext_native acl_create_entry_np \
46 acl_to_short_text acl_free_text])
47 # If the acl_get_file bug is detected, don't enable the ACL support.
48 gl_ACL_GET_FILE([use_acl=1], [])
49 if test $use_acl = 1; then
50 dnl On GNU/Linux, an additional API is declared in <acl/libacl.h>.
51 AC_CHECK_HEADERS([acl/libacl.h])
52 AC_REPLACE_FUNCS([acl_entries])
53 AC_CACHE_CHECK([for ACL_FIRST_ENTRY],
54 [gl_cv_acl_ACL_FIRST_ENTRY],
55 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
56 [[#include <sys/types.h>
58 int type = ACL_FIRST_ENTRY;]])],
59 [gl_cv_acl_ACL_FIRST_ENTRY=yes],
60 [gl_cv_acl_ACL_FIRST_ENTRY=no])])
61 if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then
62 AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1],
63 [Define to 1 if the constant ACL_FIRST_ENTRY exists.])
65 dnl On Mac OS X, other types of ACLs are supported.
66 AC_CACHE_CHECK([for ACL_TYPE_EXTENDED],
67 [gl_cv_acl_ACL_TYPE_EXTENDED],
68 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
69 [[#include <sys/types.h>
71 int type = ACL_TYPE_EXTENDED;]])],
72 [gl_cv_acl_ACL_TYPE_EXTENDED=yes],
73 [gl_cv_acl_ACL_TYPE_EXTENDED=no])])
74 if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then
75 AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1],
76 [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.])
84 dnl Test for Solaris API (Solaris, Cygwin).
85 if test $use_acl = 0; then
86 AC_CHECK_FUNCS([facl])
87 if test $ac_cv_func_facl = yes; then
88 AC_SEARCH_LIBS([acl_trivial], [sec],
89 [if test "$ac_cv_search_acl_trivial" != "none required"; then
90 LIB_ACL=$ac_cv_search_acl_trivial
93 AC_CHECK_FUNCS([acl_trivial])
98 dnl Test for HP-UX API.
99 if test $use_acl = 0; then
100 AC_CHECK_FUNCS([getacl])
101 if test $ac_cv_func_getacl = yes; then
104 dnl Test for HP-UX 11.11 API.
105 AC_CHECK_HEADERS([aclv.h], [], [], [#include <sys/types.h>])
108 dnl Test for AIX API (AIX 5.3 or newer).
109 if test $use_acl = 0; then
110 AC_CHECK_FUNCS([aclx_get])
111 if test $ac_cv_func_aclx_get = yes; then
116 dnl Test for older AIX API.
117 if test $use_acl = 0 || test "$ac_cv_func_aclx_get" = yes; then
118 AC_CHECK_FUNCS([statacl])
119 if test $ac_cv_func_statacl = yes; then
124 dnl Test for NonStop Kernel API.
125 if test $use_acl = 0; then
126 AC_CHECK_FUNCS([aclsort])
127 if test $ac_cv_func_aclsort = yes; then
135 if test "$enable_acl$use_acl" = yes0; then
136 AC_MSG_ERROR([ACLs enabled but support not detected])
137 elif test "$enable_acl$use_acl" = auto0; then
138 AC_MSG_WARN([libacl development library was not found or not usable.])
139 AC_MSG_WARN([AC_PACKAGE_NAME will be built without ACL support.])
142 test $gl_need_lib_has_acl && LIB_HAS_ACL=$LIB_ACL
144 AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
145 [Define to nonzero if you want access control list support.])
150 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
151 # ---------------------------------
152 # If 'acl_get_file' works (does not have a particular bug),
153 # run IF-WORKS, otherwise, IF-NOT.
154 # When building natively, test for a Darwin 8.7.0 bug, whereby acl_get_file
155 # returns NULL, but sets errno = ENOENT for an existing file or directory.
156 # When cross-compiling, assume that this old bug no longer applies.
157 AC_DEFUN([gl_ACL_GET_FILE],
159 AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file],
160 [gl_cv_func_working_acl_get_file=no
163 [[#include <sys/types.h>
167 [[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS);
168 return acl ? acl_free (acl) != 0 : errno == ENOENT;
170 [if test $cross_compiling = yes; then
171 gl_cv_func_working_acl_get_file="guessing yes"
172 elif ./conftest$ac_exeext; then
173 gl_cv_func_working_acl_get_file=yes
175 AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2])
178 # On GNU/Linux, testing if a file has an acl can be done with the getxattr
179 # syscall which doesn't require linking against additional libraries.
180 AC_DEFUN([gl_FILE_HAS_ACL],
182 AC_REQUIRE([gl_FUNC_ACL_ARG])
183 if test "$enable_acl" != no; then
184 AC_CACHE_CHECK([for getxattr with XATTR_NAME_POSIX_ACL macros],
185 [gl_cv_getxattr_with_posix_acls],
186 [gl_cv_getxattr_with_posix_acls=no
189 [[#include <sys/types.h>
190 #include <sys/xattr.h>
191 #include <linux/xattr.h>
193 [[ssize_t a = getxattr (".", XATTR_NAME_POSIX_ACL_ACCESS, 0, 0);
194 ssize_t b = getxattr (".", XATTR_NAME_POSIX_ACL_DEFAULT, 0, 0);
195 return a < 0 || b < 0;
197 [gl_cv_getxattr_with_posix_acls=yes])])
199 if test "$gl_cv_getxattr_with_posix_acls" = yes; then
201 AC_DEFINE([GETXATTR_WITH_POSIX_ACLS], 1,
202 [Define to 1 if getxattr works with XATTR_NAME_POSIX_ACL_ACCESS
203 and XATTR_NAME_POSIX_ACL_DEFAULT.])
205 dnl Set gl_need_lib_has_acl to a nonempty value, so that any
206 dnl later gl_FUNC_ACL call will set LIB_HAS_ACL=$LIB_ACL.
207 gl_need_lib_has_acl=1
210 AC_SUBST([LIB_HAS_ACL])