1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 @@ -25,15 +25,15 @@ VERSION=@VERSION@
16 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
17 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
18 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
19 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
20 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
21 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
22 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
23 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
24 main.o checksum.o match.o syscall.o log.o backup.o
25 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
26 - fileio.o batch.o clientname.o chmod.o
27 + fileio.o batch.o clientname.o chmod.o acls.o
28 OBJS3=progress.o pipe.o
29 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
30 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 + * Handle passing Access Control Lists between systems.
37 + * Copyright (C) 1996 Andrew Tridgell
38 + * Copyright (C) 1996 Paul Mackerras
39 + * Copyright (C) 2006 Wayne Davison
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License as published by
43 + * the Free Software Foundation; either version 2 of the License, or
44 + * (at your option) any later version.
46 + * This program is distributed in the hope that it will be useful,
47 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 + * GNU General Public License for more details.
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
57 +#include "lib/sysacls.h"
63 +extern int orig_umask;
64 +extern int preserve_acls;
65 +extern unsigned int file_struct_len;
67 +/* === ACL structures === */
79 +#define NO_ENTRY ((uchar)0x80)
80 +typedef struct rsync_acl {
83 + /* These will be NO_ENTRY if there's no such entry. */
95 +static const rsync_acl empty_rsync_acl = {
96 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
99 +static item_list access_acl_list = EMPTY_ITEM_LIST;
100 +static item_list default_acl_list = EMPTY_ITEM_LIST;
102 +/* === Calculations on ACL types === */
104 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
106 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
107 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
108 + : "unknown SMB_ACL_TYPE_T";
111 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
112 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
114 +static int count_racl_entries(const rsync_acl *racl)
116 + return racl->users.count + racl->groups.count
117 + + (racl->user_obj != NO_ENTRY)
118 + + (racl->group_obj != NO_ENTRY)
119 + + (racl->mask != NO_ENTRY)
120 + + (racl->other != NO_ENTRY);
123 +static int calc_sacl_entries(const rsync_acl *racl)
125 + /* A System ACL always gets user/group/other permission entries. */
126 + return racl->users.count + racl->groups.count
127 +#ifdef ACLS_NEED_MASK
130 + + (racl->mask != NO_ENTRY) + 3;
134 +/* Extracts and returns the permission bits from the ACL. This cannot be
135 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
136 +static int rsync_acl_get_perms(const rsync_acl *racl)
138 + return (racl->user_obj << 6)
139 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
143 +/* Removes the permission-bit entries from the ACL because these
144 + * can be reconstructed from the file's mode. */
145 +static void rsync_acl_strip_perms(rsync_acl *racl)
147 + racl->user_obj = NO_ENTRY;
148 + if (racl->mask == NO_ENTRY)
149 + racl->group_obj = NO_ENTRY;
151 + if (racl->group_obj == racl->mask)
152 + racl->group_obj = NO_ENTRY;
153 + racl->mask = NO_ENTRY;
155 + racl->other = NO_ENTRY;
158 +/* Given an empty rsync_acl, fake up the permission bits. */
159 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
161 + racl->user_obj = (mode >> 6) & 7;
162 + racl->group_obj = (mode >> 3) & 7;
163 +#ifdef ACLS_NEED_MASK
164 + racl->mask = (mode >> 3) & 7;
166 + racl->other = mode & 7;
169 +/* === Rsync ACL functions === */
171 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
173 + id_access *ida1, *ida2;
174 + int count = ial1->count;
175 + if (count != ial2->count)
179 + for (; count--; ida1++, ida2++) {
180 + if (ida1->access != ida2->access || ida1->id != ida2->id)
186 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
188 + return (racl1->user_obj == racl2->user_obj
189 + && racl1->group_obj == racl2->group_obj
190 + && racl1->mask == racl2->mask
191 + && racl1->other == racl2->other
192 + && ida_entries_equal(&racl1->users, &racl2->users)
193 + && ida_entries_equal(&racl1->groups, &racl2->groups));
196 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
197 + * the ACL will be handled by the normal mode-preservation code. This is
198 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
199 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
200 + * that it might have several of its perm objects set to NO_ENTRY. */
201 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
202 + const rsync_acl *racl2, mode_t m)
204 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
205 + return False; /* One has a mask and the other doesn't */
207 + /* When there's a mask, the group_obj becomes an extended entry. */
208 + if (racl1->mask != NO_ENTRY) {
209 + /* A condensed rsync_acl with a mask can only have no
210 + * group_obj when it was identical to the mask. This
211 + * means that it was also identical to the group attrs
212 + * from the mode. */
213 + if (racl2->group_obj == NO_ENTRY) {
214 + if (racl1->group_obj != ((m >> 3) & 7))
216 + } else if (racl1->group_obj != racl2->group_obj)
219 + return ida_entries_equal(&racl1->users, &racl2->users)
220 + && ida_entries_equal(&racl1->groups, &racl2->groups);
223 +static void rsync_acl_free(rsync_acl *racl)
225 + if (racl->users.idas)
226 + free(racl->users.idas);
227 + if (racl->groups.idas)
228 + free(racl->groups.idas);
229 + *racl = empty_rsync_acl;
232 +void free_acl(statx *sxp)
234 + if (sxp->acc_acl) {
235 + rsync_acl_free(sxp->acc_acl);
236 + free(sxp->acc_acl);
237 + sxp->acc_acl = NULL;
239 + if (sxp->def_acl) {
240 + rsync_acl_free(sxp->def_acl);
241 + free(sxp->def_acl);
242 + sxp->def_acl = NULL;
246 +static int id_access_sorter(const void *r1, const void *r2)
248 + id_access *ida1 = (id_access *)r1;
249 + id_access *ida2 = (id_access *)r2;
250 + id_t rid1 = ida1->id, rid2 = ida2->id;
251 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
254 +static void sort_ida_entries(ida_entries *idal)
258 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
261 +/* Transfer the count id_access items out of the temp_ida_list into either
262 + * the users or groups ida_entries list in racl. */
263 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
268 + if (temp_ida_list->count) {
269 + int cnt = temp_ida_list->count;
270 + id_access *temp_idas = temp_ida_list->items;
271 + if (!(idas = new_array(id_access, cnt)))
272 + out_of_memory("save_idas");
273 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
277 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
280 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
281 + exit_cleanup(RERR_UNSUPPORTED);
283 + ent->count = temp_ida_list->count;
286 + /* Truncate the temporary list now that its idas have been saved. */
287 + temp_ida_list->count = 0;
290 +/* === System ACLs === */
292 +/* Unpack system acl -> rsync acl verbatim. Return whether we succeeded. */
293 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
295 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
296 + SMB_ACL_TAG_T prior_list_type = 0;
297 + SMB_ACL_ENTRY_T entry;
298 + const char *errfun;
301 + *racl = empty_rsync_acl;
302 + errfun = "sys_acl_get_entry";
303 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
305 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
306 + SMB_ACL_TAG_T tag_type;
307 + SMB_ACL_PERMSET_T permset;
311 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
312 + errfun = "sys_acl_get_tag_type";
315 + if ((rc = sys_acl_get_permset(entry, &permset))) {
316 + errfun = "sys_acl_get_tag_type";
319 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
320 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
321 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
322 + /* continue == done with entry; break == store in temporary ida list */
323 + switch (tag_type) {
324 + case SMB_ACL_USER_OBJ:
325 + if (racl->user_obj == NO_ENTRY)
326 + racl->user_obj = access;
328 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
332 + case SMB_ACL_GROUP_OBJ:
333 + if (racl->group_obj == NO_ENTRY)
334 + racl->group_obj = access;
336 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
338 + case SMB_ACL_GROUP:
341 + if (racl->mask == NO_ENTRY)
342 + racl->mask = access;
344 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
346 + case SMB_ACL_OTHER:
347 + if (racl->other == NO_ENTRY)
348 + racl->other = access;
350 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
353 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
356 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
357 + errfun = "sys_acl_get_tag_type";
361 + if (tag_type != prior_list_type) {
362 + if (prior_list_type)
363 + save_idas(&temp_ida_list, racl, prior_list_type);
364 + prior_list_type = tag_type;
366 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
367 + ida->id = *((id_t *)qualifier);
368 + ida->access = access;
369 + sys_acl_free_qualifier(qualifier, tag_type);
372 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
373 + rsync_acl_free(racl);
376 + if (prior_list_type)
377 + save_idas(&temp_ida_list, racl, prior_list_type);
379 + sort_ida_entries(&racl->users);
380 + sort_ida_entries(&racl->groups);
382 +#ifdef ACLS_NEED_MASK
383 + if (!racl->users.count && !racl->groups.count) {
384 + /* Throw away a superfluous mask, but mask off the
385 + * group perms with it first. */
386 + racl->group_obj &= racl->mask;
387 + racl->mask = NO_ENTRY;
394 +/* Synactic sugar for system calls */
396 +#define CALL_OR_ERROR(func,args,str) \
404 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
405 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
407 +/* Store the permissions in the system ACL entry. */
408 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
410 + const char *errfun = NULL;
411 + SMB_ACL_PERMSET_T permset;
413 + COE( sys_acl_get_permset,(entry, &permset) );
414 + COE( sys_acl_clear_perms,(permset) );
416 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
418 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
420 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
421 + COE( sys_acl_set_permset,(entry, permset) );
426 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
430 +/* Pack rsync acl -> system acl verbatim. Return whether we succeeded. */
431 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
433 +#ifdef ACLS_NEED_MASK
438 + const char *errfun = NULL;
439 + SMB_ACL_ENTRY_T entry;
441 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
442 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
446 + COE( sys_acl_create_entry,(smb_acl, &entry) );
447 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
448 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
450 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
451 + COE( sys_acl_create_entry,(smb_acl, &entry) );
452 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
453 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
454 + COE2( store_access_in_entry,(ida->access, entry) );
457 + COE( sys_acl_create_entry,(smb_acl, &entry) );
458 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
459 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
461 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
462 + COE( sys_acl_create_entry,(smb_acl, &entry) );
463 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
464 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
465 + COE2( store_access_in_entry,(ida->access, entry) );
468 +#ifdef ACLS_NEED_MASK
469 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
470 + COE( sys_acl_create_entry,(smb_acl, &entry) );
471 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
472 + COE2( store_access_in_entry,(mask_bits, entry) );
474 + if (racl->mask != NO_ENTRY) {
475 + COE( sys_acl_create_entry,(smb_acl, &entry) );
476 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
477 + COE2( store_access_in_entry,(racl->mask, entry) );
481 + COE( sys_acl_create_entry,(smb_acl, &entry) );
482 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
483 + COE2( store_access_in_entry,(racl->other & 7, entry) );
486 + if (sys_acl_valid(*smb_acl) < 0)
487 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
494 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
496 + sys_acl_free_acl(*smb_acl);
500 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
501 + const item_list *racl_list,
502 + const rsync_acl *racl)
504 + static int access_match = -1, default_match = -1;
505 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
506 + size_t count = racl_list->count;
508 + /* If this is the first time through or we didn't match the last
509 + * time, then start at the end of the list, which should be the
510 + * best place to start hunting. */
512 + *match = racl_list->count - 1;
514 + rsync_acl *base = racl_list->items;
515 + if (rsync_acl_equal(base + *match, racl))
518 + *match = racl_list->count - 1;
525 +/* Return the ACL(s) for the given filename. */
526 +int get_acl(const char *fname, statx *sxp)
528 + SMB_ACL_TYPE_T type;
530 + if (S_ISLNK(sxp->st.st_mode))
533 + type = SMB_ACL_TYPE_ACCESS;
535 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
536 + rsync_acl *racl = new(rsync_acl);
539 + out_of_memory("get_acl");
540 + if (type == SMB_ACL_TYPE_ACCESS)
541 + sxp->acc_acl = racl;
543 + sxp->def_acl = racl;
546 + BOOL ok = unpack_smb_acl(racl, sacl);
548 + sys_acl_free_acl(sacl);
553 + } else if (errno == ENOTSUP) {
554 + /* ACLs are not supported, so pretend we have a basic ACL. */
555 + *racl = empty_rsync_acl;
556 + if (type == SMB_ACL_TYPE_ACCESS)
557 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
559 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
560 + fname, str_acl_type(type));
564 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
569 +/* === Send functions === */
571 +/* The general strategy with the tag_type <-> character mapping is that
572 + * lowercase implies that no qualifier follows, where uppercase does.
573 + * A similar idiom for the acl type (access or default) itself, but
574 + * lowercase in this instance means there's no ACL following, so the
575 + * ACL is a repeat, so the receiver should reuse the last of the same
578 +/* Send the ida list over the file descriptor. */
579 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
582 + size_t count = idal->count;
583 + for (ida = idal->idas; count--; ida++) {
584 + write_byte(f, tag_char);
585 + write_byte(f, ida->access);
586 + write_int(f, ida->id);
587 + /* FIXME: sorta wasteful: we should maybe buffer as
588 + * many ids as max(ACL_USER + ACL_GROUP) objects to
589 + * keep from making so many calls. */
590 + if (tag_char == 'U')
597 +/* Send an rsync acl over the file descriptor. */
598 +static void send_rsync_acl(int f, const rsync_acl *racl)
600 + size_t count = count_racl_entries(racl);
601 + write_int(f, count);
602 + if (racl->user_obj != NO_ENTRY) {
603 + write_byte(f, 'u');
604 + write_byte(f, racl->user_obj);
606 + send_ida_entries(f, &racl->users, 'U');
607 + if (racl->group_obj != NO_ENTRY) {
608 + write_byte(f, 'g');
609 + write_byte(f, racl->group_obj);
611 + send_ida_entries(f, &racl->groups, 'G');
612 + if (racl->mask != NO_ENTRY) {
613 + write_byte(f, 'm');
614 + write_byte(f, racl->mask);
616 + if (racl->other != NO_ENTRY) {
617 + write_byte(f, 'o');
618 + write_byte(f, racl->other);
622 +/* Send the ACL from the statx structure down the indicated file descriptor.
623 + * This also frees the ACL data. */
624 +void send_acl(statx *sxp, int f)
626 + SMB_ACL_TYPE_T type;
627 + rsync_acl *racl, *new_racl;
628 + item_list *racl_list;
631 + if (S_ISLNK(sxp->st.st_mode))
634 + type = SMB_ACL_TYPE_ACCESS;
635 + racl = sxp->acc_acl;
636 + racl_list = &access_acl_list;
639 + racl = new(rsync_acl);
641 + out_of_memory("send_acl");
642 + *racl = empty_rsync_acl;
643 + if (type == SMB_ACL_TYPE_ACCESS) {
644 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
645 + sxp->acc_acl = racl;
647 + sxp->def_acl = racl;
650 + /* Discard a superfluous mask. */
651 + if (racl->mask != NO_ENTRY && !racl->users.count && !racl->groups.count)
652 + racl->mask = NO_ENTRY;
653 + /* Avoid sending values that can be inferred from other data,
654 + * but only when preserve_acls == 1 (it is 2 when we must be
655 + * backward compatible with older acls.diff versions). */
656 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
657 + rsync_acl_strip_perms(racl);
658 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
659 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
662 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
663 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
664 + send_rsync_acl(f, racl);
666 + *racl = empty_rsync_acl;
668 + racl = sxp->def_acl;
669 + racl_list = &default_acl_list;
670 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
675 +/* === Receive functions === */
677 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
679 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
680 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
681 + uchar computed_mask_bits = 0;
685 + *racl = empty_rsync_acl;
687 + if (!(count = read_int(f)))
691 + char tag = read_byte(f);
692 + uchar access = read_byte(f);
693 + if (access & ~ (4 | 2 | 1)) {
694 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
696 + exit_cleanup(RERR_STREAMIO);
700 + if (racl->user_obj != NO_ENTRY) {
701 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
702 + exit_cleanup(RERR_STREAMIO);
704 + racl->user_obj = access;
707 + tag_type = SMB_ACL_USER;
710 + if (racl->group_obj != NO_ENTRY) {
711 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
712 + exit_cleanup(RERR_STREAMIO);
714 + racl->group_obj = access;
717 + tag_type = SMB_ACL_GROUP;
720 + if (racl->mask != NO_ENTRY) {
721 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
722 + exit_cleanup(RERR_STREAMIO);
724 + racl->mask = access;
727 + if (racl->other != NO_ENTRY) {
728 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
729 + exit_cleanup(RERR_STREAMIO);
731 + racl->other = access;
734 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
736 + exit_cleanup(RERR_STREAMIO);
738 + if (tag_type != prior_list_type) {
739 + if (prior_list_type)
740 + save_idas(&temp_ida_list, racl, prior_list_type);
741 + prior_list_type = tag_type;
743 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
744 + ida->access = access;
745 + ida->id = read_int(f);
746 + computed_mask_bits |= access;
748 + if (prior_list_type)
749 + save_idas(&temp_ida_list, racl, prior_list_type);
751 + if (type == SMB_ACL_TYPE_DEFAULT) {
752 + /* Ensure that these are never unset. */
753 + if (racl->user_obj == NO_ENTRY)
754 + racl->user_obj = 7;
755 + if (racl->group_obj == NO_ENTRY)
756 + racl->group_obj = 0;
757 + if (racl->other == NO_ENTRY)
761 + if (!racl->users.count && !racl->groups.count) {
762 + /* If we received a superfluous mask, throw it away. */
763 + if (racl->mask != NO_ENTRY) {
764 + /* Mask off the group perms with it first. */
765 + racl->group_obj &= racl->mask | NO_ENTRY;
766 + racl->mask = NO_ENTRY;
768 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
769 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
772 +/* Receive the ACL info the sender has included for this file-list entry. */
773 +void receive_acl(struct file_struct *file, int f)
775 + SMB_ACL_TYPE_T type;
776 + item_list *racl_list;
779 + if (S_ISLNK(file->mode))
782 + type = SMB_ACL_TYPE_ACCESS;
783 + racl_list = &access_acl_list;
784 + ndx_ptr = (char*)file + file_struct_len;
786 + char tag = read_byte(f);
789 + if (tag == 'A' || tag == 'a') {
790 + if (type != SMB_ACL_TYPE_ACCESS) {
791 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
792 + f_name(file, NULL));
793 + exit_cleanup(RERR_STREAMIO);
795 + } else if (tag == 'D' || tag == 'd') {
796 + if (type == SMB_ACL_TYPE_ACCESS) {
797 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
798 + f_name(file, NULL));
799 + exit_cleanup(RERR_STREAMIO);
802 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
803 + f_name(file, NULL), tag);
804 + exit_cleanup(RERR_STREAMIO);
806 + if (tag == 'A' || tag == 'D') {
808 + ndx = racl_list->count;
809 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
810 + receive_rsync_acl(&duo_item->racl, f, type);
811 + duo_item->sacl = NULL;
814 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
815 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
816 + f_name(file, NULL), str_acl_type(type), ndx);
817 + exit_cleanup(RERR_STREAMIO);
820 + SIVAL(ndx_ptr, 0, ndx);
821 + racl_list = &default_acl_list;
823 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
826 +/* Turn the ACL data in statx into cached ACL data, setting the index
827 + * values in the file struct. */
828 +void cache_acl(struct file_struct *file, statx *sxp)
830 + SMB_ACL_TYPE_T type;
832 + item_list *racl_list;
836 + if (S_ISLNK(file->mode))
839 + type = SMB_ACL_TYPE_ACCESS;
840 + racl = sxp->acc_acl;
841 + racl_list = &access_acl_list;
842 + ndx_ptr = (char*)file + file_struct_len;
846 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
848 + ndx = racl_list->count;
849 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
850 + new_duo->racl = *racl;
851 + new_duo->sacl = NULL;
852 + *racl = empty_rsync_acl;
854 + SIVAL(ndx_ptr, 0, ndx);
855 + racl = sxp->def_acl;
856 + racl_list = &default_acl_list;
858 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
863 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
865 + SMB_ACL_ENTRY_T entry;
866 + const char *errfun;
869 + if (S_ISDIR(mode)) {
870 + /* If the sticky bit is going on, it's not safe to allow all
871 + * the new ACLs to go into effect before it gets set. */
872 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
873 + if (mode & S_ISVTX)
876 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
879 + /* If setuid or setgid is going off, it's not safe to allow all
880 + * the new ACLs to go into effect before they get cleared. */
881 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
882 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
887 + errfun = "sys_acl_get_entry";
888 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
890 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
891 + SMB_ACL_TAG_T tag_type;
892 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
893 + errfun = "sys_acl_get_tag_type";
896 + switch (tag_type) {
897 + case SMB_ACL_USER_OBJ:
898 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
900 + case SMB_ACL_GROUP_OBJ:
901 + /* group is only empty when identical to group perms. */
902 + if (racl->group_obj != NO_ENTRY)
904 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
907 +#ifndef ACLS_NEED_MASK
908 + /* mask is only empty when we don't need it. */
909 + if (racl->mask == NO_ENTRY)
912 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
914 + case SMB_ACL_OTHER:
915 + COE2( store_access_in_entry,(mode & 7, entry) );
922 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
928 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
929 + /* Ensure that chmod() will be called to restore any lost setid bits. */
930 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
931 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
932 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
935 + /* Return the mode of the file on disk, as we will set them. */
936 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
939 +/* Set ACL on indicated filename.
941 + * This sets extended access ACL entries and default ACLs. If convenient,
942 + * it sets permission bits along with the access ACLs and signals having
943 + * done so by modifying sxp->st.st_mode.
945 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
946 + * with fname set to NULL to just check if the ACLs are unchanged. */
947 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
950 + SMB_ACL_TYPE_T type;
953 + if (S_ISLNK(file->mode))
956 + type = SMB_ACL_TYPE_ACCESS;
957 + ndx_ptr = (char*)file + file_struct_len;
961 + int32 ndx = IVAL(ndx_ptr, 0);
965 + if (type == SMB_ACL_TYPE_ACCESS) {
966 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
968 + duo_item = access_acl_list.items;
971 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
973 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
975 + duo_item = default_acl_list.items;
978 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
982 + if (!dry_run && fname) {
983 + if (type == SMB_ACL_TYPE_DEFAULT
984 + && duo_item->racl.user_obj == NO_ENTRY) {
985 + if (sys_acl_delete_def_file(fname) < 0) {
986 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
992 + mode_t cur_mode = sxp->st.st_mode;
993 + if (!duo_item->sacl
994 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
998 + if (type == SMB_ACL_TYPE_ACCESS) {
999 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
1000 + cur_mode, file->mode);
1001 + if (cur_mode == ~0u)
1004 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
1005 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1006 + fname, str_acl_type(type));
1010 + if (type == SMB_ACL_TYPE_ACCESS)
1011 + sxp->st.st_mode = cur_mode;
1014 + if (unchanged == 1)
1016 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1021 +/* === Enumeration functions for uid mapping === */
1023 +/* Context -- one and only one. Should be cycled through once on uid
1024 + * mapping and once on gid mapping. */
1025 +static item_list *_enum_racl_lists[] = {
1026 + &access_acl_list, &default_acl_list, NULL
1029 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1030 +static int enum_ida_index = 0;
1031 +static size_t enum_racl_index = 0;
1033 +/* This returns the next tag_type id from the given acl for the next entry,
1034 + * or it returns 0 if there are no more tag_type ids in the acl. */
1035 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1037 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1038 + if (enum_ida_index < idal->count) {
1039 + id_access *ida = &idal->idas[enum_ida_index++];
1042 + enum_ida_index = 0;
1046 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1048 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1050 + acl_duo *duo_item = racl_list->items;
1051 + duo_item += enum_racl_index;
1052 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1055 + enum_racl_index = 0;
1059 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1061 + for (; *enum_racl_list; enum_racl_list++) {
1062 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1066 + enum_racl_list = &_enum_racl_lists[0];
1070 +id_t *next_acl_uid()
1072 + return next_acl_list_id(SMB_ACL_USER);
1075 +id_t *next_acl_gid()
1077 + return next_acl_list_id(SMB_ACL_GROUP);
1080 +/* This is used by dest_mode(). */
1081 +int default_perms_for_dir(const char *dir)
1090 + perms = ACCESSPERMS & ~orig_umask;
1091 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1092 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1093 + if (sacl == NULL) {
1094 + /* Couldn't get an ACL. Darn. */
1097 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1101 + /* We're doing a dry run, so the containing directory
1102 + * wasn't actually created. Don't worry about it. */
1105 + /* Otherwise fall through. */
1107 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1108 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1114 + ok = unpack_smb_acl(&racl, sacl);
1115 + sys_acl_free_acl(sacl);
1117 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1121 + /* Apply the permission-bit entries of the default ACL, if any. */
1122 + if (racl.user_obj != NO_ENTRY) {
1123 + perms = rsync_acl_get_perms(&racl);
1125 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1128 + rsync_acl_free(&racl);
1132 +#endif /* SUPPORT_ACLS */
1135 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1136 extern char *backup_dir;
1139 +extern int preserve_acls;
1140 extern int preserve_devices;
1141 extern int preserve_specials;
1142 extern int preserve_links;
1143 @@ -94,7 +95,8 @@ path
1144 ****************************************************************************/
1145 static int make_bak_dir(char *fullpath)
1149 + struct file_struct *file;
1150 char *rel = fullpath + backup_dir_len;
1151 char *end = rel + strlen(rel);
1153 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1155 /* Try to transfer the directory settings of the
1156 * actual dir that the files are coming from. */
1157 - if (do_stat(rel, &st) < 0) {
1158 + if (do_stat(rel, &sx.st) < 0) {
1159 rsyserr(FERROR, errno,
1160 "make_bak_dir stat %s failed",
1163 - do_lchown(fullpath, st.st_uid, st.st_gid);
1164 - do_chmod(fullpath, st.st_mode);
1165 +#ifdef SUPPORT_ACLS
1166 + sx.acc_acl = sx.def_acl = NULL;
1168 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1170 +#ifdef SUPPORT_ACLS
1171 + if (preserve_acls) {
1172 + get_acl(rel, &sx);
1173 + cache_acl(file, &sx);
1176 + set_file_attrs(fullpath, file, NULL, 0);
1181 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1182 * We will move the file to be deleted into a parallel directory tree. */
1183 static int keep_backup(char *fname)
1187 struct file_struct *file;
1192 /* return if no file to keep */
1193 - if (do_lstat(fname, &st) < 0)
1194 + if (do_lstat(fname, &sx.st) < 0)
1196 +#ifdef SUPPORT_ACLS
1197 + sx.acc_acl = sx.def_acl = NULL;
1200 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1201 return 1; /* the file could have disappeared */
1202 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1203 if (!(buf = get_backup_name(fname)))
1206 +#ifdef SUPPORT_ACLS
1207 + if (preserve_acls) {
1208 + get_acl(fname, &sx);
1209 + cache_acl(file, &sx);
1213 /* Check to see if this is a device file, or link */
1214 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1215 || (preserve_specials && IS_SPECIAL(file->mode))) {
1216 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1217 if (robust_move(fname, buf) != 0) {
1218 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1219 full_fname(fname), buf);
1220 - } else if (st.st_nlink > 1) {
1221 + } else if (sx.st.st_nlink > 1) {
1222 /* If someone has hard-linked the file into the backup
1223 * dir, rename() might return success but do nothing! */
1224 robust_unlink(fname); /* Just in case... */
1225 --- old/configure.in
1226 +++ new/configure.in
1227 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1228 AC_CHECK_LIB(resolv, strcasecmp)
1231 +AC_CHECK_FUNCS(aclsort)
1232 +if test x"$ac_cv_func_aclsort" = x"no"; then
1233 + AC_CHECK_LIB(sec, aclsort)
1236 dnl At the moment we don't test for a broken memcmp(), because all we
1237 dnl need to do is test for equality, not comparison, and it seems that
1238 dnl every platform has a memcmp that can do at least that.
1239 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1240 AC_SUBST(CC_SHOBJ_FLAG)
1241 AC_SUBST(BUILD_POPT)
1243 +AC_CHECK_HEADERS(sys/acl.h)
1244 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1245 +#################################################
1246 +# check for ACL support
1248 +AC_MSG_CHECKING(whether to support ACLs)
1249 +AC_ARG_ENABLE(acl-support,
1250 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1251 +[ case "$enableval" in
1254 + case "$host_os" in
1256 + AC_MSG_RESULT(Using UnixWare ACLs)
1257 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1259 + *solaris*|*cygwin*)
1260 + AC_MSG_RESULT(Using solaris ACLs)
1261 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1264 + AC_MSG_RESULT(Using HPUX ACLs)
1265 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1268 + AC_MSG_RESULT(Using IRIX ACLs)
1269 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1272 + AC_MSG_RESULT(Using AIX ACLs)
1273 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1276 + AC_MSG_RESULT(Using Tru64 ACLs)
1277 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1278 + LIBS="$LIBS -lpacl"
1281 + AC_MSG_RESULT(ACLs requested -- running tests)
1282 + AC_CHECK_LIB(acl,acl_get_file)
1283 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1284 + AC_TRY_LINK([#include <sys/types.h>
1285 +#include <sys/acl.h>],
1286 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1287 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1288 + AC_MSG_CHECKING(ACL test results)
1289 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1290 + AC_MSG_RESULT(Using posix ACLs)
1291 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1292 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1293 + AC_TRY_LINK([#include <sys/types.h>
1294 +#include <sys/acl.h>],
1295 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1296 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1297 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1298 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1301 + AC_MSG_ERROR(Failed to find ACL support)
1308 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1311 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1315 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1320 @@ -41,6 +41,7 @@ extern int curr_dir_depth;
1321 extern int one_file_system;
1322 extern int copy_dirlinks;
1323 extern int keep_dirlinks;
1324 +extern int preserve_acls;
1325 extern int preserve_links;
1326 extern int preserve_hard_links;
1327 extern int preserve_devices;
1328 @@ -134,6 +135,8 @@ static void list_file_entry(struct file_
1330 permstring(permbuf, f->mode);
1332 + /* TODO: indicate '+' if the entry has an ACL. */
1334 #ifdef SUPPORT_LINKS
1335 if (preserve_links && S_ISLNK(f->mode)) {
1336 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1337 @@ -492,6 +495,9 @@ static struct file_struct *receive_file_
1338 char thisname[MAXPATHLEN];
1339 unsigned int l1 = 0, l2 = 0;
1340 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1341 +#ifdef SUPPORT_ACLS
1345 char *basename, *dirname, *bp;
1346 struct file_struct *file;
1347 @@ -595,13 +601,27 @@ static struct file_struct *receive_file_
1349 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1351 +#ifdef SUPPORT_ACLS
1352 + /* We need one or two index int32s when we're preserving ACLs. */
1353 + if (preserve_acls)
1354 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
1359 alloc_len = file_struct_len + dirname_len + basename_len
1360 +#ifdef SUPPORT_ACLS
1363 + linkname_len + sum_len;
1364 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1366 file = (struct file_struct *)bp;
1367 memset(bp, 0, file_struct_len);
1368 bp += file_struct_len;
1369 +#ifdef SUPPORT_ACLS
1373 file->modtime = modtime;
1374 file->length = file_length;
1375 @@ -694,6 +714,11 @@ static struct file_struct *receive_file_
1376 read_buf(f, sum, checksum_len);
1379 +#ifdef SUPPORT_ACLS
1380 + if (preserve_acls)
1381 + receive_acl(file, f);
1387 @@ -943,6 +968,9 @@ static struct file_struct *send_file_nam
1388 unsigned short flags)
1390 struct file_struct *file;
1391 +#ifdef SUPPORT_ACLS
1395 file = make_file(fname, flist, stp, flags,
1396 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1397 @@ -952,6 +980,15 @@ static struct file_struct *send_file_nam
1398 if (chmod_modes && !S_ISLNK(file->mode))
1399 file->mode = tweak_mode(file->mode, chmod_modes);
1401 +#ifdef SUPPORT_ACLS
1402 + if (preserve_acls) {
1403 + sx.st.st_mode = file->mode;
1404 + sx.acc_acl = sx.def_acl = NULL;
1405 + if (get_acl(fname, &sx) < 0)
1410 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1412 flist_expand(flist);
1413 @@ -959,6 +996,15 @@ static struct file_struct *send_file_nam
1414 if (file->basename[0]) {
1415 flist->files[flist->count++] = file;
1416 send_file_entry(file, f);
1417 +#ifdef SUPPORT_ACLS
1418 + if (preserve_acls)
1422 +#ifdef SUPPORT_ACLS
1423 + if (preserve_acls)
1431 @@ -36,6 +36,7 @@ extern int recurse;
1432 extern int relative_paths;
1433 extern int implied_dirs;
1434 extern int keep_dirlinks;
1435 +extern int preserve_acls;
1436 extern int preserve_links;
1437 extern int preserve_devices;
1438 extern int preserve_specials;
1439 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1440 extern int max_delete;
1441 extern int force_delete;
1442 extern int one_file_system;
1443 +extern mode_t orig_umask;
1444 extern struct stats stats;
1445 extern dev_t filesystem_dev;
1446 extern char *backup_dir;
1447 @@ -317,22 +319,27 @@ static void do_delete_pass(struct file_l
1448 rprintf(FINFO, " \r");
1451 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1452 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1455 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1456 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1459 - if (am_root && preserve_uid && st->st_uid != file->uid)
1460 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1463 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1464 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1467 +#ifdef SUPPORT_ACLS
1468 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1475 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1476 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1477 int32 iflags, uchar fnamecmp_type, char *xname)
1479 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1480 @@ -340,19 +347,23 @@ void itemize(struct file_struct *file, i
1481 : S_ISDIR(file->mode) ? !omit_dir_times
1482 : !S_ISLNK(file->mode);
1484 - if (S_ISREG(file->mode) && file->length != st->st_size)
1485 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1486 iflags |= ITEM_REPORT_SIZE;
1487 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1488 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1489 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1490 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1491 iflags |= ITEM_REPORT_TIME;
1492 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1493 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1494 iflags |= ITEM_REPORT_PERMS;
1495 - if (preserve_uid && am_root && file->uid != st->st_uid)
1496 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1497 iflags |= ITEM_REPORT_OWNER;
1498 if (preserve_gid && file->gid != GID_NONE
1499 - && st->st_gid != file->gid)
1500 + && sxp->st.st_gid != file->gid)
1501 iflags |= ITEM_REPORT_GROUP;
1502 +#ifdef SUPPORT_ACLS
1503 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1504 + iflags |= ITEM_REPORT_ACL;
1507 iflags |= ITEM_IS_NEW;
1509 @@ -603,7 +614,7 @@ void check_for_finished_hlinks(int itemi
1510 * handling the file, -1 if no dest-linking occurred, or a non-negative
1511 * value if we found an alternate basis file. */
1512 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1513 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1514 + char *cmpbuf, statx *sxp, int itemizing,
1515 int maybe_ATTRS_REPORT, enum logcode code)
1517 int save_ignore_times = ignore_times;
1518 @@ -618,7 +629,7 @@ static int try_dests_reg(struct file_str
1521 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1522 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1523 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1525 switch (match_level) {
1527 @@ -626,16 +637,20 @@ static int try_dests_reg(struct file_str
1531 - if (!unchanged_file(cmpbuf, file, stp))
1532 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1538 - if (!unchanged_attrs(file, stp))
1539 +#ifdef SUPPORT_ACLS
1540 + if (preserve_acls)
1541 + get_acl(cmpbuf, sxp);
1543 + if (!unchanged_attrs(file, sxp))
1546 - && cmp_time(stp->st_mtime, file->modtime))
1547 + && cmp_time(sxp->st.st_mtime, file->modtime))
1551 @@ -653,22 +668,27 @@ static int try_dests_reg(struct file_str
1552 if (j != best_match) {
1554 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1555 - if (link_stat(cmpbuf, stp, 0) < 0)
1556 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1561 if (match_level == 3 && !copy_dest) {
1563 - if (hard_link_one(file, ndx, fname, 0, stp,
1564 + if (hard_link_one(file, ndx, fname, 0, sxp,
1566 itemizing && verbose > 1,
1569 if (preserve_hard_links && file->link_u.links)
1570 hard_link_cluster(file, ndx, itemizing, code);
1571 - } else if (itemizing)
1572 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1573 + } else if (itemizing) {
1574 +#ifdef SUPPORT_ACLS
1575 + if (preserve_acls && !ACL_READY(*sxp))
1576 + get_acl(fname, sxp);
1578 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1580 if (verbose > 1 && maybe_ATTRS_REPORT) {
1581 code = daemon_log_format_has_i || dry_run
1583 @@ -687,8 +707,13 @@ static int try_dests_reg(struct file_str
1588 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1590 +#ifdef SUPPORT_ACLS
1591 + if (preserve_acls && !ACL_READY(*sxp))
1592 + get_acl(fname, sxp);
1594 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1596 set_file_attrs(fname, file, NULL, 0);
1597 if (maybe_ATTRS_REPORT
1598 && ((!itemizing && verbose && match_level == 2)
1599 @@ -713,13 +738,18 @@ static int try_dests_non(struct file_str
1602 char fnamebuf[MAXPATHLEN];
1608 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1609 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1610 - || !unchanged_attrs(file, &st))
1611 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1613 +#ifdef SUPPORT_ACLS
1614 + if (preserve_acls)
1615 + get_acl(fnamebuf, &sx);
1617 + if (!unchanged_attrs(file, &sx))
1619 if (S_ISLNK(file->mode)) {
1620 #ifdef SUPPORT_LINKS
1621 @@ -732,10 +762,10 @@ static int try_dests_non(struct file_str
1624 } else if (IS_SPECIAL(file->mode)) {
1625 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1626 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1628 } else if (IS_DEVICE(file->mode)) {
1629 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1630 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1634 @@ -764,7 +794,15 @@ static int try_dests_non(struct file_str
1635 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1636 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1637 char *lp = link_dest ? "" : NULL;
1638 - itemize(file, ndx, 0, &st, changes, 0, lp);
1639 +#ifdef SUPPORT_ACLS
1640 + if (preserve_acls)
1641 + get_acl(fname, &sx);
1643 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1644 +#ifdef SUPPORT_ACLS
1645 + if (preserve_acls)
1649 if (verbose > 1 && maybe_ATTRS_REPORT) {
1650 code = daemon_log_format_has_i || dry_run
1651 @@ -778,6 +816,7 @@ static int try_dests_non(struct file_str
1654 static int phase = 0;
1655 +static int dflt_perms;
1657 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1658 * make sure it exists, and has the right permissions/timestamp info. For
1659 @@ -799,7 +838,8 @@ static void recv_generator(char *fname,
1660 static int need_fuzzy_dirlist = 0;
1661 struct file_struct *fuzzy_file = NULL;
1662 int fd = -1, f_copy = -1;
1663 - STRUCT_STAT st, real_st, partial_st;
1664 + statx sx, real_sx;
1665 + STRUCT_STAT partial_st;
1666 struct file_struct *back_file = NULL;
1667 int statret, real_ret, stat_errno;
1668 char *fnamecmp, *partialptr, *backupptr = NULL;
1669 @@ -850,6 +890,9 @@ static void recv_generator(char *fname,
1673 +#ifdef SUPPORT_ACLS
1674 + sx.acc_acl = sx.def_acl = NULL;
1678 stat_errno = ENOENT;
1679 @@ -857,7 +900,7 @@ static void recv_generator(char *fname,
1680 char *dn = file->dirname ? file->dirname : ".";
1681 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1682 if (relative_paths && !implied_dirs
1683 - && safe_stat(dn, &st) < 0
1684 + && safe_stat(dn, &sx.st) < 0
1685 && create_directory_path(fname) < 0) {
1686 rsyserr(FERROR, errno,
1687 "recv_generator: mkdir %s failed",
1688 @@ -869,6 +912,10 @@ static void recv_generator(char *fname,
1691 need_fuzzy_dirlist = 1;
1692 +#ifdef SUPPORT_ACLS
1693 + if (!preserve_perms)
1694 + dflt_perms = default_perms_for_dir(dn);
1697 parent_dirname = dn;
1699 @@ -877,7 +924,7 @@ static void recv_generator(char *fname,
1700 need_fuzzy_dirlist = 0;
1703 - statret = link_stat(fname, &st,
1704 + statret = link_stat(fname, &sx.st,
1705 keep_dirlinks && S_ISDIR(file->mode));
1708 @@ -895,8 +942,9 @@ static void recv_generator(char *fname,
1709 * mode based on the local permissions and some heuristics. */
1710 if (!preserve_perms) {
1711 int exists = statret == 0
1712 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1713 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1714 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1715 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1719 if (S_ISDIR(file->mode)) {
1720 @@ -905,8 +953,8 @@ static void recv_generator(char *fname,
1721 * file of that name and it is *not* a directory, then
1722 * we need to delete it. If it doesn't exist, then
1723 * (perhaps recursively) create it. */
1724 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1725 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1726 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1727 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1731 @@ -915,7 +963,11 @@ static void recv_generator(char *fname,
1734 if (itemizing && f_out != -1) {
1735 - itemize(file, ndx, statret, &st,
1736 +#ifdef SUPPORT_ACLS
1737 + if (preserve_acls && statret == 0)
1738 + get_acl(fname, &sx);
1740 + itemize(file, ndx, statret, &sx,
1741 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1743 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1744 @@ -927,19 +979,19 @@ static void recv_generator(char *fname,
1748 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1749 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1750 && verbose && code && f_out != -1)
1751 rprintf(code, "%s/\n", fname);
1752 if (delete_during && f_out != -1 && !phase && dry_run < 2
1753 && (file->flags & FLAG_DEL_HERE))
1754 - delete_in_dir(the_file_list, fname, file, &st);
1756 + delete_in_dir(the_file_list, fname, file, &sx.st);
1760 if (preserve_hard_links && file->link_u.links
1761 - && hard_link_check(file, ndx, fname, statret, &st,
1762 + && hard_link_check(file, ndx, fname, statret, &sx,
1763 itemizing, code, HL_CHECK_MASTER))
1767 if (preserve_links && S_ISLNK(file->mode)) {
1768 #ifdef SUPPORT_LINKS
1769 @@ -957,7 +1009,7 @@ static void recv_generator(char *fname,
1770 char lnk[MAXPATHLEN];
1773 - if (!S_ISDIR(st.st_mode)
1774 + if (!S_ISDIR(sx.st.st_mode)
1775 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1777 /* A link already pointing to the
1778 @@ -965,10 +1017,10 @@ static void recv_generator(char *fname,
1780 if (strcmp(lnk, file->u.link) == 0) {
1782 - itemize(file, ndx, 0, &st, 0,
1783 + itemize(file, ndx, 0, &sx, 0,
1786 - set_file_attrs(fname, file, &st,
1787 + set_file_attrs(fname, file, &sx,
1788 maybe_ATTRS_REPORT);
1789 if (preserve_hard_links
1790 && file->link_u.links) {
1791 @@ -981,9 +1033,9 @@ static void recv_generator(char *fname,
1793 /* Not the right symlink (or not a symlink), so
1795 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1796 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1798 - if (!S_ISLNK(st.st_mode))
1799 + if (!S_ISLNK(sx.st.st_mode))
1801 } else if (basis_dir[0] != NULL) {
1802 if (try_dests_non(file, fname, ndx, itemizing,
1803 @@ -999,7 +1051,7 @@ static void recv_generator(char *fname,
1806 if (preserve_hard_links && file->link_u.links
1807 - && hard_link_check(file, ndx, fname, -1, &st,
1808 + && hard_link_check(file, ndx, fname, -1, &sx,
1809 itemizing, code, HL_SKIP))
1811 if (do_symlink(file->u.link,fname) != 0) {
1812 @@ -1008,7 +1060,7 @@ static void recv_generator(char *fname,
1814 set_file_attrs(fname, file, NULL, 0);
1816 - itemize(file, ndx, statret, &st,
1817 + itemize(file, ndx, statret, &sx,
1818 ITEM_LOCAL_CHANGE, 0, NULL);
1820 if (code && verbose) {
1821 @@ -1042,18 +1094,22 @@ static void recv_generator(char *fname,
1822 itemizing = code = 0;
1825 +#ifdef SUPPORT_ACLS
1826 + if (preserve_acls && statret == 0)
1827 + get_acl(fname, &sx);
1830 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1831 - || st.st_rdev != file->u.rdev) {
1832 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1833 + || sx.st.st_rdev != file->u.rdev) {
1835 - && delete_item(fname, st.st_mode, del_opts) < 0)
1837 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1839 if (preserve_hard_links && file->link_u.links
1840 - && hard_link_check(file, ndx, fname, -1, &st,
1841 + && hard_link_check(file, ndx, fname, -1, &sx,
1842 itemizing, code, HL_SKIP))
1844 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1845 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1847 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1848 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1851 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1852 @@ -1066,7 +1122,7 @@ static void recv_generator(char *fname,
1854 set_file_attrs(fname, file, NULL, 0);
1856 - itemize(file, ndx, statret, &st,
1857 + itemize(file, ndx, statret, &sx,
1858 ITEM_LOCAL_CHANGE, 0, NULL);
1860 if (code && verbose)
1861 @@ -1078,12 +1134,12 @@ static void recv_generator(char *fname,
1865 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1866 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1867 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1868 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1869 if (preserve_hard_links && file->link_u.links)
1870 hard_link_cluster(file, ndx, itemizing, code);
1876 if (!S_ISREG(file->mode)) {
1877 @@ -1117,7 +1173,7 @@ static void recv_generator(char *fname,
1880 if (update_only && statret == 0
1881 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1882 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1884 rprintf(FINFO, "%s is newer\n", fname);
1886 @@ -1126,18 +1182,18 @@ static void recv_generator(char *fname,
1888 fnamecmp_type = FNAMECMP_FNAME;
1890 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1891 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1892 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1893 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1896 stat_errno = ENOENT;
1899 if (statret != 0 && basis_dir[0] != NULL) {
1900 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1901 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1902 itemizing, maybe_ATTRS_REPORT, code);
1907 fnamecmp = fnamecmpbuf;
1909 @@ -1146,7 +1202,7 @@ static void recv_generator(char *fname,
1916 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1917 && link_stat(partialptr, &partial_st, 0) == 0
1918 @@ -1165,7 +1221,7 @@ static void recv_generator(char *fname,
1919 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1920 fname, fnamecmpbuf);
1922 - st.st_size = fuzzy_file->length;
1923 + sx.st.st_size = fuzzy_file->length;
1925 fnamecmp = fnamecmpbuf;
1926 fnamecmp_type = FNAMECMP_FUZZY;
1927 @@ -1174,7 +1230,7 @@ static void recv_generator(char *fname,
1930 if (preserve_hard_links && file->link_u.links
1931 - && hard_link_check(file, ndx, fname, statret, &st,
1932 + && hard_link_check(file, ndx, fname, statret, &sx,
1933 itemizing, code, HL_SKIP))
1935 if (stat_errno == ENOENT)
1936 @@ -1184,31 +1240,44 @@ static void recv_generator(char *fname,
1940 - if (append_mode && st.st_size > file->length)
1941 + if (append_mode && sx.st.st_size > file->length)
1944 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1946 else if (fnamecmp_type == FNAMECMP_FUZZY)
1948 - else if (unchanged_file(fnamecmp, file, &st)) {
1949 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1951 do_unlink(partialptr);
1952 handle_partial_dir(partialptr, PDIR_DELETE);
1955 - itemize(file, ndx, real_ret, &real_st,
1956 +#ifdef SUPPORT_ACLS
1957 + if (preserve_acls && real_ret == 0)
1958 + get_acl(fname, &real_sx);
1960 + itemize(file, ndx, real_ret, &real_sx,
1962 +#ifdef SUPPORT_ACLS
1963 + if (preserve_acls) {
1964 + if (fnamecmp_type == FNAMECMP_FNAME) {
1965 + sx.acc_acl = real_sx.acc_acl;
1966 + sx.def_acl = real_sx.def_acl;
1968 + free_acl(&real_sx);
1972 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1973 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1974 if (preserve_hard_links && file->link_u.links)
1975 hard_link_cluster(file, ndx, itemizing, code);
1983 + sx.st = partial_st;
1984 fnamecmp = partialptr;
1985 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
1987 @@ -1232,17 +1301,21 @@ static void recv_generator(char *fname,
1989 /* pretend the file didn't exist */
1990 if (preserve_hard_links && file->link_u.links
1991 - && hard_link_check(file, ndx, fname, statret, &st,
1992 + && hard_link_check(file, ndx, fname, statret, &sx,
1993 itemizing, code, HL_SKIP))
1996 statret = real_ret = -1;
1997 +#ifdef SUPPORT_ACLS
1998 + if (preserve_acls && ACL_READY(sx))
2004 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2005 if (!(backupptr = get_backup_name(fname))) {
2010 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2012 @@ -1253,7 +1326,7 @@ static void recv_generator(char *fname,
2013 full_fname(backupptr));
2019 if ((f_copy = do_open(backupptr,
2020 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2021 @@ -1261,14 +1334,14 @@ static void recv_generator(char *fname,
2022 full_fname(backupptr));
2028 fnamecmp_type = FNAMECMP_BACKUP;
2032 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2033 - fnamecmp, (double)st.st_size);
2034 + fnamecmp, (double)sx.st.st_size);
2038 @@ -1286,24 +1359,32 @@ static void recv_generator(char *fname,
2039 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2040 if (fnamecmp_type == FNAMECMP_FUZZY)
2041 iflags |= ITEM_XNAME_FOLLOWS;
2042 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2043 +#ifdef SUPPORT_ACLS
2044 + if (preserve_acls && real_ret == 0)
2045 + get_acl(fname, &real_sx);
2047 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2048 fuzzy_file ? fuzzy_file->basename : NULL);
2049 +#ifdef SUPPORT_ACLS
2050 + if (preserve_acls)
2051 + free_acl(&real_sx);
2056 if (preserve_hard_links && file->link_u.links)
2057 hard_link_cluster(file, ndx, itemizing, code);
2065 if (statret != 0 || whole_file) {
2066 write_sum_head(f_out, NULL);
2071 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2072 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2076 @@ -1316,6 +1397,13 @@ static void recv_generator(char *fname,
2082 +#ifdef SUPPORT_ACLS
2083 + if (preserve_acls)
2089 void generate_files(int f_out, struct file_list *flist, char *local_name)
2090 @@ -1375,6 +1463,8 @@ void generate_files(int f_out, struct fi
2091 * notice that and let us know via the redo pipe (or its closing). */
2094 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2096 for (i = 0; i < flist->count; i++) {
2097 struct file_struct *file = flist->files[i];
2104 extern int link_dest;
2105 +extern int preserve_acls;
2106 extern int make_backups;
2107 extern int log_format_has_i;
2108 extern char *basis_dir[];
2109 @@ -143,15 +144,19 @@ void init_hard_links(void)
2111 #ifdef SUPPORT_HARD_LINKS
2112 static int maybe_hard_link(struct file_struct *file, int ndx,
2113 - char *fname, int statret, STRUCT_STAT *st,
2114 + char *fname, int statret, statx *sxp,
2115 char *toname, STRUCT_STAT *to_st,
2116 int itemizing, enum logcode code)
2119 - if (st->st_dev == to_st->st_dev
2120 - && st->st_ino == to_st->st_ino) {
2121 + if (sxp->st.st_dev == to_st->st_dev
2122 + && sxp->st.st_ino == to_st->st_ino) {
2124 - itemize(file, ndx, statret, st,
2125 +#ifdef SUPPORT_ACLS
2126 + if (preserve_acls && !ACL_READY(*sxp))
2127 + get_acl(fname, sxp);
2129 + itemize(file, ndx, statret, sxp,
2130 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2133 @@ -166,13 +171,13 @@ static int maybe_hard_link(struct file_s
2137 - return hard_link_one(file, ndx, fname, statret, st, toname,
2138 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2139 0, itemizing, code);
2143 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2144 - int statret, STRUCT_STAT *st, int itemizing,
2145 + int statret, statx *sxp, int itemizing,
2146 enum logcode code, int skip)
2148 #ifdef SUPPORT_HARD_LINKS
2149 @@ -207,7 +212,7 @@ int hard_link_check(struct file_struct *
2150 || st2.st_ino != st3.st_ino)
2155 if (verbose < 2 || !log_format_has_i)
2156 itemizing = code = 0;
2158 @@ -215,12 +220,16 @@ int hard_link_check(struct file_struct *
2159 if (!unchanged_file(cmpbuf, file, &st3))
2163 - if (unchanged_attrs(file, &st3))
2165 +#ifdef SUPPORT_ACLS
2166 + if (preserve_acls)
2167 + get_acl(cmpbuf, sxp);
2169 + if (unchanged_attrs(file, sxp))
2171 } while (basis_dir[++j] != NULL);
2173 - maybe_hard_link(file, ndx, fname, statret, st,
2174 + maybe_hard_link(file, ndx, fname, statret, sxp,
2175 toname, &st2, itemizing, code);
2176 file->F_HLINDEX = FINISHED_LINK;
2178 @@ -233,7 +242,7 @@ int hard_link_check(struct file_struct *
2180 #ifdef SUPPORT_HARD_LINKS
2181 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2182 - int statret, STRUCT_STAT *st, char *toname, int terse,
2183 + int statret, statx *sxp, char *toname, int terse,
2184 int itemizing, enum logcode code)
2186 if (do_link(toname, fname)) {
2187 @@ -249,7 +258,11 @@ int hard_link_one(struct file_struct *fi
2191 - itemize(file, ndx, statret, st,
2192 +#ifdef SUPPORT_ACLS
2193 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2194 + get_acl(fname, sxp);
2196 + itemize(file, ndx, statret, sxp,
2197 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2198 terse ? "" : toname);
2200 @@ -266,11 +279,12 @@ void hard_link_cluster(struct file_struc
2201 #ifdef SUPPORT_HARD_LINKS
2202 char hlink1[MAXPATHLEN];
2204 - STRUCT_STAT st1, st2;
2207 int statret, ndx = master;
2209 file->F_HLINDEX = FINISHED_LINK;
2210 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2211 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2213 if (!(file->flags & FLAG_HLINK_TOL)) {
2214 while (!(file->flags & FLAG_HLINK_EOL)) {
2215 @@ -284,9 +298,13 @@ void hard_link_cluster(struct file_struc
2216 if (file->F_HLINDEX != SKIPPED_LINK)
2218 hlink2 = f_name(file, NULL);
2219 - statret = link_stat(hlink2, &st2, 0);
2220 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2221 - hlink1, &st1, itemizing, code);
2222 + statret = link_stat(hlink2, &sx.st, 0);
2223 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2224 + hlink1, &st, itemizing, code);
2225 +#ifdef SUPPORT_ACLS
2226 + if (preserve_acls)
2229 file->F_HLINDEX = FINISHED_LINK;
2230 } while (!(file->flags & FLAG_HLINK_EOL));
2232 --- old/lib/sysacls.c
2233 +++ new/lib/sysacls.c
2236 + Unix SMB/CIFS implementation.
2237 + Samba system utilities for ACL support.
2238 + Copyright (C) Jeremy Allison 2000.
2240 + This program is free software; you can redistribute it and/or modify
2241 + it under the terms of the GNU General Public License as published by
2242 + the Free Software Foundation; either version 2 of the License, or
2243 + (at your option) any later version.
2245 + This program is distributed in the hope that it will be useful,
2246 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2247 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2248 + GNU General Public License for more details.
2250 + You should have received a copy of the GNU General Public License
2251 + along with this program; if not, write to the Free Software
2252 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2256 +#include "sysacls.h" /****** ADDED ******/
2258 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2259 +void SAFE_FREE(void *mem)
2265 +char *uidtoname(uid_t uid)
2267 + static char idbuf[12];
2268 + struct passwd *pw;
2270 + if ((pw = getpwuid(uid)) == NULL) {
2271 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2274 + return pw->pw_name;
2276 +/****** EXTRAS -- END ******/
2279 + This file wraps all differing system ACL interfaces into a consistent
2280 + one based on the POSIX interface. It also returns the correct errors
2281 + for older UNIX systems that don't support ACLs.
2283 + The interfaces that each ACL implementation must support are as follows :
2285 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2286 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2287 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2288 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2289 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2290 + SMB_ACL_T sys_acl_get_fd(int fd)
2291 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2292 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2293 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2294 + SMB_ACL_T sys_acl_init( int count)
2295 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2296 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2297 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2298 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2299 + int sys_acl_valid( SMB_ACL_T theacl )
2300 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2301 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2302 + int sys_acl_delete_def_file(const char *path)
2304 + This next one is not POSIX complient - but we *have* to have it !
2305 + More POSIX braindamage.
2307 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2309 + The generic POSIX free is the following call. We split this into
2310 + several different free functions as we may need to add tag info
2311 + to structures when emulating the POSIX interface.
2313 + int sys_acl_free( void *obj_p)
2315 + The calls we actually use are :
2317 + int sys_acl_free_text(char *text) - free acl_to_text
2318 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2319 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2323 +#if defined(HAVE_POSIX_ACLS)
2325 +/* Identity mapping - easy. */
2327 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2329 + return acl_get_entry( the_acl, entry_id, entry_p);
2332 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2334 + return acl_get_tag_type( entry_d, tag_type_p);
2337 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2339 + return acl_get_permset( entry_d, permset_p);
2342 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2344 + return acl_get_qualifier( entry_d);
2347 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2349 + return acl_get_file( path_p, type);
2352 +SMB_ACL_T sys_acl_get_fd(int fd)
2354 + return acl_get_fd(fd);
2357 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2359 + return acl_clear_perms(permset);
2362 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2364 + return acl_add_perm(permset, perm);
2367 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2369 +#if defined(HAVE_ACL_GET_PERM_NP)
2371 + * Required for TrustedBSD-based ACL implementations where
2372 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2375 + return acl_get_perm_np(permset, perm);
2377 + return acl_get_perm(permset, perm);
2381 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2383 + return acl_to_text( the_acl, plen);
2386 +SMB_ACL_T sys_acl_init( int count)
2388 + return acl_init(count);
2391 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2393 + return acl_create_entry(pacl, pentry);
2396 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2398 + return acl_set_tag_type(entry, tagtype);
2401 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2403 + return acl_set_qualifier(entry, qual);
2406 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2408 + return acl_set_permset(entry, permset);
2411 +int sys_acl_valid( SMB_ACL_T theacl )
2413 + return acl_valid(theacl);
2416 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2418 + return acl_set_file(name, acltype, theacl);
2421 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2423 + return acl_set_fd(fd, theacl);
2426 +int sys_acl_delete_def_file(const char *name)
2428 + return acl_delete_def_file(name);
2431 +int sys_acl_free_text(char *text)
2433 + return acl_free(text);
2436 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2438 + return acl_free(the_acl);
2441 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2443 + return acl_free(qual);
2446 +#elif defined(HAVE_TRU64_ACLS)
2448 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2449 + * is based on Draft 13 of the POSIX spec which is
2450 + * slightly different from the Draft 16 interface.
2452 + * Also, some of the permset manipulation functions
2453 + * such as acl_clear_perm() and acl_add_perm() appear
2454 + * to be broken on Tru64 so we have to manipulate
2455 + * the permission bits in the permset directly.
2457 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2459 + SMB_ACL_ENTRY_T entry;
2461 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2466 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2471 + return errno ? -1 : 0;
2474 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2476 + return acl_get_tag_type( entry_d, tag_type_p);
2479 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2481 + return acl_get_permset( entry_d, permset_p);
2484 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2486 + return acl_get_qualifier( entry_d);
2489 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2491 + return acl_get_file((char *)path_p, type);
2494 +SMB_ACL_T sys_acl_get_fd(int fd)
2496 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2499 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2501 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2506 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2508 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2513 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2518 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2520 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2523 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2525 + return acl_to_text( the_acl, plen);
2528 +SMB_ACL_T sys_acl_init( int count)
2530 + return acl_init(count);
2533 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2535 + SMB_ACL_ENTRY_T entry;
2537 + if ((entry = acl_create_entry(pacl)) == NULL) {
2545 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2547 + return acl_set_tag_type(entry, tagtype);
2550 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2552 + return acl_set_qualifier(entry, qual);
2555 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2557 + return acl_set_permset(entry, permset);
2560 +int sys_acl_valid( SMB_ACL_T theacl )
2562 + acl_entry_t entry;
2564 + return acl_valid(theacl, &entry);
2567 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2569 + return acl_set_file((char *)name, acltype, theacl);
2572 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2574 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2577 +int sys_acl_delete_def_file(const char *name)
2579 + return acl_delete_def_file((char *)name);
2582 +int sys_acl_free_text(char *text)
2585 + * (void) cast and explicit return 0 are for DEC UNIX
2586 + * which just #defines acl_free_text() to be free()
2588 + (void) acl_free_text(text);
2592 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2594 + return acl_free(the_acl);
2597 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2599 + return acl_free_qualifier(qual, tagtype);
2602 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2605 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2606 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2610 + * Note that while this code implements sufficient functionality
2611 + * to support the sys_acl_* interfaces it does not provide all
2612 + * of the semantics of the POSIX ACL interfaces.
2614 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2615 + * from a call to sys_acl_get_entry() should not be assumed to be
2616 + * valid after calling any of the following functions, which may
2617 + * reorder the entries in the ACL.
2620 + * sys_acl_set_file()
2621 + * sys_acl_set_fd()
2625 + * The only difference between Solaris and UnixWare / OpenUNIX is
2626 + * that the #defines for the ACL operations have different names
2628 +#if defined(HAVE_UNIXWARE_ACLS)
2630 +#define SETACL ACL_SET
2631 +#define GETACL ACL_GET
2632 +#define GETACLCNT ACL_CNT
2637 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2639 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2644 + if (entry_p == NULL) {
2649 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2653 + if (acl_d->next < 0) {
2658 + if (acl_d->next >= acl_d->count) {
2662 + *entry_p = &acl_d->acl[acl_d->next++];
2667 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2669 + *type_p = entry_d->a_type;
2674 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2676 + *permset_p = &entry_d->a_perm;
2681 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2683 + if (entry_d->a_type != SMB_ACL_USER
2684 + && entry_d->a_type != SMB_ACL_GROUP) {
2689 + return &entry_d->a_id;
2693 + * There is no way of knowing what size the ACL returned by
2694 + * GETACL will be unless you first call GETACLCNT which means
2695 + * making an additional system call.
2697 + * In the hope of avoiding the cost of the additional system
2698 + * call in most cases, we initially allocate enough space for
2699 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2700 + * be too small then we use GETACLCNT to find out the actual
2701 + * size, reallocate the ACL buffer, and then call GETACL again.
2704 +#define INITIAL_ACL_SIZE 16
2706 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2709 + int count; /* # of ACL entries allocated */
2710 + int naccess; /* # of access ACL entries */
2711 + int ndefault; /* # of default ACL entries */
2713 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2718 + count = INITIAL_ACL_SIZE;
2719 + if ((acl_d = sys_acl_init(count)) == NULL) {
2724 + * If there isn't enough space for the ACL entries we use
2725 + * GETACLCNT to determine the actual number of ACL entries
2726 + * reallocate and try again. This is in a loop because it
2727 + * is possible that someone else could modify the ACL and
2728 + * increase the number of entries between the call to
2729 + * GETACLCNT and the call to GETACL.
2731 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2732 + && errno == ENOSPC) {
2734 + sys_acl_free_acl(acl_d);
2736 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2740 + if ((acl_d = sys_acl_init(count)) == NULL) {
2746 + sys_acl_free_acl(acl_d);
2751 + * calculate the number of access and default ACL entries
2753 + * Note: we assume that the acl() system call returned a
2754 + * well formed ACL which is sorted so that all of the
2755 + * access ACL entries preceed any default ACL entries
2757 + for (naccess = 0; naccess < count; naccess++) {
2758 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2761 + ndefault = count - naccess;
2764 + * if the caller wants the default ACL we have to copy
2765 + * the entries down to the start of the acl[] buffer
2766 + * and mask out the ACL_DEFAULT flag from the type field
2768 + if (type == SMB_ACL_TYPE_DEFAULT) {
2771 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2772 + acl_d->acl[i] = acl_d->acl[j];
2773 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2776 + acl_d->count = ndefault;
2778 + acl_d->count = naccess;
2784 +SMB_ACL_T sys_acl_get_fd(int fd)
2787 + int count; /* # of ACL entries allocated */
2788 + int naccess; /* # of access ACL entries */
2790 + count = INITIAL_ACL_SIZE;
2791 + if ((acl_d = sys_acl_init(count)) == NULL) {
2795 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2796 + && errno == ENOSPC) {
2798 + sys_acl_free_acl(acl_d);
2800 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2804 + if ((acl_d = sys_acl_init(count)) == NULL) {
2810 + sys_acl_free_acl(acl_d);
2815 + * calculate the number of access ACL entries
2817 + for (naccess = 0; naccess < count; naccess++) {
2818 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2822 + acl_d->count = naccess;
2827 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2834 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2836 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2837 + && perm != SMB_ACL_EXECUTE) {
2842 + if (permset_d == NULL) {
2847 + *permset_d |= perm;
2852 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2854 + return *permset_d & perm;
2857 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2864 + * use an initial estimate of 20 bytes per ACL entry
2865 + * when allocating memory for the text representation
2869 + maxlen = 20 * acl_d->count;
2870 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2875 + for (i = 0; i < acl_d->count; i++) {
2876 + struct acl *ap = &acl_d->acl[i];
2885 + switch (ap->a_type) {
2887 + * for debugging purposes it's probably more
2888 + * useful to dump unknown tag types rather
2889 + * than just returning an error
2892 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2895 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2900 + case SMB_ACL_USER:
2901 + id = uidtoname(ap->a_id);
2902 + case SMB_ACL_USER_OBJ:
2906 + case SMB_ACL_GROUP:
2907 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2908 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2914 + case SMB_ACL_GROUP_OBJ:
2918 + case SMB_ACL_OTHER:
2922 + case SMB_ACL_MASK:
2928 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2929 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2930 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2933 + /* <tag> : <qualifier> : rwx \n \0 */
2934 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2937 + * If this entry would overflow the buffer
2938 + * allocate enough additional memory for this
2939 + * entry and an estimate of another 20 bytes
2940 + * for each entry still to be processed
2942 + if ((len + nbytes) > maxlen) {
2943 + char *oldtext = text;
2945 + maxlen += nbytes + 20 * (acl_d->count - i);
2947 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2948 + SAFE_FREE(oldtext);
2954 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2955 + len += nbytes - 1;
2964 +SMB_ACL_T sys_acl_init(int count)
2974 + * note that since the definition of the structure pointed
2975 + * to by the SMB_ACL_T includes the first element of the
2976 + * acl[] array, this actually allocates an ACL with room
2977 + * for (count+1) entries
2979 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2984 + a->size = count + 1;
2992 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2995 + SMB_ACL_ENTRY_T entry_d;
2997 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3002 + if (acl_d->count >= acl_d->size) {
3007 + entry_d = &acl_d->acl[acl_d->count++];
3008 + entry_d->a_type = 0;
3009 + entry_d->a_id = -1;
3010 + entry_d->a_perm = 0;
3011 + *entry_p = entry_d;
3016 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3018 + switch (tag_type) {
3019 + case SMB_ACL_USER:
3020 + case SMB_ACL_USER_OBJ:
3021 + case SMB_ACL_GROUP:
3022 + case SMB_ACL_GROUP_OBJ:
3023 + case SMB_ACL_OTHER:
3024 + case SMB_ACL_MASK:
3025 + entry_d->a_type = tag_type;
3035 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3037 + if (entry_d->a_type != SMB_ACL_GROUP
3038 + && entry_d->a_type != SMB_ACL_USER) {
3043 + entry_d->a_id = *((id_t *)qual_p);
3048 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3050 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3054 + entry_d->a_perm = *permset_d;
3060 + * sort the ACL and check it for validity
3062 + * if it's a minimal ACL with only 4 entries then we
3063 + * need to recalculate the mask permissions to make
3064 + * sure that they are the same as the GROUP_OBJ
3065 + * permissions as required by the UnixWare acl() system call.
3067 + * (note: since POSIX allows minimal ACLs which only contain
3068 + * 3 entries - ie there is no mask entry - we should, in theory,
3069 + * check for this and add a mask entry if necessary - however
3070 + * we "know" that the caller of this interface always specifies
3071 + * a mask so, in practice "this never happens" (tm) - if it *does*
3072 + * happen aclsort() will fail and return an error and someone will
3073 + * have to fix it ...)
3076 +static int acl_sort(SMB_ACL_T acl_d)
3078 + int fixmask = (acl_d->count <= 4);
3080 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3087 +int sys_acl_valid(SMB_ACL_T acl_d)
3089 + return acl_sort(acl_d);
3092 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3095 + struct acl *acl_p;
3097 + struct acl *acl_buf = NULL;
3100 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3105 + if (acl_sort(acl_d) != 0) {
3109 + acl_p = &acl_d->acl[0];
3110 + acl_count = acl_d->count;
3113 + * if it's a directory there is extra work to do
3114 + * since the acl() system call will replace both
3115 + * the access ACLs and the default ACLs (if any)
3117 + if (stat(name, &s) != 0) {
3120 + if (S_ISDIR(s.st_mode)) {
3121 + SMB_ACL_T acc_acl;
3122 + SMB_ACL_T def_acl;
3123 + SMB_ACL_T tmp_acl;
3126 + if (type == SMB_ACL_TYPE_ACCESS) {
3128 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3132 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3135 + if (tmp_acl == NULL) {
3140 + * allocate a temporary buffer for the complete ACL
3142 + acl_count = acc_acl->count + def_acl->count;
3143 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3145 + if (acl_buf == NULL) {
3146 + sys_acl_free_acl(tmp_acl);
3152 + * copy the access control and default entries into the buffer
3154 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3155 + acc_acl->count * sizeof(acl_buf[0]));
3157 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3158 + def_acl->count * sizeof(acl_buf[0]));
3161 + * set the ACL_DEFAULT flag on the default entries
3163 + for (i = acc_acl->count; i < acl_count; i++) {
3164 + acl_buf[i].a_type |= ACL_DEFAULT;
3167 + sys_acl_free_acl(tmp_acl);
3169 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3174 + ret = acl(name, SETACL, acl_count, acl_p);
3176 + SAFE_FREE(acl_buf);
3181 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3183 + if (acl_sort(acl_d) != 0) {
3187 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3190 +int sys_acl_delete_def_file(const char *path)
3196 + * fetching the access ACL and rewriting it has
3197 + * the effect of deleting the default ACL
3199 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3203 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3205 + sys_acl_free_acl(acl_d);
3210 +int sys_acl_free_text(char *text)
3216 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3222 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3227 +#elif defined(HAVE_HPUX_ACLS)
3231 + * Based on the Solaris/SCO code - with modifications.
3235 + * Note that while this code implements sufficient functionality
3236 + * to support the sys_acl_* interfaces it does not provide all
3237 + * of the semantics of the POSIX ACL interfaces.
3239 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3240 + * from a call to sys_acl_get_entry() should not be assumed to be
3241 + * valid after calling any of the following functions, which may
3242 + * reorder the entries in the ACL.
3245 + * sys_acl_set_file()
3246 + * sys_acl_set_fd()
3249 +/* This checks if the POSIX ACL system call is defined */
3250 +/* which basically corresponds to whether JFS 3.3 or */
3251 +/* higher is installed. If acl() was called when it */
3252 +/* isn't defined, it causes the process to core dump */
3253 +/* so it is important to check this and avoid acl() */
3254 +/* calls if it isn't there. */
3256 +static BOOL hpux_acl_call_presence(void)
3259 + shl_t handle = NULL;
3262 + static BOOL already_checked=0;
3264 + if(already_checked)
3268 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3270 + if(ret_val != 0) {
3271 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3272 + ret_val, errno, strerror(errno)));
3273 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3277 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3279 + already_checked = True;
3283 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3285 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3290 + if (entry_p == NULL) {
3295 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3299 + if (acl_d->next < 0) {
3304 + if (acl_d->next >= acl_d->count) {
3308 + *entry_p = &acl_d->acl[acl_d->next++];
3313 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3315 + *type_p = entry_d->a_type;
3320 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3322 + *permset_p = &entry_d->a_perm;
3327 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3329 + if (entry_d->a_type != SMB_ACL_USER
3330 + && entry_d->a_type != SMB_ACL_GROUP) {
3335 + return &entry_d->a_id;
3339 + * There is no way of knowing what size the ACL returned by
3340 + * ACL_GET will be unless you first call ACL_CNT which means
3341 + * making an additional system call.
3343 + * In the hope of avoiding the cost of the additional system
3344 + * call in most cases, we initially allocate enough space for
3345 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3346 + * be too small then we use ACL_CNT to find out the actual
3347 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3350 +#define INITIAL_ACL_SIZE 16
3352 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3355 + int count; /* # of ACL entries allocated */
3356 + int naccess; /* # of access ACL entries */
3357 + int ndefault; /* # of default ACL entries */
3359 + if(hpux_acl_call_presence() == False) {
3360 + /* Looks like we don't have the acl() system call on HPUX.
3361 + * May be the system doesn't have the latest version of JFS.
3366 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3371 + count = INITIAL_ACL_SIZE;
3372 + if ((acl_d = sys_acl_init(count)) == NULL) {
3377 + * If there isn't enough space for the ACL entries we use
3378 + * ACL_CNT to determine the actual number of ACL entries
3379 + * reallocate and try again. This is in a loop because it
3380 + * is possible that someone else could modify the ACL and
3381 + * increase the number of entries between the call to
3382 + * ACL_CNT and the call to ACL_GET.
3384 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3386 + sys_acl_free_acl(acl_d);
3388 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3392 + if ((acl_d = sys_acl_init(count)) == NULL) {
3398 + sys_acl_free_acl(acl_d);
3403 + * calculate the number of access and default ACL entries
3405 + * Note: we assume that the acl() system call returned a
3406 + * well formed ACL which is sorted so that all of the
3407 + * access ACL entries preceed any default ACL entries
3409 + for (naccess = 0; naccess < count; naccess++) {
3410 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3413 + ndefault = count - naccess;
3416 + * if the caller wants the default ACL we have to copy
3417 + * the entries down to the start of the acl[] buffer
3418 + * and mask out the ACL_DEFAULT flag from the type field
3420 + if (type == SMB_ACL_TYPE_DEFAULT) {
3423 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3424 + acl_d->acl[i] = acl_d->acl[j];
3425 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3428 + acl_d->count = ndefault;
3430 + acl_d->count = naccess;
3436 +SMB_ACL_T sys_acl_get_fd(int fd)
3439 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3442 + files_struct *fsp = file_find_fd(fd);
3444 + if (fsp == NULL) {
3450 + * We know we're in the same conn context. So we
3451 + * can use the relative path.
3454 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3457 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3464 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3466 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3467 + && perm != SMB_ACL_EXECUTE) {
3472 + if (permset_d == NULL) {
3477 + *permset_d |= perm;
3482 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3484 + return *permset_d & perm;
3487 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3494 + * use an initial estimate of 20 bytes per ACL entry
3495 + * when allocating memory for the text representation
3499 + maxlen = 20 * acl_d->count;
3500 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3505 + for (i = 0; i < acl_d->count; i++) {
3506 + struct acl *ap = &acl_d->acl[i];
3515 + switch (ap->a_type) {
3517 + * for debugging purposes it's probably more
3518 + * useful to dump unknown tag types rather
3519 + * than just returning an error
3522 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3525 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3530 + case SMB_ACL_USER:
3531 + id = uidtoname(ap->a_id);
3532 + case SMB_ACL_USER_OBJ:
3536 + case SMB_ACL_GROUP:
3537 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3538 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3544 + case SMB_ACL_GROUP_OBJ:
3548 + case SMB_ACL_OTHER:
3552 + case SMB_ACL_MASK:
3558 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3559 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3560 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3563 + /* <tag> : <qualifier> : rwx \n \0 */
3564 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3567 + * If this entry would overflow the buffer
3568 + * allocate enough additional memory for this
3569 + * entry and an estimate of another 20 bytes
3570 + * for each entry still to be processed
3572 + if ((len + nbytes) > maxlen) {
3573 + char *oldtext = text;
3575 + maxlen += nbytes + 20 * (acl_d->count - i);
3577 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3584 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3585 + len += nbytes - 1;
3594 +SMB_ACL_T sys_acl_init(int count)
3604 + * note that since the definition of the structure pointed
3605 + * to by the SMB_ACL_T includes the first element of the
3606 + * acl[] array, this actually allocates an ACL with room
3607 + * for (count+1) entries
3609 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3614 + a->size = count + 1;
3622 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3625 + SMB_ACL_ENTRY_T entry_d;
3627 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3632 + if (acl_d->count >= acl_d->size) {
3637 + entry_d = &acl_d->acl[acl_d->count++];
3638 + entry_d->a_type = 0;
3639 + entry_d->a_id = -1;
3640 + entry_d->a_perm = 0;
3641 + *entry_p = entry_d;
3646 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3648 + switch (tag_type) {
3649 + case SMB_ACL_USER:
3650 + case SMB_ACL_USER_OBJ:
3651 + case SMB_ACL_GROUP:
3652 + case SMB_ACL_GROUP_OBJ:
3653 + case SMB_ACL_OTHER:
3654 + case SMB_ACL_MASK:
3655 + entry_d->a_type = tag_type;
3665 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3667 + if (entry_d->a_type != SMB_ACL_GROUP
3668 + && entry_d->a_type != SMB_ACL_USER) {
3673 + entry_d->a_id = *((id_t *)qual_p);
3678 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3680 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3684 + entry_d->a_perm = *permset_d;
3689 +/* Structure to capture the count for each type of ACE. */
3691 +struct hpux_acl_types {
3695 + int n_def_user_obj;
3700 + int n_def_group_obj;
3704 + int n_def_other_obj;
3707 + int n_def_class_obj;
3709 + int n_illegal_obj;
3713 + * Counts the different number of objects in a given array of ACL
3717 + * acl_count - Count of ACLs in the array of ACL strucutres.
3718 + * aclp - Array of ACL structures.
3719 + * acl_type_count - Pointer to acl_types structure. Should already be
3723 + * acl_type_count - This structure is filled up with counts of various
3727 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3731 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3733 + for(i=0;i<acl_count;i++) {
3734 + switch(aclp[i].a_type) {
3736 + acl_type_count->n_user++;
3739 + acl_type_count->n_user_obj++;
3741 + case DEF_USER_OBJ:
3742 + acl_type_count->n_def_user_obj++;
3745 + acl_type_count->n_group++;
3748 + acl_type_count->n_group_obj++;
3750 + case DEF_GROUP_OBJ:
3751 + acl_type_count->n_def_group_obj++;
3754 + acl_type_count->n_other_obj++;
3756 + case DEF_OTHER_OBJ:
3757 + acl_type_count->n_def_other_obj++;
3760 + acl_type_count->n_class_obj++;
3762 + case DEF_CLASS_OBJ:
3763 + acl_type_count->n_def_class_obj++;
3766 + acl_type_count->n_def_user++;
3769 + acl_type_count->n_def_group++;
3772 + acl_type_count->n_illegal_obj++;
3778 +/* swap_acl_entries: Swaps two ACL entries.
3780 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3783 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3785 + struct acl temp_acl;
3787 + temp_acl.a_type = aclp0->a_type;
3788 + temp_acl.a_id = aclp0->a_id;
3789 + temp_acl.a_perm = aclp0->a_perm;
3791 + aclp0->a_type = aclp1->a_type;
3792 + aclp0->a_id = aclp1->a_id;
3793 + aclp0->a_perm = aclp1->a_perm;
3795 + aclp1->a_type = temp_acl.a_type;
3796 + aclp1->a_id = temp_acl.a_id;
3797 + aclp1->a_perm = temp_acl.a_perm;
3800 +/* prohibited_duplicate_type
3801 + * Identifies if given ACL type can have duplicate entries or
3804 + * Inputs: acl_type - ACL Type.
3810 + * True - If the ACL type matches any of the prohibited types.
3811 + * False - If the ACL type doesn't match any of the prohibited types.
3814 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3816 + switch(acl_type) {
3827 +/* get_needed_class_perm
3828 + * Returns the permissions of a ACL structure only if the ACL
3829 + * type matches one of the pre-determined types for computing
3830 + * CLASS_OBJ permissions.
3832 + * Inputs: aclp - Pointer to ACL structure.
3835 +static int hpux_get_needed_class_perm(struct acl *aclp)
3837 + switch(aclp->a_type) {
3841 + case DEF_USER_OBJ:
3843 + case DEF_GROUP_OBJ:
3845 + case DEF_CLASS_OBJ:
3846 + case DEF_OTHER_OBJ:
3847 + return aclp->a_perm;
3853 +/* acl_sort for HPUX.
3854 + * Sorts the array of ACL structures as per the description in
3855 + * aclsort man page. Refer to aclsort man page for more details
3859 + * acl_count - Count of ACLs in the array of ACL structures.
3860 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3862 + * aclp - Array of ACL structures.
3866 + * aclp - Sorted array of ACL structures.
3870 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3871 + * debug log in case of failure.
3874 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3876 +#if !defined(HAVE_HPUX_ACLSORT)
3878 + * The aclsort() system call is availabe on the latest HPUX General
3879 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3880 + * function. Because, we don't want to update to a new
3881 + * HPUX GR bundle just for aclsort() call.
3884 + struct hpux_acl_types acl_obj_count;
3885 + int n_class_obj_perm = 0;
3889 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3893 + if(aclp == NULL) {
3894 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3898 + /* Count different types of ACLs in the ACLs array */
3900 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3902 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3903 + * CLASS_OBJ and OTHER_OBJ
3906 + if( (acl_obj_count.n_user_obj != 1) ||
3907 + (acl_obj_count.n_group_obj != 1) ||
3908 + (acl_obj_count.n_class_obj != 1) ||
3909 + (acl_obj_count.n_other_obj != 1)
3911 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3912 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3916 + /* If any of the default objects are present, there should be only
3917 + * one of them each.
3920 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3921 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3922 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3923 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3927 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3930 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3931 + * same ACL type, sort by ACL id.
3933 + * I am using the trival kind of sorting method here because, performance isn't
3934 + * really effected by the ACLs feature. More over there aren't going to be more
3935 + * than 17 entries on HPUX.
3938 + for(i=0; i<acl_count;i++) {
3939 + for (j=i+1; j<acl_count; j++) {
3940 + if( aclp[i].a_type > aclp[j].a_type ) {
3941 + /* ACL entries out of order, swap them */
3943 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3945 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3947 + /* ACL entries of same type, sort by id */
3949 + if(aclp[i].a_id > aclp[j].a_id) {
3950 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3951 + } else if (aclp[i].a_id == aclp[j].a_id) {
3952 + /* We have a duplicate entry. */
3953 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3954 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3955 + aclp[i].a_type, aclp[i].a_id));
3964 + /* set the class obj permissions to the computed one. */
3966 + int n_class_obj_index = -1;
3968 + for(i=0;i<acl_count;i++) {
3969 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3971 + if(aclp[i].a_type == CLASS_OBJ)
3972 + n_class_obj_index = i;
3974 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3979 + return aclsort(acl_count, calclass, aclp);
3984 + * sort the ACL and check it for validity
3986 + * if it's a minimal ACL with only 4 entries then we
3987 + * need to recalculate the mask permissions to make
3988 + * sure that they are the same as the GROUP_OBJ
3989 + * permissions as required by the UnixWare acl() system call.
3991 + * (note: since POSIX allows minimal ACLs which only contain
3992 + * 3 entries - ie there is no mask entry - we should, in theory,
3993 + * check for this and add a mask entry if necessary - however
3994 + * we "know" that the caller of this interface always specifies
3995 + * a mask so, in practice "this never happens" (tm) - if it *does*
3996 + * happen aclsort() will fail and return an error and someone will
3997 + * have to fix it ...)
4000 +static int acl_sort(SMB_ACL_T acl_d)
4002 + int fixmask = (acl_d->count <= 4);
4004 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4011 +int sys_acl_valid(SMB_ACL_T acl_d)
4013 + return acl_sort(acl_d);
4016 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4019 + struct acl *acl_p;
4021 + struct acl *acl_buf = NULL;
4024 + if(hpux_acl_call_presence() == False) {
4025 + /* Looks like we don't have the acl() system call on HPUX.
4026 + * May be the system doesn't have the latest version of JFS.
4032 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4037 + if (acl_sort(acl_d) != 0) {
4041 + acl_p = &acl_d->acl[0];
4042 + acl_count = acl_d->count;
4045 + * if it's a directory there is extra work to do
4046 + * since the acl() system call will replace both
4047 + * the access ACLs and the default ACLs (if any)
4049 + if (stat(name, &s) != 0) {
4052 + if (S_ISDIR(s.st_mode)) {
4053 + SMB_ACL_T acc_acl;
4054 + SMB_ACL_T def_acl;
4055 + SMB_ACL_T tmp_acl;
4058 + if (type == SMB_ACL_TYPE_ACCESS) {
4060 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4064 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4067 + if (tmp_acl == NULL) {
4072 + * allocate a temporary buffer for the complete ACL
4074 + acl_count = acc_acl->count + def_acl->count;
4075 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4077 + if (acl_buf == NULL) {
4078 + sys_acl_free_acl(tmp_acl);
4084 + * copy the access control and default entries into the buffer
4086 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4087 + acc_acl->count * sizeof(acl_buf[0]));
4089 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4090 + def_acl->count * sizeof(acl_buf[0]));
4093 + * set the ACL_DEFAULT flag on the default entries
4095 + for (i = acc_acl->count; i < acl_count; i++) {
4096 + acl_buf[i].a_type |= ACL_DEFAULT;
4099 + sys_acl_free_acl(tmp_acl);
4101 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4106 + ret = acl(name, ACL_SET, acl_count, acl_p);
4115 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4118 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4121 + files_struct *fsp = file_find_fd(fd);
4123 + if (fsp == NULL) {
4128 + if (acl_sort(acl_d) != 0) {
4133 + * We know we're in the same conn context. So we
4134 + * can use the relative path.
4137 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4140 +int sys_acl_delete_def_file(const char *path)
4146 + * fetching the access ACL and rewriting it has
4147 + * the effect of deleting the default ACL
4149 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4153 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4155 + sys_acl_free_acl(acl_d);
4160 +int sys_acl_free_text(char *text)
4166 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4172 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4177 +#elif defined(HAVE_IRIX_ACLS)
4179 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4181 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4186 + if (entry_p == NULL) {
4191 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4195 + if (acl_d->next < 0) {
4200 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4204 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4209 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4211 + *type_p = entry_d->ae_tag;
4216 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4218 + *permset_p = entry_d;
4223 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4225 + if (entry_d->ae_tag != SMB_ACL_USER
4226 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4231 + return &entry_d->ae_id;
4234 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4238 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4242 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4247 + a->freeaclp = True;
4251 +SMB_ACL_T sys_acl_get_fd(int fd)
4255 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4259 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4264 + a->freeaclp = True;
4268 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4270 + permset_d->ae_perm = 0;
4275 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4277 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4278 + && perm != SMB_ACL_EXECUTE) {
4283 + if (permset_d == NULL) {
4288 + permset_d->ae_perm |= perm;
4293 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4295 + return permset_d->ae_perm & perm;
4298 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4300 + return acl_to_text(acl_d->aclp, len_p);
4303 +SMB_ACL_T sys_acl_init(int count)
4312 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4318 + a->freeaclp = False;
4319 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4320 + a->aclp->acl_cnt = 0;
4326 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4329 + SMB_ACL_ENTRY_T entry_d;
4331 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4336 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4341 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4342 + entry_d->ae_tag = 0;
4343 + entry_d->ae_id = 0;
4344 + entry_d->ae_perm = 0;
4345 + *entry_p = entry_d;
4350 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4352 + switch (tag_type) {
4353 + case SMB_ACL_USER:
4354 + case SMB_ACL_USER_OBJ:
4355 + case SMB_ACL_GROUP:
4356 + case SMB_ACL_GROUP_OBJ:
4357 + case SMB_ACL_OTHER:
4358 + case SMB_ACL_MASK:
4359 + entry_d->ae_tag = tag_type;
4369 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4371 + if (entry_d->ae_tag != SMB_ACL_GROUP
4372 + && entry_d->ae_tag != SMB_ACL_USER) {
4377 + entry_d->ae_id = *((id_t *)qual_p);
4382 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4384 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4388 + entry_d->ae_perm = permset_d->ae_perm;
4393 +int sys_acl_valid(SMB_ACL_T acl_d)
4395 + return acl_valid(acl_d->aclp);
4398 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4400 + return acl_set_file(name, type, acl_d->aclp);
4403 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4405 + return acl_set_fd(fd, acl_d->aclp);
4408 +int sys_acl_delete_def_file(const char *name)
4410 + return acl_delete_def_file(name);
4413 +int sys_acl_free_text(char *text)
4415 + return acl_free(text);
4418 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4420 + if (acl_d->freeaclp) {
4421 + acl_free(acl_d->aclp);
4427 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4432 +#elif defined(HAVE_AIX_ACLS)
4434 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4436 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4438 + struct acl_entry_link *link;
4439 + struct new_acl_entry *entry;
4442 + DEBUG(10,("This is the count: %d\n",theacl->count));
4444 + /* Check if count was previously set to -1. *
4445 + * If it was, that means we reached the end *
4446 + * of the acl last time. */
4447 + if(theacl->count == -1)
4451 + /* To get to the next acl, traverse linked list until index *
4452 + * of acl matches the count we are keeping. This count is *
4453 + * incremented each time we return an acl entry. */
4455 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4456 + link = link->nextp;
4458 + entry = *entry_p = link->entryp;
4460 + DEBUG(10,("*entry_p is %d\n",entry_p));
4461 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4463 + /* Increment count */
4465 + if(link->nextp == NULL)
4466 + theacl->count = -1;
4471 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4473 + /* Initialize tag type */
4476 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4478 + /* Depending on what type of entry we have, *
4479 + * return tag type. */
4480 + switch(entry_d->ace_id->id_type) {
4482 + *tag_type_p = SMB_ACL_USER;
4485 + *tag_type_p = SMB_ACL_GROUP;
4488 + case SMB_ACL_USER_OBJ:
4489 + case SMB_ACL_GROUP_OBJ:
4490 + case SMB_ACL_OTHER:
4491 + *tag_type_p = entry_d->ace_id->id_type;
4501 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4503 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4504 + *permset_p = &entry_d->ace_access;
4505 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4506 + if(!(**permset_p & S_IXUSR) &&
4507 + !(**permset_p & S_IWUSR) &&
4508 + !(**permset_p & S_IRUSR) &&
4509 + (**permset_p != 0))
4512 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4516 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4518 + return(entry_d->ace_id->id_data);
4521 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4523 + struct acl *file_acl = (struct acl *)NULL;
4524 + struct acl_entry *acl_entry;
4525 + struct new_acl_entry *new_acl_entry;
4526 + struct ace_id *idp;
4527 + struct acl_entry_link *acl_entry_link;
4528 + struct acl_entry_link *acl_entry_link_head;
4533 + /* AIX has no DEFAULT */
4534 + if ( type == SMB_ACL_TYPE_DEFAULT )
4537 + /* Get the acl using statacl */
4539 + DEBUG(10,("Entering sys_acl_get_file\n"));
4540 + DEBUG(10,("path_p is %s\n",path_p));
4542 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4544 + if(file_acl == NULL) {
4546 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4550 + memset(file_acl,0,BUFSIZ);
4552 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4554 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4555 + SAFE_FREE(file_acl);
4559 + DEBUG(10,("Got facl and returned it\n"));
4561 + /* Point to the first acl entry in the acl */
4562 + acl_entry = file_acl->acl_ext;
4564 + /* Begin setting up the head of the linked list *
4565 + * that will be used for the storing the acl *
4566 + * in a way that is useful for the posix_acls.c *
4569 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4570 + if(acl_entry_link_head == NULL)
4573 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4574 + if(acl_entry_link->entryp == NULL) {
4575 + SAFE_FREE(file_acl);
4577 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4581 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4582 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4584 + /* Check if the extended acl bit is on. *
4585 + * If it isn't, do not show the *
4586 + * contents of the acl since AIX intends *
4587 + * the extended info to remain unused */
4589 + if(file_acl->acl_mode & S_IXACL){
4590 + /* while we are not pointing to the very end */
4591 + while(acl_entry < acl_last(file_acl)) {
4592 + /* before we malloc anything, make sure this is */
4593 + /* a valid acl entry and one that we want to map */
4594 + idp = id_nxt(acl_entry->ace_id);
4595 + if((acl_entry->ace_type == ACC_SPECIFY ||
4596 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4597 + acl_entry = acl_nxt(acl_entry);
4601 + idp = acl_entry->ace_id;
4603 + /* Check if this is the first entry in the linked list. *
4604 + * The first entry needs to keep prevp pointing to NULL *
4605 + * and already has entryp allocated. */
4607 + if(acl_entry_link_head->count != 0) {
4608 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4610 + if(acl_entry_link->nextp == NULL) {
4611 + SAFE_FREE(file_acl);
4613 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4617 + acl_entry_link->nextp->prevp = acl_entry_link;
4618 + acl_entry_link = acl_entry_link->nextp;
4619 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4620 + if(acl_entry_link->entryp == NULL) {
4621 + SAFE_FREE(file_acl);
4623 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4626 + acl_entry_link->nextp = NULL;
4629 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4631 + /* Don't really need this since all types are going *
4632 + * to be specified but, it's better than leaving it 0 */
4634 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4636 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4638 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4640 + /* The access in the acl entries must be left shifted by *
4641 + * three bites, because they will ultimately be compared *
4642 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4644 + switch(acl_entry->ace_type){
4647 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4648 + acl_entry_link->entryp->ace_access <<= 6;
4649 + acl_entry_link_head->count++;
4652 + /* Since there is no way to return a DENY acl entry *
4653 + * change to PERMIT and then shift. */
4654 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4655 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4656 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4657 + acl_entry_link->entryp->ace_access <<= 6;
4658 + acl_entry_link_head->count++;
4664 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4665 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4667 + acl_entry = acl_nxt(acl_entry);
4669 + } /* end of if enabled */
4671 + /* Since owner, group, other acl entries are not *
4672 + * part of the acl entries in an acl, they must *
4673 + * be dummied up to become part of the list. */
4675 + for( i = 1; i < 4; i++) {
4676 + DEBUG(10,("i is %d\n",i));
4677 + if(acl_entry_link_head->count != 0) {
4678 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4679 + if(acl_entry_link->nextp == NULL) {
4680 + SAFE_FREE(file_acl);
4682 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4686 + acl_entry_link->nextp->prevp = acl_entry_link;
4687 + acl_entry_link = acl_entry_link->nextp;
4688 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4689 + if(acl_entry_link->entryp == NULL) {
4690 + SAFE_FREE(file_acl);
4692 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4697 + acl_entry_link->nextp = NULL;
4699 + new_acl_entry = acl_entry_link->entryp;
4700 + idp = new_acl_entry->ace_id;
4702 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4703 + new_acl_entry->ace_type = ACC_PERMIT;
4704 + idp->id_len = sizeof(struct ace_id);
4705 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4706 + memset(idp->id_data,0,sizeof(uid_t));
4710 + new_acl_entry->ace_access = file_acl->g_access << 6;
4711 + idp->id_type = SMB_ACL_GROUP_OBJ;
4715 + new_acl_entry->ace_access = file_acl->o_access << 6;
4716 + idp->id_type = SMB_ACL_OTHER;
4720 + new_acl_entry->ace_access = file_acl->u_access << 6;
4721 + idp->id_type = SMB_ACL_USER_OBJ;
4729 + acl_entry_link_head->count++;
4730 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4733 + acl_entry_link_head->count = 0;
4734 + SAFE_FREE(file_acl);
4736 + return(acl_entry_link_head);
4739 +SMB_ACL_T sys_acl_get_fd(int fd)
4741 + struct acl *file_acl = (struct acl *)NULL;
4742 + struct acl_entry *acl_entry;
4743 + struct new_acl_entry *new_acl_entry;
4744 + struct ace_id *idp;
4745 + struct acl_entry_link *acl_entry_link;
4746 + struct acl_entry_link *acl_entry_link_head;
4751 + /* Get the acl using fstatacl */
4753 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4754 + DEBUG(10,("fd is %d\n",fd));
4755 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4757 + if(file_acl == NULL) {
4759 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4763 + memset(file_acl,0,BUFSIZ);
4765 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4767 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4768 + SAFE_FREE(file_acl);
4772 + DEBUG(10,("Got facl and returned it\n"));
4774 + /* Point to the first acl entry in the acl */
4776 + acl_entry = file_acl->acl_ext;
4777 + /* Begin setting up the head of the linked list *
4778 + * that will be used for the storing the acl *
4779 + * in a way that is useful for the posix_acls.c *
4782 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4783 + if(acl_entry_link_head == NULL){
4784 + SAFE_FREE(file_acl);
4788 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4790 + if(acl_entry_link->entryp == NULL) {
4792 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4793 + SAFE_FREE(file_acl);
4797 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4798 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4800 + /* Check if the extended acl bit is on. *
4801 + * If it isn't, do not show the *
4802 + * contents of the acl since AIX intends *
4803 + * the extended info to remain unused */
4805 + if(file_acl->acl_mode & S_IXACL){
4806 + /* while we are not pointing to the very end */
4807 + while(acl_entry < acl_last(file_acl)) {
4808 + /* before we malloc anything, make sure this is */
4809 + /* a valid acl entry and one that we want to map */
4811 + idp = id_nxt(acl_entry->ace_id);
4812 + if((acl_entry->ace_type == ACC_SPECIFY ||
4813 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4814 + acl_entry = acl_nxt(acl_entry);
4818 + idp = acl_entry->ace_id;
4820 + /* Check if this is the first entry in the linked list. *
4821 + * The first entry needs to keep prevp pointing to NULL *
4822 + * and already has entryp allocated. */
4824 + if(acl_entry_link_head->count != 0) {
4825 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4826 + if(acl_entry_link->nextp == NULL) {
4828 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4829 + SAFE_FREE(file_acl);
4832 + acl_entry_link->nextp->prevp = acl_entry_link;
4833 + acl_entry_link = acl_entry_link->nextp;
4834 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4835 + if(acl_entry_link->entryp == NULL) {
4837 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4838 + SAFE_FREE(file_acl);
4842 + acl_entry_link->nextp = NULL;
4845 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4847 + /* Don't really need this since all types are going *
4848 + * to be specified but, it's better than leaving it 0 */
4850 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4851 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4853 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4855 + /* The access in the acl entries must be left shifted by *
4856 + * three bites, because they will ultimately be compared *
4857 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4859 + switch(acl_entry->ace_type){
4862 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4863 + acl_entry_link->entryp->ace_access <<= 6;
4864 + acl_entry_link_head->count++;
4867 + /* Since there is no way to return a DENY acl entry *
4868 + * change to PERMIT and then shift. */
4869 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4870 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4871 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4872 + acl_entry_link->entryp->ace_access <<= 6;
4873 + acl_entry_link_head->count++;
4879 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4880 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4882 + acl_entry = acl_nxt(acl_entry);
4884 + } /* end of if enabled */
4886 + /* Since owner, group, other acl entries are not *
4887 + * part of the acl entries in an acl, they must *
4888 + * be dummied up to become part of the list. */
4890 + for( i = 1; i < 4; i++) {
4891 + DEBUG(10,("i is %d\n",i));
4892 + if(acl_entry_link_head->count != 0){
4893 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4894 + if(acl_entry_link->nextp == NULL) {
4896 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4897 + SAFE_FREE(file_acl);
4901 + acl_entry_link->nextp->prevp = acl_entry_link;
4902 + acl_entry_link = acl_entry_link->nextp;
4903 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4905 + if(acl_entry_link->entryp == NULL) {
4906 + SAFE_FREE(file_acl);
4908 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4913 + acl_entry_link->nextp = NULL;
4915 + new_acl_entry = acl_entry_link->entryp;
4916 + idp = new_acl_entry->ace_id;
4918 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4919 + new_acl_entry->ace_type = ACC_PERMIT;
4920 + idp->id_len = sizeof(struct ace_id);
4921 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4922 + memset(idp->id_data,0,sizeof(uid_t));
4926 + new_acl_entry->ace_access = file_acl->g_access << 6;
4927 + idp->id_type = SMB_ACL_GROUP_OBJ;
4931 + new_acl_entry->ace_access = file_acl->o_access << 6;
4932 + idp->id_type = SMB_ACL_OTHER;
4936 + new_acl_entry->ace_access = file_acl->u_access << 6;
4937 + idp->id_type = SMB_ACL_USER_OBJ;
4944 + acl_entry_link_head->count++;
4945 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4948 + acl_entry_link_head->count = 0;
4949 + SAFE_FREE(file_acl);
4951 + return(acl_entry_link_head);
4954 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4956 + *permset = *permset & ~0777;
4960 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4963 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4967 + DEBUG(10,("This is the permset now: %d\n",*permset));
4971 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4976 +SMB_ACL_T sys_acl_init( int count)
4978 + struct acl_entry_link *theacl = NULL;
4980 + DEBUG(10,("Entering sys_acl_init\n"));
4982 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4983 + if(theacl == NULL) {
4985 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4989 + theacl->count = 0;
4990 + theacl->nextp = NULL;
4991 + theacl->prevp = NULL;
4992 + theacl->entryp = NULL;
4993 + DEBUG(10,("Exiting sys_acl_init\n"));
4997 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4999 + struct acl_entry_link *theacl;
5000 + struct acl_entry_link *acl_entryp;
5001 + struct acl_entry_link *temp_entry;
5004 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5006 + theacl = acl_entryp = *pacl;
5008 + /* Get to the end of the acl before adding entry */
5010 + for(counting=0; counting < theacl->count; counting++){
5011 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5012 + temp_entry = acl_entryp;
5013 + acl_entryp = acl_entryp->nextp;
5016 + if(theacl->count != 0){
5017 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5018 + if(acl_entryp == NULL) {
5020 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5024 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5025 + acl_entryp->prevp = temp_entry;
5026 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5029 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5030 + if(*pentry == NULL) {
5032 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5036 + memset(*pentry,0,sizeof(struct new_acl_entry));
5037 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5038 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5039 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5040 + acl_entryp->nextp = NULL;
5042 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5046 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5048 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5049 + entry->ace_id->id_type = tagtype;
5050 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5051 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5054 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5056 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5057 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5058 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5062 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5064 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5065 + if(!(*permset & S_IXUSR) &&
5066 + !(*permset & S_IWUSR) &&
5067 + !(*permset & S_IRUSR) &&
5071 + entry->ace_access = *permset;
5072 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5073 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5077 +int sys_acl_valid( SMB_ACL_T theacl )
5080 + int group_obj = 0;
5081 + int other_obj = 0;
5082 + struct acl_entry_link *acl_entry;
5084 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5085 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5086 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5087 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5090 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5092 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5098 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5100 + struct acl_entry_link *acl_entry_link = NULL;
5101 + struct acl *file_acl = NULL;
5102 + struct acl *file_acl_temp = NULL;
5103 + struct acl_entry *acl_entry = NULL;
5104 + struct ace_id *ace_id = NULL;
5111 + DEBUG(10,("Entering sys_acl_set_file\n"));
5112 + DEBUG(10,("File name is %s\n",name));
5114 + /* AIX has no default ACL */
5115 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5118 + acl_length = BUFSIZ;
5119 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5121 + if(file_acl == NULL) {
5123 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5127 + memset(file_acl,0,BUFSIZ);
5129 + file_acl->acl_len = ACL_SIZ;
5130 + file_acl->acl_mode = S_IXACL;
5132 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5133 + acl_entry_link->entryp->ace_access >>= 6;
5134 + id_type = acl_entry_link->entryp->ace_id->id_type;
5137 + case SMB_ACL_USER_OBJ:
5138 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5140 + case SMB_ACL_GROUP_OBJ:
5141 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5143 + case SMB_ACL_OTHER:
5144 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5146 + case SMB_ACL_MASK:
5150 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5151 + acl_length += sizeof(struct acl_entry);
5152 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5153 + if(file_acl_temp == NULL) {
5154 + SAFE_FREE(file_acl);
5156 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5160 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5161 + SAFE_FREE(file_acl);
5162 + file_acl = file_acl_temp;
5165 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5166 + file_acl->acl_len += sizeof(struct acl_entry);
5167 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5168 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5170 + /* In order to use this, we'll need to wait until we can get denies */
5171 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5172 + acl_entry->ace_type = ACC_SPECIFY; */
5174 + acl_entry->ace_type = ACC_SPECIFY;
5176 + ace_id = acl_entry->ace_id;
5178 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5179 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5180 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5181 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5182 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5185 + rc = chacl(name,file_acl,file_acl->acl_len);
5186 + DEBUG(10,("errno is %d\n",errno));
5187 + DEBUG(10,("return code is %d\n",rc));
5188 + SAFE_FREE(file_acl);
5189 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5193 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5195 + struct acl_entry_link *acl_entry_link = NULL;
5196 + struct acl *file_acl = NULL;
5197 + struct acl *file_acl_temp = NULL;
5198 + struct acl_entry *acl_entry = NULL;
5199 + struct ace_id *ace_id = NULL;
5205 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5206 + acl_length = BUFSIZ;
5207 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5209 + if(file_acl == NULL) {
5211 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5215 + memset(file_acl,0,BUFSIZ);
5217 + file_acl->acl_len = ACL_SIZ;
5218 + file_acl->acl_mode = S_IXACL;
5220 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5221 + acl_entry_link->entryp->ace_access >>= 6;
5222 + id_type = acl_entry_link->entryp->ace_id->id_type;
5223 + DEBUG(10,("The id_type is %d\n",id_type));
5226 + case SMB_ACL_USER_OBJ:
5227 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5229 + case SMB_ACL_GROUP_OBJ:
5230 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5232 + case SMB_ACL_OTHER:
5233 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5235 + case SMB_ACL_MASK:
5239 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5240 + acl_length += sizeof(struct acl_entry);
5241 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5242 + if(file_acl_temp == NULL) {
5243 + SAFE_FREE(file_acl);
5245 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5249 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5250 + SAFE_FREE(file_acl);
5251 + file_acl = file_acl_temp;
5254 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5255 + file_acl->acl_len += sizeof(struct acl_entry);
5256 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5257 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5259 + /* In order to use this, we'll need to wait until we can get denies */
5260 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5261 + acl_entry->ace_type = ACC_SPECIFY; */
5263 + acl_entry->ace_type = ACC_SPECIFY;
5265 + ace_id = acl_entry->ace_id;
5267 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5268 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5269 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5270 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5271 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5274 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5275 + DEBUG(10,("errno is %d\n",errno));
5276 + DEBUG(10,("return code is %d\n",rc));
5277 + SAFE_FREE(file_acl);
5278 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5282 +int sys_acl_delete_def_file(const char *name)
5284 + /* AIX has no default ACL */
5288 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5290 + return(*permset & perm);
5293 +int sys_acl_free_text(char *text)
5298 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5300 + struct acl_entry_link *acl_entry_link;
5302 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5303 + SAFE_FREE(acl_entry_link->prevp->entryp);
5304 + SAFE_FREE(acl_entry_link->prevp);
5307 + SAFE_FREE(acl_entry_link->prevp->entryp);
5308 + SAFE_FREE(acl_entry_link->prevp);
5309 + SAFE_FREE(acl_entry_link->entryp);
5310 + SAFE_FREE(acl_entry_link);
5315 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5320 +#else /* No ACLs. */
5322 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5328 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5334 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5340 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5346 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5349 + return (SMB_ACL_T)NULL;
5352 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5355 + return (SMB_ACL_T)NULL;
5358 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5364 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5370 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5373 + return (permset & perm) ? 1 : 0;
5376 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5382 +int sys_acl_free_text(UNUSED(char *text))
5388 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5394 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5400 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5406 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5412 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5418 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5424 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5430 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5436 +int sys_acl_delete_def_file(UNUSED(const char *name))
5442 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5448 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5454 +#endif /* No ACLs. */
5456 +/************************************************************************
5457 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5459 +************************************************************************/
5461 +int no_acl_syscall_error(int err)
5463 +#if defined(ENOSYS)
5464 + if (err == ENOSYS) {
5468 +#if defined(ENOTSUP)
5469 + if (err == ENOTSUP) {
5475 --- old/lib/sysacls.h
5476 +++ new/lib/sysacls.h
5478 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5479 +#include <sys/acl.h>
5481 +#include "smb_acls.h"
5483 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5484 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5485 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5486 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5487 +#define slprintf snprintf
5489 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5490 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5491 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5492 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5493 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5494 +SMB_ACL_T sys_acl_get_fd(int fd);
5495 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5496 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5497 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5498 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5499 +SMB_ACL_T sys_acl_init(int count);
5500 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5501 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5502 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5503 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5504 +int sys_acl_valid(SMB_ACL_T theacl);
5505 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5506 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5507 +int sys_acl_delete_def_file(const char *name);
5508 +int sys_acl_free_text(char *text);
5509 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5510 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5513 @@ -600,8 +600,10 @@ static void log_formatted(enum logcode c
5514 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5515 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5516 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5519 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5520 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5521 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5524 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5525 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5528 @@ -58,7 +58,7 @@ BEGIN {
5532 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5533 +!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5539 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5541 int preserve_links = 0;
5542 int preserve_hard_links = 0;
5543 +int preserve_acls = 0;
5544 int preserve_perms = 0;
5545 int preserve_executability = 0;
5546 int preserve_devices = 0;
5547 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
5548 char const *got_socketpair = "no ";
5549 char const *have_inplace = "no ";
5550 char const *hardlinks = "no ";
5551 + char const *acls = "no ";
5552 char const *links = "no ";
5553 char const *ipv6 = "no ";
5554 STRUCT_STAT *dumstat;
5555 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
5559 +#ifdef SUPPORT_ACLS
5563 #ifdef SUPPORT_LINKS
5566 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
5567 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5568 rprintf(f, "<http://rsync.samba.org/>\n");
5569 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5570 - "%shard links, %ssymlinks, batchfiles,\n",
5571 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
5572 (int) (sizeof (OFF_T) * 8),
5573 - got_socketpair, hardlinks, links);
5574 + got_socketpair, hardlinks, acls, links);
5576 /* Note that this field may not have type ino_t. It depends
5577 * on the complicated interaction between largefile feature
5578 @@ -295,6 +301,9 @@ void usage(enum logcode F)
5579 rprintf(F," -H, --hard-links preserve hard links\n");
5580 rprintf(F," -p, --perms preserve permissions\n");
5581 rprintf(F," -E, --executability preserve the file's executability\n");
5582 +#ifdef SUPPORT_ACLS
5583 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5585 rprintf(F," --chmod=CHMOD change destination permissions\n");
5586 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5587 rprintf(F," -g, --group preserve group\n");
5588 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
5589 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5590 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5591 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5592 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5593 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5594 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5595 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5596 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5597 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5598 @@ -1070,6 +1082,24 @@ int parse_arguments(int *argc, const cha
5603 +#ifdef SUPPORT_ACLS
5605 + preserve_perms = 1;
5608 + /* FIXME: this should probably be ignored with a
5609 + * warning and then countermeasures taken to
5610 + * restrict group and other access in the presence
5611 + * of any more restrictive ACLs, but this is safe
5613 + snprintf(err_buf,sizeof(err_buf),
5614 + "ACLs are not supported on this %s\n",
5615 + am_server ? "server" : "client");
5621 /* A large opt value means that set_refuse_options()
5622 * turned this option off. */
5623 @@ -1504,6 +1534,10 @@ void server_options(char **args,int *arg
5625 if (preserve_hard_links)
5627 +#ifdef SUPPORT_ACLS
5628 + if (preserve_acls)
5629 + argstr[x++] = 'A';
5636 @@ -48,6 +48,7 @@ extern int keep_partial;
5637 extern int checksum_seed;
5639 extern int delay_updates;
5640 +extern mode_t orig_umask;
5641 extern struct stats stats;
5642 extern char *log_format;
5643 extern char *tmpdir;
5644 @@ -346,6 +347,10 @@ int recv_files(int f_in, struct file_lis
5645 int itemizing = am_daemon ? daemon_log_format_has_i
5646 : !am_server && log_format_has_i;
5647 int max_phase = protocol_version >= 29 ? 2 : 1;
5648 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5649 +#ifdef SUPPORT_ACLS
5650 + char *parent_dirname = "";
5655 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5656 * mode based on the local permissions and some heuristics. */
5657 if (!preserve_perms) {
5658 int exists = fd1 != -1;
5659 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5660 +#ifdef SUPPORT_ACLS
5661 + char *dn = file->dirname ? file->dirname : ".";
5662 + if (parent_dirname != dn
5663 + && strcmp(parent_dirname, dn) != 0) {
5664 + dflt_perms = default_perms_for_dir(dn);
5665 + parent_dirname = dn;
5668 + file->mode = dest_mode(file->mode, st.st_mode,
5669 + dflt_perms, exists);
5672 /* We now check to see if we are writing file "inplace" */
5678 extern int daemon_log_format_has_i;
5679 +extern int preserve_acls;
5680 extern int preserve_perms;
5681 extern int preserve_executability;
5682 extern int preserve_times;
5683 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5685 /* This is only called when we aren't preserving permissions. Figure out what
5686 * the permissions should be and return them merged back into the mode. */
5687 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5688 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5691 /* If the file already exists, we'll return the local permissions,
5692 * possibly tweaked by the --executability option. */
5693 @@ -116,55 +118,63 @@ mode_t dest_mode(mode_t flist_mode, mode
5694 cur_mode |= (cur_mode & 0444) >> 2;
5697 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5698 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5699 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5700 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5701 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5704 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5705 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5711 int change_uid, change_gid;
5717 - if (link_stat(fname, &st2, 0) < 0) {
5718 + if (link_stat(fname, &sx2.st, 0) < 0) {
5719 rsyserr(FERROR, errno, "stat %s failed",
5724 +#ifdef SUPPORT_ACLS
5725 + sx2.acc_acl = sx2.def_acl = NULL;
5727 if (!preserve_perms && S_ISDIR(file->mode)
5728 - && st->st_mode & S_ISGID) {
5729 + && sx2.st.st_mode & S_ISGID) {
5730 /* We just created this directory and its setgid
5731 * bit is on, so make sure it stays on. */
5732 file->mode |= S_ISGID;
5737 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5738 +#ifdef SUPPORT_ACLS
5739 + if (preserve_acls && !ACL_READY(*sxp))
5740 + get_acl(fname, sxp);
5743 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5744 flags |= ATTRS_SKIP_MTIME;
5745 if (!(flags & ATTRS_SKIP_MTIME)
5746 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5747 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5748 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5749 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5751 rsyserr(FERROR, errno, "failed to set times on %s",
5756 if (ret == 0) /* ret == 1 if symlink could not be set */
5760 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5761 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5762 change_gid = preserve_gid && file->gid != GID_NONE
5763 - && st->st_gid != file->gid;
5764 + && sxp->st.st_gid != file->gid;
5765 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5766 - if (S_ISLNK(st->st_mode))
5767 + if (S_ISLNK(sxp->st.st_mode))
5771 @@ -174,43 +184,55 @@ int set_file_attrs(char *fname, struct f
5773 "set uid of %s from %ld to %ld\n",
5775 - (long)st->st_uid, (long)file->uid);
5776 + (long)sxp->st.st_uid, (long)file->uid);
5780 "set gid of %s from %ld to %ld\n",
5782 - (long)st->st_gid, (long)file->gid);
5783 + (long)sxp->st.st_gid, (long)file->gid);
5786 if (do_lchown(fname,
5787 - change_uid ? file->uid : st->st_uid,
5788 - change_gid ? file->gid : st->st_gid) != 0) {
5789 + change_uid ? file->uid : sxp->st.st_uid,
5790 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5791 /* shouldn't have attempted to change uid or gid
5792 * unless have the privilege */
5793 rsyserr(FERROR, errno, "%s %s failed",
5794 change_uid ? "chown" : "chgrp",
5799 /* a lchown had been done - we have to re-stat if the
5800 * destination had the setuid or setgid bits set due
5801 * to the side effect of the chown call */
5802 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5803 - link_stat(fname, st,
5804 - keep_dirlinks && S_ISDIR(st->st_mode));
5805 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5806 + link_stat(fname, &sxp->st,
5807 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5812 +#ifdef SUPPORT_ACLS
5813 + /* It's OK to call set_acl() now, even for a dir, as the generator
5814 + * will enable owner-writability using chmod, if necessary.
5816 + * If set_acl() changes permission bits in the process of setting
5817 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5818 + * need to chmod(). */
5819 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5824 - if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5825 - int ret = do_chmod(fname, file->mode);
5826 + if ((sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5827 + mode_t mode = file->mode;
5828 + int ret = do_chmod(fname, mode);
5830 rsyserr(FERROR, errno,
5831 "failed to set permissions on %s",
5836 if (ret == 0) /* ret == 1 if symlink could not be set */
5838 @@ -225,6 +247,11 @@ int set_file_attrs(char *fname, struct f
5840 rprintf(code, "%s is uptodate\n", fname);
5843 +#ifdef SUPPORT_ACLS
5844 + if (preserve_acls && sxp == &sx2)
5852 @@ -485,6 +485,15 @@ struct idev {
5853 #define IN_LOOPBACKNET 127
5856 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5857 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5858 +#define SUPPORT_ACLS 1
5861 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5862 +#define ACLS_NEED_MASK 1
5865 #define GID_NONE ((gid_t)-1)
5867 #define HL_CHECK_MASTER 0
5868 @@ -645,6 +654,17 @@ struct stats {
5870 struct chmod_mode_struct;
5872 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5880 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5881 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5883 #include "byteorder.h"
5884 #include "lib/mdfour.h"
5885 #include "lib/wildmatch.h"
5886 @@ -660,6 +680,16 @@ struct chmod_mode_struct;
5888 #define UNUSED(x) x __attribute__((__unused__))
5892 +#ifdef SUPPORT_ACLS
5893 + struct rsync_acl *acc_acl; /* access ACL */
5894 + struct rsync_acl *def_acl; /* default ACL */
5898 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5902 /* We have replacement versions of these if they're missing. */
5905 @@ -321,6 +321,7 @@ to the detailed description below for a
5906 -H, --hard-links preserve hard links
5907 -p, --perms preserve permissions
5908 -E, --executability preserve executability
5909 + -A, --acls preserve ACLs (implies -p) [non-standard]
5910 --chmod=CHMOD change destination permissions
5911 -o, --owner preserve owner (super-user only)
5912 -g, --group preserve group
5913 @@ -742,7 +743,9 @@ quote(itemize(
5914 permissions, though the bf(--executability) option might change just
5915 the execute permission for the file.
5916 it() New files get their "normal" permission bits set to the source
5917 - file's permissions masked with the receiving end's umask setting, and
5918 + file's permissions masked with the receiving directory's default
5919 + permissions (either the receiving process's umask, or the permissions
5920 + specified via the destination directory's default ACL), and
5921 their special permission bits disabled except in the case where a new
5922 directory inherits a setgid bit from its parent directory.
5924 @@ -773,9 +776,11 @@ The preservation of the destination's se
5925 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5926 versions erroneously preserved the three special permission bits for
5927 newly-created files when bf(--perms) was off, while overriding the
5928 -destination's setgid bit setting on a newly-created directory. (Keep in
5929 -mind that it is the version of the receiving rsync that affects this
5931 +destination's setgid bit setting on a newly-created directory. Default ACL
5932 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5933 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5934 +(Keep in mind that it is the version of the receiving rsync that affects
5937 dit(bf(-E, --executability)) This option causes rsync to preserve the
5938 executability (or non-executability) of regular files when bf(--perms) is
5939 @@ -793,6 +798,15 @@ quote(itemize(
5941 If bf(--perms) is enabled, this option is ignored.
5943 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5944 +ACLs to be the same as the source ACLs. This nonstandard option only
5945 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5947 +Note also that an optimization of the ACL-sending protocol used by this
5948 +version makes it incompatible with sending files to an older ACL-enabled
5949 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5950 +doubling is not needed when pulling files from an older rsync.
5952 dit(bf(--chmod)) This option tells rsync to apply one or more
5953 comma-separated "chmod" strings to the permission of the files in the
5954 transfer. The resulting value is treated as though it was the permissions
5955 @@ -1372,8 +1386,8 @@ if the receiving rsync is at least versi
5956 with older versions of rsync, but that also turns on the output of other
5959 -The "%i" escape has a cryptic output that is 9 letters long. The general
5960 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
5961 +The "%i" escape has a cryptic output that is 11 letters long. The general
5962 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
5963 type of update being done, bf(X) is replaced by the file-type, and the
5964 other letters represent attributes that may be output if they are being
5966 @@ -1422,7 +1436,11 @@ quote(itemize(
5967 sender's value (requires bf(--owner) and super-user privileges).
5968 it() A bf(g) means the group is different and is being updated to the
5969 sender's value (requires bf(--group) and the authority to set the group).
5970 - it() The bf(z) slot is reserved for future use.
5971 + it() The bf(u) slot is reserved for reporting update (access) time changes
5972 + (a feature that is not yet released).
5973 + it() The bf(a) means that the ACL information changed.
5974 + it() The bf(x) slot is reserved for reporting extended attribute changes
5975 + (a feature that is not yet released).
5978 One other output is possible: when deleting files, the "%i" will output
5983 + Unix SMB/Netbios implementation.
5985 + Portable SMB ACL interface
5986 + Copyright (C) Jeremy Allison 2000
5988 + This program is free software; you can redistribute it and/or modify
5989 + it under the terms of the GNU General Public License as published by
5990 + the Free Software Foundation; either version 2 of the License, or
5991 + (at your option) any later version.
5993 + This program is distributed in the hope that it will be useful,
5994 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5995 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5996 + GNU General Public License for more details.
5998 + You should have received a copy of the GNU General Public License
5999 + along with this program; if not, write to the Free Software
6000 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6003 +#ifndef _SMB_ACLS_H
6004 +#define _SMB_ACLS_H
6006 +#if defined HAVE_POSIX_ACLS
6008 +/* This is an identity mapping (just remove the SMB_). */
6010 +#define SMB_ACL_TAG_T acl_tag_t
6011 +#define SMB_ACL_TYPE_T acl_type_t
6012 +#define SMB_ACL_PERMSET_T acl_permset_t
6013 +#define SMB_ACL_PERM_T acl_perm_t
6014 +#define SMB_ACL_READ ACL_READ
6015 +#define SMB_ACL_WRITE ACL_WRITE
6016 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6018 +/* Types of ACLs. */
6019 +#define SMB_ACL_USER ACL_USER
6020 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6021 +#define SMB_ACL_GROUP ACL_GROUP
6022 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6023 +#define SMB_ACL_OTHER ACL_OTHER
6024 +#define SMB_ACL_MASK ACL_MASK
6026 +#define SMB_ACL_T acl_t
6028 +#define SMB_ACL_ENTRY_T acl_entry_t
6030 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6031 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6033 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6034 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6036 +#elif defined HAVE_TRU64_ACLS
6038 +/* This is for DEC/Compaq Tru64 UNIX */
6040 +#define SMB_ACL_TAG_T acl_tag_t
6041 +#define SMB_ACL_TYPE_T acl_type_t
6042 +#define SMB_ACL_PERMSET_T acl_permset_t
6043 +#define SMB_ACL_PERM_T acl_perm_t
6044 +#define SMB_ACL_READ ACL_READ
6045 +#define SMB_ACL_WRITE ACL_WRITE
6046 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6048 +/* Types of ACLs. */
6049 +#define SMB_ACL_USER ACL_USER
6050 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6051 +#define SMB_ACL_GROUP ACL_GROUP
6052 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6053 +#define SMB_ACL_OTHER ACL_OTHER
6054 +#define SMB_ACL_MASK ACL_MASK
6056 +#define SMB_ACL_T acl_t
6058 +#define SMB_ACL_ENTRY_T acl_entry_t
6060 +#define SMB_ACL_FIRST_ENTRY 0
6061 +#define SMB_ACL_NEXT_ENTRY 1
6063 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6064 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6066 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6068 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6069 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6072 +/* SVR4.2 ES/MP ACLs */
6073 +typedef int SMB_ACL_TAG_T;
6074 +typedef int SMB_ACL_TYPE_T;
6075 +typedef ushort *SMB_ACL_PERMSET_T;
6076 +typedef ushort SMB_ACL_PERM_T;
6077 +#define SMB_ACL_READ 4
6078 +#define SMB_ACL_WRITE 2
6079 +#define SMB_ACL_EXECUTE 1
6081 +/* Types of ACLs. */
6082 +#define SMB_ACL_USER USER
6083 +#define SMB_ACL_USER_OBJ USER_OBJ
6084 +#define SMB_ACL_GROUP GROUP
6085 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6086 +#define SMB_ACL_OTHER OTHER_OBJ
6087 +#define SMB_ACL_MASK CLASS_OBJ
6089 +typedef struct SMB_ACL_T {
6093 + struct acl acl[1];
6096 +typedef struct acl *SMB_ACL_ENTRY_T;
6098 +#define SMB_ACL_FIRST_ENTRY 0
6099 +#define SMB_ACL_NEXT_ENTRY 1
6101 +#define SMB_ACL_TYPE_ACCESS 0
6102 +#define SMB_ACL_TYPE_DEFAULT 1
6105 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6108 +#elif defined HAVE_HPUX_ACLS
6111 + * Based on the Solaris & UnixWare code.
6115 +#include <sys/aclv.h>
6117 +/* SVR4.2 ES/MP ACLs */
6118 +typedef int SMB_ACL_TAG_T;
6119 +typedef int SMB_ACL_TYPE_T;
6120 +typedef ushort *SMB_ACL_PERMSET_T;
6121 +typedef ushort SMB_ACL_PERM_T;
6122 +#define SMB_ACL_READ 4
6123 +#define SMB_ACL_WRITE 2
6124 +#define SMB_ACL_EXECUTE 1
6126 +/* Types of ACLs. */
6127 +#define SMB_ACL_USER USER
6128 +#define SMB_ACL_USER_OBJ USER_OBJ
6129 +#define SMB_ACL_GROUP GROUP
6130 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6131 +#define SMB_ACL_OTHER OTHER_OBJ
6132 +#define SMB_ACL_MASK CLASS_OBJ
6134 +typedef struct SMB_ACL_T {
6138 + struct acl acl[1];
6141 +typedef struct acl *SMB_ACL_ENTRY_T;
6143 +#define SMB_ACL_FIRST_ENTRY 0
6144 +#define SMB_ACL_NEXT_ENTRY 1
6146 +#define SMB_ACL_TYPE_ACCESS 0
6147 +#define SMB_ACL_TYPE_DEFAULT 1
6149 +#elif defined HAVE_IRIX_ACLS
6151 +#define SMB_ACL_TAG_T acl_tag_t
6152 +#define SMB_ACL_TYPE_T acl_type_t
6153 +#define SMB_ACL_PERMSET_T acl_permset_t
6154 +#define SMB_ACL_PERM_T acl_perm_t
6155 +#define SMB_ACL_READ ACL_READ
6156 +#define SMB_ACL_WRITE ACL_WRITE
6157 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6159 +/* Types of ACLs. */
6160 +#define SMB_ACL_USER ACL_USER
6161 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6162 +#define SMB_ACL_GROUP ACL_GROUP
6163 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6164 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6165 +#define SMB_ACL_MASK ACL_MASK
6167 +typedef struct SMB_ACL_T {
6173 +#define SMB_ACL_ENTRY_T acl_entry_t
6175 +#define SMB_ACL_FIRST_ENTRY 0
6176 +#define SMB_ACL_NEXT_ENTRY 1
6178 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6179 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6181 +#elif defined HAVE_AIX_ACLS
6183 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6185 +#include "/usr/include/acl.h"
6187 +typedef uint *SMB_ACL_PERMSET_T;
6189 +struct acl_entry_link{
6190 + struct acl_entry_link *prevp;
6191 + struct new_acl_entry *entryp;
6192 + struct acl_entry_link *nextp;
6196 +struct new_acl_entry{
6197 + unsigned short ace_len;
6198 + unsigned short ace_type;
6199 + unsigned int ace_access;
6200 + struct ace_id ace_id[1];
6203 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6204 +#define SMB_ACL_T struct acl_entry_link*
6206 +#define SMB_ACL_TAG_T unsigned short
6207 +#define SMB_ACL_TYPE_T int
6208 +#define SMB_ACL_PERM_T uint
6209 +#define SMB_ACL_READ S_IRUSR
6210 +#define SMB_ACL_WRITE S_IWUSR
6211 +#define SMB_ACL_EXECUTE S_IXUSR
6213 +/* Types of ACLs. */
6214 +#define SMB_ACL_USER ACEID_USER
6215 +#define SMB_ACL_USER_OBJ 3
6216 +#define SMB_ACL_GROUP ACEID_GROUP
6217 +#define SMB_ACL_GROUP_OBJ 4
6218 +#define SMB_ACL_OTHER 5
6219 +#define SMB_ACL_MASK 6
6222 +#define SMB_ACL_FIRST_ENTRY 1
6223 +#define SMB_ACL_NEXT_ENTRY 2
6225 +#define SMB_ACL_TYPE_ACCESS 0
6226 +#define SMB_ACL_TYPE_DEFAULT 1
6228 +#else /* No ACLs. */
6230 +/* No ACLS - fake it. */
6231 +#define SMB_ACL_TAG_T int
6232 +#define SMB_ACL_TYPE_T int
6233 +#define SMB_ACL_PERMSET_T mode_t
6234 +#define SMB_ACL_PERM_T mode_t
6235 +#define SMB_ACL_READ S_IRUSR
6236 +#define SMB_ACL_WRITE S_IWUSR
6237 +#define SMB_ACL_EXECUTE S_IXUSR
6239 +/* Types of ACLs. */
6240 +#define SMB_ACL_USER 0
6241 +#define SMB_ACL_USER_OBJ 1
6242 +#define SMB_ACL_GROUP 2
6243 +#define SMB_ACL_GROUP_OBJ 3
6244 +#define SMB_ACL_OTHER 4
6245 +#define SMB_ACL_MASK 5
6247 +typedef struct SMB_ACL_T {
6251 +typedef struct SMB_ACL_ENTRY_T {
6253 +} *SMB_ACL_ENTRY_T;
6255 +#define SMB_ACL_FIRST_ENTRY 0
6256 +#define SMB_ACL_NEXT_ENTRY 1
6258 +#define SMB_ACL_TYPE_ACCESS 0
6259 +#define SMB_ACL_TYPE_DEFAULT 1
6261 +#endif /* No ACLs. */
6262 +#endif /* _SMB_ACLS_H */
6265 @@ -79,3 +79,7 @@ struct filter_list_struct server_filter_
6269 + const char *who_am_i(void)
6273 --- old/testsuite/acls.test
6274 +++ new/testsuite/acls.test
6278 +# This program is distributable under the terms of the GNU GPL (see
6281 +# Test that rsync handles basic ACL preservation.
6283 +. $srcdir/testsuite/rsync.fns
6285 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6286 +case "$setfacl_nodef" in
6287 +true) test_skipped "I don't know how to use your setfacl command" ;;
6290 +makepath "$fromdir/foo"
6291 +echo something >"$fromdir/file1"
6292 +echo else >"$fromdir/file2"
6294 +files='foo file1 file2'
6296 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6297 +setfacl -m u:0:5 "$fromdir/file1"
6298 +setfacl -m u:0:5 "$fromdir/file2"
6300 +$RSYNC -avvA "$fromdir/" "$todir/"
6303 +getfacl $files >"$scratchdir/acls.txt"
6306 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6308 +# The script would have aborted on error, so getting here means we've won.
6310 --- old/testsuite/default-acls.test
6311 +++ new/testsuite/default-acls.test
6315 +# This program is distributable under the terms of the GNU GPL (see
6318 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6320 +. $srcdir/testsuite/rsync.fns
6322 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6323 +case "$setfacl_nodef" in
6324 +true) test_skipped "I don't know how to use your setfacl command" ;;
6325 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6326 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6328 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6330 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6332 + todir="$scratchdir/$1"
6334 + $setfacl_nodef "$todir"
6336 + case "$setfacl_nodef" in
6337 + *-k*) opts="-dm $2" ;;
6338 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6340 + setfacl $opts "$todir"
6342 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6343 + # even though the directory itself is outside the transfer
6344 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6345 + check_perms "$todir/to" $4 "Target $1"
6346 + check_perms "$todir/to/dir" $4 "Target $1"
6347 + check_perms "$todir/to/file" $3 "Target $1"
6348 + check_perms "$todir/to/program" $4 "Target $1"
6349 + # Make sure get_local_name doesn't mess us up when transferring only one file
6350 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6351 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6352 + # Make sure we obey default ACLs when not transferring a regular file
6353 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6354 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6357 +mkdir "$scratchdir/dir"
6358 +echo "File!" >"$scratchdir/file"
6359 +echo "#!/bin/sh" >"$scratchdir/program"
6360 +chmod 777 "$scratchdir/dir"
6361 +chmod 666 "$scratchdir/file"
6362 +chmod 777 "$scratchdir/program"
6364 +# Test some target directories
6366 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6367 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6368 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6369 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6370 +testit noda1 '' rw------- rwx------
6372 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6374 +testit noda3 '' rw-r--r-- rwxr-xr-x
6378 --- old/testsuite/devices.test
6379 +++ new/testsuite/devices.test
6380 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6381 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6383 cat <<EOT >"$chkfile"
6387 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6389 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6391 cat <<EOT >"$chkfile"
6395 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6397 @@ -58,7 +58,7 @@ sleep 1
6398 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6400 cat <<EOT >"$chkfile"
6404 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6406 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6409 cat <<EOT >"$chkfile"
6414 -hD+++++++ block2.5 => block3
6423 +hD+++++++++ block2.5 => block3
6429 if test ! -b "$fromdir/block2.5"; then
6430 sed -e '/block2\.5/d' \
6431 --- old/testsuite/itemize.test
6432 +++ new/testsuite/itemize.test
6433 @@ -29,14 +29,14 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6434 $RSYNC -iplr "$fromdir/" "$todir/" \
6436 cat <<EOT >"$chkfile"
6439 ->f+++++++ bar/baz/rsync
6441 ->f+++++++ foo/config1
6442 ->f+++++++ foo/config2
6443 ->f+++++++ foo/extra
6444 -cL+++++++ foo/sym -> ../bar/baz/rsync
6446 +cd+++++++++ bar/baz/
6447 +>f+++++++++ bar/baz/rsync
6449 +>f+++++++++ foo/config1
6450 +>f+++++++++ foo/config2
6451 +>f+++++++++ foo/extra
6452 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6454 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6456 @@ -48,10 +48,10 @@ chmod 601 "$fromdir/foo/config2"
6457 $RSYNC -iplrH "$fromdir/" "$todir/" \
6459 cat <<EOT >"$chkfile"
6460 ->f..T.... bar/baz/rsync
6461 ->f..T.... foo/config1
6462 ->f.sTp... foo/config2
6463 -hf..T.... foo/extra => foo/config1
6464 +>f..T...... bar/baz/rsync
6465 +>f..T...... foo/config1
6466 +>f.sTp..... foo/config2
6467 +hf..T...... foo/extra => foo/config1
6469 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6471 @@ -68,11 +68,11 @@ chmod 777 "$todir/bar/baz/rsync"
6472 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6474 cat <<EOT >"$chkfile"
6475 -.f..tp... bar/baz/rsync
6477 -.f..t.... foo/config1
6478 ->fcstp... foo/config2
6479 -cL..T.... foo/sym -> ../bar/baz/rsync
6480 +.f..tp..... bar/baz/rsync
6482 +.f..t...... foo/config1
6483 +>fcstp..... foo/config2
6484 +cL..T...... foo/sym -> ../bar/baz/rsync
6486 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6488 @@ -97,15 +97,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6491 cat <<EOT >"$chkfile"
6495 -.f...p... bar/baz/rsync
6498 ->f..t.... foo/config2
6500 -.L foo/sym -> ../bar/baz/rsync
6504 +.f...p..... bar/baz/rsync
6507 +>f..t...... foo/config2
6509 +.L foo/sym -> ../bar/baz/rsync
6511 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6513 @@ -124,8 +124,8 @@ touch "$todir/foo/config2"
6514 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6516 cat <<EOT >"$chkfile"
6517 -.f...p... foo/config1
6518 ->f..t.... foo/config2
6519 +.f...p..... foo/config1
6520 +>f..t...... foo/config2
6522 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6524 @@ -134,15 +134,15 @@ $RSYNC -ivvplrtH --copy-dest="$lddir" "$
6527 cat <<EOT >"$chkfile"
6535 -hf foo/extra => foo/config1
6536 -cL..T.... foo/sym -> ../bar/baz/rsync
6539 +cd+++++++++ bar/baz/
6544 +hf foo/extra => foo/config1
6545 +cL..T...... foo/sym -> ../bar/baz/rsync
6547 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6549 @@ -150,11 +150,11 @@ rm -rf "$todir"
6550 $RSYNC -iplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
6552 cat <<EOT >"$chkfile"
6557 -hf foo/extra => foo/config1
6560 +cd+++++++++ bar/baz/
6562 +hf foo/extra => foo/config1
6564 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6566 @@ -181,15 +181,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6569 cat <<EOT >"$chkfile"
6577 -hf foo/extra => foo/config1
6578 -hL foo/sym -> ../bar/baz/rsync
6581 +cd+++++++++ bar/baz/
6586 +hf foo/extra => foo/config1
6587 +hL foo/sym -> ../bar/baz/rsync
6589 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6591 @@ -197,10 +197,10 @@ rm -rf "$todir"
6592 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
6594 cat <<EOT >"$chkfile"
6601 +cd+++++++++ bar/baz/
6604 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6606 @@ -228,14 +228,14 @@ filter_outfile
6607 # TODO fix really-old problem when combining -H with --compare-dest:
6608 # missing output for foo/extra hard-link (and it might not be updated)!
6609 cat <<EOT >"$chkfile"
6617 -.L foo/sym -> ../bar/baz/rsync
6620 +cd+++++++++ bar/baz/
6625 +.L foo/sym -> ../bar/baz/rsync
6627 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
6629 @@ -243,10 +243,10 @@ rm -rf "$todir"
6630 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6632 cat <<EOT >"$chkfile"
6639 +cd+++++++++ bar/baz/
6642 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6648 extern int preserve_uid;
6649 extern int preserve_gid;
6650 +extern int preserve_acls;
6651 extern int numeric_ids;
6654 @@ -275,7 +276,7 @@ void send_uid_list(int f)
6658 - if (preserve_uid) {
6659 + if (preserve_uid || preserve_acls) {
6661 /* we send sequences of uid/byte-length/name */
6662 for (list = uidlist; list; list = list->next) {
6663 @@ -292,7 +293,7 @@ void send_uid_list(int f)
6667 - if (preserve_gid) {
6668 + if (preserve_gid || preserve_acls) {
6670 for (list = gidlist; list; list = list->next) {
6672 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
6676 - if (preserve_uid && !numeric_ids) {
6677 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6678 /* read the uid list */
6679 while ((id = read_int(f)) != 0) {
6680 int len = read_byte(f);
6681 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
6685 - if (preserve_gid && !numeric_ids) {
6686 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6687 /* read the gid list */
6688 while ((id = read_int(f)) != 0) {
6689 int len = read_byte(f);
6690 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
6694 +#ifdef SUPPORT_ACLS
6695 + if (preserve_acls && !numeric_ids) {
6697 + while ((id = next_acl_uid(flist)) != NULL)
6698 + *id = match_uid(*id);
6699 + while ((id = next_acl_gid(flist)) != NULL)
6700 + *id = match_gid(*id);
6704 /* Now convert all the uids/gids from sender values to our values. */
6705 if (am_root && preserve_uid && !numeric_ids) {
6706 for (i = 0; i < flist->count; i++)
6709 @@ -1515,3 +1515,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6714 +void *expand_item_list(item_list *lp, size_t item_size,
6715 + const char *desc, int incr)
6717 + /* First time through, 0 <= 0, so list is expanded. */
6718 + if (lp->malloced <= lp->count) {
6720 + size_t new_size = lp->malloced;
6722 + new_size -= incr; /* increase slowly */
6723 + else if (new_size < (size_t)incr)
6727 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6728 + if (verbose >= 4) {
6729 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6730 + who_am_i(), desc, (double)new_size * item_size,
6731 + new_ptr == lp->items ? " not" : "");
6734 + out_of_memory("expand_item_list");
6736 + lp->items = new_ptr;
6737 + lp->malloced = new_size;
6739 + return (char*)lp->items + (lp->count++ * item_size);