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 int flist_extra_ndx;
68 +extern unsigned int file_struct_len;
70 +/* === ACL structures === */
82 +#define NO_ENTRY ((uchar)0x80)
83 +typedef struct rsync_acl {
86 + /* These will be NO_ENTRY if there's no such entry. */
98 +static const rsync_acl empty_rsync_acl = {
99 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
102 +static item_list access_acl_list = EMPTY_ITEM_LIST;
103 +static item_list default_acl_list = EMPTY_ITEM_LIST;
105 +/* === Calculations on ACL types === */
107 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
109 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
110 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
111 + : "unknown SMB_ACL_TYPE_T";
114 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
115 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
117 +static int count_racl_entries(const rsync_acl *racl)
119 + return racl->users.count + racl->groups.count
120 + + (racl->user_obj != NO_ENTRY)
121 + + (racl->group_obj != NO_ENTRY)
122 + + (racl->mask != NO_ENTRY)
123 + + (racl->other != NO_ENTRY);
126 +static int calc_sacl_entries(const rsync_acl *racl)
128 + /* A System ACL always gets user/group/other permission entries. */
129 + return racl->users.count + racl->groups.count
130 +#ifdef ACLS_NEED_MASK
133 + + (racl->mask != NO_ENTRY) + 3;
137 +/* Extracts and returns the permission bits from the ACL. This cannot be
138 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
139 +static int rsync_acl_get_perms(const rsync_acl *racl)
141 + return (racl->user_obj << 6)
142 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
146 +/* Removes the permission-bit entries from the ACL because these
147 + * can be reconstructed from the file's mode. */
148 +static void rsync_acl_strip_perms(rsync_acl *racl)
150 + racl->user_obj = NO_ENTRY;
151 + if (racl->mask == NO_ENTRY)
152 + racl->group_obj = NO_ENTRY;
154 + if (racl->group_obj == racl->mask)
155 + racl->group_obj = NO_ENTRY;
156 + racl->mask = NO_ENTRY;
158 + racl->other = NO_ENTRY;
161 +/* Given an empty rsync_acl, fake up the permission bits. */
162 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
164 + racl->user_obj = (mode >> 6) & 7;
165 + racl->group_obj = (mode >> 3) & 7;
166 + racl->other = mode & 7;
169 +/* === Rsync ACL functions === */
171 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
173 + id_access *ida1, *ida2;
174 + int count = ial1->count;
175 + if (count != ial2->count)
179 + for (; count--; ida1++, ida2++) {
180 + if (ida1->access != ida2->access || ida1->id != ida2->id)
186 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
188 + return racl1->user_obj == racl2->user_obj
189 + && racl1->group_obj == racl2->group_obj
190 + && racl1->mask == racl2->mask
191 + && racl1->other == racl2->other
192 + && ida_entries_equal(&racl1->users, &racl2->users)
193 + && ida_entries_equal(&racl1->groups, &racl2->groups);
196 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
197 + * the ACL will be handled by the normal mode-preservation code. This is
198 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
199 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
200 + * that it might have several of its permission objects set to NO_ENTRY. */
201 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
202 + const rsync_acl *racl2, mode_t m)
204 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
205 + return False; /* One has a mask and the other doesn't */
207 + /* When there's a mask, the group_obj becomes an extended entry. */
208 + if (racl1->mask != NO_ENTRY) {
209 + /* A condensed rsync_acl with a mask can only have no
210 + * group_obj when it was identical to the mask. This
211 + * means that it was also identical to the group attrs
212 + * from the mode. */
213 + if (racl2->group_obj == NO_ENTRY) {
214 + if (racl1->group_obj != ((m >> 3) & 7))
216 + } else if (racl1->group_obj != racl2->group_obj)
219 + return ida_entries_equal(&racl1->users, &racl2->users)
220 + && ida_entries_equal(&racl1->groups, &racl2->groups);
223 +static void rsync_acl_free(rsync_acl *racl)
225 + if (racl->users.idas)
226 + free(racl->users.idas);
227 + if (racl->groups.idas)
228 + free(racl->groups.idas);
229 + *racl = empty_rsync_acl;
232 +void free_acl(statx *sxp)
234 + if (sxp->acc_acl) {
235 + rsync_acl_free(sxp->acc_acl);
236 + free(sxp->acc_acl);
237 + sxp->acc_acl = NULL;
239 + if (sxp->def_acl) {
240 + rsync_acl_free(sxp->def_acl);
241 + free(sxp->def_acl);
242 + sxp->def_acl = NULL;
246 +static int id_access_sorter(const void *r1, const void *r2)
248 + id_access *ida1 = (id_access *)r1;
249 + id_access *ida2 = (id_access *)r2;
250 + id_t rid1 = ida1->id, rid2 = ida2->id;
251 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
254 +static void sort_ida_entries(ida_entries *idal)
258 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
261 +/* Transfer the count id_access items out of the temp_ida_list into either
262 + * the users or groups ida_entries list in racl. */
263 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
268 + if (temp_ida_list->count) {
269 + int cnt = temp_ida_list->count;
270 + id_access *temp_idas = temp_ida_list->items;
271 + if (!(idas = new_array(id_access, cnt)))
272 + out_of_memory("save_idas");
273 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
277 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
280 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
281 + exit_cleanup(RERR_UNSUPPORTED);
283 + ent->count = temp_ida_list->count;
286 + /* Truncate the temporary list now that its idas have been saved. */
287 + temp_ida_list->count = 0;
290 +/* === System ACLs === */
292 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
293 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
295 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
296 + SMB_ACL_TAG_T prior_list_type = 0;
297 + SMB_ACL_ENTRY_T entry;
298 + const char *errfun;
301 + errfun = "sys_acl_get_entry";
302 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
304 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
305 + SMB_ACL_TAG_T tag_type;
306 + SMB_ACL_PERMSET_T permset;
310 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
311 + errfun = "sys_acl_get_tag_type";
314 + if ((rc = sys_acl_get_permset(entry, &permset))) {
315 + errfun = "sys_acl_get_tag_type";
318 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
319 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
320 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
321 + /* continue == done with entry; break == store in temporary ida list */
322 + switch (tag_type) {
323 + case SMB_ACL_USER_OBJ:
324 + if (racl->user_obj == NO_ENTRY)
325 + racl->user_obj = access;
327 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
331 + case SMB_ACL_GROUP_OBJ:
332 + if (racl->group_obj == NO_ENTRY)
333 + racl->group_obj = access;
335 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
337 + case SMB_ACL_GROUP:
340 + if (racl->mask == NO_ENTRY)
341 + racl->mask = access;
343 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
345 + case SMB_ACL_OTHER:
346 + if (racl->other == NO_ENTRY)
347 + racl->other = access;
349 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
352 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
355 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
356 + errfun = "sys_acl_get_tag_type";
360 + if (tag_type != prior_list_type) {
361 + if (prior_list_type)
362 + save_idas(&temp_ida_list, racl, prior_list_type);
363 + prior_list_type = tag_type;
365 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
366 + ida->id = *((id_t *)qualifier);
367 + ida->access = access;
368 + sys_acl_free_qualifier(qualifier, tag_type);
371 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
372 + rsync_acl_free(racl);
375 + if (prior_list_type)
376 + save_idas(&temp_ida_list, racl, prior_list_type);
378 + sort_ida_entries(&racl->users);
379 + sort_ida_entries(&racl->groups);
381 +#ifdef ACLS_NEED_MASK
382 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
383 + /* Throw away a superfluous mask, but mask off the
384 + * group perms with it first. */
385 + racl->group_obj &= racl->mask;
386 + racl->mask = NO_ENTRY;
393 +/* Synactic sugar for system calls */
395 +#define CALL_OR_ERROR(func,args,str) \
403 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
404 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
406 +/* Store the permissions in the system ACL entry. */
407 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
409 + const char *errfun = NULL;
410 + SMB_ACL_PERMSET_T permset;
412 + COE( sys_acl_get_permset,(entry, &permset) );
413 + COE( sys_acl_clear_perms,(permset) );
415 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
417 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
419 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
420 + COE( sys_acl_set_permset,(entry, permset) );
425 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
429 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
430 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
432 +#ifdef ACLS_NEED_MASK
437 + const char *errfun = NULL;
438 + SMB_ACL_ENTRY_T entry;
440 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
441 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
445 + COE( sys_acl_create_entry,(smb_acl, &entry) );
446 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
447 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
449 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
450 + COE( sys_acl_create_entry,(smb_acl, &entry) );
451 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
452 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
453 + COE2( store_access_in_entry,(ida->access, entry) );
456 + COE( sys_acl_create_entry,(smb_acl, &entry) );
457 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
458 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
460 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
461 + COE( sys_acl_create_entry,(smb_acl, &entry) );
462 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
463 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
464 + COE2( store_access_in_entry,(ida->access, entry) );
467 +#ifdef ACLS_NEED_MASK
468 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
469 + COE( sys_acl_create_entry,(smb_acl, &entry) );
470 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
471 + COE2( store_access_in_entry,(mask_bits, entry) );
473 + if (racl->mask != NO_ENTRY) {
474 + COE( sys_acl_create_entry,(smb_acl, &entry) );
475 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
476 + COE2( store_access_in_entry,(racl->mask, entry) );
480 + COE( sys_acl_create_entry,(smb_acl, &entry) );
481 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
482 + COE2( store_access_in_entry,(racl->other & 7, entry) );
485 + if (sys_acl_valid(*smb_acl) < 0)
486 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
493 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
495 + sys_acl_free_acl(*smb_acl);
499 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
500 + const item_list *racl_list,
501 + const rsync_acl *racl)
503 + static int access_match = -1, default_match = -1;
504 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
505 + size_t count = racl_list->count;
507 + /* If this is the first time through or we didn't match the last
508 + * time, then start at the end of the list, which should be the
509 + * best place to start hunting. */
511 + *match = racl_list->count - 1;
513 + rsync_acl *base = racl_list->items;
514 + if (rsync_acl_equal(base + *match, racl))
517 + *match = racl_list->count - 1;
524 +/* Return the Access Control List for the given filename. */
525 +int get_acl(const char *fname, statx *sxp)
527 + SMB_ACL_TYPE_T type;
529 + if (S_ISLNK(sxp->st.st_mode))
532 + type = SMB_ACL_TYPE_ACCESS;
534 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
535 + rsync_acl *racl = new(rsync_acl);
538 + out_of_memory("get_acl");
539 + *racl = empty_rsync_acl;
540 + if (type == SMB_ACL_TYPE_ACCESS)
541 + sxp->acc_acl = racl;
543 + sxp->def_acl = racl;
546 + BOOL ok = unpack_smb_acl(racl, sacl);
548 + sys_acl_free_acl(sacl);
553 + } else if (errno == ENOTSUP || errno == ENOSYS) {
554 + /* ACLs are not supported, so pretend we have a basic ACL. */
555 + if (type == SMB_ACL_TYPE_ACCESS)
556 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
558 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
559 + fname, str_acl_type(type));
563 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
568 +/* === Send functions === */
570 +/* The general strategy with the tag_type <-> character mapping is that
571 + * lowercase implies that no qualifier follows, where uppercase does.
572 + * A similar idiom for the ACL type (access or default) itself, but
573 + * lowercase in this instance means there's no ACL following, so the
574 + * ACL is a repeat, so the receiver should reuse the last of the same
577 +/* Send the ida list over the file descriptor. */
578 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
581 + size_t count = idal->count;
582 + for (ida = idal->idas; count--; ida++) {
583 + write_byte(f, tag_char);
584 + write_byte(f, ida->access);
585 + write_int(f, ida->id);
586 + /* FIXME: sorta wasteful: we should maybe buffer as
587 + * many ids as max(ACL_USER + ACL_GROUP) objects to
588 + * keep from making so many calls. */
589 + if (tag_char == 'U')
596 +/* Send an rsync ACL over the file descriptor. */
597 +static void send_rsync_acl(int f, const rsync_acl *racl)
599 + size_t count = count_racl_entries(racl);
600 + write_int(f, count);
601 + if (racl->user_obj != NO_ENTRY) {
602 + write_byte(f, 'u');
603 + write_byte(f, racl->user_obj);
605 + send_ida_entries(f, &racl->users, 'U');
606 + if (racl->group_obj != NO_ENTRY) {
607 + write_byte(f, 'g');
608 + write_byte(f, racl->group_obj);
610 + send_ida_entries(f, &racl->groups, 'G');
611 + if (racl->mask != NO_ENTRY) {
612 + write_byte(f, 'm');
613 + write_byte(f, racl->mask);
615 + if (racl->other != NO_ENTRY) {
616 + write_byte(f, 'o');
617 + write_byte(f, racl->other);
621 +/* Send the ACL from the statx structure down the indicated file descriptor.
622 + * This also frees the ACL data. */
623 +void send_acl(statx *sxp, int f)
625 + SMB_ACL_TYPE_T type;
626 + rsync_acl *racl, *new_racl;
627 + item_list *racl_list;
630 + if (S_ISLNK(sxp->st.st_mode))
633 + type = SMB_ACL_TYPE_ACCESS;
634 + racl = sxp->acc_acl;
635 + racl_list = &access_acl_list;
638 + racl = new(rsync_acl);
640 + out_of_memory("send_acl");
641 + *racl = empty_rsync_acl;
642 + if (type == SMB_ACL_TYPE_ACCESS) {
643 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
644 + sxp->acc_acl = racl;
646 + sxp->def_acl = racl;
649 + /* Avoid sending values that can be inferred from other data. */
650 + if (type == SMB_ACL_TYPE_ACCESS)
651 + rsync_acl_strip_perms(racl);
652 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
653 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
656 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
657 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
658 + send_rsync_acl(f, racl);
660 + *racl = empty_rsync_acl;
662 + racl = sxp->def_acl;
663 + racl_list = &default_acl_list;
664 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
669 +/* === Receive functions === */
671 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
673 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
674 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
675 + uchar computed_mask_bits = 0;
679 + if (!(count = read_int(f)))
683 + char tag = read_byte(f);
684 + uchar access = read_byte(f);
685 + if (access & ~ (4 | 2 | 1)) {
686 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
688 + exit_cleanup(RERR_STREAMIO);
692 + if (racl->user_obj != NO_ENTRY) {
693 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
694 + exit_cleanup(RERR_STREAMIO);
696 + racl->user_obj = access;
699 + tag_type = SMB_ACL_USER;
702 + if (racl->group_obj != NO_ENTRY) {
703 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
704 + exit_cleanup(RERR_STREAMIO);
706 + racl->group_obj = access;
709 + tag_type = SMB_ACL_GROUP;
712 + if (racl->mask != NO_ENTRY) {
713 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
714 + exit_cleanup(RERR_STREAMIO);
716 + racl->mask = access;
719 + if (racl->other != NO_ENTRY) {
720 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
721 + exit_cleanup(RERR_STREAMIO);
723 + racl->other = access;
726 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
728 + exit_cleanup(RERR_STREAMIO);
730 + if (tag_type != prior_list_type) {
731 + if (prior_list_type)
732 + save_idas(&temp_ida_list, racl, prior_list_type);
733 + prior_list_type = tag_type;
735 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
736 + ida->access = access;
737 + ida->id = read_int(f);
738 + computed_mask_bits |= access;
740 + if (prior_list_type)
741 + save_idas(&temp_ida_list, racl, prior_list_type);
743 + if (type == SMB_ACL_TYPE_DEFAULT) {
744 + /* Ensure that these are never unset. */
745 + if (racl->user_obj == NO_ENTRY)
746 + racl->user_obj = 7;
747 + if (racl->group_obj == NO_ENTRY)
748 + racl->group_obj = 0;
749 + if (racl->other == NO_ENTRY)
753 + if (!racl->users.count && !racl->groups.count) {
754 + /* If we received a superfluous mask, throw it away. */
755 + if (racl->mask != NO_ENTRY) {
756 + /* Mask off the group perms with it first. */
757 + racl->group_obj &= racl->mask | NO_ENTRY;
758 + racl->mask = NO_ENTRY;
760 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
761 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
764 +/* Receive the ACL info the sender has included for this file-list entry. */
765 +void receive_acl(struct file_struct *file, int f)
767 + SMB_ACL_TYPE_T type;
768 + item_list *racl_list;
770 + if (S_ISLNK(file->mode))
773 + type = SMB_ACL_TYPE_ACCESS;
774 + racl_list = &access_acl_list;
776 + char tag = read_byte(f);
779 + if (tag == 'A' || tag == 'a') {
780 + if (type != SMB_ACL_TYPE_ACCESS) {
781 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
782 + f_name(file, NULL));
783 + exit_cleanup(RERR_STREAMIO);
785 + } else if (tag == 'D' || tag == 'd') {
786 + if (type == SMB_ACL_TYPE_ACCESS) {
787 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
788 + f_name(file, NULL));
789 + exit_cleanup(RERR_STREAMIO);
792 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
793 + f_name(file, NULL), tag);
794 + exit_cleanup(RERR_STREAMIO);
796 + if (tag == 'A' || tag == 'D') {
798 + ndx = racl_list->count;
799 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
800 + duo_item->racl = empty_rsync_acl;
801 + receive_rsync_acl(&duo_item->racl, f, type);
802 + duo_item->sacl = NULL;
805 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
806 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
807 + f_name(file, NULL), str_acl_type(type), ndx);
808 + exit_cleanup(RERR_STREAMIO);
811 + if (type == SMB_ACL_TYPE_ACCESS)
814 + F_DEFACL(file) = ndx;
815 + racl_list = &default_acl_list;
816 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
819 +/* Turn the ACL data in statx into cached ACL data, setting the index
820 + * values in the file struct. */
821 +void cache_acl(struct file_struct *file, statx *sxp)
823 + SMB_ACL_TYPE_T type;
825 + item_list *racl_list;
828 + if (S_ISLNK(file->mode))
831 + type = SMB_ACL_TYPE_ACCESS;
832 + racl = sxp->acc_acl;
833 + racl_list = &access_acl_list;
837 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
839 + ndx = racl_list->count;
840 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
841 + new_duo->racl = *racl;
842 + new_duo->sacl = NULL;
843 + *racl = empty_rsync_acl;
845 + if (type == SMB_ACL_TYPE_ACCESS)
848 + F_DEFACL(file) = ndx;
849 + racl = sxp->def_acl;
850 + racl_list = &default_acl_list;
851 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
856 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
858 + SMB_ACL_ENTRY_T entry;
859 + const char *errfun;
862 + if (S_ISDIR(mode)) {
863 + /* If the sticky bit is going on, it's not safe to allow all
864 + * the new ACL to go into effect before it gets set. */
865 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
866 + if (mode & S_ISVTX)
869 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
872 + /* If setuid or setgid is going off, it's not safe to allow all
873 + * the new ACL to go into effect before they get cleared. */
874 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
875 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
880 + errfun = "sys_acl_get_entry";
881 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
883 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
884 + SMB_ACL_TAG_T tag_type;
885 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
886 + errfun = "sys_acl_get_tag_type";
889 + switch (tag_type) {
890 + case SMB_ACL_USER_OBJ:
891 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
893 + case SMB_ACL_GROUP_OBJ:
894 + /* group is only empty when identical to group perms. */
895 + if (racl->group_obj != NO_ENTRY)
897 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
900 +#ifndef ACLS_NEED_MASK
901 + /* mask is only empty when we don't need it. */
902 + if (racl->mask == NO_ENTRY)
905 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
907 + case SMB_ACL_OTHER:
908 + COE2( store_access_in_entry,(mode & 7, entry) );
915 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
921 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
922 + /* Ensure that chmod() will be called to restore any lost setid bits. */
923 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
924 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
925 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
928 + /* Return the mode of the file on disk, as we will set them. */
929 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
932 +/* Set ACL on indicated filename.
934 + * This sets extended access ACL entries and default ACL. If convenient,
935 + * it sets permission bits along with the access ACL and signals having
936 + * done so by modifying sxp->st.st_mode.
938 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
939 + * with fname set to NULL to just check if the ACL is unchanged. */
940 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
943 + SMB_ACL_TYPE_T type;
945 + if (!dry_run && (read_only || list_only)) {
950 + if (S_ISLNK(file->mode))
953 + type = SMB_ACL_TYPE_ACCESS;
959 + if (type == SMB_ACL_TYPE_ACCESS) {
961 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
963 + duo_item = access_acl_list.items;
966 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
968 + ndx = F_DEFACL(file);
969 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
971 + duo_item = default_acl_list.items;
974 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
978 + if (!dry_run && fname) {
979 + if (type == SMB_ACL_TYPE_DEFAULT
980 + && duo_item->racl.user_obj == NO_ENTRY) {
981 + if (sys_acl_delete_def_file(fname) < 0) {
982 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
988 + mode_t cur_mode = sxp->st.st_mode;
989 + if (!duo_item->sacl
990 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
994 + if (type == SMB_ACL_TYPE_ACCESS) {
995 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
996 + cur_mode, file->mode);
997 + if (cur_mode == (mode_t)~0)
1000 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
1001 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1002 + fname, str_acl_type(type));
1006 + if (type == SMB_ACL_TYPE_ACCESS)
1007 + sxp->st.st_mode = cur_mode;
1010 + if (unchanged == 1)
1012 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1017 +/* === Enumeration functions for uid mapping === */
1019 +/* Context -- one and only one. Should be cycled through once on uid
1020 + * mapping and once on gid mapping. */
1021 +static item_list *_enum_racl_lists[] = {
1022 + &access_acl_list, &default_acl_list, NULL
1025 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1026 +static int enum_ida_index = 0;
1027 +static size_t enum_racl_index = 0;
1029 +/* This returns the next tag_type id from the given ACL for the next entry,
1030 + * or it returns 0 if there are no more tag_type ids in the acl. */
1031 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1033 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1034 + if (enum_ida_index < idal->count) {
1035 + id_access *ida = &idal->idas[enum_ida_index++];
1038 + enum_ida_index = 0;
1042 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1044 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1046 + acl_duo *duo_item = racl_list->items;
1047 + duo_item += enum_racl_index;
1048 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1051 + enum_racl_index = 0;
1055 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1057 + for (; *enum_racl_list; enum_racl_list++) {
1058 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1062 + enum_racl_list = &_enum_racl_lists[0];
1066 +id_t *next_acl_uid()
1068 + return next_acl_list_id(SMB_ACL_USER);
1071 +id_t *next_acl_gid()
1073 + return next_acl_list_id(SMB_ACL_GROUP);
1076 +/* This is used by dest_mode(). */
1077 +int default_perms_for_dir(const char *dir)
1086 + perms = ACCESSPERMS & ~orig_umask;
1087 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1088 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1089 + if (sacl == NULL) {
1090 + /* Couldn't get an ACL. Darn. */
1094 + /* No ACLs are available. */
1098 + /* We're doing a dry run, so the containing directory
1099 + * wasn't actually created. Don't worry about it. */
1102 + /* Otherwise fall through. */
1104 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1105 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1111 + racl = empty_rsync_acl;
1112 + ok = unpack_smb_acl(&racl, sacl);
1113 + sys_acl_free_acl(sacl);
1115 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1119 + /* Apply the permission-bit entries of the default ACL, if any. */
1120 + if (racl.user_obj != NO_ENTRY) {
1121 + perms = rsync_acl_get_perms(&racl);
1123 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1126 + rsync_acl_free(&racl);
1130 +#endif /* SUPPORT_ACLS */
1137 +extern int preserve_acls;
1138 extern int preserve_devices;
1139 extern int preserve_specials;
1140 extern int preserve_links;
1141 @@ -95,7 +96,8 @@ path
1142 ****************************************************************************/
1143 static int make_bak_dir(char *fullpath)
1147 + struct file_struct *file;
1148 char *rel = fullpath + backup_dir_len;
1149 char *end = rel + strlen(rel);
1151 @@ -127,15 +129,24 @@ static int make_bak_dir(char *fullpath)
1153 /* Try to transfer the directory settings of the
1154 * actual dir that the files are coming from. */
1155 - if (do_stat(rel, &st) < 0) {
1156 + if (do_stat(rel, &sx.st) < 0) {
1157 rsyserr(FERROR, errno,
1158 "make_bak_dir stat %s failed",
1161 - do_lchown(fullpath, st.st_uid, st.st_gid);
1163 - do_chmod(fullpath, st.st_mode);
1164 +#ifdef SUPPORT_ACLS
1165 + sx.acc_acl = sx.def_acl = NULL;
1167 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1169 +#ifdef SUPPORT_ACLS
1170 + if (preserve_acls) {
1171 + get_acl(rel, &sx);
1172 + cache_acl(file, &sx);
1175 + set_file_attrs(fullpath, file, NULL, 0);
1180 @@ -173,15 +184,18 @@ static int robust_move(const char *src,
1181 * We will move the file to be deleted into a parallel directory tree. */
1182 static int keep_backup(const char *fname)
1186 struct file_struct *file;
1191 /* return if no file to keep */
1192 - if (do_lstat(fname, &st) < 0)
1193 + if (do_lstat(fname, &sx.st) < 0)
1195 +#ifdef SUPPORT_ACLS
1196 + sx.acc_acl = sx.def_acl = NULL;
1199 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1200 return 1; /* the file could have disappeared */
1201 @@ -191,6 +205,13 @@ static int keep_backup(const char *fname
1205 +#ifdef SUPPORT_ACLS
1206 + if (preserve_acls) {
1207 + get_acl(fname, &sx);
1208 + cache_acl(file, &sx);
1212 /* Check to see if this is a device file, or link */
1213 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1214 || (preserve_specials && IS_SPECIAL(file->mode))) {
1215 @@ -261,7 +282,7 @@ static int keep_backup(const char *fname
1216 if (robust_move(fname, buf) != 0) {
1217 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1218 full_fname(fname), buf);
1219 - } else if (st.st_nlink > 1) {
1220 + } else if (sx.st.st_nlink > 1) {
1221 /* If someone has hard-linked the file into the backup
1222 * dir, rename() might return success but do nothing! */
1223 robust_unlink(fname); /* Just in case... */
1224 --- old/configure.in
1225 +++ new/configure.in
1226 @@ -537,6 +537,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1227 AC_CHECK_LIB(resolv, strcasecmp)
1230 +AC_CHECK_FUNCS(aclsort)
1231 +if test x"$ac_cv_func_aclsort" = x"no"; then
1232 + AC_CHECK_LIB(sec, aclsort)
1235 dnl At the moment we don't test for a broken memcmp(), because all we
1236 dnl need to do is test for equality, not comparison, and it seems that
1237 dnl every platform has a memcmp that can do at least that.
1238 @@ -801,6 +806,78 @@ AC_SUBST(OBJ_RESTORE)
1239 AC_SUBST(CC_SHOBJ_FLAG)
1240 AC_SUBST(BUILD_POPT)
1242 +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h)
1243 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1244 +#################################################
1245 +# check for ACL support
1247 +AC_MSG_CHECKING(whether to support ACLs)
1248 +AC_ARG_ENABLE(acl-support,
1249 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1250 +[ case "$enableval" in
1253 + case "$host_os" in
1255 + AC_MSG_RESULT(Using UnixWare ACLs)
1256 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1258 + *solaris*|*cygwin*)
1259 + AC_MSG_RESULT(Using solaris ACLs)
1260 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1263 + AC_MSG_RESULT(Using HPUX ACLs)
1264 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1267 + AC_MSG_RESULT(Using IRIX ACLs)
1268 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1271 + AC_MSG_RESULT(Using AIX ACLs)
1272 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1275 + AC_MSG_RESULT(Using Tru64 ACLs)
1276 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1277 + LIBS="$LIBS -lpacl"
1280 + AC_MSG_RESULT(ACLs requested -- running tests)
1281 + AC_CHECK_LIB(acl,acl_get_file)
1282 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1283 + AC_TRY_LINK([#include <sys/types.h>
1284 +#include <sys/acl.h>],
1285 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1286 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1287 + AC_MSG_CHECKING(ACL test results)
1288 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1289 + AC_MSG_RESULT(Using posix ACLs)
1290 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1291 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1292 + AC_TRY_LINK([#include <sys/types.h>
1293 +#include <sys/acl.h>],
1294 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1295 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1296 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1297 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1300 + AC_MSG_ERROR(Failed to find ACL support)
1307 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1310 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1314 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1319 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1320 extern int one_file_system;
1321 extern int copy_dirlinks;
1322 extern int keep_dirlinks;
1323 +extern int preserve_acls;
1324 extern int preserve_links;
1325 extern int preserve_hard_links;
1326 extern int preserve_devices;
1327 @@ -143,6 +144,8 @@ static void list_file_entry(struct file_
1329 permstring(permbuf, f->mode);
1331 + /* TODO: indicate '+' if the entry has an ACL. */
1333 #ifdef SUPPORT_LINKS
1334 if (preserve_links && S_ISLNK(f->mode)) {
1335 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1336 @@ -621,6 +624,12 @@ static struct file_struct *recv_file_ent
1340 +#ifdef SUPPORT_ACLS
1341 + /* We need one or two index int32s when we're preserving ACLs. */
1342 + if (preserve_acls)
1343 + extra_len += (S_ISDIR(mode) ? 2 : 1) * sizeof (union flist_extras);
1346 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1348 alloc_len = file_struct_len + dirname_len + basename_len
1349 @@ -725,6 +734,11 @@ static struct file_struct *recv_file_ent
1350 read_buf(f, bp, checksum_len);
1353 +#ifdef SUPPORT_ACLS
1354 + if (preserve_acls)
1355 + receive_acl(file, f);
1361 @@ -969,6 +983,8 @@ void unmake_file(struct file_struct *fil
1363 union flist_extras *start = (union flist_extras *)file
1364 - (flist_extra_ndx - 1);
1365 + if (preserve_acls && S_ISDIR(file->mode))
1370 @@ -977,6 +993,9 @@ static struct file_struct *send_file_nam
1371 unsigned short flags)
1373 struct file_struct *file;
1374 +#ifdef SUPPORT_ACLS
1378 file = make_file(fname, flist, stp, flags,
1379 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1380 @@ -986,11 +1005,24 @@ static struct file_struct *send_file_nam
1381 if (chmod_modes && !S_ISLNK(file->mode))
1382 file->mode = tweak_mode(file->mode, chmod_modes);
1384 +#ifdef SUPPORT_ACLS
1385 + if (preserve_acls && f >= 0) {
1386 + sx.st.st_mode = file->mode;
1387 + sx.acc_acl = sx.def_acl = NULL;
1388 + if (get_acl(fname, &sx) < 0)
1393 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1395 flist_expand(flist);
1396 flist->files[flist->count++] = file;
1397 send_file_entry(file, f);
1398 +#ifdef SUPPORT_ACLS
1399 + if (preserve_acls && f >= 0)
1407 @@ -35,6 +35,7 @@ extern int do_progress;
1408 extern int relative_paths;
1409 extern int implied_dirs;
1410 extern int keep_dirlinks;
1411 +extern int preserve_acls;
1412 extern int preserve_links;
1413 extern int preserve_devices;
1414 extern int preserve_specials;
1415 @@ -89,6 +90,7 @@ extern int one_file_system;
1416 extern int file_struct_len;
1417 extern struct stats stats;
1418 extern dev_t filesystem_dev;
1419 +extern mode_t orig_umask;
1420 extern char *backup_dir;
1421 extern char *backup_suffix;
1422 extern int backup_suffix_len;
1423 @@ -447,22 +449,27 @@ static void do_delete_pass(struct file_l
1424 rprintf(FINFO, " \r");
1427 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1428 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1431 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1432 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1435 - if (am_root && preserve_uid && st->st_uid != F_UID(file))
1436 + if (am_root && preserve_uid && sxp->st.st_uid != F_UID(file))
1439 - if (preserve_gid && F_GID(file) != GID_NONE && st->st_gid != F_GID(file))
1440 + if (preserve_gid && F_GID(file) != GID_NONE && sxp->st.st_gid != F_GID(file))
1443 +#ifdef SUPPORT_ACLS
1444 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1451 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1452 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1453 int32 iflags, uchar fnamecmp_type, const char *xname)
1455 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1456 @@ -470,20 +477,24 @@ void itemize(struct file_struct *file, i
1457 : S_ISDIR(file->mode) ? !omit_dir_times
1458 : !S_ISLNK(file->mode);
1460 - if (S_ISREG(file->mode) && file->length != st->st_size)
1461 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1462 iflags |= ITEM_REPORT_SIZE;
1463 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1464 && !(iflags & ITEM_MATCHED)
1465 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1466 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1467 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1468 iflags |= ITEM_REPORT_TIME;
1469 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1470 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1471 iflags |= ITEM_REPORT_PERMS;
1472 - if (preserve_uid && am_root && F_UID(file) != st->st_uid)
1473 + if (preserve_uid && am_root && F_UID(file) != sxp->st.st_uid)
1474 iflags |= ITEM_REPORT_OWNER;
1475 if (preserve_gid && F_GID(file) != GID_NONE
1476 - && st->st_gid != F_GID(file))
1477 + && sxp->st.st_gid != F_GID(file))
1478 iflags |= ITEM_REPORT_GROUP;
1479 +#ifdef SUPPORT_ACLS
1480 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1481 + iflags |= ITEM_REPORT_ACL;
1484 iflags |= ITEM_IS_NEW;
1486 @@ -735,7 +746,7 @@ void check_for_finished_hlinks(int itemi
1487 * handling the file, -1 if no dest-linking occurred, or a non-negative
1488 * value if we found an alternate basis file. */
1489 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1490 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1491 + char *cmpbuf, statx *sxp, int itemizing,
1492 int maybe_ATTRS_REPORT, enum logcode code)
1494 int best_match = -1;
1495 @@ -744,7 +755,7 @@ static int try_dests_reg(struct file_str
1498 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1499 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1500 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1502 switch (match_level) {
1504 @@ -752,16 +763,20 @@ static int try_dests_reg(struct file_str
1508 - if (!unchanged_file(cmpbuf, file, stp))
1509 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1515 - if (!unchanged_attrs(file, stp))
1516 +#ifdef SUPPORT_ACLS
1517 + if (preserve_acls)
1518 + get_acl(cmpbuf, sxp);
1520 + if (!unchanged_attrs(file, sxp))
1522 if (always_checksum && preserve_times
1523 - && cmp_time(stp->st_mtime, file->modtime))
1524 + && cmp_time(sxp->st.st_mtime, file->modtime))
1528 @@ -776,7 +791,7 @@ static int try_dests_reg(struct file_str
1529 if (j != best_match) {
1531 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1532 - if (link_stat(cmpbuf, stp, 0) < 0)
1533 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1537 @@ -784,15 +799,20 @@ static int try_dests_reg(struct file_str
1538 #ifdef SUPPORT_HARD_LINKS
1540 int i = itemizing && (verbose > 1 || stdout_format_has_i > 1);
1541 - if (hard_link_one(file, ndx, fname, 0, stp,
1542 + if (hard_link_one(file, ndx, fname, 0, sxp,
1543 cmpbuf, 1, i, code) < 0)
1545 if (preserve_hard_links && IS_HLINKED(file))
1546 hard_link_cluster(file, ndx, itemizing, code, j);
1550 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1552 +#ifdef SUPPORT_ACLS
1553 + if (preserve_acls && !ACL_READY(*sxp))
1554 + get_acl(fname, sxp);
1556 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1558 if (verbose > 1 && maybe_ATTRS_REPORT) {
1559 rprintf(FCLIENT, "%s is uptodate\n", fname);
1561 @@ -808,8 +828,13 @@ static int try_dests_reg(struct file_str
1566 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1568 +#ifdef SUPPORT_ACLS
1569 + if (preserve_acls && !ACL_READY(*sxp))
1570 + get_acl(fname, sxp);
1572 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1574 set_file_attrs(fname, file, NULL, 0);
1575 if (maybe_ATTRS_REPORT
1576 && ((!itemizing && verbose && match_level == 2)
1577 @@ -830,7 +855,7 @@ static int try_dests_reg(struct file_str
1578 * handling the file, or -1 if no dest-linking occurred, or a non-negative
1579 * value if we found an alternate basis file. */
1580 static int try_dests_non(struct file_struct *file, char *fname, int ndx,
1581 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1582 + char *cmpbuf, statx *sxp, int itemizing,
1583 int maybe_ATTRS_REPORT, enum logcode code)
1585 char lnk[MAXPATHLEN];
1586 @@ -862,24 +887,24 @@ static int try_dests_non(struct file_str
1589 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1590 - if (link_stat(cmpbuf, stp, 0) < 0)
1591 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1595 - if (!S_ISDIR(stp->st_mode))
1596 + if (!S_ISDIR(sxp->st.st_mode))
1600 - if (!IS_SPECIAL(stp->st_mode))
1601 + if (!IS_SPECIAL(sxp->st.st_mode))
1605 - if (!IS_DEVICE(stp->st_mode))
1606 + if (!IS_DEVICE(sxp->st.st_mode))
1609 #ifdef SUPPORT_LINKS
1611 - if (!S_ISLNK(stp->st_mode))
1612 + if (!S_ISLNK(sxp->st.st_mode))
1616 @@ -893,7 +918,7 @@ static int try_dests_non(struct file_str
1620 - if (stp->st_rdev != MAKEDEV(F_DMAJOR(file), F_DMINOR(file)))
1621 + if (sxp->st.st_rdev != MAKEDEV(F_DMAJOR(file), F_DMINOR(file)))
1624 #ifdef SUPPORT_LINKS
1625 @@ -910,7 +935,11 @@ static int try_dests_non(struct file_str
1629 - if (unchanged_attrs(file, stp)) {
1630 +#ifdef SUPPORT_ACLS
1631 + if (preserve_acls)
1632 + get_acl(cmpbuf, sxp);
1634 + if (unchanged_attrs(file, sxp)) {
1638 @@ -923,7 +952,7 @@ static int try_dests_non(struct file_str
1639 if (j != best_match) {
1641 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1642 - if (link_stat(cmpbuf, stp, 0) < 0)
1643 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1647 @@ -954,7 +983,15 @@ static int try_dests_non(struct file_str
1649 + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
1650 char *lp = match_level == 3 ? "" : NULL;
1651 - itemize(file, ndx, 0, stp, chg + ITEM_MATCHED, 0, lp);
1652 +#ifdef SUPPORT_ACLS
1653 + if (preserve_acls)
1654 + get_acl(fname, sxp);
1656 + itemize(file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp);
1657 +#ifdef SUPPORT_ACLS
1658 + if (preserve_acls)
1662 if (verbose > 1 && maybe_ATTRS_REPORT) {
1663 rprintf(FCLIENT, "%s%s is uptodate\n",
1664 @@ -967,6 +1004,7 @@ static int try_dests_non(struct file_str
1667 static int phase = 0;
1668 +static int dflt_perms;
1670 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1671 * make sure it exists, and has the right permissions/timestamp info. For
1672 @@ -988,7 +1026,8 @@ static void recv_generator(char *fname,
1673 static int need_fuzzy_dirlist = 0;
1674 struct file_struct *fuzzy_file = NULL;
1675 int fd = -1, f_copy = -1;
1676 - STRUCT_STAT st, real_st, partial_st;
1677 + statx sx, real_sx;
1678 + STRUCT_STAT partial_st;
1679 struct file_struct *back_file = NULL;
1680 int statret, real_ret, stat_errno;
1681 char *fnamecmp, *partialptr, *backupptr = NULL;
1682 @@ -1044,6 +1083,9 @@ static void recv_generator(char *fname,
1683 } else if (!dry_run)
1686 +#ifdef SUPPORT_ACLS
1687 + sx.acc_acl = sx.def_acl = NULL;
1691 stat_errno = ENOENT;
1692 @@ -1051,7 +1093,7 @@ static void recv_generator(char *fname,
1693 const char *dn = file->dirname ? file->dirname : ".";
1694 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1695 if (relative_paths && !implied_dirs
1696 - && do_stat(dn, &st) < 0
1697 + && do_stat(dn, &sx.st) < 0
1698 && create_directory_path(fname) < 0) {
1699 rsyserr(FERROR, errno,
1700 "recv_generator: mkdir %s failed",
1701 @@ -1063,6 +1105,10 @@ static void recv_generator(char *fname,
1704 need_fuzzy_dirlist = 1;
1705 +#ifdef SUPPORT_ACLS
1706 + if (!preserve_perms)
1707 + dflt_perms = default_perms_for_dir(dn);
1710 parent_dirname = dn;
1712 @@ -1072,7 +1118,7 @@ static void recv_generator(char *fname,
1713 need_fuzzy_dirlist = 0;
1716 - statret = link_stat(fname, &st,
1717 + statret = link_stat(fname, &sx.st,
1718 keep_dirlinks && S_ISDIR(file->mode));
1721 @@ -1090,8 +1136,9 @@ static void recv_generator(char *fname,
1722 * mode based on the local permissions and some heuristics. */
1723 if (!preserve_perms) {
1724 int exists = statret == 0
1725 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1726 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1727 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1728 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1732 if (S_ISDIR(file->mode)) {
1733 @@ -1100,8 +1147,8 @@ static void recv_generator(char *fname,
1734 * file of that name and it is *not* a directory, then
1735 * we need to delete it. If it doesn't exist, then
1736 * (perhaps recursively) create it. */
1737 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1738 - if (delete_item(fname, st.st_mode, "directory", del_opts) != 0)
1739 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1740 + if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0)
1744 @@ -1110,14 +1157,14 @@ static void recv_generator(char *fname,
1751 if (*fname == '.' && fname[1] == '\0')
1755 if (statret != 0 && basis_dir[0] != NULL) {
1756 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1757 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1758 itemizing, maybe_ATTRS_REPORT, code);
1761 @@ -1126,7 +1173,11 @@ static void recv_generator(char *fname,
1764 if (itemizing && f_out != -1) {
1765 - itemize(file, ndx, statret, &st,
1766 +#ifdef SUPPORT_ACLS
1767 + if (preserve_acls && statret == 0)
1768 + get_acl(fname, &sx);
1770 + itemize(file, ndx, statret, &sx,
1771 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1773 if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1774 @@ -1146,21 +1197,21 @@ static void recv_generator(char *fname,
1778 - if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0)
1779 + if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, 0)
1780 && verbose && code != FNONE && f_out != -1)
1781 rprintf(code, "%s/\n", fname);
1782 if (real_ret != 0 && one_file_system)
1783 - real_st.st_dev = filesystem_dev;
1784 + real_sx.st.st_dev = filesystem_dev;
1785 if (delete_during && f_out != -1 && !phase && dry_run < 2
1786 && (file->flags & FLAG_XFER_DIR))
1787 - delete_in_dir(the_file_list, fname, file, &real_st);
1789 + delete_in_dir(the_file_list, fname, file, &real_sx.st);
1793 if (preserve_hard_links && IS_HLINKED(file)
1794 - && hard_link_check(file, ndx, fname, statret, &st,
1795 + && hard_link_check(file, ndx, fname, statret, &sx,
1796 itemizing, code, HL_CHECK_MASTER))
1800 if (preserve_links && S_ISLNK(file->mode)) {
1801 #ifdef SUPPORT_LINKS
1802 @@ -1179,14 +1230,14 @@ static void recv_generator(char *fname,
1803 char lnk[MAXPATHLEN];
1806 - if (!S_ISLNK(st.st_mode))
1807 + if (!S_ISLNK(sx.st.st_mode))
1809 else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0
1810 && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
1811 /* The link is pointing to the right place. */
1813 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1814 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1815 + itemize(file, ndx, 0, &sx, 0, 0, NULL);
1816 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1817 if (preserve_hard_links && IS_HLINKED(file))
1818 hard_link_cluster(file, ndx, itemizing, code, -1);
1819 if (remove_source_files == 1)
1820 @@ -1195,10 +1246,10 @@ static void recv_generator(char *fname,
1822 /* Not the right symlink (or not a symlink), so
1824 - if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0)
1825 + if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0)
1827 } else if (basis_dir[0] != NULL) {
1828 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1829 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1830 itemizing, maybe_ATTRS_REPORT, code);
1832 #ifndef CAN_HARDLINK_SYMLINK
1833 @@ -1214,7 +1265,7 @@ static void recv_generator(char *fname,
1836 if (preserve_hard_links && IS_HLINKED(file)
1837 - && hard_link_check(file, ndx, fname, -1, &st,
1838 + && hard_link_check(file, ndx, fname, -1, &sx,
1839 itemizing, code, HL_SKIP))
1841 if (do_symlink(sl, fname) != 0) {
1842 @@ -1223,7 +1274,7 @@ static void recv_generator(char *fname,
1844 set_file_attrs(fname, file, NULL, 0);
1846 - itemize(file, ndx, statret, &st,
1847 + itemize(file, ndx, statret, &sx,
1848 ITEM_LOCAL_CHANGE, 0, NULL);
1850 if (code != FNONE && verbose)
1851 @@ -1246,31 +1297,36 @@ static void recv_generator(char *fname,
1854 if (IS_DEVICE(file->mode)) {
1855 - if (!IS_DEVICE(st.st_mode))
1856 + if (!IS_DEVICE(sx.st.st_mode))
1860 - if (!IS_SPECIAL(st.st_mode))
1861 + if (!IS_SPECIAL(sx.st.st_mode))
1866 - && (st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
1867 - && st.st_rdev == rdev) {
1868 + && (sx.st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
1869 + && sx.st.st_rdev == rdev) {
1870 /* The device or special file is identical. */
1872 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1873 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1875 +#ifdef SUPPORT_ACLS
1876 + if (preserve_acls)
1877 + get_acl(fname, &sx);
1879 + itemize(file, ndx, 0, &sx, 0, 0, NULL);
1881 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1882 if (preserve_hard_links && IS_HLINKED(file))
1883 hard_link_cluster(file, ndx, itemizing, code, -1);
1884 if (remove_source_files == 1)
1885 goto return_with_success;
1889 - if (delete_item(fname, st.st_mode, t, del_opts) != 0)
1890 + if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0)
1892 } else if (basis_dir[0] != NULL) {
1893 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1894 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1895 itemizing, maybe_ATTRS_REPORT, code);
1897 #ifndef CAN_HARDLINK_SPECIAL
1898 @@ -1286,7 +1342,7 @@ static void recv_generator(char *fname,
1901 if (preserve_hard_links && IS_HLINKED(file)
1902 - && hard_link_check(file, ndx, fname, -1, &st,
1903 + && hard_link_check(file, ndx, fname, -1, &sx,
1904 itemizing, code, HL_SKIP))
1907 @@ -1299,7 +1355,11 @@ static void recv_generator(char *fname,
1909 set_file_attrs(fname, file, NULL, 0);
1911 - itemize(file, ndx, statret, &st,
1912 +#ifdef SUPPORT_ACLS
1913 + if (preserve_acls && statret == 0)
1914 + get_acl(fname, &sx);
1916 + itemize(file, ndx, statret, &sx,
1917 ITEM_LOCAL_CHANGE, 0, NULL);
1919 if (code != FNONE && verbose)
1920 @@ -1309,7 +1369,7 @@ static void recv_generator(char *fname,
1921 if (remove_source_files == 1)
1922 goto return_with_success;
1928 if (!S_ISREG(file->mode)) {
1929 @@ -1343,7 +1403,7 @@ static void recv_generator(char *fname,
1932 if (update_only && statret == 0
1933 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1934 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1936 rprintf(FINFO, "%s is newer\n", fname);
1938 @@ -1352,20 +1412,20 @@ static void recv_generator(char *fname,
1940 fnamecmp_type = FNAMECMP_FNAME;
1942 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1943 - if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0)
1944 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1945 + if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0)
1948 stat_errno = ENOENT;
1951 if (statret != 0 && basis_dir[0] != NULL) {
1952 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1953 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1954 itemizing, maybe_ATTRS_REPORT, code);
1956 if (remove_source_files == 1)
1957 goto return_with_success;
1962 fnamecmp = fnamecmpbuf;
1963 @@ -1375,7 +1435,7 @@ static void recv_generator(char *fname,
1970 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1971 && link_stat(partialptr, &partial_st, 0) == 0
1972 @@ -1394,7 +1454,7 @@ static void recv_generator(char *fname,
1973 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1974 fname, fnamecmpbuf);
1976 - st.st_size = fuzzy_file->length;
1977 + sx.st.st_size = fuzzy_file->length;
1979 fnamecmp = fnamecmpbuf;
1980 fnamecmp_type = FNAMECMP_FUZZY;
1981 @@ -1403,7 +1463,7 @@ static void recv_generator(char *fname,
1984 if (preserve_hard_links && IS_HLINKED(file)
1985 - && hard_link_check(file, ndx, fname, statret, &st,
1986 + && hard_link_check(file, ndx, fname, statret, &sx,
1987 itemizing, code, HL_SKIP))
1989 if (stat_errno == ENOENT)
1990 @@ -1413,36 +1473,49 @@ static void recv_generator(char *fname,
1994 - if (append_mode && st.st_size > file->length)
1995 + if (append_mode && sx.st.st_size > file->length)
1998 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
2000 else if (fnamecmp_type == FNAMECMP_FUZZY)
2002 - else if (unchanged_file(fnamecmp, file, &st)) {
2003 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
2005 do_unlink(partialptr);
2006 handle_partial_dir(partialptr, PDIR_DELETE);
2009 - itemize(file, ndx, real_ret, &real_st,
2010 +#ifdef SUPPORT_ACLS
2011 + if (preserve_acls && real_ret == 0)
2012 + get_acl(fnamecmp, &real_sx);
2014 + itemize(file, ndx, real_ret, &real_sx,
2016 +#ifdef SUPPORT_ACLS
2017 + if (preserve_acls) {
2018 + if (fnamecmp_type == FNAMECMP_FNAME) {
2019 + sx.acc_acl = real_sx.acc_acl;
2020 + sx.def_acl = real_sx.def_acl;
2022 + free_acl(&real_sx);
2026 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
2027 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
2028 if (preserve_hard_links && IS_HLINKED(file))
2029 hard_link_cluster(file, ndx, itemizing, code, -1);
2030 if (remove_source_files != 1)
2033 return_with_success:
2035 send_msg_int(MSG_SUCCESS, ndx);
2043 + sx.st = partial_st;
2044 fnamecmp = partialptr;
2045 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2047 @@ -1466,17 +1539,21 @@ static void recv_generator(char *fname,
2049 /* pretend the file didn't exist */
2050 if (preserve_hard_links && IS_HLINKED(file)
2051 - && hard_link_check(file, ndx, fname, statret, &st,
2052 + && hard_link_check(file, ndx, fname, statret, &sx,
2053 itemizing, code, HL_SKIP))
2056 statret = real_ret = -1;
2057 +#ifdef SUPPORT_ACLS
2058 + if (preserve_acls && ACL_READY(sx))
2064 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2065 if (!(backupptr = get_backup_name(fname))) {
2070 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2072 @@ -1487,7 +1564,7 @@ static void recv_generator(char *fname,
2073 full_fname(backupptr));
2074 unmake_file(back_file);
2079 if ((f_copy = do_open(backupptr,
2080 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2081 @@ -1495,14 +1572,14 @@ static void recv_generator(char *fname,
2082 full_fname(backupptr));
2083 unmake_file(back_file);
2088 fnamecmp_type = FNAMECMP_BACKUP;
2092 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2093 - fnamecmp, (double)st.st_size);
2094 + fnamecmp, (double)sx.st.st_size);
2098 @@ -1520,24 +1597,32 @@ static void recv_generator(char *fname,
2099 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2100 if (fnamecmp_type == FNAMECMP_FUZZY)
2101 iflags |= ITEM_XNAME_FOLLOWS;
2102 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2103 +#ifdef SUPPORT_ACLS
2104 + if (preserve_acls && real_ret == 0)
2105 + get_acl(fnamecmp, &real_sx);
2107 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2108 fuzzy_file ? fuzzy_file->basename : NULL);
2109 +#ifdef SUPPORT_ACLS
2110 + if (preserve_acls)
2111 + free_acl(&real_sx);
2116 if (preserve_hard_links && IS_HLINKED(file))
2117 hard_link_cluster(file, ndx, itemizing, code, -1);
2125 if (statret != 0 || whole_file) {
2126 write_sum_head(f_out, NULL);
2131 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2132 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2136 @@ -1550,6 +1635,13 @@ static void recv_generator(char *fname,
2142 +#ifdef SUPPORT_ACLS
2143 + if (preserve_acls)
2149 void generate_files(int f_out, struct file_list *flist, char *local_name)
2150 @@ -1611,6 +1703,8 @@ void generate_files(int f_out, struct fi
2151 * notice that and let us know via the redo pipe (or its closing). */
2154 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2156 for (i = 0; i < flist->count; i++) {
2157 struct file_struct *file = flist->files[i];
2161 @@ -27,6 +27,7 @@ extern int verbose;
2163 extern int do_xfers;
2164 extern int link_dest;
2165 +extern int preserve_acls;
2166 extern int make_backups;
2167 extern int flist_extra_ndx;
2168 extern int remove_source_files;
2169 @@ -155,15 +156,19 @@ void init_hard_links(void)
2171 #ifdef SUPPORT_HARD_LINKS
2172 static int maybe_hard_link(struct file_struct *file, int ndx,
2173 - char *fname, int statret, STRUCT_STAT *st,
2174 + char *fname, int statret, statx *sxp,
2175 char *toname, STRUCT_STAT *to_st,
2176 int itemizing, enum logcode code)
2179 - if (st->st_dev == to_st->st_dev
2180 - && st->st_ino == to_st->st_ino) {
2181 + if (sxp->st.st_dev == to_st->st_dev
2182 + && sxp->st.st_ino == to_st->st_ino) {
2184 - itemize(file, ndx, statret, st,
2185 +#ifdef SUPPORT_ACLS
2186 + if (preserve_acls && !ACL_READY(*sxp))
2187 + get_acl(fname, sxp);
2189 + itemize(file, ndx, statret, sxp,
2190 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2193 @@ -178,13 +183,13 @@ static int maybe_hard_link(struct file_s
2197 - return hard_link_one(file, ndx, fname, statret, st, toname,
2198 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2199 0, itemizing, code);
2203 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2204 - int statret, STRUCT_STAT *st, int itemizing,
2205 + int statret, statx *sxp, int itemizing,
2206 enum logcode code, int skip)
2208 #ifdef SUPPORT_HARD_LINKS
2209 @@ -228,7 +233,7 @@ int hard_link_check(struct file_struct *
2210 || st2.st_ino != st3.st_ino)
2215 if (verbose < 2 || !stdout_format_has_i) {
2218 @@ -238,12 +243,16 @@ int hard_link_check(struct file_struct *
2219 if (!unchanged_file(cmpbuf, file, &st3))
2223 - if (unchanged_attrs(file, &st3))
2225 +#ifdef SUPPORT_ACLS
2226 + if (preserve_acls)
2227 + get_acl(cmpbuf, sxp);
2229 + if (unchanged_attrs(file, sxp))
2231 } while (basis_dir[++j] != NULL);
2233 - maybe_hard_link(file, ndx, fname, statret, st,
2234 + maybe_hard_link(file, ndx, fname, statret, sxp,
2235 toname, &st2, itemizing, code);
2236 if (remove_source_files == 1 && do_xfers)
2237 send_msg_int(MSG_SUCCESS, ndx);
2238 @@ -258,7 +267,7 @@ int hard_link_check(struct file_struct *
2240 #ifdef SUPPORT_HARD_LINKS
2241 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2242 - int statret, STRUCT_STAT *st, char *toname, int terse,
2243 + int statret, statx *sxp, char *toname, int terse,
2244 int itemizing, enum logcode code)
2246 if (do_link(toname, fname)) {
2247 @@ -274,7 +283,11 @@ int hard_link_one(struct file_struct *fi
2251 - itemize(file, ndx, statret, st,
2252 +#ifdef SUPPORT_ACLS
2253 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2254 + get_acl(fname, sxp);
2256 + itemize(file, ndx, statret, sxp,
2257 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2258 terse ? "" : toname);
2260 @@ -291,14 +304,15 @@ void hard_link_cluster(struct file_struc
2261 #ifdef SUPPORT_HARD_LINKS
2262 char hlink1[MAXPATHLEN];
2264 - STRUCT_STAT st1, st2;
2267 int statret, ndx = master;
2268 struct hlist *hl = F_HLIST(file);
2270 hl->hlindex = FINISHED_LINK;
2272 hl->dest_used = dest_used + 1;
2273 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2274 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2276 if (!(file->flags & FLAG_HLINK_FIRST)) {
2277 while (!(file->flags & FLAG_HLINK_LAST)) {
2278 @@ -314,9 +328,13 @@ void hard_link_cluster(struct file_struc
2279 if (hl->hlindex != SKIPPED_LINK)
2281 hlink2 = f_name(file, NULL);
2282 - statret = link_stat(hlink2, &st2, 0);
2283 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2284 - hlink1, &st1, itemizing, code);
2285 + statret = link_stat(hlink2, &sx.st, 0);
2286 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2287 + hlink1, &st, itemizing, code);
2288 +#ifdef SUPPORT_ACLS
2289 + if (preserve_acls)
2292 if (remove_source_files == 1 && do_xfers)
2293 send_msg_int(MSG_SUCCESS, ndx);
2294 hl->hlindex = FINISHED_LINK;
2295 --- old/lib/sysacls.c
2296 +++ new/lib/sysacls.c
2299 + Unix SMB/CIFS implementation.
2300 + Samba system utilities for ACL support.
2301 + Copyright (C) Jeremy Allison 2000.
2303 + This program is free software; you can redistribute it and/or modify
2304 + it under the terms of the GNU General Public License as published by
2305 + the Free Software Foundation; either version 2 of the License, or
2306 + (at your option) any later version.
2308 + This program is distributed in the hope that it will be useful,
2309 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2310 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2311 + GNU General Public License for more details.
2313 + You should have received a copy of the GNU General Public License
2314 + along with this program; if not, write to the Free Software
2315 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2319 +#include "sysacls.h" /****** ADDED ******/
2321 +#ifdef SUPPORT_ACLS
2323 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2329 +void SAFE_FREE(void *mem)
2335 +char *uidtoname(uid_t uid)
2337 + static char idbuf[12];
2338 + struct passwd *pw;
2340 + if ((pw = getpwuid(uid)) == NULL) {
2341 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2344 + return pw->pw_name;
2346 +/****** EXTRAS -- END ******/
2349 + This file wraps all differing system ACL interfaces into a consistent
2350 + one based on the POSIX interface. It also returns the correct errors
2351 + for older UNIX systems that don't support ACLs.
2353 + The interfaces that each ACL implementation must support are as follows :
2355 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2356 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2357 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2358 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2359 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2360 + SMB_ACL_T sys_acl_get_fd(int fd)
2361 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2362 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2363 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2364 + SMB_ACL_T sys_acl_init( int count)
2365 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2366 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2367 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2368 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2369 + int sys_acl_valid( SMB_ACL_T theacl )
2370 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2371 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2372 + int sys_acl_delete_def_file(const char *path)
2374 + This next one is not POSIX complient - but we *have* to have it !
2375 + More POSIX braindamage.
2377 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2379 + The generic POSIX free is the following call. We split this into
2380 + several different free functions as we may need to add tag info
2381 + to structures when emulating the POSIX interface.
2383 + int sys_acl_free( void *obj_p)
2385 + The calls we actually use are :
2387 + int sys_acl_free_text(char *text) - free acl_to_text
2388 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2389 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2393 +#if defined(HAVE_POSIX_ACLS)
2395 +/* Identity mapping - easy. */
2397 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2399 + return acl_get_entry( the_acl, entry_id, entry_p);
2402 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2404 + return acl_get_tag_type( entry_d, tag_type_p);
2407 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2409 + return acl_get_permset( entry_d, permset_p);
2412 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2414 + return acl_get_qualifier( entry_d);
2417 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2419 + return acl_get_file( path_p, type);
2422 +SMB_ACL_T sys_acl_get_fd(int fd)
2424 + return acl_get_fd(fd);
2427 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2429 + return acl_clear_perms(permset);
2432 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2434 + return acl_add_perm(permset, perm);
2437 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2439 +#if defined(HAVE_ACL_GET_PERM_NP)
2441 + * Required for TrustedBSD-based ACL implementations where
2442 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2445 + return acl_get_perm_np(permset, perm);
2447 + return acl_get_perm(permset, perm);
2451 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2453 + return acl_to_text( the_acl, plen);
2456 +SMB_ACL_T sys_acl_init( int count)
2458 + return acl_init(count);
2461 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2463 + return acl_create_entry(pacl, pentry);
2466 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2468 + return acl_set_tag_type(entry, tagtype);
2471 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2473 + return acl_set_qualifier(entry, qual);
2476 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2478 + return acl_set_permset(entry, permset);
2481 +int sys_acl_valid( SMB_ACL_T theacl )
2483 + return acl_valid(theacl);
2486 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2488 + return acl_set_file(name, acltype, theacl);
2491 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2493 + return acl_set_fd(fd, theacl);
2496 +int sys_acl_delete_def_file(const char *name)
2498 + return acl_delete_def_file(name);
2501 +int sys_acl_free_text(char *text)
2503 + return acl_free(text);
2506 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2508 + return acl_free(the_acl);
2511 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2513 + return acl_free(qual);
2516 +#elif defined(HAVE_TRU64_ACLS)
2518 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2519 + * is based on Draft 13 of the POSIX spec which is
2520 + * slightly different from the Draft 16 interface.
2522 + * Also, some of the permset manipulation functions
2523 + * such as acl_clear_perm() and acl_add_perm() appear
2524 + * to be broken on Tru64 so we have to manipulate
2525 + * the permission bits in the permset directly.
2527 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2529 + SMB_ACL_ENTRY_T entry;
2531 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2536 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2541 + return errno ? -1 : 0;
2544 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2546 + return acl_get_tag_type( entry_d, tag_type_p);
2549 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2551 + return acl_get_permset( entry_d, permset_p);
2554 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2556 + return acl_get_qualifier( entry_d);
2559 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2561 + return acl_get_file((char *)path_p, type);
2564 +SMB_ACL_T sys_acl_get_fd(int fd)
2566 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2569 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2571 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2576 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2578 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2583 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2588 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2590 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2593 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2595 + return acl_to_text( the_acl, plen);
2598 +SMB_ACL_T sys_acl_init( int count)
2600 + return acl_init(count);
2603 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2605 + SMB_ACL_ENTRY_T entry;
2607 + if ((entry = acl_create_entry(pacl)) == NULL) {
2615 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2617 + return acl_set_tag_type(entry, tagtype);
2620 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2622 + return acl_set_qualifier(entry, qual);
2625 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2627 + return acl_set_permset(entry, permset);
2630 +int sys_acl_valid( SMB_ACL_T theacl )
2632 + acl_entry_t entry;
2634 + return acl_valid(theacl, &entry);
2637 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2639 + return acl_set_file((char *)name, acltype, theacl);
2642 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2644 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2647 +int sys_acl_delete_def_file(const char *name)
2649 + return acl_delete_def_file((char *)name);
2652 +int sys_acl_free_text(char *text)
2655 + * (void) cast and explicit return 0 are for DEC UNIX
2656 + * which just #defines acl_free_text() to be free()
2658 + (void) acl_free_text(text);
2662 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2664 + return acl_free(the_acl);
2667 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2669 + return acl_free_qualifier(qual, tagtype);
2672 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2675 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2676 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2680 + * Note that while this code implements sufficient functionality
2681 + * to support the sys_acl_* interfaces it does not provide all
2682 + * of the semantics of the POSIX ACL interfaces.
2684 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2685 + * from a call to sys_acl_get_entry() should not be assumed to be
2686 + * valid after calling any of the following functions, which may
2687 + * reorder the entries in the ACL.
2690 + * sys_acl_set_file()
2691 + * sys_acl_set_fd()
2695 + * The only difference between Solaris and UnixWare / OpenUNIX is
2696 + * that the #defines for the ACL operations have different names
2698 +#if defined(HAVE_UNIXWARE_ACLS)
2700 +#define SETACL ACL_SET
2701 +#define GETACL ACL_GET
2702 +#define GETACLCNT ACL_CNT
2707 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2709 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2714 + if (entry_p == NULL) {
2719 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2723 + if (acl_d->next < 0) {
2728 + if (acl_d->next >= acl_d->count) {
2732 + *entry_p = &acl_d->acl[acl_d->next++];
2737 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2739 + *type_p = entry_d->a_type;
2744 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2746 + *permset_p = &entry_d->a_perm;
2751 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2753 + if (entry_d->a_type != SMB_ACL_USER
2754 + && entry_d->a_type != SMB_ACL_GROUP) {
2759 + return &entry_d->a_id;
2763 + * There is no way of knowing what size the ACL returned by
2764 + * GETACL will be unless you first call GETACLCNT which means
2765 + * making an additional system call.
2767 + * In the hope of avoiding the cost of the additional system
2768 + * call in most cases, we initially allocate enough space for
2769 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2770 + * be too small then we use GETACLCNT to find out the actual
2771 + * size, reallocate the ACL buffer, and then call GETACL again.
2774 +#define INITIAL_ACL_SIZE 16
2776 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2779 + int count; /* # of ACL entries allocated */
2780 + int naccess; /* # of access ACL entries */
2781 + int ndefault; /* # of default ACL entries */
2783 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2788 + count = INITIAL_ACL_SIZE;
2789 + if ((acl_d = sys_acl_init(count)) == NULL) {
2794 + * If there isn't enough space for the ACL entries we use
2795 + * GETACLCNT to determine the actual number of ACL entries
2796 + * reallocate and try again. This is in a loop because it
2797 + * is possible that someone else could modify the ACL and
2798 + * increase the number of entries between the call to
2799 + * GETACLCNT and the call to GETACL.
2801 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2802 + && errno == ENOSPC) {
2804 + sys_acl_free_acl(acl_d);
2806 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2810 + if ((acl_d = sys_acl_init(count)) == NULL) {
2816 + sys_acl_free_acl(acl_d);
2821 + * calculate the number of access and default ACL entries
2823 + * Note: we assume that the acl() system call returned a
2824 + * well formed ACL which is sorted so that all of the
2825 + * access ACL entries preceed any default ACL entries
2827 + for (naccess = 0; naccess < count; naccess++) {
2828 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2831 + ndefault = count - naccess;
2834 + * if the caller wants the default ACL we have to copy
2835 + * the entries down to the start of the acl[] buffer
2836 + * and mask out the ACL_DEFAULT flag from the type field
2838 + if (type == SMB_ACL_TYPE_DEFAULT) {
2841 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2842 + acl_d->acl[i] = acl_d->acl[j];
2843 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2846 + acl_d->count = ndefault;
2848 + acl_d->count = naccess;
2854 +SMB_ACL_T sys_acl_get_fd(int fd)
2857 + int count; /* # of ACL entries allocated */
2858 + int naccess; /* # of access ACL entries */
2860 + count = INITIAL_ACL_SIZE;
2861 + if ((acl_d = sys_acl_init(count)) == NULL) {
2865 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2866 + && errno == ENOSPC) {
2868 + sys_acl_free_acl(acl_d);
2870 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2874 + if ((acl_d = sys_acl_init(count)) == NULL) {
2880 + sys_acl_free_acl(acl_d);
2885 + * calculate the number of access ACL entries
2887 + for (naccess = 0; naccess < count; naccess++) {
2888 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2892 + acl_d->count = naccess;
2897 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2904 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2906 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2907 + && perm != SMB_ACL_EXECUTE) {
2912 + if (permset_d == NULL) {
2917 + *permset_d |= perm;
2922 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2924 + return *permset_d & perm;
2927 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2934 + * use an initial estimate of 20 bytes per ACL entry
2935 + * when allocating memory for the text representation
2939 + maxlen = 20 * acl_d->count;
2940 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2945 + for (i = 0; i < acl_d->count; i++) {
2946 + struct acl *ap = &acl_d->acl[i];
2955 + switch (ap->a_type) {
2957 + * for debugging purposes it's probably more
2958 + * useful to dump unknown tag types rather
2959 + * than just returning an error
2962 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2965 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2970 + case SMB_ACL_USER:
2971 + id = uidtoname(ap->a_id);
2972 + case SMB_ACL_USER_OBJ:
2976 + case SMB_ACL_GROUP:
2977 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2978 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2984 + case SMB_ACL_GROUP_OBJ:
2988 + case SMB_ACL_OTHER:
2992 + case SMB_ACL_MASK:
2998 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2999 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3000 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3003 + /* <tag> : <qualifier> : rwx \n \0 */
3004 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3007 + * If this entry would overflow the buffer
3008 + * allocate enough additional memory for this
3009 + * entry and an estimate of another 20 bytes
3010 + * for each entry still to be processed
3012 + if ((len + nbytes) > maxlen) {
3013 + char *oldtext = text;
3015 + maxlen += nbytes + 20 * (acl_d->count - i);
3017 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3018 + SAFE_FREE(oldtext);
3024 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3025 + len += nbytes - 1;
3034 +SMB_ACL_T sys_acl_init(int count)
3044 + * note that since the definition of the structure pointed
3045 + * to by the SMB_ACL_T includes the first element of the
3046 + * acl[] array, this actually allocates an ACL with room
3047 + * for (count+1) entries
3049 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3054 + a->size = count + 1;
3062 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3065 + SMB_ACL_ENTRY_T entry_d;
3067 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3072 + if (acl_d->count >= acl_d->size) {
3077 + entry_d = &acl_d->acl[acl_d->count++];
3078 + entry_d->a_type = 0;
3079 + entry_d->a_id = -1;
3080 + entry_d->a_perm = 0;
3081 + *entry_p = entry_d;
3086 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3088 + switch (tag_type) {
3089 + case SMB_ACL_USER:
3090 + case SMB_ACL_USER_OBJ:
3091 + case SMB_ACL_GROUP:
3092 + case SMB_ACL_GROUP_OBJ:
3093 + case SMB_ACL_OTHER:
3094 + case SMB_ACL_MASK:
3095 + entry_d->a_type = tag_type;
3105 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3107 + if (entry_d->a_type != SMB_ACL_GROUP
3108 + && entry_d->a_type != SMB_ACL_USER) {
3113 + entry_d->a_id = *((id_t *)qual_p);
3118 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3120 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3124 + entry_d->a_perm = *permset_d;
3130 + * sort the ACL and check it for validity
3132 + * if it's a minimal ACL with only 4 entries then we
3133 + * need to recalculate the mask permissions to make
3134 + * sure that they are the same as the GROUP_OBJ
3135 + * permissions as required by the UnixWare acl() system call.
3137 + * (note: since POSIX allows minimal ACLs which only contain
3138 + * 3 entries - ie there is no mask entry - we should, in theory,
3139 + * check for this and add a mask entry if necessary - however
3140 + * we "know" that the caller of this interface always specifies
3141 + * a mask so, in practice "this never happens" (tm) - if it *does*
3142 + * happen aclsort() will fail and return an error and someone will
3143 + * have to fix it ...)
3146 +static int acl_sort(SMB_ACL_T acl_d)
3148 + int fixmask = (acl_d->count <= 4);
3150 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3157 +int sys_acl_valid(SMB_ACL_T acl_d)
3159 + return acl_sort(acl_d);
3162 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3165 + struct acl *acl_p;
3167 + struct acl *acl_buf = NULL;
3170 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3175 + if (acl_sort(acl_d) != 0) {
3179 + acl_p = &acl_d->acl[0];
3180 + acl_count = acl_d->count;
3183 + * if it's a directory there is extra work to do
3184 + * since the acl() system call will replace both
3185 + * the access ACLs and the default ACLs (if any)
3187 + if (stat(name, &s) != 0) {
3190 + if (S_ISDIR(s.st_mode)) {
3191 + SMB_ACL_T acc_acl;
3192 + SMB_ACL_T def_acl;
3193 + SMB_ACL_T tmp_acl;
3196 + if (type == SMB_ACL_TYPE_ACCESS) {
3198 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3202 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3205 + if (tmp_acl == NULL) {
3210 + * allocate a temporary buffer for the complete ACL
3212 + acl_count = acc_acl->count + def_acl->count;
3213 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3215 + if (acl_buf == NULL) {
3216 + sys_acl_free_acl(tmp_acl);
3222 + * copy the access control and default entries into the buffer
3224 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3225 + acc_acl->count * sizeof(acl_buf[0]));
3227 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3228 + def_acl->count * sizeof(acl_buf[0]));
3231 + * set the ACL_DEFAULT flag on the default entries
3233 + for (i = acc_acl->count; i < acl_count; i++) {
3234 + acl_buf[i].a_type |= ACL_DEFAULT;
3237 + sys_acl_free_acl(tmp_acl);
3239 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3244 + ret = acl(name, SETACL, acl_count, acl_p);
3246 + SAFE_FREE(acl_buf);
3251 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3253 + if (acl_sort(acl_d) != 0) {
3257 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3260 +int sys_acl_delete_def_file(const char *path)
3266 + * fetching the access ACL and rewriting it has
3267 + * the effect of deleting the default ACL
3269 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3273 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3275 + sys_acl_free_acl(acl_d);
3280 +int sys_acl_free_text(char *text)
3286 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3292 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3297 +#elif defined(HAVE_HPUX_ACLS)
3301 + * Based on the Solaris/SCO code - with modifications.
3305 + * Note that while this code implements sufficient functionality
3306 + * to support the sys_acl_* interfaces it does not provide all
3307 + * of the semantics of the POSIX ACL interfaces.
3309 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3310 + * from a call to sys_acl_get_entry() should not be assumed to be
3311 + * valid after calling any of the following functions, which may
3312 + * reorder the entries in the ACL.
3315 + * sys_acl_set_file()
3316 + * sys_acl_set_fd()
3319 +/* This checks if the POSIX ACL system call is defined */
3320 +/* which basically corresponds to whether JFS 3.3 or */
3321 +/* higher is installed. If acl() was called when it */
3322 +/* isn't defined, it causes the process to core dump */
3323 +/* so it is important to check this and avoid acl() */
3324 +/* calls if it isn't there. */
3326 +static BOOL hpux_acl_call_presence(void)
3329 + shl_t handle = NULL;
3332 + static BOOL already_checked=0;
3334 + if(already_checked)
3338 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3340 + if(ret_val != 0) {
3341 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3342 + ret_val, errno, strerror(errno)));
3343 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3347 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3349 + already_checked = True;
3353 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3355 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3360 + if (entry_p == NULL) {
3365 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3369 + if (acl_d->next < 0) {
3374 + if (acl_d->next >= acl_d->count) {
3378 + *entry_p = &acl_d->acl[acl_d->next++];
3383 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3385 + *type_p = entry_d->a_type;
3390 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3392 + *permset_p = &entry_d->a_perm;
3397 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3399 + if (entry_d->a_type != SMB_ACL_USER
3400 + && entry_d->a_type != SMB_ACL_GROUP) {
3405 + return &entry_d->a_id;
3409 + * There is no way of knowing what size the ACL returned by
3410 + * ACL_GET will be unless you first call ACL_CNT which means
3411 + * making an additional system call.
3413 + * In the hope of avoiding the cost of the additional system
3414 + * call in most cases, we initially allocate enough space for
3415 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3416 + * be too small then we use ACL_CNT to find out the actual
3417 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3420 +#define INITIAL_ACL_SIZE 16
3422 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3425 + int count; /* # of ACL entries allocated */
3426 + int naccess; /* # of access ACL entries */
3427 + int ndefault; /* # of default ACL entries */
3429 + if(hpux_acl_call_presence() == False) {
3430 + /* Looks like we don't have the acl() system call on HPUX.
3431 + * May be the system doesn't have the latest version of JFS.
3436 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3441 + count = INITIAL_ACL_SIZE;
3442 + if ((acl_d = sys_acl_init(count)) == NULL) {
3447 + * If there isn't enough space for the ACL entries we use
3448 + * ACL_CNT to determine the actual number of ACL entries
3449 + * reallocate and try again. This is in a loop because it
3450 + * is possible that someone else could modify the ACL and
3451 + * increase the number of entries between the call to
3452 + * ACL_CNT and the call to ACL_GET.
3454 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3456 + sys_acl_free_acl(acl_d);
3458 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3462 + if ((acl_d = sys_acl_init(count)) == NULL) {
3468 + sys_acl_free_acl(acl_d);
3473 + * calculate the number of access and default ACL entries
3475 + * Note: we assume that the acl() system call returned a
3476 + * well formed ACL which is sorted so that all of the
3477 + * access ACL entries preceed any default ACL entries
3479 + for (naccess = 0; naccess < count; naccess++) {
3480 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3483 + ndefault = count - naccess;
3486 + * if the caller wants the default ACL we have to copy
3487 + * the entries down to the start of the acl[] buffer
3488 + * and mask out the ACL_DEFAULT flag from the type field
3490 + if (type == SMB_ACL_TYPE_DEFAULT) {
3493 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3494 + acl_d->acl[i] = acl_d->acl[j];
3495 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3498 + acl_d->count = ndefault;
3500 + acl_d->count = naccess;
3506 +SMB_ACL_T sys_acl_get_fd(int fd)
3509 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3512 + files_struct *fsp = file_find_fd(fd);
3514 + if (fsp == NULL) {
3520 + * We know we're in the same conn context. So we
3521 + * can use the relative path.
3524 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3527 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3534 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3536 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3537 + && perm != SMB_ACL_EXECUTE) {
3542 + if (permset_d == NULL) {
3547 + *permset_d |= perm;
3552 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3554 + return *permset_d & perm;
3557 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3564 + * use an initial estimate of 20 bytes per ACL entry
3565 + * when allocating memory for the text representation
3569 + maxlen = 20 * acl_d->count;
3570 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3575 + for (i = 0; i < acl_d->count; i++) {
3576 + struct acl *ap = &acl_d->acl[i];
3585 + switch (ap->a_type) {
3587 + * for debugging purposes it's probably more
3588 + * useful to dump unknown tag types rather
3589 + * than just returning an error
3592 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3595 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3600 + case SMB_ACL_USER:
3601 + id = uidtoname(ap->a_id);
3602 + case SMB_ACL_USER_OBJ:
3606 + case SMB_ACL_GROUP:
3607 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3608 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3614 + case SMB_ACL_GROUP_OBJ:
3618 + case SMB_ACL_OTHER:
3622 + case SMB_ACL_MASK:
3628 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3629 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3630 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3633 + /* <tag> : <qualifier> : rwx \n \0 */
3634 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3637 + * If this entry would overflow the buffer
3638 + * allocate enough additional memory for this
3639 + * entry and an estimate of another 20 bytes
3640 + * for each entry still to be processed
3642 + if ((len + nbytes) > maxlen) {
3643 + char *oldtext = text;
3645 + maxlen += nbytes + 20 * (acl_d->count - i);
3647 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3654 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3655 + len += nbytes - 1;
3664 +SMB_ACL_T sys_acl_init(int count)
3674 + * note that since the definition of the structure pointed
3675 + * to by the SMB_ACL_T includes the first element of the
3676 + * acl[] array, this actually allocates an ACL with room
3677 + * for (count+1) entries
3679 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3684 + a->size = count + 1;
3692 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3695 + SMB_ACL_ENTRY_T entry_d;
3697 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3702 + if (acl_d->count >= acl_d->size) {
3707 + entry_d = &acl_d->acl[acl_d->count++];
3708 + entry_d->a_type = 0;
3709 + entry_d->a_id = -1;
3710 + entry_d->a_perm = 0;
3711 + *entry_p = entry_d;
3716 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3718 + switch (tag_type) {
3719 + case SMB_ACL_USER:
3720 + case SMB_ACL_USER_OBJ:
3721 + case SMB_ACL_GROUP:
3722 + case SMB_ACL_GROUP_OBJ:
3723 + case SMB_ACL_OTHER:
3724 + case SMB_ACL_MASK:
3725 + entry_d->a_type = tag_type;
3735 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3737 + if (entry_d->a_type != SMB_ACL_GROUP
3738 + && entry_d->a_type != SMB_ACL_USER) {
3743 + entry_d->a_id = *((id_t *)qual_p);
3748 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3750 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3754 + entry_d->a_perm = *permset_d;
3759 +/* Structure to capture the count for each type of ACE. */
3761 +struct hpux_acl_types {
3765 + int n_def_user_obj;
3770 + int n_def_group_obj;
3774 + int n_def_other_obj;
3777 + int n_def_class_obj;
3779 + int n_illegal_obj;
3783 + * Counts the different number of objects in a given array of ACL
3787 + * acl_count - Count of ACLs in the array of ACL strucutres.
3788 + * aclp - Array of ACL structures.
3789 + * acl_type_count - Pointer to acl_types structure. Should already be
3793 + * acl_type_count - This structure is filled up with counts of various
3797 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3801 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3803 + for(i=0;i<acl_count;i++) {
3804 + switch(aclp[i].a_type) {
3806 + acl_type_count->n_user++;
3809 + acl_type_count->n_user_obj++;
3811 + case DEF_USER_OBJ:
3812 + acl_type_count->n_def_user_obj++;
3815 + acl_type_count->n_group++;
3818 + acl_type_count->n_group_obj++;
3820 + case DEF_GROUP_OBJ:
3821 + acl_type_count->n_def_group_obj++;
3824 + acl_type_count->n_other_obj++;
3826 + case DEF_OTHER_OBJ:
3827 + acl_type_count->n_def_other_obj++;
3830 + acl_type_count->n_class_obj++;
3832 + case DEF_CLASS_OBJ:
3833 + acl_type_count->n_def_class_obj++;
3836 + acl_type_count->n_def_user++;
3839 + acl_type_count->n_def_group++;
3842 + acl_type_count->n_illegal_obj++;
3848 +/* swap_acl_entries: Swaps two ACL entries.
3850 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3853 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3855 + struct acl temp_acl;
3857 + temp_acl.a_type = aclp0->a_type;
3858 + temp_acl.a_id = aclp0->a_id;
3859 + temp_acl.a_perm = aclp0->a_perm;
3861 + aclp0->a_type = aclp1->a_type;
3862 + aclp0->a_id = aclp1->a_id;
3863 + aclp0->a_perm = aclp1->a_perm;
3865 + aclp1->a_type = temp_acl.a_type;
3866 + aclp1->a_id = temp_acl.a_id;
3867 + aclp1->a_perm = temp_acl.a_perm;
3870 +/* prohibited_duplicate_type
3871 + * Identifies if given ACL type can have duplicate entries or
3874 + * Inputs: acl_type - ACL Type.
3880 + * True - If the ACL type matches any of the prohibited types.
3881 + * False - If the ACL type doesn't match any of the prohibited types.
3884 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3886 + switch(acl_type) {
3897 +/* get_needed_class_perm
3898 + * Returns the permissions of a ACL structure only if the ACL
3899 + * type matches one of the pre-determined types for computing
3900 + * CLASS_OBJ permissions.
3902 + * Inputs: aclp - Pointer to ACL structure.
3905 +static int hpux_get_needed_class_perm(struct acl *aclp)
3907 + switch(aclp->a_type) {
3911 + case DEF_USER_OBJ:
3913 + case DEF_GROUP_OBJ:
3915 + case DEF_CLASS_OBJ:
3916 + case DEF_OTHER_OBJ:
3917 + return aclp->a_perm;
3923 +/* acl_sort for HPUX.
3924 + * Sorts the array of ACL structures as per the description in
3925 + * aclsort man page. Refer to aclsort man page for more details
3929 + * acl_count - Count of ACLs in the array of ACL structures.
3930 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3932 + * aclp - Array of ACL structures.
3936 + * aclp - Sorted array of ACL structures.
3940 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3941 + * debug log in case of failure.
3944 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3946 +#if !defined(HAVE_HPUX_ACLSORT)
3948 + * The aclsort() system call is availabe on the latest HPUX General
3949 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3950 + * function. Because, we don't want to update to a new
3951 + * HPUX GR bundle just for aclsort() call.
3954 + struct hpux_acl_types acl_obj_count;
3955 + int n_class_obj_perm = 0;
3959 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3963 + if(aclp == NULL) {
3964 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3968 + /* Count different types of ACLs in the ACLs array */
3970 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3972 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3973 + * CLASS_OBJ and OTHER_OBJ
3976 + if( (acl_obj_count.n_user_obj != 1) ||
3977 + (acl_obj_count.n_group_obj != 1) ||
3978 + (acl_obj_count.n_class_obj != 1) ||
3979 + (acl_obj_count.n_other_obj != 1)
3981 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3982 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3986 + /* If any of the default objects are present, there should be only
3987 + * one of them each.
3990 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3991 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3992 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3993 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3997 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
4000 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
4001 + * same ACL type, sort by ACL id.
4003 + * I am using the trival kind of sorting method here because, performance isn't
4004 + * really effected by the ACLs feature. More over there aren't going to be more
4005 + * than 17 entries on HPUX.
4008 + for(i=0; i<acl_count;i++) {
4009 + for (j=i+1; j<acl_count; j++) {
4010 + if( aclp[i].a_type > aclp[j].a_type ) {
4011 + /* ACL entries out of order, swap them */
4013 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4015 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
4017 + /* ACL entries of same type, sort by id */
4019 + if(aclp[i].a_id > aclp[j].a_id) {
4020 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4021 + } else if (aclp[i].a_id == aclp[j].a_id) {
4022 + /* We have a duplicate entry. */
4023 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
4024 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
4025 + aclp[i].a_type, aclp[i].a_id));
4034 + /* set the class obj permissions to the computed one. */
4036 + int n_class_obj_index = -1;
4038 + for(i=0;i<acl_count;i++) {
4039 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
4041 + if(aclp[i].a_type == CLASS_OBJ)
4042 + n_class_obj_index = i;
4044 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
4049 + return aclsort(acl_count, calclass, aclp);
4054 + * sort the ACL and check it for validity
4056 + * if it's a minimal ACL with only 4 entries then we
4057 + * need to recalculate the mask permissions to make
4058 + * sure that they are the same as the GROUP_OBJ
4059 + * permissions as required by the UnixWare acl() system call.
4061 + * (note: since POSIX allows minimal ACLs which only contain
4062 + * 3 entries - ie there is no mask entry - we should, in theory,
4063 + * check for this and add a mask entry if necessary - however
4064 + * we "know" that the caller of this interface always specifies
4065 + * a mask so, in practice "this never happens" (tm) - if it *does*
4066 + * happen aclsort() will fail and return an error and someone will
4067 + * have to fix it ...)
4070 +static int acl_sort(SMB_ACL_T acl_d)
4072 + int fixmask = (acl_d->count <= 4);
4074 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4081 +int sys_acl_valid(SMB_ACL_T acl_d)
4083 + return acl_sort(acl_d);
4086 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4089 + struct acl *acl_p;
4091 + struct acl *acl_buf = NULL;
4094 + if(hpux_acl_call_presence() == False) {
4095 + /* Looks like we don't have the acl() system call on HPUX.
4096 + * May be the system doesn't have the latest version of JFS.
4102 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4107 + if (acl_sort(acl_d) != 0) {
4111 + acl_p = &acl_d->acl[0];
4112 + acl_count = acl_d->count;
4115 + * if it's a directory there is extra work to do
4116 + * since the acl() system call will replace both
4117 + * the access ACLs and the default ACLs (if any)
4119 + if (stat(name, &s) != 0) {
4122 + if (S_ISDIR(s.st_mode)) {
4123 + SMB_ACL_T acc_acl;
4124 + SMB_ACL_T def_acl;
4125 + SMB_ACL_T tmp_acl;
4128 + if (type == SMB_ACL_TYPE_ACCESS) {
4130 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4134 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4137 + if (tmp_acl == NULL) {
4142 + * allocate a temporary buffer for the complete ACL
4144 + acl_count = acc_acl->count + def_acl->count;
4145 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4147 + if (acl_buf == NULL) {
4148 + sys_acl_free_acl(tmp_acl);
4154 + * copy the access control and default entries into the buffer
4156 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4157 + acc_acl->count * sizeof(acl_buf[0]));
4159 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4160 + def_acl->count * sizeof(acl_buf[0]));
4163 + * set the ACL_DEFAULT flag on the default entries
4165 + for (i = acc_acl->count; i < acl_count; i++) {
4166 + acl_buf[i].a_type |= ACL_DEFAULT;
4169 + sys_acl_free_acl(tmp_acl);
4171 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4176 + ret = acl(name, ACL_SET, acl_count, acl_p);
4185 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4188 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4191 + files_struct *fsp = file_find_fd(fd);
4193 + if (fsp == NULL) {
4198 + if (acl_sort(acl_d) != 0) {
4203 + * We know we're in the same conn context. So we
4204 + * can use the relative path.
4207 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4210 +int sys_acl_delete_def_file(const char *path)
4216 + * fetching the access ACL and rewriting it has
4217 + * the effect of deleting the default ACL
4219 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4223 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4225 + sys_acl_free_acl(acl_d);
4230 +int sys_acl_free_text(char *text)
4236 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4242 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4247 +#elif defined(HAVE_IRIX_ACLS)
4249 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4251 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4256 + if (entry_p == NULL) {
4261 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4265 + if (acl_d->next < 0) {
4270 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4274 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4279 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4281 + *type_p = entry_d->ae_tag;
4286 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4288 + *permset_p = entry_d;
4293 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4295 + if (entry_d->ae_tag != SMB_ACL_USER
4296 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4301 + return &entry_d->ae_id;
4304 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4308 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4312 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4317 + a->freeaclp = True;
4321 +SMB_ACL_T sys_acl_get_fd(int fd)
4325 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4329 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4334 + a->freeaclp = True;
4338 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4340 + permset_d->ae_perm = 0;
4345 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4347 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4348 + && perm != SMB_ACL_EXECUTE) {
4353 + if (permset_d == NULL) {
4358 + permset_d->ae_perm |= perm;
4363 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4365 + return permset_d->ae_perm & perm;
4368 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4370 + return acl_to_text(acl_d->aclp, len_p);
4373 +SMB_ACL_T sys_acl_init(int count)
4382 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4388 + a->freeaclp = False;
4389 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4390 + a->aclp->acl_cnt = 0;
4396 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4399 + SMB_ACL_ENTRY_T entry_d;
4401 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4406 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4411 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4412 + entry_d->ae_tag = 0;
4413 + entry_d->ae_id = 0;
4414 + entry_d->ae_perm = 0;
4415 + *entry_p = entry_d;
4420 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4422 + switch (tag_type) {
4423 + case SMB_ACL_USER:
4424 + case SMB_ACL_USER_OBJ:
4425 + case SMB_ACL_GROUP:
4426 + case SMB_ACL_GROUP_OBJ:
4427 + case SMB_ACL_OTHER:
4428 + case SMB_ACL_MASK:
4429 + entry_d->ae_tag = tag_type;
4439 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4441 + if (entry_d->ae_tag != SMB_ACL_GROUP
4442 + && entry_d->ae_tag != SMB_ACL_USER) {
4447 + entry_d->ae_id = *((id_t *)qual_p);
4452 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4454 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4458 + entry_d->ae_perm = permset_d->ae_perm;
4463 +int sys_acl_valid(SMB_ACL_T acl_d)
4465 + return acl_valid(acl_d->aclp);
4468 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4470 + return acl_set_file(name, type, acl_d->aclp);
4473 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4475 + return acl_set_fd(fd, acl_d->aclp);
4478 +int sys_acl_delete_def_file(const char *name)
4480 + return acl_delete_def_file(name);
4483 +int sys_acl_free_text(char *text)
4485 + return acl_free(text);
4488 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4490 + if (acl_d->freeaclp) {
4491 + acl_free(acl_d->aclp);
4497 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4502 +#elif defined(HAVE_AIX_ACLS)
4504 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4506 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4508 + struct acl_entry_link *link;
4509 + struct new_acl_entry *entry;
4512 + DEBUG(10,("This is the count: %d\n",theacl->count));
4514 + /* Check if count was previously set to -1. *
4515 + * If it was, that means we reached the end *
4516 + * of the acl last time. */
4517 + if(theacl->count == -1)
4521 + /* To get to the next acl, traverse linked list until index *
4522 + * of acl matches the count we are keeping. This count is *
4523 + * incremented each time we return an acl entry. */
4525 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4526 + link = link->nextp;
4528 + entry = *entry_p = link->entryp;
4530 + DEBUG(10,("*entry_p is %d\n",entry_p));
4531 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4533 + /* Increment count */
4535 + if(link->nextp == NULL)
4536 + theacl->count = -1;
4541 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4543 + /* Initialize tag type */
4546 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4548 + /* Depending on what type of entry we have, *
4549 + * return tag type. */
4550 + switch(entry_d->ace_id->id_type) {
4552 + *tag_type_p = SMB_ACL_USER;
4555 + *tag_type_p = SMB_ACL_GROUP;
4558 + case SMB_ACL_USER_OBJ:
4559 + case SMB_ACL_GROUP_OBJ:
4560 + case SMB_ACL_OTHER:
4561 + *tag_type_p = entry_d->ace_id->id_type;
4571 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4573 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4574 + *permset_p = &entry_d->ace_access;
4575 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4576 + if(!(**permset_p & S_IXUSR) &&
4577 + !(**permset_p & S_IWUSR) &&
4578 + !(**permset_p & S_IRUSR) &&
4579 + (**permset_p != 0))
4582 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4586 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4588 + return(entry_d->ace_id->id_data);
4591 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4593 + struct acl *file_acl = (struct acl *)NULL;
4594 + struct acl_entry *acl_entry;
4595 + struct new_acl_entry *new_acl_entry;
4596 + struct ace_id *idp;
4597 + struct acl_entry_link *acl_entry_link;
4598 + struct acl_entry_link *acl_entry_link_head;
4603 + /* AIX has no DEFAULT */
4604 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4609 + /* Get the acl using statacl */
4611 + DEBUG(10,("Entering sys_acl_get_file\n"));
4612 + DEBUG(10,("path_p is %s\n",path_p));
4614 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4616 + if(file_acl == NULL) {
4618 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4622 + memset(file_acl,0,BUFSIZ);
4624 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4626 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4627 + SAFE_FREE(file_acl);
4631 + DEBUG(10,("Got facl and returned it\n"));
4633 + /* Point to the first acl entry in the acl */
4634 + acl_entry = file_acl->acl_ext;
4636 + /* Begin setting up the head of the linked list *
4637 + * that will be used for the storing the acl *
4638 + * in a way that is useful for the posix_acls.c *
4641 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4642 + if(acl_entry_link_head == NULL)
4645 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4646 + if(acl_entry_link->entryp == NULL) {
4647 + SAFE_FREE(file_acl);
4649 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4653 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4654 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4656 + /* Check if the extended acl bit is on. *
4657 + * If it isn't, do not show the *
4658 + * contents of the acl since AIX intends *
4659 + * the extended info to remain unused */
4661 + if(file_acl->acl_mode & S_IXACL){
4662 + /* while we are not pointing to the very end */
4663 + while(acl_entry < acl_last(file_acl)) {
4664 + /* before we malloc anything, make sure this is */
4665 + /* a valid acl entry and one that we want to map */
4666 + idp = id_nxt(acl_entry->ace_id);
4667 + if((acl_entry->ace_type == ACC_SPECIFY ||
4668 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4669 + acl_entry = acl_nxt(acl_entry);
4673 + idp = acl_entry->ace_id;
4675 + /* Check if this is the first entry in the linked list. *
4676 + * The first entry needs to keep prevp pointing to NULL *
4677 + * and already has entryp allocated. */
4679 + if(acl_entry_link_head->count != 0) {
4680 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4682 + if(acl_entry_link->nextp == NULL) {
4683 + SAFE_FREE(file_acl);
4685 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4689 + acl_entry_link->nextp->prevp = acl_entry_link;
4690 + acl_entry_link = acl_entry_link->nextp;
4691 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4692 + if(acl_entry_link->entryp == NULL) {
4693 + SAFE_FREE(file_acl);
4695 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4698 + acl_entry_link->nextp = NULL;
4701 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4703 + /* Don't really need this since all types are going *
4704 + * to be specified but, it's better than leaving it 0 */
4706 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4708 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4710 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4712 + /* The access in the acl entries must be left shifted by *
4713 + * three bites, because they will ultimately be compared *
4714 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4716 + switch(acl_entry->ace_type){
4719 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4720 + acl_entry_link->entryp->ace_access <<= 6;
4721 + acl_entry_link_head->count++;
4724 + /* Since there is no way to return a DENY acl entry *
4725 + * change to PERMIT and then shift. */
4726 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4727 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4728 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4729 + acl_entry_link->entryp->ace_access <<= 6;
4730 + acl_entry_link_head->count++;
4736 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4737 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4739 + acl_entry = acl_nxt(acl_entry);
4741 + } /* end of if enabled */
4743 + /* Since owner, group, other acl entries are not *
4744 + * part of the acl entries in an acl, they must *
4745 + * be dummied up to become part of the list. */
4747 + for( i = 1; i < 4; i++) {
4748 + DEBUG(10,("i is %d\n",i));
4749 + if(acl_entry_link_head->count != 0) {
4750 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4751 + if(acl_entry_link->nextp == NULL) {
4752 + SAFE_FREE(file_acl);
4754 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4758 + acl_entry_link->nextp->prevp = acl_entry_link;
4759 + acl_entry_link = acl_entry_link->nextp;
4760 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4761 + if(acl_entry_link->entryp == NULL) {
4762 + SAFE_FREE(file_acl);
4764 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4769 + acl_entry_link->nextp = NULL;
4771 + new_acl_entry = acl_entry_link->entryp;
4772 + idp = new_acl_entry->ace_id;
4774 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4775 + new_acl_entry->ace_type = ACC_PERMIT;
4776 + idp->id_len = sizeof(struct ace_id);
4777 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4778 + memset(idp->id_data,0,sizeof(uid_t));
4782 + new_acl_entry->ace_access = file_acl->g_access << 6;
4783 + idp->id_type = SMB_ACL_GROUP_OBJ;
4787 + new_acl_entry->ace_access = file_acl->o_access << 6;
4788 + idp->id_type = SMB_ACL_OTHER;
4792 + new_acl_entry->ace_access = file_acl->u_access << 6;
4793 + idp->id_type = SMB_ACL_USER_OBJ;
4801 + acl_entry_link_head->count++;
4802 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4805 + acl_entry_link_head->count = 0;
4806 + SAFE_FREE(file_acl);
4808 + return(acl_entry_link_head);
4811 +SMB_ACL_T sys_acl_get_fd(int fd)
4813 + struct acl *file_acl = (struct acl *)NULL;
4814 + struct acl_entry *acl_entry;
4815 + struct new_acl_entry *new_acl_entry;
4816 + struct ace_id *idp;
4817 + struct acl_entry_link *acl_entry_link;
4818 + struct acl_entry_link *acl_entry_link_head;
4823 + /* Get the acl using fstatacl */
4825 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4826 + DEBUG(10,("fd is %d\n",fd));
4827 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4829 + if(file_acl == NULL) {
4831 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4835 + memset(file_acl,0,BUFSIZ);
4837 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4839 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4840 + SAFE_FREE(file_acl);
4844 + DEBUG(10,("Got facl and returned it\n"));
4846 + /* Point to the first acl entry in the acl */
4848 + acl_entry = file_acl->acl_ext;
4849 + /* Begin setting up the head of the linked list *
4850 + * that will be used for the storing the acl *
4851 + * in a way that is useful for the posix_acls.c *
4854 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4855 + if(acl_entry_link_head == NULL){
4856 + SAFE_FREE(file_acl);
4860 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4862 + if(acl_entry_link->entryp == NULL) {
4864 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4865 + SAFE_FREE(file_acl);
4869 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4870 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4872 + /* Check if the extended acl bit is on. *
4873 + * If it isn't, do not show the *
4874 + * contents of the acl since AIX intends *
4875 + * the extended info to remain unused */
4877 + if(file_acl->acl_mode & S_IXACL){
4878 + /* while we are not pointing to the very end */
4879 + while(acl_entry < acl_last(file_acl)) {
4880 + /* before we malloc anything, make sure this is */
4881 + /* a valid acl entry and one that we want to map */
4883 + idp = id_nxt(acl_entry->ace_id);
4884 + if((acl_entry->ace_type == ACC_SPECIFY ||
4885 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4886 + acl_entry = acl_nxt(acl_entry);
4890 + idp = acl_entry->ace_id;
4892 + /* Check if this is the first entry in the linked list. *
4893 + * The first entry needs to keep prevp pointing to NULL *
4894 + * and already has entryp allocated. */
4896 + if(acl_entry_link_head->count != 0) {
4897 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4898 + if(acl_entry_link->nextp == NULL) {
4900 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4901 + SAFE_FREE(file_acl);
4904 + acl_entry_link->nextp->prevp = acl_entry_link;
4905 + acl_entry_link = acl_entry_link->nextp;
4906 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4907 + if(acl_entry_link->entryp == NULL) {
4909 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4910 + SAFE_FREE(file_acl);
4914 + acl_entry_link->nextp = NULL;
4917 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4919 + /* Don't really need this since all types are going *
4920 + * to be specified but, it's better than leaving it 0 */
4922 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4923 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4925 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4927 + /* The access in the acl entries must be left shifted by *
4928 + * three bites, because they will ultimately be compared *
4929 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4931 + switch(acl_entry->ace_type){
4934 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4935 + acl_entry_link->entryp->ace_access <<= 6;
4936 + acl_entry_link_head->count++;
4939 + /* Since there is no way to return a DENY acl entry *
4940 + * change to PERMIT and then shift. */
4941 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4942 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4943 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4944 + acl_entry_link->entryp->ace_access <<= 6;
4945 + acl_entry_link_head->count++;
4951 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4952 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4954 + acl_entry = acl_nxt(acl_entry);
4956 + } /* end of if enabled */
4958 + /* Since owner, group, other acl entries are not *
4959 + * part of the acl entries in an acl, they must *
4960 + * be dummied up to become part of the list. */
4962 + for( i = 1; i < 4; i++) {
4963 + DEBUG(10,("i is %d\n",i));
4964 + if(acl_entry_link_head->count != 0){
4965 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4966 + if(acl_entry_link->nextp == NULL) {
4968 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4969 + SAFE_FREE(file_acl);
4973 + acl_entry_link->nextp->prevp = acl_entry_link;
4974 + acl_entry_link = acl_entry_link->nextp;
4975 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4977 + if(acl_entry_link->entryp == NULL) {
4978 + SAFE_FREE(file_acl);
4980 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4985 + acl_entry_link->nextp = NULL;
4987 + new_acl_entry = acl_entry_link->entryp;
4988 + idp = new_acl_entry->ace_id;
4990 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4991 + new_acl_entry->ace_type = ACC_PERMIT;
4992 + idp->id_len = sizeof(struct ace_id);
4993 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4994 + memset(idp->id_data,0,sizeof(uid_t));
4998 + new_acl_entry->ace_access = file_acl->g_access << 6;
4999 + idp->id_type = SMB_ACL_GROUP_OBJ;
5003 + new_acl_entry->ace_access = file_acl->o_access << 6;
5004 + idp->id_type = SMB_ACL_OTHER;
5008 + new_acl_entry->ace_access = file_acl->u_access << 6;
5009 + idp->id_type = SMB_ACL_USER_OBJ;
5016 + acl_entry_link_head->count++;
5017 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
5020 + acl_entry_link_head->count = 0;
5021 + SAFE_FREE(file_acl);
5023 + return(acl_entry_link_head);
5026 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
5028 + *permset = *permset & ~0777;
5032 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5035 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
5039 + DEBUG(10,("This is the permset now: %d\n",*permset));
5043 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
5048 +SMB_ACL_T sys_acl_init( int count)
5050 + struct acl_entry_link *theacl = NULL;
5052 + DEBUG(10,("Entering sys_acl_init\n"));
5054 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5055 + if(theacl == NULL) {
5057 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5061 + theacl->count = 0;
5062 + theacl->nextp = NULL;
5063 + theacl->prevp = NULL;
5064 + theacl->entryp = NULL;
5065 + DEBUG(10,("Exiting sys_acl_init\n"));
5069 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5071 + struct acl_entry_link *theacl;
5072 + struct acl_entry_link *acl_entryp;
5073 + struct acl_entry_link *temp_entry;
5076 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5078 + theacl = acl_entryp = *pacl;
5080 + /* Get to the end of the acl before adding entry */
5082 + for(counting=0; counting < theacl->count; counting++){
5083 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5084 + temp_entry = acl_entryp;
5085 + acl_entryp = acl_entryp->nextp;
5088 + if(theacl->count != 0){
5089 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5090 + if(acl_entryp == NULL) {
5092 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5096 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5097 + acl_entryp->prevp = temp_entry;
5098 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5101 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5102 + if(*pentry == NULL) {
5104 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5108 + memset(*pentry,0,sizeof(struct new_acl_entry));
5109 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5110 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5111 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5112 + acl_entryp->nextp = NULL;
5114 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5118 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5120 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5121 + entry->ace_id->id_type = tagtype;
5122 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5123 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5126 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5128 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5129 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5130 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5134 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5136 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5137 + if(!(*permset & S_IXUSR) &&
5138 + !(*permset & S_IWUSR) &&
5139 + !(*permset & S_IRUSR) &&
5143 + entry->ace_access = *permset;
5144 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5145 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5149 +int sys_acl_valid( SMB_ACL_T theacl )
5152 + int group_obj = 0;
5153 + int other_obj = 0;
5154 + struct acl_entry_link *acl_entry;
5156 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5157 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5158 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5159 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5162 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5164 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5170 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5172 + struct acl_entry_link *acl_entry_link = NULL;
5173 + struct acl *file_acl = NULL;
5174 + struct acl *file_acl_temp = NULL;
5175 + struct acl_entry *acl_entry = NULL;
5176 + struct ace_id *ace_id = NULL;
5183 + DEBUG(10,("Entering sys_acl_set_file\n"));
5184 + DEBUG(10,("File name is %s\n",name));
5186 + /* AIX has no default ACL */
5187 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5190 + acl_length = BUFSIZ;
5191 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5193 + if(file_acl == NULL) {
5195 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5199 + memset(file_acl,0,BUFSIZ);
5201 + file_acl->acl_len = ACL_SIZ;
5202 + file_acl->acl_mode = S_IXACL;
5204 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5205 + acl_entry_link->entryp->ace_access >>= 6;
5206 + id_type = acl_entry_link->entryp->ace_id->id_type;
5209 + case SMB_ACL_USER_OBJ:
5210 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5212 + case SMB_ACL_GROUP_OBJ:
5213 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5215 + case SMB_ACL_OTHER:
5216 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5218 + case SMB_ACL_MASK:
5222 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5223 + acl_length += sizeof(struct acl_entry);
5224 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5225 + if(file_acl_temp == NULL) {
5226 + SAFE_FREE(file_acl);
5228 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5232 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5233 + SAFE_FREE(file_acl);
5234 + file_acl = file_acl_temp;
5237 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5238 + file_acl->acl_len += sizeof(struct acl_entry);
5239 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5240 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5242 + /* In order to use this, we'll need to wait until we can get denies */
5243 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5244 + acl_entry->ace_type = ACC_SPECIFY; */
5246 + acl_entry->ace_type = ACC_SPECIFY;
5248 + ace_id = acl_entry->ace_id;
5250 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5251 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5252 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5253 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5254 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5257 + rc = chacl(name,file_acl,file_acl->acl_len);
5258 + DEBUG(10,("errno is %d\n",errno));
5259 + DEBUG(10,("return code is %d\n",rc));
5260 + SAFE_FREE(file_acl);
5261 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5265 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5267 + struct acl_entry_link *acl_entry_link = NULL;
5268 + struct acl *file_acl = NULL;
5269 + struct acl *file_acl_temp = NULL;
5270 + struct acl_entry *acl_entry = NULL;
5271 + struct ace_id *ace_id = NULL;
5277 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5278 + acl_length = BUFSIZ;
5279 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5281 + if(file_acl == NULL) {
5283 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5287 + memset(file_acl,0,BUFSIZ);
5289 + file_acl->acl_len = ACL_SIZ;
5290 + file_acl->acl_mode = S_IXACL;
5292 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5293 + acl_entry_link->entryp->ace_access >>= 6;
5294 + id_type = acl_entry_link->entryp->ace_id->id_type;
5295 + DEBUG(10,("The id_type is %d\n",id_type));
5298 + case SMB_ACL_USER_OBJ:
5299 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5301 + case SMB_ACL_GROUP_OBJ:
5302 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5304 + case SMB_ACL_OTHER:
5305 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5307 + case SMB_ACL_MASK:
5311 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5312 + acl_length += sizeof(struct acl_entry);
5313 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5314 + if(file_acl_temp == NULL) {
5315 + SAFE_FREE(file_acl);
5317 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5321 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5322 + SAFE_FREE(file_acl);
5323 + file_acl = file_acl_temp;
5326 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5327 + file_acl->acl_len += sizeof(struct acl_entry);
5328 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5329 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5331 + /* In order to use this, we'll need to wait until we can get denies */
5332 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5333 + acl_entry->ace_type = ACC_SPECIFY; */
5335 + acl_entry->ace_type = ACC_SPECIFY;
5337 + ace_id = acl_entry->ace_id;
5339 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5340 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5341 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5342 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5343 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5346 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5347 + DEBUG(10,("errno is %d\n",errno));
5348 + DEBUG(10,("return code is %d\n",rc));
5349 + SAFE_FREE(file_acl);
5350 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5354 +int sys_acl_delete_def_file(const char *name)
5356 + /* AIX has no default ACL */
5360 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5362 + return(*permset & perm);
5365 +int sys_acl_free_text(char *text)
5370 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5372 + struct acl_entry_link *acl_entry_link;
5374 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5375 + SAFE_FREE(acl_entry_link->prevp->entryp);
5376 + SAFE_FREE(acl_entry_link->prevp);
5379 + SAFE_FREE(acl_entry_link->prevp->entryp);
5380 + SAFE_FREE(acl_entry_link->prevp);
5381 + SAFE_FREE(acl_entry_link->entryp);
5382 + SAFE_FREE(acl_entry_link);
5387 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5392 +#else /* No ACLs. */
5394 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5400 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5406 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5412 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5418 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5421 + return (SMB_ACL_T)NULL;
5424 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5427 + return (SMB_ACL_T)NULL;
5430 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5436 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5442 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5445 + return (permset & perm) ? 1 : 0;
5448 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5454 +int sys_acl_free_text(UNUSED(char *text))
5460 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5466 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5472 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5478 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5484 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5490 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5496 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5502 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5508 +int sys_acl_delete_def_file(UNUSED(const char *name))
5514 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5520 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5526 +#endif /* No ACLs. */
5528 +/************************************************************************
5529 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5531 +************************************************************************/
5533 +int no_acl_syscall_error(int err)
5535 +#if defined(ENOSYS)
5536 + if (err == ENOSYS) {
5540 +#if defined(ENOTSUP)
5541 + if (err == ENOTSUP) {
5548 +#endif /* SUPPORT_ACLS */
5549 --- old/lib/sysacls.h
5550 +++ new/lib/sysacls.h
5552 +#ifdef SUPPORT_ACLS
5554 +#ifdef HAVE_SYS_ACL_H
5555 +#include <sys/acl.h>
5557 +#ifdef HAVE_ACL_LIBACL_H
5558 +#include <acl/libacl.h>
5560 +#include "smb_acls.h"
5562 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5563 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5564 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5565 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5566 +#define slprintf snprintf
5568 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5569 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5570 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5571 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5572 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5573 +SMB_ACL_T sys_acl_get_fd(int fd);
5574 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5575 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5576 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5577 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5578 +SMB_ACL_T sys_acl_init(int count);
5579 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5580 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5581 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5582 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5583 +int sys_acl_valid(SMB_ACL_T theacl);
5584 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5585 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5586 +int sys_acl_delete_def_file(const char *name);
5587 +int sys_acl_free_text(char *text);
5588 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5589 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5591 +#endif /* SUPPORT_ACLS */
5594 @@ -618,8 +618,10 @@ static void log_formatted(enum logcode c
5595 c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5596 c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5597 c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5600 + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5601 + c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5602 + c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5605 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5606 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5609 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5611 int preserve_links = 0;
5612 int preserve_hard_links = 0;
5613 +int preserve_acls = 0;
5614 int preserve_perms = 0;
5615 int preserve_executability = 0;
5616 int preserve_devices = 0;
5617 @@ -199,6 +200,7 @@ static void print_rsync_version(enum log
5618 char const *got_socketpair = "no ";
5619 char const *have_inplace = "no ";
5620 char const *hardlinks = "no ";
5621 + char const *acls = "no ";
5622 char const *links = "no ";
5623 char const *ipv6 = "no ";
5624 STRUCT_STAT *dumstat;
5625 @@ -215,6 +217,10 @@ static void print_rsync_version(enum log
5629 +#ifdef SUPPORT_ACLS
5633 #ifdef SUPPORT_LINKS
5636 @@ -233,8 +239,8 @@ static void print_rsync_version(enum log
5637 (int)(sizeof (int64) * 8));
5638 rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
5639 got_socketpair, hardlinks, links, ipv6, have_inplace);
5640 - rprintf(f, " %sappend\n",
5642 + rprintf(f, " %sappend, %sACLs\n",
5643 + have_inplace, acls);
5645 #ifdef MAINTAINER_MODE
5646 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
5647 @@ -280,7 +286,7 @@ void usage(enum logcode F)
5648 rprintf(F," -q, --quiet suppress non-error messages\n");
5649 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5650 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5651 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5652 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5653 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5654 rprintf(F," -r, --recursive recurse into directories\n");
5655 rprintf(F," -R, --relative use relative path names\n");
5656 @@ -302,6 +308,9 @@ void usage(enum logcode F)
5657 rprintf(F," -p, --perms preserve permissions\n");
5658 rprintf(F," -E, --executability preserve the file's executability\n");
5659 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5660 +#ifdef SUPPORT_ACLS
5661 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5663 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5664 rprintf(F," -g, --group preserve group\n");
5665 rprintf(F," --devices preserve device files (super-user only)\n");
5666 @@ -422,6 +431,9 @@ static struct poptOption long_options[]
5667 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5668 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5669 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5670 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5671 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5672 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5673 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5674 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5675 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5676 @@ -1087,6 +1099,24 @@ int parse_arguments(int *argc, const cha
5681 +#ifdef SUPPORT_ACLS
5682 + preserve_acls = 1;
5683 + preserve_perms = 1;
5686 + /* FIXME: this should probably be ignored with a
5687 + * warning and then countermeasures taken to
5688 + * restrict group and other access in the presence
5689 + * of any more restrictive ACLs, but this is safe
5691 + snprintf(err_buf,sizeof(err_buf),
5692 + "ACLs are not supported on this %s\n",
5693 + am_server ? "server" : "client");
5699 /* A large opt value means that set_refuse_options()
5700 * turned this option off. */
5701 @@ -1223,6 +1253,8 @@ int parse_arguments(int *argc, const cha
5702 preserve_uid = flist_extra_ndx++;
5704 preserve_gid = flist_extra_ndx++;
5705 + if (preserve_acls)
5706 + preserve_acls = flist_extra_ndx++;
5708 *argv = poptGetArgs(pc);
5709 *argc = count_args(*argv);
5710 @@ -1534,6 +1566,10 @@ void server_options(char **args,int *arg
5712 if (preserve_hard_links)
5714 +#ifdef SUPPORT_ACLS
5715 + if (preserve_acls)
5716 + argstr[x++] = 'A';
5723 @@ -48,6 +48,7 @@ extern int keep_partial;
5724 extern int checksum_seed;
5726 extern int delay_updates;
5727 +extern mode_t orig_umask;
5728 extern struct stats stats;
5729 extern char *stdout_format;
5730 extern char *tmpdir;
5731 @@ -348,6 +349,10 @@ int recv_files(int f_in, struct file_lis
5732 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5733 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5734 int max_phase = protocol_version >= 29 ? 2 : 1;
5735 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5736 +#ifdef SUPPORT_ACLS
5737 + const char *parent_dirname = "";
5742 @@ -551,7 +556,16 @@ int recv_files(int f_in, struct file_lis
5743 * mode based on the local permissions and some heuristics. */
5744 if (!preserve_perms) {
5745 int exists = fd1 != -1;
5746 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5747 +#ifdef SUPPORT_ACLS
5748 + const char *dn = file->dirname ? file->dirname : ".";
5749 + if (parent_dirname != dn
5750 + && strcmp(parent_dirname, dn) != 0) {
5751 + dflt_perms = default_perms_for_dir(dn);
5752 + parent_dirname = dn;
5755 + file->mode = dest_mode(file->mode, st.st_mode,
5756 + dflt_perms, exists);
5759 /* We now check to see if we are writing the file "inplace" */
5766 +extern int preserve_acls;
5767 extern int preserve_perms;
5768 extern int preserve_executability;
5769 extern int preserve_times;
5770 @@ -48,7 +49,6 @@ extern int preserve_gid;
5772 extern int keep_dirlinks;
5773 extern int make_backups;
5774 -extern mode_t orig_umask;
5775 extern struct stats stats;
5776 extern struct file_list *the_file_list;
5777 extern struct chmod_mode_struct *daemon_chmod_modes;
5778 @@ -153,7 +153,8 @@ void free_sums(struct sum_struct *s)
5780 /* This is only called when we aren't preserving permissions. Figure out what
5781 * the permissions should be and return them merged back into the mode. */
5782 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5783 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5787 /* If the file already exists, we'll return the local permissions,
5788 @@ -170,56 +171,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5789 new_mode |= (new_mode & 0444) >> 2;
5792 - /* Apply the umask and turn off special permissions. */
5793 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5794 + /* Apply destination default permissions and turn
5795 + * off special permissions. */
5796 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5801 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5802 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5808 int change_uid, change_gid;
5809 mode_t new_mode = file->mode;
5815 - if (link_stat(fname, &st2, 0) < 0) {
5816 + if (link_stat(fname, &sx2.st, 0) < 0) {
5817 rsyserr(FERROR, errno, "stat %s failed",
5822 +#ifdef SUPPORT_ACLS
5823 + sx2.acc_acl = sx2.def_acl = NULL;
5825 if (!preserve_perms && S_ISDIR(new_mode)
5826 - && st->st_mode & S_ISGID) {
5827 + && sx2.st.st_mode & S_ISGID) {
5828 /* We just created this directory and its setgid
5829 * bit is on, so make sure it stays on. */
5830 new_mode |= S_ISGID;
5835 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5836 +#ifdef SUPPORT_ACLS
5837 + if (preserve_acls && !ACL_READY(*sxp))
5838 + get_acl(fname, sxp);
5841 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5842 flags |= ATTRS_SKIP_MTIME;
5843 if (!(flags & ATTRS_SKIP_MTIME)
5844 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5845 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5846 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5847 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5849 rsyserr(FERROR, errno, "failed to set times on %s",
5854 if (ret == 0) /* ret == 1 if symlink could not be set */
5858 - change_uid = am_root && preserve_uid && st->st_uid != F_UID(file);
5859 + change_uid = am_root && preserve_uid && sxp->st.st_uid != F_UID(file);
5860 change_gid = preserve_gid && F_GID(file) != GID_NONE
5861 - && st->st_gid != F_GID(file);
5862 + && sxp->st.st_gid != F_GID(file);
5863 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5864 - if (S_ISLNK(st->st_mode))
5865 + if (S_ISLNK(sxp->st.st_mode))
5869 @@ -229,45 +239,57 @@ int set_file_attrs(char *fname, struct f
5871 "set uid of %s from %ld to %ld\n",
5873 - (long)st->st_uid, (long)F_UID(file));
5874 + (long)sxp->st.st_uid, (long)F_UID(file));
5878 "set gid of %s from %ld to %ld\n",
5880 - (long)st->st_gid, (long)F_GID(file));
5881 + (long)sxp->st.st_gid, (long)F_GID(file));
5884 if (do_lchown(fname,
5885 - change_uid ? F_UID(file) : st->st_uid,
5886 - change_gid ? F_GID(file) : st->st_gid) != 0) {
5887 + change_uid ? F_UID(file) : sxp->st.st_uid,
5888 + change_gid ? F_GID(file) : sxp->st.st_gid) != 0) {
5889 /* shouldn't have attempted to change uid or gid
5890 * unless have the privilege */
5891 rsyserr(FERROR, errno, "%s %s failed",
5892 change_uid ? "chown" : "chgrp",
5897 /* a lchown had been done - we have to re-stat if the
5898 * destination had the setuid or setgid bits set due
5899 * to the side effect of the chown call */
5900 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5901 - link_stat(fname, st,
5902 - keep_dirlinks && S_ISDIR(st->st_mode));
5903 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5904 + link_stat(fname, &sxp->st,
5905 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5910 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5911 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5913 +#ifdef SUPPORT_ACLS
5914 + /* It's OK to call set_acl() now, even for a dir, as the generator
5915 + * will enable owner-writability using chmod, if necessary.
5917 + * If set_acl() changes permission bits in the process of setting
5918 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5919 + * need to chmod(). */
5920 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5925 - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5926 + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5927 int ret = do_chmod(fname, new_mode);
5929 rsyserr(FERROR, errno,
5930 "failed to set permissions on %s",
5935 if (ret == 0) /* ret == 1 if symlink could not be set */
5937 @@ -280,6 +302,11 @@ int set_file_attrs(char *fname, struct f
5939 rprintf(FCLIENT, "%s is uptodate\n", fname);
5942 +#ifdef SUPPORT_ACLS
5943 + if (preserve_acls && sxp == &sx2)
5951 @@ -495,6 +495,14 @@ struct idev {
5952 #define IN_LOOPBACKNET 127
5955 +#ifndef HAVE_NO_ACLS
5956 +#define SUPPORT_ACLS 1
5959 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5960 +#define ACLS_NEED_MASK 1
5963 #define GID_NONE ((gid_t)-1)
5965 #define HL_CHECK_MASTER 0
5966 @@ -540,10 +548,12 @@ union flist_extras {
5967 /* When enabled, all entries have these: */
5968 #define F_UID(f) FLIST_EXTRA(f, preserve_uid).uid
5969 #define F_GID(f) FLIST_EXTRA(f, preserve_gid).gid
5970 +#define F_ACL(f) FLIST_EXTRA(f, preserve_acls).num
5972 /* These are per-entry optional and mutally exclusive: */
5973 #define F_IDEV(f) FLIST_EXTRA(f, flist_extra_ndx).idev
5974 #define F_HLIST(f) FLIST_EXTRA(f, flist_extra_ndx).hlist
5975 +#define F_DEFACL(f) FLIST_EXTRA(f, flist_extra_ndx).num
5977 /* These are per-entry optional, but always both or neither: */
5978 #define F_DMAJOR(f) FLIST_EXTRA(f, flist_extra_ndx + (IS_HLINKED(f)? 1 : 0)).num
5979 @@ -667,6 +677,17 @@ struct stats {
5981 struct chmod_mode_struct;
5983 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5991 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5992 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5994 #include "byteorder.h"
5995 #include "lib/mdfour.h"
5996 #include "lib/wildmatch.h"
5997 @@ -685,6 +706,16 @@ struct chmod_mode_struct;
5998 #define NORETURN __attribute__((__noreturn__))
6003 +#ifdef SUPPORT_ACLS
6004 + struct rsync_acl *acc_acl; /* access ACL */
6005 + struct rsync_acl *def_acl; /* default ACL */
6009 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
6013 /* We have replacement versions of these if they're missing. */
6016 @@ -301,7 +301,7 @@ to the detailed description below for a
6017 -q, --quiet suppress non-error messages
6018 --no-motd suppress daemon-mode MOTD (see caveat)
6019 -c, --checksum skip based on checksum, not mod-time & size
6020 - -a, --archive archive mode; same as -rlptgoD (no -H)
6021 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
6022 --no-OPTION turn off an implied OPTION (e.g. --no-D)
6023 -r, --recursive recurse into directories
6024 -R, --relative use relative path names
6025 @@ -323,6 +323,7 @@ to the detailed description below for a
6026 -p, --perms preserve permissions
6027 -E, --executability preserve executability
6028 --chmod=CHMOD affect file and/or directory permissions
6029 + -A, --acls preserve ACLs (implies -p) [non-standard]
6030 -o, --owner preserve owner (super-user only)
6031 -g, --group preserve group
6032 --devices preserve device files (super-user only)
6033 @@ -754,7 +755,9 @@ quote(itemization(
6034 permissions, though the bf(--executability) option might change just
6035 the execute permission for the file.
6036 it() New files get their "normal" permission bits set to the source
6037 - file's permissions masked with the receiving end's umask setting, and
6038 + file's permissions masked with the receiving directory's default
6039 + permissions (either the receiving process's umask, or the permissions
6040 + specified via the destination directory's default ACL), and
6041 their special permission bits disabled except in the case where a new
6042 directory inherits a setgid bit from its parent directory.
6044 @@ -785,9 +788,11 @@ The preservation of the destination's se
6045 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
6046 versions erroneously preserved the three special permission bits for
6047 newly-created files when bf(--perms) was off, while overriding the
6048 -destination's setgid bit setting on a newly-created directory. (Keep in
6049 -mind that it is the version of the receiving rsync that affects this
6051 +destination's setgid bit setting on a newly-created directory. Default ACL
6052 +observance was added to the ACL patch for rsync 2.6.7, so older (or
6053 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
6054 +(Keep in mind that it is the version of the receiving rsync that affects
6057 dit(bf(-E, --executability)) This option causes rsync to preserve the
6058 executability (or non-executability) of regular files when bf(--perms) is
6059 @@ -805,6 +810,15 @@ quote(itemization(
6061 If bf(--perms) is enabled, this option is ignored.
6063 +dit(bf(-A, --acls)) This option causes rsync to update the destination
6064 +ACLs to be the same as the source ACLs. This nonstandard option only
6065 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
6067 +Note also that an optimization of the ACL-sending protocol used by this
6068 +version makes it incompatible with sending files to an older ACL-enabled
6069 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
6070 +doubling is not needed when pulling files from an older rsync.
6072 dit(bf(--chmod)) This option tells rsync to apply one or more
6073 comma-separated "chmod" strings to the permission of the files in the
6074 transfer. The resulting value is treated as though it was the permissions
6075 @@ -1402,8 +1416,8 @@ if the receiving rsync is at least versi
6076 with older versions of rsync, but that also turns on the output of other
6079 -The "%i" escape has a cryptic output that is 9 letters long. The general
6080 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
6081 +The "%i" escape has a cryptic output that is 11 letters long. The general
6082 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
6083 type of update being done, bf(X) is replaced by the file-type, and the
6084 other letters represent attributes that may be output if they are being
6086 @@ -1452,7 +1466,11 @@ quote(itemization(
6087 sender's value (requires bf(--owner) and super-user privileges).
6088 it() A bf(g) means the group is different and is being updated to the
6089 sender's value (requires bf(--group) and the authority to set the group).
6090 - it() The bf(z) slot is reserved for future use.
6091 + it() The bf(u) slot is reserved for reporting update (access) time changes
6092 + (a feature that is not yet released).
6093 + it() The bf(a) means that the ACL information changed.
6094 + it() The bf(x) slot is reserved for reporting extended attribute changes
6095 + (a feature that is not yet released).
6098 One other output is possible: when deleting files, the "%i" will output
6103 + Unix SMB/Netbios implementation.
6105 + Portable SMB ACL interface
6106 + Copyright (C) Jeremy Allison 2000
6108 + This program is free software; you can redistribute it and/or modify
6109 + it under the terms of the GNU General Public License as published by
6110 + the Free Software Foundation; either version 2 of the License, or
6111 + (at your option) any later version.
6113 + This program is distributed in the hope that it will be useful,
6114 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6115 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6116 + GNU General Public License for more details.
6118 + You should have received a copy of the GNU General Public License
6119 + along with this program; if not, write to the Free Software
6120 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6123 +#ifndef _SMB_ACLS_H
6124 +#define _SMB_ACLS_H
6126 +#if defined HAVE_POSIX_ACLS
6128 +/* This is an identity mapping (just remove the SMB_). */
6130 +#define SMB_ACL_TAG_T acl_tag_t
6131 +#define SMB_ACL_TYPE_T acl_type_t
6132 +#define SMB_ACL_PERMSET_T acl_permset_t
6133 +#define SMB_ACL_PERM_T acl_perm_t
6134 +#define SMB_ACL_READ ACL_READ
6135 +#define SMB_ACL_WRITE ACL_WRITE
6136 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6138 +/* Types of ACLs. */
6139 +#define SMB_ACL_USER ACL_USER
6140 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6141 +#define SMB_ACL_GROUP ACL_GROUP
6142 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6143 +#define SMB_ACL_OTHER ACL_OTHER
6144 +#define SMB_ACL_MASK ACL_MASK
6146 +#define SMB_ACL_T acl_t
6148 +#define SMB_ACL_ENTRY_T acl_entry_t
6150 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6151 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6153 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6154 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6156 +#elif defined HAVE_TRU64_ACLS
6158 +/* This is for DEC/Compaq Tru64 UNIX */
6160 +#define SMB_ACL_TAG_T acl_tag_t
6161 +#define SMB_ACL_TYPE_T acl_type_t
6162 +#define SMB_ACL_PERMSET_T acl_permset_t
6163 +#define SMB_ACL_PERM_T acl_perm_t
6164 +#define SMB_ACL_READ ACL_READ
6165 +#define SMB_ACL_WRITE ACL_WRITE
6166 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6168 +/* Types of ACLs. */
6169 +#define SMB_ACL_USER ACL_USER
6170 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6171 +#define SMB_ACL_GROUP ACL_GROUP
6172 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6173 +#define SMB_ACL_OTHER ACL_OTHER
6174 +#define SMB_ACL_MASK ACL_MASK
6176 +#define SMB_ACL_T acl_t
6178 +#define SMB_ACL_ENTRY_T acl_entry_t
6180 +#define SMB_ACL_FIRST_ENTRY 0
6181 +#define SMB_ACL_NEXT_ENTRY 1
6183 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6184 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6186 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6188 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6189 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6192 +/* SVR4.2 ES/MP ACLs */
6193 +typedef int SMB_ACL_TAG_T;
6194 +typedef int SMB_ACL_TYPE_T;
6195 +typedef ushort *SMB_ACL_PERMSET_T;
6196 +typedef ushort SMB_ACL_PERM_T;
6197 +#define SMB_ACL_READ 4
6198 +#define SMB_ACL_WRITE 2
6199 +#define SMB_ACL_EXECUTE 1
6201 +/* Types of ACLs. */
6202 +#define SMB_ACL_USER USER
6203 +#define SMB_ACL_USER_OBJ USER_OBJ
6204 +#define SMB_ACL_GROUP GROUP
6205 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6206 +#define SMB_ACL_OTHER OTHER_OBJ
6207 +#define SMB_ACL_MASK CLASS_OBJ
6209 +typedef struct SMB_ACL_T {
6213 + struct acl acl[1];
6216 +typedef struct acl *SMB_ACL_ENTRY_T;
6218 +#define SMB_ACL_FIRST_ENTRY 0
6219 +#define SMB_ACL_NEXT_ENTRY 1
6221 +#define SMB_ACL_TYPE_ACCESS 0
6222 +#define SMB_ACL_TYPE_DEFAULT 1
6225 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6228 +#elif defined HAVE_HPUX_ACLS
6231 + * Based on the Solaris & UnixWare code.
6235 +#include <sys/aclv.h>
6237 +/* SVR4.2 ES/MP ACLs */
6238 +typedef int SMB_ACL_TAG_T;
6239 +typedef int SMB_ACL_TYPE_T;
6240 +typedef ushort *SMB_ACL_PERMSET_T;
6241 +typedef ushort SMB_ACL_PERM_T;
6242 +#define SMB_ACL_READ 4
6243 +#define SMB_ACL_WRITE 2
6244 +#define SMB_ACL_EXECUTE 1
6246 +/* Types of ACLs. */
6247 +#define SMB_ACL_USER USER
6248 +#define SMB_ACL_USER_OBJ USER_OBJ
6249 +#define SMB_ACL_GROUP GROUP
6250 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6251 +#define SMB_ACL_OTHER OTHER_OBJ
6252 +#define SMB_ACL_MASK CLASS_OBJ
6254 +typedef struct SMB_ACL_T {
6258 + struct acl acl[1];
6261 +typedef struct acl *SMB_ACL_ENTRY_T;
6263 +#define SMB_ACL_FIRST_ENTRY 0
6264 +#define SMB_ACL_NEXT_ENTRY 1
6266 +#define SMB_ACL_TYPE_ACCESS 0
6267 +#define SMB_ACL_TYPE_DEFAULT 1
6269 +#elif defined HAVE_IRIX_ACLS
6271 +#define SMB_ACL_TAG_T acl_tag_t
6272 +#define SMB_ACL_TYPE_T acl_type_t
6273 +#define SMB_ACL_PERMSET_T acl_permset_t
6274 +#define SMB_ACL_PERM_T acl_perm_t
6275 +#define SMB_ACL_READ ACL_READ
6276 +#define SMB_ACL_WRITE ACL_WRITE
6277 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6279 +/* Types of ACLs. */
6280 +#define SMB_ACL_USER ACL_USER
6281 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6282 +#define SMB_ACL_GROUP ACL_GROUP
6283 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6284 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6285 +#define SMB_ACL_MASK ACL_MASK
6287 +typedef struct SMB_ACL_T {
6293 +#define SMB_ACL_ENTRY_T acl_entry_t
6295 +#define SMB_ACL_FIRST_ENTRY 0
6296 +#define SMB_ACL_NEXT_ENTRY 1
6298 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6299 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6301 +#elif defined HAVE_AIX_ACLS
6303 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6305 +#include "/usr/include/acl.h"
6307 +typedef uint *SMB_ACL_PERMSET_T;
6309 +struct acl_entry_link{
6310 + struct acl_entry_link *prevp;
6311 + struct new_acl_entry *entryp;
6312 + struct acl_entry_link *nextp;
6316 +struct new_acl_entry{
6317 + unsigned short ace_len;
6318 + unsigned short ace_type;
6319 + unsigned int ace_access;
6320 + struct ace_id ace_id[1];
6323 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6324 +#define SMB_ACL_T struct acl_entry_link*
6326 +#define SMB_ACL_TAG_T unsigned short
6327 +#define SMB_ACL_TYPE_T int
6328 +#define SMB_ACL_PERM_T uint
6329 +#define SMB_ACL_READ S_IRUSR
6330 +#define SMB_ACL_WRITE S_IWUSR
6331 +#define SMB_ACL_EXECUTE S_IXUSR
6333 +/* Types of ACLs. */
6334 +#define SMB_ACL_USER ACEID_USER
6335 +#define SMB_ACL_USER_OBJ 3
6336 +#define SMB_ACL_GROUP ACEID_GROUP
6337 +#define SMB_ACL_GROUP_OBJ 4
6338 +#define SMB_ACL_OTHER 5
6339 +#define SMB_ACL_MASK 6
6342 +#define SMB_ACL_FIRST_ENTRY 1
6343 +#define SMB_ACL_NEXT_ENTRY 2
6345 +#define SMB_ACL_TYPE_ACCESS 0
6346 +#define SMB_ACL_TYPE_DEFAULT 1
6348 +#else /* No ACLs. */
6350 +/* No ACLS - fake it. */
6351 +#define SMB_ACL_TAG_T int
6352 +#define SMB_ACL_TYPE_T int
6353 +#define SMB_ACL_PERMSET_T mode_t
6354 +#define SMB_ACL_PERM_T mode_t
6355 +#define SMB_ACL_READ S_IRUSR
6356 +#define SMB_ACL_WRITE S_IWUSR
6357 +#define SMB_ACL_EXECUTE S_IXUSR
6359 +/* Types of ACLs. */
6360 +#define SMB_ACL_USER 0
6361 +#define SMB_ACL_USER_OBJ 1
6362 +#define SMB_ACL_GROUP 2
6363 +#define SMB_ACL_GROUP_OBJ 3
6364 +#define SMB_ACL_OTHER 4
6365 +#define SMB_ACL_MASK 5
6367 +typedef struct SMB_ACL_T {
6371 +typedef struct SMB_ACL_ENTRY_T {
6373 +} *SMB_ACL_ENTRY_T;
6375 +#define SMB_ACL_FIRST_ENTRY 0
6376 +#define SMB_ACL_NEXT_ENTRY 1
6378 +#define SMB_ACL_TYPE_ACCESS 0
6379 +#define SMB_ACL_TYPE_DEFAULT 1
6381 +#endif /* No ACLs. */
6382 +#endif /* _SMB_ACLS_H */
6383 --- old/testsuite/acls.test
6384 +++ new/testsuite/acls.test
6388 +# This program is distributable under the terms of the GNU GPL (see
6391 +# Test that rsync handles basic ACL preservation.
6393 +. $srcdir/testsuite/rsync.fns
6395 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6396 +case "$setfacl_nodef" in
6397 +true) test_skipped "I don't know how to use your setfacl command" ;;
6400 +makepath "$fromdir/foo"
6401 +echo something >"$fromdir/file1"
6402 +echo else >"$fromdir/file2"
6404 +files='foo file1 file2'
6406 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6407 +setfacl -m u:0:5 "$fromdir/file1"
6408 +setfacl -m u:0:5 "$fromdir/file2"
6410 +$RSYNC -avvA "$fromdir/" "$todir/"
6413 +getfacl $files >"$scratchdir/acls.txt"
6416 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6418 +# The script would have aborted on error, so getting here means we've won.
6420 --- old/testsuite/default-acls.test
6421 +++ new/testsuite/default-acls.test
6425 +# This program is distributable under the terms of the GNU GPL (see
6428 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6430 +. $srcdir/testsuite/rsync.fns
6432 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6433 +case "$setfacl_nodef" in
6434 +true) test_skipped "I don't know how to use your setfacl command" ;;
6435 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6436 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6438 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6440 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6442 + todir="$scratchdir/$1"
6444 + $setfacl_nodef "$todir"
6446 + case "$setfacl_nodef" in
6447 + *-k*) opts="-dm $2" ;;
6448 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6450 + setfacl $opts "$todir"
6452 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6453 + # even though the directory itself is outside the transfer
6454 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6455 + check_perms "$todir/to" $4 "Target $1"
6456 + check_perms "$todir/to/dir" $4 "Target $1"
6457 + check_perms "$todir/to/file" $3 "Target $1"
6458 + check_perms "$todir/to/program" $4 "Target $1"
6459 + # Make sure get_local_name doesn't mess us up when transferring only one file
6460 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6461 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6462 + # Make sure we obey default ACLs when not transferring a regular file
6463 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6464 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6467 +mkdir "$scratchdir/dir"
6468 +echo "File!" >"$scratchdir/file"
6469 +echo "#!/bin/sh" >"$scratchdir/program"
6470 +chmod 777 "$scratchdir/dir"
6471 +chmod 666 "$scratchdir/file"
6472 +chmod 777 "$scratchdir/program"
6474 +# Test some target directories
6476 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6477 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6478 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6479 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6480 +testit noda1 '' rw------- rwx------
6482 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6484 +testit noda3 '' rw-r--r-- rwxr-xr-x
6488 --- old/testsuite/devices.test
6489 +++ new/testsuite/devices.test
6490 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6491 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6493 cat <<EOT >"$chkfile"
6497 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6499 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6501 cat <<EOT >"$chkfile"
6505 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6507 @@ -58,7 +58,7 @@ sleep 1
6508 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6510 cat <<EOT >"$chkfile"
6514 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6516 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6519 cat <<EOT >"$chkfile"
6524 -hD+++++++ block2.5 => block3
6533 +hD+++++++++ block2.5 => block3
6539 if test ! -b "$fromdir/block2.5"; then
6540 sed -e '/block2\.5/d' \
6541 @@ -94,15 +94,15 @@ if test -b "$fromdir/block2.5"; then
6542 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
6544 cat <<EOT >"$chkfile"
6564 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
6566 --- old/testsuite/itemize.test
6567 +++ new/testsuite/itemize.test
6568 @@ -38,15 +38,15 @@ rm -f "$to2dir" "$to2dir.test"
6569 $RSYNC -iplr "$fromdir/" "$todir/" \
6571 cat <<EOT >"$chkfile"
6575 ->f+++++++ bar/baz/rsync
6577 ->f+++++++ foo/config1
6578 ->f+++++++ foo/config2
6579 ->f+++++++ foo/extra
6580 -cL+++++++ foo/sym -> ../bar/baz/rsync
6583 +cd+++++++++ bar/baz/
6584 +>f+++++++++ bar/baz/rsync
6586 +>f+++++++++ foo/config1
6587 +>f+++++++++ foo/config2
6588 +>f+++++++++ foo/extra
6589 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6591 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6593 @@ -58,10 +58,10 @@ chmod 601 "$fromdir/foo/config2"
6594 $RSYNC -iplrH "$fromdir/" "$todir/" \
6596 cat <<EOT >"$chkfile"
6597 ->f..T.... bar/baz/rsync
6598 ->f..T.... foo/config1
6599 ->f.sTp... foo/config2
6600 -hf..T.... foo/extra => foo/config1
6601 +>f..T...... bar/baz/rsync
6602 +>f..T...... foo/config1
6603 +>f.sTp..... foo/config2
6604 +hf..T...... foo/extra => foo/config1
6606 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6608 @@ -78,11 +78,11 @@ chmod 777 "$todir/bar/baz/rsync"
6609 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6611 cat <<EOT >"$chkfile"
6612 -.f..tp... bar/baz/rsync
6614 -.f..t.... foo/config1
6615 ->fcstp... foo/config2
6616 -cL..T.... foo/sym -> ../bar/baz/rsync
6617 +.f..tp..... bar/baz/rsync
6619 +.f..t...... foo/config1
6620 +>fcstp..... foo/config2
6621 +cL..T...... foo/sym -> ../bar/baz/rsync
6623 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6625 @@ -107,15 +107,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6628 cat <<EOT >"$chkfile"
6632 -.f...p... bar/baz/rsync
6635 ->f..t.... foo/config2
6637 -.L foo/sym -> ../bar/baz/rsync
6641 +.f...p..... bar/baz/rsync
6644 +>f..t...... foo/config2
6646 +.L foo/sym -> ../bar/baz/rsync
6648 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6650 @@ -134,8 +134,8 @@ touch "$todir/foo/config2"
6651 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6653 cat <<EOT >"$chkfile"
6654 -.f...p... foo/config1
6655 ->f..t.... foo/config2
6656 +.f...p..... foo/config1
6657 +>f..t...... foo/config2
6659 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6661 @@ -143,15 +143,15 @@ $RSYNC -ivvplrtH --copy-dest=../to "$fro
6664 cat <<EOT >"$chkfile"
6672 -hf foo/extra => foo/config1
6673 -cL foo/sym -> ../bar/baz/rsync
6681 +hf foo/extra => foo/config1
6682 +cL foo/sym -> ../bar/baz/rsync
6684 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6686 @@ -159,7 +159,7 @@ rm -rf "$to2dir"
6687 $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \
6689 cat <<EOT >"$chkfile"
6690 -hf foo/extra => foo/config1
6691 +hf foo/extra => foo/config1
6693 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6695 @@ -186,15 +186,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$
6698 cat <<EOT >"$chkfile"
6706 -hf foo/extra => foo/config1
6707 -$L foo/sym -> ../bar/baz/rsync
6715 +hf foo/extra => foo/config1
6716 +$L foo/sym -> ../bar/baz/rsync
6718 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6720 @@ -236,14 +236,14 @@ filter_outfile
6721 # TODO fix really-old problem when combining -H with --compare-dest:
6722 # missing output for foo/extra hard-link (and it might not be updated)!
6723 cat <<EOT >"$chkfile"
6731 -.L foo/sym -> ../bar/baz/rsync
6739 +.L foo/sym -> ../bar/baz/rsync
6741 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6747 extern int preserve_uid;
6748 extern int preserve_gid;
6749 +extern int preserve_acls;
6750 extern int numeric_ids;
6753 @@ -270,7 +271,7 @@ void send_uid_list(int f)
6755 struct idlist *list;
6757 - if (preserve_uid) {
6758 + if (preserve_uid || preserve_acls) {
6760 /* we send sequences of uid/byte-length/name */
6761 for (list = uidlist; list; list = list->next) {
6762 @@ -287,7 +288,7 @@ void send_uid_list(int f)
6766 - if (preserve_gid) {
6767 + if (preserve_gid || preserve_acls) {
6769 for (list = gidlist; list; list = list->next) {
6771 @@ -308,7 +309,7 @@ void recv_uid_list(int f, struct file_li
6775 - if (preserve_uid && !numeric_ids) {
6776 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6777 /* read the uid list */
6778 while ((id = read_int(f)) != 0) {
6779 int len = read_byte(f);
6780 @@ -320,7 +321,7 @@ void recv_uid_list(int f, struct file_li
6784 - if (preserve_gid && !numeric_ids) {
6785 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6786 /* read the gid list */
6787 while ((id = read_int(f)) != 0) {
6788 int len = read_byte(f);
6789 @@ -332,6 +333,16 @@ void recv_uid_list(int f, struct file_li
6793 +#ifdef SUPPORT_ACLS
6794 + if (preserve_acls && !numeric_ids) {
6796 + while ((id = next_acl_uid(flist)) != NULL)
6797 + *id = match_uid(*id);
6798 + while ((id = next_acl_gid(flist)) != NULL)
6799 + *id = match_gid(*id);
6803 /* Now convert all the uids/gids from sender values to our values. */
6804 if (am_root && preserve_uid && !numeric_ids) {
6805 for (i = 0; i < flist->count; i++)
6808 @@ -1467,3 +1467,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6813 +void *expand_item_list(item_list *lp, size_t item_size,
6814 + const char *desc, int incr)
6816 + /* First time through, 0 <= 0, so list is expanded. */
6817 + if (lp->malloced <= lp->count) {
6819 + size_t new_size = lp->malloced;
6821 + new_size -= incr; /* increase slowly */
6822 + else if (new_size < (size_t)incr)
6826 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6827 + if (verbose >= 4) {
6828 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6829 + who_am_i(), desc, (double)new_size * item_size,
6830 + new_ptr == lp->items ? " not" : "");
6833 + out_of_memory("expand_item_list");
6835 + lp->items = new_ptr;
6836 + lp->malloced = new_size;
6838 + return (char*)lp->items + (lp->count++ * item_size);