1 To use this patch, run these commands for a successful build:
3 patch -p1 <patches/acls.diff
5 ./configure --enable-acl-support
8 See the --acls (-A) option in the revised man page for a note on using this
9 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
13 @@ -26,15 +26,15 @@ VERSION=@VERSION@
17 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
18 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
19 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
20 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
21 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
22 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
23 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
24 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
25 main.o checksum.o match.o syscall.o log.o backup.o
26 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
27 - fileio.o batch.o clientname.o chmod.o
28 + fileio.o batch.o clientname.o chmod.o acls.o
29 OBJS3=progress.o pipe.o
30 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
31 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
36 + * Handle passing Access Control Lists between systems.
38 + * Copyright (C) 1996 Andrew Tridgell
39 + * Copyright (C) 1996 Paul Mackerras
40 + * Copyright (C) 2006 Wayne Davison
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 along
53 + * with this program; if not, write to the Free Software Foundation, Inc.,
54 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
58 +#include "lib/sysacls.h"
63 +extern int read_only;
64 +extern int list_only;
65 +extern int orig_umask;
66 +extern int preserve_acls;
67 +extern unsigned int file_struct_len;
69 +/* === ACL structures === */
81 +#define NO_ENTRY ((uchar)0x80)
82 +typedef struct rsync_acl {
85 + /* These will be NO_ENTRY if there's no such entry. */
97 +static const rsync_acl empty_rsync_acl = {
98 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
101 +static item_list access_acl_list = EMPTY_ITEM_LIST;
102 +static item_list default_acl_list = EMPTY_ITEM_LIST;
104 +/* === Calculations on ACL types === */
106 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
108 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
109 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
110 + : "unknown SMB_ACL_TYPE_T";
113 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
114 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
116 +static int count_racl_entries(const rsync_acl *racl)
118 + return racl->users.count + racl->groups.count
119 + + (racl->user_obj != NO_ENTRY)
120 + + (racl->group_obj != NO_ENTRY)
121 + + (racl->mask != NO_ENTRY)
122 + + (racl->other != NO_ENTRY);
125 +static int calc_sacl_entries(const rsync_acl *racl)
127 + /* A System ACL always gets user/group/other permission entries. */
128 + return racl->users.count + racl->groups.count
129 +#ifdef ACLS_NEED_MASK
132 + + (racl->mask != NO_ENTRY) + 3;
136 +/* Extracts and returns the permission bits from the ACL. This cannot be
137 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
138 +static int rsync_acl_get_perms(const rsync_acl *racl)
140 + return (racl->user_obj << 6)
141 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
145 +/* Removes the permission-bit entries from the ACL because these
146 + * can be reconstructed from the file's mode. */
147 +static void rsync_acl_strip_perms(rsync_acl *racl)
149 + racl->user_obj = NO_ENTRY;
150 + if (racl->mask == NO_ENTRY)
151 + racl->group_obj = NO_ENTRY;
153 + if (racl->group_obj == racl->mask)
154 + racl->group_obj = NO_ENTRY;
155 + racl->mask = NO_ENTRY;
157 + racl->other = NO_ENTRY;
160 +/* Given an empty rsync_acl, fake up the permission bits. */
161 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
163 + racl->user_obj = (mode >> 6) & 7;
164 + racl->group_obj = (mode >> 3) & 7;
165 + racl->other = mode & 7;
168 +/* === Rsync ACL functions === */
170 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
172 + id_access *ida1, *ida2;
173 + int count = ial1->count;
174 + if (count != ial2->count)
178 + for (; count--; ida1++, ida2++) {
179 + if (ida1->access != ida2->access || ida1->id != ida2->id)
185 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
187 + return racl1->user_obj == racl2->user_obj
188 + && racl1->group_obj == racl2->group_obj
189 + && racl1->mask == racl2->mask
190 + && racl1->other == racl2->other
191 + && ida_entries_equal(&racl1->users, &racl2->users)
192 + && ida_entries_equal(&racl1->groups, &racl2->groups);
195 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
196 + * the ACL will be handled by the normal mode-preservation code. This is
197 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
198 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
199 + * that it might have several of its permission objects set to NO_ENTRY. */
200 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
201 + const rsync_acl *racl2, mode_t m)
203 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
204 + return False; /* One has a mask and the other doesn't */
206 + /* When there's a mask, the group_obj becomes an extended entry. */
207 + if (racl1->mask != NO_ENTRY) {
208 + /* A condensed rsync_acl with a mask can only have no
209 + * group_obj when it was identical to the mask. This
210 + * means that it was also identical to the group attrs
211 + * from the mode. */
212 + if (racl2->group_obj == NO_ENTRY) {
213 + if (racl1->group_obj != ((m >> 3) & 7))
215 + } else if (racl1->group_obj != racl2->group_obj)
218 + return ida_entries_equal(&racl1->users, &racl2->users)
219 + && ida_entries_equal(&racl1->groups, &racl2->groups);
222 +static void rsync_acl_free(rsync_acl *racl)
224 + if (racl->users.idas)
225 + free(racl->users.idas);
226 + if (racl->groups.idas)
227 + free(racl->groups.idas);
228 + *racl = empty_rsync_acl;
231 +void free_acl(statx *sxp)
233 + if (sxp->acc_acl) {
234 + rsync_acl_free(sxp->acc_acl);
235 + free(sxp->acc_acl);
236 + sxp->acc_acl = NULL;
238 + if (sxp->def_acl) {
239 + rsync_acl_free(sxp->def_acl);
240 + free(sxp->def_acl);
241 + sxp->def_acl = NULL;
245 +static int id_access_sorter(const void *r1, const void *r2)
247 + id_access *ida1 = (id_access *)r1;
248 + id_access *ida2 = (id_access *)r2;
249 + id_t rid1 = ida1->id, rid2 = ida2->id;
250 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
253 +static void sort_ida_entries(ida_entries *idal)
257 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
260 +/* Transfer the count id_access items out of the temp_ida_list into either
261 + * the users or groups ida_entries list in racl. */
262 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
267 + if (temp_ida_list->count) {
268 + int cnt = temp_ida_list->count;
269 + id_access *temp_idas = temp_ida_list->items;
270 + if (!(idas = new_array(id_access, cnt)))
271 + out_of_memory("save_idas");
272 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
276 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
279 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
280 + exit_cleanup(RERR_UNSUPPORTED);
282 + ent->count = temp_ida_list->count;
285 + /* Truncate the temporary list now that its idas have been saved. */
286 + temp_ida_list->count = 0;
289 +/* === System ACLs === */
291 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
292 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
294 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
295 + SMB_ACL_TAG_T prior_list_type = 0;
296 + SMB_ACL_ENTRY_T entry;
297 + const char *errfun;
300 + errfun = "sys_acl_get_entry";
301 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
303 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
304 + SMB_ACL_TAG_T tag_type;
305 + SMB_ACL_PERMSET_T permset;
309 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
310 + errfun = "sys_acl_get_tag_type";
313 + if ((rc = sys_acl_get_permset(entry, &permset))) {
314 + errfun = "sys_acl_get_tag_type";
317 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
318 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
319 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
320 + /* continue == done with entry; break == store in temporary ida list */
321 + switch (tag_type) {
322 + case SMB_ACL_USER_OBJ:
323 + if (racl->user_obj == NO_ENTRY)
324 + racl->user_obj = access;
326 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
330 + case SMB_ACL_GROUP_OBJ:
331 + if (racl->group_obj == NO_ENTRY)
332 + racl->group_obj = access;
334 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
336 + case SMB_ACL_GROUP:
339 + if (racl->mask == NO_ENTRY)
340 + racl->mask = access;
342 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
344 + case SMB_ACL_OTHER:
345 + if (racl->other == NO_ENTRY)
346 + racl->other = access;
348 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
351 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
354 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
355 + errfun = "sys_acl_get_tag_type";
359 + if (tag_type != prior_list_type) {
360 + if (prior_list_type)
361 + save_idas(&temp_ida_list, racl, prior_list_type);
362 + prior_list_type = tag_type;
364 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
365 + ida->id = *((id_t *)qualifier);
366 + ida->access = access;
367 + sys_acl_free_qualifier(qualifier, tag_type);
370 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
371 + rsync_acl_free(racl);
374 + if (prior_list_type)
375 + save_idas(&temp_ida_list, racl, prior_list_type);
377 + sort_ida_entries(&racl->users);
378 + sort_ida_entries(&racl->groups);
380 +#ifdef ACLS_NEED_MASK
381 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
382 + /* Throw away a superfluous mask, but mask off the
383 + * group perms with it first. */
384 + racl->group_obj &= racl->mask;
385 + racl->mask = NO_ENTRY;
392 +/* Synactic sugar for system calls */
394 +#define CALL_OR_ERROR(func,args,str) \
402 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
403 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
405 +/* Store the permissions in the system ACL entry. */
406 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
408 + const char *errfun = NULL;
409 + SMB_ACL_PERMSET_T permset;
411 + COE( sys_acl_get_permset,(entry, &permset) );
412 + COE( sys_acl_clear_perms,(permset) );
414 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
416 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
418 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
419 + COE( sys_acl_set_permset,(entry, permset) );
424 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
428 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
429 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
431 +#ifdef ACLS_NEED_MASK
436 + const char *errfun = NULL;
437 + SMB_ACL_ENTRY_T entry;
439 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
440 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
444 + COE( sys_acl_create_entry,(smb_acl, &entry) );
445 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
446 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
448 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
449 + COE( sys_acl_create_entry,(smb_acl, &entry) );
450 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
451 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
452 + COE2( store_access_in_entry,(ida->access, entry) );
455 + COE( sys_acl_create_entry,(smb_acl, &entry) );
456 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
457 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
459 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
460 + COE( sys_acl_create_entry,(smb_acl, &entry) );
461 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
462 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
463 + COE2( store_access_in_entry,(ida->access, entry) );
466 +#ifdef ACLS_NEED_MASK
467 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
468 + COE( sys_acl_create_entry,(smb_acl, &entry) );
469 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
470 + COE2( store_access_in_entry,(mask_bits, entry) );
472 + if (racl->mask != NO_ENTRY) {
473 + COE( sys_acl_create_entry,(smb_acl, &entry) );
474 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
475 + COE2( store_access_in_entry,(racl->mask, entry) );
479 + COE( sys_acl_create_entry,(smb_acl, &entry) );
480 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
481 + COE2( store_access_in_entry,(racl->other & 7, entry) );
484 + if (sys_acl_valid(*smb_acl) < 0)
485 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
492 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
494 + sys_acl_free_acl(*smb_acl);
498 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
499 + const item_list *racl_list,
500 + const rsync_acl *racl)
502 + static int access_match = -1, default_match = -1;
503 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
504 + size_t count = racl_list->count;
506 + /* If this is the first time through or we didn't match the last
507 + * time, then start at the end of the list, which should be the
508 + * best place to start hunting. */
510 + *match = racl_list->count - 1;
512 + rsync_acl *base = racl_list->items;
513 + if (rsync_acl_equal(base + *match, racl))
516 + *match = racl_list->count - 1;
523 +/* Return the Access Control List for the given filename. */
524 +int get_acl(const char *fname, statx *sxp)
526 + SMB_ACL_TYPE_T type;
528 + if (S_ISLNK(sxp->st.st_mode))
531 + type = SMB_ACL_TYPE_ACCESS;
533 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
534 + rsync_acl *racl = new(rsync_acl);
537 + out_of_memory("get_acl");
538 + *racl = empty_rsync_acl;
539 + if (type == SMB_ACL_TYPE_ACCESS)
540 + sxp->acc_acl = racl;
542 + sxp->def_acl = racl;
545 + BOOL ok = unpack_smb_acl(racl, sacl);
547 + sys_acl_free_acl(sacl);
552 + } else if (errno == ENOTSUP) {
553 + /* ACLs are not supported, so pretend we have a basic ACL. */
554 + if (type == SMB_ACL_TYPE_ACCESS)
555 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
557 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
558 + fname, str_acl_type(type));
562 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
567 +/* === Send functions === */
569 +/* The general strategy with the tag_type <-> character mapping is that
570 + * lowercase implies that no qualifier follows, where uppercase does.
571 + * A similar idiom for the ACL type (access or default) itself, but
572 + * lowercase in this instance means there's no ACL following, so the
573 + * ACL is a repeat, so the receiver should reuse the last of the same
576 +/* Send the ida list over the file descriptor. */
577 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
580 + size_t count = idal->count;
581 + for (ida = idal->idas; count--; ida++) {
582 + write_byte(f, tag_char);
583 + write_byte(f, ida->access);
584 + write_int(f, ida->id);
585 + /* FIXME: sorta wasteful: we should maybe buffer as
586 + * many ids as max(ACL_USER + ACL_GROUP) objects to
587 + * keep from making so many calls. */
588 + if (tag_char == 'U')
595 +/* Send an rsync ACL over the file descriptor. */
596 +static void send_rsync_acl(int f, const rsync_acl *racl)
598 + size_t count = count_racl_entries(racl);
599 + write_int(f, count);
600 + if (racl->user_obj != NO_ENTRY) {
601 + write_byte(f, 'u');
602 + write_byte(f, racl->user_obj);
604 + send_ida_entries(f, &racl->users, 'U');
605 + if (racl->group_obj != NO_ENTRY) {
606 + write_byte(f, 'g');
607 + write_byte(f, racl->group_obj);
609 + send_ida_entries(f, &racl->groups, 'G');
610 + if (racl->mask != NO_ENTRY) {
611 + write_byte(f, 'm');
612 + write_byte(f, racl->mask);
614 + if (racl->other != NO_ENTRY) {
615 + write_byte(f, 'o');
616 + write_byte(f, racl->other);
620 +/* Send the ACL from the statx structure down the indicated file descriptor.
621 + * This also frees the ACL data. */
622 +void send_acl(statx *sxp, int f)
624 + SMB_ACL_TYPE_T type;
625 + rsync_acl *racl, *new_racl;
626 + item_list *racl_list;
629 + if (S_ISLNK(sxp->st.st_mode))
632 + type = SMB_ACL_TYPE_ACCESS;
633 + racl = sxp->acc_acl;
634 + racl_list = &access_acl_list;
637 + racl = new(rsync_acl);
639 + out_of_memory("send_acl");
640 + *racl = empty_rsync_acl;
641 + if (type == SMB_ACL_TYPE_ACCESS) {
642 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
643 + sxp->acc_acl = racl;
645 + sxp->def_acl = racl;
648 + /* Avoid sending values that can be inferred from other data,
649 + * but only when preserve_acls == 1 (it is 2 when we must be
650 + * backward compatible with older acls.diff versions). */
651 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
652 + rsync_acl_strip_perms(racl);
653 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
654 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
657 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
658 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
659 + send_rsync_acl(f, racl);
661 + *racl = empty_rsync_acl;
663 + racl = sxp->def_acl;
664 + racl_list = &default_acl_list;
665 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
670 +/* === Receive functions === */
672 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
674 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
675 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
676 + uchar computed_mask_bits = 0;
680 + if (!(count = read_int(f)))
684 + char tag = read_byte(f);
685 + uchar access = read_byte(f);
686 + if (access & ~ (4 | 2 | 1)) {
687 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
689 + exit_cleanup(RERR_STREAMIO);
693 + if (racl->user_obj != NO_ENTRY) {
694 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
695 + exit_cleanup(RERR_STREAMIO);
697 + racl->user_obj = access;
700 + tag_type = SMB_ACL_USER;
703 + if (racl->group_obj != NO_ENTRY) {
704 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
705 + exit_cleanup(RERR_STREAMIO);
707 + racl->group_obj = access;
710 + tag_type = SMB_ACL_GROUP;
713 + if (racl->mask != NO_ENTRY) {
714 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
715 + exit_cleanup(RERR_STREAMIO);
717 + racl->mask = access;
720 + if (racl->other != NO_ENTRY) {
721 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
722 + exit_cleanup(RERR_STREAMIO);
724 + racl->other = access;
727 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
729 + exit_cleanup(RERR_STREAMIO);
731 + if (tag_type != prior_list_type) {
732 + if (prior_list_type)
733 + save_idas(&temp_ida_list, racl, prior_list_type);
734 + prior_list_type = tag_type;
736 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
737 + ida->access = access;
738 + ida->id = read_int(f);
739 + computed_mask_bits |= access;
741 + if (prior_list_type)
742 + save_idas(&temp_ida_list, racl, prior_list_type);
744 + if (type == SMB_ACL_TYPE_DEFAULT) {
745 + /* Ensure that these are never unset. */
746 + if (racl->user_obj == NO_ENTRY)
747 + racl->user_obj = 7;
748 + if (racl->group_obj == NO_ENTRY)
749 + racl->group_obj = 0;
750 + if (racl->other == NO_ENTRY)
754 + if (!racl->users.count && !racl->groups.count) {
755 + /* If we received a superfluous mask, throw it away. */
756 + if (racl->mask != NO_ENTRY) {
757 + /* Mask off the group perms with it first. */
758 + racl->group_obj &= racl->mask | NO_ENTRY;
759 + racl->mask = NO_ENTRY;
761 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
762 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
765 +/* Receive the ACL info the sender has included for this file-list entry. */
766 +void receive_acl(struct file_struct *file, int f)
768 + SMB_ACL_TYPE_T type;
769 + item_list *racl_list;
772 + if (S_ISLNK(file->mode))
775 + type = SMB_ACL_TYPE_ACCESS;
776 + racl_list = &access_acl_list;
777 + ndx_ptr = (char*)file + file_struct_len;
779 + char tag = read_byte(f);
782 + if (tag == 'A' || tag == 'a') {
783 + if (type != SMB_ACL_TYPE_ACCESS) {
784 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
785 + f_name(file, NULL));
786 + exit_cleanup(RERR_STREAMIO);
788 + } else if (tag == 'D' || tag == 'd') {
789 + if (type == SMB_ACL_TYPE_ACCESS) {
790 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
791 + f_name(file, NULL));
792 + exit_cleanup(RERR_STREAMIO);
795 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
796 + f_name(file, NULL), tag);
797 + exit_cleanup(RERR_STREAMIO);
799 + if (tag == 'A' || tag == 'D') {
801 + ndx = racl_list->count;
802 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
803 + duo_item->racl = empty_rsync_acl;
804 + receive_rsync_acl(&duo_item->racl, f, type);
805 + duo_item->sacl = NULL;
808 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
809 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
810 + f_name(file, NULL), str_acl_type(type), ndx);
811 + exit_cleanup(RERR_STREAMIO);
814 + SIVAL(ndx_ptr, 0, ndx);
815 + racl_list = &default_acl_list;
817 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
820 +/* Turn the ACL data in statx into cached ACL data, setting the index
821 + * values in the file struct. */
822 +void cache_acl(struct file_struct *file, statx *sxp)
824 + SMB_ACL_TYPE_T type;
826 + item_list *racl_list;
830 + if (S_ISLNK(file->mode))
833 + type = SMB_ACL_TYPE_ACCESS;
834 + racl = sxp->acc_acl;
835 + racl_list = &access_acl_list;
836 + ndx_ptr = (char*)file + file_struct_len;
840 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
842 + ndx = racl_list->count;
843 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
844 + new_duo->racl = *racl;
845 + new_duo->sacl = NULL;
846 + *racl = empty_rsync_acl;
848 + SIVAL(ndx_ptr, 0, ndx);
849 + racl = sxp->def_acl;
850 + racl_list = &default_acl_list;
852 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
857 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
859 + SMB_ACL_ENTRY_T entry;
860 + const char *errfun;
863 + if (S_ISDIR(mode)) {
864 + /* If the sticky bit is going on, it's not safe to allow all
865 + * the new ACL to go into effect before it gets set. */
866 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
867 + if (mode & S_ISVTX)
870 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
873 + /* If setuid or setgid is going off, it's not safe to allow all
874 + * the new ACL to go into effect before they get cleared. */
875 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
876 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
881 + errfun = "sys_acl_get_entry";
882 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
884 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
885 + SMB_ACL_TAG_T tag_type;
886 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
887 + errfun = "sys_acl_get_tag_type";
890 + switch (tag_type) {
891 + case SMB_ACL_USER_OBJ:
892 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
894 + case SMB_ACL_GROUP_OBJ:
895 + /* group is only empty when identical to group perms. */
896 + if (racl->group_obj != NO_ENTRY)
898 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
901 +#ifndef ACLS_NEED_MASK
902 + /* mask is only empty when we don't need it. */
903 + if (racl->mask == NO_ENTRY)
906 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
908 + case SMB_ACL_OTHER:
909 + COE2( store_access_in_entry,(mode & 7, entry) );
916 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
922 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
923 + /* Ensure that chmod() will be called to restore any lost setid bits. */
924 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
925 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
926 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
929 + /* Return the mode of the file on disk, as we will set them. */
930 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
933 +/* Set ACL on indicated filename.
935 + * This sets extended access ACL entries and default ACL. If convenient,
936 + * it sets permission bits along with the access ACL and signals having
937 + * done so by modifying sxp->st.st_mode.
939 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
940 + * with fname set to NULL to just check if the ACL is unchanged. */
941 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
944 + SMB_ACL_TYPE_T type;
947 + if (!dry_run && (read_only || list_only)) {
952 + if (S_ISLNK(file->mode))
955 + type = SMB_ACL_TYPE_ACCESS;
956 + ndx_ptr = (char*)file + file_struct_len;
960 + int32 ndx = IVAL(ndx_ptr, 0);
964 + if (type == SMB_ACL_TYPE_ACCESS) {
965 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
967 + duo_item = access_acl_list.items;
970 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
972 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
974 + duo_item = default_acl_list.items;
977 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
981 + if (!dry_run && fname) {
982 + if (type == SMB_ACL_TYPE_DEFAULT
983 + && duo_item->racl.user_obj == NO_ENTRY) {
984 + if (sys_acl_delete_def_file(fname) < 0) {
985 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
991 + mode_t cur_mode = sxp->st.st_mode;
992 + if (!duo_item->sacl
993 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
997 + if (type == SMB_ACL_TYPE_ACCESS) {
998 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
999 + cur_mode, file->mode);
1000 + if (cur_mode == (mode_t)~0)
1003 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
1004 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1005 + fname, str_acl_type(type));
1009 + if (type == SMB_ACL_TYPE_ACCESS)
1010 + sxp->st.st_mode = cur_mode;
1013 + if (unchanged == 1)
1015 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1020 +/* === Enumeration functions for uid mapping === */
1022 +/* Context -- one and only one. Should be cycled through once on uid
1023 + * mapping and once on gid mapping. */
1024 +static item_list *_enum_racl_lists[] = {
1025 + &access_acl_list, &default_acl_list, NULL
1028 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1029 +static int enum_ida_index = 0;
1030 +static size_t enum_racl_index = 0;
1032 +/* This returns the next tag_type id from the given ACL for the next entry,
1033 + * or it returns 0 if there are no more tag_type ids in the acl. */
1034 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1036 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1037 + if (enum_ida_index < idal->count) {
1038 + id_access *ida = &idal->idas[enum_ida_index++];
1041 + enum_ida_index = 0;
1045 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1047 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1049 + acl_duo *duo_item = racl_list->items;
1050 + duo_item += enum_racl_index;
1051 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1054 + enum_racl_index = 0;
1058 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1060 + for (; *enum_racl_list; enum_racl_list++) {
1061 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1065 + enum_racl_list = &_enum_racl_lists[0];
1069 +id_t *next_acl_uid()
1071 + return next_acl_list_id(SMB_ACL_USER);
1074 +id_t *next_acl_gid()
1076 + return next_acl_list_id(SMB_ACL_GROUP);
1079 +/* This is used by dest_mode(). */
1080 +int default_perms_for_dir(const char *dir)
1089 + perms = ACCESSPERMS & ~orig_umask;
1090 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1091 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1092 + if (sacl == NULL) {
1093 + /* Couldn't get an ACL. Darn. */
1096 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1100 + /* We're doing a dry run, so the containing directory
1101 + * wasn't actually created. Don't worry about it. */
1104 + /* Otherwise fall through. */
1106 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1107 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1113 + racl = empty_rsync_acl;
1114 + ok = unpack_smb_acl(&racl, sacl);
1115 + sys_acl_free_acl(sacl);
1117 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1121 + /* Apply the permission-bit entries of the default ACL, if any. */
1122 + if (racl.user_obj != NO_ENTRY) {
1123 + perms = rsync_acl_get_perms(&racl);
1125 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1128 + rsync_acl_free(&racl);
1132 +#endif /* SUPPORT_ACLS */
1135 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1136 extern char *backup_dir;
1139 +extern int preserve_acls;
1140 extern int preserve_devices;
1141 extern int preserve_specials;
1142 extern int preserve_links;
1143 @@ -94,7 +95,8 @@ path
1144 ****************************************************************************/
1145 static int make_bak_dir(char *fullpath)
1149 + struct file_struct *file;
1150 char *rel = fullpath + backup_dir_len;
1151 char *end = rel + strlen(rel);
1153 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1155 /* Try to transfer the directory settings of the
1156 * actual dir that the files are coming from. */
1157 - if (do_stat(rel, &st) < 0) {
1158 + if (do_stat(rel, &sx.st) < 0) {
1159 rsyserr(FERROR, errno,
1160 "make_bak_dir stat %s failed",
1163 - do_lchown(fullpath, st.st_uid, st.st_gid);
1164 - do_chmod(fullpath, st.st_mode);
1165 +#ifdef SUPPORT_ACLS
1166 + sx.acc_acl = sx.def_acl = NULL;
1168 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1170 +#ifdef SUPPORT_ACLS
1171 + if (preserve_acls) {
1172 + get_acl(rel, &sx);
1173 + cache_acl(file, &sx);
1176 + set_file_attrs(fullpath, file, NULL, 0);
1181 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1182 * We will move the file to be deleted into a parallel directory tree. */
1183 static int keep_backup(char *fname)
1187 struct file_struct *file;
1192 /* return if no file to keep */
1193 - if (do_lstat(fname, &st) < 0)
1194 + if (do_lstat(fname, &sx.st) < 0)
1196 +#ifdef SUPPORT_ACLS
1197 + sx.acc_acl = sx.def_acl = NULL;
1200 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1201 return 1; /* the file could have disappeared */
1202 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1203 if (!(buf = get_backup_name(fname)))
1206 +#ifdef SUPPORT_ACLS
1207 + if (preserve_acls) {
1208 + get_acl(fname, &sx);
1209 + cache_acl(file, &sx);
1213 /* Check to see if this is a device file, or link */
1214 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1215 || (preserve_specials && IS_SPECIAL(file->mode))) {
1216 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1217 if (robust_move(fname, buf) != 0) {
1218 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1219 full_fname(fname), buf);
1220 - } else if (st.st_nlink > 1) {
1221 + } else if (sx.st.st_nlink > 1) {
1222 /* If someone has hard-linked the file into the backup
1223 * dir, rename() might return success but do nothing! */
1224 robust_unlink(fname); /* Just in case... */
1225 --- old/configure.in
1226 +++ new/configure.in
1227 @@ -515,6 +515,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1228 AC_CHECK_LIB(resolv, strcasecmp)
1231 +AC_CHECK_FUNCS(aclsort)
1232 +if test x"$ac_cv_func_aclsort" = x"no"; then
1233 + AC_CHECK_LIB(sec, aclsort)
1236 dnl At the moment we don't test for a broken memcmp(), because all we
1237 dnl need to do is test for equality, not comparison, and it seems that
1238 dnl every platform has a memcmp that can do at least that.
1239 @@ -779,6 +784,78 @@ AC_SUBST(OBJ_RESTORE)
1240 AC_SUBST(CC_SHOBJ_FLAG)
1241 AC_SUBST(BUILD_POPT)
1243 +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h)
1244 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1245 +#################################################
1246 +# check for ACL support
1248 +AC_MSG_CHECKING(whether to support ACLs)
1249 +AC_ARG_ENABLE(acl-support,
1250 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1251 +[ case "$enableval" in
1254 + case "$host_os" in
1256 + AC_MSG_RESULT(Using UnixWare ACLs)
1257 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1259 + *solaris*|*cygwin*)
1260 + AC_MSG_RESULT(Using solaris ACLs)
1261 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1264 + AC_MSG_RESULT(Using HPUX ACLs)
1265 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1268 + AC_MSG_RESULT(Using IRIX ACLs)
1269 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1272 + AC_MSG_RESULT(Using AIX ACLs)
1273 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1276 + AC_MSG_RESULT(Using Tru64 ACLs)
1277 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1278 + LIBS="$LIBS -lpacl"
1281 + AC_MSG_RESULT(ACLs requested -- running tests)
1282 + AC_CHECK_LIB(acl,acl_get_file)
1283 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1284 + AC_TRY_LINK([#include <sys/types.h>
1285 +#include <sys/acl.h>],
1286 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1287 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1288 + AC_MSG_CHECKING(ACL test results)
1289 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1290 + AC_MSG_RESULT(Using posix ACLs)
1291 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1292 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1293 + AC_TRY_LINK([#include <sys/types.h>
1294 +#include <sys/acl.h>],
1295 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1296 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1297 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1298 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1301 + AC_MSG_ERROR(Failed to find ACL support)
1308 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1311 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1315 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1320 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1321 extern int one_file_system;
1322 extern int copy_dirlinks;
1323 extern int keep_dirlinks;
1324 +extern int preserve_acls;
1325 extern int preserve_links;
1326 extern int preserve_hard_links;
1327 extern int preserve_devices;
1328 @@ -135,6 +136,8 @@ static void list_file_entry(struct file_
1330 permstring(permbuf, f->mode);
1332 + /* TODO: indicate '+' if the entry has an ACL. */
1334 #ifdef SUPPORT_LINKS
1335 if (preserve_links && S_ISLNK(f->mode)) {
1336 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1337 @@ -497,6 +500,9 @@ static struct file_struct *receive_file_
1338 char thisname[MAXPATHLEN];
1339 unsigned int l1 = 0, l2 = 0;
1340 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1341 +#ifdef SUPPORT_ACLS
1345 char *basename, *dirname, *bp;
1346 struct file_struct *file;
1347 @@ -600,13 +606,27 @@ static struct file_struct *receive_file_
1349 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1351 +#ifdef SUPPORT_ACLS
1352 + /* We need one or two index int32s when we're preserving ACLs. */
1353 + if (preserve_acls)
1354 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
1359 alloc_len = file_struct_len + dirname_len + basename_len
1360 +#ifdef SUPPORT_ACLS
1363 + linkname_len + sum_len;
1364 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1366 file = (struct file_struct *)bp;
1367 memset(bp, 0, file_struct_len);
1368 bp += file_struct_len;
1369 +#ifdef SUPPORT_ACLS
1373 file->modtime = modtime;
1374 file->length = file_length;
1375 @@ -701,6 +721,11 @@ static struct file_struct *receive_file_
1376 read_buf(f, sum, checksum_len);
1379 +#ifdef SUPPORT_ACLS
1380 + if (preserve_acls)
1381 + receive_acl(file, f);
1387 @@ -958,6 +983,9 @@ static struct file_struct *send_file_nam
1388 unsigned short flags)
1390 struct file_struct *file;
1391 +#ifdef SUPPORT_ACLS
1395 file = make_file(fname, flist, stp, flags,
1396 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1397 @@ -967,6 +995,15 @@ static struct file_struct *send_file_nam
1398 if (chmod_modes && !S_ISLNK(file->mode))
1399 file->mode = tweak_mode(file->mode, chmod_modes);
1401 +#ifdef SUPPORT_ACLS
1402 + if (preserve_acls && f >= 0) {
1403 + sx.st.st_mode = file->mode;
1404 + sx.acc_acl = sx.def_acl = NULL;
1405 + if (get_acl(fname, &sx) < 0)
1410 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1412 flist_expand(flist);
1413 @@ -974,6 +1011,15 @@ static struct file_struct *send_file_nam
1414 if (file->basename[0]) {
1415 flist->files[flist->count++] = file;
1416 send_file_entry(file, f);
1417 +#ifdef SUPPORT_ACLS
1418 + if (preserve_acls && f >= 0)
1422 +#ifdef SUPPORT_ACLS
1423 + if (preserve_acls && f >= 0)
1431 @@ -35,6 +35,7 @@ extern int do_progress;
1432 extern int relative_paths;
1433 extern int implied_dirs;
1434 extern int keep_dirlinks;
1435 +extern int preserve_acls;
1436 extern int preserve_links;
1437 extern int preserve_devices;
1438 extern int preserve_specials;
1439 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1440 extern int max_delete;
1441 extern int force_delete;
1442 extern int one_file_system;
1443 +extern mode_t orig_umask;
1444 extern struct stats stats;
1445 extern dev_t filesystem_dev;
1446 extern char *backup_dir;
1447 @@ -379,22 +381,27 @@ static void do_delete_pass(struct file_l
1448 rprintf(FINFO, " \r");
1451 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1452 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1455 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1456 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1459 - if (am_root && preserve_uid && st->st_uid != file->uid)
1460 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1463 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1464 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1467 +#ifdef SUPPORT_ACLS
1468 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1475 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1476 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1477 int32 iflags, uchar fnamecmp_type, const char *xname)
1479 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1480 @@ -402,20 +409,24 @@ void itemize(struct file_struct *file, i
1481 : S_ISDIR(file->mode) ? !omit_dir_times
1482 : !S_ISLNK(file->mode);
1484 - if (S_ISREG(file->mode) && file->length != st->st_size)
1485 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1486 iflags |= ITEM_REPORT_SIZE;
1487 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1488 && !(iflags & ITEM_MATCHED)
1489 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1490 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1491 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1492 iflags |= ITEM_REPORT_TIME;
1493 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1494 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1495 iflags |= ITEM_REPORT_PERMS;
1496 - if (preserve_uid && am_root && file->uid != st->st_uid)
1497 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1498 iflags |= ITEM_REPORT_OWNER;
1499 if (preserve_gid && file->gid != GID_NONE
1500 - && st->st_gid != file->gid)
1501 + && sxp->st.st_gid != file->gid)
1502 iflags |= ITEM_REPORT_GROUP;
1503 +#ifdef SUPPORT_ACLS
1504 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1505 + iflags |= ITEM_REPORT_ACL;
1508 iflags |= ITEM_IS_NEW;
1510 @@ -668,7 +679,7 @@ void check_for_finished_hlinks(int itemi
1511 * handling the file, -1 if no dest-linking occurred, or a non-negative
1512 * value if we found an alternate basis file. */
1513 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1514 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1515 + char *cmpbuf, statx *sxp, int itemizing,
1516 int maybe_ATTRS_REPORT, enum logcode code)
1518 int best_match = -1;
1519 @@ -677,7 +688,7 @@ static int try_dests_reg(struct file_str
1522 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1523 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1524 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1526 switch (match_level) {
1528 @@ -685,16 +696,20 @@ static int try_dests_reg(struct file_str
1532 - if (!unchanged_file(cmpbuf, file, stp))
1533 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1539 - if (!unchanged_attrs(file, stp))
1540 +#ifdef SUPPORT_ACLS
1541 + if (preserve_acls)
1542 + get_acl(cmpbuf, sxp);
1544 + if (!unchanged_attrs(file, sxp))
1546 if (always_checksum && preserve_times
1547 - && cmp_time(stp->st_mtime, file->modtime))
1548 + && cmp_time(sxp->st.st_mtime, file->modtime))
1552 @@ -709,7 +724,7 @@ static int try_dests_reg(struct file_str
1553 if (j != best_match) {
1555 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1556 - if (link_stat(cmpbuf, stp, 0) < 0)
1557 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1561 @@ -717,7 +732,7 @@ static int try_dests_reg(struct file_str
1562 #ifdef SUPPORT_HARD_LINKS
1564 int i = itemizing && (verbose > 1 || stdout_format_has_i > 1);
1565 - if (hard_link_one(file, ndx, fname, 0, stp,
1566 + if (hard_link_one(file, ndx, fname, 0, sxp,
1567 cmpbuf, 1, i, code) < 0)
1569 if (preserve_hard_links && file->link_u.links) {
1570 @@ -727,8 +742,13 @@ static int try_dests_reg(struct file_str
1575 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1577 +#ifdef SUPPORT_ACLS
1578 + if (preserve_acls && !ACL_READY(*sxp))
1579 + get_acl(fname, sxp);
1581 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1583 if (verbose > 1 && maybe_ATTRS_REPORT) {
1584 rprintf(FCLIENT, "%s is uptodate\n", fname);
1586 @@ -744,8 +764,13 @@ static int try_dests_reg(struct file_str
1591 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1593 +#ifdef SUPPORT_ACLS
1594 + if (preserve_acls && !ACL_READY(*sxp))
1595 + get_acl(fname, sxp);
1597 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1599 set_file_attrs(fname, file, NULL, 0);
1600 if (maybe_ATTRS_REPORT
1601 && ((!itemizing && verbose && match_level == 2)
1602 @@ -766,7 +791,7 @@ static int try_dests_reg(struct file_str
1603 * handling the file, or -1 if no dest-linking occurred, or a non-negative
1604 * value if we found an alternate basis file. */
1605 static int try_dests_non(struct file_struct *file, char *fname, int ndx,
1606 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1607 + char *cmpbuf, statx *sxp, int itemizing,
1608 int maybe_ATTRS_REPORT, enum logcode code)
1610 char lnk[MAXPATHLEN];
1611 @@ -798,24 +823,24 @@ static int try_dests_non(struct file_str
1614 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1615 - if (link_stat(cmpbuf, stp, 0) < 0)
1616 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1620 - if (!S_ISDIR(stp->st_mode))
1621 + if (!S_ISDIR(sxp->st.st_mode))
1625 - if (!IS_SPECIAL(stp->st_mode))
1626 + if (!IS_SPECIAL(sxp->st.st_mode))
1630 - if (!IS_DEVICE(stp->st_mode))
1631 + if (!IS_DEVICE(sxp->st.st_mode))
1634 #ifdef SUPPORT_LINKS
1636 - if (!S_ISLNK(stp->st_mode))
1637 + if (!S_ISLNK(sxp->st.st_mode))
1641 @@ -829,7 +854,7 @@ static int try_dests_non(struct file_str
1645 - if (stp->st_rdev != file->u.rdev)
1646 + if (sxp->st.st_rdev != file->u.rdev)
1649 #ifdef SUPPORT_LINKS
1650 @@ -846,7 +871,11 @@ static int try_dests_non(struct file_str
1654 - if (unchanged_attrs(file, stp)) {
1655 +#ifdef SUPPORT_ACLS
1656 + if (preserve_acls)
1657 + get_acl(cmpbuf, sxp);
1659 + if (unchanged_attrs(file, sxp)) {
1663 @@ -859,7 +888,7 @@ static int try_dests_non(struct file_str
1664 if (j != best_match) {
1666 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1667 - if (link_stat(cmpbuf, stp, 0) < 0)
1668 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1672 @@ -890,7 +919,15 @@ static int try_dests_non(struct file_str
1674 + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
1675 char *lp = match_level == 3 ? "" : NULL;
1676 - itemize(file, ndx, 0, stp, chg + ITEM_MATCHED, 0, lp);
1677 +#ifdef SUPPORT_ACLS
1678 + if (preserve_acls)
1679 + get_acl(fname, sxp);
1681 + itemize(file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp);
1682 +#ifdef SUPPORT_ACLS
1683 + if (preserve_acls)
1687 if (verbose > 1 && maybe_ATTRS_REPORT) {
1688 rprintf(FCLIENT, "%s%s is uptodate\n",
1689 @@ -903,6 +940,7 @@ static int try_dests_non(struct file_str
1692 static int phase = 0;
1693 +static int dflt_perms;
1695 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1696 * make sure it exists, and has the right permissions/timestamp info. For
1697 @@ -924,7 +962,8 @@ static void recv_generator(char *fname,
1698 static int need_fuzzy_dirlist = 0;
1699 struct file_struct *fuzzy_file = NULL;
1700 int fd = -1, f_copy = -1;
1701 - STRUCT_STAT st, real_st, partial_st;
1702 + statx sx, real_sx;
1703 + STRUCT_STAT partial_st;
1704 struct file_struct *back_file = NULL;
1705 int statret, real_ret, stat_errno;
1706 char *fnamecmp, *partialptr, *backupptr = NULL;
1707 @@ -980,6 +1019,9 @@ static void recv_generator(char *fname,
1708 } else if (!dry_run)
1711 +#ifdef SUPPORT_ACLS
1712 + sx.acc_acl = sx.def_acl = NULL;
1716 stat_errno = ENOENT;
1717 @@ -987,7 +1029,7 @@ static void recv_generator(char *fname,
1718 const char *dn = file->dirname ? file->dirname : ".";
1719 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1720 if (relative_paths && !implied_dirs
1721 - && do_stat(dn, &st) < 0
1722 + && do_stat(dn, &sx.st) < 0
1723 && create_directory_path(fname) < 0) {
1724 rsyserr(FERROR, errno,
1725 "recv_generator: mkdir %s failed",
1726 @@ -999,6 +1041,10 @@ static void recv_generator(char *fname,
1729 need_fuzzy_dirlist = 1;
1730 +#ifdef SUPPORT_ACLS
1731 + if (!preserve_perms)
1732 + dflt_perms = default_perms_for_dir(dn);
1735 parent_dirname = dn;
1737 @@ -1008,7 +1054,7 @@ static void recv_generator(char *fname,
1738 need_fuzzy_dirlist = 0;
1741 - statret = link_stat(fname, &st,
1742 + statret = link_stat(fname, &sx.st,
1743 keep_dirlinks && S_ISDIR(file->mode));
1746 @@ -1026,8 +1072,9 @@ static void recv_generator(char *fname,
1747 * mode based on the local permissions and some heuristics. */
1748 if (!preserve_perms) {
1749 int exists = statret == 0
1750 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1751 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1752 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1753 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1757 if (S_ISDIR(file->mode)) {
1758 @@ -1036,8 +1083,8 @@ static void recv_generator(char *fname,
1759 * file of that name and it is *not* a directory, then
1760 * we need to delete it. If it doesn't exist, then
1761 * (perhaps recursively) create it. */
1762 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1763 - if (delete_item(fname, st.st_mode, "directory", del_opts) != 0)
1764 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1765 + if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0)
1769 @@ -1046,14 +1093,14 @@ static void recv_generator(char *fname,
1776 if (*fname == '.' && fname[1] == '\0')
1780 if (statret != 0 && basis_dir[0] != NULL) {
1781 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1782 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1783 itemizing, maybe_ATTRS_REPORT, code);
1786 @@ -1062,7 +1109,11 @@ static void recv_generator(char *fname,
1789 if (itemizing && f_out != -1) {
1790 - itemize(file, ndx, statret, &st,
1791 +#ifdef SUPPORT_ACLS
1792 + if (preserve_acls && statret == 0)
1793 + get_acl(fname, &sx);
1795 + itemize(file, ndx, statret, &sx,
1796 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1798 if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1799 @@ -1082,21 +1133,21 @@ static void recv_generator(char *fname,
1803 - if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0)
1804 + if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, 0)
1805 && verbose && code != FNONE && f_out != -1)
1806 rprintf(code, "%s/\n", fname);
1807 if (real_ret != 0 && one_file_system)
1808 - real_st.st_dev = filesystem_dev;
1809 + real_sx.st.st_dev = filesystem_dev;
1810 if (delete_during && f_out != -1 && !phase && dry_run < 2
1811 && (file->flags & FLAG_DEL_HERE))
1812 - delete_in_dir(the_file_list, fname, file, &real_st);
1814 + delete_in_dir(the_file_list, fname, file, &real_sx.st);
1818 if (preserve_hard_links && file->link_u.links
1819 - && hard_link_check(file, ndx, fname, statret, &st,
1820 + && hard_link_check(file, ndx, fname, statret, &sx,
1821 itemizing, code, HL_CHECK_MASTER))
1825 if (preserve_links && S_ISLNK(file->mode)) {
1826 #ifdef SUPPORT_LINKS
1827 @@ -1114,15 +1165,15 @@ static void recv_generator(char *fname,
1828 char lnk[MAXPATHLEN];
1831 - if (!S_ISLNK(st.st_mode))
1832 + if (!S_ISLNK(sx.st.st_mode))
1834 else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0
1835 && strncmp(lnk, file->u.link, len) == 0
1836 && file->u.link[len] == '\0') {
1837 /* The link is pointing to the right place. */
1839 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1840 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1841 + itemize(file, ndx, 0, &sx, 0, 0, NULL);
1842 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1843 if (preserve_hard_links && file->link_u.links)
1844 hard_link_cluster(file, ndx, itemizing, code);
1845 if (remove_source_files == 1)
1846 @@ -1131,10 +1182,10 @@ static void recv_generator(char *fname,
1848 /* Not the right symlink (or not a symlink), so
1850 - if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0)
1851 + if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0)
1853 } else if (basis_dir[0] != NULL) {
1854 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1855 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1856 itemizing, maybe_ATTRS_REPORT, code);
1858 #ifndef CAN_HARDLINK_SYMLINK
1859 @@ -1150,7 +1201,7 @@ static void recv_generator(char *fname,
1862 if (preserve_hard_links && file->link_u.links
1863 - && hard_link_check(file, ndx, fname, -1, &st,
1864 + && hard_link_check(file, ndx, fname, -1, &sx,
1865 itemizing, code, HL_SKIP))
1867 if (do_symlink(file->u.link, fname) != 0) {
1868 @@ -1159,7 +1210,7 @@ static void recv_generator(char *fname,
1870 set_file_attrs(fname, file, NULL, 0);
1872 - itemize(file, ndx, statret, &st,
1873 + itemize(file, ndx, statret, &sx,
1874 ITEM_LOCAL_CHANGE, 0, NULL);
1876 if (code != FNONE && verbose)
1877 @@ -1181,31 +1232,36 @@ static void recv_generator(char *fname,
1880 if (IS_DEVICE(file->mode)) {
1881 - if (!IS_DEVICE(st.st_mode))
1882 + if (!IS_DEVICE(sx.st.st_mode))
1886 - if (!IS_SPECIAL(st.st_mode))
1887 + if (!IS_SPECIAL(sx.st.st_mode))
1892 - && (st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
1893 - && st.st_rdev == file->u.rdev) {
1894 + && (sx.st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
1895 + && sx.st.st_rdev == file->u.rdev) {
1896 /* The device or special file is identical. */
1898 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1899 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1901 +#ifdef SUPPORT_ACLS
1902 + if (preserve_acls)
1903 + get_acl(fname, &sx);
1905 + itemize(file, ndx, 0, &sx, 0, 0, NULL);
1907 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1908 if (preserve_hard_links && file->link_u.links)
1909 hard_link_cluster(file, ndx, itemizing, code);
1910 if (remove_source_files == 1)
1911 goto return_with_success;
1915 - if (delete_item(fname, st.st_mode, t, del_opts) != 0)
1916 + if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0)
1918 } else if (basis_dir[0] != NULL) {
1919 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1920 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1921 itemizing, maybe_ATTRS_REPORT, code);
1923 #ifndef CAN_HARDLINK_SPECIAL
1924 @@ -1221,7 +1277,7 @@ static void recv_generator(char *fname,
1927 if (preserve_hard_links && file->link_u.links
1928 - && hard_link_check(file, ndx, fname, -1, &st,
1929 + && hard_link_check(file, ndx, fname, -1, &sx,
1930 itemizing, code, HL_SKIP))
1933 @@ -1234,7 +1290,11 @@ static void recv_generator(char *fname,
1935 set_file_attrs(fname, file, NULL, 0);
1937 - itemize(file, ndx, statret, &st,
1938 +#ifdef SUPPORT_ACLS
1939 + if (preserve_acls && statret == 0)
1940 + get_acl(fname, &sx);
1942 + itemize(file, ndx, statret, &sx,
1943 ITEM_LOCAL_CHANGE, 0, NULL);
1945 if (code != FNONE && verbose)
1946 @@ -1244,7 +1304,7 @@ static void recv_generator(char *fname,
1947 if (remove_source_files == 1)
1948 goto return_with_success;
1954 if (!S_ISREG(file->mode)) {
1955 @@ -1278,7 +1338,7 @@ static void recv_generator(char *fname,
1958 if (update_only && statret == 0
1959 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1960 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1962 rprintf(FINFO, "%s is newer\n", fname);
1964 @@ -1287,20 +1347,20 @@ static void recv_generator(char *fname,
1966 fnamecmp_type = FNAMECMP_FNAME;
1968 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1969 - if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0)
1970 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1971 + if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0)
1974 stat_errno = ENOENT;
1977 if (statret != 0 && basis_dir[0] != NULL) {
1978 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1979 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1980 itemizing, maybe_ATTRS_REPORT, code);
1982 if (remove_source_files == 1)
1983 goto return_with_success;
1988 fnamecmp = fnamecmpbuf;
1989 @@ -1310,7 +1370,7 @@ static void recv_generator(char *fname,
1996 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1997 && link_stat(partialptr, &partial_st, 0) == 0
1998 @@ -1329,7 +1389,7 @@ static void recv_generator(char *fname,
1999 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
2000 fname, fnamecmpbuf);
2002 - st.st_size = fuzzy_file->length;
2003 + sx.st.st_size = fuzzy_file->length;
2005 fnamecmp = fnamecmpbuf;
2006 fnamecmp_type = FNAMECMP_FUZZY;
2007 @@ -1338,7 +1398,7 @@ static void recv_generator(char *fname,
2010 if (preserve_hard_links && file->link_u.links
2011 - && hard_link_check(file, ndx, fname, statret, &st,
2012 + && hard_link_check(file, ndx, fname, statret, &sx,
2013 itemizing, code, HL_SKIP))
2015 if (stat_errno == ENOENT)
2016 @@ -1348,39 +1408,52 @@ static void recv_generator(char *fname,
2020 - if (append_mode && st.st_size > file->length)
2021 + if (append_mode && sx.st.st_size > file->length)
2024 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
2026 else if (fnamecmp_type == FNAMECMP_FUZZY)
2028 - else if (unchanged_file(fnamecmp, file, &st)) {
2029 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
2031 do_unlink(partialptr);
2032 handle_partial_dir(partialptr, PDIR_DELETE);
2035 - itemize(file, ndx, real_ret, &real_st,
2036 +#ifdef SUPPORT_ACLS
2037 + if (preserve_acls && real_ret == 0)
2038 + get_acl(fnamecmp, &real_sx);
2040 + itemize(file, ndx, real_ret, &real_sx,
2042 +#ifdef SUPPORT_ACLS
2043 + if (preserve_acls) {
2044 + if (fnamecmp_type == FNAMECMP_FNAME) {
2045 + sx.acc_acl = real_sx.acc_acl;
2046 + sx.def_acl = real_sx.def_acl;
2048 + free_acl(&real_sx);
2052 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
2053 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
2054 if (preserve_hard_links && file->link_u.links)
2055 hard_link_cluster(file, ndx, itemizing, code);
2056 if (remove_source_files != 1)
2059 return_with_success:
2062 SIVAL(numbuf, 0, ndx);
2063 send_msg(MSG_SUCCESS, numbuf, 4);
2072 + sx.st = partial_st;
2073 fnamecmp = partialptr;
2074 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2076 @@ -1404,17 +1477,21 @@ static void recv_generator(char *fname,
2078 /* pretend the file didn't exist */
2079 if (preserve_hard_links && file->link_u.links
2080 - && hard_link_check(file, ndx, fname, statret, &st,
2081 + && hard_link_check(file, ndx, fname, statret, &sx,
2082 itemizing, code, HL_SKIP))
2085 statret = real_ret = -1;
2086 +#ifdef SUPPORT_ACLS
2087 + if (preserve_acls && ACL_READY(sx))
2093 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2094 if (!(backupptr = get_backup_name(fname))) {
2099 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2101 @@ -1425,7 +1502,7 @@ static void recv_generator(char *fname,
2102 full_fname(backupptr));
2108 if ((f_copy = do_open(backupptr,
2109 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2110 @@ -1433,14 +1510,14 @@ static void recv_generator(char *fname,
2111 full_fname(backupptr));
2117 fnamecmp_type = FNAMECMP_BACKUP;
2121 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2122 - fnamecmp, (double)st.st_size);
2123 + fnamecmp, (double)sx.st.st_size);
2127 @@ -1458,24 +1535,32 @@ static void recv_generator(char *fname,
2128 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2129 if (fnamecmp_type == FNAMECMP_FUZZY)
2130 iflags |= ITEM_XNAME_FOLLOWS;
2131 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2132 +#ifdef SUPPORT_ACLS
2133 + if (preserve_acls && real_ret == 0)
2134 + get_acl(fnamecmp, &real_sx);
2136 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2137 fuzzy_file ? fuzzy_file->basename : NULL);
2138 +#ifdef SUPPORT_ACLS
2139 + if (preserve_acls)
2140 + free_acl(&real_sx);
2145 if (preserve_hard_links && file->link_u.links)
2146 hard_link_cluster(file, ndx, itemizing, code);
2154 if (statret != 0 || whole_file) {
2155 write_sum_head(f_out, NULL);
2160 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2161 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2165 @@ -1488,6 +1573,13 @@ static void recv_generator(char *fname,
2171 +#ifdef SUPPORT_ACLS
2172 + if (preserve_acls)
2178 void generate_files(int f_out, struct file_list *flist, char *local_name)
2179 @@ -1547,6 +1639,8 @@ void generate_files(int f_out, struct fi
2180 * notice that and let us know via the redo pipe (or its closing). */
2183 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2185 for (i = 0; i < flist->count; i++) {
2186 struct file_struct *file = flist->files[i];
2192 extern int do_xfers;
2193 extern int link_dest;
2194 +extern int preserve_acls;
2195 extern int make_backups;
2196 extern int remove_source_files;
2197 extern int stdout_format_has_i;
2198 @@ -146,15 +147,19 @@ void init_hard_links(void)
2200 #ifdef SUPPORT_HARD_LINKS
2201 static int maybe_hard_link(struct file_struct *file, int ndx,
2202 - char *fname, int statret, STRUCT_STAT *st,
2203 + char *fname, int statret, statx *sxp,
2204 char *toname, STRUCT_STAT *to_st,
2205 int itemizing, enum logcode code)
2208 - if (st->st_dev == to_st->st_dev
2209 - && st->st_ino == to_st->st_ino) {
2210 + if (sxp->st.st_dev == to_st->st_dev
2211 + && sxp->st.st_ino == to_st->st_ino) {
2213 - itemize(file, ndx, statret, st,
2214 +#ifdef SUPPORT_ACLS
2215 + if (preserve_acls && !ACL_READY(*sxp))
2216 + get_acl(fname, sxp);
2218 + itemize(file, ndx, statret, sxp,
2219 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2222 @@ -169,13 +174,13 @@ static int maybe_hard_link(struct file_s
2226 - return hard_link_one(file, ndx, fname, statret, st, toname,
2227 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2228 0, itemizing, code);
2232 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2233 - int statret, STRUCT_STAT *st, int itemizing,
2234 + int statret, statx *sxp, int itemizing,
2235 enum logcode code, int skip)
2237 #ifdef SUPPORT_HARD_LINKS
2238 @@ -216,7 +221,7 @@ int hard_link_check(struct file_struct *
2239 || st2.st_ino != st3.st_ino)
2244 if (verbose < 2 || !stdout_format_has_i) {
2247 @@ -226,12 +231,16 @@ int hard_link_check(struct file_struct *
2248 if (!unchanged_file(cmpbuf, file, &st3))
2252 - if (unchanged_attrs(file, &st3))
2254 +#ifdef SUPPORT_ACLS
2255 + if (preserve_acls)
2256 + get_acl(cmpbuf, sxp);
2258 + if (unchanged_attrs(file, sxp))
2260 } while (basis_dir[++j] != NULL);
2262 - maybe_hard_link(file, ndx, fname, statret, st,
2263 + maybe_hard_link(file, ndx, fname, statret, sxp,
2264 toname, &st2, itemizing, code);
2265 if (remove_source_files == 1 && do_xfers) {
2267 @@ -249,7 +258,7 @@ int hard_link_check(struct file_struct *
2269 #ifdef SUPPORT_HARD_LINKS
2270 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2271 - int statret, STRUCT_STAT *st, char *toname, int terse,
2272 + int statret, statx *sxp, char *toname, int terse,
2273 int itemizing, enum logcode code)
2275 if (do_link(toname, fname)) {
2276 @@ -265,7 +274,11 @@ int hard_link_one(struct file_struct *fi
2280 - itemize(file, ndx, statret, st,
2281 +#ifdef SUPPORT_ACLS
2282 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2283 + get_acl(fname, sxp);
2285 + itemize(file, ndx, statret, sxp,
2286 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2287 terse ? "" : toname);
2289 @@ -282,11 +295,12 @@ void hard_link_cluster(struct file_struc
2290 #ifdef SUPPORT_HARD_LINKS
2291 char hlink1[MAXPATHLEN];
2293 - STRUCT_STAT st1, st2;
2296 int statret, ndx = master;
2298 file->F_HLINDEX = FINISHED_LINK;
2299 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2300 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2302 if (!(file->flags & FLAG_HLINK_TOL)) {
2303 while (!(file->flags & FLAG_HLINK_EOL)) {
2304 @@ -300,9 +314,13 @@ void hard_link_cluster(struct file_struc
2305 if (file->F_HLINDEX != SKIPPED_LINK)
2307 hlink2 = f_name(file, NULL);
2308 - statret = link_stat(hlink2, &st2, 0);
2309 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2310 - hlink1, &st1, itemizing, code);
2311 + statret = link_stat(hlink2, &sx.st, 0);
2312 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2313 + hlink1, &st, itemizing, code);
2314 +#ifdef SUPPORT_ACLS
2315 + if (preserve_acls)
2318 if (remove_source_files == 1 && do_xfers) {
2320 SIVAL(numbuf, 0, ndx);
2321 --- old/lib/sysacls.c
2322 +++ new/lib/sysacls.c
2325 + Unix SMB/CIFS implementation.
2326 + Samba system utilities for ACL support.
2327 + Copyright (C) Jeremy Allison 2000.
2329 + This program is free software; you can redistribute it and/or modify
2330 + it under the terms of the GNU General Public License as published by
2331 + the Free Software Foundation; either version 2 of the License, or
2332 + (at your option) any later version.
2334 + This program is distributed in the hope that it will be useful,
2335 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2336 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2337 + GNU General Public License for more details.
2339 + You should have received a copy of the GNU General Public License
2340 + along with this program; if not, write to the Free Software
2341 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2345 +#include "sysacls.h" /****** ADDED ******/
2347 +#ifdef SUPPORT_ACLS
2349 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2355 +void SAFE_FREE(void *mem)
2361 +char *uidtoname(uid_t uid)
2363 + static char idbuf[12];
2364 + struct passwd *pw;
2366 + if ((pw = getpwuid(uid)) == NULL) {
2367 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2370 + return pw->pw_name;
2372 +/****** EXTRAS -- END ******/
2375 + This file wraps all differing system ACL interfaces into a consistent
2376 + one based on the POSIX interface. It also returns the correct errors
2377 + for older UNIX systems that don't support ACLs.
2379 + The interfaces that each ACL implementation must support are as follows :
2381 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2382 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2383 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2384 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2385 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2386 + SMB_ACL_T sys_acl_get_fd(int fd)
2387 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2388 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2389 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2390 + SMB_ACL_T sys_acl_init( int count)
2391 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2392 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2393 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2394 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2395 + int sys_acl_valid( SMB_ACL_T theacl )
2396 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2397 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2398 + int sys_acl_delete_def_file(const char *path)
2400 + This next one is not POSIX complient - but we *have* to have it !
2401 + More POSIX braindamage.
2403 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2405 + The generic POSIX free is the following call. We split this into
2406 + several different free functions as we may need to add tag info
2407 + to structures when emulating the POSIX interface.
2409 + int sys_acl_free( void *obj_p)
2411 + The calls we actually use are :
2413 + int sys_acl_free_text(char *text) - free acl_to_text
2414 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2415 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2419 +#if defined(HAVE_POSIX_ACLS)
2421 +/* Identity mapping - easy. */
2423 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2425 + return acl_get_entry( the_acl, entry_id, entry_p);
2428 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2430 + return acl_get_tag_type( entry_d, tag_type_p);
2433 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2435 + return acl_get_permset( entry_d, permset_p);
2438 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2440 + return acl_get_qualifier( entry_d);
2443 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2445 + return acl_get_file( path_p, type);
2448 +SMB_ACL_T sys_acl_get_fd(int fd)
2450 + return acl_get_fd(fd);
2453 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2455 + return acl_clear_perms(permset);
2458 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2460 + return acl_add_perm(permset, perm);
2463 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2465 +#if defined(HAVE_ACL_GET_PERM_NP)
2467 + * Required for TrustedBSD-based ACL implementations where
2468 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2471 + return acl_get_perm_np(permset, perm);
2473 + return acl_get_perm(permset, perm);
2477 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2479 + return acl_to_text( the_acl, plen);
2482 +SMB_ACL_T sys_acl_init( int count)
2484 + return acl_init(count);
2487 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2489 + return acl_create_entry(pacl, pentry);
2492 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2494 + return acl_set_tag_type(entry, tagtype);
2497 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2499 + return acl_set_qualifier(entry, qual);
2502 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2504 + return acl_set_permset(entry, permset);
2507 +int sys_acl_valid( SMB_ACL_T theacl )
2509 + return acl_valid(theacl);
2512 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2514 + return acl_set_file(name, acltype, theacl);
2517 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2519 + return acl_set_fd(fd, theacl);
2522 +int sys_acl_delete_def_file(const char *name)
2524 + return acl_delete_def_file(name);
2527 +int sys_acl_free_text(char *text)
2529 + return acl_free(text);
2532 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2534 + return acl_free(the_acl);
2537 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2539 + return acl_free(qual);
2542 +#elif defined(HAVE_TRU64_ACLS)
2544 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2545 + * is based on Draft 13 of the POSIX spec which is
2546 + * slightly different from the Draft 16 interface.
2548 + * Also, some of the permset manipulation functions
2549 + * such as acl_clear_perm() and acl_add_perm() appear
2550 + * to be broken on Tru64 so we have to manipulate
2551 + * the permission bits in the permset directly.
2553 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2555 + SMB_ACL_ENTRY_T entry;
2557 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2562 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2567 + return errno ? -1 : 0;
2570 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2572 + return acl_get_tag_type( entry_d, tag_type_p);
2575 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2577 + return acl_get_permset( entry_d, permset_p);
2580 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2582 + return acl_get_qualifier( entry_d);
2585 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2587 + return acl_get_file((char *)path_p, type);
2590 +SMB_ACL_T sys_acl_get_fd(int fd)
2592 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2595 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2597 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2602 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2604 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2609 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2614 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2616 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2619 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2621 + return acl_to_text( the_acl, plen);
2624 +SMB_ACL_T sys_acl_init( int count)
2626 + return acl_init(count);
2629 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2631 + SMB_ACL_ENTRY_T entry;
2633 + if ((entry = acl_create_entry(pacl)) == NULL) {
2641 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2643 + return acl_set_tag_type(entry, tagtype);
2646 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2648 + return acl_set_qualifier(entry, qual);
2651 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2653 + return acl_set_permset(entry, permset);
2656 +int sys_acl_valid( SMB_ACL_T theacl )
2658 + acl_entry_t entry;
2660 + return acl_valid(theacl, &entry);
2663 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2665 + return acl_set_file((char *)name, acltype, theacl);
2668 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2670 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2673 +int sys_acl_delete_def_file(const char *name)
2675 + return acl_delete_def_file((char *)name);
2678 +int sys_acl_free_text(char *text)
2681 + * (void) cast and explicit return 0 are for DEC UNIX
2682 + * which just #defines acl_free_text() to be free()
2684 + (void) acl_free_text(text);
2688 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2690 + return acl_free(the_acl);
2693 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2695 + return acl_free_qualifier(qual, tagtype);
2698 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2701 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2702 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2706 + * Note that while this code implements sufficient functionality
2707 + * to support the sys_acl_* interfaces it does not provide all
2708 + * of the semantics of the POSIX ACL interfaces.
2710 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2711 + * from a call to sys_acl_get_entry() should not be assumed to be
2712 + * valid after calling any of the following functions, which may
2713 + * reorder the entries in the ACL.
2716 + * sys_acl_set_file()
2717 + * sys_acl_set_fd()
2721 + * The only difference between Solaris and UnixWare / OpenUNIX is
2722 + * that the #defines for the ACL operations have different names
2724 +#if defined(HAVE_UNIXWARE_ACLS)
2726 +#define SETACL ACL_SET
2727 +#define GETACL ACL_GET
2728 +#define GETACLCNT ACL_CNT
2733 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2735 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2740 + if (entry_p == NULL) {
2745 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2749 + if (acl_d->next < 0) {
2754 + if (acl_d->next >= acl_d->count) {
2758 + *entry_p = &acl_d->acl[acl_d->next++];
2763 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2765 + *type_p = entry_d->a_type;
2770 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2772 + *permset_p = &entry_d->a_perm;
2777 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2779 + if (entry_d->a_type != SMB_ACL_USER
2780 + && entry_d->a_type != SMB_ACL_GROUP) {
2785 + return &entry_d->a_id;
2789 + * There is no way of knowing what size the ACL returned by
2790 + * GETACL will be unless you first call GETACLCNT which means
2791 + * making an additional system call.
2793 + * In the hope of avoiding the cost of the additional system
2794 + * call in most cases, we initially allocate enough space for
2795 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2796 + * be too small then we use GETACLCNT to find out the actual
2797 + * size, reallocate the ACL buffer, and then call GETACL again.
2800 +#define INITIAL_ACL_SIZE 16
2802 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2805 + int count; /* # of ACL entries allocated */
2806 + int naccess; /* # of access ACL entries */
2807 + int ndefault; /* # of default ACL entries */
2809 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2814 + count = INITIAL_ACL_SIZE;
2815 + if ((acl_d = sys_acl_init(count)) == NULL) {
2820 + * If there isn't enough space for the ACL entries we use
2821 + * GETACLCNT to determine the actual number of ACL entries
2822 + * reallocate and try again. This is in a loop because it
2823 + * is possible that someone else could modify the ACL and
2824 + * increase the number of entries between the call to
2825 + * GETACLCNT and the call to GETACL.
2827 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2828 + && errno == ENOSPC) {
2830 + sys_acl_free_acl(acl_d);
2832 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2836 + if ((acl_d = sys_acl_init(count)) == NULL) {
2842 + sys_acl_free_acl(acl_d);
2847 + * calculate the number of access and default ACL entries
2849 + * Note: we assume that the acl() system call returned a
2850 + * well formed ACL which is sorted so that all of the
2851 + * access ACL entries preceed any default ACL entries
2853 + for (naccess = 0; naccess < count; naccess++) {
2854 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2857 + ndefault = count - naccess;
2860 + * if the caller wants the default ACL we have to copy
2861 + * the entries down to the start of the acl[] buffer
2862 + * and mask out the ACL_DEFAULT flag from the type field
2864 + if (type == SMB_ACL_TYPE_DEFAULT) {
2867 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2868 + acl_d->acl[i] = acl_d->acl[j];
2869 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2872 + acl_d->count = ndefault;
2874 + acl_d->count = naccess;
2880 +SMB_ACL_T sys_acl_get_fd(int fd)
2883 + int count; /* # of ACL entries allocated */
2884 + int naccess; /* # of access ACL entries */
2886 + count = INITIAL_ACL_SIZE;
2887 + if ((acl_d = sys_acl_init(count)) == NULL) {
2891 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2892 + && errno == ENOSPC) {
2894 + sys_acl_free_acl(acl_d);
2896 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2900 + if ((acl_d = sys_acl_init(count)) == NULL) {
2906 + sys_acl_free_acl(acl_d);
2911 + * calculate the number of access ACL entries
2913 + for (naccess = 0; naccess < count; naccess++) {
2914 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2918 + acl_d->count = naccess;
2923 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2930 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2932 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2933 + && perm != SMB_ACL_EXECUTE) {
2938 + if (permset_d == NULL) {
2943 + *permset_d |= perm;
2948 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2950 + return *permset_d & perm;
2953 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2960 + * use an initial estimate of 20 bytes per ACL entry
2961 + * when allocating memory for the text representation
2965 + maxlen = 20 * acl_d->count;
2966 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2971 + for (i = 0; i < acl_d->count; i++) {
2972 + struct acl *ap = &acl_d->acl[i];
2981 + switch (ap->a_type) {
2983 + * for debugging purposes it's probably more
2984 + * useful to dump unknown tag types rather
2985 + * than just returning an error
2988 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2991 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2996 + case SMB_ACL_USER:
2997 + id = uidtoname(ap->a_id);
2998 + case SMB_ACL_USER_OBJ:
3002 + case SMB_ACL_GROUP:
3003 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3004 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3010 + case SMB_ACL_GROUP_OBJ:
3014 + case SMB_ACL_OTHER:
3018 + case SMB_ACL_MASK:
3024 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3025 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3026 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3029 + /* <tag> : <qualifier> : rwx \n \0 */
3030 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3033 + * If this entry would overflow the buffer
3034 + * allocate enough additional memory for this
3035 + * entry and an estimate of another 20 bytes
3036 + * for each entry still to be processed
3038 + if ((len + nbytes) > maxlen) {
3039 + char *oldtext = text;
3041 + maxlen += nbytes + 20 * (acl_d->count - i);
3043 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3044 + SAFE_FREE(oldtext);
3050 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3051 + len += nbytes - 1;
3060 +SMB_ACL_T sys_acl_init(int count)
3070 + * note that since the definition of the structure pointed
3071 + * to by the SMB_ACL_T includes the first element of the
3072 + * acl[] array, this actually allocates an ACL with room
3073 + * for (count+1) entries
3075 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3080 + a->size = count + 1;
3088 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3091 + SMB_ACL_ENTRY_T entry_d;
3093 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3098 + if (acl_d->count >= acl_d->size) {
3103 + entry_d = &acl_d->acl[acl_d->count++];
3104 + entry_d->a_type = 0;
3105 + entry_d->a_id = -1;
3106 + entry_d->a_perm = 0;
3107 + *entry_p = entry_d;
3112 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3114 + switch (tag_type) {
3115 + case SMB_ACL_USER:
3116 + case SMB_ACL_USER_OBJ:
3117 + case SMB_ACL_GROUP:
3118 + case SMB_ACL_GROUP_OBJ:
3119 + case SMB_ACL_OTHER:
3120 + case SMB_ACL_MASK:
3121 + entry_d->a_type = tag_type;
3131 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3133 + if (entry_d->a_type != SMB_ACL_GROUP
3134 + && entry_d->a_type != SMB_ACL_USER) {
3139 + entry_d->a_id = *((id_t *)qual_p);
3144 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3146 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3150 + entry_d->a_perm = *permset_d;
3156 + * sort the ACL and check it for validity
3158 + * if it's a minimal ACL with only 4 entries then we
3159 + * need to recalculate the mask permissions to make
3160 + * sure that they are the same as the GROUP_OBJ
3161 + * permissions as required by the UnixWare acl() system call.
3163 + * (note: since POSIX allows minimal ACLs which only contain
3164 + * 3 entries - ie there is no mask entry - we should, in theory,
3165 + * check for this and add a mask entry if necessary - however
3166 + * we "know" that the caller of this interface always specifies
3167 + * a mask so, in practice "this never happens" (tm) - if it *does*
3168 + * happen aclsort() will fail and return an error and someone will
3169 + * have to fix it ...)
3172 +static int acl_sort(SMB_ACL_T acl_d)
3174 + int fixmask = (acl_d->count <= 4);
3176 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3183 +int sys_acl_valid(SMB_ACL_T acl_d)
3185 + return acl_sort(acl_d);
3188 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3191 + struct acl *acl_p;
3193 + struct acl *acl_buf = NULL;
3196 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3201 + if (acl_sort(acl_d) != 0) {
3205 + acl_p = &acl_d->acl[0];
3206 + acl_count = acl_d->count;
3209 + * if it's a directory there is extra work to do
3210 + * since the acl() system call will replace both
3211 + * the access ACLs and the default ACLs (if any)
3213 + if (stat(name, &s) != 0) {
3216 + if (S_ISDIR(s.st_mode)) {
3217 + SMB_ACL_T acc_acl;
3218 + SMB_ACL_T def_acl;
3219 + SMB_ACL_T tmp_acl;
3222 + if (type == SMB_ACL_TYPE_ACCESS) {
3224 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3228 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3231 + if (tmp_acl == NULL) {
3236 + * allocate a temporary buffer for the complete ACL
3238 + acl_count = acc_acl->count + def_acl->count;
3239 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3241 + if (acl_buf == NULL) {
3242 + sys_acl_free_acl(tmp_acl);
3248 + * copy the access control and default entries into the buffer
3250 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3251 + acc_acl->count * sizeof(acl_buf[0]));
3253 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3254 + def_acl->count * sizeof(acl_buf[0]));
3257 + * set the ACL_DEFAULT flag on the default entries
3259 + for (i = acc_acl->count; i < acl_count; i++) {
3260 + acl_buf[i].a_type |= ACL_DEFAULT;
3263 + sys_acl_free_acl(tmp_acl);
3265 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3270 + ret = acl(name, SETACL, acl_count, acl_p);
3272 + SAFE_FREE(acl_buf);
3277 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3279 + if (acl_sort(acl_d) != 0) {
3283 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3286 +int sys_acl_delete_def_file(const char *path)
3292 + * fetching the access ACL and rewriting it has
3293 + * the effect of deleting the default ACL
3295 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3299 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3301 + sys_acl_free_acl(acl_d);
3306 +int sys_acl_free_text(char *text)
3312 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3318 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3323 +#elif defined(HAVE_HPUX_ACLS)
3327 + * Based on the Solaris/SCO code - with modifications.
3331 + * Note that while this code implements sufficient functionality
3332 + * to support the sys_acl_* interfaces it does not provide all
3333 + * of the semantics of the POSIX ACL interfaces.
3335 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3336 + * from a call to sys_acl_get_entry() should not be assumed to be
3337 + * valid after calling any of the following functions, which may
3338 + * reorder the entries in the ACL.
3341 + * sys_acl_set_file()
3342 + * sys_acl_set_fd()
3345 +/* This checks if the POSIX ACL system call is defined */
3346 +/* which basically corresponds to whether JFS 3.3 or */
3347 +/* higher is installed. If acl() was called when it */
3348 +/* isn't defined, it causes the process to core dump */
3349 +/* so it is important to check this and avoid acl() */
3350 +/* calls if it isn't there. */
3352 +static BOOL hpux_acl_call_presence(void)
3355 + shl_t handle = NULL;
3358 + static BOOL already_checked=0;
3360 + if(already_checked)
3364 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3366 + if(ret_val != 0) {
3367 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3368 + ret_val, errno, strerror(errno)));
3369 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3373 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3375 + already_checked = True;
3379 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3381 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3386 + if (entry_p == NULL) {
3391 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3395 + if (acl_d->next < 0) {
3400 + if (acl_d->next >= acl_d->count) {
3404 + *entry_p = &acl_d->acl[acl_d->next++];
3409 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3411 + *type_p = entry_d->a_type;
3416 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3418 + *permset_p = &entry_d->a_perm;
3423 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3425 + if (entry_d->a_type != SMB_ACL_USER
3426 + && entry_d->a_type != SMB_ACL_GROUP) {
3431 + return &entry_d->a_id;
3435 + * There is no way of knowing what size the ACL returned by
3436 + * ACL_GET will be unless you first call ACL_CNT which means
3437 + * making an additional system call.
3439 + * In the hope of avoiding the cost of the additional system
3440 + * call in most cases, we initially allocate enough space for
3441 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3442 + * be too small then we use ACL_CNT to find out the actual
3443 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3446 +#define INITIAL_ACL_SIZE 16
3448 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3451 + int count; /* # of ACL entries allocated */
3452 + int naccess; /* # of access ACL entries */
3453 + int ndefault; /* # of default ACL entries */
3455 + if(hpux_acl_call_presence() == False) {
3456 + /* Looks like we don't have the acl() system call on HPUX.
3457 + * May be the system doesn't have the latest version of JFS.
3462 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3467 + count = INITIAL_ACL_SIZE;
3468 + if ((acl_d = sys_acl_init(count)) == NULL) {
3473 + * If there isn't enough space for the ACL entries we use
3474 + * ACL_CNT to determine the actual number of ACL entries
3475 + * reallocate and try again. This is in a loop because it
3476 + * is possible that someone else could modify the ACL and
3477 + * increase the number of entries between the call to
3478 + * ACL_CNT and the call to ACL_GET.
3480 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3482 + sys_acl_free_acl(acl_d);
3484 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3488 + if ((acl_d = sys_acl_init(count)) == NULL) {
3494 + sys_acl_free_acl(acl_d);
3499 + * calculate the number of access and default ACL entries
3501 + * Note: we assume that the acl() system call returned a
3502 + * well formed ACL which is sorted so that all of the
3503 + * access ACL entries preceed any default ACL entries
3505 + for (naccess = 0; naccess < count; naccess++) {
3506 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3509 + ndefault = count - naccess;
3512 + * if the caller wants the default ACL we have to copy
3513 + * the entries down to the start of the acl[] buffer
3514 + * and mask out the ACL_DEFAULT flag from the type field
3516 + if (type == SMB_ACL_TYPE_DEFAULT) {
3519 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3520 + acl_d->acl[i] = acl_d->acl[j];
3521 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3524 + acl_d->count = ndefault;
3526 + acl_d->count = naccess;
3532 +SMB_ACL_T sys_acl_get_fd(int fd)
3535 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3538 + files_struct *fsp = file_find_fd(fd);
3540 + if (fsp == NULL) {
3546 + * We know we're in the same conn context. So we
3547 + * can use the relative path.
3550 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3553 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3560 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3562 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3563 + && perm != SMB_ACL_EXECUTE) {
3568 + if (permset_d == NULL) {
3573 + *permset_d |= perm;
3578 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3580 + return *permset_d & perm;
3583 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3590 + * use an initial estimate of 20 bytes per ACL entry
3591 + * when allocating memory for the text representation
3595 + maxlen = 20 * acl_d->count;
3596 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3601 + for (i = 0; i < acl_d->count; i++) {
3602 + struct acl *ap = &acl_d->acl[i];
3611 + switch (ap->a_type) {
3613 + * for debugging purposes it's probably more
3614 + * useful to dump unknown tag types rather
3615 + * than just returning an error
3618 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3621 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3626 + case SMB_ACL_USER:
3627 + id = uidtoname(ap->a_id);
3628 + case SMB_ACL_USER_OBJ:
3632 + case SMB_ACL_GROUP:
3633 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3634 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3640 + case SMB_ACL_GROUP_OBJ:
3644 + case SMB_ACL_OTHER:
3648 + case SMB_ACL_MASK:
3654 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3655 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3656 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3659 + /* <tag> : <qualifier> : rwx \n \0 */
3660 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3663 + * If this entry would overflow the buffer
3664 + * allocate enough additional memory for this
3665 + * entry and an estimate of another 20 bytes
3666 + * for each entry still to be processed
3668 + if ((len + nbytes) > maxlen) {
3669 + char *oldtext = text;
3671 + maxlen += nbytes + 20 * (acl_d->count - i);
3673 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3680 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3681 + len += nbytes - 1;
3690 +SMB_ACL_T sys_acl_init(int count)
3700 + * note that since the definition of the structure pointed
3701 + * to by the SMB_ACL_T includes the first element of the
3702 + * acl[] array, this actually allocates an ACL with room
3703 + * for (count+1) entries
3705 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3710 + a->size = count + 1;
3718 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3721 + SMB_ACL_ENTRY_T entry_d;
3723 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3728 + if (acl_d->count >= acl_d->size) {
3733 + entry_d = &acl_d->acl[acl_d->count++];
3734 + entry_d->a_type = 0;
3735 + entry_d->a_id = -1;
3736 + entry_d->a_perm = 0;
3737 + *entry_p = entry_d;
3742 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3744 + switch (tag_type) {
3745 + case SMB_ACL_USER:
3746 + case SMB_ACL_USER_OBJ:
3747 + case SMB_ACL_GROUP:
3748 + case SMB_ACL_GROUP_OBJ:
3749 + case SMB_ACL_OTHER:
3750 + case SMB_ACL_MASK:
3751 + entry_d->a_type = tag_type;
3761 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3763 + if (entry_d->a_type != SMB_ACL_GROUP
3764 + && entry_d->a_type != SMB_ACL_USER) {
3769 + entry_d->a_id = *((id_t *)qual_p);
3774 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3776 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3780 + entry_d->a_perm = *permset_d;
3785 +/* Structure to capture the count for each type of ACE. */
3787 +struct hpux_acl_types {
3791 + int n_def_user_obj;
3796 + int n_def_group_obj;
3800 + int n_def_other_obj;
3803 + int n_def_class_obj;
3805 + int n_illegal_obj;
3809 + * Counts the different number of objects in a given array of ACL
3813 + * acl_count - Count of ACLs in the array of ACL strucutres.
3814 + * aclp - Array of ACL structures.
3815 + * acl_type_count - Pointer to acl_types structure. Should already be
3819 + * acl_type_count - This structure is filled up with counts of various
3823 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3827 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3829 + for(i=0;i<acl_count;i++) {
3830 + switch(aclp[i].a_type) {
3832 + acl_type_count->n_user++;
3835 + acl_type_count->n_user_obj++;
3837 + case DEF_USER_OBJ:
3838 + acl_type_count->n_def_user_obj++;
3841 + acl_type_count->n_group++;
3844 + acl_type_count->n_group_obj++;
3846 + case DEF_GROUP_OBJ:
3847 + acl_type_count->n_def_group_obj++;
3850 + acl_type_count->n_other_obj++;
3852 + case DEF_OTHER_OBJ:
3853 + acl_type_count->n_def_other_obj++;
3856 + acl_type_count->n_class_obj++;
3858 + case DEF_CLASS_OBJ:
3859 + acl_type_count->n_def_class_obj++;
3862 + acl_type_count->n_def_user++;
3865 + acl_type_count->n_def_group++;
3868 + acl_type_count->n_illegal_obj++;
3874 +/* swap_acl_entries: Swaps two ACL entries.
3876 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3879 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3881 + struct acl temp_acl;
3883 + temp_acl.a_type = aclp0->a_type;
3884 + temp_acl.a_id = aclp0->a_id;
3885 + temp_acl.a_perm = aclp0->a_perm;
3887 + aclp0->a_type = aclp1->a_type;
3888 + aclp0->a_id = aclp1->a_id;
3889 + aclp0->a_perm = aclp1->a_perm;
3891 + aclp1->a_type = temp_acl.a_type;
3892 + aclp1->a_id = temp_acl.a_id;
3893 + aclp1->a_perm = temp_acl.a_perm;
3896 +/* prohibited_duplicate_type
3897 + * Identifies if given ACL type can have duplicate entries or
3900 + * Inputs: acl_type - ACL Type.
3906 + * True - If the ACL type matches any of the prohibited types.
3907 + * False - If the ACL type doesn't match any of the prohibited types.
3910 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3912 + switch(acl_type) {
3923 +/* get_needed_class_perm
3924 + * Returns the permissions of a ACL structure only if the ACL
3925 + * type matches one of the pre-determined types for computing
3926 + * CLASS_OBJ permissions.
3928 + * Inputs: aclp - Pointer to ACL structure.
3931 +static int hpux_get_needed_class_perm(struct acl *aclp)
3933 + switch(aclp->a_type) {
3937 + case DEF_USER_OBJ:
3939 + case DEF_GROUP_OBJ:
3941 + case DEF_CLASS_OBJ:
3942 + case DEF_OTHER_OBJ:
3943 + return aclp->a_perm;
3949 +/* acl_sort for HPUX.
3950 + * Sorts the array of ACL structures as per the description in
3951 + * aclsort man page. Refer to aclsort man page for more details
3955 + * acl_count - Count of ACLs in the array of ACL structures.
3956 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3958 + * aclp - Array of ACL structures.
3962 + * aclp - Sorted array of ACL structures.
3966 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3967 + * debug log in case of failure.
3970 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3972 +#if !defined(HAVE_HPUX_ACLSORT)
3974 + * The aclsort() system call is availabe on the latest HPUX General
3975 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3976 + * function. Because, we don't want to update to a new
3977 + * HPUX GR bundle just for aclsort() call.
3980 + struct hpux_acl_types acl_obj_count;
3981 + int n_class_obj_perm = 0;
3985 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3989 + if(aclp == NULL) {
3990 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3994 + /* Count different types of ACLs in the ACLs array */
3996 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3998 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3999 + * CLASS_OBJ and OTHER_OBJ
4002 + if( (acl_obj_count.n_user_obj != 1) ||
4003 + (acl_obj_count.n_group_obj != 1) ||
4004 + (acl_obj_count.n_class_obj != 1) ||
4005 + (acl_obj_count.n_other_obj != 1)
4007 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
4008 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
4012 + /* If any of the default objects are present, there should be only
4013 + * one of them each.
4016 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
4017 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
4018 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
4019 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
4023 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
4026 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
4027 + * same ACL type, sort by ACL id.
4029 + * I am using the trival kind of sorting method here because, performance isn't
4030 + * really effected by the ACLs feature. More over there aren't going to be more
4031 + * than 17 entries on HPUX.
4034 + for(i=0; i<acl_count;i++) {
4035 + for (j=i+1; j<acl_count; j++) {
4036 + if( aclp[i].a_type > aclp[j].a_type ) {
4037 + /* ACL entries out of order, swap them */
4039 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4041 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
4043 + /* ACL entries of same type, sort by id */
4045 + if(aclp[i].a_id > aclp[j].a_id) {
4046 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4047 + } else if (aclp[i].a_id == aclp[j].a_id) {
4048 + /* We have a duplicate entry. */
4049 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
4050 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
4051 + aclp[i].a_type, aclp[i].a_id));
4060 + /* set the class obj permissions to the computed one. */
4062 + int n_class_obj_index = -1;
4064 + for(i=0;i<acl_count;i++) {
4065 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
4067 + if(aclp[i].a_type == CLASS_OBJ)
4068 + n_class_obj_index = i;
4070 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
4075 + return aclsort(acl_count, calclass, aclp);
4080 + * sort the ACL and check it for validity
4082 + * if it's a minimal ACL with only 4 entries then we
4083 + * need to recalculate the mask permissions to make
4084 + * sure that they are the same as the GROUP_OBJ
4085 + * permissions as required by the UnixWare acl() system call.
4087 + * (note: since POSIX allows minimal ACLs which only contain
4088 + * 3 entries - ie there is no mask entry - we should, in theory,
4089 + * check for this and add a mask entry if necessary - however
4090 + * we "know" that the caller of this interface always specifies
4091 + * a mask so, in practice "this never happens" (tm) - if it *does*
4092 + * happen aclsort() will fail and return an error and someone will
4093 + * have to fix it ...)
4096 +static int acl_sort(SMB_ACL_T acl_d)
4098 + int fixmask = (acl_d->count <= 4);
4100 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4107 +int sys_acl_valid(SMB_ACL_T acl_d)
4109 + return acl_sort(acl_d);
4112 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4115 + struct acl *acl_p;
4117 + struct acl *acl_buf = NULL;
4120 + if(hpux_acl_call_presence() == False) {
4121 + /* Looks like we don't have the acl() system call on HPUX.
4122 + * May be the system doesn't have the latest version of JFS.
4128 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4133 + if (acl_sort(acl_d) != 0) {
4137 + acl_p = &acl_d->acl[0];
4138 + acl_count = acl_d->count;
4141 + * if it's a directory there is extra work to do
4142 + * since the acl() system call will replace both
4143 + * the access ACLs and the default ACLs (if any)
4145 + if (stat(name, &s) != 0) {
4148 + if (S_ISDIR(s.st_mode)) {
4149 + SMB_ACL_T acc_acl;
4150 + SMB_ACL_T def_acl;
4151 + SMB_ACL_T tmp_acl;
4154 + if (type == SMB_ACL_TYPE_ACCESS) {
4156 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4160 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4163 + if (tmp_acl == NULL) {
4168 + * allocate a temporary buffer for the complete ACL
4170 + acl_count = acc_acl->count + def_acl->count;
4171 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4173 + if (acl_buf == NULL) {
4174 + sys_acl_free_acl(tmp_acl);
4180 + * copy the access control and default entries into the buffer
4182 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4183 + acc_acl->count * sizeof(acl_buf[0]));
4185 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4186 + def_acl->count * sizeof(acl_buf[0]));
4189 + * set the ACL_DEFAULT flag on the default entries
4191 + for (i = acc_acl->count; i < acl_count; i++) {
4192 + acl_buf[i].a_type |= ACL_DEFAULT;
4195 + sys_acl_free_acl(tmp_acl);
4197 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4202 + ret = acl(name, ACL_SET, acl_count, acl_p);
4211 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4214 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4217 + files_struct *fsp = file_find_fd(fd);
4219 + if (fsp == NULL) {
4224 + if (acl_sort(acl_d) != 0) {
4229 + * We know we're in the same conn context. So we
4230 + * can use the relative path.
4233 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4236 +int sys_acl_delete_def_file(const char *path)
4242 + * fetching the access ACL and rewriting it has
4243 + * the effect of deleting the default ACL
4245 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4249 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4251 + sys_acl_free_acl(acl_d);
4256 +int sys_acl_free_text(char *text)
4262 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4268 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4273 +#elif defined(HAVE_IRIX_ACLS)
4275 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4277 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4282 + if (entry_p == NULL) {
4287 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4291 + if (acl_d->next < 0) {
4296 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4300 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4305 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4307 + *type_p = entry_d->ae_tag;
4312 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4314 + *permset_p = entry_d;
4319 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4321 + if (entry_d->ae_tag != SMB_ACL_USER
4322 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4327 + return &entry_d->ae_id;
4330 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4334 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4338 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4343 + a->freeaclp = True;
4347 +SMB_ACL_T sys_acl_get_fd(int fd)
4351 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4355 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4360 + a->freeaclp = True;
4364 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4366 + permset_d->ae_perm = 0;
4371 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4373 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4374 + && perm != SMB_ACL_EXECUTE) {
4379 + if (permset_d == NULL) {
4384 + permset_d->ae_perm |= perm;
4389 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4391 + return permset_d->ae_perm & perm;
4394 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4396 + return acl_to_text(acl_d->aclp, len_p);
4399 +SMB_ACL_T sys_acl_init(int count)
4408 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4414 + a->freeaclp = False;
4415 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4416 + a->aclp->acl_cnt = 0;
4422 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4425 + SMB_ACL_ENTRY_T entry_d;
4427 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4432 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4437 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4438 + entry_d->ae_tag = 0;
4439 + entry_d->ae_id = 0;
4440 + entry_d->ae_perm = 0;
4441 + *entry_p = entry_d;
4446 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4448 + switch (tag_type) {
4449 + case SMB_ACL_USER:
4450 + case SMB_ACL_USER_OBJ:
4451 + case SMB_ACL_GROUP:
4452 + case SMB_ACL_GROUP_OBJ:
4453 + case SMB_ACL_OTHER:
4454 + case SMB_ACL_MASK:
4455 + entry_d->ae_tag = tag_type;
4465 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4467 + if (entry_d->ae_tag != SMB_ACL_GROUP
4468 + && entry_d->ae_tag != SMB_ACL_USER) {
4473 + entry_d->ae_id = *((id_t *)qual_p);
4478 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4480 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4484 + entry_d->ae_perm = permset_d->ae_perm;
4489 +int sys_acl_valid(SMB_ACL_T acl_d)
4491 + return acl_valid(acl_d->aclp);
4494 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4496 + return acl_set_file(name, type, acl_d->aclp);
4499 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4501 + return acl_set_fd(fd, acl_d->aclp);
4504 +int sys_acl_delete_def_file(const char *name)
4506 + return acl_delete_def_file(name);
4509 +int sys_acl_free_text(char *text)
4511 + return acl_free(text);
4514 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4516 + if (acl_d->freeaclp) {
4517 + acl_free(acl_d->aclp);
4523 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4528 +#elif defined(HAVE_AIX_ACLS)
4530 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4532 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4534 + struct acl_entry_link *link;
4535 + struct new_acl_entry *entry;
4538 + DEBUG(10,("This is the count: %d\n",theacl->count));
4540 + /* Check if count was previously set to -1. *
4541 + * If it was, that means we reached the end *
4542 + * of the acl last time. */
4543 + if(theacl->count == -1)
4547 + /* To get to the next acl, traverse linked list until index *
4548 + * of acl matches the count we are keeping. This count is *
4549 + * incremented each time we return an acl entry. */
4551 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4552 + link = link->nextp;
4554 + entry = *entry_p = link->entryp;
4556 + DEBUG(10,("*entry_p is %d\n",entry_p));
4557 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4559 + /* Increment count */
4561 + if(link->nextp == NULL)
4562 + theacl->count = -1;
4567 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4569 + /* Initialize tag type */
4572 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4574 + /* Depending on what type of entry we have, *
4575 + * return tag type. */
4576 + switch(entry_d->ace_id->id_type) {
4578 + *tag_type_p = SMB_ACL_USER;
4581 + *tag_type_p = SMB_ACL_GROUP;
4584 + case SMB_ACL_USER_OBJ:
4585 + case SMB_ACL_GROUP_OBJ:
4586 + case SMB_ACL_OTHER:
4587 + *tag_type_p = entry_d->ace_id->id_type;
4597 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4599 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4600 + *permset_p = &entry_d->ace_access;
4601 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4602 + if(!(**permset_p & S_IXUSR) &&
4603 + !(**permset_p & S_IWUSR) &&
4604 + !(**permset_p & S_IRUSR) &&
4605 + (**permset_p != 0))
4608 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4612 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4614 + return(entry_d->ace_id->id_data);
4617 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4619 + struct acl *file_acl = (struct acl *)NULL;
4620 + struct acl_entry *acl_entry;
4621 + struct new_acl_entry *new_acl_entry;
4622 + struct ace_id *idp;
4623 + struct acl_entry_link *acl_entry_link;
4624 + struct acl_entry_link *acl_entry_link_head;
4629 + /* AIX has no DEFAULT */
4630 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4635 + /* Get the acl using statacl */
4637 + DEBUG(10,("Entering sys_acl_get_file\n"));
4638 + DEBUG(10,("path_p is %s\n",path_p));
4640 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4642 + if(file_acl == NULL) {
4644 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4648 + memset(file_acl,0,BUFSIZ);
4650 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4652 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4653 + SAFE_FREE(file_acl);
4657 + DEBUG(10,("Got facl and returned it\n"));
4659 + /* Point to the first acl entry in the acl */
4660 + acl_entry = file_acl->acl_ext;
4662 + /* Begin setting up the head of the linked list *
4663 + * that will be used for the storing the acl *
4664 + * in a way that is useful for the posix_acls.c *
4667 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4668 + if(acl_entry_link_head == NULL)
4671 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4672 + if(acl_entry_link->entryp == NULL) {
4673 + SAFE_FREE(file_acl);
4675 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4679 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4680 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4682 + /* Check if the extended acl bit is on. *
4683 + * If it isn't, do not show the *
4684 + * contents of the acl since AIX intends *
4685 + * the extended info to remain unused */
4687 + if(file_acl->acl_mode & S_IXACL){
4688 + /* while we are not pointing to the very end */
4689 + while(acl_entry < acl_last(file_acl)) {
4690 + /* before we malloc anything, make sure this is */
4691 + /* a valid acl entry and one that we want to map */
4692 + idp = id_nxt(acl_entry->ace_id);
4693 + if((acl_entry->ace_type == ACC_SPECIFY ||
4694 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4695 + acl_entry = acl_nxt(acl_entry);
4699 + idp = acl_entry->ace_id;
4701 + /* Check if this is the first entry in the linked list. *
4702 + * The first entry needs to keep prevp pointing to NULL *
4703 + * and already has entryp allocated. */
4705 + if(acl_entry_link_head->count != 0) {
4706 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4708 + if(acl_entry_link->nextp == NULL) {
4709 + SAFE_FREE(file_acl);
4711 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4715 + acl_entry_link->nextp->prevp = acl_entry_link;
4716 + acl_entry_link = acl_entry_link->nextp;
4717 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4718 + if(acl_entry_link->entryp == NULL) {
4719 + SAFE_FREE(file_acl);
4721 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4724 + acl_entry_link->nextp = NULL;
4727 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4729 + /* Don't really need this since all types are going *
4730 + * to be specified but, it's better than leaving it 0 */
4732 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4734 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4736 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4738 + /* The access in the acl entries must be left shifted by *
4739 + * three bites, because they will ultimately be compared *
4740 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4742 + switch(acl_entry->ace_type){
4745 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4746 + acl_entry_link->entryp->ace_access <<= 6;
4747 + acl_entry_link_head->count++;
4750 + /* Since there is no way to return a DENY acl entry *
4751 + * change to PERMIT and then shift. */
4752 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4753 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4754 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4755 + acl_entry_link->entryp->ace_access <<= 6;
4756 + acl_entry_link_head->count++;
4762 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4763 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4765 + acl_entry = acl_nxt(acl_entry);
4767 + } /* end of if enabled */
4769 + /* Since owner, group, other acl entries are not *
4770 + * part of the acl entries in an acl, they must *
4771 + * be dummied up to become part of the list. */
4773 + for( i = 1; i < 4; i++) {
4774 + DEBUG(10,("i is %d\n",i));
4775 + if(acl_entry_link_head->count != 0) {
4776 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4777 + if(acl_entry_link->nextp == NULL) {
4778 + SAFE_FREE(file_acl);
4780 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4784 + acl_entry_link->nextp->prevp = acl_entry_link;
4785 + acl_entry_link = acl_entry_link->nextp;
4786 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4787 + if(acl_entry_link->entryp == NULL) {
4788 + SAFE_FREE(file_acl);
4790 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4795 + acl_entry_link->nextp = NULL;
4797 + new_acl_entry = acl_entry_link->entryp;
4798 + idp = new_acl_entry->ace_id;
4800 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4801 + new_acl_entry->ace_type = ACC_PERMIT;
4802 + idp->id_len = sizeof(struct ace_id);
4803 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4804 + memset(idp->id_data,0,sizeof(uid_t));
4808 + new_acl_entry->ace_access = file_acl->g_access << 6;
4809 + idp->id_type = SMB_ACL_GROUP_OBJ;
4813 + new_acl_entry->ace_access = file_acl->o_access << 6;
4814 + idp->id_type = SMB_ACL_OTHER;
4818 + new_acl_entry->ace_access = file_acl->u_access << 6;
4819 + idp->id_type = SMB_ACL_USER_OBJ;
4827 + acl_entry_link_head->count++;
4828 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4831 + acl_entry_link_head->count = 0;
4832 + SAFE_FREE(file_acl);
4834 + return(acl_entry_link_head);
4837 +SMB_ACL_T sys_acl_get_fd(int fd)
4839 + struct acl *file_acl = (struct acl *)NULL;
4840 + struct acl_entry *acl_entry;
4841 + struct new_acl_entry *new_acl_entry;
4842 + struct ace_id *idp;
4843 + struct acl_entry_link *acl_entry_link;
4844 + struct acl_entry_link *acl_entry_link_head;
4849 + /* Get the acl using fstatacl */
4851 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4852 + DEBUG(10,("fd is %d\n",fd));
4853 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4855 + if(file_acl == NULL) {
4857 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4861 + memset(file_acl,0,BUFSIZ);
4863 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4865 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4866 + SAFE_FREE(file_acl);
4870 + DEBUG(10,("Got facl and returned it\n"));
4872 + /* Point to the first acl entry in the acl */
4874 + acl_entry = file_acl->acl_ext;
4875 + /* Begin setting up the head of the linked list *
4876 + * that will be used for the storing the acl *
4877 + * in a way that is useful for the posix_acls.c *
4880 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4881 + if(acl_entry_link_head == NULL){
4882 + SAFE_FREE(file_acl);
4886 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4888 + if(acl_entry_link->entryp == NULL) {
4890 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4891 + SAFE_FREE(file_acl);
4895 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4896 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4898 + /* Check if the extended acl bit is on. *
4899 + * If it isn't, do not show the *
4900 + * contents of the acl since AIX intends *
4901 + * the extended info to remain unused */
4903 + if(file_acl->acl_mode & S_IXACL){
4904 + /* while we are not pointing to the very end */
4905 + while(acl_entry < acl_last(file_acl)) {
4906 + /* before we malloc anything, make sure this is */
4907 + /* a valid acl entry and one that we want to map */
4909 + idp = id_nxt(acl_entry->ace_id);
4910 + if((acl_entry->ace_type == ACC_SPECIFY ||
4911 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4912 + acl_entry = acl_nxt(acl_entry);
4916 + idp = acl_entry->ace_id;
4918 + /* Check if this is the first entry in the linked list. *
4919 + * The first entry needs to keep prevp pointing to NULL *
4920 + * and already has entryp allocated. */
4922 + if(acl_entry_link_head->count != 0) {
4923 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4924 + if(acl_entry_link->nextp == NULL) {
4926 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4927 + SAFE_FREE(file_acl);
4930 + acl_entry_link->nextp->prevp = acl_entry_link;
4931 + acl_entry_link = acl_entry_link->nextp;
4932 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4933 + if(acl_entry_link->entryp == NULL) {
4935 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4936 + SAFE_FREE(file_acl);
4940 + acl_entry_link->nextp = NULL;
4943 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4945 + /* Don't really need this since all types are going *
4946 + * to be specified but, it's better than leaving it 0 */
4948 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4949 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4951 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4953 + /* The access in the acl entries must be left shifted by *
4954 + * three bites, because they will ultimately be compared *
4955 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4957 + switch(acl_entry->ace_type){
4960 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4961 + acl_entry_link->entryp->ace_access <<= 6;
4962 + acl_entry_link_head->count++;
4965 + /* Since there is no way to return a DENY acl entry *
4966 + * change to PERMIT and then shift. */
4967 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4968 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4969 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4970 + acl_entry_link->entryp->ace_access <<= 6;
4971 + acl_entry_link_head->count++;
4977 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4978 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4980 + acl_entry = acl_nxt(acl_entry);
4982 + } /* end of if enabled */
4984 + /* Since owner, group, other acl entries are not *
4985 + * part of the acl entries in an acl, they must *
4986 + * be dummied up to become part of the list. */
4988 + for( i = 1; i < 4; i++) {
4989 + DEBUG(10,("i is %d\n",i));
4990 + if(acl_entry_link_head->count != 0){
4991 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4992 + if(acl_entry_link->nextp == NULL) {
4994 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4995 + SAFE_FREE(file_acl);
4999 + acl_entry_link->nextp->prevp = acl_entry_link;
5000 + acl_entry_link = acl_entry_link->nextp;
5001 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
5003 + if(acl_entry_link->entryp == NULL) {
5004 + SAFE_FREE(file_acl);
5006 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
5011 + acl_entry_link->nextp = NULL;
5013 + new_acl_entry = acl_entry_link->entryp;
5014 + idp = new_acl_entry->ace_id;
5016 + new_acl_entry->ace_len = sizeof(struct acl_entry);
5017 + new_acl_entry->ace_type = ACC_PERMIT;
5018 + idp->id_len = sizeof(struct ace_id);
5019 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
5020 + memset(idp->id_data,0,sizeof(uid_t));
5024 + new_acl_entry->ace_access = file_acl->g_access << 6;
5025 + idp->id_type = SMB_ACL_GROUP_OBJ;
5029 + new_acl_entry->ace_access = file_acl->o_access << 6;
5030 + idp->id_type = SMB_ACL_OTHER;
5034 + new_acl_entry->ace_access = file_acl->u_access << 6;
5035 + idp->id_type = SMB_ACL_USER_OBJ;
5042 + acl_entry_link_head->count++;
5043 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
5046 + acl_entry_link_head->count = 0;
5047 + SAFE_FREE(file_acl);
5049 + return(acl_entry_link_head);
5052 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
5054 + *permset = *permset & ~0777;
5058 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5061 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
5065 + DEBUG(10,("This is the permset now: %d\n",*permset));
5069 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
5074 +SMB_ACL_T sys_acl_init( int count)
5076 + struct acl_entry_link *theacl = NULL;
5078 + DEBUG(10,("Entering sys_acl_init\n"));
5080 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5081 + if(theacl == NULL) {
5083 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5087 + theacl->count = 0;
5088 + theacl->nextp = NULL;
5089 + theacl->prevp = NULL;
5090 + theacl->entryp = NULL;
5091 + DEBUG(10,("Exiting sys_acl_init\n"));
5095 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5097 + struct acl_entry_link *theacl;
5098 + struct acl_entry_link *acl_entryp;
5099 + struct acl_entry_link *temp_entry;
5102 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5104 + theacl = acl_entryp = *pacl;
5106 + /* Get to the end of the acl before adding entry */
5108 + for(counting=0; counting < theacl->count; counting++){
5109 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5110 + temp_entry = acl_entryp;
5111 + acl_entryp = acl_entryp->nextp;
5114 + if(theacl->count != 0){
5115 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5116 + if(acl_entryp == NULL) {
5118 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5122 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5123 + acl_entryp->prevp = temp_entry;
5124 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5127 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5128 + if(*pentry == NULL) {
5130 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5134 + memset(*pentry,0,sizeof(struct new_acl_entry));
5135 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5136 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5137 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5138 + acl_entryp->nextp = NULL;
5140 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5144 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5146 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5147 + entry->ace_id->id_type = tagtype;
5148 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5149 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5152 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5154 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5155 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5156 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5160 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5162 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5163 + if(!(*permset & S_IXUSR) &&
5164 + !(*permset & S_IWUSR) &&
5165 + !(*permset & S_IRUSR) &&
5169 + entry->ace_access = *permset;
5170 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5171 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5175 +int sys_acl_valid( SMB_ACL_T theacl )
5178 + int group_obj = 0;
5179 + int other_obj = 0;
5180 + struct acl_entry_link *acl_entry;
5182 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5183 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5184 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5185 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5188 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5190 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5196 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5198 + struct acl_entry_link *acl_entry_link = NULL;
5199 + struct acl *file_acl = NULL;
5200 + struct acl *file_acl_temp = NULL;
5201 + struct acl_entry *acl_entry = NULL;
5202 + struct ace_id *ace_id = NULL;
5209 + DEBUG(10,("Entering sys_acl_set_file\n"));
5210 + DEBUG(10,("File name is %s\n",name));
5212 + /* AIX has no default ACL */
5213 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5216 + acl_length = BUFSIZ;
5217 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5219 + if(file_acl == NULL) {
5221 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5225 + memset(file_acl,0,BUFSIZ);
5227 + file_acl->acl_len = ACL_SIZ;
5228 + file_acl->acl_mode = S_IXACL;
5230 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5231 + acl_entry_link->entryp->ace_access >>= 6;
5232 + id_type = acl_entry_link->entryp->ace_id->id_type;
5235 + case SMB_ACL_USER_OBJ:
5236 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5238 + case SMB_ACL_GROUP_OBJ:
5239 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5241 + case SMB_ACL_OTHER:
5242 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5244 + case SMB_ACL_MASK:
5248 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5249 + acl_length += sizeof(struct acl_entry);
5250 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5251 + if(file_acl_temp == NULL) {
5252 + SAFE_FREE(file_acl);
5254 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5258 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5259 + SAFE_FREE(file_acl);
5260 + file_acl = file_acl_temp;
5263 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5264 + file_acl->acl_len += sizeof(struct acl_entry);
5265 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5266 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5268 + /* In order to use this, we'll need to wait until we can get denies */
5269 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5270 + acl_entry->ace_type = ACC_SPECIFY; */
5272 + acl_entry->ace_type = ACC_SPECIFY;
5274 + ace_id = acl_entry->ace_id;
5276 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5277 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5278 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5279 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5280 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5283 + rc = chacl(name,file_acl,file_acl->acl_len);
5284 + DEBUG(10,("errno is %d\n",errno));
5285 + DEBUG(10,("return code is %d\n",rc));
5286 + SAFE_FREE(file_acl);
5287 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5291 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5293 + struct acl_entry_link *acl_entry_link = NULL;
5294 + struct acl *file_acl = NULL;
5295 + struct acl *file_acl_temp = NULL;
5296 + struct acl_entry *acl_entry = NULL;
5297 + struct ace_id *ace_id = NULL;
5303 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5304 + acl_length = BUFSIZ;
5305 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5307 + if(file_acl == NULL) {
5309 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5313 + memset(file_acl,0,BUFSIZ);
5315 + file_acl->acl_len = ACL_SIZ;
5316 + file_acl->acl_mode = S_IXACL;
5318 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5319 + acl_entry_link->entryp->ace_access >>= 6;
5320 + id_type = acl_entry_link->entryp->ace_id->id_type;
5321 + DEBUG(10,("The id_type is %d\n",id_type));
5324 + case SMB_ACL_USER_OBJ:
5325 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5327 + case SMB_ACL_GROUP_OBJ:
5328 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5330 + case SMB_ACL_OTHER:
5331 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5333 + case SMB_ACL_MASK:
5337 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5338 + acl_length += sizeof(struct acl_entry);
5339 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5340 + if(file_acl_temp == NULL) {
5341 + SAFE_FREE(file_acl);
5343 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5347 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5348 + SAFE_FREE(file_acl);
5349 + file_acl = file_acl_temp;
5352 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5353 + file_acl->acl_len += sizeof(struct acl_entry);
5354 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5355 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5357 + /* In order to use this, we'll need to wait until we can get denies */
5358 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5359 + acl_entry->ace_type = ACC_SPECIFY; */
5361 + acl_entry->ace_type = ACC_SPECIFY;
5363 + ace_id = acl_entry->ace_id;
5365 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5366 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5367 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5368 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5369 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5372 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5373 + DEBUG(10,("errno is %d\n",errno));
5374 + DEBUG(10,("return code is %d\n",rc));
5375 + SAFE_FREE(file_acl);
5376 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5380 +int sys_acl_delete_def_file(const char *name)
5382 + /* AIX has no default ACL */
5386 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5388 + return(*permset & perm);
5391 +int sys_acl_free_text(char *text)
5396 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5398 + struct acl_entry_link *acl_entry_link;
5400 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5401 + SAFE_FREE(acl_entry_link->prevp->entryp);
5402 + SAFE_FREE(acl_entry_link->prevp);
5405 + SAFE_FREE(acl_entry_link->prevp->entryp);
5406 + SAFE_FREE(acl_entry_link->prevp);
5407 + SAFE_FREE(acl_entry_link->entryp);
5408 + SAFE_FREE(acl_entry_link);
5413 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5418 +#else /* No ACLs. */
5420 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5426 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5432 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5438 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5444 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5447 + return (SMB_ACL_T)NULL;
5450 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5453 + return (SMB_ACL_T)NULL;
5456 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5462 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5468 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5471 + return (permset & perm) ? 1 : 0;
5474 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5480 +int sys_acl_free_text(UNUSED(char *text))
5486 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5492 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5498 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5504 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5510 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5516 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5522 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5528 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5534 +int sys_acl_delete_def_file(UNUSED(const char *name))
5540 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5546 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5552 +#endif /* No ACLs. */
5554 +/************************************************************************
5555 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5557 +************************************************************************/
5559 +int no_acl_syscall_error(int err)
5561 +#if defined(ENOSYS)
5562 + if (err == ENOSYS) {
5566 +#if defined(ENOTSUP)
5567 + if (err == ENOTSUP) {
5574 +#endif /* SUPPORT_ACLS */
5575 --- old/lib/sysacls.h
5576 +++ new/lib/sysacls.h
5578 +#ifdef SUPPORT_ACLS
5580 +#ifdef HAVE_SYS_ACL_H
5581 +#include <sys/acl.h>
5583 +#ifdef HAVE_ACL_LIBACL_H
5584 +#include <acl/libacl.h>
5586 +#include "smb_acls.h"
5588 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5589 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5590 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5591 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5592 +#define slprintf snprintf
5594 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5595 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5596 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5597 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5598 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5599 +SMB_ACL_T sys_acl_get_fd(int fd);
5600 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5601 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5602 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5603 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5604 +SMB_ACL_T sys_acl_init(int count);
5605 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5606 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5607 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5608 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5609 +int sys_acl_valid(SMB_ACL_T theacl);
5610 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5611 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5612 +int sys_acl_delete_def_file(const char *name);
5613 +int sys_acl_free_text(char *text);
5614 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5615 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5617 +#endif /* SUPPORT_ACLS */
5620 @@ -611,8 +611,10 @@ static void log_formatted(enum logcode c
5621 c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5622 c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5623 c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5626 + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5627 + c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5628 + c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5631 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5632 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5635 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5637 int preserve_links = 0;
5638 int preserve_hard_links = 0;
5639 +int preserve_acls = 0;
5640 int preserve_perms = 0;
5641 int preserve_executability = 0;
5642 int preserve_devices = 0;
5643 @@ -199,6 +200,7 @@ static void print_rsync_version(enum log
5644 char const *got_socketpair = "no ";
5645 char const *have_inplace = "no ";
5646 char const *hardlinks = "no ";
5647 + char const *acls = "no ";
5648 char const *links = "no ";
5649 char const *ipv6 = "no ";
5650 STRUCT_STAT *dumstat;
5651 @@ -215,6 +217,10 @@ static void print_rsync_version(enum log
5655 +#ifdef SUPPORT_ACLS
5659 #ifdef SUPPORT_LINKS
5662 @@ -227,17 +233,16 @@ static void print_rsync_version(enum log
5663 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
5664 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5665 rprintf(f, "<http://rsync.samba.org/>\n");
5666 - rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5667 - "%shard links, %ssymlinks, batchfiles,\n",
5668 - (int) (sizeof (OFF_T) * 8),
5669 - got_socketpair, hardlinks, links);
5670 + rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n",
5671 + (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links);
5673 + rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n",
5674 + have_inplace, ipv6, acls);
5676 /* Note that this field may not have type ino_t. It depends
5677 * on the complicated interaction between largefile feature
5679 - rprintf(f, " %sinplace, %sIPv6, "
5680 - "%d-bit system inums, %d-bit internal inums\n",
5681 - have_inplace, ipv6,
5682 + rprintf(f, " %d-bit system inums, %d-bit internal inums\n",
5683 (int) (sizeof dumstat->st_ino * 8),
5684 (int) (sizeof (int64) * 8));
5685 #ifdef MAINTAINER_MODE
5686 @@ -284,7 +289,7 @@ void usage(enum logcode F)
5687 rprintf(F," -q, --quiet suppress non-error messages\n");
5688 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5689 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5690 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5691 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5692 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5693 rprintf(F," -r, --recursive recurse into directories\n");
5694 rprintf(F," -R, --relative use relative path names\n");
5695 @@ -306,6 +311,9 @@ void usage(enum logcode F)
5696 rprintf(F," -p, --perms preserve permissions\n");
5697 rprintf(F," -E, --executability preserve the file's executability\n");
5698 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5699 +#ifdef SUPPORT_ACLS
5700 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5702 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5703 rprintf(F," -g, --group preserve group\n");
5704 rprintf(F," --devices preserve device files (super-user only)\n");
5705 @@ -425,6 +433,9 @@ static struct poptOption long_options[]
5706 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5707 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5708 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5709 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5710 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5711 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5712 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5713 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5714 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5715 @@ -1089,6 +1100,24 @@ int parse_arguments(int *argc, const cha
5720 +#ifdef SUPPORT_ACLS
5722 + preserve_perms = 1;
5725 + /* FIXME: this should probably be ignored with a
5726 + * warning and then countermeasures taken to
5727 + * restrict group and other access in the presence
5728 + * of any more restrictive ACLs, but this is safe
5730 + snprintf(err_buf,sizeof(err_buf),
5731 + "ACLs are not supported on this %s\n",
5732 + am_server ? "server" : "client");
5738 /* A large opt value means that set_refuse_options()
5739 * turned this option off. */
5740 @@ -1530,6 +1559,10 @@ void server_options(char **args,int *arg
5742 if (preserve_hard_links)
5744 +#ifdef SUPPORT_ACLS
5745 + if (preserve_acls)
5746 + argstr[x++] = 'A';
5753 @@ -47,6 +47,7 @@ extern int keep_partial;
5754 extern int checksum_seed;
5756 extern int delay_updates;
5757 +extern mode_t orig_umask;
5758 extern struct stats stats;
5759 extern char *stdout_format;
5760 extern char *tmpdir;
5761 @@ -350,6 +351,10 @@ int recv_files(int f_in, struct file_lis
5762 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5763 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5764 int max_phase = protocol_version >= 29 ? 2 : 1;
5765 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5766 +#ifdef SUPPORT_ACLS
5767 + char *parent_dirname = "";
5772 @@ -553,7 +558,16 @@ int recv_files(int f_in, struct file_lis
5773 * mode based on the local permissions and some heuristics. */
5774 if (!preserve_perms) {
5775 int exists = fd1 != -1;
5776 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5777 +#ifdef SUPPORT_ACLS
5778 + char *dn = file->dirname ? file->dirname : ".";
5779 + if (parent_dirname != dn
5780 + && strcmp(parent_dirname, dn) != 0) {
5781 + dflt_perms = default_perms_for_dir(dn);
5782 + parent_dirname = dn;
5785 + file->mode = dest_mode(file->mode, st.st_mode,
5786 + dflt_perms, exists);
5789 /* We now check to see if we are writing the file "inplace" */
5796 +extern int preserve_acls;
5797 extern int preserve_perms;
5798 extern int preserve_executability;
5799 extern int preserve_times;
5800 @@ -47,7 +48,6 @@ extern int preserve_gid;
5802 extern int keep_dirlinks;
5803 extern int make_backups;
5804 -extern mode_t orig_umask;
5805 extern struct stats stats;
5806 extern struct chmod_mode_struct *daemon_chmod_modes;
5808 @@ -100,7 +100,8 @@ void free_sums(struct sum_struct *s)
5810 /* This is only called when we aren't preserving permissions. Figure out what
5811 * the permissions should be and return them merged back into the mode. */
5812 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5813 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5817 /* If the file already exists, we'll return the local permissions,
5818 @@ -117,56 +118,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5819 new_mode |= (new_mode & 0444) >> 2;
5822 - /* Apply the umask and turn off special permissions. */
5823 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5824 + /* Apply destination default permissions and turn
5825 + * off special permissions. */
5826 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5831 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5832 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5838 int change_uid, change_gid;
5839 mode_t new_mode = file->mode;
5845 - if (link_stat(fname, &st2, 0) < 0) {
5846 + if (link_stat(fname, &sx2.st, 0) < 0) {
5847 rsyserr(FERROR, errno, "stat %s failed",
5852 +#ifdef SUPPORT_ACLS
5853 + sx2.acc_acl = sx2.def_acl = NULL;
5855 if (!preserve_perms && S_ISDIR(new_mode)
5856 - && st->st_mode & S_ISGID) {
5857 + && sx2.st.st_mode & S_ISGID) {
5858 /* We just created this directory and its setgid
5859 * bit is on, so make sure it stays on. */
5860 new_mode |= S_ISGID;
5865 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5866 +#ifdef SUPPORT_ACLS
5867 + if (preserve_acls && !ACL_READY(*sxp))
5868 + get_acl(fname, sxp);
5871 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5872 flags |= ATTRS_SKIP_MTIME;
5873 if (!(flags & ATTRS_SKIP_MTIME)
5874 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5875 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5876 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5877 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5879 rsyserr(FERROR, errno, "failed to set times on %s",
5884 if (ret == 0) /* ret == 1 if symlink could not be set */
5888 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5889 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5890 change_gid = preserve_gid && file->gid != GID_NONE
5891 - && st->st_gid != file->gid;
5892 + && sxp->st.st_gid != file->gid;
5893 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5894 - if (S_ISLNK(st->st_mode))
5895 + if (S_ISLNK(sxp->st.st_mode))
5899 @@ -176,45 +186,57 @@ int set_file_attrs(char *fname, struct f
5901 "set uid of %s from %ld to %ld\n",
5903 - (long)st->st_uid, (long)file->uid);
5904 + (long)sxp->st.st_uid, (long)file->uid);
5908 "set gid of %s from %ld to %ld\n",
5910 - (long)st->st_gid, (long)file->gid);
5911 + (long)sxp->st.st_gid, (long)file->gid);
5914 if (do_lchown(fname,
5915 - change_uid ? file->uid : st->st_uid,
5916 - change_gid ? file->gid : st->st_gid) != 0) {
5917 + change_uid ? file->uid : sxp->st.st_uid,
5918 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5919 /* shouldn't have attempted to change uid or gid
5920 * unless have the privilege */
5921 rsyserr(FERROR, errno, "%s %s failed",
5922 change_uid ? "chown" : "chgrp",
5927 /* a lchown had been done - we have to re-stat if the
5928 * destination had the setuid or setgid bits set due
5929 * to the side effect of the chown call */
5930 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5931 - link_stat(fname, st,
5932 - keep_dirlinks && S_ISDIR(st->st_mode));
5933 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5934 + link_stat(fname, &sxp->st,
5935 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5940 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5941 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5943 +#ifdef SUPPORT_ACLS
5944 + /* It's OK to call set_acl() now, even for a dir, as the generator
5945 + * will enable owner-writability using chmod, if necessary.
5947 + * If set_acl() changes permission bits in the process of setting
5948 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5949 + * need to chmod(). */
5950 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5955 - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5956 + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5957 int ret = do_chmod(fname, new_mode);
5959 rsyserr(FERROR, errno,
5960 "failed to set permissions on %s",
5965 if (ret == 0) /* ret == 1 if symlink could not be set */
5967 @@ -227,6 +249,11 @@ int set_file_attrs(char *fname, struct f
5969 rprintf(FCLIENT, "%s is uptodate\n", fname);
5972 +#ifdef SUPPORT_ACLS
5973 + if (preserve_acls && sxp == &sx2)
5981 @@ -493,6 +493,14 @@ struct idev {
5982 #define IN_LOOPBACKNET 127
5985 +#ifndef HAVE_NO_ACLS
5986 +#define SUPPORT_ACLS 1
5989 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5990 +#define ACLS_NEED_MASK 1
5993 #define GID_NONE ((gid_t)-1)
5995 #define HL_CHECK_MASTER 0
5996 @@ -656,6 +664,17 @@ struct stats {
5998 struct chmod_mode_struct;
6000 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
6008 +#define EXPAND_ITEM_LIST(lp, type, incr) \
6009 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
6011 #include "byteorder.h"
6012 #include "lib/mdfour.h"
6013 #include "lib/wildmatch.h"
6014 @@ -669,6 +688,16 @@ struct chmod_mode_struct;
6015 #define UNUSED(x) x __attribute__((__unused__))
6016 #define NORETURN __attribute__((__noreturn__))
6020 +#ifdef SUPPORT_ACLS
6021 + struct rsync_acl *acc_acl; /* access ACL */
6022 + struct rsync_acl *def_acl; /* default ACL */
6026 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
6030 /* We have replacement versions of these if they're missing. */
6033 @@ -301,7 +301,7 @@ to the detailed description below for a
6034 -q, --quiet suppress non-error messages
6035 --no-motd suppress daemon-mode MOTD (see caveat)
6036 -c, --checksum skip based on checksum, not mod-time & size
6037 - -a, --archive archive mode; same as -rlptgoD (no -H)
6038 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
6039 --no-OPTION turn off an implied OPTION (e.g. --no-D)
6040 -r, --recursive recurse into directories
6041 -R, --relative use relative path names
6042 @@ -323,6 +323,7 @@ to the detailed description below for a
6043 -p, --perms preserve permissions
6044 -E, --executability preserve executability
6045 --chmod=CHMOD affect file and/or directory permissions
6046 + -A, --acls preserve ACLs (implies -p) [non-standard]
6047 -o, --owner preserve owner (super-user only)
6048 -g, --group preserve group
6049 --devices preserve device files (super-user only)
6050 @@ -753,7 +754,9 @@ quote(itemization(
6051 permissions, though the bf(--executability) option might change just
6052 the execute permission for the file.
6053 it() New files get their "normal" permission bits set to the source
6054 - file's permissions masked with the receiving end's umask setting, and
6055 + file's permissions masked with the receiving directory's default
6056 + permissions (either the receiving process's umask, or the permissions
6057 + specified via the destination directory's default ACL), and
6058 their special permission bits disabled except in the case where a new
6059 directory inherits a setgid bit from its parent directory.
6061 @@ -784,9 +787,11 @@ The preservation of the destination's se
6062 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
6063 versions erroneously preserved the three special permission bits for
6064 newly-created files when bf(--perms) was off, while overriding the
6065 -destination's setgid bit setting on a newly-created directory. (Keep in
6066 -mind that it is the version of the receiving rsync that affects this
6068 +destination's setgid bit setting on a newly-created directory. Default ACL
6069 +observance was added to the ACL patch for rsync 2.6.7, so older (or
6070 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
6071 +(Keep in mind that it is the version of the receiving rsync that affects
6074 dit(bf(-E, --executability)) This option causes rsync to preserve the
6075 executability (or non-executability) of regular files when bf(--perms) is
6076 @@ -804,6 +809,15 @@ quote(itemization(
6078 If bf(--perms) is enabled, this option is ignored.
6080 +dit(bf(-A, --acls)) This option causes rsync to update the destination
6081 +ACLs to be the same as the source ACLs. This nonstandard option only
6082 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
6084 +Note also that an optimization of the ACL-sending protocol used by this
6085 +version makes it incompatible with sending files to an older ACL-enabled
6086 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
6087 +doubling is not needed when pulling files from an older rsync.
6089 dit(bf(--chmod)) This option tells rsync to apply one or more
6090 comma-separated "chmod" strings to the permission of the files in the
6091 transfer. The resulting value is treated as though it was the permissions
6092 @@ -1395,8 +1409,8 @@ if the receiving rsync is at least versi
6093 with older versions of rsync, but that also turns on the output of other
6096 -The "%i" escape has a cryptic output that is 9 letters long. The general
6097 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
6098 +The "%i" escape has a cryptic output that is 11 letters long. The general
6099 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
6100 type of update being done, bf(X) is replaced by the file-type, and the
6101 other letters represent attributes that may be output if they are being
6103 @@ -1445,7 +1459,11 @@ quote(itemization(
6104 sender's value (requires bf(--owner) and super-user privileges).
6105 it() A bf(g) means the group is different and is being updated to the
6106 sender's value (requires bf(--group) and the authority to set the group).
6107 - it() The bf(z) slot is reserved for future use.
6108 + it() The bf(u) slot is reserved for reporting update (access) time changes
6109 + (a feature that is not yet released).
6110 + it() The bf(a) means that the ACL information changed.
6111 + it() The bf(x) slot is reserved for reporting extended attribute changes
6112 + (a feature that is not yet released).
6115 One other output is possible: when deleting files, the "%i" will output
6120 + Unix SMB/Netbios implementation.
6122 + Portable SMB ACL interface
6123 + Copyright (C) Jeremy Allison 2000
6125 + This program is free software; you can redistribute it and/or modify
6126 + it under the terms of the GNU General Public License as published by
6127 + the Free Software Foundation; either version 2 of the License, or
6128 + (at your option) any later version.
6130 + This program is distributed in the hope that it will be useful,
6131 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6132 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6133 + GNU General Public License for more details.
6135 + You should have received a copy of the GNU General Public License
6136 + along with this program; if not, write to the Free Software
6137 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6140 +#ifndef _SMB_ACLS_H
6141 +#define _SMB_ACLS_H
6143 +#if defined HAVE_POSIX_ACLS
6145 +/* This is an identity mapping (just remove the SMB_). */
6147 +#define SMB_ACL_TAG_T acl_tag_t
6148 +#define SMB_ACL_TYPE_T acl_type_t
6149 +#define SMB_ACL_PERMSET_T acl_permset_t
6150 +#define SMB_ACL_PERM_T acl_perm_t
6151 +#define SMB_ACL_READ ACL_READ
6152 +#define SMB_ACL_WRITE ACL_WRITE
6153 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6155 +/* Types of ACLs. */
6156 +#define SMB_ACL_USER ACL_USER
6157 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6158 +#define SMB_ACL_GROUP ACL_GROUP
6159 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6160 +#define SMB_ACL_OTHER ACL_OTHER
6161 +#define SMB_ACL_MASK ACL_MASK
6163 +#define SMB_ACL_T acl_t
6165 +#define SMB_ACL_ENTRY_T acl_entry_t
6167 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6168 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6170 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6171 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6173 +#elif defined HAVE_TRU64_ACLS
6175 +/* This is for DEC/Compaq Tru64 UNIX */
6177 +#define SMB_ACL_TAG_T acl_tag_t
6178 +#define SMB_ACL_TYPE_T acl_type_t
6179 +#define SMB_ACL_PERMSET_T acl_permset_t
6180 +#define SMB_ACL_PERM_T acl_perm_t
6181 +#define SMB_ACL_READ ACL_READ
6182 +#define SMB_ACL_WRITE ACL_WRITE
6183 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6185 +/* Types of ACLs. */
6186 +#define SMB_ACL_USER ACL_USER
6187 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6188 +#define SMB_ACL_GROUP ACL_GROUP
6189 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6190 +#define SMB_ACL_OTHER ACL_OTHER
6191 +#define SMB_ACL_MASK ACL_MASK
6193 +#define SMB_ACL_T acl_t
6195 +#define SMB_ACL_ENTRY_T acl_entry_t
6197 +#define SMB_ACL_FIRST_ENTRY 0
6198 +#define SMB_ACL_NEXT_ENTRY 1
6200 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6201 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6203 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6205 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6206 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6209 +/* SVR4.2 ES/MP ACLs */
6210 +typedef int SMB_ACL_TAG_T;
6211 +typedef int SMB_ACL_TYPE_T;
6212 +typedef ushort *SMB_ACL_PERMSET_T;
6213 +typedef ushort SMB_ACL_PERM_T;
6214 +#define SMB_ACL_READ 4
6215 +#define SMB_ACL_WRITE 2
6216 +#define SMB_ACL_EXECUTE 1
6218 +/* Types of ACLs. */
6219 +#define SMB_ACL_USER USER
6220 +#define SMB_ACL_USER_OBJ USER_OBJ
6221 +#define SMB_ACL_GROUP GROUP
6222 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6223 +#define SMB_ACL_OTHER OTHER_OBJ
6224 +#define SMB_ACL_MASK CLASS_OBJ
6226 +typedef struct SMB_ACL_T {
6230 + struct acl acl[1];
6233 +typedef struct acl *SMB_ACL_ENTRY_T;
6235 +#define SMB_ACL_FIRST_ENTRY 0
6236 +#define SMB_ACL_NEXT_ENTRY 1
6238 +#define SMB_ACL_TYPE_ACCESS 0
6239 +#define SMB_ACL_TYPE_DEFAULT 1
6242 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6245 +#elif defined HAVE_HPUX_ACLS
6248 + * Based on the Solaris & UnixWare code.
6252 +#include <sys/aclv.h>
6254 +/* SVR4.2 ES/MP ACLs */
6255 +typedef int SMB_ACL_TAG_T;
6256 +typedef int SMB_ACL_TYPE_T;
6257 +typedef ushort *SMB_ACL_PERMSET_T;
6258 +typedef ushort SMB_ACL_PERM_T;
6259 +#define SMB_ACL_READ 4
6260 +#define SMB_ACL_WRITE 2
6261 +#define SMB_ACL_EXECUTE 1
6263 +/* Types of ACLs. */
6264 +#define SMB_ACL_USER USER
6265 +#define SMB_ACL_USER_OBJ USER_OBJ
6266 +#define SMB_ACL_GROUP GROUP
6267 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6268 +#define SMB_ACL_OTHER OTHER_OBJ
6269 +#define SMB_ACL_MASK CLASS_OBJ
6271 +typedef struct SMB_ACL_T {
6275 + struct acl acl[1];
6278 +typedef struct acl *SMB_ACL_ENTRY_T;
6280 +#define SMB_ACL_FIRST_ENTRY 0
6281 +#define SMB_ACL_NEXT_ENTRY 1
6283 +#define SMB_ACL_TYPE_ACCESS 0
6284 +#define SMB_ACL_TYPE_DEFAULT 1
6286 +#elif defined HAVE_IRIX_ACLS
6288 +#define SMB_ACL_TAG_T acl_tag_t
6289 +#define SMB_ACL_TYPE_T acl_type_t
6290 +#define SMB_ACL_PERMSET_T acl_permset_t
6291 +#define SMB_ACL_PERM_T acl_perm_t
6292 +#define SMB_ACL_READ ACL_READ
6293 +#define SMB_ACL_WRITE ACL_WRITE
6294 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6296 +/* Types of ACLs. */
6297 +#define SMB_ACL_USER ACL_USER
6298 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6299 +#define SMB_ACL_GROUP ACL_GROUP
6300 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6301 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6302 +#define SMB_ACL_MASK ACL_MASK
6304 +typedef struct SMB_ACL_T {
6310 +#define SMB_ACL_ENTRY_T acl_entry_t
6312 +#define SMB_ACL_FIRST_ENTRY 0
6313 +#define SMB_ACL_NEXT_ENTRY 1
6315 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6316 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6318 +#elif defined HAVE_AIX_ACLS
6320 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6322 +#include "/usr/include/acl.h"
6324 +typedef uint *SMB_ACL_PERMSET_T;
6326 +struct acl_entry_link{
6327 + struct acl_entry_link *prevp;
6328 + struct new_acl_entry *entryp;
6329 + struct acl_entry_link *nextp;
6333 +struct new_acl_entry{
6334 + unsigned short ace_len;
6335 + unsigned short ace_type;
6336 + unsigned int ace_access;
6337 + struct ace_id ace_id[1];
6340 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6341 +#define SMB_ACL_T struct acl_entry_link*
6343 +#define SMB_ACL_TAG_T unsigned short
6344 +#define SMB_ACL_TYPE_T int
6345 +#define SMB_ACL_PERM_T uint
6346 +#define SMB_ACL_READ S_IRUSR
6347 +#define SMB_ACL_WRITE S_IWUSR
6348 +#define SMB_ACL_EXECUTE S_IXUSR
6350 +/* Types of ACLs. */
6351 +#define SMB_ACL_USER ACEID_USER
6352 +#define SMB_ACL_USER_OBJ 3
6353 +#define SMB_ACL_GROUP ACEID_GROUP
6354 +#define SMB_ACL_GROUP_OBJ 4
6355 +#define SMB_ACL_OTHER 5
6356 +#define SMB_ACL_MASK 6
6359 +#define SMB_ACL_FIRST_ENTRY 1
6360 +#define SMB_ACL_NEXT_ENTRY 2
6362 +#define SMB_ACL_TYPE_ACCESS 0
6363 +#define SMB_ACL_TYPE_DEFAULT 1
6365 +#else /* No ACLs. */
6367 +/* No ACLS - fake it. */
6368 +#define SMB_ACL_TAG_T int
6369 +#define SMB_ACL_TYPE_T int
6370 +#define SMB_ACL_PERMSET_T mode_t
6371 +#define SMB_ACL_PERM_T mode_t
6372 +#define SMB_ACL_READ S_IRUSR
6373 +#define SMB_ACL_WRITE S_IWUSR
6374 +#define SMB_ACL_EXECUTE S_IXUSR
6376 +/* Types of ACLs. */
6377 +#define SMB_ACL_USER 0
6378 +#define SMB_ACL_USER_OBJ 1
6379 +#define SMB_ACL_GROUP 2
6380 +#define SMB_ACL_GROUP_OBJ 3
6381 +#define SMB_ACL_OTHER 4
6382 +#define SMB_ACL_MASK 5
6384 +typedef struct SMB_ACL_T {
6388 +typedef struct SMB_ACL_ENTRY_T {
6390 +} *SMB_ACL_ENTRY_T;
6392 +#define SMB_ACL_FIRST_ENTRY 0
6393 +#define SMB_ACL_NEXT_ENTRY 1
6395 +#define SMB_ACL_TYPE_ACCESS 0
6396 +#define SMB_ACL_TYPE_DEFAULT 1
6398 +#endif /* No ACLs. */
6399 +#endif /* _SMB_ACLS_H */
6400 --- old/testsuite/acls.test
6401 +++ new/testsuite/acls.test
6405 +# This program is distributable under the terms of the GNU GPL (see
6408 +# Test that rsync handles basic ACL preservation.
6410 +. $srcdir/testsuite/rsync.fns
6412 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6413 +case "$setfacl_nodef" in
6414 +true) test_skipped "I don't know how to use your setfacl command" ;;
6417 +makepath "$fromdir/foo"
6418 +echo something >"$fromdir/file1"
6419 +echo else >"$fromdir/file2"
6421 +files='foo file1 file2'
6423 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6424 +setfacl -m u:0:5 "$fromdir/file1"
6425 +setfacl -m u:0:5 "$fromdir/file2"
6427 +$RSYNC -avvA "$fromdir/" "$todir/"
6430 +getfacl $files >"$scratchdir/acls.txt"
6433 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6435 +# The script would have aborted on error, so getting here means we've won.
6437 --- old/testsuite/default-acls.test
6438 +++ new/testsuite/default-acls.test
6442 +# This program is distributable under the terms of the GNU GPL (see
6445 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6447 +. $srcdir/testsuite/rsync.fns
6449 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6450 +case "$setfacl_nodef" in
6451 +true) test_skipped "I don't know how to use your setfacl command" ;;
6452 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6453 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6455 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6457 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6459 + todir="$scratchdir/$1"
6461 + $setfacl_nodef "$todir"
6463 + case "$setfacl_nodef" in
6464 + *-k*) opts="-dm $2" ;;
6465 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6467 + setfacl $opts "$todir"
6469 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6470 + # even though the directory itself is outside the transfer
6471 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6472 + check_perms "$todir/to" $4 "Target $1"
6473 + check_perms "$todir/to/dir" $4 "Target $1"
6474 + check_perms "$todir/to/file" $3 "Target $1"
6475 + check_perms "$todir/to/program" $4 "Target $1"
6476 + # Make sure get_local_name doesn't mess us up when transferring only one file
6477 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6478 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6479 + # Make sure we obey default ACLs when not transferring a regular file
6480 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6481 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6484 +mkdir "$scratchdir/dir"
6485 +echo "File!" >"$scratchdir/file"
6486 +echo "#!/bin/sh" >"$scratchdir/program"
6487 +chmod 777 "$scratchdir/dir"
6488 +chmod 666 "$scratchdir/file"
6489 +chmod 777 "$scratchdir/program"
6491 +# Test some target directories
6493 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6494 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6495 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6496 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6497 +testit noda1 '' rw------- rwx------
6499 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6501 +testit noda3 '' rw-r--r-- rwxr-xr-x
6505 --- old/testsuite/devices.test
6506 +++ new/testsuite/devices.test
6507 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6508 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6510 cat <<EOT >"$chkfile"
6514 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6516 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6518 cat <<EOT >"$chkfile"
6522 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6524 @@ -58,7 +58,7 @@ sleep 1
6525 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6527 cat <<EOT >"$chkfile"
6531 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6533 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6536 cat <<EOT >"$chkfile"
6541 -hD+++++++ block2.5 => block3
6550 +hD+++++++++ block2.5 => block3
6556 if test ! -b "$fromdir/block2.5"; then
6557 sed -e '/block2\.5/d' \
6558 @@ -94,15 +94,15 @@ if test -b "$fromdir/block2.5"; then
6559 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
6561 cat <<EOT >"$chkfile"
6581 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
6583 --- old/testsuite/itemize.test
6584 +++ new/testsuite/itemize.test
6585 @@ -38,15 +38,15 @@ rm -f "$to2dir" "$to2dir.test"
6586 $RSYNC -iplr "$fromdir/" "$todir/" \
6588 cat <<EOT >"$chkfile"
6592 ->f+++++++ bar/baz/rsync
6594 ->f+++++++ foo/config1
6595 ->f+++++++ foo/config2
6596 ->f+++++++ foo/extra
6597 -cL+++++++ foo/sym -> ../bar/baz/rsync
6600 +cd+++++++++ bar/baz/
6601 +>f+++++++++ bar/baz/rsync
6603 +>f+++++++++ foo/config1
6604 +>f+++++++++ foo/config2
6605 +>f+++++++++ foo/extra
6606 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6608 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6610 @@ -58,10 +58,10 @@ chmod 601 "$fromdir/foo/config2"
6611 $RSYNC -iplrH "$fromdir/" "$todir/" \
6613 cat <<EOT >"$chkfile"
6614 ->f..T.... bar/baz/rsync
6615 ->f..T.... foo/config1
6616 ->f.sTp... foo/config2
6617 -hf..T.... foo/extra => foo/config1
6618 +>f..T...... bar/baz/rsync
6619 +>f..T...... foo/config1
6620 +>f.sTp..... foo/config2
6621 +hf..T...... foo/extra => foo/config1
6623 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6625 @@ -78,11 +78,11 @@ chmod 777 "$todir/bar/baz/rsync"
6626 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6628 cat <<EOT >"$chkfile"
6629 -.f..tp... bar/baz/rsync
6631 -.f..t.... foo/config1
6632 ->fcstp... foo/config2
6633 -cL..T.... foo/sym -> ../bar/baz/rsync
6634 +.f..tp..... bar/baz/rsync
6636 +.f..t...... foo/config1
6637 +>fcstp..... foo/config2
6638 +cL..T...... foo/sym -> ../bar/baz/rsync
6640 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6642 @@ -107,15 +107,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6645 cat <<EOT >"$chkfile"
6649 -.f...p... bar/baz/rsync
6652 ->f..t.... foo/config2
6654 -.L foo/sym -> ../bar/baz/rsync
6658 +.f...p..... bar/baz/rsync
6661 +>f..t...... foo/config2
6663 +.L foo/sym -> ../bar/baz/rsync
6665 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6667 @@ -134,8 +134,8 @@ touch "$todir/foo/config2"
6668 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6670 cat <<EOT >"$chkfile"
6671 -.f...p... foo/config1
6672 ->f..t.... foo/config2
6673 +.f...p..... foo/config1
6674 +>f..t...... foo/config2
6676 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6678 @@ -143,15 +143,15 @@ $RSYNC -ivvplrtH --copy-dest=../to "$fro
6681 cat <<EOT >"$chkfile"
6689 -hf foo/extra => foo/config1
6690 -cL foo/sym -> ../bar/baz/rsync
6698 +hf foo/extra => foo/config1
6699 +cL foo/sym -> ../bar/baz/rsync
6701 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6703 @@ -159,7 +159,7 @@ rm -rf "$to2dir"
6704 $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \
6706 cat <<EOT >"$chkfile"
6707 -hf foo/extra => foo/config1
6708 +hf foo/extra => foo/config1
6710 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6712 @@ -186,15 +186,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$
6715 cat <<EOT >"$chkfile"
6723 -hf foo/extra => foo/config1
6724 -$L foo/sym -> ../bar/baz/rsync
6732 +hf foo/extra => foo/config1
6733 +$L foo/sym -> ../bar/baz/rsync
6735 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6737 @@ -236,14 +236,14 @@ filter_outfile
6738 # TODO fix really-old problem when combining -H with --compare-dest:
6739 # missing output for foo/extra hard-link (and it might not be updated)!
6740 cat <<EOT >"$chkfile"
6748 -.L foo/sym -> ../bar/baz/rsync
6756 +.L foo/sym -> ../bar/baz/rsync
6758 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6764 extern int preserve_uid;
6765 extern int preserve_gid;
6766 +extern int preserve_acls;
6767 extern int numeric_ids;
6770 @@ -273,7 +274,7 @@ void send_uid_list(int f)
6774 - if (preserve_uid) {
6775 + if (preserve_uid || preserve_acls) {
6777 /* we send sequences of uid/byte-length/name */
6778 for (list = uidlist; list; list = list->next) {
6779 @@ -290,7 +291,7 @@ void send_uid_list(int f)
6783 - if (preserve_gid) {
6784 + if (preserve_gid || preserve_acls) {
6786 for (list = gidlist; list; list = list->next) {
6788 @@ -311,7 +312,7 @@ void recv_uid_list(int f, struct file_li
6792 - if (preserve_uid && !numeric_ids) {
6793 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6794 /* read the uid list */
6795 while ((id = read_int(f)) != 0) {
6796 int len = read_byte(f);
6797 @@ -323,7 +324,7 @@ void recv_uid_list(int f, struct file_li
6801 - if (preserve_gid && !numeric_ids) {
6802 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6803 /* read the gid list */
6804 while ((id = read_int(f)) != 0) {
6805 int len = read_byte(f);
6806 @@ -335,6 +336,16 @@ void recv_uid_list(int f, struct file_li
6810 +#ifdef SUPPORT_ACLS
6811 + if (preserve_acls && !numeric_ids) {
6813 + while ((id = next_acl_uid(flist)) != NULL)
6814 + *id = match_uid(*id);
6815 + while ((id = next_acl_gid(flist)) != NULL)
6816 + *id = match_gid(*id);
6820 /* Now convert all the uids/gids from sender values to our values. */
6821 if (am_root && preserve_uid && !numeric_ids) {
6822 for (i = 0; i < flist->count; i++)
6825 @@ -1468,3 +1468,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6830 +void *expand_item_list(item_list *lp, size_t item_size,
6831 + const char *desc, int incr)
6833 + /* First time through, 0 <= 0, so list is expanded. */
6834 + if (lp->malloced <= lp->count) {
6836 + size_t new_size = lp->malloced;
6838 + new_size -= incr; /* increase slowly */
6839 + else if (new_size < (size_t)incr)
6843 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6844 + if (verbose >= 4) {
6845 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6846 + who_am_i(), desc, (double)new_size * item_size,
6847 + new_ptr == lp->items ? " not" : "");
6850 + out_of_memory("expand_item_list");
6852 + lp->items = new_ptr;
6853 + lp->malloced = new_size;
6855 + return (char*)lp->items + (lp->count++ * item_size);