1 After applying this patch, run these commands for a successful build:
5 ./configure --with-acl-support
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.
14 --- orig/Makefile.in 2004-08-13 07:18:58
15 +++ Makefile.in 2004-07-03 20:11:58
16 @@ -25,7 +25,7 @@ VERSION=@VERSION@
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 \
34 --- orig/acls.c 2004-08-19 17:09:41
35 +++ acls.c 2004-08-19 17:09:41
37 +/* -*- c-file-style: "linux" -*-
38 + Copyright (C) Andrew Tridgell 1996
39 + Copyright (C) Paul Mackerras 1996
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.
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.
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.
56 +/* handle passing ACLs between systems */
62 +extern int preserve_acls;
69 + SMB_ACL_TAG_T tag_type;
78 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
80 +static void expand_rsync_acl(rsync_acl *racl)
82 + /* first time through, 0 <= 0, so list is expanded:
83 + * diabolical, rsync guys! */
84 + if (racl->malloced <= racl->count) {
87 + racl->malloced += 10;
88 + new_size = racl->malloced * sizeof racl->races[0];
90 + new_ptr = realloc(racl->races, new_size);
92 + new_ptr = malloc(new_size);
94 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
96 + racl->races ? "" : " not");
99 + racl->races = (rsync_ace *) new_ptr;
102 + out_of_memory("expand_rsync_acl");
106 +static void rsync_acl_free(rsync_acl *racl)
109 + racl->races = NULL;
111 + racl->malloced = 0;
114 +static int rsync_ace_sorter(const void *r1, const void *r2)
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)
125 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
128 + if (rtag1 == SMB_ACL_OTHER)
130 + if (rtag2 == SMB_ACL_OTHER)
132 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
133 + if (rtag1 == SMB_ACL_USER) {
135 + case SMB_ACL_GROUP:
136 + case SMB_ACL_GROUP_OBJ:
137 + case SMB_ACL_OTHER:
141 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
143 + if (rtag2 == SMB_ACL_USER)
145 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
146 + if (rtag1 == SMB_ACL_GROUP_OBJ)
148 + if (rtag2 == SMB_ACL_GROUP_OBJ)
150 + /* only SMB_ACL_GROUPs left */
151 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
154 +static void sort_rsync_acl(rsync_acl *racl)
158 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
159 + &rsync_ace_sorter);
162 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
164 + SMB_ACL_ENTRY_T entry;
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);
171 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
172 + SMB_ACL_PERMSET_T permset;
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";
181 + if ((rc = sys_acl_get_permset(entry, &permset))) {
182 + errfun = "sys_acl_get_tag_type";
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) {
190 + case SMB_ACL_GROUP:
195 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
196 + errfun = "sys_acl_get_tag_type";
200 + race->id = *((id_t *)qualifier);
201 + sys_acl_free_qualifier(qualifier, race->tag_type);
204 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
205 + errfun, strerror(errno));
206 + rsync_acl_free(racl);
209 + sort_rsync_acl(racl);
213 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
215 + rsync_ace *race1, *race2;
216 + size_t count = racl1->count;
217 + if (count != racl2->count)
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))
238 +static rsync_acl_list _rsync_acl_lists[] = {
239 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
240 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
243 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
245 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
246 + : &_rsync_acl_lists[1];
249 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
251 + /* first time through, 0 <= 0, so list is expanded:
252 + * diabolical, rsync guys! */
253 + if (racl_list->malloced <= racl_list->count) {
256 + if (racl_list->malloced < 1000)
257 + racl_list->malloced += 1000;
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);
264 + new_ptr = malloc(new_size);
265 + if (verbose >= 3) {
266 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
268 + racl_list->racls ? "" : " not");
271 + racl_list->racls = (rsync_acl *) new_ptr;
273 + if (!racl_list->racls)
274 + out_of_memory("expand_rsync_acl_list");
279 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
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];
286 + rsync_acl_free(racl);
288 + free(racl_list->racls);
289 + racl_list->racls = NULL;
290 + racl_list->malloced = 0;
294 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
295 + const rsync_acl_list *racl_list,
296 + const rsync_acl *racl)
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 */
306 + *match = racl_list->count - 1;
308 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
311 + *match = racl_list->count - 1;
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
324 +static void send_rsync_acl(int f, const rsync_acl *racl)
327 + size_t count = racl->count;
328 + write_int(f, count);
329 + for (race = racl->races; count--; race++) {
331 + switch (race->tag_type) {
332 + case SMB_ACL_USER_OBJ:
338 + case SMB_ACL_GROUP_OBJ:
341 + case SMB_ACL_GROUP:
344 + case SMB_ACL_OTHER:
352 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
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 */
371 +static rsync_acl _curr_rsync_acls[2];
374 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
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";
381 +/* generate the ACL(s) for this flist entry;
382 + * ACL(s) are either sent or cleaned-up by send_acl() below */
384 +BOOL make_acl(const struct file_struct *file, const char *fname)
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))
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++) {
397 + *curr_racl = rsync_acl_initializer;
398 + if (!(sacl = sys_acl_get_file(fname, *type))) {
399 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
400 + fname, str_acl_type(*type), strerror(errno));
403 + ok = unpack_smb_acl(curr_racl, sacl);
404 + sys_acl_free_acl(sacl);
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) */
414 +void send_acl(const struct file_struct *file, int f)
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))
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++) {
426 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
428 + rsync_acl_free(curr_racl);
431 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
433 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
434 + write_int(f, index);
435 + rsync_acl_free(curr_racl);
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;
445 +/* the below stuff is only used by the receiver */
447 +/* structure to hold index to rsync_acl_list member corresponding to
448 + * flist->files[i] */
451 + const struct file_struct *file;
458 + file_acl_index *fileaclidxs;
459 +} file_acl_index_list;
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 */
466 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
468 + return type == SMB_ACL_TYPE_ACCESS ?
469 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
472 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
474 + /* first time through, 0 <= 0, so list is expanded:
475 + * diabolical, rsync guys! */
476 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
479 + if (fileaclidx_list->malloced < 1000)
480 + fileaclidx_list->malloced += 1000;
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);
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",
492 + fileaclidx_list->fileaclidxs ? "" : " not");
495 + fileaclidx_list->fileaclidxs = (file_acl_index *) new_ptr;
497 + if (!fileaclidx_list->fileaclidxs)
498 + out_of_memory("expand_file_acl_index_list");
503 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
505 + free(fileaclidx_list->fileaclidxs);
506 + fileaclidx_list->fileaclidxs = NULL;
507 + fileaclidx_list->malloced = 0;
511 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
519 +static smb_acl_list _smb_acl_lists[] = {
520 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
521 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
524 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
526 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
527 + &_smb_acl_lists[1];
530 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
532 + /* first time through, 0 <= 0, so list is expanded:
533 + * diabolical, rsync guys! */
534 + if (sacl_list->malloced <= sacl_list->count) {
537 + if (sacl_list->malloced < 1000)
538 + sacl_list->malloced += 1000;
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);
546 + new_ptr = malloc(new_size);
547 + if (verbose >= 3) {
548 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
550 + sacl_list->sacls ? "" : " not");
553 + sacl_list->sacls = (SMB_ACL_T *) new_ptr;
555 + if (!sacl_list->sacls)
556 + out_of_memory("expand_smb_acl_list");
561 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
563 + smb_acl_list *sacl_list = smb_acl_lists(type);
564 + SMB_ACL_T *sacl = sacl_list->sacls;
565 + while (sacl_list->count--) {
567 + sys_acl_free_acl(*sacl++);
569 + free(sacl_list->sacls);
570 + sacl_list->sacls = NULL;
571 + sacl_list->malloced = 0;
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)
578 + size_t count = racl->count;
579 + rsync_ace *race = racl->races;
580 + const char *errfun = NULL;
581 + *smb_acl = sys_acl_init(count);
583 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
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)";
594 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
595 + errfun = "sys_acl_set_tag";
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";
604 + if (sys_acl_get_permset(entry, &permset)) {
605 + errfun = "sys_acl_get_permset";
608 + if (sys_acl_clear_perms(permset)) {
609 + errfun = "sys_acl_clear_perms";
612 + if (race->access & 4)
613 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
614 + errfun = "sys_acl_add_perm";
617 + if (race->access & 2)
618 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
619 + errfun = "sys_acl_add_perm";
622 + if (race->access & 1)
623 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
624 + errfun = "sys_acl_add_perm";
627 + if (sys_acl_set_permset(entry, permset)) {
628 + errfun = "sys_acl_set_permset";
633 + sys_acl_free_acl(*smb_acl);
634 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
641 +static void receive_rsync_acl(rsync_acl *racl, int f)
644 + uchar required_mask_perm = 0;
645 + BOOL saw_mask = False;
647 + BOOL saw_user_obj = False, saw_group_obj = False,
649 + size_t count = read_int(f);
654 + uchar tag = read_byte(f);
655 + expand_rsync_acl(racl);
656 + race = &racl->races[racl->count++];
659 + race->tag_type = SMB_ACL_USER_OBJ;
660 + saw_user_obj = True;
663 + race->tag_type = SMB_ACL_USER;
666 + race->tag_type = SMB_ACL_GROUP_OBJ;
667 + saw_group_obj = True;
670 + race->tag_type = SMB_ACL_GROUP;
673 + race->tag_type = SMB_ACL_OTHER;
677 + race->tag_type = SMB_ACL_MASK;
683 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
685 + exit_cleanup(RERR_STREAMIO);
687 + race->access = read_byte(f);
688 + if (race->access & ~ (4 | 2 | 1)) {
689 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
691 + exit_cleanup(RERR_STREAMIO);
693 + if (race->tag_type == SMB_ACL_USER ||
694 + race->tag_type == SMB_ACL_GROUP) {
695 + race->id = read_int(f);
697 + required_mask_perm |= race->access;
701 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
702 + required_mask_perm |= race->access;
706 + if (!saw_user_obj) {
707 + expand_rsync_acl(racl);
708 + race = &racl->races[racl->count++];
709 + race->tag_type = SMB_ACL_USER_OBJ;
712 + if (!saw_group_obj) {
713 + expand_rsync_acl(racl);
714 + race = &racl->races[racl->count++];
715 + race->tag_type = SMB_ACL_GROUP_OBJ;
719 + expand_rsync_acl(racl);
720 + race = &racl->races[racl->count++];
721 + race->tag_type = SMB_ACL_OTHER;
726 + expand_rsync_acl(racl);
727 + race = &racl->races[racl->count++];
728 + race->tag_type = SMB_ACL_MASK;
729 + race->access = required_mask_perm;
733 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
735 + if (!(saw_user_obj && saw_group_obj && saw_other))
737 + sort_rsync_acl(racl);
740 +/* receive and build the rsync_acl_lists */
742 +void receive_acl(struct file_struct *file, int f)
744 + SMB_ACL_TYPE_T *type,
745 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
747 + if (!preserve_acls || S_ISLNK(file->mode))
749 + fname = f_name(file);
750 + for (type = &types[0];
751 + type < &types[0] + sizeof types / sizeof types[0]
752 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
754 + file_acl_index_list *fileaclidx_list =
755 + file_acl_index_lists(*type);
757 + expand_file_acl_index_list(fileaclidx_list);
759 + tag = read_byte(f);
760 + if (tag == 'A' || tag == 'a') {
761 + if (*type != SMB_ACL_TYPE_ACCESS) {
762 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
764 + exit_cleanup(RERR_STREAMIO);
766 + } else if (tag == 'D' || tag == 'd') {
767 + if (*type == SMB_ACL_TYPE_ACCESS) {
768 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
770 + exit_cleanup(RERR_STREAMIO);
773 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
775 + exit_cleanup(RERR_STREAMIO);
777 + if (tag == 'A' || tag == 'D') {
778 + rsync_acl racl = rsync_acl_initializer;
779 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
780 + smb_acl_list *sacl_list = smb_acl_lists(*type);
781 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
782 + aclidx = racl_list->count;
783 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
785 + receive_rsync_acl(&racl, f);
786 + expand_rsync_acl_list(racl_list);
787 + racl_list->racls[racl_list->count++] = racl;
788 + expand_smb_acl_list(sacl_list);
789 + sacl_list->sacls[sacl_list->count++] = NULL;
791 + int index = read_int(f);
792 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
793 + if ((size_t) index >= racl_list->count) {
794 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
796 + str_acl_type(*type),
798 + exit_cleanup(RERR_STREAMIO);
800 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
802 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
808 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
810 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
811 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
812 + return fileaclidx1->file == fileaclidx2->file ? 0 :
813 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
816 +void sort_file_acl_index_lists()
818 + SMB_ACL_TYPE_T *type,
819 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
820 + if (!preserve_acls)
822 + for (type = &types[0];
823 + type < &types[0] + sizeof types / sizeof types[0];
826 + file_acl_index_list *fileaclidx_list =
827 + file_acl_index_lists(*type);
828 + if (!fileaclidx_list->count)
830 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
831 + sizeof fileaclidx_list->fileaclidxs[0],
832 + &file_acl_index_list_sorter);
836 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
837 + const struct file_struct *file) {
838 + int low = 0, high = fileaclidx_list->count;
839 + const struct file_struct *file_mid;
843 + int mid = (high + low) / 2;
844 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
845 + if (file_mid == file)
846 + return fileaclidx_list->fileaclidxs[mid].aclidx;
847 + if (file_mid > file)
851 + } while (low < high);
853 + file_mid = fileaclidx_list->fileaclidxs[low].file;
854 + if (file_mid == file)
855 + return fileaclidx_list->fileaclidxs[low].aclidx;
858 + "find_file_acl_index: can't find entry for file in list\n");
859 + exit_cleanup(RERR_STREAMIO);
863 +/* for duplicating ACLs on backups when using backup_dir */
865 +int dup_acl(const char *orig, const char *bak, mode_t mode)
867 + SMB_ACL_TYPE_T *type,
868 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
870 + if (!preserve_acls)
872 + for (type = &types[0];
873 + type < &types[0] + sizeof types / sizeof types[0]
874 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
876 + SMB_ACL_T sacl_orig, sacl_bak;
877 + rsync_acl racl_orig, racl_bak;
878 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
879 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
880 + orig, str_acl_type(*type), strerror(errno));
884 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
885 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
886 + bak, str_acl_type(*type), strerror(errno));
888 + /* try to forge on through */
890 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
892 + goto out_with_sacls;
895 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
897 + goto out_with_one_racl;
899 + if (rsync_acls_equal(&racl_orig, &racl_bak))
902 + ; /* presume they're unequal */
904 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
905 + if (-1 == sys_acl_delete_def_file(bak)) {
906 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
907 + bak, strerror(errno));
910 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
911 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
912 + bak, str_acl_type(*type), strerror(errno));
917 + rsync_acl_free(&racl_bak);
919 + rsync_acl_free(&racl_orig);
922 + sys_acl_free_acl(sacl_bak);
923 + /* out_with_one_sacl: */
925 + sys_acl_free_acl(sacl_orig);
930 +/* stuff for redirecting calls to set_acl() from set_perms()
931 + * for keep_backup() */
932 +static const struct file_struct *backup_orig_file = NULL;
933 +static const char null_string[] = "";
934 +static const char *backup_orig_fname = null_string;
935 +static const char *backup_dest_fname = null_string;
936 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
938 +void push_keep_backup_acl(const struct file_struct *file,
939 + const char *orig, const char *dest)
941 + if (preserve_acls) {
942 + SMB_ACL_TYPE_T *type,
943 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
945 + backup_orig_file = file;
946 + backup_orig_fname = orig;
947 + backup_dest_fname = dest;
948 + for (type = &types[0], sacl = &_backup_sacl[0];
949 + type < &types[0] + sizeof types / sizeof types[0];
951 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
954 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
955 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
956 + orig, str_acl_type(*type),
964 +static int set_keep_backup_acl()
966 + if (preserve_acls) {
967 + SMB_ACL_TYPE_T *type,
968 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
971 + for (type = &types[0], sacl = &_backup_sacl[0];
972 + type < &types[0] + sizeof types / sizeof types[0];
975 + if (-1 == sys_acl_set_file(backup_dest_fname,
978 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
980 + str_acl_type(*type),
991 +void cleanup_keep_backup_acl()
993 + if (preserve_acls) {
994 + SMB_ACL_TYPE_T *type,
995 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
997 + backup_orig_file = NULL;
998 + backup_orig_fname = null_string;
999 + backup_dest_fname = null_string;
1000 + for (type = &types[0], sacl = &_backup_sacl[0];
1001 + type < &types[0] + sizeof types / sizeof types[0];
1004 + sys_acl_free_acl(*sacl);
1010 +/* set ACL on rsync-ed or keep_backup-ed file */
1012 +int set_acl(const char *fname, const struct file_struct *file)
1015 + SMB_ACL_TYPE_T *type,
1016 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1017 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1019 + if (file == backup_orig_file) {
1020 + if (!strcmp(fname, backup_dest_fname))
1021 + return set_keep_backup_acl();
1023 + for (type = &types[0];
1024 + type < &types[0] + sizeof types / sizeof types[0]
1025 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1027 + SMB_ACL_T sacl_orig, *sacl_new;
1028 + rsync_acl racl_orig, *racl_new;
1029 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1032 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1033 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1034 + sacl_orig = sys_acl_get_file(fname, *type);
1036 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1037 + fname, str_acl_type(*type), strerror(errno));
1041 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1042 + sys_acl_free_acl(sacl_orig);
1047 + ok = rsync_acls_equal(&racl_orig, racl_new);
1048 + rsync_acl_free(&racl_orig);
1051 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1052 + if (-1 == sys_acl_delete_def_file(fname)) {
1053 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1054 + fname, strerror(errno));
1060 + if (!pack_smb_acl(sacl_new, racl_new)) {
1064 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1065 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1066 + fname, str_acl_type(*type),
1078 +/* enumeration functions for uid mapping */
1080 +/* context -- one and only one. should be cycled through once on uid mapping
1081 + * and once on gid mapping */
1082 +static rsync_acl_list *_enum_racl_lists[] = {
1083 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1086 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1087 +static size_t enum_racl_index = 0;
1088 +static size_t enum_race_index = 0;
1090 +/* this returns the next tag_type id from the given acl for the next entry,
1091 + * or it returns 0 if there are no more tag_type ids in the acl */
1093 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1095 + for (; enum_race_index < racl->count; enum_race_index++) {
1096 + rsync_ace *race = &racl->races[enum_race_index];
1097 + if (race->tag_type == tag_type)
1100 + enum_race_index = 0;
1104 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1106 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1107 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1108 + id_t id = next_ace_id(tag_type, racl);
1112 + enum_racl_index = 0;
1116 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1118 + for (; *enum_racl_list; enum_racl_list++) {
1119 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1123 + enum_racl_list = &_enum_racl_lists[0];
1127 +id_t next_acl_uid()
1129 + return next_acl_list_id(SMB_ACL_USER);
1132 +id_t next_acl_gid()
1134 + return next_acl_list_id(SMB_ACL_GROUP);
1137 +/* referring to the global context enum_entry, sets the entry's id */
1138 +static void set_acl_id(id_t id)
1140 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1143 +void acl_uid_map(id_t uid)
1148 +void acl_gid_map(id_t gid)
1153 +#endif /* SUPPORT_ACLS */
1154 --- orig/backup.c 2004-07-26 06:19:04
1155 +++ backup.c 2004-07-03 20:11:58
1156 @@ -105,6 +105,7 @@ static int make_bak_dir(char *fullpath)
1158 do_lchown(fullpath, st.st_uid, st.st_gid);
1159 do_chmod(fullpath, st.st_mode);
1160 + (void)DUP_ACL(end, fullpath, st.st_mode);
1164 @@ -168,6 +169,8 @@ static int keep_backup(char *fname)
1168 + PUSH_KEEP_BACKUP_ACL(file, fname, backup_dir_buf);
1171 /* Check to see if this is a device file, or link */
1172 if (IS_DEVICE(file->mode)) {
1173 @@ -242,6 +245,7 @@ static int keep_backup(char *fname)
1176 set_perms(backup_dir_buf, file, NULL, 0);
1177 + CLEANUP_KEEP_BACKUP_ACL();
1181 --- orig/configure.in 2004-08-13 07:18:59
1182 +++ configure.in 2004-08-19 19:53:27
1183 @@ -434,6 +434,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1184 AC_CHECK_LIB(resolv, strcasecmp)
1187 +AC_CHECK_FUNCS(aclsort)
1188 +if test x"$ac_cv_func_aclsort" = x"no"; then
1189 + AC_CHECK_LIB(sec, aclsort)
1192 dnl At the moment we don't test for a broken memcmp(), because all we
1193 dnl need to do is test for equality, not comparison, and it seems that
1194 dnl every platform has a memcmp that can do at least that.
1195 @@ -656,6 +661,77 @@ AC_SUBST(OBJ_RESTORE)
1196 AC_SUBST(CC_SHOBJ_FLAG)
1197 AC_SUBST(BUILD_POPT)
1199 +AC_CHECK_HEADERS(sys/acl.h)
1200 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1201 +#################################################
1202 +# check for ACL support
1204 +AC_MSG_CHECKING(whether to support ACLs)
1205 +AC_ARG_WITH(acl-support,
1206 +[ --with-acl-support Include ACL support (default=no)],
1207 +[ case "$withval" in
1210 + case "$host_os" in
1212 + AC_MSG_RESULT(Using UnixWare ACLs)
1213 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1216 + AC_MSG_RESULT(Using solaris ACLs)
1217 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1220 + AC_MSG_RESULT(Using HPUX ACLs)
1221 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1224 + AC_MSG_RESULT(Using IRIX ACLs)
1225 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1228 + AC_MSG_RESULT(Using AIX ACLs)
1229 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1232 + AC_MSG_RESULT(Using Tru64 ACLs)
1233 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1234 + LIBS="$LIBS -lpacl"
1237 + AC_MSG_RESULT(ACLs requested -- running tests)
1238 + AC_CHECK_LIB(acl,acl_get_file)
1239 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1240 + AC_TRY_LINK([#include <sys/types.h>
1241 +#include <sys/acl.h>],
1242 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1243 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1244 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1245 + AC_MSG_RESULT(Using posix ACLs)
1246 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1247 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1248 + AC_TRY_LINK([#include <sys/types.h>
1249 +#include <sys/acl.h>],
1250 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1251 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1252 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1253 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1256 + AC_MSG_ERROR(Failed to find ACL support)
1263 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1266 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1270 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1273 --- orig/flist.c 2004-08-12 18:34:38
1274 +++ flist.c 2004-07-03 20:11:58
1275 @@ -944,6 +944,8 @@ void send_file_name(int f, struct file_l
1279 + if (!MAKE_ACL(file, fname))
1282 maybe_emit_filelist_progress(flist);
1284 @@ -952,6 +954,10 @@ void send_file_name(int f, struct file_l
1285 if (file->basename[0]) {
1286 flist->files[flist->count++] = file;
1287 send_file_entry(file, f, base_flags);
1288 + SEND_ACL(file, f);
1290 + /* Cleanup unsent ACL(s). */
1291 + SEND_ACL(file, -1);
1294 if (recursive && S_ISDIR(file->mode)
1295 @@ -1268,6 +1274,8 @@ struct file_list *recv_file_list(int f)
1296 flags |= read_byte(f) << 8;
1297 receive_file_entry(&flist->files[i], flags, flist, f);
1299 + RECEIVE_ACL(flist->files[i], f);
1301 if (S_ISREG(flist->files[i]->mode))
1302 stats.total_size += flist->files[i]->length;
1304 @@ -1290,6 +1298,8 @@ struct file_list *recv_file_list(int f)
1306 clean_flist(flist, relative_paths, 1);
1308 + SORT_FILE_ACL_INDEX_LISTS();
1311 /* Now send the uid/gid list. This was introduced in
1312 * protocol version 15 */
1313 --- orig/generator.c 2004-08-05 18:24:21
1314 +++ generator.c 2004-07-03 20:11:58
1315 @@ -332,6 +332,10 @@ static void recv_generator(char *fname,
1316 if (set_perms(fname, file, statret ? NULL : &st, 0)
1317 && verbose && f_out != -1)
1318 rprintf(FINFO, "%s/\n", safe_fname(fname));
1321 + SET_ACL(fname, file);
1326 --- orig/mkproto.awk 2004-01-01 21:10:50
1327 +++ mkproto.awk 2004-06-30 00:04:06
1328 @@ -58,7 +58,7 @@ BEGIN {
1332 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^const/ {
1333 +!/^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/ {
1337 --- orig/options.c 2004-08-12 18:34:38
1338 +++ options.c 2004-08-19 17:38:57
1339 @@ -43,6 +43,7 @@ int keep_dirlinks = 0;
1341 int preserve_links = 0;
1342 int preserve_hard_links = 0;
1343 +int preserve_acls = 0;
1344 int preserve_perms = 0;
1345 int preserve_devices = 0;
1346 int preserve_uid = 0;
1347 @@ -152,6 +153,7 @@ static void print_rsync_version(enum log
1348 char const *got_socketpair = "no ";
1349 char const *have_inplace = "no ";
1350 char const *hardlinks = "no ";
1351 + char const *acls = "no ";
1352 char const *links = "no ";
1353 char const *ipv6 = "no ";
1354 STRUCT_STAT *dumstat;
1355 @@ -168,6 +170,10 @@ static void print_rsync_version(enum log
1366 @@ -182,9 +188,9 @@ static void print_rsync_version(enum log
1367 "Copyright (C) 1996-2004 by Andrew Tridgell and others\n");
1368 rprintf(f, "<http://rsync.samba.org/>\n");
1369 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
1370 - "%shard links, %ssymlinks, batchfiles, \n",
1371 + "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
1372 (int) (sizeof (OFF_T) * 8),
1373 - got_socketpair, hardlinks, links);
1374 + got_socketpair, hardlinks, acls, links);
1376 /* Note that this field may not have type ino_t. It depends
1377 * on the complicated interaction between largefile feature
1378 @@ -249,6 +255,7 @@ void usage(enum logcode F)
1379 rprintf(F," --safe-links ignore \"unsafe\" symlinks\n");
1380 rprintf(F," -H, --hard-links preserve hard links\n");
1381 rprintf(F," -p, --perms preserve permissions\n");
1382 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
1383 rprintf(F," -o, --owner preserve owner (root only)\n");
1384 rprintf(F," -g, --group preserve group\n");
1385 rprintf(F," -D, --devices preserve devices (root only)\n");
1386 @@ -358,6 +365,7 @@ static struct poptOption long_options[]
1387 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
1388 {"copy-unsafe-links", 0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
1389 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
1390 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
1391 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
1392 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
1393 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
1394 @@ -620,6 +628,24 @@ int parse_arguments(int *argc, const cha
1400 + preserve_acls = 1;
1401 + preserve_perms = 1;
1403 + /* FIXME: this should probably be ignored with a
1404 + * warning and then countermeasures taken to
1405 + * restrict group and other access in the presence
1406 + * of any more restrictive ACLs, but this is safe
1408 + snprintf(err_buf,sizeof(err_buf),
1409 + "ACLs are not supported on this %s\n",
1410 + am_server ? "server" : "client");
1412 +#endif /* SUPPORT_ACLS */
1417 /* A large opt value means that set_refuse_options()
1418 * turned this option off (opt-BASE is its index). */
1419 @@ -932,6 +958,8 @@ void server_options(char **args,int *arg
1421 if (preserve_hard_links)
1423 + if (preserve_acls)
1424 + argstr[x++] = 'A';
1428 --- orig/rsync.c 2004-08-09 21:07:10
1429 +++ rsync.c 2004-07-03 20:11:58
1430 @@ -207,6 +207,14 @@ int set_perms(char *fname,struct file_st
1434 + /* If this is a directory, SET_ACL() will be called on the cleanup
1435 + * receive_generator() pass--if we called it here, we might clobber
1436 + * writability on the directory. everything else is OK to do now. */
1437 + if (!S_ISDIR(st->st_mode)) {
1438 + if (SET_ACL(fname, file) == 0)
1442 if (verbose > 1 && flags & PERMS_REPORT) {
1444 rprintf(FINFO,"%s\n",fname);
1445 --- orig/rsync.h 2004-08-03 15:41:32
1446 +++ rsync.h 2004-07-03 20:11:58
1447 @@ -541,6 +541,40 @@ static inline int flist_up(struct file_l
1448 #include "lib/permstring.h"
1449 #include "lib/addrinfo.h"
1451 +#define SUPPORT_ACLS HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
1452 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
1454 +#define ACLS_NEED_MASK HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
1457 +#ifdef HAVE_SYS_ACL_H
1458 +#include <sys/acl.h>
1460 +#define MAKE_ACL(file, fname) make_acl(file, fname)
1461 +#define SEND_ACL(file, f) send_acl(file, f)
1462 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
1463 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
1464 +#define SET_ACL(fname, file) set_acl(fname, file)
1465 +#define NEXT_ACL_UID() next_acl_uid()
1466 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
1467 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
1468 + push_keep_backup_acl(file, orig, dest)
1469 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
1470 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
1471 +#else /* SUPPORT_ACLS */
1472 +#define MAKE_ACL(file, fname) 1 /* checked return value */
1473 +#define SEND_ACL(file, f)
1474 +#define RECEIVE_ACL(file, f)
1475 +#define SORT_FILE_ACL_INDEX_LISTS()
1476 +#define SET_ACL(fname, file) 0 /* checked return value */
1477 +#define NEXT_ACL_UID()
1478 +#define ACL_UID_MAP(uid)
1479 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
1480 +#define CLEANUP_KEEP_BACKUP_ACL()
1481 +#define DUP_ACL(src, orig, mode) 0 /* checked return value */
1482 +#endif /* SUPPORT_ACLS */
1483 +#include "smb_acls.h"
1487 /* We have replacement versions of these if they're missing. */
1488 --- orig/rsync.yo 2004-08-19 16:30:47
1489 +++ rsync.yo 2004-07-03 20:11:58
1490 @@ -326,6 +326,7 @@ verb(
1491 --safe-links ignore "unsafe" symlinks
1492 -H, --hard-links preserve hard links
1493 -p, --perms preserve permissions
1494 + -A, --acls preserve ACLs (implies -p) [local option]
1495 -o, --owner preserve owner (root only)
1496 -g, --group preserve group
1497 -D, --devices preserve devices (root only)
1498 @@ -578,6 +579,11 @@ source file's permissions and the umask
1499 other files (including updated files) retain their existing permissions
1500 (which is the same behavior as other file-copy utilities, such as cp).
1502 +dit(bf(-A, --acls)) This option causes rsync to update the remote
1503 +ACLs to be the same as the local ACLs. This will work only if the
1504 +remote machine's rsync supports this option also. This is a non-standard
1507 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
1508 destination file to be the same as the source file. On most systems,
1509 only the super-user can set file ownership. By default, the preservation
1510 --- orig/smb_acls.h 2004-06-30 00:04:07
1511 +++ smb_acls.h 2004-06-30 00:04:07
1514 + Unix SMB/Netbios implementation.
1516 + Portable SMB ACL interface
1517 + Copyright (C) Jeremy Allison 2000
1519 + This program is free software; you can redistribute it and/or modify
1520 + it under the terms of the GNU General Public License as published by
1521 + the Free Software Foundation; either version 2 of the License, or
1522 + (at your option) any later version.
1524 + This program is distributed in the hope that it will be useful,
1525 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1526 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1527 + GNU General Public License for more details.
1529 + You should have received a copy of the GNU General Public License
1530 + along with this program; if not, write to the Free Software
1531 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1534 +#ifndef _SMB_ACLS_H
1535 +#define _SMB_ACLS_H
1537 +#if defined(HAVE_POSIX_ACLS)
1539 +/* This is an identity mapping (just remove the SMB_). */
1541 +#define SMB_ACL_TAG_T acl_tag_t
1542 +#define SMB_ACL_TYPE_T acl_type_t
1543 +#define SMB_ACL_PERMSET_T acl_permset_t
1544 +#define SMB_ACL_PERM_T acl_perm_t
1545 +#define SMB_ACL_READ ACL_READ
1546 +#define SMB_ACL_WRITE ACL_WRITE
1547 +#define SMB_ACL_EXECUTE ACL_EXECUTE
1549 +/* Types of ACLs. */
1550 +#define SMB_ACL_USER ACL_USER
1551 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
1552 +#define SMB_ACL_GROUP ACL_GROUP
1553 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
1554 +#define SMB_ACL_OTHER ACL_OTHER
1555 +#define SMB_ACL_MASK ACL_MASK
1557 +#define SMB_ACL_T acl_t
1559 +#define SMB_ACL_ENTRY_T acl_entry_t
1561 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
1562 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
1564 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
1565 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
1567 +#elif defined(HAVE_TRU64_ACLS)
1569 +/* This is for DEC/Compaq Tru64 UNIX */
1571 +#define SMB_ACL_TAG_T acl_tag_t
1572 +#define SMB_ACL_TYPE_T acl_type_t
1573 +#define SMB_ACL_PERMSET_T acl_permset_t
1574 +#define SMB_ACL_PERM_T acl_perm_t
1575 +#define SMB_ACL_READ ACL_READ
1576 +#define SMB_ACL_WRITE ACL_WRITE
1577 +#define SMB_ACL_EXECUTE ACL_EXECUTE
1579 +/* Types of ACLs. */
1580 +#define SMB_ACL_USER ACL_USER
1581 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
1582 +#define SMB_ACL_GROUP ACL_GROUP
1583 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
1584 +#define SMB_ACL_OTHER ACL_OTHER
1585 +#define SMB_ACL_MASK ACL_MASK
1587 +#define SMB_ACL_T acl_t
1589 +#define SMB_ACL_ENTRY_T acl_entry_t
1591 +#define SMB_ACL_FIRST_ENTRY 0
1592 +#define SMB_ACL_NEXT_ENTRY 1
1594 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
1595 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
1597 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1599 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1600 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1603 +/* SVR4.2 ES/MP ACLs */
1604 +typedef int SMB_ACL_TAG_T;
1605 +typedef int SMB_ACL_TYPE_T;
1606 +typedef ushort *SMB_ACL_PERMSET_T;
1607 +typedef ushort SMB_ACL_PERM_T;
1608 +#define SMB_ACL_READ 4
1609 +#define SMB_ACL_WRITE 2
1610 +#define SMB_ACL_EXECUTE 1
1612 +/* Types of ACLs. */
1613 +#define SMB_ACL_USER USER
1614 +#define SMB_ACL_USER_OBJ USER_OBJ
1615 +#define SMB_ACL_GROUP GROUP
1616 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
1617 +#define SMB_ACL_OTHER OTHER_OBJ
1618 +#define SMB_ACL_MASK CLASS_OBJ
1620 +typedef struct SMB_ACL_T {
1624 + struct acl acl[1];
1627 +typedef struct acl *SMB_ACL_ENTRY_T;
1629 +#define SMB_ACL_FIRST_ENTRY 0
1630 +#define SMB_ACL_NEXT_ENTRY 1
1632 +#define SMB_ACL_TYPE_ACCESS 0
1633 +#define SMB_ACL_TYPE_DEFAULT 1
1635 +#elif defined(HAVE_HPUX_ACLS)
1638 + * Based on the Solaris & UnixWare code.
1642 +#include <sys/aclv.h>
1644 +/* SVR4.2 ES/MP ACLs */
1645 +typedef int SMB_ACL_TAG_T;
1646 +typedef int SMB_ACL_TYPE_T;
1647 +typedef ushort *SMB_ACL_PERMSET_T;
1648 +typedef ushort SMB_ACL_PERM_T;
1649 +#define SMB_ACL_READ 4
1650 +#define SMB_ACL_WRITE 2
1651 +#define SMB_ACL_EXECUTE 1
1653 +/* Types of ACLs. */
1654 +#define SMB_ACL_USER USER
1655 +#define SMB_ACL_USER_OBJ USER_OBJ
1656 +#define SMB_ACL_GROUP GROUP
1657 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
1658 +#define SMB_ACL_OTHER OTHER_OBJ
1659 +#define SMB_ACL_MASK CLASS_OBJ
1661 +typedef struct SMB_ACL_T {
1665 + struct acl acl[1];
1668 +typedef struct acl *SMB_ACL_ENTRY_T;
1670 +#define SMB_ACL_FIRST_ENTRY 0
1671 +#define SMB_ACL_NEXT_ENTRY 1
1673 +#define SMB_ACL_TYPE_ACCESS 0
1674 +#define SMB_ACL_TYPE_DEFAULT 1
1676 +#elif defined(HAVE_IRIX_ACLS)
1678 +#define SMB_ACL_TAG_T acl_tag_t
1679 +#define SMB_ACL_TYPE_T acl_type_t
1680 +#define SMB_ACL_PERMSET_T acl_permset_t
1681 +#define SMB_ACL_PERM_T acl_perm_t
1682 +#define SMB_ACL_READ ACL_READ
1683 +#define SMB_ACL_WRITE ACL_WRITE
1684 +#define SMB_ACL_EXECUTE ACL_EXECUTE
1686 +/* Types of ACLs. */
1687 +#define SMB_ACL_USER ACL_USER
1688 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
1689 +#define SMB_ACL_GROUP ACL_GROUP
1690 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
1691 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
1692 +#define SMB_ACL_MASK ACL_MASK
1694 +typedef struct SMB_ACL_T {
1700 +#define SMB_ACL_ENTRY_T acl_entry_t
1702 +#define SMB_ACL_FIRST_ENTRY 0
1703 +#define SMB_ACL_NEXT_ENTRY 1
1705 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
1706 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
1708 +#elif defined(HAVE_AIX_ACLS)
1710 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
1712 +#include "/usr/include/acl.h"
1714 +typedef uint *SMB_ACL_PERMSET_T;
1716 +struct acl_entry_link{
1717 + struct acl_entry_link *prevp;
1718 + struct new_acl_entry *entryp;
1719 + struct acl_entry_link *nextp;
1723 +struct new_acl_entry{
1724 + unsigned short ace_len;
1725 + unsigned short ace_type;
1726 + unsigned int ace_access;
1727 + struct ace_id ace_id[1];
1730 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
1731 +#define SMB_ACL_T struct acl_entry_link*
1733 +#define SMB_ACL_TAG_T unsigned short
1734 +#define SMB_ACL_TYPE_T int
1735 +#define SMB_ACL_PERM_T uint
1736 +#define SMB_ACL_READ S_IRUSR
1737 +#define SMB_ACL_WRITE S_IWUSR
1738 +#define SMB_ACL_EXECUTE S_IXUSR
1740 +/* Types of ACLs. */
1741 +#define SMB_ACL_USER ACEID_USER
1742 +#define SMB_ACL_USER_OBJ 3
1743 +#define SMB_ACL_GROUP ACEID_GROUP
1744 +#define SMB_ACL_GROUP_OBJ 4
1745 +#define SMB_ACL_OTHER 5
1746 +#define SMB_ACL_MASK 6
1749 +#define SMB_ACL_FIRST_ENTRY 1
1750 +#define SMB_ACL_NEXT_ENTRY 2
1752 +#define SMB_ACL_TYPE_ACCESS 0
1753 +#define SMB_ACL_TYPE_DEFAULT 1
1755 +#else /* No ACLs. */
1757 +/* No ACLS - fake it. */
1758 +#define SMB_ACL_TAG_T int
1759 +#define SMB_ACL_TYPE_T int
1760 +#define SMB_ACL_PERMSET_T mode_t
1761 +#define SMB_ACL_PERM_T mode_t
1762 +#define SMB_ACL_READ S_IRUSR
1763 +#define SMB_ACL_WRITE S_IWUSR
1764 +#define SMB_ACL_EXECUTE S_IXUSR
1766 +/* Types of ACLs. */
1767 +#define SMB_ACL_USER 0
1768 +#define SMB_ACL_USER_OBJ 1
1769 +#define SMB_ACL_GROUP 2
1770 +#define SMB_ACL_GROUP_OBJ 3
1771 +#define SMB_ACL_OTHER 4
1772 +#define SMB_ACL_MASK 5
1774 +typedef struct SMB_ACL_T {
1778 +typedef struct SMB_ACL_ENTRY_T {
1780 +} *SMB_ACL_ENTRY_T;
1782 +#define SMB_ACL_FIRST_ENTRY 0
1783 +#define SMB_ACL_NEXT_ENTRY 1
1785 +#define SMB_ACL_TYPE_ACCESS 0
1786 +#define SMB_ACL_TYPE_DEFAULT 1
1788 +#endif /* No ACLs. */
1789 +#endif /* _SMB_ACLS_H */
1790 --- orig/sysacls.c 2004-08-19 17:38:21
1791 +++ sysacls.c 2004-08-19 17:38:21
1794 + Unix SMB/Netbios implementation.
1796 + Samba system utilities for ACL support.
1797 + Copyright (C) Jeremy Allison 2000.
1799 + This program is free software; you can redistribute it and/or modify
1800 + it under the terms of the GNU General Public License as published by
1801 + the Free Software Foundation; either version 2 of the License, or
1802 + (at your option) any later version.
1804 + This program is distributed in the hope that it will be useful,
1805 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1806 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1807 + GNU General Public License for more details.
1809 + You should have received a copy of the GNU General Public License
1810 + along with this program; if not, write to the Free Software
1811 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1817 + This file wraps all differing system ACL interfaces into a consistent
1818 + one based on the POSIX interface. It also returns the correct errors
1819 + for older UNIX systems that don't support ACLs.
1821 + The interfaces that each ACL implementation must support are as follows:
1823 + int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1824 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1825 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1826 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1827 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1828 + SMB_ACL_T sys_acl_get_fd(int fd)
1829 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1830 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1831 + char *sys_acl_to_text(SMB_ACL_T theacl, ssize_t *plen)
1832 + SMB_ACL_T sys_acl_init(int count)
1833 + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1834 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1835 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
1836 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1837 + int sys_acl_valid(SMB_ACL_T theacl)
1838 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1839 + int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
1840 + int sys_acl_delete_def_file(const char *path)
1842 + This next one is not POSIX complient - but we *have* to have it !
1843 + More POSIX braindamage.
1845 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1847 + The generic POSIX free is the following call. We split this into
1848 + several different free functions as we may need to add tag info
1849 + to structures when emulating the POSIX interface.
1851 + int sys_acl_free(void *obj_p)
1853 + The calls we actually use are:
1855 + int sys_acl_free_text(char *text) - free acl_to_text
1856 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1857 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1861 +#if defined(HAVE_POSIX_ACLS)
1863 +/* Identity mapping - easy. */
1865 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1867 + return acl_get_entry(the_acl, entry_id, entry_p);
1870 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1872 + return acl_get_tag_type(entry_d, tag_type_p);
1875 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1877 + return acl_get_permset(entry_d, permset_p);
1880 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1882 + return acl_get_qualifier(entry_d);
1885 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1887 + return acl_get_file(path_p, type);
1890 +SMB_ACL_T sys_acl_get_fd(int fd)
1892 + return acl_get_fd(fd);
1895 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1897 + return acl_clear_perms(permset);
1900 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1902 + return acl_add_perm(permset, perm);
1905 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1907 +#if defined(HAVE_ACL_GET_PERM_NP)
1908 + /* Required for TrustedBSD-based ACL implementations where
1909 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1911 + return acl_get_perm_np(permset, perm);
1913 + return acl_get_perm(permset, perm);
1917 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen)
1919 + return acl_to_text(the_acl, plen);
1922 +SMB_ACL_T sys_acl_init(int count)
1924 + return acl_init(count);
1927 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1929 + return acl_create_entry(pacl, pentry);
1932 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1934 + return acl_set_tag_type(entry, tagtype);
1937 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
1939 + return acl_set_qualifier(entry, qual);
1942 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1944 + return acl_set_permset(entry, permset);
1947 +int sys_acl_valid(SMB_ACL_T theacl)
1949 + return acl_valid(theacl);
1952 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1954 + return acl_set_file(name, acltype, theacl);
1957 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
1959 + return acl_set_fd(fd, theacl);
1962 +int sys_acl_delete_def_file(const char *name)
1964 + return acl_delete_def_file(name);
1967 +int sys_acl_free_text(char *text)
1969 + return acl_free(text);
1972 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1974 + return acl_free(the_acl);
1977 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1979 + return acl_free(qual);
1982 +#elif defined(HAVE_TRU64_ACLS)
1983 +/* The interface to DEC/Compaq Tru64 UNIX ACLs
1984 + * is based on Draft 13 of the POSIX spec which is
1985 + * slightly different from the Draft 16 interface.
1987 + * Also, some of the permset manipulation functions
1988 + * such as acl_clear_perm() and acl_add_perm() appear
1989 + * to be broken on Tru64 so we have to manipulate
1990 + * the permission bits in the permset directly. */
1991 + int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1993 + SMB_ACL_ENTRY_T entry;
1995 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2000 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2005 + return errno ? -1 : 0;
2008 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2010 + return acl_get_tag_type(entry_d, tag_type_p);
2013 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2015 + return acl_get_permset(entry_d, permset_p);
2018 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2020 + return acl_get_qualifier(entry_d);
2023 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2025 + return acl_get_file((char *)path_p, type);
2028 + SMB_ACL_T sys_acl_get_fd(int fd)
2030 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2033 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2035 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2040 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2042 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2047 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2052 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2054 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2057 + char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen)
2059 + return acl_to_text(the_acl, plen);
2062 + SMB_ACL_T sys_acl_init(int count)
2064 + return acl_init(count);
2067 + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2069 + SMB_ACL_ENTRY_T entry;
2071 + if ((entry = acl_create_entry(pacl)) == NULL) {
2079 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2081 + return acl_set_tag_type(entry, tagtype);
2084 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
2086 + return acl_set_qualifier(entry, qual);
2089 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2091 + return acl_set_permset(entry, permset);
2094 + int sys_acl_valid(SMB_ACL_T theacl)
2096 + acl_entry_t entry;
2098 + return acl_valid(theacl, &entry);
2101 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2103 + return acl_set_file((char *)name, acltype, theacl);
2106 + int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
2108 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2111 + int sys_acl_delete_def_file(const char *name)
2113 + return acl_delete_def_file((char *)name);
2116 + int sys_acl_free_text(char *text)
2118 + /* (void) cast and explicit return 0 are for DEC UNIX
2119 + * which just #defines acl_free_text() to be free(). */
2120 + (void) acl_free_text(text);
2124 + int sys_acl_free_acl(SMB_ACL_T the_acl)
2126 + return acl_free(the_acl);
2129 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2131 + return acl_free_qualifier(qual, tagtype);
2134 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2136 +/* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2137 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */
2139 +/* Note that while this code implements sufficient functionality
2140 + * to support the sys_acl_* interfaces it does not provide all
2141 + * of the semantics of the POSIX ACL interfaces.
2143 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2144 + * from a call to sys_acl_get_entry() should not be assumed to be
2145 + * valid after calling any of the following functions, which may
2146 + * reorder the entries in the ACL.
2149 + * sys_acl_set_file()
2150 + * sys_acl_set_fd()
2153 +/* The only difference between Solaris and UnixWare / OpenUNIX is
2154 + * that the #defines for the ACL operations have different names. */
2155 +#if defined(HAVE_UNIXWARE_ACLS)
2157 +#define SETACL ACL_SET
2158 +#define GETACL ACL_GET
2159 +#define GETACLCNT ACL_CNT
2164 + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2166 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2171 + if (entry_p == NULL) {
2176 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2180 + if (acl_d->next < 0) {
2185 + if (acl_d->next >= acl_d->count) {
2189 + *entry_p = &acl_d->acl[acl_d->next++];
2194 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2196 + *type_p = entry_d->a_type;
2201 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2203 + *permset_p = &entry_d->a_perm;
2208 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2210 + if (entry_d->a_type != SMB_ACL_USER
2211 + && entry_d->a_type != SMB_ACL_GROUP) {
2216 + return &entry_d->a_id;
2219 +/* There is no way of knowing what size the ACL returned by
2220 + * GETACL will be unless you first call GETACLCNT which means
2221 + * making an additional system call.
2223 + * In the hope of avoiding the cost of the additional system
2224 + * call in most cases, we initially allocate enough space for
2225 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2226 + * be too small then we use GETACLCNT to find out the actual
2227 + * size, reallocate the ACL buffer, and then call GETACL again. */
2229 +#define INITIAL_ACL_SIZE 16
2231 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2234 + int count; /* # of ACL entries allocated */
2235 + int naccess; /* # of access ACL entries */
2236 + int ndefault; /* # of default ACL entries */
2238 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2243 + count = INITIAL_ACL_SIZE;
2244 + if ((acl_d = sys_acl_init(count)) == NULL) {
2248 + /* If there isn't enough space for the ACL entries we use
2249 + * GETACLCNT to determine the actual number of ACL entries
2250 + * reallocate and try again. This is in a loop because it
2251 + * is possible that someone else could modify the ACL and
2252 + * increase the number of entries between the call to
2253 + * GETACLCNT and the call to GETACL. */
2254 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2255 + && errno == ENOSPC) {
2257 + sys_acl_free_acl(acl_d);
2259 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2263 + if ((acl_d = sys_acl_init(count)) == NULL) {
2269 + sys_acl_free_acl(acl_d);
2273 + /* Calculate the number of access and default ACL entries.
2275 + * Note: we assume that the acl() system call returned a
2276 + * well formed ACL which is sorted so that all of the
2277 + * access ACL entries preceed any default ACL entries. */
2278 + for (naccess = 0; naccess < count; naccess++) {
2279 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2282 + ndefault = count - naccess;
2284 + /* If the caller wants the default ACL we have to copy
2285 + * the entries down to the start of the acl[] buffer
2286 + * and mask out the ACL_DEFAULT flag from the type field. */
2287 + if (type == SMB_ACL_TYPE_DEFAULT) {
2290 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2291 + acl_d->acl[i] = acl_d->acl[j];
2292 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2295 + acl_d->count = ndefault;
2297 + acl_d->count = naccess;
2303 + SMB_ACL_T sys_acl_get_fd(int fd)
2306 + int count; /* # of ACL entries allocated */
2307 + int naccess; /* # of access ACL entries */
2309 + count = INITIAL_ACL_SIZE;
2310 + if ((acl_d = sys_acl_init(count)) == NULL) {
2314 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2315 + && errno == ENOSPC) {
2317 + sys_acl_free_acl(acl_d);
2319 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2323 + if ((acl_d = sys_acl_init(count)) == NULL) {
2329 + sys_acl_free_acl(acl_d);
2333 + /* Calculate the number of access ACL entries. */
2334 + for (naccess = 0; naccess < count; naccess++) {
2335 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2339 + acl_d->count = naccess;
2344 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2351 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2353 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2354 + && perm != SMB_ACL_EXECUTE) {
2359 + if (permset_d == NULL) {
2364 + *permset_d |= perm;
2369 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2371 + return *permset_d & perm;
2374 + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2380 + /* Use an initial estimate of 20 bytes per ACL entry
2381 + * when allocating memory for the text representation
2384 + maxlen = 20 * acl_d->count;
2385 + if ((text = malloc(maxlen)) == NULL) {
2390 + for (i = 0; i < acl_d->count; i++) {
2391 + struct acl *ap = &acl_d->acl[i];
2392 + struct passwd *pw;
2401 + switch (ap->a_type) {
2402 + /* For debugging purposes it's probably more
2403 + * useful to dump unknown tag types rather
2404 + * than just returning an error. */
2406 + snprintf(tagbuf, sizeof tagbuf - 1, "0x%x",
2409 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
2414 + case SMB_ACL_USER:
2415 + if ((pw = getpwuid(ap->a_id)) == NULL) {
2416 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
2422 + case SMB_ACL_USER_OBJ:
2426 + case SMB_ACL_GROUP:
2427 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2428 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
2434 + case SMB_ACL_GROUP_OBJ:
2438 + case SMB_ACL_OTHER:
2442 + case SMB_ACL_MASK:
2448 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2449 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2450 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2453 + /* <tag> : <qualifier> : rwx \n \0 */
2454 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2456 + /* If this entry would overflow the buffer
2457 + * allocate enough additional memory for this
2458 + * entry and an estimate of another 20 bytes
2459 + * for each entry still to be processed. */
2460 + if ((len + nbytes) > maxlen) {
2461 + char *oldtext = text;
2463 + maxlen += nbytes + 20 * (acl_d->count - i);
2465 + if ((text = Realloc(oldtext, maxlen)) == NULL) {
2472 + snprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2473 + len += nbytes - 1;
2482 + SMB_ACL_T sys_acl_init(int count)
2491 + /* Note that since the definition of the structure pointed
2492 + * to by the SMB_ACL_T includes the first element of the
2493 + * acl[] array, this actually allocates an ACL with room
2494 + * for (count+1) entries. */
2495 + if ((a = malloc(sizeof a[0] + count * sizeof (struct acl))) == NULL) {
2500 + a->size = count + 1;
2508 + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2511 + SMB_ACL_ENTRY_T entry_d;
2513 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2518 + if (acl_d->count >= acl_d->size) {
2523 + entry_d = &acl_d->acl[acl_d->count++];
2524 + entry_d->a_type = 0;
2525 + entry_d->a_id = -1;
2526 + entry_d->a_perm = 0;
2527 + *entry_p = entry_d;
2532 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2534 + switch (tag_type) {
2535 + case SMB_ACL_USER:
2536 + case SMB_ACL_USER_OBJ:
2537 + case SMB_ACL_GROUP:
2538 + case SMB_ACL_GROUP_OBJ:
2539 + case SMB_ACL_OTHER:
2540 + case SMB_ACL_MASK:
2541 + entry_d->a_type = tag_type;
2551 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2553 + if (entry_d->a_type != SMB_ACL_GROUP
2554 + && entry_d->a_type != SMB_ACL_USER) {
2559 + entry_d->a_id = *((id_t *)qual_p);
2564 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2566 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2570 + entry_d->a_perm = *permset_d;
2575 +/* Sort the ACL and check it for validity.
2577 + * If it's a minimal ACL with only 4 entries then we
2578 + * need to recalculate the mask permissions to make
2579 + * sure that they are the same as the GROUP_OBJ
2580 + * permissions as required by the UnixWare acl() system call.
2582 + * (Note: since POSIX allows minimal ACLs which only contain
2583 + * 3 entries - ie there is no mask entry - we should, in theory,
2584 + * check for this and add a mask entry if necessary - however
2585 + * we "know" that the caller of this interface always specifies
2586 + * a mask so, in practice "this never happens" (tm) - if it *does*
2587 + * happen aclsort() will fail and return an error and someone will
2588 + * have to fix it ...) */
2590 +static int acl_sort(SMB_ACL_T acl_d)
2592 + int fixmask = (acl_d->count <= 4);
2594 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2601 + int sys_acl_valid(SMB_ACL_T acl_d)
2603 + return acl_sort(acl_d);
2606 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2609 + struct acl *acl_p;
2611 + struct acl *acl_buf = NULL;
2614 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2619 + if (acl_sort(acl_d) != 0) {
2623 + acl_p = &acl_d->acl[0];
2624 + acl_count = acl_d->count;
2626 + /* If it's a directory there is extra work to do since the acl()
2627 + * system call will replace both the access ACLs and the default
2628 + * ACLs (if any). */
2629 + if (stat(name, &s) != 0) {
2632 + if (S_ISDIR(s.st_mode)) {
2633 + SMB_ACL_T acc_acl;
2634 + SMB_ACL_T def_acl;
2635 + SMB_ACL_T tmp_acl;
2638 + if (type == SMB_ACL_TYPE_ACCESS) {
2640 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2644 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2647 + if (tmp_acl == NULL) {
2651 + /* Allocate a temporary buffer for the complete ACL. */
2652 + acl_count = acc_acl->count + def_acl->count;
2653 + acl_p = acl_buf = malloc(acl_count * sizeof acl_buf[0]);
2655 + if (acl_buf == NULL) {
2656 + sys_acl_free_acl(tmp_acl);
2661 + /* Copy the access control and default entries into the buffer. */
2662 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2663 + acc_acl->count * sizeof acl_buf[0]);
2665 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2666 + def_acl->count * sizeof acl_buf[0]);
2668 + /* Set the ACL_DEFAULT flag on the default entries. */
2669 + for (i = acc_acl->count; i < acl_count; i++) {
2670 + acl_buf[i].a_type |= ACL_DEFAULT;
2673 + sys_acl_free_acl(tmp_acl);
2675 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2680 + ret = acl(name, SETACL, acl_count, acl_p);
2687 + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2689 + if (acl_sort(acl_d) != 0) {
2693 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2696 + int sys_acl_delete_def_file(const char *path)
2701 + /* Fetching the access ACL and rewriting it has the effect of
2702 + * deleting the default ACL. */
2703 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2707 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2709 + sys_acl_free_acl(acl_d);
2714 + int sys_acl_free_text(char *text)
2720 + int sys_acl_free_acl(SMB_ACL_T acl_d)
2726 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2731 +#elif defined(HAVE_HPUX_ACLS)
2734 +/* Based on the Solaris/SCO code - with modifications. */
2736 +/* Note that while this code implements sufficient functionality
2737 + * to support the sys_acl_* interfaces it does not provide all
2738 + * of the semantics of the POSIX ACL interfaces.
2740 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2741 + * from a call to sys_acl_get_entry() should not be assumed to be
2742 + * valid after calling any of the following functions, which may
2743 + * reorder the entries in the ACL.
2746 + * sys_acl_set_file()
2747 + * sys_acl_set_fd()
2750 +/* This checks if the POSIX ACL system call is defined which basically
2751 + * corresponds to whether JFS 3.3 or higher is installed. If acl() was
2752 + * called when it isn't defined, it causes the process to core dump so
2753 + * it is important to check this and avoid acl() calls if it isn't
2756 +static BOOL hpux_acl_call_presence(void)
2759 + shl_t handle = NULL;
2762 + static BOOL already_checked=0;
2764 + if (already_checked)
2768 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2770 + if (ret_val != 0) {
2771 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2772 + ret_val, errno, strerror(errno)));
2773 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2777 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2779 + already_checked = True;
2783 + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2785 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2790 + if (entry_p == NULL) {
2795 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2799 + if (acl_d->next < 0) {
2804 + if (acl_d->next >= acl_d->count) {
2808 + *entry_p = &acl_d->acl[acl_d->next++];
2813 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2815 + *type_p = entry_d->a_type;
2820 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2822 + *permset_p = &entry_d->a_perm;
2827 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2829 + if (entry_d->a_type != SMB_ACL_USER
2830 + && entry_d->a_type != SMB_ACL_GROUP) {
2835 + return &entry_d->a_id;
2838 +/* There is no way of knowing what size the ACL returned by
2839 + * ACL_GET will be unless you first call ACL_CNT which means
2840 + * making an additional system call.
2842 + * In the hope of avoiding the cost of the additional system
2843 + * call in most cases, we initially allocate enough space for
2844 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2845 + * be too small then we use ACL_CNT to find out the actual
2846 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2849 +#define INITIAL_ACL_SIZE 16
2851 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2854 + int count; /* # of ACL entries allocated */
2855 + int naccess; /* # of access ACL entries */
2856 + int ndefault; /* # of default ACL entries */
2858 + if (hpux_acl_call_presence() == False) {
2859 + /* Looks like we don't have the acl() system call on HPUX.
2860 + * May be the system doesn't have the latest version of JFS. */
2864 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2869 + count = INITIAL_ACL_SIZE;
2870 + if ((acl_d = sys_acl_init(count)) == NULL) {
2874 + /* If there isn't enough space for the ACL entries we use
2875 + * ACL_CNT to determine the actual number of ACL entries
2876 + * reallocate and try again. This is in a loop because it
2877 + * is possible that someone else could modify the ACL and
2878 + * increase the number of entries between the call to
2879 + * ACL_CNT and the call to ACL_GET. */
2880 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2882 + sys_acl_free_acl(acl_d);
2884 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2888 + if ((acl_d = sys_acl_init(count)) == NULL) {
2894 + sys_acl_free_acl(acl_d);
2898 + /* Calculate the number of access and default ACL entries.
2900 + * Note: we assume that the acl() system call returned a
2901 + * well formed ACL which is sorted so that all of the
2902 + * access ACL entries preceed any default ACL entries. */
2903 + for (naccess = 0; naccess < count; naccess++) {
2904 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2907 + ndefault = count - naccess;
2909 + /* If the caller wants the default ACL we have to copy
2910 + * the entries down to the start of the acl[] buffer
2911 + * and mask out the ACL_DEFAULT flag from the type field. */
2912 + if (type == SMB_ACL_TYPE_DEFAULT) {
2915 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2916 + acl_d->acl[i] = acl_d->acl[j];
2917 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2920 + acl_d->count = ndefault;
2922 + acl_d->count = naccess;
2928 + SMB_ACL_T sys_acl_get_fd(int fd)
2930 + /* HPUX doesn't have the facl call. Fake it using the path.... JRA. */
2932 + files_struct *fsp = file_find_fd(fd);
2934 + if (fsp == NULL) {
2939 + /* We know we're in the same conn context. So we can use the
2940 + * relative path. */
2942 + return sys_acl_get_file(dos_to_unix_static(fsp->fsp_name), SMB_ACL_TYPE_ACCESS);
2945 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2952 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2954 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2955 + && perm != SMB_ACL_EXECUTE) {
2960 + if (permset_d == NULL) {
2965 + *permset_d |= perm;
2970 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2972 + return *permset_d & perm;
2975 + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2981 + /* Use an initial estimate of 20 bytes per ACL entry when
2982 + * allocating memory for the text representation of the ACL. */
2984 + maxlen = 20 * acl_d->count;
2985 + if ((text = malloc(maxlen)) == NULL) {
2990 + for (i = 0; i < acl_d->count; i++) {
2991 + struct acl *ap = &acl_d->acl[i];
2992 + struct passwd *pw;
3001 + switch (ap->a_type) {
3002 + /* For debugging purposes it's probably more
3003 + * useful to dump unknown tag types rather
3004 + * than just returning an error. */
3006 + snprintf(tagbuf, sizeof tagbuf - 1, "0x%x",
3009 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
3014 + case SMB_ACL_USER:
3015 + if ((pw = getpwuid(ap->a_id)) == NULL) {
3016 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
3022 + case SMB_ACL_USER_OBJ:
3026 + case SMB_ACL_GROUP:
3027 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3028 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
3034 + case SMB_ACL_GROUP_OBJ:
3038 + case SMB_ACL_OTHER:
3042 + case SMB_ACL_MASK:
3048 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3049 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3050 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3053 + /* <tag> : <qualifier> : rwx \n \0 */
3054 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3056 + /* If this entry would overflow the buffer
3057 + * allocate enough additional memory for this
3058 + * entry and an estimate of another 20 bytes
3059 + * for each entry still to be processed. */
3060 + if ((len + nbytes) > maxlen) {
3061 + char *oldtext = text;
3063 + maxlen += nbytes + 20 * (acl_d->count - i);
3065 + if ((text = Realloc(oldtext, maxlen)) == NULL) {
3072 + snprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3073 + len += nbytes - 1;
3082 + SMB_ACL_T sys_acl_init(int count)
3091 + /* Note that since the definition of the structure pointed
3092 + * to by the SMB_ACL_T includes the first element of the
3093 + * acl[] array, this actually allocates an ACL with room
3094 + * for (count+1) entries. */
3095 + if ((a = malloc(sizeof a[0] + count * sizeof (struct acl))) == NULL) {
3100 + a->size = count + 1;
3108 + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3111 + SMB_ACL_ENTRY_T entry_d;
3113 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3118 + if (acl_d->count >= acl_d->size) {
3123 + entry_d = &acl_d->acl[acl_d->count++];
3124 + entry_d->a_type = 0;
3125 + entry_d->a_id = -1;
3126 + entry_d->a_perm = 0;
3127 + *entry_p = entry_d;
3132 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3134 + switch (tag_type) {
3135 + case SMB_ACL_USER:
3136 + case SMB_ACL_USER_OBJ:
3137 + case SMB_ACL_GROUP:
3138 + case SMB_ACL_GROUP_OBJ:
3139 + case SMB_ACL_OTHER:
3140 + case SMB_ACL_MASK:
3141 + entry_d->a_type = tag_type;
3151 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3153 + if (entry_d->a_type != SMB_ACL_GROUP
3154 + && entry_d->a_type != SMB_ACL_USER) {
3159 + entry_d->a_id = *((id_t *)qual_p);
3164 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3166 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3170 + entry_d->a_perm = *permset_d;
3175 +/* Structure to capture the count for each type of ACE. */
3177 +struct hpux_acl_types {
3181 + int n_def_user_obj;
3186 + int n_def_group_obj;
3190 + int n_def_other_obj;
3193 + int n_def_class_obj;
3195 + int n_illegal_obj;
3199 + * Counts the different number of objects in a given array of ACL
3203 + * acl_count - Count of ACLs in the array of ACL strucutres.
3204 + * aclp - Array of ACL structures.
3205 + * acl_type_count - Pointer to acl_types structure. Should already be
3209 + * acl_type_count - This structure is filled up with counts of various
3213 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3217 + memset(acl_type_count, 0, sizeof (struct hpux_acl_types));
3219 + for (i=0;i<acl_count;i++) {
3220 + switch (aclp[i].a_type) {
3222 + acl_type_count->n_user++;
3225 + acl_type_count->n_user_obj++;
3227 + case DEF_USER_OBJ:
3228 + acl_type_count->n_def_user_obj++;
3231 + acl_type_count->n_group++;
3234 + acl_type_count->n_group_obj++;
3236 + case DEF_GROUP_OBJ:
3237 + acl_type_count->n_def_group_obj++;
3240 + acl_type_count->n_other_obj++;
3242 + case DEF_OTHER_OBJ:
3243 + acl_type_count->n_def_other_obj++;
3246 + acl_type_count->n_class_obj++;
3248 + case DEF_CLASS_OBJ:
3249 + acl_type_count->n_def_class_obj++;
3252 + acl_type_count->n_def_user++;
3255 + acl_type_count->n_def_group++;
3258 + acl_type_count->n_illegal_obj++;
3264 +/* swap_acl_entries: Swaps two ACL entries.
3266 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3269 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3271 + struct acl temp_acl;
3273 + temp_acl.a_type = aclp0->a_type;
3274 + temp_acl.a_id = aclp0->a_id;
3275 + temp_acl.a_perm = aclp0->a_perm;
3277 + aclp0->a_type = aclp1->a_type;
3278 + aclp0->a_id = aclp1->a_id;
3279 + aclp0->a_perm = aclp1->a_perm;
3281 + aclp1->a_type = temp_acl.a_type;
3282 + aclp1->a_id = temp_acl.a_id;
3283 + aclp1->a_perm = temp_acl.a_perm;
3286 +/* prohibited_duplicate_type
3287 + * Identifies if given ACL type can have duplicate entries or
3290 + * Inputs: acl_type - ACL Type.
3296 + * True - If the ACL type matches any of the prohibited types.
3297 + * False - If the ACL type doesn't match any of the prohibited types.
3300 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3302 + switch (acl_type) {
3312 +/* get_needed_class_perm
3313 + * Returns the permissions of a ACL structure only if the ACL
3314 + * type matches one of the pre-determined types for computing
3315 + * CLASS_OBJ permissions.
3317 + * Inputs: aclp - Pointer to ACL structure.
3320 +static int hpux_get_needed_class_perm(struct acl *aclp)
3322 + switch (aclp->a_type) {
3326 + case DEF_USER_OBJ:
3328 + case DEF_GROUP_OBJ:
3330 + case DEF_CLASS_OBJ:
3331 + case DEF_OTHER_OBJ:
3332 + return aclp->a_perm;
3338 +/* acl_sort for HPUX.
3339 + * Sorts the array of ACL structures as per the description in
3340 + * aclsort man page. Refer to aclsort man page for more details
3344 + * acl_count - Count of ACLs in the array of ACL structures.
3345 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3347 + * aclp - Array of ACL structures.
3351 + * aclp - Sorted array of ACL structures.
3355 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3356 + * debug log in case of failure.
3359 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3361 +#if !defined(HAVE_HPUX_ACLSORT)
3362 + /* The aclsort() system call is availabe on the latest HPUX General
3363 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3364 + * function. Because, we don't want to update to a new
3365 + * HPUX GR bundle just for aclsort() call. */
3367 + struct hpux_acl_types acl_obj_count;
3368 + int n_class_obj_perm = 0;
3372 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3376 + if (aclp == NULL) {
3377 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3381 + /* Count different types of ACLs in the ACLs array */
3383 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3385 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3386 + * CLASS_OBJ and OTHER_OBJ
3389 + if (acl_obj_count.n_user_obj != 1
3390 + || acl_obj_count.n_group_obj != 1
3391 + || acl_obj_count.n_class_obj != 1
3392 + || acl_obj_count.n_other_obj != 1) {
3393 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3394 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3398 + /* If any of the default objects are present, there should be only
3399 + * one of them each.
3402 + if (acl_obj_count.n_def_user_obj > 1 || acl_obj_count.n_def_group_obj > 1 ||
3403 + acl_obj_count.n_def_other_obj > 1 || acl_obj_count.n_def_class_obj > 1) {
3404 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3405 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3409 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3412 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3413 + * same ACL type, sort by ACL id.
3415 + * I am using the trival kind of sorting method here because, performance isn't
3416 + * really effected by the ACLs feature. More over there aren't going to be more
3417 + * than 17 entries on HPUX.
3420 + for (i=0; i<acl_count;i++) {
3421 + for (j=i+1; j<acl_count; j++) {
3422 + if (aclp[i].a_type > aclp[j].a_type) {
3423 + /* ACL entries out of order, swap them */
3425 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3427 + } else if (aclp[i].a_type == aclp[j].a_type) {
3429 + /* ACL entries of same type, sort by id */
3431 + if (aclp[i].a_id > aclp[j].a_id) {
3432 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3433 + } else if (aclp[i].a_id == aclp[j].a_id) {
3434 + /* We have a duplicate entry. */
3435 + if (hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3436 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3437 + aclp[i].a_type, aclp[i].a_id));
3446 + /* set the class obj permissions to the computed one. */
3448 + int n_class_obj_index = -1;
3450 + for (i=0;i<acl_count;i++) {
3451 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3453 + if (aclp[i].a_type == CLASS_OBJ)
3454 + n_class_obj_index = i;
3456 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3461 + return aclsort(acl_count, calclass, aclp);
3465 +/* Sort the ACL and check it for validity.
3467 + * If it's a minimal ACL with only 4 entries then we
3468 + * need to recalculate the mask permissions to make
3469 + * sure that they are the same as the GROUP_OBJ
3470 + * permissions as required by the UnixWare acl() system call.
3472 + * (Note: since POSIX allows minimal ACLs which only contain
3473 + * 3 entries - ie there is no mask entry - we should, in theory,
3474 + * check for this and add a mask entry if necessary - however
3475 + * we "know" that the caller of this interface always specifies
3476 + * a mask so, in practice "this never happens" (tm) - if it *does*
3477 + * happen aclsort() will fail and return an error and someone will
3478 + * have to fix it ...) */
3480 +static int acl_sort(SMB_ACL_T acl_d)
3482 + int fixmask = (acl_d->count <= 4);
3484 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3491 + int sys_acl_valid(SMB_ACL_T acl_d)
3493 + return acl_sort(acl_d);
3496 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3499 + struct acl *acl_p;
3501 + struct acl *acl_buf = NULL;
3504 + if (hpux_acl_call_presence() == False) {
3505 + /* Looks like we don't have the acl() system call on HPUX.
3506 + * May be the system doesn't have the latest version of JFS. */
3511 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3516 + if (acl_sort(acl_d) != 0) {
3520 + acl_p = &acl_d->acl[0];
3521 + acl_count = acl_d->count;
3523 + /* If it's a directory there is extra work to do since the acl()
3524 + * system call will replace both the access ACLs and the default
3525 + * ACLs (if any). */
3526 + if (stat(name, &s) != 0) {
3529 + if (S_ISDIR(s.st_mode)) {
3530 + SMB_ACL_T acc_acl;
3531 + SMB_ACL_T def_acl;
3532 + SMB_ACL_T tmp_acl;
3535 + if (type == SMB_ACL_TYPE_ACCESS) {
3537 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3541 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3544 + if (tmp_acl == NULL) {
3548 + /* Allocate a temporary buffer for the complete ACL. */
3549 + acl_count = acc_acl->count + def_acl->count;
3550 + acl_p = acl_buf = malloc(acl_count * sizeof acl_buf[0]);
3552 + if (acl_buf == NULL) {
3553 + sys_acl_free_acl(tmp_acl);
3558 + /* Copy the access control and default entries into the buffer. */
3559 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3560 + acc_acl->count * sizeof acl_buf[0]);
3562 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3563 + def_acl->count * sizeof acl_buf[0]);
3565 + /* Set the ACL_DEFAULT flag on the default entries. */
3566 + for (i = acc_acl->count; i < acl_count; i++) {
3567 + acl_buf[i].a_type |= ACL_DEFAULT;
3570 + sys_acl_free_acl(tmp_acl);
3572 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3577 + ret = acl(name, ACL_SET, acl_count, acl_p);
3584 + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3586 + /* HPUX doesn't have the facl call. Fake it using the path.... JRA. */
3588 + files_struct *fsp = file_find_fd(fd);
3590 + if (fsp == NULL) {
3595 + if (acl_sort(acl_d) != 0) {
3599 + /* We know we're in the same conn context. So we can use the
3600 + * relative path. */
3602 + return sys_acl_set_file(dos_to_unix_static(fsp->fsp_name), SMB_ACL_TYPE_ACCESS, acl_d);
3605 + int sys_acl_delete_def_file(const char *path)
3610 + /* Fetching the access ACL and rewriting it has the effect of
3611 + * deleting the default ACL. */
3612 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3616 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3618 + sys_acl_free_acl(acl_d);
3623 + int sys_acl_free_text(char *text)
3629 + int sys_acl_free_acl(SMB_ACL_T acl_d)
3635 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3640 +#elif defined(HAVE_IRIX_ACLS)
3642 + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3644 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3649 + if (entry_p == NULL) {
3654 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3658 + if (acl_d->next < 0) {
3663 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3667 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3672 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3674 + *type_p = entry_d->ae_tag;
3679 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3681 + *permset_p = entry_d;
3686 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3688 + if (entry_d->ae_tag != SMB_ACL_USER
3689 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3694 + return &entry_d->ae_id;
3697 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3701 + if ((a = malloc(sizeof a[0])) == NULL) {
3705 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3710 + a->freeaclp = True;
3714 + SMB_ACL_T sys_acl_get_fd(int fd)
3718 + if ((a = malloc(sizeof a[0])) == NULL) {
3722 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3727 + a->freeaclp = True;
3731 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3733 + permset_d->ae_perm = 0;
3738 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3740 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3741 + && perm != SMB_ACL_EXECUTE) {
3746 + if (permset_d == NULL) {
3751 + permset_d->ae_perm |= perm;
3756 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3758 + return permset_d->ae_perm & perm;
3761 + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3763 + return acl_to_text(acl_d->aclp, len_p);
3766 + SMB_ACL_T sys_acl_init(int count)
3775 + if ((a = malloc(sizeof a[0] + sizeof (struct acl))) == NULL) {
3781 + a->freeaclp = False;
3782 + a->aclp = (struct acl *)(&a->aclp + sizeof (struct acl *));
3783 + a->aclp->acl_cnt = 0;
3789 + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3792 + SMB_ACL_ENTRY_T entry_d;
3794 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3799 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3804 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3805 + entry_d->ae_tag = 0;
3806 + entry_d->ae_id = 0;
3807 + entry_d->ae_perm = 0;
3808 + *entry_p = entry_d;
3813 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3815 + switch (tag_type) {
3816 + case SMB_ACL_USER:
3817 + case SMB_ACL_USER_OBJ:
3818 + case SMB_ACL_GROUP:
3819 + case SMB_ACL_GROUP_OBJ:
3820 + case SMB_ACL_OTHER:
3821 + case SMB_ACL_MASK:
3822 + entry_d->ae_tag = tag_type;
3832 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3834 + if (entry_d->ae_tag != SMB_ACL_GROUP
3835 + && entry_d->ae_tag != SMB_ACL_USER) {
3840 + entry_d->ae_id = *((id_t *)qual_p);
3845 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3847 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3851 + entry_d->ae_perm = permset_d->ae_perm;
3856 + int sys_acl_valid(SMB_ACL_T acl_d)
3858 + return acl_valid(acl_d->aclp);
3861 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3863 + return acl_set_file(name, type, acl_d->aclp);
3866 + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3868 + return acl_set_fd(fd, acl_d->aclp);
3871 + int sys_acl_delete_def_file(const char *name)
3873 + return acl_delete_def_file(name);
3876 + int sys_acl_free_text(char *text)
3878 + return acl_free(text);
3881 + int sys_acl_free_acl(SMB_ACL_T acl_d)
3883 + if (acl_d->freeaclp) {
3884 + acl_free(acl_d->aclp);
3890 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3895 +#elif defined(HAVE_AIX_ACLS)
3897 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3899 + int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3901 + struct acl_entry_link *link;
3902 + struct new_acl_entry *entry;
3905 + DEBUG(10,("This is the count: %d\n",theacl->count));
3907 + /* Check if count was previously set to -1. If it was, that
3908 + * means we reached the end of the acl last time. */
3909 + if (theacl->count == -1)
3913 + /* To get to the next acl, traverse linked list until index of
3914 + * acl matches the count we are keeping. This count is
3915 + * incremented each time we return an acl entry. */
3917 + for (keep_going = 0; keep_going < theacl->count; keep_going++)
3918 + link = link->nextp;
3920 + entry = *entry_p = link->entryp;
3922 + DEBUG(10,("*entry_p is %d\n",entry_p));
3923 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3925 + /* Increment count */
3927 + if (link->nextp == NULL)
3928 + theacl->count = -1;
3933 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3935 + /* Initialize tag type */
3938 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3940 + /* Depending on what type of entry we have, return tag type. */
3941 + switch (entry_d->ace_id->id_type) {
3943 + *tag_type_p = SMB_ACL_USER;
3946 + *tag_type_p = SMB_ACL_GROUP;
3949 + case SMB_ACL_USER_OBJ:
3950 + case SMB_ACL_GROUP_OBJ:
3951 + case SMB_ACL_OTHER:
3952 + *tag_type_p = entry_d->ace_id->id_type;
3962 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3964 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3965 + *permset_p = &entry_d->ace_access;
3966 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3967 + if (!(**permset_p & S_IXUSR)
3968 + && !(**permset_p & S_IWUSR)
3969 + && !(**permset_p & S_IRUSR)
3970 + && **permset_p != 0)
3973 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3977 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3979 + return entry_d->ace_id->id_data;
3982 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3984 + struct acl *file_acl = (struct acl *)NULL;
3985 + struct acl_entry *acl_entry;
3986 + struct new_acl_entry *new_acl_entry;
3987 + struct ace_id *idp;
3988 + struct acl_entry_link *acl_entry_link;
3989 + struct acl_entry_link *acl_entry_link_head;
3994 + /* Get the acl using statacl */
3996 + DEBUG(10,("Entering sys_acl_get_file\n"));
3997 + DEBUG(10,("path_p is %s\n",path_p));
3999 + file_acl = (struct acl *)malloc(BUFSIZ);
4001 + if (file_acl == NULL) {
4003 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4007 + memset(file_acl,0,BUFSIZ);
4009 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4011 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4016 + DEBUG(10,("Got facl and returned it\n"));
4018 + /* Point to the first acl entry in the acl */
4019 + acl_entry = file_acl->acl_ext;
4021 + /* Begin setting up the head of the linked list that will be
4022 + * used for the storing the acl in a way that is useful for the
4023 + * posix_acls.c code. */
4025 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4026 + if (acl_entry_link_head == NULL)
4029 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4030 + if (acl_entry_link->entryp == NULL) {
4033 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4037 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4038 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4040 + /* Check if the extended acl bit is on. If it isn't, do not
4041 + * show the contents of the acl since AIX intends the extended
4042 + * info to remain unused. */
4044 + if (file_acl->acl_mode & S_IXACL){
4045 + /* while we are not pointing to the very end */
4046 + while (acl_entry < acl_last(file_acl)) {
4047 + /* before we malloc anything, make sure this is */
4048 + /* a valid acl entry and one that we want to map */
4049 + idp = id_nxt(acl_entry->ace_id);
4050 + if ((acl_entry->ace_type == ACC_SPECIFY
4051 + || acl_entry->ace_type == ACC_PERMIT)
4052 + && idp != id_last(acl_entry)) {
4053 + acl_entry = acl_nxt(acl_entry);
4057 + idp = acl_entry->ace_id;
4059 + /* Check if this is the first entry in the linked list.
4060 + * The first entry needs to keep prevp pointing to NULL
4061 + * and already has entryp allocated. */
4063 + if (acl_entry_link_head->count != 0) {
4064 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4066 + if (acl_entry_link->nextp == NULL) {
4069 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4073 + acl_entry_link->nextp->prevp = acl_entry_link;
4074 + acl_entry_link = acl_entry_link->nextp;
4075 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4076 + if (acl_entry_link->entryp == NULL) {
4079 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4082 + acl_entry_link->nextp = NULL;
4085 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4087 + /* Don't really need this since all types are going
4088 + * to be specified but, it's better than leaving it 0. */
4090 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4092 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4094 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof (struct ace_id));
4096 + /* The access in the acl entries must be left shifted by
4097 + * three bites, because they will ultimately be compared
4098 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4100 + switch (acl_entry->ace_type){
4103 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4104 + acl_entry_link->entryp->ace_access <<= 6;
4105 + acl_entry_link_head->count++;
4108 + /* Since there is no way to return a DENY acl entry
4109 + * change to PERMIT and then shift. */
4110 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4111 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4112 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4113 + acl_entry_link->entryp->ace_access <<= 6;
4114 + acl_entry_link_head->count++;
4120 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4121 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4123 + acl_entry = acl_nxt(acl_entry);
4125 + } /* end of if enabled */
4127 + /* Since owner, group, other acl entries are not part of the acl
4128 + * entries in an acl, they must be dummied up to become part of
4131 + for (i = 1; i < 4; i++) {
4132 + DEBUG(10,("i is %d\n",i));
4133 + if (acl_entry_link_head->count != 0) {
4134 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4135 + if (acl_entry_link->nextp == NULL) {
4138 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4142 + acl_entry_link->nextp->prevp = acl_entry_link;
4143 + acl_entry_link = acl_entry_link->nextp;
4144 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4145 + if (acl_entry_link->entryp == NULL) {
4148 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4153 + acl_entry_link->nextp = NULL;
4155 + new_acl_entry = acl_entry_link->entryp;
4156 + idp = new_acl_entry->ace_id;
4158 + new_acl_entry->ace_len = sizeof (struct acl_entry);
4159 + new_acl_entry->ace_type = ACC_PERMIT;
4160 + idp->id_len = sizeof (struct ace_id);
4161 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4162 + memset(idp->id_data,0,sizeof (uid_t));
4166 + new_acl_entry->ace_access = file_acl->g_access << 6;
4167 + idp->id_type = SMB_ACL_GROUP_OBJ;
4171 + new_acl_entry->ace_access = file_acl->o_access << 6;
4172 + idp->id_type = SMB_ACL_OTHER;
4176 + new_acl_entry->ace_access = file_acl->u_access << 6;
4177 + idp->id_type = SMB_ACL_USER_OBJ;
4185 + acl_entry_link_head->count++;
4186 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4189 + acl_entry_link_head->count = 0;
4192 + return acl_entry_link_head;
4195 + SMB_ACL_T sys_acl_get_fd(int fd)
4197 + struct acl *file_acl = (struct acl *)NULL;
4198 + struct acl_entry *acl_entry;
4199 + struct new_acl_entry *new_acl_entry;
4200 + struct ace_id *idp;
4201 + struct acl_entry_link *acl_entry_link;
4202 + struct acl_entry_link *acl_entry_link_head;
4207 + /* Get the acl using fstatacl */
4209 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4210 + DEBUG(10,("fd is %d\n",fd));
4211 + file_acl = (struct acl *)malloc(BUFSIZ);
4213 + if (file_acl == NULL) {
4215 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4219 + memset(file_acl,0,BUFSIZ);
4221 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4223 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4228 + DEBUG(10,("Got facl and returned it\n"));
4230 + /* Point to the first acl entry in the acl */
4232 + acl_entry = file_acl->acl_ext;
4234 + /* Begin setting up the head of the linked list that will be
4235 + * used for the storing the acl in a way that is useful for the
4236 + * posix_acls.c code. */
4238 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4239 + if (acl_entry_link_head == NULL){
4244 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4246 + if (acl_entry_link->entryp == NULL) {
4248 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4253 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4254 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4256 + /* Check if the extended acl bit is on. If it isn't, do not
4257 + * show the contents of the acl since AIX intends the extended
4258 + * info to remain unused. */
4260 + if (file_acl->acl_mode & S_IXACL){
4261 + /* while we are not pointing to the very end */
4262 + while (acl_entry < acl_last(file_acl)) {
4263 + /* before we malloc anything, make sure this is */
4264 + /* a valid acl entry and one that we want to map */
4266 + idp = id_nxt(acl_entry->ace_id);
4267 + if ((acl_entry->ace_type == ACC_SPECIFY
4268 + || acl_entry->ace_type == ACC_PERMIT)
4269 + && (idp != id_last(acl_entry))) {
4270 + acl_entry = acl_nxt(acl_entry);
4274 + idp = acl_entry->ace_id;
4276 + /* Check if this is the first entry in the linked list.
4277 + * The first entry needs to keep prevp pointing to NULL
4278 + * and already has entryp allocated. */
4280 + if (acl_entry_link_head->count != 0) {
4281 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4282 + if (acl_entry_link->nextp == NULL) {
4284 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4288 + acl_entry_link->nextp->prevp = acl_entry_link;
4289 + acl_entry_link = acl_entry_link->nextp;
4290 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4291 + if (acl_entry_link->entryp == NULL) {
4293 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4298 + acl_entry_link->nextp = NULL;
4301 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4303 + /* Don't really need this since all types are going
4304 + * to be specified but, it's better than leaving it 0. */
4306 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4307 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4309 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof (struct ace_id));
4311 + /* The access in the acl entries must be left shifted by
4312 + * three bites, because they will ultimately be compared
4313 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4315 + switch (acl_entry->ace_type){
4318 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4319 + acl_entry_link->entryp->ace_access <<= 6;
4320 + acl_entry_link_head->count++;
4323 + /* Since there is no way to return a DENY acl entry
4324 + * change to PERMIT and then shift. */
4325 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4326 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4327 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4328 + acl_entry_link->entryp->ace_access <<= 6;
4329 + acl_entry_link_head->count++;
4335 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4336 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4338 + acl_entry = acl_nxt(acl_entry);
4340 + } /* end of if enabled */
4342 + /* Since owner, group, other acl entries are not
4343 + * part of the acl entries in an acl, they must
4344 + * be dummied up to become part of the list. */
4346 + for (i = 1; i < 4; i++) {
4347 + DEBUG(10,("i is %d\n",i));
4348 + if (acl_entry_link_head->count != 0){
4349 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4350 + if (acl_entry_link->nextp == NULL) {
4352 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4357 + acl_entry_link->nextp->prevp = acl_entry_link;
4358 + acl_entry_link = acl_entry_link->nextp;
4359 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4361 + if (acl_entry_link->entryp == NULL) {
4364 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4369 + acl_entry_link->nextp = NULL;
4371 + new_acl_entry = acl_entry_link->entryp;
4372 + idp = new_acl_entry->ace_id;
4374 + new_acl_entry->ace_len = sizeof (struct acl_entry);
4375 + new_acl_entry->ace_type = ACC_PERMIT;
4376 + idp->id_len = sizeof (struct ace_id);
4377 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4378 + memset(idp->id_data,0,sizeof (uid_t));
4382 + new_acl_entry->ace_access = file_acl->g_access << 6;
4383 + idp->id_type = SMB_ACL_GROUP_OBJ;
4387 + new_acl_entry->ace_access = file_acl->o_access << 6;
4388 + idp->id_type = SMB_ACL_OTHER;
4392 + new_acl_entry->ace_access = file_acl->u_access << 6;
4393 + idp->id_type = SMB_ACL_USER_OBJ;
4400 + acl_entry_link_head->count++;
4401 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4404 + acl_entry_link_head->count = 0;
4407 + return acl_entry_link_head;
4410 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4412 + *permset = *permset & ~0777;
4416 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4418 + if (perm != 0 && (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4422 + DEBUG(10,("This is the permset now: %d\n",*permset));
4426 + char *sys_acl_to_text(SMB_ACL_T theacl, ssize_t *plen)
4431 + SMB_ACL_T sys_acl_init(int count)
4433 + struct acl_entry_link *theacl = NULL;
4435 + DEBUG(10,("Entering sys_acl_init\n"));
4437 + theacl = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4438 + if (theacl == NULL) {
4440 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4444 + theacl->count = 0;
4445 + theacl->nextp = NULL;
4446 + theacl->prevp = NULL;
4447 + theacl->entryp = NULL;
4448 + DEBUG(10,("Exiting sys_acl_init\n"));
4452 + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4454 + struct acl_entry_link *theacl;
4455 + struct acl_entry_link *acl_entryp;
4456 + struct acl_entry_link *temp_entry;
4459 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4461 + theacl = acl_entryp = *pacl;
4463 + /* Get to the end of the acl before adding entry */
4465 + for (counting=0; counting < theacl->count; counting++){
4466 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4467 + temp_entry = acl_entryp;
4468 + acl_entryp = acl_entryp->nextp;
4471 + if (theacl->count != 0){
4472 + temp_entry->nextp = acl_entryp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4473 + if (acl_entryp == NULL) {
4475 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4479 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4480 + acl_entryp->prevp = temp_entry;
4481 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4484 + *pentry = acl_entryp->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4485 + if (*pentry == NULL) {
4487 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4491 + memset(*pentry,0,sizeof (struct new_acl_entry));
4492 + acl_entryp->entryp->ace_len = sizeof (struct acl_entry);
4493 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4494 + acl_entryp->entryp->ace_id->id_len = sizeof (struct ace_id);
4495 + acl_entryp->nextp = NULL;
4497 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4501 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4503 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4504 + entry->ace_id->id_type = tagtype;
4505 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4506 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4509 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
4511 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4512 + memcpy(entry->ace_id->id_data,qual,sizeof (uid_t));
4513 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4517 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4519 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4520 + if (!(*permset & S_IXUSR)
4521 + && !(*permset & S_IWUSR)
4522 + && !(*permset & S_IRUSR)
4526 + entry->ace_access = *permset;
4527 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4528 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4532 + int sys_acl_valid(SMB_ACL_T theacl)
4535 + int group_obj = 0;
4536 + int other_obj = 0;
4537 + struct acl_entry_link *acl_entry;
4539 + for (acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4540 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4541 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4542 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4545 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4547 + if (user_obj != 1 || group_obj != 1 || other_obj != 1)
4553 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4555 + struct acl_entry_link *acl_entry_link = NULL;
4556 + struct acl *file_acl = NULL;
4557 + struct acl *file_acl_temp = NULL;
4558 + struct acl_entry *acl_entry = NULL;
4559 + struct ace_id *ace_id = NULL;
4566 + DEBUG(10,("Entering sys_acl_set_file\n"));
4567 + DEBUG(10,("File name is %s\n",name));
4569 + /* AIX has no default ACL */
4570 + if (acltype == SMB_ACL_TYPE_DEFAULT)
4573 + acl_length = BUFSIZ;
4574 + file_acl = (struct acl *)malloc(BUFSIZ);
4576 + if (file_acl == NULL) {
4578 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4582 + memset(file_acl,0,BUFSIZ);
4584 + file_acl->acl_len = ACL_SIZ;
4585 + file_acl->acl_mode = S_IXACL;
4587 + for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4588 + acl_entry_link->entryp->ace_access >>= 6;
4589 + id_type = acl_entry_link->entryp->ace_id->id_type;
4591 + switch (id_type) {
4592 + case SMB_ACL_USER_OBJ:
4593 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4595 + case SMB_ACL_GROUP_OBJ:
4596 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4598 + case SMB_ACL_OTHER:
4599 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4601 + case SMB_ACL_MASK:
4605 + if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) {
4606 + acl_length += sizeof (struct acl_entry);
4607 + file_acl_temp = (struct acl *)malloc(acl_length);
4608 + if (file_acl_temp == NULL) {
4611 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4615 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4617 + file_acl = file_acl_temp;
4620 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4621 + file_acl->acl_len += sizeof (struct acl_entry);
4622 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4623 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4625 + /* In order to use this, we'll need to wait until we can get denies */
4626 + /* if (!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4627 + acl_entry->ace_type = ACC_SPECIFY; */
4629 + acl_entry->ace_type = ACC_SPECIFY;
4631 + ace_id = acl_entry->ace_id;
4633 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4634 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4635 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4636 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t));
4637 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof (uid_t));
4640 + rc = chacl((char *)name,file_acl,file_acl->acl_len);
4641 + DEBUG(10,("errno is %d\n",errno));
4642 + DEBUG(10,("return code is %d\n",rc));
4644 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4648 + int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
4650 + struct acl_entry_link *acl_entry_link = NULL;
4651 + struct acl *file_acl = NULL;
4652 + struct acl *file_acl_temp = NULL;
4653 + struct acl_entry *acl_entry = NULL;
4654 + struct ace_id *ace_id = NULL;
4660 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4661 + acl_length = BUFSIZ;
4662 + file_acl = (struct acl *)malloc(BUFSIZ);
4664 + if (file_acl == NULL) {
4666 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4670 + memset(file_acl,0,BUFSIZ);
4672 + file_acl->acl_len = ACL_SIZ;
4673 + file_acl->acl_mode = S_IXACL;
4675 + for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4676 + acl_entry_link->entryp->ace_access >>= 6;
4677 + id_type = acl_entry_link->entryp->ace_id->id_type;
4678 + DEBUG(10,("The id_type is %d\n",id_type));
4680 + switch (id_type) {
4681 + case SMB_ACL_USER_OBJ:
4682 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4684 + case SMB_ACL_GROUP_OBJ:
4685 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4687 + case SMB_ACL_OTHER:
4688 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4690 + case SMB_ACL_MASK:
4694 + if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) {
4695 + acl_length += sizeof (struct acl_entry);
4696 + file_acl_temp = (struct acl *)malloc(acl_length);
4697 + if (file_acl_temp == NULL) {
4700 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4704 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4706 + file_acl = file_acl_temp;
4709 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4710 + file_acl->acl_len += sizeof (struct acl_entry);
4711 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4712 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4714 + /* In order to use this, we'll need to wait until we can get denies */
4715 + /* if (!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4716 + acl_entry->ace_type = ACC_SPECIFY; */
4718 + acl_entry->ace_type = ACC_SPECIFY;
4720 + ace_id = acl_entry->ace_id;
4722 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4723 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4724 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4725 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t));
4726 + memcpy(ace_id->id_data, &user_id, sizeof (uid_t));
4729 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4730 + DEBUG(10,("errno is %d\n",errno));
4731 + DEBUG(10,("return code is %d\n",rc));
4733 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4737 + int sys_acl_delete_def_file(const char *name)
4739 + /* AIX has no default ACL */
4743 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4745 + return *permset & perm;
4748 + int sys_acl_free_text(char *text)
4753 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
4755 + struct acl_entry_link *acl_entry_link;
4757 + for (acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4758 + free(acl_entry_link->prevp->entryp);
4759 + free(acl_entry_link->prevp);
4762 + free(acl_entry_link->prevp->entryp);
4763 + free(acl_entry_link->prevp);
4764 + free(acl_entry_link->entryp);
4765 + free(acl_entry_link);
4770 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4775 +#else /* No ACLs. */
4777 + int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4783 + int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4789 + int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4795 + void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4801 + SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4807 + SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4813 + int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4819 + int sys_acl_add_perm(UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4825 + int sys_acl_get_perm(UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4828 + return permset & perm ? 1 : 0;
4831 + char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4837 + int sys_acl_free_text(UNUSED(char *text))
4843 + SMB_ACL_T sys_acl_init(UNUSED(int count))
4849 + int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4855 + int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4861 + int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4867 + int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4873 + int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4879 + int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4885 + int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4891 + int sys_acl_delete_def_file(UNUSED(const char *name))
4897 + int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4903 + int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4909 +#endif /* No ACLs. */
4910 --- orig/uidlist.c 2004-04-29 19:37:25
4911 +++ uidlist.c 2004-07-03 20:11:58
4914 extern int preserve_uid;
4915 extern int preserve_gid;
4916 +extern int preserve_acls;
4917 extern int numeric_ids;
4920 @@ -274,7 +275,7 @@ void send_uid_list(int f)
4924 - if (preserve_uid) {
4925 + if (preserve_uid || preserve_acls) {
4927 /* we send sequences of uid/byte-length/name */
4928 for (list = uidlist; list; list = list->next) {
4929 @@ -291,7 +292,7 @@ void send_uid_list(int f)
4933 - if (preserve_gid) {
4934 + if (preserve_gid || preserve_acls) {
4936 for (list = gidlist; list; list = list->next) {
4938 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
4942 - if (preserve_uid && !numeric_ids) {
4943 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
4944 /* read the uid list */
4945 while ((id = read_int(f)) != 0) {
4946 int len = read_byte(f);
4947 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
4951 - if (preserve_gid && !numeric_ids) {
4952 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
4953 /* read the gid list */
4954 while ((id = read_int(f)) != 0) {
4955 int len = read_byte(f);
4956 @@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li
4961 + if (preserve_acls && !numeric_ids) {
4963 + /* the enumerations don't return 0 except to flag the last
4964 + * entry, since uidlist doesn't munge 0 anyway */
4965 + while ((id = next_acl_uid(flist)))
4966 + acl_uid_map(match_uid(id));
4967 + while ((id = next_acl_gid(flist)))
4968 + acl_gid_map(match_gid(id));
4970 +#endif /* SUPPORT_ACLS */
4972 /* now convert the uid/gid of all files in the list to the mapped
4974 if (am_root && preserve_uid && !numeric_ids) {