1# acl.m4 - check for access control list (ACL) primitives 2# serial 23 3 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. 8 9# Written by Paul Eggert and Jim Meyering. 10 11AC_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 20AC_DEFUN([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> 58int 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> 71int 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 test $gl_need_lib_has_acl && LIB_HAS_ACL=$LIB_ACL 143 AC_SUBST([LIB_ACL]) 144 AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl], 145 [Define to nonzero if you want access control list support.]) 146 USE_ACL=$use_acl 147 AC_SUBST([USE_ACL]) 148]) 149 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. 157AC_DEFUN([gl_ACL_GET_FILE], 158[ 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 161 AC_LINK_IFELSE( 162 [AC_LANG_PROGRAM( 163 [[#include <sys/types.h> 164 #include <sys/acl.h> 165 #include <errno.h> 166 ]], 167 [[acl_t acl = acl_get_file (".", ACL_TYPE_ACCESS); 168 return acl ? acl_free (acl) != 0 : errno == ENOENT; 169 ]])], 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 174 fi])]) 175 AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2]) 176]) 177 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. 180AC_DEFUN([gl_FILE_HAS_ACL], 181[ 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 187 AC_LINK_IFELSE( 188 [AC_LANG_PROGRAM( 189 [[#include <sys/types.h> 190 #include <sys/xattr.h> 191 #include <linux/xattr.h> 192 ]], 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; 196 ]])], 197 [gl_cv_getxattr_with_posix_acls=yes])]) 198 fi 199 if test "$gl_cv_getxattr_with_posix_acls" = yes; then 200 LIB_HAS_ACL= 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.]) 204 else 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 208 LIB_HAS_ACL=$LIB_ACL 209 fi 210 AC_SUBST([LIB_HAS_ACL]) 211]) 212