b8b7f117e0b5bc3b633e76faeafb51a336c04e6b
[rsync/rsync.git] / lib / sysacls.h
1 /*
2  * Unix SMB/Netbios implementation.
3  * Version 2.2.x
4  * Portable SMB ACL interface
5  * Copyright (C) Jeremy Allison 2000
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 version 3 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * with this program; if not, visit the http://fsf.org website.
18  */
19
20 #ifdef SUPPORT_ACLS
21
22 #ifdef HAVE_SYS_ACL_H
23 #include <sys/acl.h>
24 #endif
25 #ifdef HAVE_ACL_LIBACL_H
26 #include <acl/libacl.h>
27 #endif
28
29 #define SMB_MALLOC(cnt) new_array(char, cnt)
30 #define SMB_MALLOC_P(obj) new_array(obj, 1)
31 #define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
32 #define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
33 #define slprintf snprintf
34
35 #if defined HAVE_POSIX_ACLS
36
37 /* This is an identity mapping (just remove the SMB_). */
38
39 #define SMB_ACL_TAG_T           acl_tag_t
40 #define SMB_ACL_TYPE_T          acl_type_t
41 #define SMB_ACL_PERMSET_T       acl_permset_t
42
43 /* Types of ACLs. */
44 #define SMB_ACL_USER            ACL_USER
45 #define SMB_ACL_USER_OBJ        ACL_USER_OBJ
46 #define SMB_ACL_GROUP           ACL_GROUP
47 #define SMB_ACL_GROUP_OBJ       ACL_GROUP_OBJ
48 #define SMB_ACL_OTHER           ACL_OTHER
49 #define SMB_ACL_MASK            ACL_MASK
50
51 #define SMB_ACL_T               acl_t
52
53 #define SMB_ACL_ENTRY_T         acl_entry_t
54
55 #define SMB_ACL_FIRST_ENTRY     ACL_FIRST_ENTRY
56 #define SMB_ACL_NEXT_ENTRY      ACL_NEXT_ENTRY
57
58 #define SMB_ACL_TYPE_ACCESS     ACL_TYPE_ACCESS
59 #define SMB_ACL_TYPE_DEFAULT    ACL_TYPE_DEFAULT
60
61 #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
62 #define SMB_ACL_VALID_OBJ_BITS  (4 | 2 | 1)
63
64 #define SMB_ACL_NEED_SORT
65
66 #elif defined HAVE_TRU64_ACLS
67
68 /* This is for DEC/Compaq Tru64 UNIX */
69
70 #define SMB_ACL_TAG_T           acl_tag_t
71 #define SMB_ACL_TYPE_T          acl_type_t
72 #define SMB_ACL_PERMSET_T       acl_permset_t
73
74 /* Types of ACLs. */
75 #define SMB_ACL_USER            ACL_USER
76 #define SMB_ACL_USER_OBJ        ACL_USER_OBJ
77 #define SMB_ACL_GROUP           ACL_GROUP
78 #define SMB_ACL_GROUP_OBJ       ACL_GROUP_OBJ
79 #define SMB_ACL_OTHER           ACL_OTHER
80 #define SMB_ACL_MASK            ACL_MASK
81
82 #define SMB_ACL_T               acl_t
83
84 #define SMB_ACL_ENTRY_T         acl_entry_t
85
86 #define SMB_ACL_FIRST_ENTRY     0
87 #define SMB_ACL_NEXT_ENTRY      1
88
89 #define SMB_ACL_TYPE_ACCESS     ACL_TYPE_ACCESS
90 #define SMB_ACL_TYPE_DEFAULT    ACL_TYPE_DEFAULT
91
92 #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
93 #define SMB_ACL_VALID_OBJ_BITS  (4 | 2 | 1)
94
95 #define SMB_ACL_NEED_SORT
96
97 #elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
98
99 /* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
100  * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.  */
101
102 /* SVR4.2 ES/MP ACLs */
103 typedef int SMB_ACL_TAG_T;
104 typedef int SMB_ACL_TYPE_T;
105 typedef ushort *SMB_ACL_PERMSET_T;
106
107 /* Types of ACLs. */
108 #define SMB_ACL_USER            USER
109 #define SMB_ACL_USER_OBJ        USER_OBJ
110 #define SMB_ACL_GROUP           GROUP
111 #define SMB_ACL_GROUP_OBJ       GROUP_OBJ
112 #define SMB_ACL_OTHER           OTHER_OBJ
113 #define SMB_ACL_MASK            CLASS_OBJ
114
115 typedef struct SMB_ACL_T {
116         int size;
117         int count;
118         int next;
119         struct acl acl[1];
120 } *SMB_ACL_T;
121
122 typedef struct acl *SMB_ACL_ENTRY_T;
123
124 #define SMB_ACL_FIRST_ENTRY     0
125 #define SMB_ACL_NEXT_ENTRY      1
126
127 #define SMB_ACL_TYPE_ACCESS     0
128 #define SMB_ACL_TYPE_DEFAULT    1
129
130 #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
131 #define SMB_ACL_VALID_OBJ_BITS  (4 | 2 | 1)
132
133 #define SMB_ACL_NEED_SORT
134
135 #ifdef __CYGWIN__
136 #define SMB_ACL_LOSES_SPECIAL_MODE_BITS
137 #endif
138
139 #elif defined HAVE_HPUX_ACLS
140
141 /* Based on the Solaris & UnixWare code. */
142
143 #undef GROUP
144 #include <sys/aclv.h>
145
146 /* SVR4.2 ES/MP ACLs */
147 typedef int SMB_ACL_TAG_T;
148 typedef int SMB_ACL_TYPE_T;
149 typedef ushort *SMB_ACL_PERMSET_T;
150
151 /* Types of ACLs. */
152 #define SMB_ACL_USER            USER
153 #define SMB_ACL_USER_OBJ        USER_OBJ
154 #define SMB_ACL_GROUP           GROUP
155 #define SMB_ACL_GROUP_OBJ       GROUP_OBJ
156 #define SMB_ACL_OTHER           OTHER_OBJ
157 #define SMB_ACL_MASK            CLASS_OBJ
158
159 typedef struct SMB_ACL_T {
160         int size;
161         int count;
162         int next;
163         struct acl acl[1];
164 } *SMB_ACL_T;
165
166 typedef struct acl *SMB_ACL_ENTRY_T;
167
168 #define SMB_ACL_FIRST_ENTRY     0
169 #define SMB_ACL_NEXT_ENTRY      1
170
171 #define SMB_ACL_TYPE_ACCESS     0
172 #define SMB_ACL_TYPE_DEFAULT    1
173
174 #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
175 #define SMB_ACL_VALID_OBJ_BITS  (4 | 2 | 1)
176
177 #define SMB_ACL_NEED_SORT
178
179 #elif defined HAVE_IRIX_ACLS
180
181 /* IRIX ACLs */
182
183 #define SMB_ACL_TAG_T           acl_tag_t
184 #define SMB_ACL_TYPE_T          acl_type_t
185 #define SMB_ACL_PERMSET_T       acl_permset_t
186
187 /* Types of ACLs. */
188 #define SMB_ACL_USER            ACL_USER
189 #define SMB_ACL_USER_OBJ        ACL_USER_OBJ
190 #define SMB_ACL_GROUP           ACL_GROUP
191 #define SMB_ACL_GROUP_OBJ       ACL_GROUP_OBJ
192 #define SMB_ACL_OTHER           ACL_OTHER_OBJ
193 #define SMB_ACL_MASK            ACL_MASK
194
195 typedef struct SMB_ACL_T {
196         int next;
197         BOOL freeaclp;
198         struct acl *aclp;
199 } *SMB_ACL_T;
200
201 #define SMB_ACL_ENTRY_T         acl_entry_t
202
203 #define SMB_ACL_FIRST_ENTRY     0
204 #define SMB_ACL_NEXT_ENTRY      1
205
206 #define SMB_ACL_TYPE_ACCESS     ACL_TYPE_ACCESS
207 #define SMB_ACL_TYPE_DEFAULT    ACL_TYPE_DEFAULT
208
209 #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
210 #define SMB_ACL_VALID_OBJ_BITS  (4 | 2 | 1)
211
212 #define SMB_ACL_NEED_SORT
213
214 #elif defined HAVE_AIX_ACLS
215
216 /* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
217
218 #include "/usr/include/acl.h"
219
220 typedef uint *SMB_ACL_PERMSET_T;
221  
222 struct acl_entry_link{
223         struct acl_entry_link *prevp;
224         struct new_acl_entry *entryp;
225         struct acl_entry_link *nextp;
226         int count;
227 };
228
229 struct new_acl_entry{
230         unsigned short ace_len;
231         unsigned short ace_type;
232         unsigned int ace_access;
233         struct ace_id ace_id[1];
234 };
235
236 #define SMB_ACL_ENTRY_T         struct new_acl_entry*
237 #define SMB_ACL_T               struct acl_entry_link*
238  
239 #define SMB_ACL_TAG_T           unsigned short
240 #define SMB_ACL_TYPE_T          int
241
242 /* Types of ACLs. */
243 #define SMB_ACL_USER            ACEID_USER
244 #define SMB_ACL_USER_OBJ        3
245 #define SMB_ACL_GROUP           ACEID_GROUP
246 #define SMB_ACL_GROUP_OBJ       4
247 #define SMB_ACL_OTHER           5
248 #define SMB_ACL_MASK            6
249
250
251 #define SMB_ACL_FIRST_ENTRY     1
252 #define SMB_ACL_NEXT_ENTRY      2
253
254 #define SMB_ACL_TYPE_ACCESS     0
255 #define SMB_ACL_TYPE_DEFAULT    1
256
257 #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1)
258 #define SMB_ACL_VALID_OBJ_BITS  (4 | 2 | 1)
259
260 #define SMB_ACL_NEED_SORT
261
262 #else
263
264 /* Unknown platform. */
265
266 #error Cannot handle ACLs on this platform!
267
268 #endif
269
270 int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
271 int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
272 int sys_acl_get_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 *bits);
273 void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
274 SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
275 SMB_ACL_T sys_acl_get_fd(int fd);
276 SMB_ACL_T sys_acl_init(int count);
277 int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
278 int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
279 int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
280 int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits);
281 int sys_acl_valid(SMB_ACL_T theacl);
282 int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
283 int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
284 int sys_acl_delete_def_file(const char *name);
285 int sys_acl_free_acl(SMB_ACL_T the_acl);
286 int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
287 int no_acl_syscall_error(int err);
288
289 #endif /* SUPPORT_ACLS */