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 Wayne Davison
49 + * This program is free software; you can redistribute it and/or modify
50 + * it under the terms of the GNU General Public License as published by
51 + * the Free Software Foundation; either version 2 of the License, or
52 + * (at your option) any later version.
54 + * This program is distributed in the hope that it will be useful,
55 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
56 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 + * GNU General Public License for more details.
59 + * You should have received a copy of the GNU General Public License along
60 + * with this program; if not, write to the Free Software Foundation, Inc.,
61 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
65 +#include "lib/sysacls.h"
71 +extern int orig_umask;
72 +extern int preserve_acls;
85 +#define ACL_NO_ENTRY ((uchar)0x80)
89 + /* These will be ACL_NO_ENTRY if there's no such entry. */
96 +static const rsync_acl empty_rsync_acl = {
97 + {0, 0, NULL}, {0, 0, NULL},
98 + ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY
101 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
102 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
104 +/* a few useful calculations */
106 +static int count_racl_entries(const rsync_acl *racl)
108 + return racl->users.count + racl->groups.count
109 + + (racl->user_obj != ACL_NO_ENTRY)
110 + + (racl->group_obj != ACL_NO_ENTRY)
111 + + (racl->mask != ACL_NO_ENTRY)
112 + + (racl->other != ACL_NO_ENTRY);
115 +static int calc_sacl_entries(const rsync_acl *racl)
117 + return racl->users.count + racl->groups.count
118 +#ifdef ACLS_NEED_MASK
121 + + (racl->mask != ACL_NO_ENTRY) + 3;
125 +/* This cannot be called on an rsync_acl that has ACL_NO_ENTRY in any
126 + * spot but the mask. */
127 +static int rsync_acl_get_perms(const rsync_acl *racl)
129 + return (racl->user_obj << 6)
130 + + ((racl->mask != ACL_NO_ENTRY ? racl->mask : racl->group_obj) << 3)
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 rsync_acl_free(rsync_acl *racl)
167 + if (racl->users.idas)
168 + free(racl->users.idas);
169 + if (racl->groups.idas)
170 + free(racl->groups.idas);
171 + *racl = empty_rsync_acl;
174 +static int id_access_sorter(const void *r1, const void *r2)
176 + id_access *ida1 = (id_access *)r1;
177 + id_access *ida2 = (id_access *)r2;
178 + id_t rid1 = ida1->id, rid2 = ida2->id;
179 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
182 +static void sort_ida_list(ida_list *idal)
186 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
187 + &id_access_sorter);
190 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
192 + SMB_ACL_ENTRY_T entry;
193 + const char *errfun;
196 + *racl = empty_rsync_acl;
197 + errfun = "sys_acl_get_entry";
198 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
200 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
201 + SMB_ACL_TAG_T tag_type;
202 + SMB_ACL_PERMSET_T permset;
207 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
208 + errfun = "sys_acl_get_tag_type";
211 + if ((rc = sys_acl_get_permset(entry, &permset))) {
212 + errfun = "sys_acl_get_tag_type";
215 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
216 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
217 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
218 + /* continue == done with entry; break == store in given idal */
219 + switch (tag_type) {
220 + case SMB_ACL_USER_OBJ:
221 + if (racl->user_obj == ACL_NO_ENTRY)
222 + racl->user_obj = access;
224 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
227 + idal = &racl->users;
229 + case SMB_ACL_GROUP_OBJ:
230 + if (racl->group_obj == ACL_NO_ENTRY)
231 + racl->group_obj = access;
233 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
235 + case SMB_ACL_GROUP:
236 + idal = &racl->groups;
239 + if (racl->mask == ACL_NO_ENTRY)
240 + racl->mask = access;
242 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
244 + case SMB_ACL_OTHER:
245 + if (racl->other == ACL_NO_ENTRY)
246 + racl->other = access;
248 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
251 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
254 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
255 + errfun = "sys_acl_get_tag_type";
259 + expand_ida_list(idal);
260 + ida = &idal->idas[idal->count++];
261 + ida->id = *((id_t *)qualifier);
262 + ida->access = access;
263 + sys_acl_free_qualifier(qualifier, tag_type);
266 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
267 + errfun, strerror(errno));
268 + rsync_acl_free(racl);
272 + sort_ida_list(&racl->users);
273 + sort_ida_list(&racl->groups);
275 +#ifdef ACLS_NEED_MASK
276 + if (!racl->users.count && !racl->groups.count) {
277 + /* Throw away a superfluous mask, but mask off the
278 + * group perms with it first. */
279 + racl->group_obj &= racl->mask;
280 + racl->mask = ACL_NO_ENTRY;
287 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
289 + id_access *ida1, *ida2;
290 + size_t count = ial1->count;
291 + if (count != ial2->count)
295 + for (; count--; ida1++, ida2++) {
296 + if (ida1->access != ida2->access || ida1->id != ida2->id)
302 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
304 + return (racl1->user_obj == racl2->user_obj
305 + && racl1->group_obj == racl2->group_obj
306 + && racl1->mask == racl2->mask
307 + && racl1->other == racl2->other
308 + && ida_lists_equal(&racl1->users, &racl2->users)
309 + && ida_lists_equal(&racl1->groups, &racl2->groups));
312 +/* The first parameter will always be a fully-populated rsync_acl.
313 + * The second parameter will usually be a condensed rsync_acl, which means
314 + * that it might have several of its access objects set to ACL_NO_ENTRY. */
315 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1,
316 + const rsync_acl *racl2, mode_t m)
318 + /* We ignore any differences that chmod() can take care of. */
319 + if ((racl1->mask ^ racl2->mask) & ACL_NO_ENTRY)
321 + if (racl1->mask != ACL_NO_ENTRY) {
322 + /* A condensed rsync_acl with a mask can only have no
323 + * group_obj when it was identical to the mask. This
324 + * means that it was also identical to the group attrs
325 + * from the mode. */
326 + if (racl2->group_obj == ACL_NO_ENTRY) {
327 + if (racl1->group_obj != ((m >> 3) & 7))
329 + } else if (racl1->group_obj != racl2->group_obj)
332 + return ida_lists_equal(&racl1->users, &racl2->users)
333 + && ida_lists_equal(&racl1->groups, &racl2->groups);
342 +static rsync_acl_list _rsync_acl_lists[] = {
343 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
344 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
347 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
349 + return &_rsync_acl_lists[type != SMB_ACL_TYPE_ACCESS];
352 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
354 + /* First time through, 0 <= 0, so list is expanded. */
355 + if (racl_list->malloced <= racl_list->count) {
356 + rsync_acl *new_ptr;
358 + if (racl_list->malloced < 1000)
359 + new_size = racl_list->malloced + 1000;
361 + new_size = racl_list->malloced * 2;
362 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
363 + if (verbose >= 3) {
364 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
365 + (double) new_size * sizeof racl_list->racls[0],
366 + racl_list->racls ? "" : " not");
369 + racl_list->racls = new_ptr;
370 + racl_list->malloced = new_size;
372 + if (!racl_list->racls)
373 + out_of_memory("expand_rsync_acl_list");
377 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
378 + const rsync_acl_list *racl_list,
379 + const rsync_acl *racl)
381 + static int access_match = -1, default_match = -1;
382 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
383 + size_t count = racl_list->count;
385 + /* If this is the first time through or we didn't match the last
386 + * time, then start at the end of the list, which should be the
387 + * best place to start hunting. */
389 + *match = racl_list->count - 1;
391 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
394 + *match = racl_list->count - 1;
401 +/* The general strategy with the tag_type <-> character mapping is that
402 + * lowercase implies that no qualifier follows, where uppercase does.
403 + * A similar idiom for the acl type (access or default) itself, but
404 + * lowercase in this instance means there's no ACL following, so the
405 + * ACL is a repeat, so the receiver should reuse the last of the same
407 +static void send_ida_list(int f, const ida_list *idal, char tag_char)
410 + size_t count = idal->count;
411 + for (ida = idal->idas; count--; ida++) {
412 + write_byte(f, tag_char);
413 + write_byte(f, ida->access);
414 + write_int(f, ida->id);
415 + /* FIXME: sorta wasteful: we should maybe buffer as
416 + * many ids as max(ACL_USER + ACL_GROUP) objects to
417 + * keep from making so many calls. */
418 + if (tag_char == 'U')
425 +static void send_rsync_acl(int f, const rsync_acl *racl)
427 + size_t count = count_racl_entries(racl);
428 + write_int(f, count);
429 + if (racl->user_obj != ACL_NO_ENTRY) {
430 + write_byte(f, 'u');
431 + write_byte(f, racl->user_obj);
433 + send_ida_list(f, &racl->users, 'U');
434 + if (racl->group_obj != ACL_NO_ENTRY) {
435 + write_byte(f, 'g');
436 + write_byte(f, racl->group_obj);
438 + send_ida_list(f, &racl->groups, 'G');
439 + if (racl->mask != ACL_NO_ENTRY) {
440 + write_byte(f, 'm');
441 + write_byte(f, racl->mask);
443 + if (racl->other != ACL_NO_ENTRY) {
444 + write_byte(f, 'o');
445 + write_byte(f, racl->other);
449 +static rsync_acl _curr_rsync_acls[2];
451 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
453 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
454 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
455 + : "unknown SMB_ACL_TYPE_T";
458 +/* Generate the ACL(s) for this flist entry;
459 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
460 +int make_acl(const struct file_struct *file, const char *fname)
462 + SMB_ACL_TYPE_T type;
463 + rsync_acl *curr_racl;
465 + if (S_ISLNK(file->mode))
468 + curr_racl = &_curr_rsync_acls[0];
469 + type = SMB_ACL_TYPE_ACCESS;
473 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
474 + ok = unpack_smb_acl(curr_racl, sacl);
475 + sys_acl_free_acl(sacl);
478 + /* Avoid sending a redundant group/mask value. */
479 + if (curr_racl->group_obj == curr_racl->mask
480 + && (preserve_acls == 1
481 + || (!curr_racl->users.count
482 + && !curr_racl->groups.count)))
483 + curr_racl->mask = ACL_NO_ENTRY;
484 + /* Strip access ACLs of permission-bit entries. */
485 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
486 + rsync_acl_strip_perms(curr_racl);
487 + } else if (errno == ENOTSUP) {
488 + /* ACLs are not supported. Leave list empty. */
489 + *curr_racl = empty_rsync_acl;
491 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
492 + fname, str_acl_type(type), strerror(errno));
496 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
501 +/* Send the make_acl()-generated ACLs for this flist entry,
502 + * or clean up after an flist entry that's not being sent (f == -1). */
503 +void send_acl(const struct file_struct *file, int f)
505 + SMB_ACL_TYPE_T type;
506 + rsync_acl *curr_racl;
508 + if (S_ISLNK(file->mode))
511 + curr_racl = &_curr_rsync_acls[0];
512 + type = SMB_ACL_TYPE_ACCESS;
515 + rsync_acl_list *racl_list = rsync_acl_lists(type);
517 + rsync_acl_free(curr_racl++);
520 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
522 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
523 + write_int(f, index);
524 + rsync_acl_free(curr_racl);
526 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
527 + send_rsync_acl(f, curr_racl);
528 + expand_rsync_acl_list(racl_list);
529 + racl_list->racls[racl_list->count++] = *curr_racl;
532 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
535 +/* The below stuff is only used by the receiver: */
537 +/* structure to hold index to rsync_acl_list member corresponding to
538 + * flist->files[i] */
541 + const struct file_struct *file;
548 + file_acl_index *fais;
549 +} file_acl_index_list;
551 +static file_acl_index_list _file_acl_index_lists[] = {
552 + {0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
553 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
556 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
558 + return &_file_acl_index_lists[type != SMB_ACL_TYPE_ACCESS];
561 +static void expand_file_acl_index_list(file_acl_index_list *flst)
563 + /* First time through, 0 <= 0, so list is expanded. */
564 + if (flst->malloced <= flst->count) {
565 + file_acl_index *new_ptr;
568 + if (flst->malloced < 1000)
569 + new_size = flst->malloced + 1000;
571 + new_size = flst->malloced * 2;
572 + new_ptr = realloc_array(flst->fais, file_acl_index, new_size);
573 + if (verbose >= 3) {
574 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
575 + (double) new_size * sizeof flst->fais[0],
576 + flst->fais ? "" : " not");
579 + flst->fais = new_ptr;
580 + flst->malloced = new_size;
583 + out_of_memory("expand_file_acl_index_list");
587 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
595 +static smb_acl_list _smb_acl_lists[] = {
596 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
597 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
600 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
602 + return &_smb_acl_lists[type != SMB_ACL_TYPE_ACCESS];
605 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
607 + /* First time through, 0 <= 0, so list is expanded. */
608 + if (sacl_list->malloced <= sacl_list->count) {
609 + SMB_ACL_T *new_ptr;
611 + if (sacl_list->malloced < 1000)
612 + new_size = sacl_list->malloced + 1000;
614 + new_size = sacl_list->malloced * 2;
615 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
616 + if (verbose >= 3) {
617 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
618 + (double) new_size * sizeof sacl_list->sacls[0],
619 + sacl_list->sacls ? "" : " not");
622 + sacl_list->sacls = new_ptr;
623 + sacl_list->malloced = new_size;
625 + if (!sacl_list->sacls)
626 + out_of_memory("expand_smb_acl_list");
630 +#define CALL_OR_ERROR(func,args,str) \
638 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
639 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
641 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
643 + const char *errfun = NULL;
644 + SMB_ACL_PERMSET_T permset;
646 + COE( sys_acl_get_permset,(entry, &permset) );
647 + COE( sys_acl_clear_perms,(permset) );
649 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
651 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
653 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
654 + COE( sys_acl_set_permset,(entry, permset) );
659 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
664 +/* build an SMB_ACL_T corresponding to an rsync_acl */
665 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
667 +#ifdef ACLS_NEED_MASK
672 + const char *errfun = NULL;
673 + SMB_ACL_ENTRY_T entry;
675 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
676 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
681 + COE( sys_acl_create_entry,(smb_acl, &entry) );
682 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
683 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
685 + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) {
686 + COE( sys_acl_create_entry,(smb_acl, &entry) );
687 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
688 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
689 + COE2( store_access_in_entry,(ida->access, entry) );
692 + COE( sys_acl_create_entry,(smb_acl, &entry) );
693 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
694 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
696 + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) {
697 + COE( sys_acl_create_entry,(smb_acl, &entry) );
698 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
699 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
700 + COE2( store_access_in_entry,(ida->access, entry) );
703 +#ifdef ACLS_NEED_MASK
704 + mask_bits = racl->mask == ACL_NO_ENTRY ? racl->group_obj & 7 : racl->mask;
705 + COE( sys_acl_create_entry,(smb_acl, &entry) );
706 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
707 + COE2( store_access_in_entry,(mask_bits, entry) );
709 + if (racl->mask != ACL_NO_ENTRY) {
710 + COE( sys_acl_create_entry,(smb_acl, &entry) );
711 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
712 + COE2( store_access_in_entry,(racl->mask, entry) );
716 + COE( sys_acl_create_entry,(smb_acl, &entry) );
717 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
718 + COE2( store_access_in_entry,(racl->other & 7, entry) );
721 + if (sys_acl_valid(*smb_acl) < 0)
722 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
729 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
732 + sys_acl_free_acl(*smb_acl);
736 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
738 + SMB_ACL_ENTRY_T entry;
739 + const char *errfun;
742 + if (S_ISDIR(mode)) {
743 + /* If the sticky bit is going on, it's not safe to allow all
744 + * the new ACLs to go into effect before it gets set. */
745 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
746 + if (mode & S_ISVTX)
749 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
752 + /* If setuid or setgid is going off, it's not safe to allow all
753 + * the new ACLs to go into effect before they get cleared. */
754 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
755 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
760 + errfun = "sys_acl_get_entry";
761 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
763 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
764 + SMB_ACL_TAG_T tag_type;
765 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
766 + errfun = "sys_acl_get_tag_type";
769 + switch (tag_type) {
770 + case SMB_ACL_USER_OBJ:
771 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
773 + case SMB_ACL_GROUP_OBJ:
774 + /* group is only empty when identical to group perms. */
775 + if (racl->group_obj != ACL_NO_ENTRY)
777 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
780 +#ifndef ACLS_NEED_MASK
781 + /* mask is only empty when we don't need it. */
782 + if (racl->mask == ACL_NO_ENTRY)
785 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
787 + case SMB_ACL_OTHER:
788 + COE2( store_access_in_entry,(mode & 7, entry) );
795 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
796 + errfun, strerror(errno));
801 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
802 + /* Ensure that chmod() will be called to restore any lost setid bits. */
803 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
804 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
805 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
808 + /* Return the mode of the file on disk, as we will set them. */
809 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
812 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
814 + uchar computed_mask_bits = 0;
815 + ida_list *idal = NULL;
819 + *racl = empty_rsync_acl;
821 + if (!(count = read_int(f)))
825 + char tag = read_byte(f);
826 + uchar access = read_byte(f);
827 + if (access & ~ (4 | 2 | 1)) {
828 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
830 + exit_cleanup(RERR_STREAMIO);
834 + if (racl->user_obj != ACL_NO_ENTRY) {
835 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
836 + exit_cleanup(RERR_STREAMIO);
838 + racl->user_obj = access;
841 + idal = &racl->users;
844 + if (racl->group_obj != ACL_NO_ENTRY) {
845 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
846 + exit_cleanup(RERR_STREAMIO);
848 + racl->group_obj = access;
851 + idal = &racl->groups;
854 + if (racl->mask != ACL_NO_ENTRY) {
855 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
856 + exit_cleanup(RERR_STREAMIO);
858 + racl->mask = access;
861 + if (racl->other != ACL_NO_ENTRY) {
862 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
863 + exit_cleanup(RERR_STREAMIO);
865 + racl->other = access;
868 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
870 + exit_cleanup(RERR_STREAMIO);
872 + expand_ida_list(idal);
873 + ida = &idal->idas[idal->count++];
874 + ida->access = access;
875 + ida->id = read_int(f);
876 + computed_mask_bits |= access;
879 + if (type == SMB_ACL_TYPE_DEFAULT) {
880 + /* Ensure that these are never unset. */
881 + if (racl->user_obj == ACL_NO_ENTRY)
882 + racl->user_obj = 7;
883 + if (racl->group_obj == ACL_NO_ENTRY)
884 + racl->group_obj = 0;
885 + if (racl->other == ACL_NO_ENTRY)
889 + if (!racl->users.count && !racl->groups.count) {
890 + /* If we received a superfluous mask, throw it away. */
891 + if (racl->mask != ACL_NO_ENTRY) {
892 + /* Mask off the group perms with it first. */
893 + racl->group_obj &= racl->mask | ACL_NO_ENTRY;
894 + racl->mask = ACL_NO_ENTRY;
896 + } else if (racl->mask == ACL_NO_ENTRY) /* Must be non-empty with lists. */
897 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
900 +/* Receive and build the rsync_acl_lists. */
901 +void receive_acl(struct file_struct *file, int f)
903 + SMB_ACL_TYPE_T type;
905 + if (S_ISLNK(file->mode))
908 + type = SMB_ACL_TYPE_ACCESS;
911 + file_acl_index_list *flst = file_acl_index_lists(type);
913 + expand_file_acl_index_list(flst);
915 + tag = read_byte(f);
916 + if (tag == 'A' || tag == 'a') {
917 + if (type != SMB_ACL_TYPE_ACCESS) {
918 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
919 + f_name(file, NULL));
920 + exit_cleanup(RERR_STREAMIO);
922 + } else if (tag == 'D' || tag == 'd') {
923 + if (type == SMB_ACL_TYPE_ACCESS) {
924 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
925 + f_name(file, NULL));
926 + exit_cleanup(RERR_STREAMIO);
929 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
930 + f_name(file, NULL), tag);
931 + exit_cleanup(RERR_STREAMIO);
933 + if (tag == 'A' || tag == 'D') {
935 + rsync_acl_list *racl_list = rsync_acl_lists(type);
936 + smb_acl_list *sacl_list = smb_acl_lists(type);
937 + flst->fais[flst->count].aclidx = racl_list->count;
938 + flst->fais[flst->count++].file = file;
939 + receive_rsync_acl(&racl, f, type);
940 + expand_rsync_acl_list(racl_list);
941 + racl_list->racls[racl_list->count++] = racl;
942 + expand_smb_acl_list(sacl_list);
943 + sacl_list->sacls[sacl_list->count++] = NULL;
945 + int index = read_int(f);
946 + rsync_acl_list *racl_list = rsync_acl_lists(type);
947 + if ((size_t) index >= racl_list->count) {
948 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
949 + f_name(file, NULL),
950 + str_acl_type(type),
952 + exit_cleanup(RERR_STREAMIO);
954 + flst->fais[flst->count].aclidx = index;
955 + flst->fais[flst->count++].file = file;
957 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
960 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
962 + const file_acl_index *fx1 = (const file_acl_index *)f1;
963 + const file_acl_index *fx2 = (const file_acl_index *)f2;
964 + return fx1->file == fx2->file ? 0 : fx1->file < fx2->file ? -1 : 1;
967 +void sort_file_acl_index_lists()
969 + SMB_ACL_TYPE_T type;
971 + type = SMB_ACL_TYPE_ACCESS;
973 + file_acl_index_list *flst = file_acl_index_lists(type);
978 + qsort(flst->fais, flst->count, sizeof flst->fais[0],
979 + &file_acl_index_list_sorter);
980 + } while (BUMP_TYPE(type));
983 +static int find_file_acl_index(const file_acl_index_list *flst,
984 + const struct file_struct *file)
986 + int low = 0, high = flst->count;
987 + const struct file_struct *file_mid;
992 + int mid = (high + low) / 2;
993 + file_mid = flst->fais[mid].file;
994 + if (file_mid == file)
995 + return flst->fais[mid].aclidx;
996 + if (file_mid > file)
1000 + } while (low < high);
1001 + if (low == high) {
1002 + file_mid = flst->fais[low].file;
1003 + if (file_mid == file)
1004 + return flst->fais[low].aclidx;
1007 + "find_file_acl_index: can't find entry for file in list\n");
1008 + exit_cleanup(RERR_STREAMIO);
1012 +/* for duplicating ACLs on backups when using backup_dir */
1013 +int dup_acl(const char *orig, const char *bak, mode_t mode)
1015 + SMB_ACL_TYPE_T type;
1018 + type = SMB_ACL_TYPE_ACCESS;
1020 + SMB_ACL_T sacl_orig, sacl_bak;
1021 + rsync_acl racl_orig, racl_bak;
1022 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
1023 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
1024 + orig, str_acl_type(type), strerror(errno));
1028 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
1029 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
1030 + bak, str_acl_type(type), strerror(errno));
1032 + /* try to forge on through */
1034 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
1036 + goto out_with_sacls;
1039 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
1041 + goto out_with_one_racl;
1043 + if (rsync_acls_equal(&racl_orig, &racl_bak))
1044 + goto out_with_all;
1046 + ; /* presume they're unequal */
1048 + if (type == SMB_ACL_TYPE_DEFAULT
1049 + && racl_orig.user_obj == ACL_NO_ENTRY) {
1050 + if (sys_acl_delete_def_file(bak) < 0) {
1051 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
1052 + bak, strerror(errno));
1055 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
1056 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
1057 + bak, str_acl_type(type), strerror(errno));
1062 + rsync_acl_free(&racl_bak);
1063 + out_with_one_racl:
1064 + rsync_acl_free(&racl_orig);
1067 + sys_acl_free_acl(sacl_bak);
1069 + sys_acl_free_acl(sacl_orig);
1070 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1075 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1076 + * for keep_backup(). */
1077 +static const struct file_struct *backup_orig_file = NULL;
1078 +static const char null_string[] = "";
1079 +static const char *backup_orig_fname = null_string;
1080 +static const char *backup_dest_fname = null_string;
1081 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1083 +void push_keep_backup_acl(const struct file_struct *file,
1084 + const char *orig, const char *dest)
1086 + SMB_ACL_TYPE_T type;
1089 + backup_orig_file = file;
1090 + backup_orig_fname = orig;
1091 + backup_dest_fname = dest;
1093 + sacl = &_backup_sacl[0];
1094 + type = SMB_ACL_TYPE_ACCESS;
1096 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1100 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1102 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1103 + orig, str_acl_type(type),
1106 + } while (BUMP_TYPE(type));
1109 +static int set_keep_backup_acl()
1111 + SMB_ACL_TYPE_T type;
1115 + sacl = &_backup_sacl[0];
1116 + type = SMB_ACL_TYPE_ACCESS;
1119 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1121 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1122 + backup_dest_fname,
1123 + str_acl_type(type),
1127 + } while (BUMP_TYPE(type));
1132 +void cleanup_keep_backup_acl()
1134 + SMB_ACL_TYPE_T type;
1137 + backup_orig_file = NULL;
1138 + backup_orig_fname = null_string;
1139 + backup_dest_fname = null_string;
1141 + sacl = &_backup_sacl[0];
1142 + type = SMB_ACL_TYPE_ACCESS;
1145 + sys_acl_free_acl(*sacl);
1148 + } while (BUMP_TYPE(type));
1151 +/* set ACL on rsync-ed or keep_backup-ed file
1153 + * This sets extended access ACL entries and default ACLs. If convenient,
1154 + * it sets permission bits along with the access ACLs and signals having
1155 + * done so by modifying mode_p, which should point into the stat buffer.
1157 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1158 + * Pass NULL for mode_p to get the return code without changing anything. */
1159 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1161 + int unchanged = 1;
1162 + SMB_ACL_TYPE_T type;
1164 + if (S_ISLNK(file->mode))
1167 + if (file == backup_orig_file) {
1168 + if (!strcmp(fname, backup_dest_fname))
1169 + return set_keep_backup_acl();
1171 + type = SMB_ACL_TYPE_ACCESS;
1174 + SMB_ACL_T sacl_orig, *sacl_new;
1175 + rsync_acl racl_orig, *racl_new;
1176 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1178 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1179 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1180 + sacl_orig = sys_acl_get_file(fname, type);
1182 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1183 + fname, str_acl_type(type), strerror(errno));
1187 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1188 + sys_acl_free_acl(sacl_orig);
1193 + if (type == SMB_ACL_TYPE_ACCESS)
1194 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new, file->mode);
1196 + ok = rsync_acls_equal(&racl_orig, racl_new);
1197 + rsync_acl_free(&racl_orig);
1200 + if (!dry_run && mode_p) {
1201 + if (type == SMB_ACL_TYPE_DEFAULT
1202 + && racl_new->user_obj == ACL_NO_ENTRY) {
1203 + if (sys_acl_delete_def_file(fname) < 0) {
1204 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1205 + fname, strerror(errno));
1210 + mode_t cur_mode = *mode_p;
1212 + && !pack_smb_acl(sacl_new, racl_new)) {
1216 + if (type == SMB_ACL_TYPE_ACCESS) {
1217 + cur_mode = change_sacl_perms(*sacl_new, racl_new,
1218 + cur_mode, file->mode);
1219 + if (cur_mode == ~0u)
1222 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1223 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1224 + fname, str_acl_type(type),
1229 + if (type == SMB_ACL_TYPE_ACCESS)
1230 + *mode_p = cur_mode;
1233 + if (unchanged == 1)
1235 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1240 +/* Enumeration functions for uid mapping: */
1242 +/* Context -- one and only one. Should be cycled through once on uid
1243 + * mapping and once on gid mapping. */
1244 +static rsync_acl_list *_enum_racl_lists[] = {
1245 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1248 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1249 +static size_t enum_racl_index = 0;
1250 +static size_t enum_ida_index = 0;
1252 +/* This returns the next tag_type id from the given acl for the next entry,
1253 + * or it returns 0 if there are no more tag_type ids in the acl. */
1254 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1256 + const ida_list *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1257 + if (enum_ida_index < idal->count) {
1258 + id_access *ida = &idal->idas[enum_ida_index++];
1261 + enum_ida_index = 0;
1265 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1267 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1268 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1269 + id_t *id = next_ace_id(tag_type, racl);
1273 + enum_racl_index = 0;
1277 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1279 + for (; *enum_racl_list; enum_racl_list++) {
1280 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1284 + enum_racl_list = &_enum_racl_lists[0];
1288 +id_t *next_acl_uid()
1290 + return next_acl_list_id(SMB_ACL_USER);
1293 +id_t *next_acl_gid()
1295 + return next_acl_list_id(SMB_ACL_GROUP);
1298 +int default_perms_for_dir(const char *dir)
1307 + perms = ACCESSPERMS & ~orig_umask;
1308 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1309 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1310 + if (sacl == NULL) {
1311 + /* Couldn't get an ACL. Darn. */
1314 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1318 + /* We're doing a dry run, so the containing directory
1319 + * wasn't actually created. Don't worry about it. */
1322 + /* Otherwise fall through. */
1324 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1325 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1331 + ok = unpack_smb_acl(&racl, sacl);
1332 + sys_acl_free_acl(sacl);
1334 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1338 + /* Apply the permission-bit entries of the default ACL, if any. */
1339 + if (racl.user_obj != ACL_NO_ENTRY) {
1340 + perms = rsync_acl_get_perms(&racl);
1342 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1345 + rsync_acl_free(&racl);
1349 +#endif /* SUPPORT_ACLS */
1352 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1353 extern char *backup_dir;
1356 +extern int preserve_acls;
1357 extern int preserve_devices;
1358 extern int preserve_specials;
1359 extern int preserve_links;
1360 @@ -133,6 +134,10 @@ static int make_bak_dir(char *fullpath)
1362 do_lchown(fullpath, st.st_uid, st.st_gid);
1363 do_chmod(fullpath, st.st_mode);
1364 +#ifdef SUPPORT_ACLS
1365 + if (preserve_acls)
1366 + dup_acl(end, fullpath, st.st_mode);
1371 @@ -186,6 +191,11 @@ static int keep_backup(char *fname)
1372 if (!(buf = get_backup_name(fname)))
1375 +#ifdef SUPPORT_ACLS
1376 + if (preserve_acls)
1377 + push_keep_backup_acl(file, fname, buf);
1380 /* Check to see if this is a device file, or link */
1381 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1382 || (preserve_specials && IS_SPECIAL(file->mode))) {
1383 @@ -261,6 +271,10 @@ static int keep_backup(char *fname)
1386 set_file_attrs(buf, file, NULL, 0);
1387 +#ifdef SUPPORT_ACLS
1388 + if (preserve_acls)
1389 + cleanup_keep_backup_acl();
1394 --- old/configure.in
1395 +++ new/configure.in
1396 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1397 AC_CHECK_LIB(resolv, strcasecmp)
1400 +AC_CHECK_FUNCS(aclsort)
1401 +if test x"$ac_cv_func_aclsort" = x"no"; then
1402 + AC_CHECK_LIB(sec, aclsort)
1405 dnl At the moment we don't test for a broken memcmp(), because all we
1406 dnl need to do is test for equality, not comparison, and it seems that
1407 dnl every platform has a memcmp that can do at least that.
1408 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1409 AC_SUBST(CC_SHOBJ_FLAG)
1410 AC_SUBST(BUILD_POPT)
1412 +AC_CHECK_HEADERS(sys/acl.h)
1413 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1414 +#################################################
1415 +# check for ACL support
1417 +AC_MSG_CHECKING(whether to support ACLs)
1418 +AC_ARG_ENABLE(acl-support,
1419 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1420 +[ case "$enableval" in
1423 + case "$host_os" in
1425 + AC_MSG_RESULT(Using UnixWare ACLs)
1426 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1428 + *solaris*|*cygwin*)
1429 + AC_MSG_RESULT(Using solaris ACLs)
1430 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1433 + AC_MSG_RESULT(Using HPUX ACLs)
1434 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1437 + AC_MSG_RESULT(Using IRIX ACLs)
1438 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1441 + AC_MSG_RESULT(Using AIX ACLs)
1442 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1445 + AC_MSG_RESULT(Using Tru64 ACLs)
1446 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1447 + LIBS="$LIBS -lpacl"
1450 + AC_MSG_RESULT(ACLs requested -- running tests)
1451 + AC_CHECK_LIB(acl,acl_get_file)
1452 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1453 + AC_TRY_LINK([#include <sys/types.h>
1454 +#include <sys/acl.h>],
1455 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1456 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1457 + AC_MSG_CHECKING(ACL test results)
1458 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1459 + AC_MSG_RESULT(Using posix ACLs)
1460 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1461 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1462 + AC_TRY_LINK([#include <sys/types.h>
1463 +#include <sys/acl.h>],
1464 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1465 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1466 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1467 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1470 + AC_MSG_ERROR(Failed to find ACL support)
1477 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1480 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1484 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1489 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1490 extern int one_file_system;
1491 extern int copy_dirlinks;
1492 extern int keep_dirlinks;
1493 +extern int preserve_acls;
1494 extern int preserve_links;
1495 extern int preserve_hard_links;
1496 extern int preserve_devices;
1497 @@ -961,6 +962,11 @@ static struct file_struct *send_file_nam
1498 if (chmod_modes && !S_ISLNK(file->mode))
1499 file->mode = tweak_mode(file->mode, chmod_modes);
1501 +#ifdef SUPPORT_ACLS
1502 + if (preserve_acls && make_acl(file, fname) < 0)
1506 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1508 flist_expand(flist);
1509 @@ -968,6 +974,16 @@ static struct file_struct *send_file_nam
1510 if (file->basename[0]) {
1511 flist->files[flist->count++] = file;
1512 send_file_entry(file, f);
1513 +#ifdef SUPPORT_ACLS
1514 + if (preserve_acls)
1515 + send_acl(file, f);
1518 +#ifdef SUPPORT_ACLS
1519 + /* Cleanup unsent ACL(s). */
1520 + if (preserve_acls)
1521 + send_acl(file, -1);
1526 @@ -1356,6 +1372,11 @@ struct file_list *recv_file_list(int f)
1527 flags |= read_byte(f) << 8;
1528 file = receive_file_entry(flist, flags, f);
1530 +#ifdef SUPPORT_ACLS
1531 + if (preserve_acls)
1532 + receive_acl(file, f);
1535 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1536 stats.total_size += file->length;
1538 @@ -1378,6 +1399,11 @@ struct file_list *recv_file_list(int f)
1540 clean_flist(flist, relative_paths, 1);
1542 +#ifdef SUPPORT_ACLS
1543 + if (preserve_acls)
1544 + sort_file_acl_index_lists();
1548 recv_uid_list(f, flist);
1552 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1553 extern int max_delete;
1554 extern int force_delete;
1555 extern int one_file_system;
1556 +extern mode_t orig_umask;
1557 extern struct stats stats;
1558 extern dev_t filesystem_dev;
1559 extern char *backup_dir;
1560 @@ -319,6 +320,8 @@ static void do_delete_pass(struct file_l
1562 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1564 + /* FIXME: Flag ACL changes. */
1567 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1569 @@ -353,6 +356,7 @@ void itemize(struct file_struct *file, i
1570 if (preserve_gid && file->gid != GID_NONE
1571 && st->st_gid != file->gid)
1572 iflags |= ITEM_REPORT_GROUP;
1573 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1575 iflags |= ITEM_IS_NEW;
1577 @@ -769,6 +773,7 @@ static int try_dests_non(struct file_str
1580 static int phase = 0;
1581 +static int dflt_perms;
1583 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1584 * make sure it exists, and has the right permissions/timestamp info. For
1585 @@ -860,6 +865,10 @@ static void recv_generator(char *fname,
1588 need_fuzzy_dirlist = 1;
1589 +#ifdef SUPPORT_ACLS
1590 + if (!preserve_perms)
1591 + dflt_perms = default_perms_for_dir(dn);
1594 parent_dirname = dn;
1596 @@ -887,7 +896,8 @@ static void recv_generator(char *fname,
1597 if (!preserve_perms) {
1598 int exists = statret == 0
1599 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1600 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1601 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1605 if (S_ISDIR(file->mode)) {
1606 @@ -1366,6 +1376,8 @@ void generate_files(int f_out, struct fi
1607 * notice that and let us know via the redo pipe (or its closing). */
1610 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1612 for (i = 0; i < flist->count; i++) {
1613 struct file_struct *file = flist->files[i];
1615 --- old/lib/sysacls.c
1616 +++ new/lib/sysacls.c
1619 + * Unix SMB/CIFS implementation.
1620 + * Samba system utilities for ACL support.
1622 + * Copyright (C) Jeremy Allison 2000.
1624 + * This program is free software; you can redistribute it and/or modify
1625 + * it under the terms of the GNU General Public License as published by
1626 + * the Free Software Foundation; either version 2 of the License, or
1627 + * (at your option) any later version.
1629 + * This program is distributed in the hope that it will be useful,
1630 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1631 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1632 + * GNU General Public License for more details.
1634 + * You should have received a copy of the GNU General Public License along
1635 + * with this program; if not, write to the Free Software Foundation, Inc.,
1636 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
1640 +#include "sysacls.h" /****** ADDED ******/
1642 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1643 +void SAFE_FREE(void *mem)
1649 +char *uidtoname(uid_t uid)
1651 + static char idbuf[12];
1652 + struct passwd *pw;
1654 + if ((pw = getpwuid(uid)) == NULL) {
1655 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1658 + return pw->pw_name;
1660 +/****** EXTRAS -- END ******/
1663 + This file wraps all differing system ACL interfaces into a consistent
1664 + one based on the POSIX interface. It also returns the correct errors
1665 + for older UNIX systems that don't support ACLs.
1667 + The interfaces that each ACL implementation must support are as follows :
1669 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1670 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1671 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1672 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1673 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1674 + SMB_ACL_T sys_acl_get_fd(int fd)
1675 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1676 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1677 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1678 + SMB_ACL_T sys_acl_init( int count)
1679 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1680 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1681 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1682 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1683 + int sys_acl_valid( SMB_ACL_T theacl )
1684 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1685 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1686 + int sys_acl_delete_def_file(const char *path)
1688 + This next one is not POSIX complient - but we *have* to have it !
1689 + More POSIX braindamage.
1691 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1693 + The generic POSIX free is the following call. We split this into
1694 + several different free functions as we may need to add tag info
1695 + to structures when emulating the POSIX interface.
1697 + int sys_acl_free( void *obj_p)
1699 + The calls we actually use are :
1701 + int sys_acl_free_text(char *text) - free acl_to_text
1702 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1703 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1707 +#if defined(HAVE_POSIX_ACLS)
1709 +/* Identity mapping - easy. */
1711 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1713 + return acl_get_entry( the_acl, entry_id, entry_p);
1716 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1718 + return acl_get_tag_type( entry_d, tag_type_p);
1721 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1723 + return acl_get_permset( entry_d, permset_p);
1726 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1728 + return acl_get_qualifier( entry_d);
1731 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1733 + return acl_get_file( path_p, type);
1736 +SMB_ACL_T sys_acl_get_fd(int fd)
1738 + return acl_get_fd(fd);
1741 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1743 + return acl_clear_perms(permset);
1746 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1748 + return acl_add_perm(permset, perm);
1751 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1753 +#if defined(HAVE_ACL_GET_PERM_NP)
1755 + * Required for TrustedBSD-based ACL implementations where
1756 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1759 + return acl_get_perm_np(permset, perm);
1761 + return acl_get_perm(permset, perm);
1765 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1767 + return acl_to_text( the_acl, plen);
1770 +SMB_ACL_T sys_acl_init( int count)
1772 + return acl_init(count);
1775 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1777 + return acl_create_entry(pacl, pentry);
1780 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1782 + return acl_set_tag_type(entry, tagtype);
1785 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1787 + return acl_set_qualifier(entry, qual);
1790 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1792 + return acl_set_permset(entry, permset);
1795 +int sys_acl_valid( SMB_ACL_T theacl )
1797 + return acl_valid(theacl);
1800 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1802 + return acl_set_file(name, acltype, theacl);
1805 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1807 + return acl_set_fd(fd, theacl);
1810 +int sys_acl_delete_def_file(const char *name)
1812 + return acl_delete_def_file(name);
1815 +int sys_acl_free_text(char *text)
1817 + return acl_free(text);
1820 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1822 + return acl_free(the_acl);
1825 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1827 + return acl_free(qual);
1830 +#elif defined(HAVE_TRU64_ACLS)
1832 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1833 + * is based on Draft 13 of the POSIX spec which is
1834 + * slightly different from the Draft 16 interface.
1836 + * Also, some of the permset manipulation functions
1837 + * such as acl_clear_perm() and acl_add_perm() appear
1838 + * to be broken on Tru64 so we have to manipulate
1839 + * the permission bits in the permset directly.
1841 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1843 + SMB_ACL_ENTRY_T entry;
1845 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1850 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1855 + return errno ? -1 : 0;
1858 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1860 + return acl_get_tag_type( entry_d, tag_type_p);
1863 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1865 + return acl_get_permset( entry_d, permset_p);
1868 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1870 + return acl_get_qualifier( entry_d);
1873 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1875 + return acl_get_file((char *)path_p, type);
1878 +SMB_ACL_T sys_acl_get_fd(int fd)
1880 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1883 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1885 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1890 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1892 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1897 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1902 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1904 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1907 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1909 + return acl_to_text( the_acl, plen);
1912 +SMB_ACL_T sys_acl_init( int count)
1914 + return acl_init(count);
1917 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1919 + SMB_ACL_ENTRY_T entry;
1921 + if ((entry = acl_create_entry(pacl)) == NULL) {
1929 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1931 + return acl_set_tag_type(entry, tagtype);
1934 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1936 + return acl_set_qualifier(entry, qual);
1939 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1941 + return acl_set_permset(entry, permset);
1944 +int sys_acl_valid( SMB_ACL_T theacl )
1946 + acl_entry_t entry;
1948 + return acl_valid(theacl, &entry);
1951 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1953 + return acl_set_file((char *)name, acltype, theacl);
1956 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1958 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1961 +int sys_acl_delete_def_file(const char *name)
1963 + return acl_delete_def_file((char *)name);
1966 +int sys_acl_free_text(char *text)
1969 + * (void) cast and explicit return 0 are for DEC UNIX
1970 + * which just #defines acl_free_text() to be free()
1972 + (void) acl_free_text(text);
1976 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1978 + return acl_free(the_acl);
1981 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1983 + return acl_free_qualifier(qual, tagtype);
1986 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1989 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1990 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1994 + * Note that while this code implements sufficient functionality
1995 + * to support the sys_acl_* interfaces it does not provide all
1996 + * of the semantics of the POSIX ACL interfaces.
1998 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1999 + * from a call to sys_acl_get_entry() should not be assumed to be
2000 + * valid after calling any of the following functions, which may
2001 + * reorder the entries in the ACL.
2004 + * sys_acl_set_file()
2005 + * sys_acl_set_fd()
2009 + * The only difference between Solaris and UnixWare / OpenUNIX is
2010 + * that the #defines for the ACL operations have different names
2012 +#if defined(HAVE_UNIXWARE_ACLS)
2014 +#define SETACL ACL_SET
2015 +#define GETACL ACL_GET
2016 +#define GETACLCNT ACL_CNT
2021 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2023 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2028 + if (entry_p == NULL) {
2033 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2037 + if (acl_d->next < 0) {
2042 + if (acl_d->next >= acl_d->count) {
2046 + *entry_p = &acl_d->acl[acl_d->next++];
2051 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2053 + *type_p = entry_d->a_type;
2058 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2060 + *permset_p = &entry_d->a_perm;
2065 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2067 + if (entry_d->a_type != SMB_ACL_USER
2068 + && entry_d->a_type != SMB_ACL_GROUP) {
2073 + return &entry_d->a_id;
2077 + * There is no way of knowing what size the ACL returned by
2078 + * GETACL will be unless you first call GETACLCNT which means
2079 + * making an additional system call.
2081 + * In the hope of avoiding the cost of the additional system
2082 + * call in most cases, we initially allocate enough space for
2083 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2084 + * be too small then we use GETACLCNT to find out the actual
2085 + * size, reallocate the ACL buffer, and then call GETACL again.
2088 +#define INITIAL_ACL_SIZE 16
2090 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2093 + int count; /* # of ACL entries allocated */
2094 + int naccess; /* # of access ACL entries */
2095 + int ndefault; /* # of default ACL entries */
2097 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2102 + count = INITIAL_ACL_SIZE;
2103 + if ((acl_d = sys_acl_init(count)) == NULL) {
2108 + * If there isn't enough space for the ACL entries we use
2109 + * GETACLCNT to determine the actual number of ACL entries
2110 + * reallocate and try again. This is in a loop because it
2111 + * is possible that someone else could modify the ACL and
2112 + * increase the number of entries between the call to
2113 + * GETACLCNT and the call to GETACL.
2115 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2116 + && errno == ENOSPC) {
2118 + sys_acl_free_acl(acl_d);
2120 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2124 + if ((acl_d = sys_acl_init(count)) == NULL) {
2130 + sys_acl_free_acl(acl_d);
2135 + * calculate the number of access and default ACL entries
2137 + * Note: we assume that the acl() system call returned a
2138 + * well formed ACL which is sorted so that all of the
2139 + * access ACL entries preceed any default ACL entries
2141 + for (naccess = 0; naccess < count; naccess++) {
2142 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2145 + ndefault = count - naccess;
2148 + * if the caller wants the default ACL we have to copy
2149 + * the entries down to the start of the acl[] buffer
2150 + * and mask out the ACL_DEFAULT flag from the type field
2152 + if (type == SMB_ACL_TYPE_DEFAULT) {
2155 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2156 + acl_d->acl[i] = acl_d->acl[j];
2157 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2160 + acl_d->count = ndefault;
2162 + acl_d->count = naccess;
2168 +SMB_ACL_T sys_acl_get_fd(int fd)
2171 + int count; /* # of ACL entries allocated */
2172 + int naccess; /* # of access ACL entries */
2174 + count = INITIAL_ACL_SIZE;
2175 + if ((acl_d = sys_acl_init(count)) == NULL) {
2179 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2180 + && errno == ENOSPC) {
2182 + sys_acl_free_acl(acl_d);
2184 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2188 + if ((acl_d = sys_acl_init(count)) == NULL) {
2194 + sys_acl_free_acl(acl_d);
2199 + * calculate the number of access ACL entries
2201 + for (naccess = 0; naccess < count; naccess++) {
2202 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2206 + acl_d->count = naccess;
2211 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2218 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2220 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2221 + && perm != SMB_ACL_EXECUTE) {
2226 + if (permset_d == NULL) {
2231 + *permset_d |= perm;
2236 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2238 + return *permset_d & perm;
2241 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2248 + * use an initial estimate of 20 bytes per ACL entry
2249 + * when allocating memory for the text representation
2253 + maxlen = 20 * acl_d->count;
2254 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2259 + for (i = 0; i < acl_d->count; i++) {
2260 + struct acl *ap = &acl_d->acl[i];
2269 + switch (ap->a_type) {
2271 + * for debugging purposes it's probably more
2272 + * useful to dump unknown tag types rather
2273 + * than just returning an error
2276 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2279 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2284 + case SMB_ACL_USER:
2285 + id = uidtoname(ap->a_id);
2286 + case SMB_ACL_USER_OBJ:
2290 + case SMB_ACL_GROUP:
2291 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2292 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2298 + case SMB_ACL_GROUP_OBJ:
2302 + case SMB_ACL_OTHER:
2306 + case SMB_ACL_MASK:
2312 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2313 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2314 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2317 + /* <tag> : <qualifier> : rwx \n \0 */
2318 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2321 + * If this entry would overflow the buffer
2322 + * allocate enough additional memory for this
2323 + * entry and an estimate of another 20 bytes
2324 + * for each entry still to be processed
2326 + if ((len + nbytes) > maxlen) {
2327 + char *oldtext = text;
2329 + maxlen += nbytes + 20 * (acl_d->count - i);
2331 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2332 + SAFE_FREE(oldtext);
2338 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2339 + len += nbytes - 1;
2348 +SMB_ACL_T sys_acl_init(int count)
2358 + * note that since the definition of the structure pointed
2359 + * to by the SMB_ACL_T includes the first element of the
2360 + * acl[] array, this actually allocates an ACL with room
2361 + * for (count+1) entries
2363 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2368 + a->size = count + 1;
2376 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2379 + SMB_ACL_ENTRY_T entry_d;
2381 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2386 + if (acl_d->count >= acl_d->size) {
2391 + entry_d = &acl_d->acl[acl_d->count++];
2392 + entry_d->a_type = 0;
2393 + entry_d->a_id = -1;
2394 + entry_d->a_perm = 0;
2395 + *entry_p = entry_d;
2400 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2402 + switch (tag_type) {
2403 + case SMB_ACL_USER:
2404 + case SMB_ACL_USER_OBJ:
2405 + case SMB_ACL_GROUP:
2406 + case SMB_ACL_GROUP_OBJ:
2407 + case SMB_ACL_OTHER:
2408 + case SMB_ACL_MASK:
2409 + entry_d->a_type = tag_type;
2419 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2421 + if (entry_d->a_type != SMB_ACL_GROUP
2422 + && entry_d->a_type != SMB_ACL_USER) {
2427 + entry_d->a_id = *((id_t *)qual_p);
2432 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2434 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2438 + entry_d->a_perm = *permset_d;
2444 + * sort the ACL and check it for validity
2446 + * if it's a minimal ACL with only 4 entries then we
2447 + * need to recalculate the mask permissions to make
2448 + * sure that they are the same as the GROUP_OBJ
2449 + * permissions as required by the UnixWare acl() system call.
2451 + * (note: since POSIX allows minimal ACLs which only contain
2452 + * 3 entries - ie there is no mask entry - we should, in theory,
2453 + * check for this and add a mask entry if necessary - however
2454 + * we "know" that the caller of this interface always specifies
2455 + * a mask so, in practice "this never happens" (tm) - if it *does*
2456 + * happen aclsort() will fail and return an error and someone will
2457 + * have to fix it ...)
2460 +static int acl_sort(SMB_ACL_T acl_d)
2462 + int fixmask = (acl_d->count <= 4);
2464 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2471 +int sys_acl_valid(SMB_ACL_T acl_d)
2473 + return acl_sort(acl_d);
2476 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2479 + struct acl *acl_p;
2481 + struct acl *acl_buf = NULL;
2484 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2489 + if (acl_sort(acl_d) != 0) {
2493 + acl_p = &acl_d->acl[0];
2494 + acl_count = acl_d->count;
2497 + * if it's a directory there is extra work to do
2498 + * since the acl() system call will replace both
2499 + * the access ACLs and the default ACLs (if any)
2501 + if (stat(name, &s) != 0) {
2504 + if (S_ISDIR(s.st_mode)) {
2505 + SMB_ACL_T acc_acl;
2506 + SMB_ACL_T def_acl;
2507 + SMB_ACL_T tmp_acl;
2510 + if (type == SMB_ACL_TYPE_ACCESS) {
2512 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2516 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2519 + if (tmp_acl == NULL) {
2524 + * allocate a temporary buffer for the complete ACL
2526 + acl_count = acc_acl->count + def_acl->count;
2527 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2529 + if (acl_buf == NULL) {
2530 + sys_acl_free_acl(tmp_acl);
2536 + * copy the access control and default entries into the buffer
2538 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2539 + acc_acl->count * sizeof(acl_buf[0]));
2541 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2542 + def_acl->count * sizeof(acl_buf[0]));
2545 + * set the ACL_DEFAULT flag on the default entries
2547 + for (i = acc_acl->count; i < acl_count; i++) {
2548 + acl_buf[i].a_type |= ACL_DEFAULT;
2551 + sys_acl_free_acl(tmp_acl);
2553 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2558 + ret = acl(name, SETACL, acl_count, acl_p);
2560 + SAFE_FREE(acl_buf);
2565 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2567 + if (acl_sort(acl_d) != 0) {
2571 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2574 +int sys_acl_delete_def_file(const char *path)
2580 + * fetching the access ACL and rewriting it has
2581 + * the effect of deleting the default ACL
2583 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2587 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2589 + sys_acl_free_acl(acl_d);
2594 +int sys_acl_free_text(char *text)
2600 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2606 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2611 +#elif defined(HAVE_HPUX_ACLS)
2615 + * Based on the Solaris/SCO code - with modifications.
2619 + * Note that while this code implements sufficient functionality
2620 + * to support the sys_acl_* interfaces it does not provide all
2621 + * of the semantics of the POSIX ACL interfaces.
2623 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2624 + * from a call to sys_acl_get_entry() should not be assumed to be
2625 + * valid after calling any of the following functions, which may
2626 + * reorder the entries in the ACL.
2629 + * sys_acl_set_file()
2630 + * sys_acl_set_fd()
2633 +/* This checks if the POSIX ACL system call is defined */
2634 +/* which basically corresponds to whether JFS 3.3 or */
2635 +/* higher is installed. If acl() was called when it */
2636 +/* isn't defined, it causes the process to core dump */
2637 +/* so it is important to check this and avoid acl() */
2638 +/* calls if it isn't there. */
2640 +static BOOL hpux_acl_call_presence(void)
2643 + shl_t handle = NULL;
2646 + static BOOL already_checked=0;
2648 + if(already_checked)
2652 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2654 + if(ret_val != 0) {
2655 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2656 + ret_val, errno, strerror(errno)));
2657 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2661 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2663 + already_checked = True;
2667 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2669 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2674 + if (entry_p == NULL) {
2679 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2683 + if (acl_d->next < 0) {
2688 + if (acl_d->next >= acl_d->count) {
2692 + *entry_p = &acl_d->acl[acl_d->next++];
2697 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2699 + *type_p = entry_d->a_type;
2704 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2706 + *permset_p = &entry_d->a_perm;
2711 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2713 + if (entry_d->a_type != SMB_ACL_USER
2714 + && entry_d->a_type != SMB_ACL_GROUP) {
2719 + return &entry_d->a_id;
2723 + * There is no way of knowing what size the ACL returned by
2724 + * ACL_GET will be unless you first call ACL_CNT which means
2725 + * making an additional system call.
2727 + * In the hope of avoiding the cost of the additional system
2728 + * call in most cases, we initially allocate enough space for
2729 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2730 + * be too small then we use ACL_CNT to find out the actual
2731 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2734 +#define INITIAL_ACL_SIZE 16
2736 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2739 + int count; /* # of ACL entries allocated */
2740 + int naccess; /* # of access ACL entries */
2741 + int ndefault; /* # of default ACL entries */
2743 + if(hpux_acl_call_presence() == False) {
2744 + /* Looks like we don't have the acl() system call on HPUX.
2745 + * May be the system doesn't have the latest version of JFS.
2750 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2755 + count = INITIAL_ACL_SIZE;
2756 + if ((acl_d = sys_acl_init(count)) == NULL) {
2761 + * If there isn't enough space for the ACL entries we use
2762 + * ACL_CNT to determine the actual number of ACL entries
2763 + * reallocate and try again. This is in a loop because it
2764 + * is possible that someone else could modify the ACL and
2765 + * increase the number of entries between the call to
2766 + * ACL_CNT and the call to ACL_GET.
2768 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2770 + sys_acl_free_acl(acl_d);
2772 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2776 + if ((acl_d = sys_acl_init(count)) == NULL) {
2782 + sys_acl_free_acl(acl_d);
2787 + * calculate the number of access and default ACL entries
2789 + * Note: we assume that the acl() system call returned a
2790 + * well formed ACL which is sorted so that all of the
2791 + * access ACL entries preceed any default ACL entries
2793 + for (naccess = 0; naccess < count; naccess++) {
2794 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2797 + ndefault = count - naccess;
2800 + * if the caller wants the default ACL we have to copy
2801 + * the entries down to the start of the acl[] buffer
2802 + * and mask out the ACL_DEFAULT flag from the type field
2804 + if (type == SMB_ACL_TYPE_DEFAULT) {
2807 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2808 + acl_d->acl[i] = acl_d->acl[j];
2809 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2812 + acl_d->count = ndefault;
2814 + acl_d->count = naccess;
2820 +SMB_ACL_T sys_acl_get_fd(int fd)
2823 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2826 + files_struct *fsp = file_find_fd(fd);
2828 + if (fsp == NULL) {
2834 + * We know we're in the same conn context. So we
2835 + * can use the relative path.
2838 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2841 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2848 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2850 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2851 + && perm != SMB_ACL_EXECUTE) {
2856 + if (permset_d == NULL) {
2861 + *permset_d |= perm;
2866 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2868 + return *permset_d & perm;
2871 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2878 + * use an initial estimate of 20 bytes per ACL entry
2879 + * when allocating memory for the text representation
2883 + maxlen = 20 * acl_d->count;
2884 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2889 + for (i = 0; i < acl_d->count; i++) {
2890 + struct acl *ap = &acl_d->acl[i];
2899 + switch (ap->a_type) {
2901 + * for debugging purposes it's probably more
2902 + * useful to dump unknown tag types rather
2903 + * than just returning an error
2906 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2909 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2914 + case SMB_ACL_USER:
2915 + id = uidtoname(ap->a_id);
2916 + case SMB_ACL_USER_OBJ:
2920 + case SMB_ACL_GROUP:
2921 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2922 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2928 + case SMB_ACL_GROUP_OBJ:
2932 + case SMB_ACL_OTHER:
2936 + case SMB_ACL_MASK:
2942 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2943 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2944 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2947 + /* <tag> : <qualifier> : rwx \n \0 */
2948 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2951 + * If this entry would overflow the buffer
2952 + * allocate enough additional memory for this
2953 + * entry and an estimate of another 20 bytes
2954 + * for each entry still to be processed
2956 + if ((len + nbytes) > maxlen) {
2957 + char *oldtext = text;
2959 + maxlen += nbytes + 20 * (acl_d->count - i);
2961 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2968 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2969 + len += nbytes - 1;
2978 +SMB_ACL_T sys_acl_init(int count)
2988 + * note that since the definition of the structure pointed
2989 + * to by the SMB_ACL_T includes the first element of the
2990 + * acl[] array, this actually allocates an ACL with room
2991 + * for (count+1) entries
2993 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2998 + a->size = count + 1;
3006 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3009 + SMB_ACL_ENTRY_T entry_d;
3011 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3016 + if (acl_d->count >= acl_d->size) {
3021 + entry_d = &acl_d->acl[acl_d->count++];
3022 + entry_d->a_type = 0;
3023 + entry_d->a_id = -1;
3024 + entry_d->a_perm = 0;
3025 + *entry_p = entry_d;
3030 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3032 + switch (tag_type) {
3033 + case SMB_ACL_USER:
3034 + case SMB_ACL_USER_OBJ:
3035 + case SMB_ACL_GROUP:
3036 + case SMB_ACL_GROUP_OBJ:
3037 + case SMB_ACL_OTHER:
3038 + case SMB_ACL_MASK:
3039 + entry_d->a_type = tag_type;
3049 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3051 + if (entry_d->a_type != SMB_ACL_GROUP
3052 + && entry_d->a_type != SMB_ACL_USER) {
3057 + entry_d->a_id = *((id_t *)qual_p);
3062 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3064 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3068 + entry_d->a_perm = *permset_d;
3073 +/* Structure to capture the count for each type of ACE. */
3075 +struct hpux_acl_types {
3079 + int n_def_user_obj;
3084 + int n_def_group_obj;
3088 + int n_def_other_obj;
3091 + int n_def_class_obj;
3093 + int n_illegal_obj;
3097 + * Counts the different number of objects in a given array of ACL
3101 + * acl_count - Count of ACLs in the array of ACL strucutres.
3102 + * aclp - Array of ACL structures.
3103 + * acl_type_count - Pointer to acl_types structure. Should already be
3107 + * acl_type_count - This structure is filled up with counts of various
3111 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3115 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3117 + for(i=0;i<acl_count;i++) {
3118 + switch(aclp[i].a_type) {
3120 + acl_type_count->n_user++;
3123 + acl_type_count->n_user_obj++;
3125 + case DEF_USER_OBJ:
3126 + acl_type_count->n_def_user_obj++;
3129 + acl_type_count->n_group++;
3132 + acl_type_count->n_group_obj++;
3134 + case DEF_GROUP_OBJ:
3135 + acl_type_count->n_def_group_obj++;
3138 + acl_type_count->n_other_obj++;
3140 + case DEF_OTHER_OBJ:
3141 + acl_type_count->n_def_other_obj++;
3144 + acl_type_count->n_class_obj++;
3146 + case DEF_CLASS_OBJ:
3147 + acl_type_count->n_def_class_obj++;
3150 + acl_type_count->n_def_user++;
3153 + acl_type_count->n_def_group++;
3156 + acl_type_count->n_illegal_obj++;
3162 +/* swap_acl_entries: Swaps two ACL entries.
3164 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3167 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3169 + struct acl temp_acl;
3171 + temp_acl.a_type = aclp0->a_type;
3172 + temp_acl.a_id = aclp0->a_id;
3173 + temp_acl.a_perm = aclp0->a_perm;
3175 + aclp0->a_type = aclp1->a_type;
3176 + aclp0->a_id = aclp1->a_id;
3177 + aclp0->a_perm = aclp1->a_perm;
3179 + aclp1->a_type = temp_acl.a_type;
3180 + aclp1->a_id = temp_acl.a_id;
3181 + aclp1->a_perm = temp_acl.a_perm;
3184 +/* prohibited_duplicate_type
3185 + * Identifies if given ACL type can have duplicate entries or
3188 + * Inputs: acl_type - ACL Type.
3194 + * True - If the ACL type matches any of the prohibited types.
3195 + * False - If the ACL type doesn't match any of the prohibited types.
3198 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3200 + switch(acl_type) {
3211 +/* get_needed_class_perm
3212 + * Returns the permissions of a ACL structure only if the ACL
3213 + * type matches one of the pre-determined types for computing
3214 + * CLASS_OBJ permissions.
3216 + * Inputs: aclp - Pointer to ACL structure.
3219 +static int hpux_get_needed_class_perm(struct acl *aclp)
3221 + switch(aclp->a_type) {
3225 + case DEF_USER_OBJ:
3227 + case DEF_GROUP_OBJ:
3229 + case DEF_CLASS_OBJ:
3230 + case DEF_OTHER_OBJ:
3231 + return aclp->a_perm;
3237 +/* acl_sort for HPUX.
3238 + * Sorts the array of ACL structures as per the description in
3239 + * aclsort man page. Refer to aclsort man page for more details
3243 + * acl_count - Count of ACLs in the array of ACL structures.
3244 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3246 + * aclp - Array of ACL structures.
3250 + * aclp - Sorted array of ACL structures.
3254 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3255 + * debug log in case of failure.
3258 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3260 +#if !defined(HAVE_HPUX_ACLSORT)
3262 + * The aclsort() system call is availabe on the latest HPUX General
3263 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3264 + * function. Because, we don't want to update to a new
3265 + * HPUX GR bundle just for aclsort() call.
3268 + struct hpux_acl_types acl_obj_count;
3269 + int n_class_obj_perm = 0;
3273 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3277 + if(aclp == NULL) {
3278 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3282 + /* Count different types of ACLs in the ACLs array */
3284 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3286 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3287 + * CLASS_OBJ and OTHER_OBJ
3290 + if( (acl_obj_count.n_user_obj != 1) ||
3291 + (acl_obj_count.n_group_obj != 1) ||
3292 + (acl_obj_count.n_class_obj != 1) ||
3293 + (acl_obj_count.n_other_obj != 1)
3295 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3296 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3300 + /* If any of the default objects are present, there should be only
3301 + * one of them each.
3304 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3305 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3306 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3307 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3311 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3314 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3315 + * same ACL type, sort by ACL id.
3317 + * I am using the trival kind of sorting method here because, performance isn't
3318 + * really effected by the ACLs feature. More over there aren't going to be more
3319 + * than 17 entries on HPUX.
3322 + for(i=0; i<acl_count;i++) {
3323 + for (j=i+1; j<acl_count; j++) {
3324 + if( aclp[i].a_type > aclp[j].a_type ) {
3325 + /* ACL entries out of order, swap them */
3327 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3329 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3331 + /* ACL entries of same type, sort by id */
3333 + if(aclp[i].a_id > aclp[j].a_id) {
3334 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3335 + } else if (aclp[i].a_id == aclp[j].a_id) {
3336 + /* We have a duplicate entry. */
3337 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3338 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3339 + aclp[i].a_type, aclp[i].a_id));
3348 + /* set the class obj permissions to the computed one. */
3350 + int n_class_obj_index = -1;
3352 + for(i=0;i<acl_count;i++) {
3353 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3355 + if(aclp[i].a_type == CLASS_OBJ)
3356 + n_class_obj_index = i;
3358 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3363 + return aclsort(acl_count, calclass, aclp);
3368 + * sort the ACL and check it for validity
3370 + * if it's a minimal ACL with only 4 entries then we
3371 + * need to recalculate the mask permissions to make
3372 + * sure that they are the same as the GROUP_OBJ
3373 + * permissions as required by the UnixWare acl() system call.
3375 + * (note: since POSIX allows minimal ACLs which only contain
3376 + * 3 entries - ie there is no mask entry - we should, in theory,
3377 + * check for this and add a mask entry if necessary - however
3378 + * we "know" that the caller of this interface always specifies
3379 + * a mask so, in practice "this never happens" (tm) - if it *does*
3380 + * happen aclsort() will fail and return an error and someone will
3381 + * have to fix it ...)
3384 +static int acl_sort(SMB_ACL_T acl_d)
3386 + int fixmask = (acl_d->count <= 4);
3388 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3395 +int sys_acl_valid(SMB_ACL_T acl_d)
3397 + return acl_sort(acl_d);
3400 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3403 + struct acl *acl_p;
3405 + struct acl *acl_buf = NULL;
3408 + if(hpux_acl_call_presence() == False) {
3409 + /* Looks like we don't have the acl() system call on HPUX.
3410 + * May be the system doesn't have the latest version of JFS.
3416 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3421 + if (acl_sort(acl_d) != 0) {
3425 + acl_p = &acl_d->acl[0];
3426 + acl_count = acl_d->count;
3429 + * if it's a directory there is extra work to do
3430 + * since the acl() system call will replace both
3431 + * the access ACLs and the default ACLs (if any)
3433 + if (stat(name, &s) != 0) {
3436 + if (S_ISDIR(s.st_mode)) {
3437 + SMB_ACL_T acc_acl;
3438 + SMB_ACL_T def_acl;
3439 + SMB_ACL_T tmp_acl;
3442 + if (type == SMB_ACL_TYPE_ACCESS) {
3444 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3448 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3451 + if (tmp_acl == NULL) {
3456 + * allocate a temporary buffer for the complete ACL
3458 + acl_count = acc_acl->count + def_acl->count;
3459 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3461 + if (acl_buf == NULL) {
3462 + sys_acl_free_acl(tmp_acl);
3468 + * copy the access control and default entries into the buffer
3470 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3471 + acc_acl->count * sizeof(acl_buf[0]));
3473 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3474 + def_acl->count * sizeof(acl_buf[0]));
3477 + * set the ACL_DEFAULT flag on the default entries
3479 + for (i = acc_acl->count; i < acl_count; i++) {
3480 + acl_buf[i].a_type |= ACL_DEFAULT;
3483 + sys_acl_free_acl(tmp_acl);
3485 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3490 + ret = acl(name, ACL_SET, acl_count, acl_p);
3499 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3502 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3505 + files_struct *fsp = file_find_fd(fd);
3507 + if (fsp == NULL) {
3512 + if (acl_sort(acl_d) != 0) {
3517 + * We know we're in the same conn context. So we
3518 + * can use the relative path.
3521 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3524 +int sys_acl_delete_def_file(const char *path)
3530 + * fetching the access ACL and rewriting it has
3531 + * the effect of deleting the default ACL
3533 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3537 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3539 + sys_acl_free_acl(acl_d);
3544 +int sys_acl_free_text(char *text)
3550 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3556 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3561 +#elif defined(HAVE_IRIX_ACLS)
3563 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3565 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3570 + if (entry_p == NULL) {
3575 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3579 + if (acl_d->next < 0) {
3584 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3588 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3593 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3595 + *type_p = entry_d->ae_tag;
3600 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3602 + *permset_p = entry_d;
3607 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3609 + if (entry_d->ae_tag != SMB_ACL_USER
3610 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3615 + return &entry_d->ae_id;
3618 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3622 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3626 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3631 + a->freeaclp = True;
3635 +SMB_ACL_T sys_acl_get_fd(int fd)
3639 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3643 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3648 + a->freeaclp = True;
3652 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3654 + permset_d->ae_perm = 0;
3659 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3661 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3662 + && perm != SMB_ACL_EXECUTE) {
3667 + if (permset_d == NULL) {
3672 + permset_d->ae_perm |= perm;
3677 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3679 + return permset_d->ae_perm & perm;
3682 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3684 + return acl_to_text(acl_d->aclp, len_p);
3687 +SMB_ACL_T sys_acl_init(int count)
3696 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3702 + a->freeaclp = False;
3703 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3704 + a->aclp->acl_cnt = 0;
3710 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3713 + SMB_ACL_ENTRY_T entry_d;
3715 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3720 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3725 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3726 + entry_d->ae_tag = 0;
3727 + entry_d->ae_id = 0;
3728 + entry_d->ae_perm = 0;
3729 + *entry_p = entry_d;
3734 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3736 + switch (tag_type) {
3737 + case SMB_ACL_USER:
3738 + case SMB_ACL_USER_OBJ:
3739 + case SMB_ACL_GROUP:
3740 + case SMB_ACL_GROUP_OBJ:
3741 + case SMB_ACL_OTHER:
3742 + case SMB_ACL_MASK:
3743 + entry_d->ae_tag = tag_type;
3753 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3755 + if (entry_d->ae_tag != SMB_ACL_GROUP
3756 + && entry_d->ae_tag != SMB_ACL_USER) {
3761 + entry_d->ae_id = *((id_t *)qual_p);
3766 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3768 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3772 + entry_d->ae_perm = permset_d->ae_perm;
3777 +int sys_acl_valid(SMB_ACL_T acl_d)
3779 + return acl_valid(acl_d->aclp);
3782 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3784 + return acl_set_file(name, type, acl_d->aclp);
3787 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3789 + return acl_set_fd(fd, acl_d->aclp);
3792 +int sys_acl_delete_def_file(const char *name)
3794 + return acl_delete_def_file(name);
3797 +int sys_acl_free_text(char *text)
3799 + return acl_free(text);
3802 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3804 + if (acl_d->freeaclp) {
3805 + acl_free(acl_d->aclp);
3811 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3816 +#elif defined(HAVE_AIX_ACLS)
3818 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3820 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3822 + struct acl_entry_link *link;
3823 + struct new_acl_entry *entry;
3826 + DEBUG(10,("This is the count: %d\n",theacl->count));
3828 + /* Check if count was previously set to -1. *
3829 + * If it was, that means we reached the end *
3830 + * of the acl last time. */
3831 + if(theacl->count == -1)
3835 + /* To get to the next acl, traverse linked list until index *
3836 + * of acl matches the count we are keeping. This count is *
3837 + * incremented each time we return an acl entry. */
3839 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3840 + link = link->nextp;
3842 + entry = *entry_p = link->entryp;
3844 + DEBUG(10,("*entry_p is %d\n",entry_p));
3845 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3847 + /* Increment count */
3849 + if(link->nextp == NULL)
3850 + theacl->count = -1;
3855 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3857 + /* Initialize tag type */
3860 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3862 + /* Depending on what type of entry we have, *
3863 + * return tag type. */
3864 + switch(entry_d->ace_id->id_type) {
3866 + *tag_type_p = SMB_ACL_USER;
3869 + *tag_type_p = SMB_ACL_GROUP;
3872 + case SMB_ACL_USER_OBJ:
3873 + case SMB_ACL_GROUP_OBJ:
3874 + case SMB_ACL_OTHER:
3875 + *tag_type_p = entry_d->ace_id->id_type;
3885 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3887 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3888 + *permset_p = &entry_d->ace_access;
3889 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3890 + if(!(**permset_p & S_IXUSR) &&
3891 + !(**permset_p & S_IWUSR) &&
3892 + !(**permset_p & S_IRUSR) &&
3893 + (**permset_p != 0))
3896 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3900 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3902 + return(entry_d->ace_id->id_data);
3905 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3907 + struct acl *file_acl = (struct acl *)NULL;
3908 + struct acl_entry *acl_entry;
3909 + struct new_acl_entry *new_acl_entry;
3910 + struct ace_id *idp;
3911 + struct acl_entry_link *acl_entry_link;
3912 + struct acl_entry_link *acl_entry_link_head;
3917 + /* AIX has no DEFAULT */
3918 + if ( type == SMB_ACL_TYPE_DEFAULT )
3921 + /* Get the acl using statacl */
3923 + DEBUG(10,("Entering sys_acl_get_file\n"));
3924 + DEBUG(10,("path_p is %s\n",path_p));
3926 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3928 + if(file_acl == NULL) {
3930 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3934 + memset(file_acl,0,BUFSIZ);
3936 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3938 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3939 + SAFE_FREE(file_acl);
3943 + DEBUG(10,("Got facl and returned it\n"));
3945 + /* Point to the first acl entry in the acl */
3946 + acl_entry = file_acl->acl_ext;
3948 + /* Begin setting up the head of the linked list *
3949 + * that will be used for the storing the acl *
3950 + * in a way that is useful for the posix_acls.c *
3953 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3954 + if(acl_entry_link_head == NULL)
3957 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3958 + if(acl_entry_link->entryp == NULL) {
3959 + SAFE_FREE(file_acl);
3961 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3965 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3966 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3968 + /* Check if the extended acl bit is on. *
3969 + * If it isn't, do not show the *
3970 + * contents of the acl since AIX intends *
3971 + * the extended info to remain unused */
3973 + if(file_acl->acl_mode & S_IXACL){
3974 + /* while we are not pointing to the very end */
3975 + while(acl_entry < acl_last(file_acl)) {
3976 + /* before we malloc anything, make sure this is */
3977 + /* a valid acl entry and one that we want to map */
3978 + idp = id_nxt(acl_entry->ace_id);
3979 + if((acl_entry->ace_type == ACC_SPECIFY ||
3980 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3981 + acl_entry = acl_nxt(acl_entry);
3985 + idp = acl_entry->ace_id;
3987 + /* Check if this is the first entry in the linked list. *
3988 + * The first entry needs to keep prevp pointing to NULL *
3989 + * and already has entryp allocated. */
3991 + if(acl_entry_link_head->count != 0) {
3992 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3994 + if(acl_entry_link->nextp == NULL) {
3995 + SAFE_FREE(file_acl);
3997 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4001 + acl_entry_link->nextp->prevp = acl_entry_link;
4002 + acl_entry_link = acl_entry_link->nextp;
4003 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4004 + if(acl_entry_link->entryp == NULL) {
4005 + SAFE_FREE(file_acl);
4007 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4010 + acl_entry_link->nextp = NULL;
4013 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4015 + /* Don't really need this since all types are going *
4016 + * to be specified but, it's better than leaving it 0 */
4018 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4020 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4022 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4024 + /* The access in the acl entries must be left shifted by *
4025 + * three bites, because they will ultimately be compared *
4026 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4028 + switch(acl_entry->ace_type){
4031 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4032 + acl_entry_link->entryp->ace_access <<= 6;
4033 + acl_entry_link_head->count++;
4036 + /* Since there is no way to return a DENY acl entry *
4037 + * change to PERMIT and then shift. */
4038 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4039 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4040 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4041 + acl_entry_link->entryp->ace_access <<= 6;
4042 + acl_entry_link_head->count++;
4048 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4049 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4051 + acl_entry = acl_nxt(acl_entry);
4053 + } /* end of if enabled */
4055 + /* Since owner, group, other acl entries are not *
4056 + * part of the acl entries in an acl, they must *
4057 + * be dummied up to become part of the list. */
4059 + for( i = 1; i < 4; i++) {
4060 + DEBUG(10,("i is %d\n",i));
4061 + if(acl_entry_link_head->count != 0) {
4062 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4063 + if(acl_entry_link->nextp == NULL) {
4064 + SAFE_FREE(file_acl);
4066 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4070 + acl_entry_link->nextp->prevp = acl_entry_link;
4071 + acl_entry_link = acl_entry_link->nextp;
4072 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4073 + if(acl_entry_link->entryp == NULL) {
4074 + SAFE_FREE(file_acl);
4076 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4081 + acl_entry_link->nextp = NULL;
4083 + new_acl_entry = acl_entry_link->entryp;
4084 + idp = new_acl_entry->ace_id;
4086 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4087 + new_acl_entry->ace_type = ACC_PERMIT;
4088 + idp->id_len = sizeof(struct ace_id);
4089 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4090 + memset(idp->id_data,0,sizeof(uid_t));
4094 + new_acl_entry->ace_access = file_acl->g_access << 6;
4095 + idp->id_type = SMB_ACL_GROUP_OBJ;
4099 + new_acl_entry->ace_access = file_acl->o_access << 6;
4100 + idp->id_type = SMB_ACL_OTHER;
4104 + new_acl_entry->ace_access = file_acl->u_access << 6;
4105 + idp->id_type = SMB_ACL_USER_OBJ;
4113 + acl_entry_link_head->count++;
4114 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4117 + acl_entry_link_head->count = 0;
4118 + SAFE_FREE(file_acl);
4120 + return(acl_entry_link_head);
4123 +SMB_ACL_T sys_acl_get_fd(int fd)
4125 + struct acl *file_acl = (struct acl *)NULL;
4126 + struct acl_entry *acl_entry;
4127 + struct new_acl_entry *new_acl_entry;
4128 + struct ace_id *idp;
4129 + struct acl_entry_link *acl_entry_link;
4130 + struct acl_entry_link *acl_entry_link_head;
4135 + /* Get the acl using fstatacl */
4137 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4138 + DEBUG(10,("fd is %d\n",fd));
4139 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4141 + if(file_acl == NULL) {
4143 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4147 + memset(file_acl,0,BUFSIZ);
4149 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4151 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4152 + SAFE_FREE(file_acl);
4156 + DEBUG(10,("Got facl and returned it\n"));
4158 + /* Point to the first acl entry in the acl */
4160 + acl_entry = file_acl->acl_ext;
4161 + /* Begin setting up the head of the linked list *
4162 + * that will be used for the storing the acl *
4163 + * in a way that is useful for the posix_acls.c *
4166 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4167 + if(acl_entry_link_head == NULL){
4168 + SAFE_FREE(file_acl);
4172 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4174 + if(acl_entry_link->entryp == NULL) {
4176 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4177 + SAFE_FREE(file_acl);
4181 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4182 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4184 + /* Check if the extended acl bit is on. *
4185 + * If it isn't, do not show the *
4186 + * contents of the acl since AIX intends *
4187 + * the extended info to remain unused */
4189 + if(file_acl->acl_mode & S_IXACL){
4190 + /* while we are not pointing to the very end */
4191 + while(acl_entry < acl_last(file_acl)) {
4192 + /* before we malloc anything, make sure this is */
4193 + /* a valid acl entry and one that we want to map */
4195 + idp = id_nxt(acl_entry->ace_id);
4196 + if((acl_entry->ace_type == ACC_SPECIFY ||
4197 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4198 + acl_entry = acl_nxt(acl_entry);
4202 + idp = acl_entry->ace_id;
4204 + /* Check if this is the first entry in the linked list. *
4205 + * The first entry needs to keep prevp pointing to NULL *
4206 + * and already has entryp allocated. */
4208 + if(acl_entry_link_head->count != 0) {
4209 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4210 + if(acl_entry_link->nextp == NULL) {
4212 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4213 + SAFE_FREE(file_acl);
4216 + acl_entry_link->nextp->prevp = acl_entry_link;
4217 + acl_entry_link = acl_entry_link->nextp;
4218 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4219 + if(acl_entry_link->entryp == NULL) {
4221 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4222 + SAFE_FREE(file_acl);
4226 + acl_entry_link->nextp = NULL;
4229 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4231 + /* Don't really need this since all types are going *
4232 + * to be specified but, it's better than leaving it 0 */
4234 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4235 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4237 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4239 + /* The access in the acl entries must be left shifted by *
4240 + * three bites, because they will ultimately be compared *
4241 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4243 + switch(acl_entry->ace_type){
4246 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4247 + acl_entry_link->entryp->ace_access <<= 6;
4248 + acl_entry_link_head->count++;
4251 + /* Since there is no way to return a DENY acl entry *
4252 + * change to PERMIT and then shift. */
4253 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4254 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4255 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4256 + acl_entry_link->entryp->ace_access <<= 6;
4257 + acl_entry_link_head->count++;
4263 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4264 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4266 + acl_entry = acl_nxt(acl_entry);
4268 + } /* end of if enabled */
4270 + /* Since owner, group, other acl entries are not *
4271 + * part of the acl entries in an acl, they must *
4272 + * be dummied up to become part of the list. */
4274 + for( i = 1; i < 4; i++) {
4275 + DEBUG(10,("i is %d\n",i));
4276 + if(acl_entry_link_head->count != 0){
4277 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4278 + if(acl_entry_link->nextp == NULL) {
4280 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4281 + SAFE_FREE(file_acl);
4285 + acl_entry_link->nextp->prevp = acl_entry_link;
4286 + acl_entry_link = acl_entry_link->nextp;
4287 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4289 + if(acl_entry_link->entryp == NULL) {
4290 + SAFE_FREE(file_acl);
4292 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4297 + acl_entry_link->nextp = NULL;
4299 + new_acl_entry = acl_entry_link->entryp;
4300 + idp = new_acl_entry->ace_id;
4302 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4303 + new_acl_entry->ace_type = ACC_PERMIT;
4304 + idp->id_len = sizeof(struct ace_id);
4305 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4306 + memset(idp->id_data,0,sizeof(uid_t));
4310 + new_acl_entry->ace_access = file_acl->g_access << 6;
4311 + idp->id_type = SMB_ACL_GROUP_OBJ;
4315 + new_acl_entry->ace_access = file_acl->o_access << 6;
4316 + idp->id_type = SMB_ACL_OTHER;
4320 + new_acl_entry->ace_access = file_acl->u_access << 6;
4321 + idp->id_type = SMB_ACL_USER_OBJ;
4328 + acl_entry_link_head->count++;
4329 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4332 + acl_entry_link_head->count = 0;
4333 + SAFE_FREE(file_acl);
4335 + return(acl_entry_link_head);
4338 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4340 + *permset = *permset & ~0777;
4344 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4347 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4351 + DEBUG(10,("This is the permset now: %d\n",*permset));
4355 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4360 +SMB_ACL_T sys_acl_init( int count)
4362 + struct acl_entry_link *theacl = NULL;
4364 + DEBUG(10,("Entering sys_acl_init\n"));
4366 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4367 + if(theacl == NULL) {
4369 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4373 + theacl->count = 0;
4374 + theacl->nextp = NULL;
4375 + theacl->prevp = NULL;
4376 + theacl->entryp = NULL;
4377 + DEBUG(10,("Exiting sys_acl_init\n"));
4381 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4383 + struct acl_entry_link *theacl;
4384 + struct acl_entry_link *acl_entryp;
4385 + struct acl_entry_link *temp_entry;
4388 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4390 + theacl = acl_entryp = *pacl;
4392 + /* Get to the end of the acl before adding entry */
4394 + for(counting=0; counting < theacl->count; counting++){
4395 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4396 + temp_entry = acl_entryp;
4397 + acl_entryp = acl_entryp->nextp;
4400 + if(theacl->count != 0){
4401 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4402 + if(acl_entryp == NULL) {
4404 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4408 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4409 + acl_entryp->prevp = temp_entry;
4410 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4413 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4414 + if(*pentry == NULL) {
4416 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4420 + memset(*pentry,0,sizeof(struct new_acl_entry));
4421 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4422 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4423 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4424 + acl_entryp->nextp = NULL;
4426 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4430 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4432 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4433 + entry->ace_id->id_type = tagtype;
4434 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4435 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4438 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4440 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4441 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4442 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4446 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4448 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4449 + if(!(*permset & S_IXUSR) &&
4450 + !(*permset & S_IWUSR) &&
4451 + !(*permset & S_IRUSR) &&
4455 + entry->ace_access = *permset;
4456 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4457 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4461 +int sys_acl_valid( SMB_ACL_T theacl )
4464 + int group_obj = 0;
4465 + int other_obj = 0;
4466 + struct acl_entry_link *acl_entry;
4468 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4469 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4470 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4471 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4474 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4476 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4482 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4484 + struct acl_entry_link *acl_entry_link = NULL;
4485 + struct acl *file_acl = NULL;
4486 + struct acl *file_acl_temp = NULL;
4487 + struct acl_entry *acl_entry = NULL;
4488 + struct ace_id *ace_id = NULL;
4495 + DEBUG(10,("Entering sys_acl_set_file\n"));
4496 + DEBUG(10,("File name is %s\n",name));
4498 + /* AIX has no default ACL */
4499 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4502 + acl_length = BUFSIZ;
4503 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4505 + if(file_acl == NULL) {
4507 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4511 + memset(file_acl,0,BUFSIZ);
4513 + file_acl->acl_len = ACL_SIZ;
4514 + file_acl->acl_mode = S_IXACL;
4516 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4517 + acl_entry_link->entryp->ace_access >>= 6;
4518 + id_type = acl_entry_link->entryp->ace_id->id_type;
4521 + case SMB_ACL_USER_OBJ:
4522 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4524 + case SMB_ACL_GROUP_OBJ:
4525 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4527 + case SMB_ACL_OTHER:
4528 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4530 + case SMB_ACL_MASK:
4534 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4535 + acl_length += sizeof(struct acl_entry);
4536 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4537 + if(file_acl_temp == NULL) {
4538 + SAFE_FREE(file_acl);
4540 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4544 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4545 + SAFE_FREE(file_acl);
4546 + file_acl = file_acl_temp;
4549 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4550 + file_acl->acl_len += sizeof(struct acl_entry);
4551 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4552 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4554 + /* In order to use this, we'll need to wait until we can get denies */
4555 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4556 + acl_entry->ace_type = ACC_SPECIFY; */
4558 + acl_entry->ace_type = ACC_SPECIFY;
4560 + ace_id = acl_entry->ace_id;
4562 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4563 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4564 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4565 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4566 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4569 + rc = chacl(name,file_acl,file_acl->acl_len);
4570 + DEBUG(10,("errno is %d\n",errno));
4571 + DEBUG(10,("return code is %d\n",rc));
4572 + SAFE_FREE(file_acl);
4573 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4577 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4579 + struct acl_entry_link *acl_entry_link = NULL;
4580 + struct acl *file_acl = NULL;
4581 + struct acl *file_acl_temp = NULL;
4582 + struct acl_entry *acl_entry = NULL;
4583 + struct ace_id *ace_id = NULL;
4589 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4590 + acl_length = BUFSIZ;
4591 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4593 + if(file_acl == NULL) {
4595 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4599 + memset(file_acl,0,BUFSIZ);
4601 + file_acl->acl_len = ACL_SIZ;
4602 + file_acl->acl_mode = S_IXACL;
4604 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4605 + acl_entry_link->entryp->ace_access >>= 6;
4606 + id_type = acl_entry_link->entryp->ace_id->id_type;
4607 + DEBUG(10,("The id_type is %d\n",id_type));
4610 + case SMB_ACL_USER_OBJ:
4611 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4613 + case SMB_ACL_GROUP_OBJ:
4614 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4616 + case SMB_ACL_OTHER:
4617 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4619 + case SMB_ACL_MASK:
4623 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4624 + acl_length += sizeof(struct acl_entry);
4625 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4626 + if(file_acl_temp == NULL) {
4627 + SAFE_FREE(file_acl);
4629 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4633 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4634 + SAFE_FREE(file_acl);
4635 + file_acl = file_acl_temp;
4638 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4639 + file_acl->acl_len += sizeof(struct acl_entry);
4640 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4641 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4643 + /* In order to use this, we'll need to wait until we can get denies */
4644 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4645 + acl_entry->ace_type = ACC_SPECIFY; */
4647 + acl_entry->ace_type = ACC_SPECIFY;
4649 + ace_id = acl_entry->ace_id;
4651 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4652 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4653 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4654 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4655 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4658 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4659 + DEBUG(10,("errno is %d\n",errno));
4660 + DEBUG(10,("return code is %d\n",rc));
4661 + SAFE_FREE(file_acl);
4662 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4666 +int sys_acl_delete_def_file(const char *name)
4668 + /* AIX has no default ACL */
4672 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4674 + return(*permset & perm);
4677 +int sys_acl_free_text(char *text)
4682 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4684 + struct acl_entry_link *acl_entry_link;
4686 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4687 + SAFE_FREE(acl_entry_link->prevp->entryp);
4688 + SAFE_FREE(acl_entry_link->prevp);
4691 + SAFE_FREE(acl_entry_link->prevp->entryp);
4692 + SAFE_FREE(acl_entry_link->prevp);
4693 + SAFE_FREE(acl_entry_link->entryp);
4694 + SAFE_FREE(acl_entry_link);
4699 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4704 +#else /* No ACLs. */
4706 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4712 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4718 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4724 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4730 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4733 + return (SMB_ACL_T)NULL;
4736 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4739 + return (SMB_ACL_T)NULL;
4742 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4748 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4754 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4757 + return (permset & perm) ? 1 : 0;
4760 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4766 +int sys_acl_free_text(UNUSED(char *text))
4772 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4778 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4784 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4790 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4796 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4802 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4808 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4814 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4820 +int sys_acl_delete_def_file(UNUSED(const char *name))
4826 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4832 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4838 +#endif /* No ACLs. */
4840 +/************************************************************************
4841 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4843 +************************************************************************/
4845 +int no_acl_syscall_error(int err)
4847 +#if defined(ENOSYS)
4848 + if (err == ENOSYS) {
4852 +#if defined(ENOTSUP)
4853 + if (err == ENOTSUP) {
4859 --- old/lib/sysacls.h
4860 +++ new/lib/sysacls.h
4862 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4863 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4864 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4865 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4866 +#define slprintf snprintf
4868 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4869 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4870 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4871 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4872 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4873 +SMB_ACL_T sys_acl_get_fd(int fd);
4874 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4875 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4876 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4877 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4878 +SMB_ACL_T sys_acl_init(int count);
4879 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4880 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4881 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4882 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4883 +int sys_acl_valid(SMB_ACL_T theacl);
4884 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4885 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4886 +int sys_acl_delete_def_file(const char *name);
4887 +int sys_acl_free_text(char *text);
4888 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4889 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4892 @@ -58,7 +58,7 @@ BEGIN {
4896 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4897 +!/^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/ {
4903 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
4905 int preserve_links = 0;
4906 int preserve_hard_links = 0;
4907 +int preserve_acls = 0;
4908 int preserve_perms = 0;
4909 int preserve_executability = 0;
4910 int preserve_devices = 0;
4911 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4912 char const *got_socketpair = "no ";
4913 char const *have_inplace = "no ";
4914 char const *hardlinks = "no ";
4915 + char const *acls = "no ";
4916 char const *links = "no ";
4917 char const *ipv6 = "no ";
4918 STRUCT_STAT *dumstat;
4919 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4923 +#ifdef SUPPORT_ACLS
4927 #ifdef SUPPORT_LINKS
4930 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4931 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4932 rprintf(f, "<http://rsync.samba.org/>\n");
4933 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4934 - "%shard links, %ssymlinks, batchfiles,\n",
4935 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4936 (int) (sizeof (OFF_T) * 8),
4937 - got_socketpair, hardlinks, links);
4938 + got_socketpair, hardlinks, acls, links);
4940 /* Note that this field may not have type ino_t. It depends
4941 * on the complicated interaction between largefile feature
4942 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4943 rprintf(F," -H, --hard-links preserve hard links\n");
4944 rprintf(F," -p, --perms preserve permissions\n");
4945 rprintf(F," -E, --executability preserve the file's executability\n");
4946 +#ifdef SUPPORT_ACLS
4947 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4949 rprintf(F," --chmod=CHMOD change destination permissions\n");
4950 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4951 rprintf(F," -g, --group preserve group\n");
4952 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4953 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4954 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4955 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4956 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4957 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4958 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4959 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4960 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4961 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4962 @@ -1070,6 +1082,24 @@ int parse_arguments(int *argc, const cha
4967 +#ifdef SUPPORT_ACLS
4969 + preserve_perms = 1;
4972 + /* FIXME: this should probably be ignored with a
4973 + * warning and then countermeasures taken to
4974 + * restrict group and other access in the presence
4975 + * of any more restrictive ACLs, but this is safe
4977 + snprintf(err_buf,sizeof(err_buf),
4978 + "ACLs are not supported on this %s\n",
4979 + am_server ? "server" : "client");
4985 /* A large opt value means that set_refuse_options()
4986 * turned this option off. */
4987 @@ -1504,6 +1534,10 @@ void server_options(char **args,int *arg
4989 if (preserve_hard_links)
4991 +#ifdef SUPPORT_ACLS
4992 + if (preserve_acls)
4993 + argstr[x++] = 'A';
5000 @@ -48,6 +48,7 @@ extern int keep_partial;
5001 extern int checksum_seed;
5003 extern int delay_updates;
5004 +extern mode_t orig_umask;
5005 extern struct stats stats;
5006 extern char *log_format;
5007 extern char *tmpdir;
5008 @@ -346,6 +347,10 @@ int recv_files(int f_in, struct file_lis
5009 int itemizing = am_daemon ? daemon_log_format_has_i
5010 : !am_server && log_format_has_i;
5011 int max_phase = protocol_version >= 29 ? 2 : 1;
5012 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5013 +#ifdef SUPPORT_ACLS
5014 + char *parent_dirname = "";
5019 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5020 * mode based on the local permissions and some heuristics. */
5021 if (!preserve_perms) {
5022 int exists = fd1 != -1;
5023 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5024 +#ifdef SUPPORT_ACLS
5025 + char *dn = file->dirname ? file->dirname : ".";
5026 + if (parent_dirname != dn
5027 + && strcmp(parent_dirname, dn) != 0) {
5028 + dflt_perms = default_perms_for_dir(dn);
5029 + parent_dirname = dn;
5032 + file->mode = dest_mode(file->mode, st.st_mode,
5033 + dflt_perms, exists);
5036 /* We now check to see if we are writing file "inplace" */
5042 extern int daemon_log_format_has_i;
5043 +extern int preserve_acls;
5044 extern int preserve_perms;
5045 extern int preserve_executability;
5046 extern int preserve_times;
5047 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5049 /* This is only called when we aren't preserving permissions. Figure out what
5050 * the permissions should be and return them merged back into the mode. */
5051 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5052 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5055 /* If the file already exists, we'll return the local permissions,
5056 * possibly tweaked by the --executability option. */
5057 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
5058 cur_mode |= (cur_mode & 0444) >> 2;
5061 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5062 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5063 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5064 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5065 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5066 @@ -203,6 +205,17 @@ int set_file_attrs(char *fname, struct f
5070 +#ifdef SUPPORT_ACLS
5071 + /* It's OK to call set_acl() now, even for a dir, as the generator
5072 + * will enable owner-writability using chmod, if necessary.
5074 + * If set_acl changes permission bits in the process of setting
5075 + * an access ACL, it changes st->st_mode so we know whether we
5076 + * need to chmod. */
5077 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5082 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5083 int ret = do_chmod(fname, file->mode);
5086 @@ -660,6 +660,20 @@ struct chmod_mode_struct;
5088 #define UNUSED(x) x __attribute__((__unused__))
5090 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5091 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5092 +#define SUPPORT_ACLS 1
5095 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5096 +#define ACLS_NEED_MASK 1
5099 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5100 +#include <sys/acl.h>
5102 +#include "smb_acls.h"
5106 /* We have replacement versions of these if they're missing. */
5109 @@ -321,6 +321,7 @@ to the detailed description below for a
5110 -H, --hard-links preserve hard links
5111 -p, --perms preserve permissions
5112 -E, --executability preserve executability
5113 + -A, --acls preserve ACLs (implies -p) [non-standard]
5114 --chmod=CHMOD change destination permissions
5115 -o, --owner preserve owner (super-user only)
5116 -g, --group preserve group
5117 @@ -742,7 +743,9 @@ quote(itemize(
5118 permissions, though the bf(--executability) option might change just
5119 the execute permission for the file.
5120 it() New files get their "normal" permission bits set to the source
5121 - file's permissions masked with the receiving end's umask setting, and
5122 + file's permissions masked with the receiving directory's default
5123 + permissions (either the receiving process's umask, or the permissions
5124 + specified via the destination directory's default ACL), and
5125 their special permission bits disabled except in the case where a new
5126 directory inherits a setgid bit from its parent directory.
5128 @@ -773,9 +776,11 @@ The preservation of the destination's se
5129 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5130 versions erroneously preserved the three special permission bits for
5131 newly-created files when bf(--perms) was off, while overriding the
5132 -destination's setgid bit setting on a newly-created directory. (Keep in
5133 -mind that it is the version of the receiving rsync that affects this
5135 +destination's setgid bit setting on a newly-created directory. Default ACL
5136 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5137 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5138 +(Keep in mind that it is the version of the receiving rsync that affects
5141 dit(bf(-E, --executability)) This option causes rsync to preserve the
5142 executability (or non-executability) of regular files when bf(--perms) is
5143 @@ -793,6 +798,15 @@ quote(itemize(
5145 If bf(--perms) is enabled, this option is ignored.
5147 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5148 +ACLs to be the same as the source ACLs. This nonstandard option only
5149 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5151 +Note also that an optimization of the ACL-sending protocol used by this
5152 +version makes it incompatible with sending files to an older ACL-enabled
5153 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5154 +doubling is not needed when pulling files from an older rsync.
5156 dit(bf(--chmod)) This option tells rsync to apply one or more
5157 comma-separated "chmod" strings to the permission of the files in the
5158 transfer. The resulting value is treated as though it was the permissions
5163 + * Unix SMB/Netbios implementation.
5165 + * Portable SMB ACL interface
5167 + * Copyright (C) 2000 Jeremy Allison
5169 + * This program is free software; you can redistribute it and/or modify
5170 + * it under the terms of the GNU General Public License as published by
5171 + * the Free Software Foundation; either version 2 of the License, or
5172 + * (at your option) any later version.
5174 + * This program is distributed in the hope that it will be useful,
5175 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5176 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5177 + * GNU General Public License for more details.
5179 + * You should have received a copy of the GNU General Public License along
5180 + * with this program; if not, write to the Free Software Foundation, Inc.,
5181 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
5184 +#ifndef _SMB_ACLS_H
5185 +#define _SMB_ACLS_H
5187 +#if defined HAVE_POSIX_ACLS
5189 +/* This is an identity mapping (just remove the SMB_). */
5191 +#define SMB_ACL_TAG_T acl_tag_t
5192 +#define SMB_ACL_TYPE_T acl_type_t
5193 +#define SMB_ACL_PERMSET_T acl_permset_t
5194 +#define SMB_ACL_PERM_T acl_perm_t
5195 +#define SMB_ACL_READ ACL_READ
5196 +#define SMB_ACL_WRITE ACL_WRITE
5197 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5199 +/* Types of ACLs. */
5200 +#define SMB_ACL_USER ACL_USER
5201 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5202 +#define SMB_ACL_GROUP ACL_GROUP
5203 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5204 +#define SMB_ACL_OTHER ACL_OTHER
5205 +#define SMB_ACL_MASK ACL_MASK
5207 +#define SMB_ACL_T acl_t
5209 +#define SMB_ACL_ENTRY_T acl_entry_t
5211 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5212 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5214 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5215 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5217 +#elif defined HAVE_TRU64_ACLS
5219 +/* This is for DEC/Compaq Tru64 UNIX */
5221 +#define SMB_ACL_TAG_T acl_tag_t
5222 +#define SMB_ACL_TYPE_T acl_type_t
5223 +#define SMB_ACL_PERMSET_T acl_permset_t
5224 +#define SMB_ACL_PERM_T acl_perm_t
5225 +#define SMB_ACL_READ ACL_READ
5226 +#define SMB_ACL_WRITE ACL_WRITE
5227 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5229 +/* Types of ACLs. */
5230 +#define SMB_ACL_USER ACL_USER
5231 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5232 +#define SMB_ACL_GROUP ACL_GROUP
5233 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5234 +#define SMB_ACL_OTHER ACL_OTHER
5235 +#define SMB_ACL_MASK ACL_MASK
5237 +#define SMB_ACL_T acl_t
5239 +#define SMB_ACL_ENTRY_T acl_entry_t
5241 +#define SMB_ACL_FIRST_ENTRY 0
5242 +#define SMB_ACL_NEXT_ENTRY 1
5244 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5245 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5247 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5249 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5250 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5253 +/* SVR4.2 ES/MP ACLs */
5254 +typedef int SMB_ACL_TAG_T;
5255 +typedef int SMB_ACL_TYPE_T;
5256 +typedef ushort *SMB_ACL_PERMSET_T;
5257 +typedef ushort SMB_ACL_PERM_T;
5258 +#define SMB_ACL_READ 4
5259 +#define SMB_ACL_WRITE 2
5260 +#define SMB_ACL_EXECUTE 1
5262 +/* Types of ACLs. */
5263 +#define SMB_ACL_USER USER
5264 +#define SMB_ACL_USER_OBJ USER_OBJ
5265 +#define SMB_ACL_GROUP GROUP
5266 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5267 +#define SMB_ACL_OTHER OTHER_OBJ
5268 +#define SMB_ACL_MASK CLASS_OBJ
5270 +typedef struct SMB_ACL_T {
5274 + struct acl acl[1];
5277 +typedef struct acl *SMB_ACL_ENTRY_T;
5279 +#define SMB_ACL_FIRST_ENTRY 0
5280 +#define SMB_ACL_NEXT_ENTRY 1
5282 +#define SMB_ACL_TYPE_ACCESS 0
5283 +#define SMB_ACL_TYPE_DEFAULT 1
5286 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5289 +#elif defined HAVE_HPUX_ACLS
5292 + * Based on the Solaris & UnixWare code.
5296 +#include <sys/aclv.h>
5298 +/* SVR4.2 ES/MP ACLs */
5299 +typedef int SMB_ACL_TAG_T;
5300 +typedef int SMB_ACL_TYPE_T;
5301 +typedef ushort *SMB_ACL_PERMSET_T;
5302 +typedef ushort SMB_ACL_PERM_T;
5303 +#define SMB_ACL_READ 4
5304 +#define SMB_ACL_WRITE 2
5305 +#define SMB_ACL_EXECUTE 1
5307 +/* Types of ACLs. */
5308 +#define SMB_ACL_USER USER
5309 +#define SMB_ACL_USER_OBJ USER_OBJ
5310 +#define SMB_ACL_GROUP GROUP
5311 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5312 +#define SMB_ACL_OTHER OTHER_OBJ
5313 +#define SMB_ACL_MASK CLASS_OBJ
5315 +typedef struct SMB_ACL_T {
5319 + struct acl acl[1];
5322 +typedef struct acl *SMB_ACL_ENTRY_T;
5324 +#define SMB_ACL_FIRST_ENTRY 0
5325 +#define SMB_ACL_NEXT_ENTRY 1
5327 +#define SMB_ACL_TYPE_ACCESS 0
5328 +#define SMB_ACL_TYPE_DEFAULT 1
5330 +#elif defined HAVE_IRIX_ACLS
5332 +#define SMB_ACL_TAG_T acl_tag_t
5333 +#define SMB_ACL_TYPE_T acl_type_t
5334 +#define SMB_ACL_PERMSET_T acl_permset_t
5335 +#define SMB_ACL_PERM_T acl_perm_t
5336 +#define SMB_ACL_READ ACL_READ
5337 +#define SMB_ACL_WRITE ACL_WRITE
5338 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5340 +/* Types of ACLs. */
5341 +#define SMB_ACL_USER ACL_USER
5342 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5343 +#define SMB_ACL_GROUP ACL_GROUP
5344 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5345 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5346 +#define SMB_ACL_MASK ACL_MASK
5348 +typedef struct SMB_ACL_T {
5354 +#define SMB_ACL_ENTRY_T acl_entry_t
5356 +#define SMB_ACL_FIRST_ENTRY 0
5357 +#define SMB_ACL_NEXT_ENTRY 1
5359 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5360 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5362 +#elif defined HAVE_AIX_ACLS
5364 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5366 +#include "/usr/include/acl.h"
5368 +typedef uint *SMB_ACL_PERMSET_T;
5370 +struct acl_entry_link{
5371 + struct acl_entry_link *prevp;
5372 + struct new_acl_entry *entryp;
5373 + struct acl_entry_link *nextp;
5377 +struct new_acl_entry{
5378 + unsigned short ace_len;
5379 + unsigned short ace_type;
5380 + unsigned int ace_access;
5381 + struct ace_id ace_id[1];
5384 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5385 +#define SMB_ACL_T struct acl_entry_link*
5387 +#define SMB_ACL_TAG_T unsigned short
5388 +#define SMB_ACL_TYPE_T int
5389 +#define SMB_ACL_PERM_T uint
5390 +#define SMB_ACL_READ S_IRUSR
5391 +#define SMB_ACL_WRITE S_IWUSR
5392 +#define SMB_ACL_EXECUTE S_IXUSR
5394 +/* Types of ACLs. */
5395 +#define SMB_ACL_USER ACEID_USER
5396 +#define SMB_ACL_USER_OBJ 3
5397 +#define SMB_ACL_GROUP ACEID_GROUP
5398 +#define SMB_ACL_GROUP_OBJ 4
5399 +#define SMB_ACL_OTHER 5
5400 +#define SMB_ACL_MASK 6
5403 +#define SMB_ACL_FIRST_ENTRY 1
5404 +#define SMB_ACL_NEXT_ENTRY 2
5406 +#define SMB_ACL_TYPE_ACCESS 0
5407 +#define SMB_ACL_TYPE_DEFAULT 1
5409 +#else /* No ACLs. */
5411 +/* No ACLS - fake it. */
5412 +#define SMB_ACL_TAG_T int
5413 +#define SMB_ACL_TYPE_T int
5414 +#define SMB_ACL_PERMSET_T mode_t
5415 +#define SMB_ACL_PERM_T mode_t
5416 +#define SMB_ACL_READ S_IRUSR
5417 +#define SMB_ACL_WRITE S_IWUSR
5418 +#define SMB_ACL_EXECUTE S_IXUSR
5420 +/* Types of ACLs. */
5421 +#define SMB_ACL_USER 0
5422 +#define SMB_ACL_USER_OBJ 1
5423 +#define SMB_ACL_GROUP 2
5424 +#define SMB_ACL_GROUP_OBJ 3
5425 +#define SMB_ACL_OTHER 4
5426 +#define SMB_ACL_MASK 5
5428 +typedef struct SMB_ACL_T {
5432 +typedef struct SMB_ACL_ENTRY_T {
5434 +} *SMB_ACL_ENTRY_T;
5436 +#define SMB_ACL_FIRST_ENTRY 0
5437 +#define SMB_ACL_NEXT_ENTRY 1
5439 +#define SMB_ACL_TYPE_ACCESS 0
5440 +#define SMB_ACL_TYPE_DEFAULT 1
5442 +#endif /* No ACLs. */
5443 +#endif /* _SMB_ACLS_H */
5444 --- old/testsuite/acls.test
5445 +++ new/testsuite/acls.test
5449 +# This program is distributable under the terms of the GNU GPL (see
5452 +# Test that rsync handles basic ACL preservation.
5454 +. $srcdir/testsuite/rsync.fns
5456 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5457 +case "$setfacl_nodef" in
5458 +true) test_skipped "I don't know how to use your setfacl command" ;;
5461 +makepath "$fromdir/foo"
5462 +echo something >"$fromdir/file1"
5463 +echo else >"$fromdir/file2"
5465 +files='foo file1 file2'
5467 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
5468 +setfacl -m u:0:5 "$fromdir/file1"
5469 +setfacl -m u:0:5 "$fromdir/file2"
5471 +$RSYNC -avvA "$fromdir/" "$todir/"
5474 +getfacl $files >"$scratchdir/acls.txt"
5477 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
5479 +# The script would have aborted on error, so getting here means we've won.
5481 --- old/testsuite/default-acls.test
5482 +++ new/testsuite/default-acls.test
5486 +# This program is distributable under the terms of the GNU GPL (see
5489 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5491 +. $srcdir/testsuite/rsync.fns
5493 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5494 +case "$setfacl_nodef" in
5495 +true) test_skipped "I don't know how to use your setfacl command" ;;
5496 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5497 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5499 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5501 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5503 + todir="$scratchdir/$1"
5505 + $setfacl_nodef "$todir"
5507 + case "$setfacl_nodef" in
5508 + *-k*) opts="-dm $2" ;;
5509 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5511 + setfacl $opts "$todir"
5513 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5514 + # even though the directory itself is outside the transfer
5515 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5516 + check_perms "$todir/to" $4 "Target $1"
5517 + check_perms "$todir/to/dir" $4 "Target $1"
5518 + check_perms "$todir/to/file" $3 "Target $1"
5519 + check_perms "$todir/to/program" $4 "Target $1"
5520 + # Make sure get_local_name doesn't mess us up when transferring only one file
5521 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5522 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5523 + # Make sure we obey default ACLs when not transferring a regular file
5524 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5525 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5528 +mkdir "$scratchdir/dir"
5529 +echo "File!" >"$scratchdir/file"
5530 +echo "#!/bin/sh" >"$scratchdir/program"
5531 +chmod 777 "$scratchdir/dir"
5532 +chmod 666 "$scratchdir/file"
5533 +chmod 777 "$scratchdir/program"
5535 +# Test some target directories
5537 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5538 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5539 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5540 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5541 +testit noda1 '' rw------- rwx------
5543 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5545 +testit noda3 '' rw-r--r-- rwxr-xr-x
5553 extern int preserve_uid;
5554 extern int preserve_gid;
5555 +extern int preserve_acls;
5556 extern int numeric_ids;
5559 @@ -275,7 +276,7 @@ void send_uid_list(int f)
5563 - if (preserve_uid) {
5564 + if (preserve_uid || preserve_acls) {
5566 /* we send sequences of uid/byte-length/name */
5567 for (list = uidlist; list; list = list->next) {
5568 @@ -292,7 +293,7 @@ void send_uid_list(int f)
5572 - if (preserve_gid) {
5573 + if (preserve_gid || preserve_acls) {
5575 for (list = gidlist; list; list = list->next) {
5577 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
5581 - if (preserve_uid && !numeric_ids) {
5582 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5583 /* read the uid list */
5584 while ((id = read_int(f)) != 0) {
5585 int len = read_byte(f);
5586 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
5590 - if (preserve_gid && !numeric_ids) {
5591 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5592 /* read the gid list */
5593 while ((id = read_int(f)) != 0) {
5594 int len = read_byte(f);
5595 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
5599 +#ifdef SUPPORT_ACLS
5600 + if (preserve_acls && !numeric_ids) {
5602 + while ((id = next_acl_uid(flist)) != NULL)
5603 + *id = match_uid(*id);
5604 + while ((id = next_acl_gid(flist)) != NULL)
5605 + *id = match_gid(*id);
5609 /* Now convert all the uids/gids from sender values to our values. */
5610 if (am_root && preserve_uid && !numeric_ids) {
5611 for (i = 0; i < flist->count; i++)