3 dnl Copyright (C) 2002, 2004-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # Check for access control list (ACL) primitives
10 # Written by Paul Eggert and Jim Meyering.
12 AC_DEFUN([gl_FUNC_ACL_ARG],
16 AS_HELP_STRING([[--disable-acl]], [do not support ACLs]),
21 AC_DEFUN_ONCE([gl_FUNC_ACL],
23 AC_REQUIRE([gl_FUNC_ACL_ARG])
24 AC_CHECK_FUNCS_ONCE([fchmod])
27 if test "$enable_acl" != no; then
28 dnl On all platforms, the ACL related API is declared in <sys/acl.h>.
29 AC_CHECK_HEADERS([sys/acl.h])
30 if test $ac_cv_header_sys_acl_h = yes; then
33 dnl Test for POSIX-draft-like API (GNU/Linux, FreeBSD, Mac OS X,
34 dnl IRIX, Tru64, Cygwin >= 2.5).
35 dnl -lacl is needed on GNU/Linux, -lpacl on OSF/1.
36 if test $use_acl = 0; then
37 AC_SEARCH_LIBS([acl_get_file], [acl pacl],
38 [if test "$ac_cv_search_acl_get_file" != "none required"; then
39 LIB_ACL=$ac_cv_search_acl_get_file
42 [acl_get_file acl_get_fd acl_set_file acl_set_fd \
43 acl_free acl_from_mode acl_from_text \
44 acl_delete_def_file acl_extended_file \
45 acl_delete_fd_np acl_delete_file_np \
46 acl_copy_ext_native acl_create_entry_np \
47 acl_to_short_text acl_free_text])
48 # If the acl_get_file bug is detected, don't enable the ACL support.
49 gl_ACL_GET_FILE([use_acl=1], [])
50 if test $use_acl = 1; then
51 dnl On GNU/Linux, an additional API is declared in <acl/libacl.h>.
52 AC_CHECK_HEADERS([acl/libacl.h])
53 AC_REPLACE_FUNCS([acl_entries])
54 AC_CACHE_CHECK([for ACL_FIRST_ENTRY],
55 [gl_cv_acl_ACL_FIRST_ENTRY],
56 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
57 [[#include <sys/types.h>
59 int type = ACL_FIRST_ENTRY;]])],
60 [gl_cv_acl_ACL_FIRST_ENTRY=yes],
61 [gl_cv_acl_ACL_FIRST_ENTRY=no])])
62 if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then
63 AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1],
64 [Define to 1 if the constant ACL_FIRST_ENTRY exists.])
66 dnl On Mac OS X, other types of ACLs are supported.
67 AC_CACHE_CHECK([for ACL_TYPE_EXTENDED],
68 [gl_cv_acl_ACL_TYPE_EXTENDED],
69 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
70 [[#include <sys/types.h>
72 int type = ACL_TYPE_EXTENDED;]])],
73 [gl_cv_acl_ACL_TYPE_EXTENDED=yes],
74 [gl_cv_acl_ACL_TYPE_EXTENDED=no])])
75 if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then
76 AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1],
77 [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.])
85 dnl Test for Solaris API (Solaris, Cygwin).
86 if test $use_acl = 0; then
87 AC_CHECK_FUNCS([facl])
88 if test $ac_cv_func_facl = yes; then
89 AC_SEARCH_LIBS([acl_trivial], [sec],
90 [if test "$ac_cv_search_acl_trivial" != "none required"; then
91 LIB_ACL=$ac_cv_search_acl_trivial
94 AC_CHECK_FUNCS([acl_trivial])
99 dnl Test for HP-UX API.
100 if test $use_acl = 0; then
101 AC_CHECK_FUNCS([getacl])
102 if test $ac_cv_func_getacl = yes; then
105 dnl Test for HP-UX 11.11 API.
106 AC_CHECK_HEADERS([aclv.h], [], [], [#include <sys/types.h>])
109 dnl Test for AIX API (AIX 5.3 or newer).
110 if test $use_acl = 0; then
111 AC_CHECK_FUNCS([aclx_get])
112 if test $ac_cv_func_aclx_get = yes; then
117 dnl Test for older AIX API.
118 if test $use_acl = 0 || test "$ac_cv_func_aclx_get" = yes; then
119 AC_CHECK_FUNCS([statacl])
120 if test $ac_cv_func_statacl = yes; then
125 dnl Test for NonStop Kernel API.
126 if test $use_acl = 0; then
127 AC_CHECK_FUNCS([aclsort])
128 if test $ac_cv_func_aclsort = yes; then
136 if test "$enable_acl$use_acl" = yes0; then
137 AC_MSG_ERROR([ACLs enabled but support not detected])
138 elif test "$enable_acl$use_acl" = auto0; then
139 AC_MSG_WARN([libacl development library was not found or not usable.])
140 AC_MSG_WARN([AC_PACKAGE_NAME will be built without ACL support.])
143 if test -n "$gl_need_lib_has_acl"; then
144 FILE_HAS_ACL_LIB=$LIB_ACL
147 AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
148 [Define to nonzero if you want access control list support.])
153 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
154 # ---------------------------------
155 # If 'acl_get_file' works (does not have a particular bug),
156 # run IF-WORKS, otherwise, IF-NOT.
157 # When building natively, test for a Darwin 8.7.0 bug, whereby acl_get_file
158 # returns NULL, but sets errno = ENOENT for an existing file or directory.
159 # When cross-compiling, assume that this old bug no longer applies.
160 AC_DEFUN([gl_ACL_GET_FILE],
162 AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file],
163 [gl_cv_func_working_acl_get_file=no
166 [[#include <sys/types.h>
170 [[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS);
171 return acl ? acl_free (acl) != 0 : errno == ENOENT;
173 [if test $cross_compiling = yes; then
174 gl_cv_func_working_acl_get_file="guessing yes"
175 elif ./conftest$ac_exeext; then
176 gl_cv_func_working_acl_get_file=yes
178 AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2])
181 # On GNU/Linux, testing if a file has an acl can be done with the
182 # listxattr and getxattr syscalls, which don't require linking
183 # against additional libraries. Assume this works if linux/attr.h
184 # and listxattr are present.
185 AC_DEFUN([gl_FILE_HAS_ACL],
187 AC_REQUIRE([gl_FUNC_ACL_ARG])
188 AC_CHECK_HEADERS_ONCE([linux/xattr.h])
189 AC_CHECK_FUNCS_ONCE([listxattr])
191 AS_CASE([$enable_acl,$ac_cv_header_linux_xattr_h,$ac_cv_func_listxattr],
195 [dnl Set gl_need_lib_has_acl to a nonempty value, so that any
196 dnl later gl_FUNC_ACL call will set FILE_HAS_ACL_LIB=$LIB_ACL.
197 gl_need_lib_has_acl=1
198 FILE_HAS_ACL_LIB=$LIB_ACL])
199 AC_SUBST([FILE_HAS_ACL_LIB])