Commit | Line | Data |
---|---|---|
fa26e11c WD |
1 | After applying this patch, run these commands for a successful build: |
2 | ||
3 | autoconf | |
a30f8abd | 4 | autoheader |
fa26e11c WD |
5 | ./configure --with-acl-support |
6 | make proto | |
7 | make | |
8 | ||
f05cc718 WD |
9 | The program currently complains when the --acls (-A) option is used to copy |
10 | from a disk that doesn't support ACLs. This should be changed to silently | |
11 | notice that no ACLs are available to copy. Of course, trying to write out | |
12 | ACLs to a non-ACL-supporting disk should complain. | |
fa26e11c | 13 | |
35a9a417 | 14 | --- orig/Makefile.in 2004-10-08 20:16:26 |
13bed3dd | 15 | +++ Makefile.in 2004-07-03 20:11:58 |
fa26e11c WD |
16 | @@ -25,7 +25,7 @@ VERSION=@VERSION@ |
17 | .SUFFIXES: | |
18 | .SUFFIXES: .c .o | |
19 | ||
20 | -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h | |
21 | +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h | |
22 | LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \ | |
23 | lib/permstring.o lib/pool_alloc.o @LIBOBJS@ | |
24 | ZLIBOBJ=zlib/deflate.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o \ | |
25 | @@ -34,7 +34,7 @@ ZLIBOBJ=zlib/deflate.o zlib/infblock.o z | |
26 | OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \ | |
27 | main.o checksum.o match.o syscall.o log.o backup.o | |
28 | OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \ | |
29 | - fileio.o batch.o clientname.o | |
30 | + fileio.o batch.o clientname.o sysacls.o acls.o | |
31 | OBJS3=progress.o pipe.o | |
32 | DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o | |
33 | popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \ | |
1ce58df1 WD |
34 | --- orig/acls.c 2004-09-08 06:09:30 |
35 | +++ acls.c 2004-09-08 06:09:30 | |
36 | @@ -0,0 +1,1144 @@ | |
fa26e11c WD |
37 | +/* -*- c-file-style: "linux" -*- |
38 | + Copyright (C) Andrew Tridgell 1996 | |
39 | + Copyright (C) Paul Mackerras 1996 | |
40 | + | |
41 | + This program is free software; you can redistribute it and/or modify | |
42 | + it under the terms of the GNU General Public License as published by | |
43 | + the Free Software Foundation; either version 2 of the License, or | |
44 | + (at your option) any later version. | |
45 | + | |
46 | + This program is distributed in the hope that it will be useful, | |
47 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
48 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
49 | + GNU General Public License for more details. | |
50 | + | |
51 | + You should have received a copy of the GNU General Public License | |
52 | + along with this program; if not, write to the Free Software | |
53 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
54 | +*/ | |
55 | + | |
56 | +/* handle passing ACLs between systems */ | |
57 | + | |
58 | +#include "rsync.h" | |
59 | + | |
3559aee3 | 60 | +#if SUPPORT_ACLS |
fa26e11c WD |
61 | + |
62 | +extern int preserve_acls; | |
63 | +extern int am_root; | |
64 | +extern int dry_run; | |
65 | + | |
66 | +typedef struct { | |
67 | + id_t id; | |
68 | + uchar access; | |
69 | + SMB_ACL_TAG_T tag_type; | |
70 | +} rsync_ace; | |
71 | + | |
72 | +typedef struct { | |
73 | + size_t count; | |
74 | + size_t malloced; | |
75 | + rsync_ace *races; | |
76 | +} rsync_acl; | |
77 | + | |
78 | +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL }; | |
79 | + | |
80 | +static void expand_rsync_acl(rsync_acl *racl) | |
81 | +{ | |
82 | + /* first time through, 0 <= 0, so list is expanded: | |
83 | + * diabolical, rsync guys! */ | |
84 | + if (racl->malloced <= racl->count) { | |
85 | + void *new_ptr; | |
86 | + size_t new_size; | |
87 | + racl->malloced += 10; | |
88 | + new_size = racl->malloced * sizeof racl->races[0]; | |
89 | + if (racl->races) | |
90 | + new_ptr = realloc(racl->races, new_size); | |
91 | + else | |
92 | + new_ptr = malloc(new_size); | |
93 | + if (verbose >= 4) { | |
94 | + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n", | |
95 | + (double) new_size, | |
96 | + racl->races ? "" : " not"); | |
97 | + } | |
98 | + | |
99 | + racl->races = (rsync_ace *) new_ptr; | |
100 | + | |
101 | + if (!racl->races) | |
102 | + out_of_memory("expand_rsync_acl"); | |
103 | + } | |
104 | +} | |
105 | + | |
106 | +static void rsync_acl_free(rsync_acl *racl) | |
107 | +{ | |
108 | + free(racl->races); | |
109 | + racl->races = NULL; | |
110 | + racl->count = 0; | |
111 | + racl->malloced = 0; | |
112 | +} | |
113 | + | |
114 | +static int rsync_ace_sorter(const void *r1, const void *r2) | |
115 | +{ | |
116 | + rsync_ace *race1 = (rsync_ace *)r1; | |
117 | + SMB_ACL_TAG_T rtag1 = race1->tag_type; | |
118 | + id_t rid1 = race1->id; | |
119 | + rsync_ace *race2 = (rsync_ace *)r2; | |
120 | + SMB_ACL_TAG_T rtag2 = race2->tag_type; | |
121 | + id_t rid2 = race2->id; | |
122 | + /* start at the extrema */ | |
123 | + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK) | |
124 | + return -1; | |
125 | + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK) | |
126 | + return 1; | |
127 | + /* work inwards */ | |
128 | + if (rtag1 == SMB_ACL_OTHER) | |
129 | + return 1; | |
130 | + if (rtag2 == SMB_ACL_OTHER) | |
131 | + return -1; | |
132 | + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */ | |
133 | + if (rtag1 == SMB_ACL_USER) { | |
134 | + switch (rtag2) { | |
135 | + case SMB_ACL_GROUP: | |
136 | + case SMB_ACL_GROUP_OBJ: | |
137 | + case SMB_ACL_OTHER: | |
138 | + return -1; | |
139 | + } | |
140 | + /* both USER */ | |
141 | + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1; | |
142 | + } | |
143 | + if (rtag2 == SMB_ACL_USER) | |
144 | + return 1; | |
145 | + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */ | |
146 | + if (rtag1 == SMB_ACL_GROUP_OBJ) | |
147 | + return -1; | |
148 | + if (rtag2 == SMB_ACL_GROUP_OBJ) | |
149 | + return 1; | |
150 | + /* only SMB_ACL_GROUPs left */ | |
151 | + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1; | |
152 | +} | |
153 | + | |
154 | +static void sort_rsync_acl(rsync_acl *racl) | |
155 | +{ | |
156 | + if (!racl->count) | |
157 | + return; | |
158 | + qsort((void **)racl->races, racl->count, sizeof racl->races[0], | |
159 | + &rsync_ace_sorter); | |
160 | +} | |
161 | + | |
162 | +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl) | |
163 | +{ | |
164 | + SMB_ACL_ENTRY_T entry; | |
165 | + int rc; | |
166 | + const char *errfun; | |
167 | + *racl = rsync_acl_initializer; | |
168 | + errfun = "sys_acl_get_entry"; | |
169 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); | |
170 | + rc == 1; | |
171 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { | |
172 | + SMB_ACL_PERMSET_T permset; | |
173 | + void *qualifier; | |
174 | + rsync_ace *race; | |
175 | + expand_rsync_acl(racl); | |
176 | + race = &racl->races[racl->count++]; | |
177 | + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) { | |
178 | + errfun = "sys_acl_get_tag_type"; | |
179 | + break; | |
180 | + } | |
181 | + if ((rc = sys_acl_get_permset(entry, &permset))) { | |
182 | + errfun = "sys_acl_get_tag_type"; | |
183 | + break; | |
184 | + } | |
185 | + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0) | |
186 | + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0) | |
187 | + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0); | |
188 | + switch (race->tag_type) { | |
189 | + case SMB_ACL_USER: | |
190 | + case SMB_ACL_GROUP: | |
191 | + break; | |
192 | + default: | |
193 | + continue; | |
194 | + } | |
195 | + if (!(qualifier = sys_acl_get_qualifier(entry))) { | |
196 | + errfun = "sys_acl_get_tag_type"; | |
197 | + rc = EINVAL; | |
198 | + break; | |
199 | + } | |
200 | + race->id = *((id_t *)qualifier); | |
201 | + sys_acl_free_qualifier(qualifier, race->tag_type); | |
202 | + } | |
203 | + if (rc) { | |
204 | + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n", | |
205 | + errfun, strerror(errno)); | |
206 | + rsync_acl_free(racl); | |
207 | + return False; | |
208 | + } | |
209 | + sort_rsync_acl(racl); | |
210 | + return True; | |
211 | +} | |
212 | + | |
213 | +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2) | |
214 | +{ | |
215 | + rsync_ace *race1, *race2; | |
216 | + size_t count = racl1->count; | |
217 | + if (count != racl2->count) | |
218 | + return False; | |
219 | + race1 = racl1->races; | |
220 | + race2 = racl2->races; | |
221 | + for (; count--; race1++, race2++) { | |
222 | + if (race1->tag_type != race2->tag_type | |
223 | + || race1->access != race2->access | |
224 | + || ((race1->tag_type == SMB_ACL_USER | |
225 | + || race1->tag_type == SMB_ACL_GROUP) | |
226 | + && race1->id != race2->id)) | |
227 | + return False; | |
228 | + } | |
229 | + return True; | |
230 | +} | |
231 | + | |
232 | +typedef struct { | |
233 | + size_t count; | |
234 | + size_t malloced; | |
235 | + rsync_acl *racls; | |
236 | +} rsync_acl_list; | |
237 | + | |
238 | +static rsync_acl_list _rsync_acl_lists[] = { | |
239 | + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */ | |
240 | + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */ | |
241 | +}; | |
242 | + | |
243 | +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type) | |
244 | +{ | |
245 | + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0] | |
246 | + : &_rsync_acl_lists[1]; | |
247 | +} | |
248 | + | |
249 | +static void expand_rsync_acl_list(rsync_acl_list *racl_list) | |
250 | +{ | |
251 | + /* first time through, 0 <= 0, so list is expanded: | |
252 | + * diabolical, rsync guys! */ | |
253 | + if (racl_list->malloced <= racl_list->count) { | |
254 | + void *new_ptr; | |
255 | + size_t new_size; | |
256 | + if (racl_list->malloced < 1000) | |
257 | + racl_list->malloced += 1000; | |
258 | + else | |
259 | + racl_list->malloced *= 2; | |
260 | + new_size = racl_list->malloced * sizeof racl_list->racls[0]; | |
261 | + if (racl_list->racls) | |
262 | + new_ptr = realloc(racl_list->racls, new_size); | |
263 | + else | |
264 | + new_ptr = malloc(new_size); | |
265 | + if (verbose >= 3) { | |
266 | + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n", | |
267 | + (double) new_size, | |
268 | + racl_list->racls ? "" : " not"); | |
269 | + } | |
270 | + | |
271 | + racl_list->racls = (rsync_acl *) new_ptr; | |
272 | + | |
273 | + if (!racl_list->racls) | |
274 | + out_of_memory("expand_rsync_acl_list"); | |
275 | + } | |
276 | +} | |
277 | + | |
278 | +#if 0 | |
279 | +static void free_rsync_acl_list(rsync_acl_list *racl_list) | |
280 | +{ | |
281 | + /* run this in reverse, so references are freed before referents, */ | |
282 | + /* although not currently necessary */ | |
283 | + while (racl_list->count--) { | |
284 | + rsync_acl *racl = &racl_list->racls[racl_list->count]; | |
285 | + if (racl) | |
286 | + rsync_acl_free(racl); | |
287 | + } | |
288 | + free(racl_list->racls); | |
289 | + racl_list->racls = NULL; | |
290 | + racl_list->malloced = 0; | |
291 | +} | |
292 | +#endif | |
293 | + | |
294 | +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type, | |
295 | + const rsync_acl_list *racl_list, | |
296 | + const rsync_acl *racl) | |
297 | +{ | |
298 | + static int access_match = -1, default_match = -1; | |
299 | + int *match = (type == SMB_ACL_TYPE_ACCESS) ? | |
300 | + &access_match : &default_match; | |
301 | + size_t count = racl_list->count; | |
302 | + /* if this is the first time through or we didn't match the last | |
303 | + * time, then start at the end of the list, which should be the | |
304 | + * best place to start hunting */ | |
305 | + if (*match == -1) | |
306 | + *match = racl_list->count - 1; | |
307 | + while (count--) { | |
308 | + if (rsync_acls_equal(&racl_list->racls[*match], racl)) | |
309 | + return *match; | |
310 | + if (!(*match)--) | |
311 | + *match = racl_list->count - 1; | |
312 | + } | |
313 | + *match = -1; | |
314 | + return *match; | |
315 | +} | |
316 | + | |
317 | +/* the general strategy with the tag_type <-> character mapping is that | |
318 | + * lowercase implies that no qualifier follows, where uppercase does. | |
319 | + * same sorta thing for the acl type (access or default) itself, but | |
320 | + * lowercase in this instance means there's no ACL following, so the | |
321 | + * ACL is a repeat, so the receiver should reuse the last of the same | |
322 | + * type ACL */ | |
323 | + | |
324 | +static void send_rsync_acl(int f, const rsync_acl *racl) | |
325 | +{ | |
326 | + rsync_ace *race; | |
327 | + size_t count = racl->count; | |
328 | + write_int(f, count); | |
329 | + for (race = racl->races; count--; race++) { | |
330 | + char ch; | |
331 | + switch (race->tag_type) { | |
332 | + case SMB_ACL_USER_OBJ: | |
333 | + ch = 'u'; | |
334 | + break; | |
335 | + case SMB_ACL_USER: | |
336 | + ch = 'U'; | |
337 | + break; | |
338 | + case SMB_ACL_GROUP_OBJ: | |
339 | + ch = 'g'; | |
340 | + break; | |
341 | + case SMB_ACL_GROUP: | |
342 | + ch = 'G'; | |
343 | + break; | |
344 | + case SMB_ACL_OTHER: | |
345 | + ch = 'o'; | |
346 | + break; | |
347 | + case SMB_ACL_MASK: | |
348 | + ch = 'm'; | |
349 | + break; | |
350 | + default: | |
351 | + rprintf(FERROR, | |
352 | + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n", | |
353 | + race->tag_type); | |
354 | + continue; | |
355 | + } | |
356 | + write_byte(f, ch); | |
357 | + write_byte(f, race->access); | |
358 | + if (isupper((int)ch)) { | |
359 | + write_int(f, race->id); | |
360 | + /* FIXME: sorta wasteful. we should maybe buffer as | |
361 | + * many ids as max(ACL_USER + ACL_GROUP) objects to | |
362 | + * keep from making so many calls */ | |
363 | + if (ch == 'U') | |
364 | + add_uid(race->id); | |
365 | + else | |
366 | + add_gid(race->id); | |
367 | + } | |
368 | + } | |
369 | +} | |
370 | + | |
371 | +static rsync_acl _curr_rsync_acls[2]; | |
372 | + | |
373 | + | |
374 | +static const char *str_acl_type(SMB_ACL_TYPE_T type) | |
375 | +{ | |
376 | + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" : | |
377 | + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" : | |
378 | + "unknown SMB_ACL_TYPE_T"; | |
379 | +} | |
380 | + | |
381 | +/* generate the ACL(s) for this flist entry; | |
382 | + * ACL(s) are either sent or cleaned-up by send_acl() below */ | |
383 | + | |
384 | +BOOL make_acl(const struct file_struct *file, const char *fname) | |
385 | +{ | |
386 | + SMB_ACL_TYPE_T *type, | |
387 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
388 | + rsync_acl *curr_racl; | |
389 | + if (!preserve_acls || S_ISLNK(file->mode)) | |
390 | + return True; | |
391 | + for (type = &types[0], curr_racl = &_curr_rsync_acls[0]; | |
392 | + type < &types[0] + sizeof types / sizeof types[0] | |
393 | + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode)); | |
394 | + type++, curr_racl++) { | |
395 | + SMB_ACL_T sacl; | |
396 | + BOOL ok; | |
397 | + *curr_racl = rsync_acl_initializer; | |
398 | + if (!(sacl = sys_acl_get_file(fname, *type))) { | |
c171f097 | 399 | + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n", |
fa26e11c WD |
400 | + fname, str_acl_type(*type), strerror(errno)); |
401 | + return False; | |
402 | + } | |
403 | + ok = unpack_smb_acl(curr_racl, sacl); | |
404 | + sys_acl_free_acl(sacl); | |
405 | + if (!ok) | |
406 | + return False; | |
407 | + } | |
408 | + return True; | |
409 | +} | |
410 | + | |
411 | +/* send the make_acl()-generated ACLs for this flist entry, | |
412 | + * or clean up after an flist entry that's not being sent (f == -1) */ | |
413 | + | |
414 | +void send_acl(const struct file_struct *file, int f) | |
415 | +{ | |
416 | + SMB_ACL_TYPE_T *type, | |
417 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
418 | + rsync_acl *curr_racl; | |
419 | + if (!preserve_acls || S_ISLNK(file->mode)) | |
420 | + return; | |
421 | + for (type = &types[0], curr_racl = &_curr_rsync_acls[0]; | |
422 | + type < &types[0] + sizeof types / sizeof types[0] | |
423 | + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode)); | |
424 | + type++, curr_racl++) { | |
425 | + int index; | |
426 | + rsync_acl_list *racl_list = rsync_acl_lists(*type); | |
427 | + if (f == -1) { | |
428 | + rsync_acl_free(curr_racl); | |
429 | + continue; | |
430 | + } | |
431 | + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl)) | |
432 | + != -1) { | |
433 | + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd'); | |
434 | + write_int(f, index); | |
435 | + rsync_acl_free(curr_racl); | |
436 | + } else { | |
437 | + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D'); | |
438 | + send_rsync_acl(f, curr_racl); | |
439 | + expand_rsync_acl_list(racl_list); | |
440 | + racl_list->racls[racl_list->count++] = *curr_racl; | |
441 | + } | |
442 | + } | |
443 | +} | |
444 | + | |
445 | +/* the below stuff is only used by the receiver */ | |
446 | + | |
447 | +/* structure to hold index to rsync_acl_list member corresponding to | |
448 | + * flist->files[i] */ | |
449 | + | |
450 | +typedef struct { | |
451 | + const struct file_struct *file; | |
452 | + int aclidx; | |
453 | +} file_acl_index; | |
454 | + | |
455 | +typedef struct { | |
456 | + size_t count; | |
457 | + size_t malloced; | |
458 | + file_acl_index *fileaclidxs; | |
459 | +} file_acl_index_list; | |
460 | + | |
461 | +static file_acl_index_list _file_acl_index_lists[] = { | |
462 | + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */ | |
463 | + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */ | |
464 | +}; | |
465 | + | |
466 | +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type) | |
467 | +{ | |
468 | + return type == SMB_ACL_TYPE_ACCESS ? | |
469 | + &_file_acl_index_lists[0] : &_file_acl_index_lists[1]; | |
470 | +} | |
471 | + | |
472 | +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list) | |
473 | +{ | |
474 | + /* first time through, 0 <= 0, so list is expanded: | |
475 | + * diabolical, rsync guys! */ | |
476 | + if (fileaclidx_list->malloced <= fileaclidx_list->count) { | |
477 | + void *new_ptr; | |
478 | + size_t new_size; | |
479 | + if (fileaclidx_list->malloced < 1000) | |
480 | + fileaclidx_list->malloced += 1000; | |
481 | + else | |
482 | + fileaclidx_list->malloced *= 2; | |
483 | + new_size = fileaclidx_list->malloced | |
484 | + * sizeof fileaclidx_list->fileaclidxs[0]; | |
485 | + if (fileaclidx_list->fileaclidxs) | |
486 | + new_ptr = realloc(fileaclidx_list->fileaclidxs, new_size); | |
487 | + else | |
488 | + new_ptr = malloc(new_size); | |
489 | + if (verbose >= 3) { | |
490 | + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n", | |
491 | + (double) new_size, | |
492 | + fileaclidx_list->fileaclidxs ? "" : " not"); | |
493 | + } | |
494 | + | |
495 | + fileaclidx_list->fileaclidxs = (file_acl_index *) new_ptr; | |
496 | + | |
497 | + if (!fileaclidx_list->fileaclidxs) | |
498 | + out_of_memory("expand_file_acl_index_list"); | |
499 | + } | |
500 | +} | |
501 | + | |
502 | +#if 0 | |
503 | +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list) | |
504 | +{ | |
505 | + free(fileaclidx_list->fileaclidxs); | |
506 | + fileaclidx_list->fileaclidxs = NULL; | |
507 | + fileaclidx_list->malloced = 0; | |
508 | +} | |
509 | +#endif | |
510 | + | |
511 | +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */ | |
512 | + | |
513 | +typedef struct { | |
514 | + size_t count; | |
515 | + size_t malloced; | |
516 | + SMB_ACL_T *sacls; | |
517 | +} smb_acl_list; | |
518 | + | |
519 | +static smb_acl_list _smb_acl_lists[] = { | |
520 | + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */ | |
521 | + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */ | |
522 | +}; | |
523 | + | |
524 | +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type) | |
525 | +{ | |
526 | + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] : | |
527 | + &_smb_acl_lists[1]; | |
528 | +} | |
529 | + | |
530 | +static void expand_smb_acl_list(smb_acl_list *sacl_list) | |
531 | +{ | |
532 | + /* first time through, 0 <= 0, so list is expanded: | |
533 | + * diabolical, rsync guys! */ | |
534 | + if (sacl_list->malloced <= sacl_list->count) { | |
535 | + void *new_ptr; | |
536 | + size_t new_size; | |
537 | + if (sacl_list->malloced < 1000) | |
538 | + sacl_list->malloced += 1000; | |
539 | + else | |
540 | + sacl_list->malloced *= 2; | |
541 | + new_size = sacl_list->malloced | |
542 | + * sizeof sacl_list->sacls[0]; | |
543 | + if (sacl_list->sacls) | |
544 | + new_ptr = realloc(sacl_list->sacls, new_size); | |
545 | + else | |
546 | + new_ptr = malloc(new_size); | |
547 | + if (verbose >= 3) { | |
548 | + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n", | |
549 | + (double) new_size, | |
550 | + sacl_list->sacls ? "" : " not"); | |
551 | + } | |
552 | + | |
553 | + sacl_list->sacls = (SMB_ACL_T *) new_ptr; | |
554 | + | |
555 | + if (!sacl_list->sacls) | |
556 | + out_of_memory("expand_smb_acl_list"); | |
557 | + } | |
558 | +} | |
559 | + | |
560 | +#if 0 | |
561 | +static void free_smb_acl_list(SMB_ACL_TYPE_T type) | |
562 | +{ | |
563 | + smb_acl_list *sacl_list = smb_acl_lists(type); | |
564 | + SMB_ACL_T *sacl = sacl_list->sacls; | |
565 | + while (sacl_list->count--) { | |
566 | + if (*sacl) | |
567 | + sys_acl_free_acl(*sacl++); | |
568 | + } | |
569 | + free(sacl_list->sacls); | |
570 | + sacl_list->sacls = NULL; | |
571 | + sacl_list->malloced = 0; | |
572 | +} | |
573 | +#endif | |
574 | + | |
575 | +/* build an SMB_ACL_T corresponding to an rsync_acl */ | |
576 | +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl) | |
577 | +{ | |
578 | + size_t count = racl->count; | |
579 | + rsync_ace *race = racl->races; | |
580 | + const char *errfun = NULL; | |
581 | + *smb_acl = sys_acl_init(count); | |
582 | + if (!*smb_acl) { | |
583 | + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n", | |
584 | + strerror(errno)); | |
585 | + return False; | |
586 | + } | |
587 | + for (; count--; race++) { | |
588 | + SMB_ACL_ENTRY_T entry; | |
589 | + SMB_ACL_PERMSET_T permset; | |
590 | + if (sys_acl_create_entry(smb_acl, &entry)) { | |
591 | + errfun = "sys_acl_create)"; | |
592 | + break; | |
593 | + } | |
594 | + if (sys_acl_set_tag_type(entry, race->tag_type)) { | |
595 | + errfun = "sys_acl_set_tag"; | |
596 | + break; | |
597 | + } | |
598 | + if (race->tag_type == SMB_ACL_USER || | |
599 | + race->tag_type == SMB_ACL_GROUP) | |
600 | + if (sys_acl_set_qualifier(entry, (void*)&race->id)) { | |
601 | + errfun = "sys_acl_set_qualfier"; | |
602 | + break; | |
603 | + } | |
604 | + if (sys_acl_get_permset(entry, &permset)) { | |
605 | + errfun = "sys_acl_get_permset"; | |
606 | + break; | |
607 | + } | |
608 | + if (sys_acl_clear_perms(permset)) { | |
609 | + errfun = "sys_acl_clear_perms"; | |
610 | + break; | |
611 | + } | |
612 | + if (race->access & 4) | |
613 | + if (sys_acl_add_perm(permset, SMB_ACL_READ)) { | |
614 | + errfun = "sys_acl_add_perm"; | |
615 | + break; | |
616 | + } | |
617 | + if (race->access & 2) | |
618 | + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) { | |
619 | + errfun = "sys_acl_add_perm"; | |
620 | + break; | |
621 | + } | |
622 | + if (race->access & 1) | |
623 | + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) { | |
624 | + errfun = "sys_acl_add_perm"; | |
625 | + break; | |
626 | + } | |
627 | + if (sys_acl_set_permset(entry, permset)) { | |
628 | + errfun = "sys_acl_set_permset"; | |
629 | + break; | |
630 | + } | |
631 | + } | |
632 | + if (errfun) { | |
633 | + sys_acl_free_acl(*smb_acl); | |
634 | + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun, | |
635 | + strerror(errno)); | |
636 | + return False; | |
637 | + } | |
638 | + return True; | |
639 | +} | |
640 | + | |
641 | +static void receive_rsync_acl(rsync_acl *racl, int f) | |
642 | +{ | |
643 | +#if ACLS_NEED_MASK | |
644 | + uchar required_mask_perm = 0; | |
fa26e11c | 645 | +#endif |
1ce58df1 | 646 | + BOOL saw_mask = False; |
fa26e11c WD |
647 | + BOOL saw_user_obj = False, saw_group_obj = False, |
648 | + saw_other = False; | |
649 | + size_t count = read_int(f); | |
650 | + rsync_ace *race; | |
651 | + if (!count) | |
652 | + return; | |
653 | + while (count--) { | |
654 | + uchar tag = read_byte(f); | |
655 | + expand_rsync_acl(racl); | |
656 | + race = &racl->races[racl->count++]; | |
657 | + switch (tag) { | |
658 | + case 'u': | |
659 | + race->tag_type = SMB_ACL_USER_OBJ; | |
660 | + saw_user_obj = True; | |
661 | + break; | |
662 | + case 'U': | |
663 | + race->tag_type = SMB_ACL_USER; | |
664 | + break; | |
665 | + case 'g': | |
666 | + race->tag_type = SMB_ACL_GROUP_OBJ; | |
667 | + saw_group_obj = True; | |
668 | + break; | |
669 | + case 'G': | |
670 | + race->tag_type = SMB_ACL_GROUP; | |
671 | + break; | |
672 | + case 'o': | |
673 | + race->tag_type = SMB_ACL_OTHER; | |
674 | + saw_other = True; | |
675 | + break; | |
676 | + case 'm': | |
677 | + race->tag_type = SMB_ACL_MASK; | |
fa26e11c | 678 | + saw_mask = True; |
fa26e11c WD |
679 | + break; |
680 | + default: | |
681 | + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n", | |
682 | + tag); | |
683 | + exit_cleanup(RERR_STREAMIO); | |
684 | + } | |
685 | + race->access = read_byte(f); | |
686 | + if (race->access & ~ (4 | 2 | 1)) { | |
687 | + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n", | |
688 | + race->access); | |
689 | + exit_cleanup(RERR_STREAMIO); | |
690 | + } | |
691 | + if (race->tag_type == SMB_ACL_USER || | |
692 | + race->tag_type == SMB_ACL_GROUP) { | |
693 | + race->id = read_int(f); | |
694 | +#if ACLS_NEED_MASK | |
695 | + required_mask_perm |= race->access; | |
696 | +#endif | |
697 | + } | |
698 | +#if ACLS_NEED_MASK | |
699 | + else if (race->tag_type == SMB_ACL_GROUP_OBJ) | |
700 | + required_mask_perm |= race->access; | |
701 | +#endif | |
702 | + | |
703 | + } | |
704 | + if (!saw_user_obj) { | |
705 | + expand_rsync_acl(racl); | |
706 | + race = &racl->races[racl->count++]; | |
707 | + race->tag_type = SMB_ACL_USER_OBJ; | |
708 | + race->access = 7; | |
709 | + } | |
710 | + if (!saw_group_obj) { | |
711 | + expand_rsync_acl(racl); | |
712 | + race = &racl->races[racl->count++]; | |
713 | + race->tag_type = SMB_ACL_GROUP_OBJ; | |
714 | + race->access = 0; | |
715 | + } | |
716 | + if (!saw_other) { | |
717 | + expand_rsync_acl(racl); | |
718 | + race = &racl->races[racl->count++]; | |
719 | + race->tag_type = SMB_ACL_OTHER; | |
720 | + race->access = 0; | |
721 | + } | |
722 | +#if ACLS_NEED_MASK | |
723 | + if (!saw_mask) { | |
724 | + expand_rsync_acl(racl); | |
725 | + race = &racl->races[racl->count++]; | |
726 | + race->tag_type = SMB_ACL_MASK; | |
727 | + race->access = required_mask_perm; | |
728 | + } | |
1ce58df1 WD |
729 | +#else |
730 | + /* If we, a system without ACLS_NEED_MASK, received data from a | |
731 | + * system that has masks, throw away the extraneous CLASS_OBJs. */ | |
732 | + if (saw_mask && racl->count == 4) { | |
733 | + rsync_ace *group_obj_race = NULL, *mask_race = NULL; | |
734 | + rsync_ace *p; | |
735 | + size_t i; | |
736 | + for (i = 0, p = racl->races; i < racl->count; i++, p++) { | |
737 | + if (p->tag_type == SMB_ACL_MASK) | |
738 | + mask_race = p; | |
739 | + else if (p->tag_type == SMB_ACL_GROUP_OBJ) | |
740 | + group_obj_race = p; | |
741 | + } | |
742 | + if (mask_race == NULL || group_obj_race == NULL) { | |
743 | + rprintf(FERROR, "receive_rsync_acl: have four ACES " | |
744 | + "and one's ACL_MASK but missing " | |
745 | + "either it or ACL_GROUP_OBJ, " | |
746 | + "when pruning ACL\n"); | |
747 | + } else { | |
748 | + /* mask off group perms with it first */ | |
749 | + group_obj_race->access &= mask_race->access; | |
750 | + /* dump mask_race; re-slot any followers-on */ | |
751 | + racl->count--; | |
752 | + if (mask_race != &racl->races[racl->count]) { | |
753 | + *mask_race = racl->races[racl->count]; | |
754 | + saw_user_obj = False; /* force re-sort */ | |
755 | + } | |
756 | + } | |
757 | + } | |
fa26e11c WD |
758 | +#endif |
759 | +#if ACLS_NEED_MASK | |
760 | + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask)) | |
761 | +#else | |
762 | + if (!(saw_user_obj && saw_group_obj && saw_other)) | |
763 | +#endif | |
764 | + sort_rsync_acl(racl); | |
765 | +} | |
766 | + | |
767 | +/* receive and build the rsync_acl_lists */ | |
768 | + | |
769 | +void receive_acl(struct file_struct *file, int f) | |
770 | +{ | |
771 | + SMB_ACL_TYPE_T *type, | |
772 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
773 | + char *fname; | |
774 | + if (!preserve_acls || S_ISLNK(file->mode)) | |
775 | + return; | |
776 | + fname = f_name(file); | |
777 | + for (type = &types[0]; | |
778 | + type < &types[0] + sizeof types / sizeof types[0] | |
779 | + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode)); | |
780 | + type++) { | |
781 | + file_acl_index_list *fileaclidx_list = | |
782 | + file_acl_index_lists(*type); | |
783 | + uchar tag; | |
784 | + expand_file_acl_index_list(fileaclidx_list); | |
785 | + | |
786 | + tag = read_byte(f); | |
787 | + if (tag == 'A' || tag == 'a') { | |
788 | + if (*type != SMB_ACL_TYPE_ACCESS) { | |
789 | + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n", | |
790 | + fname); | |
791 | + exit_cleanup(RERR_STREAMIO); | |
792 | + } | |
793 | + } else if (tag == 'D' || tag == 'd') { | |
794 | + if (*type == SMB_ACL_TYPE_ACCESS) { | |
795 | + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n", | |
796 | + fname); | |
797 | + exit_cleanup(RERR_STREAMIO); | |
798 | + } | |
799 | + } else { | |
800 | + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n", | |
801 | + fname, tag); | |
802 | + exit_cleanup(RERR_STREAMIO); | |
803 | + } | |
804 | + if (tag == 'A' || tag == 'D') { | |
805 | + rsync_acl racl = rsync_acl_initializer; | |
806 | + rsync_acl_list *racl_list = rsync_acl_lists(*type); | |
807 | + smb_acl_list *sacl_list = smb_acl_lists(*type); | |
808 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count]. | |
809 | + aclidx = racl_list->count; | |
810 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count++]. | |
811 | + file = file; | |
812 | + receive_rsync_acl(&racl, f); | |
813 | + expand_rsync_acl_list(racl_list); | |
814 | + racl_list->racls[racl_list->count++] = racl; | |
815 | + expand_smb_acl_list(sacl_list); | |
816 | + sacl_list->sacls[sacl_list->count++] = NULL; | |
817 | + } else { | |
818 | + int index = read_int(f); | |
819 | + rsync_acl_list *racl_list = rsync_acl_lists(*type); | |
820 | + if ((size_t) index >= racl_list->count) { | |
821 | + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n", | |
822 | + fname, | |
823 | + str_acl_type(*type), | |
824 | + index); | |
825 | + exit_cleanup(RERR_STREAMIO); | |
826 | + } | |
827 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count]. | |
828 | + aclidx = index; | |
829 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count++]. | |
830 | + file = file; | |
831 | + } | |
832 | + } | |
833 | +} | |
834 | + | |
835 | +static int file_acl_index_list_sorter(const void *f1, const void *f2) | |
836 | +{ | |
837 | + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1; | |
838 | + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2; | |
839 | + return fileaclidx1->file == fileaclidx2->file ? 0 : | |
840 | + fileaclidx1->file < fileaclidx2->file ? -1 : 1; | |
841 | +} | |
842 | + | |
843 | +void sort_file_acl_index_lists() | |
844 | +{ | |
845 | + SMB_ACL_TYPE_T *type, | |
846 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
847 | + if (!preserve_acls) | |
848 | + return; | |
849 | + for (type = &types[0]; | |
850 | + type < &types[0] + sizeof types / sizeof types[0]; | |
851 | + type++) | |
852 | + { | |
853 | + file_acl_index_list *fileaclidx_list = | |
854 | + file_acl_index_lists(*type); | |
855 | + if (!fileaclidx_list->count) | |
856 | + continue; | |
857 | + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count, | |
858 | + sizeof fileaclidx_list->fileaclidxs[0], | |
859 | + &file_acl_index_list_sorter); | |
860 | + } | |
861 | +} | |
862 | + | |
863 | +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list, | |
864 | + const struct file_struct *file) { | |
865 | + int low = 0, high = fileaclidx_list->count; | |
866 | + const struct file_struct *file_mid; | |
867 | + if (!high--) | |
868 | + return -1; | |
869 | + do { | |
870 | + int mid = (high + low) / 2; | |
871 | + file_mid = fileaclidx_list->fileaclidxs[mid].file; | |
872 | + if (file_mid == file) | |
873 | + return fileaclidx_list->fileaclidxs[mid].aclidx; | |
874 | + if (file_mid > file) | |
875 | + high = mid - 1; | |
876 | + else | |
877 | + low = mid + 1; | |
878 | + } while (low < high); | |
879 | + if (low == high) { | |
880 | + file_mid = fileaclidx_list->fileaclidxs[low].file; | |
881 | + if (file_mid == file) | |
882 | + return fileaclidx_list->fileaclidxs[low].aclidx; | |
883 | + } | |
884 | + rprintf(FERROR, | |
885 | + "find_file_acl_index: can't find entry for file in list\n"); | |
886 | + exit_cleanup(RERR_STREAMIO); | |
887 | + return -1; | |
888 | +} | |
889 | + | |
890 | +/* for duplicating ACLs on backups when using backup_dir */ | |
891 | + | |
892 | +int dup_acl(const char *orig, const char *bak, mode_t mode) | |
893 | +{ | |
894 | + SMB_ACL_TYPE_T *type, | |
895 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
896 | + int ret = 0; | |
897 | + if (!preserve_acls) | |
898 | + return 0; | |
899 | + for (type = &types[0]; | |
900 | + type < &types[0] + sizeof types / sizeof types[0] | |
901 | + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode)); | |
902 | + type++) { | |
903 | + SMB_ACL_T sacl_orig, sacl_bak; | |
904 | + rsync_acl racl_orig, racl_bak; | |
905 | + if (!(sacl_orig = sys_acl_get_file(orig, *type))) { | |
c171f097 | 906 | + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n", |
fa26e11c WD |
907 | + orig, str_acl_type(*type), strerror(errno)); |
908 | + ret = -1; | |
909 | + continue; | |
910 | + } | |
911 | + if (!(sacl_bak = sys_acl_get_file(orig, *type))) { | |
c171f097 | 912 | + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n", |
fa26e11c WD |
913 | + bak, str_acl_type(*type), strerror(errno)); |
914 | + ret = -1; | |
915 | + /* try to forge on through */ | |
916 | + } | |
917 | + if (!unpack_smb_acl(&racl_orig, sacl_orig)) { | |
918 | + ret = -1; | |
919 | + goto out_with_sacls; | |
920 | + } | |
921 | + if (sacl_bak) { | |
922 | + if (!unpack_smb_acl(&racl_bak, sacl_bak)) { | |
923 | + ret = -1; | |
924 | + goto out_with_one_racl; | |
925 | + } | |
926 | + if (rsync_acls_equal(&racl_orig, &racl_bak)) | |
927 | + goto out_with_all; | |
928 | + } else { | |
929 | + ; /* presume they're unequal */ | |
930 | + } | |
931 | + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) { | |
932 | + if (-1 == sys_acl_delete_def_file(bak)) { | |
933 | + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n", | |
934 | + bak, strerror(errno)); | |
935 | + ret = -1; | |
936 | + } | |
937 | + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) { | |
c171f097 | 938 | + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n", |
fa26e11c WD |
939 | + bak, str_acl_type(*type), strerror(errno)); |
940 | + ret = -1; | |
941 | + } | |
942 | + out_with_all: | |
943 | + if (sacl_bak) | |
944 | + rsync_acl_free(&racl_bak); | |
945 | + out_with_one_racl: | |
946 | + rsync_acl_free(&racl_orig); | |
947 | + out_with_sacls: | |
948 | + if (sacl_bak) | |
949 | + sys_acl_free_acl(sacl_bak); | |
950 | + /* out_with_one_sacl: */ | |
951 | + if (sacl_orig) | |
952 | + sys_acl_free_acl(sacl_orig); | |
953 | + } | |
954 | + return ret; | |
955 | +} | |
956 | + | |
957 | +/* stuff for redirecting calls to set_acl() from set_perms() | |
958 | + * for keep_backup() */ | |
959 | +static const struct file_struct *backup_orig_file = NULL; | |
960 | +static const char null_string[] = ""; | |
961 | +static const char *backup_orig_fname = null_string; | |
962 | +static const char *backup_dest_fname = null_string; | |
963 | +static SMB_ACL_T _backup_sacl[] = { NULL, NULL }; | |
964 | + | |
965 | +void push_keep_backup_acl(const struct file_struct *file, | |
966 | + const char *orig, const char *dest) | |
967 | +{ | |
968 | + if (preserve_acls) { | |
969 | + SMB_ACL_TYPE_T *type, | |
970 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
971 | + SMB_ACL_T *sacl; | |
972 | + backup_orig_file = file; | |
973 | + backup_orig_fname = orig; | |
974 | + backup_dest_fname = dest; | |
975 | + for (type = &types[0], sacl = &_backup_sacl[0]; | |
976 | + type < &types[0] + sizeof types / sizeof types[0]; | |
977 | + type++) { | |
978 | + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) | |
979 | + *sacl = NULL; | |
980 | + else { | |
981 | + if (!(*sacl = sys_acl_get_file(orig, *type))) { | |
c171f097 | 982 | + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n", |
fa26e11c WD |
983 | + orig, str_acl_type(*type), |
984 | + strerror(errno)); | |
985 | + } | |
986 | + } | |
987 | + } | |
988 | + } | |
989 | +} | |
990 | + | |
991 | +static int set_keep_backup_acl() | |
992 | +{ | |
993 | + if (preserve_acls) { | |
994 | + SMB_ACL_TYPE_T *type, | |
995 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
996 | + SMB_ACL_T *sacl; | |
997 | + int ret = 0; | |
998 | + for (type = &types[0], sacl = &_backup_sacl[0]; | |
999 | + type < &types[0] + sizeof types / sizeof types[0]; | |
1000 | + type++) { | |
1001 | + if (*sacl) { | |
1002 | + if (-1 == sys_acl_set_file(backup_dest_fname, | |
1003 | + *type, *sacl)) | |
1004 | + { | |
c171f097 | 1005 | + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n", |
fa26e11c WD |
1006 | + backup_dest_fname, |
1007 | + str_acl_type(*type), | |
1008 | + strerror(errno)); | |
1009 | + ret = -1; | |
1010 | + } | |
1011 | + } | |
1012 | + } | |
1013 | + return ret; | |
1014 | + } | |
1015 | + return 0; | |
1016 | +} | |
1017 | + | |
1018 | +void cleanup_keep_backup_acl() | |
1019 | +{ | |
1020 | + if (preserve_acls) { | |
1021 | + SMB_ACL_TYPE_T *type, | |
1022 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
1023 | + SMB_ACL_T *sacl; | |
1024 | + backup_orig_file = NULL; | |
1025 | + backup_orig_fname = null_string; | |
1026 | + backup_dest_fname = null_string; | |
1027 | + for (type = &types[0], sacl = &_backup_sacl[0]; | |
1028 | + type < &types[0] + sizeof types / sizeof types[0]; | |
1029 | + type++) { | |
1030 | + if (*sacl) | |
1031 | + sys_acl_free_acl(*sacl); | |
1032 | + *sacl = NULL; | |
1033 | + } | |
1034 | + } | |
1035 | +} | |
1036 | + | |
1037 | +/* set ACL on rsync-ed or keep_backup-ed file */ | |
1038 | + | |
1039 | +int set_acl(const char *fname, const struct file_struct *file) | |
1040 | +{ | |
1041 | + int updated = 0; | |
1042 | + SMB_ACL_TYPE_T *type, | |
1043 | + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT}; | |
1044 | + if (dry_run || !preserve_acls || S_ISLNK(file->mode)) | |
1045 | + return 0; | |
1046 | + if (file == backup_orig_file) { | |
1047 | + if (!strcmp(fname, backup_dest_fname)) | |
1048 | + return set_keep_backup_acl(); | |
1049 | + } | |
1050 | + for (type = &types[0]; | |
1051 | + type < &types[0] + sizeof types / sizeof types[0] | |
1052 | + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode)); | |
1053 | + type++) { | |
1054 | + SMB_ACL_T sacl_orig, *sacl_new; | |
1055 | + rsync_acl racl_orig, *racl_new; | |
1056 | + int aclidx = find_file_acl_index(file_acl_index_lists(*type), | |
1057 | + file); | |
1058 | + BOOL ok; | |
1059 | + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]); | |
1060 | + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]); | |
1061 | + sacl_orig = sys_acl_get_file(fname, *type); | |
1062 | + if (!sacl_orig) { | |
1063 | + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n", | |
1064 | + fname, str_acl_type(*type), strerror(errno)); | |
1065 | + updated = -1; | |
1066 | + continue; | |
1067 | + } | |
1068 | + ok = unpack_smb_acl(&racl_orig, sacl_orig); | |
1069 | + sys_acl_free_acl(sacl_orig); | |
1070 | + if (!ok) { | |
1071 | + updated = -1; | |
1072 | + continue; | |
1073 | + } | |
1074 | + ok = rsync_acls_equal(&racl_orig, racl_new); | |
1075 | + rsync_acl_free(&racl_orig); | |
1076 | + if (ok) | |
1077 | + continue; | |
1078 | + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) { | |
1079 | + if (-1 == sys_acl_delete_def_file(fname)) { | |
1080 | + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n", | |
1081 | + fname, strerror(errno)); | |
1082 | + updated = -1; | |
1083 | + continue; | |
1084 | + } | |
1085 | + } else { | |
1086 | + if (!*sacl_new) | |
1087 | + if (!pack_smb_acl(sacl_new, racl_new)) { | |
1088 | + updated = -1; | |
1089 | + continue; | |
1090 | + } | |
1091 | + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) { | |
1092 | + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n", | |
1093 | + fname, str_acl_type(*type), | |
1094 | + strerror(errno)); | |
1095 | + updated = -1; | |
1096 | + continue; | |
1097 | + } | |
1098 | + } | |
1099 | + if (!updated) | |
1100 | + updated = 1; | |
1101 | + } | |
1102 | + return updated; | |
1103 | +} | |
1104 | + | |
1105 | +/* enumeration functions for uid mapping */ | |
1106 | + | |
1107 | +/* context -- one and only one. should be cycled through once on uid mapping | |
1108 | + * and once on gid mapping */ | |
1109 | +static rsync_acl_list *_enum_racl_lists[] = { | |
1110 | + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL | |
1111 | +}; | |
1112 | + | |
1113 | +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0]; | |
1114 | +static size_t enum_racl_index = 0; | |
1115 | +static size_t enum_race_index = 0; | |
1116 | + | |
1117 | +/* this returns the next tag_type id from the given acl for the next entry, | |
1118 | + * or it returns 0 if there are no more tag_type ids in the acl */ | |
1119 | + | |
1120 | +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl) | |
1121 | +{ | |
1122 | + for (; enum_race_index < racl->count; enum_race_index++) { | |
1123 | + rsync_ace *race = &racl->races[enum_race_index]; | |
1124 | + if (race->tag_type == tag_type) | |
1125 | + return race->id; | |
1126 | + } | |
1127 | + enum_race_index = 0; | |
1128 | + return 0; | |
1129 | +} | |
1130 | + | |
1131 | +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list) | |
1132 | +{ | |
1133 | + for (; enum_racl_index < racl_list->count; enum_racl_index++) { | |
1134 | + rsync_acl *racl = &racl_list->racls[enum_racl_index]; | |
1135 | + id_t id = next_ace_id(tag_type, racl); | |
1136 | + if (id) | |
1137 | + return id; | |
1138 | + } | |
1139 | + enum_racl_index = 0; | |
1140 | + return 0; | |
1141 | +} | |
1142 | + | |
1143 | +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type) | |
1144 | +{ | |
1145 | + for (; *enum_racl_list; enum_racl_list++) { | |
1146 | + id_t id = next_acl_id(tag_type, *enum_racl_list); | |
1147 | + if (id) | |
1148 | + return id; | |
1149 | + } | |
1150 | + enum_racl_list = &_enum_racl_lists[0]; | |
1151 | + return 0; | |
1152 | +} | |
1153 | + | |
1154 | +id_t next_acl_uid() | |
1155 | +{ | |
1156 | + return next_acl_list_id(SMB_ACL_USER); | |
1157 | +} | |
1158 | + | |
1159 | +id_t next_acl_gid() | |
1160 | +{ | |
1161 | + return next_acl_list_id(SMB_ACL_GROUP); | |
1162 | +} | |
1163 | + | |
1164 | +/* referring to the global context enum_entry, sets the entry's id */ | |
1165 | +static void set_acl_id(id_t id) | |
1166 | +{ | |
1167 | + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id; | |
1168 | +} | |
1169 | + | |
1170 | +void acl_uid_map(id_t uid) | |
1171 | +{ | |
1172 | + set_acl_id(uid); | |
1173 | +} | |
1174 | + | |
1175 | +void acl_gid_map(id_t gid) | |
1176 | +{ | |
1177 | + set_acl_id(gid); | |
1178 | +} | |
1179 | + | |
fa26e11c | 1180 | +#endif /* SUPPORT_ACLS */ |
35a9a417 WD |
1181 | --- orig/backup.c 2004-10-06 00:12:15 |
1182 | +++ backup.c 2004-10-06 00:13:09 | |
a6587818 | 1183 | @@ -119,6 +119,7 @@ static int make_bak_dir(char *fullpath) |
fa26e11c WD |
1184 | } else { |
1185 | do_lchown(fullpath, st.st_uid, st.st_gid); | |
1186 | do_chmod(fullpath, st.st_mode); | |
1187 | + (void)DUP_ACL(end, fullpath, st.st_mode); | |
1188 | } | |
1189 | } | |
1190 | *p = '/'; | |
a6587818 | 1191 | @@ -176,6 +177,8 @@ static int keep_backup(char *fname) |
172ad6c3 | 1192 | if (!(buf = get_backup_name(fname))) |
fa26e11c | 1193 | return 0; |
fa26e11c | 1194 | |
172ad6c3 | 1195 | + PUSH_KEEP_BACKUP_ACL(file, fname, buf); |
fa26e11c | 1196 | + |
fa26e11c WD |
1197 | /* Check to see if this is a device file, or link */ |
1198 | if (IS_DEVICE(file->mode)) { | |
35a9a417 WD |
1199 | if (am_root && preserve_devices) { |
1200 | @@ -249,6 +252,7 @@ static int keep_backup(char *fname) | |
fa26e11c WD |
1201 | } |
1202 | } | |
172ad6c3 | 1203 | set_perms(buf, file, NULL, 0); |
fa26e11c WD |
1204 | + CLEANUP_KEEP_BACKUP_ACL(); |
1205 | free(file); | |
1206 | ||
1207 | if (verbose > 1) | |
35a9a417 | 1208 | --- orig/configure.in 2004-10-06 00:12:16 |
81549708 | 1209 | +++ configure.in 2004-08-19 19:53:27 |
35a9a417 | 1210 | @@ -443,6 +443,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no |
fa26e11c WD |
1211 | AC_CHECK_LIB(resolv, strcasecmp) |
1212 | fi | |
1213 | ||
1214 | +AC_CHECK_FUNCS(aclsort) | |
1215 | +if test x"$ac_cv_func_aclsort" = x"no"; then | |
1216 | + AC_CHECK_LIB(sec, aclsort) | |
1217 | +fi | |
1218 | + | |
1219 | dnl At the moment we don't test for a broken memcmp(), because all we | |
1220 | dnl need to do is test for equality, not comparison, and it seems that | |
1221 | dnl every platform has a memcmp that can do at least that. | |
35a9a417 | 1222 | @@ -693,6 +698,77 @@ AC_SUBST(OBJ_RESTORE) |
fa26e11c WD |
1223 | AC_SUBST(CC_SHOBJ_FLAG) |
1224 | AC_SUBST(BUILD_POPT) | |
125d7fca | 1225 | |
fa26e11c WD |
1226 | +AC_CHECK_HEADERS(sys/acl.h) |
1227 | +AC_CHECK_FUNCS(_acl __acl _facl __facl) | |
1228 | +################################################# | |
1229 | +# check for ACL support | |
1230 | + | |
1231 | +AC_MSG_CHECKING(whether to support ACLs) | |
1232 | +AC_ARG_WITH(acl-support, | |
1233 | +[ --with-acl-support Include ACL support (default=no)], | |
1234 | +[ case "$withval" in | |
1235 | + yes) | |
1236 | + | |
1237 | + case "$host_os" in | |
1238 | + *sysv5*) | |
1239 | + AC_MSG_RESULT(Using UnixWare ACLs) | |
1240 | + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs]) | |
1241 | + ;; | |
1242 | + *solaris*) | |
1243 | + AC_MSG_RESULT(Using solaris ACLs) | |
1244 | + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs]) | |
1245 | + ;; | |
1246 | + *hpux*) | |
1247 | + AC_MSG_RESULT(Using HPUX ACLs) | |
1248 | + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs]) | |
1249 | + ;; | |
1250 | + *irix*) | |
1251 | + AC_MSG_RESULT(Using IRIX ACLs) | |
1252 | + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs]) | |
1253 | + ;; | |
1254 | + *aix*) | |
1255 | + AC_MSG_RESULT(Using AIX ACLs) | |
1256 | + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs]) | |
1257 | + ;; | |
1258 | + *osf*) | |
1259 | + AC_MSG_RESULT(Using Tru64 ACLs) | |
1260 | + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs]) | |
1261 | + LIBS="$LIBS -lpacl" | |
1262 | + ;; | |
1263 | + *) | |
81549708 | 1264 | + AC_MSG_RESULT(ACLs requested -- running tests) |
fa26e11c WD |
1265 | + AC_CHECK_LIB(acl,acl_get_file) |
1266 | + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[ | |
1267 | + AC_TRY_LINK([#include <sys/types.h> | |
1268 | +#include <sys/acl.h>], | |
1269 | +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);], | |
1270 | +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)]) | |
1271 | + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then | |
1272 | + AC_MSG_RESULT(Using posix ACLs) | |
1273 | + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs]) | |
81549708 | 1274 | + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[ |
fa26e11c WD |
1275 | + AC_TRY_LINK([#include <sys/types.h> |
1276 | +#include <sys/acl.h>], | |
1277 | +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);], | |
1278 | +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)]) | |
81549708 WD |
1279 | + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then |
1280 | + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np]) | |
1281 | + fi | |
1282 | + else | |
1283 | + AC_MSG_ERROR(Failed to find ACL support) | |
fa26e11c WD |
1284 | + fi |
1285 | + ;; | |
1286 | + esac | |
1287 | + ;; | |
1288 | + *) | |
1289 | + AC_MSG_RESULT(no) | |
1290 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) | |
1291 | + ;; | |
1292 | + esac ], | |
1293 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) | |
1294 | + AC_MSG_RESULT(no) | |
1295 | +) | |
125d7fca | 1296 | + |
fa26e11c WD |
1297 | AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig]) |
1298 | AC_OUTPUT | |
125d7fca | 1299 | |
a6587818 | 1300 | --- orig/flist.c 2004-09-21 09:40:27 |
13bed3dd | 1301 | +++ flist.c 2004-07-03 20:11:58 |
a6587818 | 1302 | @@ -966,6 +966,8 @@ void send_file_name(int f, struct file_l |
fa26e11c WD |
1303 | |
1304 | if (!file) | |
1305 | return; | |
1306 | + if (!MAKE_ACL(file, fname)) | |
1307 | + return; | |
1308 | ||
1309 | maybe_emit_filelist_progress(flist); | |
1310 | ||
a6587818 | 1311 | @@ -974,6 +976,10 @@ void send_file_name(int f, struct file_l |
fa26e11c WD |
1312 | if (file->basename[0]) { |
1313 | flist->files[flist->count++] = file; | |
1314 | send_file_entry(file, f, base_flags); | |
1315 | + SEND_ACL(file, f); | |
1316 | + } else { | |
1317 | + /* Cleanup unsent ACL(s). */ | |
1318 | + SEND_ACL(file, -1); | |
1319 | } | |
1320 | ||
1321 | if (recursive && S_ISDIR(file->mode) | |
a6587818 | 1322 | @@ -1291,6 +1297,8 @@ struct file_list *recv_file_list(int f) |
fa26e11c WD |
1323 | flags |= read_byte(f) << 8; |
1324 | receive_file_entry(&flist->files[i], flags, flist, f); | |
1325 | ||
1326 | + RECEIVE_ACL(flist->files[i], f); | |
1327 | + | |
1328 | if (S_ISREG(flist->files[i]->mode)) | |
1329 | stats.total_size += flist->files[i]->length; | |
1330 | ||
a6587818 | 1331 | @@ -1313,6 +1321,8 @@ struct file_list *recv_file_list(int f) |
fa26e11c WD |
1332 | |
1333 | clean_flist(flist, relative_paths, 1); | |
fa26e11c | 1334 | |
125d7fca WD |
1335 | + SORT_FILE_ACL_INDEX_LISTS(); |
1336 | + | |
fa26e11c WD |
1337 | if (f != -1) { |
1338 | /* Now send the uid/gid list. This was introduced in | |
125d7fca | 1339 | * protocol version 15 */ |
35a9a417 | 1340 | --- orig/generator.c 2004-10-06 00:12:16 |
13bed3dd | 1341 | +++ generator.c 2004-07-03 20:11:58 |
172ad6c3 | 1342 | @@ -338,6 +338,10 @@ static void recv_generator(char *fname, |
125d7fca WD |
1343 | if (set_perms(fname, file, statret ? NULL : &st, 0) |
1344 | && verbose && f_out != -1) | |
982426b8 | 1345 | rprintf(FINFO, "%s/\n", safe_fname(fname)); |
fa26e11c WD |
1346 | +#if SUPPORT_ACLS |
1347 | + if (f_out == -1) | |
1348 | + SET_ACL(fname, file); | |
1349 | +#endif | |
1350 | return; | |
1351 | } | |
1352 | ||
13bed3dd WD |
1353 | --- orig/mkproto.awk 2004-01-01 21:10:50 |
1354 | +++ mkproto.awk 2004-06-30 00:04:06 | |
fa26e11c WD |
1355 | @@ -58,7 +58,7 @@ BEGIN { |
1356 | next; | |
1357 | } | |
1358 | ||
1359 | -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^const/ { | |
1360 | +!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^const|^SMB_ACL_T|^id_t/ { | |
1361 | next; | |
1362 | } | |
1363 | ||
35a9a417 | 1364 | --- orig/options.c 2004-10-08 20:16:26 |
81549708 | 1365 | +++ options.c 2004-08-19 17:38:57 |
125d7fca | 1366 | @@ -43,6 +43,7 @@ int keep_dirlinks = 0; |
fa26e11c WD |
1367 | int copy_links = 0; |
1368 | int preserve_links = 0; | |
1369 | int preserve_hard_links = 0; | |
1370 | +int preserve_acls = 0; | |
1371 | int preserve_perms = 0; | |
1372 | int preserve_devices = 0; | |
1373 | int preserve_uid = 0; | |
f635ed27 | 1374 | @@ -152,6 +153,7 @@ static void print_rsync_version(enum log |
fa26e11c | 1375 | char const *got_socketpair = "no "; |
f6c3b300 | 1376 | char const *have_inplace = "no "; |
fa26e11c WD |
1377 | char const *hardlinks = "no "; |
1378 | + char const *acls = "no "; | |
1379 | char const *links = "no "; | |
1380 | char const *ipv6 = "no "; | |
1381 | STRUCT_STAT *dumstat; | |
f635ed27 | 1382 | @@ -168,6 +170,10 @@ static void print_rsync_version(enum log |
fa26e11c WD |
1383 | hardlinks = ""; |
1384 | #endif | |
1385 | ||
1386 | +#if SUPPORT_ACLS | |
1387 | + acls = ""; | |
1388 | +#endif | |
1389 | + | |
1390 | #if SUPPORT_LINKS | |
1391 | links = ""; | |
1392 | #endif | |
f635ed27 | 1393 | @@ -182,9 +188,9 @@ static void print_rsync_version(enum log |
fa26e11c WD |
1394 | "Copyright (C) 1996-2004 by Andrew Tridgell and others\n"); |
1395 | rprintf(f, "<http://rsync.samba.org/>\n"); | |
1396 | rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, " | |
1397 | - "%shard links, %ssymlinks, batchfiles, \n", | |
81549708 | 1398 | + "%shard links, %sACLs, %ssymlinks, batchfiles, \n", |
fa26e11c WD |
1399 | (int) (sizeof (OFF_T) * 8), |
1400 | - got_socketpair, hardlinks, links); | |
1401 | + got_socketpair, hardlinks, acls, links); | |
1402 | ||
1403 | /* Note that this field may not have type ino_t. It depends | |
1404 | * on the complicated interaction between largefile feature | |
f635ed27 | 1405 | @@ -249,6 +255,7 @@ void usage(enum logcode F) |
fa26e11c WD |
1406 | rprintf(F," --safe-links ignore \"unsafe\" symlinks\n"); |
1407 | rprintf(F," -H, --hard-links preserve hard links\n"); | |
1408 | rprintf(F," -p, --perms preserve permissions\n"); | |
1409 | + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); | |
1410 | rprintf(F," -o, --owner preserve owner (root only)\n"); | |
1411 | rprintf(F," -g, --group preserve group\n"); | |
1412 | rprintf(F," -D, --devices preserve devices (root only)\n"); | |
f635ed27 | 1413 | @@ -358,6 +365,7 @@ static struct poptOption long_options[] |
9be39c35 WD |
1414 | {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 }, |
1415 | {"copy-unsafe-links", 0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 }, | |
1416 | {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 }, | |
3559aee3 | 1417 | + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
9be39c35 WD |
1418 | {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 }, |
1419 | {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 }, | |
1420 | {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 }, | |
172ad6c3 | 1421 | @@ -616,6 +624,24 @@ int parse_arguments(int *argc, const cha |
fa26e11c WD |
1422 | return 0; |
1423 | #endif | |
1424 | ||
1425 | + case 'A': | |
1426 | +#if SUPPORT_ACLS | |
1427 | + preserve_acls = 1; | |
1428 | + preserve_perms = 1; | |
1429 | +#else | |
1430 | + /* FIXME: this should probably be ignored with a | |
1431 | + * warning and then countermeasures taken to | |
1432 | + * restrict group and other access in the presence | |
1433 | + * of any more restrictive ACLs, but this is safe | |
1434 | + * for now */ | |
fa26e11c WD |
1435 | + snprintf(err_buf,sizeof(err_buf), |
1436 | + "ACLs are not supported on this %s\n", | |
1437 | + am_server ? "server" : "client"); | |
fa26e11c WD |
1438 | + return 0; |
1439 | +#endif /* SUPPORT_ACLS */ | |
1440 | + break; | |
1441 | + | |
1442 | + | |
1443 | default: | |
1444 | /* A large opt value means that set_refuse_options() | |
1445 | * turned this option off (opt-BASE is its index). */ | |
a60267ab | 1446 | @@ -942,6 +968,8 @@ void server_options(char **args,int *arg |
fa26e11c WD |
1447 | |
1448 | if (preserve_hard_links) | |
1449 | argstr[x++] = 'H'; | |
1450 | + if (preserve_acls) | |
1451 | + argstr[x++] = 'A'; | |
1452 | if (preserve_uid) | |
1453 | argstr[x++] = 'o'; | |
1454 | if (preserve_gid) | |
172ad6c3 | 1455 | --- orig/rsync.c 2004-09-07 21:45:30 |
13bed3dd | 1456 | +++ rsync.c 2004-07-03 20:11:58 |
f635ed27 | 1457 | @@ -207,6 +207,14 @@ int set_perms(char *fname,struct file_st |
fa26e11c WD |
1458 | } |
1459 | #endif | |
1460 | ||
1461 | + /* If this is a directory, SET_ACL() will be called on the cleanup | |
1462 | + * receive_generator() pass--if we called it here, we might clobber | |
1463 | + * writability on the directory. everything else is OK to do now. */ | |
1464 | + if (!S_ISDIR(st->st_mode)) { | |
1465 | + if (SET_ACL(fname, file) == 0) | |
1466 | + updated = 1; | |
1467 | + } | |
1468 | + | |
1469 | if (verbose > 1 && flags & PERMS_REPORT) { | |
1470 | if (updated) | |
1471 | rprintf(FINFO,"%s\n",fname); | |
35a9a417 | 1472 | --- orig/rsync.h 2004-10-09 03:21:56 |
13bed3dd | 1473 | +++ rsync.h 2004-07-03 20:11:58 |
35a9a417 | 1474 | @@ -545,6 +545,40 @@ static inline int flist_up(struct file_l |
fa26e11c WD |
1475 | #include "lib/permstring.h" |
1476 | #include "lib/addrinfo.h" | |
1477 | ||
1478 | +#define SUPPORT_ACLS HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\ | |
1479 | + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS | |
1480 | + | |
1481 | +#define ACLS_NEED_MASK HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS | |
1482 | + | |
1483 | +#if SUPPORT_ACLS | |
1484 | +#ifdef HAVE_SYS_ACL_H | |
1485 | +#include <sys/acl.h> | |
1486 | +#endif | |
1487 | +#define MAKE_ACL(file, fname) make_acl(file, fname) | |
1488 | +#define SEND_ACL(file, f) send_acl(file, f) | |
1489 | +#define RECEIVE_ACL(file, f) receive_acl(file, f) | |
1490 | +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists() | |
1491 | +#define SET_ACL(fname, file) set_acl(fname, file) | |
1492 | +#define NEXT_ACL_UID() next_acl_uid() | |
1493 | +#define ACL_UID_MAP(uid) acl_uid_map(uid) | |
1494 | +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \ | |
1495 | + push_keep_backup_acl(file, orig, dest) | |
1496 | +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl() | |
1497 | +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode) | |
1498 | +#else /* SUPPORT_ACLS */ | |
1499 | +#define MAKE_ACL(file, fname) 1 /* checked return value */ | |
1500 | +#define SEND_ACL(file, f) | |
1501 | +#define RECEIVE_ACL(file, f) | |
1502 | +#define SORT_FILE_ACL_INDEX_LISTS() | |
1503 | +#define SET_ACL(fname, file) 0 /* checked return value */ | |
1504 | +#define NEXT_ACL_UID() | |
1505 | +#define ACL_UID_MAP(uid) | |
1506 | +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) | |
1507 | +#define CLEANUP_KEEP_BACKUP_ACL() | |
1508 | +#define DUP_ACL(src, orig, mode) 0 /* checked return value */ | |
1509 | +#endif /* SUPPORT_ACLS */ | |
1510 | +#include "smb_acls.h" | |
1511 | + | |
1512 | #include "proto.h" | |
1513 | ||
1514 | /* We have replacement versions of these if they're missing. */ | |
35a9a417 | 1515 | --- orig/rsync.yo 2004-10-06 00:12:16 |
13bed3dd | 1516 | +++ rsync.yo 2004-07-03 20:11:58 |
a30f8abd | 1517 | @@ -326,6 +326,7 @@ verb( |
fa26e11c WD |
1518 | --safe-links ignore "unsafe" symlinks |
1519 | -H, --hard-links preserve hard links | |
1520 | -p, --perms preserve permissions | |
1521 | + -A, --acls preserve ACLs (implies -p) [local option] | |
1522 | -o, --owner preserve owner (root only) | |
1523 | -g, --group preserve group | |
1524 | -D, --devices preserve devices (root only) | |
a60267ab | 1525 | @@ -585,6 +586,11 @@ source file's permissions and the umask |
fa26e11c WD |
1526 | other files (including updated files) retain their existing permissions |
1527 | (which is the same behavior as other file-copy utilities, such as cp). | |
125d7fca | 1528 | |
fa26e11c WD |
1529 | +dit(bf(-A, --acls)) This option causes rsync to update the remote |
1530 | +ACLs to be the same as the local ACLs. This will work only if the | |
1531 | +remote machine's rsync supports this option also. This is a non-standard | |
1532 | +option. | |
125d7fca | 1533 | + |
fa26e11c WD |
1534 | dit(bf(-o, --owner)) This option causes rsync to set the owner of the |
1535 | destination file to be the same as the source file. On most systems, | |
125d7fca | 1536 | only the super-user can set file ownership. By default, the preservation |
13bed3dd WD |
1537 | --- orig/smb_acls.h 2004-06-30 00:04:07 |
1538 | +++ smb_acls.h 2004-06-30 00:04:07 | |
fa26e11c WD |
1539 | @@ -0,0 +1,277 @@ |
1540 | +/* | |
1541 | + Unix SMB/Netbios implementation. | |
1542 | + Version 2.2.x | |
1543 | + Portable SMB ACL interface | |
1544 | + Copyright (C) Jeremy Allison 2000 | |
1545 | + | |
1546 | + This program is free software; you can redistribute it and/or modify | |
1547 | + it under the terms of the GNU General Public License as published by | |
1548 | + the Free Software Foundation; either version 2 of the License, or | |
1549 | + (at your option) any later version. | |
1550 | + | |
1551 | + This program is distributed in the hope that it will be useful, | |
1552 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1553 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1554 | + GNU General Public License for more details. | |
1555 | + | |
1556 | + You should have received a copy of the GNU General Public License | |
1557 | + along with this program; if not, write to the Free Software | |
1558 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
1559 | +*/ | |
1560 | + | |
1561 | +#ifndef _SMB_ACLS_H | |
1562 | +#define _SMB_ACLS_H | |
1563 | + | |
1564 | +#if defined(HAVE_POSIX_ACLS) | |
1565 | + | |
1566 | +/* This is an identity mapping (just remove the SMB_). */ | |
1567 | + | |
1568 | +#define SMB_ACL_TAG_T acl_tag_t | |
1569 | +#define SMB_ACL_TYPE_T acl_type_t | |
1570 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
1571 | +#define SMB_ACL_PERM_T acl_perm_t | |
1572 | +#define SMB_ACL_READ ACL_READ | |
1573 | +#define SMB_ACL_WRITE ACL_WRITE | |
1574 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
1575 | + | |
1576 | +/* Types of ACLs. */ | |
1577 | +#define SMB_ACL_USER ACL_USER | |
1578 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
1579 | +#define SMB_ACL_GROUP ACL_GROUP | |
1580 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
1581 | +#define SMB_ACL_OTHER ACL_OTHER | |
1582 | +#define SMB_ACL_MASK ACL_MASK | |
1583 | + | |
1584 | +#define SMB_ACL_T acl_t | |
1585 | + | |
1586 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
1587 | + | |
1588 | +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
1589 | +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
1590 | + | |
1591 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
1592 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
1593 | + | |
1594 | +#elif defined(HAVE_TRU64_ACLS) | |
1595 | + | |
1596 | +/* This is for DEC/Compaq Tru64 UNIX */ | |
1597 | + | |
1598 | +#define SMB_ACL_TAG_T acl_tag_t | |
1599 | +#define SMB_ACL_TYPE_T acl_type_t | |
1600 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
1601 | +#define SMB_ACL_PERM_T acl_perm_t | |
1602 | +#define SMB_ACL_READ ACL_READ | |
1603 | +#define SMB_ACL_WRITE ACL_WRITE | |
1604 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
1605 | + | |
1606 | +/* Types of ACLs. */ | |
1607 | +#define SMB_ACL_USER ACL_USER | |
1608 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
1609 | +#define SMB_ACL_GROUP ACL_GROUP | |
1610 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
1611 | +#define SMB_ACL_OTHER ACL_OTHER | |
1612 | +#define SMB_ACL_MASK ACL_MASK | |
1613 | + | |
1614 | +#define SMB_ACL_T acl_t | |
1615 | + | |
1616 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
1617 | + | |
1618 | +#define SMB_ACL_FIRST_ENTRY 0 | |
1619 | +#define SMB_ACL_NEXT_ENTRY 1 | |
1620 | + | |
1621 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
1622 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
1623 | + | |
1624 | +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) | |
1625 | +/* | |
1626 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
1627 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
1628 | + */ | |
1629 | + | |
1630 | +/* SVR4.2 ES/MP ACLs */ | |
1631 | +typedef int SMB_ACL_TAG_T; | |
1632 | +typedef int SMB_ACL_TYPE_T; | |
1633 | +typedef ushort *SMB_ACL_PERMSET_T; | |
1634 | +typedef ushort SMB_ACL_PERM_T; | |
1635 | +#define SMB_ACL_READ 4 | |
1636 | +#define SMB_ACL_WRITE 2 | |
1637 | +#define SMB_ACL_EXECUTE 1 | |
1638 | + | |
1639 | +/* Types of ACLs. */ | |
1640 | +#define SMB_ACL_USER USER | |
1641 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
1642 | +#define SMB_ACL_GROUP GROUP | |
1643 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
1644 | +#define SMB_ACL_OTHER OTHER_OBJ | |
1645 | +#define SMB_ACL_MASK CLASS_OBJ | |
1646 | + | |
1647 | +typedef struct SMB_ACL_T { | |
1648 | + int size; | |
1649 | + int count; | |
1650 | + int next; | |
1651 | + struct acl acl[1]; | |
1652 | +} *SMB_ACL_T; | |
1653 | + | |
1654 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
1655 | + | |
1656 | +#define SMB_ACL_FIRST_ENTRY 0 | |
1657 | +#define SMB_ACL_NEXT_ENTRY 1 | |
1658 | + | |
1659 | +#define SMB_ACL_TYPE_ACCESS 0 | |
1660 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
1661 | + | |
1662 | +#elif defined(HAVE_HPUX_ACLS) | |
1663 | + | |
1664 | +/* | |
1665 | + * Based on the Solaris & UnixWare code. | |
1666 | + */ | |
1667 | + | |
1668 | +#undef GROUP | |
1669 | +#include <sys/aclv.h> | |
1670 | + | |
1671 | +/* SVR4.2 ES/MP ACLs */ | |
1672 | +typedef int SMB_ACL_TAG_T; | |
1673 | +typedef int SMB_ACL_TYPE_T; | |
1674 | +typedef ushort *SMB_ACL_PERMSET_T; | |
1675 | +typedef ushort SMB_ACL_PERM_T; | |
1676 | +#define SMB_ACL_READ 4 | |
1677 | +#define SMB_ACL_WRITE 2 | |
1678 | +#define SMB_ACL_EXECUTE 1 | |
1679 | + | |
1680 | +/* Types of ACLs. */ | |
1681 | +#define SMB_ACL_USER USER | |
1682 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
1683 | +#define SMB_ACL_GROUP GROUP | |
1684 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
1685 | +#define SMB_ACL_OTHER OTHER_OBJ | |
1686 | +#define SMB_ACL_MASK CLASS_OBJ | |
1687 | + | |
1688 | +typedef struct SMB_ACL_T { | |
1689 | + int size; | |
1690 | + int count; | |
1691 | + int next; | |
1692 | + struct acl acl[1]; | |
1693 | +} *SMB_ACL_T; | |
1694 | + | |
1695 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
1696 | + | |
1697 | +#define SMB_ACL_FIRST_ENTRY 0 | |
1698 | +#define SMB_ACL_NEXT_ENTRY 1 | |
1699 | + | |
1700 | +#define SMB_ACL_TYPE_ACCESS 0 | |
1701 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
1702 | + | |
1703 | +#elif defined(HAVE_IRIX_ACLS) | |
1704 | + | |
1705 | +#define SMB_ACL_TAG_T acl_tag_t | |
1706 | +#define SMB_ACL_TYPE_T acl_type_t | |
1707 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
1708 | +#define SMB_ACL_PERM_T acl_perm_t | |
1709 | +#define SMB_ACL_READ ACL_READ | |
1710 | +#define SMB_ACL_WRITE ACL_WRITE | |
1711 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
1712 | + | |
1713 | +/* Types of ACLs. */ | |
1714 | +#define SMB_ACL_USER ACL_USER | |
1715 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
1716 | +#define SMB_ACL_GROUP ACL_GROUP | |
1717 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
1718 | +#define SMB_ACL_OTHER ACL_OTHER_OBJ | |
1719 | +#define SMB_ACL_MASK ACL_MASK | |
1720 | + | |
1721 | +typedef struct SMB_ACL_T { | |
1722 | + int next; | |
1723 | + BOOL freeaclp; | |
1724 | + struct acl *aclp; | |
1725 | +} *SMB_ACL_T; | |
1726 | + | |
1727 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
1728 | + | |
1729 | +#define SMB_ACL_FIRST_ENTRY 0 | |
1730 | +#define SMB_ACL_NEXT_ENTRY 1 | |
1731 | + | |
1732 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
1733 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
1734 | + | |
1735 | +#elif defined(HAVE_AIX_ACLS) | |
1736 | + | |
1737 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
1738 | + | |
1739 | +#include "/usr/include/acl.h" | |
1740 | + | |
1741 | +typedef uint *SMB_ACL_PERMSET_T; | |
1742 | + | |
1743 | +struct acl_entry_link{ | |
1744 | + struct acl_entry_link *prevp; | |
1745 | + struct new_acl_entry *entryp; | |
1746 | + struct acl_entry_link *nextp; | |
1747 | + int count; | |
1748 | +}; | |
1749 | + | |
1750 | +struct new_acl_entry{ | |
1751 | + unsigned short ace_len; | |
1752 | + unsigned short ace_type; | |
1753 | + unsigned int ace_access; | |
1754 | + struct ace_id ace_id[1]; | |
1755 | +}; | |
1756 | + | |
1757 | +#define SMB_ACL_ENTRY_T struct new_acl_entry* | |
1758 | +#define SMB_ACL_T struct acl_entry_link* | |
1759 | + | |
1760 | +#define SMB_ACL_TAG_T unsigned short | |
1761 | +#define SMB_ACL_TYPE_T int | |
1762 | +#define SMB_ACL_PERM_T uint | |
1763 | +#define SMB_ACL_READ S_IRUSR | |
1764 | +#define SMB_ACL_WRITE S_IWUSR | |
1765 | +#define SMB_ACL_EXECUTE S_IXUSR | |
1766 | + | |
1767 | +/* Types of ACLs. */ | |
1768 | +#define SMB_ACL_USER ACEID_USER | |
1769 | +#define SMB_ACL_USER_OBJ 3 | |
1770 | +#define SMB_ACL_GROUP ACEID_GROUP | |
1771 | +#define SMB_ACL_GROUP_OBJ 4 | |
1772 | +#define SMB_ACL_OTHER 5 | |
1773 | +#define SMB_ACL_MASK 6 | |
1774 | + | |
1775 | + | |
1776 | +#define SMB_ACL_FIRST_ENTRY 1 | |
1777 | +#define SMB_ACL_NEXT_ENTRY 2 | |
1778 | + | |
1779 | +#define SMB_ACL_TYPE_ACCESS 0 | |
1780 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
1781 | + | |
1782 | +#else /* No ACLs. */ | |
1783 | + | |
1784 | +/* No ACLS - fake it. */ | |
1785 | +#define SMB_ACL_TAG_T int | |
1786 | +#define SMB_ACL_TYPE_T int | |
1787 | +#define SMB_ACL_PERMSET_T mode_t | |
1788 | +#define SMB_ACL_PERM_T mode_t | |
1789 | +#define SMB_ACL_READ S_IRUSR | |
1790 | +#define SMB_ACL_WRITE S_IWUSR | |
1791 | +#define SMB_ACL_EXECUTE S_IXUSR | |
1792 | + | |
1793 | +/* Types of ACLs. */ | |
1794 | +#define SMB_ACL_USER 0 | |
1795 | +#define SMB_ACL_USER_OBJ 1 | |
1796 | +#define SMB_ACL_GROUP 2 | |
1797 | +#define SMB_ACL_GROUP_OBJ 3 | |
1798 | +#define SMB_ACL_OTHER 4 | |
1799 | +#define SMB_ACL_MASK 5 | |
1800 | + | |
1801 | +typedef struct SMB_ACL_T { | |
1802 | + int dummy; | |
1803 | +} *SMB_ACL_T; | |
1804 | + | |
1805 | +typedef struct SMB_ACL_ENTRY_T { | |
1806 | + int dummy; | |
1807 | +} *SMB_ACL_ENTRY_T; | |
1808 | + | |
1809 | +#define SMB_ACL_FIRST_ENTRY 0 | |
1810 | +#define SMB_ACL_NEXT_ENTRY 1 | |
1811 | + | |
1812 | +#define SMB_ACL_TYPE_ACCESS 0 | |
1813 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
1814 | + | |
1815 | +#endif /* No ACLs. */ | |
1816 | +#endif /* _SMB_ACLS_H */ | |
81549708 WD |
1817 | --- orig/sysacls.c 2004-08-19 17:38:21 |
1818 | +++ sysacls.c 2004-08-19 17:38:21 | |
fa26e11c WD |
1819 | @@ -0,0 +1,3117 @@ |
1820 | +/* | |
1821 | + Unix SMB/Netbios implementation. | |
1822 | + Version 2.2. | |
1823 | + Samba system utilities for ACL support. | |
1824 | + Copyright (C) Jeremy Allison 2000. | |
1825 | + | |
1826 | + This program is free software; you can redistribute it and/or modify | |
1827 | + it under the terms of the GNU General Public License as published by | |
1828 | + the Free Software Foundation; either version 2 of the License, or | |
1829 | + (at your option) any later version. | |
1830 | + | |
1831 | + This program is distributed in the hope that it will be useful, | |
1832 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1833 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1834 | + GNU General Public License for more details. | |
1835 | + | |
1836 | + You should have received a copy of the GNU General Public License | |
1837 | + along with this program; if not, write to the Free Software | |
1838 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
1839 | +*/ | |
1840 | + | |
1841 | +#include "rsync.h" | |
1842 | + | |
1843 | +/* | |
1844 | + This file wraps all differing system ACL interfaces into a consistent | |
1845 | + one based on the POSIX interface. It also returns the correct errors | |
1846 | + for older UNIX systems that don't support ACLs. | |
1847 | + | |
1848 | + The interfaces that each ACL implementation must support are as follows: | |
1849 | + | |
1850 | + int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
1851 | + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
1852 | + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p | |
1853 | + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
1854 | + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
1855 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
1856 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
1857 | + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
1858 | + char *sys_acl_to_text(SMB_ACL_T theacl, ssize_t *plen) | |
1859 | + SMB_ACL_T sys_acl_init(int count) | |
1860 | + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
1861 | + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
1862 | + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual) | |
1863 | + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
1864 | + int sys_acl_valid(SMB_ACL_T theacl) | |
1865 | + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
1866 | + int sys_acl_set_fd(int fd, SMB_ACL_T theacl) | |
1867 | + int sys_acl_delete_def_file(const char *path) | |
1868 | + | |
1869 | + This next one is not POSIX complient - but we *have* to have it ! | |
1870 | + More POSIX braindamage. | |
1871 | + | |
1872 | + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
1873 | + | |
1874 | + The generic POSIX free is the following call. We split this into | |
1875 | + several different free functions as we may need to add tag info | |
1876 | + to structures when emulating the POSIX interface. | |
1877 | + | |
1878 | + int sys_acl_free(void *obj_p) | |
1879 | + | |
1880 | + The calls we actually use are: | |
1881 | + | |
1882 | + int sys_acl_free_text(char *text) - free acl_to_text | |
1883 | + int sys_acl_free_acl(SMB_ACL_T posix_acl) | |
1884 | + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype) | |
1885 | + | |
1886 | +*/ | |
1887 | + | |
1888 | +#if defined(HAVE_POSIX_ACLS) | |
1889 | + | |
1890 | +/* Identity mapping - easy. */ | |
1891 | + | |
1892 | +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
1893 | +{ | |
1894 | + return acl_get_entry(the_acl, entry_id, entry_p); | |
1895 | +} | |
1896 | + | |
1897 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
1898 | +{ | |
1899 | + return acl_get_tag_type(entry_d, tag_type_p); | |
1900 | +} | |
1901 | + | |
1902 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) | |
1903 | +{ | |
1904 | + return acl_get_permset(entry_d, permset_p); | |
1905 | +} | |
1906 | + | |
1907 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
1908 | +{ | |
1909 | + return acl_get_qualifier(entry_d); | |
1910 | +} | |
1911 | + | |
1912 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
1913 | +{ | |
1914 | + return acl_get_file(path_p, type); | |
1915 | +} | |
1916 | + | |
1917 | +SMB_ACL_T sys_acl_get_fd(int fd) | |
1918 | +{ | |
1919 | + return acl_get_fd(fd); | |
1920 | +} | |
1921 | + | |
1922 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) | |
1923 | +{ | |
1924 | + return acl_clear_perms(permset); | |
1925 | +} | |
1926 | + | |
1927 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
1928 | +{ | |
1929 | + return acl_add_perm(permset, perm); | |
1930 | +} | |
1931 | + | |
1932 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
1933 | +{ | |
1934 | +#if defined(HAVE_ACL_GET_PERM_NP) | |
1935 | + /* Required for TrustedBSD-based ACL implementations where | |
1936 | + * non-POSIX.1e functions are denoted by a _np (non-portable) | |
1937 | + * suffix. */ | |
1938 | + return acl_get_perm_np(permset, perm); | |
1939 | +#else | |
1940 | + return acl_get_perm(permset, perm); | |
1941 | +#endif | |
1942 | +} | |
1943 | + | |
1944 | +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen) | |
1945 | +{ | |
1946 | + return acl_to_text(the_acl, plen); | |
1947 | +} | |
1948 | + | |
1949 | +SMB_ACL_T sys_acl_init(int count) | |
1950 | +{ | |
1951 | + return acl_init(count); | |
1952 | +} | |
1953 | + | |
1954 | +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
1955 | +{ | |
1956 | + return acl_create_entry(pacl, pentry); | |
1957 | +} | |
1958 | + | |
1959 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
1960 | +{ | |
1961 | + return acl_set_tag_type(entry, tagtype); | |
1962 | +} | |
1963 | + | |
1964 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual) | |
1965 | +{ | |
1966 | + return acl_set_qualifier(entry, qual); | |
1967 | +} | |
1968 | + | |
1969 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
1970 | +{ | |
1971 | + return acl_set_permset(entry, permset); | |
1972 | +} | |
1973 | + | |
1974 | +int sys_acl_valid(SMB_ACL_T theacl) | |
1975 | +{ | |
1976 | + return acl_valid(theacl); | |
1977 | +} | |
1978 | + | |
1979 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
1980 | +{ | |
1981 | + return acl_set_file(name, acltype, theacl); | |
1982 | +} | |
1983 | + | |
1984 | +int sys_acl_set_fd(int fd, SMB_ACL_T theacl) | |
1985 | +{ | |
1986 | + return acl_set_fd(fd, theacl); | |
1987 | +} | |
1988 | + | |
1989 | +int sys_acl_delete_def_file(const char *name) | |
1990 | +{ | |
1991 | + return acl_delete_def_file(name); | |
1992 | +} | |
1993 | + | |
1994 | +int sys_acl_free_text(char *text) | |
1995 | +{ | |
1996 | + return acl_free(text); | |
1997 | +} | |
1998 | + | |
1999 | +int sys_acl_free_acl(SMB_ACL_T the_acl) | |
2000 | +{ | |
2001 | + return acl_free(the_acl); | |
2002 | +} | |
2003 | + | |
c9133e4e | 2004 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2005 | +{ |
2006 | + return acl_free(qual); | |
2007 | +} | |
2008 | + | |
2009 | +#elif defined(HAVE_TRU64_ACLS) | |
2010 | +/* The interface to DEC/Compaq Tru64 UNIX ACLs | |
2011 | + * is based on Draft 13 of the POSIX spec which is | |
2012 | + * slightly different from the Draft 16 interface. | |
2013 | + * | |
2014 | + * Also, some of the permset manipulation functions | |
2015 | + * such as acl_clear_perm() and acl_add_perm() appear | |
2016 | + * to be broken on Tru64 so we have to manipulate | |
2017 | + * the permission bits in the permset directly. */ | |
2018 | + int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
2019 | +{ | |
2020 | + SMB_ACL_ENTRY_T entry; | |
2021 | + | |
2022 | + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { | |
2023 | + return -1; | |
2024 | + } | |
2025 | + | |
2026 | + errno = 0; | |
2027 | + if ((entry = acl_get_entry(the_acl)) != NULL) { | |
2028 | + *entry_p = entry; | |
2029 | + return 1; | |
2030 | + } | |
2031 | + | |
2032 | + return errno ? -1 : 0; | |
2033 | +} | |
2034 | + | |
2035 | + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
2036 | +{ | |
2037 | + return acl_get_tag_type(entry_d, tag_type_p); | |
2038 | +} | |
2039 | + | |
2040 | + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) | |
2041 | +{ | |
2042 | + return acl_get_permset(entry_d, permset_p); | |
2043 | +} | |
2044 | + | |
2045 | + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
2046 | +{ | |
2047 | + return acl_get_qualifier(entry_d); | |
2048 | +} | |
2049 | + | |
2050 | + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
2051 | +{ | |
2052 | + return acl_get_file((char *)path_p, type); | |
2053 | +} | |
2054 | + | |
2055 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
2056 | +{ | |
2057 | + return acl_get_fd(fd, ACL_TYPE_ACCESS); | |
2058 | +} | |
2059 | + | |
2060 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) | |
2061 | +{ | |
2062 | + *permset = 0; /* acl_clear_perm() is broken on Tru64 */ | |
2063 | + | |
2064 | + return 0; | |
2065 | +} | |
2066 | + | |
2067 | + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
2068 | +{ | |
2069 | + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) { | |
2070 | + errno = EINVAL; | |
2071 | + return -1; | |
2072 | + } | |
2073 | + | |
2074 | + *permset |= perm; /* acl_add_perm() is broken on Tru64 */ | |
2075 | + | |
2076 | + return 0; | |
2077 | +} | |
2078 | + | |
2079 | + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
2080 | +{ | |
2081 | + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */ | |
2082 | +} | |
2083 | + | |
2084 | + char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen) | |
2085 | +{ | |
2086 | + return acl_to_text(the_acl, plen); | |
2087 | +} | |
2088 | + | |
2089 | + SMB_ACL_T sys_acl_init(int count) | |
2090 | +{ | |
2091 | + return acl_init(count); | |
2092 | +} | |
2093 | + | |
2094 | + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
2095 | +{ | |
2096 | + SMB_ACL_ENTRY_T entry; | |
2097 | + | |
2098 | + if ((entry = acl_create_entry(pacl)) == NULL) { | |
2099 | + return -1; | |
2100 | + } | |
2101 | + | |
2102 | + *pentry = entry; | |
2103 | + return 0; | |
2104 | +} | |
2105 | + | |
2106 | + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
2107 | +{ | |
2108 | + return acl_set_tag_type(entry, tagtype); | |
2109 | +} | |
2110 | + | |
2111 | + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual) | |
2112 | +{ | |
2113 | + return acl_set_qualifier(entry, qual); | |
2114 | +} | |
2115 | + | |
2116 | + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
2117 | +{ | |
2118 | + return acl_set_permset(entry, permset); | |
2119 | +} | |
2120 | + | |
2121 | + int sys_acl_valid(SMB_ACL_T theacl) | |
2122 | +{ | |
2123 | + acl_entry_t entry; | |
2124 | + | |
2125 | + return acl_valid(theacl, &entry); | |
2126 | +} | |
2127 | + | |
2128 | + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
2129 | +{ | |
2130 | + return acl_set_file((char *)name, acltype, theacl); | |
2131 | +} | |
2132 | + | |
2133 | + int sys_acl_set_fd(int fd, SMB_ACL_T theacl) | |
2134 | +{ | |
2135 | + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); | |
2136 | +} | |
2137 | + | |
2138 | + int sys_acl_delete_def_file(const char *name) | |
2139 | +{ | |
2140 | + return acl_delete_def_file((char *)name); | |
2141 | +} | |
2142 | + | |
2143 | + int sys_acl_free_text(char *text) | |
2144 | +{ | |
2145 | + /* (void) cast and explicit return 0 are for DEC UNIX | |
2146 | + * which just #defines acl_free_text() to be free(). */ | |
2147 | + (void) acl_free_text(text); | |
2148 | + return 0; | |
2149 | +} | |
2150 | + | |
2151 | + int sys_acl_free_acl(SMB_ACL_T the_acl) | |
2152 | +{ | |
2153 | + return acl_free(the_acl); | |
2154 | +} | |
2155 | + | |
2156 | + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) | |
2157 | +{ | |
2158 | + return acl_free_qualifier(qual, tagtype); | |
2159 | +} | |
2160 | + | |
2161 | +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) | |
2162 | + | |
2163 | +/* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
2164 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */ | |
2165 | + | |
2166 | +/* Note that while this code implements sufficient functionality | |
2167 | + * to support the sys_acl_* interfaces it does not provide all | |
2168 | + * of the semantics of the POSIX ACL interfaces. | |
2169 | + * | |
2170 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
2171 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
2172 | + * valid after calling any of the following functions, which may | |
2173 | + * reorder the entries in the ACL. | |
2174 | + * | |
2175 | + * sys_acl_valid() | |
2176 | + * sys_acl_set_file() | |
2177 | + * sys_acl_set_fd() | |
2178 | + */ | |
2179 | + | |
2180 | +/* The only difference between Solaris and UnixWare / OpenUNIX is | |
2181 | + * that the #defines for the ACL operations have different names. */ | |
2182 | +#if defined(HAVE_UNIXWARE_ACLS) | |
2183 | + | |
2184 | +#define SETACL ACL_SET | |
2185 | +#define GETACL ACL_GET | |
2186 | +#define GETACLCNT ACL_CNT | |
2187 | + | |
2188 | +#endif | |
2189 | + | |
2190 | + | |
2191 | + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
2192 | +{ | |
2193 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
2194 | + errno = EINVAL; | |
2195 | + return -1; | |
2196 | + } | |
2197 | + | |
2198 | + if (entry_p == NULL) { | |
2199 | + errno = EINVAL; | |
2200 | + return -1; | |
2201 | + } | |
2202 | + | |
2203 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
2204 | + acl_d->next = 0; | |
2205 | + } | |
2206 | + | |
2207 | + if (acl_d->next < 0) { | |
2208 | + errno = EINVAL; | |
2209 | + return -1; | |
2210 | + } | |
2211 | + | |
2212 | + if (acl_d->next >= acl_d->count) { | |
2213 | + return 0; | |
2214 | + } | |
2215 | + | |
2216 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
2217 | + | |
2218 | + return 1; | |
2219 | +} | |
2220 | + | |
2221 | + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) | |
2222 | +{ | |
2223 | + *type_p = entry_d->a_type; | |
2224 | + | |
2225 | + return 0; | |
2226 | +} | |
2227 | + | |
2228 | + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) | |
2229 | +{ | |
2230 | + *permset_p = &entry_d->a_perm; | |
2231 | + | |
2232 | + return 0; | |
2233 | +} | |
2234 | + | |
2235 | + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
2236 | +{ | |
2237 | + if (entry_d->a_type != SMB_ACL_USER | |
2238 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
2239 | + errno = EINVAL; | |
2240 | + return NULL; | |
2241 | + } | |
2242 | + | |
2243 | + return &entry_d->a_id; | |
2244 | +} | |
2245 | + | |
2246 | +/* There is no way of knowing what size the ACL returned by | |
2247 | + * GETACL will be unless you first call GETACLCNT which means | |
2248 | + * making an additional system call. | |
2249 | + * | |
2250 | + * In the hope of avoiding the cost of the additional system | |
2251 | + * call in most cases, we initially allocate enough space for | |
2252 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
2253 | + * be too small then we use GETACLCNT to find out the actual | |
2254 | + * size, reallocate the ACL buffer, and then call GETACL again. */ | |
2255 | + | |
2256 | +#define INITIAL_ACL_SIZE 16 | |
2257 | + | |
2258 | + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
2259 | +{ | |
2260 | + SMB_ACL_T acl_d; | |
2261 | + int count; /* # of ACL entries allocated */ | |
2262 | + int naccess; /* # of access ACL entries */ | |
2263 | + int ndefault; /* # of default ACL entries */ | |
2264 | + | |
2265 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2266 | + errno = EINVAL; | |
2267 | + return NULL; | |
2268 | + } | |
2269 | + | |
2270 | + count = INITIAL_ACL_SIZE; | |
2271 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2272 | + return NULL; | |
2273 | + } | |
2274 | + | |
2275 | + /* If there isn't enough space for the ACL entries we use | |
2276 | + * GETACLCNT to determine the actual number of ACL entries | |
2277 | + * reallocate and try again. This is in a loop because it | |
2278 | + * is possible that someone else could modify the ACL and | |
2279 | + * increase the number of entries between the call to | |
2280 | + * GETACLCNT and the call to GETACL. */ | |
2281 | + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0 | |
2282 | + && errno == ENOSPC) { | |
2283 | + | |
2284 | + sys_acl_free_acl(acl_d); | |
2285 | + | |
2286 | + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) { | |
2287 | + return NULL; | |
2288 | + } | |
2289 | + | |
2290 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2291 | + return NULL; | |
2292 | + } | |
2293 | + } | |
2294 | + | |
2295 | + if (count < 0) { | |
2296 | + sys_acl_free_acl(acl_d); | |
2297 | + return NULL; | |
2298 | + } | |
2299 | + | |
2300 | + /* Calculate the number of access and default ACL entries. | |
2301 | + * | |
2302 | + * Note: we assume that the acl() system call returned a | |
2303 | + * well formed ACL which is sorted so that all of the | |
2304 | + * access ACL entries preceed any default ACL entries. */ | |
2305 | + for (naccess = 0; naccess < count; naccess++) { | |
2306 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2307 | + break; | |
2308 | + } | |
2309 | + ndefault = count - naccess; | |
2310 | + | |
2311 | + /* If the caller wants the default ACL we have to copy | |
2312 | + * the entries down to the start of the acl[] buffer | |
2313 | + * and mask out the ACL_DEFAULT flag from the type field. */ | |
2314 | + if (type == SMB_ACL_TYPE_DEFAULT) { | |
2315 | + int i, j; | |
2316 | + | |
2317 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
2318 | + acl_d->acl[i] = acl_d->acl[j]; | |
2319 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
2320 | + } | |
2321 | + | |
2322 | + acl_d->count = ndefault; | |
2323 | + } else { | |
2324 | + acl_d->count = naccess; | |
2325 | + } | |
2326 | + | |
2327 | + return acl_d; | |
2328 | +} | |
2329 | + | |
2330 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
2331 | +{ | |
2332 | + SMB_ACL_T acl_d; | |
2333 | + int count; /* # of ACL entries allocated */ | |
2334 | + int naccess; /* # of access ACL entries */ | |
2335 | + | |
2336 | + count = INITIAL_ACL_SIZE; | |
2337 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2338 | + return NULL; | |
2339 | + } | |
2340 | + | |
2341 | + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0 | |
2342 | + && errno == ENOSPC) { | |
2343 | + | |
2344 | + sys_acl_free_acl(acl_d); | |
2345 | + | |
2346 | + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) { | |
2347 | + return NULL; | |
2348 | + } | |
2349 | + | |
2350 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2351 | + return NULL; | |
2352 | + } | |
2353 | + } | |
2354 | + | |
2355 | + if (count < 0) { | |
2356 | + sys_acl_free_acl(acl_d); | |
2357 | + return NULL; | |
2358 | + } | |
2359 | + | |
2360 | + /* Calculate the number of access ACL entries. */ | |
2361 | + for (naccess = 0; naccess < count; naccess++) { | |
2362 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2363 | + break; | |
2364 | + } | |
2365 | + | |
2366 | + acl_d->count = naccess; | |
2367 | + | |
2368 | + return acl_d; | |
2369 | +} | |
2370 | + | |
2371 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) | |
2372 | +{ | |
2373 | + *permset_d = 0; | |
2374 | + | |
2375 | + return 0; | |
2376 | +} | |
2377 | + | |
2378 | + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) | |
2379 | +{ | |
2380 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
2381 | + && perm != SMB_ACL_EXECUTE) { | |
2382 | + errno = EINVAL; | |
2383 | + return -1; | |
2384 | + } | |
2385 | + | |
2386 | + if (permset_d == NULL) { | |
2387 | + errno = EINVAL; | |
2388 | + return -1; | |
2389 | + } | |
2390 | + | |
2391 | + *permset_d |= perm; | |
2392 | + | |
2393 | + return 0; | |
2394 | +} | |
2395 | + | |
2396 | + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) | |
2397 | +{ | |
2398 | + return *permset_d & perm; | |
2399 | +} | |
2400 | + | |
2401 | + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) | |
2402 | +{ | |
2403 | + int i; | |
2404 | + int len, maxlen; | |
2405 | + char *text; | |
2406 | + | |
2407 | + /* Use an initial estimate of 20 bytes per ACL entry | |
2408 | + * when allocating memory for the text representation | |
2409 | + * of the ACL. */ | |
2410 | + len = 0; | |
2411 | + maxlen = 20 * acl_d->count; | |
2412 | + if ((text = malloc(maxlen)) == NULL) { | |
2413 | + errno = ENOMEM; | |
2414 | + return NULL; | |
2415 | + } | |
2416 | + | |
2417 | + for (i = 0; i < acl_d->count; i++) { | |
2418 | + struct acl *ap = &acl_d->acl[i]; | |
2419 | + struct passwd *pw; | |
2420 | + struct group *gr; | |
2421 | + char tagbuf[12]; | |
2422 | + char idbuf[12]; | |
2423 | + char *tag; | |
2424 | + char *id = ""; | |
2425 | + char perms[4]; | |
2426 | + int nbytes; | |
2427 | + | |
2428 | + switch (ap->a_type) { | |
2429 | + /* For debugging purposes it's probably more | |
2430 | + * useful to dump unknown tag types rather | |
2431 | + * than just returning an error. */ | |
2432 | + default: | |
2433 | + snprintf(tagbuf, sizeof tagbuf - 1, "0x%x", | |
2434 | + ap->a_type); | |
2435 | + tag = tagbuf; | |
2436 | + snprintf(idbuf, sizeof idbuf - 1, "%ld", | |
2437 | + (long)ap->a_id); | |
2438 | + id = idbuf; | |
2439 | + break; | |
2440 | + | |
2441 | + case SMB_ACL_USER: | |
2442 | + if ((pw = getpwuid(ap->a_id)) == NULL) { | |
2443 | + snprintf(idbuf, sizeof idbuf - 1, "%ld", | |
2444 | + (long)ap->a_id); | |
2445 | + id = idbuf; | |
2446 | + } else { | |
2447 | + id = pw->pw_name; | |
2448 | + } | |
2449 | + case SMB_ACL_USER_OBJ: | |
2450 | + tag = "user"; | |
2451 | + break; | |
2452 | + | |
2453 | + case SMB_ACL_GROUP: | |
2454 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
2455 | + snprintf(idbuf, sizeof idbuf - 1, "%ld", | |
2456 | + (long)ap->a_id); | |
2457 | + id = idbuf; | |
2458 | + } else { | |
2459 | + id = gr->gr_name; | |
2460 | + } | |
2461 | + case SMB_ACL_GROUP_OBJ: | |
2462 | + tag = "group"; | |
2463 | + break; | |
2464 | + | |
2465 | + case SMB_ACL_OTHER: | |
2466 | + tag = "other"; | |
2467 | + break; | |
2468 | + | |
2469 | + case SMB_ACL_MASK: | |
2470 | + tag = "mask"; | |
2471 | + break; | |
2472 | + | |
2473 | + } | |
2474 | + | |
2475 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
2476 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
2477 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
2478 | + perms[3] = '\0'; | |
2479 | + | |
2480 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
2481 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
2482 | + | |
2483 | + /* If this entry would overflow the buffer | |
2484 | + * allocate enough additional memory for this | |
2485 | + * entry and an estimate of another 20 bytes | |
2486 | + * for each entry still to be processed. */ | |
2487 | + if ((len + nbytes) > maxlen) { | |
2488 | + char *oldtext = text; | |
2489 | + | |
2490 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
2491 | + | |
2492 | + if ((text = Realloc(oldtext, maxlen)) == NULL) { | |
2493 | + free(oldtext); | |
2494 | + errno = ENOMEM; | |
2495 | + return NULL; | |
2496 | + } | |
2497 | + } | |
2498 | + | |
2499 | + snprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); | |
2500 | + len += nbytes - 1; | |
2501 | + } | |
2502 | + | |
2503 | + if (len_p) | |
2504 | + *len_p = len; | |
2505 | + | |
2506 | + return text; | |
2507 | +} | |
2508 | + | |
2509 | + SMB_ACL_T sys_acl_init(int count) | |
2510 | +{ | |
2511 | + SMB_ACL_T a; | |
2512 | + | |
2513 | + if (count < 0) { | |
2514 | + errno = EINVAL; | |
2515 | + return NULL; | |
2516 | + } | |
2517 | + | |
2518 | + /* Note that since the definition of the structure pointed | |
2519 | + * to by the SMB_ACL_T includes the first element of the | |
2520 | + * acl[] array, this actually allocates an ACL with room | |
2521 | + * for (count+1) entries. */ | |
2522 | + if ((a = malloc(sizeof a[0] + count * sizeof (struct acl))) == NULL) { | |
2523 | + errno = ENOMEM; | |
2524 | + return NULL; | |
2525 | + } | |
2526 | + | |
2527 | + a->size = count + 1; | |
2528 | + a->count = 0; | |
2529 | + a->next = -1; | |
2530 | + | |
2531 | + return a; | |
2532 | +} | |
2533 | + | |
2534 | + | |
2535 | + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) | |
2536 | +{ | |
2537 | + SMB_ACL_T acl_d; | |
2538 | + SMB_ACL_ENTRY_T entry_d; | |
2539 | + | |
2540 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
2541 | + errno = EINVAL; | |
2542 | + return -1; | |
2543 | + } | |
2544 | + | |
2545 | + if (acl_d->count >= acl_d->size) { | |
2546 | + errno = ENOSPC; | |
2547 | + return -1; | |
2548 | + } | |
2549 | + | |
2550 | + entry_d = &acl_d->acl[acl_d->count++]; | |
2551 | + entry_d->a_type = 0; | |
2552 | + entry_d->a_id = -1; | |
2553 | + entry_d->a_perm = 0; | |
2554 | + *entry_p = entry_d; | |
2555 | + | |
2556 | + return 0; | |
2557 | +} | |
2558 | + | |
2559 | + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) | |
2560 | +{ | |
2561 | + switch (tag_type) { | |
2562 | + case SMB_ACL_USER: | |
2563 | + case SMB_ACL_USER_OBJ: | |
2564 | + case SMB_ACL_GROUP: | |
2565 | + case SMB_ACL_GROUP_OBJ: | |
2566 | + case SMB_ACL_OTHER: | |
2567 | + case SMB_ACL_MASK: | |
2568 | + entry_d->a_type = tag_type; | |
2569 | + break; | |
2570 | + default: | |
2571 | + errno = EINVAL; | |
2572 | + return -1; | |
2573 | + } | |
2574 | + | |
2575 | + return 0; | |
2576 | +} | |
2577 | + | |
2578 | + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) | |
2579 | +{ | |
2580 | + if (entry_d->a_type != SMB_ACL_GROUP | |
2581 | + && entry_d->a_type != SMB_ACL_USER) { | |
2582 | + errno = EINVAL; | |
2583 | + return -1; | |
2584 | + } | |
2585 | + | |
2586 | + entry_d->a_id = *((id_t *)qual_p); | |
2587 | + | |
2588 | + return 0; | |
2589 | +} | |
2590 | + | |
2591 | + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) | |
2592 | +{ | |
2593 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
2594 | + return EINVAL; | |
2595 | + } | |
2596 | + | |
2597 | + entry_d->a_perm = *permset_d; | |
2598 | + | |
2599 | + return 0; | |
2600 | +} | |
2601 | + | |
2602 | +/* Sort the ACL and check it for validity. | |
2603 | + * | |
2604 | + * If it's a minimal ACL with only 4 entries then we | |
2605 | + * need to recalculate the mask permissions to make | |
2606 | + * sure that they are the same as the GROUP_OBJ | |
2607 | + * permissions as required by the UnixWare acl() system call. | |
2608 | + * | |
2609 | + * (Note: since POSIX allows minimal ACLs which only contain | |
2610 | + * 3 entries - ie there is no mask entry - we should, in theory, | |
2611 | + * check for this and add a mask entry if necessary - however | |
2612 | + * we "know" that the caller of this interface always specifies | |
2613 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
2614 | + * happen aclsort() will fail and return an error and someone will | |
2615 | + * have to fix it ...) */ | |
2616 | + | |
2617 | +static int acl_sort(SMB_ACL_T acl_d) | |
2618 | +{ | |
2619 | + int fixmask = (acl_d->count <= 4); | |
2620 | + | |
2621 | + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
2622 | + errno = EINVAL; | |
2623 | + return -1; | |
2624 | + } | |
2625 | + return 0; | |
2626 | +} | |
2627 | + | |
2628 | + int sys_acl_valid(SMB_ACL_T acl_d) | |
2629 | +{ | |
2630 | + return acl_sort(acl_d); | |
2631 | +} | |
2632 | + | |
2633 | + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) | |
2634 | +{ | |
2635 | + struct stat s; | |
2636 | + struct acl *acl_p; | |
2637 | + int acl_count; | |
2638 | + struct acl *acl_buf = NULL; | |
2639 | + int ret; | |
2640 | + | |
2641 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2642 | + errno = EINVAL; | |
2643 | + return -1; | |
2644 | + } | |
2645 | + | |
2646 | + if (acl_sort(acl_d) != 0) { | |
2647 | + return -1; | |
2648 | + } | |
2649 | + | |
2650 | + acl_p = &acl_d->acl[0]; | |
2651 | + acl_count = acl_d->count; | |
2652 | + | |
2653 | + /* If it's a directory there is extra work to do since the acl() | |
2654 | + * system call will replace both the access ACLs and the default | |
2655 | + * ACLs (if any). */ | |
2656 | + if (stat(name, &s) != 0) { | |
2657 | + return -1; | |
2658 | + } | |
2659 | + if (S_ISDIR(s.st_mode)) { | |
2660 | + SMB_ACL_T acc_acl; | |
2661 | + SMB_ACL_T def_acl; | |
2662 | + SMB_ACL_T tmp_acl; | |
2663 | + int i; | |
2664 | + | |
2665 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
2666 | + acc_acl = acl_d; | |
2667 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
2668 | + | |
2669 | + } else { | |
2670 | + def_acl = acl_d; | |
2671 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
2672 | + } | |
2673 | + | |
2674 | + if (tmp_acl == NULL) { | |
2675 | + return -1; | |
2676 | + } | |
2677 | + | |
2678 | + /* Allocate a temporary buffer for the complete ACL. */ | |
2679 | + acl_count = acc_acl->count + def_acl->count; | |
2680 | + acl_p = acl_buf = malloc(acl_count * sizeof acl_buf[0]); | |
2681 | + | |
2682 | + if (acl_buf == NULL) { | |
2683 | + sys_acl_free_acl(tmp_acl); | |
2684 | + errno = ENOMEM; | |
2685 | + return -1; | |
2686 | + } | |
2687 | + | |
2688 | + /* Copy the access control and default entries into the buffer. */ | |
2689 | + memcpy(&acl_buf[0], &acc_acl->acl[0], | |
2690 | + acc_acl->count * sizeof acl_buf[0]); | |
2691 | + | |
2692 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
2693 | + def_acl->count * sizeof acl_buf[0]); | |
2694 | + | |
2695 | + /* Set the ACL_DEFAULT flag on the default entries. */ | |
2696 | + for (i = acc_acl->count; i < acl_count; i++) { | |
2697 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
2698 | + } | |
2699 | + | |
2700 | + sys_acl_free_acl(tmp_acl); | |
2701 | + | |
2702 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
2703 | + errno = EINVAL; | |
2704 | + return -1; | |
2705 | + } | |
2706 | + | |
2707 | + ret = acl(name, SETACL, acl_count, acl_p); | |
2708 | + | |
2709 | + free(acl_buf); | |
2710 | + | |
2711 | + return ret; | |
2712 | +} | |
2713 | + | |
2714 | + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) | |
2715 | +{ | |
2716 | + if (acl_sort(acl_d) != 0) { | |
2717 | + return -1; | |
2718 | + } | |
2719 | + | |
2720 | + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]); | |
2721 | +} | |
2722 | + | |
2723 | + int sys_acl_delete_def_file(const char *path) | |
2724 | +{ | |
2725 | + SMB_ACL_T acl_d; | |
2726 | + int ret; | |
2727 | + | |
2728 | + /* Fetching the access ACL and rewriting it has the effect of | |
2729 | + * deleting the default ACL. */ | |
2730 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { | |
2731 | + return -1; | |
2732 | + } | |
2733 | + | |
2734 | + ret = acl(path, SETACL, acl_d->count, acl_d->acl); | |
2735 | + | |
2736 | + sys_acl_free_acl(acl_d); | |
2737 | + | |
2738 | + return ret; | |
2739 | +} | |
2740 | + | |
2741 | + int sys_acl_free_text(char *text) | |
2742 | +{ | |
2743 | + free(text); | |
2744 | + return 0; | |
2745 | +} | |
2746 | + | |
2747 | + int sys_acl_free_acl(SMB_ACL_T acl_d) | |
2748 | +{ | |
2749 | + free(acl_d); | |
2750 | + return 0; | |
2751 | +} | |
2752 | + | |
2753 | + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) | |
2754 | +{ | |
2755 | + return 0; | |
2756 | +} | |
2757 | + | |
2758 | +#elif defined(HAVE_HPUX_ACLS) | |
2759 | +#include <dl.h> | |
2760 | + | |
2761 | +/* Based on the Solaris/SCO code - with modifications. */ | |
2762 | + | |
2763 | +/* Note that while this code implements sufficient functionality | |
2764 | + * to support the sys_acl_* interfaces it does not provide all | |
2765 | + * of the semantics of the POSIX ACL interfaces. | |
2766 | + * | |
2767 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
2768 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
2769 | + * valid after calling any of the following functions, which may | |
2770 | + * reorder the entries in the ACL. | |
2771 | + * | |
2772 | + * sys_acl_valid() | |
2773 | + * sys_acl_set_file() | |
2774 | + * sys_acl_set_fd() | |
2775 | + */ | |
2776 | + | |
2777 | +/* This checks if the POSIX ACL system call is defined which basically | |
2778 | + * corresponds to whether JFS 3.3 or higher is installed. If acl() was | |
2779 | + * called when it isn't defined, it causes the process to core dump so | |
2780 | + * it is important to check this and avoid acl() calls if it isn't | |
2781 | + * there. */ | |
2782 | + | |
2783 | +static BOOL hpux_acl_call_presence(void) | |
2784 | +{ | |
2785 | + | |
2786 | + shl_t handle = NULL; | |
2787 | + void *value; | |
2788 | + int ret_val=0; | |
2789 | + static BOOL already_checked=0; | |
2790 | + | |
2791 | + if (already_checked) | |
2792 | + return True; | |
2793 | + | |
2794 | + | |
2795 | + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value); | |
2796 | + | |
2797 | + if (ret_val != 0) { | |
2798 | + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n", | |
2799 | + ret_val, errno, strerror(errno))); | |
2800 | + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n")); | |
2801 | + return False; | |
2802 | + } | |
2803 | + | |
2804 | + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n")); | |
2805 | + | |
2806 | + already_checked = True; | |
2807 | + return True; | |
2808 | +} | |
2809 | + | |
2810 | + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
2811 | +{ | |
2812 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
2813 | + errno = EINVAL; | |
2814 | + return -1; | |
2815 | + } | |
2816 | + | |
2817 | + if (entry_p == NULL) { | |
2818 | + errno = EINVAL; | |
2819 | + return -1; | |
2820 | + } | |
2821 | + | |
2822 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
2823 | + acl_d->next = 0; | |
2824 | + } | |
2825 | + | |
2826 | + if (acl_d->next < 0) { | |
2827 | + errno = EINVAL; | |
2828 | + return -1; | |
2829 | + } | |
2830 | + | |
2831 | + if (acl_d->next >= acl_d->count) { | |
2832 | + return 0; | |
2833 | + } | |
2834 | + | |
2835 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
2836 | + | |
2837 | + return 1; | |
2838 | +} | |
2839 | + | |
2840 | + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) | |
2841 | +{ | |
2842 | + *type_p = entry_d->a_type; | |
2843 | + | |
2844 | + return 0; | |
2845 | +} | |
2846 | + | |
2847 | + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) | |
2848 | +{ | |
2849 | + *permset_p = &entry_d->a_perm; | |
2850 | + | |
2851 | + return 0; | |
2852 | +} | |
2853 | + | |
2854 | + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
2855 | +{ | |
2856 | + if (entry_d->a_type != SMB_ACL_USER | |
2857 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
2858 | + errno = EINVAL; | |
2859 | + return NULL; | |
2860 | + } | |
2861 | + | |
2862 | + return &entry_d->a_id; | |
2863 | +} | |
2864 | + | |
2865 | +/* There is no way of knowing what size the ACL returned by | |
2866 | + * ACL_GET will be unless you first call ACL_CNT which means | |
2867 | + * making an additional system call. | |
2868 | + * | |
2869 | + * In the hope of avoiding the cost of the additional system | |
2870 | + * call in most cases, we initially allocate enough space for | |
2871 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
2872 | + * be too small then we use ACL_CNT to find out the actual | |
2873 | + * size, reallocate the ACL buffer, and then call ACL_GET again. | |
2874 | + */ | |
2875 | + | |
2876 | +#define INITIAL_ACL_SIZE 16 | |
2877 | + | |
2878 | + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
2879 | +{ | |
2880 | + SMB_ACL_T acl_d; | |
2881 | + int count; /* # of ACL entries allocated */ | |
2882 | + int naccess; /* # of access ACL entries */ | |
2883 | + int ndefault; /* # of default ACL entries */ | |
2884 | + | |
2885 | + if (hpux_acl_call_presence() == False) { | |
2886 | + /* Looks like we don't have the acl() system call on HPUX. | |
2887 | + * May be the system doesn't have the latest version of JFS. */ | |
2888 | + return NULL; | |
2889 | + } | |
2890 | + | |
2891 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2892 | + errno = EINVAL; | |
2893 | + return NULL; | |
2894 | + } | |
2895 | + | |
2896 | + count = INITIAL_ACL_SIZE; | |
2897 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2898 | + return NULL; | |
2899 | + } | |
2900 | + | |
2901 | + /* If there isn't enough space for the ACL entries we use | |
2902 | + * ACL_CNT to determine the actual number of ACL entries | |
2903 | + * reallocate and try again. This is in a loop because it | |
2904 | + * is possible that someone else could modify the ACL and | |
2905 | + * increase the number of entries between the call to | |
2906 | + * ACL_CNT and the call to ACL_GET. */ | |
2907 | + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) { | |
2908 | + | |
2909 | + sys_acl_free_acl(acl_d); | |
2910 | + | |
2911 | + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) { | |
2912 | + return NULL; | |
2913 | + } | |
2914 | + | |
2915 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2916 | + return NULL; | |
2917 | + } | |
2918 | + } | |
2919 | + | |
2920 | + if (count < 0) { | |
2921 | + sys_acl_free_acl(acl_d); | |
2922 | + return NULL; | |
2923 | + } | |
2924 | + | |
2925 | + /* Calculate the number of access and default ACL entries. | |
2926 | + * | |
2927 | + * Note: we assume that the acl() system call returned a | |
2928 | + * well formed ACL which is sorted so that all of the | |
2929 | + * access ACL entries preceed any default ACL entries. */ | |
2930 | + for (naccess = 0; naccess < count; naccess++) { | |
2931 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2932 | + break; | |
2933 | + } | |
2934 | + ndefault = count - naccess; | |
2935 | + | |
2936 | + /* If the caller wants the default ACL we have to copy | |
2937 | + * the entries down to the start of the acl[] buffer | |
2938 | + * and mask out the ACL_DEFAULT flag from the type field. */ | |
2939 | + if (type == SMB_ACL_TYPE_DEFAULT) { | |
2940 | + int i, j; | |
2941 | + | |
2942 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
2943 | + acl_d->acl[i] = acl_d->acl[j]; | |
2944 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
2945 | + } | |
2946 | + | |
2947 | + acl_d->count = ndefault; | |
2948 | + } else { | |
2949 | + acl_d->count = naccess; | |
2950 | + } | |
2951 | + | |
2952 | + return acl_d; | |
2953 | +} | |
2954 | + | |
2955 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
2956 | +{ | |
2957 | + /* HPUX doesn't have the facl call. Fake it using the path.... JRA. */ | |
2958 | + | |
2959 | + files_struct *fsp = file_find_fd(fd); | |
2960 | + | |
2961 | + if (fsp == NULL) { | |
2962 | + errno = EBADF; | |
2963 | + return NULL; | |
2964 | + } | |
2965 | + | |
2966 | + /* We know we're in the same conn context. So we can use the | |
2967 | + * relative path. */ | |
2968 | + | |
2969 | + return sys_acl_get_file(dos_to_unix_static(fsp->fsp_name), SMB_ACL_TYPE_ACCESS); | |
2970 | +} | |
2971 | + | |
2972 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) | |
2973 | +{ | |
2974 | + *permset_d = 0; | |
2975 | + | |
2976 | + return 0; | |
2977 | +} | |
2978 | + | |
2979 | + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) | |
2980 | +{ | |
2981 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
2982 | + && perm != SMB_ACL_EXECUTE) { | |
2983 | + errno = EINVAL; | |
2984 | + return -1; | |
2985 | + } | |
2986 | + | |
2987 | + if (permset_d == NULL) { | |
2988 | + errno = EINVAL; | |
2989 | + return -1; | |
2990 | + } | |
2991 | + | |
2992 | + *permset_d |= perm; | |
2993 | + | |
2994 | + return 0; | |
2995 | +} | |
2996 | + | |
2997 | + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) | |
2998 | +{ | |
2999 | + return *permset_d & perm; | |
3000 | +} | |
3001 | + | |
3002 | + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) | |
3003 | +{ | |
3004 | + int i; | |
3005 | + int len, maxlen; | |
3006 | + char *text; | |
3007 | + | |
3008 | + /* Use an initial estimate of 20 bytes per ACL entry when | |
3009 | + * allocating memory for the text representation of the ACL. */ | |
3010 | + len = 0; | |
3011 | + maxlen = 20 * acl_d->count; | |
3012 | + if ((text = malloc(maxlen)) == NULL) { | |
3013 | + errno = ENOMEM; | |
3014 | + return NULL; | |
3015 | + } | |
3016 | + | |
3017 | + for (i = 0; i < acl_d->count; i++) { | |
3018 | + struct acl *ap = &acl_d->acl[i]; | |
3019 | + struct passwd *pw; | |
3020 | + struct group *gr; | |
3021 | + char tagbuf[12]; | |
3022 | + char idbuf[12]; | |
3023 | + char *tag; | |
3024 | + char *id = ""; | |
3025 | + char perms[4]; | |
3026 | + int nbytes; | |
3027 | + | |
3028 | + switch (ap->a_type) { | |
3029 | + /* For debugging purposes it's probably more | |
3030 | + * useful to dump unknown tag types rather | |
3031 | + * than just returning an error. */ | |
3032 | + default: | |
3033 | + snprintf(tagbuf, sizeof tagbuf - 1, "0x%x", | |
3034 | + ap->a_type); | |
3035 | + tag = tagbuf; | |
3036 | + snprintf(idbuf, sizeof idbuf - 1, "%ld", | |
3037 | + (long)ap->a_id); | |
3038 | + id = idbuf; | |
3039 | + break; | |
3040 | + | |
3041 | + case SMB_ACL_USER: | |
3042 | + if ((pw = getpwuid(ap->a_id)) == NULL) { | |
3043 | + snprintf(idbuf, sizeof idbuf - 1, "%ld", | |
3044 | + (long)ap->a_id); | |
3045 | + id = idbuf; | |
3046 | + } else { | |
3047 | + id = pw->pw_name; | |
3048 | + } | |
3049 | + case SMB_ACL_USER_OBJ: | |
3050 | + tag = "user"; | |
3051 | + break; | |
3052 | + | |
3053 | + case SMB_ACL_GROUP: | |
3054 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
3055 | + snprintf(idbuf, sizeof idbuf - 1, "%ld", | |
3056 | + (long)ap->a_id); | |
3057 | + id = idbuf; | |
3058 | + } else { | |
3059 | + id = gr->gr_name; | |
3060 | + } | |
3061 | + case SMB_ACL_GROUP_OBJ: | |
3062 | + tag = "group"; | |
3063 | + break; | |
3064 | + | |
3065 | + case SMB_ACL_OTHER: | |
3066 | + tag = "other"; | |
3067 | + break; | |
3068 | + | |
3069 | + case SMB_ACL_MASK: | |
3070 | + tag = "mask"; | |
3071 | + break; | |
3072 | + | |
3073 | + } | |
3074 | + | |
3075 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
3076 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
3077 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
3078 | + perms[3] = '\0'; | |
3079 | + | |
3080 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
3081 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
3082 | + | |
3083 | + /* If this entry would overflow the buffer | |
3084 | + * allocate enough additional memory for this | |
3085 | + * entry and an estimate of another 20 bytes | |
3086 | + * for each entry still to be processed. */ | |
3087 | + if ((len + nbytes) > maxlen) { | |
3088 | + char *oldtext = text; | |
3089 | + | |
3090 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
3091 | + | |
3092 | + if ((text = Realloc(oldtext, maxlen)) == NULL) { | |
3093 | + free(oldtext); | |
3094 | + errno = ENOMEM; | |
3095 | + return NULL; | |
3096 | + } | |
3097 | + } | |
3098 | + | |
3099 | + snprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); | |
3100 | + len += nbytes - 1; | |
3101 | + } | |
3102 | + | |
3103 | + if (len_p) | |
3104 | + *len_p = len; | |
3105 | + | |
3106 | + return text; | |
3107 | +} | |
3108 | + | |
3109 | + SMB_ACL_T sys_acl_init(int count) | |
3110 | +{ | |
3111 | + SMB_ACL_T a; | |
3112 | + | |
3113 | + if (count < 0) { | |
3114 | + errno = EINVAL; | |
3115 | + return NULL; | |
3116 | + } | |
3117 | + | |
3118 | + /* Note that since the definition of the structure pointed | |
3119 | + * to by the SMB_ACL_T includes the first element of the | |
3120 | + * acl[] array, this actually allocates an ACL with room | |
3121 | + * for (count+1) entries. */ | |
3122 | + if ((a = malloc(sizeof a[0] + count * sizeof (struct acl))) == NULL) { | |
3123 | + errno = ENOMEM; | |
3124 | + return NULL; | |
3125 | + } | |
3126 | + | |
3127 | + a->size = count + 1; | |
3128 | + a->count = 0; | |
3129 | + a->next = -1; | |
3130 | + | |
3131 | + return a; | |
3132 | +} | |
3133 | + | |
3134 | + | |
3135 | + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) | |
3136 | +{ | |
3137 | + SMB_ACL_T acl_d; | |
3138 | + SMB_ACL_ENTRY_T entry_d; | |
3139 | + | |
3140 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3141 | + errno = EINVAL; | |
3142 | + return -1; | |
3143 | + } | |
3144 | + | |
3145 | + if (acl_d->count >= acl_d->size) { | |
3146 | + errno = ENOSPC; | |
3147 | + return -1; | |
3148 | + } | |
3149 | + | |
3150 | + entry_d = &acl_d->acl[acl_d->count++]; | |
3151 | + entry_d->a_type = 0; | |
3152 | + entry_d->a_id = -1; | |
3153 | + entry_d->a_perm = 0; | |
3154 | + *entry_p = entry_d; | |
3155 | + | |
3156 | + return 0; | |
3157 | +} | |
3158 | + | |
3159 | + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) | |
3160 | +{ | |
3161 | + switch (tag_type) { | |
3162 | + case SMB_ACL_USER: | |
3163 | + case SMB_ACL_USER_OBJ: | |
3164 | + case SMB_ACL_GROUP: | |
3165 | + case SMB_ACL_GROUP_OBJ: | |
3166 | + case SMB_ACL_OTHER: | |
3167 | + case SMB_ACL_MASK: | |
3168 | + entry_d->a_type = tag_type; | |
3169 | + break; | |
3170 | + default: | |
3171 | + errno = EINVAL; | |
3172 | + return -1; | |
3173 | + } | |
3174 | + | |
3175 | + return 0; | |
3176 | +} | |
3177 | + | |
3178 | + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) | |
3179 | +{ | |
3180 | + if (entry_d->a_type != SMB_ACL_GROUP | |
3181 | + && entry_d->a_type != SMB_ACL_USER) { | |
3182 | + errno = EINVAL; | |
3183 | + return -1; | |
3184 | + } | |
3185 | + | |
3186 | + entry_d->a_id = *((id_t *)qual_p); | |
3187 | + | |
3188 | + return 0; | |
3189 | +} | |
3190 | + | |
3191 | + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) | |
3192 | +{ | |
3193 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3194 | + return EINVAL; | |
3195 | + } | |
3196 | + | |
3197 | + entry_d->a_perm = *permset_d; | |
3198 | + | |
3199 | + return 0; | |
3200 | +} | |
3201 | + | |
3202 | +/* Structure to capture the count for each type of ACE. */ | |
3203 | + | |
3204 | +struct hpux_acl_types { | |
3205 | + int n_user; | |
3206 | + int n_def_user; | |
3207 | + int n_user_obj; | |
3208 | + int n_def_user_obj; | |
3209 | + | |
3210 | + int n_group; | |
3211 | + int n_def_group; | |
3212 | + int n_group_obj; | |
3213 | + int n_def_group_obj; | |
3214 | + | |
3215 | + int n_other; | |
3216 | + int n_other_obj; | |
3217 | + int n_def_other_obj; | |
3218 | + | |
3219 | + int n_class_obj; | |
3220 | + int n_def_class_obj; | |
3221 | + | |
3222 | + int n_illegal_obj; | |
3223 | +}; | |
3224 | + | |
3225 | +/* count_obj: | |
3226 | + * Counts the different number of objects in a given array of ACL | |
3227 | + * structures. | |
3228 | + * Inputs: | |
3229 | + * | |
3230 | + * acl_count - Count of ACLs in the array of ACL strucutres. | |
3231 | + * aclp - Array of ACL structures. | |
3232 | + * acl_type_count - Pointer to acl_types structure. Should already be | |
3233 | + * allocated. | |
3234 | + * Output: | |
3235 | + * | |
3236 | + * acl_type_count - This structure is filled up with counts of various | |
3237 | + * acl types. | |
3238 | + */ | |
3239 | + | |
3240 | +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count) | |
3241 | +{ | |
3242 | + int i; | |
3243 | + | |
3244 | + memset(acl_type_count, 0, sizeof (struct hpux_acl_types)); | |
3245 | + | |
3246 | + for (i=0;i<acl_count;i++) { | |
3247 | + switch (aclp[i].a_type) { | |
3248 | + case USER: | |
3249 | + acl_type_count->n_user++; | |
3250 | + break; | |
3251 | + case USER_OBJ: | |
3252 | + acl_type_count->n_user_obj++; | |
3253 | + break; | |
3254 | + case DEF_USER_OBJ: | |
3255 | + acl_type_count->n_def_user_obj++; | |
3256 | + break; | |
3257 | + case GROUP: | |
3258 | + acl_type_count->n_group++; | |
3259 | + break; | |
3260 | + case GROUP_OBJ: | |
3261 | + acl_type_count->n_group_obj++; | |
3262 | + break; | |
3263 | + case DEF_GROUP_OBJ: | |
3264 | + acl_type_count->n_def_group_obj++; | |
3265 | + break; | |
3266 | + case OTHER_OBJ: | |
3267 | + acl_type_count->n_other_obj++; | |
3268 | + break; | |
3269 | + case DEF_OTHER_OBJ: | |
3270 | + acl_type_count->n_def_other_obj++; | |
3271 | + break; | |
3272 | + case CLASS_OBJ: | |
3273 | + acl_type_count->n_class_obj++; | |
3274 | + break; | |
3275 | + case DEF_CLASS_OBJ: | |
3276 | + acl_type_count->n_def_class_obj++; | |
3277 | + break; | |
3278 | + case DEF_USER: | |
3279 | + acl_type_count->n_def_user++; | |
3280 | + break; | |
3281 | + case DEF_GROUP: | |
3282 | + acl_type_count->n_def_group++; | |
3283 | + break; | |
3284 | + default: | |
3285 | + acl_type_count->n_illegal_obj++; | |
3286 | + break; | |
3287 | + } | |
3288 | + } | |
3289 | +} | |
3290 | + | |
3291 | +/* swap_acl_entries: Swaps two ACL entries. | |
3292 | + * | |
3293 | + * Inputs: aclp0, aclp1 - ACL entries to be swapped. | |
3294 | + */ | |
3295 | + | |
3296 | +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1) | |
3297 | +{ | |
3298 | + struct acl temp_acl; | |
3299 | + | |
3300 | + temp_acl.a_type = aclp0->a_type; | |
3301 | + temp_acl.a_id = aclp0->a_id; | |
3302 | + temp_acl.a_perm = aclp0->a_perm; | |
3303 | + | |
3304 | + aclp0->a_type = aclp1->a_type; | |
3305 | + aclp0->a_id = aclp1->a_id; | |
3306 | + aclp0->a_perm = aclp1->a_perm; | |
3307 | + | |
3308 | + aclp1->a_type = temp_acl.a_type; | |
3309 | + aclp1->a_id = temp_acl.a_id; | |
3310 | + aclp1->a_perm = temp_acl.a_perm; | |
3311 | +} | |
3312 | + | |
3313 | +/* prohibited_duplicate_type | |
3314 | + * Identifies if given ACL type can have duplicate entries or | |
3315 | + * not. | |
3316 | + * | |
3317 | + * Inputs: acl_type - ACL Type. | |
3318 | + * | |
3319 | + * Outputs: | |
3320 | + * | |
3321 | + * Return.. | |
3322 | + * | |
3323 | + * True - If the ACL type matches any of the prohibited types. | |
3324 | + * False - If the ACL type doesn't match any of the prohibited types. | |
3325 | + */ | |
3326 | + | |
3327 | +static BOOL hpux_prohibited_duplicate_type(int acl_type) | |
3328 | +{ | |
3329 | + switch (acl_type) { | |
3330 | + case USER: | |
3331 | + case GROUP: | |
3332 | + case DEF_USER: | |
3333 | + case DEF_GROUP: | |
3334 | + return True; | |
3335 | + } | |
3336 | + return False; | |
3337 | +} | |
3338 | + | |
3339 | +/* get_needed_class_perm | |
3340 | + * Returns the permissions of a ACL structure only if the ACL | |
3341 | + * type matches one of the pre-determined types for computing | |
3342 | + * CLASS_OBJ permissions. | |
3343 | + * | |
3344 | + * Inputs: aclp - Pointer to ACL structure. | |
3345 | + */ | |
3346 | + | |
3347 | +static int hpux_get_needed_class_perm(struct acl *aclp) | |
3348 | +{ | |
3349 | + switch (aclp->a_type) { | |
3350 | + case USER: | |
3351 | + case GROUP_OBJ: | |
3352 | + case GROUP: | |
3353 | + case DEF_USER_OBJ: | |
3354 | + case DEF_USER: | |
3355 | + case DEF_GROUP_OBJ: | |
3356 | + case DEF_GROUP: | |
3357 | + case DEF_CLASS_OBJ: | |
3358 | + case DEF_OTHER_OBJ: | |
3359 | + return aclp->a_perm; | |
3360 | + default: | |
3361 | + return 0; | |
3362 | + } | |
3363 | +} | |
3364 | + | |
3365 | +/* acl_sort for HPUX. | |
3366 | + * Sorts the array of ACL structures as per the description in | |
3367 | + * aclsort man page. Refer to aclsort man page for more details | |
3368 | + * | |
3369 | + * Inputs: | |
3370 | + * | |
3371 | + * acl_count - Count of ACLs in the array of ACL structures. | |
3372 | + * calclass - If this is not zero, then we compute the CLASS_OBJ | |
3373 | + * permissions. | |
3374 | + * aclp - Array of ACL structures. | |
3375 | + * | |
3376 | + * Outputs: | |
3377 | + * | |
3378 | + * aclp - Sorted array of ACL structures. | |
3379 | + * | |
3380 | + * Outputs: | |
3381 | + * | |
3382 | + * Returns 0 for success -1 for failure. Prints a message to the Samba | |
3383 | + * debug log in case of failure. | |
3384 | + */ | |
3385 | + | |
3386 | +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp) | |
3387 | +{ | |
3388 | +#if !defined(HAVE_HPUX_ACLSORT) | |
3389 | + /* The aclsort() system call is availabe on the latest HPUX General | |
3390 | + * Patch Bundles. So for HPUX, we developed our version of acl_sort | |
3391 | + * function. Because, we don't want to update to a new | |
3392 | + * HPUX GR bundle just for aclsort() call. */ | |
3393 | + | |
3394 | + struct hpux_acl_types acl_obj_count; | |
3395 | + int n_class_obj_perm = 0; | |
3396 | + int i, j; | |
3397 | + | |
3398 | + if (!acl_count) { | |
3399 | + DEBUG(10,("Zero acl count passed. Returning Success\n")); | |
3400 | + return 0; | |
3401 | + } | |
3402 | + | |
3403 | + if (aclp == NULL) { | |
3404 | + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n")); | |
3405 | + return -1; | |
3406 | + } | |
3407 | + | |
3408 | + /* Count different types of ACLs in the ACLs array */ | |
3409 | + | |
3410 | + hpux_count_obj(acl_count, aclp, &acl_obj_count); | |
3411 | + | |
3412 | + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ, | |
3413 | + * CLASS_OBJ and OTHER_OBJ | |
3414 | + */ | |
3415 | + | |
3416 | + if (acl_obj_count.n_user_obj != 1 | |
3417 | + || acl_obj_count.n_group_obj != 1 | |
3418 | + || acl_obj_count.n_class_obj != 1 | |
3419 | + || acl_obj_count.n_other_obj != 1) { | |
3420 | + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \ | |
3421 | +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n")); | |
3422 | + return -1; | |
3423 | + } | |
3424 | + | |
3425 | + /* If any of the default objects are present, there should be only | |
3426 | + * one of them each. | |
3427 | + */ | |
3428 | + | |
3429 | + if (acl_obj_count.n_def_user_obj > 1 || acl_obj_count.n_def_group_obj > 1 || | |
3430 | + acl_obj_count.n_def_other_obj > 1 || acl_obj_count.n_def_class_obj > 1) { | |
3431 | + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \ | |
3432 | +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n")); | |
3433 | + return -1; | |
3434 | + } | |
3435 | + | |
3436 | + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl | |
3437 | + * structures. | |
3438 | + * | |
3439 | + * Sorting crieteria - First sort by ACL type. If there are multiple entries of | |
3440 | + * same ACL type, sort by ACL id. | |
3441 | + * | |
3442 | + * I am using the trival kind of sorting method here because, performance isn't | |
3443 | + * really effected by the ACLs feature. More over there aren't going to be more | |
3444 | + * than 17 entries on HPUX. | |
3445 | + */ | |
3446 | + | |
3447 | + for (i=0; i<acl_count;i++) { | |
3448 | + for (j=i+1; j<acl_count; j++) { | |
3449 | + if (aclp[i].a_type > aclp[j].a_type) { | |
3450 | + /* ACL entries out of order, swap them */ | |
3451 | + | |
3452 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); | |
3453 | + | |
3454 | + } else if (aclp[i].a_type == aclp[j].a_type) { | |
3455 | + | |
3456 | + /* ACL entries of same type, sort by id */ | |
3457 | + | |
3458 | + if (aclp[i].a_id > aclp[j].a_id) { | |
3459 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); | |
3460 | + } else if (aclp[i].a_id == aclp[j].a_id) { | |
3461 | + /* We have a duplicate entry. */ | |
3462 | + if (hpux_prohibited_duplicate_type(aclp[i].a_type)) { | |
3463 | + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n", | |
3464 | + aclp[i].a_type, aclp[i].a_id)); | |
3465 | + return -1; | |
3466 | + } | |
3467 | + } | |
3468 | + | |
3469 | + } | |
3470 | + } | |
3471 | + } | |
3472 | + | |
3473 | + /* set the class obj permissions to the computed one. */ | |
3474 | + if (calclass) { | |
3475 | + int n_class_obj_index = -1; | |
3476 | + | |
3477 | + for (i=0;i<acl_count;i++) { | |
3478 | + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i)); | |
3479 | + | |
3480 | + if (aclp[i].a_type == CLASS_OBJ) | |
3481 | + n_class_obj_index = i; | |
3482 | + } | |
3483 | + aclp[n_class_obj_index].a_perm = n_class_obj_perm; | |
3484 | + } | |
3485 | + | |
3486 | + return 0; | |
3487 | +#else | |
3488 | + return aclsort(acl_count, calclass, aclp); | |
3489 | +#endif | |
3490 | +} | |
3491 | + | |
3492 | +/* Sort the ACL and check it for validity. | |
3493 | + * | |
3494 | + * If it's a minimal ACL with only 4 entries then we | |
3495 | + * need to recalculate the mask permissions to make | |
3496 | + * sure that they are the same as the GROUP_OBJ | |
3497 | + * permissions as required by the UnixWare acl() system call. | |
3498 | + * | |
3499 | + * (Note: since POSIX allows minimal ACLs which only contain | |
3500 | + * 3 entries - ie there is no mask entry - we should, in theory, | |
3501 | + * check for this and add a mask entry if necessary - however | |
3502 | + * we "know" that the caller of this interface always specifies | |
3503 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
3504 | + * happen aclsort() will fail and return an error and someone will | |
3505 | + * have to fix it ...) */ | |
3506 | + | |
3507 | +static int acl_sort(SMB_ACL_T acl_d) | |
3508 | +{ | |
3509 | + int fixmask = (acl_d->count <= 4); | |
3510 | + | |
3511 | + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
3512 | + errno = EINVAL; | |
3513 | + return -1; | |
3514 | + } | |
3515 | + return 0; | |
3516 | +} | |
3517 | + | |
3518 | + int sys_acl_valid(SMB_ACL_T acl_d) | |
3519 | +{ | |
3520 | + return acl_sort(acl_d); | |
3521 | +} | |
3522 | + | |
3523 | + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) | |
3524 | +{ | |
3525 | + struct stat s; | |
3526 | + struct acl *acl_p; | |
3527 | + int acl_count; | |
3528 | + struct acl *acl_buf = NULL; | |
3529 | + int ret; | |
3530 | + | |
3531 | + if (hpux_acl_call_presence() == False) { | |
3532 | + /* Looks like we don't have the acl() system call on HPUX. | |
3533 | + * May be the system doesn't have the latest version of JFS. */ | |
3534 | + errno = ENOSYS; | |
3535 | + return -1; | |
3536 | + } | |
3537 | + | |
3538 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
3539 | + errno = EINVAL; | |
3540 | + return -1; | |
3541 | + } | |
3542 | + | |
3543 | + if (acl_sort(acl_d) != 0) { | |
3544 | + return -1; | |
3545 | + } | |
3546 | + | |
3547 | + acl_p = &acl_d->acl[0]; | |
3548 | + acl_count = acl_d->count; | |
3549 | + | |
3550 | + /* If it's a directory there is extra work to do since the acl() | |
3551 | + * system call will replace both the access ACLs and the default | |
3552 | + * ACLs (if any). */ | |
3553 | + if (stat(name, &s) != 0) { | |
3554 | + return -1; | |
3555 | + } | |
3556 | + if (S_ISDIR(s.st_mode)) { | |
3557 | + SMB_ACL_T acc_acl; | |
3558 | + SMB_ACL_T def_acl; | |
3559 | + SMB_ACL_T tmp_acl; | |
3560 | + int i; | |
3561 | + | |
3562 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
3563 | + acc_acl = acl_d; | |
3564 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
3565 | + | |
3566 | + } else { | |
3567 | + def_acl = acl_d; | |
3568 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
3569 | + } | |
3570 | + | |
3571 | + if (tmp_acl == NULL) { | |
3572 | + return -1; | |
3573 | + } | |
3574 | + | |
3575 | + /* Allocate a temporary buffer for the complete ACL. */ | |
3576 | + acl_count = acc_acl->count + def_acl->count; | |
3577 | + acl_p = acl_buf = malloc(acl_count * sizeof acl_buf[0]); | |
3578 | + | |
3579 | + if (acl_buf == NULL) { | |
3580 | + sys_acl_free_acl(tmp_acl); | |
3581 | + errno = ENOMEM; | |
3582 | + return -1; | |
3583 | + } | |
3584 | + | |
3585 | + /* Copy the access control and default entries into the buffer. */ | |
3586 | + memcpy(&acl_buf[0], &acc_acl->acl[0], | |
3587 | + acc_acl->count * sizeof acl_buf[0]); | |
3588 | + | |
3589 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
3590 | + def_acl->count * sizeof acl_buf[0]); | |
3591 | + | |
3592 | + /* Set the ACL_DEFAULT flag on the default entries. */ | |
3593 | + for (i = acc_acl->count; i < acl_count; i++) { | |
3594 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
3595 | + } | |
3596 | + | |
3597 | + sys_acl_free_acl(tmp_acl); | |
3598 | + | |
3599 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
3600 | + errno = EINVAL; | |
3601 | + return -1; | |
3602 | + } | |
3603 | + | |
3604 | + ret = acl(name, ACL_SET, acl_count, acl_p); | |
3605 | + | |
3606 | + free(acl_buf); | |
3607 | + | |
3608 | + return ret; | |
3609 | +} | |
3610 | + | |
3611 | + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) | |
3612 | +{ | |
3613 | + /* HPUX doesn't have the facl call. Fake it using the path.... JRA. */ | |
3614 | + | |
3615 | + files_struct *fsp = file_find_fd(fd); | |
3616 | + | |
3617 | + if (fsp == NULL) { | |
3618 | + errno = EBADF; | |
3619 | + return NULL; | |
3620 | + } | |
3621 | + | |
3622 | + if (acl_sort(acl_d) != 0) { | |
3623 | + return -1; | |
3624 | + } | |
3625 | + | |
3626 | + /* We know we're in the same conn context. So we can use the | |
3627 | + * relative path. */ | |
3628 | + | |
3629 | + return sys_acl_set_file(dos_to_unix_static(fsp->fsp_name), SMB_ACL_TYPE_ACCESS, acl_d); | |
3630 | +} | |
3631 | + | |
3632 | + int sys_acl_delete_def_file(const char *path) | |
3633 | +{ | |
3634 | + SMB_ACL_T acl_d; | |
3635 | + int ret; | |
3636 | + | |
3637 | + /* Fetching the access ACL and rewriting it has the effect of | |
3638 | + * deleting the default ACL. */ | |
3639 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { | |
3640 | + return -1; | |
3641 | + } | |
3642 | + | |
3643 | + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl); | |
3644 | + | |
3645 | + sys_acl_free_acl(acl_d); | |
3646 | + | |
3647 | + return ret; | |
3648 | +} | |
3649 | + | |
3650 | + int sys_acl_free_text(char *text) | |
3651 | +{ | |
3652 | + free(text); | |
3653 | + return 0; | |
3654 | +} | |
3655 | + | |
3656 | + int sys_acl_free_acl(SMB_ACL_T acl_d) | |
3657 | +{ | |
3658 | + free(acl_d); | |
3659 | + return 0; | |
3660 | +} | |
3661 | + | |
3662 | + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) | |
3663 | +{ | |
3664 | + return 0; | |
3665 | +} | |
3666 | + | |
3667 | +#elif defined(HAVE_IRIX_ACLS) | |
3668 | + | |
3669 | + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
3670 | +{ | |
3671 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
3672 | + errno = EINVAL; | |
3673 | + return -1; | |
3674 | + } | |
3675 | + | |
3676 | + if (entry_p == NULL) { | |
3677 | + errno = EINVAL; | |
3678 | + return -1; | |
3679 | + } | |
3680 | + | |
3681 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
3682 | + acl_d->next = 0; | |
3683 | + } | |
3684 | + | |
3685 | + if (acl_d->next < 0) { | |
3686 | + errno = EINVAL; | |
3687 | + return -1; | |
3688 | + } | |
3689 | + | |
3690 | + if (acl_d->next >= acl_d->aclp->acl_cnt) { | |
3691 | + return 0; | |
3692 | + } | |
3693 | + | |
3694 | + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++]; | |
3695 | + | |
3696 | + return 1; | |
3697 | +} | |
3698 | + | |
3699 | + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) | |
3700 | +{ | |
3701 | + *type_p = entry_d->ae_tag; | |
3702 | + | |
3703 | + return 0; | |
3704 | +} | |
3705 | + | |
3706 | + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) | |
3707 | +{ | |
3708 | + *permset_p = entry_d; | |
3709 | + | |
3710 | + return 0; | |
3711 | +} | |
3712 | + | |
3713 | + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
3714 | +{ | |
3715 | + if (entry_d->ae_tag != SMB_ACL_USER | |
3716 | + && entry_d->ae_tag != SMB_ACL_GROUP) { | |
3717 | + errno = EINVAL; | |
3718 | + return NULL; | |
3719 | + } | |
3720 | + | |
3721 | + return &entry_d->ae_id; | |
3722 | +} | |
3723 | + | |
3724 | + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
3725 | +{ | |
3726 | + SMB_ACL_T a; | |
3727 | + | |
3728 | + if ((a = malloc(sizeof a[0])) == NULL) { | |
3729 | + errno = ENOMEM; | |
3730 | + return NULL; | |
3731 | + } | |
3732 | + if ((a->aclp = acl_get_file(path_p, type)) == NULL) { | |
3733 | + free(a); | |
3734 | + return NULL; | |
3735 | + } | |
3736 | + a->next = -1; | |
3737 | + a->freeaclp = True; | |
3738 | + return a; | |
3739 | +} | |
3740 | + | |
3741 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
3742 | +{ | |
3743 | + SMB_ACL_T a; | |
3744 | + | |
3745 | + if ((a = malloc(sizeof a[0])) == NULL) { | |
3746 | + errno = ENOMEM; | |
3747 | + return NULL; | |
3748 | + } | |
3749 | + if ((a->aclp = acl_get_fd(fd)) == NULL) { | |
3750 | + free(a); | |
3751 | + return NULL; | |
3752 | + } | |
3753 | + a->next = -1; | |
3754 | + a->freeaclp = True; | |
3755 | + return a; | |
3756 | +} | |
3757 | + | |
3758 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) | |
3759 | +{ | |
3760 | + permset_d->ae_perm = 0; | |
3761 | + | |
3762 | + return 0; | |
3763 | +} | |
3764 | + | |
3765 | + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) | |
3766 | +{ | |
3767 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
3768 | + && perm != SMB_ACL_EXECUTE) { | |
3769 | + errno = EINVAL; | |
3770 | + return -1; | |
3771 | + } | |
3772 | + | |
3773 | + if (permset_d == NULL) { | |
3774 | + errno = EINVAL; | |
3775 | + return -1; | |
3776 | + } | |
3777 | + | |
3778 | + permset_d->ae_perm |= perm; | |
3779 | + | |
3780 | + return 0; | |
3781 | +} | |
3782 | + | |
3783 | + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) | |
3784 | +{ | |
3785 | + return permset_d->ae_perm & perm; | |
3786 | +} | |
3787 | + | |
3788 | + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) | |
3789 | +{ | |
3790 | + return acl_to_text(acl_d->aclp, len_p); | |
3791 | +} | |
3792 | + | |
3793 | + SMB_ACL_T sys_acl_init(int count) | |
3794 | +{ | |
3795 | + SMB_ACL_T a; | |
3796 | + | |
3797 | + if (count < 0) { | |
3798 | + errno = EINVAL; | |
3799 | + return NULL; | |
3800 | + } | |
3801 | + | |
3802 | + if ((a = malloc(sizeof a[0] + sizeof (struct acl))) == NULL) { | |
3803 | + errno = ENOMEM; | |
3804 | + return NULL; | |
3805 | + } | |
3806 | + | |
3807 | + a->next = -1; | |
3808 | + a->freeaclp = False; | |
3809 | + a->aclp = (struct acl *)(&a->aclp + sizeof (struct acl *)); | |
3810 | + a->aclp->acl_cnt = 0; | |
3811 | + | |
3812 | + return a; | |
3813 | +} | |
3814 | + | |
3815 | + | |
3816 | + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) | |
3817 | +{ | |
3818 | + SMB_ACL_T acl_d; | |
3819 | + SMB_ACL_ENTRY_T entry_d; | |
3820 | + | |
3821 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3822 | + errno = EINVAL; | |
3823 | + return -1; | |
3824 | + } | |
3825 | + | |
3826 | + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) { | |
3827 | + errno = ENOSPC; | |
3828 | + return -1; | |
3829 | + } | |
3830 | + | |
3831 | + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++]; | |
3832 | + entry_d->ae_tag = 0; | |
3833 | + entry_d->ae_id = 0; | |
3834 | + entry_d->ae_perm = 0; | |
3835 | + *entry_p = entry_d; | |
3836 | + | |
3837 | + return 0; | |
3838 | +} | |
3839 | + | |
3840 | + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) | |
3841 | +{ | |
3842 | + switch (tag_type) { | |
3843 | + case SMB_ACL_USER: | |
3844 | + case SMB_ACL_USER_OBJ: | |
3845 | + case SMB_ACL_GROUP: | |
3846 | + case SMB_ACL_GROUP_OBJ: | |
3847 | + case SMB_ACL_OTHER: | |
3848 | + case SMB_ACL_MASK: | |
3849 | + entry_d->ae_tag = tag_type; | |
3850 | + break; | |
3851 | + default: | |
3852 | + errno = EINVAL; | |
3853 | + return -1; | |
3854 | + } | |
3855 | + | |
3856 | + return 0; | |
3857 | +} | |
3858 | + | |
3859 | + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) | |
3860 | +{ | |
3861 | + if (entry_d->ae_tag != SMB_ACL_GROUP | |
3862 | + && entry_d->ae_tag != SMB_ACL_USER) { | |
3863 | + errno = EINVAL; | |
3864 | + return -1; | |
3865 | + } | |
3866 | + | |
3867 | + entry_d->ae_id = *((id_t *)qual_p); | |
3868 | + | |
3869 | + return 0; | |
3870 | +} | |
3871 | + | |
3872 | + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) | |
3873 | +{ | |
3874 | + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3875 | + return EINVAL; | |
3876 | + } | |
3877 | + | |
3878 | + entry_d->ae_perm = permset_d->ae_perm; | |
3879 | + | |
3880 | + return 0; | |
3881 | +} | |
3882 | + | |
3883 | + int sys_acl_valid(SMB_ACL_T acl_d) | |
3884 | +{ | |
3885 | + return acl_valid(acl_d->aclp); | |
3886 | +} | |
3887 | + | |
3888 | + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) | |
3889 | +{ | |
3890 | + return acl_set_file(name, type, acl_d->aclp); | |
3891 | +} | |
3892 | + | |
3893 | + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) | |
3894 | +{ | |
3895 | + return acl_set_fd(fd, acl_d->aclp); | |
3896 | +} | |
3897 | + | |
3898 | + int sys_acl_delete_def_file(const char *name) | |
3899 | +{ | |
3900 | + return acl_delete_def_file(name); | |
3901 | +} | |
3902 | + | |
3903 | + int sys_acl_free_text(char *text) | |
3904 | +{ | |
3905 | + return acl_free(text); | |
3906 | +} | |
3907 | + | |
3908 | + int sys_acl_free_acl(SMB_ACL_T acl_d) | |
3909 | +{ | |
3910 | + if (acl_d->freeaclp) { | |
3911 | + acl_free(acl_d->aclp); | |
3912 | + } | |
3913 | + acl_free(acl_d); | |
3914 | + return 0; | |
3915 | +} | |
3916 | + | |
3917 | + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) | |
3918 | +{ | |
3919 | + return 0; | |
3920 | +} | |
3921 | + | |
3922 | +#elif defined(HAVE_AIX_ACLS) | |
3923 | + | |
3924 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
3925 | + | |
3926 | + int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
3927 | +{ | |
3928 | + struct acl_entry_link *link; | |
3929 | + struct new_acl_entry *entry; | |
3930 | + int keep_going; | |
3931 | + | |
3932 | + DEBUG(10,("This is the count: %d\n",theacl->count)); | |
3933 | + | |
3934 | + /* Check if count was previously set to -1. If it was, that | |
3935 | + * means we reached the end of the acl last time. */ | |
3936 | + if (theacl->count == -1) | |
3937 | + return 0; | |
3938 | + | |
3939 | + link = theacl; | |
3940 | + /* To get to the next acl, traverse linked list until index of | |
3941 | + * acl matches the count we are keeping. This count is | |
3942 | + * incremented each time we return an acl entry. */ | |
3943 | + | |
3944 | + for (keep_going = 0; keep_going < theacl->count; keep_going++) | |
3945 | + link = link->nextp; | |
3946 | + | |
3947 | + entry = *entry_p = link->entryp; | |
3948 | + | |
3949 | + DEBUG(10,("*entry_p is %d\n",entry_p)); | |
3950 | + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access)); | |
3951 | + | |
3952 | + /* Increment count */ | |
3953 | + theacl->count++; | |
3954 | + if (link->nextp == NULL) | |
3955 | + theacl->count = -1; | |
3956 | + | |
3957 | + return 1; | |
3958 | +} | |
3959 | + | |
3960 | + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
3961 | +{ | |
3962 | + /* Initialize tag type */ | |
3963 | + | |
3964 | + *tag_type_p = -1; | |
3965 | + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type)); | |
3966 | + | |
3967 | + /* Depending on what type of entry we have, return tag type. */ | |
3968 | + switch (entry_d->ace_id->id_type) { | |
3969 | + case ACEID_USER: | |
3970 | + *tag_type_p = SMB_ACL_USER; | |
3971 | + break; | |
3972 | + case ACEID_GROUP: | |
3973 | + *tag_type_p = SMB_ACL_GROUP; | |
3974 | + break; | |
3975 | + | |
3976 | + case SMB_ACL_USER_OBJ: | |
3977 | + case SMB_ACL_GROUP_OBJ: | |
3978 | + case SMB_ACL_OTHER: | |
3979 | + *tag_type_p = entry_d->ace_id->id_type; | |
3980 | + break; | |
3981 | + | |
3982 | + default: | |
3983 | + return -1; | |
3984 | + } | |
3985 | + | |
3986 | + return 0; | |
3987 | +} | |
3988 | + | |
3989 | + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) | |
3990 | +{ | |
3991 | + DEBUG(10,("Starting AIX sys_acl_get_permset\n")); | |
3992 | + *permset_p = &entry_d->ace_access; | |
3993 | + DEBUG(10,("**permset_p is %d\n",**permset_p)); | |
3994 | + if (!(**permset_p & S_IXUSR) | |
3995 | + && !(**permset_p & S_IWUSR) | |
3996 | + && !(**permset_p & S_IRUSR) | |
3997 | + && **permset_p != 0) | |
3998 | + return -1; | |
3999 | + | |
4000 | + DEBUG(10,("Ending AIX sys_acl_get_permset\n")); | |
4001 | + return 0; | |
4002 | +} | |
4003 | + | |
4004 | + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) | |
4005 | +{ | |
4006 | + return entry_d->ace_id->id_data; | |
4007 | +} | |
4008 | + | |
4009 | + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) | |
4010 | +{ | |
4011 | + struct acl *file_acl = (struct acl *)NULL; | |
4012 | + struct acl_entry *acl_entry; | |
4013 | + struct new_acl_entry *new_acl_entry; | |
4014 | + struct ace_id *idp; | |
4015 | + struct acl_entry_link *acl_entry_link; | |
4016 | + struct acl_entry_link *acl_entry_link_head; | |
4017 | + int i; | |
4018 | + int rc = 0; | |
4019 | + uid_t user_id; | |
4020 | + | |
4021 | + /* Get the acl using statacl */ | |
4022 | + | |
4023 | + DEBUG(10,("Entering sys_acl_get_file\n")); | |
4024 | + DEBUG(10,("path_p is %s\n",path_p)); | |
4025 | + | |
4026 | + file_acl = (struct acl *)malloc(BUFSIZ); | |
4027 | + | |
4028 | + if (file_acl == NULL) { | |
4029 | + errno=ENOMEM; | |
4030 | + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno)); | |
4031 | + return NULL; | |
4032 | + } | |
4033 | + | |
4034 | + memset(file_acl,0,BUFSIZ); | |
4035 | + | |
4036 | + rc = statacl((char *)path_p,0,file_acl,BUFSIZ); | |
4037 | + if (rc == -1) { | |
4038 | + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno)); | |
4039 | + free(file_acl); | |
4040 | + return NULL; | |
4041 | + } | |
4042 | + | |
4043 | + DEBUG(10,("Got facl and returned it\n")); | |
4044 | + | |
4045 | + /* Point to the first acl entry in the acl */ | |
4046 | + acl_entry = file_acl->acl_ext; | |
4047 | + | |
4048 | + /* Begin setting up the head of the linked list that will be | |
4049 | + * used for the storing the acl in a way that is useful for the | |
4050 | + * posix_acls.c code. */ | |
4051 | + | |
4052 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
4053 | + if (acl_entry_link_head == NULL) | |
4054 | + return NULL; | |
4055 | + | |
4056 | + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4057 | + if (acl_entry_link->entryp == NULL) { | |
4058 | + free(file_acl); | |
4059 | + errno = ENOMEM; | |
4060 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
4061 | + return NULL; | |
4062 | + } | |
4063 | + | |
4064 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4065 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
4066 | + | |
4067 | + /* Check if the extended acl bit is on. If it isn't, do not | |
4068 | + * show the contents of the acl since AIX intends the extended | |
4069 | + * info to remain unused. */ | |
4070 | + | |
4071 | + if (file_acl->acl_mode & S_IXACL){ | |
4072 | + /* while we are not pointing to the very end */ | |
4073 | + while (acl_entry < acl_last(file_acl)) { | |
4074 | + /* before we malloc anything, make sure this is */ | |
4075 | + /* a valid acl entry and one that we want to map */ | |
4076 | + idp = id_nxt(acl_entry->ace_id); | |
4077 | + if ((acl_entry->ace_type == ACC_SPECIFY | |
4078 | + || acl_entry->ace_type == ACC_PERMIT) | |
4079 | + && idp != id_last(acl_entry)) { | |
4080 | + acl_entry = acl_nxt(acl_entry); | |
4081 | + continue; | |
4082 | + } | |
4083 | + | |
4084 | + idp = acl_entry->ace_id; | |
4085 | + | |
4086 | + /* Check if this is the first entry in the linked list. | |
4087 | + * The first entry needs to keep prevp pointing to NULL | |
4088 | + * and already has entryp allocated. */ | |
4089 | + | |
4090 | + if (acl_entry_link_head->count != 0) { | |
4091 | + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link)); | |
4092 | + | |
4093 | + if (acl_entry_link->nextp == NULL) { | |
4094 | + free(file_acl); | |
4095 | + errno = ENOMEM; | |
4096 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
4097 | + return NULL; | |
4098 | + } | |
4099 | + | |
4100 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4101 | + acl_entry_link = acl_entry_link->nextp; | |
4102 | + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4103 | + if (acl_entry_link->entryp == NULL) { | |
4104 | + free(file_acl); | |
4105 | + errno = ENOMEM; | |
4106 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
4107 | + return NULL; | |
4108 | + } | |
4109 | + acl_entry_link->nextp = NULL; | |
4110 | + } | |
4111 | + | |
4112 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
4113 | + | |
4114 | + /* Don't really need this since all types are going | |
4115 | + * to be specified but, it's better than leaving it 0. */ | |
4116 | + | |
4117 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
4118 | + | |
4119 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4120 | + | |
4121 | + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof (struct ace_id)); | |
4122 | + | |
4123 | + /* The access in the acl entries must be left shifted by | |
4124 | + * three bites, because they will ultimately be compared | |
4125 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
4126 | + | |
4127 | + switch (acl_entry->ace_type){ | |
4128 | + case ACC_PERMIT: | |
4129 | + case ACC_SPECIFY: | |
4130 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4131 | + acl_entry_link->entryp->ace_access <<= 6; | |
4132 | + acl_entry_link_head->count++; | |
4133 | + break; | |
4134 | + case ACC_DENY: | |
4135 | + /* Since there is no way to return a DENY acl entry | |
4136 | + * change to PERMIT and then shift. */ | |
4137 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); | |
4138 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
4139 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
4140 | + acl_entry_link->entryp->ace_access <<= 6; | |
4141 | + acl_entry_link_head->count++; | |
4142 | + break; | |
4143 | + default: | |
4144 | + return 0; | |
4145 | + } | |
4146 | + | |
4147 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
4148 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
4149 | + | |
4150 | + acl_entry = acl_nxt(acl_entry); | |
4151 | + } | |
4152 | + } /* end of if enabled */ | |
4153 | + | |
4154 | + /* Since owner, group, other acl entries are not part of the acl | |
4155 | + * entries in an acl, they must be dummied up to become part of | |
4156 | + * the list. */ | |
4157 | + | |
4158 | + for (i = 1; i < 4; i++) { | |
4159 | + DEBUG(10,("i is %d\n",i)); | |
4160 | + if (acl_entry_link_head->count != 0) { | |
4161 | + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link)); | |
4162 | + if (acl_entry_link->nextp == NULL) { | |
4163 | + free(file_acl); | |
4164 | + errno = ENOMEM; | |
4165 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
4166 | + return NULL; | |
4167 | + } | |
4168 | + | |
4169 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4170 | + acl_entry_link = acl_entry_link->nextp; | |
4171 | + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4172 | + if (acl_entry_link->entryp == NULL) { | |
4173 | + free(file_acl); | |
4174 | + errno = ENOMEM; | |
4175 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
4176 | + return NULL; | |
4177 | + } | |
4178 | + } | |
4179 | + | |
4180 | + acl_entry_link->nextp = NULL; | |
4181 | + | |
4182 | + new_acl_entry = acl_entry_link->entryp; | |
4183 | + idp = new_acl_entry->ace_id; | |
4184 | + | |
4185 | + new_acl_entry->ace_len = sizeof (struct acl_entry); | |
4186 | + new_acl_entry->ace_type = ACC_PERMIT; | |
4187 | + idp->id_len = sizeof (struct ace_id); | |
4188 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); | |
4189 | + memset(idp->id_data,0,sizeof (uid_t)); | |
4190 | + | |
4191 | + switch (i) { | |
4192 | + case 2: | |
4193 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4194 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4195 | + break; | |
4196 | + | |
4197 | + case 3: | |
4198 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4199 | + idp->id_type = SMB_ACL_OTHER; | |
4200 | + break; | |
4201 | + | |
4202 | + case 1: | |
4203 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4204 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4205 | + break; | |
4206 | + | |
4207 | + default: | |
4208 | + return NULL; | |
4209 | + | |
4210 | + } | |
4211 | + | |
4212 | + acl_entry_link_head->count++; | |
4213 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4214 | + } | |
4215 | + | |
4216 | + acl_entry_link_head->count = 0; | |
4217 | + free(file_acl); | |
4218 | + | |
4219 | + return acl_entry_link_head; | |
4220 | +} | |
4221 | + | |
4222 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
4223 | +{ | |
4224 | + struct acl *file_acl = (struct acl *)NULL; | |
4225 | + struct acl_entry *acl_entry; | |
4226 | + struct new_acl_entry *new_acl_entry; | |
4227 | + struct ace_id *idp; | |
4228 | + struct acl_entry_link *acl_entry_link; | |
4229 | + struct acl_entry_link *acl_entry_link_head; | |
4230 | + int i; | |
4231 | + int rc = 0; | |
4232 | + uid_t user_id; | |
4233 | + | |
4234 | + /* Get the acl using fstatacl */ | |
4235 | + | |
4236 | + DEBUG(10,("Entering sys_acl_get_fd\n")); | |
4237 | + DEBUG(10,("fd is %d\n",fd)); | |
4238 | + file_acl = (struct acl *)malloc(BUFSIZ); | |
4239 | + | |
4240 | + if (file_acl == NULL) { | |
4241 | + errno=ENOMEM; | |
4242 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
4243 | + return NULL; | |
4244 | + } | |
4245 | + | |
4246 | + memset(file_acl,0,BUFSIZ); | |
4247 | + | |
4248 | + rc = fstatacl(fd,0,file_acl,BUFSIZ); | |
4249 | + if (rc == -1) { | |
4250 | + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno)); | |
4251 | + free(file_acl); | |
4252 | + return NULL; | |
4253 | + } | |
4254 | + | |
4255 | + DEBUG(10,("Got facl and returned it\n")); | |
4256 | + | |
4257 | + /* Point to the first acl entry in the acl */ | |
4258 | + | |
4259 | + acl_entry = file_acl->acl_ext; | |
4260 | + | |
4261 | + /* Begin setting up the head of the linked list that will be | |
4262 | + * used for the storing the acl in a way that is useful for the | |
4263 | + * posix_acls.c code. */ | |
4264 | + | |
4265 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
4266 | + if (acl_entry_link_head == NULL){ | |
4267 | + free(file_acl); | |
4268 | + return NULL; | |
4269 | + } | |
4270 | + | |
4271 | + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4272 | + | |
4273 | + if (acl_entry_link->entryp == NULL) { | |
4274 | + errno = ENOMEM; | |
4275 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
4276 | + free(file_acl); | |
4277 | + return NULL; | |
4278 | + } | |
4279 | + | |
4280 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4281 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
4282 | + | |
4283 | + /* Check if the extended acl bit is on. If it isn't, do not | |
4284 | + * show the contents of the acl since AIX intends the extended | |
4285 | + * info to remain unused. */ | |
4286 | + | |
4287 | + if (file_acl->acl_mode & S_IXACL){ | |
4288 | + /* while we are not pointing to the very end */ | |
4289 | + while (acl_entry < acl_last(file_acl)) { | |
4290 | + /* before we malloc anything, make sure this is */ | |
4291 | + /* a valid acl entry and one that we want to map */ | |
4292 | + | |
4293 | + idp = id_nxt(acl_entry->ace_id); | |
4294 | + if ((acl_entry->ace_type == ACC_SPECIFY | |
4295 | + || acl_entry->ace_type == ACC_PERMIT) | |
4296 | + && (idp != id_last(acl_entry))) { | |
4297 | + acl_entry = acl_nxt(acl_entry); | |
4298 | + continue; | |
4299 | + } | |
4300 | + | |
4301 | + idp = acl_entry->ace_id; | |
4302 | + | |
4303 | + /* Check if this is the first entry in the linked list. | |
4304 | + * The first entry needs to keep prevp pointing to NULL | |
4305 | + * and already has entryp allocated. */ | |
4306 | + | |
4307 | + if (acl_entry_link_head->count != 0) { | |
4308 | + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link)); | |
4309 | + if (acl_entry_link->nextp == NULL) { | |
4310 | + errno = ENOMEM; | |
4311 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
4312 | + free(file_acl); | |
4313 | + return NULL; | |
4314 | + } | |
4315 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4316 | + acl_entry_link = acl_entry_link->nextp; | |
4317 | + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4318 | + if (acl_entry_link->entryp == NULL) { | |
4319 | + errno = ENOMEM; | |
4320 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
4321 | + free(file_acl); | |
4322 | + return NULL; | |
4323 | + } | |
4324 | + | |
4325 | + acl_entry_link->nextp = NULL; | |
4326 | + } | |
4327 | + | |
4328 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
4329 | + | |
4330 | + /* Don't really need this since all types are going | |
4331 | + * to be specified but, it's better than leaving it 0. */ | |
4332 | + | |
4333 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
4334 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4335 | + | |
4336 | + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof (struct ace_id)); | |
4337 | + | |
4338 | + /* The access in the acl entries must be left shifted by | |
4339 | + * three bites, because they will ultimately be compared | |
4340 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
4341 | + | |
4342 | + switch (acl_entry->ace_type){ | |
4343 | + case ACC_PERMIT: | |
4344 | + case ACC_SPECIFY: | |
4345 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4346 | + acl_entry_link->entryp->ace_access <<= 6; | |
4347 | + acl_entry_link_head->count++; | |
4348 | + break; | |
4349 | + case ACC_DENY: | |
4350 | + /* Since there is no way to return a DENY acl entry | |
4351 | + * change to PERMIT and then shift. */ | |
4352 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); | |
4353 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
4354 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
4355 | + acl_entry_link->entryp->ace_access <<= 6; | |
4356 | + acl_entry_link_head->count++; | |
4357 | + break; | |
4358 | + default: | |
4359 | + return 0; | |
4360 | + } | |
4361 | + | |
4362 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
4363 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
4364 | + | |
4365 | + acl_entry = acl_nxt(acl_entry); | |
4366 | + } | |
4367 | + } /* end of if enabled */ | |
4368 | + | |
4369 | + /* Since owner, group, other acl entries are not | |
4370 | + * part of the acl entries in an acl, they must | |
4371 | + * be dummied up to become part of the list. */ | |
4372 | + | |
4373 | + for (i = 1; i < 4; i++) { | |
4374 | + DEBUG(10,("i is %d\n",i)); | |
4375 | + if (acl_entry_link_head->count != 0){ | |
4376 | + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link)); | |
4377 | + if (acl_entry_link->nextp == NULL) { | |
4378 | + errno = ENOMEM; | |
4379 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
4380 | + free(file_acl); | |
4381 | + return NULL; | |
4382 | + } | |
4383 | + | |
4384 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4385 | + acl_entry_link = acl_entry_link->nextp; | |
4386 | + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4387 | + | |
4388 | + if (acl_entry_link->entryp == NULL) { | |
4389 | + free(file_acl); | |
4390 | + errno = ENOMEM; | |
4391 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
4392 | + return NULL; | |
4393 | + } | |
4394 | + } | |
4395 | + | |
4396 | + acl_entry_link->nextp = NULL; | |
4397 | + | |
4398 | + new_acl_entry = acl_entry_link->entryp; | |
4399 | + idp = new_acl_entry->ace_id; | |
4400 | + | |
4401 | + new_acl_entry->ace_len = sizeof (struct acl_entry); | |
4402 | + new_acl_entry->ace_type = ACC_PERMIT; | |
4403 | + idp->id_len = sizeof (struct ace_id); | |
4404 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); | |
4405 | + memset(idp->id_data,0,sizeof (uid_t)); | |
4406 | + | |
4407 | + switch (i) { | |
4408 | + case 2: | |
4409 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4410 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4411 | + break; | |
4412 | + | |
4413 | + case 3: | |
4414 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4415 | + idp->id_type = SMB_ACL_OTHER; | |
4416 | + break; | |
4417 | + | |
4418 | + case 1: | |
4419 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4420 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4421 | + break; | |
4422 | + | |
4423 | + default: | |
4424 | + return NULL; | |
4425 | + } | |
4426 | + | |
4427 | + acl_entry_link_head->count++; | |
4428 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4429 | + } | |
4430 | + | |
4431 | + acl_entry_link_head->count = 0; | |
4432 | + free(file_acl); | |
4433 | + | |
4434 | + return acl_entry_link_head; | |
4435 | +} | |
4436 | + | |
4437 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) | |
4438 | +{ | |
4439 | + *permset = *permset & ~0777; | |
4440 | + return 0; | |
4441 | +} | |
4442 | + | |
4443 | + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
4444 | +{ | |
4445 | + if (perm != 0 && (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0) | |
4446 | + return -1; | |
4447 | + | |
4448 | + *permset |= perm; | |
4449 | + DEBUG(10,("This is the permset now: %d\n",*permset)); | |
4450 | + return 0; | |
4451 | +} | |
4452 | + | |
4453 | + char *sys_acl_to_text(SMB_ACL_T theacl, ssize_t *plen) | |
4454 | +{ | |
4455 | + return NULL; | |
4456 | +} | |
4457 | + | |
4458 | + SMB_ACL_T sys_acl_init(int count) | |
4459 | +{ | |
4460 | + struct acl_entry_link *theacl = NULL; | |
4461 | + | |
4462 | + DEBUG(10,("Entering sys_acl_init\n")); | |
4463 | + | |
4464 | + theacl = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link)); | |
4465 | + if (theacl == NULL) { | |
4466 | + errno = ENOMEM; | |
4467 | + DEBUG(0,("Error in sys_acl_init is %d\n",errno)); | |
4468 | + return NULL; | |
4469 | + } | |
4470 | + | |
4471 | + theacl->count = 0; | |
4472 | + theacl->nextp = NULL; | |
4473 | + theacl->prevp = NULL; | |
4474 | + theacl->entryp = NULL; | |
4475 | + DEBUG(10,("Exiting sys_acl_init\n")); | |
4476 | + return theacl; | |
4477 | +} | |
4478 | + | |
4479 | + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
4480 | +{ | |
4481 | + struct acl_entry_link *theacl; | |
4482 | + struct acl_entry_link *acl_entryp; | |
4483 | + struct acl_entry_link *temp_entry; | |
4484 | + int counting; | |
4485 | + | |
4486 | + DEBUG(10,("Entering the sys_acl_create_entry\n")); | |
4487 | + | |
4488 | + theacl = acl_entryp = *pacl; | |
4489 | + | |
4490 | + /* Get to the end of the acl before adding entry */ | |
4491 | + | |
4492 | + for (counting=0; counting < theacl->count; counting++){ | |
4493 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); | |
4494 | + temp_entry = acl_entryp; | |
4495 | + acl_entryp = acl_entryp->nextp; | |
4496 | + } | |
4497 | + | |
4498 | + if (theacl->count != 0){ | |
4499 | + temp_entry->nextp = acl_entryp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link)); | |
4500 | + if (acl_entryp == NULL) { | |
4501 | + errno = ENOMEM; | |
4502 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
4503 | + return -1; | |
4504 | + } | |
4505 | + | |
4506 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); | |
4507 | + acl_entryp->prevp = temp_entry; | |
4508 | + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp)); | |
4509 | + } | |
4510 | + | |
4511 | + *pentry = acl_entryp->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry)); | |
4512 | + if (*pentry == NULL) { | |
4513 | + errno = ENOMEM; | |
4514 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
4515 | + return -1; | |
4516 | + } | |
4517 | + | |
4518 | + memset(*pentry,0,sizeof (struct new_acl_entry)); | |
4519 | + acl_entryp->entryp->ace_len = sizeof (struct acl_entry); | |
4520 | + acl_entryp->entryp->ace_type = ACC_PERMIT; | |
4521 | + acl_entryp->entryp->ace_id->id_len = sizeof (struct ace_id); | |
4522 | + acl_entryp->nextp = NULL; | |
4523 | + theacl->count++; | |
4524 | + DEBUG(10,("Exiting sys_acl_create_entry\n")); | |
4525 | + return 0; | |
4526 | +} | |
4527 | + | |
4528 | + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
4529 | +{ | |
4530 | + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n")); | |
4531 | + entry->ace_id->id_type = tagtype; | |
4532 | + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type)); | |
4533 | + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n")); | |
4534 | +} | |
4535 | + | |
4536 | + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual) | |
4537 | +{ | |
4538 | + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n")); | |
4539 | + memcpy(entry->ace_id->id_data,qual,sizeof (uid_t)); | |
4540 | + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n")); | |
4541 | + return 0; | |
4542 | +} | |
4543 | + | |
4544 | + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
4545 | +{ | |
4546 | + DEBUG(10,("Starting AIX sys_acl_set_permset\n")); | |
4547 | + if (!(*permset & S_IXUSR) | |
4548 | + && !(*permset & S_IWUSR) | |
4549 | + && !(*permset & S_IRUSR) | |
4550 | + && *permset != 0) | |
4551 | + return -1; | |
4552 | + | |
4553 | + entry->ace_access = *permset; | |
4554 | + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access)); | |
4555 | + DEBUG(10,("Ending AIX sys_acl_set_permset\n")); | |
4556 | + return 0; | |
4557 | +} | |
4558 | + | |
4559 | + int sys_acl_valid(SMB_ACL_T theacl) | |
4560 | +{ | |
4561 | + int user_obj = 0; | |
4562 | + int group_obj = 0; | |
4563 | + int other_obj = 0; | |
4564 | + struct acl_entry_link *acl_entry; | |
4565 | + | |
4566 | + for (acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) { | |
4567 | + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ); | |
4568 | + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ); | |
4569 | + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER); | |
4570 | + } | |
4571 | + | |
4572 | + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj)); | |
4573 | + | |
4574 | + if (user_obj != 1 || group_obj != 1 || other_obj != 1) | |
4575 | + return -1; | |
4576 | + | |
4577 | + return 0; | |
4578 | +} | |
4579 | + | |
4580 | + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
4581 | +{ | |
4582 | + struct acl_entry_link *acl_entry_link = NULL; | |
4583 | + struct acl *file_acl = NULL; | |
4584 | + struct acl *file_acl_temp = NULL; | |
4585 | + struct acl_entry *acl_entry = NULL; | |
4586 | + struct ace_id *ace_id = NULL; | |
4587 | + uint id_type; | |
4588 | + uint ace_access; | |
4589 | + uint user_id; | |
4590 | + uint acl_length; | |
4591 | + uint rc; | |
4592 | + | |
4593 | + DEBUG(10,("Entering sys_acl_set_file\n")); | |
4594 | + DEBUG(10,("File name is %s\n",name)); | |
4595 | + | |
4596 | + /* AIX has no default ACL */ | |
4597 | + if (acltype == SMB_ACL_TYPE_DEFAULT) | |
4598 | + return 0; | |
4599 | + | |
4600 | + acl_length = BUFSIZ; | |
4601 | + file_acl = (struct acl *)malloc(BUFSIZ); | |
4602 | + | |
4603 | + if (file_acl == NULL) { | |
4604 | + errno = ENOMEM; | |
4605 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
4606 | + return -1; | |
4607 | + } | |
4608 | + | |
4609 | + memset(file_acl,0,BUFSIZ); | |
4610 | + | |
4611 | + file_acl->acl_len = ACL_SIZ; | |
4612 | + file_acl->acl_mode = S_IXACL; | |
4613 | + | |
4614 | + for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { | |
4615 | + acl_entry_link->entryp->ace_access >>= 6; | |
4616 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
4617 | + | |
4618 | + switch (id_type) { | |
4619 | + case SMB_ACL_USER_OBJ: | |
4620 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
4621 | + continue; | |
4622 | + case SMB_ACL_GROUP_OBJ: | |
4623 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
4624 | + continue; | |
4625 | + case SMB_ACL_OTHER: | |
4626 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
4627 | + continue; | |
4628 | + case SMB_ACL_MASK: | |
4629 | + continue; | |
4630 | + } | |
4631 | + | |
4632 | + if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) { | |
4633 | + acl_length += sizeof (struct acl_entry); | |
4634 | + file_acl_temp = (struct acl *)malloc(acl_length); | |
4635 | + if (file_acl_temp == NULL) { | |
4636 | + free(file_acl); | |
4637 | + errno = ENOMEM; | |
4638 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
4639 | + return -1; | |
4640 | + } | |
4641 | + | |
4642 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
4643 | + free(file_acl); | |
4644 | + file_acl = file_acl_temp; | |
4645 | + } | |
4646 | + | |
4647 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
4648 | + file_acl->acl_len += sizeof (struct acl_entry); | |
4649 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; | |
4650 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
4651 | + | |
4652 | + /* In order to use this, we'll need to wait until we can get denies */ | |
4653 | + /* if (!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) | |
4654 | + acl_entry->ace_type = ACC_SPECIFY; */ | |
4655 | + | |
4656 | + acl_entry->ace_type = ACC_SPECIFY; | |
4657 | + | |
4658 | + ace_id = acl_entry->ace_id; | |
4659 | + | |
4660 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; | |
4661 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
4662 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
4663 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t)); | |
4664 | + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof (uid_t)); | |
4665 | + } | |
4666 | + | |
4667 | + rc = chacl((char *)name,file_acl,file_acl->acl_len); | |
4668 | + DEBUG(10,("errno is %d\n",errno)); | |
4669 | + DEBUG(10,("return code is %d\n",rc)); | |
4670 | + free(file_acl); | |
4671 | + DEBUG(10,("Exiting the sys_acl_set_file\n")); | |
4672 | + return rc; | |
4673 | +} | |
4674 | + | |
4675 | + int sys_acl_set_fd(int fd, SMB_ACL_T theacl) | |
4676 | +{ | |
4677 | + struct acl_entry_link *acl_entry_link = NULL; | |
4678 | + struct acl *file_acl = NULL; | |
4679 | + struct acl *file_acl_temp = NULL; | |
4680 | + struct acl_entry *acl_entry = NULL; | |
4681 | + struct ace_id *ace_id = NULL; | |
4682 | + uint id_type; | |
4683 | + uint user_id; | |
4684 | + uint acl_length; | |
4685 | + uint rc; | |
4686 | + | |
4687 | + DEBUG(10,("Entering sys_acl_set_fd\n")); | |
4688 | + acl_length = BUFSIZ; | |
4689 | + file_acl = (struct acl *)malloc(BUFSIZ); | |
4690 | + | |
4691 | + if (file_acl == NULL) { | |
4692 | + errno = ENOMEM; | |
4693 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
4694 | + return -1; | |
4695 | + } | |
4696 | + | |
4697 | + memset(file_acl,0,BUFSIZ); | |
4698 | + | |
4699 | + file_acl->acl_len = ACL_SIZ; | |
4700 | + file_acl->acl_mode = S_IXACL; | |
4701 | + | |
4702 | + for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { | |
4703 | + acl_entry_link->entryp->ace_access >>= 6; | |
4704 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
4705 | + DEBUG(10,("The id_type is %d\n",id_type)); | |
4706 | + | |
4707 | + switch (id_type) { | |
4708 | + case SMB_ACL_USER_OBJ: | |
4709 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
4710 | + continue; | |
4711 | + case SMB_ACL_GROUP_OBJ: | |
4712 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
4713 | + continue; | |
4714 | + case SMB_ACL_OTHER: | |
4715 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
4716 | + continue; | |
4717 | + case SMB_ACL_MASK: | |
4718 | + continue; | |
4719 | + } | |
4720 | + | |
4721 | + if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) { | |
4722 | + acl_length += sizeof (struct acl_entry); | |
4723 | + file_acl_temp = (struct acl *)malloc(acl_length); | |
4724 | + if (file_acl_temp == NULL) { | |
4725 | + free(file_acl); | |
4726 | + errno = ENOMEM; | |
4727 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
4728 | + return -1; | |
4729 | + } | |
4730 | + | |
4731 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
4732 | + free(file_acl); | |
4733 | + file_acl = file_acl_temp; | |
4734 | + } | |
4735 | + | |
4736 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
4737 | + file_acl->acl_len += sizeof (struct acl_entry); | |
4738 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; | |
4739 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
4740 | + | |
4741 | + /* In order to use this, we'll need to wait until we can get denies */ | |
4742 | + /* if (!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) | |
4743 | + acl_entry->ace_type = ACC_SPECIFY; */ | |
4744 | + | |
4745 | + acl_entry->ace_type = ACC_SPECIFY; | |
4746 | + | |
4747 | + ace_id = acl_entry->ace_id; | |
4748 | + | |
4749 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; | |
4750 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
4751 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
4752 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t)); | |
4753 | + memcpy(ace_id->id_data, &user_id, sizeof (uid_t)); | |
4754 | + } | |
4755 | + | |
4756 | + rc = fchacl(fd,file_acl,file_acl->acl_len); | |
4757 | + DEBUG(10,("errno is %d\n",errno)); | |
4758 | + DEBUG(10,("return code is %d\n",rc)); | |
4759 | + free(file_acl); | |
4760 | + DEBUG(10,("Exiting sys_acl_set_fd\n")); | |
4761 | + return rc; | |
4762 | +} | |
4763 | + | |
4764 | + int sys_acl_delete_def_file(const char *name) | |
4765 | +{ | |
4766 | + /* AIX has no default ACL */ | |
4767 | + return 0; | |
4768 | +} | |
4769 | + | |
4770 | + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) | |
4771 | +{ | |
4772 | + return *permset & perm; | |
4773 | +} | |
4774 | + | |
4775 | + int sys_acl_free_text(char *text) | |
4776 | +{ | |
4777 | + return 0; | |
4778 | +} | |
4779 | + | |
4780 | + int sys_acl_free_acl(SMB_ACL_T posix_acl) | |
4781 | +{ | |
4782 | + struct acl_entry_link *acl_entry_link; | |
4783 | + | |
4784 | + for (acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) { | |
4785 | + free(acl_entry_link->prevp->entryp); | |
4786 | + free(acl_entry_link->prevp); | |
4787 | + } | |
4788 | + | |
4789 | + free(acl_entry_link->prevp->entryp); | |
4790 | + free(acl_entry_link->prevp); | |
4791 | + free(acl_entry_link->entryp); | |
4792 | + free(acl_entry_link); | |
4793 | + | |
4794 | + return 0; | |
4795 | +} | |
4796 | + | |
4797 | + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) | |
4798 | +{ | |
4799 | + return 0; | |
4800 | +} | |
4801 | + | |
4802 | +#else /* No ACLs. */ | |
4803 | + | |
4804 | + int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p)) | |
4805 | +{ | |
4806 | + errno = ENOSYS; | |
4807 | + return -1; | |
4808 | +} | |
4809 | + | |
4810 | + int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p)) | |
4811 | +{ | |
4812 | + errno = ENOSYS; | |
4813 | + return -1; | |
4814 | +} | |
4815 | + | |
4816 | + int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p)) | |
4817 | +{ | |
4818 | + errno = ENOSYS; | |
4819 | + return -1; | |
4820 | +} | |
4821 | + | |
4822 | + void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d)) | |
4823 | +{ | |
4824 | + errno = ENOSYS; | |
4825 | + return NULL; | |
4826 | +} | |
4827 | + | |
4828 | + SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type)) | |
4829 | +{ | |
4830 | + errno = ENOSYS; | |
4831 | + return 0; | |
4832 | +} | |
4833 | + | |
4834 | + SMB_ACL_T sys_acl_get_fd(UNUSED(int fd)) | |
4835 | +{ | |
4836 | + errno = ENOSYS; | |
4837 | + return 0; | |
4838 | +} | |
4839 | + | |
4840 | + int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset)) | |
4841 | +{ | |
4842 | + errno = ENOSYS; | |
4843 | + return -1; | |
4844 | +} | |
4845 | + | |
4846 | + int sys_acl_add_perm(UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm)) | |
4847 | +{ | |
4848 | + errno = ENOSYS; | |
4849 | + return -1; | |
4850 | +} | |
4851 | + | |
4852 | + int sys_acl_get_perm(UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm)) | |
4853 | +{ | |
4854 | + errno = ENOSYS; | |
4855 | + return permset & perm ? 1 : 0; | |
4856 | +} | |
4857 | + | |
4858 | + char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen)) | |
4859 | +{ | |
4860 | + errno = ENOSYS; | |
4861 | + return NULL; | |
4862 | +} | |
4863 | + | |
4864 | + int sys_acl_free_text(UNUSED(char *text)) | |
4865 | +{ | |
4866 | + errno = ENOSYS; | |
4867 | + return -1; | |
4868 | +} | |
4869 | + | |
4870 | + SMB_ACL_T sys_acl_init(UNUSED(int count)) | |
4871 | +{ | |
4872 | + errno = ENOSYS; | |
4873 | + return NULL; | |
4874 | +} | |
4875 | + | |
4876 | + int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry)) | |
4877 | +{ | |
4878 | + errno = ENOSYS; | |
4879 | + return -1; | |
4880 | +} | |
4881 | + | |
4882 | + int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype)) | |
4883 | +{ | |
4884 | + errno = ENOSYS; | |
4885 | + return -1; | |
4886 | +} | |
4887 | + | |
4888 | + int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual)) | |
4889 | +{ | |
4890 | + errno = ENOSYS; | |
4891 | + return -1; | |
4892 | +} | |
4893 | + | |
4894 | + int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset)) | |
4895 | +{ | |
4896 | + errno = ENOSYS; | |
4897 | + return -1; | |
4898 | +} | |
4899 | + | |
4900 | + int sys_acl_valid(UNUSED(SMB_ACL_T theacl)) | |
4901 | +{ | |
4902 | + errno = ENOSYS; | |
4903 | + return -1; | |
4904 | +} | |
4905 | + | |
4906 | + int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl)) | |
4907 | +{ | |
4908 | + errno = ENOSYS; | |
4909 | + return -1; | |
4910 | +} | |
4911 | + | |
4912 | + int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl)) | |
4913 | +{ | |
4914 | + errno = ENOSYS; | |
4915 | + return -1; | |
4916 | +} | |
4917 | + | |
4918 | + int sys_acl_delete_def_file(UNUSED(const char *name)) | |
4919 | +{ | |
4920 | + errno = ENOSYS; | |
4921 | + return -1; | |
4922 | +} | |
4923 | + | |
4924 | + int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl)) | |
4925 | +{ | |
4926 | + errno = ENOSYS; | |
4927 | + return -1; | |
4928 | +} | |
4929 | + | |
4930 | + int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) | |
4931 | +{ | |
4932 | + errno = ENOSYS; | |
4933 | + return -1; | |
4934 | +} | |
4935 | + | |
4936 | +#endif /* No ACLs. */ | |
13bed3dd WD |
4937 | --- orig/uidlist.c 2004-04-29 19:37:25 |
4938 | +++ uidlist.c 2004-07-03 20:11:58 | |
fa26e11c WD |
4939 | @@ -34,6 +34,7 @@ |
4940 | extern int verbose; | |
4941 | extern int preserve_uid; | |
4942 | extern int preserve_gid; | |
4943 | +extern int preserve_acls; | |
4944 | extern int numeric_ids; | |
4945 | extern int am_root; | |
4946 | ||
4947 | @@ -274,7 +275,7 @@ void send_uid_list(int f) | |
4948 | if (numeric_ids) | |
4949 | return; | |
4950 | ||
4951 | - if (preserve_uid) { | |
4952 | + if (preserve_uid || preserve_acls) { | |
4953 | int len; | |
4954 | /* we send sequences of uid/byte-length/name */ | |
4955 | for (list = uidlist; list; list = list->next) { | |
4956 | @@ -291,7 +292,7 @@ void send_uid_list(int f) | |
4957 | write_int(f, 0); | |
4958 | } | |
4959 | ||
4960 | - if (preserve_gid) { | |
4961 | + if (preserve_gid || preserve_acls) { | |
4962 | int len; | |
4963 | for (list = gidlist; list; list = list->next) { | |
4964 | if (!list->name) | |
4965 | @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li | |
4966 | int id, i; | |
4967 | char *name; | |
4968 | ||
4969 | - if (preserve_uid && !numeric_ids) { | |
4970 | + if ((preserve_uid || preserve_acls) && !numeric_ids) { | |
4971 | /* read the uid list */ | |
4972 | while ((id = read_int(f)) != 0) { | |
4973 | int len = read_byte(f); | |
4974 | @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li | |
4975 | } | |
4976 | ||
4977 | ||
4978 | - if (preserve_gid && !numeric_ids) { | |
4979 | + if ((preserve_gid || preserve_acls) && !numeric_ids) { | |
4980 | /* read the gid list */ | |
4981 | while ((id = read_int(f)) != 0) { | |
4982 | int len = read_byte(f); | |
125d7fca | 4983 | @@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li |
fa26e11c WD |
4984 | } |
4985 | } | |
125d7fca | 4986 | |
fa26e11c WD |
4987 | +#if SUPPORT_ACLS |
4988 | + if (preserve_acls && !numeric_ids) { | |
4989 | + id_t id; | |
4990 | + /* the enumerations don't return 0 except to flag the last | |
4991 | + * entry, since uidlist doesn't munge 0 anyway */ | |
4992 | + while ((id = next_acl_uid(flist))) | |
4993 | + acl_uid_map(match_uid(id)); | |
4994 | + while ((id = next_acl_gid(flist))) | |
4995 | + acl_gid_map(match_gid(id)); | |
4996 | + } | |
4997 | +#endif /* SUPPORT_ACLS */ | |
125d7fca | 4998 | + |
fa26e11c WD |
4999 | /* now convert the uid/gid of all files in the list to the mapped |
5000 | * uid/gid */ | |
125d7fca | 5001 | if (am_root && preserve_uid && !numeric_ids) { |