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_DEF_ACL(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_DEF_ACL(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 + && BITS_EQUAL(old_mode, 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_DEF_ACL(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 @@ -93,7 +94,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 @@ -125,15 +127,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 @@ -171,15 +182,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 @@ -189,6 +203,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 @@ -260,7 +281,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 @@ -147,6 +148,8 @@ static void list_file_entry(struct file_
1328 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 @@ -662,6 +665,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 if (always_checksum && S_ISREG(mode))
1347 extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
1349 @@ -787,6 +796,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 @@ -1047,6 +1061,9 @@ static struct file_struct *send_file_nam
1362 unsigned short flags)
1364 struct file_struct *file;
1365 +#ifdef SUPPORT_ACLS
1369 file = make_file(fname, flist, stp, flags,
1370 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1371 @@ -1056,12 +1073,26 @@ static struct file_struct *send_file_nam
1372 if (chmod_modes && !S_ISLNK(file->mode))
1373 file->mode = tweak_mode(file->mode, chmod_modes);
1375 +#ifdef SUPPORT_ACLS
1376 + if (preserve_acls && f >= 0) {
1377 + sx.st.st_mode = file->mode;
1378 + sx.acc_acl = sx.def_acl = NULL;
1379 + if (get_acl(fname, &sx) < 0)
1384 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1386 flist_expand(flist);
1387 flist->files[flist->count++] = file;
1390 send_file_entry(file, f, flist->count - 1);
1391 +#ifdef SUPPORT_ACLS
1392 + if (preserve_acls)
1401 @@ -35,6 +35,7 @@ extern int do_progress;
1402 extern int relative_paths;
1403 extern int implied_dirs;
1404 extern int keep_dirlinks;
1405 +extern int preserve_acls;
1406 extern int preserve_links;
1407 extern int preserve_devices;
1408 extern int preserve_specials;
1409 @@ -87,6 +88,7 @@ extern int force_delete;
1410 extern int one_file_system;
1411 extern struct stats stats;
1412 extern dev_t filesystem_dev;
1413 +extern mode_t orig_umask;
1414 extern char *backup_dir;
1415 extern char *backup_suffix;
1416 extern int backup_suffix_len;
1417 @@ -518,21 +520,26 @@ static void do_delete_pass(struct file_l
1418 rprintf(FINFO, " \r");
1421 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1422 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1424 - if (preserve_perms && !BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS))
1425 + if (preserve_perms && !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
1428 - if (am_root && preserve_uid && st->st_uid != F_UID(file))
1429 + if (am_root && preserve_uid && sxp->st.st_uid != F_UID(file))
1432 - if (preserve_gid && F_GID(file) != GID_NONE && st->st_gid != F_GID(file))
1433 + if (preserve_gid && F_GID(file) != GID_NONE && sxp->st.st_gid != F_GID(file))
1436 +#ifdef SUPPORT_ACLS
1437 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1444 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1445 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1446 int32 iflags, uchar fnamecmp_type, const char *xname)
1448 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1449 @@ -540,20 +547,24 @@ void itemize(struct file_struct *file, i
1450 : S_ISDIR(file->mode) ? !omit_dir_times
1451 : !S_ISLNK(file->mode);
1453 - if (S_ISREG(file->mode) && F_LENGTH(file) != st->st_size)
1454 + if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
1455 iflags |= ITEM_REPORT_SIZE;
1456 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1457 && !(iflags & ITEM_MATCHED)
1458 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1459 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1460 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1461 iflags |= ITEM_REPORT_TIME;
1462 - if (!BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS))
1463 + if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
1464 iflags |= ITEM_REPORT_PERMS;
1465 - if (preserve_uid && am_root && F_UID(file) != st->st_uid)
1466 + if (preserve_uid && am_root && F_UID(file) != sxp->st.st_uid)
1467 iflags |= ITEM_REPORT_OWNER;
1468 if (preserve_gid && F_GID(file) != GID_NONE
1469 - && st->st_gid != F_GID(file))
1470 + && sxp->st.st_gid != F_GID(file))
1471 iflags |= ITEM_REPORT_GROUP;
1472 +#ifdef SUPPORT_ACLS
1473 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1474 + iflags |= ITEM_REPORT_ACL;
1477 iflags |= ITEM_IS_NEW;
1479 @@ -808,7 +819,7 @@ void check_for_finished_hlinks(int itemi
1480 * handling the file, -1 if no dest-linking occurred, or a non-negative
1481 * value if we found an alternate basis file. */
1482 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1483 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1484 + char *cmpbuf, statx *sxp, int itemizing,
1487 int best_match = -1;
1488 @@ -817,7 +828,7 @@ static int try_dests_reg(struct file_str
1491 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1492 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1493 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1495 switch (match_level) {
1497 @@ -825,16 +836,20 @@ static int try_dests_reg(struct file_str
1501 - if (!unchanged_file(cmpbuf, file, stp))
1502 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1508 - if (!unchanged_attrs(file, stp))
1509 +#ifdef SUPPORT_ACLS
1510 + if (preserve_acls)
1511 + get_acl(cmpbuf, sxp);
1513 + if (!unchanged_attrs(file, sxp))
1515 if (always_checksum && preserve_times
1516 - && cmp_time(stp->st_mtime, file->modtime))
1517 + && cmp_time(sxp->st.st_mtime, file->modtime))
1521 @@ -849,7 +864,7 @@ static int try_dests_reg(struct file_str
1522 if (j != best_match) {
1524 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1525 - if (link_stat(cmpbuf, stp, 0) < 0)
1526 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1530 @@ -859,16 +874,25 @@ static int try_dests_reg(struct file_str
1531 if (!hard_link_one(file, fname, cmpbuf, 1))
1533 if (preserve_hard_links && F_IS_HLINKED(file))
1534 - finish_hard_link(file, fname, stp, itemizing, code, j);
1535 + finish_hard_link(file, fname, &sxp->st, itemizing, code, j);
1536 if (itemizing && (verbose > 1 || stdout_format_has_i > 1)) {
1537 - itemize(file, ndx, 1, stp,
1538 +#ifdef SUPPORT_ACLS
1539 + if (preserve_acls && !ACL_READY(*sxp))
1540 + get_acl(fname, sxp);
1542 + itemize(file, ndx, 1, sxp,
1543 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
1549 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1551 +#ifdef SUPPORT_ACLS
1552 + if (preserve_acls && !ACL_READY(*sxp))
1553 + get_acl(fname, sxp);
1555 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1557 if (verbose > 1 && maybe_ATTRS_REPORT)
1558 rprintf(FCLIENT, "%s is uptodate\n", fname);
1560 @@ -885,8 +909,13 @@ static int try_dests_reg(struct file_str
1565 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1567 +#ifdef SUPPORT_ACLS
1568 + if (preserve_acls && !ACL_READY(*sxp))
1569 + get_acl(fname, sxp);
1571 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1573 set_file_attrs(fname, file, NULL, 0);
1574 if (maybe_ATTRS_REPORT
1575 && ((!itemizing && verbose && match_level == 2)
1576 @@ -897,7 +926,7 @@ static int try_dests_reg(struct file_str
1578 #ifdef SUPPORT_HARD_LINKS
1579 if (preserve_hard_links && F_IS_HLINKED(file))
1580 - finish_hard_link(file, fname, stp, itemizing, code, -1);
1581 + finish_hard_link(file, fname, &sxp->st, itemizing, code, -1);
1585 @@ -909,7 +938,7 @@ static int try_dests_reg(struct file_str
1586 * handling the file, or -1 if no dest-linking occurred, or a non-negative
1587 * value if we found an alternate basis file. */
1588 static int try_dests_non(struct file_struct *file, char *fname, int ndx,
1589 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1590 + char *cmpbuf, statx *sxp, int itemizing,
1593 char lnk[MAXPATHLEN];
1594 @@ -942,24 +971,24 @@ static int try_dests_non(struct file_str
1597 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1598 - if (link_stat(cmpbuf, stp, 0) < 0)
1599 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1603 - if (!S_ISDIR(stp->st_mode))
1604 + if (!S_ISDIR(sxp->st.st_mode))
1608 - if (!IS_SPECIAL(stp->st_mode))
1609 + if (!IS_SPECIAL(sxp->st.st_mode))
1613 - if (!IS_DEVICE(stp->st_mode))
1614 + if (!IS_DEVICE(sxp->st.st_mode))
1617 #ifdef SUPPORT_LINKS
1619 - if (!S_ISLNK(stp->st_mode))
1620 + if (!S_ISLNK(sxp->st.st_mode))
1624 @@ -974,7 +1003,7 @@ static int try_dests_non(struct file_str
1627 devp = F_RDEV_P(file);
1628 - if (stp->st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
1629 + if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
1632 #ifdef SUPPORT_LINKS
1633 @@ -991,7 +1020,11 @@ static int try_dests_non(struct file_str
1637 - if (unchanged_attrs(file, stp)) {
1638 +#ifdef SUPPORT_ACLS
1639 + if (preserve_acls)
1640 + get_acl(cmpbuf, sxp);
1642 + if (unchanged_attrs(file, sxp)) {
1646 @@ -1004,7 +1037,7 @@ static int try_dests_non(struct file_str
1647 if (j != best_match) {
1649 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1650 - if (link_stat(cmpbuf, stp, 0) < 0)
1651 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1655 @@ -1035,7 +1068,15 @@ static int try_dests_non(struct file_str
1657 + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
1658 char *lp = match_level == 3 ? "" : NULL;
1659 - itemize(file, ndx, 0, stp, chg + ITEM_MATCHED, 0, lp);
1660 +#ifdef SUPPORT_ACLS
1661 + if (preserve_acls)
1662 + get_acl(fname, sxp);
1664 + itemize(file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp);
1665 +#ifdef SUPPORT_ACLS
1666 + if (preserve_acls)
1670 if (verbose > 1 && maybe_ATTRS_REPORT) {
1671 rprintf(FCLIENT, "%s%s is uptodate\n",
1672 @@ -1048,6 +1089,7 @@ static int try_dests_non(struct file_str
1675 static int phase = 0;
1676 +static int dflt_perms;
1678 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1679 * make sure it exists, and has the right permissions/timestamp info. For
1680 @@ -1068,7 +1110,8 @@ static void recv_generator(char *fname,
1681 static int need_fuzzy_dirlist = 0;
1682 struct file_struct *fuzzy_file = NULL;
1683 int fd = -1, f_copy = -1;
1684 - STRUCT_STAT st, real_st, partial_st;
1685 + statx sx, real_sx;
1686 + STRUCT_STAT partial_st;
1687 struct file_struct *back_file = NULL;
1688 int statret, real_ret, stat_errno;
1689 char *fnamecmp, *partialptr, *backupptr = NULL;
1690 @@ -1124,6 +1167,9 @@ static void recv_generator(char *fname,
1691 } else if (!dry_run)
1694 +#ifdef SUPPORT_ACLS
1695 + sx.acc_acl = sx.def_acl = NULL;
1699 stat_errno = ENOENT;
1700 @@ -1131,7 +1177,7 @@ static void recv_generator(char *fname,
1701 const char *dn = file->dirname ? file->dirname : ".";
1702 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1703 if (relative_paths && !implied_dirs
1704 - && do_stat(dn, &st) < 0
1705 + && do_stat(dn, &sx.st) < 0
1706 && create_directory_path(fname) < 0) {
1707 rsyserr(FERROR, errno,
1708 "recv_generator: mkdir %s failed",
1709 @@ -1143,6 +1189,10 @@ static void recv_generator(char *fname,
1712 need_fuzzy_dirlist = 1;
1713 +#ifdef SUPPORT_ACLS
1714 + if (!preserve_perms)
1715 + dflt_perms = default_perms_for_dir(dn);
1718 parent_dirname = dn;
1720 @@ -1152,7 +1202,7 @@ static void recv_generator(char *fname,
1721 need_fuzzy_dirlist = 0;
1724 - statret = link_stat(fname, &st,
1725 + statret = link_stat(fname, &sx.st,
1726 keep_dirlinks && S_ISDIR(file->mode));
1729 @@ -1170,8 +1220,9 @@ static void recv_generator(char *fname,
1730 * mode based on the local permissions and some heuristics. */
1731 if (!preserve_perms) {
1732 int exists = statret == 0
1733 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1734 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1735 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1736 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1740 if (S_ISDIR(file->mode)) {
1741 @@ -1180,8 +1231,8 @@ static void recv_generator(char *fname,
1742 * file of that name and it is *not* a directory, then
1743 * we need to delete it. If it doesn't exist, then
1744 * (perhaps recursively) create it. */
1745 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1746 - if (delete_item(fname, st.st_mode, "directory", del_opts) != 0)
1747 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1748 + if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0)
1752 @@ -1190,14 +1241,14 @@ static void recv_generator(char *fname,
1759 if (*fname == '.' && fname[1] == '\0')
1763 if (statret != 0 && basis_dir[0] != NULL) {
1764 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1765 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1769 @@ -1206,7 +1257,11 @@ static void recv_generator(char *fname,
1772 if (itemizing && f_out != -1) {
1773 - itemize(file, ndx, statret, &st,
1774 +#ifdef SUPPORT_ACLS
1775 + if (preserve_acls && statret == 0)
1776 + get_acl(fname, &sx);
1778 + itemize(file, ndx, statret, &sx,
1779 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1781 if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1782 @@ -1226,21 +1281,21 @@ static void recv_generator(char *fname,
1786 - if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0)
1787 + if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, 0)
1788 && verbose && code != FNONE && f_out != -1)
1789 rprintf(code, "%s/\n", fname);
1790 if (real_ret != 0 && one_file_system)
1791 - real_st.st_dev = filesystem_dev;
1792 + real_sx.st.st_dev = filesystem_dev;
1793 if (delete_during && f_out != -1 && !phase && dry_run < 2
1794 && (file->flags & FLAG_XFER_DIR))
1795 - delete_in_dir(the_file_list, fname, file, &real_st);
1797 + delete_in_dir(the_file_list, fname, file, &real_sx.st);
1801 #ifdef SUPPORT_HARD_LINKS
1802 if (preserve_hard_links && F_HLINK_NOT_FIRST(file)
1803 - && hard_link_check(file, ndx, fname, statret, &st, itemizing, code))
1805 + && hard_link_check(file, ndx, fname, statret, &sx, itemizing, code))
1809 if (preserve_links && S_ISLNK(file->mode)) {
1810 @@ -1260,17 +1315,17 @@ static void recv_generator(char *fname,
1811 char lnk[MAXPATHLEN];
1814 - if (!S_ISLNK(st.st_mode))
1815 + if (!S_ISLNK(sx.st.st_mode))
1817 else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0
1818 && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
1819 /* The link is pointing to the right place. */
1821 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1822 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1823 + itemize(file, ndx, 0, &sx, 0, 0, NULL);
1824 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1825 #ifdef SUPPORT_HARD_LINKS
1826 if (preserve_hard_links && F_IS_HLINKED(file))
1827 - finish_hard_link(file, fname, &st, itemizing, code, -1);
1828 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
1830 if (remove_source_files == 1)
1831 goto return_with_success;
1832 @@ -1278,10 +1333,10 @@ static void recv_generator(char *fname,
1834 /* Not the right symlink (or not a symlink), so
1836 - if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0)
1837 + if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0)
1839 } else if (basis_dir[0] != NULL) {
1840 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1841 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1844 #ifndef CAN_HARDLINK_SYMLINK
1845 @@ -1306,7 +1361,7 @@ static void recv_generator(char *fname,
1847 set_file_attrs(fname, file, NULL, 0);
1849 - itemize(file, ndx, statret, &st,
1850 + itemize(file, ndx, statret, &sx,
1851 ITEM_LOCAL_CHANGE, 0, NULL);
1853 if (code != FNONE && verbose)
1854 @@ -1332,33 +1387,38 @@ static void recv_generator(char *fname,
1857 if (IS_DEVICE(file->mode)) {
1858 - if (!IS_DEVICE(st.st_mode))
1859 + if (!IS_DEVICE(sx.st.st_mode))
1863 - if (!IS_SPECIAL(st.st_mode))
1864 + if (!IS_SPECIAL(sx.st.st_mode))
1869 - && BITS_EQUAL(st.st_mode, file->mode, _S_IFMT)
1870 - && st.st_rdev == rdev) {
1871 + && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT)
1872 + && sx.st.st_rdev == rdev) {
1873 /* The device or special file is identical. */
1875 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1876 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1878 +#ifdef SUPPORT_ACLS
1879 + if (preserve_acls)
1880 + get_acl(fname, &sx);
1882 + itemize(file, ndx, 0, &sx, 0, 0, NULL);
1884 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1885 #ifdef SUPPORT_HARD_LINKS
1886 if (preserve_hard_links && F_IS_HLINKED(file))
1887 - finish_hard_link(file, fname, &st, itemizing, code, -1);
1888 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
1890 if (remove_source_files == 1)
1891 goto return_with_success;
1895 - if (delete_item(fname, st.st_mode, t, del_opts) != 0)
1896 + if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0)
1898 } else if (basis_dir[0] != NULL) {
1899 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1900 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1903 #ifndef CAN_HARDLINK_SPECIAL
1904 @@ -1388,7 +1448,11 @@ static void recv_generator(char *fname,
1906 set_file_attrs(fname, file, NULL, 0);
1908 - itemize(file, ndx, statret, &st,
1909 +#ifdef SUPPORT_ACLS
1910 + if (preserve_acls && statret == 0)
1911 + get_acl(fname, &sx);
1913 + itemize(file, ndx, statret, &sx,
1914 ITEM_LOCAL_CHANGE, 0, NULL);
1916 if (code != FNONE && verbose)
1917 @@ -1400,7 +1464,7 @@ static void recv_generator(char *fname,
1918 if (remove_source_files == 1)
1919 goto return_with_success;
1925 if (!S_ISREG(file->mode)) {
1926 @@ -1434,7 +1498,7 @@ static void recv_generator(char *fname,
1929 if (update_only && statret == 0
1930 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1931 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1933 rprintf(FINFO, "%s is newer\n", fname);
1935 @@ -1443,20 +1507,20 @@ static void recv_generator(char *fname,
1937 fnamecmp_type = FNAMECMP_FNAME;
1939 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1940 - if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0)
1941 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1942 + if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0)
1945 stat_errno = ENOENT;
1948 if (statret != 0 && basis_dir[0] != NULL) {
1949 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1950 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1953 if (remove_source_files == 1)
1954 goto return_with_success;
1959 fnamecmp = fnamecmpbuf;
1960 @@ -1466,7 +1530,7 @@ static void recv_generator(char *fname,
1967 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1968 && link_stat(partialptr, &partial_st, 0) == 0
1969 @@ -1485,7 +1549,7 @@ static void recv_generator(char *fname,
1970 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1971 fname, fnamecmpbuf);
1973 - st.st_size = F_LENGTH(fuzzy_file);
1974 + sx.st.st_size = F_LENGTH(fuzzy_file);
1976 fnamecmp = fnamecmpbuf;
1977 fnamecmp_type = FNAMECMP_FUZZY;
1978 @@ -1504,36 +1568,41 @@ static void recv_generator(char *fname,
1982 - if (append_mode && st.st_size > F_LENGTH(file))
1983 + if (append_mode && sx.st.st_size > F_LENGTH(file))
1986 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1988 else if (fnamecmp_type == FNAMECMP_FUZZY)
1990 - else if (unchanged_file(fnamecmp, file, &st)) {
1991 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1993 do_unlink(partialptr);
1994 handle_partial_dir(partialptr, PDIR_DELETE);
1997 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1998 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
2000 +#ifdef SUPPORT_ACLS
2001 + if (preserve_acls && statret == 0)
2002 + get_acl(fnamecmp, &sx);
2004 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
2006 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
2007 #ifdef SUPPORT_HARD_LINKS
2008 if (preserve_hard_links && F_IS_HLINKED(file))
2009 - finish_hard_link(file, fname, &st, itemizing, code, -1);
2010 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
2012 if (remove_source_files != 1)
2015 return_with_success:
2017 send_msg_int(MSG_SUCCESS, ndx);
2025 + sx.st = partial_st;
2026 fnamecmp = partialptr;
2027 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2029 @@ -1558,16 +1627,20 @@ static void recv_generator(char *fname,
2030 /* pretend the file didn't exist */
2031 #ifdef SUPPORT_HARD_LINKS
2032 if (preserve_hard_links && F_HLINK_NOT_LAST(file))
2036 statret = real_ret = -1;
2037 +#ifdef SUPPORT_ACLS
2038 + if (preserve_acls && ACL_READY(sx))
2044 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2045 if (!(backupptr = get_backup_name(fname))) {
2050 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2052 @@ -1578,7 +1651,7 @@ static void recv_generator(char *fname,
2053 full_fname(backupptr));
2054 unmake_file(back_file);
2059 if ((f_copy = do_open(backupptr,
2060 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2061 @@ -1586,14 +1659,14 @@ static void recv_generator(char *fname,
2062 full_fname(backupptr));
2063 unmake_file(back_file);
2068 fnamecmp_type = FNAMECMP_BACKUP;
2072 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2073 - fnamecmp, (double)st.st_size);
2074 + fnamecmp, (double)sx.st.st_size);
2078 @@ -1615,26 +1688,34 @@ static void recv_generator(char *fname,
2079 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2080 if (fnamecmp_type == FNAMECMP_FUZZY)
2081 iflags |= ITEM_XNAME_FOLLOWS;
2082 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2083 +#ifdef SUPPORT_ACLS
2084 + if (preserve_acls && real_ret == 0)
2085 + get_acl(fnamecmp, &real_sx);
2087 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2088 fuzzy_file ? F_BASENAME(fuzzy_file) : NULL);
2089 +#ifdef SUPPORT_ACLS
2090 + if (preserve_acls)
2091 + free_acl(&real_sx);
2096 #ifdef SUPPORT_HARD_LINKS
2097 if (preserve_hard_links && F_IS_HLINKED(file))
2098 - finish_hard_link(file, fname, &st, itemizing, code, -1);
2099 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
2108 if (statret != 0 || whole_file) {
2109 write_sum_head(f_out, NULL);
2114 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2115 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2119 @@ -1647,6 +1728,13 @@ static void recv_generator(char *fname,
2125 +#ifdef SUPPORT_ACLS
2126 + if (preserve_acls)
2132 void generate_files(int f_out, struct file_list *flist, char *local_name)
2133 @@ -1713,6 +1801,8 @@ void generate_files(int f_out, struct fi
2134 * notice that and let us know via the redo pipe (or its closing). */
2137 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2139 for (i = 0; i < flist->count; i++) {
2140 struct file_struct *file = flist->files[i];
2144 @@ -27,6 +27,7 @@ extern int verbose;
2146 extern int do_xfers;
2147 extern int link_dest;
2148 +extern int preserve_acls;
2149 extern int make_backups;
2150 extern int protocol_version;
2151 extern int remove_source_files;
2152 @@ -334,15 +335,19 @@ void match_hard_links(void)
2155 static int maybe_hard_link(struct file_struct *file, int ndx,
2156 - const char *fname, int statret, STRUCT_STAT *stp,
2157 + const char *fname, int statret, statx *sxp,
2158 const char *oldname, STRUCT_STAT *old_stp,
2159 const char *realname, int itemizing, enum logcode code)
2162 - if (stp->st_dev == old_stp->st_dev
2163 - && stp->st_ino == old_stp->st_ino) {
2164 + if (sxp->st.st_dev == old_stp->st_dev
2165 + && sxp->st.st_ino == old_stp->st_ino) {
2167 - itemize(file, ndx, statret, stp,
2168 +#ifdef SUPPORT_ACLS
2169 + if (preserve_acls && !ACL_READY(*sxp))
2170 + get_acl(fname, sxp);
2172 + itemize(file, ndx, statret, sxp,
2173 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2176 @@ -363,7 +368,11 @@ static int maybe_hard_link(struct file_s
2178 if (hard_link_one(file, fname, oldname, 0)) {
2180 - itemize(file, ndx, statret, stp,
2181 +#ifdef SUPPORT_ACLS
2182 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2183 + get_acl(fname, sxp);
2185 + itemize(file, ndx, statret, sxp,
2186 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2189 @@ -377,7 +386,7 @@ static int maybe_hard_link(struct file_s
2190 /* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not. Returns:
2191 * 0 = process the file, 1 = skip the file, -1 = error occurred. */
2192 int hard_link_check(struct file_struct *file, int ndx, const char *fname,
2193 - int statret, STRUCT_STAT *stp, int itemizing,
2194 + int statret, statx *sxp, int itemizing,
2197 STRUCT_STAT prev_st;
2198 @@ -428,18 +437,20 @@ int hard_link_check(struct file_struct *
2199 if (statret < 0 && basis_dir[0] != NULL) {
2200 /* If we match an alt-dest item, we don't output this as a change. */
2201 char cmpbuf[MAXPATHLEN];
2202 - STRUCT_STAT alt_st;
2205 +#ifdef SUPPORT_ACLS
2206 + alt_sx.acc_acl = alt_sx.def_acl = NULL;
2209 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
2210 - if (link_stat(cmpbuf, &alt_st, 0) < 0)
2211 + if (link_stat(cmpbuf, &alt_sx.st, 0) < 0)
2214 - if (prev_st.st_dev != alt_st.st_dev
2215 - || prev_st.st_ino != alt_st.st_ino)
2216 + if (prev_st.st_dev != alt_sx.st.st_dev
2217 + || prev_st.st_ino != alt_sx.st.st_ino)
2221 if (verbose < 2 || !stdout_format_has_i) {
2224 @@ -448,16 +459,36 @@ int hard_link_check(struct file_struct *
2228 - if (!unchanged_file(cmpbuf, file, &alt_st))
2229 + if (!unchanged_file(cmpbuf, file, &alt_sx.st))
2233 - if (unchanged_attrs(file, &alt_st))
2234 +#ifdef SUPPORT_ACLS
2235 + if (preserve_acls)
2236 + get_acl(cmpbuf, &alt_sx);
2238 + if (unchanged_attrs(file, &alt_sx))
2240 } while (basis_dir[++j] != NULL);
2241 + if (statret == 1) {
2242 + sxp->st = alt_sx.st;
2243 +#ifdef SUPPORT_ACLS
2244 + if (preserve_acls) {
2245 + if (!ACL_READY(*sxp))
2246 + get_acl(cmpbuf, sxp);
2248 + sxp->acc_acl = alt_sx.acc_acl;
2249 + sxp->def_acl = alt_sx.def_acl;
2254 +#ifdef SUPPORT_ACLS
2255 + else if (preserve_acls)
2256 + free_acl(&alt_sx);
2260 - if (maybe_hard_link(file, ndx, fname, statret, stp, prev_name, &prev_st,
2261 + if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st,
2262 realname, itemizing, code) < 0)
2265 @@ -492,7 +523,8 @@ void finish_hard_link(struct file_struct
2266 STRUCT_STAT *stp, int itemizing, enum logcode code,
2269 - STRUCT_STAT st, prev_st;
2272 char alt_name[MAXPATHLEN], *prev_name;
2273 const char *our_name;
2274 int prev_statret, ndx, prev_ndx = F_HL_PREV(file);
2275 @@ -516,14 +548,24 @@ void finish_hard_link(struct file_struct
2279 +#ifdef SUPPORT_ACLS
2280 + prev_sx.acc_acl = prev_sx.def_acl = NULL;
2283 while ((ndx = prev_ndx) >= 0) {
2286 file->flags = (file->flags & ~FLAG_HLINK_FIRST) | FLAG_HLINK_DONE;
2287 prev_ndx = F_HL_PREV(file);
2288 prev_name = f_name(file, NULL);
2289 - prev_statret = link_stat(prev_name, &prev_st, 0);
2290 - if (maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_st,
2291 - our_name, stp, fname, itemizing, code) < 0)
2292 + prev_statret = link_stat(prev_name, &prev_sx.st, 0);
2293 + val = maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_sx,
2294 + our_name, stp, fname, itemizing, code);
2295 +#ifdef SUPPORT_ACLS
2296 + if (preserve_acls)
2297 + free_acl(&prev_sx);
2301 if (remove_source_files == 1 && do_xfers)
2302 send_msg_int(MSG_SUCCESS, ndx);
2303 --- old/lib/sysacls.c
2304 +++ new/lib/sysacls.c
2307 + Unix SMB/CIFS implementation.
2308 + Samba system utilities for ACL support.
2309 + Copyright (C) Jeremy Allison 2000.
2311 + This program is free software; you can redistribute it and/or modify
2312 + it under the terms of the GNU General Public License as published by
2313 + the Free Software Foundation; either version 2 of the License, or
2314 + (at your option) any later version.
2316 + This program is distributed in the hope that it will be useful,
2317 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2318 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2319 + GNU General Public License for more details.
2321 + You should have received a copy of the GNU General Public License
2322 + along with this program; if not, write to the Free Software
2323 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2327 +#include "sysacls.h" /****** ADDED ******/
2329 +#ifdef SUPPORT_ACLS
2331 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2337 +void SAFE_FREE(void *mem)
2343 +char *uidtoname(uid_t uid)
2345 + static char idbuf[12];
2346 + struct passwd *pw;
2348 + if ((pw = getpwuid(uid)) == NULL) {
2349 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2352 + return pw->pw_name;
2354 +/****** EXTRAS -- END ******/
2357 + This file wraps all differing system ACL interfaces into a consistent
2358 + one based on the POSIX interface. It also returns the correct errors
2359 + for older UNIX systems that don't support ACLs.
2361 + The interfaces that each ACL implementation must support are as follows :
2363 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2364 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2365 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2366 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2367 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2368 + SMB_ACL_T sys_acl_get_fd(int fd)
2369 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2370 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2371 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2372 + SMB_ACL_T sys_acl_init( int count)
2373 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2374 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2375 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2376 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2377 + int sys_acl_valid( SMB_ACL_T theacl )
2378 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2379 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2380 + int sys_acl_delete_def_file(const char *path)
2382 + This next one is not POSIX complient - but we *have* to have it !
2383 + More POSIX braindamage.
2385 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2387 + The generic POSIX free is the following call. We split this into
2388 + several different free functions as we may need to add tag info
2389 + to structures when emulating the POSIX interface.
2391 + int sys_acl_free( void *obj_p)
2393 + The calls we actually use are :
2395 + int sys_acl_free_text(char *text) - free acl_to_text
2396 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2397 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2401 +#if defined(HAVE_POSIX_ACLS)
2403 +/* Identity mapping - easy. */
2405 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2407 + return acl_get_entry( the_acl, entry_id, entry_p);
2410 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2412 + return acl_get_tag_type( entry_d, tag_type_p);
2415 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2417 + return acl_get_permset( entry_d, permset_p);
2420 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2422 + return acl_get_qualifier( entry_d);
2425 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2427 + return acl_get_file( path_p, type);
2430 +SMB_ACL_T sys_acl_get_fd(int fd)
2432 + return acl_get_fd(fd);
2435 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2437 + return acl_clear_perms(permset);
2440 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2442 + return acl_add_perm(permset, perm);
2445 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2447 +#if defined(HAVE_ACL_GET_PERM_NP)
2449 + * Required for TrustedBSD-based ACL implementations where
2450 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2453 + return acl_get_perm_np(permset, perm);
2455 + return acl_get_perm(permset, perm);
2459 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2461 + return acl_to_text( the_acl, plen);
2464 +SMB_ACL_T sys_acl_init( int count)
2466 + return acl_init(count);
2469 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2471 + return acl_create_entry(pacl, pentry);
2474 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2476 + return acl_set_tag_type(entry, tagtype);
2479 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2481 + return acl_set_qualifier(entry, qual);
2484 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2486 + return acl_set_permset(entry, permset);
2489 +int sys_acl_valid( SMB_ACL_T theacl )
2491 + return acl_valid(theacl);
2494 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2496 + return acl_set_file(name, acltype, theacl);
2499 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2501 + return acl_set_fd(fd, theacl);
2504 +int sys_acl_delete_def_file(const char *name)
2506 + return acl_delete_def_file(name);
2509 +int sys_acl_free_text(char *text)
2511 + return acl_free(text);
2514 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2516 + return acl_free(the_acl);
2519 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2521 + return acl_free(qual);
2524 +#elif defined(HAVE_TRU64_ACLS)
2526 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2527 + * is based on Draft 13 of the POSIX spec which is
2528 + * slightly different from the Draft 16 interface.
2530 + * Also, some of the permset manipulation functions
2531 + * such as acl_clear_perm() and acl_add_perm() appear
2532 + * to be broken on Tru64 so we have to manipulate
2533 + * the permission bits in the permset directly.
2535 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2537 + SMB_ACL_ENTRY_T entry;
2539 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2544 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2549 + return errno ? -1 : 0;
2552 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2554 + return acl_get_tag_type( entry_d, tag_type_p);
2557 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2559 + return acl_get_permset( entry_d, permset_p);
2562 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2564 + return acl_get_qualifier( entry_d);
2567 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2569 + return acl_get_file((char *)path_p, type);
2572 +SMB_ACL_T sys_acl_get_fd(int fd)
2574 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2577 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2579 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2584 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2586 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2591 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2596 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2598 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2601 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2603 + return acl_to_text( the_acl, plen);
2606 +SMB_ACL_T sys_acl_init( int count)
2608 + return acl_init(count);
2611 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2613 + SMB_ACL_ENTRY_T entry;
2615 + if ((entry = acl_create_entry(pacl)) == NULL) {
2623 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2625 + return acl_set_tag_type(entry, tagtype);
2628 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2630 + return acl_set_qualifier(entry, qual);
2633 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2635 + return acl_set_permset(entry, permset);
2638 +int sys_acl_valid( SMB_ACL_T theacl )
2640 + acl_entry_t entry;
2642 + return acl_valid(theacl, &entry);
2645 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2647 + return acl_set_file((char *)name, acltype, theacl);
2650 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2652 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2655 +int sys_acl_delete_def_file(const char *name)
2657 + return acl_delete_def_file((char *)name);
2660 +int sys_acl_free_text(char *text)
2663 + * (void) cast and explicit return 0 are for DEC UNIX
2664 + * which just #defines acl_free_text() to be free()
2666 + (void) acl_free_text(text);
2670 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2672 + return acl_free(the_acl);
2675 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2677 + return acl_free_qualifier(qual, tagtype);
2680 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2683 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2684 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2688 + * Note that while this code implements sufficient functionality
2689 + * to support the sys_acl_* interfaces it does not provide all
2690 + * of the semantics of the POSIX ACL interfaces.
2692 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2693 + * from a call to sys_acl_get_entry() should not be assumed to be
2694 + * valid after calling any of the following functions, which may
2695 + * reorder the entries in the ACL.
2698 + * sys_acl_set_file()
2699 + * sys_acl_set_fd()
2703 + * The only difference between Solaris and UnixWare / OpenUNIX is
2704 + * that the #defines for the ACL operations have different names
2706 +#if defined(HAVE_UNIXWARE_ACLS)
2708 +#define SETACL ACL_SET
2709 +#define GETACL ACL_GET
2710 +#define GETACLCNT ACL_CNT
2715 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2717 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2722 + if (entry_p == NULL) {
2727 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2731 + if (acl_d->next < 0) {
2736 + if (acl_d->next >= acl_d->count) {
2740 + *entry_p = &acl_d->acl[acl_d->next++];
2745 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2747 + *type_p = entry_d->a_type;
2752 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2754 + *permset_p = &entry_d->a_perm;
2759 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2761 + if (entry_d->a_type != SMB_ACL_USER
2762 + && entry_d->a_type != SMB_ACL_GROUP) {
2767 + return &entry_d->a_id;
2771 + * There is no way of knowing what size the ACL returned by
2772 + * GETACL will be unless you first call GETACLCNT which means
2773 + * making an additional system call.
2775 + * In the hope of avoiding the cost of the additional system
2776 + * call in most cases, we initially allocate enough space for
2777 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2778 + * be too small then we use GETACLCNT to find out the actual
2779 + * size, reallocate the ACL buffer, and then call GETACL again.
2782 +#define INITIAL_ACL_SIZE 16
2784 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2787 + int count; /* # of ACL entries allocated */
2788 + int naccess; /* # of access ACL entries */
2789 + int ndefault; /* # of default ACL entries */
2791 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2796 + count = INITIAL_ACL_SIZE;
2797 + if ((acl_d = sys_acl_init(count)) == NULL) {
2802 + * If there isn't enough space for the ACL entries we use
2803 + * GETACLCNT to determine the actual number of ACL entries
2804 + * reallocate and try again. This is in a loop because it
2805 + * is possible that someone else could modify the ACL and
2806 + * increase the number of entries between the call to
2807 + * GETACLCNT and the call to GETACL.
2809 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2810 + && errno == ENOSPC) {
2812 + sys_acl_free_acl(acl_d);
2814 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2818 + if ((acl_d = sys_acl_init(count)) == NULL) {
2824 + sys_acl_free_acl(acl_d);
2829 + * calculate the number of access and default ACL entries
2831 + * Note: we assume that the acl() system call returned a
2832 + * well formed ACL which is sorted so that all of the
2833 + * access ACL entries preceed any default ACL entries
2835 + for (naccess = 0; naccess < count; naccess++) {
2836 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2839 + ndefault = count - naccess;
2842 + * if the caller wants the default ACL we have to copy
2843 + * the entries down to the start of the acl[] buffer
2844 + * and mask out the ACL_DEFAULT flag from the type field
2846 + if (type == SMB_ACL_TYPE_DEFAULT) {
2849 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2850 + acl_d->acl[i] = acl_d->acl[j];
2851 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2854 + acl_d->count = ndefault;
2856 + acl_d->count = naccess;
2862 +SMB_ACL_T sys_acl_get_fd(int fd)
2865 + int count; /* # of ACL entries allocated */
2866 + int naccess; /* # of access ACL entries */
2868 + count = INITIAL_ACL_SIZE;
2869 + if ((acl_d = sys_acl_init(count)) == NULL) {
2873 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2874 + && errno == ENOSPC) {
2876 + sys_acl_free_acl(acl_d);
2878 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2882 + if ((acl_d = sys_acl_init(count)) == NULL) {
2888 + sys_acl_free_acl(acl_d);
2893 + * calculate the number of access ACL entries
2895 + for (naccess = 0; naccess < count; naccess++) {
2896 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2900 + acl_d->count = naccess;
2905 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2912 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2914 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2915 + && perm != SMB_ACL_EXECUTE) {
2920 + if (permset_d == NULL) {
2925 + *permset_d |= perm;
2930 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2932 + return *permset_d & perm;
2935 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2942 + * use an initial estimate of 20 bytes per ACL entry
2943 + * when allocating memory for the text representation
2947 + maxlen = 20 * acl_d->count;
2948 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2953 + for (i = 0; i < acl_d->count; i++) {
2954 + struct acl *ap = &acl_d->acl[i];
2963 + switch (ap->a_type) {
2965 + * for debugging purposes it's probably more
2966 + * useful to dump unknown tag types rather
2967 + * than just returning an error
2970 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2973 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2978 + case SMB_ACL_USER:
2979 + id = uidtoname(ap->a_id);
2980 + case SMB_ACL_USER_OBJ:
2984 + case SMB_ACL_GROUP:
2985 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2986 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2992 + case SMB_ACL_GROUP_OBJ:
2996 + case SMB_ACL_OTHER:
3000 + case SMB_ACL_MASK:
3006 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3007 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3008 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3011 + /* <tag> : <qualifier> : rwx \n \0 */
3012 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3015 + * If this entry would overflow the buffer
3016 + * allocate enough additional memory for this
3017 + * entry and an estimate of another 20 bytes
3018 + * for each entry still to be processed
3020 + if ((len + nbytes) > maxlen) {
3021 + char *oldtext = text;
3023 + maxlen += nbytes + 20 * (acl_d->count - i);
3025 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3026 + SAFE_FREE(oldtext);
3032 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3033 + len += nbytes - 1;
3042 +SMB_ACL_T sys_acl_init(int count)
3052 + * note that since the definition of the structure pointed
3053 + * to by the SMB_ACL_T includes the first element of the
3054 + * acl[] array, this actually allocates an ACL with room
3055 + * for (count+1) entries
3057 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3062 + a->size = count + 1;
3070 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3073 + SMB_ACL_ENTRY_T entry_d;
3075 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3080 + if (acl_d->count >= acl_d->size) {
3085 + entry_d = &acl_d->acl[acl_d->count++];
3086 + entry_d->a_type = 0;
3087 + entry_d->a_id = -1;
3088 + entry_d->a_perm = 0;
3089 + *entry_p = entry_d;
3094 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3096 + switch (tag_type) {
3097 + case SMB_ACL_USER:
3098 + case SMB_ACL_USER_OBJ:
3099 + case SMB_ACL_GROUP:
3100 + case SMB_ACL_GROUP_OBJ:
3101 + case SMB_ACL_OTHER:
3102 + case SMB_ACL_MASK:
3103 + entry_d->a_type = tag_type;
3113 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3115 + if (entry_d->a_type != SMB_ACL_GROUP
3116 + && entry_d->a_type != SMB_ACL_USER) {
3121 + entry_d->a_id = *((id_t *)qual_p);
3126 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3128 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3132 + entry_d->a_perm = *permset_d;
3138 + * sort the ACL and check it for validity
3140 + * if it's a minimal ACL with only 4 entries then we
3141 + * need to recalculate the mask permissions to make
3142 + * sure that they are the same as the GROUP_OBJ
3143 + * permissions as required by the UnixWare acl() system call.
3145 + * (note: since POSIX allows minimal ACLs which only contain
3146 + * 3 entries - ie there is no mask entry - we should, in theory,
3147 + * check for this and add a mask entry if necessary - however
3148 + * we "know" that the caller of this interface always specifies
3149 + * a mask so, in practice "this never happens" (tm) - if it *does*
3150 + * happen aclsort() will fail and return an error and someone will
3151 + * have to fix it ...)
3154 +static int acl_sort(SMB_ACL_T acl_d)
3156 + int fixmask = (acl_d->count <= 4);
3158 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3165 +int sys_acl_valid(SMB_ACL_T acl_d)
3167 + return acl_sort(acl_d);
3170 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3173 + struct acl *acl_p;
3175 + struct acl *acl_buf = NULL;
3178 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3183 + if (acl_sort(acl_d) != 0) {
3187 + acl_p = &acl_d->acl[0];
3188 + acl_count = acl_d->count;
3191 + * if it's a directory there is extra work to do
3192 + * since the acl() system call will replace both
3193 + * the access ACLs and the default ACLs (if any)
3195 + if (stat(name, &s) != 0) {
3198 + if (S_ISDIR(s.st_mode)) {
3199 + SMB_ACL_T acc_acl;
3200 + SMB_ACL_T def_acl;
3201 + SMB_ACL_T tmp_acl;
3204 + if (type == SMB_ACL_TYPE_ACCESS) {
3206 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3210 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3213 + if (tmp_acl == NULL) {
3218 + * allocate a temporary buffer for the complete ACL
3220 + acl_count = acc_acl->count + def_acl->count;
3221 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3223 + if (acl_buf == NULL) {
3224 + sys_acl_free_acl(tmp_acl);
3230 + * copy the access control and default entries into the buffer
3232 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3233 + acc_acl->count * sizeof(acl_buf[0]));
3235 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3236 + def_acl->count * sizeof(acl_buf[0]));
3239 + * set the ACL_DEFAULT flag on the default entries
3241 + for (i = acc_acl->count; i < acl_count; i++) {
3242 + acl_buf[i].a_type |= ACL_DEFAULT;
3245 + sys_acl_free_acl(tmp_acl);
3247 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3252 + ret = acl(name, SETACL, acl_count, acl_p);
3254 + SAFE_FREE(acl_buf);
3259 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3261 + if (acl_sort(acl_d) != 0) {
3265 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3268 +int sys_acl_delete_def_file(const char *path)
3274 + * fetching the access ACL and rewriting it has
3275 + * the effect of deleting the default ACL
3277 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3281 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3283 + sys_acl_free_acl(acl_d);
3288 +int sys_acl_free_text(char *text)
3294 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3300 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3305 +#elif defined(HAVE_HPUX_ACLS)
3309 + * Based on the Solaris/SCO code - with modifications.
3313 + * Note that while this code implements sufficient functionality
3314 + * to support the sys_acl_* interfaces it does not provide all
3315 + * of the semantics of the POSIX ACL interfaces.
3317 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3318 + * from a call to sys_acl_get_entry() should not be assumed to be
3319 + * valid after calling any of the following functions, which may
3320 + * reorder the entries in the ACL.
3323 + * sys_acl_set_file()
3324 + * sys_acl_set_fd()
3327 +/* This checks if the POSIX ACL system call is defined */
3328 +/* which basically corresponds to whether JFS 3.3 or */
3329 +/* higher is installed. If acl() was called when it */
3330 +/* isn't defined, it causes the process to core dump */
3331 +/* so it is important to check this and avoid acl() */
3332 +/* calls if it isn't there. */
3334 +static BOOL hpux_acl_call_presence(void)
3337 + shl_t handle = NULL;
3340 + static BOOL already_checked=0;
3342 + if(already_checked)
3346 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3348 + if(ret_val != 0) {
3349 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3350 + ret_val, errno, strerror(errno)));
3351 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3355 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3357 + already_checked = True;
3361 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3363 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3368 + if (entry_p == NULL) {
3373 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3377 + if (acl_d->next < 0) {
3382 + if (acl_d->next >= acl_d->count) {
3386 + *entry_p = &acl_d->acl[acl_d->next++];
3391 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3393 + *type_p = entry_d->a_type;
3398 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3400 + *permset_p = &entry_d->a_perm;
3405 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3407 + if (entry_d->a_type != SMB_ACL_USER
3408 + && entry_d->a_type != SMB_ACL_GROUP) {
3413 + return &entry_d->a_id;
3417 + * There is no way of knowing what size the ACL returned by
3418 + * ACL_GET will be unless you first call ACL_CNT which means
3419 + * making an additional system call.
3421 + * In the hope of avoiding the cost of the additional system
3422 + * call in most cases, we initially allocate enough space for
3423 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3424 + * be too small then we use ACL_CNT to find out the actual
3425 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3428 +#define INITIAL_ACL_SIZE 16
3430 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3433 + int count; /* # of ACL entries allocated */
3434 + int naccess; /* # of access ACL entries */
3435 + int ndefault; /* # of default ACL entries */
3437 + if(hpux_acl_call_presence() == False) {
3438 + /* Looks like we don't have the acl() system call on HPUX.
3439 + * May be the system doesn't have the latest version of JFS.
3444 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3449 + count = INITIAL_ACL_SIZE;
3450 + if ((acl_d = sys_acl_init(count)) == NULL) {
3455 + * If there isn't enough space for the ACL entries we use
3456 + * ACL_CNT to determine the actual number of ACL entries
3457 + * reallocate and try again. This is in a loop because it
3458 + * is possible that someone else could modify the ACL and
3459 + * increase the number of entries between the call to
3460 + * ACL_CNT and the call to ACL_GET.
3462 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3464 + sys_acl_free_acl(acl_d);
3466 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3470 + if ((acl_d = sys_acl_init(count)) == NULL) {
3476 + sys_acl_free_acl(acl_d);
3481 + * calculate the number of access and default ACL entries
3483 + * Note: we assume that the acl() system call returned a
3484 + * well formed ACL which is sorted so that all of the
3485 + * access ACL entries preceed any default ACL entries
3487 + for (naccess = 0; naccess < count; naccess++) {
3488 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3491 + ndefault = count - naccess;
3494 + * if the caller wants the default ACL we have to copy
3495 + * the entries down to the start of the acl[] buffer
3496 + * and mask out the ACL_DEFAULT flag from the type field
3498 + if (type == SMB_ACL_TYPE_DEFAULT) {
3501 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3502 + acl_d->acl[i] = acl_d->acl[j];
3503 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3506 + acl_d->count = ndefault;
3508 + acl_d->count = naccess;
3514 +SMB_ACL_T sys_acl_get_fd(int fd)
3517 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3520 + files_struct *fsp = file_find_fd(fd);
3522 + if (fsp == NULL) {
3528 + * We know we're in the same conn context. So we
3529 + * can use the relative path.
3532 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3535 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3542 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3544 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3545 + && perm != SMB_ACL_EXECUTE) {
3550 + if (permset_d == NULL) {
3555 + *permset_d |= perm;
3560 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3562 + return *permset_d & perm;
3565 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3572 + * use an initial estimate of 20 bytes per ACL entry
3573 + * when allocating memory for the text representation
3577 + maxlen = 20 * acl_d->count;
3578 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3583 + for (i = 0; i < acl_d->count; i++) {
3584 + struct acl *ap = &acl_d->acl[i];
3593 + switch (ap->a_type) {
3595 + * for debugging purposes it's probably more
3596 + * useful to dump unknown tag types rather
3597 + * than just returning an error
3600 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3603 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3608 + case SMB_ACL_USER:
3609 + id = uidtoname(ap->a_id);
3610 + case SMB_ACL_USER_OBJ:
3614 + case SMB_ACL_GROUP:
3615 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3616 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3622 + case SMB_ACL_GROUP_OBJ:
3626 + case SMB_ACL_OTHER:
3630 + case SMB_ACL_MASK:
3636 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3637 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3638 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3641 + /* <tag> : <qualifier> : rwx \n \0 */
3642 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3645 + * If this entry would overflow the buffer
3646 + * allocate enough additional memory for this
3647 + * entry and an estimate of another 20 bytes
3648 + * for each entry still to be processed
3650 + if ((len + nbytes) > maxlen) {
3651 + char *oldtext = text;
3653 + maxlen += nbytes + 20 * (acl_d->count - i);
3655 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3662 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3663 + len += nbytes - 1;
3672 +SMB_ACL_T sys_acl_init(int count)
3682 + * note that since the definition of the structure pointed
3683 + * to by the SMB_ACL_T includes the first element of the
3684 + * acl[] array, this actually allocates an ACL with room
3685 + * for (count+1) entries
3687 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3692 + a->size = count + 1;
3700 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3703 + SMB_ACL_ENTRY_T entry_d;
3705 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3710 + if (acl_d->count >= acl_d->size) {
3715 + entry_d = &acl_d->acl[acl_d->count++];
3716 + entry_d->a_type = 0;
3717 + entry_d->a_id = -1;
3718 + entry_d->a_perm = 0;
3719 + *entry_p = entry_d;
3724 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3726 + switch (tag_type) {
3727 + case SMB_ACL_USER:
3728 + case SMB_ACL_USER_OBJ:
3729 + case SMB_ACL_GROUP:
3730 + case SMB_ACL_GROUP_OBJ:
3731 + case SMB_ACL_OTHER:
3732 + case SMB_ACL_MASK:
3733 + entry_d->a_type = tag_type;
3743 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3745 + if (entry_d->a_type != SMB_ACL_GROUP
3746 + && entry_d->a_type != SMB_ACL_USER) {
3751 + entry_d->a_id = *((id_t *)qual_p);
3756 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3758 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3762 + entry_d->a_perm = *permset_d;
3767 +/* Structure to capture the count for each type of ACE. */
3769 +struct hpux_acl_types {
3773 + int n_def_user_obj;
3778 + int n_def_group_obj;
3782 + int n_def_other_obj;
3785 + int n_def_class_obj;
3787 + int n_illegal_obj;
3791 + * Counts the different number of objects in a given array of ACL
3795 + * acl_count - Count of ACLs in the array of ACL strucutres.
3796 + * aclp - Array of ACL structures.
3797 + * acl_type_count - Pointer to acl_types structure. Should already be
3801 + * acl_type_count - This structure is filled up with counts of various
3805 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3809 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3811 + for(i=0;i<acl_count;i++) {
3812 + switch(aclp[i].a_type) {
3814 + acl_type_count->n_user++;
3817 + acl_type_count->n_user_obj++;
3819 + case DEF_USER_OBJ:
3820 + acl_type_count->n_def_user_obj++;
3823 + acl_type_count->n_group++;
3826 + acl_type_count->n_group_obj++;
3828 + case DEF_GROUP_OBJ:
3829 + acl_type_count->n_def_group_obj++;
3832 + acl_type_count->n_other_obj++;
3834 + case DEF_OTHER_OBJ:
3835 + acl_type_count->n_def_other_obj++;
3838 + acl_type_count->n_class_obj++;
3840 + case DEF_CLASS_OBJ:
3841 + acl_type_count->n_def_class_obj++;
3844 + acl_type_count->n_def_user++;
3847 + acl_type_count->n_def_group++;
3850 + acl_type_count->n_illegal_obj++;
3856 +/* swap_acl_entries: Swaps two ACL entries.
3858 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3861 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3863 + struct acl temp_acl;
3865 + temp_acl.a_type = aclp0->a_type;
3866 + temp_acl.a_id = aclp0->a_id;
3867 + temp_acl.a_perm = aclp0->a_perm;
3869 + aclp0->a_type = aclp1->a_type;
3870 + aclp0->a_id = aclp1->a_id;
3871 + aclp0->a_perm = aclp1->a_perm;
3873 + aclp1->a_type = temp_acl.a_type;
3874 + aclp1->a_id = temp_acl.a_id;
3875 + aclp1->a_perm = temp_acl.a_perm;
3878 +/* prohibited_duplicate_type
3879 + * Identifies if given ACL type can have duplicate entries or
3882 + * Inputs: acl_type - ACL Type.
3888 + * True - If the ACL type matches any of the prohibited types.
3889 + * False - If the ACL type doesn't match any of the prohibited types.
3892 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3894 + switch(acl_type) {
3905 +/* get_needed_class_perm
3906 + * Returns the permissions of a ACL structure only if the ACL
3907 + * type matches one of the pre-determined types for computing
3908 + * CLASS_OBJ permissions.
3910 + * Inputs: aclp - Pointer to ACL structure.
3913 +static int hpux_get_needed_class_perm(struct acl *aclp)
3915 + switch(aclp->a_type) {
3919 + case DEF_USER_OBJ:
3921 + case DEF_GROUP_OBJ:
3923 + case DEF_CLASS_OBJ:
3924 + case DEF_OTHER_OBJ:
3925 + return aclp->a_perm;
3931 +/* acl_sort for HPUX.
3932 + * Sorts the array of ACL structures as per the description in
3933 + * aclsort man page. Refer to aclsort man page for more details
3937 + * acl_count - Count of ACLs in the array of ACL structures.
3938 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3940 + * aclp - Array of ACL structures.
3944 + * aclp - Sorted array of ACL structures.
3948 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3949 + * debug log in case of failure.
3952 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3954 +#if !defined(HAVE_HPUX_ACLSORT)
3956 + * The aclsort() system call is availabe on the latest HPUX General
3957 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3958 + * function. Because, we don't want to update to a new
3959 + * HPUX GR bundle just for aclsort() call.
3962 + struct hpux_acl_types acl_obj_count;
3963 + int n_class_obj_perm = 0;
3967 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3971 + if(aclp == NULL) {
3972 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3976 + /* Count different types of ACLs in the ACLs array */
3978 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3980 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3981 + * CLASS_OBJ and OTHER_OBJ
3984 + if( (acl_obj_count.n_user_obj != 1) ||
3985 + (acl_obj_count.n_group_obj != 1) ||
3986 + (acl_obj_count.n_class_obj != 1) ||
3987 + (acl_obj_count.n_other_obj != 1)
3989 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3990 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3994 + /* If any of the default objects are present, there should be only
3995 + * one of them each.
3998 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3999 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
4000 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
4001 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
4005 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
4008 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
4009 + * same ACL type, sort by ACL id.
4011 + * I am using the trival kind of sorting method here because, performance isn't
4012 + * really effected by the ACLs feature. More over there aren't going to be more
4013 + * than 17 entries on HPUX.
4016 + for(i=0; i<acl_count;i++) {
4017 + for (j=i+1; j<acl_count; j++) {
4018 + if( aclp[i].a_type > aclp[j].a_type ) {
4019 + /* ACL entries out of order, swap them */
4021 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4023 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
4025 + /* ACL entries of same type, sort by id */
4027 + if(aclp[i].a_id > aclp[j].a_id) {
4028 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4029 + } else if (aclp[i].a_id == aclp[j].a_id) {
4030 + /* We have a duplicate entry. */
4031 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
4032 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
4033 + aclp[i].a_type, aclp[i].a_id));
4042 + /* set the class obj permissions to the computed one. */
4044 + int n_class_obj_index = -1;
4046 + for(i=0;i<acl_count;i++) {
4047 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
4049 + if(aclp[i].a_type == CLASS_OBJ)
4050 + n_class_obj_index = i;
4052 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
4057 + return aclsort(acl_count, calclass, aclp);
4062 + * sort the ACL and check it for validity
4064 + * if it's a minimal ACL with only 4 entries then we
4065 + * need to recalculate the mask permissions to make
4066 + * sure that they are the same as the GROUP_OBJ
4067 + * permissions as required by the UnixWare acl() system call.
4069 + * (note: since POSIX allows minimal ACLs which only contain
4070 + * 3 entries - ie there is no mask entry - we should, in theory,
4071 + * check for this and add a mask entry if necessary - however
4072 + * we "know" that the caller of this interface always specifies
4073 + * a mask so, in practice "this never happens" (tm) - if it *does*
4074 + * happen aclsort() will fail and return an error and someone will
4075 + * have to fix it ...)
4078 +static int acl_sort(SMB_ACL_T acl_d)
4080 + int fixmask = (acl_d->count <= 4);
4082 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4089 +int sys_acl_valid(SMB_ACL_T acl_d)
4091 + return acl_sort(acl_d);
4094 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4097 + struct acl *acl_p;
4099 + struct acl *acl_buf = NULL;
4102 + if(hpux_acl_call_presence() == False) {
4103 + /* Looks like we don't have the acl() system call on HPUX.
4104 + * May be the system doesn't have the latest version of JFS.
4110 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4115 + if (acl_sort(acl_d) != 0) {
4119 + acl_p = &acl_d->acl[0];
4120 + acl_count = acl_d->count;
4123 + * if it's a directory there is extra work to do
4124 + * since the acl() system call will replace both
4125 + * the access ACLs and the default ACLs (if any)
4127 + if (stat(name, &s) != 0) {
4130 + if (S_ISDIR(s.st_mode)) {
4131 + SMB_ACL_T acc_acl;
4132 + SMB_ACL_T def_acl;
4133 + SMB_ACL_T tmp_acl;
4136 + if (type == SMB_ACL_TYPE_ACCESS) {
4138 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4142 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4145 + if (tmp_acl == NULL) {
4150 + * allocate a temporary buffer for the complete ACL
4152 + acl_count = acc_acl->count + def_acl->count;
4153 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4155 + if (acl_buf == NULL) {
4156 + sys_acl_free_acl(tmp_acl);
4162 + * copy the access control and default entries into the buffer
4164 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4165 + acc_acl->count * sizeof(acl_buf[0]));
4167 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4168 + def_acl->count * sizeof(acl_buf[0]));
4171 + * set the ACL_DEFAULT flag on the default entries
4173 + for (i = acc_acl->count; i < acl_count; i++) {
4174 + acl_buf[i].a_type |= ACL_DEFAULT;
4177 + sys_acl_free_acl(tmp_acl);
4179 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4184 + ret = acl(name, ACL_SET, acl_count, acl_p);
4193 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4196 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4199 + files_struct *fsp = file_find_fd(fd);
4201 + if (fsp == NULL) {
4206 + if (acl_sort(acl_d) != 0) {
4211 + * We know we're in the same conn context. So we
4212 + * can use the relative path.
4215 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4218 +int sys_acl_delete_def_file(const char *path)
4224 + * fetching the access ACL and rewriting it has
4225 + * the effect of deleting the default ACL
4227 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4231 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4233 + sys_acl_free_acl(acl_d);
4238 +int sys_acl_free_text(char *text)
4244 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4250 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4255 +#elif defined(HAVE_IRIX_ACLS)
4257 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4259 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4264 + if (entry_p == NULL) {
4269 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4273 + if (acl_d->next < 0) {
4278 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4282 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4287 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4289 + *type_p = entry_d->ae_tag;
4294 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4296 + *permset_p = entry_d;
4301 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4303 + if (entry_d->ae_tag != SMB_ACL_USER
4304 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4309 + return &entry_d->ae_id;
4312 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4316 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4320 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4325 + a->freeaclp = True;
4329 +SMB_ACL_T sys_acl_get_fd(int fd)
4333 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4337 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4342 + a->freeaclp = True;
4346 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4348 + permset_d->ae_perm = 0;
4353 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4355 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4356 + && perm != SMB_ACL_EXECUTE) {
4361 + if (permset_d == NULL) {
4366 + permset_d->ae_perm |= perm;
4371 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4373 + return permset_d->ae_perm & perm;
4376 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4378 + return acl_to_text(acl_d->aclp, len_p);
4381 +SMB_ACL_T sys_acl_init(int count)
4390 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4396 + a->freeaclp = False;
4397 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4398 + a->aclp->acl_cnt = 0;
4404 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4407 + SMB_ACL_ENTRY_T entry_d;
4409 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4414 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4419 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4420 + entry_d->ae_tag = 0;
4421 + entry_d->ae_id = 0;
4422 + entry_d->ae_perm = 0;
4423 + *entry_p = entry_d;
4428 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4430 + switch (tag_type) {
4431 + case SMB_ACL_USER:
4432 + case SMB_ACL_USER_OBJ:
4433 + case SMB_ACL_GROUP:
4434 + case SMB_ACL_GROUP_OBJ:
4435 + case SMB_ACL_OTHER:
4436 + case SMB_ACL_MASK:
4437 + entry_d->ae_tag = tag_type;
4447 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4449 + if (entry_d->ae_tag != SMB_ACL_GROUP
4450 + && entry_d->ae_tag != SMB_ACL_USER) {
4455 + entry_d->ae_id = *((id_t *)qual_p);
4460 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4462 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4466 + entry_d->ae_perm = permset_d->ae_perm;
4471 +int sys_acl_valid(SMB_ACL_T acl_d)
4473 + return acl_valid(acl_d->aclp);
4476 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4478 + return acl_set_file(name, type, acl_d->aclp);
4481 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4483 + return acl_set_fd(fd, acl_d->aclp);
4486 +int sys_acl_delete_def_file(const char *name)
4488 + return acl_delete_def_file(name);
4491 +int sys_acl_free_text(char *text)
4493 + return acl_free(text);
4496 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4498 + if (acl_d->freeaclp) {
4499 + acl_free(acl_d->aclp);
4505 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4510 +#elif defined(HAVE_AIX_ACLS)
4512 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4514 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4516 + struct acl_entry_link *link;
4517 + struct new_acl_entry *entry;
4520 + DEBUG(10,("This is the count: %d\n",theacl->count));
4522 + /* Check if count was previously set to -1. *
4523 + * If it was, that means we reached the end *
4524 + * of the acl last time. */
4525 + if(theacl->count == -1)
4529 + /* To get to the next acl, traverse linked list until index *
4530 + * of acl matches the count we are keeping. This count is *
4531 + * incremented each time we return an acl entry. */
4533 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4534 + link = link->nextp;
4536 + entry = *entry_p = link->entryp;
4538 + DEBUG(10,("*entry_p is %d\n",entry_p));
4539 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4541 + /* Increment count */
4543 + if(link->nextp == NULL)
4544 + theacl->count = -1;
4549 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4551 + /* Initialize tag type */
4554 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4556 + /* Depending on what type of entry we have, *
4557 + * return tag type. */
4558 + switch(entry_d->ace_id->id_type) {
4560 + *tag_type_p = SMB_ACL_USER;
4563 + *tag_type_p = SMB_ACL_GROUP;
4566 + case SMB_ACL_USER_OBJ:
4567 + case SMB_ACL_GROUP_OBJ:
4568 + case SMB_ACL_OTHER:
4569 + *tag_type_p = entry_d->ace_id->id_type;
4579 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4581 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4582 + *permset_p = &entry_d->ace_access;
4583 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4584 + if(!(**permset_p & S_IXUSR) &&
4585 + !(**permset_p & S_IWUSR) &&
4586 + !(**permset_p & S_IRUSR) &&
4587 + (**permset_p != 0))
4590 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4594 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4596 + return(entry_d->ace_id->id_data);
4599 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4601 + struct acl *file_acl = (struct acl *)NULL;
4602 + struct acl_entry *acl_entry;
4603 + struct new_acl_entry *new_acl_entry;
4604 + struct ace_id *idp;
4605 + struct acl_entry_link *acl_entry_link;
4606 + struct acl_entry_link *acl_entry_link_head;
4611 + /* AIX has no DEFAULT */
4612 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4617 + /* Get the acl using statacl */
4619 + DEBUG(10,("Entering sys_acl_get_file\n"));
4620 + DEBUG(10,("path_p is %s\n",path_p));
4622 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4624 + if(file_acl == NULL) {
4626 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4630 + memset(file_acl,0,BUFSIZ);
4632 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4634 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4635 + SAFE_FREE(file_acl);
4639 + DEBUG(10,("Got facl and returned it\n"));
4641 + /* Point to the first acl entry in the acl */
4642 + acl_entry = file_acl->acl_ext;
4644 + /* Begin setting up the head of the linked list *
4645 + * that will be used for the storing the acl *
4646 + * in a way that is useful for the posix_acls.c *
4649 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4650 + if(acl_entry_link_head == NULL)
4653 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4654 + if(acl_entry_link->entryp == NULL) {
4655 + SAFE_FREE(file_acl);
4657 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4661 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4662 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4664 + /* Check if the extended acl bit is on. *
4665 + * If it isn't, do not show the *
4666 + * contents of the acl since AIX intends *
4667 + * the extended info to remain unused */
4669 + if(file_acl->acl_mode & S_IXACL){
4670 + /* while we are not pointing to the very end */
4671 + while(acl_entry < acl_last(file_acl)) {
4672 + /* before we malloc anything, make sure this is */
4673 + /* a valid acl entry and one that we want to map */
4674 + idp = id_nxt(acl_entry->ace_id);
4675 + if((acl_entry->ace_type == ACC_SPECIFY ||
4676 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4677 + acl_entry = acl_nxt(acl_entry);
4681 + idp = acl_entry->ace_id;
4683 + /* Check if this is the first entry in the linked list. *
4684 + * The first entry needs to keep prevp pointing to NULL *
4685 + * and already has entryp allocated. */
4687 + if(acl_entry_link_head->count != 0) {
4688 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4690 + if(acl_entry_link->nextp == NULL) {
4691 + SAFE_FREE(file_acl);
4693 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4697 + acl_entry_link->nextp->prevp = acl_entry_link;
4698 + acl_entry_link = acl_entry_link->nextp;
4699 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4700 + if(acl_entry_link->entryp == NULL) {
4701 + SAFE_FREE(file_acl);
4703 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4706 + acl_entry_link->nextp = NULL;
4709 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4711 + /* Don't really need this since all types are going *
4712 + * to be specified but, it's better than leaving it 0 */
4714 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4716 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4718 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4720 + /* The access in the acl entries must be left shifted by *
4721 + * three bites, because they will ultimately be compared *
4722 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4724 + switch(acl_entry->ace_type){
4727 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4728 + acl_entry_link->entryp->ace_access <<= 6;
4729 + acl_entry_link_head->count++;
4732 + /* Since there is no way to return a DENY acl entry *
4733 + * change to PERMIT and then shift. */
4734 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4735 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4736 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4737 + acl_entry_link->entryp->ace_access <<= 6;
4738 + acl_entry_link_head->count++;
4744 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4745 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4747 + acl_entry = acl_nxt(acl_entry);
4749 + } /* end of if enabled */
4751 + /* Since owner, group, other acl entries are not *
4752 + * part of the acl entries in an acl, they must *
4753 + * be dummied up to become part of the list. */
4755 + for( i = 1; i < 4; i++) {
4756 + DEBUG(10,("i is %d\n",i));
4757 + if(acl_entry_link_head->count != 0) {
4758 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4759 + if(acl_entry_link->nextp == NULL) {
4760 + SAFE_FREE(file_acl);
4762 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4766 + acl_entry_link->nextp->prevp = acl_entry_link;
4767 + acl_entry_link = acl_entry_link->nextp;
4768 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4769 + if(acl_entry_link->entryp == NULL) {
4770 + SAFE_FREE(file_acl);
4772 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4777 + acl_entry_link->nextp = NULL;
4779 + new_acl_entry = acl_entry_link->entryp;
4780 + idp = new_acl_entry->ace_id;
4782 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4783 + new_acl_entry->ace_type = ACC_PERMIT;
4784 + idp->id_len = sizeof(struct ace_id);
4785 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4786 + memset(idp->id_data,0,sizeof(uid_t));
4790 + new_acl_entry->ace_access = file_acl->g_access << 6;
4791 + idp->id_type = SMB_ACL_GROUP_OBJ;
4795 + new_acl_entry->ace_access = file_acl->o_access << 6;
4796 + idp->id_type = SMB_ACL_OTHER;
4800 + new_acl_entry->ace_access = file_acl->u_access << 6;
4801 + idp->id_type = SMB_ACL_USER_OBJ;
4809 + acl_entry_link_head->count++;
4810 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4813 + acl_entry_link_head->count = 0;
4814 + SAFE_FREE(file_acl);
4816 + return(acl_entry_link_head);
4819 +SMB_ACL_T sys_acl_get_fd(int fd)
4821 + struct acl *file_acl = (struct acl *)NULL;
4822 + struct acl_entry *acl_entry;
4823 + struct new_acl_entry *new_acl_entry;
4824 + struct ace_id *idp;
4825 + struct acl_entry_link *acl_entry_link;
4826 + struct acl_entry_link *acl_entry_link_head;
4831 + /* Get the acl using fstatacl */
4833 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4834 + DEBUG(10,("fd is %d\n",fd));
4835 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4837 + if(file_acl == NULL) {
4839 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4843 + memset(file_acl,0,BUFSIZ);
4845 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4847 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4848 + SAFE_FREE(file_acl);
4852 + DEBUG(10,("Got facl and returned it\n"));
4854 + /* Point to the first acl entry in the acl */
4856 + acl_entry = file_acl->acl_ext;
4857 + /* Begin setting up the head of the linked list *
4858 + * that will be used for the storing the acl *
4859 + * in a way that is useful for the posix_acls.c *
4862 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4863 + if(acl_entry_link_head == NULL){
4864 + SAFE_FREE(file_acl);
4868 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4870 + if(acl_entry_link->entryp == NULL) {
4872 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4873 + SAFE_FREE(file_acl);
4877 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4878 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4880 + /* Check if the extended acl bit is on. *
4881 + * If it isn't, do not show the *
4882 + * contents of the acl since AIX intends *
4883 + * the extended info to remain unused */
4885 + if(file_acl->acl_mode & S_IXACL){
4886 + /* while we are not pointing to the very end */
4887 + while(acl_entry < acl_last(file_acl)) {
4888 + /* before we malloc anything, make sure this is */
4889 + /* a valid acl entry and one that we want to map */
4891 + idp = id_nxt(acl_entry->ace_id);
4892 + if((acl_entry->ace_type == ACC_SPECIFY ||
4893 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4894 + acl_entry = acl_nxt(acl_entry);
4898 + idp = acl_entry->ace_id;
4900 + /* Check if this is the first entry in the linked list. *
4901 + * The first entry needs to keep prevp pointing to NULL *
4902 + * and already has entryp allocated. */
4904 + if(acl_entry_link_head->count != 0) {
4905 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4906 + if(acl_entry_link->nextp == NULL) {
4908 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4909 + SAFE_FREE(file_acl);
4912 + acl_entry_link->nextp->prevp = acl_entry_link;
4913 + acl_entry_link = acl_entry_link->nextp;
4914 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4915 + if(acl_entry_link->entryp == NULL) {
4917 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4918 + SAFE_FREE(file_acl);
4922 + acl_entry_link->nextp = NULL;
4925 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4927 + /* Don't really need this since all types are going *
4928 + * to be specified but, it's better than leaving it 0 */
4930 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4931 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4933 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4935 + /* The access in the acl entries must be left shifted by *
4936 + * three bites, because they will ultimately be compared *
4937 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4939 + switch(acl_entry->ace_type){
4942 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4943 + acl_entry_link->entryp->ace_access <<= 6;
4944 + acl_entry_link_head->count++;
4947 + /* Since there is no way to return a DENY acl entry *
4948 + * change to PERMIT and then shift. */
4949 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4950 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4951 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4952 + acl_entry_link->entryp->ace_access <<= 6;
4953 + acl_entry_link_head->count++;
4959 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4960 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4962 + acl_entry = acl_nxt(acl_entry);
4964 + } /* end of if enabled */
4966 + /* Since owner, group, other acl entries are not *
4967 + * part of the acl entries in an acl, they must *
4968 + * be dummied up to become part of the list. */
4970 + for( i = 1; i < 4; i++) {
4971 + DEBUG(10,("i is %d\n",i));
4972 + if(acl_entry_link_head->count != 0){
4973 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4974 + if(acl_entry_link->nextp == NULL) {
4976 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4977 + SAFE_FREE(file_acl);
4981 + acl_entry_link->nextp->prevp = acl_entry_link;
4982 + acl_entry_link = acl_entry_link->nextp;
4983 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4985 + if(acl_entry_link->entryp == NULL) {
4986 + SAFE_FREE(file_acl);
4988 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4993 + acl_entry_link->nextp = NULL;
4995 + new_acl_entry = acl_entry_link->entryp;
4996 + idp = new_acl_entry->ace_id;
4998 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4999 + new_acl_entry->ace_type = ACC_PERMIT;
5000 + idp->id_len = sizeof(struct ace_id);
5001 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
5002 + memset(idp->id_data,0,sizeof(uid_t));
5006 + new_acl_entry->ace_access = file_acl->g_access << 6;
5007 + idp->id_type = SMB_ACL_GROUP_OBJ;
5011 + new_acl_entry->ace_access = file_acl->o_access << 6;
5012 + idp->id_type = SMB_ACL_OTHER;
5016 + new_acl_entry->ace_access = file_acl->u_access << 6;
5017 + idp->id_type = SMB_ACL_USER_OBJ;
5024 + acl_entry_link_head->count++;
5025 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
5028 + acl_entry_link_head->count = 0;
5029 + SAFE_FREE(file_acl);
5031 + return(acl_entry_link_head);
5034 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
5036 + *permset = *permset & ~0777;
5040 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5043 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
5047 + DEBUG(10,("This is the permset now: %d\n",*permset));
5051 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
5056 +SMB_ACL_T sys_acl_init( int count)
5058 + struct acl_entry_link *theacl = NULL;
5060 + DEBUG(10,("Entering sys_acl_init\n"));
5062 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5063 + if(theacl == NULL) {
5065 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5069 + theacl->count = 0;
5070 + theacl->nextp = NULL;
5071 + theacl->prevp = NULL;
5072 + theacl->entryp = NULL;
5073 + DEBUG(10,("Exiting sys_acl_init\n"));
5077 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5079 + struct acl_entry_link *theacl;
5080 + struct acl_entry_link *acl_entryp;
5081 + struct acl_entry_link *temp_entry;
5084 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5086 + theacl = acl_entryp = *pacl;
5088 + /* Get to the end of the acl before adding entry */
5090 + for(counting=0; counting < theacl->count; counting++){
5091 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5092 + temp_entry = acl_entryp;
5093 + acl_entryp = acl_entryp->nextp;
5096 + if(theacl->count != 0){
5097 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5098 + if(acl_entryp == NULL) {
5100 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5104 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5105 + acl_entryp->prevp = temp_entry;
5106 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5109 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5110 + if(*pentry == NULL) {
5112 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5116 + memset(*pentry,0,sizeof(struct new_acl_entry));
5117 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5118 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5119 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5120 + acl_entryp->nextp = NULL;
5122 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5126 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5128 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5129 + entry->ace_id->id_type = tagtype;
5130 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5131 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5134 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5136 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5137 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5138 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5142 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5144 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5145 + if(!(*permset & S_IXUSR) &&
5146 + !(*permset & S_IWUSR) &&
5147 + !(*permset & S_IRUSR) &&
5151 + entry->ace_access = *permset;
5152 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5153 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5157 +int sys_acl_valid( SMB_ACL_T theacl )
5160 + int group_obj = 0;
5161 + int other_obj = 0;
5162 + struct acl_entry_link *acl_entry;
5164 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5165 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5166 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5167 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5170 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5172 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5178 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5180 + struct acl_entry_link *acl_entry_link = NULL;
5181 + struct acl *file_acl = NULL;
5182 + struct acl *file_acl_temp = NULL;
5183 + struct acl_entry *acl_entry = NULL;
5184 + struct ace_id *ace_id = NULL;
5191 + DEBUG(10,("Entering sys_acl_set_file\n"));
5192 + DEBUG(10,("File name is %s\n",name));
5194 + /* AIX has no default ACL */
5195 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5198 + acl_length = BUFSIZ;
5199 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5201 + if(file_acl == NULL) {
5203 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5207 + memset(file_acl,0,BUFSIZ);
5209 + file_acl->acl_len = ACL_SIZ;
5210 + file_acl->acl_mode = S_IXACL;
5212 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5213 + acl_entry_link->entryp->ace_access >>= 6;
5214 + id_type = acl_entry_link->entryp->ace_id->id_type;
5217 + case SMB_ACL_USER_OBJ:
5218 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5220 + case SMB_ACL_GROUP_OBJ:
5221 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5223 + case SMB_ACL_OTHER:
5224 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5226 + case SMB_ACL_MASK:
5230 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5231 + acl_length += sizeof(struct acl_entry);
5232 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5233 + if(file_acl_temp == NULL) {
5234 + SAFE_FREE(file_acl);
5236 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5240 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5241 + SAFE_FREE(file_acl);
5242 + file_acl = file_acl_temp;
5245 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5246 + file_acl->acl_len += sizeof(struct acl_entry);
5247 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5248 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5250 + /* In order to use this, we'll need to wait until we can get denies */
5251 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5252 + acl_entry->ace_type = ACC_SPECIFY; */
5254 + acl_entry->ace_type = ACC_SPECIFY;
5256 + ace_id = acl_entry->ace_id;
5258 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5259 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5260 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5261 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5262 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5265 + rc = chacl(name,file_acl,file_acl->acl_len);
5266 + DEBUG(10,("errno is %d\n",errno));
5267 + DEBUG(10,("return code is %d\n",rc));
5268 + SAFE_FREE(file_acl);
5269 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5273 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5275 + struct acl_entry_link *acl_entry_link = NULL;
5276 + struct acl *file_acl = NULL;
5277 + struct acl *file_acl_temp = NULL;
5278 + struct acl_entry *acl_entry = NULL;
5279 + struct ace_id *ace_id = NULL;
5285 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5286 + acl_length = BUFSIZ;
5287 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5289 + if(file_acl == NULL) {
5291 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5295 + memset(file_acl,0,BUFSIZ);
5297 + file_acl->acl_len = ACL_SIZ;
5298 + file_acl->acl_mode = S_IXACL;
5300 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5301 + acl_entry_link->entryp->ace_access >>= 6;
5302 + id_type = acl_entry_link->entryp->ace_id->id_type;
5303 + DEBUG(10,("The id_type is %d\n",id_type));
5306 + case SMB_ACL_USER_OBJ:
5307 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5309 + case SMB_ACL_GROUP_OBJ:
5310 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5312 + case SMB_ACL_OTHER:
5313 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5315 + case SMB_ACL_MASK:
5319 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5320 + acl_length += sizeof(struct acl_entry);
5321 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5322 + if(file_acl_temp == NULL) {
5323 + SAFE_FREE(file_acl);
5325 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5329 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5330 + SAFE_FREE(file_acl);
5331 + file_acl = file_acl_temp;
5334 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5335 + file_acl->acl_len += sizeof(struct acl_entry);
5336 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5337 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5339 + /* In order to use this, we'll need to wait until we can get denies */
5340 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5341 + acl_entry->ace_type = ACC_SPECIFY; */
5343 + acl_entry->ace_type = ACC_SPECIFY;
5345 + ace_id = acl_entry->ace_id;
5347 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5348 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5349 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5350 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5351 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5354 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5355 + DEBUG(10,("errno is %d\n",errno));
5356 + DEBUG(10,("return code is %d\n",rc));
5357 + SAFE_FREE(file_acl);
5358 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5362 +int sys_acl_delete_def_file(const char *name)
5364 + /* AIX has no default ACL */
5368 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5370 + return(*permset & perm);
5373 +int sys_acl_free_text(char *text)
5378 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5380 + struct acl_entry_link *acl_entry_link;
5382 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5383 + SAFE_FREE(acl_entry_link->prevp->entryp);
5384 + SAFE_FREE(acl_entry_link->prevp);
5387 + SAFE_FREE(acl_entry_link->prevp->entryp);
5388 + SAFE_FREE(acl_entry_link->prevp);
5389 + SAFE_FREE(acl_entry_link->entryp);
5390 + SAFE_FREE(acl_entry_link);
5395 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5400 +#else /* No ACLs. */
5402 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5408 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5414 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5420 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5426 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5429 + return (SMB_ACL_T)NULL;
5432 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5435 + return (SMB_ACL_T)NULL;
5438 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5444 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5450 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5453 + return (permset & perm) ? 1 : 0;
5456 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5462 +int sys_acl_free_text(UNUSED(char *text))
5468 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5474 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5480 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5486 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5492 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5498 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5504 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5510 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5516 +int sys_acl_delete_def_file(UNUSED(const char *name))
5522 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5528 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5534 +#endif /* No ACLs. */
5536 +/************************************************************************
5537 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5539 +************************************************************************/
5541 +int no_acl_syscall_error(int err)
5543 +#if defined(ENOSYS)
5544 + if (err == ENOSYS) {
5548 +#if defined(ENOTSUP)
5549 + if (err == ENOTSUP) {
5556 +#endif /* SUPPORT_ACLS */
5557 --- old/lib/sysacls.h
5558 +++ new/lib/sysacls.h
5560 +#ifdef SUPPORT_ACLS
5562 +#ifdef HAVE_SYS_ACL_H
5563 +#include <sys/acl.h>
5565 +#ifdef HAVE_ACL_LIBACL_H
5566 +#include <acl/libacl.h>
5568 +#include "smb_acls.h"
5570 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5571 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5572 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5573 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5574 +#define slprintf snprintf
5576 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5577 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5578 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5579 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5580 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5581 +SMB_ACL_T sys_acl_get_fd(int fd);
5582 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5583 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5584 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5585 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5586 +SMB_ACL_T sys_acl_init(int count);
5587 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5588 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5589 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5590 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5591 +int sys_acl_valid(SMB_ACL_T theacl);
5592 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5593 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5594 +int sys_acl_delete_def_file(const char *name);
5595 +int sys_acl_free_text(char *text);
5596 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5597 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5599 +#endif /* SUPPORT_ACLS */
5602 @@ -625,8 +625,10 @@ static void log_formatted(enum logcode c
5603 c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5604 c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5605 c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5608 + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5609 + c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5610 + c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5613 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5614 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5617 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5619 int preserve_links = 0;
5620 int preserve_hard_links = 0;
5621 +int preserve_acls = 0;
5622 int preserve_perms = 0;
5623 int preserve_executability = 0;
5624 int preserve_devices = 0;
5625 @@ -199,6 +200,7 @@ static void print_rsync_version(enum log
5626 char const *got_socketpair = "no ";
5627 char const *have_inplace = "no ";
5628 char const *hardlinks = "no ";
5629 + char const *acls = "no ";
5630 char const *links = "no ";
5631 char const *ipv6 = "no ";
5632 STRUCT_STAT *dumstat;
5633 @@ -215,6 +217,10 @@ static void print_rsync_version(enum log
5637 +#ifdef SUPPORT_ACLS
5641 #ifdef SUPPORT_LINKS
5644 @@ -233,8 +239,8 @@ static void print_rsync_version(enum log
5645 (int)(sizeof (int64) * 8));
5646 rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
5647 got_socketpair, hardlinks, links, ipv6, have_inplace);
5648 - rprintf(f, " %sappend\n",
5650 + rprintf(f, " %sappend, %sACLs\n",
5651 + have_inplace, acls);
5653 #ifdef MAINTAINER_MODE
5654 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
5655 @@ -280,7 +286,7 @@ void usage(enum logcode F)
5656 rprintf(F," -q, --quiet suppress non-error messages\n");
5657 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5658 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5659 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5660 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5661 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5662 rprintf(F," -r, --recursive recurse into directories\n");
5663 rprintf(F," -R, --relative use relative path names\n");
5664 @@ -302,6 +308,9 @@ void usage(enum logcode F)
5665 rprintf(F," -p, --perms preserve permissions\n");
5666 rprintf(F," -E, --executability preserve the file's executability\n");
5667 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5668 +#ifdef SUPPORT_ACLS
5669 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5671 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5672 rprintf(F," -g, --group preserve group\n");
5673 rprintf(F," --devices preserve device files (super-user only)\n");
5674 @@ -422,6 +431,9 @@ static struct poptOption long_options[]
5675 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5676 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5677 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5678 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5679 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5680 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5681 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5682 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5683 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5684 @@ -1087,6 +1099,24 @@ int parse_arguments(int *argc, const cha
5689 +#ifdef SUPPORT_ACLS
5690 + preserve_acls = 1;
5691 + preserve_perms = 1;
5694 + /* FIXME: this should probably be ignored with a
5695 + * warning and then countermeasures taken to
5696 + * restrict group and other access in the presence
5697 + * of any more restrictive ACLs, but this is safe
5699 + snprintf(err_buf,sizeof(err_buf),
5700 + "ACLs are not supported on this %s\n",
5701 + am_server ? "server" : "client");
5707 /* A large opt value means that set_refuse_options()
5708 * turned this option off. */
5709 @@ -1223,6 +1253,8 @@ int parse_arguments(int *argc, const cha
5710 preserve_uid = ++flist_extra_cnt;
5712 preserve_gid = ++flist_extra_cnt;
5713 + if (preserve_acls)
5714 + preserve_acls = ++flist_extra_cnt;
5716 *argv = poptGetArgs(pc);
5717 *argc = count_args(*argv);
5718 @@ -1534,6 +1566,10 @@ void server_options(char **args,int *arg
5720 if (preserve_hard_links)
5722 +#ifdef SUPPORT_ACLS
5723 + if (preserve_acls)
5724 + argstr[x++] = 'A';
5731 @@ -47,6 +47,7 @@ extern int keep_partial;
5732 extern int checksum_seed;
5734 extern int delay_updates;
5735 +extern mode_t orig_umask;
5736 extern struct stats stats;
5737 extern char *stdout_format;
5738 extern char *tmpdir;
5739 @@ -347,6 +348,10 @@ int recv_files(int f_in, struct file_lis
5740 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5741 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5742 int max_phase = protocol_version >= 29 ? 2 : 1;
5743 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5744 +#ifdef SUPPORT_ACLS
5745 + const char *parent_dirname = "";
5750 @@ -545,7 +550,16 @@ int recv_files(int f_in, struct file_lis
5751 * mode based on the local permissions and some heuristics. */
5752 if (!preserve_perms) {
5753 int exists = fd1 != -1;
5754 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5755 +#ifdef SUPPORT_ACLS
5756 + const char *dn = file->dirname ? file->dirname : ".";
5757 + if (parent_dirname != dn
5758 + && strcmp(parent_dirname, dn) != 0) {
5759 + dflt_perms = default_perms_for_dir(dn);
5760 + parent_dirname = dn;
5763 + file->mode = dest_mode(file->mode, st.st_mode,
5764 + dflt_perms, exists);
5767 /* We now check to see if we are writing the file "inplace" */
5774 +extern int preserve_acls;
5775 extern int preserve_perms;
5776 extern int preserve_executability;
5777 extern int preserve_times;
5778 @@ -48,7 +49,6 @@ extern int preserve_gid;
5780 extern int keep_dirlinks;
5781 extern int make_backups;
5782 -extern mode_t orig_umask;
5783 extern struct stats stats;
5784 extern struct file_list *the_file_list;
5785 extern struct chmod_mode_struct *daemon_chmod_modes;
5786 @@ -153,7 +153,8 @@ void free_sums(struct sum_struct *s)
5788 /* This is only called when we aren't preserving permissions. Figure out what
5789 * the permissions should be and return them merged back into the mode. */
5790 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5791 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5795 /* If the file already exists, we'll return the local permissions,
5796 @@ -170,56 +171,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5797 new_mode |= (new_mode & 0444) >> 2;
5800 - /* Apply the umask and turn off special permissions. */
5801 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5802 + /* Apply destination default permissions and turn
5803 + * off special permissions. */
5804 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5809 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5810 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5816 int change_uid, change_gid;
5817 mode_t new_mode = file->mode;
5823 - if (link_stat(fname, &st2, 0) < 0) {
5824 + if (link_stat(fname, &sx2.st, 0) < 0) {
5825 rsyserr(FERROR, errno, "stat %s failed",
5830 +#ifdef SUPPORT_ACLS
5831 + sx2.acc_acl = sx2.def_acl = NULL;
5833 if (!preserve_perms && S_ISDIR(new_mode)
5834 - && st->st_mode & S_ISGID) {
5835 + && sx2.st.st_mode & S_ISGID) {
5836 /* We just created this directory and its setgid
5837 * bit is on, so make sure it stays on. */
5838 new_mode |= S_ISGID;
5843 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5844 +#ifdef SUPPORT_ACLS
5845 + if (preserve_acls && !ACL_READY(*sxp))
5846 + get_acl(fname, sxp);
5849 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5850 flags |= ATTRS_SKIP_MTIME;
5851 if (!(flags & ATTRS_SKIP_MTIME)
5852 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5853 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5854 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5855 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5857 rsyserr(FERROR, errno, "failed to set times on %s",
5862 if (ret == 0) /* ret == 1 if symlink could not be set */
5866 - change_uid = am_root && preserve_uid && st->st_uid != F_UID(file);
5867 + change_uid = am_root && preserve_uid && sxp->st.st_uid != F_UID(file);
5868 change_gid = preserve_gid && F_GID(file) != GID_NONE
5869 - && st->st_gid != F_GID(file);
5870 + && sxp->st.st_gid != F_GID(file);
5871 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5872 - if (S_ISLNK(st->st_mode))
5873 + if (S_ISLNK(sxp->st.st_mode))
5877 @@ -229,45 +239,57 @@ int set_file_attrs(char *fname, struct f
5879 "set uid of %s from %ld to %ld\n",
5881 - (long)st->st_uid, (long)F_UID(file));
5882 + (long)sxp->st.st_uid, (long)F_UID(file));
5886 "set gid of %s from %ld to %ld\n",
5888 - (long)st->st_gid, (long)F_GID(file));
5889 + (long)sxp->st.st_gid, (long)F_GID(file));
5892 if (do_lchown(fname,
5893 - change_uid ? F_UID(file) : st->st_uid,
5894 - change_gid ? F_GID(file) : st->st_gid) != 0) {
5895 + change_uid ? F_UID(file) : sxp->st.st_uid,
5896 + change_gid ? F_GID(file) : sxp->st.st_gid) != 0) {
5897 /* shouldn't have attempted to change uid or gid
5898 * unless have the privilege */
5899 rsyserr(FERROR, errno, "%s %s failed",
5900 change_uid ? "chown" : "chgrp",
5905 /* a lchown had been done - we have to re-stat if the
5906 * destination had the setuid or setgid bits set due
5907 * to the side effect of the chown call */
5908 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5909 - link_stat(fname, st,
5910 - keep_dirlinks && S_ISDIR(st->st_mode));
5911 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5912 + link_stat(fname, &sxp->st,
5913 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5918 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5919 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5921 +#ifdef SUPPORT_ACLS
5922 + /* It's OK to call set_acl() now, even for a dir, as the generator
5923 + * will enable owner-writability using chmod, if necessary.
5925 + * If set_acl() changes permission bits in the process of setting
5926 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5927 + * need to chmod(). */
5928 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5933 - if (!BITS_EQUAL(st->st_mode, new_mode, CHMOD_BITS)) {
5934 + if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) {
5935 int ret = do_chmod(fname, new_mode);
5937 rsyserr(FERROR, errno,
5938 "failed to set permissions on %s",
5943 if (ret == 0) /* ret == 1 if symlink could not be set */
5945 @@ -280,6 +302,11 @@ int set_file_attrs(char *fname, struct f
5947 rprintf(FCLIENT, "%s is uptodate\n", fname);
5950 +#ifdef SUPPORT_ACLS
5951 + if (preserve_acls && sxp == &sx2)
5959 @@ -508,6 +508,14 @@ struct idev_node {
5960 #define IN_LOOPBACKNET 127
5963 +#ifndef HAVE_NO_ACLS
5964 +#define SUPPORT_ACLS 1
5967 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5968 +#define ACLS_NEED_MASK 1
5971 #define GID_NONE ((gid_t)-1)
5973 struct file_struct {
5974 @@ -559,11 +567,13 @@ extern int preserve_gid;
5975 /* When the associated option is on, all entries will have these present: */
5976 #define F_UID(f) REQ_EXTRA(f, preserve_uid)->uid
5977 #define F_GID(f) REQ_EXTRA(f, preserve_gid)->gid
5978 +#define F_ACL(f) REQ_EXTRA(f, preserve_acls)->unum
5980 /* These items are per-entry optional and mutally exclusive: */
5981 #define F_HL_IDEV(f) OPT_EXTRA(f, LEN64_BUMP(f))->idev
5982 #define F_HL_GNUM(f) OPT_EXTRA(f, LEN64_BUMP(f))->num
5983 #define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f))->num
5984 +#define F_DEF_ACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum
5986 /* This optional item might follow an F_HL_*() item.
5987 * (Note: a device doesn't need to check LEN64_BUMP(f).) */
5988 @@ -699,6 +709,17 @@ struct stats {
5990 struct chmod_mode_struct;
5992 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
6000 +#define EXPAND_ITEM_LIST(lp, type, incr) \
6001 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
6003 #include "byteorder.h"
6004 #include "lib/mdfour.h"
6005 #include "lib/wildmatch.h"
6006 @@ -717,6 +738,16 @@ struct chmod_mode_struct;
6007 #define NORETURN __attribute__((__noreturn__))
6012 +#ifdef SUPPORT_ACLS
6013 + struct rsync_acl *acc_acl; /* access ACL */
6014 + struct rsync_acl *def_acl; /* default ACL */
6018 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
6022 /* We have replacement versions of these if they're missing. */
6025 @@ -301,7 +301,7 @@ to the detailed description below for a
6026 -q, --quiet suppress non-error messages
6027 --no-motd suppress daemon-mode MOTD (see caveat)
6028 -c, --checksum skip based on checksum, not mod-time & size
6029 - -a, --archive archive mode; same as -rlptgoD (no -H)
6030 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
6031 --no-OPTION turn off an implied OPTION (e.g. --no-D)
6032 -r, --recursive recurse into directories
6033 -R, --relative use relative path names
6034 @@ -323,6 +323,7 @@ to the detailed description below for a
6035 -p, --perms preserve permissions
6036 -E, --executability preserve executability
6037 --chmod=CHMOD affect file and/or directory permissions
6038 + -A, --acls preserve ACLs (implies -p) [non-standard]
6039 -o, --owner preserve owner (super-user only)
6040 -g, --group preserve group
6041 --devices preserve device files (super-user only)
6042 @@ -754,7 +755,9 @@ quote(itemization(
6043 permissions, though the bf(--executability) option might change just
6044 the execute permission for the file.
6045 it() New files get their "normal" permission bits set to the source
6046 - file's permissions masked with the receiving end's umask setting, and
6047 + file's permissions masked with the receiving directory's default
6048 + permissions (either the receiving process's umask, or the permissions
6049 + specified via the destination directory's default ACL), and
6050 their special permission bits disabled except in the case where a new
6051 directory inherits a setgid bit from its parent directory.
6053 @@ -785,9 +788,11 @@ The preservation of the destination's se
6054 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
6055 versions erroneously preserved the three special permission bits for
6056 newly-created files when bf(--perms) was off, while overriding the
6057 -destination's setgid bit setting on a newly-created directory. (Keep in
6058 -mind that it is the version of the receiving rsync that affects this
6060 +destination's setgid bit setting on a newly-created directory. Default ACL
6061 +observance was added to the ACL patch for rsync 2.6.7, so older (or
6062 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
6063 +(Keep in mind that it is the version of the receiving rsync that affects
6066 dit(bf(-E, --executability)) This option causes rsync to preserve the
6067 executability (or non-executability) of regular files when bf(--perms) is
6068 @@ -805,6 +810,15 @@ quote(itemization(
6070 If bf(--perms) is enabled, this option is ignored.
6072 +dit(bf(-A, --acls)) This option causes rsync to update the destination
6073 +ACLs to be the same as the source ACLs. This nonstandard option only
6074 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
6076 +Note also that an optimization of the ACL-sending protocol used by this
6077 +version makes it incompatible with sending files to an older ACL-enabled
6078 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
6079 +doubling is not needed when pulling files from an older rsync.
6081 dit(bf(--chmod)) This option tells rsync to apply one or more
6082 comma-separated "chmod" strings to the permission of the files in the
6083 transfer. The resulting value is treated as though it was the permissions
6084 @@ -1402,8 +1416,8 @@ if the receiving rsync is at least versi
6085 with older versions of rsync, but that also turns on the output of other
6088 -The "%i" escape has a cryptic output that is 9 letters long. The general
6089 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
6090 +The "%i" escape has a cryptic output that is 11 letters long. The general
6091 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
6092 type of update being done, bf(X) is replaced by the file-type, and the
6093 other letters represent attributes that may be output if they are being
6095 @@ -1452,7 +1466,11 @@ quote(itemization(
6096 sender's value (requires bf(--owner) and super-user privileges).
6097 it() A bf(g) means the group is different and is being updated to the
6098 sender's value (requires bf(--group) and the authority to set the group).
6099 - it() The bf(z) slot is reserved for future use.
6100 + it() The bf(u) slot is reserved for reporting update (access) time changes
6101 + (a feature that is not yet released).
6102 + it() The bf(a) means that the ACL information changed.
6103 + it() The bf(x) slot is reserved for reporting extended attribute changes
6104 + (a feature that is not yet released).
6107 One other output is possible: when deleting files, the "%i" will output
6112 + Unix SMB/Netbios implementation.
6114 + Portable SMB ACL interface
6115 + Copyright (C) Jeremy Allison 2000
6117 + This program is free software; you can redistribute it and/or modify
6118 + it under the terms of the GNU General Public License as published by
6119 + the Free Software Foundation; either version 2 of the License, or
6120 + (at your option) any later version.
6122 + This program is distributed in the hope that it will be useful,
6123 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6124 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6125 + GNU General Public License for more details.
6127 + You should have received a copy of the GNU General Public License
6128 + along with this program; if not, write to the Free Software
6129 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6132 +#ifndef _SMB_ACLS_H
6133 +#define _SMB_ACLS_H
6135 +#if defined HAVE_POSIX_ACLS
6137 +/* This is an identity mapping (just remove the SMB_). */
6139 +#define SMB_ACL_TAG_T acl_tag_t
6140 +#define SMB_ACL_TYPE_T acl_type_t
6141 +#define SMB_ACL_PERMSET_T acl_permset_t
6142 +#define SMB_ACL_PERM_T acl_perm_t
6143 +#define SMB_ACL_READ ACL_READ
6144 +#define SMB_ACL_WRITE ACL_WRITE
6145 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6147 +/* Types of ACLs. */
6148 +#define SMB_ACL_USER ACL_USER
6149 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6150 +#define SMB_ACL_GROUP ACL_GROUP
6151 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6152 +#define SMB_ACL_OTHER ACL_OTHER
6153 +#define SMB_ACL_MASK ACL_MASK
6155 +#define SMB_ACL_T acl_t
6157 +#define SMB_ACL_ENTRY_T acl_entry_t
6159 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6160 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6162 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6163 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6165 +#elif defined HAVE_TRU64_ACLS
6167 +/* This is for DEC/Compaq Tru64 UNIX */
6169 +#define SMB_ACL_TAG_T acl_tag_t
6170 +#define SMB_ACL_TYPE_T acl_type_t
6171 +#define SMB_ACL_PERMSET_T acl_permset_t
6172 +#define SMB_ACL_PERM_T acl_perm_t
6173 +#define SMB_ACL_READ ACL_READ
6174 +#define SMB_ACL_WRITE ACL_WRITE
6175 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6177 +/* Types of ACLs. */
6178 +#define SMB_ACL_USER ACL_USER
6179 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6180 +#define SMB_ACL_GROUP ACL_GROUP
6181 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6182 +#define SMB_ACL_OTHER ACL_OTHER
6183 +#define SMB_ACL_MASK ACL_MASK
6185 +#define SMB_ACL_T acl_t
6187 +#define SMB_ACL_ENTRY_T acl_entry_t
6189 +#define SMB_ACL_FIRST_ENTRY 0
6190 +#define SMB_ACL_NEXT_ENTRY 1
6192 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6193 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6195 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6197 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6198 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6201 +/* SVR4.2 ES/MP ACLs */
6202 +typedef int SMB_ACL_TAG_T;
6203 +typedef int SMB_ACL_TYPE_T;
6204 +typedef ushort *SMB_ACL_PERMSET_T;
6205 +typedef ushort SMB_ACL_PERM_T;
6206 +#define SMB_ACL_READ 4
6207 +#define SMB_ACL_WRITE 2
6208 +#define SMB_ACL_EXECUTE 1
6210 +/* Types of ACLs. */
6211 +#define SMB_ACL_USER USER
6212 +#define SMB_ACL_USER_OBJ USER_OBJ
6213 +#define SMB_ACL_GROUP GROUP
6214 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6215 +#define SMB_ACL_OTHER OTHER_OBJ
6216 +#define SMB_ACL_MASK CLASS_OBJ
6218 +typedef struct SMB_ACL_T {
6222 + struct acl acl[1];
6225 +typedef struct acl *SMB_ACL_ENTRY_T;
6227 +#define SMB_ACL_FIRST_ENTRY 0
6228 +#define SMB_ACL_NEXT_ENTRY 1
6230 +#define SMB_ACL_TYPE_ACCESS 0
6231 +#define SMB_ACL_TYPE_DEFAULT 1
6234 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6237 +#elif defined HAVE_HPUX_ACLS
6240 + * Based on the Solaris & UnixWare code.
6244 +#include <sys/aclv.h>
6246 +/* SVR4.2 ES/MP ACLs */
6247 +typedef int SMB_ACL_TAG_T;
6248 +typedef int SMB_ACL_TYPE_T;
6249 +typedef ushort *SMB_ACL_PERMSET_T;
6250 +typedef ushort SMB_ACL_PERM_T;
6251 +#define SMB_ACL_READ 4
6252 +#define SMB_ACL_WRITE 2
6253 +#define SMB_ACL_EXECUTE 1
6255 +/* Types of ACLs. */
6256 +#define SMB_ACL_USER USER
6257 +#define SMB_ACL_USER_OBJ USER_OBJ
6258 +#define SMB_ACL_GROUP GROUP
6259 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6260 +#define SMB_ACL_OTHER OTHER_OBJ
6261 +#define SMB_ACL_MASK CLASS_OBJ
6263 +typedef struct SMB_ACL_T {
6267 + struct acl acl[1];
6270 +typedef struct acl *SMB_ACL_ENTRY_T;
6272 +#define SMB_ACL_FIRST_ENTRY 0
6273 +#define SMB_ACL_NEXT_ENTRY 1
6275 +#define SMB_ACL_TYPE_ACCESS 0
6276 +#define SMB_ACL_TYPE_DEFAULT 1
6278 +#elif defined HAVE_IRIX_ACLS
6280 +#define SMB_ACL_TAG_T acl_tag_t
6281 +#define SMB_ACL_TYPE_T acl_type_t
6282 +#define SMB_ACL_PERMSET_T acl_permset_t
6283 +#define SMB_ACL_PERM_T acl_perm_t
6284 +#define SMB_ACL_READ ACL_READ
6285 +#define SMB_ACL_WRITE ACL_WRITE
6286 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6288 +/* Types of ACLs. */
6289 +#define SMB_ACL_USER ACL_USER
6290 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6291 +#define SMB_ACL_GROUP ACL_GROUP
6292 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6293 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6294 +#define SMB_ACL_MASK ACL_MASK
6296 +typedef struct SMB_ACL_T {
6302 +#define SMB_ACL_ENTRY_T acl_entry_t
6304 +#define SMB_ACL_FIRST_ENTRY 0
6305 +#define SMB_ACL_NEXT_ENTRY 1
6307 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6308 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6310 +#elif defined HAVE_AIX_ACLS
6312 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6314 +#include "/usr/include/acl.h"
6316 +typedef uint *SMB_ACL_PERMSET_T;
6318 +struct acl_entry_link{
6319 + struct acl_entry_link *prevp;
6320 + struct new_acl_entry *entryp;
6321 + struct acl_entry_link *nextp;
6325 +struct new_acl_entry{
6326 + unsigned short ace_len;
6327 + unsigned short ace_type;
6328 + unsigned int ace_access;
6329 + struct ace_id ace_id[1];
6332 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6333 +#define SMB_ACL_T struct acl_entry_link*
6335 +#define SMB_ACL_TAG_T unsigned short
6336 +#define SMB_ACL_TYPE_T int
6337 +#define SMB_ACL_PERM_T uint
6338 +#define SMB_ACL_READ S_IRUSR
6339 +#define SMB_ACL_WRITE S_IWUSR
6340 +#define SMB_ACL_EXECUTE S_IXUSR
6342 +/* Types of ACLs. */
6343 +#define SMB_ACL_USER ACEID_USER
6344 +#define SMB_ACL_USER_OBJ 3
6345 +#define SMB_ACL_GROUP ACEID_GROUP
6346 +#define SMB_ACL_GROUP_OBJ 4
6347 +#define SMB_ACL_OTHER 5
6348 +#define SMB_ACL_MASK 6
6351 +#define SMB_ACL_FIRST_ENTRY 1
6352 +#define SMB_ACL_NEXT_ENTRY 2
6354 +#define SMB_ACL_TYPE_ACCESS 0
6355 +#define SMB_ACL_TYPE_DEFAULT 1
6357 +#else /* No ACLs. */
6359 +/* No ACLS - fake it. */
6360 +#define SMB_ACL_TAG_T int
6361 +#define SMB_ACL_TYPE_T int
6362 +#define SMB_ACL_PERMSET_T mode_t
6363 +#define SMB_ACL_PERM_T mode_t
6364 +#define SMB_ACL_READ S_IRUSR
6365 +#define SMB_ACL_WRITE S_IWUSR
6366 +#define SMB_ACL_EXECUTE S_IXUSR
6368 +/* Types of ACLs. */
6369 +#define SMB_ACL_USER 0
6370 +#define SMB_ACL_USER_OBJ 1
6371 +#define SMB_ACL_GROUP 2
6372 +#define SMB_ACL_GROUP_OBJ 3
6373 +#define SMB_ACL_OTHER 4
6374 +#define SMB_ACL_MASK 5
6376 +typedef struct SMB_ACL_T {
6380 +typedef struct SMB_ACL_ENTRY_T {
6382 +} *SMB_ACL_ENTRY_T;
6384 +#define SMB_ACL_FIRST_ENTRY 0
6385 +#define SMB_ACL_NEXT_ENTRY 1
6387 +#define SMB_ACL_TYPE_ACCESS 0
6388 +#define SMB_ACL_TYPE_DEFAULT 1
6390 +#endif /* No ACLs. */
6391 +#endif /* _SMB_ACLS_H */
6392 --- old/testsuite/acls.test
6393 +++ new/testsuite/acls.test
6397 +# This program is distributable under the terms of the GNU GPL (see
6400 +# Test that rsync handles basic ACL preservation.
6402 +. $srcdir/testsuite/rsync.fns
6404 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6405 +case "$setfacl_nodef" in
6406 +true) test_skipped "I don't know how to use your setfacl command" ;;
6409 +makepath "$fromdir/foo"
6410 +echo something >"$fromdir/file1"
6411 +echo else >"$fromdir/file2"
6413 +files='foo file1 file2'
6415 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6416 +setfacl -m u:0:5 "$fromdir/file1"
6417 +setfacl -m u:0:5 "$fromdir/file2"
6419 +$RSYNC -avvA "$fromdir/" "$todir/"
6422 +getfacl $files >"$scratchdir/acls.txt"
6425 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6427 +# The script would have aborted on error, so getting here means we've won.
6429 --- old/testsuite/default-acls.test
6430 +++ new/testsuite/default-acls.test
6434 +# This program is distributable under the terms of the GNU GPL (see
6437 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6439 +. $srcdir/testsuite/rsync.fns
6441 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6442 +case "$setfacl_nodef" in
6443 +true) test_skipped "I don't know how to use your setfacl command" ;;
6444 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6445 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6447 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6449 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6451 + todir="$scratchdir/$1"
6453 + $setfacl_nodef "$todir"
6455 + case "$setfacl_nodef" in
6456 + *-k*) opts="-dm $2" ;;
6457 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6459 + setfacl $opts "$todir"
6461 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6462 + # even though the directory itself is outside the transfer
6463 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6464 + check_perms "$todir/to" $4 "Target $1"
6465 + check_perms "$todir/to/dir" $4 "Target $1"
6466 + check_perms "$todir/to/file" $3 "Target $1"
6467 + check_perms "$todir/to/program" $4 "Target $1"
6468 + # Make sure get_local_name doesn't mess us up when transferring only one file
6469 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6470 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6471 + # Make sure we obey default ACLs when not transferring a regular file
6472 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6473 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6476 +mkdir "$scratchdir/dir"
6477 +echo "File!" >"$scratchdir/file"
6478 +echo "#!/bin/sh" >"$scratchdir/program"
6479 +chmod 777 "$scratchdir/dir"
6480 +chmod 666 "$scratchdir/file"
6481 +chmod 777 "$scratchdir/program"
6483 +# Test some target directories
6485 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6486 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6487 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6488 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6489 +testit noda1 '' rw------- rwx------
6491 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6493 +testit noda3 '' rw-r--r-- rwxr-xr-x
6497 --- old/testsuite/devices.test
6498 +++ new/testsuite/devices.test
6499 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6500 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6502 cat <<EOT >"$chkfile"
6506 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6508 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6510 cat <<EOT >"$chkfile"
6514 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6516 @@ -58,7 +58,7 @@ sleep 1
6517 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6519 cat <<EOT >"$chkfile"
6523 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6525 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6528 cat <<EOT >"$chkfile"
6533 -hD+++++++ block2.5 => block3
6542 +hD+++++++++ block2.5 => block3
6548 if test ! -b "$fromdir/block2.5"; then
6549 sed -e '/block2\.5/d' \
6550 @@ -94,15 +94,15 @@ if test -b "$fromdir/block2.5"; then
6551 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
6553 cat <<EOT >"$chkfile"
6573 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
6575 --- old/testsuite/itemize.test
6576 +++ new/testsuite/itemize.test
6577 @@ -38,15 +38,15 @@ rm -f "$to2dir" "$to2dir.test"
6578 $RSYNC -iplr "$fromdir/" "$todir/" \
6580 cat <<EOT >"$chkfile"
6584 ->f+++++++ bar/baz/rsync
6586 ->f+++++++ foo/config1
6587 ->f+++++++ foo/config2
6588 ->f+++++++ foo/extra
6589 -cL+++++++ foo/sym -> ../bar/baz/rsync
6592 +cd+++++++++ bar/baz/
6593 +>f+++++++++ bar/baz/rsync
6595 +>f+++++++++ foo/config1
6596 +>f+++++++++ foo/config2
6597 +>f+++++++++ foo/extra
6598 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6600 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6602 @@ -58,10 +58,10 @@ chmod 601 "$fromdir/foo/config2"
6603 $RSYNC -iplrH "$fromdir/" "$todir/" \
6605 cat <<EOT >"$chkfile"
6606 ->f..T.... bar/baz/rsync
6607 ->f..T.... foo/config1
6608 ->f.sTp... foo/config2
6609 -hf..T.... foo/extra => foo/config1
6610 +>f..T...... bar/baz/rsync
6611 +>f..T...... foo/config1
6612 +>f.sTp..... foo/config2
6613 +hf..T...... foo/extra => foo/config1
6615 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6617 @@ -78,11 +78,11 @@ chmod 777 "$todir/bar/baz/rsync"
6618 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6620 cat <<EOT >"$chkfile"
6621 -.f..tp... bar/baz/rsync
6623 -.f..t.... foo/config1
6624 ->fcstp... foo/config2
6625 -cL..T.... foo/sym -> ../bar/baz/rsync
6626 +.f..tp..... bar/baz/rsync
6628 +.f..t...... foo/config1
6629 +>fcstp..... foo/config2
6630 +cL..T...... foo/sym -> ../bar/baz/rsync
6632 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6634 @@ -107,15 +107,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6637 cat <<EOT >"$chkfile"
6641 -.f...p... bar/baz/rsync
6644 ->f..t.... foo/config2
6646 -.L foo/sym -> ../bar/baz/rsync
6650 +.f...p..... bar/baz/rsync
6653 +>f..t...... foo/config2
6655 +.L foo/sym -> ../bar/baz/rsync
6657 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6659 @@ -134,8 +134,8 @@ touch "$todir/foo/config2"
6660 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6662 cat <<EOT >"$chkfile"
6663 -.f...p... foo/config1
6664 ->f..t.... foo/config2
6665 +.f...p..... foo/config1
6666 +>f..t...... foo/config2
6668 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6670 @@ -143,15 +143,15 @@ $RSYNC -ivvplrtH --copy-dest=../to "$fro
6673 cat <<EOT >"$chkfile"
6681 -hf foo/extra => foo/config1
6682 -cL foo/sym -> ../bar/baz/rsync
6690 +hf foo/extra => foo/config1
6691 +cL foo/sym -> ../bar/baz/rsync
6693 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6695 @@ -159,7 +159,7 @@ rm -rf "$to2dir"
6696 $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \
6698 cat <<EOT >"$chkfile"
6699 -hf foo/extra => foo/config1
6700 +hf foo/extra => foo/config1
6702 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6704 @@ -185,15 +185,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$
6707 cat <<EOT >"$chkfile"
6715 -hf foo/extra => foo/config1
6716 -$L foo/sym -> ../bar/baz/rsync
6724 +hf foo/extra => foo/config1
6725 +$L foo/sym -> ../bar/baz/rsync
6727 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6729 @@ -233,15 +233,15 @@ $RSYNC -ivvplrtH --compare-dest="$todir"
6732 cat <<EOT >"$chkfile"
6741 -.L foo/sym -> ../bar/baz/rsync
6750 +.L foo/sym -> ../bar/baz/rsync
6752 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6758 extern int preserve_uid;
6759 extern int preserve_gid;
6760 +extern int preserve_acls;
6761 extern int numeric_ids;
6764 @@ -270,7 +271,7 @@ void send_uid_list(int f)
6766 struct idlist *list;
6768 - if (preserve_uid) {
6769 + if (preserve_uid || preserve_acls) {
6771 /* we send sequences of uid/byte-length/name */
6772 for (list = uidlist; list; list = list->next) {
6773 @@ -287,7 +288,7 @@ void send_uid_list(int f)
6777 - if (preserve_gid) {
6778 + if (preserve_gid || preserve_acls) {
6780 for (list = gidlist; list; list = list->next) {
6782 @@ -308,7 +309,7 @@ void recv_uid_list(int f, struct file_li
6786 - if (preserve_uid && !numeric_ids) {
6787 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6788 /* read the uid list */
6789 while ((id = read_int(f)) != 0) {
6790 int len = read_byte(f);
6791 @@ -320,7 +321,7 @@ void recv_uid_list(int f, struct file_li
6795 - if (preserve_gid && !numeric_ids) {
6796 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6797 /* read the gid list */
6798 while ((id = read_int(f)) != 0) {
6799 int len = read_byte(f);
6800 @@ -332,6 +333,16 @@ void recv_uid_list(int f, struct file_li
6804 +#ifdef SUPPORT_ACLS
6805 + if (preserve_acls && !numeric_ids) {
6807 + while ((id = next_acl_uid(flist)) != NULL)
6808 + *id = match_uid(*id);
6809 + while ((id = next_acl_gid(flist)) != NULL)
6810 + *id = match_gid(*id);
6814 /* Now convert all the uids/gids from sender values to our values. */
6815 if (am_root && preserve_uid && !numeric_ids) {
6816 for (i = 0; i < flist->count; i++)
6819 @@ -1467,3 +1467,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6824 +void *expand_item_list(item_list *lp, size_t item_size,
6825 + const char *desc, int incr)
6827 + /* First time through, 0 <= 0, so list is expanded. */
6828 + if (lp->malloced <= lp->count) {
6830 + size_t new_size = lp->malloced;
6832 + new_size -= incr; /* increase slowly */
6833 + else if (new_size < (size_t)incr)
6837 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6838 + if (verbose >= 4) {
6839 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6840 + who_am_i(), desc, (double)new_size * item_size,
6841 + new_ptr == lp->items ? " not" : "");
6844 + out_of_memory("expand_item_list");
6846 + lp->items = new_ptr;
6847 + lp->malloced = new_size;
6849 + return (char*)lp->items + (lp->count++ * item_size);