1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 @@ -25,15 +25,15 @@ VERSION=@VERSION@
16 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
17 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
18 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
19 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
20 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
21 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
22 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
23 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
24 main.o checksum.o match.o syscall.o log.o backup.o
25 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
26 - fileio.o batch.o clientname.o chmod.o
27 + fileio.o batch.o clientname.o chmod.o acls.o
28 OBJS3=progress.o pipe.o
29 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
30 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 + * Handle passing Access Control Lists between systems.
37 + * Copyright (C) 1996 Andrew Tridgell
38 + * Copyright (C) 1996 Paul Mackerras
39 + * Copyright (C) 2006 Wayne Davison
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License as published by
43 + * the Free Software Foundation; either version 2 of the License, or
44 + * (at your option) any later version.
46 + * This program is distributed in the hope that it will be useful,
47 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 + * GNU General Public License for more details.
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
57 +#include "lib/sysacls.h"
63 +extern int orig_umask;
64 +extern int preserve_acls;
65 +extern unsigned int file_struct_len;
67 +/* === ACL structures === */
79 +#define NO_ENTRY ((uchar)0x80)
80 +typedef struct rsync_acl {
83 + /* These will be NO_ENTRY if there's no such entry. */
95 +static const rsync_acl empty_rsync_acl = {
96 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
99 +static item_list access_acl_list = EMPTY_ITEM_LIST;
100 +static item_list default_acl_list = EMPTY_ITEM_LIST;
102 +/* === Calculations on ACL types === */
104 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
106 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
107 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
108 + : "unknown SMB_ACL_TYPE_T";
111 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
112 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
114 +static int count_racl_entries(const rsync_acl *racl)
116 + return racl->users.count + racl->groups.count
117 + + (racl->user_obj != NO_ENTRY)
118 + + (racl->group_obj != NO_ENTRY)
119 + + (racl->mask != NO_ENTRY)
120 + + (racl->other != NO_ENTRY);
123 +static int calc_sacl_entries(const rsync_acl *racl)
125 + /* A System ACL always gets user/group/other permission entries. */
126 + return racl->users.count + racl->groups.count
127 +#ifdef ACLS_NEED_MASK
130 + + (racl->mask != NO_ENTRY) + 3;
134 +/* Extracts and returns the permission bits from the ACL. This cannot be
135 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
136 +static int rsync_acl_get_perms(const rsync_acl *racl)
138 + return (racl->user_obj << 6)
139 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
143 +/* Removes the permission-bit entries from the ACL because these
144 + * can be reconstructed from the file's mode. */
145 +static void rsync_acl_strip_perms(rsync_acl *racl)
147 + racl->user_obj = NO_ENTRY;
148 + if (racl->mask == NO_ENTRY)
149 + racl->group_obj = NO_ENTRY;
151 + if (racl->group_obj == racl->mask)
152 + racl->group_obj = NO_ENTRY;
153 + racl->mask = NO_ENTRY;
155 + racl->other = NO_ENTRY;
158 +/* Given an empty rsync_acl, fake up the permission bits. */
159 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
161 + racl->user_obj = (mode >> 6) & 7;
162 + racl->group_obj = (mode >> 3) & 7;
163 +#ifdef ACLS_NEED_MASK
164 + racl->mask = (mode >> 3) & 7;
166 + racl->other = mode & 7;
169 +/* === Rsync ACL functions === */
171 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
173 + id_access *ida1, *ida2;
174 + int count = ial1->count;
175 + if (count != ial2->count)
179 + for (; count--; ida1++, ida2++) {
180 + if (ida1->access != ida2->access || ida1->id != ida2->id)
186 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
188 + return (racl1->user_obj == racl2->user_obj
189 + && racl1->group_obj == racl2->group_obj
190 + && racl1->mask == racl2->mask
191 + && racl1->other == racl2->other
192 + && ida_entries_equal(&racl1->users, &racl2->users)
193 + && ida_entries_equal(&racl1->groups, &racl2->groups));
196 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
197 + * the ACL will be handled by the normal mode-preservation code. This is
198 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
199 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
200 + * that it might have several of its perm objects set to NO_ENTRY. */
201 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
202 + const rsync_acl *racl2, mode_t m)
204 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
205 + return False; /* One has a mask and the other doesn't */
207 + /* When there's a mask, the group_obj becomes an extended entry. */
208 + if (racl1->mask != NO_ENTRY) {
209 + /* A condensed rsync_acl with a mask can only have no
210 + * group_obj when it was identical to the mask. This
211 + * means that it was also identical to the group attrs
212 + * from the mode. */
213 + if (racl2->group_obj == NO_ENTRY) {
214 + if (racl1->group_obj != ((m >> 3) & 7))
216 + } else if (racl1->group_obj != racl2->group_obj)
219 + return ida_entries_equal(&racl1->users, &racl2->users)
220 + && ida_entries_equal(&racl1->groups, &racl2->groups);
223 +static void rsync_acl_free(rsync_acl *racl)
225 + if (racl->users.idas)
226 + free(racl->users.idas);
227 + if (racl->groups.idas)
228 + free(racl->groups.idas);
229 + *racl = empty_rsync_acl;
232 +void free_acl(statx *sxp)
234 + if (sxp->acc_acl) {
235 + rsync_acl_free(sxp->acc_acl);
236 + free(sxp->acc_acl);
237 + sxp->acc_acl = NULL;
239 + if (sxp->def_acl) {
240 + rsync_acl_free(sxp->def_acl);
241 + free(sxp->def_acl);
242 + sxp->def_acl = NULL;
246 +static int id_access_sorter(const void *r1, const void *r2)
248 + id_access *ida1 = (id_access *)r1;
249 + id_access *ida2 = (id_access *)r2;
250 + id_t rid1 = ida1->id, rid2 = ida2->id;
251 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
254 +static void sort_ida_entries(ida_entries *idal)
258 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
261 +/* Transfer the count id_access items out of the temp_ida_list into either
262 + * the users or groups ida_entries list in racl. */
263 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
268 + if (temp_ida_list->count) {
269 + int cnt = temp_ida_list->count;
270 + id_access *temp_idas = temp_ida_list->items;
271 + if (!(idas = new_array(id_access, cnt)))
272 + out_of_memory("save_idas");
273 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
277 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
280 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
281 + exit_cleanup(RERR_UNSUPPORTED);
283 + ent->count = temp_ida_list->count;
286 + /* Truncate the temporary list now that its idas have been saved. */
287 + temp_ida_list->count = 0;
290 +/* === System ACLs === */
292 +/* Unpack system acl -> rsync acl verbatim. Return whether we succeeded. */
293 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
295 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
296 + SMB_ACL_TAG_T prior_list_type = 0;
297 + SMB_ACL_ENTRY_T entry;
298 + const char *errfun;
301 + *racl = empty_rsync_acl;
302 + errfun = "sys_acl_get_entry";
303 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
305 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
306 + SMB_ACL_TAG_T tag_type;
307 + SMB_ACL_PERMSET_T permset;
311 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
312 + errfun = "sys_acl_get_tag_type";
315 + if ((rc = sys_acl_get_permset(entry, &permset))) {
316 + errfun = "sys_acl_get_tag_type";
319 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
320 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
321 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
322 + /* continue == done with entry; break == store in temporary ida list */
323 + switch (tag_type) {
324 + case SMB_ACL_USER_OBJ:
325 + if (racl->user_obj == NO_ENTRY)
326 + racl->user_obj = access;
328 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
332 + case SMB_ACL_GROUP_OBJ:
333 + if (racl->group_obj == NO_ENTRY)
334 + racl->group_obj = access;
336 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
338 + case SMB_ACL_GROUP:
341 + if (racl->mask == NO_ENTRY)
342 + racl->mask = access;
344 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
346 + case SMB_ACL_OTHER:
347 + if (racl->other == NO_ENTRY)
348 + racl->other = access;
350 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
353 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
356 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
357 + errfun = "sys_acl_get_tag_type";
361 + if (tag_type != prior_list_type) {
362 + if (prior_list_type)
363 + save_idas(&temp_ida_list, racl, prior_list_type);
364 + prior_list_type = tag_type;
366 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
367 + ida->id = *((id_t *)qualifier);
368 + ida->access = access;
369 + sys_acl_free_qualifier(qualifier, tag_type);
372 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
373 + rsync_acl_free(racl);
376 + if (prior_list_type)
377 + save_idas(&temp_ida_list, racl, prior_list_type);
379 + sort_ida_entries(&racl->users);
380 + sort_ida_entries(&racl->groups);
382 +#ifdef ACLS_NEED_MASK
383 + if (!racl->users.count && !racl->groups.count) {
384 + /* Throw away a superfluous mask, but mask off the
385 + * group perms with it first. */
386 + racl->group_obj &= racl->mask;
387 + racl->mask = NO_ENTRY;
394 +/* Synactic sugar for system calls */
396 +#define CALL_OR_ERROR(func,args,str) \
404 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
405 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
407 +/* Store the permissions in the system ACL entry. */
408 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
410 + const char *errfun = NULL;
411 + SMB_ACL_PERMSET_T permset;
413 + COE( sys_acl_get_permset,(entry, &permset) );
414 + COE( sys_acl_clear_perms,(permset) );
416 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
418 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
420 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
421 + COE( sys_acl_set_permset,(entry, permset) );
426 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
430 +/* Pack rsync acl -> system acl verbatim. Return whether we succeeded. */
431 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
433 +#ifdef ACLS_NEED_MASK
438 + const char *errfun = NULL;
439 + SMB_ACL_ENTRY_T entry;
441 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
442 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
446 + COE( sys_acl_create_entry,(smb_acl, &entry) );
447 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
448 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
450 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
451 + COE( sys_acl_create_entry,(smb_acl, &entry) );
452 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
453 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
454 + COE2( store_access_in_entry,(ida->access, entry) );
457 + COE( sys_acl_create_entry,(smb_acl, &entry) );
458 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
459 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
461 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
462 + COE( sys_acl_create_entry,(smb_acl, &entry) );
463 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
464 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
465 + COE2( store_access_in_entry,(ida->access, entry) );
468 +#ifdef ACLS_NEED_MASK
469 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
470 + COE( sys_acl_create_entry,(smb_acl, &entry) );
471 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
472 + COE2( store_access_in_entry,(mask_bits, entry) );
474 + if (racl->mask != NO_ENTRY) {
475 + COE( sys_acl_create_entry,(smb_acl, &entry) );
476 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
477 + COE2( store_access_in_entry,(racl->mask, entry) );
481 + COE( sys_acl_create_entry,(smb_acl, &entry) );
482 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
483 + COE2( store_access_in_entry,(racl->other & 7, entry) );
486 + if (sys_acl_valid(*smb_acl) < 0)
487 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
494 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
496 + sys_acl_free_acl(*smb_acl);
500 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
501 + const item_list *racl_list,
502 + const rsync_acl *racl)
504 + static int access_match = -1, default_match = -1;
505 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
506 + size_t count = racl_list->count;
508 + /* If this is the first time through or we didn't match the last
509 + * time, then start at the end of the list, which should be the
510 + * best place to start hunting. */
512 + *match = racl_list->count - 1;
514 + rsync_acl *base = racl_list->items;
515 + if (rsync_acl_equal(base + *match, racl))
518 + *match = racl_list->count - 1;
525 +/* Turn the ACL data in statx into cached ACL data, setting the index
526 + * values in the file struct. */
527 +void cache_acl(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, 1000);
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_acl(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_acl");
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_acl: 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 ACL from the statx structure down the indicated file descriptor.
657 + * This also frees the ACL data. */
658 +void send_acl(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');
685 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
686 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
687 + send_rsync_acl(f, racl);
689 + *racl = empty_rsync_acl;
691 + racl = sxp->def_acl;
692 + racl_list = &default_acl_list;
693 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
698 +/* === Receive functions === */
700 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
702 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
703 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
704 + uchar computed_mask_bits = 0;
708 + *racl = empty_rsync_acl;
710 + if (!(count = read_int(f)))
714 + char tag = read_byte(f);
715 + uchar access = read_byte(f);
716 + if (access & ~ (4 | 2 | 1)) {
717 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
719 + exit_cleanup(RERR_STREAMIO);
723 + if (racl->user_obj != NO_ENTRY) {
724 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
725 + exit_cleanup(RERR_STREAMIO);
727 + racl->user_obj = access;
730 + tag_type = SMB_ACL_USER;
733 + if (racl->group_obj != NO_ENTRY) {
734 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
735 + exit_cleanup(RERR_STREAMIO);
737 + racl->group_obj = access;
740 + tag_type = SMB_ACL_GROUP;
743 + if (racl->mask != NO_ENTRY) {
744 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
745 + exit_cleanup(RERR_STREAMIO);
747 + racl->mask = access;
750 + if (racl->other != NO_ENTRY) {
751 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
752 + exit_cleanup(RERR_STREAMIO);
754 + racl->other = access;
757 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
759 + exit_cleanup(RERR_STREAMIO);
761 + if (tag_type != prior_list_type) {
762 + if (prior_list_type)
763 + save_idas(&temp_ida_list, racl, prior_list_type);
764 + prior_list_type = tag_type;
766 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
767 + ida->access = access;
768 + ida->id = read_int(f);
769 + computed_mask_bits |= access;
771 + if (prior_list_type)
772 + save_idas(&temp_ida_list, racl, prior_list_type);
774 + if (type == SMB_ACL_TYPE_DEFAULT) {
775 + /* Ensure that these are never unset. */
776 + if (racl->user_obj == NO_ENTRY)
777 + racl->user_obj = 7;
778 + if (racl->group_obj == NO_ENTRY)
779 + racl->group_obj = 0;
780 + if (racl->other == NO_ENTRY)
784 + if (!racl->users.count && !racl->groups.count) {
785 + /* If we received a superfluous mask, throw it away. */
786 + if (racl->mask != NO_ENTRY) {
787 + /* Mask off the group perms with it first. */
788 + racl->group_obj &= racl->mask | NO_ENTRY;
789 + racl->mask = NO_ENTRY;
791 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
792 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
795 +/* Receive the ACL info the sender has included for this file-list entry. */
796 +void receive_acl(struct file_struct *file, int f)
798 + SMB_ACL_TYPE_T type;
799 + item_list *racl_list;
802 + if (S_ISLNK(file->mode))
805 + type = SMB_ACL_TYPE_ACCESS;
806 + racl_list = &access_acl_list;
807 + ndx_ptr = (char*)file + file_struct_len;
809 + char tag = read_byte(f);
812 + if (tag == 'A' || tag == 'a') {
813 + if (type != SMB_ACL_TYPE_ACCESS) {
814 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
815 + f_name(file, NULL));
816 + exit_cleanup(RERR_STREAMIO);
818 + } else if (tag == 'D' || tag == 'd') {
819 + if (type == SMB_ACL_TYPE_ACCESS) {
820 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
821 + f_name(file, NULL));
822 + exit_cleanup(RERR_STREAMIO);
825 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
826 + f_name(file, NULL), tag);
827 + exit_cleanup(RERR_STREAMIO);
829 + if (tag == 'A' || tag == 'D') {
831 + ndx = racl_list->count;
832 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
833 + receive_rsync_acl(&duo_item->racl, f, type);
834 + duo_item->sacl = NULL;
837 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
838 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
839 + f_name(file, NULL), str_acl_type(type), ndx);
840 + exit_cleanup(RERR_STREAMIO);
843 + SIVAL(ndx_ptr, 0, ndx);
844 + racl_list = &default_acl_list;
846 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
849 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
851 + SMB_ACL_ENTRY_T entry;
852 + const char *errfun;
855 + if (S_ISDIR(mode)) {
856 + /* If the sticky bit is going on, it's not safe to allow all
857 + * the new ACLs to go into effect before it gets set. */
858 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
859 + if (mode & S_ISVTX)
862 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
865 + /* If setuid or setgid is going off, it's not safe to allow all
866 + * the new ACLs to go into effect before they get cleared. */
867 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
868 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
873 + errfun = "sys_acl_get_entry";
874 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
876 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
877 + SMB_ACL_TAG_T tag_type;
878 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
879 + errfun = "sys_acl_get_tag_type";
882 + switch (tag_type) {
883 + case SMB_ACL_USER_OBJ:
884 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
886 + case SMB_ACL_GROUP_OBJ:
887 + /* group is only empty when identical to group perms. */
888 + if (racl->group_obj != NO_ENTRY)
890 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
893 +#ifndef ACLS_NEED_MASK
894 + /* mask is only empty when we don't need it. */
895 + if (racl->mask == NO_ENTRY)
898 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
900 + case SMB_ACL_OTHER:
901 + COE2( store_access_in_entry,(mode & 7, entry) );
908 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
914 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
915 + /* Ensure that chmod() will be called to restore any lost setid bits. */
916 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
917 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
918 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
921 + /* Return the mode of the file on disk, as we will set them. */
922 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
925 +/* Set ACL on indicated filename.
927 + * This sets extended access ACL entries and default ACLs. If convenient,
928 + * it sets permission bits along with the access ACLs and signals having
929 + * done so by modifying sxp->st.st_mode.
931 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
932 + * with fname set to NULL to just check if the ACLs are unchanged. */
933 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
936 + SMB_ACL_TYPE_T type;
939 + if (S_ISLNK(file->mode))
942 + type = SMB_ACL_TYPE_ACCESS;
943 + ndx_ptr = (char*)file + file_struct_len;
947 + int ndx = IVAL(ndx_ptr, 0);
951 + if (type == SMB_ACL_TYPE_ACCESS) {
952 + duo_item = access_acl_list.items;
954 + eq = rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
956 + duo_item = default_acl_list.items;
958 + eq = rsync_acl_equal(sxp->def_acl, &duo_item->racl);
962 + if (!dry_run && fname) {
963 + if (type == SMB_ACL_TYPE_DEFAULT
964 + && duo_item->racl.user_obj == NO_ENTRY) {
965 + if (sys_acl_delete_def_file(fname) < 0) {
966 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
972 + mode_t cur_mode = sxp->st.st_mode;
973 + if (!duo_item->sacl
974 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
978 + if (type == SMB_ACL_TYPE_ACCESS) {
979 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
980 + cur_mode, file->mode);
981 + if (cur_mode == ~0u)
984 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
985 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
986 + fname, str_acl_type(type));
990 + if (type == SMB_ACL_TYPE_ACCESS)
991 + sxp->st.st_mode = cur_mode;
994 + if (unchanged == 1)
996 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1001 +/* === Enumeration functions for uid mapping === */
1003 +/* Context -- one and only one. Should be cycled through once on uid
1004 + * mapping and once on gid mapping. */
1005 +static item_list *_enum_racl_lists[] = {
1006 + &access_acl_list, &default_acl_list, NULL
1009 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1010 +static int enum_ida_index = 0;
1011 +static size_t enum_racl_index = 0;
1013 +/* This returns the next tag_type id from the given acl for the next entry,
1014 + * or it returns 0 if there are no more tag_type ids in the acl. */
1015 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1017 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1018 + if (enum_ida_index < idal->count) {
1019 + id_access *ida = &idal->idas[enum_ida_index++];
1022 + enum_ida_index = 0;
1026 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1028 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1030 + acl_duo *duo_item = racl_list->items;
1031 + duo_item += enum_racl_index;
1032 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1035 + enum_racl_index = 0;
1039 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1041 + for (; *enum_racl_list; enum_racl_list++) {
1042 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1046 + enum_racl_list = &_enum_racl_lists[0];
1050 +id_t *next_acl_uid()
1052 + return next_acl_list_id(SMB_ACL_USER);
1055 +id_t *next_acl_gid()
1057 + return next_acl_list_id(SMB_ACL_GROUP);
1060 +/* This is used by dest_mode(). */
1061 +int default_perms_for_dir(const char *dir)
1070 + perms = ACCESSPERMS & ~orig_umask;
1071 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1072 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1073 + if (sacl == NULL) {
1074 + /* Couldn't get an ACL. Darn. */
1077 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1081 + /* We're doing a dry run, so the containing directory
1082 + * wasn't actually created. Don't worry about it. */
1085 + /* Otherwise fall through. */
1087 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1088 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1094 + ok = unpack_smb_acl(&racl, sacl);
1095 + sys_acl_free_acl(sacl);
1097 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1101 + /* Apply the permission-bit entries of the default ACL, if any. */
1102 + if (racl.user_obj != NO_ENTRY) {
1103 + perms = rsync_acl_get_perms(&racl);
1105 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1108 + rsync_acl_free(&racl);
1112 +#endif /* SUPPORT_ACLS */
1115 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1116 extern char *backup_dir;
1119 +extern int preserve_acls;
1120 extern int preserve_devices;
1121 extern int preserve_specials;
1122 extern int preserve_links;
1123 @@ -94,7 +95,8 @@ path
1124 ****************************************************************************/
1125 static int make_bak_dir(char *fullpath)
1129 + struct file_struct *file;
1130 char *rel = fullpath + backup_dir_len;
1131 char *end = rel + strlen(rel);
1133 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1135 /* Try to transfer the directory settings of the
1136 * actual dir that the files are coming from. */
1137 - if (do_stat(rel, &st) < 0) {
1138 + if (do_stat(rel, &sx.st) < 0) {
1139 rsyserr(FERROR, errno,
1140 "make_bak_dir stat %s failed",
1143 - do_lchown(fullpath, st.st_uid, st.st_gid);
1144 - do_chmod(fullpath, st.st_mode);
1145 +#ifdef SUPPORT_ACLS
1146 + sx.acc_acl = sx.def_acl = NULL;
1148 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1150 +#ifdef SUPPORT_ACLS
1151 + if (preserve_acls) {
1152 + get_acl(rel, &sx);
1153 + cache_acl(file, &sx);
1156 + set_file_attrs(fullpath, file, NULL, 0);
1161 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1162 * We will move the file to be deleted into a parallel directory tree. */
1163 static int keep_backup(char *fname)
1167 struct file_struct *file;
1172 /* return if no file to keep */
1173 - if (do_lstat(fname, &st) < 0)
1174 + if (do_lstat(fname, &sx.st) < 0)
1176 +#ifdef SUPPORT_ACLS
1177 + sx.acc_acl = sx.def_acl = NULL;
1180 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1181 return 1; /* the file could have disappeared */
1182 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1183 if (!(buf = get_backup_name(fname)))
1186 +#ifdef SUPPORT_ACLS
1187 + if (preserve_acls) {
1188 + get_acl(fname, &sx);
1189 + cache_acl(file, &sx);
1193 /* Check to see if this is a device file, or link */
1194 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1195 || (preserve_specials && IS_SPECIAL(file->mode))) {
1196 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1197 if (robust_move(fname, buf) != 0) {
1198 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1199 full_fname(fname), buf);
1200 - } else if (st.st_nlink > 1) {
1201 + } else if (sx.st.st_nlink > 1) {
1202 /* If someone has hard-linked the file into the backup
1203 * dir, rename() might return success but do nothing! */
1204 robust_unlink(fname); /* Just in case... */
1205 --- old/configure.in
1206 +++ new/configure.in
1207 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1208 AC_CHECK_LIB(resolv, strcasecmp)
1211 +AC_CHECK_FUNCS(aclsort)
1212 +if test x"$ac_cv_func_aclsort" = x"no"; then
1213 + AC_CHECK_LIB(sec, aclsort)
1216 dnl At the moment we don't test for a broken memcmp(), because all we
1217 dnl need to do is test for equality, not comparison, and it seems that
1218 dnl every platform has a memcmp that can do at least that.
1219 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1220 AC_SUBST(CC_SHOBJ_FLAG)
1221 AC_SUBST(BUILD_POPT)
1223 +AC_CHECK_HEADERS(sys/acl.h)
1224 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1225 +#################################################
1226 +# check for ACL support
1228 +AC_MSG_CHECKING(whether to support ACLs)
1229 +AC_ARG_ENABLE(acl-support,
1230 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1231 +[ case "$enableval" in
1234 + case "$host_os" in
1236 + AC_MSG_RESULT(Using UnixWare ACLs)
1237 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1239 + *solaris*|*cygwin*)
1240 + AC_MSG_RESULT(Using solaris ACLs)
1241 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1244 + AC_MSG_RESULT(Using HPUX ACLs)
1245 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1248 + AC_MSG_RESULT(Using IRIX ACLs)
1249 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1252 + AC_MSG_RESULT(Using AIX ACLs)
1253 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1256 + AC_MSG_RESULT(Using Tru64 ACLs)
1257 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1258 + LIBS="$LIBS -lpacl"
1261 + AC_MSG_RESULT(ACLs requested -- running tests)
1262 + AC_CHECK_LIB(acl,acl_get_file)
1263 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1264 + AC_TRY_LINK([#include <sys/types.h>
1265 +#include <sys/acl.h>],
1266 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1267 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1268 + AC_MSG_CHECKING(ACL test results)
1269 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1270 + AC_MSG_RESULT(Using posix ACLs)
1271 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1272 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1273 + AC_TRY_LINK([#include <sys/types.h>
1274 +#include <sys/acl.h>],
1275 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1276 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1277 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1278 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1281 + AC_MSG_ERROR(Failed to find ACL support)
1288 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1291 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1295 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1300 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1301 extern int one_file_system;
1302 extern int copy_dirlinks;
1303 extern int keep_dirlinks;
1304 +extern int preserve_acls;
1305 extern int preserve_links;
1306 extern int preserve_hard_links;
1307 extern int preserve_devices;
1308 @@ -133,6 +134,8 @@ static void list_file_entry(struct file_
1310 permstring(permbuf, f->mode);
1312 + /* TODO: indicate '+' if the entry has an ACL. */
1314 #ifdef SUPPORT_LINKS
1315 if (preserve_links && S_ISLNK(f->mode)) {
1316 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1317 @@ -499,6 +502,9 @@ static struct file_struct *receive_file_
1318 char thisname[MAXPATHLEN];
1319 unsigned int l1 = 0, l2 = 0;
1320 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1321 +#ifdef SUPPORT_ACLS
1325 char *basename, *dirname, *bp;
1326 struct file_struct *file;
1327 @@ -602,13 +608,27 @@ static struct file_struct *receive_file_
1329 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1331 +#ifdef SUPPORT_ACLS
1332 + /* We need one or two index int32s when we're preserving ACLs. */
1333 + if (preserve_acls)
1334 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
1339 alloc_len = file_struct_len + dirname_len + basename_len
1340 +#ifdef SUPPORT_ACLS
1343 + linkname_len + sum_len;
1344 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1346 file = (struct file_struct *)bp;
1347 memset(bp, 0, file_struct_len);
1348 bp += file_struct_len;
1349 +#ifdef SUPPORT_ACLS
1353 file->modtime = modtime;
1354 file->length = file_length;
1355 @@ -703,6 +723,11 @@ static struct file_struct *receive_file_
1356 read_buf(f, sum, checksum_len);
1359 +#ifdef SUPPORT_ACLS
1360 + if (preserve_acls)
1361 + receive_acl(file, f);
1367 @@ -952,6 +977,9 @@ static struct file_struct *send_file_nam
1368 unsigned short flags)
1370 struct file_struct *file;
1371 +#ifdef SUPPORT_ACLS
1375 file = make_file(fname, flist, stp, flags,
1376 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1377 @@ -961,6 +989,15 @@ static struct file_struct *send_file_nam
1378 if (chmod_modes && !S_ISLNK(file->mode))
1379 file->mode = tweak_mode(file->mode, chmod_modes);
1381 +#ifdef SUPPORT_ACLS
1382 + if (preserve_acls) {
1383 + sx.st.st_mode = file->mode;
1384 + sx.acc_acl = sx.def_acl = NULL;
1385 + if (get_acl(fname, &sx) < 0)
1390 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1392 flist_expand(flist);
1393 @@ -968,6 +1005,15 @@ static struct file_struct *send_file_nam
1394 if (file->basename[0]) {
1395 flist->files[flist->count++] = file;
1396 send_file_entry(file, f);
1397 +#ifdef SUPPORT_ACLS
1398 + if (preserve_acls)
1402 +#ifdef SUPPORT_ACLS
1403 + if (preserve_acls)
1411 @@ -36,6 +36,7 @@ extern int recurse;
1412 extern int relative_paths;
1413 extern int implied_dirs;
1414 extern int keep_dirlinks;
1415 +extern int preserve_acls;
1416 extern int preserve_links;
1417 extern int preserve_devices;
1418 extern int preserve_specials;
1419 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1420 extern int max_delete;
1421 extern int force_delete;
1422 extern int one_file_system;
1423 +extern mode_t orig_umask;
1424 extern struct stats stats;
1425 extern dev_t filesystem_dev;
1426 extern char *backup_dir;
1427 @@ -317,22 +319,27 @@ static void do_delete_pass(struct file_l
1428 rprintf(FINFO, " \r");
1431 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1432 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1435 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1436 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1439 - if (am_root && preserve_uid && st->st_uid != file->uid)
1440 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1443 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1444 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1447 +#ifdef SUPPORT_ACLS
1448 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1455 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1456 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1457 int32 iflags, uchar fnamecmp_type, char *xname)
1459 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1460 @@ -340,19 +347,23 @@ void itemize(struct file_struct *file, i
1461 : S_ISDIR(file->mode) ? !omit_dir_times
1462 : !S_ISLNK(file->mode);
1464 - if (S_ISREG(file->mode) && file->length != st->st_size)
1465 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1466 iflags |= ITEM_REPORT_SIZE;
1467 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1468 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1469 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1470 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1471 iflags |= ITEM_REPORT_TIME;
1472 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1473 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1474 iflags |= ITEM_REPORT_PERMS;
1475 - if (preserve_uid && am_root && file->uid != st->st_uid)
1476 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1477 iflags |= ITEM_REPORT_OWNER;
1478 if (preserve_gid && file->gid != GID_NONE
1479 - && st->st_gid != file->gid)
1480 + && sxp->st.st_gid != file->gid)
1481 iflags |= ITEM_REPORT_GROUP;
1482 +#ifdef SUPPORT_ACLS
1483 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1484 + iflags |= ITEM_REPORT_ACL;
1487 iflags |= ITEM_IS_NEW;
1489 @@ -603,7 +614,7 @@ void check_for_finished_hlinks(int itemi
1490 * handling the file, -1 if no dest-linking occurred, or a non-negative
1491 * value if we found an alternate basis file. */
1492 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1493 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1494 + char *cmpbuf, statx *sxp, int itemizing,
1495 int maybe_ATTRS_REPORT, enum logcode code)
1497 int best_match = -1;
1498 @@ -612,7 +623,7 @@ static int try_dests_reg(struct file_str
1501 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1502 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1503 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1505 switch (match_level) {
1507 @@ -620,16 +631,20 @@ static int try_dests_reg(struct file_str
1511 - if (!unchanged_file(cmpbuf, file, stp))
1512 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1518 - if (!unchanged_attrs(file, stp))
1519 +#ifdef SUPPORT_ACLS
1520 + if (preserve_acls)
1521 + get_acl(cmpbuf, sxp);
1523 + if (!unchanged_attrs(file, sxp))
1525 if ((always_checksum || ignore_times)
1526 - && cmp_time(stp->st_mtime, file->modtime))
1527 + && cmp_time(sxp->st.st_mtime, file->modtime))
1531 @@ -644,22 +659,27 @@ static int try_dests_reg(struct file_str
1532 if (j != best_match) {
1534 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1535 - if (link_stat(cmpbuf, stp, 0) < 0)
1536 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1541 if (match_level == 3 && !copy_dest) {
1543 - if (hard_link_one(file, ndx, fname, 0, stp,
1544 + if (hard_link_one(file, ndx, fname, 0, sxp,
1546 itemizing && verbose > 1,
1549 if (preserve_hard_links && file->link_u.links)
1550 hard_link_cluster(file, ndx, itemizing, code);
1551 - } else if (itemizing)
1552 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1553 + } else if (itemizing) {
1554 +#ifdef SUPPORT_ACLS
1555 + if (preserve_acls && !ACL_READY(*sxp))
1556 + get_acl(fname, sxp);
1558 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1560 if (verbose > 1 && maybe_ATTRS_REPORT) {
1561 code = daemon_log_format_has_i || dry_run
1563 @@ -678,8 +698,13 @@ static int try_dests_reg(struct file_str
1568 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1570 +#ifdef SUPPORT_ACLS
1571 + if (preserve_acls && !ACL_READY(*sxp))
1572 + get_acl(fname, sxp);
1574 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1576 set_file_attrs(fname, file, NULL, 0);
1577 if (maybe_ATTRS_REPORT
1578 && ((!itemizing && verbose && match_level == 2)
1579 @@ -704,13 +729,18 @@ static int try_dests_non(struct file_str
1582 char fnamebuf[MAXPATHLEN];
1588 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1589 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1590 - || !unchanged_attrs(file, &st))
1591 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1593 +#ifdef SUPPORT_ACLS
1594 + if (preserve_acls)
1595 + get_acl(fnamebuf, &sx);
1597 + if (!unchanged_attrs(file, &sx))
1599 if (S_ISLNK(file->mode)) {
1600 #ifdef SUPPORT_LINKS
1601 @@ -723,10 +753,10 @@ static int try_dests_non(struct file_str
1604 } else if (IS_SPECIAL(file->mode)) {
1605 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1606 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1608 } else if (IS_DEVICE(file->mode)) {
1609 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1610 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1614 @@ -755,7 +785,15 @@ static int try_dests_non(struct file_str
1615 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1616 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1617 char *lp = link_dest ? "" : NULL;
1618 - itemize(file, ndx, 0, &st, changes, 0, lp);
1619 +#ifdef SUPPORT_ACLS
1620 + if (preserve_acls)
1621 + get_acl(fname, &sx);
1623 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1624 +#ifdef SUPPORT_ACLS
1625 + if (preserve_acls)
1629 if (verbose > 1 && maybe_ATTRS_REPORT) {
1630 code = daemon_log_format_has_i || dry_run
1631 @@ -769,6 +807,7 @@ static int try_dests_non(struct file_str
1634 static int phase = 0;
1635 +static int dflt_perms;
1637 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1638 * make sure it exists, and has the right permissions/timestamp info. For
1639 @@ -790,7 +829,8 @@ static void recv_generator(char *fname,
1640 static int need_fuzzy_dirlist = 0;
1641 struct file_struct *fuzzy_file = NULL;
1642 int fd = -1, f_copy = -1;
1643 - STRUCT_STAT st, real_st, partial_st;
1644 + statx sx, real_sx;
1645 + STRUCT_STAT partial_st;
1646 struct file_struct *back_file = NULL;
1647 int statret, real_ret, stat_errno;
1648 char *fnamecmp, *partialptr, *backupptr = NULL;
1649 @@ -841,6 +881,9 @@ static void recv_generator(char *fname,
1653 +#ifdef SUPPORT_ACLS
1654 + sx.acc_acl = sx.def_acl = NULL;
1658 stat_errno = ENOENT;
1659 @@ -848,7 +891,7 @@ static void recv_generator(char *fname,
1660 char *dn = file->dirname ? file->dirname : ".";
1661 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1662 if (relative_paths && !implied_dirs
1663 - && do_stat(dn, &st) < 0
1664 + && do_stat(dn, &sx.st) < 0
1665 && create_directory_path(fname) < 0) {
1666 rsyserr(FERROR, errno,
1667 "recv_generator: mkdir %s failed",
1668 @@ -860,6 +903,10 @@ static void recv_generator(char *fname,
1671 need_fuzzy_dirlist = 1;
1672 +#ifdef SUPPORT_ACLS
1673 + if (!preserve_perms)
1674 + dflt_perms = default_perms_for_dir(dn);
1677 parent_dirname = dn;
1679 @@ -868,7 +915,7 @@ static void recv_generator(char *fname,
1680 need_fuzzy_dirlist = 0;
1683 - statret = link_stat(fname, &st,
1684 + statret = link_stat(fname, &sx.st,
1685 keep_dirlinks && S_ISDIR(file->mode));
1688 @@ -886,8 +933,9 @@ static void recv_generator(char *fname,
1689 * mode based on the local permissions and some heuristics. */
1690 if (!preserve_perms) {
1691 int exists = statret == 0
1692 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1693 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1694 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1695 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1699 if (S_ISDIR(file->mode)) {
1700 @@ -896,8 +944,8 @@ static void recv_generator(char *fname,
1701 * file of that name and it is *not* a directory, then
1702 * we need to delete it. If it doesn't exist, then
1703 * (perhaps recursively) create it. */
1704 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1705 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1706 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1707 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1711 @@ -906,7 +954,11 @@ static void recv_generator(char *fname,
1714 if (itemizing && f_out != -1) {
1715 - itemize(file, ndx, statret, &st,
1716 +#ifdef SUPPORT_ACLS
1717 + if (preserve_acls && statret == 0)
1718 + get_acl(fname, &sx);
1720 + itemize(file, ndx, statret, &sx,
1721 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1723 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1724 @@ -918,19 +970,19 @@ static void recv_generator(char *fname,
1728 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1729 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1730 && verbose && code && f_out != -1)
1731 rprintf(code, "%s/\n", fname);
1732 if (delete_during && f_out != -1 && !phase && dry_run < 2
1733 && (file->flags & FLAG_DEL_HERE))
1734 - delete_in_dir(the_file_list, fname, file, &st);
1736 + delete_in_dir(the_file_list, fname, file, &sx.st);
1740 if (preserve_hard_links && file->link_u.links
1741 - && hard_link_check(file, ndx, fname, statret, &st,
1742 + && hard_link_check(file, ndx, fname, statret, &sx,
1743 itemizing, code, HL_CHECK_MASTER))
1747 if (preserve_links && S_ISLNK(file->mode)) {
1748 #ifdef SUPPORT_LINKS
1749 @@ -948,7 +1000,7 @@ static void recv_generator(char *fname,
1750 char lnk[MAXPATHLEN];
1753 - if (!S_ISDIR(st.st_mode)
1754 + if (!S_ISDIR(sx.st.st_mode)
1755 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1757 /* A link already pointing to the
1758 @@ -956,10 +1008,10 @@ static void recv_generator(char *fname,
1760 if (strcmp(lnk, file->u.link) == 0) {
1762 - itemize(file, ndx, 0, &st, 0,
1763 + itemize(file, ndx, 0, &sx, 0,
1766 - set_file_attrs(fname, file, &st,
1767 + set_file_attrs(fname, file, &sx,
1768 maybe_ATTRS_REPORT);
1769 if (preserve_hard_links
1770 && file->link_u.links) {
1771 @@ -972,9 +1024,9 @@ static void recv_generator(char *fname,
1773 /* Not the right symlink (or not a symlink), so
1775 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1776 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1778 - if (!S_ISLNK(st.st_mode))
1779 + if (!S_ISLNK(sx.st.st_mode))
1781 } else if (basis_dir[0] != NULL) {
1782 if (try_dests_non(file, fname, ndx, itemizing,
1783 @@ -990,7 +1042,7 @@ static void recv_generator(char *fname,
1786 if (preserve_hard_links && file->link_u.links
1787 - && hard_link_check(file, ndx, fname, -1, &st,
1788 + && hard_link_check(file, ndx, fname, -1, &sx,
1789 itemizing, code, HL_SKIP))
1791 if (do_symlink(file->u.link,fname) != 0) {
1792 @@ -999,7 +1051,7 @@ static void recv_generator(char *fname,
1794 set_file_attrs(fname, file, NULL, 0);
1796 - itemize(file, ndx, statret, &st,
1797 + itemize(file, ndx, statret, &sx,
1798 ITEM_LOCAL_CHANGE, 0, NULL);
1800 if (code && verbose) {
1801 @@ -1033,18 +1085,22 @@ static void recv_generator(char *fname,
1802 itemizing = code = 0;
1805 +#ifdef SUPPORT_ACLS
1806 + if (preserve_acls && statret == 0)
1807 + get_acl(fname, &sx);
1810 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1811 - || st.st_rdev != file->u.rdev) {
1812 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1813 + || sx.st.st_rdev != file->u.rdev) {
1815 - && delete_item(fname, st.st_mode, del_opts) < 0)
1817 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1819 if (preserve_hard_links && file->link_u.links
1820 - && hard_link_check(file, ndx, fname, -1, &st,
1821 + && hard_link_check(file, ndx, fname, -1, &sx,
1822 itemizing, code, HL_SKIP))
1824 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1825 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1827 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1828 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1831 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1832 @@ -1057,7 +1113,7 @@ static void recv_generator(char *fname,
1834 set_file_attrs(fname, file, NULL, 0);
1836 - itemize(file, ndx, statret, &st,
1837 + itemize(file, ndx, statret, &sx,
1838 ITEM_LOCAL_CHANGE, 0, NULL);
1840 if (code && verbose)
1841 @@ -1069,12 +1125,12 @@ static void recv_generator(char *fname,
1845 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1846 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1847 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1848 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1849 if (preserve_hard_links && file->link_u.links)
1850 hard_link_cluster(file, ndx, itemizing, code);
1856 if (!S_ISREG(file->mode)) {
1857 @@ -1108,7 +1164,7 @@ static void recv_generator(char *fname,
1860 if (update_only && statret == 0
1861 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1862 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1864 rprintf(FINFO, "%s is newer\n", fname);
1866 @@ -1117,18 +1173,18 @@ static void recv_generator(char *fname,
1868 fnamecmp_type = FNAMECMP_FNAME;
1870 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1871 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1872 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1873 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1876 stat_errno = ENOENT;
1879 if (statret != 0 && basis_dir[0] != NULL) {
1880 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1881 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1882 itemizing, maybe_ATTRS_REPORT, code);
1887 fnamecmp = fnamecmpbuf;
1889 @@ -1137,7 +1193,7 @@ static void recv_generator(char *fname,
1896 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1897 && link_stat(partialptr, &partial_st, 0) == 0
1898 @@ -1156,7 +1212,7 @@ static void recv_generator(char *fname,
1899 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1900 fname, fnamecmpbuf);
1902 - st.st_size = fuzzy_file->length;
1903 + sx.st.st_size = fuzzy_file->length;
1905 fnamecmp = fnamecmpbuf;
1906 fnamecmp_type = FNAMECMP_FUZZY;
1907 @@ -1165,7 +1221,7 @@ static void recv_generator(char *fname,
1910 if (preserve_hard_links && file->link_u.links
1911 - && hard_link_check(file, ndx, fname, statret, &st,
1912 + && hard_link_check(file, ndx, fname, statret, &sx,
1913 itemizing, code, HL_SKIP))
1915 if (stat_errno == ENOENT)
1916 @@ -1175,31 +1231,44 @@ static void recv_generator(char *fname,
1920 - if (append_mode && st.st_size > file->length)
1921 + if (append_mode && sx.st.st_size > file->length)
1924 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1926 else if (fnamecmp_type == FNAMECMP_FUZZY)
1928 - else if (unchanged_file(fnamecmp, file, &st)) {
1929 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1931 do_unlink(partialptr);
1932 handle_partial_dir(partialptr, PDIR_DELETE);
1935 - itemize(file, ndx, real_ret, &real_st,
1936 +#ifdef SUPPORT_ACLS
1937 + if (preserve_acls && real_ret == 0)
1938 + get_acl(fname, &real_sx);
1940 + itemize(file, ndx, real_ret, &real_sx,
1942 +#ifdef SUPPORT_ACLS
1943 + if (preserve_acls) {
1944 + if (fnamecmp_type == FNAMECMP_FNAME) {
1945 + sx.acc_acl = real_sx.acc_acl;
1946 + sx.def_acl = real_sx.def_acl;
1948 + free_acl(&real_sx);
1952 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1953 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1954 if (preserve_hard_links && file->link_u.links)
1955 hard_link_cluster(file, ndx, itemizing, code);
1963 + sx.st = partial_st;
1964 fnamecmp = partialptr;
1965 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
1967 @@ -1223,17 +1292,21 @@ static void recv_generator(char *fname,
1969 /* pretend the file didn't exist */
1970 if (preserve_hard_links && file->link_u.links
1971 - && hard_link_check(file, ndx, fname, statret, &st,
1972 + && hard_link_check(file, ndx, fname, statret, &sx,
1973 itemizing, code, HL_SKIP))
1976 statret = real_ret = -1;
1977 +#ifdef SUPPORT_ACLS
1978 + if (preserve_acls && ACL_READY(sx))
1984 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
1985 if (!(backupptr = get_backup_name(fname))) {
1990 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
1992 @@ -1244,7 +1317,7 @@ static void recv_generator(char *fname,
1993 full_fname(backupptr));
1999 if ((f_copy = do_open(backupptr,
2000 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2001 @@ -1252,14 +1325,14 @@ static void recv_generator(char *fname,
2002 full_fname(backupptr));
2008 fnamecmp_type = FNAMECMP_BACKUP;
2012 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2013 - fnamecmp, (double)st.st_size);
2014 + fnamecmp, (double)sx.st.st_size);
2018 @@ -1277,24 +1350,32 @@ static void recv_generator(char *fname,
2019 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2020 if (fnamecmp_type == FNAMECMP_FUZZY)
2021 iflags |= ITEM_XNAME_FOLLOWS;
2022 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2023 +#ifdef SUPPORT_ACLS
2024 + if (preserve_acls && real_ret == 0)
2025 + get_acl(fname, &real_sx);
2027 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2028 fuzzy_file ? fuzzy_file->basename : NULL);
2029 +#ifdef SUPPORT_ACLS
2030 + if (preserve_acls)
2031 + free_acl(&real_sx);
2036 if (preserve_hard_links && file->link_u.links)
2037 hard_link_cluster(file, ndx, itemizing, code);
2045 if (statret != 0 || whole_file) {
2046 write_sum_head(f_out, NULL);
2051 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2052 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2056 @@ -1307,6 +1388,13 @@ static void recv_generator(char *fname,
2062 +#ifdef SUPPORT_ACLS
2063 + if (preserve_acls)
2069 void generate_files(int f_out, struct file_list *flist, char *local_name)
2070 @@ -1366,6 +1454,8 @@ void generate_files(int f_out, struct fi
2071 * notice that and let us know via the redo pipe (or its closing). */
2074 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2076 for (i = 0; i < flist->count; i++) {
2077 struct file_struct *file = flist->files[i];
2084 extern int link_dest;
2085 +extern int preserve_acls;
2086 extern int make_backups;
2087 extern int log_format_has_i;
2088 extern char *basis_dir[];
2089 @@ -143,15 +144,19 @@ void init_hard_links(void)
2091 #ifdef SUPPORT_HARD_LINKS
2092 static int maybe_hard_link(struct file_struct *file, int ndx,
2093 - char *fname, int statret, STRUCT_STAT *st,
2094 + char *fname, int statret, statx *sxp,
2095 char *toname, STRUCT_STAT *to_st,
2096 int itemizing, enum logcode code)
2099 - if (st->st_dev == to_st->st_dev
2100 - && st->st_ino == to_st->st_ino) {
2101 + if (sxp->st.st_dev == to_st->st_dev
2102 + && sxp->st.st_ino == to_st->st_ino) {
2104 - itemize(file, ndx, statret, st,
2105 +#ifdef SUPPORT_ACLS
2106 + if (preserve_acls && !ACL_READY(*sxp))
2107 + get_acl(fname, sxp);
2109 + itemize(file, ndx, statret, sxp,
2110 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2113 @@ -166,13 +171,13 @@ static int maybe_hard_link(struct file_s
2117 - return hard_link_one(file, ndx, fname, statret, st, toname,
2118 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2119 0, itemizing, code);
2123 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2124 - int statret, STRUCT_STAT *st, int itemizing,
2125 + int statret, statx *sxp, int itemizing,
2126 enum logcode code, int skip)
2128 #ifdef SUPPORT_HARD_LINKS
2129 @@ -207,7 +212,7 @@ int hard_link_check(struct file_struct *
2130 || st2.st_ino != st3.st_ino)
2135 if (verbose < 2 || !log_format_has_i)
2136 itemizing = code = 0;
2138 @@ -215,12 +220,16 @@ int hard_link_check(struct file_struct *
2139 if (!unchanged_file(cmpbuf, file, &st3))
2143 - if (unchanged_attrs(file, &st3))
2145 +#ifdef SUPPORT_ACLS
2146 + if (preserve_acls)
2147 + get_acl(cmpbuf, sxp);
2149 + if (unchanged_attrs(file, sxp))
2151 } while (basis_dir[++j] != NULL);
2153 - maybe_hard_link(file, ndx, fname, statret, st,
2154 + maybe_hard_link(file, ndx, fname, statret, sxp,
2155 toname, &st2, itemizing, code);
2156 file->F_HLINDEX = FINISHED_LINK;
2158 @@ -233,7 +242,7 @@ int hard_link_check(struct file_struct *
2160 #ifdef SUPPORT_HARD_LINKS
2161 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2162 - int statret, STRUCT_STAT *st, char *toname, int terse,
2163 + int statret, statx *sxp, char *toname, int terse,
2164 int itemizing, enum logcode code)
2166 if (do_link(toname, fname)) {
2167 @@ -249,7 +258,11 @@ int hard_link_one(struct file_struct *fi
2171 - itemize(file, ndx, statret, st,
2172 +#ifdef SUPPORT_ACLS
2173 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2174 + get_acl(fname, sxp);
2176 + itemize(file, ndx, statret, sxp,
2177 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2178 terse ? "" : toname);
2180 @@ -266,11 +279,12 @@ void hard_link_cluster(struct file_struc
2181 #ifdef SUPPORT_HARD_LINKS
2182 char hlink1[MAXPATHLEN];
2184 - STRUCT_STAT st1, st2;
2187 int statret, ndx = master;
2189 file->F_HLINDEX = FINISHED_LINK;
2190 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2191 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2193 if (!(file->flags & FLAG_HLINK_TOL)) {
2194 while (!(file->flags & FLAG_HLINK_EOL)) {
2195 @@ -284,9 +298,13 @@ void hard_link_cluster(struct file_struc
2196 if (file->F_HLINDEX != SKIPPED_LINK)
2198 hlink2 = f_name(file, NULL);
2199 - statret = link_stat(hlink2, &st2, 0);
2200 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2201 - hlink1, &st1, itemizing, code);
2202 + statret = link_stat(hlink2, &sx.st, 0);
2203 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2204 + hlink1, &st, itemizing, code);
2205 +#ifdef SUPPORT_ACLS
2206 + if (preserve_acls)
2209 file->F_HLINDEX = FINISHED_LINK;
2210 } while (!(file->flags & FLAG_HLINK_EOL));
2212 --- old/lib/sysacls.c
2213 +++ new/lib/sysacls.c
2216 + Unix SMB/CIFS implementation.
2217 + Samba system utilities for ACL support.
2218 + Copyright (C) Jeremy Allison 2000.
2220 + This program is free software; you can redistribute it and/or modify
2221 + it under the terms of the GNU General Public License as published by
2222 + the Free Software Foundation; either version 2 of the License, or
2223 + (at your option) any later version.
2225 + This program is distributed in the hope that it will be useful,
2226 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2227 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2228 + GNU General Public License for more details.
2230 + You should have received a copy of the GNU General Public License
2231 + along with this program; if not, write to the Free Software
2232 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2236 +#include "sysacls.h" /****** ADDED ******/
2238 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2239 +void SAFE_FREE(void *mem)
2245 +char *uidtoname(uid_t uid)
2247 + static char idbuf[12];
2248 + struct passwd *pw;
2250 + if ((pw = getpwuid(uid)) == NULL) {
2251 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2254 + return pw->pw_name;
2256 +/****** EXTRAS -- END ******/
2259 + This file wraps all differing system ACL interfaces into a consistent
2260 + one based on the POSIX interface. It also returns the correct errors
2261 + for older UNIX systems that don't support ACLs.
2263 + The interfaces that each ACL implementation must support are as follows :
2265 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2266 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2267 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2268 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2269 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2270 + SMB_ACL_T sys_acl_get_fd(int fd)
2271 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2272 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2273 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2274 + SMB_ACL_T sys_acl_init( int count)
2275 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2276 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2277 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2278 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2279 + int sys_acl_valid( SMB_ACL_T theacl )
2280 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2281 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2282 + int sys_acl_delete_def_file(const char *path)
2284 + This next one is not POSIX complient - but we *have* to have it !
2285 + More POSIX braindamage.
2287 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2289 + The generic POSIX free is the following call. We split this into
2290 + several different free functions as we may need to add tag info
2291 + to structures when emulating the POSIX interface.
2293 + int sys_acl_free( void *obj_p)
2295 + The calls we actually use are :
2297 + int sys_acl_free_text(char *text) - free acl_to_text
2298 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2299 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2303 +#if defined(HAVE_POSIX_ACLS)
2305 +/* Identity mapping - easy. */
2307 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2309 + return acl_get_entry( the_acl, entry_id, entry_p);
2312 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2314 + return acl_get_tag_type( entry_d, tag_type_p);
2317 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2319 + return acl_get_permset( entry_d, permset_p);
2322 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2324 + return acl_get_qualifier( entry_d);
2327 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2329 + return acl_get_file( path_p, type);
2332 +SMB_ACL_T sys_acl_get_fd(int fd)
2334 + return acl_get_fd(fd);
2337 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2339 + return acl_clear_perms(permset);
2342 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2344 + return acl_add_perm(permset, perm);
2347 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2349 +#if defined(HAVE_ACL_GET_PERM_NP)
2351 + * Required for TrustedBSD-based ACL implementations where
2352 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2355 + return acl_get_perm_np(permset, perm);
2357 + return acl_get_perm(permset, perm);
2361 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2363 + return acl_to_text( the_acl, plen);
2366 +SMB_ACL_T sys_acl_init( int count)
2368 + return acl_init(count);
2371 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2373 + return acl_create_entry(pacl, pentry);
2376 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2378 + return acl_set_tag_type(entry, tagtype);
2381 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2383 + return acl_set_qualifier(entry, qual);
2386 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2388 + return acl_set_permset(entry, permset);
2391 +int sys_acl_valid( SMB_ACL_T theacl )
2393 + return acl_valid(theacl);
2396 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2398 + return acl_set_file(name, acltype, theacl);
2401 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2403 + return acl_set_fd(fd, theacl);
2406 +int sys_acl_delete_def_file(const char *name)
2408 + return acl_delete_def_file(name);
2411 +int sys_acl_free_text(char *text)
2413 + return acl_free(text);
2416 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2418 + return acl_free(the_acl);
2421 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2423 + return acl_free(qual);
2426 +#elif defined(HAVE_TRU64_ACLS)
2428 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2429 + * is based on Draft 13 of the POSIX spec which is
2430 + * slightly different from the Draft 16 interface.
2432 + * Also, some of the permset manipulation functions
2433 + * such as acl_clear_perm() and acl_add_perm() appear
2434 + * to be broken on Tru64 so we have to manipulate
2435 + * the permission bits in the permset directly.
2437 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2439 + SMB_ACL_ENTRY_T entry;
2441 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2446 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2451 + return errno ? -1 : 0;
2454 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2456 + return acl_get_tag_type( entry_d, tag_type_p);
2459 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2461 + return acl_get_permset( entry_d, permset_p);
2464 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2466 + return acl_get_qualifier( entry_d);
2469 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2471 + return acl_get_file((char *)path_p, type);
2474 +SMB_ACL_T sys_acl_get_fd(int fd)
2476 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2479 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2481 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2486 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2488 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2493 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2498 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2500 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2503 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2505 + return acl_to_text( the_acl, plen);
2508 +SMB_ACL_T sys_acl_init( int count)
2510 + return acl_init(count);
2513 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2515 + SMB_ACL_ENTRY_T entry;
2517 + if ((entry = acl_create_entry(pacl)) == NULL) {
2525 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2527 + return acl_set_tag_type(entry, tagtype);
2530 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2532 + return acl_set_qualifier(entry, qual);
2535 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2537 + return acl_set_permset(entry, permset);
2540 +int sys_acl_valid( SMB_ACL_T theacl )
2542 + acl_entry_t entry;
2544 + return acl_valid(theacl, &entry);
2547 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2549 + return acl_set_file((char *)name, acltype, theacl);
2552 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2554 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2557 +int sys_acl_delete_def_file(const char *name)
2559 + return acl_delete_def_file((char *)name);
2562 +int sys_acl_free_text(char *text)
2565 + * (void) cast and explicit return 0 are for DEC UNIX
2566 + * which just #defines acl_free_text() to be free()
2568 + (void) acl_free_text(text);
2572 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2574 + return acl_free(the_acl);
2577 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2579 + return acl_free_qualifier(qual, tagtype);
2582 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2585 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2586 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2590 + * Note that while this code implements sufficient functionality
2591 + * to support the sys_acl_* interfaces it does not provide all
2592 + * of the semantics of the POSIX ACL interfaces.
2594 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2595 + * from a call to sys_acl_get_entry() should not be assumed to be
2596 + * valid after calling any of the following functions, which may
2597 + * reorder the entries in the ACL.
2600 + * sys_acl_set_file()
2601 + * sys_acl_set_fd()
2605 + * The only difference between Solaris and UnixWare / OpenUNIX is
2606 + * that the #defines for the ACL operations have different names
2608 +#if defined(HAVE_UNIXWARE_ACLS)
2610 +#define SETACL ACL_SET
2611 +#define GETACL ACL_GET
2612 +#define GETACLCNT ACL_CNT
2617 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2619 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2624 + if (entry_p == NULL) {
2629 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2633 + if (acl_d->next < 0) {
2638 + if (acl_d->next >= acl_d->count) {
2642 + *entry_p = &acl_d->acl[acl_d->next++];
2647 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2649 + *type_p = entry_d->a_type;
2654 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2656 + *permset_p = &entry_d->a_perm;
2661 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2663 + if (entry_d->a_type != SMB_ACL_USER
2664 + && entry_d->a_type != SMB_ACL_GROUP) {
2669 + return &entry_d->a_id;
2673 + * There is no way of knowing what size the ACL returned by
2674 + * GETACL will be unless you first call GETACLCNT which means
2675 + * making an additional system call.
2677 + * In the hope of avoiding the cost of the additional system
2678 + * call in most cases, we initially allocate enough space for
2679 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2680 + * be too small then we use GETACLCNT to find out the actual
2681 + * size, reallocate the ACL buffer, and then call GETACL again.
2684 +#define INITIAL_ACL_SIZE 16
2686 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2689 + int count; /* # of ACL entries allocated */
2690 + int naccess; /* # of access ACL entries */
2691 + int ndefault; /* # of default ACL entries */
2693 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2698 + count = INITIAL_ACL_SIZE;
2699 + if ((acl_d = sys_acl_init(count)) == NULL) {
2704 + * If there isn't enough space for the ACL entries we use
2705 + * GETACLCNT to determine the actual number of ACL entries
2706 + * reallocate and try again. This is in a loop because it
2707 + * is possible that someone else could modify the ACL and
2708 + * increase the number of entries between the call to
2709 + * GETACLCNT and the call to GETACL.
2711 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2712 + && errno == ENOSPC) {
2714 + sys_acl_free_acl(acl_d);
2716 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2720 + if ((acl_d = sys_acl_init(count)) == NULL) {
2726 + sys_acl_free_acl(acl_d);
2731 + * calculate the number of access and default ACL entries
2733 + * Note: we assume that the acl() system call returned a
2734 + * well formed ACL which is sorted so that all of the
2735 + * access ACL entries preceed any default ACL entries
2737 + for (naccess = 0; naccess < count; naccess++) {
2738 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2741 + ndefault = count - naccess;
2744 + * if the caller wants the default ACL we have to copy
2745 + * the entries down to the start of the acl[] buffer
2746 + * and mask out the ACL_DEFAULT flag from the type field
2748 + if (type == SMB_ACL_TYPE_DEFAULT) {
2751 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2752 + acl_d->acl[i] = acl_d->acl[j];
2753 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2756 + acl_d->count = ndefault;
2758 + acl_d->count = naccess;
2764 +SMB_ACL_T sys_acl_get_fd(int fd)
2767 + int count; /* # of ACL entries allocated */
2768 + int naccess; /* # of access ACL entries */
2770 + count = INITIAL_ACL_SIZE;
2771 + if ((acl_d = sys_acl_init(count)) == NULL) {
2775 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2776 + && errno == ENOSPC) {
2778 + sys_acl_free_acl(acl_d);
2780 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2784 + if ((acl_d = sys_acl_init(count)) == NULL) {
2790 + sys_acl_free_acl(acl_d);
2795 + * calculate the number of access ACL entries
2797 + for (naccess = 0; naccess < count; naccess++) {
2798 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2802 + acl_d->count = naccess;
2807 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2814 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2816 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2817 + && perm != SMB_ACL_EXECUTE) {
2822 + if (permset_d == NULL) {
2827 + *permset_d |= perm;
2832 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2834 + return *permset_d & perm;
2837 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2844 + * use an initial estimate of 20 bytes per ACL entry
2845 + * when allocating memory for the text representation
2849 + maxlen = 20 * acl_d->count;
2850 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2855 + for (i = 0; i < acl_d->count; i++) {
2856 + struct acl *ap = &acl_d->acl[i];
2865 + switch (ap->a_type) {
2867 + * for debugging purposes it's probably more
2868 + * useful to dump unknown tag types rather
2869 + * than just returning an error
2872 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2875 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2880 + case SMB_ACL_USER:
2881 + id = uidtoname(ap->a_id);
2882 + case SMB_ACL_USER_OBJ:
2886 + case SMB_ACL_GROUP:
2887 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2888 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2894 + case SMB_ACL_GROUP_OBJ:
2898 + case SMB_ACL_OTHER:
2902 + case SMB_ACL_MASK:
2908 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2909 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2910 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2913 + /* <tag> : <qualifier> : rwx \n \0 */
2914 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2917 + * If this entry would overflow the buffer
2918 + * allocate enough additional memory for this
2919 + * entry and an estimate of another 20 bytes
2920 + * for each entry still to be processed
2922 + if ((len + nbytes) > maxlen) {
2923 + char *oldtext = text;
2925 + maxlen += nbytes + 20 * (acl_d->count - i);
2927 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2928 + SAFE_FREE(oldtext);
2934 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2935 + len += nbytes - 1;
2944 +SMB_ACL_T sys_acl_init(int count)
2954 + * note that since the definition of the structure pointed
2955 + * to by the SMB_ACL_T includes the first element of the
2956 + * acl[] array, this actually allocates an ACL with room
2957 + * for (count+1) entries
2959 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2964 + a->size = count + 1;
2972 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2975 + SMB_ACL_ENTRY_T entry_d;
2977 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2982 + if (acl_d->count >= acl_d->size) {
2987 + entry_d = &acl_d->acl[acl_d->count++];
2988 + entry_d->a_type = 0;
2989 + entry_d->a_id = -1;
2990 + entry_d->a_perm = 0;
2991 + *entry_p = entry_d;
2996 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2998 + switch (tag_type) {
2999 + case SMB_ACL_USER:
3000 + case SMB_ACL_USER_OBJ:
3001 + case SMB_ACL_GROUP:
3002 + case SMB_ACL_GROUP_OBJ:
3003 + case SMB_ACL_OTHER:
3004 + case SMB_ACL_MASK:
3005 + entry_d->a_type = tag_type;
3015 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3017 + if (entry_d->a_type != SMB_ACL_GROUP
3018 + && entry_d->a_type != SMB_ACL_USER) {
3023 + entry_d->a_id = *((id_t *)qual_p);
3028 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3030 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3034 + entry_d->a_perm = *permset_d;
3040 + * sort the ACL and check it for validity
3042 + * if it's a minimal ACL with only 4 entries then we
3043 + * need to recalculate the mask permissions to make
3044 + * sure that they are the same as the GROUP_OBJ
3045 + * permissions as required by the UnixWare acl() system call.
3047 + * (note: since POSIX allows minimal ACLs which only contain
3048 + * 3 entries - ie there is no mask entry - we should, in theory,
3049 + * check for this and add a mask entry if necessary - however
3050 + * we "know" that the caller of this interface always specifies
3051 + * a mask so, in practice "this never happens" (tm) - if it *does*
3052 + * happen aclsort() will fail and return an error and someone will
3053 + * have to fix it ...)
3056 +static int acl_sort(SMB_ACL_T acl_d)
3058 + int fixmask = (acl_d->count <= 4);
3060 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3067 +int sys_acl_valid(SMB_ACL_T acl_d)
3069 + return acl_sort(acl_d);
3072 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3075 + struct acl *acl_p;
3077 + struct acl *acl_buf = NULL;
3080 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3085 + if (acl_sort(acl_d) != 0) {
3089 + acl_p = &acl_d->acl[0];
3090 + acl_count = acl_d->count;
3093 + * if it's a directory there is extra work to do
3094 + * since the acl() system call will replace both
3095 + * the access ACLs and the default ACLs (if any)
3097 + if (stat(name, &s) != 0) {
3100 + if (S_ISDIR(s.st_mode)) {
3101 + SMB_ACL_T acc_acl;
3102 + SMB_ACL_T def_acl;
3103 + SMB_ACL_T tmp_acl;
3106 + if (type == SMB_ACL_TYPE_ACCESS) {
3108 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3112 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3115 + if (tmp_acl == NULL) {
3120 + * allocate a temporary buffer for the complete ACL
3122 + acl_count = acc_acl->count + def_acl->count;
3123 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3125 + if (acl_buf == NULL) {
3126 + sys_acl_free_acl(tmp_acl);
3132 + * copy the access control and default entries into the buffer
3134 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3135 + acc_acl->count * sizeof(acl_buf[0]));
3137 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3138 + def_acl->count * sizeof(acl_buf[0]));
3141 + * set the ACL_DEFAULT flag on the default entries
3143 + for (i = acc_acl->count; i < acl_count; i++) {
3144 + acl_buf[i].a_type |= ACL_DEFAULT;
3147 + sys_acl_free_acl(tmp_acl);
3149 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3154 + ret = acl(name, SETACL, acl_count, acl_p);
3156 + SAFE_FREE(acl_buf);
3161 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3163 + if (acl_sort(acl_d) != 0) {
3167 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3170 +int sys_acl_delete_def_file(const char *path)
3176 + * fetching the access ACL and rewriting it has
3177 + * the effect of deleting the default ACL
3179 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3183 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3185 + sys_acl_free_acl(acl_d);
3190 +int sys_acl_free_text(char *text)
3196 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3202 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3207 +#elif defined(HAVE_HPUX_ACLS)
3211 + * Based on the Solaris/SCO code - with modifications.
3215 + * Note that while this code implements sufficient functionality
3216 + * to support the sys_acl_* interfaces it does not provide all
3217 + * of the semantics of the POSIX ACL interfaces.
3219 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3220 + * from a call to sys_acl_get_entry() should not be assumed to be
3221 + * valid after calling any of the following functions, which may
3222 + * reorder the entries in the ACL.
3225 + * sys_acl_set_file()
3226 + * sys_acl_set_fd()
3229 +/* This checks if the POSIX ACL system call is defined */
3230 +/* which basically corresponds to whether JFS 3.3 or */
3231 +/* higher is installed. If acl() was called when it */
3232 +/* isn't defined, it causes the process to core dump */
3233 +/* so it is important to check this and avoid acl() */
3234 +/* calls if it isn't there. */
3236 +static BOOL hpux_acl_call_presence(void)
3239 + shl_t handle = NULL;
3242 + static BOOL already_checked=0;
3244 + if(already_checked)
3248 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3250 + if(ret_val != 0) {
3251 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3252 + ret_val, errno, strerror(errno)));
3253 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3257 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3259 + already_checked = True;
3263 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3265 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3270 + if (entry_p == NULL) {
3275 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3279 + if (acl_d->next < 0) {
3284 + if (acl_d->next >= acl_d->count) {
3288 + *entry_p = &acl_d->acl[acl_d->next++];
3293 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3295 + *type_p = entry_d->a_type;
3300 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3302 + *permset_p = &entry_d->a_perm;
3307 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3309 + if (entry_d->a_type != SMB_ACL_USER
3310 + && entry_d->a_type != SMB_ACL_GROUP) {
3315 + return &entry_d->a_id;
3319 + * There is no way of knowing what size the ACL returned by
3320 + * ACL_GET will be unless you first call ACL_CNT which means
3321 + * making an additional system call.
3323 + * In the hope of avoiding the cost of the additional system
3324 + * call in most cases, we initially allocate enough space for
3325 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3326 + * be too small then we use ACL_CNT to find out the actual
3327 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3330 +#define INITIAL_ACL_SIZE 16
3332 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3335 + int count; /* # of ACL entries allocated */
3336 + int naccess; /* # of access ACL entries */
3337 + int ndefault; /* # of default ACL entries */
3339 + if(hpux_acl_call_presence() == False) {
3340 + /* Looks like we don't have the acl() system call on HPUX.
3341 + * May be the system doesn't have the latest version of JFS.
3346 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3351 + count = INITIAL_ACL_SIZE;
3352 + if ((acl_d = sys_acl_init(count)) == NULL) {
3357 + * If there isn't enough space for the ACL entries we use
3358 + * ACL_CNT to determine the actual number of ACL entries
3359 + * reallocate and try again. This is in a loop because it
3360 + * is possible that someone else could modify the ACL and
3361 + * increase the number of entries between the call to
3362 + * ACL_CNT and the call to ACL_GET.
3364 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3366 + sys_acl_free_acl(acl_d);
3368 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3372 + if ((acl_d = sys_acl_init(count)) == NULL) {
3378 + sys_acl_free_acl(acl_d);
3383 + * calculate the number of access and default ACL entries
3385 + * Note: we assume that the acl() system call returned a
3386 + * well formed ACL which is sorted so that all of the
3387 + * access ACL entries preceed any default ACL entries
3389 + for (naccess = 0; naccess < count; naccess++) {
3390 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3393 + ndefault = count - naccess;
3396 + * if the caller wants the default ACL we have to copy
3397 + * the entries down to the start of the acl[] buffer
3398 + * and mask out the ACL_DEFAULT flag from the type field
3400 + if (type == SMB_ACL_TYPE_DEFAULT) {
3403 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3404 + acl_d->acl[i] = acl_d->acl[j];
3405 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3408 + acl_d->count = ndefault;
3410 + acl_d->count = naccess;
3416 +SMB_ACL_T sys_acl_get_fd(int fd)
3419 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3422 + files_struct *fsp = file_find_fd(fd);
3424 + if (fsp == NULL) {
3430 + * We know we're in the same conn context. So we
3431 + * can use the relative path.
3434 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3437 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3444 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3446 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3447 + && perm != SMB_ACL_EXECUTE) {
3452 + if (permset_d == NULL) {
3457 + *permset_d |= perm;
3462 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3464 + return *permset_d & perm;
3467 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3474 + * use an initial estimate of 20 bytes per ACL entry
3475 + * when allocating memory for the text representation
3479 + maxlen = 20 * acl_d->count;
3480 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3485 + for (i = 0; i < acl_d->count; i++) {
3486 + struct acl *ap = &acl_d->acl[i];
3495 + switch (ap->a_type) {
3497 + * for debugging purposes it's probably more
3498 + * useful to dump unknown tag types rather
3499 + * than just returning an error
3502 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3505 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3510 + case SMB_ACL_USER:
3511 + id = uidtoname(ap->a_id);
3512 + case SMB_ACL_USER_OBJ:
3516 + case SMB_ACL_GROUP:
3517 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3518 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3524 + case SMB_ACL_GROUP_OBJ:
3528 + case SMB_ACL_OTHER:
3532 + case SMB_ACL_MASK:
3538 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3539 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3540 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3543 + /* <tag> : <qualifier> : rwx \n \0 */
3544 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3547 + * If this entry would overflow the buffer
3548 + * allocate enough additional memory for this
3549 + * entry and an estimate of another 20 bytes
3550 + * for each entry still to be processed
3552 + if ((len + nbytes) > maxlen) {
3553 + char *oldtext = text;
3555 + maxlen += nbytes + 20 * (acl_d->count - i);
3557 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3564 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3565 + len += nbytes - 1;
3574 +SMB_ACL_T sys_acl_init(int count)
3584 + * note that since the definition of the structure pointed
3585 + * to by the SMB_ACL_T includes the first element of the
3586 + * acl[] array, this actually allocates an ACL with room
3587 + * for (count+1) entries
3589 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3594 + a->size = count + 1;
3602 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3605 + SMB_ACL_ENTRY_T entry_d;
3607 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3612 + if (acl_d->count >= acl_d->size) {
3617 + entry_d = &acl_d->acl[acl_d->count++];
3618 + entry_d->a_type = 0;
3619 + entry_d->a_id = -1;
3620 + entry_d->a_perm = 0;
3621 + *entry_p = entry_d;
3626 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3628 + switch (tag_type) {
3629 + case SMB_ACL_USER:
3630 + case SMB_ACL_USER_OBJ:
3631 + case SMB_ACL_GROUP:
3632 + case SMB_ACL_GROUP_OBJ:
3633 + case SMB_ACL_OTHER:
3634 + case SMB_ACL_MASK:
3635 + entry_d->a_type = tag_type;
3645 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3647 + if (entry_d->a_type != SMB_ACL_GROUP
3648 + && entry_d->a_type != SMB_ACL_USER) {
3653 + entry_d->a_id = *((id_t *)qual_p);
3658 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3660 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3664 + entry_d->a_perm = *permset_d;
3669 +/* Structure to capture the count for each type of ACE. */
3671 +struct hpux_acl_types {
3675 + int n_def_user_obj;
3680 + int n_def_group_obj;
3684 + int n_def_other_obj;
3687 + int n_def_class_obj;
3689 + int n_illegal_obj;
3693 + * Counts the different number of objects in a given array of ACL
3697 + * acl_count - Count of ACLs in the array of ACL strucutres.
3698 + * aclp - Array of ACL structures.
3699 + * acl_type_count - Pointer to acl_types structure. Should already be
3703 + * acl_type_count - This structure is filled up with counts of various
3707 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3711 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3713 + for(i=0;i<acl_count;i++) {
3714 + switch(aclp[i].a_type) {
3716 + acl_type_count->n_user++;
3719 + acl_type_count->n_user_obj++;
3721 + case DEF_USER_OBJ:
3722 + acl_type_count->n_def_user_obj++;
3725 + acl_type_count->n_group++;
3728 + acl_type_count->n_group_obj++;
3730 + case DEF_GROUP_OBJ:
3731 + acl_type_count->n_def_group_obj++;
3734 + acl_type_count->n_other_obj++;
3736 + case DEF_OTHER_OBJ:
3737 + acl_type_count->n_def_other_obj++;
3740 + acl_type_count->n_class_obj++;
3742 + case DEF_CLASS_OBJ:
3743 + acl_type_count->n_def_class_obj++;
3746 + acl_type_count->n_def_user++;
3749 + acl_type_count->n_def_group++;
3752 + acl_type_count->n_illegal_obj++;
3758 +/* swap_acl_entries: Swaps two ACL entries.
3760 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3763 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3765 + struct acl temp_acl;
3767 + temp_acl.a_type = aclp0->a_type;
3768 + temp_acl.a_id = aclp0->a_id;
3769 + temp_acl.a_perm = aclp0->a_perm;
3771 + aclp0->a_type = aclp1->a_type;
3772 + aclp0->a_id = aclp1->a_id;
3773 + aclp0->a_perm = aclp1->a_perm;
3775 + aclp1->a_type = temp_acl.a_type;
3776 + aclp1->a_id = temp_acl.a_id;
3777 + aclp1->a_perm = temp_acl.a_perm;
3780 +/* prohibited_duplicate_type
3781 + * Identifies if given ACL type can have duplicate entries or
3784 + * Inputs: acl_type - ACL Type.
3790 + * True - If the ACL type matches any of the prohibited types.
3791 + * False - If the ACL type doesn't match any of the prohibited types.
3794 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3796 + switch(acl_type) {
3807 +/* get_needed_class_perm
3808 + * Returns the permissions of a ACL structure only if the ACL
3809 + * type matches one of the pre-determined types for computing
3810 + * CLASS_OBJ permissions.
3812 + * Inputs: aclp - Pointer to ACL structure.
3815 +static int hpux_get_needed_class_perm(struct acl *aclp)
3817 + switch(aclp->a_type) {
3821 + case DEF_USER_OBJ:
3823 + case DEF_GROUP_OBJ:
3825 + case DEF_CLASS_OBJ:
3826 + case DEF_OTHER_OBJ:
3827 + return aclp->a_perm;
3833 +/* acl_sort for HPUX.
3834 + * Sorts the array of ACL structures as per the description in
3835 + * aclsort man page. Refer to aclsort man page for more details
3839 + * acl_count - Count of ACLs in the array of ACL structures.
3840 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3842 + * aclp - Array of ACL structures.
3846 + * aclp - Sorted array of ACL structures.
3850 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3851 + * debug log in case of failure.
3854 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3856 +#if !defined(HAVE_HPUX_ACLSORT)
3858 + * The aclsort() system call is availabe on the latest HPUX General
3859 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3860 + * function. Because, we don't want to update to a new
3861 + * HPUX GR bundle just for aclsort() call.
3864 + struct hpux_acl_types acl_obj_count;
3865 + int n_class_obj_perm = 0;
3869 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3873 + if(aclp == NULL) {
3874 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3878 + /* Count different types of ACLs in the ACLs array */
3880 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3882 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3883 + * CLASS_OBJ and OTHER_OBJ
3886 + if( (acl_obj_count.n_user_obj != 1) ||
3887 + (acl_obj_count.n_group_obj != 1) ||
3888 + (acl_obj_count.n_class_obj != 1) ||
3889 + (acl_obj_count.n_other_obj != 1)
3891 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3892 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3896 + /* If any of the default objects are present, there should be only
3897 + * one of them each.
3900 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3901 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3902 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3903 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3907 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3910 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3911 + * same ACL type, sort by ACL id.
3913 + * I am using the trival kind of sorting method here because, performance isn't
3914 + * really effected by the ACLs feature. More over there aren't going to be more
3915 + * than 17 entries on HPUX.
3918 + for(i=0; i<acl_count;i++) {
3919 + for (j=i+1; j<acl_count; j++) {
3920 + if( aclp[i].a_type > aclp[j].a_type ) {
3921 + /* ACL entries out of order, swap them */
3923 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3925 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3927 + /* ACL entries of same type, sort by id */
3929 + if(aclp[i].a_id > aclp[j].a_id) {
3930 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3931 + } else if (aclp[i].a_id == aclp[j].a_id) {
3932 + /* We have a duplicate entry. */
3933 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3934 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3935 + aclp[i].a_type, aclp[i].a_id));
3944 + /* set the class obj permissions to the computed one. */
3946 + int n_class_obj_index = -1;
3948 + for(i=0;i<acl_count;i++) {
3949 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3951 + if(aclp[i].a_type == CLASS_OBJ)
3952 + n_class_obj_index = i;
3954 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3959 + return aclsort(acl_count, calclass, aclp);
3964 + * sort the ACL and check it for validity
3966 + * if it's a minimal ACL with only 4 entries then we
3967 + * need to recalculate the mask permissions to make
3968 + * sure that they are the same as the GROUP_OBJ
3969 + * permissions as required by the UnixWare acl() system call.
3971 + * (note: since POSIX allows minimal ACLs which only contain
3972 + * 3 entries - ie there is no mask entry - we should, in theory,
3973 + * check for this and add a mask entry if necessary - however
3974 + * we "know" that the caller of this interface always specifies
3975 + * a mask so, in practice "this never happens" (tm) - if it *does*
3976 + * happen aclsort() will fail and return an error and someone will
3977 + * have to fix it ...)
3980 +static int acl_sort(SMB_ACL_T acl_d)
3982 + int fixmask = (acl_d->count <= 4);
3984 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3991 +int sys_acl_valid(SMB_ACL_T acl_d)
3993 + return acl_sort(acl_d);
3996 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3999 + struct acl *acl_p;
4001 + struct acl *acl_buf = NULL;
4004 + if(hpux_acl_call_presence() == False) {
4005 + /* Looks like we don't have the acl() system call on HPUX.
4006 + * May be the system doesn't have the latest version of JFS.
4012 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4017 + if (acl_sort(acl_d) != 0) {
4021 + acl_p = &acl_d->acl[0];
4022 + acl_count = acl_d->count;
4025 + * if it's a directory there is extra work to do
4026 + * since the acl() system call will replace both
4027 + * the access ACLs and the default ACLs (if any)
4029 + if (stat(name, &s) != 0) {
4032 + if (S_ISDIR(s.st_mode)) {
4033 + SMB_ACL_T acc_acl;
4034 + SMB_ACL_T def_acl;
4035 + SMB_ACL_T tmp_acl;
4038 + if (type == SMB_ACL_TYPE_ACCESS) {
4040 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4044 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4047 + if (tmp_acl == NULL) {
4052 + * allocate a temporary buffer for the complete ACL
4054 + acl_count = acc_acl->count + def_acl->count;
4055 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4057 + if (acl_buf == NULL) {
4058 + sys_acl_free_acl(tmp_acl);
4064 + * copy the access control and default entries into the buffer
4066 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4067 + acc_acl->count * sizeof(acl_buf[0]));
4069 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4070 + def_acl->count * sizeof(acl_buf[0]));
4073 + * set the ACL_DEFAULT flag on the default entries
4075 + for (i = acc_acl->count; i < acl_count; i++) {
4076 + acl_buf[i].a_type |= ACL_DEFAULT;
4079 + sys_acl_free_acl(tmp_acl);
4081 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4086 + ret = acl(name, ACL_SET, acl_count, acl_p);
4095 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4098 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4101 + files_struct *fsp = file_find_fd(fd);
4103 + if (fsp == NULL) {
4108 + if (acl_sort(acl_d) != 0) {
4113 + * We know we're in the same conn context. So we
4114 + * can use the relative path.
4117 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4120 +int sys_acl_delete_def_file(const char *path)
4126 + * fetching the access ACL and rewriting it has
4127 + * the effect of deleting the default ACL
4129 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4133 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4135 + sys_acl_free_acl(acl_d);
4140 +int sys_acl_free_text(char *text)
4146 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4152 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4157 +#elif defined(HAVE_IRIX_ACLS)
4159 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4161 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4166 + if (entry_p == NULL) {
4171 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4175 + if (acl_d->next < 0) {
4180 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4184 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4189 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4191 + *type_p = entry_d->ae_tag;
4196 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4198 + *permset_p = entry_d;
4203 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4205 + if (entry_d->ae_tag != SMB_ACL_USER
4206 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4211 + return &entry_d->ae_id;
4214 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4218 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4222 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4227 + a->freeaclp = True;
4231 +SMB_ACL_T sys_acl_get_fd(int fd)
4235 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4239 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4244 + a->freeaclp = True;
4248 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4250 + permset_d->ae_perm = 0;
4255 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4257 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4258 + && perm != SMB_ACL_EXECUTE) {
4263 + if (permset_d == NULL) {
4268 + permset_d->ae_perm |= perm;
4273 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4275 + return permset_d->ae_perm & perm;
4278 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4280 + return acl_to_text(acl_d->aclp, len_p);
4283 +SMB_ACL_T sys_acl_init(int count)
4292 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4298 + a->freeaclp = False;
4299 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4300 + a->aclp->acl_cnt = 0;
4306 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4309 + SMB_ACL_ENTRY_T entry_d;
4311 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4316 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4321 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4322 + entry_d->ae_tag = 0;
4323 + entry_d->ae_id = 0;
4324 + entry_d->ae_perm = 0;
4325 + *entry_p = entry_d;
4330 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4332 + switch (tag_type) {
4333 + case SMB_ACL_USER:
4334 + case SMB_ACL_USER_OBJ:
4335 + case SMB_ACL_GROUP:
4336 + case SMB_ACL_GROUP_OBJ:
4337 + case SMB_ACL_OTHER:
4338 + case SMB_ACL_MASK:
4339 + entry_d->ae_tag = tag_type;
4349 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4351 + if (entry_d->ae_tag != SMB_ACL_GROUP
4352 + && entry_d->ae_tag != SMB_ACL_USER) {
4357 + entry_d->ae_id = *((id_t *)qual_p);
4362 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4364 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4368 + entry_d->ae_perm = permset_d->ae_perm;
4373 +int sys_acl_valid(SMB_ACL_T acl_d)
4375 + return acl_valid(acl_d->aclp);
4378 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4380 + return acl_set_file(name, type, acl_d->aclp);
4383 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4385 + return acl_set_fd(fd, acl_d->aclp);
4388 +int sys_acl_delete_def_file(const char *name)
4390 + return acl_delete_def_file(name);
4393 +int sys_acl_free_text(char *text)
4395 + return acl_free(text);
4398 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4400 + if (acl_d->freeaclp) {
4401 + acl_free(acl_d->aclp);
4407 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4412 +#elif defined(HAVE_AIX_ACLS)
4414 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4416 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4418 + struct acl_entry_link *link;
4419 + struct new_acl_entry *entry;
4422 + DEBUG(10,("This is the count: %d\n",theacl->count));
4424 + /* Check if count was previously set to -1. *
4425 + * If it was, that means we reached the end *
4426 + * of the acl last time. */
4427 + if(theacl->count == -1)
4431 + /* To get to the next acl, traverse linked list until index *
4432 + * of acl matches the count we are keeping. This count is *
4433 + * incremented each time we return an acl entry. */
4435 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4436 + link = link->nextp;
4438 + entry = *entry_p = link->entryp;
4440 + DEBUG(10,("*entry_p is %d\n",entry_p));
4441 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4443 + /* Increment count */
4445 + if(link->nextp == NULL)
4446 + theacl->count = -1;
4451 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4453 + /* Initialize tag type */
4456 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4458 + /* Depending on what type of entry we have, *
4459 + * return tag type. */
4460 + switch(entry_d->ace_id->id_type) {
4462 + *tag_type_p = SMB_ACL_USER;
4465 + *tag_type_p = SMB_ACL_GROUP;
4468 + case SMB_ACL_USER_OBJ:
4469 + case SMB_ACL_GROUP_OBJ:
4470 + case SMB_ACL_OTHER:
4471 + *tag_type_p = entry_d->ace_id->id_type;
4481 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4483 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4484 + *permset_p = &entry_d->ace_access;
4485 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4486 + if(!(**permset_p & S_IXUSR) &&
4487 + !(**permset_p & S_IWUSR) &&
4488 + !(**permset_p & S_IRUSR) &&
4489 + (**permset_p != 0))
4492 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4496 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4498 + return(entry_d->ace_id->id_data);
4501 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4503 + struct acl *file_acl = (struct acl *)NULL;
4504 + struct acl_entry *acl_entry;
4505 + struct new_acl_entry *new_acl_entry;
4506 + struct ace_id *idp;
4507 + struct acl_entry_link *acl_entry_link;
4508 + struct acl_entry_link *acl_entry_link_head;
4513 + /* AIX has no DEFAULT */
4514 + if ( type == SMB_ACL_TYPE_DEFAULT )
4517 + /* Get the acl using statacl */
4519 + DEBUG(10,("Entering sys_acl_get_file\n"));
4520 + DEBUG(10,("path_p is %s\n",path_p));
4522 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4524 + if(file_acl == NULL) {
4526 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4530 + memset(file_acl,0,BUFSIZ);
4532 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4534 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4535 + SAFE_FREE(file_acl);
4539 + DEBUG(10,("Got facl and returned it\n"));
4541 + /* Point to the first acl entry in the acl */
4542 + acl_entry = file_acl->acl_ext;
4544 + /* Begin setting up the head of the linked list *
4545 + * that will be used for the storing the acl *
4546 + * in a way that is useful for the posix_acls.c *
4549 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4550 + if(acl_entry_link_head == NULL)
4553 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4554 + if(acl_entry_link->entryp == NULL) {
4555 + SAFE_FREE(file_acl);
4557 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4561 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4562 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4564 + /* Check if the extended acl bit is on. *
4565 + * If it isn't, do not show the *
4566 + * contents of the acl since AIX intends *
4567 + * the extended info to remain unused */
4569 + if(file_acl->acl_mode & S_IXACL){
4570 + /* while we are not pointing to the very end */
4571 + while(acl_entry < acl_last(file_acl)) {
4572 + /* before we malloc anything, make sure this is */
4573 + /* a valid acl entry and one that we want to map */
4574 + idp = id_nxt(acl_entry->ace_id);
4575 + if((acl_entry->ace_type == ACC_SPECIFY ||
4576 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4577 + acl_entry = acl_nxt(acl_entry);
4581 + idp = acl_entry->ace_id;
4583 + /* Check if this is the first entry in the linked list. *
4584 + * The first entry needs to keep prevp pointing to NULL *
4585 + * and already has entryp allocated. */
4587 + if(acl_entry_link_head->count != 0) {
4588 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4590 + if(acl_entry_link->nextp == NULL) {
4591 + SAFE_FREE(file_acl);
4593 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4597 + acl_entry_link->nextp->prevp = acl_entry_link;
4598 + acl_entry_link = acl_entry_link->nextp;
4599 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4600 + if(acl_entry_link->entryp == NULL) {
4601 + SAFE_FREE(file_acl);
4603 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4606 + acl_entry_link->nextp = NULL;
4609 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4611 + /* Don't really need this since all types are going *
4612 + * to be specified but, it's better than leaving it 0 */
4614 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4616 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4618 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4620 + /* The access in the acl entries must be left shifted by *
4621 + * three bites, because they will ultimately be compared *
4622 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4624 + switch(acl_entry->ace_type){
4627 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4628 + acl_entry_link->entryp->ace_access <<= 6;
4629 + acl_entry_link_head->count++;
4632 + /* Since there is no way to return a DENY acl entry *
4633 + * change to PERMIT and then shift. */
4634 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4635 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4636 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4637 + acl_entry_link->entryp->ace_access <<= 6;
4638 + acl_entry_link_head->count++;
4644 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4645 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4647 + acl_entry = acl_nxt(acl_entry);
4649 + } /* end of if enabled */
4651 + /* Since owner, group, other acl entries are not *
4652 + * part of the acl entries in an acl, they must *
4653 + * be dummied up to become part of the list. */
4655 + for( i = 1; i < 4; i++) {
4656 + DEBUG(10,("i is %d\n",i));
4657 + if(acl_entry_link_head->count != 0) {
4658 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4659 + if(acl_entry_link->nextp == NULL) {
4660 + SAFE_FREE(file_acl);
4662 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4666 + acl_entry_link->nextp->prevp = acl_entry_link;
4667 + acl_entry_link = acl_entry_link->nextp;
4668 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4669 + if(acl_entry_link->entryp == NULL) {
4670 + SAFE_FREE(file_acl);
4672 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4677 + acl_entry_link->nextp = NULL;
4679 + new_acl_entry = acl_entry_link->entryp;
4680 + idp = new_acl_entry->ace_id;
4682 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4683 + new_acl_entry->ace_type = ACC_PERMIT;
4684 + idp->id_len = sizeof(struct ace_id);
4685 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4686 + memset(idp->id_data,0,sizeof(uid_t));
4690 + new_acl_entry->ace_access = file_acl->g_access << 6;
4691 + idp->id_type = SMB_ACL_GROUP_OBJ;
4695 + new_acl_entry->ace_access = file_acl->o_access << 6;
4696 + idp->id_type = SMB_ACL_OTHER;
4700 + new_acl_entry->ace_access = file_acl->u_access << 6;
4701 + idp->id_type = SMB_ACL_USER_OBJ;
4709 + acl_entry_link_head->count++;
4710 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4713 + acl_entry_link_head->count = 0;
4714 + SAFE_FREE(file_acl);
4716 + return(acl_entry_link_head);
4719 +SMB_ACL_T sys_acl_get_fd(int fd)
4721 + struct acl *file_acl = (struct acl *)NULL;
4722 + struct acl_entry *acl_entry;
4723 + struct new_acl_entry *new_acl_entry;
4724 + struct ace_id *idp;
4725 + struct acl_entry_link *acl_entry_link;
4726 + struct acl_entry_link *acl_entry_link_head;
4731 + /* Get the acl using fstatacl */
4733 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4734 + DEBUG(10,("fd is %d\n",fd));
4735 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4737 + if(file_acl == NULL) {
4739 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4743 + memset(file_acl,0,BUFSIZ);
4745 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4747 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4748 + SAFE_FREE(file_acl);
4752 + DEBUG(10,("Got facl and returned it\n"));
4754 + /* Point to the first acl entry in the acl */
4756 + acl_entry = file_acl->acl_ext;
4757 + /* Begin setting up the head of the linked list *
4758 + * that will be used for the storing the acl *
4759 + * in a way that is useful for the posix_acls.c *
4762 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4763 + if(acl_entry_link_head == NULL){
4764 + SAFE_FREE(file_acl);
4768 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4770 + if(acl_entry_link->entryp == NULL) {
4772 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4773 + SAFE_FREE(file_acl);
4777 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4778 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4780 + /* Check if the extended acl bit is on. *
4781 + * If it isn't, do not show the *
4782 + * contents of the acl since AIX intends *
4783 + * the extended info to remain unused */
4785 + if(file_acl->acl_mode & S_IXACL){
4786 + /* while we are not pointing to the very end */
4787 + while(acl_entry < acl_last(file_acl)) {
4788 + /* before we malloc anything, make sure this is */
4789 + /* a valid acl entry and one that we want to map */
4791 + idp = id_nxt(acl_entry->ace_id);
4792 + if((acl_entry->ace_type == ACC_SPECIFY ||
4793 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4794 + acl_entry = acl_nxt(acl_entry);
4798 + idp = acl_entry->ace_id;
4800 + /* Check if this is the first entry in the linked list. *
4801 + * The first entry needs to keep prevp pointing to NULL *
4802 + * and already has entryp allocated. */
4804 + if(acl_entry_link_head->count != 0) {
4805 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4806 + if(acl_entry_link->nextp == NULL) {
4808 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4809 + SAFE_FREE(file_acl);
4812 + acl_entry_link->nextp->prevp = acl_entry_link;
4813 + acl_entry_link = acl_entry_link->nextp;
4814 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4815 + if(acl_entry_link->entryp == NULL) {
4817 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4818 + SAFE_FREE(file_acl);
4822 + acl_entry_link->nextp = NULL;
4825 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4827 + /* Don't really need this since all types are going *
4828 + * to be specified but, it's better than leaving it 0 */
4830 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4831 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4833 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4835 + /* The access in the acl entries must be left shifted by *
4836 + * three bites, because they will ultimately be compared *
4837 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4839 + switch(acl_entry->ace_type){
4842 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4843 + acl_entry_link->entryp->ace_access <<= 6;
4844 + acl_entry_link_head->count++;
4847 + /* Since there is no way to return a DENY acl entry *
4848 + * change to PERMIT and then shift. */
4849 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4850 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4851 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4852 + acl_entry_link->entryp->ace_access <<= 6;
4853 + acl_entry_link_head->count++;
4859 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4860 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4862 + acl_entry = acl_nxt(acl_entry);
4864 + } /* end of if enabled */
4866 + /* Since owner, group, other acl entries are not *
4867 + * part of the acl entries in an acl, they must *
4868 + * be dummied up to become part of the list. */
4870 + for( i = 1; i < 4; i++) {
4871 + DEBUG(10,("i is %d\n",i));
4872 + if(acl_entry_link_head->count != 0){
4873 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4874 + if(acl_entry_link->nextp == NULL) {
4876 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4877 + SAFE_FREE(file_acl);
4881 + acl_entry_link->nextp->prevp = acl_entry_link;
4882 + acl_entry_link = acl_entry_link->nextp;
4883 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4885 + if(acl_entry_link->entryp == NULL) {
4886 + SAFE_FREE(file_acl);
4888 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4893 + acl_entry_link->nextp = NULL;
4895 + new_acl_entry = acl_entry_link->entryp;
4896 + idp = new_acl_entry->ace_id;
4898 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4899 + new_acl_entry->ace_type = ACC_PERMIT;
4900 + idp->id_len = sizeof(struct ace_id);
4901 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4902 + memset(idp->id_data,0,sizeof(uid_t));
4906 + new_acl_entry->ace_access = file_acl->g_access << 6;
4907 + idp->id_type = SMB_ACL_GROUP_OBJ;
4911 + new_acl_entry->ace_access = file_acl->o_access << 6;
4912 + idp->id_type = SMB_ACL_OTHER;
4916 + new_acl_entry->ace_access = file_acl->u_access << 6;
4917 + idp->id_type = SMB_ACL_USER_OBJ;
4924 + acl_entry_link_head->count++;
4925 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4928 + acl_entry_link_head->count = 0;
4929 + SAFE_FREE(file_acl);
4931 + return(acl_entry_link_head);
4934 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4936 + *permset = *permset & ~0777;
4940 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4943 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4947 + DEBUG(10,("This is the permset now: %d\n",*permset));
4951 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4956 +SMB_ACL_T sys_acl_init( int count)
4958 + struct acl_entry_link *theacl = NULL;
4960 + DEBUG(10,("Entering sys_acl_init\n"));
4962 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4963 + if(theacl == NULL) {
4965 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4969 + theacl->count = 0;
4970 + theacl->nextp = NULL;
4971 + theacl->prevp = NULL;
4972 + theacl->entryp = NULL;
4973 + DEBUG(10,("Exiting sys_acl_init\n"));
4977 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4979 + struct acl_entry_link *theacl;
4980 + struct acl_entry_link *acl_entryp;
4981 + struct acl_entry_link *temp_entry;
4984 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4986 + theacl = acl_entryp = *pacl;
4988 + /* Get to the end of the acl before adding entry */
4990 + for(counting=0; counting < theacl->count; counting++){
4991 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4992 + temp_entry = acl_entryp;
4993 + acl_entryp = acl_entryp->nextp;
4996 + if(theacl->count != 0){
4997 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4998 + if(acl_entryp == NULL) {
5000 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5004 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5005 + acl_entryp->prevp = temp_entry;
5006 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5009 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5010 + if(*pentry == NULL) {
5012 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5016 + memset(*pentry,0,sizeof(struct new_acl_entry));
5017 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5018 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5019 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5020 + acl_entryp->nextp = NULL;
5022 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5026 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5028 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5029 + entry->ace_id->id_type = tagtype;
5030 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5031 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5034 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5036 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5037 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5038 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5042 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5044 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5045 + if(!(*permset & S_IXUSR) &&
5046 + !(*permset & S_IWUSR) &&
5047 + !(*permset & S_IRUSR) &&
5051 + entry->ace_access = *permset;
5052 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5053 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5057 +int sys_acl_valid( SMB_ACL_T theacl )
5060 + int group_obj = 0;
5061 + int other_obj = 0;
5062 + struct acl_entry_link *acl_entry;
5064 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5065 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5066 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5067 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5070 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5072 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5078 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5080 + struct acl_entry_link *acl_entry_link = NULL;
5081 + struct acl *file_acl = NULL;
5082 + struct acl *file_acl_temp = NULL;
5083 + struct acl_entry *acl_entry = NULL;
5084 + struct ace_id *ace_id = NULL;
5091 + DEBUG(10,("Entering sys_acl_set_file\n"));
5092 + DEBUG(10,("File name is %s\n",name));
5094 + /* AIX has no default ACL */
5095 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5098 + acl_length = BUFSIZ;
5099 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5101 + if(file_acl == NULL) {
5103 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5107 + memset(file_acl,0,BUFSIZ);
5109 + file_acl->acl_len = ACL_SIZ;
5110 + file_acl->acl_mode = S_IXACL;
5112 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5113 + acl_entry_link->entryp->ace_access >>= 6;
5114 + id_type = acl_entry_link->entryp->ace_id->id_type;
5117 + case SMB_ACL_USER_OBJ:
5118 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5120 + case SMB_ACL_GROUP_OBJ:
5121 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5123 + case SMB_ACL_OTHER:
5124 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5126 + case SMB_ACL_MASK:
5130 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5131 + acl_length += sizeof(struct acl_entry);
5132 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5133 + if(file_acl_temp == NULL) {
5134 + SAFE_FREE(file_acl);
5136 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5140 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5141 + SAFE_FREE(file_acl);
5142 + file_acl = file_acl_temp;
5145 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5146 + file_acl->acl_len += sizeof(struct acl_entry);
5147 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5148 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5150 + /* In order to use this, we'll need to wait until we can get denies */
5151 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5152 + acl_entry->ace_type = ACC_SPECIFY; */
5154 + acl_entry->ace_type = ACC_SPECIFY;
5156 + ace_id = acl_entry->ace_id;
5158 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5159 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5160 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5161 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5162 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5165 + rc = chacl(name,file_acl,file_acl->acl_len);
5166 + DEBUG(10,("errno is %d\n",errno));
5167 + DEBUG(10,("return code is %d\n",rc));
5168 + SAFE_FREE(file_acl);
5169 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5173 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5175 + struct acl_entry_link *acl_entry_link = NULL;
5176 + struct acl *file_acl = NULL;
5177 + struct acl *file_acl_temp = NULL;
5178 + struct acl_entry *acl_entry = NULL;
5179 + struct ace_id *ace_id = NULL;
5185 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5186 + acl_length = BUFSIZ;
5187 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5189 + if(file_acl == NULL) {
5191 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5195 + memset(file_acl,0,BUFSIZ);
5197 + file_acl->acl_len = ACL_SIZ;
5198 + file_acl->acl_mode = S_IXACL;
5200 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5201 + acl_entry_link->entryp->ace_access >>= 6;
5202 + id_type = acl_entry_link->entryp->ace_id->id_type;
5203 + DEBUG(10,("The id_type is %d\n",id_type));
5206 + case SMB_ACL_USER_OBJ:
5207 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5209 + case SMB_ACL_GROUP_OBJ:
5210 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5212 + case SMB_ACL_OTHER:
5213 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5215 + case SMB_ACL_MASK:
5219 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5220 + acl_length += sizeof(struct acl_entry);
5221 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5222 + if(file_acl_temp == NULL) {
5223 + SAFE_FREE(file_acl);
5225 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5229 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5230 + SAFE_FREE(file_acl);
5231 + file_acl = file_acl_temp;
5234 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5235 + file_acl->acl_len += sizeof(struct acl_entry);
5236 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5237 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5239 + /* In order to use this, we'll need to wait until we can get denies */
5240 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5241 + acl_entry->ace_type = ACC_SPECIFY; */
5243 + acl_entry->ace_type = ACC_SPECIFY;
5245 + ace_id = acl_entry->ace_id;
5247 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5248 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5249 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5250 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5251 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5254 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5255 + DEBUG(10,("errno is %d\n",errno));
5256 + DEBUG(10,("return code is %d\n",rc));
5257 + SAFE_FREE(file_acl);
5258 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5262 +int sys_acl_delete_def_file(const char *name)
5264 + /* AIX has no default ACL */
5268 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5270 + return(*permset & perm);
5273 +int sys_acl_free_text(char *text)
5278 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5280 + struct acl_entry_link *acl_entry_link;
5282 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5283 + SAFE_FREE(acl_entry_link->prevp->entryp);
5284 + SAFE_FREE(acl_entry_link->prevp);
5287 + SAFE_FREE(acl_entry_link->prevp->entryp);
5288 + SAFE_FREE(acl_entry_link->prevp);
5289 + SAFE_FREE(acl_entry_link->entryp);
5290 + SAFE_FREE(acl_entry_link);
5295 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5300 +#else /* No ACLs. */
5302 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5308 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5314 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5320 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5326 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5329 + return (SMB_ACL_T)NULL;
5332 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5335 + return (SMB_ACL_T)NULL;
5338 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5344 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5350 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5353 + return (permset & perm) ? 1 : 0;
5356 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5362 +int sys_acl_free_text(UNUSED(char *text))
5368 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5374 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5380 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5386 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5392 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5398 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5404 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5410 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5416 +int sys_acl_delete_def_file(UNUSED(const char *name))
5422 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5428 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5434 +#endif /* No ACLs. */
5436 +/************************************************************************
5437 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5439 +************************************************************************/
5441 +int no_acl_syscall_error(int err)
5443 +#if defined(ENOSYS)
5444 + if (err == ENOSYS) {
5448 +#if defined(ENOTSUP)
5449 + if (err == ENOTSUP) {
5455 --- old/lib/sysacls.h
5456 +++ new/lib/sysacls.h
5458 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5459 +#include <sys/acl.h>
5461 +#include "smb_acls.h"
5463 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5464 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5465 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5466 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5467 +#define slprintf snprintf
5469 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5470 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5471 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5472 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5473 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5474 +SMB_ACL_T sys_acl_get_fd(int fd);
5475 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5476 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5477 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5478 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5479 +SMB_ACL_T sys_acl_init(int count);
5480 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5481 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5482 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5483 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5484 +int sys_acl_valid(SMB_ACL_T theacl);
5485 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5486 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5487 +int sys_acl_delete_def_file(const char *name);
5488 +int sys_acl_free_text(char *text);
5489 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5490 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5493 @@ -603,8 +603,10 @@ static void log_formatted(enum logcode c
5494 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5495 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5496 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5499 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5500 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5501 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5504 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5505 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5508 @@ -58,7 +58,7 @@ BEGIN {
5512 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5513 +!/^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/ {
5519 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5521 int preserve_links = 0;
5522 int preserve_hard_links = 0;
5523 +int preserve_acls = 0;
5524 int preserve_perms = 0;
5525 int preserve_executability = 0;
5526 int preserve_devices = 0;
5527 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
5528 char const *got_socketpair = "no ";
5529 char const *have_inplace = "no ";
5530 char const *hardlinks = "no ";
5531 + char const *acls = "no ";
5532 char const *links = "no ";
5533 char const *ipv6 = "no ";
5534 STRUCT_STAT *dumstat;
5535 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
5539 +#ifdef SUPPORT_ACLS
5543 #ifdef SUPPORT_LINKS
5546 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
5547 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5548 rprintf(f, "<http://rsync.samba.org/>\n");
5549 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5550 - "%shard links, %ssymlinks, batchfiles,\n",
5551 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
5552 (int) (sizeof (OFF_T) * 8),
5553 - got_socketpair, hardlinks, links);
5554 + got_socketpair, hardlinks, acls, links);
5556 /* Note that this field may not have type ino_t. It depends
5557 * on the complicated interaction between largefile feature
5558 @@ -295,6 +301,9 @@ void usage(enum logcode F)
5559 rprintf(F," -H, --hard-links preserve hard links\n");
5560 rprintf(F," -p, --perms preserve permissions\n");
5561 rprintf(F," -E, --executability preserve the file's executability\n");
5562 +#ifdef SUPPORT_ACLS
5563 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5565 rprintf(F," --chmod=CHMOD change destination permissions\n");
5566 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5567 rprintf(F," -g, --group preserve group\n");
5568 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
5569 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5570 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5571 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5572 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5573 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5574 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5575 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5576 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5577 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5578 @@ -1070,6 +1082,24 @@ int parse_arguments(int *argc, const cha
5583 +#ifdef SUPPORT_ACLS
5585 + preserve_perms = 1;
5588 + /* FIXME: this should probably be ignored with a
5589 + * warning and then countermeasures taken to
5590 + * restrict group and other access in the presence
5591 + * of any more restrictive ACLs, but this is safe
5593 + snprintf(err_buf,sizeof(err_buf),
5594 + "ACLs are not supported on this %s\n",
5595 + am_server ? "server" : "client");
5601 /* A large opt value means that set_refuse_options()
5602 * turned this option off. */
5603 @@ -1504,6 +1534,10 @@ void server_options(char **args,int *arg
5605 if (preserve_hard_links)
5607 +#ifdef SUPPORT_ACLS
5608 + if (preserve_acls)
5609 + argstr[x++] = 'A';
5616 @@ -48,6 +48,7 @@ extern int keep_partial;
5617 extern int checksum_seed;
5619 extern int delay_updates;
5620 +extern mode_t orig_umask;
5621 extern struct stats stats;
5622 extern char *log_format;
5623 extern char *tmpdir;
5624 @@ -346,6 +347,10 @@ int recv_files(int f_in, struct file_lis
5625 int itemizing = am_daemon ? daemon_log_format_has_i
5626 : !am_server && log_format_has_i;
5627 int max_phase = protocol_version >= 29 ? 2 : 1;
5628 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5629 +#ifdef SUPPORT_ACLS
5630 + char *parent_dirname = "";
5635 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5636 * mode based on the local permissions and some heuristics. */
5637 if (!preserve_perms) {
5638 int exists = fd1 != -1;
5639 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5640 +#ifdef SUPPORT_ACLS
5641 + char *dn = file->dirname ? file->dirname : ".";
5642 + if (parent_dirname != dn
5643 + && strcmp(parent_dirname, dn) != 0) {
5644 + dflt_perms = default_perms_for_dir(dn);
5645 + parent_dirname = dn;
5648 + file->mode = dest_mode(file->mode, st.st_mode,
5649 + dflt_perms, exists);
5652 /* We now check to see if we are writing file "inplace" */
5658 extern int daemon_log_format_has_i;
5659 +extern int preserve_acls;
5660 extern int preserve_perms;
5661 extern int preserve_executability;
5662 extern int preserve_times;
5663 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5665 /* This is only called when we aren't preserving permissions. Figure out what
5666 * the permissions should be and return them merged back into the mode. */
5667 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5668 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5671 /* If the file already exists, we'll return the local permissions,
5672 * possibly tweaked by the --executability option. */
5673 @@ -116,55 +118,63 @@ mode_t dest_mode(mode_t flist_mode, mode
5674 cur_mode |= (cur_mode & 0444) >> 2;
5677 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5678 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5679 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5680 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5681 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5684 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5685 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5691 int change_uid, change_gid;
5697 - if (link_stat(fname, &st2, 0) < 0) {
5698 + if (link_stat(fname, &sx2.st, 0) < 0) {
5699 rsyserr(FERROR, errno, "stat %s failed",
5704 +#ifdef SUPPORT_ACLS
5705 + sx2.acc_acl = sx2.def_acl = NULL;
5707 if (!preserve_perms && S_ISDIR(file->mode)
5708 - && st->st_mode & S_ISGID) {
5709 + && sx2.st.st_mode & S_ISGID) {
5710 /* We just created this directory and its setgid
5711 * bit is on, so make sure it stays on. */
5712 file->mode |= S_ISGID;
5717 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5718 +#ifdef SUPPORT_ACLS
5719 + if (preserve_acls && !ACL_READY(*sxp))
5720 + get_acl(fname, sxp);
5723 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5724 flags |= ATTRS_SKIP_MTIME;
5725 if (!(flags & ATTRS_SKIP_MTIME)
5726 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5727 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5728 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5729 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5731 rsyserr(FERROR, errno, "failed to set times on %s",
5736 if (ret == 0) /* ret == 1 if symlink could not be set */
5740 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5741 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5742 change_gid = preserve_gid && file->gid != GID_NONE
5743 - && st->st_gid != file->gid;
5744 + && sxp->st.st_gid != file->gid;
5745 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5746 - if (S_ISLNK(st->st_mode))
5747 + if (S_ISLNK(sxp->st.st_mode))
5751 @@ -174,43 +184,55 @@ int set_file_attrs(char *fname, struct f
5753 "set uid of %s from %ld to %ld\n",
5755 - (long)st->st_uid, (long)file->uid);
5756 + (long)sxp->st.st_uid, (long)file->uid);
5760 "set gid of %s from %ld to %ld\n",
5762 - (long)st->st_gid, (long)file->gid);
5763 + (long)sxp->st.st_gid, (long)file->gid);
5766 if (do_lchown(fname,
5767 - change_uid ? file->uid : st->st_uid,
5768 - change_gid ? file->gid : st->st_gid) != 0) {
5769 + change_uid ? file->uid : sxp->st.st_uid,
5770 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5771 /* shouldn't have attempted to change uid or gid
5772 * unless have the privilege */
5773 rsyserr(FERROR, errno, "%s %s failed",
5774 change_uid ? "chown" : "chgrp",
5779 /* a lchown had been done - we have to re-stat if the
5780 * destination had the setuid or setgid bits set due
5781 * to the side effect of the chown call */
5782 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5783 - link_stat(fname, st,
5784 - keep_dirlinks && S_ISDIR(st->st_mode));
5785 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5786 + link_stat(fname, &sxp->st,
5787 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5792 +#ifdef SUPPORT_ACLS
5793 + /* It's OK to call set_acl() now, even for a dir, as the generator
5794 + * will enable owner-writability using chmod, if necessary.
5796 + * If set_acl() changes permission bits in the process of setting
5797 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5798 + * need to chmod(). */
5799 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5804 - if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5805 - int ret = do_chmod(fname, file->mode);
5806 + if ((sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5807 + mode_t mode = file->mode;
5808 + int ret = do_chmod(fname, mode);
5810 rsyserr(FERROR, errno,
5811 "failed to set permissions on %s",
5816 if (ret == 0) /* ret == 1 if symlink could not be set */
5818 @@ -225,6 +247,11 @@ int set_file_attrs(char *fname, struct f
5820 rprintf(code, "%s is uptodate\n", fname);
5823 +#ifdef SUPPORT_ACLS
5824 + if (preserve_acls && sxp == &sx2)
5832 @@ -485,6 +485,15 @@ struct idev {
5833 #define IN_LOOPBACKNET 127
5836 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5837 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5838 +#define SUPPORT_ACLS 1
5841 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5842 +#define ACLS_NEED_MASK 1
5845 #define GID_NONE ((gid_t)-1)
5847 #define HL_CHECK_MASTER 0
5848 @@ -645,6 +654,17 @@ struct stats {
5850 struct chmod_mode_struct;
5852 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5860 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5861 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5863 #include "byteorder.h"
5864 #include "lib/mdfour.h"
5865 #include "lib/wildmatch.h"
5866 @@ -660,6 +680,16 @@ struct chmod_mode_struct;
5868 #define UNUSED(x) x __attribute__((__unused__))
5872 +#ifdef SUPPORT_ACLS
5873 + struct rsync_acl *acc_acl; /* access ACL */
5874 + struct rsync_acl *def_acl; /* default ACL */
5878 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5882 /* We have replacement versions of these if they're missing. */
5885 @@ -321,6 +321,7 @@ to the detailed description below for a
5886 -H, --hard-links preserve hard links
5887 -p, --perms preserve permissions
5888 -E, --executability preserve executability
5889 + -A, --acls preserve ACLs (implies -p) [non-standard]
5890 --chmod=CHMOD change destination permissions
5891 -o, --owner preserve owner (super-user only)
5892 -g, --group preserve group
5893 @@ -742,7 +743,9 @@ quote(itemize(
5894 permissions, though the bf(--executability) option might change just
5895 the execute permission for the file.
5896 it() New files get their "normal" permission bits set to the source
5897 - file's permissions masked with the receiving end's umask setting, and
5898 + file's permissions masked with the receiving directory's default
5899 + permissions (either the receiving process's umask, or the permissions
5900 + specified via the destination directory's default ACL), and
5901 their special permission bits disabled except in the case where a new
5902 directory inherits a setgid bit from its parent directory.
5904 @@ -773,9 +776,11 @@ The preservation of the destination's se
5905 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5906 versions erroneously preserved the three special permission bits for
5907 newly-created files when bf(--perms) was off, while overriding the
5908 -destination's setgid bit setting on a newly-created directory. (Keep in
5909 -mind that it is the version of the receiving rsync that affects this
5911 +destination's setgid bit setting on a newly-created directory. Default ACL
5912 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5913 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5914 +(Keep in mind that it is the version of the receiving rsync that affects
5917 dit(bf(-E, --executability)) This option causes rsync to preserve the
5918 executability (or non-executability) of regular files when bf(--perms) is
5919 @@ -793,6 +798,15 @@ quote(itemize(
5921 If bf(--perms) is enabled, this option is ignored.
5923 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5924 +ACLs to be the same as the source ACLs. This nonstandard option only
5925 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5927 +Note also that an optimization of the ACL-sending protocol used by this
5928 +version makes it incompatible with sending files to an older ACL-enabled
5929 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5930 +doubling is not needed when pulling files from an older rsync.
5932 dit(bf(--chmod)) This option tells rsync to apply one or more
5933 comma-separated "chmod" strings to the permission of the files in the
5934 transfer. The resulting value is treated as though it was the permissions
5935 @@ -1372,8 +1386,8 @@ if the receiving rsync is at least versi
5936 with older versions of rsync, but that also turns on the output of other
5939 -The "%i" escape has a cryptic output that is 9 letters long. The general
5940 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
5941 +The "%i" escape has a cryptic output that is 11 letters long. The general
5942 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
5943 type of update being done, bf(X) is replaced by the file-type, and the
5944 other letters represent attributes that may be output if they are being
5946 @@ -1422,7 +1436,11 @@ quote(itemize(
5947 sender's value (requires bf(--owner) and super-user privileges).
5948 it() A bf(g) means the group is different and is being updated to the
5949 sender's value (requires bf(--group) and the authority to set the group).
5950 - it() The bf(z) slot is reserved for future use.
5951 + it() The bf(u) slot is reserved for reporting update (access) time changes
5952 + (a feature that is not yet released).
5953 + it() The bf(a) means that the ACL information changed.
5954 + it() The bf(x) slot is reserved for reporting extended attribute changes
5955 + (a feature that is not yet released).
5958 One other output is possible: when deleting files, the "%i" will output
5963 + Unix SMB/Netbios implementation.
5965 + Portable SMB ACL interface
5966 + Copyright (C) Jeremy Allison 2000
5968 + This program is free software; you can redistribute it and/or modify
5969 + it under the terms of the GNU General Public License as published by
5970 + the Free Software Foundation; either version 2 of the License, or
5971 + (at your option) any later version.
5973 + This program is distributed in the hope that it will be useful,
5974 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5975 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5976 + GNU General Public License for more details.
5978 + You should have received a copy of the GNU General Public License
5979 + along with this program; if not, write to the Free Software
5980 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5983 +#ifndef _SMB_ACLS_H
5984 +#define _SMB_ACLS_H
5986 +#if defined HAVE_POSIX_ACLS
5988 +/* This is an identity mapping (just remove the SMB_). */
5990 +#define SMB_ACL_TAG_T acl_tag_t
5991 +#define SMB_ACL_TYPE_T acl_type_t
5992 +#define SMB_ACL_PERMSET_T acl_permset_t
5993 +#define SMB_ACL_PERM_T acl_perm_t
5994 +#define SMB_ACL_READ ACL_READ
5995 +#define SMB_ACL_WRITE ACL_WRITE
5996 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5998 +/* Types of ACLs. */
5999 +#define SMB_ACL_USER ACL_USER
6000 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6001 +#define SMB_ACL_GROUP ACL_GROUP
6002 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6003 +#define SMB_ACL_OTHER ACL_OTHER
6004 +#define SMB_ACL_MASK ACL_MASK
6006 +#define SMB_ACL_T acl_t
6008 +#define SMB_ACL_ENTRY_T acl_entry_t
6010 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6011 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6013 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6014 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6016 +#elif defined HAVE_TRU64_ACLS
6018 +/* This is for DEC/Compaq Tru64 UNIX */
6020 +#define SMB_ACL_TAG_T acl_tag_t
6021 +#define SMB_ACL_TYPE_T acl_type_t
6022 +#define SMB_ACL_PERMSET_T acl_permset_t
6023 +#define SMB_ACL_PERM_T acl_perm_t
6024 +#define SMB_ACL_READ ACL_READ
6025 +#define SMB_ACL_WRITE ACL_WRITE
6026 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6028 +/* Types of ACLs. */
6029 +#define SMB_ACL_USER ACL_USER
6030 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6031 +#define SMB_ACL_GROUP ACL_GROUP
6032 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6033 +#define SMB_ACL_OTHER ACL_OTHER
6034 +#define SMB_ACL_MASK ACL_MASK
6036 +#define SMB_ACL_T acl_t
6038 +#define SMB_ACL_ENTRY_T acl_entry_t
6040 +#define SMB_ACL_FIRST_ENTRY 0
6041 +#define SMB_ACL_NEXT_ENTRY 1
6043 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6044 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6046 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6048 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6049 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6052 +/* SVR4.2 ES/MP ACLs */
6053 +typedef int SMB_ACL_TAG_T;
6054 +typedef int SMB_ACL_TYPE_T;
6055 +typedef ushort *SMB_ACL_PERMSET_T;
6056 +typedef ushort SMB_ACL_PERM_T;
6057 +#define SMB_ACL_READ 4
6058 +#define SMB_ACL_WRITE 2
6059 +#define SMB_ACL_EXECUTE 1
6061 +/* Types of ACLs. */
6062 +#define SMB_ACL_USER USER
6063 +#define SMB_ACL_USER_OBJ USER_OBJ
6064 +#define SMB_ACL_GROUP GROUP
6065 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6066 +#define SMB_ACL_OTHER OTHER_OBJ
6067 +#define SMB_ACL_MASK CLASS_OBJ
6069 +typedef struct SMB_ACL_T {
6073 + struct acl acl[1];
6076 +typedef struct acl *SMB_ACL_ENTRY_T;
6078 +#define SMB_ACL_FIRST_ENTRY 0
6079 +#define SMB_ACL_NEXT_ENTRY 1
6081 +#define SMB_ACL_TYPE_ACCESS 0
6082 +#define SMB_ACL_TYPE_DEFAULT 1
6085 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6088 +#elif defined HAVE_HPUX_ACLS
6091 + * Based on the Solaris & UnixWare code.
6095 +#include <sys/aclv.h>
6097 +/* SVR4.2 ES/MP ACLs */
6098 +typedef int SMB_ACL_TAG_T;
6099 +typedef int SMB_ACL_TYPE_T;
6100 +typedef ushort *SMB_ACL_PERMSET_T;
6101 +typedef ushort SMB_ACL_PERM_T;
6102 +#define SMB_ACL_READ 4
6103 +#define SMB_ACL_WRITE 2
6104 +#define SMB_ACL_EXECUTE 1
6106 +/* Types of ACLs. */
6107 +#define SMB_ACL_USER USER
6108 +#define SMB_ACL_USER_OBJ USER_OBJ
6109 +#define SMB_ACL_GROUP GROUP
6110 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6111 +#define SMB_ACL_OTHER OTHER_OBJ
6112 +#define SMB_ACL_MASK CLASS_OBJ
6114 +typedef struct SMB_ACL_T {
6118 + struct acl acl[1];
6121 +typedef struct acl *SMB_ACL_ENTRY_T;
6123 +#define SMB_ACL_FIRST_ENTRY 0
6124 +#define SMB_ACL_NEXT_ENTRY 1
6126 +#define SMB_ACL_TYPE_ACCESS 0
6127 +#define SMB_ACL_TYPE_DEFAULT 1
6129 +#elif defined HAVE_IRIX_ACLS
6131 +#define SMB_ACL_TAG_T acl_tag_t
6132 +#define SMB_ACL_TYPE_T acl_type_t
6133 +#define SMB_ACL_PERMSET_T acl_permset_t
6134 +#define SMB_ACL_PERM_T acl_perm_t
6135 +#define SMB_ACL_READ ACL_READ
6136 +#define SMB_ACL_WRITE ACL_WRITE
6137 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6139 +/* Types of ACLs. */
6140 +#define SMB_ACL_USER ACL_USER
6141 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6142 +#define SMB_ACL_GROUP ACL_GROUP
6143 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6144 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6145 +#define SMB_ACL_MASK ACL_MASK
6147 +typedef struct SMB_ACL_T {
6153 +#define SMB_ACL_ENTRY_T acl_entry_t
6155 +#define SMB_ACL_FIRST_ENTRY 0
6156 +#define SMB_ACL_NEXT_ENTRY 1
6158 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6159 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6161 +#elif defined HAVE_AIX_ACLS
6163 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6165 +#include "/usr/include/acl.h"
6167 +typedef uint *SMB_ACL_PERMSET_T;
6169 +struct acl_entry_link{
6170 + struct acl_entry_link *prevp;
6171 + struct new_acl_entry *entryp;
6172 + struct acl_entry_link *nextp;
6176 +struct new_acl_entry{
6177 + unsigned short ace_len;
6178 + unsigned short ace_type;
6179 + unsigned int ace_access;
6180 + struct ace_id ace_id[1];
6183 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6184 +#define SMB_ACL_T struct acl_entry_link*
6186 +#define SMB_ACL_TAG_T unsigned short
6187 +#define SMB_ACL_TYPE_T int
6188 +#define SMB_ACL_PERM_T uint
6189 +#define SMB_ACL_READ S_IRUSR
6190 +#define SMB_ACL_WRITE S_IWUSR
6191 +#define SMB_ACL_EXECUTE S_IXUSR
6193 +/* Types of ACLs. */
6194 +#define SMB_ACL_USER ACEID_USER
6195 +#define SMB_ACL_USER_OBJ 3
6196 +#define SMB_ACL_GROUP ACEID_GROUP
6197 +#define SMB_ACL_GROUP_OBJ 4
6198 +#define SMB_ACL_OTHER 5
6199 +#define SMB_ACL_MASK 6
6202 +#define SMB_ACL_FIRST_ENTRY 1
6203 +#define SMB_ACL_NEXT_ENTRY 2
6205 +#define SMB_ACL_TYPE_ACCESS 0
6206 +#define SMB_ACL_TYPE_DEFAULT 1
6208 +#else /* No ACLs. */
6210 +/* No ACLS - fake it. */
6211 +#define SMB_ACL_TAG_T int
6212 +#define SMB_ACL_TYPE_T int
6213 +#define SMB_ACL_PERMSET_T mode_t
6214 +#define SMB_ACL_PERM_T mode_t
6215 +#define SMB_ACL_READ S_IRUSR
6216 +#define SMB_ACL_WRITE S_IWUSR
6217 +#define SMB_ACL_EXECUTE S_IXUSR
6219 +/* Types of ACLs. */
6220 +#define SMB_ACL_USER 0
6221 +#define SMB_ACL_USER_OBJ 1
6222 +#define SMB_ACL_GROUP 2
6223 +#define SMB_ACL_GROUP_OBJ 3
6224 +#define SMB_ACL_OTHER 4
6225 +#define SMB_ACL_MASK 5
6227 +typedef struct SMB_ACL_T {
6231 +typedef struct SMB_ACL_ENTRY_T {
6233 +} *SMB_ACL_ENTRY_T;
6235 +#define SMB_ACL_FIRST_ENTRY 0
6236 +#define SMB_ACL_NEXT_ENTRY 1
6238 +#define SMB_ACL_TYPE_ACCESS 0
6239 +#define SMB_ACL_TYPE_DEFAULT 1
6241 +#endif /* No ACLs. */
6242 +#endif /* _SMB_ACLS_H */
6245 @@ -78,3 +78,7 @@ struct filter_list_struct server_filter_
6249 + const char *who_am_i(void)
6253 --- old/testsuite/acls.test
6254 +++ new/testsuite/acls.test
6258 +# This program is distributable under the terms of the GNU GPL (see
6261 +# Test that rsync handles basic ACL preservation.
6263 +. $srcdir/testsuite/rsync.fns
6265 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6266 +case "$setfacl_nodef" in
6267 +true) test_skipped "I don't know how to use your setfacl command" ;;
6270 +makepath "$fromdir/foo"
6271 +echo something >"$fromdir/file1"
6272 +echo else >"$fromdir/file2"
6274 +files='foo file1 file2'
6276 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6277 +setfacl -m u:0:5 "$fromdir/file1"
6278 +setfacl -m u:0:5 "$fromdir/file2"
6280 +$RSYNC -avvA "$fromdir/" "$todir/"
6283 +getfacl $files >"$scratchdir/acls.txt"
6286 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6288 +# The script would have aborted on error, so getting here means we've won.
6290 --- old/testsuite/default-acls.test
6291 +++ new/testsuite/default-acls.test
6295 +# This program is distributable under the terms of the GNU GPL (see
6298 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6300 +. $srcdir/testsuite/rsync.fns
6302 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6303 +case "$setfacl_nodef" in
6304 +true) test_skipped "I don't know how to use your setfacl command" ;;
6305 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6306 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6308 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6310 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6312 + todir="$scratchdir/$1"
6314 + $setfacl_nodef "$todir"
6316 + case "$setfacl_nodef" in
6317 + *-k*) opts="-dm $2" ;;
6318 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6320 + setfacl $opts "$todir"
6322 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6323 + # even though the directory itself is outside the transfer
6324 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6325 + check_perms "$todir/to" $4 "Target $1"
6326 + check_perms "$todir/to/dir" $4 "Target $1"
6327 + check_perms "$todir/to/file" $3 "Target $1"
6328 + check_perms "$todir/to/program" $4 "Target $1"
6329 + # Make sure get_local_name doesn't mess us up when transferring only one file
6330 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6331 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6332 + # Make sure we obey default ACLs when not transferring a regular file
6333 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6334 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6337 +mkdir "$scratchdir/dir"
6338 +echo "File!" >"$scratchdir/file"
6339 +echo "#!/bin/sh" >"$scratchdir/program"
6340 +chmod 777 "$scratchdir/dir"
6341 +chmod 666 "$scratchdir/file"
6342 +chmod 777 "$scratchdir/program"
6344 +# Test some target directories
6346 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6347 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6348 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6349 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6350 +testit noda1 '' rw------- rwx------
6352 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6354 +testit noda3 '' rw-r--r-- rwxr-xr-x
6358 --- old/testsuite/devices.test
6359 +++ new/testsuite/devices.test
6360 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6361 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6363 cat <<EOT >"$chkfile"
6367 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6369 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6371 cat <<EOT >"$chkfile"
6375 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6377 @@ -58,7 +58,7 @@ sleep 1
6378 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6380 cat <<EOT >"$chkfile"
6384 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6386 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6389 cat <<EOT >"$chkfile"
6394 -hD+++++++ block2.5 => block3
6403 +hD+++++++++ block2.5 => block3
6409 if test ! -b "$fromdir/block2.5"; then
6410 sed -e '/block2\.5/d' \
6411 --- old/testsuite/itemize.test
6412 +++ new/testsuite/itemize.test
6413 @@ -29,14 +29,14 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6414 $RSYNC -iplr "$fromdir/" "$todir/" \
6416 cat <<EOT >"$chkfile"
6419 ->f+++++++ bar/baz/rsync
6421 ->f+++++++ foo/config1
6422 ->f+++++++ foo/config2
6423 ->f+++++++ foo/extra
6424 -cL+++++++ foo/sym -> ../bar/baz/rsync
6426 +cd+++++++++ bar/baz/
6427 +>f+++++++++ bar/baz/rsync
6429 +>f+++++++++ foo/config1
6430 +>f+++++++++ foo/config2
6431 +>f+++++++++ foo/extra
6432 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6434 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6436 @@ -48,10 +48,10 @@ chmod 601 "$fromdir/foo/config2"
6437 $RSYNC -iplrH "$fromdir/" "$todir/" \
6439 cat <<EOT >"$chkfile"
6440 ->f..T.... bar/baz/rsync
6441 ->f..T.... foo/config1
6442 ->f.sTp... foo/config2
6443 -hf..T.... foo/extra => foo/config1
6444 +>f..T...... bar/baz/rsync
6445 +>f..T...... foo/config1
6446 +>f.sTp..... foo/config2
6447 +hf..T...... foo/extra => foo/config1
6449 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6451 @@ -68,11 +68,11 @@ chmod 777 "$todir/bar/baz/rsync"
6452 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6454 cat <<EOT >"$chkfile"
6455 -.f..tp... bar/baz/rsync
6457 -.f..t.... foo/config1
6458 ->fcstp... foo/config2
6459 -cL..T.... foo/sym -> ../bar/baz/rsync
6460 +.f..tp..... bar/baz/rsync
6462 +.f..t...... foo/config1
6463 +>fcstp..... foo/config2
6464 +cL..T...... foo/sym -> ../bar/baz/rsync
6466 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6468 @@ -97,15 +97,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6471 cat <<EOT >"$chkfile"
6475 -.f...p... bar/baz/rsync
6478 ->f..t.... foo/config2
6480 -.L foo/sym -> ../bar/baz/rsync
6484 +.f...p..... bar/baz/rsync
6487 +>f..t...... foo/config2
6489 +.L foo/sym -> ../bar/baz/rsync
6491 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6493 @@ -124,8 +124,8 @@ touch "$todir/foo/config2"
6494 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6496 cat <<EOT >"$chkfile"
6497 -.f...p... foo/config1
6498 ->f..t.... foo/config2
6499 +.f...p..... foo/config1
6500 +>f..t...... foo/config2
6502 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6504 @@ -134,15 +134,15 @@ $RSYNC -ivvplrtH --copy-dest="$lddir" "$
6507 cat <<EOT >"$chkfile"
6515 -hf foo/extra => foo/config1
6516 -cL..T.... foo/sym -> ../bar/baz/rsync
6519 +cd+++++++++ bar/baz/
6524 +hf foo/extra => foo/config1
6525 +cL..T...... foo/sym -> ../bar/baz/rsync
6527 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6529 @@ -150,11 +150,11 @@ rm -rf "$todir"
6530 $RSYNC -iplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
6532 cat <<EOT >"$chkfile"
6537 -hf foo/extra => foo/config1
6540 +cd+++++++++ bar/baz/
6542 +hf foo/extra => foo/config1
6544 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6546 @@ -181,15 +181,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6549 cat <<EOT >"$chkfile"
6557 -hf foo/extra => foo/config1
6558 -hL foo/sym -> ../bar/baz/rsync
6561 +cd+++++++++ bar/baz/
6566 +hf foo/extra => foo/config1
6567 +hL foo/sym -> ../bar/baz/rsync
6569 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6571 @@ -197,10 +197,10 @@ rm -rf "$todir"
6572 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
6574 cat <<EOT >"$chkfile"
6581 +cd+++++++++ bar/baz/
6584 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6586 @@ -228,14 +228,14 @@ filter_outfile
6587 # TODO fix really-old problem when combining -H with --compare-dest:
6588 # missing output for foo/extra hard-link (and it might not be updated)!
6589 cat <<EOT >"$chkfile"
6597 -.L foo/sym -> ../bar/baz/rsync
6600 +cd+++++++++ bar/baz/
6605 +.L foo/sym -> ../bar/baz/rsync
6607 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
6609 @@ -243,10 +243,10 @@ rm -rf "$todir"
6610 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6612 cat <<EOT >"$chkfile"
6619 +cd+++++++++ bar/baz/
6622 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6628 extern int preserve_uid;
6629 extern int preserve_gid;
6630 +extern int preserve_acls;
6631 extern int numeric_ids;
6634 @@ -275,7 +276,7 @@ void send_uid_list(int f)
6638 - if (preserve_uid) {
6639 + if (preserve_uid || preserve_acls) {
6641 /* we send sequences of uid/byte-length/name */
6642 for (list = uidlist; list; list = list->next) {
6643 @@ -292,7 +293,7 @@ void send_uid_list(int f)
6647 - if (preserve_gid) {
6648 + if (preserve_gid || preserve_acls) {
6650 for (list = gidlist; list; list = list->next) {
6652 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
6656 - if (preserve_uid && !numeric_ids) {
6657 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6658 /* read the uid list */
6659 while ((id = read_int(f)) != 0) {
6660 int len = read_byte(f);
6661 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
6665 - if (preserve_gid && !numeric_ids) {
6666 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6667 /* read the gid list */
6668 while ((id = read_int(f)) != 0) {
6669 int len = read_byte(f);
6670 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
6674 +#ifdef SUPPORT_ACLS
6675 + if (preserve_acls && !numeric_ids) {
6677 + while ((id = next_acl_uid(flist)) != NULL)
6678 + *id = match_uid(*id);
6679 + while ((id = next_acl_gid(flist)) != NULL)
6680 + *id = match_gid(*id);
6684 /* Now convert all the uids/gids from sender values to our values. */
6685 if (am_root && preserve_uid && !numeric_ids) {
6686 for (i = 0; i < flist->count; i++)
6689 @@ -1446,3 +1446,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6694 +void *expand_item_list(item_list *lp, size_t item_size,
6695 + const char *desc, int incr)
6697 + /* First time through, 0 <= 0, so list is expanded. */
6698 + if (lp->malloced <= lp->count) {
6700 + size_t new_size = lp->malloced;
6702 + new_size -= incr; /* increase slowly */
6703 + else if (new_size < (size_t)incr)
6707 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6708 + if (verbose >= 4) {
6709 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6710 + who_am_i(), desc, (double)new_size * item_size,
6711 + new_ptr == lp->items ? " not" : "");
6714 + out_of_memory("expand_item_list");
6716 + lp->items = new_ptr;
6717 + lp->malloced = new_size;
6719 + return (char*)lp->items + (lp->count++ * item_size);