1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 @@ -26,15 +26,15 @@ VERSION=@VERSION@
16 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
17 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
18 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
19 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
20 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
21 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
22 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
23 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
24 main.o checksum.o match.o syscall.o log.o backup.o
25 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
26 - fileio.o batch.o clientname.o chmod.o
27 + fileio.o batch.o clientname.o chmod.o acls.o
28 OBJS3=progress.o pipe.o
29 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
30 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 + * Handle passing Access Control Lists between systems.
37 + * Copyright (C) 1996 Andrew Tridgell
38 + * Copyright (C) 1996 Paul Mackerras
39 + * Copyright (C) 2006 Wayne Davison
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License as published by
43 + * the Free Software Foundation; either version 2 of the License, or
44 + * (at your option) any later version.
46 + * This program is distributed in the hope that it will be useful,
47 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 + * GNU General Public License for more details.
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
57 +#include "lib/sysacls.h"
63 +extern int 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 + racl->other = mode & 7;
166 +/* === Rsync ACL functions === */
168 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
170 + id_access *ida1, *ida2;
171 + int count = ial1->count;
172 + if (count != ial2->count)
176 + for (; count--; ida1++, ida2++) {
177 + if (ida1->access != ida2->access || ida1->id != ida2->id)
183 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
185 + return racl1->user_obj == racl2->user_obj
186 + && racl1->group_obj == racl2->group_obj
187 + && racl1->mask == racl2->mask
188 + && racl1->other == racl2->other
189 + && ida_entries_equal(&racl1->users, &racl2->users)
190 + && ida_entries_equal(&racl1->groups, &racl2->groups);
193 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
194 + * the ACL will be handled by the normal mode-preservation code. This is
195 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
196 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
197 + * that it might have several of its permission objects set to NO_ENTRY. */
198 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
199 + const rsync_acl *racl2, mode_t m)
201 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
202 + return False; /* One has a mask and the other doesn't */
204 + /* When there's a mask, the group_obj becomes an extended entry. */
205 + if (racl1->mask != NO_ENTRY) {
206 + /* A condensed rsync_acl with a mask can only have no
207 + * group_obj when it was identical to the mask. This
208 + * means that it was also identical to the group attrs
209 + * from the mode. */
210 + if (racl2->group_obj == NO_ENTRY) {
211 + if (racl1->group_obj != ((m >> 3) & 7))
213 + } else if (racl1->group_obj != racl2->group_obj)
216 + return ida_entries_equal(&racl1->users, &racl2->users)
217 + && ida_entries_equal(&racl1->groups, &racl2->groups);
220 +static void rsync_acl_free(rsync_acl *racl)
222 + if (racl->users.idas)
223 + free(racl->users.idas);
224 + if (racl->groups.idas)
225 + free(racl->groups.idas);
226 + *racl = empty_rsync_acl;
229 +void free_acl(statx *sxp)
231 + if (sxp->acc_acl) {
232 + rsync_acl_free(sxp->acc_acl);
233 + free(sxp->acc_acl);
234 + sxp->acc_acl = NULL;
236 + if (sxp->def_acl) {
237 + rsync_acl_free(sxp->def_acl);
238 + free(sxp->def_acl);
239 + sxp->def_acl = NULL;
243 +static int id_access_sorter(const void *r1, const void *r2)
245 + id_access *ida1 = (id_access *)r1;
246 + id_access *ida2 = (id_access *)r2;
247 + id_t rid1 = ida1->id, rid2 = ida2->id;
248 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
251 +static void sort_ida_entries(ida_entries *idal)
255 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
258 +/* Transfer the count id_access items out of the temp_ida_list into either
259 + * the users or groups ida_entries list in racl. */
260 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
265 + if (temp_ida_list->count) {
266 + int cnt = temp_ida_list->count;
267 + id_access *temp_idas = temp_ida_list->items;
268 + if (!(idas = new_array(id_access, cnt)))
269 + out_of_memory("save_idas");
270 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
274 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
277 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
278 + exit_cleanup(RERR_UNSUPPORTED);
280 + ent->count = temp_ida_list->count;
283 + /* Truncate the temporary list now that its idas have been saved. */
284 + temp_ida_list->count = 0;
287 +/* === System ACLs === */
289 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
290 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
292 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
293 + SMB_ACL_TAG_T prior_list_type = 0;
294 + SMB_ACL_ENTRY_T entry;
295 + const char *errfun;
298 + *racl = empty_rsync_acl;
299 + errfun = "sys_acl_get_entry";
300 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
302 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
303 + SMB_ACL_TAG_T tag_type;
304 + SMB_ACL_PERMSET_T permset;
308 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
309 + errfun = "sys_acl_get_tag_type";
312 + if ((rc = sys_acl_get_permset(entry, &permset))) {
313 + errfun = "sys_acl_get_tag_type";
316 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
317 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
318 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
319 + /* continue == done with entry; break == store in temporary ida list */
320 + switch (tag_type) {
321 + case SMB_ACL_USER_OBJ:
322 + if (racl->user_obj == NO_ENTRY)
323 + racl->user_obj = access;
325 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
329 + case SMB_ACL_GROUP_OBJ:
330 + if (racl->group_obj == NO_ENTRY)
331 + racl->group_obj = access;
333 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
335 + case SMB_ACL_GROUP:
338 + if (racl->mask == NO_ENTRY)
339 + racl->mask = access;
341 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
343 + case SMB_ACL_OTHER:
344 + if (racl->other == NO_ENTRY)
345 + racl->other = access;
347 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
350 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
353 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
354 + errfun = "sys_acl_get_tag_type";
358 + if (tag_type != prior_list_type) {
359 + if (prior_list_type)
360 + save_idas(&temp_ida_list, racl, prior_list_type);
361 + prior_list_type = tag_type;
363 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
364 + ida->id = *((id_t *)qualifier);
365 + ida->access = access;
366 + sys_acl_free_qualifier(qualifier, tag_type);
369 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
370 + rsync_acl_free(racl);
373 + if (prior_list_type)
374 + save_idas(&temp_ida_list, racl, prior_list_type);
376 + sort_ida_entries(&racl->users);
377 + sort_ida_entries(&racl->groups);
379 +#ifdef ACLS_NEED_MASK
380 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
381 + /* Throw away a superfluous mask, but mask off the
382 + * group perms with it first. */
383 + racl->group_obj &= racl->mask;
384 + racl->mask = NO_ENTRY;
391 +/* Synactic sugar for system calls */
393 +#define CALL_OR_ERROR(func,args,str) \
401 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
402 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
404 +/* Store the permissions in the system ACL entry. */
405 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
407 + const char *errfun = NULL;
408 + SMB_ACL_PERMSET_T permset;
410 + COE( sys_acl_get_permset,(entry, &permset) );
411 + COE( sys_acl_clear_perms,(permset) );
413 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
415 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
417 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
418 + COE( sys_acl_set_permset,(entry, permset) );
423 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
427 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
428 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
430 +#ifdef ACLS_NEED_MASK
435 + const char *errfun = NULL;
436 + SMB_ACL_ENTRY_T entry;
438 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
439 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
443 + COE( sys_acl_create_entry,(smb_acl, &entry) );
444 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
445 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
447 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
448 + COE( sys_acl_create_entry,(smb_acl, &entry) );
449 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
450 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
451 + COE2( store_access_in_entry,(ida->access, entry) );
454 + COE( sys_acl_create_entry,(smb_acl, &entry) );
455 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
456 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
458 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
459 + COE( sys_acl_create_entry,(smb_acl, &entry) );
460 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
461 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
462 + COE2( store_access_in_entry,(ida->access, entry) );
465 +#ifdef ACLS_NEED_MASK
466 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
467 + COE( sys_acl_create_entry,(smb_acl, &entry) );
468 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
469 + COE2( store_access_in_entry,(mask_bits, entry) );
471 + if (racl->mask != NO_ENTRY) {
472 + COE( sys_acl_create_entry,(smb_acl, &entry) );
473 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
474 + COE2( store_access_in_entry,(racl->mask, entry) );
478 + COE( sys_acl_create_entry,(smb_acl, &entry) );
479 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
480 + COE2( store_access_in_entry,(racl->other & 7, entry) );
483 + if (sys_acl_valid(*smb_acl) < 0)
484 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
491 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
493 + sys_acl_free_acl(*smb_acl);
497 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
498 + const item_list *racl_list,
499 + const rsync_acl *racl)
501 + static int access_match = -1, default_match = -1;
502 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
503 + size_t count = racl_list->count;
505 + /* If this is the first time through or we didn't match the last
506 + * time, then start at the end of the list, which should be the
507 + * best place to start hunting. */
509 + *match = racl_list->count - 1;
511 + rsync_acl *base = racl_list->items;
512 + if (rsync_acl_equal(base + *match, racl))
515 + *match = racl_list->count - 1;
522 +/* Return the Access Control List for the given filename. */
523 +int get_acl(const char *fname, statx *sxp)
525 + SMB_ACL_TYPE_T type;
527 + if (S_ISLNK(sxp->st.st_mode))
530 + type = SMB_ACL_TYPE_ACCESS;
532 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
533 + rsync_acl *racl = new(rsync_acl);
536 + out_of_memory("get_acl");
537 + if (type == SMB_ACL_TYPE_ACCESS)
538 + sxp->acc_acl = racl;
540 + sxp->def_acl = racl;
543 + BOOL ok = unpack_smb_acl(racl, sacl);
545 + sys_acl_free_acl(sacl);
550 + } else if (errno == ENOTSUP) {
551 + /* ACLs are not supported, so pretend we have a basic ACL. */
552 + *racl = empty_rsync_acl;
553 + if (type == SMB_ACL_TYPE_ACCESS)
554 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
556 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
557 + fname, str_acl_type(type));
561 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
566 +/* === Send functions === */
568 +/* The general strategy with the tag_type <-> character mapping is that
569 + * lowercase implies that no qualifier follows, where uppercase does.
570 + * A similar idiom for the ACL type (access or default) itself, but
571 + * lowercase in this instance means there's no ACL following, so the
572 + * ACL is a repeat, so the receiver should reuse the last of the same
575 +/* Send the ida list over the file descriptor. */
576 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
579 + size_t count = idal->count;
580 + for (ida = idal->idas; count--; ida++) {
581 + write_byte(f, tag_char);
582 + write_byte(f, ida->access);
583 + write_int(f, ida->id);
584 + /* FIXME: sorta wasteful: we should maybe buffer as
585 + * many ids as max(ACL_USER + ACL_GROUP) objects to
586 + * keep from making so many calls. */
587 + if (tag_char == 'U')
594 +/* Send an rsync ACL over the file descriptor. */
595 +static void send_rsync_acl(int f, const rsync_acl *racl)
597 + size_t count = count_racl_entries(racl);
598 + write_int(f, count);
599 + if (racl->user_obj != NO_ENTRY) {
600 + write_byte(f, 'u');
601 + write_byte(f, racl->user_obj);
603 + send_ida_entries(f, &racl->users, 'U');
604 + if (racl->group_obj != NO_ENTRY) {
605 + write_byte(f, 'g');
606 + write_byte(f, racl->group_obj);
608 + send_ida_entries(f, &racl->groups, 'G');
609 + if (racl->mask != NO_ENTRY) {
610 + write_byte(f, 'm');
611 + write_byte(f, racl->mask);
613 + if (racl->other != NO_ENTRY) {
614 + write_byte(f, 'o');
615 + write_byte(f, racl->other);
619 +/* Send the ACL from the statx structure down the indicated file descriptor.
620 + * This also frees the ACL data. */
621 +void send_acl(statx *sxp, int f)
623 + SMB_ACL_TYPE_T type;
624 + rsync_acl *racl, *new_racl;
625 + item_list *racl_list;
628 + if (S_ISLNK(sxp->st.st_mode))
631 + type = SMB_ACL_TYPE_ACCESS;
632 + racl = sxp->acc_acl;
633 + racl_list = &access_acl_list;
636 + racl = new(rsync_acl);
638 + out_of_memory("send_acl");
639 + *racl = empty_rsync_acl;
640 + if (type == SMB_ACL_TYPE_ACCESS) {
641 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
642 + sxp->acc_acl = racl;
644 + sxp->def_acl = racl;
647 + /* Avoid sending values that can be inferred from other data,
648 + * but only when preserve_acls == 1 (it is 2 when we must be
649 + * backward compatible with older acls.diff versions). */
650 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
651 + rsync_acl_strip_perms(racl);
652 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
653 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
656 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
657 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
658 + send_rsync_acl(f, racl);
660 + *racl = empty_rsync_acl;
662 + racl = sxp->def_acl;
663 + racl_list = &default_acl_list;
664 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
669 +/* === Receive functions === */
671 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
673 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
674 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
675 + uchar computed_mask_bits = 0;
679 + *racl = empty_rsync_acl;
681 + if (!(count = read_int(f)))
685 + char tag = read_byte(f);
686 + uchar access = read_byte(f);
687 + if (access & ~ (4 | 2 | 1)) {
688 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
690 + exit_cleanup(RERR_STREAMIO);
694 + if (racl->user_obj != NO_ENTRY) {
695 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
696 + exit_cleanup(RERR_STREAMIO);
698 + racl->user_obj = access;
701 + tag_type = SMB_ACL_USER;
704 + if (racl->group_obj != NO_ENTRY) {
705 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
706 + exit_cleanup(RERR_STREAMIO);
708 + racl->group_obj = access;
711 + tag_type = SMB_ACL_GROUP;
714 + if (racl->mask != NO_ENTRY) {
715 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
716 + exit_cleanup(RERR_STREAMIO);
718 + racl->mask = access;
721 + if (racl->other != NO_ENTRY) {
722 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
723 + exit_cleanup(RERR_STREAMIO);
725 + racl->other = access;
728 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
730 + exit_cleanup(RERR_STREAMIO);
732 + if (tag_type != prior_list_type) {
733 + if (prior_list_type)
734 + save_idas(&temp_ida_list, racl, prior_list_type);
735 + prior_list_type = tag_type;
737 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
738 + ida->access = access;
739 + ida->id = read_int(f);
740 + computed_mask_bits |= access;
742 + if (prior_list_type)
743 + save_idas(&temp_ida_list, racl, prior_list_type);
745 + if (type == SMB_ACL_TYPE_DEFAULT) {
746 + /* Ensure that these are never unset. */
747 + if (racl->user_obj == NO_ENTRY)
748 + racl->user_obj = 7;
749 + if (racl->group_obj == NO_ENTRY)
750 + racl->group_obj = 0;
751 + if (racl->other == NO_ENTRY)
755 + if (!racl->users.count && !racl->groups.count) {
756 + /* If we received a superfluous mask, throw it away. */
757 + if (racl->mask != NO_ENTRY) {
758 + /* Mask off the group perms with it first. */
759 + racl->group_obj &= racl->mask | NO_ENTRY;
760 + racl->mask = NO_ENTRY;
762 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
763 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
766 +/* Receive the ACL info the sender has included for this file-list entry. */
767 +void receive_acl(struct file_struct *file, int f)
769 + SMB_ACL_TYPE_T type;
770 + item_list *racl_list;
773 + if (S_ISLNK(file->mode))
776 + type = SMB_ACL_TYPE_ACCESS;
777 + racl_list = &access_acl_list;
778 + ndx_ptr = (char*)file + file_struct_len;
780 + char tag = read_byte(f);
783 + if (tag == 'A' || tag == 'a') {
784 + if (type != SMB_ACL_TYPE_ACCESS) {
785 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
786 + f_name(file, NULL));
787 + exit_cleanup(RERR_STREAMIO);
789 + } else if (tag == 'D' || tag == 'd') {
790 + if (type == SMB_ACL_TYPE_ACCESS) {
791 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
792 + f_name(file, NULL));
793 + exit_cleanup(RERR_STREAMIO);
796 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
797 + f_name(file, NULL), tag);
798 + exit_cleanup(RERR_STREAMIO);
800 + if (tag == 'A' || tag == 'D') {
802 + ndx = racl_list->count;
803 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
804 + receive_rsync_acl(&duo_item->racl, f, type);
805 + duo_item->sacl = NULL;
808 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
809 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
810 + f_name(file, NULL), str_acl_type(type), ndx);
811 + exit_cleanup(RERR_STREAMIO);
814 + SIVAL(ndx_ptr, 0, ndx);
815 + racl_list = &default_acl_list;
817 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
820 +/* Turn the ACL data in statx into cached ACL data, setting the index
821 + * values in the file struct. */
822 +void cache_acl(struct file_struct *file, statx *sxp)
824 + SMB_ACL_TYPE_T type;
826 + item_list *racl_list;
830 + if (S_ISLNK(file->mode))
833 + type = SMB_ACL_TYPE_ACCESS;
834 + racl = sxp->acc_acl;
835 + racl_list = &access_acl_list;
836 + ndx_ptr = (char*)file + file_struct_len;
840 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
842 + ndx = racl_list->count;
843 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
844 + new_duo->racl = *racl;
845 + new_duo->sacl = NULL;
846 + *racl = empty_rsync_acl;
848 + SIVAL(ndx_ptr, 0, ndx);
849 + racl = sxp->def_acl;
850 + racl_list = &default_acl_list;
852 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
857 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
859 + SMB_ACL_ENTRY_T entry;
860 + const char *errfun;
863 + if (S_ISDIR(mode)) {
864 + /* If the sticky bit is going on, it's not safe to allow all
865 + * the new ACL to go into effect before it gets set. */
866 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
867 + if (mode & S_ISVTX)
870 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
873 + /* If setuid or setgid is going off, it's not safe to allow all
874 + * the new ACL to go into effect before they get cleared. */
875 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
876 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
881 + errfun = "sys_acl_get_entry";
882 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
884 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
885 + SMB_ACL_TAG_T tag_type;
886 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
887 + errfun = "sys_acl_get_tag_type";
890 + switch (tag_type) {
891 + case SMB_ACL_USER_OBJ:
892 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
894 + case SMB_ACL_GROUP_OBJ:
895 + /* group is only empty when identical to group perms. */
896 + if (racl->group_obj != NO_ENTRY)
898 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
901 +#ifndef ACLS_NEED_MASK
902 + /* mask is only empty when we don't need it. */
903 + if (racl->mask == NO_ENTRY)
906 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
908 + case SMB_ACL_OTHER:
909 + COE2( store_access_in_entry,(mode & 7, entry) );
916 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
922 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
923 + /* Ensure that chmod() will be called to restore any lost setid bits. */
924 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
925 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
926 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
929 + /* Return the mode of the file on disk, as we will set them. */
930 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
933 +/* Set ACL on indicated filename.
935 + * This sets extended access ACL entries and default ACL. If convenient,
936 + * it sets permission bits along with the access ACL and signals having
937 + * done so by modifying sxp->st.st_mode.
939 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
940 + * with fname set to NULL to just check if the ACL is unchanged. */
941 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
944 + SMB_ACL_TYPE_T type;
947 + if (S_ISLNK(file->mode))
950 + type = SMB_ACL_TYPE_ACCESS;
951 + ndx_ptr = (char*)file + file_struct_len;
955 + int32 ndx = IVAL(ndx_ptr, 0);
959 + if (type == SMB_ACL_TYPE_ACCESS) {
960 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
962 + duo_item = access_acl_list.items;
965 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
967 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
969 + duo_item = default_acl_list.items;
972 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
976 + if (!dry_run && fname) {
977 + if (type == SMB_ACL_TYPE_DEFAULT
978 + && duo_item->racl.user_obj == NO_ENTRY) {
979 + if (sys_acl_delete_def_file(fname) < 0) {
980 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
986 + mode_t cur_mode = sxp->st.st_mode;
987 + if (!duo_item->sacl
988 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
992 + if (type == SMB_ACL_TYPE_ACCESS) {
993 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
994 + cur_mode, file->mode);
995 + if (cur_mode == ~0u)
998 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
999 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1000 + fname, str_acl_type(type));
1004 + if (type == SMB_ACL_TYPE_ACCESS)
1005 + sxp->st.st_mode = cur_mode;
1008 + if (unchanged == 1)
1010 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1015 +/* === Enumeration functions for uid mapping === */
1017 +/* Context -- one and only one. Should be cycled through once on uid
1018 + * mapping and once on gid mapping. */
1019 +static item_list *_enum_racl_lists[] = {
1020 + &access_acl_list, &default_acl_list, NULL
1023 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1024 +static int enum_ida_index = 0;
1025 +static size_t enum_racl_index = 0;
1027 +/* This returns the next tag_type id from the given ACL for the next entry,
1028 + * or it returns 0 if there are no more tag_type ids in the acl. */
1029 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1031 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1032 + if (enum_ida_index < idal->count) {
1033 + id_access *ida = &idal->idas[enum_ida_index++];
1036 + enum_ida_index = 0;
1040 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1042 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1044 + acl_duo *duo_item = racl_list->items;
1045 + duo_item += enum_racl_index;
1046 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1049 + enum_racl_index = 0;
1053 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1055 + for (; *enum_racl_list; enum_racl_list++) {
1056 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1060 + enum_racl_list = &_enum_racl_lists[0];
1064 +id_t *next_acl_uid()
1066 + return next_acl_list_id(SMB_ACL_USER);
1069 +id_t *next_acl_gid()
1071 + return next_acl_list_id(SMB_ACL_GROUP);
1074 +/* This is used by dest_mode(). */
1075 +int default_perms_for_dir(const char *dir)
1084 + perms = ACCESSPERMS & ~orig_umask;
1085 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1086 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1087 + if (sacl == NULL) {
1088 + /* Couldn't get an ACL. Darn. */
1091 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1095 + /* We're doing a dry run, so the containing directory
1096 + * wasn't actually created. Don't worry about it. */
1099 + /* Otherwise fall through. */
1101 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1102 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1108 + ok = unpack_smb_acl(&racl, sacl);
1109 + sys_acl_free_acl(sacl);
1111 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1115 + /* Apply the permission-bit entries of the default ACL, if any. */
1116 + if (racl.user_obj != NO_ENTRY) {
1117 + perms = rsync_acl_get_perms(&racl);
1119 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1122 + rsync_acl_free(&racl);
1126 +#endif /* SUPPORT_ACLS */
1129 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1130 extern char *backup_dir;
1133 +extern int preserve_acls;
1134 extern int preserve_devices;
1135 extern int preserve_specials;
1136 extern int preserve_links;
1137 @@ -94,7 +95,8 @@ path
1138 ****************************************************************************/
1139 static int make_bak_dir(char *fullpath)
1143 + struct file_struct *file;
1144 char *rel = fullpath + backup_dir_len;
1145 char *end = rel + strlen(rel);
1147 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1149 /* Try to transfer the directory settings of the
1150 * actual dir that the files are coming from. */
1151 - if (do_stat(rel, &st) < 0) {
1152 + if (do_stat(rel, &sx.st) < 0) {
1153 rsyserr(FERROR, errno,
1154 "make_bak_dir stat %s failed",
1157 - do_lchown(fullpath, st.st_uid, st.st_gid);
1158 - do_chmod(fullpath, st.st_mode);
1159 +#ifdef SUPPORT_ACLS
1160 + sx.acc_acl = sx.def_acl = NULL;
1162 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1164 +#ifdef SUPPORT_ACLS
1165 + if (preserve_acls) {
1166 + get_acl(rel, &sx);
1167 + cache_acl(file, &sx);
1170 + set_file_attrs(fullpath, file, NULL, 0);
1175 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1176 * We will move the file to be deleted into a parallel directory tree. */
1177 static int keep_backup(char *fname)
1181 struct file_struct *file;
1186 /* return if no file to keep */
1187 - if (do_lstat(fname, &st) < 0)
1188 + if (do_lstat(fname, &sx.st) < 0)
1190 +#ifdef SUPPORT_ACLS
1191 + sx.acc_acl = sx.def_acl = NULL;
1194 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1195 return 1; /* the file could have disappeared */
1196 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1197 if (!(buf = get_backup_name(fname)))
1200 +#ifdef SUPPORT_ACLS
1201 + if (preserve_acls) {
1202 + get_acl(fname, &sx);
1203 + cache_acl(file, &sx);
1207 /* Check to see if this is a device file, or link */
1208 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1209 || (preserve_specials && IS_SPECIAL(file->mode))) {
1210 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1211 if (robust_move(fname, buf) != 0) {
1212 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1213 full_fname(fname), buf);
1214 - } else if (st.st_nlink > 1) {
1215 + } else if (sx.st.st_nlink > 1) {
1216 /* If someone has hard-linked the file into the backup
1217 * dir, rename() might return success but do nothing! */
1218 robust_unlink(fname); /* Just in case... */
1219 --- old/configure.in
1220 +++ new/configure.in
1221 @@ -515,6 +515,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1222 AC_CHECK_LIB(resolv, strcasecmp)
1225 +AC_CHECK_FUNCS(aclsort)
1226 +if test x"$ac_cv_func_aclsort" = x"no"; then
1227 + AC_CHECK_LIB(sec, aclsort)
1230 dnl At the moment we don't test for a broken memcmp(), because all we
1231 dnl need to do is test for equality, not comparison, and it seems that
1232 dnl every platform has a memcmp that can do at least that.
1233 @@ -779,6 +784,78 @@ AC_SUBST(OBJ_RESTORE)
1234 AC_SUBST(CC_SHOBJ_FLAG)
1235 AC_SUBST(BUILD_POPT)
1237 +AC_CHECK_HEADERS(sys/acl.h)
1238 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1239 +#################################################
1240 +# check for ACL support
1242 +AC_MSG_CHECKING(whether to support ACLs)
1243 +AC_ARG_ENABLE(acl-support,
1244 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1245 +[ case "$enableval" in
1248 + case "$host_os" in
1250 + AC_MSG_RESULT(Using UnixWare ACLs)
1251 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1253 + *solaris*|*cygwin*)
1254 + AC_MSG_RESULT(Using solaris ACLs)
1255 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1258 + AC_MSG_RESULT(Using HPUX ACLs)
1259 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1262 + AC_MSG_RESULT(Using IRIX ACLs)
1263 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1266 + AC_MSG_RESULT(Using AIX ACLs)
1267 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1270 + AC_MSG_RESULT(Using Tru64 ACLs)
1271 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1272 + LIBS="$LIBS -lpacl"
1275 + AC_MSG_RESULT(ACLs requested -- running tests)
1276 + AC_CHECK_LIB(acl,acl_get_file)
1277 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1278 + AC_TRY_LINK([#include <sys/types.h>
1279 +#include <sys/acl.h>],
1280 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1281 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1282 + AC_MSG_CHECKING(ACL test results)
1283 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1284 + AC_MSG_RESULT(Using posix ACLs)
1285 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1286 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1287 + AC_TRY_LINK([#include <sys/types.h>
1288 +#include <sys/acl.h>],
1289 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1290 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1291 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1292 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1295 + AC_MSG_ERROR(Failed to find ACL support)
1302 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1305 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1309 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1314 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1315 extern int one_file_system;
1316 extern int copy_dirlinks;
1317 extern int keep_dirlinks;
1318 +extern int preserve_acls;
1319 extern int preserve_links;
1320 extern int preserve_hard_links;
1321 extern int preserve_devices;
1322 @@ -133,6 +134,8 @@ static void list_file_entry(struct file_
1324 permstring(permbuf, f->mode);
1326 + /* TODO: indicate '+' if the entry has an ACL. */
1328 #ifdef SUPPORT_LINKS
1329 if (preserve_links && S_ISLNK(f->mode)) {
1330 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1331 @@ -491,6 +494,9 @@ static struct file_struct *receive_file_
1332 char thisname[MAXPATHLEN];
1333 unsigned int l1 = 0, l2 = 0;
1334 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1335 +#ifdef SUPPORT_ACLS
1339 char *basename, *dirname, *bp;
1340 struct file_struct *file;
1341 @@ -594,13 +600,27 @@ static struct file_struct *receive_file_
1343 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1345 +#ifdef SUPPORT_ACLS
1346 + /* We need one or two index int32s when we're preserving ACLs. */
1347 + if (preserve_acls)
1348 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
1353 alloc_len = file_struct_len + dirname_len + basename_len
1354 +#ifdef SUPPORT_ACLS
1357 + linkname_len + sum_len;
1358 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1360 file = (struct file_struct *)bp;
1361 memset(bp, 0, file_struct_len);
1362 bp += file_struct_len;
1363 +#ifdef SUPPORT_ACLS
1367 file->modtime = modtime;
1368 file->length = file_length;
1369 @@ -695,6 +715,11 @@ static struct file_struct *receive_file_
1370 read_buf(f, sum, checksum_len);
1373 +#ifdef SUPPORT_ACLS
1374 + if (preserve_acls)
1375 + receive_acl(file, f);
1381 @@ -944,6 +969,9 @@ static struct file_struct *send_file_nam
1382 unsigned short flags)
1384 struct file_struct *file;
1385 +#ifdef SUPPORT_ACLS
1389 file = make_file(fname, flist, stp, flags,
1390 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1391 @@ -953,6 +981,15 @@ static struct file_struct *send_file_nam
1392 if (chmod_modes && !S_ISLNK(file->mode))
1393 file->mode = tweak_mode(file->mode, chmod_modes);
1395 +#ifdef SUPPORT_ACLS
1396 + if (preserve_acls) {
1397 + sx.st.st_mode = file->mode;
1398 + sx.acc_acl = sx.def_acl = NULL;
1399 + if (get_acl(fname, &sx) < 0)
1404 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1406 flist_expand(flist);
1407 @@ -960,6 +997,15 @@ static struct file_struct *send_file_nam
1408 if (file->basename[0]) {
1409 flist->files[flist->count++] = file;
1410 send_file_entry(file, f);
1411 +#ifdef SUPPORT_ACLS
1412 + if (preserve_acls)
1416 +#ifdef SUPPORT_ACLS
1417 + if (preserve_acls)
1425 @@ -35,6 +35,7 @@ extern int do_progress;
1426 extern int relative_paths;
1427 extern int implied_dirs;
1428 extern int keep_dirlinks;
1429 +extern int preserve_acls;
1430 extern int preserve_links;
1431 extern int preserve_devices;
1432 extern int preserve_specials;
1433 @@ -84,6 +85,7 @@ extern long block_size; /* "long" becaus
1434 extern int max_delete;
1435 extern int force_delete;
1436 extern int one_file_system;
1437 +extern mode_t orig_umask;
1438 extern struct stats stats;
1439 extern dev_t filesystem_dev;
1440 extern char *backup_dir;
1441 @@ -316,22 +318,27 @@ static void do_delete_pass(struct file_l
1442 rprintf(FINFO, " \r");
1445 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1446 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1449 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1450 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1453 - if (am_root && preserve_uid && st->st_uid != file->uid)
1454 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1457 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1458 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1461 +#ifdef SUPPORT_ACLS
1462 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1469 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1470 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1471 int32 iflags, uchar fnamecmp_type, char *xname)
1473 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1474 @@ -339,19 +346,23 @@ void itemize(struct file_struct *file, i
1475 : S_ISDIR(file->mode) ? !omit_dir_times
1476 : !S_ISLNK(file->mode);
1478 - if (S_ISREG(file->mode) && file->length != st->st_size)
1479 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1480 iflags |= ITEM_REPORT_SIZE;
1481 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1482 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1483 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1484 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1485 iflags |= ITEM_REPORT_TIME;
1486 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1487 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1488 iflags |= ITEM_REPORT_PERMS;
1489 - if (preserve_uid && am_root && file->uid != st->st_uid)
1490 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1491 iflags |= ITEM_REPORT_OWNER;
1492 if (preserve_gid && file->gid != GID_NONE
1493 - && st->st_gid != file->gid)
1494 + && sxp->st.st_gid != file->gid)
1495 iflags |= ITEM_REPORT_GROUP;
1496 +#ifdef SUPPORT_ACLS
1497 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1498 + iflags |= ITEM_REPORT_ACL;
1501 iflags |= ITEM_IS_NEW;
1503 @@ -604,7 +615,7 @@ void check_for_finished_hlinks(int itemi
1504 * handling the file, -1 if no dest-linking occurred, or a non-negative
1505 * value if we found an alternate basis file. */
1506 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1507 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1508 + char *cmpbuf, statx *sxp, int itemizing,
1509 int maybe_ATTRS_REPORT, enum logcode code)
1511 int best_match = -1;
1512 @@ -613,7 +624,7 @@ static int try_dests_reg(struct file_str
1515 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1516 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1517 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1519 switch (match_level) {
1521 @@ -621,16 +632,20 @@ static int try_dests_reg(struct file_str
1525 - if (!unchanged_file(cmpbuf, file, stp))
1526 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1532 - if (!unchanged_attrs(file, stp))
1533 +#ifdef SUPPORT_ACLS
1534 + if (preserve_acls)
1535 + get_acl(cmpbuf, sxp);
1537 + if (!unchanged_attrs(file, sxp))
1539 if (always_checksum && preserve_times
1540 - && cmp_time(stp->st_mtime, file->modtime))
1541 + && cmp_time(sxp->st.st_mtime, file->modtime))
1545 @@ -645,14 +660,14 @@ static int try_dests_reg(struct file_str
1546 if (j != best_match) {
1548 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1549 - if (link_stat(cmpbuf, stp, 0) < 0)
1550 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1554 if (match_level == 3 && !copy_dest) {
1555 #ifdef SUPPORT_HARD_LINKS
1557 - if (hard_link_one(file, ndx, fname, 0, stp,
1558 + if (hard_link_one(file, ndx, fname, 0, sxp,
1560 itemizing && verbose > 1,
1562 @@ -661,8 +676,13 @@ static int try_dests_reg(struct file_str
1563 hard_link_cluster(file, ndx, itemizing, code);
1567 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1569 +#ifdef SUPPORT_ACLS
1570 + if (preserve_acls && !ACL_READY(*sxp))
1571 + get_acl(fname, sxp);
1573 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1575 if (verbose > 1 && maybe_ATTRS_REPORT) {
1576 rprintf(FCLIENT, "%s is uptodate\n", fname);
1578 @@ -678,8 +698,13 @@ static int try_dests_reg(struct file_str
1583 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1585 +#ifdef SUPPORT_ACLS
1586 + if (preserve_acls && !ACL_READY(*sxp))
1587 + get_acl(fname, sxp);
1589 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1591 set_file_attrs(fname, file, NULL, 0);
1592 if (maybe_ATTRS_REPORT
1593 && ((!itemizing && verbose && match_level == 2)
1594 @@ -703,13 +728,18 @@ static int try_dests_non(struct file_str
1597 char fnamebuf[MAXPATHLEN];
1603 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1604 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1605 - || !unchanged_attrs(file, &st))
1606 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1608 +#ifdef SUPPORT_ACLS
1609 + if (preserve_acls)
1610 + get_acl(fnamebuf, &sx);
1612 + if (!unchanged_attrs(file, &sx))
1614 if (S_ISLNK(file->mode)) {
1615 #ifdef SUPPORT_LINKS
1616 @@ -722,10 +752,10 @@ static int try_dests_non(struct file_str
1619 } else if (IS_SPECIAL(file->mode)) {
1620 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1621 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1623 } else if (IS_DEVICE(file->mode)) {
1624 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1625 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1629 @@ -756,7 +786,15 @@ static int try_dests_non(struct file_str
1630 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1631 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1632 char *lp = link_dest ? "" : NULL;
1633 - itemize(file, ndx, 0, &st, changes, 0, lp);
1634 +#ifdef SUPPORT_ACLS
1635 + if (preserve_acls)
1636 + get_acl(fname, &sx);
1638 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1639 +#ifdef SUPPORT_ACLS
1640 + if (preserve_acls)
1644 if (verbose > 1 && maybe_ATTRS_REPORT) {
1645 rprintf(FCLIENT, "%s is uptodate\n", fname);
1646 @@ -768,6 +806,7 @@ static int try_dests_non(struct file_str
1649 static int phase = 0;
1650 +static int dflt_perms;
1652 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1653 * make sure it exists, and has the right permissions/timestamp info. For
1654 @@ -789,7 +828,8 @@ static void recv_generator(char *fname,
1655 static int need_fuzzy_dirlist = 0;
1656 struct file_struct *fuzzy_file = NULL;
1657 int fd = -1, f_copy = -1;
1658 - STRUCT_STAT st, real_st, partial_st;
1659 + statx sx, real_sx;
1660 + STRUCT_STAT partial_st;
1661 struct file_struct *back_file = NULL;
1662 int statret, real_ret, stat_errno;
1663 char *fnamecmp, *partialptr, *backupptr = NULL;
1664 @@ -845,6 +885,9 @@ static void recv_generator(char *fname,
1665 } else if (!dry_run)
1668 +#ifdef SUPPORT_ACLS
1669 + sx.acc_acl = sx.def_acl = NULL;
1673 stat_errno = ENOENT;
1674 @@ -852,7 +895,7 @@ static void recv_generator(char *fname,
1675 char *dn = file->dirname ? file->dirname : ".";
1676 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1677 if (relative_paths && !implied_dirs
1678 - && safe_stat(dn, &st) < 0
1679 + && safe_stat(dn, &sx.st) < 0
1680 && create_directory_path(fname) < 0) {
1681 rsyserr(FERROR, errno,
1682 "recv_generator: mkdir %s failed",
1683 @@ -864,6 +907,10 @@ static void recv_generator(char *fname,
1686 need_fuzzy_dirlist = 1;
1687 +#ifdef SUPPORT_ACLS
1688 + if (!preserve_perms)
1689 + dflt_perms = default_perms_for_dir(dn);
1692 parent_dirname = dn;
1694 @@ -872,7 +919,7 @@ static void recv_generator(char *fname,
1695 need_fuzzy_dirlist = 0;
1698 - statret = link_stat(fname, &st,
1699 + statret = link_stat(fname, &sx.st,
1700 keep_dirlinks && S_ISDIR(file->mode));
1703 @@ -890,8 +937,9 @@ static void recv_generator(char *fname,
1704 * mode based on the local permissions and some heuristics. */
1705 if (!preserve_perms) {
1706 int exists = statret == 0
1707 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1708 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1709 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1710 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1714 if (S_ISDIR(file->mode)) {
1715 @@ -900,8 +948,8 @@ static void recv_generator(char *fname,
1716 * file of that name and it is *not* a directory, then
1717 * we need to delete it. If it doesn't exist, then
1718 * (perhaps recursively) create it. */
1719 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1720 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1721 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1722 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1726 @@ -910,7 +958,11 @@ static void recv_generator(char *fname,
1729 if (itemizing && f_out != -1) {
1730 - itemize(file, ndx, statret, &st,
1731 +#ifdef SUPPORT_ACLS
1732 + if (preserve_acls && statret == 0)
1733 + get_acl(fname, &sx);
1735 + itemize(file, ndx, statret, &sx,
1736 statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1738 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1739 @@ -930,19 +982,19 @@ static void recv_generator(char *fname,
1743 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1744 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1745 && verbose && code && f_out != -1)
1746 rprintf(code, "%s/\n", fname);
1747 if (delete_during && f_out != -1 && !phase && dry_run < 2
1748 && (file->flags & FLAG_DEL_HERE))
1749 - delete_in_dir(the_file_list, fname, file, &st);
1751 + delete_in_dir(the_file_list, fname, file, &sx.st);
1755 if (preserve_hard_links && file->link_u.links
1756 - && hard_link_check(file, ndx, fname, statret, &st,
1757 + && hard_link_check(file, ndx, fname, statret, &sx,
1758 itemizing, code, HL_CHECK_MASTER))
1762 if (preserve_links && S_ISLNK(file->mode)) {
1763 #ifdef SUPPORT_LINKS
1764 @@ -960,7 +1012,7 @@ static void recv_generator(char *fname,
1765 char lnk[MAXPATHLEN];
1768 - if (!S_ISDIR(st.st_mode)
1769 + if (!S_ISDIR(sx.st.st_mode)
1770 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1772 /* A link already pointing to the
1773 @@ -968,10 +1020,10 @@ static void recv_generator(char *fname,
1775 if (strcmp(lnk, file->u.link) == 0) {
1777 - itemize(file, ndx, 0, &st, 0,
1778 + itemize(file, ndx, 0, &sx, 0,
1781 - set_file_attrs(fname, file, &st,
1782 + set_file_attrs(fname, file, &sx,
1783 maybe_ATTRS_REPORT);
1784 if (preserve_hard_links
1785 && file->link_u.links) {
1786 @@ -986,9 +1038,9 @@ static void recv_generator(char *fname,
1788 /* Not the right symlink (or not a symlink), so
1790 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1791 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1793 - if (!S_ISLNK(st.st_mode))
1794 + if (!S_ISLNK(sx.st.st_mode))
1796 } else if (basis_dir[0] != NULL) {
1797 if (try_dests_non(file, fname, ndx, itemizing,
1798 @@ -1004,7 +1056,7 @@ static void recv_generator(char *fname,
1801 if (preserve_hard_links && file->link_u.links
1802 - && hard_link_check(file, ndx, fname, -1, &st,
1803 + && hard_link_check(file, ndx, fname, -1, &sx,
1804 itemizing, code, HL_SKIP))
1806 if (do_symlink(file->u.link,fname) != 0) {
1807 @@ -1013,7 +1065,7 @@ static void recv_generator(char *fname,
1809 set_file_attrs(fname, file, NULL, 0);
1811 - itemize(file, ndx, statret, &st,
1812 + itemize(file, ndx, statret, &sx,
1813 ITEM_LOCAL_CHANGE, 0, NULL);
1815 if (code && verbose) {
1816 @@ -1044,18 +1096,22 @@ static void recv_generator(char *fname,
1817 itemizing = code = 0;
1820 +#ifdef SUPPORT_ACLS
1821 + if (preserve_acls && statret == 0)
1822 + get_acl(fname, &sx);
1825 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1826 - || st.st_rdev != file->u.rdev) {
1827 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1828 + || sx.st.st_rdev != file->u.rdev) {
1830 - && delete_item(fname, st.st_mode, del_opts) < 0)
1832 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1834 if (preserve_hard_links && file->link_u.links
1835 - && hard_link_check(file, ndx, fname, -1, &st,
1836 + && hard_link_check(file, ndx, fname, -1, &sx,
1837 itemizing, code, HL_SKIP))
1839 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1840 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1842 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1843 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1846 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1847 @@ -1068,7 +1124,7 @@ static void recv_generator(char *fname,
1849 set_file_attrs(fname, file, NULL, 0);
1851 - itemize(file, ndx, statret, &st,
1852 + itemize(file, ndx, statret, &sx,
1853 ITEM_LOCAL_CHANGE, 0, NULL);
1855 if (code && verbose)
1856 @@ -1082,14 +1138,14 @@ static void recv_generator(char *fname,
1860 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1861 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1862 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1863 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1864 if (preserve_hard_links && file->link_u.links)
1865 hard_link_cluster(file, ndx, itemizing, code);
1866 if (remove_source_files == 1)
1867 goto return_with_success;
1873 if (!S_ISREG(file->mode)) {
1874 @@ -1123,7 +1179,7 @@ static void recv_generator(char *fname,
1877 if (update_only && statret == 0
1878 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1879 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1881 rprintf(FINFO, "%s is newer\n", fname);
1883 @@ -1132,20 +1188,20 @@ static void recv_generator(char *fname,
1885 fnamecmp_type = FNAMECMP_FNAME;
1887 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1888 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1889 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1890 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1893 stat_errno = ENOENT;
1896 if (statret != 0 && basis_dir[0] != NULL) {
1897 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1898 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1899 itemizing, maybe_ATTRS_REPORT, code);
1901 if (remove_source_files == 1)
1902 goto return_with_success;
1907 fnamecmp = fnamecmpbuf;
1908 @@ -1155,7 +1211,7 @@ static void recv_generator(char *fname,
1915 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1916 && link_stat(partialptr, &partial_st, 0) == 0
1917 @@ -1174,7 +1230,7 @@ static void recv_generator(char *fname,
1918 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1919 fname, fnamecmpbuf);
1921 - st.st_size = fuzzy_file->length;
1922 + sx.st.st_size = fuzzy_file->length;
1924 fnamecmp = fnamecmpbuf;
1925 fnamecmp_type = FNAMECMP_FUZZY;
1926 @@ -1183,7 +1239,7 @@ static void recv_generator(char *fname,
1929 if (preserve_hard_links && file->link_u.links
1930 - && hard_link_check(file, ndx, fname, statret, &st,
1931 + && hard_link_check(file, ndx, fname, statret, &sx,
1932 itemizing, code, HL_SKIP))
1934 if (stat_errno == ENOENT)
1935 @@ -1193,39 +1249,52 @@ static void recv_generator(char *fname,
1939 - if (append_mode && st.st_size > file->length)
1940 + if (append_mode && sx.st.st_size > file->length)
1943 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1945 else if (fnamecmp_type == FNAMECMP_FUZZY)
1947 - else if (unchanged_file(fnamecmp, file, &st)) {
1948 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1950 do_unlink(partialptr);
1951 handle_partial_dir(partialptr, PDIR_DELETE);
1954 - itemize(file, ndx, real_ret, &real_st,
1955 +#ifdef SUPPORT_ACLS
1956 + if (preserve_acls && real_ret == 0)
1957 + get_acl(fname, &real_sx);
1959 + itemize(file, ndx, real_ret, &real_sx,
1961 +#ifdef SUPPORT_ACLS
1962 + if (preserve_acls) {
1963 + if (fnamecmp_type == FNAMECMP_FNAME) {
1964 + sx.acc_acl = real_sx.acc_acl;
1965 + sx.def_acl = real_sx.def_acl;
1967 + free_acl(&real_sx);
1971 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1972 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1973 if (preserve_hard_links && file->link_u.links)
1974 hard_link_cluster(file, ndx, itemizing, code);
1975 if (remove_source_files != 1)
1978 return_with_success:
1981 SIVAL(numbuf, 0, ndx);
1982 send_msg(MSG_SUCCESS, numbuf, 4);
1991 + sx.st = partial_st;
1992 fnamecmp = partialptr;
1993 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
1995 @@ -1249,17 +1318,21 @@ static void recv_generator(char *fname,
1997 /* pretend the file didn't exist */
1998 if (preserve_hard_links && file->link_u.links
1999 - && hard_link_check(file, ndx, fname, statret, &st,
2000 + && hard_link_check(file, ndx, fname, statret, &sx,
2001 itemizing, code, HL_SKIP))
2004 statret = real_ret = -1;
2005 +#ifdef SUPPORT_ACLS
2006 + if (preserve_acls && ACL_READY(sx))
2012 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2013 if (!(backupptr = get_backup_name(fname))) {
2018 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2020 @@ -1270,7 +1343,7 @@ static void recv_generator(char *fname,
2021 full_fname(backupptr));
2027 if ((f_copy = do_open(backupptr,
2028 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2029 @@ -1278,14 +1351,14 @@ static void recv_generator(char *fname,
2030 full_fname(backupptr));
2036 fnamecmp_type = FNAMECMP_BACKUP;
2040 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2041 - fnamecmp, (double)st.st_size);
2042 + fnamecmp, (double)sx.st.st_size);
2046 @@ -1303,24 +1376,32 @@ static void recv_generator(char *fname,
2047 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2048 if (fnamecmp_type == FNAMECMP_FUZZY)
2049 iflags |= ITEM_XNAME_FOLLOWS;
2050 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2051 +#ifdef SUPPORT_ACLS
2052 + if (preserve_acls && real_ret == 0)
2053 + get_acl(fname, &real_sx);
2055 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2056 fuzzy_file ? fuzzy_file->basename : NULL);
2057 +#ifdef SUPPORT_ACLS
2058 + if (preserve_acls)
2059 + free_acl(&real_sx);
2064 if (preserve_hard_links && file->link_u.links)
2065 hard_link_cluster(file, ndx, itemizing, code);
2073 if (statret != 0 || whole_file) {
2074 write_sum_head(f_out, NULL);
2079 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2080 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2084 @@ -1333,6 +1414,13 @@ static void recv_generator(char *fname,
2090 +#ifdef SUPPORT_ACLS
2091 + if (preserve_acls)
2097 void generate_files(int f_out, struct file_list *flist, char *local_name)
2098 @@ -1392,6 +1480,8 @@ void generate_files(int f_out, struct fi
2099 * notice that and let us know via the redo pipe (or its closing). */
2102 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2104 for (i = 0; i < flist->count; i++) {
2105 struct file_struct *file = flist->files[i];
2111 extern int do_xfers;
2112 extern int link_dest;
2113 +extern int preserve_acls;
2114 extern int make_backups;
2115 extern int remove_source_files;
2116 extern int stdout_format_has_i;
2117 @@ -145,15 +146,19 @@ void init_hard_links(void)
2119 #ifdef SUPPORT_HARD_LINKS
2120 static int maybe_hard_link(struct file_struct *file, int ndx,
2121 - char *fname, int statret, STRUCT_STAT *st,
2122 + char *fname, int statret, statx *sxp,
2123 char *toname, STRUCT_STAT *to_st,
2124 int itemizing, enum logcode code)
2127 - if (st->st_dev == to_st->st_dev
2128 - && st->st_ino == to_st->st_ino) {
2129 + if (sxp->st.st_dev == to_st->st_dev
2130 + && sxp->st.st_ino == to_st->st_ino) {
2132 - itemize(file, ndx, statret, st,
2133 +#ifdef SUPPORT_ACLS
2134 + if (preserve_acls && !ACL_READY(*sxp))
2135 + get_acl(fname, sxp);
2137 + itemize(file, ndx, statret, sxp,
2138 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2141 @@ -168,13 +173,13 @@ static int maybe_hard_link(struct file_s
2145 - return hard_link_one(file, ndx, fname, statret, st, toname,
2146 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2147 0, itemizing, code);
2151 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2152 - int statret, STRUCT_STAT *st, int itemizing,
2153 + int statret, statx *sxp, int itemizing,
2154 enum logcode code, int skip)
2156 #ifdef SUPPORT_HARD_LINKS
2157 @@ -209,7 +214,7 @@ int hard_link_check(struct file_struct *
2158 || st2.st_ino != st3.st_ino)
2163 if (verbose < 2 || !stdout_format_has_i)
2164 itemizing = code = 0;
2166 @@ -217,12 +222,16 @@ int hard_link_check(struct file_struct *
2167 if (!unchanged_file(cmpbuf, file, &st3))
2171 - if (unchanged_attrs(file, &st3))
2173 +#ifdef SUPPORT_ACLS
2174 + if (preserve_acls)
2175 + get_acl(cmpbuf, sxp);
2177 + if (unchanged_attrs(file, sxp))
2179 } while (basis_dir[++j] != NULL);
2181 - maybe_hard_link(file, ndx, fname, statret, st,
2182 + maybe_hard_link(file, ndx, fname, statret, sxp,
2183 toname, &st2, itemizing, code);
2184 if (remove_source_files == 1 && do_xfers) {
2186 @@ -240,7 +249,7 @@ int hard_link_check(struct file_struct *
2188 #ifdef SUPPORT_HARD_LINKS
2189 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2190 - int statret, STRUCT_STAT *st, char *toname, int terse,
2191 + int statret, statx *sxp, char *toname, int terse,
2192 int itemizing, enum logcode code)
2194 if (do_link(toname, fname)) {
2195 @@ -256,7 +265,11 @@ int hard_link_one(struct file_struct *fi
2199 - itemize(file, ndx, statret, st,
2200 +#ifdef SUPPORT_ACLS
2201 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2202 + get_acl(fname, sxp);
2204 + itemize(file, ndx, statret, sxp,
2205 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2206 terse ? "" : toname);
2208 @@ -273,11 +286,12 @@ void hard_link_cluster(struct file_struc
2209 #ifdef SUPPORT_HARD_LINKS
2210 char hlink1[MAXPATHLEN];
2212 - STRUCT_STAT st1, st2;
2215 int statret, ndx = master;
2217 file->F_HLINDEX = FINISHED_LINK;
2218 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2219 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2221 if (!(file->flags & FLAG_HLINK_TOL)) {
2222 while (!(file->flags & FLAG_HLINK_EOL)) {
2223 @@ -291,9 +305,13 @@ void hard_link_cluster(struct file_struc
2224 if (file->F_HLINDEX != SKIPPED_LINK)
2226 hlink2 = f_name(file, NULL);
2227 - statret = link_stat(hlink2, &st2, 0);
2228 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2229 - hlink1, &st1, itemizing, code);
2230 + statret = link_stat(hlink2, &sx.st, 0);
2231 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2232 + hlink1, &st, itemizing, code);
2233 +#ifdef SUPPORT_ACLS
2234 + if (preserve_acls)
2237 if (remove_source_files == 1 && do_xfers) {
2239 SIVAL(numbuf, 0, ndx);
2240 --- old/lib/sysacls.c
2241 +++ new/lib/sysacls.c
2244 + Unix SMB/CIFS implementation.
2245 + Samba system utilities for ACL support.
2246 + Copyright (C) Jeremy Allison 2000.
2248 + This program is free software; you can redistribute it and/or modify
2249 + it under the terms of the GNU General Public License as published by
2250 + the Free Software Foundation; either version 2 of the License, or
2251 + (at your option) any later version.
2253 + This program is distributed in the hope that it will be useful,
2254 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2255 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2256 + GNU General Public License for more details.
2258 + You should have received a copy of the GNU General Public License
2259 + along with this program; if not, write to the Free Software
2260 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2264 +#include "sysacls.h" /****** ADDED ******/
2266 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2267 +void SAFE_FREE(void *mem)
2273 +char *uidtoname(uid_t uid)
2275 + static char idbuf[12];
2276 + struct passwd *pw;
2278 + if ((pw = getpwuid(uid)) == NULL) {
2279 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2282 + return pw->pw_name;
2284 +/****** EXTRAS -- END ******/
2287 + This file wraps all differing system ACL interfaces into a consistent
2288 + one based on the POSIX interface. It also returns the correct errors
2289 + for older UNIX systems that don't support ACLs.
2291 + The interfaces that each ACL implementation must support are as follows :
2293 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2294 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2295 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2296 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2297 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2298 + SMB_ACL_T sys_acl_get_fd(int fd)
2299 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2300 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2301 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2302 + SMB_ACL_T sys_acl_init( int count)
2303 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2304 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2305 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2306 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2307 + int sys_acl_valid( SMB_ACL_T theacl )
2308 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2309 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2310 + int sys_acl_delete_def_file(const char *path)
2312 + This next one is not POSIX complient - but we *have* to have it !
2313 + More POSIX braindamage.
2315 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2317 + The generic POSIX free is the following call. We split this into
2318 + several different free functions as we may need to add tag info
2319 + to structures when emulating the POSIX interface.
2321 + int sys_acl_free( void *obj_p)
2323 + The calls we actually use are :
2325 + int sys_acl_free_text(char *text) - free acl_to_text
2326 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2327 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2331 +#if defined(HAVE_POSIX_ACLS)
2333 +/* Identity mapping - easy. */
2335 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2337 + return acl_get_entry( the_acl, entry_id, entry_p);
2340 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2342 + return acl_get_tag_type( entry_d, tag_type_p);
2345 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2347 + return acl_get_permset( entry_d, permset_p);
2350 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2352 + return acl_get_qualifier( entry_d);
2355 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2357 + return acl_get_file( path_p, type);
2360 +SMB_ACL_T sys_acl_get_fd(int fd)
2362 + return acl_get_fd(fd);
2365 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2367 + return acl_clear_perms(permset);
2370 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2372 + return acl_add_perm(permset, perm);
2375 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2377 +#if defined(HAVE_ACL_GET_PERM_NP)
2379 + * Required for TrustedBSD-based ACL implementations where
2380 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2383 + return acl_get_perm_np(permset, perm);
2385 + return acl_get_perm(permset, perm);
2389 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2391 + return acl_to_text( the_acl, plen);
2394 +SMB_ACL_T sys_acl_init( int count)
2396 + return acl_init(count);
2399 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2401 + return acl_create_entry(pacl, pentry);
2404 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2406 + return acl_set_tag_type(entry, tagtype);
2409 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2411 + return acl_set_qualifier(entry, qual);
2414 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2416 + return acl_set_permset(entry, permset);
2419 +int sys_acl_valid( SMB_ACL_T theacl )
2421 + return acl_valid(theacl);
2424 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2426 + return acl_set_file(name, acltype, theacl);
2429 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2431 + return acl_set_fd(fd, theacl);
2434 +int sys_acl_delete_def_file(const char *name)
2436 + return acl_delete_def_file(name);
2439 +int sys_acl_free_text(char *text)
2441 + return acl_free(text);
2444 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2446 + return acl_free(the_acl);
2449 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2451 + return acl_free(qual);
2454 +#elif defined(HAVE_TRU64_ACLS)
2456 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2457 + * is based on Draft 13 of the POSIX spec which is
2458 + * slightly different from the Draft 16 interface.
2460 + * Also, some of the permset manipulation functions
2461 + * such as acl_clear_perm() and acl_add_perm() appear
2462 + * to be broken on Tru64 so we have to manipulate
2463 + * the permission bits in the permset directly.
2465 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2467 + SMB_ACL_ENTRY_T entry;
2469 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2474 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2479 + return errno ? -1 : 0;
2482 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2484 + return acl_get_tag_type( entry_d, tag_type_p);
2487 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2489 + return acl_get_permset( entry_d, permset_p);
2492 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2494 + return acl_get_qualifier( entry_d);
2497 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2499 + return acl_get_file((char *)path_p, type);
2502 +SMB_ACL_T sys_acl_get_fd(int fd)
2504 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2507 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2509 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2514 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2516 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2521 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2526 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2528 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2531 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2533 + return acl_to_text( the_acl, plen);
2536 +SMB_ACL_T sys_acl_init( int count)
2538 + return acl_init(count);
2541 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2543 + SMB_ACL_ENTRY_T entry;
2545 + if ((entry = acl_create_entry(pacl)) == NULL) {
2553 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2555 + return acl_set_tag_type(entry, tagtype);
2558 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2560 + return acl_set_qualifier(entry, qual);
2563 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2565 + return acl_set_permset(entry, permset);
2568 +int sys_acl_valid( SMB_ACL_T theacl )
2570 + acl_entry_t entry;
2572 + return acl_valid(theacl, &entry);
2575 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2577 + return acl_set_file((char *)name, acltype, theacl);
2580 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2582 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2585 +int sys_acl_delete_def_file(const char *name)
2587 + return acl_delete_def_file((char *)name);
2590 +int sys_acl_free_text(char *text)
2593 + * (void) cast and explicit return 0 are for DEC UNIX
2594 + * which just #defines acl_free_text() to be free()
2596 + (void) acl_free_text(text);
2600 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2602 + return acl_free(the_acl);
2605 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2607 + return acl_free_qualifier(qual, tagtype);
2610 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2613 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2614 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2618 + * Note that while this code implements sufficient functionality
2619 + * to support the sys_acl_* interfaces it does not provide all
2620 + * of the semantics of the POSIX ACL interfaces.
2622 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2623 + * from a call to sys_acl_get_entry() should not be assumed to be
2624 + * valid after calling any of the following functions, which may
2625 + * reorder the entries in the ACL.
2628 + * sys_acl_set_file()
2629 + * sys_acl_set_fd()
2633 + * The only difference between Solaris and UnixWare / OpenUNIX is
2634 + * that the #defines for the ACL operations have different names
2636 +#if defined(HAVE_UNIXWARE_ACLS)
2638 +#define SETACL ACL_SET
2639 +#define GETACL ACL_GET
2640 +#define GETACLCNT ACL_CNT
2645 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2647 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2652 + if (entry_p == NULL) {
2657 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2661 + if (acl_d->next < 0) {
2666 + if (acl_d->next >= acl_d->count) {
2670 + *entry_p = &acl_d->acl[acl_d->next++];
2675 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2677 + *type_p = entry_d->a_type;
2682 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2684 + *permset_p = &entry_d->a_perm;
2689 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2691 + if (entry_d->a_type != SMB_ACL_USER
2692 + && entry_d->a_type != SMB_ACL_GROUP) {
2697 + return &entry_d->a_id;
2701 + * There is no way of knowing what size the ACL returned by
2702 + * GETACL will be unless you first call GETACLCNT which means
2703 + * making an additional system call.
2705 + * In the hope of avoiding the cost of the additional system
2706 + * call in most cases, we initially allocate enough space for
2707 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2708 + * be too small then we use GETACLCNT to find out the actual
2709 + * size, reallocate the ACL buffer, and then call GETACL again.
2712 +#define INITIAL_ACL_SIZE 16
2714 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2717 + int count; /* # of ACL entries allocated */
2718 + int naccess; /* # of access ACL entries */
2719 + int ndefault; /* # of default ACL entries */
2721 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2726 + count = INITIAL_ACL_SIZE;
2727 + if ((acl_d = sys_acl_init(count)) == NULL) {
2732 + * If there isn't enough space for the ACL entries we use
2733 + * GETACLCNT to determine the actual number of ACL entries
2734 + * reallocate and try again. This is in a loop because it
2735 + * is possible that someone else could modify the ACL and
2736 + * increase the number of entries between the call to
2737 + * GETACLCNT and the call to GETACL.
2739 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2740 + && errno == ENOSPC) {
2742 + sys_acl_free_acl(acl_d);
2744 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2748 + if ((acl_d = sys_acl_init(count)) == NULL) {
2754 + sys_acl_free_acl(acl_d);
2759 + * calculate the number of access and default ACL entries
2761 + * Note: we assume that the acl() system call returned a
2762 + * well formed ACL which is sorted so that all of the
2763 + * access ACL entries preceed any default ACL entries
2765 + for (naccess = 0; naccess < count; naccess++) {
2766 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2769 + ndefault = count - naccess;
2772 + * if the caller wants the default ACL we have to copy
2773 + * the entries down to the start of the acl[] buffer
2774 + * and mask out the ACL_DEFAULT flag from the type field
2776 + if (type == SMB_ACL_TYPE_DEFAULT) {
2779 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2780 + acl_d->acl[i] = acl_d->acl[j];
2781 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2784 + acl_d->count = ndefault;
2786 + acl_d->count = naccess;
2792 +SMB_ACL_T sys_acl_get_fd(int fd)
2795 + int count; /* # of ACL entries allocated */
2796 + int naccess; /* # of access ACL entries */
2798 + count = INITIAL_ACL_SIZE;
2799 + if ((acl_d = sys_acl_init(count)) == NULL) {
2803 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2804 + && errno == ENOSPC) {
2806 + sys_acl_free_acl(acl_d);
2808 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2812 + if ((acl_d = sys_acl_init(count)) == NULL) {
2818 + sys_acl_free_acl(acl_d);
2823 + * calculate the number of access ACL entries
2825 + for (naccess = 0; naccess < count; naccess++) {
2826 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2830 + acl_d->count = naccess;
2835 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2842 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2844 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2845 + && perm != SMB_ACL_EXECUTE) {
2850 + if (permset_d == NULL) {
2855 + *permset_d |= perm;
2860 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2862 + return *permset_d & perm;
2865 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2872 + * use an initial estimate of 20 bytes per ACL entry
2873 + * when allocating memory for the text representation
2877 + maxlen = 20 * acl_d->count;
2878 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2883 + for (i = 0; i < acl_d->count; i++) {
2884 + struct acl *ap = &acl_d->acl[i];
2893 + switch (ap->a_type) {
2895 + * for debugging purposes it's probably more
2896 + * useful to dump unknown tag types rather
2897 + * than just returning an error
2900 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2903 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2908 + case SMB_ACL_USER:
2909 + id = uidtoname(ap->a_id);
2910 + case SMB_ACL_USER_OBJ:
2914 + case SMB_ACL_GROUP:
2915 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2916 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2922 + case SMB_ACL_GROUP_OBJ:
2926 + case SMB_ACL_OTHER:
2930 + case SMB_ACL_MASK:
2936 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2937 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2938 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2941 + /* <tag> : <qualifier> : rwx \n \0 */
2942 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2945 + * If this entry would overflow the buffer
2946 + * allocate enough additional memory for this
2947 + * entry and an estimate of another 20 bytes
2948 + * for each entry still to be processed
2950 + if ((len + nbytes) > maxlen) {
2951 + char *oldtext = text;
2953 + maxlen += nbytes + 20 * (acl_d->count - i);
2955 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2956 + SAFE_FREE(oldtext);
2962 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2963 + len += nbytes - 1;
2972 +SMB_ACL_T sys_acl_init(int count)
2982 + * note that since the definition of the structure pointed
2983 + * to by the SMB_ACL_T includes the first element of the
2984 + * acl[] array, this actually allocates an ACL with room
2985 + * for (count+1) entries
2987 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2992 + a->size = count + 1;
3000 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3003 + SMB_ACL_ENTRY_T entry_d;
3005 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3010 + if (acl_d->count >= acl_d->size) {
3015 + entry_d = &acl_d->acl[acl_d->count++];
3016 + entry_d->a_type = 0;
3017 + entry_d->a_id = -1;
3018 + entry_d->a_perm = 0;
3019 + *entry_p = entry_d;
3024 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3026 + switch (tag_type) {
3027 + case SMB_ACL_USER:
3028 + case SMB_ACL_USER_OBJ:
3029 + case SMB_ACL_GROUP:
3030 + case SMB_ACL_GROUP_OBJ:
3031 + case SMB_ACL_OTHER:
3032 + case SMB_ACL_MASK:
3033 + entry_d->a_type = tag_type;
3043 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3045 + if (entry_d->a_type != SMB_ACL_GROUP
3046 + && entry_d->a_type != SMB_ACL_USER) {
3051 + entry_d->a_id = *((id_t *)qual_p);
3056 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3058 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3062 + entry_d->a_perm = *permset_d;
3068 + * sort the ACL and check it for validity
3070 + * if it's a minimal ACL with only 4 entries then we
3071 + * need to recalculate the mask permissions to make
3072 + * sure that they are the same as the GROUP_OBJ
3073 + * permissions as required by the UnixWare acl() system call.
3075 + * (note: since POSIX allows minimal ACLs which only contain
3076 + * 3 entries - ie there is no mask entry - we should, in theory,
3077 + * check for this and add a mask entry if necessary - however
3078 + * we "know" that the caller of this interface always specifies
3079 + * a mask so, in practice "this never happens" (tm) - if it *does*
3080 + * happen aclsort() will fail and return an error and someone will
3081 + * have to fix it ...)
3084 +static int acl_sort(SMB_ACL_T acl_d)
3086 + int fixmask = (acl_d->count <= 4);
3088 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3095 +int sys_acl_valid(SMB_ACL_T acl_d)
3097 + return acl_sort(acl_d);
3100 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3103 + struct acl *acl_p;
3105 + struct acl *acl_buf = NULL;
3108 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3113 + if (acl_sort(acl_d) != 0) {
3117 + acl_p = &acl_d->acl[0];
3118 + acl_count = acl_d->count;
3121 + * if it's a directory there is extra work to do
3122 + * since the acl() system call will replace both
3123 + * the access ACLs and the default ACLs (if any)
3125 + if (stat(name, &s) != 0) {
3128 + if (S_ISDIR(s.st_mode)) {
3129 + SMB_ACL_T acc_acl;
3130 + SMB_ACL_T def_acl;
3131 + SMB_ACL_T tmp_acl;
3134 + if (type == SMB_ACL_TYPE_ACCESS) {
3136 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3140 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3143 + if (tmp_acl == NULL) {
3148 + * allocate a temporary buffer for the complete ACL
3150 + acl_count = acc_acl->count + def_acl->count;
3151 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3153 + if (acl_buf == NULL) {
3154 + sys_acl_free_acl(tmp_acl);
3160 + * copy the access control and default entries into the buffer
3162 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3163 + acc_acl->count * sizeof(acl_buf[0]));
3165 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3166 + def_acl->count * sizeof(acl_buf[0]));
3169 + * set the ACL_DEFAULT flag on the default entries
3171 + for (i = acc_acl->count; i < acl_count; i++) {
3172 + acl_buf[i].a_type |= ACL_DEFAULT;
3175 + sys_acl_free_acl(tmp_acl);
3177 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3182 + ret = acl(name, SETACL, acl_count, acl_p);
3184 + SAFE_FREE(acl_buf);
3189 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3191 + if (acl_sort(acl_d) != 0) {
3195 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3198 +int sys_acl_delete_def_file(const char *path)
3204 + * fetching the access ACL and rewriting it has
3205 + * the effect of deleting the default ACL
3207 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3211 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3213 + sys_acl_free_acl(acl_d);
3218 +int sys_acl_free_text(char *text)
3224 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3230 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3235 +#elif defined(HAVE_HPUX_ACLS)
3239 + * Based on the Solaris/SCO code - with modifications.
3243 + * Note that while this code implements sufficient functionality
3244 + * to support the sys_acl_* interfaces it does not provide all
3245 + * of the semantics of the POSIX ACL interfaces.
3247 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3248 + * from a call to sys_acl_get_entry() should not be assumed to be
3249 + * valid after calling any of the following functions, which may
3250 + * reorder the entries in the ACL.
3253 + * sys_acl_set_file()
3254 + * sys_acl_set_fd()
3257 +/* This checks if the POSIX ACL system call is defined */
3258 +/* which basically corresponds to whether JFS 3.3 or */
3259 +/* higher is installed. If acl() was called when it */
3260 +/* isn't defined, it causes the process to core dump */
3261 +/* so it is important to check this and avoid acl() */
3262 +/* calls if it isn't there. */
3264 +static BOOL hpux_acl_call_presence(void)
3267 + shl_t handle = NULL;
3270 + static BOOL already_checked=0;
3272 + if(already_checked)
3276 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3278 + if(ret_val != 0) {
3279 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3280 + ret_val, errno, strerror(errno)));
3281 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3285 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3287 + already_checked = True;
3291 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3293 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3298 + if (entry_p == NULL) {
3303 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3307 + if (acl_d->next < 0) {
3312 + if (acl_d->next >= acl_d->count) {
3316 + *entry_p = &acl_d->acl[acl_d->next++];
3321 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3323 + *type_p = entry_d->a_type;
3328 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3330 + *permset_p = &entry_d->a_perm;
3335 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3337 + if (entry_d->a_type != SMB_ACL_USER
3338 + && entry_d->a_type != SMB_ACL_GROUP) {
3343 + return &entry_d->a_id;
3347 + * There is no way of knowing what size the ACL returned by
3348 + * ACL_GET will be unless you first call ACL_CNT which means
3349 + * making an additional system call.
3351 + * In the hope of avoiding the cost of the additional system
3352 + * call in most cases, we initially allocate enough space for
3353 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3354 + * be too small then we use ACL_CNT to find out the actual
3355 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3358 +#define INITIAL_ACL_SIZE 16
3360 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3363 + int count; /* # of ACL entries allocated */
3364 + int naccess; /* # of access ACL entries */
3365 + int ndefault; /* # of default ACL entries */
3367 + if(hpux_acl_call_presence() == False) {
3368 + /* Looks like we don't have the acl() system call on HPUX.
3369 + * May be the system doesn't have the latest version of JFS.
3374 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3379 + count = INITIAL_ACL_SIZE;
3380 + if ((acl_d = sys_acl_init(count)) == NULL) {
3385 + * If there isn't enough space for the ACL entries we use
3386 + * ACL_CNT to determine the actual number of ACL entries
3387 + * reallocate and try again. This is in a loop because it
3388 + * is possible that someone else could modify the ACL and
3389 + * increase the number of entries between the call to
3390 + * ACL_CNT and the call to ACL_GET.
3392 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3394 + sys_acl_free_acl(acl_d);
3396 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3400 + if ((acl_d = sys_acl_init(count)) == NULL) {
3406 + sys_acl_free_acl(acl_d);
3411 + * calculate the number of access and default ACL entries
3413 + * Note: we assume that the acl() system call returned a
3414 + * well formed ACL which is sorted so that all of the
3415 + * access ACL entries preceed any default ACL entries
3417 + for (naccess = 0; naccess < count; naccess++) {
3418 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3421 + ndefault = count - naccess;
3424 + * if the caller wants the default ACL we have to copy
3425 + * the entries down to the start of the acl[] buffer
3426 + * and mask out the ACL_DEFAULT flag from the type field
3428 + if (type == SMB_ACL_TYPE_DEFAULT) {
3431 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3432 + acl_d->acl[i] = acl_d->acl[j];
3433 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3436 + acl_d->count = ndefault;
3438 + acl_d->count = naccess;
3444 +SMB_ACL_T sys_acl_get_fd(int fd)
3447 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3450 + files_struct *fsp = file_find_fd(fd);
3452 + if (fsp == NULL) {
3458 + * We know we're in the same conn context. So we
3459 + * can use the relative path.
3462 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3465 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3472 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3474 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3475 + && perm != SMB_ACL_EXECUTE) {
3480 + if (permset_d == NULL) {
3485 + *permset_d |= perm;
3490 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3492 + return *permset_d & perm;
3495 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3502 + * use an initial estimate of 20 bytes per ACL entry
3503 + * when allocating memory for the text representation
3507 + maxlen = 20 * acl_d->count;
3508 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3513 + for (i = 0; i < acl_d->count; i++) {
3514 + struct acl *ap = &acl_d->acl[i];
3523 + switch (ap->a_type) {
3525 + * for debugging purposes it's probably more
3526 + * useful to dump unknown tag types rather
3527 + * than just returning an error
3530 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3533 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3538 + case SMB_ACL_USER:
3539 + id = uidtoname(ap->a_id);
3540 + case SMB_ACL_USER_OBJ:
3544 + case SMB_ACL_GROUP:
3545 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3546 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3552 + case SMB_ACL_GROUP_OBJ:
3556 + case SMB_ACL_OTHER:
3560 + case SMB_ACL_MASK:
3566 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3567 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3568 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3571 + /* <tag> : <qualifier> : rwx \n \0 */
3572 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3575 + * If this entry would overflow the buffer
3576 + * allocate enough additional memory for this
3577 + * entry and an estimate of another 20 bytes
3578 + * for each entry still to be processed
3580 + if ((len + nbytes) > maxlen) {
3581 + char *oldtext = text;
3583 + maxlen += nbytes + 20 * (acl_d->count - i);
3585 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3592 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3593 + len += nbytes - 1;
3602 +SMB_ACL_T sys_acl_init(int count)
3612 + * note that since the definition of the structure pointed
3613 + * to by the SMB_ACL_T includes the first element of the
3614 + * acl[] array, this actually allocates an ACL with room
3615 + * for (count+1) entries
3617 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3622 + a->size = count + 1;
3630 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3633 + SMB_ACL_ENTRY_T entry_d;
3635 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3640 + if (acl_d->count >= acl_d->size) {
3645 + entry_d = &acl_d->acl[acl_d->count++];
3646 + entry_d->a_type = 0;
3647 + entry_d->a_id = -1;
3648 + entry_d->a_perm = 0;
3649 + *entry_p = entry_d;
3654 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3656 + switch (tag_type) {
3657 + case SMB_ACL_USER:
3658 + case SMB_ACL_USER_OBJ:
3659 + case SMB_ACL_GROUP:
3660 + case SMB_ACL_GROUP_OBJ:
3661 + case SMB_ACL_OTHER:
3662 + case SMB_ACL_MASK:
3663 + entry_d->a_type = tag_type;
3673 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3675 + if (entry_d->a_type != SMB_ACL_GROUP
3676 + && entry_d->a_type != SMB_ACL_USER) {
3681 + entry_d->a_id = *((id_t *)qual_p);
3686 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3688 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3692 + entry_d->a_perm = *permset_d;
3697 +/* Structure to capture the count for each type of ACE. */
3699 +struct hpux_acl_types {
3703 + int n_def_user_obj;
3708 + int n_def_group_obj;
3712 + int n_def_other_obj;
3715 + int n_def_class_obj;
3717 + int n_illegal_obj;
3721 + * Counts the different number of objects in a given array of ACL
3725 + * acl_count - Count of ACLs in the array of ACL strucutres.
3726 + * aclp - Array of ACL structures.
3727 + * acl_type_count - Pointer to acl_types structure. Should already be
3731 + * acl_type_count - This structure is filled up with counts of various
3735 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3739 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3741 + for(i=0;i<acl_count;i++) {
3742 + switch(aclp[i].a_type) {
3744 + acl_type_count->n_user++;
3747 + acl_type_count->n_user_obj++;
3749 + case DEF_USER_OBJ:
3750 + acl_type_count->n_def_user_obj++;
3753 + acl_type_count->n_group++;
3756 + acl_type_count->n_group_obj++;
3758 + case DEF_GROUP_OBJ:
3759 + acl_type_count->n_def_group_obj++;
3762 + acl_type_count->n_other_obj++;
3764 + case DEF_OTHER_OBJ:
3765 + acl_type_count->n_def_other_obj++;
3768 + acl_type_count->n_class_obj++;
3770 + case DEF_CLASS_OBJ:
3771 + acl_type_count->n_def_class_obj++;
3774 + acl_type_count->n_def_user++;
3777 + acl_type_count->n_def_group++;
3780 + acl_type_count->n_illegal_obj++;
3786 +/* swap_acl_entries: Swaps two ACL entries.
3788 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3791 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3793 + struct acl temp_acl;
3795 + temp_acl.a_type = aclp0->a_type;
3796 + temp_acl.a_id = aclp0->a_id;
3797 + temp_acl.a_perm = aclp0->a_perm;
3799 + aclp0->a_type = aclp1->a_type;
3800 + aclp0->a_id = aclp1->a_id;
3801 + aclp0->a_perm = aclp1->a_perm;
3803 + aclp1->a_type = temp_acl.a_type;
3804 + aclp1->a_id = temp_acl.a_id;
3805 + aclp1->a_perm = temp_acl.a_perm;
3808 +/* prohibited_duplicate_type
3809 + * Identifies if given ACL type can have duplicate entries or
3812 + * Inputs: acl_type - ACL Type.
3818 + * True - If the ACL type matches any of the prohibited types.
3819 + * False - If the ACL type doesn't match any of the prohibited types.
3822 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3824 + switch(acl_type) {
3835 +/* get_needed_class_perm
3836 + * Returns the permissions of a ACL structure only if the ACL
3837 + * type matches one of the pre-determined types for computing
3838 + * CLASS_OBJ permissions.
3840 + * Inputs: aclp - Pointer to ACL structure.
3843 +static int hpux_get_needed_class_perm(struct acl *aclp)
3845 + switch(aclp->a_type) {
3849 + case DEF_USER_OBJ:
3851 + case DEF_GROUP_OBJ:
3853 + case DEF_CLASS_OBJ:
3854 + case DEF_OTHER_OBJ:
3855 + return aclp->a_perm;
3861 +/* acl_sort for HPUX.
3862 + * Sorts the array of ACL structures as per the description in
3863 + * aclsort man page. Refer to aclsort man page for more details
3867 + * acl_count - Count of ACLs in the array of ACL structures.
3868 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3870 + * aclp - Array of ACL structures.
3874 + * aclp - Sorted array of ACL structures.
3878 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3879 + * debug log in case of failure.
3882 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3884 +#if !defined(HAVE_HPUX_ACLSORT)
3886 + * The aclsort() system call is availabe on the latest HPUX General
3887 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3888 + * function. Because, we don't want to update to a new
3889 + * HPUX GR bundle just for aclsort() call.
3892 + struct hpux_acl_types acl_obj_count;
3893 + int n_class_obj_perm = 0;
3897 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3901 + if(aclp == NULL) {
3902 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3906 + /* Count different types of ACLs in the ACLs array */
3908 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3910 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3911 + * CLASS_OBJ and OTHER_OBJ
3914 + if( (acl_obj_count.n_user_obj != 1) ||
3915 + (acl_obj_count.n_group_obj != 1) ||
3916 + (acl_obj_count.n_class_obj != 1) ||
3917 + (acl_obj_count.n_other_obj != 1)
3919 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3920 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3924 + /* If any of the default objects are present, there should be only
3925 + * one of them each.
3928 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3929 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3930 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3931 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3935 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3938 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3939 + * same ACL type, sort by ACL id.
3941 + * I am using the trival kind of sorting method here because, performance isn't
3942 + * really effected by the ACLs feature. More over there aren't going to be more
3943 + * than 17 entries on HPUX.
3946 + for(i=0; i<acl_count;i++) {
3947 + for (j=i+1; j<acl_count; j++) {
3948 + if( aclp[i].a_type > aclp[j].a_type ) {
3949 + /* ACL entries out of order, swap them */
3951 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3953 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3955 + /* ACL entries of same type, sort by id */
3957 + if(aclp[i].a_id > aclp[j].a_id) {
3958 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3959 + } else if (aclp[i].a_id == aclp[j].a_id) {
3960 + /* We have a duplicate entry. */
3961 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3962 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3963 + aclp[i].a_type, aclp[i].a_id));
3972 + /* set the class obj permissions to the computed one. */
3974 + int n_class_obj_index = -1;
3976 + for(i=0;i<acl_count;i++) {
3977 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3979 + if(aclp[i].a_type == CLASS_OBJ)
3980 + n_class_obj_index = i;
3982 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3987 + return aclsort(acl_count, calclass, aclp);
3992 + * sort the ACL and check it for validity
3994 + * if it's a minimal ACL with only 4 entries then we
3995 + * need to recalculate the mask permissions to make
3996 + * sure that they are the same as the GROUP_OBJ
3997 + * permissions as required by the UnixWare acl() system call.
3999 + * (note: since POSIX allows minimal ACLs which only contain
4000 + * 3 entries - ie there is no mask entry - we should, in theory,
4001 + * check for this and add a mask entry if necessary - however
4002 + * we "know" that the caller of this interface always specifies
4003 + * a mask so, in practice "this never happens" (tm) - if it *does*
4004 + * happen aclsort() will fail and return an error and someone will
4005 + * have to fix it ...)
4008 +static int acl_sort(SMB_ACL_T acl_d)
4010 + int fixmask = (acl_d->count <= 4);
4012 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4019 +int sys_acl_valid(SMB_ACL_T acl_d)
4021 + return acl_sort(acl_d);
4024 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4027 + struct acl *acl_p;
4029 + struct acl *acl_buf = NULL;
4032 + if(hpux_acl_call_presence() == False) {
4033 + /* Looks like we don't have the acl() system call on HPUX.
4034 + * May be the system doesn't have the latest version of JFS.
4040 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4045 + if (acl_sort(acl_d) != 0) {
4049 + acl_p = &acl_d->acl[0];
4050 + acl_count = acl_d->count;
4053 + * if it's a directory there is extra work to do
4054 + * since the acl() system call will replace both
4055 + * the access ACLs and the default ACLs (if any)
4057 + if (stat(name, &s) != 0) {
4060 + if (S_ISDIR(s.st_mode)) {
4061 + SMB_ACL_T acc_acl;
4062 + SMB_ACL_T def_acl;
4063 + SMB_ACL_T tmp_acl;
4066 + if (type == SMB_ACL_TYPE_ACCESS) {
4068 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4072 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4075 + if (tmp_acl == NULL) {
4080 + * allocate a temporary buffer for the complete ACL
4082 + acl_count = acc_acl->count + def_acl->count;
4083 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4085 + if (acl_buf == NULL) {
4086 + sys_acl_free_acl(tmp_acl);
4092 + * copy the access control and default entries into the buffer
4094 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4095 + acc_acl->count * sizeof(acl_buf[0]));
4097 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4098 + def_acl->count * sizeof(acl_buf[0]));
4101 + * set the ACL_DEFAULT flag on the default entries
4103 + for (i = acc_acl->count; i < acl_count; i++) {
4104 + acl_buf[i].a_type |= ACL_DEFAULT;
4107 + sys_acl_free_acl(tmp_acl);
4109 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4114 + ret = acl(name, ACL_SET, acl_count, acl_p);
4123 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4126 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4129 + files_struct *fsp = file_find_fd(fd);
4131 + if (fsp == NULL) {
4136 + if (acl_sort(acl_d) != 0) {
4141 + * We know we're in the same conn context. So we
4142 + * can use the relative path.
4145 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4148 +int sys_acl_delete_def_file(const char *path)
4154 + * fetching the access ACL and rewriting it has
4155 + * the effect of deleting the default ACL
4157 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4161 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4163 + sys_acl_free_acl(acl_d);
4168 +int sys_acl_free_text(char *text)
4174 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4180 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4185 +#elif defined(HAVE_IRIX_ACLS)
4187 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4189 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4194 + if (entry_p == NULL) {
4199 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4203 + if (acl_d->next < 0) {
4208 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4212 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4217 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4219 + *type_p = entry_d->ae_tag;
4224 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4226 + *permset_p = entry_d;
4231 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4233 + if (entry_d->ae_tag != SMB_ACL_USER
4234 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4239 + return &entry_d->ae_id;
4242 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4246 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4250 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4255 + a->freeaclp = True;
4259 +SMB_ACL_T sys_acl_get_fd(int fd)
4263 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4267 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4272 + a->freeaclp = True;
4276 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4278 + permset_d->ae_perm = 0;
4283 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4285 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4286 + && perm != SMB_ACL_EXECUTE) {
4291 + if (permset_d == NULL) {
4296 + permset_d->ae_perm |= perm;
4301 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4303 + return permset_d->ae_perm & perm;
4306 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4308 + return acl_to_text(acl_d->aclp, len_p);
4311 +SMB_ACL_T sys_acl_init(int count)
4320 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4326 + a->freeaclp = False;
4327 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4328 + a->aclp->acl_cnt = 0;
4334 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4337 + SMB_ACL_ENTRY_T entry_d;
4339 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4344 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4349 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4350 + entry_d->ae_tag = 0;
4351 + entry_d->ae_id = 0;
4352 + entry_d->ae_perm = 0;
4353 + *entry_p = entry_d;
4358 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4360 + switch (tag_type) {
4361 + case SMB_ACL_USER:
4362 + case SMB_ACL_USER_OBJ:
4363 + case SMB_ACL_GROUP:
4364 + case SMB_ACL_GROUP_OBJ:
4365 + case SMB_ACL_OTHER:
4366 + case SMB_ACL_MASK:
4367 + entry_d->ae_tag = tag_type;
4377 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4379 + if (entry_d->ae_tag != SMB_ACL_GROUP
4380 + && entry_d->ae_tag != SMB_ACL_USER) {
4385 + entry_d->ae_id = *((id_t *)qual_p);
4390 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4392 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4396 + entry_d->ae_perm = permset_d->ae_perm;
4401 +int sys_acl_valid(SMB_ACL_T acl_d)
4403 + return acl_valid(acl_d->aclp);
4406 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4408 + return acl_set_file(name, type, acl_d->aclp);
4411 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4413 + return acl_set_fd(fd, acl_d->aclp);
4416 +int sys_acl_delete_def_file(const char *name)
4418 + return acl_delete_def_file(name);
4421 +int sys_acl_free_text(char *text)
4423 + return acl_free(text);
4426 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4428 + if (acl_d->freeaclp) {
4429 + acl_free(acl_d->aclp);
4435 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4440 +#elif defined(HAVE_AIX_ACLS)
4442 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4444 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4446 + struct acl_entry_link *link;
4447 + struct new_acl_entry *entry;
4450 + DEBUG(10,("This is the count: %d\n",theacl->count));
4452 + /* Check if count was previously set to -1. *
4453 + * If it was, that means we reached the end *
4454 + * of the acl last time. */
4455 + if(theacl->count == -1)
4459 + /* To get to the next acl, traverse linked list until index *
4460 + * of acl matches the count we are keeping. This count is *
4461 + * incremented each time we return an acl entry. */
4463 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4464 + link = link->nextp;
4466 + entry = *entry_p = link->entryp;
4468 + DEBUG(10,("*entry_p is %d\n",entry_p));
4469 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4471 + /* Increment count */
4473 + if(link->nextp == NULL)
4474 + theacl->count = -1;
4479 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4481 + /* Initialize tag type */
4484 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4486 + /* Depending on what type of entry we have, *
4487 + * return tag type. */
4488 + switch(entry_d->ace_id->id_type) {
4490 + *tag_type_p = SMB_ACL_USER;
4493 + *tag_type_p = SMB_ACL_GROUP;
4496 + case SMB_ACL_USER_OBJ:
4497 + case SMB_ACL_GROUP_OBJ:
4498 + case SMB_ACL_OTHER:
4499 + *tag_type_p = entry_d->ace_id->id_type;
4509 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4511 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4512 + *permset_p = &entry_d->ace_access;
4513 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4514 + if(!(**permset_p & S_IXUSR) &&
4515 + !(**permset_p & S_IWUSR) &&
4516 + !(**permset_p & S_IRUSR) &&
4517 + (**permset_p != 0))
4520 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4524 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4526 + return(entry_d->ace_id->id_data);
4529 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4531 + struct acl *file_acl = (struct acl *)NULL;
4532 + struct acl_entry *acl_entry;
4533 + struct new_acl_entry *new_acl_entry;
4534 + struct ace_id *idp;
4535 + struct acl_entry_link *acl_entry_link;
4536 + struct acl_entry_link *acl_entry_link_head;
4541 + /* AIX has no DEFAULT */
4542 + if ( type == SMB_ACL_TYPE_DEFAULT )
4545 + /* Get the acl using statacl */
4547 + DEBUG(10,("Entering sys_acl_get_file\n"));
4548 + DEBUG(10,("path_p is %s\n",path_p));
4550 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4552 + if(file_acl == NULL) {
4554 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4558 + memset(file_acl,0,BUFSIZ);
4560 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4562 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4563 + SAFE_FREE(file_acl);
4567 + DEBUG(10,("Got facl and returned it\n"));
4569 + /* Point to the first acl entry in the acl */
4570 + acl_entry = file_acl->acl_ext;
4572 + /* Begin setting up the head of the linked list *
4573 + * that will be used for the storing the acl *
4574 + * in a way that is useful for the posix_acls.c *
4577 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4578 + if(acl_entry_link_head == NULL)
4581 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4582 + if(acl_entry_link->entryp == NULL) {
4583 + SAFE_FREE(file_acl);
4585 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4589 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4590 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4592 + /* Check if the extended acl bit is on. *
4593 + * If it isn't, do not show the *
4594 + * contents of the acl since AIX intends *
4595 + * the extended info to remain unused */
4597 + if(file_acl->acl_mode & S_IXACL){
4598 + /* while we are not pointing to the very end */
4599 + while(acl_entry < acl_last(file_acl)) {
4600 + /* before we malloc anything, make sure this is */
4601 + /* a valid acl entry and one that we want to map */
4602 + idp = id_nxt(acl_entry->ace_id);
4603 + if((acl_entry->ace_type == ACC_SPECIFY ||
4604 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4605 + acl_entry = acl_nxt(acl_entry);
4609 + idp = acl_entry->ace_id;
4611 + /* Check if this is the first entry in the linked list. *
4612 + * The first entry needs to keep prevp pointing to NULL *
4613 + * and already has entryp allocated. */
4615 + if(acl_entry_link_head->count != 0) {
4616 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4618 + if(acl_entry_link->nextp == NULL) {
4619 + SAFE_FREE(file_acl);
4621 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4625 + acl_entry_link->nextp->prevp = acl_entry_link;
4626 + acl_entry_link = acl_entry_link->nextp;
4627 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4628 + if(acl_entry_link->entryp == NULL) {
4629 + SAFE_FREE(file_acl);
4631 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4634 + acl_entry_link->nextp = NULL;
4637 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4639 + /* Don't really need this since all types are going *
4640 + * to be specified but, it's better than leaving it 0 */
4642 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4644 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4646 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4648 + /* The access in the acl entries must be left shifted by *
4649 + * three bites, because they will ultimately be compared *
4650 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4652 + switch(acl_entry->ace_type){
4655 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4656 + acl_entry_link->entryp->ace_access <<= 6;
4657 + acl_entry_link_head->count++;
4660 + /* Since there is no way to return a DENY acl entry *
4661 + * change to PERMIT and then shift. */
4662 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4663 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4664 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4665 + acl_entry_link->entryp->ace_access <<= 6;
4666 + acl_entry_link_head->count++;
4672 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4673 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4675 + acl_entry = acl_nxt(acl_entry);
4677 + } /* end of if enabled */
4679 + /* Since owner, group, other acl entries are not *
4680 + * part of the acl entries in an acl, they must *
4681 + * be dummied up to become part of the list. */
4683 + for( i = 1; i < 4; i++) {
4684 + DEBUG(10,("i is %d\n",i));
4685 + if(acl_entry_link_head->count != 0) {
4686 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4687 + if(acl_entry_link->nextp == NULL) {
4688 + SAFE_FREE(file_acl);
4690 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4694 + acl_entry_link->nextp->prevp = acl_entry_link;
4695 + acl_entry_link = acl_entry_link->nextp;
4696 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4697 + if(acl_entry_link->entryp == NULL) {
4698 + SAFE_FREE(file_acl);
4700 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4705 + acl_entry_link->nextp = NULL;
4707 + new_acl_entry = acl_entry_link->entryp;
4708 + idp = new_acl_entry->ace_id;
4710 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4711 + new_acl_entry->ace_type = ACC_PERMIT;
4712 + idp->id_len = sizeof(struct ace_id);
4713 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4714 + memset(idp->id_data,0,sizeof(uid_t));
4718 + new_acl_entry->ace_access = file_acl->g_access << 6;
4719 + idp->id_type = SMB_ACL_GROUP_OBJ;
4723 + new_acl_entry->ace_access = file_acl->o_access << 6;
4724 + idp->id_type = SMB_ACL_OTHER;
4728 + new_acl_entry->ace_access = file_acl->u_access << 6;
4729 + idp->id_type = SMB_ACL_USER_OBJ;
4737 + acl_entry_link_head->count++;
4738 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4741 + acl_entry_link_head->count = 0;
4742 + SAFE_FREE(file_acl);
4744 + return(acl_entry_link_head);
4747 +SMB_ACL_T sys_acl_get_fd(int fd)
4749 + struct acl *file_acl = (struct acl *)NULL;
4750 + struct acl_entry *acl_entry;
4751 + struct new_acl_entry *new_acl_entry;
4752 + struct ace_id *idp;
4753 + struct acl_entry_link *acl_entry_link;
4754 + struct acl_entry_link *acl_entry_link_head;
4759 + /* Get the acl using fstatacl */
4761 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4762 + DEBUG(10,("fd is %d\n",fd));
4763 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4765 + if(file_acl == NULL) {
4767 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4771 + memset(file_acl,0,BUFSIZ);
4773 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4775 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4776 + SAFE_FREE(file_acl);
4780 + DEBUG(10,("Got facl and returned it\n"));
4782 + /* Point to the first acl entry in the acl */
4784 + acl_entry = file_acl->acl_ext;
4785 + /* Begin setting up the head of the linked list *
4786 + * that will be used for the storing the acl *
4787 + * in a way that is useful for the posix_acls.c *
4790 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4791 + if(acl_entry_link_head == NULL){
4792 + SAFE_FREE(file_acl);
4796 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4798 + if(acl_entry_link->entryp == NULL) {
4800 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4801 + SAFE_FREE(file_acl);
4805 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4806 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4808 + /* Check if the extended acl bit is on. *
4809 + * If it isn't, do not show the *
4810 + * contents of the acl since AIX intends *
4811 + * the extended info to remain unused */
4813 + if(file_acl->acl_mode & S_IXACL){
4814 + /* while we are not pointing to the very end */
4815 + while(acl_entry < acl_last(file_acl)) {
4816 + /* before we malloc anything, make sure this is */
4817 + /* a valid acl entry and one that we want to map */
4819 + idp = id_nxt(acl_entry->ace_id);
4820 + if((acl_entry->ace_type == ACC_SPECIFY ||
4821 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4822 + acl_entry = acl_nxt(acl_entry);
4826 + idp = acl_entry->ace_id;
4828 + /* Check if this is the first entry in the linked list. *
4829 + * The first entry needs to keep prevp pointing to NULL *
4830 + * and already has entryp allocated. */
4832 + if(acl_entry_link_head->count != 0) {
4833 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4834 + if(acl_entry_link->nextp == NULL) {
4836 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4837 + SAFE_FREE(file_acl);
4840 + acl_entry_link->nextp->prevp = acl_entry_link;
4841 + acl_entry_link = acl_entry_link->nextp;
4842 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4843 + if(acl_entry_link->entryp == NULL) {
4845 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4846 + SAFE_FREE(file_acl);
4850 + acl_entry_link->nextp = NULL;
4853 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4855 + /* Don't really need this since all types are going *
4856 + * to be specified but, it's better than leaving it 0 */
4858 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4859 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4861 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4863 + /* The access in the acl entries must be left shifted by *
4864 + * three bites, because they will ultimately be compared *
4865 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4867 + switch(acl_entry->ace_type){
4870 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4871 + acl_entry_link->entryp->ace_access <<= 6;
4872 + acl_entry_link_head->count++;
4875 + /* Since there is no way to return a DENY acl entry *
4876 + * change to PERMIT and then shift. */
4877 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4878 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4879 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4880 + acl_entry_link->entryp->ace_access <<= 6;
4881 + acl_entry_link_head->count++;
4887 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4888 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4890 + acl_entry = acl_nxt(acl_entry);
4892 + } /* end of if enabled */
4894 + /* Since owner, group, other acl entries are not *
4895 + * part of the acl entries in an acl, they must *
4896 + * be dummied up to become part of the list. */
4898 + for( i = 1; i < 4; i++) {
4899 + DEBUG(10,("i is %d\n",i));
4900 + if(acl_entry_link_head->count != 0){
4901 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4902 + if(acl_entry_link->nextp == NULL) {
4904 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4905 + SAFE_FREE(file_acl);
4909 + acl_entry_link->nextp->prevp = acl_entry_link;
4910 + acl_entry_link = acl_entry_link->nextp;
4911 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4913 + if(acl_entry_link->entryp == NULL) {
4914 + SAFE_FREE(file_acl);
4916 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4921 + acl_entry_link->nextp = NULL;
4923 + new_acl_entry = acl_entry_link->entryp;
4924 + idp = new_acl_entry->ace_id;
4926 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4927 + new_acl_entry->ace_type = ACC_PERMIT;
4928 + idp->id_len = sizeof(struct ace_id);
4929 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4930 + memset(idp->id_data,0,sizeof(uid_t));
4934 + new_acl_entry->ace_access = file_acl->g_access << 6;
4935 + idp->id_type = SMB_ACL_GROUP_OBJ;
4939 + new_acl_entry->ace_access = file_acl->o_access << 6;
4940 + idp->id_type = SMB_ACL_OTHER;
4944 + new_acl_entry->ace_access = file_acl->u_access << 6;
4945 + idp->id_type = SMB_ACL_USER_OBJ;
4952 + acl_entry_link_head->count++;
4953 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4956 + acl_entry_link_head->count = 0;
4957 + SAFE_FREE(file_acl);
4959 + return(acl_entry_link_head);
4962 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4964 + *permset = *permset & ~0777;
4968 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4971 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4975 + DEBUG(10,("This is the permset now: %d\n",*permset));
4979 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4984 +SMB_ACL_T sys_acl_init( int count)
4986 + struct acl_entry_link *theacl = NULL;
4988 + DEBUG(10,("Entering sys_acl_init\n"));
4990 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4991 + if(theacl == NULL) {
4993 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4997 + theacl->count = 0;
4998 + theacl->nextp = NULL;
4999 + theacl->prevp = NULL;
5000 + theacl->entryp = NULL;
5001 + DEBUG(10,("Exiting sys_acl_init\n"));
5005 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5007 + struct acl_entry_link *theacl;
5008 + struct acl_entry_link *acl_entryp;
5009 + struct acl_entry_link *temp_entry;
5012 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5014 + theacl = acl_entryp = *pacl;
5016 + /* Get to the end of the acl before adding entry */
5018 + for(counting=0; counting < theacl->count; counting++){
5019 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5020 + temp_entry = acl_entryp;
5021 + acl_entryp = acl_entryp->nextp;
5024 + if(theacl->count != 0){
5025 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5026 + if(acl_entryp == NULL) {
5028 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5032 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5033 + acl_entryp->prevp = temp_entry;
5034 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5037 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5038 + if(*pentry == NULL) {
5040 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5044 + memset(*pentry,0,sizeof(struct new_acl_entry));
5045 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5046 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5047 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5048 + acl_entryp->nextp = NULL;
5050 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5054 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5056 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5057 + entry->ace_id->id_type = tagtype;
5058 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5059 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5062 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5064 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5065 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5066 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5070 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5072 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5073 + if(!(*permset & S_IXUSR) &&
5074 + !(*permset & S_IWUSR) &&
5075 + !(*permset & S_IRUSR) &&
5079 + entry->ace_access = *permset;
5080 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5081 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5085 +int sys_acl_valid( SMB_ACL_T theacl )
5088 + int group_obj = 0;
5089 + int other_obj = 0;
5090 + struct acl_entry_link *acl_entry;
5092 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5093 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5094 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5095 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5098 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5100 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5106 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5108 + struct acl_entry_link *acl_entry_link = NULL;
5109 + struct acl *file_acl = NULL;
5110 + struct acl *file_acl_temp = NULL;
5111 + struct acl_entry *acl_entry = NULL;
5112 + struct ace_id *ace_id = NULL;
5119 + DEBUG(10,("Entering sys_acl_set_file\n"));
5120 + DEBUG(10,("File name is %s\n",name));
5122 + /* AIX has no default ACL */
5123 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5126 + acl_length = BUFSIZ;
5127 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5129 + if(file_acl == NULL) {
5131 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5135 + memset(file_acl,0,BUFSIZ);
5137 + file_acl->acl_len = ACL_SIZ;
5138 + file_acl->acl_mode = S_IXACL;
5140 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5141 + acl_entry_link->entryp->ace_access >>= 6;
5142 + id_type = acl_entry_link->entryp->ace_id->id_type;
5145 + case SMB_ACL_USER_OBJ:
5146 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5148 + case SMB_ACL_GROUP_OBJ:
5149 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5151 + case SMB_ACL_OTHER:
5152 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5154 + case SMB_ACL_MASK:
5158 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5159 + acl_length += sizeof(struct acl_entry);
5160 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5161 + if(file_acl_temp == NULL) {
5162 + SAFE_FREE(file_acl);
5164 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5168 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5169 + SAFE_FREE(file_acl);
5170 + file_acl = file_acl_temp;
5173 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5174 + file_acl->acl_len += sizeof(struct acl_entry);
5175 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5176 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5178 + /* In order to use this, we'll need to wait until we can get denies */
5179 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5180 + acl_entry->ace_type = ACC_SPECIFY; */
5182 + acl_entry->ace_type = ACC_SPECIFY;
5184 + ace_id = acl_entry->ace_id;
5186 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5187 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5188 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5189 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5190 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5193 + rc = chacl(name,file_acl,file_acl->acl_len);
5194 + DEBUG(10,("errno is %d\n",errno));
5195 + DEBUG(10,("return code is %d\n",rc));
5196 + SAFE_FREE(file_acl);
5197 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5201 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5203 + struct acl_entry_link *acl_entry_link = NULL;
5204 + struct acl *file_acl = NULL;
5205 + struct acl *file_acl_temp = NULL;
5206 + struct acl_entry *acl_entry = NULL;
5207 + struct ace_id *ace_id = NULL;
5213 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5214 + acl_length = BUFSIZ;
5215 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5217 + if(file_acl == NULL) {
5219 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5223 + memset(file_acl,0,BUFSIZ);
5225 + file_acl->acl_len = ACL_SIZ;
5226 + file_acl->acl_mode = S_IXACL;
5228 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5229 + acl_entry_link->entryp->ace_access >>= 6;
5230 + id_type = acl_entry_link->entryp->ace_id->id_type;
5231 + DEBUG(10,("The id_type is %d\n",id_type));
5234 + case SMB_ACL_USER_OBJ:
5235 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5237 + case SMB_ACL_GROUP_OBJ:
5238 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5240 + case SMB_ACL_OTHER:
5241 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5243 + case SMB_ACL_MASK:
5247 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5248 + acl_length += sizeof(struct acl_entry);
5249 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5250 + if(file_acl_temp == NULL) {
5251 + SAFE_FREE(file_acl);
5253 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5257 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5258 + SAFE_FREE(file_acl);
5259 + file_acl = file_acl_temp;
5262 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5263 + file_acl->acl_len += sizeof(struct acl_entry);
5264 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5265 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5267 + /* In order to use this, we'll need to wait until we can get denies */
5268 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5269 + acl_entry->ace_type = ACC_SPECIFY; */
5271 + acl_entry->ace_type = ACC_SPECIFY;
5273 + ace_id = acl_entry->ace_id;
5275 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5276 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5277 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5278 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5279 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5282 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5283 + DEBUG(10,("errno is %d\n",errno));
5284 + DEBUG(10,("return code is %d\n",rc));
5285 + SAFE_FREE(file_acl);
5286 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5290 +int sys_acl_delete_def_file(const char *name)
5292 + /* AIX has no default ACL */
5296 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5298 + return(*permset & perm);
5301 +int sys_acl_free_text(char *text)
5306 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5308 + struct acl_entry_link *acl_entry_link;
5310 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5311 + SAFE_FREE(acl_entry_link->prevp->entryp);
5312 + SAFE_FREE(acl_entry_link->prevp);
5315 + SAFE_FREE(acl_entry_link->prevp->entryp);
5316 + SAFE_FREE(acl_entry_link->prevp);
5317 + SAFE_FREE(acl_entry_link->entryp);
5318 + SAFE_FREE(acl_entry_link);
5323 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5328 +#else /* No ACLs. */
5330 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5336 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5342 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5348 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5354 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5357 + return (SMB_ACL_T)NULL;
5360 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5363 + return (SMB_ACL_T)NULL;
5366 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5372 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5378 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5381 + return (permset & perm) ? 1 : 0;
5384 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5390 +int sys_acl_free_text(UNUSED(char *text))
5396 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5402 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5408 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5414 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5420 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5426 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5432 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5438 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5444 +int sys_acl_delete_def_file(UNUSED(const char *name))
5450 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5456 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5462 +#endif /* No ACLs. */
5464 +/************************************************************************
5465 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5467 +************************************************************************/
5469 +int no_acl_syscall_error(int err)
5471 +#if defined(ENOSYS)
5472 + if (err == ENOSYS) {
5476 +#if defined(ENOTSUP)
5477 + if (err == ENOTSUP) {
5483 --- old/lib/sysacls.h
5484 +++ new/lib/sysacls.h
5486 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5487 +#include <sys/acl.h>
5489 +#include "smb_acls.h"
5491 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5492 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5493 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5494 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5495 +#define slprintf snprintf
5497 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5498 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5499 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5500 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5501 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5502 +SMB_ACL_T sys_acl_get_fd(int fd);
5503 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5504 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5505 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5506 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5507 +SMB_ACL_T sys_acl_init(int count);
5508 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5509 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5510 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5511 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5512 +int sys_acl_valid(SMB_ACL_T theacl);
5513 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5514 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5515 +int sys_acl_delete_def_file(const char *name);
5516 +int sys_acl_free_text(char *text);
5517 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5518 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5521 @@ -609,8 +609,10 @@ static void log_formatted(enum logcode c
5522 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5523 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5524 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5527 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5528 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5529 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5532 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5533 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5536 @@ -58,7 +58,7 @@ BEGIN {
5540 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5541 +!/^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/ {
5547 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5549 int preserve_links = 0;
5550 int preserve_hard_links = 0;
5551 +int preserve_acls = 0;
5552 int preserve_perms = 0;
5553 int preserve_executability = 0;
5554 int preserve_devices = 0;
5555 @@ -198,6 +199,7 @@ static void print_rsync_version(enum log
5556 char const *got_socketpair = "no ";
5557 char const *have_inplace = "no ";
5558 char const *hardlinks = "no ";
5559 + char const *acls = "no ";
5560 char const *links = "no ";
5561 char const *ipv6 = "no ";
5562 STRUCT_STAT *dumstat;
5563 @@ -214,6 +216,10 @@ static void print_rsync_version(enum log
5567 +#ifdef SUPPORT_ACLS
5571 #ifdef SUPPORT_LINKS
5574 @@ -227,9 +233,9 @@ static void print_rsync_version(enum log
5575 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5576 rprintf(f, "<http://rsync.samba.org/>\n");
5577 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5578 - "%shard links, %ssymlinks, batchfiles,\n",
5579 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
5580 (int) (sizeof (OFF_T) * 8),
5581 - got_socketpair, hardlinks, links);
5582 + got_socketpair, hardlinks, acls, links);
5584 /* Note that this field may not have type ino_t. It depends
5585 * on the complicated interaction between largefile feature
5586 @@ -282,7 +288,7 @@ void usage(enum logcode F)
5587 rprintf(F," -v, --verbose increase verbosity\n");
5588 rprintf(F," -q, --quiet suppress non-error messages\n");
5589 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5590 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5591 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5592 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5593 rprintf(F," -r, --recursive recurse into directories\n");
5594 rprintf(F," -R, --relative use relative path names\n");
5595 @@ -304,6 +310,9 @@ void usage(enum logcode F)
5596 rprintf(F," -p, --perms preserve permissions\n");
5597 rprintf(F," -E, --executability preserve the file's executability\n");
5598 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5599 +#ifdef SUPPORT_ACLS
5600 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5602 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5603 rprintf(F," -g, --group preserve group\n");
5604 rprintf(F," --devices preserve device files (super-user only)\n");
5605 @@ -421,6 +430,9 @@ static struct poptOption long_options[]
5606 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5607 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5608 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5609 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5610 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5611 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5612 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5613 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5614 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5615 @@ -1084,6 +1096,24 @@ int parse_arguments(int *argc, const cha
5620 +#ifdef SUPPORT_ACLS
5622 + preserve_perms = 1;
5625 + /* FIXME: this should probably be ignored with a
5626 + * warning and then countermeasures taken to
5627 + * restrict group and other access in the presence
5628 + * of any more restrictive ACLs, but this is safe
5630 + snprintf(err_buf,sizeof(err_buf),
5631 + "ACLs are not supported on this %s\n",
5632 + am_server ? "server" : "client");
5638 /* A large opt value means that set_refuse_options()
5639 * turned this option off. */
5640 @@ -1529,6 +1559,10 @@ void server_options(char **args,int *arg
5642 if (preserve_hard_links)
5644 +#ifdef SUPPORT_ACLS
5645 + if (preserve_acls)
5646 + argstr[x++] = 'A';
5653 @@ -47,6 +47,7 @@ extern int keep_partial;
5654 extern int checksum_seed;
5656 extern int delay_updates;
5657 +extern mode_t orig_umask;
5658 extern struct stats stats;
5659 extern char *stdout_format;
5660 extern char *tmpdir;
5661 @@ -349,6 +350,10 @@ int recv_files(int f_in, struct file_lis
5662 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5663 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5664 int max_phase = protocol_version >= 29 ? 2 : 1;
5665 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5666 +#ifdef SUPPORT_ACLS
5667 + char *parent_dirname = "";
5672 @@ -549,7 +554,16 @@ int recv_files(int f_in, struct file_lis
5673 * mode based on the local permissions and some heuristics. */
5674 if (!preserve_perms) {
5675 int exists = fd1 != -1;
5676 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5677 +#ifdef SUPPORT_ACLS
5678 + char *dn = file->dirname ? file->dirname : ".";
5679 + if (parent_dirname != dn
5680 + && strcmp(parent_dirname, dn) != 0) {
5681 + dflt_perms = default_perms_for_dir(dn);
5682 + parent_dirname = dn;
5685 + file->mode = dest_mode(file->mode, st.st_mode,
5686 + dflt_perms, exists);
5689 /* We now check to see if we are writing the file "inplace" */
5696 +extern int preserve_acls;
5697 extern int preserve_perms;
5698 extern int preserve_executability;
5699 extern int preserve_times;
5700 @@ -100,7 +101,8 @@ void free_sums(struct sum_struct *s)
5702 /* This is only called when we aren't preserving permissions. Figure out what
5703 * the permissions should be and return them merged back into the mode. */
5704 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5705 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5709 /* If the file already exists, we'll return the local permissions,
5710 @@ -117,56 +119,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5711 new_mode |= (new_mode & 0444) >> 2;
5714 - /* Apply the umask and turn off special permissions. */
5715 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5716 + /* Apply destination default permissions and turn
5717 + * off special permissions. */
5718 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5723 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5724 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5730 int change_uid, change_gid;
5731 mode_t new_mode = file->mode;
5737 - if (link_stat(fname, &st2, 0) < 0) {
5738 + if (link_stat(fname, &sx2.st, 0) < 0) {
5739 rsyserr(FERROR, errno, "stat %s failed",
5744 +#ifdef SUPPORT_ACLS
5745 + sx2.acc_acl = sx2.def_acl = NULL;
5747 if (!preserve_perms && S_ISDIR(new_mode)
5748 - && st->st_mode & S_ISGID) {
5749 + && sx2.st.st_mode & S_ISGID) {
5750 /* We just created this directory and its setgid
5751 * bit is on, so make sure it stays on. */
5752 new_mode |= S_ISGID;
5757 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5758 +#ifdef SUPPORT_ACLS
5759 + if (preserve_acls && !ACL_READY(*sxp))
5760 + get_acl(fname, sxp);
5763 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5764 flags |= ATTRS_SKIP_MTIME;
5765 if (!(flags & ATTRS_SKIP_MTIME)
5766 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5767 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5768 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5769 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5771 rsyserr(FERROR, errno, "failed to set times on %s",
5776 if (ret == 0) /* ret == 1 if symlink could not be set */
5780 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5781 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5782 change_gid = preserve_gid && file->gid != GID_NONE
5783 - && st->st_gid != file->gid;
5784 + && sxp->st.st_gid != file->gid;
5785 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5786 - if (S_ISLNK(st->st_mode))
5787 + if (S_ISLNK(sxp->st.st_mode))
5791 @@ -176,45 +187,57 @@ int set_file_attrs(char *fname, struct f
5793 "set uid of %s from %ld to %ld\n",
5795 - (long)st->st_uid, (long)file->uid);
5796 + (long)sxp->st.st_uid, (long)file->uid);
5800 "set gid of %s from %ld to %ld\n",
5802 - (long)st->st_gid, (long)file->gid);
5803 + (long)sxp->st.st_gid, (long)file->gid);
5806 if (do_lchown(fname,
5807 - change_uid ? file->uid : st->st_uid,
5808 - change_gid ? file->gid : st->st_gid) != 0) {
5809 + change_uid ? file->uid : sxp->st.st_uid,
5810 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5811 /* shouldn't have attempted to change uid or gid
5812 * unless have the privilege */
5813 rsyserr(FERROR, errno, "%s %s failed",
5814 change_uid ? "chown" : "chgrp",
5819 /* a lchown had been done - we have to re-stat if the
5820 * destination had the setuid or setgid bits set due
5821 * to the side effect of the chown call */
5822 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5823 - link_stat(fname, st,
5824 - keep_dirlinks && S_ISDIR(st->st_mode));
5825 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5826 + link_stat(fname, &sxp->st,
5827 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5832 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5833 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5835 +#ifdef SUPPORT_ACLS
5836 + /* It's OK to call set_acl() now, even for a dir, as the generator
5837 + * will enable owner-writability using chmod, if necessary.
5839 + * If set_acl() changes permission bits in the process of setting
5840 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5841 + * need to chmod(). */
5842 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5847 - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5848 + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5849 int ret = do_chmod(fname, new_mode);
5851 rsyserr(FERROR, errno,
5852 "failed to set permissions on %s",
5857 if (ret == 0) /* ret == 1 if symlink could not be set */
5859 @@ -227,6 +250,11 @@ int set_file_attrs(char *fname, struct f
5861 rprintf(FCLIENT, "%s is uptodate\n", fname);
5864 +#ifdef SUPPORT_ACLS
5865 + if (preserve_acls && sxp == &sx2)
5873 @@ -492,6 +492,15 @@ struct idev {
5874 #define IN_LOOPBACKNET 127
5877 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5878 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5879 +#define SUPPORT_ACLS 1
5882 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5883 +#define ACLS_NEED_MASK 1
5886 #define GID_NONE ((gid_t)-1)
5888 #define HL_CHECK_MASTER 0
5889 @@ -652,6 +661,17 @@ struct stats {
5891 struct chmod_mode_struct;
5893 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5901 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5902 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5904 #include "byteorder.h"
5905 #include "lib/mdfour.h"
5906 #include "lib/wildmatch.h"
5907 @@ -667,6 +687,16 @@ struct chmod_mode_struct;
5909 #define UNUSED(x) x __attribute__((__unused__))
5913 +#ifdef SUPPORT_ACLS
5914 + struct rsync_acl *acc_acl; /* access ACL */
5915 + struct rsync_acl *def_acl; /* default ACL */
5919 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5923 /* We have replacement versions of these if they're missing. */
5926 @@ -300,7 +300,7 @@ to the detailed description below for a
5927 -v, --verbose increase verbosity
5928 -q, --quiet suppress non-error messages
5929 -c, --checksum skip based on checksum, not mod-time & size
5930 - -a, --archive archive mode; same as -rlptgoD (no -H)
5931 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
5932 --no-OPTION turn off an implied OPTION (e.g. --no-D)
5933 -r, --recursive recurse into directories
5934 -R, --relative use relative path names
5935 @@ -322,6 +322,7 @@ to the detailed description below for a
5936 -p, --perms preserve permissions
5937 -E, --executability preserve executability
5938 --chmod=CHMOD affect file and/or directory permissions
5939 + -A, --acls preserve ACLs (implies -p) [non-standard]
5940 -o, --owner preserve owner (super-user only)
5941 -g, --group preserve group
5942 --devices preserve device files (super-user only)
5943 @@ -747,7 +748,9 @@ quote(itemize(
5944 permissions, though the bf(--executability) option might change just
5945 the execute permission for the file.
5946 it() New files get their "normal" permission bits set to the source
5947 - file's permissions masked with the receiving end's umask setting, and
5948 + file's permissions masked with the receiving directory's default
5949 + permissions (either the receiving process's umask, or the permissions
5950 + specified via the destination directory's default ACL), and
5951 their special permission bits disabled except in the case where a new
5952 directory inherits a setgid bit from its parent directory.
5954 @@ -778,9 +781,11 @@ The preservation of the destination's se
5955 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5956 versions erroneously preserved the three special permission bits for
5957 newly-created files when bf(--perms) was off, while overriding the
5958 -destination's setgid bit setting on a newly-created directory. (Keep in
5959 -mind that it is the version of the receiving rsync that affects this
5961 +destination's setgid bit setting on a newly-created directory. Default ACL
5962 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5963 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5964 +(Keep in mind that it is the version of the receiving rsync that affects
5967 dit(bf(-E, --executability)) This option causes rsync to preserve the
5968 executability (or non-executability) of regular files when bf(--perms) is
5969 @@ -798,6 +803,15 @@ quote(itemize(
5971 If bf(--perms) is enabled, this option is ignored.
5973 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5974 +ACLs to be the same as the source ACLs. This nonstandard option only
5975 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5977 +Note also that an optimization of the ACL-sending protocol used by this
5978 +version makes it incompatible with sending files to an older ACL-enabled
5979 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5980 +doubling is not needed when pulling files from an older rsync.
5982 dit(bf(--chmod)) This option tells rsync to apply one or more
5983 comma-separated "chmod" strings to the permission of the files in the
5984 transfer. The resulting value is treated as though it was the permissions
5985 @@ -1383,8 +1397,8 @@ if the receiving rsync is at least versi
5986 with older versions of rsync, but that also turns on the output of other
5989 -The "%i" escape has a cryptic output that is 9 letters long. The general
5990 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
5991 +The "%i" escape has a cryptic output that is 11 letters long. The general
5992 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
5993 type of update being done, bf(X) is replaced by the file-type, and the
5994 other letters represent attributes that may be output if they are being
5996 @@ -1433,7 +1447,11 @@ quote(itemize(
5997 sender's value (requires bf(--owner) and super-user privileges).
5998 it() A bf(g) means the group is different and is being updated to the
5999 sender's value (requires bf(--group) and the authority to set the group).
6000 - it() The bf(z) slot is reserved for future use.
6001 + it() The bf(u) slot is reserved for reporting update (access) time changes
6002 + (a feature that is not yet released).
6003 + it() The bf(a) means that the ACL information changed.
6004 + it() The bf(x) slot is reserved for reporting extended attribute changes
6005 + (a feature that is not yet released).
6008 One other output is possible: when deleting files, the "%i" will output
6013 + Unix SMB/Netbios implementation.
6015 + Portable SMB ACL interface
6016 + Copyright (C) Jeremy Allison 2000
6018 + This program is free software; you can redistribute it and/or modify
6019 + it under the terms of the GNU General Public License as published by
6020 + the Free Software Foundation; either version 2 of the License, or
6021 + (at your option) any later version.
6023 + This program is distributed in the hope that it will be useful,
6024 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6025 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6026 + GNU General Public License for more details.
6028 + You should have received a copy of the GNU General Public License
6029 + along with this program; if not, write to the Free Software
6030 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6033 +#ifndef _SMB_ACLS_H
6034 +#define _SMB_ACLS_H
6036 +#if defined HAVE_POSIX_ACLS
6038 +/* This is an identity mapping (just remove the SMB_). */
6040 +#define SMB_ACL_TAG_T acl_tag_t
6041 +#define SMB_ACL_TYPE_T acl_type_t
6042 +#define SMB_ACL_PERMSET_T acl_permset_t
6043 +#define SMB_ACL_PERM_T acl_perm_t
6044 +#define SMB_ACL_READ ACL_READ
6045 +#define SMB_ACL_WRITE ACL_WRITE
6046 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6048 +/* Types of ACLs. */
6049 +#define SMB_ACL_USER ACL_USER
6050 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6051 +#define SMB_ACL_GROUP ACL_GROUP
6052 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6053 +#define SMB_ACL_OTHER ACL_OTHER
6054 +#define SMB_ACL_MASK ACL_MASK
6056 +#define SMB_ACL_T acl_t
6058 +#define SMB_ACL_ENTRY_T acl_entry_t
6060 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6061 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6063 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6064 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6066 +#elif defined HAVE_TRU64_ACLS
6068 +/* This is for DEC/Compaq Tru64 UNIX */
6070 +#define SMB_ACL_TAG_T acl_tag_t
6071 +#define SMB_ACL_TYPE_T acl_type_t
6072 +#define SMB_ACL_PERMSET_T acl_permset_t
6073 +#define SMB_ACL_PERM_T acl_perm_t
6074 +#define SMB_ACL_READ ACL_READ
6075 +#define SMB_ACL_WRITE ACL_WRITE
6076 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6078 +/* Types of ACLs. */
6079 +#define SMB_ACL_USER ACL_USER
6080 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6081 +#define SMB_ACL_GROUP ACL_GROUP
6082 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6083 +#define SMB_ACL_OTHER ACL_OTHER
6084 +#define SMB_ACL_MASK ACL_MASK
6086 +#define SMB_ACL_T acl_t
6088 +#define SMB_ACL_ENTRY_T acl_entry_t
6090 +#define SMB_ACL_FIRST_ENTRY 0
6091 +#define SMB_ACL_NEXT_ENTRY 1
6093 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6094 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6096 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6098 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6099 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6102 +/* SVR4.2 ES/MP ACLs */
6103 +typedef int SMB_ACL_TAG_T;
6104 +typedef int SMB_ACL_TYPE_T;
6105 +typedef ushort *SMB_ACL_PERMSET_T;
6106 +typedef ushort SMB_ACL_PERM_T;
6107 +#define SMB_ACL_READ 4
6108 +#define SMB_ACL_WRITE 2
6109 +#define SMB_ACL_EXECUTE 1
6111 +/* Types of ACLs. */
6112 +#define SMB_ACL_USER USER
6113 +#define SMB_ACL_USER_OBJ USER_OBJ
6114 +#define SMB_ACL_GROUP GROUP
6115 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6116 +#define SMB_ACL_OTHER OTHER_OBJ
6117 +#define SMB_ACL_MASK CLASS_OBJ
6119 +typedef struct SMB_ACL_T {
6123 + struct acl acl[1];
6126 +typedef struct acl *SMB_ACL_ENTRY_T;
6128 +#define SMB_ACL_FIRST_ENTRY 0
6129 +#define SMB_ACL_NEXT_ENTRY 1
6131 +#define SMB_ACL_TYPE_ACCESS 0
6132 +#define SMB_ACL_TYPE_DEFAULT 1
6135 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6138 +#elif defined HAVE_HPUX_ACLS
6141 + * Based on the Solaris & UnixWare code.
6145 +#include <sys/aclv.h>
6147 +/* SVR4.2 ES/MP ACLs */
6148 +typedef int SMB_ACL_TAG_T;
6149 +typedef int SMB_ACL_TYPE_T;
6150 +typedef ushort *SMB_ACL_PERMSET_T;
6151 +typedef ushort SMB_ACL_PERM_T;
6152 +#define SMB_ACL_READ 4
6153 +#define SMB_ACL_WRITE 2
6154 +#define SMB_ACL_EXECUTE 1
6156 +/* Types of ACLs. */
6157 +#define SMB_ACL_USER USER
6158 +#define SMB_ACL_USER_OBJ USER_OBJ
6159 +#define SMB_ACL_GROUP GROUP
6160 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6161 +#define SMB_ACL_OTHER OTHER_OBJ
6162 +#define SMB_ACL_MASK CLASS_OBJ
6164 +typedef struct SMB_ACL_T {
6168 + struct acl acl[1];
6171 +typedef struct acl *SMB_ACL_ENTRY_T;
6173 +#define SMB_ACL_FIRST_ENTRY 0
6174 +#define SMB_ACL_NEXT_ENTRY 1
6176 +#define SMB_ACL_TYPE_ACCESS 0
6177 +#define SMB_ACL_TYPE_DEFAULT 1
6179 +#elif defined HAVE_IRIX_ACLS
6181 +#define SMB_ACL_TAG_T acl_tag_t
6182 +#define SMB_ACL_TYPE_T acl_type_t
6183 +#define SMB_ACL_PERMSET_T acl_permset_t
6184 +#define SMB_ACL_PERM_T acl_perm_t
6185 +#define SMB_ACL_READ ACL_READ
6186 +#define SMB_ACL_WRITE ACL_WRITE
6187 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6189 +/* Types of ACLs. */
6190 +#define SMB_ACL_USER ACL_USER
6191 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6192 +#define SMB_ACL_GROUP ACL_GROUP
6193 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6194 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6195 +#define SMB_ACL_MASK ACL_MASK
6197 +typedef struct SMB_ACL_T {
6203 +#define SMB_ACL_ENTRY_T acl_entry_t
6205 +#define SMB_ACL_FIRST_ENTRY 0
6206 +#define SMB_ACL_NEXT_ENTRY 1
6208 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6209 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6211 +#elif defined HAVE_AIX_ACLS
6213 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6215 +#include "/usr/include/acl.h"
6217 +typedef uint *SMB_ACL_PERMSET_T;
6219 +struct acl_entry_link{
6220 + struct acl_entry_link *prevp;
6221 + struct new_acl_entry *entryp;
6222 + struct acl_entry_link *nextp;
6226 +struct new_acl_entry{
6227 + unsigned short ace_len;
6228 + unsigned short ace_type;
6229 + unsigned int ace_access;
6230 + struct ace_id ace_id[1];
6233 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6234 +#define SMB_ACL_T struct acl_entry_link*
6236 +#define SMB_ACL_TAG_T unsigned short
6237 +#define SMB_ACL_TYPE_T int
6238 +#define SMB_ACL_PERM_T uint
6239 +#define SMB_ACL_READ S_IRUSR
6240 +#define SMB_ACL_WRITE S_IWUSR
6241 +#define SMB_ACL_EXECUTE S_IXUSR
6243 +/* Types of ACLs. */
6244 +#define SMB_ACL_USER ACEID_USER
6245 +#define SMB_ACL_USER_OBJ 3
6246 +#define SMB_ACL_GROUP ACEID_GROUP
6247 +#define SMB_ACL_GROUP_OBJ 4
6248 +#define SMB_ACL_OTHER 5
6249 +#define SMB_ACL_MASK 6
6252 +#define SMB_ACL_FIRST_ENTRY 1
6253 +#define SMB_ACL_NEXT_ENTRY 2
6255 +#define SMB_ACL_TYPE_ACCESS 0
6256 +#define SMB_ACL_TYPE_DEFAULT 1
6258 +#else /* No ACLs. */
6260 +/* No ACLS - fake it. */
6261 +#define SMB_ACL_TAG_T int
6262 +#define SMB_ACL_TYPE_T int
6263 +#define SMB_ACL_PERMSET_T mode_t
6264 +#define SMB_ACL_PERM_T mode_t
6265 +#define SMB_ACL_READ S_IRUSR
6266 +#define SMB_ACL_WRITE S_IWUSR
6267 +#define SMB_ACL_EXECUTE S_IXUSR
6269 +/* Types of ACLs. */
6270 +#define SMB_ACL_USER 0
6271 +#define SMB_ACL_USER_OBJ 1
6272 +#define SMB_ACL_GROUP 2
6273 +#define SMB_ACL_GROUP_OBJ 3
6274 +#define SMB_ACL_OTHER 4
6275 +#define SMB_ACL_MASK 5
6277 +typedef struct SMB_ACL_T {
6281 +typedef struct SMB_ACL_ENTRY_T {
6283 +} *SMB_ACL_ENTRY_T;
6285 +#define SMB_ACL_FIRST_ENTRY 0
6286 +#define SMB_ACL_NEXT_ENTRY 1
6288 +#define SMB_ACL_TYPE_ACCESS 0
6289 +#define SMB_ACL_TYPE_DEFAULT 1
6291 +#endif /* No ACLs. */
6292 +#endif /* _SMB_ACLS_H */
6293 --- old/testsuite/acls.test
6294 +++ new/testsuite/acls.test
6298 +# This program is distributable under the terms of the GNU GPL (see
6301 +# Test that rsync handles basic ACL preservation.
6303 +. $srcdir/testsuite/rsync.fns
6305 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6306 +case "$setfacl_nodef" in
6307 +true) test_skipped "I don't know how to use your setfacl command" ;;
6310 +makepath "$fromdir/foo"
6311 +echo something >"$fromdir/file1"
6312 +echo else >"$fromdir/file2"
6314 +files='foo file1 file2'
6316 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6317 +setfacl -m u:0:5 "$fromdir/file1"
6318 +setfacl -m u:0:5 "$fromdir/file2"
6320 +$RSYNC -avvA "$fromdir/" "$todir/"
6323 +getfacl $files >"$scratchdir/acls.txt"
6326 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6328 +# The script would have aborted on error, so getting here means we've won.
6330 --- old/testsuite/default-acls.test
6331 +++ new/testsuite/default-acls.test
6335 +# This program is distributable under the terms of the GNU GPL (see
6338 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6340 +. $srcdir/testsuite/rsync.fns
6342 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6343 +case "$setfacl_nodef" in
6344 +true) test_skipped "I don't know how to use your setfacl command" ;;
6345 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6346 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6348 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6350 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6352 + todir="$scratchdir/$1"
6354 + $setfacl_nodef "$todir"
6356 + case "$setfacl_nodef" in
6357 + *-k*) opts="-dm $2" ;;
6358 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6360 + setfacl $opts "$todir"
6362 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6363 + # even though the directory itself is outside the transfer
6364 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6365 + check_perms "$todir/to" $4 "Target $1"
6366 + check_perms "$todir/to/dir" $4 "Target $1"
6367 + check_perms "$todir/to/file" $3 "Target $1"
6368 + check_perms "$todir/to/program" $4 "Target $1"
6369 + # Make sure get_local_name doesn't mess us up when transferring only one file
6370 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6371 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6372 + # Make sure we obey default ACLs when not transferring a regular file
6373 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6374 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6377 +mkdir "$scratchdir/dir"
6378 +echo "File!" >"$scratchdir/file"
6379 +echo "#!/bin/sh" >"$scratchdir/program"
6380 +chmod 777 "$scratchdir/dir"
6381 +chmod 666 "$scratchdir/file"
6382 +chmod 777 "$scratchdir/program"
6384 +# Test some target directories
6386 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6387 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6388 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6389 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6390 +testit noda1 '' rw------- rwx------
6392 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6394 +testit noda3 '' rw-r--r-- rwxr-xr-x
6398 --- old/testsuite/devices.test
6399 +++ new/testsuite/devices.test
6400 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6401 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6403 cat <<EOT >"$chkfile"
6407 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6409 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6411 cat <<EOT >"$chkfile"
6415 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6417 @@ -58,7 +58,7 @@ sleep 1
6418 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6420 cat <<EOT >"$chkfile"
6424 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6426 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6429 cat <<EOT >"$chkfile"
6434 -hD+++++++ block2.5 => block3
6443 +hD+++++++++ block2.5 => block3
6449 if test ! -b "$fromdir/block2.5"; then
6450 sed -e '/block2\.5/d' \
6451 --- old/testsuite/itemize.test
6452 +++ new/testsuite/itemize.test
6453 @@ -29,14 +29,14 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6454 $RSYNC -iplr "$fromdir/" "$todir/" \
6456 cat <<EOT >"$chkfile"
6459 ->f+++++++ bar/baz/rsync
6461 ->f+++++++ foo/config1
6462 ->f+++++++ foo/config2
6463 ->f+++++++ foo/extra
6464 -cL+++++++ foo/sym -> ../bar/baz/rsync
6466 +cd+++++++++ bar/baz/
6467 +>f+++++++++ bar/baz/rsync
6469 +>f+++++++++ foo/config1
6470 +>f+++++++++ foo/config2
6471 +>f+++++++++ foo/extra
6472 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6474 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6476 @@ -48,10 +48,10 @@ chmod 601 "$fromdir/foo/config2"
6477 $RSYNC -iplrH "$fromdir/" "$todir/" \
6479 cat <<EOT >"$chkfile"
6480 ->f..T.... bar/baz/rsync
6481 ->f..T.... foo/config1
6482 ->f.sTp... foo/config2
6483 -hf..T.... foo/extra => foo/config1
6484 +>f..T...... bar/baz/rsync
6485 +>f..T...... foo/config1
6486 +>f.sTp..... foo/config2
6487 +hf..T...... foo/extra => foo/config1
6489 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6491 @@ -68,11 +68,11 @@ chmod 777 "$todir/bar/baz/rsync"
6492 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6494 cat <<EOT >"$chkfile"
6495 -.f..tp... bar/baz/rsync
6497 -.f..t.... foo/config1
6498 ->fcstp... foo/config2
6499 -cL..T.... foo/sym -> ../bar/baz/rsync
6500 +.f..tp..... bar/baz/rsync
6502 +.f..t...... foo/config1
6503 +>fcstp..... foo/config2
6504 +cL..T...... foo/sym -> ../bar/baz/rsync
6506 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6508 @@ -97,15 +97,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6511 cat <<EOT >"$chkfile"
6515 -.f...p... bar/baz/rsync
6518 ->f..t.... foo/config2
6520 -.L foo/sym -> ../bar/baz/rsync
6524 +.f...p..... bar/baz/rsync
6527 +>f..t...... foo/config2
6529 +.L foo/sym -> ../bar/baz/rsync
6531 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6533 @@ -124,8 +124,8 @@ touch "$todir/foo/config2"
6534 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6536 cat <<EOT >"$chkfile"
6537 -.f...p... foo/config1
6538 ->f..t.... foo/config2
6539 +.f...p..... foo/config1
6540 +>f..t...... foo/config2
6542 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6544 @@ -134,15 +134,15 @@ $RSYNC -ivvplrtH --copy-dest="$lddir" "$
6547 cat <<EOT >"$chkfile"
6555 -hf foo/extra => foo/config1
6556 -cL..T.... foo/sym -> ../bar/baz/rsync
6559 +cd+++++++++ bar/baz/
6564 +hf foo/extra => foo/config1
6565 +cL..T...... foo/sym -> ../bar/baz/rsync
6567 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6569 @@ -150,11 +150,11 @@ rm -rf "$todir"
6570 $RSYNC -iplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
6572 cat <<EOT >"$chkfile"
6577 -hf foo/extra => foo/config1
6580 +cd+++++++++ bar/baz/
6582 +hf foo/extra => foo/config1
6584 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6586 @@ -181,15 +181,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6589 cat <<EOT >"$chkfile"
6597 -hf foo/extra => foo/config1
6598 -hL foo/sym -> ../bar/baz/rsync
6601 +cd+++++++++ bar/baz/
6606 +hf foo/extra => foo/config1
6607 +hL foo/sym -> ../bar/baz/rsync
6609 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6611 @@ -197,10 +197,10 @@ rm -rf "$todir"
6612 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
6614 cat <<EOT >"$chkfile"
6621 +cd+++++++++ bar/baz/
6624 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6626 @@ -228,14 +228,14 @@ filter_outfile
6627 # TODO fix really-old problem when combining -H with --compare-dest:
6628 # missing output for foo/extra hard-link (and it might not be updated)!
6629 cat <<EOT >"$chkfile"
6637 -.L foo/sym -> ../bar/baz/rsync
6640 +cd+++++++++ bar/baz/
6645 +.L foo/sym -> ../bar/baz/rsync
6647 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
6649 @@ -243,10 +243,10 @@ rm -rf "$todir"
6650 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6652 cat <<EOT >"$chkfile"
6659 +cd+++++++++ bar/baz/
6662 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6668 extern int preserve_uid;
6669 extern int preserve_gid;
6670 +extern int preserve_acls;
6671 extern int numeric_ids;
6674 @@ -275,7 +276,7 @@ void send_uid_list(int f)
6678 - if (preserve_uid) {
6679 + if (preserve_uid || preserve_acls) {
6681 /* we send sequences of uid/byte-length/name */
6682 for (list = uidlist; list; list = list->next) {
6683 @@ -292,7 +293,7 @@ void send_uid_list(int f)
6687 - if (preserve_gid) {
6688 + if (preserve_gid || preserve_acls) {
6690 for (list = gidlist; list; list = list->next) {
6692 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
6696 - if (preserve_uid && !numeric_ids) {
6697 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6698 /* read the uid list */
6699 while ((id = read_int(f)) != 0) {
6700 int len = read_byte(f);
6701 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
6705 - if (preserve_gid && !numeric_ids) {
6706 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6707 /* read the gid list */
6708 while ((id = read_int(f)) != 0) {
6709 int len = read_byte(f);
6710 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
6714 +#ifdef SUPPORT_ACLS
6715 + if (preserve_acls && !numeric_ids) {
6717 + while ((id = next_acl_uid(flist)) != NULL)
6718 + *id = match_uid(*id);
6719 + while ((id = next_acl_gid(flist)) != NULL)
6720 + *id = match_gid(*id);
6724 /* Now convert all the uids/gids from sender values to our values. */
6725 if (am_root && preserve_uid && !numeric_ids) {
6726 for (i = 0; i < flist->count; i++)
6729 @@ -1550,3 +1550,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6734 +void *expand_item_list(item_list *lp, size_t item_size,
6735 + const char *desc, int incr)
6737 + /* First time through, 0 <= 0, so list is expanded. */
6738 + if (lp->malloced <= lp->count) {
6740 + size_t new_size = lp->malloced;
6742 + new_size -= incr; /* increase slowly */
6743 + else if (new_size < (size_t)incr)
6747 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6748 + if (verbose >= 4) {
6749 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6750 + who_am_i(), desc, (double)new_size * item_size,
6751 + new_ptr == lp->items ? " not" : "");
6754 + out_of_memory("expand_item_list");
6756 + lp->items = new_ptr;
6757 + lp->malloced = new_size;
6759 + return (char*)lp->items + (lp->count++ * item_size);