Add support for ACLs on OSF/1.
[gnulib.git] / m4 / acl.m4
1 # acl.m4 - check for access control list (ACL) primitives
2 # serial 6
3
4 # Copyright (C) 2002, 2004-2008 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   LIB_ACL=
18   use_acl=0
19   AC_REQUIRE([AC_C_INLINE])
20   if test "x$enable_acl" != "xno"; then
21     dnl Prerequisites of lib/acl.c.
22     AC_CHECK_HEADERS(sys/acl.h)
23     if test $ac_cv_header_sys_acl_h = yes; then
24       ac_save_LIBS=$LIBS
25       AC_CHECK_FUNCS([acl])
26       use_acl=1
27       AC_SEARCH_LIBS([acl_trivial], [sec],
28         [test "$ac_cv_search_acl_trivial" = "none required" ||
29          LIB_ACL=$ac_cv_search_acl_trivial
30          AC_CHECK_FUNCS([acl_trivial])],
31         [AC_CHECK_FUNCS([acl_trivial])
32          if test $ac_cv_func_acl_trivial != yes; then
33            dnl -lacl is needed on Linux, -lpacl is needed on OSF/1.
34            AC_SEARCH_LIBS([acl_get_file], [acl pacl],
35              [test "$ac_cv_search_acl_get_file" = "none required" ||
36               LIB_ACL=$ac_cv_search_acl_get_file
37               AC_CHECK_FUNCS(
38                 [acl_get_file acl_get_fd acl_set_file acl_set_fd \
39                  acl_free acl_from_mode acl_from_text \
40                  acl_delete_def_file acl_extended_file \
41                  acl_delete_fd_np acl_delete_file_np \
42                  acl_copy_ext_native acl_create_entry_np \
43                  acl_to_short_text acl_free_text])
44               if test $ac_cv_func_acl_get_file = yes; then
45                 # If the acl_get_file bug is detected, disable all ACL support.
46                 gl_ACL_GET_FILE( , [use_acl=0])
47               fi
48               if test $use_acl = 1; then
49                 AC_CHECK_HEADERS([acl/libacl.h])
50                 if test $ac_cv_func_acl_get_file = yes &&
51                    test $ac_cv_func_acl_free = yes; then
52                   AC_REPLACE_FUNCS([acl_entries])
53                 fi
54               else
55                 LIB_ACL=
56               fi])
57          fi])
58       LIBS=$ac_save_LIBS
59     fi
60     if test "x$enable_acl$use_acl" = "xyes0"; then
61       AC_MSG_ERROR([ACLs enabled but support not detected])
62     fi
63   fi
64   AC_SUBST([LIB_ACL])
65   AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
66     [Define to nonzero if you want access control list support.])
67
68   # This is for backwards compatibility; remove this by the end of 2007.
69   LIB_ACL_TRIVIAL=
70   AC_SUBST([LIB_ACL_TRIVIAL])
71 ])
72
73 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
74 # -------------------------------------
75 # If `acl_get_file' works (does not have a particular bug),
76 # run IF-WORKS, otherwise, IF-NOT.
77 # This tests for a Darwin 8.7.0 bug, whereby acl_get_file returns NULL,
78 # but sets errno = ENOENT for an existing file or directory.
79 AC_DEFUN([gl_ACL_GET_FILE],
80 [
81   AC_CACHE_CHECK([for working acl_get_file], gl_cv_func_working_acl_get_file,
82     [AC_RUN_IFELSE(
83        [AC_LANG_PROGRAM(
84           [[#include <sys/types.h>
85            #include <sys/acl.h>
86            #include <errno.h>
87           ]],
88           [[return !! (!acl_get_file (".", ACL_TYPE_ACCESS)
89                        && errno == ENOENT);]])],
90        [gl_cv_func_working_acl_get_file=yes],
91        [gl_cv_func_working_acl_get_file=no],
92        [gl_cv_func_working_acl_get_file=cross-compiling])])
93
94   AS_IF([test $gl_cv_func_working_acl_get_file = yes], [$1], [$2])
95 ])