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=flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o \
25 util.o main.o checksum.o match.o syscall.o log.o backup.o
26 OBJS2=options.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 protocol_version;
68 +/* === ACL structures === */
80 +#define NO_ENTRY ((uchar)0x80)
81 +typedef struct rsync_acl {
84 + /* These will be NO_ENTRY if there's no such entry. */
96 +static const rsync_acl empty_rsync_acl = {
97 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
100 +static item_list access_acl_list = EMPTY_ITEM_LIST;
101 +static item_list default_acl_list = EMPTY_ITEM_LIST;
103 +/* === Calculations on ACL types === */
105 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
107 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
108 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
109 + : "unknown SMB_ACL_TYPE_T";
112 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
113 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
115 +static int count_racl_entries(const rsync_acl *racl)
117 + return racl->users.count + racl->groups.count
118 + + (racl->user_obj != NO_ENTRY)
119 + + (racl->group_obj != NO_ENTRY)
120 + + (racl->mask != NO_ENTRY)
121 + + (racl->other != NO_ENTRY);
124 +static int calc_sacl_entries(const rsync_acl *racl)
126 + /* A System ACL always gets user/group/other permission entries. */
127 + return racl->users.count + racl->groups.count
128 +#ifdef ACLS_NEED_MASK
131 + + (racl->mask != NO_ENTRY) + 3;
135 +/* Extracts and returns the permission bits from the ACL. This cannot be
136 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
137 +static int rsync_acl_get_perms(const rsync_acl *racl)
139 + return (racl->user_obj << 6)
140 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
144 +/* Removes the permission-bit entries from the ACL because these
145 + * can be reconstructed from the file's mode. */
146 +static void rsync_acl_strip_perms(rsync_acl *racl)
148 + racl->user_obj = NO_ENTRY;
149 + if (racl->mask == NO_ENTRY)
150 + racl->group_obj = NO_ENTRY;
152 + if (racl->group_obj == racl->mask)
153 + racl->group_obj = NO_ENTRY;
154 + racl->mask = NO_ENTRY;
156 + racl->other = NO_ENTRY;
159 +/* Given an empty rsync_acl, fake up the permission bits. */
160 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
162 + racl->user_obj = (mode >> 6) & 7;
163 + racl->group_obj = (mode >> 3) & 7;
164 + racl->other = mode & 7;
167 +/* === Rsync ACL functions === */
169 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
171 + id_access *ida1, *ida2;
172 + int count = ial1->count;
173 + if (count != ial2->count)
177 + for (; count--; ida1++, ida2++) {
178 + if (ida1->access != ida2->access || ida1->id != ida2->id)
184 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
186 + return racl1->user_obj == racl2->user_obj
187 + && racl1->group_obj == racl2->group_obj
188 + && racl1->mask == racl2->mask
189 + && racl1->other == racl2->other
190 + && ida_entries_equal(&racl1->users, &racl2->users)
191 + && ida_entries_equal(&racl1->groups, &racl2->groups);
194 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
195 + * the ACL will be handled by the normal mode-preservation code. This is
196 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
197 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
198 + * that it might have several of its permission objects set to NO_ENTRY. */
199 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
200 + const rsync_acl *racl2, mode_t m)
202 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
203 + return False; /* One has a mask and the other doesn't */
205 + /* When there's a mask, the group_obj becomes an extended entry. */
206 + if (racl1->mask != NO_ENTRY) {
207 + /* A condensed rsync_acl with a mask can only have no
208 + * group_obj when it was identical to the mask. This
209 + * means that it was also identical to the group attrs
210 + * from the mode. */
211 + if (racl2->group_obj == NO_ENTRY) {
212 + if (racl1->group_obj != ((m >> 3) & 7))
214 + } else if (racl1->group_obj != racl2->group_obj)
217 + return ida_entries_equal(&racl1->users, &racl2->users)
218 + && ida_entries_equal(&racl1->groups, &racl2->groups);
221 +static void rsync_acl_free(rsync_acl *racl)
223 + if (racl->users.idas)
224 + free(racl->users.idas);
225 + if (racl->groups.idas)
226 + free(racl->groups.idas);
227 + *racl = empty_rsync_acl;
230 +void free_acl(statx *sxp)
232 + if (sxp->acc_acl) {
233 + rsync_acl_free(sxp->acc_acl);
234 + free(sxp->acc_acl);
235 + sxp->acc_acl = NULL;
237 + if (sxp->def_acl) {
238 + rsync_acl_free(sxp->def_acl);
239 + free(sxp->def_acl);
240 + sxp->def_acl = NULL;
244 +static int id_access_sorter(const void *r1, const void *r2)
246 + id_access *ida1 = (id_access *)r1;
247 + id_access *ida2 = (id_access *)r2;
248 + id_t rid1 = ida1->id, rid2 = ida2->id;
249 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
252 +static void sort_ida_entries(ida_entries *idal)
256 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
259 +/* Transfer the count id_access items out of the temp_ida_list into either
260 + * the users or groups ida_entries list in racl. */
261 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
266 + if (temp_ida_list->count) {
267 + int cnt = temp_ida_list->count;
268 + id_access *temp_idas = temp_ida_list->items;
269 + if (!(idas = new_array(id_access, cnt)))
270 + out_of_memory("save_idas");
271 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
275 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
278 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
279 + exit_cleanup(RERR_UNSUPPORTED);
281 + ent->count = temp_ida_list->count;
284 + /* Truncate the temporary list now that its idas have been saved. */
285 + temp_ida_list->count = 0;
288 +/* === System ACLs === */
290 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
291 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
293 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
294 + SMB_ACL_TAG_T prior_list_type = 0;
295 + SMB_ACL_ENTRY_T entry;
296 + const char *errfun;
299 + errfun = "sys_acl_get_entry";
300 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
302 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
303 + SMB_ACL_TAG_T tag_type;
304 + SMB_ACL_PERMSET_T permset;
308 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
309 + errfun = "sys_acl_get_tag_type";
312 + if ((rc = sys_acl_get_permset(entry, &permset))) {
313 + errfun = "sys_acl_get_tag_type";
316 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
317 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
318 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
319 + /* continue == done with entry; break == store in temporary ida list */
320 + switch (tag_type) {
321 + case SMB_ACL_USER_OBJ:
322 + if (racl->user_obj == NO_ENTRY)
323 + racl->user_obj = access;
325 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
329 + case SMB_ACL_GROUP_OBJ:
330 + if (racl->group_obj == NO_ENTRY)
331 + racl->group_obj = access;
333 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
335 + case SMB_ACL_GROUP:
338 + if (racl->mask == NO_ENTRY)
339 + racl->mask = access;
341 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
343 + case SMB_ACL_OTHER:
344 + if (racl->other == NO_ENTRY)
345 + racl->other = access;
347 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
350 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
353 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
354 + errfun = "sys_acl_get_tag_type";
358 + if (tag_type != prior_list_type) {
359 + if (prior_list_type)
360 + save_idas(&temp_ida_list, racl, prior_list_type);
361 + prior_list_type = tag_type;
363 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
364 + ida->id = *((id_t *)qualifier);
365 + ida->access = access;
366 + sys_acl_free_qualifier(qualifier, tag_type);
369 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
370 + rsync_acl_free(racl);
373 + if (prior_list_type)
374 + save_idas(&temp_ida_list, racl, prior_list_type);
376 + sort_ida_entries(&racl->users);
377 + sort_ida_entries(&racl->groups);
379 +#ifdef ACLS_NEED_MASK
380 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
381 + /* Throw away a superfluous mask, but mask off the
382 + * group perms with it first. */
383 + racl->group_obj &= racl->mask;
384 + racl->mask = NO_ENTRY;
391 +/* Synactic sugar for system calls */
393 +#define CALL_OR_ERROR(func,args,str) \
401 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
402 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
404 +/* Store the permissions in the system ACL entry. */
405 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
407 + const char *errfun = NULL;
408 + SMB_ACL_PERMSET_T permset;
410 + COE( sys_acl_get_permset,(entry, &permset) );
411 + COE( sys_acl_clear_perms,(permset) );
413 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
415 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
417 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
418 + COE( sys_acl_set_permset,(entry, permset) );
423 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
427 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
428 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
430 +#ifdef ACLS_NEED_MASK
435 + const char *errfun = NULL;
436 + SMB_ACL_ENTRY_T entry;
438 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
439 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
443 + COE( sys_acl_create_entry,(smb_acl, &entry) );
444 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
445 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
447 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
448 + COE( sys_acl_create_entry,(smb_acl, &entry) );
449 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
450 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
451 + COE2( store_access_in_entry,(ida->access, entry) );
454 + COE( sys_acl_create_entry,(smb_acl, &entry) );
455 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
456 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
458 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
459 + COE( sys_acl_create_entry,(smb_acl, &entry) );
460 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
461 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
462 + COE2( store_access_in_entry,(ida->access, entry) );
465 +#ifdef ACLS_NEED_MASK
466 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
467 + COE( sys_acl_create_entry,(smb_acl, &entry) );
468 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
469 + COE2( store_access_in_entry,(mask_bits, entry) );
471 + if (racl->mask != NO_ENTRY) {
472 + COE( sys_acl_create_entry,(smb_acl, &entry) );
473 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
474 + COE2( store_access_in_entry,(racl->mask, entry) );
478 + COE( sys_acl_create_entry,(smb_acl, &entry) );
479 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
480 + COE2( store_access_in_entry,(racl->other & 7, entry) );
483 + if (sys_acl_valid(*smb_acl) < 0)
484 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
491 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
493 + sys_acl_free_acl(*smb_acl);
497 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
498 + const item_list *racl_list,
499 + const rsync_acl *racl)
501 + static int access_match = -1, default_match = -1;
502 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
503 + size_t count = racl_list->count;
505 + /* If this is the first time through or we didn't match the last
506 + * time, then start at the end of the list, which should be the
507 + * best place to start hunting. */
509 + *match = racl_list->count - 1;
511 + rsync_acl *base = racl_list->items;
512 + if (rsync_acl_equal(base + *match, racl))
515 + *match = racl_list->count - 1;
522 +/* Return the Access Control List for the given filename. */
523 +int get_acl(const char *fname, statx *sxp)
525 + SMB_ACL_TYPE_T type;
527 + if (S_ISLNK(sxp->st.st_mode))
530 + type = SMB_ACL_TYPE_ACCESS;
532 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
533 + rsync_acl *racl = new(rsync_acl);
536 + out_of_memory("get_acl");
537 + *racl = empty_rsync_acl;
538 + if (type == SMB_ACL_TYPE_ACCESS)
539 + sxp->acc_acl = racl;
541 + sxp->def_acl = racl;
544 + BOOL ok = unpack_smb_acl(racl, sacl);
546 + sys_acl_free_acl(sacl);
551 + } else if (errno == ENOTSUP || errno == ENOSYS) {
552 + /* ACLs are not supported, so pretend we have a basic ACL. */
553 + if (type == SMB_ACL_TYPE_ACCESS)
554 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
556 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
557 + fname, str_acl_type(type));
561 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
566 +/* === Send functions === */
568 +/* The general strategy with the tag_type <-> character mapping is that
569 + * lowercase implies that no qualifier follows, where uppercase does.
570 + * A similar idiom for the ACL type (access or default) itself, but
571 + * lowercase in this instance means there's no ACL following, so the
572 + * ACL is a repeat, so the receiver should reuse the last of the same
575 +/* Send the ida list over the file descriptor. */
576 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
579 + size_t count = idal->count;
580 + for (ida = idal->idas; count--; ida++) {
581 + write_byte(f, tag_char);
582 + write_byte(f, ida->access);
583 + write_int(f, ida->id);
584 + /* FIXME: sorta wasteful: we should maybe buffer as
585 + * many ids as max(ACL_USER + ACL_GROUP) objects to
586 + * keep from making so many calls. */
587 + if (tag_char == 'U')
594 +/* Send an rsync ACL over the file descriptor. */
595 +static void send_rsync_acl(int f, const rsync_acl *racl)
597 + size_t count = count_racl_entries(racl);
598 + write_int(f, count);
599 + if (racl->user_obj != NO_ENTRY) {
600 + write_byte(f, 'u');
601 + write_byte(f, racl->user_obj);
603 + send_ida_entries(f, &racl->users, 'U');
604 + if (racl->group_obj != NO_ENTRY) {
605 + write_byte(f, 'g');
606 + write_byte(f, racl->group_obj);
608 + send_ida_entries(f, &racl->groups, 'G');
609 + if (racl->mask != NO_ENTRY) {
610 + write_byte(f, 'm');
611 + write_byte(f, racl->mask);
613 + if (racl->other != NO_ENTRY) {
614 + write_byte(f, 'o');
615 + write_byte(f, racl->other);
619 +/* Send the ACL from the statx structure down the indicated file descriptor.
620 + * This also frees the ACL data. */
621 +void send_acl(statx *sxp, int f)
623 + SMB_ACL_TYPE_T type;
624 + rsync_acl *racl, *new_racl;
625 + item_list *racl_list;
628 + if (S_ISLNK(sxp->st.st_mode))
631 + type = SMB_ACL_TYPE_ACCESS;
632 + racl = sxp->acc_acl;
633 + racl_list = &access_acl_list;
636 + racl = new(rsync_acl);
638 + out_of_memory("send_acl");
639 + *racl = empty_rsync_acl;
640 + if (type == SMB_ACL_TYPE_ACCESS) {
641 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
642 + sxp->acc_acl = racl;
644 + sxp->def_acl = racl;
647 + /* Avoid sending values that can be inferred from other data. */
648 + if (type == SMB_ACL_TYPE_ACCESS && protocol_version >= 30)
649 + rsync_acl_strip_perms(racl);
650 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
651 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
654 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
655 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
656 + send_rsync_acl(f, racl);
658 + *racl = empty_rsync_acl;
660 + racl = sxp->def_acl;
661 + racl_list = &default_acl_list;
662 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
667 +/* === Receive functions === */
669 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
671 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
672 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
673 + uchar computed_mask_bits = 0;
677 + if (!(count = read_int(f)))
681 + char tag = read_byte(f);
682 + uchar access = read_byte(f);
683 + if (access & ~ (4 | 2 | 1)) {
684 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
686 + exit_cleanup(RERR_STREAMIO);
690 + if (racl->user_obj != NO_ENTRY) {
691 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
692 + exit_cleanup(RERR_STREAMIO);
694 + racl->user_obj = access;
697 + tag_type = SMB_ACL_USER;
700 + if (racl->group_obj != NO_ENTRY) {
701 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
702 + exit_cleanup(RERR_STREAMIO);
704 + racl->group_obj = access;
707 + tag_type = SMB_ACL_GROUP;
710 + if (racl->mask != NO_ENTRY) {
711 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
712 + exit_cleanup(RERR_STREAMIO);
714 + racl->mask = access;
717 + if (racl->other != NO_ENTRY) {
718 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
719 + exit_cleanup(RERR_STREAMIO);
721 + racl->other = access;
724 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
726 + exit_cleanup(RERR_STREAMIO);
728 + if (tag_type != prior_list_type) {
729 + if (prior_list_type)
730 + save_idas(&temp_ida_list, racl, prior_list_type);
731 + prior_list_type = tag_type;
733 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
734 + ida->access = access;
735 + ida->id = read_int(f);
736 + computed_mask_bits |= access;
738 + if (prior_list_type)
739 + save_idas(&temp_ida_list, racl, prior_list_type);
741 + if (type == SMB_ACL_TYPE_DEFAULT) {
742 + /* Ensure that these are never unset. */
743 + if (racl->user_obj == NO_ENTRY)
744 + racl->user_obj = 7;
745 + if (racl->group_obj == NO_ENTRY)
746 + racl->group_obj = 0;
747 + if (racl->other == NO_ENTRY)
751 + if (!racl->users.count && !racl->groups.count) {
752 + /* If we received a superfluous mask, throw it away. */
753 + if (racl->mask != NO_ENTRY) {
754 + /* Mask off the group perms with it first. */
755 + racl->group_obj &= racl->mask | NO_ENTRY;
756 + racl->mask = NO_ENTRY;
758 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
759 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
762 +/* Receive the ACL info the sender has included for this file-list entry. */
763 +void receive_acl(struct file_struct *file, int f)
765 + SMB_ACL_TYPE_T type;
766 + item_list *racl_list;
768 + if (S_ISLNK(file->mode))
771 + type = SMB_ACL_TYPE_ACCESS;
772 + racl_list = &access_acl_list;
774 + char tag = read_byte(f);
777 + if (tag == 'A' || tag == 'a') {
778 + if (type != SMB_ACL_TYPE_ACCESS) {
779 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
780 + f_name(file, NULL));
781 + exit_cleanup(RERR_STREAMIO);
783 + } else if (tag == 'D' || tag == 'd') {
784 + if (type == SMB_ACL_TYPE_ACCESS) {
785 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
786 + f_name(file, NULL));
787 + exit_cleanup(RERR_STREAMIO);
790 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
791 + f_name(file, NULL), tag);
792 + exit_cleanup(RERR_STREAMIO);
794 + if (tag == 'A' || tag == 'D') {
796 + ndx = racl_list->count;
797 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
798 + duo_item->racl = empty_rsync_acl;
799 + receive_rsync_acl(&duo_item->racl, f, type);
800 + duo_item->sacl = NULL;
803 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
804 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
805 + f_name(file, NULL), str_acl_type(type), ndx);
806 + exit_cleanup(RERR_STREAMIO);
809 + if (type == SMB_ACL_TYPE_ACCESS)
812 + F_DEF_ACL(file) = ndx;
813 + racl_list = &default_acl_list;
814 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
817 +/* Turn the ACL data in statx into cached ACL data, setting the index
818 + * values in the file struct. */
819 +void cache_acl(struct file_struct *file, statx *sxp)
821 + SMB_ACL_TYPE_T type;
823 + item_list *racl_list;
826 + if (S_ISLNK(file->mode))
829 + type = SMB_ACL_TYPE_ACCESS;
830 + racl = sxp->acc_acl;
831 + racl_list = &access_acl_list;
835 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
837 + ndx = racl_list->count;
838 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
839 + new_duo->racl = *racl;
840 + new_duo->sacl = NULL;
841 + *racl = empty_rsync_acl;
843 + if (type == SMB_ACL_TYPE_ACCESS)
846 + F_DEF_ACL(file) = ndx;
847 + racl = sxp->def_acl;
848 + racl_list = &default_acl_list;
849 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
854 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
856 + SMB_ACL_ENTRY_T entry;
857 + const char *errfun;
860 + if (S_ISDIR(mode)) {
861 + /* If the sticky bit is going on, it's not safe to allow all
862 + * the new ACL to go into effect before it gets set. */
863 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
864 + if (mode & S_ISVTX)
867 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
870 + /* If setuid or setgid is going off, it's not safe to allow all
871 + * the new ACL to go into effect before they get cleared. */
872 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
873 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
878 + errfun = "sys_acl_get_entry";
879 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
881 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
882 + SMB_ACL_TAG_T tag_type;
883 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
884 + errfun = "sys_acl_get_tag_type";
887 + switch (tag_type) {
888 + case SMB_ACL_USER_OBJ:
889 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
891 + case SMB_ACL_GROUP_OBJ:
892 + /* group is only empty when identical to group perms. */
893 + if (racl->group_obj != NO_ENTRY)
895 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
898 +#ifndef ACLS_NEED_MASK
899 + /* mask is only empty when we don't need it. */
900 + if (racl->mask == NO_ENTRY)
903 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
905 + case SMB_ACL_OTHER:
906 + COE2( store_access_in_entry,(mode & 7, entry) );
913 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
919 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
920 + /* Ensure that chmod() will be called to restore any lost setid bits. */
921 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
922 + && BITS_EQUAL(old_mode, mode, CHMOD_BITS))
923 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
926 + /* Return the mode of the file on disk, as we will set them. */
927 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
930 +/* Set ACL on indicated filename.
932 + * This sets extended access ACL entries and default ACL. If convenient,
933 + * it sets permission bits along with the access ACL and signals having
934 + * done so by modifying sxp->st.st_mode.
936 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
937 + * with fname set to NULL to just check if the ACL is unchanged. */
938 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
941 + SMB_ACL_TYPE_T type;
943 + if (!dry_run && (read_only || list_only)) {
948 + if (S_ISLNK(file->mode))
951 + type = SMB_ACL_TYPE_ACCESS;
957 + if (type == SMB_ACL_TYPE_ACCESS) {
959 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
961 + duo_item = access_acl_list.items;
964 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
966 + ndx = F_DEF_ACL(file);
967 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
969 + duo_item = default_acl_list.items;
972 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
976 + if (!dry_run && fname) {
977 + if (type == SMB_ACL_TYPE_DEFAULT
978 + && duo_item->racl.user_obj == NO_ENTRY) {
979 + if (sys_acl_delete_def_file(fname) < 0) {
980 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
986 + mode_t cur_mode = sxp->st.st_mode;
987 + if (!duo_item->sacl
988 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
992 + if (type == SMB_ACL_TYPE_ACCESS) {
993 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
994 + cur_mode, file->mode);
995 + if (cur_mode == (mode_t)~0)
998 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
999 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1000 + fname, str_acl_type(type));
1004 + if (type == SMB_ACL_TYPE_ACCESS)
1005 + sxp->st.st_mode = cur_mode;
1008 + if (unchanged == 1)
1010 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1015 +/* === Enumeration functions for uid mapping === */
1017 +/* Context -- one and only one. Should be cycled through once on uid
1018 + * mapping and once on gid mapping. */
1019 +static item_list *_enum_racl_lists[] = {
1020 + &access_acl_list, &default_acl_list, NULL
1023 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1024 +static int enum_ida_index = 0;
1025 +static size_t enum_racl_index = 0;
1027 +/* This returns the next tag_type id from the given ACL for the next entry,
1028 + * or it returns 0 if there are no more tag_type ids in the acl. */
1029 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1031 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1032 + if (enum_ida_index < idal->count) {
1033 + id_access *ida = &idal->idas[enum_ida_index++];
1036 + enum_ida_index = 0;
1040 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1042 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1044 + acl_duo *duo_item = racl_list->items;
1045 + duo_item += enum_racl_index;
1046 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1049 + enum_racl_index = 0;
1053 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1055 + for (; *enum_racl_list; enum_racl_list++) {
1056 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1060 + enum_racl_list = &_enum_racl_lists[0];
1064 +id_t *next_acl_uid()
1066 + return next_acl_list_id(SMB_ACL_USER);
1069 +id_t *next_acl_gid()
1071 + return next_acl_list_id(SMB_ACL_GROUP);
1074 +/* This is used by dest_mode(). */
1075 +int default_perms_for_dir(const char *dir)
1084 + perms = ACCESSPERMS & ~orig_umask;
1085 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1086 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1087 + if (sacl == NULL) {
1088 + /* Couldn't get an ACL. Darn. */
1092 + /* No ACLs are available. */
1096 + /* We're doing a dry run, so the containing directory
1097 + * wasn't actually created. Don't worry about it. */
1100 + /* Otherwise fall through. */
1102 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1103 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1109 + racl = empty_rsync_acl;
1110 + ok = unpack_smb_acl(&racl, sacl);
1111 + sys_acl_free_acl(sacl);
1113 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1117 + /* Apply the permission-bit entries of the default ACL, if any. */
1118 + if (racl.user_obj != NO_ENTRY) {
1119 + perms = rsync_acl_get_perms(&racl);
1121 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1124 + rsync_acl_free(&racl);
1128 +#endif /* SUPPORT_ACLS */
1135 +extern int preserve_acls;
1136 extern int preserve_devices;
1137 extern int preserve_specials;
1138 extern int preserve_links;
1139 @@ -92,7 +93,8 @@ path
1140 ****************************************************************************/
1141 static int make_bak_dir(char *fullpath)
1145 + struct file_struct *file;
1146 char *rel = fullpath + backup_dir_len;
1147 char *end = rel + strlen(rel);
1149 @@ -124,15 +126,24 @@ static int make_bak_dir(char *fullpath)
1151 /* Try to transfer the directory settings of the
1152 * actual dir that the files are coming from. */
1153 - if (do_stat(rel, &st) < 0) {
1154 + if (do_stat(rel, &sx.st) < 0) {
1155 rsyserr(FERROR, errno,
1156 "make_bak_dir stat %s failed",
1159 - do_lchown(fullpath, st.st_uid, st.st_gid);
1161 - do_chmod(fullpath, st.st_mode);
1162 +#ifdef SUPPORT_ACLS
1163 + sx.acc_acl = sx.def_acl = NULL;
1165 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1167 +#ifdef SUPPORT_ACLS
1168 + if (preserve_acls) {
1169 + get_acl(rel, &sx);
1170 + cache_acl(file, &sx);
1173 + set_file_attrs(fullpath, file, NULL, 0);
1178 @@ -170,15 +181,18 @@ static int robust_move(const char *src,
1179 * We will move the file to be deleted into a parallel directory tree. */
1180 static int keep_backup(const char *fname)
1184 struct file_struct *file;
1189 /* return if no file to keep */
1190 - if (do_lstat(fname, &st) < 0)
1191 + if (do_lstat(fname, &sx.st) < 0)
1193 +#ifdef SUPPORT_ACLS
1194 + sx.acc_acl = sx.def_acl = NULL;
1197 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1198 return 1; /* the file could have disappeared */
1199 @@ -188,6 +202,13 @@ static int keep_backup(const char *fname
1203 +#ifdef SUPPORT_ACLS
1204 + if (preserve_acls) {
1205 + get_acl(fname, &sx);
1206 + cache_acl(file, &sx);
1210 /* Check to see if this is a device file, or link */
1211 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1212 || (preserve_specials && IS_SPECIAL(file->mode))) {
1213 @@ -259,7 +280,7 @@ static int keep_backup(const char *fname
1214 if (robust_move(fname, buf) != 0) {
1215 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1216 full_fname(fname), buf);
1217 - } else if (st.st_nlink > 1) {
1218 + } else if (sx.st.st_nlink > 1) {
1219 /* If someone has hard-linked the file into the backup
1220 * dir, rename() might return success but do nothing! */
1221 robust_unlink(fname); /* Just in case... */
1224 @@ -40,6 +40,7 @@ extern int prune_empty_dirs;
1225 extern int protocol_version;
1226 extern int preserve_uid;
1227 extern int preserve_gid;
1228 +extern int preserve_acls;
1229 extern int preserve_hard_links;
1230 extern int need_messages_from_generator;
1231 extern int delete_mode, delete_before, delete_during, delete_after;
1232 @@ -60,6 +61,8 @@ void setup_protocol(int f_out,int f_in)
1233 preserve_uid = ++file_extra_cnt;
1235 preserve_gid = ++file_extra_cnt;
1236 + if (preserve_acls && !am_sender)
1237 + preserve_acls = ++file_extra_cnt;
1239 if (remote_protocol == 0) {
1241 --- old/configure.in
1242 +++ new/configure.in
1243 @@ -542,6 +542,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1244 AC_CHECK_LIB(resolv, strcasecmp)
1247 +AC_CHECK_FUNCS(aclsort)
1248 +if test x"$ac_cv_func_aclsort" = x"no"; then
1249 + AC_CHECK_LIB(sec, aclsort)
1252 dnl At the moment we don't test for a broken memcmp(), because all we
1253 dnl need to do is test for equality, not comparison, and it seems that
1254 dnl every platform has a memcmp that can do at least that.
1255 @@ -806,6 +811,78 @@ AC_SUBST(OBJ_RESTORE)
1256 AC_SUBST(CC_SHOBJ_FLAG)
1257 AC_SUBST(BUILD_POPT)
1259 +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h)
1260 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1261 +#################################################
1262 +# check for ACL support
1264 +AC_MSG_CHECKING(whether to support ACLs)
1265 +AC_ARG_ENABLE(acl-support,
1266 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1267 +[ case "$enableval" in
1270 + case "$host_os" in
1272 + AC_MSG_RESULT(Using UnixWare ACLs)
1273 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1275 + *solaris*|*cygwin*)
1276 + AC_MSG_RESULT(Using solaris ACLs)
1277 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1280 + AC_MSG_RESULT(Using HPUX ACLs)
1281 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1284 + AC_MSG_RESULT(Using IRIX ACLs)
1285 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1288 + AC_MSG_RESULT(Using AIX ACLs)
1289 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1292 + AC_MSG_RESULT(Using Tru64 ACLs)
1293 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1294 + LIBS="$LIBS -lpacl"
1297 + AC_MSG_RESULT(ACLs requested -- running tests)
1298 + AC_CHECK_LIB(acl,acl_get_file)
1299 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1300 + AC_TRY_LINK([#include <sys/types.h>
1301 +#include <sys/acl.h>],
1302 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1303 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1304 + AC_MSG_CHECKING(ACL test results)
1305 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1306 + AC_MSG_RESULT(Using posix ACLs)
1307 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1308 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1309 + AC_TRY_LINK([#include <sys/types.h>
1310 +#include <sys/acl.h>],
1311 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1312 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1313 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1314 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1317 + AC_MSG_ERROR(Failed to find ACL support)
1324 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1327 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1331 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1336 @@ -41,6 +41,7 @@ extern int filesfrom_fd;
1337 extern int one_file_system;
1338 extern int copy_dirlinks;
1339 extern int keep_dirlinks;
1340 +extern int preserve_acls;
1341 extern int preserve_links;
1342 extern int preserve_hard_links;
1343 extern int preserve_devices;
1344 @@ -152,6 +153,8 @@ static void list_file_entry(struct file_
1345 permstring(permbuf, f->mode);
1348 + /* TODO: indicate '+' if the entry has an ACL. */
1350 #ifdef SUPPORT_LINKS
1351 if (preserve_links && S_ISLNK(f->mode)) {
1352 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1353 @@ -714,6 +717,12 @@ static struct file_struct *recv_file_ent
1357 +#ifdef SUPPORT_ACLS
1358 + /* We need one or two index int32s when we're preserving ACLs. */
1359 + if (preserve_acls)
1360 + extra_len += (S_ISDIR(mode) ? 2 : 1) * EXTRA_LEN;
1363 if (always_checksum && S_ISREG(mode))
1364 extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
1366 @@ -851,6 +860,11 @@ static struct file_struct *recv_file_ent
1367 read_buf(f, bp, checksum_len);
1370 +#ifdef SUPPORT_ACLS
1371 + if (preserve_acls)
1372 + receive_acl(file, f);
1375 if (S_ISREG(mode) || S_ISLNK(mode))
1376 stats.total_size += file_length;
1378 @@ -1122,6 +1136,9 @@ static struct file_struct *send_file_nam
1379 int flags, int filter_flags)
1381 struct file_struct *file;
1382 +#ifdef SUPPORT_ACLS
1386 file = make_file(fname, flist, stp, flags, filter_flags);
1388 @@ -1130,12 +1147,26 @@ static struct file_struct *send_file_nam
1389 if (chmod_modes && !S_ISLNK(file->mode))
1390 file->mode = tweak_mode(file->mode, chmod_modes);
1392 +#ifdef SUPPORT_ACLS
1393 + if (preserve_acls && f >= 0) {
1394 + sx.st.st_mode = file->mode;
1395 + sx.acc_acl = sx.def_acl = NULL;
1396 + if (get_acl(fname, &sx) < 0)
1401 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1403 flist_expand(flist);
1404 flist->files[flist->count++] = file;
1407 send_file_entry(f, file, flist->count - 1);
1408 +#ifdef SUPPORT_ACLS
1409 + if (preserve_acls)
1418 @@ -35,6 +35,7 @@ extern int do_progress;
1419 extern int relative_paths;
1420 extern int implied_dirs;
1421 extern int keep_dirlinks;
1422 +extern int preserve_acls;
1423 extern int preserve_links;
1424 extern int preserve_devices;
1425 extern int preserve_specials;
1426 @@ -89,6 +90,7 @@ extern int force_delete;
1427 extern int one_file_system;
1428 extern struct stats stats;
1429 extern dev_t filesystem_dev;
1430 +extern mode_t orig_umask;
1431 extern char *backup_dir;
1432 extern char *backup_suffix;
1433 extern int backup_suffix_len;
1434 @@ -511,22 +513,31 @@ static void do_delete_pass(struct file_l
1435 rprintf(FINFO, " \r");
1438 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1439 +int unchanged_attrs(const char *fname, struct file_struct *file, statx *sxp)
1441 - if (preserve_perms && !BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS))
1442 + if (preserve_perms && !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
1445 - if (am_root && preserve_uid && st->st_uid != F_UID(file))
1446 + if (am_root && preserve_uid && sxp->st.st_uid != F_UID(file))
1449 - if (preserve_gid && F_GID(file) != GID_NONE && st->st_gid != F_GID(file))
1450 + if (preserve_gid && F_GID(file) != GID_NONE && sxp->st.st_gid != F_GID(file))
1453 +#ifdef SUPPORT_ACLS
1454 + if (preserve_acls) {
1455 + if (!ACL_READY(*sxp))
1456 + get_acl(fname, sxp);
1457 + if (set_acl(NULL, file, sxp) == 0)
1465 -void itemize(struct file_struct *file, int ndx, int statret,
1466 - STRUCT_STAT *st, int32 iflags, uchar fnamecmp_type,
1467 +void itemize(const char *fname, struct file_struct *file, int ndx, int statret,
1468 + statx *sxp, int32 iflags, uchar fnamecmp_type,
1471 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1472 @@ -534,20 +545,28 @@ void itemize(struct file_struct *file, i
1473 : S_ISDIR(file->mode) ? !omit_dir_times
1474 : !S_ISLNK(file->mode);
1476 - if (S_ISREG(file->mode) && F_LENGTH(file) != st->st_size)
1477 + if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
1478 iflags |= ITEM_REPORT_SIZE;
1479 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1480 && !(iflags & ITEM_MATCHED)
1481 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1482 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1483 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1484 iflags |= ITEM_REPORT_TIME;
1485 - if (!BITS_EQUAL(st->st_mode, file->mode, CHMOD_BITS))
1486 + if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
1487 iflags |= ITEM_REPORT_PERMS;
1488 - if (preserve_uid && am_root && F_UID(file) != st->st_uid)
1489 + if (preserve_uid && am_root && F_UID(file) != sxp->st.st_uid)
1490 iflags |= ITEM_REPORT_OWNER;
1491 if (preserve_gid && F_GID(file) != GID_NONE
1492 - && st->st_gid != F_GID(file))
1493 + && sxp->st.st_gid != F_GID(file))
1494 iflags |= ITEM_REPORT_GROUP;
1495 +#ifdef SUPPORT_ACLS
1496 + if (preserve_acls) {
1497 + if (!ACL_READY(*sxp))
1498 + get_acl(fname, sxp);
1499 + if (set_acl(NULL, file, sxp) == 0)
1500 + iflags |= ITEM_REPORT_ACL;
1504 iflags |= ITEM_IS_NEW;
1506 @@ -783,7 +802,7 @@ static int find_fuzzy(struct file_struct
1507 * handling the file, -1 if no dest-linking occurred, or a non-negative
1508 * value if we found an alternate basis file. */
1509 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1510 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1511 + char *cmpbuf, statx *sxp, int itemizing,
1514 int best_match = -1;
1515 @@ -792,7 +811,7 @@ static int try_dests_reg(struct file_str
1518 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1519 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1520 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1522 switch (match_level) {
1524 @@ -800,16 +819,16 @@ static int try_dests_reg(struct file_str
1528 - if (!unchanged_file(cmpbuf, file, stp))
1529 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1535 - if (!unchanged_attrs(file, stp))
1536 + if (!unchanged_attrs(cmpbuf, file, sxp))
1538 if (always_checksum > 0 && preserve_times
1539 - && cmp_time(stp->st_mtime, file->modtime))
1540 + && cmp_time(sxp->st.st_mtime, file->modtime))
1544 @@ -824,7 +843,7 @@ static int try_dests_reg(struct file_str
1545 if (j != best_match) {
1547 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1548 - if (link_stat(cmpbuf, stp, 0) < 0)
1549 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1553 @@ -834,16 +853,16 @@ static int try_dests_reg(struct file_str
1554 if (!hard_link_one(file, fname, cmpbuf, 1))
1556 if (preserve_hard_links && F_IS_HLINKED(file))
1557 - finish_hard_link(file, fname, stp, itemizing, code, j);
1558 + finish_hard_link(file, fname, &sxp->st, itemizing, code, j);
1559 if (itemizing && (verbose > 1 || stdout_format_has_i > 1)) {
1560 - itemize(file, ndx, 1, stp,
1561 + itemize(fname, file, ndx, 1, sxp,
1562 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
1568 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1569 + itemize(fname, file, ndx, 0, sxp, 0, 0, NULL);
1570 if (verbose > 1 && maybe_ATTRS_REPORT)
1571 rprintf(FCLIENT, "%s is uptodate\n", fname);
1573 @@ -861,7 +880,7 @@ static int try_dests_reg(struct file_str
1577 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1578 + itemize(fname, file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1579 set_file_attrs(fname, file, NULL, 0);
1580 if (maybe_ATTRS_REPORT
1581 && ((!itemizing && verbose && match_level == 2)
1582 @@ -872,7 +891,7 @@ static int try_dests_reg(struct file_str
1584 #ifdef SUPPORT_HARD_LINKS
1585 if (preserve_hard_links && F_IS_HLINKED(file))
1586 - finish_hard_link(file, fname, stp, itemizing, code, -1);
1587 + finish_hard_link(file, fname, &sxp->st, itemizing, code, -1);
1591 @@ -884,7 +903,7 @@ static int try_dests_reg(struct file_str
1592 * handling the file, or -1 if no dest-linking occurred, or a non-negative
1593 * value if we found an alternate basis file. */
1594 static int try_dests_non(struct file_struct *file, char *fname, int ndx,
1595 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1596 + char *cmpbuf, statx *sxp, int itemizing,
1599 char lnk[MAXPATHLEN];
1600 @@ -917,24 +936,24 @@ static int try_dests_non(struct file_str
1603 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1604 - if (link_stat(cmpbuf, stp, 0) < 0)
1605 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1609 - if (!S_ISDIR(stp->st_mode))
1610 + if (!S_ISDIR(sxp->st.st_mode))
1614 - if (!IS_SPECIAL(stp->st_mode))
1615 + if (!IS_SPECIAL(sxp->st.st_mode))
1619 - if (!IS_DEVICE(stp->st_mode))
1620 + if (!IS_DEVICE(sxp->st.st_mode))
1623 #ifdef SUPPORT_LINKS
1625 - if (!S_ISLNK(stp->st_mode))
1626 + if (!S_ISLNK(sxp->st.st_mode))
1630 @@ -949,7 +968,7 @@ static int try_dests_non(struct file_str
1633 devp = F_RDEV_P(file);
1634 - if (stp->st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
1635 + if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
1638 #ifdef SUPPORT_LINKS
1639 @@ -966,7 +985,7 @@ static int try_dests_non(struct file_str
1643 - if (unchanged_attrs(file, stp)) {
1644 + if (unchanged_attrs(cmpbuf, file, sxp)) {
1648 @@ -979,7 +998,7 @@ static int try_dests_non(struct file_str
1649 if (j != best_match) {
1651 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1652 - if (link_stat(cmpbuf, stp, 0) < 0)
1653 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1657 @@ -1010,7 +1029,7 @@ static int try_dests_non(struct file_str
1659 + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
1660 char *lp = match_level == 3 ? "" : NULL;
1661 - itemize(file, ndx, 0, stp, chg + ITEM_MATCHED, 0, lp);
1662 + itemize(fname, file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp);
1664 if (verbose > 1 && maybe_ATTRS_REPORT) {
1665 rprintf(FCLIENT, "%s%s is uptodate\n",
1666 @@ -1023,6 +1042,7 @@ static int try_dests_non(struct file_str
1669 static int phase = 0;
1670 +static int dflt_perms;
1672 /* Acts on the indicated item in cur_flist whose name is fname. If a dir,
1673 * make sure it exists, and has the right permissions/timestamp info. For
1674 @@ -1043,7 +1063,8 @@ static void recv_generator(char *fname,
1675 static int need_fuzzy_dirlist = 0;
1676 struct file_struct *fuzzy_file = NULL;
1677 int fd = -1, f_copy = -1;
1678 - STRUCT_STAT st, real_st, partial_st;
1679 + statx sx, real_sx;
1680 + STRUCT_STAT partial_st;
1681 struct file_struct *back_file = NULL;
1682 int statret, real_ret, stat_errno;
1683 char *fnamecmp, *partialptr, *backupptr = NULL;
1684 @@ -1088,6 +1109,9 @@ static void recv_generator(char *fname,
1688 +#ifdef SUPPORT_ACLS
1689 + sx.acc_acl = sx.def_acl = NULL;
1692 if (fuzzy_dirlist) {
1693 flist_free(fuzzy_dirlist);
1694 @@ -1100,7 +1124,7 @@ static void recv_generator(char *fname,
1695 const char *dn = file->dirname ? file->dirname : ".";
1696 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1697 if (relative_paths && !implied_dirs
1698 - && do_stat(dn, &st) < 0
1699 + && do_stat(dn, &sx.st) < 0
1700 && create_directory_path(fname) < 0) {
1701 rsyserr(FERROR, errno,
1702 "recv_generator: mkdir %s failed",
1703 @@ -1112,6 +1136,10 @@ static void recv_generator(char *fname,
1706 need_fuzzy_dirlist = 1;
1707 +#ifdef SUPPORT_ACLS
1708 + if (!preserve_perms)
1709 + dflt_perms = default_perms_for_dir(dn);
1712 parent_dirname = dn;
1714 @@ -1121,7 +1149,7 @@ static void recv_generator(char *fname,
1715 need_fuzzy_dirlist = 0;
1718 - statret = link_stat(fname, &st,
1719 + statret = link_stat(fname, &sx.st,
1720 keep_dirlinks && S_ISDIR(file->mode));
1723 @@ -1149,8 +1177,8 @@ static void recv_generator(char *fname,
1724 * file of that name and it is *not* a directory, then
1725 * we need to delete it. If it doesn't exist, then
1726 * (perhaps recursively) create it. */
1727 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1728 - if (delete_item(fname, st.st_mode, "directory", del_opts) != 0)
1729 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1730 + if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0)
1734 @@ -1159,18 +1187,18 @@ static void recv_generator(char *fname,
1741 if (*fname == '.' && fname[1] == '\0')
1745 if (!preserve_perms) { /* See comment in non-dir code below. */
1746 - file->mode = dest_mode(file->mode, st.st_mode,
1748 + file->mode = dest_mode(file->mode, sx.st.st_mode,
1749 + dflt_perms, statret == 0);
1751 if (statret != 0 && basis_dir[0] != NULL) {
1752 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1753 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1757 @@ -1179,7 +1207,7 @@ static void recv_generator(char *fname,
1760 if (itemizing && f_out != -1) {
1761 - itemize(file, ndx, statret, &st,
1762 + itemize(fname, file, ndx, statret, &sx,
1763 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1765 if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1766 @@ -1193,38 +1221,39 @@ static void recv_generator(char *fname,
1767 "*** Skipping any contents from this failed directory ***\n");
1768 missing_below = F_DEPTH(file);
1769 file->flags |= FLAG_MISSING_DIR;
1774 - if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0)
1775 + if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, 0)
1776 && verbose && code != FNONE && f_out != -1)
1777 rprintf(code, "%s/\n", fname);
1778 if (real_ret != 0 && one_file_system)
1779 - real_st.st_dev = filesystem_dev;
1780 + real_sx.st.st_dev = filesystem_dev;
1782 if (one_file_system) {
1783 uint32 *devp = F_DIRDEV_P(file);
1784 - DEV_MAJOR(devp) = major(real_st.st_dev);
1785 - DEV_MINOR(devp) = minor(real_st.st_dev);
1786 + DEV_MAJOR(devp) = major(real_sx.st.st_dev);
1787 + DEV_MINOR(devp) = minor(real_sx.st.st_dev);
1790 else if (delete_during && f_out != -1 && !phase && dry_run < 2
1791 && (file->flags & FLAG_XFER_DIR))
1792 - delete_in_dir(cur_flist, fname, file, &real_st.st_dev);
1794 + delete_in_dir(cur_flist, fname, file, &real_sx.st.st_dev);
1798 /* If we're not preserving permissions, change the file-list's
1799 * mode based on the local permissions and some heuristics. */
1800 if (!preserve_perms) {
1801 - int exists = statret == 0 && !S_ISDIR(st.st_mode);
1802 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1803 + int exists = statret == 0 && !S_ISDIR(sx.st.st_mode);
1804 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1808 #ifdef SUPPORT_HARD_LINKS
1809 if (preserve_hard_links && F_HLINK_NOT_FIRST(file)
1810 - && hard_link_check(file, ndx, fname, statret, &st, itemizing, code))
1812 + && hard_link_check(file, ndx, fname, statret, &sx, itemizing, code))
1816 if (preserve_links && S_ISLNK(file->mode)) {
1817 @@ -1244,28 +1273,28 @@ static void recv_generator(char *fname,
1818 char lnk[MAXPATHLEN];
1821 - if (!S_ISLNK(st.st_mode))
1822 + if (!S_ISLNK(sx.st.st_mode))
1824 else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0
1825 && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
1826 /* The link is pointing to the right place. */
1828 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1829 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1830 + itemize(fname, file, ndx, 0, &sx, 0, 0, NULL);
1831 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1832 #ifdef SUPPORT_HARD_LINKS
1833 if (preserve_hard_links && F_IS_HLINKED(file))
1834 - finish_hard_link(file, fname, &st, itemizing, code, -1);
1835 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
1837 if (remove_source_files == 1)
1838 goto return_with_success;
1842 /* Not the right symlink (or not a symlink), so
1844 - if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0)
1846 + if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0)
1848 } else if (basis_dir[0] != NULL) {
1849 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1850 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1853 #ifndef CAN_HARDLINK_SYMLINK
1854 @@ -1274,7 +1303,7 @@ static void recv_generator(char *fname,
1863 @@ -1282,7 +1311,7 @@ static void recv_generator(char *fname,
1865 #ifdef SUPPORT_HARD_LINKS
1866 if (preserve_hard_links && F_HLINK_NOT_LAST(file))
1870 if (do_symlink(sl, fname) != 0) {
1871 rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed",
1872 @@ -1290,7 +1319,7 @@ static void recv_generator(char *fname,
1874 set_file_attrs(fname, file, NULL, 0);
1876 - itemize(file, ndx, statret, &st,
1877 + itemize(fname, file, ndx, statret, &sx,
1878 ITEM_LOCAL_CHANGE, 0, NULL);
1880 if (code != FNONE && verbose)
1881 @@ -1306,7 +1335,7 @@ static void recv_generator(char *fname,
1882 goto return_with_success;
1889 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1890 @@ -1316,33 +1345,33 @@ static void recv_generator(char *fname,
1893 if (IS_DEVICE(file->mode)) {
1894 - if (!IS_DEVICE(st.st_mode))
1895 + if (!IS_DEVICE(sx.st.st_mode))
1899 - if (!IS_SPECIAL(st.st_mode))
1900 + if (!IS_SPECIAL(sx.st.st_mode))
1905 - && BITS_EQUAL(st.st_mode, file->mode, _S_IFMT)
1906 - && st.st_rdev == rdev) {
1907 + && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT)
1908 + && sx.st.st_rdev == rdev) {
1909 /* The device or special file is identical. */
1911 - itemize(file, ndx, 0, &st, 0, 0, NULL);
1912 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1913 + itemize(fname, file, ndx, 0, &sx, 0, 0, NULL);
1914 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1915 #ifdef SUPPORT_HARD_LINKS
1916 if (preserve_hard_links && F_IS_HLINKED(file))
1917 - finish_hard_link(file, fname, &st, itemizing, code, -1);
1918 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
1920 if (remove_source_files == 1)
1921 goto return_with_success;
1925 - if (delete_item(fname, st.st_mode, t, del_opts) != 0)
1927 + if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0)
1929 } else if (basis_dir[0] != NULL) {
1930 - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st,
1931 + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
1934 #ifndef CAN_HARDLINK_SPECIAL
1935 @@ -1351,7 +1380,7 @@ static void recv_generator(char *fname,
1944 @@ -1359,7 +1388,7 @@ static void recv_generator(char *fname,
1946 #ifdef SUPPORT_HARD_LINKS
1947 if (preserve_hard_links && F_HLINK_NOT_LAST(file))
1952 rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n",
1953 @@ -1372,7 +1401,7 @@ static void recv_generator(char *fname,
1955 set_file_attrs(fname, file, NULL, 0);
1957 - itemize(file, ndx, statret, &st,
1958 + itemize(fname, file, ndx, statret, &sx,
1959 ITEM_LOCAL_CHANGE, 0, NULL);
1961 if (code != FNONE && verbose)
1962 @@ -1384,14 +1413,14 @@ static void recv_generator(char *fname,
1963 if (remove_source_files == 1)
1964 goto return_with_success;
1970 if (!S_ISREG(file->mode)) {
1972 fname = f_name(file, NULL);
1973 rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname);
1978 if (max_size > 0 && F_LENGTH(file) > max_size) {
1979 @@ -1400,7 +1429,7 @@ static void recv_generator(char *fname,
1980 fname = f_name(file, NULL);
1981 rprintf(FINFO, "%s is over max-size\n", fname);
1986 if (min_size > 0 && F_LENGTH(file) < min_size) {
1988 @@ -1408,39 +1437,39 @@ static void recv_generator(char *fname,
1989 fname = f_name(file, NULL);
1990 rprintf(FINFO, "%s is under min-size\n", fname);
1996 if (ignore_existing > 0 && statret == 0) {
1998 rprintf(FINFO, "%s exists\n", fname);
2003 if (update_only > 0 && statret == 0
2004 - && cmp_time(st.st_mtime, file->modtime) > 0) {
2005 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
2007 rprintf(FINFO, "%s is newer\n", fname);
2013 fnamecmp_type = FNAMECMP_FNAME;
2015 - if (statret == 0 && !S_ISREG(st.st_mode)) {
2016 - if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0)
2018 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
2019 + if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0)
2022 stat_errno = ENOENT;
2025 if (statret != 0 && basis_dir[0] != NULL) {
2026 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
2027 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
2030 if (remove_source_files == 1)
2031 goto return_with_success;
2036 fnamecmp = fnamecmpbuf;
2037 @@ -1450,7 +1479,7 @@ static void recv_generator(char *fname,
2044 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
2045 && link_stat(partialptr, &partial_st, 0) == 0
2046 @@ -1469,7 +1498,7 @@ static void recv_generator(char *fname,
2047 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
2048 fname, fnamecmpbuf);
2050 - st.st_size = F_LENGTH(fuzzy_file);
2051 + sx.st.st_size = F_LENGTH(fuzzy_file);
2053 fnamecmp = fnamecmpbuf;
2054 fnamecmp_type = FNAMECMP_FUZZY;
2055 @@ -1479,45 +1508,45 @@ static void recv_generator(char *fname,
2057 #ifdef SUPPORT_HARD_LINKS
2058 if (preserve_hard_links && F_HLINK_NOT_LAST(file))
2062 if (stat_errno == ENOENT)
2064 rsyserr(FERROR, stat_errno, "recv_generator: failed to stat %s",
2070 - if (append_mode > 0 && st.st_size > F_LENGTH(file))
2072 + if (append_mode > 0 && sx.st.st_size > F_LENGTH(file))
2075 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
2077 else if (fnamecmp_type == FNAMECMP_FUZZY)
2079 - else if (unchanged_file(fnamecmp, file, &st)) {
2080 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
2082 do_unlink(partialptr);
2083 handle_partial_dir(partialptr, PDIR_DELETE);
2086 - itemize(file, ndx, statret, &st, 0, 0, NULL);
2087 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
2088 + itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL);
2089 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
2090 #ifdef SUPPORT_HARD_LINKS
2091 if (preserve_hard_links && F_IS_HLINKED(file))
2092 - finish_hard_link(file, fname, &st, itemizing, code, -1);
2093 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
2095 if (remove_source_files != 1)
2098 return_with_success:
2100 send_msg_int(MSG_SUCCESS, ndx);
2108 + sx.st = partial_st;
2109 fnamecmp = partialptr;
2110 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2112 @@ -1542,7 +1571,7 @@ static void recv_generator(char *fname,
2113 /* pretend the file didn't exist */
2114 #ifdef SUPPORT_HARD_LINKS
2115 if (preserve_hard_links && F_HLINK_NOT_LAST(file))
2119 statret = real_ret = -1;
2121 @@ -1551,7 +1580,7 @@ static void recv_generator(char *fname,
2122 if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) {
2123 if (!(backupptr = get_backup_name(fname))) {
2128 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2130 @@ -1562,7 +1591,7 @@ static void recv_generator(char *fname,
2131 full_fname(backupptr));
2132 unmake_file(back_file);
2137 if ((f_copy = do_open(backupptr,
2138 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2139 @@ -1570,14 +1599,14 @@ static void recv_generator(char *fname,
2140 full_fname(backupptr));
2141 unmake_file(back_file);
2146 fnamecmp_type = FNAMECMP_BACKUP;
2150 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2151 - fnamecmp, (double)st.st_size);
2152 + fnamecmp, (double)sx.st.st_size);
2156 @@ -1601,26 +1630,30 @@ static void recv_generator(char *fname,
2157 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2158 if (fnamecmp_type == FNAMECMP_FUZZY)
2159 iflags |= ITEM_XNAME_FOLLOWS;
2160 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2161 + itemize(fnamecmp, file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2162 fuzzy_file ? fuzzy_file->basename : NULL);
2163 +#ifdef SUPPORT_ACLS
2164 + if (preserve_acls)
2165 + free_acl(&real_sx);
2170 #ifdef SUPPORT_HARD_LINKS
2171 if (preserve_hard_links && F_IS_HLINKED(file))
2172 - finish_hard_link(file, fname, &st, itemizing, code, -1);
2173 + finish_hard_link(file, fname, &sx.st, itemizing, code, -1);
2182 if (statret != 0 || whole_file) {
2183 write_sum_head(f_out, NULL);
2188 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2189 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2193 @@ -1633,6 +1666,13 @@ static void recv_generator(char *fname,
2199 +#ifdef SUPPORT_ACLS
2200 + if (preserve_acls)
2206 static void touch_up_dirs(struct file_list *flist, int ndx)
2207 @@ -1803,6 +1843,8 @@ void generate_files(int f_out, const cha
2208 * notice that and let us know via the redo pipe (or its closing). */
2211 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2214 if (inc_recurse && delete_during && cur_flist->ndx_start) {
2215 struct file_struct *fp = dir_flist->files[cur_flist->parent_ndx];
2218 @@ -26,6 +26,7 @@ extern int verbose;
2220 extern int do_xfers;
2221 extern int link_dest;
2222 +extern int preserve_acls;
2223 extern int make_backups;
2224 extern int protocol_version;
2225 extern int remove_source_files;
2226 @@ -267,15 +268,15 @@ void match_hard_links(void)
2229 static int maybe_hard_link(struct file_struct *file, int ndx,
2230 - const char *fname, int statret, STRUCT_STAT *stp,
2231 + const char *fname, int statret, statx *sxp,
2232 const char *oldname, STRUCT_STAT *old_stp,
2233 const char *realname, int itemizing, enum logcode code)
2236 - if (stp->st_dev == old_stp->st_dev
2237 - && stp->st_ino == old_stp->st_ino) {
2238 + if (sxp->st.st_dev == old_stp->st_dev
2239 + && sxp->st.st_ino == old_stp->st_ino) {
2241 - itemize(file, ndx, statret, stp,
2242 + itemize(fname, file, ndx, statret, sxp,
2243 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2246 @@ -296,7 +297,7 @@ static int maybe_hard_link(struct file_s
2248 if (hard_link_one(file, fname, oldname, 0)) {
2250 - itemize(file, ndx, statret, stp,
2251 + itemize(fname, file, ndx, statret, sxp,
2252 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2255 @@ -310,7 +311,7 @@ static int maybe_hard_link(struct file_s
2256 /* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not. Returns:
2257 * 0 = process the file, 1 = skip the file, -1 = error occurred. */
2258 int hard_link_check(struct file_struct *file, int ndx, const char *fname,
2259 - int statret, STRUCT_STAT *stp, int itemizing,
2260 + int statret, statx *sxp, int itemizing,
2263 STRUCT_STAT prev_st;
2264 @@ -361,18 +362,20 @@ int hard_link_check(struct file_struct *
2265 if (statret < 0 && basis_dir[0] != NULL) {
2266 /* If we match an alt-dest item, we don't output this as a change. */
2267 char cmpbuf[MAXPATHLEN];
2268 - STRUCT_STAT alt_st;
2271 +#ifdef SUPPORT_ACLS
2272 + alt_sx.acc_acl = alt_sx.def_acl = NULL;
2275 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
2276 - if (link_stat(cmpbuf, &alt_st, 0) < 0)
2277 + if (link_stat(cmpbuf, &alt_sx.st, 0) < 0)
2280 - if (prev_st.st_dev != alt_st.st_dev
2281 - || prev_st.st_ino != alt_st.st_ino)
2282 + if (prev_st.st_dev != alt_sx.st.st_dev
2283 + || prev_st.st_ino != alt_sx.st.st_ino)
2287 if (verbose < 2 || !stdout_format_has_i) {
2290 @@ -381,16 +384,32 @@ int hard_link_check(struct file_struct *
2294 - if (!unchanged_file(cmpbuf, file, &alt_st))
2295 + if (!unchanged_file(cmpbuf, file, &alt_sx.st))
2299 - if (unchanged_attrs(file, &alt_st))
2300 + if (unchanged_attrs(cmpbuf, file, &alt_sx))
2302 } while (basis_dir[++j] != NULL);
2303 + if (statret == 1) {
2304 + sxp->st = alt_sx.st;
2305 +#ifdef SUPPORT_ACLS
2306 + if (preserve_acls) {
2307 + if (!ACL_READY(*sxp))
2308 + get_acl(cmpbuf, sxp);
2310 + sxp->acc_acl = alt_sx.acc_acl;
2311 + sxp->def_acl = alt_sx.def_acl;
2316 +#ifdef SUPPORT_ACLS
2317 + else if (preserve_acls)
2318 + free_acl(&alt_sx);
2322 - if (maybe_hard_link(file, ndx, fname, statret, stp, prev_name, &prev_st,
2323 + if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st,
2324 realname, itemizing, code) < 0)
2327 @@ -425,7 +444,8 @@ void finish_hard_link(struct file_struct
2328 STRUCT_STAT *stp, int itemizing, enum logcode code,
2331 - STRUCT_STAT st, prev_st;
2334 char alt_name[MAXPATHLEN], *prev_name;
2335 const char *our_name;
2336 int prev_statret, ndx, prev_ndx = F_HL_PREV(file);
2337 @@ -449,14 +469,24 @@ void finish_hard_link(struct file_struct
2341 +#ifdef SUPPORT_ACLS
2342 + prev_sx.acc_acl = prev_sx.def_acl = NULL;
2345 while ((ndx = prev_ndx) >= 0) {
2348 file->flags = (file->flags & ~FLAG_HLINK_FIRST) | FLAG_HLINK_DONE;
2349 prev_ndx = F_HL_PREV(file);
2350 prev_name = f_name(file, NULL);
2351 - prev_statret = link_stat(prev_name, &prev_st, 0);
2352 - if (maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_st,
2353 - our_name, stp, fname, itemizing, code) < 0)
2354 + prev_statret = link_stat(prev_name, &prev_sx.st, 0);
2355 + val = maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_sx,
2356 + our_name, stp, fname, itemizing, code);
2357 +#ifdef SUPPORT_ACLS
2358 + if (preserve_acls)
2359 + free_acl(&prev_sx);
2363 if (remove_source_files == 1 && do_xfers)
2364 send_msg_int(MSG_SUCCESS, ndx);
2365 --- old/lib/sysacls.c
2366 +++ new/lib/sysacls.c
2369 + Unix SMB/CIFS implementation.
2370 + Samba system utilities for ACL support.
2371 + Copyright (C) Jeremy Allison 2000.
2373 + This program is free software; you can redistribute it and/or modify
2374 + it under the terms of the GNU General Public License as published by
2375 + the Free Software Foundation; either version 2 of the License, or
2376 + (at your option) any later version.
2378 + This program is distributed in the hope that it will be useful,
2379 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2380 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2381 + GNU General Public License for more details.
2383 + You should have received a copy of the GNU General Public License
2384 + along with this program; if not, write to the Free Software
2385 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2389 +#include "sysacls.h" /****** ADDED ******/
2391 +#ifdef SUPPORT_ACLS
2393 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2399 +void SAFE_FREE(void *mem)
2405 +char *uidtoname(uid_t uid)
2407 + static char idbuf[12];
2408 + struct passwd *pw;
2410 + if ((pw = getpwuid(uid)) == NULL) {
2411 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2414 + return pw->pw_name;
2416 +/****** EXTRAS -- END ******/
2419 + This file wraps all differing system ACL interfaces into a consistent
2420 + one based on the POSIX interface. It also returns the correct errors
2421 + for older UNIX systems that don't support ACLs.
2423 + The interfaces that each ACL implementation must support are as follows :
2425 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2426 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2427 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2428 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2429 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2430 + SMB_ACL_T sys_acl_get_fd(int fd)
2431 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2432 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2433 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2434 + SMB_ACL_T sys_acl_init( int count)
2435 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2436 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2437 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2438 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2439 + int sys_acl_valid( SMB_ACL_T theacl )
2440 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2441 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2442 + int sys_acl_delete_def_file(const char *path)
2444 + This next one is not POSIX complient - but we *have* to have it !
2445 + More POSIX braindamage.
2447 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2449 + The generic POSIX free is the following call. We split this into
2450 + several different free functions as we may need to add tag info
2451 + to structures when emulating the POSIX interface.
2453 + int sys_acl_free( void *obj_p)
2455 + The calls we actually use are :
2457 + int sys_acl_free_text(char *text) - free acl_to_text
2458 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2459 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2463 +#if defined(HAVE_POSIX_ACLS)
2465 +/* Identity mapping - easy. */
2467 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2469 + return acl_get_entry( the_acl, entry_id, entry_p);
2472 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2474 + return acl_get_tag_type( entry_d, tag_type_p);
2477 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2479 + return acl_get_permset( entry_d, permset_p);
2482 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2484 + return acl_get_qualifier( entry_d);
2487 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2489 + return acl_get_file( path_p, type);
2492 +SMB_ACL_T sys_acl_get_fd(int fd)
2494 + return acl_get_fd(fd);
2497 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2499 + return acl_clear_perms(permset);
2502 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2504 + return acl_add_perm(permset, perm);
2507 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2509 +#if defined(HAVE_ACL_GET_PERM_NP)
2511 + * Required for TrustedBSD-based ACL implementations where
2512 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2515 + return acl_get_perm_np(permset, perm);
2517 + return acl_get_perm(permset, perm);
2521 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2523 + return acl_to_text( the_acl, plen);
2526 +SMB_ACL_T sys_acl_init( int count)
2528 + return acl_init(count);
2531 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2533 + return acl_create_entry(pacl, pentry);
2536 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2538 + return acl_set_tag_type(entry, tagtype);
2541 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2543 + return acl_set_qualifier(entry, qual);
2546 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2548 + return acl_set_permset(entry, permset);
2551 +int sys_acl_valid( SMB_ACL_T theacl )
2553 + return acl_valid(theacl);
2556 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2558 + return acl_set_file(name, acltype, theacl);
2561 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2563 + return acl_set_fd(fd, theacl);
2566 +int sys_acl_delete_def_file(const char *name)
2568 + return acl_delete_def_file(name);
2571 +int sys_acl_free_text(char *text)
2573 + return acl_free(text);
2576 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2578 + return acl_free(the_acl);
2581 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2583 + return acl_free(qual);
2586 +#elif defined(HAVE_TRU64_ACLS)
2588 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2589 + * is based on Draft 13 of the POSIX spec which is
2590 + * slightly different from the Draft 16 interface.
2592 + * Also, some of the permset manipulation functions
2593 + * such as acl_clear_perm() and acl_add_perm() appear
2594 + * to be broken on Tru64 so we have to manipulate
2595 + * the permission bits in the permset directly.
2597 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2599 + SMB_ACL_ENTRY_T entry;
2601 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2606 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2611 + return errno ? -1 : 0;
2614 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2616 + return acl_get_tag_type( entry_d, tag_type_p);
2619 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2621 + return acl_get_permset( entry_d, permset_p);
2624 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2626 + return acl_get_qualifier( entry_d);
2629 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2631 + return acl_get_file((char *)path_p, type);
2634 +SMB_ACL_T sys_acl_get_fd(int fd)
2636 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2639 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2641 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2646 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2648 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2653 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2658 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2660 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2663 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2665 + return acl_to_text( the_acl, plen);
2668 +SMB_ACL_T sys_acl_init( int count)
2670 + return acl_init(count);
2673 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2675 + SMB_ACL_ENTRY_T entry;
2677 + if ((entry = acl_create_entry(pacl)) == NULL) {
2685 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2687 + return acl_set_tag_type(entry, tagtype);
2690 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2692 + return acl_set_qualifier(entry, qual);
2695 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2697 + return acl_set_permset(entry, permset);
2700 +int sys_acl_valid( SMB_ACL_T theacl )
2702 + acl_entry_t entry;
2704 + return acl_valid(theacl, &entry);
2707 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2709 + return acl_set_file((char *)name, acltype, theacl);
2712 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2714 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2717 +int sys_acl_delete_def_file(const char *name)
2719 + return acl_delete_def_file((char *)name);
2722 +int sys_acl_free_text(char *text)
2725 + * (void) cast and explicit return 0 are for DEC UNIX
2726 + * which just #defines acl_free_text() to be free()
2728 + (void) acl_free_text(text);
2732 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2734 + return acl_free(the_acl);
2737 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2739 + return acl_free_qualifier(qual, tagtype);
2742 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2745 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2746 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2750 + * Note that while this code implements sufficient functionality
2751 + * to support the sys_acl_* interfaces it does not provide all
2752 + * of the semantics of the POSIX ACL interfaces.
2754 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2755 + * from a call to sys_acl_get_entry() should not be assumed to be
2756 + * valid after calling any of the following functions, which may
2757 + * reorder the entries in the ACL.
2760 + * sys_acl_set_file()
2761 + * sys_acl_set_fd()
2765 + * The only difference between Solaris and UnixWare / OpenUNIX is
2766 + * that the #defines for the ACL operations have different names
2768 +#if defined(HAVE_UNIXWARE_ACLS)
2770 +#define SETACL ACL_SET
2771 +#define GETACL ACL_GET
2772 +#define GETACLCNT ACL_CNT
2777 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2779 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2784 + if (entry_p == NULL) {
2789 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2793 + if (acl_d->next < 0) {
2798 + if (acl_d->next >= acl_d->count) {
2802 + *entry_p = &acl_d->acl[acl_d->next++];
2807 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2809 + *type_p = entry_d->a_type;
2814 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2816 + *permset_p = &entry_d->a_perm;
2821 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2823 + if (entry_d->a_type != SMB_ACL_USER
2824 + && entry_d->a_type != SMB_ACL_GROUP) {
2829 + return &entry_d->a_id;
2833 + * There is no way of knowing what size the ACL returned by
2834 + * GETACL will be unless you first call GETACLCNT which means
2835 + * making an additional system call.
2837 + * In the hope of avoiding the cost of the additional system
2838 + * call in most cases, we initially allocate enough space for
2839 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2840 + * be too small then we use GETACLCNT to find out the actual
2841 + * size, reallocate the ACL buffer, and then call GETACL again.
2844 +#define INITIAL_ACL_SIZE 16
2846 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2849 + int count; /* # of ACL entries allocated */
2850 + int naccess; /* # of access ACL entries */
2851 + int ndefault; /* # of default ACL entries */
2853 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2858 + count = INITIAL_ACL_SIZE;
2859 + if ((acl_d = sys_acl_init(count)) == NULL) {
2864 + * If there isn't enough space for the ACL entries we use
2865 + * GETACLCNT to determine the actual number of ACL entries
2866 + * reallocate and try again. This is in a loop because it
2867 + * is possible that someone else could modify the ACL and
2868 + * increase the number of entries between the call to
2869 + * GETACLCNT and the call to GETACL.
2871 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2872 + && errno == ENOSPC) {
2874 + sys_acl_free_acl(acl_d);
2876 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2880 + if ((acl_d = sys_acl_init(count)) == NULL) {
2886 + sys_acl_free_acl(acl_d);
2891 + * calculate the number of access and default ACL entries
2893 + * Note: we assume that the acl() system call returned a
2894 + * well formed ACL which is sorted so that all of the
2895 + * access ACL entries preceed any default ACL entries
2897 + for (naccess = 0; naccess < count; naccess++) {
2898 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2901 + ndefault = count - naccess;
2904 + * if the caller wants the default ACL we have to copy
2905 + * the entries down to the start of the acl[] buffer
2906 + * and mask out the ACL_DEFAULT flag from the type field
2908 + if (type == SMB_ACL_TYPE_DEFAULT) {
2911 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2912 + acl_d->acl[i] = acl_d->acl[j];
2913 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2916 + acl_d->count = ndefault;
2918 + acl_d->count = naccess;
2924 +SMB_ACL_T sys_acl_get_fd(int fd)
2927 + int count; /* # of ACL entries allocated */
2928 + int naccess; /* # of access ACL entries */
2930 + count = INITIAL_ACL_SIZE;
2931 + if ((acl_d = sys_acl_init(count)) == NULL) {
2935 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2936 + && errno == ENOSPC) {
2938 + sys_acl_free_acl(acl_d);
2940 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2944 + if ((acl_d = sys_acl_init(count)) == NULL) {
2950 + sys_acl_free_acl(acl_d);
2955 + * calculate the number of access ACL entries
2957 + for (naccess = 0; naccess < count; naccess++) {
2958 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2962 + acl_d->count = naccess;
2967 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2974 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2976 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2977 + && perm != SMB_ACL_EXECUTE) {
2982 + if (permset_d == NULL) {
2987 + *permset_d |= perm;
2992 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2994 + return *permset_d & perm;
2997 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3004 + * use an initial estimate of 20 bytes per ACL entry
3005 + * when allocating memory for the text representation
3009 + maxlen = 20 * acl_d->count;
3010 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3015 + for (i = 0; i < acl_d->count; i++) {
3016 + struct acl *ap = &acl_d->acl[i];
3025 + switch (ap->a_type) {
3027 + * for debugging purposes it's probably more
3028 + * useful to dump unknown tag types rather
3029 + * than just returning an error
3032 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3035 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3040 + case SMB_ACL_USER:
3041 + id = uidtoname(ap->a_id);
3042 + case SMB_ACL_USER_OBJ:
3046 + case SMB_ACL_GROUP:
3047 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3048 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3054 + case SMB_ACL_GROUP_OBJ:
3058 + case SMB_ACL_OTHER:
3062 + case SMB_ACL_MASK:
3068 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3069 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3070 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3073 + /* <tag> : <qualifier> : rwx \n \0 */
3074 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3077 + * If this entry would overflow the buffer
3078 + * allocate enough additional memory for this
3079 + * entry and an estimate of another 20 bytes
3080 + * for each entry still to be processed
3082 + if ((len + nbytes) > maxlen) {
3083 + char *oldtext = text;
3085 + maxlen += nbytes + 20 * (acl_d->count - i);
3087 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3088 + SAFE_FREE(oldtext);
3094 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3095 + len += nbytes - 1;
3104 +SMB_ACL_T sys_acl_init(int count)
3114 + * note that since the definition of the structure pointed
3115 + * to by the SMB_ACL_T includes the first element of the
3116 + * acl[] array, this actually allocates an ACL with room
3117 + * for (count+1) entries
3119 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3124 + a->size = count + 1;
3132 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3135 + SMB_ACL_ENTRY_T entry_d;
3137 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3142 + if (acl_d->count >= acl_d->size) {
3147 + entry_d = &acl_d->acl[acl_d->count++];
3148 + entry_d->a_type = 0;
3149 + entry_d->a_id = -1;
3150 + entry_d->a_perm = 0;
3151 + *entry_p = entry_d;
3156 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3158 + switch (tag_type) {
3159 + case SMB_ACL_USER:
3160 + case SMB_ACL_USER_OBJ:
3161 + case SMB_ACL_GROUP:
3162 + case SMB_ACL_GROUP_OBJ:
3163 + case SMB_ACL_OTHER:
3164 + case SMB_ACL_MASK:
3165 + entry_d->a_type = tag_type;
3175 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3177 + if (entry_d->a_type != SMB_ACL_GROUP
3178 + && entry_d->a_type != SMB_ACL_USER) {
3183 + entry_d->a_id = *((id_t *)qual_p);
3188 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3190 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3194 + entry_d->a_perm = *permset_d;
3200 + * sort the ACL and check it for validity
3202 + * if it's a minimal ACL with only 4 entries then we
3203 + * need to recalculate the mask permissions to make
3204 + * sure that they are the same as the GROUP_OBJ
3205 + * permissions as required by the UnixWare acl() system call.
3207 + * (note: since POSIX allows minimal ACLs which only contain
3208 + * 3 entries - ie there is no mask entry - we should, in theory,
3209 + * check for this and add a mask entry if necessary - however
3210 + * we "know" that the caller of this interface always specifies
3211 + * a mask so, in practice "this never happens" (tm) - if it *does*
3212 + * happen aclsort() will fail and return an error and someone will
3213 + * have to fix it ...)
3216 +static int acl_sort(SMB_ACL_T acl_d)
3218 + int fixmask = (acl_d->count <= 4);
3220 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3227 +int sys_acl_valid(SMB_ACL_T acl_d)
3229 + return acl_sort(acl_d);
3232 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3235 + struct acl *acl_p;
3237 + struct acl *acl_buf = NULL;
3240 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3245 + if (acl_sort(acl_d) != 0) {
3249 + acl_p = &acl_d->acl[0];
3250 + acl_count = acl_d->count;
3253 + * if it's a directory there is extra work to do
3254 + * since the acl() system call will replace both
3255 + * the access ACLs and the default ACLs (if any)
3257 + if (stat(name, &s) != 0) {
3260 + if (S_ISDIR(s.st_mode)) {
3261 + SMB_ACL_T acc_acl;
3262 + SMB_ACL_T def_acl;
3263 + SMB_ACL_T tmp_acl;
3266 + if (type == SMB_ACL_TYPE_ACCESS) {
3268 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3272 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3275 + if (tmp_acl == NULL) {
3280 + * allocate a temporary buffer for the complete ACL
3282 + acl_count = acc_acl->count + def_acl->count;
3283 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3285 + if (acl_buf == NULL) {
3286 + sys_acl_free_acl(tmp_acl);
3292 + * copy the access control and default entries into the buffer
3294 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3295 + acc_acl->count * sizeof(acl_buf[0]));
3297 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3298 + def_acl->count * sizeof(acl_buf[0]));
3301 + * set the ACL_DEFAULT flag on the default entries
3303 + for (i = acc_acl->count; i < acl_count; i++) {
3304 + acl_buf[i].a_type |= ACL_DEFAULT;
3307 + sys_acl_free_acl(tmp_acl);
3309 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3314 + ret = acl(name, SETACL, acl_count, acl_p);
3316 + SAFE_FREE(acl_buf);
3321 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3323 + if (acl_sort(acl_d) != 0) {
3327 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3330 +int sys_acl_delete_def_file(const char *path)
3336 + * fetching the access ACL and rewriting it has
3337 + * the effect of deleting the default ACL
3339 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3343 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3345 + sys_acl_free_acl(acl_d);
3350 +int sys_acl_free_text(char *text)
3356 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3362 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3367 +#elif defined(HAVE_HPUX_ACLS)
3371 + * Based on the Solaris/SCO code - with modifications.
3375 + * Note that while this code implements sufficient functionality
3376 + * to support the sys_acl_* interfaces it does not provide all
3377 + * of the semantics of the POSIX ACL interfaces.
3379 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3380 + * from a call to sys_acl_get_entry() should not be assumed to be
3381 + * valid after calling any of the following functions, which may
3382 + * reorder the entries in the ACL.
3385 + * sys_acl_set_file()
3386 + * sys_acl_set_fd()
3389 +/* This checks if the POSIX ACL system call is defined */
3390 +/* which basically corresponds to whether JFS 3.3 or */
3391 +/* higher is installed. If acl() was called when it */
3392 +/* isn't defined, it causes the process to core dump */
3393 +/* so it is important to check this and avoid acl() */
3394 +/* calls if it isn't there. */
3396 +static BOOL hpux_acl_call_presence(void)
3399 + shl_t handle = NULL;
3402 + static BOOL already_checked=0;
3404 + if(already_checked)
3408 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3410 + if(ret_val != 0) {
3411 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3412 + ret_val, errno, strerror(errno)));
3413 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3417 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3419 + already_checked = True;
3423 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3425 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3430 + if (entry_p == NULL) {
3435 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3439 + if (acl_d->next < 0) {
3444 + if (acl_d->next >= acl_d->count) {
3448 + *entry_p = &acl_d->acl[acl_d->next++];
3453 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3455 + *type_p = entry_d->a_type;
3460 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3462 + *permset_p = &entry_d->a_perm;
3467 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3469 + if (entry_d->a_type != SMB_ACL_USER
3470 + && entry_d->a_type != SMB_ACL_GROUP) {
3475 + return &entry_d->a_id;
3479 + * There is no way of knowing what size the ACL returned by
3480 + * ACL_GET will be unless you first call ACL_CNT which means
3481 + * making an additional system call.
3483 + * In the hope of avoiding the cost of the additional system
3484 + * call in most cases, we initially allocate enough space for
3485 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3486 + * be too small then we use ACL_CNT to find out the actual
3487 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3490 +#define INITIAL_ACL_SIZE 16
3492 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3495 + int count; /* # of ACL entries allocated */
3496 + int naccess; /* # of access ACL entries */
3497 + int ndefault; /* # of default ACL entries */
3499 + if(hpux_acl_call_presence() == False) {
3500 + /* Looks like we don't have the acl() system call on HPUX.
3501 + * May be the system doesn't have the latest version of JFS.
3506 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3511 + count = INITIAL_ACL_SIZE;
3512 + if ((acl_d = sys_acl_init(count)) == NULL) {
3517 + * If there isn't enough space for the ACL entries we use
3518 + * ACL_CNT to determine the actual number of ACL entries
3519 + * reallocate and try again. This is in a loop because it
3520 + * is possible that someone else could modify the ACL and
3521 + * increase the number of entries between the call to
3522 + * ACL_CNT and the call to ACL_GET.
3524 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3526 + sys_acl_free_acl(acl_d);
3528 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3532 + if ((acl_d = sys_acl_init(count)) == NULL) {
3538 + sys_acl_free_acl(acl_d);
3543 + * calculate the number of access and default ACL entries
3545 + * Note: we assume that the acl() system call returned a
3546 + * well formed ACL which is sorted so that all of the
3547 + * access ACL entries preceed any default ACL entries
3549 + for (naccess = 0; naccess < count; naccess++) {
3550 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3553 + ndefault = count - naccess;
3556 + * if the caller wants the default ACL we have to copy
3557 + * the entries down to the start of the acl[] buffer
3558 + * and mask out the ACL_DEFAULT flag from the type field
3560 + if (type == SMB_ACL_TYPE_DEFAULT) {
3563 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3564 + acl_d->acl[i] = acl_d->acl[j];
3565 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3568 + acl_d->count = ndefault;
3570 + acl_d->count = naccess;
3576 +SMB_ACL_T sys_acl_get_fd(int fd)
3579 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3582 + files_struct *fsp = file_find_fd(fd);
3584 + if (fsp == NULL) {
3590 + * We know we're in the same conn context. So we
3591 + * can use the relative path.
3594 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3597 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3604 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3606 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3607 + && perm != SMB_ACL_EXECUTE) {
3612 + if (permset_d == NULL) {
3617 + *permset_d |= perm;
3622 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3624 + return *permset_d & perm;
3627 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3634 + * use an initial estimate of 20 bytes per ACL entry
3635 + * when allocating memory for the text representation
3639 + maxlen = 20 * acl_d->count;
3640 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3645 + for (i = 0; i < acl_d->count; i++) {
3646 + struct acl *ap = &acl_d->acl[i];
3655 + switch (ap->a_type) {
3657 + * for debugging purposes it's probably more
3658 + * useful to dump unknown tag types rather
3659 + * than just returning an error
3662 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3665 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3670 + case SMB_ACL_USER:
3671 + id = uidtoname(ap->a_id);
3672 + case SMB_ACL_USER_OBJ:
3676 + case SMB_ACL_GROUP:
3677 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3678 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3684 + case SMB_ACL_GROUP_OBJ:
3688 + case SMB_ACL_OTHER:
3692 + case SMB_ACL_MASK:
3698 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3699 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3700 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3703 + /* <tag> : <qualifier> : rwx \n \0 */
3704 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3707 + * If this entry would overflow the buffer
3708 + * allocate enough additional memory for this
3709 + * entry and an estimate of another 20 bytes
3710 + * for each entry still to be processed
3712 + if ((len + nbytes) > maxlen) {
3713 + char *oldtext = text;
3715 + maxlen += nbytes + 20 * (acl_d->count - i);
3717 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3724 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3725 + len += nbytes - 1;
3734 +SMB_ACL_T sys_acl_init(int count)
3744 + * note that since the definition of the structure pointed
3745 + * to by the SMB_ACL_T includes the first element of the
3746 + * acl[] array, this actually allocates an ACL with room
3747 + * for (count+1) entries
3749 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3754 + a->size = count + 1;
3762 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3765 + SMB_ACL_ENTRY_T entry_d;
3767 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3772 + if (acl_d->count >= acl_d->size) {
3777 + entry_d = &acl_d->acl[acl_d->count++];
3778 + entry_d->a_type = 0;
3779 + entry_d->a_id = -1;
3780 + entry_d->a_perm = 0;
3781 + *entry_p = entry_d;
3786 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3788 + switch (tag_type) {
3789 + case SMB_ACL_USER:
3790 + case SMB_ACL_USER_OBJ:
3791 + case SMB_ACL_GROUP:
3792 + case SMB_ACL_GROUP_OBJ:
3793 + case SMB_ACL_OTHER:
3794 + case SMB_ACL_MASK:
3795 + entry_d->a_type = tag_type;
3805 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3807 + if (entry_d->a_type != SMB_ACL_GROUP
3808 + && entry_d->a_type != SMB_ACL_USER) {
3813 + entry_d->a_id = *((id_t *)qual_p);
3818 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3820 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3824 + entry_d->a_perm = *permset_d;
3829 +/* Structure to capture the count for each type of ACE. */
3831 +struct hpux_acl_types {
3835 + int n_def_user_obj;
3840 + int n_def_group_obj;
3844 + int n_def_other_obj;
3847 + int n_def_class_obj;
3849 + int n_illegal_obj;
3853 + * Counts the different number of objects in a given array of ACL
3857 + * acl_count - Count of ACLs in the array of ACL strucutres.
3858 + * aclp - Array of ACL structures.
3859 + * acl_type_count - Pointer to acl_types structure. Should already be
3863 + * acl_type_count - This structure is filled up with counts of various
3867 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3871 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3873 + for(i=0;i<acl_count;i++) {
3874 + switch(aclp[i].a_type) {
3876 + acl_type_count->n_user++;
3879 + acl_type_count->n_user_obj++;
3881 + case DEF_USER_OBJ:
3882 + acl_type_count->n_def_user_obj++;
3885 + acl_type_count->n_group++;
3888 + acl_type_count->n_group_obj++;
3890 + case DEF_GROUP_OBJ:
3891 + acl_type_count->n_def_group_obj++;
3894 + acl_type_count->n_other_obj++;
3896 + case DEF_OTHER_OBJ:
3897 + acl_type_count->n_def_other_obj++;
3900 + acl_type_count->n_class_obj++;
3902 + case DEF_CLASS_OBJ:
3903 + acl_type_count->n_def_class_obj++;
3906 + acl_type_count->n_def_user++;
3909 + acl_type_count->n_def_group++;
3912 + acl_type_count->n_illegal_obj++;
3918 +/* swap_acl_entries: Swaps two ACL entries.
3920 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3923 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3925 + struct acl temp_acl;
3927 + temp_acl.a_type = aclp0->a_type;
3928 + temp_acl.a_id = aclp0->a_id;
3929 + temp_acl.a_perm = aclp0->a_perm;
3931 + aclp0->a_type = aclp1->a_type;
3932 + aclp0->a_id = aclp1->a_id;
3933 + aclp0->a_perm = aclp1->a_perm;
3935 + aclp1->a_type = temp_acl.a_type;
3936 + aclp1->a_id = temp_acl.a_id;
3937 + aclp1->a_perm = temp_acl.a_perm;
3940 +/* prohibited_duplicate_type
3941 + * Identifies if given ACL type can have duplicate entries or
3944 + * Inputs: acl_type - ACL Type.
3950 + * True - If the ACL type matches any of the prohibited types.
3951 + * False - If the ACL type doesn't match any of the prohibited types.
3954 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3956 + switch(acl_type) {
3967 +/* get_needed_class_perm
3968 + * Returns the permissions of a ACL structure only if the ACL
3969 + * type matches one of the pre-determined types for computing
3970 + * CLASS_OBJ permissions.
3972 + * Inputs: aclp - Pointer to ACL structure.
3975 +static int hpux_get_needed_class_perm(struct acl *aclp)
3977 + switch(aclp->a_type) {
3981 + case DEF_USER_OBJ:
3983 + case DEF_GROUP_OBJ:
3985 + case DEF_CLASS_OBJ:
3986 + case DEF_OTHER_OBJ:
3987 + return aclp->a_perm;
3993 +/* acl_sort for HPUX.
3994 + * Sorts the array of ACL structures as per the description in
3995 + * aclsort man page. Refer to aclsort man page for more details
3999 + * acl_count - Count of ACLs in the array of ACL structures.
4000 + * calclass - If this is not zero, then we compute the CLASS_OBJ
4002 + * aclp - Array of ACL structures.
4006 + * aclp - Sorted array of ACL structures.
4010 + * Returns 0 for success -1 for failure. Prints a message to the Samba
4011 + * debug log in case of failure.
4014 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
4016 +#if !defined(HAVE_HPUX_ACLSORT)
4018 + * The aclsort() system call is availabe on the latest HPUX General
4019 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
4020 + * function. Because, we don't want to update to a new
4021 + * HPUX GR bundle just for aclsort() call.
4024 + struct hpux_acl_types acl_obj_count;
4025 + int n_class_obj_perm = 0;
4029 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
4033 + if(aclp == NULL) {
4034 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
4038 + /* Count different types of ACLs in the ACLs array */
4040 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
4042 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
4043 + * CLASS_OBJ and OTHER_OBJ
4046 + if( (acl_obj_count.n_user_obj != 1) ||
4047 + (acl_obj_count.n_group_obj != 1) ||
4048 + (acl_obj_count.n_class_obj != 1) ||
4049 + (acl_obj_count.n_other_obj != 1)
4051 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
4052 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
4056 + /* If any of the default objects are present, there should be only
4057 + * one of them each.
4060 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
4061 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
4062 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
4063 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
4067 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
4070 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
4071 + * same ACL type, sort by ACL id.
4073 + * I am using the trival kind of sorting method here because, performance isn't
4074 + * really effected by the ACLs feature. More over there aren't going to be more
4075 + * than 17 entries on HPUX.
4078 + for(i=0; i<acl_count;i++) {
4079 + for (j=i+1; j<acl_count; j++) {
4080 + if( aclp[i].a_type > aclp[j].a_type ) {
4081 + /* ACL entries out of order, swap them */
4083 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4085 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
4087 + /* ACL entries of same type, sort by id */
4089 + if(aclp[i].a_id > aclp[j].a_id) {
4090 + hpux_swap_acl_entries((aclp+i), (aclp+j));
4091 + } else if (aclp[i].a_id == aclp[j].a_id) {
4092 + /* We have a duplicate entry. */
4093 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
4094 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
4095 + aclp[i].a_type, aclp[i].a_id));
4104 + /* set the class obj permissions to the computed one. */
4106 + int n_class_obj_index = -1;
4108 + for(i=0;i<acl_count;i++) {
4109 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
4111 + if(aclp[i].a_type == CLASS_OBJ)
4112 + n_class_obj_index = i;
4114 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
4119 + return aclsort(acl_count, calclass, aclp);
4124 + * sort the ACL and check it for validity
4126 + * if it's a minimal ACL with only 4 entries then we
4127 + * need to recalculate the mask permissions to make
4128 + * sure that they are the same as the GROUP_OBJ
4129 + * permissions as required by the UnixWare acl() system call.
4131 + * (note: since POSIX allows minimal ACLs which only contain
4132 + * 3 entries - ie there is no mask entry - we should, in theory,
4133 + * check for this and add a mask entry if necessary - however
4134 + * we "know" that the caller of this interface always specifies
4135 + * a mask so, in practice "this never happens" (tm) - if it *does*
4136 + * happen aclsort() will fail and return an error and someone will
4137 + * have to fix it ...)
4140 +static int acl_sort(SMB_ACL_T acl_d)
4142 + int fixmask = (acl_d->count <= 4);
4144 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4151 +int sys_acl_valid(SMB_ACL_T acl_d)
4153 + return acl_sort(acl_d);
4156 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4159 + struct acl *acl_p;
4161 + struct acl *acl_buf = NULL;
4164 + if(hpux_acl_call_presence() == False) {
4165 + /* Looks like we don't have the acl() system call on HPUX.
4166 + * May be the system doesn't have the latest version of JFS.
4172 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4177 + if (acl_sort(acl_d) != 0) {
4181 + acl_p = &acl_d->acl[0];
4182 + acl_count = acl_d->count;
4185 + * if it's a directory there is extra work to do
4186 + * since the acl() system call will replace both
4187 + * the access ACLs and the default ACLs (if any)
4189 + if (stat(name, &s) != 0) {
4192 + if (S_ISDIR(s.st_mode)) {
4193 + SMB_ACL_T acc_acl;
4194 + SMB_ACL_T def_acl;
4195 + SMB_ACL_T tmp_acl;
4198 + if (type == SMB_ACL_TYPE_ACCESS) {
4200 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4204 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4207 + if (tmp_acl == NULL) {
4212 + * allocate a temporary buffer for the complete ACL
4214 + acl_count = acc_acl->count + def_acl->count;
4215 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4217 + if (acl_buf == NULL) {
4218 + sys_acl_free_acl(tmp_acl);
4224 + * copy the access control and default entries into the buffer
4226 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4227 + acc_acl->count * sizeof(acl_buf[0]));
4229 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4230 + def_acl->count * sizeof(acl_buf[0]));
4233 + * set the ACL_DEFAULT flag on the default entries
4235 + for (i = acc_acl->count; i < acl_count; i++) {
4236 + acl_buf[i].a_type |= ACL_DEFAULT;
4239 + sys_acl_free_acl(tmp_acl);
4241 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4246 + ret = acl(name, ACL_SET, acl_count, acl_p);
4255 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4258 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4261 + files_struct *fsp = file_find_fd(fd);
4263 + if (fsp == NULL) {
4268 + if (acl_sort(acl_d) != 0) {
4273 + * We know we're in the same conn context. So we
4274 + * can use the relative path.
4277 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4280 +int sys_acl_delete_def_file(const char *path)
4286 + * fetching the access ACL and rewriting it has
4287 + * the effect of deleting the default ACL
4289 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4293 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4295 + sys_acl_free_acl(acl_d);
4300 +int sys_acl_free_text(char *text)
4306 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4312 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4317 +#elif defined(HAVE_IRIX_ACLS)
4319 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4321 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4326 + if (entry_p == NULL) {
4331 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4335 + if (acl_d->next < 0) {
4340 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4344 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4349 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4351 + *type_p = entry_d->ae_tag;
4356 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4358 + *permset_p = entry_d;
4363 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4365 + if (entry_d->ae_tag != SMB_ACL_USER
4366 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4371 + return &entry_d->ae_id;
4374 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4378 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4382 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4387 + a->freeaclp = True;
4391 +SMB_ACL_T sys_acl_get_fd(int fd)
4395 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4399 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4404 + a->freeaclp = True;
4408 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4410 + permset_d->ae_perm = 0;
4415 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4417 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4418 + && perm != SMB_ACL_EXECUTE) {
4423 + if (permset_d == NULL) {
4428 + permset_d->ae_perm |= perm;
4433 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4435 + return permset_d->ae_perm & perm;
4438 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4440 + return acl_to_text(acl_d->aclp, len_p);
4443 +SMB_ACL_T sys_acl_init(int count)
4452 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4458 + a->freeaclp = False;
4459 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4460 + a->aclp->acl_cnt = 0;
4466 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4469 + SMB_ACL_ENTRY_T entry_d;
4471 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4476 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4481 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4482 + entry_d->ae_tag = 0;
4483 + entry_d->ae_id = 0;
4484 + entry_d->ae_perm = 0;
4485 + *entry_p = entry_d;
4490 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4492 + switch (tag_type) {
4493 + case SMB_ACL_USER:
4494 + case SMB_ACL_USER_OBJ:
4495 + case SMB_ACL_GROUP:
4496 + case SMB_ACL_GROUP_OBJ:
4497 + case SMB_ACL_OTHER:
4498 + case SMB_ACL_MASK:
4499 + entry_d->ae_tag = tag_type;
4509 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4511 + if (entry_d->ae_tag != SMB_ACL_GROUP
4512 + && entry_d->ae_tag != SMB_ACL_USER) {
4517 + entry_d->ae_id = *((id_t *)qual_p);
4522 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4524 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4528 + entry_d->ae_perm = permset_d->ae_perm;
4533 +int sys_acl_valid(SMB_ACL_T acl_d)
4535 + return acl_valid(acl_d->aclp);
4538 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4540 + return acl_set_file(name, type, acl_d->aclp);
4543 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4545 + return acl_set_fd(fd, acl_d->aclp);
4548 +int sys_acl_delete_def_file(const char *name)
4550 + return acl_delete_def_file(name);
4553 +int sys_acl_free_text(char *text)
4555 + return acl_free(text);
4558 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4560 + if (acl_d->freeaclp) {
4561 + acl_free(acl_d->aclp);
4567 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4572 +#elif defined(HAVE_AIX_ACLS)
4574 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4576 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4578 + struct acl_entry_link *link;
4579 + struct new_acl_entry *entry;
4582 + DEBUG(10,("This is the count: %d\n",theacl->count));
4584 + /* Check if count was previously set to -1. *
4585 + * If it was, that means we reached the end *
4586 + * of the acl last time. */
4587 + if(theacl->count == -1)
4591 + /* To get to the next acl, traverse linked list until index *
4592 + * of acl matches the count we are keeping. This count is *
4593 + * incremented each time we return an acl entry. */
4595 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4596 + link = link->nextp;
4598 + entry = *entry_p = link->entryp;
4600 + DEBUG(10,("*entry_p is %d\n",entry_p));
4601 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4603 + /* Increment count */
4605 + if(link->nextp == NULL)
4606 + theacl->count = -1;
4611 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4613 + /* Initialize tag type */
4616 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4618 + /* Depending on what type of entry we have, *
4619 + * return tag type. */
4620 + switch(entry_d->ace_id->id_type) {
4622 + *tag_type_p = SMB_ACL_USER;
4625 + *tag_type_p = SMB_ACL_GROUP;
4628 + case SMB_ACL_USER_OBJ:
4629 + case SMB_ACL_GROUP_OBJ:
4630 + case SMB_ACL_OTHER:
4631 + *tag_type_p = entry_d->ace_id->id_type;
4641 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4643 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4644 + *permset_p = &entry_d->ace_access;
4645 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4646 + if(!(**permset_p & S_IXUSR) &&
4647 + !(**permset_p & S_IWUSR) &&
4648 + !(**permset_p & S_IRUSR) &&
4649 + (**permset_p != 0))
4652 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4656 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4658 + return(entry_d->ace_id->id_data);
4661 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4663 + struct acl *file_acl = (struct acl *)NULL;
4664 + struct acl_entry *acl_entry;
4665 + struct new_acl_entry *new_acl_entry;
4666 + struct ace_id *idp;
4667 + struct acl_entry_link *acl_entry_link;
4668 + struct acl_entry_link *acl_entry_link_head;
4673 + /* AIX has no DEFAULT */
4674 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4679 + /* Get the acl using statacl */
4681 + DEBUG(10,("Entering sys_acl_get_file\n"));
4682 + DEBUG(10,("path_p is %s\n",path_p));
4684 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4686 + if(file_acl == NULL) {
4688 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4692 + memset(file_acl,0,BUFSIZ);
4694 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4696 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4697 + SAFE_FREE(file_acl);
4701 + DEBUG(10,("Got facl and returned it\n"));
4703 + /* Point to the first acl entry in the acl */
4704 + acl_entry = file_acl->acl_ext;
4706 + /* Begin setting up the head of the linked list *
4707 + * that will be used for the storing the acl *
4708 + * in a way that is useful for the posix_acls.c *
4711 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4712 + if(acl_entry_link_head == NULL)
4715 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4716 + if(acl_entry_link->entryp == NULL) {
4717 + SAFE_FREE(file_acl);
4719 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4723 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4724 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4726 + /* Check if the extended acl bit is on. *
4727 + * If it isn't, do not show the *
4728 + * contents of the acl since AIX intends *
4729 + * the extended info to remain unused */
4731 + if(file_acl->acl_mode & S_IXACL){
4732 + /* while we are not pointing to the very end */
4733 + while(acl_entry < acl_last(file_acl)) {
4734 + /* before we malloc anything, make sure this is */
4735 + /* a valid acl entry and one that we want to map */
4736 + idp = id_nxt(acl_entry->ace_id);
4737 + if((acl_entry->ace_type == ACC_SPECIFY ||
4738 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4739 + acl_entry = acl_nxt(acl_entry);
4743 + idp = acl_entry->ace_id;
4745 + /* Check if this is the first entry in the linked list. *
4746 + * The first entry needs to keep prevp pointing to NULL *
4747 + * and already has entryp allocated. */
4749 + if(acl_entry_link_head->count != 0) {
4750 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4752 + if(acl_entry_link->nextp == NULL) {
4753 + SAFE_FREE(file_acl);
4755 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4759 + acl_entry_link->nextp->prevp = acl_entry_link;
4760 + acl_entry_link = acl_entry_link->nextp;
4761 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4762 + if(acl_entry_link->entryp == NULL) {
4763 + SAFE_FREE(file_acl);
4765 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4768 + acl_entry_link->nextp = NULL;
4771 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4773 + /* Don't really need this since all types are going *
4774 + * to be specified but, it's better than leaving it 0 */
4776 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4778 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4780 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4782 + /* The access in the acl entries must be left shifted by *
4783 + * three bites, because they will ultimately be compared *
4784 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4786 + switch(acl_entry->ace_type){
4789 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4790 + acl_entry_link->entryp->ace_access <<= 6;
4791 + acl_entry_link_head->count++;
4794 + /* Since there is no way to return a DENY acl entry *
4795 + * change to PERMIT and then shift. */
4796 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4797 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4798 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4799 + acl_entry_link->entryp->ace_access <<= 6;
4800 + acl_entry_link_head->count++;
4806 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4807 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4809 + acl_entry = acl_nxt(acl_entry);
4811 + } /* end of if enabled */
4813 + /* Since owner, group, other acl entries are not *
4814 + * part of the acl entries in an acl, they must *
4815 + * be dummied up to become part of the list. */
4817 + for( i = 1; i < 4; i++) {
4818 + DEBUG(10,("i is %d\n",i));
4819 + if(acl_entry_link_head->count != 0) {
4820 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4821 + if(acl_entry_link->nextp == NULL) {
4822 + SAFE_FREE(file_acl);
4824 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4828 + acl_entry_link->nextp->prevp = acl_entry_link;
4829 + acl_entry_link = acl_entry_link->nextp;
4830 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4831 + if(acl_entry_link->entryp == NULL) {
4832 + SAFE_FREE(file_acl);
4834 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4839 + acl_entry_link->nextp = NULL;
4841 + new_acl_entry = acl_entry_link->entryp;
4842 + idp = new_acl_entry->ace_id;
4844 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4845 + new_acl_entry->ace_type = ACC_PERMIT;
4846 + idp->id_len = sizeof(struct ace_id);
4847 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4848 + memset(idp->id_data,0,sizeof(uid_t));
4852 + new_acl_entry->ace_access = file_acl->g_access << 6;
4853 + idp->id_type = SMB_ACL_GROUP_OBJ;
4857 + new_acl_entry->ace_access = file_acl->o_access << 6;
4858 + idp->id_type = SMB_ACL_OTHER;
4862 + new_acl_entry->ace_access = file_acl->u_access << 6;
4863 + idp->id_type = SMB_ACL_USER_OBJ;
4871 + acl_entry_link_head->count++;
4872 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4875 + acl_entry_link_head->count = 0;
4876 + SAFE_FREE(file_acl);
4878 + return(acl_entry_link_head);
4881 +SMB_ACL_T sys_acl_get_fd(int fd)
4883 + struct acl *file_acl = (struct acl *)NULL;
4884 + struct acl_entry *acl_entry;
4885 + struct new_acl_entry *new_acl_entry;
4886 + struct ace_id *idp;
4887 + struct acl_entry_link *acl_entry_link;
4888 + struct acl_entry_link *acl_entry_link_head;
4893 + /* Get the acl using fstatacl */
4895 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4896 + DEBUG(10,("fd is %d\n",fd));
4897 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4899 + if(file_acl == NULL) {
4901 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4905 + memset(file_acl,0,BUFSIZ);
4907 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4909 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4910 + SAFE_FREE(file_acl);
4914 + DEBUG(10,("Got facl and returned it\n"));
4916 + /* Point to the first acl entry in the acl */
4918 + acl_entry = file_acl->acl_ext;
4919 + /* Begin setting up the head of the linked list *
4920 + * that will be used for the storing the acl *
4921 + * in a way that is useful for the posix_acls.c *
4924 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4925 + if(acl_entry_link_head == NULL){
4926 + SAFE_FREE(file_acl);
4930 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4932 + if(acl_entry_link->entryp == NULL) {
4934 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4935 + SAFE_FREE(file_acl);
4939 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4940 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4942 + /* Check if the extended acl bit is on. *
4943 + * If it isn't, do not show the *
4944 + * contents of the acl since AIX intends *
4945 + * the extended info to remain unused */
4947 + if(file_acl->acl_mode & S_IXACL){
4948 + /* while we are not pointing to the very end */
4949 + while(acl_entry < acl_last(file_acl)) {
4950 + /* before we malloc anything, make sure this is */
4951 + /* a valid acl entry and one that we want to map */
4953 + idp = id_nxt(acl_entry->ace_id);
4954 + if((acl_entry->ace_type == ACC_SPECIFY ||
4955 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4956 + acl_entry = acl_nxt(acl_entry);
4960 + idp = acl_entry->ace_id;
4962 + /* Check if this is the first entry in the linked list. *
4963 + * The first entry needs to keep prevp pointing to NULL *
4964 + * and already has entryp allocated. */
4966 + if(acl_entry_link_head->count != 0) {
4967 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4968 + if(acl_entry_link->nextp == NULL) {
4970 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4971 + SAFE_FREE(file_acl);
4974 + acl_entry_link->nextp->prevp = acl_entry_link;
4975 + acl_entry_link = acl_entry_link->nextp;
4976 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4977 + if(acl_entry_link->entryp == NULL) {
4979 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4980 + SAFE_FREE(file_acl);
4984 + acl_entry_link->nextp = NULL;
4987 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4989 + /* Don't really need this since all types are going *
4990 + * to be specified but, it's better than leaving it 0 */
4992 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4993 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4995 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4997 + /* The access in the acl entries must be left shifted by *
4998 + * three bites, because they will ultimately be compared *
4999 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
5001 + switch(acl_entry->ace_type){
5004 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
5005 + acl_entry_link->entryp->ace_access <<= 6;
5006 + acl_entry_link_head->count++;
5009 + /* Since there is no way to return a DENY acl entry *
5010 + * change to PERMIT and then shift. */
5011 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
5012 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
5013 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
5014 + acl_entry_link->entryp->ace_access <<= 6;
5015 + acl_entry_link_head->count++;
5021 + DEBUG(10,("acl_entry = %d\n",acl_entry));
5022 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
5024 + acl_entry = acl_nxt(acl_entry);
5026 + } /* end of if enabled */
5028 + /* Since owner, group, other acl entries are not *
5029 + * part of the acl entries in an acl, they must *
5030 + * be dummied up to become part of the list. */
5032 + for( i = 1; i < 4; i++) {
5033 + DEBUG(10,("i is %d\n",i));
5034 + if(acl_entry_link_head->count != 0){
5035 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
5036 + if(acl_entry_link->nextp == NULL) {
5038 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
5039 + SAFE_FREE(file_acl);
5043 + acl_entry_link->nextp->prevp = acl_entry_link;
5044 + acl_entry_link = acl_entry_link->nextp;
5045 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
5047 + if(acl_entry_link->entryp == NULL) {
5048 + SAFE_FREE(file_acl);
5050 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
5055 + acl_entry_link->nextp = NULL;
5057 + new_acl_entry = acl_entry_link->entryp;
5058 + idp = new_acl_entry->ace_id;
5060 + new_acl_entry->ace_len = sizeof(struct acl_entry);
5061 + new_acl_entry->ace_type = ACC_PERMIT;
5062 + idp->id_len = sizeof(struct ace_id);
5063 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
5064 + memset(idp->id_data,0,sizeof(uid_t));
5068 + new_acl_entry->ace_access = file_acl->g_access << 6;
5069 + idp->id_type = SMB_ACL_GROUP_OBJ;
5073 + new_acl_entry->ace_access = file_acl->o_access << 6;
5074 + idp->id_type = SMB_ACL_OTHER;
5078 + new_acl_entry->ace_access = file_acl->u_access << 6;
5079 + idp->id_type = SMB_ACL_USER_OBJ;
5086 + acl_entry_link_head->count++;
5087 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
5090 + acl_entry_link_head->count = 0;
5091 + SAFE_FREE(file_acl);
5093 + return(acl_entry_link_head);
5096 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
5098 + *permset = *permset & ~0777;
5102 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5105 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
5109 + DEBUG(10,("This is the permset now: %d\n",*permset));
5113 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
5118 +SMB_ACL_T sys_acl_init( int count)
5120 + struct acl_entry_link *theacl = NULL;
5122 + DEBUG(10,("Entering sys_acl_init\n"));
5124 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5125 + if(theacl == NULL) {
5127 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5131 + theacl->count = 0;
5132 + theacl->nextp = NULL;
5133 + theacl->prevp = NULL;
5134 + theacl->entryp = NULL;
5135 + DEBUG(10,("Exiting sys_acl_init\n"));
5139 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5141 + struct acl_entry_link *theacl;
5142 + struct acl_entry_link *acl_entryp;
5143 + struct acl_entry_link *temp_entry;
5146 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5148 + theacl = acl_entryp = *pacl;
5150 + /* Get to the end of the acl before adding entry */
5152 + for(counting=0; counting < theacl->count; counting++){
5153 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5154 + temp_entry = acl_entryp;
5155 + acl_entryp = acl_entryp->nextp;
5158 + if(theacl->count != 0){
5159 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5160 + if(acl_entryp == NULL) {
5162 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5166 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5167 + acl_entryp->prevp = temp_entry;
5168 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5171 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5172 + if(*pentry == NULL) {
5174 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5178 + memset(*pentry,0,sizeof(struct new_acl_entry));
5179 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5180 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5181 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5182 + acl_entryp->nextp = NULL;
5184 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5188 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5190 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5191 + entry->ace_id->id_type = tagtype;
5192 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5193 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5196 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5198 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5199 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5200 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5204 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5206 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5207 + if(!(*permset & S_IXUSR) &&
5208 + !(*permset & S_IWUSR) &&
5209 + !(*permset & S_IRUSR) &&
5213 + entry->ace_access = *permset;
5214 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5215 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5219 +int sys_acl_valid( SMB_ACL_T theacl )
5222 + int group_obj = 0;
5223 + int other_obj = 0;
5224 + struct acl_entry_link *acl_entry;
5226 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5227 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5228 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5229 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5232 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5234 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5240 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5242 + struct acl_entry_link *acl_entry_link = NULL;
5243 + struct acl *file_acl = NULL;
5244 + struct acl *file_acl_temp = NULL;
5245 + struct acl_entry *acl_entry = NULL;
5246 + struct ace_id *ace_id = NULL;
5253 + DEBUG(10,("Entering sys_acl_set_file\n"));
5254 + DEBUG(10,("File name is %s\n",name));
5256 + /* AIX has no default ACL */
5257 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5260 + acl_length = BUFSIZ;
5261 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5263 + if(file_acl == NULL) {
5265 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5269 + memset(file_acl,0,BUFSIZ);
5271 + file_acl->acl_len = ACL_SIZ;
5272 + file_acl->acl_mode = S_IXACL;
5274 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5275 + acl_entry_link->entryp->ace_access >>= 6;
5276 + id_type = acl_entry_link->entryp->ace_id->id_type;
5279 + case SMB_ACL_USER_OBJ:
5280 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5282 + case SMB_ACL_GROUP_OBJ:
5283 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5285 + case SMB_ACL_OTHER:
5286 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5288 + case SMB_ACL_MASK:
5292 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5293 + acl_length += sizeof(struct acl_entry);
5294 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5295 + if(file_acl_temp == NULL) {
5296 + SAFE_FREE(file_acl);
5298 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5302 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5303 + SAFE_FREE(file_acl);
5304 + file_acl = file_acl_temp;
5307 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5308 + file_acl->acl_len += sizeof(struct acl_entry);
5309 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5310 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5312 + /* In order to use this, we'll need to wait until we can get denies */
5313 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5314 + acl_entry->ace_type = ACC_SPECIFY; */
5316 + acl_entry->ace_type = ACC_SPECIFY;
5318 + ace_id = acl_entry->ace_id;
5320 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5321 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5322 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5323 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5324 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5327 + rc = chacl(name,file_acl,file_acl->acl_len);
5328 + DEBUG(10,("errno is %d\n",errno));
5329 + DEBUG(10,("return code is %d\n",rc));
5330 + SAFE_FREE(file_acl);
5331 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5335 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5337 + struct acl_entry_link *acl_entry_link = NULL;
5338 + struct acl *file_acl = NULL;
5339 + struct acl *file_acl_temp = NULL;
5340 + struct acl_entry *acl_entry = NULL;
5341 + struct ace_id *ace_id = NULL;
5347 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5348 + acl_length = BUFSIZ;
5349 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5351 + if(file_acl == NULL) {
5353 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5357 + memset(file_acl,0,BUFSIZ);
5359 + file_acl->acl_len = ACL_SIZ;
5360 + file_acl->acl_mode = S_IXACL;
5362 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5363 + acl_entry_link->entryp->ace_access >>= 6;
5364 + id_type = acl_entry_link->entryp->ace_id->id_type;
5365 + DEBUG(10,("The id_type is %d\n",id_type));
5368 + case SMB_ACL_USER_OBJ:
5369 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5371 + case SMB_ACL_GROUP_OBJ:
5372 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5374 + case SMB_ACL_OTHER:
5375 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5377 + case SMB_ACL_MASK:
5381 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5382 + acl_length += sizeof(struct acl_entry);
5383 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5384 + if(file_acl_temp == NULL) {
5385 + SAFE_FREE(file_acl);
5387 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5391 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5392 + SAFE_FREE(file_acl);
5393 + file_acl = file_acl_temp;
5396 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5397 + file_acl->acl_len += sizeof(struct acl_entry);
5398 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5399 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5401 + /* In order to use this, we'll need to wait until we can get denies */
5402 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5403 + acl_entry->ace_type = ACC_SPECIFY; */
5405 + acl_entry->ace_type = ACC_SPECIFY;
5407 + ace_id = acl_entry->ace_id;
5409 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5410 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5411 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5412 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5413 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5416 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5417 + DEBUG(10,("errno is %d\n",errno));
5418 + DEBUG(10,("return code is %d\n",rc));
5419 + SAFE_FREE(file_acl);
5420 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5424 +int sys_acl_delete_def_file(const char *name)
5426 + /* AIX has no default ACL */
5430 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5432 + return(*permset & perm);
5435 +int sys_acl_free_text(char *text)
5440 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5442 + struct acl_entry_link *acl_entry_link;
5444 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5445 + SAFE_FREE(acl_entry_link->prevp->entryp);
5446 + SAFE_FREE(acl_entry_link->prevp);
5449 + SAFE_FREE(acl_entry_link->prevp->entryp);
5450 + SAFE_FREE(acl_entry_link->prevp);
5451 + SAFE_FREE(acl_entry_link->entryp);
5452 + SAFE_FREE(acl_entry_link);
5457 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5462 +#else /* No ACLs. */
5464 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5470 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5476 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5482 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5488 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5491 + return (SMB_ACL_T)NULL;
5494 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5497 + return (SMB_ACL_T)NULL;
5500 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5506 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5512 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5515 + return (permset & perm) ? 1 : 0;
5518 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5524 +int sys_acl_free_text(UNUSED(char *text))
5530 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5536 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5542 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5548 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5554 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5560 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5566 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5572 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5578 +int sys_acl_delete_def_file(UNUSED(const char *name))
5584 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5590 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5596 +#endif /* No ACLs. */
5598 +/************************************************************************
5599 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5601 +************************************************************************/
5603 +int no_acl_syscall_error(int err)
5605 +#if defined(ENOSYS)
5606 + if (err == ENOSYS) {
5610 +#if defined(ENOTSUP)
5611 + if (err == ENOTSUP) {
5618 +#endif /* SUPPORT_ACLS */
5619 --- old/lib/sysacls.h
5620 +++ new/lib/sysacls.h
5622 +#ifdef SUPPORT_ACLS
5624 +#ifdef HAVE_SYS_ACL_H
5625 +#include <sys/acl.h>
5627 +#ifdef HAVE_ACL_LIBACL_H
5628 +#include <acl/libacl.h>
5630 +#include "smb_acls.h"
5632 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5633 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5634 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5635 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5636 +#define slprintf snprintf
5638 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5639 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5640 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5641 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5642 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5643 +SMB_ACL_T sys_acl_get_fd(int fd);
5644 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5645 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5646 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5647 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5648 +SMB_ACL_T sys_acl_init(int count);
5649 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5650 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5651 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5652 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5653 +int sys_acl_valid(SMB_ACL_T theacl);
5654 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5655 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5656 +int sys_acl_delete_def_file(const char *name);
5657 +int sys_acl_free_text(char *text);
5658 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5659 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5661 +#endif /* SUPPORT_ACLS */
5664 @@ -624,8 +624,10 @@ static void log_formatted(enum logcode c
5665 c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5666 c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5667 c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5670 + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5671 + c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5672 + c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5675 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5676 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5679 @@ -46,6 +46,7 @@ int copy_dirlinks = 0;
5681 int preserve_links = 0;
5682 int preserve_hard_links = 0;
5683 +int preserve_acls = 0;
5684 int preserve_perms = 0;
5685 int preserve_executability = 0;
5686 int preserve_devices = 0;
5687 @@ -198,6 +199,7 @@ static void print_rsync_version(enum log
5688 char const *got_socketpair = "no ";
5689 char const *have_inplace = "no ";
5690 char const *hardlinks = "no ";
5691 + char const *acls = "no ";
5692 char const *links = "no ";
5693 char const *ipv6 = "no ";
5694 STRUCT_STAT *dumstat;
5695 @@ -214,6 +216,10 @@ static void print_rsync_version(enum log
5699 +#ifdef SUPPORT_ACLS
5703 #ifdef SUPPORT_LINKS
5706 @@ -232,8 +238,8 @@ static void print_rsync_version(enum log
5707 (int)(sizeof (int64) * 8));
5708 rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
5709 got_socketpair, hardlinks, links, ipv6, have_inplace);
5710 - rprintf(f, " %sappend\n",
5712 + rprintf(f, " %sappend, %sACLs\n",
5713 + have_inplace, acls);
5715 #ifdef MAINTAINER_MODE
5716 rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
5717 @@ -279,7 +285,7 @@ void usage(enum logcode F)
5718 rprintf(F," -q, --quiet suppress non-error messages\n");
5719 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5720 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5721 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5722 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5723 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5724 rprintf(F," -r, --recursive recurse into directories\n");
5725 rprintf(F," -R, --relative use relative path names\n");
5726 @@ -301,6 +307,9 @@ void usage(enum logcode F)
5727 rprintf(F," -p, --perms preserve permissions\n");
5728 rprintf(F," -E, --executability preserve the file's executability\n");
5729 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5730 +#ifdef SUPPORT_ACLS
5731 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5733 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5734 rprintf(F," -g, --group preserve group\n");
5735 rprintf(F," --devices preserve device files (super-user only)\n");
5736 @@ -421,6 +430,9 @@ static struct poptOption long_options[]
5737 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5738 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5739 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5740 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5741 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5742 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5743 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5744 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5745 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5746 @@ -1092,6 +1104,24 @@ int parse_arguments(int *argc, const cha
5751 +#ifdef SUPPORT_ACLS
5752 + preserve_acls = 1;
5753 + preserve_perms = 1;
5756 + /* FIXME: this should probably be ignored with a
5757 + * warning and then countermeasures taken to
5758 + * restrict group and other access in the presence
5759 + * of any more restrictive ACLs, but this is safe
5761 + snprintf(err_buf,sizeof(err_buf),
5762 + "ACLs are not supported on this %s\n",
5763 + am_server ? "server" : "client");
5769 /* A large opt value means that set_refuse_options()
5770 * turned this option off. */
5771 @@ -1547,6 +1577,10 @@ void server_options(char **args,int *arg
5773 else if (preserve_executability && am_sender)
5775 +#ifdef SUPPORT_ACLS
5776 + if (preserve_acls)
5777 + argstr[x++] = 'A';
5781 if (always_checksum)
5784 @@ -47,6 +47,7 @@ extern int keep_partial;
5785 extern int checksum_seed;
5787 extern int delay_updates;
5788 +extern mode_t orig_umask;
5789 extern struct stats stats;
5790 extern char *tmpdir;
5791 extern char *partial_dir;
5792 @@ -347,6 +348,10 @@ int recv_files(int f_in, char *local_nam
5793 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5794 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5795 int max_phase = protocol_version >= 29 ? 2 : 1;
5796 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5797 +#ifdef SUPPORT_ACLS
5798 + const char *parent_dirname = "";
5803 @@ -562,7 +567,16 @@ int recv_files(int f_in, char *local_nam
5804 * mode based on the local permissions and some heuristics. */
5805 if (!preserve_perms) {
5806 int exists = fd1 != -1;
5807 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5808 +#ifdef SUPPORT_ACLS
5809 + const char *dn = file->dirname ? file->dirname : ".";
5810 + if (parent_dirname != dn
5811 + && strcmp(parent_dirname, dn) != 0) {
5812 + dflt_perms = default_perms_for_dir(dn);
5813 + parent_dirname = dn;
5816 + file->mode = dest_mode(file->mode, st.st_mode,
5817 + dflt_perms, exists);
5820 /* We now check to see if we are writing the file "inplace" */
5827 +extern int preserve_acls;
5828 extern int preserve_perms;
5829 extern int preserve_executability;
5830 extern int preserve_times;
5831 @@ -49,7 +50,6 @@ extern int inplace;
5832 extern int flist_eof;
5833 extern int keep_dirlinks;
5834 extern int make_backups;
5835 -extern mode_t orig_umask;
5836 extern struct file_list *cur_flist, *first_flist, *dir_flist;
5837 extern struct chmod_mode_struct *daemon_chmod_modes;
5839 @@ -203,7 +203,8 @@ void free_sums(struct sum_struct *s)
5841 /* This is only called when we aren't preserving permissions. Figure out what
5842 * the permissions should be and return them merged back into the mode. */
5843 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5844 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5848 /* If the file already exists, we'll return the local permissions,
5849 @@ -220,56 +221,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5850 new_mode |= (new_mode & 0444) >> 2;
5853 - /* Apply the umask and turn off special permissions. */
5854 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5855 + /* Apply destination default permissions and turn
5856 + * off special permissions. */
5857 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5862 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5863 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5869 int change_uid, change_gid;
5870 mode_t new_mode = file->mode;
5876 - if (link_stat(fname, &st2, 0) < 0) {
5877 + if (link_stat(fname, &sx2.st, 0) < 0) {
5878 rsyserr(FERROR, errno, "stat %s failed",
5883 +#ifdef SUPPORT_ACLS
5884 + sx2.acc_acl = sx2.def_acl = NULL;
5886 if (!preserve_perms && S_ISDIR(new_mode)
5887 - && st->st_mode & S_ISGID) {
5888 + && sx2.st.st_mode & S_ISGID) {
5889 /* We just created this directory and its setgid
5890 * bit is on, so make sure it stays on. */
5891 new_mode |= S_ISGID;
5896 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5897 +#ifdef SUPPORT_ACLS
5898 + if (preserve_acls && !ACL_READY(*sxp))
5899 + get_acl(fname, sxp);
5902 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5903 flags |= ATTRS_SKIP_MTIME;
5904 if (!(flags & ATTRS_SKIP_MTIME)
5905 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5906 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5907 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5908 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5910 rsyserr(FERROR, errno, "failed to set times on %s",
5915 if (ret == 0) /* ret == 1 if symlink could not be set */
5919 - change_uid = am_root && preserve_uid && st->st_uid != F_UID(file);
5920 + change_uid = am_root && preserve_uid && sxp->st.st_uid != F_UID(file);
5921 change_gid = preserve_gid && F_GID(file) != GID_NONE
5922 - && st->st_gid != F_GID(file);
5923 + && sxp->st.st_gid != F_GID(file);
5924 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5925 - if (S_ISLNK(st->st_mode))
5926 + if (S_ISLNK(sxp->st.st_mode))
5930 @@ -279,45 +289,57 @@ int set_file_attrs(char *fname, struct f
5932 "set uid of %s from %ld to %ld\n",
5934 - (long)st->st_uid, (long)F_UID(file));
5935 + (long)sxp->st.st_uid, (long)F_UID(file));
5939 "set gid of %s from %ld to %ld\n",
5941 - (long)st->st_gid, (long)F_GID(file));
5942 + (long)sxp->st.st_gid, (long)F_GID(file));
5945 if (do_lchown(fname,
5946 - change_uid ? F_UID(file) : st->st_uid,
5947 - change_gid ? F_GID(file) : st->st_gid) != 0) {
5948 + change_uid ? F_UID(file) : sxp->st.st_uid,
5949 + change_gid ? F_GID(file) : sxp->st.st_gid) != 0) {
5950 /* shouldn't have attempted to change uid or gid
5951 * unless have the privilege */
5952 rsyserr(FERROR, errno, "%s %s failed",
5953 change_uid ? "chown" : "chgrp",
5958 /* a lchown had been done - we have to re-stat if the
5959 * destination had the setuid or setgid bits set due
5960 * to the side effect of the chown call */
5961 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5962 - link_stat(fname, st,
5963 - keep_dirlinks && S_ISDIR(st->st_mode));
5964 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5965 + link_stat(fname, &sxp->st,
5966 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5971 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5972 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5974 +#ifdef SUPPORT_ACLS
5975 + /* It's OK to call set_acl() now, even for a dir, as the generator
5976 + * will enable owner-writability using chmod, if necessary.
5978 + * If set_acl() changes permission bits in the process of setting
5979 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5980 + * need to chmod(). */
5981 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5986 - if (!BITS_EQUAL(st->st_mode, new_mode, CHMOD_BITS)) {
5987 + if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) {
5988 int ret = do_chmod(fname, new_mode);
5990 rsyserr(FERROR, errno,
5991 "failed to set permissions on %s",
5996 if (ret == 0) /* ret == 1 if symlink could not be set */
5998 @@ -330,6 +352,11 @@ int set_file_attrs(char *fname, struct f
6000 rprintf(FCLIENT, "%s is uptodate\n", fname);
6003 +#ifdef SUPPORT_ACLS
6004 + if (preserve_acls && sxp == &sx2)
6012 @@ -547,6 +547,14 @@ struct idev_node {
6013 #define IN_LOOPBACKNET 127
6016 +#ifndef HAVE_NO_ACLS
6017 +#define SUPPORT_ACLS 1
6020 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
6021 +#define ACLS_NEED_MASK 1
6024 #define GID_NONE ((gid_t)-1)
6027 @@ -566,6 +574,7 @@ struct file_struct {
6028 extern int file_extra_cnt;
6029 extern int preserve_uid;
6030 extern int preserve_gid;
6031 +extern int preserve_acls;
6033 #define FILE_STRUCT_LEN (offsetof(struct file_struct, basename))
6034 #define EXTRA_LEN (sizeof (union file_extras))
6035 @@ -598,10 +607,12 @@ extern int preserve_gid;
6036 /* When the associated option is on, all entries will have these present: */
6037 #define F_OWNER(f) REQ_EXTRA(f, preserve_uid)->unum
6038 #define F_GROUP(f) REQ_EXTRA(f, preserve_gid)->unum
6039 +#define F_ACL(f) REQ_EXTRA(f, preserve_acls)->unum
6041 /* These items are per-entry optional and mutally exclusive: */
6042 #define F_HL_GNUM(f) OPT_EXTRA(f, LEN64_BUMP(f))->num
6043 #define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f))->num
6044 +#define F_DEF_ACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum
6045 #define F_DIRDEV_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + 2 - 1)->unum)
6046 #define F_DIRNODE_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + 3 - 1)->num)
6048 @@ -753,6 +764,17 @@ struct stats {
6050 struct chmod_mode_struct;
6052 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
6060 +#define EXPAND_ITEM_LIST(lp, type, incr) \
6061 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
6063 #include "byteorder.h"
6064 #include "lib/mdfour.h"
6065 #include "lib/wildmatch.h"
6066 @@ -771,6 +793,16 @@ struct chmod_mode_struct;
6067 #define NORETURN __attribute__((__noreturn__))
6072 +#ifdef SUPPORT_ACLS
6073 + struct rsync_acl *acc_acl; /* access ACL */
6074 + struct rsync_acl *def_acl; /* default ACL */
6078 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
6082 /* We have replacement versions of these if they're missing. */
6085 @@ -301,7 +301,7 @@ to the detailed description below for a
6086 -q, --quiet suppress non-error messages
6087 --no-motd suppress daemon-mode MOTD (see caveat)
6088 -c, --checksum skip based on checksum, not mod-time & size
6089 - -a, --archive archive mode; same as -rlptgoD (no -H)
6090 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
6091 --no-OPTION turn off an implied OPTION (e.g. --no-D)
6092 -r, --recursive recurse into directories
6093 -R, --relative use relative path names
6094 @@ -323,6 +323,7 @@ to the detailed description below for a
6095 -p, --perms preserve permissions
6096 -E, --executability preserve executability
6097 --chmod=CHMOD affect file and/or directory permissions
6098 + -A, --acls preserve ACLs (implies -p) [non-standard]
6099 -o, --owner preserve owner (super-user only)
6100 -g, --group preserve group
6101 --devices preserve device files (super-user only)
6102 @@ -771,7 +772,9 @@ quote(itemization(
6103 permissions, though the bf(--executability) option might change just
6104 the execute permission for the file.
6105 it() New files get their "normal" permission bits set to the source
6106 - file's permissions masked with the receiving end's umask setting, and
6107 + file's permissions masked with the receiving directory's default
6108 + permissions (either the receiving process's umask, or the permissions
6109 + specified via the destination directory's default ACL), and
6110 their special permission bits disabled except in the case where a new
6111 directory inherits a setgid bit from its parent directory.
6113 @@ -802,9 +805,11 @@ The preservation of the destination's se
6114 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
6115 versions erroneously preserved the three special permission bits for
6116 newly-created files when bf(--perms) was off, while overriding the
6117 -destination's setgid bit setting on a newly-created directory. (Keep in
6118 -mind that it is the version of the receiving rsync that affects this
6120 +destination's setgid bit setting on a newly-created directory. Default ACL
6121 +observance was added to the ACL patch for rsync 2.6.7, so older (or
6122 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
6123 +(Keep in mind that it is the version of the receiving rsync that affects
6126 dit(bf(-E, --executability)) This option causes rsync to preserve the
6127 executability (or non-executability) of regular files when bf(--perms) is
6128 @@ -822,6 +827,14 @@ quote(itemization(
6130 If bf(--perms) is enabled, this option is ignored.
6132 +dit(bf(-A, --acls)) This option causes rsync to update the destination
6133 +ACLs to be the same as the source ACLs. This nonstandard option only
6134 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
6136 +The ACL-sending protocol used by this version was first introduced in
6137 +the patch that was shipped with 2.6.8. Sending ACLs to an older version
6138 +of the ACL patch is not supported.
6140 dit(bf(--chmod)) This option tells rsync to apply one or more
6141 comma-separated "chmod" strings to the permission of the files in the
6142 transfer. The resulting value is treated as though it was the permissions
6143 @@ -1432,8 +1445,8 @@ if the receiving rsync is at least versi
6144 with older versions of rsync, but that also turns on the output of other
6147 -The "%i" escape has a cryptic output that is 9 letters long. The general
6148 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
6149 +The "%i" escape has a cryptic output that is 11 letters long. The general
6150 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
6151 type of update being done, bf(X) is replaced by the file-type, and the
6152 other letters represent attributes that may be output if they are being
6154 @@ -1482,7 +1495,11 @@ quote(itemization(
6155 sender's value (requires bf(--owner) and super-user privileges).
6156 it() A bf(g) means the group is different and is being updated to the
6157 sender's value (requires bf(--group) and the authority to set the group).
6158 - it() The bf(z) slot is reserved for future use.
6159 + it() The bf(u) slot is reserved for reporting update (access) time changes
6160 + (a feature that is not yet released).
6161 + it() The bf(a) means that the ACL information changed.
6162 + it() The bf(x) slot is reserved for reporting extended attribute changes
6163 + (a feature that is not yet released).
6166 One other output is possible: when deleting files, the "%i" will output
6171 + Unix SMB/Netbios implementation.
6173 + Portable SMB ACL interface
6174 + Copyright (C) Jeremy Allison 2000
6176 + This program is free software; you can redistribute it and/or modify
6177 + it under the terms of the GNU General Public License as published by
6178 + the Free Software Foundation; either version 2 of the License, or
6179 + (at your option) any later version.
6181 + This program is distributed in the hope that it will be useful,
6182 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6183 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6184 + GNU General Public License for more details.
6186 + You should have received a copy of the GNU General Public License
6187 + along with this program; if not, write to the Free Software
6188 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6191 +#ifndef _SMB_ACLS_H
6192 +#define _SMB_ACLS_H
6194 +#if defined HAVE_POSIX_ACLS
6196 +/* This is an identity mapping (just remove the SMB_). */
6198 +#define SMB_ACL_TAG_T acl_tag_t
6199 +#define SMB_ACL_TYPE_T acl_type_t
6200 +#define SMB_ACL_PERMSET_T acl_permset_t
6201 +#define SMB_ACL_PERM_T acl_perm_t
6202 +#define SMB_ACL_READ ACL_READ
6203 +#define SMB_ACL_WRITE ACL_WRITE
6204 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6206 +/* Types of ACLs. */
6207 +#define SMB_ACL_USER ACL_USER
6208 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6209 +#define SMB_ACL_GROUP ACL_GROUP
6210 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6211 +#define SMB_ACL_OTHER ACL_OTHER
6212 +#define SMB_ACL_MASK ACL_MASK
6214 +#define SMB_ACL_T acl_t
6216 +#define SMB_ACL_ENTRY_T acl_entry_t
6218 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6219 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6221 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6222 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6224 +#elif defined HAVE_TRU64_ACLS
6226 +/* This is for DEC/Compaq Tru64 UNIX */
6228 +#define SMB_ACL_TAG_T acl_tag_t
6229 +#define SMB_ACL_TYPE_T acl_type_t
6230 +#define SMB_ACL_PERMSET_T acl_permset_t
6231 +#define SMB_ACL_PERM_T acl_perm_t
6232 +#define SMB_ACL_READ ACL_READ
6233 +#define SMB_ACL_WRITE ACL_WRITE
6234 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6236 +/* Types of ACLs. */
6237 +#define SMB_ACL_USER ACL_USER
6238 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6239 +#define SMB_ACL_GROUP ACL_GROUP
6240 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6241 +#define SMB_ACL_OTHER ACL_OTHER
6242 +#define SMB_ACL_MASK ACL_MASK
6244 +#define SMB_ACL_T acl_t
6246 +#define SMB_ACL_ENTRY_T acl_entry_t
6248 +#define SMB_ACL_FIRST_ENTRY 0
6249 +#define SMB_ACL_NEXT_ENTRY 1
6251 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6252 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6254 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6256 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6257 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6260 +/* SVR4.2 ES/MP ACLs */
6261 +typedef int SMB_ACL_TAG_T;
6262 +typedef int SMB_ACL_TYPE_T;
6263 +typedef ushort *SMB_ACL_PERMSET_T;
6264 +typedef ushort SMB_ACL_PERM_T;
6265 +#define SMB_ACL_READ 4
6266 +#define SMB_ACL_WRITE 2
6267 +#define SMB_ACL_EXECUTE 1
6269 +/* Types of ACLs. */
6270 +#define SMB_ACL_USER USER
6271 +#define SMB_ACL_USER_OBJ USER_OBJ
6272 +#define SMB_ACL_GROUP GROUP
6273 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6274 +#define SMB_ACL_OTHER OTHER_OBJ
6275 +#define SMB_ACL_MASK CLASS_OBJ
6277 +typedef struct SMB_ACL_T {
6281 + struct acl acl[1];
6284 +typedef struct acl *SMB_ACL_ENTRY_T;
6286 +#define SMB_ACL_FIRST_ENTRY 0
6287 +#define SMB_ACL_NEXT_ENTRY 1
6289 +#define SMB_ACL_TYPE_ACCESS 0
6290 +#define SMB_ACL_TYPE_DEFAULT 1
6293 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6296 +#elif defined HAVE_HPUX_ACLS
6299 + * Based on the Solaris & UnixWare code.
6303 +#include <sys/aclv.h>
6305 +/* SVR4.2 ES/MP ACLs */
6306 +typedef int SMB_ACL_TAG_T;
6307 +typedef int SMB_ACL_TYPE_T;
6308 +typedef ushort *SMB_ACL_PERMSET_T;
6309 +typedef ushort SMB_ACL_PERM_T;
6310 +#define SMB_ACL_READ 4
6311 +#define SMB_ACL_WRITE 2
6312 +#define SMB_ACL_EXECUTE 1
6314 +/* Types of ACLs. */
6315 +#define SMB_ACL_USER USER
6316 +#define SMB_ACL_USER_OBJ USER_OBJ
6317 +#define SMB_ACL_GROUP GROUP
6318 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6319 +#define SMB_ACL_OTHER OTHER_OBJ
6320 +#define SMB_ACL_MASK CLASS_OBJ
6322 +typedef struct SMB_ACL_T {
6326 + struct acl acl[1];
6329 +typedef struct acl *SMB_ACL_ENTRY_T;
6331 +#define SMB_ACL_FIRST_ENTRY 0
6332 +#define SMB_ACL_NEXT_ENTRY 1
6334 +#define SMB_ACL_TYPE_ACCESS 0
6335 +#define SMB_ACL_TYPE_DEFAULT 1
6337 +#elif defined HAVE_IRIX_ACLS
6339 +#define SMB_ACL_TAG_T acl_tag_t
6340 +#define SMB_ACL_TYPE_T acl_type_t
6341 +#define SMB_ACL_PERMSET_T acl_permset_t
6342 +#define SMB_ACL_PERM_T acl_perm_t
6343 +#define SMB_ACL_READ ACL_READ
6344 +#define SMB_ACL_WRITE ACL_WRITE
6345 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6347 +/* Types of ACLs. */
6348 +#define SMB_ACL_USER ACL_USER
6349 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6350 +#define SMB_ACL_GROUP ACL_GROUP
6351 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6352 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6353 +#define SMB_ACL_MASK ACL_MASK
6355 +typedef struct SMB_ACL_T {
6361 +#define SMB_ACL_ENTRY_T acl_entry_t
6363 +#define SMB_ACL_FIRST_ENTRY 0
6364 +#define SMB_ACL_NEXT_ENTRY 1
6366 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6367 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6369 +#elif defined HAVE_AIX_ACLS
6371 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6373 +#include "/usr/include/acl.h"
6375 +typedef uint *SMB_ACL_PERMSET_T;
6377 +struct acl_entry_link{
6378 + struct acl_entry_link *prevp;
6379 + struct new_acl_entry *entryp;
6380 + struct acl_entry_link *nextp;
6384 +struct new_acl_entry{
6385 + unsigned short ace_len;
6386 + unsigned short ace_type;
6387 + unsigned int ace_access;
6388 + struct ace_id ace_id[1];
6391 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6392 +#define SMB_ACL_T struct acl_entry_link*
6394 +#define SMB_ACL_TAG_T unsigned short
6395 +#define SMB_ACL_TYPE_T int
6396 +#define SMB_ACL_PERM_T uint
6397 +#define SMB_ACL_READ S_IRUSR
6398 +#define SMB_ACL_WRITE S_IWUSR
6399 +#define SMB_ACL_EXECUTE S_IXUSR
6401 +/* Types of ACLs. */
6402 +#define SMB_ACL_USER ACEID_USER
6403 +#define SMB_ACL_USER_OBJ 3
6404 +#define SMB_ACL_GROUP ACEID_GROUP
6405 +#define SMB_ACL_GROUP_OBJ 4
6406 +#define SMB_ACL_OTHER 5
6407 +#define SMB_ACL_MASK 6
6410 +#define SMB_ACL_FIRST_ENTRY 1
6411 +#define SMB_ACL_NEXT_ENTRY 2
6413 +#define SMB_ACL_TYPE_ACCESS 0
6414 +#define SMB_ACL_TYPE_DEFAULT 1
6416 +#else /* No ACLs. */
6418 +/* No ACLS - fake it. */
6419 +#define SMB_ACL_TAG_T int
6420 +#define SMB_ACL_TYPE_T int
6421 +#define SMB_ACL_PERMSET_T mode_t
6422 +#define SMB_ACL_PERM_T mode_t
6423 +#define SMB_ACL_READ S_IRUSR
6424 +#define SMB_ACL_WRITE S_IWUSR
6425 +#define SMB_ACL_EXECUTE S_IXUSR
6427 +/* Types of ACLs. */
6428 +#define SMB_ACL_USER 0
6429 +#define SMB_ACL_USER_OBJ 1
6430 +#define SMB_ACL_GROUP 2
6431 +#define SMB_ACL_GROUP_OBJ 3
6432 +#define SMB_ACL_OTHER 4
6433 +#define SMB_ACL_MASK 5
6435 +typedef struct SMB_ACL_T {
6439 +typedef struct SMB_ACL_ENTRY_T {
6441 +} *SMB_ACL_ENTRY_T;
6443 +#define SMB_ACL_FIRST_ENTRY 0
6444 +#define SMB_ACL_NEXT_ENTRY 1
6446 +#define SMB_ACL_TYPE_ACCESS 0
6447 +#define SMB_ACL_TYPE_DEFAULT 1
6449 +#endif /* No ACLs. */
6450 +#endif /* _SMB_ACLS_H */
6451 --- old/testsuite/acls.test
6452 +++ new/testsuite/acls.test
6456 +# This program is distributable under the terms of the GNU GPL (see
6459 +# Test that rsync handles basic ACL preservation.
6461 +. $srcdir/testsuite/rsync.fns
6463 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6464 +case "$setfacl_nodef" in
6465 +true) test_skipped "I don't know how to use your setfacl command" ;;
6468 +makepath "$fromdir/foo"
6469 +echo something >"$fromdir/file1"
6470 +echo else >"$fromdir/file2"
6472 +files='foo file1 file2'
6474 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6475 +setfacl -m u:0:5 "$fromdir/file1"
6476 +setfacl -m u:0:5 "$fromdir/file2"
6478 +$RSYNC -avvA "$fromdir/" "$todir/"
6481 +getfacl $files >"$scratchdir/acls.txt"
6484 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6486 +# The script would have aborted on error, so getting here means we've won.
6488 --- old/testsuite/default-acls.test
6489 +++ new/testsuite/default-acls.test
6493 +# This program is distributable under the terms of the GNU GPL (see
6496 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6498 +. $srcdir/testsuite/rsync.fns
6500 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6501 +case "$setfacl_nodef" in
6502 +true) test_skipped "I don't know how to use your setfacl command" ;;
6503 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6504 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6506 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6508 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6510 + todir="$scratchdir/$1"
6512 + $setfacl_nodef "$todir"
6514 + case "$setfacl_nodef" in
6515 + *-k*) opts="-dm $2" ;;
6516 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6518 + setfacl $opts "$todir"
6520 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6521 + # even though the directory itself is outside the transfer
6522 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6523 + check_perms "$todir/to" $4 "Target $1"
6524 + check_perms "$todir/to/dir" $4 "Target $1"
6525 + check_perms "$todir/to/file" $3 "Target $1"
6526 + check_perms "$todir/to/program" $4 "Target $1"
6527 + # Make sure get_local_name doesn't mess us up when transferring only one file
6528 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6529 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6530 + # Make sure we obey default ACLs when not transferring a regular file
6531 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6532 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6535 +mkdir "$scratchdir/dir"
6536 +echo "File!" >"$scratchdir/file"
6537 +echo "#!/bin/sh" >"$scratchdir/program"
6538 +chmod 777 "$scratchdir/dir"
6539 +chmod 666 "$scratchdir/file"
6540 +chmod 777 "$scratchdir/program"
6542 +# Test some target directories
6544 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6545 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6546 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6547 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6548 +testit noda1 '' rw------- rwx------
6550 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6552 +testit noda3 '' rw-r--r-- rwxr-xr-x
6556 --- old/testsuite/devices.test
6557 +++ new/testsuite/devices.test
6558 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6559 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6561 cat <<EOT >"$chkfile"
6565 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6567 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6569 cat <<EOT >"$chkfile"
6573 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6575 @@ -58,7 +58,7 @@ sleep 1
6576 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6578 cat <<EOT >"$chkfile"
6582 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6584 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6587 cat <<EOT >"$chkfile"
6592 -hD+++++++ block2.5 => block3
6601 +hD+++++++++ block2.5 => block3
6607 if test ! -b "$fromdir/block2.5"; then
6608 sed -e '/block2\.5/d' \
6609 @@ -94,15 +94,15 @@ if test -b "$fromdir/block2.5"; then
6610 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
6612 cat <<EOT >"$chkfile"
6632 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
6634 --- old/testsuite/itemize.test
6635 +++ new/testsuite/itemize.test
6636 @@ -47,16 +47,16 @@ rm -f "$to2dir" "$to2dir.test"
6637 $RSYNC -iplr "$fromdir/" "$todir/" \
6639 sed -e "$sed_cmd" <<EOT >"$chkfile"
6642 -cd+++++++ foo/_P30_
6644 ->f+++++++ bar/baz/rsync
6645 -cd+++++++ foo/_P29_
6646 ->f+++++++ foo/config1
6647 ->f+++++++ foo/config2
6648 ->f+++++++ foo/extra
6649 -cL+++++++ foo/sym -> ../bar/baz/rsync
6652 +cd+++++++++ foo/_P30_
6653 +cd+++++++++ bar/baz/
6654 +>f+++++++++ bar/baz/rsync
6655 +cd+++++++++ foo/_P29_
6656 +>f+++++++++ foo/config1
6657 +>f+++++++++ foo/config2
6658 +>f+++++++++ foo/extra
6659 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6661 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6663 @@ -68,10 +68,10 @@ chmod 601 "$fromdir/foo/config2"
6664 $RSYNC -iplrH "$fromdir/" "$todir/" \
6666 sed -e "$sed_cmd" <<EOT >"$chkfile"
6667 ->f..T.... bar/baz/rsync
6668 ->f..T.... foo/config1
6669 ->f.sTp... foo/config2
6670 -hf..T.... foo/extra => foo/config1
6671 +>f..T...... bar/baz/rsync
6672 +>f..T...... foo/config1
6673 +>f.sTp..... foo/config2
6674 +hf..T...... foo/extra => foo/config1
6676 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6678 @@ -88,12 +88,12 @@ chmod 777 "$todir/bar/baz/rsync"
6679 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6681 sed -e "$sed_cmd" <<EOT >"$chkfile"
6682 -.d..t.... foo/_P30_
6683 -.f..tp... bar/baz/rsync
6684 -.d..t.... foo/_P29_
6685 -.f..t.... foo/config1
6686 ->fcstp... foo/config2
6687 -cL..T.... foo/sym -> ../bar/baz/rsync
6688 +.d..t...... foo/_P30_
6689 +.f..tp..... bar/baz/rsync
6690 +.d..t...... foo/_P29_
6691 +.f..t...... foo/config1
6692 +>fcstp..... foo/config2
6693 +cL..T...... foo/sym -> ../bar/baz/rsync
6695 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6697 @@ -118,15 +118,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6700 sed -e "$sed_cmd" <<EOT >"$chkfile"
6704 -.f...p... bar/baz/rsync
6707 ->f..t.... foo/config2
6709 -.L foo/sym -> ../bar/baz/rsync
6713 +.f...p..... bar/baz/rsync
6716 +>f..t...... foo/config2
6718 +.L foo/sym -> ../bar/baz/rsync
6720 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6722 @@ -145,8 +145,8 @@ touch "$todir/foo/config2"
6723 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6725 sed -e "$sed_cmd" <<EOT >"$chkfile"
6726 -.f...p... foo/config1
6727 ->f..t.... foo/config2
6728 +.f...p..... foo/config1
6729 +>f..t...... foo/config2
6731 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6733 @@ -154,15 +154,15 @@ $RSYNC -ivvplrtH --copy-dest=../to "$fro
6736 sed -e "$sed_cmd" <<EOT >"$chkfile"
6744 -hf foo/extra => foo/config1
6745 -cL foo/sym -> ../bar/baz/rsync
6753 +hf foo/extra => foo/config1
6754 +cL foo/sym -> ../bar/baz/rsync
6756 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6758 @@ -170,7 +170,7 @@ rm -rf "$to2dir"
6759 $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \
6761 sed -e "$sed_cmd" <<EOT >"$chkfile"
6762 -hf foo/extra => foo/config1
6763 +hf foo/extra => foo/config1
6765 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6767 @@ -196,15 +196,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$
6770 sed -e "$sed_cmd" <<EOT >"$chkfile"
6778 -hf foo/extra => foo/config1
6779 -$L foo/sym -> ../bar/baz/rsync
6787 +hf foo/extra => foo/config1
6788 +$L foo/sym -> ../bar/baz/rsync
6790 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6792 @@ -244,15 +244,15 @@ $RSYNC -ivvplrtH --compare-dest="$todir"
6795 sed -e "$sed_cmd" <<EOT >"$chkfile"
6804 -.L foo/sym -> ../bar/baz/rsync
6813 +.L foo/sym -> ../bar/baz/rsync
6815 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6819 @@ -35,6 +35,7 @@ extern int verbose;
6821 extern int preserve_uid;
6822 extern int preserve_gid;
6823 +extern int preserve_acls;
6824 extern int numeric_ids;
6827 @@ -271,7 +272,7 @@ void send_uid_list(int f)
6829 struct idlist *list;
6831 - if (preserve_uid) {
6832 + if (preserve_uid || preserve_acls) {
6834 /* we send sequences of uid/byte-length/name */
6835 for (list = uidlist; list; list = list->next) {
6836 @@ -288,7 +289,7 @@ void send_uid_list(int f)
6840 - if (preserve_gid) {
6841 + if (preserve_gid || preserve_acls) {
6843 for (list = gidlist; list; list = list->next) {
6845 @@ -328,18 +329,28 @@ void recv_uid_list(int f, struct file_li
6849 - if (preserve_uid && !numeric_ids) {
6850 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6851 /* read the uid list */
6852 while ((id = read_int(f)) != 0)
6853 recv_user_name(f, (uid_t)id);
6856 - if (preserve_gid && !numeric_ids) {
6857 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6858 /* read the gid list */
6859 while ((id = read_int(f)) != 0)
6860 recv_group_name(f, (gid_t)id);
6863 +#ifdef SUPPORT_ACLS
6864 + if (preserve_acls && !numeric_ids) {
6866 + while ((id = next_acl_uid(flist)) != NULL)
6867 + *id = match_uid(*id);
6868 + while ((id = next_acl_gid(flist)) != NULL)
6869 + *id = match_gid(*id);
6873 /* Now convert all the uids/gids from sender values to our values. */
6874 if (am_root && preserve_uid && !numeric_ids) {
6875 for (i = 0; i < flist->count; i++)
6878 @@ -1466,3 +1466,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6883 +void *expand_item_list(item_list *lp, size_t item_size,
6884 + const char *desc, int incr)
6886 + /* First time through, 0 <= 0, so list is expanded. */
6887 + if (lp->malloced <= lp->count) {
6889 + size_t new_size = lp->malloced;
6891 + new_size -= incr; /* increase slowly */
6892 + else if (new_size < (size_t)incr)
6896 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6897 + if (verbose >= 4) {
6898 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6899 + who_am_i(), desc, (double)new_size * item_size,
6900 + new_ptr == lp->items ? " not" : "");
6903 + out_of_memory("expand_item_list");
6905 + lp->items = new_ptr;
6906 + lp->malloced = new_size;
6908 + return (char*)lp->items + (lp->count++ * item_size);