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;
906 + if (S_ISLNK(file->mode))
909 + fname = f_name(file, NULL);
910 + type = SMB_ACL_TYPE_ACCESS;
913 + file_acl_index_list *flst = file_acl_index_lists(type);
915 + expand_file_acl_index_list(flst);
917 + tag = read_byte(f);
918 + if (tag == 'A' || tag == 'a') {
919 + if (type != SMB_ACL_TYPE_ACCESS) {
920 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
922 + exit_cleanup(RERR_STREAMIO);
924 + } else if (tag == 'D' || tag == 'd') {
925 + if (type == SMB_ACL_TYPE_ACCESS) {
926 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
928 + exit_cleanup(RERR_STREAMIO);
931 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
933 + exit_cleanup(RERR_STREAMIO);
935 + if (tag == 'A' || tag == 'D') {
937 + rsync_acl_list *racl_list = rsync_acl_lists(type);
938 + smb_acl_list *sacl_list = smb_acl_lists(type);
939 + flst->fais[flst->count].aclidx = racl_list->count;
940 + flst->fais[flst->count++].file = file;
941 + receive_rsync_acl(&racl, f, type);
942 + expand_rsync_acl_list(racl_list);
943 + racl_list->racls[racl_list->count++] = racl;
944 + expand_smb_acl_list(sacl_list);
945 + sacl_list->sacls[sacl_list->count++] = NULL;
947 + int index = read_int(f);
948 + rsync_acl_list *racl_list = rsync_acl_lists(type);
949 + if ((size_t) index >= racl_list->count) {
950 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
952 + str_acl_type(type),
954 + exit_cleanup(RERR_STREAMIO);
956 + flst->fais[flst->count].aclidx = index;
957 + flst->fais[flst->count++].file = file;
959 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
962 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
964 + const file_acl_index *fx1 = (const file_acl_index *)f1;
965 + const file_acl_index *fx2 = (const file_acl_index *)f2;
966 + return fx1->file == fx2->file ? 0 : fx1->file < fx2->file ? -1 : 1;
969 +void sort_file_acl_index_lists()
971 + SMB_ACL_TYPE_T type;
973 + type = SMB_ACL_TYPE_ACCESS;
975 + file_acl_index_list *flst = file_acl_index_lists(type);
980 + qsort(flst->fais, flst->count, sizeof flst->fais[0],
981 + &file_acl_index_list_sorter);
982 + } while (BUMP_TYPE(type));
985 +static int find_file_acl_index(const file_acl_index_list *flst,
986 + const struct file_struct *file)
988 + int low = 0, high = flst->count;
989 + const struct file_struct *file_mid;
994 + int mid = (high + low) / 2;
995 + file_mid = flst->fais[mid].file;
996 + if (file_mid == file)
997 + return flst->fais[mid].aclidx;
998 + if (file_mid > file)
1002 + } while (low < high);
1003 + if (low == high) {
1004 + file_mid = flst->fais[low].file;
1005 + if (file_mid == file)
1006 + return flst->fais[low].aclidx;
1009 + "find_file_acl_index: can't find entry for file in list\n");
1010 + exit_cleanup(RERR_STREAMIO);
1014 +/* for duplicating ACLs on backups when using backup_dir */
1015 +int dup_acl(const char *orig, const char *bak, mode_t mode)
1017 + SMB_ACL_TYPE_T type;
1020 + type = SMB_ACL_TYPE_ACCESS;
1022 + SMB_ACL_T sacl_orig, sacl_bak;
1023 + rsync_acl racl_orig, racl_bak;
1024 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
1025 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
1026 + orig, str_acl_type(type), strerror(errno));
1030 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
1031 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
1032 + bak, str_acl_type(type), strerror(errno));
1034 + /* try to forge on through */
1036 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
1038 + goto out_with_sacls;
1041 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
1043 + goto out_with_one_racl;
1045 + if (rsync_acls_equal(&racl_orig, &racl_bak))
1046 + goto out_with_all;
1048 + ; /* presume they're unequal */
1050 + if (type == SMB_ACL_TYPE_DEFAULT
1051 + && racl_orig.user_obj == ACL_NO_ENTRY) {
1052 + if (sys_acl_delete_def_file(bak) < 0) {
1053 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
1054 + bak, strerror(errno));
1057 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
1058 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
1059 + bak, str_acl_type(type), strerror(errno));
1064 + rsync_acl_free(&racl_bak);
1065 + out_with_one_racl:
1066 + rsync_acl_free(&racl_orig);
1069 + sys_acl_free_acl(sacl_bak);
1071 + sys_acl_free_acl(sacl_orig);
1072 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1077 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1078 + * for keep_backup(). */
1079 +static const struct file_struct *backup_orig_file = NULL;
1080 +static const char null_string[] = "";
1081 +static const char *backup_orig_fname = null_string;
1082 +static const char *backup_dest_fname = null_string;
1083 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1085 +void push_keep_backup_acl(const struct file_struct *file,
1086 + const char *orig, const char *dest)
1088 + SMB_ACL_TYPE_T type;
1091 + backup_orig_file = file;
1092 + backup_orig_fname = orig;
1093 + backup_dest_fname = dest;
1095 + sacl = &_backup_sacl[0];
1096 + type = SMB_ACL_TYPE_ACCESS;
1098 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1102 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1104 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1105 + orig, str_acl_type(type),
1108 + } while (BUMP_TYPE(type));
1111 +static int set_keep_backup_acl()
1113 + SMB_ACL_TYPE_T type;
1117 + sacl = &_backup_sacl[0];
1118 + type = SMB_ACL_TYPE_ACCESS;
1121 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1123 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1124 + backup_dest_fname,
1125 + str_acl_type(type),
1129 + } while (BUMP_TYPE(type));
1134 +void cleanup_keep_backup_acl()
1136 + SMB_ACL_TYPE_T type;
1139 + backup_orig_file = NULL;
1140 + backup_orig_fname = null_string;
1141 + backup_dest_fname = null_string;
1143 + sacl = &_backup_sacl[0];
1144 + type = SMB_ACL_TYPE_ACCESS;
1147 + sys_acl_free_acl(*sacl);
1150 + } while (BUMP_TYPE(type));
1153 +/* set ACL on rsync-ed or keep_backup-ed file
1155 + * This sets extended access ACL entries and default ACLs. If convenient,
1156 + * it sets permission bits along with the access ACLs and signals having
1157 + * done so by modifying mode_p, which should point into the stat buffer.
1159 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1160 + * Pass NULL for mode_p to get the return code without changing anything. */
1161 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1163 + int unchanged = 1;
1164 + SMB_ACL_TYPE_T type;
1166 + if (S_ISLNK(file->mode))
1169 + if (file == backup_orig_file) {
1170 + if (!strcmp(fname, backup_dest_fname))
1171 + return set_keep_backup_acl();
1173 + type = SMB_ACL_TYPE_ACCESS;
1176 + SMB_ACL_T sacl_orig, *sacl_new;
1177 + rsync_acl racl_orig, *racl_new;
1178 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1180 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1181 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1182 + sacl_orig = sys_acl_get_file(fname, type);
1184 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1185 + fname, str_acl_type(type), strerror(errno));
1189 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1190 + sys_acl_free_acl(sacl_orig);
1195 + if (type == SMB_ACL_TYPE_ACCESS)
1196 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new, file->mode);
1198 + ok = rsync_acls_equal(&racl_orig, racl_new);
1199 + rsync_acl_free(&racl_orig);
1202 + if (!dry_run && mode_p) {
1203 + if (type == SMB_ACL_TYPE_DEFAULT
1204 + && racl_new->user_obj == ACL_NO_ENTRY) {
1205 + if (sys_acl_delete_def_file(fname) < 0) {
1206 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1207 + fname, strerror(errno));
1212 + mode_t cur_mode = *mode_p;
1214 + && !pack_smb_acl(sacl_new, racl_new)) {
1218 + if (type == SMB_ACL_TYPE_ACCESS) {
1219 + cur_mode = change_sacl_perms(*sacl_new, racl_new,
1220 + cur_mode, file->mode);
1221 + if (cur_mode == ~0u)
1224 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1225 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1226 + fname, str_acl_type(type),
1231 + if (type == SMB_ACL_TYPE_ACCESS)
1232 + *mode_p = cur_mode;
1235 + if (unchanged == 1)
1237 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1242 +/* Enumeration functions for uid mapping: */
1244 +/* Context -- one and only one. Should be cycled through once on uid
1245 + * mapping and once on gid mapping. */
1246 +static rsync_acl_list *_enum_racl_lists[] = {
1247 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1250 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1251 +static size_t enum_racl_index = 0;
1252 +static size_t enum_ida_index = 0;
1254 +/* This returns the next tag_type id from the given acl for the next entry,
1255 + * or it returns 0 if there are no more tag_type ids in the acl. */
1256 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1258 + const ida_list *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1259 + if (enum_ida_index < idal->count) {
1260 + id_access *ida = &idal->idas[enum_ida_index++];
1263 + enum_ida_index = 0;
1267 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1269 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1270 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1271 + id_t *id = next_ace_id(tag_type, racl);
1275 + enum_racl_index = 0;
1279 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1281 + for (; *enum_racl_list; enum_racl_list++) {
1282 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1286 + enum_racl_list = &_enum_racl_lists[0];
1290 +id_t *next_acl_uid()
1292 + return next_acl_list_id(SMB_ACL_USER);
1295 +id_t *next_acl_gid()
1297 + return next_acl_list_id(SMB_ACL_GROUP);
1300 +int default_perms_for_dir(const char *dir)
1309 + perms = ACCESSPERMS & ~orig_umask;
1310 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1311 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1312 + if (sacl == NULL) {
1313 + /* Couldn't get an ACL. Darn. */
1316 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1320 + /* We're doing a dry run, so the containing directory
1321 + * wasn't actually created. Don't worry about it. */
1324 + /* Otherwise fall through. */
1326 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1327 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1333 + ok = unpack_smb_acl(&racl, sacl);
1334 + sys_acl_free_acl(sacl);
1336 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1340 + /* Apply the permission-bit entries of the default ACL, if any. */
1341 + if (racl.user_obj != ACL_NO_ENTRY) {
1342 + perms = rsync_acl_get_perms(&racl);
1344 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1347 + rsync_acl_free(&racl);
1351 +#endif /* SUPPORT_ACLS */
1354 @@ -29,6 +29,7 @@ extern char *backup_suffix;
1355 extern char *backup_dir;
1358 +extern int preserve_acls;
1359 extern int preserve_devices;
1360 extern int preserve_specials;
1361 extern int preserve_links;
1362 @@ -133,6 +134,10 @@ static int make_bak_dir(char *fullpath)
1364 do_lchown(fullpath, st.st_uid, st.st_gid);
1365 do_chmod(fullpath, st.st_mode);
1366 +#ifdef SUPPORT_ACLS
1367 + if (preserve_acls)
1368 + dup_acl(end, fullpath, st.st_mode);
1373 @@ -186,6 +191,11 @@ static int keep_backup(char *fname)
1374 if (!(buf = get_backup_name(fname)))
1377 +#ifdef SUPPORT_ACLS
1378 + if (preserve_acls)
1379 + push_keep_backup_acl(file, fname, buf);
1382 /* Check to see if this is a device file, or link */
1383 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1384 || (preserve_specials && IS_SPECIAL(file->mode))) {
1385 @@ -261,6 +271,10 @@ static int keep_backup(char *fname)
1388 set_file_attrs(buf, file, NULL, 0);
1389 +#ifdef SUPPORT_ACLS
1390 + if (preserve_acls)
1391 + cleanup_keep_backup_acl();
1396 --- old/configure.in
1397 +++ new/configure.in
1398 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1399 AC_CHECK_LIB(resolv, strcasecmp)
1402 +AC_CHECK_FUNCS(aclsort)
1403 +if test x"$ac_cv_func_aclsort" = x"no"; then
1404 + AC_CHECK_LIB(sec, aclsort)
1407 dnl At the moment we don't test for a broken memcmp(), because all we
1408 dnl need to do is test for equality, not comparison, and it seems that
1409 dnl every platform has a memcmp that can do at least that.
1410 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1411 AC_SUBST(CC_SHOBJ_FLAG)
1412 AC_SUBST(BUILD_POPT)
1414 +AC_CHECK_HEADERS(sys/acl.h)
1415 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1416 +#################################################
1417 +# check for ACL support
1419 +AC_MSG_CHECKING(whether to support ACLs)
1420 +AC_ARG_ENABLE(acl-support,
1421 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1422 +[ case "$enableval" in
1425 + case "$host_os" in
1427 + AC_MSG_RESULT(Using UnixWare ACLs)
1428 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1430 + *solaris*|*cygwin*)
1431 + AC_MSG_RESULT(Using solaris ACLs)
1432 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1435 + AC_MSG_RESULT(Using HPUX ACLs)
1436 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1439 + AC_MSG_RESULT(Using IRIX ACLs)
1440 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1443 + AC_MSG_RESULT(Using AIX ACLs)
1444 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1447 + AC_MSG_RESULT(Using Tru64 ACLs)
1448 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1449 + LIBS="$LIBS -lpacl"
1452 + AC_MSG_RESULT(ACLs requested -- running tests)
1453 + AC_CHECK_LIB(acl,acl_get_file)
1454 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1455 + AC_TRY_LINK([#include <sys/types.h>
1456 +#include <sys/acl.h>],
1457 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1458 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1459 + AC_MSG_CHECKING(ACL test results)
1460 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1461 + AC_MSG_RESULT(Using posix ACLs)
1462 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1463 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1464 + AC_TRY_LINK([#include <sys/types.h>
1465 +#include <sys/acl.h>],
1466 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1467 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1468 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1469 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1472 + AC_MSG_ERROR(Failed to find ACL support)
1479 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1482 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1486 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1491 @@ -40,6 +40,7 @@ extern int filesfrom_fd;
1492 extern int one_file_system;
1493 extern int copy_dirlinks;
1494 extern int keep_dirlinks;
1495 +extern int preserve_acls;
1496 extern int preserve_links;
1497 extern int preserve_hard_links;
1498 extern int preserve_devices;
1499 @@ -961,6 +962,11 @@ static struct file_struct *send_file_nam
1500 if (chmod_modes && !S_ISLNK(file->mode))
1501 file->mode = tweak_mode(file->mode, chmod_modes);
1503 +#ifdef SUPPORT_ACLS
1504 + if (preserve_acls && make_acl(file, fname) < 0)
1508 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1510 flist_expand(flist);
1511 @@ -968,6 +974,16 @@ static struct file_struct *send_file_nam
1512 if (file->basename[0]) {
1513 flist->files[flist->count++] = file;
1514 send_file_entry(file, f);
1515 +#ifdef SUPPORT_ACLS
1516 + if (preserve_acls)
1517 + send_acl(file, f);
1520 +#ifdef SUPPORT_ACLS
1521 + /* Cleanup unsent ACL(s). */
1522 + if (preserve_acls)
1523 + send_acl(file, -1);
1528 @@ -1356,6 +1372,11 @@ struct file_list *recv_file_list(int f)
1529 flags |= read_byte(f) << 8;
1530 file = receive_file_entry(flist, flags, f);
1532 +#ifdef SUPPORT_ACLS
1533 + if (preserve_acls)
1534 + receive_acl(file, f);
1537 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1538 stats.total_size += file->length;
1540 @@ -1378,6 +1399,11 @@ struct file_list *recv_file_list(int f)
1542 clean_flist(flist, relative_paths, 1);
1544 +#ifdef SUPPORT_ACLS
1545 + if (preserve_acls)
1546 + sort_file_acl_index_lists();
1550 recv_uid_list(f, flist);
1554 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1555 extern int max_delete;
1556 extern int force_delete;
1557 extern int one_file_system;
1558 +extern mode_t orig_umask;
1559 extern struct stats stats;
1560 extern dev_t filesystem_dev;
1561 extern char *backup_dir;
1562 @@ -319,6 +320,8 @@ static void do_delete_pass(struct file_l
1564 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1566 + /* FIXME: Flag ACL changes. */
1569 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1571 @@ -353,6 +356,7 @@ void itemize(struct file_struct *file, i
1572 if (preserve_gid && file->gid != GID_NONE
1573 && st->st_gid != file->gid)
1574 iflags |= ITEM_REPORT_GROUP;
1575 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1577 iflags |= ITEM_IS_NEW;
1579 @@ -769,6 +773,7 @@ static int try_dests_non(struct file_str
1582 static int phase = 0;
1583 +static int dflt_perms;
1585 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1586 * make sure it exists, and has the right permissions/timestamp info. For
1587 @@ -860,6 +865,10 @@ static void recv_generator(char *fname,
1590 need_fuzzy_dirlist = 1;
1591 +#ifdef SUPPORT_ACLS
1592 + if (!preserve_perms)
1593 + dflt_perms = default_perms_for_dir(dn);
1596 parent_dirname = dn;
1598 @@ -887,7 +896,8 @@ static void recv_generator(char *fname,
1599 if (!preserve_perms) {
1600 int exists = statret == 0
1601 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1602 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1603 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1607 if (S_ISDIR(file->mode)) {
1608 @@ -1366,6 +1376,8 @@ void generate_files(int f_out, struct fi
1609 * notice that and let us know via the redo pipe (or its closing). */
1612 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1614 for (i = 0; i < flist->count; i++) {
1615 struct file_struct *file = flist->files[i];
1617 --- old/lib/sysacls.c
1618 +++ new/lib/sysacls.c
1621 + * Unix SMB/CIFS implementation.
1622 + * Samba system utilities for ACL support.
1624 + * Copyright (C) Jeremy Allison 2000.
1626 + * This program is free software; you can redistribute it and/or modify
1627 + * it under the terms of the GNU General Public License as published by
1628 + * the Free Software Foundation; either version 2 of the License, or
1629 + * (at your option) any later version.
1631 + * This program is distributed in the hope that it will be useful,
1632 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1633 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1634 + * GNU General Public License for more details.
1636 + * You should have received a copy of the GNU General Public License along
1637 + * with this program; if not, write to the Free Software Foundation, Inc.,
1638 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
1642 +#include "sysacls.h" /****** ADDED ******/
1644 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1645 +void SAFE_FREE(void *mem)
1651 +char *uidtoname(uid_t uid)
1653 + static char idbuf[12];
1654 + struct passwd *pw;
1656 + if ((pw = getpwuid(uid)) == NULL) {
1657 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1660 + return pw->pw_name;
1662 +/****** EXTRAS -- END ******/
1665 + This file wraps all differing system ACL interfaces into a consistent
1666 + one based on the POSIX interface. It also returns the correct errors
1667 + for older UNIX systems that don't support ACLs.
1669 + The interfaces that each ACL implementation must support are as follows :
1671 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1672 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1673 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1674 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1675 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1676 + SMB_ACL_T sys_acl_get_fd(int fd)
1677 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1678 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1679 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1680 + SMB_ACL_T sys_acl_init( int count)
1681 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1682 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1683 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1684 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1685 + int sys_acl_valid( SMB_ACL_T theacl )
1686 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1687 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1688 + int sys_acl_delete_def_file(const char *path)
1690 + This next one is not POSIX complient - but we *have* to have it !
1691 + More POSIX braindamage.
1693 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1695 + The generic POSIX free is the following call. We split this into
1696 + several different free functions as we may need to add tag info
1697 + to structures when emulating the POSIX interface.
1699 + int sys_acl_free( void *obj_p)
1701 + The calls we actually use are :
1703 + int sys_acl_free_text(char *text) - free acl_to_text
1704 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1705 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1709 +#if defined(HAVE_POSIX_ACLS)
1711 +/* Identity mapping - easy. */
1713 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1715 + return acl_get_entry( the_acl, entry_id, entry_p);
1718 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1720 + return acl_get_tag_type( entry_d, tag_type_p);
1723 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1725 + return acl_get_permset( entry_d, permset_p);
1728 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1730 + return acl_get_qualifier( entry_d);
1733 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1735 + return acl_get_file( path_p, type);
1738 +SMB_ACL_T sys_acl_get_fd(int fd)
1740 + return acl_get_fd(fd);
1743 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1745 + return acl_clear_perms(permset);
1748 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1750 + return acl_add_perm(permset, perm);
1753 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1755 +#if defined(HAVE_ACL_GET_PERM_NP)
1757 + * Required for TrustedBSD-based ACL implementations where
1758 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1761 + return acl_get_perm_np(permset, perm);
1763 + return acl_get_perm(permset, perm);
1767 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1769 + return acl_to_text( the_acl, plen);
1772 +SMB_ACL_T sys_acl_init( int count)
1774 + return acl_init(count);
1777 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1779 + return acl_create_entry(pacl, pentry);
1782 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1784 + return acl_set_tag_type(entry, tagtype);
1787 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1789 + return acl_set_qualifier(entry, qual);
1792 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1794 + return acl_set_permset(entry, permset);
1797 +int sys_acl_valid( SMB_ACL_T theacl )
1799 + return acl_valid(theacl);
1802 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1804 + return acl_set_file(name, acltype, theacl);
1807 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1809 + return acl_set_fd(fd, theacl);
1812 +int sys_acl_delete_def_file(const char *name)
1814 + return acl_delete_def_file(name);
1817 +int sys_acl_free_text(char *text)
1819 + return acl_free(text);
1822 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1824 + return acl_free(the_acl);
1827 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1829 + return acl_free(qual);
1832 +#elif defined(HAVE_TRU64_ACLS)
1834 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1835 + * is based on Draft 13 of the POSIX spec which is
1836 + * slightly different from the Draft 16 interface.
1838 + * Also, some of the permset manipulation functions
1839 + * such as acl_clear_perm() and acl_add_perm() appear
1840 + * to be broken on Tru64 so we have to manipulate
1841 + * the permission bits in the permset directly.
1843 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1845 + SMB_ACL_ENTRY_T entry;
1847 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1852 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1857 + return errno ? -1 : 0;
1860 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1862 + return acl_get_tag_type( entry_d, tag_type_p);
1865 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1867 + return acl_get_permset( entry_d, permset_p);
1870 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1872 + return acl_get_qualifier( entry_d);
1875 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1877 + return acl_get_file((char *)path_p, type);
1880 +SMB_ACL_T sys_acl_get_fd(int fd)
1882 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1885 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1887 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1892 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1894 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1899 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1904 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1906 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1909 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1911 + return acl_to_text( the_acl, plen);
1914 +SMB_ACL_T sys_acl_init( int count)
1916 + return acl_init(count);
1919 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1921 + SMB_ACL_ENTRY_T entry;
1923 + if ((entry = acl_create_entry(pacl)) == NULL) {
1931 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1933 + return acl_set_tag_type(entry, tagtype);
1936 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1938 + return acl_set_qualifier(entry, qual);
1941 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1943 + return acl_set_permset(entry, permset);
1946 +int sys_acl_valid( SMB_ACL_T theacl )
1948 + acl_entry_t entry;
1950 + return acl_valid(theacl, &entry);
1953 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1955 + return acl_set_file((char *)name, acltype, theacl);
1958 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1960 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1963 +int sys_acl_delete_def_file(const char *name)
1965 + return acl_delete_def_file((char *)name);
1968 +int sys_acl_free_text(char *text)
1971 + * (void) cast and explicit return 0 are for DEC UNIX
1972 + * which just #defines acl_free_text() to be free()
1974 + (void) acl_free_text(text);
1978 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1980 + return acl_free(the_acl);
1983 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1985 + return acl_free_qualifier(qual, tagtype);
1988 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1991 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1992 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1996 + * Note that while this code implements sufficient functionality
1997 + * to support the sys_acl_* interfaces it does not provide all
1998 + * of the semantics of the POSIX ACL interfaces.
2000 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2001 + * from a call to sys_acl_get_entry() should not be assumed to be
2002 + * valid after calling any of the following functions, which may
2003 + * reorder the entries in the ACL.
2006 + * sys_acl_set_file()
2007 + * sys_acl_set_fd()
2011 + * The only difference between Solaris and UnixWare / OpenUNIX is
2012 + * that the #defines for the ACL operations have different names
2014 +#if defined(HAVE_UNIXWARE_ACLS)
2016 +#define SETACL ACL_SET
2017 +#define GETACL ACL_GET
2018 +#define GETACLCNT ACL_CNT
2023 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2025 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2030 + if (entry_p == NULL) {
2035 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2039 + if (acl_d->next < 0) {
2044 + if (acl_d->next >= acl_d->count) {
2048 + *entry_p = &acl_d->acl[acl_d->next++];
2053 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2055 + *type_p = entry_d->a_type;
2060 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2062 + *permset_p = &entry_d->a_perm;
2067 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2069 + if (entry_d->a_type != SMB_ACL_USER
2070 + && entry_d->a_type != SMB_ACL_GROUP) {
2075 + return &entry_d->a_id;
2079 + * There is no way of knowing what size the ACL returned by
2080 + * GETACL will be unless you first call GETACLCNT which means
2081 + * making an additional system call.
2083 + * In the hope of avoiding the cost of the additional system
2084 + * call in most cases, we initially allocate enough space for
2085 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2086 + * be too small then we use GETACLCNT to find out the actual
2087 + * size, reallocate the ACL buffer, and then call GETACL again.
2090 +#define INITIAL_ACL_SIZE 16
2092 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2095 + int count; /* # of ACL entries allocated */
2096 + int naccess; /* # of access ACL entries */
2097 + int ndefault; /* # of default ACL entries */
2099 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2104 + count = INITIAL_ACL_SIZE;
2105 + if ((acl_d = sys_acl_init(count)) == NULL) {
2110 + * If there isn't enough space for the ACL entries we use
2111 + * GETACLCNT to determine the actual number of ACL entries
2112 + * reallocate and try again. This is in a loop because it
2113 + * is possible that someone else could modify the ACL and
2114 + * increase the number of entries between the call to
2115 + * GETACLCNT and the call to GETACL.
2117 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2118 + && errno == ENOSPC) {
2120 + sys_acl_free_acl(acl_d);
2122 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2126 + if ((acl_d = sys_acl_init(count)) == NULL) {
2132 + sys_acl_free_acl(acl_d);
2137 + * calculate the number of access and default ACL entries
2139 + * Note: we assume that the acl() system call returned a
2140 + * well formed ACL which is sorted so that all of the
2141 + * access ACL entries preceed any default ACL entries
2143 + for (naccess = 0; naccess < count; naccess++) {
2144 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2147 + ndefault = count - naccess;
2150 + * if the caller wants the default ACL we have to copy
2151 + * the entries down to the start of the acl[] buffer
2152 + * and mask out the ACL_DEFAULT flag from the type field
2154 + if (type == SMB_ACL_TYPE_DEFAULT) {
2157 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2158 + acl_d->acl[i] = acl_d->acl[j];
2159 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2162 + acl_d->count = ndefault;
2164 + acl_d->count = naccess;
2170 +SMB_ACL_T sys_acl_get_fd(int fd)
2173 + int count; /* # of ACL entries allocated */
2174 + int naccess; /* # of access ACL entries */
2176 + count = INITIAL_ACL_SIZE;
2177 + if ((acl_d = sys_acl_init(count)) == NULL) {
2181 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2182 + && errno == ENOSPC) {
2184 + sys_acl_free_acl(acl_d);
2186 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2190 + if ((acl_d = sys_acl_init(count)) == NULL) {
2196 + sys_acl_free_acl(acl_d);
2201 + * calculate the number of access ACL entries
2203 + for (naccess = 0; naccess < count; naccess++) {
2204 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2208 + acl_d->count = naccess;
2213 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2220 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2222 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2223 + && perm != SMB_ACL_EXECUTE) {
2228 + if (permset_d == NULL) {
2233 + *permset_d |= perm;
2238 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2240 + return *permset_d & perm;
2243 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2250 + * use an initial estimate of 20 bytes per ACL entry
2251 + * when allocating memory for the text representation
2255 + maxlen = 20 * acl_d->count;
2256 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2261 + for (i = 0; i < acl_d->count; i++) {
2262 + struct acl *ap = &acl_d->acl[i];
2271 + switch (ap->a_type) {
2273 + * for debugging purposes it's probably more
2274 + * useful to dump unknown tag types rather
2275 + * than just returning an error
2278 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2281 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2286 + case SMB_ACL_USER:
2287 + id = uidtoname(ap->a_id);
2288 + case SMB_ACL_USER_OBJ:
2292 + case SMB_ACL_GROUP:
2293 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2294 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2300 + case SMB_ACL_GROUP_OBJ:
2304 + case SMB_ACL_OTHER:
2308 + case SMB_ACL_MASK:
2314 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2315 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2316 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2319 + /* <tag> : <qualifier> : rwx \n \0 */
2320 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2323 + * If this entry would overflow the buffer
2324 + * allocate enough additional memory for this
2325 + * entry and an estimate of another 20 bytes
2326 + * for each entry still to be processed
2328 + if ((len + nbytes) > maxlen) {
2329 + char *oldtext = text;
2331 + maxlen += nbytes + 20 * (acl_d->count - i);
2333 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2334 + SAFE_FREE(oldtext);
2340 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2341 + len += nbytes - 1;
2350 +SMB_ACL_T sys_acl_init(int count)
2360 + * note that since the definition of the structure pointed
2361 + * to by the SMB_ACL_T includes the first element of the
2362 + * acl[] array, this actually allocates an ACL with room
2363 + * for (count+1) entries
2365 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2370 + a->size = count + 1;
2378 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2381 + SMB_ACL_ENTRY_T entry_d;
2383 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2388 + if (acl_d->count >= acl_d->size) {
2393 + entry_d = &acl_d->acl[acl_d->count++];
2394 + entry_d->a_type = 0;
2395 + entry_d->a_id = -1;
2396 + entry_d->a_perm = 0;
2397 + *entry_p = entry_d;
2402 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2404 + switch (tag_type) {
2405 + case SMB_ACL_USER:
2406 + case SMB_ACL_USER_OBJ:
2407 + case SMB_ACL_GROUP:
2408 + case SMB_ACL_GROUP_OBJ:
2409 + case SMB_ACL_OTHER:
2410 + case SMB_ACL_MASK:
2411 + entry_d->a_type = tag_type;
2421 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2423 + if (entry_d->a_type != SMB_ACL_GROUP
2424 + && entry_d->a_type != SMB_ACL_USER) {
2429 + entry_d->a_id = *((id_t *)qual_p);
2434 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2436 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2440 + entry_d->a_perm = *permset_d;
2446 + * sort the ACL and check it for validity
2448 + * if it's a minimal ACL with only 4 entries then we
2449 + * need to recalculate the mask permissions to make
2450 + * sure that they are the same as the GROUP_OBJ
2451 + * permissions as required by the UnixWare acl() system call.
2453 + * (note: since POSIX allows minimal ACLs which only contain
2454 + * 3 entries - ie there is no mask entry - we should, in theory,
2455 + * check for this and add a mask entry if necessary - however
2456 + * we "know" that the caller of this interface always specifies
2457 + * a mask so, in practice "this never happens" (tm) - if it *does*
2458 + * happen aclsort() will fail and return an error and someone will
2459 + * have to fix it ...)
2462 +static int acl_sort(SMB_ACL_T acl_d)
2464 + int fixmask = (acl_d->count <= 4);
2466 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2473 +int sys_acl_valid(SMB_ACL_T acl_d)
2475 + return acl_sort(acl_d);
2478 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2481 + struct acl *acl_p;
2483 + struct acl *acl_buf = NULL;
2486 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2491 + if (acl_sort(acl_d) != 0) {
2495 + acl_p = &acl_d->acl[0];
2496 + acl_count = acl_d->count;
2499 + * if it's a directory there is extra work to do
2500 + * since the acl() system call will replace both
2501 + * the access ACLs and the default ACLs (if any)
2503 + if (stat(name, &s) != 0) {
2506 + if (S_ISDIR(s.st_mode)) {
2507 + SMB_ACL_T acc_acl;
2508 + SMB_ACL_T def_acl;
2509 + SMB_ACL_T tmp_acl;
2512 + if (type == SMB_ACL_TYPE_ACCESS) {
2514 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2518 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2521 + if (tmp_acl == NULL) {
2526 + * allocate a temporary buffer for the complete ACL
2528 + acl_count = acc_acl->count + def_acl->count;
2529 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2531 + if (acl_buf == NULL) {
2532 + sys_acl_free_acl(tmp_acl);
2538 + * copy the access control and default entries into the buffer
2540 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2541 + acc_acl->count * sizeof(acl_buf[0]));
2543 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2544 + def_acl->count * sizeof(acl_buf[0]));
2547 + * set the ACL_DEFAULT flag on the default entries
2549 + for (i = acc_acl->count; i < acl_count; i++) {
2550 + acl_buf[i].a_type |= ACL_DEFAULT;
2553 + sys_acl_free_acl(tmp_acl);
2555 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2560 + ret = acl(name, SETACL, acl_count, acl_p);
2562 + SAFE_FREE(acl_buf);
2567 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2569 + if (acl_sort(acl_d) != 0) {
2573 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2576 +int sys_acl_delete_def_file(const char *path)
2582 + * fetching the access ACL and rewriting it has
2583 + * the effect of deleting the default ACL
2585 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2589 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2591 + sys_acl_free_acl(acl_d);
2596 +int sys_acl_free_text(char *text)
2602 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2608 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2613 +#elif defined(HAVE_HPUX_ACLS)
2617 + * Based on the Solaris/SCO code - with modifications.
2621 + * Note that while this code implements sufficient functionality
2622 + * to support the sys_acl_* interfaces it does not provide all
2623 + * of the semantics of the POSIX ACL interfaces.
2625 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2626 + * from a call to sys_acl_get_entry() should not be assumed to be
2627 + * valid after calling any of the following functions, which may
2628 + * reorder the entries in the ACL.
2631 + * sys_acl_set_file()
2632 + * sys_acl_set_fd()
2635 +/* This checks if the POSIX ACL system call is defined */
2636 +/* which basically corresponds to whether JFS 3.3 or */
2637 +/* higher is installed. If acl() was called when it */
2638 +/* isn't defined, it causes the process to core dump */
2639 +/* so it is important to check this and avoid acl() */
2640 +/* calls if it isn't there. */
2642 +static BOOL hpux_acl_call_presence(void)
2645 + shl_t handle = NULL;
2648 + static BOOL already_checked=0;
2650 + if(already_checked)
2654 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2656 + if(ret_val != 0) {
2657 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2658 + ret_val, errno, strerror(errno)));
2659 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2663 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2665 + already_checked = True;
2669 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2671 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2676 + if (entry_p == NULL) {
2681 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2685 + if (acl_d->next < 0) {
2690 + if (acl_d->next >= acl_d->count) {
2694 + *entry_p = &acl_d->acl[acl_d->next++];
2699 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2701 + *type_p = entry_d->a_type;
2706 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2708 + *permset_p = &entry_d->a_perm;
2713 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2715 + if (entry_d->a_type != SMB_ACL_USER
2716 + && entry_d->a_type != SMB_ACL_GROUP) {
2721 + return &entry_d->a_id;
2725 + * There is no way of knowing what size the ACL returned by
2726 + * ACL_GET will be unless you first call ACL_CNT which means
2727 + * making an additional system call.
2729 + * In the hope of avoiding the cost of the additional system
2730 + * call in most cases, we initially allocate enough space for
2731 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2732 + * be too small then we use ACL_CNT to find out the actual
2733 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2736 +#define INITIAL_ACL_SIZE 16
2738 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2741 + int count; /* # of ACL entries allocated */
2742 + int naccess; /* # of access ACL entries */
2743 + int ndefault; /* # of default ACL entries */
2745 + if(hpux_acl_call_presence() == False) {
2746 + /* Looks like we don't have the acl() system call on HPUX.
2747 + * May be the system doesn't have the latest version of JFS.
2752 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2757 + count = INITIAL_ACL_SIZE;
2758 + if ((acl_d = sys_acl_init(count)) == NULL) {
2763 + * If there isn't enough space for the ACL entries we use
2764 + * ACL_CNT to determine the actual number of ACL entries
2765 + * reallocate and try again. This is in a loop because it
2766 + * is possible that someone else could modify the ACL and
2767 + * increase the number of entries between the call to
2768 + * ACL_CNT and the call to ACL_GET.
2770 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2772 + sys_acl_free_acl(acl_d);
2774 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2778 + if ((acl_d = sys_acl_init(count)) == NULL) {
2784 + sys_acl_free_acl(acl_d);
2789 + * calculate the number of access and default ACL entries
2791 + * Note: we assume that the acl() system call returned a
2792 + * well formed ACL which is sorted so that all of the
2793 + * access ACL entries preceed any default ACL entries
2795 + for (naccess = 0; naccess < count; naccess++) {
2796 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2799 + ndefault = count - naccess;
2802 + * if the caller wants the default ACL we have to copy
2803 + * the entries down to the start of the acl[] buffer
2804 + * and mask out the ACL_DEFAULT flag from the type field
2806 + if (type == SMB_ACL_TYPE_DEFAULT) {
2809 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2810 + acl_d->acl[i] = acl_d->acl[j];
2811 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2814 + acl_d->count = ndefault;
2816 + acl_d->count = naccess;
2822 +SMB_ACL_T sys_acl_get_fd(int fd)
2825 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2828 + files_struct *fsp = file_find_fd(fd);
2830 + if (fsp == NULL) {
2836 + * We know we're in the same conn context. So we
2837 + * can use the relative path.
2840 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2843 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2850 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2852 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2853 + && perm != SMB_ACL_EXECUTE) {
2858 + if (permset_d == NULL) {
2863 + *permset_d |= perm;
2868 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2870 + return *permset_d & perm;
2873 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2880 + * use an initial estimate of 20 bytes per ACL entry
2881 + * when allocating memory for the text representation
2885 + maxlen = 20 * acl_d->count;
2886 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2891 + for (i = 0; i < acl_d->count; i++) {
2892 + struct acl *ap = &acl_d->acl[i];
2901 + switch (ap->a_type) {
2903 + * for debugging purposes it's probably more
2904 + * useful to dump unknown tag types rather
2905 + * than just returning an error
2908 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2911 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2916 + case SMB_ACL_USER:
2917 + id = uidtoname(ap->a_id);
2918 + case SMB_ACL_USER_OBJ:
2922 + case SMB_ACL_GROUP:
2923 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2924 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2930 + case SMB_ACL_GROUP_OBJ:
2934 + case SMB_ACL_OTHER:
2938 + case SMB_ACL_MASK:
2944 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2945 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2946 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2949 + /* <tag> : <qualifier> : rwx \n \0 */
2950 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2953 + * If this entry would overflow the buffer
2954 + * allocate enough additional memory for this
2955 + * entry and an estimate of another 20 bytes
2956 + * for each entry still to be processed
2958 + if ((len + nbytes) > maxlen) {
2959 + char *oldtext = text;
2961 + maxlen += nbytes + 20 * (acl_d->count - i);
2963 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2970 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2971 + len += nbytes - 1;
2980 +SMB_ACL_T sys_acl_init(int count)
2990 + * note that since the definition of the structure pointed
2991 + * to by the SMB_ACL_T includes the first element of the
2992 + * acl[] array, this actually allocates an ACL with room
2993 + * for (count+1) entries
2995 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
3000 + a->size = count + 1;
3008 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3011 + SMB_ACL_ENTRY_T entry_d;
3013 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3018 + if (acl_d->count >= acl_d->size) {
3023 + entry_d = &acl_d->acl[acl_d->count++];
3024 + entry_d->a_type = 0;
3025 + entry_d->a_id = -1;
3026 + entry_d->a_perm = 0;
3027 + *entry_p = entry_d;
3032 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3034 + switch (tag_type) {
3035 + case SMB_ACL_USER:
3036 + case SMB_ACL_USER_OBJ:
3037 + case SMB_ACL_GROUP:
3038 + case SMB_ACL_GROUP_OBJ:
3039 + case SMB_ACL_OTHER:
3040 + case SMB_ACL_MASK:
3041 + entry_d->a_type = tag_type;
3051 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3053 + if (entry_d->a_type != SMB_ACL_GROUP
3054 + && entry_d->a_type != SMB_ACL_USER) {
3059 + entry_d->a_id = *((id_t *)qual_p);
3064 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3066 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3070 + entry_d->a_perm = *permset_d;
3075 +/* Structure to capture the count for each type of ACE. */
3077 +struct hpux_acl_types {
3081 + int n_def_user_obj;
3086 + int n_def_group_obj;
3090 + int n_def_other_obj;
3093 + int n_def_class_obj;
3095 + int n_illegal_obj;
3099 + * Counts the different number of objects in a given array of ACL
3103 + * acl_count - Count of ACLs in the array of ACL strucutres.
3104 + * aclp - Array of ACL structures.
3105 + * acl_type_count - Pointer to acl_types structure. Should already be
3109 + * acl_type_count - This structure is filled up with counts of various
3113 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3117 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3119 + for(i=0;i<acl_count;i++) {
3120 + switch(aclp[i].a_type) {
3122 + acl_type_count->n_user++;
3125 + acl_type_count->n_user_obj++;
3127 + case DEF_USER_OBJ:
3128 + acl_type_count->n_def_user_obj++;
3131 + acl_type_count->n_group++;
3134 + acl_type_count->n_group_obj++;
3136 + case DEF_GROUP_OBJ:
3137 + acl_type_count->n_def_group_obj++;
3140 + acl_type_count->n_other_obj++;
3142 + case DEF_OTHER_OBJ:
3143 + acl_type_count->n_def_other_obj++;
3146 + acl_type_count->n_class_obj++;
3148 + case DEF_CLASS_OBJ:
3149 + acl_type_count->n_def_class_obj++;
3152 + acl_type_count->n_def_user++;
3155 + acl_type_count->n_def_group++;
3158 + acl_type_count->n_illegal_obj++;
3164 +/* swap_acl_entries: Swaps two ACL entries.
3166 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3169 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3171 + struct acl temp_acl;
3173 + temp_acl.a_type = aclp0->a_type;
3174 + temp_acl.a_id = aclp0->a_id;
3175 + temp_acl.a_perm = aclp0->a_perm;
3177 + aclp0->a_type = aclp1->a_type;
3178 + aclp0->a_id = aclp1->a_id;
3179 + aclp0->a_perm = aclp1->a_perm;
3181 + aclp1->a_type = temp_acl.a_type;
3182 + aclp1->a_id = temp_acl.a_id;
3183 + aclp1->a_perm = temp_acl.a_perm;
3186 +/* prohibited_duplicate_type
3187 + * Identifies if given ACL type can have duplicate entries or
3190 + * Inputs: acl_type - ACL Type.
3196 + * True - If the ACL type matches any of the prohibited types.
3197 + * False - If the ACL type doesn't match any of the prohibited types.
3200 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3202 + switch(acl_type) {
3213 +/* get_needed_class_perm
3214 + * Returns the permissions of a ACL structure only if the ACL
3215 + * type matches one of the pre-determined types for computing
3216 + * CLASS_OBJ permissions.
3218 + * Inputs: aclp - Pointer to ACL structure.
3221 +static int hpux_get_needed_class_perm(struct acl *aclp)
3223 + switch(aclp->a_type) {
3227 + case DEF_USER_OBJ:
3229 + case DEF_GROUP_OBJ:
3231 + case DEF_CLASS_OBJ:
3232 + case DEF_OTHER_OBJ:
3233 + return aclp->a_perm;
3239 +/* acl_sort for HPUX.
3240 + * Sorts the array of ACL structures as per the description in
3241 + * aclsort man page. Refer to aclsort man page for more details
3245 + * acl_count - Count of ACLs in the array of ACL structures.
3246 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3248 + * aclp - Array of ACL structures.
3252 + * aclp - Sorted array of ACL structures.
3256 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3257 + * debug log in case of failure.
3260 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3262 +#if !defined(HAVE_HPUX_ACLSORT)
3264 + * The aclsort() system call is availabe on the latest HPUX General
3265 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3266 + * function. Because, we don't want to update to a new
3267 + * HPUX GR bundle just for aclsort() call.
3270 + struct hpux_acl_types acl_obj_count;
3271 + int n_class_obj_perm = 0;
3275 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3279 + if(aclp == NULL) {
3280 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3284 + /* Count different types of ACLs in the ACLs array */
3286 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3288 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3289 + * CLASS_OBJ and OTHER_OBJ
3292 + if( (acl_obj_count.n_user_obj != 1) ||
3293 + (acl_obj_count.n_group_obj != 1) ||
3294 + (acl_obj_count.n_class_obj != 1) ||
3295 + (acl_obj_count.n_other_obj != 1)
3297 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3298 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3302 + /* If any of the default objects are present, there should be only
3303 + * one of them each.
3306 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3307 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3308 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3309 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3313 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3316 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3317 + * same ACL type, sort by ACL id.
3319 + * I am using the trival kind of sorting method here because, performance isn't
3320 + * really effected by the ACLs feature. More over there aren't going to be more
3321 + * than 17 entries on HPUX.
3324 + for(i=0; i<acl_count;i++) {
3325 + for (j=i+1; j<acl_count; j++) {
3326 + if( aclp[i].a_type > aclp[j].a_type ) {
3327 + /* ACL entries out of order, swap them */
3329 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3331 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3333 + /* ACL entries of same type, sort by id */
3335 + if(aclp[i].a_id > aclp[j].a_id) {
3336 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3337 + } else if (aclp[i].a_id == aclp[j].a_id) {
3338 + /* We have a duplicate entry. */
3339 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3340 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3341 + aclp[i].a_type, aclp[i].a_id));
3350 + /* set the class obj permissions to the computed one. */
3352 + int n_class_obj_index = -1;
3354 + for(i=0;i<acl_count;i++) {
3355 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3357 + if(aclp[i].a_type == CLASS_OBJ)
3358 + n_class_obj_index = i;
3360 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3365 + return aclsort(acl_count, calclass, aclp);
3370 + * sort the ACL and check it for validity
3372 + * if it's a minimal ACL with only 4 entries then we
3373 + * need to recalculate the mask permissions to make
3374 + * sure that they are the same as the GROUP_OBJ
3375 + * permissions as required by the UnixWare acl() system call.
3377 + * (note: since POSIX allows minimal ACLs which only contain
3378 + * 3 entries - ie there is no mask entry - we should, in theory,
3379 + * check for this and add a mask entry if necessary - however
3380 + * we "know" that the caller of this interface always specifies
3381 + * a mask so, in practice "this never happens" (tm) - if it *does*
3382 + * happen aclsort() will fail and return an error and someone will
3383 + * have to fix it ...)
3386 +static int acl_sort(SMB_ACL_T acl_d)
3388 + int fixmask = (acl_d->count <= 4);
3390 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3397 +int sys_acl_valid(SMB_ACL_T acl_d)
3399 + return acl_sort(acl_d);
3402 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3405 + struct acl *acl_p;
3407 + struct acl *acl_buf = NULL;
3410 + if(hpux_acl_call_presence() == False) {
3411 + /* Looks like we don't have the acl() system call on HPUX.
3412 + * May be the system doesn't have the latest version of JFS.
3418 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3423 + if (acl_sort(acl_d) != 0) {
3427 + acl_p = &acl_d->acl[0];
3428 + acl_count = acl_d->count;
3431 + * if it's a directory there is extra work to do
3432 + * since the acl() system call will replace both
3433 + * the access ACLs and the default ACLs (if any)
3435 + if (stat(name, &s) != 0) {
3438 + if (S_ISDIR(s.st_mode)) {
3439 + SMB_ACL_T acc_acl;
3440 + SMB_ACL_T def_acl;
3441 + SMB_ACL_T tmp_acl;
3444 + if (type == SMB_ACL_TYPE_ACCESS) {
3446 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3450 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3453 + if (tmp_acl == NULL) {
3458 + * allocate a temporary buffer for the complete ACL
3460 + acl_count = acc_acl->count + def_acl->count;
3461 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3463 + if (acl_buf == NULL) {
3464 + sys_acl_free_acl(tmp_acl);
3470 + * copy the access control and default entries into the buffer
3472 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3473 + acc_acl->count * sizeof(acl_buf[0]));
3475 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3476 + def_acl->count * sizeof(acl_buf[0]));
3479 + * set the ACL_DEFAULT flag on the default entries
3481 + for (i = acc_acl->count; i < acl_count; i++) {
3482 + acl_buf[i].a_type |= ACL_DEFAULT;
3485 + sys_acl_free_acl(tmp_acl);
3487 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3492 + ret = acl(name, ACL_SET, acl_count, acl_p);
3501 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3504 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3507 + files_struct *fsp = file_find_fd(fd);
3509 + if (fsp == NULL) {
3514 + if (acl_sort(acl_d) != 0) {
3519 + * We know we're in the same conn context. So we
3520 + * can use the relative path.
3523 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3526 +int sys_acl_delete_def_file(const char *path)
3532 + * fetching the access ACL and rewriting it has
3533 + * the effect of deleting the default ACL
3535 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3539 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3541 + sys_acl_free_acl(acl_d);
3546 +int sys_acl_free_text(char *text)
3552 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3558 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3563 +#elif defined(HAVE_IRIX_ACLS)
3565 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3567 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3572 + if (entry_p == NULL) {
3577 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3581 + if (acl_d->next < 0) {
3586 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3590 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3595 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3597 + *type_p = entry_d->ae_tag;
3602 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3604 + *permset_p = entry_d;
3609 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3611 + if (entry_d->ae_tag != SMB_ACL_USER
3612 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3617 + return &entry_d->ae_id;
3620 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3624 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3628 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3633 + a->freeaclp = True;
3637 +SMB_ACL_T sys_acl_get_fd(int fd)
3641 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3645 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3650 + a->freeaclp = True;
3654 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3656 + permset_d->ae_perm = 0;
3661 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3663 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3664 + && perm != SMB_ACL_EXECUTE) {
3669 + if (permset_d == NULL) {
3674 + permset_d->ae_perm |= perm;
3679 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3681 + return permset_d->ae_perm & perm;
3684 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3686 + return acl_to_text(acl_d->aclp, len_p);
3689 +SMB_ACL_T sys_acl_init(int count)
3698 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3704 + a->freeaclp = False;
3705 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3706 + a->aclp->acl_cnt = 0;
3712 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3715 + SMB_ACL_ENTRY_T entry_d;
3717 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3722 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3727 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3728 + entry_d->ae_tag = 0;
3729 + entry_d->ae_id = 0;
3730 + entry_d->ae_perm = 0;
3731 + *entry_p = entry_d;
3736 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3738 + switch (tag_type) {
3739 + case SMB_ACL_USER:
3740 + case SMB_ACL_USER_OBJ:
3741 + case SMB_ACL_GROUP:
3742 + case SMB_ACL_GROUP_OBJ:
3743 + case SMB_ACL_OTHER:
3744 + case SMB_ACL_MASK:
3745 + entry_d->ae_tag = tag_type;
3755 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3757 + if (entry_d->ae_tag != SMB_ACL_GROUP
3758 + && entry_d->ae_tag != SMB_ACL_USER) {
3763 + entry_d->ae_id = *((id_t *)qual_p);
3768 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3770 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3774 + entry_d->ae_perm = permset_d->ae_perm;
3779 +int sys_acl_valid(SMB_ACL_T acl_d)
3781 + return acl_valid(acl_d->aclp);
3784 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3786 + return acl_set_file(name, type, acl_d->aclp);
3789 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3791 + return acl_set_fd(fd, acl_d->aclp);
3794 +int sys_acl_delete_def_file(const char *name)
3796 + return acl_delete_def_file(name);
3799 +int sys_acl_free_text(char *text)
3801 + return acl_free(text);
3804 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3806 + if (acl_d->freeaclp) {
3807 + acl_free(acl_d->aclp);
3813 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3818 +#elif defined(HAVE_AIX_ACLS)
3820 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3822 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3824 + struct acl_entry_link *link;
3825 + struct new_acl_entry *entry;
3828 + DEBUG(10,("This is the count: %d\n",theacl->count));
3830 + /* Check if count was previously set to -1. *
3831 + * If it was, that means we reached the end *
3832 + * of the acl last time. */
3833 + if(theacl->count == -1)
3837 + /* To get to the next acl, traverse linked list until index *
3838 + * of acl matches the count we are keeping. This count is *
3839 + * incremented each time we return an acl entry. */
3841 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3842 + link = link->nextp;
3844 + entry = *entry_p = link->entryp;
3846 + DEBUG(10,("*entry_p is %d\n",entry_p));
3847 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3849 + /* Increment count */
3851 + if(link->nextp == NULL)
3852 + theacl->count = -1;
3857 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3859 + /* Initialize tag type */
3862 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3864 + /* Depending on what type of entry we have, *
3865 + * return tag type. */
3866 + switch(entry_d->ace_id->id_type) {
3868 + *tag_type_p = SMB_ACL_USER;
3871 + *tag_type_p = SMB_ACL_GROUP;
3874 + case SMB_ACL_USER_OBJ:
3875 + case SMB_ACL_GROUP_OBJ:
3876 + case SMB_ACL_OTHER:
3877 + *tag_type_p = entry_d->ace_id->id_type;
3887 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3889 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3890 + *permset_p = &entry_d->ace_access;
3891 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3892 + if(!(**permset_p & S_IXUSR) &&
3893 + !(**permset_p & S_IWUSR) &&
3894 + !(**permset_p & S_IRUSR) &&
3895 + (**permset_p != 0))
3898 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3902 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3904 + return(entry_d->ace_id->id_data);
3907 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3909 + struct acl *file_acl = (struct acl *)NULL;
3910 + struct acl_entry *acl_entry;
3911 + struct new_acl_entry *new_acl_entry;
3912 + struct ace_id *idp;
3913 + struct acl_entry_link *acl_entry_link;
3914 + struct acl_entry_link *acl_entry_link_head;
3919 + /* AIX has no DEFAULT */
3920 + if ( type == SMB_ACL_TYPE_DEFAULT )
3923 + /* Get the acl using statacl */
3925 + DEBUG(10,("Entering sys_acl_get_file\n"));
3926 + DEBUG(10,("path_p is %s\n",path_p));
3928 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3930 + if(file_acl == NULL) {
3932 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3936 + memset(file_acl,0,BUFSIZ);
3938 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3940 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3941 + SAFE_FREE(file_acl);
3945 + DEBUG(10,("Got facl and returned it\n"));
3947 + /* Point to the first acl entry in the acl */
3948 + acl_entry = file_acl->acl_ext;
3950 + /* Begin setting up the head of the linked list *
3951 + * that will be used for the storing the acl *
3952 + * in a way that is useful for the posix_acls.c *
3955 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3956 + if(acl_entry_link_head == NULL)
3959 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3960 + if(acl_entry_link->entryp == NULL) {
3961 + SAFE_FREE(file_acl);
3963 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3967 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3968 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3970 + /* Check if the extended acl bit is on. *
3971 + * If it isn't, do not show the *
3972 + * contents of the acl since AIX intends *
3973 + * the extended info to remain unused */
3975 + if(file_acl->acl_mode & S_IXACL){
3976 + /* while we are not pointing to the very end */
3977 + while(acl_entry < acl_last(file_acl)) {
3978 + /* before we malloc anything, make sure this is */
3979 + /* a valid acl entry and one that we want to map */
3980 + idp = id_nxt(acl_entry->ace_id);
3981 + if((acl_entry->ace_type == ACC_SPECIFY ||
3982 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3983 + acl_entry = acl_nxt(acl_entry);
3987 + idp = acl_entry->ace_id;
3989 + /* Check if this is the first entry in the linked list. *
3990 + * The first entry needs to keep prevp pointing to NULL *
3991 + * and already has entryp allocated. */
3993 + if(acl_entry_link_head->count != 0) {
3994 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3996 + if(acl_entry_link->nextp == NULL) {
3997 + SAFE_FREE(file_acl);
3999 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4003 + acl_entry_link->nextp->prevp = acl_entry_link;
4004 + acl_entry_link = acl_entry_link->nextp;
4005 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4006 + if(acl_entry_link->entryp == NULL) {
4007 + SAFE_FREE(file_acl);
4009 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4012 + acl_entry_link->nextp = NULL;
4015 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4017 + /* Don't really need this since all types are going *
4018 + * to be specified but, it's better than leaving it 0 */
4020 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4022 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4024 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4026 + /* The access in the acl entries must be left shifted by *
4027 + * three bites, because they will ultimately be compared *
4028 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4030 + switch(acl_entry->ace_type){
4033 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4034 + acl_entry_link->entryp->ace_access <<= 6;
4035 + acl_entry_link_head->count++;
4038 + /* Since there is no way to return a DENY acl entry *
4039 + * change to PERMIT and then shift. */
4040 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4041 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4042 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4043 + acl_entry_link->entryp->ace_access <<= 6;
4044 + acl_entry_link_head->count++;
4050 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4051 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4053 + acl_entry = acl_nxt(acl_entry);
4055 + } /* end of if enabled */
4057 + /* Since owner, group, other acl entries are not *
4058 + * part of the acl entries in an acl, they must *
4059 + * be dummied up to become part of the list. */
4061 + for( i = 1; i < 4; i++) {
4062 + DEBUG(10,("i is %d\n",i));
4063 + if(acl_entry_link_head->count != 0) {
4064 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4065 + if(acl_entry_link->nextp == NULL) {
4066 + SAFE_FREE(file_acl);
4068 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4072 + acl_entry_link->nextp->prevp = acl_entry_link;
4073 + acl_entry_link = acl_entry_link->nextp;
4074 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4075 + if(acl_entry_link->entryp == NULL) {
4076 + SAFE_FREE(file_acl);
4078 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4083 + acl_entry_link->nextp = NULL;
4085 + new_acl_entry = acl_entry_link->entryp;
4086 + idp = new_acl_entry->ace_id;
4088 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4089 + new_acl_entry->ace_type = ACC_PERMIT;
4090 + idp->id_len = sizeof(struct ace_id);
4091 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4092 + memset(idp->id_data,0,sizeof(uid_t));
4096 + new_acl_entry->ace_access = file_acl->g_access << 6;
4097 + idp->id_type = SMB_ACL_GROUP_OBJ;
4101 + new_acl_entry->ace_access = file_acl->o_access << 6;
4102 + idp->id_type = SMB_ACL_OTHER;
4106 + new_acl_entry->ace_access = file_acl->u_access << 6;
4107 + idp->id_type = SMB_ACL_USER_OBJ;
4115 + acl_entry_link_head->count++;
4116 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4119 + acl_entry_link_head->count = 0;
4120 + SAFE_FREE(file_acl);
4122 + return(acl_entry_link_head);
4125 +SMB_ACL_T sys_acl_get_fd(int fd)
4127 + struct acl *file_acl = (struct acl *)NULL;
4128 + struct acl_entry *acl_entry;
4129 + struct new_acl_entry *new_acl_entry;
4130 + struct ace_id *idp;
4131 + struct acl_entry_link *acl_entry_link;
4132 + struct acl_entry_link *acl_entry_link_head;
4137 + /* Get the acl using fstatacl */
4139 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4140 + DEBUG(10,("fd is %d\n",fd));
4141 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4143 + if(file_acl == NULL) {
4145 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4149 + memset(file_acl,0,BUFSIZ);
4151 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4153 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4154 + SAFE_FREE(file_acl);
4158 + DEBUG(10,("Got facl and returned it\n"));
4160 + /* Point to the first acl entry in the acl */
4162 + acl_entry = file_acl->acl_ext;
4163 + /* Begin setting up the head of the linked list *
4164 + * that will be used for the storing the acl *
4165 + * in a way that is useful for the posix_acls.c *
4168 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4169 + if(acl_entry_link_head == NULL){
4170 + SAFE_FREE(file_acl);
4174 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4176 + if(acl_entry_link->entryp == NULL) {
4178 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4179 + SAFE_FREE(file_acl);
4183 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4184 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4186 + /* Check if the extended acl bit is on. *
4187 + * If it isn't, do not show the *
4188 + * contents of the acl since AIX intends *
4189 + * the extended info to remain unused */
4191 + if(file_acl->acl_mode & S_IXACL){
4192 + /* while we are not pointing to the very end */
4193 + while(acl_entry < acl_last(file_acl)) {
4194 + /* before we malloc anything, make sure this is */
4195 + /* a valid acl entry and one that we want to map */
4197 + idp = id_nxt(acl_entry->ace_id);
4198 + if((acl_entry->ace_type == ACC_SPECIFY ||
4199 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4200 + acl_entry = acl_nxt(acl_entry);
4204 + idp = acl_entry->ace_id;
4206 + /* Check if this is the first entry in the linked list. *
4207 + * The first entry needs to keep prevp pointing to NULL *
4208 + * and already has entryp allocated. */
4210 + if(acl_entry_link_head->count != 0) {
4211 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4212 + if(acl_entry_link->nextp == NULL) {
4214 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4215 + SAFE_FREE(file_acl);
4218 + acl_entry_link->nextp->prevp = acl_entry_link;
4219 + acl_entry_link = acl_entry_link->nextp;
4220 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4221 + if(acl_entry_link->entryp == NULL) {
4223 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4224 + SAFE_FREE(file_acl);
4228 + acl_entry_link->nextp = NULL;
4231 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4233 + /* Don't really need this since all types are going *
4234 + * to be specified but, it's better than leaving it 0 */
4236 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4237 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4239 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4241 + /* The access in the acl entries must be left shifted by *
4242 + * three bites, because they will ultimately be compared *
4243 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4245 + switch(acl_entry->ace_type){
4248 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4249 + acl_entry_link->entryp->ace_access <<= 6;
4250 + acl_entry_link_head->count++;
4253 + /* Since there is no way to return a DENY acl entry *
4254 + * change to PERMIT and then shift. */
4255 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4256 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4257 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4258 + acl_entry_link->entryp->ace_access <<= 6;
4259 + acl_entry_link_head->count++;
4265 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4266 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4268 + acl_entry = acl_nxt(acl_entry);
4270 + } /* end of if enabled */
4272 + /* Since owner, group, other acl entries are not *
4273 + * part of the acl entries in an acl, they must *
4274 + * be dummied up to become part of the list. */
4276 + for( i = 1; i < 4; i++) {
4277 + DEBUG(10,("i is %d\n",i));
4278 + if(acl_entry_link_head->count != 0){
4279 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4280 + if(acl_entry_link->nextp == NULL) {
4282 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4283 + SAFE_FREE(file_acl);
4287 + acl_entry_link->nextp->prevp = acl_entry_link;
4288 + acl_entry_link = acl_entry_link->nextp;
4289 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4291 + if(acl_entry_link->entryp == NULL) {
4292 + SAFE_FREE(file_acl);
4294 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4299 + acl_entry_link->nextp = NULL;
4301 + new_acl_entry = acl_entry_link->entryp;
4302 + idp = new_acl_entry->ace_id;
4304 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4305 + new_acl_entry->ace_type = ACC_PERMIT;
4306 + idp->id_len = sizeof(struct ace_id);
4307 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4308 + memset(idp->id_data,0,sizeof(uid_t));
4312 + new_acl_entry->ace_access = file_acl->g_access << 6;
4313 + idp->id_type = SMB_ACL_GROUP_OBJ;
4317 + new_acl_entry->ace_access = file_acl->o_access << 6;
4318 + idp->id_type = SMB_ACL_OTHER;
4322 + new_acl_entry->ace_access = file_acl->u_access << 6;
4323 + idp->id_type = SMB_ACL_USER_OBJ;
4330 + acl_entry_link_head->count++;
4331 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4334 + acl_entry_link_head->count = 0;
4335 + SAFE_FREE(file_acl);
4337 + return(acl_entry_link_head);
4340 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4342 + *permset = *permset & ~0777;
4346 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4349 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4353 + DEBUG(10,("This is the permset now: %d\n",*permset));
4357 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4362 +SMB_ACL_T sys_acl_init( int count)
4364 + struct acl_entry_link *theacl = NULL;
4366 + DEBUG(10,("Entering sys_acl_init\n"));
4368 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4369 + if(theacl == NULL) {
4371 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4375 + theacl->count = 0;
4376 + theacl->nextp = NULL;
4377 + theacl->prevp = NULL;
4378 + theacl->entryp = NULL;
4379 + DEBUG(10,("Exiting sys_acl_init\n"));
4383 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4385 + struct acl_entry_link *theacl;
4386 + struct acl_entry_link *acl_entryp;
4387 + struct acl_entry_link *temp_entry;
4390 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4392 + theacl = acl_entryp = *pacl;
4394 + /* Get to the end of the acl before adding entry */
4396 + for(counting=0; counting < theacl->count; counting++){
4397 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4398 + temp_entry = acl_entryp;
4399 + acl_entryp = acl_entryp->nextp;
4402 + if(theacl->count != 0){
4403 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4404 + if(acl_entryp == NULL) {
4406 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4410 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4411 + acl_entryp->prevp = temp_entry;
4412 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4415 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4416 + if(*pentry == NULL) {
4418 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4422 + memset(*pentry,0,sizeof(struct new_acl_entry));
4423 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4424 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4425 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4426 + acl_entryp->nextp = NULL;
4428 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4432 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4434 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4435 + entry->ace_id->id_type = tagtype;
4436 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4437 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4440 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4442 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4443 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4444 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4448 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4450 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4451 + if(!(*permset & S_IXUSR) &&
4452 + !(*permset & S_IWUSR) &&
4453 + !(*permset & S_IRUSR) &&
4457 + entry->ace_access = *permset;
4458 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4459 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4463 +int sys_acl_valid( SMB_ACL_T theacl )
4466 + int group_obj = 0;
4467 + int other_obj = 0;
4468 + struct acl_entry_link *acl_entry;
4470 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4471 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4472 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4473 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4476 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4478 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4484 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4486 + struct acl_entry_link *acl_entry_link = NULL;
4487 + struct acl *file_acl = NULL;
4488 + struct acl *file_acl_temp = NULL;
4489 + struct acl_entry *acl_entry = NULL;
4490 + struct ace_id *ace_id = NULL;
4497 + DEBUG(10,("Entering sys_acl_set_file\n"));
4498 + DEBUG(10,("File name is %s\n",name));
4500 + /* AIX has no default ACL */
4501 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4504 + acl_length = BUFSIZ;
4505 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4507 + if(file_acl == NULL) {
4509 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4513 + memset(file_acl,0,BUFSIZ);
4515 + file_acl->acl_len = ACL_SIZ;
4516 + file_acl->acl_mode = S_IXACL;
4518 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4519 + acl_entry_link->entryp->ace_access >>= 6;
4520 + id_type = acl_entry_link->entryp->ace_id->id_type;
4523 + case SMB_ACL_USER_OBJ:
4524 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4526 + case SMB_ACL_GROUP_OBJ:
4527 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4529 + case SMB_ACL_OTHER:
4530 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4532 + case SMB_ACL_MASK:
4536 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4537 + acl_length += sizeof(struct acl_entry);
4538 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4539 + if(file_acl_temp == NULL) {
4540 + SAFE_FREE(file_acl);
4542 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4546 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4547 + SAFE_FREE(file_acl);
4548 + file_acl = file_acl_temp;
4551 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4552 + file_acl->acl_len += sizeof(struct acl_entry);
4553 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4554 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4556 + /* In order to use this, we'll need to wait until we can get denies */
4557 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4558 + acl_entry->ace_type = ACC_SPECIFY; */
4560 + acl_entry->ace_type = ACC_SPECIFY;
4562 + ace_id = acl_entry->ace_id;
4564 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4565 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4566 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4567 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4568 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4571 + rc = chacl(name,file_acl,file_acl->acl_len);
4572 + DEBUG(10,("errno is %d\n",errno));
4573 + DEBUG(10,("return code is %d\n",rc));
4574 + SAFE_FREE(file_acl);
4575 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4579 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4581 + struct acl_entry_link *acl_entry_link = NULL;
4582 + struct acl *file_acl = NULL;
4583 + struct acl *file_acl_temp = NULL;
4584 + struct acl_entry *acl_entry = NULL;
4585 + struct ace_id *ace_id = NULL;
4591 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4592 + acl_length = BUFSIZ;
4593 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4595 + if(file_acl == NULL) {
4597 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4601 + memset(file_acl,0,BUFSIZ);
4603 + file_acl->acl_len = ACL_SIZ;
4604 + file_acl->acl_mode = S_IXACL;
4606 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4607 + acl_entry_link->entryp->ace_access >>= 6;
4608 + id_type = acl_entry_link->entryp->ace_id->id_type;
4609 + DEBUG(10,("The id_type is %d\n",id_type));
4612 + case SMB_ACL_USER_OBJ:
4613 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4615 + case SMB_ACL_GROUP_OBJ:
4616 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4618 + case SMB_ACL_OTHER:
4619 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4621 + case SMB_ACL_MASK:
4625 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4626 + acl_length += sizeof(struct acl_entry);
4627 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4628 + if(file_acl_temp == NULL) {
4629 + SAFE_FREE(file_acl);
4631 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4635 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4636 + SAFE_FREE(file_acl);
4637 + file_acl = file_acl_temp;
4640 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4641 + file_acl->acl_len += sizeof(struct acl_entry);
4642 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4643 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4645 + /* In order to use this, we'll need to wait until we can get denies */
4646 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4647 + acl_entry->ace_type = ACC_SPECIFY; */
4649 + acl_entry->ace_type = ACC_SPECIFY;
4651 + ace_id = acl_entry->ace_id;
4653 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4654 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4655 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4656 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4657 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4660 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4661 + DEBUG(10,("errno is %d\n",errno));
4662 + DEBUG(10,("return code is %d\n",rc));
4663 + SAFE_FREE(file_acl);
4664 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4668 +int sys_acl_delete_def_file(const char *name)
4670 + /* AIX has no default ACL */
4674 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4676 + return(*permset & perm);
4679 +int sys_acl_free_text(char *text)
4684 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4686 + struct acl_entry_link *acl_entry_link;
4688 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4689 + SAFE_FREE(acl_entry_link->prevp->entryp);
4690 + SAFE_FREE(acl_entry_link->prevp);
4693 + SAFE_FREE(acl_entry_link->prevp->entryp);
4694 + SAFE_FREE(acl_entry_link->prevp);
4695 + SAFE_FREE(acl_entry_link->entryp);
4696 + SAFE_FREE(acl_entry_link);
4701 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4706 +#else /* No ACLs. */
4708 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4714 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4720 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4726 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4732 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4735 + return (SMB_ACL_T)NULL;
4738 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4741 + return (SMB_ACL_T)NULL;
4744 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4750 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4756 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4759 + return (permset & perm) ? 1 : 0;
4762 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4768 +int sys_acl_free_text(UNUSED(char *text))
4774 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4780 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4786 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4792 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4798 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4804 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4810 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4816 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4822 +int sys_acl_delete_def_file(UNUSED(const char *name))
4828 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4834 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4840 +#endif /* No ACLs. */
4842 +/************************************************************************
4843 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4845 +************************************************************************/
4847 +int no_acl_syscall_error(int err)
4849 +#if defined(ENOSYS)
4850 + if (err == ENOSYS) {
4854 +#if defined(ENOTSUP)
4855 + if (err == ENOTSUP) {
4861 --- old/lib/sysacls.h
4862 +++ new/lib/sysacls.h
4864 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4865 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4866 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4867 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4868 +#define slprintf snprintf
4870 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4871 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4872 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4873 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4874 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4875 +SMB_ACL_T sys_acl_get_fd(int fd);
4876 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4877 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4878 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4879 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4880 +SMB_ACL_T sys_acl_init(int count);
4881 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4882 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4883 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4884 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4885 +int sys_acl_valid(SMB_ACL_T theacl);
4886 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4887 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4888 +int sys_acl_delete_def_file(const char *name);
4889 +int sys_acl_free_text(char *text);
4890 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4891 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4894 @@ -58,7 +58,7 @@ BEGIN {
4898 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4899 +!/^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/ {
4905 @@ -47,6 +47,7 @@ int copy_dirlinks = 0;
4907 int preserve_links = 0;
4908 int preserve_hard_links = 0;
4909 +int preserve_acls = 0;
4910 int preserve_perms = 0;
4911 int preserve_executability = 0;
4912 int preserve_devices = 0;
4913 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4914 char const *got_socketpair = "no ";
4915 char const *have_inplace = "no ";
4916 char const *hardlinks = "no ";
4917 + char const *acls = "no ";
4918 char const *links = "no ";
4919 char const *ipv6 = "no ";
4920 STRUCT_STAT *dumstat;
4921 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4925 +#ifdef SUPPORT_ACLS
4929 #ifdef SUPPORT_LINKS
4932 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4933 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4934 rprintf(f, "<http://rsync.samba.org/>\n");
4935 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4936 - "%shard links, %ssymlinks, batchfiles,\n",
4937 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4938 (int) (sizeof (OFF_T) * 8),
4939 - got_socketpair, hardlinks, links);
4940 + got_socketpair, hardlinks, acls, links);
4942 /* Note that this field may not have type ino_t. It depends
4943 * on the complicated interaction between largefile feature
4944 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4945 rprintf(F," -H, --hard-links preserve hard links\n");
4946 rprintf(F," -p, --perms preserve permissions\n");
4947 rprintf(F," -E, --executability preserve the file's executability\n");
4948 +#ifdef SUPPORT_ACLS
4949 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4951 rprintf(F," --chmod=CHMOD change destination permissions\n");
4952 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4953 rprintf(F," -g, --group preserve group\n");
4954 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4955 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4956 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4957 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4958 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4959 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4960 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4961 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4962 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4963 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4964 @@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
4969 +#ifdef SUPPORT_ACLS
4971 + preserve_perms = 1;
4974 + /* FIXME: this should probably be ignored with a
4975 + * warning and then countermeasures taken to
4976 + * restrict group and other access in the presence
4977 + * of any more restrictive ACLs, but this is safe
4979 + snprintf(err_buf,sizeof(err_buf),
4980 + "ACLs are not supported on this %s\n",
4981 + am_server ? "server" : "client");
4987 /* A large opt value means that set_refuse_options()
4988 * turned this option off. */
4989 @@ -1510,6 +1540,10 @@ void server_options(char **args,int *arg
4991 if (preserve_hard_links)
4993 +#ifdef SUPPORT_ACLS
4994 + if (preserve_acls)
4995 + argstr[x++] = 'A';
5002 @@ -48,6 +48,7 @@ extern int keep_partial;
5003 extern int checksum_seed;
5005 extern int delay_updates;
5006 +extern mode_t orig_umask;
5007 extern struct stats stats;
5008 extern char *log_format;
5009 extern char *tmpdir;
5010 @@ -346,6 +347,10 @@ int recv_files(int f_in, struct file_lis
5011 int itemizing = am_daemon ? daemon_log_format_has_i
5012 : !am_server && log_format_has_i;
5013 int max_phase = protocol_version >= 29 ? 2 : 1;
5014 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5015 +#ifdef SUPPORT_ACLS
5016 + char *parent_dirname = "";
5021 @@ -543,7 +548,16 @@ int recv_files(int f_in, struct file_lis
5022 * mode based on the local permissions and some heuristics. */
5023 if (!preserve_perms) {
5024 int exists = fd1 != -1;
5025 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5026 +#ifdef SUPPORT_ACLS
5027 + char *dn = file->dirname ? file->dirname : ".";
5028 + if (parent_dirname != dn
5029 + && strcmp(parent_dirname, dn) != 0) {
5030 + dflt_perms = default_perms_for_dir(dn);
5031 + parent_dirname = dn;
5034 + file->mode = dest_mode(file->mode, st.st_mode,
5035 + dflt_perms, exists);
5038 /* We now check to see if we are writing file "inplace" */
5044 extern int daemon_log_format_has_i;
5045 +extern int preserve_acls;
5046 extern int preserve_perms;
5047 extern int preserve_executability;
5048 extern int preserve_times;
5049 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5051 /* This is only called when we aren't preserving permissions. Figure out what
5052 * the permissions should be and return them merged back into the mode. */
5053 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5054 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5057 /* If the file already exists, we'll return the local permissions,
5058 * possibly tweaked by the --executability option. */
5059 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
5060 cur_mode |= (cur_mode & 0444) >> 2;
5063 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5064 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5065 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5066 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5067 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5068 @@ -203,6 +205,17 @@ int set_file_attrs(char *fname, struct f
5072 +#ifdef SUPPORT_ACLS
5073 + /* It's OK to call set_acl() now, even for a dir, as the generator
5074 + * will enable owner-writability using chmod, if necessary.
5076 + * If set_acl changes permission bits in the process of setting
5077 + * an access ACL, it changes st->st_mode so we know whether we
5078 + * need to chmod. */
5079 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5084 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5085 int ret = do_chmod(fname, file->mode);
5088 @@ -660,6 +660,20 @@ struct chmod_mode_struct;
5090 #define UNUSED(x) x __attribute__((__unused__))
5092 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5093 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5094 +#define SUPPORT_ACLS 1
5097 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5098 +#define ACLS_NEED_MASK 1
5101 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5102 +#include <sys/acl.h>
5104 +#include "smb_acls.h"
5108 /* We have replacement versions of these if they're missing. */
5111 @@ -321,6 +321,7 @@ to the detailed description below for a
5112 -H, --hard-links preserve hard links
5113 -p, --perms preserve permissions
5114 -E, --executability preserve executability
5115 + -A, --acls preserve ACLs (implies -p) [non-standard]
5116 --chmod=CHMOD change destination permissions
5117 -o, --owner preserve owner (super-user only)
5118 -g, --group preserve group
5119 @@ -742,7 +743,9 @@ quote(itemize(
5120 permissions, though the bf(--executability) option might change just
5121 the execute permission for the file.
5122 it() New files get their "normal" permission bits set to the source
5123 - file's permissions masked with the receiving end's umask setting, and
5124 + file's permissions masked with the receiving directory's default
5125 + permissions (either the receiving process's umask, or the permissions
5126 + specified via the destination directory's default ACL), and
5127 their special permission bits disabled except in the case where a new
5128 directory inherits a setgid bit from its parent directory.
5130 @@ -773,9 +776,11 @@ The preservation of the destination's se
5131 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5132 versions erroneously preserved the three special permission bits for
5133 newly-created files when bf(--perms) was off, while overriding the
5134 -destination's setgid bit setting on a newly-created directory. (Keep in
5135 -mind that it is the version of the receiving rsync that affects this
5137 +destination's setgid bit setting on a newly-created directory. Default ACL
5138 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5139 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5140 +(Keep in mind that it is the version of the receiving rsync that affects
5143 dit(bf(-E, --executability)) This option causes rsync to preserve the
5144 executability (or non-executability) of regular files when bf(--perms) is
5145 @@ -793,6 +798,15 @@ quote(itemize(
5147 If bf(--perms) is enabled, this option is ignored.
5149 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5150 +ACLs to be the same as the source ACLs. This nonstandard option only
5151 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5153 +Note also that an optimization of the ACL-sending protocol used by this
5154 +version makes it incompatible with sending files to an older ACL-enabled
5155 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5156 +doubling is not needed when pulling files from an older rsync.
5158 dit(bf(--chmod)) This option tells rsync to apply one or more
5159 comma-separated "chmod" strings to the permission of the files in the
5160 transfer. The resulting value is treated as though it was the permissions
5165 + * Unix SMB/Netbios implementation.
5167 + * Portable SMB ACL interface
5169 + * Copyright (C) 2000 Jeremy Allison
5171 + * This program is free software; you can redistribute it and/or modify
5172 + * it under the terms of the GNU General Public License as published by
5173 + * the Free Software Foundation; either version 2 of the License, or
5174 + * (at your option) any later version.
5176 + * This program is distributed in the hope that it will be useful,
5177 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5178 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5179 + * GNU General Public License for more details.
5181 + * You should have received a copy of the GNU General Public License along
5182 + * with this program; if not, write to the Free Software Foundation, Inc.,
5183 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
5186 +#ifndef _SMB_ACLS_H
5187 +#define _SMB_ACLS_H
5189 +#if defined HAVE_POSIX_ACLS
5191 +/* This is an identity mapping (just remove the SMB_). */
5193 +#define SMB_ACL_TAG_T acl_tag_t
5194 +#define SMB_ACL_TYPE_T acl_type_t
5195 +#define SMB_ACL_PERMSET_T acl_permset_t
5196 +#define SMB_ACL_PERM_T acl_perm_t
5197 +#define SMB_ACL_READ ACL_READ
5198 +#define SMB_ACL_WRITE ACL_WRITE
5199 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5201 +/* Types of ACLs. */
5202 +#define SMB_ACL_USER ACL_USER
5203 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5204 +#define SMB_ACL_GROUP ACL_GROUP
5205 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5206 +#define SMB_ACL_OTHER ACL_OTHER
5207 +#define SMB_ACL_MASK ACL_MASK
5209 +#define SMB_ACL_T acl_t
5211 +#define SMB_ACL_ENTRY_T acl_entry_t
5213 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5214 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5216 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5217 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5219 +#elif defined HAVE_TRU64_ACLS
5221 +/* This is for DEC/Compaq Tru64 UNIX */
5223 +#define SMB_ACL_TAG_T acl_tag_t
5224 +#define SMB_ACL_TYPE_T acl_type_t
5225 +#define SMB_ACL_PERMSET_T acl_permset_t
5226 +#define SMB_ACL_PERM_T acl_perm_t
5227 +#define SMB_ACL_READ ACL_READ
5228 +#define SMB_ACL_WRITE ACL_WRITE
5229 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5231 +/* Types of ACLs. */
5232 +#define SMB_ACL_USER ACL_USER
5233 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5234 +#define SMB_ACL_GROUP ACL_GROUP
5235 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5236 +#define SMB_ACL_OTHER ACL_OTHER
5237 +#define SMB_ACL_MASK ACL_MASK
5239 +#define SMB_ACL_T acl_t
5241 +#define SMB_ACL_ENTRY_T acl_entry_t
5243 +#define SMB_ACL_FIRST_ENTRY 0
5244 +#define SMB_ACL_NEXT_ENTRY 1
5246 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5247 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5249 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5251 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5252 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5255 +/* SVR4.2 ES/MP ACLs */
5256 +typedef int SMB_ACL_TAG_T;
5257 +typedef int SMB_ACL_TYPE_T;
5258 +typedef ushort *SMB_ACL_PERMSET_T;
5259 +typedef ushort SMB_ACL_PERM_T;
5260 +#define SMB_ACL_READ 4
5261 +#define SMB_ACL_WRITE 2
5262 +#define SMB_ACL_EXECUTE 1
5264 +/* Types of ACLs. */
5265 +#define SMB_ACL_USER USER
5266 +#define SMB_ACL_USER_OBJ USER_OBJ
5267 +#define SMB_ACL_GROUP GROUP
5268 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5269 +#define SMB_ACL_OTHER OTHER_OBJ
5270 +#define SMB_ACL_MASK CLASS_OBJ
5272 +typedef struct SMB_ACL_T {
5276 + struct acl acl[1];
5279 +typedef struct acl *SMB_ACL_ENTRY_T;
5281 +#define SMB_ACL_FIRST_ENTRY 0
5282 +#define SMB_ACL_NEXT_ENTRY 1
5284 +#define SMB_ACL_TYPE_ACCESS 0
5285 +#define SMB_ACL_TYPE_DEFAULT 1
5288 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5291 +#elif defined HAVE_HPUX_ACLS
5294 + * Based on the Solaris & UnixWare code.
5298 +#include <sys/aclv.h>
5300 +/* SVR4.2 ES/MP ACLs */
5301 +typedef int SMB_ACL_TAG_T;
5302 +typedef int SMB_ACL_TYPE_T;
5303 +typedef ushort *SMB_ACL_PERMSET_T;
5304 +typedef ushort SMB_ACL_PERM_T;
5305 +#define SMB_ACL_READ 4
5306 +#define SMB_ACL_WRITE 2
5307 +#define SMB_ACL_EXECUTE 1
5309 +/* Types of ACLs. */
5310 +#define SMB_ACL_USER USER
5311 +#define SMB_ACL_USER_OBJ USER_OBJ
5312 +#define SMB_ACL_GROUP GROUP
5313 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5314 +#define SMB_ACL_OTHER OTHER_OBJ
5315 +#define SMB_ACL_MASK CLASS_OBJ
5317 +typedef struct SMB_ACL_T {
5321 + struct acl acl[1];
5324 +typedef struct acl *SMB_ACL_ENTRY_T;
5326 +#define SMB_ACL_FIRST_ENTRY 0
5327 +#define SMB_ACL_NEXT_ENTRY 1
5329 +#define SMB_ACL_TYPE_ACCESS 0
5330 +#define SMB_ACL_TYPE_DEFAULT 1
5332 +#elif defined HAVE_IRIX_ACLS
5334 +#define SMB_ACL_TAG_T acl_tag_t
5335 +#define SMB_ACL_TYPE_T acl_type_t
5336 +#define SMB_ACL_PERMSET_T acl_permset_t
5337 +#define SMB_ACL_PERM_T acl_perm_t
5338 +#define SMB_ACL_READ ACL_READ
5339 +#define SMB_ACL_WRITE ACL_WRITE
5340 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5342 +/* Types of ACLs. */
5343 +#define SMB_ACL_USER ACL_USER
5344 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5345 +#define SMB_ACL_GROUP ACL_GROUP
5346 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5347 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5348 +#define SMB_ACL_MASK ACL_MASK
5350 +typedef struct SMB_ACL_T {
5356 +#define SMB_ACL_ENTRY_T acl_entry_t
5358 +#define SMB_ACL_FIRST_ENTRY 0
5359 +#define SMB_ACL_NEXT_ENTRY 1
5361 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5362 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5364 +#elif defined HAVE_AIX_ACLS
5366 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5368 +#include "/usr/include/acl.h"
5370 +typedef uint *SMB_ACL_PERMSET_T;
5372 +struct acl_entry_link{
5373 + struct acl_entry_link *prevp;
5374 + struct new_acl_entry *entryp;
5375 + struct acl_entry_link *nextp;
5379 +struct new_acl_entry{
5380 + unsigned short ace_len;
5381 + unsigned short ace_type;
5382 + unsigned int ace_access;
5383 + struct ace_id ace_id[1];
5386 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5387 +#define SMB_ACL_T struct acl_entry_link*
5389 +#define SMB_ACL_TAG_T unsigned short
5390 +#define SMB_ACL_TYPE_T int
5391 +#define SMB_ACL_PERM_T uint
5392 +#define SMB_ACL_READ S_IRUSR
5393 +#define SMB_ACL_WRITE S_IWUSR
5394 +#define SMB_ACL_EXECUTE S_IXUSR
5396 +/* Types of ACLs. */
5397 +#define SMB_ACL_USER ACEID_USER
5398 +#define SMB_ACL_USER_OBJ 3
5399 +#define SMB_ACL_GROUP ACEID_GROUP
5400 +#define SMB_ACL_GROUP_OBJ 4
5401 +#define SMB_ACL_OTHER 5
5402 +#define SMB_ACL_MASK 6
5405 +#define SMB_ACL_FIRST_ENTRY 1
5406 +#define SMB_ACL_NEXT_ENTRY 2
5408 +#define SMB_ACL_TYPE_ACCESS 0
5409 +#define SMB_ACL_TYPE_DEFAULT 1
5411 +#else /* No ACLs. */
5413 +/* No ACLS - fake it. */
5414 +#define SMB_ACL_TAG_T int
5415 +#define SMB_ACL_TYPE_T int
5416 +#define SMB_ACL_PERMSET_T mode_t
5417 +#define SMB_ACL_PERM_T mode_t
5418 +#define SMB_ACL_READ S_IRUSR
5419 +#define SMB_ACL_WRITE S_IWUSR
5420 +#define SMB_ACL_EXECUTE S_IXUSR
5422 +/* Types of ACLs. */
5423 +#define SMB_ACL_USER 0
5424 +#define SMB_ACL_USER_OBJ 1
5425 +#define SMB_ACL_GROUP 2
5426 +#define SMB_ACL_GROUP_OBJ 3
5427 +#define SMB_ACL_OTHER 4
5428 +#define SMB_ACL_MASK 5
5430 +typedef struct SMB_ACL_T {
5434 +typedef struct SMB_ACL_ENTRY_T {
5436 +} *SMB_ACL_ENTRY_T;
5438 +#define SMB_ACL_FIRST_ENTRY 0
5439 +#define SMB_ACL_NEXT_ENTRY 1
5441 +#define SMB_ACL_TYPE_ACCESS 0
5442 +#define SMB_ACL_TYPE_DEFAULT 1
5444 +#endif /* No ACLs. */
5445 +#endif /* _SMB_ACLS_H */
5446 --- old/testsuite/acls.test
5447 +++ new/testsuite/acls.test
5451 +# This program is distributable under the terms of the GNU GPL (see
5454 +# Test that rsync handles basic ACL preservation.
5456 +. $srcdir/testsuite/rsync.fns
5458 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5459 +case "$setfacl_nodef" in
5460 +true) test_skipped "I don't know how to use your setfacl command" ;;
5463 +makepath "$fromdir/foo"
5464 +echo something >"$fromdir/file1"
5465 +echo else >"$fromdir/file2"
5467 +files='foo file1 file2'
5469 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
5470 +setfacl -m u:0:5 "$fromdir/file1"
5471 +setfacl -m u:0:5 "$fromdir/file2"
5473 +$RSYNC -avvA "$fromdir/" "$todir/"
5476 +getfacl $files >"$scratchdir/acls.txt"
5479 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
5481 +# The script would have aborted on error, so getting here means we've won.
5483 --- old/testsuite/default-acls.test
5484 +++ new/testsuite/default-acls.test
5488 +# This program is distributable under the terms of the GNU GPL (see
5491 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5493 +. $srcdir/testsuite/rsync.fns
5495 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5496 +case "$setfacl_nodef" in
5497 +true) test_skipped "I don't know how to use your setfacl command" ;;
5498 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5499 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5501 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5503 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5505 + todir="$scratchdir/$1"
5507 + $setfacl_nodef "$todir"
5509 + case "$setfacl_nodef" in
5510 + *-k*) opts="-dm $2" ;;
5511 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5513 + setfacl $opts "$todir"
5515 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5516 + # even though the directory itself is outside the transfer
5517 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5518 + check_perms "$todir/to" $4 "Target $1"
5519 + check_perms "$todir/to/dir" $4 "Target $1"
5520 + check_perms "$todir/to/file" $3 "Target $1"
5521 + check_perms "$todir/to/program" $4 "Target $1"
5522 + # Make sure get_local_name doesn't mess us up when transferring only one file
5523 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5524 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5525 + # Make sure we obey default ACLs when not transferring a regular file
5526 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5527 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5530 +mkdir "$scratchdir/dir"
5531 +echo "File!" >"$scratchdir/file"
5532 +echo "#!/bin/sh" >"$scratchdir/program"
5533 +chmod 777 "$scratchdir/dir"
5534 +chmod 666 "$scratchdir/file"
5535 +chmod 777 "$scratchdir/program"
5537 +# Test some target directories
5539 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5540 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5541 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5542 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5543 +testit noda1 '' rw------- rwx------
5545 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5547 +testit noda3 '' rw-r--r-- rwxr-xr-x
5555 extern int preserve_uid;
5556 extern int preserve_gid;
5557 +extern int preserve_acls;
5558 extern int numeric_ids;
5561 @@ -275,7 +276,7 @@ void send_uid_list(int f)
5565 - if (preserve_uid) {
5566 + if (preserve_uid || preserve_acls) {
5568 /* we send sequences of uid/byte-length/name */
5569 for (list = uidlist; list; list = list->next) {
5570 @@ -292,7 +293,7 @@ void send_uid_list(int f)
5574 - if (preserve_gid) {
5575 + if (preserve_gid || preserve_acls) {
5577 for (list = gidlist; list; list = list->next) {
5579 @@ -313,7 +314,7 @@ void recv_uid_list(int f, struct file_li
5583 - if (preserve_uid && !numeric_ids) {
5584 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5585 /* read the uid list */
5586 while ((id = read_int(f)) != 0) {
5587 int len = read_byte(f);
5588 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
5592 - if (preserve_gid && !numeric_ids) {
5593 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5594 /* read the gid list */
5595 while ((id = read_int(f)) != 0) {
5596 int len = read_byte(f);
5597 @@ -337,6 +338,16 @@ void recv_uid_list(int f, struct file_li
5601 +#ifdef SUPPORT_ACLS
5602 + if (preserve_acls && !numeric_ids) {
5604 + while ((id = next_acl_uid(flist)) != NULL)
5605 + *id = match_uid(*id);
5606 + while ((id = next_acl_gid(flist)) != NULL)
5607 + *id = match_gid(*id);
5611 /* Now convert all the uids/gids from sender values to our values. */
5612 if (am_root && preserve_uid && !numeric_ids) {
5613 for (i = 0; i < flist->count; i++)