| 1 |
# acl.m4 - check for access control list (ACL) primitives |
| 2 |
# serial 29 |
| 3 |
|
| 4 |
# Copyright (C) 2002, 2004-2023 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. |
| 8 |
|
| 9 |
# Written by Paul Eggert and Jim Meyering. |
| 10 |
|
| 11 |
AC_DEFUN([gl_FUNC_ACL_ARG], |
| 12 |
[ |
| 13 |
gl_need_lib_has_acl= |
| 14 |
AC_ARG_ENABLE([acl], |
| 15 |
AS_HELP_STRING([[--disable-acl]], [do not support ACLs]), |
| 16 |
, [enable_acl=auto]) |
| 17 |
]) |
| 18 |
|
| 19 |
|
| 20 |
AC_DEFUN_ONCE([gl_FUNC_ACL], |
| 21 |
[ |
| 22 |
AC_REQUIRE([gl_FUNC_ACL_ARG]) |
| 23 |
AC_CHECK_FUNCS_ONCE([fchmod]) |
| 24 |
LIB_ACL= |
| 25 |
use_acl=0 |
| 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 |
| 30 |
ac_save_LIBS=$LIBS |
| 31 |
|
| 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 |
| 39 |
fi |
| 40 |
AC_CHECK_FUNCS( |
| 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> |
| 57 |
#include <sys/acl.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.]) |
| 64 |
fi |
| 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> |
| 70 |
#include <sys/acl.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.]) |
| 77 |
fi |
| 78 |
else |
| 79 |
LIB_ACL= |
| 80 |
fi |
| 81 |
]) |
| 82 |
fi |
| 83 |
|
| 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 |
| 91 |
fi |
| 92 |
]) |
| 93 |
AC_CHECK_FUNCS([acl_trivial]) |
| 94 |
use_acl=1 |
| 95 |
fi |
| 96 |
fi |
| 97 |
|
| 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 |
| 102 |
use_acl=1 |
| 103 |
fi |
| 104 |
dnl Test for HP-UX 11.11 API. |
| 105 |
AC_CHECK_HEADERS([aclv.h], [], [], [#include <sys/types.h>]) |
| 106 |
fi |
| 107 |
|
| 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 |
| 112 |
use_acl=1 |
| 113 |
fi |
| 114 |
fi |
| 115 |
|
| 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 |
| 120 |
use_acl=1 |
| 121 |
fi |
| 122 |
fi |
| 123 |
|
| 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 |
| 128 |
use_acl=1 |
| 129 |
fi |
| 130 |
fi |
| 131 |
|
| 132 |
LIBS=$ac_save_LIBS |
| 133 |
fi |
| 134 |
|
| 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.]) |
| 140 |
fi |
| 141 |
fi |
| 142 |
if test -n "$gl_need_lib_has_acl"; then |
| 143 |
FILE_HAS_ACL_LIB=$LIB_ACL |
| 144 |
fi |
| 145 |
AC_SUBST([LIB_ACL]) |
| 146 |
AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl], |
| 147 |
[Define to nonzero if you want access control list support.]) |
| 148 |
USE_ACL=$use_acl |
| 149 |
AC_SUBST([USE_ACL]) |
| 150 |
]) |
| 151 |
|
| 152 |
# gl_ACL_GET_FILE(IF-WORKS, IF-NOT) |
| 153 |
# --------------------------------- |
| 154 |
# If 'acl_get_file' works (does not have a particular bug), |
| 155 |
# run IF-WORKS, otherwise, IF-NOT. |
| 156 |
# When building natively, test for a Darwin 8.7.0 bug, whereby acl_get_file |
| 157 |
# returns NULL, but sets errno = ENOENT for an existing file or directory. |
| 158 |
# When cross-compiling, assume that this old bug no longer applies. |
| 159 |
AC_DEFUN([gl_ACL_GET_FILE], |
| 160 |
[ |
| 161 |
AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file], |
| 162 |
[gl_cv_func_working_acl_get_file=no |
| 163 |
AC_LINK_IFELSE( |
| 164 |
[AC_LANG_PROGRAM( |
| 165 |
[[#include <sys/types.h> |
| 166 |
#include <sys/acl.h> |
| 167 |
#include <errno.h> |
| 168 |
]], |
| 169 |
[[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS); |
| 170 |
return acl ? acl_free (acl) != 0 : errno == ENOENT; |
| 171 |
]])], |
| 172 |
[if test $cross_compiling = yes; then |
| 173 |
gl_cv_func_working_acl_get_file="guessing yes" |
| 174 |
elif ./conftest$ac_exeext; then |
| 175 |
gl_cv_func_working_acl_get_file=yes |
| 176 |
fi])]) |
| 177 |
AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2]) |
| 178 |
]) |
| 179 |
|
| 180 |
# On GNU/Linux, testing if a file has an acl can be done with the |
| 181 |
# listxattr and getxattr syscalls, which don't require linking |
| 182 |
# against additional libraries. Assume this works if linux/attr.h |
| 183 |
# and listxattr are present. |
| 184 |
AC_DEFUN([gl_FILE_HAS_ACL], |
| 185 |
[ |
| 186 |
AC_REQUIRE([gl_FUNC_ACL_ARG]) |
| 187 |
AC_CHECK_HEADERS_ONCE([linux/xattr.h]) |
| 188 |
AC_CHECK_FUNCS_ONCE([listxattr]) |
| 189 |
FILE_HAS_ACL_LIB= |
| 190 |
AS_CASE([$enable_acl,$ac_cv_header_linux_xattr_h,$ac_cv_func_listxattr], |
| 191 |
[no,*,*], [], |
| 192 |
[*,yes,yes], [], |
| 193 |
[*], |
| 194 |
[dnl Set gl_need_lib_has_acl to a nonempty value, so that any |
| 195 |
dnl later gl_FUNC_ACL call will set FILE_HAS_ACL_LIB=$LIB_ACL. |
| 196 |
gl_need_lib_has_acl=1 |
| 197 |
FILE_HAS_ACL_LIB=$LIB_ACL]) |
| 198 |
AC_SUBST([FILE_HAS_ACL_LIB]) |
| 199 |
]) |