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.
10 This code does not yet itemize changes in ACL information (see --itemize).
14 @@ -25,15 +25,15 @@ VERSION=@VERSION@
18 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
19 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
20 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
21 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
22 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
23 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
24 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
25 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
26 main.o checksum.o match.o syscall.o log.o backup.o
27 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
28 - fileio.o batch.o clientname.o chmod.o
29 + fileio.o batch.o clientname.o chmod.o acls.o
30 OBJS3=progress.o pipe.o
31 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
32 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
36 +/* -*- c-file-style: "linux" -*-
37 + Copyright (C) Andrew Tridgell 1996
38 + Copyright (C) Paul Mackerras 1996
39 + Copyright (C) Matt McCutchen 2006
40 + Copyright (C) Wayne Davison 2006
42 + This program is free software; you can redistribute it and/or modify
43 + it under the terms of the GNU General Public License as published by
44 + the Free Software Foundation; either version 2 of the License, or
45 + (at your option) any later version.
47 + This program is distributed in the hope that it will be useful,
48 + but WITHOUT ANY WARRANTY; without even the implied warranty of
49 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 + GNU General Public License for more details.
52 + You should have received a copy of the GNU General Public License
53 + along with this program; if not, write to the Free Software
54 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
57 +/* handle passing ACLs between systems */
60 +#include "lib/sysacls.h"
66 +extern int orig_umask;
67 +extern int preserve_acls;
80 +#define ACL_NO_ENTRY ((uchar)0x80)
84 + /* These will be ACL_NO_ENTRY if there's no such entry. */
91 +static const rsync_acl rsync_acl_initializer = {
92 + {0, 0, NULL}, {0, 0, NULL},
93 + ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY
96 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
97 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
99 +/* a few useful calculations */
101 +static int count_racl_entries(const rsync_acl *racl)
103 + return racl->users.count + racl->groups.count
104 + + (racl->user_obj != ACL_NO_ENTRY)
105 + + (racl->group_obj != ACL_NO_ENTRY)
106 + + (racl->mask != ACL_NO_ENTRY)
107 + + (racl->other != ACL_NO_ENTRY);
110 +static int calc_sacl_entries(const rsync_acl *racl)
112 + return racl->users.count + racl->groups.count
113 +#ifdef ACLS_NEED_MASK
116 + + (racl->mask != ACL_NO_ENTRY) + 3;
120 +static int rsync_acl_get_perms(const rsync_acl *racl)
122 + /* Note that (ACL_NO_ENTRY & 7) is 0. */
123 + return ((racl->user_obj & 7) << 6)
124 + + (((racl->mask != ACL_NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
125 + + (racl->other & 7);
128 +static void rsync_acl_strip_perms(rsync_acl *racl)
130 + racl->user_obj = ACL_NO_ENTRY;
131 + if (racl->mask == ACL_NO_ENTRY)
132 + racl->group_obj = ACL_NO_ENTRY;
134 + racl->mask = ACL_NO_ENTRY;
135 + racl->other = ACL_NO_ENTRY;
138 +static void expand_ida_list(ida_list *idal)
140 + /* First time through, 0 <= 0, so list is expanded. */
141 + if (idal->malloced <= idal->count) {
142 + id_access *new_ptr;
143 + size_t new_size = idal->malloced + 10;
144 + new_ptr = realloc_array(idal->idas, id_access, new_size);
145 + if (verbose >= 4) {
146 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
147 + (double) new_size * sizeof idal->idas[0],
148 + idal->idas ? "" : " not");
151 + idal->idas = new_ptr;
152 + idal->malloced = new_size;
155 + out_of_memory("expand_ida_list");
159 +static void ida_list_free(ida_list *idal)
164 + idal->malloced = 0;
167 +static void rsync_acl_free(rsync_acl *racl)
169 + ida_list_free(&racl->users);
170 + ida_list_free(&racl->groups);
173 +static int id_access_sorter(const void *r1, const void *r2)
175 + id_access *ida1 = (id_access *)r1;
176 + id_access *ida2 = (id_access *)r2;
177 + id_t rid1 = ida1->id, rid2 = ida2->id;
178 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
181 +static void sort_ida_list(ida_list *idal)
185 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
186 + &id_access_sorter);
189 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
191 + SMB_ACL_ENTRY_T entry;
192 + const char *errfun;
195 + *racl = rsync_acl_initializer;
196 + errfun = "sys_acl_get_entry";
197 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
199 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
200 + SMB_ACL_TAG_T tag_type;
201 + SMB_ACL_PERMSET_T permset;
206 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
207 + errfun = "sys_acl_get_tag_type";
210 + if ((rc = sys_acl_get_permset(entry, &permset))) {
211 + errfun = "sys_acl_get_tag_type";
214 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
215 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
216 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
217 + /* continue == done with entry; break == store in given idal */
218 + switch (tag_type) {
219 + case SMB_ACL_USER_OBJ:
220 + if (racl->user_obj == ACL_NO_ENTRY)
221 + racl->user_obj = access;
223 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
226 + idal = &racl->users;
228 + case SMB_ACL_GROUP_OBJ:
229 + if (racl->group_obj == ACL_NO_ENTRY)
230 + racl->group_obj = access;
232 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
234 + case SMB_ACL_GROUP:
235 + idal = &racl->groups;
238 + if (racl->mask == ACL_NO_ENTRY)
239 + racl->mask = access;
241 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
243 + case SMB_ACL_OTHER:
244 + if (racl->other == ACL_NO_ENTRY)
245 + racl->other = access;
247 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
250 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
253 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
254 + errfun = "sys_acl_get_tag_type";
258 + expand_ida_list(idal);
259 + ida = &idal->idas[idal->count++];
260 + ida->id = *((id_t *)qualifier);
261 + ida->access = access;
262 + sys_acl_free_qualifier(qualifier, tag_type);
265 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
266 + errfun, strerror(errno));
267 + rsync_acl_free(racl);
271 + sort_ida_list(&racl->users);
272 + sort_ida_list(&racl->groups);
277 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
279 + id_access *ida1, *ida2;
280 + size_t count = ial1->count;
281 + if (count != ial2->count)
285 + for (; count--; ida1++, ida2++) {
286 + if (ida1->access != ida2->access || ida1->id != ida2->id)
292 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
294 + return (racl1->user_obj == racl2->user_obj
295 + && racl1->group_obj == racl2->group_obj
296 + && racl1->mask == racl2->mask
297 + && racl1->other == racl2->other
298 + && ida_lists_equal(&racl1->users, &racl2->users)
299 + && ida_lists_equal(&racl1->groups, &racl2->groups));
302 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1, const rsync_acl *racl2)
304 + /* We ignore any differences that chmod() can take care of. */
305 + if ((racl1->mask ^ racl2->mask) & ACL_NO_ENTRY)
307 + if (racl1->mask != ACL_NO_ENTRY && racl1->group_obj != racl2->group_obj)
309 + return ida_lists_equal(&racl1->users, &racl2->users)
310 + && ida_lists_equal(&racl1->groups, &racl2->groups);
319 +static rsync_acl_list _rsync_acl_lists[] = {
320 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
321 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
324 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
326 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
327 + : &_rsync_acl_lists[1];
330 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
332 + /* First time through, 0 <= 0, so list is expanded. */
333 + if (racl_list->malloced <= racl_list->count) {
334 + rsync_acl *new_ptr;
336 + if (racl_list->malloced < 1000)
337 + new_size = racl_list->malloced + 1000;
339 + new_size = racl_list->malloced * 2;
340 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
341 + if (verbose >= 3) {
342 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
343 + (double) new_size * sizeof racl_list->racls[0],
344 + racl_list->racls ? "" : " not");
347 + racl_list->racls = new_ptr;
348 + racl_list->malloced = new_size;
350 + if (!racl_list->racls)
351 + out_of_memory("expand_rsync_acl_list");
355 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
356 + const rsync_acl_list *racl_list,
357 + const rsync_acl *racl)
359 + static int access_match = -1, default_match = -1;
360 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
361 + &access_match : &default_match;
362 + size_t count = racl_list->count;
363 + /* If this is the first time through or we didn't match the last
364 + * time, then start at the end of the list, which should be the
365 + * best place to start hunting. */
367 + *match = racl_list->count - 1;
369 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
372 + *match = racl_list->count - 1;
378 +/* The general strategy with the tag_type <-> character mapping is that
379 + * lowercase implies that no qualifier follows, where uppercase does.
380 + * A similar idiom for the acl type (access or default) itself, but
381 + * lowercase in this instance means there's no ACL following, so the
382 + * ACL is a repeat, so the receiver should reuse the last of the same
384 +static void send_ida_list(int f, const ida_list *idal, char tag_char)
387 + size_t count = idal->count;
388 + for (ida = idal->idas; count--; ida++) {
389 + write_byte(f, tag_char);
390 + write_byte(f, ida->access);
391 + write_int(f, ida->id);
392 + /* FIXME: sorta wasteful: we should maybe buffer as
393 + * many ids as max(ACL_USER + ACL_GROUP) objects to
394 + * keep from making so many calls. */
395 + if (tag_char == 'U')
402 +static void send_rsync_acl(int f, const rsync_acl *racl)
404 + size_t count = count_racl_entries(racl);
405 + write_int(f, count);
406 + if (racl->user_obj != ACL_NO_ENTRY) {
407 + write_byte(f, 'u');
408 + write_byte(f, racl->user_obj);
410 + send_ida_list(f, &racl->users, 'U');
411 + if (racl->group_obj != ACL_NO_ENTRY) {
412 + write_byte(f, 'g');
413 + write_byte(f, racl->group_obj);
415 + send_ida_list(f, &racl->groups, 'G');
416 + if (racl->mask != ACL_NO_ENTRY) {
417 + write_byte(f, 'm');
418 + write_byte(f, racl->mask);
420 + if (racl->other != ACL_NO_ENTRY) {
421 + write_byte(f, 'o');
422 + write_byte(f, racl->other);
426 +static rsync_acl _curr_rsync_acls[2];
428 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
430 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
431 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
432 + "unknown SMB_ACL_TYPE_T";
435 +/* Generate the ACL(s) for this flist entry;
436 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
437 +int make_acl(const struct file_struct *file, const char *fname)
439 + SMB_ACL_TYPE_T type;
440 + rsync_acl *curr_racl;
442 + if (S_ISLNK(file->mode))
445 + curr_racl = &_curr_rsync_acls[0];
446 + type = SMB_ACL_TYPE_ACCESS;
450 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
451 + ok = unpack_smb_acl(curr_racl, sacl);
452 + sys_acl_free_acl(sacl);
455 + /* Avoid sending a redundant group/mask value. */
456 + if (curr_racl->group_obj == curr_racl->mask
457 + && (preserve_acls == 1
458 + || (!curr_racl->users.count
459 + && !curr_racl->groups.count)))
460 + curr_racl->mask = ACL_NO_ENTRY;
461 + /* Strip access ACLs of permission-bit entries. */
462 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
463 + rsync_acl_strip_perms(curr_racl);
464 + } else if (errno == ENOTSUP) {
465 + /* ACLs are not supported. Leave list empty. */
466 + *curr_racl = rsync_acl_initializer;
468 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
469 + fname, str_acl_type(type), strerror(errno));
473 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
478 +/* Send the make_acl()-generated ACLs for this flist entry,
479 + * or clean up after an flist entry that's not being sent (f == -1). */
480 +void send_acl(const struct file_struct *file, int f)
482 + SMB_ACL_TYPE_T type;
483 + rsync_acl *curr_racl;
485 + if (S_ISLNK(file->mode))
488 + curr_racl = &_curr_rsync_acls[0];
489 + type = SMB_ACL_TYPE_ACCESS;
492 + rsync_acl_list *racl_list = rsync_acl_lists(type);
494 + rsync_acl_free(curr_racl);
497 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
499 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
500 + write_int(f, index);
501 + rsync_acl_free(curr_racl);
503 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
504 + send_rsync_acl(f, curr_racl);
505 + expand_rsync_acl_list(racl_list);
506 + racl_list->racls[racl_list->count++] = *curr_racl;
509 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
512 +/* The below stuff is only used by the receiver: */
514 +/* structure to hold index to rsync_acl_list member corresponding to
515 + * flist->files[i] */
518 + const struct file_struct *file;
525 + file_acl_index *fileaclidxs;
526 +} file_acl_index_list;
528 +static file_acl_index_list _file_acl_index_lists[] = {
529 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
530 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
533 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
535 + return type == SMB_ACL_TYPE_ACCESS ?
536 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
539 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
541 + /* First time through, 0 <= 0, so list is expanded. */
542 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
543 + file_acl_index *new_ptr;
545 + if (fileaclidx_list->malloced < 1000)
546 + new_size = fileaclidx_list->malloced + 1000;
548 + new_size = fileaclidx_list->malloced * 2;
549 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
550 + if (verbose >= 3) {
551 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
552 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
553 + fileaclidx_list->fileaclidxs ? "" : " not");
556 + fileaclidx_list->fileaclidxs = new_ptr;
557 + fileaclidx_list->malloced = new_size;
559 + if (!fileaclidx_list->fileaclidxs)
560 + out_of_memory("expand_file_acl_index_list");
564 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
572 +static smb_acl_list _smb_acl_lists[] = {
573 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
574 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
577 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
579 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
580 + &_smb_acl_lists[1];
583 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
585 + /* First time through, 0 <= 0, so list is expanded. */
586 + if (sacl_list->malloced <= sacl_list->count) {
587 + SMB_ACL_T *new_ptr;
589 + if (sacl_list->malloced < 1000)
590 + new_size = sacl_list->malloced + 1000;
592 + new_size = sacl_list->malloced * 2;
593 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
594 + if (verbose >= 3) {
595 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
596 + (double) new_size * sizeof sacl_list->sacls[0],
597 + sacl_list->sacls ? "" : " not");
600 + sacl_list->sacls = new_ptr;
601 + sacl_list->malloced = new_size;
603 + if (!sacl_list->sacls)
604 + out_of_memory("expand_smb_acl_list");
608 +#define CALL_OR_ERROR(func,args,str) \
616 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
617 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
619 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
621 + const char *errfun = NULL;
622 + SMB_ACL_PERMSET_T permset;
624 + COE( sys_acl_get_permset,(entry, &permset) );
625 + COE( sys_acl_clear_perms,(permset) );
627 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
629 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
631 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
632 + COE( sys_acl_set_permset,(entry, permset) );
637 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
642 +/* build an SMB_ACL_T corresponding to an rsync_acl */
643 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
647 + const char *errfun = NULL;
648 + SMB_ACL_ENTRY_T entry;
650 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
651 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
656 + COE( sys_acl_create_entry,(smb_acl, &entry) );
657 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
658 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
660 + for (ida = racl->users.idas, count = racl->users.count;
662 + COE( sys_acl_create_entry,(smb_acl, &entry) );
663 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
664 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
665 + COE2( store_access_in_entry,(ida->access, entry) );
668 + COE( sys_acl_create_entry,(smb_acl, &entry) );
669 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
670 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
672 + for (ida = racl->groups.idas, count = racl->groups.count;
674 + COE( sys_acl_create_entry,(smb_acl, &entry) );
675 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
676 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
677 + COE2( store_access_in_entry,(ida->access, entry) );
679 +#ifndef ACLS_NEED_MASK
680 + if (racl->mask != ACL_NO_ENTRY) {
682 + COE( sys_acl_create_entry,(smb_acl, &entry) );
683 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
684 + COE2( store_access_in_entry,(racl->mask, entry) );
685 +#ifndef ACLS_NEED_MASK
689 + COE( sys_acl_create_entry,(smb_acl, &entry) );
690 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
691 + COE2( store_access_in_entry,(racl->other & 7, entry) );
694 + if (sys_acl_valid(*smb_acl) < 0)
695 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
702 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
705 + sys_acl_free_acl(*smb_acl);
709 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
711 + SMB_ACL_ENTRY_T entry;
712 + const char *errfun;
715 + if (S_ISDIR(mode)) {
716 + /* If the sticky bit is going on, it's not safe to allow all
717 + * the new ACLs to go into effect before it gets set. */
718 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
719 + if (mode & S_ISVTX)
722 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
725 + /* If setuid or setgid is going off, it's not safe to allow all
726 + * the new ACLs to go into effect before they get cleared. */
727 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
728 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
733 + errfun = "sys_acl_get_entry";
734 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
736 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
737 + SMB_ACL_TAG_T tag_type;
738 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
739 + errfun = "sys_acl_get_tag_type";
742 + switch (tag_type) {
743 + case SMB_ACL_USER_OBJ:
744 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
746 + case SMB_ACL_GROUP_OBJ:
747 + /* group is only empty when identical to group perms. */
748 + if (racl->group_obj != ACL_NO_ENTRY)
750 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
753 +#ifndef ACLS_NEED_MASK
754 + /* mask is only empty when we don't need it. */
755 + if (racl->mask == ACL_NO_ENTRY)
758 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
760 + case SMB_ACL_OTHER:
761 + COE2( store_access_in_entry,(mode & 7, entry) );
768 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
769 + errfun, strerror(errno));
774 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
775 + /* Ensure that chmod() will be called to restore any lost setid bits. */
776 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
777 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
778 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
781 + /* Return the mode of the file on disk, as we will set them. */
782 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
785 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
787 + uchar computed_mask_bits = 0;
788 + ida_list *idal = NULL;
792 + *racl = rsync_acl_initializer;
794 + if (!(count = read_int(f)))
798 + char tag = read_byte(f);
799 + uchar access = read_byte(f);
800 + if (access & ~ (4 | 2 | 1)) {
801 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
803 + exit_cleanup(RERR_STREAMIO);
807 + if (racl->user_obj != ACL_NO_ENTRY) {
808 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
809 + exit_cleanup(RERR_STREAMIO);
811 + racl->user_obj = access;
814 + idal = &racl->users;
817 + if (racl->group_obj != ACL_NO_ENTRY) {
818 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
819 + exit_cleanup(RERR_STREAMIO);
821 + racl->group_obj = access;
824 + idal = &racl->groups;
827 + if (racl->mask != ACL_NO_ENTRY) {
828 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
829 + exit_cleanup(RERR_STREAMIO);
831 + racl->mask = access;
834 + if (racl->other != ACL_NO_ENTRY) {
835 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
836 + exit_cleanup(RERR_STREAMIO);
838 + racl->other = access;
841 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
843 + exit_cleanup(RERR_STREAMIO);
845 + expand_ida_list(idal);
846 + ida = &idal->idas[idal->count++];
847 + ida->access = access;
848 + ida->id = read_int(f);
849 + computed_mask_bits |= access;
852 + if (type == SMB_ACL_TYPE_DEFAULT) {
853 + /* Ensure that these are never unset. */
854 + if (racl->user_obj == ACL_NO_ENTRY)
855 + racl->user_obj = 7;
856 + if (racl->group_obj == ACL_NO_ENTRY)
857 + racl->group_obj = 0;
858 + if (racl->other == ACL_NO_ENTRY)
861 +#ifndef ACLS_NEED_MASK
862 + if (!racl->users.count && !racl->groups.count) {
863 + /* If we, a system without ACLS_NEED_MASK, received a
864 + * superfluous mask, throw it away. */
865 + if (racl->mask != ACL_NO_ENTRY) {
866 + /* mask off group perms with it first */
867 + racl->group_obj &= racl->mask | ACL_NO_ENTRY;
868 + racl->mask = ACL_NO_ENTRY;
872 + if (racl->mask == ACL_NO_ENTRY) /* always made non-empty when needed */
873 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
876 +/* receive and build the rsync_acl_lists */
877 +void receive_acl(struct file_struct *file, int f)
879 + SMB_ACL_TYPE_T type;
882 + if (S_ISLNK(file->mode))
885 + fname = f_name(file, NULL);
886 + type = SMB_ACL_TYPE_ACCESS;
888 + file_acl_index_list *fileaclidx_list =
889 + file_acl_index_lists(type);
891 + expand_file_acl_index_list(fileaclidx_list);
893 + tag = read_byte(f);
894 + if (tag == 'A' || tag == 'a') {
895 + if (type != SMB_ACL_TYPE_ACCESS) {
896 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
898 + exit_cleanup(RERR_STREAMIO);
900 + } else if (tag == 'D' || tag == 'd') {
901 + if (type == SMB_ACL_TYPE_ACCESS) {
902 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
904 + exit_cleanup(RERR_STREAMIO);
907 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
909 + exit_cleanup(RERR_STREAMIO);
911 + if (tag == 'A' || tag == 'D') {
913 + rsync_acl_list *racl_list = rsync_acl_lists(type);
914 + smb_acl_list *sacl_list = smb_acl_lists(type);
915 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
916 + aclidx = racl_list->count;
917 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
919 + receive_rsync_acl(&racl, f, type);
920 + expand_rsync_acl_list(racl_list);
921 + racl_list->racls[racl_list->count++] = racl;
922 + expand_smb_acl_list(sacl_list);
923 + sacl_list->sacls[sacl_list->count++] = NULL;
925 + int index = read_int(f);
926 + rsync_acl_list *racl_list = rsync_acl_lists(type);
927 + if ((size_t) index >= racl_list->count) {
928 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
930 + str_acl_type(type),
932 + exit_cleanup(RERR_STREAMIO);
934 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
936 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
939 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
942 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
944 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
945 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
946 + return fileaclidx1->file == fileaclidx2->file ? 0 :
947 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
950 +void sort_file_acl_index_lists()
952 + SMB_ACL_TYPE_T type;
954 + type = SMB_ACL_TYPE_ACCESS;
956 + file_acl_index_list *fileaclidx_list =
957 + file_acl_index_lists(type);
958 + if (!fileaclidx_list->count)
960 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
961 + sizeof fileaclidx_list->fileaclidxs[0],
962 + &file_acl_index_list_sorter);
963 + } while (BUMP_TYPE(type));
966 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
967 + const struct file_struct *file) {
968 + int low = 0, high = fileaclidx_list->count;
969 + const struct file_struct *file_mid;
973 + int mid = (high + low) / 2;
974 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
975 + if (file_mid == file)
976 + return fileaclidx_list->fileaclidxs[mid].aclidx;
977 + if (file_mid > file)
981 + } while (low < high);
983 + file_mid = fileaclidx_list->fileaclidxs[low].file;
984 + if (file_mid == file)
985 + return fileaclidx_list->fileaclidxs[low].aclidx;
988 + "find_file_acl_index: can't find entry for file in list\n");
989 + exit_cleanup(RERR_STREAMIO);
993 +/* for duplicating ACLs on backups when using backup_dir */
994 +int dup_acl(const char *orig, const char *bak, mode_t mode)
996 + SMB_ACL_TYPE_T type;
999 + type = SMB_ACL_TYPE_ACCESS;
1001 + SMB_ACL_T sacl_orig, sacl_bak;
1002 + rsync_acl racl_orig, racl_bak;
1003 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
1004 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
1005 + orig, str_acl_type(type), strerror(errno));
1009 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
1010 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
1011 + bak, str_acl_type(type), strerror(errno));
1013 + /* try to forge on through */
1015 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
1017 + goto out_with_sacls;
1020 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
1022 + goto out_with_one_racl;
1024 + if (rsync_acls_equal(&racl_orig, &racl_bak))
1025 + goto out_with_all;
1027 + ; /* presume they're unequal */
1029 + if (type == SMB_ACL_TYPE_DEFAULT
1030 + && racl_orig.user_obj == ACL_NO_ENTRY) {
1031 + if (sys_acl_delete_def_file(bak) < 0) {
1032 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
1033 + bak, strerror(errno));
1036 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
1037 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
1038 + bak, str_acl_type(type), strerror(errno));
1043 + rsync_acl_free(&racl_bak);
1044 + out_with_one_racl:
1045 + rsync_acl_free(&racl_orig);
1048 + sys_acl_free_acl(sacl_bak);
1049 + /* out_with_one_sacl: */
1051 + sys_acl_free_acl(sacl_orig);
1052 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1057 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1058 + * for keep_backup(). */
1059 +static const struct file_struct *backup_orig_file = NULL;
1060 +static const char null_string[] = "";
1061 +static const char *backup_orig_fname = null_string;
1062 +static const char *backup_dest_fname = null_string;
1063 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1065 +void push_keep_backup_acl(const struct file_struct *file,
1066 + const char *orig, const char *dest)
1068 + SMB_ACL_TYPE_T type;
1071 + backup_orig_file = file;
1072 + backup_orig_fname = orig;
1073 + backup_dest_fname = dest;
1075 + sacl = &_backup_sacl[0];
1076 + type = SMB_ACL_TYPE_ACCESS;
1078 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1082 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1084 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1085 + orig, str_acl_type(type),
1088 + } while (BUMP_TYPE(type));
1091 +static int set_keep_backup_acl()
1093 + SMB_ACL_TYPE_T type;
1097 + sacl = &_backup_sacl[0];
1098 + type = SMB_ACL_TYPE_ACCESS;
1101 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1103 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1104 + backup_dest_fname,
1105 + str_acl_type(type),
1109 + } while (BUMP_TYPE(type));
1114 +void cleanup_keep_backup_acl()
1116 + SMB_ACL_TYPE_T type;
1119 + backup_orig_file = NULL;
1120 + backup_orig_fname = null_string;
1121 + backup_dest_fname = null_string;
1123 + sacl = &_backup_sacl[0];
1124 + type = SMB_ACL_TYPE_ACCESS;
1127 + sys_acl_free_acl(*sacl);
1130 + } while (BUMP_TYPE(type));
1133 +/* set ACL on rsync-ed or keep_backup-ed file
1135 + * This sets extended access ACL entries and default ACLs. If convenient,
1136 + * it sets permission bits along with the access ACLs and signals having
1137 + * done so by modifying mode_p, which should point into the stat buffer.
1139 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1140 + * Pass NULL for mode_p to get the return code without changing anything. */
1141 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1143 + int unchanged = 1;
1144 + SMB_ACL_TYPE_T type;
1146 + if (S_ISLNK(file->mode))
1149 + if (file == backup_orig_file) {
1150 + if (!strcmp(fname, backup_dest_fname))
1151 + return set_keep_backup_acl();
1153 + type = SMB_ACL_TYPE_ACCESS;
1156 + SMB_ACL_T sacl_orig, *sacl_new;
1157 + rsync_acl racl_orig, *racl_new;
1158 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1160 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1161 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1162 + sacl_orig = sys_acl_get_file(fname, type);
1164 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1165 + fname, str_acl_type(type), strerror(errno));
1169 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1170 + sys_acl_free_acl(sacl_orig);
1175 + if (type == SMB_ACL_TYPE_ACCESS)
1176 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new);
1178 + ok = rsync_acls_equal(&racl_orig, racl_new);
1179 + rsync_acl_free(&racl_orig);
1182 + if (!dry_run && mode_p) {
1183 + if (type == SMB_ACL_TYPE_DEFAULT
1184 + && racl_new->user_obj == ACL_NO_ENTRY) {
1185 + if (sys_acl_delete_def_file(fname) < 0) {
1186 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1187 + fname, strerror(errno));
1192 + mode_t cur_mode = *mode_p;
1194 + && !pack_smb_acl(sacl_new, racl_new)) {
1198 + if (type == SMB_ACL_TYPE_ACCESS) {
1199 + cur_mode = change_sacl_perms(*sacl_new, racl_new,
1200 + cur_mode, file->mode);
1201 + if (cur_mode == ~0u)
1204 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1205 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1206 + fname, str_acl_type(type),
1211 + if (type == SMB_ACL_TYPE_ACCESS)
1212 + *mode_p = cur_mode;
1215 + if (unchanged == 1)
1217 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1222 +/* Enumeration functions for uid mapping: */
1224 +/* Context -- one and only one. Should be cycled through once on uid
1225 + * mapping and once on gid mapping. */
1226 +static rsync_acl_list *_enum_racl_lists[] = {
1227 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1230 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1231 +static size_t enum_racl_index = 0;
1232 +static size_t enum_ida_index = 0;
1234 +/* This returns the next tag_type id from the given acl for the next entry,
1235 + * or it returns 0 if there are no more tag_type ids in the acl. */
1236 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1238 + const ida_list *idal = (tag_type == SMB_ACL_USER ?
1239 + &racl->users : &racl->groups);
1240 + if (enum_ida_index < idal->count) {
1241 + id_access *ida = &idal->idas[enum_ida_index++];
1244 + enum_ida_index = 0;
1248 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1250 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1251 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1252 + id_t *id = next_ace_id(tag_type, racl);
1256 + enum_racl_index = 0;
1260 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1262 + for (; *enum_racl_list; enum_racl_list++) {
1263 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1267 + enum_racl_list = &_enum_racl_lists[0];
1271 +id_t *next_acl_uid()
1273 + return next_acl_list_id(SMB_ACL_USER);
1276 +id_t *next_acl_gid()
1278 + return next_acl_list_id(SMB_ACL_GROUP);
1281 +int default_perms_for_dir(const char *dir)
1290 + perms = ACCESSPERMS & ~orig_umask;
1291 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1292 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1293 + if (sacl == NULL) {
1294 + /* Couldn't get an ACL. Darn. */
1297 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1301 + /* We're doing a dry run, so the containing directory
1302 + * wasn't actually created. Don't worry about it. */
1305 + /* Otherwise fall through. */
1307 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1308 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1314 + ok = unpack_smb_acl(&racl, sacl);
1315 + sys_acl_free_acl(sacl);
1317 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1321 + /* Apply the permission-bit entries of the default ACL, if any. */
1322 + if (racl.user_obj != ACL_NO_ENTRY) {
1323 + perms = rsync_acl_get_perms(&racl);
1325 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1328 + rsync_acl_free(&racl);
1332 +#endif /* SUPPORT_ACLS */
1335 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1336 extern char *backup_dir;
1339 +extern int preserve_acls;
1340 extern int preserve_devices;
1341 extern int preserve_specials;
1342 extern int preserve_links;
1343 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1345 do_lchown(fullpath, st.st_uid, st.st_gid);
1346 do_chmod(fullpath, st.st_mode);
1347 +#ifdef SUPPORT_ACLS
1348 + if (preserve_acls)
1349 + dup_acl(end, fullpath, st.st_mode);
1354 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1355 if (!(buf = get_backup_name(fname)))
1358 +#ifdef SUPPORT_ACLS
1359 + if (preserve_acls)
1360 + push_keep_backup_acl(file, fname, buf);
1363 /* Check to see if this is a device file, or link */
1364 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1365 || (preserve_specials && IS_SPECIAL(file->mode))) {
1366 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1369 set_file_attrs(buf, file, NULL, 0);
1370 +#ifdef SUPPORT_ACLS
1371 + if (preserve_acls)
1372 + cleanup_keep_backup_acl();
1377 --- old/configure.in
1378 +++ new/configure.in
1379 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1380 AC_CHECK_LIB(resolv, strcasecmp)
1383 +AC_CHECK_FUNCS(aclsort)
1384 +if test x"$ac_cv_func_aclsort" = x"no"; then
1385 + AC_CHECK_LIB(sec, aclsort)
1388 dnl At the moment we don't test for a broken memcmp(), because all we
1389 dnl need to do is test for equality, not comparison, and it seems that
1390 dnl every platform has a memcmp that can do at least that.
1391 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1392 AC_SUBST(CC_SHOBJ_FLAG)
1393 AC_SUBST(BUILD_POPT)
1395 +AC_CHECK_HEADERS(sys/acl.h)
1396 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1397 +#################################################
1398 +# check for ACL support
1400 +AC_MSG_CHECKING(whether to support ACLs)
1401 +AC_ARG_ENABLE(acl-support,
1402 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1403 +[ case "$enableval" in
1406 + case "$host_os" in
1408 + AC_MSG_RESULT(Using UnixWare ACLs)
1409 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1411 + *solaris*|*cygwin*)
1412 + AC_MSG_RESULT(Using solaris ACLs)
1413 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1416 + AC_MSG_RESULT(Using HPUX ACLs)
1417 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1420 + AC_MSG_RESULT(Using IRIX ACLs)
1421 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1424 + AC_MSG_RESULT(Using AIX ACLs)
1425 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1428 + AC_MSG_RESULT(Using Tru64 ACLs)
1429 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1430 + LIBS="$LIBS -lpacl"
1433 + AC_MSG_RESULT(ACLs requested -- running tests)
1434 + AC_CHECK_LIB(acl,acl_get_file)
1435 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1436 + AC_TRY_LINK([#include <sys/types.h>
1437 +#include <sys/acl.h>],
1438 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1439 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1440 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1441 + AC_MSG_RESULT(Using posix ACLs)
1442 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1443 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1444 + AC_TRY_LINK([#include <sys/types.h>
1445 +#include <sys/acl.h>],
1446 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1447 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1448 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1449 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1452 + AC_MSG_ERROR(Failed to find ACL support)
1459 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1462 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1466 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1471 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1472 extern int one_file_system;
1473 extern int copy_dirlinks;
1474 extern int keep_dirlinks;
1475 +extern int preserve_acls;
1476 extern int preserve_links;
1477 extern int preserve_hard_links;
1478 extern int preserve_devices;
1479 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1480 if (chmod_modes && !S_ISLNK(file->mode))
1481 file->mode = tweak_mode(file->mode, chmod_modes);
1483 +#ifdef SUPPORT_ACLS
1484 + if (preserve_acls && make_acl(file, fname) < 0)
1488 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1490 flist_expand(flist);
1491 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1492 if (file->basename[0]) {
1493 flist->files[flist->count++] = file;
1494 send_file_entry(file, f);
1495 +#ifdef SUPPORT_ACLS
1496 + if (preserve_acls)
1497 + send_acl(file, f);
1500 +#ifdef SUPPORT_ACLS
1501 + /* Cleanup unsent ACL(s). */
1502 + if (preserve_acls)
1503 + send_acl(file, -1);
1508 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1509 flags |= read_byte(f) << 8;
1510 file = receive_file_entry(flist, flags, f);
1512 +#ifdef SUPPORT_ACLS
1513 + if (preserve_acls)
1514 + receive_acl(file, f);
1517 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1518 stats.total_size += file->length;
1520 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1522 clean_flist(flist, relative_paths, 1);
1524 +#ifdef SUPPORT_ACLS
1525 + if (preserve_acls)
1526 + sort_file_acl_index_lists();
1530 recv_uid_list(f, flist);
1534 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1535 extern int max_delete;
1536 extern int force_delete;
1537 extern int one_file_system;
1538 +extern mode_t orig_umask;
1539 extern struct stats stats;
1540 extern dev_t filesystem_dev;
1541 extern char *backup_dir;
1542 @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l
1544 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1546 + /* FIXME: Flag ACL changes. */
1549 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1551 @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i
1552 if (preserve_gid && file->gid != GID_NONE
1553 && st->st_gid != file->gid)
1554 iflags |= ITEM_REPORT_GROUP;
1555 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1557 iflags |= ITEM_IS_NEW;
1559 @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str
1562 static int phase = 0;
1563 +static int dflt_perms;
1565 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1566 * make sure it exists, and has the right permissions/timestamp info. For
1567 @@ -844,6 +849,10 @@ static void recv_generator(char *fname,
1570 need_fuzzy_dirlist = 1;
1571 +#ifdef SUPPORT_ACLS
1572 + if (!preserve_perms)
1573 + dflt_perms = default_perms_for_dir(dn);
1576 parent_dirname = dn;
1578 @@ -871,7 +880,8 @@ static void recv_generator(char *fname,
1579 if (!preserve_perms) {
1580 int exists = statret == 0
1581 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1582 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1583 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1587 if (S_ISDIR(file->mode)) {
1588 @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi
1589 * notice that and let us know via the redo pipe (or its closing). */
1592 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1594 for (i = 0; i < flist->count; i++) {
1595 struct file_struct *file = flist->files[i];
1597 --- old/lib/sysacls.c
1598 +++ new/lib/sysacls.c
1601 + Unix SMB/CIFS implementation.
1602 + Samba system utilities for ACL support.
1603 + Copyright (C) Jeremy Allison 2000.
1605 + This program is free software; you can redistribute it and/or modify
1606 + it under the terms of the GNU General Public License as published by
1607 + the Free Software Foundation; either version 2 of the License, or
1608 + (at your option) any later version.
1610 + This program is distributed in the hope that it will be useful,
1611 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1612 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1613 + GNU General Public License for more details.
1615 + You should have received a copy of the GNU General Public License
1616 + along with this program; if not, write to the Free Software
1617 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1621 +#include "sysacls.h" /****** ADDED ******/
1623 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1624 +void SAFE_FREE(void *mem)
1630 +char *uidtoname(uid_t uid)
1632 + static char idbuf[12];
1633 + struct passwd *pw;
1635 + if ((pw = getpwuid(uid)) == NULL) {
1636 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1639 + return pw->pw_name;
1641 +/****** EXTRAS -- END ******/
1644 + This file wraps all differing system ACL interfaces into a consistent
1645 + one based on the POSIX interface. It also returns the correct errors
1646 + for older UNIX systems that don't support ACLs.
1648 + The interfaces that each ACL implementation must support are as follows :
1650 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1651 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1652 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1653 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1654 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1655 + SMB_ACL_T sys_acl_get_fd(int fd)
1656 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1657 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1658 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1659 + SMB_ACL_T sys_acl_init( int count)
1660 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1661 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1662 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1663 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1664 + int sys_acl_valid( SMB_ACL_T theacl )
1665 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1666 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1667 + int sys_acl_delete_def_file(const char *path)
1669 + This next one is not POSIX complient - but we *have* to have it !
1670 + More POSIX braindamage.
1672 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1674 + The generic POSIX free is the following call. We split this into
1675 + several different free functions as we may need to add tag info
1676 + to structures when emulating the POSIX interface.
1678 + int sys_acl_free( void *obj_p)
1680 + The calls we actually use are :
1682 + int sys_acl_free_text(char *text) - free acl_to_text
1683 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1684 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1688 +#if defined(HAVE_POSIX_ACLS)
1690 +/* Identity mapping - easy. */
1692 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1694 + return acl_get_entry( the_acl, entry_id, entry_p);
1697 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1699 + return acl_get_tag_type( entry_d, tag_type_p);
1702 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1704 + return acl_get_permset( entry_d, permset_p);
1707 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1709 + return acl_get_qualifier( entry_d);
1712 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1714 + return acl_get_file( path_p, type);
1717 +SMB_ACL_T sys_acl_get_fd(int fd)
1719 + return acl_get_fd(fd);
1722 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1724 + return acl_clear_perms(permset);
1727 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1729 + return acl_add_perm(permset, perm);
1732 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1734 +#if defined(HAVE_ACL_GET_PERM_NP)
1736 + * Required for TrustedBSD-based ACL implementations where
1737 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1740 + return acl_get_perm_np(permset, perm);
1742 + return acl_get_perm(permset, perm);
1746 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1748 + return acl_to_text( the_acl, plen);
1751 +SMB_ACL_T sys_acl_init( int count)
1753 + return acl_init(count);
1756 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1758 + return acl_create_entry(pacl, pentry);
1761 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1763 + return acl_set_tag_type(entry, tagtype);
1766 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1768 + return acl_set_qualifier(entry, qual);
1771 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1773 + return acl_set_permset(entry, permset);
1776 +int sys_acl_valid( SMB_ACL_T theacl )
1778 + return acl_valid(theacl);
1781 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1783 + return acl_set_file(name, acltype, theacl);
1786 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1788 + return acl_set_fd(fd, theacl);
1791 +int sys_acl_delete_def_file(const char *name)
1793 + return acl_delete_def_file(name);
1796 +int sys_acl_free_text(char *text)
1798 + return acl_free(text);
1801 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1803 + return acl_free(the_acl);
1806 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1808 + return acl_free(qual);
1811 +#elif defined(HAVE_TRU64_ACLS)
1813 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1814 + * is based on Draft 13 of the POSIX spec which is
1815 + * slightly different from the Draft 16 interface.
1817 + * Also, some of the permset manipulation functions
1818 + * such as acl_clear_perm() and acl_add_perm() appear
1819 + * to be broken on Tru64 so we have to manipulate
1820 + * the permission bits in the permset directly.
1822 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1824 + SMB_ACL_ENTRY_T entry;
1826 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1831 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1836 + return errno ? -1 : 0;
1839 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1841 + return acl_get_tag_type( entry_d, tag_type_p);
1844 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1846 + return acl_get_permset( entry_d, permset_p);
1849 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1851 + return acl_get_qualifier( entry_d);
1854 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1856 + return acl_get_file((char *)path_p, type);
1859 +SMB_ACL_T sys_acl_get_fd(int fd)
1861 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1864 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1866 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1871 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1873 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1878 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1883 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1885 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1888 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1890 + return acl_to_text( the_acl, plen);
1893 +SMB_ACL_T sys_acl_init( int count)
1895 + return acl_init(count);
1898 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1900 + SMB_ACL_ENTRY_T entry;
1902 + if ((entry = acl_create_entry(pacl)) == NULL) {
1910 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1912 + return acl_set_tag_type(entry, tagtype);
1915 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1917 + return acl_set_qualifier(entry, qual);
1920 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1922 + return acl_set_permset(entry, permset);
1925 +int sys_acl_valid( SMB_ACL_T theacl )
1927 + acl_entry_t entry;
1929 + return acl_valid(theacl, &entry);
1932 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1934 + return acl_set_file((char *)name, acltype, theacl);
1937 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1939 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1942 +int sys_acl_delete_def_file(const char *name)
1944 + return acl_delete_def_file((char *)name);
1947 +int sys_acl_free_text(char *text)
1950 + * (void) cast and explicit return 0 are for DEC UNIX
1951 + * which just #defines acl_free_text() to be free()
1953 + (void) acl_free_text(text);
1957 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1959 + return acl_free(the_acl);
1962 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1964 + return acl_free_qualifier(qual, tagtype);
1967 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1970 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1971 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1975 + * Note that while this code implements sufficient functionality
1976 + * to support the sys_acl_* interfaces it does not provide all
1977 + * of the semantics of the POSIX ACL interfaces.
1979 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1980 + * from a call to sys_acl_get_entry() should not be assumed to be
1981 + * valid after calling any of the following functions, which may
1982 + * reorder the entries in the ACL.
1985 + * sys_acl_set_file()
1986 + * sys_acl_set_fd()
1990 + * The only difference between Solaris and UnixWare / OpenUNIX is
1991 + * that the #defines for the ACL operations have different names
1993 +#if defined(HAVE_UNIXWARE_ACLS)
1995 +#define SETACL ACL_SET
1996 +#define GETACL ACL_GET
1997 +#define GETACLCNT ACL_CNT
2002 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2004 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2009 + if (entry_p == NULL) {
2014 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2018 + if (acl_d->next < 0) {
2023 + if (acl_d->next >= acl_d->count) {
2027 + *entry_p = &acl_d->acl[acl_d->next++];
2032 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2034 + *type_p = entry_d->a_type;
2039 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2041 + *permset_p = &entry_d->a_perm;
2046 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2048 + if (entry_d->a_type != SMB_ACL_USER
2049 + && entry_d->a_type != SMB_ACL_GROUP) {
2054 + return &entry_d->a_id;
2058 + * There is no way of knowing what size the ACL returned by
2059 + * GETACL will be unless you first call GETACLCNT which means
2060 + * making an additional system call.
2062 + * In the hope of avoiding the cost of the additional system
2063 + * call in most cases, we initially allocate enough space for
2064 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2065 + * be too small then we use GETACLCNT to find out the actual
2066 + * size, reallocate the ACL buffer, and then call GETACL again.
2069 +#define INITIAL_ACL_SIZE 16
2071 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2074 + int count; /* # of ACL entries allocated */
2075 + int naccess; /* # of access ACL entries */
2076 + int ndefault; /* # of default ACL entries */
2078 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2083 + count = INITIAL_ACL_SIZE;
2084 + if ((acl_d = sys_acl_init(count)) == NULL) {
2089 + * If there isn't enough space for the ACL entries we use
2090 + * GETACLCNT to determine the actual number of ACL entries
2091 + * reallocate and try again. This is in a loop because it
2092 + * is possible that someone else could modify the ACL and
2093 + * increase the number of entries between the call to
2094 + * GETACLCNT and the call to GETACL.
2096 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2097 + && errno == ENOSPC) {
2099 + sys_acl_free_acl(acl_d);
2101 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2105 + if ((acl_d = sys_acl_init(count)) == NULL) {
2111 + sys_acl_free_acl(acl_d);
2116 + * calculate the number of access and default ACL entries
2118 + * Note: we assume that the acl() system call returned a
2119 + * well formed ACL which is sorted so that all of the
2120 + * access ACL entries preceed any default ACL entries
2122 + for (naccess = 0; naccess < count; naccess++) {
2123 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2126 + ndefault = count - naccess;
2129 + * if the caller wants the default ACL we have to copy
2130 + * the entries down to the start of the acl[] buffer
2131 + * and mask out the ACL_DEFAULT flag from the type field
2133 + if (type == SMB_ACL_TYPE_DEFAULT) {
2136 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2137 + acl_d->acl[i] = acl_d->acl[j];
2138 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2141 + acl_d->count = ndefault;
2143 + acl_d->count = naccess;
2149 +SMB_ACL_T sys_acl_get_fd(int fd)
2152 + int count; /* # of ACL entries allocated */
2153 + int naccess; /* # of access ACL entries */
2155 + count = INITIAL_ACL_SIZE;
2156 + if ((acl_d = sys_acl_init(count)) == NULL) {
2160 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2161 + && errno == ENOSPC) {
2163 + sys_acl_free_acl(acl_d);
2165 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2169 + if ((acl_d = sys_acl_init(count)) == NULL) {
2175 + sys_acl_free_acl(acl_d);
2180 + * calculate the number of access ACL entries
2182 + for (naccess = 0; naccess < count; naccess++) {
2183 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2187 + acl_d->count = naccess;
2192 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2199 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2201 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2202 + && perm != SMB_ACL_EXECUTE) {
2207 + if (permset_d == NULL) {
2212 + *permset_d |= perm;
2217 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2219 + return *permset_d & perm;
2222 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2229 + * use an initial estimate of 20 bytes per ACL entry
2230 + * when allocating memory for the text representation
2234 + maxlen = 20 * acl_d->count;
2235 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2240 + for (i = 0; i < acl_d->count; i++) {
2241 + struct acl *ap = &acl_d->acl[i];
2250 + switch (ap->a_type) {
2252 + * for debugging purposes it's probably more
2253 + * useful to dump unknown tag types rather
2254 + * than just returning an error
2257 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2260 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2265 + case SMB_ACL_USER:
2266 + id = uidtoname(ap->a_id);
2267 + case SMB_ACL_USER_OBJ:
2271 + case SMB_ACL_GROUP:
2272 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2273 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2279 + case SMB_ACL_GROUP_OBJ:
2283 + case SMB_ACL_OTHER:
2287 + case SMB_ACL_MASK:
2293 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2294 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2295 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2298 + /* <tag> : <qualifier> : rwx \n \0 */
2299 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2302 + * If this entry would overflow the buffer
2303 + * allocate enough additional memory for this
2304 + * entry and an estimate of another 20 bytes
2305 + * for each entry still to be processed
2307 + if ((len + nbytes) > maxlen) {
2308 + char *oldtext = text;
2310 + maxlen += nbytes + 20 * (acl_d->count - i);
2312 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2313 + SAFE_FREE(oldtext);
2319 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2320 + len += nbytes - 1;
2329 +SMB_ACL_T sys_acl_init(int count)
2339 + * note that since the definition of the structure pointed
2340 + * to by the SMB_ACL_T includes the first element of the
2341 + * acl[] array, this actually allocates an ACL with room
2342 + * for (count+1) entries
2344 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2349 + a->size = count + 1;
2357 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2360 + SMB_ACL_ENTRY_T entry_d;
2362 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2367 + if (acl_d->count >= acl_d->size) {
2372 + entry_d = &acl_d->acl[acl_d->count++];
2373 + entry_d->a_type = 0;
2374 + entry_d->a_id = -1;
2375 + entry_d->a_perm = 0;
2376 + *entry_p = entry_d;
2381 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2383 + switch (tag_type) {
2384 + case SMB_ACL_USER:
2385 + case SMB_ACL_USER_OBJ:
2386 + case SMB_ACL_GROUP:
2387 + case SMB_ACL_GROUP_OBJ:
2388 + case SMB_ACL_OTHER:
2389 + case SMB_ACL_MASK:
2390 + entry_d->a_type = tag_type;
2400 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2402 + if (entry_d->a_type != SMB_ACL_GROUP
2403 + && entry_d->a_type != SMB_ACL_USER) {
2408 + entry_d->a_id = *((id_t *)qual_p);
2413 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2415 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2419 + entry_d->a_perm = *permset_d;
2425 + * sort the ACL and check it for validity
2427 + * if it's a minimal ACL with only 4 entries then we
2428 + * need to recalculate the mask permissions to make
2429 + * sure that they are the same as the GROUP_OBJ
2430 + * permissions as required by the UnixWare acl() system call.
2432 + * (note: since POSIX allows minimal ACLs which only contain
2433 + * 3 entries - ie there is no mask entry - we should, in theory,
2434 + * check for this and add a mask entry if necessary - however
2435 + * we "know" that the caller of this interface always specifies
2436 + * a mask so, in practice "this never happens" (tm) - if it *does*
2437 + * happen aclsort() will fail and return an error and someone will
2438 + * have to fix it ...)
2441 +static int acl_sort(SMB_ACL_T acl_d)
2443 + int fixmask = (acl_d->count <= 4);
2445 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2452 +int sys_acl_valid(SMB_ACL_T acl_d)
2454 + return acl_sort(acl_d);
2457 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2460 + struct acl *acl_p;
2462 + struct acl *acl_buf = NULL;
2465 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2470 + if (acl_sort(acl_d) != 0) {
2474 + acl_p = &acl_d->acl[0];
2475 + acl_count = acl_d->count;
2478 + * if it's a directory there is extra work to do
2479 + * since the acl() system call will replace both
2480 + * the access ACLs and the default ACLs (if any)
2482 + if (stat(name, &s) != 0) {
2485 + if (S_ISDIR(s.st_mode)) {
2486 + SMB_ACL_T acc_acl;
2487 + SMB_ACL_T def_acl;
2488 + SMB_ACL_T tmp_acl;
2491 + if (type == SMB_ACL_TYPE_ACCESS) {
2493 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2497 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2500 + if (tmp_acl == NULL) {
2505 + * allocate a temporary buffer for the complete ACL
2507 + acl_count = acc_acl->count + def_acl->count;
2508 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2510 + if (acl_buf == NULL) {
2511 + sys_acl_free_acl(tmp_acl);
2517 + * copy the access control and default entries into the buffer
2519 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2520 + acc_acl->count * sizeof(acl_buf[0]));
2522 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2523 + def_acl->count * sizeof(acl_buf[0]));
2526 + * set the ACL_DEFAULT flag on the default entries
2528 + for (i = acc_acl->count; i < acl_count; i++) {
2529 + acl_buf[i].a_type |= ACL_DEFAULT;
2532 + sys_acl_free_acl(tmp_acl);
2534 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2539 + ret = acl(name, SETACL, acl_count, acl_p);
2541 + SAFE_FREE(acl_buf);
2546 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2548 + if (acl_sort(acl_d) != 0) {
2552 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2555 +int sys_acl_delete_def_file(const char *path)
2561 + * fetching the access ACL and rewriting it has
2562 + * the effect of deleting the default ACL
2564 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2568 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2570 + sys_acl_free_acl(acl_d);
2575 +int sys_acl_free_text(char *text)
2581 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2587 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2592 +#elif defined(HAVE_HPUX_ACLS)
2596 + * Based on the Solaris/SCO code - with modifications.
2600 + * Note that while this code implements sufficient functionality
2601 + * to support the sys_acl_* interfaces it does not provide all
2602 + * of the semantics of the POSIX ACL interfaces.
2604 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2605 + * from a call to sys_acl_get_entry() should not be assumed to be
2606 + * valid after calling any of the following functions, which may
2607 + * reorder the entries in the ACL.
2610 + * sys_acl_set_file()
2611 + * sys_acl_set_fd()
2614 +/* This checks if the POSIX ACL system call is defined */
2615 +/* which basically corresponds to whether JFS 3.3 or */
2616 +/* higher is installed. If acl() was called when it */
2617 +/* isn't defined, it causes the process to core dump */
2618 +/* so it is important to check this and avoid acl() */
2619 +/* calls if it isn't there. */
2621 +static BOOL hpux_acl_call_presence(void)
2624 + shl_t handle = NULL;
2627 + static BOOL already_checked=0;
2629 + if(already_checked)
2633 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2635 + if(ret_val != 0) {
2636 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2637 + ret_val, errno, strerror(errno)));
2638 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2642 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2644 + already_checked = True;
2648 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2650 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2655 + if (entry_p == NULL) {
2660 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2664 + if (acl_d->next < 0) {
2669 + if (acl_d->next >= acl_d->count) {
2673 + *entry_p = &acl_d->acl[acl_d->next++];
2678 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2680 + *type_p = entry_d->a_type;
2685 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2687 + *permset_p = &entry_d->a_perm;
2692 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2694 + if (entry_d->a_type != SMB_ACL_USER
2695 + && entry_d->a_type != SMB_ACL_GROUP) {
2700 + return &entry_d->a_id;
2704 + * There is no way of knowing what size the ACL returned by
2705 + * ACL_GET will be unless you first call ACL_CNT which means
2706 + * making an additional system call.
2708 + * In the hope of avoiding the cost of the additional system
2709 + * call in most cases, we initially allocate enough space for
2710 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2711 + * be too small then we use ACL_CNT to find out the actual
2712 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2715 +#define INITIAL_ACL_SIZE 16
2717 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2720 + int count; /* # of ACL entries allocated */
2721 + int naccess; /* # of access ACL entries */
2722 + int ndefault; /* # of default ACL entries */
2724 + if(hpux_acl_call_presence() == False) {
2725 + /* Looks like we don't have the acl() system call on HPUX.
2726 + * May be the system doesn't have the latest version of JFS.
2731 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2736 + count = INITIAL_ACL_SIZE;
2737 + if ((acl_d = sys_acl_init(count)) == NULL) {
2742 + * If there isn't enough space for the ACL entries we use
2743 + * ACL_CNT to determine the actual number of ACL entries
2744 + * reallocate and try again. This is in a loop because it
2745 + * is possible that someone else could modify the ACL and
2746 + * increase the number of entries between the call to
2747 + * ACL_CNT and the call to ACL_GET.
2749 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2751 + sys_acl_free_acl(acl_d);
2753 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2757 + if ((acl_d = sys_acl_init(count)) == NULL) {
2763 + sys_acl_free_acl(acl_d);
2768 + * calculate the number of access and default ACL entries
2770 + * Note: we assume that the acl() system call returned a
2771 + * well formed ACL which is sorted so that all of the
2772 + * access ACL entries preceed any default ACL entries
2774 + for (naccess = 0; naccess < count; naccess++) {
2775 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2778 + ndefault = count - naccess;
2781 + * if the caller wants the default ACL we have to copy
2782 + * the entries down to the start of the acl[] buffer
2783 + * and mask out the ACL_DEFAULT flag from the type field
2785 + if (type == SMB_ACL_TYPE_DEFAULT) {
2788 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2789 + acl_d->acl[i] = acl_d->acl[j];
2790 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2793 + acl_d->count = ndefault;
2795 + acl_d->count = naccess;
2801 +SMB_ACL_T sys_acl_get_fd(int fd)
2804 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2807 + files_struct *fsp = file_find_fd(fd);
2809 + if (fsp == NULL) {
2815 + * We know we're in the same conn context. So we
2816 + * can use the relative path.
2819 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2822 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2829 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2831 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2832 + && perm != SMB_ACL_EXECUTE) {
2837 + if (permset_d == NULL) {
2842 + *permset_d |= perm;
2847 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2849 + return *permset_d & perm;
2852 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2859 + * use an initial estimate of 20 bytes per ACL entry
2860 + * when allocating memory for the text representation
2864 + maxlen = 20 * acl_d->count;
2865 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2870 + for (i = 0; i < acl_d->count; i++) {
2871 + struct acl *ap = &acl_d->acl[i];
2880 + switch (ap->a_type) {
2882 + * for debugging purposes it's probably more
2883 + * useful to dump unknown tag types rather
2884 + * than just returning an error
2887 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2890 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2895 + case SMB_ACL_USER:
2896 + id = uidtoname(ap->a_id);
2897 + case SMB_ACL_USER_OBJ:
2901 + case SMB_ACL_GROUP:
2902 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2903 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2909 + case SMB_ACL_GROUP_OBJ:
2913 + case SMB_ACL_OTHER:
2917 + case SMB_ACL_MASK:
2923 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2924 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2925 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2928 + /* <tag> : <qualifier> : rwx \n \0 */
2929 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2932 + * If this entry would overflow the buffer
2933 + * allocate enough additional memory for this
2934 + * entry and an estimate of another 20 bytes
2935 + * for each entry still to be processed
2937 + if ((len + nbytes) > maxlen) {
2938 + char *oldtext = text;
2940 + maxlen += nbytes + 20 * (acl_d->count - i);
2942 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2949 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2950 + len += nbytes - 1;
2959 +SMB_ACL_T sys_acl_init(int count)
2969 + * note that since the definition of the structure pointed
2970 + * to by the SMB_ACL_T includes the first element of the
2971 + * acl[] array, this actually allocates an ACL with room
2972 + * for (count+1) entries
2974 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2979 + a->size = count + 1;
2987 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2990 + SMB_ACL_ENTRY_T entry_d;
2992 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2997 + if (acl_d->count >= acl_d->size) {
3002 + entry_d = &acl_d->acl[acl_d->count++];
3003 + entry_d->a_type = 0;
3004 + entry_d->a_id = -1;
3005 + entry_d->a_perm = 0;
3006 + *entry_p = entry_d;
3011 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3013 + switch (tag_type) {
3014 + case SMB_ACL_USER:
3015 + case SMB_ACL_USER_OBJ:
3016 + case SMB_ACL_GROUP:
3017 + case SMB_ACL_GROUP_OBJ:
3018 + case SMB_ACL_OTHER:
3019 + case SMB_ACL_MASK:
3020 + entry_d->a_type = tag_type;
3030 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3032 + if (entry_d->a_type != SMB_ACL_GROUP
3033 + && entry_d->a_type != SMB_ACL_USER) {
3038 + entry_d->a_id = *((id_t *)qual_p);
3043 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3045 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3049 + entry_d->a_perm = *permset_d;
3054 +/* Structure to capture the count for each type of ACE. */
3056 +struct hpux_acl_types {
3060 + int n_def_user_obj;
3065 + int n_def_group_obj;
3069 + int n_def_other_obj;
3072 + int n_def_class_obj;
3074 + int n_illegal_obj;
3078 + * Counts the different number of objects in a given array of ACL
3082 + * acl_count - Count of ACLs in the array of ACL strucutres.
3083 + * aclp - Array of ACL structures.
3084 + * acl_type_count - Pointer to acl_types structure. Should already be
3088 + * acl_type_count - This structure is filled up with counts of various
3092 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3096 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3098 + for(i=0;i<acl_count;i++) {
3099 + switch(aclp[i].a_type) {
3101 + acl_type_count->n_user++;
3104 + acl_type_count->n_user_obj++;
3106 + case DEF_USER_OBJ:
3107 + acl_type_count->n_def_user_obj++;
3110 + acl_type_count->n_group++;
3113 + acl_type_count->n_group_obj++;
3115 + case DEF_GROUP_OBJ:
3116 + acl_type_count->n_def_group_obj++;
3119 + acl_type_count->n_other_obj++;
3121 + case DEF_OTHER_OBJ:
3122 + acl_type_count->n_def_other_obj++;
3125 + acl_type_count->n_class_obj++;
3127 + case DEF_CLASS_OBJ:
3128 + acl_type_count->n_def_class_obj++;
3131 + acl_type_count->n_def_user++;
3134 + acl_type_count->n_def_group++;
3137 + acl_type_count->n_illegal_obj++;
3143 +/* swap_acl_entries: Swaps two ACL entries.
3145 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3148 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3150 + struct acl temp_acl;
3152 + temp_acl.a_type = aclp0->a_type;
3153 + temp_acl.a_id = aclp0->a_id;
3154 + temp_acl.a_perm = aclp0->a_perm;
3156 + aclp0->a_type = aclp1->a_type;
3157 + aclp0->a_id = aclp1->a_id;
3158 + aclp0->a_perm = aclp1->a_perm;
3160 + aclp1->a_type = temp_acl.a_type;
3161 + aclp1->a_id = temp_acl.a_id;
3162 + aclp1->a_perm = temp_acl.a_perm;
3165 +/* prohibited_duplicate_type
3166 + * Identifies if given ACL type can have duplicate entries or
3169 + * Inputs: acl_type - ACL Type.
3175 + * True - If the ACL type matches any of the prohibited types.
3176 + * False - If the ACL type doesn't match any of the prohibited types.
3179 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3181 + switch(acl_type) {
3192 +/* get_needed_class_perm
3193 + * Returns the permissions of a ACL structure only if the ACL
3194 + * type matches one of the pre-determined types for computing
3195 + * CLASS_OBJ permissions.
3197 + * Inputs: aclp - Pointer to ACL structure.
3200 +static int hpux_get_needed_class_perm(struct acl *aclp)
3202 + switch(aclp->a_type) {
3206 + case DEF_USER_OBJ:
3208 + case DEF_GROUP_OBJ:
3210 + case DEF_CLASS_OBJ:
3211 + case DEF_OTHER_OBJ:
3212 + return aclp->a_perm;
3218 +/* acl_sort for HPUX.
3219 + * Sorts the array of ACL structures as per the description in
3220 + * aclsort man page. Refer to aclsort man page for more details
3224 + * acl_count - Count of ACLs in the array of ACL structures.
3225 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3227 + * aclp - Array of ACL structures.
3231 + * aclp - Sorted array of ACL structures.
3235 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3236 + * debug log in case of failure.
3239 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3241 +#if !defined(HAVE_HPUX_ACLSORT)
3243 + * The aclsort() system call is availabe on the latest HPUX General
3244 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3245 + * function. Because, we don't want to update to a new
3246 + * HPUX GR bundle just for aclsort() call.
3249 + struct hpux_acl_types acl_obj_count;
3250 + int n_class_obj_perm = 0;
3254 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3258 + if(aclp == NULL) {
3259 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3263 + /* Count different types of ACLs in the ACLs array */
3265 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3267 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3268 + * CLASS_OBJ and OTHER_OBJ
3271 + if( (acl_obj_count.n_user_obj != 1) ||
3272 + (acl_obj_count.n_group_obj != 1) ||
3273 + (acl_obj_count.n_class_obj != 1) ||
3274 + (acl_obj_count.n_other_obj != 1)
3276 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3277 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3281 + /* If any of the default objects are present, there should be only
3282 + * one of them each.
3285 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3286 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3287 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3288 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3292 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3295 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3296 + * same ACL type, sort by ACL id.
3298 + * I am using the trival kind of sorting method here because, performance isn't
3299 + * really effected by the ACLs feature. More over there aren't going to be more
3300 + * than 17 entries on HPUX.
3303 + for(i=0; i<acl_count;i++) {
3304 + for (j=i+1; j<acl_count; j++) {
3305 + if( aclp[i].a_type > aclp[j].a_type ) {
3306 + /* ACL entries out of order, swap them */
3308 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3310 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3312 + /* ACL entries of same type, sort by id */
3314 + if(aclp[i].a_id > aclp[j].a_id) {
3315 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3316 + } else if (aclp[i].a_id == aclp[j].a_id) {
3317 + /* We have a duplicate entry. */
3318 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3319 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3320 + aclp[i].a_type, aclp[i].a_id));
3329 + /* set the class obj permissions to the computed one. */
3331 + int n_class_obj_index = -1;
3333 + for(i=0;i<acl_count;i++) {
3334 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3336 + if(aclp[i].a_type == CLASS_OBJ)
3337 + n_class_obj_index = i;
3339 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3344 + return aclsort(acl_count, calclass, aclp);
3349 + * sort the ACL and check it for validity
3351 + * if it's a minimal ACL with only 4 entries then we
3352 + * need to recalculate the mask permissions to make
3353 + * sure that they are the same as the GROUP_OBJ
3354 + * permissions as required by the UnixWare acl() system call.
3356 + * (note: since POSIX allows minimal ACLs which only contain
3357 + * 3 entries - ie there is no mask entry - we should, in theory,
3358 + * check for this and add a mask entry if necessary - however
3359 + * we "know" that the caller of this interface always specifies
3360 + * a mask so, in practice "this never happens" (tm) - if it *does*
3361 + * happen aclsort() will fail and return an error and someone will
3362 + * have to fix it ...)
3365 +static int acl_sort(SMB_ACL_T acl_d)
3367 + int fixmask = (acl_d->count <= 4);
3369 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3376 +int sys_acl_valid(SMB_ACL_T acl_d)
3378 + return acl_sort(acl_d);
3381 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3384 + struct acl *acl_p;
3386 + struct acl *acl_buf = NULL;
3389 + if(hpux_acl_call_presence() == False) {
3390 + /* Looks like we don't have the acl() system call on HPUX.
3391 + * May be the system doesn't have the latest version of JFS.
3397 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3402 + if (acl_sort(acl_d) != 0) {
3406 + acl_p = &acl_d->acl[0];
3407 + acl_count = acl_d->count;
3410 + * if it's a directory there is extra work to do
3411 + * since the acl() system call will replace both
3412 + * the access ACLs and the default ACLs (if any)
3414 + if (stat(name, &s) != 0) {
3417 + if (S_ISDIR(s.st_mode)) {
3418 + SMB_ACL_T acc_acl;
3419 + SMB_ACL_T def_acl;
3420 + SMB_ACL_T tmp_acl;
3423 + if (type == SMB_ACL_TYPE_ACCESS) {
3425 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3429 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3432 + if (tmp_acl == NULL) {
3437 + * allocate a temporary buffer for the complete ACL
3439 + acl_count = acc_acl->count + def_acl->count;
3440 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3442 + if (acl_buf == NULL) {
3443 + sys_acl_free_acl(tmp_acl);
3449 + * copy the access control and default entries into the buffer
3451 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3452 + acc_acl->count * sizeof(acl_buf[0]));
3454 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3455 + def_acl->count * sizeof(acl_buf[0]));
3458 + * set the ACL_DEFAULT flag on the default entries
3460 + for (i = acc_acl->count; i < acl_count; i++) {
3461 + acl_buf[i].a_type |= ACL_DEFAULT;
3464 + sys_acl_free_acl(tmp_acl);
3466 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3471 + ret = acl(name, ACL_SET, acl_count, acl_p);
3480 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3483 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3486 + files_struct *fsp = file_find_fd(fd);
3488 + if (fsp == NULL) {
3493 + if (acl_sort(acl_d) != 0) {
3498 + * We know we're in the same conn context. So we
3499 + * can use the relative path.
3502 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3505 +int sys_acl_delete_def_file(const char *path)
3511 + * fetching the access ACL and rewriting it has
3512 + * the effect of deleting the default ACL
3514 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3518 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3520 + sys_acl_free_acl(acl_d);
3525 +int sys_acl_free_text(char *text)
3531 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3537 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3542 +#elif defined(HAVE_IRIX_ACLS)
3544 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3546 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3551 + if (entry_p == NULL) {
3556 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3560 + if (acl_d->next < 0) {
3565 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3569 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3574 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3576 + *type_p = entry_d->ae_tag;
3581 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3583 + *permset_p = entry_d;
3588 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3590 + if (entry_d->ae_tag != SMB_ACL_USER
3591 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3596 + return &entry_d->ae_id;
3599 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3603 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3607 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3612 + a->freeaclp = True;
3616 +SMB_ACL_T sys_acl_get_fd(int fd)
3620 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3624 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3629 + a->freeaclp = True;
3633 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3635 + permset_d->ae_perm = 0;
3640 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3642 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3643 + && perm != SMB_ACL_EXECUTE) {
3648 + if (permset_d == NULL) {
3653 + permset_d->ae_perm |= perm;
3658 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3660 + return permset_d->ae_perm & perm;
3663 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3665 + return acl_to_text(acl_d->aclp, len_p);
3668 +SMB_ACL_T sys_acl_init(int count)
3677 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3683 + a->freeaclp = False;
3684 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3685 + a->aclp->acl_cnt = 0;
3691 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3694 + SMB_ACL_ENTRY_T entry_d;
3696 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3701 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3706 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3707 + entry_d->ae_tag = 0;
3708 + entry_d->ae_id = 0;
3709 + entry_d->ae_perm = 0;
3710 + *entry_p = entry_d;
3715 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3717 + switch (tag_type) {
3718 + case SMB_ACL_USER:
3719 + case SMB_ACL_USER_OBJ:
3720 + case SMB_ACL_GROUP:
3721 + case SMB_ACL_GROUP_OBJ:
3722 + case SMB_ACL_OTHER:
3723 + case SMB_ACL_MASK:
3724 + entry_d->ae_tag = tag_type;
3734 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3736 + if (entry_d->ae_tag != SMB_ACL_GROUP
3737 + && entry_d->ae_tag != SMB_ACL_USER) {
3742 + entry_d->ae_id = *((id_t *)qual_p);
3747 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3749 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3753 + entry_d->ae_perm = permset_d->ae_perm;
3758 +int sys_acl_valid(SMB_ACL_T acl_d)
3760 + return acl_valid(acl_d->aclp);
3763 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3765 + return acl_set_file(name, type, acl_d->aclp);
3768 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3770 + return acl_set_fd(fd, acl_d->aclp);
3773 +int sys_acl_delete_def_file(const char *name)
3775 + return acl_delete_def_file(name);
3778 +int sys_acl_free_text(char *text)
3780 + return acl_free(text);
3783 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3785 + if (acl_d->freeaclp) {
3786 + acl_free(acl_d->aclp);
3792 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3797 +#elif defined(HAVE_AIX_ACLS)
3799 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3801 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3803 + struct acl_entry_link *link;
3804 + struct new_acl_entry *entry;
3807 + DEBUG(10,("This is the count: %d\n",theacl->count));
3809 + /* Check if count was previously set to -1. *
3810 + * If it was, that means we reached the end *
3811 + * of the acl last time. */
3812 + if(theacl->count == -1)
3816 + /* To get to the next acl, traverse linked list until index *
3817 + * of acl matches the count we are keeping. This count is *
3818 + * incremented each time we return an acl entry. */
3820 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3821 + link = link->nextp;
3823 + entry = *entry_p = link->entryp;
3825 + DEBUG(10,("*entry_p is %d\n",entry_p));
3826 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3828 + /* Increment count */
3830 + if(link->nextp == NULL)
3831 + theacl->count = -1;
3836 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3838 + /* Initialize tag type */
3841 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3843 + /* Depending on what type of entry we have, *
3844 + * return tag type. */
3845 + switch(entry_d->ace_id->id_type) {
3847 + *tag_type_p = SMB_ACL_USER;
3850 + *tag_type_p = SMB_ACL_GROUP;
3853 + case SMB_ACL_USER_OBJ:
3854 + case SMB_ACL_GROUP_OBJ:
3855 + case SMB_ACL_OTHER:
3856 + *tag_type_p = entry_d->ace_id->id_type;
3866 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3868 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3869 + *permset_p = &entry_d->ace_access;
3870 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3871 + if(!(**permset_p & S_IXUSR) &&
3872 + !(**permset_p & S_IWUSR) &&
3873 + !(**permset_p & S_IRUSR) &&
3874 + (**permset_p != 0))
3877 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3881 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3883 + return(entry_d->ace_id->id_data);
3886 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3888 + struct acl *file_acl = (struct acl *)NULL;
3889 + struct acl_entry *acl_entry;
3890 + struct new_acl_entry *new_acl_entry;
3891 + struct ace_id *idp;
3892 + struct acl_entry_link *acl_entry_link;
3893 + struct acl_entry_link *acl_entry_link_head;
3898 + /* AIX has no DEFAULT */
3899 + if ( type == SMB_ACL_TYPE_DEFAULT )
3902 + /* Get the acl using statacl */
3904 + DEBUG(10,("Entering sys_acl_get_file\n"));
3905 + DEBUG(10,("path_p is %s\n",path_p));
3907 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3909 + if(file_acl == NULL) {
3911 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3915 + memset(file_acl,0,BUFSIZ);
3917 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3919 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3920 + SAFE_FREE(file_acl);
3924 + DEBUG(10,("Got facl and returned it\n"));
3926 + /* Point to the first acl entry in the acl */
3927 + acl_entry = file_acl->acl_ext;
3929 + /* Begin setting up the head of the linked list *
3930 + * that will be used for the storing the acl *
3931 + * in a way that is useful for the posix_acls.c *
3934 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3935 + if(acl_entry_link_head == NULL)
3938 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3939 + if(acl_entry_link->entryp == NULL) {
3940 + SAFE_FREE(file_acl);
3942 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3946 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3947 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3949 + /* Check if the extended acl bit is on. *
3950 + * If it isn't, do not show the *
3951 + * contents of the acl since AIX intends *
3952 + * the extended info to remain unused */
3954 + if(file_acl->acl_mode & S_IXACL){
3955 + /* while we are not pointing to the very end */
3956 + while(acl_entry < acl_last(file_acl)) {
3957 + /* before we malloc anything, make sure this is */
3958 + /* a valid acl entry and one that we want to map */
3959 + idp = id_nxt(acl_entry->ace_id);
3960 + if((acl_entry->ace_type == ACC_SPECIFY ||
3961 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3962 + acl_entry = acl_nxt(acl_entry);
3966 + idp = acl_entry->ace_id;
3968 + /* Check if this is the first entry in the linked list. *
3969 + * The first entry needs to keep prevp pointing to NULL *
3970 + * and already has entryp allocated. */
3972 + if(acl_entry_link_head->count != 0) {
3973 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3975 + if(acl_entry_link->nextp == NULL) {
3976 + SAFE_FREE(file_acl);
3978 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3982 + acl_entry_link->nextp->prevp = acl_entry_link;
3983 + acl_entry_link = acl_entry_link->nextp;
3984 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3985 + if(acl_entry_link->entryp == NULL) {
3986 + SAFE_FREE(file_acl);
3988 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3991 + acl_entry_link->nextp = NULL;
3994 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3996 + /* Don't really need this since all types are going *
3997 + * to be specified but, it's better than leaving it 0 */
3999 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4001 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4003 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4005 + /* The access in the acl entries must be left shifted by *
4006 + * three bites, because they will ultimately be compared *
4007 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4009 + switch(acl_entry->ace_type){
4012 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4013 + acl_entry_link->entryp->ace_access <<= 6;
4014 + acl_entry_link_head->count++;
4017 + /* Since there is no way to return a DENY acl entry *
4018 + * change to PERMIT and then shift. */
4019 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4020 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4021 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4022 + acl_entry_link->entryp->ace_access <<= 6;
4023 + acl_entry_link_head->count++;
4029 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4030 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4032 + acl_entry = acl_nxt(acl_entry);
4034 + } /* end of if enabled */
4036 + /* Since owner, group, other acl entries are not *
4037 + * part of the acl entries in an acl, they must *
4038 + * be dummied up to become part of the list. */
4040 + for( i = 1; i < 4; i++) {
4041 + DEBUG(10,("i is %d\n",i));
4042 + if(acl_entry_link_head->count != 0) {
4043 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4044 + if(acl_entry_link->nextp == NULL) {
4045 + SAFE_FREE(file_acl);
4047 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4051 + acl_entry_link->nextp->prevp = acl_entry_link;
4052 + acl_entry_link = acl_entry_link->nextp;
4053 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4054 + if(acl_entry_link->entryp == NULL) {
4055 + SAFE_FREE(file_acl);
4057 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4062 + acl_entry_link->nextp = NULL;
4064 + new_acl_entry = acl_entry_link->entryp;
4065 + idp = new_acl_entry->ace_id;
4067 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4068 + new_acl_entry->ace_type = ACC_PERMIT;
4069 + idp->id_len = sizeof(struct ace_id);
4070 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4071 + memset(idp->id_data,0,sizeof(uid_t));
4075 + new_acl_entry->ace_access = file_acl->g_access << 6;
4076 + idp->id_type = SMB_ACL_GROUP_OBJ;
4080 + new_acl_entry->ace_access = file_acl->o_access << 6;
4081 + idp->id_type = SMB_ACL_OTHER;
4085 + new_acl_entry->ace_access = file_acl->u_access << 6;
4086 + idp->id_type = SMB_ACL_USER_OBJ;
4094 + acl_entry_link_head->count++;
4095 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4098 + acl_entry_link_head->count = 0;
4099 + SAFE_FREE(file_acl);
4101 + return(acl_entry_link_head);
4104 +SMB_ACL_T sys_acl_get_fd(int fd)
4106 + struct acl *file_acl = (struct acl *)NULL;
4107 + struct acl_entry *acl_entry;
4108 + struct new_acl_entry *new_acl_entry;
4109 + struct ace_id *idp;
4110 + struct acl_entry_link *acl_entry_link;
4111 + struct acl_entry_link *acl_entry_link_head;
4116 + /* Get the acl using fstatacl */
4118 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4119 + DEBUG(10,("fd is %d\n",fd));
4120 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4122 + if(file_acl == NULL) {
4124 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4128 + memset(file_acl,0,BUFSIZ);
4130 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4132 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4133 + SAFE_FREE(file_acl);
4137 + DEBUG(10,("Got facl and returned it\n"));
4139 + /* Point to the first acl entry in the acl */
4141 + acl_entry = file_acl->acl_ext;
4142 + /* Begin setting up the head of the linked list *
4143 + * that will be used for the storing the acl *
4144 + * in a way that is useful for the posix_acls.c *
4147 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4148 + if(acl_entry_link_head == NULL){
4149 + SAFE_FREE(file_acl);
4153 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4155 + if(acl_entry_link->entryp == NULL) {
4157 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4158 + SAFE_FREE(file_acl);
4162 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4163 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4165 + /* Check if the extended acl bit is on. *
4166 + * If it isn't, do not show the *
4167 + * contents of the acl since AIX intends *
4168 + * the extended info to remain unused */
4170 + if(file_acl->acl_mode & S_IXACL){
4171 + /* while we are not pointing to the very end */
4172 + while(acl_entry < acl_last(file_acl)) {
4173 + /* before we malloc anything, make sure this is */
4174 + /* a valid acl entry and one that we want to map */
4176 + idp = id_nxt(acl_entry->ace_id);
4177 + if((acl_entry->ace_type == ACC_SPECIFY ||
4178 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4179 + acl_entry = acl_nxt(acl_entry);
4183 + idp = acl_entry->ace_id;
4185 + /* Check if this is the first entry in the linked list. *
4186 + * The first entry needs to keep prevp pointing to NULL *
4187 + * and already has entryp allocated. */
4189 + if(acl_entry_link_head->count != 0) {
4190 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4191 + if(acl_entry_link->nextp == NULL) {
4193 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4194 + SAFE_FREE(file_acl);
4197 + acl_entry_link->nextp->prevp = acl_entry_link;
4198 + acl_entry_link = acl_entry_link->nextp;
4199 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4200 + if(acl_entry_link->entryp == NULL) {
4202 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4203 + SAFE_FREE(file_acl);
4207 + acl_entry_link->nextp = NULL;
4210 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4212 + /* Don't really need this since all types are going *
4213 + * to be specified but, it's better than leaving it 0 */
4215 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4216 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4218 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4220 + /* The access in the acl entries must be left shifted by *
4221 + * three bites, because they will ultimately be compared *
4222 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4224 + switch(acl_entry->ace_type){
4227 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4228 + acl_entry_link->entryp->ace_access <<= 6;
4229 + acl_entry_link_head->count++;
4232 + /* Since there is no way to return a DENY acl entry *
4233 + * change to PERMIT and then shift. */
4234 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4235 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4236 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4237 + acl_entry_link->entryp->ace_access <<= 6;
4238 + acl_entry_link_head->count++;
4244 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4245 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4247 + acl_entry = acl_nxt(acl_entry);
4249 + } /* end of if enabled */
4251 + /* Since owner, group, other acl entries are not *
4252 + * part of the acl entries in an acl, they must *
4253 + * be dummied up to become part of the list. */
4255 + for( i = 1; i < 4; i++) {
4256 + DEBUG(10,("i is %d\n",i));
4257 + if(acl_entry_link_head->count != 0){
4258 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4259 + if(acl_entry_link->nextp == NULL) {
4261 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4262 + SAFE_FREE(file_acl);
4266 + acl_entry_link->nextp->prevp = acl_entry_link;
4267 + acl_entry_link = acl_entry_link->nextp;
4268 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4270 + if(acl_entry_link->entryp == NULL) {
4271 + SAFE_FREE(file_acl);
4273 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4278 + acl_entry_link->nextp = NULL;
4280 + new_acl_entry = acl_entry_link->entryp;
4281 + idp = new_acl_entry->ace_id;
4283 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4284 + new_acl_entry->ace_type = ACC_PERMIT;
4285 + idp->id_len = sizeof(struct ace_id);
4286 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4287 + memset(idp->id_data,0,sizeof(uid_t));
4291 + new_acl_entry->ace_access = file_acl->g_access << 6;
4292 + idp->id_type = SMB_ACL_GROUP_OBJ;
4296 + new_acl_entry->ace_access = file_acl->o_access << 6;
4297 + idp->id_type = SMB_ACL_OTHER;
4301 + new_acl_entry->ace_access = file_acl->u_access << 6;
4302 + idp->id_type = SMB_ACL_USER_OBJ;
4309 + acl_entry_link_head->count++;
4310 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4313 + acl_entry_link_head->count = 0;
4314 + SAFE_FREE(file_acl);
4316 + return(acl_entry_link_head);
4319 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4321 + *permset = *permset & ~0777;
4325 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4328 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4332 + DEBUG(10,("This is the permset now: %d\n",*permset));
4336 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4341 +SMB_ACL_T sys_acl_init( int count)
4343 + struct acl_entry_link *theacl = NULL;
4345 + DEBUG(10,("Entering sys_acl_init\n"));
4347 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4348 + if(theacl == NULL) {
4350 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4354 + theacl->count = 0;
4355 + theacl->nextp = NULL;
4356 + theacl->prevp = NULL;
4357 + theacl->entryp = NULL;
4358 + DEBUG(10,("Exiting sys_acl_init\n"));
4362 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4364 + struct acl_entry_link *theacl;
4365 + struct acl_entry_link *acl_entryp;
4366 + struct acl_entry_link *temp_entry;
4369 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4371 + theacl = acl_entryp = *pacl;
4373 + /* Get to the end of the acl before adding entry */
4375 + for(counting=0; counting < theacl->count; counting++){
4376 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4377 + temp_entry = acl_entryp;
4378 + acl_entryp = acl_entryp->nextp;
4381 + if(theacl->count != 0){
4382 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4383 + if(acl_entryp == NULL) {
4385 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4389 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4390 + acl_entryp->prevp = temp_entry;
4391 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4394 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4395 + if(*pentry == NULL) {
4397 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4401 + memset(*pentry,0,sizeof(struct new_acl_entry));
4402 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4403 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4404 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4405 + acl_entryp->nextp = NULL;
4407 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4411 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4413 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4414 + entry->ace_id->id_type = tagtype;
4415 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4416 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4419 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4421 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4422 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4423 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4427 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4429 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4430 + if(!(*permset & S_IXUSR) &&
4431 + !(*permset & S_IWUSR) &&
4432 + !(*permset & S_IRUSR) &&
4436 + entry->ace_access = *permset;
4437 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4438 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4442 +int sys_acl_valid( SMB_ACL_T theacl )
4445 + int group_obj = 0;
4446 + int other_obj = 0;
4447 + struct acl_entry_link *acl_entry;
4449 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4450 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4451 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4452 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4455 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4457 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4463 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4465 + struct acl_entry_link *acl_entry_link = NULL;
4466 + struct acl *file_acl = NULL;
4467 + struct acl *file_acl_temp = NULL;
4468 + struct acl_entry *acl_entry = NULL;
4469 + struct ace_id *ace_id = NULL;
4476 + DEBUG(10,("Entering sys_acl_set_file\n"));
4477 + DEBUG(10,("File name is %s\n",name));
4479 + /* AIX has no default ACL */
4480 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4483 + acl_length = BUFSIZ;
4484 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4486 + if(file_acl == NULL) {
4488 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4492 + memset(file_acl,0,BUFSIZ);
4494 + file_acl->acl_len = ACL_SIZ;
4495 + file_acl->acl_mode = S_IXACL;
4497 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4498 + acl_entry_link->entryp->ace_access >>= 6;
4499 + id_type = acl_entry_link->entryp->ace_id->id_type;
4502 + case SMB_ACL_USER_OBJ:
4503 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4505 + case SMB_ACL_GROUP_OBJ:
4506 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4508 + case SMB_ACL_OTHER:
4509 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4511 + case SMB_ACL_MASK:
4515 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4516 + acl_length += sizeof(struct acl_entry);
4517 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4518 + if(file_acl_temp == NULL) {
4519 + SAFE_FREE(file_acl);
4521 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4525 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4526 + SAFE_FREE(file_acl);
4527 + file_acl = file_acl_temp;
4530 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4531 + file_acl->acl_len += sizeof(struct acl_entry);
4532 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4533 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4535 + /* In order to use this, we'll need to wait until we can get denies */
4536 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4537 + acl_entry->ace_type = ACC_SPECIFY; */
4539 + acl_entry->ace_type = ACC_SPECIFY;
4541 + ace_id = acl_entry->ace_id;
4543 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4544 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4545 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4546 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4547 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4550 + rc = chacl(name,file_acl,file_acl->acl_len);
4551 + DEBUG(10,("errno is %d\n",errno));
4552 + DEBUG(10,("return code is %d\n",rc));
4553 + SAFE_FREE(file_acl);
4554 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4558 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4560 + struct acl_entry_link *acl_entry_link = NULL;
4561 + struct acl *file_acl = NULL;
4562 + struct acl *file_acl_temp = NULL;
4563 + struct acl_entry *acl_entry = NULL;
4564 + struct ace_id *ace_id = NULL;
4570 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4571 + acl_length = BUFSIZ;
4572 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4574 + if(file_acl == NULL) {
4576 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4580 + memset(file_acl,0,BUFSIZ);
4582 + file_acl->acl_len = ACL_SIZ;
4583 + file_acl->acl_mode = S_IXACL;
4585 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4586 + acl_entry_link->entryp->ace_access >>= 6;
4587 + id_type = acl_entry_link->entryp->ace_id->id_type;
4588 + DEBUG(10,("The id_type is %d\n",id_type));
4591 + case SMB_ACL_USER_OBJ:
4592 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4594 + case SMB_ACL_GROUP_OBJ:
4595 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4597 + case SMB_ACL_OTHER:
4598 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4600 + case SMB_ACL_MASK:
4604 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4605 + acl_length += sizeof(struct acl_entry);
4606 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4607 + if(file_acl_temp == NULL) {
4608 + SAFE_FREE(file_acl);
4610 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4614 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4615 + SAFE_FREE(file_acl);
4616 + file_acl = file_acl_temp;
4619 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4620 + file_acl->acl_len += sizeof(struct acl_entry);
4621 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4622 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4624 + /* In order to use this, we'll need to wait until we can get denies */
4625 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4626 + acl_entry->ace_type = ACC_SPECIFY; */
4628 + acl_entry->ace_type = ACC_SPECIFY;
4630 + ace_id = acl_entry->ace_id;
4632 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4633 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4634 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4635 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4636 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4639 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4640 + DEBUG(10,("errno is %d\n",errno));
4641 + DEBUG(10,("return code is %d\n",rc));
4642 + SAFE_FREE(file_acl);
4643 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4647 +int sys_acl_delete_def_file(const char *name)
4649 + /* AIX has no default ACL */
4653 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4655 + return(*permset & perm);
4658 +int sys_acl_free_text(char *text)
4663 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4665 + struct acl_entry_link *acl_entry_link;
4667 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4668 + SAFE_FREE(acl_entry_link->prevp->entryp);
4669 + SAFE_FREE(acl_entry_link->prevp);
4672 + SAFE_FREE(acl_entry_link->prevp->entryp);
4673 + SAFE_FREE(acl_entry_link->prevp);
4674 + SAFE_FREE(acl_entry_link->entryp);
4675 + SAFE_FREE(acl_entry_link);
4680 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4685 +#else /* No ACLs. */
4687 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4693 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4699 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4705 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4711 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4714 + return (SMB_ACL_T)NULL;
4717 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4720 + return (SMB_ACL_T)NULL;
4723 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4729 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4735 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4738 + return (permset & perm) ? 1 : 0;
4741 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4747 +int sys_acl_free_text(UNUSED(char *text))
4753 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4759 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4765 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4771 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4777 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4783 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4789 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4795 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4801 +int sys_acl_delete_def_file(UNUSED(const char *name))
4807 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4813 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4819 +#endif /* No ACLs. */
4821 +/************************************************************************
4822 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4824 +************************************************************************/
4826 +int no_acl_syscall_error(int err)
4828 +#if defined(ENOSYS)
4829 + if (err == ENOSYS) {
4833 +#if defined(ENOTSUP)
4834 + if (err == ENOTSUP) {
4840 --- old/lib/sysacls.h
4841 +++ new/lib/sysacls.h
4843 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4844 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4845 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4846 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4847 +#define slprintf snprintf
4849 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4850 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4851 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4852 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4853 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4854 +SMB_ACL_T sys_acl_get_fd(int fd);
4855 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4856 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4857 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4858 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4859 +SMB_ACL_T sys_acl_init(int count);
4860 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4861 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4862 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4863 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4864 +int sys_acl_valid(SMB_ACL_T theacl);
4865 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4866 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4867 +int sys_acl_delete_def_file(const char *name);
4868 +int sys_acl_free_text(char *text);
4869 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4870 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4873 @@ -58,7 +58,7 @@ BEGIN {
4877 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4878 +!/^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/ {
4884 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4886 int preserve_links = 0;
4887 int preserve_hard_links = 0;
4888 +int preserve_acls = 0;
4889 int preserve_perms = 0;
4890 int preserve_executability = 0;
4891 int preserve_devices = 0;
4892 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4893 char const *got_socketpair = "no ";
4894 char const *have_inplace = "no ";
4895 char const *hardlinks = "no ";
4896 + char const *acls = "no ";
4897 char const *links = "no ";
4898 char const *ipv6 = "no ";
4899 STRUCT_STAT *dumstat;
4900 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4904 +#ifdef SUPPORT_ACLS
4908 #ifdef SUPPORT_LINKS
4911 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4912 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4913 rprintf(f, "<http://rsync.samba.org/>\n");
4914 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4915 - "%shard links, %ssymlinks, batchfiles,\n",
4916 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4917 (int) (sizeof (OFF_T) * 8),
4918 - got_socketpair, hardlinks, links);
4919 + got_socketpair, hardlinks, acls, links);
4921 /* Note that this field may not have type ino_t. It depends
4922 * on the complicated interaction between largefile feature
4923 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4924 rprintf(F," -H, --hard-links preserve hard links\n");
4925 rprintf(F," -p, --perms preserve permissions\n");
4926 rprintf(F," -E, --executability preserve the file's executability\n");
4927 +#ifdef SUPPORT_ACLS
4928 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4930 rprintf(F," --chmod=CHMOD change destination permissions\n");
4931 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4932 rprintf(F," -g, --group preserve group\n");
4933 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4934 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4935 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4936 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4937 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4938 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4939 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4940 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4941 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4942 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4943 @@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
4948 +#ifdef SUPPORT_ACLS
4950 + preserve_perms = 1;
4953 + /* FIXME: this should probably be ignored with a
4954 + * warning and then countermeasures taken to
4955 + * restrict group and other access in the presence
4956 + * of any more restrictive ACLs, but this is safe
4958 + snprintf(err_buf,sizeof(err_buf),
4959 + "ACLs are not supported on this %s\n",
4960 + am_server ? "server" : "client");
4966 /* A large opt value means that set_refuse_options()
4967 * turned this option off. */
4968 @@ -1511,6 +1541,10 @@ void server_options(char **args,int *arg
4970 if (preserve_hard_links)
4972 +#ifdef SUPPORT_ACLS
4973 + if (preserve_acls)
4974 + argstr[x++] = 'A';
4981 @@ -46,6 +46,7 @@ extern int keep_partial;
4982 extern int checksum_seed;
4984 extern int delay_updates;
4985 +extern mode_t orig_umask;
4986 extern struct stats stats;
4987 extern char *log_format;
4988 extern char *tmpdir;
4989 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4990 int itemizing = am_daemon ? daemon_log_format_has_i
4991 : !am_server && log_format_has_i;
4992 int max_phase = protocol_version >= 29 ? 2 : 1;
4993 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4994 +#ifdef SUPPORT_ACLS
4995 + char *parent_dirname = "";
5000 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
5001 * mode based on the local permissions and some heuristics. */
5002 if (!preserve_perms) {
5003 int exists = fd1 != -1;
5004 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5005 +#ifdef SUPPORT_ACLS
5006 + char *dn = file->dirname ? file->dirname : ".";
5007 + if (parent_dirname != dn
5008 + && strcmp(parent_dirname, dn) != 0) {
5009 + dflt_perms = default_perms_for_dir(dn);
5010 + parent_dirname = dn;
5013 + file->mode = dest_mode(file->mode, st.st_mode,
5014 + dflt_perms, exists);
5017 /* We now check to see if we are writing file "inplace" */
5023 extern int daemon_log_format_has_i;
5024 +extern int preserve_acls;
5025 extern int preserve_perms;
5026 extern int preserve_executability;
5027 extern int preserve_times;
5028 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5030 /* This is only called when we aren't preserving permissions. Figure out what
5031 * the permissions should be and return them merged back into the mode. */
5032 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5033 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5036 /* If the file already exists, we'll return the local permissions,
5037 * possibly tweaked by the --executability option. */
5038 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
5039 cur_mode |= (cur_mode & 0444) >> 2;
5042 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5043 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5044 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5045 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5046 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5047 @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
5051 +#ifdef SUPPORT_ACLS
5052 + /* It's OK to call set_acl() now, even for a dir, as the generator
5053 + * will enable owner-writability using chmod, if necessary.
5055 + * If set_acl changes permission bits in the process of setting
5056 + * an access ACL, it changes st->st_mode so we know whether we
5057 + * need to chmod. */
5058 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5063 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5064 - int ret = do_chmod(fname, file->mode);
5065 + mode_t mode = file->mode;
5066 + int ret = do_chmod(fname, mode);
5068 rsyserr(FERROR, errno,
5069 "failed to set permissions on %s",
5072 @@ -660,6 +660,20 @@ struct chmod_mode_struct;
5074 #define UNUSED(x) x __attribute__((__unused__))
5076 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5077 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5078 +#define SUPPORT_ACLS 1
5081 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5082 +#define ACLS_NEED_MASK 1
5085 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5086 +#include <sys/acl.h>
5088 +#include "smb_acls.h"
5092 /* We have replacement versions of these if they're missing. */
5095 @@ -321,6 +321,7 @@ to the detailed description below for a
5096 -H, --hard-links preserve hard links
5097 -p, --perms preserve permissions
5098 -E, --executability preserve executability
5099 + -A, --acls preserve ACLs (implies -p) [non-standard]
5100 --chmod=CHMOD change destination permissions
5101 -o, --owner preserve owner (super-user only)
5102 -g, --group preserve group
5103 @@ -742,7 +743,9 @@ quote(itemize(
5104 permissions, though the bf(--executability) option might change just
5105 the execute permission for the file.
5106 it() New files get their "normal" permission bits set to the source
5107 - file's permissions masked with the receiving end's umask setting, and
5108 + file's permissions masked with the receiving directory's default
5109 + permissions (either the receiving process's umask, or the permissions
5110 + specified via the destination directory's default ACL), and
5111 their special permission bits disabled except in the case where a new
5112 directory inherits a setgid bit from its parent directory.
5114 @@ -773,9 +776,11 @@ The preservation of the destination's se
5115 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5116 versions erroneously preserved the three special permission bits for
5117 newly-created files when bf(--perms) was off, while overriding the
5118 -destination's setgid bit setting on a newly-created directory. (Keep in
5119 -mind that it is the version of the receiving rsync that affects this
5121 +destination's setgid bit setting on a newly-created directory. Default ACL
5122 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5123 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5124 +(Keep in mind that it is the version of the receiving rsync that affects
5127 dit(bf(-E, --executability)) This option causes rsync to preserve the
5128 executability (or non-executability) of regular files when bf(--perms) is
5129 @@ -793,6 +798,15 @@ quote(itemize(
5131 If bf(--perms) is enabled, this option is ignored.
5133 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5134 +ACLs to be the same as the source ACLs. This nonstandard option only
5135 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5137 +Note also that an optimization of the ACL-sending protocol used by this
5138 +version makes it incompatible with sending files to an older ACL-enabled
5139 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5140 +doubling is not needed when pulling files from an older rsync.
5142 dit(bf(--chmod)) This option tells rsync to apply one or more
5143 comma-separated "chmod" strings to the permission of the files in the
5144 transfer. The resulting value is treated as though it was the permissions
5149 + Unix SMB/Netbios implementation.
5151 + Portable SMB ACL interface
5152 + Copyright (C) Jeremy Allison 2000
5154 + This program is free software; you can redistribute it and/or modify
5155 + it under the terms of the GNU General Public License as published by
5156 + the Free Software Foundation; either version 2 of the License, or
5157 + (at your option) any later version.
5159 + This program is distributed in the hope that it will be useful,
5160 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5161 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5162 + GNU General Public License for more details.
5164 + You should have received a copy of the GNU General Public License
5165 + along with this program; if not, write to the Free Software
5166 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5169 +#ifndef _SMB_ACLS_H
5170 +#define _SMB_ACLS_H
5172 +#if defined HAVE_POSIX_ACLS
5174 +/* This is an identity mapping (just remove the SMB_). */
5176 +#define SMB_ACL_TAG_T acl_tag_t
5177 +#define SMB_ACL_TYPE_T acl_type_t
5178 +#define SMB_ACL_PERMSET_T acl_permset_t
5179 +#define SMB_ACL_PERM_T acl_perm_t
5180 +#define SMB_ACL_READ ACL_READ
5181 +#define SMB_ACL_WRITE ACL_WRITE
5182 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5184 +/* Types of ACLs. */
5185 +#define SMB_ACL_USER ACL_USER
5186 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5187 +#define SMB_ACL_GROUP ACL_GROUP
5188 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5189 +#define SMB_ACL_OTHER ACL_OTHER
5190 +#define SMB_ACL_MASK ACL_MASK
5192 +#define SMB_ACL_T acl_t
5194 +#define SMB_ACL_ENTRY_T acl_entry_t
5196 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5197 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5199 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5200 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5202 +#elif defined HAVE_TRU64_ACLS
5204 +/* This is for DEC/Compaq Tru64 UNIX */
5206 +#define SMB_ACL_TAG_T acl_tag_t
5207 +#define SMB_ACL_TYPE_T acl_type_t
5208 +#define SMB_ACL_PERMSET_T acl_permset_t
5209 +#define SMB_ACL_PERM_T acl_perm_t
5210 +#define SMB_ACL_READ ACL_READ
5211 +#define SMB_ACL_WRITE ACL_WRITE
5212 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5214 +/* Types of ACLs. */
5215 +#define SMB_ACL_USER ACL_USER
5216 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5217 +#define SMB_ACL_GROUP ACL_GROUP
5218 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5219 +#define SMB_ACL_OTHER ACL_OTHER
5220 +#define SMB_ACL_MASK ACL_MASK
5222 +#define SMB_ACL_T acl_t
5224 +#define SMB_ACL_ENTRY_T acl_entry_t
5226 +#define SMB_ACL_FIRST_ENTRY 0
5227 +#define SMB_ACL_NEXT_ENTRY 1
5229 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5230 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5232 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5234 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5235 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5238 +/* SVR4.2 ES/MP ACLs */
5239 +typedef int SMB_ACL_TAG_T;
5240 +typedef int SMB_ACL_TYPE_T;
5241 +typedef ushort *SMB_ACL_PERMSET_T;
5242 +typedef ushort SMB_ACL_PERM_T;
5243 +#define SMB_ACL_READ 4
5244 +#define SMB_ACL_WRITE 2
5245 +#define SMB_ACL_EXECUTE 1
5247 +/* Types of ACLs. */
5248 +#define SMB_ACL_USER USER
5249 +#define SMB_ACL_USER_OBJ USER_OBJ
5250 +#define SMB_ACL_GROUP GROUP
5251 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5252 +#define SMB_ACL_OTHER OTHER_OBJ
5253 +#define SMB_ACL_MASK CLASS_OBJ
5255 +typedef struct SMB_ACL_T {
5259 + struct acl acl[1];
5262 +typedef struct acl *SMB_ACL_ENTRY_T;
5264 +#define SMB_ACL_FIRST_ENTRY 0
5265 +#define SMB_ACL_NEXT_ENTRY 1
5267 +#define SMB_ACL_TYPE_ACCESS 0
5268 +#define SMB_ACL_TYPE_DEFAULT 1
5271 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5274 +#elif defined HAVE_HPUX_ACLS
5277 + * Based on the Solaris & UnixWare code.
5281 +#include <sys/aclv.h>
5283 +/* SVR4.2 ES/MP ACLs */
5284 +typedef int SMB_ACL_TAG_T;
5285 +typedef int SMB_ACL_TYPE_T;
5286 +typedef ushort *SMB_ACL_PERMSET_T;
5287 +typedef ushort SMB_ACL_PERM_T;
5288 +#define SMB_ACL_READ 4
5289 +#define SMB_ACL_WRITE 2
5290 +#define SMB_ACL_EXECUTE 1
5292 +/* Types of ACLs. */
5293 +#define SMB_ACL_USER USER
5294 +#define SMB_ACL_USER_OBJ USER_OBJ
5295 +#define SMB_ACL_GROUP GROUP
5296 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5297 +#define SMB_ACL_OTHER OTHER_OBJ
5298 +#define SMB_ACL_MASK CLASS_OBJ
5300 +typedef struct SMB_ACL_T {
5304 + struct acl acl[1];
5307 +typedef struct acl *SMB_ACL_ENTRY_T;
5309 +#define SMB_ACL_FIRST_ENTRY 0
5310 +#define SMB_ACL_NEXT_ENTRY 1
5312 +#define SMB_ACL_TYPE_ACCESS 0
5313 +#define SMB_ACL_TYPE_DEFAULT 1
5315 +#elif defined HAVE_IRIX_ACLS
5317 +#define SMB_ACL_TAG_T acl_tag_t
5318 +#define SMB_ACL_TYPE_T acl_type_t
5319 +#define SMB_ACL_PERMSET_T acl_permset_t
5320 +#define SMB_ACL_PERM_T acl_perm_t
5321 +#define SMB_ACL_READ ACL_READ
5322 +#define SMB_ACL_WRITE ACL_WRITE
5323 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5325 +/* Types of ACLs. */
5326 +#define SMB_ACL_USER ACL_USER
5327 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5328 +#define SMB_ACL_GROUP ACL_GROUP
5329 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5330 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5331 +#define SMB_ACL_MASK ACL_MASK
5333 +typedef struct SMB_ACL_T {
5339 +#define SMB_ACL_ENTRY_T acl_entry_t
5341 +#define SMB_ACL_FIRST_ENTRY 0
5342 +#define SMB_ACL_NEXT_ENTRY 1
5344 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5345 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5347 +#elif defined HAVE_AIX_ACLS
5349 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5351 +#include "/usr/include/acl.h"
5353 +typedef uint *SMB_ACL_PERMSET_T;
5355 +struct acl_entry_link{
5356 + struct acl_entry_link *prevp;
5357 + struct new_acl_entry *entryp;
5358 + struct acl_entry_link *nextp;
5362 +struct new_acl_entry{
5363 + unsigned short ace_len;
5364 + unsigned short ace_type;
5365 + unsigned int ace_access;
5366 + struct ace_id ace_id[1];
5369 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5370 +#define SMB_ACL_T struct acl_entry_link*
5372 +#define SMB_ACL_TAG_T unsigned short
5373 +#define SMB_ACL_TYPE_T int
5374 +#define SMB_ACL_PERM_T uint
5375 +#define SMB_ACL_READ S_IRUSR
5376 +#define SMB_ACL_WRITE S_IWUSR
5377 +#define SMB_ACL_EXECUTE S_IXUSR
5379 +/* Types of ACLs. */
5380 +#define SMB_ACL_USER ACEID_USER
5381 +#define SMB_ACL_USER_OBJ 3
5382 +#define SMB_ACL_GROUP ACEID_GROUP
5383 +#define SMB_ACL_GROUP_OBJ 4
5384 +#define SMB_ACL_OTHER 5
5385 +#define SMB_ACL_MASK 6
5388 +#define SMB_ACL_FIRST_ENTRY 1
5389 +#define SMB_ACL_NEXT_ENTRY 2
5391 +#define SMB_ACL_TYPE_ACCESS 0
5392 +#define SMB_ACL_TYPE_DEFAULT 1
5394 +#else /* No ACLs. */
5396 +/* No ACLS - fake it. */
5397 +#define SMB_ACL_TAG_T int
5398 +#define SMB_ACL_TYPE_T int
5399 +#define SMB_ACL_PERMSET_T mode_t
5400 +#define SMB_ACL_PERM_T mode_t
5401 +#define SMB_ACL_READ S_IRUSR
5402 +#define SMB_ACL_WRITE S_IWUSR
5403 +#define SMB_ACL_EXECUTE S_IXUSR
5405 +/* Types of ACLs. */
5406 +#define SMB_ACL_USER 0
5407 +#define SMB_ACL_USER_OBJ 1
5408 +#define SMB_ACL_GROUP 2
5409 +#define SMB_ACL_GROUP_OBJ 3
5410 +#define SMB_ACL_OTHER 4
5411 +#define SMB_ACL_MASK 5
5413 +typedef struct SMB_ACL_T {
5417 +typedef struct SMB_ACL_ENTRY_T {
5419 +} *SMB_ACL_ENTRY_T;
5421 +#define SMB_ACL_FIRST_ENTRY 0
5422 +#define SMB_ACL_NEXT_ENTRY 1
5424 +#define SMB_ACL_TYPE_ACCESS 0
5425 +#define SMB_ACL_TYPE_DEFAULT 1
5427 +#endif /* No ACLs. */
5428 +#endif /* _SMB_ACLS_H */
5429 --- old/testsuite/default-acls.test
5430 +++ new/testsuite/default-acls.test
5434 +# This program is distributable under the terms of the GNU GPL see
5437 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5439 +. $srcdir/testsuite/rsync.fns
5441 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5442 +case "$setfacl_nodef" in
5443 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5444 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5446 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5448 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5450 + todir="$scratchdir/$1"
5452 + $setfacl_nodef "$todir"
5454 + case "$setfacl_nodef" in
5455 + *-k*) opts="-dm $2" ;;
5456 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5458 + setfacl $opts "$todir"
5460 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5461 + # even though the directory itself is outside the transfer
5462 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5463 + check_perms "$todir/to" $4 "Target $1"
5464 + check_perms "$todir/to/dir" $4 "Target $1"
5465 + check_perms "$todir/to/file" $3 "Target $1"
5466 + check_perms "$todir/to/program" $4 "Target $1"
5467 + # Make sure get_local_name doesn't mess us up when transferring only one file
5468 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5469 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5470 + # Make sure we obey default ACLs when not transferring a regular file
5471 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5472 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5475 +mkdir "$scratchdir/dir"
5476 +echo "File!" >"$scratchdir/file"
5477 +echo "#!/bin/sh" >"$scratchdir/program"
5478 +chmod 777 "$scratchdir/dir"
5479 +chmod 666 "$scratchdir/file"
5480 +chmod 777 "$scratchdir/program"
5482 +# Test some target directories
5484 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5485 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5486 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5487 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5488 +testit noda1 '' rw------- rwx------
5490 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5492 +testit noda3 '' rw-r--r-- rwxr-xr-x
5500 extern int preserve_uid;
5501 extern int preserve_gid;
5502 +extern int preserve_acls;
5503 extern int numeric_ids;
5506 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5510 - if (preserve_uid) {
5511 + if (preserve_uid || preserve_acls) {
5513 /* we send sequences of uid/byte-length/name */
5514 for (list = uidlist; list; list = list->next) {
5515 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5519 - if (preserve_gid) {
5520 + if (preserve_gid || preserve_acls) {
5522 for (list = gidlist; list; list = list->next) {
5524 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5528 - if (preserve_uid && !numeric_ids) {
5529 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5530 /* read the uid list */
5531 while ((id = read_int(f)) != 0) {
5532 int len = read_byte(f);
5533 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5537 - if (preserve_gid && !numeric_ids) {
5538 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5539 /* read the gid list */
5540 while ((id = read_int(f)) != 0) {
5541 int len = read_byte(f);
5542 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5546 +#ifdef SUPPORT_ACLS
5547 + if (preserve_acls && !numeric_ids) {
5549 + while ((id = next_acl_uid(flist)) != NULL)
5550 + *id = match_uid(*id);
5551 + while ((id = next_acl_gid(flist)) != NULL)
5552 + *id = match_gid(*id);
5556 /* Now convert all the uids/gids from sender values to our values. */
5557 if (am_root && preserve_uid && !numeric_ids) {
5558 for (i = 0; i < flist->count; i++)