1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 @@ -25,15 +25,15 @@ VERSION=@VERSION@
16 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
17 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
18 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
19 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
20 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
21 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
22 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
23 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
24 main.o checksum.o match.o syscall.o log.o backup.o
25 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
26 - fileio.o batch.o clientname.o chmod.o
27 + fileio.o batch.o clientname.o chmod.o acls.o
28 OBJS3=progress.o pipe.o
29 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
30 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 + * Handle passing Access Control Lists between systems.
37 + * Copyright (C) 1996 Andrew Tridgell
38 + * Copyright (C) 1996 Paul Mackerras
39 + * Copyright (C) 2006 Wayne Davison
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License as published by
43 + * the Free Software Foundation; either version 2 of the License, or
44 + * (at your option) any later version.
46 + * This program is distributed in the hope that it will be useful,
47 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 + * GNU General Public License for more details.
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
57 +#include "lib/sysacls.h"
63 +extern int orig_umask;
64 +extern int preserve_acls;
65 +extern unsigned int file_struct_len;
67 +/* === ACL structures === */
79 +#define NO_ENTRY ((uchar)0x80)
80 +typedef struct rsync_acl {
83 + /* These will be NO_ENTRY if there's no such entry. */
95 +static const rsync_acl empty_rsync_acl = {
96 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
99 +static item_list access_acl_list = EMPTY_ITEM_LIST;
100 +static item_list default_acl_list = EMPTY_ITEM_LIST;
102 +/* === Calculations on ACL types === */
104 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
106 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
107 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
108 + : "unknown SMB_ACL_TYPE_T";
111 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
112 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
114 +static int count_racl_entries(const rsync_acl *racl)
116 + return racl->users.count + racl->groups.count
117 + + (racl->user_obj != NO_ENTRY)
118 + + (racl->group_obj != NO_ENTRY)
119 + + (racl->mask != NO_ENTRY)
120 + + (racl->other != NO_ENTRY);
123 +static int calc_sacl_entries(const rsync_acl *racl)
125 + /* A System ACL always gets user/group/other permission entries. */
126 + return racl->users.count + racl->groups.count
127 +#ifdef ACLS_NEED_MASK
130 + + (racl->mask != NO_ENTRY) + 3;
134 +/* Extracts and returns the permission bits from the ACL. This cannot be
135 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
136 +static int rsync_acl_get_perms(const rsync_acl *racl)
138 + return (racl->user_obj << 6)
139 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
143 +/* Removes the permission-bit entries from the ACL because these
144 + * can be reconstructed from the file's mode. */
145 +static void rsync_acl_strip_perms(rsync_acl *racl)
147 + racl->user_obj = NO_ENTRY;
148 + if (racl->mask == NO_ENTRY)
149 + racl->group_obj = NO_ENTRY;
151 + if (racl->group_obj == racl->mask)
152 + racl->group_obj = NO_ENTRY;
153 + racl->mask = NO_ENTRY;
155 + racl->other = NO_ENTRY;
158 +/* Given an empty rsync_acl, fake up the permission bits. */
159 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
161 + racl->user_obj = (mode >> 6) & 7;
162 + racl->group_obj = (mode >> 3) & 7;
163 +#ifdef ACLS_NEED_MASK
164 + racl->mask = (mode >> 3) & 7;
166 + racl->other = mode & 7;
169 +/* === Rsync ACL functions === */
171 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
173 + id_access *ida1, *ida2;
174 + int count = ial1->count;
175 + if (count != ial2->count)
179 + for (; count--; ida1++, ida2++) {
180 + if (ida1->access != ida2->access || ida1->id != ida2->id)
186 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
188 + return (racl1->user_obj == racl2->user_obj
189 + && racl1->group_obj == racl2->group_obj
190 + && racl1->mask == racl2->mask
191 + && racl1->other == racl2->other
192 + && ida_entries_equal(&racl1->users, &racl2->users)
193 + && ida_entries_equal(&racl1->groups, &racl2->groups));
196 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
197 + * the ACL will be handled by the normal mode-preservation code. This is
198 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
199 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
200 + * that it might have several of its perm objects set to NO_ENTRY. */
201 +static BOOL rsync_acls_equal_enough(const rsync_acl *racl1,
202 + const rsync_acl *racl2, mode_t m)
204 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
205 + return False; /* One has a mask and the other doesn't */
207 + /* When there's a mask, the group_obj becomes an extended entry. */
208 + if (racl1->mask != NO_ENTRY) {
209 + /* A condensed rsync_acl with a mask can only have no
210 + * group_obj when it was identical to the mask. This
211 + * means that it was also identical to the group attrs
212 + * from the mode. */
213 + if (racl2->group_obj == NO_ENTRY) {
214 + if (racl1->group_obj != ((m >> 3) & 7))
216 + } else if (racl1->group_obj != racl2->group_obj)
219 + return ida_entries_equal(&racl1->users, &racl2->users)
220 + && ida_entries_equal(&racl1->groups, &racl2->groups);
223 +static void rsync_acl_free(rsync_acl *racl)
225 + if (racl->users.idas)
226 + free(racl->users.idas);
227 + if (racl->groups.idas)
228 + free(racl->groups.idas);
229 + *racl = empty_rsync_acl;
232 +void free_acls(statx *sxp)
234 + if (sxp->acc_acl) {
235 + rsync_acl_free(sxp->acc_acl);
236 + free(sxp->acc_acl);
237 + sxp->acc_acl = NULL;
239 + if (sxp->def_acl) {
240 + rsync_acl_free(sxp->def_acl);
241 + free(sxp->def_acl);
242 + sxp->def_acl = NULL;
246 +static int id_access_sorter(const void *r1, const void *r2)
248 + id_access *ida1 = (id_access *)r1;
249 + id_access *ida2 = (id_access *)r2;
250 + id_t rid1 = ida1->id, rid2 = ida2->id;
251 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
254 +static void sort_ida_entries(ida_entries *idal)
258 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
261 +/* Transfer the count id_access items out of the temp_ida_list into either
262 + * the users or groups ida_entries list in racl. */
263 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
268 + if (temp_ida_list->count) {
269 + int cnt = temp_ida_list->count;
270 + id_access *temp_idas = temp_ida_list->items;
271 + if (!(idas = new_array(id_access, cnt)))
272 + out_of_memory("save_idas");
273 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
277 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
280 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
281 + exit_cleanup(RERR_UNSUPPORTED);
283 + ent->count = temp_ida_list->count;
286 + /* Truncate the temporary list now that its idas have been saved. */
287 + temp_ida_list->count = 0;
290 +/* === System ACLs === */
292 +/* Unpack system acl -> rsync acl verbatim. Return whether we succeeded. */
293 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
295 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
296 + SMB_ACL_TAG_T prior_list_type = 0;
297 + SMB_ACL_ENTRY_T entry;
298 + const char *errfun;
301 + *racl = empty_rsync_acl;
302 + errfun = "sys_acl_get_entry";
303 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
305 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
306 + SMB_ACL_TAG_T tag_type;
307 + SMB_ACL_PERMSET_T permset;
311 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
312 + errfun = "sys_acl_get_tag_type";
315 + if ((rc = sys_acl_get_permset(entry, &permset))) {
316 + errfun = "sys_acl_get_tag_type";
319 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
320 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
321 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
322 + /* continue == done with entry; break == store in temporary ida list */
323 + switch (tag_type) {
324 + case SMB_ACL_USER_OBJ:
325 + if (racl->user_obj == NO_ENTRY)
326 + racl->user_obj = access;
328 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
332 + case SMB_ACL_GROUP_OBJ:
333 + if (racl->group_obj == NO_ENTRY)
334 + racl->group_obj = access;
336 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
338 + case SMB_ACL_GROUP:
341 + if (racl->mask == NO_ENTRY)
342 + racl->mask = access;
344 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
346 + case SMB_ACL_OTHER:
347 + if (racl->other == NO_ENTRY)
348 + racl->other = access;
350 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
353 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
356 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
357 + errfun = "sys_acl_get_tag_type";
361 + if (tag_type != prior_list_type) {
362 + if (prior_list_type)
363 + save_idas(&temp_ida_list, racl, prior_list_type);
364 + prior_list_type = tag_type;
366 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, 0);
367 + ida->id = *((id_t *)qualifier);
368 + ida->access = access;
369 + sys_acl_free_qualifier(qualifier, tag_type);
372 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
373 + rsync_acl_free(racl);
376 + if (prior_list_type)
377 + save_idas(&temp_ida_list, racl, prior_list_type);
379 + sort_ida_entries(&racl->users);
380 + sort_ida_entries(&racl->groups);
382 +#ifdef ACLS_NEED_MASK
383 + if (!racl->users.count && !racl->groups.count) {
384 + /* Throw away a superfluous mask, but mask off the
385 + * group perms with it first. */
386 + racl->group_obj &= racl->mask;
387 + racl->mask = NO_ENTRY;
394 +/* Synactic sugar for system calls */
396 +#define CALL_OR_ERROR(func,args,str) \
404 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
405 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
407 +/* Store the permissions in the system ACL entry. */
408 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
410 + const char *errfun = NULL;
411 + SMB_ACL_PERMSET_T permset;
413 + COE( sys_acl_get_permset,(entry, &permset) );
414 + COE( sys_acl_clear_perms,(permset) );
416 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
418 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
420 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
421 + COE( sys_acl_set_permset,(entry, permset) );
426 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
430 +/* Pack rsync acl -> system acl verbatim. Return whether we succeeded. */
431 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
433 +#ifdef ACLS_NEED_MASK
438 + const char *errfun = NULL;
439 + SMB_ACL_ENTRY_T entry;
441 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
442 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
446 + COE( sys_acl_create_entry,(smb_acl, &entry) );
447 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
448 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
450 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
451 + COE( sys_acl_create_entry,(smb_acl, &entry) );
452 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
453 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
454 + COE2( store_access_in_entry,(ida->access, entry) );
457 + COE( sys_acl_create_entry,(smb_acl, &entry) );
458 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
459 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
461 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
462 + COE( sys_acl_create_entry,(smb_acl, &entry) );
463 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
464 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
465 + COE2( store_access_in_entry,(ida->access, entry) );
468 +#ifdef ACLS_NEED_MASK
469 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
470 + COE( sys_acl_create_entry,(smb_acl, &entry) );
471 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
472 + COE2( store_access_in_entry,(mask_bits, entry) );
474 + if (racl->mask != NO_ENTRY) {
475 + COE( sys_acl_create_entry,(smb_acl, &entry) );
476 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
477 + COE2( store_access_in_entry,(racl->mask, entry) );
481 + COE( sys_acl_create_entry,(smb_acl, &entry) );
482 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
483 + COE2( store_access_in_entry,(racl->other & 7, entry) );
486 + if (sys_acl_valid(*smb_acl) < 0)
487 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
494 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
496 + sys_acl_free_acl(*smb_acl);
500 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
501 + const item_list *racl_list,
502 + const rsync_acl *racl)
504 + static int access_match = -1, default_match = -1;
505 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
506 + size_t count = racl_list->count;
508 + /* If this is the first time through or we didn't match the last
509 + * time, then start at the end of the list, which should be the
510 + * best place to start hunting. */
512 + *match = racl_list->count - 1;
514 + rsync_acl *base = racl_list->items;
515 + if (rsync_acls_equal(base + *match, racl))
518 + *match = racl_list->count - 1;
525 +/* Turn the ACL data in statx into cached ACL data, setting the index
526 + * values in the file struct. */
527 +void cache_acls(struct file_struct *file, statx *sxp)
529 + SMB_ACL_TYPE_T type;
531 + item_list *racl_list;
537 + type = SMB_ACL_TYPE_ACCESS;
538 + racl = sxp->acc_acl;
539 + racl_list = &access_acl_list;
540 + ndx_ptr = (char*)file + file_struct_len;
542 + int ndx = find_matching_rsync_acl(type, racl_list, racl);
545 + ndx = racl_list->count;
546 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1);
547 + new_duo->racl = *racl;
548 + new_duo->sacl = NULL;
549 + *racl = empty_rsync_acl;
551 + rsync_acl_free(racl);
552 + SIVAL(ndx_ptr, 0, ndx);
553 + racl = sxp->def_acl;
554 + racl_list = &default_acl_list;
556 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
559 +/* Return the ACL(s) for the given filename. */
560 +int get_acls(const char *fname, statx *sxp)
562 + SMB_ACL_TYPE_T type;
564 + if (S_ISLNK(sxp->st.st_mode))
567 + type = SMB_ACL_TYPE_ACCESS;
569 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
570 + rsync_acl *racl = new(rsync_acl);
573 + out_of_memory("get_acls");
574 + if (type == SMB_ACL_TYPE_ACCESS)
575 + sxp->acc_acl = racl;
577 + sxp->def_acl = racl;
580 + BOOL ok = unpack_smb_acl(racl, sacl);
582 + sys_acl_free_acl(sacl);
587 + } else if (errno == ENOTSUP) {
588 + /* ACLs are not supported, so pretend we have a basic ACL. */
589 + *racl = empty_rsync_acl;
590 + if (type == SMB_ACL_TYPE_ACCESS)
591 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
593 + rsyserr(FERROR, errno, "get_acls: sys_acl_get_file(%s, %s)",
594 + fname, str_acl_type(type));
598 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
603 +/* === Send functions === */
605 +/* The general strategy with the tag_type <-> character mapping is that
606 + * lowercase implies that no qualifier follows, where uppercase does.
607 + * A similar idiom for the acl type (access or default) itself, but
608 + * lowercase in this instance means there's no ACL following, so the
609 + * ACL is a repeat, so the receiver should reuse the last of the same
612 +/* Send the ida list over the file descriptor. */
613 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
616 + size_t count = idal->count;
617 + for (ida = idal->idas; count--; ida++) {
618 + write_byte(f, tag_char);
619 + write_byte(f, ida->access);
620 + write_int(f, ida->id);
621 + /* FIXME: sorta wasteful: we should maybe buffer as
622 + * many ids as max(ACL_USER + ACL_GROUP) objects to
623 + * keep from making so many calls. */
624 + if (tag_char == 'U')
631 +/* Send an rsync acl over the file descriptor. */
632 +static void send_rsync_acl(int f, const rsync_acl *racl)
634 + size_t count = count_racl_entries(racl);
635 + write_int(f, count);
636 + if (racl->user_obj != NO_ENTRY) {
637 + write_byte(f, 'u');
638 + write_byte(f, racl->user_obj);
640 + send_ida_entries(f, &racl->users, 'U');
641 + if (racl->group_obj != NO_ENTRY) {
642 + write_byte(f, 'g');
643 + write_byte(f, racl->group_obj);
645 + send_ida_entries(f, &racl->groups, 'G');
646 + if (racl->mask != NO_ENTRY) {
647 + write_byte(f, 'm');
648 + write_byte(f, racl->mask);
650 + if (racl->other != NO_ENTRY) {
651 + write_byte(f, 'o');
652 + write_byte(f, racl->other);
656 +/* Send the ACLs from the statx structure down the indicated file descriptor.
657 + * This also frees the ACL data. */
658 +void send_acls(statx *sxp, int f)
660 + SMB_ACL_TYPE_T type;
661 + rsync_acl *racl, *new_racl;
662 + item_list *racl_list;
664 + if (S_ISLNK(sxp->st.st_mode))
667 + type = SMB_ACL_TYPE_ACCESS;
668 + racl = sxp->acc_acl;
669 + racl_list = &access_acl_list;
673 + /* Discard a superfluous mask. */
674 + if (racl->mask != NO_ENTRY && !racl->users.count && !racl->groups.count)
675 + racl->mask = NO_ENTRY;
676 + /* Avoid sending values that can be inferred from other data,
677 + * but only when preserve_acls == 1 (it is 2 when we must be
678 + * backward compatible with older acls.diff versions). */
679 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
680 + rsync_acl_strip_perms(racl);
681 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
682 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
684 + rsync_acl_free(racl);
686 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1);
687 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
688 + send_rsync_acl(f, racl);
690 + *racl = empty_rsync_acl;
692 + racl = sxp->def_acl;
693 + racl_list = &default_acl_list;
694 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
699 +/* === Receive functions === */
701 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
703 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
704 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
705 + uchar computed_mask_bits = 0;
709 + *racl = empty_rsync_acl;
711 + if (!(count = read_int(f)))
715 + char tag = read_byte(f);
716 + uchar access = read_byte(f);
717 + if (access & ~ (4 | 2 | 1)) {
718 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
720 + exit_cleanup(RERR_STREAMIO);
724 + if (racl->user_obj != NO_ENTRY) {
725 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
726 + exit_cleanup(RERR_STREAMIO);
728 + racl->user_obj = access;
731 + tag_type = SMB_ACL_USER;
734 + if (racl->group_obj != NO_ENTRY) {
735 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
736 + exit_cleanup(RERR_STREAMIO);
738 + racl->group_obj = access;
741 + tag_type = SMB_ACL_GROUP;
744 + if (racl->mask != NO_ENTRY) {
745 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
746 + exit_cleanup(RERR_STREAMIO);
748 + racl->mask = access;
751 + if (racl->other != NO_ENTRY) {
752 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
753 + exit_cleanup(RERR_STREAMIO);
755 + racl->other = access;
758 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
760 + exit_cleanup(RERR_STREAMIO);
762 + if (tag_type != prior_list_type) {
763 + if (prior_list_type)
764 + save_idas(&temp_ida_list, racl, prior_list_type);
765 + prior_list_type = tag_type;
767 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, 0);
768 + ida->access = access;
769 + ida->id = read_int(f);
770 + computed_mask_bits |= access;
772 + if (prior_list_type)
773 + save_idas(&temp_ida_list, racl, prior_list_type);
775 + if (type == SMB_ACL_TYPE_DEFAULT) {
776 + /* Ensure that these are never unset. */
777 + if (racl->user_obj == NO_ENTRY)
778 + racl->user_obj = 7;
779 + if (racl->group_obj == NO_ENTRY)
780 + racl->group_obj = 0;
781 + if (racl->other == NO_ENTRY)
785 + if (!racl->users.count && !racl->groups.count) {
786 + /* If we received a superfluous mask, throw it away. */
787 + if (racl->mask != NO_ENTRY) {
788 + /* Mask off the group perms with it first. */
789 + racl->group_obj &= racl->mask | NO_ENTRY;
790 + racl->mask = NO_ENTRY;
792 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
793 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
796 +/* Receive the ACL info the sender has included for this file-list entry. */
797 +void receive_acls(struct file_struct *file, int f)
799 + SMB_ACL_TYPE_T type;
800 + item_list *racl_list;
803 + if (S_ISLNK(file->mode))
806 + type = SMB_ACL_TYPE_ACCESS;
807 + racl_list = &access_acl_list;
808 + ndx_ptr = (char*)file + file_struct_len;
810 + char tag = read_byte(f);
813 + if (tag == 'A' || tag == 'a') {
814 + if (type != SMB_ACL_TYPE_ACCESS) {
815 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
816 + f_name(file, NULL));
817 + exit_cleanup(RERR_STREAMIO);
819 + } else if (tag == 'D' || tag == 'd') {
820 + if (type == SMB_ACL_TYPE_ACCESS) {
821 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
822 + f_name(file, NULL));
823 + exit_cleanup(RERR_STREAMIO);
826 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
827 + f_name(file, NULL), tag);
828 + exit_cleanup(RERR_STREAMIO);
830 + if (tag == 'A' || tag == 'D') {
832 + ndx = racl_list->count;
833 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1);
834 + receive_rsync_acl(&duo_item->racl, f, type);
835 + duo_item->sacl = NULL;
838 + if ((size_t)ndx >= racl_list->count) {
839 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
840 + f_name(file, NULL), str_acl_type(type), ndx);
841 + exit_cleanup(RERR_STREAMIO);
844 + SIVAL(ndx_ptr, 0, ndx);
845 + racl_list = &default_acl_list;
847 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
850 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
852 + SMB_ACL_ENTRY_T entry;
853 + const char *errfun;
856 + if (S_ISDIR(mode)) {
857 + /* If the sticky bit is going on, it's not safe to allow all
858 + * the new ACLs to go into effect before it gets set. */
859 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
860 + if (mode & S_ISVTX)
863 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
866 + /* If setuid or setgid is going off, it's not safe to allow all
867 + * the new ACLs to go into effect before they get cleared. */
868 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
869 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
874 + errfun = "sys_acl_get_entry";
875 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
877 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
878 + SMB_ACL_TAG_T tag_type;
879 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
880 + errfun = "sys_acl_get_tag_type";
883 + switch (tag_type) {
884 + case SMB_ACL_USER_OBJ:
885 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
887 + case SMB_ACL_GROUP_OBJ:
888 + /* group is only empty when identical to group perms. */
889 + if (racl->group_obj != NO_ENTRY)
891 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
894 +#ifndef ACLS_NEED_MASK
895 + /* mask is only empty when we don't need it. */
896 + if (racl->mask == NO_ENTRY)
899 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
901 + case SMB_ACL_OTHER:
902 + COE2( store_access_in_entry,(mode & 7, entry) );
909 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
915 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
916 + /* Ensure that chmod() will be called to restore any lost setid bits. */
917 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
918 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
919 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
922 + /* Return the mode of the file on disk, as we will set them. */
923 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
926 +/* Set ACL on indicated filename.
928 + * This sets extended access ACL entries and default ACLs. If convenient,
929 + * it sets permission bits along with the access ACLs and signals having
930 + * done so by modifying sxp->st.st_mode.
932 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
933 + * with fname set to NULL to just check if the ACLs are unchanged. */
934 +int set_acls(const char *fname, const struct file_struct *file, statx *sxp)
937 + SMB_ACL_TYPE_T type;
940 + if (S_ISLNK(file->mode))
943 + type = SMB_ACL_TYPE_ACCESS;
944 + ndx_ptr = (char*)file + file_struct_len;
948 + int ndx = IVAL(ndx_ptr, 0);
952 + if (type == SMB_ACL_TYPE_ACCESS) {
953 + duo_item = access_acl_list.items;
955 + eq = rsync_acls_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
957 + duo_item = default_acl_list.items;
959 + eq = rsync_acls_equal(sxp->def_acl, &duo_item->racl);
963 + if (!dry_run && fname) {
964 + if (type == SMB_ACL_TYPE_DEFAULT
965 + && duo_item->racl.user_obj == NO_ENTRY) {
966 + if (sys_acl_delete_def_file(fname) < 0) {
967 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
973 + mode_t cur_mode = sxp->st.st_mode;
974 + if (!duo_item->sacl
975 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
979 + if (type == SMB_ACL_TYPE_ACCESS) {
980 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
981 + cur_mode, file->mode);
982 + if (cur_mode == ~0u)
985 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
986 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
987 + fname, str_acl_type(type));
991 + if (type == SMB_ACL_TYPE_ACCESS)
992 + sxp->st.st_mode = cur_mode;
995 + if (unchanged == 1)
997 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1002 +/* === Enumeration functions for uid mapping === */
1004 +/* Context -- one and only one. Should be cycled through once on uid
1005 + * mapping and once on gid mapping. */
1006 +static item_list *_enum_racl_lists[] = {
1007 + &access_acl_list, &default_acl_list, NULL
1010 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1011 +static int enum_ida_index = 0;
1012 +static size_t enum_racl_index = 0;
1014 +/* This returns the next tag_type id from the given acl for the next entry,
1015 + * or it returns 0 if there are no more tag_type ids in the acl. */
1016 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1018 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1019 + if (enum_ida_index < idal->count) {
1020 + id_access *ida = &idal->idas[enum_ida_index++];
1023 + enum_ida_index = 0;
1027 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1029 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1031 + acl_duo *duo_item = racl_list->items;
1032 + duo_item += enum_racl_index;
1033 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1036 + enum_racl_index = 0;
1040 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1042 + for (; *enum_racl_list; enum_racl_list++) {
1043 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1047 + enum_racl_list = &_enum_racl_lists[0];
1051 +id_t *next_acl_uid()
1053 + return next_acl_list_id(SMB_ACL_USER);
1056 +id_t *next_acl_gid()
1058 + return next_acl_list_id(SMB_ACL_GROUP);
1061 +/* This is used by dest_mode(). */
1062 +int default_perms_for_dir(const char *dir)
1071 + perms = ACCESSPERMS & ~orig_umask;
1072 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1073 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1074 + if (sacl == NULL) {
1075 + /* Couldn't get an ACL. Darn. */
1078 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1082 + /* We're doing a dry run, so the containing directory
1083 + * wasn't actually created. Don't worry about it. */
1086 + /* Otherwise fall through. */
1088 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1089 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1095 + ok = unpack_smb_acl(&racl, sacl);
1096 + sys_acl_free_acl(sacl);
1098 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1102 + /* Apply the permission-bit entries of the default ACL, if any. */
1103 + if (racl.user_obj != NO_ENTRY) {
1104 + perms = rsync_acl_get_perms(&racl);
1106 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1109 + rsync_acl_free(&racl);
1113 +#endif /* SUPPORT_ACLS */
1116 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1117 extern char *backup_dir;
1120 +extern int preserve_acls;
1121 extern int preserve_devices;
1122 extern int preserve_specials;
1123 extern int preserve_links;
1124 @@ -94,7 +95,8 @@ path
1125 ****************************************************************************/
1126 static int make_bak_dir(char *fullpath)
1130 + struct file_struct *file;
1131 char *rel = fullpath + backup_dir_len;
1132 char *end = rel + strlen(rel);
1134 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1136 /* Try to transfer the directory settings of the
1137 * actual dir that the files are coming from. */
1138 - if (do_stat(rel, &st) < 0) {
1139 + if (do_stat(rel, &sx.st) < 0) {
1140 rsyserr(FERROR, errno,
1141 "make_bak_dir stat %s failed",
1144 - do_lchown(fullpath, st.st_uid, st.st_gid);
1145 - do_chmod(fullpath, st.st_mode);
1146 +#ifdef SUPPORT_ACLS
1147 + sx.acc_acl = sx.def_acl = NULL;
1149 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1151 +#ifdef SUPPORT_ACLS
1152 + if (preserve_acls) {
1153 + get_acls(rel, &sx);
1154 + cache_acls(file, &sx);
1157 + set_file_attrs(fullpath, file, NULL, 0);
1162 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1163 * We will move the file to be deleted into a parallel directory tree. */
1164 static int keep_backup(char *fname)
1168 struct file_struct *file;
1173 /* return if no file to keep */
1174 - if (do_lstat(fname, &st) < 0)
1175 + if (do_lstat(fname, &sx.st) < 0)
1177 +#ifdef SUPPORT_ACLS
1178 + sx.acc_acl = sx.def_acl = NULL;
1181 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1182 return 1; /* the file could have disappeared */
1183 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1184 if (!(buf = get_backup_name(fname)))
1187 +#ifdef SUPPORT_ACLS
1188 + if (preserve_acls) {
1189 + get_acls(fname, &sx);
1190 + cache_acls(file, &sx);
1194 /* Check to see if this is a device file, or link */
1195 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1196 || (preserve_specials && IS_SPECIAL(file->mode))) {
1197 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1198 if (robust_move(fname, buf) != 0) {
1199 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1200 full_fname(fname), buf);
1201 - } else if (st.st_nlink > 1) {
1202 + } else if (sx.st.st_nlink > 1) {
1203 /* If someone has hard-linked the file into the backup
1204 * dir, rename() might return success but do nothing! */
1205 robust_unlink(fname); /* Just in case... */
1206 --- old/configure.in
1207 +++ new/configure.in
1208 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1209 AC_CHECK_LIB(resolv, strcasecmp)
1212 +AC_CHECK_FUNCS(aclsort)
1213 +if test x"$ac_cv_func_aclsort" = x"no"; then
1214 + AC_CHECK_LIB(sec, aclsort)
1217 dnl At the moment we don't test for a broken memcmp(), because all we
1218 dnl need to do is test for equality, not comparison, and it seems that
1219 dnl every platform has a memcmp that can do at least that.
1220 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1221 AC_SUBST(CC_SHOBJ_FLAG)
1222 AC_SUBST(BUILD_POPT)
1224 +AC_CHECK_HEADERS(sys/acl.h)
1225 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1226 +#################################################
1227 +# check for ACL support
1229 +AC_MSG_CHECKING(whether to support ACLs)
1230 +AC_ARG_ENABLE(acl-support,
1231 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1232 +[ case "$enableval" in
1235 + case "$host_os" in
1237 + AC_MSG_RESULT(Using UnixWare ACLs)
1238 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1240 + *solaris*|*cygwin*)
1241 + AC_MSG_RESULT(Using solaris ACLs)
1242 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1245 + AC_MSG_RESULT(Using HPUX ACLs)
1246 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1249 + AC_MSG_RESULT(Using IRIX ACLs)
1250 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1253 + AC_MSG_RESULT(Using AIX ACLs)
1254 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1257 + AC_MSG_RESULT(Using Tru64 ACLs)
1258 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1259 + LIBS="$LIBS -lpacl"
1262 + AC_MSG_RESULT(ACLs requested -- running tests)
1263 + AC_CHECK_LIB(acl,acl_get_file)
1264 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1265 + AC_TRY_LINK([#include <sys/types.h>
1266 +#include <sys/acl.h>],
1267 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1268 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1269 + AC_MSG_CHECKING(ACL test results)
1270 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1271 + AC_MSG_RESULT(Using posix ACLs)
1272 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1273 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1274 + AC_TRY_LINK([#include <sys/types.h>
1275 +#include <sys/acl.h>],
1276 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1277 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1278 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1279 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1282 + AC_MSG_ERROR(Failed to find ACL support)
1289 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1292 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1296 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1301 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1302 extern int one_file_system;
1303 extern int copy_dirlinks;
1304 extern int keep_dirlinks;
1305 +extern int preserve_acls;
1306 extern int preserve_links;
1307 extern int preserve_hard_links;
1308 extern int preserve_devices;
1309 @@ -133,6 +134,8 @@ static void list_file_entry(struct file_
1311 permstring(permbuf, f->mode);
1313 + /* TODO: indicate '+' if the entry has ACLs. */
1315 #ifdef SUPPORT_LINKS
1316 if (preserve_links && S_ISLNK(f->mode)) {
1317 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1318 @@ -499,6 +502,9 @@ static struct file_struct *receive_file_
1319 char thisname[MAXPATHLEN];
1320 unsigned int l1 = 0, l2 = 0;
1321 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1322 +#ifdef SUPPORT_ACLS
1326 char *basename, *dirname, *bp;
1327 struct file_struct *file;
1328 @@ -602,13 +608,27 @@ static struct file_struct *receive_file_
1330 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1332 +#ifdef SUPPORT_ACLS
1333 + /* We need one or two index int32s when we're preserving ACLs. */
1334 + if (preserve_acls)
1335 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * sizeof (int32);
1340 alloc_len = file_struct_len + dirname_len + basename_len
1341 +#ifdef SUPPORT_ACLS
1344 + linkname_len + sum_len;
1345 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1347 file = (struct file_struct *)bp;
1348 memset(bp, 0, file_struct_len);
1349 bp += file_struct_len;
1350 +#ifdef SUPPORT_ACLS
1354 file->modtime = modtime;
1355 file->length = file_length;
1356 @@ -703,6 +723,11 @@ static struct file_struct *receive_file_
1357 read_buf(f, sum, checksum_len);
1360 +#ifdef SUPPORT_ACLS
1361 + if (preserve_acls)
1362 + receive_acls(file, f);
1368 @@ -733,6 +758,9 @@ struct file_struct *make_file(char *fnam
1369 char thisname[MAXPATHLEN];
1370 char linkname[MAXPATHLEN];
1371 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1372 +#ifdef SUPPORT_ACLS
1375 char *basename, *dirname, *bp;
1377 if (!flist || !flist->count) /* Ignore lastdir when invalid. */
1378 @@ -848,8 +876,19 @@ struct file_struct *make_file(char *fnam
1379 sum_len = always_checksum && am_sender && S_ISREG(st.st_mode)
1380 ? MD4_SUM_LENGTH : 0;
1382 +#ifdef SUPPORT_ACLS
1383 + /* We need one or two index int32s when we're preserving ACLs. */
1384 + if (preserve_acls)
1385 + xtra_len = (S_ISDIR(st.st_mode) ? 2 : 1) * sizeof (int32);
1390 alloc_len = file_struct_len + dirname_len + basename_len
1391 - + linkname_len + sum_len;
1392 +#ifdef SUPPORT_ACLS
1395 + + linkname_len + sum_len;
1397 bp = pool_alloc(flist->file_pool, alloc_len, "make_file");
1399 @@ -860,6 +899,9 @@ struct file_struct *make_file(char *fnam
1400 file = (struct file_struct *)bp;
1401 memset(bp, 0, file_struct_len);
1402 bp += file_struct_len;
1403 +#ifdef SUPPORT_ACLS
1407 file->flags = flags;
1408 file->modtime = st.st_mtime;
1409 @@ -952,6 +994,9 @@ static struct file_struct *send_file_nam
1410 unsigned short flags)
1412 struct file_struct *file;
1413 +#ifdef SUPPORT_ACLS
1417 file = make_file(fname, flist, stp, flags,
1418 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1419 @@ -961,6 +1006,15 @@ static struct file_struct *send_file_nam
1420 if (chmod_modes && !S_ISLNK(file->mode))
1421 file->mode = tweak_mode(file->mode, chmod_modes);
1423 +#ifdef SUPPORT_ACLS
1424 + if (preserve_acls) {
1425 + sx.st.st_mode = file->mode;
1426 + sx.acc_acl = sx.def_acl = NULL;
1427 + if (get_acls(fname, &sx) < 0)
1432 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1434 flist_expand(flist);
1435 @@ -968,6 +1022,15 @@ static struct file_struct *send_file_nam
1436 if (file->basename[0]) {
1437 flist->files[flist->count++] = file;
1438 send_file_entry(file, f);
1439 +#ifdef SUPPORT_ACLS
1440 + if (preserve_acls)
1441 + send_acls(&sx, f);
1444 +#ifdef SUPPORT_ACLS
1445 + if (preserve_acls)
1453 @@ -36,6 +36,7 @@ extern int recurse;
1454 extern int relative_paths;
1455 extern int implied_dirs;
1456 extern int keep_dirlinks;
1457 +extern int preserve_acls;
1458 extern int preserve_links;
1459 extern int preserve_devices;
1460 extern int preserve_specials;
1461 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1462 extern int max_delete;
1463 extern int force_delete;
1464 extern int one_file_system;
1465 +extern mode_t orig_umask;
1466 extern struct stats stats;
1467 extern dev_t filesystem_dev;
1468 extern char *backup_dir;
1469 @@ -317,22 +319,27 @@ static void do_delete_pass(struct file_l
1470 rprintf(FINFO, " \r");
1473 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1474 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1477 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1478 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1481 - if (am_root && preserve_uid && st->st_uid != file->uid)
1482 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1485 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1486 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1489 +#ifdef SUPPORT_ACLS
1490 + if (preserve_acls && set_acls(NULL, file, sxp) == 0)
1497 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1498 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1499 int32 iflags, uchar fnamecmp_type, char *xname)
1501 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1502 @@ -340,19 +347,23 @@ void itemize(struct file_struct *file, i
1503 : S_ISDIR(file->mode) ? !omit_dir_times
1504 : !S_ISLNK(file->mode);
1506 - if (S_ISREG(file->mode) && file->length != st->st_size)
1507 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1508 iflags |= ITEM_REPORT_SIZE;
1509 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1510 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1511 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1512 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1513 iflags |= ITEM_REPORT_TIME;
1514 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1515 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1516 iflags |= ITEM_REPORT_PERMS;
1517 - if (preserve_uid && am_root && file->uid != st->st_uid)
1518 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1519 iflags |= ITEM_REPORT_OWNER;
1520 if (preserve_gid && file->gid != GID_NONE
1521 - && st->st_gid != file->gid)
1522 + && sxp->st.st_gid != file->gid)
1523 iflags |= ITEM_REPORT_GROUP;
1524 +#ifdef SUPPORT_ACLS
1525 + if (preserve_acls && set_acls(NULL, file, sxp) == 0)
1526 + iflags |= ITEM_REPORT_ACL;
1529 iflags |= ITEM_IS_NEW;
1531 @@ -603,7 +614,7 @@ void check_for_finished_hlinks(int itemi
1532 * handling the file, -1 if no dest-linking occurred, or a non-negative
1533 * value if we found an alternate basis file. */
1534 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1535 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1536 + char *cmpbuf, statx *sxp, int itemizing,
1537 int maybe_ATTRS_REPORT, enum logcode code)
1539 int best_match = -1;
1540 @@ -612,7 +623,7 @@ static int try_dests_reg(struct file_str
1543 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1544 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1545 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1547 switch (match_level) {
1549 @@ -620,16 +631,20 @@ static int try_dests_reg(struct file_str
1553 - if (!unchanged_file(cmpbuf, file, stp))
1554 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1560 - if (!unchanged_attrs(file, stp))
1561 +#ifdef SUPPORT_ACLS
1562 + if (preserve_acls)
1563 + get_acls(cmpbuf, sxp);
1565 + if (!unchanged_attrs(file, sxp))
1567 if ((always_checksum || ignore_times)
1568 - && cmp_time(stp->st_mtime, file->modtime))
1569 + && cmp_time(sxp->st.st_mtime, file->modtime))
1573 @@ -644,22 +659,27 @@ static int try_dests_reg(struct file_str
1574 if (j != best_match) {
1576 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1577 - if (link_stat(cmpbuf, stp, 0) < 0)
1578 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1583 if (match_level == 3 && !copy_dest) {
1585 - if (hard_link_one(file, ndx, fname, 0, stp,
1586 + if (hard_link_one(file, ndx, fname, 0, sxp,
1588 itemizing && verbose > 1,
1591 if (preserve_hard_links && file->link_u.links)
1592 hard_link_cluster(file, ndx, itemizing, code);
1593 - } else if (itemizing)
1594 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1595 + } else if (itemizing) {
1596 +#ifdef SUPPORT_ACLS
1597 + if (preserve_acls && !ACL_READY(*sxp))
1598 + get_acls(fname, sxp);
1600 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1602 if (verbose > 1 && maybe_ATTRS_REPORT) {
1603 code = daemon_log_format_has_i || dry_run
1605 @@ -678,8 +698,13 @@ static int try_dests_reg(struct file_str
1610 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1612 +#ifdef SUPPORT_ACLS
1613 + if (preserve_acls && !ACL_READY(*sxp))
1614 + get_acls(fname, sxp);
1616 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1618 set_file_attrs(fname, file, NULL, 0);
1619 if (maybe_ATTRS_REPORT
1620 && ((!itemizing && verbose && match_level == 2)
1621 @@ -704,13 +729,18 @@ static int try_dests_non(struct file_str
1624 char fnamebuf[MAXPATHLEN];
1630 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1631 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1632 - || !unchanged_attrs(file, &st))
1633 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1635 +#ifdef SUPPORT_ACLS
1636 + if (preserve_acls)
1637 + get_acls(fnamebuf, &sx);
1639 + if (!unchanged_attrs(file, &sx))
1641 if (S_ISLNK(file->mode)) {
1642 #ifdef SUPPORT_LINKS
1643 @@ -723,10 +753,10 @@ static int try_dests_non(struct file_str
1646 } else if (IS_SPECIAL(file->mode)) {
1647 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1648 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1650 } else if (IS_DEVICE(file->mode)) {
1651 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1652 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1656 @@ -755,7 +785,15 @@ static int try_dests_non(struct file_str
1657 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1658 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1659 char *lp = link_dest ? "" : NULL;
1660 - itemize(file, ndx, 0, &st, changes, 0, lp);
1661 +#ifdef SUPPORT_ACLS
1662 + if (preserve_acls)
1663 + get_acls(fname, &sx);
1665 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1666 +#ifdef SUPPORT_ACLS
1667 + if (preserve_acls)
1671 if (verbose > 1 && maybe_ATTRS_REPORT) {
1672 code = daemon_log_format_has_i || dry_run
1673 @@ -769,6 +807,7 @@ static int try_dests_non(struct file_str
1676 static int phase = 0;
1677 +static int dflt_perms;
1679 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1680 * make sure it exists, and has the right permissions/timestamp info. For
1681 @@ -790,7 +829,8 @@ static void recv_generator(char *fname,
1682 static int need_fuzzy_dirlist = 0;
1683 struct file_struct *fuzzy_file = NULL;
1684 int fd = -1, f_copy = -1;
1685 - STRUCT_STAT st, real_st, partial_st;
1686 + statx sx, real_sx;
1687 + STRUCT_STAT partial_st;
1688 struct file_struct *back_file = NULL;
1689 int statret, real_ret, stat_errno;
1690 char *fnamecmp, *partialptr, *backupptr = NULL;
1691 @@ -841,6 +881,9 @@ static void recv_generator(char *fname,
1695 +#ifdef SUPPORT_ACLS
1696 + sx.acc_acl = sx.def_acl = NULL;
1700 stat_errno = ENOENT;
1701 @@ -848,7 +891,7 @@ static void recv_generator(char *fname,
1702 char *dn = file->dirname ? file->dirname : ".";
1703 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1704 if (relative_paths && !implied_dirs
1705 - && do_stat(dn, &st) < 0
1706 + && do_stat(dn, &sx.st) < 0
1707 && create_directory_path(fname) < 0) {
1708 rsyserr(FERROR, errno,
1709 "recv_generator: mkdir %s failed",
1710 @@ -860,6 +903,10 @@ static void recv_generator(char *fname,
1713 need_fuzzy_dirlist = 1;
1714 +#ifdef SUPPORT_ACLS
1715 + if (!preserve_perms)
1716 + dflt_perms = default_perms_for_dir(dn);
1719 parent_dirname = dn;
1721 @@ -868,7 +915,7 @@ static void recv_generator(char *fname,
1722 need_fuzzy_dirlist = 0;
1725 - statret = link_stat(fname, &st,
1726 + statret = link_stat(fname, &sx.st,
1727 keep_dirlinks && S_ISDIR(file->mode));
1730 @@ -886,8 +933,9 @@ static void recv_generator(char *fname,
1731 * mode based on the local permissions and some heuristics. */
1732 if (!preserve_perms) {
1733 int exists = statret == 0
1734 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1735 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1736 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1737 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1741 if (S_ISDIR(file->mode)) {
1742 @@ -896,8 +944,8 @@ static void recv_generator(char *fname,
1743 * file of that name and it is *not* a directory, then
1744 * we need to delete it. If it doesn't exist, then
1745 * (perhaps recursively) create it. */
1746 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1747 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1748 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1749 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1753 @@ -906,7 +954,11 @@ static void recv_generator(char *fname,
1756 if (itemizing && f_out != -1) {
1757 - itemize(file, ndx, statret, &st,
1758 +#ifdef SUPPORT_ACLS
1759 + if (preserve_acls && statret == 0)
1760 + get_acls(fname, &sx);
1762 + itemize(file, ndx, statret, &sx,
1763 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1765 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1766 @@ -918,19 +970,19 @@ static void recv_generator(char *fname,
1770 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1771 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1772 && verbose && code && f_out != -1)
1773 rprintf(code, "%s/\n", fname);
1774 if (delete_during && f_out != -1 && !phase && dry_run < 2
1775 && (file->flags & FLAG_DEL_HERE))
1776 - delete_in_dir(the_file_list, fname, file, &st);
1778 + delete_in_dir(the_file_list, fname, file, &sx.st);
1782 if (preserve_hard_links && file->link_u.links
1783 - && hard_link_check(file, ndx, fname, statret, &st,
1784 + && hard_link_check(file, ndx, fname, statret, &sx,
1785 itemizing, code, HL_CHECK_MASTER))
1789 if (preserve_links && S_ISLNK(file->mode)) {
1790 #ifdef SUPPORT_LINKS
1791 @@ -948,7 +1000,7 @@ static void recv_generator(char *fname,
1792 char lnk[MAXPATHLEN];
1795 - if (!S_ISDIR(st.st_mode)
1796 + if (!S_ISDIR(sx.st.st_mode)
1797 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1799 /* A link already pointing to the
1800 @@ -956,10 +1008,10 @@ static void recv_generator(char *fname,
1802 if (strcmp(lnk, file->u.link) == 0) {
1804 - itemize(file, ndx, 0, &st, 0,
1805 + itemize(file, ndx, 0, &sx, 0,
1808 - set_file_attrs(fname, file, &st,
1809 + set_file_attrs(fname, file, &sx,
1810 maybe_ATTRS_REPORT);
1811 if (preserve_hard_links
1812 && file->link_u.links) {
1813 @@ -972,9 +1024,9 @@ static void recv_generator(char *fname,
1815 /* Not the right symlink (or not a symlink), so
1817 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1818 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1820 - if (!S_ISLNK(st.st_mode))
1821 + if (!S_ISLNK(sx.st.st_mode))
1823 } else if (basis_dir[0] != NULL) {
1824 if (try_dests_non(file, fname, ndx, itemizing,
1825 @@ -990,7 +1042,7 @@ static void recv_generator(char *fname,
1828 if (preserve_hard_links && file->link_u.links
1829 - && hard_link_check(file, ndx, fname, -1, &st,
1830 + && hard_link_check(file, ndx, fname, -1, &sx,
1831 itemizing, code, HL_SKIP))
1833 if (do_symlink(file->u.link,fname) != 0) {
1834 @@ -999,7 +1051,7 @@ static void recv_generator(char *fname,
1836 set_file_attrs(fname, file, NULL, 0);
1838 - itemize(file, ndx, statret, &st,
1839 + itemize(file, ndx, statret, &sx,
1840 ITEM_LOCAL_CHANGE, 0, NULL);
1842 if (code && verbose) {
1843 @@ -1033,18 +1085,22 @@ static void recv_generator(char *fname,
1844 itemizing = code = 0;
1847 +#ifdef SUPPORT_ACLS
1848 + if (preserve_acls && statret == 0)
1849 + get_acls(fname, &sx);
1852 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1853 - || st.st_rdev != file->u.rdev) {
1854 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1855 + || sx.st.st_rdev != file->u.rdev) {
1857 - && delete_item(fname, st.st_mode, del_opts) < 0)
1859 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1861 if (preserve_hard_links && file->link_u.links
1862 - && hard_link_check(file, ndx, fname, -1, &st,
1863 + && hard_link_check(file, ndx, fname, -1, &sx,
1864 itemizing, code, HL_SKIP))
1866 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1867 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1869 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1870 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1873 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1874 @@ -1057,7 +1113,7 @@ static void recv_generator(char *fname,
1876 set_file_attrs(fname, file, NULL, 0);
1878 - itemize(file, ndx, statret, &st,
1879 + itemize(file, ndx, statret, &sx,
1880 ITEM_LOCAL_CHANGE, 0, NULL);
1882 if (code && verbose)
1883 @@ -1069,12 +1125,12 @@ static void recv_generator(char *fname,
1887 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1888 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1889 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1890 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1891 if (preserve_hard_links && file->link_u.links)
1892 hard_link_cluster(file, ndx, itemizing, code);
1898 if (!S_ISREG(file->mode)) {
1899 @@ -1108,7 +1164,7 @@ static void recv_generator(char *fname,
1902 if (update_only && statret == 0
1903 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1904 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1906 rprintf(FINFO, "%s is newer\n", fname);
1908 @@ -1117,18 +1173,18 @@ static void recv_generator(char *fname,
1910 fnamecmp_type = FNAMECMP_FNAME;
1912 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1913 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1914 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1915 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1918 stat_errno = ENOENT;
1921 if (statret != 0 && basis_dir[0] != NULL) {
1922 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1923 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1924 itemizing, maybe_ATTRS_REPORT, code);
1929 fnamecmp = fnamecmpbuf;
1931 @@ -1137,7 +1193,7 @@ static void recv_generator(char *fname,
1938 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1939 && link_stat(partialptr, &partial_st, 0) == 0
1940 @@ -1156,7 +1212,7 @@ static void recv_generator(char *fname,
1941 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1942 fname, fnamecmpbuf);
1944 - st.st_size = fuzzy_file->length;
1945 + sx.st.st_size = fuzzy_file->length;
1947 fnamecmp = fnamecmpbuf;
1948 fnamecmp_type = FNAMECMP_FUZZY;
1949 @@ -1165,7 +1221,7 @@ static void recv_generator(char *fname,
1952 if (preserve_hard_links && file->link_u.links
1953 - && hard_link_check(file, ndx, fname, statret, &st,
1954 + && hard_link_check(file, ndx, fname, statret, &sx,
1955 itemizing, code, HL_SKIP))
1957 if (stat_errno == ENOENT)
1958 @@ -1175,31 +1231,44 @@ static void recv_generator(char *fname,
1962 - if (append_mode && st.st_size > file->length)
1963 + if (append_mode && sx.st.st_size > file->length)
1966 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1968 else if (fnamecmp_type == FNAMECMP_FUZZY)
1970 - else if (unchanged_file(fnamecmp, file, &st)) {
1971 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1973 do_unlink(partialptr);
1974 handle_partial_dir(partialptr, PDIR_DELETE);
1977 - itemize(file, ndx, real_ret, &real_st,
1978 +#ifdef SUPPORT_ACLS
1979 + if (preserve_acls && real_ret == 0)
1980 + get_acls(fname, &real_sx);
1982 + itemize(file, ndx, real_ret, &real_sx,
1984 +#ifdef SUPPORT_ACLS
1985 + if (preserve_acls) {
1986 + if (fnamecmp_type == FNAMECMP_FNAME) {
1987 + sx.acc_acl = real_sx.acc_acl;
1988 + sx.def_acl = real_sx.def_acl;
1990 + free_acls(&real_sx);
1994 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1995 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1996 if (preserve_hard_links && file->link_u.links)
1997 hard_link_cluster(file, ndx, itemizing, code);
2005 + sx.st = partial_st;
2006 fnamecmp = partialptr;
2007 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2009 @@ -1223,17 +1292,21 @@ static void recv_generator(char *fname,
2011 /* pretend the file didn't exist */
2012 if (preserve_hard_links && file->link_u.links
2013 - && hard_link_check(file, ndx, fname, statret, &st,
2014 + && hard_link_check(file, ndx, fname, statret, &sx,
2015 itemizing, code, HL_SKIP))
2018 statret = real_ret = -1;
2019 +#ifdef SUPPORT_ACLS
2020 + if (preserve_acls && ACL_READY(sx))
2026 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2027 if (!(backupptr = get_backup_name(fname))) {
2032 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2034 @@ -1244,7 +1317,7 @@ static void recv_generator(char *fname,
2035 full_fname(backupptr));
2041 if ((f_copy = do_open(backupptr,
2042 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2043 @@ -1252,14 +1325,14 @@ static void recv_generator(char *fname,
2044 full_fname(backupptr));
2050 fnamecmp_type = FNAMECMP_BACKUP;
2054 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2055 - fnamecmp, (double)st.st_size);
2056 + fnamecmp, (double)sx.st.st_size);
2060 @@ -1277,24 +1350,32 @@ static void recv_generator(char *fname,
2061 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2062 if (fnamecmp_type == FNAMECMP_FUZZY)
2063 iflags |= ITEM_XNAME_FOLLOWS;
2064 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2065 +#ifdef SUPPORT_ACLS
2066 + if (preserve_acls && real_ret == 0)
2067 + get_acls(fname, &real_sx);
2069 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2070 fuzzy_file ? fuzzy_file->basename : NULL);
2071 +#ifdef SUPPORT_ACLS
2072 + if (preserve_acls)
2073 + free_acls(&real_sx);
2078 if (preserve_hard_links && file->link_u.links)
2079 hard_link_cluster(file, ndx, itemizing, code);
2087 if (statret != 0 || whole_file) {
2088 write_sum_head(f_out, NULL);
2093 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2094 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2098 @@ -1307,6 +1388,13 @@ static void recv_generator(char *fname,
2104 +#ifdef SUPPORT_ACLS
2105 + if (preserve_acls)
2111 void generate_files(int f_out, struct file_list *flist, char *local_name)
2112 @@ -1366,6 +1454,8 @@ void generate_files(int f_out, struct fi
2113 * notice that and let us know via the redo pipe (or its closing). */
2116 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2118 for (i = 0; i < flist->count; i++) {
2119 struct file_struct *file = flist->files[i];
2126 extern int link_dest;
2127 +extern int preserve_acls;
2128 extern int make_backups;
2129 extern int log_format_has_i;
2130 extern char *basis_dir[];
2131 @@ -143,15 +144,19 @@ void init_hard_links(void)
2133 #ifdef SUPPORT_HARD_LINKS
2134 static int maybe_hard_link(struct file_struct *file, int ndx,
2135 - char *fname, int statret, STRUCT_STAT *st,
2136 + char *fname, int statret, statx *sxp,
2137 char *toname, STRUCT_STAT *to_st,
2138 int itemizing, enum logcode code)
2141 - if (st->st_dev == to_st->st_dev
2142 - && st->st_ino == to_st->st_ino) {
2143 + if (sxp->st.st_dev == to_st->st_dev
2144 + && sxp->st.st_ino == to_st->st_ino) {
2146 - itemize(file, ndx, statret, st,
2147 +#ifdef SUPPORT_ACLS
2148 + if (preserve_acls && !ACL_READY(*sxp))
2149 + get_acls(fname, sxp);
2151 + itemize(file, ndx, statret, sxp,
2152 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2155 @@ -166,13 +171,13 @@ static int maybe_hard_link(struct file_s
2159 - return hard_link_one(file, ndx, fname, statret, st, toname,
2160 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2161 0, itemizing, code);
2165 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2166 - int statret, STRUCT_STAT *st, int itemizing,
2167 + int statret, statx *sxp, int itemizing,
2168 enum logcode code, int skip)
2170 #ifdef SUPPORT_HARD_LINKS
2171 @@ -207,7 +212,7 @@ int hard_link_check(struct file_struct *
2172 || st2.st_ino != st3.st_ino)
2177 if (verbose < 2 || !log_format_has_i)
2178 itemizing = code = 0;
2180 @@ -215,12 +220,16 @@ int hard_link_check(struct file_struct *
2181 if (!unchanged_file(cmpbuf, file, &st3))
2185 - if (unchanged_attrs(file, &st3))
2187 +#ifdef SUPPORT_ACLS
2188 + if (preserve_acls)
2189 + get_acls(cmpbuf, sxp);
2191 + if (unchanged_attrs(file, sxp))
2193 } while (basis_dir[++j] != NULL);
2195 - maybe_hard_link(file, ndx, fname, statret, st,
2196 + maybe_hard_link(file, ndx, fname, statret, sxp,
2197 toname, &st2, itemizing, code);
2198 file->F_HLINDEX = FINISHED_LINK;
2200 @@ -233,7 +242,7 @@ int hard_link_check(struct file_struct *
2202 #ifdef SUPPORT_HARD_LINKS
2203 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2204 - int statret, STRUCT_STAT *st, char *toname, int terse,
2205 + int statret, statx *sxp, char *toname, int terse,
2206 int itemizing, enum logcode code)
2208 if (do_link(toname, fname)) {
2209 @@ -249,7 +258,11 @@ int hard_link_one(struct file_struct *fi
2213 - itemize(file, ndx, statret, st,
2214 +#ifdef SUPPORT_ACLS
2215 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2216 + get_acls(fname, sxp);
2218 + itemize(file, ndx, statret, sxp,
2219 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2220 terse ? "" : toname);
2222 @@ -266,11 +279,12 @@ void hard_link_cluster(struct file_struc
2223 #ifdef SUPPORT_HARD_LINKS
2224 char hlink1[MAXPATHLEN];
2226 - STRUCT_STAT st1, st2;
2229 int statret, ndx = master;
2231 file->F_HLINDEX = FINISHED_LINK;
2232 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2233 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2235 if (!(file->flags & FLAG_HLINK_TOL)) {
2236 while (!(file->flags & FLAG_HLINK_EOL)) {
2237 @@ -284,9 +298,13 @@ void hard_link_cluster(struct file_struc
2238 if (file->F_HLINDEX != SKIPPED_LINK)
2240 hlink2 = f_name(file, NULL);
2241 - statret = link_stat(hlink2, &st2, 0);
2242 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2243 - hlink1, &st1, itemizing, code);
2244 + statret = link_stat(hlink2, &sx.st, 0);
2245 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2246 + hlink1, &st, itemizing, code);
2247 +#ifdef SUPPORT_ACLS
2248 + if (preserve_acls)
2251 file->F_HLINDEX = FINISHED_LINK;
2252 } while (!(file->flags & FLAG_HLINK_EOL));
2254 --- old/lib/sysacls.c
2255 +++ new/lib/sysacls.c
2258 + Unix SMB/CIFS implementation.
2259 + Samba system utilities for ACL support.
2260 + Copyright (C) Jeremy Allison 2000.
2262 + This program is free software; you can redistribute it and/or modify
2263 + it under the terms of the GNU General Public License as published by
2264 + the Free Software Foundation; either version 2 of the License, or
2265 + (at your option) any later version.
2267 + This program is distributed in the hope that it will be useful,
2268 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2269 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2270 + GNU General Public License for more details.
2272 + You should have received a copy of the GNU General Public License
2273 + along with this program; if not, write to the Free Software
2274 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2278 +#include "sysacls.h" /****** ADDED ******/
2280 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2281 +void SAFE_FREE(void *mem)
2287 +char *uidtoname(uid_t uid)
2289 + static char idbuf[12];
2290 + struct passwd *pw;
2292 + if ((pw = getpwuid(uid)) == NULL) {
2293 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2296 + return pw->pw_name;
2298 +/****** EXTRAS -- END ******/
2301 + This file wraps all differing system ACL interfaces into a consistent
2302 + one based on the POSIX interface. It also returns the correct errors
2303 + for older UNIX systems that don't support ACLs.
2305 + The interfaces that each ACL implementation must support are as follows :
2307 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2308 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2309 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2310 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2311 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2312 + SMB_ACL_T sys_acl_get_fd(int fd)
2313 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2314 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2315 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2316 + SMB_ACL_T sys_acl_init( int count)
2317 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2318 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2319 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2320 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2321 + int sys_acl_valid( SMB_ACL_T theacl )
2322 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2323 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2324 + int sys_acl_delete_def_file(const char *path)
2326 + This next one is not POSIX complient - but we *have* to have it !
2327 + More POSIX braindamage.
2329 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2331 + The generic POSIX free is the following call. We split this into
2332 + several different free functions as we may need to add tag info
2333 + to structures when emulating the POSIX interface.
2335 + int sys_acl_free( void *obj_p)
2337 + The calls we actually use are :
2339 + int sys_acl_free_text(char *text) - free acl_to_text
2340 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2341 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2345 +#if defined(HAVE_POSIX_ACLS)
2347 +/* Identity mapping - easy. */
2349 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2351 + return acl_get_entry( the_acl, entry_id, entry_p);
2354 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2356 + return acl_get_tag_type( entry_d, tag_type_p);
2359 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2361 + return acl_get_permset( entry_d, permset_p);
2364 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2366 + return acl_get_qualifier( entry_d);
2369 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2371 + return acl_get_file( path_p, type);
2374 +SMB_ACL_T sys_acl_get_fd(int fd)
2376 + return acl_get_fd(fd);
2379 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2381 + return acl_clear_perms(permset);
2384 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2386 + return acl_add_perm(permset, perm);
2389 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2391 +#if defined(HAVE_ACL_GET_PERM_NP)
2393 + * Required for TrustedBSD-based ACL implementations where
2394 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2397 + return acl_get_perm_np(permset, perm);
2399 + return acl_get_perm(permset, perm);
2403 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2405 + return acl_to_text( the_acl, plen);
2408 +SMB_ACL_T sys_acl_init( int count)
2410 + return acl_init(count);
2413 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2415 + return acl_create_entry(pacl, pentry);
2418 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2420 + return acl_set_tag_type(entry, tagtype);
2423 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2425 + return acl_set_qualifier(entry, qual);
2428 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2430 + return acl_set_permset(entry, permset);
2433 +int sys_acl_valid( SMB_ACL_T theacl )
2435 + return acl_valid(theacl);
2438 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2440 + return acl_set_file(name, acltype, theacl);
2443 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2445 + return acl_set_fd(fd, theacl);
2448 +int sys_acl_delete_def_file(const char *name)
2450 + return acl_delete_def_file(name);
2453 +int sys_acl_free_text(char *text)
2455 + return acl_free(text);
2458 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2460 + return acl_free(the_acl);
2463 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2465 + return acl_free(qual);
2468 +#elif defined(HAVE_TRU64_ACLS)
2470 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2471 + * is based on Draft 13 of the POSIX spec which is
2472 + * slightly different from the Draft 16 interface.
2474 + * Also, some of the permset manipulation functions
2475 + * such as acl_clear_perm() and acl_add_perm() appear
2476 + * to be broken on Tru64 so we have to manipulate
2477 + * the permission bits in the permset directly.
2479 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2481 + SMB_ACL_ENTRY_T entry;
2483 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2488 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2493 + return errno ? -1 : 0;
2496 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2498 + return acl_get_tag_type( entry_d, tag_type_p);
2501 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2503 + return acl_get_permset( entry_d, permset_p);
2506 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2508 + return acl_get_qualifier( entry_d);
2511 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2513 + return acl_get_file((char *)path_p, type);
2516 +SMB_ACL_T sys_acl_get_fd(int fd)
2518 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2521 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2523 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2528 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2530 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2535 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2540 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2542 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2545 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2547 + return acl_to_text( the_acl, plen);
2550 +SMB_ACL_T sys_acl_init( int count)
2552 + return acl_init(count);
2555 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2557 + SMB_ACL_ENTRY_T entry;
2559 + if ((entry = acl_create_entry(pacl)) == NULL) {
2567 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2569 + return acl_set_tag_type(entry, tagtype);
2572 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2574 + return acl_set_qualifier(entry, qual);
2577 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2579 + return acl_set_permset(entry, permset);
2582 +int sys_acl_valid( SMB_ACL_T theacl )
2584 + acl_entry_t entry;
2586 + return acl_valid(theacl, &entry);
2589 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2591 + return acl_set_file((char *)name, acltype, theacl);
2594 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2596 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2599 +int sys_acl_delete_def_file(const char *name)
2601 + return acl_delete_def_file((char *)name);
2604 +int sys_acl_free_text(char *text)
2607 + * (void) cast and explicit return 0 are for DEC UNIX
2608 + * which just #defines acl_free_text() to be free()
2610 + (void) acl_free_text(text);
2614 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2616 + return acl_free(the_acl);
2619 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2621 + return acl_free_qualifier(qual, tagtype);
2624 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2627 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2628 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2632 + * Note that while this code implements sufficient functionality
2633 + * to support the sys_acl_* interfaces it does not provide all
2634 + * of the semantics of the POSIX ACL interfaces.
2636 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2637 + * from a call to sys_acl_get_entry() should not be assumed to be
2638 + * valid after calling any of the following functions, which may
2639 + * reorder the entries in the ACL.
2642 + * sys_acl_set_file()
2643 + * sys_acl_set_fd()
2647 + * The only difference between Solaris and UnixWare / OpenUNIX is
2648 + * that the #defines for the ACL operations have different names
2650 +#if defined(HAVE_UNIXWARE_ACLS)
2652 +#define SETACL ACL_SET
2653 +#define GETACL ACL_GET
2654 +#define GETACLCNT ACL_CNT
2659 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2661 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2666 + if (entry_p == NULL) {
2671 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2675 + if (acl_d->next < 0) {
2680 + if (acl_d->next >= acl_d->count) {
2684 + *entry_p = &acl_d->acl[acl_d->next++];
2689 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2691 + *type_p = entry_d->a_type;
2696 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2698 + *permset_p = &entry_d->a_perm;
2703 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2705 + if (entry_d->a_type != SMB_ACL_USER
2706 + && entry_d->a_type != SMB_ACL_GROUP) {
2711 + return &entry_d->a_id;
2715 + * There is no way of knowing what size the ACL returned by
2716 + * GETACL will be unless you first call GETACLCNT which means
2717 + * making an additional system call.
2719 + * In the hope of avoiding the cost of the additional system
2720 + * call in most cases, we initially allocate enough space for
2721 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2722 + * be too small then we use GETACLCNT to find out the actual
2723 + * size, reallocate the ACL buffer, and then call GETACL again.
2726 +#define INITIAL_ACL_SIZE 16
2728 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2731 + int count; /* # of ACL entries allocated */
2732 + int naccess; /* # of access ACL entries */
2733 + int ndefault; /* # of default ACL entries */
2735 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2740 + count = INITIAL_ACL_SIZE;
2741 + if ((acl_d = sys_acl_init(count)) == NULL) {
2746 + * If there isn't enough space for the ACL entries we use
2747 + * GETACLCNT to determine the actual number of ACL entries
2748 + * reallocate and try again. This is in a loop because it
2749 + * is possible that someone else could modify the ACL and
2750 + * increase the number of entries between the call to
2751 + * GETACLCNT and the call to GETACL.
2753 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2754 + && errno == ENOSPC) {
2756 + sys_acl_free_acl(acl_d);
2758 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2762 + if ((acl_d = sys_acl_init(count)) == NULL) {
2768 + sys_acl_free_acl(acl_d);
2773 + * calculate the number of access and default ACL entries
2775 + * Note: we assume that the acl() system call returned a
2776 + * well formed ACL which is sorted so that all of the
2777 + * access ACL entries preceed any default ACL entries
2779 + for (naccess = 0; naccess < count; naccess++) {
2780 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2783 + ndefault = count - naccess;
2786 + * if the caller wants the default ACL we have to copy
2787 + * the entries down to the start of the acl[] buffer
2788 + * and mask out the ACL_DEFAULT flag from the type field
2790 + if (type == SMB_ACL_TYPE_DEFAULT) {
2793 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2794 + acl_d->acl[i] = acl_d->acl[j];
2795 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2798 + acl_d->count = ndefault;
2800 + acl_d->count = naccess;
2806 +SMB_ACL_T sys_acl_get_fd(int fd)
2809 + int count; /* # of ACL entries allocated */
2810 + int naccess; /* # of access ACL entries */
2812 + count = INITIAL_ACL_SIZE;
2813 + if ((acl_d = sys_acl_init(count)) == NULL) {
2817 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2818 + && errno == ENOSPC) {
2820 + sys_acl_free_acl(acl_d);
2822 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2826 + if ((acl_d = sys_acl_init(count)) == NULL) {
2832 + sys_acl_free_acl(acl_d);
2837 + * calculate the number of access ACL entries
2839 + for (naccess = 0; naccess < count; naccess++) {
2840 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2844 + acl_d->count = naccess;
2849 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2856 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2858 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2859 + && perm != SMB_ACL_EXECUTE) {
2864 + if (permset_d == NULL) {
2869 + *permset_d |= perm;
2874 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2876 + return *permset_d & perm;
2879 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2886 + * use an initial estimate of 20 bytes per ACL entry
2887 + * when allocating memory for the text representation
2891 + maxlen = 20 * acl_d->count;
2892 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2897 + for (i = 0; i < acl_d->count; i++) {
2898 + struct acl *ap = &acl_d->acl[i];
2907 + switch (ap->a_type) {
2909 + * for debugging purposes it's probably more
2910 + * useful to dump unknown tag types rather
2911 + * than just returning an error
2914 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2917 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2922 + case SMB_ACL_USER:
2923 + id = uidtoname(ap->a_id);
2924 + case SMB_ACL_USER_OBJ:
2928 + case SMB_ACL_GROUP:
2929 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2930 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2936 + case SMB_ACL_GROUP_OBJ:
2940 + case SMB_ACL_OTHER:
2944 + case SMB_ACL_MASK:
2950 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2951 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2952 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2955 + /* <tag> : <qualifier> : rwx \n \0 */
2956 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2959 + * If this entry would overflow the buffer
2960 + * allocate enough additional memory for this
2961 + * entry and an estimate of another 20 bytes
2962 + * for each entry still to be processed
2964 + if ((len + nbytes) > maxlen) {
2965 + char *oldtext = text;
2967 + maxlen += nbytes + 20 * (acl_d->count - i);
2969 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2970 + SAFE_FREE(oldtext);
2976 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2977 + len += nbytes - 1;
2986 +SMB_ACL_T sys_acl_init(int count)
2996 + * note that since the definition of the structure pointed
2997 + * to by the SMB_ACL_T includes the first element of the
2998 + * acl[] array, this actually allocates an ACL with room
2999 + * for (count+1) entries
3001 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3006 + a->size = count + 1;
3014 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3017 + SMB_ACL_ENTRY_T entry_d;
3019 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3024 + if (acl_d->count >= acl_d->size) {
3029 + entry_d = &acl_d->acl[acl_d->count++];
3030 + entry_d->a_type = 0;
3031 + entry_d->a_id = -1;
3032 + entry_d->a_perm = 0;
3033 + *entry_p = entry_d;
3038 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3040 + switch (tag_type) {
3041 + case SMB_ACL_USER:
3042 + case SMB_ACL_USER_OBJ:
3043 + case SMB_ACL_GROUP:
3044 + case SMB_ACL_GROUP_OBJ:
3045 + case SMB_ACL_OTHER:
3046 + case SMB_ACL_MASK:
3047 + entry_d->a_type = tag_type;
3057 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3059 + if (entry_d->a_type != SMB_ACL_GROUP
3060 + && entry_d->a_type != SMB_ACL_USER) {
3065 + entry_d->a_id = *((id_t *)qual_p);
3070 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3072 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3076 + entry_d->a_perm = *permset_d;
3082 + * sort the ACL and check it for validity
3084 + * if it's a minimal ACL with only 4 entries then we
3085 + * need to recalculate the mask permissions to make
3086 + * sure that they are the same as the GROUP_OBJ
3087 + * permissions as required by the UnixWare acl() system call.
3089 + * (note: since POSIX allows minimal ACLs which only contain
3090 + * 3 entries - ie there is no mask entry - we should, in theory,
3091 + * check for this and add a mask entry if necessary - however
3092 + * we "know" that the caller of this interface always specifies
3093 + * a mask so, in practice "this never happens" (tm) - if it *does*
3094 + * happen aclsort() will fail and return an error and someone will
3095 + * have to fix it ...)
3098 +static int acl_sort(SMB_ACL_T acl_d)
3100 + int fixmask = (acl_d->count <= 4);
3102 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3109 +int sys_acl_valid(SMB_ACL_T acl_d)
3111 + return acl_sort(acl_d);
3114 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3117 + struct acl *acl_p;
3119 + struct acl *acl_buf = NULL;
3122 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3127 + if (acl_sort(acl_d) != 0) {
3131 + acl_p = &acl_d->acl[0];
3132 + acl_count = acl_d->count;
3135 + * if it's a directory there is extra work to do
3136 + * since the acl() system call will replace both
3137 + * the access ACLs and the default ACLs (if any)
3139 + if (stat(name, &s) != 0) {
3142 + if (S_ISDIR(s.st_mode)) {
3143 + SMB_ACL_T acc_acl;
3144 + SMB_ACL_T def_acl;
3145 + SMB_ACL_T tmp_acl;
3148 + if (type == SMB_ACL_TYPE_ACCESS) {
3150 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3154 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3157 + if (tmp_acl == NULL) {
3162 + * allocate a temporary buffer for the complete ACL
3164 + acl_count = acc_acl->count + def_acl->count;
3165 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3167 + if (acl_buf == NULL) {
3168 + sys_acl_free_acl(tmp_acl);
3174 + * copy the access control and default entries into the buffer
3176 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3177 + acc_acl->count * sizeof(acl_buf[0]));
3179 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3180 + def_acl->count * sizeof(acl_buf[0]));
3183 + * set the ACL_DEFAULT flag on the default entries
3185 + for (i = acc_acl->count; i < acl_count; i++) {
3186 + acl_buf[i].a_type |= ACL_DEFAULT;
3189 + sys_acl_free_acl(tmp_acl);
3191 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3196 + ret = acl(name, SETACL, acl_count, acl_p);
3198 + SAFE_FREE(acl_buf);
3203 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3205 + if (acl_sort(acl_d) != 0) {
3209 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3212 +int sys_acl_delete_def_file(const char *path)
3218 + * fetching the access ACL and rewriting it has
3219 + * the effect of deleting the default ACL
3221 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3225 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3227 + sys_acl_free_acl(acl_d);
3232 +int sys_acl_free_text(char *text)
3238 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3244 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3249 +#elif defined(HAVE_HPUX_ACLS)
3253 + * Based on the Solaris/SCO code - with modifications.
3257 + * Note that while this code implements sufficient functionality
3258 + * to support the sys_acl_* interfaces it does not provide all
3259 + * of the semantics of the POSIX ACL interfaces.
3261 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3262 + * from a call to sys_acl_get_entry() should not be assumed to be
3263 + * valid after calling any of the following functions, which may
3264 + * reorder the entries in the ACL.
3267 + * sys_acl_set_file()
3268 + * sys_acl_set_fd()
3271 +/* This checks if the POSIX ACL system call is defined */
3272 +/* which basically corresponds to whether JFS 3.3 or */
3273 +/* higher is installed. If acl() was called when it */
3274 +/* isn't defined, it causes the process to core dump */
3275 +/* so it is important to check this and avoid acl() */
3276 +/* calls if it isn't there. */
3278 +static BOOL hpux_acl_call_presence(void)
3281 + shl_t handle = NULL;
3284 + static BOOL already_checked=0;
3286 + if(already_checked)
3290 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3292 + if(ret_val != 0) {
3293 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3294 + ret_val, errno, strerror(errno)));
3295 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3299 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3301 + already_checked = True;
3305 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3307 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3312 + if (entry_p == NULL) {
3317 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3321 + if (acl_d->next < 0) {
3326 + if (acl_d->next >= acl_d->count) {
3330 + *entry_p = &acl_d->acl[acl_d->next++];
3335 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3337 + *type_p = entry_d->a_type;
3342 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3344 + *permset_p = &entry_d->a_perm;
3349 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3351 + if (entry_d->a_type != SMB_ACL_USER
3352 + && entry_d->a_type != SMB_ACL_GROUP) {
3357 + return &entry_d->a_id;
3361 + * There is no way of knowing what size the ACL returned by
3362 + * ACL_GET will be unless you first call ACL_CNT which means
3363 + * making an additional system call.
3365 + * In the hope of avoiding the cost of the additional system
3366 + * call in most cases, we initially allocate enough space for
3367 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3368 + * be too small then we use ACL_CNT to find out the actual
3369 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3372 +#define INITIAL_ACL_SIZE 16
3374 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3377 + int count; /* # of ACL entries allocated */
3378 + int naccess; /* # of access ACL entries */
3379 + int ndefault; /* # of default ACL entries */
3381 + if(hpux_acl_call_presence() == False) {
3382 + /* Looks like we don't have the acl() system call on HPUX.
3383 + * May be the system doesn't have the latest version of JFS.
3388 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3393 + count = INITIAL_ACL_SIZE;
3394 + if ((acl_d = sys_acl_init(count)) == NULL) {
3399 + * If there isn't enough space for the ACL entries we use
3400 + * ACL_CNT to determine the actual number of ACL entries
3401 + * reallocate and try again. This is in a loop because it
3402 + * is possible that someone else could modify the ACL and
3403 + * increase the number of entries between the call to
3404 + * ACL_CNT and the call to ACL_GET.
3406 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3408 + sys_acl_free_acl(acl_d);
3410 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3414 + if ((acl_d = sys_acl_init(count)) == NULL) {
3420 + sys_acl_free_acl(acl_d);
3425 + * calculate the number of access and default ACL entries
3427 + * Note: we assume that the acl() system call returned a
3428 + * well formed ACL which is sorted so that all of the
3429 + * access ACL entries preceed any default ACL entries
3431 + for (naccess = 0; naccess < count; naccess++) {
3432 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3435 + ndefault = count - naccess;
3438 + * if the caller wants the default ACL we have to copy
3439 + * the entries down to the start of the acl[] buffer
3440 + * and mask out the ACL_DEFAULT flag from the type field
3442 + if (type == SMB_ACL_TYPE_DEFAULT) {
3445 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3446 + acl_d->acl[i] = acl_d->acl[j];
3447 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3450 + acl_d->count = ndefault;
3452 + acl_d->count = naccess;
3458 +SMB_ACL_T sys_acl_get_fd(int fd)
3461 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3464 + files_struct *fsp = file_find_fd(fd);
3466 + if (fsp == NULL) {
3472 + * We know we're in the same conn context. So we
3473 + * can use the relative path.
3476 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3479 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3486 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3488 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3489 + && perm != SMB_ACL_EXECUTE) {
3494 + if (permset_d == NULL) {
3499 + *permset_d |= perm;
3504 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3506 + return *permset_d & perm;
3509 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3516 + * use an initial estimate of 20 bytes per ACL entry
3517 + * when allocating memory for the text representation
3521 + maxlen = 20 * acl_d->count;
3522 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3527 + for (i = 0; i < acl_d->count; i++) {
3528 + struct acl *ap = &acl_d->acl[i];
3537 + switch (ap->a_type) {
3539 + * for debugging purposes it's probably more
3540 + * useful to dump unknown tag types rather
3541 + * than just returning an error
3544 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3547 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3552 + case SMB_ACL_USER:
3553 + id = uidtoname(ap->a_id);
3554 + case SMB_ACL_USER_OBJ:
3558 + case SMB_ACL_GROUP:
3559 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3560 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3566 + case SMB_ACL_GROUP_OBJ:
3570 + case SMB_ACL_OTHER:
3574 + case SMB_ACL_MASK:
3580 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3581 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3582 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3585 + /* <tag> : <qualifier> : rwx \n \0 */
3586 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3589 + * If this entry would overflow the buffer
3590 + * allocate enough additional memory for this
3591 + * entry and an estimate of another 20 bytes
3592 + * for each entry still to be processed
3594 + if ((len + nbytes) > maxlen) {
3595 + char *oldtext = text;
3597 + maxlen += nbytes + 20 * (acl_d->count - i);
3599 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3606 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3607 + len += nbytes - 1;
3616 +SMB_ACL_T sys_acl_init(int count)
3626 + * note that since the definition of the structure pointed
3627 + * to by the SMB_ACL_T includes the first element of the
3628 + * acl[] array, this actually allocates an ACL with room
3629 + * for (count+1) entries
3631 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3636 + a->size = count + 1;
3644 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3647 + SMB_ACL_ENTRY_T entry_d;
3649 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3654 + if (acl_d->count >= acl_d->size) {
3659 + entry_d = &acl_d->acl[acl_d->count++];
3660 + entry_d->a_type = 0;
3661 + entry_d->a_id = -1;
3662 + entry_d->a_perm = 0;
3663 + *entry_p = entry_d;
3668 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3670 + switch (tag_type) {
3671 + case SMB_ACL_USER:
3672 + case SMB_ACL_USER_OBJ:
3673 + case SMB_ACL_GROUP:
3674 + case SMB_ACL_GROUP_OBJ:
3675 + case SMB_ACL_OTHER:
3676 + case SMB_ACL_MASK:
3677 + entry_d->a_type = tag_type;
3687 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3689 + if (entry_d->a_type != SMB_ACL_GROUP
3690 + && entry_d->a_type != SMB_ACL_USER) {
3695 + entry_d->a_id = *((id_t *)qual_p);
3700 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3702 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3706 + entry_d->a_perm = *permset_d;
3711 +/* Structure to capture the count for each type of ACE. */
3713 +struct hpux_acl_types {
3717 + int n_def_user_obj;
3722 + int n_def_group_obj;
3726 + int n_def_other_obj;
3729 + int n_def_class_obj;
3731 + int n_illegal_obj;
3735 + * Counts the different number of objects in a given array of ACL
3739 + * acl_count - Count of ACLs in the array of ACL strucutres.
3740 + * aclp - Array of ACL structures.
3741 + * acl_type_count - Pointer to acl_types structure. Should already be
3745 + * acl_type_count - This structure is filled up with counts of various
3749 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3753 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3755 + for(i=0;i<acl_count;i++) {
3756 + switch(aclp[i].a_type) {
3758 + acl_type_count->n_user++;
3761 + acl_type_count->n_user_obj++;
3763 + case DEF_USER_OBJ:
3764 + acl_type_count->n_def_user_obj++;
3767 + acl_type_count->n_group++;
3770 + acl_type_count->n_group_obj++;
3772 + case DEF_GROUP_OBJ:
3773 + acl_type_count->n_def_group_obj++;
3776 + acl_type_count->n_other_obj++;
3778 + case DEF_OTHER_OBJ:
3779 + acl_type_count->n_def_other_obj++;
3782 + acl_type_count->n_class_obj++;
3784 + case DEF_CLASS_OBJ:
3785 + acl_type_count->n_def_class_obj++;
3788 + acl_type_count->n_def_user++;
3791 + acl_type_count->n_def_group++;
3794 + acl_type_count->n_illegal_obj++;
3800 +/* swap_acl_entries: Swaps two ACL entries.
3802 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3805 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3807 + struct acl temp_acl;
3809 + temp_acl.a_type = aclp0->a_type;
3810 + temp_acl.a_id = aclp0->a_id;
3811 + temp_acl.a_perm = aclp0->a_perm;
3813 + aclp0->a_type = aclp1->a_type;
3814 + aclp0->a_id = aclp1->a_id;
3815 + aclp0->a_perm = aclp1->a_perm;
3817 + aclp1->a_type = temp_acl.a_type;
3818 + aclp1->a_id = temp_acl.a_id;
3819 + aclp1->a_perm = temp_acl.a_perm;
3822 +/* prohibited_duplicate_type
3823 + * Identifies if given ACL type can have duplicate entries or
3826 + * Inputs: acl_type - ACL Type.
3832 + * True - If the ACL type matches any of the prohibited types.
3833 + * False - If the ACL type doesn't match any of the prohibited types.
3836 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3838 + switch(acl_type) {
3849 +/* get_needed_class_perm
3850 + * Returns the permissions of a ACL structure only if the ACL
3851 + * type matches one of the pre-determined types for computing
3852 + * CLASS_OBJ permissions.
3854 + * Inputs: aclp - Pointer to ACL structure.
3857 +static int hpux_get_needed_class_perm(struct acl *aclp)
3859 + switch(aclp->a_type) {
3863 + case DEF_USER_OBJ:
3865 + case DEF_GROUP_OBJ:
3867 + case DEF_CLASS_OBJ:
3868 + case DEF_OTHER_OBJ:
3869 + return aclp->a_perm;
3875 +/* acl_sort for HPUX.
3876 + * Sorts the array of ACL structures as per the description in
3877 + * aclsort man page. Refer to aclsort man page for more details
3881 + * acl_count - Count of ACLs in the array of ACL structures.
3882 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3884 + * aclp - Array of ACL structures.
3888 + * aclp - Sorted array of ACL structures.
3892 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3893 + * debug log in case of failure.
3896 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3898 +#if !defined(HAVE_HPUX_ACLSORT)
3900 + * The aclsort() system call is availabe on the latest HPUX General
3901 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3902 + * function. Because, we don't want to update to a new
3903 + * HPUX GR bundle just for aclsort() call.
3906 + struct hpux_acl_types acl_obj_count;
3907 + int n_class_obj_perm = 0;
3911 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3915 + if(aclp == NULL) {
3916 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3920 + /* Count different types of ACLs in the ACLs array */
3922 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3924 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3925 + * CLASS_OBJ and OTHER_OBJ
3928 + if( (acl_obj_count.n_user_obj != 1) ||
3929 + (acl_obj_count.n_group_obj != 1) ||
3930 + (acl_obj_count.n_class_obj != 1) ||
3931 + (acl_obj_count.n_other_obj != 1)
3933 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3934 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3938 + /* If any of the default objects are present, there should be only
3939 + * one of them each.
3942 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3943 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3944 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3945 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3949 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3952 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3953 + * same ACL type, sort by ACL id.
3955 + * I am using the trival kind of sorting method here because, performance isn't
3956 + * really effected by the ACLs feature. More over there aren't going to be more
3957 + * than 17 entries on HPUX.
3960 + for(i=0; i<acl_count;i++) {
3961 + for (j=i+1; j<acl_count; j++) {
3962 + if( aclp[i].a_type > aclp[j].a_type ) {
3963 + /* ACL entries out of order, swap them */
3965 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3967 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3969 + /* ACL entries of same type, sort by id */
3971 + if(aclp[i].a_id > aclp[j].a_id) {
3972 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3973 + } else if (aclp[i].a_id == aclp[j].a_id) {
3974 + /* We have a duplicate entry. */
3975 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3976 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3977 + aclp[i].a_type, aclp[i].a_id));
3986 + /* set the class obj permissions to the computed one. */
3988 + int n_class_obj_index = -1;
3990 + for(i=0;i<acl_count;i++) {
3991 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3993 + if(aclp[i].a_type == CLASS_OBJ)
3994 + n_class_obj_index = i;
3996 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
4001 + return aclsort(acl_count, calclass, aclp);
4006 + * sort the ACL and check it for validity
4008 + * if it's a minimal ACL with only 4 entries then we
4009 + * need to recalculate the mask permissions to make
4010 + * sure that they are the same as the GROUP_OBJ
4011 + * permissions as required by the UnixWare acl() system call.
4013 + * (note: since POSIX allows minimal ACLs which only contain
4014 + * 3 entries - ie there is no mask entry - we should, in theory,
4015 + * check for this and add a mask entry if necessary - however
4016 + * we "know" that the caller of this interface always specifies
4017 + * a mask so, in practice "this never happens" (tm) - if it *does*
4018 + * happen aclsort() will fail and return an error and someone will
4019 + * have to fix it ...)
4022 +static int acl_sort(SMB_ACL_T acl_d)
4024 + int fixmask = (acl_d->count <= 4);
4026 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4033 +int sys_acl_valid(SMB_ACL_T acl_d)
4035 + return acl_sort(acl_d);
4038 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4041 + struct acl *acl_p;
4043 + struct acl *acl_buf = NULL;
4046 + if(hpux_acl_call_presence() == False) {
4047 + /* Looks like we don't have the acl() system call on HPUX.
4048 + * May be the system doesn't have the latest version of JFS.
4054 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4059 + if (acl_sort(acl_d) != 0) {
4063 + acl_p = &acl_d->acl[0];
4064 + acl_count = acl_d->count;
4067 + * if it's a directory there is extra work to do
4068 + * since the acl() system call will replace both
4069 + * the access ACLs and the default ACLs (if any)
4071 + if (stat(name, &s) != 0) {
4074 + if (S_ISDIR(s.st_mode)) {
4075 + SMB_ACL_T acc_acl;
4076 + SMB_ACL_T def_acl;
4077 + SMB_ACL_T tmp_acl;
4080 + if (type == SMB_ACL_TYPE_ACCESS) {
4082 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4086 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4089 + if (tmp_acl == NULL) {
4094 + * allocate a temporary buffer for the complete ACL
4096 + acl_count = acc_acl->count + def_acl->count;
4097 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4099 + if (acl_buf == NULL) {
4100 + sys_acl_free_acl(tmp_acl);
4106 + * copy the access control and default entries into the buffer
4108 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4109 + acc_acl->count * sizeof(acl_buf[0]));
4111 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4112 + def_acl->count * sizeof(acl_buf[0]));
4115 + * set the ACL_DEFAULT flag on the default entries
4117 + for (i = acc_acl->count; i < acl_count; i++) {
4118 + acl_buf[i].a_type |= ACL_DEFAULT;
4121 + sys_acl_free_acl(tmp_acl);
4123 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4128 + ret = acl(name, ACL_SET, acl_count, acl_p);
4137 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4140 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4143 + files_struct *fsp = file_find_fd(fd);
4145 + if (fsp == NULL) {
4150 + if (acl_sort(acl_d) != 0) {
4155 + * We know we're in the same conn context. So we
4156 + * can use the relative path.
4159 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4162 +int sys_acl_delete_def_file(const char *path)
4168 + * fetching the access ACL and rewriting it has
4169 + * the effect of deleting the default ACL
4171 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4175 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4177 + sys_acl_free_acl(acl_d);
4182 +int sys_acl_free_text(char *text)
4188 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4194 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4199 +#elif defined(HAVE_IRIX_ACLS)
4201 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4203 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4208 + if (entry_p == NULL) {
4213 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4217 + if (acl_d->next < 0) {
4222 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4226 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4231 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4233 + *type_p = entry_d->ae_tag;
4238 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4240 + *permset_p = entry_d;
4245 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4247 + if (entry_d->ae_tag != SMB_ACL_USER
4248 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4253 + return &entry_d->ae_id;
4256 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4260 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4264 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4269 + a->freeaclp = True;
4273 +SMB_ACL_T sys_acl_get_fd(int fd)
4277 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4281 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4286 + a->freeaclp = True;
4290 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4292 + permset_d->ae_perm = 0;
4297 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4299 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4300 + && perm != SMB_ACL_EXECUTE) {
4305 + if (permset_d == NULL) {
4310 + permset_d->ae_perm |= perm;
4315 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4317 + return permset_d->ae_perm & perm;
4320 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4322 + return acl_to_text(acl_d->aclp, len_p);
4325 +SMB_ACL_T sys_acl_init(int count)
4334 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4340 + a->freeaclp = False;
4341 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4342 + a->aclp->acl_cnt = 0;
4348 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4351 + SMB_ACL_ENTRY_T entry_d;
4353 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4358 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4363 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4364 + entry_d->ae_tag = 0;
4365 + entry_d->ae_id = 0;
4366 + entry_d->ae_perm = 0;
4367 + *entry_p = entry_d;
4372 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4374 + switch (tag_type) {
4375 + case SMB_ACL_USER:
4376 + case SMB_ACL_USER_OBJ:
4377 + case SMB_ACL_GROUP:
4378 + case SMB_ACL_GROUP_OBJ:
4379 + case SMB_ACL_OTHER:
4380 + case SMB_ACL_MASK:
4381 + entry_d->ae_tag = tag_type;
4391 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4393 + if (entry_d->ae_tag != SMB_ACL_GROUP
4394 + && entry_d->ae_tag != SMB_ACL_USER) {
4399 + entry_d->ae_id = *((id_t *)qual_p);
4404 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4406 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4410 + entry_d->ae_perm = permset_d->ae_perm;
4415 +int sys_acl_valid(SMB_ACL_T acl_d)
4417 + return acl_valid(acl_d->aclp);
4420 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4422 + return acl_set_file(name, type, acl_d->aclp);
4425 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4427 + return acl_set_fd(fd, acl_d->aclp);
4430 +int sys_acl_delete_def_file(const char *name)
4432 + return acl_delete_def_file(name);
4435 +int sys_acl_free_text(char *text)
4437 + return acl_free(text);
4440 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4442 + if (acl_d->freeaclp) {
4443 + acl_free(acl_d->aclp);
4449 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4454 +#elif defined(HAVE_AIX_ACLS)
4456 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4458 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4460 + struct acl_entry_link *link;
4461 + struct new_acl_entry *entry;
4464 + DEBUG(10,("This is the count: %d\n",theacl->count));
4466 + /* Check if count was previously set to -1. *
4467 + * If it was, that means we reached the end *
4468 + * of the acl last time. */
4469 + if(theacl->count == -1)
4473 + /* To get to the next acl, traverse linked list until index *
4474 + * of acl matches the count we are keeping. This count is *
4475 + * incremented each time we return an acl entry. */
4477 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4478 + link = link->nextp;
4480 + entry = *entry_p = link->entryp;
4482 + DEBUG(10,("*entry_p is %d\n",entry_p));
4483 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4485 + /* Increment count */
4487 + if(link->nextp == NULL)
4488 + theacl->count = -1;
4493 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4495 + /* Initialize tag type */
4498 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4500 + /* Depending on what type of entry we have, *
4501 + * return tag type. */
4502 + switch(entry_d->ace_id->id_type) {
4504 + *tag_type_p = SMB_ACL_USER;
4507 + *tag_type_p = SMB_ACL_GROUP;
4510 + case SMB_ACL_USER_OBJ:
4511 + case SMB_ACL_GROUP_OBJ:
4512 + case SMB_ACL_OTHER:
4513 + *tag_type_p = entry_d->ace_id->id_type;
4523 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4525 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4526 + *permset_p = &entry_d->ace_access;
4527 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4528 + if(!(**permset_p & S_IXUSR) &&
4529 + !(**permset_p & S_IWUSR) &&
4530 + !(**permset_p & S_IRUSR) &&
4531 + (**permset_p != 0))
4534 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4538 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4540 + return(entry_d->ace_id->id_data);
4543 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4545 + struct acl *file_acl = (struct acl *)NULL;
4546 + struct acl_entry *acl_entry;
4547 + struct new_acl_entry *new_acl_entry;
4548 + struct ace_id *idp;
4549 + struct acl_entry_link *acl_entry_link;
4550 + struct acl_entry_link *acl_entry_link_head;
4555 + /* AIX has no DEFAULT */
4556 + if ( type == SMB_ACL_TYPE_DEFAULT )
4559 + /* Get the acl using statacl */
4561 + DEBUG(10,("Entering sys_acl_get_file\n"));
4562 + DEBUG(10,("path_p is %s\n",path_p));
4564 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4566 + if(file_acl == NULL) {
4568 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4572 + memset(file_acl,0,BUFSIZ);
4574 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4576 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4577 + SAFE_FREE(file_acl);
4581 + DEBUG(10,("Got facl and returned it\n"));
4583 + /* Point to the first acl entry in the acl */
4584 + acl_entry = file_acl->acl_ext;
4586 + /* Begin setting up the head of the linked list *
4587 + * that will be used for the storing the acl *
4588 + * in a way that is useful for the posix_acls.c *
4591 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4592 + if(acl_entry_link_head == NULL)
4595 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4596 + if(acl_entry_link->entryp == NULL) {
4597 + SAFE_FREE(file_acl);
4599 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4603 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4604 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4606 + /* Check if the extended acl bit is on. *
4607 + * If it isn't, do not show the *
4608 + * contents of the acl since AIX intends *
4609 + * the extended info to remain unused */
4611 + if(file_acl->acl_mode & S_IXACL){
4612 + /* while we are not pointing to the very end */
4613 + while(acl_entry < acl_last(file_acl)) {
4614 + /* before we malloc anything, make sure this is */
4615 + /* a valid acl entry and one that we want to map */
4616 + idp = id_nxt(acl_entry->ace_id);
4617 + if((acl_entry->ace_type == ACC_SPECIFY ||
4618 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4619 + acl_entry = acl_nxt(acl_entry);
4623 + idp = acl_entry->ace_id;
4625 + /* Check if this is the first entry in the linked list. *
4626 + * The first entry needs to keep prevp pointing to NULL *
4627 + * and already has entryp allocated. */
4629 + if(acl_entry_link_head->count != 0) {
4630 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4632 + if(acl_entry_link->nextp == NULL) {
4633 + SAFE_FREE(file_acl);
4635 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4639 + acl_entry_link->nextp->prevp = acl_entry_link;
4640 + acl_entry_link = acl_entry_link->nextp;
4641 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4642 + if(acl_entry_link->entryp == NULL) {
4643 + SAFE_FREE(file_acl);
4645 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4648 + acl_entry_link->nextp = NULL;
4651 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4653 + /* Don't really need this since all types are going *
4654 + * to be specified but, it's better than leaving it 0 */
4656 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4658 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4660 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4662 + /* The access in the acl entries must be left shifted by *
4663 + * three bites, because they will ultimately be compared *
4664 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4666 + switch(acl_entry->ace_type){
4669 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4670 + acl_entry_link->entryp->ace_access <<= 6;
4671 + acl_entry_link_head->count++;
4674 + /* Since there is no way to return a DENY acl entry *
4675 + * change to PERMIT and then shift. */
4676 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4677 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4678 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4679 + acl_entry_link->entryp->ace_access <<= 6;
4680 + acl_entry_link_head->count++;
4686 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4687 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4689 + acl_entry = acl_nxt(acl_entry);
4691 + } /* end of if enabled */
4693 + /* Since owner, group, other acl entries are not *
4694 + * part of the acl entries in an acl, they must *
4695 + * be dummied up to become part of the list. */
4697 + for( i = 1; i < 4; i++) {
4698 + DEBUG(10,("i is %d\n",i));
4699 + if(acl_entry_link_head->count != 0) {
4700 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4701 + if(acl_entry_link->nextp == NULL) {
4702 + SAFE_FREE(file_acl);
4704 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4708 + acl_entry_link->nextp->prevp = acl_entry_link;
4709 + acl_entry_link = acl_entry_link->nextp;
4710 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4711 + if(acl_entry_link->entryp == NULL) {
4712 + SAFE_FREE(file_acl);
4714 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4719 + acl_entry_link->nextp = NULL;
4721 + new_acl_entry = acl_entry_link->entryp;
4722 + idp = new_acl_entry->ace_id;
4724 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4725 + new_acl_entry->ace_type = ACC_PERMIT;
4726 + idp->id_len = sizeof(struct ace_id);
4727 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4728 + memset(idp->id_data,0,sizeof(uid_t));
4732 + new_acl_entry->ace_access = file_acl->g_access << 6;
4733 + idp->id_type = SMB_ACL_GROUP_OBJ;
4737 + new_acl_entry->ace_access = file_acl->o_access << 6;
4738 + idp->id_type = SMB_ACL_OTHER;
4742 + new_acl_entry->ace_access = file_acl->u_access << 6;
4743 + idp->id_type = SMB_ACL_USER_OBJ;
4751 + acl_entry_link_head->count++;
4752 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4755 + acl_entry_link_head->count = 0;
4756 + SAFE_FREE(file_acl);
4758 + return(acl_entry_link_head);
4761 +SMB_ACL_T sys_acl_get_fd(int fd)
4763 + struct acl *file_acl = (struct acl *)NULL;
4764 + struct acl_entry *acl_entry;
4765 + struct new_acl_entry *new_acl_entry;
4766 + struct ace_id *idp;
4767 + struct acl_entry_link *acl_entry_link;
4768 + struct acl_entry_link *acl_entry_link_head;
4773 + /* Get the acl using fstatacl */
4775 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4776 + DEBUG(10,("fd is %d\n",fd));
4777 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4779 + if(file_acl == NULL) {
4781 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4785 + memset(file_acl,0,BUFSIZ);
4787 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4789 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4790 + SAFE_FREE(file_acl);
4794 + DEBUG(10,("Got facl and returned it\n"));
4796 + /* Point to the first acl entry in the acl */
4798 + acl_entry = file_acl->acl_ext;
4799 + /* Begin setting up the head of the linked list *
4800 + * that will be used for the storing the acl *
4801 + * in a way that is useful for the posix_acls.c *
4804 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4805 + if(acl_entry_link_head == NULL){
4806 + SAFE_FREE(file_acl);
4810 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4812 + if(acl_entry_link->entryp == NULL) {
4814 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4815 + SAFE_FREE(file_acl);
4819 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4820 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4822 + /* Check if the extended acl bit is on. *
4823 + * If it isn't, do not show the *
4824 + * contents of the acl since AIX intends *
4825 + * the extended info to remain unused */
4827 + if(file_acl->acl_mode & S_IXACL){
4828 + /* while we are not pointing to the very end */
4829 + while(acl_entry < acl_last(file_acl)) {
4830 + /* before we malloc anything, make sure this is */
4831 + /* a valid acl entry and one that we want to map */
4833 + idp = id_nxt(acl_entry->ace_id);
4834 + if((acl_entry->ace_type == ACC_SPECIFY ||
4835 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4836 + acl_entry = acl_nxt(acl_entry);
4840 + idp = acl_entry->ace_id;
4842 + /* Check if this is the first entry in the linked list. *
4843 + * The first entry needs to keep prevp pointing to NULL *
4844 + * and already has entryp allocated. */
4846 + if(acl_entry_link_head->count != 0) {
4847 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4848 + if(acl_entry_link->nextp == NULL) {
4850 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4851 + SAFE_FREE(file_acl);
4854 + acl_entry_link->nextp->prevp = acl_entry_link;
4855 + acl_entry_link = acl_entry_link->nextp;
4856 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4857 + if(acl_entry_link->entryp == NULL) {
4859 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4860 + SAFE_FREE(file_acl);
4864 + acl_entry_link->nextp = NULL;
4867 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4869 + /* Don't really need this since all types are going *
4870 + * to be specified but, it's better than leaving it 0 */
4872 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4873 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4875 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4877 + /* The access in the acl entries must be left shifted by *
4878 + * three bites, because they will ultimately be compared *
4879 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4881 + switch(acl_entry->ace_type){
4884 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4885 + acl_entry_link->entryp->ace_access <<= 6;
4886 + acl_entry_link_head->count++;
4889 + /* Since there is no way to return a DENY acl entry *
4890 + * change to PERMIT and then shift. */
4891 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4892 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4893 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4894 + acl_entry_link->entryp->ace_access <<= 6;
4895 + acl_entry_link_head->count++;
4901 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4902 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4904 + acl_entry = acl_nxt(acl_entry);
4906 + } /* end of if enabled */
4908 + /* Since owner, group, other acl entries are not *
4909 + * part of the acl entries in an acl, they must *
4910 + * be dummied up to become part of the list. */
4912 + for( i = 1; i < 4; i++) {
4913 + DEBUG(10,("i is %d\n",i));
4914 + if(acl_entry_link_head->count != 0){
4915 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4916 + if(acl_entry_link->nextp == NULL) {
4918 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4919 + SAFE_FREE(file_acl);
4923 + acl_entry_link->nextp->prevp = acl_entry_link;
4924 + acl_entry_link = acl_entry_link->nextp;
4925 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4927 + if(acl_entry_link->entryp == NULL) {
4928 + SAFE_FREE(file_acl);
4930 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4935 + acl_entry_link->nextp = NULL;
4937 + new_acl_entry = acl_entry_link->entryp;
4938 + idp = new_acl_entry->ace_id;
4940 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4941 + new_acl_entry->ace_type = ACC_PERMIT;
4942 + idp->id_len = sizeof(struct ace_id);
4943 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4944 + memset(idp->id_data,0,sizeof(uid_t));
4948 + new_acl_entry->ace_access = file_acl->g_access << 6;
4949 + idp->id_type = SMB_ACL_GROUP_OBJ;
4953 + new_acl_entry->ace_access = file_acl->o_access << 6;
4954 + idp->id_type = SMB_ACL_OTHER;
4958 + new_acl_entry->ace_access = file_acl->u_access << 6;
4959 + idp->id_type = SMB_ACL_USER_OBJ;
4966 + acl_entry_link_head->count++;
4967 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4970 + acl_entry_link_head->count = 0;
4971 + SAFE_FREE(file_acl);
4973 + return(acl_entry_link_head);
4976 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4978 + *permset = *permset & ~0777;
4982 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4985 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4989 + DEBUG(10,("This is the permset now: %d\n",*permset));
4993 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4998 +SMB_ACL_T sys_acl_init( int count)
5000 + struct acl_entry_link *theacl = NULL;
5002 + DEBUG(10,("Entering sys_acl_init\n"));
5004 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5005 + if(theacl == NULL) {
5007 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5011 + theacl->count = 0;
5012 + theacl->nextp = NULL;
5013 + theacl->prevp = NULL;
5014 + theacl->entryp = NULL;
5015 + DEBUG(10,("Exiting sys_acl_init\n"));
5019 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5021 + struct acl_entry_link *theacl;
5022 + struct acl_entry_link *acl_entryp;
5023 + struct acl_entry_link *temp_entry;
5026 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5028 + theacl = acl_entryp = *pacl;
5030 + /* Get to the end of the acl before adding entry */
5032 + for(counting=0; counting < theacl->count; counting++){
5033 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5034 + temp_entry = acl_entryp;
5035 + acl_entryp = acl_entryp->nextp;
5038 + if(theacl->count != 0){
5039 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5040 + if(acl_entryp == NULL) {
5042 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5046 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5047 + acl_entryp->prevp = temp_entry;
5048 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5051 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5052 + if(*pentry == NULL) {
5054 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5058 + memset(*pentry,0,sizeof(struct new_acl_entry));
5059 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5060 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5061 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5062 + acl_entryp->nextp = NULL;
5064 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5068 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5070 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5071 + entry->ace_id->id_type = tagtype;
5072 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5073 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5076 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5078 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5079 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5080 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5084 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5086 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5087 + if(!(*permset & S_IXUSR) &&
5088 + !(*permset & S_IWUSR) &&
5089 + !(*permset & S_IRUSR) &&
5093 + entry->ace_access = *permset;
5094 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5095 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5099 +int sys_acl_valid( SMB_ACL_T theacl )
5102 + int group_obj = 0;
5103 + int other_obj = 0;
5104 + struct acl_entry_link *acl_entry;
5106 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5107 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5108 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5109 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5112 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5114 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5120 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5122 + struct acl_entry_link *acl_entry_link = NULL;
5123 + struct acl *file_acl = NULL;
5124 + struct acl *file_acl_temp = NULL;
5125 + struct acl_entry *acl_entry = NULL;
5126 + struct ace_id *ace_id = NULL;
5133 + DEBUG(10,("Entering sys_acl_set_file\n"));
5134 + DEBUG(10,("File name is %s\n",name));
5136 + /* AIX has no default ACL */
5137 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5140 + acl_length = BUFSIZ;
5141 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5143 + if(file_acl == NULL) {
5145 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5149 + memset(file_acl,0,BUFSIZ);
5151 + file_acl->acl_len = ACL_SIZ;
5152 + file_acl->acl_mode = S_IXACL;
5154 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5155 + acl_entry_link->entryp->ace_access >>= 6;
5156 + id_type = acl_entry_link->entryp->ace_id->id_type;
5159 + case SMB_ACL_USER_OBJ:
5160 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5162 + case SMB_ACL_GROUP_OBJ:
5163 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5165 + case SMB_ACL_OTHER:
5166 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5168 + case SMB_ACL_MASK:
5172 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5173 + acl_length += sizeof(struct acl_entry);
5174 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5175 + if(file_acl_temp == NULL) {
5176 + SAFE_FREE(file_acl);
5178 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5182 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5183 + SAFE_FREE(file_acl);
5184 + file_acl = file_acl_temp;
5187 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5188 + file_acl->acl_len += sizeof(struct acl_entry);
5189 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5190 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5192 + /* In order to use this, we'll need to wait until we can get denies */
5193 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5194 + acl_entry->ace_type = ACC_SPECIFY; */
5196 + acl_entry->ace_type = ACC_SPECIFY;
5198 + ace_id = acl_entry->ace_id;
5200 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5201 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5202 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5203 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5204 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5207 + rc = chacl(name,file_acl,file_acl->acl_len);
5208 + DEBUG(10,("errno is %d\n",errno));
5209 + DEBUG(10,("return code is %d\n",rc));
5210 + SAFE_FREE(file_acl);
5211 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5215 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5217 + struct acl_entry_link *acl_entry_link = NULL;
5218 + struct acl *file_acl = NULL;
5219 + struct acl *file_acl_temp = NULL;
5220 + struct acl_entry *acl_entry = NULL;
5221 + struct ace_id *ace_id = NULL;
5227 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5228 + acl_length = BUFSIZ;
5229 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5231 + if(file_acl == NULL) {
5233 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5237 + memset(file_acl,0,BUFSIZ);
5239 + file_acl->acl_len = ACL_SIZ;
5240 + file_acl->acl_mode = S_IXACL;
5242 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5243 + acl_entry_link->entryp->ace_access >>= 6;
5244 + id_type = acl_entry_link->entryp->ace_id->id_type;
5245 + DEBUG(10,("The id_type is %d\n",id_type));
5248 + case SMB_ACL_USER_OBJ:
5249 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5251 + case SMB_ACL_GROUP_OBJ:
5252 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5254 + case SMB_ACL_OTHER:
5255 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5257 + case SMB_ACL_MASK:
5261 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5262 + acl_length += sizeof(struct acl_entry);
5263 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5264 + if(file_acl_temp == NULL) {
5265 + SAFE_FREE(file_acl);
5267 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5271 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5272 + SAFE_FREE(file_acl);
5273 + file_acl = file_acl_temp;
5276 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5277 + file_acl->acl_len += sizeof(struct acl_entry);
5278 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5279 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5281 + /* In order to use this, we'll need to wait until we can get denies */
5282 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5283 + acl_entry->ace_type = ACC_SPECIFY; */
5285 + acl_entry->ace_type = ACC_SPECIFY;
5287 + ace_id = acl_entry->ace_id;
5289 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5290 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5291 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5292 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5293 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5296 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5297 + DEBUG(10,("errno is %d\n",errno));
5298 + DEBUG(10,("return code is %d\n",rc));
5299 + SAFE_FREE(file_acl);
5300 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5304 +int sys_acl_delete_def_file(const char *name)
5306 + /* AIX has no default ACL */
5310 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5312 + return(*permset & perm);
5315 +int sys_acl_free_text(char *text)
5320 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5322 + struct acl_entry_link *acl_entry_link;
5324 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5325 + SAFE_FREE(acl_entry_link->prevp->entryp);
5326 + SAFE_FREE(acl_entry_link->prevp);
5329 + SAFE_FREE(acl_entry_link->prevp->entryp);
5330 + SAFE_FREE(acl_entry_link->prevp);
5331 + SAFE_FREE(acl_entry_link->entryp);
5332 + SAFE_FREE(acl_entry_link);
5337 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5342 +#else /* No ACLs. */
5344 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5350 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5356 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5362 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5368 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5371 + return (SMB_ACL_T)NULL;
5374 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5377 + return (SMB_ACL_T)NULL;
5380 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5386 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5392 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5395 + return (permset & perm) ? 1 : 0;
5398 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5404 +int sys_acl_free_text(UNUSED(char *text))
5410 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5416 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5422 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5428 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5434 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5440 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5446 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5452 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5458 +int sys_acl_delete_def_file(UNUSED(const char *name))
5464 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5470 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5476 +#endif /* No ACLs. */
5478 +/************************************************************************
5479 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5481 +************************************************************************/
5483 +int no_acl_syscall_error(int err)
5485 +#if defined(ENOSYS)
5486 + if (err == ENOSYS) {
5490 +#if defined(ENOTSUP)
5491 + if (err == ENOTSUP) {
5497 --- old/lib/sysacls.h
5498 +++ new/lib/sysacls.h
5500 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5501 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5502 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5503 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5504 +#define slprintf snprintf
5506 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5507 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5508 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5509 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5510 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5511 +SMB_ACL_T sys_acl_get_fd(int fd);
5512 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5513 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5514 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5515 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5516 +SMB_ACL_T sys_acl_init(int count);
5517 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5518 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5519 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5520 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5521 +int sys_acl_valid(SMB_ACL_T theacl);
5522 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5523 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5524 +int sys_acl_delete_def_file(const char *name);
5525 +int sys_acl_free_text(char *text);
5526 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5527 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5530 @@ -603,8 +603,10 @@ static void log_formatted(enum logcode c
5531 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5532 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5533 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5536 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5537 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5538 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5541 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5542 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5545 @@ -58,7 +58,7 @@ BEGIN {
5549 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5550 +!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5556 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5558 int preserve_links = 0;
5559 int preserve_hard_links = 0;
5560 +int preserve_acls = 0;
5561 int preserve_perms = 0;
5562 int preserve_executability = 0;
5563 int preserve_devices = 0;
5564 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
5565 char const *got_socketpair = "no ";
5566 char const *have_inplace = "no ";
5567 char const *hardlinks = "no ";
5568 + char const *acls = "no ";
5569 char const *links = "no ";
5570 char const *ipv6 = "no ";
5571 STRUCT_STAT *dumstat;
5572 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
5576 +#ifdef SUPPORT_ACLS
5580 #ifdef SUPPORT_LINKS
5583 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
5584 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5585 rprintf(f, "<http://rsync.samba.org/>\n");
5586 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5587 - "%shard links, %ssymlinks, batchfiles,\n",
5588 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
5589 (int) (sizeof (OFF_T) * 8),
5590 - got_socketpair, hardlinks, links);
5591 + got_socketpair, hardlinks, acls, links);
5593 /* Note that this field may not have type ino_t. It depends
5594 * on the complicated interaction between largefile feature
5595 @@ -295,6 +301,9 @@ void usage(enum logcode F)
5596 rprintf(F," -H, --hard-links preserve hard links\n");
5597 rprintf(F," -p, --perms preserve permissions\n");
5598 rprintf(F," -E, --executability preserve the file's executability\n");
5599 +#ifdef SUPPORT_ACLS
5600 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5602 rprintf(F," --chmod=CHMOD change destination permissions\n");
5603 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5604 rprintf(F," -g, --group preserve group\n");
5605 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
5606 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5607 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5608 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5609 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5610 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5611 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5612 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5613 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5614 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5615 @@ -1070,6 +1082,24 @@ int parse_arguments(int *argc, const cha
5620 +#ifdef SUPPORT_ACLS
5622 + preserve_perms = 1;
5625 + /* FIXME: this should probably be ignored with a
5626 + * warning and then countermeasures taken to
5627 + * restrict group and other access in the presence
5628 + * of any more restrictive ACLs, but this is safe
5630 + snprintf(err_buf,sizeof(err_buf),
5631 + "ACLs are not supported on this %s\n",
5632 + am_server ? "server" : "client");
5638 /* A large opt value means that set_refuse_options()
5639 * turned this option off. */
5640 @@ -1504,6 +1534,10 @@ void server_options(char **args,int *arg
5642 if (preserve_hard_links)
5644 +#ifdef SUPPORT_ACLS
5645 + if (preserve_acls)
5646 + argstr[x++] = 'A';
5653 @@ -48,6 +48,7 @@ extern int keep_partial;
5654 extern int checksum_seed;
5656 extern int delay_updates;
5657 +extern mode_t orig_umask;
5658 extern struct stats stats;
5659 extern char *log_format;
5660 extern char *tmpdir;
5661 @@ -346,6 +347,10 @@ int recv_files(int f_in, struct file_lis
5662 int itemizing = am_daemon ? daemon_log_format_has_i
5663 : !am_server && log_format_has_i;
5664 int max_phase = protocol_version >= 29 ? 2 : 1;
5665 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5666 +#ifdef SUPPORT_ACLS
5667 + char *parent_dirname = "";
5672 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5673 * mode based on the local permissions and some heuristics. */
5674 if (!preserve_perms) {
5675 int exists = fd1 != -1;
5676 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5677 +#ifdef SUPPORT_ACLS
5678 + char *dn = file->dirname ? file->dirname : ".";
5679 + if (parent_dirname != dn
5680 + && strcmp(parent_dirname, dn) != 0) {
5681 + dflt_perms = default_perms_for_dir(dn);
5682 + parent_dirname = dn;
5685 + file->mode = dest_mode(file->mode, st.st_mode,
5686 + dflt_perms, exists);
5689 /* We now check to see if we are writing file "inplace" */
5695 extern int daemon_log_format_has_i;
5696 +extern int preserve_acls;
5697 extern int preserve_perms;
5698 extern int preserve_executability;
5699 extern int preserve_times;
5700 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5702 /* This is only called when we aren't preserving permissions. Figure out what
5703 * the permissions should be and return them merged back into the mode. */
5704 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5705 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5708 /* If the file already exists, we'll return the local permissions,
5709 * possibly tweaked by the --executability option. */
5710 @@ -116,55 +118,63 @@ mode_t dest_mode(mode_t flist_mode, mode
5711 cur_mode |= (cur_mode & 0444) >> 2;
5714 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5715 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5716 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5717 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5718 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5721 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5722 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5728 int change_uid, change_gid;
5734 - if (link_stat(fname, &st2, 0) < 0) {
5735 + if (link_stat(fname, &sx2.st, 0) < 0) {
5736 rsyserr(FERROR, errno, "stat %s failed",
5741 +#ifdef SUPPORT_ACLS
5742 + sx2.acc_acl = sx2.def_acl = NULL;
5744 if (!preserve_perms && S_ISDIR(file->mode)
5745 - && st->st_mode & S_ISGID) {
5746 + && sx2.st.st_mode & S_ISGID) {
5747 /* We just created this directory and its setgid
5748 * bit is on, so make sure it stays on. */
5749 file->mode |= S_ISGID;
5754 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5755 +#ifdef SUPPORT_ACLS
5756 + if (preserve_acls && !ACL_READY(*sxp))
5757 + get_acls(fname, sxp);
5760 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5761 flags |= ATTRS_SKIP_MTIME;
5762 if (!(flags & ATTRS_SKIP_MTIME)
5763 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5764 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5765 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5766 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5768 rsyserr(FERROR, errno, "failed to set times on %s",
5773 if (ret == 0) /* ret == 1 if symlink could not be set */
5777 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5778 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5779 change_gid = preserve_gid && file->gid != GID_NONE
5780 - && st->st_gid != file->gid;
5781 + && sxp->st.st_gid != file->gid;
5782 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5783 - if (S_ISLNK(st->st_mode))
5784 + if (S_ISLNK(sxp->st.st_mode))
5788 @@ -174,43 +184,55 @@ int set_file_attrs(char *fname, struct f
5790 "set uid of %s from %ld to %ld\n",
5792 - (long)st->st_uid, (long)file->uid);
5793 + (long)sxp->st.st_uid, (long)file->uid);
5797 "set gid of %s from %ld to %ld\n",
5799 - (long)st->st_gid, (long)file->gid);
5800 + (long)sxp->st.st_gid, (long)file->gid);
5803 if (do_lchown(fname,
5804 - change_uid ? file->uid : st->st_uid,
5805 - change_gid ? file->gid : st->st_gid) != 0) {
5806 + change_uid ? file->uid : sxp->st.st_uid,
5807 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5808 /* shouldn't have attempted to change uid or gid
5809 * unless have the privilege */
5810 rsyserr(FERROR, errno, "%s %s failed",
5811 change_uid ? "chown" : "chgrp",
5816 /* a lchown had been done - we have to re-stat if the
5817 * destination had the setuid or setgid bits set due
5818 * to the side effect of the chown call */
5819 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5820 - link_stat(fname, st,
5821 - keep_dirlinks && S_ISDIR(st->st_mode));
5822 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5823 + link_stat(fname, &sxp->st,
5824 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5829 +#ifdef SUPPORT_ACLS
5830 + /* It's OK to call set_acls() now, even for a dir, as the generator
5831 + * will enable owner-writability using chmod, if necessary.
5833 + * If set_acl changes permission bits in the process of setting
5834 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5835 + * need to chmod. */
5836 + if (preserve_acls && set_acls(fname, file, sxp) == 0)
5841 - if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5842 - int ret = do_chmod(fname, file->mode);
5843 + if ((sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5844 + mode_t mode = file->mode;
5845 + int ret = do_chmod(fname, mode);
5847 rsyserr(FERROR, errno,
5848 "failed to set permissions on %s",
5853 if (ret == 0) /* ret == 1 if symlink could not be set */
5855 @@ -225,6 +247,11 @@ int set_file_attrs(char *fname, struct f
5857 rprintf(code, "%s is uptodate\n", fname);
5860 +#ifdef SUPPORT_ACLS
5861 + if (preserve_acls && sxp == &sx2)
5869 @@ -485,6 +485,15 @@ struct idev {
5870 #define IN_LOOPBACKNET 127
5873 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5874 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5875 +#define SUPPORT_ACLS 1
5878 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5879 +#define ACLS_NEED_MASK 1
5882 #define GID_NONE ((gid_t)-1)
5884 #define HL_CHECK_MASTER 0
5885 @@ -645,6 +654,17 @@ struct stats {
5887 struct chmod_mode_struct;
5889 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5897 +#define EXPAND_ITEM_LIST(lp, type, fast) \
5898 + (type*)expand_item_list(lp, sizeof (type), #type, fast)
5900 #include "byteorder.h"
5901 #include "lib/mdfour.h"
5902 #include "lib/wildmatch.h"
5903 @@ -660,6 +680,21 @@ struct chmod_mode_struct;
5905 #define UNUSED(x) x __attribute__((__unused__))
5907 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5908 +#include <sys/acl.h>
5910 +#include "smb_acls.h"
5914 +#ifdef SUPPORT_ACLS
5915 + struct rsync_acl *acc_acl; /* access ACL */
5916 + struct rsync_acl *def_acl; /* default ACL */
5920 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5924 /* We have replacement versions of these if they're missing. */
5927 @@ -321,6 +321,7 @@ to the detailed description below for a
5928 -H, --hard-links preserve hard links
5929 -p, --perms preserve permissions
5930 -E, --executability preserve executability
5931 + -A, --acls preserve ACLs (implies -p) [non-standard]
5932 --chmod=CHMOD change destination permissions
5933 -o, --owner preserve owner (super-user only)
5934 -g, --group preserve group
5935 @@ -742,7 +743,9 @@ quote(itemize(
5936 permissions, though the bf(--executability) option might change just
5937 the execute permission for the file.
5938 it() New files get their "normal" permission bits set to the source
5939 - file's permissions masked with the receiving end's umask setting, and
5940 + file's permissions masked with the receiving directory's default
5941 + permissions (either the receiving process's umask, or the permissions
5942 + specified via the destination directory's default ACL), and
5943 their special permission bits disabled except in the case where a new
5944 directory inherits a setgid bit from its parent directory.
5946 @@ -773,9 +776,11 @@ The preservation of the destination's se
5947 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5948 versions erroneously preserved the three special permission bits for
5949 newly-created files when bf(--perms) was off, while overriding the
5950 -destination's setgid bit setting on a newly-created directory. (Keep in
5951 -mind that it is the version of the receiving rsync that affects this
5953 +destination's setgid bit setting on a newly-created directory. Default ACL
5954 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5955 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5956 +(Keep in mind that it is the version of the receiving rsync that affects
5959 dit(bf(-E, --executability)) This option causes rsync to preserve the
5960 executability (or non-executability) of regular files when bf(--perms) is
5961 @@ -793,6 +798,15 @@ quote(itemize(
5963 If bf(--perms) is enabled, this option is ignored.
5965 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5966 +ACLs to be the same as the source ACLs. This nonstandard option only
5967 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5969 +Note also that an optimization of the ACL-sending protocol used by this
5970 +version makes it incompatible with sending files to an older ACL-enabled
5971 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5972 +doubling is not needed when pulling files from an older rsync.
5974 dit(bf(--chmod)) This option tells rsync to apply one or more
5975 comma-separated "chmod" strings to the permission of the files in the
5976 transfer. The resulting value is treated as though it was the permissions
5977 @@ -1372,8 +1386,8 @@ if the receiving rsync is at least versi
5978 with older versions of rsync, but that also turns on the output of other
5981 -The "%i" escape has a cryptic output that is 9 letters long. The general
5982 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
5983 +The "%i" escape has a cryptic output that is 11 letters long. The general
5984 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
5985 type of update being done, bf(X) is replaced by the file-type, and the
5986 other letters represent attributes that may be output if they are being
5988 @@ -1422,7 +1436,11 @@ quote(itemize(
5989 sender's value (requires bf(--owner) and super-user privileges).
5990 it() A bf(g) means the group is different and is being updated to the
5991 sender's value (requires bf(--group) and the authority to set the group).
5992 - it() The bf(z) slot is reserved for future use.
5993 + it() The bf(u) slot is reserved for reporting update (access) time changes
5994 + (a feature that is not yet released).
5995 + it() The bf(a) means that the ACL information changed.
5996 + it() The bf(x) slot is reserved for reporting extended attribute changes
5997 + (a feature that is not yet released).
6000 One other output is possible: when deleting files, the "%i" will output
6005 + Unix SMB/Netbios implementation.
6007 + Portable SMB ACL interface
6008 + Copyright (C) Jeremy Allison 2000
6010 + This program is free software; you can redistribute it and/or modify
6011 + it under the terms of the GNU General Public License as published by
6012 + the Free Software Foundation; either version 2 of the License, or
6013 + (at your option) any later version.
6015 + This program is distributed in the hope that it will be useful,
6016 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6017 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6018 + GNU General Public License for more details.
6020 + You should have received a copy of the GNU General Public License
6021 + along with this program; if not, write to the Free Software
6022 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6025 +#ifndef _SMB_ACLS_H
6026 +#define _SMB_ACLS_H
6028 +#if defined HAVE_POSIX_ACLS
6030 +/* This is an identity mapping (just remove the SMB_). */
6032 +#define SMB_ACL_TAG_T acl_tag_t
6033 +#define SMB_ACL_TYPE_T acl_type_t
6034 +#define SMB_ACL_PERMSET_T acl_permset_t
6035 +#define SMB_ACL_PERM_T acl_perm_t
6036 +#define SMB_ACL_READ ACL_READ
6037 +#define SMB_ACL_WRITE ACL_WRITE
6038 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6040 +/* Types of ACLs. */
6041 +#define SMB_ACL_USER ACL_USER
6042 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6043 +#define SMB_ACL_GROUP ACL_GROUP
6044 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6045 +#define SMB_ACL_OTHER ACL_OTHER
6046 +#define SMB_ACL_MASK ACL_MASK
6048 +#define SMB_ACL_T acl_t
6050 +#define SMB_ACL_ENTRY_T acl_entry_t
6052 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6053 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6055 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6056 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6058 +#elif defined HAVE_TRU64_ACLS
6060 +/* This is for DEC/Compaq Tru64 UNIX */
6062 +#define SMB_ACL_TAG_T acl_tag_t
6063 +#define SMB_ACL_TYPE_T acl_type_t
6064 +#define SMB_ACL_PERMSET_T acl_permset_t
6065 +#define SMB_ACL_PERM_T acl_perm_t
6066 +#define SMB_ACL_READ ACL_READ
6067 +#define SMB_ACL_WRITE ACL_WRITE
6068 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6070 +/* Types of ACLs. */
6071 +#define SMB_ACL_USER ACL_USER
6072 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6073 +#define SMB_ACL_GROUP ACL_GROUP
6074 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6075 +#define SMB_ACL_OTHER ACL_OTHER
6076 +#define SMB_ACL_MASK ACL_MASK
6078 +#define SMB_ACL_T acl_t
6080 +#define SMB_ACL_ENTRY_T acl_entry_t
6082 +#define SMB_ACL_FIRST_ENTRY 0
6083 +#define SMB_ACL_NEXT_ENTRY 1
6085 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6086 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6088 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6090 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6091 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6094 +/* SVR4.2 ES/MP ACLs */
6095 +typedef int SMB_ACL_TAG_T;
6096 +typedef int SMB_ACL_TYPE_T;
6097 +typedef ushort *SMB_ACL_PERMSET_T;
6098 +typedef ushort SMB_ACL_PERM_T;
6099 +#define SMB_ACL_READ 4
6100 +#define SMB_ACL_WRITE 2
6101 +#define SMB_ACL_EXECUTE 1
6103 +/* Types of ACLs. */
6104 +#define SMB_ACL_USER USER
6105 +#define SMB_ACL_USER_OBJ USER_OBJ
6106 +#define SMB_ACL_GROUP GROUP
6107 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6108 +#define SMB_ACL_OTHER OTHER_OBJ
6109 +#define SMB_ACL_MASK CLASS_OBJ
6111 +typedef struct SMB_ACL_T {
6115 + struct acl acl[1];
6118 +typedef struct acl *SMB_ACL_ENTRY_T;
6120 +#define SMB_ACL_FIRST_ENTRY 0
6121 +#define SMB_ACL_NEXT_ENTRY 1
6123 +#define SMB_ACL_TYPE_ACCESS 0
6124 +#define SMB_ACL_TYPE_DEFAULT 1
6127 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6130 +#elif defined HAVE_HPUX_ACLS
6133 + * Based on the Solaris & UnixWare code.
6137 +#include <sys/aclv.h>
6139 +/* SVR4.2 ES/MP ACLs */
6140 +typedef int SMB_ACL_TAG_T;
6141 +typedef int SMB_ACL_TYPE_T;
6142 +typedef ushort *SMB_ACL_PERMSET_T;
6143 +typedef ushort SMB_ACL_PERM_T;
6144 +#define SMB_ACL_READ 4
6145 +#define SMB_ACL_WRITE 2
6146 +#define SMB_ACL_EXECUTE 1
6148 +/* Types of ACLs. */
6149 +#define SMB_ACL_USER USER
6150 +#define SMB_ACL_USER_OBJ USER_OBJ
6151 +#define SMB_ACL_GROUP GROUP
6152 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6153 +#define SMB_ACL_OTHER OTHER_OBJ
6154 +#define SMB_ACL_MASK CLASS_OBJ
6156 +typedef struct SMB_ACL_T {
6160 + struct acl acl[1];
6163 +typedef struct acl *SMB_ACL_ENTRY_T;
6165 +#define SMB_ACL_FIRST_ENTRY 0
6166 +#define SMB_ACL_NEXT_ENTRY 1
6168 +#define SMB_ACL_TYPE_ACCESS 0
6169 +#define SMB_ACL_TYPE_DEFAULT 1
6171 +#elif defined HAVE_IRIX_ACLS
6173 +#define SMB_ACL_TAG_T acl_tag_t
6174 +#define SMB_ACL_TYPE_T acl_type_t
6175 +#define SMB_ACL_PERMSET_T acl_permset_t
6176 +#define SMB_ACL_PERM_T acl_perm_t
6177 +#define SMB_ACL_READ ACL_READ
6178 +#define SMB_ACL_WRITE ACL_WRITE
6179 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6181 +/* Types of ACLs. */
6182 +#define SMB_ACL_USER ACL_USER
6183 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6184 +#define SMB_ACL_GROUP ACL_GROUP
6185 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6186 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6187 +#define SMB_ACL_MASK ACL_MASK
6189 +typedef struct SMB_ACL_T {
6195 +#define SMB_ACL_ENTRY_T acl_entry_t
6197 +#define SMB_ACL_FIRST_ENTRY 0
6198 +#define SMB_ACL_NEXT_ENTRY 1
6200 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6201 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6203 +#elif defined HAVE_AIX_ACLS
6205 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6207 +#include "/usr/include/acl.h"
6209 +typedef uint *SMB_ACL_PERMSET_T;
6211 +struct acl_entry_link{
6212 + struct acl_entry_link *prevp;
6213 + struct new_acl_entry *entryp;
6214 + struct acl_entry_link *nextp;
6218 +struct new_acl_entry{
6219 + unsigned short ace_len;
6220 + unsigned short ace_type;
6221 + unsigned int ace_access;
6222 + struct ace_id ace_id[1];
6225 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6226 +#define SMB_ACL_T struct acl_entry_link*
6228 +#define SMB_ACL_TAG_T unsigned short
6229 +#define SMB_ACL_TYPE_T int
6230 +#define SMB_ACL_PERM_T uint
6231 +#define SMB_ACL_READ S_IRUSR
6232 +#define SMB_ACL_WRITE S_IWUSR
6233 +#define SMB_ACL_EXECUTE S_IXUSR
6235 +/* Types of ACLs. */
6236 +#define SMB_ACL_USER ACEID_USER
6237 +#define SMB_ACL_USER_OBJ 3
6238 +#define SMB_ACL_GROUP ACEID_GROUP
6239 +#define SMB_ACL_GROUP_OBJ 4
6240 +#define SMB_ACL_OTHER 5
6241 +#define SMB_ACL_MASK 6
6244 +#define SMB_ACL_FIRST_ENTRY 1
6245 +#define SMB_ACL_NEXT_ENTRY 2
6247 +#define SMB_ACL_TYPE_ACCESS 0
6248 +#define SMB_ACL_TYPE_DEFAULT 1
6250 +#else /* No ACLs. */
6252 +/* No ACLS - fake it. */
6253 +#define SMB_ACL_TAG_T int
6254 +#define SMB_ACL_TYPE_T int
6255 +#define SMB_ACL_PERMSET_T mode_t
6256 +#define SMB_ACL_PERM_T mode_t
6257 +#define SMB_ACL_READ S_IRUSR
6258 +#define SMB_ACL_WRITE S_IWUSR
6259 +#define SMB_ACL_EXECUTE S_IXUSR
6261 +/* Types of ACLs. */
6262 +#define SMB_ACL_USER 0
6263 +#define SMB_ACL_USER_OBJ 1
6264 +#define SMB_ACL_GROUP 2
6265 +#define SMB_ACL_GROUP_OBJ 3
6266 +#define SMB_ACL_OTHER 4
6267 +#define SMB_ACL_MASK 5
6269 +typedef struct SMB_ACL_T {
6273 +typedef struct SMB_ACL_ENTRY_T {
6275 +} *SMB_ACL_ENTRY_T;
6277 +#define SMB_ACL_FIRST_ENTRY 0
6278 +#define SMB_ACL_NEXT_ENTRY 1
6280 +#define SMB_ACL_TYPE_ACCESS 0
6281 +#define SMB_ACL_TYPE_DEFAULT 1
6283 +#endif /* No ACLs. */
6284 +#endif /* _SMB_ACLS_H */
6287 @@ -78,3 +78,7 @@ struct filter_list_struct server_filter_
6291 + const char *who_am_i(void)
6295 --- old/testsuite/acls.test
6296 +++ new/testsuite/acls.test
6300 +# This program is distributable under the terms of the GNU GPL (see
6303 +# Test that rsync handles basic ACL preservation.
6305 +. $srcdir/testsuite/rsync.fns
6307 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6308 +case "$setfacl_nodef" in
6309 +true) test_skipped "I don't know how to use your setfacl command" ;;
6312 +makepath "$fromdir/foo"
6313 +echo something >"$fromdir/file1"
6314 +echo else >"$fromdir/file2"
6316 +files='foo file1 file2'
6318 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6319 +setfacl -m u:0:5 "$fromdir/file1"
6320 +setfacl -m u:0:5 "$fromdir/file2"
6322 +$RSYNC -avvA "$fromdir/" "$todir/"
6325 +getfacl $files >"$scratchdir/acls.txt"
6328 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6330 +# The script would have aborted on error, so getting here means we've won.
6332 --- old/testsuite/default-acls.test
6333 +++ new/testsuite/default-acls.test
6337 +# This program is distributable under the terms of the GNU GPL (see
6340 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6342 +. $srcdir/testsuite/rsync.fns
6344 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6345 +case "$setfacl_nodef" in
6346 +true) test_skipped "I don't know how to use your setfacl command" ;;
6347 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6348 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6350 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6352 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6354 + todir="$scratchdir/$1"
6356 + $setfacl_nodef "$todir"
6358 + case "$setfacl_nodef" in
6359 + *-k*) opts="-dm $2" ;;
6360 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6362 + setfacl $opts "$todir"
6364 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6365 + # even though the directory itself is outside the transfer
6366 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6367 + check_perms "$todir/to" $4 "Target $1"
6368 + check_perms "$todir/to/dir" $4 "Target $1"
6369 + check_perms "$todir/to/file" $3 "Target $1"
6370 + check_perms "$todir/to/program" $4 "Target $1"
6371 + # Make sure get_local_name doesn't mess us up when transferring only one file
6372 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6373 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6374 + # Make sure we obey default ACLs when not transferring a regular file
6375 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6376 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6379 +mkdir "$scratchdir/dir"
6380 +echo "File!" >"$scratchdir/file"
6381 +echo "#!/bin/sh" >"$scratchdir/program"
6382 +chmod 777 "$scratchdir/dir"
6383 +chmod 666 "$scratchdir/file"
6384 +chmod 777 "$scratchdir/program"
6386 +# Test some target directories
6388 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6389 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6390 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6391 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6392 +testit noda1 '' rw------- rwx------
6394 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6396 +testit noda3 '' rw-r--r-- rwxr-xr-x
6400 --- old/testsuite/devices.test
6401 +++ new/testsuite/devices.test
6402 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6403 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6405 cat <<EOT >"$chkfile"
6409 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6411 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6413 cat <<EOT >"$chkfile"
6417 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6419 @@ -58,7 +58,7 @@ sleep 1
6420 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6422 cat <<EOT >"$chkfile"
6426 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6428 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6431 cat <<EOT >"$chkfile"
6436 -hD+++++++ block2.5 => block3
6445 +hD+++++++++ block2.5 => block3
6451 if test ! -b "$fromdir/block2.5"; then
6452 sed -e '/block2\.5/d' \
6453 --- old/testsuite/itemize.test
6454 +++ new/testsuite/itemize.test
6455 @@ -29,14 +29,14 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6456 $RSYNC -iplr "$fromdir/" "$todir/" \
6458 cat <<EOT >"$chkfile"
6461 ->f+++++++ bar/baz/rsync
6463 ->f+++++++ foo/config1
6464 ->f+++++++ foo/config2
6465 ->f+++++++ foo/extra
6466 -cL+++++++ foo/sym -> ../bar/baz/rsync
6468 +cd+++++++++ bar/baz/
6469 +>f+++++++++ bar/baz/rsync
6471 +>f+++++++++ foo/config1
6472 +>f+++++++++ foo/config2
6473 +>f+++++++++ foo/extra
6474 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6476 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6478 @@ -48,10 +48,10 @@ chmod 601 "$fromdir/foo/config2"
6479 $RSYNC -iplrH "$fromdir/" "$todir/" \
6481 cat <<EOT >"$chkfile"
6482 ->f..T.... bar/baz/rsync
6483 ->f..T.... foo/config1
6484 ->f.sTp... foo/config2
6485 -hf..T.... foo/extra => foo/config1
6486 +>f..T...... bar/baz/rsync
6487 +>f..T...... foo/config1
6488 +>f.sTp..... foo/config2
6489 +hf..T...... foo/extra => foo/config1
6491 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6493 @@ -68,11 +68,11 @@ chmod 777 "$todir/bar/baz/rsync"
6494 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6496 cat <<EOT >"$chkfile"
6497 -.f..tp... bar/baz/rsync
6499 -.f..t.... foo/config1
6500 ->fcstp... foo/config2
6501 -cL..T.... foo/sym -> ../bar/baz/rsync
6502 +.f..tp..... bar/baz/rsync
6504 +.f..t...... foo/config1
6505 +>fcstp..... foo/config2
6506 +cL..T...... foo/sym -> ../bar/baz/rsync
6508 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6510 @@ -97,15 +97,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6513 cat <<EOT >"$chkfile"
6517 -.f...p... bar/baz/rsync
6520 ->f..t.... foo/config2
6522 -.L foo/sym -> ../bar/baz/rsync
6526 +.f...p..... bar/baz/rsync
6529 +>f..t...... foo/config2
6531 +.L foo/sym -> ../bar/baz/rsync
6533 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6535 @@ -124,8 +124,8 @@ touch "$todir/foo/config2"
6536 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6538 cat <<EOT >"$chkfile"
6539 -.f...p... foo/config1
6540 ->f..t.... foo/config2
6541 +.f...p..... foo/config1
6542 +>f..t...... foo/config2
6544 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6546 @@ -134,15 +134,15 @@ $RSYNC -ivvplrtH --copy-dest="$lddir" "$
6549 cat <<EOT >"$chkfile"
6557 -hf foo/extra => foo/config1
6558 -cL..T.... foo/sym -> ../bar/baz/rsync
6561 +cd+++++++++ bar/baz/
6566 +hf foo/extra => foo/config1
6567 +cL..T...... foo/sym -> ../bar/baz/rsync
6569 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6571 @@ -150,11 +150,11 @@ rm -rf "$todir"
6572 $RSYNC -iplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
6574 cat <<EOT >"$chkfile"
6579 -hf foo/extra => foo/config1
6582 +cd+++++++++ bar/baz/
6584 +hf foo/extra => foo/config1
6586 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6588 @@ -181,15 +181,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6591 cat <<EOT >"$chkfile"
6599 -hf foo/extra => foo/config1
6600 -hL foo/sym -> ../bar/baz/rsync
6603 +cd+++++++++ bar/baz/
6608 +hf foo/extra => foo/config1
6609 +hL foo/sym -> ../bar/baz/rsync
6611 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6613 @@ -197,10 +197,10 @@ rm -rf "$todir"
6614 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
6616 cat <<EOT >"$chkfile"
6623 +cd+++++++++ bar/baz/
6626 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6628 @@ -228,14 +228,14 @@ filter_outfile
6629 # TODO fix really-old problem when combining -H with --compare-dest:
6630 # missing output for foo/extra hard-link (and it might not be updated)!
6631 cat <<EOT >"$chkfile"
6639 -.L foo/sym -> ../bar/baz/rsync
6642 +cd+++++++++ bar/baz/
6647 +.L foo/sym -> ../bar/baz/rsync
6649 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
6651 @@ -243,10 +243,10 @@ rm -rf "$todir"
6652 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6654 cat <<EOT >"$chkfile"
6661 +cd+++++++++ bar/baz/
6664 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6670 extern int preserve_uid;
6671 extern int preserve_gid;
6672 +extern int preserve_acls;
6673 extern int numeric_ids;
6676 @@ -275,7 +276,7 @@ void send_uid_list(int f)
6680 - if (preserve_uid) {
6681 + if (preserve_uid || preserve_acls) {
6683 /* we send sequences of uid/byte-length/name */
6684 for (list = uidlist; list; list = list->next) {
6685 @@ -292,7 +293,7 @@ void send_uid_list(int f)
6689 - if (preserve_gid) {
6690 + if (preserve_gid || preserve_acls) {
6692 for (list = gidlist; list; list = list->next) {
6694 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
6698 - if (preserve_uid && !numeric_ids) {
6699 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6700 /* read the uid list */
6701 while ((id = read_int(f)) != 0) {
6702 int len = read_byte(f);
6703 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
6707 - if (preserve_gid && !numeric_ids) {
6708 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6709 /* read the gid list */
6710 while ((id = read_int(f)) != 0) {
6711 int len = read_byte(f);
6712 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
6716 +#ifdef SUPPORT_ACLS
6717 + if (preserve_acls && !numeric_ids) {
6719 + while ((id = next_acl_uid(flist)) != NULL)
6720 + *id = match_uid(*id);
6721 + while ((id = next_acl_gid(flist)) != NULL)
6722 + *id = match_gid(*id);
6726 /* Now convert all the uids/gids from sender values to our values. */
6727 if (am_root && preserve_uid && !numeric_ids) {
6728 for (i = 0; i < flist->count; i++)
6731 @@ -1446,3 +1446,32 @@ int bitbag_next_bit(struct bitbag *bb, i
6736 +void *expand_item_list(item_list *lp, size_t item_size,
6737 + const char *desc, int fast)
6739 + /* First time through, 0 <= 0, so list is expanded. */
6740 + if (lp->malloced <= lp->count) {
6742 + size_t new_size = lp->malloced;
6744 + if (new_size < 1000)
6750 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6751 + if (verbose >= 4) {
6752 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6753 + who_am_i(), desc, (double)new_size * item_size,
6754 + new_ptr == lp->items ? " not" : "");
6757 + out_of_memory("expand_item_list");
6759 + lp->items = new_ptr;
6760 + lp->malloced = new_size;
6762 + return (char*)lp->items + (lp->count++ * item_size);