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 @@ -26,15 +26,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 read_only;
64 +extern int list_only;
65 +extern int orig_umask;
66 +extern int preserve_acls;
67 +extern unsigned int file_struct_len;
69 +/* === ACL structures === */
81 +#define NO_ENTRY ((uchar)0x80)
82 +typedef struct rsync_acl {
85 + /* These will be NO_ENTRY if there's no such entry. */
97 +static const rsync_acl empty_rsync_acl = {
98 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
101 +static item_list access_acl_list = EMPTY_ITEM_LIST;
102 +static item_list default_acl_list = EMPTY_ITEM_LIST;
104 +/* === Calculations on ACL types === */
106 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
108 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
109 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
110 + : "unknown SMB_ACL_TYPE_T";
113 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
114 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
116 +static int count_racl_entries(const rsync_acl *racl)
118 + return racl->users.count + racl->groups.count
119 + + (racl->user_obj != NO_ENTRY)
120 + + (racl->group_obj != NO_ENTRY)
121 + + (racl->mask != NO_ENTRY)
122 + + (racl->other != NO_ENTRY);
125 +static int calc_sacl_entries(const rsync_acl *racl)
127 + /* A System ACL always gets user/group/other permission entries. */
128 + return racl->users.count + racl->groups.count
129 +#ifdef ACLS_NEED_MASK
132 + + (racl->mask != NO_ENTRY) + 3;
136 +/* Extracts and returns the permission bits from the ACL. This cannot be
137 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
138 +static int rsync_acl_get_perms(const rsync_acl *racl)
140 + return (racl->user_obj << 6)
141 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
145 +/* Removes the permission-bit entries from the ACL because these
146 + * can be reconstructed from the file's mode. */
147 +static void rsync_acl_strip_perms(rsync_acl *racl)
149 + racl->user_obj = NO_ENTRY;
150 + if (racl->mask == NO_ENTRY)
151 + racl->group_obj = NO_ENTRY;
153 + if (racl->group_obj == racl->mask)
154 + racl->group_obj = NO_ENTRY;
155 + racl->mask = NO_ENTRY;
157 + racl->other = NO_ENTRY;
160 +/* Given an empty rsync_acl, fake up the permission bits. */
161 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
163 + racl->user_obj = (mode >> 6) & 7;
164 + racl->group_obj = (mode >> 3) & 7;
165 + racl->other = mode & 7;
168 +/* === Rsync ACL functions === */
170 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
172 + id_access *ida1, *ida2;
173 + int count = ial1->count;
174 + if (count != ial2->count)
178 + for (; count--; ida1++, ida2++) {
179 + if (ida1->access != ida2->access || ida1->id != ida2->id)
185 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
187 + return racl1->user_obj == racl2->user_obj
188 + && racl1->group_obj == racl2->group_obj
189 + && racl1->mask == racl2->mask
190 + && racl1->other == racl2->other
191 + && ida_entries_equal(&racl1->users, &racl2->users)
192 + && ida_entries_equal(&racl1->groups, &racl2->groups);
195 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
196 + * the ACL will be handled by the normal mode-preservation code. This is
197 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
198 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
199 + * that it might have several of its permission objects set to NO_ENTRY. */
200 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
201 + const rsync_acl *racl2, mode_t m)
203 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
204 + return False; /* One has a mask and the other doesn't */
206 + /* When there's a mask, the group_obj becomes an extended entry. */
207 + if (racl1->mask != NO_ENTRY) {
208 + /* A condensed rsync_acl with a mask can only have no
209 + * group_obj when it was identical to the mask. This
210 + * means that it was also identical to the group attrs
211 + * from the mode. */
212 + if (racl2->group_obj == NO_ENTRY) {
213 + if (racl1->group_obj != ((m >> 3) & 7))
215 + } else if (racl1->group_obj != racl2->group_obj)
218 + return ida_entries_equal(&racl1->users, &racl2->users)
219 + && ida_entries_equal(&racl1->groups, &racl2->groups);
222 +static void rsync_acl_free(rsync_acl *racl)
224 + if (racl->users.idas)
225 + free(racl->users.idas);
226 + if (racl->groups.idas)
227 + free(racl->groups.idas);
228 + *racl = empty_rsync_acl;
231 +void free_acl(statx *sxp)
233 + if (sxp->acc_acl) {
234 + rsync_acl_free(sxp->acc_acl);
235 + free(sxp->acc_acl);
236 + sxp->acc_acl = NULL;
238 + if (sxp->def_acl) {
239 + rsync_acl_free(sxp->def_acl);
240 + free(sxp->def_acl);
241 + sxp->def_acl = NULL;
245 +static int id_access_sorter(const void *r1, const void *r2)
247 + id_access *ida1 = (id_access *)r1;
248 + id_access *ida2 = (id_access *)r2;
249 + id_t rid1 = ida1->id, rid2 = ida2->id;
250 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
253 +static void sort_ida_entries(ida_entries *idal)
257 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
260 +/* Transfer the count id_access items out of the temp_ida_list into either
261 + * the users or groups ida_entries list in racl. */
262 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
267 + if (temp_ida_list->count) {
268 + int cnt = temp_ida_list->count;
269 + id_access *temp_idas = temp_ida_list->items;
270 + if (!(idas = new_array(id_access, cnt)))
271 + out_of_memory("save_idas");
272 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
276 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
279 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
280 + exit_cleanup(RERR_UNSUPPORTED);
282 + ent->count = temp_ida_list->count;
285 + /* Truncate the temporary list now that its idas have been saved. */
286 + temp_ida_list->count = 0;
289 +/* === System ACLs === */
291 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
292 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
294 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
295 + SMB_ACL_TAG_T prior_list_type = 0;
296 + SMB_ACL_ENTRY_T entry;
297 + const char *errfun;
300 + errfun = "sys_acl_get_entry";
301 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
303 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
304 + SMB_ACL_TAG_T tag_type;
305 + SMB_ACL_PERMSET_T permset;
309 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
310 + errfun = "sys_acl_get_tag_type";
313 + if ((rc = sys_acl_get_permset(entry, &permset))) {
314 + errfun = "sys_acl_get_tag_type";
317 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
318 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
319 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
320 + /* continue == done with entry; break == store in temporary ida list */
321 + switch (tag_type) {
322 + case SMB_ACL_USER_OBJ:
323 + if (racl->user_obj == NO_ENTRY)
324 + racl->user_obj = access;
326 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
330 + case SMB_ACL_GROUP_OBJ:
331 + if (racl->group_obj == NO_ENTRY)
332 + racl->group_obj = access;
334 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
336 + case SMB_ACL_GROUP:
339 + if (racl->mask == NO_ENTRY)
340 + racl->mask = access;
342 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
344 + case SMB_ACL_OTHER:
345 + if (racl->other == NO_ENTRY)
346 + racl->other = access;
348 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
351 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
354 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
355 + errfun = "sys_acl_get_tag_type";
359 + if (tag_type != prior_list_type) {
360 + if (prior_list_type)
361 + save_idas(&temp_ida_list, racl, prior_list_type);
362 + prior_list_type = tag_type;
364 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
365 + ida->id = *((id_t *)qualifier);
366 + ida->access = access;
367 + sys_acl_free_qualifier(qualifier, tag_type);
370 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
371 + rsync_acl_free(racl);
374 + if (prior_list_type)
375 + save_idas(&temp_ida_list, racl, prior_list_type);
377 + sort_ida_entries(&racl->users);
378 + sort_ida_entries(&racl->groups);
380 +#ifdef ACLS_NEED_MASK
381 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
382 + /* Throw away a superfluous mask, but mask off the
383 + * group perms with it first. */
384 + racl->group_obj &= racl->mask;
385 + racl->mask = NO_ENTRY;
392 +/* Synactic sugar for system calls */
394 +#define CALL_OR_ERROR(func,args,str) \
402 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
403 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
405 +/* Store the permissions in the system ACL entry. */
406 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
408 + const char *errfun = NULL;
409 + SMB_ACL_PERMSET_T permset;
411 + COE( sys_acl_get_permset,(entry, &permset) );
412 + COE( sys_acl_clear_perms,(permset) );
414 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
416 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
418 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
419 + COE( sys_acl_set_permset,(entry, permset) );
424 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
428 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
429 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
431 +#ifdef ACLS_NEED_MASK
436 + const char *errfun = NULL;
437 + SMB_ACL_ENTRY_T entry;
439 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
440 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
444 + COE( sys_acl_create_entry,(smb_acl, &entry) );
445 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
446 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
448 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
449 + COE( sys_acl_create_entry,(smb_acl, &entry) );
450 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
451 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
452 + COE2( store_access_in_entry,(ida->access, entry) );
455 + COE( sys_acl_create_entry,(smb_acl, &entry) );
456 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
457 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
459 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
460 + COE( sys_acl_create_entry,(smb_acl, &entry) );
461 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
462 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
463 + COE2( store_access_in_entry,(ida->access, entry) );
466 +#ifdef ACLS_NEED_MASK
467 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
468 + COE( sys_acl_create_entry,(smb_acl, &entry) );
469 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
470 + COE2( store_access_in_entry,(mask_bits, entry) );
472 + if (racl->mask != NO_ENTRY) {
473 + COE( sys_acl_create_entry,(smb_acl, &entry) );
474 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
475 + COE2( store_access_in_entry,(racl->mask, entry) );
479 + COE( sys_acl_create_entry,(smb_acl, &entry) );
480 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
481 + COE2( store_access_in_entry,(racl->other & 7, entry) );
484 + if (sys_acl_valid(*smb_acl) < 0)
485 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
492 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
494 + sys_acl_free_acl(*smb_acl);
498 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
499 + const item_list *racl_list,
500 + const rsync_acl *racl)
502 + static int access_match = -1, default_match = -1;
503 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
504 + size_t count = racl_list->count;
506 + /* If this is the first time through or we didn't match the last
507 + * time, then start at the end of the list, which should be the
508 + * best place to start hunting. */
510 + *match = racl_list->count - 1;
512 + rsync_acl *base = racl_list->items;
513 + if (rsync_acl_equal(base + *match, racl))
516 + *match = racl_list->count - 1;
523 +/* Return the Access Control List for the given filename. */
524 +int get_acl(const char *fname, statx *sxp)
526 + SMB_ACL_TYPE_T type;
528 + if (S_ISLNK(sxp->st.st_mode))
531 + type = SMB_ACL_TYPE_ACCESS;
533 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
534 + rsync_acl *racl = new(rsync_acl);
537 + out_of_memory("get_acl");
538 + *racl = empty_rsync_acl;
539 + if (type == SMB_ACL_TYPE_ACCESS)
540 + sxp->acc_acl = racl;
542 + sxp->def_acl = racl;
545 + BOOL ok = unpack_smb_acl(racl, sacl);
547 + sys_acl_free_acl(sacl);
552 + } else if (errno == ENOTSUP) {
553 + /* ACLs are not supported, so pretend we have a basic ACL. */
554 + if (type == SMB_ACL_TYPE_ACCESS)
555 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
557 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
558 + fname, str_acl_type(type));
562 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
567 +/* === Send functions === */
569 +/* The general strategy with the tag_type <-> character mapping is that
570 + * lowercase implies that no qualifier follows, where uppercase does.
571 + * A similar idiom for the ACL type (access or default) itself, but
572 + * lowercase in this instance means there's no ACL following, so the
573 + * ACL is a repeat, so the receiver should reuse the last of the same
576 +/* Send the ida list over the file descriptor. */
577 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
580 + size_t count = idal->count;
581 + for (ida = idal->idas; count--; ida++) {
582 + write_byte(f, tag_char);
583 + write_byte(f, ida->access);
584 + write_int(f, ida->id);
585 + /* FIXME: sorta wasteful: we should maybe buffer as
586 + * many ids as max(ACL_USER + ACL_GROUP) objects to
587 + * keep from making so many calls. */
588 + if (tag_char == 'U')
595 +/* Send an rsync ACL over the file descriptor. */
596 +static void send_rsync_acl(int f, const rsync_acl *racl)
598 + size_t count = count_racl_entries(racl);
599 + write_int(f, count);
600 + if (racl->user_obj != NO_ENTRY) {
601 + write_byte(f, 'u');
602 + write_byte(f, racl->user_obj);
604 + send_ida_entries(f, &racl->users, 'U');
605 + if (racl->group_obj != NO_ENTRY) {
606 + write_byte(f, 'g');
607 + write_byte(f, racl->group_obj);
609 + send_ida_entries(f, &racl->groups, 'G');
610 + if (racl->mask != NO_ENTRY) {
611 + write_byte(f, 'm');
612 + write_byte(f, racl->mask);
614 + if (racl->other != NO_ENTRY) {
615 + write_byte(f, 'o');
616 + write_byte(f, racl->other);
620 +/* Send the ACL from the statx structure down the indicated file descriptor.
621 + * This also frees the ACL data. */
622 +void send_acl(statx *sxp, int f)
624 + SMB_ACL_TYPE_T type;
625 + rsync_acl *racl, *new_racl;
626 + item_list *racl_list;
629 + if (S_ISLNK(sxp->st.st_mode))
632 + type = SMB_ACL_TYPE_ACCESS;
633 + racl = sxp->acc_acl;
634 + racl_list = &access_acl_list;
637 + racl = new(rsync_acl);
639 + out_of_memory("send_acl");
640 + *racl = empty_rsync_acl;
641 + if (type == SMB_ACL_TYPE_ACCESS) {
642 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
643 + sxp->acc_acl = racl;
645 + sxp->def_acl = racl;
648 + /* Avoid sending values that can be inferred from other data,
649 + * but only when preserve_acls == 1 (it is 2 when we must be
650 + * backward compatible with older acls.diff versions). */
651 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
652 + rsync_acl_strip_perms(racl);
653 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
654 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
657 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
658 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
659 + send_rsync_acl(f, racl);
661 + *racl = empty_rsync_acl;
663 + racl = sxp->def_acl;
664 + racl_list = &default_acl_list;
665 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
670 +/* === Receive functions === */
672 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
674 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
675 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
676 + uchar computed_mask_bits = 0;
680 + if (!(count = read_int(f)))
684 + char tag = read_byte(f);
685 + uchar access = read_byte(f);
686 + if (access & ~ (4 | 2 | 1)) {
687 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
689 + exit_cleanup(RERR_STREAMIO);
693 + if (racl->user_obj != NO_ENTRY) {
694 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
695 + exit_cleanup(RERR_STREAMIO);
697 + racl->user_obj = access;
700 + tag_type = SMB_ACL_USER;
703 + if (racl->group_obj != NO_ENTRY) {
704 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
705 + exit_cleanup(RERR_STREAMIO);
707 + racl->group_obj = access;
710 + tag_type = SMB_ACL_GROUP;
713 + if (racl->mask != NO_ENTRY) {
714 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
715 + exit_cleanup(RERR_STREAMIO);
717 + racl->mask = access;
720 + if (racl->other != NO_ENTRY) {
721 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
722 + exit_cleanup(RERR_STREAMIO);
724 + racl->other = access;
727 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
729 + exit_cleanup(RERR_STREAMIO);
731 + if (tag_type != prior_list_type) {
732 + if (prior_list_type)
733 + save_idas(&temp_ida_list, racl, prior_list_type);
734 + prior_list_type = tag_type;
736 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
737 + ida->access = access;
738 + ida->id = read_int(f);
739 + computed_mask_bits |= access;
741 + if (prior_list_type)
742 + save_idas(&temp_ida_list, racl, prior_list_type);
744 + if (type == SMB_ACL_TYPE_DEFAULT) {
745 + /* Ensure that these are never unset. */
746 + if (racl->user_obj == NO_ENTRY)
747 + racl->user_obj = 7;
748 + if (racl->group_obj == NO_ENTRY)
749 + racl->group_obj = 0;
750 + if (racl->other == NO_ENTRY)
754 + if (!racl->users.count && !racl->groups.count) {
755 + /* If we received a superfluous mask, throw it away. */
756 + if (racl->mask != NO_ENTRY) {
757 + /* Mask off the group perms with it first. */
758 + racl->group_obj &= racl->mask | NO_ENTRY;
759 + racl->mask = NO_ENTRY;
761 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
762 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
765 +/* Receive the ACL info the sender has included for this file-list entry. */
766 +void receive_acl(struct file_struct *file, int f)
768 + SMB_ACL_TYPE_T type;
769 + item_list *racl_list;
772 + if (S_ISLNK(file->mode))
775 + type = SMB_ACL_TYPE_ACCESS;
776 + racl_list = &access_acl_list;
777 + ndx_ptr = (char*)file + file_struct_len;
779 + char tag = read_byte(f);
782 + if (tag == 'A' || tag == 'a') {
783 + if (type != SMB_ACL_TYPE_ACCESS) {
784 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
785 + f_name(file, NULL));
786 + exit_cleanup(RERR_STREAMIO);
788 + } else if (tag == 'D' || tag == 'd') {
789 + if (type == SMB_ACL_TYPE_ACCESS) {
790 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
791 + f_name(file, NULL));
792 + exit_cleanup(RERR_STREAMIO);
795 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
796 + f_name(file, NULL), tag);
797 + exit_cleanup(RERR_STREAMIO);
799 + if (tag == 'A' || tag == 'D') {
801 + ndx = racl_list->count;
802 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
803 + duo_item->racl = empty_rsync_acl;
804 + receive_rsync_acl(&duo_item->racl, f, type);
805 + duo_item->sacl = NULL;
808 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
809 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
810 + f_name(file, NULL), str_acl_type(type), ndx);
811 + exit_cleanup(RERR_STREAMIO);
814 + SIVAL(ndx_ptr, 0, ndx);
815 + racl_list = &default_acl_list;
817 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
820 +/* Turn the ACL data in statx into cached ACL data, setting the index
821 + * values in the file struct. */
822 +void cache_acl(struct file_struct *file, statx *sxp)
824 + SMB_ACL_TYPE_T type;
826 + item_list *racl_list;
830 + if (S_ISLNK(file->mode))
833 + type = SMB_ACL_TYPE_ACCESS;
834 + racl = sxp->acc_acl;
835 + racl_list = &access_acl_list;
836 + ndx_ptr = (char*)file + file_struct_len;
840 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
842 + ndx = racl_list->count;
843 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
844 + new_duo->racl = *racl;
845 + new_duo->sacl = NULL;
846 + *racl = empty_rsync_acl;
848 + SIVAL(ndx_ptr, 0, ndx);
849 + racl = sxp->def_acl;
850 + racl_list = &default_acl_list;
852 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
857 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
859 + SMB_ACL_ENTRY_T entry;
860 + const char *errfun;
863 + if (S_ISDIR(mode)) {
864 + /* If the sticky bit is going on, it's not safe to allow all
865 + * the new ACL to go into effect before it gets set. */
866 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
867 + if (mode & S_ISVTX)
870 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
873 + /* If setuid or setgid is going off, it's not safe to allow all
874 + * the new ACL to go into effect before they get cleared. */
875 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
876 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
881 + errfun = "sys_acl_get_entry";
882 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
884 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
885 + SMB_ACL_TAG_T tag_type;
886 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
887 + errfun = "sys_acl_get_tag_type";
890 + switch (tag_type) {
891 + case SMB_ACL_USER_OBJ:
892 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
894 + case SMB_ACL_GROUP_OBJ:
895 + /* group is only empty when identical to group perms. */
896 + if (racl->group_obj != NO_ENTRY)
898 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
901 +#ifndef ACLS_NEED_MASK
902 + /* mask is only empty when we don't need it. */
903 + if (racl->mask == NO_ENTRY)
906 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
908 + case SMB_ACL_OTHER:
909 + COE2( store_access_in_entry,(mode & 7, entry) );
916 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
922 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
923 + /* Ensure that chmod() will be called to restore any lost setid bits. */
924 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
925 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
926 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
929 + /* Return the mode of the file on disk, as we will set them. */
930 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
933 +/* Set ACL on indicated filename.
935 + * This sets extended access ACL entries and default ACL. If convenient,
936 + * it sets permission bits along with the access ACL and signals having
937 + * done so by modifying sxp->st.st_mode.
939 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
940 + * with fname set to NULL to just check if the ACL is unchanged. */
941 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
944 + SMB_ACL_TYPE_T type;
947 + if (!dry_run && (read_only || list_only)) {
952 + if (S_ISLNK(file->mode))
955 + type = SMB_ACL_TYPE_ACCESS;
956 + ndx_ptr = (char*)file + file_struct_len;
960 + int32 ndx = IVAL(ndx_ptr, 0);
964 + if (type == SMB_ACL_TYPE_ACCESS) {
965 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
967 + duo_item = access_acl_list.items;
970 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
972 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
974 + duo_item = default_acl_list.items;
977 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
981 + if (!dry_run && fname) {
982 + if (type == SMB_ACL_TYPE_DEFAULT
983 + && duo_item->racl.user_obj == NO_ENTRY) {
984 + if (sys_acl_delete_def_file(fname) < 0) {
985 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
991 + mode_t cur_mode = sxp->st.st_mode;
992 + if (!duo_item->sacl
993 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
997 + if (type == SMB_ACL_TYPE_ACCESS) {
998 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
999 + cur_mode, file->mode);
1000 + if (cur_mode == (mode_t)~0)
1003 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
1004 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1005 + fname, str_acl_type(type));
1009 + if (type == SMB_ACL_TYPE_ACCESS)
1010 + sxp->st.st_mode = cur_mode;
1013 + if (unchanged == 1)
1015 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1020 +/* === Enumeration functions for uid mapping === */
1022 +/* Context -- one and only one. Should be cycled through once on uid
1023 + * mapping and once on gid mapping. */
1024 +static item_list *_enum_racl_lists[] = {
1025 + &access_acl_list, &default_acl_list, NULL
1028 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1029 +static int enum_ida_index = 0;
1030 +static size_t enum_racl_index = 0;
1032 +/* This returns the next tag_type id from the given ACL for the next entry,
1033 + * or it returns 0 if there are no more tag_type ids in the acl. */
1034 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1036 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1037 + if (enum_ida_index < idal->count) {
1038 + id_access *ida = &idal->idas[enum_ida_index++];
1041 + enum_ida_index = 0;
1045 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1047 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1049 + acl_duo *duo_item = racl_list->items;
1050 + duo_item += enum_racl_index;
1051 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1054 + enum_racl_index = 0;
1058 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1060 + for (; *enum_racl_list; enum_racl_list++) {
1061 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1065 + enum_racl_list = &_enum_racl_lists[0];
1069 +id_t *next_acl_uid()
1071 + return next_acl_list_id(SMB_ACL_USER);
1074 +id_t *next_acl_gid()
1076 + return next_acl_list_id(SMB_ACL_GROUP);
1079 +/* This is used by dest_mode(). */
1080 +int default_perms_for_dir(const char *dir)
1089 + perms = ACCESSPERMS & ~orig_umask;
1090 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1091 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1092 + if (sacl == NULL) {
1093 + /* Couldn't get an ACL. Darn. */
1096 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1100 + /* We're doing a dry run, so the containing directory
1101 + * wasn't actually created. Don't worry about it. */
1104 + /* Otherwise fall through. */
1106 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1107 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1113 + racl = empty_rsync_acl;
1114 + ok = unpack_smb_acl(&racl, sacl);
1115 + sys_acl_free_acl(sacl);
1117 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1121 + /* Apply the permission-bit entries of the default ACL, if any. */
1122 + if (racl.user_obj != NO_ENTRY) {
1123 + perms = rsync_acl_get_perms(&racl);
1125 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1128 + rsync_acl_free(&racl);
1132 +#endif /* SUPPORT_ACLS */
1135 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1136 extern char *backup_dir;
1139 +extern int preserve_acls;
1140 extern int preserve_devices;
1141 extern int preserve_specials;
1142 extern int preserve_links;
1143 @@ -94,7 +95,8 @@ path
1144 ****************************************************************************/
1145 static int make_bak_dir(char *fullpath)
1149 + struct file_struct *file;
1150 char *rel = fullpath + backup_dir_len;
1151 char *end = rel + strlen(rel);
1153 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1155 /* Try to transfer the directory settings of the
1156 * actual dir that the files are coming from. */
1157 - if (do_stat(rel, &st) < 0) {
1158 + if (do_stat(rel, &sx.st) < 0) {
1159 rsyserr(FERROR, errno,
1160 "make_bak_dir stat %s failed",
1163 - do_lchown(fullpath, st.st_uid, st.st_gid);
1164 - do_chmod(fullpath, st.st_mode);
1165 +#ifdef SUPPORT_ACLS
1166 + sx.acc_acl = sx.def_acl = NULL;
1168 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1170 +#ifdef SUPPORT_ACLS
1171 + if (preserve_acls) {
1172 + get_acl(rel, &sx);
1173 + cache_acl(file, &sx);
1176 + set_file_attrs(fullpath, file, NULL, 0);
1181 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1182 * We will move the file to be deleted into a parallel directory tree. */
1183 static int keep_backup(char *fname)
1187 struct file_struct *file;
1192 /* return if no file to keep */
1193 - if (do_lstat(fname, &st) < 0)
1194 + if (do_lstat(fname, &sx.st) < 0)
1196 +#ifdef SUPPORT_ACLS
1197 + sx.acc_acl = sx.def_acl = NULL;
1200 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1201 return 1; /* the file could have disappeared */
1202 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1203 if (!(buf = get_backup_name(fname)))
1206 +#ifdef SUPPORT_ACLS
1207 + if (preserve_acls) {
1208 + get_acl(fname, &sx);
1209 + cache_acl(file, &sx);
1213 /* Check to see if this is a device file, or link */
1214 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1215 || (preserve_specials && IS_SPECIAL(file->mode))) {
1216 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1217 if (robust_move(fname, buf) != 0) {
1218 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1219 full_fname(fname), buf);
1220 - } else if (st.st_nlink > 1) {
1221 + } else if (sx.st.st_nlink > 1) {
1222 /* If someone has hard-linked the file into the backup
1223 * dir, rename() might return success but do nothing! */
1224 robust_unlink(fname); /* Just in case... */
1225 --- old/configure.in
1226 +++ new/configure.in
1227 @@ -515,6 +515,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1228 AC_CHECK_LIB(resolv, strcasecmp)
1231 +AC_CHECK_FUNCS(aclsort)
1232 +if test x"$ac_cv_func_aclsort" = x"no"; then
1233 + AC_CHECK_LIB(sec, aclsort)
1236 dnl At the moment we don't test for a broken memcmp(), because all we
1237 dnl need to do is test for equality, not comparison, and it seems that
1238 dnl every platform has a memcmp that can do at least that.
1239 @@ -779,6 +784,78 @@ AC_SUBST(OBJ_RESTORE)
1240 AC_SUBST(CC_SHOBJ_FLAG)
1241 AC_SUBST(BUILD_POPT)
1243 +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h)
1244 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1245 +#################################################
1246 +# check for ACL support
1248 +AC_MSG_CHECKING(whether to support ACLs)
1249 +AC_ARG_ENABLE(acl-support,
1250 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1251 +[ case "$enableval" in
1254 + case "$host_os" in
1256 + AC_MSG_RESULT(Using UnixWare ACLs)
1257 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1259 + *solaris*|*cygwin*)
1260 + AC_MSG_RESULT(Using solaris ACLs)
1261 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1264 + AC_MSG_RESULT(Using HPUX ACLs)
1265 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1268 + AC_MSG_RESULT(Using IRIX ACLs)
1269 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1272 + AC_MSG_RESULT(Using AIX ACLs)
1273 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1276 + AC_MSG_RESULT(Using Tru64 ACLs)
1277 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1278 + LIBS="$LIBS -lpacl"
1281 + AC_MSG_RESULT(ACLs requested -- running tests)
1282 + AC_CHECK_LIB(acl,acl_get_file)
1283 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1284 + AC_TRY_LINK([#include <sys/types.h>
1285 +#include <sys/acl.h>],
1286 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1287 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1288 + AC_MSG_CHECKING(ACL test results)
1289 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1290 + AC_MSG_RESULT(Using posix ACLs)
1291 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1292 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1293 + AC_TRY_LINK([#include <sys/types.h>
1294 +#include <sys/acl.h>],
1295 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1296 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1297 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1298 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1301 + AC_MSG_ERROR(Failed to find ACL support)
1308 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1311 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1315 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1320 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1321 extern int one_file_system;
1322 extern int copy_dirlinks;
1323 extern int keep_dirlinks;
1324 +extern int preserve_acls;
1325 extern int preserve_links;
1326 extern int preserve_hard_links;
1327 extern int preserve_devices;
1328 @@ -133,6 +134,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 @@ -495,6 +498,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 @@ -598,13 +604,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 @@ -699,6 +719,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 @@ -949,6 +974,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 @@ -958,6 +986,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 @@ -965,6 +1002,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 @@ -35,6 +35,7 @@ extern int do_progress;
1432 extern int relative_paths;
1433 extern int implied_dirs;
1434 extern int keep_dirlinks;
1435 +extern int preserve_acls;
1436 extern int preserve_links;
1437 extern int preserve_devices;
1438 extern int preserve_specials;
1439 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1440 extern int max_delete;
1441 extern int force_delete;
1442 extern int one_file_system;
1443 +extern mode_t orig_umask;
1444 extern struct stats stats;
1445 extern dev_t filesystem_dev;
1446 extern char *backup_dir;
1447 @@ -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 @@ -605,7 +616,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 best_match = -1;
1518 @@ -614,7 +625,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 @@ -622,16 +633,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))
1545 if (always_checksum && preserve_times
1546 - && cmp_time(stp->st_mtime, file->modtime))
1547 + && cmp_time(sxp->st.st_mtime, file->modtime))
1551 @@ -646,14 +661,14 @@ 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)
1560 if (match_level == 3 && !copy_dest) {
1561 #ifdef SUPPORT_HARD_LINKS
1563 - if (hard_link_one(file, ndx, fname, 0, stp,
1564 + if (hard_link_one(file, ndx, fname, 0, sxp,
1566 itemizing && verbose > 1,
1568 @@ -665,8 +680,13 @@ static int try_dests_reg(struct file_str
1573 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1575 +#ifdef SUPPORT_ACLS
1576 + if (preserve_acls && !ACL_READY(*sxp))
1577 + get_acl(fname, sxp);
1579 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1581 if (verbose > 1 && maybe_ATTRS_REPORT) {
1582 rprintf(FCLIENT, "%s is uptodate\n", fname);
1584 @@ -682,8 +702,13 @@ static int try_dests_reg(struct file_str
1589 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1591 +#ifdef SUPPORT_ACLS
1592 + if (preserve_acls && !ACL_READY(*sxp))
1593 + get_acl(fname, sxp);
1595 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1597 set_file_attrs(fname, file, NULL, 0);
1598 if (maybe_ATTRS_REPORT
1599 && ((!itemizing && verbose && match_level == 2)
1600 @@ -707,13 +732,18 @@ static int try_dests_non(struct file_str
1603 char fnamebuf[MAXPATHLEN];
1609 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1610 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1611 - || !unchanged_attrs(file, &st))
1612 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1614 +#ifdef SUPPORT_ACLS
1615 + if (preserve_acls)
1616 + get_acl(fnamebuf, &sx);
1618 + if (!unchanged_attrs(file, &sx))
1620 if (S_ISLNK(file->mode)) {
1621 #ifdef SUPPORT_LINKS
1622 @@ -726,10 +756,10 @@ static int try_dests_non(struct file_str
1625 } else if (IS_SPECIAL(file->mode)) {
1626 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1627 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1629 } else if (IS_DEVICE(file->mode)) {
1630 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1631 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1635 @@ -760,7 +790,15 @@ static int try_dests_non(struct file_str
1636 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1637 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1638 char *lp = link_dest ? "" : NULL;
1639 - itemize(file, ndx, 0, &st, changes, 0, lp);
1640 +#ifdef SUPPORT_ACLS
1641 + if (preserve_acls)
1642 + get_acl(fname, &sx);
1644 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1645 +#ifdef SUPPORT_ACLS
1646 + if (preserve_acls)
1650 if (verbose > 1 && maybe_ATTRS_REPORT) {
1651 rprintf(FCLIENT, "%s is uptodate\n", fname);
1652 @@ -772,6 +810,7 @@ static int try_dests_non(struct file_str
1655 static int phase = 0;
1656 +static int dflt_perms;
1658 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1659 * make sure it exists, and has the right permissions/timestamp info. For
1660 @@ -793,7 +832,8 @@ static void recv_generator(char *fname,
1661 static int need_fuzzy_dirlist = 0;
1662 struct file_struct *fuzzy_file = NULL;
1663 int fd = -1, f_copy = -1;
1664 - STRUCT_STAT st, real_st, partial_st;
1665 + statx sx, real_sx;
1666 + STRUCT_STAT partial_st;
1667 struct file_struct *back_file = NULL;
1668 int statret, real_ret, stat_errno;
1669 char *fnamecmp, *partialptr, *backupptr = NULL;
1670 @@ -849,6 +889,9 @@ static void recv_generator(char *fname,
1671 } else if (!dry_run)
1674 +#ifdef SUPPORT_ACLS
1675 + sx.acc_acl = sx.def_acl = NULL;
1679 stat_errno = ENOENT;
1680 @@ -856,7 +899,7 @@ static void recv_generator(char *fname,
1681 char *dn = file->dirname ? file->dirname : ".";
1682 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1683 if (relative_paths && !implied_dirs
1684 - && do_stat(dn, &st) < 0
1685 + && do_stat(dn, &sx.st) < 0
1686 && create_directory_path(fname) < 0) {
1687 rsyserr(FERROR, errno,
1688 "recv_generator: mkdir %s failed",
1689 @@ -868,6 +911,10 @@ static void recv_generator(char *fname,
1692 need_fuzzy_dirlist = 1;
1693 +#ifdef SUPPORT_ACLS
1694 + if (!preserve_perms)
1695 + dflt_perms = default_perms_for_dir(dn);
1698 parent_dirname = dn;
1700 @@ -876,7 +923,7 @@ static void recv_generator(char *fname,
1701 need_fuzzy_dirlist = 0;
1704 - statret = link_stat(fname, &st,
1705 + statret = link_stat(fname, &sx.st,
1706 keep_dirlinks && S_ISDIR(file->mode));
1709 @@ -894,8 +941,9 @@ static void recv_generator(char *fname,
1710 * mode based on the local permissions and some heuristics. */
1711 if (!preserve_perms) {
1712 int exists = statret == 0
1713 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1714 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1715 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1716 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1720 if (S_ISDIR(file->mode)) {
1721 @@ -904,8 +952,8 @@ static void recv_generator(char *fname,
1722 * file of that name and it is *not* a directory, then
1723 * we need to delete it. If it doesn't exist, then
1724 * (perhaps recursively) create it. */
1725 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1726 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1727 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1728 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1732 @@ -920,7 +968,11 @@ static void recv_generator(char *fname,
1736 - itemize(file, ndx, sr, &st,
1737 +#ifdef SUPPORT_ACLS
1738 + if (preserve_acls && sr == 0)
1739 + get_acl(fname, &sx);
1741 + itemize(file, ndx, sr, &sx,
1742 sr ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1744 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1745 @@ -940,19 +992,19 @@ static void recv_generator(char *fname,
1749 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1750 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1751 && verbose && code != FNONE && f_out != -1)
1752 rprintf(code, "%s/\n", fname);
1753 if (delete_during && f_out != -1 && !phase && dry_run < 2
1754 && (file->flags & FLAG_DEL_HERE))
1755 - delete_in_dir(the_file_list, fname, file, &st);
1757 + delete_in_dir(the_file_list, fname, file, &sx.st);
1761 if (preserve_hard_links && file->link_u.links
1762 - && hard_link_check(file, ndx, fname, statret, &st,
1763 + && hard_link_check(file, ndx, fname, statret, &sx,
1764 itemizing, code, HL_CHECK_MASTER))
1768 if (preserve_links && S_ISLNK(file->mode)) {
1769 #ifdef SUPPORT_LINKS
1770 @@ -970,7 +1022,7 @@ static void recv_generator(char *fname,
1771 char lnk[MAXPATHLEN];
1774 - if (!S_ISDIR(st.st_mode)
1775 + if (!S_ISDIR(sx.st.st_mode)
1776 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1778 /* A link already pointing to the
1779 @@ -978,10 +1030,10 @@ static void recv_generator(char *fname,
1781 if (strcmp(lnk, file->u.link) == 0) {
1783 - itemize(file, ndx, 0, &st, 0,
1784 + itemize(file, ndx, 0, &sx, 0,
1787 - set_file_attrs(fname, file, &st,
1788 + set_file_attrs(fname, file, &sx,
1789 maybe_ATTRS_REPORT);
1790 if (preserve_hard_links
1791 && file->link_u.links) {
1792 @@ -996,9 +1048,9 @@ static void recv_generator(char *fname,
1794 /* Not the right symlink (or not a symlink), so
1796 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1797 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1799 - if (!S_ISLNK(st.st_mode))
1800 + if (!S_ISLNK(sx.st.st_mode))
1802 } else if (basis_dir[0] != NULL) {
1803 if (try_dests_non(file, fname, ndx, itemizing,
1804 @@ -1015,7 +1067,7 @@ static void recv_generator(char *fname,
1807 if (preserve_hard_links && file->link_u.links
1808 - && hard_link_check(file, ndx, fname, -1, &st,
1809 + && hard_link_check(file, ndx, fname, -1, &sx,
1810 itemizing, code, HL_SKIP))
1812 if (do_symlink(file->u.link,fname) != 0) {
1813 @@ -1024,7 +1076,7 @@ static void recv_generator(char *fname,
1815 set_file_attrs(fname, file, NULL, 0);
1817 - itemize(file, ndx, statret, &st,
1818 + itemize(file, ndx, statret, &sx,
1819 ITEM_LOCAL_CHANGE, 0, NULL);
1821 if (code != FNONE && verbose) {
1822 @@ -1059,18 +1111,22 @@ static void recv_generator(char *fname,
1826 +#ifdef SUPPORT_ACLS
1827 + if (preserve_acls && statret == 0)
1828 + get_acl(fname, &sx);
1831 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1832 - || st.st_rdev != file->u.rdev) {
1833 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1834 + || sx.st.st_rdev != file->u.rdev) {
1836 - && delete_item(fname, st.st_mode, del_opts) < 0)
1838 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1840 if (preserve_hard_links && file->link_u.links
1841 - && hard_link_check(file, ndx, fname, -1, &st,
1842 + && hard_link_check(file, ndx, fname, -1, &sx,
1843 itemizing, code, HL_SKIP))
1845 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1846 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1848 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1849 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1852 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1853 @@ -1083,7 +1139,7 @@ static void recv_generator(char *fname,
1855 set_file_attrs(fname, file, NULL, 0);
1857 - itemize(file, ndx, statret, &st,
1858 + itemize(file, ndx, statret, &sx,
1859 ITEM_LOCAL_CHANGE, 0, NULL);
1861 if (code != FNONE && verbose)
1862 @@ -1097,14 +1153,14 @@ static void recv_generator(char *fname,
1866 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1867 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1868 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1869 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1870 if (preserve_hard_links && file->link_u.links)
1871 hard_link_cluster(file, ndx, itemizing, code);
1872 if (remove_source_files == 1)
1873 goto return_with_success;
1879 if (!S_ISREG(file->mode)) {
1880 @@ -1138,7 +1194,7 @@ static void recv_generator(char *fname,
1883 if (update_only && statret == 0
1884 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1885 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1887 rprintf(FINFO, "%s is newer\n", fname);
1889 @@ -1147,20 +1203,20 @@ static void recv_generator(char *fname,
1891 fnamecmp_type = FNAMECMP_FNAME;
1893 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1894 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1895 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1896 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1899 stat_errno = ENOENT;
1902 if (statret != 0 && basis_dir[0] != NULL) {
1903 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1904 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1905 itemizing, maybe_ATTRS_REPORT, code);
1907 if (remove_source_files == 1)
1908 goto return_with_success;
1913 fnamecmp = fnamecmpbuf;
1914 @@ -1170,7 +1226,7 @@ static void recv_generator(char *fname,
1921 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1922 && link_stat(partialptr, &partial_st, 0) == 0
1923 @@ -1189,7 +1245,7 @@ static void recv_generator(char *fname,
1924 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1925 fname, fnamecmpbuf);
1927 - st.st_size = fuzzy_file->length;
1928 + sx.st.st_size = fuzzy_file->length;
1930 fnamecmp = fnamecmpbuf;
1931 fnamecmp_type = FNAMECMP_FUZZY;
1932 @@ -1198,7 +1254,7 @@ static void recv_generator(char *fname,
1935 if (preserve_hard_links && file->link_u.links
1936 - && hard_link_check(file, ndx, fname, statret, &st,
1937 + && hard_link_check(file, ndx, fname, statret, &sx,
1938 itemizing, code, HL_SKIP))
1940 if (stat_errno == ENOENT)
1941 @@ -1208,39 +1264,52 @@ static void recv_generator(char *fname,
1945 - if (append_mode && st.st_size > file->length)
1946 + if (append_mode && sx.st.st_size > file->length)
1949 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1951 else if (fnamecmp_type == FNAMECMP_FUZZY)
1953 - else if (unchanged_file(fnamecmp, file, &st)) {
1954 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1956 do_unlink(partialptr);
1957 handle_partial_dir(partialptr, PDIR_DELETE);
1960 - itemize(file, ndx, real_ret, &real_st,
1961 +#ifdef SUPPORT_ACLS
1962 + if (preserve_acls && real_ret == 0)
1963 + get_acl(fnamecmp, &real_sx);
1965 + itemize(file, ndx, real_ret, &real_sx,
1967 +#ifdef SUPPORT_ACLS
1968 + if (preserve_acls) {
1969 + if (fnamecmp_type == FNAMECMP_FNAME) {
1970 + sx.acc_acl = real_sx.acc_acl;
1971 + sx.def_acl = real_sx.def_acl;
1973 + free_acl(&real_sx);
1977 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1978 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1979 if (preserve_hard_links && file->link_u.links)
1980 hard_link_cluster(file, ndx, itemizing, code);
1981 if (remove_source_files != 1)
1984 return_with_success:
1987 SIVAL(numbuf, 0, ndx);
1988 send_msg(MSG_SUCCESS, numbuf, 4);
1997 + sx.st = partial_st;
1998 fnamecmp = partialptr;
1999 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2001 @@ -1264,17 +1333,21 @@ static void recv_generator(char *fname,
2003 /* pretend the file didn't exist */
2004 if (preserve_hard_links && file->link_u.links
2005 - && hard_link_check(file, ndx, fname, statret, &st,
2006 + && hard_link_check(file, ndx, fname, statret, &sx,
2007 itemizing, code, HL_SKIP))
2010 statret = real_ret = -1;
2011 +#ifdef SUPPORT_ACLS
2012 + if (preserve_acls && ACL_READY(sx))
2018 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2019 if (!(backupptr = get_backup_name(fname))) {
2024 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2026 @@ -1285,7 +1358,7 @@ static void recv_generator(char *fname,
2027 full_fname(backupptr));
2033 if ((f_copy = do_open(backupptr,
2034 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2035 @@ -1293,14 +1366,14 @@ static void recv_generator(char *fname,
2036 full_fname(backupptr));
2042 fnamecmp_type = FNAMECMP_BACKUP;
2046 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2047 - fnamecmp, (double)st.st_size);
2048 + fnamecmp, (double)sx.st.st_size);
2052 @@ -1318,24 +1391,32 @@ static void recv_generator(char *fname,
2053 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2054 if (fnamecmp_type == FNAMECMP_FUZZY)
2055 iflags |= ITEM_XNAME_FOLLOWS;
2056 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2057 +#ifdef SUPPORT_ACLS
2058 + if (preserve_acls && real_ret == 0)
2059 + get_acl(fnamecmp, &real_sx);
2061 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2062 fuzzy_file ? fuzzy_file->basename : NULL);
2063 +#ifdef SUPPORT_ACLS
2064 + if (preserve_acls)
2065 + free_acl(&real_sx);
2070 if (preserve_hard_links && file->link_u.links)
2071 hard_link_cluster(file, ndx, itemizing, code);
2079 if (statret != 0 || whole_file) {
2080 write_sum_head(f_out, NULL);
2085 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2086 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2090 @@ -1348,6 +1429,13 @@ static void recv_generator(char *fname,
2096 +#ifdef SUPPORT_ACLS
2097 + if (preserve_acls)
2103 void generate_files(int f_out, struct file_list *flist, char *local_name)
2104 @@ -1407,6 +1495,8 @@ void generate_files(int f_out, struct fi
2105 * notice that and let us know via the redo pipe (or its closing). */
2108 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2110 for (i = 0; i < flist->count; i++) {
2111 struct file_struct *file = flist->files[i];
2117 extern int do_xfers;
2118 extern int link_dest;
2119 +extern int preserve_acls;
2120 extern int make_backups;
2121 extern int remove_source_files;
2122 extern int stdout_format_has_i;
2123 @@ -147,15 +148,19 @@ void init_hard_links(void)
2125 #ifdef SUPPORT_HARD_LINKS
2126 static int maybe_hard_link(struct file_struct *file, int ndx,
2127 - char *fname, int statret, STRUCT_STAT *st,
2128 + char *fname, int statret, statx *sxp,
2129 char *toname, STRUCT_STAT *to_st,
2130 int itemizing, enum logcode code)
2133 - if (st->st_dev == to_st->st_dev
2134 - && st->st_ino == to_st->st_ino) {
2135 + if (sxp->st.st_dev == to_st->st_dev
2136 + && sxp->st.st_ino == to_st->st_ino) {
2138 - itemize(file, ndx, statret, st,
2139 +#ifdef SUPPORT_ACLS
2140 + if (preserve_acls && !ACL_READY(*sxp))
2141 + get_acl(fname, sxp);
2143 + itemize(file, ndx, statret, sxp,
2144 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2147 @@ -170,13 +175,13 @@ static int maybe_hard_link(struct file_s
2151 - return hard_link_one(file, ndx, fname, statret, st, toname,
2152 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2153 0, itemizing, code);
2157 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2158 - int statret, STRUCT_STAT *st, int itemizing,
2159 + int statret, statx *sxp, int itemizing,
2160 enum logcode code, int skip)
2162 #ifdef SUPPORT_HARD_LINKS
2163 @@ -217,7 +222,7 @@ int hard_link_check(struct file_struct *
2164 || st2.st_ino != st3.st_ino)
2169 if (verbose < 2 || !stdout_format_has_i) {
2172 @@ -227,12 +232,16 @@ int hard_link_check(struct file_struct *
2173 if (!unchanged_file(cmpbuf, file, &st3))
2177 - if (unchanged_attrs(file, &st3))
2179 +#ifdef SUPPORT_ACLS
2180 + if (preserve_acls)
2181 + get_acl(cmpbuf, sxp);
2183 + if (unchanged_attrs(file, sxp))
2185 } while (basis_dir[++j] != NULL);
2187 - maybe_hard_link(file, ndx, fname, statret, st,
2188 + maybe_hard_link(file, ndx, fname, statret, sxp,
2189 toname, &st2, itemizing, code);
2190 if (remove_source_files == 1 && do_xfers) {
2192 @@ -250,7 +259,7 @@ int hard_link_check(struct file_struct *
2194 #ifdef SUPPORT_HARD_LINKS
2195 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2196 - int statret, STRUCT_STAT *st, char *toname, int terse,
2197 + int statret, statx *sxp, char *toname, int terse,
2198 int itemizing, enum logcode code)
2200 if (do_link(toname, fname)) {
2201 @@ -266,7 +275,11 @@ int hard_link_one(struct file_struct *fi
2205 - itemize(file, ndx, statret, st,
2206 +#ifdef SUPPORT_ACLS
2207 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2208 + get_acl(fname, sxp);
2210 + itemize(file, ndx, statret, sxp,
2211 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2212 terse ? "" : toname);
2214 @@ -283,11 +296,12 @@ void hard_link_cluster(struct file_struc
2215 #ifdef SUPPORT_HARD_LINKS
2216 char hlink1[MAXPATHLEN];
2218 - STRUCT_STAT st1, st2;
2221 int statret, ndx = master;
2223 file->F_HLINDEX = FINISHED_LINK;
2224 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2225 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2227 if (!(file->flags & FLAG_HLINK_TOL)) {
2228 while (!(file->flags & FLAG_HLINK_EOL)) {
2229 @@ -301,9 +315,13 @@ void hard_link_cluster(struct file_struc
2230 if (file->F_HLINDEX != SKIPPED_LINK)
2232 hlink2 = f_name(file, NULL);
2233 - statret = link_stat(hlink2, &st2, 0);
2234 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2235 - hlink1, &st1, itemizing, code);
2236 + statret = link_stat(hlink2, &sx.st, 0);
2237 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2238 + hlink1, &st, itemizing, code);
2239 +#ifdef SUPPORT_ACLS
2240 + if (preserve_acls)
2243 if (remove_source_files == 1 && do_xfers) {
2245 SIVAL(numbuf, 0, ndx);
2246 --- old/lib/sysacls.c
2247 +++ new/lib/sysacls.c
2250 + Unix SMB/CIFS implementation.
2251 + Samba system utilities for ACL support.
2252 + Copyright (C) Jeremy Allison 2000.
2254 + This program is free software; you can redistribute it and/or modify
2255 + it under the terms of the GNU General Public License as published by
2256 + the Free Software Foundation; either version 2 of the License, or
2257 + (at your option) any later version.
2259 + This program is distributed in the hope that it will be useful,
2260 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2261 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2262 + GNU General Public License for more details.
2264 + You should have received a copy of the GNU General Public License
2265 + along with this program; if not, write to the Free Software
2266 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2270 +#include "sysacls.h" /****** ADDED ******/
2272 +#ifdef SUPPORT_ACLS
2274 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2280 +void SAFE_FREE(void *mem)
2286 +char *uidtoname(uid_t uid)
2288 + static char idbuf[12];
2289 + struct passwd *pw;
2291 + if ((pw = getpwuid(uid)) == NULL) {
2292 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2295 + return pw->pw_name;
2297 +/****** EXTRAS -- END ******/
2300 + This file wraps all differing system ACL interfaces into a consistent
2301 + one based on the POSIX interface. It also returns the correct errors
2302 + for older UNIX systems that don't support ACLs.
2304 + The interfaces that each ACL implementation must support are as follows :
2306 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2307 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2308 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2309 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2310 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2311 + SMB_ACL_T sys_acl_get_fd(int fd)
2312 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2313 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2314 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2315 + SMB_ACL_T sys_acl_init( int count)
2316 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2317 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2318 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2319 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2320 + int sys_acl_valid( SMB_ACL_T theacl )
2321 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2322 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2323 + int sys_acl_delete_def_file(const char *path)
2325 + This next one is not POSIX complient - but we *have* to have it !
2326 + More POSIX braindamage.
2328 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2330 + The generic POSIX free is the following call. We split this into
2331 + several different free functions as we may need to add tag info
2332 + to structures when emulating the POSIX interface.
2334 + int sys_acl_free( void *obj_p)
2336 + The calls we actually use are :
2338 + int sys_acl_free_text(char *text) - free acl_to_text
2339 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2340 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2344 +#if defined(HAVE_POSIX_ACLS)
2346 +/* Identity mapping - easy. */
2348 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2350 + return acl_get_entry( the_acl, entry_id, entry_p);
2353 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2355 + return acl_get_tag_type( entry_d, tag_type_p);
2358 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2360 + return acl_get_permset( entry_d, permset_p);
2363 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2365 + return acl_get_qualifier( entry_d);
2368 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2370 + return acl_get_file( path_p, type);
2373 +SMB_ACL_T sys_acl_get_fd(int fd)
2375 + return acl_get_fd(fd);
2378 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2380 + return acl_clear_perms(permset);
2383 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2385 + return acl_add_perm(permset, perm);
2388 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2390 +#if defined(HAVE_ACL_GET_PERM_NP)
2392 + * Required for TrustedBSD-based ACL implementations where
2393 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2396 + return acl_get_perm_np(permset, perm);
2398 + return acl_get_perm(permset, perm);
2402 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2404 + return acl_to_text( the_acl, plen);
2407 +SMB_ACL_T sys_acl_init( int count)
2409 + return acl_init(count);
2412 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2414 + return acl_create_entry(pacl, pentry);
2417 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2419 + return acl_set_tag_type(entry, tagtype);
2422 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2424 + return acl_set_qualifier(entry, qual);
2427 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2429 + return acl_set_permset(entry, permset);
2432 +int sys_acl_valid( SMB_ACL_T theacl )
2434 + return acl_valid(theacl);
2437 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2439 + return acl_set_file(name, acltype, theacl);
2442 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2444 + return acl_set_fd(fd, theacl);
2447 +int sys_acl_delete_def_file(const char *name)
2449 + return acl_delete_def_file(name);
2452 +int sys_acl_free_text(char *text)
2454 + return acl_free(text);
2457 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2459 + return acl_free(the_acl);
2462 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2464 + return acl_free(qual);
2467 +#elif defined(HAVE_TRU64_ACLS)
2469 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2470 + * is based on Draft 13 of the POSIX spec which is
2471 + * slightly different from the Draft 16 interface.
2473 + * Also, some of the permset manipulation functions
2474 + * such as acl_clear_perm() and acl_add_perm() appear
2475 + * to be broken on Tru64 so we have to manipulate
2476 + * the permission bits in the permset directly.
2478 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2480 + SMB_ACL_ENTRY_T entry;
2482 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2487 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2492 + return errno ? -1 : 0;
2495 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2497 + return acl_get_tag_type( entry_d, tag_type_p);
2500 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2502 + return acl_get_permset( entry_d, permset_p);
2505 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2507 + return acl_get_qualifier( entry_d);
2510 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2512 + return acl_get_file((char *)path_p, type);
2515 +SMB_ACL_T sys_acl_get_fd(int fd)
2517 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2520 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2522 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2527 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2529 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2534 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2539 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2541 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2544 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2546 + return acl_to_text( the_acl, plen);
2549 +SMB_ACL_T sys_acl_init( int count)
2551 + return acl_init(count);
2554 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2556 + SMB_ACL_ENTRY_T entry;
2558 + if ((entry = acl_create_entry(pacl)) == NULL) {
2566 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2568 + return acl_set_tag_type(entry, tagtype);
2571 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2573 + return acl_set_qualifier(entry, qual);
2576 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2578 + return acl_set_permset(entry, permset);
2581 +int sys_acl_valid( SMB_ACL_T theacl )
2583 + acl_entry_t entry;
2585 + return acl_valid(theacl, &entry);
2588 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2590 + return acl_set_file((char *)name, acltype, theacl);
2593 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2595 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2598 +int sys_acl_delete_def_file(const char *name)
2600 + return acl_delete_def_file((char *)name);
2603 +int sys_acl_free_text(char *text)
2606 + * (void) cast and explicit return 0 are for DEC UNIX
2607 + * which just #defines acl_free_text() to be free()
2609 + (void) acl_free_text(text);
2613 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2615 + return acl_free(the_acl);
2618 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2620 + return acl_free_qualifier(qual, tagtype);
2623 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2626 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2627 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2631 + * Note that while this code implements sufficient functionality
2632 + * to support the sys_acl_* interfaces it does not provide all
2633 + * of the semantics of the POSIX ACL interfaces.
2635 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2636 + * from a call to sys_acl_get_entry() should not be assumed to be
2637 + * valid after calling any of the following functions, which may
2638 + * reorder the entries in the ACL.
2641 + * sys_acl_set_file()
2642 + * sys_acl_set_fd()
2646 + * The only difference between Solaris and UnixWare / OpenUNIX is
2647 + * that the #defines for the ACL operations have different names
2649 +#if defined(HAVE_UNIXWARE_ACLS)
2651 +#define SETACL ACL_SET
2652 +#define GETACL ACL_GET
2653 +#define GETACLCNT ACL_CNT
2658 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2660 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2665 + if (entry_p == NULL) {
2670 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2674 + if (acl_d->next < 0) {
2679 + if (acl_d->next >= acl_d->count) {
2683 + *entry_p = &acl_d->acl[acl_d->next++];
2688 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2690 + *type_p = entry_d->a_type;
2695 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2697 + *permset_p = &entry_d->a_perm;
2702 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2704 + if (entry_d->a_type != SMB_ACL_USER
2705 + && entry_d->a_type != SMB_ACL_GROUP) {
2710 + return &entry_d->a_id;
2714 + * There is no way of knowing what size the ACL returned by
2715 + * GETACL will be unless you first call GETACLCNT which means
2716 + * making an additional system call.
2718 + * In the hope of avoiding the cost of the additional system
2719 + * call in most cases, we initially allocate enough space for
2720 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2721 + * be too small then we use GETACLCNT to find out the actual
2722 + * size, reallocate the ACL buffer, and then call GETACL again.
2725 +#define INITIAL_ACL_SIZE 16
2727 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2730 + int count; /* # of ACL entries allocated */
2731 + int naccess; /* # of access ACL entries */
2732 + int ndefault; /* # of default ACL entries */
2734 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2739 + count = INITIAL_ACL_SIZE;
2740 + if ((acl_d = sys_acl_init(count)) == NULL) {
2745 + * If there isn't enough space for the ACL entries we use
2746 + * GETACLCNT to determine the actual number of ACL entries
2747 + * reallocate and try again. This is in a loop because it
2748 + * is possible that someone else could modify the ACL and
2749 + * increase the number of entries between the call to
2750 + * GETACLCNT and the call to GETACL.
2752 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2753 + && errno == ENOSPC) {
2755 + sys_acl_free_acl(acl_d);
2757 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2761 + if ((acl_d = sys_acl_init(count)) == NULL) {
2767 + sys_acl_free_acl(acl_d);
2772 + * calculate the number of access and default ACL entries
2774 + * Note: we assume that the acl() system call returned a
2775 + * well formed ACL which is sorted so that all of the
2776 + * access ACL entries preceed any default ACL entries
2778 + for (naccess = 0; naccess < count; naccess++) {
2779 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2782 + ndefault = count - naccess;
2785 + * if the caller wants the default ACL we have to copy
2786 + * the entries down to the start of the acl[] buffer
2787 + * and mask out the ACL_DEFAULT flag from the type field
2789 + if (type == SMB_ACL_TYPE_DEFAULT) {
2792 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2793 + acl_d->acl[i] = acl_d->acl[j];
2794 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2797 + acl_d->count = ndefault;
2799 + acl_d->count = naccess;
2805 +SMB_ACL_T sys_acl_get_fd(int fd)
2808 + int count; /* # of ACL entries allocated */
2809 + int naccess; /* # of access ACL entries */
2811 + count = INITIAL_ACL_SIZE;
2812 + if ((acl_d = sys_acl_init(count)) == NULL) {
2816 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2817 + && errno == ENOSPC) {
2819 + sys_acl_free_acl(acl_d);
2821 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2825 + if ((acl_d = sys_acl_init(count)) == NULL) {
2831 + sys_acl_free_acl(acl_d);
2836 + * calculate the number of access ACL entries
2838 + for (naccess = 0; naccess < count; naccess++) {
2839 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2843 + acl_d->count = naccess;
2848 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2855 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2857 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2858 + && perm != SMB_ACL_EXECUTE) {
2863 + if (permset_d == NULL) {
2868 + *permset_d |= perm;
2873 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2875 + return *permset_d & perm;
2878 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2885 + * use an initial estimate of 20 bytes per ACL entry
2886 + * when allocating memory for the text representation
2890 + maxlen = 20 * acl_d->count;
2891 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2896 + for (i = 0; i < acl_d->count; i++) {
2897 + struct acl *ap = &acl_d->acl[i];
2906 + switch (ap->a_type) {
2908 + * for debugging purposes it's probably more
2909 + * useful to dump unknown tag types rather
2910 + * than just returning an error
2913 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2916 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2921 + case SMB_ACL_USER:
2922 + id = uidtoname(ap->a_id);
2923 + case SMB_ACL_USER_OBJ:
2927 + case SMB_ACL_GROUP:
2928 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2929 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2935 + case SMB_ACL_GROUP_OBJ:
2939 + case SMB_ACL_OTHER:
2943 + case SMB_ACL_MASK:
2949 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2950 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2951 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2954 + /* <tag> : <qualifier> : rwx \n \0 */
2955 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2958 + * If this entry would overflow the buffer
2959 + * allocate enough additional memory for this
2960 + * entry and an estimate of another 20 bytes
2961 + * for each entry still to be processed
2963 + if ((len + nbytes) > maxlen) {
2964 + char *oldtext = text;
2966 + maxlen += nbytes + 20 * (acl_d->count - i);
2968 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2969 + SAFE_FREE(oldtext);
2975 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2976 + len += nbytes - 1;
2985 +SMB_ACL_T sys_acl_init(int count)
2995 + * note that since the definition of the structure pointed
2996 + * to by the SMB_ACL_T includes the first element of the
2997 + * acl[] array, this actually allocates an ACL with room
2998 + * for (count+1) entries
3000 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3005 + a->size = count + 1;
3013 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3016 + SMB_ACL_ENTRY_T entry_d;
3018 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3023 + if (acl_d->count >= acl_d->size) {
3028 + entry_d = &acl_d->acl[acl_d->count++];
3029 + entry_d->a_type = 0;
3030 + entry_d->a_id = -1;
3031 + entry_d->a_perm = 0;
3032 + *entry_p = entry_d;
3037 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3039 + switch (tag_type) {
3040 + case SMB_ACL_USER:
3041 + case SMB_ACL_USER_OBJ:
3042 + case SMB_ACL_GROUP:
3043 + case SMB_ACL_GROUP_OBJ:
3044 + case SMB_ACL_OTHER:
3045 + case SMB_ACL_MASK:
3046 + entry_d->a_type = tag_type;
3056 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3058 + if (entry_d->a_type != SMB_ACL_GROUP
3059 + && entry_d->a_type != SMB_ACL_USER) {
3064 + entry_d->a_id = *((id_t *)qual_p);
3069 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3071 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3075 + entry_d->a_perm = *permset_d;
3081 + * sort the ACL and check it for validity
3083 + * if it's a minimal ACL with only 4 entries then we
3084 + * need to recalculate the mask permissions to make
3085 + * sure that they are the same as the GROUP_OBJ
3086 + * permissions as required by the UnixWare acl() system call.
3088 + * (note: since POSIX allows minimal ACLs which only contain
3089 + * 3 entries - ie there is no mask entry - we should, in theory,
3090 + * check for this and add a mask entry if necessary - however
3091 + * we "know" that the caller of this interface always specifies
3092 + * a mask so, in practice "this never happens" (tm) - if it *does*
3093 + * happen aclsort() will fail and return an error and someone will
3094 + * have to fix it ...)
3097 +static int acl_sort(SMB_ACL_T acl_d)
3099 + int fixmask = (acl_d->count <= 4);
3101 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3108 +int sys_acl_valid(SMB_ACL_T acl_d)
3110 + return acl_sort(acl_d);
3113 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3116 + struct acl *acl_p;
3118 + struct acl *acl_buf = NULL;
3121 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3126 + if (acl_sort(acl_d) != 0) {
3130 + acl_p = &acl_d->acl[0];
3131 + acl_count = acl_d->count;
3134 + * if it's a directory there is extra work to do
3135 + * since the acl() system call will replace both
3136 + * the access ACLs and the default ACLs (if any)
3138 + if (stat(name, &s) != 0) {
3141 + if (S_ISDIR(s.st_mode)) {
3142 + SMB_ACL_T acc_acl;
3143 + SMB_ACL_T def_acl;
3144 + SMB_ACL_T tmp_acl;
3147 + if (type == SMB_ACL_TYPE_ACCESS) {
3149 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3153 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3156 + if (tmp_acl == NULL) {
3161 + * allocate a temporary buffer for the complete ACL
3163 + acl_count = acc_acl->count + def_acl->count;
3164 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3166 + if (acl_buf == NULL) {
3167 + sys_acl_free_acl(tmp_acl);
3173 + * copy the access control and default entries into the buffer
3175 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3176 + acc_acl->count * sizeof(acl_buf[0]));
3178 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3179 + def_acl->count * sizeof(acl_buf[0]));
3182 + * set the ACL_DEFAULT flag on the default entries
3184 + for (i = acc_acl->count; i < acl_count; i++) {
3185 + acl_buf[i].a_type |= ACL_DEFAULT;
3188 + sys_acl_free_acl(tmp_acl);
3190 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3195 + ret = acl(name, SETACL, acl_count, acl_p);
3197 + SAFE_FREE(acl_buf);
3202 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3204 + if (acl_sort(acl_d) != 0) {
3208 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3211 +int sys_acl_delete_def_file(const char *path)
3217 + * fetching the access ACL and rewriting it has
3218 + * the effect of deleting the default ACL
3220 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3224 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3226 + sys_acl_free_acl(acl_d);
3231 +int sys_acl_free_text(char *text)
3237 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3243 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3248 +#elif defined(HAVE_HPUX_ACLS)
3252 + * Based on the Solaris/SCO code - with modifications.
3256 + * Note that while this code implements sufficient functionality
3257 + * to support the sys_acl_* interfaces it does not provide all
3258 + * of the semantics of the POSIX ACL interfaces.
3260 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3261 + * from a call to sys_acl_get_entry() should not be assumed to be
3262 + * valid after calling any of the following functions, which may
3263 + * reorder the entries in the ACL.
3266 + * sys_acl_set_file()
3267 + * sys_acl_set_fd()
3270 +/* This checks if the POSIX ACL system call is defined */
3271 +/* which basically corresponds to whether JFS 3.3 or */
3272 +/* higher is installed. If acl() was called when it */
3273 +/* isn't defined, it causes the process to core dump */
3274 +/* so it is important to check this and avoid acl() */
3275 +/* calls if it isn't there. */
3277 +static BOOL hpux_acl_call_presence(void)
3280 + shl_t handle = NULL;
3283 + static BOOL already_checked=0;
3285 + if(already_checked)
3289 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3291 + if(ret_val != 0) {
3292 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3293 + ret_val, errno, strerror(errno)));
3294 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3298 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3300 + already_checked = True;
3304 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3306 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3311 + if (entry_p == NULL) {
3316 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3320 + if (acl_d->next < 0) {
3325 + if (acl_d->next >= acl_d->count) {
3329 + *entry_p = &acl_d->acl[acl_d->next++];
3334 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3336 + *type_p = entry_d->a_type;
3341 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3343 + *permset_p = &entry_d->a_perm;
3348 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3350 + if (entry_d->a_type != SMB_ACL_USER
3351 + && entry_d->a_type != SMB_ACL_GROUP) {
3356 + return &entry_d->a_id;
3360 + * There is no way of knowing what size the ACL returned by
3361 + * ACL_GET will be unless you first call ACL_CNT which means
3362 + * making an additional system call.
3364 + * In the hope of avoiding the cost of the additional system
3365 + * call in most cases, we initially allocate enough space for
3366 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3367 + * be too small then we use ACL_CNT to find out the actual
3368 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3371 +#define INITIAL_ACL_SIZE 16
3373 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3376 + int count; /* # of ACL entries allocated */
3377 + int naccess; /* # of access ACL entries */
3378 + int ndefault; /* # of default ACL entries */
3380 + if(hpux_acl_call_presence() == False) {
3381 + /* Looks like we don't have the acl() system call on HPUX.
3382 + * May be the system doesn't have the latest version of JFS.
3387 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3392 + count = INITIAL_ACL_SIZE;
3393 + if ((acl_d = sys_acl_init(count)) == NULL) {
3398 + * If there isn't enough space for the ACL entries we use
3399 + * ACL_CNT to determine the actual number of ACL entries
3400 + * reallocate and try again. This is in a loop because it
3401 + * is possible that someone else could modify the ACL and
3402 + * increase the number of entries between the call to
3403 + * ACL_CNT and the call to ACL_GET.
3405 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3407 + sys_acl_free_acl(acl_d);
3409 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3413 + if ((acl_d = sys_acl_init(count)) == NULL) {
3419 + sys_acl_free_acl(acl_d);
3424 + * calculate the number of access and default ACL entries
3426 + * Note: we assume that the acl() system call returned a
3427 + * well formed ACL which is sorted so that all of the
3428 + * access ACL entries preceed any default ACL entries
3430 + for (naccess = 0; naccess < count; naccess++) {
3431 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3434 + ndefault = count - naccess;
3437 + * if the caller wants the default ACL we have to copy
3438 + * the entries down to the start of the acl[] buffer
3439 + * and mask out the ACL_DEFAULT flag from the type field
3441 + if (type == SMB_ACL_TYPE_DEFAULT) {
3444 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3445 + acl_d->acl[i] = acl_d->acl[j];
3446 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3449 + acl_d->count = ndefault;
3451 + acl_d->count = naccess;
3457 +SMB_ACL_T sys_acl_get_fd(int fd)
3460 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3463 + files_struct *fsp = file_find_fd(fd);
3465 + if (fsp == NULL) {
3471 + * We know we're in the same conn context. So we
3472 + * can use the relative path.
3475 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3478 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3485 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3487 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3488 + && perm != SMB_ACL_EXECUTE) {
3493 + if (permset_d == NULL) {
3498 + *permset_d |= perm;
3503 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3505 + return *permset_d & perm;
3508 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3515 + * use an initial estimate of 20 bytes per ACL entry
3516 + * when allocating memory for the text representation
3520 + maxlen = 20 * acl_d->count;
3521 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3526 + for (i = 0; i < acl_d->count; i++) {
3527 + struct acl *ap = &acl_d->acl[i];
3536 + switch (ap->a_type) {
3538 + * for debugging purposes it's probably more
3539 + * useful to dump unknown tag types rather
3540 + * than just returning an error
3543 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3546 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3551 + case SMB_ACL_USER:
3552 + id = uidtoname(ap->a_id);
3553 + case SMB_ACL_USER_OBJ:
3557 + case SMB_ACL_GROUP:
3558 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3559 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3565 + case SMB_ACL_GROUP_OBJ:
3569 + case SMB_ACL_OTHER:
3573 + case SMB_ACL_MASK:
3579 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3580 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3581 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3584 + /* <tag> : <qualifier> : rwx \n \0 */
3585 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3588 + * If this entry would overflow the buffer
3589 + * allocate enough additional memory for this
3590 + * entry and an estimate of another 20 bytes
3591 + * for each entry still to be processed
3593 + if ((len + nbytes) > maxlen) {
3594 + char *oldtext = text;
3596 + maxlen += nbytes + 20 * (acl_d->count - i);
3598 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3605 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3606 + len += nbytes - 1;
3615 +SMB_ACL_T sys_acl_init(int count)
3625 + * note that since the definition of the structure pointed
3626 + * to by the SMB_ACL_T includes the first element of the
3627 + * acl[] array, this actually allocates an ACL with room
3628 + * for (count+1) entries
3630 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3635 + a->size = count + 1;
3643 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3646 + SMB_ACL_ENTRY_T entry_d;
3648 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3653 + if (acl_d->count >= acl_d->size) {
3658 + entry_d = &acl_d->acl[acl_d->count++];
3659 + entry_d->a_type = 0;
3660 + entry_d->a_id = -1;
3661 + entry_d->a_perm = 0;
3662 + *entry_p = entry_d;
3667 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3669 + switch (tag_type) {
3670 + case SMB_ACL_USER:
3671 + case SMB_ACL_USER_OBJ:
3672 + case SMB_ACL_GROUP:
3673 + case SMB_ACL_GROUP_OBJ:
3674 + case SMB_ACL_OTHER:
3675 + case SMB_ACL_MASK:
3676 + entry_d->a_type = tag_type;
3686 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3688 + if (entry_d->a_type != SMB_ACL_GROUP
3689 + && entry_d->a_type != SMB_ACL_USER) {
3694 + entry_d->a_id = *((id_t *)qual_p);
3699 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3701 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3705 + entry_d->a_perm = *permset_d;
3710 +/* Structure to capture the count for each type of ACE. */
3712 +struct hpux_acl_types {
3716 + int n_def_user_obj;
3721 + int n_def_group_obj;
3725 + int n_def_other_obj;
3728 + int n_def_class_obj;
3730 + int n_illegal_obj;
3734 + * Counts the different number of objects in a given array of ACL
3738 + * acl_count - Count of ACLs in the array of ACL strucutres.
3739 + * aclp - Array of ACL structures.
3740 + * acl_type_count - Pointer to acl_types structure. Should already be
3744 + * acl_type_count - This structure is filled up with counts of various
3748 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3752 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3754 + for(i=0;i<acl_count;i++) {
3755 + switch(aclp[i].a_type) {
3757 + acl_type_count->n_user++;
3760 + acl_type_count->n_user_obj++;
3762 + case DEF_USER_OBJ:
3763 + acl_type_count->n_def_user_obj++;
3766 + acl_type_count->n_group++;
3769 + acl_type_count->n_group_obj++;
3771 + case DEF_GROUP_OBJ:
3772 + acl_type_count->n_def_group_obj++;
3775 + acl_type_count->n_other_obj++;
3777 + case DEF_OTHER_OBJ:
3778 + acl_type_count->n_def_other_obj++;
3781 + acl_type_count->n_class_obj++;
3783 + case DEF_CLASS_OBJ:
3784 + acl_type_count->n_def_class_obj++;
3787 + acl_type_count->n_def_user++;
3790 + acl_type_count->n_def_group++;
3793 + acl_type_count->n_illegal_obj++;
3799 +/* swap_acl_entries: Swaps two ACL entries.
3801 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3804 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3806 + struct acl temp_acl;
3808 + temp_acl.a_type = aclp0->a_type;
3809 + temp_acl.a_id = aclp0->a_id;
3810 + temp_acl.a_perm = aclp0->a_perm;
3812 + aclp0->a_type = aclp1->a_type;
3813 + aclp0->a_id = aclp1->a_id;
3814 + aclp0->a_perm = aclp1->a_perm;
3816 + aclp1->a_type = temp_acl.a_type;
3817 + aclp1->a_id = temp_acl.a_id;
3818 + aclp1->a_perm = temp_acl.a_perm;
3821 +/* prohibited_duplicate_type
3822 + * Identifies if given ACL type can have duplicate entries or
3825 + * Inputs: acl_type - ACL Type.
3831 + * True - If the ACL type matches any of the prohibited types.
3832 + * False - If the ACL type doesn't match any of the prohibited types.
3835 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3837 + switch(acl_type) {
3848 +/* get_needed_class_perm
3849 + * Returns the permissions of a ACL structure only if the ACL
3850 + * type matches one of the pre-determined types for computing
3851 + * CLASS_OBJ permissions.
3853 + * Inputs: aclp - Pointer to ACL structure.
3856 +static int hpux_get_needed_class_perm(struct acl *aclp)
3858 + switch(aclp->a_type) {
3862 + case DEF_USER_OBJ:
3864 + case DEF_GROUP_OBJ:
3866 + case DEF_CLASS_OBJ:
3867 + case DEF_OTHER_OBJ:
3868 + return aclp->a_perm;
3874 +/* acl_sort for HPUX.
3875 + * Sorts the array of ACL structures as per the description in
3876 + * aclsort man page. Refer to aclsort man page for more details
3880 + * acl_count - Count of ACLs in the array of ACL structures.
3881 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3883 + * aclp - Array of ACL structures.
3887 + * aclp - Sorted array of ACL structures.
3891 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3892 + * debug log in case of failure.
3895 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3897 +#if !defined(HAVE_HPUX_ACLSORT)
3899 + * The aclsort() system call is availabe on the latest HPUX General
3900 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3901 + * function. Because, we don't want to update to a new
3902 + * HPUX GR bundle just for aclsort() call.
3905 + struct hpux_acl_types acl_obj_count;
3906 + int n_class_obj_perm = 0;
3910 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3914 + if(aclp == NULL) {
3915 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3919 + /* Count different types of ACLs in the ACLs array */
3921 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3923 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3924 + * CLASS_OBJ and OTHER_OBJ
3927 + if( (acl_obj_count.n_user_obj != 1) ||
3928 + (acl_obj_count.n_group_obj != 1) ||
3929 + (acl_obj_count.n_class_obj != 1) ||
3930 + (acl_obj_count.n_other_obj != 1)
3932 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3933 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3937 + /* If any of the default objects are present, there should be only
3938 + * one of them each.
3941 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3942 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3943 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3944 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3948 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3951 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3952 + * same ACL type, sort by ACL id.
3954 + * I am using the trival kind of sorting method here because, performance isn't
3955 + * really effected by the ACLs feature. More over there aren't going to be more
3956 + * than 17 entries on HPUX.
3959 + for(i=0; i<acl_count;i++) {
3960 + for (j=i+1; j<acl_count; j++) {
3961 + if( aclp[i].a_type > aclp[j].a_type ) {
3962 + /* ACL entries out of order, swap them */
3964 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3966 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3968 + /* ACL entries of same type, sort by id */
3970 + if(aclp[i].a_id > aclp[j].a_id) {
3971 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3972 + } else if (aclp[i].a_id == aclp[j].a_id) {
3973 + /* We have a duplicate entry. */
3974 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3975 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3976 + aclp[i].a_type, aclp[i].a_id));
3985 + /* set the class obj permissions to the computed one. */
3987 + int n_class_obj_index = -1;
3989 + for(i=0;i<acl_count;i++) {
3990 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3992 + if(aclp[i].a_type == CLASS_OBJ)
3993 + n_class_obj_index = i;
3995 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
4000 + return aclsort(acl_count, calclass, aclp);
4005 + * sort the ACL and check it for validity
4007 + * if it's a minimal ACL with only 4 entries then we
4008 + * need to recalculate the mask permissions to make
4009 + * sure that they are the same as the GROUP_OBJ
4010 + * permissions as required by the UnixWare acl() system call.
4012 + * (note: since POSIX allows minimal ACLs which only contain
4013 + * 3 entries - ie there is no mask entry - we should, in theory,
4014 + * check for this and add a mask entry if necessary - however
4015 + * we "know" that the caller of this interface always specifies
4016 + * a mask so, in practice "this never happens" (tm) - if it *does*
4017 + * happen aclsort() will fail and return an error and someone will
4018 + * have to fix it ...)
4021 +static int acl_sort(SMB_ACL_T acl_d)
4023 + int fixmask = (acl_d->count <= 4);
4025 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4032 +int sys_acl_valid(SMB_ACL_T acl_d)
4034 + return acl_sort(acl_d);
4037 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4040 + struct acl *acl_p;
4042 + struct acl *acl_buf = NULL;
4045 + if(hpux_acl_call_presence() == False) {
4046 + /* Looks like we don't have the acl() system call on HPUX.
4047 + * May be the system doesn't have the latest version of JFS.
4053 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4058 + if (acl_sort(acl_d) != 0) {
4062 + acl_p = &acl_d->acl[0];
4063 + acl_count = acl_d->count;
4066 + * if it's a directory there is extra work to do
4067 + * since the acl() system call will replace both
4068 + * the access ACLs and the default ACLs (if any)
4070 + if (stat(name, &s) != 0) {
4073 + if (S_ISDIR(s.st_mode)) {
4074 + SMB_ACL_T acc_acl;
4075 + SMB_ACL_T def_acl;
4076 + SMB_ACL_T tmp_acl;
4079 + if (type == SMB_ACL_TYPE_ACCESS) {
4081 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4085 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4088 + if (tmp_acl == NULL) {
4093 + * allocate a temporary buffer for the complete ACL
4095 + acl_count = acc_acl->count + def_acl->count;
4096 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4098 + if (acl_buf == NULL) {
4099 + sys_acl_free_acl(tmp_acl);
4105 + * copy the access control and default entries into the buffer
4107 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4108 + acc_acl->count * sizeof(acl_buf[0]));
4110 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4111 + def_acl->count * sizeof(acl_buf[0]));
4114 + * set the ACL_DEFAULT flag on the default entries
4116 + for (i = acc_acl->count; i < acl_count; i++) {
4117 + acl_buf[i].a_type |= ACL_DEFAULT;
4120 + sys_acl_free_acl(tmp_acl);
4122 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4127 + ret = acl(name, ACL_SET, acl_count, acl_p);
4136 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4139 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4142 + files_struct *fsp = file_find_fd(fd);
4144 + if (fsp == NULL) {
4149 + if (acl_sort(acl_d) != 0) {
4154 + * We know we're in the same conn context. So we
4155 + * can use the relative path.
4158 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4161 +int sys_acl_delete_def_file(const char *path)
4167 + * fetching the access ACL and rewriting it has
4168 + * the effect of deleting the default ACL
4170 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4174 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4176 + sys_acl_free_acl(acl_d);
4181 +int sys_acl_free_text(char *text)
4187 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4193 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4198 +#elif defined(HAVE_IRIX_ACLS)
4200 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4202 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4207 + if (entry_p == NULL) {
4212 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4216 + if (acl_d->next < 0) {
4221 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4225 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4230 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4232 + *type_p = entry_d->ae_tag;
4237 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4239 + *permset_p = entry_d;
4244 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4246 + if (entry_d->ae_tag != SMB_ACL_USER
4247 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4252 + return &entry_d->ae_id;
4255 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4259 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4263 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4268 + a->freeaclp = True;
4272 +SMB_ACL_T sys_acl_get_fd(int fd)
4276 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4280 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4285 + a->freeaclp = True;
4289 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4291 + permset_d->ae_perm = 0;
4296 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4298 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4299 + && perm != SMB_ACL_EXECUTE) {
4304 + if (permset_d == NULL) {
4309 + permset_d->ae_perm |= perm;
4314 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4316 + return permset_d->ae_perm & perm;
4319 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4321 + return acl_to_text(acl_d->aclp, len_p);
4324 +SMB_ACL_T sys_acl_init(int count)
4333 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4339 + a->freeaclp = False;
4340 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4341 + a->aclp->acl_cnt = 0;
4347 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4350 + SMB_ACL_ENTRY_T entry_d;
4352 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4357 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4362 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4363 + entry_d->ae_tag = 0;
4364 + entry_d->ae_id = 0;
4365 + entry_d->ae_perm = 0;
4366 + *entry_p = entry_d;
4371 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4373 + switch (tag_type) {
4374 + case SMB_ACL_USER:
4375 + case SMB_ACL_USER_OBJ:
4376 + case SMB_ACL_GROUP:
4377 + case SMB_ACL_GROUP_OBJ:
4378 + case SMB_ACL_OTHER:
4379 + case SMB_ACL_MASK:
4380 + entry_d->ae_tag = tag_type;
4390 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4392 + if (entry_d->ae_tag != SMB_ACL_GROUP
4393 + && entry_d->ae_tag != SMB_ACL_USER) {
4398 + entry_d->ae_id = *((id_t *)qual_p);
4403 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4405 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4409 + entry_d->ae_perm = permset_d->ae_perm;
4414 +int sys_acl_valid(SMB_ACL_T acl_d)
4416 + return acl_valid(acl_d->aclp);
4419 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4421 + return acl_set_file(name, type, acl_d->aclp);
4424 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4426 + return acl_set_fd(fd, acl_d->aclp);
4429 +int sys_acl_delete_def_file(const char *name)
4431 + return acl_delete_def_file(name);
4434 +int sys_acl_free_text(char *text)
4436 + return acl_free(text);
4439 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4441 + if (acl_d->freeaclp) {
4442 + acl_free(acl_d->aclp);
4448 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4453 +#elif defined(HAVE_AIX_ACLS)
4455 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4457 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4459 + struct acl_entry_link *link;
4460 + struct new_acl_entry *entry;
4463 + DEBUG(10,("This is the count: %d\n",theacl->count));
4465 + /* Check if count was previously set to -1. *
4466 + * If it was, that means we reached the end *
4467 + * of the acl last time. */
4468 + if(theacl->count == -1)
4472 + /* To get to the next acl, traverse linked list until index *
4473 + * of acl matches the count we are keeping. This count is *
4474 + * incremented each time we return an acl entry. */
4476 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4477 + link = link->nextp;
4479 + entry = *entry_p = link->entryp;
4481 + DEBUG(10,("*entry_p is %d\n",entry_p));
4482 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4484 + /* Increment count */
4486 + if(link->nextp == NULL)
4487 + theacl->count = -1;
4492 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4494 + /* Initialize tag type */
4497 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4499 + /* Depending on what type of entry we have, *
4500 + * return tag type. */
4501 + switch(entry_d->ace_id->id_type) {
4503 + *tag_type_p = SMB_ACL_USER;
4506 + *tag_type_p = SMB_ACL_GROUP;
4509 + case SMB_ACL_USER_OBJ:
4510 + case SMB_ACL_GROUP_OBJ:
4511 + case SMB_ACL_OTHER:
4512 + *tag_type_p = entry_d->ace_id->id_type;
4522 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4524 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4525 + *permset_p = &entry_d->ace_access;
4526 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4527 + if(!(**permset_p & S_IXUSR) &&
4528 + !(**permset_p & S_IWUSR) &&
4529 + !(**permset_p & S_IRUSR) &&
4530 + (**permset_p != 0))
4533 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4537 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4539 + return(entry_d->ace_id->id_data);
4542 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4544 + struct acl *file_acl = (struct acl *)NULL;
4545 + struct acl_entry *acl_entry;
4546 + struct new_acl_entry *new_acl_entry;
4547 + struct ace_id *idp;
4548 + struct acl_entry_link *acl_entry_link;
4549 + struct acl_entry_link *acl_entry_link_head;
4554 + /* AIX has no DEFAULT */
4555 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4560 + /* Get the acl using statacl */
4562 + DEBUG(10,("Entering sys_acl_get_file\n"));
4563 + DEBUG(10,("path_p is %s\n",path_p));
4565 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4567 + if(file_acl == NULL) {
4569 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4573 + memset(file_acl,0,BUFSIZ);
4575 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4577 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4578 + SAFE_FREE(file_acl);
4582 + DEBUG(10,("Got facl and returned it\n"));
4584 + /* Point to the first acl entry in the acl */
4585 + acl_entry = file_acl->acl_ext;
4587 + /* Begin setting up the head of the linked list *
4588 + * that will be used for the storing the acl *
4589 + * in a way that is useful for the posix_acls.c *
4592 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4593 + if(acl_entry_link_head == NULL)
4596 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4597 + if(acl_entry_link->entryp == NULL) {
4598 + SAFE_FREE(file_acl);
4600 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4604 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4605 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4607 + /* Check if the extended acl bit is on. *
4608 + * If it isn't, do not show the *
4609 + * contents of the acl since AIX intends *
4610 + * the extended info to remain unused */
4612 + if(file_acl->acl_mode & S_IXACL){
4613 + /* while we are not pointing to the very end */
4614 + while(acl_entry < acl_last(file_acl)) {
4615 + /* before we malloc anything, make sure this is */
4616 + /* a valid acl entry and one that we want to map */
4617 + idp = id_nxt(acl_entry->ace_id);
4618 + if((acl_entry->ace_type == ACC_SPECIFY ||
4619 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4620 + acl_entry = acl_nxt(acl_entry);
4624 + idp = acl_entry->ace_id;
4626 + /* Check if this is the first entry in the linked list. *
4627 + * The first entry needs to keep prevp pointing to NULL *
4628 + * and already has entryp allocated. */
4630 + if(acl_entry_link_head->count != 0) {
4631 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4633 + if(acl_entry_link->nextp == NULL) {
4634 + SAFE_FREE(file_acl);
4636 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4640 + acl_entry_link->nextp->prevp = acl_entry_link;
4641 + acl_entry_link = acl_entry_link->nextp;
4642 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4643 + if(acl_entry_link->entryp == NULL) {
4644 + SAFE_FREE(file_acl);
4646 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4649 + acl_entry_link->nextp = NULL;
4652 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4654 + /* Don't really need this since all types are going *
4655 + * to be specified but, it's better than leaving it 0 */
4657 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4659 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4661 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4663 + /* The access in the acl entries must be left shifted by *
4664 + * three bites, because they will ultimately be compared *
4665 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4667 + switch(acl_entry->ace_type){
4670 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4671 + acl_entry_link->entryp->ace_access <<= 6;
4672 + acl_entry_link_head->count++;
4675 + /* Since there is no way to return a DENY acl entry *
4676 + * change to PERMIT and then shift. */
4677 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4678 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4679 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4680 + acl_entry_link->entryp->ace_access <<= 6;
4681 + acl_entry_link_head->count++;
4687 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4688 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4690 + acl_entry = acl_nxt(acl_entry);
4692 + } /* end of if enabled */
4694 + /* Since owner, group, other acl entries are not *
4695 + * part of the acl entries in an acl, they must *
4696 + * be dummied up to become part of the list. */
4698 + for( i = 1; i < 4; i++) {
4699 + DEBUG(10,("i is %d\n",i));
4700 + if(acl_entry_link_head->count != 0) {
4701 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4702 + if(acl_entry_link->nextp == NULL) {
4703 + SAFE_FREE(file_acl);
4705 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4709 + acl_entry_link->nextp->prevp = acl_entry_link;
4710 + acl_entry_link = acl_entry_link->nextp;
4711 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4712 + if(acl_entry_link->entryp == NULL) {
4713 + SAFE_FREE(file_acl);
4715 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4720 + acl_entry_link->nextp = NULL;
4722 + new_acl_entry = acl_entry_link->entryp;
4723 + idp = new_acl_entry->ace_id;
4725 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4726 + new_acl_entry->ace_type = ACC_PERMIT;
4727 + idp->id_len = sizeof(struct ace_id);
4728 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4729 + memset(idp->id_data,0,sizeof(uid_t));
4733 + new_acl_entry->ace_access = file_acl->g_access << 6;
4734 + idp->id_type = SMB_ACL_GROUP_OBJ;
4738 + new_acl_entry->ace_access = file_acl->o_access << 6;
4739 + idp->id_type = SMB_ACL_OTHER;
4743 + new_acl_entry->ace_access = file_acl->u_access << 6;
4744 + idp->id_type = SMB_ACL_USER_OBJ;
4752 + acl_entry_link_head->count++;
4753 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4756 + acl_entry_link_head->count = 0;
4757 + SAFE_FREE(file_acl);
4759 + return(acl_entry_link_head);
4762 +SMB_ACL_T sys_acl_get_fd(int fd)
4764 + struct acl *file_acl = (struct acl *)NULL;
4765 + struct acl_entry *acl_entry;
4766 + struct new_acl_entry *new_acl_entry;
4767 + struct ace_id *idp;
4768 + struct acl_entry_link *acl_entry_link;
4769 + struct acl_entry_link *acl_entry_link_head;
4774 + /* Get the acl using fstatacl */
4776 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4777 + DEBUG(10,("fd is %d\n",fd));
4778 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4780 + if(file_acl == NULL) {
4782 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4786 + memset(file_acl,0,BUFSIZ);
4788 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4790 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4791 + SAFE_FREE(file_acl);
4795 + DEBUG(10,("Got facl and returned it\n"));
4797 + /* Point to the first acl entry in the acl */
4799 + acl_entry = file_acl->acl_ext;
4800 + /* Begin setting up the head of the linked list *
4801 + * that will be used for the storing the acl *
4802 + * in a way that is useful for the posix_acls.c *
4805 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4806 + if(acl_entry_link_head == NULL){
4807 + SAFE_FREE(file_acl);
4811 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4813 + if(acl_entry_link->entryp == NULL) {
4815 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4816 + SAFE_FREE(file_acl);
4820 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4821 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4823 + /* Check if the extended acl bit is on. *
4824 + * If it isn't, do not show the *
4825 + * contents of the acl since AIX intends *
4826 + * the extended info to remain unused */
4828 + if(file_acl->acl_mode & S_IXACL){
4829 + /* while we are not pointing to the very end */
4830 + while(acl_entry < acl_last(file_acl)) {
4831 + /* before we malloc anything, make sure this is */
4832 + /* a valid acl entry and one that we want to map */
4834 + idp = id_nxt(acl_entry->ace_id);
4835 + if((acl_entry->ace_type == ACC_SPECIFY ||
4836 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4837 + acl_entry = acl_nxt(acl_entry);
4841 + idp = acl_entry->ace_id;
4843 + /* Check if this is the first entry in the linked list. *
4844 + * The first entry needs to keep prevp pointing to NULL *
4845 + * and already has entryp allocated. */
4847 + if(acl_entry_link_head->count != 0) {
4848 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4849 + if(acl_entry_link->nextp == NULL) {
4851 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4852 + SAFE_FREE(file_acl);
4855 + acl_entry_link->nextp->prevp = acl_entry_link;
4856 + acl_entry_link = acl_entry_link->nextp;
4857 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4858 + if(acl_entry_link->entryp == NULL) {
4860 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4861 + SAFE_FREE(file_acl);
4865 + acl_entry_link->nextp = NULL;
4868 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4870 + /* Don't really need this since all types are going *
4871 + * to be specified but, it's better than leaving it 0 */
4873 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4874 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4876 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4878 + /* The access in the acl entries must be left shifted by *
4879 + * three bites, because they will ultimately be compared *
4880 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4882 + switch(acl_entry->ace_type){
4885 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4886 + acl_entry_link->entryp->ace_access <<= 6;
4887 + acl_entry_link_head->count++;
4890 + /* Since there is no way to return a DENY acl entry *
4891 + * change to PERMIT and then shift. */
4892 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4893 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4894 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4895 + acl_entry_link->entryp->ace_access <<= 6;
4896 + acl_entry_link_head->count++;
4902 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4903 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4905 + acl_entry = acl_nxt(acl_entry);
4907 + } /* end of if enabled */
4909 + /* Since owner, group, other acl entries are not *
4910 + * part of the acl entries in an acl, they must *
4911 + * be dummied up to become part of the list. */
4913 + for( i = 1; i < 4; i++) {
4914 + DEBUG(10,("i is %d\n",i));
4915 + if(acl_entry_link_head->count != 0){
4916 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4917 + if(acl_entry_link->nextp == NULL) {
4919 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4920 + SAFE_FREE(file_acl);
4924 + acl_entry_link->nextp->prevp = acl_entry_link;
4925 + acl_entry_link = acl_entry_link->nextp;
4926 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4928 + if(acl_entry_link->entryp == NULL) {
4929 + SAFE_FREE(file_acl);
4931 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4936 + acl_entry_link->nextp = NULL;
4938 + new_acl_entry = acl_entry_link->entryp;
4939 + idp = new_acl_entry->ace_id;
4941 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4942 + new_acl_entry->ace_type = ACC_PERMIT;
4943 + idp->id_len = sizeof(struct ace_id);
4944 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4945 + memset(idp->id_data,0,sizeof(uid_t));
4949 + new_acl_entry->ace_access = file_acl->g_access << 6;
4950 + idp->id_type = SMB_ACL_GROUP_OBJ;
4954 + new_acl_entry->ace_access = file_acl->o_access << 6;
4955 + idp->id_type = SMB_ACL_OTHER;
4959 + new_acl_entry->ace_access = file_acl->u_access << 6;
4960 + idp->id_type = SMB_ACL_USER_OBJ;
4967 + acl_entry_link_head->count++;
4968 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4971 + acl_entry_link_head->count = 0;
4972 + SAFE_FREE(file_acl);
4974 + return(acl_entry_link_head);
4977 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4979 + *permset = *permset & ~0777;
4983 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4986 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4990 + DEBUG(10,("This is the permset now: %d\n",*permset));
4994 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4999 +SMB_ACL_T sys_acl_init( int count)
5001 + struct acl_entry_link *theacl = NULL;
5003 + DEBUG(10,("Entering sys_acl_init\n"));
5005 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5006 + if(theacl == NULL) {
5008 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5012 + theacl->count = 0;
5013 + theacl->nextp = NULL;
5014 + theacl->prevp = NULL;
5015 + theacl->entryp = NULL;
5016 + DEBUG(10,("Exiting sys_acl_init\n"));
5020 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5022 + struct acl_entry_link *theacl;
5023 + struct acl_entry_link *acl_entryp;
5024 + struct acl_entry_link *temp_entry;
5027 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5029 + theacl = acl_entryp = *pacl;
5031 + /* Get to the end of the acl before adding entry */
5033 + for(counting=0; counting < theacl->count; counting++){
5034 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5035 + temp_entry = acl_entryp;
5036 + acl_entryp = acl_entryp->nextp;
5039 + if(theacl->count != 0){
5040 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5041 + if(acl_entryp == NULL) {
5043 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5047 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5048 + acl_entryp->prevp = temp_entry;
5049 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5052 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5053 + if(*pentry == NULL) {
5055 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5059 + memset(*pentry,0,sizeof(struct new_acl_entry));
5060 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5061 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5062 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5063 + acl_entryp->nextp = NULL;
5065 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5069 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5071 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5072 + entry->ace_id->id_type = tagtype;
5073 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5074 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5077 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5079 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5080 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5081 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5085 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5087 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5088 + if(!(*permset & S_IXUSR) &&
5089 + !(*permset & S_IWUSR) &&
5090 + !(*permset & S_IRUSR) &&
5094 + entry->ace_access = *permset;
5095 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5096 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5100 +int sys_acl_valid( SMB_ACL_T theacl )
5103 + int group_obj = 0;
5104 + int other_obj = 0;
5105 + struct acl_entry_link *acl_entry;
5107 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5108 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5109 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5110 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5113 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5115 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5121 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5123 + struct acl_entry_link *acl_entry_link = NULL;
5124 + struct acl *file_acl = NULL;
5125 + struct acl *file_acl_temp = NULL;
5126 + struct acl_entry *acl_entry = NULL;
5127 + struct ace_id *ace_id = NULL;
5134 + DEBUG(10,("Entering sys_acl_set_file\n"));
5135 + DEBUG(10,("File name is %s\n",name));
5137 + /* AIX has no default ACL */
5138 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5141 + acl_length = BUFSIZ;
5142 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5144 + if(file_acl == NULL) {
5146 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5150 + memset(file_acl,0,BUFSIZ);
5152 + file_acl->acl_len = ACL_SIZ;
5153 + file_acl->acl_mode = S_IXACL;
5155 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5156 + acl_entry_link->entryp->ace_access >>= 6;
5157 + id_type = acl_entry_link->entryp->ace_id->id_type;
5160 + case SMB_ACL_USER_OBJ:
5161 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5163 + case SMB_ACL_GROUP_OBJ:
5164 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5166 + case SMB_ACL_OTHER:
5167 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5169 + case SMB_ACL_MASK:
5173 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5174 + acl_length += sizeof(struct acl_entry);
5175 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5176 + if(file_acl_temp == NULL) {
5177 + SAFE_FREE(file_acl);
5179 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5183 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5184 + SAFE_FREE(file_acl);
5185 + file_acl = file_acl_temp;
5188 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5189 + file_acl->acl_len += sizeof(struct acl_entry);
5190 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5191 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5193 + /* In order to use this, we'll need to wait until we can get denies */
5194 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5195 + acl_entry->ace_type = ACC_SPECIFY; */
5197 + acl_entry->ace_type = ACC_SPECIFY;
5199 + ace_id = acl_entry->ace_id;
5201 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5202 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5203 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5204 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5205 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5208 + rc = chacl(name,file_acl,file_acl->acl_len);
5209 + DEBUG(10,("errno is %d\n",errno));
5210 + DEBUG(10,("return code is %d\n",rc));
5211 + SAFE_FREE(file_acl);
5212 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5216 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5218 + struct acl_entry_link *acl_entry_link = NULL;
5219 + struct acl *file_acl = NULL;
5220 + struct acl *file_acl_temp = NULL;
5221 + struct acl_entry *acl_entry = NULL;
5222 + struct ace_id *ace_id = NULL;
5228 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5229 + acl_length = BUFSIZ;
5230 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5232 + if(file_acl == NULL) {
5234 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5238 + memset(file_acl,0,BUFSIZ);
5240 + file_acl->acl_len = ACL_SIZ;
5241 + file_acl->acl_mode = S_IXACL;
5243 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5244 + acl_entry_link->entryp->ace_access >>= 6;
5245 + id_type = acl_entry_link->entryp->ace_id->id_type;
5246 + DEBUG(10,("The id_type is %d\n",id_type));
5249 + case SMB_ACL_USER_OBJ:
5250 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5252 + case SMB_ACL_GROUP_OBJ:
5253 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5255 + case SMB_ACL_OTHER:
5256 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5258 + case SMB_ACL_MASK:
5262 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5263 + acl_length += sizeof(struct acl_entry);
5264 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5265 + if(file_acl_temp == NULL) {
5266 + SAFE_FREE(file_acl);
5268 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5272 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5273 + SAFE_FREE(file_acl);
5274 + file_acl = file_acl_temp;
5277 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5278 + file_acl->acl_len += sizeof(struct acl_entry);
5279 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5280 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5282 + /* In order to use this, we'll need to wait until we can get denies */
5283 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5284 + acl_entry->ace_type = ACC_SPECIFY; */
5286 + acl_entry->ace_type = ACC_SPECIFY;
5288 + ace_id = acl_entry->ace_id;
5290 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5291 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5292 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5293 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5294 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5297 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5298 + DEBUG(10,("errno is %d\n",errno));
5299 + DEBUG(10,("return code is %d\n",rc));
5300 + SAFE_FREE(file_acl);
5301 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5305 +int sys_acl_delete_def_file(const char *name)
5307 + /* AIX has no default ACL */
5311 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5313 + return(*permset & perm);
5316 +int sys_acl_free_text(char *text)
5321 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5323 + struct acl_entry_link *acl_entry_link;
5325 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5326 + SAFE_FREE(acl_entry_link->prevp->entryp);
5327 + SAFE_FREE(acl_entry_link->prevp);
5330 + SAFE_FREE(acl_entry_link->prevp->entryp);
5331 + SAFE_FREE(acl_entry_link->prevp);
5332 + SAFE_FREE(acl_entry_link->entryp);
5333 + SAFE_FREE(acl_entry_link);
5338 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5343 +#else /* No ACLs. */
5345 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5351 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5357 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5363 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5369 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5372 + return (SMB_ACL_T)NULL;
5375 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5378 + return (SMB_ACL_T)NULL;
5381 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5387 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5393 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5396 + return (permset & perm) ? 1 : 0;
5399 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5405 +int sys_acl_free_text(UNUSED(char *text))
5411 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5417 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5423 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5429 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5435 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5441 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5447 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5453 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5459 +int sys_acl_delete_def_file(UNUSED(const char *name))
5465 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5471 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5477 +#endif /* No ACLs. */
5479 +/************************************************************************
5480 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5482 +************************************************************************/
5484 +int no_acl_syscall_error(int err)
5486 +#if defined(ENOSYS)
5487 + if (err == ENOSYS) {
5491 +#if defined(ENOTSUP)
5492 + if (err == ENOTSUP) {
5499 +#endif /* SUPPORT_ACLS */
5500 --- old/lib/sysacls.h
5501 +++ new/lib/sysacls.h
5503 +#ifdef SUPPORT_ACLS
5505 +#ifdef HAVE_SYS_ACL_H
5506 +#include <sys/acl.h>
5508 +#ifdef HAVE_ACL_LIBACL_H
5509 +#include <acl/libacl.h>
5511 +#include "smb_acls.h"
5513 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5514 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5515 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5516 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5517 +#define slprintf snprintf
5519 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5520 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5521 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5522 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5523 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5524 +SMB_ACL_T sys_acl_get_fd(int fd);
5525 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5526 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5527 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5528 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5529 +SMB_ACL_T sys_acl_init(int count);
5530 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5531 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5532 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5533 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5534 +int sys_acl_valid(SMB_ACL_T theacl);
5535 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5536 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5537 +int sys_acl_delete_def_file(const char *name);
5538 +int sys_acl_free_text(char *text);
5539 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5540 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5542 +#endif /* SUPPORT_ACLS */
5545 @@ -606,8 +606,10 @@ static void log_formatted(enum logcode c
5546 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5547 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5548 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5551 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5552 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5553 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5556 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5557 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5560 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5562 int preserve_links = 0;
5563 int preserve_hard_links = 0;
5564 +int preserve_acls = 0;
5565 int preserve_perms = 0;
5566 int preserve_executability = 0;
5567 int preserve_devices = 0;
5568 @@ -199,6 +200,7 @@ static void print_rsync_version(enum log
5569 char const *got_socketpair = "no ";
5570 char const *have_inplace = "no ";
5571 char const *hardlinks = "no ";
5572 + char const *acls = "no ";
5573 char const *links = "no ";
5574 char const *ipv6 = "no ";
5575 STRUCT_STAT *dumstat;
5576 @@ -215,6 +217,10 @@ static void print_rsync_version(enum log
5580 +#ifdef SUPPORT_ACLS
5584 #ifdef SUPPORT_LINKS
5587 @@ -227,17 +233,16 @@ static void print_rsync_version(enum log
5588 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
5589 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5590 rprintf(f, "<http://rsync.samba.org/>\n");
5591 - rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5592 - "%shard links, %ssymlinks, batchfiles,\n",
5593 - (int) (sizeof (OFF_T) * 8),
5594 - got_socketpair, hardlinks, links);
5595 + rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n",
5596 + (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links);
5598 + rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n",
5599 + have_inplace, ipv6, acls);
5601 /* Note that this field may not have type ino_t. It depends
5602 * on the complicated interaction between largefile feature
5604 - rprintf(f, " %sinplace, %sIPv6, "
5605 - "%d-bit system inums, %d-bit internal inums\n",
5606 - have_inplace, ipv6,
5607 + rprintf(f, " %d-bit system inums, %d-bit internal inums\n",
5608 (int) (sizeof dumstat->st_ino * 8),
5609 (int) (sizeof (int64) * 8));
5610 #ifdef MAINTAINER_MODE
5611 @@ -284,7 +289,7 @@ void usage(enum logcode F)
5612 rprintf(F," -q, --quiet suppress non-error messages\n");
5613 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5614 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5615 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5616 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5617 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5618 rprintf(F," -r, --recursive recurse into directories\n");
5619 rprintf(F," -R, --relative use relative path names\n");
5620 @@ -306,6 +311,9 @@ void usage(enum logcode F)
5621 rprintf(F," -p, --perms preserve permissions\n");
5622 rprintf(F," -E, --executability preserve the file's executability\n");
5623 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5624 +#ifdef SUPPORT_ACLS
5625 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5627 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5628 rprintf(F," -g, --group preserve group\n");
5629 rprintf(F," --devices preserve device files (super-user only)\n");
5630 @@ -425,6 +433,9 @@ static struct poptOption long_options[]
5631 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5632 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5633 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5634 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5635 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5636 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5637 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5638 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5639 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5640 @@ -1089,6 +1100,24 @@ int parse_arguments(int *argc, const cha
5645 +#ifdef SUPPORT_ACLS
5647 + preserve_perms = 1;
5650 + /* FIXME: this should probably be ignored with a
5651 + * warning and then countermeasures taken to
5652 + * restrict group and other access in the presence
5653 + * of any more restrictive ACLs, but this is safe
5655 + snprintf(err_buf,sizeof(err_buf),
5656 + "ACLs are not supported on this %s\n",
5657 + am_server ? "server" : "client");
5663 /* A large opt value means that set_refuse_options()
5664 * turned this option off. */
5665 @@ -1530,6 +1559,10 @@ void server_options(char **args,int *arg
5667 if (preserve_hard_links)
5669 +#ifdef SUPPORT_ACLS
5670 + if (preserve_acls)
5671 + argstr[x++] = 'A';
5678 @@ -47,6 +47,7 @@ extern int keep_partial;
5679 extern int checksum_seed;
5681 extern int delay_updates;
5682 +extern mode_t orig_umask;
5683 extern struct stats stats;
5684 extern char *stdout_format;
5685 extern char *tmpdir;
5686 @@ -350,6 +351,10 @@ int recv_files(int f_in, struct file_lis
5687 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5688 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5689 int max_phase = protocol_version >= 29 ? 2 : 1;
5690 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5691 +#ifdef SUPPORT_ACLS
5692 + char *parent_dirname = "";
5697 @@ -553,7 +558,16 @@ int recv_files(int f_in, struct file_lis
5698 * mode based on the local permissions and some heuristics. */
5699 if (!preserve_perms) {
5700 int exists = fd1 != -1;
5701 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5702 +#ifdef SUPPORT_ACLS
5703 + char *dn = file->dirname ? file->dirname : ".";
5704 + if (parent_dirname != dn
5705 + && strcmp(parent_dirname, dn) != 0) {
5706 + dflt_perms = default_perms_for_dir(dn);
5707 + parent_dirname = dn;
5710 + file->mode = dest_mode(file->mode, st.st_mode,
5711 + dflt_perms, exists);
5714 /* We now check to see if we are writing the file "inplace" */
5721 +extern int preserve_acls;
5722 extern int preserve_perms;
5723 extern int preserve_executability;
5724 extern int preserve_times;
5725 @@ -100,7 +101,8 @@ void free_sums(struct sum_struct *s)
5727 /* This is only called when we aren't preserving permissions. Figure out what
5728 * the permissions should be and return them merged back into the mode. */
5729 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5730 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5734 /* If the file already exists, we'll return the local permissions,
5735 @@ -117,56 +119,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5736 new_mode |= (new_mode & 0444) >> 2;
5739 - /* Apply the umask and turn off special permissions. */
5740 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5741 + /* Apply destination default permissions and turn
5742 + * off special permissions. */
5743 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5748 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5749 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5755 int change_uid, change_gid;
5756 mode_t new_mode = file->mode;
5762 - if (link_stat(fname, &st2, 0) < 0) {
5763 + if (link_stat(fname, &sx2.st, 0) < 0) {
5764 rsyserr(FERROR, errno, "stat %s failed",
5769 +#ifdef SUPPORT_ACLS
5770 + sx2.acc_acl = sx2.def_acl = NULL;
5772 if (!preserve_perms && S_ISDIR(new_mode)
5773 - && st->st_mode & S_ISGID) {
5774 + && sx2.st.st_mode & S_ISGID) {
5775 /* We just created this directory and its setgid
5776 * bit is on, so make sure it stays on. */
5777 new_mode |= S_ISGID;
5782 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5783 +#ifdef SUPPORT_ACLS
5784 + if (preserve_acls && !ACL_READY(*sxp))
5785 + get_acl(fname, sxp);
5788 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5789 flags |= ATTRS_SKIP_MTIME;
5790 if (!(flags & ATTRS_SKIP_MTIME)
5791 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5792 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5793 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5794 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5796 rsyserr(FERROR, errno, "failed to set times on %s",
5801 if (ret == 0) /* ret == 1 if symlink could not be set */
5805 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5806 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5807 change_gid = preserve_gid && file->gid != GID_NONE
5808 - && st->st_gid != file->gid;
5809 + && sxp->st.st_gid != file->gid;
5810 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5811 - if (S_ISLNK(st->st_mode))
5812 + if (S_ISLNK(sxp->st.st_mode))
5816 @@ -176,45 +187,57 @@ int set_file_attrs(char *fname, struct f
5818 "set uid of %s from %ld to %ld\n",
5820 - (long)st->st_uid, (long)file->uid);
5821 + (long)sxp->st.st_uid, (long)file->uid);
5825 "set gid of %s from %ld to %ld\n",
5827 - (long)st->st_gid, (long)file->gid);
5828 + (long)sxp->st.st_gid, (long)file->gid);
5831 if (do_lchown(fname,
5832 - change_uid ? file->uid : st->st_uid,
5833 - change_gid ? file->gid : st->st_gid) != 0) {
5834 + change_uid ? file->uid : sxp->st.st_uid,
5835 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5836 /* shouldn't have attempted to change uid or gid
5837 * unless have the privilege */
5838 rsyserr(FERROR, errno, "%s %s failed",
5839 change_uid ? "chown" : "chgrp",
5844 /* a lchown had been done - we have to re-stat if the
5845 * destination had the setuid or setgid bits set due
5846 * to the side effect of the chown call */
5847 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5848 - link_stat(fname, st,
5849 - keep_dirlinks && S_ISDIR(st->st_mode));
5850 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5851 + link_stat(fname, &sxp->st,
5852 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5857 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5858 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5860 +#ifdef SUPPORT_ACLS
5861 + /* It's OK to call set_acl() now, even for a dir, as the generator
5862 + * will enable owner-writability using chmod, if necessary.
5864 + * If set_acl() changes permission bits in the process of setting
5865 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5866 + * need to chmod(). */
5867 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5872 - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5873 + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5874 int ret = do_chmod(fname, new_mode);
5876 rsyserr(FERROR, errno,
5877 "failed to set permissions on %s",
5882 if (ret == 0) /* ret == 1 if symlink could not be set */
5884 @@ -227,6 +250,11 @@ int set_file_attrs(char *fname, struct f
5886 rprintf(FCLIENT, "%s is uptodate\n", fname);
5889 +#ifdef SUPPORT_ACLS
5890 + if (preserve_acls && sxp == &sx2)
5898 @@ -492,6 +492,14 @@ struct idev {
5899 #define IN_LOOPBACKNET 127
5902 +#ifndef HAVE_NO_ACLS
5903 +#define SUPPORT_ACLS 1
5906 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5907 +#define ACLS_NEED_MASK 1
5910 #define GID_NONE ((gid_t)-1)
5912 #define HL_CHECK_MASTER 0
5913 @@ -653,6 +661,17 @@ struct stats {
5915 struct chmod_mode_struct;
5917 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5925 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5926 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5928 #include "byteorder.h"
5929 #include "lib/mdfour.h"
5930 #include "lib/wildmatch.h"
5931 @@ -669,6 +688,16 @@ struct chmod_mode_struct;
5932 #define UNUSED(x) x __attribute__((__unused__))
5933 #define NORETURN __attribute__((__noreturn__))
5937 +#ifdef SUPPORT_ACLS
5938 + struct rsync_acl *acc_acl; /* access ACL */
5939 + struct rsync_acl *def_acl; /* default ACL */
5943 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5947 /* We have replacement versions of these if they're missing. */
5950 @@ -301,7 +301,7 @@ to the detailed description below for a
5951 -q, --quiet suppress non-error messages
5952 --no-motd suppress daemon-mode MOTD (see caveat)
5953 -c, --checksum skip based on checksum, not mod-time & size
5954 - -a, --archive archive mode; same as -rlptgoD (no -H)
5955 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
5956 --no-OPTION turn off an implied OPTION (e.g. --no-D)
5957 -r, --recursive recurse into directories
5958 -R, --relative use relative path names
5959 @@ -323,6 +323,7 @@ to the detailed description below for a
5960 -p, --perms preserve permissions
5961 -E, --executability preserve executability
5962 --chmod=CHMOD affect file and/or directory permissions
5963 + -A, --acls preserve ACLs (implies -p) [non-standard]
5964 -o, --owner preserve owner (super-user only)
5965 -g, --group preserve group
5966 --devices preserve device files (super-user only)
5967 @@ -753,7 +754,9 @@ quote(itemization(
5968 permissions, though the bf(--executability) option might change just
5969 the execute permission for the file.
5970 it() New files get their "normal" permission bits set to the source
5971 - file's permissions masked with the receiving end's umask setting, and
5972 + file's permissions masked with the receiving directory's default
5973 + permissions (either the receiving process's umask, or the permissions
5974 + specified via the destination directory's default ACL), and
5975 their special permission bits disabled except in the case where a new
5976 directory inherits a setgid bit from its parent directory.
5978 @@ -784,9 +787,11 @@ The preservation of the destination's se
5979 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5980 versions erroneously preserved the three special permission bits for
5981 newly-created files when bf(--perms) was off, while overriding the
5982 -destination's setgid bit setting on a newly-created directory. (Keep in
5983 -mind that it is the version of the receiving rsync that affects this
5985 +destination's setgid bit setting on a newly-created directory. Default ACL
5986 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5987 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5988 +(Keep in mind that it is the version of the receiving rsync that affects
5991 dit(bf(-E, --executability)) This option causes rsync to preserve the
5992 executability (or non-executability) of regular files when bf(--perms) is
5993 @@ -804,6 +809,15 @@ quote(itemization(
5995 If bf(--perms) is enabled, this option is ignored.
5997 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5998 +ACLs to be the same as the source ACLs. This nonstandard option only
5999 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
6001 +Note also that an optimization of the ACL-sending protocol used by this
6002 +version makes it incompatible with sending files to an older ACL-enabled
6003 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
6004 +doubling is not needed when pulling files from an older rsync.
6006 dit(bf(--chmod)) This option tells rsync to apply one or more
6007 comma-separated "chmod" strings to the permission of the files in the
6008 transfer. The resulting value is treated as though it was the permissions
6009 @@ -1389,8 +1403,8 @@ if the receiving rsync is at least versi
6010 with older versions of rsync, but that also turns on the output of other
6013 -The "%i" escape has a cryptic output that is 9 letters long. The general
6014 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
6015 +The "%i" escape has a cryptic output that is 11 letters long. The general
6016 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
6017 type of update being done, bf(X) is replaced by the file-type, and the
6018 other letters represent attributes that may be output if they are being
6020 @@ -1439,7 +1453,11 @@ quote(itemization(
6021 sender's value (requires bf(--owner) and super-user privileges).
6022 it() A bf(g) means the group is different and is being updated to the
6023 sender's value (requires bf(--group) and the authority to set the group).
6024 - it() The bf(z) slot is reserved for future use.
6025 + it() The bf(u) slot is reserved for reporting update (access) time changes
6026 + (a feature that is not yet released).
6027 + it() The bf(a) means that the ACL information changed.
6028 + it() The bf(x) slot is reserved for reporting extended attribute changes
6029 + (a feature that is not yet released).
6032 One other output is possible: when deleting files, the "%i" will output
6037 + Unix SMB/Netbios implementation.
6039 + Portable SMB ACL interface
6040 + Copyright (C) Jeremy Allison 2000
6042 + This program is free software; you can redistribute it and/or modify
6043 + it under the terms of the GNU General Public License as published by
6044 + the Free Software Foundation; either version 2 of the License, or
6045 + (at your option) any later version.
6047 + This program is distributed in the hope that it will be useful,
6048 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6049 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6050 + GNU General Public License for more details.
6052 + You should have received a copy of the GNU General Public License
6053 + along with this program; if not, write to the Free Software
6054 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6057 +#ifndef _SMB_ACLS_H
6058 +#define _SMB_ACLS_H
6060 +#if defined HAVE_POSIX_ACLS
6062 +/* This is an identity mapping (just remove the SMB_). */
6064 +#define SMB_ACL_TAG_T acl_tag_t
6065 +#define SMB_ACL_TYPE_T acl_type_t
6066 +#define SMB_ACL_PERMSET_T acl_permset_t
6067 +#define SMB_ACL_PERM_T acl_perm_t
6068 +#define SMB_ACL_READ ACL_READ
6069 +#define SMB_ACL_WRITE ACL_WRITE
6070 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6072 +/* Types of ACLs. */
6073 +#define SMB_ACL_USER ACL_USER
6074 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6075 +#define SMB_ACL_GROUP ACL_GROUP
6076 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6077 +#define SMB_ACL_OTHER ACL_OTHER
6078 +#define SMB_ACL_MASK ACL_MASK
6080 +#define SMB_ACL_T acl_t
6082 +#define SMB_ACL_ENTRY_T acl_entry_t
6084 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6085 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6087 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6088 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6090 +#elif defined HAVE_TRU64_ACLS
6092 +/* This is for DEC/Compaq Tru64 UNIX */
6094 +#define SMB_ACL_TAG_T acl_tag_t
6095 +#define SMB_ACL_TYPE_T acl_type_t
6096 +#define SMB_ACL_PERMSET_T acl_permset_t
6097 +#define SMB_ACL_PERM_T acl_perm_t
6098 +#define SMB_ACL_READ ACL_READ
6099 +#define SMB_ACL_WRITE ACL_WRITE
6100 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6102 +/* Types of ACLs. */
6103 +#define SMB_ACL_USER ACL_USER
6104 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6105 +#define SMB_ACL_GROUP ACL_GROUP
6106 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6107 +#define SMB_ACL_OTHER ACL_OTHER
6108 +#define SMB_ACL_MASK ACL_MASK
6110 +#define SMB_ACL_T acl_t
6112 +#define SMB_ACL_ENTRY_T acl_entry_t
6114 +#define SMB_ACL_FIRST_ENTRY 0
6115 +#define SMB_ACL_NEXT_ENTRY 1
6117 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6118 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6120 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6122 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6123 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6126 +/* SVR4.2 ES/MP ACLs */
6127 +typedef int SMB_ACL_TAG_T;
6128 +typedef int SMB_ACL_TYPE_T;
6129 +typedef ushort *SMB_ACL_PERMSET_T;
6130 +typedef ushort SMB_ACL_PERM_T;
6131 +#define SMB_ACL_READ 4
6132 +#define SMB_ACL_WRITE 2
6133 +#define SMB_ACL_EXECUTE 1
6135 +/* Types of ACLs. */
6136 +#define SMB_ACL_USER USER
6137 +#define SMB_ACL_USER_OBJ USER_OBJ
6138 +#define SMB_ACL_GROUP GROUP
6139 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6140 +#define SMB_ACL_OTHER OTHER_OBJ
6141 +#define SMB_ACL_MASK CLASS_OBJ
6143 +typedef struct SMB_ACL_T {
6147 + struct acl acl[1];
6150 +typedef struct acl *SMB_ACL_ENTRY_T;
6152 +#define SMB_ACL_FIRST_ENTRY 0
6153 +#define SMB_ACL_NEXT_ENTRY 1
6155 +#define SMB_ACL_TYPE_ACCESS 0
6156 +#define SMB_ACL_TYPE_DEFAULT 1
6159 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6162 +#elif defined HAVE_HPUX_ACLS
6165 + * Based on the Solaris & UnixWare code.
6169 +#include <sys/aclv.h>
6171 +/* SVR4.2 ES/MP ACLs */
6172 +typedef int SMB_ACL_TAG_T;
6173 +typedef int SMB_ACL_TYPE_T;
6174 +typedef ushort *SMB_ACL_PERMSET_T;
6175 +typedef ushort SMB_ACL_PERM_T;
6176 +#define SMB_ACL_READ 4
6177 +#define SMB_ACL_WRITE 2
6178 +#define SMB_ACL_EXECUTE 1
6180 +/* Types of ACLs. */
6181 +#define SMB_ACL_USER USER
6182 +#define SMB_ACL_USER_OBJ USER_OBJ
6183 +#define SMB_ACL_GROUP GROUP
6184 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6185 +#define SMB_ACL_OTHER OTHER_OBJ
6186 +#define SMB_ACL_MASK CLASS_OBJ
6188 +typedef struct SMB_ACL_T {
6192 + struct acl acl[1];
6195 +typedef struct acl *SMB_ACL_ENTRY_T;
6197 +#define SMB_ACL_FIRST_ENTRY 0
6198 +#define SMB_ACL_NEXT_ENTRY 1
6200 +#define SMB_ACL_TYPE_ACCESS 0
6201 +#define SMB_ACL_TYPE_DEFAULT 1
6203 +#elif defined HAVE_IRIX_ACLS
6205 +#define SMB_ACL_TAG_T acl_tag_t
6206 +#define SMB_ACL_TYPE_T acl_type_t
6207 +#define SMB_ACL_PERMSET_T acl_permset_t
6208 +#define SMB_ACL_PERM_T acl_perm_t
6209 +#define SMB_ACL_READ ACL_READ
6210 +#define SMB_ACL_WRITE ACL_WRITE
6211 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6213 +/* Types of ACLs. */
6214 +#define SMB_ACL_USER ACL_USER
6215 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6216 +#define SMB_ACL_GROUP ACL_GROUP
6217 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6218 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6219 +#define SMB_ACL_MASK ACL_MASK
6221 +typedef struct SMB_ACL_T {
6227 +#define SMB_ACL_ENTRY_T acl_entry_t
6229 +#define SMB_ACL_FIRST_ENTRY 0
6230 +#define SMB_ACL_NEXT_ENTRY 1
6232 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6233 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6235 +#elif defined HAVE_AIX_ACLS
6237 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6239 +#include "/usr/include/acl.h"
6241 +typedef uint *SMB_ACL_PERMSET_T;
6243 +struct acl_entry_link{
6244 + struct acl_entry_link *prevp;
6245 + struct new_acl_entry *entryp;
6246 + struct acl_entry_link *nextp;
6250 +struct new_acl_entry{
6251 + unsigned short ace_len;
6252 + unsigned short ace_type;
6253 + unsigned int ace_access;
6254 + struct ace_id ace_id[1];
6257 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6258 +#define SMB_ACL_T struct acl_entry_link*
6260 +#define SMB_ACL_TAG_T unsigned short
6261 +#define SMB_ACL_TYPE_T int
6262 +#define SMB_ACL_PERM_T uint
6263 +#define SMB_ACL_READ S_IRUSR
6264 +#define SMB_ACL_WRITE S_IWUSR
6265 +#define SMB_ACL_EXECUTE S_IXUSR
6267 +/* Types of ACLs. */
6268 +#define SMB_ACL_USER ACEID_USER
6269 +#define SMB_ACL_USER_OBJ 3
6270 +#define SMB_ACL_GROUP ACEID_GROUP
6271 +#define SMB_ACL_GROUP_OBJ 4
6272 +#define SMB_ACL_OTHER 5
6273 +#define SMB_ACL_MASK 6
6276 +#define SMB_ACL_FIRST_ENTRY 1
6277 +#define SMB_ACL_NEXT_ENTRY 2
6279 +#define SMB_ACL_TYPE_ACCESS 0
6280 +#define SMB_ACL_TYPE_DEFAULT 1
6282 +#else /* No ACLs. */
6284 +/* No ACLS - fake it. */
6285 +#define SMB_ACL_TAG_T int
6286 +#define SMB_ACL_TYPE_T int
6287 +#define SMB_ACL_PERMSET_T mode_t
6288 +#define SMB_ACL_PERM_T mode_t
6289 +#define SMB_ACL_READ S_IRUSR
6290 +#define SMB_ACL_WRITE S_IWUSR
6291 +#define SMB_ACL_EXECUTE S_IXUSR
6293 +/* Types of ACLs. */
6294 +#define SMB_ACL_USER 0
6295 +#define SMB_ACL_USER_OBJ 1
6296 +#define SMB_ACL_GROUP 2
6297 +#define SMB_ACL_GROUP_OBJ 3
6298 +#define SMB_ACL_OTHER 4
6299 +#define SMB_ACL_MASK 5
6301 +typedef struct SMB_ACL_T {
6305 +typedef struct SMB_ACL_ENTRY_T {
6307 +} *SMB_ACL_ENTRY_T;
6309 +#define SMB_ACL_FIRST_ENTRY 0
6310 +#define SMB_ACL_NEXT_ENTRY 1
6312 +#define SMB_ACL_TYPE_ACCESS 0
6313 +#define SMB_ACL_TYPE_DEFAULT 1
6315 +#endif /* No ACLs. */
6316 +#endif /* _SMB_ACLS_H */
6317 --- old/testsuite/acls.test
6318 +++ new/testsuite/acls.test
6322 +# This program is distributable under the terms of the GNU GPL (see
6325 +# Test that rsync handles basic ACL preservation.
6327 +. $srcdir/testsuite/rsync.fns
6329 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6330 +case "$setfacl_nodef" in
6331 +true) test_skipped "I don't know how to use your setfacl command" ;;
6334 +makepath "$fromdir/foo"
6335 +echo something >"$fromdir/file1"
6336 +echo else >"$fromdir/file2"
6338 +files='foo file1 file2'
6340 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6341 +setfacl -m u:0:5 "$fromdir/file1"
6342 +setfacl -m u:0:5 "$fromdir/file2"
6344 +$RSYNC -avvA "$fromdir/" "$todir/"
6347 +getfacl $files >"$scratchdir/acls.txt"
6350 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6352 +# The script would have aborted on error, so getting here means we've won.
6354 --- old/testsuite/default-acls.test
6355 +++ new/testsuite/default-acls.test
6359 +# This program is distributable under the terms of the GNU GPL (see
6362 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6364 +. $srcdir/testsuite/rsync.fns
6366 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6367 +case "$setfacl_nodef" in
6368 +true) test_skipped "I don't know how to use your setfacl command" ;;
6369 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6370 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6372 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6374 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6376 + todir="$scratchdir/$1"
6378 + $setfacl_nodef "$todir"
6380 + case "$setfacl_nodef" in
6381 + *-k*) opts="-dm $2" ;;
6382 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6384 + setfacl $opts "$todir"
6386 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6387 + # even though the directory itself is outside the transfer
6388 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6389 + check_perms "$todir/to" $4 "Target $1"
6390 + check_perms "$todir/to/dir" $4 "Target $1"
6391 + check_perms "$todir/to/file" $3 "Target $1"
6392 + check_perms "$todir/to/program" $4 "Target $1"
6393 + # Make sure get_local_name doesn't mess us up when transferring only one file
6394 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6395 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6396 + # Make sure we obey default ACLs when not transferring a regular file
6397 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6398 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6401 +mkdir "$scratchdir/dir"
6402 +echo "File!" >"$scratchdir/file"
6403 +echo "#!/bin/sh" >"$scratchdir/program"
6404 +chmod 777 "$scratchdir/dir"
6405 +chmod 666 "$scratchdir/file"
6406 +chmod 777 "$scratchdir/program"
6408 +# Test some target directories
6410 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6411 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6412 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6413 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6414 +testit noda1 '' rw------- rwx------
6416 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6418 +testit noda3 '' rw-r--r-- rwxr-xr-x
6422 --- old/testsuite/devices.test
6423 +++ new/testsuite/devices.test
6424 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6425 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6427 cat <<EOT >"$chkfile"
6431 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6433 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6435 cat <<EOT >"$chkfile"
6439 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6441 @@ -58,7 +58,7 @@ sleep 1
6442 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6444 cat <<EOT >"$chkfile"
6448 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6450 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6453 cat <<EOT >"$chkfile"
6458 -hD+++++++ block2.5 => block3
6467 +hD+++++++++ block2.5 => block3
6473 if test ! -b "$fromdir/block2.5"; then
6474 sed -e '/block2\.5/d' \
6475 --- old/testsuite/itemize.test
6476 +++ new/testsuite/itemize.test
6477 @@ -29,15 +29,15 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6478 $RSYNC -iplr "$fromdir/" "$todir/" \
6480 cat <<EOT >"$chkfile"
6484 ->f+++++++ bar/baz/rsync
6486 ->f+++++++ foo/config1
6487 ->f+++++++ foo/config2
6488 ->f+++++++ foo/extra
6489 -cL+++++++ foo/sym -> ../bar/baz/rsync
6492 +cd+++++++++ bar/baz/
6493 +>f+++++++++ bar/baz/rsync
6495 +>f+++++++++ foo/config1
6496 +>f+++++++++ foo/config2
6497 +>f+++++++++ foo/extra
6498 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6500 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6502 @@ -49,10 +49,10 @@ chmod 601 "$fromdir/foo/config2"
6503 $RSYNC -iplrH "$fromdir/" "$todir/" \
6505 cat <<EOT >"$chkfile"
6506 ->f..T.... bar/baz/rsync
6507 ->f..T.... foo/config1
6508 ->f.sTp... foo/config2
6509 -hf..T.... foo/extra => foo/config1
6510 +>f..T...... bar/baz/rsync
6511 +>f..T...... foo/config1
6512 +>f.sTp..... foo/config2
6513 +hf..T...... foo/extra => foo/config1
6515 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6517 @@ -69,11 +69,11 @@ chmod 777 "$todir/bar/baz/rsync"
6518 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6520 cat <<EOT >"$chkfile"
6521 -.f..tp... bar/baz/rsync
6523 -.f..t.... foo/config1
6524 ->fcstp... foo/config2
6525 -cL..T.... foo/sym -> ../bar/baz/rsync
6526 +.f..tp..... bar/baz/rsync
6528 +.f..t...... foo/config1
6529 +>fcstp..... foo/config2
6530 +cL..T...... foo/sym -> ../bar/baz/rsync
6532 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6534 @@ -98,15 +98,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6537 cat <<EOT >"$chkfile"
6541 -.f...p... bar/baz/rsync
6544 ->f..t.... foo/config2
6546 -.L foo/sym -> ../bar/baz/rsync
6550 +.f...p..... bar/baz/rsync
6553 +>f..t...... foo/config2
6555 +.L foo/sym -> ../bar/baz/rsync
6557 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6559 @@ -125,8 +125,8 @@ touch "$todir/foo/config2"
6560 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6562 cat <<EOT >"$chkfile"
6563 -.f...p... foo/config1
6564 ->f..t.... foo/config2
6565 +.f...p..... foo/config1
6566 +>f..t...... foo/config2
6568 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6570 @@ -135,15 +135,15 @@ $RSYNC -ivvplrtH --copy-dest=../ld "$fro
6573 cat <<EOT >"$chkfile"
6581 -hf foo/extra => foo/config1
6582 -cL..T.... foo/sym -> ../bar/baz/rsync
6585 +cd+++++++++ bar/baz/
6590 +hf foo/extra => foo/config1
6591 +cL..T...... foo/sym -> ../bar/baz/rsync
6593 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6595 @@ -151,11 +151,11 @@ rm -rf "$todir"
6596 $RSYNC -iplrtH --copy-dest=../ld "$fromdir/" "$todir/" \
6598 cat <<EOT >"$chkfile"
6603 -hf foo/extra => foo/config1
6606 +cd+++++++++ bar/baz/
6608 +hf foo/extra => foo/config1
6610 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6612 @@ -182,15 +182,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6615 cat <<EOT >"$chkfile"
6623 -hf foo/extra => foo/config1
6624 -hL foo/sym -> ../bar/baz/rsync
6627 +cd+++++++++ bar/baz/
6632 +hf foo/extra => foo/config1
6633 +hL foo/sym -> ../bar/baz/rsync
6635 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6637 @@ -198,10 +198,10 @@ rm -rf "$todir"
6638 $RSYNC -iplrtH --dry-run --link-dest=../ld "$fromdir/" "$todir/" \
6640 cat <<EOT >"$chkfile"
6647 +cd+++++++++ bar/baz/
6650 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6652 @@ -209,10 +209,10 @@ rm -rf "$todir"
6653 $RSYNC -iplrtH --link-dest=../ld "$fromdir/" "$todir/" \
6655 cat <<EOT >"$chkfile"
6662 +cd+++++++++ bar/baz/
6665 diff $diffopt "$chkfile" "$outfile" || test_fail "test 13 failed"
6667 @@ -240,14 +240,14 @@ filter_outfile
6668 # TODO fix really-old problem when combining -H with --compare-dest:
6669 # missing output for foo/extra hard-link (and it might not be updated)!
6670 cat <<EOT >"$chkfile"
6678 -.L foo/sym -> ../bar/baz/rsync
6681 +cd+++++++++ bar/baz/
6686 +.L foo/sym -> ../bar/baz/rsync
6688 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6690 @@ -255,10 +255,10 @@ rm -rf "$todir"
6691 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6693 cat <<EOT >"$chkfile"
6700 +cd+++++++++ bar/baz/
6703 diff $diffopt "$chkfile" "$outfile" || test_fail "test 16 failed"
6709 extern int preserve_uid;
6710 extern int preserve_gid;
6711 +extern int preserve_acls;
6712 extern int numeric_ids;
6715 @@ -273,7 +274,7 @@ void send_uid_list(int f)
6719 - if (preserve_uid) {
6720 + if (preserve_uid || preserve_acls) {
6722 /* we send sequences of uid/byte-length/name */
6723 for (list = uidlist; list; list = list->next) {
6724 @@ -290,7 +291,7 @@ void send_uid_list(int f)
6728 - if (preserve_gid) {
6729 + if (preserve_gid || preserve_acls) {
6731 for (list = gidlist; list; list = list->next) {
6733 @@ -311,7 +312,7 @@ void recv_uid_list(int f, struct file_li
6737 - if (preserve_uid && !numeric_ids) {
6738 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6739 /* read the uid list */
6740 while ((id = read_int(f)) != 0) {
6741 int len = read_byte(f);
6742 @@ -323,7 +324,7 @@ void recv_uid_list(int f, struct file_li
6746 - if (preserve_gid && !numeric_ids) {
6747 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6748 /* read the gid list */
6749 while ((id = read_int(f)) != 0) {
6750 int len = read_byte(f);
6751 @@ -335,6 +336,16 @@ void recv_uid_list(int f, struct file_li
6755 +#ifdef SUPPORT_ACLS
6756 + if (preserve_acls && !numeric_ids) {
6758 + while ((id = next_acl_uid(flist)) != NULL)
6759 + *id = match_uid(*id);
6760 + while ((id = next_acl_gid(flist)) != NULL)
6761 + *id = match_gid(*id);
6765 /* Now convert all the uids/gids from sender values to our values. */
6766 if (am_root && preserve_uid && !numeric_ids) {
6767 for (i = 0; i < flist->count; i++)
6770 @@ -1468,3 +1468,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6775 +void *expand_item_list(item_list *lp, size_t item_size,
6776 + const char *desc, int incr)
6778 + /* First time through, 0 <= 0, so list is expanded. */
6779 + if (lp->malloced <= lp->count) {
6781 + size_t new_size = lp->malloced;
6783 + new_size -= incr; /* increase slowly */
6784 + else if (new_size < (size_t)incr)
6788 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6789 + if (verbose >= 4) {
6790 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6791 + who_am_i(), desc, (double)new_size * item_size,
6792 + new_ptr == lp->items ? " not" : "");
6795 + out_of_memory("expand_item_list");
6797 + lp->items = new_ptr;
6798 + lp->malloced = new_size;
6800 + return (char*)lp->items + (lp->count++ * item_size);