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"
62 +extern int read_only;
63 +extern int list_only;
64 +extern int orig_umask;
65 +extern int preserve_acls;
66 +extern unsigned int file_struct_len;
68 +/* === ACL structures === */
80 +#define NO_ENTRY ((uchar)0x80)
81 +typedef struct rsync_acl {
84 + /* These will be NO_ENTRY if there's no such entry. */
96 +static const rsync_acl empty_rsync_acl = {
97 + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
100 +static item_list access_acl_list = EMPTY_ITEM_LIST;
101 +static item_list default_acl_list = EMPTY_ITEM_LIST;
103 +/* === Calculations on ACL types === */
105 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
107 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
108 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
109 + : "unknown SMB_ACL_TYPE_T";
112 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
113 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
115 +static int count_racl_entries(const rsync_acl *racl)
117 + return racl->users.count + racl->groups.count
118 + + (racl->user_obj != NO_ENTRY)
119 + + (racl->group_obj != NO_ENTRY)
120 + + (racl->mask != NO_ENTRY)
121 + + (racl->other != NO_ENTRY);
124 +static int calc_sacl_entries(const rsync_acl *racl)
126 + /* A System ACL always gets user/group/other permission entries. */
127 + return racl->users.count + racl->groups.count
128 +#ifdef ACLS_NEED_MASK
131 + + (racl->mask != NO_ENTRY) + 3;
135 +/* Extracts and returns the permission bits from the ACL. This cannot be
136 + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
137 +static int rsync_acl_get_perms(const rsync_acl *racl)
139 + return (racl->user_obj << 6)
140 + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3)
144 +/* Removes the permission-bit entries from the ACL because these
145 + * can be reconstructed from the file's mode. */
146 +static void rsync_acl_strip_perms(rsync_acl *racl)
148 + racl->user_obj = NO_ENTRY;
149 + if (racl->mask == NO_ENTRY)
150 + racl->group_obj = NO_ENTRY;
152 + if (racl->group_obj == racl->mask)
153 + racl->group_obj = NO_ENTRY;
154 + racl->mask = NO_ENTRY;
156 + racl->other = NO_ENTRY;
159 +/* Given an empty rsync_acl, fake up the permission bits. */
160 +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
162 + racl->user_obj = (mode >> 6) & 7;
163 + racl->group_obj = (mode >> 3) & 7;
164 + racl->other = mode & 7;
167 +/* === Rsync ACL functions === */
169 +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
171 + id_access *ida1, *ida2;
172 + int count = ial1->count;
173 + if (count != ial2->count)
177 + for (; count--; ida1++, ida2++) {
178 + if (ida1->access != ida2->access || ida1->id != ida2->id)
184 +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
186 + return racl1->user_obj == racl2->user_obj
187 + && racl1->group_obj == racl2->group_obj
188 + && racl1->mask == racl2->mask
189 + && racl1->other == racl2->other
190 + && ida_entries_equal(&racl1->users, &racl2->users)
191 + && ida_entries_equal(&racl1->groups, &racl2->groups);
194 +/* Are the extended (non-permission-bit) entries equal? If so, the rest of
195 + * the ACL will be handled by the normal mode-preservation code. This is
196 + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated
197 + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
198 + * that it might have several of its permission objects set to NO_ENTRY. */
199 +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
200 + const rsync_acl *racl2, mode_t m)
202 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
203 + return False; /* One has a mask and the other doesn't */
205 + /* When there's a mask, the group_obj becomes an extended entry. */
206 + if (racl1->mask != NO_ENTRY) {
207 + /* A condensed rsync_acl with a mask can only have no
208 + * group_obj when it was identical to the mask. This
209 + * means that it was also identical to the group attrs
210 + * from the mode. */
211 + if (racl2->group_obj == NO_ENTRY) {
212 + if (racl1->group_obj != ((m >> 3) & 7))
214 + } else if (racl1->group_obj != racl2->group_obj)
217 + return ida_entries_equal(&racl1->users, &racl2->users)
218 + && ida_entries_equal(&racl1->groups, &racl2->groups);
221 +static void rsync_acl_free(rsync_acl *racl)
223 + if (racl->users.idas)
224 + free(racl->users.idas);
225 + if (racl->groups.idas)
226 + free(racl->groups.idas);
227 + *racl = empty_rsync_acl;
230 +void free_acl(statx *sxp)
232 + if (sxp->acc_acl) {
233 + rsync_acl_free(sxp->acc_acl);
234 + free(sxp->acc_acl);
235 + sxp->acc_acl = NULL;
237 + if (sxp->def_acl) {
238 + rsync_acl_free(sxp->def_acl);
239 + free(sxp->def_acl);
240 + sxp->def_acl = NULL;
244 +static int id_access_sorter(const void *r1, const void *r2)
246 + id_access *ida1 = (id_access *)r1;
247 + id_access *ida2 = (id_access *)r2;
248 + id_t rid1 = ida1->id, rid2 = ida2->id;
249 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
252 +static void sort_ida_entries(ida_entries *idal)
256 + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter);
259 +/* Transfer the count id_access items out of the temp_ida_list into either
260 + * the users or groups ida_entries list in racl. */
261 +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type)
266 + if (temp_ida_list->count) {
267 + int cnt = temp_ida_list->count;
268 + id_access *temp_idas = temp_ida_list->items;
269 + if (!(idas = new_array(id_access, cnt)))
270 + out_of_memory("save_idas");
271 + memcpy(idas, temp_idas, cnt * sizeof *temp_idas);
275 + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups;
278 + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type);
279 + exit_cleanup(RERR_UNSUPPORTED);
281 + ent->count = temp_ida_list->count;
284 + /* Truncate the temporary list now that its idas have been saved. */
285 + temp_ida_list->count = 0;
288 +/* === System ACLs === */
290 +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
291 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
293 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
294 + SMB_ACL_TAG_T prior_list_type = 0;
295 + SMB_ACL_ENTRY_T entry;
296 + const char *errfun;
299 + errfun = "sys_acl_get_entry";
300 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
302 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
303 + SMB_ACL_TAG_T tag_type;
304 + SMB_ACL_PERMSET_T permset;
308 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
309 + errfun = "sys_acl_get_tag_type";
312 + if ((rc = sys_acl_get_permset(entry, &permset))) {
313 + errfun = "sys_acl_get_tag_type";
316 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
317 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
318 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
319 + /* continue == done with entry; break == store in temporary ida list */
320 + switch (tag_type) {
321 + case SMB_ACL_USER_OBJ:
322 + if (racl->user_obj == NO_ENTRY)
323 + racl->user_obj = access;
325 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
329 + case SMB_ACL_GROUP_OBJ:
330 + if (racl->group_obj == NO_ENTRY)
331 + racl->group_obj = access;
333 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
335 + case SMB_ACL_GROUP:
338 + if (racl->mask == NO_ENTRY)
339 + racl->mask = access;
341 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
343 + case SMB_ACL_OTHER:
344 + if (racl->other == NO_ENTRY)
345 + racl->other = access;
347 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
350 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
353 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
354 + errfun = "sys_acl_get_tag_type";
358 + if (tag_type != prior_list_type) {
359 + if (prior_list_type)
360 + save_idas(&temp_ida_list, racl, prior_list_type);
361 + prior_list_type = tag_type;
363 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
364 + ida->id = *((id_t *)qualifier);
365 + ida->access = access;
366 + sys_acl_free_qualifier(qualifier, tag_type);
369 + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun);
370 + rsync_acl_free(racl);
373 + if (prior_list_type)
374 + save_idas(&temp_ida_list, racl, prior_list_type);
376 + sort_ida_entries(&racl->users);
377 + sort_ida_entries(&racl->groups);
379 +#ifdef ACLS_NEED_MASK
380 + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) {
381 + /* Throw away a superfluous mask, but mask off the
382 + * group perms with it first. */
383 + racl->group_obj &= racl->mask;
384 + racl->mask = NO_ENTRY;
391 +/* Synactic sugar for system calls */
393 +#define CALL_OR_ERROR(func,args,str) \
401 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
402 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
404 +/* Store the permissions in the system ACL entry. */
405 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
407 + const char *errfun = NULL;
408 + SMB_ACL_PERMSET_T permset;
410 + COE( sys_acl_get_permset,(entry, &permset) );
411 + COE( sys_acl_clear_perms,(permset) );
413 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
415 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
417 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
418 + COE( sys_acl_set_permset,(entry, permset) );
423 + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun);
427 +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
428 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
430 +#ifdef ACLS_NEED_MASK
435 + const char *errfun = NULL;
436 + SMB_ACL_ENTRY_T entry;
438 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
439 + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()");
443 + COE( sys_acl_create_entry,(smb_acl, &entry) );
444 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
445 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
447 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
448 + COE( sys_acl_create_entry,(smb_acl, &entry) );
449 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
450 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
451 + COE2( store_access_in_entry,(ida->access, entry) );
454 + COE( sys_acl_create_entry,(smb_acl, &entry) );
455 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
456 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
458 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
459 + COE( sys_acl_create_entry,(smb_acl, &entry) );
460 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
461 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
462 + COE2( store_access_in_entry,(ida->access, entry) );
465 +#ifdef ACLS_NEED_MASK
466 + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask;
467 + COE( sys_acl_create_entry,(smb_acl, &entry) );
468 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
469 + COE2( store_access_in_entry,(mask_bits, entry) );
471 + if (racl->mask != NO_ENTRY) {
472 + COE( sys_acl_create_entry,(smb_acl, &entry) );
473 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
474 + COE2( store_access_in_entry,(racl->mask, entry) );
478 + COE( sys_acl_create_entry,(smb_acl, &entry) );
479 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
480 + COE2( store_access_in_entry,(racl->other & 7, entry) );
483 + if (sys_acl_valid(*smb_acl) < 0)
484 + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
491 + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun);
493 + sys_acl_free_acl(*smb_acl);
497 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
498 + const item_list *racl_list,
499 + const rsync_acl *racl)
501 + static int access_match = -1, default_match = -1;
502 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
503 + size_t count = racl_list->count;
505 + /* If this is the first time through or we didn't match the last
506 + * time, then start at the end of the list, which should be the
507 + * best place to start hunting. */
509 + *match = racl_list->count - 1;
511 + rsync_acl *base = racl_list->items;
512 + if (rsync_acl_equal(base + *match, racl))
515 + *match = racl_list->count - 1;
522 +/* Return the Access Control List for the given filename. */
523 +int get_acl(const char *fname, statx *sxp)
525 + SMB_ACL_TYPE_T type;
527 + if (S_ISLNK(sxp->st.st_mode))
530 + type = SMB_ACL_TYPE_ACCESS;
532 + SMB_ACL_T sacl = sys_acl_get_file(fname, type);
533 + rsync_acl *racl = new(rsync_acl);
536 + out_of_memory("get_acl");
537 + *racl = empty_rsync_acl;
538 + if (type == SMB_ACL_TYPE_ACCESS)
539 + sxp->acc_acl = racl;
541 + sxp->def_acl = racl;
544 + BOOL ok = unpack_smb_acl(racl, sacl);
546 + sys_acl_free_acl(sacl);
551 + } else if (errno == ENOTSUP) {
552 + /* ACLs are not supported, so pretend we have a basic ACL. */
553 + if (type == SMB_ACL_TYPE_ACCESS)
554 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
556 + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)",
557 + fname, str_acl_type(type));
561 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
566 +/* === Send functions === */
568 +/* The general strategy with the tag_type <-> character mapping is that
569 + * lowercase implies that no qualifier follows, where uppercase does.
570 + * A similar idiom for the ACL type (access or default) itself, but
571 + * lowercase in this instance means there's no ACL following, so the
572 + * ACL is a repeat, so the receiver should reuse the last of the same
575 +/* Send the ida list over the file descriptor. */
576 +static void send_ida_entries(int f, const ida_entries *idal, char tag_char)
579 + size_t count = idal->count;
580 + for (ida = idal->idas; count--; ida++) {
581 + write_byte(f, tag_char);
582 + write_byte(f, ida->access);
583 + write_int(f, ida->id);
584 + /* FIXME: sorta wasteful: we should maybe buffer as
585 + * many ids as max(ACL_USER + ACL_GROUP) objects to
586 + * keep from making so many calls. */
587 + if (tag_char == 'U')
594 +/* Send an rsync ACL over the file descriptor. */
595 +static void send_rsync_acl(int f, const rsync_acl *racl)
597 + size_t count = count_racl_entries(racl);
598 + write_int(f, count);
599 + if (racl->user_obj != NO_ENTRY) {
600 + write_byte(f, 'u');
601 + write_byte(f, racl->user_obj);
603 + send_ida_entries(f, &racl->users, 'U');
604 + if (racl->group_obj != NO_ENTRY) {
605 + write_byte(f, 'g');
606 + write_byte(f, racl->group_obj);
608 + send_ida_entries(f, &racl->groups, 'G');
609 + if (racl->mask != NO_ENTRY) {
610 + write_byte(f, 'm');
611 + write_byte(f, racl->mask);
613 + if (racl->other != NO_ENTRY) {
614 + write_byte(f, 'o');
615 + write_byte(f, racl->other);
619 +/* Send the ACL from the statx structure down the indicated file descriptor.
620 + * This also frees the ACL data. */
621 +void send_acl(statx *sxp, int f)
623 + SMB_ACL_TYPE_T type;
624 + rsync_acl *racl, *new_racl;
625 + item_list *racl_list;
628 + if (S_ISLNK(sxp->st.st_mode))
631 + type = SMB_ACL_TYPE_ACCESS;
632 + racl = sxp->acc_acl;
633 + racl_list = &access_acl_list;
636 + racl = new(rsync_acl);
638 + out_of_memory("send_acl");
639 + *racl = empty_rsync_acl;
640 + if (type == SMB_ACL_TYPE_ACCESS) {
641 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
642 + sxp->acc_acl = racl;
644 + sxp->def_acl = racl;
647 + /* Avoid sending values that can be inferred from other data,
648 + * but only when preserve_acls == 1 (it is 2 when we must be
649 + * backward compatible with older acls.diff versions). */
650 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
651 + rsync_acl_strip_perms(racl);
652 + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) {
653 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
656 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
657 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
658 + send_rsync_acl(f, racl);
660 + *racl = empty_rsync_acl;
662 + racl = sxp->def_acl;
663 + racl_list = &default_acl_list;
664 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
669 +/* === Receive functions === */
671 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
673 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
674 + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0;
675 + uchar computed_mask_bits = 0;
679 + if (!(count = read_int(f)))
683 + char tag = read_byte(f);
684 + uchar access = read_byte(f);
685 + if (access & ~ (4 | 2 | 1)) {
686 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
688 + exit_cleanup(RERR_STREAMIO);
692 + if (racl->user_obj != NO_ENTRY) {
693 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
694 + exit_cleanup(RERR_STREAMIO);
696 + racl->user_obj = access;
699 + tag_type = SMB_ACL_USER;
702 + if (racl->group_obj != NO_ENTRY) {
703 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
704 + exit_cleanup(RERR_STREAMIO);
706 + racl->group_obj = access;
709 + tag_type = SMB_ACL_GROUP;
712 + if (racl->mask != NO_ENTRY) {
713 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
714 + exit_cleanup(RERR_STREAMIO);
716 + racl->mask = access;
719 + if (racl->other != NO_ENTRY) {
720 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
721 + exit_cleanup(RERR_STREAMIO);
723 + racl->other = access;
726 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
728 + exit_cleanup(RERR_STREAMIO);
730 + if (tag_type != prior_list_type) {
731 + if (prior_list_type)
732 + save_idas(&temp_ida_list, racl, prior_list_type);
733 + prior_list_type = tag_type;
735 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
736 + ida->access = access;
737 + ida->id = read_int(f);
738 + computed_mask_bits |= access;
740 + if (prior_list_type)
741 + save_idas(&temp_ida_list, racl, prior_list_type);
743 + if (type == SMB_ACL_TYPE_DEFAULT) {
744 + /* Ensure that these are never unset. */
745 + if (racl->user_obj == NO_ENTRY)
746 + racl->user_obj = 7;
747 + if (racl->group_obj == NO_ENTRY)
748 + racl->group_obj = 0;
749 + if (racl->other == NO_ENTRY)
753 + if (!racl->users.count && !racl->groups.count) {
754 + /* If we received a superfluous mask, throw it away. */
755 + if (racl->mask != NO_ENTRY) {
756 + /* Mask off the group perms with it first. */
757 + racl->group_obj &= racl->mask | NO_ENTRY;
758 + racl->mask = NO_ENTRY;
760 + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */
761 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
764 +/* Receive the ACL info the sender has included for this file-list entry. */
765 +void receive_acl(struct file_struct *file, int f)
767 + SMB_ACL_TYPE_T type;
768 + item_list *racl_list;
771 + if (S_ISLNK(file->mode))
774 + type = SMB_ACL_TYPE_ACCESS;
775 + racl_list = &access_acl_list;
776 + ndx_ptr = (char*)file + file_struct_len;
778 + char tag = read_byte(f);
781 + if (tag == 'A' || tag == 'a') {
782 + if (type != SMB_ACL_TYPE_ACCESS) {
783 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
784 + f_name(file, NULL));
785 + exit_cleanup(RERR_STREAMIO);
787 + } else if (tag == 'D' || tag == 'd') {
788 + if (type == SMB_ACL_TYPE_ACCESS) {
789 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
790 + f_name(file, NULL));
791 + exit_cleanup(RERR_STREAMIO);
794 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
795 + f_name(file, NULL), tag);
796 + exit_cleanup(RERR_STREAMIO);
798 + if (tag == 'A' || tag == 'D') {
800 + ndx = racl_list->count;
801 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
802 + duo_item->racl = empty_rsync_acl;
803 + receive_rsync_acl(&duo_item->racl, f, type);
804 + duo_item->sacl = NULL;
807 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
808 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
809 + f_name(file, NULL), str_acl_type(type), ndx);
810 + exit_cleanup(RERR_STREAMIO);
813 + SIVAL(ndx_ptr, 0, ndx);
814 + racl_list = &default_acl_list;
816 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
819 +/* Turn the ACL data in statx into cached ACL data, setting the index
820 + * values in the file struct. */
821 +void cache_acl(struct file_struct *file, statx *sxp)
823 + SMB_ACL_TYPE_T type;
825 + item_list *racl_list;
829 + if (S_ISLNK(file->mode))
832 + type = SMB_ACL_TYPE_ACCESS;
833 + racl = sxp->acc_acl;
834 + racl_list = &access_acl_list;
835 + ndx_ptr = (char*)file + file_struct_len;
839 + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) {
841 + ndx = racl_list->count;
842 + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
843 + new_duo->racl = *racl;
844 + new_duo->sacl = NULL;
845 + *racl = empty_rsync_acl;
847 + SIVAL(ndx_ptr, 0, ndx);
848 + racl = sxp->def_acl;
849 + racl_list = &default_acl_list;
851 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
856 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
858 + SMB_ACL_ENTRY_T entry;
859 + const char *errfun;
862 + if (S_ISDIR(mode)) {
863 + /* If the sticky bit is going on, it's not safe to allow all
864 + * the new ACL to go into effect before it gets set. */
865 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
866 + if (mode & S_ISVTX)
869 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
872 + /* If setuid or setgid is going off, it's not safe to allow all
873 + * the new ACL to go into effect before they get cleared. */
874 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
875 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
880 + errfun = "sys_acl_get_entry";
881 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
883 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
884 + SMB_ACL_TAG_T tag_type;
885 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
886 + errfun = "sys_acl_get_tag_type";
889 + switch (tag_type) {
890 + case SMB_ACL_USER_OBJ:
891 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
893 + case SMB_ACL_GROUP_OBJ:
894 + /* group is only empty when identical to group perms. */
895 + if (racl->group_obj != NO_ENTRY)
897 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
900 +#ifndef ACLS_NEED_MASK
901 + /* mask is only empty when we don't need it. */
902 + if (racl->mask == NO_ENTRY)
905 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
907 + case SMB_ACL_OTHER:
908 + COE2( store_access_in_entry,(mode & 7, entry) );
915 + rsyserr(FERROR, errno, "change_sacl_perms: %s()",
921 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
922 + /* Ensure that chmod() will be called to restore any lost setid bits. */
923 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
924 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
925 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
928 + /* Return the mode of the file on disk, as we will set them. */
929 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
932 +/* Set ACL on indicated filename.
934 + * This sets extended access ACL entries and default ACL. If convenient,
935 + * it sets permission bits along with the access ACL and signals having
936 + * done so by modifying sxp->st.st_mode.
938 + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this
939 + * with fname set to NULL to just check if the ACL is unchanged. */
940 +int set_acl(const char *fname, const struct file_struct *file, statx *sxp)
943 + SMB_ACL_TYPE_T type;
946 + if (!dry_run && (read_only || list_only)) {
951 + if (S_ISLNK(file->mode))
954 + type = SMB_ACL_TYPE_ACCESS;
955 + ndx_ptr = (char*)file + file_struct_len;
959 + int32 ndx = IVAL(ndx_ptr, 0);
963 + if (type == SMB_ACL_TYPE_ACCESS) {
964 + if (ndx < 0 || (size_t)ndx >= access_acl_list.count)
966 + duo_item = access_acl_list.items;
969 + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode);
971 + if (ndx < 0 || (size_t)ndx >= default_acl_list.count)
973 + duo_item = default_acl_list.items;
976 + && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
980 + if (!dry_run && fname) {
981 + if (type == SMB_ACL_TYPE_DEFAULT
982 + && duo_item->racl.user_obj == NO_ENTRY) {
983 + if (sys_acl_delete_def_file(fname) < 0) {
984 + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)",
990 + mode_t cur_mode = sxp->st.st_mode;
991 + if (!duo_item->sacl
992 + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) {
996 + if (type == SMB_ACL_TYPE_ACCESS) {
997 + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
998 + cur_mode, file->mode);
999 + if (cur_mode == (mode_t)~0)
1002 + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
1003 + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)",
1004 + fname, str_acl_type(type));
1008 + if (type == SMB_ACL_TYPE_ACCESS)
1009 + sxp->st.st_mode = cur_mode;
1012 + if (unchanged == 1)
1014 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1019 +/* === Enumeration functions for uid mapping === */
1021 +/* Context -- one and only one. Should be cycled through once on uid
1022 + * mapping and once on gid mapping. */
1023 +static item_list *_enum_racl_lists[] = {
1024 + &access_acl_list, &default_acl_list, NULL
1027 +static item_list **enum_racl_list = &_enum_racl_lists[0];
1028 +static int enum_ida_index = 0;
1029 +static size_t enum_racl_index = 0;
1031 +/* This returns the next tag_type id from the given ACL for the next entry,
1032 + * or it returns 0 if there are no more tag_type ids in the acl. */
1033 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1035 + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1036 + if (enum_ida_index < idal->count) {
1037 + id_access *ida = &idal->idas[enum_ida_index++];
1040 + enum_ida_index = 0;
1044 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list)
1046 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1048 + acl_duo *duo_item = racl_list->items;
1049 + duo_item += enum_racl_index;
1050 + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL)
1053 + enum_racl_index = 0;
1057 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1059 + for (; *enum_racl_list; enum_racl_list++) {
1060 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1064 + enum_racl_list = &_enum_racl_lists[0];
1068 +id_t *next_acl_uid()
1070 + return next_acl_list_id(SMB_ACL_USER);
1073 +id_t *next_acl_gid()
1075 + return next_acl_list_id(SMB_ACL_GROUP);
1078 +/* This is used by dest_mode(). */
1079 +int default_perms_for_dir(const char *dir)
1088 + perms = ACCESSPERMS & ~orig_umask;
1089 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1090 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1091 + if (sacl == NULL) {
1092 + /* Couldn't get an ACL. Darn. */
1095 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1099 + /* We're doing a dry run, so the containing directory
1100 + * wasn't actually created. Don't worry about it. */
1103 + /* Otherwise fall through. */
1105 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1106 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1112 + racl = empty_rsync_acl;
1113 + ok = unpack_smb_acl(&racl, sacl);
1114 + sys_acl_free_acl(sacl);
1116 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1120 + /* Apply the permission-bit entries of the default ACL, if any. */
1121 + if (racl.user_obj != NO_ENTRY) {
1122 + perms = rsync_acl_get_perms(&racl);
1124 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1127 + rsync_acl_free(&racl);
1131 +#endif /* SUPPORT_ACLS */
1134 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1135 extern char *backup_dir;
1138 +extern int preserve_acls;
1139 extern int preserve_devices;
1140 extern int preserve_specials;
1141 extern int preserve_links;
1142 @@ -94,7 +95,8 @@ path
1143 ****************************************************************************/
1144 static int make_bak_dir(char *fullpath)
1148 + struct file_struct *file;
1149 char *rel = fullpath + backup_dir_len;
1150 char *end = rel + strlen(rel);
1152 @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath)
1154 /* Try to transfer the directory settings of the
1155 * actual dir that the files are coming from. */
1156 - if (do_stat(rel, &st) < 0) {
1157 + if (do_stat(rel, &sx.st) < 0) {
1158 rsyserr(FERROR, errno,
1159 "make_bak_dir stat %s failed",
1162 - do_lchown(fullpath, st.st_uid, st.st_gid);
1163 - do_chmod(fullpath, st.st_mode);
1164 +#ifdef SUPPORT_ACLS
1165 + sx.acc_acl = sx.def_acl = NULL;
1167 + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
1169 +#ifdef SUPPORT_ACLS
1170 + if (preserve_acls) {
1171 + get_acl(rel, &sx);
1172 + cache_acl(file, &sx);
1175 + set_file_attrs(fullpath, file, NULL, 0);
1180 @@ -170,15 +183,18 @@ static int robust_move(char *src, char *
1181 * We will move the file to be deleted into a parallel directory tree. */
1182 static int keep_backup(char *fname)
1186 struct file_struct *file;
1191 /* return if no file to keep */
1192 - if (do_lstat(fname, &st) < 0)
1193 + if (do_lstat(fname, &sx.st) < 0)
1195 +#ifdef SUPPORT_ACLS
1196 + sx.acc_acl = sx.def_acl = NULL;
1199 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
1200 return 1; /* the file could have disappeared */
1201 @@ -186,6 +202,13 @@ static int keep_backup(char *fname)
1202 if (!(buf = get_backup_name(fname)))
1205 +#ifdef SUPPORT_ACLS
1206 + if (preserve_acls) {
1207 + get_acl(fname, &sx);
1208 + cache_acl(file, &sx);
1212 /* Check to see if this is a device file, or link */
1213 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1214 || (preserve_specials && IS_SPECIAL(file->mode))) {
1215 @@ -254,7 +277,7 @@ static int keep_backup(char *fname)
1216 if (robust_move(fname, buf) != 0) {
1217 rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
1218 full_fname(fname), buf);
1219 - } else if (st.st_nlink > 1) {
1220 + } else if (sx.st.st_nlink > 1) {
1221 /* If someone has hard-linked the file into the backup
1222 * dir, rename() might return success but do nothing! */
1223 robust_unlink(fname); /* Just in case... */
1224 --- old/configure.in
1225 +++ new/configure.in
1226 @@ -515,6 +515,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1227 AC_CHECK_LIB(resolv, strcasecmp)
1230 +AC_CHECK_FUNCS(aclsort)
1231 +if test x"$ac_cv_func_aclsort" = x"no"; then
1232 + AC_CHECK_LIB(sec, aclsort)
1235 dnl At the moment we don't test for a broken memcmp(), because all we
1236 dnl need to do is test for equality, not comparison, and it seems that
1237 dnl every platform has a memcmp that can do at least that.
1238 @@ -779,6 +784,78 @@ AC_SUBST(OBJ_RESTORE)
1239 AC_SUBST(CC_SHOBJ_FLAG)
1240 AC_SUBST(BUILD_POPT)
1242 +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h)
1243 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1244 +#################################################
1245 +# check for ACL support
1247 +AC_MSG_CHECKING(whether to support ACLs)
1248 +AC_ARG_ENABLE(acl-support,
1249 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1250 +[ case "$enableval" in
1253 + case "$host_os" in
1255 + AC_MSG_RESULT(Using UnixWare ACLs)
1256 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1258 + *solaris*|*cygwin*)
1259 + AC_MSG_RESULT(Using solaris ACLs)
1260 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1263 + AC_MSG_RESULT(Using HPUX ACLs)
1264 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1267 + AC_MSG_RESULT(Using IRIX ACLs)
1268 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1271 + AC_MSG_RESULT(Using AIX ACLs)
1272 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1275 + AC_MSG_RESULT(Using Tru64 ACLs)
1276 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1277 + LIBS="$LIBS -lpacl"
1280 + AC_MSG_RESULT(ACLs requested -- running tests)
1281 + AC_CHECK_LIB(acl,acl_get_file)
1282 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1283 + AC_TRY_LINK([#include <sys/types.h>
1284 +#include <sys/acl.h>],
1285 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1286 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1287 + AC_MSG_CHECKING(ACL test results)
1288 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1289 + AC_MSG_RESULT(Using posix ACLs)
1290 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1291 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1292 + AC_TRY_LINK([#include <sys/types.h>
1293 +#include <sys/acl.h>],
1294 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1295 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1296 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1297 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1300 + AC_MSG_ERROR(Failed to find ACL support)
1307 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1310 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1314 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1319 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1320 extern int one_file_system;
1321 extern int copy_dirlinks;
1322 extern int keep_dirlinks;
1323 +extern int preserve_acls;
1324 extern int preserve_links;
1325 extern int preserve_hard_links;
1326 extern int preserve_devices;
1327 @@ -133,6 +134,8 @@ static void list_file_entry(struct file_
1329 permstring(permbuf, f->mode);
1331 + /* TODO: indicate '+' if the entry has an ACL. */
1333 #ifdef SUPPORT_LINKS
1334 if (preserve_links && S_ISLNK(f->mode)) {
1335 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
1336 @@ -495,6 +498,9 @@ static struct file_struct *receive_file_
1337 char thisname[MAXPATHLEN];
1338 unsigned int l1 = 0, l2 = 0;
1339 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
1340 +#ifdef SUPPORT_ACLS
1344 char *basename, *dirname, *bp;
1345 struct file_struct *file;
1346 @@ -598,13 +604,27 @@ static struct file_struct *receive_file_
1348 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
1350 +#ifdef SUPPORT_ACLS
1351 + /* We need one or two index int32s when we're preserving ACLs. */
1352 + if (preserve_acls)
1353 + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
1358 alloc_len = file_struct_len + dirname_len + basename_len
1359 +#ifdef SUPPORT_ACLS
1362 + linkname_len + sum_len;
1363 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
1365 file = (struct file_struct *)bp;
1366 memset(bp, 0, file_struct_len);
1367 bp += file_struct_len;
1368 +#ifdef SUPPORT_ACLS
1372 file->modtime = modtime;
1373 file->length = file_length;
1374 @@ -699,6 +719,11 @@ static struct file_struct *receive_file_
1375 read_buf(f, sum, checksum_len);
1378 +#ifdef SUPPORT_ACLS
1379 + if (preserve_acls)
1380 + receive_acl(file, f);
1386 @@ -949,6 +974,9 @@ static struct file_struct *send_file_nam
1387 unsigned short flags)
1389 struct file_struct *file;
1390 +#ifdef SUPPORT_ACLS
1394 file = make_file(fname, flist, stp, flags,
1395 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1396 @@ -958,6 +986,15 @@ static struct file_struct *send_file_nam
1397 if (chmod_modes && !S_ISLNK(file->mode))
1398 file->mode = tweak_mode(file->mode, chmod_modes);
1400 +#ifdef SUPPORT_ACLS
1401 + if (preserve_acls) {
1402 + sx.st.st_mode = file->mode;
1403 + sx.acc_acl = sx.def_acl = NULL;
1404 + if (get_acl(fname, &sx) < 0)
1409 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1411 flist_expand(flist);
1412 @@ -965,6 +1002,15 @@ static struct file_struct *send_file_nam
1413 if (file->basename[0]) {
1414 flist->files[flist->count++] = file;
1415 send_file_entry(file, f);
1416 +#ifdef SUPPORT_ACLS
1417 + if (preserve_acls)
1421 +#ifdef SUPPORT_ACLS
1422 + if (preserve_acls)
1430 @@ -35,6 +35,7 @@ extern int do_progress;
1431 extern int relative_paths;
1432 extern int implied_dirs;
1433 extern int keep_dirlinks;
1434 +extern int preserve_acls;
1435 extern int preserve_links;
1436 extern int preserve_devices;
1437 extern int preserve_specials;
1438 @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus
1439 extern int max_delete;
1440 extern int force_delete;
1441 extern int one_file_system;
1442 +extern mode_t orig_umask;
1443 extern struct stats stats;
1444 extern dev_t filesystem_dev;
1445 extern char *backup_dir;
1446 @@ -317,22 +319,27 @@ static void do_delete_pass(struct file_l
1447 rprintf(FINFO, " \r");
1450 -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1451 +int unchanged_attrs(struct file_struct *file, statx *sxp)
1454 - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1455 + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1458 - if (am_root && preserve_uid && st->st_uid != file->uid)
1459 + if (am_root && preserve_uid && sxp->st.st_uid != file->uid)
1462 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
1463 + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid)
1466 +#ifdef SUPPORT_ACLS
1467 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1474 -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
1475 +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp,
1476 int32 iflags, uchar fnamecmp_type, char *xname)
1478 if (statret >= 0) { /* A from-dest-dir statret can == 1! */
1479 @@ -340,19 +347,23 @@ void itemize(struct file_struct *file, i
1480 : S_ISDIR(file->mode) ? !omit_dir_times
1481 : !S_ISLNK(file->mode);
1483 - if (S_ISREG(file->mode) && file->length != st->st_size)
1484 + if (S_ISREG(file->mode) && file->length != sxp->st.st_size)
1485 iflags |= ITEM_REPORT_SIZE;
1486 if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
1487 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
1488 - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
1489 + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0))
1490 iflags |= ITEM_REPORT_TIME;
1491 - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
1492 + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS))
1493 iflags |= ITEM_REPORT_PERMS;
1494 - if (preserve_uid && am_root && file->uid != st->st_uid)
1495 + if (preserve_uid && am_root && file->uid != sxp->st.st_uid)
1496 iflags |= ITEM_REPORT_OWNER;
1497 if (preserve_gid && file->gid != GID_NONE
1498 - && st->st_gid != file->gid)
1499 + && sxp->st.st_gid != file->gid)
1500 iflags |= ITEM_REPORT_GROUP;
1501 +#ifdef SUPPORT_ACLS
1502 + if (preserve_acls && set_acl(NULL, file, sxp) == 0)
1503 + iflags |= ITEM_REPORT_ACL;
1506 iflags |= ITEM_IS_NEW;
1508 @@ -605,7 +616,7 @@ void check_for_finished_hlinks(int itemi
1509 * handling the file, -1 if no dest-linking occurred, or a non-negative
1510 * value if we found an alternate basis file. */
1511 static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
1512 - char *cmpbuf, STRUCT_STAT *stp, int itemizing,
1513 + char *cmpbuf, statx *sxp, int itemizing,
1514 int maybe_ATTRS_REPORT, enum logcode code)
1516 int best_match = -1;
1517 @@ -614,7 +625,7 @@ static int try_dests_reg(struct file_str
1520 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1521 - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode))
1522 + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
1524 switch (match_level) {
1526 @@ -622,16 +633,20 @@ static int try_dests_reg(struct file_str
1530 - if (!unchanged_file(cmpbuf, file, stp))
1531 + if (!unchanged_file(cmpbuf, file, &sxp->st))
1537 - if (!unchanged_attrs(file, stp))
1538 +#ifdef SUPPORT_ACLS
1539 + if (preserve_acls)
1540 + get_acl(cmpbuf, sxp);
1542 + if (!unchanged_attrs(file, sxp))
1544 if (always_checksum && preserve_times
1545 - && cmp_time(stp->st_mtime, file->modtime))
1546 + && cmp_time(sxp->st.st_mtime, file->modtime))
1550 @@ -646,14 +661,14 @@ static int try_dests_reg(struct file_str
1551 if (j != best_match) {
1553 pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
1554 - if (link_stat(cmpbuf, stp, 0) < 0)
1555 + if (link_stat(cmpbuf, &sxp->st, 0) < 0)
1559 if (match_level == 3 && !copy_dest) {
1560 #ifdef SUPPORT_HARD_LINKS
1562 - if (hard_link_one(file, ndx, fname, 0, stp,
1563 + if (hard_link_one(file, ndx, fname, 0, sxp,
1565 itemizing && verbose > 1,
1567 @@ -665,8 +680,13 @@ static int try_dests_reg(struct file_str
1572 - itemize(file, ndx, 0, stp, 0, 0, NULL);
1574 +#ifdef SUPPORT_ACLS
1575 + if (preserve_acls && !ACL_READY(*sxp))
1576 + get_acl(fname, sxp);
1578 + itemize(file, ndx, 0, sxp, 0, 0, NULL);
1580 if (verbose > 1 && maybe_ATTRS_REPORT) {
1581 rprintf(FCLIENT, "%s is uptodate\n", fname);
1583 @@ -682,8 +702,13 @@ static int try_dests_reg(struct file_str
1588 - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL);
1590 +#ifdef SUPPORT_ACLS
1591 + if (preserve_acls && !ACL_READY(*sxp))
1592 + get_acl(fname, sxp);
1594 + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
1596 set_file_attrs(fname, file, NULL, 0);
1597 if (maybe_ATTRS_REPORT
1598 && ((!itemizing && verbose && match_level == 2)
1599 @@ -707,13 +732,18 @@ static int try_dests_non(struct file_str
1602 char fnamebuf[MAXPATHLEN];
1608 pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname);
1609 - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode)
1610 - || !unchanged_attrs(file, &st))
1611 + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode))
1613 +#ifdef SUPPORT_ACLS
1614 + if (preserve_acls)
1615 + get_acl(fnamebuf, &sx);
1617 + if (!unchanged_attrs(file, &sx))
1619 if (S_ISLNK(file->mode)) {
1620 #ifdef SUPPORT_LINKS
1621 @@ -726,10 +756,10 @@ static int try_dests_non(struct file_str
1624 } else if (IS_SPECIAL(file->mode)) {
1625 - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev)
1626 + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1628 } else if (IS_DEVICE(file->mode)) {
1629 - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev)
1630 + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev)
1634 @@ -760,7 +790,15 @@ static int try_dests_non(struct file_str
1635 int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE
1636 + (link_dest ? ITEM_XNAME_FOLLOWS : 0);
1637 char *lp = link_dest ? "" : NULL;
1638 - itemize(file, ndx, 0, &st, changes, 0, lp);
1639 +#ifdef SUPPORT_ACLS
1640 + if (preserve_acls)
1641 + get_acl(fname, &sx);
1643 + itemize(file, ndx, 0, &sx, changes, 0, lp);
1644 +#ifdef SUPPORT_ACLS
1645 + if (preserve_acls)
1649 if (verbose > 1 && maybe_ATTRS_REPORT) {
1650 rprintf(FCLIENT, "%s is uptodate\n", fname);
1651 @@ -772,6 +810,7 @@ static int try_dests_non(struct file_str
1654 static int phase = 0;
1655 +static int dflt_perms;
1657 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1658 * make sure it exists, and has the right permissions/timestamp info. For
1659 @@ -793,7 +832,8 @@ static void recv_generator(char *fname,
1660 static int need_fuzzy_dirlist = 0;
1661 struct file_struct *fuzzy_file = NULL;
1662 int fd = -1, f_copy = -1;
1663 - STRUCT_STAT st, real_st, partial_st;
1664 + statx sx, real_sx;
1665 + STRUCT_STAT partial_st;
1666 struct file_struct *back_file = NULL;
1667 int statret, real_ret, stat_errno;
1668 char *fnamecmp, *partialptr, *backupptr = NULL;
1669 @@ -849,6 +889,9 @@ static void recv_generator(char *fname,
1670 } else if (!dry_run)
1673 +#ifdef SUPPORT_ACLS
1674 + sx.acc_acl = sx.def_acl = NULL;
1678 stat_errno = ENOENT;
1679 @@ -856,7 +899,7 @@ static void recv_generator(char *fname,
1680 char *dn = file->dirname ? file->dirname : ".";
1681 if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
1682 if (relative_paths && !implied_dirs
1683 - && do_stat(dn, &st) < 0
1684 + && do_stat(dn, &sx.st) < 0
1685 && create_directory_path(fname) < 0) {
1686 rsyserr(FERROR, errno,
1687 "recv_generator: mkdir %s failed",
1688 @@ -868,6 +911,10 @@ static void recv_generator(char *fname,
1691 need_fuzzy_dirlist = 1;
1692 +#ifdef SUPPORT_ACLS
1693 + if (!preserve_perms)
1694 + dflt_perms = default_perms_for_dir(dn);
1697 parent_dirname = dn;
1699 @@ -876,7 +923,7 @@ static void recv_generator(char *fname,
1700 need_fuzzy_dirlist = 0;
1703 - statret = link_stat(fname, &st,
1704 + statret = link_stat(fname, &sx.st,
1705 keep_dirlinks && S_ISDIR(file->mode));
1708 @@ -894,8 +941,9 @@ static void recv_generator(char *fname,
1709 * mode based on the local permissions and some heuristics. */
1710 if (!preserve_perms) {
1711 int exists = statret == 0
1712 - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1713 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1714 + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode);
1715 + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
1719 if (S_ISDIR(file->mode)) {
1720 @@ -904,8 +952,8 @@ static void recv_generator(char *fname,
1721 * file of that name and it is *not* a directory, then
1722 * we need to delete it. If it doesn't exist, then
1723 * (perhaps recursively) create it. */
1724 - if (statret == 0 && !S_ISDIR(st.st_mode)) {
1725 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1726 + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
1727 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1731 @@ -920,7 +968,11 @@ static void recv_generator(char *fname,
1735 - itemize(file, ndx, sr, &st,
1736 +#ifdef SUPPORT_ACLS
1737 + if (preserve_acls && sr == 0)
1738 + get_acl(fname, &sx);
1740 + itemize(file, ndx, sr, &sx,
1741 sr ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
1743 if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) {
1744 @@ -940,19 +992,19 @@ static void recv_generator(char *fname,
1748 - if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1749 + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0)
1750 && verbose && code != FNONE && f_out != -1)
1751 rprintf(code, "%s/\n", fname);
1752 if (delete_during && f_out != -1 && !phase && dry_run < 2
1753 && (file->flags & FLAG_DEL_HERE))
1754 - delete_in_dir(the_file_list, fname, file, &st);
1756 + delete_in_dir(the_file_list, fname, file, &sx.st);
1760 if (preserve_hard_links && file->link_u.links
1761 - && hard_link_check(file, ndx, fname, statret, &st,
1762 + && hard_link_check(file, ndx, fname, statret, &sx,
1763 itemizing, code, HL_CHECK_MASTER))
1767 if (preserve_links && S_ISLNK(file->mode)) {
1768 #ifdef SUPPORT_LINKS
1769 @@ -970,7 +1022,7 @@ static void recv_generator(char *fname,
1770 char lnk[MAXPATHLEN];
1773 - if (!S_ISDIR(st.st_mode)
1774 + if (!S_ISDIR(sx.st.st_mode)
1775 && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) {
1777 /* A link already pointing to the
1778 @@ -978,10 +1030,10 @@ static void recv_generator(char *fname,
1780 if (strcmp(lnk, file->u.link) == 0) {
1782 - itemize(file, ndx, 0, &st, 0,
1783 + itemize(file, ndx, 0, &sx, 0,
1786 - set_file_attrs(fname, file, &st,
1787 + set_file_attrs(fname, file, &sx,
1788 maybe_ATTRS_REPORT);
1789 if (preserve_hard_links
1790 && file->link_u.links) {
1791 @@ -996,9 +1048,9 @@ static void recv_generator(char *fname,
1793 /* Not the right symlink (or not a symlink), so
1795 - if (delete_item(fname, st.st_mode, del_opts) < 0)
1796 + if (delete_item(fname, sx.st.st_mode, del_opts) < 0)
1798 - if (!S_ISLNK(st.st_mode))
1799 + if (!S_ISLNK(sx.st.st_mode))
1801 } else if (basis_dir[0] != NULL) {
1802 if (try_dests_non(file, fname, ndx, itemizing,
1803 @@ -1015,7 +1067,7 @@ static void recv_generator(char *fname,
1806 if (preserve_hard_links && file->link_u.links
1807 - && hard_link_check(file, ndx, fname, -1, &st,
1808 + && hard_link_check(file, ndx, fname, -1, &sx,
1809 itemizing, code, HL_SKIP))
1811 if (do_symlink(file->u.link,fname) != 0) {
1812 @@ -1024,7 +1076,7 @@ static void recv_generator(char *fname,
1814 set_file_attrs(fname, file, NULL, 0);
1816 - itemize(file, ndx, statret, &st,
1817 + itemize(file, ndx, statret, &sx,
1818 ITEM_LOCAL_CHANGE, 0, NULL);
1820 if (code != FNONE && verbose) {
1821 @@ -1059,18 +1111,22 @@ static void recv_generator(char *fname,
1825 +#ifdef SUPPORT_ACLS
1826 + if (preserve_acls && statret == 0)
1827 + get_acl(fname, &sx);
1830 - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1831 - || st.st_rdev != file->u.rdev) {
1832 + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS)
1833 + || sx.st.st_rdev != file->u.rdev) {
1835 - && delete_item(fname, st.st_mode, del_opts) < 0)
1837 + && delete_item(fname, sx.st.st_mode, del_opts) < 0)
1839 if (preserve_hard_links && file->link_u.links
1840 - && hard_link_check(file, ndx, fname, -1, &st,
1841 + && hard_link_check(file, ndx, fname, -1, &sx,
1842 itemizing, code, HL_SKIP))
1844 - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode))
1845 - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode)))
1847 + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode))
1848 + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode)))
1851 rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
1852 @@ -1083,7 +1139,7 @@ static void recv_generator(char *fname,
1854 set_file_attrs(fname, file, NULL, 0);
1856 - itemize(file, ndx, statret, &st,
1857 + itemize(file, ndx, statret, &sx,
1858 ITEM_LOCAL_CHANGE, 0, NULL);
1860 if (code != FNONE && verbose)
1861 @@ -1097,14 +1153,14 @@ static void recv_generator(char *fname,
1865 - itemize(file, ndx, statret, &st, 0, 0, NULL);
1866 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1867 + itemize(file, ndx, statret, &sx, 0, 0, NULL);
1868 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1869 if (preserve_hard_links && file->link_u.links)
1870 hard_link_cluster(file, ndx, itemizing, code);
1871 if (remove_source_files == 1)
1872 goto return_with_success;
1878 if (!S_ISREG(file->mode)) {
1879 @@ -1138,7 +1194,7 @@ static void recv_generator(char *fname,
1882 if (update_only && statret == 0
1883 - && cmp_time(st.st_mtime, file->modtime) > 0) {
1884 + && cmp_time(sx.st.st_mtime, file->modtime) > 0) {
1886 rprintf(FINFO, "%s is newer\n", fname);
1888 @@ -1147,20 +1203,20 @@ static void recv_generator(char *fname,
1890 fnamecmp_type = FNAMECMP_FNAME;
1892 - if (statret == 0 && !S_ISREG(st.st_mode)) {
1893 - if (delete_item(fname, st.st_mode, del_opts) != 0)
1894 + if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
1895 + if (delete_item(fname, sx.st.st_mode, del_opts) != 0)
1898 stat_errno = ENOENT;
1901 if (statret != 0 && basis_dir[0] != NULL) {
1902 - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st,
1903 + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
1904 itemizing, maybe_ATTRS_REPORT, code);
1906 if (remove_source_files == 1)
1907 goto return_with_success;
1912 fnamecmp = fnamecmpbuf;
1913 @@ -1170,7 +1226,7 @@ static void recv_generator(char *fname,
1920 if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
1921 && link_stat(partialptr, &partial_st, 0) == 0
1922 @@ -1189,7 +1245,7 @@ static void recv_generator(char *fname,
1923 rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
1924 fname, fnamecmpbuf);
1926 - st.st_size = fuzzy_file->length;
1927 + sx.st.st_size = fuzzy_file->length;
1929 fnamecmp = fnamecmpbuf;
1930 fnamecmp_type = FNAMECMP_FUZZY;
1931 @@ -1198,7 +1254,7 @@ static void recv_generator(char *fname,
1934 if (preserve_hard_links && file->link_u.links
1935 - && hard_link_check(file, ndx, fname, statret, &st,
1936 + && hard_link_check(file, ndx, fname, statret, &sx,
1937 itemizing, code, HL_SKIP))
1939 if (stat_errno == ENOENT)
1940 @@ -1208,39 +1264,52 @@ static void recv_generator(char *fname,
1944 - if (append_mode && st.st_size > file->length)
1945 + if (append_mode && sx.st.st_size > file->length)
1948 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
1950 else if (fnamecmp_type == FNAMECMP_FUZZY)
1952 - else if (unchanged_file(fnamecmp, file, &st)) {
1953 + else if (unchanged_file(fnamecmp, file, &sx.st)) {
1955 do_unlink(partialptr);
1956 handle_partial_dir(partialptr, PDIR_DELETE);
1959 - itemize(file, ndx, real_ret, &real_st,
1960 +#ifdef SUPPORT_ACLS
1961 + if (preserve_acls && real_ret == 0)
1962 + get_acl(fnamecmp, &real_sx);
1964 + itemize(file, ndx, real_ret, &real_sx,
1966 +#ifdef SUPPORT_ACLS
1967 + if (preserve_acls) {
1968 + if (fnamecmp_type == FNAMECMP_FNAME) {
1969 + sx.acc_acl = real_sx.acc_acl;
1970 + sx.def_acl = real_sx.def_acl;
1972 + free_acl(&real_sx);
1976 - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
1977 + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT);
1978 if (preserve_hard_links && file->link_u.links)
1979 hard_link_cluster(file, ndx, itemizing, code);
1980 if (remove_source_files != 1)
1983 return_with_success:
1986 SIVAL(numbuf, 0, ndx);
1987 send_msg(MSG_SUCCESS, numbuf, 4);
1996 + sx.st = partial_st;
1997 fnamecmp = partialptr;
1998 fnamecmp_type = FNAMECMP_PARTIAL_DIR;
2000 @@ -1264,17 +1333,21 @@ static void recv_generator(char *fname,
2002 /* pretend the file didn't exist */
2003 if (preserve_hard_links && file->link_u.links
2004 - && hard_link_check(file, ndx, fname, statret, &st,
2005 + && hard_link_check(file, ndx, fname, statret, &sx,
2006 itemizing, code, HL_SKIP))
2009 statret = real_ret = -1;
2010 +#ifdef SUPPORT_ACLS
2011 + if (preserve_acls && ACL_READY(sx))
2017 if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
2018 if (!(backupptr = get_backup_name(fname))) {
2023 if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
2025 @@ -1285,7 +1358,7 @@ static void recv_generator(char *fname,
2026 full_fname(backupptr));
2032 if ((f_copy = do_open(backupptr,
2033 O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
2034 @@ -1293,14 +1366,14 @@ static void recv_generator(char *fname,
2035 full_fname(backupptr));
2041 fnamecmp_type = FNAMECMP_BACKUP;
2045 rprintf(FINFO, "gen mapped %s of size %.0f\n",
2046 - fnamecmp, (double)st.st_size);
2047 + fnamecmp, (double)sx.st.st_size);
2051 @@ -1318,24 +1391,32 @@ static void recv_generator(char *fname,
2052 iflags |= ITEM_BASIS_TYPE_FOLLOWS;
2053 if (fnamecmp_type == FNAMECMP_FUZZY)
2054 iflags |= ITEM_XNAME_FOLLOWS;
2055 - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type,
2056 +#ifdef SUPPORT_ACLS
2057 + if (preserve_acls && real_ret == 0)
2058 + get_acl(fnamecmp, &real_sx);
2060 + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
2061 fuzzy_file ? fuzzy_file->basename : NULL);
2062 +#ifdef SUPPORT_ACLS
2063 + if (preserve_acls)
2064 + free_acl(&real_sx);
2069 if (preserve_hard_links && file->link_u.links)
2070 hard_link_cluster(file, ndx, itemizing, code);
2078 if (statret != 0 || whole_file) {
2079 write_sum_head(f_out, NULL);
2084 - generate_and_send_sums(fd, st.st_size, f_out, f_copy);
2085 + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy);
2089 @@ -1348,6 +1429,13 @@ static void recv_generator(char *fname,
2095 +#ifdef SUPPORT_ACLS
2096 + if (preserve_acls)
2102 void generate_files(int f_out, struct file_list *flist, char *local_name)
2103 @@ -1407,6 +1495,8 @@ void generate_files(int f_out, struct fi
2104 * notice that and let us know via the redo pipe (or its closing). */
2107 + dflt_perms = (ACCESSPERMS & ~orig_umask);
2109 for (i = 0; i < flist->count; i++) {
2110 struct file_struct *file = flist->files[i];
2116 extern int do_xfers;
2117 extern int link_dest;
2118 +extern int preserve_acls;
2119 extern int make_backups;
2120 extern int remove_source_files;
2121 extern int stdout_format_has_i;
2122 @@ -147,15 +148,19 @@ void init_hard_links(void)
2124 #ifdef SUPPORT_HARD_LINKS
2125 static int maybe_hard_link(struct file_struct *file, int ndx,
2126 - char *fname, int statret, STRUCT_STAT *st,
2127 + char *fname, int statret, statx *sxp,
2128 char *toname, STRUCT_STAT *to_st,
2129 int itemizing, enum logcode code)
2132 - if (st->st_dev == to_st->st_dev
2133 - && st->st_ino == to_st->st_ino) {
2134 + if (sxp->st.st_dev == to_st->st_dev
2135 + && sxp->st.st_ino == to_st->st_ino) {
2137 - itemize(file, ndx, statret, st,
2138 +#ifdef SUPPORT_ACLS
2139 + if (preserve_acls && !ACL_READY(*sxp))
2140 + get_acl(fname, sxp);
2142 + itemize(file, ndx, statret, sxp,
2143 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
2146 @@ -170,13 +175,13 @@ static int maybe_hard_link(struct file_s
2150 - return hard_link_one(file, ndx, fname, statret, st, toname,
2151 + return hard_link_one(file, ndx, fname, statret, sxp, toname,
2152 0, itemizing, code);
2156 int hard_link_check(struct file_struct *file, int ndx, char *fname,
2157 - int statret, STRUCT_STAT *st, int itemizing,
2158 + int statret, statx *sxp, int itemizing,
2159 enum logcode code, int skip)
2161 #ifdef SUPPORT_HARD_LINKS
2162 @@ -217,7 +222,7 @@ int hard_link_check(struct file_struct *
2163 || st2.st_ino != st3.st_ino)
2168 if (verbose < 2 || !stdout_format_has_i) {
2171 @@ -227,12 +232,16 @@ int hard_link_check(struct file_struct *
2172 if (!unchanged_file(cmpbuf, file, &st3))
2176 - if (unchanged_attrs(file, &st3))
2178 +#ifdef SUPPORT_ACLS
2179 + if (preserve_acls)
2180 + get_acl(cmpbuf, sxp);
2182 + if (unchanged_attrs(file, sxp))
2184 } while (basis_dir[++j] != NULL);
2186 - maybe_hard_link(file, ndx, fname, statret, st,
2187 + maybe_hard_link(file, ndx, fname, statret, sxp,
2188 toname, &st2, itemizing, code);
2189 if (remove_source_files == 1 && do_xfers) {
2191 @@ -250,7 +259,7 @@ int hard_link_check(struct file_struct *
2193 #ifdef SUPPORT_HARD_LINKS
2194 int hard_link_one(struct file_struct *file, int ndx, char *fname,
2195 - int statret, STRUCT_STAT *st, char *toname, int terse,
2196 + int statret, statx *sxp, char *toname, int terse,
2197 int itemizing, enum logcode code)
2199 if (do_link(toname, fname)) {
2200 @@ -266,7 +275,11 @@ int hard_link_one(struct file_struct *fi
2204 - itemize(file, ndx, statret, st,
2205 +#ifdef SUPPORT_ACLS
2206 + if (preserve_acls && statret == 0 && !ACL_READY(*sxp))
2207 + get_acl(fname, sxp);
2209 + itemize(file, ndx, statret, sxp,
2210 ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
2211 terse ? "" : toname);
2213 @@ -283,11 +296,12 @@ void hard_link_cluster(struct file_struc
2214 #ifdef SUPPORT_HARD_LINKS
2215 char hlink1[MAXPATHLEN];
2217 - STRUCT_STAT st1, st2;
2220 int statret, ndx = master;
2222 file->F_HLINDEX = FINISHED_LINK;
2223 - if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
2224 + if (link_stat(f_name(file, hlink1), &st, 0) < 0)
2226 if (!(file->flags & FLAG_HLINK_TOL)) {
2227 while (!(file->flags & FLAG_HLINK_EOL)) {
2228 @@ -301,9 +315,13 @@ void hard_link_cluster(struct file_struc
2229 if (file->F_HLINDEX != SKIPPED_LINK)
2231 hlink2 = f_name(file, NULL);
2232 - statret = link_stat(hlink2, &st2, 0);
2233 - maybe_hard_link(file, ndx, hlink2, statret, &st2,
2234 - hlink1, &st1, itemizing, code);
2235 + statret = link_stat(hlink2, &sx.st, 0);
2236 + maybe_hard_link(file, ndx, hlink2, statret, &sx,
2237 + hlink1, &st, itemizing, code);
2238 +#ifdef SUPPORT_ACLS
2239 + if (preserve_acls)
2242 if (remove_source_files == 1 && do_xfers) {
2244 SIVAL(numbuf, 0, ndx);
2245 --- old/lib/sysacls.c
2246 +++ new/lib/sysacls.c
2249 + Unix SMB/CIFS implementation.
2250 + Samba system utilities for ACL support.
2251 + Copyright (C) Jeremy Allison 2000.
2253 + This program is free software; you can redistribute it and/or modify
2254 + it under the terms of the GNU General Public License as published by
2255 + the Free Software Foundation; either version 2 of the License, or
2256 + (at your option) any later version.
2258 + This program is distributed in the hope that it will be useful,
2259 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2260 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2261 + GNU General Public License for more details.
2263 + You should have received a copy of the GNU General Public License
2264 + along with this program; if not, write to the Free Software
2265 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2269 +#include "sysacls.h" /****** ADDED ******/
2271 +#ifdef SUPPORT_ACLS
2273 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
2279 +void SAFE_FREE(void *mem)
2285 +char *uidtoname(uid_t uid)
2287 + static char idbuf[12];
2288 + struct passwd *pw;
2290 + if ((pw = getpwuid(uid)) == NULL) {
2291 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
2294 + return pw->pw_name;
2296 +/****** EXTRAS -- END ******/
2299 + This file wraps all differing system ACL interfaces into a consistent
2300 + one based on the POSIX interface. It also returns the correct errors
2301 + for older UNIX systems that don't support ACLs.
2303 + The interfaces that each ACL implementation must support are as follows :
2305 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2306 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2307 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
2308 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2309 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2310 + SMB_ACL_T sys_acl_get_fd(int fd)
2311 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
2312 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
2313 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
2314 + SMB_ACL_T sys_acl_init( int count)
2315 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2316 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2317 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2318 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2319 + int sys_acl_valid( SMB_ACL_T theacl )
2320 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2321 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2322 + int sys_acl_delete_def_file(const char *path)
2324 + This next one is not POSIX complient - but we *have* to have it !
2325 + More POSIX braindamage.
2327 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2329 + The generic POSIX free is the following call. We split this into
2330 + several different free functions as we may need to add tag info
2331 + to structures when emulating the POSIX interface.
2333 + int sys_acl_free( void *obj_p)
2335 + The calls we actually use are :
2337 + int sys_acl_free_text(char *text) - free acl_to_text
2338 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
2339 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
2343 +#if defined(HAVE_POSIX_ACLS)
2345 +/* Identity mapping - easy. */
2347 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2349 + return acl_get_entry( the_acl, entry_id, entry_p);
2352 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2354 + return acl_get_tag_type( entry_d, tag_type_p);
2357 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2359 + return acl_get_permset( entry_d, permset_p);
2362 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2364 + return acl_get_qualifier( entry_d);
2367 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2369 + return acl_get_file( path_p, type);
2372 +SMB_ACL_T sys_acl_get_fd(int fd)
2374 + return acl_get_fd(fd);
2377 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2379 + return acl_clear_perms(permset);
2382 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2384 + return acl_add_perm(permset, perm);
2387 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2389 +#if defined(HAVE_ACL_GET_PERM_NP)
2391 + * Required for TrustedBSD-based ACL implementations where
2392 + * non-POSIX.1e functions are denoted by a _np (non-portable)
2395 + return acl_get_perm_np(permset, perm);
2397 + return acl_get_perm(permset, perm);
2401 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2403 + return acl_to_text( the_acl, plen);
2406 +SMB_ACL_T sys_acl_init( int count)
2408 + return acl_init(count);
2411 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2413 + return acl_create_entry(pacl, pentry);
2416 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2418 + return acl_set_tag_type(entry, tagtype);
2421 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2423 + return acl_set_qualifier(entry, qual);
2426 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2428 + return acl_set_permset(entry, permset);
2431 +int sys_acl_valid( SMB_ACL_T theacl )
2433 + return acl_valid(theacl);
2436 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2438 + return acl_set_file(name, acltype, theacl);
2441 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2443 + return acl_set_fd(fd, theacl);
2446 +int sys_acl_delete_def_file(const char *name)
2448 + return acl_delete_def_file(name);
2451 +int sys_acl_free_text(char *text)
2453 + return acl_free(text);
2456 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2458 + return acl_free(the_acl);
2461 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
2463 + return acl_free(qual);
2466 +#elif defined(HAVE_TRU64_ACLS)
2468 + * The interface to DEC/Compaq Tru64 UNIX ACLs
2469 + * is based on Draft 13 of the POSIX spec which is
2470 + * slightly different from the Draft 16 interface.
2472 + * Also, some of the permset manipulation functions
2473 + * such as acl_clear_perm() and acl_add_perm() appear
2474 + * to be broken on Tru64 so we have to manipulate
2475 + * the permission bits in the permset directly.
2477 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2479 + SMB_ACL_ENTRY_T entry;
2481 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
2486 + if ((entry = acl_get_entry(the_acl)) != NULL) {
2491 + return errno ? -1 : 0;
2494 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
2496 + return acl_get_tag_type( entry_d, tag_type_p);
2499 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2501 + return acl_get_permset( entry_d, permset_p);
2504 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
2506 + return acl_get_qualifier( entry_d);
2509 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
2511 + return acl_get_file((char *)path_p, type);
2514 +SMB_ACL_T sys_acl_get_fd(int fd)
2516 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
2519 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
2521 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
2526 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2528 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
2533 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
2538 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
2540 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
2543 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
2545 + return acl_to_text( the_acl, plen);
2548 +SMB_ACL_T sys_acl_init( int count)
2550 + return acl_init(count);
2553 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
2555 + SMB_ACL_ENTRY_T entry;
2557 + if ((entry = acl_create_entry(pacl)) == NULL) {
2565 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
2567 + return acl_set_tag_type(entry, tagtype);
2570 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
2572 + return acl_set_qualifier(entry, qual);
2575 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
2577 + return acl_set_permset(entry, permset);
2580 +int sys_acl_valid( SMB_ACL_T theacl )
2582 + acl_entry_t entry;
2584 + return acl_valid(theacl, &entry);
2587 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
2589 + return acl_set_file((char *)name, acltype, theacl);
2592 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
2594 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
2597 +int sys_acl_delete_def_file(const char *name)
2599 + return acl_delete_def_file((char *)name);
2602 +int sys_acl_free_text(char *text)
2605 + * (void) cast and explicit return 0 are for DEC UNIX
2606 + * which just #defines acl_free_text() to be free()
2608 + (void) acl_free_text(text);
2612 +int sys_acl_free_acl(SMB_ACL_T the_acl)
2614 + return acl_free(the_acl);
2617 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2619 + return acl_free_qualifier(qual, tagtype);
2622 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
2625 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
2626 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
2630 + * Note that while this code implements sufficient functionality
2631 + * to support the sys_acl_* interfaces it does not provide all
2632 + * of the semantics of the POSIX ACL interfaces.
2634 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2635 + * from a call to sys_acl_get_entry() should not be assumed to be
2636 + * valid after calling any of the following functions, which may
2637 + * reorder the entries in the ACL.
2640 + * sys_acl_set_file()
2641 + * sys_acl_set_fd()
2645 + * The only difference between Solaris and UnixWare / OpenUNIX is
2646 + * that the #defines for the ACL operations have different names
2648 +#if defined(HAVE_UNIXWARE_ACLS)
2650 +#define SETACL ACL_SET
2651 +#define GETACL ACL_GET
2652 +#define GETACLCNT ACL_CNT
2657 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2659 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2664 + if (entry_p == NULL) {
2669 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2673 + if (acl_d->next < 0) {
2678 + if (acl_d->next >= acl_d->count) {
2682 + *entry_p = &acl_d->acl[acl_d->next++];
2687 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2689 + *type_p = entry_d->a_type;
2694 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2696 + *permset_p = &entry_d->a_perm;
2701 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2703 + if (entry_d->a_type != SMB_ACL_USER
2704 + && entry_d->a_type != SMB_ACL_GROUP) {
2709 + return &entry_d->a_id;
2713 + * There is no way of knowing what size the ACL returned by
2714 + * GETACL will be unless you first call GETACLCNT which means
2715 + * making an additional system call.
2717 + * In the hope of avoiding the cost of the additional system
2718 + * call in most cases, we initially allocate enough space for
2719 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2720 + * be too small then we use GETACLCNT to find out the actual
2721 + * size, reallocate the ACL buffer, and then call GETACL again.
2724 +#define INITIAL_ACL_SIZE 16
2726 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2729 + int count; /* # of ACL entries allocated */
2730 + int naccess; /* # of access ACL entries */
2731 + int ndefault; /* # of default ACL entries */
2733 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2738 + count = INITIAL_ACL_SIZE;
2739 + if ((acl_d = sys_acl_init(count)) == NULL) {
2744 + * If there isn't enough space for the ACL entries we use
2745 + * GETACLCNT to determine the actual number of ACL entries
2746 + * reallocate and try again. This is in a loop because it
2747 + * is possible that someone else could modify the ACL and
2748 + * increase the number of entries between the call to
2749 + * GETACLCNT and the call to GETACL.
2751 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2752 + && errno == ENOSPC) {
2754 + sys_acl_free_acl(acl_d);
2756 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2760 + if ((acl_d = sys_acl_init(count)) == NULL) {
2766 + sys_acl_free_acl(acl_d);
2771 + * calculate the number of access and default ACL entries
2773 + * Note: we assume that the acl() system call returned a
2774 + * well formed ACL which is sorted so that all of the
2775 + * access ACL entries preceed any default ACL entries
2777 + for (naccess = 0; naccess < count; naccess++) {
2778 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2781 + ndefault = count - naccess;
2784 + * if the caller wants the default ACL we have to copy
2785 + * the entries down to the start of the acl[] buffer
2786 + * and mask out the ACL_DEFAULT flag from the type field
2788 + if (type == SMB_ACL_TYPE_DEFAULT) {
2791 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2792 + acl_d->acl[i] = acl_d->acl[j];
2793 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2796 + acl_d->count = ndefault;
2798 + acl_d->count = naccess;
2804 +SMB_ACL_T sys_acl_get_fd(int fd)
2807 + int count; /* # of ACL entries allocated */
2808 + int naccess; /* # of access ACL entries */
2810 + count = INITIAL_ACL_SIZE;
2811 + if ((acl_d = sys_acl_init(count)) == NULL) {
2815 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2816 + && errno == ENOSPC) {
2818 + sys_acl_free_acl(acl_d);
2820 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2824 + if ((acl_d = sys_acl_init(count)) == NULL) {
2830 + sys_acl_free_acl(acl_d);
2835 + * calculate the number of access ACL entries
2837 + for (naccess = 0; naccess < count; naccess++) {
2838 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2842 + acl_d->count = naccess;
2847 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2854 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2856 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2857 + && perm != SMB_ACL_EXECUTE) {
2862 + if (permset_d == NULL) {
2867 + *permset_d |= perm;
2872 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2874 + return *permset_d & perm;
2877 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2884 + * use an initial estimate of 20 bytes per ACL entry
2885 + * when allocating memory for the text representation
2889 + maxlen = 20 * acl_d->count;
2890 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2895 + for (i = 0; i < acl_d->count; i++) {
2896 + struct acl *ap = &acl_d->acl[i];
2905 + switch (ap->a_type) {
2907 + * for debugging purposes it's probably more
2908 + * useful to dump unknown tag types rather
2909 + * than just returning an error
2912 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2915 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2920 + case SMB_ACL_USER:
2921 + id = uidtoname(ap->a_id);
2922 + case SMB_ACL_USER_OBJ:
2926 + case SMB_ACL_GROUP:
2927 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2928 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2934 + case SMB_ACL_GROUP_OBJ:
2938 + case SMB_ACL_OTHER:
2942 + case SMB_ACL_MASK:
2948 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2949 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2950 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2953 + /* <tag> : <qualifier> : rwx \n \0 */
2954 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2957 + * If this entry would overflow the buffer
2958 + * allocate enough additional memory for this
2959 + * entry and an estimate of another 20 bytes
2960 + * for each entry still to be processed
2962 + if ((len + nbytes) > maxlen) {
2963 + char *oldtext = text;
2965 + maxlen += nbytes + 20 * (acl_d->count - i);
2967 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2968 + SAFE_FREE(oldtext);
2974 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2975 + len += nbytes - 1;
2984 +SMB_ACL_T sys_acl_init(int count)
2994 + * note that since the definition of the structure pointed
2995 + * to by the SMB_ACL_T includes the first element of the
2996 + * acl[] array, this actually allocates an ACL with room
2997 + * for (count+1) entries
2999 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3004 + a->size = count + 1;
3012 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3015 + SMB_ACL_ENTRY_T entry_d;
3017 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3022 + if (acl_d->count >= acl_d->size) {
3027 + entry_d = &acl_d->acl[acl_d->count++];
3028 + entry_d->a_type = 0;
3029 + entry_d->a_id = -1;
3030 + entry_d->a_perm = 0;
3031 + *entry_p = entry_d;
3036 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3038 + switch (tag_type) {
3039 + case SMB_ACL_USER:
3040 + case SMB_ACL_USER_OBJ:
3041 + case SMB_ACL_GROUP:
3042 + case SMB_ACL_GROUP_OBJ:
3043 + case SMB_ACL_OTHER:
3044 + case SMB_ACL_MASK:
3045 + entry_d->a_type = tag_type;
3055 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3057 + if (entry_d->a_type != SMB_ACL_GROUP
3058 + && entry_d->a_type != SMB_ACL_USER) {
3063 + entry_d->a_id = *((id_t *)qual_p);
3068 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3070 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3074 + entry_d->a_perm = *permset_d;
3080 + * sort the ACL and check it for validity
3082 + * if it's a minimal ACL with only 4 entries then we
3083 + * need to recalculate the mask permissions to make
3084 + * sure that they are the same as the GROUP_OBJ
3085 + * permissions as required by the UnixWare acl() system call.
3087 + * (note: since POSIX allows minimal ACLs which only contain
3088 + * 3 entries - ie there is no mask entry - we should, in theory,
3089 + * check for this and add a mask entry if necessary - however
3090 + * we "know" that the caller of this interface always specifies
3091 + * a mask so, in practice "this never happens" (tm) - if it *does*
3092 + * happen aclsort() will fail and return an error and someone will
3093 + * have to fix it ...)
3096 +static int acl_sort(SMB_ACL_T acl_d)
3098 + int fixmask = (acl_d->count <= 4);
3100 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
3107 +int sys_acl_valid(SMB_ACL_T acl_d)
3109 + return acl_sort(acl_d);
3112 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3115 + struct acl *acl_p;
3117 + struct acl *acl_buf = NULL;
3120 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3125 + if (acl_sort(acl_d) != 0) {
3129 + acl_p = &acl_d->acl[0];
3130 + acl_count = acl_d->count;
3133 + * if it's a directory there is extra work to do
3134 + * since the acl() system call will replace both
3135 + * the access ACLs and the default ACLs (if any)
3137 + if (stat(name, &s) != 0) {
3140 + if (S_ISDIR(s.st_mode)) {
3141 + SMB_ACL_T acc_acl;
3142 + SMB_ACL_T def_acl;
3143 + SMB_ACL_T tmp_acl;
3146 + if (type == SMB_ACL_TYPE_ACCESS) {
3148 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3152 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3155 + if (tmp_acl == NULL) {
3160 + * allocate a temporary buffer for the complete ACL
3162 + acl_count = acc_acl->count + def_acl->count;
3163 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3165 + if (acl_buf == NULL) {
3166 + sys_acl_free_acl(tmp_acl);
3172 + * copy the access control and default entries into the buffer
3174 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3175 + acc_acl->count * sizeof(acl_buf[0]));
3177 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3178 + def_acl->count * sizeof(acl_buf[0]));
3181 + * set the ACL_DEFAULT flag on the default entries
3183 + for (i = acc_acl->count; i < acl_count; i++) {
3184 + acl_buf[i].a_type |= ACL_DEFAULT;
3187 + sys_acl_free_acl(tmp_acl);
3189 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3194 + ret = acl(name, SETACL, acl_count, acl_p);
3196 + SAFE_FREE(acl_buf);
3201 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3203 + if (acl_sort(acl_d) != 0) {
3207 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
3210 +int sys_acl_delete_def_file(const char *path)
3216 + * fetching the access ACL and rewriting it has
3217 + * the effect of deleting the default ACL
3219 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3223 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
3225 + sys_acl_free_acl(acl_d);
3230 +int sys_acl_free_text(char *text)
3236 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3242 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
3247 +#elif defined(HAVE_HPUX_ACLS)
3251 + * Based on the Solaris/SCO code - with modifications.
3255 + * Note that while this code implements sufficient functionality
3256 + * to support the sys_acl_* interfaces it does not provide all
3257 + * of the semantics of the POSIX ACL interfaces.
3259 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
3260 + * from a call to sys_acl_get_entry() should not be assumed to be
3261 + * valid after calling any of the following functions, which may
3262 + * reorder the entries in the ACL.
3265 + * sys_acl_set_file()
3266 + * sys_acl_set_fd()
3269 +/* This checks if the POSIX ACL system call is defined */
3270 +/* which basically corresponds to whether JFS 3.3 or */
3271 +/* higher is installed. If acl() was called when it */
3272 +/* isn't defined, it causes the process to core dump */
3273 +/* so it is important to check this and avoid acl() */
3274 +/* calls if it isn't there. */
3276 +static BOOL hpux_acl_call_presence(void)
3279 + shl_t handle = NULL;
3282 + static BOOL already_checked=0;
3284 + if(already_checked)
3288 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
3290 + if(ret_val != 0) {
3291 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
3292 + ret_val, errno, strerror(errno)));
3293 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
3297 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
3299 + already_checked = True;
3303 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3305 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3310 + if (entry_p == NULL) {
3315 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3319 + if (acl_d->next < 0) {
3324 + if (acl_d->next >= acl_d->count) {
3328 + *entry_p = &acl_d->acl[acl_d->next++];
3333 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3335 + *type_p = entry_d->a_type;
3340 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3342 + *permset_p = &entry_d->a_perm;
3347 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3349 + if (entry_d->a_type != SMB_ACL_USER
3350 + && entry_d->a_type != SMB_ACL_GROUP) {
3355 + return &entry_d->a_id;
3359 + * There is no way of knowing what size the ACL returned by
3360 + * ACL_GET will be unless you first call ACL_CNT which means
3361 + * making an additional system call.
3363 + * In the hope of avoiding the cost of the additional system
3364 + * call in most cases, we initially allocate enough space for
3365 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
3366 + * be too small then we use ACL_CNT to find out the actual
3367 + * size, reallocate the ACL buffer, and then call ACL_GET again.
3370 +#define INITIAL_ACL_SIZE 16
3372 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3375 + int count; /* # of ACL entries allocated */
3376 + int naccess; /* # of access ACL entries */
3377 + int ndefault; /* # of default ACL entries */
3379 + if(hpux_acl_call_presence() == False) {
3380 + /* Looks like we don't have the acl() system call on HPUX.
3381 + * May be the system doesn't have the latest version of JFS.
3386 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3391 + count = INITIAL_ACL_SIZE;
3392 + if ((acl_d = sys_acl_init(count)) == NULL) {
3397 + * If there isn't enough space for the ACL entries we use
3398 + * ACL_CNT to determine the actual number of ACL entries
3399 + * reallocate and try again. This is in a loop because it
3400 + * is possible that someone else could modify the ACL and
3401 + * increase the number of entries between the call to
3402 + * ACL_CNT and the call to ACL_GET.
3404 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
3406 + sys_acl_free_acl(acl_d);
3408 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
3412 + if ((acl_d = sys_acl_init(count)) == NULL) {
3418 + sys_acl_free_acl(acl_d);
3423 + * calculate the number of access and default ACL entries
3425 + * Note: we assume that the acl() system call returned a
3426 + * well formed ACL which is sorted so that all of the
3427 + * access ACL entries preceed any default ACL entries
3429 + for (naccess = 0; naccess < count; naccess++) {
3430 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
3433 + ndefault = count - naccess;
3436 + * if the caller wants the default ACL we have to copy
3437 + * the entries down to the start of the acl[] buffer
3438 + * and mask out the ACL_DEFAULT flag from the type field
3440 + if (type == SMB_ACL_TYPE_DEFAULT) {
3443 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
3444 + acl_d->acl[i] = acl_d->acl[j];
3445 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
3448 + acl_d->count = ndefault;
3450 + acl_d->count = naccess;
3456 +SMB_ACL_T sys_acl_get_fd(int fd)
3459 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3462 + files_struct *fsp = file_find_fd(fd);
3464 + if (fsp == NULL) {
3470 + * We know we're in the same conn context. So we
3471 + * can use the relative path.
3474 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
3477 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3484 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3486 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3487 + && perm != SMB_ACL_EXECUTE) {
3492 + if (permset_d == NULL) {
3497 + *permset_d |= perm;
3502 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3504 + return *permset_d & perm;
3507 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3514 + * use an initial estimate of 20 bytes per ACL entry
3515 + * when allocating memory for the text representation
3519 + maxlen = 20 * acl_d->count;
3520 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
3525 + for (i = 0; i < acl_d->count; i++) {
3526 + struct acl *ap = &acl_d->acl[i];
3535 + switch (ap->a_type) {
3537 + * for debugging purposes it's probably more
3538 + * useful to dump unknown tag types rather
3539 + * than just returning an error
3542 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
3545 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3550 + case SMB_ACL_USER:
3551 + id = uidtoname(ap->a_id);
3552 + case SMB_ACL_USER_OBJ:
3556 + case SMB_ACL_GROUP:
3557 + if ((gr = getgrgid(ap->a_id)) == NULL) {
3558 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
3564 + case SMB_ACL_GROUP_OBJ:
3568 + case SMB_ACL_OTHER:
3572 + case SMB_ACL_MASK:
3578 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
3579 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
3580 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
3583 + /* <tag> : <qualifier> : rwx \n \0 */
3584 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
3587 + * If this entry would overflow the buffer
3588 + * allocate enough additional memory for this
3589 + * entry and an estimate of another 20 bytes
3590 + * for each entry still to be processed
3592 + if ((len + nbytes) > maxlen) {
3593 + char *oldtext = text;
3595 + maxlen += nbytes + 20 * (acl_d->count - i);
3597 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
3604 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
3605 + len += nbytes - 1;
3614 +SMB_ACL_T sys_acl_init(int count)
3624 + * note that since the definition of the structure pointed
3625 + * to by the SMB_ACL_T includes the first element of the
3626 + * acl[] array, this actually allocates an ACL with room
3627 + * for (count+1) entries
3629 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3634 + a->size = count + 1;
3642 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3645 + SMB_ACL_ENTRY_T entry_d;
3647 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3652 + if (acl_d->count >= acl_d->size) {
3657 + entry_d = &acl_d->acl[acl_d->count++];
3658 + entry_d->a_type = 0;
3659 + entry_d->a_id = -1;
3660 + entry_d->a_perm = 0;
3661 + *entry_p = entry_d;
3666 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3668 + switch (tag_type) {
3669 + case SMB_ACL_USER:
3670 + case SMB_ACL_USER_OBJ:
3671 + case SMB_ACL_GROUP:
3672 + case SMB_ACL_GROUP_OBJ:
3673 + case SMB_ACL_OTHER:
3674 + case SMB_ACL_MASK:
3675 + entry_d->a_type = tag_type;
3685 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3687 + if (entry_d->a_type != SMB_ACL_GROUP
3688 + && entry_d->a_type != SMB_ACL_USER) {
3693 + entry_d->a_id = *((id_t *)qual_p);
3698 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3700 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3704 + entry_d->a_perm = *permset_d;
3709 +/* Structure to capture the count for each type of ACE. */
3711 +struct hpux_acl_types {
3715 + int n_def_user_obj;
3720 + int n_def_group_obj;
3724 + int n_def_other_obj;
3727 + int n_def_class_obj;
3729 + int n_illegal_obj;
3733 + * Counts the different number of objects in a given array of ACL
3737 + * acl_count - Count of ACLs in the array of ACL strucutres.
3738 + * aclp - Array of ACL structures.
3739 + * acl_type_count - Pointer to acl_types structure. Should already be
3743 + * acl_type_count - This structure is filled up with counts of various
3747 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3751 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3753 + for(i=0;i<acl_count;i++) {
3754 + switch(aclp[i].a_type) {
3756 + acl_type_count->n_user++;
3759 + acl_type_count->n_user_obj++;
3761 + case DEF_USER_OBJ:
3762 + acl_type_count->n_def_user_obj++;
3765 + acl_type_count->n_group++;
3768 + acl_type_count->n_group_obj++;
3770 + case DEF_GROUP_OBJ:
3771 + acl_type_count->n_def_group_obj++;
3774 + acl_type_count->n_other_obj++;
3776 + case DEF_OTHER_OBJ:
3777 + acl_type_count->n_def_other_obj++;
3780 + acl_type_count->n_class_obj++;
3782 + case DEF_CLASS_OBJ:
3783 + acl_type_count->n_def_class_obj++;
3786 + acl_type_count->n_def_user++;
3789 + acl_type_count->n_def_group++;
3792 + acl_type_count->n_illegal_obj++;
3798 +/* swap_acl_entries: Swaps two ACL entries.
3800 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3803 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3805 + struct acl temp_acl;
3807 + temp_acl.a_type = aclp0->a_type;
3808 + temp_acl.a_id = aclp0->a_id;
3809 + temp_acl.a_perm = aclp0->a_perm;
3811 + aclp0->a_type = aclp1->a_type;
3812 + aclp0->a_id = aclp1->a_id;
3813 + aclp0->a_perm = aclp1->a_perm;
3815 + aclp1->a_type = temp_acl.a_type;
3816 + aclp1->a_id = temp_acl.a_id;
3817 + aclp1->a_perm = temp_acl.a_perm;
3820 +/* prohibited_duplicate_type
3821 + * Identifies if given ACL type can have duplicate entries or
3824 + * Inputs: acl_type - ACL Type.
3830 + * True - If the ACL type matches any of the prohibited types.
3831 + * False - If the ACL type doesn't match any of the prohibited types.
3834 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3836 + switch(acl_type) {
3847 +/* get_needed_class_perm
3848 + * Returns the permissions of a ACL structure only if the ACL
3849 + * type matches one of the pre-determined types for computing
3850 + * CLASS_OBJ permissions.
3852 + * Inputs: aclp - Pointer to ACL structure.
3855 +static int hpux_get_needed_class_perm(struct acl *aclp)
3857 + switch(aclp->a_type) {
3861 + case DEF_USER_OBJ:
3863 + case DEF_GROUP_OBJ:
3865 + case DEF_CLASS_OBJ:
3866 + case DEF_OTHER_OBJ:
3867 + return aclp->a_perm;
3873 +/* acl_sort for HPUX.
3874 + * Sorts the array of ACL structures as per the description in
3875 + * aclsort man page. Refer to aclsort man page for more details
3879 + * acl_count - Count of ACLs in the array of ACL structures.
3880 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3882 + * aclp - Array of ACL structures.
3886 + * aclp - Sorted array of ACL structures.
3890 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3891 + * debug log in case of failure.
3894 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3896 +#if !defined(HAVE_HPUX_ACLSORT)
3898 + * The aclsort() system call is availabe on the latest HPUX General
3899 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3900 + * function. Because, we don't want to update to a new
3901 + * HPUX GR bundle just for aclsort() call.
3904 + struct hpux_acl_types acl_obj_count;
3905 + int n_class_obj_perm = 0;
3909 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3913 + if(aclp == NULL) {
3914 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3918 + /* Count different types of ACLs in the ACLs array */
3920 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3922 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3923 + * CLASS_OBJ and OTHER_OBJ
3926 + if( (acl_obj_count.n_user_obj != 1) ||
3927 + (acl_obj_count.n_group_obj != 1) ||
3928 + (acl_obj_count.n_class_obj != 1) ||
3929 + (acl_obj_count.n_other_obj != 1)
3931 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3932 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3936 + /* If any of the default objects are present, there should be only
3937 + * one of them each.
3940 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3941 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3942 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3943 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3947 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3950 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3951 + * same ACL type, sort by ACL id.
3953 + * I am using the trival kind of sorting method here because, performance isn't
3954 + * really effected by the ACLs feature. More over there aren't going to be more
3955 + * than 17 entries on HPUX.
3958 + for(i=0; i<acl_count;i++) {
3959 + for (j=i+1; j<acl_count; j++) {
3960 + if( aclp[i].a_type > aclp[j].a_type ) {
3961 + /* ACL entries out of order, swap them */
3963 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3965 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3967 + /* ACL entries of same type, sort by id */
3969 + if(aclp[i].a_id > aclp[j].a_id) {
3970 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3971 + } else if (aclp[i].a_id == aclp[j].a_id) {
3972 + /* We have a duplicate entry. */
3973 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3974 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3975 + aclp[i].a_type, aclp[i].a_id));
3984 + /* set the class obj permissions to the computed one. */
3986 + int n_class_obj_index = -1;
3988 + for(i=0;i<acl_count;i++) {
3989 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3991 + if(aclp[i].a_type == CLASS_OBJ)
3992 + n_class_obj_index = i;
3994 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3999 + return aclsort(acl_count, calclass, aclp);
4004 + * sort the ACL and check it for validity
4006 + * if it's a minimal ACL with only 4 entries then we
4007 + * need to recalculate the mask permissions to make
4008 + * sure that they are the same as the GROUP_OBJ
4009 + * permissions as required by the UnixWare acl() system call.
4011 + * (note: since POSIX allows minimal ACLs which only contain
4012 + * 3 entries - ie there is no mask entry - we should, in theory,
4013 + * check for this and add a mask entry if necessary - however
4014 + * we "know" that the caller of this interface always specifies
4015 + * a mask so, in practice "this never happens" (tm) - if it *does*
4016 + * happen aclsort() will fail and return an error and someone will
4017 + * have to fix it ...)
4020 +static int acl_sort(SMB_ACL_T acl_d)
4022 + int fixmask = (acl_d->count <= 4);
4024 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
4031 +int sys_acl_valid(SMB_ACL_T acl_d)
4033 + return acl_sort(acl_d);
4036 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4039 + struct acl *acl_p;
4041 + struct acl *acl_buf = NULL;
4044 + if(hpux_acl_call_presence() == False) {
4045 + /* Looks like we don't have the acl() system call on HPUX.
4046 + * May be the system doesn't have the latest version of JFS.
4052 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
4057 + if (acl_sort(acl_d) != 0) {
4061 + acl_p = &acl_d->acl[0];
4062 + acl_count = acl_d->count;
4065 + * if it's a directory there is extra work to do
4066 + * since the acl() system call will replace both
4067 + * the access ACLs and the default ACLs (if any)
4069 + if (stat(name, &s) != 0) {
4072 + if (S_ISDIR(s.st_mode)) {
4073 + SMB_ACL_T acc_acl;
4074 + SMB_ACL_T def_acl;
4075 + SMB_ACL_T tmp_acl;
4078 + if (type == SMB_ACL_TYPE_ACCESS) {
4080 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
4084 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
4087 + if (tmp_acl == NULL) {
4092 + * allocate a temporary buffer for the complete ACL
4094 + acl_count = acc_acl->count + def_acl->count;
4095 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
4097 + if (acl_buf == NULL) {
4098 + sys_acl_free_acl(tmp_acl);
4104 + * copy the access control and default entries into the buffer
4106 + memcpy(&acl_buf[0], &acc_acl->acl[0],
4107 + acc_acl->count * sizeof(acl_buf[0]));
4109 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
4110 + def_acl->count * sizeof(acl_buf[0]));
4113 + * set the ACL_DEFAULT flag on the default entries
4115 + for (i = acc_acl->count; i < acl_count; i++) {
4116 + acl_buf[i].a_type |= ACL_DEFAULT;
4119 + sys_acl_free_acl(tmp_acl);
4121 + } else if (type != SMB_ACL_TYPE_ACCESS) {
4126 + ret = acl(name, ACL_SET, acl_count, acl_p);
4135 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4138 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
4141 + files_struct *fsp = file_find_fd(fd);
4143 + if (fsp == NULL) {
4148 + if (acl_sort(acl_d) != 0) {
4153 + * We know we're in the same conn context. So we
4154 + * can use the relative path.
4157 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
4160 +int sys_acl_delete_def_file(const char *path)
4166 + * fetching the access ACL and rewriting it has
4167 + * the effect of deleting the default ACL
4169 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
4173 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
4175 + sys_acl_free_acl(acl_d);
4180 +int sys_acl_free_text(char *text)
4186 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4192 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4197 +#elif defined(HAVE_IRIX_ACLS)
4199 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4201 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
4206 + if (entry_p == NULL) {
4211 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
4215 + if (acl_d->next < 0) {
4220 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
4224 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
4229 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
4231 + *type_p = entry_d->ae_tag;
4236 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4238 + *permset_p = entry_d;
4243 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
4245 + if (entry_d->ae_tag != SMB_ACL_USER
4246 + && entry_d->ae_tag != SMB_ACL_GROUP) {
4251 + return &entry_d->ae_id;
4254 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
4258 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4262 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
4267 + a->freeaclp = True;
4271 +SMB_ACL_T sys_acl_get_fd(int fd)
4275 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
4279 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
4284 + a->freeaclp = True;
4288 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
4290 + permset_d->ae_perm = 0;
4295 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4297 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
4298 + && perm != SMB_ACL_EXECUTE) {
4303 + if (permset_d == NULL) {
4308 + permset_d->ae_perm |= perm;
4313 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
4315 + return permset_d->ae_perm & perm;
4318 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
4320 + return acl_to_text(acl_d->aclp, len_p);
4323 +SMB_ACL_T sys_acl_init(int count)
4332 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
4338 + a->freeaclp = False;
4339 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
4340 + a->aclp->acl_cnt = 0;
4346 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
4349 + SMB_ACL_ENTRY_T entry_d;
4351 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
4356 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
4361 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
4362 + entry_d->ae_tag = 0;
4363 + entry_d->ae_id = 0;
4364 + entry_d->ae_perm = 0;
4365 + *entry_p = entry_d;
4370 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
4372 + switch (tag_type) {
4373 + case SMB_ACL_USER:
4374 + case SMB_ACL_USER_OBJ:
4375 + case SMB_ACL_GROUP:
4376 + case SMB_ACL_GROUP_OBJ:
4377 + case SMB_ACL_OTHER:
4378 + case SMB_ACL_MASK:
4379 + entry_d->ae_tag = tag_type;
4389 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
4391 + if (entry_d->ae_tag != SMB_ACL_GROUP
4392 + && entry_d->ae_tag != SMB_ACL_USER) {
4397 + entry_d->ae_id = *((id_t *)qual_p);
4402 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
4404 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
4408 + entry_d->ae_perm = permset_d->ae_perm;
4413 +int sys_acl_valid(SMB_ACL_T acl_d)
4415 + return acl_valid(acl_d->aclp);
4418 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
4420 + return acl_set_file(name, type, acl_d->aclp);
4423 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
4425 + return acl_set_fd(fd, acl_d->aclp);
4428 +int sys_acl_delete_def_file(const char *name)
4430 + return acl_delete_def_file(name);
4433 +int sys_acl_free_text(char *text)
4435 + return acl_free(text);
4438 +int sys_acl_free_acl(SMB_ACL_T acl_d)
4440 + if (acl_d->freeaclp) {
4441 + acl_free(acl_d->aclp);
4447 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4452 +#elif defined(HAVE_AIX_ACLS)
4454 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4456 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4458 + struct acl_entry_link *link;
4459 + struct new_acl_entry *entry;
4462 + DEBUG(10,("This is the count: %d\n",theacl->count));
4464 + /* Check if count was previously set to -1. *
4465 + * If it was, that means we reached the end *
4466 + * of the acl last time. */
4467 + if(theacl->count == -1)
4471 + /* To get to the next acl, traverse linked list until index *
4472 + * of acl matches the count we are keeping. This count is *
4473 + * incremented each time we return an acl entry. */
4475 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
4476 + link = link->nextp;
4478 + entry = *entry_p = link->entryp;
4480 + DEBUG(10,("*entry_p is %d\n",entry_p));
4481 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
4483 + /* Increment count */
4485 + if(link->nextp == NULL)
4486 + theacl->count = -1;
4491 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4493 + /* Initialize tag type */
4496 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
4498 + /* Depending on what type of entry we have, *
4499 + * return tag type. */
4500 + switch(entry_d->ace_id->id_type) {
4502 + *tag_type_p = SMB_ACL_USER;
4505 + *tag_type_p = SMB_ACL_GROUP;
4508 + case SMB_ACL_USER_OBJ:
4509 + case SMB_ACL_GROUP_OBJ:
4510 + case SMB_ACL_OTHER:
4511 + *tag_type_p = entry_d->ace_id->id_type;
4521 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4523 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
4524 + *permset_p = &entry_d->ace_access;
4525 + DEBUG(10,("**permset_p is %d\n",**permset_p));
4526 + if(!(**permset_p & S_IXUSR) &&
4527 + !(**permset_p & S_IWUSR) &&
4528 + !(**permset_p & S_IRUSR) &&
4529 + (**permset_p != 0))
4532 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
4536 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4538 + return(entry_d->ace_id->id_data);
4541 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4543 + struct acl *file_acl = (struct acl *)NULL;
4544 + struct acl_entry *acl_entry;
4545 + struct new_acl_entry *new_acl_entry;
4546 + struct ace_id *idp;
4547 + struct acl_entry_link *acl_entry_link;
4548 + struct acl_entry_link *acl_entry_link_head;
4553 + /* AIX has no DEFAULT */
4554 + if ( type == SMB_ACL_TYPE_DEFAULT ) {
4559 + /* Get the acl using statacl */
4561 + DEBUG(10,("Entering sys_acl_get_file\n"));
4562 + DEBUG(10,("path_p is %s\n",path_p));
4564 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4566 + if(file_acl == NULL) {
4568 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
4572 + memset(file_acl,0,BUFSIZ);
4574 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
4576 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
4577 + SAFE_FREE(file_acl);
4581 + DEBUG(10,("Got facl and returned it\n"));
4583 + /* Point to the first acl entry in the acl */
4584 + acl_entry = file_acl->acl_ext;
4586 + /* Begin setting up the head of the linked list *
4587 + * that will be used for the storing the acl *
4588 + * in a way that is useful for the posix_acls.c *
4591 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4592 + if(acl_entry_link_head == NULL)
4595 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4596 + if(acl_entry_link->entryp == NULL) {
4597 + SAFE_FREE(file_acl);
4599 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4603 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4604 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4606 + /* Check if the extended acl bit is on. *
4607 + * If it isn't, do not show the *
4608 + * contents of the acl since AIX intends *
4609 + * the extended info to remain unused */
4611 + if(file_acl->acl_mode & S_IXACL){
4612 + /* while we are not pointing to the very end */
4613 + while(acl_entry < acl_last(file_acl)) {
4614 + /* before we malloc anything, make sure this is */
4615 + /* a valid acl entry and one that we want to map */
4616 + idp = id_nxt(acl_entry->ace_id);
4617 + if((acl_entry->ace_type == ACC_SPECIFY ||
4618 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4619 + acl_entry = acl_nxt(acl_entry);
4623 + idp = acl_entry->ace_id;
4625 + /* Check if this is the first entry in the linked list. *
4626 + * The first entry needs to keep prevp pointing to NULL *
4627 + * and already has entryp allocated. */
4629 + if(acl_entry_link_head->count != 0) {
4630 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4632 + if(acl_entry_link->nextp == NULL) {
4633 + SAFE_FREE(file_acl);
4635 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4639 + acl_entry_link->nextp->prevp = acl_entry_link;
4640 + acl_entry_link = acl_entry_link->nextp;
4641 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4642 + if(acl_entry_link->entryp == NULL) {
4643 + SAFE_FREE(file_acl);
4645 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4648 + acl_entry_link->nextp = NULL;
4651 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4653 + /* Don't really need this since all types are going *
4654 + * to be specified but, it's better than leaving it 0 */
4656 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4658 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4660 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4662 + /* The access in the acl entries must be left shifted by *
4663 + * three bites, because they will ultimately be compared *
4664 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4666 + switch(acl_entry->ace_type){
4669 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4670 + acl_entry_link->entryp->ace_access <<= 6;
4671 + acl_entry_link_head->count++;
4674 + /* Since there is no way to return a DENY acl entry *
4675 + * change to PERMIT and then shift. */
4676 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4677 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4678 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4679 + acl_entry_link->entryp->ace_access <<= 6;
4680 + acl_entry_link_head->count++;
4686 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4687 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4689 + acl_entry = acl_nxt(acl_entry);
4691 + } /* end of if enabled */
4693 + /* Since owner, group, other acl entries are not *
4694 + * part of the acl entries in an acl, they must *
4695 + * be dummied up to become part of the list. */
4697 + for( i = 1; i < 4; i++) {
4698 + DEBUG(10,("i is %d\n",i));
4699 + if(acl_entry_link_head->count != 0) {
4700 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4701 + if(acl_entry_link->nextp == NULL) {
4702 + SAFE_FREE(file_acl);
4704 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4708 + acl_entry_link->nextp->prevp = acl_entry_link;
4709 + acl_entry_link = acl_entry_link->nextp;
4710 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4711 + if(acl_entry_link->entryp == NULL) {
4712 + SAFE_FREE(file_acl);
4714 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4719 + acl_entry_link->nextp = NULL;
4721 + new_acl_entry = acl_entry_link->entryp;
4722 + idp = new_acl_entry->ace_id;
4724 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4725 + new_acl_entry->ace_type = ACC_PERMIT;
4726 + idp->id_len = sizeof(struct ace_id);
4727 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4728 + memset(idp->id_data,0,sizeof(uid_t));
4732 + new_acl_entry->ace_access = file_acl->g_access << 6;
4733 + idp->id_type = SMB_ACL_GROUP_OBJ;
4737 + new_acl_entry->ace_access = file_acl->o_access << 6;
4738 + idp->id_type = SMB_ACL_OTHER;
4742 + new_acl_entry->ace_access = file_acl->u_access << 6;
4743 + idp->id_type = SMB_ACL_USER_OBJ;
4751 + acl_entry_link_head->count++;
4752 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4755 + acl_entry_link_head->count = 0;
4756 + SAFE_FREE(file_acl);
4758 + return(acl_entry_link_head);
4761 +SMB_ACL_T sys_acl_get_fd(int fd)
4763 + struct acl *file_acl = (struct acl *)NULL;
4764 + struct acl_entry *acl_entry;
4765 + struct new_acl_entry *new_acl_entry;
4766 + struct ace_id *idp;
4767 + struct acl_entry_link *acl_entry_link;
4768 + struct acl_entry_link *acl_entry_link_head;
4773 + /* Get the acl using fstatacl */
4775 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4776 + DEBUG(10,("fd is %d\n",fd));
4777 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4779 + if(file_acl == NULL) {
4781 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4785 + memset(file_acl,0,BUFSIZ);
4787 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4789 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4790 + SAFE_FREE(file_acl);
4794 + DEBUG(10,("Got facl and returned it\n"));
4796 + /* Point to the first acl entry in the acl */
4798 + acl_entry = file_acl->acl_ext;
4799 + /* Begin setting up the head of the linked list *
4800 + * that will be used for the storing the acl *
4801 + * in a way that is useful for the posix_acls.c *
4804 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4805 + if(acl_entry_link_head == NULL){
4806 + SAFE_FREE(file_acl);
4810 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4812 + if(acl_entry_link->entryp == NULL) {
4814 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4815 + SAFE_FREE(file_acl);
4819 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4820 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4822 + /* Check if the extended acl bit is on. *
4823 + * If it isn't, do not show the *
4824 + * contents of the acl since AIX intends *
4825 + * the extended info to remain unused */
4827 + if(file_acl->acl_mode & S_IXACL){
4828 + /* while we are not pointing to the very end */
4829 + while(acl_entry < acl_last(file_acl)) {
4830 + /* before we malloc anything, make sure this is */
4831 + /* a valid acl entry and one that we want to map */
4833 + idp = id_nxt(acl_entry->ace_id);
4834 + if((acl_entry->ace_type == ACC_SPECIFY ||
4835 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4836 + acl_entry = acl_nxt(acl_entry);
4840 + idp = acl_entry->ace_id;
4842 + /* Check if this is the first entry in the linked list. *
4843 + * The first entry needs to keep prevp pointing to NULL *
4844 + * and already has entryp allocated. */
4846 + if(acl_entry_link_head->count != 0) {
4847 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4848 + if(acl_entry_link->nextp == NULL) {
4850 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4851 + SAFE_FREE(file_acl);
4854 + acl_entry_link->nextp->prevp = acl_entry_link;
4855 + acl_entry_link = acl_entry_link->nextp;
4856 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4857 + if(acl_entry_link->entryp == NULL) {
4859 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4860 + SAFE_FREE(file_acl);
4864 + acl_entry_link->nextp = NULL;
4867 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4869 + /* Don't really need this since all types are going *
4870 + * to be specified but, it's better than leaving it 0 */
4872 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4873 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4875 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4877 + /* The access in the acl entries must be left shifted by *
4878 + * three bites, because they will ultimately be compared *
4879 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4881 + switch(acl_entry->ace_type){
4884 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4885 + acl_entry_link->entryp->ace_access <<= 6;
4886 + acl_entry_link_head->count++;
4889 + /* Since there is no way to return a DENY acl entry *
4890 + * change to PERMIT and then shift. */
4891 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4892 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4893 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4894 + acl_entry_link->entryp->ace_access <<= 6;
4895 + acl_entry_link_head->count++;
4901 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4902 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4904 + acl_entry = acl_nxt(acl_entry);
4906 + } /* end of if enabled */
4908 + /* Since owner, group, other acl entries are not *
4909 + * part of the acl entries in an acl, they must *
4910 + * be dummied up to become part of the list. */
4912 + for( i = 1; i < 4; i++) {
4913 + DEBUG(10,("i is %d\n",i));
4914 + if(acl_entry_link_head->count != 0){
4915 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4916 + if(acl_entry_link->nextp == NULL) {
4918 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4919 + SAFE_FREE(file_acl);
4923 + acl_entry_link->nextp->prevp = acl_entry_link;
4924 + acl_entry_link = acl_entry_link->nextp;
4925 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4927 + if(acl_entry_link->entryp == NULL) {
4928 + SAFE_FREE(file_acl);
4930 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4935 + acl_entry_link->nextp = NULL;
4937 + new_acl_entry = acl_entry_link->entryp;
4938 + idp = new_acl_entry->ace_id;
4940 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4941 + new_acl_entry->ace_type = ACC_PERMIT;
4942 + idp->id_len = sizeof(struct ace_id);
4943 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4944 + memset(idp->id_data,0,sizeof(uid_t));
4948 + new_acl_entry->ace_access = file_acl->g_access << 6;
4949 + idp->id_type = SMB_ACL_GROUP_OBJ;
4953 + new_acl_entry->ace_access = file_acl->o_access << 6;
4954 + idp->id_type = SMB_ACL_OTHER;
4958 + new_acl_entry->ace_access = file_acl->u_access << 6;
4959 + idp->id_type = SMB_ACL_USER_OBJ;
4966 + acl_entry_link_head->count++;
4967 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4970 + acl_entry_link_head->count = 0;
4971 + SAFE_FREE(file_acl);
4973 + return(acl_entry_link_head);
4976 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4978 + *permset = *permset & ~0777;
4982 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4985 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4989 + DEBUG(10,("This is the permset now: %d\n",*permset));
4993 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4998 +SMB_ACL_T sys_acl_init( int count)
5000 + struct acl_entry_link *theacl = NULL;
5002 + DEBUG(10,("Entering sys_acl_init\n"));
5004 + theacl = SMB_MALLOC_P(struct acl_entry_link);
5005 + if(theacl == NULL) {
5007 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
5011 + theacl->count = 0;
5012 + theacl->nextp = NULL;
5013 + theacl->prevp = NULL;
5014 + theacl->entryp = NULL;
5015 + DEBUG(10,("Exiting sys_acl_init\n"));
5019 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
5021 + struct acl_entry_link *theacl;
5022 + struct acl_entry_link *acl_entryp;
5023 + struct acl_entry_link *temp_entry;
5026 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
5028 + theacl = acl_entryp = *pacl;
5030 + /* Get to the end of the acl before adding entry */
5032 + for(counting=0; counting < theacl->count; counting++){
5033 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5034 + temp_entry = acl_entryp;
5035 + acl_entryp = acl_entryp->nextp;
5038 + if(theacl->count != 0){
5039 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
5040 + if(acl_entryp == NULL) {
5042 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5046 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
5047 + acl_entryp->prevp = temp_entry;
5048 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
5051 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
5052 + if(*pentry == NULL) {
5054 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
5058 + memset(*pentry,0,sizeof(struct new_acl_entry));
5059 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
5060 + acl_entryp->entryp->ace_type = ACC_PERMIT;
5061 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
5062 + acl_entryp->nextp = NULL;
5064 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
5068 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
5070 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
5071 + entry->ace_id->id_type = tagtype;
5072 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
5073 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
5076 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
5078 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
5079 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
5080 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
5084 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
5086 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
5087 + if(!(*permset & S_IXUSR) &&
5088 + !(*permset & S_IWUSR) &&
5089 + !(*permset & S_IRUSR) &&
5093 + entry->ace_access = *permset;
5094 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
5095 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
5099 +int sys_acl_valid( SMB_ACL_T theacl )
5102 + int group_obj = 0;
5103 + int other_obj = 0;
5104 + struct acl_entry_link *acl_entry;
5106 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
5107 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
5108 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
5109 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
5112 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
5114 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
5120 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
5122 + struct acl_entry_link *acl_entry_link = NULL;
5123 + struct acl *file_acl = NULL;
5124 + struct acl *file_acl_temp = NULL;
5125 + struct acl_entry *acl_entry = NULL;
5126 + struct ace_id *ace_id = NULL;
5133 + DEBUG(10,("Entering sys_acl_set_file\n"));
5134 + DEBUG(10,("File name is %s\n",name));
5136 + /* AIX has no default ACL */
5137 + if(acltype == SMB_ACL_TYPE_DEFAULT)
5140 + acl_length = BUFSIZ;
5141 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5143 + if(file_acl == NULL) {
5145 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5149 + memset(file_acl,0,BUFSIZ);
5151 + file_acl->acl_len = ACL_SIZ;
5152 + file_acl->acl_mode = S_IXACL;
5154 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5155 + acl_entry_link->entryp->ace_access >>= 6;
5156 + id_type = acl_entry_link->entryp->ace_id->id_type;
5159 + case SMB_ACL_USER_OBJ:
5160 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5162 + case SMB_ACL_GROUP_OBJ:
5163 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5165 + case SMB_ACL_OTHER:
5166 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5168 + case SMB_ACL_MASK:
5172 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5173 + acl_length += sizeof(struct acl_entry);
5174 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5175 + if(file_acl_temp == NULL) {
5176 + SAFE_FREE(file_acl);
5178 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
5182 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5183 + SAFE_FREE(file_acl);
5184 + file_acl = file_acl_temp;
5187 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5188 + file_acl->acl_len += sizeof(struct acl_entry);
5189 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5190 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5192 + /* In order to use this, we'll need to wait until we can get denies */
5193 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5194 + acl_entry->ace_type = ACC_SPECIFY; */
5196 + acl_entry->ace_type = ACC_SPECIFY;
5198 + ace_id = acl_entry->ace_id;
5200 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5201 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5202 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5203 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5204 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
5207 + rc = chacl(name,file_acl,file_acl->acl_len);
5208 + DEBUG(10,("errno is %d\n",errno));
5209 + DEBUG(10,("return code is %d\n",rc));
5210 + SAFE_FREE(file_acl);
5211 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
5215 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
5217 + struct acl_entry_link *acl_entry_link = NULL;
5218 + struct acl *file_acl = NULL;
5219 + struct acl *file_acl_temp = NULL;
5220 + struct acl_entry *acl_entry = NULL;
5221 + struct ace_id *ace_id = NULL;
5227 + DEBUG(10,("Entering sys_acl_set_fd\n"));
5228 + acl_length = BUFSIZ;
5229 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
5231 + if(file_acl == NULL) {
5233 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5237 + memset(file_acl,0,BUFSIZ);
5239 + file_acl->acl_len = ACL_SIZ;
5240 + file_acl->acl_mode = S_IXACL;
5242 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
5243 + acl_entry_link->entryp->ace_access >>= 6;
5244 + id_type = acl_entry_link->entryp->ace_id->id_type;
5245 + DEBUG(10,("The id_type is %d\n",id_type));
5248 + case SMB_ACL_USER_OBJ:
5249 + file_acl->u_access = acl_entry_link->entryp->ace_access;
5251 + case SMB_ACL_GROUP_OBJ:
5252 + file_acl->g_access = acl_entry_link->entryp->ace_access;
5254 + case SMB_ACL_OTHER:
5255 + file_acl->o_access = acl_entry_link->entryp->ace_access;
5257 + case SMB_ACL_MASK:
5261 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
5262 + acl_length += sizeof(struct acl_entry);
5263 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
5264 + if(file_acl_temp == NULL) {
5265 + SAFE_FREE(file_acl);
5267 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
5271 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
5272 + SAFE_FREE(file_acl);
5273 + file_acl = file_acl_temp;
5276 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
5277 + file_acl->acl_len += sizeof(struct acl_entry);
5278 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
5279 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
5281 + /* In order to use this, we'll need to wait until we can get denies */
5282 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
5283 + acl_entry->ace_type = ACC_SPECIFY; */
5285 + acl_entry->ace_type = ACC_SPECIFY;
5287 + ace_id = acl_entry->ace_id;
5289 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
5290 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
5291 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
5292 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
5293 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
5296 + rc = fchacl(fd,file_acl,file_acl->acl_len);
5297 + DEBUG(10,("errno is %d\n",errno));
5298 + DEBUG(10,("return code is %d\n",rc));
5299 + SAFE_FREE(file_acl);
5300 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
5304 +int sys_acl_delete_def_file(const char *name)
5306 + /* AIX has no default ACL */
5310 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5312 + return(*permset & perm);
5315 +int sys_acl_free_text(char *text)
5320 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
5322 + struct acl_entry_link *acl_entry_link;
5324 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
5325 + SAFE_FREE(acl_entry_link->prevp->entryp);
5326 + SAFE_FREE(acl_entry_link->prevp);
5329 + SAFE_FREE(acl_entry_link->prevp->entryp);
5330 + SAFE_FREE(acl_entry_link->prevp);
5331 + SAFE_FREE(acl_entry_link->entryp);
5332 + SAFE_FREE(acl_entry_link);
5337 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
5342 +#else /* No ACLs. */
5344 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
5350 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
5356 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
5362 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
5368 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
5371 + return (SMB_ACL_T)NULL;
5374 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
5377 + return (SMB_ACL_T)NULL;
5380 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
5386 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
5392 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
5395 + return (permset & perm) ? 1 : 0;
5398 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
5404 +int sys_acl_free_text(UNUSED(char *text))
5410 +SMB_ACL_T sys_acl_init(UNUSED(int count))
5416 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
5422 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
5428 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
5434 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
5440 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
5446 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
5452 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
5458 +int sys_acl_delete_def_file(UNUSED(const char *name))
5464 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
5470 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
5476 +#endif /* No ACLs. */
5478 +/************************************************************************
5479 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
5481 +************************************************************************/
5483 +int no_acl_syscall_error(int err)
5485 +#if defined(ENOSYS)
5486 + if (err == ENOSYS) {
5490 +#if defined(ENOTSUP)
5491 + if (err == ENOTSUP) {
5498 +#endif /* SUPPORT_ACLS */
5499 --- old/lib/sysacls.h
5500 +++ new/lib/sysacls.h
5502 +#ifdef SUPPORT_ACLS
5504 +#ifdef HAVE_SYS_ACL_H
5505 +#include <sys/acl.h>
5507 +#ifdef HAVE_ACL_LIBACL_H
5508 +#include <acl/libacl.h>
5510 +#include "smb_acls.h"
5512 +#define SMB_MALLOC(cnt) new_array(char, cnt)
5513 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
5514 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
5515 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5516 +#define slprintf snprintf
5518 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
5519 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
5520 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
5521 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
5522 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
5523 +SMB_ACL_T sys_acl_get_fd(int fd);
5524 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
5525 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5526 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
5527 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
5528 +SMB_ACL_T sys_acl_init(int count);
5529 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
5530 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
5531 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
5532 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
5533 +int sys_acl_valid(SMB_ACL_T theacl);
5534 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
5535 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
5536 +int sys_acl_delete_def_file(const char *name);
5537 +int sys_acl_free_text(char *text);
5538 +int sys_acl_free_acl(SMB_ACL_T the_acl);
5539 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
5541 +#endif /* SUPPORT_ACLS */
5544 @@ -606,8 +606,10 @@ static void log_formatted(enum logcode c
5545 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
5546 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
5547 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
5550 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u';
5551 + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a';
5552 + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x';
5555 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
5556 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
5559 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
5561 int preserve_links = 0;
5562 int preserve_hard_links = 0;
5563 +int preserve_acls = 0;
5564 int preserve_perms = 0;
5565 int preserve_executability = 0;
5566 int preserve_devices = 0;
5567 @@ -199,6 +200,7 @@ static void print_rsync_version(enum log
5568 char const *got_socketpair = "no ";
5569 char const *have_inplace = "no ";
5570 char const *hardlinks = "no ";
5571 + char const *acls = "no ";
5572 char const *links = "no ";
5573 char const *ipv6 = "no ";
5574 STRUCT_STAT *dumstat;
5575 @@ -215,6 +217,10 @@ static void print_rsync_version(enum log
5579 +#ifdef SUPPORT_ACLS
5583 #ifdef SUPPORT_LINKS
5586 @@ -227,17 +233,16 @@ static void print_rsync_version(enum log
5587 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
5588 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
5589 rprintf(f, "<http://rsync.samba.org/>\n");
5590 - rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
5591 - "%shard links, %ssymlinks, batchfiles,\n",
5592 - (int) (sizeof (OFF_T) * 8),
5593 - got_socketpair, hardlinks, links);
5594 + rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n",
5595 + (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links);
5597 + rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n",
5598 + have_inplace, ipv6, acls);
5600 /* Note that this field may not have type ino_t. It depends
5601 * on the complicated interaction between largefile feature
5603 - rprintf(f, " %sinplace, %sIPv6, "
5604 - "%d-bit system inums, %d-bit internal inums\n",
5605 - have_inplace, ipv6,
5606 + rprintf(f, " %d-bit system inums, %d-bit internal inums\n",
5607 (int) (sizeof dumstat->st_ino * 8),
5608 (int) (sizeof (int64) * 8));
5609 #ifdef MAINTAINER_MODE
5610 @@ -284,7 +289,7 @@ void usage(enum logcode F)
5611 rprintf(F," -q, --quiet suppress non-error messages\n");
5612 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
5613 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
5614 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n");
5615 + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
5616 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
5617 rprintf(F," -r, --recursive recurse into directories\n");
5618 rprintf(F," -R, --relative use relative path names\n");
5619 @@ -306,6 +311,9 @@ void usage(enum logcode F)
5620 rprintf(F," -p, --perms preserve permissions\n");
5621 rprintf(F," -E, --executability preserve the file's executability\n");
5622 rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
5623 +#ifdef SUPPORT_ACLS
5624 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
5626 rprintf(F," -o, --owner preserve owner (super-user only)\n");
5627 rprintf(F," -g, --group preserve group\n");
5628 rprintf(F," --devices preserve device files (super-user only)\n");
5629 @@ -425,6 +433,9 @@ static struct poptOption long_options[]
5630 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5631 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
5632 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
5633 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
5634 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5635 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
5636 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
5637 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5638 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
5639 @@ -1089,6 +1100,24 @@ int parse_arguments(int *argc, const cha
5644 +#ifdef SUPPORT_ACLS
5646 + preserve_perms = 1;
5649 + /* FIXME: this should probably be ignored with a
5650 + * warning and then countermeasures taken to
5651 + * restrict group and other access in the presence
5652 + * of any more restrictive ACLs, but this is safe
5654 + snprintf(err_buf,sizeof(err_buf),
5655 + "ACLs are not supported on this %s\n",
5656 + am_server ? "server" : "client");
5662 /* A large opt value means that set_refuse_options()
5663 * turned this option off. */
5664 @@ -1530,6 +1559,10 @@ void server_options(char **args,int *arg
5666 if (preserve_hard_links)
5668 +#ifdef SUPPORT_ACLS
5669 + if (preserve_acls)
5670 + argstr[x++] = 'A';
5677 @@ -47,6 +47,7 @@ extern int keep_partial;
5678 extern int checksum_seed;
5680 extern int delay_updates;
5681 +extern mode_t orig_umask;
5682 extern struct stats stats;
5683 extern char *stdout_format;
5684 extern char *tmpdir;
5685 @@ -350,6 +351,10 @@ int recv_files(int f_in, struct file_lis
5686 int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i;
5687 enum logcode log_code = log_before_transfer ? FLOG : FINFO;
5688 int max_phase = protocol_version >= 29 ? 2 : 1;
5689 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5690 +#ifdef SUPPORT_ACLS
5691 + char *parent_dirname = "";
5696 @@ -553,7 +558,16 @@ int recv_files(int f_in, struct file_lis
5697 * mode based on the local permissions and some heuristics. */
5698 if (!preserve_perms) {
5699 int exists = fd1 != -1;
5700 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5701 +#ifdef SUPPORT_ACLS
5702 + char *dn = file->dirname ? file->dirname : ".";
5703 + if (parent_dirname != dn
5704 + && strcmp(parent_dirname, dn) != 0) {
5705 + dflt_perms = default_perms_for_dir(dn);
5706 + parent_dirname = dn;
5709 + file->mode = dest_mode(file->mode, st.st_mode,
5710 + dflt_perms, exists);
5713 /* We now check to see if we are writing the file "inplace" */
5720 +extern int preserve_acls;
5721 extern int preserve_perms;
5722 extern int preserve_executability;
5723 extern int preserve_times;
5724 @@ -47,7 +48,6 @@ extern int preserve_gid;
5726 extern int keep_dirlinks;
5727 extern int make_backups;
5728 -extern mode_t orig_umask;
5729 extern struct stats stats;
5730 extern struct chmod_mode_struct *daemon_chmod_modes;
5732 @@ -100,7 +100,8 @@ void free_sums(struct sum_struct *s)
5734 /* This is only called when we aren't preserving permissions. Figure out what
5735 * the permissions should be and return them merged back into the mode. */
5736 -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists)
5737 +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
5741 /* If the file already exists, we'll return the local permissions,
5742 @@ -117,56 +118,65 @@ mode_t dest_mode(mode_t flist_mode, mode
5743 new_mode |= (new_mode & 0444) >> 2;
5746 - /* Apply the umask and turn off special permissions. */
5747 - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask));
5748 + /* Apply destination default permissions and turn
5749 + * off special permissions. */
5750 + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
5755 -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st,
5756 +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp,
5762 int change_uid, change_gid;
5763 mode_t new_mode = file->mode;
5769 - if (link_stat(fname, &st2, 0) < 0) {
5770 + if (link_stat(fname, &sx2.st, 0) < 0) {
5771 rsyserr(FERROR, errno, "stat %s failed",
5776 +#ifdef SUPPORT_ACLS
5777 + sx2.acc_acl = sx2.def_acl = NULL;
5779 if (!preserve_perms && S_ISDIR(new_mode)
5780 - && st->st_mode & S_ISGID) {
5781 + && sx2.st.st_mode & S_ISGID) {
5782 /* We just created this directory and its setgid
5783 * bit is on, so make sure it stays on. */
5784 new_mode |= S_ISGID;
5789 - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
5790 +#ifdef SUPPORT_ACLS
5791 + if (preserve_acls && !ACL_READY(*sxp))
5792 + get_acl(fname, sxp);
5795 + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
5796 flags |= ATTRS_SKIP_MTIME;
5797 if (!(flags & ATTRS_SKIP_MTIME)
5798 - && cmp_time(st->st_mtime, file->modtime) != 0) {
5799 - int ret = set_modtime(fname, file->modtime, st->st_mode);
5800 + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
5801 + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode);
5803 rsyserr(FERROR, errno, "failed to set times on %s",
5808 if (ret == 0) /* ret == 1 if symlink could not be set */
5812 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
5813 + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid;
5814 change_gid = preserve_gid && file->gid != GID_NONE
5815 - && st->st_gid != file->gid;
5816 + && sxp->st.st_gid != file->gid;
5817 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
5818 - if (S_ISLNK(st->st_mode))
5819 + if (S_ISLNK(sxp->st.st_mode))
5823 @@ -176,45 +186,57 @@ int set_file_attrs(char *fname, struct f
5825 "set uid of %s from %ld to %ld\n",
5827 - (long)st->st_uid, (long)file->uid);
5828 + (long)sxp->st.st_uid, (long)file->uid);
5832 "set gid of %s from %ld to %ld\n",
5834 - (long)st->st_gid, (long)file->gid);
5835 + (long)sxp->st.st_gid, (long)file->gid);
5838 if (do_lchown(fname,
5839 - change_uid ? file->uid : st->st_uid,
5840 - change_gid ? file->gid : st->st_gid) != 0) {
5841 + change_uid ? file->uid : sxp->st.st_uid,
5842 + change_gid ? file->gid : sxp->st.st_gid) != 0) {
5843 /* shouldn't have attempted to change uid or gid
5844 * unless have the privilege */
5845 rsyserr(FERROR, errno, "%s %s failed",
5846 change_uid ? "chown" : "chgrp",
5851 /* a lchown had been done - we have to re-stat if the
5852 * destination had the setuid or setgid bits set due
5853 * to the side effect of the chown call */
5854 - if (st->st_mode & (S_ISUID | S_ISGID)) {
5855 - link_stat(fname, st,
5856 - keep_dirlinks && S_ISDIR(st->st_mode));
5857 + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) {
5858 + link_stat(fname, &sxp->st,
5859 + keep_dirlinks && S_ISDIR(sxp->st.st_mode));
5864 if (daemon_chmod_modes && !S_ISLNK(new_mode))
5865 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
5867 +#ifdef SUPPORT_ACLS
5868 + /* It's OK to call set_acl() now, even for a dir, as the generator
5869 + * will enable owner-writability using chmod, if necessary.
5871 + * If set_acl() changes permission bits in the process of setting
5872 + * an access ACL, it changes sxp->st.st_mode so we know whether we
5873 + * need to chmod(). */
5874 + if (preserve_acls && set_acl(fname, file, sxp) == 0)
5879 - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5880 + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
5881 int ret = do_chmod(fname, new_mode);
5883 rsyserr(FERROR, errno,
5884 "failed to set permissions on %s",
5889 if (ret == 0) /* ret == 1 if symlink could not be set */
5891 @@ -227,6 +249,11 @@ int set_file_attrs(char *fname, struct f
5893 rprintf(FCLIENT, "%s is uptodate\n", fname);
5896 +#ifdef SUPPORT_ACLS
5897 + if (preserve_acls && sxp == &sx2)
5905 @@ -492,6 +492,14 @@ struct idev {
5906 #define IN_LOOPBACKNET 127
5909 +#ifndef HAVE_NO_ACLS
5910 +#define SUPPORT_ACLS 1
5913 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5914 +#define ACLS_NEED_MASK 1
5917 #define GID_NONE ((gid_t)-1)
5919 #define HL_CHECK_MASTER 0
5920 @@ -653,6 +661,17 @@ struct stats {
5922 struct chmod_mode_struct;
5924 +#define EMPTY_ITEM_LIST {NULL, 0, 0}
5932 +#define EXPAND_ITEM_LIST(lp, type, incr) \
5933 + (type*)expand_item_list(lp, sizeof (type), #type, incr)
5935 #include "byteorder.h"
5936 #include "lib/mdfour.h"
5937 #include "lib/wildmatch.h"
5938 @@ -669,6 +688,16 @@ struct chmod_mode_struct;
5939 #define UNUSED(x) x __attribute__((__unused__))
5940 #define NORETURN __attribute__((__noreturn__))
5944 +#ifdef SUPPORT_ACLS
5945 + struct rsync_acl *acc_acl; /* access ACL */
5946 + struct rsync_acl *def_acl; /* default ACL */
5950 +#define ACL_READY(sx) ((sx).acc_acl != NULL)
5954 /* We have replacement versions of these if they're missing. */
5957 @@ -301,7 +301,7 @@ to the detailed description below for a
5958 -q, --quiet suppress non-error messages
5959 --no-motd suppress daemon-mode MOTD (see caveat)
5960 -c, --checksum skip based on checksum, not mod-time & size
5961 - -a, --archive archive mode; same as -rlptgoD (no -H)
5962 + -a, --archive archive mode; same as -rlptgoD (no -H, -A)
5963 --no-OPTION turn off an implied OPTION (e.g. --no-D)
5964 -r, --recursive recurse into directories
5965 -R, --relative use relative path names
5966 @@ -323,6 +323,7 @@ to the detailed description below for a
5967 -p, --perms preserve permissions
5968 -E, --executability preserve executability
5969 --chmod=CHMOD affect file and/or directory permissions
5970 + -A, --acls preserve ACLs (implies -p) [non-standard]
5971 -o, --owner preserve owner (super-user only)
5972 -g, --group preserve group
5973 --devices preserve device files (super-user only)
5974 @@ -753,7 +754,9 @@ quote(itemization(
5975 permissions, though the bf(--executability) option might change just
5976 the execute permission for the file.
5977 it() New files get their "normal" permission bits set to the source
5978 - file's permissions masked with the receiving end's umask setting, and
5979 + file's permissions masked with the receiving directory's default
5980 + permissions (either the receiving process's umask, or the permissions
5981 + specified via the destination directory's default ACL), and
5982 their special permission bits disabled except in the case where a new
5983 directory inherits a setgid bit from its parent directory.
5985 @@ -784,9 +787,11 @@ The preservation of the destination's se
5986 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5987 versions erroneously preserved the three special permission bits for
5988 newly-created files when bf(--perms) was off, while overriding the
5989 -destination's setgid bit setting on a newly-created directory. (Keep in
5990 -mind that it is the version of the receiving rsync that affects this
5992 +destination's setgid bit setting on a newly-created directory. Default ACL
5993 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5994 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5995 +(Keep in mind that it is the version of the receiving rsync that affects
5998 dit(bf(-E, --executability)) This option causes rsync to preserve the
5999 executability (or non-executability) of regular files when bf(--perms) is
6000 @@ -804,6 +809,15 @@ quote(itemization(
6002 If bf(--perms) is enabled, this option is ignored.
6004 +dit(bf(-A, --acls)) This option causes rsync to update the destination
6005 +ACLs to be the same as the source ACLs. This nonstandard option only
6006 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
6008 +Note also that an optimization of the ACL-sending protocol used by this
6009 +version makes it incompatible with sending files to an older ACL-enabled
6010 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
6011 +doubling is not needed when pulling files from an older rsync.
6013 dit(bf(--chmod)) This option tells rsync to apply one or more
6014 comma-separated "chmod" strings to the permission of the files in the
6015 transfer. The resulting value is treated as though it was the permissions
6016 @@ -1389,8 +1403,8 @@ if the receiving rsync is at least versi
6017 with older versions of rsync, but that also turns on the output of other
6020 -The "%i" escape has a cryptic output that is 9 letters long. The general
6021 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
6022 +The "%i" escape has a cryptic output that is 11 letters long. The general
6023 +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the
6024 type of update being done, bf(X) is replaced by the file-type, and the
6025 other letters represent attributes that may be output if they are being
6027 @@ -1439,7 +1453,11 @@ quote(itemization(
6028 sender's value (requires bf(--owner) and super-user privileges).
6029 it() A bf(g) means the group is different and is being updated to the
6030 sender's value (requires bf(--group) and the authority to set the group).
6031 - it() The bf(z) slot is reserved for future use.
6032 + it() The bf(u) slot is reserved for reporting update (access) time changes
6033 + (a feature that is not yet released).
6034 + it() The bf(a) means that the ACL information changed.
6035 + it() The bf(x) slot is reserved for reporting extended attribute changes
6036 + (a feature that is not yet released).
6039 One other output is possible: when deleting files, the "%i" will output
6044 + Unix SMB/Netbios implementation.
6046 + Portable SMB ACL interface
6047 + Copyright (C) Jeremy Allison 2000
6049 + This program is free software; you can redistribute it and/or modify
6050 + it under the terms of the GNU General Public License as published by
6051 + the Free Software Foundation; either version 2 of the License, or
6052 + (at your option) any later version.
6054 + This program is distributed in the hope that it will be useful,
6055 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6056 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6057 + GNU General Public License for more details.
6059 + You should have received a copy of the GNU General Public License
6060 + along with this program; if not, write to the Free Software
6061 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6064 +#ifndef _SMB_ACLS_H
6065 +#define _SMB_ACLS_H
6067 +#if defined HAVE_POSIX_ACLS
6069 +/* This is an identity mapping (just remove the SMB_). */
6071 +#define SMB_ACL_TAG_T acl_tag_t
6072 +#define SMB_ACL_TYPE_T acl_type_t
6073 +#define SMB_ACL_PERMSET_T acl_permset_t
6074 +#define SMB_ACL_PERM_T acl_perm_t
6075 +#define SMB_ACL_READ ACL_READ
6076 +#define SMB_ACL_WRITE ACL_WRITE
6077 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6079 +/* Types of ACLs. */
6080 +#define SMB_ACL_USER ACL_USER
6081 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6082 +#define SMB_ACL_GROUP ACL_GROUP
6083 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6084 +#define SMB_ACL_OTHER ACL_OTHER
6085 +#define SMB_ACL_MASK ACL_MASK
6087 +#define SMB_ACL_T acl_t
6089 +#define SMB_ACL_ENTRY_T acl_entry_t
6091 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
6092 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
6094 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6095 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6097 +#elif defined HAVE_TRU64_ACLS
6099 +/* This is for DEC/Compaq Tru64 UNIX */
6101 +#define SMB_ACL_TAG_T acl_tag_t
6102 +#define SMB_ACL_TYPE_T acl_type_t
6103 +#define SMB_ACL_PERMSET_T acl_permset_t
6104 +#define SMB_ACL_PERM_T acl_perm_t
6105 +#define SMB_ACL_READ ACL_READ
6106 +#define SMB_ACL_WRITE ACL_WRITE
6107 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6109 +/* Types of ACLs. */
6110 +#define SMB_ACL_USER ACL_USER
6111 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6112 +#define SMB_ACL_GROUP ACL_GROUP
6113 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6114 +#define SMB_ACL_OTHER ACL_OTHER
6115 +#define SMB_ACL_MASK ACL_MASK
6117 +#define SMB_ACL_T acl_t
6119 +#define SMB_ACL_ENTRY_T acl_entry_t
6121 +#define SMB_ACL_FIRST_ENTRY 0
6122 +#define SMB_ACL_NEXT_ENTRY 1
6124 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6125 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6127 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
6129 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
6130 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
6133 +/* SVR4.2 ES/MP ACLs */
6134 +typedef int SMB_ACL_TAG_T;
6135 +typedef int SMB_ACL_TYPE_T;
6136 +typedef ushort *SMB_ACL_PERMSET_T;
6137 +typedef ushort SMB_ACL_PERM_T;
6138 +#define SMB_ACL_READ 4
6139 +#define SMB_ACL_WRITE 2
6140 +#define SMB_ACL_EXECUTE 1
6142 +/* Types of ACLs. */
6143 +#define SMB_ACL_USER USER
6144 +#define SMB_ACL_USER_OBJ USER_OBJ
6145 +#define SMB_ACL_GROUP GROUP
6146 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6147 +#define SMB_ACL_OTHER OTHER_OBJ
6148 +#define SMB_ACL_MASK CLASS_OBJ
6150 +typedef struct SMB_ACL_T {
6154 + struct acl acl[1];
6157 +typedef struct acl *SMB_ACL_ENTRY_T;
6159 +#define SMB_ACL_FIRST_ENTRY 0
6160 +#define SMB_ACL_NEXT_ENTRY 1
6162 +#define SMB_ACL_TYPE_ACCESS 0
6163 +#define SMB_ACL_TYPE_DEFAULT 1
6166 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
6169 +#elif defined HAVE_HPUX_ACLS
6172 + * Based on the Solaris & UnixWare code.
6176 +#include <sys/aclv.h>
6178 +/* SVR4.2 ES/MP ACLs */
6179 +typedef int SMB_ACL_TAG_T;
6180 +typedef int SMB_ACL_TYPE_T;
6181 +typedef ushort *SMB_ACL_PERMSET_T;
6182 +typedef ushort SMB_ACL_PERM_T;
6183 +#define SMB_ACL_READ 4
6184 +#define SMB_ACL_WRITE 2
6185 +#define SMB_ACL_EXECUTE 1
6187 +/* Types of ACLs. */
6188 +#define SMB_ACL_USER USER
6189 +#define SMB_ACL_USER_OBJ USER_OBJ
6190 +#define SMB_ACL_GROUP GROUP
6191 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
6192 +#define SMB_ACL_OTHER OTHER_OBJ
6193 +#define SMB_ACL_MASK CLASS_OBJ
6195 +typedef struct SMB_ACL_T {
6199 + struct acl acl[1];
6202 +typedef struct acl *SMB_ACL_ENTRY_T;
6204 +#define SMB_ACL_FIRST_ENTRY 0
6205 +#define SMB_ACL_NEXT_ENTRY 1
6207 +#define SMB_ACL_TYPE_ACCESS 0
6208 +#define SMB_ACL_TYPE_DEFAULT 1
6210 +#elif defined HAVE_IRIX_ACLS
6212 +#define SMB_ACL_TAG_T acl_tag_t
6213 +#define SMB_ACL_TYPE_T acl_type_t
6214 +#define SMB_ACL_PERMSET_T acl_permset_t
6215 +#define SMB_ACL_PERM_T acl_perm_t
6216 +#define SMB_ACL_READ ACL_READ
6217 +#define SMB_ACL_WRITE ACL_WRITE
6218 +#define SMB_ACL_EXECUTE ACL_EXECUTE
6220 +/* Types of ACLs. */
6221 +#define SMB_ACL_USER ACL_USER
6222 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
6223 +#define SMB_ACL_GROUP ACL_GROUP
6224 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
6225 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
6226 +#define SMB_ACL_MASK ACL_MASK
6228 +typedef struct SMB_ACL_T {
6234 +#define SMB_ACL_ENTRY_T acl_entry_t
6236 +#define SMB_ACL_FIRST_ENTRY 0
6237 +#define SMB_ACL_NEXT_ENTRY 1
6239 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
6240 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
6242 +#elif defined HAVE_AIX_ACLS
6244 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
6246 +#include "/usr/include/acl.h"
6248 +typedef uint *SMB_ACL_PERMSET_T;
6250 +struct acl_entry_link{
6251 + struct acl_entry_link *prevp;
6252 + struct new_acl_entry *entryp;
6253 + struct acl_entry_link *nextp;
6257 +struct new_acl_entry{
6258 + unsigned short ace_len;
6259 + unsigned short ace_type;
6260 + unsigned int ace_access;
6261 + struct ace_id ace_id[1];
6264 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
6265 +#define SMB_ACL_T struct acl_entry_link*
6267 +#define SMB_ACL_TAG_T unsigned short
6268 +#define SMB_ACL_TYPE_T int
6269 +#define SMB_ACL_PERM_T uint
6270 +#define SMB_ACL_READ S_IRUSR
6271 +#define SMB_ACL_WRITE S_IWUSR
6272 +#define SMB_ACL_EXECUTE S_IXUSR
6274 +/* Types of ACLs. */
6275 +#define SMB_ACL_USER ACEID_USER
6276 +#define SMB_ACL_USER_OBJ 3
6277 +#define SMB_ACL_GROUP ACEID_GROUP
6278 +#define SMB_ACL_GROUP_OBJ 4
6279 +#define SMB_ACL_OTHER 5
6280 +#define SMB_ACL_MASK 6
6283 +#define SMB_ACL_FIRST_ENTRY 1
6284 +#define SMB_ACL_NEXT_ENTRY 2
6286 +#define SMB_ACL_TYPE_ACCESS 0
6287 +#define SMB_ACL_TYPE_DEFAULT 1
6289 +#else /* No ACLs. */
6291 +/* No ACLS - fake it. */
6292 +#define SMB_ACL_TAG_T int
6293 +#define SMB_ACL_TYPE_T int
6294 +#define SMB_ACL_PERMSET_T mode_t
6295 +#define SMB_ACL_PERM_T mode_t
6296 +#define SMB_ACL_READ S_IRUSR
6297 +#define SMB_ACL_WRITE S_IWUSR
6298 +#define SMB_ACL_EXECUTE S_IXUSR
6300 +/* Types of ACLs. */
6301 +#define SMB_ACL_USER 0
6302 +#define SMB_ACL_USER_OBJ 1
6303 +#define SMB_ACL_GROUP 2
6304 +#define SMB_ACL_GROUP_OBJ 3
6305 +#define SMB_ACL_OTHER 4
6306 +#define SMB_ACL_MASK 5
6308 +typedef struct SMB_ACL_T {
6312 +typedef struct SMB_ACL_ENTRY_T {
6314 +} *SMB_ACL_ENTRY_T;
6316 +#define SMB_ACL_FIRST_ENTRY 0
6317 +#define SMB_ACL_NEXT_ENTRY 1
6319 +#define SMB_ACL_TYPE_ACCESS 0
6320 +#define SMB_ACL_TYPE_DEFAULT 1
6322 +#endif /* No ACLs. */
6323 +#endif /* _SMB_ACLS_H */
6324 --- old/testsuite/acls.test
6325 +++ new/testsuite/acls.test
6329 +# This program is distributable under the terms of the GNU GPL (see
6332 +# Test that rsync handles basic ACL preservation.
6334 +. $srcdir/testsuite/rsync.fns
6336 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6337 +case "$setfacl_nodef" in
6338 +true) test_skipped "I don't know how to use your setfacl command" ;;
6341 +makepath "$fromdir/foo"
6342 +echo something >"$fromdir/file1"
6343 +echo else >"$fromdir/file2"
6345 +files='foo file1 file2'
6347 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
6348 +setfacl -m u:0:5 "$fromdir/file1"
6349 +setfacl -m u:0:5 "$fromdir/file2"
6351 +$RSYNC -avvA "$fromdir/" "$todir/"
6354 +getfacl $files >"$scratchdir/acls.txt"
6357 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
6359 +# The script would have aborted on error, so getting here means we've won.
6361 --- old/testsuite/default-acls.test
6362 +++ new/testsuite/default-acls.test
6366 +# This program is distributable under the terms of the GNU GPL (see
6369 +# Test that rsync obeys default ACLs. -- Matt McCutchen
6371 +. $srcdir/testsuite/rsync.fns
6373 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
6374 +case "$setfacl_nodef" in
6375 +true) test_skipped "I don't know how to use your setfacl command" ;;
6376 +*-k*) opts='-dm u::7,g::5,o:5' ;;
6377 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
6379 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
6381 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
6383 + todir="$scratchdir/$1"
6385 + $setfacl_nodef "$todir"
6387 + case "$setfacl_nodef" in
6388 + *-k*) opts="-dm $2" ;;
6389 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
6391 + setfacl $opts "$todir"
6393 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
6394 + # even though the directory itself is outside the transfer
6395 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
6396 + check_perms "$todir/to" $4 "Target $1"
6397 + check_perms "$todir/to/dir" $4 "Target $1"
6398 + check_perms "$todir/to/file" $3 "Target $1"
6399 + check_perms "$todir/to/program" $4 "Target $1"
6400 + # Make sure get_local_name doesn't mess us up when transferring only one file
6401 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
6402 + check_perms "$todir/to/anotherfile" $3 "Target $1"
6403 + # Make sure we obey default ACLs when not transferring a regular file
6404 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
6405 + check_perms "$todir/to/anotherdir" $4 "Target $1"
6408 +mkdir "$scratchdir/dir"
6409 +echo "File!" >"$scratchdir/file"
6410 +echo "#!/bin/sh" >"$scratchdir/program"
6411 +chmod 777 "$scratchdir/dir"
6412 +chmod 666 "$scratchdir/file"
6413 +chmod 777 "$scratchdir/program"
6415 +# Test some target directories
6417 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
6418 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
6419 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
6420 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
6421 +testit noda1 '' rw------- rwx------
6423 +testit noda2 '' rw-rw-rw- rwxrwxrwx
6425 +testit noda3 '' rw-r--r-- rwxr-xr-x
6429 --- old/testsuite/devices.test
6430 +++ new/testsuite/devices.test
6431 @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
6432 $RSYNC -ai "$fromdir/block" "$todir/block2" \
6434 cat <<EOT >"$chkfile"
6438 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6440 $RSYNC -ai "$fromdir/block2" "$todir/block" \
6442 cat <<EOT >"$chkfile"
6446 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6448 @@ -58,7 +58,7 @@ sleep 1
6449 $RSYNC -Di "$fromdir/block3" "$todir/block" \
6451 cat <<EOT >"$chkfile"
6455 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6457 @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
6460 cat <<EOT >"$chkfile"
6465 -hD+++++++ block2.5 => block3
6474 +hD+++++++++ block2.5 => block3
6480 if test ! -b "$fromdir/block2.5"; then
6481 sed -e '/block2\.5/d' \
6482 --- old/testsuite/itemize.test
6483 +++ new/testsuite/itemize.test
6484 @@ -29,15 +29,15 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
6485 $RSYNC -iplr "$fromdir/" "$todir/" \
6487 cat <<EOT >"$chkfile"
6491 ->f+++++++ bar/baz/rsync
6493 ->f+++++++ foo/config1
6494 ->f+++++++ foo/config2
6495 ->f+++++++ foo/extra
6496 -cL+++++++ foo/sym -> ../bar/baz/rsync
6499 +cd+++++++++ bar/baz/
6500 +>f+++++++++ bar/baz/rsync
6502 +>f+++++++++ foo/config1
6503 +>f+++++++++ foo/config2
6504 +>f+++++++++ foo/extra
6505 +cL+++++++++ foo/sym -> ../bar/baz/rsync
6507 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
6509 @@ -49,10 +49,10 @@ chmod 601 "$fromdir/foo/config2"
6510 $RSYNC -iplrH "$fromdir/" "$todir/" \
6512 cat <<EOT >"$chkfile"
6513 ->f..T.... bar/baz/rsync
6514 ->f..T.... foo/config1
6515 ->f.sTp... foo/config2
6516 -hf..T.... foo/extra => foo/config1
6517 +>f..T...... bar/baz/rsync
6518 +>f..T...... foo/config1
6519 +>f.sTp..... foo/config2
6520 +hf..T...... foo/extra => foo/config1
6522 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
6524 @@ -69,11 +69,11 @@ chmod 777 "$todir/bar/baz/rsync"
6525 $RSYNC -iplrtc "$fromdir/" "$todir/" \
6527 cat <<EOT >"$chkfile"
6528 -.f..tp... bar/baz/rsync
6530 -.f..t.... foo/config1
6531 ->fcstp... foo/config2
6532 -cL..T.... foo/sym -> ../bar/baz/rsync
6533 +.f..tp..... bar/baz/rsync
6535 +.f..t...... foo/config1
6536 +>fcstp..... foo/config2
6537 +cL..T...... foo/sym -> ../bar/baz/rsync
6539 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
6541 @@ -98,15 +98,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
6544 cat <<EOT >"$chkfile"
6548 -.f...p... bar/baz/rsync
6551 ->f..t.... foo/config2
6553 -.L foo/sym -> ../bar/baz/rsync
6557 +.f...p..... bar/baz/rsync
6560 +>f..t...... foo/config2
6562 +.L foo/sym -> ../bar/baz/rsync
6564 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
6566 @@ -125,8 +125,8 @@ touch "$todir/foo/config2"
6567 $RSYNC -iplrtH "$fromdir/" "$todir/" \
6569 cat <<EOT >"$chkfile"
6570 -.f...p... foo/config1
6571 ->f..t.... foo/config2
6572 +.f...p..... foo/config1
6573 +>f..t...... foo/config2
6575 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
6577 @@ -135,15 +135,15 @@ $RSYNC -ivvplrtH --copy-dest=../ld "$fro
6580 cat <<EOT >"$chkfile"
6588 -hf foo/extra => foo/config1
6589 -cL..T.... foo/sym -> ../bar/baz/rsync
6592 +cd+++++++++ bar/baz/
6597 +hf foo/extra => foo/config1
6598 +cL..T...... foo/sym -> ../bar/baz/rsync
6600 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
6602 @@ -151,11 +151,11 @@ rm -rf "$todir"
6603 $RSYNC -iplrtH --copy-dest=../ld "$fromdir/" "$todir/" \
6605 cat <<EOT >"$chkfile"
6610 -hf foo/extra => foo/config1
6613 +cd+++++++++ bar/baz/
6615 +hf foo/extra => foo/config1
6617 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
6619 @@ -182,15 +182,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
6622 cat <<EOT >"$chkfile"
6630 -hf foo/extra => foo/config1
6631 -hL foo/sym -> ../bar/baz/rsync
6634 +cd+++++++++ bar/baz/
6639 +hf foo/extra => foo/config1
6640 +hL foo/sym -> ../bar/baz/rsync
6642 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
6644 @@ -198,10 +198,10 @@ rm -rf "$todir"
6645 $RSYNC -iplrtH --dry-run --link-dest=../ld "$fromdir/" "$todir/" \
6647 cat <<EOT >"$chkfile"
6654 +cd+++++++++ bar/baz/
6657 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
6659 @@ -209,10 +209,10 @@ rm -rf "$todir"
6660 $RSYNC -iplrtH --link-dest=../ld "$fromdir/" "$todir/" \
6662 cat <<EOT >"$chkfile"
6669 +cd+++++++++ bar/baz/
6672 diff $diffopt "$chkfile" "$outfile" || test_fail "test 13 failed"
6674 @@ -240,14 +240,14 @@ filter_outfile
6675 # TODO fix really-old problem when combining -H with --compare-dest:
6676 # missing output for foo/extra hard-link (and it might not be updated)!
6677 cat <<EOT >"$chkfile"
6685 -.L foo/sym -> ../bar/baz/rsync
6688 +cd+++++++++ bar/baz/
6693 +.L foo/sym -> ../bar/baz/rsync
6695 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
6697 @@ -255,10 +255,10 @@ rm -rf "$todir"
6698 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
6700 cat <<EOT >"$chkfile"
6707 +cd+++++++++ bar/baz/
6710 diff $diffopt "$chkfile" "$outfile" || test_fail "test 16 failed"
6716 extern int preserve_uid;
6717 extern int preserve_gid;
6718 +extern int preserve_acls;
6719 extern int numeric_ids;
6722 @@ -273,7 +274,7 @@ void send_uid_list(int f)
6726 - if (preserve_uid) {
6727 + if (preserve_uid || preserve_acls) {
6729 /* we send sequences of uid/byte-length/name */
6730 for (list = uidlist; list; list = list->next) {
6731 @@ -290,7 +291,7 @@ void send_uid_list(int f)
6735 - if (preserve_gid) {
6736 + if (preserve_gid || preserve_acls) {
6738 for (list = gidlist; list; list = list->next) {
6740 @@ -311,7 +312,7 @@ void recv_uid_list(int f, struct file_li
6744 - if (preserve_uid && !numeric_ids) {
6745 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
6746 /* read the uid list */
6747 while ((id = read_int(f)) != 0) {
6748 int len = read_byte(f);
6749 @@ -323,7 +324,7 @@ void recv_uid_list(int f, struct file_li
6753 - if (preserve_gid && !numeric_ids) {
6754 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
6755 /* read the gid list */
6756 while ((id = read_int(f)) != 0) {
6757 int len = read_byte(f);
6758 @@ -335,6 +336,16 @@ void recv_uid_list(int f, struct file_li
6762 +#ifdef SUPPORT_ACLS
6763 + if (preserve_acls && !numeric_ids) {
6765 + while ((id = next_acl_uid(flist)) != NULL)
6766 + *id = match_uid(*id);
6767 + while ((id = next_acl_gid(flist)) != NULL)
6768 + *id = match_gid(*id);
6772 /* Now convert all the uids/gids from sender values to our values. */
6773 if (am_root && preserve_uid && !numeric_ids) {
6774 for (i = 0; i < flist->count; i++)
6777 @@ -1468,3 +1468,31 @@ int bitbag_next_bit(struct bitbag *bb, i
6782 +void *expand_item_list(item_list *lp, size_t item_size,
6783 + const char *desc, int incr)
6785 + /* First time through, 0 <= 0, so list is expanded. */
6786 + if (lp->malloced <= lp->count) {
6788 + size_t new_size = lp->malloced;
6790 + new_size -= incr; /* increase slowly */
6791 + else if (new_size < (size_t)incr)
6795 + new_ptr = realloc_array(lp->items, char, new_size * item_size);
6796 + if (verbose >= 4) {
6797 + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n",
6798 + who_am_i(), desc, (double)new_size * item_size,
6799 + new_ptr == lp->items ? " not" : "");
6802 + out_of_memory("expand_item_list");
6804 + lp->items = new_ptr;
6805 + lp->malloced = new_size;
6807 + return (char*)lp->items + (lp->count++ * item_size);