strtod: avoid C99 decl-after-statement
[gnulib.git] / lib / acl-internal.h
1 /* Internal implementation of access control lists.
2
3    Copyright (C) 2002-2003, 2005-2008 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18    Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible.  */
19
20 #include "acl.h"
21
22 #include <stdbool.h>
23 #include <stdlib.h>
24
25 /* All systems define the ACL related API in <sys/acl.h>.  */
26 #if HAVE_SYS_ACL_H
27 # include <sys/acl.h>
28 #endif
29 #if defined HAVE_ACL && ! defined GETACLCNT && defined ACL_CNT
30 # define GETACLCNT ACL_CNT
31 #endif
32
33 /* On Linux, additional ACL related API is available in <acl/libacl.h>.  */
34 #ifdef HAVE_ACL_LIBACL_H
35 # include <acl/libacl.h>
36 #endif
37
38 #include "error.h"
39 #include "quote.h"
40
41 #include <errno.h>
42 #ifndef ENOSYS
43 # define ENOSYS (-1)
44 #endif
45 #ifndef ENOTSUP
46 # define ENOTSUP (-1)
47 #endif
48
49 #ifndef HAVE_FCHMOD
50 # define HAVE_FCHMOD false
51 # define fchmod(fd, mode) (-1)
52 #endif
53
54
55 #if USE_ACL
56
57 # if HAVE_ACL_GET_FILE
58 /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
59 /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
60
61 #  ifndef MIN_ACL_ENTRIES
62 #   define MIN_ACL_ENTRIES 4
63 #  endif
64
65 /* POSIX 1003.1e (draft 17) */
66 #  ifdef HAVE_ACL_GET_FD
67 /* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument
68    macro(!).  */
69 #   if HAVE_ACL_FREE_TEXT /* OSF/1 */
70 static inline acl_t
71 rpl_acl_get_fd (int fd)
72 {
73   return acl_get_fd (fd, ACL_TYPE_ACCESS);
74 }
75 #    undef acl_get_fd
76 #    define acl_get_fd rpl_acl_get_fd
77 #   endif
78 #  else
79 #   define HAVE_ACL_GET_FD false
80 #   undef acl_get_fd
81 #   define acl_get_fd(fd) (NULL)
82 #  endif
83
84 /* POSIX 1003.1e (draft 17) */
85 #  ifdef HAVE_ACL_SET_FD
86 /* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument
87    macro(!).  */
88 #   if HAVE_ACL_FREE_TEXT /* OSF/1 */
89 static inline int
90 rpl_acl_set_fd (int fd, acl_t acl)
91 {
92   return acl_set_fd (fd, ACL_TYPE_ACCESS, acl);
93 }
94 #    undef acl_set_fd
95 #    define acl_set_fd rpl_acl_set_fd
96 #   endif
97 #  else
98 #   define HAVE_ACL_SET_FD false
99 #   undef acl_set_fd
100 #   define acl_set_fd(fd, acl) (-1)
101 #  endif
102
103 /* POSIX 1003.1e (draft 13) */
104 #  if ! HAVE_ACL_FREE_TEXT
105 #   define acl_free_text(buf) acl_free (buf)
106 #  endif
107
108 /* Linux-specific */
109 #  ifndef HAVE_ACL_EXTENDED_FILE
110 #   define HAVE_ACL_EXTENDED_FILE false
111 #   define acl_extended_file(name) (-1)
112 #  endif
113
114 /* Linux-specific */
115 #  ifndef HAVE_ACL_FROM_MODE
116 #   define HAVE_ACL_FROM_MODE false
117 #   define acl_from_mode(mode) (NULL)
118 #  endif
119
120 /* Set to 1 if a file's mode is implicit by the ACL.
121    Set to 0 if a file's mode is stored independently from the ACL.  */
122 #  if HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP /* MacOS X */
123 #   define MODE_INSIDE_ACL 0
124 #  else
125 #   define MODE_INSIDE_ACL 1
126 #  endif
127
128 #  if defined __APPLE__ && defined __MACH__ /* MacOS X */
129 #   define ACL_NOT_WELL_SUPPORTED(Err) \
130      ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == ENOENT)
131 #  elif defined EOPNOTSUPP /* Tru64 NFS */
132 #   define ACL_NOT_WELL_SUPPORTED(Err) \
133      ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == EOPNOTSUPP)
134 #  else
135 #   define ACL_NOT_WELL_SUPPORTED(Err) \
136      ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY)
137 #  endif
138
139 /* Define a replacement for acl_entries if needed. (Only Linux has it.)  */
140 #  if !HAVE_ACL_ENTRIES
141 #   define acl_entries rpl_acl_entries
142 extern int acl_entries (acl_t);
143 #  endif
144
145 #  if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
146 /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
147    Return 1 if the given ACL is non-trivial.
148    Return 0 if it is trivial.  */
149 extern int acl_extended_nontrivial (acl_t);
150 #  else
151 /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
152    Return 1 if the given ACL is non-trivial.
153    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
154    Return -1 and set errno upon failure to determine it.  */
155 extern int acl_access_nontrivial (acl_t);
156 #  endif
157
158 # elif HAVE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
159
160 /* Set to 1 if a file's mode is implicit by the ACL.
161    Set to 0 if a file's mode is stored independently from the ACL.  */
162 #  if defined __CYGWIN__ /* Cygwin */
163 #   define MODE_INSIDE_ACL 0
164 #  else /* Solaris */
165 #   define MODE_INSIDE_ACL 1
166 #  endif
167
168 #  if !defined ACL_NO_TRIVIAL /* Solaris <= 10, Cygwin */
169
170 /* Return 1 if the given ACL is non-trivial.
171    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
172 extern int acl_nontrivial (int count, aclent_t *entries);
173
174 #   ifdef ACE_GETACL /* Solaris 10 */
175
176 /* Test an ACL retrieved with ACE_GETACL.
177    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
178    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
179 extern int acl_ace_nontrivial (int count, ace_t *entries);
180
181 /* Definitions for when the built executable is executed on Solaris 10
182    (newer version) or Solaris 11.  */
183 /* For a_type.  */
184 #    define ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */
185 #    define ACE_ACCESS_DENIED_ACE_TYPE  1 /* replaces DENY */
186 /* For a_flags.  */
187 #    define NEW_ACE_OWNER            0x1000
188 #    define NEW_ACE_GROUP            0x2000
189 #    define NEW_ACE_IDENTIFIER_GROUP 0x0040
190 #    define ACE_EVERYONE             0x4000
191 /* For a_access_mask.  */
192 #    define NEW_ACE_READ_DATA  0x001 /* corresponds to 'r' */
193 #    define NEW_ACE_WRITE_DATA 0x002 /* corresponds to 'w' */
194 #    define NEW_ACE_EXECUTE    0x004 /* corresponds to 'x' */
195
196 #   endif
197
198 #  endif
199
200 # elif HAVE_GETACL /* HP-UX */
201
202 /* Return 1 if the given ACL is non-trivial.
203    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
204 extern int acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb);
205
206 # elif HAVE_ACLX_GET && 0 /* AIX */
207
208 /* TODO */
209
210 # elif HAVE_STATACL /* older AIX */
211
212 /* Return 1 if the given ACL is non-trivial.
213    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
214 extern int acl_nontrivial (struct acl *a);
215
216 # endif
217
218 #endif