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-10-08 20:16:26
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-09-08 06:09:30
35 +++ acls.c 2004-09-08 06:09:30
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;
646 + 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;
681 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
683 + exit_cleanup(RERR_STREAMIO);
685 + race->access = read_byte(f);
686 + if (race->access & ~ (4 | 2 | 1)) {
687 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
689 + exit_cleanup(RERR_STREAMIO);
691 + if (race->tag_type == SMB_ACL_USER ||
692 + race->tag_type == SMB_ACL_GROUP) {
693 + race->id = read_int(f);
695 + required_mask_perm |= race->access;
699 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
700 + required_mask_perm |= race->access;
704 + if (!saw_user_obj) {
705 + expand_rsync_acl(racl);
706 + race = &racl->races[racl->count++];
707 + race->tag_type = SMB_ACL_USER_OBJ;
710 + if (!saw_group_obj) {
711 + expand_rsync_acl(racl);
712 + race = &racl->races[racl->count++];
713 + race->tag_type = SMB_ACL_GROUP_OBJ;
717 + expand_rsync_acl(racl);
718 + race = &racl->races[racl->count++];
719 + race->tag_type = SMB_ACL_OTHER;
724 + expand_rsync_acl(racl);
725 + race = &racl->races[racl->count++];
726 + race->tag_type = SMB_ACL_MASK;
727 + race->access = required_mask_perm;
730 + /* If we, a system without ACLS_NEED_MASK, received data from a
731 + * system that has masks, throw away the extraneous CLASS_OBJs. */
732 + if (saw_mask && racl->count == 4) {
733 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
736 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
737 + if (p->tag_type == SMB_ACL_MASK)
739 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
740 + group_obj_race = p;
742 + if (mask_race == NULL || group_obj_race == NULL) {
743 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
744 + "and one's ACL_MASK but missing "
745 + "either it or ACL_GROUP_OBJ, "
746 + "when pruning ACL\n");
748 + /* mask off group perms with it first */
749 + group_obj_race->access &= mask_race->access;
750 + /* dump mask_race; re-slot any followers-on */
752 + if (mask_race != &racl->races[racl->count]) {
753 + *mask_race = racl->races[racl->count];
754 + saw_user_obj = False; /* force re-sort */
760 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
762 + if (!(saw_user_obj && saw_group_obj && saw_other))
764 + sort_rsync_acl(racl);
767 +/* receive and build the rsync_acl_lists */
769 +void receive_acl(struct file_struct *file, int f)
771 + SMB_ACL_TYPE_T *type,
772 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
774 + if (!preserve_acls || S_ISLNK(file->mode))
776 + fname = f_name(file);
777 + for (type = &types[0];
778 + type < &types[0] + sizeof types / sizeof types[0]
779 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
781 + file_acl_index_list *fileaclidx_list =
782 + file_acl_index_lists(*type);
784 + expand_file_acl_index_list(fileaclidx_list);
786 + tag = read_byte(f);
787 + if (tag == 'A' || tag == 'a') {
788 + if (*type != SMB_ACL_TYPE_ACCESS) {
789 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
791 + exit_cleanup(RERR_STREAMIO);
793 + } else if (tag == 'D' || tag == 'd') {
794 + if (*type == SMB_ACL_TYPE_ACCESS) {
795 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
797 + exit_cleanup(RERR_STREAMIO);
800 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
802 + exit_cleanup(RERR_STREAMIO);
804 + if (tag == 'A' || tag == 'D') {
805 + rsync_acl racl = rsync_acl_initializer;
806 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
807 + smb_acl_list *sacl_list = smb_acl_lists(*type);
808 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
809 + aclidx = racl_list->count;
810 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
812 + receive_rsync_acl(&racl, f);
813 + expand_rsync_acl_list(racl_list);
814 + racl_list->racls[racl_list->count++] = racl;
815 + expand_smb_acl_list(sacl_list);
816 + sacl_list->sacls[sacl_list->count++] = NULL;
818 + int index = read_int(f);
819 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
820 + if ((size_t) index >= racl_list->count) {
821 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
823 + str_acl_type(*type),
825 + exit_cleanup(RERR_STREAMIO);
827 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
829 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
835 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
837 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
838 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
839 + return fileaclidx1->file == fileaclidx2->file ? 0 :
840 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
843 +void sort_file_acl_index_lists()
845 + SMB_ACL_TYPE_T *type,
846 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
847 + if (!preserve_acls)
849 + for (type = &types[0];
850 + type < &types[0] + sizeof types / sizeof types[0];
853 + file_acl_index_list *fileaclidx_list =
854 + file_acl_index_lists(*type);
855 + if (!fileaclidx_list->count)
857 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
858 + sizeof fileaclidx_list->fileaclidxs[0],
859 + &file_acl_index_list_sorter);
863 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
864 + const struct file_struct *file) {
865 + int low = 0, high = fileaclidx_list->count;
866 + const struct file_struct *file_mid;
870 + int mid = (high + low) / 2;
871 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
872 + if (file_mid == file)
873 + return fileaclidx_list->fileaclidxs[mid].aclidx;
874 + if (file_mid > file)
878 + } while (low < high);
880 + file_mid = fileaclidx_list->fileaclidxs[low].file;
881 + if (file_mid == file)
882 + return fileaclidx_list->fileaclidxs[low].aclidx;
885 + "find_file_acl_index: can't find entry for file in list\n");
886 + exit_cleanup(RERR_STREAMIO);
890 +/* for duplicating ACLs on backups when using backup_dir */
892 +int dup_acl(const char *orig, const char *bak, mode_t mode)
894 + SMB_ACL_TYPE_T *type,
895 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
897 + if (!preserve_acls)
899 + for (type = &types[0];
900 + type < &types[0] + sizeof types / sizeof types[0]
901 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
903 + SMB_ACL_T sacl_orig, sacl_bak;
904 + rsync_acl racl_orig, racl_bak;
905 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
906 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
907 + orig, str_acl_type(*type), strerror(errno));
911 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
912 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
913 + bak, str_acl_type(*type), strerror(errno));
915 + /* try to forge on through */
917 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
919 + goto out_with_sacls;
922 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
924 + goto out_with_one_racl;
926 + if (rsync_acls_equal(&racl_orig, &racl_bak))
929 + ; /* presume they're unequal */
931 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
932 + if (-1 == sys_acl_delete_def_file(bak)) {
933 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
934 + bak, strerror(errno));
937 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
938 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
939 + bak, str_acl_type(*type), strerror(errno));
944 + rsync_acl_free(&racl_bak);
946 + rsync_acl_free(&racl_orig);
949 + sys_acl_free_acl(sacl_bak);
950 + /* out_with_one_sacl: */
952 + sys_acl_free_acl(sacl_orig);
957 +/* stuff for redirecting calls to set_acl() from set_perms()
958 + * for keep_backup() */
959 +static const struct file_struct *backup_orig_file = NULL;
960 +static const char null_string[] = "";
961 +static const char *backup_orig_fname = null_string;
962 +static const char *backup_dest_fname = null_string;
963 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
965 +void push_keep_backup_acl(const struct file_struct *file,
966 + const char *orig, const char *dest)
968 + if (preserve_acls) {
969 + SMB_ACL_TYPE_T *type,
970 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
972 + backup_orig_file = file;
973 + backup_orig_fname = orig;
974 + backup_dest_fname = dest;
975 + for (type = &types[0], sacl = &_backup_sacl[0];
976 + type < &types[0] + sizeof types / sizeof types[0];
978 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
981 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
982 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
983 + orig, str_acl_type(*type),
991 +static int set_keep_backup_acl()
993 + if (preserve_acls) {
994 + SMB_ACL_TYPE_T *type,
995 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
998 + for (type = &types[0], sacl = &_backup_sacl[0];
999 + type < &types[0] + sizeof types / sizeof types[0];
1002 + if (-1 == sys_acl_set_file(backup_dest_fname,
1005 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1006 + backup_dest_fname,
1007 + str_acl_type(*type),
1018 +void cleanup_keep_backup_acl()
1020 + if (preserve_acls) {
1021 + SMB_ACL_TYPE_T *type,
1022 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1024 + backup_orig_file = NULL;
1025 + backup_orig_fname = null_string;
1026 + backup_dest_fname = null_string;
1027 + for (type = &types[0], sacl = &_backup_sacl[0];
1028 + type < &types[0] + sizeof types / sizeof types[0];
1031 + sys_acl_free_acl(*sacl);
1037 +/* set ACL on rsync-ed or keep_backup-ed file */
1039 +int set_acl(const char *fname, const struct file_struct *file)
1042 + SMB_ACL_TYPE_T *type,
1043 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1044 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1046 + if (file == backup_orig_file) {
1047 + if (!strcmp(fname, backup_dest_fname))
1048 + return set_keep_backup_acl();
1050 + for (type = &types[0];
1051 + type < &types[0] + sizeof types / sizeof types[0]
1052 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1054 + SMB_ACL_T sacl_orig, *sacl_new;
1055 + rsync_acl racl_orig, *racl_new;
1056 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1059 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1060 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1061 + sacl_orig = sys_acl_get_file(fname, *type);
1063 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1064 + fname, str_acl_type(*type), strerror(errno));
1068 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1069 + sys_acl_free_acl(sacl_orig);
1074 + ok = rsync_acls_equal(&racl_orig, racl_new);
1075 + rsync_acl_free(&racl_orig);
1078 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1079 + if (-1 == sys_acl_delete_def_file(fname)) {
1080 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1081 + fname, strerror(errno));
1087 + if (!pack_smb_acl(sacl_new, racl_new)) {
1091 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1092 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1093 + fname, str_acl_type(*type),
1105 +/* enumeration functions for uid mapping */
1107 +/* context -- one and only one. should be cycled through once on uid mapping
1108 + * and once on gid mapping */
1109 +static rsync_acl_list *_enum_racl_lists[] = {
1110 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1113 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1114 +static size_t enum_racl_index = 0;
1115 +static size_t enum_race_index = 0;
1117 +/* this returns the next tag_type id from the given acl for the next entry,
1118 + * or it returns 0 if there are no more tag_type ids in the acl */
1120 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1122 + for (; enum_race_index < racl->count; enum_race_index++) {
1123 + rsync_ace *race = &racl->races[enum_race_index];
1124 + if (race->tag_type == tag_type)
1127 + enum_race_index = 0;
1131 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1133 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1134 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1135 + id_t id = next_ace_id(tag_type, racl);
1139 + enum_racl_index = 0;
1143 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1145 + for (; *enum_racl_list; enum_racl_list++) {
1146 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1150 + enum_racl_list = &_enum_racl_lists[0];
1154 +id_t next_acl_uid()
1156 + return next_acl_list_id(SMB_ACL_USER);
1159 +id_t next_acl_gid()
1161 + return next_acl_list_id(SMB_ACL_GROUP);
1164 +/* referring to the global context enum_entry, sets the entry's id */
1165 +static void set_acl_id(id_t id)
1167 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1170 +void acl_uid_map(id_t uid)
1175 +void acl_gid_map(id_t gid)
1180 +#endif /* SUPPORT_ACLS */
1181 --- orig/backup.c 2004-10-06 00:12:15
1182 +++ backup.c 2004-10-06 00:13:09
1183 @@ -119,6 +119,7 @@ static int make_bak_dir(char *fullpath)
1185 do_lchown(fullpath, st.st_uid, st.st_gid);
1186 do_chmod(fullpath, st.st_mode);
1187 + (void)DUP_ACL(end, fullpath, st.st_mode);
1191 @@ -176,6 +177,8 @@ static int keep_backup(char *fname)
1192 if (!(buf = get_backup_name(fname)))
1195 + PUSH_KEEP_BACKUP_ACL(file, fname, buf);
1197 /* Check to see if this is a device file, or link */
1198 if (IS_DEVICE(file->mode)) {
1199 if (am_root && preserve_devices) {
1200 @@ -249,6 +252,7 @@ static int keep_backup(char *fname)
1203 set_perms(buf, file, NULL, 0);
1204 + CLEANUP_KEEP_BACKUP_ACL();
1208 --- orig/configure.in 2004-10-06 00:12:16
1209 +++ configure.in 2004-08-19 19:53:27
1210 @@ -443,6 +443,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1211 AC_CHECK_LIB(resolv, strcasecmp)
1214 +AC_CHECK_FUNCS(aclsort)
1215 +if test x"$ac_cv_func_aclsort" = x"no"; then
1216 + AC_CHECK_LIB(sec, aclsort)
1219 dnl At the moment we don't test for a broken memcmp(), because all we
1220 dnl need to do is test for equality, not comparison, and it seems that
1221 dnl every platform has a memcmp that can do at least that.
1222 @@ -693,6 +698,77 @@ AC_SUBST(OBJ_RESTORE)
1223 AC_SUBST(CC_SHOBJ_FLAG)
1224 AC_SUBST(BUILD_POPT)
1226 +AC_CHECK_HEADERS(sys/acl.h)
1227 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1228 +#################################################
1229 +# check for ACL support
1231 +AC_MSG_CHECKING(whether to support ACLs)
1232 +AC_ARG_WITH(acl-support,
1233 +[ --with-acl-support Include ACL support (default=no)],
1234 +[ case "$withval" in
1237 + case "$host_os" in
1239 + AC_MSG_RESULT(Using UnixWare ACLs)
1240 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1243 + AC_MSG_RESULT(Using solaris ACLs)
1244 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1247 + AC_MSG_RESULT(Using HPUX ACLs)
1248 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1251 + AC_MSG_RESULT(Using IRIX ACLs)
1252 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1255 + AC_MSG_RESULT(Using AIX ACLs)
1256 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1259 + AC_MSG_RESULT(Using Tru64 ACLs)
1260 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1261 + LIBS="$LIBS -lpacl"
1264 + AC_MSG_RESULT(ACLs requested -- running tests)
1265 + AC_CHECK_LIB(acl,acl_get_file)
1266 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1267 + AC_TRY_LINK([#include <sys/types.h>
1268 +#include <sys/acl.h>],
1269 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1270 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1271 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1272 + AC_MSG_RESULT(Using posix ACLs)
1273 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1274 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1275 + AC_TRY_LINK([#include <sys/types.h>
1276 +#include <sys/acl.h>],
1277 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1278 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1279 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1280 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1283 + AC_MSG_ERROR(Failed to find ACL support)
1290 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1293 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1297 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1300 --- orig/flist.c 2004-09-21 09:40:27
1301 +++ flist.c 2004-07-03 20:11:58
1302 @@ -966,6 +966,8 @@ void send_file_name(int f, struct file_l
1306 + if (!MAKE_ACL(file, fname))
1309 maybe_emit_filelist_progress(flist);
1311 @@ -974,6 +976,10 @@ void send_file_name(int f, struct file_l
1312 if (file->basename[0]) {
1313 flist->files[flist->count++] = file;
1314 send_file_entry(file, f, base_flags);
1315 + SEND_ACL(file, f);
1317 + /* Cleanup unsent ACL(s). */
1318 + SEND_ACL(file, -1);
1321 if (recursive && S_ISDIR(file->mode)
1322 @@ -1291,6 +1297,8 @@ struct file_list *recv_file_list(int f)
1323 flags |= read_byte(f) << 8;
1324 receive_file_entry(&flist->files[i], flags, flist, f);
1326 + RECEIVE_ACL(flist->files[i], f);
1328 if (S_ISREG(flist->files[i]->mode))
1329 stats.total_size += flist->files[i]->length;
1331 @@ -1313,6 +1321,8 @@ struct file_list *recv_file_list(int f)
1333 clean_flist(flist, relative_paths, 1);
1335 + SORT_FILE_ACL_INDEX_LISTS();
1338 /* Now send the uid/gid list. This was introduced in
1339 * protocol version 15 */
1340 --- orig/generator.c 2004-10-06 00:12:16
1341 +++ generator.c 2004-07-03 20:11:58
1342 @@ -338,6 +338,10 @@ static void recv_generator(char *fname,
1343 if (set_perms(fname, file, statret ? NULL : &st, 0)
1344 && verbose && f_out != -1)
1345 rprintf(FINFO, "%s/\n", safe_fname(fname));
1348 + SET_ACL(fname, file);
1353 --- orig/mkproto.awk 2004-01-01 21:10:50
1354 +++ mkproto.awk 2004-06-30 00:04:06
1355 @@ -58,7 +58,7 @@ BEGIN {
1359 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^const/ {
1360 +!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^BOOL|^void|^time|^const|^SMB_ACL_T|^id_t/ {
1364 --- orig/options.c 2004-10-08 20:16:26
1365 +++ options.c 2004-08-19 17:38:57
1366 @@ -43,6 +43,7 @@ int keep_dirlinks = 0;
1368 int preserve_links = 0;
1369 int preserve_hard_links = 0;
1370 +int preserve_acls = 0;
1371 int preserve_perms = 0;
1372 int preserve_devices = 0;
1373 int preserve_uid = 0;
1374 @@ -152,6 +153,7 @@ static void print_rsync_version(enum log
1375 char const *got_socketpair = "no ";
1376 char const *have_inplace = "no ";
1377 char const *hardlinks = "no ";
1378 + char const *acls = "no ";
1379 char const *links = "no ";
1380 char const *ipv6 = "no ";
1381 STRUCT_STAT *dumstat;
1382 @@ -168,6 +170,10 @@ static void print_rsync_version(enum log
1393 @@ -182,9 +188,9 @@ static void print_rsync_version(enum log
1394 "Copyright (C) 1996-2004 by Andrew Tridgell and others\n");
1395 rprintf(f, "<http://rsync.samba.org/>\n");
1396 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
1397 - "%shard links, %ssymlinks, batchfiles, \n",
1398 + "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
1399 (int) (sizeof (OFF_T) * 8),
1400 - got_socketpair, hardlinks, links);
1401 + got_socketpair, hardlinks, acls, links);
1403 /* Note that this field may not have type ino_t. It depends
1404 * on the complicated interaction between largefile feature
1405 @@ -249,6 +255,7 @@ void usage(enum logcode F)
1406 rprintf(F," --safe-links ignore \"unsafe\" symlinks\n");
1407 rprintf(F," -H, --hard-links preserve hard links\n");
1408 rprintf(F," -p, --perms preserve permissions\n");
1409 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
1410 rprintf(F," -o, --owner preserve owner (root only)\n");
1411 rprintf(F," -g, --group preserve group\n");
1412 rprintf(F," -D, --devices preserve devices (root only)\n");
1413 @@ -358,6 +365,7 @@ static struct poptOption long_options[]
1414 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
1415 {"copy-unsafe-links", 0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
1416 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
1417 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
1418 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
1419 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
1420 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
1421 @@ -616,6 +624,24 @@ int parse_arguments(int *argc, const cha
1427 + preserve_acls = 1;
1428 + preserve_perms = 1;
1430 + /* FIXME: this should probably be ignored with a
1431 + * warning and then countermeasures taken to
1432 + * restrict group and other access in the presence
1433 + * of any more restrictive ACLs, but this is safe
1435 + snprintf(err_buf,sizeof(err_buf),
1436 + "ACLs are not supported on this %s\n",
1437 + am_server ? "server" : "client");
1439 +#endif /* SUPPORT_ACLS */
1444 /* A large opt value means that set_refuse_options()
1445 * turned this option off (opt-BASE is its index). */
1446 @@ -942,6 +968,8 @@ void server_options(char **args,int *arg
1448 if (preserve_hard_links)
1450 + if (preserve_acls)
1451 + argstr[x++] = 'A';
1455 --- orig/rsync.c 2004-09-07 21:45:30
1456 +++ rsync.c 2004-07-03 20:11:58
1457 @@ -207,6 +207,14 @@ int set_perms(char *fname,struct file_st
1461 + /* If this is a directory, SET_ACL() will be called on the cleanup
1462 + * receive_generator() pass--if we called it here, we might clobber
1463 + * writability on the directory. everything else is OK to do now. */
1464 + if (!S_ISDIR(st->st_mode)) {
1465 + if (SET_ACL(fname, file) == 0)
1469 if (verbose > 1 && flags & PERMS_REPORT) {
1471 rprintf(FINFO,"%s\n",fname);
1472 --- orig/rsync.h 2004-10-09 03:21:56
1473 +++ rsync.h 2004-07-03 20:11:58
1474 @@ -545,6 +545,40 @@ static inline int flist_up(struct file_l
1475 #include "lib/permstring.h"
1476 #include "lib/addrinfo.h"
1478 +#define SUPPORT_ACLS HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
1479 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
1481 +#define ACLS_NEED_MASK HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
1484 +#ifdef HAVE_SYS_ACL_H
1485 +#include <sys/acl.h>
1487 +#define MAKE_ACL(file, fname) make_acl(file, fname)
1488 +#define SEND_ACL(file, f) send_acl(file, f)
1489 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
1490 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
1491 +#define SET_ACL(fname, file) set_acl(fname, file)
1492 +#define NEXT_ACL_UID() next_acl_uid()
1493 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
1494 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
1495 + push_keep_backup_acl(file, orig, dest)
1496 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
1497 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
1498 +#else /* SUPPORT_ACLS */
1499 +#define MAKE_ACL(file, fname) 1 /* checked return value */
1500 +#define SEND_ACL(file, f)
1501 +#define RECEIVE_ACL(file, f)
1502 +#define SORT_FILE_ACL_INDEX_LISTS()
1503 +#define SET_ACL(fname, file) 0 /* checked return value */
1504 +#define NEXT_ACL_UID()
1505 +#define ACL_UID_MAP(uid)
1506 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
1507 +#define CLEANUP_KEEP_BACKUP_ACL()
1508 +#define DUP_ACL(src, orig, mode) 0 /* checked return value */
1509 +#endif /* SUPPORT_ACLS */
1510 +#include "smb_acls.h"
1514 /* We have replacement versions of these if they're missing. */
1515 --- orig/rsync.yo 2004-10-06 00:12:16
1516 +++ rsync.yo 2004-07-03 20:11:58
1517 @@ -326,6 +326,7 @@ verb(
1518 --safe-links ignore "unsafe" symlinks
1519 -H, --hard-links preserve hard links
1520 -p, --perms preserve permissions
1521 + -A, --acls preserve ACLs (implies -p) [local option]
1522 -o, --owner preserve owner (root only)
1523 -g, --group preserve group
1524 -D, --devices preserve devices (root only)
1525 @@ -585,6 +586,11 @@ source file's permissions and the umask
1526 other files (including updated files) retain their existing permissions
1527 (which is the same behavior as other file-copy utilities, such as cp).
1529 +dit(bf(-A, --acls)) This option causes rsync to update the remote
1530 +ACLs to be the same as the local ACLs. This will work only if the
1531 +remote machine's rsync supports this option also. This is a non-standard
1534 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
1535 destination file to be the same as the source file. On most systems,
1536 only the super-user can set file ownership. By default, the preservation
1537 --- orig/smb_acls.h 2004-06-30 00:04:07
1538 +++ smb_acls.h 2004-06-30 00:04:07
1541 + Unix SMB/Netbios implementation.
1543 + Portable SMB ACL interface
1544 + Copyright (C) Jeremy Allison 2000
1546 + This program is free software; you can redistribute it and/or modify
1547 + it under the terms of the GNU General Public License as published by
1548 + the Free Software Foundation; either version 2 of the License, or
1549 + (at your option) any later version.
1551 + This program is distributed in the hope that it will be useful,
1552 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1553 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1554 + GNU General Public License for more details.
1556 + You should have received a copy of the GNU General Public License
1557 + along with this program; if not, write to the Free Software
1558 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1561 +#ifndef _SMB_ACLS_H
1562 +#define _SMB_ACLS_H
1564 +#if defined(HAVE_POSIX_ACLS)
1566 +/* This is an identity mapping (just remove the SMB_). */
1568 +#define SMB_ACL_TAG_T acl_tag_t
1569 +#define SMB_ACL_TYPE_T acl_type_t
1570 +#define SMB_ACL_PERMSET_T acl_permset_t
1571 +#define SMB_ACL_PERM_T acl_perm_t
1572 +#define SMB_ACL_READ ACL_READ
1573 +#define SMB_ACL_WRITE ACL_WRITE
1574 +#define SMB_ACL_EXECUTE ACL_EXECUTE
1576 +/* Types of ACLs. */
1577 +#define SMB_ACL_USER ACL_USER
1578 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
1579 +#define SMB_ACL_GROUP ACL_GROUP
1580 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
1581 +#define SMB_ACL_OTHER ACL_OTHER
1582 +#define SMB_ACL_MASK ACL_MASK
1584 +#define SMB_ACL_T acl_t
1586 +#define SMB_ACL_ENTRY_T acl_entry_t
1588 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
1589 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
1591 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
1592 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
1594 +#elif defined(HAVE_TRU64_ACLS)
1596 +/* This is for DEC/Compaq Tru64 UNIX */
1598 +#define SMB_ACL_TAG_T acl_tag_t
1599 +#define SMB_ACL_TYPE_T acl_type_t
1600 +#define SMB_ACL_PERMSET_T acl_permset_t
1601 +#define SMB_ACL_PERM_T acl_perm_t
1602 +#define SMB_ACL_READ ACL_READ
1603 +#define SMB_ACL_WRITE ACL_WRITE
1604 +#define SMB_ACL_EXECUTE ACL_EXECUTE
1606 +/* Types of ACLs. */
1607 +#define SMB_ACL_USER ACL_USER
1608 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
1609 +#define SMB_ACL_GROUP ACL_GROUP
1610 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
1611 +#define SMB_ACL_OTHER ACL_OTHER
1612 +#define SMB_ACL_MASK ACL_MASK
1614 +#define SMB_ACL_T acl_t
1616 +#define SMB_ACL_ENTRY_T acl_entry_t
1618 +#define SMB_ACL_FIRST_ENTRY 0
1619 +#define SMB_ACL_NEXT_ENTRY 1
1621 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
1622 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
1624 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1626 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1627 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1630 +/* SVR4.2 ES/MP ACLs */
1631 +typedef int SMB_ACL_TAG_T;
1632 +typedef int SMB_ACL_TYPE_T;
1633 +typedef ushort *SMB_ACL_PERMSET_T;
1634 +typedef ushort SMB_ACL_PERM_T;
1635 +#define SMB_ACL_READ 4
1636 +#define SMB_ACL_WRITE 2
1637 +#define SMB_ACL_EXECUTE 1
1639 +/* Types of ACLs. */
1640 +#define SMB_ACL_USER USER
1641 +#define SMB_ACL_USER_OBJ USER_OBJ
1642 +#define SMB_ACL_GROUP GROUP
1643 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
1644 +#define SMB_ACL_OTHER OTHER_OBJ
1645 +#define SMB_ACL_MASK CLASS_OBJ
1647 +typedef struct SMB_ACL_T {
1651 + struct acl acl[1];
1654 +typedef struct acl *SMB_ACL_ENTRY_T;
1656 +#define SMB_ACL_FIRST_ENTRY 0
1657 +#define SMB_ACL_NEXT_ENTRY 1
1659 +#define SMB_ACL_TYPE_ACCESS 0
1660 +#define SMB_ACL_TYPE_DEFAULT 1
1662 +#elif defined(HAVE_HPUX_ACLS)
1665 + * Based on the Solaris & UnixWare code.
1669 +#include <sys/aclv.h>
1671 +/* SVR4.2 ES/MP ACLs */
1672 +typedef int SMB_ACL_TAG_T;
1673 +typedef int SMB_ACL_TYPE_T;
1674 +typedef ushort *SMB_ACL_PERMSET_T;
1675 +typedef ushort SMB_ACL_PERM_T;
1676 +#define SMB_ACL_READ 4
1677 +#define SMB_ACL_WRITE 2
1678 +#define SMB_ACL_EXECUTE 1
1680 +/* Types of ACLs. */
1681 +#define SMB_ACL_USER USER
1682 +#define SMB_ACL_USER_OBJ USER_OBJ
1683 +#define SMB_ACL_GROUP GROUP
1684 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
1685 +#define SMB_ACL_OTHER OTHER_OBJ
1686 +#define SMB_ACL_MASK CLASS_OBJ
1688 +typedef struct SMB_ACL_T {
1692 + struct acl acl[1];
1695 +typedef struct acl *SMB_ACL_ENTRY_T;
1697 +#define SMB_ACL_FIRST_ENTRY 0
1698 +#define SMB_ACL_NEXT_ENTRY 1
1700 +#define SMB_ACL_TYPE_ACCESS 0
1701 +#define SMB_ACL_TYPE_DEFAULT 1
1703 +#elif defined(HAVE_IRIX_ACLS)
1705 +#define SMB_ACL_TAG_T acl_tag_t
1706 +#define SMB_ACL_TYPE_T acl_type_t
1707 +#define SMB_ACL_PERMSET_T acl_permset_t
1708 +#define SMB_ACL_PERM_T acl_perm_t
1709 +#define SMB_ACL_READ ACL_READ
1710 +#define SMB_ACL_WRITE ACL_WRITE
1711 +#define SMB_ACL_EXECUTE ACL_EXECUTE
1713 +/* Types of ACLs. */
1714 +#define SMB_ACL_USER ACL_USER
1715 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
1716 +#define SMB_ACL_GROUP ACL_GROUP
1717 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
1718 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
1719 +#define SMB_ACL_MASK ACL_MASK
1721 +typedef struct SMB_ACL_T {
1727 +#define SMB_ACL_ENTRY_T acl_entry_t
1729 +#define SMB_ACL_FIRST_ENTRY 0
1730 +#define SMB_ACL_NEXT_ENTRY 1
1732 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
1733 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
1735 +#elif defined(HAVE_AIX_ACLS)
1737 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
1739 +#include "/usr/include/acl.h"
1741 +typedef uint *SMB_ACL_PERMSET_T;
1743 +struct acl_entry_link{
1744 + struct acl_entry_link *prevp;
1745 + struct new_acl_entry *entryp;
1746 + struct acl_entry_link *nextp;
1750 +struct new_acl_entry{
1751 + unsigned short ace_len;
1752 + unsigned short ace_type;
1753 + unsigned int ace_access;
1754 + struct ace_id ace_id[1];
1757 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
1758 +#define SMB_ACL_T struct acl_entry_link*
1760 +#define SMB_ACL_TAG_T unsigned short
1761 +#define SMB_ACL_TYPE_T int
1762 +#define SMB_ACL_PERM_T uint
1763 +#define SMB_ACL_READ S_IRUSR
1764 +#define SMB_ACL_WRITE S_IWUSR
1765 +#define SMB_ACL_EXECUTE S_IXUSR
1767 +/* Types of ACLs. */
1768 +#define SMB_ACL_USER ACEID_USER
1769 +#define SMB_ACL_USER_OBJ 3
1770 +#define SMB_ACL_GROUP ACEID_GROUP
1771 +#define SMB_ACL_GROUP_OBJ 4
1772 +#define SMB_ACL_OTHER 5
1773 +#define SMB_ACL_MASK 6
1776 +#define SMB_ACL_FIRST_ENTRY 1
1777 +#define SMB_ACL_NEXT_ENTRY 2
1779 +#define SMB_ACL_TYPE_ACCESS 0
1780 +#define SMB_ACL_TYPE_DEFAULT 1
1782 +#else /* No ACLs. */
1784 +/* No ACLS - fake it. */
1785 +#define SMB_ACL_TAG_T int
1786 +#define SMB_ACL_TYPE_T int
1787 +#define SMB_ACL_PERMSET_T mode_t
1788 +#define SMB_ACL_PERM_T mode_t
1789 +#define SMB_ACL_READ S_IRUSR
1790 +#define SMB_ACL_WRITE S_IWUSR
1791 +#define SMB_ACL_EXECUTE S_IXUSR
1793 +/* Types of ACLs. */
1794 +#define SMB_ACL_USER 0
1795 +#define SMB_ACL_USER_OBJ 1
1796 +#define SMB_ACL_GROUP 2
1797 +#define SMB_ACL_GROUP_OBJ 3
1798 +#define SMB_ACL_OTHER 4
1799 +#define SMB_ACL_MASK 5
1801 +typedef struct SMB_ACL_T {
1805 +typedef struct SMB_ACL_ENTRY_T {
1807 +} *SMB_ACL_ENTRY_T;
1809 +#define SMB_ACL_FIRST_ENTRY 0
1810 +#define SMB_ACL_NEXT_ENTRY 1
1812 +#define SMB_ACL_TYPE_ACCESS 0
1813 +#define SMB_ACL_TYPE_DEFAULT 1
1815 +#endif /* No ACLs. */
1816 +#endif /* _SMB_ACLS_H */
1817 --- orig/sysacls.c 2004-08-19 17:38:21
1818 +++ sysacls.c 2004-08-19 17:38:21
1821 + Unix SMB/Netbios implementation.
1823 + Samba system utilities for ACL support.
1824 + Copyright (C) Jeremy Allison 2000.
1826 + This program is free software; you can redistribute it and/or modify
1827 + it under the terms of the GNU General Public License as published by
1828 + the Free Software Foundation; either version 2 of the License, or
1829 + (at your option) any later version.
1831 + This program is distributed in the hope that it will be useful,
1832 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1833 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1834 + GNU General Public License for more details.
1836 + You should have received a copy of the GNU General Public License
1837 + along with this program; if not, write to the Free Software
1838 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1844 + This file wraps all differing system ACL interfaces into a consistent
1845 + one based on the POSIX interface. It also returns the correct errors
1846 + for older UNIX systems that don't support ACLs.
1848 + The interfaces that each ACL implementation must support are as follows:
1850 + int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1851 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1852 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1853 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1854 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1855 + SMB_ACL_T sys_acl_get_fd(int fd)
1856 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1857 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1858 + char *sys_acl_to_text(SMB_ACL_T theacl, ssize_t *plen)
1859 + SMB_ACL_T sys_acl_init(int count)
1860 + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1861 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1862 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
1863 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1864 + int sys_acl_valid(SMB_ACL_T theacl)
1865 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1866 + int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
1867 + int sys_acl_delete_def_file(const char *path)
1869 + This next one is not POSIX complient - but we *have* to have it !
1870 + More POSIX braindamage.
1872 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1874 + The generic POSIX free is the following call. We split this into
1875 + several different free functions as we may need to add tag info
1876 + to structures when emulating the POSIX interface.
1878 + int sys_acl_free(void *obj_p)
1880 + The calls we actually use are:
1882 + int sys_acl_free_text(char *text) - free acl_to_text
1883 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1884 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1888 +#if defined(HAVE_POSIX_ACLS)
1890 +/* Identity mapping - easy. */
1892 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1894 + return acl_get_entry(the_acl, entry_id, entry_p);
1897 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1899 + return acl_get_tag_type(entry_d, tag_type_p);
1902 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1904 + return acl_get_permset(entry_d, permset_p);
1907 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1909 + return acl_get_qualifier(entry_d);
1912 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1914 + return acl_get_file(path_p, type);
1917 +SMB_ACL_T sys_acl_get_fd(int fd)
1919 + return acl_get_fd(fd);
1922 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1924 + return acl_clear_perms(permset);
1927 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1929 + return acl_add_perm(permset, perm);
1932 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1934 +#if defined(HAVE_ACL_GET_PERM_NP)
1935 + /* Required for TrustedBSD-based ACL implementations where
1936 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1938 + return acl_get_perm_np(permset, perm);
1940 + return acl_get_perm(permset, perm);
1944 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen)
1946 + return acl_to_text(the_acl, plen);
1949 +SMB_ACL_T sys_acl_init(int count)
1951 + return acl_init(count);
1954 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1956 + return acl_create_entry(pacl, pentry);
1959 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1961 + return acl_set_tag_type(entry, tagtype);
1964 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
1966 + return acl_set_qualifier(entry, qual);
1969 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1971 + return acl_set_permset(entry, permset);
1974 +int sys_acl_valid(SMB_ACL_T theacl)
1976 + return acl_valid(theacl);
1979 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1981 + return acl_set_file(name, acltype, theacl);
1984 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
1986 + return acl_set_fd(fd, theacl);
1989 +int sys_acl_delete_def_file(const char *name)
1991 + return acl_delete_def_file(name);
1994 +int sys_acl_free_text(char *text)
1996 + return acl_free(text);
1999 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2001 + return acl_free(the_acl);
2004 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2006 + return acl_free(qual);
2009 +#elif defined(HAVE_TRU64_ACLS)
2010 +/* The interface to DEC/Compaq Tru64 UNIX ACLs
2011 + * is based on Draft 13 of the POSIX spec which is
2012 + * slightly different from the Draft 16 interface.
2014 + * Also, some of the permset manipulation functions
2015 + * such as acl_clear_perm() and acl_add_perm() appear
2016 + * to be broken on Tru64 so we have to manipulate
2017 + * the permission bits in the permset directly. */
2018 + int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2020 + SMB_ACL_ENTRY_T entry;
2022 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2027 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2032 + return errno ? -1 : 0;
2035 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2037 + return acl_get_tag_type(entry_d, tag_type_p);
2040 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2042 + return acl_get_permset(entry_d, permset_p);
2045 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2047 + return acl_get_qualifier(entry_d);
2050 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2052 + return acl_get_file((char *)path_p, type);
2055 + SMB_ACL_T sys_acl_get_fd(int fd)
2057 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2060 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2062 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2067 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2069 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2074 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2079 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2081 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2084 + char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen)
2086 + return acl_to_text(the_acl, plen);
2089 + SMB_ACL_T sys_acl_init(int count)
2091 + return acl_init(count);
2094 + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2096 + SMB_ACL_ENTRY_T entry;
2098 + if ((entry = acl_create_entry(pacl)) == NULL) {
2106 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2108 + return acl_set_tag_type(entry, tagtype);
2111 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
2113 + return acl_set_qualifier(entry, qual);
2116 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2118 + return acl_set_permset(entry, permset);
2121 + int sys_acl_valid(SMB_ACL_T theacl)
2123 + acl_entry_t entry;
2125 + return acl_valid(theacl, &entry);
2128 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2130 + return acl_set_file((char *)name, acltype, theacl);
2133 + int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
2135 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2138 + int sys_acl_delete_def_file(const char *name)
2140 + return acl_delete_def_file((char *)name);
2143 + int sys_acl_free_text(char *text)
2145 + /* (void) cast and explicit return 0 are for DEC UNIX
2146 + * which just #defines acl_free_text() to be free(). */
2147 + (void) acl_free_text(text);
2151 + int sys_acl_free_acl(SMB_ACL_T the_acl)
2153 + return acl_free(the_acl);
2156 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2158 + return acl_free_qualifier(qual, tagtype);
2161 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2163 +/* Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2164 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. */
2166 +/* Note that while this code implements sufficient functionality
2167 + * to support the sys_acl_* interfaces it does not provide all
2168 + * of the semantics of the POSIX ACL interfaces.
2170 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2171 + * from a call to sys_acl_get_entry() should not be assumed to be
2172 + * valid after calling any of the following functions, which may
2173 + * reorder the entries in the ACL.
2176 + * sys_acl_set_file()
2177 + * sys_acl_set_fd()
2180 +/* The only difference between Solaris and UnixWare / OpenUNIX is
2181 + * that the #defines for the ACL operations have different names. */
2182 +#if defined(HAVE_UNIXWARE_ACLS)
2184 +#define SETACL ACL_SET
2185 +#define GETACL ACL_GET
2186 +#define GETACLCNT ACL_CNT
2191 + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2193 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2198 + if (entry_p == NULL) {
2203 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2207 + if (acl_d->next < 0) {
2212 + if (acl_d->next >= acl_d->count) {
2216 + *entry_p = &acl_d->acl[acl_d->next++];
2221 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2223 + *type_p = entry_d->a_type;
2228 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2230 + *permset_p = &entry_d->a_perm;
2235 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2237 + if (entry_d->a_type != SMB_ACL_USER
2238 + && entry_d->a_type != SMB_ACL_GROUP) {
2243 + return &entry_d->a_id;
2246 +/* There is no way of knowing what size the ACL returned by
2247 + * GETACL will be unless you first call GETACLCNT which means
2248 + * making an additional system call.
2250 + * In the hope of avoiding the cost of the additional system
2251 + * call in most cases, we initially allocate enough space for
2252 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2253 + * be too small then we use GETACLCNT to find out the actual
2254 + * size, reallocate the ACL buffer, and then call GETACL again. */
2256 +#define INITIAL_ACL_SIZE 16
2258 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2261 + int count; /* # of ACL entries allocated */
2262 + int naccess; /* # of access ACL entries */
2263 + int ndefault; /* # of default ACL entries */
2265 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2270 + count = INITIAL_ACL_SIZE;
2271 + if ((acl_d = sys_acl_init(count)) == NULL) {
2275 + /* If there isn't enough space for the ACL entries we use
2276 + * GETACLCNT to determine the actual number of ACL entries
2277 + * reallocate and try again. This is in a loop because it
2278 + * is possible that someone else could modify the ACL and
2279 + * increase the number of entries between the call to
2280 + * GETACLCNT and the call to GETACL. */
2281 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2282 + && errno == ENOSPC) {
2284 + sys_acl_free_acl(acl_d);
2286 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2290 + if ((acl_d = sys_acl_init(count)) == NULL) {
2296 + sys_acl_free_acl(acl_d);
2300 + /* Calculate the number of access and default ACL entries.
2302 + * Note: we assume that the acl() system call returned a
2303 + * well formed ACL which is sorted so that all of the
2304 + * access ACL entries preceed any default ACL entries. */
2305 + for (naccess = 0; naccess < count; naccess++) {
2306 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2309 + ndefault = count - naccess;
2311 + /* If the caller wants the default ACL we have to copy
2312 + * the entries down to the start of the acl[] buffer
2313 + * and mask out the ACL_DEFAULT flag from the type field. */
2314 + if (type == SMB_ACL_TYPE_DEFAULT) {
2317 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2318 + acl_d->acl[i] = acl_d->acl[j];
2319 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2322 + acl_d->count = ndefault;
2324 + acl_d->count = naccess;
2330 + SMB_ACL_T sys_acl_get_fd(int fd)
2333 + int count; /* # of ACL entries allocated */
2334 + int naccess; /* # of access ACL entries */
2336 + count = INITIAL_ACL_SIZE;
2337 + if ((acl_d = sys_acl_init(count)) == NULL) {
2341 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2342 + && errno == ENOSPC) {
2344 + sys_acl_free_acl(acl_d);
2346 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2350 + if ((acl_d = sys_acl_init(count)) == NULL) {
2356 + sys_acl_free_acl(acl_d);
2360 + /* Calculate the number of access ACL entries. */
2361 + for (naccess = 0; naccess < count; naccess++) {
2362 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2366 + acl_d->count = naccess;
2371 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2378 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2380 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2381 + && perm != SMB_ACL_EXECUTE) {
2386 + if (permset_d == NULL) {
2391 + *permset_d |= perm;
2396 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2398 + return *permset_d & perm;
2401 + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2407 + /* Use an initial estimate of 20 bytes per ACL entry
2408 + * when allocating memory for the text representation
2411 + maxlen = 20 * acl_d->count;
2412 + if ((text = malloc(maxlen)) == NULL) {
2417 + for (i = 0; i < acl_d->count; i++) {
2418 + struct acl *ap = &acl_d->acl[i];
2419 + struct passwd *pw;
2428 + switch (ap->a_type) {
2429 + /* For debugging purposes it's probably more
2430 + * useful to dump unknown tag types rather
2431 + * than just returning an error. */
2433 + snprintf(tagbuf, sizeof tagbuf - 1, "0x%x",
2436 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
2441 + case SMB_ACL_USER:
2442 + if ((pw = getpwuid(ap->a_id)) == NULL) {
2443 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
2449 + case SMB_ACL_USER_OBJ:
2453 + case SMB_ACL_GROUP:
2454 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2455 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
2461 + case SMB_ACL_GROUP_OBJ:
2465 + case SMB_ACL_OTHER:
2469 + case SMB_ACL_MASK:
2475 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2476 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2477 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2480 + /* <tag> : <qualifier> : rwx \n \0 */
2481 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2483 + /* If this entry would overflow the buffer
2484 + * allocate enough additional memory for this
2485 + * entry and an estimate of another 20 bytes
2486 + * for each entry still to be processed. */
2487 + if ((len + nbytes) > maxlen) {
2488 + char *oldtext = text;
2490 + maxlen += nbytes + 20 * (acl_d->count - i);
2492 + if ((text = Realloc(oldtext, maxlen)) == NULL) {
2499 + snprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2500 + len += nbytes - 1;
2509 + SMB_ACL_T sys_acl_init(int count)
2518 + /* Note that since the definition of the structure pointed
2519 + * to by the SMB_ACL_T includes the first element of the
2520 + * acl[] array, this actually allocates an ACL with room
2521 + * for (count+1) entries. */
2522 + if ((a = malloc(sizeof a[0] + count * sizeof (struct acl))) == NULL) {
2527 + a->size = count + 1;
2535 + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2538 + SMB_ACL_ENTRY_T entry_d;
2540 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2545 + if (acl_d->count >= acl_d->size) {
2550 + entry_d = &acl_d->acl[acl_d->count++];
2551 + entry_d->a_type = 0;
2552 + entry_d->a_id = -1;
2553 + entry_d->a_perm = 0;
2554 + *entry_p = entry_d;
2559 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2561 + switch (tag_type) {
2562 + case SMB_ACL_USER:
2563 + case SMB_ACL_USER_OBJ:
2564 + case SMB_ACL_GROUP:
2565 + case SMB_ACL_GROUP_OBJ:
2566 + case SMB_ACL_OTHER:
2567 + case SMB_ACL_MASK:
2568 + entry_d->a_type = tag_type;
2578 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2580 + if (entry_d->a_type != SMB_ACL_GROUP
2581 + && entry_d->a_type != SMB_ACL_USER) {
2586 + entry_d->a_id = *((id_t *)qual_p);
2591 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2593 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2597 + entry_d->a_perm = *permset_d;
2602 +/* Sort the ACL and check it for validity.
2604 + * If it's a minimal ACL with only 4 entries then we
2605 + * need to recalculate the mask permissions to make
2606 + * sure that they are the same as the GROUP_OBJ
2607 + * permissions as required by the UnixWare acl() system call.
2609 + * (Note: since POSIX allows minimal ACLs which only contain
2610 + * 3 entries - ie there is no mask entry - we should, in theory,
2611 + * check for this and add a mask entry if necessary - however
2612 + * we "know" that the caller of this interface always specifies
2613 + * a mask so, in practice "this never happens" (tm) - if it *does*
2614 + * happen aclsort() will fail and return an error and someone will
2615 + * have to fix it ...) */
2617 +static int acl_sort(SMB_ACL_T acl_d)
2619 + int fixmask = (acl_d->count <= 4);
2621 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2628 + int sys_acl_valid(SMB_ACL_T acl_d)
2630 + return acl_sort(acl_d);
2633 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2636 + struct acl *acl_p;
2638 + struct acl *acl_buf = NULL;
2641 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2646 + if (acl_sort(acl_d) != 0) {
2650 + acl_p = &acl_d->acl[0];
2651 + acl_count = acl_d->count;
2653 + /* If it's a directory there is extra work to do since the acl()
2654 + * system call will replace both the access ACLs and the default
2655 + * ACLs (if any). */
2656 + if (stat(name, &s) != 0) {
2659 + if (S_ISDIR(s.st_mode)) {
2660 + SMB_ACL_T acc_acl;
2661 + SMB_ACL_T def_acl;
2662 + SMB_ACL_T tmp_acl;
2665 + if (type == SMB_ACL_TYPE_ACCESS) {
2667 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2671 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2674 + if (tmp_acl == NULL) {
2678 + /* Allocate a temporary buffer for the complete ACL. */
2679 + acl_count = acc_acl->count + def_acl->count;
2680 + acl_p = acl_buf = malloc(acl_count * sizeof acl_buf[0]);
2682 + if (acl_buf == NULL) {
2683 + sys_acl_free_acl(tmp_acl);
2688 + /* Copy the access control and default entries into the buffer. */
2689 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2690 + acc_acl->count * sizeof acl_buf[0]);
2692 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2693 + def_acl->count * sizeof acl_buf[0]);
2695 + /* Set the ACL_DEFAULT flag on the default entries. */
2696 + for (i = acc_acl->count; i < acl_count; i++) {
2697 + acl_buf[i].a_type |= ACL_DEFAULT;
2700 + sys_acl_free_acl(tmp_acl);
2702 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2707 + ret = acl(name, SETACL, acl_count, acl_p);
2714 + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2716 + if (acl_sort(acl_d) != 0) {
2720 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2723 + int sys_acl_delete_def_file(const char *path)
2728 + /* Fetching the access ACL and rewriting it has the effect of
2729 + * deleting the default ACL. */
2730 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2734 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2736 + sys_acl_free_acl(acl_d);
2741 + int sys_acl_free_text(char *text)
2747 + int sys_acl_free_acl(SMB_ACL_T acl_d)
2753 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2758 +#elif defined(HAVE_HPUX_ACLS)
2761 +/* Based on the Solaris/SCO code - with modifications. */
2763 +/* Note that while this code implements sufficient functionality
2764 + * to support the sys_acl_* interfaces it does not provide all
2765 + * of the semantics of the POSIX ACL interfaces.
2767 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2768 + * from a call to sys_acl_get_entry() should not be assumed to be
2769 + * valid after calling any of the following functions, which may
2770 + * reorder the entries in the ACL.
2773 + * sys_acl_set_file()
2774 + * sys_acl_set_fd()
2777 +/* This checks if the POSIX ACL system call is defined which basically
2778 + * corresponds to whether JFS 3.3 or higher is installed. If acl() was
2779 + * called when it isn't defined, it causes the process to core dump so
2780 + * it is important to check this and avoid acl() calls if it isn't
2783 +static BOOL hpux_acl_call_presence(void)
2786 + shl_t handle = NULL;
2789 + static BOOL already_checked=0;
2791 + if (already_checked)
2795 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2797 + if (ret_val != 0) {
2798 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2799 + ret_val, errno, strerror(errno)));
2800 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2804 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2806 + already_checked = True;
2810 + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2812 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2817 + if (entry_p == NULL) {
2822 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2826 + if (acl_d->next < 0) {
2831 + if (acl_d->next >= acl_d->count) {
2835 + *entry_p = &acl_d->acl[acl_d->next++];
2840 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2842 + *type_p = entry_d->a_type;
2847 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2849 + *permset_p = &entry_d->a_perm;
2854 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2856 + if (entry_d->a_type != SMB_ACL_USER
2857 + && entry_d->a_type != SMB_ACL_GROUP) {
2862 + return &entry_d->a_id;
2865 +/* There is no way of knowing what size the ACL returned by
2866 + * ACL_GET will be unless you first call ACL_CNT which means
2867 + * making an additional system call.
2869 + * In the hope of avoiding the cost of the additional system
2870 + * call in most cases, we initially allocate enough space for
2871 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2872 + * be too small then we use ACL_CNT to find out the actual
2873 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2876 +#define INITIAL_ACL_SIZE 16
2878 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2881 + int count; /* # of ACL entries allocated */
2882 + int naccess; /* # of access ACL entries */
2883 + int ndefault; /* # of default ACL entries */
2885 + if (hpux_acl_call_presence() == False) {
2886 + /* Looks like we don't have the acl() system call on HPUX.
2887 + * May be the system doesn't have the latest version of JFS. */
2891 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2896 + count = INITIAL_ACL_SIZE;
2897 + if ((acl_d = sys_acl_init(count)) == NULL) {
2901 + /* If there isn't enough space for the ACL entries we use
2902 + * ACL_CNT to determine the actual number of ACL entries
2903 + * reallocate and try again. This is in a loop because it
2904 + * is possible that someone else could modify the ACL and
2905 + * increase the number of entries between the call to
2906 + * ACL_CNT and the call to ACL_GET. */
2907 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2909 + sys_acl_free_acl(acl_d);
2911 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2915 + if ((acl_d = sys_acl_init(count)) == NULL) {
2921 + sys_acl_free_acl(acl_d);
2925 + /* Calculate the number of access and default ACL entries.
2927 + * Note: we assume that the acl() system call returned a
2928 + * well formed ACL which is sorted so that all of the
2929 + * access ACL entries preceed any default ACL entries. */
2930 + for (naccess = 0; naccess < count; naccess++) {
2931 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2934 + ndefault = count - naccess;
2936 + /* If the caller wants the default ACL we have to copy
2937 + * the entries down to the start of the acl[] buffer
2938 + * and mask out the ACL_DEFAULT flag from the type field. */
2939 + if (type == SMB_ACL_TYPE_DEFAULT) {
2942 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2943 + acl_d->acl[i] = acl_d->acl[j];
2944 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2947 + acl_d->count = ndefault;
2949 + acl_d->count = naccess;
2955 + SMB_ACL_T sys_acl_get_fd(int fd)
2957 + /* HPUX doesn't have the facl call. Fake it using the path.... JRA. */
2959 + files_struct *fsp = file_find_fd(fd);
2961 + if (fsp == NULL) {
2966 + /* We know we're in the same conn context. So we can use the
2967 + * relative path. */
2969 + return sys_acl_get_file(dos_to_unix_static(fsp->fsp_name), SMB_ACL_TYPE_ACCESS);
2972 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2979 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2981 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2982 + && perm != SMB_ACL_EXECUTE) {
2987 + if (permset_d == NULL) {
2992 + *permset_d |= perm;
2997 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2999 + return *permset_d & perm;
3002 + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3008 + /* Use an initial estimate of 20 bytes per ACL entry when
3009 + * allocating memory for the text representation of the ACL. */
3011 + maxlen = 20 * acl_d->count;
3012 + if ((text = malloc(maxlen)) == NULL) {
3017 + for (i = 0; i < acl_d->count; i++) {
3018 + struct acl *ap = &acl_d->acl[i];
3019 + struct passwd *pw;
3028 + switch (ap->a_type) {
3029 + /* For debugging purposes it's probably more
3030 + * useful to dump unknown tag types rather
3031 + * than just returning an error. */
3033 + snprintf(tagbuf, sizeof tagbuf - 1, "0x%x",
3036 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
3041 + case SMB_ACL_USER:
3042 + if ((pw = getpwuid(ap->a_id)) == NULL) {
3043 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
3049 + case SMB_ACL_USER_OBJ:
3053 + case SMB_ACL_GROUP:
3054 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3055 + snprintf(idbuf, sizeof idbuf - 1, "%ld",
3061 + case SMB_ACL_GROUP_OBJ:
3065 + case SMB_ACL_OTHER:
3069 + case SMB_ACL_MASK:
3075 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3076 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3077 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3080 + /* <tag> : <qualifier> : rwx \n \0 */
3081 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3083 + /* If this entry would overflow the buffer
3084 + * allocate enough additional memory for this
3085 + * entry and an estimate of another 20 bytes
3086 + * for each entry still to be processed. */
3087 + if ((len + nbytes) > maxlen) {
3088 + char *oldtext = text;
3090 + maxlen += nbytes + 20 * (acl_d->count - i);
3092 + if ((text = Realloc(oldtext, maxlen)) == NULL) {
3099 + snprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3100 + len += nbytes - 1;
3109 + SMB_ACL_T sys_acl_init(int count)
3118 + /* Note that since the definition of the structure pointed
3119 + * to by the SMB_ACL_T includes the first element of the
3120 + * acl[] array, this actually allocates an ACL with room
3121 + * for (count+1) entries. */
3122 + if ((a = malloc(sizeof a[0] + count * sizeof (struct acl))) == NULL) {
3127 + a->size = count + 1;
3135 + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3138 + SMB_ACL_ENTRY_T entry_d;
3140 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3145 + if (acl_d->count >= acl_d->size) {
3150 + entry_d = &acl_d->acl[acl_d->count++];
3151 + entry_d->a_type = 0;
3152 + entry_d->a_id = -1;
3153 + entry_d->a_perm = 0;
3154 + *entry_p = entry_d;
3159 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3161 + switch (tag_type) {
3162 + case SMB_ACL_USER:
3163 + case SMB_ACL_USER_OBJ:
3164 + case SMB_ACL_GROUP:
3165 + case SMB_ACL_GROUP_OBJ:
3166 + case SMB_ACL_OTHER:
3167 + case SMB_ACL_MASK:
3168 + entry_d->a_type = tag_type;
3178 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3180 + if (entry_d->a_type != SMB_ACL_GROUP
3181 + && entry_d->a_type != SMB_ACL_USER) {
3186 + entry_d->a_id = *((id_t *)qual_p);
3191 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3193 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3197 + entry_d->a_perm = *permset_d;
3202 +/* Structure to capture the count for each type of ACE. */
3204 +struct hpux_acl_types {
3208 + int n_def_user_obj;
3213 + int n_def_group_obj;
3217 + int n_def_other_obj;
3220 + int n_def_class_obj;
3222 + int n_illegal_obj;
3226 + * Counts the different number of objects in a given array of ACL
3230 + * acl_count - Count of ACLs in the array of ACL strucutres.
3231 + * aclp - Array of ACL structures.
3232 + * acl_type_count - Pointer to acl_types structure. Should already be
3236 + * acl_type_count - This structure is filled up with counts of various
3240 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3244 + memset(acl_type_count, 0, sizeof (struct hpux_acl_types));
3246 + for (i=0;i<acl_count;i++) {
3247 + switch (aclp[i].a_type) {
3249 + acl_type_count->n_user++;
3252 + acl_type_count->n_user_obj++;
3254 + case DEF_USER_OBJ:
3255 + acl_type_count->n_def_user_obj++;
3258 + acl_type_count->n_group++;
3261 + acl_type_count->n_group_obj++;
3263 + case DEF_GROUP_OBJ:
3264 + acl_type_count->n_def_group_obj++;
3267 + acl_type_count->n_other_obj++;
3269 + case DEF_OTHER_OBJ:
3270 + acl_type_count->n_def_other_obj++;
3273 + acl_type_count->n_class_obj++;
3275 + case DEF_CLASS_OBJ:
3276 + acl_type_count->n_def_class_obj++;
3279 + acl_type_count->n_def_user++;
3282 + acl_type_count->n_def_group++;
3285 + acl_type_count->n_illegal_obj++;
3291 +/* swap_acl_entries: Swaps two ACL entries.
3293 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3296 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3298 + struct acl temp_acl;
3300 + temp_acl.a_type = aclp0->a_type;
3301 + temp_acl.a_id = aclp0->a_id;
3302 + temp_acl.a_perm = aclp0->a_perm;
3304 + aclp0->a_type = aclp1->a_type;
3305 + aclp0->a_id = aclp1->a_id;
3306 + aclp0->a_perm = aclp1->a_perm;
3308 + aclp1->a_type = temp_acl.a_type;
3309 + aclp1->a_id = temp_acl.a_id;
3310 + aclp1->a_perm = temp_acl.a_perm;
3313 +/* prohibited_duplicate_type
3314 + * Identifies if given ACL type can have duplicate entries or
3317 + * Inputs: acl_type - ACL Type.
3323 + * True - If the ACL type matches any of the prohibited types.
3324 + * False - If the ACL type doesn't match any of the prohibited types.
3327 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3329 + switch (acl_type) {
3339 +/* get_needed_class_perm
3340 + * Returns the permissions of a ACL structure only if the ACL
3341 + * type matches one of the pre-determined types for computing
3342 + * CLASS_OBJ permissions.
3344 + * Inputs: aclp - Pointer to ACL structure.
3347 +static int hpux_get_needed_class_perm(struct acl *aclp)
3349 + switch (aclp->a_type) {
3353 + case DEF_USER_OBJ:
3355 + case DEF_GROUP_OBJ:
3357 + case DEF_CLASS_OBJ:
3358 + case DEF_OTHER_OBJ:
3359 + return aclp->a_perm;
3365 +/* acl_sort for HPUX.
3366 + * Sorts the array of ACL structures as per the description in
3367 + * aclsort man page. Refer to aclsort man page for more details
3371 + * acl_count - Count of ACLs in the array of ACL structures.
3372 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3374 + * aclp - Array of ACL structures.
3378 + * aclp - Sorted array of ACL structures.
3382 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3383 + * debug log in case of failure.
3386 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3388 +#if !defined(HAVE_HPUX_ACLSORT)
3389 + /* The aclsort() system call is availabe on the latest HPUX General
3390 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3391 + * function. Because, we don't want to update to a new
3392 + * HPUX GR bundle just for aclsort() call. */
3394 + struct hpux_acl_types acl_obj_count;
3395 + int n_class_obj_perm = 0;
3399 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3403 + if (aclp == NULL) {
3404 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3408 + /* Count different types of ACLs in the ACLs array */
3410 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3412 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3413 + * CLASS_OBJ and OTHER_OBJ
3416 + if (acl_obj_count.n_user_obj != 1
3417 + || acl_obj_count.n_group_obj != 1
3418 + || acl_obj_count.n_class_obj != 1
3419 + || acl_obj_count.n_other_obj != 1) {
3420 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3421 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3425 + /* If any of the default objects are present, there should be only
3426 + * one of them each.
3429 + if (acl_obj_count.n_def_user_obj > 1 || acl_obj_count.n_def_group_obj > 1 ||
3430 + acl_obj_count.n_def_other_obj > 1 || acl_obj_count.n_def_class_obj > 1) {
3431 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3432 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3436 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3439 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3440 + * same ACL type, sort by ACL id.
3442 + * I am using the trival kind of sorting method here because, performance isn't
3443 + * really effected by the ACLs feature. More over there aren't going to be more
3444 + * than 17 entries on HPUX.
3447 + for (i=0; i<acl_count;i++) {
3448 + for (j=i+1; j<acl_count; j++) {
3449 + if (aclp[i].a_type > aclp[j].a_type) {
3450 + /* ACL entries out of order, swap them */
3452 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3454 + } else if (aclp[i].a_type == aclp[j].a_type) {
3456 + /* ACL entries of same type, sort by id */
3458 + if (aclp[i].a_id > aclp[j].a_id) {
3459 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3460 + } else if (aclp[i].a_id == aclp[j].a_id) {
3461 + /* We have a duplicate entry. */
3462 + if (hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3463 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3464 + aclp[i].a_type, aclp[i].a_id));
3473 + /* set the class obj permissions to the computed one. */
3475 + int n_class_obj_index = -1;
3477 + for (i=0;i<acl_count;i++) {
3478 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3480 + if (aclp[i].a_type == CLASS_OBJ)
3481 + n_class_obj_index = i;
3483 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3488 + return aclsort(acl_count, calclass, aclp);
3492 +/* Sort the ACL and check it for validity.
3494 + * If it's a minimal ACL with only 4 entries then we
3495 + * need to recalculate the mask permissions to make
3496 + * sure that they are the same as the GROUP_OBJ
3497 + * permissions as required by the UnixWare acl() system call.
3499 + * (Note: since POSIX allows minimal ACLs which only contain
3500 + * 3 entries - ie there is no mask entry - we should, in theory,
3501 + * check for this and add a mask entry if necessary - however
3502 + * we "know" that the caller of this interface always specifies
3503 + * a mask so, in practice "this never happens" (tm) - if it *does*
3504 + * happen aclsort() will fail and return an error and someone will
3505 + * have to fix it ...) */
3507 +static int acl_sort(SMB_ACL_T acl_d)
3509 + int fixmask = (acl_d->count <= 4);
3511 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3518 + int sys_acl_valid(SMB_ACL_T acl_d)
3520 + return acl_sort(acl_d);
3523 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3526 + struct acl *acl_p;
3528 + struct acl *acl_buf = NULL;
3531 + if (hpux_acl_call_presence() == False) {
3532 + /* Looks like we don't have the acl() system call on HPUX.
3533 + * May be the system doesn't have the latest version of JFS. */
3538 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3543 + if (acl_sort(acl_d) != 0) {
3547 + acl_p = &acl_d->acl[0];
3548 + acl_count = acl_d->count;
3550 + /* If it's a directory there is extra work to do since the acl()
3551 + * system call will replace both the access ACLs and the default
3552 + * ACLs (if any). */
3553 + if (stat(name, &s) != 0) {
3556 + if (S_ISDIR(s.st_mode)) {
3557 + SMB_ACL_T acc_acl;
3558 + SMB_ACL_T def_acl;
3559 + SMB_ACL_T tmp_acl;
3562 + if (type == SMB_ACL_TYPE_ACCESS) {
3564 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3568 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3571 + if (tmp_acl == NULL) {
3575 + /* Allocate a temporary buffer for the complete ACL. */
3576 + acl_count = acc_acl->count + def_acl->count;
3577 + acl_p = acl_buf = malloc(acl_count * sizeof acl_buf[0]);
3579 + if (acl_buf == NULL) {
3580 + sys_acl_free_acl(tmp_acl);
3585 + /* Copy the access control and default entries into the buffer. */
3586 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3587 + acc_acl->count * sizeof acl_buf[0]);
3589 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3590 + def_acl->count * sizeof acl_buf[0]);
3592 + /* Set the ACL_DEFAULT flag on the default entries. */
3593 + for (i = acc_acl->count; i < acl_count; i++) {
3594 + acl_buf[i].a_type |= ACL_DEFAULT;
3597 + sys_acl_free_acl(tmp_acl);
3599 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3604 + ret = acl(name, ACL_SET, acl_count, acl_p);
3611 + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3613 + /* HPUX doesn't have the facl call. Fake it using the path.... JRA. */
3615 + files_struct *fsp = file_find_fd(fd);
3617 + if (fsp == NULL) {
3622 + if (acl_sort(acl_d) != 0) {
3626 + /* We know we're in the same conn context. So we can use the
3627 + * relative path. */
3629 + return sys_acl_set_file(dos_to_unix_static(fsp->fsp_name), SMB_ACL_TYPE_ACCESS, acl_d);
3632 + int sys_acl_delete_def_file(const char *path)
3637 + /* Fetching the access ACL and rewriting it has the effect of
3638 + * deleting the default ACL. */
3639 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3643 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3645 + sys_acl_free_acl(acl_d);
3650 + int sys_acl_free_text(char *text)
3656 + int sys_acl_free_acl(SMB_ACL_T acl_d)
3662 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3667 +#elif defined(HAVE_IRIX_ACLS)
3669 + int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3671 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3676 + if (entry_p == NULL) {
3681 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3685 + if (acl_d->next < 0) {
3690 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3694 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3699 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3701 + *type_p = entry_d->ae_tag;
3706 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3708 + *permset_p = entry_d;
3713 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3715 + if (entry_d->ae_tag != SMB_ACL_USER
3716 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3721 + return &entry_d->ae_id;
3724 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3728 + if ((a = malloc(sizeof a[0])) == NULL) {
3732 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3737 + a->freeaclp = True;
3741 + SMB_ACL_T sys_acl_get_fd(int fd)
3745 + if ((a = malloc(sizeof a[0])) == NULL) {
3749 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3754 + a->freeaclp = True;
3758 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3760 + permset_d->ae_perm = 0;
3765 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3767 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3768 + && perm != SMB_ACL_EXECUTE) {
3773 + if (permset_d == NULL) {
3778 + permset_d->ae_perm |= perm;
3783 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3785 + return permset_d->ae_perm & perm;
3788 + char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3790 + return acl_to_text(acl_d->aclp, len_p);
3793 + SMB_ACL_T sys_acl_init(int count)
3802 + if ((a = malloc(sizeof a[0] + sizeof (struct acl))) == NULL) {
3808 + a->freeaclp = False;
3809 + a->aclp = (struct acl *)(&a->aclp + sizeof (struct acl *));
3810 + a->aclp->acl_cnt = 0;
3816 + int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3819 + SMB_ACL_ENTRY_T entry_d;
3821 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3826 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3831 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3832 + entry_d->ae_tag = 0;
3833 + entry_d->ae_id = 0;
3834 + entry_d->ae_perm = 0;
3835 + *entry_p = entry_d;
3840 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3842 + switch (tag_type) {
3843 + case SMB_ACL_USER:
3844 + case SMB_ACL_USER_OBJ:
3845 + case SMB_ACL_GROUP:
3846 + case SMB_ACL_GROUP_OBJ:
3847 + case SMB_ACL_OTHER:
3848 + case SMB_ACL_MASK:
3849 + entry_d->ae_tag = tag_type;
3859 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3861 + if (entry_d->ae_tag != SMB_ACL_GROUP
3862 + && entry_d->ae_tag != SMB_ACL_USER) {
3867 + entry_d->ae_id = *((id_t *)qual_p);
3872 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3874 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3878 + entry_d->ae_perm = permset_d->ae_perm;
3883 + int sys_acl_valid(SMB_ACL_T acl_d)
3885 + return acl_valid(acl_d->aclp);
3888 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3890 + return acl_set_file(name, type, acl_d->aclp);
3893 + int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3895 + return acl_set_fd(fd, acl_d->aclp);
3898 + int sys_acl_delete_def_file(const char *name)
3900 + return acl_delete_def_file(name);
3903 + int sys_acl_free_text(char *text)
3905 + return acl_free(text);
3908 + int sys_acl_free_acl(SMB_ACL_T acl_d)
3910 + if (acl_d->freeaclp) {
3911 + acl_free(acl_d->aclp);
3917 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3922 +#elif defined(HAVE_AIX_ACLS)
3924 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3926 + int sys_acl_get_entry(SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3928 + struct acl_entry_link *link;
3929 + struct new_acl_entry *entry;
3932 + DEBUG(10,("This is the count: %d\n",theacl->count));
3934 + /* Check if count was previously set to -1. If it was, that
3935 + * means we reached the end of the acl last time. */
3936 + if (theacl->count == -1)
3940 + /* To get to the next acl, traverse linked list until index of
3941 + * acl matches the count we are keeping. This count is
3942 + * incremented each time we return an acl entry. */
3944 + for (keep_going = 0; keep_going < theacl->count; keep_going++)
3945 + link = link->nextp;
3947 + entry = *entry_p = link->entryp;
3949 + DEBUG(10,("*entry_p is %d\n",entry_p));
3950 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3952 + /* Increment count */
3954 + if (link->nextp == NULL)
3955 + theacl->count = -1;
3960 + int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3962 + /* Initialize tag type */
3965 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3967 + /* Depending on what type of entry we have, return tag type. */
3968 + switch (entry_d->ace_id->id_type) {
3970 + *tag_type_p = SMB_ACL_USER;
3973 + *tag_type_p = SMB_ACL_GROUP;
3976 + case SMB_ACL_USER_OBJ:
3977 + case SMB_ACL_GROUP_OBJ:
3978 + case SMB_ACL_OTHER:
3979 + *tag_type_p = entry_d->ace_id->id_type;
3989 + int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3991 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3992 + *permset_p = &entry_d->ace_access;
3993 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3994 + if (!(**permset_p & S_IXUSR)
3995 + && !(**permset_p & S_IWUSR)
3996 + && !(**permset_p & S_IRUSR)
3997 + && **permset_p != 0)
4000 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4004 + void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4006 + return entry_d->ace_id->id_data;
4009 + SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4011 + struct acl *file_acl = (struct acl *)NULL;
4012 + struct acl_entry *acl_entry;
4013 + struct new_acl_entry *new_acl_entry;
4014 + struct ace_id *idp;
4015 + struct acl_entry_link *acl_entry_link;
4016 + struct acl_entry_link *acl_entry_link_head;
4021 + /* Get the acl using statacl */
4023 + DEBUG(10,("Entering sys_acl_get_file\n"));
4024 + DEBUG(10,("path_p is %s\n",path_p));
4026 + file_acl = (struct acl *)malloc(BUFSIZ);
4028 + if (file_acl == NULL) {
4030 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4034 + memset(file_acl,0,BUFSIZ);
4036 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4038 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4043 + DEBUG(10,("Got facl and returned it\n"));
4045 + /* Point to the first acl entry in the acl */
4046 + acl_entry = file_acl->acl_ext;
4048 + /* Begin setting up the head of the linked list that will be
4049 + * used for the storing the acl in a way that is useful for the
4050 + * posix_acls.c code. */
4052 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4053 + if (acl_entry_link_head == NULL)
4056 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4057 + if (acl_entry_link->entryp == NULL) {
4060 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4064 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4065 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4067 + /* Check if the extended acl bit is on. If it isn't, do not
4068 + * show the contents of the acl since AIX intends the extended
4069 + * info to remain unused. */
4071 + if (file_acl->acl_mode & S_IXACL){
4072 + /* while we are not pointing to the very end */
4073 + while (acl_entry < acl_last(file_acl)) {
4074 + /* before we malloc anything, make sure this is */
4075 + /* a valid acl entry and one that we want to map */
4076 + idp = id_nxt(acl_entry->ace_id);
4077 + if ((acl_entry->ace_type == ACC_SPECIFY
4078 + || acl_entry->ace_type == ACC_PERMIT)
4079 + && idp != id_last(acl_entry)) {
4080 + acl_entry = acl_nxt(acl_entry);
4084 + idp = acl_entry->ace_id;
4086 + /* Check if this is the first entry in the linked list.
4087 + * The first entry needs to keep prevp pointing to NULL
4088 + * and already has entryp allocated. */
4090 + if (acl_entry_link_head->count != 0) {
4091 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4093 + if (acl_entry_link->nextp == NULL) {
4096 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4100 + acl_entry_link->nextp->prevp = acl_entry_link;
4101 + acl_entry_link = acl_entry_link->nextp;
4102 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4103 + if (acl_entry_link->entryp == NULL) {
4106 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4109 + acl_entry_link->nextp = NULL;
4112 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4114 + /* Don't really need this since all types are going
4115 + * to be specified but, it's better than leaving it 0. */
4117 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4119 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4121 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof (struct ace_id));
4123 + /* The access in the acl entries must be left shifted by
4124 + * three bites, because they will ultimately be compared
4125 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4127 + switch (acl_entry->ace_type){
4130 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4131 + acl_entry_link->entryp->ace_access <<= 6;
4132 + acl_entry_link_head->count++;
4135 + /* Since there is no way to return a DENY acl entry
4136 + * change to PERMIT and then shift. */
4137 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4138 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4139 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4140 + acl_entry_link->entryp->ace_access <<= 6;
4141 + acl_entry_link_head->count++;
4147 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4148 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4150 + acl_entry = acl_nxt(acl_entry);
4152 + } /* end of if enabled */
4154 + /* Since owner, group, other acl entries are not part of the acl
4155 + * entries in an acl, they must be dummied up to become part of
4158 + for (i = 1; i < 4; i++) {
4159 + DEBUG(10,("i is %d\n",i));
4160 + if (acl_entry_link_head->count != 0) {
4161 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4162 + if (acl_entry_link->nextp == NULL) {
4165 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4169 + acl_entry_link->nextp->prevp = acl_entry_link;
4170 + acl_entry_link = acl_entry_link->nextp;
4171 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4172 + if (acl_entry_link->entryp == NULL) {
4175 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4180 + acl_entry_link->nextp = NULL;
4182 + new_acl_entry = acl_entry_link->entryp;
4183 + idp = new_acl_entry->ace_id;
4185 + new_acl_entry->ace_len = sizeof (struct acl_entry);
4186 + new_acl_entry->ace_type = ACC_PERMIT;
4187 + idp->id_len = sizeof (struct ace_id);
4188 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4189 + memset(idp->id_data,0,sizeof (uid_t));
4193 + new_acl_entry->ace_access = file_acl->g_access << 6;
4194 + idp->id_type = SMB_ACL_GROUP_OBJ;
4198 + new_acl_entry->ace_access = file_acl->o_access << 6;
4199 + idp->id_type = SMB_ACL_OTHER;
4203 + new_acl_entry->ace_access = file_acl->u_access << 6;
4204 + idp->id_type = SMB_ACL_USER_OBJ;
4212 + acl_entry_link_head->count++;
4213 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4216 + acl_entry_link_head->count = 0;
4219 + return acl_entry_link_head;
4222 + SMB_ACL_T sys_acl_get_fd(int fd)
4224 + struct acl *file_acl = (struct acl *)NULL;
4225 + struct acl_entry *acl_entry;
4226 + struct new_acl_entry *new_acl_entry;
4227 + struct ace_id *idp;
4228 + struct acl_entry_link *acl_entry_link;
4229 + struct acl_entry_link *acl_entry_link_head;
4234 + /* Get the acl using fstatacl */
4236 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4237 + DEBUG(10,("fd is %d\n",fd));
4238 + file_acl = (struct acl *)malloc(BUFSIZ);
4240 + if (file_acl == NULL) {
4242 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4246 + memset(file_acl,0,BUFSIZ);
4248 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4250 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4255 + DEBUG(10,("Got facl and returned it\n"));
4257 + /* Point to the first acl entry in the acl */
4259 + acl_entry = file_acl->acl_ext;
4261 + /* Begin setting up the head of the linked list that will be
4262 + * used for the storing the acl in a way that is useful for the
4263 + * posix_acls.c code. */
4265 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4266 + if (acl_entry_link_head == NULL){
4271 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4273 + if (acl_entry_link->entryp == NULL) {
4275 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4280 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4281 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4283 + /* Check if the extended acl bit is on. If it isn't, do not
4284 + * show the contents of the acl since AIX intends the extended
4285 + * info to remain unused. */
4287 + if (file_acl->acl_mode & S_IXACL){
4288 + /* while we are not pointing to the very end */
4289 + while (acl_entry < acl_last(file_acl)) {
4290 + /* before we malloc anything, make sure this is */
4291 + /* a valid acl entry and one that we want to map */
4293 + idp = id_nxt(acl_entry->ace_id);
4294 + if ((acl_entry->ace_type == ACC_SPECIFY
4295 + || acl_entry->ace_type == ACC_PERMIT)
4296 + && (idp != id_last(acl_entry))) {
4297 + acl_entry = acl_nxt(acl_entry);
4301 + idp = acl_entry->ace_id;
4303 + /* Check if this is the first entry in the linked list.
4304 + * The first entry needs to keep prevp pointing to NULL
4305 + * and already has entryp allocated. */
4307 + if (acl_entry_link_head->count != 0) {
4308 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4309 + if (acl_entry_link->nextp == NULL) {
4311 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4315 + acl_entry_link->nextp->prevp = acl_entry_link;
4316 + acl_entry_link = acl_entry_link->nextp;
4317 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4318 + if (acl_entry_link->entryp == NULL) {
4320 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4325 + acl_entry_link->nextp = NULL;
4328 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4330 + /* Don't really need this since all types are going
4331 + * to be specified but, it's better than leaving it 0. */
4333 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4334 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4336 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof (struct ace_id));
4338 + /* The access in the acl entries must be left shifted by
4339 + * three bites, because they will ultimately be compared
4340 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4342 + switch (acl_entry->ace_type){
4345 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4346 + acl_entry_link->entryp->ace_access <<= 6;
4347 + acl_entry_link_head->count++;
4350 + /* Since there is no way to return a DENY acl entry
4351 + * change to PERMIT and then shift. */
4352 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4353 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4354 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4355 + acl_entry_link->entryp->ace_access <<= 6;
4356 + acl_entry_link_head->count++;
4362 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4363 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4365 + acl_entry = acl_nxt(acl_entry);
4367 + } /* end of if enabled */
4369 + /* Since owner, group, other acl entries are not
4370 + * part of the acl entries in an acl, they must
4371 + * be dummied up to become part of the list. */
4373 + for (i = 1; i < 4; i++) {
4374 + DEBUG(10,("i is %d\n",i));
4375 + if (acl_entry_link_head->count != 0){
4376 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4377 + if (acl_entry_link->nextp == NULL) {
4379 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4384 + acl_entry_link->nextp->prevp = acl_entry_link;
4385 + acl_entry_link = acl_entry_link->nextp;
4386 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4388 + if (acl_entry_link->entryp == NULL) {
4391 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4396 + acl_entry_link->nextp = NULL;
4398 + new_acl_entry = acl_entry_link->entryp;
4399 + idp = new_acl_entry->ace_id;
4401 + new_acl_entry->ace_len = sizeof (struct acl_entry);
4402 + new_acl_entry->ace_type = ACC_PERMIT;
4403 + idp->id_len = sizeof (struct ace_id);
4404 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4405 + memset(idp->id_data,0,sizeof (uid_t));
4409 + new_acl_entry->ace_access = file_acl->g_access << 6;
4410 + idp->id_type = SMB_ACL_GROUP_OBJ;
4414 + new_acl_entry->ace_access = file_acl->o_access << 6;
4415 + idp->id_type = SMB_ACL_OTHER;
4419 + new_acl_entry->ace_access = file_acl->u_access << 6;
4420 + idp->id_type = SMB_ACL_USER_OBJ;
4427 + acl_entry_link_head->count++;
4428 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4431 + acl_entry_link_head->count = 0;
4434 + return acl_entry_link_head;
4437 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4439 + *permset = *permset & ~0777;
4443 + int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4445 + if (perm != 0 && (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4449 + DEBUG(10,("This is the permset now: %d\n",*permset));
4453 + char *sys_acl_to_text(SMB_ACL_T theacl, ssize_t *plen)
4458 + SMB_ACL_T sys_acl_init(int count)
4460 + struct acl_entry_link *theacl = NULL;
4462 + DEBUG(10,("Entering sys_acl_init\n"));
4464 + theacl = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4465 + if (theacl == NULL) {
4467 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4471 + theacl->count = 0;
4472 + theacl->nextp = NULL;
4473 + theacl->prevp = NULL;
4474 + theacl->entryp = NULL;
4475 + DEBUG(10,("Exiting sys_acl_init\n"));
4479 + int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4481 + struct acl_entry_link *theacl;
4482 + struct acl_entry_link *acl_entryp;
4483 + struct acl_entry_link *temp_entry;
4486 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4488 + theacl = acl_entryp = *pacl;
4490 + /* Get to the end of the acl before adding entry */
4492 + for (counting=0; counting < theacl->count; counting++){
4493 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4494 + temp_entry = acl_entryp;
4495 + acl_entryp = acl_entryp->nextp;
4498 + if (theacl->count != 0){
4499 + temp_entry->nextp = acl_entryp = (struct acl_entry_link *)malloc(sizeof (struct acl_entry_link));
4500 + if (acl_entryp == NULL) {
4502 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4506 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4507 + acl_entryp->prevp = temp_entry;
4508 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4511 + *pentry = acl_entryp->entryp = (struct new_acl_entry *)malloc(sizeof (struct new_acl_entry));
4512 + if (*pentry == NULL) {
4514 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4518 + memset(*pentry,0,sizeof (struct new_acl_entry));
4519 + acl_entryp->entryp->ace_len = sizeof (struct acl_entry);
4520 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4521 + acl_entryp->entryp->ace_id->id_len = sizeof (struct ace_id);
4522 + acl_entryp->nextp = NULL;
4524 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4528 + int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4530 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4531 + entry->ace_id->id_type = tagtype;
4532 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4533 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4536 + int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual)
4538 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4539 + memcpy(entry->ace_id->id_data,qual,sizeof (uid_t));
4540 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4544 + int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4546 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4547 + if (!(*permset & S_IXUSR)
4548 + && !(*permset & S_IWUSR)
4549 + && !(*permset & S_IRUSR)
4553 + entry->ace_access = *permset;
4554 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4555 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4559 + int sys_acl_valid(SMB_ACL_T theacl)
4562 + int group_obj = 0;
4563 + int other_obj = 0;
4564 + struct acl_entry_link *acl_entry;
4566 + for (acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4567 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4568 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4569 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4572 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4574 + if (user_obj != 1 || group_obj != 1 || other_obj != 1)
4580 + int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4582 + struct acl_entry_link *acl_entry_link = NULL;
4583 + struct acl *file_acl = NULL;
4584 + struct acl *file_acl_temp = NULL;
4585 + struct acl_entry *acl_entry = NULL;
4586 + struct ace_id *ace_id = NULL;
4593 + DEBUG(10,("Entering sys_acl_set_file\n"));
4594 + DEBUG(10,("File name is %s\n",name));
4596 + /* AIX has no default ACL */
4597 + if (acltype == SMB_ACL_TYPE_DEFAULT)
4600 + acl_length = BUFSIZ;
4601 + file_acl = (struct acl *)malloc(BUFSIZ);
4603 + if (file_acl == NULL) {
4605 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4609 + memset(file_acl,0,BUFSIZ);
4611 + file_acl->acl_len = ACL_SIZ;
4612 + file_acl->acl_mode = S_IXACL;
4614 + for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4615 + acl_entry_link->entryp->ace_access >>= 6;
4616 + id_type = acl_entry_link->entryp->ace_id->id_type;
4618 + switch (id_type) {
4619 + case SMB_ACL_USER_OBJ:
4620 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4622 + case SMB_ACL_GROUP_OBJ:
4623 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4625 + case SMB_ACL_OTHER:
4626 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4628 + case SMB_ACL_MASK:
4632 + if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) {
4633 + acl_length += sizeof (struct acl_entry);
4634 + file_acl_temp = (struct acl *)malloc(acl_length);
4635 + if (file_acl_temp == NULL) {
4638 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4642 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4644 + file_acl = file_acl_temp;
4647 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4648 + file_acl->acl_len += sizeof (struct acl_entry);
4649 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4650 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4652 + /* In order to use this, we'll need to wait until we can get denies */
4653 + /* if (!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4654 + acl_entry->ace_type = ACC_SPECIFY; */
4656 + acl_entry->ace_type = ACC_SPECIFY;
4658 + ace_id = acl_entry->ace_id;
4660 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4661 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4662 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4663 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t));
4664 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof (uid_t));
4667 + rc = chacl((char *)name,file_acl,file_acl->acl_len);
4668 + DEBUG(10,("errno is %d\n",errno));
4669 + DEBUG(10,("return code is %d\n",rc));
4671 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4675 + int sys_acl_set_fd(int fd, SMB_ACL_T theacl)
4677 + struct acl_entry_link *acl_entry_link = NULL;
4678 + struct acl *file_acl = NULL;
4679 + struct acl *file_acl_temp = NULL;
4680 + struct acl_entry *acl_entry = NULL;
4681 + struct ace_id *ace_id = NULL;
4687 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4688 + acl_length = BUFSIZ;
4689 + file_acl = (struct acl *)malloc(BUFSIZ);
4691 + if (file_acl == NULL) {
4693 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4697 + memset(file_acl,0,BUFSIZ);
4699 + file_acl->acl_len = ACL_SIZ;
4700 + file_acl->acl_mode = S_IXACL;
4702 + for (acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4703 + acl_entry_link->entryp->ace_access >>= 6;
4704 + id_type = acl_entry_link->entryp->ace_id->id_type;
4705 + DEBUG(10,("The id_type is %d\n",id_type));
4707 + switch (id_type) {
4708 + case SMB_ACL_USER_OBJ:
4709 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4711 + case SMB_ACL_GROUP_OBJ:
4712 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4714 + case SMB_ACL_OTHER:
4715 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4717 + case SMB_ACL_MASK:
4721 + if ((file_acl->acl_len + sizeof (struct acl_entry)) > acl_length) {
4722 + acl_length += sizeof (struct acl_entry);
4723 + file_acl_temp = (struct acl *)malloc(acl_length);
4724 + if (file_acl_temp == NULL) {
4727 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4731 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4733 + file_acl = file_acl_temp;
4736 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4737 + file_acl->acl_len += sizeof (struct acl_entry);
4738 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4739 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4741 + /* In order to use this, we'll need to wait until we can get denies */
4742 + /* if (!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4743 + acl_entry->ace_type = ACC_SPECIFY; */
4745 + acl_entry->ace_type = ACC_SPECIFY;
4747 + ace_id = acl_entry->ace_id;
4749 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4750 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4751 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4752 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof (uid_t));
4753 + memcpy(ace_id->id_data, &user_id, sizeof (uid_t));
4756 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4757 + DEBUG(10,("errno is %d\n",errno));
4758 + DEBUG(10,("return code is %d\n",rc));
4760 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4764 + int sys_acl_delete_def_file(const char *name)
4766 + /* AIX has no default ACL */
4770 + int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4772 + return *permset & perm;
4775 + int sys_acl_free_text(char *text)
4780 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
4782 + struct acl_entry_link *acl_entry_link;
4784 + for (acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4785 + free(acl_entry_link->prevp->entryp);
4786 + free(acl_entry_link->prevp);
4789 + free(acl_entry_link->prevp->entryp);
4790 + free(acl_entry_link->prevp);
4791 + free(acl_entry_link->entryp);
4792 + free(acl_entry_link);
4797 + int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4802 +#else /* No ACLs. */
4804 + int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4810 + int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4816 + int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4822 + void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4828 + SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4834 + SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4840 + int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4846 + int sys_acl_add_perm(UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4852 + int sys_acl_get_perm(UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4855 + return permset & perm ? 1 : 0;
4858 + char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4864 + int sys_acl_free_text(UNUSED(char *text))
4870 + SMB_ACL_T sys_acl_init(UNUSED(int count))
4876 + int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4882 + int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4888 + int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4894 + int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4900 + int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4906 + int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4912 + int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4918 + int sys_acl_delete_def_file(UNUSED(const char *name))
4924 + int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4930 + int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4936 +#endif /* No ACLs. */
4937 --- orig/uidlist.c 2004-04-29 19:37:25
4938 +++ uidlist.c 2004-07-03 20:11:58
4941 extern int preserve_uid;
4942 extern int preserve_gid;
4943 +extern int preserve_acls;
4944 extern int numeric_ids;
4947 @@ -274,7 +275,7 @@ void send_uid_list(int f)
4951 - if (preserve_uid) {
4952 + if (preserve_uid || preserve_acls) {
4954 /* we send sequences of uid/byte-length/name */
4955 for (list = uidlist; list; list = list->next) {
4956 @@ -291,7 +292,7 @@ void send_uid_list(int f)
4960 - if (preserve_gid) {
4961 + if (preserve_gid || preserve_acls) {
4963 for (list = gidlist; list; list = list->next) {
4965 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
4969 - if (preserve_uid && !numeric_ids) {
4970 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
4971 /* read the uid list */
4972 while ((id = read_int(f)) != 0) {
4973 int len = read_byte(f);
4974 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
4978 - if (preserve_gid && !numeric_ids) {
4979 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
4980 /* read the gid list */
4981 while ((id = read_int(f)) != 0) {
4982 int len = read_byte(f);
4983 @@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li
4988 + if (preserve_acls && !numeric_ids) {
4990 + /* the enumerations don't return 0 except to flag the last
4991 + * entry, since uidlist doesn't munge 0 anyway */
4992 + while ((id = next_acl_uid(flist)))
4993 + acl_uid_map(match_uid(id));
4994 + while ((id = next_acl_gid(flist)))
4995 + acl_gid_map(match_gid(id));
4997 +#endif /* SUPPORT_ACLS */
4999 /* now convert the uid/gid of all files in the list to the mapped
5001 if (am_root && preserve_uid && !numeric_ids) {