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 | |
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 | */ | |
1c702303 | 19 | |
1c3344a1 WD |
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 | |
1c3344a1 WD |
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 | ||
1c702303 WD |
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 | |
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 | ||
1c702303 WD |
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 | |
1c702303 WD |
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 | ||
043ef55b WD |
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 | ||
1c702303 | 97 | #elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS |
043ef55b WD |
98 | |
99 | /* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
100 | * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */ | |
1c702303 WD |
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; | |
1c702303 WD |
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 | ||
043ef55b WD |
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 | ||
1c702303 WD |
135 | #ifdef __CYGWIN__ |
136 | #define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
137 | #endif | |
138 | ||
139 | #elif defined HAVE_HPUX_ACLS | |
140 | ||
043ef55b | 141 | /* Based on the Solaris & UnixWare code. */ |
1c702303 WD |
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; | |
1c702303 WD |
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 | ||
043ef55b WD |
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 | ||
1c702303 WD |
179 | #elif defined HAVE_IRIX_ACLS |
180 | ||
043ef55b WD |
181 | /* IRIX ACLs */ |
182 | ||
1c702303 WD |
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 | |
1c702303 WD |
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 | ||
043ef55b WD |
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 | ||
1c702303 WD |
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 | |
1c702303 WD |
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 | ||
043ef55b WD |
257 | #define SMB_ACL_VALID_NAME_BITS (4 | 2 | 1) |
258 | #define SMB_ACL_VALID_OBJ_BITS (4 | 2 | 1) | |
1c702303 | 259 | |
043ef55b | 260 | #define SMB_ACL_NEED_SORT |
1c702303 | 261 | |
043ef55b | 262 | #else |
1c702303 | 263 | |
043ef55b | 264 | /* Unknown platform. */ |
1c702303 | 265 | |
043ef55b | 266 | #error Cannot handle ACLs on this platform! |
1c702303 | 267 | |
043ef55b | 268 | #endif |
1c702303 | 269 | |
1c3344a1 WD |
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); | |
043ef55b | 272 | int sys_acl_get_access_bits(SMB_ACL_ENTRY_T entry_d, uint32 *bits); |
1c3344a1 WD |
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); | |
1c3344a1 WD |
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); | |
043ef55b | 280 | int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits); |
1c3344a1 WD |
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); | |
1c3344a1 WD |
285 | int sys_acl_free_acl(SMB_ACL_T the_acl); |
286 | int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); | |
d4a013ed | 287 | int no_acl_syscall_error(int err); |
1c3344a1 WD |
288 | |
289 | #endif /* SUPPORT_ACLS */ |