Commit | Line | Data |
---|---|---|
4fd842f9 WD |
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 | |
8e41b68e WD |
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. | |
4fd842f9 WD |
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 | * with this program; if not, visit the http://fsf.org website. | |
19 | */ | |
1c702303 | 20 | |
1c3344a1 WD |
21 | #ifdef SUPPORT_ACLS |
22 | ||
23 | #ifdef HAVE_SYS_ACL_H | |
24 | #include <sys/acl.h> | |
25 | #endif | |
26 | #ifdef HAVE_ACL_LIBACL_H | |
27 | #include <acl/libacl.h> | |
28 | #endif | |
1c3344a1 WD |
29 | |
30 | #define SMB_MALLOC(cnt) new_array(char, cnt) | |
31 | #define SMB_MALLOC_P(obj) new_array(obj, 1) | |
32 | #define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt) | |
33 | #define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt) | |
34 | #define slprintf snprintf | |
35 | ||
d417c516 | 36 | #if defined HAVE_POSIX_ACLS /*-----------------------------------------------*/ |
1c702303 WD |
37 | |
38 | /* This is an identity mapping (just remove the SMB_). */ | |
39 | ||
40 | #define SMB_ACL_TAG_T acl_tag_t | |
41 | #define SMB_ACL_TYPE_T acl_type_t | |
1c702303 WD |
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 | ||
043ef55b WD |
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 | ||
d417c516 | 66 | #elif defined HAVE_TRU64_ACLS /*---------------------------------------------*/ |
1c702303 WD |
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 | |
1c702303 WD |
72 | |
73 | /* Types of ACLs. */ | |
74 | #define SMB_ACL_USER ACL_USER | |
75 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
76 | #define SMB_ACL_GROUP ACL_GROUP | |
77 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
78 | #define SMB_ACL_OTHER ACL_OTHER | |
79 | #define SMB_ACL_MASK ACL_MASK | |
80 | ||
81 | #define SMB_ACL_T acl_t | |
82 | ||
83 | #define SMB_ACL_ENTRY_T acl_entry_t | |
84 | ||
85 | #define SMB_ACL_FIRST_ENTRY 0 | |
86 | #define SMB_ACL_NEXT_ENTRY 1 | |
87 | ||
88 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
89 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
90 | ||
043ef55b WD |
91 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
92 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
93 | ||
94 | #define SMB_ACL_NEED_SORT | |
95 | ||
d417c516 | 96 | #elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS /*-------------*/ |
043ef55b WD |
97 | |
98 | /* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
99 | * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */ | |
1c702303 WD |
100 | |
101 | /* SVR4.2 ES/MP ACLs */ | |
102 | typedef int SMB_ACL_TAG_T; | |
103 | typedef int SMB_ACL_TYPE_T; | |
1c702303 WD |
104 | |
105 | /* Types of ACLs. */ | |
106 | #define SMB_ACL_USER USER | |
107 | #define SMB_ACL_USER_OBJ USER_OBJ | |
108 | #define SMB_ACL_GROUP GROUP | |
109 | #define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
110 | #define SMB_ACL_OTHER OTHER_OBJ | |
111 | #define SMB_ACL_MASK CLASS_OBJ | |
112 | ||
113 | typedef struct SMB_ACL_T { | |
114 | int size; | |
115 | int count; | |
116 | int next; | |
117 | struct acl acl[1]; | |
118 | } *SMB_ACL_T; | |
119 | ||
120 | typedef struct acl *SMB_ACL_ENTRY_T; | |
121 | ||
122 | #define SMB_ACL_FIRST_ENTRY 0 | |
123 | #define SMB_ACL_NEXT_ENTRY 1 | |
124 | ||
125 | #define SMB_ACL_TYPE_ACCESS 0 | |
126 | #define SMB_ACL_TYPE_DEFAULT 1 | |
127 | ||
043ef55b WD |
128 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
129 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
130 | ||
131 | #define SMB_ACL_NEED_SORT | |
132 | ||
1c702303 WD |
133 | #ifdef __CYGWIN__ |
134 | #define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
135 | #endif | |
136 | ||
d417c516 | 137 | #elif defined HAVE_HPUX_ACLS /*----------------------------------------------*/ |
1c702303 | 138 | |
043ef55b | 139 | /* Based on the Solaris & UnixWare code. */ |
1c702303 WD |
140 | |
141 | #undef GROUP | |
142 | #include <sys/aclv.h> | |
143 | ||
144 | /* SVR4.2 ES/MP ACLs */ | |
145 | typedef int SMB_ACL_TAG_T; | |
146 | typedef int SMB_ACL_TYPE_T; | |
1c702303 WD |
147 | |
148 | /* Types of ACLs. */ | |
149 | #define SMB_ACL_USER USER | |
150 | #define SMB_ACL_USER_OBJ USER_OBJ | |
151 | #define SMB_ACL_GROUP GROUP | |
152 | #define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
153 | #define SMB_ACL_OTHER OTHER_OBJ | |
154 | #define SMB_ACL_MASK CLASS_OBJ | |
155 | ||
156 | typedef struct SMB_ACL_T { | |
157 | int size; | |
158 | int count; | |
159 | int next; | |
160 | struct acl acl[1]; | |
161 | } *SMB_ACL_T; | |
162 | ||
163 | typedef struct acl *SMB_ACL_ENTRY_T; | |
164 | ||
165 | #define SMB_ACL_FIRST_ENTRY 0 | |
166 | #define SMB_ACL_NEXT_ENTRY 1 | |
167 | ||
168 | #define SMB_ACL_TYPE_ACCESS 0 | |
169 | #define SMB_ACL_TYPE_DEFAULT 1 | |
170 | ||
043ef55b WD |
171 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
172 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
173 | ||
174 | #define SMB_ACL_NEED_SORT | |
175 | ||
d417c516 | 176 | #elif defined HAVE_IRIX_ACLS /*----------------------------------------------*/ |
1c702303 | 177 | |
043ef55b WD |
178 | /* IRIX ACLs */ |
179 | ||
1c702303 WD |
180 | #define SMB_ACL_TAG_T acl_tag_t |
181 | #define SMB_ACL_TYPE_T acl_type_t | |
1c702303 WD |
182 | |
183 | /* Types of ACLs. */ | |
184 | #define SMB_ACL_USER ACL_USER | |
185 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
186 | #define SMB_ACL_GROUP ACL_GROUP | |
187 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
188 | #define SMB_ACL_OTHER ACL_OTHER_OBJ | |
189 | #define SMB_ACL_MASK ACL_MASK | |
190 | ||
191 | typedef struct SMB_ACL_T { | |
192 | int next; | |
193 | BOOL freeaclp; | |
194 | struct acl *aclp; | |
195 | } *SMB_ACL_T; | |
196 | ||
197 | #define SMB_ACL_ENTRY_T acl_entry_t | |
198 | ||
199 | #define SMB_ACL_FIRST_ENTRY 0 | |
200 | #define SMB_ACL_NEXT_ENTRY 1 | |
201 | ||
202 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
203 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
204 | ||
043ef55b WD |
205 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
206 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
207 | ||
208 | #define SMB_ACL_NEED_SORT | |
209 | ||
d417c516 | 210 | #elif defined HAVE_AIX_ACLS /*-----------------------------------------------*/ |
1c702303 WD |
211 | |
212 | /* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
213 | ||
214 | #include "/usr/include/acl.h" | |
215 | ||
1c702303 WD |
216 | struct acl_entry_link{ |
217 | struct acl_entry_link *prevp; | |
218 | struct new_acl_entry *entryp; | |
219 | struct acl_entry_link *nextp; | |
220 | int count; | |
221 | }; | |
222 | ||
223 | struct new_acl_entry{ | |
224 | unsigned short ace_len; | |
225 | unsigned short ace_type; | |
226 | unsigned int ace_access; | |
227 | struct ace_id ace_id[1]; | |
228 | }; | |
229 | ||
230 | #define SMB_ACL_ENTRY_T struct new_acl_entry* | |
231 | #define SMB_ACL_T struct acl_entry_link* | |
232 | ||
233 | #define SMB_ACL_TAG_T unsigned short | |
234 | #define SMB_ACL_TYPE_T int | |
1c702303 WD |
235 | |
236 | /* Types of ACLs. */ | |
237 | #define SMB_ACL_USER ACEID_USER | |
238 | #define SMB_ACL_USER_OBJ 3 | |
239 | #define SMB_ACL_GROUP ACEID_GROUP | |
240 | #define SMB_ACL_GROUP_OBJ 4 | |
241 | #define SMB_ACL_OTHER 5 | |
242 | #define SMB_ACL_MASK 6 | |
243 | ||
1c702303 WD |
244 | #define SMB_ACL_FIRST_ENTRY 1 |
245 | #define SMB_ACL_NEXT_ENTRY 2 | |
246 | ||
247 | #define SMB_ACL_TYPE_ACCESS 0 | |
248 | #define SMB_ACL_TYPE_DEFAULT 1 | |
249 | ||
043ef55b WD |
250 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
251 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
1c702303 | 252 | |
043ef55b | 253 | #define SMB_ACL_NEED_SORT |
1c702303 | 254 | |
d417c516 WD |
255 | #elif defined(HAVE_OSX_ACLS) /*----------------------------------------------*/ |
256 | ||
257 | /* Special handling for OS X ACLs */ | |
258 | ||
259 | #define SMB_ACL_TAG_T acl_tag_t | |
260 | #define SMB_ACL_TYPE_T acl_type_t | |
261 | ||
262 | #define SMB_ACL_T acl_t | |
263 | ||
264 | #define SMB_ACL_ENTRY_T acl_entry_t | |
265 | ||
266 | #define SMB_ACL_USER 1 | |
267 | #define SMB_ACL_GROUP 2 | |
268 | ||
269 | #define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
270 | #define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
271 | ||
272 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_EXTENDED | |
273 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
274 | ||
b0ca7d25 | 275 | #define SMB_ACL_VALID_NAME_BITS ((1<<25)-1) |
d417c516 WD |
276 | #define SMB_ACL_VALID_OBJ_BITS 0 |
277 | ||
278 | /*#undef SMB_ACL_NEED_SORT*/ | |
279 | ||
280 | #else /*---------------------------------------------------------------------*/ | |
1c702303 | 281 | |
043ef55b | 282 | /* Unknown platform. */ |
1c702303 | 283 | |
043ef55b | 284 | #error Cannot handle ACLs on this platform! |
1c702303 | 285 | |
043ef55b | 286 | #endif |
1c702303 | 287 | |
1c3344a1 WD |
288 | int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); |
289 | int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); | |
d417c516 | 290 | int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *bits_p, id_t *u_g_id_p); |
1c3344a1 WD |
291 | SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); |
292 | SMB_ACL_T sys_acl_get_fd(int fd); | |
1c3344a1 WD |
293 | SMB_ACL_T sys_acl_init(int count); |
294 | int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); | |
d417c516 | 295 | int sys_acl_set_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype, uint32 bits, id_t u_g_id); |
043ef55b | 296 | int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits); |
1c3344a1 WD |
297 | int sys_acl_valid(SMB_ACL_T theacl); |
298 | int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); | |
299 | int sys_acl_set_fd(int fd, SMB_ACL_T theacl); | |
300 | int sys_acl_delete_def_file(const char *name); | |
1c3344a1 | 301 | int sys_acl_free_acl(SMB_ACL_T the_acl); |
d4a013ed | 302 | int no_acl_syscall_error(int err); |
1c3344a1 WD |
303 | |
304 | #endif /* SUPPORT_ACLS */ |