Import upstream version 1.28
[debian/tar] / gnu / acl-internal.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Internal implementation of access control lists.
4
5    Copyright (C) 2002-2003, 2005-2014 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20    Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible.  */
21
22 #include "acl.h"
23
24 #include <stdbool.h>
25 #include <stdlib.h>
26
27 /* All systems define the ACL related API in <sys/acl.h>.  */
28 #if HAVE_SYS_ACL_H
29 # include <sys/acl.h>
30 #endif
31 #if defined HAVE_FACL && ! defined GETACLCNT && defined ACL_CNT
32 # define GETACLCNT ACL_CNT
33 #endif
34
35 /* On Linux, additional ACL related API is available in <acl/libacl.h>.  */
36 #ifdef HAVE_ACL_LIBACL_H
37 # include <acl/libacl.h>
38 #endif
39
40 /* On HP-UX >= 11.11, additional ACL API is available in <aclv.h>.  */
41 #if HAVE_ACLV_H
42 # include <sys/types.h>
43 # include <aclv.h>
44 /* HP-UX 11.11 lacks these declarations.  */
45 extern int acl (char *, int, int, struct acl *);
46 extern int aclsort (int, int, struct acl *);
47 #endif
48
49 #include <errno.h>
50
51 #include <limits.h>
52 #ifndef MIN
53 # define MIN(a,b) ((a) < (b) ? (a) : (b))
54 #endif
55
56 #ifndef SIZE_MAX
57 # define SIZE_MAX ((size_t) -1)
58 #endif
59
60 #ifndef HAVE_FCHMOD
61 # define HAVE_FCHMOD false
62 # define fchmod(fd, mode) (-1)
63 #endif
64
65 #ifndef _GL_INLINE_HEADER_BEGIN
66  #error "Please include config.h first."
67 #endif
68 _GL_INLINE_HEADER_BEGIN
69 #ifndef ACL_INTERNAL_INLINE
70 # define ACL_INTERNAL_INLINE _GL_INLINE
71 #endif
72
73 #if USE_ACL
74
75 # if HAVE_ACL_GET_FILE
76 /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
77 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
78
79 #  ifndef MIN_ACL_ENTRIES
80 #   define MIN_ACL_ENTRIES 4
81 #  endif
82
83 /* POSIX 1003.1e (draft 17) */
84 #  ifdef HAVE_ACL_GET_FD
85 /* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument
86    macro(!).  */
87 #   if HAVE_ACL_FREE_TEXT /* OSF/1 */
88 ACL_INTERNAL_INLINE acl_t
89 rpl_acl_get_fd (int fd)
90 {
91   return acl_get_fd (fd, ACL_TYPE_ACCESS);
92 }
93 #    undef acl_get_fd
94 #    define acl_get_fd rpl_acl_get_fd
95 #   endif
96 #  else
97 #   define HAVE_ACL_GET_FD false
98 #   undef acl_get_fd
99 #   define acl_get_fd(fd) (NULL)
100 #  endif
101
102 /* POSIX 1003.1e (draft 17) */
103 #  ifdef HAVE_ACL_SET_FD
104 /* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument
105    macro(!).  */
106 #   if HAVE_ACL_FREE_TEXT /* OSF/1 */
107 ACL_INTERNAL_INLINE int
108 rpl_acl_set_fd (int fd, acl_t acl)
109 {
110   return acl_set_fd (fd, ACL_TYPE_ACCESS, acl);
111 }
112 #    undef acl_set_fd
113 #    define acl_set_fd rpl_acl_set_fd
114 #   endif
115 #  else
116 #   define HAVE_ACL_SET_FD false
117 #   undef acl_set_fd
118 #   define acl_set_fd(fd, acl) (-1)
119 #  endif
120
121 /* POSIX 1003.1e (draft 13) */
122 #  if ! HAVE_ACL_FREE_TEXT
123 #   define acl_free_text(buf) acl_free (buf)
124 #  endif
125
126 /* Linux-specific */
127 #  ifndef HAVE_ACL_EXTENDED_FILE
128 #   define HAVE_ACL_EXTENDED_FILE false
129 #   define acl_extended_file(name) (-1)
130 #  endif
131
132 /* Linux-specific */
133 #  ifndef HAVE_ACL_FROM_MODE
134 #   define HAVE_ACL_FROM_MODE false
135 #   define acl_from_mode(mode) (NULL)
136 #  endif
137
138 /* Set to 1 if a file's mode is implicit by the ACL.
139    Set to 0 if a file's mode is stored independently from the ACL.  */
140 #  if (HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP) || defined __sgi /* Mac OS X, IRIX */
141 #   define MODE_INSIDE_ACL 0
142 #  else
143 #   define MODE_INSIDE_ACL 1
144 #  endif
145
146 /* Return the number of entries in ACL.
147    Return -1 and set errno upon failure to determine it.  */
148 /* Define a replacement for acl_entries if needed. (Only Linux has it.)  */
149 #  if !HAVE_ACL_ENTRIES
150 #   define acl_entries rpl_acl_entries
151 extern int acl_entries (acl_t);
152 #  endif
153
154 #  if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
155 /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
156    Return 1 if the given ACL is non-trivial.
157    Return 0 if it is trivial.  */
158 extern int acl_extended_nontrivial (acl_t);
159 #  else
160 /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
161    Return 1 if the given ACL is non-trivial.
162    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
163    Return -1 and set errno upon failure to determine it.  */
164 extern int acl_access_nontrivial (acl_t);
165 #  endif
166
167 # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
168
169 /* Set to 1 if a file's mode is implicit by the ACL.
170    Set to 0 if a file's mode is stored independently from the ACL.  */
171 #  if defined __CYGWIN__ /* Cygwin */
172 #   define MODE_INSIDE_ACL 0
173 #  else /* Solaris */
174 #   define MODE_INSIDE_ACL 1
175 #  endif
176
177 /* Return 1 if the given ACL is non-trivial.
178    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
179 extern int acl_nontrivial (int count, aclent_t *entries);
180
181 #  ifdef ACE_GETACL /* Solaris 10 */
182
183 /* Test an ACL retrieved with ACE_GETACL.
184    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
185    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
186 extern int acl_ace_nontrivial (int count, ace_t *entries);
187
188 /* Definitions for when the built executable is executed on Solaris 10
189    (newer version) or Solaris 11.  */
190 /* For a_type.  */
191 #   define OLD_ALLOW 0
192 #   define OLD_DENY  1
193 #   define NEW_ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */
194 #   define NEW_ACE_ACCESS_DENIED_ACE_TYPE  1 /* replaces DENY */
195 /* For a_flags.  */
196 #   define OLD_ACE_OWNER            0x0100
197 #   define OLD_ACE_GROUP            0x0200
198 #   define OLD_ACE_OTHER            0x0400
199 #   define NEW_ACE_OWNER            0x1000
200 #   define NEW_ACE_GROUP            0x2000
201 #   define NEW_ACE_IDENTIFIER_GROUP 0x0040
202 #   define NEW_ACE_EVERYONE         0x4000
203 /* For a_access_mask.  */
204 #   define NEW_ACE_READ_DATA         0x001 /* corresponds to 'r' */
205 #   define NEW_ACE_WRITE_DATA        0x002 /* corresponds to 'w' */
206 #   define NEW_ACE_APPEND_DATA       0x004
207 #   define NEW_ACE_READ_NAMED_ATTRS  0x008
208 #   define NEW_ACE_WRITE_NAMED_ATTRS 0x010
209 #   define NEW_ACE_EXECUTE           0x020
210 #   define NEW_ACE_DELETE_CHILD      0x040
211 #   define NEW_ACE_READ_ATTRIBUTES   0x080
212 #   define NEW_ACE_WRITE_ATTRIBUTES  0x100
213 #   define NEW_ACE_DELETE          0x10000
214 #   define NEW_ACE_READ_ACL        0x20000
215 #   define NEW_ACE_WRITE_ACL       0x40000
216 #   define NEW_ACE_WRITE_OWNER     0x80000
217 #   define NEW_ACE_SYNCHRONIZE    0x100000
218
219 #  endif
220
221 # elif HAVE_GETACL /* HP-UX */
222
223 /* Return 1 if the given ACL is non-trivial.
224    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
225 extern int acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb);
226
227 #  if HAVE_ACLV_H /* HP-UX >= 11.11 */
228
229 /* Return 1 if the given ACL is non-trivial.
230    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
231 extern int aclv_nontrivial (int count, struct acl *entries);
232
233 #  endif
234
235 # elif HAVE_ACLX_GET && 0 /* AIX */
236
237 /* TODO */
238
239 # elif HAVE_STATACL /* older AIX */
240
241 /* Return 1 if the given ACL is non-trivial.
242    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
243 extern int acl_nontrivial (struct acl *a);
244
245 # elif HAVE_ACLSORT /* NonStop Kernel */
246
247 /* Return 1 if the given ACL is non-trivial.
248    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
249 extern int acl_nontrivial (int count, struct acl *entries);
250
251 # endif
252
253 #endif
254
255 _GL_INLINE_HEADER_END