1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 @@ -25,15 +25,15 @@ VERSION=@VERSION@
16 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
17 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
18 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
19 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
20 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
21 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
22 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
23 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
24 main.o checksum.o match.o syscall.o log.o backup.o
25 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
26 - fileio.o batch.o clientname.o chmod.o
27 + fileio.o batch.o clientname.o chmod.o acls.o
28 OBJS3=progress.o pipe.o
29 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
30 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 + * Handle passing Access Control Lists between systems.
37 + * Copyright (C) 1996 Andrew Tridgell
38 + * Copyright (C) 1996 Paul Mackerras
39 + * Copyright (C) 2006 Wayne Davison
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License as published by
43 + * the Free Software Foundation; either version 2 of the License, or
44 + * (at your option) any later version.
46 + * This program is distributed in the hope that it will be useful,
47 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 + * GNU General Public License for more details.
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
57 +#include "lib/sysacls.h"
63 +extern int orig_umask;
64 +extern int preserve_acls;
65 +extern unsigned int file_struct_len;
67 +/* === ACL structures === */
79 +#define NO_ENTRY ((uchar)0x80)
80 +typedef struct rsync_acl {
83 + /* These will be NO_ENTRY if there's no such entry. */
95 +static const rsync_acl empty_rsync_acl = {
96 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
99 +static item_list access_acl_list = EMPTY_ITEM_LIST;
100 +static item_list default_acl_list = EMPTY_ITEM_LIST;
102 +/* === Calculations on ACL types === */
104 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
106 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
107 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
108 + : "unknown SMB_ACL_TYPE_T";
111 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
112 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
114 +static int count_racl_entries(const rsync_acl *racl)
116 + return racl->users.count + racl->groups.count
117 + + (racl->user_obj != NO_ENTRY)
118 + + (racl->group_obj != NO_ENTRY)
119 + + (racl->mask != NO_ENTRY)
120 + + (racl->other != NO_ENTRY);
123 +static int calc_sacl_entries(const rsync_acl *racl)
125 + /* A System ACL always gets user/group/other permission entries. */
126 + return racl->users.count + racl->groups.count
127 +#ifdef ACLS_NEED_MASK
130 + + (racl->mask != NO_ENTRY) + 3;
134 +/* Extracts and returns the permission bits from the ACL. This cannot be
135 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
136 +static int rsync_acl_get_perms(const rsync_acl *racl)
138 + return (racl->user_obj << 6)
139 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
143 +/* Removes the permission-bit entries from the ACL because these
144 + * can be reconstructed from the file's mode. */
145 +static void rsync_acl_strip_perms(rsync_acl *racl)
147 + racl->user_obj = NO_ENTRY;
148 + if (racl->mask == NO_ENTRY)
149 + racl->group_obj = NO_ENTRY;
151 + if (racl->group_obj == racl->mask)
152 + racl->group_obj = NO_ENTRY;
153 + racl->mask = NO_ENTRY;
155 + racl->other = NO_ENTRY;
158 +/* Given an empty rsync_acl, fake up the permission bits. */
159 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
161 + racl->user_obj = (mode >> 6) & 7;
162 + racl->group_obj = (mode >> 3) & 7;
163 + 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 @@ -482,6 +482,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 @@ -746,6 +751,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 @@ -693,6 +713,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 @@ -942,6 +967,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 @@ -951,6 +979,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 @@ -958,6 +995,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 save_ignore_times = ignore_times;
1512 @@ -618,7 +629,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 @@ -626,16 +637,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 @@ -652,14 +667,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 @@ -668,8 +683,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 @@ -685,8 +705,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 @@ -710,13 +735,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 @@ -729,10 +759,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 @@ -763,7 +793,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 @@ -775,6 +813,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 @@ -796,7 +835,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 @@ -852,6 +892,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 @@ -859,7 +902,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 @@ -871,6 +914,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 @@ -879,7 +926,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 @@ -897,8 +944,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 @@ -907,8 +955,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 @@ -917,7 +965,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 @@ -937,19 +989,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 @@ -967,7 +1019,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 @@ -975,10 +1027,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 @@ -991,9 +1043,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 @@ -1009,7 +1061,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 @@ -1018,7 +1070,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 @@ -1052,18 +1104,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 @@ -1076,7 +1132,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 @@ -1088,12 +1144,12 @@ 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);
1871 if (!S_ISREG(file->mode)) {
1872 @@ -1127,7 +1183,7 @@ static void recv_generator(char *fname,
1875 if (update_only && statret == 0
1876 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1877 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1879 rprintf(FINFO, "%s is newer\n", fname);
1881 @@ -1136,18 +1192,18 @@ static void recv_generator(char *fname,
1883 fnamecmp_type = FNAMECMP_FNAME;
1885 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1886 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1887 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1888 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1891 stat_errno = ENOENT;
1894 if (statret != 0 && basis_dir[0] != NULL) {
1895 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1896 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1897 itemizing, maybe_ATTRS_REPORT, code);
1902 fnamecmp = fnamecmpbuf;
1904 @@ -1156,7 +1212,7 @@ static void recv_generator(char *fname,
1911 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1912 && link_stat(partialptr, &partial_st, 0) == 0
1913 @@ -1175,7 +1231,7 @@ static void recv_generator(char *fname,
1914 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1915 fname, fnamecmpbuf);
1917 - st.st_size = fuzzy_file->length;
1918 + sx.st.st_size = fuzzy_file->length;
1920 fnamecmp = fnamecmpbuf;
1921 fnamecmp_type = FNAMECMP_FUZZY;
1922 @@ -1184,7 +1240,7 @@ static void recv_generator(char *fname,
1925 if (preserve_hard_links && file->link_u.links
1926 - && hard_link_check(file, ndx, fname, statret, &st,
1927 + && hard_link_check(file, ndx, fname, statret, &sx,
1928 itemizing, code, HL_SKIP))
1930 if (stat_errno == ENOENT)
1931 @@ -1194,31 +1250,44 @@ static void recv_generator(char *fname,
1935 - if (append_mode && st.st_size > file->length)
1936 + if (append_mode && sx.st.st_size > file->length)
1939 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1941 else if (fnamecmp_type == FNAMECMP_FUZZY)
1943 - else if (unchanged_file(fnamecmp, file, &st)) {
1944 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1946 do_unlink(partialptr);
1947 handle_partial_dir(partialptr, PDIR_DELETE);
1950 - itemize(file, ndx, real_ret, &real_st,
1951 +#ifdef SUPPORT_ACLS
1952 + if (preserve_acls && real_ret == 0)
1953 + get_acl(fname, &real_sx);
1955 + itemize(file, ndx, real_ret, &real_sx,
1957 +#ifdef SUPPORT_ACLS
1958 + if (preserve_acls) {
1959 + if (fnamecmp_type == FNAMECMP_FNAME) {
1960 + sx.acc_acl = real_sx.acc_acl;
1961 + sx.def_acl = real_sx.def_acl;
1963 + free_acl(&real_sx);
1967 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1968 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1969 if (preserve_hard_links && file->link_u.links)
1970 hard_link_cluster(file, ndx, itemizing, code);
1978 + sx.st = partial_st;
1979 fnamecmp = partialptr;
1980 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
1982 @@ -1242,17 +1311,21 @@ static void recv_generator(char *fname,
1984 /* pretend the file didn't exist */
1985 if (preserve_hard_links && file->link_u.links
1986 - && hard_link_check(file, ndx, fname, statret, &st,
1987 + && hard_link_check(file, ndx, fname, statret, &sx,
1988 itemizing, code, HL_SKIP))
1991 statret = real_ret = -1;
1992 +#ifdef SUPPORT_ACLS
1993 + if (preserve_acls && ACL_READY(sx))
1999 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2000 if (!(backupptr = get_backup_name(fname))) {
2005 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2007 @@ -1263,7 +1336,7 @@ static void recv_generator(char *fname,
2008 full_fname(backupptr));
2014 if ((f_copy = do_open(backupptr,
2015 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2016 @@ -1271,14 +1344,14 @@ static void recv_generator(char *fname,
2017 full_fname(backupptr));
2023 fnamecmp_type = FNAMECMP_BACKUP;
2027 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2028 - fnamecmp, (double)st.st_size);
2029 + fnamecmp, (double)sx.st.st_size);
2033 @@ -1296,24 +1369,32 @@ static void recv_generator(char *fname,
2034 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2035 if (fnamecmp_type == FNAMECMP_FUZZY)
2036 iflags |= ITEM_XNAME_FOLLOWS;
2037 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2038 +#ifdef SUPPORT_ACLS
2039 + if (preserve_acls && real_ret == 0)
2040 + get_acl(fname, &real_sx);
2042 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2043 fuzzy_file ? fuzzy_file->basename : NULL);
2044 +#ifdef SUPPORT_ACLS
2045 + if (preserve_acls)
2046 + free_acl(&real_sx);
2051 if (preserve_hard_links && file->link_u.links)
2052 hard_link_cluster(file, ndx, itemizing, code);
2060 if (statret != 0 || whole_file) {
2061 write_sum_head(f_out, NULL);
2066 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2067 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2071 @@ -1326,6 +1407,13 @@ static void recv_generator(char *fname,
2077 +#ifdef SUPPORT_ACLS
2078 + if (preserve_acls)
2084 void generate_files(int f_out, struct file_list *flist, char *local_name)
2085 @@ -1385,6 +1473,8 @@ void generate_files(int f_out, struct fi
2086 * notice that and let us know via the redo pipe (or its closing). */
2089 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2091 for (i = 0; i < flist->count; i++) {
2092 struct file_struct *file = flist->files[i];
2099 extern int link_dest;
2100 +extern int preserve_acls;
2101 extern int make_backups;
2102 extern int stdout_format_has_i;
2103 extern char *basis_dir[];
2104 @@ -143,15 +144,19 @@ void init_hard_links(void)
2106 #ifdef SUPPORT_HARD_LINKS
2107 static int maybe_hard_link(struct file_struct *file, int ndx,
2108 - char *fname, int statret, STRUCT_STAT *st,
2109 + char *fname, int statret, statx *sxp,
2110 char *toname, STRUCT_STAT *to_st,
2111 int itemizing, enum logcode code)
2114 - if (st->st_dev == to_st->st_dev
2115 - && st->st_ino == to_st->st_ino) {
2116 + if (sxp->st.st_dev == to_st->st_dev
2117 + && sxp->st.st_ino == to_st->st_ino) {
2119 - itemize(file, ndx, statret, st,
2120 +#ifdef SUPPORT_ACLS
2121 + if (preserve_acls && !ACL_READY(*sxp))
2122 + get_acl(fname, sxp);
2124 + itemize(file, ndx, statret, sxp,
2125 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2128 @@ -166,13 +171,13 @@ static int maybe_hard_link(struct file_s
2132 - return hard_link_one(file, ndx, fname, statret, st, toname,
2133 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2134 0, itemizing, code);
2138 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2139 - int statret, STRUCT_STAT *st, int itemizing,
2140 + int statret, statx *sxp, int itemizing,
2141 enum logcode code, int skip)
2143 #ifdef SUPPORT_HARD_LINKS
2144 @@ -207,7 +212,7 @@ int hard_link_check(struct file_struct *
2145 || st2.st_ino != st3.st_ino)
2150 if (verbose < 2 || !stdout_format_has_i)
2151 itemizing = code = 0;
2153 @@ -215,12 +220,16 @@ int hard_link_check(struct file_struct *
2154 if (!unchanged_file(cmpbuf, file, &st3))
2158 - if (unchanged_attrs(file, &st3))
2160 +#ifdef SUPPORT_ACLS
2161 + if (preserve_acls)
2162 + get_acl(cmpbuf, sxp);
2164 + if (unchanged_attrs(file, sxp))
2166 } while (basis_dir[++j] != NULL);
2168 - maybe_hard_link(file, ndx, fname, statret, st,
2169 + maybe_hard_link(file, ndx, fname, statret, sxp,
2170 toname, &st2, itemizing, code);
2171 file->F_HLINDEX = FINISHED_LINK;
2173 @@ -233,7 +242,7 @@ int hard_link_check(struct file_struct *
2175 #ifdef SUPPORT_HARD_LINKS
2176 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2177 - int statret, STRUCT_STAT *st, char *toname, int terse,
2178 + int statret, statx *sxp, char *toname, int terse,
2179 int itemizing, enum logcode code)
2181 if (do_link(toname, fname)) {
2182 @@ -249,7 +258,11 @@ int hard_link_one(struct file_struct *fi
2186 - itemize(file, ndx, statret, st,
2187 +#ifdef SUPPORT_ACLS
2188 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2189 + get_acl(fname, sxp);
2191 + itemize(file, ndx, statret, sxp,
2192 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2193 terse ? "" : toname);
2195 @@ -266,11 +279,12 @@ void hard_link_cluster(struct file_struc
2196 #ifdef SUPPORT_HARD_LINKS
2197 char hlink1[MAXPATHLEN];
2199 - STRUCT_STAT st1, st2;
2202 int statret, ndx = master;
2204 file->F_HLINDEX = FINISHED_LINK;
2205 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2206 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2208 if (!(file->flags & FLAG_HLINK_TOL)) {
2209 while (!(file->flags & FLAG_HLINK_EOL)) {
2210 @@ -284,9 +298,13 @@ void hard_link_cluster(struct file_struc
2211 if (file->F_HLINDEX != SKIPPED_LINK)
2213 hlink2 = f_name(file, NULL);
2214 - statret = link_stat(hlink2, &st2, 0);
2215 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2216 - hlink1, &st1, itemizing, code);
2217 + statret = link_stat(hlink2, &sx.st, 0);
2218 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2219 + hlink1, &st, itemizing, code);
2220 +#ifdef SUPPORT_ACLS
2221 + if (preserve_acls)
2224 file->F_HLINDEX = FINISHED_LINK;
2225 } while (!(file->flags & FLAG_HLINK_EOL));
2227 --- old/lib/sysacls.c
2228 +++ new/lib/sysacls.c
2231 + Unix SMB/CIFS implementation.
2232 + Samba system utilities for ACL support.
2233 + Copyright (C) Jeremy Allison 2000.
2235 + This program is free software; you can redistribute it and/or modify
2236 + it under the terms of the GNU General Public License as published by
2237 + the Free Software Foundation; either version 2 of the License, or
2238 + (at your option) any later version.
2240 + This program is distributed in the hope that it will be useful,
2241 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2242 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2243 + GNU General Public License for more details.
2245 + You should have received a copy of the GNU General Public License
2246 + along with this program; if not, write to the Free Software
2247 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2251 +#include "sysacls.h" /****** ADDED ******/
2253 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2254 +void SAFE_FREE(void *mem)
2260 +char *uidtoname(uid_t uid)
2262 + static char idbuf[12];
2263 + struct passwd *pw;
2265 + if ((pw = getpwuid(uid)) == NULL) {
2266 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2269 + return pw->pw_name;
2271 +/****** EXTRAS -- END ******/
2274 + This file wraps all differing system ACL interfaces into a consistent
2275 + one based on the POSIX interface. It also returns the correct errors
2276 + for older UNIX systems that don't support ACLs.
2278 + The interfaces that each ACL implementation must support are as follows :
2280 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2281 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2282 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2283 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2284 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2285 + SMB_ACL_T sys_acl_get_fd(int fd)
2286 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2287 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2288 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2289 + SMB_ACL_T sys_acl_init( int count)
2290 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2291 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2292 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2293 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2294 + int sys_acl_valid( SMB_ACL_T theacl )
2295 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2296 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2297 + int sys_acl_delete_def_file(const char *path)
2299 + This next one is not POSIX complient - but we *have* to have it !
2300 + More POSIX braindamage.
2302 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2304 + The generic POSIX free is the following call. We split this into
2305 + several different free functions as we may need to add tag info
2306 + to structures when emulating the POSIX interface.
2308 + int sys_acl_free( void *obj_p)
2310 + The calls we actually use are :
2312 + int sys_acl_free_text(char *text) - free acl_to_text
2313 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2314 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2318 +#if defined(HAVE_POSIX_ACLS)
2320 +/* Identity mapping - easy. */
2322 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2324 + return acl_get_entry( the_acl, entry_id, entry_p);
2327 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2329 + return acl_get_tag_type( entry_d, tag_type_p);
2332 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2334 + return acl_get_permset( entry_d, permset_p);
2337 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2339 + return acl_get_qualifier( entry_d);
2342 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2344 + return acl_get_file( path_p, type);
2347 +SMB_ACL_T sys_acl_get_fd(int fd)
2349 + return acl_get_fd(fd);
2352 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2354 + return acl_clear_perms(permset);
2357 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2359 + return acl_add_perm(permset, perm);
2362 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2364 +#if defined(HAVE_ACL_GET_PERM_NP)
2366 + * Required for TrustedBSD-based ACL implementations where
2367 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2370 + return acl_get_perm_np(permset, perm);
2372 + return acl_get_perm(permset, perm);
2376 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2378 + return acl_to_text( the_acl, plen);
2381 +SMB_ACL_T sys_acl_init( int count)
2383 + return acl_init(count);
2386 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2388 + return acl_create_entry(pacl, pentry);
2391 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2393 + return acl_set_tag_type(entry, tagtype);
2396 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2398 + return acl_set_qualifier(entry, qual);
2401 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2403 + return acl_set_permset(entry, permset);
2406 +int sys_acl_valid( SMB_ACL_T theacl )
2408 + return acl_valid(theacl);
2411 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2413 + return acl_set_file(name, acltype, theacl);
2416 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2418 + return acl_set_fd(fd, theacl);
2421 +int sys_acl_delete_def_file(const char *name)
2423 + return acl_delete_def_file(name);
2426 +int sys_acl_free_text(char *text)
2428 + return acl_free(text);
2431 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2433 + return acl_free(the_acl);
2436 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2438 + return acl_free(qual);
2441 +#elif defined(HAVE_TRU64_ACLS)
2443 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2444 + * is based on Draft 13 of the POSIX spec which is
2445 + * slightly different from the Draft 16 interface.
2447 + * Also, some of the permset manipulation functions
2448 + * such as acl_clear_perm() and acl_add_perm() appear
2449 + * to be broken on Tru64 so we have to manipulate
2450 + * the permission bits in the permset directly.
2452 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2454 + SMB_ACL_ENTRY_T entry;
2456 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2461 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2466 + return errno ? -1 : 0;
2469 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2471 + return acl_get_tag_type( entry_d, tag_type_p);
2474 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2476 + return acl_get_permset( entry_d, permset_p);
2479 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2481 + return acl_get_qualifier( entry_d);
2484 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2486 + return acl_get_file((char *)path_p, type);
2489 +SMB_ACL_T sys_acl_get_fd(int fd)
2491 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2494 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2496 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2501 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2503 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2508 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2513 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2515 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2518 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2520 + return acl_to_text( the_acl, plen);
2523 +SMB_ACL_T sys_acl_init( int count)
2525 + return acl_init(count);
2528 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2530 + SMB_ACL_ENTRY_T entry;
2532 + if ((entry = acl_create_entry(pacl)) == NULL) {
2540 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2542 + return acl_set_tag_type(entry, tagtype);
2545 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2547 + return acl_set_qualifier(entry, qual);
2550 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2552 + return acl_set_permset(entry, permset);
2555 +int sys_acl_valid( SMB_ACL_T theacl )
2557 + acl_entry_t entry;
2559 + return acl_valid(theacl, &entry);
2562 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2564 + return acl_set_file((char *)name, acltype, theacl);
2567 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2569 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2572 +int sys_acl_delete_def_file(const char *name)
2574 + return acl_delete_def_file((char *)name);
2577 +int sys_acl_free_text(char *text)
2580 + * (void) cast and explicit return 0 are for DEC UNIX
2581 + * which just #defines acl_free_text() to be free()
2583 + (void) acl_free_text(text);
2587 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2589 + return acl_free(the_acl);
2592 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2594 + return acl_free_qualifier(qual, tagtype);
2597 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2600 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2601 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2605 + * Note that while this code implements sufficient functionality
2606 + * to support the sys_acl_* interfaces it does not provide all
2607 + * of the semantics of the POSIX ACL interfaces.
2609 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2610 + * from a call to sys_acl_get_entry() should not be assumed to be
2611 + * valid after calling any of the following functions, which may
2612 + * reorder the entries in the ACL.
2615 + * sys_acl_set_file()
2616 + * sys_acl_set_fd()
2620 + * The only difference between Solaris and UnixWare / OpenUNIX is
2621 + * that the #defines for the ACL operations have different names
2623 +#if defined(HAVE_UNIXWARE_ACLS)
2625 +#define SETACL ACL_SET
2626 +#define GETACL ACL_GET
2627 +#define GETACLCNT ACL_CNT
2632 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2634 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2639 + if (entry_p == NULL) {
2644 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2648 + if (acl_d->next < 0) {
2653 + if (acl_d->next >= acl_d->count) {
2657 + *entry_p = &acl_d->acl[acl_d->next++];
2662 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2664 + *type_p = entry_d->a_type;
2669 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2671 + *permset_p = &entry_d->a_perm;
2676 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2678 + if (entry_d->a_type != SMB_ACL_USER
2679 + && entry_d->a_type != SMB_ACL_GROUP) {
2684 + return &entry_d->a_id;
2688 + * There is no way of knowing what size the ACL returned by
2689 + * GETACL will be unless you first call GETACLCNT which means
2690 + * making an additional system call.
2692 + * In the hope of avoiding the cost of the additional system
2693 + * call in most cases, we initially allocate enough space for
2694 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2695 + * be too small then we use GETACLCNT to find out the actual
2696 + * size, reallocate the ACL buffer, and then call GETACL again.
2699 +#define INITIAL_ACL_SIZE 16
2701 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2704 + int count; /* # of ACL entries allocated */
2705 + int naccess; /* # of access ACL entries */
2706 + int ndefault; /* # of default ACL entries */
2708 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2713 + count = INITIAL_ACL_SIZE;
2714 + if ((acl_d = sys_acl_init(count)) == NULL) {
2719 + * If there isn't enough space for the ACL entries we use
2720 + * GETACLCNT to determine the actual number of ACL entries
2721 + * reallocate and try again. This is in a loop because it
2722 + * is possible that someone else could modify the ACL and
2723 + * increase the number of entries between the call to
2724 + * GETACLCNT and the call to GETACL.
2726 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2727 + && errno == ENOSPC) {
2729 + sys_acl_free_acl(acl_d);
2731 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2735 + if ((acl_d = sys_acl_init(count)) == NULL) {
2741 + sys_acl_free_acl(acl_d);
2746 + * calculate the number of access and default ACL entries
2748 + * Note: we assume that the acl() system call returned a
2749 + * well formed ACL which is sorted so that all of the
2750 + * access ACL entries preceed any default ACL entries
2752 + for (naccess = 0; naccess < count; naccess++) {
2753 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2756 + ndefault = count - naccess;
2759 + * if the caller wants the default ACL we have to copy
2760 + * the entries down to the start of the acl[] buffer
2761 + * and mask out the ACL_DEFAULT flag from the type field
2763 + if (type == SMB_ACL_TYPE_DEFAULT) {
2766 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2767 + acl_d->acl[i] = acl_d->acl[j];
2768 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2771 + acl_d->count = ndefault;
2773 + acl_d->count = naccess;
2779 +SMB_ACL_T sys_acl_get_fd(int fd)
2782 + int count; /* # of ACL entries allocated */
2783 + int naccess; /* # of access ACL entries */
2785 + count = INITIAL_ACL_SIZE;
2786 + if ((acl_d = sys_acl_init(count)) == NULL) {
2790 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2791 + && errno == ENOSPC) {
2793 + sys_acl_free_acl(acl_d);
2795 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2799 + if ((acl_d = sys_acl_init(count)) == NULL) {
2805 + sys_acl_free_acl(acl_d);
2810 + * calculate the number of access ACL entries
2812 + for (naccess = 0; naccess < count; naccess++) {
2813 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2817 + acl_d->count = naccess;
2822 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2829 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2831 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2832 + && perm != SMB_ACL_EXECUTE) {
2837 + if (permset_d == NULL) {
2842 + *permset_d |= perm;
2847 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2849 + return *permset_d & perm;
2852 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2859 + * use an initial estimate of 20 bytes per ACL entry
2860 + * when allocating memory for the text representation
2864 + maxlen = 20 * acl_d->count;
2865 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2870 + for (i = 0; i < acl_d->count; i++) {
2871 + struct acl *ap = &acl_d->acl[i];
2880 + switch (ap->a_type) {
2882 + * for debugging purposes it's probably more
2883 + * useful to dump unknown tag types rather
2884 + * than just returning an error
2887 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2890 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2895 + case SMB_ACL_USER:
2896 + id = uidtoname(ap->a_id);
2897 + case SMB_ACL_USER_OBJ:
2901 + case SMB_ACL_GROUP:
2902 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2903 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2909 + case SMB_ACL_GROUP_OBJ:
2913 + case SMB_ACL_OTHER:
2917 + case SMB_ACL_MASK:
2923 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2924 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2925 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2928 + /* <tag> : <qualifier> : rwx \n \0 */
2929 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2932 + * If this entry would overflow the buffer
2933 + * allocate enough additional memory for this
2934 + * entry and an estimate of another 20 bytes
2935 + * for each entry still to be processed
2937 + if ((len + nbytes) > maxlen) {
2938 + char *oldtext = text;
2940 + maxlen += nbytes + 20 * (acl_d->count - i);
2942 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2943 + SAFE_FREE(oldtext);
2949 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2950 + len += nbytes - 1;
2959 +SMB_ACL_T sys_acl_init(int count)
2969 + * note that since the definition of the structure pointed
2970 + * to by the SMB_ACL_T includes the first element of the
2971 + * acl[] array, this actually allocates an ACL with room
2972 + * for (count+1) entries
2974 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2979 + a->size = count + 1;
2987 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2990 + SMB_ACL_ENTRY_T entry_d;
2992 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2997 + if (acl_d->count >= acl_d->size) {
3002 + entry_d = &acl_d->acl[acl_d->count++];
3003 + entry_d->a_type = 0;
3004 + entry_d->a_id = -1;
3005 + entry_d->a_perm = 0;
3006 + *entry_p = entry_d;
3011 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3013 + switch (tag_type) {
3014 + case SMB_ACL_USER:
3015 + case SMB_ACL_USER_OBJ:
3016 + case SMB_ACL_GROUP:
3017 + case SMB_ACL_GROUP_OBJ:
3018 + case SMB_ACL_OTHER:
3019 + case SMB_ACL_MASK:
3020 + entry_d->a_type = tag_type;
3030 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3032 + if (entry_d->a_type != SMB_ACL_GROUP
3033 + && entry_d->a_type != SMB_ACL_USER) {
3038 + entry_d->a_id = *((id_t *)qual_p);
3043 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3045 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3049 + entry_d->a_perm = *permset_d;
3055 + * sort the ACL and check it for validity
3057 + * if it's a minimal ACL with only 4 entries then we
3058 + * need to recalculate the mask permissions to make
3059 + * sure that they are the same as the GROUP_OBJ
3060 + * permissions as required by the UnixWare acl() system call.
3062 + * (note: since POSIX allows minimal ACLs which only contain
3063 + * 3 entries - ie there is no mask entry - we should, in theory,
3064 + * check for this and add a mask entry if necessary - however
3065 + * we "know" that the caller of this interface always specifies
3066 + * a mask so, in practice "this never happens" (tm) - if it *does*
3067 + * happen aclsort() will fail and return an error and someone will
3068 + * have to fix it ...)
3071 +static int acl_sort(SMB_ACL_T acl_d)
3073 + int fixmask = (acl_d->count <= 4);
3075 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3082 +int sys_acl_valid(SMB_ACL_T acl_d)
3084 + return acl_sort(acl_d);
3087 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3090 + struct acl *acl_p;
3092 + struct acl *acl_buf = NULL;
3095 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3100 + if (acl_sort(acl_d) != 0) {
3104 + acl_p = &acl_d->acl[0];
3105 + acl_count = acl_d->count;
3108 + * if it's a directory there is extra work to do
3109 + * since the acl() system call will replace both
3110 + * the access ACLs and the default ACLs (if any)
3112 + if (stat(name, &s) != 0) {
3115 + if (S_ISDIR(s.st_mode)) {
3116 + SMB_ACL_T acc_acl;
3117 + SMB_ACL_T def_acl;
3118 + SMB_ACL_T tmp_acl;
3121 + if (type == SMB_ACL_TYPE_ACCESS) {
3123 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3127 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3130 + if (tmp_acl == NULL) {
3135 + * allocate a temporary buffer for the complete ACL
3137 + acl_count = acc_acl->count + def_acl->count;
3138 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3140 + if (acl_buf == NULL) {
3141 + sys_acl_free_acl(tmp_acl);
3147 + * copy the access control and default entries into the buffer
3149 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3150 + acc_acl->count * sizeof(acl_buf[0]));
3152 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3153 + def_acl->count * sizeof(acl_buf[0]));
3156 + * set the ACL_DEFAULT flag on the default entries
3158 + for (i = acc_acl->count; i < acl_count; i++) {
3159 + acl_buf[i].a_type |= ACL_DEFAULT;
3162 + sys_acl_free_acl(tmp_acl);
3164 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3169 + ret = acl(name, SETACL, acl_count, acl_p);
3171 + SAFE_FREE(acl_buf);
3176 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3178 + if (acl_sort(acl_d) != 0) {
3182 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3185 +int sys_acl_delete_def_file(const char *path)
3191 + * fetching the access ACL and rewriting it has
3192 + * the effect of deleting the default ACL
3194 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3198 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3200 + sys_acl_free_acl(acl_d);
3205 +int sys_acl_free_text(char *text)
3211 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3217 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3222 +#elif defined(HAVE_HPUX_ACLS)
3226 + * Based on the Solaris/SCO code - with modifications.
3230 + * Note that while this code implements sufficient functionality
3231 + * to support the sys_acl_* interfaces it does not provide all
3232 + * of the semantics of the POSIX ACL interfaces.
3234 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3235 + * from a call to sys_acl_get_entry() should not be assumed to be
3236 + * valid after calling any of the following functions, which may
3237 + * reorder the entries in the ACL.
3240 + * sys_acl_set_file()
3241 + * sys_acl_set_fd()
3244 +/* This checks if the POSIX ACL system call is defined */
3245 +/* which basically corresponds to whether JFS 3.3 or */
3246 +/* higher is installed. If acl() was called when it */
3247 +/* isn't defined, it causes the process to core dump */
3248 +/* so it is important to check this and avoid acl() */
3249 +/* calls if it isn't there. */
3251 +static BOOL hpux_acl_call_presence(void)
3254 + shl_t handle = NULL;
3257 + static BOOL already_checked=0;
3259 + if(already_checked)
3263 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3265 + if(ret_val != 0) {
3266 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3267 + ret_val, errno, strerror(errno)));
3268 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3272 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3274 + already_checked = True;
3278 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3280 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3285 + if (entry_p == NULL) {
3290 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3294 + if (acl_d->next < 0) {
3299 + if (acl_d->next >= acl_d->count) {
3303 + *entry_p = &acl_d->acl[acl_d->next++];
3308 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3310 + *type_p = entry_d->a_type;
3315 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3317 + *permset_p = &entry_d->a_perm;
3322 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3324 + if (entry_d->a_type != SMB_ACL_USER
3325 + && entry_d->a_type != SMB_ACL_GROUP) {
3330 + return &entry_d->a_id;
3334 + * There is no way of knowing what size the ACL returned by
3335 + * ACL_GET will be unless you first call ACL_CNT which means
3336 + * making an additional system call.
3338 + * In the hope of avoiding the cost of the additional system
3339 + * call in most cases, we initially allocate enough space for
3340 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3341 + * be too small then we use ACL_CNT to find out the actual
3342 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3345 +#define INITIAL_ACL_SIZE 16
3347 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3350 + int count; /* # of ACL entries allocated */
3351 + int naccess; /* # of access ACL entries */
3352 + int ndefault; /* # of default ACL entries */
3354 + if(hpux_acl_call_presence() == False) {
3355 + /* Looks like we don't have the acl() system call on HPUX.
3356 + * May be the system doesn't have the latest version of JFS.
3361 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3366 + count = INITIAL_ACL_SIZE;
3367 + if ((acl_d = sys_acl_init(count)) == NULL) {
3372 + * If there isn't enough space for the ACL entries we use
3373 + * ACL_CNT to determine the actual number of ACL entries
3374 + * reallocate and try again. This is in a loop because it
3375 + * is possible that someone else could modify the ACL and
3376 + * increase the number of entries between the call to
3377 + * ACL_CNT and the call to ACL_GET.
3379 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3381 + sys_acl_free_acl(acl_d);
3383 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3387 + if ((acl_d = sys_acl_init(count)) == NULL) {
3393 + sys_acl_free_acl(acl_d);
3398 + * calculate the number of access and default ACL entries
3400 + * Note: we assume that the acl() system call returned a
3401 + * well formed ACL which is sorted so that all of the
3402 + * access ACL entries preceed any default ACL entries
3404 + for (naccess = 0; naccess < count; naccess++) {
3405 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3408 + ndefault = count - naccess;
3411 + * if the caller wants the default ACL we have to copy
3412 + * the entries down to the start of the acl[] buffer
3413 + * and mask out the ACL_DEFAULT flag from the type field
3415 + if (type == SMB_ACL_TYPE_DEFAULT) {
3418 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3419 + acl_d->acl[i] = acl_d->acl[j];
3420 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3423 + acl_d->count = ndefault;
3425 + acl_d->count = naccess;
3431 +SMB_ACL_T sys_acl_get_fd(int fd)
3434 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3437 + files_struct *fsp = file_find_fd(fd);
3439 + if (fsp == NULL) {
3445 + * We know we're in the same conn context. So we
3446 + * can use the relative path.
3449 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3452 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3459 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3461 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3462 + && perm != SMB_ACL_EXECUTE) {
3467 + if (permset_d == NULL) {
3472 + *permset_d |= perm;
3477 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3479 + return *permset_d & perm;
3482 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3489 + * use an initial estimate of 20 bytes per ACL entry
3490 + * when allocating memory for the text representation
3494 + maxlen = 20 * acl_d->count;
3495 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3500 + for (i = 0; i < acl_d->count; i++) {
3501 + struct acl *ap = &acl_d->acl[i];
3510 + switch (ap->a_type) {
3512 + * for debugging purposes it's probably more
3513 + * useful to dump unknown tag types rather
3514 + * than just returning an error
3517 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3520 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3525 + case SMB_ACL_USER:
3526 + id = uidtoname(ap->a_id);
3527 + case SMB_ACL_USER_OBJ:
3531 + case SMB_ACL_GROUP:
3532 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3533 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3539 + case SMB_ACL_GROUP_OBJ:
3543 + case SMB_ACL_OTHER:
3547 + case SMB_ACL_MASK:
3553 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3554 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3555 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3558 + /* <tag> : <qualifier> : rwx \n \0 */
3559 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3562 + * If this entry would overflow the buffer
3563 + * allocate enough additional memory for this
3564 + * entry and an estimate of another 20 bytes
3565 + * for each entry still to be processed
3567 + if ((len + nbytes) > maxlen) {
3568 + char *oldtext = text;
3570 + maxlen += nbytes + 20 * (acl_d->count - i);
3572 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3579 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3580 + len += nbytes - 1;
3589 +SMB_ACL_T sys_acl_init(int count)
3599 + * note that since the definition of the structure pointed
3600 + * to by the SMB_ACL_T includes the first element of the
3601 + * acl[] array, this actually allocates an ACL with room
3602 + * for (count+1) entries
3604 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3609 + a->size = count + 1;
3617 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3620 + SMB_ACL_ENTRY_T entry_d;
3622 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3627 + if (acl_d->count >= acl_d->size) {
3632 + entry_d = &acl_d->acl[acl_d->count++];
3633 + entry_d->a_type = 0;
3634 + entry_d->a_id = -1;
3635 + entry_d->a_perm = 0;
3636 + *entry_p = entry_d;
3641 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3643 + switch (tag_type) {
3644 + case SMB_ACL_USER:
3645 + case SMB_ACL_USER_OBJ:
3646 + case SMB_ACL_GROUP:
3647 + case SMB_ACL_GROUP_OBJ:
3648 + case SMB_ACL_OTHER:
3649 + case SMB_ACL_MASK:
3650 + entry_d->a_type = tag_type;
3660 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3662 + if (entry_d->a_type != SMB_ACL_GROUP
3663 + && entry_d->a_type != SMB_ACL_USER) {
3668 + entry_d->a_id = *((id_t *)qual_p);
3673 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3675 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3679 + entry_d->a_perm = *permset_d;
3684 +/* Structure to capture the count for each type of ACE. */
3686 +struct hpux_acl_types {
3690 + int n_def_user_obj;
3695 + int n_def_group_obj;
3699 + int n_def_other_obj;
3702 + int n_def_class_obj;
3704 + int n_illegal_obj;
3708 + * Counts the different number of objects in a given array of ACL
3712 + * acl_count - Count of ACLs in the array of ACL strucutres.
3713 + * aclp - Array of ACL structures.
3714 + * acl_type_count - Pointer to acl_types structure. Should already be
3718 + * acl_type_count - This structure is filled up with counts of various
3722 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3726 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3728 + for(i=0;i<acl_count;i++) {
3729 + switch(aclp[i].a_type) {
3731 + acl_type_count->n_user++;
3734 + acl_type_count->n_user_obj++;
3736 + case DEF_USER_OBJ:
3737 + acl_type_count->n_def_user_obj++;
3740 + acl_type_count->n_group++;
3743 + acl_type_count->n_group_obj++;
3745 + case DEF_GROUP_OBJ:
3746 + acl_type_count->n_def_group_obj++;
3749 + acl_type_count->n_other_obj++;
3751 + case DEF_OTHER_OBJ:
3752 + acl_type_count->n_def_other_obj++;
3755 + acl_type_count->n_class_obj++;
3757 + case DEF_CLASS_OBJ:
3758 + acl_type_count->n_def_class_obj++;
3761 + acl_type_count->n_def_user++;
3764 + acl_type_count->n_def_group++;
3767 + acl_type_count->n_illegal_obj++;
3773 +/* swap_acl_entries: Swaps two ACL entries.
3775 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3778 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3780 + struct acl temp_acl;
3782 + temp_acl.a_type = aclp0->a_type;
3783 + temp_acl.a_id = aclp0->a_id;
3784 + temp_acl.a_perm = aclp0->a_perm;
3786 + aclp0->a_type = aclp1->a_type;
3787 + aclp0->a_id = aclp1->a_id;
3788 + aclp0->a_perm = aclp1->a_perm;
3790 + aclp1->a_type = temp_acl.a_type;
3791 + aclp1->a_id = temp_acl.a_id;
3792 + aclp1->a_perm = temp_acl.a_perm;
3795 +/* prohibited_duplicate_type
3796 + * Identifies if given ACL type can have duplicate entries or
3799 + * Inputs: acl_type - ACL Type.
3805 + * True - If the ACL type matches any of the prohibited types.
3806 + * False - If the ACL type doesn't match any of the prohibited types.
3809 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3811 + switch(acl_type) {
3822 +/* get_needed_class_perm
3823 + * Returns the permissions of a ACL structure only if the ACL
3824 + * type matches one of the pre-determined types for computing
3825 + * CLASS_OBJ permissions.
3827 + * Inputs: aclp - Pointer to ACL structure.
3830 +static int hpux_get_needed_class_perm(struct acl *aclp)
3832 + switch(aclp->a_type) {
3836 + case DEF_USER_OBJ:
3838 + case DEF_GROUP_OBJ:
3840 + case DEF_CLASS_OBJ:
3841 + case DEF_OTHER_OBJ:
3842 + return aclp->a_perm;
3848 +/* acl_sort for HPUX.
3849 + * Sorts the array of ACL structures as per the description in
3850 + * aclsort man page. Refer to aclsort man page for more details
3854 + * acl_count - Count of ACLs in the array of ACL structures.
3855 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3857 + * aclp - Array of ACL structures.
3861 + * aclp - Sorted array of ACL structures.
3865 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3866 + * debug log in case of failure.
3869 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3871 +#if !defined(HAVE_HPUX_ACLSORT)
3873 + * The aclsort() system call is availabe on the latest HPUX General
3874 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3875 + * function. Because, we don't want to update to a new
3876 + * HPUX GR bundle just for aclsort() call.
3879 + struct hpux_acl_types acl_obj_count;
3880 + int n_class_obj_perm = 0;
3884 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3888 + if(aclp == NULL) {
3889 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3893 + /* Count different types of ACLs in the ACLs array */
3895 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3897 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3898 + * CLASS_OBJ and OTHER_OBJ
3901 + if( (acl_obj_count.n_user_obj != 1) ||
3902 + (acl_obj_count.n_group_obj != 1) ||
3903 + (acl_obj_count.n_class_obj != 1) ||
3904 + (acl_obj_count.n_other_obj != 1)
3906 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3907 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3911 + /* If any of the default objects are present, there should be only
3912 + * one of them each.
3915 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3916 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3917 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3918 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3922 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3925 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3926 + * same ACL type, sort by ACL id.
3928 + * I am using the trival kind of sorting method here because, performance isn't
3929 + * really effected by the ACLs feature. More over there aren't going to be more
3930 + * than 17 entries on HPUX.
3933 + for(i=0; i<acl_count;i++) {
3934 + for (j=i+1; j<acl_count; j++) {
3935 + if( aclp[i].a_type > aclp[j].a_type ) {
3936 + /* ACL entries out of order, swap them */
3938 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3940 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3942 + /* ACL entries of same type, sort by id */
3944 + if(aclp[i].a_id > aclp[j].a_id) {
3945 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3946 + } else if (aclp[i].a_id == aclp[j].a_id) {
3947 + /* We have a duplicate entry. */
3948 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3949 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3950 + aclp[i].a_type, aclp[i].a_id));
3959 + /* set the class obj permissions to the computed one. */
3961 + int n_class_obj_index = -1;
3963 + for(i=0;i<acl_count;i++) {
3964 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3966 + if(aclp[i].a_type == CLASS_OBJ)
3967 + n_class_obj_index = i;
3969 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3974 + return aclsort(acl_count, calclass, aclp);
3979 + * sort the ACL and check it for validity
3981 + * if it's a minimal ACL with only 4 entries then we
3982 + * need to recalculate the mask permissions to make
3983 + * sure that they are the same as the GROUP_OBJ
3984 + * permissions as required by the UnixWare acl() system call.
3986 + * (note: since POSIX allows minimal ACLs which only contain
3987 + * 3 entries - ie there is no mask entry - we should, in theory,
3988 + * check for this and add a mask entry if necessary - however
3989 + * we "know" that the caller of this interface always specifies
3990 + * a mask so, in practice "this never happens" (tm) - if it *does*
3991 + * happen aclsort() will fail and return an error and someone will
3992 + * have to fix it ...)
3995 +static int acl_sort(SMB_ACL_T acl_d)
3997 + int fixmask = (acl_d->count <= 4);
3999 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4006 +int sys_acl_valid(SMB_ACL_T acl_d)
4008 + return acl_sort(acl_d);
4011 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4014 + struct acl *acl_p;
4016 + struct acl *acl_buf = NULL;
4019 + if(hpux_acl_call_presence() == False) {
4020 + /* Looks like we don't have the acl() system call on HPUX.
4021 + * May be the system doesn't have the latest version of JFS.
4027 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4032 + if (acl_sort(acl_d) != 0) {
4036 + acl_p = &acl_d->acl[0];
4037 + acl_count = acl_d->count;
4040 + * if it's a directory there is extra work to do
4041 + * since the acl() system call will replace both
4042 + * the access ACLs and the default ACLs (if any)
4044 + if (stat(name, &s) != 0) {
4047 + if (S_ISDIR(s.st_mode)) {
4048 + SMB_ACL_T acc_acl;
4049 + SMB_ACL_T def_acl;
4050 + SMB_ACL_T tmp_acl;
4053 + if (type == SMB_ACL_TYPE_ACCESS) {
4055 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4059 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4062 + if (tmp_acl == NULL) {
4067 + * allocate a temporary buffer for the complete ACL
4069 + acl_count = acc_acl->count + def_acl->count;
4070 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4072 + if (acl_buf == NULL) {
4073 + sys_acl_free_acl(tmp_acl);
4079 + * copy the access control and default entries into the buffer
4081 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4082 + acc_acl->count * sizeof(acl_buf[0]));
4084 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4085 + def_acl->count * sizeof(acl_buf[0]));
4088 + * set the ACL_DEFAULT flag on the default entries
4090 + for (i = acc_acl->count; i < acl_count; i++) {
4091 + acl_buf[i].a_type |= ACL_DEFAULT;
4094 + sys_acl_free_acl(tmp_acl);
4096 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4101 + ret = acl(name, ACL_SET, acl_count, acl_p);
4110 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4113 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4116 + files_struct *fsp = file_find_fd(fd);
4118 + if (fsp == NULL) {
4123 + if (acl_sort(acl_d) != 0) {
4128 + * We know we're in the same conn context. So we
4129 + * can use the relative path.
4132 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4135 +int sys_acl_delete_def_file(const char *path)
4141 + * fetching the access ACL and rewriting it has
4142 + * the effect of deleting the default ACL
4144 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4148 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4150 + sys_acl_free_acl(acl_d);
4155 +int sys_acl_free_text(char *text)
4161 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4167 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4172 +#elif defined(HAVE_IRIX_ACLS)
4174 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4176 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4181 + if (entry_p == NULL) {
4186 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4190 + if (acl_d->next < 0) {
4195 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4199 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4204 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4206 + *type_p = entry_d->ae_tag;
4211 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4213 + *permset_p = entry_d;
4218 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4220 + if (entry_d->ae_tag != SMB_ACL_USER
4221 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4226 + return &entry_d->ae_id;
4229 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4233 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4237 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4242 + a->freeaclp = True;
4246 +SMB_ACL_T sys_acl_get_fd(int fd)
4250 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4254 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4259 + a->freeaclp = True;
4263 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4265 + permset_d->ae_perm = 0;
4270 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4272 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4273 + && perm != SMB_ACL_EXECUTE) {
4278 + if (permset_d == NULL) {
4283 + permset_d->ae_perm |= perm;
4288 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4290 + return permset_d->ae_perm & perm;
4293 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4295 + return acl_to_text(acl_d->aclp, len_p);
4298 +SMB_ACL_T sys_acl_init(int count)
4307 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4313 + a->freeaclp = False;
4314 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4315 + a->aclp->acl_cnt = 0;
4321 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4324 + SMB_ACL_ENTRY_T entry_d;
4326 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4331 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4336 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4337 + entry_d->ae_tag = 0;
4338 + entry_d->ae_id = 0;
4339 + entry_d->ae_perm = 0;
4340 + *entry_p = entry_d;
4345 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4347 + switch (tag_type) {
4348 + case SMB_ACL_USER:
4349 + case SMB_ACL_USER_OBJ:
4350 + case SMB_ACL_GROUP:
4351 + case SMB_ACL_GROUP_OBJ:
4352 + case SMB_ACL_OTHER:
4353 + case SMB_ACL_MASK:
4354 + entry_d->ae_tag = tag_type;
4364 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4366 + if (entry_d->ae_tag != SMB_ACL_GROUP
4367 + && entry_d->ae_tag != SMB_ACL_USER) {
4372 + entry_d->ae_id = *((id_t *)qual_p);
4377 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4379 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4383 + entry_d->ae_perm = permset_d->ae_perm;
4388 +int sys_acl_valid(SMB_ACL_T acl_d)
4390 + return acl_valid(acl_d->aclp);
4393 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4395 + return acl_set_file(name, type, acl_d->aclp);
4398 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4400 + return acl_set_fd(fd, acl_d->aclp);
4403 +int sys_acl_delete_def_file(const char *name)
4405 + return acl_delete_def_file(name);
4408 +int sys_acl_free_text(char *text)
4410 + return acl_free(text);
4413 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4415 + if (acl_d->freeaclp) {
4416 + acl_free(acl_d->aclp);
4422 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4427 +#elif defined(HAVE_AIX_ACLS)
4429 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4431 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4433 + struct acl_entry_link *link;
4434 + struct new_acl_entry *entry;
4437 + DEBUG(10,("This is the count: %d\n",theacl->count));
4439 + /* Check if count was previously set to -1. *
4440 + * If it was, that means we reached the end *
4441 + * of the acl last time. */
4442 + if(theacl->count == -1)
4446 + /* To get to the next acl, traverse linked list until index *
4447 + * of acl matches the count we are keeping. This count is *
4448 + * incremented each time we return an acl entry. */
4450 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4451 + link = link->nextp;
4453 + entry = *entry_p = link->entryp;
4455 + DEBUG(10,("*entry_p is %d\n",entry_p));
4456 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4458 + /* Increment count */
4460 + if(link->nextp == NULL)
4461 + theacl->count = -1;
4466 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4468 + /* Initialize tag type */
4471 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4473 + /* Depending on what type of entry we have, *
4474 + * return tag type. */
4475 + switch(entry_d->ace_id->id_type) {
4477 + *tag_type_p = SMB_ACL_USER;
4480 + *tag_type_p = SMB_ACL_GROUP;
4483 + case SMB_ACL_USER_OBJ:
4484 + case SMB_ACL_GROUP_OBJ:
4485 + case SMB_ACL_OTHER:
4486 + *tag_type_p = entry_d->ace_id->id_type;
4496 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4498 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4499 + *permset_p = &entry_d->ace_access;
4500 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4501 + if(!(**permset_p & S_IXUSR) &&
4502 + !(**permset_p & S_IWUSR) &&
4503 + !(**permset_p & S_IRUSR) &&
4504 + (**permset_p != 0))
4507 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4511 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4513 + return(entry_d->ace_id->id_data);
4516 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4518 + struct acl *file_acl = (struct acl *)NULL;
4519 + struct acl_entry *acl_entry;
4520 + struct new_acl_entry *new_acl_entry;
4521 + struct ace_id *idp;
4522 + struct acl_entry_link *acl_entry_link;
4523 + struct acl_entry_link *acl_entry_link_head;
4528 + /* AIX has no DEFAULT */
4529 + if ( type == SMB_ACL_TYPE_DEFAULT )
4532 + /* Get the acl using statacl */
4534 + DEBUG(10,("Entering sys_acl_get_file\n"));
4535 + DEBUG(10,("path_p is %s\n",path_p));
4537 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4539 + if(file_acl == NULL) {
4541 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4545 + memset(file_acl,0,BUFSIZ);
4547 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4549 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4550 + SAFE_FREE(file_acl);
4554 + DEBUG(10,("Got facl and returned it\n"));
4556 + /* Point to the first acl entry in the acl */
4557 + acl_entry = file_acl->acl_ext;
4559 + /* Begin setting up the head of the linked list *
4560 + * that will be used for the storing the acl *
4561 + * in a way that is useful for the posix_acls.c *
4564 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4565 + if(acl_entry_link_head == NULL)
4568 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4569 + if(acl_entry_link->entryp == NULL) {
4570 + SAFE_FREE(file_acl);
4572 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4576 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4577 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4579 + /* Check if the extended acl bit is on. *
4580 + * If it isn't, do not show the *
4581 + * contents of the acl since AIX intends *
4582 + * the extended info to remain unused */
4584 + if(file_acl->acl_mode & S_IXACL){
4585 + /* while we are not pointing to the very end */
4586 + while(acl_entry < acl_last(file_acl)) {
4587 + /* before we malloc anything, make sure this is */
4588 + /* a valid acl entry and one that we want to map */
4589 + idp = id_nxt(acl_entry->ace_id);
4590 + if((acl_entry->ace_type == ACC_SPECIFY ||
4591 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4592 + acl_entry = acl_nxt(acl_entry);
4596 + idp = acl_entry->ace_id;
4598 + /* Check if this is the first entry in the linked list. *
4599 + * The first entry needs to keep prevp pointing to NULL *
4600 + * and already has entryp allocated. */
4602 + if(acl_entry_link_head->count != 0) {
4603 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4605 + if(acl_entry_link->nextp == NULL) {
4606 + SAFE_FREE(file_acl);
4608 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4612 + acl_entry_link->nextp->prevp = acl_entry_link;
4613 + acl_entry_link = acl_entry_link->nextp;
4614 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4615 + if(acl_entry_link->entryp == NULL) {
4616 + SAFE_FREE(file_acl);
4618 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4621 + acl_entry_link->nextp = NULL;
4624 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4626 + /* Don't really need this since all types are going *
4627 + * to be specified but, it's better than leaving it 0 */
4629 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4631 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4633 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4635 + /* The access in the acl entries must be left shifted by *
4636 + * three bites, because they will ultimately be compared *
4637 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4639 + switch(acl_entry->ace_type){
4642 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4643 + acl_entry_link->entryp->ace_access <<= 6;
4644 + acl_entry_link_head->count++;
4647 + /* Since there is no way to return a DENY acl entry *
4648 + * change to PERMIT and then shift. */
4649 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4650 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4651 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4652 + acl_entry_link->entryp->ace_access <<= 6;
4653 + acl_entry_link_head->count++;
4659 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4660 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4662 + acl_entry = acl_nxt(acl_entry);
4664 + } /* end of if enabled */
4666 + /* Since owner, group, other acl entries are not *
4667 + * part of the acl entries in an acl, they must *
4668 + * be dummied up to become part of the list. */
4670 + for( i = 1; i < 4; i++) {
4671 + DEBUG(10,("i is %d\n",i));
4672 + if(acl_entry_link_head->count != 0) {
4673 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4674 + if(acl_entry_link->nextp == NULL) {
4675 + SAFE_FREE(file_acl);
4677 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4681 + acl_entry_link->nextp->prevp = acl_entry_link;
4682 + acl_entry_link = acl_entry_link->nextp;
4683 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4684 + if(acl_entry_link->entryp == NULL) {
4685 + SAFE_FREE(file_acl);
4687 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4692 + acl_entry_link->nextp = NULL;
4694 + new_acl_entry = acl_entry_link->entryp;
4695 + idp = new_acl_entry->ace_id;
4697 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4698 + new_acl_entry->ace_type = ACC_PERMIT;
4699 + idp->id_len = sizeof(struct ace_id);
4700 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4701 + memset(idp->id_data,0,sizeof(uid_t));
4705 + new_acl_entry->ace_access = file_acl->g_access << 6;
4706 + idp->id_type = SMB_ACL_GROUP_OBJ;
4710 + new_acl_entry->ace_access = file_acl->o_access << 6;
4711 + idp->id_type = SMB_ACL_OTHER;
4715 + new_acl_entry->ace_access = file_acl->u_access << 6;
4716 + idp->id_type = SMB_ACL_USER_OBJ;
4724 + acl_entry_link_head->count++;
4725 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4728 + acl_entry_link_head->count = 0;
4729 + SAFE_FREE(file_acl);
4731 + return(acl_entry_link_head);
4734 +SMB_ACL_T sys_acl_get_fd(int fd)
4736 + struct acl *file_acl = (struct acl *)NULL;
4737 + struct acl_entry *acl_entry;
4738 + struct new_acl_entry *new_acl_entry;
4739 + struct ace_id *idp;
4740 + struct acl_entry_link *acl_entry_link;
4741 + struct acl_entry_link *acl_entry_link_head;
4746 + /* Get the acl using fstatacl */
4748 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4749 + DEBUG(10,("fd is %d\n",fd));
4750 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4752 + if(file_acl == NULL) {
4754 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4758 + memset(file_acl,0,BUFSIZ);
4760 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4762 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4763 + SAFE_FREE(file_acl);
4767 + DEBUG(10,("Got facl and returned it\n"));
4769 + /* Point to the first acl entry in the acl */
4771 + acl_entry = file_acl->acl_ext;
4772 + /* Begin setting up the head of the linked list *
4773 + * that will be used for the storing the acl *
4774 + * in a way that is useful for the posix_acls.c *
4777 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4778 + if(acl_entry_link_head == NULL){
4779 + SAFE_FREE(file_acl);
4783 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4785 + if(acl_entry_link->entryp == NULL) {
4787 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4788 + SAFE_FREE(file_acl);
4792 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4793 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4795 + /* Check if the extended acl bit is on. *
4796 + * If it isn't, do not show the *
4797 + * contents of the acl since AIX intends *
4798 + * the extended info to remain unused */
4800 + if(file_acl->acl_mode & S_IXACL){
4801 + /* while we are not pointing to the very end */
4802 + while(acl_entry < acl_last(file_acl)) {
4803 + /* before we malloc anything, make sure this is */
4804 + /* a valid acl entry and one that we want to map */
4806 + idp = id_nxt(acl_entry->ace_id);
4807 + if((acl_entry->ace_type == ACC_SPECIFY ||
4808 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4809 + acl_entry = acl_nxt(acl_entry);
4813 + idp = acl_entry->ace_id;
4815 + /* Check if this is the first entry in the linked list. *
4816 + * The first entry needs to keep prevp pointing to NULL *
4817 + * and already has entryp allocated. */
4819 + if(acl_entry_link_head->count != 0) {
4820 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4821 + if(acl_entry_link->nextp == NULL) {
4823 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4824 + SAFE_FREE(file_acl);
4827 + acl_entry_link->nextp->prevp = acl_entry_link;
4828 + acl_entry_link = acl_entry_link->nextp;
4829 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4830 + if(acl_entry_link->entryp == NULL) {
4832 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4833 + SAFE_FREE(file_acl);
4837 + acl_entry_link->nextp = NULL;
4840 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4842 + /* Don't really need this since all types are going *
4843 + * to be specified but, it's better than leaving it 0 */
4845 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4846 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4848 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4850 + /* The access in the acl entries must be left shifted by *
4851 + * three bites, because they will ultimately be compared *
4852 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4854 + switch(acl_entry->ace_type){
4857 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4858 + acl_entry_link->entryp->ace_access <<= 6;
4859 + acl_entry_link_head->count++;
4862 + /* Since there is no way to return a DENY acl entry *
4863 + * change to PERMIT and then shift. */
4864 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4865 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4866 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4867 + acl_entry_link->entryp->ace_access <<= 6;
4868 + acl_entry_link_head->count++;
4874 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4875 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4877 + acl_entry = acl_nxt(acl_entry);
4879 + } /* end of if enabled */
4881 + /* Since owner, group, other acl entries are not *
4882 + * part of the acl entries in an acl, they must *
4883 + * be dummied up to become part of the list. */
4885 + for( i = 1; i < 4; i++) {
4886 + DEBUG(10,("i is %d\n",i));
4887 + if(acl_entry_link_head->count != 0){
4888 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4889 + if(acl_entry_link->nextp == NULL) {
4891 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4892 + SAFE_FREE(file_acl);
4896 + acl_entry_link->nextp->prevp = acl_entry_link;
4897 + acl_entry_link = acl_entry_link->nextp;
4898 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4900 + if(acl_entry_link->entryp == NULL) {
4901 + SAFE_FREE(file_acl);
4903 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4908 + acl_entry_link->nextp = NULL;
4910 + new_acl_entry = acl_entry_link->entryp;
4911 + idp = new_acl_entry->ace_id;
4913 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4914 + new_acl_entry->ace_type = ACC_PERMIT;
4915 + idp->id_len = sizeof(struct ace_id);
4916 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4917 + memset(idp->id_data,0,sizeof(uid_t));
4921 + new_acl_entry->ace_access = file_acl->g_access << 6;
4922 + idp->id_type = SMB_ACL_GROUP_OBJ;
4926 + new_acl_entry->ace_access = file_acl->o_access << 6;
4927 + idp->id_type = SMB_ACL_OTHER;
4931 + new_acl_entry->ace_access = file_acl->u_access << 6;
4932 + idp->id_type = SMB_ACL_USER_OBJ;
4939 + acl_entry_link_head->count++;
4940 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4943 + acl_entry_link_head->count = 0;
4944 + SAFE_FREE(file_acl);
4946 + return(acl_entry_link_head);
4949 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4951 + *permset = *permset & ~0777;
4955 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4958 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4962 + DEBUG(10,("This is the permset now: %d\n",*permset));
4966 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4971 +SMB_ACL_T sys_acl_init( int count)
4973 + struct acl_entry_link *theacl = NULL;
4975 + DEBUG(10,("Entering sys_acl_init\n"));
4977 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4978 + if(theacl == NULL) {
4980 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4984 + theacl->count = 0;
4985 + theacl->nextp = NULL;
4986 + theacl->prevp = NULL;
4987 + theacl->entryp = NULL;
4988 + DEBUG(10,("Exiting sys_acl_init\n"));
4992 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4994 + struct acl_entry_link *theacl;
4995 + struct acl_entry_link *acl_entryp;
4996 + struct acl_entry_link *temp_entry;
4999 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5001 + theacl = acl_entryp = *pacl;
5003 + /* Get to the end of the acl before adding entry */
5005 + for(counting=0; counting < theacl->count; counting++){
5006 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5007 + temp_entry = acl_entryp;
5008 + acl_entryp = acl_entryp->nextp;
5011 + if(theacl->count != 0){
5012 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5013 + if(acl_entryp == NULL) {
5015 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5019 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5020 + acl_entryp->prevp = temp_entry;
5021 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5024 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5025 + if(*pentry == NULL) {
5027 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5031 + memset(*pentry,0,sizeof(struct new_acl_entry));
5032 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5033 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5034 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5035 + acl_entryp->nextp = NULL;
5037 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5041 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5043 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5044 + entry->ace_id->id_type = tagtype;
5045 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5046 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5049 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5051 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5052 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5053 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5057 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5059 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5060 + if(!(*permset & S_IXUSR) &&
5061 + !(*permset & S_IWUSR) &&
5062 + !(*permset & S_IRUSR) &&
5066 + entry->ace_access = *permset;
5067 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5068 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5072 +int sys_acl_valid( SMB_ACL_T theacl )
5075 + int group_obj = 0;
5076 + int other_obj = 0;
5077 + struct acl_entry_link *acl_entry;
5079 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5080 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5081 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5082 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5085 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5087 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5093 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5095 + struct acl_entry_link *acl_entry_link = NULL;
5096 + struct acl *file_acl = NULL;
5097 + struct acl *file_acl_temp = NULL;
5098 + struct acl_entry *acl_entry = NULL;
5099 + struct ace_id *ace_id = NULL;
5106 + DEBUG(10,("Entering sys_acl_set_file\n"));
5107 + DEBUG(10,("File name is %s\n",name));
5109 + /* AIX has no default ACL */
5110 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5113 + acl_length = BUFSIZ;
5114 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5116 + if(file_acl == NULL) {
5118 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5122 + memset(file_acl,0,BUFSIZ);
5124 + file_acl->acl_len = ACL_SIZ;
5125 + file_acl->acl_mode = S_IXACL;
5127 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5128 + acl_entry_link->entryp->ace_access >>= 6;
5129 + id_type = acl_entry_link->entryp->ace_id->id_type;
5132 + case SMB_ACL_USER_OBJ:
5133 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5135 + case SMB_ACL_GROUP_OBJ:
5136 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5138 + case SMB_ACL_OTHER:
5139 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5141 + case SMB_ACL_MASK:
5145 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5146 + acl_length += sizeof(struct acl_entry);
5147 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5148 + if(file_acl_temp == NULL) {
5149 + SAFE_FREE(file_acl);
5151 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5155 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5156 + SAFE_FREE(file_acl);
5157 + file_acl = file_acl_temp;
5160 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5161 + file_acl->acl_len += sizeof(struct acl_entry);
5162 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5163 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5165 + /* In order to use this, we'll need to wait until we can get denies */
5166 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5167 + acl_entry->ace_type = ACC_SPECIFY; */
5169 + acl_entry->ace_type = ACC_SPECIFY;
5171 + ace_id = acl_entry->ace_id;
5173 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5174 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5175 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5176 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5177 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5180 + rc = chacl(name,file_acl,file_acl->acl_len);
5181 + DEBUG(10,("errno is %d\n",errno));
5182 + DEBUG(10,("return code is %d\n",rc));
5183 + SAFE_FREE(file_acl);
5184 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5188 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5190 + struct acl_entry_link *acl_entry_link = NULL;
5191 + struct acl *file_acl = NULL;
5192 + struct acl *file_acl_temp = NULL;
5193 + struct acl_entry *acl_entry = NULL;
5194 + struct ace_id *ace_id = NULL;
5200 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5201 + acl_length = BUFSIZ;
5202 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5204 + if(file_acl == NULL) {
5206 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5210 + memset(file_acl,0,BUFSIZ);
5212 + file_acl->acl_len = ACL_SIZ;
5213 + file_acl->acl_mode = S_IXACL;
5215 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5216 + acl_entry_link->entryp->ace_access >>= 6;
5217 + id_type = acl_entry_link->entryp->ace_id->id_type;
5218 + DEBUG(10,("The id_type is %d\n",id_type));
5221 + case SMB_ACL_USER_OBJ:
5222 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5224 + case SMB_ACL_GROUP_OBJ:
5225 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5227 + case SMB_ACL_OTHER:
5228 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5230 + case SMB_ACL_MASK:
5234 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5235 + acl_length += sizeof(struct acl_entry);
5236 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5237 + if(file_acl_temp == NULL) {
5238 + SAFE_FREE(file_acl);
5240 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5244 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5245 + SAFE_FREE(file_acl);
5246 + file_acl = file_acl_temp;
5249 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5250 + file_acl->acl_len += sizeof(struct acl_entry);
5251 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5252 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5254 + /* In order to use this, we'll need to wait until we can get denies */
5255 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5256 + acl_entry->ace_type = ACC_SPECIFY; */
5258 + acl_entry->ace_type = ACC_SPECIFY;
5260 + ace_id = acl_entry->ace_id;
5262 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5263 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5264 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5265 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5266 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5269 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5270 + DEBUG(10,("errno is %d\n",errno));
5271 + DEBUG(10,("return code is %d\n",rc));
5272 + SAFE_FREE(file_acl);
5273 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5277 +int sys_acl_delete_def_file(const char *name)
5279 + /* AIX has no default ACL */
5283 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5285 + return(*permset & perm);
5288 +int sys_acl_free_text(char *text)
5293 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5295 + struct acl_entry_link *acl_entry_link;
5297 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5298 + SAFE_FREE(acl_entry_link->prevp->entryp);
5299 + SAFE_FREE(acl_entry_link->prevp);
5302 + SAFE_FREE(acl_entry_link->prevp->entryp);
5303 + SAFE_FREE(acl_entry_link->prevp);
5304 + SAFE_FREE(acl_entry_link->entryp);
5305 + SAFE_FREE(acl_entry_link);
5310 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5315 +#else /* No ACLs. */
5317 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5323 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5329 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5335 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5341 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5344 + return (SMB_ACL_T)NULL;
5347 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5350 + return (SMB_ACL_T)NULL;
5353 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5359 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5365 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5368 + return (permset & perm) ? 1 : 0;
5371 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5377 +int sys_acl_free_text(UNUSED(char *text))
5383 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5389 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5395 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5401 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5407 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5413 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5419 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5425 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5431 +int sys_acl_delete_def_file(UNUSED(const char *name))
5437 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5443 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5449 +#endif /* No ACLs. */
5451 +/************************************************************************
5452 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5454 +************************************************************************/
5456 +int no_acl_syscall_error(int err)
5458 +#if defined(ENOSYS)
5459 + if (err == ENOSYS) {
5463 +#if defined(ENOTSUP)
5464 + if (err == ENOTSUP) {
5470 --- old/lib/sysacls.h
5471 +++ new/lib/sysacls.h
5473 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5474 +#include <sys/acl.h>
5476 +#include "smb_acls.h"
5478 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5479 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5480 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5481 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5482 +#define slprintf snprintf
5484 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5485 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5486 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5487 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5488 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5489 +SMB_ACL_T sys_acl_get_fd(int fd);
5490 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5491 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5492 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5493 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5494 +SMB_ACL_T sys_acl_init(int count);
5495 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5496 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5497 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5498 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5499 +int sys_acl_valid(SMB_ACL_T theacl);
5500 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5501 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5502 +int sys_acl_delete_def_file(const char *name);
5503 +int sys_acl_free_text(char *text);
5504 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5505 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5508 @@ -582,8 +582,10 @@ static void log_formatted(enum logcode c
5509 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5510 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5511 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5514 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5515 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5516 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5519 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5520 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5523 @@ -58,7 +58,7 @@ BEGIN {
5527 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
5528 +!/^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/ {
5534 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5536 int preserve_links = 0;
5537 int preserve_hard_links = 0;
5538 +int preserve_acls = 0;
5539 int preserve_perms = 0;
5540 int preserve_executability = 0;
5541 int preserve_devices = 0;
5542 @@ -198,6 +199,7 @@ static void print_rsync_version(enum log
5543 char const *got_socketpair = "no ";
5544 char const *have_inplace = "no ";
5545 char const *hardlinks = "no ";
5546 + char const *acls = "no ";
5547 char const *links = "no ";
5548 char const *ipv6 = "no ";
5549 STRUCT_STAT *dumstat;
5550 @@ -214,6 +216,10 @@ static void print_rsync_version(enum log
5554 +#ifdef SUPPORT_ACLS
5558 #ifdef SUPPORT_LINKS
5561 @@ -227,9 +233,9 @@ static void print_rsync_version(enum log
5562 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5563 rprintf(f, "<http://rsync.samba.org/>\n");
5564 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5565 - "%shard links, %ssymlinks, batchfiles,\n",
5566 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
5567 (int) (sizeof (OFF_T) * 8),
5568 - got_socketpair, hardlinks, links);
5569 + got_socketpair, hardlinks, acls, links);
5571 /* Note that this field may not have type ino_t. It depends
5572 * on the complicated interaction between largefile feature
5573 @@ -282,7 +288,7 @@ void usage(enum logcode F)
5574 rprintf(F," -v, --verbose increase verbosity\n");
5575 rprintf(F," -q, --quiet suppress non-error messages\n");
5576 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5577 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5578 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5579 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5580 rprintf(F," -r, --recursive recurse into directories\n");
5581 rprintf(F," -R, --relative use relative path names\n");
5582 @@ -303,6 +309,9 @@ void usage(enum logcode F)
5583 rprintf(F," -H, --hard-links preserve hard links\n");
5584 rprintf(F," -p, --perms preserve permissions\n");
5585 rprintf(F," -E, --executability preserve the file's executability\n");
5586 +#ifdef SUPPORT_ACLS
5587 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5589 rprintf(F," --chmod=CHMOD change destination permissions\n");
5590 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5591 rprintf(F," -g, --group preserve group\n");
5592 @@ -421,6 +430,9 @@ static struct poptOption long_options[]
5593 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5594 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5595 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5596 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5597 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5598 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5599 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5600 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5601 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5602 @@ -1083,6 +1095,24 @@ int parse_arguments(int *argc, const cha
5607 +#ifdef SUPPORT_ACLS
5609 + preserve_perms = 1;
5612 + /* FIXME: this should probably be ignored with a
5613 + * warning and then countermeasures taken to
5614 + * restrict group and other access in the presence
5615 + * of any more restrictive ACLs, but this is safe
5617 + snprintf(err_buf,sizeof(err_buf),
5618 + "ACLs are not supported on this %s\n",
5619 + am_server ? "server" : "client");
5625 /* A large opt value means that set_refuse_options()
5626 * turned this option off. */
5627 @@ -1528,6 +1558,10 @@ void server_options(char **args,int *arg
5629 if (preserve_hard_links)
5631 +#ifdef SUPPORT_ACLS
5632 + if (preserve_acls)
5633 + argstr[x++] = 'A';
5640 @@ -47,6 +47,7 @@ extern int keep_partial;
5641 extern int checksum_seed;
5643 extern int delay_updates;
5644 +extern mode_t orig_umask;
5645 extern struct stats stats;
5646 extern char *stdout_format;
5647 extern char *tmpdir;
5648 @@ -347,6 +348,10 @@ int recv_files(int f_in, struct file_lis
5649 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5650 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5651 int max_phase = protocol_version >= 29 ? 2 : 1;
5652 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5653 +#ifdef SUPPORT_ACLS
5654 + char *parent_dirname = "";
5659 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5660 * mode based on the local permissions and some heuristics. */
5661 if (!preserve_perms) {
5662 int exists = fd1 != -1;
5663 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5664 +#ifdef SUPPORT_ACLS
5665 + char *dn = file->dirname ? file->dirname : ".";
5666 + if (parent_dirname != dn
5667 + && strcmp(parent_dirname, dn) != 0) {
5668 + dflt_perms = default_perms_for_dir(dn);
5669 + parent_dirname = dn;
5672 + file->mode = dest_mode(file->mode, st.st_mode,
5673 + dflt_perms, exists);
5676 /* We now check to see if we are writing file "inplace" */
5683 +extern int preserve_acls;
5684 extern int preserve_perms;
5685 extern int preserve_executability;
5686 extern int preserve_times;
5687 @@ -100,7 +101,8 @@ void free_sums(struct sum_struct *s)
5689 /* This is only called when we aren't preserving permissions. Figure out what
5690 * the permissions should be and return them merged back into the mode. */
5691 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5692 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5695 /* If the file already exists, we'll return the local permissions,
5696 * possibly tweaked by the --executability option. */
5697 @@ -115,55 +117,63 @@ mode_t dest_mode(mode_t flist_mode, mode
5698 cur_mode |= (cur_mode & 0444) >> 2;
5701 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5702 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5703 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5704 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5705 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5708 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5709 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5715 int change_uid, change_gid;
5721 - if (link_stat(fname, &st2, 0) < 0) {
5722 + if (link_stat(fname, &sx2.st, 0) < 0) {
5723 rsyserr(FERROR, errno, "stat %s failed",
5728 +#ifdef SUPPORT_ACLS
5729 + sx2.acc_acl = sx2.def_acl = NULL;
5731 if (!preserve_perms && S_ISDIR(file->mode)
5732 - && st->st_mode & S_ISGID) {
5733 + && sx2.st.st_mode & S_ISGID) {
5734 /* We just created this directory and its setgid
5735 * bit is on, so make sure it stays on. */
5736 file->mode |= S_ISGID;
5741 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5742 +#ifdef SUPPORT_ACLS
5743 + if (preserve_acls && !ACL_READY(*sxp))
5744 + get_acl(fname, sxp);
5747 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5748 flags |= ATTRS_SKIP_MTIME;
5749 if (!(flags & ATTRS_SKIP_MTIME)
5750 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5751 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5752 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5753 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5755 rsyserr(FERROR, errno, "failed to set times on %s",
5760 if (ret == 0) /* ret == 1 if symlink could not be set */
5764 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5765 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5766 change_gid = preserve_gid && file->gid != GID_NONE
5767 - && st->st_gid != file->gid;
5768 + && sxp->st.st_gid != file->gid;
5769 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5770 - if (S_ISLNK(st->st_mode))
5771 + if (S_ISLNK(sxp->st.st_mode))
5775 @@ -173,43 +183,55 @@ int set_file_attrs(char *fname, struct f
5777 "set uid of %s from %ld to %ld\n",
5779 - (long)st->st_uid, (long)file->uid);
5780 + (long)sxp->st.st_uid, (long)file->uid);
5784 "set gid of %s from %ld to %ld\n",
5786 - (long)st->st_gid, (long)file->gid);
5787 + (long)sxp->st.st_gid, (long)file->gid);
5790 if (do_lchown(fname,
5791 - change_uid ? file->uid : st->st_uid,
5792 - change_gid ? file->gid : st->st_gid) != 0) {
5793 + change_uid ? file->uid : sxp->st.st_uid,
5794 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5795 /* shouldn't have attempted to change uid or gid
5796 * unless have the privilege */
5797 rsyserr(FERROR, errno, "%s %s failed",
5798 change_uid ? "chown" : "chgrp",
5803 /* a lchown had been done - we have to re-stat if the
5804 * destination had the setuid or setgid bits set due
5805 * to the side effect of the chown call */
5806 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5807 - link_stat(fname, st,
5808 - keep_dirlinks && S_ISDIR(st->st_mode));
5809 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5810 + link_stat(fname, &sxp->st,
5811 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5816 +#ifdef SUPPORT_ACLS
5817 + /* It's OK to call set_acl() now, even for a dir, as the generator
5818 + * will enable owner-writability using chmod, if necessary.
5820 + * If set_acl() changes permission bits in the process of setting
5821 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5822 + * need to chmod(). */
5823 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5828 - if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5829 - int ret = do_chmod(fname, file->mode);
5830 + if ((sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5831 + mode_t mode = file->mode;
5832 + int ret = do_chmod(fname, mode);
5834 rsyserr(FERROR, errno,
5835 "failed to set permissions on %s",
5840 if (ret == 0) /* ret == 1 if symlink could not be set */
5842 @@ -222,6 +244,11 @@ int set_file_attrs(char *fname, struct f
5844 rprintf(FCLIENT, "%s is uptodate\n", fname);
5847 +#ifdef SUPPORT_ACLS
5848 + if (preserve_acls && sxp == &sx2)
5856 @@ -486,6 +486,15 @@ struct idev {
5857 #define IN_LOOPBACKNET 127
5860 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5861 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5862 +#define SUPPORT_ACLS 1
5865 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5866 +#define ACLS_NEED_MASK 1
5869 #define GID_NONE ((gid_t)-1)
5871 #define HL_CHECK_MASTER 0
5872 @@ -646,6 +655,17 @@ struct stats {
5874 struct chmod_mode_struct;
5876 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5884 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5885 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5887 #include "byteorder.h"
5888 #include "lib/mdfour.h"
5889 #include "lib/wildmatch.h"
5890 @@ -661,6 +681,16 @@ struct chmod_mode_struct;
5892 #define UNUSED(x) x __attribute__((__unused__))
5896 +#ifdef SUPPORT_ACLS
5897 + struct rsync_acl *acc_acl; /* access ACL */
5898 + struct rsync_acl *def_acl; /* default ACL */
5902 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5906 /* We have replacement versions of these if they're missing. */
5909 @@ -300,7 +300,7 @@ to the detailed description below for a
5910 -v, --verbose increase verbosity
5911 -q, --quiet suppress non-error messages
5912 -c, --checksum skip based on checksum, not mod-time & size
5913 - -a, --archive archive mode; same as -rlptgoD (no -H)
5914 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
5915 --no-OPTION turn off an implied OPTION (e.g. --no-D)
5916 -r, --recursive recurse into directories
5917 -R, --relative use relative path names
5918 @@ -321,6 +321,7 @@ to the detailed description below for a
5919 -H, --hard-links preserve hard links
5920 -p, --perms preserve permissions
5921 -E, --executability preserve executability
5922 + -A, --acls preserve ACLs (implies -p) [non-standard]
5923 --chmod=CHMOD change destination permissions
5924 -o, --owner preserve owner (super-user only)
5925 -g, --group preserve group
5926 @@ -746,7 +747,9 @@ quote(itemize(
5927 permissions, though the bf(--executability) option might change just
5928 the execute permission for the file.
5929 it() New files get their "normal" permission bits set to the source
5930 - file's permissions masked with the receiving end's umask setting, and
5931 + file's permissions masked with the receiving directory's default
5932 + permissions (either the receiving process's umask, or the permissions
5933 + specified via the destination directory's default ACL), and
5934 their special permission bits disabled except in the case where a new
5935 directory inherits a setgid bit from its parent directory.
5937 @@ -777,9 +780,11 @@ The preservation of the destination's se
5938 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5939 versions erroneously preserved the three special permission bits for
5940 newly-created files when bf(--perms) was off, while overriding the
5941 -destination's setgid bit setting on a newly-created directory. (Keep in
5942 -mind that it is the version of the receiving rsync that affects this
5944 +destination's setgid bit setting on a newly-created directory. Default ACL
5945 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5946 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5947 +(Keep in mind that it is the version of the receiving rsync that affects
5950 dit(bf(-E, --executability)) This option causes rsync to preserve the
5951 executability (or non-executability) of regular files when bf(--perms) is
5952 @@ -797,6 +802,15 @@ quote(itemize(
5954 If bf(--perms) is enabled, this option is ignored.
5956 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5957 +ACLs to be the same as the source ACLs. This nonstandard option only
5958 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5960 +Note also that an optimization of the ACL-sending protocol used by this
5961 +version makes it incompatible with sending files to an older ACL-enabled
5962 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5963 +doubling is not needed when pulling files from an older rsync.
5965 dit(bf(--chmod)) This option tells rsync to apply one or more
5966 comma-separated "chmod" strings to the permission of the files in the
5967 transfer. The resulting value is treated as though it was the permissions
5968 @@ -1378,8 +1392,8 @@ if the receiving rsync is at least versi
5969 with older versions of rsync, but that also turns on the output of other
5972 -The "%i" escape has a cryptic output that is 9 letters long. The general
5973 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
5974 +The "%i" escape has a cryptic output that is 11 letters long. The general
5975 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
5976 type of update being done, bf(X) is replaced by the file-type, and the
5977 other letters represent attributes that may be output if they are being
5979 @@ -1428,7 +1442,11 @@ quote(itemize(
5980 sender's value (requires bf(--owner) and super-user privileges).
5981 it() A bf(g) means the group is different and is being updated to the
5982 sender's value (requires bf(--group) and the authority to set the group).
5983 - it() The bf(z) slot is reserved for future use.
5984 + it() The bf(u) slot is reserved for reporting update (access) time changes
5985 + (a feature that is not yet released).
5986 + it() The bf(a) means that the ACL information changed.
5987 + it() The bf(x) slot is reserved for reporting extended attribute changes
5988 + (a feature that is not yet released).
5991 One other output is possible: when deleting files, the "%i" will output
5996 + Unix SMB/Netbios implementation.
5998 + Portable SMB ACL interface
5999 + Copyright (C) Jeremy Allison 2000
6001 + This program is free software; you can redistribute it and/or modify
6002 + it under the terms of the GNU General Public License as published by
6003 + the Free Software Foundation; either version 2 of the License, or
6004 + (at your option) any later version.
6006 + This program is distributed in the hope that it will be useful,
6007 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6008 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6009 + GNU General Public License for more details.
6011 + You should have received a copy of the GNU General Public License
6012 + along with this program; if not, write to the Free Software
6013 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6016 +#ifndef _SMB_ACLS_H
6017 +#define _SMB_ACLS_H
6019 +#if defined HAVE_POSIX_ACLS
6021 +/* This is an identity mapping (just remove the SMB_). */
6023 +#define SMB_ACL_TAG_T acl_tag_t
6024 +#define SMB_ACL_TYPE_T acl_type_t
6025 +#define SMB_ACL_PERMSET_T acl_permset_t
6026 +#define SMB_ACL_PERM_T acl_perm_t
6027 +#define SMB_ACL_READ ACL_READ
6028 +#define SMB_ACL_WRITE ACL_WRITE
6029 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6031 +/* Types of ACLs. */
6032 +#define SMB_ACL_USER ACL_USER
6033 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6034 +#define SMB_ACL_GROUP ACL_GROUP
6035 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6036 +#define SMB_ACL_OTHER ACL_OTHER
6037 +#define SMB_ACL_MASK ACL_MASK
6039 +#define SMB_ACL_T acl_t
6041 +#define SMB_ACL_ENTRY_T acl_entry_t
6043 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6044 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6046 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6047 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6049 +#elif defined HAVE_TRU64_ACLS
6051 +/* This is for DEC/Compaq Tru64 UNIX */
6053 +#define SMB_ACL_TAG_T acl_tag_t
6054 +#define SMB_ACL_TYPE_T acl_type_t
6055 +#define SMB_ACL_PERMSET_T acl_permset_t
6056 +#define SMB_ACL_PERM_T acl_perm_t
6057 +#define SMB_ACL_READ ACL_READ
6058 +#define SMB_ACL_WRITE ACL_WRITE
6059 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6061 +/* Types of ACLs. */
6062 +#define SMB_ACL_USER ACL_USER
6063 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6064 +#define SMB_ACL_GROUP ACL_GROUP
6065 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6066 +#define SMB_ACL_OTHER ACL_OTHER
6067 +#define SMB_ACL_MASK ACL_MASK
6069 +#define SMB_ACL_T acl_t
6071 +#define SMB_ACL_ENTRY_T acl_entry_t
6073 +#define SMB_ACL_FIRST_ENTRY 0
6074 +#define SMB_ACL_NEXT_ENTRY 1
6076 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6077 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6079 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6081 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6082 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6085 +/* SVR4.2 ES/MP ACLs */
6086 +typedef int SMB_ACL_TAG_T;
6087 +typedef int SMB_ACL_TYPE_T;
6088 +typedef ushort *SMB_ACL_PERMSET_T;
6089 +typedef ushort SMB_ACL_PERM_T;
6090 +#define SMB_ACL_READ 4
6091 +#define SMB_ACL_WRITE 2
6092 +#define SMB_ACL_EXECUTE 1
6094 +/* Types of ACLs. */
6095 +#define SMB_ACL_USER USER
6096 +#define SMB_ACL_USER_OBJ USER_OBJ
6097 +#define SMB_ACL_GROUP GROUP
6098 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6099 +#define SMB_ACL_OTHER OTHER_OBJ
6100 +#define SMB_ACL_MASK CLASS_OBJ
6102 +typedef struct SMB_ACL_T {
6106 + struct acl acl[1];
6109 +typedef struct acl *SMB_ACL_ENTRY_T;
6111 +#define SMB_ACL_FIRST_ENTRY 0
6112 +#define SMB_ACL_NEXT_ENTRY 1
6114 +#define SMB_ACL_TYPE_ACCESS 0
6115 +#define SMB_ACL_TYPE_DEFAULT 1
6118 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6121 +#elif defined HAVE_HPUX_ACLS
6124 + * Based on the Solaris & UnixWare code.
6128 +#include <sys/aclv.h>
6130 +/* SVR4.2 ES/MP ACLs */
6131 +typedef int SMB_ACL_TAG_T;
6132 +typedef int SMB_ACL_TYPE_T;
6133 +typedef ushort *SMB_ACL_PERMSET_T;
6134 +typedef ushort SMB_ACL_PERM_T;
6135 +#define SMB_ACL_READ 4
6136 +#define SMB_ACL_WRITE 2
6137 +#define SMB_ACL_EXECUTE 1
6139 +/* Types of ACLs. */
6140 +#define SMB_ACL_USER USER
6141 +#define SMB_ACL_USER_OBJ USER_OBJ
6142 +#define SMB_ACL_GROUP GROUP
6143 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6144 +#define SMB_ACL_OTHER OTHER_OBJ
6145 +#define SMB_ACL_MASK CLASS_OBJ
6147 +typedef struct SMB_ACL_T {
6151 + struct acl acl[1];
6154 +typedef struct acl *SMB_ACL_ENTRY_T;
6156 +#define SMB_ACL_FIRST_ENTRY 0
6157 +#define SMB_ACL_NEXT_ENTRY 1
6159 +#define SMB_ACL_TYPE_ACCESS 0
6160 +#define SMB_ACL_TYPE_DEFAULT 1
6162 +#elif defined HAVE_IRIX_ACLS
6164 +#define SMB_ACL_TAG_T acl_tag_t
6165 +#define SMB_ACL_TYPE_T acl_type_t
6166 +#define SMB_ACL_PERMSET_T acl_permset_t
6167 +#define SMB_ACL_PERM_T acl_perm_t
6168 +#define SMB_ACL_READ ACL_READ
6169 +#define SMB_ACL_WRITE ACL_WRITE
6170 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6172 +/* Types of ACLs. */
6173 +#define SMB_ACL_USER ACL_USER
6174 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6175 +#define SMB_ACL_GROUP ACL_GROUP
6176 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6177 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6178 +#define SMB_ACL_MASK ACL_MASK
6180 +typedef struct SMB_ACL_T {
6186 +#define SMB_ACL_ENTRY_T acl_entry_t
6188 +#define SMB_ACL_FIRST_ENTRY 0
6189 +#define SMB_ACL_NEXT_ENTRY 1
6191 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6192 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6194 +#elif defined HAVE_AIX_ACLS
6196 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6198 +#include "/usr/include/acl.h"
6200 +typedef uint *SMB_ACL_PERMSET_T;
6202 +struct acl_entry_link{
6203 + struct acl_entry_link *prevp;
6204 + struct new_acl_entry *entryp;
6205 + struct acl_entry_link *nextp;
6209 +struct new_acl_entry{
6210 + unsigned short ace_len;
6211 + unsigned short ace_type;
6212 + unsigned int ace_access;
6213 + struct ace_id ace_id[1];
6216 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6217 +#define SMB_ACL_T struct acl_entry_link*
6219 +#define SMB_ACL_TAG_T unsigned short
6220 +#define SMB_ACL_TYPE_T int
6221 +#define SMB_ACL_PERM_T uint
6222 +#define SMB_ACL_READ S_IRUSR
6223 +#define SMB_ACL_WRITE S_IWUSR
6224 +#define SMB_ACL_EXECUTE S_IXUSR
6226 +/* Types of ACLs. */
6227 +#define SMB_ACL_USER ACEID_USER
6228 +#define SMB_ACL_USER_OBJ 3
6229 +#define SMB_ACL_GROUP ACEID_GROUP
6230 +#define SMB_ACL_GROUP_OBJ 4
6231 +#define SMB_ACL_OTHER 5
6232 +#define SMB_ACL_MASK 6
6235 +#define SMB_ACL_FIRST_ENTRY 1
6236 +#define SMB_ACL_NEXT_ENTRY 2
6238 +#define SMB_ACL_TYPE_ACCESS 0
6239 +#define SMB_ACL_TYPE_DEFAULT 1
6241 +#else /* No ACLs. */
6243 +/* No ACLS - fake it. */
6244 +#define SMB_ACL_TAG_T int
6245 +#define SMB_ACL_TYPE_T int
6246 +#define SMB_ACL_PERMSET_T mode_t
6247 +#define SMB_ACL_PERM_T mode_t
6248 +#define SMB_ACL_READ S_IRUSR
6249 +#define SMB_ACL_WRITE S_IWUSR
6250 +#define SMB_ACL_EXECUTE S_IXUSR
6252 +/* Types of ACLs. */
6253 +#define SMB_ACL_USER 0
6254 +#define SMB_ACL_USER_OBJ 1
6255 +#define SMB_ACL_GROUP 2
6256 +#define SMB_ACL_GROUP_OBJ 3
6257 +#define SMB_ACL_OTHER 4
6258 +#define SMB_ACL_MASK 5
6260 +typedef struct SMB_ACL_T {
6264 +typedef struct SMB_ACL_ENTRY_T {
6266 +} *SMB_ACL_ENTRY_T;
6268 +#define SMB_ACL_FIRST_ENTRY 0
6269 +#define SMB_ACL_NEXT_ENTRY 1
6271 +#define SMB_ACL_TYPE_ACCESS 0
6272 +#define SMB_ACL_TYPE_DEFAULT 1
6274 +#endif /* No ACLs. */
6275 +#endif /* _SMB_ACLS_H */
6278 @@ -79,3 +79,7 @@ struct filter_list_struct server_filter_
6282 + const char *who_am_i(void)
6286 --- old/testsuite/acls.test
6287 +++ new/testsuite/acls.test
6291 +# This program is distributable under the terms of the GNU GPL (see
6294 +# Test that rsync handles basic ACL preservation.
6296 +. $srcdir/testsuite/rsync.fns
6298 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6299 +case "$setfacl_nodef" in
6300 +true) test_skipped "I don't know how to use your setfacl command" ;;
6303 +makepath "$fromdir/foo"
6304 +echo something >"$fromdir/file1"
6305 +echo else >"$fromdir/file2"
6307 +files='foo file1 file2'
6309 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6310 +setfacl -m u:0:5 "$fromdir/file1"
6311 +setfacl -m u:0:5 "$fromdir/file2"
6313 +$RSYNC -avvA "$fromdir/" "$todir/"
6316 +getfacl $files >"$scratchdir/acls.txt"
6319 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6321 +# The script would have aborted on error, so getting here means we've won.
6323 --- old/testsuite/default-acls.test
6324 +++ new/testsuite/default-acls.test
6328 +# This program is distributable under the terms of the GNU GPL (see
6331 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6333 +. $srcdir/testsuite/rsync.fns
6335 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6336 +case "$setfacl_nodef" in
6337 +true) test_skipped "I don't know how to use your setfacl command" ;;
6338 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6339 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6341 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6343 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6345 + todir="$scratchdir/$1"
6347 + $setfacl_nodef "$todir"
6349 + case "$setfacl_nodef" in
6350 + *-k*) opts="-dm $2" ;;
6351 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6353 + setfacl $opts "$todir"
6355 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6356 + # even though the directory itself is outside the transfer
6357 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6358 + check_perms "$todir/to" $4 "Target $1"
6359 + check_perms "$todir/to/dir" $4 "Target $1"
6360 + check_perms "$todir/to/file" $3 "Target $1"
6361 + check_perms "$todir/to/program" $4 "Target $1"
6362 + # Make sure get_local_name doesn't mess us up when transferring only one file
6363 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6364 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6365 + # Make sure we obey default ACLs when not transferring a regular file
6366 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6367 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6370 +mkdir "$scratchdir/dir"
6371 +echo "File!" >"$scratchdir/file"
6372 +echo "#!/bin/sh" >"$scratchdir/program"
6373 +chmod 777 "$scratchdir/dir"
6374 +chmod 666 "$scratchdir/file"
6375 +chmod 777 "$scratchdir/program"
6377 +# Test some target directories
6379 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6380 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6381 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6382 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6383 +testit noda1 '' rw------- rwx------
6385 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6387 +testit noda3 '' rw-r--r-- rwxr-xr-x
6391 --- old/testsuite/devices.test
6392 +++ new/testsuite/devices.test
6393 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6394 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6396 cat <<EOT >"$chkfile"
6400 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6402 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6404 cat <<EOT >"$chkfile"
6408 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6410 @@ -58,7 +58,7 @@ sleep 1
6411 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6413 cat <<EOT >"$chkfile"
6417 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6419 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6422 cat <<EOT >"$chkfile"
6427 -hD+++++++ block2.5 => block3
6436 +hD+++++++++ block2.5 => block3
6442 if test ! -b "$fromdir/block2.5"; then
6443 sed -e '/block2\.5/d' \
6444 --- old/testsuite/itemize.test
6445 +++ new/testsuite/itemize.test
6446 @@ -29,14 +29,14 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6447 $RSYNC -iplr "$fromdir/" "$todir/" \
6449 cat <<EOT >"$chkfile"
6452 ->f+++++++ bar/baz/rsync
6454 ->f+++++++ foo/config1
6455 ->f+++++++ foo/config2
6456 ->f+++++++ foo/extra
6457 -cL+++++++ foo/sym -> ../bar/baz/rsync
6459 +cd+++++++++ bar/baz/
6460 +>f+++++++++ bar/baz/rsync
6462 +>f+++++++++ foo/config1
6463 +>f+++++++++ foo/config2
6464 +>f+++++++++ foo/extra
6465 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6467 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6469 @@ -48,10 +48,10 @@ chmod 601 "$fromdir/foo/config2"
6470 $RSYNC -iplrH "$fromdir/" "$todir/" \
6472 cat <<EOT >"$chkfile"
6473 ->f..T.... bar/baz/rsync
6474 ->f..T.... foo/config1
6475 ->f.sTp... foo/config2
6476 -hf..T.... foo/extra => foo/config1
6477 +>f..T...... bar/baz/rsync
6478 +>f..T...... foo/config1
6479 +>f.sTp..... foo/config2
6480 +hf..T...... foo/extra => foo/config1
6482 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6484 @@ -68,11 +68,11 @@ chmod 777 "$todir/bar/baz/rsync"
6485 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6487 cat <<EOT >"$chkfile"
6488 -.f..tp... bar/baz/rsync
6490 -.f..t.... foo/config1
6491 ->fcstp... foo/config2
6492 -cL..T.... foo/sym -> ../bar/baz/rsync
6493 +.f..tp..... bar/baz/rsync
6495 +.f..t...... foo/config1
6496 +>fcstp..... foo/config2
6497 +cL..T...... foo/sym -> ../bar/baz/rsync
6499 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6501 @@ -97,15 +97,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6504 cat <<EOT >"$chkfile"
6508 -.f...p... bar/baz/rsync
6511 ->f..t.... foo/config2
6513 -.L foo/sym -> ../bar/baz/rsync
6517 +.f...p..... bar/baz/rsync
6520 +>f..t...... foo/config2
6522 +.L foo/sym -> ../bar/baz/rsync
6524 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6526 @@ -124,8 +124,8 @@ touch "$todir/foo/config2"
6527 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6529 cat <<EOT >"$chkfile"
6530 -.f...p... foo/config1
6531 ->f..t.... foo/config2
6532 +.f...p..... foo/config1
6533 +>f..t...... foo/config2
6535 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6537 @@ -134,15 +134,15 @@ $RSYNC -ivvplrtH --copy-dest="$lddir" "$
6540 cat <<EOT >"$chkfile"
6548 -hf foo/extra => foo/config1
6549 -cL..T.... foo/sym -> ../bar/baz/rsync
6552 +cd+++++++++ bar/baz/
6557 +hf foo/extra => foo/config1
6558 +cL..T...... foo/sym -> ../bar/baz/rsync
6560 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6562 @@ -150,11 +150,11 @@ rm -rf "$todir"
6563 $RSYNC -iplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
6565 cat <<EOT >"$chkfile"
6570 -hf foo/extra => foo/config1
6573 +cd+++++++++ bar/baz/
6575 +hf foo/extra => foo/config1
6577 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6579 @@ -181,15 +181,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6582 cat <<EOT >"$chkfile"
6590 -hf foo/extra => foo/config1
6591 -hL foo/sym -> ../bar/baz/rsync
6594 +cd+++++++++ bar/baz/
6599 +hf foo/extra => foo/config1
6600 +hL foo/sym -> ../bar/baz/rsync
6602 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6604 @@ -197,10 +197,10 @@ rm -rf "$todir"
6605 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
6607 cat <<EOT >"$chkfile"
6614 +cd+++++++++ bar/baz/
6617 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6619 @@ -228,14 +228,14 @@ filter_outfile
6620 # TODO fix really-old problem when combining -H with --compare-dest:
6621 # missing output for foo/extra hard-link (and it might not be updated)!
6622 cat <<EOT >"$chkfile"
6630 -.L foo/sym -> ../bar/baz/rsync
6633 +cd+++++++++ bar/baz/
6638 +.L foo/sym -> ../bar/baz/rsync
6640 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
6642 @@ -243,10 +243,10 @@ rm -rf "$todir"
6643 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6645 cat <<EOT >"$chkfile"
6652 +cd+++++++++ bar/baz/
6655 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6661 extern int preserve_uid;
6662 extern int preserve_gid;
6663 +extern int preserve_acls;
6664 extern int numeric_ids;
6667 @@ -275,7 +276,7 @@ void send_uid_list(int f)
6671 - if (preserve_uid) {
6672 + if (preserve_uid || preserve_acls) {
6674 /* we send sequences of uid/byte-length/name */
6675 for (list = uidlist; list; list = list->next) {
6676 @@ -292,7 +293,7 @@ void send_uid_list(int f)
6680 - if (preserve_gid) {
6681 + if (preserve_gid || preserve_acls) {
6683 for (list = gidlist; list; list = list->next) {
6685 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
6689 - if (preserve_uid && !numeric_ids) {
6690 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6691 /* read the uid list */
6692 while ((id = read_int(f)) != 0) {
6693 int len = read_byte(f);
6694 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
6698 - if (preserve_gid && !numeric_ids) {
6699 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6700 /* read the gid list */
6701 while ((id = read_int(f)) != 0) {
6702 int len = read_byte(f);
6703 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
6707 +#ifdef SUPPORT_ACLS
6708 + if (preserve_acls && !numeric_ids) {
6710 + while ((id = next_acl_uid(flist)) != NULL)
6711 + *id = match_uid(*id);
6712 + while ((id = next_acl_gid(flist)) != NULL)
6713 + *id = match_gid(*id);
6717 /* Now convert all the uids/gids from sender values to our values. */
6718 if (am_root && preserve_uid && !numeric_ids) {
6719 for (i = 0; i < flist->count; i++)
6722 @@ -1555,3 +1555,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6727 +void *expand_item_list(item_list *lp, size_t item_size,
6728 + const char *desc, int incr)
6730 + /* First time through, 0 <= 0, so list is expanded. */
6731 + if (lp->malloced <= lp->count) {
6733 + size_t new_size = lp->malloced;
6735 + new_size -= incr; /* increase slowly */
6736 + else if (new_size < (size_t)incr)
6740 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6741 + if (verbose >= 4) {
6742 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6743 + who_am_i(), desc, (double)new_size * item_size,
6744 + new_ptr == lp->items ? " not" : "");
6747 + out_of_memory("expand_item_list");
6749 + lp->items = new_ptr;
6750 + lp->malloced = new_size;
6752 + return (char*)lp->items + (lp->count++ * item_size);