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