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 - The -i option does not yet itemize changes in ACL information.
14 - The --link-dest option might link together two files that differ just
15 in their ACL info, and if that happens the file in the --link-dest dir
16 would get its ACLs updated.
20 @@ -25,15 +25,15 @@ VERSION=@VERSION@
24 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
25 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
26 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
27 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
28 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
29 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
30 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
31 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
32 main.o checksum.o match.o syscall.o log.o backup.o
33 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
34 - fileio.o batch.o clientname.o chmod.o
35 + fileio.o batch.o clientname.o chmod.o acls.o
36 OBJS3=progress.o pipe.o
37 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
38 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
43 + * Handle passing Access Control Lists between systems.
45 + * Copyright (C) 1996 Andrew Tridgell
46 + * Copyright (C) 1996 Paul Mackerras
47 + * Copyright (C) 2006 Matt McCutchen
48 + * Copyright (C) 2006 Wayne Davison
50 + * This program is free software; you can redistribute it and/or modify
51 + * it under the terms of the GNU General Public License as published by
52 + * the Free Software Foundation; either version 2 of the License, or
53 + * (at your option) any later version.
55 + * This program is distributed in the hope that it will be useful,
56 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58 + * GNU General Public License for more details.
60 + * You should have received a copy of the GNU General Public License along
61 + * with this program; if not, write to the Free Software Foundation, Inc.,
62 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
66 +#include "lib/sysacls.h"
72 +extern int orig_umask;
73 +extern int preserve_acls;
86 +#define ACL_NO_ENTRY ((uchar)0x80)
90 + /* These will be ACL_NO_ENTRY if there's no such entry. */
97 +static const rsync_acl rsync_acl_initializer = {
98 + {0, 0, NULL}, {0, 0, NULL},
99 + ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY
102 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
103 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
105 +/* a few useful calculations */
107 +static int count_racl_entries(const rsync_acl *racl)
109 + return racl->users.count + racl->groups.count
110 + + (racl->user_obj != ACL_NO_ENTRY)
111 + + (racl->group_obj != ACL_NO_ENTRY)
112 + + (racl->mask != ACL_NO_ENTRY)
113 + + (racl->other != ACL_NO_ENTRY);
116 +static int calc_sacl_entries(const rsync_acl *racl)
118 + return racl->users.count + racl->groups.count
119 +#ifdef ACLS_NEED_MASK
122 + + (racl->mask != ACL_NO_ENTRY) + 3;
126 +static int rsync_acl_get_perms(const rsync_acl *racl)
128 + /* Note that (ACL_NO_ENTRY & 7) is 0. */
129 + return ((racl->user_obj & 7) << 6)
130 + + (((racl->mask != ACL_NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
131 + + (racl->other & 7);
134 +static void rsync_acl_strip_perms(rsync_acl *racl)
136 + racl->user_obj = ACL_NO_ENTRY;
137 + if (racl->mask == ACL_NO_ENTRY)
138 + racl->group_obj = ACL_NO_ENTRY;
140 + racl->mask = ACL_NO_ENTRY;
141 + racl->other = ACL_NO_ENTRY;
144 +static void expand_ida_list(ida_list *idal)
146 + /* First time through, 0 <= 0, so list is expanded. */
147 + if (idal->malloced <= idal->count) {
148 + id_access *new_ptr;
149 + size_t new_size = idal->malloced + 10;
150 + new_ptr = realloc_array(idal->idas, id_access, new_size);
151 + if (verbose >= 4) {
152 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
153 + (double) new_size * sizeof idal->idas[0],
154 + idal->idas ? "" : " not");
157 + idal->idas = new_ptr;
158 + idal->malloced = new_size;
161 + out_of_memory("expand_ida_list");
165 +static void ida_list_free(ida_list *idal)
171 + idal->malloced = 0;
175 +static void rsync_acl_free(rsync_acl *racl)
177 + ida_list_free(&racl->users);
178 + ida_list_free(&racl->groups);
181 +static int id_access_sorter(const void *r1, const void *r2)
183 + id_access *ida1 = (id_access *)r1;
184 + id_access *ida2 = (id_access *)r2;
185 + id_t rid1 = ida1->id, rid2 = ida2->id;
186 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
189 +static void sort_ida_list(ida_list *idal)
193 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
194 + &id_access_sorter);
197 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
199 + SMB_ACL_ENTRY_T entry;
200 + const char *errfun;
203 + *racl = rsync_acl_initializer;
204 + errfun = "sys_acl_get_entry";
205 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
207 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
208 + SMB_ACL_TAG_T tag_type;
209 + SMB_ACL_PERMSET_T permset;
214 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
215 + errfun = "sys_acl_get_tag_type";
218 + if ((rc = sys_acl_get_permset(entry, &permset))) {
219 + errfun = "sys_acl_get_tag_type";
222 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
223 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
224 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
225 + /* continue == done with entry; break == store in given idal */
226 + switch (tag_type) {
227 + case SMB_ACL_USER_OBJ:
228 + if (racl->user_obj == ACL_NO_ENTRY)
229 + racl->user_obj = access;
231 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
234 + idal = &racl->users;
236 + case SMB_ACL_GROUP_OBJ:
237 + if (racl->group_obj == ACL_NO_ENTRY)
238 + racl->group_obj = access;
240 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
242 + case SMB_ACL_GROUP:
243 + idal = &racl->groups;
246 + if (racl->mask == ACL_NO_ENTRY)
247 + racl->mask = access;
249 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
251 + case SMB_ACL_OTHER:
252 + if (racl->other == ACL_NO_ENTRY)
253 + racl->other = access;
255 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
258 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
261 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
262 + errfun = "sys_acl_get_tag_type";
266 + expand_ida_list(idal);
267 + ida = &idal->idas[idal->count++];
268 + ida->id = *((id_t *)qualifier);
269 + ida->access = access;
270 + sys_acl_free_qualifier(qualifier, tag_type);
273 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
274 + errfun, strerror(errno));
275 + rsync_acl_free(racl);
279 + sort_ida_list(&racl->users);
280 + sort_ida_list(&racl->groups);
285 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
287 + id_access *ida1, *ida2;
288 + size_t count = ial1->count;
289 + if (count != ial2->count)
293 + for (; count--; ida1++, ida2++) {
294 + if (ida1->access != ida2->access || ida1->id != ida2->id)
300 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
302 + return (racl1->user_obj == racl2->user_obj
303 + && racl1->group_obj == racl2->group_obj
304 + && racl1->mask == racl2->mask
305 + && racl1->other == racl2->other
306 + && ida_lists_equal(&racl1->users, &racl2->users)
307 + && ida_lists_equal(&racl1->groups, &racl2->groups));
310 +/* The first parameter will always be a fully-populated rsync_acl.
311 + * The second parameter will usually be a condensed rsync_acl, which means
312 + * that it might have several of its access objects set to ACL_NO_ENTRY. */
313 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1,
314 + const rsync_acl *racl2, mode_t m)
316 + /* We ignore any differences that chmod() can take care of. */
317 + if ((racl1->mask ^ racl2->mask) & ACL_NO_ENTRY)
319 + if (racl1->mask != ACL_NO_ENTRY) {
320 + /* A condensed rsync_acl with a mask can only have no
321 + * group_obj when it was identical to the mask. This
322 + * means that it was also identical to the group attrs
323 + * from the mode. */
324 + if (racl2->group_obj == ACL_NO_ENTRY) {
325 + if (racl1->group_obj != ((m >> 3) & 7))
327 + } else if (racl1->group_obj != racl2->group_obj)
330 + return ida_lists_equal(&racl1->users, &racl2->users)
331 + && ida_lists_equal(&racl1->groups, &racl2->groups);
340 +static rsync_acl_list _rsync_acl_lists[] = {
341 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
342 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
345 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
347 + return &_rsync_acl_lists[type != SMB_ACL_TYPE_ACCESS];
350 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
352 + /* First time through, 0 <= 0, so list is expanded. */
353 + if (racl_list->malloced <= racl_list->count) {
354 + rsync_acl *new_ptr;
356 + if (racl_list->malloced < 1000)
357 + new_size = racl_list->malloced + 1000;
359 + new_size = racl_list->malloced * 2;
360 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
361 + if (verbose >= 3) {
362 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
363 + (double) new_size * sizeof racl_list->racls[0],
364 + racl_list->racls ? "" : " not");
367 + racl_list->racls = new_ptr;
368 + racl_list->malloced = new_size;
370 + if (!racl_list->racls)
371 + out_of_memory("expand_rsync_acl_list");
375 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
376 + const rsync_acl_list *racl_list,
377 + const rsync_acl *racl)
379 + static int access_match = -1, default_match = -1;
380 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
381 + size_t count = racl_list->count;
383 + /* If this is the first time through or we didn't match the last
384 + * time, then start at the end of the list, which should be the
385 + * best place to start hunting. */
387 + *match = racl_list->count - 1;
389 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
392 + *match = racl_list->count - 1;
399 +/* The general strategy with the tag_type <-> character mapping is that
400 + * lowercase implies that no qualifier follows, where uppercase does.
401 + * A similar idiom for the acl type (access or default) itself, but
402 + * lowercase in this instance means there's no ACL following, so the
403 + * ACL is a repeat, so the receiver should reuse the last of the same
405 +static void send_ida_list(int f, const ida_list *idal, char tag_char)
408 + size_t count = idal->count;
409 + for (ida = idal->idas; count--; ida++) {
410 + write_byte(f, tag_char);
411 + write_byte(f, ida->access);
412 + write_int(f, ida->id);
413 + /* FIXME: sorta wasteful: we should maybe buffer as
414 + * many ids as max(ACL_USER + ACL_GROUP) objects to
415 + * keep from making so many calls. */
416 + if (tag_char == 'U')
423 +static void send_rsync_acl(int f, const rsync_acl *racl)
425 + size_t count = count_racl_entries(racl);
426 + write_int(f, count);
427 + if (racl->user_obj != ACL_NO_ENTRY) {
428 + write_byte(f, 'u');
429 + write_byte(f, racl->user_obj);
431 + send_ida_list(f, &racl->users, 'U');
432 + if (racl->group_obj != ACL_NO_ENTRY) {
433 + write_byte(f, 'g');
434 + write_byte(f, racl->group_obj);
436 + send_ida_list(f, &racl->groups, 'G');
437 + if (racl->mask != ACL_NO_ENTRY) {
438 + write_byte(f, 'm');
439 + write_byte(f, racl->mask);
441 + if (racl->other != ACL_NO_ENTRY) {
442 + write_byte(f, 'o');
443 + write_byte(f, racl->other);
447 +static rsync_acl _curr_rsync_acls[2];
449 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
451 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
452 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
453 + : "unknown SMB_ACL_TYPE_T";
456 +/* Generate the ACL(s) for this flist entry;
457 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
458 +int make_acl(const struct file_struct *file, const char *fname)
460 + SMB_ACL_TYPE_T type;
461 + rsync_acl *curr_racl;
463 + if (S_ISLNK(file->mode))
466 + curr_racl = &_curr_rsync_acls[0];
467 + type = SMB_ACL_TYPE_ACCESS;
471 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
472 + ok = unpack_smb_acl(curr_racl, sacl);
473 + sys_acl_free_acl(sacl);
476 + /* Avoid sending a redundant group/mask value. */
477 + if (curr_racl->group_obj == curr_racl->mask
478 + && (preserve_acls == 1
479 + || (!curr_racl->users.count
480 + && !curr_racl->groups.count)))
481 + curr_racl->mask = ACL_NO_ENTRY;
482 + /* Strip access ACLs of permission-bit entries. */
483 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
484 + rsync_acl_strip_perms(curr_racl);
485 + } else if (errno == ENOTSUP) {
486 + /* ACLs are not supported. Leave list empty. */
487 + *curr_racl = rsync_acl_initializer;
489 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
490 + fname, str_acl_type(type), strerror(errno));
494 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
499 +/* Send the make_acl()-generated ACLs for this flist entry,
500 + * or clean up after an flist entry that's not being sent (f == -1). */
501 +void send_acl(const struct file_struct *file, int f)
503 + SMB_ACL_TYPE_T type;
504 + rsync_acl *curr_racl;
506 + if (S_ISLNK(file->mode))
509 + curr_racl = &_curr_rsync_acls[0];
510 + type = SMB_ACL_TYPE_ACCESS;
513 + rsync_acl_list *racl_list = rsync_acl_lists(type);
515 + rsync_acl_free(curr_racl);
518 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
520 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
521 + write_int(f, index);
522 + rsync_acl_free(curr_racl);
524 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
525 + send_rsync_acl(f, curr_racl);
526 + expand_rsync_acl_list(racl_list);
527 + racl_list->racls[racl_list->count++] = *curr_racl;
530 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
533 +/* The below stuff is only used by the receiver: */
535 +/* structure to hold index to rsync_acl_list member corresponding to
536 + * flist->files[i] */
539 + const struct file_struct *file;
546 + file_acl_index *fais;
547 +} file_acl_index_list;
549 +static file_acl_index_list _file_acl_index_lists[] = {
550 + {0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
551 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
554 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
556 + return &_file_acl_index_lists[type != SMB_ACL_TYPE_ACCESS];
559 +static void expand_file_acl_index_list(file_acl_index_list *flst)
561 + /* First time through, 0 <= 0, so list is expanded. */
562 + if (flst->malloced <= flst->count) {
563 + file_acl_index *new_ptr;
566 + if (flst->malloced < 1000)
567 + new_size = flst->malloced + 1000;
569 + new_size = flst->malloced * 2;
570 + new_ptr = realloc_array(flst->fais, file_acl_index, new_size);
571 + if (verbose >= 3) {
572 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
573 + (double) new_size * sizeof flst->fais[0],
574 + flst->fais ? "" : " not");
577 + flst->fais = new_ptr;
578 + flst->malloced = new_size;
581 + out_of_memory("expand_file_acl_index_list");
585 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
593 +static smb_acl_list _smb_acl_lists[] = {
594 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
595 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
598 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
600 + return &_smb_acl_lists[type != SMB_ACL_TYPE_ACCESS];
603 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
605 + /* First time through, 0 <= 0, so list is expanded. */
606 + if (sacl_list->malloced <= sacl_list->count) {
607 + SMB_ACL_T *new_ptr;
609 + if (sacl_list->malloced < 1000)
610 + new_size = sacl_list->malloced + 1000;
612 + new_size = sacl_list->malloced * 2;
613 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
614 + if (verbose >= 3) {
615 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
616 + (double) new_size * sizeof sacl_list->sacls[0],
617 + sacl_list->sacls ? "" : " not");
620 + sacl_list->sacls = new_ptr;
621 + sacl_list->malloced = new_size;
623 + if (!sacl_list->sacls)
624 + out_of_memory("expand_smb_acl_list");
628 +#define CALL_OR_ERROR(func,args,str) \
636 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
637 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
639 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
641 + const char *errfun = NULL;
642 + SMB_ACL_PERMSET_T permset;
644 + COE( sys_acl_get_permset,(entry, &permset) );
645 + COE( sys_acl_clear_perms,(permset) );
647 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
649 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
651 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
652 + COE( sys_acl_set_permset,(entry, permset) );
657 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
662 +/* build an SMB_ACL_T corresponding to an rsync_acl */
663 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
667 + const char *errfun = NULL;
668 + SMB_ACL_ENTRY_T entry;
670 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
671 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
676 + COE( sys_acl_create_entry,(smb_acl, &entry) );
677 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
678 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
680 + for (ida = racl->users.idas, count = racl->users.count;
682 + COE( sys_acl_create_entry,(smb_acl, &entry) );
683 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
684 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
685 + COE2( store_access_in_entry,(ida->access, entry) );
688 + COE( sys_acl_create_entry,(smb_acl, &entry) );
689 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
690 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
692 + for (ida = racl->groups.idas, count = racl->groups.count;
694 + COE( sys_acl_create_entry,(smb_acl, &entry) );
695 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
696 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
697 + COE2( store_access_in_entry,(ida->access, entry) );
699 +#ifndef ACLS_NEED_MASK
700 + if (racl->mask != ACL_NO_ENTRY) {
702 + COE( sys_acl_create_entry,(smb_acl, &entry) );
703 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
704 + COE2( store_access_in_entry,(racl->mask, entry) );
705 +#ifndef ACLS_NEED_MASK
709 + COE( sys_acl_create_entry,(smb_acl, &entry) );
710 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
711 + COE2( store_access_in_entry,(racl->other & 7, entry) );
714 + if (sys_acl_valid(*smb_acl) < 0)
715 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
722 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
725 + sys_acl_free_acl(*smb_acl);
729 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
731 + SMB_ACL_ENTRY_T entry;
732 + const char *errfun;
735 + if (S_ISDIR(mode)) {
736 + /* If the sticky bit is going on, it's not safe to allow all
737 + * the new ACLs to go into effect before it gets set. */
738 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
739 + if (mode & S_ISVTX)
742 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
745 + /* If setuid or setgid is going off, it's not safe to allow all
746 + * the new ACLs to go into effect before they get cleared. */
747 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
748 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
753 + errfun = "sys_acl_get_entry";
754 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
756 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
757 + SMB_ACL_TAG_T tag_type;
758 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
759 + errfun = "sys_acl_get_tag_type";
762 + switch (tag_type) {
763 + case SMB_ACL_USER_OBJ:
764 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
766 + case SMB_ACL_GROUP_OBJ:
767 + /* group is only empty when identical to group perms. */
768 + if (racl->group_obj != ACL_NO_ENTRY)
770 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
773 +#ifndef ACLS_NEED_MASK
774 + /* mask is only empty when we don't need it. */
775 + if (racl->mask == ACL_NO_ENTRY)
778 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
780 + case SMB_ACL_OTHER:
781 + COE2( store_access_in_entry,(mode & 7, entry) );
788 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
789 + errfun, strerror(errno));
794 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
795 + /* Ensure that chmod() will be called to restore any lost setid bits. */
796 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
797 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
798 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
801 + /* Return the mode of the file on disk, as we will set them. */
802 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
805 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
807 + uchar computed_mask_bits = 0;
808 + ida_list *idal = NULL;
812 + *racl = rsync_acl_initializer;
814 + if (!(count = read_int(f)))
818 + char tag = read_byte(f);
819 + uchar access = read_byte(f);
820 + if (access & ~ (4 | 2 | 1)) {
821 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
823 + exit_cleanup(RERR_STREAMIO);
827 + if (racl->user_obj != ACL_NO_ENTRY) {
828 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
829 + exit_cleanup(RERR_STREAMIO);
831 + racl->user_obj = access;
834 + idal = &racl->users;
837 + if (racl->group_obj != ACL_NO_ENTRY) {
838 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
839 + exit_cleanup(RERR_STREAMIO);
841 + racl->group_obj = access;
844 + idal = &racl->groups;
847 + if (racl->mask != ACL_NO_ENTRY) {
848 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
849 + exit_cleanup(RERR_STREAMIO);
851 + racl->mask = access;
854 + if (racl->other != ACL_NO_ENTRY) {
855 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
856 + exit_cleanup(RERR_STREAMIO);
858 + racl->other = access;
861 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
863 + exit_cleanup(RERR_STREAMIO);
865 + expand_ida_list(idal);
866 + ida = &idal->idas[idal->count++];
867 + ida->access = access;
868 + ida->id = read_int(f);
869 + computed_mask_bits |= access;
872 + if (type == SMB_ACL_TYPE_DEFAULT) {
873 + /* Ensure that these are never unset. */
874 + if (racl->user_obj == ACL_NO_ENTRY)
875 + racl->user_obj = 7;
876 + if (racl->group_obj == ACL_NO_ENTRY)
877 + racl->group_obj = 0;
878 + if (racl->other == ACL_NO_ENTRY)
881 +#ifndef ACLS_NEED_MASK
882 + if (!racl->users.count && !racl->groups.count) {
883 + /* If we, a system without ACLS_NEED_MASK, received a
884 + * superfluous mask, throw it away. */
885 + if (racl->mask != ACL_NO_ENTRY) {
886 + /* mask off group perms with it first */
887 + racl->group_obj &= racl->mask | ACL_NO_ENTRY;
888 + racl->mask = ACL_NO_ENTRY;
892 + if (racl->mask == ACL_NO_ENTRY) /* Always non-empty when needed. */
893 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
896 +/* receive and build the rsync_acl_lists */
897 +void receive_acl(struct file_struct *file, int f)
899 + SMB_ACL_TYPE_T type;
902 + if (S_ISLNK(file->mode))
905 + fname = f_name(file, NULL);
906 + type = SMB_ACL_TYPE_ACCESS;
909 + file_acl_index_list *flst = file_acl_index_lists(type);
911 + expand_file_acl_index_list(flst);
913 + tag = read_byte(f);
914 + if (tag == 'A' || tag == 'a') {
915 + if (type != SMB_ACL_TYPE_ACCESS) {
916 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
918 + exit_cleanup(RERR_STREAMIO);
920 + } else if (tag == 'D' || tag == 'd') {
921 + if (type == SMB_ACL_TYPE_ACCESS) {
922 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
924 + exit_cleanup(RERR_STREAMIO);
927 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
929 + exit_cleanup(RERR_STREAMIO);
931 + if (tag == 'A' || tag == 'D') {
933 + rsync_acl_list *racl_list = rsync_acl_lists(type);
934 + smb_acl_list *sacl_list = smb_acl_lists(type);
935 + flst->fais[flst->count].aclidx = racl_list->count;
936 + flst->fais[flst->count++].file = file;
937 + receive_rsync_acl(&racl, f, type);
938 + expand_rsync_acl_list(racl_list);
939 + racl_list->racls[racl_list->count++] = racl;
940 + expand_smb_acl_list(sacl_list);
941 + sacl_list->sacls[sacl_list->count++] = NULL;
943 + int index = read_int(f);
944 + rsync_acl_list *racl_list = rsync_acl_lists(type);
945 + if ((size_t) index >= racl_list->count) {
946 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
948 + str_acl_type(type),
950 + exit_cleanup(RERR_STREAMIO);
952 + flst->fais[flst->count].aclidx = index;
953 + flst->fais[flst->count++].file = file;
955 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
958 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
960 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
961 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
962 + return fileaclidx1->file == fileaclidx2->file ? 0
963 + : fileaclidx1->file < fileaclidx2->file ? -1 : 1;
966 +void sort_file_acl_index_lists()
968 + SMB_ACL_TYPE_T type;
970 + type = SMB_ACL_TYPE_ACCESS;
972 + file_acl_index_list *flst = file_acl_index_lists(type);
977 + qsort(flst->fais, flst->count, sizeof flst->fais[0],
978 + &file_acl_index_list_sorter);
979 + } while (BUMP_TYPE(type));
982 +static int find_file_acl_index(const file_acl_index_list *flst,
983 + const struct file_struct *file)
985 + int low = 0, high = flst->count;
986 + const struct file_struct *file_mid;
991 + int mid = (high + low) / 2;
992 + file_mid = flst->fais[mid].file;
993 + if (file_mid == file)
994 + return flst->fais[mid].aclidx;
995 + if (file_mid > file)
999 + } while (low < high);
1000 + if (low == high) {
1001 + file_mid = flst->fais[low].file;
1002 + if (file_mid == file)
1003 + return flst->fais[low].aclidx;
1006 + "find_file_acl_index: can't find entry for file in list\n");
1007 + exit_cleanup(RERR_STREAMIO);
1011 +/* for duplicating ACLs on backups when using backup_dir */
1012 +int dup_acl(const char *orig, const char *bak, mode_t mode)
1014 + SMB_ACL_TYPE_T type;
1017 + type = SMB_ACL_TYPE_ACCESS;
1019 + SMB_ACL_T sacl_orig, sacl_bak;
1020 + rsync_acl racl_orig, racl_bak;
1021 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
1022 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
1023 + orig, str_acl_type(type), strerror(errno));
1027 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
1028 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
1029 + bak, str_acl_type(type), strerror(errno));
1031 + /* try to forge on through */
1033 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
1035 + goto out_with_sacls;
1038 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
1040 + goto out_with_one_racl;
1042 + if (rsync_acls_equal(&racl_orig, &racl_bak))
1043 + goto out_with_all;
1045 + ; /* presume they're unequal */
1047 + if (type == SMB_ACL_TYPE_DEFAULT
1048 + && racl_orig.user_obj == ACL_NO_ENTRY) {
1049 + if (sys_acl_delete_def_file(bak) < 0) {
1050 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
1051 + bak, strerror(errno));
1054 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
1055 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
1056 + bak, str_acl_type(type), strerror(errno));
1061 + rsync_acl_free(&racl_bak);
1062 + out_with_one_racl:
1063 + rsync_acl_free(&racl_orig);
1066 + sys_acl_free_acl(sacl_bak);
1068 + sys_acl_free_acl(sacl_orig);
1069 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1074 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1075 + * for keep_backup(). */
1076 +static const struct file_struct *backup_orig_file = NULL;
1077 +static const char null_string[] = "";
1078 +static const char *backup_orig_fname = null_string;
1079 +static const char *backup_dest_fname = null_string;
1080 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1082 +void push_keep_backup_acl(const struct file_struct *file,
1083 + const char *orig, const char *dest)
1085 + SMB_ACL_TYPE_T type;
1088 + backup_orig_file = file;
1089 + backup_orig_fname = orig;
1090 + backup_dest_fname = dest;
1092 + sacl = &_backup_sacl[0];
1093 + type = SMB_ACL_TYPE_ACCESS;
1095 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1099 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1101 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1102 + orig, str_acl_type(type),
1105 + } while (BUMP_TYPE(type));
1108 +static int set_keep_backup_acl()
1110 + SMB_ACL_TYPE_T type;
1114 + sacl = &_backup_sacl[0];
1115 + type = SMB_ACL_TYPE_ACCESS;
1118 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1120 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1121 + backup_dest_fname,
1122 + str_acl_type(type),
1126 + } while (BUMP_TYPE(type));
1131 +void cleanup_keep_backup_acl()
1133 + SMB_ACL_TYPE_T type;
1136 + backup_orig_file = NULL;
1137 + backup_orig_fname = null_string;
1138 + backup_dest_fname = null_string;
1140 + sacl = &_backup_sacl[0];
1141 + type = SMB_ACL_TYPE_ACCESS;
1144 + sys_acl_free_acl(*sacl);
1147 + } while (BUMP_TYPE(type));
1150 +/* set ACL on rsync-ed or keep_backup-ed file
1152 + * This sets extended access ACL entries and default ACLs. If convenient,
1153 + * it sets permission bits along with the access ACLs and signals having
1154 + * done so by modifying mode_p, which should point into the stat buffer.
1156 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1157 + * Pass NULL for mode_p to get the return code without changing anything. */
1158 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1160 + int unchanged = 1;
1161 + SMB_ACL_TYPE_T type;
1163 + if (S_ISLNK(file->mode))
1166 + if (file == backup_orig_file) {
1167 + if (!strcmp(fname, backup_dest_fname))
1168 + return set_keep_backup_acl();
1170 + type = SMB_ACL_TYPE_ACCESS;
1173 + SMB_ACL_T sacl_orig, *sacl_new;
1174 + rsync_acl racl_orig, *racl_new;
1175 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1177 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1178 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1179 + sacl_orig = sys_acl_get_file(fname, type);
1181 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1182 + fname, str_acl_type(type), strerror(errno));
1186 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1187 + sys_acl_free_acl(sacl_orig);
1192 + if (type == SMB_ACL_TYPE_ACCESS)
1193 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new, file->mode);
1195 + ok = rsync_acls_equal(&racl_orig, racl_new);
1196 + rsync_acl_free(&racl_orig);
1199 + if (!dry_run && mode_p) {
1200 + if (type == SMB_ACL_TYPE_DEFAULT
1201 + && racl_new->user_obj == ACL_NO_ENTRY) {
1202 + if (sys_acl_delete_def_file(fname) < 0) {
1203 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1204 + fname, strerror(errno));
1209 + mode_t cur_mode = *mode_p;
1211 + && !pack_smb_acl(sacl_new, racl_new)) {
1215 + if (type == SMB_ACL_TYPE_ACCESS) {
1216 + cur_mode = change_sacl_perms(*sacl_new, racl_new,
1217 + cur_mode, file->mode);
1218 + if (cur_mode == ~0u)
1221 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1222 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1223 + fname, str_acl_type(type),
1228 + if (type == SMB_ACL_TYPE_ACCESS)
1229 + *mode_p = cur_mode;
1232 + if (unchanged == 1)
1234 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1239 +/* Enumeration functions for uid mapping: */
1241 +/* Context -- one and only one. Should be cycled through once on uid
1242 + * mapping and once on gid mapping. */
1243 +static rsync_acl_list *_enum_racl_lists[] = {
1244 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1247 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1248 +static size_t enum_racl_index = 0;
1249 +static size_t enum_ida_index = 0;
1251 +/* This returns the next tag_type id from the given acl for the next entry,
1252 + * or it returns 0 if there are no more tag_type ids in the acl. */
1253 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1255 + const ida_list *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1256 + if (enum_ida_index < idal->count) {
1257 + id_access *ida = &idal->idas[enum_ida_index++];
1260 + enum_ida_index = 0;
1264 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1266 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1267 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1268 + id_t *id = next_ace_id(tag_type, racl);
1272 + enum_racl_index = 0;
1276 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1278 + for (; *enum_racl_list; enum_racl_list++) {
1279 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1283 + enum_racl_list = &_enum_racl_lists[0];
1287 +id_t *next_acl_uid()
1289 + return next_acl_list_id(SMB_ACL_USER);
1292 +id_t *next_acl_gid()
1294 + return next_acl_list_id(SMB_ACL_GROUP);
1297 +int default_perms_for_dir(const char *dir)
1306 + perms = ACCESSPERMS & ~orig_umask;
1307 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1308 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1309 + if (sacl == NULL) {
1310 + /* Couldn't get an ACL. Darn. */
1313 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1317 + /* We're doing a dry run, so the containing directory
1318 + * wasn't actually created. Don't worry about it. */
1321 + /* Otherwise fall through. */
1323 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1324 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1330 + ok = unpack_smb_acl(&racl, sacl);
1331 + sys_acl_free_acl(sacl);
1333 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1337 + /* Apply the permission-bit entries of the default ACL, if any. */
1338 + if (racl.user_obj != ACL_NO_ENTRY) {
1339 + perms = rsync_acl_get_perms(&racl);
1341 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1344 + rsync_acl_free(&racl);
1348 +#endif /* SUPPORT_ACLS */
1351 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1352 extern char *backup_dir;
1355 +extern int preserve_acls;
1356 extern int preserve_devices;
1357 extern int preserve_specials;
1358 extern int preserve_links;
1359 @@ -133,6 +134,10 @@ static int make_bak_dir(char *fullpath)
1361 do_lchown(fullpath, st.st_uid, st.st_gid);
1362 do_chmod(fullpath, st.st_mode);
1363 +#ifdef SUPPORT_ACLS
1364 + if (preserve_acls)
1365 + dup_acl(end, fullpath, st.st_mode);
1370 @@ -186,6 +191,11 @@ static int keep_backup(char *fname)
1371 if (!(buf = get_backup_name(fname)))
1374 +#ifdef SUPPORT_ACLS
1375 + if (preserve_acls)
1376 + push_keep_backup_acl(file, fname, buf);
1379 /* Check to see if this is a device file, or link */
1380 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1381 || (preserve_specials && IS_SPECIAL(file->mode))) {
1382 @@ -261,6 +271,10 @@ static int keep_backup(char *fname)
1385 set_file_attrs(buf, file, NULL, 0);
1386 +#ifdef SUPPORT_ACLS
1387 + if (preserve_acls)
1388 + cleanup_keep_backup_acl();
1393 --- old/configure.in
1394 +++ new/configure.in
1395 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1396 AC_CHECK_LIB(resolv, strcasecmp)
1399 +AC_CHECK_FUNCS(aclsort)
1400 +if test x"$ac_cv_func_aclsort" = x"no"; then
1401 + AC_CHECK_LIB(sec, aclsort)
1404 dnl At the moment we don't test for a broken memcmp(), because all we
1405 dnl need to do is test for equality, not comparison, and it seems that
1406 dnl every platform has a memcmp that can do at least that.
1407 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1408 AC_SUBST(CC_SHOBJ_FLAG)
1409 AC_SUBST(BUILD_POPT)
1411 +AC_CHECK_HEADERS(sys/acl.h)
1412 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1413 +#################################################
1414 +# check for ACL support
1416 +AC_MSG_CHECKING(whether to support ACLs)
1417 +AC_ARG_ENABLE(acl-support,
1418 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1419 +[ case "$enableval" in
1422 + case "$host_os" in
1424 + AC_MSG_RESULT(Using UnixWare ACLs)
1425 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1427 + *solaris*|*cygwin*)
1428 + AC_MSG_RESULT(Using solaris ACLs)
1429 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1432 + AC_MSG_RESULT(Using HPUX ACLs)
1433 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1436 + AC_MSG_RESULT(Using IRIX ACLs)
1437 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1440 + AC_MSG_RESULT(Using AIX ACLs)
1441 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1444 + AC_MSG_RESULT(Using Tru64 ACLs)
1445 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1446 + LIBS="$LIBS -lpacl"
1449 + AC_MSG_RESULT(ACLs requested -- running tests)
1450 + AC_CHECK_LIB(acl,acl_get_file)
1451 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1452 + AC_TRY_LINK([#include <sys/types.h>
1453 +#include <sys/acl.h>],
1454 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1455 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1456 + AC_MSG_CHECKING(ACL test results)
1457 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1458 + AC_MSG_RESULT(Using posix ACLs)
1459 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1460 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1461 + AC_TRY_LINK([#include <sys/types.h>
1462 +#include <sys/acl.h>],
1463 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1464 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1465 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1466 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1469 + AC_MSG_ERROR(Failed to find ACL support)
1476 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1479 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1483 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1488 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1489 extern int one_file_system;
1490 extern int copy_dirlinks;
1491 extern int keep_dirlinks;
1492 +extern int preserve_acls;
1493 extern int preserve_links;
1494 extern int preserve_hard_links;
1495 extern int preserve_devices;
1496 @@ -961,6 +962,11 @@ static struct file_struct *send_file_nam
1497 if (chmod_modes && !S_ISLNK(file->mode))
1498 file->mode = tweak_mode(file->mode, chmod_modes);
1500 +#ifdef SUPPORT_ACLS
1501 + if (preserve_acls && make_acl(file, fname) < 0)
1505 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1507 flist_expand(flist);
1508 @@ -968,6 +974,16 @@ static struct file_struct *send_file_nam
1509 if (file->basename[0]) {
1510 flist->files[flist->count++] = file;
1511 send_file_entry(file, f);
1512 +#ifdef SUPPORT_ACLS
1513 + if (preserve_acls)
1514 + send_acl(file, f);
1517 +#ifdef SUPPORT_ACLS
1518 + /* Cleanup unsent ACL(s). */
1519 + if (preserve_acls)
1520 + send_acl(file, -1);
1525 @@ -1356,6 +1372,11 @@ struct file_list *recv_file_list(int f)
1526 flags |= read_byte(f) << 8;
1527 file = receive_file_entry(flist, flags, f);
1529 +#ifdef SUPPORT_ACLS
1530 + if (preserve_acls)
1531 + receive_acl(file, f);
1534 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1535 stats.total_size += file->length;
1537 @@ -1378,6 +1399,11 @@ struct file_list *recv_file_list(int f)
1539 clean_flist(flist, relative_paths, 1);
1541 +#ifdef SUPPORT_ACLS
1542 + if (preserve_acls)
1543 + sort_file_acl_index_lists();
1547 recv_uid_list(f, flist);
1551 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1552 extern int max_delete;
1553 extern int force_delete;
1554 extern int one_file_system;
1555 +extern mode_t orig_umask;
1556 extern struct stats stats;
1557 extern dev_t filesystem_dev;
1558 extern char *backup_dir;
1559 @@ -319,6 +320,8 @@ static void do_delete_pass(struct file_l
1561 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1563 + /* FIXME: Flag ACL changes. */
1566 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1568 @@ -353,6 +356,7 @@ void itemize(struct file_struct *file, i
1569 if (preserve_gid && file->gid != GID_NONE
1570 && st->st_gid != file->gid)
1571 iflags |= ITEM_REPORT_GROUP;
1572 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1574 iflags |= ITEM_IS_NEW;
1576 @@ -769,6 +773,7 @@ static int try_dests_non(struct file_str
1579 static int phase = 0;
1580 +static int dflt_perms;
1582 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1583 * make sure it exists, and has the right permissions/timestamp info. For
1584 @@ -860,6 +865,10 @@ static void recv_generator(char *fname,
1587 need_fuzzy_dirlist = 1;
1588 +#ifdef SUPPORT_ACLS
1589 + if (!preserve_perms)
1590 + dflt_perms = default_perms_for_dir(dn);
1593 parent_dirname = dn;
1595 @@ -887,7 +896,8 @@ static void recv_generator(char *fname,
1596 if (!preserve_perms) {
1597 int exists = statret == 0
1598 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1599 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1600 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1604 if (S_ISDIR(file->mode)) {
1605 @@ -1366,6 +1376,8 @@ void generate_files(int f_out, struct fi
1606 * notice that and let us know via the redo pipe (or its closing). */
1609 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1611 for (i = 0; i < flist->count; i++) {
1612 struct file_struct *file = flist->files[i];
1614 --- old/lib/sysacls.c
1615 +++ new/lib/sysacls.c
1618 + Unix SMB/CIFS implementation.
1619 + Samba system utilities for ACL support.
1620 + Copyright (C) Jeremy Allison 2000.
1622 + This program is free software; you can redistribute it and/or modify
1623 + it under the terms of the GNU General Public License as published by
1624 + the Free Software Foundation; either version 2 of the License, or
1625 + (at your option) any later version.
1627 + This program is distributed in the hope that it will be useful,
1628 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1629 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1630 + GNU General Public License for more details.
1632 + You should have received a copy of the GNU General Public License
1633 + along with this program; if not, write to the Free Software
1634 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1638 +#include "sysacls.h" /****** ADDED ******/
1640 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1641 +void SAFE_FREE(void *mem)
1647 +char *uidtoname(uid_t uid)
1649 + static char idbuf[12];
1650 + struct passwd *pw;
1652 + if ((pw = getpwuid(uid)) == NULL) {
1653 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1656 + return pw->pw_name;
1658 +/****** EXTRAS -- END ******/
1661 + This file wraps all differing system ACL interfaces into a consistent
1662 + one based on the POSIX interface. It also returns the correct errors
1663 + for older UNIX systems that don't support ACLs.
1665 + The interfaces that each ACL implementation must support are as follows :
1667 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1668 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1669 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1670 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1671 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1672 + SMB_ACL_T sys_acl_get_fd(int fd)
1673 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1674 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1675 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1676 + SMB_ACL_T sys_acl_init( int count)
1677 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1678 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1679 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1680 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1681 + int sys_acl_valid( SMB_ACL_T theacl )
1682 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1683 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1684 + int sys_acl_delete_def_file(const char *path)
1686 + This next one is not POSIX complient - but we *have* to have it !
1687 + More POSIX braindamage.
1689 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1691 + The generic POSIX free is the following call. We split this into
1692 + several different free functions as we may need to add tag info
1693 + to structures when emulating the POSIX interface.
1695 + int sys_acl_free( void *obj_p)
1697 + The calls we actually use are :
1699 + int sys_acl_free_text(char *text) - free acl_to_text
1700 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1701 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1705 +#if defined(HAVE_POSIX_ACLS)
1707 +/* Identity mapping - easy. */
1709 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1711 + return acl_get_entry( the_acl, entry_id, entry_p);
1714 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1716 + return acl_get_tag_type( entry_d, tag_type_p);
1719 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1721 + return acl_get_permset( entry_d, permset_p);
1724 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1726 + return acl_get_qualifier( entry_d);
1729 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1731 + return acl_get_file( path_p, type);
1734 +SMB_ACL_T sys_acl_get_fd(int fd)
1736 + return acl_get_fd(fd);
1739 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1741 + return acl_clear_perms(permset);
1744 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1746 + return acl_add_perm(permset, perm);
1749 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1751 +#if defined(HAVE_ACL_GET_PERM_NP)
1753 + * Required for TrustedBSD-based ACL implementations where
1754 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1757 + return acl_get_perm_np(permset, perm);
1759 + return acl_get_perm(permset, perm);
1763 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1765 + return acl_to_text( the_acl, plen);
1768 +SMB_ACL_T sys_acl_init( int count)
1770 + return acl_init(count);
1773 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1775 + return acl_create_entry(pacl, pentry);
1778 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1780 + return acl_set_tag_type(entry, tagtype);
1783 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1785 + return acl_set_qualifier(entry, qual);
1788 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1790 + return acl_set_permset(entry, permset);
1793 +int sys_acl_valid( SMB_ACL_T theacl )
1795 + return acl_valid(theacl);
1798 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1800 + return acl_set_file(name, acltype, theacl);
1803 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1805 + return acl_set_fd(fd, theacl);
1808 +int sys_acl_delete_def_file(const char *name)
1810 + return acl_delete_def_file(name);
1813 +int sys_acl_free_text(char *text)
1815 + return acl_free(text);
1818 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1820 + return acl_free(the_acl);
1823 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1825 + return acl_free(qual);
1828 +#elif defined(HAVE_TRU64_ACLS)
1830 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1831 + * is based on Draft 13 of the POSIX spec which is
1832 + * slightly different from the Draft 16 interface.
1834 + * Also, some of the permset manipulation functions
1835 + * such as acl_clear_perm() and acl_add_perm() appear
1836 + * to be broken on Tru64 so we have to manipulate
1837 + * the permission bits in the permset directly.
1839 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1841 + SMB_ACL_ENTRY_T entry;
1843 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1848 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1853 + return errno ? -1 : 0;
1856 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1858 + return acl_get_tag_type( entry_d, tag_type_p);
1861 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1863 + return acl_get_permset( entry_d, permset_p);
1866 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1868 + return acl_get_qualifier( entry_d);
1871 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1873 + return acl_get_file((char *)path_p, type);
1876 +SMB_ACL_T sys_acl_get_fd(int fd)
1878 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1881 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1883 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1888 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1890 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1895 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1900 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1902 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1905 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1907 + return acl_to_text( the_acl, plen);
1910 +SMB_ACL_T sys_acl_init( int count)
1912 + return acl_init(count);
1915 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1917 + SMB_ACL_ENTRY_T entry;
1919 + if ((entry = acl_create_entry(pacl)) == NULL) {
1927 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1929 + return acl_set_tag_type(entry, tagtype);
1932 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1934 + return acl_set_qualifier(entry, qual);
1937 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1939 + return acl_set_permset(entry, permset);
1942 +int sys_acl_valid( SMB_ACL_T theacl )
1944 + acl_entry_t entry;
1946 + return acl_valid(theacl, &entry);
1949 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1951 + return acl_set_file((char *)name, acltype, theacl);
1954 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1956 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1959 +int sys_acl_delete_def_file(const char *name)
1961 + return acl_delete_def_file((char *)name);
1964 +int sys_acl_free_text(char *text)
1967 + * (void) cast and explicit return 0 are for DEC UNIX
1968 + * which just #defines acl_free_text() to be free()
1970 + (void) acl_free_text(text);
1974 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1976 + return acl_free(the_acl);
1979 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1981 + return acl_free_qualifier(qual, tagtype);
1984 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1987 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1988 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1992 + * Note that while this code implements sufficient functionality
1993 + * to support the sys_acl_* interfaces it does not provide all
1994 + * of the semantics of the POSIX ACL interfaces.
1996 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1997 + * from a call to sys_acl_get_entry() should not be assumed to be
1998 + * valid after calling any of the following functions, which may
1999 + * reorder the entries in the ACL.
2002 + * sys_acl_set_file()
2003 + * sys_acl_set_fd()
2007 + * The only difference between Solaris and UnixWare / OpenUNIX is
2008 + * that the #defines for the ACL operations have different names
2010 +#if defined(HAVE_UNIXWARE_ACLS)
2012 +#define SETACL ACL_SET
2013 +#define GETACL ACL_GET
2014 +#define GETACLCNT ACL_CNT
2019 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2021 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2026 + if (entry_p == NULL) {
2031 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2035 + if (acl_d->next < 0) {
2040 + if (acl_d->next >= acl_d->count) {
2044 + *entry_p = &acl_d->acl[acl_d->next++];
2049 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2051 + *type_p = entry_d->a_type;
2056 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2058 + *permset_p = &entry_d->a_perm;
2063 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2065 + if (entry_d->a_type != SMB_ACL_USER
2066 + && entry_d->a_type != SMB_ACL_GROUP) {
2071 + return &entry_d->a_id;
2075 + * There is no way of knowing what size the ACL returned by
2076 + * GETACL will be unless you first call GETACLCNT which means
2077 + * making an additional system call.
2079 + * In the hope of avoiding the cost of the additional system
2080 + * call in most cases, we initially allocate enough space for
2081 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2082 + * be too small then we use GETACLCNT to find out the actual
2083 + * size, reallocate the ACL buffer, and then call GETACL again.
2086 +#define INITIAL_ACL_SIZE 16
2088 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2091 + int count; /* # of ACL entries allocated */
2092 + int naccess; /* # of access ACL entries */
2093 + int ndefault; /* # of default ACL entries */
2095 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2100 + count = INITIAL_ACL_SIZE;
2101 + if ((acl_d = sys_acl_init(count)) == NULL) {
2106 + * If there isn't enough space for the ACL entries we use
2107 + * GETACLCNT to determine the actual number of ACL entries
2108 + * reallocate and try again. This is in a loop because it
2109 + * is possible that someone else could modify the ACL and
2110 + * increase the number of entries between the call to
2111 + * GETACLCNT and the call to GETACL.
2113 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2114 + && errno == ENOSPC) {
2116 + sys_acl_free_acl(acl_d);
2118 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2122 + if ((acl_d = sys_acl_init(count)) == NULL) {
2128 + sys_acl_free_acl(acl_d);
2133 + * calculate the number of access and default ACL entries
2135 + * Note: we assume that the acl() system call returned a
2136 + * well formed ACL which is sorted so that all of the
2137 + * access ACL entries preceed any default ACL entries
2139 + for (naccess = 0; naccess < count; naccess++) {
2140 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2143 + ndefault = count - naccess;
2146 + * if the caller wants the default ACL we have to copy
2147 + * the entries down to the start of the acl[] buffer
2148 + * and mask out the ACL_DEFAULT flag from the type field
2150 + if (type == SMB_ACL_TYPE_DEFAULT) {
2153 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2154 + acl_d->acl[i] = acl_d->acl[j];
2155 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2158 + acl_d->count = ndefault;
2160 + acl_d->count = naccess;
2166 +SMB_ACL_T sys_acl_get_fd(int fd)
2169 + int count; /* # of ACL entries allocated */
2170 + int naccess; /* # of access ACL entries */
2172 + count = INITIAL_ACL_SIZE;
2173 + if ((acl_d = sys_acl_init(count)) == NULL) {
2177 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2178 + && errno == ENOSPC) {
2180 + sys_acl_free_acl(acl_d);
2182 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2186 + if ((acl_d = sys_acl_init(count)) == NULL) {
2192 + sys_acl_free_acl(acl_d);
2197 + * calculate the number of access ACL entries
2199 + for (naccess = 0; naccess < count; naccess++) {
2200 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2204 + acl_d->count = naccess;
2209 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2216 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2218 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2219 + && perm != SMB_ACL_EXECUTE) {
2224 + if (permset_d == NULL) {
2229 + *permset_d |= perm;
2234 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2236 + return *permset_d & perm;
2239 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2246 + * use an initial estimate of 20 bytes per ACL entry
2247 + * when allocating memory for the text representation
2251 + maxlen = 20 * acl_d->count;
2252 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2257 + for (i = 0; i < acl_d->count; i++) {
2258 + struct acl *ap = &acl_d->acl[i];
2267 + switch (ap->a_type) {
2269 + * for debugging purposes it's probably more
2270 + * useful to dump unknown tag types rather
2271 + * than just returning an error
2274 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2277 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2282 + case SMB_ACL_USER:
2283 + id = uidtoname(ap->a_id);
2284 + case SMB_ACL_USER_OBJ:
2288 + case SMB_ACL_GROUP:
2289 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2290 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2296 + case SMB_ACL_GROUP_OBJ:
2300 + case SMB_ACL_OTHER:
2304 + case SMB_ACL_MASK:
2310 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2311 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2312 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2315 + /* <tag> : <qualifier> : rwx \n \0 */
2316 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2319 + * If this entry would overflow the buffer
2320 + * allocate enough additional memory for this
2321 + * entry and an estimate of another 20 bytes
2322 + * for each entry still to be processed
2324 + if ((len + nbytes) > maxlen) {
2325 + char *oldtext = text;
2327 + maxlen += nbytes + 20 * (acl_d->count - i);
2329 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2330 + SAFE_FREE(oldtext);
2336 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2337 + len += nbytes - 1;
2346 +SMB_ACL_T sys_acl_init(int count)
2356 + * note that since the definition of the structure pointed
2357 + * to by the SMB_ACL_T includes the first element of the
2358 + * acl[] array, this actually allocates an ACL with room
2359 + * for (count+1) entries
2361 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2366 + a->size = count + 1;
2374 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2377 + SMB_ACL_ENTRY_T entry_d;
2379 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2384 + if (acl_d->count >= acl_d->size) {
2389 + entry_d = &acl_d->acl[acl_d->count++];
2390 + entry_d->a_type = 0;
2391 + entry_d->a_id = -1;
2392 + entry_d->a_perm = 0;
2393 + *entry_p = entry_d;
2398 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2400 + switch (tag_type) {
2401 + case SMB_ACL_USER:
2402 + case SMB_ACL_USER_OBJ:
2403 + case SMB_ACL_GROUP:
2404 + case SMB_ACL_GROUP_OBJ:
2405 + case SMB_ACL_OTHER:
2406 + case SMB_ACL_MASK:
2407 + entry_d->a_type = tag_type;
2417 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2419 + if (entry_d->a_type != SMB_ACL_GROUP
2420 + && entry_d->a_type != SMB_ACL_USER) {
2425 + entry_d->a_id = *((id_t *)qual_p);
2430 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2432 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2436 + entry_d->a_perm = *permset_d;
2442 + * sort the ACL and check it for validity
2444 + * if it's a minimal ACL with only 4 entries then we
2445 + * need to recalculate the mask permissions to make
2446 + * sure that they are the same as the GROUP_OBJ
2447 + * permissions as required by the UnixWare acl() system call.
2449 + * (note: since POSIX allows minimal ACLs which only contain
2450 + * 3 entries - ie there is no mask entry - we should, in theory,
2451 + * check for this and add a mask entry if necessary - however
2452 + * we "know" that the caller of this interface always specifies
2453 + * a mask so, in practice "this never happens" (tm) - if it *does*
2454 + * happen aclsort() will fail and return an error and someone will
2455 + * have to fix it ...)
2458 +static int acl_sort(SMB_ACL_T acl_d)
2460 + int fixmask = (acl_d->count <= 4);
2462 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2469 +int sys_acl_valid(SMB_ACL_T acl_d)
2471 + return acl_sort(acl_d);
2474 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2477 + struct acl *acl_p;
2479 + struct acl *acl_buf = NULL;
2482 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2487 + if (acl_sort(acl_d) != 0) {
2491 + acl_p = &acl_d->acl[0];
2492 + acl_count = acl_d->count;
2495 + * if it's a directory there is extra work to do
2496 + * since the acl() system call will replace both
2497 + * the access ACLs and the default ACLs (if any)
2499 + if (stat(name, &s) != 0) {
2502 + if (S_ISDIR(s.st_mode)) {
2503 + SMB_ACL_T acc_acl;
2504 + SMB_ACL_T def_acl;
2505 + SMB_ACL_T tmp_acl;
2508 + if (type == SMB_ACL_TYPE_ACCESS) {
2510 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2514 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2517 + if (tmp_acl == NULL) {
2522 + * allocate a temporary buffer for the complete ACL
2524 + acl_count = acc_acl->count + def_acl->count;
2525 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2527 + if (acl_buf == NULL) {
2528 + sys_acl_free_acl(tmp_acl);
2534 + * copy the access control and default entries into the buffer
2536 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2537 + acc_acl->count * sizeof(acl_buf[0]));
2539 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2540 + def_acl->count * sizeof(acl_buf[0]));
2543 + * set the ACL_DEFAULT flag on the default entries
2545 + for (i = acc_acl->count; i < acl_count; i++) {
2546 + acl_buf[i].a_type |= ACL_DEFAULT;
2549 + sys_acl_free_acl(tmp_acl);
2551 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2556 + ret = acl(name, SETACL, acl_count, acl_p);
2558 + SAFE_FREE(acl_buf);
2563 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2565 + if (acl_sort(acl_d) != 0) {
2569 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2572 +int sys_acl_delete_def_file(const char *path)
2578 + * fetching the access ACL and rewriting it has
2579 + * the effect of deleting the default ACL
2581 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2585 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2587 + sys_acl_free_acl(acl_d);
2592 +int sys_acl_free_text(char *text)
2598 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2604 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2609 +#elif defined(HAVE_HPUX_ACLS)
2613 + * Based on the Solaris/SCO code - with modifications.
2617 + * Note that while this code implements sufficient functionality
2618 + * to support the sys_acl_* interfaces it does not provide all
2619 + * of the semantics of the POSIX ACL interfaces.
2621 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2622 + * from a call to sys_acl_get_entry() should not be assumed to be
2623 + * valid after calling any of the following functions, which may
2624 + * reorder the entries in the ACL.
2627 + * sys_acl_set_file()
2628 + * sys_acl_set_fd()
2631 +/* This checks if the POSIX ACL system call is defined */
2632 +/* which basically corresponds to whether JFS 3.3 or */
2633 +/* higher is installed. If acl() was called when it */
2634 +/* isn't defined, it causes the process to core dump */
2635 +/* so it is important to check this and avoid acl() */
2636 +/* calls if it isn't there. */
2638 +static BOOL hpux_acl_call_presence(void)
2641 + shl_t handle = NULL;
2644 + static BOOL already_checked=0;
2646 + if(already_checked)
2650 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2652 + if(ret_val != 0) {
2653 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2654 + ret_val, errno, strerror(errno)));
2655 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2659 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2661 + already_checked = True;
2665 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2667 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2672 + if (entry_p == NULL) {
2677 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2681 + if (acl_d->next < 0) {
2686 + if (acl_d->next >= acl_d->count) {
2690 + *entry_p = &acl_d->acl[acl_d->next++];
2695 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2697 + *type_p = entry_d->a_type;
2702 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2704 + *permset_p = &entry_d->a_perm;
2709 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2711 + if (entry_d->a_type != SMB_ACL_USER
2712 + && entry_d->a_type != SMB_ACL_GROUP) {
2717 + return &entry_d->a_id;
2721 + * There is no way of knowing what size the ACL returned by
2722 + * ACL_GET will be unless you first call ACL_CNT which means
2723 + * making an additional system call.
2725 + * In the hope of avoiding the cost of the additional system
2726 + * call in most cases, we initially allocate enough space for
2727 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2728 + * be too small then we use ACL_CNT to find out the actual
2729 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2732 +#define INITIAL_ACL_SIZE 16
2734 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2737 + int count; /* # of ACL entries allocated */
2738 + int naccess; /* # of access ACL entries */
2739 + int ndefault; /* # of default ACL entries */
2741 + if(hpux_acl_call_presence() == False) {
2742 + /* Looks like we don't have the acl() system call on HPUX.
2743 + * May be the system doesn't have the latest version of JFS.
2748 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2753 + count = INITIAL_ACL_SIZE;
2754 + if ((acl_d = sys_acl_init(count)) == NULL) {
2759 + * If there isn't enough space for the ACL entries we use
2760 + * ACL_CNT to determine the actual number of ACL entries
2761 + * reallocate and try again. This is in a loop because it
2762 + * is possible that someone else could modify the ACL and
2763 + * increase the number of entries between the call to
2764 + * ACL_CNT and the call to ACL_GET.
2766 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2768 + sys_acl_free_acl(acl_d);
2770 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2774 + if ((acl_d = sys_acl_init(count)) == NULL) {
2780 + sys_acl_free_acl(acl_d);
2785 + * calculate the number of access and default ACL entries
2787 + * Note: we assume that the acl() system call returned a
2788 + * well formed ACL which is sorted so that all of the
2789 + * access ACL entries preceed any default ACL entries
2791 + for (naccess = 0; naccess < count; naccess++) {
2792 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2795 + ndefault = count - naccess;
2798 + * if the caller wants the default ACL we have to copy
2799 + * the entries down to the start of the acl[] buffer
2800 + * and mask out the ACL_DEFAULT flag from the type field
2802 + if (type == SMB_ACL_TYPE_DEFAULT) {
2805 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2806 + acl_d->acl[i] = acl_d->acl[j];
2807 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2810 + acl_d->count = ndefault;
2812 + acl_d->count = naccess;
2818 +SMB_ACL_T sys_acl_get_fd(int fd)
2821 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2824 + files_struct *fsp = file_find_fd(fd);
2826 + if (fsp == NULL) {
2832 + * We know we're in the same conn context. So we
2833 + * can use the relative path.
2836 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2839 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2846 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2848 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2849 + && perm != SMB_ACL_EXECUTE) {
2854 + if (permset_d == NULL) {
2859 + *permset_d |= perm;
2864 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2866 + return *permset_d & perm;
2869 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2876 + * use an initial estimate of 20 bytes per ACL entry
2877 + * when allocating memory for the text representation
2881 + maxlen = 20 * acl_d->count;
2882 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2887 + for (i = 0; i < acl_d->count; i++) {
2888 + struct acl *ap = &acl_d->acl[i];
2897 + switch (ap->a_type) {
2899 + * for debugging purposes it's probably more
2900 + * useful to dump unknown tag types rather
2901 + * than just returning an error
2904 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2907 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2912 + case SMB_ACL_USER:
2913 + id = uidtoname(ap->a_id);
2914 + case SMB_ACL_USER_OBJ:
2918 + case SMB_ACL_GROUP:
2919 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2920 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2926 + case SMB_ACL_GROUP_OBJ:
2930 + case SMB_ACL_OTHER:
2934 + case SMB_ACL_MASK:
2940 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2941 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2942 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2945 + /* <tag> : <qualifier> : rwx \n \0 */
2946 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2949 + * If this entry would overflow the buffer
2950 + * allocate enough additional memory for this
2951 + * entry and an estimate of another 20 bytes
2952 + * for each entry still to be processed
2954 + if ((len + nbytes) > maxlen) {
2955 + char *oldtext = text;
2957 + maxlen += nbytes + 20 * (acl_d->count - i);
2959 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2966 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2967 + len += nbytes - 1;
2976 +SMB_ACL_T sys_acl_init(int count)
2986 + * note that since the definition of the structure pointed
2987 + * to by the SMB_ACL_T includes the first element of the
2988 + * acl[] array, this actually allocates an ACL with room
2989 + * for (count+1) entries
2991 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2996 + a->size = count + 1;
3004 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3007 + SMB_ACL_ENTRY_T entry_d;
3009 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3014 + if (acl_d->count >= acl_d->size) {
3019 + entry_d = &acl_d->acl[acl_d->count++];
3020 + entry_d->a_type = 0;
3021 + entry_d->a_id = -1;
3022 + entry_d->a_perm = 0;
3023 + *entry_p = entry_d;
3028 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3030 + switch (tag_type) {
3031 + case SMB_ACL_USER:
3032 + case SMB_ACL_USER_OBJ:
3033 + case SMB_ACL_GROUP:
3034 + case SMB_ACL_GROUP_OBJ:
3035 + case SMB_ACL_OTHER:
3036 + case SMB_ACL_MASK:
3037 + entry_d->a_type = tag_type;
3047 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3049 + if (entry_d->a_type != SMB_ACL_GROUP
3050 + && entry_d->a_type != SMB_ACL_USER) {
3055 + entry_d->a_id = *((id_t *)qual_p);
3060 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3062 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3066 + entry_d->a_perm = *permset_d;
3071 +/* Structure to capture the count for each type of ACE. */
3073 +struct hpux_acl_types {
3077 + int n_def_user_obj;
3082 + int n_def_group_obj;
3086 + int n_def_other_obj;
3089 + int n_def_class_obj;
3091 + int n_illegal_obj;
3095 + * Counts the different number of objects in a given array of ACL
3099 + * acl_count - Count of ACLs in the array of ACL strucutres.
3100 + * aclp - Array of ACL structures.
3101 + * acl_type_count - Pointer to acl_types structure. Should already be
3105 + * acl_type_count - This structure is filled up with counts of various
3109 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3113 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3115 + for(i=0;i<acl_count;i++) {
3116 + switch(aclp[i].a_type) {
3118 + acl_type_count->n_user++;
3121 + acl_type_count->n_user_obj++;
3123 + case DEF_USER_OBJ:
3124 + acl_type_count->n_def_user_obj++;
3127 + acl_type_count->n_group++;
3130 + acl_type_count->n_group_obj++;
3132 + case DEF_GROUP_OBJ:
3133 + acl_type_count->n_def_group_obj++;
3136 + acl_type_count->n_other_obj++;
3138 + case DEF_OTHER_OBJ:
3139 + acl_type_count->n_def_other_obj++;
3142 + acl_type_count->n_class_obj++;
3144 + case DEF_CLASS_OBJ:
3145 + acl_type_count->n_def_class_obj++;
3148 + acl_type_count->n_def_user++;
3151 + acl_type_count->n_def_group++;
3154 + acl_type_count->n_illegal_obj++;
3160 +/* swap_acl_entries: Swaps two ACL entries.
3162 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3165 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3167 + struct acl temp_acl;
3169 + temp_acl.a_type = aclp0->a_type;
3170 + temp_acl.a_id = aclp0->a_id;
3171 + temp_acl.a_perm = aclp0->a_perm;
3173 + aclp0->a_type = aclp1->a_type;
3174 + aclp0->a_id = aclp1->a_id;
3175 + aclp0->a_perm = aclp1->a_perm;
3177 + aclp1->a_type = temp_acl.a_type;
3178 + aclp1->a_id = temp_acl.a_id;
3179 + aclp1->a_perm = temp_acl.a_perm;
3182 +/* prohibited_duplicate_type
3183 + * Identifies if given ACL type can have duplicate entries or
3186 + * Inputs: acl_type - ACL Type.
3192 + * True - If the ACL type matches any of the prohibited types.
3193 + * False - If the ACL type doesn't match any of the prohibited types.
3196 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3198 + switch(acl_type) {
3209 +/* get_needed_class_perm
3210 + * Returns the permissions of a ACL structure only if the ACL
3211 + * type matches one of the pre-determined types for computing
3212 + * CLASS_OBJ permissions.
3214 + * Inputs: aclp - Pointer to ACL structure.
3217 +static int hpux_get_needed_class_perm(struct acl *aclp)
3219 + switch(aclp->a_type) {
3223 + case DEF_USER_OBJ:
3225 + case DEF_GROUP_OBJ:
3227 + case DEF_CLASS_OBJ:
3228 + case DEF_OTHER_OBJ:
3229 + return aclp->a_perm;
3235 +/* acl_sort for HPUX.
3236 + * Sorts the array of ACL structures as per the description in
3237 + * aclsort man page. Refer to aclsort man page for more details
3241 + * acl_count - Count of ACLs in the array of ACL structures.
3242 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3244 + * aclp - Array of ACL structures.
3248 + * aclp - Sorted array of ACL structures.
3252 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3253 + * debug log in case of failure.
3256 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3258 +#if !defined(HAVE_HPUX_ACLSORT)
3260 + * The aclsort() system call is availabe on the latest HPUX General
3261 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3262 + * function. Because, we don't want to update to a new
3263 + * HPUX GR bundle just for aclsort() call.
3266 + struct hpux_acl_types acl_obj_count;
3267 + int n_class_obj_perm = 0;
3271 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3275 + if(aclp == NULL) {
3276 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3280 + /* Count different types of ACLs in the ACLs array */
3282 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3284 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3285 + * CLASS_OBJ and OTHER_OBJ
3288 + if( (acl_obj_count.n_user_obj != 1) ||
3289 + (acl_obj_count.n_group_obj != 1) ||
3290 + (acl_obj_count.n_class_obj != 1) ||
3291 + (acl_obj_count.n_other_obj != 1)
3293 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3294 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3298 + /* If any of the default objects are present, there should be only
3299 + * one of them each.
3302 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3303 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3304 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3305 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3309 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3312 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3313 + * same ACL type, sort by ACL id.
3315 + * I am using the trival kind of sorting method here because, performance isn't
3316 + * really effected by the ACLs feature. More over there aren't going to be more
3317 + * than 17 entries on HPUX.
3320 + for(i=0; i<acl_count;i++) {
3321 + for (j=i+1; j<acl_count; j++) {
3322 + if( aclp[i].a_type > aclp[j].a_type ) {
3323 + /* ACL entries out of order, swap them */
3325 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3327 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3329 + /* ACL entries of same type, sort by id */
3331 + if(aclp[i].a_id > aclp[j].a_id) {
3332 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3333 + } else if (aclp[i].a_id == aclp[j].a_id) {
3334 + /* We have a duplicate entry. */
3335 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3336 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3337 + aclp[i].a_type, aclp[i].a_id));
3346 + /* set the class obj permissions to the computed one. */
3348 + int n_class_obj_index = -1;
3350 + for(i=0;i<acl_count;i++) {
3351 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3353 + if(aclp[i].a_type == CLASS_OBJ)
3354 + n_class_obj_index = i;
3356 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3361 + return aclsort(acl_count, calclass, aclp);
3366 + * sort the ACL and check it for validity
3368 + * if it's a minimal ACL with only 4 entries then we
3369 + * need to recalculate the mask permissions to make
3370 + * sure that they are the same as the GROUP_OBJ
3371 + * permissions as required by the UnixWare acl() system call.
3373 + * (note: since POSIX allows minimal ACLs which only contain
3374 + * 3 entries - ie there is no mask entry - we should, in theory,
3375 + * check for this and add a mask entry if necessary - however
3376 + * we "know" that the caller of this interface always specifies
3377 + * a mask so, in practice "this never happens" (tm) - if it *does*
3378 + * happen aclsort() will fail and return an error and someone will
3379 + * have to fix it ...)
3382 +static int acl_sort(SMB_ACL_T acl_d)
3384 + int fixmask = (acl_d->count <= 4);
3386 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3393 +int sys_acl_valid(SMB_ACL_T acl_d)
3395 + return acl_sort(acl_d);
3398 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3401 + struct acl *acl_p;
3403 + struct acl *acl_buf = NULL;
3406 + if(hpux_acl_call_presence() == False) {
3407 + /* Looks like we don't have the acl() system call on HPUX.
3408 + * May be the system doesn't have the latest version of JFS.
3414 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3419 + if (acl_sort(acl_d) != 0) {
3423 + acl_p = &acl_d->acl[0];
3424 + acl_count = acl_d->count;
3427 + * if it's a directory there is extra work to do
3428 + * since the acl() system call will replace both
3429 + * the access ACLs and the default ACLs (if any)
3431 + if (stat(name, &s) != 0) {
3434 + if (S_ISDIR(s.st_mode)) {
3435 + SMB_ACL_T acc_acl;
3436 + SMB_ACL_T def_acl;
3437 + SMB_ACL_T tmp_acl;
3440 + if (type == SMB_ACL_TYPE_ACCESS) {
3442 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3446 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3449 + if (tmp_acl == NULL) {
3454 + * allocate a temporary buffer for the complete ACL
3456 + acl_count = acc_acl->count + def_acl->count;
3457 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3459 + if (acl_buf == NULL) {
3460 + sys_acl_free_acl(tmp_acl);
3466 + * copy the access control and default entries into the buffer
3468 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3469 + acc_acl->count * sizeof(acl_buf[0]));
3471 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3472 + def_acl->count * sizeof(acl_buf[0]));
3475 + * set the ACL_DEFAULT flag on the default entries
3477 + for (i = acc_acl->count; i < acl_count; i++) {
3478 + acl_buf[i].a_type |= ACL_DEFAULT;
3481 + sys_acl_free_acl(tmp_acl);
3483 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3488 + ret = acl(name, ACL_SET, acl_count, acl_p);
3497 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3500 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3503 + files_struct *fsp = file_find_fd(fd);
3505 + if (fsp == NULL) {
3510 + if (acl_sort(acl_d) != 0) {
3515 + * We know we're in the same conn context. So we
3516 + * can use the relative path.
3519 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3522 +int sys_acl_delete_def_file(const char *path)
3528 + * fetching the access ACL and rewriting it has
3529 + * the effect of deleting the default ACL
3531 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3535 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3537 + sys_acl_free_acl(acl_d);
3542 +int sys_acl_free_text(char *text)
3548 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3554 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3559 +#elif defined(HAVE_IRIX_ACLS)
3561 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3563 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3568 + if (entry_p == NULL) {
3573 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3577 + if (acl_d->next < 0) {
3582 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3586 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3591 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3593 + *type_p = entry_d->ae_tag;
3598 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3600 + *permset_p = entry_d;
3605 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3607 + if (entry_d->ae_tag != SMB_ACL_USER
3608 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3613 + return &entry_d->ae_id;
3616 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3620 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3624 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3629 + a->freeaclp = True;
3633 +SMB_ACL_T sys_acl_get_fd(int fd)
3637 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3641 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3646 + a->freeaclp = True;
3650 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3652 + permset_d->ae_perm = 0;
3657 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3659 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3660 + && perm != SMB_ACL_EXECUTE) {
3665 + if (permset_d == NULL) {
3670 + permset_d->ae_perm |= perm;
3675 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3677 + return permset_d->ae_perm & perm;
3680 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3682 + return acl_to_text(acl_d->aclp, len_p);
3685 +SMB_ACL_T sys_acl_init(int count)
3694 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3700 + a->freeaclp = False;
3701 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3702 + a->aclp->acl_cnt = 0;
3708 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3711 + SMB_ACL_ENTRY_T entry_d;
3713 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3718 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3723 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3724 + entry_d->ae_tag = 0;
3725 + entry_d->ae_id = 0;
3726 + entry_d->ae_perm = 0;
3727 + *entry_p = entry_d;
3732 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3734 + switch (tag_type) {
3735 + case SMB_ACL_USER:
3736 + case SMB_ACL_USER_OBJ:
3737 + case SMB_ACL_GROUP:
3738 + case SMB_ACL_GROUP_OBJ:
3739 + case SMB_ACL_OTHER:
3740 + case SMB_ACL_MASK:
3741 + entry_d->ae_tag = tag_type;
3751 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3753 + if (entry_d->ae_tag != SMB_ACL_GROUP
3754 + && entry_d->ae_tag != SMB_ACL_USER) {
3759 + entry_d->ae_id = *((id_t *)qual_p);
3764 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3766 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3770 + entry_d->ae_perm = permset_d->ae_perm;
3775 +int sys_acl_valid(SMB_ACL_T acl_d)
3777 + return acl_valid(acl_d->aclp);
3780 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3782 + return acl_set_file(name, type, acl_d->aclp);
3785 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3787 + return acl_set_fd(fd, acl_d->aclp);
3790 +int sys_acl_delete_def_file(const char *name)
3792 + return acl_delete_def_file(name);
3795 +int sys_acl_free_text(char *text)
3797 + return acl_free(text);
3800 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3802 + if (acl_d->freeaclp) {
3803 + acl_free(acl_d->aclp);
3809 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3814 +#elif defined(HAVE_AIX_ACLS)
3816 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3818 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3820 + struct acl_entry_link *link;
3821 + struct new_acl_entry *entry;
3824 + DEBUG(10,("This is the count: %d\n",theacl->count));
3826 + /* Check if count was previously set to -1. *
3827 + * If it was, that means we reached the end *
3828 + * of the acl last time. */
3829 + if(theacl->count == -1)
3833 + /* To get to the next acl, traverse linked list until index *
3834 + * of acl matches the count we are keeping. This count is *
3835 + * incremented each time we return an acl entry. */
3837 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3838 + link = link->nextp;
3840 + entry = *entry_p = link->entryp;
3842 + DEBUG(10,("*entry_p is %d\n",entry_p));
3843 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3845 + /* Increment count */
3847 + if(link->nextp == NULL)
3848 + theacl->count = -1;
3853 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3855 + /* Initialize tag type */
3858 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3860 + /* Depending on what type of entry we have, *
3861 + * return tag type. */
3862 + switch(entry_d->ace_id->id_type) {
3864 + *tag_type_p = SMB_ACL_USER;
3867 + *tag_type_p = SMB_ACL_GROUP;
3870 + case SMB_ACL_USER_OBJ:
3871 + case SMB_ACL_GROUP_OBJ:
3872 + case SMB_ACL_OTHER:
3873 + *tag_type_p = entry_d->ace_id->id_type;
3883 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3885 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3886 + *permset_p = &entry_d->ace_access;
3887 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3888 + if(!(**permset_p & S_IXUSR) &&
3889 + !(**permset_p & S_IWUSR) &&
3890 + !(**permset_p & S_IRUSR) &&
3891 + (**permset_p != 0))
3894 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3898 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3900 + return(entry_d->ace_id->id_data);
3903 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3905 + struct acl *file_acl = (struct acl *)NULL;
3906 + struct acl_entry *acl_entry;
3907 + struct new_acl_entry *new_acl_entry;
3908 + struct ace_id *idp;
3909 + struct acl_entry_link *acl_entry_link;
3910 + struct acl_entry_link *acl_entry_link_head;
3915 + /* AIX has no DEFAULT */
3916 + if ( type == SMB_ACL_TYPE_DEFAULT )
3919 + /* Get the acl using statacl */
3921 + DEBUG(10,("Entering sys_acl_get_file\n"));
3922 + DEBUG(10,("path_p is %s\n",path_p));
3924 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3926 + if(file_acl == NULL) {
3928 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3932 + memset(file_acl,0,BUFSIZ);
3934 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3936 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3937 + SAFE_FREE(file_acl);
3941 + DEBUG(10,("Got facl and returned it\n"));
3943 + /* Point to the first acl entry in the acl */
3944 + acl_entry = file_acl->acl_ext;
3946 + /* Begin setting up the head of the linked list *
3947 + * that will be used for the storing the acl *
3948 + * in a way that is useful for the posix_acls.c *
3951 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3952 + if(acl_entry_link_head == NULL)
3955 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3956 + if(acl_entry_link->entryp == NULL) {
3957 + SAFE_FREE(file_acl);
3959 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3963 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3964 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3966 + /* Check if the extended acl bit is on. *
3967 + * If it isn't, do not show the *
3968 + * contents of the acl since AIX intends *
3969 + * the extended info to remain unused */
3971 + if(file_acl->acl_mode & S_IXACL){
3972 + /* while we are not pointing to the very end */
3973 + while(acl_entry < acl_last(file_acl)) {
3974 + /* before we malloc anything, make sure this is */
3975 + /* a valid acl entry and one that we want to map */
3976 + idp = id_nxt(acl_entry->ace_id);
3977 + if((acl_entry->ace_type == ACC_SPECIFY ||
3978 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3979 + acl_entry = acl_nxt(acl_entry);
3983 + idp = acl_entry->ace_id;
3985 + /* Check if this is the first entry in the linked list. *
3986 + * The first entry needs to keep prevp pointing to NULL *
3987 + * and already has entryp allocated. */
3989 + if(acl_entry_link_head->count != 0) {
3990 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3992 + if(acl_entry_link->nextp == NULL) {
3993 + SAFE_FREE(file_acl);
3995 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3999 + acl_entry_link->nextp->prevp = acl_entry_link;
4000 + acl_entry_link = acl_entry_link->nextp;
4001 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4002 + if(acl_entry_link->entryp == NULL) {
4003 + SAFE_FREE(file_acl);
4005 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4008 + acl_entry_link->nextp = NULL;
4011 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4013 + /* Don't really need this since all types are going *
4014 + * to be specified but, it's better than leaving it 0 */
4016 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4018 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4020 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4022 + /* The access in the acl entries must be left shifted by *
4023 + * three bites, because they will ultimately be compared *
4024 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4026 + switch(acl_entry->ace_type){
4029 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4030 + acl_entry_link->entryp->ace_access <<= 6;
4031 + acl_entry_link_head->count++;
4034 + /* Since there is no way to return a DENY acl entry *
4035 + * change to PERMIT and then shift. */
4036 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4037 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4038 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4039 + acl_entry_link->entryp->ace_access <<= 6;
4040 + acl_entry_link_head->count++;
4046 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4047 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4049 + acl_entry = acl_nxt(acl_entry);
4051 + } /* end of if enabled */
4053 + /* Since owner, group, other acl entries are not *
4054 + * part of the acl entries in an acl, they must *
4055 + * be dummied up to become part of the list. */
4057 + for( i = 1; i < 4; i++) {
4058 + DEBUG(10,("i is %d\n",i));
4059 + if(acl_entry_link_head->count != 0) {
4060 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4061 + if(acl_entry_link->nextp == NULL) {
4062 + SAFE_FREE(file_acl);
4064 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4068 + acl_entry_link->nextp->prevp = acl_entry_link;
4069 + acl_entry_link = acl_entry_link->nextp;
4070 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4071 + if(acl_entry_link->entryp == NULL) {
4072 + SAFE_FREE(file_acl);
4074 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4079 + acl_entry_link->nextp = NULL;
4081 + new_acl_entry = acl_entry_link->entryp;
4082 + idp = new_acl_entry->ace_id;
4084 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4085 + new_acl_entry->ace_type = ACC_PERMIT;
4086 + idp->id_len = sizeof(struct ace_id);
4087 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4088 + memset(idp->id_data,0,sizeof(uid_t));
4092 + new_acl_entry->ace_access = file_acl->g_access << 6;
4093 + idp->id_type = SMB_ACL_GROUP_OBJ;
4097 + new_acl_entry->ace_access = file_acl->o_access << 6;
4098 + idp->id_type = SMB_ACL_OTHER;
4102 + new_acl_entry->ace_access = file_acl->u_access << 6;
4103 + idp->id_type = SMB_ACL_USER_OBJ;
4111 + acl_entry_link_head->count++;
4112 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4115 + acl_entry_link_head->count = 0;
4116 + SAFE_FREE(file_acl);
4118 + return(acl_entry_link_head);
4121 +SMB_ACL_T sys_acl_get_fd(int fd)
4123 + struct acl *file_acl = (struct acl *)NULL;
4124 + struct acl_entry *acl_entry;
4125 + struct new_acl_entry *new_acl_entry;
4126 + struct ace_id *idp;
4127 + struct acl_entry_link *acl_entry_link;
4128 + struct acl_entry_link *acl_entry_link_head;
4133 + /* Get the acl using fstatacl */
4135 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4136 + DEBUG(10,("fd is %d\n",fd));
4137 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4139 + if(file_acl == NULL) {
4141 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4145 + memset(file_acl,0,BUFSIZ);
4147 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4149 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4150 + SAFE_FREE(file_acl);
4154 + DEBUG(10,("Got facl and returned it\n"));
4156 + /* Point to the first acl entry in the acl */
4158 + acl_entry = file_acl->acl_ext;
4159 + /* Begin setting up the head of the linked list *
4160 + * that will be used for the storing the acl *
4161 + * in a way that is useful for the posix_acls.c *
4164 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4165 + if(acl_entry_link_head == NULL){
4166 + SAFE_FREE(file_acl);
4170 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4172 + if(acl_entry_link->entryp == NULL) {
4174 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4175 + SAFE_FREE(file_acl);
4179 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4180 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4182 + /* Check if the extended acl bit is on. *
4183 + * If it isn't, do not show the *
4184 + * contents of the acl since AIX intends *
4185 + * the extended info to remain unused */
4187 + if(file_acl->acl_mode & S_IXACL){
4188 + /* while we are not pointing to the very end */
4189 + while(acl_entry < acl_last(file_acl)) {
4190 + /* before we malloc anything, make sure this is */
4191 + /* a valid acl entry and one that we want to map */
4193 + idp = id_nxt(acl_entry->ace_id);
4194 + if((acl_entry->ace_type == ACC_SPECIFY ||
4195 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4196 + acl_entry = acl_nxt(acl_entry);
4200 + idp = acl_entry->ace_id;
4202 + /* Check if this is the first entry in the linked list. *
4203 + * The first entry needs to keep prevp pointing to NULL *
4204 + * and already has entryp allocated. */
4206 + if(acl_entry_link_head->count != 0) {
4207 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4208 + if(acl_entry_link->nextp == NULL) {
4210 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4211 + SAFE_FREE(file_acl);
4214 + acl_entry_link->nextp->prevp = acl_entry_link;
4215 + acl_entry_link = acl_entry_link->nextp;
4216 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4217 + if(acl_entry_link->entryp == NULL) {
4219 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4220 + SAFE_FREE(file_acl);
4224 + acl_entry_link->nextp = NULL;
4227 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4229 + /* Don't really need this since all types are going *
4230 + * to be specified but, it's better than leaving it 0 */
4232 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4233 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4235 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4237 + /* The access in the acl entries must be left shifted by *
4238 + * three bites, because they will ultimately be compared *
4239 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4241 + switch(acl_entry->ace_type){
4244 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4245 + acl_entry_link->entryp->ace_access <<= 6;
4246 + acl_entry_link_head->count++;
4249 + /* Since there is no way to return a DENY acl entry *
4250 + * change to PERMIT and then shift. */
4251 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4252 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4253 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4254 + acl_entry_link->entryp->ace_access <<= 6;
4255 + acl_entry_link_head->count++;
4261 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4262 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4264 + acl_entry = acl_nxt(acl_entry);
4266 + } /* end of if enabled */
4268 + /* Since owner, group, other acl entries are not *
4269 + * part of the acl entries in an acl, they must *
4270 + * be dummied up to become part of the list. */
4272 + for( i = 1; i < 4; i++) {
4273 + DEBUG(10,("i is %d\n",i));
4274 + if(acl_entry_link_head->count != 0){
4275 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4276 + if(acl_entry_link->nextp == NULL) {
4278 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4279 + SAFE_FREE(file_acl);
4283 + acl_entry_link->nextp->prevp = acl_entry_link;
4284 + acl_entry_link = acl_entry_link->nextp;
4285 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4287 + if(acl_entry_link->entryp == NULL) {
4288 + SAFE_FREE(file_acl);
4290 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4295 + acl_entry_link->nextp = NULL;
4297 + new_acl_entry = acl_entry_link->entryp;
4298 + idp = new_acl_entry->ace_id;
4300 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4301 + new_acl_entry->ace_type = ACC_PERMIT;
4302 + idp->id_len = sizeof(struct ace_id);
4303 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4304 + memset(idp->id_data,0,sizeof(uid_t));
4308 + new_acl_entry->ace_access = file_acl->g_access << 6;
4309 + idp->id_type = SMB_ACL_GROUP_OBJ;
4313 + new_acl_entry->ace_access = file_acl->o_access << 6;
4314 + idp->id_type = SMB_ACL_OTHER;
4318 + new_acl_entry->ace_access = file_acl->u_access << 6;
4319 + idp->id_type = SMB_ACL_USER_OBJ;
4326 + acl_entry_link_head->count++;
4327 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4330 + acl_entry_link_head->count = 0;
4331 + SAFE_FREE(file_acl);
4333 + return(acl_entry_link_head);
4336 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4338 + *permset = *permset & ~0777;
4342 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4345 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4349 + DEBUG(10,("This is the permset now: %d\n",*permset));
4353 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4358 +SMB_ACL_T sys_acl_init( int count)
4360 + struct acl_entry_link *theacl = NULL;
4362 + DEBUG(10,("Entering sys_acl_init\n"));
4364 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4365 + if(theacl == NULL) {
4367 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4371 + theacl->count = 0;
4372 + theacl->nextp = NULL;
4373 + theacl->prevp = NULL;
4374 + theacl->entryp = NULL;
4375 + DEBUG(10,("Exiting sys_acl_init\n"));
4379 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4381 + struct acl_entry_link *theacl;
4382 + struct acl_entry_link *acl_entryp;
4383 + struct acl_entry_link *temp_entry;
4386 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4388 + theacl = acl_entryp = *pacl;
4390 + /* Get to the end of the acl before adding entry */
4392 + for(counting=0; counting < theacl->count; counting++){
4393 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4394 + temp_entry = acl_entryp;
4395 + acl_entryp = acl_entryp->nextp;
4398 + if(theacl->count != 0){
4399 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4400 + if(acl_entryp == NULL) {
4402 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4406 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4407 + acl_entryp->prevp = temp_entry;
4408 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4411 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4412 + if(*pentry == NULL) {
4414 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4418 + memset(*pentry,0,sizeof(struct new_acl_entry));
4419 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4420 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4421 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4422 + acl_entryp->nextp = NULL;
4424 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4428 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4430 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4431 + entry->ace_id->id_type = tagtype;
4432 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4433 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4436 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4438 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4439 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4440 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4444 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4446 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4447 + if(!(*permset & S_IXUSR) &&
4448 + !(*permset & S_IWUSR) &&
4449 + !(*permset & S_IRUSR) &&
4453 + entry->ace_access = *permset;
4454 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4455 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4459 +int sys_acl_valid( SMB_ACL_T theacl )
4462 + int group_obj = 0;
4463 + int other_obj = 0;
4464 + struct acl_entry_link *acl_entry;
4466 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4467 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4468 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4469 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4472 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4474 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4480 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4482 + struct acl_entry_link *acl_entry_link = NULL;
4483 + struct acl *file_acl = NULL;
4484 + struct acl *file_acl_temp = NULL;
4485 + struct acl_entry *acl_entry = NULL;
4486 + struct ace_id *ace_id = NULL;
4493 + DEBUG(10,("Entering sys_acl_set_file\n"));
4494 + DEBUG(10,("File name is %s\n",name));
4496 + /* AIX has no default ACL */
4497 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4500 + acl_length = BUFSIZ;
4501 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4503 + if(file_acl == NULL) {
4505 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4509 + memset(file_acl,0,BUFSIZ);
4511 + file_acl->acl_len = ACL_SIZ;
4512 + file_acl->acl_mode = S_IXACL;
4514 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4515 + acl_entry_link->entryp->ace_access >>= 6;
4516 + id_type = acl_entry_link->entryp->ace_id->id_type;
4519 + case SMB_ACL_USER_OBJ:
4520 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4522 + case SMB_ACL_GROUP_OBJ:
4523 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4525 + case SMB_ACL_OTHER:
4526 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4528 + case SMB_ACL_MASK:
4532 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4533 + acl_length += sizeof(struct acl_entry);
4534 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4535 + if(file_acl_temp == NULL) {
4536 + SAFE_FREE(file_acl);
4538 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4542 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4543 + SAFE_FREE(file_acl);
4544 + file_acl = file_acl_temp;
4547 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4548 + file_acl->acl_len += sizeof(struct acl_entry);
4549 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4550 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4552 + /* In order to use this, we'll need to wait until we can get denies */
4553 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4554 + acl_entry->ace_type = ACC_SPECIFY; */
4556 + acl_entry->ace_type = ACC_SPECIFY;
4558 + ace_id = acl_entry->ace_id;
4560 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4561 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4562 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4563 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4564 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4567 + rc = chacl(name,file_acl,file_acl->acl_len);
4568 + DEBUG(10,("errno is %d\n",errno));
4569 + DEBUG(10,("return code is %d\n",rc));
4570 + SAFE_FREE(file_acl);
4571 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4575 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4577 + struct acl_entry_link *acl_entry_link = NULL;
4578 + struct acl *file_acl = NULL;
4579 + struct acl *file_acl_temp = NULL;
4580 + struct acl_entry *acl_entry = NULL;
4581 + struct ace_id *ace_id = NULL;
4587 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4588 + acl_length = BUFSIZ;
4589 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4591 + if(file_acl == NULL) {
4593 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4597 + memset(file_acl,0,BUFSIZ);
4599 + file_acl->acl_len = ACL_SIZ;
4600 + file_acl->acl_mode = S_IXACL;
4602 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4603 + acl_entry_link->entryp->ace_access >>= 6;
4604 + id_type = acl_entry_link->entryp->ace_id->id_type;
4605 + DEBUG(10,("The id_type is %d\n",id_type));
4608 + case SMB_ACL_USER_OBJ:
4609 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4611 + case SMB_ACL_GROUP_OBJ:
4612 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4614 + case SMB_ACL_OTHER:
4615 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4617 + case SMB_ACL_MASK:
4621 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4622 + acl_length += sizeof(struct acl_entry);
4623 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4624 + if(file_acl_temp == NULL) {
4625 + SAFE_FREE(file_acl);
4627 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4631 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4632 + SAFE_FREE(file_acl);
4633 + file_acl = file_acl_temp;
4636 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4637 + file_acl->acl_len += sizeof(struct acl_entry);
4638 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4639 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4641 + /* In order to use this, we'll need to wait until we can get denies */
4642 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4643 + acl_entry->ace_type = ACC_SPECIFY; */
4645 + acl_entry->ace_type = ACC_SPECIFY;
4647 + ace_id = acl_entry->ace_id;
4649 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4650 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4651 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4652 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4653 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4656 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4657 + DEBUG(10,("errno is %d\n",errno));
4658 + DEBUG(10,("return code is %d\n",rc));
4659 + SAFE_FREE(file_acl);
4660 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4664 +int sys_acl_delete_def_file(const char *name)
4666 + /* AIX has no default ACL */
4670 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4672 + return(*permset & perm);
4675 +int sys_acl_free_text(char *text)
4680 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4682 + struct acl_entry_link *acl_entry_link;
4684 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4685 + SAFE_FREE(acl_entry_link->prevp->entryp);
4686 + SAFE_FREE(acl_entry_link->prevp);
4689 + SAFE_FREE(acl_entry_link->prevp->entryp);
4690 + SAFE_FREE(acl_entry_link->prevp);
4691 + SAFE_FREE(acl_entry_link->entryp);
4692 + SAFE_FREE(acl_entry_link);
4697 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4702 +#else /* No ACLs. */
4704 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4710 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4716 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4722 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4728 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4731 + return (SMB_ACL_T)NULL;
4734 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4737 + return (SMB_ACL_T)NULL;
4740 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4746 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4752 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4755 + return (permset & perm) ? 1 : 0;
4758 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4764 +int sys_acl_free_text(UNUSED(char *text))
4770 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4776 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4782 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4788 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4794 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4800 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4806 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4812 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4818 +int sys_acl_delete_def_file(UNUSED(const char *name))
4824 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4830 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4836 +#endif /* No ACLs. */
4838 +/************************************************************************
4839 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4841 +************************************************************************/
4843 +int no_acl_syscall_error(int err)
4845 +#if defined(ENOSYS)
4846 + if (err == ENOSYS) {
4850 +#if defined(ENOTSUP)
4851 + if (err == ENOTSUP) {
4857 --- old/lib/sysacls.h
4858 +++ new/lib/sysacls.h
4860 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4861 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4862 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4863 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4864 +#define slprintf snprintf
4866 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4867 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4868 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4869 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4870 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4871 +SMB_ACL_T sys_acl_get_fd(int fd);
4872 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4873 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4874 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4875 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4876 +SMB_ACL_T sys_acl_init(int count);
4877 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4878 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4879 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4880 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4881 +int sys_acl_valid(SMB_ACL_T theacl);
4882 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4883 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4884 +int sys_acl_delete_def_file(const char *name);
4885 +int sys_acl_free_text(char *text);
4886 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4887 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4890 @@ -58,7 +58,7 @@ BEGIN {
4894 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4895 +!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4901 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
4903 int preserve_links = 0;
4904 int preserve_hard_links = 0;
4905 +int preserve_acls = 0;
4906 int preserve_perms = 0;
4907 int preserve_executability = 0;
4908 int preserve_devices = 0;
4909 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4910 char const *got_socketpair = "no ";
4911 char const *have_inplace = "no ";
4912 char const *hardlinks = "no ";
4913 + char const *acls = "no ";
4914 char const *links = "no ";
4915 char const *ipv6 = "no ";
4916 STRUCT_STAT *dumstat;
4917 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4921 +#ifdef SUPPORT_ACLS
4925 #ifdef SUPPORT_LINKS
4928 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4929 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4930 rprintf(f, "<http://rsync.samba.org/>\n");
4931 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4932 - "%shard links, %ssymlinks, batchfiles,\n",
4933 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4934 (int) (sizeof (OFF_T) * 8),
4935 - got_socketpair, hardlinks, links);
4936 + got_socketpair, hardlinks, acls, links);
4938 /* Note that this field may not have type ino_t. It depends
4939 * on the complicated interaction between largefile feature
4940 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4941 rprintf(F," -H, --hard-links preserve hard links\n");
4942 rprintf(F," -p, --perms preserve permissions\n");
4943 rprintf(F," -E, --executability preserve the file's executability\n");
4944 +#ifdef SUPPORT_ACLS
4945 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4947 rprintf(F," --chmod=CHMOD change destination permissions\n");
4948 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4949 rprintf(F," -g, --group preserve group\n");
4950 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4951 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4952 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4953 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4954 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4955 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4956 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4957 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4958 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4959 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4960 @@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
4965 +#ifdef SUPPORT_ACLS
4967 + preserve_perms = 1;
4970 + /* FIXME: this should probably be ignored with a
4971 + * warning and then countermeasures taken to
4972 + * restrict group and other access in the presence
4973 + * of any more restrictive ACLs, but this is safe
4975 + snprintf(err_buf,sizeof(err_buf),
4976 + "ACLs are not supported on this %s\n",
4977 + am_server ? "server" : "client");
4983 /* A large opt value means that set_refuse_options()
4984 * turned this option off. */
4985 @@ -1510,6 +1540,10 @@ void server_options(char **args,int *arg
4987 if (preserve_hard_links)
4989 +#ifdef SUPPORT_ACLS
4990 + if (preserve_acls)
4991 + argstr[x++] = 'A';
4998 @@ -48,6 +48,7 @@ extern int keep_partial;
4999 extern int checksum_seed;
5001 extern int delay_updates;
5002 +extern mode_t orig_umask;
5003 extern struct stats stats;
5004 extern char *log_format;
5005 extern char *tmpdir;
5006 @@ -346,6 +347,10 @@ int recv_files(int f_in, struct file_lis
5007 int itemizing = am_daemon ? daemon_log_format_has_i
5008 : !am_server && log_format_has_i;
5009 int max_phase = protocol_version >= 29 ? 2 : 1;
5010 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5011 +#ifdef SUPPORT_ACLS
5012 + char *parent_dirname = "";
5017 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5018 * mode based on the local permissions and some heuristics. */
5019 if (!preserve_perms) {
5020 int exists = fd1 != -1;
5021 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5022 +#ifdef SUPPORT_ACLS
5023 + char *dn = file->dirname ? file->dirname : ".";
5024 + if (parent_dirname != dn
5025 + && strcmp(parent_dirname, dn) != 0) {
5026 + dflt_perms = default_perms_for_dir(dn);
5027 + parent_dirname = dn;
5030 + file->mode = dest_mode(file->mode, st.st_mode,
5031 + dflt_perms, exists);
5034 /* We now check to see if we are writing file "inplace" */
5040 extern int daemon_log_format_has_i;
5041 +extern int preserve_acls;
5042 extern int preserve_perms;
5043 extern int preserve_executability;
5044 extern int preserve_times;
5045 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5047 /* This is only called when we aren't preserving permissions. Figure out what
5048 * the permissions should be and return them merged back into the mode. */
5049 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5050 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5053 /* If the file already exists, we'll return the local permissions,
5054 * possibly tweaked by the --executability option. */
5055 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
5056 cur_mode |= (cur_mode & 0444) >> 2;
5059 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5060 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5061 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5062 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5063 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5064 @@ -203,6 +205,17 @@ int set_file_attrs(char *fname, struct f
5068 +#ifdef SUPPORT_ACLS
5069 + /* It's OK to call set_acl() now, even for a dir, as the generator
5070 + * will enable owner-writability using chmod, if necessary.
5072 + * If set_acl changes permission bits in the process of setting
5073 + * an access ACL, it changes st->st_mode so we know whether we
5074 + * need to chmod. */
5075 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5080 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5081 int ret = do_chmod(fname, file->mode);
5084 @@ -660,6 +660,20 @@ struct chmod_mode_struct;
5086 #define UNUSED(x) x __attribute__((__unused__))
5088 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5089 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5090 +#define SUPPORT_ACLS 1
5093 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5094 +#define ACLS_NEED_MASK 1
5097 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5098 +#include <sys/acl.h>
5100 +#include "smb_acls.h"
5104 /* We have replacement versions of these if they're missing. */
5107 @@ -321,6 +321,7 @@ to the detailed description below for a
5108 -H, --hard-links preserve hard links
5109 -p, --perms preserve permissions
5110 -E, --executability preserve executability
5111 + -A, --acls preserve ACLs (implies -p) [non-standard]
5112 --chmod=CHMOD change destination permissions
5113 -o, --owner preserve owner (super-user only)
5114 -g, --group preserve group
5115 @@ -742,7 +743,9 @@ quote(itemize(
5116 permissions, though the bf(--executability) option might change just
5117 the execute permission for the file.
5118 it() New files get their "normal" permission bits set to the source
5119 - file's permissions masked with the receiving end's umask setting, and
5120 + file's permissions masked with the receiving directory's default
5121 + permissions (either the receiving process's umask, or the permissions
5122 + specified via the destination directory's default ACL), and
5123 their special permission bits disabled except in the case where a new
5124 directory inherits a setgid bit from its parent directory.
5126 @@ -773,9 +776,11 @@ The preservation of the destination's se
5127 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5128 versions erroneously preserved the three special permission bits for
5129 newly-created files when bf(--perms) was off, while overriding the
5130 -destination's setgid bit setting on a newly-created directory. (Keep in
5131 -mind that it is the version of the receiving rsync that affects this
5133 +destination's setgid bit setting on a newly-created directory. Default ACL
5134 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5135 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5136 +(Keep in mind that it is the version of the receiving rsync that affects
5139 dit(bf(-E, --executability)) This option causes rsync to preserve the
5140 executability (or non-executability) of regular files when bf(--perms) is
5141 @@ -793,6 +798,15 @@ quote(itemize(
5143 If bf(--perms) is enabled, this option is ignored.
5145 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5146 +ACLs to be the same as the source ACLs. This nonstandard option only
5147 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5149 +Note also that an optimization of the ACL-sending protocol used by this
5150 +version makes it incompatible with sending files to an older ACL-enabled
5151 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5152 +doubling is not needed when pulling files from an older rsync.
5154 dit(bf(--chmod)) This option tells rsync to apply one or more
5155 comma-separated "chmod" strings to the permission of the files in the
5156 transfer. The resulting value is treated as though it was the permissions
5161 + Unix SMB/Netbios implementation.
5163 + Portable SMB ACL interface
5164 + Copyright (C) Jeremy Allison 2000
5166 + This program is free software; you can redistribute it and/or modify
5167 + it under the terms of the GNU General Public License as published by
5168 + the Free Software Foundation; either version 2 of the License, or
5169 + (at your option) any later version.
5171 + This program is distributed in the hope that it will be useful,
5172 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5173 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5174 + GNU General Public License for more details.
5176 + You should have received a copy of the GNU General Public License
5177 + along with this program; if not, write to the Free Software
5178 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5181 +#ifndef _SMB_ACLS_H
5182 +#define _SMB_ACLS_H
5184 +#if defined HAVE_POSIX_ACLS
5186 +/* This is an identity mapping (just remove the SMB_). */
5188 +#define SMB_ACL_TAG_T acl_tag_t
5189 +#define SMB_ACL_TYPE_T acl_type_t
5190 +#define SMB_ACL_PERMSET_T acl_permset_t
5191 +#define SMB_ACL_PERM_T acl_perm_t
5192 +#define SMB_ACL_READ ACL_READ
5193 +#define SMB_ACL_WRITE ACL_WRITE
5194 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5196 +/* Types of ACLs. */
5197 +#define SMB_ACL_USER ACL_USER
5198 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5199 +#define SMB_ACL_GROUP ACL_GROUP
5200 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5201 +#define SMB_ACL_OTHER ACL_OTHER
5202 +#define SMB_ACL_MASK ACL_MASK
5204 +#define SMB_ACL_T acl_t
5206 +#define SMB_ACL_ENTRY_T acl_entry_t
5208 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5209 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5211 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5212 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5214 +#elif defined HAVE_TRU64_ACLS
5216 +/* This is for DEC/Compaq Tru64 UNIX */
5218 +#define SMB_ACL_TAG_T acl_tag_t
5219 +#define SMB_ACL_TYPE_T acl_type_t
5220 +#define SMB_ACL_PERMSET_T acl_permset_t
5221 +#define SMB_ACL_PERM_T acl_perm_t
5222 +#define SMB_ACL_READ ACL_READ
5223 +#define SMB_ACL_WRITE ACL_WRITE
5224 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5226 +/* Types of ACLs. */
5227 +#define SMB_ACL_USER ACL_USER
5228 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5229 +#define SMB_ACL_GROUP ACL_GROUP
5230 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5231 +#define SMB_ACL_OTHER ACL_OTHER
5232 +#define SMB_ACL_MASK ACL_MASK
5234 +#define SMB_ACL_T acl_t
5236 +#define SMB_ACL_ENTRY_T acl_entry_t
5238 +#define SMB_ACL_FIRST_ENTRY 0
5239 +#define SMB_ACL_NEXT_ENTRY 1
5241 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5242 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5244 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5246 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5247 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5250 +/* SVR4.2 ES/MP ACLs */
5251 +typedef int SMB_ACL_TAG_T;
5252 +typedef int SMB_ACL_TYPE_T;
5253 +typedef ushort *SMB_ACL_PERMSET_T;
5254 +typedef ushort SMB_ACL_PERM_T;
5255 +#define SMB_ACL_READ 4
5256 +#define SMB_ACL_WRITE 2
5257 +#define SMB_ACL_EXECUTE 1
5259 +/* Types of ACLs. */
5260 +#define SMB_ACL_USER USER
5261 +#define SMB_ACL_USER_OBJ USER_OBJ
5262 +#define SMB_ACL_GROUP GROUP
5263 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5264 +#define SMB_ACL_OTHER OTHER_OBJ
5265 +#define SMB_ACL_MASK CLASS_OBJ
5267 +typedef struct SMB_ACL_T {
5271 + struct acl acl[1];
5274 +typedef struct acl *SMB_ACL_ENTRY_T;
5276 +#define SMB_ACL_FIRST_ENTRY 0
5277 +#define SMB_ACL_NEXT_ENTRY 1
5279 +#define SMB_ACL_TYPE_ACCESS 0
5280 +#define SMB_ACL_TYPE_DEFAULT 1
5283 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5286 +#elif defined HAVE_HPUX_ACLS
5289 + * Based on the Solaris & UnixWare code.
5293 +#include <sys/aclv.h>
5295 +/* SVR4.2 ES/MP ACLs */
5296 +typedef int SMB_ACL_TAG_T;
5297 +typedef int SMB_ACL_TYPE_T;
5298 +typedef ushort *SMB_ACL_PERMSET_T;
5299 +typedef ushort SMB_ACL_PERM_T;
5300 +#define SMB_ACL_READ 4
5301 +#define SMB_ACL_WRITE 2
5302 +#define SMB_ACL_EXECUTE 1
5304 +/* Types of ACLs. */
5305 +#define SMB_ACL_USER USER
5306 +#define SMB_ACL_USER_OBJ USER_OBJ
5307 +#define SMB_ACL_GROUP GROUP
5308 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5309 +#define SMB_ACL_OTHER OTHER_OBJ
5310 +#define SMB_ACL_MASK CLASS_OBJ
5312 +typedef struct SMB_ACL_T {
5316 + struct acl acl[1];
5319 +typedef struct acl *SMB_ACL_ENTRY_T;
5321 +#define SMB_ACL_FIRST_ENTRY 0
5322 +#define SMB_ACL_NEXT_ENTRY 1
5324 +#define SMB_ACL_TYPE_ACCESS 0
5325 +#define SMB_ACL_TYPE_DEFAULT 1
5327 +#elif defined HAVE_IRIX_ACLS
5329 +#define SMB_ACL_TAG_T acl_tag_t
5330 +#define SMB_ACL_TYPE_T acl_type_t
5331 +#define SMB_ACL_PERMSET_T acl_permset_t
5332 +#define SMB_ACL_PERM_T acl_perm_t
5333 +#define SMB_ACL_READ ACL_READ
5334 +#define SMB_ACL_WRITE ACL_WRITE
5335 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5337 +/* Types of ACLs. */
5338 +#define SMB_ACL_USER ACL_USER
5339 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5340 +#define SMB_ACL_GROUP ACL_GROUP
5341 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5342 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5343 +#define SMB_ACL_MASK ACL_MASK
5345 +typedef struct SMB_ACL_T {
5351 +#define SMB_ACL_ENTRY_T acl_entry_t
5353 +#define SMB_ACL_FIRST_ENTRY 0
5354 +#define SMB_ACL_NEXT_ENTRY 1
5356 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5357 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5359 +#elif defined HAVE_AIX_ACLS
5361 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5363 +#include "/usr/include/acl.h"
5365 +typedef uint *SMB_ACL_PERMSET_T;
5367 +struct acl_entry_link{
5368 + struct acl_entry_link *prevp;
5369 + struct new_acl_entry *entryp;
5370 + struct acl_entry_link *nextp;
5374 +struct new_acl_entry{
5375 + unsigned short ace_len;
5376 + unsigned short ace_type;
5377 + unsigned int ace_access;
5378 + struct ace_id ace_id[1];
5381 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5382 +#define SMB_ACL_T struct acl_entry_link*
5384 +#define SMB_ACL_TAG_T unsigned short
5385 +#define SMB_ACL_TYPE_T int
5386 +#define SMB_ACL_PERM_T uint
5387 +#define SMB_ACL_READ S_IRUSR
5388 +#define SMB_ACL_WRITE S_IWUSR
5389 +#define SMB_ACL_EXECUTE S_IXUSR
5391 +/* Types of ACLs. */
5392 +#define SMB_ACL_USER ACEID_USER
5393 +#define SMB_ACL_USER_OBJ 3
5394 +#define SMB_ACL_GROUP ACEID_GROUP
5395 +#define SMB_ACL_GROUP_OBJ 4
5396 +#define SMB_ACL_OTHER 5
5397 +#define SMB_ACL_MASK 6
5400 +#define SMB_ACL_FIRST_ENTRY 1
5401 +#define SMB_ACL_NEXT_ENTRY 2
5403 +#define SMB_ACL_TYPE_ACCESS 0
5404 +#define SMB_ACL_TYPE_DEFAULT 1
5406 +#else /* No ACLs. */
5408 +/* No ACLS - fake it. */
5409 +#define SMB_ACL_TAG_T int
5410 +#define SMB_ACL_TYPE_T int
5411 +#define SMB_ACL_PERMSET_T mode_t
5412 +#define SMB_ACL_PERM_T mode_t
5413 +#define SMB_ACL_READ S_IRUSR
5414 +#define SMB_ACL_WRITE S_IWUSR
5415 +#define SMB_ACL_EXECUTE S_IXUSR
5417 +/* Types of ACLs. */
5418 +#define SMB_ACL_USER 0
5419 +#define SMB_ACL_USER_OBJ 1
5420 +#define SMB_ACL_GROUP 2
5421 +#define SMB_ACL_GROUP_OBJ 3
5422 +#define SMB_ACL_OTHER 4
5423 +#define SMB_ACL_MASK 5
5425 +typedef struct SMB_ACL_T {
5429 +typedef struct SMB_ACL_ENTRY_T {
5431 +} *SMB_ACL_ENTRY_T;
5433 +#define SMB_ACL_FIRST_ENTRY 0
5434 +#define SMB_ACL_NEXT_ENTRY 1
5436 +#define SMB_ACL_TYPE_ACCESS 0
5437 +#define SMB_ACL_TYPE_DEFAULT 1
5439 +#endif /* No ACLs. */
5440 +#endif /* _SMB_ACLS_H */
5441 --- old/testsuite/acls.test
5442 +++ new/testsuite/acls.test
5446 +# This program is distributable under the terms of the GNU GPL (see
5449 +# Test that rsync handles basic ACL preservation.
5451 +. $srcdir/testsuite/rsync.fns
5453 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5454 +case "$setfacl_nodef" in
5455 +true) test_skipped "I don't know how to use your setfacl command" ;;
5458 +makepath "$fromdir/foo"
5459 +echo something >"$fromdir/file1"
5460 +echo else >"$fromdir/file2"
5462 +files='foo file1 file2'
5464 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
5465 +setfacl -m u:0:5 "$fromdir/file1"
5466 +setfacl -m u:0:5 "$fromdir/file2"
5468 +$RSYNC -avvA "$fromdir/" "$todir/"
5471 +getfacl $files >"$scratchdir/acls.txt"
5474 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
5476 +# The script would have aborted on error, so getting here means we've won.
5478 --- old/testsuite/default-acls.test
5479 +++ new/testsuite/default-acls.test
5483 +# This program is distributable under the terms of the GNU GPL (see
5486 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5488 +. $srcdir/testsuite/rsync.fns
5490 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5491 +case "$setfacl_nodef" in
5492 +true) test_skipped "I don't know how to use your setfacl command" ;;
5493 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5494 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5496 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5498 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5500 + todir="$scratchdir/$1"
5502 + $setfacl_nodef "$todir"
5504 + case "$setfacl_nodef" in
5505 + *-k*) opts="-dm $2" ;;
5506 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5508 + setfacl $opts "$todir"
5510 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5511 + # even though the directory itself is outside the transfer
5512 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5513 + check_perms "$todir/to" $4 "Target $1"
5514 + check_perms "$todir/to/dir" $4 "Target $1"
5515 + check_perms "$todir/to/file" $3 "Target $1"
5516 + check_perms "$todir/to/program" $4 "Target $1"
5517 + # Make sure get_local_name doesn't mess us up when transferring only one file
5518 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5519 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5520 + # Make sure we obey default ACLs when not transferring a regular file
5521 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5522 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5525 +mkdir "$scratchdir/dir"
5526 +echo "File!" >"$scratchdir/file"
5527 +echo "#!/bin/sh" >"$scratchdir/program"
5528 +chmod 777 "$scratchdir/dir"
5529 +chmod 666 "$scratchdir/file"
5530 +chmod 777 "$scratchdir/program"
5532 +# Test some target directories
5534 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5535 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5536 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5537 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5538 +testit noda1 '' rw------- rwx------
5540 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5542 +testit noda3 '' rw-r--r-- rwxr-xr-x
5550 extern int preserve_uid;
5551 extern int preserve_gid;
5552 +extern int preserve_acls;
5553 extern int numeric_ids;
5556 @@ -275,7 +276,7 @@ void send_uid_list(int f)
5560 - if (preserve_uid) {
5561 + if (preserve_uid || preserve_acls) {
5563 /* we send sequences of uid/byte-length/name */
5564 for (list = uidlist; list; list = list->next) {
5565 @@ -292,7 +293,7 @@ void send_uid_list(int f)
5569 - if (preserve_gid) {
5570 + if (preserve_gid || preserve_acls) {
5572 for (list = gidlist; list; list = list->next) {
5574 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
5578 - if (preserve_uid && !numeric_ids) {
5579 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5580 /* read the uid list */
5581 while ((id = read_int(f)) != 0) {
5582 int len = read_byte(f);
5583 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
5587 - if (preserve_gid && !numeric_ids) {
5588 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5589 /* read the gid list */
5590 while ((id = read_int(f)) != 0) {
5591 int len = read_byte(f);
5592 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
5596 +#ifdef SUPPORT_ACLS
5597 + if (preserve_acls && !numeric_ids) {
5599 + while ((id = next_acl_uid(flist)) != NULL)
5600 + *id = match_uid(*id);
5601 + while ((id = next_acl_gid(flist)) != NULL)
5602 + *id = match_gid(*id);
5606 /* Now convert all the uids/gids from sender values to our values. */
5607 if (am_root && preserve_uid && !numeric_ids) {
5608 for (i = 0; i < flist->count; i++)