1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 @@ -26,15 +26,15 @@ VERSION=@VERSION@
16 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
17 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
18 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
19 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
20 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
21 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
22 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
23 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
24 main.o checksum.o match.o syscall.o log.o backup.o
25 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
26 - fileio.o batch.o clientname.o chmod.o
27 + fileio.o batch.o clientname.o chmod.o acls.o
28 OBJS3=progress.o pipe.o
29 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
30 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 + * Handle passing Access Control Lists between systems.
37 + * Copyright (C) 1996 Andrew Tridgell
38 + * Copyright (C) 1996 Paul Mackerras
39 + * Copyright (C) 2006 Wayne Davison
41 + * This program is free software; you can redistribute it and/or modify
42 + * it under the terms of the GNU General Public License as published by
43 + * the Free Software Foundation; either version 2 of the License, or
44 + * (at your option) any later version.
46 + * This program is distributed in the hope that it will be useful,
47 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 + * GNU General Public License for more details.
51 + * You should have received a copy of the GNU General Public License along
52 + * with this program; if not, write to the Free Software Foundation, Inc.,
53 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
57 +#include "lib/sysacls.h"
63 +extern int orig_umask;
64 +extern int preserve_acls;
65 +extern unsigned int file_struct_len;
67 +/* === ACL structures === */
79 +#define NO_ENTRY ((uchar)0x80)
80 +typedef struct rsync_acl {
83 + /* These will be NO_ENTRY if there's no such entry. */
95 +static const rsync_acl empty_rsync_acl = {
96 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
99 +static item_list access_acl_list = EMPTY_ITEM_LIST;
100 +static item_list default_acl_list = EMPTY_ITEM_LIST;
102 +/* === Calculations on ACL types === */
104 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
106 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
107 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
108 + : "unknown SMB_ACL_TYPE_T";
111 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
112 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
114 +static int count_racl_entries(const rsync_acl *racl)
116 + return racl->users.count + racl->groups.count
117 + + (racl->user_obj != NO_ENTRY)
118 + + (racl->group_obj != NO_ENTRY)
119 + + (racl->mask != NO_ENTRY)
120 + + (racl->other != NO_ENTRY);
123 +static int calc_sacl_entries(const rsync_acl *racl)
125 + /* A System ACL always gets user/group/other permission entries. */
126 + return racl->users.count + racl->groups.count
127 +#ifdef ACLS_NEED_MASK
130 + + (racl->mask != NO_ENTRY) + 3;
134 +/* Extracts and returns the permission bits from the ACL. This cannot be
135 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
136 +static int rsync_acl_get_perms(const rsync_acl *racl)
138 + return (racl->user_obj << 6)
139 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
143 +/* Removes the permission-bit entries from the ACL because these
144 + * can be reconstructed from the file's mode. */
145 +static void rsync_acl_strip_perms(rsync_acl *racl)
147 + racl->user_obj = NO_ENTRY;
148 + if (racl->mask == NO_ENTRY)
149 + racl->group_obj = NO_ENTRY;
151 + if (racl->group_obj == racl->mask)
152 + racl->group_obj = NO_ENTRY;
153 + racl->mask = NO_ENTRY;
155 + racl->other = NO_ENTRY;
158 +/* Given an empty rsync_acl, fake up the permission bits. */
159 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
161 + racl->user_obj = (mode >> 6) & 7;
162 + racl->group_obj = (mode >> 3) & 7;
163 + racl->other = mode & 7;
166 +/* === Rsync ACL functions === */
168 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
170 + id_access *ida1, *ida2;
171 + int count = ial1->count;
172 + if (count != ial2->count)
176 + for (; count--; ida1++, ida2++) {
177 + if (ida1->access != ida2->access || ida1->id != ida2->id)
183 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
185 + return racl1->user_obj == racl2->user_obj
186 + && racl1->group_obj == racl2->group_obj
187 + && racl1->mask == racl2->mask
188 + && racl1->other == racl2->other
189 + && ida_entries_equal(&racl1->users, &racl2->users)
190 + && ida_entries_equal(&racl1->groups, &racl2->groups);
193 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
194 + * the ACL will be handled by the normal mode-preservation code. This is
195 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
196 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
197 + * that it might have several of its permission objects set to NO_ENTRY. */
198 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
199 + const rsync_acl *racl2, mode_t m)
201 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
202 + return False; /* One has a mask and the other doesn't */
204 + /* When there's a mask, the group_obj becomes an extended entry. */
205 + if (racl1->mask != NO_ENTRY) {
206 + /* A condensed rsync_acl with a mask can only have no
207 + * group_obj when it was identical to the mask. This
208 + * means that it was also identical to the group attrs
209 + * from the mode. */
210 + if (racl2->group_obj == NO_ENTRY) {
211 + if (racl1->group_obj != ((m >> 3) & 7))
213 + } else if (racl1->group_obj != racl2->group_obj)
216 + return ida_entries_equal(&racl1->users, &racl2->users)
217 + && ida_entries_equal(&racl1->groups, &racl2->groups);
220 +static void rsync_acl_free(rsync_acl *racl)
222 + if (racl->users.idas)
223 + free(racl->users.idas);
224 + if (racl->groups.idas)
225 + free(racl->groups.idas);
226 + *racl = empty_rsync_acl;
229 +void free_acl(statx *sxp)
231 + if (sxp->acc_acl) {
232 + rsync_acl_free(sxp->acc_acl);
233 + free(sxp->acc_acl);
234 + sxp->acc_acl = NULL;
236 + if (sxp->def_acl) {
237 + rsync_acl_free(sxp->def_acl);
238 + free(sxp->def_acl);
239 + sxp->def_acl = NULL;
243 +static int id_access_sorter(const void *r1, const void *r2)
245 + id_access *ida1 = (id_access *)r1;
246 + id_access *ida2 = (id_access *)r2;
247 + id_t rid1 = ida1->id, rid2 = ida2->id;
248 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
251 +static void sort_ida_entries(ida_entries *idal)
255 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
258 +/* Transfer the count id_access items out of the temp_ida_list into either
259 + * the users or groups ida_entries list in racl. */
260 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
265 + if (temp_ida_list->count) {
266 + int cnt = temp_ida_list->count;
267 + id_access *temp_idas = temp_ida_list->items;
268 + if (!(idas = new_array(id_access, cnt)))
269 + out_of_memory("save_idas");
270 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
274 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
277 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
278 + exit_cleanup(RERR_UNSUPPORTED);
280 + ent->count = temp_ida_list->count;
283 + /* Truncate the temporary list now that its idas have been saved. */
284 + temp_ida_list->count = 0;
287 +/* === System ACLs === */
289 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
290 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
292 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
293 + SMB_ACL_TAG_T prior_list_type = 0;
294 + SMB_ACL_ENTRY_T entry;
295 + const char *errfun;
298 + errfun = "sys_acl_get_entry";
299 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
301 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
302 + SMB_ACL_TAG_T tag_type;
303 + SMB_ACL_PERMSET_T permset;
307 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
308 + errfun = "sys_acl_get_tag_type";
311 + if ((rc = sys_acl_get_permset(entry, &permset))) {
312 + errfun = "sys_acl_get_tag_type";
315 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
316 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
317 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
318 + /* continue == done with entry; break == store in temporary ida list */
319 + switch (tag_type) {
320 + case SMB_ACL_USER_OBJ:
321 + if (racl->user_obj == NO_ENTRY)
322 + racl->user_obj = access;
324 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
328 + case SMB_ACL_GROUP_OBJ:
329 + if (racl->group_obj == NO_ENTRY)
330 + racl->group_obj = access;
332 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
334 + case SMB_ACL_GROUP:
337 + if (racl->mask == NO_ENTRY)
338 + racl->mask = access;
340 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
342 + case SMB_ACL_OTHER:
343 + if (racl->other == NO_ENTRY)
344 + racl->other = access;
346 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
349 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
352 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
353 + errfun = "sys_acl_get_tag_type";
357 + if (tag_type != prior_list_type) {
358 + if (prior_list_type)
359 + save_idas(&temp_ida_list, racl, prior_list_type);
360 + prior_list_type = tag_type;
362 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
363 + ida->id = *((id_t *)qualifier);
364 + ida->access = access;
365 + sys_acl_free_qualifier(qualifier, tag_type);
368 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
369 + rsync_acl_free(racl);
372 + if (prior_list_type)
373 + save_idas(&temp_ida_list, racl, prior_list_type);
375 + sort_ida_entries(&racl->users);
376 + sort_ida_entries(&racl->groups);
378 +#ifdef ACLS_NEED_MASK
379 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
380 + /* Throw away a superfluous mask, but mask off the
381 + * group perms with it first. */
382 + racl->group_obj &= racl->mask;
383 + racl->mask = NO_ENTRY;
390 +/* Synactic sugar for system calls */
392 +#define CALL_OR_ERROR(func,args,str) \
400 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
401 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
403 +/* Store the permissions in the system ACL entry. */
404 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
406 + const char *errfun = NULL;
407 + SMB_ACL_PERMSET_T permset;
409 + COE( sys_acl_get_permset,(entry, &permset) );
410 + COE( sys_acl_clear_perms,(permset) );
412 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
414 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
416 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
417 + COE( sys_acl_set_permset,(entry, permset) );
422 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
426 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
427 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
429 +#ifdef ACLS_NEED_MASK
434 + const char *errfun = NULL;
435 + SMB_ACL_ENTRY_T entry;
437 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
438 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
442 + COE( sys_acl_create_entry,(smb_acl, &entry) );
443 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
444 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
446 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
447 + COE( sys_acl_create_entry,(smb_acl, &entry) );
448 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
449 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
450 + COE2( store_access_in_entry,(ida->access, entry) );
453 + COE( sys_acl_create_entry,(smb_acl, &entry) );
454 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
455 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
457 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
458 + COE( sys_acl_create_entry,(smb_acl, &entry) );
459 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
460 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
461 + COE2( store_access_in_entry,(ida->access, entry) );
464 +#ifdef ACLS_NEED_MASK
465 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
466 + COE( sys_acl_create_entry,(smb_acl, &entry) );
467 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
468 + COE2( store_access_in_entry,(mask_bits, entry) );
470 + if (racl->mask != NO_ENTRY) {
471 + COE( sys_acl_create_entry,(smb_acl, &entry) );
472 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
473 + COE2( store_access_in_entry,(racl->mask, entry) );
477 + COE( sys_acl_create_entry,(smb_acl, &entry) );
478 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
479 + COE2( store_access_in_entry,(racl->other & 7, entry) );
482 + if (sys_acl_valid(*smb_acl) < 0)
483 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
490 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
492 + sys_acl_free_acl(*smb_acl);
496 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
497 + const item_list *racl_list,
498 + const rsync_acl *racl)
500 + static int access_match = -1, default_match = -1;
501 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
502 + size_t count = racl_list->count;
504 + /* If this is the first time through or we didn't match the last
505 + * time, then start at the end of the list, which should be the
506 + * best place to start hunting. */
508 + *match = racl_list->count - 1;
510 + rsync_acl *base = racl_list->items;
511 + if (rsync_acl_equal(base + *match, racl))
514 + *match = racl_list->count - 1;
521 +/* Return the Access Control List for the given filename. */
522 +int get_acl(const char *fname, statx *sxp)
524 + SMB_ACL_TYPE_T type;
526 + if (S_ISLNK(sxp->st.st_mode))
529 + type = SMB_ACL_TYPE_ACCESS;
531 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
532 + rsync_acl *racl = new(rsync_acl);
535 + out_of_memory("get_acl");
536 + *racl = empty_rsync_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 + if (type == SMB_ACL_TYPE_ACCESS)
553 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
555 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
556 + fname, str_acl_type(type));
560 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
565 +/* === Send functions === */
567 +/* The general strategy with the tag_type <-> character mapping is that
568 + * lowercase implies that no qualifier follows, where uppercase does.
569 + * A similar idiom for the ACL type (access or default) itself, but
570 + * lowercase in this instance means there's no ACL following, so the
571 + * ACL is a repeat, so the receiver should reuse the last of the same
574 +/* Send the ida list over the file descriptor. */
575 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
578 + size_t count = idal->count;
579 + for (ida = idal->idas; count--; ida++) {
580 + write_byte(f, tag_char);
581 + write_byte(f, ida->access);
582 + write_int(f, ida->id);
583 + /* FIXME: sorta wasteful: we should maybe buffer as
584 + * many ids as max(ACL_USER + ACL_GROUP) objects to
585 + * keep from making so many calls. */
586 + if (tag_char == 'U')
593 +/* Send an rsync ACL over the file descriptor. */
594 +static void send_rsync_acl(int f, const rsync_acl *racl)
596 + size_t count = count_racl_entries(racl);
597 + write_int(f, count);
598 + if (racl->user_obj != NO_ENTRY) {
599 + write_byte(f, 'u');
600 + write_byte(f, racl->user_obj);
602 + send_ida_entries(f, &racl->users, 'U');
603 + if (racl->group_obj != NO_ENTRY) {
604 + write_byte(f, 'g');
605 + write_byte(f, racl->group_obj);
607 + send_ida_entries(f, &racl->groups, 'G');
608 + if (racl->mask != NO_ENTRY) {
609 + write_byte(f, 'm');
610 + write_byte(f, racl->mask);
612 + if (racl->other != NO_ENTRY) {
613 + write_byte(f, 'o');
614 + write_byte(f, racl->other);
618 +/* Send the ACL from the statx structure down the indicated file descriptor.
619 + * This also frees the ACL data. */
620 +void send_acl(statx *sxp, int f)
622 + SMB_ACL_TYPE_T type;
623 + rsync_acl *racl, *new_racl;
624 + item_list *racl_list;
627 + if (S_ISLNK(sxp->st.st_mode))
630 + type = SMB_ACL_TYPE_ACCESS;
631 + racl = sxp->acc_acl;
632 + racl_list = &access_acl_list;
635 + racl = new(rsync_acl);
637 + out_of_memory("send_acl");
638 + *racl = empty_rsync_acl;
639 + if (type == SMB_ACL_TYPE_ACCESS) {
640 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
641 + sxp->acc_acl = racl;
643 + sxp->def_acl = racl;
646 + /* Avoid sending values that can be inferred from other data,
647 + * but only when preserve_acls == 1 (it is 2 when we must be
648 + * backward compatible with older acls.diff versions). */
649 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
650 + rsync_acl_strip_perms(racl);
651 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
652 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
655 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
656 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
657 + send_rsync_acl(f, racl);
659 + *racl = empty_rsync_acl;
661 + racl = sxp->def_acl;
662 + racl_list = &default_acl_list;
663 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
668 +/* === Receive functions === */
670 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
672 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
673 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
674 + uchar computed_mask_bits = 0;
678 + if (!(count = read_int(f)))
682 + char tag = read_byte(f);
683 + uchar access = read_byte(f);
684 + if (access & ~ (4 | 2 | 1)) {
685 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
687 + exit_cleanup(RERR_STREAMIO);
691 + if (racl->user_obj != NO_ENTRY) {
692 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
693 + exit_cleanup(RERR_STREAMIO);
695 + racl->user_obj = access;
698 + tag_type = SMB_ACL_USER;
701 + if (racl->group_obj != NO_ENTRY) {
702 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
703 + exit_cleanup(RERR_STREAMIO);
705 + racl->group_obj = access;
708 + tag_type = SMB_ACL_GROUP;
711 + if (racl->mask != NO_ENTRY) {
712 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
713 + exit_cleanup(RERR_STREAMIO);
715 + racl->mask = access;
718 + if (racl->other != NO_ENTRY) {
719 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
720 + exit_cleanup(RERR_STREAMIO);
722 + racl->other = access;
725 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
727 + exit_cleanup(RERR_STREAMIO);
729 + if (tag_type != prior_list_type) {
730 + if (prior_list_type)
731 + save_idas(&temp_ida_list, racl, prior_list_type);
732 + prior_list_type = tag_type;
734 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
735 + ida->access = access;
736 + ida->id = read_int(f);
737 + computed_mask_bits |= access;
739 + if (prior_list_type)
740 + save_idas(&temp_ida_list, racl, prior_list_type);
742 + if (type == SMB_ACL_TYPE_DEFAULT) {
743 + /* Ensure that these are never unset. */
744 + if (racl->user_obj == NO_ENTRY)
745 + racl->user_obj = 7;
746 + if (racl->group_obj == NO_ENTRY)
747 + racl->group_obj = 0;
748 + if (racl->other == NO_ENTRY)
752 + if (!racl->users.count && !racl->groups.count) {
753 + /* If we received a superfluous mask, throw it away. */
754 + if (racl->mask != NO_ENTRY) {
755 + /* Mask off the group perms with it first. */
756 + racl->group_obj &= racl->mask | NO_ENTRY;
757 + racl->mask = NO_ENTRY;
759 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
760 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
763 +/* Receive the ACL info the sender has included for this file-list entry. */
764 +void receive_acl(struct file_struct *file, int f)
766 + SMB_ACL_TYPE_T type;
767 + item_list *racl_list;
770 + if (S_ISLNK(file->mode))
773 + type = SMB_ACL_TYPE_ACCESS;
774 + racl_list = &access_acl_list;
775 + ndx_ptr = (char*)file + file_struct_len;
777 + char tag = read_byte(f);
780 + if (tag == 'A' || tag == 'a') {
781 + if (type != SMB_ACL_TYPE_ACCESS) {
782 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
783 + f_name(file, NULL));
784 + exit_cleanup(RERR_STREAMIO);
786 + } else if (tag == 'D' || tag == 'd') {
787 + if (type == SMB_ACL_TYPE_ACCESS) {
788 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
789 + f_name(file, NULL));
790 + exit_cleanup(RERR_STREAMIO);
793 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
794 + f_name(file, NULL), tag);
795 + exit_cleanup(RERR_STREAMIO);
797 + if (tag == 'A' || tag == 'D') {
799 + ndx = racl_list->count;
800 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
801 + duo_item->racl = empty_rsync_acl;
802 + receive_rsync_acl(&duo_item->racl, f, type);
803 + duo_item->sacl = NULL;
806 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
807 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
808 + f_name(file, NULL), str_acl_type(type), ndx);
809 + exit_cleanup(RERR_STREAMIO);
812 + SIVAL(ndx_ptr, 0, ndx);
813 + racl_list = &default_acl_list;
815 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
818 +/* Turn the ACL data in statx into cached ACL data, setting the index
819 + * values in the file struct. */
820 +void cache_acl(struct file_struct *file, statx *sxp)
822 + SMB_ACL_TYPE_T type;
824 + item_list *racl_list;
828 + if (S_ISLNK(file->mode))
831 + type = SMB_ACL_TYPE_ACCESS;
832 + racl = sxp->acc_acl;
833 + racl_list = &access_acl_list;
834 + ndx_ptr = (char*)file + file_struct_len;
838 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
840 + ndx = racl_list->count;
841 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
842 + new_duo->racl = *racl;
843 + new_duo->sacl = NULL;
844 + *racl = empty_rsync_acl;
846 + SIVAL(ndx_ptr, 0, ndx);
847 + racl = sxp->def_acl;
848 + racl_list = &default_acl_list;
850 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
855 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
857 + SMB_ACL_ENTRY_T entry;
858 + const char *errfun;
861 + if (S_ISDIR(mode)) {
862 + /* If the sticky bit is going on, it's not safe to allow all
863 + * the new ACL to go into effect before it gets set. */
864 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
865 + if (mode & S_ISVTX)
868 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
871 + /* If setuid or setgid is going off, it's not safe to allow all
872 + * the new ACL to go into effect before they get cleared. */
873 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
874 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
879 + errfun = "sys_acl_get_entry";
880 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
882 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
883 + SMB_ACL_TAG_T tag_type;
884 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
885 + errfun = "sys_acl_get_tag_type";
888 + switch (tag_type) {
889 + case SMB_ACL_USER_OBJ:
890 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
892 + case SMB_ACL_GROUP_OBJ:
893 + /* group is only empty when identical to group perms. */
894 + if (racl->group_obj != NO_ENTRY)
896 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
899 +#ifndef ACLS_NEED_MASK
900 + /* mask is only empty when we don't need it. */
901 + if (racl->mask == NO_ENTRY)
904 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
906 + case SMB_ACL_OTHER:
907 + COE2( store_access_in_entry,(mode & 7, entry) );
914 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
920 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
921 + /* Ensure that chmod() will be called to restore any lost setid bits. */
922 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
923 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
924 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
927 + /* Return the mode of the file on disk, as we will set them. */
928 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
931 +/* Set ACL on indicated filename.
933 + * This sets extended access ACL entries and default ACL. If convenient,
934 + * it sets permission bits along with the access ACL and signals having
935 + * done so by modifying sxp->st.st_mode.
937 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
938 + * with fname set to NULL to just check if the ACL is unchanged. */
939 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
942 + SMB_ACL_TYPE_T type;
945 + if (S_ISLNK(file->mode))
948 + type = SMB_ACL_TYPE_ACCESS;
949 + ndx_ptr = (char*)file + file_struct_len;
953 + int32 ndx = IVAL(ndx_ptr, 0);
957 + if (type == SMB_ACL_TYPE_ACCESS) {
958 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
960 + duo_item = access_acl_list.items;
963 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
965 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
967 + duo_item = default_acl_list.items;
970 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
974 + if (!dry_run && fname) {
975 + if (type == SMB_ACL_TYPE_DEFAULT
976 + && duo_item->racl.user_obj == NO_ENTRY) {
977 + if (sys_acl_delete_def_file(fname) < 0) {
978 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
984 + mode_t cur_mode = sxp->st.st_mode;
985 + if (!duo_item->sacl
986 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
990 + if (type == SMB_ACL_TYPE_ACCESS) {
991 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
992 + cur_mode, file->mode);
993 + if (cur_mode == (mode_t)~0)
996 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
997 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
998 + fname, str_acl_type(type));
1002 + if (type == SMB_ACL_TYPE_ACCESS)
1003 + sxp->st.st_mode = cur_mode;
1006 + if (unchanged == 1)
1008 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1013 +/* === Enumeration functions for uid mapping === */
1015 +/* Context -- one and only one. Should be cycled through once on uid
1016 + * mapping and once on gid mapping. */
1017 +static item_list *_enum_racl_lists[] = {
1018 + &access_acl_list, &default_acl_list, NULL
1021 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1022 +static int enum_ida_index = 0;
1023 +static size_t enum_racl_index = 0;
1025 +/* This returns the next tag_type id from the given ACL for the next entry,
1026 + * or it returns 0 if there are no more tag_type ids in the acl. */
1027 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1029 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1030 + if (enum_ida_index < idal->count) {
1031 + id_access *ida = &idal->idas[enum_ida_index++];
1034 + enum_ida_index = 0;
1038 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1040 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1042 + acl_duo *duo_item = racl_list->items;
1043 + duo_item += enum_racl_index;
1044 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1047 + enum_racl_index = 0;
1051 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1053 + for (; *enum_racl_list; enum_racl_list++) {
1054 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1058 + enum_racl_list = &_enum_racl_lists[0];
1062 +id_t *next_acl_uid()
1064 + return next_acl_list_id(SMB_ACL_USER);
1067 +id_t *next_acl_gid()
1069 + return next_acl_list_id(SMB_ACL_GROUP);
1072 +/* This is used by dest_mode(). */
1073 +int default_perms_for_dir(const char *dir)
1082 + perms = ACCESSPERMS & ~orig_umask;
1083 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1084 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1085 + if (sacl == NULL) {
1086 + /* Couldn't get an ACL. Darn. */
1089 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1093 + /* We're doing a dry run, so the containing directory
1094 + * wasn't actually created. Don't worry about it. */
1097 + /* Otherwise fall through. */
1099 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1100 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1106 + racl = empty_rsync_acl;
1107 + ok = unpack_smb_acl(&racl, sacl);
1108 + sys_acl_free_acl(sacl);
1110 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1114 + /* Apply the permission-bit entries of the default ACL, if any. */
1115 + if (racl.user_obj != NO_ENTRY) {
1116 + perms = rsync_acl_get_perms(&racl);
1118 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1121 + rsync_acl_free(&racl);
1125 +#endif /* SUPPORT_ACLS */
1128 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1129 extern char *backup_dir;
1132 +extern int preserve_acls;
1133 extern int preserve_devices;
1134 extern int preserve_specials;
1135 extern int preserve_links;
1136 @@ -94,7 +95,8 @@ path
1137 ****************************************************************************/
1138 static int make_bak_dir(char *fullpath)
1142 + struct file_struct *file;
1143 char *rel = fullpath + backup_dir_len;
1144 char *end = rel + strlen(rel);
1146 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1148 /* Try to transfer the directory settings of the
1149 * actual dir that the files are coming from. */
1150 - if (do_stat(rel, &st) < 0) {
1151 + if (do_stat(rel, &sx.st) < 0) {
1152 rsyserr(FERROR, errno,
1153 "make_bak_dir stat %s failed",
1156 - do_lchown(fullpath, st.st_uid, st.st_gid);
1157 - do_chmod(fullpath, st.st_mode);
1158 +#ifdef SUPPORT_ACLS
1159 + sx.acc_acl = sx.def_acl = NULL;
1161 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1163 +#ifdef SUPPORT_ACLS
1164 + if (preserve_acls) {
1165 + get_acl(rel, &sx);
1166 + cache_acl(file, &sx);
1169 + set_file_attrs(fullpath, file, NULL, 0);
1174 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1175 * We will move the file to be deleted into a parallel directory tree. */
1176 static int keep_backup(char *fname)
1180 struct file_struct *file;
1185 /* return if no file to keep */
1186 - if (do_lstat(fname, &st) < 0)
1187 + if (do_lstat(fname, &sx.st) < 0)
1189 +#ifdef SUPPORT_ACLS
1190 + sx.acc_acl = sx.def_acl = NULL;
1193 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1194 return 1; /* the file could have disappeared */
1195 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1196 if (!(buf = get_backup_name(fname)))
1199 +#ifdef SUPPORT_ACLS
1200 + if (preserve_acls) {
1201 + get_acl(fname, &sx);
1202 + cache_acl(file, &sx);
1206 /* Check to see if this is a device file, or link */
1207 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1208 || (preserve_specials && IS_SPECIAL(file->mode))) {
1209 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1210 if (robust_move(fname, buf) != 0) {
1211 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1212 full_fname(fname), buf);
1213 - } else if (st.st_nlink > 1) {
1214 + } else if (sx.st.st_nlink > 1) {
1215 /* If someone has hard-linked the file into the backup
1216 * dir, rename() might return success but do nothing! */
1217 robust_unlink(fname); /* Just in case... */
1218 --- old/configure.in
1219 +++ new/configure.in
1220 @@ -515,6 +515,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1221 AC_CHECK_LIB(resolv, strcasecmp)
1224 +AC_CHECK_FUNCS(aclsort)
1225 +if test x"$ac_cv_func_aclsort" = x"no"; then
1226 + AC_CHECK_LIB(sec, aclsort)
1229 dnl At the moment we don't test for a broken memcmp(), because all we
1230 dnl need to do is test for equality, not comparison, and it seems that
1231 dnl every platform has a memcmp that can do at least that.
1232 @@ -779,6 +784,78 @@ AC_SUBST(OBJ_RESTORE)
1233 AC_SUBST(CC_SHOBJ_FLAG)
1234 AC_SUBST(BUILD_POPT)
1236 +AC_CHECK_HEADERS(sys/acl.h)
1237 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1238 +#################################################
1239 +# check for ACL support
1241 +AC_MSG_CHECKING(whether to support ACLs)
1242 +AC_ARG_ENABLE(acl-support,
1243 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1244 +[ case "$enableval" in
1247 + case "$host_os" in
1249 + AC_MSG_RESULT(Using UnixWare ACLs)
1250 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1252 + *solaris*|*cygwin*)
1253 + AC_MSG_RESULT(Using solaris ACLs)
1254 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1257 + AC_MSG_RESULT(Using HPUX ACLs)
1258 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1261 + AC_MSG_RESULT(Using IRIX ACLs)
1262 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1265 + AC_MSG_RESULT(Using AIX ACLs)
1266 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1269 + AC_MSG_RESULT(Using Tru64 ACLs)
1270 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1271 + LIBS="$LIBS -lpacl"
1274 + AC_MSG_RESULT(ACLs requested -- running tests)
1275 + AC_CHECK_LIB(acl,acl_get_file)
1276 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1277 + AC_TRY_LINK([#include <sys/types.h>
1278 +#include <sys/acl.h>],
1279 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1280 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1281 + AC_MSG_CHECKING(ACL test results)
1282 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1283 + AC_MSG_RESULT(Using posix ACLs)
1284 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1285 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1286 + AC_TRY_LINK([#include <sys/types.h>
1287 +#include <sys/acl.h>],
1288 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1289 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1290 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1291 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1294 + AC_MSG_ERROR(Failed to find ACL support)
1301 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1304 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1308 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1313 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1314 extern int one_file_system;
1315 extern int copy_dirlinks;
1316 extern int keep_dirlinks;
1317 +extern int preserve_acls;
1318 extern int preserve_links;
1319 extern int preserve_hard_links;
1320 extern int preserve_devices;
1321 @@ -133,6 +134,8 @@ static void list_file_entry(struct file_
1323 permstring(permbuf, f->mode);
1325 + /* TODO: indicate '+' if the entry has an ACL. */
1327 #ifdef SUPPORT_LINKS
1328 if (preserve_links && S_ISLNK(f->mode)) {
1329 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1330 @@ -495,6 +498,9 @@ static struct file_struct *receive_file_
1331 char thisname[MAXPATHLEN];
1332 unsigned int l1 = 0, l2 = 0;
1333 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1334 +#ifdef SUPPORT_ACLS
1338 char *basename, *dirname, *bp;
1339 struct file_struct *file;
1340 @@ -598,13 +604,27 @@ static struct file_struct *receive_file_
1342 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1344 +#ifdef SUPPORT_ACLS
1345 + /* We need one or two index int32s when we're preserving ACLs. */
1346 + if (preserve_acls)
1347 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
1352 alloc_len = file_struct_len + dirname_len + basename_len
1353 +#ifdef SUPPORT_ACLS
1356 + linkname_len + sum_len;
1357 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1359 file = (struct file_struct *)bp;
1360 memset(bp, 0, file_struct_len);
1361 bp += file_struct_len;
1362 +#ifdef SUPPORT_ACLS
1366 file->modtime = modtime;
1367 file->length = file_length;
1368 @@ -699,6 +719,11 @@ static struct file_struct *receive_file_
1369 read_buf(f, sum, checksum_len);
1372 +#ifdef SUPPORT_ACLS
1373 + if (preserve_acls)
1374 + receive_acl(file, f);
1380 @@ -949,6 +974,9 @@ static struct file_struct *send_file_nam
1381 unsigned short flags)
1383 struct file_struct *file;
1384 +#ifdef SUPPORT_ACLS
1388 file = make_file(fname, flist, stp, flags,
1389 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1390 @@ -958,6 +986,15 @@ static struct file_struct *send_file_nam
1391 if (chmod_modes && !S_ISLNK(file->mode))
1392 file->mode = tweak_mode(file->mode, chmod_modes);
1394 +#ifdef SUPPORT_ACLS
1395 + if (preserve_acls) {
1396 + sx.st.st_mode = file->mode;
1397 + sx.acc_acl = sx.def_acl = NULL;
1398 + if (get_acl(fname, &sx) < 0)
1403 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1405 flist_expand(flist);
1406 @@ -965,6 +1002,15 @@ static struct file_struct *send_file_nam
1407 if (file->basename[0]) {
1408 flist->files[flist->count++] = file;
1409 send_file_entry(file, f);
1410 +#ifdef SUPPORT_ACLS
1411 + if (preserve_acls)
1415 +#ifdef SUPPORT_ACLS
1416 + if (preserve_acls)
1424 @@ -35,6 +35,7 @@ extern int do_progress;
1425 extern int relative_paths;
1426 extern int implied_dirs;
1427 extern int keep_dirlinks;
1428 +extern int preserve_acls;
1429 extern int preserve_links;
1430 extern int preserve_devices;
1431 extern int preserve_specials;
1432 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1433 extern int max_delete;
1434 extern int force_delete;
1435 extern int one_file_system;
1436 +extern mode_t orig_umask;
1437 extern struct stats stats;
1438 extern dev_t filesystem_dev;
1439 extern char *backup_dir;
1440 @@ -317,22 +319,27 @@ static void do_delete_pass(struct file_l
1441 rprintf(FINFO, " \r");
1444 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1445 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1448 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1449 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1452 - if (am_root && preserve_uid && st->st_uid != file->uid)
1453 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1456 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1457 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1460 +#ifdef SUPPORT_ACLS
1461 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1468 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1469 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1470 int32 iflags, uchar fnamecmp_type, char *xname)
1472 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1473 @@ -340,19 +347,23 @@ void itemize(struct file_struct *file, i
1474 : S_ISDIR(file->mode) ? !omit_dir_times
1475 : !S_ISLNK(file->mode);
1477 - if (S_ISREG(file->mode) && file->length != st->st_size)
1478 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1479 iflags |= ITEM_REPORT_SIZE;
1480 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1481 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1482 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1483 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1484 iflags |= ITEM_REPORT_TIME;
1485 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1486 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1487 iflags |= ITEM_REPORT_PERMS;
1488 - if (preserve_uid && am_root && file->uid != st->st_uid)
1489 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1490 iflags |= ITEM_REPORT_OWNER;
1491 if (preserve_gid && file->gid != GID_NONE
1492 - && st->st_gid != file->gid)
1493 + && sxp->st.st_gid != file->gid)
1494 iflags |= ITEM_REPORT_GROUP;
1495 +#ifdef SUPPORT_ACLS
1496 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1497 + iflags |= ITEM_REPORT_ACL;
1500 iflags |= ITEM_IS_NEW;
1502 @@ -605,7 +616,7 @@ void check_for_finished_hlinks(int itemi
1503 * handling the file, -1 if no dest-linking occurred, or a non-negative
1504 * value if we found an alternate basis file. */
1505 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1506 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1507 + char *cmpbuf, statx *sxp, int itemizing,
1508 int maybe_ATTRS_REPORT, enum logcode code)
1510 int best_match = -1;
1511 @@ -614,7 +625,7 @@ static int try_dests_reg(struct file_str
1514 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1515 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1516 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1518 switch (match_level) {
1520 @@ -622,16 +633,20 @@ static int try_dests_reg(struct file_str
1524 - if (!unchanged_file(cmpbuf, file, stp))
1525 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1531 - if (!unchanged_attrs(file, stp))
1532 +#ifdef SUPPORT_ACLS
1533 + if (preserve_acls)
1534 + get_acl(cmpbuf, sxp);
1536 + if (!unchanged_attrs(file, sxp))
1538 if (always_checksum && preserve_times
1539 - && cmp_time(stp->st_mtime, file->modtime))
1540 + && cmp_time(sxp->st.st_mtime, file->modtime))
1544 @@ -646,14 +661,14 @@ static int try_dests_reg(struct file_str
1545 if (j != best_match) {
1547 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1548 - if (link_stat(cmpbuf, stp, 0) < 0)
1549 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1553 if (match_level == 3 && !copy_dest) {
1554 #ifdef SUPPORT_HARD_LINKS
1556 - if (hard_link_one(file, ndx, fname, 0, stp,
1557 + if (hard_link_one(file, ndx, fname, 0, sxp,
1559 itemizing && verbose > 1,
1561 @@ -665,8 +680,13 @@ static int try_dests_reg(struct file_str
1566 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1568 +#ifdef SUPPORT_ACLS
1569 + if (preserve_acls && !ACL_READY(*sxp))
1570 + get_acl(fname, sxp);
1572 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1574 if (verbose > 1 && maybe_ATTRS_REPORT) {
1575 rprintf(FCLIENT, "%s is uptodate\n", fname);
1577 @@ -682,8 +702,13 @@ static int try_dests_reg(struct file_str
1582 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1584 +#ifdef SUPPORT_ACLS
1585 + if (preserve_acls && !ACL_READY(*sxp))
1586 + get_acl(fname, sxp);
1588 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1590 set_file_attrs(fname, file, NULL, 0);
1591 if (maybe_ATTRS_REPORT
1592 && ((!itemizing && verbose && match_level == 2)
1593 @@ -707,13 +732,18 @@ static int try_dests_non(struct file_str
1596 char fnamebuf[MAXPATHLEN];
1602 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1603 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1604 - || !unchanged_attrs(file, &st))
1605 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1607 +#ifdef SUPPORT_ACLS
1608 + if (preserve_acls)
1609 + get_acl(fnamebuf, &sx);
1611 + if (!unchanged_attrs(file, &sx))
1613 if (S_ISLNK(file->mode)) {
1614 #ifdef SUPPORT_LINKS
1615 @@ -726,10 +756,10 @@ static int try_dests_non(struct file_str
1618 } else if (IS_SPECIAL(file->mode)) {
1619 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1620 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1622 } else if (IS_DEVICE(file->mode)) {
1623 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1624 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1628 @@ -760,7 +790,15 @@ static int try_dests_non(struct file_str
1629 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1630 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1631 char *lp = link_dest ? "" : NULL;
1632 - itemize(file, ndx, 0, &st, changes, 0, lp);
1633 +#ifdef SUPPORT_ACLS
1634 + if (preserve_acls)
1635 + get_acl(fname, &sx);
1637 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1638 +#ifdef SUPPORT_ACLS
1639 + if (preserve_acls)
1643 if (verbose > 1 && maybe_ATTRS_REPORT) {
1644 rprintf(FCLIENT, "%s is uptodate\n", fname);
1645 @@ -772,6 +810,7 @@ static int try_dests_non(struct file_str
1648 static int phase = 0;
1649 +static int dflt_perms;
1651 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1652 * make sure it exists, and has the right permissions/timestamp info. For
1653 @@ -793,7 +832,8 @@ static void recv_generator(char *fname,
1654 static int need_fuzzy_dirlist = 0;
1655 struct file_struct *fuzzy_file = NULL;
1656 int fd = -1, f_copy = -1;
1657 - STRUCT_STAT st, real_st, partial_st;
1658 + statx sx, real_sx;
1659 + STRUCT_STAT partial_st;
1660 struct file_struct *back_file = NULL;
1661 int statret, real_ret, stat_errno;
1662 char *fnamecmp, *partialptr, *backupptr = NULL;
1663 @@ -849,6 +889,9 @@ static void recv_generator(char *fname,
1664 } else if (!dry_run)
1667 +#ifdef SUPPORT_ACLS
1668 + sx.acc_acl = sx.def_acl = NULL;
1672 stat_errno = ENOENT;
1673 @@ -856,7 +899,7 @@ static void recv_generator(char *fname,
1674 char *dn = file->dirname ? file->dirname : ".";
1675 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1676 if (relative_paths && !implied_dirs
1677 - && do_stat(dn, &st) < 0
1678 + && do_stat(dn, &sx.st) < 0
1679 && create_directory_path(fname) < 0) {
1680 rsyserr(FERROR, errno,
1681 "recv_generator: mkdir %s failed",
1682 @@ -868,6 +911,10 @@ static void recv_generator(char *fname,
1685 need_fuzzy_dirlist = 1;
1686 +#ifdef SUPPORT_ACLS
1687 + if (!preserve_perms)
1688 + dflt_perms = default_perms_for_dir(dn);
1691 parent_dirname = dn;
1693 @@ -876,7 +923,7 @@ static void recv_generator(char *fname,
1694 need_fuzzy_dirlist = 0;
1697 - statret = link_stat(fname, &st,
1698 + statret = link_stat(fname, &sx.st,
1699 keep_dirlinks && S_ISDIR(file->mode));
1702 @@ -894,8 +941,9 @@ static void recv_generator(char *fname,
1703 * mode based on the local permissions and some heuristics. */
1704 if (!preserve_perms) {
1705 int exists = statret == 0
1706 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1707 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1708 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1709 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1713 if (S_ISDIR(file->mode)) {
1714 @@ -904,8 +952,8 @@ static void recv_generator(char *fname,
1715 * file of that name and it is *not* a directory, then
1716 * we need to delete it. If it doesn't exist, then
1717 * (perhaps recursively) create it. */
1718 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1719 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1720 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1721 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1725 @@ -920,7 +968,11 @@ static void recv_generator(char *fname,
1729 - itemize(file, ndx, sr, &st,
1730 +#ifdef SUPPORT_ACLS
1731 + if (preserve_acls && sr == 0)
1732 + get_acl(fname, &sx);
1734 + itemize(file, ndx, sr, &sx,
1735 sr ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1737 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1738 @@ -940,19 +992,19 @@ static void recv_generator(char *fname,
1742 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1743 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1744 && verbose && code != FNONE && f_out != -1)
1745 rprintf(code, "%s/\n", fname);
1746 if (delete_during && f_out != -1 && !phase && dry_run < 2
1747 && (file->flags & FLAG_DEL_HERE))
1748 - delete_in_dir(the_file_list, fname, file, &st);
1750 + delete_in_dir(the_file_list, fname, file, &sx.st);
1754 if (preserve_hard_links && file->link_u.links
1755 - && hard_link_check(file, ndx, fname, statret, &st,
1756 + && hard_link_check(file, ndx, fname, statret, &sx,
1757 itemizing, code, HL_CHECK_MASTER))
1761 if (preserve_links && S_ISLNK(file->mode)) {
1762 #ifdef SUPPORT_LINKS
1763 @@ -970,7 +1022,7 @@ static void recv_generator(char *fname,
1764 char lnk[MAXPATHLEN];
1767 - if (!S_ISDIR(st.st_mode)
1768 + if (!S_ISDIR(sx.st.st_mode)
1769 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1771 /* A link already pointing to the
1772 @@ -978,10 +1030,10 @@ static void recv_generator(char *fname,
1774 if (strcmp(lnk, file->u.link) == 0) {
1776 - itemize(file, ndx, 0, &st, 0,
1777 + itemize(file, ndx, 0, &sx, 0,
1780 - set_file_attrs(fname, file, &st,
1781 + set_file_attrs(fname, file, &sx,
1782 maybe_ATTRS_REPORT);
1783 if (preserve_hard_links
1784 && file->link_u.links) {
1785 @@ -996,9 +1048,9 @@ static void recv_generator(char *fname,
1787 /* Not the right symlink (or not a symlink), so
1789 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1790 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1792 - if (!S_ISLNK(st.st_mode))
1793 + if (!S_ISLNK(sx.st.st_mode))
1795 } else if (basis_dir[0] != NULL) {
1796 if (try_dests_non(file, fname, ndx, itemizing,
1797 @@ -1015,7 +1067,7 @@ static void recv_generator(char *fname,
1800 if (preserve_hard_links && file->link_u.links
1801 - && hard_link_check(file, ndx, fname, -1, &st,
1802 + && hard_link_check(file, ndx, fname, -1, &sx,
1803 itemizing, code, HL_SKIP))
1805 if (do_symlink(file->u.link,fname) != 0) {
1806 @@ -1024,7 +1076,7 @@ static void recv_generator(char *fname,
1808 set_file_attrs(fname, file, NULL, 0);
1810 - itemize(file, ndx, statret, &st,
1811 + itemize(file, ndx, statret, &sx,
1812 ITEM_LOCAL_CHANGE, 0, NULL);
1814 if (code != FNONE && verbose) {
1815 @@ -1059,18 +1111,22 @@ static void recv_generator(char *fname,
1819 +#ifdef SUPPORT_ACLS
1820 + if (preserve_acls && statret == 0)
1821 + get_acl(fname, &sx);
1824 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1825 - || st.st_rdev != file->u.rdev) {
1826 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1827 + || sx.st.st_rdev != file->u.rdev) {
1829 - && delete_item(fname, st.st_mode, del_opts) < 0)
1831 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1833 if (preserve_hard_links && file->link_u.links
1834 - && hard_link_check(file, ndx, fname, -1, &st,
1835 + && hard_link_check(file, ndx, fname, -1, &sx,
1836 itemizing, code, HL_SKIP))
1838 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1839 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1841 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1842 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1845 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1846 @@ -1083,7 +1139,7 @@ static void recv_generator(char *fname,
1848 set_file_attrs(fname, file, NULL, 0);
1850 - itemize(file, ndx, statret, &st,
1851 + itemize(file, ndx, statret, &sx,
1852 ITEM_LOCAL_CHANGE, 0, NULL);
1854 if (code != FNONE && verbose)
1855 @@ -1097,14 +1153,14 @@ static void recv_generator(char *fname,
1859 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1860 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1861 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1862 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1863 if (preserve_hard_links && file->link_u.links)
1864 hard_link_cluster(file, ndx, itemizing, code);
1865 if (remove_source_files == 1)
1866 goto return_with_success;
1872 if (!S_ISREG(file->mode)) {
1873 @@ -1138,7 +1194,7 @@ static void recv_generator(char *fname,
1876 if (update_only && statret == 0
1877 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1878 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1880 rprintf(FINFO, "%s is newer\n", fname);
1882 @@ -1147,20 +1203,20 @@ static void recv_generator(char *fname,
1884 fnamecmp_type = FNAMECMP_FNAME;
1886 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1887 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1888 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1889 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1892 stat_errno = ENOENT;
1895 if (statret != 0 && basis_dir[0] != NULL) {
1896 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1897 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1898 itemizing, maybe_ATTRS_REPORT, code);
1900 if (remove_source_files == 1)
1901 goto return_with_success;
1906 fnamecmp = fnamecmpbuf;
1907 @@ -1170,7 +1226,7 @@ static void recv_generator(char *fname,
1914 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1915 && link_stat(partialptr, &partial_st, 0) == 0
1916 @@ -1189,7 +1245,7 @@ static void recv_generator(char *fname,
1917 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1918 fname, fnamecmpbuf);
1920 - st.st_size = fuzzy_file->length;
1921 + sx.st.st_size = fuzzy_file->length;
1923 fnamecmp = fnamecmpbuf;
1924 fnamecmp_type = FNAMECMP_FUZZY;
1925 @@ -1198,7 +1254,7 @@ static void recv_generator(char *fname,
1928 if (preserve_hard_links && file->link_u.links
1929 - && hard_link_check(file, ndx, fname, statret, &st,
1930 + && hard_link_check(file, ndx, fname, statret, &sx,
1931 itemizing, code, HL_SKIP))
1933 if (stat_errno == ENOENT)
1934 @@ -1208,39 +1264,52 @@ static void recv_generator(char *fname,
1938 - if (append_mode && st.st_size > file->length)
1939 + if (append_mode && sx.st.st_size > file->length)
1942 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1944 else if (fnamecmp_type == FNAMECMP_FUZZY)
1946 - else if (unchanged_file(fnamecmp, file, &st)) {
1947 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1949 do_unlink(partialptr);
1950 handle_partial_dir(partialptr, PDIR_DELETE);
1953 - itemize(file, ndx, real_ret, &real_st,
1954 +#ifdef SUPPORT_ACLS
1955 + if (preserve_acls && real_ret == 0)
1956 + get_acl(fnamecmp, &real_sx);
1958 + itemize(file, ndx, real_ret, &real_sx,
1960 +#ifdef SUPPORT_ACLS
1961 + if (preserve_acls) {
1962 + if (fnamecmp_type == FNAMECMP_FNAME) {
1963 + sx.acc_acl = real_sx.acc_acl;
1964 + sx.def_acl = real_sx.def_acl;
1966 + free_acl(&real_sx);
1970 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1971 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1972 if (preserve_hard_links && file->link_u.links)
1973 hard_link_cluster(file, ndx, itemizing, code);
1974 if (remove_source_files != 1)
1977 return_with_success:
1980 SIVAL(numbuf, 0, ndx);
1981 send_msg(MSG_SUCCESS, numbuf, 4);
1990 + sx.st = partial_st;
1991 fnamecmp = partialptr;
1992 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
1994 @@ -1264,17 +1333,21 @@ static void recv_generator(char *fname,
1996 /* pretend the file didn't exist */
1997 if (preserve_hard_links && file->link_u.links
1998 - && hard_link_check(file, ndx, fname, statret, &st,
1999 + && hard_link_check(file, ndx, fname, statret, &sx,
2000 itemizing, code, HL_SKIP))
2003 statret = real_ret = -1;
2004 +#ifdef SUPPORT_ACLS
2005 + if (preserve_acls && ACL_READY(sx))
2011 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2012 if (!(backupptr = get_backup_name(fname))) {
2017 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2019 @@ -1285,7 +1358,7 @@ static void recv_generator(char *fname,
2020 full_fname(backupptr));
2026 if ((f_copy = do_open(backupptr,
2027 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2028 @@ -1293,14 +1366,14 @@ static void recv_generator(char *fname,
2029 full_fname(backupptr));
2035 fnamecmp_type = FNAMECMP_BACKUP;
2039 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2040 - fnamecmp, (double)st.st_size);
2041 + fnamecmp, (double)sx.st.st_size);
2045 @@ -1318,24 +1391,32 @@ static void recv_generator(char *fname,
2046 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2047 if (fnamecmp_type == FNAMECMP_FUZZY)
2048 iflags |= ITEM_XNAME_FOLLOWS;
2049 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2050 +#ifdef SUPPORT_ACLS
2051 + if (preserve_acls && real_ret == 0)
2052 + get_acl(fnamecmp, &real_sx);
2054 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2055 fuzzy_file ? fuzzy_file->basename : NULL);
2056 +#ifdef SUPPORT_ACLS
2057 + if (preserve_acls)
2058 + free_acl(&real_sx);
2063 if (preserve_hard_links && file->link_u.links)
2064 hard_link_cluster(file, ndx, itemizing, code);
2072 if (statret != 0 || whole_file) {
2073 write_sum_head(f_out, NULL);
2078 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2079 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2083 @@ -1348,6 +1429,13 @@ static void recv_generator(char *fname,
2089 +#ifdef SUPPORT_ACLS
2090 + if (preserve_acls)
2096 void generate_files(int f_out, struct file_list *flist, char *local_name)
2097 @@ -1407,6 +1495,8 @@ void generate_files(int f_out, struct fi
2098 * notice that and let us know via the redo pipe (or its closing). */
2101 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2103 for (i = 0; i < flist->count; i++) {
2104 struct file_struct *file = flist->files[i];
2110 extern int do_xfers;
2111 extern int link_dest;
2112 +extern int preserve_acls;
2113 extern int make_backups;
2114 extern int remove_source_files;
2115 extern int stdout_format_has_i;
2116 @@ -147,15 +148,19 @@ void init_hard_links(void)
2118 #ifdef SUPPORT_HARD_LINKS
2119 static int maybe_hard_link(struct file_struct *file, int ndx,
2120 - char *fname, int statret, STRUCT_STAT *st,
2121 + char *fname, int statret, statx *sxp,
2122 char *toname, STRUCT_STAT *to_st,
2123 int itemizing, enum logcode code)
2126 - if (st->st_dev == to_st->st_dev
2127 - && st->st_ino == to_st->st_ino) {
2128 + if (sxp->st.st_dev == to_st->st_dev
2129 + && sxp->st.st_ino == to_st->st_ino) {
2131 - itemize(file, ndx, statret, st,
2132 +#ifdef SUPPORT_ACLS
2133 + if (preserve_acls && !ACL_READY(*sxp))
2134 + get_acl(fname, sxp);
2136 + itemize(file, ndx, statret, sxp,
2137 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2140 @@ -170,13 +175,13 @@ static int maybe_hard_link(struct file_s
2144 - return hard_link_one(file, ndx, fname, statret, st, toname,
2145 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2146 0, itemizing, code);
2150 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2151 - int statret, STRUCT_STAT *st, int itemizing,
2152 + int statret, statx *sxp, int itemizing,
2153 enum logcode code, int skip)
2155 #ifdef SUPPORT_HARD_LINKS
2156 @@ -217,7 +222,7 @@ int hard_link_check(struct file_struct *
2157 || st2.st_ino != st3.st_ino)
2162 if (verbose < 2 || !stdout_format_has_i) {
2165 @@ -227,12 +232,16 @@ int hard_link_check(struct file_struct *
2166 if (!unchanged_file(cmpbuf, file, &st3))
2170 - if (unchanged_attrs(file, &st3))
2172 +#ifdef SUPPORT_ACLS
2173 + if (preserve_acls)
2174 + get_acl(cmpbuf, sxp);
2176 + if (unchanged_attrs(file, sxp))
2178 } while (basis_dir[++j] != NULL);
2180 - maybe_hard_link(file, ndx, fname, statret, st,
2181 + maybe_hard_link(file, ndx, fname, statret, sxp,
2182 toname, &st2, itemizing, code);
2183 if (remove_source_files == 1 && do_xfers) {
2185 @@ -250,7 +259,7 @@ int hard_link_check(struct file_struct *
2187 #ifdef SUPPORT_HARD_LINKS
2188 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2189 - int statret, STRUCT_STAT *st, char *toname, int terse,
2190 + int statret, statx *sxp, char *toname, int terse,
2191 int itemizing, enum logcode code)
2193 if (do_link(toname, fname)) {
2194 @@ -266,7 +275,11 @@ int hard_link_one(struct file_struct *fi
2198 - itemize(file, ndx, statret, st,
2199 +#ifdef SUPPORT_ACLS
2200 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2201 + get_acl(fname, sxp);
2203 + itemize(file, ndx, statret, sxp,
2204 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2205 terse ? "" : toname);
2207 @@ -283,11 +296,12 @@ void hard_link_cluster(struct file_struc
2208 #ifdef SUPPORT_HARD_LINKS
2209 char hlink1[MAXPATHLEN];
2211 - STRUCT_STAT st1, st2;
2214 int statret, ndx = master;
2216 file->F_HLINDEX = FINISHED_LINK;
2217 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2218 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2220 if (!(file->flags & FLAG_HLINK_TOL)) {
2221 while (!(file->flags & FLAG_HLINK_EOL)) {
2222 @@ -301,9 +315,13 @@ void hard_link_cluster(struct file_struc
2223 if (file->F_HLINDEX != SKIPPED_LINK)
2225 hlink2 = f_name(file, NULL);
2226 - statret = link_stat(hlink2, &st2, 0);
2227 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2228 - hlink1, &st1, itemizing, code);
2229 + statret = link_stat(hlink2, &sx.st, 0);
2230 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2231 + hlink1, &st, itemizing, code);
2232 +#ifdef SUPPORT_ACLS
2233 + if (preserve_acls)
2236 if (remove_source_files == 1 && do_xfers) {
2238 SIVAL(numbuf, 0, ndx);
2239 --- old/lib/sysacls.c
2240 +++ new/lib/sysacls.c
2243 + Unix SMB/CIFS implementation.
2244 + Samba system utilities for ACL support.
2245 + Copyright (C) Jeremy Allison 2000.
2247 + This program is free software; you can redistribute it and/or modify
2248 + it under the terms of the GNU General Public License as published by
2249 + the Free Software Foundation; either version 2 of the License, or
2250 + (at your option) any later version.
2252 + This program is distributed in the hope that it will be useful,
2253 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2254 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2255 + GNU General Public License for more details.
2257 + You should have received a copy of the GNU General Public License
2258 + along with this program; if not, write to the Free Software
2259 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2263 +#include "sysacls.h" /****** ADDED ******/
2265 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2271 +void SAFE_FREE(void *mem)
2277 +char *uidtoname(uid_t uid)
2279 + static char idbuf[12];
2280 + struct passwd *pw;
2282 + if ((pw = getpwuid(uid)) == NULL) {
2283 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2286 + return pw->pw_name;
2288 +/****** EXTRAS -- END ******/
2291 + This file wraps all differing system ACL interfaces into a consistent
2292 + one based on the POSIX interface. It also returns the correct errors
2293 + for older UNIX systems that don't support ACLs.
2295 + The interfaces that each ACL implementation must support are as follows :
2297 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2298 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2299 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2300 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2301 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2302 + SMB_ACL_T sys_acl_get_fd(int fd)
2303 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2304 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2305 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2306 + SMB_ACL_T sys_acl_init( int count)
2307 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2308 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2309 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2310 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2311 + int sys_acl_valid( SMB_ACL_T theacl )
2312 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2313 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2314 + int sys_acl_delete_def_file(const char *path)
2316 + This next one is not POSIX complient - but we *have* to have it !
2317 + More POSIX braindamage.
2319 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2321 + The generic POSIX free is the following call. We split this into
2322 + several different free functions as we may need to add tag info
2323 + to structures when emulating the POSIX interface.
2325 + int sys_acl_free( void *obj_p)
2327 + The calls we actually use are :
2329 + int sys_acl_free_text(char *text) - free acl_to_text
2330 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2331 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2335 +#if defined(HAVE_POSIX_ACLS)
2337 +/* Identity mapping - easy. */
2339 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2341 + return acl_get_entry( the_acl, entry_id, entry_p);
2344 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2346 + return acl_get_tag_type( entry_d, tag_type_p);
2349 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2351 + return acl_get_permset( entry_d, permset_p);
2354 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2356 + return acl_get_qualifier( entry_d);
2359 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2361 + return acl_get_file( path_p, type);
2364 +SMB_ACL_T sys_acl_get_fd(int fd)
2366 + return acl_get_fd(fd);
2369 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2371 + return acl_clear_perms(permset);
2374 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2376 + return acl_add_perm(permset, perm);
2379 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2381 +#if defined(HAVE_ACL_GET_PERM_NP)
2383 + * Required for TrustedBSD-based ACL implementations where
2384 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2387 + return acl_get_perm_np(permset, perm);
2389 + return acl_get_perm(permset, perm);
2393 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2395 + return acl_to_text( the_acl, plen);
2398 +SMB_ACL_T sys_acl_init( int count)
2400 + return acl_init(count);
2403 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2405 + return acl_create_entry(pacl, pentry);
2408 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2410 + return acl_set_tag_type(entry, tagtype);
2413 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2415 + return acl_set_qualifier(entry, qual);
2418 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2420 + return acl_set_permset(entry, permset);
2423 +int sys_acl_valid( SMB_ACL_T theacl )
2425 + return acl_valid(theacl);
2428 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2430 + return acl_set_file(name, acltype, theacl);
2433 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2435 + return acl_set_fd(fd, theacl);
2438 +int sys_acl_delete_def_file(const char *name)
2440 + return acl_delete_def_file(name);
2443 +int sys_acl_free_text(char *text)
2445 + return acl_free(text);
2448 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2450 + return acl_free(the_acl);
2453 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2455 + return acl_free(qual);
2458 +#elif defined(HAVE_TRU64_ACLS)
2460 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2461 + * is based on Draft 13 of the POSIX spec which is
2462 + * slightly different from the Draft 16 interface.
2464 + * Also, some of the permset manipulation functions
2465 + * such as acl_clear_perm() and acl_add_perm() appear
2466 + * to be broken on Tru64 so we have to manipulate
2467 + * the permission bits in the permset directly.
2469 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2471 + SMB_ACL_ENTRY_T entry;
2473 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2478 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2483 + return errno ? -1 : 0;
2486 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2488 + return acl_get_tag_type( entry_d, tag_type_p);
2491 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2493 + return acl_get_permset( entry_d, permset_p);
2496 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2498 + return acl_get_qualifier( entry_d);
2501 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2503 + return acl_get_file((char *)path_p, type);
2506 +SMB_ACL_T sys_acl_get_fd(int fd)
2508 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2511 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2513 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2518 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2520 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2525 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2530 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2532 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2535 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2537 + return acl_to_text( the_acl, plen);
2540 +SMB_ACL_T sys_acl_init( int count)
2542 + return acl_init(count);
2545 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2547 + SMB_ACL_ENTRY_T entry;
2549 + if ((entry = acl_create_entry(pacl)) == NULL) {
2557 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2559 + return acl_set_tag_type(entry, tagtype);
2562 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2564 + return acl_set_qualifier(entry, qual);
2567 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2569 + return acl_set_permset(entry, permset);
2572 +int sys_acl_valid( SMB_ACL_T theacl )
2574 + acl_entry_t entry;
2576 + return acl_valid(theacl, &entry);
2579 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2581 + return acl_set_file((char *)name, acltype, theacl);
2584 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2586 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2589 +int sys_acl_delete_def_file(const char *name)
2591 + return acl_delete_def_file((char *)name);
2594 +int sys_acl_free_text(char *text)
2597 + * (void) cast and explicit return 0 are for DEC UNIX
2598 + * which just #defines acl_free_text() to be free()
2600 + (void) acl_free_text(text);
2604 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2606 + return acl_free(the_acl);
2609 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2611 + return acl_free_qualifier(qual, tagtype);
2614 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2617 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2618 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2622 + * Note that while this code implements sufficient functionality
2623 + * to support the sys_acl_* interfaces it does not provide all
2624 + * of the semantics of the POSIX ACL interfaces.
2626 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2627 + * from a call to sys_acl_get_entry() should not be assumed to be
2628 + * valid after calling any of the following functions, which may
2629 + * reorder the entries in the ACL.
2632 + * sys_acl_set_file()
2633 + * sys_acl_set_fd()
2637 + * The only difference between Solaris and UnixWare / OpenUNIX is
2638 + * that the #defines for the ACL operations have different names
2640 +#if defined(HAVE_UNIXWARE_ACLS)
2642 +#define SETACL ACL_SET
2643 +#define GETACL ACL_GET
2644 +#define GETACLCNT ACL_CNT
2649 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2651 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2656 + if (entry_p == NULL) {
2661 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2665 + if (acl_d->next < 0) {
2670 + if (acl_d->next >= acl_d->count) {
2674 + *entry_p = &acl_d->acl[acl_d->next++];
2679 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2681 + *type_p = entry_d->a_type;
2686 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2688 + *permset_p = &entry_d->a_perm;
2693 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2695 + if (entry_d->a_type != SMB_ACL_USER
2696 + && entry_d->a_type != SMB_ACL_GROUP) {
2701 + return &entry_d->a_id;
2705 + * There is no way of knowing what size the ACL returned by
2706 + * GETACL will be unless you first call GETACLCNT which means
2707 + * making an additional system call.
2709 + * In the hope of avoiding the cost of the additional system
2710 + * call in most cases, we initially allocate enough space for
2711 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2712 + * be too small then we use GETACLCNT to find out the actual
2713 + * size, reallocate the ACL buffer, and then call GETACL again.
2716 +#define INITIAL_ACL_SIZE 16
2718 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2721 + int count; /* # of ACL entries allocated */
2722 + int naccess; /* # of access ACL entries */
2723 + int ndefault; /* # of default ACL entries */
2725 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2730 + count = INITIAL_ACL_SIZE;
2731 + if ((acl_d = sys_acl_init(count)) == NULL) {
2736 + * If there isn't enough space for the ACL entries we use
2737 + * GETACLCNT to determine the actual number of ACL entries
2738 + * reallocate and try again. This is in a loop because it
2739 + * is possible that someone else could modify the ACL and
2740 + * increase the number of entries between the call to
2741 + * GETACLCNT and the call to GETACL.
2743 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2744 + && errno == ENOSPC) {
2746 + sys_acl_free_acl(acl_d);
2748 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2752 + if ((acl_d = sys_acl_init(count)) == NULL) {
2758 + sys_acl_free_acl(acl_d);
2763 + * calculate the number of access and default ACL entries
2765 + * Note: we assume that the acl() system call returned a
2766 + * well formed ACL which is sorted so that all of the
2767 + * access ACL entries preceed any default ACL entries
2769 + for (naccess = 0; naccess < count; naccess++) {
2770 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2773 + ndefault = count - naccess;
2776 + * if the caller wants the default ACL we have to copy
2777 + * the entries down to the start of the acl[] buffer
2778 + * and mask out the ACL_DEFAULT flag from the type field
2780 + if (type == SMB_ACL_TYPE_DEFAULT) {
2783 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2784 + acl_d->acl[i] = acl_d->acl[j];
2785 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2788 + acl_d->count = ndefault;
2790 + acl_d->count = naccess;
2796 +SMB_ACL_T sys_acl_get_fd(int fd)
2799 + int count; /* # of ACL entries allocated */
2800 + int naccess; /* # of access ACL entries */
2802 + count = INITIAL_ACL_SIZE;
2803 + if ((acl_d = sys_acl_init(count)) == NULL) {
2807 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2808 + && errno == ENOSPC) {
2810 + sys_acl_free_acl(acl_d);
2812 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2816 + if ((acl_d = sys_acl_init(count)) == NULL) {
2822 + sys_acl_free_acl(acl_d);
2827 + * calculate the number of access ACL entries
2829 + for (naccess = 0; naccess < count; naccess++) {
2830 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2834 + acl_d->count = naccess;
2839 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2846 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2848 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2849 + && perm != SMB_ACL_EXECUTE) {
2854 + if (permset_d == NULL) {
2859 + *permset_d |= perm;
2864 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2866 + return *permset_d & perm;
2869 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2876 + * use an initial estimate of 20 bytes per ACL entry
2877 + * when allocating memory for the text representation
2881 + maxlen = 20 * acl_d->count;
2882 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2887 + for (i = 0; i < acl_d->count; i++) {
2888 + struct acl *ap = &acl_d->acl[i];
2897 + switch (ap->a_type) {
2899 + * for debugging purposes it's probably more
2900 + * useful to dump unknown tag types rather
2901 + * than just returning an error
2904 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2907 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2912 + case SMB_ACL_USER:
2913 + id = uidtoname(ap->a_id);
2914 + case SMB_ACL_USER_OBJ:
2918 + case SMB_ACL_GROUP:
2919 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2920 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2926 + case SMB_ACL_GROUP_OBJ:
2930 + case SMB_ACL_OTHER:
2934 + case SMB_ACL_MASK:
2940 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2941 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2942 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2945 + /* <tag> : <qualifier> : rwx \n \0 */
2946 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2949 + * If this entry would overflow the buffer
2950 + * allocate enough additional memory for this
2951 + * entry and an estimate of another 20 bytes
2952 + * for each entry still to be processed
2954 + if ((len + nbytes) > maxlen) {
2955 + char *oldtext = text;
2957 + maxlen += nbytes + 20 * (acl_d->count - i);
2959 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2960 + SAFE_FREE(oldtext);
2966 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2967 + len += nbytes - 1;
2976 +SMB_ACL_T sys_acl_init(int count)
2986 + * note that since the definition of the structure pointed
2987 + * to by the SMB_ACL_T includes the first element of the
2988 + * acl[] array, this actually allocates an ACL with room
2989 + * for (count+1) entries
2991 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2996 + a->size = count + 1;
3004 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3007 + SMB_ACL_ENTRY_T entry_d;
3009 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3014 + if (acl_d->count >= acl_d->size) {
3019 + entry_d = &acl_d->acl[acl_d->count++];
3020 + entry_d->a_type = 0;
3021 + entry_d->a_id = -1;
3022 + entry_d->a_perm = 0;
3023 + *entry_p = entry_d;
3028 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3030 + switch (tag_type) {
3031 + case SMB_ACL_USER:
3032 + case SMB_ACL_USER_OBJ:
3033 + case SMB_ACL_GROUP:
3034 + case SMB_ACL_GROUP_OBJ:
3035 + case SMB_ACL_OTHER:
3036 + case SMB_ACL_MASK:
3037 + entry_d->a_type = tag_type;
3047 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3049 + if (entry_d->a_type != SMB_ACL_GROUP
3050 + && entry_d->a_type != SMB_ACL_USER) {
3055 + entry_d->a_id = *((id_t *)qual_p);
3060 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3062 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3066 + entry_d->a_perm = *permset_d;
3072 + * sort the ACL and check it for validity
3074 + * if it's a minimal ACL with only 4 entries then we
3075 + * need to recalculate the mask permissions to make
3076 + * sure that they are the same as the GROUP_OBJ
3077 + * permissions as required by the UnixWare acl() system call.
3079 + * (note: since POSIX allows minimal ACLs which only contain
3080 + * 3 entries - ie there is no mask entry - we should, in theory,
3081 + * check for this and add a mask entry if necessary - however
3082 + * we "know" that the caller of this interface always specifies
3083 + * a mask so, in practice "this never happens" (tm) - if it *does*
3084 + * happen aclsort() will fail and return an error and someone will
3085 + * have to fix it ...)
3088 +static int acl_sort(SMB_ACL_T acl_d)
3090 + int fixmask = (acl_d->count <= 4);
3092 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3099 +int sys_acl_valid(SMB_ACL_T acl_d)
3101 + return acl_sort(acl_d);
3104 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3107 + struct acl *acl_p;
3109 + struct acl *acl_buf = NULL;
3112 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3117 + if (acl_sort(acl_d) != 0) {
3121 + acl_p = &acl_d->acl[0];
3122 + acl_count = acl_d->count;
3125 + * if it's a directory there is extra work to do
3126 + * since the acl() system call will replace both
3127 + * the access ACLs and the default ACLs (if any)
3129 + if (stat(name, &s) != 0) {
3132 + if (S_ISDIR(s.st_mode)) {
3133 + SMB_ACL_T acc_acl;
3134 + SMB_ACL_T def_acl;
3135 + SMB_ACL_T tmp_acl;
3138 + if (type == SMB_ACL_TYPE_ACCESS) {
3140 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3144 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3147 + if (tmp_acl == NULL) {
3152 + * allocate a temporary buffer for the complete ACL
3154 + acl_count = acc_acl->count + def_acl->count;
3155 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3157 + if (acl_buf == NULL) {
3158 + sys_acl_free_acl(tmp_acl);
3164 + * copy the access control and default entries into the buffer
3166 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3167 + acc_acl->count * sizeof(acl_buf[0]));
3169 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3170 + def_acl->count * sizeof(acl_buf[0]));
3173 + * set the ACL_DEFAULT flag on the default entries
3175 + for (i = acc_acl->count; i < acl_count; i++) {
3176 + acl_buf[i].a_type |= ACL_DEFAULT;
3179 + sys_acl_free_acl(tmp_acl);
3181 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3186 + ret = acl(name, SETACL, acl_count, acl_p);
3188 + SAFE_FREE(acl_buf);
3193 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3195 + if (acl_sort(acl_d) != 0) {
3199 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3202 +int sys_acl_delete_def_file(const char *path)
3208 + * fetching the access ACL and rewriting it has
3209 + * the effect of deleting the default ACL
3211 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3215 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3217 + sys_acl_free_acl(acl_d);
3222 +int sys_acl_free_text(char *text)
3228 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3234 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3239 +#elif defined(HAVE_HPUX_ACLS)
3243 + * Based on the Solaris/SCO code - with modifications.
3247 + * Note that while this code implements sufficient functionality
3248 + * to support the sys_acl_* interfaces it does not provide all
3249 + * of the semantics of the POSIX ACL interfaces.
3251 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3252 + * from a call to sys_acl_get_entry() should not be assumed to be
3253 + * valid after calling any of the following functions, which may
3254 + * reorder the entries in the ACL.
3257 + * sys_acl_set_file()
3258 + * sys_acl_set_fd()
3261 +/* This checks if the POSIX ACL system call is defined */
3262 +/* which basically corresponds to whether JFS 3.3 or */
3263 +/* higher is installed. If acl() was called when it */
3264 +/* isn't defined, it causes the process to core dump */
3265 +/* so it is important to check this and avoid acl() */
3266 +/* calls if it isn't there. */
3268 +static BOOL hpux_acl_call_presence(void)
3271 + shl_t handle = NULL;
3274 + static BOOL already_checked=0;
3276 + if(already_checked)
3280 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3282 + if(ret_val != 0) {
3283 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3284 + ret_val, errno, strerror(errno)));
3285 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3289 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3291 + already_checked = True;
3295 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3297 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3302 + if (entry_p == NULL) {
3307 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3311 + if (acl_d->next < 0) {
3316 + if (acl_d->next >= acl_d->count) {
3320 + *entry_p = &acl_d->acl[acl_d->next++];
3325 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3327 + *type_p = entry_d->a_type;
3332 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3334 + *permset_p = &entry_d->a_perm;
3339 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3341 + if (entry_d->a_type != SMB_ACL_USER
3342 + && entry_d->a_type != SMB_ACL_GROUP) {
3347 + return &entry_d->a_id;
3351 + * There is no way of knowing what size the ACL returned by
3352 + * ACL_GET will be unless you first call ACL_CNT which means
3353 + * making an additional system call.
3355 + * In the hope of avoiding the cost of the additional system
3356 + * call in most cases, we initially allocate enough space for
3357 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3358 + * be too small then we use ACL_CNT to find out the actual
3359 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3362 +#define INITIAL_ACL_SIZE 16
3364 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3367 + int count; /* # of ACL entries allocated */
3368 + int naccess; /* # of access ACL entries */
3369 + int ndefault; /* # of default ACL entries */
3371 + if(hpux_acl_call_presence() == False) {
3372 + /* Looks like we don't have the acl() system call on HPUX.
3373 + * May be the system doesn't have the latest version of JFS.
3378 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3383 + count = INITIAL_ACL_SIZE;
3384 + if ((acl_d = sys_acl_init(count)) == NULL) {
3389 + * If there isn't enough space for the ACL entries we use
3390 + * ACL_CNT to determine the actual number of ACL entries
3391 + * reallocate and try again. This is in a loop because it
3392 + * is possible that someone else could modify the ACL and
3393 + * increase the number of entries between the call to
3394 + * ACL_CNT and the call to ACL_GET.
3396 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3398 + sys_acl_free_acl(acl_d);
3400 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3404 + if ((acl_d = sys_acl_init(count)) == NULL) {
3410 + sys_acl_free_acl(acl_d);
3415 + * calculate the number of access and default ACL entries
3417 + * Note: we assume that the acl() system call returned a
3418 + * well formed ACL which is sorted so that all of the
3419 + * access ACL entries preceed any default ACL entries
3421 + for (naccess = 0; naccess < count; naccess++) {
3422 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3425 + ndefault = count - naccess;
3428 + * if the caller wants the default ACL we have to copy
3429 + * the entries down to the start of the acl[] buffer
3430 + * and mask out the ACL_DEFAULT flag from the type field
3432 + if (type == SMB_ACL_TYPE_DEFAULT) {
3435 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3436 + acl_d->acl[i] = acl_d->acl[j];
3437 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3440 + acl_d->count = ndefault;
3442 + acl_d->count = naccess;
3448 +SMB_ACL_T sys_acl_get_fd(int fd)
3451 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3454 + files_struct *fsp = file_find_fd(fd);
3456 + if (fsp == NULL) {
3462 + * We know we're in the same conn context. So we
3463 + * can use the relative path.
3466 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3469 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3476 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3478 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3479 + && perm != SMB_ACL_EXECUTE) {
3484 + if (permset_d == NULL) {
3489 + *permset_d |= perm;
3494 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3496 + return *permset_d & perm;
3499 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3506 + * use an initial estimate of 20 bytes per ACL entry
3507 + * when allocating memory for the text representation
3511 + maxlen = 20 * acl_d->count;
3512 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3517 + for (i = 0; i < acl_d->count; i++) {
3518 + struct acl *ap = &acl_d->acl[i];
3527 + switch (ap->a_type) {
3529 + * for debugging purposes it's probably more
3530 + * useful to dump unknown tag types rather
3531 + * than just returning an error
3534 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3537 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3542 + case SMB_ACL_USER:
3543 + id = uidtoname(ap->a_id);
3544 + case SMB_ACL_USER_OBJ:
3548 + case SMB_ACL_GROUP:
3549 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3550 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3556 + case SMB_ACL_GROUP_OBJ:
3560 + case SMB_ACL_OTHER:
3564 + case SMB_ACL_MASK:
3570 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3571 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3572 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3575 + /* <tag> : <qualifier> : rwx \n \0 */
3576 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3579 + * If this entry would overflow the buffer
3580 + * allocate enough additional memory for this
3581 + * entry and an estimate of another 20 bytes
3582 + * for each entry still to be processed
3584 + if ((len + nbytes) > maxlen) {
3585 + char *oldtext = text;
3587 + maxlen += nbytes + 20 * (acl_d->count - i);
3589 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3596 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3597 + len += nbytes - 1;
3606 +SMB_ACL_T sys_acl_init(int count)
3616 + * note that since the definition of the structure pointed
3617 + * to by the SMB_ACL_T includes the first element of the
3618 + * acl[] array, this actually allocates an ACL with room
3619 + * for (count+1) entries
3621 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3626 + a->size = count + 1;
3634 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3637 + SMB_ACL_ENTRY_T entry_d;
3639 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3644 + if (acl_d->count >= acl_d->size) {
3649 + entry_d = &acl_d->acl[acl_d->count++];
3650 + entry_d->a_type = 0;
3651 + entry_d->a_id = -1;
3652 + entry_d->a_perm = 0;
3653 + *entry_p = entry_d;
3658 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3660 + switch (tag_type) {
3661 + case SMB_ACL_USER:
3662 + case SMB_ACL_USER_OBJ:
3663 + case SMB_ACL_GROUP:
3664 + case SMB_ACL_GROUP_OBJ:
3665 + case SMB_ACL_OTHER:
3666 + case SMB_ACL_MASK:
3667 + entry_d->a_type = tag_type;
3677 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3679 + if (entry_d->a_type != SMB_ACL_GROUP
3680 + && entry_d->a_type != SMB_ACL_USER) {
3685 + entry_d->a_id = *((id_t *)qual_p);
3690 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3692 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3696 + entry_d->a_perm = *permset_d;
3701 +/* Structure to capture the count for each type of ACE. */
3703 +struct hpux_acl_types {
3707 + int n_def_user_obj;
3712 + int n_def_group_obj;
3716 + int n_def_other_obj;
3719 + int n_def_class_obj;
3721 + int n_illegal_obj;
3725 + * Counts the different number of objects in a given array of ACL
3729 + * acl_count - Count of ACLs in the array of ACL strucutres.
3730 + * aclp - Array of ACL structures.
3731 + * acl_type_count - Pointer to acl_types structure. Should already be
3735 + * acl_type_count - This structure is filled up with counts of various
3739 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3743 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3745 + for(i=0;i<acl_count;i++) {
3746 + switch(aclp[i].a_type) {
3748 + acl_type_count->n_user++;
3751 + acl_type_count->n_user_obj++;
3753 + case DEF_USER_OBJ:
3754 + acl_type_count->n_def_user_obj++;
3757 + acl_type_count->n_group++;
3760 + acl_type_count->n_group_obj++;
3762 + case DEF_GROUP_OBJ:
3763 + acl_type_count->n_def_group_obj++;
3766 + acl_type_count->n_other_obj++;
3768 + case DEF_OTHER_OBJ:
3769 + acl_type_count->n_def_other_obj++;
3772 + acl_type_count->n_class_obj++;
3774 + case DEF_CLASS_OBJ:
3775 + acl_type_count->n_def_class_obj++;
3778 + acl_type_count->n_def_user++;
3781 + acl_type_count->n_def_group++;
3784 + acl_type_count->n_illegal_obj++;
3790 +/* swap_acl_entries: Swaps two ACL entries.
3792 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3795 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3797 + struct acl temp_acl;
3799 + temp_acl.a_type = aclp0->a_type;
3800 + temp_acl.a_id = aclp0->a_id;
3801 + temp_acl.a_perm = aclp0->a_perm;
3803 + aclp0->a_type = aclp1->a_type;
3804 + aclp0->a_id = aclp1->a_id;
3805 + aclp0->a_perm = aclp1->a_perm;
3807 + aclp1->a_type = temp_acl.a_type;
3808 + aclp1->a_id = temp_acl.a_id;
3809 + aclp1->a_perm = temp_acl.a_perm;
3812 +/* prohibited_duplicate_type
3813 + * Identifies if given ACL type can have duplicate entries or
3816 + * Inputs: acl_type - ACL Type.
3822 + * True - If the ACL type matches any of the prohibited types.
3823 + * False - If the ACL type doesn't match any of the prohibited types.
3826 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3828 + switch(acl_type) {
3839 +/* get_needed_class_perm
3840 + * Returns the permissions of a ACL structure only if the ACL
3841 + * type matches one of the pre-determined types for computing
3842 + * CLASS_OBJ permissions.
3844 + * Inputs: aclp - Pointer to ACL structure.
3847 +static int hpux_get_needed_class_perm(struct acl *aclp)
3849 + switch(aclp->a_type) {
3853 + case DEF_USER_OBJ:
3855 + case DEF_GROUP_OBJ:
3857 + case DEF_CLASS_OBJ:
3858 + case DEF_OTHER_OBJ:
3859 + return aclp->a_perm;
3865 +/* acl_sort for HPUX.
3866 + * Sorts the array of ACL structures as per the description in
3867 + * aclsort man page. Refer to aclsort man page for more details
3871 + * acl_count - Count of ACLs in the array of ACL structures.
3872 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3874 + * aclp - Array of ACL structures.
3878 + * aclp - Sorted array of ACL structures.
3882 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3883 + * debug log in case of failure.
3886 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3888 +#if !defined(HAVE_HPUX_ACLSORT)
3890 + * The aclsort() system call is availabe on the latest HPUX General
3891 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3892 + * function. Because, we don't want to update to a new
3893 + * HPUX GR bundle just for aclsort() call.
3896 + struct hpux_acl_types acl_obj_count;
3897 + int n_class_obj_perm = 0;
3901 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3905 + if(aclp == NULL) {
3906 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3910 + /* Count different types of ACLs in the ACLs array */
3912 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3914 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3915 + * CLASS_OBJ and OTHER_OBJ
3918 + if( (acl_obj_count.n_user_obj != 1) ||
3919 + (acl_obj_count.n_group_obj != 1) ||
3920 + (acl_obj_count.n_class_obj != 1) ||
3921 + (acl_obj_count.n_other_obj != 1)
3923 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3924 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3928 + /* If any of the default objects are present, there should be only
3929 + * one of them each.
3932 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3933 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3934 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3935 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3939 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3942 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3943 + * same ACL type, sort by ACL id.
3945 + * I am using the trival kind of sorting method here because, performance isn't
3946 + * really effected by the ACLs feature. More over there aren't going to be more
3947 + * than 17 entries on HPUX.
3950 + for(i=0; i<acl_count;i++) {
3951 + for (j=i+1; j<acl_count; j++) {
3952 + if( aclp[i].a_type > aclp[j].a_type ) {
3953 + /* ACL entries out of order, swap them */
3955 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3957 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3959 + /* ACL entries of same type, sort by id */
3961 + if(aclp[i].a_id > aclp[j].a_id) {
3962 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3963 + } else if (aclp[i].a_id == aclp[j].a_id) {
3964 + /* We have a duplicate entry. */
3965 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3966 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3967 + aclp[i].a_type, aclp[i].a_id));
3976 + /* set the class obj permissions to the computed one. */
3978 + int n_class_obj_index = -1;
3980 + for(i=0;i<acl_count;i++) {
3981 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3983 + if(aclp[i].a_type == CLASS_OBJ)
3984 + n_class_obj_index = i;
3986 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3991 + return aclsort(acl_count, calclass, aclp);
3996 + * sort the ACL and check it for validity
3998 + * if it's a minimal ACL with only 4 entries then we
3999 + * need to recalculate the mask permissions to make
4000 + * sure that they are the same as the GROUP_OBJ
4001 + * permissions as required by the UnixWare acl() system call.
4003 + * (note: since POSIX allows minimal ACLs which only contain
4004 + * 3 entries - ie there is no mask entry - we should, in theory,
4005 + * check for this and add a mask entry if necessary - however
4006 + * we "know" that the caller of this interface always specifies
4007 + * a mask so, in practice "this never happens" (tm) - if it *does*
4008 + * happen aclsort() will fail and return an error and someone will
4009 + * have to fix it ...)
4012 +static int acl_sort(SMB_ACL_T acl_d)
4014 + int fixmask = (acl_d->count <= 4);
4016 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4023 +int sys_acl_valid(SMB_ACL_T acl_d)
4025 + return acl_sort(acl_d);
4028 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4031 + struct acl *acl_p;
4033 + struct acl *acl_buf = NULL;
4036 + if(hpux_acl_call_presence() == False) {
4037 + /* Looks like we don't have the acl() system call on HPUX.
4038 + * May be the system doesn't have the latest version of JFS.
4044 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4049 + if (acl_sort(acl_d) != 0) {
4053 + acl_p = &acl_d->acl[0];
4054 + acl_count = acl_d->count;
4057 + * if it's a directory there is extra work to do
4058 + * since the acl() system call will replace both
4059 + * the access ACLs and the default ACLs (if any)
4061 + if (stat(name, &s) != 0) {
4064 + if (S_ISDIR(s.st_mode)) {
4065 + SMB_ACL_T acc_acl;
4066 + SMB_ACL_T def_acl;
4067 + SMB_ACL_T tmp_acl;
4070 + if (type == SMB_ACL_TYPE_ACCESS) {
4072 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4076 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4079 + if (tmp_acl == NULL) {
4084 + * allocate a temporary buffer for the complete ACL
4086 + acl_count = acc_acl->count + def_acl->count;
4087 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4089 + if (acl_buf == NULL) {
4090 + sys_acl_free_acl(tmp_acl);
4096 + * copy the access control and default entries into the buffer
4098 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4099 + acc_acl->count * sizeof(acl_buf[0]));
4101 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4102 + def_acl->count * sizeof(acl_buf[0]));
4105 + * set the ACL_DEFAULT flag on the default entries
4107 + for (i = acc_acl->count; i < acl_count; i++) {
4108 + acl_buf[i].a_type |= ACL_DEFAULT;
4111 + sys_acl_free_acl(tmp_acl);
4113 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4118 + ret = acl(name, ACL_SET, acl_count, acl_p);
4127 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4130 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4133 + files_struct *fsp = file_find_fd(fd);
4135 + if (fsp == NULL) {
4140 + if (acl_sort(acl_d) != 0) {
4145 + * We know we're in the same conn context. So we
4146 + * can use the relative path.
4149 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4152 +int sys_acl_delete_def_file(const char *path)
4158 + * fetching the access ACL and rewriting it has
4159 + * the effect of deleting the default ACL
4161 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4165 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4167 + sys_acl_free_acl(acl_d);
4172 +int sys_acl_free_text(char *text)
4178 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4184 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4189 +#elif defined(HAVE_IRIX_ACLS)
4191 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4193 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4198 + if (entry_p == NULL) {
4203 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4207 + if (acl_d->next < 0) {
4212 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4216 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4221 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4223 + *type_p = entry_d->ae_tag;
4228 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4230 + *permset_p = entry_d;
4235 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4237 + if (entry_d->ae_tag != SMB_ACL_USER
4238 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4243 + return &entry_d->ae_id;
4246 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4250 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4254 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4259 + a->freeaclp = True;
4263 +SMB_ACL_T sys_acl_get_fd(int fd)
4267 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4271 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4276 + a->freeaclp = True;
4280 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4282 + permset_d->ae_perm = 0;
4287 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4289 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4290 + && perm != SMB_ACL_EXECUTE) {
4295 + if (permset_d == NULL) {
4300 + permset_d->ae_perm |= perm;
4305 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4307 + return permset_d->ae_perm & perm;
4310 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4312 + return acl_to_text(acl_d->aclp, len_p);
4315 +SMB_ACL_T sys_acl_init(int count)
4324 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4330 + a->freeaclp = False;
4331 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4332 + a->aclp->acl_cnt = 0;
4338 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4341 + SMB_ACL_ENTRY_T entry_d;
4343 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4348 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4353 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4354 + entry_d->ae_tag = 0;
4355 + entry_d->ae_id = 0;
4356 + entry_d->ae_perm = 0;
4357 + *entry_p = entry_d;
4362 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4364 + switch (tag_type) {
4365 + case SMB_ACL_USER:
4366 + case SMB_ACL_USER_OBJ:
4367 + case SMB_ACL_GROUP:
4368 + case SMB_ACL_GROUP_OBJ:
4369 + case SMB_ACL_OTHER:
4370 + case SMB_ACL_MASK:
4371 + entry_d->ae_tag = tag_type;
4381 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4383 + if (entry_d->ae_tag != SMB_ACL_GROUP
4384 + && entry_d->ae_tag != SMB_ACL_USER) {
4389 + entry_d->ae_id = *((id_t *)qual_p);
4394 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4396 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4400 + entry_d->ae_perm = permset_d->ae_perm;
4405 +int sys_acl_valid(SMB_ACL_T acl_d)
4407 + return acl_valid(acl_d->aclp);
4410 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4412 + return acl_set_file(name, type, acl_d->aclp);
4415 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4417 + return acl_set_fd(fd, acl_d->aclp);
4420 +int sys_acl_delete_def_file(const char *name)
4422 + return acl_delete_def_file(name);
4425 +int sys_acl_free_text(char *text)
4427 + return acl_free(text);
4430 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4432 + if (acl_d->freeaclp) {
4433 + acl_free(acl_d->aclp);
4439 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4444 +#elif defined(HAVE_AIX_ACLS)
4446 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4448 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4450 + struct acl_entry_link *link;
4451 + struct new_acl_entry *entry;
4454 + DEBUG(10,("This is the count: %d\n",theacl->count));
4456 + /* Check if count was previously set to -1. *
4457 + * If it was, that means we reached the end *
4458 + * of the acl last time. */
4459 + if(theacl->count == -1)
4463 + /* To get to the next acl, traverse linked list until index *
4464 + * of acl matches the count we are keeping. This count is *
4465 + * incremented each time we return an acl entry. */
4467 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4468 + link = link->nextp;
4470 + entry = *entry_p = link->entryp;
4472 + DEBUG(10,("*entry_p is %d\n",entry_p));
4473 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4475 + /* Increment count */
4477 + if(link->nextp == NULL)
4478 + theacl->count = -1;
4483 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4485 + /* Initialize tag type */
4488 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4490 + /* Depending on what type of entry we have, *
4491 + * return tag type. */
4492 + switch(entry_d->ace_id->id_type) {
4494 + *tag_type_p = SMB_ACL_USER;
4497 + *tag_type_p = SMB_ACL_GROUP;
4500 + case SMB_ACL_USER_OBJ:
4501 + case SMB_ACL_GROUP_OBJ:
4502 + case SMB_ACL_OTHER:
4503 + *tag_type_p = entry_d->ace_id->id_type;
4513 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4515 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4516 + *permset_p = &entry_d->ace_access;
4517 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4518 + if(!(**permset_p & S_IXUSR) &&
4519 + !(**permset_p & S_IWUSR) &&
4520 + !(**permset_p & S_IRUSR) &&
4521 + (**permset_p != 0))
4524 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4528 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4530 + return(entry_d->ace_id->id_data);
4533 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4535 + struct acl *file_acl = (struct acl *)NULL;
4536 + struct acl_entry *acl_entry;
4537 + struct new_acl_entry *new_acl_entry;
4538 + struct ace_id *idp;
4539 + struct acl_entry_link *acl_entry_link;
4540 + struct acl_entry_link *acl_entry_link_head;
4545 + /* AIX has no DEFAULT */
4546 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4551 + /* Get the acl using statacl */
4553 + DEBUG(10,("Entering sys_acl_get_file\n"));
4554 + DEBUG(10,("path_p is %s\n",path_p));
4556 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4558 + if(file_acl == NULL) {
4560 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4564 + memset(file_acl,0,BUFSIZ);
4566 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4568 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4569 + SAFE_FREE(file_acl);
4573 + DEBUG(10,("Got facl and returned it\n"));
4575 + /* Point to the first acl entry in the acl */
4576 + acl_entry = file_acl->acl_ext;
4578 + /* Begin setting up the head of the linked list *
4579 + * that will be used for the storing the acl *
4580 + * in a way that is useful for the posix_acls.c *
4583 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4584 + if(acl_entry_link_head == NULL)
4587 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4588 + if(acl_entry_link->entryp == NULL) {
4589 + SAFE_FREE(file_acl);
4591 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4595 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4596 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4598 + /* Check if the extended acl bit is on. *
4599 + * If it isn't, do not show the *
4600 + * contents of the acl since AIX intends *
4601 + * the extended info to remain unused */
4603 + if(file_acl->acl_mode & S_IXACL){
4604 + /* while we are not pointing to the very end */
4605 + while(acl_entry < acl_last(file_acl)) {
4606 + /* before we malloc anything, make sure this is */
4607 + /* a valid acl entry and one that we want to map */
4608 + idp = id_nxt(acl_entry->ace_id);
4609 + if((acl_entry->ace_type == ACC_SPECIFY ||
4610 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4611 + acl_entry = acl_nxt(acl_entry);
4615 + idp = acl_entry->ace_id;
4617 + /* Check if this is the first entry in the linked list. *
4618 + * The first entry needs to keep prevp pointing to NULL *
4619 + * and already has entryp allocated. */
4621 + if(acl_entry_link_head->count != 0) {
4622 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4624 + if(acl_entry_link->nextp == NULL) {
4625 + SAFE_FREE(file_acl);
4627 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4631 + acl_entry_link->nextp->prevp = acl_entry_link;
4632 + acl_entry_link = acl_entry_link->nextp;
4633 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4634 + if(acl_entry_link->entryp == NULL) {
4635 + SAFE_FREE(file_acl);
4637 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4640 + acl_entry_link->nextp = NULL;
4643 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4645 + /* Don't really need this since all types are going *
4646 + * to be specified but, it's better than leaving it 0 */
4648 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4650 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4652 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4654 + /* The access in the acl entries must be left shifted by *
4655 + * three bites, because they will ultimately be compared *
4656 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4658 + switch(acl_entry->ace_type){
4661 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4662 + acl_entry_link->entryp->ace_access <<= 6;
4663 + acl_entry_link_head->count++;
4666 + /* Since there is no way to return a DENY acl entry *
4667 + * change to PERMIT and then shift. */
4668 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4669 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4670 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4671 + acl_entry_link->entryp->ace_access <<= 6;
4672 + acl_entry_link_head->count++;
4678 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4679 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4681 + acl_entry = acl_nxt(acl_entry);
4683 + } /* end of if enabled */
4685 + /* Since owner, group, other acl entries are not *
4686 + * part of the acl entries in an acl, they must *
4687 + * be dummied up to become part of the list. */
4689 + for( i = 1; i < 4; i++) {
4690 + DEBUG(10,("i is %d\n",i));
4691 + if(acl_entry_link_head->count != 0) {
4692 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4693 + if(acl_entry_link->nextp == NULL) {
4694 + SAFE_FREE(file_acl);
4696 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4700 + acl_entry_link->nextp->prevp = acl_entry_link;
4701 + acl_entry_link = acl_entry_link->nextp;
4702 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4703 + if(acl_entry_link->entryp == NULL) {
4704 + SAFE_FREE(file_acl);
4706 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4711 + acl_entry_link->nextp = NULL;
4713 + new_acl_entry = acl_entry_link->entryp;
4714 + idp = new_acl_entry->ace_id;
4716 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4717 + new_acl_entry->ace_type = ACC_PERMIT;
4718 + idp->id_len = sizeof(struct ace_id);
4719 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4720 + memset(idp->id_data,0,sizeof(uid_t));
4724 + new_acl_entry->ace_access = file_acl->g_access << 6;
4725 + idp->id_type = SMB_ACL_GROUP_OBJ;
4729 + new_acl_entry->ace_access = file_acl->o_access << 6;
4730 + idp->id_type = SMB_ACL_OTHER;
4734 + new_acl_entry->ace_access = file_acl->u_access << 6;
4735 + idp->id_type = SMB_ACL_USER_OBJ;
4743 + acl_entry_link_head->count++;
4744 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4747 + acl_entry_link_head->count = 0;
4748 + SAFE_FREE(file_acl);
4750 + return(acl_entry_link_head);
4753 +SMB_ACL_T sys_acl_get_fd(int fd)
4755 + struct acl *file_acl = (struct acl *)NULL;
4756 + struct acl_entry *acl_entry;
4757 + struct new_acl_entry *new_acl_entry;
4758 + struct ace_id *idp;
4759 + struct acl_entry_link *acl_entry_link;
4760 + struct acl_entry_link *acl_entry_link_head;
4765 + /* Get the acl using fstatacl */
4767 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4768 + DEBUG(10,("fd is %d\n",fd));
4769 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4771 + if(file_acl == NULL) {
4773 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4777 + memset(file_acl,0,BUFSIZ);
4779 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4781 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4782 + SAFE_FREE(file_acl);
4786 + DEBUG(10,("Got facl and returned it\n"));
4788 + /* Point to the first acl entry in the acl */
4790 + acl_entry = file_acl->acl_ext;
4791 + /* Begin setting up the head of the linked list *
4792 + * that will be used for the storing the acl *
4793 + * in a way that is useful for the posix_acls.c *
4796 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4797 + if(acl_entry_link_head == NULL){
4798 + SAFE_FREE(file_acl);
4802 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4804 + if(acl_entry_link->entryp == NULL) {
4806 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4807 + SAFE_FREE(file_acl);
4811 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4812 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4814 + /* Check if the extended acl bit is on. *
4815 + * If it isn't, do not show the *
4816 + * contents of the acl since AIX intends *
4817 + * the extended info to remain unused */
4819 + if(file_acl->acl_mode & S_IXACL){
4820 + /* while we are not pointing to the very end */
4821 + while(acl_entry < acl_last(file_acl)) {
4822 + /* before we malloc anything, make sure this is */
4823 + /* a valid acl entry and one that we want to map */
4825 + idp = id_nxt(acl_entry->ace_id);
4826 + if((acl_entry->ace_type == ACC_SPECIFY ||
4827 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4828 + acl_entry = acl_nxt(acl_entry);
4832 + idp = acl_entry->ace_id;
4834 + /* Check if this is the first entry in the linked list. *
4835 + * The first entry needs to keep prevp pointing to NULL *
4836 + * and already has entryp allocated. */
4838 + if(acl_entry_link_head->count != 0) {
4839 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4840 + if(acl_entry_link->nextp == NULL) {
4842 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4843 + SAFE_FREE(file_acl);
4846 + acl_entry_link->nextp->prevp = acl_entry_link;
4847 + acl_entry_link = acl_entry_link->nextp;
4848 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4849 + if(acl_entry_link->entryp == NULL) {
4851 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4852 + SAFE_FREE(file_acl);
4856 + acl_entry_link->nextp = NULL;
4859 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4861 + /* Don't really need this since all types are going *
4862 + * to be specified but, it's better than leaving it 0 */
4864 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4865 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4867 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4869 + /* The access in the acl entries must be left shifted by *
4870 + * three bites, because they will ultimately be compared *
4871 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4873 + switch(acl_entry->ace_type){
4876 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4877 + acl_entry_link->entryp->ace_access <<= 6;
4878 + acl_entry_link_head->count++;
4881 + /* Since there is no way to return a DENY acl entry *
4882 + * change to PERMIT and then shift. */
4883 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4884 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4885 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4886 + acl_entry_link->entryp->ace_access <<= 6;
4887 + acl_entry_link_head->count++;
4893 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4894 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4896 + acl_entry = acl_nxt(acl_entry);
4898 + } /* end of if enabled */
4900 + /* Since owner, group, other acl entries are not *
4901 + * part of the acl entries in an acl, they must *
4902 + * be dummied up to become part of the list. */
4904 + for( i = 1; i < 4; i++) {
4905 + DEBUG(10,("i is %d\n",i));
4906 + if(acl_entry_link_head->count != 0){
4907 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4908 + if(acl_entry_link->nextp == NULL) {
4910 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4911 + SAFE_FREE(file_acl);
4915 + acl_entry_link->nextp->prevp = acl_entry_link;
4916 + acl_entry_link = acl_entry_link->nextp;
4917 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4919 + if(acl_entry_link->entryp == NULL) {
4920 + SAFE_FREE(file_acl);
4922 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4927 + acl_entry_link->nextp = NULL;
4929 + new_acl_entry = acl_entry_link->entryp;
4930 + idp = new_acl_entry->ace_id;
4932 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4933 + new_acl_entry->ace_type = ACC_PERMIT;
4934 + idp->id_len = sizeof(struct ace_id);
4935 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4936 + memset(idp->id_data,0,sizeof(uid_t));
4940 + new_acl_entry->ace_access = file_acl->g_access << 6;
4941 + idp->id_type = SMB_ACL_GROUP_OBJ;
4945 + new_acl_entry->ace_access = file_acl->o_access << 6;
4946 + idp->id_type = SMB_ACL_OTHER;
4950 + new_acl_entry->ace_access = file_acl->u_access << 6;
4951 + idp->id_type = SMB_ACL_USER_OBJ;
4958 + acl_entry_link_head->count++;
4959 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4962 + acl_entry_link_head->count = 0;
4963 + SAFE_FREE(file_acl);
4965 + return(acl_entry_link_head);
4968 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4970 + *permset = *permset & ~0777;
4974 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4977 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4981 + DEBUG(10,("This is the permset now: %d\n",*permset));
4985 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4990 +SMB_ACL_T sys_acl_init( int count)
4992 + struct acl_entry_link *theacl = NULL;
4994 + DEBUG(10,("Entering sys_acl_init\n"));
4996 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4997 + if(theacl == NULL) {
4999 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5003 + theacl->count = 0;
5004 + theacl->nextp = NULL;
5005 + theacl->prevp = NULL;
5006 + theacl->entryp = NULL;
5007 + DEBUG(10,("Exiting sys_acl_init\n"));
5011 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5013 + struct acl_entry_link *theacl;
5014 + struct acl_entry_link *acl_entryp;
5015 + struct acl_entry_link *temp_entry;
5018 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5020 + theacl = acl_entryp = *pacl;
5022 + /* Get to the end of the acl before adding entry */
5024 + for(counting=0; counting < theacl->count; counting++){
5025 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5026 + temp_entry = acl_entryp;
5027 + acl_entryp = acl_entryp->nextp;
5030 + if(theacl->count != 0){
5031 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5032 + if(acl_entryp == NULL) {
5034 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5038 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5039 + acl_entryp->prevp = temp_entry;
5040 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5043 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5044 + if(*pentry == NULL) {
5046 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5050 + memset(*pentry,0,sizeof(struct new_acl_entry));
5051 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5052 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5053 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5054 + acl_entryp->nextp = NULL;
5056 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5060 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5062 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5063 + entry->ace_id->id_type = tagtype;
5064 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5065 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5068 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5070 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5071 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5072 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5076 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5078 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5079 + if(!(*permset & S_IXUSR) &&
5080 + !(*permset & S_IWUSR) &&
5081 + !(*permset & S_IRUSR) &&
5085 + entry->ace_access = *permset;
5086 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5087 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5091 +int sys_acl_valid( SMB_ACL_T theacl )
5094 + int group_obj = 0;
5095 + int other_obj = 0;
5096 + struct acl_entry_link *acl_entry;
5098 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5099 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5100 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5101 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5104 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5106 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5112 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5114 + struct acl_entry_link *acl_entry_link = NULL;
5115 + struct acl *file_acl = NULL;
5116 + struct acl *file_acl_temp = NULL;
5117 + struct acl_entry *acl_entry = NULL;
5118 + struct ace_id *ace_id = NULL;
5125 + DEBUG(10,("Entering sys_acl_set_file\n"));
5126 + DEBUG(10,("File name is %s\n",name));
5128 + /* AIX has no default ACL */
5129 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5132 + acl_length = BUFSIZ;
5133 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5135 + if(file_acl == NULL) {
5137 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5141 + memset(file_acl,0,BUFSIZ);
5143 + file_acl->acl_len = ACL_SIZ;
5144 + file_acl->acl_mode = S_IXACL;
5146 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5147 + acl_entry_link->entryp->ace_access >>= 6;
5148 + id_type = acl_entry_link->entryp->ace_id->id_type;
5151 + case SMB_ACL_USER_OBJ:
5152 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5154 + case SMB_ACL_GROUP_OBJ:
5155 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5157 + case SMB_ACL_OTHER:
5158 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5160 + case SMB_ACL_MASK:
5164 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5165 + acl_length += sizeof(struct acl_entry);
5166 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5167 + if(file_acl_temp == NULL) {
5168 + SAFE_FREE(file_acl);
5170 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5174 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5175 + SAFE_FREE(file_acl);
5176 + file_acl = file_acl_temp;
5179 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5180 + file_acl->acl_len += sizeof(struct acl_entry);
5181 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5182 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5184 + /* In order to use this, we'll need to wait until we can get denies */
5185 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5186 + acl_entry->ace_type = ACC_SPECIFY; */
5188 + acl_entry->ace_type = ACC_SPECIFY;
5190 + ace_id = acl_entry->ace_id;
5192 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5193 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5194 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5195 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5196 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5199 + rc = chacl(name,file_acl,file_acl->acl_len);
5200 + DEBUG(10,("errno is %d\n",errno));
5201 + DEBUG(10,("return code is %d\n",rc));
5202 + SAFE_FREE(file_acl);
5203 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5207 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5209 + struct acl_entry_link *acl_entry_link = NULL;
5210 + struct acl *file_acl = NULL;
5211 + struct acl *file_acl_temp = NULL;
5212 + struct acl_entry *acl_entry = NULL;
5213 + struct ace_id *ace_id = NULL;
5219 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5220 + acl_length = BUFSIZ;
5221 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5223 + if(file_acl == NULL) {
5225 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5229 + memset(file_acl,0,BUFSIZ);
5231 + file_acl->acl_len = ACL_SIZ;
5232 + file_acl->acl_mode = S_IXACL;
5234 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5235 + acl_entry_link->entryp->ace_access >>= 6;
5236 + id_type = acl_entry_link->entryp->ace_id->id_type;
5237 + DEBUG(10,("The id_type is %d\n",id_type));
5240 + case SMB_ACL_USER_OBJ:
5241 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5243 + case SMB_ACL_GROUP_OBJ:
5244 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5246 + case SMB_ACL_OTHER:
5247 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5249 + case SMB_ACL_MASK:
5253 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5254 + acl_length += sizeof(struct acl_entry);
5255 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5256 + if(file_acl_temp == NULL) {
5257 + SAFE_FREE(file_acl);
5259 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5263 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5264 + SAFE_FREE(file_acl);
5265 + file_acl = file_acl_temp;
5268 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5269 + file_acl->acl_len += sizeof(struct acl_entry);
5270 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5271 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5273 + /* In order to use this, we'll need to wait until we can get denies */
5274 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5275 + acl_entry->ace_type = ACC_SPECIFY; */
5277 + acl_entry->ace_type = ACC_SPECIFY;
5279 + ace_id = acl_entry->ace_id;
5281 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5282 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5283 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5284 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5285 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5288 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5289 + DEBUG(10,("errno is %d\n",errno));
5290 + DEBUG(10,("return code is %d\n",rc));
5291 + SAFE_FREE(file_acl);
5292 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5296 +int sys_acl_delete_def_file(const char *name)
5298 + /* AIX has no default ACL */
5302 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5304 + return(*permset & perm);
5307 +int sys_acl_free_text(char *text)
5312 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5314 + struct acl_entry_link *acl_entry_link;
5316 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5317 + SAFE_FREE(acl_entry_link->prevp->entryp);
5318 + SAFE_FREE(acl_entry_link->prevp);
5321 + SAFE_FREE(acl_entry_link->prevp->entryp);
5322 + SAFE_FREE(acl_entry_link->prevp);
5323 + SAFE_FREE(acl_entry_link->entryp);
5324 + SAFE_FREE(acl_entry_link);
5329 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5334 +#else /* No ACLs. */
5336 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5342 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5348 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5354 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5360 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5363 + return (SMB_ACL_T)NULL;
5366 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5369 + return (SMB_ACL_T)NULL;
5372 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5378 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5384 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5387 + return (permset & perm) ? 1 : 0;
5390 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5396 +int sys_acl_free_text(UNUSED(char *text))
5402 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5408 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5414 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5420 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5426 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5432 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5438 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5444 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5450 +int sys_acl_delete_def_file(UNUSED(const char *name))
5456 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5462 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5468 +#endif /* No ACLs. */
5470 +/************************************************************************
5471 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5473 +************************************************************************/
5475 +int no_acl_syscall_error(int err)
5477 +#if defined(ENOSYS)
5478 + if (err == ENOSYS) {
5482 +#if defined(ENOTSUP)
5483 + if (err == ENOTSUP) {
5489 --- old/lib/sysacls.h
5490 +++ new/lib/sysacls.h
5492 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5493 +#include <sys/acl.h>
5495 +#include "smb_acls.h"
5497 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5498 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5499 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5500 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5501 +#define slprintf snprintf
5503 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5504 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5505 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5506 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5507 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5508 +SMB_ACL_T sys_acl_get_fd(int fd);
5509 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5510 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5511 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5512 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5513 +SMB_ACL_T sys_acl_init(int count);
5514 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5515 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5516 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5517 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5518 +int sys_acl_valid(SMB_ACL_T theacl);
5519 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5520 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5521 +int sys_acl_delete_def_file(const char *name);
5522 +int sys_acl_free_text(char *text);
5523 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5524 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5527 @@ -606,8 +606,10 @@ static void log_formatted(enum logcode c
5528 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5529 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5530 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5533 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5534 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5535 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5538 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5539 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5542 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5544 int preserve_links = 0;
5545 int preserve_hard_links = 0;
5546 +int preserve_acls = 0;
5547 int preserve_perms = 0;
5548 int preserve_executability = 0;
5549 int preserve_devices = 0;
5550 @@ -199,6 +200,7 @@ static void print_rsync_version(enum log
5551 char const *got_socketpair = "no ";
5552 char const *have_inplace = "no ";
5553 char const *hardlinks = "no ";
5554 + char const *acls = "no ";
5555 char const *links = "no ";
5556 char const *ipv6 = "no ";
5557 STRUCT_STAT *dumstat;
5558 @@ -215,6 +217,10 @@ static void print_rsync_version(enum log
5562 +#ifdef SUPPORT_ACLS
5566 #ifdef SUPPORT_LINKS
5569 @@ -228,9 +234,9 @@ static void print_rsync_version(enum log
5570 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5571 rprintf(f, "<http://rsync.samba.org/>\n");
5572 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5573 - "%shard links, %ssymlinks, batchfiles,\n",
5574 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
5575 (int) (sizeof (OFF_T) * 8),
5576 - got_socketpair, hardlinks, links);
5577 + got_socketpair, hardlinks, acls, links);
5579 /* Note that this field may not have type ino_t. It depends
5580 * on the complicated interaction between largefile feature
5581 @@ -284,7 +290,7 @@ void usage(enum logcode F)
5582 rprintf(F," -q, --quiet suppress non-error messages\n");
5583 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5584 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5585 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5586 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5587 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5588 rprintf(F," -r, --recursive recurse into directories\n");
5589 rprintf(F," -R, --relative use relative path names\n");
5590 @@ -306,6 +312,9 @@ void usage(enum logcode F)
5591 rprintf(F," -p, --perms preserve permissions\n");
5592 rprintf(F," -E, --executability preserve the file's executability\n");
5593 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5594 +#ifdef SUPPORT_ACLS
5595 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5597 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5598 rprintf(F," -g, --group preserve group\n");
5599 rprintf(F," --devices preserve device files (super-user only)\n");
5600 @@ -425,6 +434,9 @@ static struct poptOption long_options[]
5601 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5602 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5603 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5604 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5605 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5606 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5607 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5608 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5609 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5610 @@ -1089,6 +1101,24 @@ int parse_arguments(int *argc, const cha
5615 +#ifdef SUPPORT_ACLS
5617 + preserve_perms = 1;
5620 + /* FIXME: this should probably be ignored with a
5621 + * warning and then countermeasures taken to
5622 + * restrict group and other access in the presence
5623 + * of any more restrictive ACLs, but this is safe
5625 + snprintf(err_buf,sizeof(err_buf),
5626 + "ACLs are not supported on this %s\n",
5627 + am_server ? "server" : "client");
5633 /* A large opt value means that set_refuse_options()
5634 * turned this option off. */
5635 @@ -1530,6 +1560,10 @@ void server_options(char **args,int *arg
5637 if (preserve_hard_links)
5639 +#ifdef SUPPORT_ACLS
5640 + if (preserve_acls)
5641 + argstr[x++] = 'A';
5648 @@ -47,6 +47,7 @@ extern int keep_partial;
5649 extern int checksum_seed;
5651 extern int delay_updates;
5652 +extern mode_t orig_umask;
5653 extern struct stats stats;
5654 extern char *stdout_format;
5655 extern char *tmpdir;
5656 @@ -350,6 +351,10 @@ int recv_files(int f_in, struct file_lis
5657 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5658 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5659 int max_phase = protocol_version >= 29 ? 2 : 1;
5660 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5661 +#ifdef SUPPORT_ACLS
5662 + char *parent_dirname = "";
5667 @@ -553,7 +558,16 @@ int recv_files(int f_in, struct file_lis
5668 * mode based on the local permissions and some heuristics. */
5669 if (!preserve_perms) {
5670 int exists = fd1 != -1;
5671 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5672 +#ifdef SUPPORT_ACLS
5673 + char *dn = file->dirname ? file->dirname : ".";
5674 + if (parent_dirname != dn
5675 + && strcmp(parent_dirname, dn) != 0) {
5676 + dflt_perms = default_perms_for_dir(dn);
5677 + parent_dirname = dn;
5680 + file->mode = dest_mode(file->mode, st.st_mode,
5681 + dflt_perms, exists);
5684 /* We now check to see if we are writing the file "inplace" */
5691 +extern int preserve_acls;
5692 extern int preserve_perms;
5693 extern int preserve_executability;
5694 extern int preserve_times;
5695 @@ -100,7 +101,8 @@ void free_sums(struct sum_struct *s)
5697 /* This is only called when we aren't preserving permissions. Figure out what
5698 * the permissions should be and return them merged back into the mode. */
5699 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5700 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5704 /* If the file already exists, we'll return the local permissions,
5705 @@ -117,56 +119,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5706 new_mode |= (new_mode & 0444) >> 2;
5709 - /* Apply the umask and turn off special permissions. */
5710 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5711 + /* Apply destination default permissions and turn
5712 + * off special permissions. */
5713 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5718 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5719 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5725 int change_uid, change_gid;
5726 mode_t new_mode = file->mode;
5732 - if (link_stat(fname, &st2, 0) < 0) {
5733 + if (link_stat(fname, &sx2.st, 0) < 0) {
5734 rsyserr(FERROR, errno, "stat %s failed",
5739 +#ifdef SUPPORT_ACLS
5740 + sx2.acc_acl = sx2.def_acl = NULL;
5742 if (!preserve_perms && S_ISDIR(new_mode)
5743 - && st->st_mode & S_ISGID) {
5744 + && sx2.st.st_mode & S_ISGID) {
5745 /* We just created this directory and its setgid
5746 * bit is on, so make sure it stays on. */
5747 new_mode |= S_ISGID;
5752 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5753 +#ifdef SUPPORT_ACLS
5754 + if (preserve_acls && !ACL_READY(*sxp))
5755 + get_acl(fname, sxp);
5758 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5759 flags |= ATTRS_SKIP_MTIME;
5760 if (!(flags & ATTRS_SKIP_MTIME)
5761 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5762 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5763 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5764 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5766 rsyserr(FERROR, errno, "failed to set times on %s",
5771 if (ret == 0) /* ret == 1 if symlink could not be set */
5775 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5776 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5777 change_gid = preserve_gid && file->gid != GID_NONE
5778 - && st->st_gid != file->gid;
5779 + && sxp->st.st_gid != file->gid;
5780 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5781 - if (S_ISLNK(st->st_mode))
5782 + if (S_ISLNK(sxp->st.st_mode))
5786 @@ -176,45 +187,57 @@ int set_file_attrs(char *fname, struct f
5788 "set uid of %s from %ld to %ld\n",
5790 - (long)st->st_uid, (long)file->uid);
5791 + (long)sxp->st.st_uid, (long)file->uid);
5795 "set gid of %s from %ld to %ld\n",
5797 - (long)st->st_gid, (long)file->gid);
5798 + (long)sxp->st.st_gid, (long)file->gid);
5801 if (do_lchown(fname,
5802 - change_uid ? file->uid : st->st_uid,
5803 - change_gid ? file->gid : st->st_gid) != 0) {
5804 + change_uid ? file->uid : sxp->st.st_uid,
5805 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5806 /* shouldn't have attempted to change uid or gid
5807 * unless have the privilege */
5808 rsyserr(FERROR, errno, "%s %s failed",
5809 change_uid ? "chown" : "chgrp",
5814 /* a lchown had been done - we have to re-stat if the
5815 * destination had the setuid or setgid bits set due
5816 * to the side effect of the chown call */
5817 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5818 - link_stat(fname, st,
5819 - keep_dirlinks && S_ISDIR(st->st_mode));
5820 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5821 + link_stat(fname, &sxp->st,
5822 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5827 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5828 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5830 +#ifdef SUPPORT_ACLS
5831 + /* It's OK to call set_acl() now, even for a dir, as the generator
5832 + * will enable owner-writability using chmod, if necessary.
5834 + * If set_acl() changes permission bits in the process of setting
5835 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5836 + * need to chmod(). */
5837 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5842 - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5843 + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5844 int ret = do_chmod(fname, new_mode);
5846 rsyserr(FERROR, errno,
5847 "failed to set permissions on %s",
5852 if (ret == 0) /* ret == 1 if symlink could not be set */
5854 @@ -227,6 +250,11 @@ int set_file_attrs(char *fname, struct f
5856 rprintf(FCLIENT, "%s is uptodate\n", fname);
5859 +#ifdef SUPPORT_ACLS
5860 + if (preserve_acls && sxp == &sx2)
5868 @@ -492,6 +492,15 @@ struct idev {
5869 #define IN_LOOPBACKNET 127
5872 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5873 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5874 +#define SUPPORT_ACLS 1
5877 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5878 +#define ACLS_NEED_MASK 1
5881 #define GID_NONE ((gid_t)-1)
5883 #define HL_CHECK_MASTER 0
5884 @@ -653,6 +662,17 @@ struct stats {
5886 struct chmod_mode_struct;
5888 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5896 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5897 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5899 #include "byteorder.h"
5900 #include "lib/mdfour.h"
5901 #include "lib/wildmatch.h"
5902 @@ -669,6 +689,16 @@ struct chmod_mode_struct;
5903 #define UNUSED(x) x __attribute__((__unused__))
5904 #define NORETURN __attribute__((__noreturn__))
5908 +#ifdef SUPPORT_ACLS
5909 + struct rsync_acl *acc_acl; /* access ACL */
5910 + struct rsync_acl *def_acl; /* default ACL */
5914 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5918 /* We have replacement versions of these if they're missing. */
5921 @@ -301,7 +301,7 @@ to the detailed description below for a
5922 -q, --quiet suppress non-error messages
5923 --no-motd suppress daemon-mode MOTD (see caveat)
5924 -c, --checksum skip based on checksum, not mod-time & size
5925 - -a, --archive archive mode; same as -rlptgoD (no -H)
5926 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
5927 --no-OPTION turn off an implied OPTION (e.g. --no-D)
5928 -r, --recursive recurse into directories
5929 -R, --relative use relative path names
5930 @@ -323,6 +323,7 @@ to the detailed description below for a
5931 -p, --perms preserve permissions
5932 -E, --executability preserve executability
5933 --chmod=CHMOD affect file and/or directory permissions
5934 + -A, --acls preserve ACLs (implies -p) [non-standard]
5935 -o, --owner preserve owner (super-user only)
5936 -g, --group preserve group
5937 --devices preserve device files (super-user only)
5938 @@ -753,7 +754,9 @@ quote(itemization(
5939 permissions, though the bf(--executability) option might change just
5940 the execute permission for the file.
5941 it() New files get their "normal" permission bits set to the source
5942 - file's permissions masked with the receiving end's umask setting, and
5943 + file's permissions masked with the receiving directory's default
5944 + permissions (either the receiving process's umask, or the permissions
5945 + specified via the destination directory's default ACL), and
5946 their special permission bits disabled except in the case where a new
5947 directory inherits a setgid bit from its parent directory.
5949 @@ -784,9 +787,11 @@ The preservation of the destination's se
5950 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5951 versions erroneously preserved the three special permission bits for
5952 newly-created files when bf(--perms) was off, while overriding the
5953 -destination's setgid bit setting on a newly-created directory. (Keep in
5954 -mind that it is the version of the receiving rsync that affects this
5956 +destination's setgid bit setting on a newly-created directory. Default ACL
5957 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5958 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5959 +(Keep in mind that it is the version of the receiving rsync that affects
5962 dit(bf(-E, --executability)) This option causes rsync to preserve the
5963 executability (or non-executability) of regular files when bf(--perms) is
5964 @@ -804,6 +809,15 @@ quote(itemization(
5966 If bf(--perms) is enabled, this option is ignored.
5968 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5969 +ACLs to be the same as the source ACLs. This nonstandard option only
5970 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5972 +Note also that an optimization of the ACL-sending protocol used by this
5973 +version makes it incompatible with sending files to an older ACL-enabled
5974 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5975 +doubling is not needed when pulling files from an older rsync.
5977 dit(bf(--chmod)) This option tells rsync to apply one or more
5978 comma-separated "chmod" strings to the permission of the files in the
5979 transfer. The resulting value is treated as though it was the permissions
5980 @@ -1389,8 +1403,8 @@ if the receiving rsync is at least versi
5981 with older versions of rsync, but that also turns on the output of other
5984 -The "%i" escape has a cryptic output that is 9 letters long. The general
5985 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
5986 +The "%i" escape has a cryptic output that is 11 letters long. The general
5987 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
5988 type of update being done, bf(X) is replaced by the file-type, and the
5989 other letters represent attributes that may be output if they are being
5991 @@ -1439,7 +1453,11 @@ quote(itemization(
5992 sender's value (requires bf(--owner) and super-user privileges).
5993 it() A bf(g) means the group is different and is being updated to the
5994 sender's value (requires bf(--group) and the authority to set the group).
5995 - it() The bf(z) slot is reserved for future use.
5996 + it() The bf(u) slot is reserved for reporting update (access) time changes
5997 + (a feature that is not yet released).
5998 + it() The bf(a) means that the ACL information changed.
5999 + it() The bf(x) slot is reserved for reporting extended attribute changes
6000 + (a feature that is not yet released).
6003 One other output is possible: when deleting files, the "%i" will output
6008 + Unix SMB/Netbios implementation.
6010 + Portable SMB ACL interface
6011 + Copyright (C) Jeremy Allison 2000
6013 + This program is free software; you can redistribute it and/or modify
6014 + it under the terms of the GNU General Public License as published by
6015 + the Free Software Foundation; either version 2 of the License, or
6016 + (at your option) any later version.
6018 + This program is distributed in the hope that it will be useful,
6019 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6020 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6021 + GNU General Public License for more details.
6023 + You should have received a copy of the GNU General Public License
6024 + along with this program; if not, write to the Free Software
6025 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6028 +#ifndef _SMB_ACLS_H
6029 +#define _SMB_ACLS_H
6031 +#if defined HAVE_POSIX_ACLS
6033 +/* This is an identity mapping (just remove the SMB_). */
6035 +#define SMB_ACL_TAG_T acl_tag_t
6036 +#define SMB_ACL_TYPE_T acl_type_t
6037 +#define SMB_ACL_PERMSET_T acl_permset_t
6038 +#define SMB_ACL_PERM_T acl_perm_t
6039 +#define SMB_ACL_READ ACL_READ
6040 +#define SMB_ACL_WRITE ACL_WRITE
6041 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6043 +/* Types of ACLs. */
6044 +#define SMB_ACL_USER ACL_USER
6045 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6046 +#define SMB_ACL_GROUP ACL_GROUP
6047 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6048 +#define SMB_ACL_OTHER ACL_OTHER
6049 +#define SMB_ACL_MASK ACL_MASK
6051 +#define SMB_ACL_T acl_t
6053 +#define SMB_ACL_ENTRY_T acl_entry_t
6055 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6056 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6058 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6059 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6061 +#elif defined HAVE_TRU64_ACLS
6063 +/* This is for DEC/Compaq Tru64 UNIX */
6065 +#define SMB_ACL_TAG_T acl_tag_t
6066 +#define SMB_ACL_TYPE_T acl_type_t
6067 +#define SMB_ACL_PERMSET_T acl_permset_t
6068 +#define SMB_ACL_PERM_T acl_perm_t
6069 +#define SMB_ACL_READ ACL_READ
6070 +#define SMB_ACL_WRITE ACL_WRITE
6071 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6073 +/* Types of ACLs. */
6074 +#define SMB_ACL_USER ACL_USER
6075 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6076 +#define SMB_ACL_GROUP ACL_GROUP
6077 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6078 +#define SMB_ACL_OTHER ACL_OTHER
6079 +#define SMB_ACL_MASK ACL_MASK
6081 +#define SMB_ACL_T acl_t
6083 +#define SMB_ACL_ENTRY_T acl_entry_t
6085 +#define SMB_ACL_FIRST_ENTRY 0
6086 +#define SMB_ACL_NEXT_ENTRY 1
6088 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6089 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6091 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6093 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6094 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6097 +/* SVR4.2 ES/MP ACLs */
6098 +typedef int SMB_ACL_TAG_T;
6099 +typedef int SMB_ACL_TYPE_T;
6100 +typedef ushort *SMB_ACL_PERMSET_T;
6101 +typedef ushort SMB_ACL_PERM_T;
6102 +#define SMB_ACL_READ 4
6103 +#define SMB_ACL_WRITE 2
6104 +#define SMB_ACL_EXECUTE 1
6106 +/* Types of ACLs. */
6107 +#define SMB_ACL_USER USER
6108 +#define SMB_ACL_USER_OBJ USER_OBJ
6109 +#define SMB_ACL_GROUP GROUP
6110 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6111 +#define SMB_ACL_OTHER OTHER_OBJ
6112 +#define SMB_ACL_MASK CLASS_OBJ
6114 +typedef struct SMB_ACL_T {
6118 + struct acl acl[1];
6121 +typedef struct acl *SMB_ACL_ENTRY_T;
6123 +#define SMB_ACL_FIRST_ENTRY 0
6124 +#define SMB_ACL_NEXT_ENTRY 1
6126 +#define SMB_ACL_TYPE_ACCESS 0
6127 +#define SMB_ACL_TYPE_DEFAULT 1
6130 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6133 +#elif defined HAVE_HPUX_ACLS
6136 + * Based on the Solaris & UnixWare code.
6140 +#include <sys/aclv.h>
6142 +/* SVR4.2 ES/MP ACLs */
6143 +typedef int SMB_ACL_TAG_T;
6144 +typedef int SMB_ACL_TYPE_T;
6145 +typedef ushort *SMB_ACL_PERMSET_T;
6146 +typedef ushort SMB_ACL_PERM_T;
6147 +#define SMB_ACL_READ 4
6148 +#define SMB_ACL_WRITE 2
6149 +#define SMB_ACL_EXECUTE 1
6151 +/* Types of ACLs. */
6152 +#define SMB_ACL_USER USER
6153 +#define SMB_ACL_USER_OBJ USER_OBJ
6154 +#define SMB_ACL_GROUP GROUP
6155 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6156 +#define SMB_ACL_OTHER OTHER_OBJ
6157 +#define SMB_ACL_MASK CLASS_OBJ
6159 +typedef struct SMB_ACL_T {
6163 + struct acl acl[1];
6166 +typedef struct acl *SMB_ACL_ENTRY_T;
6168 +#define SMB_ACL_FIRST_ENTRY 0
6169 +#define SMB_ACL_NEXT_ENTRY 1
6171 +#define SMB_ACL_TYPE_ACCESS 0
6172 +#define SMB_ACL_TYPE_DEFAULT 1
6174 +#elif defined HAVE_IRIX_ACLS
6176 +#define SMB_ACL_TAG_T acl_tag_t
6177 +#define SMB_ACL_TYPE_T acl_type_t
6178 +#define SMB_ACL_PERMSET_T acl_permset_t
6179 +#define SMB_ACL_PERM_T acl_perm_t
6180 +#define SMB_ACL_READ ACL_READ
6181 +#define SMB_ACL_WRITE ACL_WRITE
6182 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6184 +/* Types of ACLs. */
6185 +#define SMB_ACL_USER ACL_USER
6186 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6187 +#define SMB_ACL_GROUP ACL_GROUP
6188 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6189 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6190 +#define SMB_ACL_MASK ACL_MASK
6192 +typedef struct SMB_ACL_T {
6198 +#define SMB_ACL_ENTRY_T acl_entry_t
6200 +#define SMB_ACL_FIRST_ENTRY 0
6201 +#define SMB_ACL_NEXT_ENTRY 1
6203 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6204 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6206 +#elif defined HAVE_AIX_ACLS
6208 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6210 +#include "/usr/include/acl.h"
6212 +typedef uint *SMB_ACL_PERMSET_T;
6214 +struct acl_entry_link{
6215 + struct acl_entry_link *prevp;
6216 + struct new_acl_entry *entryp;
6217 + struct acl_entry_link *nextp;
6221 +struct new_acl_entry{
6222 + unsigned short ace_len;
6223 + unsigned short ace_type;
6224 + unsigned int ace_access;
6225 + struct ace_id ace_id[1];
6228 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6229 +#define SMB_ACL_T struct acl_entry_link*
6231 +#define SMB_ACL_TAG_T unsigned short
6232 +#define SMB_ACL_TYPE_T int
6233 +#define SMB_ACL_PERM_T uint
6234 +#define SMB_ACL_READ S_IRUSR
6235 +#define SMB_ACL_WRITE S_IWUSR
6236 +#define SMB_ACL_EXECUTE S_IXUSR
6238 +/* Types of ACLs. */
6239 +#define SMB_ACL_USER ACEID_USER
6240 +#define SMB_ACL_USER_OBJ 3
6241 +#define SMB_ACL_GROUP ACEID_GROUP
6242 +#define SMB_ACL_GROUP_OBJ 4
6243 +#define SMB_ACL_OTHER 5
6244 +#define SMB_ACL_MASK 6
6247 +#define SMB_ACL_FIRST_ENTRY 1
6248 +#define SMB_ACL_NEXT_ENTRY 2
6250 +#define SMB_ACL_TYPE_ACCESS 0
6251 +#define SMB_ACL_TYPE_DEFAULT 1
6253 +#else /* No ACLs. */
6255 +/* No ACLS - fake it. */
6256 +#define SMB_ACL_TAG_T int
6257 +#define SMB_ACL_TYPE_T int
6258 +#define SMB_ACL_PERMSET_T mode_t
6259 +#define SMB_ACL_PERM_T mode_t
6260 +#define SMB_ACL_READ S_IRUSR
6261 +#define SMB_ACL_WRITE S_IWUSR
6262 +#define SMB_ACL_EXECUTE S_IXUSR
6264 +/* Types of ACLs. */
6265 +#define SMB_ACL_USER 0
6266 +#define SMB_ACL_USER_OBJ 1
6267 +#define SMB_ACL_GROUP 2
6268 +#define SMB_ACL_GROUP_OBJ 3
6269 +#define SMB_ACL_OTHER 4
6270 +#define SMB_ACL_MASK 5
6272 +typedef struct SMB_ACL_T {
6276 +typedef struct SMB_ACL_ENTRY_T {
6278 +} *SMB_ACL_ENTRY_T;
6280 +#define SMB_ACL_FIRST_ENTRY 0
6281 +#define SMB_ACL_NEXT_ENTRY 1
6283 +#define SMB_ACL_TYPE_ACCESS 0
6284 +#define SMB_ACL_TYPE_DEFAULT 1
6286 +#endif /* No ACLs. */
6287 +#endif /* _SMB_ACLS_H */
6288 --- old/testsuite/acls.test
6289 +++ new/testsuite/acls.test
6293 +# This program is distributable under the terms of the GNU GPL (see
6296 +# Test that rsync handles basic ACL preservation.
6298 +. $srcdir/testsuite/rsync.fns
6300 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6301 +case "$setfacl_nodef" in
6302 +true) test_skipped "I don't know how to use your setfacl command" ;;
6305 +makepath "$fromdir/foo"
6306 +echo something >"$fromdir/file1"
6307 +echo else >"$fromdir/file2"
6309 +files='foo file1 file2'
6311 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6312 +setfacl -m u:0:5 "$fromdir/file1"
6313 +setfacl -m u:0:5 "$fromdir/file2"
6315 +$RSYNC -avvA "$fromdir/" "$todir/"
6318 +getfacl $files >"$scratchdir/acls.txt"
6321 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6323 +# The script would have aborted on error, so getting here means we've won.
6325 --- old/testsuite/default-acls.test
6326 +++ new/testsuite/default-acls.test
6330 +# This program is distributable under the terms of the GNU GPL (see
6333 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6335 +. $srcdir/testsuite/rsync.fns
6337 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6338 +case "$setfacl_nodef" in
6339 +true) test_skipped "I don't know how to use your setfacl command" ;;
6340 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6341 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6343 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6345 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6347 + todir="$scratchdir/$1"
6349 + $setfacl_nodef "$todir"
6351 + case "$setfacl_nodef" in
6352 + *-k*) opts="-dm $2" ;;
6353 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6355 + setfacl $opts "$todir"
6357 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6358 + # even though the directory itself is outside the transfer
6359 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6360 + check_perms "$todir/to" $4 "Target $1"
6361 + check_perms "$todir/to/dir" $4 "Target $1"
6362 + check_perms "$todir/to/file" $3 "Target $1"
6363 + check_perms "$todir/to/program" $4 "Target $1"
6364 + # Make sure get_local_name doesn't mess us up when transferring only one file
6365 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6366 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6367 + # Make sure we obey default ACLs when not transferring a regular file
6368 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6369 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6372 +mkdir "$scratchdir/dir"
6373 +echo "File!" >"$scratchdir/file"
6374 +echo "#!/bin/sh" >"$scratchdir/program"
6375 +chmod 777 "$scratchdir/dir"
6376 +chmod 666 "$scratchdir/file"
6377 +chmod 777 "$scratchdir/program"
6379 +# Test some target directories
6381 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6382 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6383 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6384 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6385 +testit noda1 '' rw------- rwx------
6387 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6389 +testit noda3 '' rw-r--r-- rwxr-xr-x
6393 --- old/testsuite/devices.test
6394 +++ new/testsuite/devices.test
6395 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6396 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6398 cat <<EOT >"$chkfile"
6402 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6404 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6406 cat <<EOT >"$chkfile"
6410 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6412 @@ -58,7 +58,7 @@ sleep 1
6413 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6415 cat <<EOT >"$chkfile"
6419 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6421 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6424 cat <<EOT >"$chkfile"
6429 -hD+++++++ block2.5 => block3
6438 +hD+++++++++ block2.5 => block3
6444 if test ! -b "$fromdir/block2.5"; then
6445 sed -e '/block2\.5/d' \
6446 --- old/testsuite/itemize.test
6447 +++ new/testsuite/itemize.test
6448 @@ -29,15 +29,15 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6449 $RSYNC -iplr "$fromdir/" "$todir/" \
6451 cat <<EOT >"$chkfile"
6455 ->f+++++++ bar/baz/rsync
6457 ->f+++++++ foo/config1
6458 ->f+++++++ foo/config2
6459 ->f+++++++ foo/extra
6460 -cL+++++++ foo/sym -> ../bar/baz/rsync
6463 +cd+++++++++ bar/baz/
6464 +>f+++++++++ bar/baz/rsync
6466 +>f+++++++++ foo/config1
6467 +>f+++++++++ foo/config2
6468 +>f+++++++++ foo/extra
6469 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6471 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6473 @@ -49,10 +49,10 @@ chmod 601 "$fromdir/foo/config2"
6474 $RSYNC -iplrH "$fromdir/" "$todir/" \
6476 cat <<EOT >"$chkfile"
6477 ->f..T.... bar/baz/rsync
6478 ->f..T.... foo/config1
6479 ->f.sTp... foo/config2
6480 -hf..T.... foo/extra => foo/config1
6481 +>f..T...... bar/baz/rsync
6482 +>f..T...... foo/config1
6483 +>f.sTp..... foo/config2
6484 +hf..T...... foo/extra => foo/config1
6486 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6488 @@ -69,11 +69,11 @@ chmod 777 "$todir/bar/baz/rsync"
6489 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6491 cat <<EOT >"$chkfile"
6492 -.f..tp... bar/baz/rsync
6494 -.f..t.... foo/config1
6495 ->fcstp... foo/config2
6496 -cL..T.... foo/sym -> ../bar/baz/rsync
6497 +.f..tp..... bar/baz/rsync
6499 +.f..t...... foo/config1
6500 +>fcstp..... foo/config2
6501 +cL..T...... foo/sym -> ../bar/baz/rsync
6503 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6505 @@ -98,15 +98,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6508 cat <<EOT >"$chkfile"
6512 -.f...p... bar/baz/rsync
6515 ->f..t.... foo/config2
6517 -.L foo/sym -> ../bar/baz/rsync
6521 +.f...p..... bar/baz/rsync
6524 +>f..t...... foo/config2
6526 +.L foo/sym -> ../bar/baz/rsync
6528 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6530 @@ -125,8 +125,8 @@ touch "$todir/foo/config2"
6531 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6533 cat <<EOT >"$chkfile"
6534 -.f...p... foo/config1
6535 ->f..t.... foo/config2
6536 +.f...p..... foo/config1
6537 +>f..t...... foo/config2
6539 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6541 @@ -135,15 +135,15 @@ $RSYNC -ivvplrtH --copy-dest=../ld "$fro
6544 cat <<EOT >"$chkfile"
6552 -hf foo/extra => foo/config1
6553 -cL..T.... foo/sym -> ../bar/baz/rsync
6556 +cd+++++++++ bar/baz/
6561 +hf foo/extra => foo/config1
6562 +cL..T...... foo/sym -> ../bar/baz/rsync
6564 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6566 @@ -151,11 +151,11 @@ rm -rf "$todir"
6567 $RSYNC -iplrtH --copy-dest=../ld "$fromdir/" "$todir/" \
6569 cat <<EOT >"$chkfile"
6574 -hf foo/extra => foo/config1
6577 +cd+++++++++ bar/baz/
6579 +hf foo/extra => foo/config1
6581 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6583 @@ -182,15 +182,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6586 cat <<EOT >"$chkfile"
6594 -hf foo/extra => foo/config1
6595 -hL foo/sym -> ../bar/baz/rsync
6598 +cd+++++++++ bar/baz/
6603 +hf foo/extra => foo/config1
6604 +hL foo/sym -> ../bar/baz/rsync
6606 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6608 @@ -198,10 +198,10 @@ rm -rf "$todir"
6609 $RSYNC -iplrtH --dry-run --link-dest=../ld "$fromdir/" "$todir/" \
6611 cat <<EOT >"$chkfile"
6618 +cd+++++++++ bar/baz/
6621 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6623 @@ -209,10 +209,10 @@ rm -rf "$todir"
6624 $RSYNC -iplrtH --link-dest=../ld "$fromdir/" "$todir/" \
6626 cat <<EOT >"$chkfile"
6633 +cd+++++++++ bar/baz/
6636 diff $diffopt "$chkfile" "$outfile" || test_fail "test 13 failed"
6638 @@ -240,14 +240,14 @@ filter_outfile
6639 # TODO fix really-old problem when combining -H with --compare-dest:
6640 # missing output for foo/extra hard-link (and it might not be updated)!
6641 cat <<EOT >"$chkfile"
6649 -.L foo/sym -> ../bar/baz/rsync
6652 +cd+++++++++ bar/baz/
6657 +.L foo/sym -> ../bar/baz/rsync
6659 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6661 @@ -255,10 +255,10 @@ rm -rf "$todir"
6662 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6664 cat <<EOT >"$chkfile"
6671 +cd+++++++++ bar/baz/
6674 diff $diffopt "$chkfile" "$outfile" || test_fail "test 16 failed"
6680 extern int preserve_uid;
6681 extern int preserve_gid;
6682 +extern int preserve_acls;
6683 extern int numeric_ids;
6686 @@ -273,7 +274,7 @@ void send_uid_list(int f)
6690 - if (preserve_uid) {
6691 + if (preserve_uid || preserve_acls) {
6693 /* we send sequences of uid/byte-length/name */
6694 for (list = uidlist; list; list = list->next) {
6695 @@ -290,7 +291,7 @@ void send_uid_list(int f)
6699 - if (preserve_gid) {
6700 + if (preserve_gid || preserve_acls) {
6702 for (list = gidlist; list; list = list->next) {
6704 @@ -311,7 +312,7 @@ void recv_uid_list(int f, struct file_li
6708 - if (preserve_uid && !numeric_ids) {
6709 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6710 /* read the uid list */
6711 while ((id = read_int(f)) != 0) {
6712 int len = read_byte(f);
6713 @@ -323,7 +324,7 @@ void recv_uid_list(int f, struct file_li
6717 - if (preserve_gid && !numeric_ids) {
6718 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6719 /* read the gid list */
6720 while ((id = read_int(f)) != 0) {
6721 int len = read_byte(f);
6722 @@ -335,6 +336,16 @@ void recv_uid_list(int f, struct file_li
6726 +#ifdef SUPPORT_ACLS
6727 + if (preserve_acls && !numeric_ids) {
6729 + while ((id = next_acl_uid(flist)) != NULL)
6730 + *id = match_uid(*id);
6731 + while ((id = next_acl_gid(flist)) != NULL)
6732 + *id = match_gid(*id);
6736 /* Now convert all the uids/gids from sender values to our values. */
6737 if (am_root && preserve_uid && !numeric_ids) {
6738 for (i = 0; i < flist->count; i++)
6741 @@ -1468,3 +1468,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6746 +void *expand_item_list(item_list *lp, size_t item_size,
6747 + const char *desc, int incr)
6749 + /* First time through, 0 <= 0, so list is expanded. */
6750 + if (lp->malloced <= lp->count) {
6752 + size_t new_size = lp->malloced;
6754 + new_size -= incr; /* increase slowly */
6755 + else if (new_size < (size_t)incr)
6759 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6760 + if (verbose >= 4) {
6761 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6762 + who_am_i(), desc, (double)new_size * item_size,
6763 + new_ptr == lp->items ? " not" : "");
6766 + out_of_memory("expand_item_list");
6768 + lp->items = new_ptr;
6769 + lp->malloced = new_size;
6771 + return (char*)lp->items + (lp->count++ * item_size);