1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
9 @@ -25,15 +25,15 @@ VERSION=@VERSION@
13 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
14 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
15 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
16 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
17 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
18 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
19 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
20 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
21 main.o checksum.o match.o syscall.o log.o backup.o
22 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
23 - fileio.o batch.o clientname.o chmod.o
24 + fileio.o batch.o clientname.o chmod.o acls.o
25 OBJS3=progress.o pipe.o
26 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
27 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
31 +/* -*- c-file-style: "linux" -*-
32 + Copyright (C) Andrew Tridgell 1996
33 + Copyright (C) Paul Mackerras 1996
35 + This program is free software; you can redistribute it and/or modify
36 + it under the terms of the GNU General Public License as published by
37 + the Free Software Foundation; either version 2 of the License, or
38 + (at your option) any later version.
40 + This program is distributed in the hope that it will be useful,
41 + but WITHOUT ANY WARRANTY; without even the implied warranty of
42 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 + GNU General Public License for more details.
45 + You should have received a copy of the GNU General Public License
46 + along with this program; if not, write to the Free Software
47 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50 +/* handle passing ACLs between systems */
53 +#include "lib/sysacls.h"
59 +extern int orig_umask;
64 + SMB_ACL_TAG_T tag_type;
73 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
75 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
76 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
78 +static void expand_rsync_acl(rsync_acl *racl)
80 + /* First time through, 0 <= 0, so list is expanded. */
81 + if (racl->malloced <= racl->count) {
83 + size_t new_size = racl->malloced + 10;
84 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
86 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
87 + (double) new_size * sizeof racl->races[0],
88 + racl->races ? "" : " not");
91 + racl->races = new_ptr;
92 + racl->malloced = new_size;
95 + out_of_memory("expand_rsync_acl");
99 +static void rsync_acl_free(rsync_acl *racl)
102 + racl->races = NULL;
104 + racl->malloced = 0;
107 +static int rsync_ace_sorter(const void *r1, const void *r2)
109 + rsync_ace *race1 = (rsync_ace *)r1;
110 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
111 + id_t rid1 = race1->id;
112 + rsync_ace *race2 = (rsync_ace *)r2;
113 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
114 + id_t rid2 = race2->id;
115 + /* start at the extrema */
116 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
118 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
121 + if (rtag1 == SMB_ACL_OTHER)
123 + if (rtag2 == SMB_ACL_OTHER)
125 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
126 + if (rtag1 == SMB_ACL_USER) {
128 + case SMB_ACL_GROUP:
129 + case SMB_ACL_GROUP_OBJ:
130 + case SMB_ACL_OTHER:
134 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
136 + if (rtag2 == SMB_ACL_USER)
138 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
139 + if (rtag1 == SMB_ACL_GROUP_OBJ)
141 + if (rtag2 == SMB_ACL_GROUP_OBJ)
143 + /* only SMB_ACL_GROUPs left */
144 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
147 +static void sort_rsync_acl(rsync_acl *racl)
151 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
152 + &rsync_ace_sorter);
155 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
157 + SMB_ACL_ENTRY_T entry;
159 + const char *errfun;
160 + *racl = rsync_acl_initializer;
161 + errfun = "sys_acl_get_entry";
162 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
164 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
165 + SMB_ACL_PERMSET_T permset;
168 + expand_rsync_acl(racl);
169 + race = &racl->races[racl->count++];
170 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
171 + errfun = "sys_acl_get_tag_type";
174 + if ((rc = sys_acl_get_permset(entry, &permset))) {
175 + errfun = "sys_acl_get_tag_type";
178 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
179 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
180 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
181 + switch (race->tag_type) {
183 + case SMB_ACL_GROUP:
188 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
189 + errfun = "sys_acl_get_tag_type";
193 + race->id = *((id_t *)qualifier);
194 + sys_acl_free_qualifier(qualifier, race->tag_type);
197 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
198 + errfun, strerror(errno));
199 + rsync_acl_free(racl);
202 + sort_rsync_acl(racl);
206 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
208 + rsync_ace *race1, *race2;
209 + size_t count = racl1->count;
210 + if (count != racl2->count)
212 + race1 = racl1->races;
213 + race2 = racl2->races;
214 + for (; count--; race1++, race2++) {
215 + if (race1->tag_type != race2->tag_type
216 + || race1->access != race2->access
217 + || ((race1->tag_type == SMB_ACL_USER
218 + || race1->tag_type == SMB_ACL_GROUP)
219 + && race1->id != race2->id))
231 +static rsync_acl_list _rsync_acl_lists[] = {
232 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
233 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
236 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
238 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
239 + : &_rsync_acl_lists[1];
242 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
244 + /* First time through, 0 <= 0, so list is expanded. */
245 + if (racl_list->malloced <= racl_list->count) {
246 + rsync_acl *new_ptr;
248 + if (racl_list->malloced < 1000)
249 + new_size = racl_list->malloced + 1000;
251 + new_size = racl_list->malloced * 2;
252 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
253 + if (verbose >= 3) {
254 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
255 + (double) new_size * sizeof racl_list->racls[0],
256 + racl_list->racls ? "" : " not");
259 + racl_list->racls = new_ptr;
260 + racl_list->malloced = new_size;
262 + if (!racl_list->racls)
263 + out_of_memory("expand_rsync_acl_list");
268 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
270 + /* Run this in reverse, so references are freed before referents,
271 + * although not currently necessary. */
272 + while (racl_list->count--) {
273 + rsync_acl *racl = &racl_list->racls[racl_list->count];
275 + rsync_acl_free(racl);
277 + free(racl_list->racls);
278 + racl_list->racls = NULL;
279 + racl_list->malloced = 0;
283 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
284 + const rsync_acl_list *racl_list,
285 + const rsync_acl *racl)
287 + static int access_match = -1, default_match = -1;
288 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
289 + &access_match : &default_match;
290 + size_t count = racl_list->count;
291 + /* If this is the first time through or we didn't match the last
292 + * time, then start at the end of the list, which should be the
293 + * best place to start hunting. */
295 + *match = racl_list->count - 1;
297 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
300 + *match = racl_list->count - 1;
306 +/* The general strategy with the tag_type <-> character mapping is that
307 + * lowercase implies that no qualifier follows, where uppercase does.
308 + * A similar idiom for the acl type (access or default) itself, but
309 + * lowercase in this instance means there's no ACL following, so the
310 + * ACL is a repeat, so the receiver should reuse the last of the same
313 +static void send_rsync_acl(int f, const rsync_acl *racl)
316 + size_t count = racl->count;
317 + write_int(f, count);
318 + for (race = racl->races; count--; race++) {
320 + switch (race->tag_type) {
321 + case SMB_ACL_USER_OBJ:
327 + case SMB_ACL_GROUP_OBJ:
330 + case SMB_ACL_GROUP:
333 + case SMB_ACL_OTHER:
341 + "send_rsync_acl: unknown tag_type (%02x) on ACE; disregarding\n",
346 + write_byte(f, race->access);
348 + write_int(f, race->id);
349 + /* FIXME: sorta wasteful: we should maybe buffer as
350 + * many ids as max(ACL_USER + ACL_GROUP) objects to
351 + * keep from making so many calls. */
360 +static rsync_acl _curr_rsync_acls[2];
363 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
365 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
366 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
367 + "unknown SMB_ACL_TYPE_T";
371 + * Overwrite racl with a new three-entry ACL from the given permissions.
373 +static void perms_to_acl(int perms, rsync_acl *racl)
376 + expand_rsync_acl(racl);
377 + racl->races[racl->count].tag_type = SMB_ACL_USER_OBJ;
378 + racl->races[racl->count++].access = (perms >> 6) & 7;
379 + expand_rsync_acl(racl);
380 + racl->races[racl->count].tag_type = SMB_ACL_GROUP_OBJ;
381 + racl->races[racl->count++].access = (perms >> 3) & 7;
382 + expand_rsync_acl(racl);
383 + racl->races[racl->count].tag_type = SMB_ACL_OTHER;
384 + racl->races[racl->count++].access = (perms >> 0) & 7;
387 +/* Generate the ACL(s) for this flist entry;
388 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
390 +int make_acl(const struct file_struct *file, const char *fname)
392 + SMB_ACL_TYPE_T type;
393 + rsync_acl *curr_racl;
395 + if (S_ISLNK(file->mode))
398 + curr_racl = &_curr_rsync_acls[0];
399 + type = SMB_ACL_TYPE_ACCESS;
403 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
404 + ok = unpack_smb_acl(curr_racl, sacl);
405 + sys_acl_free_acl(sacl);
408 + } else if (errno == ENOTSUP) {
409 + /* ACLs are not supported. Invent an access ACL from
410 + * permissions; let the default ACL default to empty. */
411 + *curr_racl = rsync_acl_initializer;
412 + if (type == SMB_ACL_TYPE_ACCESS)
413 + perms_to_acl(file->mode & ACCESSPERMS, curr_racl);
415 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
416 + fname, str_acl_type(type), strerror(errno));
420 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
425 +/* Send the make_acl()-generated ACLs for this flist entry,
426 + * or clean up after an flist entry that's not being sent (f == -1). */
428 +void send_acl(const struct file_struct *file, int f)
430 + SMB_ACL_TYPE_T type;
431 + rsync_acl *curr_racl;
433 + if (S_ISLNK(file->mode))
436 + curr_racl = &_curr_rsync_acls[0];
437 + type = SMB_ACL_TYPE_ACCESS;
440 + rsync_acl_list *racl_list = rsync_acl_lists(type);
442 + rsync_acl_free(curr_racl);
445 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
447 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
448 + write_int(f, index);
449 + rsync_acl_free(curr_racl);
451 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
452 + send_rsync_acl(f, curr_racl);
453 + expand_rsync_acl_list(racl_list);
454 + racl_list->racls[racl_list->count++] = *curr_racl;
457 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
460 +/* The below stuff is only used by the receiver: */
462 +/* structure to hold index to rsync_acl_list member corresponding to
463 + * flist->files[i] */
466 + const struct file_struct *file;
473 + file_acl_index *fileaclidxs;
474 +} file_acl_index_list;
476 +static file_acl_index_list _file_acl_index_lists[] = {
477 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
478 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
481 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
483 + return type == SMB_ACL_TYPE_ACCESS ?
484 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
487 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
489 + /* First time through, 0 <= 0, so list is expanded. */
490 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
491 + file_acl_index *new_ptr;
493 + if (fileaclidx_list->malloced < 1000)
494 + new_size = fileaclidx_list->malloced + 1000;
496 + new_size = fileaclidx_list->malloced * 2;
497 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
498 + if (verbose >= 3) {
499 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
500 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
501 + fileaclidx_list->fileaclidxs ? "" : " not");
504 + fileaclidx_list->fileaclidxs = new_ptr;
505 + fileaclidx_list->malloced = new_size;
507 + if (!fileaclidx_list->fileaclidxs)
508 + out_of_memory("expand_file_acl_index_list");
513 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
515 + free(fileaclidx_list->fileaclidxs);
516 + fileaclidx_list->fileaclidxs = NULL;
517 + fileaclidx_list->malloced = 0;
521 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
529 +static smb_acl_list _smb_acl_lists[] = {
530 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
531 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
534 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
536 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
537 + &_smb_acl_lists[1];
540 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
542 + /* First time through, 0 <= 0, so list is expanded. */
543 + if (sacl_list->malloced <= sacl_list->count) {
544 + SMB_ACL_T *new_ptr;
546 + if (sacl_list->malloced < 1000)
547 + new_size = sacl_list->malloced + 1000;
549 + new_size = sacl_list->malloced * 2;
550 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
551 + if (verbose >= 3) {
552 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
553 + (double) new_size * sizeof sacl_list->sacls[0],
554 + sacl_list->sacls ? "" : " not");
557 + sacl_list->sacls = new_ptr;
558 + sacl_list->malloced = new_size;
560 + if (!sacl_list->sacls)
561 + out_of_memory("expand_smb_acl_list");
566 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
568 + smb_acl_list *sacl_list = smb_acl_lists(type);
569 + SMB_ACL_T *sacl = sacl_list->sacls;
570 + while (sacl_list->count--) {
572 + sys_acl_free_acl(*sacl++);
574 + free(sacl_list->sacls);
575 + sacl_list->sacls = NULL;
576 + sacl_list->malloced = 0;
580 +/* build an SMB_ACL_T corresponding to an rsync_acl */
581 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl, int perms)
583 + size_t count = racl->count;
584 + rsync_ace *race = racl->races;
585 + const char *errfun = NULL;
588 + *smb_acl = sys_acl_init(count);
590 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
595 + for (; count--; race++) {
596 + SMB_ACL_ENTRY_T entry;
597 + SMB_ACL_PERMSET_T permset;
598 + if (sys_acl_create_entry(smb_acl, &entry)) {
599 + errfun = "sys_acl_create)";
602 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
603 + errfun = "sys_acl_set_tag";
606 + if (race->tag_type == SMB_ACL_USER ||
607 + race->tag_type == SMB_ACL_GROUP) {
608 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
609 + errfun = "sys_acl_set_qualfier";
613 + if (sys_acl_get_permset(entry, &permset)) {
614 + errfun = "sys_acl_get_permset";
617 + if (sys_acl_clear_perms(permset)) {
618 + errfun = "sys_acl_clear_perms";
621 + switch (perms >= 0 ? race->tag_type : SMB_ACL_USER_OBJ) {
622 + case SMB_ACL_GROUP_OBJ:
623 + bits = racl->count > 3 ? race->access : (perms >> 3) & 7;
626 + bits = (perms >> 3) & 7;
628 + case SMB_ACL_OTHER:
632 + bits = race->access;
636 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
637 + errfun = "sys_acl_add_perm";
642 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
643 + errfun = "sys_acl_add_perm";
648 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
649 + errfun = "sys_acl_add_perm";
653 + if (sys_acl_set_permset(entry, permset)) {
654 + errfun = "sys_acl_set_permset";
659 + sys_acl_free_acl(*smb_acl);
660 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
667 +static void receive_rsync_acl(rsync_acl *racl, mode_t mode, int f)
669 + rsync_ace *user = NULL, *group = NULL, *other = NULL, *mask = NULL;
671 + BOOL need_sort = 0;
674 + if (!(count = read_int(f)))
678 + uchar tag = read_byte(f);
679 + expand_rsync_acl(racl);
680 + race = &racl->races[racl->count++];
683 + race->tag_type = SMB_ACL_USER_OBJ;
687 + race->tag_type = SMB_ACL_USER;
690 + race->tag_type = SMB_ACL_GROUP_OBJ;
694 + race->tag_type = SMB_ACL_GROUP;
697 + race->tag_type = SMB_ACL_OTHER;
701 + race->tag_type = SMB_ACL_MASK;
705 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
707 + exit_cleanup(RERR_STREAMIO);
709 + race->access = read_byte(f);
710 + if (race->access & ~ (4 | 2 | 1)) {
711 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
713 + exit_cleanup(RERR_STREAMIO);
715 + if (race->tag_type == SMB_ACL_USER ||
716 + race->tag_type == SMB_ACL_GROUP) {
717 + race->id = read_int(f);
721 + expand_rsync_acl(racl);
722 + user = &racl->races[racl->count++];
723 + user->tag_type = SMB_ACL_USER_OBJ;
724 + user->access = (mode >> 6) & 7;
728 + expand_rsync_acl(racl);
729 + group = &racl->races[racl->count++];
730 + group->tag_type = SMB_ACL_GROUP_OBJ;
731 + group->access = (mode >> 3) & 7;
735 + expand_rsync_acl(racl);
736 + other = &racl->races[racl->count++];
737 + other->tag_type = SMB_ACL_OTHER;
738 + other->access = mode & 7;
743 + expand_rsync_acl(racl);
744 + mask = &racl->races[racl->count++];
745 + mask->tag_type = SMB_ACL_MASK;
746 + mask->access = (mode >> 3) & 7;
750 + /* If we, a system without ACLS_NEED_MASK, received data from a
751 + * system that has masks, throw away the extraneous CLASS_OBJs. */
752 + if (mask && racl->count == 4) {
753 + /* mask off group perms with it first */
754 + group->access &= mask->access;
755 + /* dump mask; re-slot any followers-on */
757 + if (mask != &racl->races[racl->count]) {
758 + *mask = racl->races[racl->count];
764 + sort_rsync_acl(racl);
767 +/* receive and build the rsync_acl_lists */
769 +void receive_acl(struct file_struct *file, int f)
771 + SMB_ACL_TYPE_T type;
774 + if (S_ISLNK(file->mode))
777 + fname = f_name(file, NULL);
778 + type = SMB_ACL_TYPE_ACCESS;
780 + file_acl_index_list *fileaclidx_list =
781 + file_acl_index_lists(type);
783 + expand_file_acl_index_list(fileaclidx_list);
785 + tag = read_byte(f);
786 + if (tag == 'A' || tag == 'a') {
787 + if (type != SMB_ACL_TYPE_ACCESS) {
788 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
790 + exit_cleanup(RERR_STREAMIO);
792 + } else if (tag == 'D' || tag == 'd') {
793 + if (type == SMB_ACL_TYPE_ACCESS) {
794 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
796 + exit_cleanup(RERR_STREAMIO);
799 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
801 + exit_cleanup(RERR_STREAMIO);
803 + if (tag == 'A' || tag == 'D') {
804 + rsync_acl racl = rsync_acl_initializer;
805 + rsync_acl_list *racl_list = rsync_acl_lists(type);
806 + smb_acl_list *sacl_list = smb_acl_lists(type);
807 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
808 + aclidx = racl_list->count;
809 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
811 + receive_rsync_acl(&racl, file->mode, f);
812 + expand_rsync_acl_list(racl_list);
813 + racl_list->racls[racl_list->count++] = racl;
814 + expand_smb_acl_list(sacl_list);
815 + sacl_list->sacls[sacl_list->count++] = NULL;
817 + int index = read_int(f);
818 + rsync_acl_list *racl_list = rsync_acl_lists(type);
819 + if ((size_t) index >= racl_list->count) {
820 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
822 + str_acl_type(type),
824 + exit_cleanup(RERR_STREAMIO);
826 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
828 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
831 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
834 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
836 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
837 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
838 + return fileaclidx1->file == fileaclidx2->file ? 0 :
839 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
842 +void sort_file_acl_index_lists()
844 + SMB_ACL_TYPE_T type;
846 + type = SMB_ACL_TYPE_ACCESS;
848 + file_acl_index_list *fileaclidx_list =
849 + file_acl_index_lists(type);
850 + if (!fileaclidx_list->count)
852 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
853 + sizeof fileaclidx_list->fileaclidxs[0],
854 + &file_acl_index_list_sorter);
855 + } while (BUMP_TYPE(type));
858 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
859 + const struct file_struct *file) {
860 + int low = 0, high = fileaclidx_list->count;
861 + const struct file_struct *file_mid;
865 + int mid = (high + low) / 2;
866 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
867 + if (file_mid == file)
868 + return fileaclidx_list->fileaclidxs[mid].aclidx;
869 + if (file_mid > file)
873 + } while (low < high);
875 + file_mid = fileaclidx_list->fileaclidxs[low].file;
876 + if (file_mid == file)
877 + return fileaclidx_list->fileaclidxs[low].aclidx;
880 + "find_file_acl_index: can't find entry for file in list\n");
881 + exit_cleanup(RERR_STREAMIO);
885 +/* for duplicating ACLs on backups when using backup_dir */
887 +int dup_acl(const char *orig, const char *bak, mode_t mode)
889 + SMB_ACL_TYPE_T type;
892 + type = SMB_ACL_TYPE_ACCESS;
894 + SMB_ACL_T sacl_orig, sacl_bak;
895 + rsync_acl racl_orig, racl_bak;
896 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
897 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
898 + orig, str_acl_type(type), strerror(errno));
902 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
903 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
904 + bak, str_acl_type(type), strerror(errno));
906 + /* try to forge on through */
908 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
910 + goto out_with_sacls;
913 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
915 + goto out_with_one_racl;
917 + if (rsync_acls_equal(&racl_orig, &racl_bak))
920 + ; /* presume they're unequal */
922 + if (type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
923 + if (sys_acl_delete_def_file(bak) < 0) {
924 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
925 + bak, strerror(errno));
928 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
929 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
930 + bak, str_acl_type(type), strerror(errno));
935 + rsync_acl_free(&racl_bak);
937 + rsync_acl_free(&racl_orig);
940 + sys_acl_free_acl(sacl_bak);
941 + /* out_with_one_sacl: */
943 + sys_acl_free_acl(sacl_orig);
944 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
949 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
950 + * for keep_backup(). */
951 +static const struct file_struct *backup_orig_file = NULL;
952 +static const char null_string[] = "";
953 +static const char *backup_orig_fname = null_string;
954 +static const char *backup_dest_fname = null_string;
955 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
957 +void push_keep_backup_acl(const struct file_struct *file,
958 + const char *orig, const char *dest)
960 + SMB_ACL_TYPE_T type;
963 + backup_orig_file = file;
964 + backup_orig_fname = orig;
965 + backup_dest_fname = dest;
967 + sacl = &_backup_sacl[0];
968 + type = SMB_ACL_TYPE_ACCESS;
970 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
974 + if (!(*sacl = sys_acl_get_file(orig, type))) {
976 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
977 + orig, str_acl_type(type),
980 + } while (BUMP_TYPE(type));
983 +static int set_keep_backup_acl()
985 + SMB_ACL_TYPE_T type;
989 + sacl = &_backup_sacl[0];
990 + type = SMB_ACL_TYPE_ACCESS;
993 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
995 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
997 + str_acl_type(type),
1001 + } while (BUMP_TYPE(type));
1006 +void cleanup_keep_backup_acl()
1008 + SMB_ACL_TYPE_T type;
1011 + backup_orig_file = NULL;
1012 + backup_orig_fname = null_string;
1013 + backup_dest_fname = null_string;
1015 + sacl = &_backup_sacl[0];
1016 + type = SMB_ACL_TYPE_ACCESS;
1019 + sys_acl_free_acl(*sacl);
1022 + } while (BUMP_TYPE(type));
1025 +/* set ACL on rsync-ed or keep_backup-ed file */
1027 +int set_acl(const char *fname, const struct file_struct *file, mode_t old_mode)
1029 + int unchanged = 1;
1030 + SMB_ACL_TYPE_T type;
1032 + if (dry_run || S_ISLNK(file->mode))
1033 + return 1; /* FIXME: --dry-run needs to compute this value */
1035 + if (file == backup_orig_file) {
1036 + if (!strcmp(fname, backup_dest_fname))
1037 + return set_keep_backup_acl();
1039 + type = SMB_ACL_TYPE_ACCESS;
1041 + SMB_ACL_T sacl_orig, *sacl_new;
1042 + rsync_acl racl_orig, *racl_new;
1043 + int aclidx = find_file_acl_index(file_acl_index_lists(type),
1046 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1047 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1048 + sacl_orig = sys_acl_get_file(fname, type);
1050 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1051 + fname, str_acl_type(type), strerror(errno));
1055 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1056 + sys_acl_free_acl(sacl_orig);
1061 + ok = rsync_acls_equal(&racl_orig, racl_new);
1062 + rsync_acl_free(&racl_orig);
1065 + if (type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1066 + if (sys_acl_delete_def_file(fname) < 0) {
1067 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1068 + fname, strerror(errno));
1073 + /* We set the mask (if it exists) to the file's group
1074 + * permissions (as they currently exist on the disk).
1075 + * This avoids a permission race, particularly for new
1076 + * files (where the current group permissions == 0).
1077 + * If this is not the right value, the upcoming chmod()
1078 + * call will change it. */
1079 + int perms = type == SMB_ACL_TYPE_ACCESS
1080 + ? (int)(old_mode & CHMOD_BITS) : -1;
1082 + && !pack_smb_acl(sacl_new, racl_new, perms)) {
1086 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1087 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1088 + fname, str_acl_type(type),
1094 + if (unchanged == 1)
1096 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1101 +/* Enumeration functions for uid mapping: */
1103 +/* Context -- one and only one. Should be cycled through once on uid
1104 + * mapping and once on gid mapping. */
1105 +static rsync_acl_list *_enum_racl_lists[] = {
1106 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1109 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1110 +static size_t enum_racl_index = 0;
1111 +static size_t enum_race_index = 0;
1113 +/* This returns the next tag_type id from the given acl for the next entry,
1114 + * or it returns 0 if there are no more tag_type ids in the acl. */
1116 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1118 + for (; enum_race_index < racl->count; enum_race_index++) {
1119 + rsync_ace *race = &racl->races[enum_race_index++];
1120 + if (race->tag_type == tag_type)
1123 + enum_race_index = 0;
1127 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1129 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1130 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1131 + id_t *id = next_ace_id(tag_type, racl);
1135 + enum_racl_index = 0;
1139 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1141 + for (; *enum_racl_list; enum_racl_list++) {
1142 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1146 + enum_racl_list = &_enum_racl_lists[0];
1150 +id_t *next_acl_uid()
1152 + return next_acl_list_id(SMB_ACL_USER);
1155 +id_t *next_acl_gid()
1157 + return next_acl_list_id(SMB_ACL_GROUP);
1160 +#define PERMS_SPLICE(perms,newbits,where) (((perms) & ~(7 << (where))) | ((newbits) << (where)))
1162 +int default_perms_for_dir(const char *dir)
1166 + BOOL ok, saw_mask = False;
1172 + perms = ACCESSPERMS & ~orig_umask;
1173 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1174 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1175 + if (sacl == NULL) {
1176 + /* Couldn't get an ACL. Darn. */
1179 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1183 + /* We're doing a dry run, so the containing directory
1184 + * wasn't actually created. Don't worry about it. */
1187 + /* Otherwise fall through. */
1189 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1190 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1196 + ok = unpack_smb_acl(&racl, sacl);
1197 + sys_acl_free_acl(sacl);
1199 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1203 + /* Look at each default ACL entry and possibly modify three bits of `perms' accordingly.
1204 + * If there's "no" default ACL, there will be zero entries and the umask-based perms is unchanged. */
1205 + for (i = 0; i < racl.count; i++) {
1206 + switch (racl.races[i].tag_type) {
1207 + case SMB_ACL_USER_OBJ:
1208 + perms = PERMS_SPLICE(perms, racl.races[i].access, 6);
1210 + case SMB_ACL_GROUP_OBJ:
1212 + perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
1214 + case SMB_ACL_MASK:
1216 + perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
1218 + case SMB_ACL_OTHER:
1219 + perms = PERMS_SPLICE(perms, racl.races[i].access, 0);
1225 + rsync_acl_free(&racl);
1227 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1231 +#endif /* SUPPORT_ACLS */
1234 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1235 extern char *backup_dir;
1238 +extern int preserve_acls;
1239 extern int preserve_devices;
1240 extern int preserve_specials;
1241 extern int preserve_links;
1242 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1244 do_lchown(fullpath, st.st_uid, st.st_gid);
1245 do_chmod(fullpath, st.st_mode);
1246 +#ifdef SUPPORT_ACLS
1247 + if (preserve_acls)
1248 + dup_acl(end, fullpath, st.st_mode);
1253 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1254 if (!(buf = get_backup_name(fname)))
1257 +#ifdef SUPPORT_ACLS
1258 + if (preserve_acls)
1259 + push_keep_backup_acl(file, fname, buf);
1262 /* Check to see if this is a device file, or link */
1263 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1264 || (preserve_specials && IS_SPECIAL(file->mode))) {
1265 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1268 set_file_attrs(buf, file, NULL, 0);
1269 +#ifdef SUPPORT_ACLS
1270 + if (preserve_acls)
1271 + cleanup_keep_backup_acl();
1276 --- old/configure.in
1277 +++ new/configure.in
1278 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1279 AC_CHECK_LIB(resolv, strcasecmp)
1282 +AC_CHECK_FUNCS(aclsort)
1283 +if test x"$ac_cv_func_aclsort" = x"no"; then
1284 + AC_CHECK_LIB(sec, aclsort)
1287 dnl At the moment we don't test for a broken memcmp(), because all we
1288 dnl need to do is test for equality, not comparison, and it seems that
1289 dnl every platform has a memcmp that can do at least that.
1290 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1291 AC_SUBST(CC_SHOBJ_FLAG)
1292 AC_SUBST(BUILD_POPT)
1294 +AC_CHECK_HEADERS(sys/acl.h)
1295 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1296 +#################################################
1297 +# check for ACL support
1299 +AC_MSG_CHECKING(whether to support ACLs)
1300 +AC_ARG_ENABLE(acl-support,
1301 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1302 +[ case "$enableval" in
1305 + case "$host_os" in
1307 + AC_MSG_RESULT(Using UnixWare ACLs)
1308 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1311 + AC_MSG_RESULT(Using solaris ACLs)
1312 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1315 + AC_MSG_RESULT(Using HPUX ACLs)
1316 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1319 + AC_MSG_RESULT(Using IRIX ACLs)
1320 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1323 + AC_MSG_RESULT(Using AIX ACLs)
1324 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1327 + AC_MSG_RESULT(Using Tru64 ACLs)
1328 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1329 + LIBS="$LIBS -lpacl"
1332 + AC_MSG_RESULT(ACLs requested -- running tests)
1333 + AC_CHECK_LIB(acl,acl_get_file)
1334 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1335 + AC_TRY_LINK([#include <sys/types.h>
1336 +#include <sys/acl.h>],
1337 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1338 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1339 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1340 + AC_MSG_RESULT(Using posix ACLs)
1341 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1342 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1343 + AC_TRY_LINK([#include <sys/types.h>
1344 +#include <sys/acl.h>],
1345 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1346 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1347 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1348 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1351 + AC_MSG_ERROR(Failed to find ACL support)
1358 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1361 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1365 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1370 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1371 extern int one_file_system;
1372 extern int copy_dirlinks;
1373 extern int keep_dirlinks;
1374 +extern int preserve_acls;
1375 extern int preserve_links;
1376 extern int preserve_hard_links;
1377 extern int preserve_devices;
1378 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1379 if (chmod_modes && !S_ISLNK(file->mode))
1380 file->mode = tweak_mode(file->mode, chmod_modes);
1382 +#ifdef SUPPORT_ACLS
1383 + if (preserve_acls && make_acl(file, fname) < 0)
1387 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1389 flist_expand(flist);
1390 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1391 if (file->basename[0]) {
1392 flist->files[flist->count++] = file;
1393 send_file_entry(file, f);
1394 +#ifdef SUPPORT_ACLS
1395 + if (preserve_acls)
1396 + send_acl(file, f);
1399 +#ifdef SUPPORT_ACLS
1400 + /* Cleanup unsent ACL(s). */
1401 + if (preserve_acls)
1402 + send_acl(file, -1);
1407 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1408 flags |= read_byte(f) << 8;
1409 file = receive_file_entry(flist, flags, f);
1411 +#ifdef SUPPORT_ACLS
1412 + if (preserve_acls)
1413 + receive_acl(file, f);
1416 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1417 stats.total_size += file->length;
1419 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1421 clean_flist(flist, relative_paths, 1);
1423 +#ifdef SUPPORT_ACLS
1424 + if (preserve_acls)
1425 + sort_file_acl_index_lists();
1429 recv_uid_list(f, flist);
1433 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1434 extern int max_delete;
1435 extern int force_delete;
1436 extern int one_file_system;
1437 +extern mode_t orig_umask;
1438 extern struct stats stats;
1439 extern dev_t filesystem_dev;
1440 extern char *backup_dir;
1441 @@ -753,6 +754,7 @@ static int try_dests_non(struct file_str
1444 static int phase = 0;
1445 +static int dflt_perms;
1447 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1448 * make sure it exists, and has the right permissions/timestamp info. For
1449 @@ -844,6 +846,10 @@ static void recv_generator(char *fname,
1452 need_fuzzy_dirlist = 1;
1453 +#ifdef SUPPORT_ACLS
1454 + if (!preserve_perms)
1455 + dflt_perms = default_perms_for_dir(dn);
1458 parent_dirname = dn;
1460 @@ -871,7 +877,8 @@ static void recv_generator(char *fname,
1461 if (!preserve_perms) {
1462 int exists = statret == 0
1463 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1464 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1465 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1469 if (S_ISDIR(file->mode)) {
1470 @@ -1343,6 +1350,8 @@ void generate_files(int f_out, struct fi
1471 * notice that and let us know via the redo pipe (or its closing). */
1474 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1476 for (i = 0; i < flist->count; i++) {
1477 struct file_struct *file = flist->files[i];
1479 --- old/lib/sysacls.c
1480 +++ new/lib/sysacls.c
1483 + Unix SMB/CIFS implementation.
1484 + Samba system utilities for ACL support.
1485 + Copyright (C) Jeremy Allison 2000.
1487 + This program is free software; you can redistribute it and/or modify
1488 + it under the terms of the GNU General Public License as published by
1489 + the Free Software Foundation; either version 2 of the License, or
1490 + (at your option) any later version.
1492 + This program is distributed in the hope that it will be useful,
1493 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1494 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1495 + GNU General Public License for more details.
1497 + You should have received a copy of the GNU General Public License
1498 + along with this program; if not, write to the Free Software
1499 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1503 +#include "sysacls.h" /****** ADDED ******/
1505 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1506 +void SAFE_FREE(void *mem)
1512 +char *uidtoname(uid_t uid)
1514 + static char idbuf[12];
1515 + struct passwd *pw;
1517 + if ((pw = getpwuid(uid)) == NULL) {
1518 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1521 + return pw->pw_name;
1523 +/****** EXTRAS -- END ******/
1526 + This file wraps all differing system ACL interfaces into a consistent
1527 + one based on the POSIX interface. It also returns the correct errors
1528 + for older UNIX systems that don't support ACLs.
1530 + The interfaces that each ACL implementation must support are as follows :
1532 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1533 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1534 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1535 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1536 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1537 + SMB_ACL_T sys_acl_get_fd(int fd)
1538 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1539 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1540 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1541 + SMB_ACL_T sys_acl_init( int count)
1542 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1543 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1544 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1545 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1546 + int sys_acl_valid( SMB_ACL_T theacl )
1547 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1548 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1549 + int sys_acl_delete_def_file(const char *path)
1551 + This next one is not POSIX complient - but we *have* to have it !
1552 + More POSIX braindamage.
1554 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1556 + The generic POSIX free is the following call. We split this into
1557 + several different free functions as we may need to add tag info
1558 + to structures when emulating the POSIX interface.
1560 + int sys_acl_free( void *obj_p)
1562 + The calls we actually use are :
1564 + int sys_acl_free_text(char *text) - free acl_to_text
1565 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1566 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1570 +#if defined(HAVE_POSIX_ACLS)
1572 +/* Identity mapping - easy. */
1574 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1576 + return acl_get_entry( the_acl, entry_id, entry_p);
1579 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1581 + return acl_get_tag_type( entry_d, tag_type_p);
1584 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1586 + return acl_get_permset( entry_d, permset_p);
1589 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1591 + return acl_get_qualifier( entry_d);
1594 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1596 + return acl_get_file( path_p, type);
1599 +SMB_ACL_T sys_acl_get_fd(int fd)
1601 + return acl_get_fd(fd);
1604 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1606 + return acl_clear_perms(permset);
1609 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1611 + return acl_add_perm(permset, perm);
1614 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1616 +#if defined(HAVE_ACL_GET_PERM_NP)
1618 + * Required for TrustedBSD-based ACL implementations where
1619 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1622 + return acl_get_perm_np(permset, perm);
1624 + return acl_get_perm(permset, perm);
1628 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1630 + return acl_to_text( the_acl, plen);
1633 +SMB_ACL_T sys_acl_init( int count)
1635 + return acl_init(count);
1638 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1640 + return acl_create_entry(pacl, pentry);
1643 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1645 + return acl_set_tag_type(entry, tagtype);
1648 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1650 + return acl_set_qualifier(entry, qual);
1653 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1655 + return acl_set_permset(entry, permset);
1658 +int sys_acl_valid( SMB_ACL_T theacl )
1660 + return acl_valid(theacl);
1663 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1665 + return acl_set_file(name, acltype, theacl);
1668 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1670 + return acl_set_fd(fd, theacl);
1673 +int sys_acl_delete_def_file(const char *name)
1675 + return acl_delete_def_file(name);
1678 +int sys_acl_free_text(char *text)
1680 + return acl_free(text);
1683 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1685 + return acl_free(the_acl);
1688 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1690 + return acl_free(qual);
1693 +#elif defined(HAVE_TRU64_ACLS)
1695 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1696 + * is based on Draft 13 of the POSIX spec which is
1697 + * slightly different from the Draft 16 interface.
1699 + * Also, some of the permset manipulation functions
1700 + * such as acl_clear_perm() and acl_add_perm() appear
1701 + * to be broken on Tru64 so we have to manipulate
1702 + * the permission bits in the permset directly.
1704 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1706 + SMB_ACL_ENTRY_T entry;
1708 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1713 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1718 + return errno ? -1 : 0;
1721 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1723 + return acl_get_tag_type( entry_d, tag_type_p);
1726 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1728 + return acl_get_permset( entry_d, permset_p);
1731 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1733 + return acl_get_qualifier( entry_d);
1736 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1738 + return acl_get_file((char *)path_p, type);
1741 +SMB_ACL_T sys_acl_get_fd(int fd)
1743 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1746 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1748 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1753 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1755 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1760 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1765 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1767 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1770 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1772 + return acl_to_text( the_acl, plen);
1775 +SMB_ACL_T sys_acl_init( int count)
1777 + return acl_init(count);
1780 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1782 + SMB_ACL_ENTRY_T entry;
1784 + if ((entry = acl_create_entry(pacl)) == NULL) {
1792 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1794 + return acl_set_tag_type(entry, tagtype);
1797 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1799 + return acl_set_qualifier(entry, qual);
1802 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1804 + return acl_set_permset(entry, permset);
1807 +int sys_acl_valid( SMB_ACL_T theacl )
1809 + acl_entry_t entry;
1811 + return acl_valid(theacl, &entry);
1814 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1816 + return acl_set_file((char *)name, acltype, theacl);
1819 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1821 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1824 +int sys_acl_delete_def_file(const char *name)
1826 + return acl_delete_def_file((char *)name);
1829 +int sys_acl_free_text(char *text)
1832 + * (void) cast and explicit return 0 are for DEC UNIX
1833 + * which just #defines acl_free_text() to be free()
1835 + (void) acl_free_text(text);
1839 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1841 + return acl_free(the_acl);
1844 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1846 + return acl_free_qualifier(qual, tagtype);
1849 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1852 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1853 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1857 + * Note that while this code implements sufficient functionality
1858 + * to support the sys_acl_* interfaces it does not provide all
1859 + * of the semantics of the POSIX ACL interfaces.
1861 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1862 + * from a call to sys_acl_get_entry() should not be assumed to be
1863 + * valid after calling any of the following functions, which may
1864 + * reorder the entries in the ACL.
1867 + * sys_acl_set_file()
1868 + * sys_acl_set_fd()
1872 + * The only difference between Solaris and UnixWare / OpenUNIX is
1873 + * that the #defines for the ACL operations have different names
1875 +#if defined(HAVE_UNIXWARE_ACLS)
1877 +#define SETACL ACL_SET
1878 +#define GETACL ACL_GET
1879 +#define GETACLCNT ACL_CNT
1884 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1886 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1891 + if (entry_p == NULL) {
1896 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1900 + if (acl_d->next < 0) {
1905 + if (acl_d->next >= acl_d->count) {
1909 + *entry_p = &acl_d->acl[acl_d->next++];
1914 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1916 + *type_p = entry_d->a_type;
1921 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1923 + *permset_p = &entry_d->a_perm;
1928 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1930 + if (entry_d->a_type != SMB_ACL_USER
1931 + && entry_d->a_type != SMB_ACL_GROUP) {
1936 + return &entry_d->a_id;
1940 + * There is no way of knowing what size the ACL returned by
1941 + * GETACL will be unless you first call GETACLCNT which means
1942 + * making an additional system call.
1944 + * In the hope of avoiding the cost of the additional system
1945 + * call in most cases, we initially allocate enough space for
1946 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1947 + * be too small then we use GETACLCNT to find out the actual
1948 + * size, reallocate the ACL buffer, and then call GETACL again.
1951 +#define INITIAL_ACL_SIZE 16
1953 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1956 + int count; /* # of ACL entries allocated */
1957 + int naccess; /* # of access ACL entries */
1958 + int ndefault; /* # of default ACL entries */
1960 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1965 + count = INITIAL_ACL_SIZE;
1966 + if ((acl_d = sys_acl_init(count)) == NULL) {
1971 + * If there isn't enough space for the ACL entries we use
1972 + * GETACLCNT to determine the actual number of ACL entries
1973 + * reallocate and try again. This is in a loop because it
1974 + * is possible that someone else could modify the ACL and
1975 + * increase the number of entries between the call to
1976 + * GETACLCNT and the call to GETACL.
1978 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1979 + && errno == ENOSPC) {
1981 + sys_acl_free_acl(acl_d);
1983 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1987 + if ((acl_d = sys_acl_init(count)) == NULL) {
1993 + sys_acl_free_acl(acl_d);
1998 + * calculate the number of access and default ACL entries
2000 + * Note: we assume that the acl() system call returned a
2001 + * well formed ACL which is sorted so that all of the
2002 + * access ACL entries preceed any default ACL entries
2004 + for (naccess = 0; naccess < count; naccess++) {
2005 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2008 + ndefault = count - naccess;
2011 + * if the caller wants the default ACL we have to copy
2012 + * the entries down to the start of the acl[] buffer
2013 + * and mask out the ACL_DEFAULT flag from the type field
2015 + if (type == SMB_ACL_TYPE_DEFAULT) {
2018 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2019 + acl_d->acl[i] = acl_d->acl[j];
2020 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2023 + acl_d->count = ndefault;
2025 + acl_d->count = naccess;
2031 +SMB_ACL_T sys_acl_get_fd(int fd)
2034 + int count; /* # of ACL entries allocated */
2035 + int naccess; /* # of access ACL entries */
2037 + count = INITIAL_ACL_SIZE;
2038 + if ((acl_d = sys_acl_init(count)) == NULL) {
2042 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2043 + && errno == ENOSPC) {
2045 + sys_acl_free_acl(acl_d);
2047 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2051 + if ((acl_d = sys_acl_init(count)) == NULL) {
2057 + sys_acl_free_acl(acl_d);
2062 + * calculate the number of access ACL entries
2064 + for (naccess = 0; naccess < count; naccess++) {
2065 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2069 + acl_d->count = naccess;
2074 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2081 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2083 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2084 + && perm != SMB_ACL_EXECUTE) {
2089 + if (permset_d == NULL) {
2094 + *permset_d |= perm;
2099 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2101 + return *permset_d & perm;
2104 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2111 + * use an initial estimate of 20 bytes per ACL entry
2112 + * when allocating memory for the text representation
2116 + maxlen = 20 * acl_d->count;
2117 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2122 + for (i = 0; i < acl_d->count; i++) {
2123 + struct acl *ap = &acl_d->acl[i];
2124 + struct passwd *pw;
2133 + switch (ap->a_type) {
2135 + * for debugging purposes it's probably more
2136 + * useful to dump unknown tag types rather
2137 + * than just returning an error
2140 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2143 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2148 + case SMB_ACL_USER:
2149 + id = uidtoname(ap->a_id);
2150 + case SMB_ACL_USER_OBJ:
2154 + case SMB_ACL_GROUP:
2155 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2156 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2162 + case SMB_ACL_GROUP_OBJ:
2166 + case SMB_ACL_OTHER:
2170 + case SMB_ACL_MASK:
2176 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2177 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2178 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2181 + /* <tag> : <qualifier> : rwx \n \0 */
2182 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2185 + * If this entry would overflow the buffer
2186 + * allocate enough additional memory for this
2187 + * entry and an estimate of another 20 bytes
2188 + * for each entry still to be processed
2190 + if ((len + nbytes) > maxlen) {
2191 + char *oldtext = text;
2193 + maxlen += nbytes + 20 * (acl_d->count - i);
2195 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2196 + SAFE_FREE(oldtext);
2202 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2203 + len += nbytes - 1;
2212 +SMB_ACL_T sys_acl_init(int count)
2222 + * note that since the definition of the structure pointed
2223 + * to by the SMB_ACL_T includes the first element of the
2224 + * acl[] array, this actually allocates an ACL with room
2225 + * for (count+1) entries
2227 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2232 + a->size = count + 1;
2240 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2243 + SMB_ACL_ENTRY_T entry_d;
2245 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2250 + if (acl_d->count >= acl_d->size) {
2255 + entry_d = &acl_d->acl[acl_d->count++];
2256 + entry_d->a_type = 0;
2257 + entry_d->a_id = -1;
2258 + entry_d->a_perm = 0;
2259 + *entry_p = entry_d;
2264 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2266 + switch (tag_type) {
2267 + case SMB_ACL_USER:
2268 + case SMB_ACL_USER_OBJ:
2269 + case SMB_ACL_GROUP:
2270 + case SMB_ACL_GROUP_OBJ:
2271 + case SMB_ACL_OTHER:
2272 + case SMB_ACL_MASK:
2273 + entry_d->a_type = tag_type;
2283 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2285 + if (entry_d->a_type != SMB_ACL_GROUP
2286 + && entry_d->a_type != SMB_ACL_USER) {
2291 + entry_d->a_id = *((id_t *)qual_p);
2296 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2298 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2302 + entry_d->a_perm = *permset_d;
2308 + * sort the ACL and check it for validity
2310 + * if it's a minimal ACL with only 4 entries then we
2311 + * need to recalculate the mask permissions to make
2312 + * sure that they are the same as the GROUP_OBJ
2313 + * permissions as required by the UnixWare acl() system call.
2315 + * (note: since POSIX allows minimal ACLs which only contain
2316 + * 3 entries - ie there is no mask entry - we should, in theory,
2317 + * check for this and add a mask entry if necessary - however
2318 + * we "know" that the caller of this interface always specifies
2319 + * a mask so, in practice "this never happens" (tm) - if it *does*
2320 + * happen aclsort() will fail and return an error and someone will
2321 + * have to fix it ...)
2324 +static int acl_sort(SMB_ACL_T acl_d)
2326 + int fixmask = (acl_d->count <= 4);
2328 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2335 +int sys_acl_valid(SMB_ACL_T acl_d)
2337 + return acl_sort(acl_d);
2340 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2343 + struct acl *acl_p;
2345 + struct acl *acl_buf = NULL;
2348 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2353 + if (acl_sort(acl_d) != 0) {
2357 + acl_p = &acl_d->acl[0];
2358 + acl_count = acl_d->count;
2361 + * if it's a directory there is extra work to do
2362 + * since the acl() system call will replace both
2363 + * the access ACLs and the default ACLs (if any)
2365 + if (stat(name, &s) != 0) {
2368 + if (S_ISDIR(s.st_mode)) {
2369 + SMB_ACL_T acc_acl;
2370 + SMB_ACL_T def_acl;
2371 + SMB_ACL_T tmp_acl;
2374 + if (type == SMB_ACL_TYPE_ACCESS) {
2376 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2380 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2383 + if (tmp_acl == NULL) {
2388 + * allocate a temporary buffer for the complete ACL
2390 + acl_count = acc_acl->count + def_acl->count;
2391 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2393 + if (acl_buf == NULL) {
2394 + sys_acl_free_acl(tmp_acl);
2400 + * copy the access control and default entries into the buffer
2402 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2403 + acc_acl->count * sizeof(acl_buf[0]));
2405 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2406 + def_acl->count * sizeof(acl_buf[0]));
2409 + * set the ACL_DEFAULT flag on the default entries
2411 + for (i = acc_acl->count; i < acl_count; i++) {
2412 + acl_buf[i].a_type |= ACL_DEFAULT;
2415 + sys_acl_free_acl(tmp_acl);
2417 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2422 + ret = acl(name, SETACL, acl_count, acl_p);
2424 + SAFE_FREE(acl_buf);
2429 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2431 + if (acl_sort(acl_d) != 0) {
2435 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2438 +int sys_acl_delete_def_file(const char *path)
2444 + * fetching the access ACL and rewriting it has
2445 + * the effect of deleting the default ACL
2447 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2451 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2453 + sys_acl_free_acl(acl_d);
2458 +int sys_acl_free_text(char *text)
2464 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2470 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2475 +#elif defined(HAVE_HPUX_ACLS)
2479 + * Based on the Solaris/SCO code - with modifications.
2483 + * Note that while this code implements sufficient functionality
2484 + * to support the sys_acl_* interfaces it does not provide all
2485 + * of the semantics of the POSIX ACL interfaces.
2487 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2488 + * from a call to sys_acl_get_entry() should not be assumed to be
2489 + * valid after calling any of the following functions, which may
2490 + * reorder the entries in the ACL.
2493 + * sys_acl_set_file()
2494 + * sys_acl_set_fd()
2497 +/* This checks if the POSIX ACL system call is defined */
2498 +/* which basically corresponds to whether JFS 3.3 or */
2499 +/* higher is installed. If acl() was called when it */
2500 +/* isn't defined, it causes the process to core dump */
2501 +/* so it is important to check this and avoid acl() */
2502 +/* calls if it isn't there. */
2504 +static BOOL hpux_acl_call_presence(void)
2507 + shl_t handle = NULL;
2510 + static BOOL already_checked=0;
2512 + if(already_checked)
2516 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2518 + if(ret_val != 0) {
2519 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2520 + ret_val, errno, strerror(errno)));
2521 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2525 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2527 + already_checked = True;
2531 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2533 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2538 + if (entry_p == NULL) {
2543 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2547 + if (acl_d->next < 0) {
2552 + if (acl_d->next >= acl_d->count) {
2556 + *entry_p = &acl_d->acl[acl_d->next++];
2561 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2563 + *type_p = entry_d->a_type;
2568 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2570 + *permset_p = &entry_d->a_perm;
2575 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2577 + if (entry_d->a_type != SMB_ACL_USER
2578 + && entry_d->a_type != SMB_ACL_GROUP) {
2583 + return &entry_d->a_id;
2587 + * There is no way of knowing what size the ACL returned by
2588 + * ACL_GET will be unless you first call ACL_CNT which means
2589 + * making an additional system call.
2591 + * In the hope of avoiding the cost of the additional system
2592 + * call in most cases, we initially allocate enough space for
2593 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2594 + * be too small then we use ACL_CNT to find out the actual
2595 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2598 +#define INITIAL_ACL_SIZE 16
2600 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2603 + int count; /* # of ACL entries allocated */
2604 + int naccess; /* # of access ACL entries */
2605 + int ndefault; /* # of default ACL entries */
2607 + if(hpux_acl_call_presence() == False) {
2608 + /* Looks like we don't have the acl() system call on HPUX.
2609 + * May be the system doesn't have the latest version of JFS.
2614 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2619 + count = INITIAL_ACL_SIZE;
2620 + if ((acl_d = sys_acl_init(count)) == NULL) {
2625 + * If there isn't enough space for the ACL entries we use
2626 + * ACL_CNT to determine the actual number of ACL entries
2627 + * reallocate and try again. This is in a loop because it
2628 + * is possible that someone else could modify the ACL and
2629 + * increase the number of entries between the call to
2630 + * ACL_CNT and the call to ACL_GET.
2632 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2634 + sys_acl_free_acl(acl_d);
2636 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2640 + if ((acl_d = sys_acl_init(count)) == NULL) {
2646 + sys_acl_free_acl(acl_d);
2651 + * calculate the number of access and default ACL entries
2653 + * Note: we assume that the acl() system call returned a
2654 + * well formed ACL which is sorted so that all of the
2655 + * access ACL entries preceed any default ACL entries
2657 + for (naccess = 0; naccess < count; naccess++) {
2658 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2661 + ndefault = count - naccess;
2664 + * if the caller wants the default ACL we have to copy
2665 + * the entries down to the start of the acl[] buffer
2666 + * and mask out the ACL_DEFAULT flag from the type field
2668 + if (type == SMB_ACL_TYPE_DEFAULT) {
2671 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2672 + acl_d->acl[i] = acl_d->acl[j];
2673 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2676 + acl_d->count = ndefault;
2678 + acl_d->count = naccess;
2684 +SMB_ACL_T sys_acl_get_fd(int fd)
2687 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2690 + files_struct *fsp = file_find_fd(fd);
2692 + if (fsp == NULL) {
2698 + * We know we're in the same conn context. So we
2699 + * can use the relative path.
2702 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2705 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2712 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2714 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2715 + && perm != SMB_ACL_EXECUTE) {
2720 + if (permset_d == NULL) {
2725 + *permset_d |= perm;
2730 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2732 + return *permset_d & perm;
2735 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2742 + * use an initial estimate of 20 bytes per ACL entry
2743 + * when allocating memory for the text representation
2747 + maxlen = 20 * acl_d->count;
2748 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2753 + for (i = 0; i < acl_d->count; i++) {
2754 + struct acl *ap = &acl_d->acl[i];
2755 + struct passwd *pw;
2764 + switch (ap->a_type) {
2766 + * for debugging purposes it's probably more
2767 + * useful to dump unknown tag types rather
2768 + * than just returning an error
2771 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2774 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2779 + case SMB_ACL_USER:
2780 + id = uidtoname(ap->a_id);
2781 + case SMB_ACL_USER_OBJ:
2785 + case SMB_ACL_GROUP:
2786 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2787 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2793 + case SMB_ACL_GROUP_OBJ:
2797 + case SMB_ACL_OTHER:
2801 + case SMB_ACL_MASK:
2807 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2808 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2809 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2812 + /* <tag> : <qualifier> : rwx \n \0 */
2813 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2816 + * If this entry would overflow the buffer
2817 + * allocate enough additional memory for this
2818 + * entry and an estimate of another 20 bytes
2819 + * for each entry still to be processed
2821 + if ((len + nbytes) > maxlen) {
2822 + char *oldtext = text;
2824 + maxlen += nbytes + 20 * (acl_d->count - i);
2826 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2833 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2834 + len += nbytes - 1;
2843 +SMB_ACL_T sys_acl_init(int count)
2853 + * note that since the definition of the structure pointed
2854 + * to by the SMB_ACL_T includes the first element of the
2855 + * acl[] array, this actually allocates an ACL with room
2856 + * for (count+1) entries
2858 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2863 + a->size = count + 1;
2871 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2874 + SMB_ACL_ENTRY_T entry_d;
2876 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2881 + if (acl_d->count >= acl_d->size) {
2886 + entry_d = &acl_d->acl[acl_d->count++];
2887 + entry_d->a_type = 0;
2888 + entry_d->a_id = -1;
2889 + entry_d->a_perm = 0;
2890 + *entry_p = entry_d;
2895 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2897 + switch (tag_type) {
2898 + case SMB_ACL_USER:
2899 + case SMB_ACL_USER_OBJ:
2900 + case SMB_ACL_GROUP:
2901 + case SMB_ACL_GROUP_OBJ:
2902 + case SMB_ACL_OTHER:
2903 + case SMB_ACL_MASK:
2904 + entry_d->a_type = tag_type;
2914 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2916 + if (entry_d->a_type != SMB_ACL_GROUP
2917 + && entry_d->a_type != SMB_ACL_USER) {
2922 + entry_d->a_id = *((id_t *)qual_p);
2927 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2929 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2933 + entry_d->a_perm = *permset_d;
2938 +/* Structure to capture the count for each type of ACE. */
2940 +struct hpux_acl_types {
2944 + int n_def_user_obj;
2949 + int n_def_group_obj;
2953 + int n_def_other_obj;
2956 + int n_def_class_obj;
2958 + int n_illegal_obj;
2962 + * Counts the different number of objects in a given array of ACL
2966 + * acl_count - Count of ACLs in the array of ACL strucutres.
2967 + * aclp - Array of ACL structures.
2968 + * acl_type_count - Pointer to acl_types structure. Should already be
2972 + * acl_type_count - This structure is filled up with counts of various
2976 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2980 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2982 + for(i=0;i<acl_count;i++) {
2983 + switch(aclp[i].a_type) {
2985 + acl_type_count->n_user++;
2988 + acl_type_count->n_user_obj++;
2990 + case DEF_USER_OBJ:
2991 + acl_type_count->n_def_user_obj++;
2994 + acl_type_count->n_group++;
2997 + acl_type_count->n_group_obj++;
2999 + case DEF_GROUP_OBJ:
3000 + acl_type_count->n_def_group_obj++;
3003 + acl_type_count->n_other_obj++;
3005 + case DEF_OTHER_OBJ:
3006 + acl_type_count->n_def_other_obj++;
3009 + acl_type_count->n_class_obj++;
3011 + case DEF_CLASS_OBJ:
3012 + acl_type_count->n_def_class_obj++;
3015 + acl_type_count->n_def_user++;
3018 + acl_type_count->n_def_group++;
3021 + acl_type_count->n_illegal_obj++;
3027 +/* swap_acl_entries: Swaps two ACL entries.
3029 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3032 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3034 + struct acl temp_acl;
3036 + temp_acl.a_type = aclp0->a_type;
3037 + temp_acl.a_id = aclp0->a_id;
3038 + temp_acl.a_perm = aclp0->a_perm;
3040 + aclp0->a_type = aclp1->a_type;
3041 + aclp0->a_id = aclp1->a_id;
3042 + aclp0->a_perm = aclp1->a_perm;
3044 + aclp1->a_type = temp_acl.a_type;
3045 + aclp1->a_id = temp_acl.a_id;
3046 + aclp1->a_perm = temp_acl.a_perm;
3049 +/* prohibited_duplicate_type
3050 + * Identifies if given ACL type can have duplicate entries or
3053 + * Inputs: acl_type - ACL Type.
3059 + * True - If the ACL type matches any of the prohibited types.
3060 + * False - If the ACL type doesn't match any of the prohibited types.
3063 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3065 + switch(acl_type) {
3076 +/* get_needed_class_perm
3077 + * Returns the permissions of a ACL structure only if the ACL
3078 + * type matches one of the pre-determined types for computing
3079 + * CLASS_OBJ permissions.
3081 + * Inputs: aclp - Pointer to ACL structure.
3084 +static int hpux_get_needed_class_perm(struct acl *aclp)
3086 + switch(aclp->a_type) {
3090 + case DEF_USER_OBJ:
3092 + case DEF_GROUP_OBJ:
3094 + case DEF_CLASS_OBJ:
3095 + case DEF_OTHER_OBJ:
3096 + return aclp->a_perm;
3102 +/* acl_sort for HPUX.
3103 + * Sorts the array of ACL structures as per the description in
3104 + * aclsort man page. Refer to aclsort man page for more details
3108 + * acl_count - Count of ACLs in the array of ACL structures.
3109 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3111 + * aclp - Array of ACL structures.
3115 + * aclp - Sorted array of ACL structures.
3119 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3120 + * debug log in case of failure.
3123 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3125 +#if !defined(HAVE_HPUX_ACLSORT)
3127 + * The aclsort() system call is availabe on the latest HPUX General
3128 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3129 + * function. Because, we don't want to update to a new
3130 + * HPUX GR bundle just for aclsort() call.
3133 + struct hpux_acl_types acl_obj_count;
3134 + int n_class_obj_perm = 0;
3138 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3142 + if(aclp == NULL) {
3143 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3147 + /* Count different types of ACLs in the ACLs array */
3149 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3151 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3152 + * CLASS_OBJ and OTHER_OBJ
3155 + if( (acl_obj_count.n_user_obj != 1) ||
3156 + (acl_obj_count.n_group_obj != 1) ||
3157 + (acl_obj_count.n_class_obj != 1) ||
3158 + (acl_obj_count.n_other_obj != 1)
3160 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3161 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3165 + /* If any of the default objects are present, there should be only
3166 + * one of them each.
3169 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3170 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3171 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3172 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3176 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3179 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3180 + * same ACL type, sort by ACL id.
3182 + * I am using the trival kind of sorting method here because, performance isn't
3183 + * really effected by the ACLs feature. More over there aren't going to be more
3184 + * than 17 entries on HPUX.
3187 + for(i=0; i<acl_count;i++) {
3188 + for (j=i+1; j<acl_count; j++) {
3189 + if( aclp[i].a_type > aclp[j].a_type ) {
3190 + /* ACL entries out of order, swap them */
3192 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3194 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3196 + /* ACL entries of same type, sort by id */
3198 + if(aclp[i].a_id > aclp[j].a_id) {
3199 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3200 + } else if (aclp[i].a_id == aclp[j].a_id) {
3201 + /* We have a duplicate entry. */
3202 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3203 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3204 + aclp[i].a_type, aclp[i].a_id));
3213 + /* set the class obj permissions to the computed one. */
3215 + int n_class_obj_index = -1;
3217 + for(i=0;i<acl_count;i++) {
3218 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3220 + if(aclp[i].a_type == CLASS_OBJ)
3221 + n_class_obj_index = i;
3223 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3228 + return aclsort(acl_count, calclass, aclp);
3233 + * sort the ACL and check it for validity
3235 + * if it's a minimal ACL with only 4 entries then we
3236 + * need to recalculate the mask permissions to make
3237 + * sure that they are the same as the GROUP_OBJ
3238 + * permissions as required by the UnixWare acl() system call.
3240 + * (note: since POSIX allows minimal ACLs which only contain
3241 + * 3 entries - ie there is no mask entry - we should, in theory,
3242 + * check for this and add a mask entry if necessary - however
3243 + * we "know" that the caller of this interface always specifies
3244 + * a mask so, in practice "this never happens" (tm) - if it *does*
3245 + * happen aclsort() will fail and return an error and someone will
3246 + * have to fix it ...)
3249 +static int acl_sort(SMB_ACL_T acl_d)
3251 + int fixmask = (acl_d->count <= 4);
3253 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3260 +int sys_acl_valid(SMB_ACL_T acl_d)
3262 + return acl_sort(acl_d);
3265 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3268 + struct acl *acl_p;
3270 + struct acl *acl_buf = NULL;
3273 + if(hpux_acl_call_presence() == False) {
3274 + /* Looks like we don't have the acl() system call on HPUX.
3275 + * May be the system doesn't have the latest version of JFS.
3281 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3286 + if (acl_sort(acl_d) != 0) {
3290 + acl_p = &acl_d->acl[0];
3291 + acl_count = acl_d->count;
3294 + * if it's a directory there is extra work to do
3295 + * since the acl() system call will replace both
3296 + * the access ACLs and the default ACLs (if any)
3298 + if (stat(name, &s) != 0) {
3301 + if (S_ISDIR(s.st_mode)) {
3302 + SMB_ACL_T acc_acl;
3303 + SMB_ACL_T def_acl;
3304 + SMB_ACL_T tmp_acl;
3307 + if (type == SMB_ACL_TYPE_ACCESS) {
3309 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3313 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3316 + if (tmp_acl == NULL) {
3321 + * allocate a temporary buffer for the complete ACL
3323 + acl_count = acc_acl->count + def_acl->count;
3324 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3326 + if (acl_buf == NULL) {
3327 + sys_acl_free_acl(tmp_acl);
3333 + * copy the access control and default entries into the buffer
3335 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3336 + acc_acl->count * sizeof(acl_buf[0]));
3338 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3339 + def_acl->count * sizeof(acl_buf[0]));
3342 + * set the ACL_DEFAULT flag on the default entries
3344 + for (i = acc_acl->count; i < acl_count; i++) {
3345 + acl_buf[i].a_type |= ACL_DEFAULT;
3348 + sys_acl_free_acl(tmp_acl);
3350 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3355 + ret = acl(name, ACL_SET, acl_count, acl_p);
3364 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3367 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3370 + files_struct *fsp = file_find_fd(fd);
3372 + if (fsp == NULL) {
3377 + if (acl_sort(acl_d) != 0) {
3382 + * We know we're in the same conn context. So we
3383 + * can use the relative path.
3386 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3389 +int sys_acl_delete_def_file(const char *path)
3395 + * fetching the access ACL and rewriting it has
3396 + * the effect of deleting the default ACL
3398 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3402 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3404 + sys_acl_free_acl(acl_d);
3409 +int sys_acl_free_text(char *text)
3415 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3421 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3426 +#elif defined(HAVE_IRIX_ACLS)
3428 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3430 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3435 + if (entry_p == NULL) {
3440 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3444 + if (acl_d->next < 0) {
3449 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3453 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3458 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3460 + *type_p = entry_d->ae_tag;
3465 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3467 + *permset_p = entry_d;
3472 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3474 + if (entry_d->ae_tag != SMB_ACL_USER
3475 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3480 + return &entry_d->ae_id;
3483 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3487 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3491 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3496 + a->freeaclp = True;
3500 +SMB_ACL_T sys_acl_get_fd(int fd)
3504 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3508 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3513 + a->freeaclp = True;
3517 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3519 + permset_d->ae_perm = 0;
3524 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3526 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3527 + && perm != SMB_ACL_EXECUTE) {
3532 + if (permset_d == NULL) {
3537 + permset_d->ae_perm |= perm;
3542 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3544 + return permset_d->ae_perm & perm;
3547 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3549 + return acl_to_text(acl_d->aclp, len_p);
3552 +SMB_ACL_T sys_acl_init(int count)
3561 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3567 + a->freeaclp = False;
3568 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3569 + a->aclp->acl_cnt = 0;
3575 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3578 + SMB_ACL_ENTRY_T entry_d;
3580 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3585 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3590 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3591 + entry_d->ae_tag = 0;
3592 + entry_d->ae_id = 0;
3593 + entry_d->ae_perm = 0;
3594 + *entry_p = entry_d;
3599 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3601 + switch (tag_type) {
3602 + case SMB_ACL_USER:
3603 + case SMB_ACL_USER_OBJ:
3604 + case SMB_ACL_GROUP:
3605 + case SMB_ACL_GROUP_OBJ:
3606 + case SMB_ACL_OTHER:
3607 + case SMB_ACL_MASK:
3608 + entry_d->ae_tag = tag_type;
3618 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3620 + if (entry_d->ae_tag != SMB_ACL_GROUP
3621 + && entry_d->ae_tag != SMB_ACL_USER) {
3626 + entry_d->ae_id = *((id_t *)qual_p);
3631 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3633 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3637 + entry_d->ae_perm = permset_d->ae_perm;
3642 +int sys_acl_valid(SMB_ACL_T acl_d)
3644 + return acl_valid(acl_d->aclp);
3647 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3649 + return acl_set_file(name, type, acl_d->aclp);
3652 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3654 + return acl_set_fd(fd, acl_d->aclp);
3657 +int sys_acl_delete_def_file(const char *name)
3659 + return acl_delete_def_file(name);
3662 +int sys_acl_free_text(char *text)
3664 + return acl_free(text);
3667 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3669 + if (acl_d->freeaclp) {
3670 + acl_free(acl_d->aclp);
3676 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3681 +#elif defined(HAVE_AIX_ACLS)
3683 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3685 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3687 + struct acl_entry_link *link;
3688 + struct new_acl_entry *entry;
3691 + DEBUG(10,("This is the count: %d\n",theacl->count));
3693 + /* Check if count was previously set to -1. *
3694 + * If it was, that means we reached the end *
3695 + * of the acl last time. */
3696 + if(theacl->count == -1)
3700 + /* To get to the next acl, traverse linked list until index *
3701 + * of acl matches the count we are keeping. This count is *
3702 + * incremented each time we return an acl entry. */
3704 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3705 + link = link->nextp;
3707 + entry = *entry_p = link->entryp;
3709 + DEBUG(10,("*entry_p is %d\n",entry_p));
3710 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3712 + /* Increment count */
3714 + if(link->nextp == NULL)
3715 + theacl->count = -1;
3720 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3722 + /* Initialize tag type */
3725 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3727 + /* Depending on what type of entry we have, *
3728 + * return tag type. */
3729 + switch(entry_d->ace_id->id_type) {
3731 + *tag_type_p = SMB_ACL_USER;
3734 + *tag_type_p = SMB_ACL_GROUP;
3737 + case SMB_ACL_USER_OBJ:
3738 + case SMB_ACL_GROUP_OBJ:
3739 + case SMB_ACL_OTHER:
3740 + *tag_type_p = entry_d->ace_id->id_type;
3750 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3752 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3753 + *permset_p = &entry_d->ace_access;
3754 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3755 + if(!(**permset_p & S_IXUSR) &&
3756 + !(**permset_p & S_IWUSR) &&
3757 + !(**permset_p & S_IRUSR) &&
3758 + (**permset_p != 0))
3761 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3765 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3767 + return(entry_d->ace_id->id_data);
3770 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3772 + struct acl *file_acl = (struct acl *)NULL;
3773 + struct acl_entry *acl_entry;
3774 + struct new_acl_entry *new_acl_entry;
3775 + struct ace_id *idp;
3776 + struct acl_entry_link *acl_entry_link;
3777 + struct acl_entry_link *acl_entry_link_head;
3782 + /* AIX has no DEFAULT */
3783 + if ( type == SMB_ACL_TYPE_DEFAULT )
3786 + /* Get the acl using statacl */
3788 + DEBUG(10,("Entering sys_acl_get_file\n"));
3789 + DEBUG(10,("path_p is %s\n",path_p));
3791 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3793 + if(file_acl == NULL) {
3795 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3799 + memset(file_acl,0,BUFSIZ);
3801 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3803 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3804 + SAFE_FREE(file_acl);
3808 + DEBUG(10,("Got facl and returned it\n"));
3810 + /* Point to the first acl entry in the acl */
3811 + acl_entry = file_acl->acl_ext;
3813 + /* Begin setting up the head of the linked list *
3814 + * that will be used for the storing the acl *
3815 + * in a way that is useful for the posix_acls.c *
3818 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3819 + if(acl_entry_link_head == NULL)
3822 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3823 + if(acl_entry_link->entryp == NULL) {
3824 + SAFE_FREE(file_acl);
3826 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3830 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3831 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3833 + /* Check if the extended acl bit is on. *
3834 + * If it isn't, do not show the *
3835 + * contents of the acl since AIX intends *
3836 + * the extended info to remain unused */
3838 + if(file_acl->acl_mode & S_IXACL){
3839 + /* while we are not pointing to the very end */
3840 + while(acl_entry < acl_last(file_acl)) {
3841 + /* before we malloc anything, make sure this is */
3842 + /* a valid acl entry and one that we want to map */
3843 + idp = id_nxt(acl_entry->ace_id);
3844 + if((acl_entry->ace_type == ACC_SPECIFY ||
3845 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3846 + acl_entry = acl_nxt(acl_entry);
3850 + idp = acl_entry->ace_id;
3852 + /* Check if this is the first entry in the linked list. *
3853 + * The first entry needs to keep prevp pointing to NULL *
3854 + * and already has entryp allocated. */
3856 + if(acl_entry_link_head->count != 0) {
3857 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3859 + if(acl_entry_link->nextp == NULL) {
3860 + SAFE_FREE(file_acl);
3862 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3866 + acl_entry_link->nextp->prevp = acl_entry_link;
3867 + acl_entry_link = acl_entry_link->nextp;
3868 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3869 + if(acl_entry_link->entryp == NULL) {
3870 + SAFE_FREE(file_acl);
3872 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3875 + acl_entry_link->nextp = NULL;
3878 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3880 + /* Don't really need this since all types are going *
3881 + * to be specified but, it's better than leaving it 0 */
3883 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3885 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3887 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3889 + /* The access in the acl entries must be left shifted by *
3890 + * three bites, because they will ultimately be compared *
3891 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3893 + switch(acl_entry->ace_type){
3896 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3897 + acl_entry_link->entryp->ace_access <<= 6;
3898 + acl_entry_link_head->count++;
3901 + /* Since there is no way to return a DENY acl entry *
3902 + * change to PERMIT and then shift. */
3903 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3904 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3905 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3906 + acl_entry_link->entryp->ace_access <<= 6;
3907 + acl_entry_link_head->count++;
3913 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3914 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3916 + acl_entry = acl_nxt(acl_entry);
3918 + } /* end of if enabled */
3920 + /* Since owner, group, other acl entries are not *
3921 + * part of the acl entries in an acl, they must *
3922 + * be dummied up to become part of the list. */
3924 + for( i = 1; i < 4; i++) {
3925 + DEBUG(10,("i is %d\n",i));
3926 + if(acl_entry_link_head->count != 0) {
3927 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3928 + if(acl_entry_link->nextp == NULL) {
3929 + SAFE_FREE(file_acl);
3931 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3935 + acl_entry_link->nextp->prevp = acl_entry_link;
3936 + acl_entry_link = acl_entry_link->nextp;
3937 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3938 + if(acl_entry_link->entryp == NULL) {
3939 + SAFE_FREE(file_acl);
3941 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3946 + acl_entry_link->nextp = NULL;
3948 + new_acl_entry = acl_entry_link->entryp;
3949 + idp = new_acl_entry->ace_id;
3951 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3952 + new_acl_entry->ace_type = ACC_PERMIT;
3953 + idp->id_len = sizeof(struct ace_id);
3954 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3955 + memset(idp->id_data,0,sizeof(uid_t));
3959 + new_acl_entry->ace_access = file_acl->g_access << 6;
3960 + idp->id_type = SMB_ACL_GROUP_OBJ;
3964 + new_acl_entry->ace_access = file_acl->o_access << 6;
3965 + idp->id_type = SMB_ACL_OTHER;
3969 + new_acl_entry->ace_access = file_acl->u_access << 6;
3970 + idp->id_type = SMB_ACL_USER_OBJ;
3978 + acl_entry_link_head->count++;
3979 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3982 + acl_entry_link_head->count = 0;
3983 + SAFE_FREE(file_acl);
3985 + return(acl_entry_link_head);
3988 +SMB_ACL_T sys_acl_get_fd(int fd)
3990 + struct acl *file_acl = (struct acl *)NULL;
3991 + struct acl_entry *acl_entry;
3992 + struct new_acl_entry *new_acl_entry;
3993 + struct ace_id *idp;
3994 + struct acl_entry_link *acl_entry_link;
3995 + struct acl_entry_link *acl_entry_link_head;
4000 + /* Get the acl using fstatacl */
4002 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4003 + DEBUG(10,("fd is %d\n",fd));
4004 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4006 + if(file_acl == NULL) {
4008 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4012 + memset(file_acl,0,BUFSIZ);
4014 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4016 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4017 + SAFE_FREE(file_acl);
4021 + DEBUG(10,("Got facl and returned it\n"));
4023 + /* Point to the first acl entry in the acl */
4025 + acl_entry = file_acl->acl_ext;
4026 + /* Begin setting up the head of the linked list *
4027 + * that will be used for the storing the acl *
4028 + * in a way that is useful for the posix_acls.c *
4031 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4032 + if(acl_entry_link_head == NULL){
4033 + SAFE_FREE(file_acl);
4037 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4039 + if(acl_entry_link->entryp == NULL) {
4041 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4042 + SAFE_FREE(file_acl);
4046 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4047 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4049 + /* Check if the extended acl bit is on. *
4050 + * If it isn't, do not show the *
4051 + * contents of the acl since AIX intends *
4052 + * the extended info to remain unused */
4054 + if(file_acl->acl_mode & S_IXACL){
4055 + /* while we are not pointing to the very end */
4056 + while(acl_entry < acl_last(file_acl)) {
4057 + /* before we malloc anything, make sure this is */
4058 + /* a valid acl entry and one that we want to map */
4060 + idp = id_nxt(acl_entry->ace_id);
4061 + if((acl_entry->ace_type == ACC_SPECIFY ||
4062 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4063 + acl_entry = acl_nxt(acl_entry);
4067 + idp = acl_entry->ace_id;
4069 + /* Check if this is the first entry in the linked list. *
4070 + * The first entry needs to keep prevp pointing to NULL *
4071 + * and already has entryp allocated. */
4073 + if(acl_entry_link_head->count != 0) {
4074 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4075 + if(acl_entry_link->nextp == NULL) {
4077 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4078 + SAFE_FREE(file_acl);
4081 + acl_entry_link->nextp->prevp = acl_entry_link;
4082 + acl_entry_link = acl_entry_link->nextp;
4083 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4084 + if(acl_entry_link->entryp == NULL) {
4086 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4087 + SAFE_FREE(file_acl);
4091 + acl_entry_link->nextp = NULL;
4094 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4096 + /* Don't really need this since all types are going *
4097 + * to be specified but, it's better than leaving it 0 */
4099 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4100 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4102 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4104 + /* The access in the acl entries must be left shifted by *
4105 + * three bites, because they will ultimately be compared *
4106 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4108 + switch(acl_entry->ace_type){
4111 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4112 + acl_entry_link->entryp->ace_access <<= 6;
4113 + acl_entry_link_head->count++;
4116 + /* Since there is no way to return a DENY acl entry *
4117 + * change to PERMIT and then shift. */
4118 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4119 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4120 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4121 + acl_entry_link->entryp->ace_access <<= 6;
4122 + acl_entry_link_head->count++;
4128 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4129 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4131 + acl_entry = acl_nxt(acl_entry);
4133 + } /* end of if enabled */
4135 + /* Since owner, group, other acl entries are not *
4136 + * part of the acl entries in an acl, they must *
4137 + * be dummied up to become part of the list. */
4139 + for( i = 1; i < 4; i++) {
4140 + DEBUG(10,("i is %d\n",i));
4141 + if(acl_entry_link_head->count != 0){
4142 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4143 + if(acl_entry_link->nextp == NULL) {
4145 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4146 + SAFE_FREE(file_acl);
4150 + acl_entry_link->nextp->prevp = acl_entry_link;
4151 + acl_entry_link = acl_entry_link->nextp;
4152 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4154 + if(acl_entry_link->entryp == NULL) {
4155 + SAFE_FREE(file_acl);
4157 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4162 + acl_entry_link->nextp = NULL;
4164 + new_acl_entry = acl_entry_link->entryp;
4165 + idp = new_acl_entry->ace_id;
4167 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4168 + new_acl_entry->ace_type = ACC_PERMIT;
4169 + idp->id_len = sizeof(struct ace_id);
4170 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4171 + memset(idp->id_data,0,sizeof(uid_t));
4175 + new_acl_entry->ace_access = file_acl->g_access << 6;
4176 + idp->id_type = SMB_ACL_GROUP_OBJ;
4180 + new_acl_entry->ace_access = file_acl->o_access << 6;
4181 + idp->id_type = SMB_ACL_OTHER;
4185 + new_acl_entry->ace_access = file_acl->u_access << 6;
4186 + idp->id_type = SMB_ACL_USER_OBJ;
4193 + acl_entry_link_head->count++;
4194 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4197 + acl_entry_link_head->count = 0;
4198 + SAFE_FREE(file_acl);
4200 + return(acl_entry_link_head);
4203 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4205 + *permset = *permset & ~0777;
4209 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4212 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4216 + DEBUG(10,("This is the permset now: %d\n",*permset));
4220 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4225 +SMB_ACL_T sys_acl_init( int count)
4227 + struct acl_entry_link *theacl = NULL;
4229 + DEBUG(10,("Entering sys_acl_init\n"));
4231 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4232 + if(theacl == NULL) {
4234 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4238 + theacl->count = 0;
4239 + theacl->nextp = NULL;
4240 + theacl->prevp = NULL;
4241 + theacl->entryp = NULL;
4242 + DEBUG(10,("Exiting sys_acl_init\n"));
4246 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4248 + struct acl_entry_link *theacl;
4249 + struct acl_entry_link *acl_entryp;
4250 + struct acl_entry_link *temp_entry;
4253 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4255 + theacl = acl_entryp = *pacl;
4257 + /* Get to the end of the acl before adding entry */
4259 + for(counting=0; counting < theacl->count; counting++){
4260 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4261 + temp_entry = acl_entryp;
4262 + acl_entryp = acl_entryp->nextp;
4265 + if(theacl->count != 0){
4266 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4267 + if(acl_entryp == NULL) {
4269 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4273 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4274 + acl_entryp->prevp = temp_entry;
4275 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4278 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4279 + if(*pentry == NULL) {
4281 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4285 + memset(*pentry,0,sizeof(struct new_acl_entry));
4286 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4287 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4288 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4289 + acl_entryp->nextp = NULL;
4291 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4295 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4297 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4298 + entry->ace_id->id_type = tagtype;
4299 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4300 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4303 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4305 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4306 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4307 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4311 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4313 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4314 + if(!(*permset & S_IXUSR) &&
4315 + !(*permset & S_IWUSR) &&
4316 + !(*permset & S_IRUSR) &&
4320 + entry->ace_access = *permset;
4321 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4322 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4326 +int sys_acl_valid( SMB_ACL_T theacl )
4329 + int group_obj = 0;
4330 + int other_obj = 0;
4331 + struct acl_entry_link *acl_entry;
4333 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4334 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4335 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4336 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4339 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4341 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4347 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4349 + struct acl_entry_link *acl_entry_link = NULL;
4350 + struct acl *file_acl = NULL;
4351 + struct acl *file_acl_temp = NULL;
4352 + struct acl_entry *acl_entry = NULL;
4353 + struct ace_id *ace_id = NULL;
4360 + DEBUG(10,("Entering sys_acl_set_file\n"));
4361 + DEBUG(10,("File name is %s\n",name));
4363 + /* AIX has no default ACL */
4364 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4367 + acl_length = BUFSIZ;
4368 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4370 + if(file_acl == NULL) {
4372 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4376 + memset(file_acl,0,BUFSIZ);
4378 + file_acl->acl_len = ACL_SIZ;
4379 + file_acl->acl_mode = S_IXACL;
4381 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4382 + acl_entry_link->entryp->ace_access >>= 6;
4383 + id_type = acl_entry_link->entryp->ace_id->id_type;
4386 + case SMB_ACL_USER_OBJ:
4387 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4389 + case SMB_ACL_GROUP_OBJ:
4390 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4392 + case SMB_ACL_OTHER:
4393 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4395 + case SMB_ACL_MASK:
4399 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4400 + acl_length += sizeof(struct acl_entry);
4401 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4402 + if(file_acl_temp == NULL) {
4403 + SAFE_FREE(file_acl);
4405 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4409 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4410 + SAFE_FREE(file_acl);
4411 + file_acl = file_acl_temp;
4414 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4415 + file_acl->acl_len += sizeof(struct acl_entry);
4416 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4417 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4419 + /* In order to use this, we'll need to wait until we can get denies */
4420 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4421 + acl_entry->ace_type = ACC_SPECIFY; */
4423 + acl_entry->ace_type = ACC_SPECIFY;
4425 + ace_id = acl_entry->ace_id;
4427 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4428 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4429 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4430 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4431 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4434 + rc = chacl(name,file_acl,file_acl->acl_len);
4435 + DEBUG(10,("errno is %d\n",errno));
4436 + DEBUG(10,("return code is %d\n",rc));
4437 + SAFE_FREE(file_acl);
4438 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4442 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4444 + struct acl_entry_link *acl_entry_link = NULL;
4445 + struct acl *file_acl = NULL;
4446 + struct acl *file_acl_temp = NULL;
4447 + struct acl_entry *acl_entry = NULL;
4448 + struct ace_id *ace_id = NULL;
4454 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4455 + acl_length = BUFSIZ;
4456 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4458 + if(file_acl == NULL) {
4460 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4464 + memset(file_acl,0,BUFSIZ);
4466 + file_acl->acl_len = ACL_SIZ;
4467 + file_acl->acl_mode = S_IXACL;
4469 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4470 + acl_entry_link->entryp->ace_access >>= 6;
4471 + id_type = acl_entry_link->entryp->ace_id->id_type;
4472 + DEBUG(10,("The id_type is %d\n",id_type));
4475 + case SMB_ACL_USER_OBJ:
4476 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4478 + case SMB_ACL_GROUP_OBJ:
4479 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4481 + case SMB_ACL_OTHER:
4482 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4484 + case SMB_ACL_MASK:
4488 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4489 + acl_length += sizeof(struct acl_entry);
4490 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4491 + if(file_acl_temp == NULL) {
4492 + SAFE_FREE(file_acl);
4494 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4498 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4499 + SAFE_FREE(file_acl);
4500 + file_acl = file_acl_temp;
4503 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4504 + file_acl->acl_len += sizeof(struct acl_entry);
4505 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4506 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4508 + /* In order to use this, we'll need to wait until we can get denies */
4509 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4510 + acl_entry->ace_type = ACC_SPECIFY; */
4512 + acl_entry->ace_type = ACC_SPECIFY;
4514 + ace_id = acl_entry->ace_id;
4516 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4517 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4518 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4519 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4520 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4523 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4524 + DEBUG(10,("errno is %d\n",errno));
4525 + DEBUG(10,("return code is %d\n",rc));
4526 + SAFE_FREE(file_acl);
4527 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4531 +int sys_acl_delete_def_file(const char *name)
4533 + /* AIX has no default ACL */
4537 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4539 + return(*permset & perm);
4542 +int sys_acl_free_text(char *text)
4547 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4549 + struct acl_entry_link *acl_entry_link;
4551 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4552 + SAFE_FREE(acl_entry_link->prevp->entryp);
4553 + SAFE_FREE(acl_entry_link->prevp);
4556 + SAFE_FREE(acl_entry_link->prevp->entryp);
4557 + SAFE_FREE(acl_entry_link->prevp);
4558 + SAFE_FREE(acl_entry_link->entryp);
4559 + SAFE_FREE(acl_entry_link);
4564 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4569 +#else /* No ACLs. */
4571 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4577 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4583 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4589 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4595 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4598 + return (SMB_ACL_T)NULL;
4601 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4604 + return (SMB_ACL_T)NULL;
4607 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4613 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4619 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4622 + return (permset & perm) ? 1 : 0;
4625 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4631 +int sys_acl_free_text(UNUSED(char *text))
4637 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4643 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4649 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4655 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4661 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4667 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4673 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4679 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4685 +int sys_acl_delete_def_file(UNUSED(const char *name))
4691 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4697 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4703 +#endif /* No ACLs. */
4705 +/************************************************************************
4706 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4708 +************************************************************************/
4710 +int no_acl_syscall_error(int err)
4712 +#if defined(ENOSYS)
4713 + if (err == ENOSYS) {
4717 +#if defined(ENOTSUP)
4718 + if (err == ENOTSUP) {
4724 --- old/lib/sysacls.h
4725 +++ new/lib/sysacls.h
4727 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4728 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4729 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4730 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4731 +#define slprintf snprintf
4733 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4734 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4735 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4736 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4737 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4738 +SMB_ACL_T sys_acl_get_fd(int fd);
4739 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4740 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4741 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4742 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4743 +SMB_ACL_T sys_acl_init(int count);
4744 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4745 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4746 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4747 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4748 +int sys_acl_valid(SMB_ACL_T theacl);
4749 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4750 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4751 +int sys_acl_delete_def_file(const char *name);
4752 +int sys_acl_free_text(char *text);
4753 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4754 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4757 @@ -58,7 +58,7 @@ BEGIN {
4761 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4762 +!/^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/ {
4768 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4770 int preserve_links = 0;
4771 int preserve_hard_links = 0;
4772 +int preserve_acls = 0;
4773 int preserve_perms = 0;
4774 int preserve_executability = 0;
4775 int preserve_devices = 0;
4776 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4777 char const *got_socketpair = "no ";
4778 char const *have_inplace = "no ";
4779 char const *hardlinks = "no ";
4780 + char const *acls = "no ";
4781 char const *links = "no ";
4782 char const *ipv6 = "no ";
4783 STRUCT_STAT *dumstat;
4784 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4788 +#ifdef SUPPORT_ACLS
4792 #ifdef SUPPORT_LINKS
4795 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4796 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4797 rprintf(f, "<http://rsync.samba.org/>\n");
4798 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4799 - "%shard links, %ssymlinks, batchfiles,\n",
4800 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4801 (int) (sizeof (OFF_T) * 8),
4802 - got_socketpair, hardlinks, links);
4803 + got_socketpair, hardlinks, acls, links);
4805 /* Note that this field may not have type ino_t. It depends
4806 * on the complicated interaction between largefile feature
4807 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4808 rprintf(F," -H, --hard-links preserve hard links\n");
4809 rprintf(F," -p, --perms preserve permissions\n");
4810 rprintf(F," -E, --executability preserve the file's executability\n");
4811 +#ifdef SUPPORT_ACLS
4812 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4814 rprintf(F," --chmod=CHMOD change destination permissions\n");
4815 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4816 rprintf(F," -g, --group preserve group\n");
4817 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4818 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4819 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4820 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4821 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4822 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4823 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4824 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4825 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4826 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4827 @@ -1068,6 +1080,23 @@ int parse_arguments(int *argc, const cha
4832 +#ifdef SUPPORT_ACLS
4833 + preserve_acls = preserve_perms = 1;
4836 + /* FIXME: this should probably be ignored with a
4837 + * warning and then countermeasures taken to
4838 + * restrict group and other access in the presence
4839 + * of any more restrictive ACLs, but this is safe
4841 + snprintf(err_buf,sizeof(err_buf),
4842 + "ACLs are not supported on this %s\n",
4843 + am_server ? "server" : "client");
4849 /* A large opt value means that set_refuse_options()
4850 * turned this option off. */
4851 @@ -1511,6 +1540,10 @@ void server_options(char **args,int *arg
4853 if (preserve_hard_links)
4855 +#ifdef SUPPORT_ACLS
4856 + if (preserve_acls)
4857 + argstr[x++] = 'A';
4864 @@ -46,6 +46,7 @@ extern int keep_partial;
4865 extern int checksum_seed;
4867 extern int delay_updates;
4868 +extern mode_t orig_umask;
4869 extern struct stats stats;
4870 extern char *log_format;
4871 extern char *tmpdir;
4872 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4873 int itemizing = am_daemon ? daemon_log_format_has_i
4874 : !am_server && log_format_has_i;
4875 int max_phase = protocol_version >= 29 ? 2 : 1;
4876 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4877 +#ifdef SUPPORT_ACLS
4878 + char *parent_dirname = "";
4883 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
4884 * mode based on the local permissions and some heuristics. */
4885 if (!preserve_perms) {
4886 int exists = fd1 != -1;
4887 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4888 +#ifdef SUPPORT_ACLS
4889 + char *dn = file->dirname ? file->dirname : ".";
4890 + if (parent_dirname != dn
4891 + && strcmp(parent_dirname, dn) != 0) {
4892 + dflt_perms = default_perms_for_dir(dn);
4893 + parent_dirname = dn;
4896 + file->mode = dest_mode(file->mode, st.st_mode,
4897 + dflt_perms, exists);
4900 /* We now check to see if we are writing file "inplace" */
4906 extern int daemon_log_format_has_i;
4907 +extern int preserve_acls;
4908 extern int preserve_perms;
4909 extern int preserve_executability;
4910 extern int preserve_times;
4911 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
4913 /* This is only called when we aren't preserving permissions. Figure out what
4914 * the permissions should be and return them merged back into the mode. */
4915 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4916 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
4919 /* If the file already exists, we'll return the local permissions,
4920 * possibly tweaked by the --executability option. */
4921 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4922 cur_mode |= (cur_mode & 0444) >> 2;
4925 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
4926 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
4927 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
4928 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
4929 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
4930 @@ -203,6 +205,13 @@ int set_file_attrs(char *fname, struct f
4934 +#ifdef SUPPORT_ACLS
4935 + /* It's OK to call set_acl() now, even for a dir, as the generator
4936 + * will enable owner-writability using chmod, if necessary. */
4937 + if (preserve_acls && set_acl(fname, file, st->st_mode) == 0)
4942 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
4943 int ret = do_chmod(fname, file->mode);
4946 @@ -658,6 +658,20 @@ struct chmod_mode_struct;
4948 #define UNUSED(x) x __attribute__((__unused__))
4950 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4951 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4952 +#define SUPPORT_ACLS 1
4955 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4956 +#define ACLS_NEED_MASK 1
4959 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
4960 +#include <sys/acl.h>
4962 +#include "smb_acls.h"
4966 /* We have replacement versions of these if they're missing. */
4969 @@ -321,6 +321,7 @@ to the detailed description below for a
4970 -H, --hard-links preserve hard links
4971 -p, --perms preserve permissions
4972 -E, --executability preserve executability
4973 + -A, --acls preserve ACLs (implies -p) [non-standard]
4974 --chmod=CHMOD change destination permissions
4975 -o, --owner preserve owner (super-user only)
4976 -g, --group preserve group
4977 @@ -742,7 +743,9 @@ quote(itemize(
4978 permissions, though the bf(--executability) option might change just
4979 the execute permission for the file.
4980 it() New files get their "normal" permission bits set to the source
4981 - file's permissions masked with the receiving end's umask setting, and
4982 + file's permissions masked with the receiving directory's default
4983 + permissions (either the receiving process's umask, or the permissions
4984 + specified via the destination directory's default ACL), and
4985 their special permission bits disabled except in the case where a new
4986 directory inherits a setgid bit from its parent directory.
4988 @@ -773,9 +776,11 @@ The preservation of the destination's se
4989 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
4990 versions erroneously preserved the three special permission bits for
4991 newly-created files when bf(--perms) was off, while overriding the
4992 -destination's setgid bit setting on a newly-created directory. (Keep in
4993 -mind that it is the version of the receiving rsync that affects this
4995 +destination's setgid bit setting on a newly-created directory. Default ACL
4996 +observance was added to the ACL patch for rsync 2.6.7, so older (or
4997 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
4998 +(Keep in mind that it is the version of the receiving rsync that affects
5001 dit(bf(-E, --executability)) This option causes rsync to preserve the
5002 executability (or non-executability) of regular files when bf(--perms) is
5003 @@ -793,6 +798,10 @@ quote(itemize(
5005 If bf(--perms) is enabled, this option is ignored.
5007 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5008 +ACLs to be the same as the source ACLs. This nonstandard option only
5009 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5011 dit(bf(--chmod)) This option tells rsync to apply one or more
5012 comma-separated "chmod" strings to the permission of the files in the
5013 transfer. The resulting value is treated as though it was the permissions
5018 + Unix SMB/Netbios implementation.
5020 + Portable SMB ACL interface
5021 + Copyright (C) Jeremy Allison 2000
5023 + This program is free software; you can redistribute it and/or modify
5024 + it under the terms of the GNU General Public License as published by
5025 + the Free Software Foundation; either version 2 of the License, or
5026 + (at your option) any later version.
5028 + This program is distributed in the hope that it will be useful,
5029 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5030 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5031 + GNU General Public License for more details.
5033 + You should have received a copy of the GNU General Public License
5034 + along with this program; if not, write to the Free Software
5035 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5038 +#ifndef _SMB_ACLS_H
5039 +#define _SMB_ACLS_H
5041 +#if defined HAVE_POSIX_ACLS
5043 +/* This is an identity mapping (just remove the SMB_). */
5045 +#define SMB_ACL_TAG_T acl_tag_t
5046 +#define SMB_ACL_TYPE_T acl_type_t
5047 +#define SMB_ACL_PERMSET_T acl_permset_t
5048 +#define SMB_ACL_PERM_T acl_perm_t
5049 +#define SMB_ACL_READ ACL_READ
5050 +#define SMB_ACL_WRITE ACL_WRITE
5051 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5053 +/* Types of ACLs. */
5054 +#define SMB_ACL_USER ACL_USER
5055 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5056 +#define SMB_ACL_GROUP ACL_GROUP
5057 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5058 +#define SMB_ACL_OTHER ACL_OTHER
5059 +#define SMB_ACL_MASK ACL_MASK
5061 +#define SMB_ACL_T acl_t
5063 +#define SMB_ACL_ENTRY_T acl_entry_t
5065 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5066 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5068 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5069 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5071 +#elif defined HAVE_TRU64_ACLS
5073 +/* This is for DEC/Compaq Tru64 UNIX */
5075 +#define SMB_ACL_TAG_T acl_tag_t
5076 +#define SMB_ACL_TYPE_T acl_type_t
5077 +#define SMB_ACL_PERMSET_T acl_permset_t
5078 +#define SMB_ACL_PERM_T acl_perm_t
5079 +#define SMB_ACL_READ ACL_READ
5080 +#define SMB_ACL_WRITE ACL_WRITE
5081 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5083 +/* Types of ACLs. */
5084 +#define SMB_ACL_USER ACL_USER
5085 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5086 +#define SMB_ACL_GROUP ACL_GROUP
5087 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5088 +#define SMB_ACL_OTHER ACL_OTHER
5089 +#define SMB_ACL_MASK ACL_MASK
5091 +#define SMB_ACL_T acl_t
5093 +#define SMB_ACL_ENTRY_T acl_entry_t
5095 +#define SMB_ACL_FIRST_ENTRY 0
5096 +#define SMB_ACL_NEXT_ENTRY 1
5098 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5099 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5101 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5103 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5104 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5107 +/* SVR4.2 ES/MP ACLs */
5108 +typedef int SMB_ACL_TAG_T;
5109 +typedef int SMB_ACL_TYPE_T;
5110 +typedef ushort *SMB_ACL_PERMSET_T;
5111 +typedef ushort SMB_ACL_PERM_T;
5112 +#define SMB_ACL_READ 4
5113 +#define SMB_ACL_WRITE 2
5114 +#define SMB_ACL_EXECUTE 1
5116 +/* Types of ACLs. */
5117 +#define SMB_ACL_USER USER
5118 +#define SMB_ACL_USER_OBJ USER_OBJ
5119 +#define SMB_ACL_GROUP GROUP
5120 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5121 +#define SMB_ACL_OTHER OTHER_OBJ
5122 +#define SMB_ACL_MASK CLASS_OBJ
5124 +typedef struct SMB_ACL_T {
5128 + struct acl acl[1];
5131 +typedef struct acl *SMB_ACL_ENTRY_T;
5133 +#define SMB_ACL_FIRST_ENTRY 0
5134 +#define SMB_ACL_NEXT_ENTRY 1
5136 +#define SMB_ACL_TYPE_ACCESS 0
5137 +#define SMB_ACL_TYPE_DEFAULT 1
5139 +#elif defined HAVE_HPUX_ACLS
5142 + * Based on the Solaris & UnixWare code.
5146 +#include <sys/aclv.h>
5148 +/* SVR4.2 ES/MP ACLs */
5149 +typedef int SMB_ACL_TAG_T;
5150 +typedef int SMB_ACL_TYPE_T;
5151 +typedef ushort *SMB_ACL_PERMSET_T;
5152 +typedef ushort SMB_ACL_PERM_T;
5153 +#define SMB_ACL_READ 4
5154 +#define SMB_ACL_WRITE 2
5155 +#define SMB_ACL_EXECUTE 1
5157 +/* Types of ACLs. */
5158 +#define SMB_ACL_USER USER
5159 +#define SMB_ACL_USER_OBJ USER_OBJ
5160 +#define SMB_ACL_GROUP GROUP
5161 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5162 +#define SMB_ACL_OTHER OTHER_OBJ
5163 +#define SMB_ACL_MASK CLASS_OBJ
5165 +typedef struct SMB_ACL_T {
5169 + struct acl acl[1];
5172 +typedef struct acl *SMB_ACL_ENTRY_T;
5174 +#define SMB_ACL_FIRST_ENTRY 0
5175 +#define SMB_ACL_NEXT_ENTRY 1
5177 +#define SMB_ACL_TYPE_ACCESS 0
5178 +#define SMB_ACL_TYPE_DEFAULT 1
5180 +#elif defined HAVE_IRIX_ACLS
5182 +#define SMB_ACL_TAG_T acl_tag_t
5183 +#define SMB_ACL_TYPE_T acl_type_t
5184 +#define SMB_ACL_PERMSET_T acl_permset_t
5185 +#define SMB_ACL_PERM_T acl_perm_t
5186 +#define SMB_ACL_READ ACL_READ
5187 +#define SMB_ACL_WRITE ACL_WRITE
5188 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5190 +/* Types of ACLs. */
5191 +#define SMB_ACL_USER ACL_USER
5192 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5193 +#define SMB_ACL_GROUP ACL_GROUP
5194 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5195 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5196 +#define SMB_ACL_MASK ACL_MASK
5198 +typedef struct SMB_ACL_T {
5204 +#define SMB_ACL_ENTRY_T acl_entry_t
5206 +#define SMB_ACL_FIRST_ENTRY 0
5207 +#define SMB_ACL_NEXT_ENTRY 1
5209 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5210 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5212 +#elif defined HAVE_AIX_ACLS
5214 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5216 +#include "/usr/include/acl.h"
5218 +typedef uint *SMB_ACL_PERMSET_T;
5220 +struct acl_entry_link{
5221 + struct acl_entry_link *prevp;
5222 + struct new_acl_entry *entryp;
5223 + struct acl_entry_link *nextp;
5227 +struct new_acl_entry{
5228 + unsigned short ace_len;
5229 + unsigned short ace_type;
5230 + unsigned int ace_access;
5231 + struct ace_id ace_id[1];
5234 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5235 +#define SMB_ACL_T struct acl_entry_link*
5237 +#define SMB_ACL_TAG_T unsigned short
5238 +#define SMB_ACL_TYPE_T int
5239 +#define SMB_ACL_PERM_T uint
5240 +#define SMB_ACL_READ S_IRUSR
5241 +#define SMB_ACL_WRITE S_IWUSR
5242 +#define SMB_ACL_EXECUTE S_IXUSR
5244 +/* Types of ACLs. */
5245 +#define SMB_ACL_USER ACEID_USER
5246 +#define SMB_ACL_USER_OBJ 3
5247 +#define SMB_ACL_GROUP ACEID_GROUP
5248 +#define SMB_ACL_GROUP_OBJ 4
5249 +#define SMB_ACL_OTHER 5
5250 +#define SMB_ACL_MASK 6
5253 +#define SMB_ACL_FIRST_ENTRY 1
5254 +#define SMB_ACL_NEXT_ENTRY 2
5256 +#define SMB_ACL_TYPE_ACCESS 0
5257 +#define SMB_ACL_TYPE_DEFAULT 1
5259 +#else /* No ACLs. */
5261 +/* No ACLS - fake it. */
5262 +#define SMB_ACL_TAG_T int
5263 +#define SMB_ACL_TYPE_T int
5264 +#define SMB_ACL_PERMSET_T mode_t
5265 +#define SMB_ACL_PERM_T mode_t
5266 +#define SMB_ACL_READ S_IRUSR
5267 +#define SMB_ACL_WRITE S_IWUSR
5268 +#define SMB_ACL_EXECUTE S_IXUSR
5270 +/* Types of ACLs. */
5271 +#define SMB_ACL_USER 0
5272 +#define SMB_ACL_USER_OBJ 1
5273 +#define SMB_ACL_GROUP 2
5274 +#define SMB_ACL_GROUP_OBJ 3
5275 +#define SMB_ACL_OTHER 4
5276 +#define SMB_ACL_MASK 5
5278 +typedef struct SMB_ACL_T {
5282 +typedef struct SMB_ACL_ENTRY_T {
5284 +} *SMB_ACL_ENTRY_T;
5286 +#define SMB_ACL_FIRST_ENTRY 0
5287 +#define SMB_ACL_NEXT_ENTRY 1
5289 +#define SMB_ACL_TYPE_ACCESS 0
5290 +#define SMB_ACL_TYPE_DEFAULT 1
5292 +#endif /* No ACLs. */
5293 +#endif /* _SMB_ACLS_H */
5294 --- old/testsuite/default-acls.test
5295 +++ new/testsuite/default-acls.test
5299 +# This program is distributable under the terms of the GNU GPL see
5302 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5304 +. $srcdir/testsuite/rsync.fns
5306 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5307 +setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5309 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5311 + todir="$scratchdir/$1"
5313 + # FIXME This doesn't work on solaris...
5314 + setfacl -k "$todir"
5315 + [ "$2" ] && setfacl -dm "$2" "$todir"
5316 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5317 + # even though the directory itself is outside the transfer
5318 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5319 + check_perms "$todir/to" $4 "Target $1"
5320 + check_perms "$todir/to/dir" $4 "Target $1"
5321 + check_perms "$todir/to/file" $3 "Target $1"
5322 + check_perms "$todir/to/program" $4 "Target $1"
5323 + # Make sure get_local_name doesn't mess us up when transferring only one file
5324 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5325 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5326 + # Make sure we obey default ACLs when not transferring a regular file
5327 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5328 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5331 +mkdir "$scratchdir/dir"
5332 +echo "File!" >"$scratchdir/file"
5333 +echo "#!/bin/sh" >"$scratchdir/program"
5334 +chmod 777 "$scratchdir/dir"
5335 +chmod 666 "$scratchdir/file"
5336 +chmod 777 "$scratchdir/program"
5338 +# Test some target directories
5340 +testit da777 u::rwx,g::rwx,o::rwx rw-rw-rw- rwxrwxrwx
5341 +testit da775 u::rwx,g::rwx,o::r-x rw-rw-r-- rwxrwxr-x
5342 +testit da750 u::rwx,g::r-x,o::--- rw-r----- rwxr-x---
5343 +testit da770mask u::rwx,g::---,m::rwx,o::--- rw-rw---- rwxrwx---
5344 +testit noda1 '' rw------- rwx------
5346 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5348 +testit noda3 '' rw-r--r-- rwxr-xr-x
5356 extern int preserve_uid;
5357 extern int preserve_gid;
5358 +extern int preserve_acls;
5359 extern int numeric_ids;
5362 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5366 - if (preserve_uid) {
5367 + if (preserve_uid || preserve_acls) {
5369 /* we send sequences of uid/byte-length/name */
5370 for (list = uidlist; list; list = list->next) {
5371 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5375 - if (preserve_gid) {
5376 + if (preserve_gid || preserve_acls) {
5378 for (list = gidlist; list; list = list->next) {
5380 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5384 - if (preserve_uid && !numeric_ids) {
5385 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5386 /* read the uid list */
5387 while ((id = read_int(f)) != 0) {
5388 int len = read_byte(f);
5389 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5393 - if (preserve_gid && !numeric_ids) {
5394 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5395 /* read the gid list */
5396 while ((id = read_int(f)) != 0) {
5397 int len = read_byte(f);
5398 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5402 +#ifdef SUPPORT_ACLS
5403 + if (preserve_acls && !numeric_ids) {
5405 + while ((id = next_acl_uid(flist)) != NULL)
5406 + *id = match_uid(*id);
5407 + while ((id = next_acl_gid(flist)) != NULL)
5408 + *id = match_gid(*id);
5412 /* Now convert all the uids/gids from sender values to our values. */
5413 if (am_root && preserve_uid && !numeric_ids) {
5414 for (i = 0; i < flist->count; i++)