1 After applying this patch, run these commands for a successful build:
5 ./configure --enable-acl-support
9 The program currently complains when the --acls (-A) option is used to copy
10 from a disk that doesn't support ACLs. This should be changed to silently
11 notice that no ACLs are available to copy. Of course, trying to write out
12 ACLs to a non-ACL-supporting disk should complain.
14 --- orig/Makefile.in 2006-01-14 08:14:29
15 +++ Makefile.in 2005-11-07 04:31:05
16 @@ -25,15 +25,15 @@ VERSION=@VERSION@
20 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
21 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
22 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
23 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
24 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
25 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
26 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
27 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
28 main.o checksum.o match.o syscall.o log.o backup.o
29 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
30 - fileio.o batch.o clientname.o chmod.o
31 + fileio.o batch.o clientname.o chmod.o acls.o
32 OBJS3=progress.o pipe.o
33 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
34 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 --- orig/acls.c 2006-01-31 19:25:53
36 +++ acls.c 2006-01-31 19:25:53
38 +/* -*- c-file-style: "linux" -*-
39 + Copyright (C) Andrew Tridgell 1996
40 + Copyright (C) Paul Mackerras 1996
42 + This program is free software; you can redistribute it and/or modify
43 + it under the terms of the GNU General Public License as published by
44 + the Free Software Foundation; either version 2 of the License, or
45 + (at your option) any later version.
47 + This program is distributed in the hope that it will be useful,
48 + but WITHOUT ANY WARRANTY; without even the implied warranty of
49 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 + GNU General Public License for more details.
52 + You should have received a copy of the GNU General Public License
53 + along with this program; if not, write to the Free Software
54 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
57 +/* handle passing ACLs between systems */
60 +#include "lib/sysacls.h"
64 +extern int preserve_acls;
67 +extern int orig_umask;
72 + SMB_ACL_TAG_T tag_type;
81 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
83 +static void expand_rsync_acl(rsync_acl *racl)
85 + /* First time through, 0 <= 0, so list is expanded.
86 + * (Diabolical, rsync guys!) */
87 + if (racl->malloced <= racl->count) {
89 + size_t new_size = racl->malloced + 10;
90 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
92 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
93 + (double) new_size * sizeof racl->races[0],
94 + racl->races ? "" : " not");
97 + racl->races = new_ptr;
98 + racl->malloced = new_size;
101 + out_of_memory("expand_rsync_acl");
105 +static void rsync_acl_free(rsync_acl *racl)
108 + racl->races = NULL;
110 + racl->malloced = 0;
113 +static int rsync_ace_sorter(const void *r1, const void *r2)
115 + rsync_ace *race1 = (rsync_ace *)r1;
116 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
117 + id_t rid1 = race1->id;
118 + rsync_ace *race2 = (rsync_ace *)r2;
119 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
120 + id_t rid2 = race2->id;
121 + /* start at the extrema */
122 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
124 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
127 + if (rtag1 == SMB_ACL_OTHER)
129 + if (rtag2 == SMB_ACL_OTHER)
131 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
132 + if (rtag1 == SMB_ACL_USER) {
134 + case SMB_ACL_GROUP:
135 + case SMB_ACL_GROUP_OBJ:
136 + case SMB_ACL_OTHER:
140 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
142 + if (rtag2 == SMB_ACL_USER)
144 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
145 + if (rtag1 == SMB_ACL_GROUP_OBJ)
147 + if (rtag2 == SMB_ACL_GROUP_OBJ)
149 + /* only SMB_ACL_GROUPs left */
150 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
153 +static void sort_rsync_acl(rsync_acl *racl)
157 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
158 + &rsync_ace_sorter);
161 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
163 + SMB_ACL_ENTRY_T entry;
165 + const char *errfun;
166 + *racl = rsync_acl_initializer;
167 + errfun = "sys_acl_get_entry";
168 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
170 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
171 + SMB_ACL_PERMSET_T permset;
174 + expand_rsync_acl(racl);
175 + race = &racl->races[racl->count++];
176 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
177 + errfun = "sys_acl_get_tag_type";
180 + if ((rc = sys_acl_get_permset(entry, &permset))) {
181 + errfun = "sys_acl_get_tag_type";
184 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
185 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
186 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
187 + switch (race->tag_type) {
189 + case SMB_ACL_GROUP:
194 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
195 + errfun = "sys_acl_get_tag_type";
199 + race->id = *((id_t *)qualifier);
200 + sys_acl_free_qualifier(qualifier, race->tag_type);
203 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
204 + errfun, strerror(errno));
205 + rsync_acl_free(racl);
208 + sort_rsync_acl(racl);
212 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
214 + rsync_ace *race1, *race2;
215 + size_t count = racl1->count;
216 + if (count != racl2->count)
218 + race1 = racl1->races;
219 + race2 = racl2->races;
220 + for (; count--; race1++, race2++) {
221 + if (race1->tag_type != race2->tag_type
222 + || race1->access != race2->access
223 + || ((race1->tag_type == SMB_ACL_USER
224 + || race1->tag_type == SMB_ACL_GROUP)
225 + && race1->id != race2->id))
237 +static rsync_acl_list _rsync_acl_lists[] = {
238 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
239 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
242 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
244 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
245 + : &_rsync_acl_lists[1];
248 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
250 + /* First time through, 0 <= 0, so list is expanded.
251 + * (Diabolical, rsync guys!) */
252 + if (racl_list->malloced <= racl_list->count) {
253 + rsync_acl *new_ptr;
255 + if (racl_list->malloced < 1000)
256 + new_size = racl_list->malloced + 1000;
258 + new_size = racl_list->malloced * 2;
259 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
260 + if (verbose >= 3) {
261 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
262 + (double) new_size * sizeof racl_list->racls[0],
263 + racl_list->racls ? "" : " not");
266 + racl_list->racls = new_ptr;
267 + racl_list->malloced = new_size;
269 + if (!racl_list->racls)
270 + out_of_memory("expand_rsync_acl_list");
275 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
277 + /* Run this in reverse, so references are freed before referents,
278 + * although not currently necessary. */
279 + while (racl_list->count--) {
280 + rsync_acl *racl = &racl_list->racls[racl_list->count];
282 + rsync_acl_free(racl);
284 + free(racl_list->racls);
285 + racl_list->racls = NULL;
286 + racl_list->malloced = 0;
290 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
291 + const rsync_acl_list *racl_list,
292 + const rsync_acl *racl)
294 + static int access_match = -1, default_match = -1;
295 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
296 + &access_match : &default_match;
297 + size_t count = racl_list->count;
298 + /* If this is the first time through or we didn't match the last
299 + * time, then start at the end of the list, which should be the
300 + * best place to start hunting. */
302 + *match = racl_list->count - 1;
304 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
307 + *match = racl_list->count - 1;
313 +/* The general strategy with the tag_type <-> character mapping is that
314 + * lowercase implies that no qualifier follows, where uppercase does.
315 + * A similar idiom for the acl type (access or default) itself, but
316 + * lowercase in this instance means there's no ACL following, so the
317 + * ACL is a repeat, so the receiver should reuse the last of the same
320 +static void send_rsync_acl(int f, const rsync_acl *racl)
323 + size_t count = racl->count;
324 + write_int(f, count);
325 + for (race = racl->races; count--; race++) {
327 + switch (race->tag_type) {
328 + case SMB_ACL_USER_OBJ:
334 + case SMB_ACL_GROUP_OBJ:
337 + case SMB_ACL_GROUP:
340 + case SMB_ACL_OTHER:
348 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
353 + write_byte(f, race->access);
354 + if (isupper((int)ch)) {
355 + write_int(f, race->id);
356 + /* FIXME: sorta wasteful: we should maybe buffer as
357 + * many ids as max(ACL_USER + ACL_GROUP) objects to
358 + * keep from making so many calls. */
367 +static rsync_acl _curr_rsync_acls[2];
370 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
372 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
373 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
374 + "unknown SMB_ACL_TYPE_T";
377 +/* Generate the ACL(s) for this flist entry;
378 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
380 +int make_acl(const struct file_struct *file, const char *fname)
382 + SMB_ACL_TYPE_T *type,
383 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
384 + rsync_acl *curr_racl;
385 + if (!preserve_acls || S_ISLNK(file->mode))
387 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
388 + type < &types[0] + sizeof types / sizeof types[0]
389 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
390 + type++, curr_racl++) {
393 + *curr_racl = rsync_acl_initializer;
394 + if (!(sacl = sys_acl_get_file(fname, *type))) {
395 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
396 + fname, str_acl_type(*type), strerror(errno));
399 + ok = unpack_smb_acl(curr_racl, sacl);
400 + sys_acl_free_acl(sacl);
407 +/* Send the make_acl()-generated ACLs for this flist entry,
408 + * or clean up after an flist entry that's not being sent (f == -1). */
410 +void send_acl(const struct file_struct *file, int f)
412 + SMB_ACL_TYPE_T *type,
413 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
414 + rsync_acl *curr_racl;
415 + if (!preserve_acls || S_ISLNK(file->mode))
417 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
418 + type < &types[0] + sizeof types / sizeof types[0]
419 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
420 + type++, curr_racl++) {
422 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
424 + rsync_acl_free(curr_racl);
427 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
429 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
430 + write_int(f, index);
431 + rsync_acl_free(curr_racl);
433 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
434 + send_rsync_acl(f, curr_racl);
435 + expand_rsync_acl_list(racl_list);
436 + racl_list->racls[racl_list->count++] = *curr_racl;
441 +/* The below stuff is only used by the receiver: */
443 +/* structure to hold index to rsync_acl_list member corresponding to
444 + * flist->files[i] */
447 + const struct file_struct *file;
454 + file_acl_index *fileaclidxs;
455 +} file_acl_index_list;
457 +static file_acl_index_list _file_acl_index_lists[] = {
458 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
459 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
462 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
464 + return type == SMB_ACL_TYPE_ACCESS ?
465 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
468 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
470 + /* First time through, 0 <= 0, so list is expanded.
471 + * (Diabolical, rsync guys!) */
472 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
473 + file_acl_index *new_ptr;
475 + if (fileaclidx_list->malloced < 1000)
476 + new_size = fileaclidx_list->malloced + 1000;
478 + new_size = fileaclidx_list->malloced * 2;
479 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
480 + if (verbose >= 3) {
481 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
482 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
483 + fileaclidx_list->fileaclidxs ? "" : " not");
486 + fileaclidx_list->fileaclidxs = new_ptr;
487 + fileaclidx_list->malloced = new_size;
489 + if (!fileaclidx_list->fileaclidxs)
490 + out_of_memory("expand_file_acl_index_list");
495 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
497 + free(fileaclidx_list->fileaclidxs);
498 + fileaclidx_list->fileaclidxs = NULL;
499 + fileaclidx_list->malloced = 0;
503 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
511 +static smb_acl_list _smb_acl_lists[] = {
512 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
513 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
516 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
518 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
519 + &_smb_acl_lists[1];
522 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
524 + /* First time through, 0 <= 0, so list is expanded.
525 + * (Diabolical, rsync guys!) */
526 + if (sacl_list->malloced <= sacl_list->count) {
527 + SMB_ACL_T *new_ptr;
529 + if (sacl_list->malloced < 1000)
530 + new_size = sacl_list->malloced + 1000;
532 + new_size = sacl_list->malloced * 2;
533 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
534 + if (verbose >= 3) {
535 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
536 + (double) new_size * sizeof sacl_list->sacls[0],
537 + sacl_list->sacls ? "" : " not");
540 + sacl_list->sacls = new_ptr;
541 + sacl_list->malloced = new_size;
543 + if (!sacl_list->sacls)
544 + out_of_memory("expand_smb_acl_list");
549 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
551 + smb_acl_list *sacl_list = smb_acl_lists(type);
552 + SMB_ACL_T *sacl = sacl_list->sacls;
553 + while (sacl_list->count--) {
555 + sys_acl_free_acl(*sacl++);
557 + free(sacl_list->sacls);
558 + sacl_list->sacls = NULL;
559 + sacl_list->malloced = 0;
563 +/* build an SMB_ACL_T corresponding to an rsync_acl */
564 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
566 + size_t count = racl->count;
567 + rsync_ace *race = racl->races;
568 + const char *errfun = NULL;
569 + *smb_acl = sys_acl_init(count);
571 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
575 + for (; count--; race++) {
576 + SMB_ACL_ENTRY_T entry;
577 + SMB_ACL_PERMSET_T permset;
578 + if (sys_acl_create_entry(smb_acl, &entry)) {
579 + errfun = "sys_acl_create)";
582 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
583 + errfun = "sys_acl_set_tag";
586 + if (race->tag_type == SMB_ACL_USER ||
587 + race->tag_type == SMB_ACL_GROUP)
588 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
589 + errfun = "sys_acl_set_qualfier";
592 + if (sys_acl_get_permset(entry, &permset)) {
593 + errfun = "sys_acl_get_permset";
596 + if (sys_acl_clear_perms(permset)) {
597 + errfun = "sys_acl_clear_perms";
600 + if (race->access & 4)
601 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
602 + errfun = "sys_acl_add_perm";
605 + if (race->access & 2)
606 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
607 + errfun = "sys_acl_add_perm";
610 + if (race->access & 1)
611 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
612 + errfun = "sys_acl_add_perm";
615 + if (sys_acl_set_permset(entry, permset)) {
616 + errfun = "sys_acl_set_permset";
621 + sys_acl_free_acl(*smb_acl);
622 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
629 +static void receive_rsync_acl(rsync_acl *racl, int f)
632 + uchar required_mask_perm = 0;
634 + BOOL saw_mask = False;
635 + BOOL saw_user_obj = False, saw_group_obj = False,
637 + size_t count = read_int(f);
642 + uchar tag = read_byte(f);
643 + expand_rsync_acl(racl);
644 + race = &racl->races[racl->count++];
647 + race->tag_type = SMB_ACL_USER_OBJ;
648 + saw_user_obj = True;
651 + race->tag_type = SMB_ACL_USER;
654 + race->tag_type = SMB_ACL_GROUP_OBJ;
655 + saw_group_obj = True;
658 + race->tag_type = SMB_ACL_GROUP;
661 + race->tag_type = SMB_ACL_OTHER;
665 + race->tag_type = SMB_ACL_MASK;
669 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
671 + exit_cleanup(RERR_STREAMIO);
673 + race->access = read_byte(f);
674 + if (race->access & ~ (4 | 2 | 1)) {
675 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
677 + exit_cleanup(RERR_STREAMIO);
679 + if (race->tag_type == SMB_ACL_USER ||
680 + race->tag_type == SMB_ACL_GROUP) {
681 + race->id = read_int(f);
683 + required_mask_perm |= race->access;
687 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
688 + required_mask_perm |= race->access;
692 + if (!saw_user_obj) {
693 + expand_rsync_acl(racl);
694 + race = &racl->races[racl->count++];
695 + race->tag_type = SMB_ACL_USER_OBJ;
698 + if (!saw_group_obj) {
699 + expand_rsync_acl(racl);
700 + race = &racl->races[racl->count++];
701 + race->tag_type = SMB_ACL_GROUP_OBJ;
705 + expand_rsync_acl(racl);
706 + race = &racl->races[racl->count++];
707 + race->tag_type = SMB_ACL_OTHER;
712 + expand_rsync_acl(racl);
713 + race = &racl->races[racl->count++];
714 + race->tag_type = SMB_ACL_MASK;
715 + race->access = required_mask_perm;
718 + /* If we, a system without ACLS_NEED_MASK, received data from a
719 + * system that has masks, throw away the extraneous CLASS_OBJs. */
720 + if (saw_mask && racl->count == 4) {
721 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
724 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
725 + if (p->tag_type == SMB_ACL_MASK)
727 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
728 + group_obj_race = p;
730 + if (mask_race == NULL || group_obj_race == NULL) {
731 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
732 + "and one's ACL_MASK but missing "
733 + "either it or ACL_GROUP_OBJ, "
734 + "when pruning ACL\n");
736 + /* mask off group perms with it first */
737 + group_obj_race->access &= mask_race->access;
738 + /* dump mask_race; re-slot any followers-on */
740 + if (mask_race != &racl->races[racl->count]) {
741 + *mask_race = racl->races[racl->count];
742 + saw_user_obj = False; /* force re-sort */
748 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
750 + if (!(saw_user_obj && saw_group_obj && saw_other))
752 + sort_rsync_acl(racl);
755 +/* receive and build the rsync_acl_lists */
757 +void receive_acl(struct file_struct *file, int f)
759 + SMB_ACL_TYPE_T *type,
760 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
762 + if (!preserve_acls || S_ISLNK(file->mode))
764 + fname = f_name(file, NULL);
765 + for (type = &types[0];
766 + type < &types[0] + sizeof types / sizeof types[0]
767 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
769 + file_acl_index_list *fileaclidx_list =
770 + file_acl_index_lists(*type);
772 + expand_file_acl_index_list(fileaclidx_list);
774 + tag = read_byte(f);
775 + if (tag == 'A' || tag == 'a') {
776 + if (*type != SMB_ACL_TYPE_ACCESS) {
777 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
779 + exit_cleanup(RERR_STREAMIO);
781 + } else if (tag == 'D' || tag == 'd') {
782 + if (*type == SMB_ACL_TYPE_ACCESS) {
783 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
785 + exit_cleanup(RERR_STREAMIO);
788 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
790 + exit_cleanup(RERR_STREAMIO);
792 + if (tag == 'A' || tag == 'D') {
793 + rsync_acl racl = rsync_acl_initializer;
794 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
795 + smb_acl_list *sacl_list = smb_acl_lists(*type);
796 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
797 + aclidx = racl_list->count;
798 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
800 + receive_rsync_acl(&racl, f);
801 + expand_rsync_acl_list(racl_list);
802 + racl_list->racls[racl_list->count++] = racl;
803 + expand_smb_acl_list(sacl_list);
804 + sacl_list->sacls[sacl_list->count++] = NULL;
806 + int index = read_int(f);
807 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
808 + if ((size_t) index >= racl_list->count) {
809 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
811 + str_acl_type(*type),
813 + exit_cleanup(RERR_STREAMIO);
815 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
817 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
823 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
825 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
826 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
827 + return fileaclidx1->file == fileaclidx2->file ? 0 :
828 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
831 +void sort_file_acl_index_lists()
833 + SMB_ACL_TYPE_T *type,
834 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
835 + if (!preserve_acls)
837 + for (type = &types[0];
838 + type < &types[0] + sizeof types / sizeof types[0];
841 + file_acl_index_list *fileaclidx_list =
842 + file_acl_index_lists(*type);
843 + if (!fileaclidx_list->count)
845 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
846 + sizeof fileaclidx_list->fileaclidxs[0],
847 + &file_acl_index_list_sorter);
851 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
852 + const struct file_struct *file) {
853 + int low = 0, high = fileaclidx_list->count;
854 + const struct file_struct *file_mid;
858 + int mid = (high + low) / 2;
859 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
860 + if (file_mid == file)
861 + return fileaclidx_list->fileaclidxs[mid].aclidx;
862 + if (file_mid > file)
866 + } while (low < high);
868 + file_mid = fileaclidx_list->fileaclidxs[low].file;
869 + if (file_mid == file)
870 + return fileaclidx_list->fileaclidxs[low].aclidx;
873 + "find_file_acl_index: can't find entry for file in list\n");
874 + exit_cleanup(RERR_STREAMIO);
878 +/* for duplicating ACLs on backups when using backup_dir */
880 +int dup_acl(const char *orig, const char *bak, mode_t mode)
882 + SMB_ACL_TYPE_T *type,
883 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
885 + if (!preserve_acls)
887 + for (type = &types[0];
888 + type < &types[0] + sizeof types / sizeof types[0]
889 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
891 + SMB_ACL_T sacl_orig, sacl_bak;
892 + rsync_acl racl_orig, racl_bak;
893 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
894 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
895 + orig, str_acl_type(*type), strerror(errno));
899 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
900 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
901 + bak, str_acl_type(*type), strerror(errno));
903 + /* try to forge on through */
905 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
907 + goto out_with_sacls;
910 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
912 + goto out_with_one_racl;
914 + if (rsync_acls_equal(&racl_orig, &racl_bak))
917 + ; /* presume they're unequal */
919 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
920 + if (-1 == sys_acl_delete_def_file(bak)) {
921 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
922 + bak, strerror(errno));
925 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
926 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
927 + bak, str_acl_type(*type), strerror(errno));
932 + rsync_acl_free(&racl_bak);
934 + rsync_acl_free(&racl_orig);
937 + sys_acl_free_acl(sacl_bak);
938 + /* out_with_one_sacl: */
940 + sys_acl_free_acl(sacl_orig);
945 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
946 + * for keep_backup(). */
947 +static const struct file_struct *backup_orig_file = NULL;
948 +static const char null_string[] = "";
949 +static const char *backup_orig_fname = null_string;
950 +static const char *backup_dest_fname = null_string;
951 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
953 +void push_keep_backup_acl(const struct file_struct *file,
954 + const char *orig, const char *dest)
956 + if (preserve_acls) {
957 + SMB_ACL_TYPE_T *type,
958 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
960 + backup_orig_file = file;
961 + backup_orig_fname = orig;
962 + backup_dest_fname = dest;
963 + for (type = &types[0], sacl = &_backup_sacl[0];
964 + type < &types[0] + sizeof types / sizeof types[0];
966 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
969 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
970 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
971 + orig, str_acl_type(*type),
979 +static int set_keep_backup_acl()
981 + if (preserve_acls) {
982 + SMB_ACL_TYPE_T *type,
983 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
986 + for (type = &types[0], sacl = &_backup_sacl[0];
987 + type < &types[0] + sizeof types / sizeof types[0];
990 + if (-1 == sys_acl_set_file(backup_dest_fname,
993 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
995 + str_acl_type(*type),
1006 +void cleanup_keep_backup_acl()
1008 + if (preserve_acls) {
1009 + SMB_ACL_TYPE_T *type,
1010 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1012 + backup_orig_file = NULL;
1013 + backup_orig_fname = null_string;
1014 + backup_dest_fname = null_string;
1015 + for (type = &types[0], sacl = &_backup_sacl[0];
1016 + type < &types[0] + sizeof types / sizeof types[0];
1019 + sys_acl_free_acl(*sacl);
1025 +/* set ACL on rsync-ed or keep_backup-ed file */
1027 +int set_acl(const char *fname, const struct file_struct *file)
1030 + SMB_ACL_TYPE_T *type,
1031 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1032 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1034 + if (file == backup_orig_file) {
1035 + if (!strcmp(fname, backup_dest_fname))
1036 + return set_keep_backup_acl();
1038 + for (type = &types[0];
1039 + type < &types[0] + sizeof types / sizeof types[0]
1040 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1042 + SMB_ACL_T sacl_orig, *sacl_new;
1043 + rsync_acl racl_orig, *racl_new;
1044 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1047 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1048 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1049 + sacl_orig = sys_acl_get_file(fname, *type);
1051 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1052 + fname, str_acl_type(*type), strerror(errno));
1056 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1057 + sys_acl_free_acl(sacl_orig);
1062 + ok = rsync_acls_equal(&racl_orig, racl_new);
1063 + rsync_acl_free(&racl_orig);
1066 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1067 + if (-1 == sys_acl_delete_def_file(fname)) {
1068 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1069 + fname, strerror(errno));
1075 + if (!pack_smb_acl(sacl_new, racl_new)) {
1079 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1080 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1081 + fname, str_acl_type(*type),
1093 +/* Enumeration functions for uid mapping: */
1095 +/* Context -- one and only one. Should be cycled through once on uid
1096 + * mapping and once on gid mapping. */
1097 +static rsync_acl_list *_enum_racl_lists[] = {
1098 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1101 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1102 +static size_t enum_racl_index = 0;
1103 +static size_t enum_race_index = 0;
1105 +/* This returns the next tag_type id from the given acl for the next entry,
1106 + * or it returns 0 if there are no more tag_type ids in the acl. */
1108 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1110 + for (; enum_race_index < racl->count; enum_race_index++) {
1111 + rsync_ace *race = &racl->races[enum_race_index];
1112 + if (race->tag_type == tag_type)
1115 + enum_race_index = 0;
1119 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1121 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1122 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1123 + id_t id = next_ace_id(tag_type, racl);
1127 + enum_racl_index = 0;
1131 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1133 + for (; *enum_racl_list; enum_racl_list++) {
1134 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1138 + enum_racl_list = &_enum_racl_lists[0];
1142 +id_t next_acl_uid()
1144 + return next_acl_list_id(SMB_ACL_USER);
1147 +id_t next_acl_gid()
1149 + return next_acl_list_id(SMB_ACL_GROUP);
1152 +/* referring to the global context enum_entry, sets the entry's id */
1153 +static void set_acl_id(id_t id)
1155 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1158 +void acl_uid_map(id_t uid)
1163 +void acl_gid_map(id_t gid)
1168 +#define PERMS_SPLICE(perms,newbits,where) (((perms) & ~(7 << (where))) | ((newbits) << (where)))
1170 +int default_perms_for_dir(const char *dir)
1174 + BOOL ok, saw_mask = False;
1180 + perms = ACCESSPERMS & ~orig_umask;
1181 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1182 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1183 + if (sacl == NULL) {
1184 + /* Couldn't get an ACL. Darn. */
1187 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1191 + /* We're doing a dry run, so the containing directory
1192 + * wasn't actually created. Don't worry about it. */
1195 + /* Otherwise fall through. */
1197 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1198 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1204 + ok = unpack_smb_acl(&racl, sacl);
1205 + sys_acl_free_acl(sacl);
1207 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1211 + /* Look at each default ACL entry and possibly modify three bits of `perms' accordingly.
1212 + * If there's "no" default ACL, there will be zero entries and the umask-based perms is unchanged. */
1213 + for (i = 0; i < racl.count; i++) {
1214 + switch (racl.races[i].tag_type) {
1215 + case SMB_ACL_USER_OBJ:
1216 + perms = PERMS_SPLICE(perms, racl.races[i].access, 6);
1218 + case SMB_ACL_GROUP_OBJ:
1220 + perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
1222 + case SMB_ACL_MASK:
1224 + perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
1226 + case SMB_ACL_OTHER:
1227 + perms = PERMS_SPLICE(perms, racl.races[i].access, 0);
1233 + rsync_acl_free(&racl);
1235 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1239 +#endif /* SUPPORT_ACLS */
1240 --- orig/backup.c 2006-01-30 07:18:27
1241 +++ backup.c 2004-10-06 00:13:09
1242 @@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
1244 do_lchown(fullpath, st.st_uid, st.st_gid);
1245 do_chmod(fullpath, st.st_mode);
1246 + (void)DUP_ACL(end, fullpath, st.st_mode);
1250 @@ -188,6 +189,8 @@ static int keep_backup(char *fname)
1251 if (!(buf = get_backup_name(fname)))
1254 + PUSH_KEEP_BACKUP_ACL(file, fname, buf);
1256 /* Check to see if this is a device file, or link */
1257 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1258 || (preserve_specials && IS_SPECIAL(file->mode))) {
1259 @@ -263,6 +266,7 @@ static int keep_backup(char *fname)
1262 set_file_attrs(buf, file, NULL, 0);
1263 + CLEANUP_KEEP_BACKUP_ACL();
1267 --- orig/configure.in 2006-02-02 02:41:09
1268 +++ configure.in 2004-08-19 19:53:27
1269 @@ -478,6 +478,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1270 AC_CHECK_LIB(resolv, strcasecmp)
1273 +AC_CHECK_FUNCS(aclsort)
1274 +if test x"$ac_cv_func_aclsort" = x"no"; then
1275 + AC_CHECK_LIB(sec, aclsort)
1278 dnl At the moment we don't test for a broken memcmp(), because all we
1279 dnl need to do is test for equality, not comparison, and it seems that
1280 dnl every platform has a memcmp that can do at least that.
1281 @@ -751,6 +756,77 @@ AC_SUBST(OBJ_RESTORE)
1282 AC_SUBST(CC_SHOBJ_FLAG)
1283 AC_SUBST(BUILD_POPT)
1285 +AC_CHECK_HEADERS(sys/acl.h)
1286 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1287 +#################################################
1288 +# check for ACL support
1290 +AC_MSG_CHECKING(whether to support ACLs)
1291 +AC_ARG_ENABLE(acl-support,
1292 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1293 +[ case "$enableval" in
1296 + case "$host_os" in
1298 + AC_MSG_RESULT(Using UnixWare ACLs)
1299 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1302 + AC_MSG_RESULT(Using solaris ACLs)
1303 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1306 + AC_MSG_RESULT(Using HPUX ACLs)
1307 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1310 + AC_MSG_RESULT(Using IRIX ACLs)
1311 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1314 + AC_MSG_RESULT(Using AIX ACLs)
1315 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1318 + AC_MSG_RESULT(Using Tru64 ACLs)
1319 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1320 + LIBS="$LIBS -lpacl"
1323 + AC_MSG_RESULT(ACLs requested -- running tests)
1324 + AC_CHECK_LIB(acl,acl_get_file)
1325 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1326 + AC_TRY_LINK([#include <sys/types.h>
1327 +#include <sys/acl.h>],
1328 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1329 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1330 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1331 + AC_MSG_RESULT(Using posix ACLs)
1332 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1333 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1334 + AC_TRY_LINK([#include <sys/types.h>
1335 +#include <sys/acl.h>],
1336 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1337 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1338 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1339 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1342 + AC_MSG_ERROR(Failed to find ACL support)
1349 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1352 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1356 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1359 --- orig/flist.c 2006-01-31 02:30:18
1360 +++ flist.c 2006-01-31 02:37:33
1361 @@ -967,6 +967,8 @@ static struct file_struct *send_file_nam
1362 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1365 + if (MAKE_ACL(file, fname) < 0)
1368 if (chmod_modes && !S_ISLNK(file->mode))
1369 file->mode = tweak_mode(file->mode, chmod_modes);
1370 @@ -978,6 +980,10 @@ static struct file_struct *send_file_nam
1371 if (file->basename[0]) {
1372 flist->files[flist->count++] = file;
1373 send_file_entry(file, f);
1374 + SEND_ACL(file, f);
1376 + /* Cleanup unsent ACL(s). */
1377 + SEND_ACL(file, -1);
1381 @@ -1366,6 +1372,8 @@ struct file_list *recv_file_list(int f)
1382 flags |= read_byte(f) << 8;
1383 file = receive_file_entry(flist, flags, f);
1385 + RECEIVE_ACL(file, f);
1387 if (S_ISREG(file->mode))
1388 stats.total_size += file->length;
1390 @@ -1388,6 +1396,8 @@ struct file_list *recv_file_list(int f)
1392 clean_flist(flist, relative_paths, 1);
1394 + SORT_FILE_ACL_INDEX_LISTS();
1397 recv_uid_list(f, flist);
1399 --- orig/generator.c 2006-01-31 18:59:39
1400 +++ generator.c 2006-02-03 05:44:04
1401 @@ -756,6 +756,7 @@ static int try_dests_non(struct file_str
1404 static int phase = 0;
1405 +static int dflt_perms;
1407 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1408 * make sure it exists, and has the right permissions/timestamp info. For
1409 @@ -772,7 +773,7 @@ static void recv_generator(char *fname,
1410 enum logcode code, int f_out)
1412 static int missing_below = -1, excluded_below = -1;
1413 - static char *fuzzy_dirname = "";
1414 + static char *parent_dirname = "";
1415 static struct file_list *fuzzy_dirlist = NULL;
1416 struct file_struct *fuzzy_file = NULL;
1417 int fd = -1, f_copy = -1;
1418 @@ -791,12 +792,12 @@ static void recv_generator(char *fname,
1419 if (fuzzy_dirlist) {
1420 flist_free(fuzzy_dirlist);
1421 fuzzy_dirlist = NULL;
1422 - fuzzy_dirname = "";
1424 if (missing_below >= 0) {
1428 + parent_dirname = "";
1432 @@ -831,15 +832,20 @@ static void recv_generator(char *fname,
1434 stat_errno = ENOENT;
1436 - if (fuzzy_basis && S_ISREG(file->mode)) {
1437 + if ((fuzzy_basis || !preserve_perms) && S_ISREG(file->mode)) {
1438 char *dn = file->dirname ? file->dirname : ".";
1439 - if (fuzzy_dirname != dn
1440 - && strcmp(fuzzy_dirname, dn) != 0) {
1441 + if (parent_dirname != dn
1442 + && strcmp(parent_dirname, dn) != 0) {
1444 flist_free(fuzzy_dirlist);
1445 - fuzzy_dirlist = get_dirlist(dn, -1, 1);
1447 + fuzzy_dirlist = get_dirlist(dn, -1, 1);
1448 +#ifdef SUPPORT_ACLS
1449 + if (!preserve_perms)
1450 + dflt_perms = default_perms_for_dir(dn);
1453 - fuzzy_dirname = dn;
1454 + parent_dirname = dn;
1457 statret = link_stat(fname, &st,
1458 @@ -861,7 +867,8 @@ static void recv_generator(char *fname,
1459 if (!preserve_perms) {
1460 int exists = statret == 0
1461 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1462 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1463 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1467 if (S_ISDIR(file->mode)) {
1468 @@ -895,6 +902,10 @@ static void recv_generator(char *fname,
1469 if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1470 && verbose && code && f_out != -1)
1471 rprintf(code, "%s/\n", fname);
1472 +#ifdef SUPPORT_ACLS
1474 + SET_ACL(fname, file);
1476 if (delete_during && f_out != -1 && !phase && dry_run < 2
1477 && (file->flags & FLAG_DEL_HERE))
1478 delete_in_dir(the_file_list, fname, file, &st);
1479 @@ -1330,6 +1341,8 @@ void generate_files(int f_out, struct fi
1480 * notice that and let us know via the redo pipe (or its closing). */
1483 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1485 for (i = 0; i < flist->count; i++) {
1486 struct file_struct *file = flist->files[i];
1488 --- orig/lib/sysacls.c 2005-05-16 23:27:53
1489 +++ lib/sysacls.c 2005-05-16 23:27:53
1492 + Unix SMB/CIFS implementation.
1493 + Samba system utilities for ACL support.
1494 + Copyright (C) Jeremy Allison 2000.
1496 + This program is free software; you can redistribute it and/or modify
1497 + it under the terms of the GNU General Public License as published by
1498 + the Free Software Foundation; either version 2 of the License, or
1499 + (at your option) any later version.
1501 + This program is distributed in the hope that it will be useful,
1502 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1503 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1504 + GNU General Public License for more details.
1506 + You should have received a copy of the GNU General Public License
1507 + along with this program; if not, write to the Free Software
1508 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1512 +#include "sysacls.h" /****** ADDED ******/
1514 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1515 +void SAFE_FREE(void *mem)
1521 +char *uidtoname(uid_t uid)
1523 + static char idbuf[12];
1524 + struct passwd *pw;
1526 + if ((pw = getpwuid(uid)) == NULL) {
1527 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1530 + return pw->pw_name;
1532 +/****** EXTRAS -- END ******/
1535 + This file wraps all differing system ACL interfaces into a consistent
1536 + one based on the POSIX interface. It also returns the correct errors
1537 + for older UNIX systems that don't support ACLs.
1539 + The interfaces that each ACL implementation must support are as follows :
1541 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1542 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1543 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1544 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1545 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1546 + SMB_ACL_T sys_acl_get_fd(int fd)
1547 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1548 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1549 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1550 + SMB_ACL_T sys_acl_init( int count)
1551 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1552 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1553 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1554 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1555 + int sys_acl_valid( SMB_ACL_T theacl )
1556 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1557 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1558 + int sys_acl_delete_def_file(const char *path)
1560 + This next one is not POSIX complient - but we *have* to have it !
1561 + More POSIX braindamage.
1563 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1565 + The generic POSIX free is the following call. We split this into
1566 + several different free functions as we may need to add tag info
1567 + to structures when emulating the POSIX interface.
1569 + int sys_acl_free( void *obj_p)
1571 + The calls we actually use are :
1573 + int sys_acl_free_text(char *text) - free acl_to_text
1574 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1575 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1579 +#if defined(HAVE_POSIX_ACLS)
1581 +/* Identity mapping - easy. */
1583 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1585 + return acl_get_entry( the_acl, entry_id, entry_p);
1588 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1590 + return acl_get_tag_type( entry_d, tag_type_p);
1593 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1595 + return acl_get_permset( entry_d, permset_p);
1598 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1600 + return acl_get_qualifier( entry_d);
1603 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1605 + return acl_get_file( path_p, type);
1608 +SMB_ACL_T sys_acl_get_fd(int fd)
1610 + return acl_get_fd(fd);
1613 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1615 + return acl_clear_perms(permset);
1618 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1620 + return acl_add_perm(permset, perm);
1623 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1625 +#if defined(HAVE_ACL_GET_PERM_NP)
1627 + * Required for TrustedBSD-based ACL implementations where
1628 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1631 + return acl_get_perm_np(permset, perm);
1633 + return acl_get_perm(permset, perm);
1637 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1639 + return acl_to_text( the_acl, plen);
1642 +SMB_ACL_T sys_acl_init( int count)
1644 + return acl_init(count);
1647 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1649 + return acl_create_entry(pacl, pentry);
1652 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1654 + return acl_set_tag_type(entry, tagtype);
1657 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1659 + return acl_set_qualifier(entry, qual);
1662 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1664 + return acl_set_permset(entry, permset);
1667 +int sys_acl_valid( SMB_ACL_T theacl )
1669 + return acl_valid(theacl);
1672 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1674 + return acl_set_file(name, acltype, theacl);
1677 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1679 + return acl_set_fd(fd, theacl);
1682 +int sys_acl_delete_def_file(const char *name)
1684 + return acl_delete_def_file(name);
1687 +int sys_acl_free_text(char *text)
1689 + return acl_free(text);
1692 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1694 + return acl_free(the_acl);
1697 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1699 + return acl_free(qual);
1702 +#elif defined(HAVE_TRU64_ACLS)
1704 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1705 + * is based on Draft 13 of the POSIX spec which is
1706 + * slightly different from the Draft 16 interface.
1708 + * Also, some of the permset manipulation functions
1709 + * such as acl_clear_perm() and acl_add_perm() appear
1710 + * to be broken on Tru64 so we have to manipulate
1711 + * the permission bits in the permset directly.
1713 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1715 + SMB_ACL_ENTRY_T entry;
1717 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1722 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1727 + return errno ? -1 : 0;
1730 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1732 + return acl_get_tag_type( entry_d, tag_type_p);
1735 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1737 + return acl_get_permset( entry_d, permset_p);
1740 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1742 + return acl_get_qualifier( entry_d);
1745 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1747 + return acl_get_file((char *)path_p, type);
1750 +SMB_ACL_T sys_acl_get_fd(int fd)
1752 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1755 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1757 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1762 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1764 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1769 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1774 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1776 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1779 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1781 + return acl_to_text( the_acl, plen);
1784 +SMB_ACL_T sys_acl_init( int count)
1786 + return acl_init(count);
1789 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1791 + SMB_ACL_ENTRY_T entry;
1793 + if ((entry = acl_create_entry(pacl)) == NULL) {
1801 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1803 + return acl_set_tag_type(entry, tagtype);
1806 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1808 + return acl_set_qualifier(entry, qual);
1811 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1813 + return acl_set_permset(entry, permset);
1816 +int sys_acl_valid( SMB_ACL_T theacl )
1818 + acl_entry_t entry;
1820 + return acl_valid(theacl, &entry);
1823 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1825 + return acl_set_file((char *)name, acltype, theacl);
1828 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1830 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1833 +int sys_acl_delete_def_file(const char *name)
1835 + return acl_delete_def_file((char *)name);
1838 +int sys_acl_free_text(char *text)
1841 + * (void) cast and explicit return 0 are for DEC UNIX
1842 + * which just #defines acl_free_text() to be free()
1844 + (void) acl_free_text(text);
1848 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1850 + return acl_free(the_acl);
1853 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1855 + return acl_free_qualifier(qual, tagtype);
1858 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1861 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1862 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1866 + * Note that while this code implements sufficient functionality
1867 + * to support the sys_acl_* interfaces it does not provide all
1868 + * of the semantics of the POSIX ACL interfaces.
1870 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1871 + * from a call to sys_acl_get_entry() should not be assumed to be
1872 + * valid after calling any of the following functions, which may
1873 + * reorder the entries in the ACL.
1876 + * sys_acl_set_file()
1877 + * sys_acl_set_fd()
1881 + * The only difference between Solaris and UnixWare / OpenUNIX is
1882 + * that the #defines for the ACL operations have different names
1884 +#if defined(HAVE_UNIXWARE_ACLS)
1886 +#define SETACL ACL_SET
1887 +#define GETACL ACL_GET
1888 +#define GETACLCNT ACL_CNT
1893 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1895 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1900 + if (entry_p == NULL) {
1905 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1909 + if (acl_d->next < 0) {
1914 + if (acl_d->next >= acl_d->count) {
1918 + *entry_p = &acl_d->acl[acl_d->next++];
1923 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1925 + *type_p = entry_d->a_type;
1930 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1932 + *permset_p = &entry_d->a_perm;
1937 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1939 + if (entry_d->a_type != SMB_ACL_USER
1940 + && entry_d->a_type != SMB_ACL_GROUP) {
1945 + return &entry_d->a_id;
1949 + * There is no way of knowing what size the ACL returned by
1950 + * GETACL will be unless you first call GETACLCNT which means
1951 + * making an additional system call.
1953 + * In the hope of avoiding the cost of the additional system
1954 + * call in most cases, we initially allocate enough space for
1955 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1956 + * be too small then we use GETACLCNT to find out the actual
1957 + * size, reallocate the ACL buffer, and then call GETACL again.
1960 +#define INITIAL_ACL_SIZE 16
1962 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1965 + int count; /* # of ACL entries allocated */
1966 + int naccess; /* # of access ACL entries */
1967 + int ndefault; /* # of default ACL entries */
1969 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1974 + count = INITIAL_ACL_SIZE;
1975 + if ((acl_d = sys_acl_init(count)) == NULL) {
1980 + * If there isn't enough space for the ACL entries we use
1981 + * GETACLCNT to determine the actual number of ACL entries
1982 + * reallocate and try again. This is in a loop because it
1983 + * is possible that someone else could modify the ACL and
1984 + * increase the number of entries between the call to
1985 + * GETACLCNT and the call to GETACL.
1987 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1988 + && errno == ENOSPC) {
1990 + sys_acl_free_acl(acl_d);
1992 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1996 + if ((acl_d = sys_acl_init(count)) == NULL) {
2002 + sys_acl_free_acl(acl_d);
2007 + * calculate the number of access and default ACL entries
2009 + * Note: we assume that the acl() system call returned a
2010 + * well formed ACL which is sorted so that all of the
2011 + * access ACL entries preceed any default ACL entries
2013 + for (naccess = 0; naccess < count; naccess++) {
2014 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2017 + ndefault = count - naccess;
2020 + * if the caller wants the default ACL we have to copy
2021 + * the entries down to the start of the acl[] buffer
2022 + * and mask out the ACL_DEFAULT flag from the type field
2024 + if (type == SMB_ACL_TYPE_DEFAULT) {
2027 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2028 + acl_d->acl[i] = acl_d->acl[j];
2029 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2032 + acl_d->count = ndefault;
2034 + acl_d->count = naccess;
2040 +SMB_ACL_T sys_acl_get_fd(int fd)
2043 + int count; /* # of ACL entries allocated */
2044 + int naccess; /* # of access ACL entries */
2046 + count = INITIAL_ACL_SIZE;
2047 + if ((acl_d = sys_acl_init(count)) == NULL) {
2051 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2052 + && errno == ENOSPC) {
2054 + sys_acl_free_acl(acl_d);
2056 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2060 + if ((acl_d = sys_acl_init(count)) == NULL) {
2066 + sys_acl_free_acl(acl_d);
2071 + * calculate the number of access ACL entries
2073 + for (naccess = 0; naccess < count; naccess++) {
2074 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2078 + acl_d->count = naccess;
2083 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2090 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2092 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2093 + && perm != SMB_ACL_EXECUTE) {
2098 + if (permset_d == NULL) {
2103 + *permset_d |= perm;
2108 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2110 + return *permset_d & perm;
2113 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2120 + * use an initial estimate of 20 bytes per ACL entry
2121 + * when allocating memory for the text representation
2125 + maxlen = 20 * acl_d->count;
2126 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2131 + for (i = 0; i < acl_d->count; i++) {
2132 + struct acl *ap = &acl_d->acl[i];
2133 + struct passwd *pw;
2142 + switch (ap->a_type) {
2144 + * for debugging purposes it's probably more
2145 + * useful to dump unknown tag types rather
2146 + * than just returning an error
2149 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2152 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2157 + case SMB_ACL_USER:
2158 + id = uidtoname(ap->a_id);
2159 + case SMB_ACL_USER_OBJ:
2163 + case SMB_ACL_GROUP:
2164 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2165 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2171 + case SMB_ACL_GROUP_OBJ:
2175 + case SMB_ACL_OTHER:
2179 + case SMB_ACL_MASK:
2185 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2186 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2187 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2190 + /* <tag> : <qualifier> : rwx \n \0 */
2191 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2194 + * If this entry would overflow the buffer
2195 + * allocate enough additional memory for this
2196 + * entry and an estimate of another 20 bytes
2197 + * for each entry still to be processed
2199 + if ((len + nbytes) > maxlen) {
2200 + char *oldtext = text;
2202 + maxlen += nbytes + 20 * (acl_d->count - i);
2204 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2205 + SAFE_FREE(oldtext);
2211 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2212 + len += nbytes - 1;
2221 +SMB_ACL_T sys_acl_init(int count)
2231 + * note that since the definition of the structure pointed
2232 + * to by the SMB_ACL_T includes the first element of the
2233 + * acl[] array, this actually allocates an ACL with room
2234 + * for (count+1) entries
2236 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2241 + a->size = count + 1;
2249 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2252 + SMB_ACL_ENTRY_T entry_d;
2254 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2259 + if (acl_d->count >= acl_d->size) {
2264 + entry_d = &acl_d->acl[acl_d->count++];
2265 + entry_d->a_type = 0;
2266 + entry_d->a_id = -1;
2267 + entry_d->a_perm = 0;
2268 + *entry_p = entry_d;
2273 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2275 + switch (tag_type) {
2276 + case SMB_ACL_USER:
2277 + case SMB_ACL_USER_OBJ:
2278 + case SMB_ACL_GROUP:
2279 + case SMB_ACL_GROUP_OBJ:
2280 + case SMB_ACL_OTHER:
2281 + case SMB_ACL_MASK:
2282 + entry_d->a_type = tag_type;
2292 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2294 + if (entry_d->a_type != SMB_ACL_GROUP
2295 + && entry_d->a_type != SMB_ACL_USER) {
2300 + entry_d->a_id = *((id_t *)qual_p);
2305 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2307 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2311 + entry_d->a_perm = *permset_d;
2317 + * sort the ACL and check it for validity
2319 + * if it's a minimal ACL with only 4 entries then we
2320 + * need to recalculate the mask permissions to make
2321 + * sure that they are the same as the GROUP_OBJ
2322 + * permissions as required by the UnixWare acl() system call.
2324 + * (note: since POSIX allows minimal ACLs which only contain
2325 + * 3 entries - ie there is no mask entry - we should, in theory,
2326 + * check for this and add a mask entry if necessary - however
2327 + * we "know" that the caller of this interface always specifies
2328 + * a mask so, in practice "this never happens" (tm) - if it *does*
2329 + * happen aclsort() will fail and return an error and someone will
2330 + * have to fix it ...)
2333 +static int acl_sort(SMB_ACL_T acl_d)
2335 + int fixmask = (acl_d->count <= 4);
2337 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2344 +int sys_acl_valid(SMB_ACL_T acl_d)
2346 + return acl_sort(acl_d);
2349 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2352 + struct acl *acl_p;
2354 + struct acl *acl_buf = NULL;
2357 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2362 + if (acl_sort(acl_d) != 0) {
2366 + acl_p = &acl_d->acl[0];
2367 + acl_count = acl_d->count;
2370 + * if it's a directory there is extra work to do
2371 + * since the acl() system call will replace both
2372 + * the access ACLs and the default ACLs (if any)
2374 + if (stat(name, &s) != 0) {
2377 + if (S_ISDIR(s.st_mode)) {
2378 + SMB_ACL_T acc_acl;
2379 + SMB_ACL_T def_acl;
2380 + SMB_ACL_T tmp_acl;
2383 + if (type == SMB_ACL_TYPE_ACCESS) {
2385 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2389 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2392 + if (tmp_acl == NULL) {
2397 + * allocate a temporary buffer for the complete ACL
2399 + acl_count = acc_acl->count + def_acl->count;
2400 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2402 + if (acl_buf == NULL) {
2403 + sys_acl_free_acl(tmp_acl);
2409 + * copy the access control and default entries into the buffer
2411 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2412 + acc_acl->count * sizeof(acl_buf[0]));
2414 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2415 + def_acl->count * sizeof(acl_buf[0]));
2418 + * set the ACL_DEFAULT flag on the default entries
2420 + for (i = acc_acl->count; i < acl_count; i++) {
2421 + acl_buf[i].a_type |= ACL_DEFAULT;
2424 + sys_acl_free_acl(tmp_acl);
2426 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2431 + ret = acl(name, SETACL, acl_count, acl_p);
2433 + SAFE_FREE(acl_buf);
2438 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2440 + if (acl_sort(acl_d) != 0) {
2444 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2447 +int sys_acl_delete_def_file(const char *path)
2453 + * fetching the access ACL and rewriting it has
2454 + * the effect of deleting the default ACL
2456 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2460 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2462 + sys_acl_free_acl(acl_d);
2467 +int sys_acl_free_text(char *text)
2473 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2479 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2484 +#elif defined(HAVE_HPUX_ACLS)
2488 + * Based on the Solaris/SCO code - with modifications.
2492 + * Note that while this code implements sufficient functionality
2493 + * to support the sys_acl_* interfaces it does not provide all
2494 + * of the semantics of the POSIX ACL interfaces.
2496 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2497 + * from a call to sys_acl_get_entry() should not be assumed to be
2498 + * valid after calling any of the following functions, which may
2499 + * reorder the entries in the ACL.
2502 + * sys_acl_set_file()
2503 + * sys_acl_set_fd()
2506 +/* This checks if the POSIX ACL system call is defined */
2507 +/* which basically corresponds to whether JFS 3.3 or */
2508 +/* higher is installed. If acl() was called when it */
2509 +/* isn't defined, it causes the process to core dump */
2510 +/* so it is important to check this and avoid acl() */
2511 +/* calls if it isn't there. */
2513 +static BOOL hpux_acl_call_presence(void)
2516 + shl_t handle = NULL;
2519 + static BOOL already_checked=0;
2521 + if(already_checked)
2525 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2527 + if(ret_val != 0) {
2528 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2529 + ret_val, errno, strerror(errno)));
2530 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2534 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2536 + already_checked = True;
2540 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2542 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2547 + if (entry_p == NULL) {
2552 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2556 + if (acl_d->next < 0) {
2561 + if (acl_d->next >= acl_d->count) {
2565 + *entry_p = &acl_d->acl[acl_d->next++];
2570 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2572 + *type_p = entry_d->a_type;
2577 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2579 + *permset_p = &entry_d->a_perm;
2584 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2586 + if (entry_d->a_type != SMB_ACL_USER
2587 + && entry_d->a_type != SMB_ACL_GROUP) {
2592 + return &entry_d->a_id;
2596 + * There is no way of knowing what size the ACL returned by
2597 + * ACL_GET will be unless you first call ACL_CNT which means
2598 + * making an additional system call.
2600 + * In the hope of avoiding the cost of the additional system
2601 + * call in most cases, we initially allocate enough space for
2602 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2603 + * be too small then we use ACL_CNT to find out the actual
2604 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2607 +#define INITIAL_ACL_SIZE 16
2609 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2612 + int count; /* # of ACL entries allocated */
2613 + int naccess; /* # of access ACL entries */
2614 + int ndefault; /* # of default ACL entries */
2616 + if(hpux_acl_call_presence() == False) {
2617 + /* Looks like we don't have the acl() system call on HPUX.
2618 + * May be the system doesn't have the latest version of JFS.
2623 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2628 + count = INITIAL_ACL_SIZE;
2629 + if ((acl_d = sys_acl_init(count)) == NULL) {
2634 + * If there isn't enough space for the ACL entries we use
2635 + * ACL_CNT to determine the actual number of ACL entries
2636 + * reallocate and try again. This is in a loop because it
2637 + * is possible that someone else could modify the ACL and
2638 + * increase the number of entries between the call to
2639 + * ACL_CNT and the call to ACL_GET.
2641 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2643 + sys_acl_free_acl(acl_d);
2645 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2649 + if ((acl_d = sys_acl_init(count)) == NULL) {
2655 + sys_acl_free_acl(acl_d);
2660 + * calculate the number of access and default ACL entries
2662 + * Note: we assume that the acl() system call returned a
2663 + * well formed ACL which is sorted so that all of the
2664 + * access ACL entries preceed any default ACL entries
2666 + for (naccess = 0; naccess < count; naccess++) {
2667 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2670 + ndefault = count - naccess;
2673 + * if the caller wants the default ACL we have to copy
2674 + * the entries down to the start of the acl[] buffer
2675 + * and mask out the ACL_DEFAULT flag from the type field
2677 + if (type == SMB_ACL_TYPE_DEFAULT) {
2680 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2681 + acl_d->acl[i] = acl_d->acl[j];
2682 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2685 + acl_d->count = ndefault;
2687 + acl_d->count = naccess;
2693 +SMB_ACL_T sys_acl_get_fd(int fd)
2696 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2699 + files_struct *fsp = file_find_fd(fd);
2701 + if (fsp == NULL) {
2707 + * We know we're in the same conn context. So we
2708 + * can use the relative path.
2711 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2714 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2721 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2723 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2724 + && perm != SMB_ACL_EXECUTE) {
2729 + if (permset_d == NULL) {
2734 + *permset_d |= perm;
2739 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2741 + return *permset_d & perm;
2744 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2751 + * use an initial estimate of 20 bytes per ACL entry
2752 + * when allocating memory for the text representation
2756 + maxlen = 20 * acl_d->count;
2757 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2762 + for (i = 0; i < acl_d->count; i++) {
2763 + struct acl *ap = &acl_d->acl[i];
2764 + struct passwd *pw;
2773 + switch (ap->a_type) {
2775 + * for debugging purposes it's probably more
2776 + * useful to dump unknown tag types rather
2777 + * than just returning an error
2780 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2783 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2788 + case SMB_ACL_USER:
2789 + id = uidtoname(ap->a_id);
2790 + case SMB_ACL_USER_OBJ:
2794 + case SMB_ACL_GROUP:
2795 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2796 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2802 + case SMB_ACL_GROUP_OBJ:
2806 + case SMB_ACL_OTHER:
2810 + case SMB_ACL_MASK:
2816 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2817 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2818 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2821 + /* <tag> : <qualifier> : rwx \n \0 */
2822 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2825 + * If this entry would overflow the buffer
2826 + * allocate enough additional memory for this
2827 + * entry and an estimate of another 20 bytes
2828 + * for each entry still to be processed
2830 + if ((len + nbytes) > maxlen) {
2831 + char *oldtext = text;
2833 + maxlen += nbytes + 20 * (acl_d->count - i);
2835 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2842 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2843 + len += nbytes - 1;
2852 +SMB_ACL_T sys_acl_init(int count)
2862 + * note that since the definition of the structure pointed
2863 + * to by the SMB_ACL_T includes the first element of the
2864 + * acl[] array, this actually allocates an ACL with room
2865 + * for (count+1) entries
2867 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2872 + a->size = count + 1;
2880 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2883 + SMB_ACL_ENTRY_T entry_d;
2885 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2890 + if (acl_d->count >= acl_d->size) {
2895 + entry_d = &acl_d->acl[acl_d->count++];
2896 + entry_d->a_type = 0;
2897 + entry_d->a_id = -1;
2898 + entry_d->a_perm = 0;
2899 + *entry_p = entry_d;
2904 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2906 + switch (tag_type) {
2907 + case SMB_ACL_USER:
2908 + case SMB_ACL_USER_OBJ:
2909 + case SMB_ACL_GROUP:
2910 + case SMB_ACL_GROUP_OBJ:
2911 + case SMB_ACL_OTHER:
2912 + case SMB_ACL_MASK:
2913 + entry_d->a_type = tag_type;
2923 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2925 + if (entry_d->a_type != SMB_ACL_GROUP
2926 + && entry_d->a_type != SMB_ACL_USER) {
2931 + entry_d->a_id = *((id_t *)qual_p);
2936 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2938 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2942 + entry_d->a_perm = *permset_d;
2947 +/* Structure to capture the count for each type of ACE. */
2949 +struct hpux_acl_types {
2953 + int n_def_user_obj;
2958 + int n_def_group_obj;
2962 + int n_def_other_obj;
2965 + int n_def_class_obj;
2967 + int n_illegal_obj;
2971 + * Counts the different number of objects in a given array of ACL
2975 + * acl_count - Count of ACLs in the array of ACL strucutres.
2976 + * aclp - Array of ACL structures.
2977 + * acl_type_count - Pointer to acl_types structure. Should already be
2981 + * acl_type_count - This structure is filled up with counts of various
2985 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2989 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2991 + for(i=0;i<acl_count;i++) {
2992 + switch(aclp[i].a_type) {
2994 + acl_type_count->n_user++;
2997 + acl_type_count->n_user_obj++;
2999 + case DEF_USER_OBJ:
3000 + acl_type_count->n_def_user_obj++;
3003 + acl_type_count->n_group++;
3006 + acl_type_count->n_group_obj++;
3008 + case DEF_GROUP_OBJ:
3009 + acl_type_count->n_def_group_obj++;
3012 + acl_type_count->n_other_obj++;
3014 + case DEF_OTHER_OBJ:
3015 + acl_type_count->n_def_other_obj++;
3018 + acl_type_count->n_class_obj++;
3020 + case DEF_CLASS_OBJ:
3021 + acl_type_count->n_def_class_obj++;
3024 + acl_type_count->n_def_user++;
3027 + acl_type_count->n_def_group++;
3030 + acl_type_count->n_illegal_obj++;
3036 +/* swap_acl_entries: Swaps two ACL entries.
3038 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3041 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3043 + struct acl temp_acl;
3045 + temp_acl.a_type = aclp0->a_type;
3046 + temp_acl.a_id = aclp0->a_id;
3047 + temp_acl.a_perm = aclp0->a_perm;
3049 + aclp0->a_type = aclp1->a_type;
3050 + aclp0->a_id = aclp1->a_id;
3051 + aclp0->a_perm = aclp1->a_perm;
3053 + aclp1->a_type = temp_acl.a_type;
3054 + aclp1->a_id = temp_acl.a_id;
3055 + aclp1->a_perm = temp_acl.a_perm;
3058 +/* prohibited_duplicate_type
3059 + * Identifies if given ACL type can have duplicate entries or
3062 + * Inputs: acl_type - ACL Type.
3068 + * True - If the ACL type matches any of the prohibited types.
3069 + * False - If the ACL type doesn't match any of the prohibited types.
3072 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3074 + switch(acl_type) {
3085 +/* get_needed_class_perm
3086 + * Returns the permissions of a ACL structure only if the ACL
3087 + * type matches one of the pre-determined types for computing
3088 + * CLASS_OBJ permissions.
3090 + * Inputs: aclp - Pointer to ACL structure.
3093 +static int hpux_get_needed_class_perm(struct acl *aclp)
3095 + switch(aclp->a_type) {
3099 + case DEF_USER_OBJ:
3101 + case DEF_GROUP_OBJ:
3103 + case DEF_CLASS_OBJ:
3104 + case DEF_OTHER_OBJ:
3105 + return aclp->a_perm;
3111 +/* acl_sort for HPUX.
3112 + * Sorts the array of ACL structures as per the description in
3113 + * aclsort man page. Refer to aclsort man page for more details
3117 + * acl_count - Count of ACLs in the array of ACL structures.
3118 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3120 + * aclp - Array of ACL structures.
3124 + * aclp - Sorted array of ACL structures.
3128 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3129 + * debug log in case of failure.
3132 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3134 +#if !defined(HAVE_HPUX_ACLSORT)
3136 + * The aclsort() system call is availabe on the latest HPUX General
3137 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3138 + * function. Because, we don't want to update to a new
3139 + * HPUX GR bundle just for aclsort() call.
3142 + struct hpux_acl_types acl_obj_count;
3143 + int n_class_obj_perm = 0;
3147 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3151 + if(aclp == NULL) {
3152 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3156 + /* Count different types of ACLs in the ACLs array */
3158 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3160 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3161 + * CLASS_OBJ and OTHER_OBJ
3164 + if( (acl_obj_count.n_user_obj != 1) ||
3165 + (acl_obj_count.n_group_obj != 1) ||
3166 + (acl_obj_count.n_class_obj != 1) ||
3167 + (acl_obj_count.n_other_obj != 1)
3169 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3170 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3174 + /* If any of the default objects are present, there should be only
3175 + * one of them each.
3178 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3179 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3180 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3181 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3185 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3188 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3189 + * same ACL type, sort by ACL id.
3191 + * I am using the trival kind of sorting method here because, performance isn't
3192 + * really effected by the ACLs feature. More over there aren't going to be more
3193 + * than 17 entries on HPUX.
3196 + for(i=0; i<acl_count;i++) {
3197 + for (j=i+1; j<acl_count; j++) {
3198 + if( aclp[i].a_type > aclp[j].a_type ) {
3199 + /* ACL entries out of order, swap them */
3201 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3203 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3205 + /* ACL entries of same type, sort by id */
3207 + if(aclp[i].a_id > aclp[j].a_id) {
3208 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3209 + } else if (aclp[i].a_id == aclp[j].a_id) {
3210 + /* We have a duplicate entry. */
3211 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3212 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3213 + aclp[i].a_type, aclp[i].a_id));
3222 + /* set the class obj permissions to the computed one. */
3224 + int n_class_obj_index = -1;
3226 + for(i=0;i<acl_count;i++) {
3227 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3229 + if(aclp[i].a_type == CLASS_OBJ)
3230 + n_class_obj_index = i;
3232 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3237 + return aclsort(acl_count, calclass, aclp);
3242 + * sort the ACL and check it for validity
3244 + * if it's a minimal ACL with only 4 entries then we
3245 + * need to recalculate the mask permissions to make
3246 + * sure that they are the same as the GROUP_OBJ
3247 + * permissions as required by the UnixWare acl() system call.
3249 + * (note: since POSIX allows minimal ACLs which only contain
3250 + * 3 entries - ie there is no mask entry - we should, in theory,
3251 + * check for this and add a mask entry if necessary - however
3252 + * we "know" that the caller of this interface always specifies
3253 + * a mask so, in practice "this never happens" (tm) - if it *does*
3254 + * happen aclsort() will fail and return an error and someone will
3255 + * have to fix it ...)
3258 +static int acl_sort(SMB_ACL_T acl_d)
3260 + int fixmask = (acl_d->count <= 4);
3262 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3269 +int sys_acl_valid(SMB_ACL_T acl_d)
3271 + return acl_sort(acl_d);
3274 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3277 + struct acl *acl_p;
3279 + struct acl *acl_buf = NULL;
3282 + if(hpux_acl_call_presence() == False) {
3283 + /* Looks like we don't have the acl() system call on HPUX.
3284 + * May be the system doesn't have the latest version of JFS.
3290 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3295 + if (acl_sort(acl_d) != 0) {
3299 + acl_p = &acl_d->acl[0];
3300 + acl_count = acl_d->count;
3303 + * if it's a directory there is extra work to do
3304 + * since the acl() system call will replace both
3305 + * the access ACLs and the default ACLs (if any)
3307 + if (stat(name, &s) != 0) {
3310 + if (S_ISDIR(s.st_mode)) {
3311 + SMB_ACL_T acc_acl;
3312 + SMB_ACL_T def_acl;
3313 + SMB_ACL_T tmp_acl;
3316 + if (type == SMB_ACL_TYPE_ACCESS) {
3318 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3322 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3325 + if (tmp_acl == NULL) {
3330 + * allocate a temporary buffer for the complete ACL
3332 + acl_count = acc_acl->count + def_acl->count;
3333 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3335 + if (acl_buf == NULL) {
3336 + sys_acl_free_acl(tmp_acl);
3342 + * copy the access control and default entries into the buffer
3344 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3345 + acc_acl->count * sizeof(acl_buf[0]));
3347 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3348 + def_acl->count * sizeof(acl_buf[0]));
3351 + * set the ACL_DEFAULT flag on the default entries
3353 + for (i = acc_acl->count; i < acl_count; i++) {
3354 + acl_buf[i].a_type |= ACL_DEFAULT;
3357 + sys_acl_free_acl(tmp_acl);
3359 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3364 + ret = acl(name, ACL_SET, acl_count, acl_p);
3373 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3376 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3379 + files_struct *fsp = file_find_fd(fd);
3381 + if (fsp == NULL) {
3386 + if (acl_sort(acl_d) != 0) {
3391 + * We know we're in the same conn context. So we
3392 + * can use the relative path.
3395 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3398 +int sys_acl_delete_def_file(const char *path)
3404 + * fetching the access ACL and rewriting it has
3405 + * the effect of deleting the default ACL
3407 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3411 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3413 + sys_acl_free_acl(acl_d);
3418 +int sys_acl_free_text(char *text)
3424 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3430 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3435 +#elif defined(HAVE_IRIX_ACLS)
3437 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3439 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3444 + if (entry_p == NULL) {
3449 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3453 + if (acl_d->next < 0) {
3458 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3462 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3467 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3469 + *type_p = entry_d->ae_tag;
3474 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3476 + *permset_p = entry_d;
3481 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3483 + if (entry_d->ae_tag != SMB_ACL_USER
3484 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3489 + return &entry_d->ae_id;
3492 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3496 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3500 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3505 + a->freeaclp = True;
3509 +SMB_ACL_T sys_acl_get_fd(int fd)
3513 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3517 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3522 + a->freeaclp = True;
3526 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3528 + permset_d->ae_perm = 0;
3533 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3535 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3536 + && perm != SMB_ACL_EXECUTE) {
3541 + if (permset_d == NULL) {
3546 + permset_d->ae_perm |= perm;
3551 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3553 + return permset_d->ae_perm & perm;
3556 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3558 + return acl_to_text(acl_d->aclp, len_p);
3561 +SMB_ACL_T sys_acl_init(int count)
3570 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3576 + a->freeaclp = False;
3577 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3578 + a->aclp->acl_cnt = 0;
3584 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3587 + SMB_ACL_ENTRY_T entry_d;
3589 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3594 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3599 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3600 + entry_d->ae_tag = 0;
3601 + entry_d->ae_id = 0;
3602 + entry_d->ae_perm = 0;
3603 + *entry_p = entry_d;
3608 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3610 + switch (tag_type) {
3611 + case SMB_ACL_USER:
3612 + case SMB_ACL_USER_OBJ:
3613 + case SMB_ACL_GROUP:
3614 + case SMB_ACL_GROUP_OBJ:
3615 + case SMB_ACL_OTHER:
3616 + case SMB_ACL_MASK:
3617 + entry_d->ae_tag = tag_type;
3627 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3629 + if (entry_d->ae_tag != SMB_ACL_GROUP
3630 + && entry_d->ae_tag != SMB_ACL_USER) {
3635 + entry_d->ae_id = *((id_t *)qual_p);
3640 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3642 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3646 + entry_d->ae_perm = permset_d->ae_perm;
3651 +int sys_acl_valid(SMB_ACL_T acl_d)
3653 + return acl_valid(acl_d->aclp);
3656 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3658 + return acl_set_file(name, type, acl_d->aclp);
3661 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3663 + return acl_set_fd(fd, acl_d->aclp);
3666 +int sys_acl_delete_def_file(const char *name)
3668 + return acl_delete_def_file(name);
3671 +int sys_acl_free_text(char *text)
3673 + return acl_free(text);
3676 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3678 + if (acl_d->freeaclp) {
3679 + acl_free(acl_d->aclp);
3685 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3690 +#elif defined(HAVE_AIX_ACLS)
3692 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3694 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3696 + struct acl_entry_link *link;
3697 + struct new_acl_entry *entry;
3700 + DEBUG(10,("This is the count: %d\n",theacl->count));
3702 + /* Check if count was previously set to -1. *
3703 + * If it was, that means we reached the end *
3704 + * of the acl last time. */
3705 + if(theacl->count == -1)
3709 + /* To get to the next acl, traverse linked list until index *
3710 + * of acl matches the count we are keeping. This count is *
3711 + * incremented each time we return an acl entry. */
3713 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3714 + link = link->nextp;
3716 + entry = *entry_p = link->entryp;
3718 + DEBUG(10,("*entry_p is %d\n",entry_p));
3719 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3721 + /* Increment count */
3723 + if(link->nextp == NULL)
3724 + theacl->count = -1;
3729 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3731 + /* Initialize tag type */
3734 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3736 + /* Depending on what type of entry we have, *
3737 + * return tag type. */
3738 + switch(entry_d->ace_id->id_type) {
3740 + *tag_type_p = SMB_ACL_USER;
3743 + *tag_type_p = SMB_ACL_GROUP;
3746 + case SMB_ACL_USER_OBJ:
3747 + case SMB_ACL_GROUP_OBJ:
3748 + case SMB_ACL_OTHER:
3749 + *tag_type_p = entry_d->ace_id->id_type;
3759 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3761 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3762 + *permset_p = &entry_d->ace_access;
3763 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3764 + if(!(**permset_p & S_IXUSR) &&
3765 + !(**permset_p & S_IWUSR) &&
3766 + !(**permset_p & S_IRUSR) &&
3767 + (**permset_p != 0))
3770 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3774 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3776 + return(entry_d->ace_id->id_data);
3779 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3781 + struct acl *file_acl = (struct acl *)NULL;
3782 + struct acl_entry *acl_entry;
3783 + struct new_acl_entry *new_acl_entry;
3784 + struct ace_id *idp;
3785 + struct acl_entry_link *acl_entry_link;
3786 + struct acl_entry_link *acl_entry_link_head;
3791 + /* AIX has no DEFAULT */
3792 + if ( type == SMB_ACL_TYPE_DEFAULT )
3795 + /* Get the acl using statacl */
3797 + DEBUG(10,("Entering sys_acl_get_file\n"));
3798 + DEBUG(10,("path_p is %s\n",path_p));
3800 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3802 + if(file_acl == NULL) {
3804 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3808 + memset(file_acl,0,BUFSIZ);
3810 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3812 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3813 + SAFE_FREE(file_acl);
3817 + DEBUG(10,("Got facl and returned it\n"));
3819 + /* Point to the first acl entry in the acl */
3820 + acl_entry = file_acl->acl_ext;
3822 + /* Begin setting up the head of the linked list *
3823 + * that will be used for the storing the acl *
3824 + * in a way that is useful for the posix_acls.c *
3827 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3828 + if(acl_entry_link_head == NULL)
3831 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3832 + if(acl_entry_link->entryp == NULL) {
3833 + SAFE_FREE(file_acl);
3835 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3839 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3840 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3842 + /* Check if the extended acl bit is on. *
3843 + * If it isn't, do not show the *
3844 + * contents of the acl since AIX intends *
3845 + * the extended info to remain unused */
3847 + if(file_acl->acl_mode & S_IXACL){
3848 + /* while we are not pointing to the very end */
3849 + while(acl_entry < acl_last(file_acl)) {
3850 + /* before we malloc anything, make sure this is */
3851 + /* a valid acl entry and one that we want to map */
3852 + idp = id_nxt(acl_entry->ace_id);
3853 + if((acl_entry->ace_type == ACC_SPECIFY ||
3854 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3855 + acl_entry = acl_nxt(acl_entry);
3859 + idp = acl_entry->ace_id;
3861 + /* Check if this is the first entry in the linked list. *
3862 + * The first entry needs to keep prevp pointing to NULL *
3863 + * and already has entryp allocated. */
3865 + if(acl_entry_link_head->count != 0) {
3866 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3868 + if(acl_entry_link->nextp == NULL) {
3869 + SAFE_FREE(file_acl);
3871 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3875 + acl_entry_link->nextp->prevp = acl_entry_link;
3876 + acl_entry_link = acl_entry_link->nextp;
3877 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3878 + if(acl_entry_link->entryp == NULL) {
3879 + SAFE_FREE(file_acl);
3881 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3884 + acl_entry_link->nextp = NULL;
3887 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3889 + /* Don't really need this since all types are going *
3890 + * to be specified but, it's better than leaving it 0 */
3892 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3894 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3896 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3898 + /* The access in the acl entries must be left shifted by *
3899 + * three bites, because they will ultimately be compared *
3900 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3902 + switch(acl_entry->ace_type){
3905 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3906 + acl_entry_link->entryp->ace_access <<= 6;
3907 + acl_entry_link_head->count++;
3910 + /* Since there is no way to return a DENY acl entry *
3911 + * change to PERMIT and then shift. */
3912 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3913 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3914 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3915 + acl_entry_link->entryp->ace_access <<= 6;
3916 + acl_entry_link_head->count++;
3922 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3923 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3925 + acl_entry = acl_nxt(acl_entry);
3927 + } /* end of if enabled */
3929 + /* Since owner, group, other acl entries are not *
3930 + * part of the acl entries in an acl, they must *
3931 + * be dummied up to become part of the list. */
3933 + for( i = 1; i < 4; i++) {
3934 + DEBUG(10,("i is %d\n",i));
3935 + if(acl_entry_link_head->count != 0) {
3936 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3937 + if(acl_entry_link->nextp == NULL) {
3938 + SAFE_FREE(file_acl);
3940 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3944 + acl_entry_link->nextp->prevp = acl_entry_link;
3945 + acl_entry_link = acl_entry_link->nextp;
3946 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3947 + if(acl_entry_link->entryp == NULL) {
3948 + SAFE_FREE(file_acl);
3950 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3955 + acl_entry_link->nextp = NULL;
3957 + new_acl_entry = acl_entry_link->entryp;
3958 + idp = new_acl_entry->ace_id;
3960 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3961 + new_acl_entry->ace_type = ACC_PERMIT;
3962 + idp->id_len = sizeof(struct ace_id);
3963 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3964 + memset(idp->id_data,0,sizeof(uid_t));
3968 + new_acl_entry->ace_access = file_acl->g_access << 6;
3969 + idp->id_type = SMB_ACL_GROUP_OBJ;
3973 + new_acl_entry->ace_access = file_acl->o_access << 6;
3974 + idp->id_type = SMB_ACL_OTHER;
3978 + new_acl_entry->ace_access = file_acl->u_access << 6;
3979 + idp->id_type = SMB_ACL_USER_OBJ;
3987 + acl_entry_link_head->count++;
3988 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3991 + acl_entry_link_head->count = 0;
3992 + SAFE_FREE(file_acl);
3994 + return(acl_entry_link_head);
3997 +SMB_ACL_T sys_acl_get_fd(int fd)
3999 + struct acl *file_acl = (struct acl *)NULL;
4000 + struct acl_entry *acl_entry;
4001 + struct new_acl_entry *new_acl_entry;
4002 + struct ace_id *idp;
4003 + struct acl_entry_link *acl_entry_link;
4004 + struct acl_entry_link *acl_entry_link_head;
4009 + /* Get the acl using fstatacl */
4011 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4012 + DEBUG(10,("fd is %d\n",fd));
4013 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4015 + if(file_acl == NULL) {
4017 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4021 + memset(file_acl,0,BUFSIZ);
4023 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4025 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4026 + SAFE_FREE(file_acl);
4030 + DEBUG(10,("Got facl and returned it\n"));
4032 + /* Point to the first acl entry in the acl */
4034 + acl_entry = file_acl->acl_ext;
4035 + /* Begin setting up the head of the linked list *
4036 + * that will be used for the storing the acl *
4037 + * in a way that is useful for the posix_acls.c *
4040 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4041 + if(acl_entry_link_head == NULL){
4042 + SAFE_FREE(file_acl);
4046 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4048 + if(acl_entry_link->entryp == NULL) {
4050 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4051 + SAFE_FREE(file_acl);
4055 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4056 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4058 + /* Check if the extended acl bit is on. *
4059 + * If it isn't, do not show the *
4060 + * contents of the acl since AIX intends *
4061 + * the extended info to remain unused */
4063 + if(file_acl->acl_mode & S_IXACL){
4064 + /* while we are not pointing to the very end */
4065 + while(acl_entry < acl_last(file_acl)) {
4066 + /* before we malloc anything, make sure this is */
4067 + /* a valid acl entry and one that we want to map */
4069 + idp = id_nxt(acl_entry->ace_id);
4070 + if((acl_entry->ace_type == ACC_SPECIFY ||
4071 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4072 + acl_entry = acl_nxt(acl_entry);
4076 + idp = acl_entry->ace_id;
4078 + /* Check if this is the first entry in the linked list. *
4079 + * The first entry needs to keep prevp pointing to NULL *
4080 + * and already has entryp allocated. */
4082 + if(acl_entry_link_head->count != 0) {
4083 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4084 + if(acl_entry_link->nextp == NULL) {
4086 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4087 + SAFE_FREE(file_acl);
4090 + acl_entry_link->nextp->prevp = acl_entry_link;
4091 + acl_entry_link = acl_entry_link->nextp;
4092 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4093 + if(acl_entry_link->entryp == NULL) {
4095 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4096 + SAFE_FREE(file_acl);
4100 + acl_entry_link->nextp = NULL;
4103 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4105 + /* Don't really need this since all types are going *
4106 + * to be specified but, it's better than leaving it 0 */
4108 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4109 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4111 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4113 + /* The access in the acl entries must be left shifted by *
4114 + * three bites, because they will ultimately be compared *
4115 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4117 + switch(acl_entry->ace_type){
4120 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4121 + acl_entry_link->entryp->ace_access <<= 6;
4122 + acl_entry_link_head->count++;
4125 + /* Since there is no way to return a DENY acl entry *
4126 + * change to PERMIT and then shift. */
4127 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4128 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4129 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4130 + acl_entry_link->entryp->ace_access <<= 6;
4131 + acl_entry_link_head->count++;
4137 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4138 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4140 + acl_entry = acl_nxt(acl_entry);
4142 + } /* end of if enabled */
4144 + /* Since owner, group, other acl entries are not *
4145 + * part of the acl entries in an acl, they must *
4146 + * be dummied up to become part of the list. */
4148 + for( i = 1; i < 4; i++) {
4149 + DEBUG(10,("i is %d\n",i));
4150 + if(acl_entry_link_head->count != 0){
4151 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4152 + if(acl_entry_link->nextp == NULL) {
4154 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4155 + SAFE_FREE(file_acl);
4159 + acl_entry_link->nextp->prevp = acl_entry_link;
4160 + acl_entry_link = acl_entry_link->nextp;
4161 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4163 + if(acl_entry_link->entryp == NULL) {
4164 + SAFE_FREE(file_acl);
4166 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4171 + acl_entry_link->nextp = NULL;
4173 + new_acl_entry = acl_entry_link->entryp;
4174 + idp = new_acl_entry->ace_id;
4176 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4177 + new_acl_entry->ace_type = ACC_PERMIT;
4178 + idp->id_len = sizeof(struct ace_id);
4179 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4180 + memset(idp->id_data,0,sizeof(uid_t));
4184 + new_acl_entry->ace_access = file_acl->g_access << 6;
4185 + idp->id_type = SMB_ACL_GROUP_OBJ;
4189 + new_acl_entry->ace_access = file_acl->o_access << 6;
4190 + idp->id_type = SMB_ACL_OTHER;
4194 + new_acl_entry->ace_access = file_acl->u_access << 6;
4195 + idp->id_type = SMB_ACL_USER_OBJ;
4202 + acl_entry_link_head->count++;
4203 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4206 + acl_entry_link_head->count = 0;
4207 + SAFE_FREE(file_acl);
4209 + return(acl_entry_link_head);
4212 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4214 + *permset = *permset & ~0777;
4218 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4221 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4225 + DEBUG(10,("This is the permset now: %d\n",*permset));
4229 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4234 +SMB_ACL_T sys_acl_init( int count)
4236 + struct acl_entry_link *theacl = NULL;
4238 + DEBUG(10,("Entering sys_acl_init\n"));
4240 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4241 + if(theacl == NULL) {
4243 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4247 + theacl->count = 0;
4248 + theacl->nextp = NULL;
4249 + theacl->prevp = NULL;
4250 + theacl->entryp = NULL;
4251 + DEBUG(10,("Exiting sys_acl_init\n"));
4255 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4257 + struct acl_entry_link *theacl;
4258 + struct acl_entry_link *acl_entryp;
4259 + struct acl_entry_link *temp_entry;
4262 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4264 + theacl = acl_entryp = *pacl;
4266 + /* Get to the end of the acl before adding entry */
4268 + for(counting=0; counting < theacl->count; counting++){
4269 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4270 + temp_entry = acl_entryp;
4271 + acl_entryp = acl_entryp->nextp;
4274 + if(theacl->count != 0){
4275 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4276 + if(acl_entryp == NULL) {
4278 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4282 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4283 + acl_entryp->prevp = temp_entry;
4284 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4287 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4288 + if(*pentry == NULL) {
4290 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4294 + memset(*pentry,0,sizeof(struct new_acl_entry));
4295 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4296 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4297 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4298 + acl_entryp->nextp = NULL;
4300 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4304 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4306 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4307 + entry->ace_id->id_type = tagtype;
4308 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4309 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4312 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4314 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4315 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4316 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4320 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4322 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4323 + if(!(*permset & S_IXUSR) &&
4324 + !(*permset & S_IWUSR) &&
4325 + !(*permset & S_IRUSR) &&
4329 + entry->ace_access = *permset;
4330 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4331 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4335 +int sys_acl_valid( SMB_ACL_T theacl )
4338 + int group_obj = 0;
4339 + int other_obj = 0;
4340 + struct acl_entry_link *acl_entry;
4342 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4343 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4344 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4345 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4348 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4350 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4356 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4358 + struct acl_entry_link *acl_entry_link = NULL;
4359 + struct acl *file_acl = NULL;
4360 + struct acl *file_acl_temp = NULL;
4361 + struct acl_entry *acl_entry = NULL;
4362 + struct ace_id *ace_id = NULL;
4369 + DEBUG(10,("Entering sys_acl_set_file\n"));
4370 + DEBUG(10,("File name is %s\n",name));
4372 + /* AIX has no default ACL */
4373 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4376 + acl_length = BUFSIZ;
4377 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4379 + if(file_acl == NULL) {
4381 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4385 + memset(file_acl,0,BUFSIZ);
4387 + file_acl->acl_len = ACL_SIZ;
4388 + file_acl->acl_mode = S_IXACL;
4390 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4391 + acl_entry_link->entryp->ace_access >>= 6;
4392 + id_type = acl_entry_link->entryp->ace_id->id_type;
4395 + case SMB_ACL_USER_OBJ:
4396 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4398 + case SMB_ACL_GROUP_OBJ:
4399 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4401 + case SMB_ACL_OTHER:
4402 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4404 + case SMB_ACL_MASK:
4408 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4409 + acl_length += sizeof(struct acl_entry);
4410 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4411 + if(file_acl_temp == NULL) {
4412 + SAFE_FREE(file_acl);
4414 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4418 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4419 + SAFE_FREE(file_acl);
4420 + file_acl = file_acl_temp;
4423 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4424 + file_acl->acl_len += sizeof(struct acl_entry);
4425 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4426 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4428 + /* In order to use this, we'll need to wait until we can get denies */
4429 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4430 + acl_entry->ace_type = ACC_SPECIFY; */
4432 + acl_entry->ace_type = ACC_SPECIFY;
4434 + ace_id = acl_entry->ace_id;
4436 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4437 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4438 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4439 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4440 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4443 + rc = chacl(name,file_acl,file_acl->acl_len);
4444 + DEBUG(10,("errno is %d\n",errno));
4445 + DEBUG(10,("return code is %d\n",rc));
4446 + SAFE_FREE(file_acl);
4447 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4451 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4453 + struct acl_entry_link *acl_entry_link = NULL;
4454 + struct acl *file_acl = NULL;
4455 + struct acl *file_acl_temp = NULL;
4456 + struct acl_entry *acl_entry = NULL;
4457 + struct ace_id *ace_id = NULL;
4463 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4464 + acl_length = BUFSIZ;
4465 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4467 + if(file_acl == NULL) {
4469 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4473 + memset(file_acl,0,BUFSIZ);
4475 + file_acl->acl_len = ACL_SIZ;
4476 + file_acl->acl_mode = S_IXACL;
4478 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4479 + acl_entry_link->entryp->ace_access >>= 6;
4480 + id_type = acl_entry_link->entryp->ace_id->id_type;
4481 + DEBUG(10,("The id_type is %d\n",id_type));
4484 + case SMB_ACL_USER_OBJ:
4485 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4487 + case SMB_ACL_GROUP_OBJ:
4488 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4490 + case SMB_ACL_OTHER:
4491 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4493 + case SMB_ACL_MASK:
4497 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4498 + acl_length += sizeof(struct acl_entry);
4499 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4500 + if(file_acl_temp == NULL) {
4501 + SAFE_FREE(file_acl);
4503 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4507 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4508 + SAFE_FREE(file_acl);
4509 + file_acl = file_acl_temp;
4512 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4513 + file_acl->acl_len += sizeof(struct acl_entry);
4514 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4515 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4517 + /* In order to use this, we'll need to wait until we can get denies */
4518 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4519 + acl_entry->ace_type = ACC_SPECIFY; */
4521 + acl_entry->ace_type = ACC_SPECIFY;
4523 + ace_id = acl_entry->ace_id;
4525 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4526 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4527 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4528 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4529 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4532 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4533 + DEBUG(10,("errno is %d\n",errno));
4534 + DEBUG(10,("return code is %d\n",rc));
4535 + SAFE_FREE(file_acl);
4536 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4540 +int sys_acl_delete_def_file(const char *name)
4542 + /* AIX has no default ACL */
4546 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4548 + return(*permset & perm);
4551 +int sys_acl_free_text(char *text)
4556 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4558 + struct acl_entry_link *acl_entry_link;
4560 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4561 + SAFE_FREE(acl_entry_link->prevp->entryp);
4562 + SAFE_FREE(acl_entry_link->prevp);
4565 + SAFE_FREE(acl_entry_link->prevp->entryp);
4566 + SAFE_FREE(acl_entry_link->prevp);
4567 + SAFE_FREE(acl_entry_link->entryp);
4568 + SAFE_FREE(acl_entry_link);
4573 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4578 +#else /* No ACLs. */
4580 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4586 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4592 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4598 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4604 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4607 + return (SMB_ACL_T)NULL;
4610 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4613 + return (SMB_ACL_T)NULL;
4616 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4622 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4628 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4631 + return (permset & perm) ? 1 : 0;
4634 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4640 +int sys_acl_free_text(UNUSED(char *text))
4646 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4652 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4658 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4664 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4670 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4676 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4682 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4688 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4694 +int sys_acl_delete_def_file(UNUSED(const char *name))
4700 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4706 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4712 +#endif /* No ACLs. */
4714 +/************************************************************************
4715 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4717 +************************************************************************/
4719 +int no_acl_syscall_error(int err)
4721 +#if defined(ENOSYS)
4722 + if (err == ENOSYS) {
4726 +#if defined(ENOTSUP)
4727 + if (err == ENOTSUP) {
4733 --- orig/lib/sysacls.h 2005-05-16 23:25:51
4734 +++ lib/sysacls.h 2005-05-16 23:25:51
4736 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4737 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4738 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4739 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4740 +#define slprintf snprintf
4742 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4743 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4744 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4745 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4746 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4747 +SMB_ACL_T sys_acl_get_fd(int fd);
4748 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4749 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4750 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4751 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4752 +SMB_ACL_T sys_acl_init(int count);
4753 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4754 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4755 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4756 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4757 +int sys_acl_valid(SMB_ACL_T theacl);
4758 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4759 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4760 +int sys_acl_delete_def_file(const char *name);
4761 +int sys_acl_free_text(char *text);
4762 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4763 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4764 --- orig/mkproto.awk 2006-02-02 02:41:09
4765 +++ mkproto.awk 2006-02-02 02:41:47
4766 @@ -58,7 +58,7 @@ BEGIN {
4770 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4771 +!/^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/ {
4775 --- orig/options.c 2006-02-02 11:40:45
4776 +++ options.c 2006-02-02 11:45:46
4777 @@ -44,6 +44,7 @@ int keep_dirlinks = 0;
4779 int preserve_links = 0;
4780 int preserve_hard_links = 0;
4781 +int preserve_acls = 0;
4782 int preserve_perms = 0;
4783 int preserve_executability = 0;
4784 int preserve_devices = 0;
4785 @@ -193,6 +194,7 @@ static void print_rsync_version(enum log
4786 char const *got_socketpair = "no ";
4787 char const *have_inplace = "no ";
4788 char const *hardlinks = "no ";
4789 + char const *acls = "no ";
4790 char const *links = "no ";
4791 char const *ipv6 = "no ";
4792 STRUCT_STAT *dumstat;
4793 @@ -209,6 +211,10 @@ static void print_rsync_version(enum log
4797 +#ifdef SUPPORT_ACLS
4801 #ifdef SUPPORT_LINKS
4804 @@ -222,9 +228,9 @@ static void print_rsync_version(enum log
4805 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4806 rprintf(f, "<http://rsync.samba.org/>\n");
4807 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4808 - "%shard links, %ssymlinks, batchfiles,\n",
4809 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4810 (int) (sizeof (OFF_T) * 8),
4811 - got_socketpair, hardlinks, links);
4812 + got_socketpair, hardlinks, acls, links);
4814 /* Note that this field may not have type ino_t. It depends
4815 * on the complicated interaction between largefile feature
4816 @@ -293,6 +299,7 @@ void usage(enum logcode F)
4817 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
4818 rprintf(F," -p, --perms preserve permissions\n");
4819 rprintf(F," -E, --executability preserve the file's executability\n");
4820 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4821 rprintf(F," --chmod=CHMOD change destination permissions\n");
4822 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4823 rprintf(F," -g, --group preserve group\n");
4824 @@ -409,6 +416,9 @@ static struct poptOption long_options[]
4825 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4826 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4827 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4828 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4829 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4830 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4831 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4832 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4833 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4834 @@ -1057,6 +1067,24 @@ int parse_arguments(int *argc, const cha
4839 +#ifdef SUPPORT_ACLS
4840 + preserve_acls = 1;
4841 + preserve_perms = 1;
4844 + /* FIXME: this should probably be ignored with a
4845 + * warning and then countermeasures taken to
4846 + * restrict group and other access in the presence
4847 + * of any more restrictive ACLs, but this is safe
4849 + snprintf(err_buf,sizeof(err_buf),
4850 + "ACLs are not supported on this %s\n",
4851 + am_server ? "server" : "client");
4853 +#endif /* SUPPORT_ACLS */
4857 /* A large opt value means that set_refuse_options()
4858 * turned this option off. */
4859 @@ -1497,6 +1525,8 @@ void server_options(char **args,int *arg
4861 if (preserve_hard_links)
4863 + if (preserve_acls)
4864 + argstr[x++] = 'A';
4868 --- orig/receiver.c 2006-01-31 02:30:18
4869 +++ receiver.c 2006-02-03 05:46:43
4870 @@ -410,6 +410,10 @@ int recv_files(int f_in, struct file_lis
4871 int itemizing = am_daemon ? daemon_log_format_has_i
4872 : !am_server && log_format_has_i;
4873 int max_phase = protocol_version >= 29 ? 2 : 1;
4874 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4875 +#ifdef SUPPORT_ACLS
4876 + char *parent_dirname = "";
4881 @@ -607,7 +611,16 @@ int recv_files(int f_in, struct file_lis
4882 * mode based on the local permissions and some heuristics. */
4883 if (!preserve_perms) {
4884 int exists = fd1 != -1;
4885 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4886 +#ifdef SUPPORT_ACLS
4887 + char *dn = file->dirname ? file->dirname : ".";
4888 + if (parent_dirname != dn
4889 + && strcmp(parent_dirname, dn) != 0) {
4890 + dflt_perms = default_perms_for_dir(dn);
4891 + parent_dirname = dn;
4894 + file->mode = dest_mode(file->mode, st.st_mode,
4895 + dflt_perms, exists);
4898 /* We now check to see if we are writing file "inplace" */
4899 --- orig/rsync.c 2006-02-02 02:41:09
4900 +++ rsync.c 2006-01-31 19:35:44
4901 @@ -53,7 +53,8 @@ void free_sums(struct sum_struct *s)
4903 /* This is only called when we aren't preserving permissions. Figure out what
4904 * the permissions should be and return them merged back into the mode. */
4905 -mode_t dest_mode(mode_t flist_mode, mode_t dest_mode, int exists)
4906 +mode_t dest_mode(mode_t flist_mode, mode_t dest_mode, int dflt_perms,
4909 /* If the file already exists we'll return the local permissions,
4910 * possibly tweaked by the --executability option. */
4911 @@ -68,7 +69,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4912 dest_mode |= (dest_mode & 0444) >> 2;
4915 - dest_mode = flist_mode & ~orig_umask;
4916 + dest_mode = ((flist_mode & CHMOD_BITS) & dflt_perms) | S_IWUSR;
4917 return (flist_mode & ~CHMOD_BITS) | (dest_mode & CHMOD_BITS);
4920 @@ -161,6 +162,14 @@ int set_file_attrs(char *fname, struct f
4924 + /* If this is a directory, SET_ACL() will be called on the cleanup
4925 + * receive_generator() pass (if we called it here, we might clobber
4926 + * writability on the directory). Everything else is OK to do now. */
4927 + if (!S_ISDIR(st->st_mode)) {
4928 + if (SET_ACL(fname, file) == 0)
4932 if (verbose > 1 && flags & ATTRS_REPORT) {
4933 enum logcode code = daemon_log_format_has_i || dry_run
4935 --- orig/rsync.h 2006-02-03 05:40:23
4936 +++ rsync.h 2006-01-31 19:27:00
4937 @@ -657,6 +657,44 @@ struct chmod_mode_struct;
4939 #define UNUSED(x) x __attribute__((__unused__))
4941 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4942 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4943 +#define SUPPORT_ACLS 1
4946 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4947 +#define ACLS_NEED_MASK 1
4950 +#ifdef SUPPORT_ACLS
4951 +#ifdef HAVE_SYS_ACL_H
4952 +#include <sys/acl.h>
4954 +#define MAKE_ACL(file, fname) make_acl(file, fname)
4955 +#define SEND_ACL(file, f) send_acl(file, f)
4956 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
4957 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4958 +#define SET_ACL(fname, file) set_acl(fname, file)
4959 +#define NEXT_ACL_UID() next_acl_uid()
4960 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
4961 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4962 + push_keep_backup_acl(file, orig, dest)
4963 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4964 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4965 +#else /* SUPPORT_ACLS */
4966 +#define MAKE_ACL(file, fname) 1 /* checked return value */
4967 +#define SEND_ACL(file, f)
4968 +#define RECEIVE_ACL(file, f)
4969 +#define SORT_FILE_ACL_INDEX_LISTS()
4970 +#define SET_ACL(fname, file) 1 /* checked return value */
4971 +#define NEXT_ACL_UID()
4972 +#define ACL_UID_MAP(uid)
4973 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4974 +#define CLEANUP_KEEP_BACKUP_ACL()
4975 +#define DUP_ACL(src, orig, mode) 1 /* checked return value */
4976 +#endif /* SUPPORT_ACLS */
4977 +#include "smb_acls.h"
4981 /* We have replacement versions of these if they're missing. */
4982 --- orig/rsync.yo 2006-01-31 03:05:44
4983 +++ rsync.yo 2006-01-31 03:14:05
4984 @@ -317,6 +317,7 @@ to the detailed description below for a
4985 -K, --keep-dirlinks treat symlinked dir on receiver as dir
4986 -p, --perms preserve permissions
4987 -E, --executability preserve executability
4988 + -A, --acls preserve ACLs (implies -p) [non-standard]
4989 --chmod=CHMOD change destination permissions
4990 -o, --owner preserve owner (super-user only)
4991 -g, --group preserve group
4992 @@ -691,14 +692,23 @@ quote(itemize(
4993 permissions, though the bf(--executability) option might change just
4994 the execute permission for the file.
4995 it() Each new file gets its permissions set based on the source file's
4996 - permissions, but masked by the receiving end's umask setting (including
4997 + permissions, but masked by the receiving end's destination-default
4998 + permissions (which is either based on the ACL of the destination
4999 + directory, if available, or the receiving end's umask setting) and
5001 the stripping of the three special permission bits).
5002 + Hint: Using bf(--chmod=ugo=rwX) without bf(--perms) will cause new
5003 + files to get all the destination-default permissions.
5006 Thus, when bf(--perms) and bf(--executability) are both disabled,
5007 rsync's behavior is the same as that of other file-copy utilities,
5008 such as bf(cp)(1) and bf(tar)(1).
5010 +This version of rsync observes default ACLs; patched versions of rsync only
5011 +applied the umask, and could thus set wrong permissions in the presence of
5014 dit(bf(-E, --executability)) This option causes rsync to preserve the
5015 executability (or non-executability) of regular files when bf(--perms) is
5016 not enabled. A regular file is considered to be executable if at least one
5017 @@ -713,6 +723,10 @@ quote(itemize(
5019 If bf(--perms) is enabled, this option is ignored.
5021 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5022 +ACLs to be the same as the source ACLs. This nonstandard option only
5023 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5025 dit(bf(--chmod)) This option tells rsync to apply one or more
5026 comma-separated "chmod" strings to the permission of the files in the
5027 transfer. The resulting value is treated as though it was the permissions
5028 --- orig/smb_acls.h 2004-06-30 00:04:07
5029 +++ smb_acls.h 2004-06-30 00:04:07
5032 + Unix SMB/Netbios implementation.
5034 + Portable SMB ACL interface
5035 + Copyright (C) Jeremy Allison 2000
5037 + This program is free software; you can redistribute it and/or modify
5038 + it under the terms of the GNU General Public License as published by
5039 + the Free Software Foundation; either version 2 of the License, or
5040 + (at your option) any later version.
5042 + This program is distributed in the hope that it will be useful,
5043 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5044 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5045 + GNU General Public License for more details.
5047 + You should have received a copy of the GNU General Public License
5048 + along with this program; if not, write to the Free Software
5049 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5052 +#ifndef _SMB_ACLS_H
5053 +#define _SMB_ACLS_H
5055 +#if defined(HAVE_POSIX_ACLS)
5057 +/* This is an identity mapping (just remove the SMB_). */
5059 +#define SMB_ACL_TAG_T acl_tag_t
5060 +#define SMB_ACL_TYPE_T acl_type_t
5061 +#define SMB_ACL_PERMSET_T acl_permset_t
5062 +#define SMB_ACL_PERM_T acl_perm_t
5063 +#define SMB_ACL_READ ACL_READ
5064 +#define SMB_ACL_WRITE ACL_WRITE
5065 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5067 +/* Types of ACLs. */
5068 +#define SMB_ACL_USER ACL_USER
5069 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5070 +#define SMB_ACL_GROUP ACL_GROUP
5071 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5072 +#define SMB_ACL_OTHER ACL_OTHER
5073 +#define SMB_ACL_MASK ACL_MASK
5075 +#define SMB_ACL_T acl_t
5077 +#define SMB_ACL_ENTRY_T acl_entry_t
5079 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5080 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5082 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5083 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5085 +#elif defined(HAVE_TRU64_ACLS)
5087 +/* This is for DEC/Compaq Tru64 UNIX */
5089 +#define SMB_ACL_TAG_T acl_tag_t
5090 +#define SMB_ACL_TYPE_T acl_type_t
5091 +#define SMB_ACL_PERMSET_T acl_permset_t
5092 +#define SMB_ACL_PERM_T acl_perm_t
5093 +#define SMB_ACL_READ ACL_READ
5094 +#define SMB_ACL_WRITE ACL_WRITE
5095 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5097 +/* Types of ACLs. */
5098 +#define SMB_ACL_USER ACL_USER
5099 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5100 +#define SMB_ACL_GROUP ACL_GROUP
5101 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5102 +#define SMB_ACL_OTHER ACL_OTHER
5103 +#define SMB_ACL_MASK ACL_MASK
5105 +#define SMB_ACL_T acl_t
5107 +#define SMB_ACL_ENTRY_T acl_entry_t
5109 +#define SMB_ACL_FIRST_ENTRY 0
5110 +#define SMB_ACL_NEXT_ENTRY 1
5112 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5113 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5115 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
5117 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5118 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5121 +/* SVR4.2 ES/MP ACLs */
5122 +typedef int SMB_ACL_TAG_T;
5123 +typedef int SMB_ACL_TYPE_T;
5124 +typedef ushort *SMB_ACL_PERMSET_T;
5125 +typedef ushort SMB_ACL_PERM_T;
5126 +#define SMB_ACL_READ 4
5127 +#define SMB_ACL_WRITE 2
5128 +#define SMB_ACL_EXECUTE 1
5130 +/* Types of ACLs. */
5131 +#define SMB_ACL_USER USER
5132 +#define SMB_ACL_USER_OBJ USER_OBJ
5133 +#define SMB_ACL_GROUP GROUP
5134 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5135 +#define SMB_ACL_OTHER OTHER_OBJ
5136 +#define SMB_ACL_MASK CLASS_OBJ
5138 +typedef struct SMB_ACL_T {
5142 + struct acl acl[1];
5145 +typedef struct acl *SMB_ACL_ENTRY_T;
5147 +#define SMB_ACL_FIRST_ENTRY 0
5148 +#define SMB_ACL_NEXT_ENTRY 1
5150 +#define SMB_ACL_TYPE_ACCESS 0
5151 +#define SMB_ACL_TYPE_DEFAULT 1
5153 +#elif defined(HAVE_HPUX_ACLS)
5156 + * Based on the Solaris & UnixWare code.
5160 +#include <sys/aclv.h>
5162 +/* SVR4.2 ES/MP ACLs */
5163 +typedef int SMB_ACL_TAG_T;
5164 +typedef int SMB_ACL_TYPE_T;
5165 +typedef ushort *SMB_ACL_PERMSET_T;
5166 +typedef ushort SMB_ACL_PERM_T;
5167 +#define SMB_ACL_READ 4
5168 +#define SMB_ACL_WRITE 2
5169 +#define SMB_ACL_EXECUTE 1
5171 +/* Types of ACLs. */
5172 +#define SMB_ACL_USER USER
5173 +#define SMB_ACL_USER_OBJ USER_OBJ
5174 +#define SMB_ACL_GROUP GROUP
5175 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5176 +#define SMB_ACL_OTHER OTHER_OBJ
5177 +#define SMB_ACL_MASK CLASS_OBJ
5179 +typedef struct SMB_ACL_T {
5183 + struct acl acl[1];
5186 +typedef struct acl *SMB_ACL_ENTRY_T;
5188 +#define SMB_ACL_FIRST_ENTRY 0
5189 +#define SMB_ACL_NEXT_ENTRY 1
5191 +#define SMB_ACL_TYPE_ACCESS 0
5192 +#define SMB_ACL_TYPE_DEFAULT 1
5194 +#elif defined(HAVE_IRIX_ACLS)
5196 +#define SMB_ACL_TAG_T acl_tag_t
5197 +#define SMB_ACL_TYPE_T acl_type_t
5198 +#define SMB_ACL_PERMSET_T acl_permset_t
5199 +#define SMB_ACL_PERM_T acl_perm_t
5200 +#define SMB_ACL_READ ACL_READ
5201 +#define SMB_ACL_WRITE ACL_WRITE
5202 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5204 +/* Types of ACLs. */
5205 +#define SMB_ACL_USER ACL_USER
5206 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5207 +#define SMB_ACL_GROUP ACL_GROUP
5208 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5209 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5210 +#define SMB_ACL_MASK ACL_MASK
5212 +typedef struct SMB_ACL_T {
5218 +#define SMB_ACL_ENTRY_T acl_entry_t
5220 +#define SMB_ACL_FIRST_ENTRY 0
5221 +#define SMB_ACL_NEXT_ENTRY 1
5223 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5224 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5226 +#elif defined(HAVE_AIX_ACLS)
5228 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5230 +#include "/usr/include/acl.h"
5232 +typedef uint *SMB_ACL_PERMSET_T;
5234 +struct acl_entry_link{
5235 + struct acl_entry_link *prevp;
5236 + struct new_acl_entry *entryp;
5237 + struct acl_entry_link *nextp;
5241 +struct new_acl_entry{
5242 + unsigned short ace_len;
5243 + unsigned short ace_type;
5244 + unsigned int ace_access;
5245 + struct ace_id ace_id[1];
5248 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5249 +#define SMB_ACL_T struct acl_entry_link*
5251 +#define SMB_ACL_TAG_T unsigned short
5252 +#define SMB_ACL_TYPE_T int
5253 +#define SMB_ACL_PERM_T uint
5254 +#define SMB_ACL_READ S_IRUSR
5255 +#define SMB_ACL_WRITE S_IWUSR
5256 +#define SMB_ACL_EXECUTE S_IXUSR
5258 +/* Types of ACLs. */
5259 +#define SMB_ACL_USER ACEID_USER
5260 +#define SMB_ACL_USER_OBJ 3
5261 +#define SMB_ACL_GROUP ACEID_GROUP
5262 +#define SMB_ACL_GROUP_OBJ 4
5263 +#define SMB_ACL_OTHER 5
5264 +#define SMB_ACL_MASK 6
5267 +#define SMB_ACL_FIRST_ENTRY 1
5268 +#define SMB_ACL_NEXT_ENTRY 2
5270 +#define SMB_ACL_TYPE_ACCESS 0
5271 +#define SMB_ACL_TYPE_DEFAULT 1
5273 +#else /* No ACLs. */
5275 +/* No ACLS - fake it. */
5276 +#define SMB_ACL_TAG_T int
5277 +#define SMB_ACL_TYPE_T int
5278 +#define SMB_ACL_PERMSET_T mode_t
5279 +#define SMB_ACL_PERM_T mode_t
5280 +#define SMB_ACL_READ S_IRUSR
5281 +#define SMB_ACL_WRITE S_IWUSR
5282 +#define SMB_ACL_EXECUTE S_IXUSR
5284 +/* Types of ACLs. */
5285 +#define SMB_ACL_USER 0
5286 +#define SMB_ACL_USER_OBJ 1
5287 +#define SMB_ACL_GROUP 2
5288 +#define SMB_ACL_GROUP_OBJ 3
5289 +#define SMB_ACL_OTHER 4
5290 +#define SMB_ACL_MASK 5
5292 +typedef struct SMB_ACL_T {
5296 +typedef struct SMB_ACL_ENTRY_T {
5298 +} *SMB_ACL_ENTRY_T;
5300 +#define SMB_ACL_FIRST_ENTRY 0
5301 +#define SMB_ACL_NEXT_ENTRY 1
5303 +#define SMB_ACL_TYPE_ACCESS 0
5304 +#define SMB_ACL_TYPE_DEFAULT 1
5306 +#endif /* No ACLs. */
5307 +#endif /* _SMB_ACLS_H */
5308 --- orig/testsuite/default-acls-obey.test 2005-10-15 16:08:45
5309 +++ testsuite/default-acls-obey.test 2005-10-15 16:08:45
5313 +# This program is distributable under the terms of the GNU GPL see
5316 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5318 +. $srcdir/testsuite/rsync.fns
5322 +$RSYNC --help | grep -q "ACLs" || test_skipped "Rsync is configured without ACL support"
5323 +setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5325 +echo "File!" >"$scratchdir/file"
5326 +echo "#!/bin/bash" >"$scratchdir/program"
5327 +chmod 666 "$scratchdir/file"
5328 +chmod 777 "$scratchdir/program"
5330 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5332 + todir="$scratchdir/$1"
5334 + setfacl -k "$todir"
5335 + chmod g-s "$todir" ### Don't let directory setgid interfere
5336 + [ "$2" ] && setfacl -dm "$2" "$todir"
5337 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5338 + # even though the directory itself is outside the transfer
5339 + $RSYNC -rvv "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5340 + [ `stat --format=%a "$todir/to"` == $4 ] || test_fail "Target $1: to should have $4 permissions"
5341 + [ `stat --format=%a "$todir/to/file"` == $3 ] || test_fail "Target $1: to/file should have $3 permissions"
5342 + [ `stat --format=%a "$todir/to/program"` == $4 ] || test_fail "Target $1: to/program should have $4 permissions"
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 + [ `stat --format=%a "$todir/to/anotherfile"` == $3 ] || test_fail "Target $1: to/anotherfile should have $3 permissions"
5348 +# Test some target directories
5350 +testit da777 u::rwx,g::rwx,o::rwx 666 777
5351 +testit da775 u::rwx,g::rwx,o::r-x 664 775
5352 +testit da750 u::rwx,g::r-x,o::--- 640 750
5353 +testit da770mask u::rwx,g::---,m::rwx,o::--- 660 770
5354 +testit noda1 '' 600 700
5356 +testit noda2 '' 666 777
5358 +testit noda3 '' 644 755
5362 --- orig/uidlist.c 2006-01-25 17:15:13
5363 +++ uidlist.c 2006-01-25 17:45:21
5366 extern int preserve_uid;
5367 extern int preserve_gid;
5368 +extern int preserve_acls;
5369 extern int numeric_ids;
5372 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5376 - if (preserve_uid) {
5377 + if (preserve_uid || preserve_acls) {
5379 /* we send sequences of uid/byte-length/name */
5380 for (list = uidlist; list; list = list->next) {
5381 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5385 - if (preserve_gid) {
5386 + if (preserve_gid || preserve_acls) {
5388 for (list = gidlist; list; list = list->next) {
5390 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5394 - if (preserve_uid && !numeric_ids) {
5395 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5396 /* read the uid list */
5397 while ((id = read_int(f)) != 0) {
5398 int len = read_byte(f);
5399 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5403 - if (preserve_gid && !numeric_ids) {
5404 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5405 /* read the gid list */
5406 while ((id = read_int(f)) != 0) {
5407 int len = read_byte(f);
5408 @@ -336,6 +337,18 @@ void recv_uid_list(int f, struct file_li
5412 +#ifdef SUPPORT_ACLS
5413 + if (preserve_acls && !numeric_ids) {
5415 + /* The enumerations don't return 0 except to flag the last
5416 + * entry, since uidlist doesn't munge 0 anyway. */
5417 + while ((id = next_acl_uid(flist)) != 0)
5418 + acl_uid_map(match_uid(id));
5419 + while ((id = next_acl_gid(flist)) != 0)
5420 + acl_gid_map(match_gid(id));
5422 +#endif /* SUPPORT_ACLS */
5424 /* Now convert all the uids/gids from sender values to our values. */
5425 if (am_root && preserve_uid && !numeric_ids) {
5426 for (i = 0; i < flist->count; i++)