1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 The program currently complains when the --acls (-A) option is used to copy
8 from a disk that doesn't support ACLs. This should be changed to silently
9 notice that no ACLs are available to copy. Of course, trying to write out
10 ACLs to a non-ACL-supporting disk should complain.
14 @@ -25,15 +25,15 @@ VERSION=@VERSION@
18 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
19 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
20 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
21 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
22 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
23 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
24 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
25 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
26 main.o checksum.o match.o syscall.o log.o backup.o
27 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
28 - fileio.o batch.o clientname.o chmod.o
29 + fileio.o batch.o clientname.o chmod.o acls.o
30 OBJS3=progress.o pipe.o
31 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
32 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
36 +/* -*- c-file-style: "linux" -*-
37 + Copyright (C) Andrew Tridgell 1996
38 + Copyright (C) Paul Mackerras 1996
40 + This program is free software; you can redistribute it and/or modify
41 + it under the terms of the GNU General Public License as published by
42 + the Free Software Foundation; either version 2 of the License, or
43 + (at your option) any later version.
45 + This program is distributed in the hope that it will be useful,
46 + but WITHOUT ANY WARRANTY; without even the implied warranty of
47 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 + GNU General Public License for more details.
50 + You should have received a copy of the GNU General Public License
51 + along with this program; if not, write to the Free Software
52 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
55 +/* handle passing ACLs between systems */
58 +#include "lib/sysacls.h"
62 +extern int preserve_acls;
65 +extern int orig_umask;
70 + SMB_ACL_TAG_T tag_type;
79 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
81 +static void expand_rsync_acl(rsync_acl *racl)
83 + /* First time through, 0 <= 0, so list is expanded.
84 + * (Diabolical, rsync guys!) */
85 + if (racl->malloced <= racl->count) {
87 + size_t new_size = racl->malloced + 10;
88 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
90 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
91 + (double) new_size * sizeof racl->races[0],
92 + racl->races ? "" : " not");
95 + racl->races = new_ptr;
96 + racl->malloced = new_size;
99 + out_of_memory("expand_rsync_acl");
103 +static void rsync_acl_free(rsync_acl *racl)
106 + racl->races = NULL;
108 + racl->malloced = 0;
111 +static int rsync_ace_sorter(const void *r1, const void *r2)
113 + rsync_ace *race1 = (rsync_ace *)r1;
114 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
115 + id_t rid1 = race1->id;
116 + rsync_ace *race2 = (rsync_ace *)r2;
117 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
118 + id_t rid2 = race2->id;
119 + /* start at the extrema */
120 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
122 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
125 + if (rtag1 == SMB_ACL_OTHER)
127 + if (rtag2 == SMB_ACL_OTHER)
129 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
130 + if (rtag1 == SMB_ACL_USER) {
132 + case SMB_ACL_GROUP:
133 + case SMB_ACL_GROUP_OBJ:
134 + case SMB_ACL_OTHER:
138 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
140 + if (rtag2 == SMB_ACL_USER)
142 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
143 + if (rtag1 == SMB_ACL_GROUP_OBJ)
145 + if (rtag2 == SMB_ACL_GROUP_OBJ)
147 + /* only SMB_ACL_GROUPs left */
148 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
151 +static void sort_rsync_acl(rsync_acl *racl)
155 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
156 + &rsync_ace_sorter);
159 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
161 + SMB_ACL_ENTRY_T entry;
163 + const char *errfun;
164 + *racl = rsync_acl_initializer;
165 + errfun = "sys_acl_get_entry";
166 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
168 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
169 + SMB_ACL_PERMSET_T permset;
172 + expand_rsync_acl(racl);
173 + race = &racl->races[racl->count++];
174 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
175 + errfun = "sys_acl_get_tag_type";
178 + if ((rc = sys_acl_get_permset(entry, &permset))) {
179 + errfun = "sys_acl_get_tag_type";
182 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
183 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
184 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
185 + switch (race->tag_type) {
187 + case SMB_ACL_GROUP:
192 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
193 + errfun = "sys_acl_get_tag_type";
197 + race->id = *((id_t *)qualifier);
198 + sys_acl_free_qualifier(qualifier, race->tag_type);
201 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
202 + errfun, strerror(errno));
203 + rsync_acl_free(racl);
206 + sort_rsync_acl(racl);
210 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
212 + rsync_ace *race1, *race2;
213 + size_t count = racl1->count;
214 + if (count != racl2->count)
216 + race1 = racl1->races;
217 + race2 = racl2->races;
218 + for (; count--; race1++, race2++) {
219 + if (race1->tag_type != race2->tag_type
220 + || race1->access != race2->access
221 + || ((race1->tag_type == SMB_ACL_USER
222 + || race1->tag_type == SMB_ACL_GROUP)
223 + && race1->id != race2->id))
235 +static rsync_acl_list _rsync_acl_lists[] = {
236 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
237 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
240 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
242 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
243 + : &_rsync_acl_lists[1];
246 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
248 + /* First time through, 0 <= 0, so list is expanded.
249 + * (Diabolical, rsync guys!) */
250 + if (racl_list->malloced <= racl_list->count) {
251 + rsync_acl *new_ptr;
253 + if (racl_list->malloced < 1000)
254 + new_size = racl_list->malloced + 1000;
256 + new_size = racl_list->malloced * 2;
257 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
258 + if (verbose >= 3) {
259 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
260 + (double) new_size * sizeof racl_list->racls[0],
261 + racl_list->racls ? "" : " not");
264 + racl_list->racls = new_ptr;
265 + racl_list->malloced = new_size;
267 + if (!racl_list->racls)
268 + out_of_memory("expand_rsync_acl_list");
273 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
275 + /* Run this in reverse, so references are freed before referents,
276 + * although not currently necessary. */
277 + while (racl_list->count--) {
278 + rsync_acl *racl = &racl_list->racls[racl_list->count];
280 + rsync_acl_free(racl);
282 + free(racl_list->racls);
283 + racl_list->racls = NULL;
284 + racl_list->malloced = 0;
288 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
289 + const rsync_acl_list *racl_list,
290 + const rsync_acl *racl)
292 + static int access_match = -1, default_match = -1;
293 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
294 + &access_match : &default_match;
295 + size_t count = racl_list->count;
296 + /* If this is the first time through or we didn't match the last
297 + * time, then start at the end of the list, which should be the
298 + * best place to start hunting. */
300 + *match = racl_list->count - 1;
302 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
305 + *match = racl_list->count - 1;
311 +/* The general strategy with the tag_type <-> character mapping is that
312 + * lowercase implies that no qualifier follows, where uppercase does.
313 + * A similar idiom for the acl type (access or default) itself, but
314 + * lowercase in this instance means there's no ACL following, so the
315 + * ACL is a repeat, so the receiver should reuse the last of the same
318 +static void send_rsync_acl(int f, const rsync_acl *racl)
321 + size_t count = racl->count;
322 + write_int(f, count);
323 + for (race = racl->races; count--; race++) {
325 + switch (race->tag_type) {
326 + case SMB_ACL_USER_OBJ:
332 + case SMB_ACL_GROUP_OBJ:
335 + case SMB_ACL_GROUP:
338 + case SMB_ACL_OTHER:
346 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
351 + write_byte(f, race->access);
352 + if (isupper((int)ch)) {
353 + write_int(f, race->id);
354 + /* FIXME: sorta wasteful: we should maybe buffer as
355 + * many ids as max(ACL_USER + ACL_GROUP) objects to
356 + * keep from making so many calls. */
365 +static rsync_acl _curr_rsync_acls[2];
368 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
370 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
371 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
372 + "unknown SMB_ACL_TYPE_T";
375 +/* Generate the ACL(s) for this flist entry;
376 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
378 +int make_acl(const struct file_struct *file, const char *fname)
380 + SMB_ACL_TYPE_T *type,
381 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
382 + rsync_acl *curr_racl;
383 + if (!preserve_acls || S_ISLNK(file->mode))
385 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
386 + type < &types[0] + sizeof types / sizeof types[0]
387 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
388 + type++, curr_racl++) {
391 + *curr_racl = rsync_acl_initializer;
392 + if (!(sacl = sys_acl_get_file(fname, *type))) {
393 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
394 + fname, str_acl_type(*type), strerror(errno));
397 + ok = unpack_smb_acl(curr_racl, sacl);
398 + sys_acl_free_acl(sacl);
405 +/* Send the make_acl()-generated ACLs for this flist entry,
406 + * or clean up after an flist entry that's not being sent (f == -1). */
408 +void send_acl(const struct file_struct *file, int f)
410 + SMB_ACL_TYPE_T *type,
411 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
412 + rsync_acl *curr_racl;
413 + if (!preserve_acls || S_ISLNK(file->mode))
415 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
416 + type < &types[0] + sizeof types / sizeof types[0]
417 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
418 + type++, curr_racl++) {
420 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
422 + rsync_acl_free(curr_racl);
425 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
427 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
428 + write_int(f, index);
429 + rsync_acl_free(curr_racl);
431 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
432 + send_rsync_acl(f, curr_racl);
433 + expand_rsync_acl_list(racl_list);
434 + racl_list->racls[racl_list->count++] = *curr_racl;
439 +/* The below stuff is only used by the receiver: */
441 +/* structure to hold index to rsync_acl_list member corresponding to
442 + * flist->files[i] */
445 + const struct file_struct *file;
452 + file_acl_index *fileaclidxs;
453 +} file_acl_index_list;
455 +static file_acl_index_list _file_acl_index_lists[] = {
456 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
457 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
460 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
462 + return type == SMB_ACL_TYPE_ACCESS ?
463 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
466 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
468 + /* First time through, 0 <= 0, so list is expanded.
469 + * (Diabolical, rsync guys!) */
470 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
471 + file_acl_index *new_ptr;
473 + if (fileaclidx_list->malloced < 1000)
474 + new_size = fileaclidx_list->malloced + 1000;
476 + new_size = fileaclidx_list->malloced * 2;
477 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
478 + if (verbose >= 3) {
479 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
480 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
481 + fileaclidx_list->fileaclidxs ? "" : " not");
484 + fileaclidx_list->fileaclidxs = new_ptr;
485 + fileaclidx_list->malloced = new_size;
487 + if (!fileaclidx_list->fileaclidxs)
488 + out_of_memory("expand_file_acl_index_list");
493 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
495 + free(fileaclidx_list->fileaclidxs);
496 + fileaclidx_list->fileaclidxs = NULL;
497 + fileaclidx_list->malloced = 0;
501 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
509 +static smb_acl_list _smb_acl_lists[] = {
510 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
511 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
514 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
516 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
517 + &_smb_acl_lists[1];
520 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
522 + /* First time through, 0 <= 0, so list is expanded.
523 + * (Diabolical, rsync guys!) */
524 + if (sacl_list->malloced <= sacl_list->count) {
525 + SMB_ACL_T *new_ptr;
527 + if (sacl_list->malloced < 1000)
528 + new_size = sacl_list->malloced + 1000;
530 + new_size = sacl_list->malloced * 2;
531 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
532 + if (verbose >= 3) {
533 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
534 + (double) new_size * sizeof sacl_list->sacls[0],
535 + sacl_list->sacls ? "" : " not");
538 + sacl_list->sacls = new_ptr;
539 + sacl_list->malloced = new_size;
541 + if (!sacl_list->sacls)
542 + out_of_memory("expand_smb_acl_list");
547 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
549 + smb_acl_list *sacl_list = smb_acl_lists(type);
550 + SMB_ACL_T *sacl = sacl_list->sacls;
551 + while (sacl_list->count--) {
553 + sys_acl_free_acl(*sacl++);
555 + free(sacl_list->sacls);
556 + sacl_list->sacls = NULL;
557 + sacl_list->malloced = 0;
561 +/* build an SMB_ACL_T corresponding to an rsync_acl */
562 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
564 + size_t count = racl->count;
565 + rsync_ace *race = racl->races;
566 + const char *errfun = NULL;
567 + *smb_acl = sys_acl_init(count);
569 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
573 + for (; count--; race++) {
574 + SMB_ACL_ENTRY_T entry;
575 + SMB_ACL_PERMSET_T permset;
576 + if (sys_acl_create_entry(smb_acl, &entry)) {
577 + errfun = "sys_acl_create)";
580 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
581 + errfun = "sys_acl_set_tag";
584 + if (race->tag_type == SMB_ACL_USER ||
585 + race->tag_type == SMB_ACL_GROUP)
586 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
587 + errfun = "sys_acl_set_qualfier";
590 + if (sys_acl_get_permset(entry, &permset)) {
591 + errfun = "sys_acl_get_permset";
594 + if (sys_acl_clear_perms(permset)) {
595 + errfun = "sys_acl_clear_perms";
598 + if (race->access & 4)
599 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
600 + errfun = "sys_acl_add_perm";
603 + if (race->access & 2)
604 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
605 + errfun = "sys_acl_add_perm";
608 + if (race->access & 1)
609 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
610 + errfun = "sys_acl_add_perm";
613 + if (sys_acl_set_permset(entry, permset)) {
614 + errfun = "sys_acl_set_permset";
619 + sys_acl_free_acl(*smb_acl);
620 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
627 +static void receive_rsync_acl(rsync_acl *racl, int f)
630 + uchar required_mask_perm = 0;
632 + BOOL saw_mask = False;
633 + BOOL saw_user_obj = False, saw_group_obj = False,
635 + size_t count = read_int(f);
640 + uchar tag = read_byte(f);
641 + expand_rsync_acl(racl);
642 + race = &racl->races[racl->count++];
645 + race->tag_type = SMB_ACL_USER_OBJ;
646 + saw_user_obj = True;
649 + race->tag_type = SMB_ACL_USER;
652 + race->tag_type = SMB_ACL_GROUP_OBJ;
653 + saw_group_obj = True;
656 + race->tag_type = SMB_ACL_GROUP;
659 + race->tag_type = SMB_ACL_OTHER;
663 + race->tag_type = SMB_ACL_MASK;
667 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
669 + exit_cleanup(RERR_STREAMIO);
671 + race->access = read_byte(f);
672 + if (race->access & ~ (4 | 2 | 1)) {
673 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
675 + exit_cleanup(RERR_STREAMIO);
677 + if (race->tag_type == SMB_ACL_USER ||
678 + race->tag_type == SMB_ACL_GROUP) {
679 + race->id = read_int(f);
681 + required_mask_perm |= race->access;
685 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
686 + required_mask_perm |= race->access;
690 + if (!saw_user_obj) {
691 + expand_rsync_acl(racl);
692 + race = &racl->races[racl->count++];
693 + race->tag_type = SMB_ACL_USER_OBJ;
696 + if (!saw_group_obj) {
697 + expand_rsync_acl(racl);
698 + race = &racl->races[racl->count++];
699 + race->tag_type = SMB_ACL_GROUP_OBJ;
703 + expand_rsync_acl(racl);
704 + race = &racl->races[racl->count++];
705 + race->tag_type = SMB_ACL_OTHER;
710 + expand_rsync_acl(racl);
711 + race = &racl->races[racl->count++];
712 + race->tag_type = SMB_ACL_MASK;
713 + race->access = required_mask_perm;
716 + /* If we, a system without ACLS_NEED_MASK, received data from a
717 + * system that has masks, throw away the extraneous CLASS_OBJs. */
718 + if (saw_mask && racl->count == 4) {
719 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
722 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
723 + if (p->tag_type == SMB_ACL_MASK)
725 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
726 + group_obj_race = p;
728 + if (mask_race == NULL || group_obj_race == NULL) {
729 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
730 + "and one's ACL_MASK but missing "
731 + "either it or ACL_GROUP_OBJ, "
732 + "when pruning ACL\n");
734 + /* mask off group perms with it first */
735 + group_obj_race->access &= mask_race->access;
736 + /* dump mask_race; re-slot any followers-on */
738 + if (mask_race != &racl->races[racl->count]) {
739 + *mask_race = racl->races[racl->count];
740 + saw_user_obj = False; /* force re-sort */
746 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
748 + if (!(saw_user_obj && saw_group_obj && saw_other))
750 + sort_rsync_acl(racl);
753 +/* receive and build the rsync_acl_lists */
755 +void receive_acl(struct file_struct *file, int f)
757 + SMB_ACL_TYPE_T *type,
758 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
760 + if (!preserve_acls || S_ISLNK(file->mode))
762 + fname = f_name(file, NULL);
763 + for (type = &types[0];
764 + type < &types[0] + sizeof types / sizeof types[0]
765 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
767 + file_acl_index_list *fileaclidx_list =
768 + file_acl_index_lists(*type);
770 + expand_file_acl_index_list(fileaclidx_list);
772 + tag = read_byte(f);
773 + if (tag == 'A' || tag == 'a') {
774 + if (*type != SMB_ACL_TYPE_ACCESS) {
775 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
777 + exit_cleanup(RERR_STREAMIO);
779 + } else if (tag == 'D' || tag == 'd') {
780 + if (*type == SMB_ACL_TYPE_ACCESS) {
781 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
783 + exit_cleanup(RERR_STREAMIO);
786 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
788 + exit_cleanup(RERR_STREAMIO);
790 + if (tag == 'A' || tag == 'D') {
791 + rsync_acl racl = rsync_acl_initializer;
792 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
793 + smb_acl_list *sacl_list = smb_acl_lists(*type);
794 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
795 + aclidx = racl_list->count;
796 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
798 + receive_rsync_acl(&racl, f);
799 + expand_rsync_acl_list(racl_list);
800 + racl_list->racls[racl_list->count++] = racl;
801 + expand_smb_acl_list(sacl_list);
802 + sacl_list->sacls[sacl_list->count++] = NULL;
804 + int index = read_int(f);
805 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
806 + if ((size_t) index >= racl_list->count) {
807 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
809 + str_acl_type(*type),
811 + exit_cleanup(RERR_STREAMIO);
813 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
815 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
821 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
823 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
824 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
825 + return fileaclidx1->file == fileaclidx2->file ? 0 :
826 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
829 +void sort_file_acl_index_lists()
831 + SMB_ACL_TYPE_T *type,
832 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
833 + if (!preserve_acls)
835 + for (type = &types[0];
836 + type < &types[0] + sizeof types / sizeof types[0];
839 + file_acl_index_list *fileaclidx_list =
840 + file_acl_index_lists(*type);
841 + if (!fileaclidx_list->count)
843 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
844 + sizeof fileaclidx_list->fileaclidxs[0],
845 + &file_acl_index_list_sorter);
849 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
850 + const struct file_struct *file) {
851 + int low = 0, high = fileaclidx_list->count;
852 + const struct file_struct *file_mid;
856 + int mid = (high + low) / 2;
857 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
858 + if (file_mid == file)
859 + return fileaclidx_list->fileaclidxs[mid].aclidx;
860 + if (file_mid > file)
864 + } while (low < high);
866 + file_mid = fileaclidx_list->fileaclidxs[low].file;
867 + if (file_mid == file)
868 + return fileaclidx_list->fileaclidxs[low].aclidx;
871 + "find_file_acl_index: can't find entry for file in list\n");
872 + exit_cleanup(RERR_STREAMIO);
876 +/* for duplicating ACLs on backups when using backup_dir */
878 +int dup_acl(const char *orig, const char *bak, mode_t mode)
880 + SMB_ACL_TYPE_T *type,
881 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
883 + if (!preserve_acls)
885 + for (type = &types[0];
886 + type < &types[0] + sizeof types / sizeof types[0]
887 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
889 + SMB_ACL_T sacl_orig, sacl_bak;
890 + rsync_acl racl_orig, racl_bak;
891 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
892 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
893 + orig, str_acl_type(*type), strerror(errno));
897 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
898 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
899 + bak, str_acl_type(*type), strerror(errno));
901 + /* try to forge on through */
903 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
905 + goto out_with_sacls;
908 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
910 + goto out_with_one_racl;
912 + if (rsync_acls_equal(&racl_orig, &racl_bak))
915 + ; /* presume they're unequal */
917 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
918 + if (-1 == sys_acl_delete_def_file(bak)) {
919 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
920 + bak, strerror(errno));
923 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
924 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
925 + bak, str_acl_type(*type), strerror(errno));
930 + rsync_acl_free(&racl_bak);
932 + rsync_acl_free(&racl_orig);
935 + sys_acl_free_acl(sacl_bak);
936 + /* out_with_one_sacl: */
938 + sys_acl_free_acl(sacl_orig);
943 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
944 + * for keep_backup(). */
945 +static const struct file_struct *backup_orig_file = NULL;
946 +static const char null_string[] = "";
947 +static const char *backup_orig_fname = null_string;
948 +static const char *backup_dest_fname = null_string;
949 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
951 +void push_keep_backup_acl(const struct file_struct *file,
952 + const char *orig, const char *dest)
954 + if (preserve_acls) {
955 + SMB_ACL_TYPE_T *type,
956 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
958 + backup_orig_file = file;
959 + backup_orig_fname = orig;
960 + backup_dest_fname = dest;
961 + for (type = &types[0], sacl = &_backup_sacl[0];
962 + type < &types[0] + sizeof types / sizeof types[0];
964 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
967 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
968 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
969 + orig, str_acl_type(*type),
977 +static int set_keep_backup_acl()
979 + if (preserve_acls) {
980 + SMB_ACL_TYPE_T *type,
981 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
984 + for (type = &types[0], sacl = &_backup_sacl[0];
985 + type < &types[0] + sizeof types / sizeof types[0];
988 + if (-1 == sys_acl_set_file(backup_dest_fname,
991 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
993 + str_acl_type(*type),
1004 +void cleanup_keep_backup_acl()
1006 + if (preserve_acls) {
1007 + SMB_ACL_TYPE_T *type,
1008 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1010 + backup_orig_file = NULL;
1011 + backup_orig_fname = null_string;
1012 + backup_dest_fname = null_string;
1013 + for (type = &types[0], sacl = &_backup_sacl[0];
1014 + type < &types[0] + sizeof types / sizeof types[0];
1017 + sys_acl_free_acl(*sacl);
1023 +/* set ACL on rsync-ed or keep_backup-ed file */
1025 +int set_acl(const char *fname, const struct file_struct *file)
1028 + SMB_ACL_TYPE_T *type,
1029 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1030 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1032 + if (file == backup_orig_file) {
1033 + if (!strcmp(fname, backup_dest_fname))
1034 + return set_keep_backup_acl();
1036 + for (type = &types[0];
1037 + type < &types[0] + sizeof types / sizeof types[0]
1038 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1040 + SMB_ACL_T sacl_orig, *sacl_new;
1041 + rsync_acl racl_orig, *racl_new;
1042 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1045 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1046 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1047 + sacl_orig = sys_acl_get_file(fname, *type);
1049 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1050 + fname, str_acl_type(*type), strerror(errno));
1054 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1055 + sys_acl_free_acl(sacl_orig);
1060 + ok = rsync_acls_equal(&racl_orig, racl_new);
1061 + rsync_acl_free(&racl_orig);
1064 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1065 + if (-1 == sys_acl_delete_def_file(fname)) {
1066 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1067 + fname, strerror(errno));
1073 + if (!pack_smb_acl(sacl_new, racl_new)) {
1077 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1078 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1079 + fname, str_acl_type(*type),
1091 +/* Enumeration functions for uid mapping: */
1093 +/* Context -- one and only one. Should be cycled through once on uid
1094 + * mapping and once on gid mapping. */
1095 +static rsync_acl_list *_enum_racl_lists[] = {
1096 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1099 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1100 +static size_t enum_racl_index = 0;
1101 +static size_t enum_race_index = 0;
1103 +/* This returns the next tag_type id from the given acl for the next entry,
1104 + * or it returns 0 if there are no more tag_type ids in the acl. */
1106 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1108 + for (; enum_race_index < racl->count; enum_race_index++) {
1109 + rsync_ace *race = &racl->races[enum_race_index];
1110 + if (race->tag_type == tag_type)
1113 + enum_race_index = 0;
1117 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1119 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1120 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1121 + id_t id = next_ace_id(tag_type, racl);
1125 + enum_racl_index = 0;
1129 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1131 + for (; *enum_racl_list; enum_racl_list++) {
1132 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1136 + enum_racl_list = &_enum_racl_lists[0];
1140 +id_t next_acl_uid()
1142 + return next_acl_list_id(SMB_ACL_USER);
1145 +id_t next_acl_gid()
1147 + return next_acl_list_id(SMB_ACL_GROUP);
1150 +/* referring to the global context enum_entry, sets the entry's id */
1151 +static void set_acl_id(id_t id)
1153 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1156 +void acl_uid_map(id_t uid)
1161 +void acl_gid_map(id_t gid)
1166 +#define PERMS_SPLICE(perms,newbits,where) (((perms) & ~(7 << (where))) | ((newbits) << (where)))
1168 +int default_perms_for_dir(const char *dir)
1172 + BOOL ok, saw_mask = False;
1178 + perms = ACCESSPERMS & ~orig_umask;
1179 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1180 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1181 + if (sacl == NULL) {
1182 + /* Couldn't get an ACL. Darn. */
1185 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1189 + /* We're doing a dry run, so the containing directory
1190 + * wasn't actually created. Don't worry about it. */
1193 + /* Otherwise fall through. */
1195 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1196 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1202 + ok = unpack_smb_acl(&racl, sacl);
1203 + sys_acl_free_acl(sacl);
1205 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1209 + /* Look at each default ACL entry and possibly modify three bits of `perms' accordingly.
1210 + * If there's "no" default ACL, there will be zero entries and the umask-based perms is unchanged. */
1211 + for (i = 0; i < racl.count; i++) {
1212 + switch (racl.races[i].tag_type) {
1213 + case SMB_ACL_USER_OBJ:
1214 + perms = PERMS_SPLICE(perms, racl.races[i].access, 6);
1216 + case SMB_ACL_GROUP_OBJ:
1218 + perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
1220 + case SMB_ACL_MASK:
1222 + perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
1224 + case SMB_ACL_OTHER:
1225 + perms = PERMS_SPLICE(perms, racl.races[i].access, 0);
1231 + rsync_acl_free(&racl);
1233 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1237 +#endif /* SUPPORT_ACLS */
1240 @@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
1242 do_lchown(fullpath, st.st_uid, st.st_gid);
1243 do_chmod(fullpath, st.st_mode);
1244 + (void)DUP_ACL(end, fullpath, st.st_mode);
1248 @@ -188,6 +189,8 @@ static int keep_backup(char *fname)
1249 if (!(buf = get_backup_name(fname)))
1252 + PUSH_KEEP_BACKUP_ACL(file, fname, buf);
1254 /* Check to see if this is a device file, or link */
1255 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1256 || (preserve_specials && IS_SPECIAL(file->mode))) {
1257 @@ -263,6 +266,7 @@ static int keep_backup(char *fname)
1260 set_file_attrs(buf, file, NULL, 0);
1261 + CLEANUP_KEEP_BACKUP_ACL();
1265 --- old/configure.in
1266 +++ new/configure.in
1267 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1268 AC_CHECK_LIB(resolv, strcasecmp)
1271 +AC_CHECK_FUNCS(aclsort)
1272 +if test x"$ac_cv_func_aclsort" = x"no"; then
1273 + AC_CHECK_LIB(sec, aclsort)
1276 dnl At the moment we don't test for a broken memcmp(), because all we
1277 dnl need to do is test for equality, not comparison, and it seems that
1278 dnl every platform has a memcmp that can do at least that.
1279 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1280 AC_SUBST(CC_SHOBJ_FLAG)
1281 AC_SUBST(BUILD_POPT)
1283 +AC_CHECK_HEADERS(sys/acl.h)
1284 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1285 +#################################################
1286 +# check for ACL support
1288 +AC_MSG_CHECKING(whether to support ACLs)
1289 +AC_ARG_ENABLE(acl-support,
1290 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1291 +[ case "$enableval" in
1294 + case "$host_os" in
1296 + AC_MSG_RESULT(Using UnixWare ACLs)
1297 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1300 + AC_MSG_RESULT(Using solaris ACLs)
1301 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1304 + AC_MSG_RESULT(Using HPUX ACLs)
1305 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1308 + AC_MSG_RESULT(Using IRIX ACLs)
1309 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1312 + AC_MSG_RESULT(Using AIX ACLs)
1313 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1316 + AC_MSG_RESULT(Using Tru64 ACLs)
1317 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1318 + LIBS="$LIBS -lpacl"
1321 + AC_MSG_RESULT(ACLs requested -- running tests)
1322 + AC_CHECK_LIB(acl,acl_get_file)
1323 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1324 + AC_TRY_LINK([#include <sys/types.h>
1325 +#include <sys/acl.h>],
1326 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1327 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1328 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1329 + AC_MSG_RESULT(Using posix ACLs)
1330 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1331 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1332 + AC_TRY_LINK([#include <sys/types.h>
1333 +#include <sys/acl.h>],
1334 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1335 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1336 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1337 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1340 + AC_MSG_ERROR(Failed to find ACL support)
1347 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1350 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1354 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1359 @@ -967,6 +967,8 @@ static struct file_struct *send_file_nam
1360 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1363 + if (MAKE_ACL(file, fname) < 0)
1366 if (chmod_modes && !S_ISLNK(file->mode))
1367 file->mode = tweak_mode(file->mode, chmod_modes);
1368 @@ -978,6 +980,10 @@ static struct file_struct *send_file_nam
1369 if (file->basename[0]) {
1370 flist->files[flist->count++] = file;
1371 send_file_entry(file, f);
1372 + SEND_ACL(file, f);
1374 + /* Cleanup unsent ACL(s). */
1375 + SEND_ACL(file, -1);
1379 @@ -1366,6 +1372,8 @@ struct file_list *recv_file_list(int f)
1380 flags |= read_byte(f) << 8;
1381 file = receive_file_entry(flist, flags, f);
1383 + RECEIVE_ACL(file, f);
1385 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1386 stats.total_size += file->length;
1388 @@ -1388,6 +1396,8 @@ struct file_list *recv_file_list(int f)
1390 clean_flist(flist, relative_paths, 1);
1392 + SORT_FILE_ACL_INDEX_LISTS();
1395 recv_uid_list(f, flist);
1399 @@ -754,6 +754,7 @@ static int try_dests_non(struct file_str
1402 static int phase = 0;
1403 +static int dflt_perms;
1405 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1406 * make sure it exists, and has the right permissions/timestamp info. For
1407 @@ -770,7 +771,7 @@ static void recv_generator(char *fname,
1408 enum logcode code, int f_out)
1410 static int missing_below = -1, excluded_below = -1;
1411 - static char *fuzzy_dirname = "";
1412 + static char *parent_dirname = "";
1413 static struct file_list *fuzzy_dirlist = NULL;
1414 struct file_struct *fuzzy_file = NULL;
1415 int fd = -1, f_copy = -1;
1416 @@ -789,12 +790,12 @@ static void recv_generator(char *fname,
1417 if (fuzzy_dirlist) {
1418 flist_free(fuzzy_dirlist);
1419 fuzzy_dirlist = NULL;
1420 - fuzzy_dirname = "";
1422 if (missing_below >= 0) {
1426 + parent_dirname = "";
1430 @@ -829,15 +830,24 @@ static void recv_generator(char *fname,
1432 stat_errno = ENOENT;
1434 - if (fuzzy_basis && S_ISREG(file->mode)) {
1435 + if ((fuzzy_basis && S_ISREG(file->mode))
1436 +#ifdef SUPPORT_ACLS
1437 + || !preserve_perms
1440 char *dn = file->dirname ? file->dirname : ".";
1441 - if (fuzzy_dirname != dn
1442 - && strcmp(fuzzy_dirname, dn) != 0) {
1443 + if (parent_dirname != dn
1444 + && strcmp(parent_dirname, dn) != 0) {
1446 flist_free(fuzzy_dirlist);
1447 - fuzzy_dirlist = get_dirlist(dn, -1, 1);
1448 + if (fuzzy_basis && S_ISREG(file->mode))
1449 + fuzzy_dirlist = get_dirlist(dn, -1, 1);
1450 +#ifdef SUPPORT_ACLS
1451 + if (!preserve_perms)
1452 + dflt_perms = default_perms_for_dir(dn);
1455 - fuzzy_dirname = dn;
1456 + parent_dirname = dn;
1459 statret = link_stat(fname, &st,
1460 @@ -859,7 +869,8 @@ static void recv_generator(char *fname,
1461 if (!preserve_perms) {
1462 int exists = statret == 0
1463 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1464 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1465 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1469 if (S_ISDIR(file->mode)) {
1470 @@ -893,6 +904,10 @@ static void recv_generator(char *fname,
1471 if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1472 && verbose && code && f_out != -1)
1473 rprintf(code, "%s/\n", fname);
1474 +#ifdef SUPPORT_ACLS
1476 + SET_ACL(fname, file);
1478 if (delete_during && f_out != -1 && !phase && dry_run < 2
1479 && (file->flags & FLAG_DEL_HERE))
1480 delete_in_dir(the_file_list, fname, file, &st);
1481 @@ -1328,6 +1343,8 @@ void generate_files(int f_out, struct fi
1482 * notice that and let us know via the redo pipe (or its closing). */
1485 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1487 for (i = 0; i < flist->count; i++) {
1488 struct file_struct *file = flist->files[i];
1490 --- old/lib/sysacls.c
1491 +++ new/lib/sysacls.c
1494 + Unix SMB/CIFS implementation.
1495 + Samba system utilities for ACL support.
1496 + Copyright (C) Jeremy Allison 2000.
1498 + This program is free software; you can redistribute it and/or modify
1499 + it under the terms of the GNU General Public License as published by
1500 + the Free Software Foundation; either version 2 of the License, or
1501 + (at your option) any later version.
1503 + This program is distributed in the hope that it will be useful,
1504 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1505 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1506 + GNU General Public License for more details.
1508 + You should have received a copy of the GNU General Public License
1509 + along with this program; if not, write to the Free Software
1510 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1514 +#include "sysacls.h" /****** ADDED ******/
1516 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1517 +void SAFE_FREE(void *mem)
1523 +char *uidtoname(uid_t uid)
1525 + static char idbuf[12];
1526 + struct passwd *pw;
1528 + if ((pw = getpwuid(uid)) == NULL) {
1529 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1532 + return pw->pw_name;
1534 +/****** EXTRAS -- END ******/
1537 + This file wraps all differing system ACL interfaces into a consistent
1538 + one based on the POSIX interface. It also returns the correct errors
1539 + for older UNIX systems that don't support ACLs.
1541 + The interfaces that each ACL implementation must support are as follows :
1543 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1544 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1545 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1546 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1547 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1548 + SMB_ACL_T sys_acl_get_fd(int fd)
1549 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1550 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1551 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1552 + SMB_ACL_T sys_acl_init( int count)
1553 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1554 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1555 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1556 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1557 + int sys_acl_valid( SMB_ACL_T theacl )
1558 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1559 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1560 + int sys_acl_delete_def_file(const char *path)
1562 + This next one is not POSIX complient - but we *have* to have it !
1563 + More POSIX braindamage.
1565 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1567 + The generic POSIX free is the following call. We split this into
1568 + several different free functions as we may need to add tag info
1569 + to structures when emulating the POSIX interface.
1571 + int sys_acl_free( void *obj_p)
1573 + The calls we actually use are :
1575 + int sys_acl_free_text(char *text) - free acl_to_text
1576 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1577 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1581 +#if defined(HAVE_POSIX_ACLS)
1583 +/* Identity mapping - easy. */
1585 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1587 + return acl_get_entry( the_acl, entry_id, entry_p);
1590 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1592 + return acl_get_tag_type( entry_d, tag_type_p);
1595 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1597 + return acl_get_permset( entry_d, permset_p);
1600 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1602 + return acl_get_qualifier( entry_d);
1605 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1607 + return acl_get_file( path_p, type);
1610 +SMB_ACL_T sys_acl_get_fd(int fd)
1612 + return acl_get_fd(fd);
1615 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1617 + return acl_clear_perms(permset);
1620 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1622 + return acl_add_perm(permset, perm);
1625 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1627 +#if defined(HAVE_ACL_GET_PERM_NP)
1629 + * Required for TrustedBSD-based ACL implementations where
1630 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1633 + return acl_get_perm_np(permset, perm);
1635 + return acl_get_perm(permset, perm);
1639 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1641 + return acl_to_text( the_acl, plen);
1644 +SMB_ACL_T sys_acl_init( int count)
1646 + return acl_init(count);
1649 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1651 + return acl_create_entry(pacl, pentry);
1654 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1656 + return acl_set_tag_type(entry, tagtype);
1659 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1661 + return acl_set_qualifier(entry, qual);
1664 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1666 + return acl_set_permset(entry, permset);
1669 +int sys_acl_valid( SMB_ACL_T theacl )
1671 + return acl_valid(theacl);
1674 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1676 + return acl_set_file(name, acltype, theacl);
1679 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1681 + return acl_set_fd(fd, theacl);
1684 +int sys_acl_delete_def_file(const char *name)
1686 + return acl_delete_def_file(name);
1689 +int sys_acl_free_text(char *text)
1691 + return acl_free(text);
1694 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1696 + return acl_free(the_acl);
1699 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1701 + return acl_free(qual);
1704 +#elif defined(HAVE_TRU64_ACLS)
1706 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1707 + * is based on Draft 13 of the POSIX spec which is
1708 + * slightly different from the Draft 16 interface.
1710 + * Also, some of the permset manipulation functions
1711 + * such as acl_clear_perm() and acl_add_perm() appear
1712 + * to be broken on Tru64 so we have to manipulate
1713 + * the permission bits in the permset directly.
1715 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1717 + SMB_ACL_ENTRY_T entry;
1719 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1724 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1729 + return errno ? -1 : 0;
1732 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1734 + return acl_get_tag_type( entry_d, tag_type_p);
1737 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1739 + return acl_get_permset( entry_d, permset_p);
1742 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1744 + return acl_get_qualifier( entry_d);
1747 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1749 + return acl_get_file((char *)path_p, type);
1752 +SMB_ACL_T sys_acl_get_fd(int fd)
1754 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1757 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1759 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1764 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1766 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1771 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1776 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1778 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1781 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1783 + return acl_to_text( the_acl, plen);
1786 +SMB_ACL_T sys_acl_init( int count)
1788 + return acl_init(count);
1791 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1793 + SMB_ACL_ENTRY_T entry;
1795 + if ((entry = acl_create_entry(pacl)) == NULL) {
1803 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1805 + return acl_set_tag_type(entry, tagtype);
1808 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1810 + return acl_set_qualifier(entry, qual);
1813 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1815 + return acl_set_permset(entry, permset);
1818 +int sys_acl_valid( SMB_ACL_T theacl )
1820 + acl_entry_t entry;
1822 + return acl_valid(theacl, &entry);
1825 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1827 + return acl_set_file((char *)name, acltype, theacl);
1830 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1832 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1835 +int sys_acl_delete_def_file(const char *name)
1837 + return acl_delete_def_file((char *)name);
1840 +int sys_acl_free_text(char *text)
1843 + * (void) cast and explicit return 0 are for DEC UNIX
1844 + * which just #defines acl_free_text() to be free()
1846 + (void) acl_free_text(text);
1850 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1852 + return acl_free(the_acl);
1855 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1857 + return acl_free_qualifier(qual, tagtype);
1860 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1863 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1864 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1868 + * Note that while this code implements sufficient functionality
1869 + * to support the sys_acl_* interfaces it does not provide all
1870 + * of the semantics of the POSIX ACL interfaces.
1872 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1873 + * from a call to sys_acl_get_entry() should not be assumed to be
1874 + * valid after calling any of the following functions, which may
1875 + * reorder the entries in the ACL.
1878 + * sys_acl_set_file()
1879 + * sys_acl_set_fd()
1883 + * The only difference between Solaris and UnixWare / OpenUNIX is
1884 + * that the #defines for the ACL operations have different names
1886 +#if defined(HAVE_UNIXWARE_ACLS)
1888 +#define SETACL ACL_SET
1889 +#define GETACL ACL_GET
1890 +#define GETACLCNT ACL_CNT
1895 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1897 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1902 + if (entry_p == NULL) {
1907 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1911 + if (acl_d->next < 0) {
1916 + if (acl_d->next >= acl_d->count) {
1920 + *entry_p = &acl_d->acl[acl_d->next++];
1925 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1927 + *type_p = entry_d->a_type;
1932 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1934 + *permset_p = &entry_d->a_perm;
1939 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1941 + if (entry_d->a_type != SMB_ACL_USER
1942 + && entry_d->a_type != SMB_ACL_GROUP) {
1947 + return &entry_d->a_id;
1951 + * There is no way of knowing what size the ACL returned by
1952 + * GETACL will be unless you first call GETACLCNT which means
1953 + * making an additional system call.
1955 + * In the hope of avoiding the cost of the additional system
1956 + * call in most cases, we initially allocate enough space for
1957 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1958 + * be too small then we use GETACLCNT to find out the actual
1959 + * size, reallocate the ACL buffer, and then call GETACL again.
1962 +#define INITIAL_ACL_SIZE 16
1964 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1967 + int count; /* # of ACL entries allocated */
1968 + int naccess; /* # of access ACL entries */
1969 + int ndefault; /* # of default ACL entries */
1971 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1976 + count = INITIAL_ACL_SIZE;
1977 + if ((acl_d = sys_acl_init(count)) == NULL) {
1982 + * If there isn't enough space for the ACL entries we use
1983 + * GETACLCNT to determine the actual number of ACL entries
1984 + * reallocate and try again. This is in a loop because it
1985 + * is possible that someone else could modify the ACL and
1986 + * increase the number of entries between the call to
1987 + * GETACLCNT and the call to GETACL.
1989 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1990 + && errno == ENOSPC) {
1992 + sys_acl_free_acl(acl_d);
1994 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1998 + if ((acl_d = sys_acl_init(count)) == NULL) {
2004 + sys_acl_free_acl(acl_d);
2009 + * calculate the number of access and default ACL entries
2011 + * Note: we assume that the acl() system call returned a
2012 + * well formed ACL which is sorted so that all of the
2013 + * access ACL entries preceed any default ACL entries
2015 + for (naccess = 0; naccess < count; naccess++) {
2016 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2019 + ndefault = count - naccess;
2022 + * if the caller wants the default ACL we have to copy
2023 + * the entries down to the start of the acl[] buffer
2024 + * and mask out the ACL_DEFAULT flag from the type field
2026 + if (type == SMB_ACL_TYPE_DEFAULT) {
2029 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2030 + acl_d->acl[i] = acl_d->acl[j];
2031 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2034 + acl_d->count = ndefault;
2036 + acl_d->count = naccess;
2042 +SMB_ACL_T sys_acl_get_fd(int fd)
2045 + int count; /* # of ACL entries allocated */
2046 + int naccess; /* # of access ACL entries */
2048 + count = INITIAL_ACL_SIZE;
2049 + if ((acl_d = sys_acl_init(count)) == NULL) {
2053 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2054 + && errno == ENOSPC) {
2056 + sys_acl_free_acl(acl_d);
2058 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2062 + if ((acl_d = sys_acl_init(count)) == NULL) {
2068 + sys_acl_free_acl(acl_d);
2073 + * calculate the number of access ACL entries
2075 + for (naccess = 0; naccess < count; naccess++) {
2076 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2080 + acl_d->count = naccess;
2085 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2092 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2094 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2095 + && perm != SMB_ACL_EXECUTE) {
2100 + if (permset_d == NULL) {
2105 + *permset_d |= perm;
2110 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2112 + return *permset_d & perm;
2115 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2122 + * use an initial estimate of 20 bytes per ACL entry
2123 + * when allocating memory for the text representation
2127 + maxlen = 20 * acl_d->count;
2128 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2133 + for (i = 0; i < acl_d->count; i++) {
2134 + struct acl *ap = &acl_d->acl[i];
2135 + struct passwd *pw;
2144 + switch (ap->a_type) {
2146 + * for debugging purposes it's probably more
2147 + * useful to dump unknown tag types rather
2148 + * than just returning an error
2151 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2154 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2159 + case SMB_ACL_USER:
2160 + id = uidtoname(ap->a_id);
2161 + case SMB_ACL_USER_OBJ:
2165 + case SMB_ACL_GROUP:
2166 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2167 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2173 + case SMB_ACL_GROUP_OBJ:
2177 + case SMB_ACL_OTHER:
2181 + case SMB_ACL_MASK:
2187 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2188 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2189 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2192 + /* <tag> : <qualifier> : rwx \n \0 */
2193 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2196 + * If this entry would overflow the buffer
2197 + * allocate enough additional memory for this
2198 + * entry and an estimate of another 20 bytes
2199 + * for each entry still to be processed
2201 + if ((len + nbytes) > maxlen) {
2202 + char *oldtext = text;
2204 + maxlen += nbytes + 20 * (acl_d->count - i);
2206 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2207 + SAFE_FREE(oldtext);
2213 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2214 + len += nbytes - 1;
2223 +SMB_ACL_T sys_acl_init(int count)
2233 + * note that since the definition of the structure pointed
2234 + * to by the SMB_ACL_T includes the first element of the
2235 + * acl[] array, this actually allocates an ACL with room
2236 + * for (count+1) entries
2238 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2243 + a->size = count + 1;
2251 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2254 + SMB_ACL_ENTRY_T entry_d;
2256 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2261 + if (acl_d->count >= acl_d->size) {
2266 + entry_d = &acl_d->acl[acl_d->count++];
2267 + entry_d->a_type = 0;
2268 + entry_d->a_id = -1;
2269 + entry_d->a_perm = 0;
2270 + *entry_p = entry_d;
2275 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2277 + switch (tag_type) {
2278 + case SMB_ACL_USER:
2279 + case SMB_ACL_USER_OBJ:
2280 + case SMB_ACL_GROUP:
2281 + case SMB_ACL_GROUP_OBJ:
2282 + case SMB_ACL_OTHER:
2283 + case SMB_ACL_MASK:
2284 + entry_d->a_type = tag_type;
2294 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2296 + if (entry_d->a_type != SMB_ACL_GROUP
2297 + && entry_d->a_type != SMB_ACL_USER) {
2302 + entry_d->a_id = *((id_t *)qual_p);
2307 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2309 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2313 + entry_d->a_perm = *permset_d;
2319 + * sort the ACL and check it for validity
2321 + * if it's a minimal ACL with only 4 entries then we
2322 + * need to recalculate the mask permissions to make
2323 + * sure that they are the same as the GROUP_OBJ
2324 + * permissions as required by the UnixWare acl() system call.
2326 + * (note: since POSIX allows minimal ACLs which only contain
2327 + * 3 entries - ie there is no mask entry - we should, in theory,
2328 + * check for this and add a mask entry if necessary - however
2329 + * we "know" that the caller of this interface always specifies
2330 + * a mask so, in practice "this never happens" (tm) - if it *does*
2331 + * happen aclsort() will fail and return an error and someone will
2332 + * have to fix it ...)
2335 +static int acl_sort(SMB_ACL_T acl_d)
2337 + int fixmask = (acl_d->count <= 4);
2339 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2346 +int sys_acl_valid(SMB_ACL_T acl_d)
2348 + return acl_sort(acl_d);
2351 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2354 + struct acl *acl_p;
2356 + struct acl *acl_buf = NULL;
2359 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2364 + if (acl_sort(acl_d) != 0) {
2368 + acl_p = &acl_d->acl[0];
2369 + acl_count = acl_d->count;
2372 + * if it's a directory there is extra work to do
2373 + * since the acl() system call will replace both
2374 + * the access ACLs and the default ACLs (if any)
2376 + if (stat(name, &s) != 0) {
2379 + if (S_ISDIR(s.st_mode)) {
2380 + SMB_ACL_T acc_acl;
2381 + SMB_ACL_T def_acl;
2382 + SMB_ACL_T tmp_acl;
2385 + if (type == SMB_ACL_TYPE_ACCESS) {
2387 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2391 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2394 + if (tmp_acl == NULL) {
2399 + * allocate a temporary buffer for the complete ACL
2401 + acl_count = acc_acl->count + def_acl->count;
2402 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2404 + if (acl_buf == NULL) {
2405 + sys_acl_free_acl(tmp_acl);
2411 + * copy the access control and default entries into the buffer
2413 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2414 + acc_acl->count * sizeof(acl_buf[0]));
2416 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2417 + def_acl->count * sizeof(acl_buf[0]));
2420 + * set the ACL_DEFAULT flag on the default entries
2422 + for (i = acc_acl->count; i < acl_count; i++) {
2423 + acl_buf[i].a_type |= ACL_DEFAULT;
2426 + sys_acl_free_acl(tmp_acl);
2428 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2433 + ret = acl(name, SETACL, acl_count, acl_p);
2435 + SAFE_FREE(acl_buf);
2440 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2442 + if (acl_sort(acl_d) != 0) {
2446 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2449 +int sys_acl_delete_def_file(const char *path)
2455 + * fetching the access ACL and rewriting it has
2456 + * the effect of deleting the default ACL
2458 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2462 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2464 + sys_acl_free_acl(acl_d);
2469 +int sys_acl_free_text(char *text)
2475 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2481 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2486 +#elif defined(HAVE_HPUX_ACLS)
2490 + * Based on the Solaris/SCO code - with modifications.
2494 + * Note that while this code implements sufficient functionality
2495 + * to support the sys_acl_* interfaces it does not provide all
2496 + * of the semantics of the POSIX ACL interfaces.
2498 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2499 + * from a call to sys_acl_get_entry() should not be assumed to be
2500 + * valid after calling any of the following functions, which may
2501 + * reorder the entries in the ACL.
2504 + * sys_acl_set_file()
2505 + * sys_acl_set_fd()
2508 +/* This checks if the POSIX ACL system call is defined */
2509 +/* which basically corresponds to whether JFS 3.3 or */
2510 +/* higher is installed. If acl() was called when it */
2511 +/* isn't defined, it causes the process to core dump */
2512 +/* so it is important to check this and avoid acl() */
2513 +/* calls if it isn't there. */
2515 +static BOOL hpux_acl_call_presence(void)
2518 + shl_t handle = NULL;
2521 + static BOOL already_checked=0;
2523 + if(already_checked)
2527 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2529 + if(ret_val != 0) {
2530 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2531 + ret_val, errno, strerror(errno)));
2532 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2536 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2538 + already_checked = True;
2542 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2544 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2549 + if (entry_p == NULL) {
2554 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2558 + if (acl_d->next < 0) {
2563 + if (acl_d->next >= acl_d->count) {
2567 + *entry_p = &acl_d->acl[acl_d->next++];
2572 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2574 + *type_p = entry_d->a_type;
2579 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2581 + *permset_p = &entry_d->a_perm;
2586 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2588 + if (entry_d->a_type != SMB_ACL_USER
2589 + && entry_d->a_type != SMB_ACL_GROUP) {
2594 + return &entry_d->a_id;
2598 + * There is no way of knowing what size the ACL returned by
2599 + * ACL_GET will be unless you first call ACL_CNT which means
2600 + * making an additional system call.
2602 + * In the hope of avoiding the cost of the additional system
2603 + * call in most cases, we initially allocate enough space for
2604 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2605 + * be too small then we use ACL_CNT to find out the actual
2606 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2609 +#define INITIAL_ACL_SIZE 16
2611 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2614 + int count; /* # of ACL entries allocated */
2615 + int naccess; /* # of access ACL entries */
2616 + int ndefault; /* # of default ACL entries */
2618 + if(hpux_acl_call_presence() == False) {
2619 + /* Looks like we don't have the acl() system call on HPUX.
2620 + * May be the system doesn't have the latest version of JFS.
2625 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2630 + count = INITIAL_ACL_SIZE;
2631 + if ((acl_d = sys_acl_init(count)) == NULL) {
2636 + * If there isn't enough space for the ACL entries we use
2637 + * ACL_CNT to determine the actual number of ACL entries
2638 + * reallocate and try again. This is in a loop because it
2639 + * is possible that someone else could modify the ACL and
2640 + * increase the number of entries between the call to
2641 + * ACL_CNT and the call to ACL_GET.
2643 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2645 + sys_acl_free_acl(acl_d);
2647 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2651 + if ((acl_d = sys_acl_init(count)) == NULL) {
2657 + sys_acl_free_acl(acl_d);
2662 + * calculate the number of access and default ACL entries
2664 + * Note: we assume that the acl() system call returned a
2665 + * well formed ACL which is sorted so that all of the
2666 + * access ACL entries preceed any default ACL entries
2668 + for (naccess = 0; naccess < count; naccess++) {
2669 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2672 + ndefault = count - naccess;
2675 + * if the caller wants the default ACL we have to copy
2676 + * the entries down to the start of the acl[] buffer
2677 + * and mask out the ACL_DEFAULT flag from the type field
2679 + if (type == SMB_ACL_TYPE_DEFAULT) {
2682 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2683 + acl_d->acl[i] = acl_d->acl[j];
2684 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2687 + acl_d->count = ndefault;
2689 + acl_d->count = naccess;
2695 +SMB_ACL_T sys_acl_get_fd(int fd)
2698 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2701 + files_struct *fsp = file_find_fd(fd);
2703 + if (fsp == NULL) {
2709 + * We know we're in the same conn context. So we
2710 + * can use the relative path.
2713 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2716 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2723 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2725 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2726 + && perm != SMB_ACL_EXECUTE) {
2731 + if (permset_d == NULL) {
2736 + *permset_d |= perm;
2741 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2743 + return *permset_d & perm;
2746 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2753 + * use an initial estimate of 20 bytes per ACL entry
2754 + * when allocating memory for the text representation
2758 + maxlen = 20 * acl_d->count;
2759 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2764 + for (i = 0; i < acl_d->count; i++) {
2765 + struct acl *ap = &acl_d->acl[i];
2766 + struct passwd *pw;
2775 + switch (ap->a_type) {
2777 + * for debugging purposes it's probably more
2778 + * useful to dump unknown tag types rather
2779 + * than just returning an error
2782 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2785 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2790 + case SMB_ACL_USER:
2791 + id = uidtoname(ap->a_id);
2792 + case SMB_ACL_USER_OBJ:
2796 + case SMB_ACL_GROUP:
2797 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2798 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2804 + case SMB_ACL_GROUP_OBJ:
2808 + case SMB_ACL_OTHER:
2812 + case SMB_ACL_MASK:
2818 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2819 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2820 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2823 + /* <tag> : <qualifier> : rwx \n \0 */
2824 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2827 + * If this entry would overflow the buffer
2828 + * allocate enough additional memory for this
2829 + * entry and an estimate of another 20 bytes
2830 + * for each entry still to be processed
2832 + if ((len + nbytes) > maxlen) {
2833 + char *oldtext = text;
2835 + maxlen += nbytes + 20 * (acl_d->count - i);
2837 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2844 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2845 + len += nbytes - 1;
2854 +SMB_ACL_T sys_acl_init(int count)
2864 + * note that since the definition of the structure pointed
2865 + * to by the SMB_ACL_T includes the first element of the
2866 + * acl[] array, this actually allocates an ACL with room
2867 + * for (count+1) entries
2869 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2874 + a->size = count + 1;
2882 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2885 + SMB_ACL_ENTRY_T entry_d;
2887 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2892 + if (acl_d->count >= acl_d->size) {
2897 + entry_d = &acl_d->acl[acl_d->count++];
2898 + entry_d->a_type = 0;
2899 + entry_d->a_id = -1;
2900 + entry_d->a_perm = 0;
2901 + *entry_p = entry_d;
2906 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2908 + switch (tag_type) {
2909 + case SMB_ACL_USER:
2910 + case SMB_ACL_USER_OBJ:
2911 + case SMB_ACL_GROUP:
2912 + case SMB_ACL_GROUP_OBJ:
2913 + case SMB_ACL_OTHER:
2914 + case SMB_ACL_MASK:
2915 + entry_d->a_type = tag_type;
2925 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2927 + if (entry_d->a_type != SMB_ACL_GROUP
2928 + && entry_d->a_type != SMB_ACL_USER) {
2933 + entry_d->a_id = *((id_t *)qual_p);
2938 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2940 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2944 + entry_d->a_perm = *permset_d;
2949 +/* Structure to capture the count for each type of ACE. */
2951 +struct hpux_acl_types {
2955 + int n_def_user_obj;
2960 + int n_def_group_obj;
2964 + int n_def_other_obj;
2967 + int n_def_class_obj;
2969 + int n_illegal_obj;
2973 + * Counts the different number of objects in a given array of ACL
2977 + * acl_count - Count of ACLs in the array of ACL strucutres.
2978 + * aclp - Array of ACL structures.
2979 + * acl_type_count - Pointer to acl_types structure. Should already be
2983 + * acl_type_count - This structure is filled up with counts of various
2987 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2991 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2993 + for(i=0;i<acl_count;i++) {
2994 + switch(aclp[i].a_type) {
2996 + acl_type_count->n_user++;
2999 + acl_type_count->n_user_obj++;
3001 + case DEF_USER_OBJ:
3002 + acl_type_count->n_def_user_obj++;
3005 + acl_type_count->n_group++;
3008 + acl_type_count->n_group_obj++;
3010 + case DEF_GROUP_OBJ:
3011 + acl_type_count->n_def_group_obj++;
3014 + acl_type_count->n_other_obj++;
3016 + case DEF_OTHER_OBJ:
3017 + acl_type_count->n_def_other_obj++;
3020 + acl_type_count->n_class_obj++;
3022 + case DEF_CLASS_OBJ:
3023 + acl_type_count->n_def_class_obj++;
3026 + acl_type_count->n_def_user++;
3029 + acl_type_count->n_def_group++;
3032 + acl_type_count->n_illegal_obj++;
3038 +/* swap_acl_entries: Swaps two ACL entries.
3040 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3043 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3045 + struct acl temp_acl;
3047 + temp_acl.a_type = aclp0->a_type;
3048 + temp_acl.a_id = aclp0->a_id;
3049 + temp_acl.a_perm = aclp0->a_perm;
3051 + aclp0->a_type = aclp1->a_type;
3052 + aclp0->a_id = aclp1->a_id;
3053 + aclp0->a_perm = aclp1->a_perm;
3055 + aclp1->a_type = temp_acl.a_type;
3056 + aclp1->a_id = temp_acl.a_id;
3057 + aclp1->a_perm = temp_acl.a_perm;
3060 +/* prohibited_duplicate_type
3061 + * Identifies if given ACL type can have duplicate entries or
3064 + * Inputs: acl_type - ACL Type.
3070 + * True - If the ACL type matches any of the prohibited types.
3071 + * False - If the ACL type doesn't match any of the prohibited types.
3074 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3076 + switch(acl_type) {
3087 +/* get_needed_class_perm
3088 + * Returns the permissions of a ACL structure only if the ACL
3089 + * type matches one of the pre-determined types for computing
3090 + * CLASS_OBJ permissions.
3092 + * Inputs: aclp - Pointer to ACL structure.
3095 +static int hpux_get_needed_class_perm(struct acl *aclp)
3097 + switch(aclp->a_type) {
3101 + case DEF_USER_OBJ:
3103 + case DEF_GROUP_OBJ:
3105 + case DEF_CLASS_OBJ:
3106 + case DEF_OTHER_OBJ:
3107 + return aclp->a_perm;
3113 +/* acl_sort for HPUX.
3114 + * Sorts the array of ACL structures as per the description in
3115 + * aclsort man page. Refer to aclsort man page for more details
3119 + * acl_count - Count of ACLs in the array of ACL structures.
3120 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3122 + * aclp - Array of ACL structures.
3126 + * aclp - Sorted array of ACL structures.
3130 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3131 + * debug log in case of failure.
3134 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3136 +#if !defined(HAVE_HPUX_ACLSORT)
3138 + * The aclsort() system call is availabe on the latest HPUX General
3139 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3140 + * function. Because, we don't want to update to a new
3141 + * HPUX GR bundle just for aclsort() call.
3144 + struct hpux_acl_types acl_obj_count;
3145 + int n_class_obj_perm = 0;
3149 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3153 + if(aclp == NULL) {
3154 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3158 + /* Count different types of ACLs in the ACLs array */
3160 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3162 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3163 + * CLASS_OBJ and OTHER_OBJ
3166 + if( (acl_obj_count.n_user_obj != 1) ||
3167 + (acl_obj_count.n_group_obj != 1) ||
3168 + (acl_obj_count.n_class_obj != 1) ||
3169 + (acl_obj_count.n_other_obj != 1)
3171 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3172 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3176 + /* If any of the default objects are present, there should be only
3177 + * one of them each.
3180 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3181 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3182 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3183 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3187 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3190 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3191 + * same ACL type, sort by ACL id.
3193 + * I am using the trival kind of sorting method here because, performance isn't
3194 + * really effected by the ACLs feature. More over there aren't going to be more
3195 + * than 17 entries on HPUX.
3198 + for(i=0; i<acl_count;i++) {
3199 + for (j=i+1; j<acl_count; j++) {
3200 + if( aclp[i].a_type > aclp[j].a_type ) {
3201 + /* ACL entries out of order, swap them */
3203 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3205 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3207 + /* ACL entries of same type, sort by id */
3209 + if(aclp[i].a_id > aclp[j].a_id) {
3210 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3211 + } else if (aclp[i].a_id == aclp[j].a_id) {
3212 + /* We have a duplicate entry. */
3213 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3214 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3215 + aclp[i].a_type, aclp[i].a_id));
3224 + /* set the class obj permissions to the computed one. */
3226 + int n_class_obj_index = -1;
3228 + for(i=0;i<acl_count;i++) {
3229 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3231 + if(aclp[i].a_type == CLASS_OBJ)
3232 + n_class_obj_index = i;
3234 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3239 + return aclsort(acl_count, calclass, aclp);
3244 + * sort the ACL and check it for validity
3246 + * if it's a minimal ACL with only 4 entries then we
3247 + * need to recalculate the mask permissions to make
3248 + * sure that they are the same as the GROUP_OBJ
3249 + * permissions as required by the UnixWare acl() system call.
3251 + * (note: since POSIX allows minimal ACLs which only contain
3252 + * 3 entries - ie there is no mask entry - we should, in theory,
3253 + * check for this and add a mask entry if necessary - however
3254 + * we "know" that the caller of this interface always specifies
3255 + * a mask so, in practice "this never happens" (tm) - if it *does*
3256 + * happen aclsort() will fail and return an error and someone will
3257 + * have to fix it ...)
3260 +static int acl_sort(SMB_ACL_T acl_d)
3262 + int fixmask = (acl_d->count <= 4);
3264 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3271 +int sys_acl_valid(SMB_ACL_T acl_d)
3273 + return acl_sort(acl_d);
3276 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3279 + struct acl *acl_p;
3281 + struct acl *acl_buf = NULL;
3284 + if(hpux_acl_call_presence() == False) {
3285 + /* Looks like we don't have the acl() system call on HPUX.
3286 + * May be the system doesn't have the latest version of JFS.
3292 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3297 + if (acl_sort(acl_d) != 0) {
3301 + acl_p = &acl_d->acl[0];
3302 + acl_count = acl_d->count;
3305 + * if it's a directory there is extra work to do
3306 + * since the acl() system call will replace both
3307 + * the access ACLs and the default ACLs (if any)
3309 + if (stat(name, &s) != 0) {
3312 + if (S_ISDIR(s.st_mode)) {
3313 + SMB_ACL_T acc_acl;
3314 + SMB_ACL_T def_acl;
3315 + SMB_ACL_T tmp_acl;
3318 + if (type == SMB_ACL_TYPE_ACCESS) {
3320 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3324 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3327 + if (tmp_acl == NULL) {
3332 + * allocate a temporary buffer for the complete ACL
3334 + acl_count = acc_acl->count + def_acl->count;
3335 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3337 + if (acl_buf == NULL) {
3338 + sys_acl_free_acl(tmp_acl);
3344 + * copy the access control and default entries into the buffer
3346 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3347 + acc_acl->count * sizeof(acl_buf[0]));
3349 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3350 + def_acl->count * sizeof(acl_buf[0]));
3353 + * set the ACL_DEFAULT flag on the default entries
3355 + for (i = acc_acl->count; i < acl_count; i++) {
3356 + acl_buf[i].a_type |= ACL_DEFAULT;
3359 + sys_acl_free_acl(tmp_acl);
3361 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3366 + ret = acl(name, ACL_SET, acl_count, acl_p);
3375 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3378 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3381 + files_struct *fsp = file_find_fd(fd);
3383 + if (fsp == NULL) {
3388 + if (acl_sort(acl_d) != 0) {
3393 + * We know we're in the same conn context. So we
3394 + * can use the relative path.
3397 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3400 +int sys_acl_delete_def_file(const char *path)
3406 + * fetching the access ACL and rewriting it has
3407 + * the effect of deleting the default ACL
3409 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3413 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3415 + sys_acl_free_acl(acl_d);
3420 +int sys_acl_free_text(char *text)
3426 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3432 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3437 +#elif defined(HAVE_IRIX_ACLS)
3439 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3441 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3446 + if (entry_p == NULL) {
3451 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3455 + if (acl_d->next < 0) {
3460 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3464 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3469 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3471 + *type_p = entry_d->ae_tag;
3476 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3478 + *permset_p = entry_d;
3483 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3485 + if (entry_d->ae_tag != SMB_ACL_USER
3486 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3491 + return &entry_d->ae_id;
3494 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3498 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3502 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3507 + a->freeaclp = True;
3511 +SMB_ACL_T sys_acl_get_fd(int fd)
3515 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3519 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3524 + a->freeaclp = True;
3528 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3530 + permset_d->ae_perm = 0;
3535 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3537 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3538 + && perm != SMB_ACL_EXECUTE) {
3543 + if (permset_d == NULL) {
3548 + permset_d->ae_perm |= perm;
3553 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3555 + return permset_d->ae_perm & perm;
3558 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3560 + return acl_to_text(acl_d->aclp, len_p);
3563 +SMB_ACL_T sys_acl_init(int count)
3572 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3578 + a->freeaclp = False;
3579 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3580 + a->aclp->acl_cnt = 0;
3586 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3589 + SMB_ACL_ENTRY_T entry_d;
3591 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3596 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3601 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3602 + entry_d->ae_tag = 0;
3603 + entry_d->ae_id = 0;
3604 + entry_d->ae_perm = 0;
3605 + *entry_p = entry_d;
3610 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3612 + switch (tag_type) {
3613 + case SMB_ACL_USER:
3614 + case SMB_ACL_USER_OBJ:
3615 + case SMB_ACL_GROUP:
3616 + case SMB_ACL_GROUP_OBJ:
3617 + case SMB_ACL_OTHER:
3618 + case SMB_ACL_MASK:
3619 + entry_d->ae_tag = tag_type;
3629 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3631 + if (entry_d->ae_tag != SMB_ACL_GROUP
3632 + && entry_d->ae_tag != SMB_ACL_USER) {
3637 + entry_d->ae_id = *((id_t *)qual_p);
3642 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3644 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3648 + entry_d->ae_perm = permset_d->ae_perm;
3653 +int sys_acl_valid(SMB_ACL_T acl_d)
3655 + return acl_valid(acl_d->aclp);
3658 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3660 + return acl_set_file(name, type, acl_d->aclp);
3663 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3665 + return acl_set_fd(fd, acl_d->aclp);
3668 +int sys_acl_delete_def_file(const char *name)
3670 + return acl_delete_def_file(name);
3673 +int sys_acl_free_text(char *text)
3675 + return acl_free(text);
3678 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3680 + if (acl_d->freeaclp) {
3681 + acl_free(acl_d->aclp);
3687 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3692 +#elif defined(HAVE_AIX_ACLS)
3694 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3696 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3698 + struct acl_entry_link *link;
3699 + struct new_acl_entry *entry;
3702 + DEBUG(10,("This is the count: %d\n",theacl->count));
3704 + /* Check if count was previously set to -1. *
3705 + * If it was, that means we reached the end *
3706 + * of the acl last time. */
3707 + if(theacl->count == -1)
3711 + /* To get to the next acl, traverse linked list until index *
3712 + * of acl matches the count we are keeping. This count is *
3713 + * incremented each time we return an acl entry. */
3715 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3716 + link = link->nextp;
3718 + entry = *entry_p = link->entryp;
3720 + DEBUG(10,("*entry_p is %d\n",entry_p));
3721 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3723 + /* Increment count */
3725 + if(link->nextp == NULL)
3726 + theacl->count = -1;
3731 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3733 + /* Initialize tag type */
3736 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3738 + /* Depending on what type of entry we have, *
3739 + * return tag type. */
3740 + switch(entry_d->ace_id->id_type) {
3742 + *tag_type_p = SMB_ACL_USER;
3745 + *tag_type_p = SMB_ACL_GROUP;
3748 + case SMB_ACL_USER_OBJ:
3749 + case SMB_ACL_GROUP_OBJ:
3750 + case SMB_ACL_OTHER:
3751 + *tag_type_p = entry_d->ace_id->id_type;
3761 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3763 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3764 + *permset_p = &entry_d->ace_access;
3765 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3766 + if(!(**permset_p & S_IXUSR) &&
3767 + !(**permset_p & S_IWUSR) &&
3768 + !(**permset_p & S_IRUSR) &&
3769 + (**permset_p != 0))
3772 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3776 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3778 + return(entry_d->ace_id->id_data);
3781 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3783 + struct acl *file_acl = (struct acl *)NULL;
3784 + struct acl_entry *acl_entry;
3785 + struct new_acl_entry *new_acl_entry;
3786 + struct ace_id *idp;
3787 + struct acl_entry_link *acl_entry_link;
3788 + struct acl_entry_link *acl_entry_link_head;
3793 + /* AIX has no DEFAULT */
3794 + if ( type == SMB_ACL_TYPE_DEFAULT )
3797 + /* Get the acl using statacl */
3799 + DEBUG(10,("Entering sys_acl_get_file\n"));
3800 + DEBUG(10,("path_p is %s\n",path_p));
3802 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3804 + if(file_acl == NULL) {
3806 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3810 + memset(file_acl,0,BUFSIZ);
3812 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3814 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3815 + SAFE_FREE(file_acl);
3819 + DEBUG(10,("Got facl and returned it\n"));
3821 + /* Point to the first acl entry in the acl */
3822 + acl_entry = file_acl->acl_ext;
3824 + /* Begin setting up the head of the linked list *
3825 + * that will be used for the storing the acl *
3826 + * in a way that is useful for the posix_acls.c *
3829 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3830 + if(acl_entry_link_head == NULL)
3833 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3834 + if(acl_entry_link->entryp == NULL) {
3835 + SAFE_FREE(file_acl);
3837 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3841 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3842 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3844 + /* Check if the extended acl bit is on. *
3845 + * If it isn't, do not show the *
3846 + * contents of the acl since AIX intends *
3847 + * the extended info to remain unused */
3849 + if(file_acl->acl_mode & S_IXACL){
3850 + /* while we are not pointing to the very end */
3851 + while(acl_entry < acl_last(file_acl)) {
3852 + /* before we malloc anything, make sure this is */
3853 + /* a valid acl entry and one that we want to map */
3854 + idp = id_nxt(acl_entry->ace_id);
3855 + if((acl_entry->ace_type == ACC_SPECIFY ||
3856 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3857 + acl_entry = acl_nxt(acl_entry);
3861 + idp = acl_entry->ace_id;
3863 + /* Check if this is the first entry in the linked list. *
3864 + * The first entry needs to keep prevp pointing to NULL *
3865 + * and already has entryp allocated. */
3867 + if(acl_entry_link_head->count != 0) {
3868 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3870 + if(acl_entry_link->nextp == NULL) {
3871 + SAFE_FREE(file_acl);
3873 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3877 + acl_entry_link->nextp->prevp = acl_entry_link;
3878 + acl_entry_link = acl_entry_link->nextp;
3879 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3880 + if(acl_entry_link->entryp == NULL) {
3881 + SAFE_FREE(file_acl);
3883 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3886 + acl_entry_link->nextp = NULL;
3889 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3891 + /* Don't really need this since all types are going *
3892 + * to be specified but, it's better than leaving it 0 */
3894 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3896 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3898 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3900 + /* The access in the acl entries must be left shifted by *
3901 + * three bites, because they will ultimately be compared *
3902 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3904 + switch(acl_entry->ace_type){
3907 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3908 + acl_entry_link->entryp->ace_access <<= 6;
3909 + acl_entry_link_head->count++;
3912 + /* Since there is no way to return a DENY acl entry *
3913 + * change to PERMIT and then shift. */
3914 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3915 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3916 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3917 + acl_entry_link->entryp->ace_access <<= 6;
3918 + acl_entry_link_head->count++;
3924 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3925 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3927 + acl_entry = acl_nxt(acl_entry);
3929 + } /* end of if enabled */
3931 + /* Since owner, group, other acl entries are not *
3932 + * part of the acl entries in an acl, they must *
3933 + * be dummied up to become part of the list. */
3935 + for( i = 1; i < 4; i++) {
3936 + DEBUG(10,("i is %d\n",i));
3937 + if(acl_entry_link_head->count != 0) {
3938 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3939 + if(acl_entry_link->nextp == NULL) {
3940 + SAFE_FREE(file_acl);
3942 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3946 + acl_entry_link->nextp->prevp = acl_entry_link;
3947 + acl_entry_link = acl_entry_link->nextp;
3948 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3949 + if(acl_entry_link->entryp == NULL) {
3950 + SAFE_FREE(file_acl);
3952 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3957 + acl_entry_link->nextp = NULL;
3959 + new_acl_entry = acl_entry_link->entryp;
3960 + idp = new_acl_entry->ace_id;
3962 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3963 + new_acl_entry->ace_type = ACC_PERMIT;
3964 + idp->id_len = sizeof(struct ace_id);
3965 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3966 + memset(idp->id_data,0,sizeof(uid_t));
3970 + new_acl_entry->ace_access = file_acl->g_access << 6;
3971 + idp->id_type = SMB_ACL_GROUP_OBJ;
3975 + new_acl_entry->ace_access = file_acl->o_access << 6;
3976 + idp->id_type = SMB_ACL_OTHER;
3980 + new_acl_entry->ace_access = file_acl->u_access << 6;
3981 + idp->id_type = SMB_ACL_USER_OBJ;
3989 + acl_entry_link_head->count++;
3990 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3993 + acl_entry_link_head->count = 0;
3994 + SAFE_FREE(file_acl);
3996 + return(acl_entry_link_head);
3999 +SMB_ACL_T sys_acl_get_fd(int fd)
4001 + struct acl *file_acl = (struct acl *)NULL;
4002 + struct acl_entry *acl_entry;
4003 + struct new_acl_entry *new_acl_entry;
4004 + struct ace_id *idp;
4005 + struct acl_entry_link *acl_entry_link;
4006 + struct acl_entry_link *acl_entry_link_head;
4011 + /* Get the acl using fstatacl */
4013 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4014 + DEBUG(10,("fd is %d\n",fd));
4015 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4017 + if(file_acl == NULL) {
4019 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4023 + memset(file_acl,0,BUFSIZ);
4025 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4027 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4028 + SAFE_FREE(file_acl);
4032 + DEBUG(10,("Got facl and returned it\n"));
4034 + /* Point to the first acl entry in the acl */
4036 + acl_entry = file_acl->acl_ext;
4037 + /* Begin setting up the head of the linked list *
4038 + * that will be used for the storing the acl *
4039 + * in a way that is useful for the posix_acls.c *
4042 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4043 + if(acl_entry_link_head == NULL){
4044 + SAFE_FREE(file_acl);
4048 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4050 + if(acl_entry_link->entryp == NULL) {
4052 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4053 + SAFE_FREE(file_acl);
4057 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4058 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4060 + /* Check if the extended acl bit is on. *
4061 + * If it isn't, do not show the *
4062 + * contents of the acl since AIX intends *
4063 + * the extended info to remain unused */
4065 + if(file_acl->acl_mode & S_IXACL){
4066 + /* while we are not pointing to the very end */
4067 + while(acl_entry < acl_last(file_acl)) {
4068 + /* before we malloc anything, make sure this is */
4069 + /* a valid acl entry and one that we want to map */
4071 + idp = id_nxt(acl_entry->ace_id);
4072 + if((acl_entry->ace_type == ACC_SPECIFY ||
4073 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4074 + acl_entry = acl_nxt(acl_entry);
4078 + idp = acl_entry->ace_id;
4080 + /* Check if this is the first entry in the linked list. *
4081 + * The first entry needs to keep prevp pointing to NULL *
4082 + * and already has entryp allocated. */
4084 + if(acl_entry_link_head->count != 0) {
4085 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4086 + if(acl_entry_link->nextp == NULL) {
4088 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4089 + SAFE_FREE(file_acl);
4092 + acl_entry_link->nextp->prevp = acl_entry_link;
4093 + acl_entry_link = acl_entry_link->nextp;
4094 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4095 + if(acl_entry_link->entryp == NULL) {
4097 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4098 + SAFE_FREE(file_acl);
4102 + acl_entry_link->nextp = NULL;
4105 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4107 + /* Don't really need this since all types are going *
4108 + * to be specified but, it's better than leaving it 0 */
4110 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4111 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4113 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4115 + /* The access in the acl entries must be left shifted by *
4116 + * three bites, because they will ultimately be compared *
4117 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4119 + switch(acl_entry->ace_type){
4122 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4123 + acl_entry_link->entryp->ace_access <<= 6;
4124 + acl_entry_link_head->count++;
4127 + /* Since there is no way to return a DENY acl entry *
4128 + * change to PERMIT and then shift. */
4129 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4130 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4131 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4132 + acl_entry_link->entryp->ace_access <<= 6;
4133 + acl_entry_link_head->count++;
4139 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4140 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4142 + acl_entry = acl_nxt(acl_entry);
4144 + } /* end of if enabled */
4146 + /* Since owner, group, other acl entries are not *
4147 + * part of the acl entries in an acl, they must *
4148 + * be dummied up to become part of the list. */
4150 + for( i = 1; i < 4; i++) {
4151 + DEBUG(10,("i is %d\n",i));
4152 + if(acl_entry_link_head->count != 0){
4153 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4154 + if(acl_entry_link->nextp == NULL) {
4156 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4157 + SAFE_FREE(file_acl);
4161 + acl_entry_link->nextp->prevp = acl_entry_link;
4162 + acl_entry_link = acl_entry_link->nextp;
4163 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4165 + if(acl_entry_link->entryp == NULL) {
4166 + SAFE_FREE(file_acl);
4168 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4173 + acl_entry_link->nextp = NULL;
4175 + new_acl_entry = acl_entry_link->entryp;
4176 + idp = new_acl_entry->ace_id;
4178 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4179 + new_acl_entry->ace_type = ACC_PERMIT;
4180 + idp->id_len = sizeof(struct ace_id);
4181 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4182 + memset(idp->id_data,0,sizeof(uid_t));
4186 + new_acl_entry->ace_access = file_acl->g_access << 6;
4187 + idp->id_type = SMB_ACL_GROUP_OBJ;
4191 + new_acl_entry->ace_access = file_acl->o_access << 6;
4192 + idp->id_type = SMB_ACL_OTHER;
4196 + new_acl_entry->ace_access = file_acl->u_access << 6;
4197 + idp->id_type = SMB_ACL_USER_OBJ;
4204 + acl_entry_link_head->count++;
4205 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4208 + acl_entry_link_head->count = 0;
4209 + SAFE_FREE(file_acl);
4211 + return(acl_entry_link_head);
4214 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4216 + *permset = *permset & ~0777;
4220 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4223 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4227 + DEBUG(10,("This is the permset now: %d\n",*permset));
4231 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4236 +SMB_ACL_T sys_acl_init( int count)
4238 + struct acl_entry_link *theacl = NULL;
4240 + DEBUG(10,("Entering sys_acl_init\n"));
4242 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4243 + if(theacl == NULL) {
4245 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4249 + theacl->count = 0;
4250 + theacl->nextp = NULL;
4251 + theacl->prevp = NULL;
4252 + theacl->entryp = NULL;
4253 + DEBUG(10,("Exiting sys_acl_init\n"));
4257 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4259 + struct acl_entry_link *theacl;
4260 + struct acl_entry_link *acl_entryp;
4261 + struct acl_entry_link *temp_entry;
4264 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4266 + theacl = acl_entryp = *pacl;
4268 + /* Get to the end of the acl before adding entry */
4270 + for(counting=0; counting < theacl->count; counting++){
4271 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4272 + temp_entry = acl_entryp;
4273 + acl_entryp = acl_entryp->nextp;
4276 + if(theacl->count != 0){
4277 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4278 + if(acl_entryp == NULL) {
4280 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4284 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4285 + acl_entryp->prevp = temp_entry;
4286 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4289 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4290 + if(*pentry == NULL) {
4292 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4296 + memset(*pentry,0,sizeof(struct new_acl_entry));
4297 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4298 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4299 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4300 + acl_entryp->nextp = NULL;
4302 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4306 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4308 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4309 + entry->ace_id->id_type = tagtype;
4310 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4311 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4314 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4316 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4317 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4318 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4322 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4324 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4325 + if(!(*permset & S_IXUSR) &&
4326 + !(*permset & S_IWUSR) &&
4327 + !(*permset & S_IRUSR) &&
4331 + entry->ace_access = *permset;
4332 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4333 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4337 +int sys_acl_valid( SMB_ACL_T theacl )
4340 + int group_obj = 0;
4341 + int other_obj = 0;
4342 + struct acl_entry_link *acl_entry;
4344 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4345 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4346 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4347 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4350 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4352 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4358 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4360 + struct acl_entry_link *acl_entry_link = NULL;
4361 + struct acl *file_acl = NULL;
4362 + struct acl *file_acl_temp = NULL;
4363 + struct acl_entry *acl_entry = NULL;
4364 + struct ace_id *ace_id = NULL;
4371 + DEBUG(10,("Entering sys_acl_set_file\n"));
4372 + DEBUG(10,("File name is %s\n",name));
4374 + /* AIX has no default ACL */
4375 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4378 + acl_length = BUFSIZ;
4379 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4381 + if(file_acl == NULL) {
4383 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4387 + memset(file_acl,0,BUFSIZ);
4389 + file_acl->acl_len = ACL_SIZ;
4390 + file_acl->acl_mode = S_IXACL;
4392 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4393 + acl_entry_link->entryp->ace_access >>= 6;
4394 + id_type = acl_entry_link->entryp->ace_id->id_type;
4397 + case SMB_ACL_USER_OBJ:
4398 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4400 + case SMB_ACL_GROUP_OBJ:
4401 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4403 + case SMB_ACL_OTHER:
4404 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4406 + case SMB_ACL_MASK:
4410 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4411 + acl_length += sizeof(struct acl_entry);
4412 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4413 + if(file_acl_temp == NULL) {
4414 + SAFE_FREE(file_acl);
4416 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4420 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4421 + SAFE_FREE(file_acl);
4422 + file_acl = file_acl_temp;
4425 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4426 + file_acl->acl_len += sizeof(struct acl_entry);
4427 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4428 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4430 + /* In order to use this, we'll need to wait until we can get denies */
4431 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4432 + acl_entry->ace_type = ACC_SPECIFY; */
4434 + acl_entry->ace_type = ACC_SPECIFY;
4436 + ace_id = acl_entry->ace_id;
4438 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4439 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4440 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4441 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4442 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4445 + rc = chacl(name,file_acl,file_acl->acl_len);
4446 + DEBUG(10,("errno is %d\n",errno));
4447 + DEBUG(10,("return code is %d\n",rc));
4448 + SAFE_FREE(file_acl);
4449 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4453 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4455 + struct acl_entry_link *acl_entry_link = NULL;
4456 + struct acl *file_acl = NULL;
4457 + struct acl *file_acl_temp = NULL;
4458 + struct acl_entry *acl_entry = NULL;
4459 + struct ace_id *ace_id = NULL;
4465 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4466 + acl_length = BUFSIZ;
4467 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4469 + if(file_acl == NULL) {
4471 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4475 + memset(file_acl,0,BUFSIZ);
4477 + file_acl->acl_len = ACL_SIZ;
4478 + file_acl->acl_mode = S_IXACL;
4480 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4481 + acl_entry_link->entryp->ace_access >>= 6;
4482 + id_type = acl_entry_link->entryp->ace_id->id_type;
4483 + DEBUG(10,("The id_type is %d\n",id_type));
4486 + case SMB_ACL_USER_OBJ:
4487 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4489 + case SMB_ACL_GROUP_OBJ:
4490 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4492 + case SMB_ACL_OTHER:
4493 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4495 + case SMB_ACL_MASK:
4499 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4500 + acl_length += sizeof(struct acl_entry);
4501 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4502 + if(file_acl_temp == NULL) {
4503 + SAFE_FREE(file_acl);
4505 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4509 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4510 + SAFE_FREE(file_acl);
4511 + file_acl = file_acl_temp;
4514 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4515 + file_acl->acl_len += sizeof(struct acl_entry);
4516 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4517 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4519 + /* In order to use this, we'll need to wait until we can get denies */
4520 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4521 + acl_entry->ace_type = ACC_SPECIFY; */
4523 + acl_entry->ace_type = ACC_SPECIFY;
4525 + ace_id = acl_entry->ace_id;
4527 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4528 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4529 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4530 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4531 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4534 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4535 + DEBUG(10,("errno is %d\n",errno));
4536 + DEBUG(10,("return code is %d\n",rc));
4537 + SAFE_FREE(file_acl);
4538 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4542 +int sys_acl_delete_def_file(const char *name)
4544 + /* AIX has no default ACL */
4548 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4550 + return(*permset & perm);
4553 +int sys_acl_free_text(char *text)
4558 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4560 + struct acl_entry_link *acl_entry_link;
4562 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4563 + SAFE_FREE(acl_entry_link->prevp->entryp);
4564 + SAFE_FREE(acl_entry_link->prevp);
4567 + SAFE_FREE(acl_entry_link->prevp->entryp);
4568 + SAFE_FREE(acl_entry_link->prevp);
4569 + SAFE_FREE(acl_entry_link->entryp);
4570 + SAFE_FREE(acl_entry_link);
4575 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4580 +#else /* No ACLs. */
4582 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4588 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4594 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4600 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4606 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4609 + return (SMB_ACL_T)NULL;
4612 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4615 + return (SMB_ACL_T)NULL;
4618 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4624 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4630 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4633 + return (permset & perm) ? 1 : 0;
4636 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4642 +int sys_acl_free_text(UNUSED(char *text))
4648 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4654 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4660 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4666 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4672 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4678 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4684 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4690 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4696 +int sys_acl_delete_def_file(UNUSED(const char *name))
4702 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4708 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4714 +#endif /* No ACLs. */
4716 +/************************************************************************
4717 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4719 +************************************************************************/
4721 +int no_acl_syscall_error(int err)
4723 +#if defined(ENOSYS)
4724 + if (err == ENOSYS) {
4728 +#if defined(ENOTSUP)
4729 + if (err == ENOTSUP) {
4735 --- old/lib/sysacls.h
4736 +++ new/lib/sysacls.h
4738 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4739 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4740 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4741 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4742 +#define slprintf snprintf
4744 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4745 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4746 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4747 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4748 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4749 +SMB_ACL_T sys_acl_get_fd(int fd);
4750 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4751 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4752 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4753 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4754 +SMB_ACL_T sys_acl_init(int count);
4755 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4756 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4757 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4758 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4759 +int sys_acl_valid(SMB_ACL_T theacl);
4760 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4761 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4762 +int sys_acl_delete_def_file(const char *name);
4763 +int sys_acl_free_text(char *text);
4764 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4765 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4768 @@ -58,7 +58,7 @@ BEGIN {
4772 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4773 +!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4779 @@ -44,6 +44,7 @@ int keep_dirlinks = 0;
4781 int preserve_links = 0;
4782 int preserve_hard_links = 0;
4783 +int preserve_acls = 0;
4784 int preserve_perms = 0;
4785 int preserve_executability = 0;
4786 int preserve_devices = 0;
4787 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4788 char const *got_socketpair = "no ";
4789 char const *have_inplace = "no ";
4790 char const *hardlinks = "no ";
4791 + char const *acls = "no ";
4792 char const *links = "no ";
4793 char const *ipv6 = "no ";
4794 STRUCT_STAT *dumstat;
4795 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4799 +#ifdef SUPPORT_ACLS
4803 #ifdef SUPPORT_LINKS
4806 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4807 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4808 rprintf(f, "<http://rsync.samba.org/>\n");
4809 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4810 - "%shard links, %ssymlinks, batchfiles,\n",
4811 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4812 (int) (sizeof (OFF_T) * 8),
4813 - got_socketpair, hardlinks, links);
4814 + got_socketpair, hardlinks, acls, links);
4816 /* Note that this field may not have type ino_t. It depends
4817 * on the complicated interaction between largefile feature
4818 @@ -294,6 +300,9 @@ void usage(enum logcode F)
4819 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
4820 rprintf(F," -p, --perms preserve permissions\n");
4821 rprintf(F," -E, --executability preserve the file's executability\n");
4822 +#ifdef SUPPORT_ACLS
4823 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4825 rprintf(F," --chmod=CHMOD change destination permissions\n");
4826 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4827 rprintf(F," -g, --group preserve group\n");
4828 @@ -409,6 +418,9 @@ static struct poptOption long_options[]
4829 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4830 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4831 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4832 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4833 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4834 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4835 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4836 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4837 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4838 @@ -1062,6 +1074,23 @@ int parse_arguments(int *argc, const cha
4843 +#ifdef SUPPORT_ACLS
4844 + preserve_acls = preserve_perms = 1;
4847 + /* FIXME: this should probably be ignored with a
4848 + * warning and then countermeasures taken to
4849 + * restrict group and other access in the presence
4850 + * of any more restrictive ACLs, but this is safe
4852 + snprintf(err_buf,sizeof(err_buf),
4853 + "ACLs are not supported on this %s\n",
4854 + am_server ? "server" : "client");
4860 /* A large opt value means that set_refuse_options()
4861 * turned this option off. */
4862 @@ -1502,6 +1531,10 @@ void server_options(char **args,int *arg
4864 if (preserve_hard_links)
4866 +#ifdef SUPPORT_ACLS
4867 + if (preserve_acls)
4868 + argstr[x++] = 'A';
4875 @@ -349,6 +349,10 @@ int recv_files(int f_in, struct file_lis
4876 int itemizing = am_daemon ? daemon_log_format_has_i
4877 : !am_server && log_format_has_i;
4878 int max_phase = protocol_version >= 29 ? 2 : 1;
4879 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4880 +#ifdef SUPPORT_ACLS
4881 + char *parent_dirname = "";
4886 @@ -546,7 +550,16 @@ int recv_files(int f_in, struct file_lis
4887 * mode based on the local permissions and some heuristics. */
4888 if (!preserve_perms) {
4889 int exists = fd1 != -1;
4890 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4891 +#ifdef SUPPORT_ACLS
4892 + char *dn = file->dirname ? file->dirname : ".";
4893 + if (parent_dirname != dn
4894 + && strcmp(parent_dirname, dn) != 0) {
4895 + dflt_perms = default_perms_for_dir(dn);
4896 + parent_dirname = dn;
4899 + file->mode = dest_mode(file->mode, st.st_mode,
4900 + dflt_perms, exists);
4903 /* We now check to see if we are writing file "inplace" */
4906 @@ -100,7 +100,8 @@ void free_sums(struct sum_struct *s)
4908 /* This is only called when we aren't preserving permissions. Figure out what
4909 * the permissions should be and return them merged back into the mode. */
4910 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4911 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
4914 /* If the file already exists, we'll return the local permissions,
4915 * possibly tweaked by the --executability option. */
4916 @@ -115,7 +116,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4917 cur_mode |= (cur_mode & 0444) >> 2;
4920 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
4921 + cur_mode = (flist_mode & ACCESSPERMS & dflt_perms) | S_IWUSR;
4922 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
4925 @@ -214,6 +215,14 @@ int set_file_attrs(char *fname, struct f
4929 + /* If this is a directory, SET_ACL() will be called on the cleanup
4930 + * receive_generator() pass (if we called it here, we might clobber
4931 + * writability on the directory). Everything else is OK to do now. */
4932 + if (!S_ISDIR(st->st_mode)) {
4933 + if (SET_ACL(fname, file) == 0)
4937 if (verbose > 1 && flags & ATTRS_REPORT) {
4938 enum logcode code = daemon_log_format_has_i || dry_run
4942 @@ -657,6 +657,44 @@ struct chmod_mode_struct;
4944 #define UNUSED(x) x __attribute__((__unused__))
4946 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4947 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4948 +#define SUPPORT_ACLS 1
4951 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4952 +#define ACLS_NEED_MASK 1
4955 +#ifdef SUPPORT_ACLS
4956 +#ifdef HAVE_SYS_ACL_H
4957 +#include <sys/acl.h>
4959 +#define MAKE_ACL(file, fname) make_acl(file, fname)
4960 +#define SEND_ACL(file, f) send_acl(file, f)
4961 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
4962 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4963 +#define SET_ACL(fname, file) set_acl(fname, file)
4964 +#define NEXT_ACL_UID() next_acl_uid()
4965 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
4966 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4967 + push_keep_backup_acl(file, orig, dest)
4968 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4969 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4970 +#else /* SUPPORT_ACLS */
4971 +#define MAKE_ACL(file, fname) 1 /* checked return value */
4972 +#define SEND_ACL(file, f)
4973 +#define RECEIVE_ACL(file, f)
4974 +#define SORT_FILE_ACL_INDEX_LISTS()
4975 +#define SET_ACL(fname, file) 1 /* checked return value */
4976 +#define NEXT_ACL_UID()
4977 +#define ACL_UID_MAP(uid)
4978 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4979 +#define CLEANUP_KEEP_BACKUP_ACL()
4980 +#define DUP_ACL(src, orig, mode) 1 /* checked return value */
4981 +#endif /* SUPPORT_ACLS */
4982 +#include "smb_acls.h"
4986 /* We have replacement versions of these if they're missing. */
4989 @@ -317,6 +317,7 @@ to the detailed description below for a
4990 -K, --keep-dirlinks treat symlinked dir on receiver as dir
4991 -p, --perms preserve permissions
4992 -E, --executability preserve executability
4993 + -A, --acls preserve ACLs (implies -p) [non-standard]
4994 --chmod=CHMOD change destination permissions
4995 -o, --owner preserve owner (super-user only)
4996 -g, --group preserve group
4997 @@ -693,7 +694,9 @@ quote(itemize(
4998 permissions, though the bf(--executability) option might change just
4999 the execute permission for the file.
5000 it() New files get their "normal" permission bits set to the source
5001 - file's permissions masked with the receiving end's umask setting, and
5002 + file's permissions masked with the receiving directory's default
5003 + permissions (either the receiving process's umask, or the permissions
5004 + specified via the destination directory's default ACL), and
5005 their special permission bits disabled except in the case where a new
5006 directory inherits a setgid bit from its parent directory.
5008 @@ -724,9 +727,11 @@ The preservation of the destination's se
5009 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5010 versions erroneously preserved the three special permission bits for
5011 newly-created files when bf(--perms) was off, while overriding the
5012 -destination's setgid bit setting on a newly-created directory. (Keep in
5013 -mind that it is the version of the receiving rsync that affects this
5015 +destination's setgid bit setting on a newly-created directory. Default ACL
5016 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5017 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5018 +(Keep in mind that it is the version of the receiving rsync that affects
5021 dit(bf(-E, --executability)) This option causes rsync to preserve the
5022 executability (or non-executability) of regular files when bf(--perms) is
5023 @@ -744,6 +749,10 @@ quote(itemize(
5025 If bf(--perms) is enabled, this option is ignored.
5027 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5028 +ACLs to be the same as the source ACLs. This nonstandard option only
5029 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5031 dit(bf(--chmod)) This option tells rsync to apply one or more
5032 comma-separated "chmod" strings to the permission of the files in the
5033 transfer. The resulting value is treated as though it was the permissions
5038 + Unix SMB/Netbios implementation.
5040 + Portable SMB ACL interface
5041 + Copyright (C) Jeremy Allison 2000
5043 + This program is free software; you can redistribute it and/or modify
5044 + it under the terms of the GNU General Public License as published by
5045 + the Free Software Foundation; either version 2 of the License, or
5046 + (at your option) any later version.
5048 + This program is distributed in the hope that it will be useful,
5049 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5050 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5051 + GNU General Public License for more details.
5053 + You should have received a copy of the GNU General Public License
5054 + along with this program; if not, write to the Free Software
5055 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5058 +#ifndef _SMB_ACLS_H
5059 +#define _SMB_ACLS_H
5061 +#if defined(HAVE_POSIX_ACLS)
5063 +/* This is an identity mapping (just remove the SMB_). */
5065 +#define SMB_ACL_TAG_T acl_tag_t
5066 +#define SMB_ACL_TYPE_T acl_type_t
5067 +#define SMB_ACL_PERMSET_T acl_permset_t
5068 +#define SMB_ACL_PERM_T acl_perm_t
5069 +#define SMB_ACL_READ ACL_READ
5070 +#define SMB_ACL_WRITE ACL_WRITE
5071 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5073 +/* Types of ACLs. */
5074 +#define SMB_ACL_USER ACL_USER
5075 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5076 +#define SMB_ACL_GROUP ACL_GROUP
5077 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5078 +#define SMB_ACL_OTHER ACL_OTHER
5079 +#define SMB_ACL_MASK ACL_MASK
5081 +#define SMB_ACL_T acl_t
5083 +#define SMB_ACL_ENTRY_T acl_entry_t
5085 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5086 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5088 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5089 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5091 +#elif defined(HAVE_TRU64_ACLS)
5093 +/* This is for DEC/Compaq Tru64 UNIX */
5095 +#define SMB_ACL_TAG_T acl_tag_t
5096 +#define SMB_ACL_TYPE_T acl_type_t
5097 +#define SMB_ACL_PERMSET_T acl_permset_t
5098 +#define SMB_ACL_PERM_T acl_perm_t
5099 +#define SMB_ACL_READ ACL_READ
5100 +#define SMB_ACL_WRITE ACL_WRITE
5101 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5103 +/* Types of ACLs. */
5104 +#define SMB_ACL_USER ACL_USER
5105 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5106 +#define SMB_ACL_GROUP ACL_GROUP
5107 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5108 +#define SMB_ACL_OTHER ACL_OTHER
5109 +#define SMB_ACL_MASK ACL_MASK
5111 +#define SMB_ACL_T acl_t
5113 +#define SMB_ACL_ENTRY_T acl_entry_t
5115 +#define SMB_ACL_FIRST_ENTRY 0
5116 +#define SMB_ACL_NEXT_ENTRY 1
5118 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5119 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5121 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
5123 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5124 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5127 +/* SVR4.2 ES/MP ACLs */
5128 +typedef int SMB_ACL_TAG_T;
5129 +typedef int SMB_ACL_TYPE_T;
5130 +typedef ushort *SMB_ACL_PERMSET_T;
5131 +typedef ushort SMB_ACL_PERM_T;
5132 +#define SMB_ACL_READ 4
5133 +#define SMB_ACL_WRITE 2
5134 +#define SMB_ACL_EXECUTE 1
5136 +/* Types of ACLs. */
5137 +#define SMB_ACL_USER USER
5138 +#define SMB_ACL_USER_OBJ USER_OBJ
5139 +#define SMB_ACL_GROUP GROUP
5140 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5141 +#define SMB_ACL_OTHER OTHER_OBJ
5142 +#define SMB_ACL_MASK CLASS_OBJ
5144 +typedef struct SMB_ACL_T {
5148 + struct acl acl[1];
5151 +typedef struct acl *SMB_ACL_ENTRY_T;
5153 +#define SMB_ACL_FIRST_ENTRY 0
5154 +#define SMB_ACL_NEXT_ENTRY 1
5156 +#define SMB_ACL_TYPE_ACCESS 0
5157 +#define SMB_ACL_TYPE_DEFAULT 1
5159 +#elif defined(HAVE_HPUX_ACLS)
5162 + * Based on the Solaris & UnixWare code.
5166 +#include <sys/aclv.h>
5168 +/* SVR4.2 ES/MP ACLs */
5169 +typedef int SMB_ACL_TAG_T;
5170 +typedef int SMB_ACL_TYPE_T;
5171 +typedef ushort *SMB_ACL_PERMSET_T;
5172 +typedef ushort SMB_ACL_PERM_T;
5173 +#define SMB_ACL_READ 4
5174 +#define SMB_ACL_WRITE 2
5175 +#define SMB_ACL_EXECUTE 1
5177 +/* Types of ACLs. */
5178 +#define SMB_ACL_USER USER
5179 +#define SMB_ACL_USER_OBJ USER_OBJ
5180 +#define SMB_ACL_GROUP GROUP
5181 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5182 +#define SMB_ACL_OTHER OTHER_OBJ
5183 +#define SMB_ACL_MASK CLASS_OBJ
5185 +typedef struct SMB_ACL_T {
5189 + struct acl acl[1];
5192 +typedef struct acl *SMB_ACL_ENTRY_T;
5194 +#define SMB_ACL_FIRST_ENTRY 0
5195 +#define SMB_ACL_NEXT_ENTRY 1
5197 +#define SMB_ACL_TYPE_ACCESS 0
5198 +#define SMB_ACL_TYPE_DEFAULT 1
5200 +#elif defined(HAVE_IRIX_ACLS)
5202 +#define SMB_ACL_TAG_T acl_tag_t
5203 +#define SMB_ACL_TYPE_T acl_type_t
5204 +#define SMB_ACL_PERMSET_T acl_permset_t
5205 +#define SMB_ACL_PERM_T acl_perm_t
5206 +#define SMB_ACL_READ ACL_READ
5207 +#define SMB_ACL_WRITE ACL_WRITE
5208 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5210 +/* Types of ACLs. */
5211 +#define SMB_ACL_USER ACL_USER
5212 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5213 +#define SMB_ACL_GROUP ACL_GROUP
5214 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5215 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5216 +#define SMB_ACL_MASK ACL_MASK
5218 +typedef struct SMB_ACL_T {
5224 +#define SMB_ACL_ENTRY_T acl_entry_t
5226 +#define SMB_ACL_FIRST_ENTRY 0
5227 +#define SMB_ACL_NEXT_ENTRY 1
5229 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5230 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5232 +#elif defined(HAVE_AIX_ACLS)
5234 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5236 +#include "/usr/include/acl.h"
5238 +typedef uint *SMB_ACL_PERMSET_T;
5240 +struct acl_entry_link{
5241 + struct acl_entry_link *prevp;
5242 + struct new_acl_entry *entryp;
5243 + struct acl_entry_link *nextp;
5247 +struct new_acl_entry{
5248 + unsigned short ace_len;
5249 + unsigned short ace_type;
5250 + unsigned int ace_access;
5251 + struct ace_id ace_id[1];
5254 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5255 +#define SMB_ACL_T struct acl_entry_link*
5257 +#define SMB_ACL_TAG_T unsigned short
5258 +#define SMB_ACL_TYPE_T int
5259 +#define SMB_ACL_PERM_T uint
5260 +#define SMB_ACL_READ S_IRUSR
5261 +#define SMB_ACL_WRITE S_IWUSR
5262 +#define SMB_ACL_EXECUTE S_IXUSR
5264 +/* Types of ACLs. */
5265 +#define SMB_ACL_USER ACEID_USER
5266 +#define SMB_ACL_USER_OBJ 3
5267 +#define SMB_ACL_GROUP ACEID_GROUP
5268 +#define SMB_ACL_GROUP_OBJ 4
5269 +#define SMB_ACL_OTHER 5
5270 +#define SMB_ACL_MASK 6
5273 +#define SMB_ACL_FIRST_ENTRY 1
5274 +#define SMB_ACL_NEXT_ENTRY 2
5276 +#define SMB_ACL_TYPE_ACCESS 0
5277 +#define SMB_ACL_TYPE_DEFAULT 1
5279 +#else /* No ACLs. */
5281 +/* No ACLS - fake it. */
5282 +#define SMB_ACL_TAG_T int
5283 +#define SMB_ACL_TYPE_T int
5284 +#define SMB_ACL_PERMSET_T mode_t
5285 +#define SMB_ACL_PERM_T mode_t
5286 +#define SMB_ACL_READ S_IRUSR
5287 +#define SMB_ACL_WRITE S_IWUSR
5288 +#define SMB_ACL_EXECUTE S_IXUSR
5290 +/* Types of ACLs. */
5291 +#define SMB_ACL_USER 0
5292 +#define SMB_ACL_USER_OBJ 1
5293 +#define SMB_ACL_GROUP 2
5294 +#define SMB_ACL_GROUP_OBJ 3
5295 +#define SMB_ACL_OTHER 4
5296 +#define SMB_ACL_MASK 5
5298 +typedef struct SMB_ACL_T {
5302 +typedef struct SMB_ACL_ENTRY_T {
5304 +} *SMB_ACL_ENTRY_T;
5306 +#define SMB_ACL_FIRST_ENTRY 0
5307 +#define SMB_ACL_NEXT_ENTRY 1
5309 +#define SMB_ACL_TYPE_ACCESS 0
5310 +#define SMB_ACL_TYPE_DEFAULT 1
5312 +#endif /* No ACLs. */
5313 +#endif /* _SMB_ACLS_H */
5314 --- old/testsuite/default-acls.test
5315 +++ new/testsuite/default-acls.test
5319 +# This program is distributable under the terms of the GNU GPL see
5322 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5324 +. $srcdir/testsuite/rsync.fns
5326 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5327 +setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5329 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5331 + todir="$scratchdir/$1"
5333 + # FIXME This doesn't work on solaris...
5334 + setfacl -k "$todir"
5335 + [ "$2" ] && setfacl -dm "$2" "$todir"
5336 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5337 + # even though the directory itself is outside the transfer
5338 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5339 + check_perms "$todir/to" $4 "Target $1"
5340 + check_perms "$todir/to/dir" $4 "Target $1"
5341 + check_perms "$todir/to/file" $3 "Target $1"
5342 + check_perms "$todir/to/program" $4 "Target $1"
5343 + # Make sure get_local_name doesn't mess us up when transferring only one file
5344 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5345 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5346 + # Make sure we obey default ACLs when not transferring a regular file
5347 + $RSYNC -rvv "$scratchdir/dir" "$todir/to/anotherdir"
5348 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5351 +mkdir "$scratchdir/dir"
5352 +echo "File!" >"$scratchdir/file"
5353 +echo "#!/bin/sh" >"$scratchdir/program"
5354 +chmod 777 "$scratchdir/dir"
5355 +chmod 666 "$scratchdir/file"
5356 +chmod 777 "$scratchdir/program"
5358 +# Test some target directories
5360 +testit da777 u::rwx,g::rwx,o::rwx rw-rw-rw- rwxrwxrwx
5361 +testit da775 u::rwx,g::rwx,o::r-x rw-rw-r-- rwxrwxr-x
5362 +testit da750 u::rwx,g::r-x,o::--- rw-r----- rwxr-x---
5363 +testit da770mask u::rwx,g::---,m::rwx,o::--- rw-rw---- rwxrwx---
5364 +testit noda1 '' rw------- rwx------
5366 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5368 +testit noda3 '' rw-r--r-- rwxr-xr-x
5376 extern int preserve_uid;
5377 extern int preserve_gid;
5378 +extern int preserve_acls;
5379 extern int numeric_ids;
5382 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5386 - if (preserve_uid) {
5387 + if (preserve_uid || preserve_acls) {
5389 /* we send sequences of uid/byte-length/name */
5390 for (list = uidlist; list; list = list->next) {
5391 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5395 - if (preserve_gid) {
5396 + if (preserve_gid || preserve_acls) {
5398 for (list = gidlist; list; list = list->next) {
5400 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5404 - if (preserve_uid && !numeric_ids) {
5405 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5406 /* read the uid list */
5407 while ((id = read_int(f)) != 0) {
5408 int len = read_byte(f);
5409 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5413 - if (preserve_gid && !numeric_ids) {
5414 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5415 /* read the gid list */
5416 while ((id = read_int(f)) != 0) {
5417 int len = read_byte(f);
5418 @@ -336,6 +337,18 @@ void recv_uid_list(int f, struct file_li
5422 +#ifdef SUPPORT_ACLS
5423 + if (preserve_acls && !numeric_ids) {
5425 + /* The enumerations don't return 0 except to flag the last
5426 + * entry, since uidlist doesn't munge 0 anyway. */
5427 + while ((id = next_acl_uid(flist)) != 0)
5428 + acl_uid_map(match_uid(id));
5429 + while ((id = next_acl_gid(flist)) != 0)
5430 + acl_gid_map(match_gid(id));
5432 +#endif /* SUPPORT_ACLS */
5434 /* Now convert all the uids/gids from sender values to our values. */
5435 if (am_root && preserve_uid && !numeric_ids) {
5436 for (i = 0; i < flist->count; i++)