6d3e4cbd8236edfd1d5ab2fec8b4c15a5b9404c6
[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-2013 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 _GL_INLINE_HEADER_BEGIN
66 #ifndef ACL_INTERNAL_INLINE
67 # define ACL_INTERNAL_INLINE _GL_INLINE
68 #endif
69
70 #if USE_ACL
71
72 # if HAVE_ACL_GET_FILE
73 /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
74 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
75
76 #  ifndef MIN_ACL_ENTRIES
77 #   define MIN_ACL_ENTRIES 4
78 #  endif
79
80 /* POSIX 1003.1e (draft 17) */
81 #  ifdef HAVE_ACL_GET_FD
82 /* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument
83    macro(!).  */
84 #   if HAVE_ACL_FREE_TEXT /* OSF/1 */
85 ACL_INTERNAL_INLINE acl_t
86 rpl_acl_get_fd (int fd)
87 {
88   return acl_get_fd (fd, ACL_TYPE_ACCESS);
89 }
90 #    undef acl_get_fd
91 #    define acl_get_fd rpl_acl_get_fd
92 #   endif
93 #  else
94 #   define HAVE_ACL_GET_FD false
95 #   undef acl_get_fd
96 #   define acl_get_fd(fd) (NULL)
97 #  endif
98
99 /* POSIX 1003.1e (draft 17) */
100 #  ifdef HAVE_ACL_SET_FD
101 /* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument
102    macro(!).  */
103 #   if HAVE_ACL_FREE_TEXT /* OSF/1 */
104 ACL_INTERNAL_INLINE int
105 rpl_acl_set_fd (int fd, acl_t acl)
106 {
107   return acl_set_fd (fd, ACL_TYPE_ACCESS, acl);
108 }
109 #    undef acl_set_fd
110 #    define acl_set_fd rpl_acl_set_fd
111 #   endif
112 #  else
113 #   define HAVE_ACL_SET_FD false
114 #   undef acl_set_fd
115 #   define acl_set_fd(fd, acl) (-1)
116 #  endif
117
118 /* POSIX 1003.1e (draft 13) */
119 #  if ! HAVE_ACL_FREE_TEXT
120 #   define acl_free_text(buf) acl_free (buf)
121 #  endif
122
123 /* Linux-specific */
124 #  ifndef HAVE_ACL_EXTENDED_FILE
125 #   define HAVE_ACL_EXTENDED_FILE false
126 #   define acl_extended_file(name) (-1)
127 #  endif
128
129 /* Linux-specific */
130 #  ifndef HAVE_ACL_FROM_MODE
131 #   define HAVE_ACL_FROM_MODE false
132 #   define acl_from_mode(mode) (NULL)
133 #  endif
134
135 /* Set to 1 if a file's mode is implicit by the ACL.
136    Set to 0 if a file's mode is stored independently from the ACL.  */
137 #  if (HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP) || defined __sgi /* Mac OS X, IRIX */
138 #   define MODE_INSIDE_ACL 0
139 #  else
140 #   define MODE_INSIDE_ACL 1
141 #  endif
142
143 /* Return the number of entries in ACL.
144    Return -1 and set errno upon failure to determine it.  */
145 /* Define a replacement for acl_entries if needed. (Only Linux has it.)  */
146 #  if !HAVE_ACL_ENTRIES
147 #   define acl_entries rpl_acl_entries
148 extern int acl_entries (acl_t);
149 #  endif
150
151 #  if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
152 /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
153    Return 1 if the given ACL is non-trivial.
154    Return 0 if it is trivial.  */
155 extern int acl_extended_nontrivial (acl_t);
156 #  else
157 /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
158    Return 1 if the given ACL is non-trivial.
159    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
160    Return -1 and set errno upon failure to determine it.  */
161 extern int acl_access_nontrivial (acl_t);
162 #  endif
163
164 # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
165
166 /* Set to 1 if a file's mode is implicit by the ACL.
167    Set to 0 if a file's mode is stored independently from the ACL.  */
168 #  if defined __CYGWIN__ /* Cygwin */
169 #   define MODE_INSIDE_ACL 0
170 #  else /* Solaris */
171 #   define MODE_INSIDE_ACL 1
172 #  endif
173
174 /* Return 1 if the given ACL is non-trivial.
175    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
176 extern int acl_nontrivial (int count, aclent_t *entries);
177
178 #  ifdef ACE_GETACL /* Solaris 10 */
179
180 /* Test an ACL retrieved with ACE_GETACL.
181    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
182    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
183 extern int acl_ace_nontrivial (int count, ace_t *entries);
184
185 /* Definitions for when the built executable is executed on Solaris 10
186    (newer version) or Solaris 11.  */
187 /* For a_type.  */
188 #   define OLD_ALLOW 0
189 #   define OLD_DENY  1
190 #   define NEW_ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */
191 #   define NEW_ACE_ACCESS_DENIED_ACE_TYPE  1 /* replaces DENY */
192 /* For a_flags.  */
193 #   define OLD_ACE_OWNER            0x0100
194 #   define OLD_ACE_GROUP            0x0200
195 #   define OLD_ACE_OTHER            0x0400
196 #   define NEW_ACE_OWNER            0x1000
197 #   define NEW_ACE_GROUP            0x2000
198 #   define NEW_ACE_IDENTIFIER_GROUP 0x0040
199 #   define NEW_ACE_EVERYONE         0x4000
200 /* For a_access_mask.  */
201 #   define NEW_ACE_READ_DATA         0x001 /* corresponds to 'r' */
202 #   define NEW_ACE_WRITE_DATA        0x002 /* corresponds to 'w' */
203 #   define NEW_ACE_APPEND_DATA       0x004
204 #   define NEW_ACE_READ_NAMED_ATTRS  0x008
205 #   define NEW_ACE_WRITE_NAMED_ATTRS 0x010
206 #   define NEW_ACE_EXECUTE           0x020
207 #   define NEW_ACE_DELETE_CHILD      0x040
208 #   define NEW_ACE_READ_ATTRIBUTES   0x080
209 #   define NEW_ACE_WRITE_ATTRIBUTES  0x100
210 #   define NEW_ACE_DELETE          0x10000
211 #   define NEW_ACE_READ_ACL        0x20000
212 #   define NEW_ACE_WRITE_ACL       0x40000
213 #   define NEW_ACE_WRITE_OWNER     0x80000
214 #   define NEW_ACE_SYNCHRONIZE    0x100000
215
216 #  endif
217
218 # elif HAVE_GETACL /* HP-UX */
219
220 /* Return 1 if the given ACL is non-trivial.
221    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
222 extern int acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb);
223
224 #  if HAVE_ACLV_H /* HP-UX >= 11.11 */
225
226 /* Return 1 if the given ACL is non-trivial.
227    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
228 extern int aclv_nontrivial (int count, struct acl *entries);
229
230 #  endif
231
232 # elif HAVE_ACLX_GET && 0 /* AIX */
233
234 /* TODO */
235
236 # elif HAVE_STATACL /* older AIX */
237
238 /* Return 1 if the given ACL is non-trivial.
239    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
240 extern int acl_nontrivial (struct acl *a);
241
242 # elif HAVE_ACLSORT /* NonStop Kernel */
243
244 /* Return 1 if the given ACL is non-trivial.
245    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
246 extern int acl_nontrivial (int count, struct acl *entries);
247
248 # endif
249
250 #endif
251
252 _GL_INLINE_HEADER_END