Commit | Line | Data |
---|---|---|
1c702303 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 | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 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, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | */ | |
21 | ||
1c3344a1 WD |
22 | #ifdef SUPPORT_ACLS |
23 | ||
24 | #ifdef HAVE_SYS_ACL_H | |
25 | #include <sys/acl.h> | |
26 | #endif | |
27 | #ifdef HAVE_ACL_LIBACL_H | |
28 | #include <acl/libacl.h> | |
29 | #endif | |
1c3344a1 WD |
30 | |
31 | #define SMB_MALLOC(cnt) new_array(char, cnt) | |
32 | #define SMB_MALLOC_P(obj) new_array(obj, 1) | |
33 | #define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt) | |
34 | #define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt) | |
35 | #define slprintf snprintf | |
36 | ||
1c702303 WD |
37 | #if defined HAVE_POSIX_ACLS |
38 | ||
39 | /* This is an identity mapping (just remove the SMB_). */ | |
40 | ||
41 | #define SMB_ACL_TAG_T acl_tag_t | |
42 | #define SMB_ACL_TYPE_T acl_type_t | |
43 | #define SMB_ACL_PERMSET_T acl_permset_t | |
44 | #define SMB_ACL_PERM_T acl_perm_t | |
45 | #define SMB_ACL_READ ACL_READ | |
46 | #define SMB_ACL_WRITE ACL_WRITE | |
47 | #define SMB_ACL_EXECUTE ACL_EXECUTE | |
48 | ||
49 | /* Types of ACLs. */ | |
50 | #define SMB_ACL_USER ACL_USER | |
51 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
52 | #define SMB_ACL_GROUP ACL_GROUP | |
53 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
54 | #define SMB_ACL_OTHER ACL_OTHER | |
55 | #define SMB_ACL_MASK ACL_MASK | |
56 | ||
57 | #define SMB_ACL_T acl_t | |
58 | ||
59 | #define SMB_ACL_ENTRY_T acl_entry_t | |
60 | ||
61 | #define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
62 | #define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
63 | ||
64 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
65 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
66 | ||
67 | #elif defined HAVE_TRU64_ACLS | |
68 | ||
69 | /* This is for DEC/Compaq Tru64 UNIX */ | |
70 | ||
71 | #define SMB_ACL_TAG_T acl_tag_t | |
72 | #define SMB_ACL_TYPE_T acl_type_t | |
73 | #define SMB_ACL_PERMSET_T acl_permset_t | |
74 | #define SMB_ACL_PERM_T acl_perm_t | |
75 | #define SMB_ACL_READ ACL_READ | |
76 | #define SMB_ACL_WRITE ACL_WRITE | |
77 | #define SMB_ACL_EXECUTE ACL_EXECUTE | |
78 | ||
79 | /* Types of ACLs. */ | |
80 | #define SMB_ACL_USER ACL_USER | |
81 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
82 | #define SMB_ACL_GROUP ACL_GROUP | |
83 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
84 | #define SMB_ACL_OTHER ACL_OTHER | |
85 | #define SMB_ACL_MASK ACL_MASK | |
86 | ||
87 | #define SMB_ACL_T acl_t | |
88 | ||
89 | #define SMB_ACL_ENTRY_T acl_entry_t | |
90 | ||
91 | #define SMB_ACL_FIRST_ENTRY 0 | |
92 | #define SMB_ACL_NEXT_ENTRY 1 | |
93 | ||
94 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
95 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
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 | ||
103 | /* SVR4.2 ES/MP ACLs */ | |
104 | typedef int SMB_ACL_TAG_T; | |
105 | typedef int SMB_ACL_TYPE_T; | |
106 | typedef ushort *SMB_ACL_PERMSET_T; | |
107 | typedef ushort SMB_ACL_PERM_T; | |
108 | #define SMB_ACL_READ 4 | |
109 | #define SMB_ACL_WRITE 2 | |
110 | #define SMB_ACL_EXECUTE 1 | |
111 | ||
112 | /* Types of ACLs. */ | |
113 | #define SMB_ACL_USER USER | |
114 | #define SMB_ACL_USER_OBJ USER_OBJ | |
115 | #define SMB_ACL_GROUP GROUP | |
116 | #define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
117 | #define SMB_ACL_OTHER OTHER_OBJ | |
118 | #define SMB_ACL_MASK CLASS_OBJ | |
119 | ||
120 | typedef struct SMB_ACL_T { | |
121 | int size; | |
122 | int count; | |
123 | int next; | |
124 | struct acl acl[1]; | |
125 | } *SMB_ACL_T; | |
126 | ||
127 | typedef struct acl *SMB_ACL_ENTRY_T; | |
128 | ||
129 | #define SMB_ACL_FIRST_ENTRY 0 | |
130 | #define SMB_ACL_NEXT_ENTRY 1 | |
131 | ||
132 | #define SMB_ACL_TYPE_ACCESS 0 | |
133 | #define SMB_ACL_TYPE_DEFAULT 1 | |
134 | ||
135 | #ifdef __CYGWIN__ | |
136 | #define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
137 | #endif | |
138 | ||
139 | #elif defined HAVE_HPUX_ACLS | |
140 | ||
141 | /* | |
142 | * Based on the Solaris & UnixWare code. | |
143 | */ | |
144 | ||
145 | #undef GROUP | |
146 | #include <sys/aclv.h> | |
147 | ||
148 | /* SVR4.2 ES/MP ACLs */ | |
149 | typedef int SMB_ACL_TAG_T; | |
150 | typedef int SMB_ACL_TYPE_T; | |
151 | typedef ushort *SMB_ACL_PERMSET_T; | |
152 | typedef ushort SMB_ACL_PERM_T; | |
153 | #define SMB_ACL_READ 4 | |
154 | #define SMB_ACL_WRITE 2 | |
155 | #define SMB_ACL_EXECUTE 1 | |
156 | ||
157 | /* Types of ACLs. */ | |
158 | #define SMB_ACL_USER USER | |
159 | #define SMB_ACL_USER_OBJ USER_OBJ | |
160 | #define SMB_ACL_GROUP GROUP | |
161 | #define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
162 | #define SMB_ACL_OTHER OTHER_OBJ | |
163 | #define SMB_ACL_MASK CLASS_OBJ | |
164 | ||
165 | typedef struct SMB_ACL_T { | |
166 | int size; | |
167 | int count; | |
168 | int next; | |
169 | struct acl acl[1]; | |
170 | } *SMB_ACL_T; | |
171 | ||
172 | typedef struct acl *SMB_ACL_ENTRY_T; | |
173 | ||
174 | #define SMB_ACL_FIRST_ENTRY 0 | |
175 | #define SMB_ACL_NEXT_ENTRY 1 | |
176 | ||
177 | #define SMB_ACL_TYPE_ACCESS 0 | |
178 | #define SMB_ACL_TYPE_DEFAULT 1 | |
179 | ||
180 | #elif defined HAVE_IRIX_ACLS | |
181 | ||
182 | #define SMB_ACL_TAG_T acl_tag_t | |
183 | #define SMB_ACL_TYPE_T acl_type_t | |
184 | #define SMB_ACL_PERMSET_T acl_permset_t | |
185 | #define SMB_ACL_PERM_T acl_perm_t | |
186 | #define SMB_ACL_READ ACL_READ | |
187 | #define SMB_ACL_WRITE ACL_WRITE | |
188 | #define SMB_ACL_EXECUTE ACL_EXECUTE | |
189 | ||
190 | /* Types of ACLs. */ | |
191 | #define SMB_ACL_USER ACL_USER | |
192 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
193 | #define SMB_ACL_GROUP ACL_GROUP | |
194 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
195 | #define SMB_ACL_OTHER ACL_OTHER_OBJ | |
196 | #define SMB_ACL_MASK ACL_MASK | |
197 | ||
198 | typedef struct SMB_ACL_T { | |
199 | int next; | |
200 | BOOL freeaclp; | |
201 | struct acl *aclp; | |
202 | } *SMB_ACL_T; | |
203 | ||
204 | #define SMB_ACL_ENTRY_T acl_entry_t | |
205 | ||
206 | #define SMB_ACL_FIRST_ENTRY 0 | |
207 | #define SMB_ACL_NEXT_ENTRY 1 | |
208 | ||
209 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
210 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
211 | ||
212 | #elif defined HAVE_AIX_ACLS | |
213 | ||
214 | /* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
215 | ||
216 | #include "/usr/include/acl.h" | |
217 | ||
218 | typedef uint *SMB_ACL_PERMSET_T; | |
219 | ||
220 | struct acl_entry_link{ | |
221 | struct acl_entry_link *prevp; | |
222 | struct new_acl_entry *entryp; | |
223 | struct acl_entry_link *nextp; | |
224 | int count; | |
225 | }; | |
226 | ||
227 | struct new_acl_entry{ | |
228 | unsigned short ace_len; | |
229 | unsigned short ace_type; | |
230 | unsigned int ace_access; | |
231 | struct ace_id ace_id[1]; | |
232 | }; | |
233 | ||
234 | #define SMB_ACL_ENTRY_T struct new_acl_entry* | |
235 | #define SMB_ACL_T struct acl_entry_link* | |
236 | ||
237 | #define SMB_ACL_TAG_T unsigned short | |
238 | #define SMB_ACL_TYPE_T int | |
239 | #define SMB_ACL_PERM_T uint | |
240 | #define SMB_ACL_READ S_IRUSR | |
241 | #define SMB_ACL_WRITE S_IWUSR | |
242 | #define SMB_ACL_EXECUTE S_IXUSR | |
243 | ||
244 | /* Types of ACLs. */ | |
245 | #define SMB_ACL_USER ACEID_USER | |
246 | #define SMB_ACL_USER_OBJ 3 | |
247 | #define SMB_ACL_GROUP ACEID_GROUP | |
248 | #define SMB_ACL_GROUP_OBJ 4 | |
249 | #define SMB_ACL_OTHER 5 | |
250 | #define SMB_ACL_MASK 6 | |
251 | ||
252 | ||
253 | #define SMB_ACL_FIRST_ENTRY 1 | |
254 | #define SMB_ACL_NEXT_ENTRY 2 | |
255 | ||
256 | #define SMB_ACL_TYPE_ACCESS 0 | |
257 | #define SMB_ACL_TYPE_DEFAULT 1 | |
258 | ||
259 | #else /* No ACLs. */ | |
260 | ||
261 | /* No ACLS - fake it. */ | |
262 | #define SMB_ACL_TAG_T int | |
263 | #define SMB_ACL_TYPE_T int | |
264 | #define SMB_ACL_PERMSET_T mode_t | |
265 | #define SMB_ACL_PERM_T mode_t | |
266 | #define SMB_ACL_READ S_IRUSR | |
267 | #define SMB_ACL_WRITE S_IWUSR | |
268 | #define SMB_ACL_EXECUTE S_IXUSR | |
269 | ||
270 | /* Types of ACLs. */ | |
271 | #define SMB_ACL_USER 0 | |
272 | #define SMB_ACL_USER_OBJ 1 | |
273 | #define SMB_ACL_GROUP 2 | |
274 | #define SMB_ACL_GROUP_OBJ 3 | |
275 | #define SMB_ACL_OTHER 4 | |
276 | #define SMB_ACL_MASK 5 | |
277 | ||
278 | typedef struct SMB_ACL_T { | |
279 | int dummy; | |
280 | } *SMB_ACL_T; | |
281 | ||
282 | typedef struct SMB_ACL_ENTRY_T { | |
283 | int dummy; | |
284 | } *SMB_ACL_ENTRY_T; | |
285 | ||
286 | #define SMB_ACL_FIRST_ENTRY 0 | |
287 | #define SMB_ACL_NEXT_ENTRY 1 | |
288 | ||
289 | #define SMB_ACL_TYPE_ACCESS 0 | |
290 | #define SMB_ACL_TYPE_DEFAULT 1 | |
291 | ||
292 | #endif /* No ACLs. */ | |
293 | ||
1c3344a1 WD |
294 | int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); |
295 | int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); | |
296 | int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); | |
297 | void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); | |
298 | SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); | |
299 | SMB_ACL_T sys_acl_get_fd(int fd); | |
300 | int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
301 | int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
302 | int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
303 | char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen); | |
304 | SMB_ACL_T sys_acl_init(int count); | |
305 | int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); | |
306 | int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); | |
307 | int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual); | |
308 | int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset); | |
309 | int sys_acl_valid(SMB_ACL_T theacl); | |
310 | int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); | |
311 | int sys_acl_set_fd(int fd, SMB_ACL_T theacl); | |
312 | int sys_acl_delete_def_file(const char *name); | |
313 | int sys_acl_free_text(char *text); | |
314 | int sys_acl_free_acl(SMB_ACL_T the_acl); | |
315 | int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); | |
d4a013ed | 316 | int no_acl_syscall_error(int err); |
1c3344a1 WD |
317 | |
318 | #endif /* SUPPORT_ACLS */ |