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 | ||
1c702303 WD |
36 | #if defined HAVE_POSIX_ACLS |
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 | |
42 | #define SMB_ACL_PERMSET_T acl_permset_t | |
1c702303 WD |
43 | |
44 | /* Types of ACLs. */ | |
45 | #define SMB_ACL_USER ACL_USER | |
46 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
47 | #define SMB_ACL_GROUP ACL_GROUP | |
48 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
49 | #define SMB_ACL_OTHER ACL_OTHER | |
50 | #define SMB_ACL_MASK ACL_MASK | |
51 | ||
52 | #define SMB_ACL_T acl_t | |
53 | ||
54 | #define SMB_ACL_ENTRY_T acl_entry_t | |
55 | ||
56 | #define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
57 | #define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
58 | ||
59 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
60 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
61 | ||
043ef55b WD |
62 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
63 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
64 | ||
65 | #define SMB_ACL_NEED_SORT | |
66 | ||
1c702303 WD |
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 | |
1c702303 WD |
74 | |
75 | /* Types of ACLs. */ | |
76 | #define SMB_ACL_USER ACL_USER | |
77 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
78 | #define SMB_ACL_GROUP ACL_GROUP | |
79 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
80 | #define SMB_ACL_OTHER ACL_OTHER | |
81 | #define SMB_ACL_MASK ACL_MASK | |
82 | ||
83 | #define SMB_ACL_T acl_t | |
84 | ||
85 | #define SMB_ACL_ENTRY_T acl_entry_t | |
86 | ||
87 | #define SMB_ACL_FIRST_ENTRY 0 | |
88 | #define SMB_ACL_NEXT_ENTRY 1 | |
89 | ||
90 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
91 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
92 | ||
043ef55b WD |
93 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
94 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
95 | ||
96 | #define SMB_ACL_NEED_SORT | |
97 | ||
1c702303 | 98 | #elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS |
043ef55b WD |
99 | |
100 | /* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
101 | * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */ | |
1c702303 WD |
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; | |
1c702303 WD |
107 | |
108 | /* Types of ACLs. */ | |
109 | #define SMB_ACL_USER USER | |
110 | #define SMB_ACL_USER_OBJ USER_OBJ | |
111 | #define SMB_ACL_GROUP GROUP | |
112 | #define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
113 | #define SMB_ACL_OTHER OTHER_OBJ | |
114 | #define SMB_ACL_MASK CLASS_OBJ | |
115 | ||
116 | typedef struct SMB_ACL_T { | |
117 | int size; | |
118 | int count; | |
119 | int next; | |
120 | struct acl acl[1]; | |
121 | } *SMB_ACL_T; | |
122 | ||
123 | typedef struct acl *SMB_ACL_ENTRY_T; | |
124 | ||
125 | #define SMB_ACL_FIRST_ENTRY 0 | |
126 | #define SMB_ACL_NEXT_ENTRY 1 | |
127 | ||
128 | #define SMB_ACL_TYPE_ACCESS 0 | |
129 | #define SMB_ACL_TYPE_DEFAULT 1 | |
130 | ||
043ef55b WD |
131 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
132 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
133 | ||
134 | #define SMB_ACL_NEED_SORT | |
135 | ||
1c702303 WD |
136 | #ifdef __CYGWIN__ |
137 | #define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
138 | #endif | |
139 | ||
140 | #elif defined HAVE_HPUX_ACLS | |
141 | ||
043ef55b | 142 | /* Based on the Solaris & UnixWare code. */ |
1c702303 WD |
143 | |
144 | #undef GROUP | |
145 | #include <sys/aclv.h> | |
146 | ||
147 | /* SVR4.2 ES/MP ACLs */ | |
148 | typedef int SMB_ACL_TAG_T; | |
149 | typedef int SMB_ACL_TYPE_T; | |
150 | typedef ushort *SMB_ACL_PERMSET_T; | |
1c702303 WD |
151 | |
152 | /* Types of ACLs. */ | |
153 | #define SMB_ACL_USER USER | |
154 | #define SMB_ACL_USER_OBJ USER_OBJ | |
155 | #define SMB_ACL_GROUP GROUP | |
156 | #define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
157 | #define SMB_ACL_OTHER OTHER_OBJ | |
158 | #define SMB_ACL_MASK CLASS_OBJ | |
159 | ||
160 | typedef struct SMB_ACL_T { | |
161 | int size; | |
162 | int count; | |
163 | int next; | |
164 | struct acl acl[1]; | |
165 | } *SMB_ACL_T; | |
166 | ||
167 | typedef struct acl *SMB_ACL_ENTRY_T; | |
168 | ||
169 | #define SMB_ACL_FIRST_ENTRY 0 | |
170 | #define SMB_ACL_NEXT_ENTRY 1 | |
171 | ||
172 | #define SMB_ACL_TYPE_ACCESS 0 | |
173 | #define SMB_ACL_TYPE_DEFAULT 1 | |
174 | ||
043ef55b WD |
175 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
176 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
177 | ||
178 | #define SMB_ACL_NEED_SORT | |
179 | ||
1c702303 WD |
180 | #elif defined HAVE_IRIX_ACLS |
181 | ||
043ef55b WD |
182 | /* IRIX ACLs */ |
183 | ||
1c702303 WD |
184 | #define SMB_ACL_TAG_T acl_tag_t |
185 | #define SMB_ACL_TYPE_T acl_type_t | |
186 | #define SMB_ACL_PERMSET_T acl_permset_t | |
1c702303 WD |
187 | |
188 | /* Types of ACLs. */ | |
189 | #define SMB_ACL_USER ACL_USER | |
190 | #define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
191 | #define SMB_ACL_GROUP ACL_GROUP | |
192 | #define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
193 | #define SMB_ACL_OTHER ACL_OTHER_OBJ | |
194 | #define SMB_ACL_MASK ACL_MASK | |
195 | ||
196 | typedef struct SMB_ACL_T { | |
197 | int next; | |
198 | BOOL freeaclp; | |
199 | struct acl *aclp; | |
200 | } *SMB_ACL_T; | |
201 | ||
202 | #define SMB_ACL_ENTRY_T acl_entry_t | |
203 | ||
204 | #define SMB_ACL_FIRST_ENTRY 0 | |
205 | #define SMB_ACL_NEXT_ENTRY 1 | |
206 | ||
207 | #define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
208 | #define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
209 | ||
043ef55b WD |
210 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
211 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
212 | ||
213 | #define SMB_ACL_NEED_SORT | |
214 | ||
1c702303 WD |
215 | #elif defined HAVE_AIX_ACLS |
216 | ||
217 | /* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
218 | ||
219 | #include "/usr/include/acl.h" | |
220 | ||
221 | typedef uint *SMB_ACL_PERMSET_T; | |
222 | ||
223 | struct acl_entry_link{ | |
224 | struct acl_entry_link *prevp; | |
225 | struct new_acl_entry *entryp; | |
226 | struct acl_entry_link *nextp; | |
227 | int count; | |
228 | }; | |
229 | ||
230 | struct new_acl_entry{ | |
231 | unsigned short ace_len; | |
232 | unsigned short ace_type; | |
233 | unsigned int ace_access; | |
234 | struct ace_id ace_id[1]; | |
235 | }; | |
236 | ||
237 | #define SMB_ACL_ENTRY_T struct new_acl_entry* | |
238 | #define SMB_ACL_T struct acl_entry_link* | |
239 | ||
240 | #define SMB_ACL_TAG_T unsigned short | |
241 | #define SMB_ACL_TYPE_T int | |
1c702303 WD |
242 | |
243 | /* Types of ACLs. */ | |
244 | #define SMB_ACL_USER ACEID_USER | |
245 | #define SMB_ACL_USER_OBJ 3 | |
246 | #define SMB_ACL_GROUP ACEID_GROUP | |
247 | #define SMB_ACL_GROUP_OBJ 4 | |
248 | #define SMB_ACL_OTHER 5 | |
249 | #define SMB_ACL_MASK 6 | |
250 | ||
251 | ||
252 | #define SMB_ACL_FIRST_ENTRY 1 | |
253 | #define SMB_ACL_NEXT_ENTRY 2 | |
254 | ||
255 | #define SMB_ACL_TYPE_ACCESS 0 | |
256 | #define SMB_ACL_TYPE_DEFAULT 1 | |
257 | ||
043ef55b WD |
258 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
259 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
1c702303 | 260 | |
043ef55b | 261 | #define SMB_ACL_NEED_SORT |
1c702303 | 262 | |
043ef55b | 263 | #else |
1c702303 | 264 | |
043ef55b | 265 | /* Unknown platform. */ |
1c702303 | 266 | |
043ef55b | 267 | #error Cannot handle ACLs on this platform! |
1c702303 | 268 | |
043ef55b | 269 | #endif |
1c702303 | 270 | |
1c3344a1 WD |
271 | int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); |
272 | int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); | |
043ef55b | 273 | int sys_acl_get_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 *bits); |
1c3344a1 WD |
274 | void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); |
275 | SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); | |
276 | SMB_ACL_T sys_acl_get_fd(int fd); | |
1c3344a1 WD |
277 | SMB_ACL_T sys_acl_init(int count); |
278 | int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); | |
279 | int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); | |
280 | int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual); | |
043ef55b | 281 | int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits); |
1c3344a1 WD |
282 | int sys_acl_valid(SMB_ACL_T theacl); |
283 | int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); | |
284 | int sys_acl_set_fd(int fd, SMB_ACL_T theacl); | |
285 | int sys_acl_delete_def_file(const char *name); | |
1c3344a1 WD |
286 | int sys_acl_free_acl(SMB_ACL_T the_acl); |
287 | int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); | |
d4a013ed | 288 | int no_acl_syscall_error(int err); |
1c3344a1 WD |
289 | |
290 | #endif /* SUPPORT_ACLS */ |