| 1 | # acl.m4 - check for access control list (ACL) primitives |
| 2 | # serial 17 |
| 3 | |
| 4 | # Copyright (C) 2002, 2004-2014 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], |
| 12 | [ |
| 13 | AC_ARG_ENABLE([acl], |
| 14 | AS_HELP_STRING([--disable-acl], [do not support ACLs]), |
| 15 | , [enable_acl=auto]) |
| 16 | |
| 17 | AC_CHECK_FUNCS_ONCE([fchmod]) |
| 18 | LIB_ACL= |
| 19 | use_acl=0 |
| 20 | if test "x$enable_acl" != "xno"; then |
| 21 | dnl On all platforms, the ACL related API is declared in <sys/acl.h>. |
| 22 | AC_CHECK_HEADERS([sys/acl.h]) |
| 23 | if test $ac_cv_header_sys_acl_h = yes; then |
| 24 | ac_save_LIBS=$LIBS |
| 25 | |
| 26 | dnl Test for POSIX-draft-like API (Linux, FreeBSD, Mac OS X, IRIX, Tru64). |
| 27 | dnl -lacl is needed on Linux, -lpacl is needed on OSF/1. |
| 28 | if test $use_acl = 0; then |
| 29 | AC_SEARCH_LIBS([acl_get_file], [acl pacl], |
| 30 | [if test "$ac_cv_search_acl_get_file" != "none required"; then |
| 31 | LIB_ACL=$ac_cv_search_acl_get_file |
| 32 | fi |
| 33 | AC_CHECK_FUNCS( |
| 34 | [acl_get_file acl_get_fd acl_set_file acl_set_fd \ |
| 35 | acl_free acl_from_mode acl_from_text \ |
| 36 | acl_delete_def_file acl_extended_file \ |
| 37 | acl_delete_fd_np acl_delete_file_np \ |
| 38 | acl_copy_ext_native acl_create_entry_np \ |
| 39 | acl_to_short_text acl_free_text]) |
| 40 | # If the acl_get_file bug is detected, don't enable the ACL support. |
| 41 | gl_ACL_GET_FILE([use_acl=1], []) |
| 42 | if test $use_acl = 1; then |
| 43 | dnl On Linux, additional API is declared in <acl/libacl.h>. |
| 44 | AC_CHECK_HEADERS([acl/libacl.h]) |
| 45 | AC_REPLACE_FUNCS([acl_entries]) |
| 46 | AC_CACHE_CHECK([for ACL_FIRST_ENTRY], |
| 47 | [gl_cv_acl_ACL_FIRST_ENTRY], |
| 48 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( |
| 49 | [[#include <sys/types.h> |
| 50 | #include <sys/acl.h> |
| 51 | int type = ACL_FIRST_ENTRY;]])], |
| 52 | [gl_cv_acl_ACL_FIRST_ENTRY=yes], |
| 53 | [gl_cv_acl_ACL_FIRST_ENTRY=no])]) |
| 54 | if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then |
| 55 | AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1], |
| 56 | [Define to 1 if the constant ACL_FIRST_ENTRY exists.]) |
| 57 | fi |
| 58 | dnl On Mac OS X, other types of ACLs are supported. |
| 59 | AC_CACHE_CHECK([for ACL_TYPE_EXTENDED], |
| 60 | [gl_cv_acl_ACL_TYPE_EXTENDED], |
| 61 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( |
| 62 | [[#include <sys/types.h> |
| 63 | #include <sys/acl.h> |
| 64 | int type = ACL_TYPE_EXTENDED;]])], |
| 65 | [gl_cv_acl_ACL_TYPE_EXTENDED=yes], |
| 66 | [gl_cv_acl_ACL_TYPE_EXTENDED=no])]) |
| 67 | if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then |
| 68 | AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1], |
| 69 | [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.]) |
| 70 | fi |
| 71 | else |
| 72 | LIB_ACL= |
| 73 | fi |
| 74 | ]) |
| 75 | fi |
| 76 | |
| 77 | dnl Test for Solaris API (Solaris, Cygwin). |
| 78 | if test $use_acl = 0; then |
| 79 | AC_CHECK_FUNCS([facl]) |
| 80 | if test $ac_cv_func_facl = yes; then |
| 81 | AC_SEARCH_LIBS([acl_trivial], [sec], |
| 82 | [if test "$ac_cv_search_acl_trivial" != "none required"; then |
| 83 | LIB_ACL=$ac_cv_search_acl_trivial |
| 84 | fi |
| 85 | ]) |
| 86 | AC_CHECK_FUNCS([acl_trivial]) |
| 87 | use_acl=1 |
| 88 | fi |
| 89 | fi |
| 90 | |
| 91 | dnl Test for HP-UX API. |
| 92 | if test $use_acl = 0; then |
| 93 | AC_CHECK_FUNCS([getacl]) |
| 94 | if test $ac_cv_func_getacl = yes; then |
| 95 | use_acl=1 |
| 96 | fi |
| 97 | dnl Test for HP-UX 11.11 API. |
| 98 | AC_CHECK_HEADERS([aclv.h], [], [], [#include <sys/types.h>]) |
| 99 | fi |
| 100 | |
| 101 | dnl Test for AIX API (AIX 5.3 or newer). |
| 102 | if test $use_acl = 0; then |
| 103 | AC_CHECK_FUNCS([aclx_get]) |
| 104 | if test $ac_cv_func_aclx_get = yes; then |
| 105 | use_acl=1 |
| 106 | fi |
| 107 | fi |
| 108 | |
| 109 | dnl Test for older AIX API. |
| 110 | if test $use_acl = 0 || test "$ac_cv_func_aclx_get" = yes; then |
| 111 | AC_CHECK_FUNCS([statacl]) |
| 112 | if test $ac_cv_func_statacl = yes; then |
| 113 | use_acl=1 |
| 114 | fi |
| 115 | fi |
| 116 | |
| 117 | dnl Test for NonStop Kernel API. |
| 118 | if test $use_acl = 0; then |
| 119 | AC_CHECK_FUNCS([aclsort]) |
| 120 | if test $ac_cv_func_aclsort = yes; then |
| 121 | use_acl=1 |
| 122 | fi |
| 123 | fi |
| 124 | |
| 125 | LIBS=$ac_save_LIBS |
| 126 | fi |
| 127 | if test "x$enable_acl$use_acl" = "xyes0"; then |
| 128 | AC_MSG_ERROR([ACLs enabled but support not detected]) |
| 129 | elif test "x$enable_acl$use_acl" = "xauto0"; then |
| 130 | AC_MSG_WARN([libacl development library was not found or not usable.]) |
| 131 | AC_MSG_WARN([AC_PACKAGE_NAME will be built without ACL support.]) |
| 132 | fi |
| 133 | fi |
| 134 | AC_SUBST([LIB_ACL]) |
| 135 | AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl], |
| 136 | [Define to nonzero if you want access control list support.]) |
| 137 | USE_ACL=$use_acl |
| 138 | AC_SUBST([USE_ACL]) |
| 139 | ]) |
| 140 | |
| 141 | # gl_ACL_GET_FILE(IF-WORKS, IF-NOT) |
| 142 | # ------------------------------------- |
| 143 | # If 'acl_get_file' works (does not have a particular bug), |
| 144 | # run IF-WORKS, otherwise, IF-NOT. |
| 145 | # When building natively, test for a Darwin 8.7.0 bug, whereby acl_get_file |
| 146 | # returns NULL, but sets errno = ENOENT for an existing file or directory. |
| 147 | # When cross-compiling, assume that this old bug no longer applies. |
| 148 | AC_DEFUN([gl_ACL_GET_FILE], |
| 149 | [ |
| 150 | AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file], |
| 151 | [gl_cv_func_working_acl_get_file=no |
| 152 | AC_LINK_IFELSE( |
| 153 | [AC_LANG_PROGRAM( |
| 154 | [[#include <sys/types.h> |
| 155 | #include <sys/acl.h> |
| 156 | #include <errno.h> |
| 157 | ]], |
| 158 | [[if (!acl_get_file (".", ACL_TYPE_ACCESS) && errno == ENOENT) |
| 159 | return 1; |
| 160 | return 0; |
| 161 | ]])], |
| 162 | [if test $cross_compiling = yes; then |
| 163 | gl_cv_func_working_acl_get_file="guessing yes" |
| 164 | elif ./conftest$ac_exeext; then |
| 165 | gl_cv_func_working_acl_get_file=yes |
| 166 | fi])]) |
| 167 | AS_IF([test "$gl_cv_func_working_acl_get_file" != no], [$1], [$2]) |
| 168 | ]) |