1 After applying this patch, run these commands for a successful build:
5 ./configure --enable-acl-support
9 The program currently complains when the --acls (-A) option is used to copy
10 from a disk that doesn't support ACLs. This should be changed to silently
11 notice that no ACLs are available to copy. Of course, trying to write out
12 ACLs to a non-ACL-supporting disk should complain.
14 TODO: we need to cache the return from default_mode_for_dir_acl() so that
15 it only gets re-called when the destination directory changes (and does not
16 get called if dry_run > 1).
18 --- orig/Makefile.in 2006-01-14 08:14:29
19 +++ Makefile.in 2005-11-07 04:31:05
20 @@ -25,15 +25,15 @@ VERSION=@VERSION@
24 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
25 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
26 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
27 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
28 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
29 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
30 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
31 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
32 main.o checksum.o match.o syscall.o log.o backup.o
33 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
34 - fileio.o batch.o clientname.o chmod.o
35 + fileio.o batch.o clientname.o chmod.o acls.o
36 OBJS3=progress.o pipe.o
37 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
38 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
39 --- orig/acls.c 2006-01-31 03:29:49
40 +++ acls.c 2006-01-31 03:29:49
42 +/* -*- c-file-style: "linux" -*-
43 + Copyright (C) Andrew Tridgell 1996
44 + Copyright (C) Paul Mackerras 1996
46 + This program is free software; you can redistribute it and/or modify
47 + it under the terms of the GNU General Public License as published by
48 + the Free Software Foundation; either version 2 of the License, or
49 + (at your option) any later version.
51 + This program is distributed in the hope that it will be useful,
52 + but WITHOUT ANY WARRANTY; without even the implied warranty of
53 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 + GNU General Public License for more details.
56 + You should have received a copy of the GNU General Public License
57 + along with this program; if not, write to the Free Software
58 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
61 +/* handle passing ACLs between systems */
64 +#include "lib/sysacls.h"
68 +extern int preserve_acls;
71 +extern int orig_umask;
76 + SMB_ACL_TAG_T tag_type;
85 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
87 +static void expand_rsync_acl(rsync_acl *racl)
89 + /* First time through, 0 <= 0, so list is expanded.
90 + * (Diabolical, rsync guys!) */
91 + if (racl->malloced <= racl->count) {
93 + size_t new_size = racl->malloced + 10;
94 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
96 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
97 + (double) new_size * sizeof racl->races[0],
98 + racl->races ? "" : " not");
101 + racl->races = new_ptr;
102 + racl->malloced = new_size;
105 + out_of_memory("expand_rsync_acl");
109 +static void rsync_acl_free(rsync_acl *racl)
112 + racl->races = NULL;
114 + racl->malloced = 0;
117 +static int rsync_ace_sorter(const void *r1, const void *r2)
119 + rsync_ace *race1 = (rsync_ace *)r1;
120 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
121 + id_t rid1 = race1->id;
122 + rsync_ace *race2 = (rsync_ace *)r2;
123 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
124 + id_t rid2 = race2->id;
125 + /* start at the extrema */
126 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
128 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
131 + if (rtag1 == SMB_ACL_OTHER)
133 + if (rtag2 == SMB_ACL_OTHER)
135 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
136 + if (rtag1 == SMB_ACL_USER) {
138 + case SMB_ACL_GROUP:
139 + case SMB_ACL_GROUP_OBJ:
140 + case SMB_ACL_OTHER:
144 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
146 + if (rtag2 == SMB_ACL_USER)
148 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
149 + if (rtag1 == SMB_ACL_GROUP_OBJ)
151 + if (rtag2 == SMB_ACL_GROUP_OBJ)
153 + /* only SMB_ACL_GROUPs left */
154 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
157 +static void sort_rsync_acl(rsync_acl *racl)
161 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
162 + &rsync_ace_sorter);
165 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
167 + SMB_ACL_ENTRY_T entry;
169 + const char *errfun;
170 + *racl = rsync_acl_initializer;
171 + errfun = "sys_acl_get_entry";
172 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
174 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
175 + SMB_ACL_PERMSET_T permset;
178 + expand_rsync_acl(racl);
179 + race = &racl->races[racl->count++];
180 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
181 + errfun = "sys_acl_get_tag_type";
184 + if ((rc = sys_acl_get_permset(entry, &permset))) {
185 + errfun = "sys_acl_get_tag_type";
188 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
189 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
190 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
191 + switch (race->tag_type) {
193 + case SMB_ACL_GROUP:
198 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
199 + errfun = "sys_acl_get_tag_type";
203 + race->id = *((id_t *)qualifier);
204 + sys_acl_free_qualifier(qualifier, race->tag_type);
207 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
208 + errfun, strerror(errno));
209 + rsync_acl_free(racl);
212 + sort_rsync_acl(racl);
216 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
218 + rsync_ace *race1, *race2;
219 + size_t count = racl1->count;
220 + if (count != racl2->count)
222 + race1 = racl1->races;
223 + race2 = racl2->races;
224 + for (; count--; race1++, race2++) {
225 + if (race1->tag_type != race2->tag_type
226 + || race1->access != race2->access
227 + || ((race1->tag_type == SMB_ACL_USER
228 + || race1->tag_type == SMB_ACL_GROUP)
229 + && race1->id != race2->id))
241 +static rsync_acl_list _rsync_acl_lists[] = {
242 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
243 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
246 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
248 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
249 + : &_rsync_acl_lists[1];
252 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
254 + /* First time through, 0 <= 0, so list is expanded.
255 + * (Diabolical, rsync guys!) */
256 + if (racl_list->malloced <= racl_list->count) {
257 + rsync_acl *new_ptr;
259 + if (racl_list->malloced < 1000)
260 + new_size = racl_list->malloced + 1000;
262 + new_size = racl_list->malloced * 2;
263 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
264 + if (verbose >= 3) {
265 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
266 + (double) new_size * sizeof racl_list->racls[0],
267 + racl_list->racls ? "" : " not");
270 + racl_list->racls = new_ptr;
271 + racl_list->malloced = new_size;
273 + if (!racl_list->racls)
274 + out_of_memory("expand_rsync_acl_list");
279 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
281 + /* Run this in reverse, so references are freed before referents,
282 + * although not currently necessary. */
283 + while (racl_list->count--) {
284 + rsync_acl *racl = &racl_list->racls[racl_list->count];
286 + rsync_acl_free(racl);
288 + free(racl_list->racls);
289 + racl_list->racls = NULL;
290 + racl_list->malloced = 0;
294 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
295 + const rsync_acl_list *racl_list,
296 + const rsync_acl *racl)
298 + static int access_match = -1, default_match = -1;
299 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
300 + &access_match : &default_match;
301 + size_t count = racl_list->count;
302 + /* If this is the first time through or we didn't match the last
303 + * time, then start at the end of the list, which should be the
304 + * best place to start hunting. */
306 + *match = racl_list->count - 1;
308 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
311 + *match = racl_list->count - 1;
317 +/* The general strategy with the tag_type <-> character mapping is that
318 + * lowercase implies that no qualifier follows, where uppercase does.
319 + * A similar idiom for the acl type (access or default) itself, but
320 + * lowercase in this instance means there's no ACL following, so the
321 + * ACL is a repeat, so the receiver should reuse the last of the same
324 +static void send_rsync_acl(int f, const rsync_acl *racl)
327 + size_t count = racl->count;
328 + write_int(f, count);
329 + for (race = racl->races; count--; race++) {
331 + switch (race->tag_type) {
332 + case SMB_ACL_USER_OBJ:
338 + case SMB_ACL_GROUP_OBJ:
341 + case SMB_ACL_GROUP:
344 + case SMB_ACL_OTHER:
352 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
357 + write_byte(f, race->access);
358 + if (isupper((int)ch)) {
359 + write_int(f, race->id);
360 + /* FIXME: sorta wasteful: we should maybe buffer as
361 + * many ids as max(ACL_USER + ACL_GROUP) objects to
362 + * keep from making so many calls. */
371 +static rsync_acl _curr_rsync_acls[2];
374 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
376 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
377 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
378 + "unknown SMB_ACL_TYPE_T";
381 +/* Generate the ACL(s) for this flist entry;
382 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
384 +int make_acl(const struct file_struct *file, const char *fname)
386 + SMB_ACL_TYPE_T *type,
387 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
388 + rsync_acl *curr_racl;
389 + if (!preserve_acls || S_ISLNK(file->mode))
391 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
392 + type < &types[0] + sizeof types / sizeof types[0]
393 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
394 + type++, curr_racl++) {
397 + *curr_racl = rsync_acl_initializer;
398 + if (!(sacl = sys_acl_get_file(fname, *type))) {
399 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
400 + fname, str_acl_type(*type), strerror(errno));
403 + ok = unpack_smb_acl(curr_racl, sacl);
404 + sys_acl_free_acl(sacl);
411 +/* Send the make_acl()-generated ACLs for this flist entry,
412 + * or clean up after an flist entry that's not being sent (f == -1). */
414 +void send_acl(const struct file_struct *file, int f)
416 + SMB_ACL_TYPE_T *type,
417 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
418 + rsync_acl *curr_racl;
419 + if (!preserve_acls || S_ISLNK(file->mode))
421 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
422 + type < &types[0] + sizeof types / sizeof types[0]
423 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
424 + type++, curr_racl++) {
426 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
428 + rsync_acl_free(curr_racl);
431 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
433 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
434 + write_int(f, index);
435 + rsync_acl_free(curr_racl);
437 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
438 + send_rsync_acl(f, curr_racl);
439 + expand_rsync_acl_list(racl_list);
440 + racl_list->racls[racl_list->count++] = *curr_racl;
445 +/* The below stuff is only used by the receiver: */
447 +/* structure to hold index to rsync_acl_list member corresponding to
448 + * flist->files[i] */
451 + const struct file_struct *file;
458 + file_acl_index *fileaclidxs;
459 +} file_acl_index_list;
461 +static file_acl_index_list _file_acl_index_lists[] = {
462 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
463 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
466 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
468 + return type == SMB_ACL_TYPE_ACCESS ?
469 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
472 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
474 + /* First time through, 0 <= 0, so list is expanded.
475 + * (Diabolical, rsync guys!) */
476 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
477 + file_acl_index *new_ptr;
479 + if (fileaclidx_list->malloced < 1000)
480 + new_size = fileaclidx_list->malloced + 1000;
482 + new_size = fileaclidx_list->malloced * 2;
483 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
484 + if (verbose >= 3) {
485 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
486 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
487 + fileaclidx_list->fileaclidxs ? "" : " not");
490 + fileaclidx_list->fileaclidxs = new_ptr;
491 + fileaclidx_list->malloced = new_size;
493 + if (!fileaclidx_list->fileaclidxs)
494 + out_of_memory("expand_file_acl_index_list");
499 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
501 + free(fileaclidx_list->fileaclidxs);
502 + fileaclidx_list->fileaclidxs = NULL;
503 + fileaclidx_list->malloced = 0;
507 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
515 +static smb_acl_list _smb_acl_lists[] = {
516 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
517 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
520 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
522 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
523 + &_smb_acl_lists[1];
526 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
528 + /* First time through, 0 <= 0, so list is expanded.
529 + * (Diabolical, rsync guys!) */
530 + if (sacl_list->malloced <= sacl_list->count) {
531 + SMB_ACL_T *new_ptr;
533 + if (sacl_list->malloced < 1000)
534 + new_size = sacl_list->malloced + 1000;
536 + new_size = sacl_list->malloced * 2;
537 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
538 + if (verbose >= 3) {
539 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
540 + (double) new_size * sizeof sacl_list->sacls[0],
541 + sacl_list->sacls ? "" : " not");
544 + sacl_list->sacls = new_ptr;
545 + sacl_list->malloced = new_size;
547 + if (!sacl_list->sacls)
548 + out_of_memory("expand_smb_acl_list");
553 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
555 + smb_acl_list *sacl_list = smb_acl_lists(type);
556 + SMB_ACL_T *sacl = sacl_list->sacls;
557 + while (sacl_list->count--) {
559 + sys_acl_free_acl(*sacl++);
561 + free(sacl_list->sacls);
562 + sacl_list->sacls = NULL;
563 + sacl_list->malloced = 0;
567 +/* build an SMB_ACL_T corresponding to an rsync_acl */
568 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
570 + size_t count = racl->count;
571 + rsync_ace *race = racl->races;
572 + const char *errfun = NULL;
573 + *smb_acl = sys_acl_init(count);
575 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
579 + for (; count--; race++) {
580 + SMB_ACL_ENTRY_T entry;
581 + SMB_ACL_PERMSET_T permset;
582 + if (sys_acl_create_entry(smb_acl, &entry)) {
583 + errfun = "sys_acl_create)";
586 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
587 + errfun = "sys_acl_set_tag";
590 + if (race->tag_type == SMB_ACL_USER ||
591 + race->tag_type == SMB_ACL_GROUP)
592 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
593 + errfun = "sys_acl_set_qualfier";
596 + if (sys_acl_get_permset(entry, &permset)) {
597 + errfun = "sys_acl_get_permset";
600 + if (sys_acl_clear_perms(permset)) {
601 + errfun = "sys_acl_clear_perms";
604 + if (race->access & 4)
605 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
606 + errfun = "sys_acl_add_perm";
609 + if (race->access & 2)
610 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
611 + errfun = "sys_acl_add_perm";
614 + if (race->access & 1)
615 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
616 + errfun = "sys_acl_add_perm";
619 + if (sys_acl_set_permset(entry, permset)) {
620 + errfun = "sys_acl_set_permset";
625 + sys_acl_free_acl(*smb_acl);
626 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
633 +static void receive_rsync_acl(rsync_acl *racl, int f)
636 + uchar required_mask_perm = 0;
638 + BOOL saw_mask = False;
639 + BOOL saw_user_obj = False, saw_group_obj = False,
641 + size_t count = read_int(f);
646 + uchar tag = read_byte(f);
647 + expand_rsync_acl(racl);
648 + race = &racl->races[racl->count++];
651 + race->tag_type = SMB_ACL_USER_OBJ;
652 + saw_user_obj = True;
655 + race->tag_type = SMB_ACL_USER;
658 + race->tag_type = SMB_ACL_GROUP_OBJ;
659 + saw_group_obj = True;
662 + race->tag_type = SMB_ACL_GROUP;
665 + race->tag_type = SMB_ACL_OTHER;
669 + race->tag_type = SMB_ACL_MASK;
673 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
675 + exit_cleanup(RERR_STREAMIO);
677 + race->access = read_byte(f);
678 + if (race->access & ~ (4 | 2 | 1)) {
679 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
681 + exit_cleanup(RERR_STREAMIO);
683 + if (race->tag_type == SMB_ACL_USER ||
684 + race->tag_type == SMB_ACL_GROUP) {
685 + race->id = read_int(f);
687 + required_mask_perm |= race->access;
691 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
692 + required_mask_perm |= race->access;
696 + if (!saw_user_obj) {
697 + expand_rsync_acl(racl);
698 + race = &racl->races[racl->count++];
699 + race->tag_type = SMB_ACL_USER_OBJ;
702 + if (!saw_group_obj) {
703 + expand_rsync_acl(racl);
704 + race = &racl->races[racl->count++];
705 + race->tag_type = SMB_ACL_GROUP_OBJ;
709 + expand_rsync_acl(racl);
710 + race = &racl->races[racl->count++];
711 + race->tag_type = SMB_ACL_OTHER;
716 + expand_rsync_acl(racl);
717 + race = &racl->races[racl->count++];
718 + race->tag_type = SMB_ACL_MASK;
719 + race->access = required_mask_perm;
722 + /* If we, a system without ACLS_NEED_MASK, received data from a
723 + * system that has masks, throw away the extraneous CLASS_OBJs. */
724 + if (saw_mask && racl->count == 4) {
725 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
728 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
729 + if (p->tag_type == SMB_ACL_MASK)
731 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
732 + group_obj_race = p;
734 + if (mask_race == NULL || group_obj_race == NULL) {
735 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
736 + "and one's ACL_MASK but missing "
737 + "either it or ACL_GROUP_OBJ, "
738 + "when pruning ACL\n");
740 + /* mask off group perms with it first */
741 + group_obj_race->access &= mask_race->access;
742 + /* dump mask_race; re-slot any followers-on */
744 + if (mask_race != &racl->races[racl->count]) {
745 + *mask_race = racl->races[racl->count];
746 + saw_user_obj = False; /* force re-sort */
752 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
754 + if (!(saw_user_obj && saw_group_obj && saw_other))
756 + sort_rsync_acl(racl);
759 +/* receive and build the rsync_acl_lists */
761 +void receive_acl(struct file_struct *file, int f)
763 + SMB_ACL_TYPE_T *type,
764 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
766 + if (!preserve_acls || S_ISLNK(file->mode))
768 + fname = f_name(file, NULL);
769 + for (type = &types[0];
770 + type < &types[0] + sizeof types / sizeof types[0]
771 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
773 + file_acl_index_list *fileaclidx_list =
774 + file_acl_index_lists(*type);
776 + expand_file_acl_index_list(fileaclidx_list);
778 + tag = read_byte(f);
779 + if (tag == 'A' || tag == 'a') {
780 + if (*type != SMB_ACL_TYPE_ACCESS) {
781 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
783 + exit_cleanup(RERR_STREAMIO);
785 + } else if (tag == 'D' || tag == 'd') {
786 + if (*type == SMB_ACL_TYPE_ACCESS) {
787 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
789 + exit_cleanup(RERR_STREAMIO);
792 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
794 + exit_cleanup(RERR_STREAMIO);
796 + if (tag == 'A' || tag == 'D') {
797 + rsync_acl racl = rsync_acl_initializer;
798 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
799 + smb_acl_list *sacl_list = smb_acl_lists(*type);
800 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
801 + aclidx = racl_list->count;
802 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
804 + receive_rsync_acl(&racl, f);
805 + expand_rsync_acl_list(racl_list);
806 + racl_list->racls[racl_list->count++] = racl;
807 + expand_smb_acl_list(sacl_list);
808 + sacl_list->sacls[sacl_list->count++] = NULL;
810 + int index = read_int(f);
811 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
812 + if ((size_t) index >= racl_list->count) {
813 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
815 + str_acl_type(*type),
817 + exit_cleanup(RERR_STREAMIO);
819 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
821 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
827 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
829 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
830 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
831 + return fileaclidx1->file == fileaclidx2->file ? 0 :
832 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
835 +void sort_file_acl_index_lists()
837 + SMB_ACL_TYPE_T *type,
838 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
839 + if (!preserve_acls)
841 + for (type = &types[0];
842 + type < &types[0] + sizeof types / sizeof types[0];
845 + file_acl_index_list *fileaclidx_list =
846 + file_acl_index_lists(*type);
847 + if (!fileaclidx_list->count)
849 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
850 + sizeof fileaclidx_list->fileaclidxs[0],
851 + &file_acl_index_list_sorter);
855 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
856 + const struct file_struct *file) {
857 + int low = 0, high = fileaclidx_list->count;
858 + const struct file_struct *file_mid;
862 + int mid = (high + low) / 2;
863 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
864 + if (file_mid == file)
865 + return fileaclidx_list->fileaclidxs[mid].aclidx;
866 + if (file_mid > file)
870 + } while (low < high);
872 + file_mid = fileaclidx_list->fileaclidxs[low].file;
873 + if (file_mid == file)
874 + return fileaclidx_list->fileaclidxs[low].aclidx;
877 + "find_file_acl_index: can't find entry for file in list\n");
878 + exit_cleanup(RERR_STREAMIO);
882 +/* for duplicating ACLs on backups when using backup_dir */
884 +int dup_acl(const char *orig, const char *bak, mode_t mode)
886 + SMB_ACL_TYPE_T *type,
887 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
889 + if (!preserve_acls)
891 + for (type = &types[0];
892 + type < &types[0] + sizeof types / sizeof types[0]
893 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
895 + SMB_ACL_T sacl_orig, sacl_bak;
896 + rsync_acl racl_orig, racl_bak;
897 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
898 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
899 + orig, str_acl_type(*type), strerror(errno));
903 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
904 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
905 + bak, str_acl_type(*type), strerror(errno));
907 + /* try to forge on through */
909 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
911 + goto out_with_sacls;
914 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
916 + goto out_with_one_racl;
918 + if (rsync_acls_equal(&racl_orig, &racl_bak))
921 + ; /* presume they're unequal */
923 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
924 + if (-1 == sys_acl_delete_def_file(bak)) {
925 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
926 + bak, strerror(errno));
929 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
930 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
931 + bak, str_acl_type(*type), strerror(errno));
936 + rsync_acl_free(&racl_bak);
938 + rsync_acl_free(&racl_orig);
941 + sys_acl_free_acl(sacl_bak);
942 + /* out_with_one_sacl: */
944 + sys_acl_free_acl(sacl_orig);
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 + if (preserve_acls) {
961 + SMB_ACL_TYPE_T *type,
962 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
964 + backup_orig_file = file;
965 + backup_orig_fname = orig;
966 + backup_dest_fname = dest;
967 + for (type = &types[0], sacl = &_backup_sacl[0];
968 + type < &types[0] + sizeof types / sizeof types[0];
970 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
973 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
974 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
975 + orig, str_acl_type(*type),
983 +static int set_keep_backup_acl()
985 + if (preserve_acls) {
986 + SMB_ACL_TYPE_T *type,
987 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
990 + for (type = &types[0], sacl = &_backup_sacl[0];
991 + type < &types[0] + sizeof types / sizeof types[0];
994 + if (-1 == sys_acl_set_file(backup_dest_fname,
997 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
999 + str_acl_type(*type),
1010 +void cleanup_keep_backup_acl()
1012 + if (preserve_acls) {
1013 + SMB_ACL_TYPE_T *type,
1014 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1016 + backup_orig_file = NULL;
1017 + backup_orig_fname = null_string;
1018 + backup_dest_fname = null_string;
1019 + for (type = &types[0], sacl = &_backup_sacl[0];
1020 + type < &types[0] + sizeof types / sizeof types[0];
1023 + sys_acl_free_acl(*sacl);
1029 +/* set ACL on rsync-ed or keep_backup-ed file */
1031 +int set_acl(const char *fname, const struct file_struct *file)
1034 + SMB_ACL_TYPE_T *type,
1035 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1036 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1038 + if (file == backup_orig_file) {
1039 + if (!strcmp(fname, backup_dest_fname))
1040 + return set_keep_backup_acl();
1042 + for (type = &types[0];
1043 + type < &types[0] + sizeof types / sizeof types[0]
1044 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1046 + SMB_ACL_T sacl_orig, *sacl_new;
1047 + rsync_acl racl_orig, *racl_new;
1048 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1051 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1052 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1053 + sacl_orig = sys_acl_get_file(fname, *type);
1055 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1056 + fname, str_acl_type(*type), strerror(errno));
1060 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1061 + sys_acl_free_acl(sacl_orig);
1066 + ok = rsync_acls_equal(&racl_orig, racl_new);
1067 + rsync_acl_free(&racl_orig);
1070 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1071 + if (-1 == sys_acl_delete_def_file(fname)) {
1072 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1073 + fname, strerror(errno));
1079 + if (!pack_smb_acl(sacl_new, racl_new)) {
1083 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1084 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1085 + fname, str_acl_type(*type),
1097 +/* Enumeration functions for uid mapping: */
1099 +/* Context -- one and only one. Should be cycled through once on uid
1100 + * mapping and once on gid mapping. */
1101 +static rsync_acl_list *_enum_racl_lists[] = {
1102 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1105 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1106 +static size_t enum_racl_index = 0;
1107 +static size_t enum_race_index = 0;
1109 +/* This returns the next tag_type id from the given acl for the next entry,
1110 + * or it returns 0 if there are no more tag_type ids in the acl. */
1112 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1114 + for (; enum_race_index < racl->count; enum_race_index++) {
1115 + rsync_ace *race = &racl->races[enum_race_index];
1116 + if (race->tag_type == tag_type)
1119 + enum_race_index = 0;
1123 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1125 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1126 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1127 + id_t id = next_ace_id(tag_type, racl);
1131 + enum_racl_index = 0;
1135 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1137 + for (; *enum_racl_list; enum_racl_list++) {
1138 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1142 + enum_racl_list = &_enum_racl_lists[0];
1146 +id_t next_acl_uid()
1148 + return next_acl_list_id(SMB_ACL_USER);
1151 +id_t next_acl_gid()
1153 + return next_acl_list_id(SMB_ACL_GROUP);
1156 +/* referring to the global context enum_entry, sets the entry's id */
1157 +static void set_acl_id(id_t id)
1159 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1162 +void acl_uid_map(id_t uid)
1167 +void acl_gid_map(id_t gid)
1172 +static int mode_splice(int mode, int newbits, int where) {
1173 + return (mode & ~(7 << where)) | (newbits << where);
1176 +int default_mode_for_dir_acl(const char *dir)
1180 + BOOL ok, saw_mask = False;
1186 + mode = ACCESSPERMS & ~orig_umask;
1187 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1188 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1189 + if (sacl == NULL) {
1190 + /* Couldn't get an ACL. Darn. */
1193 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1197 + /* We're doing a dry run, so the containing directory
1198 + * wasn't actually created. Don't worry about it. */
1201 + /* Otherwise fall through. */
1203 + rprintf(FERROR, "default_mode_for_dir_acl: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1204 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1210 + ok = unpack_smb_acl(&racl, sacl);
1211 + sys_acl_free_acl(sacl);
1213 + rprintf(FERROR, "default_mode_for_dir_acl: unpack_smb_acl failed, falling back on umask\n");
1217 + /* Look at each default ACL entry and possibly modify three bits of `mode' accordingly.
1218 + * If there's "no" default ACL, there will be zero entries and the umask-based mode is unchanged. */
1219 + for (i = 0; i < racl.count; i++) {
1220 + switch (racl.races[i].tag_type) {
1221 + case SMB_ACL_USER_OBJ:
1222 + mode = mode_splice(mode, racl.races[i].access, 6);
1224 + case SMB_ACL_GROUP_OBJ:
1226 + mode = mode_splice(mode, racl.races[i].access, 3);
1228 + case SMB_ACL_MASK:
1230 + mode = mode_splice(mode, racl.races[i].access, 3);
1232 + case SMB_ACL_OTHER:
1233 + mode = mode_splice(mode, racl.races[i].access, 0);
1239 + rsync_acl_free(&racl);
1241 + rprintf(FINFO, "got ACL-based default mode %o for directory %s\n", mode, dir);
1245 +#endif /* SUPPORT_ACLS */
1246 --- orig/backup.c 2006-01-30 07:18:27
1247 +++ backup.c 2004-10-06 00:13:09
1248 @@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
1250 do_lchown(fullpath, st.st_uid, st.st_gid);
1251 do_chmod(fullpath, st.st_mode);
1252 + (void)DUP_ACL(end, fullpath, st.st_mode);
1256 @@ -188,6 +189,8 @@ static int keep_backup(char *fname)
1257 if (!(buf = get_backup_name(fname)))
1260 + 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 @@ -263,6 +266,7 @@ static int keep_backup(char *fname)
1268 set_file_attrs(buf, file, NULL, 0);
1269 + CLEANUP_KEEP_BACKUP_ACL();
1273 --- orig/configure.in 2006-01-15 14:52:33
1274 +++ configure.in 2004-08-19 19:53:27
1275 @@ -478,6 +478,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1276 AC_CHECK_LIB(resolv, strcasecmp)
1279 +AC_CHECK_FUNCS(aclsort)
1280 +if test x"$ac_cv_func_aclsort" = x"no"; then
1281 + AC_CHECK_LIB(sec, aclsort)
1284 dnl At the moment we don't test for a broken memcmp(), because all we
1285 dnl need to do is test for equality, not comparison, and it seems that
1286 dnl every platform has a memcmp that can do at least that.
1287 @@ -750,6 +755,77 @@ AC_SUBST(OBJ_RESTORE)
1288 AC_SUBST(CC_SHOBJ_FLAG)
1289 AC_SUBST(BUILD_POPT)
1291 +AC_CHECK_HEADERS(sys/acl.h)
1292 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1293 +#################################################
1294 +# check for ACL support
1296 +AC_MSG_CHECKING(whether to support ACLs)
1297 +AC_ARG_ENABLE(acl-support,
1298 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1299 +[ case "$enableval" in
1302 + case "$host_os" in
1304 + AC_MSG_RESULT(Using UnixWare ACLs)
1305 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1308 + AC_MSG_RESULT(Using solaris ACLs)
1309 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1312 + AC_MSG_RESULT(Using HPUX ACLs)
1313 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1316 + AC_MSG_RESULT(Using IRIX ACLs)
1317 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1320 + AC_MSG_RESULT(Using AIX ACLs)
1321 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1324 + AC_MSG_RESULT(Using Tru64 ACLs)
1325 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1326 + LIBS="$LIBS -lpacl"
1329 + AC_MSG_RESULT(ACLs requested -- running tests)
1330 + AC_CHECK_LIB(acl,acl_get_file)
1331 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1332 + AC_TRY_LINK([#include <sys/types.h>
1333 +#include <sys/acl.h>],
1334 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1335 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1336 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1337 + AC_MSG_RESULT(Using posix ACLs)
1338 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1339 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1340 + AC_TRY_LINK([#include <sys/types.h>
1341 +#include <sys/acl.h>],
1342 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1343 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1344 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1345 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1348 + AC_MSG_ERROR(Failed to find ACL support)
1355 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1358 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1362 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1365 --- orig/flist.c 2006-01-31 02:30:18
1366 +++ flist.c 2006-01-31 02:37:33
1367 @@ -967,6 +967,8 @@ static struct file_struct *send_file_nam
1368 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1371 + if (MAKE_ACL(file, fname) < 0)
1374 if (chmod_modes && !S_ISLNK(file->mode))
1375 file->mode = tweak_mode(file->mode, chmod_modes);
1376 @@ -978,6 +980,10 @@ static struct file_struct *send_file_nam
1377 if (file->basename[0]) {
1378 flist->files[flist->count++] = file;
1379 send_file_entry(file, f);
1380 + SEND_ACL(file, f);
1382 + /* Cleanup unsent ACL(s). */
1383 + SEND_ACL(file, -1);
1387 @@ -1366,6 +1372,8 @@ struct file_list *recv_file_list(int f)
1388 flags |= read_byte(f) << 8;
1389 file = receive_file_entry(flist, flags, f);
1391 + RECEIVE_ACL(file, f);
1393 if (S_ISREG(file->mode))
1394 stats.total_size += file->length;
1396 @@ -1388,6 +1396,8 @@ struct file_list *recv_file_list(int f)
1398 clean_flist(flist, relative_paths, 1);
1400 + SORT_FILE_ACL_INDEX_LISTS();
1403 recv_uid_list(f, flist);
1405 --- orig/generator.c 2006-01-31 02:30:18
1406 +++ generator.c 2006-01-31 02:35:44
1407 @@ -860,7 +860,8 @@ static void recv_generator(char *fname,
1408 if (!preserve_perms) {
1409 int exists = statret == 0
1410 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1411 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1412 + file->mode = dest_mode(file->mode, st.st_mode, exists,
1416 if (S_ISDIR(file->mode)) {
1417 @@ -894,6 +895,10 @@ static void recv_generator(char *fname,
1418 if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1419 && verbose && code && f_out != -1)
1420 rprintf(code, "%s/\n", fname);
1421 +#ifdef SUPPORT_ACLS
1423 + SET_ACL(fname, file);
1425 if (delete_during && f_out != -1 && !phase && dry_run < 2
1426 && (file->flags & FLAG_DEL_HERE))
1427 delete_in_dir(the_file_list, fname, file, &st);
1428 --- orig/lib/sysacls.c 2005-05-16 23:27:53
1429 +++ lib/sysacls.c 2005-05-16 23:27:53
1432 + Unix SMB/CIFS implementation.
1433 + Samba system utilities for ACL support.
1434 + Copyright (C) Jeremy Allison 2000.
1436 + This program is free software; you can redistribute it and/or modify
1437 + it under the terms of the GNU General Public License as published by
1438 + the Free Software Foundation; either version 2 of the License, or
1439 + (at your option) any later version.
1441 + This program is distributed in the hope that it will be useful,
1442 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1443 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1444 + GNU General Public License for more details.
1446 + You should have received a copy of the GNU General Public License
1447 + along with this program; if not, write to the Free Software
1448 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1452 +#include "sysacls.h" /****** ADDED ******/
1454 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1455 +void SAFE_FREE(void *mem)
1461 +char *uidtoname(uid_t uid)
1463 + static char idbuf[12];
1464 + struct passwd *pw;
1466 + if ((pw = getpwuid(uid)) == NULL) {
1467 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1470 + return pw->pw_name;
1472 +/****** EXTRAS -- END ******/
1475 + This file wraps all differing system ACL interfaces into a consistent
1476 + one based on the POSIX interface. It also returns the correct errors
1477 + for older UNIX systems that don't support ACLs.
1479 + The interfaces that each ACL implementation must support are as follows :
1481 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1482 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1483 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1484 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1485 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1486 + SMB_ACL_T sys_acl_get_fd(int fd)
1487 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1488 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1489 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1490 + SMB_ACL_T sys_acl_init( int count)
1491 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1492 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1493 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1494 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1495 + int sys_acl_valid( SMB_ACL_T theacl )
1496 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1497 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1498 + int sys_acl_delete_def_file(const char *path)
1500 + This next one is not POSIX complient - but we *have* to have it !
1501 + More POSIX braindamage.
1503 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1505 + The generic POSIX free is the following call. We split this into
1506 + several different free functions as we may need to add tag info
1507 + to structures when emulating the POSIX interface.
1509 + int sys_acl_free( void *obj_p)
1511 + The calls we actually use are :
1513 + int sys_acl_free_text(char *text) - free acl_to_text
1514 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1515 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1519 +#if defined(HAVE_POSIX_ACLS)
1521 +/* Identity mapping - easy. */
1523 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1525 + return acl_get_entry( the_acl, entry_id, entry_p);
1528 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1530 + return acl_get_tag_type( entry_d, tag_type_p);
1533 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1535 + return acl_get_permset( entry_d, permset_p);
1538 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1540 + return acl_get_qualifier( entry_d);
1543 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1545 + return acl_get_file( path_p, type);
1548 +SMB_ACL_T sys_acl_get_fd(int fd)
1550 + return acl_get_fd(fd);
1553 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1555 + return acl_clear_perms(permset);
1558 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1560 + return acl_add_perm(permset, perm);
1563 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1565 +#if defined(HAVE_ACL_GET_PERM_NP)
1567 + * Required for TrustedBSD-based ACL implementations where
1568 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1571 + return acl_get_perm_np(permset, perm);
1573 + return acl_get_perm(permset, perm);
1577 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1579 + return acl_to_text( the_acl, plen);
1582 +SMB_ACL_T sys_acl_init( int count)
1584 + return acl_init(count);
1587 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1589 + return acl_create_entry(pacl, pentry);
1592 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1594 + return acl_set_tag_type(entry, tagtype);
1597 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1599 + return acl_set_qualifier(entry, qual);
1602 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1604 + return acl_set_permset(entry, permset);
1607 +int sys_acl_valid( SMB_ACL_T theacl )
1609 + return acl_valid(theacl);
1612 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1614 + return acl_set_file(name, acltype, theacl);
1617 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1619 + return acl_set_fd(fd, theacl);
1622 +int sys_acl_delete_def_file(const char *name)
1624 + return acl_delete_def_file(name);
1627 +int sys_acl_free_text(char *text)
1629 + return acl_free(text);
1632 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1634 + return acl_free(the_acl);
1637 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1639 + return acl_free(qual);
1642 +#elif defined(HAVE_TRU64_ACLS)
1644 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1645 + * is based on Draft 13 of the POSIX spec which is
1646 + * slightly different from the Draft 16 interface.
1648 + * Also, some of the permset manipulation functions
1649 + * such as acl_clear_perm() and acl_add_perm() appear
1650 + * to be broken on Tru64 so we have to manipulate
1651 + * the permission bits in the permset directly.
1653 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1655 + SMB_ACL_ENTRY_T entry;
1657 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1662 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1667 + return errno ? -1 : 0;
1670 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1672 + return acl_get_tag_type( entry_d, tag_type_p);
1675 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1677 + return acl_get_permset( entry_d, permset_p);
1680 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1682 + return acl_get_qualifier( entry_d);
1685 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1687 + return acl_get_file((char *)path_p, type);
1690 +SMB_ACL_T sys_acl_get_fd(int fd)
1692 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1695 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1697 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1702 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1704 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1709 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1714 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1716 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1719 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1721 + return acl_to_text( the_acl, plen);
1724 +SMB_ACL_T sys_acl_init( int count)
1726 + return acl_init(count);
1729 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1731 + SMB_ACL_ENTRY_T entry;
1733 + if ((entry = acl_create_entry(pacl)) == NULL) {
1741 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1743 + return acl_set_tag_type(entry, tagtype);
1746 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1748 + return acl_set_qualifier(entry, qual);
1751 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1753 + return acl_set_permset(entry, permset);
1756 +int sys_acl_valid( SMB_ACL_T theacl )
1758 + acl_entry_t entry;
1760 + return acl_valid(theacl, &entry);
1763 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1765 + return acl_set_file((char *)name, acltype, theacl);
1768 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1770 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1773 +int sys_acl_delete_def_file(const char *name)
1775 + return acl_delete_def_file((char *)name);
1778 +int sys_acl_free_text(char *text)
1781 + * (void) cast and explicit return 0 are for DEC UNIX
1782 + * which just #defines acl_free_text() to be free()
1784 + (void) acl_free_text(text);
1788 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1790 + return acl_free(the_acl);
1793 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1795 + return acl_free_qualifier(qual, tagtype);
1798 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1801 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1802 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1806 + * Note that while this code implements sufficient functionality
1807 + * to support the sys_acl_* interfaces it does not provide all
1808 + * of the semantics of the POSIX ACL interfaces.
1810 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1811 + * from a call to sys_acl_get_entry() should not be assumed to be
1812 + * valid after calling any of the following functions, which may
1813 + * reorder the entries in the ACL.
1816 + * sys_acl_set_file()
1817 + * sys_acl_set_fd()
1821 + * The only difference between Solaris and UnixWare / OpenUNIX is
1822 + * that the #defines for the ACL operations have different names
1824 +#if defined(HAVE_UNIXWARE_ACLS)
1826 +#define SETACL ACL_SET
1827 +#define GETACL ACL_GET
1828 +#define GETACLCNT ACL_CNT
1833 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1835 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1840 + if (entry_p == NULL) {
1845 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1849 + if (acl_d->next < 0) {
1854 + if (acl_d->next >= acl_d->count) {
1858 + *entry_p = &acl_d->acl[acl_d->next++];
1863 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1865 + *type_p = entry_d->a_type;
1870 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1872 + *permset_p = &entry_d->a_perm;
1877 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1879 + if (entry_d->a_type != SMB_ACL_USER
1880 + && entry_d->a_type != SMB_ACL_GROUP) {
1885 + return &entry_d->a_id;
1889 + * There is no way of knowing what size the ACL returned by
1890 + * GETACL will be unless you first call GETACLCNT which means
1891 + * making an additional system call.
1893 + * In the hope of avoiding the cost of the additional system
1894 + * call in most cases, we initially allocate enough space for
1895 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1896 + * be too small then we use GETACLCNT to find out the actual
1897 + * size, reallocate the ACL buffer, and then call GETACL again.
1900 +#define INITIAL_ACL_SIZE 16
1902 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1905 + int count; /* # of ACL entries allocated */
1906 + int naccess; /* # of access ACL entries */
1907 + int ndefault; /* # of default ACL entries */
1909 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1914 + count = INITIAL_ACL_SIZE;
1915 + if ((acl_d = sys_acl_init(count)) == NULL) {
1920 + * If there isn't enough space for the ACL entries we use
1921 + * GETACLCNT to determine the actual number of ACL entries
1922 + * reallocate and try again. This is in a loop because it
1923 + * is possible that someone else could modify the ACL and
1924 + * increase the number of entries between the call to
1925 + * GETACLCNT and the call to GETACL.
1927 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1928 + && errno == ENOSPC) {
1930 + sys_acl_free_acl(acl_d);
1932 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1936 + if ((acl_d = sys_acl_init(count)) == NULL) {
1942 + sys_acl_free_acl(acl_d);
1947 + * calculate the number of access and default ACL entries
1949 + * Note: we assume that the acl() system call returned a
1950 + * well formed ACL which is sorted so that all of the
1951 + * access ACL entries preceed any default ACL entries
1953 + for (naccess = 0; naccess < count; naccess++) {
1954 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1957 + ndefault = count - naccess;
1960 + * if the caller wants the default ACL we have to copy
1961 + * the entries down to the start of the acl[] buffer
1962 + * and mask out the ACL_DEFAULT flag from the type field
1964 + if (type == SMB_ACL_TYPE_DEFAULT) {
1967 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
1968 + acl_d->acl[i] = acl_d->acl[j];
1969 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
1972 + acl_d->count = ndefault;
1974 + acl_d->count = naccess;
1980 +SMB_ACL_T sys_acl_get_fd(int fd)
1983 + int count; /* # of ACL entries allocated */
1984 + int naccess; /* # of access ACL entries */
1986 + count = INITIAL_ACL_SIZE;
1987 + if ((acl_d = sys_acl_init(count)) == NULL) {
1991 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
1992 + && errno == ENOSPC) {
1994 + sys_acl_free_acl(acl_d);
1996 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2000 + if ((acl_d = sys_acl_init(count)) == NULL) {
2006 + sys_acl_free_acl(acl_d);
2011 + * calculate the number of access ACL entries
2013 + for (naccess = 0; naccess < count; naccess++) {
2014 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2018 + acl_d->count = naccess;
2023 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2030 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2032 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2033 + && perm != SMB_ACL_EXECUTE) {
2038 + if (permset_d == NULL) {
2043 + *permset_d |= perm;
2048 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2050 + return *permset_d & perm;
2053 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2060 + * use an initial estimate of 20 bytes per ACL entry
2061 + * when allocating memory for the text representation
2065 + maxlen = 20 * acl_d->count;
2066 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2071 + for (i = 0; i < acl_d->count; i++) {
2072 + struct acl *ap = &acl_d->acl[i];
2073 + struct passwd *pw;
2082 + switch (ap->a_type) {
2084 + * for debugging purposes it's probably more
2085 + * useful to dump unknown tag types rather
2086 + * than just returning an error
2089 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2092 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2097 + case SMB_ACL_USER:
2098 + id = uidtoname(ap->a_id);
2099 + case SMB_ACL_USER_OBJ:
2103 + case SMB_ACL_GROUP:
2104 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2105 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2111 + case SMB_ACL_GROUP_OBJ:
2115 + case SMB_ACL_OTHER:
2119 + case SMB_ACL_MASK:
2125 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2126 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2127 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2130 + /* <tag> : <qualifier> : rwx \n \0 */
2131 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2134 + * If this entry would overflow the buffer
2135 + * allocate enough additional memory for this
2136 + * entry and an estimate of another 20 bytes
2137 + * for each entry still to be processed
2139 + if ((len + nbytes) > maxlen) {
2140 + char *oldtext = text;
2142 + maxlen += nbytes + 20 * (acl_d->count - i);
2144 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2145 + SAFE_FREE(oldtext);
2151 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2152 + len += nbytes - 1;
2161 +SMB_ACL_T sys_acl_init(int count)
2171 + * note that since the definition of the structure pointed
2172 + * to by the SMB_ACL_T includes the first element of the
2173 + * acl[] array, this actually allocates an ACL with room
2174 + * for (count+1) entries
2176 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2181 + a->size = count + 1;
2189 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2192 + SMB_ACL_ENTRY_T entry_d;
2194 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2199 + if (acl_d->count >= acl_d->size) {
2204 + entry_d = &acl_d->acl[acl_d->count++];
2205 + entry_d->a_type = 0;
2206 + entry_d->a_id = -1;
2207 + entry_d->a_perm = 0;
2208 + *entry_p = entry_d;
2213 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2215 + switch (tag_type) {
2216 + case SMB_ACL_USER:
2217 + case SMB_ACL_USER_OBJ:
2218 + case SMB_ACL_GROUP:
2219 + case SMB_ACL_GROUP_OBJ:
2220 + case SMB_ACL_OTHER:
2221 + case SMB_ACL_MASK:
2222 + entry_d->a_type = tag_type;
2232 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2234 + if (entry_d->a_type != SMB_ACL_GROUP
2235 + && entry_d->a_type != SMB_ACL_USER) {
2240 + entry_d->a_id = *((id_t *)qual_p);
2245 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2247 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2251 + entry_d->a_perm = *permset_d;
2257 + * sort the ACL and check it for validity
2259 + * if it's a minimal ACL with only 4 entries then we
2260 + * need to recalculate the mask permissions to make
2261 + * sure that they are the same as the GROUP_OBJ
2262 + * permissions as required by the UnixWare acl() system call.
2264 + * (note: since POSIX allows minimal ACLs which only contain
2265 + * 3 entries - ie there is no mask entry - we should, in theory,
2266 + * check for this and add a mask entry if necessary - however
2267 + * we "know" that the caller of this interface always specifies
2268 + * a mask so, in practice "this never happens" (tm) - if it *does*
2269 + * happen aclsort() will fail and return an error and someone will
2270 + * have to fix it ...)
2273 +static int acl_sort(SMB_ACL_T acl_d)
2275 + int fixmask = (acl_d->count <= 4);
2277 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2284 +int sys_acl_valid(SMB_ACL_T acl_d)
2286 + return acl_sort(acl_d);
2289 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2292 + struct acl *acl_p;
2294 + struct acl *acl_buf = NULL;
2297 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2302 + if (acl_sort(acl_d) != 0) {
2306 + acl_p = &acl_d->acl[0];
2307 + acl_count = acl_d->count;
2310 + * if it's a directory there is extra work to do
2311 + * since the acl() system call will replace both
2312 + * the access ACLs and the default ACLs (if any)
2314 + if (stat(name, &s) != 0) {
2317 + if (S_ISDIR(s.st_mode)) {
2318 + SMB_ACL_T acc_acl;
2319 + SMB_ACL_T def_acl;
2320 + SMB_ACL_T tmp_acl;
2323 + if (type == SMB_ACL_TYPE_ACCESS) {
2325 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2329 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2332 + if (tmp_acl == NULL) {
2337 + * allocate a temporary buffer for the complete ACL
2339 + acl_count = acc_acl->count + def_acl->count;
2340 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2342 + if (acl_buf == NULL) {
2343 + sys_acl_free_acl(tmp_acl);
2349 + * copy the access control and default entries into the buffer
2351 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2352 + acc_acl->count * sizeof(acl_buf[0]));
2354 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2355 + def_acl->count * sizeof(acl_buf[0]));
2358 + * set the ACL_DEFAULT flag on the default entries
2360 + for (i = acc_acl->count; i < acl_count; i++) {
2361 + acl_buf[i].a_type |= ACL_DEFAULT;
2364 + sys_acl_free_acl(tmp_acl);
2366 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2371 + ret = acl(name, SETACL, acl_count, acl_p);
2373 + SAFE_FREE(acl_buf);
2378 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2380 + if (acl_sort(acl_d) != 0) {
2384 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2387 +int sys_acl_delete_def_file(const char *path)
2393 + * fetching the access ACL and rewriting it has
2394 + * the effect of deleting the default ACL
2396 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2400 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2402 + sys_acl_free_acl(acl_d);
2407 +int sys_acl_free_text(char *text)
2413 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2419 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2424 +#elif defined(HAVE_HPUX_ACLS)
2428 + * Based on the Solaris/SCO code - with modifications.
2432 + * Note that while this code implements sufficient functionality
2433 + * to support the sys_acl_* interfaces it does not provide all
2434 + * of the semantics of the POSIX ACL interfaces.
2436 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2437 + * from a call to sys_acl_get_entry() should not be assumed to be
2438 + * valid after calling any of the following functions, which may
2439 + * reorder the entries in the ACL.
2442 + * sys_acl_set_file()
2443 + * sys_acl_set_fd()
2446 +/* This checks if the POSIX ACL system call is defined */
2447 +/* which basically corresponds to whether JFS 3.3 or */
2448 +/* higher is installed. If acl() was called when it */
2449 +/* isn't defined, it causes the process to core dump */
2450 +/* so it is important to check this and avoid acl() */
2451 +/* calls if it isn't there. */
2453 +static BOOL hpux_acl_call_presence(void)
2456 + shl_t handle = NULL;
2459 + static BOOL already_checked=0;
2461 + if(already_checked)
2465 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2467 + if(ret_val != 0) {
2468 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2469 + ret_val, errno, strerror(errno)));
2470 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2474 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2476 + already_checked = True;
2480 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2482 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2487 + if (entry_p == NULL) {
2492 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2496 + if (acl_d->next < 0) {
2501 + if (acl_d->next >= acl_d->count) {
2505 + *entry_p = &acl_d->acl[acl_d->next++];
2510 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2512 + *type_p = entry_d->a_type;
2517 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2519 + *permset_p = &entry_d->a_perm;
2524 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2526 + if (entry_d->a_type != SMB_ACL_USER
2527 + && entry_d->a_type != SMB_ACL_GROUP) {
2532 + return &entry_d->a_id;
2536 + * There is no way of knowing what size the ACL returned by
2537 + * ACL_GET will be unless you first call ACL_CNT which means
2538 + * making an additional system call.
2540 + * In the hope of avoiding the cost of the additional system
2541 + * call in most cases, we initially allocate enough space for
2542 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2543 + * be too small then we use ACL_CNT to find out the actual
2544 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2547 +#define INITIAL_ACL_SIZE 16
2549 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2552 + int count; /* # of ACL entries allocated */
2553 + int naccess; /* # of access ACL entries */
2554 + int ndefault; /* # of default ACL entries */
2556 + if(hpux_acl_call_presence() == False) {
2557 + /* Looks like we don't have the acl() system call on HPUX.
2558 + * May be the system doesn't have the latest version of JFS.
2563 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2568 + count = INITIAL_ACL_SIZE;
2569 + if ((acl_d = sys_acl_init(count)) == NULL) {
2574 + * If there isn't enough space for the ACL entries we use
2575 + * ACL_CNT to determine the actual number of ACL entries
2576 + * reallocate and try again. This is in a loop because it
2577 + * is possible that someone else could modify the ACL and
2578 + * increase the number of entries between the call to
2579 + * ACL_CNT and the call to ACL_GET.
2581 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2583 + sys_acl_free_acl(acl_d);
2585 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2589 + if ((acl_d = sys_acl_init(count)) == NULL) {
2595 + sys_acl_free_acl(acl_d);
2600 + * calculate the number of access and default ACL entries
2602 + * Note: we assume that the acl() system call returned a
2603 + * well formed ACL which is sorted so that all of the
2604 + * access ACL entries preceed any default ACL entries
2606 + for (naccess = 0; naccess < count; naccess++) {
2607 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2610 + ndefault = count - naccess;
2613 + * if the caller wants the default ACL we have to copy
2614 + * the entries down to the start of the acl[] buffer
2615 + * and mask out the ACL_DEFAULT flag from the type field
2617 + if (type == SMB_ACL_TYPE_DEFAULT) {
2620 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2621 + acl_d->acl[i] = acl_d->acl[j];
2622 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2625 + acl_d->count = ndefault;
2627 + acl_d->count = naccess;
2633 +SMB_ACL_T sys_acl_get_fd(int fd)
2636 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2639 + files_struct *fsp = file_find_fd(fd);
2641 + if (fsp == NULL) {
2647 + * We know we're in the same conn context. So we
2648 + * can use the relative path.
2651 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2654 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2661 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2663 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2664 + && perm != SMB_ACL_EXECUTE) {
2669 + if (permset_d == NULL) {
2674 + *permset_d |= perm;
2679 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2681 + return *permset_d & perm;
2684 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2691 + * use an initial estimate of 20 bytes per ACL entry
2692 + * when allocating memory for the text representation
2696 + maxlen = 20 * acl_d->count;
2697 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2702 + for (i = 0; i < acl_d->count; i++) {
2703 + struct acl *ap = &acl_d->acl[i];
2704 + struct passwd *pw;
2713 + switch (ap->a_type) {
2715 + * for debugging purposes it's probably more
2716 + * useful to dump unknown tag types rather
2717 + * than just returning an error
2720 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2723 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2728 + case SMB_ACL_USER:
2729 + id = uidtoname(ap->a_id);
2730 + case SMB_ACL_USER_OBJ:
2734 + case SMB_ACL_GROUP:
2735 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2736 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2742 + case SMB_ACL_GROUP_OBJ:
2746 + case SMB_ACL_OTHER:
2750 + case SMB_ACL_MASK:
2756 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2757 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2758 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2761 + /* <tag> : <qualifier> : rwx \n \0 */
2762 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2765 + * If this entry would overflow the buffer
2766 + * allocate enough additional memory for this
2767 + * entry and an estimate of another 20 bytes
2768 + * for each entry still to be processed
2770 + if ((len + nbytes) > maxlen) {
2771 + char *oldtext = text;
2773 + maxlen += nbytes + 20 * (acl_d->count - i);
2775 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2782 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2783 + len += nbytes - 1;
2792 +SMB_ACL_T sys_acl_init(int count)
2802 + * note that since the definition of the structure pointed
2803 + * to by the SMB_ACL_T includes the first element of the
2804 + * acl[] array, this actually allocates an ACL with room
2805 + * for (count+1) entries
2807 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2812 + a->size = count + 1;
2820 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2823 + SMB_ACL_ENTRY_T entry_d;
2825 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2830 + if (acl_d->count >= acl_d->size) {
2835 + entry_d = &acl_d->acl[acl_d->count++];
2836 + entry_d->a_type = 0;
2837 + entry_d->a_id = -1;
2838 + entry_d->a_perm = 0;
2839 + *entry_p = entry_d;
2844 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2846 + switch (tag_type) {
2847 + case SMB_ACL_USER:
2848 + case SMB_ACL_USER_OBJ:
2849 + case SMB_ACL_GROUP:
2850 + case SMB_ACL_GROUP_OBJ:
2851 + case SMB_ACL_OTHER:
2852 + case SMB_ACL_MASK:
2853 + entry_d->a_type = tag_type;
2863 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2865 + if (entry_d->a_type != SMB_ACL_GROUP
2866 + && entry_d->a_type != SMB_ACL_USER) {
2871 + entry_d->a_id = *((id_t *)qual_p);
2876 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2878 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2882 + entry_d->a_perm = *permset_d;
2887 +/* Structure to capture the count for each type of ACE. */
2889 +struct hpux_acl_types {
2893 + int n_def_user_obj;
2898 + int n_def_group_obj;
2902 + int n_def_other_obj;
2905 + int n_def_class_obj;
2907 + int n_illegal_obj;
2911 + * Counts the different number of objects in a given array of ACL
2915 + * acl_count - Count of ACLs in the array of ACL strucutres.
2916 + * aclp - Array of ACL structures.
2917 + * acl_type_count - Pointer to acl_types structure. Should already be
2921 + * acl_type_count - This structure is filled up with counts of various
2925 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2929 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2931 + for(i=0;i<acl_count;i++) {
2932 + switch(aclp[i].a_type) {
2934 + acl_type_count->n_user++;
2937 + acl_type_count->n_user_obj++;
2939 + case DEF_USER_OBJ:
2940 + acl_type_count->n_def_user_obj++;
2943 + acl_type_count->n_group++;
2946 + acl_type_count->n_group_obj++;
2948 + case DEF_GROUP_OBJ:
2949 + acl_type_count->n_def_group_obj++;
2952 + acl_type_count->n_other_obj++;
2954 + case DEF_OTHER_OBJ:
2955 + acl_type_count->n_def_other_obj++;
2958 + acl_type_count->n_class_obj++;
2960 + case DEF_CLASS_OBJ:
2961 + acl_type_count->n_def_class_obj++;
2964 + acl_type_count->n_def_user++;
2967 + acl_type_count->n_def_group++;
2970 + acl_type_count->n_illegal_obj++;
2976 +/* swap_acl_entries: Swaps two ACL entries.
2978 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
2981 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
2983 + struct acl temp_acl;
2985 + temp_acl.a_type = aclp0->a_type;
2986 + temp_acl.a_id = aclp0->a_id;
2987 + temp_acl.a_perm = aclp0->a_perm;
2989 + aclp0->a_type = aclp1->a_type;
2990 + aclp0->a_id = aclp1->a_id;
2991 + aclp0->a_perm = aclp1->a_perm;
2993 + aclp1->a_type = temp_acl.a_type;
2994 + aclp1->a_id = temp_acl.a_id;
2995 + aclp1->a_perm = temp_acl.a_perm;
2998 +/* prohibited_duplicate_type
2999 + * Identifies if given ACL type can have duplicate entries or
3002 + * Inputs: acl_type - ACL Type.
3008 + * True - If the ACL type matches any of the prohibited types.
3009 + * False - If the ACL type doesn't match any of the prohibited types.
3012 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3014 + switch(acl_type) {
3025 +/* get_needed_class_perm
3026 + * Returns the permissions of a ACL structure only if the ACL
3027 + * type matches one of the pre-determined types for computing
3028 + * CLASS_OBJ permissions.
3030 + * Inputs: aclp - Pointer to ACL structure.
3033 +static int hpux_get_needed_class_perm(struct acl *aclp)
3035 + switch(aclp->a_type) {
3039 + case DEF_USER_OBJ:
3041 + case DEF_GROUP_OBJ:
3043 + case DEF_CLASS_OBJ:
3044 + case DEF_OTHER_OBJ:
3045 + return aclp->a_perm;
3051 +/* acl_sort for HPUX.
3052 + * Sorts the array of ACL structures as per the description in
3053 + * aclsort man page. Refer to aclsort man page for more details
3057 + * acl_count - Count of ACLs in the array of ACL structures.
3058 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3060 + * aclp - Array of ACL structures.
3064 + * aclp - Sorted array of ACL structures.
3068 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3069 + * debug log in case of failure.
3072 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3074 +#if !defined(HAVE_HPUX_ACLSORT)
3076 + * The aclsort() system call is availabe on the latest HPUX General
3077 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3078 + * function. Because, we don't want to update to a new
3079 + * HPUX GR bundle just for aclsort() call.
3082 + struct hpux_acl_types acl_obj_count;
3083 + int n_class_obj_perm = 0;
3087 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3091 + if(aclp == NULL) {
3092 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3096 + /* Count different types of ACLs in the ACLs array */
3098 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3100 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3101 + * CLASS_OBJ and OTHER_OBJ
3104 + if( (acl_obj_count.n_user_obj != 1) ||
3105 + (acl_obj_count.n_group_obj != 1) ||
3106 + (acl_obj_count.n_class_obj != 1) ||
3107 + (acl_obj_count.n_other_obj != 1)
3109 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3110 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3114 + /* If any of the default objects are present, there should be only
3115 + * one of them each.
3118 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3119 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3120 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3121 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3125 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3128 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3129 + * same ACL type, sort by ACL id.
3131 + * I am using the trival kind of sorting method here because, performance isn't
3132 + * really effected by the ACLs feature. More over there aren't going to be more
3133 + * than 17 entries on HPUX.
3136 + for(i=0; i<acl_count;i++) {
3137 + for (j=i+1; j<acl_count; j++) {
3138 + if( aclp[i].a_type > aclp[j].a_type ) {
3139 + /* ACL entries out of order, swap them */
3141 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3143 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3145 + /* ACL entries of same type, sort by id */
3147 + if(aclp[i].a_id > aclp[j].a_id) {
3148 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3149 + } else if (aclp[i].a_id == aclp[j].a_id) {
3150 + /* We have a duplicate entry. */
3151 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3152 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3153 + aclp[i].a_type, aclp[i].a_id));
3162 + /* set the class obj permissions to the computed one. */
3164 + int n_class_obj_index = -1;
3166 + for(i=0;i<acl_count;i++) {
3167 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3169 + if(aclp[i].a_type == CLASS_OBJ)
3170 + n_class_obj_index = i;
3172 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3177 + return aclsort(acl_count, calclass, aclp);
3182 + * sort the ACL and check it for validity
3184 + * if it's a minimal ACL with only 4 entries then we
3185 + * need to recalculate the mask permissions to make
3186 + * sure that they are the same as the GROUP_OBJ
3187 + * permissions as required by the UnixWare acl() system call.
3189 + * (note: since POSIX allows minimal ACLs which only contain
3190 + * 3 entries - ie there is no mask entry - we should, in theory,
3191 + * check for this and add a mask entry if necessary - however
3192 + * we "know" that the caller of this interface always specifies
3193 + * a mask so, in practice "this never happens" (tm) - if it *does*
3194 + * happen aclsort() will fail and return an error and someone will
3195 + * have to fix it ...)
3198 +static int acl_sort(SMB_ACL_T acl_d)
3200 + int fixmask = (acl_d->count <= 4);
3202 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3209 +int sys_acl_valid(SMB_ACL_T acl_d)
3211 + return acl_sort(acl_d);
3214 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3217 + struct acl *acl_p;
3219 + struct acl *acl_buf = NULL;
3222 + if(hpux_acl_call_presence() == False) {
3223 + /* Looks like we don't have the acl() system call on HPUX.
3224 + * May be the system doesn't have the latest version of JFS.
3230 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3235 + if (acl_sort(acl_d) != 0) {
3239 + acl_p = &acl_d->acl[0];
3240 + acl_count = acl_d->count;
3243 + * if it's a directory there is extra work to do
3244 + * since the acl() system call will replace both
3245 + * the access ACLs and the default ACLs (if any)
3247 + if (stat(name, &s) != 0) {
3250 + if (S_ISDIR(s.st_mode)) {
3251 + SMB_ACL_T acc_acl;
3252 + SMB_ACL_T def_acl;
3253 + SMB_ACL_T tmp_acl;
3256 + if (type == SMB_ACL_TYPE_ACCESS) {
3258 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3262 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3265 + if (tmp_acl == NULL) {
3270 + * allocate a temporary buffer for the complete ACL
3272 + acl_count = acc_acl->count + def_acl->count;
3273 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3275 + if (acl_buf == NULL) {
3276 + sys_acl_free_acl(tmp_acl);
3282 + * copy the access control and default entries into the buffer
3284 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3285 + acc_acl->count * sizeof(acl_buf[0]));
3287 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3288 + def_acl->count * sizeof(acl_buf[0]));
3291 + * set the ACL_DEFAULT flag on the default entries
3293 + for (i = acc_acl->count; i < acl_count; i++) {
3294 + acl_buf[i].a_type |= ACL_DEFAULT;
3297 + sys_acl_free_acl(tmp_acl);
3299 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3304 + ret = acl(name, ACL_SET, acl_count, acl_p);
3313 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3316 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3319 + files_struct *fsp = file_find_fd(fd);
3321 + if (fsp == NULL) {
3326 + if (acl_sort(acl_d) != 0) {
3331 + * We know we're in the same conn context. So we
3332 + * can use the relative path.
3335 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3338 +int sys_acl_delete_def_file(const char *path)
3344 + * fetching the access ACL and rewriting it has
3345 + * the effect of deleting the default ACL
3347 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3351 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3353 + sys_acl_free_acl(acl_d);
3358 +int sys_acl_free_text(char *text)
3364 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3370 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3375 +#elif defined(HAVE_IRIX_ACLS)
3377 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3379 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3384 + if (entry_p == NULL) {
3389 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3393 + if (acl_d->next < 0) {
3398 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3402 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3407 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3409 + *type_p = entry_d->ae_tag;
3414 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3416 + *permset_p = entry_d;
3421 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3423 + if (entry_d->ae_tag != SMB_ACL_USER
3424 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3429 + return &entry_d->ae_id;
3432 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3436 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3440 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3445 + a->freeaclp = True;
3449 +SMB_ACL_T sys_acl_get_fd(int fd)
3453 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3457 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3462 + a->freeaclp = True;
3466 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3468 + permset_d->ae_perm = 0;
3473 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3475 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3476 + && perm != SMB_ACL_EXECUTE) {
3481 + if (permset_d == NULL) {
3486 + permset_d->ae_perm |= perm;
3491 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3493 + return permset_d->ae_perm & perm;
3496 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3498 + return acl_to_text(acl_d->aclp, len_p);
3501 +SMB_ACL_T sys_acl_init(int count)
3510 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3516 + a->freeaclp = False;
3517 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3518 + a->aclp->acl_cnt = 0;
3524 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3527 + SMB_ACL_ENTRY_T entry_d;
3529 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3534 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3539 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3540 + entry_d->ae_tag = 0;
3541 + entry_d->ae_id = 0;
3542 + entry_d->ae_perm = 0;
3543 + *entry_p = entry_d;
3548 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3550 + switch (tag_type) {
3551 + case SMB_ACL_USER:
3552 + case SMB_ACL_USER_OBJ:
3553 + case SMB_ACL_GROUP:
3554 + case SMB_ACL_GROUP_OBJ:
3555 + case SMB_ACL_OTHER:
3556 + case SMB_ACL_MASK:
3557 + entry_d->ae_tag = tag_type;
3567 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3569 + if (entry_d->ae_tag != SMB_ACL_GROUP
3570 + && entry_d->ae_tag != SMB_ACL_USER) {
3575 + entry_d->ae_id = *((id_t *)qual_p);
3580 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3582 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3586 + entry_d->ae_perm = permset_d->ae_perm;
3591 +int sys_acl_valid(SMB_ACL_T acl_d)
3593 + return acl_valid(acl_d->aclp);
3596 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3598 + return acl_set_file(name, type, acl_d->aclp);
3601 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3603 + return acl_set_fd(fd, acl_d->aclp);
3606 +int sys_acl_delete_def_file(const char *name)
3608 + return acl_delete_def_file(name);
3611 +int sys_acl_free_text(char *text)
3613 + return acl_free(text);
3616 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3618 + if (acl_d->freeaclp) {
3619 + acl_free(acl_d->aclp);
3625 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3630 +#elif defined(HAVE_AIX_ACLS)
3632 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3634 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3636 + struct acl_entry_link *link;
3637 + struct new_acl_entry *entry;
3640 + DEBUG(10,("This is the count: %d\n",theacl->count));
3642 + /* Check if count was previously set to -1. *
3643 + * If it was, that means we reached the end *
3644 + * of the acl last time. */
3645 + if(theacl->count == -1)
3649 + /* To get to the next acl, traverse linked list until index *
3650 + * of acl matches the count we are keeping. This count is *
3651 + * incremented each time we return an acl entry. */
3653 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3654 + link = link->nextp;
3656 + entry = *entry_p = link->entryp;
3658 + DEBUG(10,("*entry_p is %d\n",entry_p));
3659 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3661 + /* Increment count */
3663 + if(link->nextp == NULL)
3664 + theacl->count = -1;
3669 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3671 + /* Initialize tag type */
3674 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3676 + /* Depending on what type of entry we have, *
3677 + * return tag type. */
3678 + switch(entry_d->ace_id->id_type) {
3680 + *tag_type_p = SMB_ACL_USER;
3683 + *tag_type_p = SMB_ACL_GROUP;
3686 + case SMB_ACL_USER_OBJ:
3687 + case SMB_ACL_GROUP_OBJ:
3688 + case SMB_ACL_OTHER:
3689 + *tag_type_p = entry_d->ace_id->id_type;
3699 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3701 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3702 + *permset_p = &entry_d->ace_access;
3703 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3704 + if(!(**permset_p & S_IXUSR) &&
3705 + !(**permset_p & S_IWUSR) &&
3706 + !(**permset_p & S_IRUSR) &&
3707 + (**permset_p != 0))
3710 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3714 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3716 + return(entry_d->ace_id->id_data);
3719 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3721 + struct acl *file_acl = (struct acl *)NULL;
3722 + struct acl_entry *acl_entry;
3723 + struct new_acl_entry *new_acl_entry;
3724 + struct ace_id *idp;
3725 + struct acl_entry_link *acl_entry_link;
3726 + struct acl_entry_link *acl_entry_link_head;
3731 + /* AIX has no DEFAULT */
3732 + if ( type == SMB_ACL_TYPE_DEFAULT )
3735 + /* Get the acl using statacl */
3737 + DEBUG(10,("Entering sys_acl_get_file\n"));
3738 + DEBUG(10,("path_p is %s\n",path_p));
3740 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3742 + if(file_acl == NULL) {
3744 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3748 + memset(file_acl,0,BUFSIZ);
3750 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3752 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3753 + SAFE_FREE(file_acl);
3757 + DEBUG(10,("Got facl and returned it\n"));
3759 + /* Point to the first acl entry in the acl */
3760 + acl_entry = file_acl->acl_ext;
3762 + /* Begin setting up the head of the linked list *
3763 + * that will be used for the storing the acl *
3764 + * in a way that is useful for the posix_acls.c *
3767 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3768 + if(acl_entry_link_head == NULL)
3771 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3772 + if(acl_entry_link->entryp == NULL) {
3773 + SAFE_FREE(file_acl);
3775 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3779 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3780 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3782 + /* Check if the extended acl bit is on. *
3783 + * If it isn't, do not show the *
3784 + * contents of the acl since AIX intends *
3785 + * the extended info to remain unused */
3787 + if(file_acl->acl_mode & S_IXACL){
3788 + /* while we are not pointing to the very end */
3789 + while(acl_entry < acl_last(file_acl)) {
3790 + /* before we malloc anything, make sure this is */
3791 + /* a valid acl entry and one that we want to map */
3792 + idp = id_nxt(acl_entry->ace_id);
3793 + if((acl_entry->ace_type == ACC_SPECIFY ||
3794 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3795 + acl_entry = acl_nxt(acl_entry);
3799 + idp = acl_entry->ace_id;
3801 + /* Check if this is the first entry in the linked list. *
3802 + * The first entry needs to keep prevp pointing to NULL *
3803 + * and already has entryp allocated. */
3805 + if(acl_entry_link_head->count != 0) {
3806 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3808 + if(acl_entry_link->nextp == NULL) {
3809 + SAFE_FREE(file_acl);
3811 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3815 + acl_entry_link->nextp->prevp = acl_entry_link;
3816 + acl_entry_link = acl_entry_link->nextp;
3817 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3818 + if(acl_entry_link->entryp == NULL) {
3819 + SAFE_FREE(file_acl);
3821 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3824 + acl_entry_link->nextp = NULL;
3827 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3829 + /* Don't really need this since all types are going *
3830 + * to be specified but, it's better than leaving it 0 */
3832 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3834 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3836 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3838 + /* The access in the acl entries must be left shifted by *
3839 + * three bites, because they will ultimately be compared *
3840 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3842 + switch(acl_entry->ace_type){
3845 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3846 + acl_entry_link->entryp->ace_access <<= 6;
3847 + acl_entry_link_head->count++;
3850 + /* Since there is no way to return a DENY acl entry *
3851 + * change to PERMIT and then shift. */
3852 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3853 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3854 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3855 + acl_entry_link->entryp->ace_access <<= 6;
3856 + acl_entry_link_head->count++;
3862 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3863 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3865 + acl_entry = acl_nxt(acl_entry);
3867 + } /* end of if enabled */
3869 + /* Since owner, group, other acl entries are not *
3870 + * part of the acl entries in an acl, they must *
3871 + * be dummied up to become part of the list. */
3873 + for( i = 1; i < 4; i++) {
3874 + DEBUG(10,("i is %d\n",i));
3875 + if(acl_entry_link_head->count != 0) {
3876 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3877 + if(acl_entry_link->nextp == NULL) {
3878 + SAFE_FREE(file_acl);
3880 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3884 + acl_entry_link->nextp->prevp = acl_entry_link;
3885 + acl_entry_link = acl_entry_link->nextp;
3886 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3887 + if(acl_entry_link->entryp == NULL) {
3888 + SAFE_FREE(file_acl);
3890 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3895 + acl_entry_link->nextp = NULL;
3897 + new_acl_entry = acl_entry_link->entryp;
3898 + idp = new_acl_entry->ace_id;
3900 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3901 + new_acl_entry->ace_type = ACC_PERMIT;
3902 + idp->id_len = sizeof(struct ace_id);
3903 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3904 + memset(idp->id_data,0,sizeof(uid_t));
3908 + new_acl_entry->ace_access = file_acl->g_access << 6;
3909 + idp->id_type = SMB_ACL_GROUP_OBJ;
3913 + new_acl_entry->ace_access = file_acl->o_access << 6;
3914 + idp->id_type = SMB_ACL_OTHER;
3918 + new_acl_entry->ace_access = file_acl->u_access << 6;
3919 + idp->id_type = SMB_ACL_USER_OBJ;
3927 + acl_entry_link_head->count++;
3928 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3931 + acl_entry_link_head->count = 0;
3932 + SAFE_FREE(file_acl);
3934 + return(acl_entry_link_head);
3937 +SMB_ACL_T sys_acl_get_fd(int fd)
3939 + struct acl *file_acl = (struct acl *)NULL;
3940 + struct acl_entry *acl_entry;
3941 + struct new_acl_entry *new_acl_entry;
3942 + struct ace_id *idp;
3943 + struct acl_entry_link *acl_entry_link;
3944 + struct acl_entry_link *acl_entry_link_head;
3949 + /* Get the acl using fstatacl */
3951 + DEBUG(10,("Entering sys_acl_get_fd\n"));
3952 + DEBUG(10,("fd is %d\n",fd));
3953 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3955 + if(file_acl == NULL) {
3957 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3961 + memset(file_acl,0,BUFSIZ);
3963 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
3965 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
3966 + SAFE_FREE(file_acl);
3970 + DEBUG(10,("Got facl and returned it\n"));
3972 + /* Point to the first acl entry in the acl */
3974 + acl_entry = file_acl->acl_ext;
3975 + /* Begin setting up the head of the linked list *
3976 + * that will be used for the storing the acl *
3977 + * in a way that is useful for the posix_acls.c *
3980 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3981 + if(acl_entry_link_head == NULL){
3982 + SAFE_FREE(file_acl);
3986 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3988 + if(acl_entry_link->entryp == NULL) {
3990 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3991 + SAFE_FREE(file_acl);
3995 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3996 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3998 + /* Check if the extended acl bit is on. *
3999 + * If it isn't, do not show the *
4000 + * contents of the acl since AIX intends *
4001 + * the extended info to remain unused */
4003 + if(file_acl->acl_mode & S_IXACL){
4004 + /* while we are not pointing to the very end */
4005 + while(acl_entry < acl_last(file_acl)) {
4006 + /* before we malloc anything, make sure this is */
4007 + /* a valid acl entry and one that we want to map */
4009 + idp = id_nxt(acl_entry->ace_id);
4010 + if((acl_entry->ace_type == ACC_SPECIFY ||
4011 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4012 + acl_entry = acl_nxt(acl_entry);
4016 + idp = acl_entry->ace_id;
4018 + /* Check if this is the first entry in the linked list. *
4019 + * The first entry needs to keep prevp pointing to NULL *
4020 + * and already has entryp allocated. */
4022 + if(acl_entry_link_head->count != 0) {
4023 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4024 + if(acl_entry_link->nextp == NULL) {
4026 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4027 + SAFE_FREE(file_acl);
4030 + acl_entry_link->nextp->prevp = acl_entry_link;
4031 + acl_entry_link = acl_entry_link->nextp;
4032 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4033 + if(acl_entry_link->entryp == NULL) {
4035 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4036 + SAFE_FREE(file_acl);
4040 + acl_entry_link->nextp = NULL;
4043 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4045 + /* Don't really need this since all types are going *
4046 + * to be specified but, it's better than leaving it 0 */
4048 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4049 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4051 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4053 + /* The access in the acl entries must be left shifted by *
4054 + * three bites, because they will ultimately be compared *
4055 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4057 + switch(acl_entry->ace_type){
4060 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4061 + acl_entry_link->entryp->ace_access <<= 6;
4062 + acl_entry_link_head->count++;
4065 + /* Since there is no way to return a DENY acl entry *
4066 + * change to PERMIT and then shift. */
4067 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4068 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4069 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4070 + acl_entry_link->entryp->ace_access <<= 6;
4071 + acl_entry_link_head->count++;
4077 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4078 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4080 + acl_entry = acl_nxt(acl_entry);
4082 + } /* end of if enabled */
4084 + /* Since owner, group, other acl entries are not *
4085 + * part of the acl entries in an acl, they must *
4086 + * be dummied up to become part of the list. */
4088 + for( i = 1; i < 4; i++) {
4089 + DEBUG(10,("i is %d\n",i));
4090 + if(acl_entry_link_head->count != 0){
4091 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4092 + if(acl_entry_link->nextp == NULL) {
4094 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4095 + SAFE_FREE(file_acl);
4099 + acl_entry_link->nextp->prevp = acl_entry_link;
4100 + acl_entry_link = acl_entry_link->nextp;
4101 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4103 + if(acl_entry_link->entryp == NULL) {
4104 + SAFE_FREE(file_acl);
4106 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4111 + acl_entry_link->nextp = NULL;
4113 + new_acl_entry = acl_entry_link->entryp;
4114 + idp = new_acl_entry->ace_id;
4116 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4117 + new_acl_entry->ace_type = ACC_PERMIT;
4118 + idp->id_len = sizeof(struct ace_id);
4119 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4120 + memset(idp->id_data,0,sizeof(uid_t));
4124 + new_acl_entry->ace_access = file_acl->g_access << 6;
4125 + idp->id_type = SMB_ACL_GROUP_OBJ;
4129 + new_acl_entry->ace_access = file_acl->o_access << 6;
4130 + idp->id_type = SMB_ACL_OTHER;
4134 + new_acl_entry->ace_access = file_acl->u_access << 6;
4135 + idp->id_type = SMB_ACL_USER_OBJ;
4142 + acl_entry_link_head->count++;
4143 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4146 + acl_entry_link_head->count = 0;
4147 + SAFE_FREE(file_acl);
4149 + return(acl_entry_link_head);
4152 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4154 + *permset = *permset & ~0777;
4158 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4161 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4165 + DEBUG(10,("This is the permset now: %d\n",*permset));
4169 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4174 +SMB_ACL_T sys_acl_init( int count)
4176 + struct acl_entry_link *theacl = NULL;
4178 + DEBUG(10,("Entering sys_acl_init\n"));
4180 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4181 + if(theacl == NULL) {
4183 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4187 + theacl->count = 0;
4188 + theacl->nextp = NULL;
4189 + theacl->prevp = NULL;
4190 + theacl->entryp = NULL;
4191 + DEBUG(10,("Exiting sys_acl_init\n"));
4195 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4197 + struct acl_entry_link *theacl;
4198 + struct acl_entry_link *acl_entryp;
4199 + struct acl_entry_link *temp_entry;
4202 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4204 + theacl = acl_entryp = *pacl;
4206 + /* Get to the end of the acl before adding entry */
4208 + for(counting=0; counting < theacl->count; counting++){
4209 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4210 + temp_entry = acl_entryp;
4211 + acl_entryp = acl_entryp->nextp;
4214 + if(theacl->count != 0){
4215 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4216 + if(acl_entryp == NULL) {
4218 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4222 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4223 + acl_entryp->prevp = temp_entry;
4224 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4227 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4228 + if(*pentry == NULL) {
4230 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4234 + memset(*pentry,0,sizeof(struct new_acl_entry));
4235 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4236 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4237 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4238 + acl_entryp->nextp = NULL;
4240 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4244 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4246 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4247 + entry->ace_id->id_type = tagtype;
4248 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4249 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4252 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4254 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4255 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4256 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4260 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4262 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4263 + if(!(*permset & S_IXUSR) &&
4264 + !(*permset & S_IWUSR) &&
4265 + !(*permset & S_IRUSR) &&
4269 + entry->ace_access = *permset;
4270 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4271 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4275 +int sys_acl_valid( SMB_ACL_T theacl )
4278 + int group_obj = 0;
4279 + int other_obj = 0;
4280 + struct acl_entry_link *acl_entry;
4282 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4283 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4284 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4285 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4288 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4290 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4296 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4298 + struct acl_entry_link *acl_entry_link = NULL;
4299 + struct acl *file_acl = NULL;
4300 + struct acl *file_acl_temp = NULL;
4301 + struct acl_entry *acl_entry = NULL;
4302 + struct ace_id *ace_id = NULL;
4309 + DEBUG(10,("Entering sys_acl_set_file\n"));
4310 + DEBUG(10,("File name is %s\n",name));
4312 + /* AIX has no default ACL */
4313 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4316 + acl_length = BUFSIZ;
4317 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4319 + if(file_acl == NULL) {
4321 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4325 + memset(file_acl,0,BUFSIZ);
4327 + file_acl->acl_len = ACL_SIZ;
4328 + file_acl->acl_mode = S_IXACL;
4330 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4331 + acl_entry_link->entryp->ace_access >>= 6;
4332 + id_type = acl_entry_link->entryp->ace_id->id_type;
4335 + case SMB_ACL_USER_OBJ:
4336 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4338 + case SMB_ACL_GROUP_OBJ:
4339 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4341 + case SMB_ACL_OTHER:
4342 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4344 + case SMB_ACL_MASK:
4348 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4349 + acl_length += sizeof(struct acl_entry);
4350 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4351 + if(file_acl_temp == NULL) {
4352 + SAFE_FREE(file_acl);
4354 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4358 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4359 + SAFE_FREE(file_acl);
4360 + file_acl = file_acl_temp;
4363 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4364 + file_acl->acl_len += sizeof(struct acl_entry);
4365 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4366 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4368 + /* In order to use this, we'll need to wait until we can get denies */
4369 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4370 + acl_entry->ace_type = ACC_SPECIFY; */
4372 + acl_entry->ace_type = ACC_SPECIFY;
4374 + ace_id = acl_entry->ace_id;
4376 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4377 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4378 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4379 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4380 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4383 + rc = chacl(name,file_acl,file_acl->acl_len);
4384 + DEBUG(10,("errno is %d\n",errno));
4385 + DEBUG(10,("return code is %d\n",rc));
4386 + SAFE_FREE(file_acl);
4387 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4391 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4393 + struct acl_entry_link *acl_entry_link = NULL;
4394 + struct acl *file_acl = NULL;
4395 + struct acl *file_acl_temp = NULL;
4396 + struct acl_entry *acl_entry = NULL;
4397 + struct ace_id *ace_id = NULL;
4403 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4404 + acl_length = BUFSIZ;
4405 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4407 + if(file_acl == NULL) {
4409 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4413 + memset(file_acl,0,BUFSIZ);
4415 + file_acl->acl_len = ACL_SIZ;
4416 + file_acl->acl_mode = S_IXACL;
4418 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4419 + acl_entry_link->entryp->ace_access >>= 6;
4420 + id_type = acl_entry_link->entryp->ace_id->id_type;
4421 + DEBUG(10,("The id_type is %d\n",id_type));
4424 + case SMB_ACL_USER_OBJ:
4425 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4427 + case SMB_ACL_GROUP_OBJ:
4428 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4430 + case SMB_ACL_OTHER:
4431 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4433 + case SMB_ACL_MASK:
4437 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4438 + acl_length += sizeof(struct acl_entry);
4439 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4440 + if(file_acl_temp == NULL) {
4441 + SAFE_FREE(file_acl);
4443 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4447 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4448 + SAFE_FREE(file_acl);
4449 + file_acl = file_acl_temp;
4452 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4453 + file_acl->acl_len += sizeof(struct acl_entry);
4454 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4455 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4457 + /* In order to use this, we'll need to wait until we can get denies */
4458 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4459 + acl_entry->ace_type = ACC_SPECIFY; */
4461 + acl_entry->ace_type = ACC_SPECIFY;
4463 + ace_id = acl_entry->ace_id;
4465 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4466 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4467 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4468 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4469 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4472 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4473 + DEBUG(10,("errno is %d\n",errno));
4474 + DEBUG(10,("return code is %d\n",rc));
4475 + SAFE_FREE(file_acl);
4476 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4480 +int sys_acl_delete_def_file(const char *name)
4482 + /* AIX has no default ACL */
4486 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4488 + return(*permset & perm);
4491 +int sys_acl_free_text(char *text)
4496 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4498 + struct acl_entry_link *acl_entry_link;
4500 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4501 + SAFE_FREE(acl_entry_link->prevp->entryp);
4502 + SAFE_FREE(acl_entry_link->prevp);
4505 + SAFE_FREE(acl_entry_link->prevp->entryp);
4506 + SAFE_FREE(acl_entry_link->prevp);
4507 + SAFE_FREE(acl_entry_link->entryp);
4508 + SAFE_FREE(acl_entry_link);
4513 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4518 +#else /* No ACLs. */
4520 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4526 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4532 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4538 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4544 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4547 + return (SMB_ACL_T)NULL;
4550 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4553 + return (SMB_ACL_T)NULL;
4556 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4562 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4568 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4571 + return (permset & perm) ? 1 : 0;
4574 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4580 +int sys_acl_free_text(UNUSED(char *text))
4586 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4592 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4598 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4604 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4610 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4616 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4622 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4628 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4634 +int sys_acl_delete_def_file(UNUSED(const char *name))
4640 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4646 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4652 +#endif /* No ACLs. */
4654 +/************************************************************************
4655 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4657 +************************************************************************/
4659 +int no_acl_syscall_error(int err)
4661 +#if defined(ENOSYS)
4662 + if (err == ENOSYS) {
4666 +#if defined(ENOTSUP)
4667 + if (err == ENOTSUP) {
4673 --- orig/lib/sysacls.h 2005-05-16 23:25:51
4674 +++ lib/sysacls.h 2005-05-16 23:25:51
4676 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4677 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4678 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4679 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4680 +#define slprintf snprintf
4682 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4683 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4684 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4685 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4686 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4687 +SMB_ACL_T sys_acl_get_fd(int fd);
4688 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4689 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4690 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4691 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4692 +SMB_ACL_T sys_acl_init(int count);
4693 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4694 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4695 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4696 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4697 +int sys_acl_valid(SMB_ACL_T theacl);
4698 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4699 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4700 +int sys_acl_delete_def_file(const char *name);
4701 +int sys_acl_free_text(char *text);
4702 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4703 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4704 --- orig/mkproto.awk 2005-02-18 20:16:59
4705 +++ mkproto.awk 2005-02-18 20:18:17
4706 @@ -58,7 +58,7 @@ BEGIN {
4710 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const/ {
4711 +!/^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/ {
4715 --- orig/options.c 2006-01-31 03:11:30
4716 +++ options.c 2006-01-31 03:11:18
4717 @@ -44,6 +44,7 @@ int keep_dirlinks = 0;
4719 int preserve_links = 0;
4720 int preserve_hard_links = 0;
4721 +int preserve_acls = 0;
4722 int preserve_perms = 0;
4723 int preserve_executability = 0;
4724 int preserve_devices = 0;
4725 @@ -193,6 +194,7 @@ static void print_rsync_version(enum log
4726 char const *got_socketpair = "no ";
4727 char const *have_inplace = "no ";
4728 char const *hardlinks = "no ";
4729 + char const *acls = "no ";
4730 char const *links = "no ";
4731 char const *ipv6 = "no ";
4732 STRUCT_STAT *dumstat;
4733 @@ -209,6 +211,10 @@ static void print_rsync_version(enum log
4737 +#ifdef SUPPORT_ACLS
4741 #ifdef SUPPORT_LINKS
4744 @@ -222,9 +228,9 @@ static void print_rsync_version(enum log
4745 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4746 rprintf(f, "<http://rsync.samba.org/>\n");
4747 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4748 - "%shard links, %ssymlinks, batchfiles, \n",
4749 + "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
4750 (int) (sizeof (OFF_T) * 8),
4751 - got_socketpair, hardlinks, links);
4752 + got_socketpair, hardlinks, acls, links);
4754 /* Note that this field may not have type ino_t. It depends
4755 * on the complicated interaction between largefile feature
4756 @@ -293,6 +299,7 @@ void usage(enum logcode F)
4757 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
4758 rprintf(F," -p, --perms preserve permissions\n");
4759 rprintf(F," -E, --executability preserve the file's executability\n");
4760 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4761 rprintf(F," --chmod=CHMOD change destination permissions\n");
4762 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4763 rprintf(F," -g, --group preserve group\n");
4764 @@ -409,6 +416,9 @@ static struct poptOption long_options[]
4765 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4766 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4767 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4768 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4769 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4770 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4771 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4772 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4773 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4774 @@ -1057,6 +1067,24 @@ int parse_arguments(int *argc, const cha
4779 +#ifdef SUPPORT_ACLS
4780 + preserve_acls = 1;
4781 + preserve_perms = 1;
4784 + /* FIXME: this should probably be ignored with a
4785 + * warning and then countermeasures taken to
4786 + * restrict group and other access in the presence
4787 + * of any more restrictive ACLs, but this is safe
4789 + snprintf(err_buf,sizeof(err_buf),
4790 + "ACLs are not supported on this %s\n",
4791 + am_server ? "server" : "client");
4793 +#endif /* SUPPORT_ACLS */
4797 /* A large opt value means that set_refuse_options()
4798 * turned this option off. */
4799 @@ -1497,6 +1525,8 @@ void server_options(char **args,int *arg
4801 if (preserve_hard_links)
4803 + if (preserve_acls)
4804 + argstr[x++] = 'A';
4808 --- orig/receiver.c 2006-01-31 02:30:18
4809 +++ receiver.c 2006-01-31 02:36:26
4810 @@ -607,7 +607,8 @@ int recv_files(int f_in, struct file_lis
4811 * mode based on the local permissions and some heuristics. */
4812 if (!preserve_perms) {
4813 int exists = fd1 != -1;
4814 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4815 + file->mode = dest_mode(file->mode, st.st_mode, exists,
4819 /* We now check to see if we are writing file "inplace" */
4820 --- orig/rsync.c 2006-01-31 02:30:18
4821 +++ rsync.c 2006-01-31 02:33:51
4822 @@ -53,7 +53,7 @@ void free_sums(struct sum_struct *s)
4824 /* This is only called when we aren't preserving permissions. Figure out what
4825 * the permissions should be and return them merged back into the mode. */
4826 -mode_t dest_mode(mode_t flist_mode, mode_t dest_mode, int exists)
4827 +mode_t dest_mode(mode_t flist_mode, mode_t dest_mode, int exists, const char *dirname)
4829 /* If the file already exists we'll return the local permissions,
4830 * possibly tweaked by the --executability option. */
4831 @@ -67,8 +67,10 @@ mode_t dest_mode(mode_t flist_mode, mode
4832 else if (!(dest_mode & 0111))
4833 dest_mode |= (dest_mode & 0444) >> 2;
4836 - dest_mode = flist_mode & ~orig_umask;
4838 + dest_mode = ((flist_mode & CHMOD_BITS)
4839 + & DEFAULT_MODE_FOR_DIR(dirname)) | S_IWUSR;
4841 return (flist_mode & ~CHMOD_BITS) | (dest_mode & CHMOD_BITS);
4844 @@ -161,6 +163,14 @@ int set_file_attrs(char *fname, struct f
4848 + /* If this is a directory, SET_ACL() will be called on the cleanup
4849 + * receive_generator() pass (if we called it here, we might clobber
4850 + * writability on the directory). Everything else is OK to do now. */
4851 + if (!S_ISDIR(st->st_mode)) {
4852 + if (SET_ACL(fname, file) == 0)
4856 if (verbose > 1 && flags & ATTRS_REPORT) {
4857 enum logcode code = daemon_log_format_has_i || dry_run
4859 --- orig/rsync.h 2006-01-30 20:39:09
4860 +++ rsync.h 2006-01-23 21:24:53
4861 @@ -648,6 +648,46 @@ struct chmod_mode_struct;
4862 #include "lib/permstring.h"
4863 #include "lib/addrinfo.h"
4865 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4866 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4867 +#define SUPPORT_ACLS 1
4870 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4871 +#define ACLS_NEED_MASK 1
4874 +#ifdef SUPPORT_ACLS
4875 +#ifdef HAVE_SYS_ACL_H
4876 +#include <sys/acl.h>
4878 +#define MAKE_ACL(file, fname) make_acl(file, fname)
4879 +#define SEND_ACL(file, f) send_acl(file, f)
4880 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
4881 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4882 +#define SET_ACL(fname, file) set_acl(fname, file)
4883 +#define NEXT_ACL_UID() next_acl_uid()
4884 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
4885 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4886 + push_keep_backup_acl(file, orig, dest)
4887 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4888 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4889 +#define DEFAULT_MODE_FOR_DIR(dir) default_mode_for_dir_acl(dir)
4890 +#else /* SUPPORT_ACLS */
4891 +#define MAKE_ACL(file, fname) 1 /* checked return value */
4892 +#define SEND_ACL(file, f)
4893 +#define RECEIVE_ACL(file, f)
4894 +#define SORT_FILE_ACL_INDEX_LISTS()
4895 +#define SET_ACL(fname, file) 1 /* checked return value */
4896 +#define NEXT_ACL_UID()
4897 +#define ACL_UID_MAP(uid)
4898 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4899 +#define CLEANUP_KEEP_BACKUP_ACL()
4900 +#define DUP_ACL(src, orig, mode) 1 /* checked return value */
4901 +#define DEFAULT_MODE_FOR_DIR(dir) (ACCESSPERMS & ~orig_umask)
4902 +#endif /* SUPPORT_ACLS */
4903 +#include "smb_acls.h"
4907 /* We have replacement versions of these if they're missing. */
4908 --- orig/rsync.yo 2006-01-31 03:05:44
4909 +++ rsync.yo 2006-01-31 03:14:05
4910 @@ -317,6 +317,7 @@ to the detailed description below for a
4911 -K, --keep-dirlinks treat symlinked dir on receiver as dir
4912 -p, --perms preserve permissions
4913 -E, --executability preserve executability
4914 + -A, --acls preserve ACLs (implies -p) [non-standard]
4915 --chmod=CHMOD change destination permissions
4916 -o, --owner preserve owner (super-user only)
4917 -g, --group preserve group
4918 @@ -691,14 +692,23 @@ quote(itemize(
4919 permissions, though the bf(--executability) option might change just
4920 the execute permission for the file.
4921 it() Each new file gets its permissions set based on the source file's
4922 - permissions, but masked by the receiving end's umask setting (including
4923 + permissions, but masked by the receiving end's destination-default
4924 + permissions (which is either based on the ACL of the destination
4925 + directory, if available, or the receiving end's umask setting) and
4927 the stripping of the three special permission bits).
4928 + Hint: Using bf(--chmod=ugo=rwX) without bf(--perms) will cause new
4929 + files to get all the destination-default permissions.
4932 Thus, when bf(--perms) and bf(--executability) are both disabled,
4933 rsync's behavior is the same as that of other file-copy utilities,
4934 such as bf(cp)(1) and bf(tar)(1).
4936 +This version of rsync observes default ACLs; patched versions of rsync only
4937 +applied the umask, and could thus set wrong permissions in the presence of
4940 dit(bf(-E, --executability)) This option causes rsync to preserve the
4941 executability (or non-executability) of regular files when bf(--perms) is
4942 not enabled. A regular file is considered to be executable if at least one
4943 @@ -713,6 +723,10 @@ quote(itemize(
4945 If bf(--perms) is enabled, this option is ignored.
4947 +dit(bf(-A, --acls)) This option causes rsync to update the destination
4948 +ACLs to be the same as the source ACLs. This nonstandard option only
4949 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
4951 dit(bf(--chmod)) This option tells rsync to apply one or more
4952 comma-separated "chmod" strings to the permission of the files in the
4953 transfer. The resulting value is treated as though it was the permissions
4954 --- orig/runtests.sh 2005-08-17 06:45:08
4955 +++ runtests.sh 2006-01-23 21:24:53
4956 @@ -195,6 +195,9 @@ export scratchdir suitedir
4958 [ -d "$scratchdir" ] && rm -rf "$scratchdir"
4960 + # Get rid of default ACLs and directory setgid because they confuse some tests.
4961 + setfacl -k "$scratchdir" || true
4962 + chmod g-s "$scratchdir"
4966 --- orig/smb_acls.h 2004-06-30 00:04:07
4967 +++ smb_acls.h 2004-06-30 00:04:07
4970 + Unix SMB/Netbios implementation.
4972 + Portable SMB ACL interface
4973 + Copyright (C) Jeremy Allison 2000
4975 + This program is free software; you can redistribute it and/or modify
4976 + it under the terms of the GNU General Public License as published by
4977 + the Free Software Foundation; either version 2 of the License, or
4978 + (at your option) any later version.
4980 + This program is distributed in the hope that it will be useful,
4981 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4982 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4983 + GNU General Public License for more details.
4985 + You should have received a copy of the GNU General Public License
4986 + along with this program; if not, write to the Free Software
4987 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4990 +#ifndef _SMB_ACLS_H
4991 +#define _SMB_ACLS_H
4993 +#if defined(HAVE_POSIX_ACLS)
4995 +/* This is an identity mapping (just remove the SMB_). */
4997 +#define SMB_ACL_TAG_T acl_tag_t
4998 +#define SMB_ACL_TYPE_T acl_type_t
4999 +#define SMB_ACL_PERMSET_T acl_permset_t
5000 +#define SMB_ACL_PERM_T acl_perm_t
5001 +#define SMB_ACL_READ ACL_READ
5002 +#define SMB_ACL_WRITE ACL_WRITE
5003 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5005 +/* Types of ACLs. */
5006 +#define SMB_ACL_USER ACL_USER
5007 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5008 +#define SMB_ACL_GROUP ACL_GROUP
5009 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5010 +#define SMB_ACL_OTHER ACL_OTHER
5011 +#define SMB_ACL_MASK ACL_MASK
5013 +#define SMB_ACL_T acl_t
5015 +#define SMB_ACL_ENTRY_T acl_entry_t
5017 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5018 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5020 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5021 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5023 +#elif defined(HAVE_TRU64_ACLS)
5025 +/* This is for DEC/Compaq Tru64 UNIX */
5027 +#define SMB_ACL_TAG_T acl_tag_t
5028 +#define SMB_ACL_TYPE_T acl_type_t
5029 +#define SMB_ACL_PERMSET_T acl_permset_t
5030 +#define SMB_ACL_PERM_T acl_perm_t
5031 +#define SMB_ACL_READ ACL_READ
5032 +#define SMB_ACL_WRITE ACL_WRITE
5033 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5035 +/* Types of ACLs. */
5036 +#define SMB_ACL_USER ACL_USER
5037 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5038 +#define SMB_ACL_GROUP ACL_GROUP
5039 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5040 +#define SMB_ACL_OTHER ACL_OTHER
5041 +#define SMB_ACL_MASK ACL_MASK
5043 +#define SMB_ACL_T acl_t
5045 +#define SMB_ACL_ENTRY_T acl_entry_t
5047 +#define SMB_ACL_FIRST_ENTRY 0
5048 +#define SMB_ACL_NEXT_ENTRY 1
5050 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5051 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5053 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
5055 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5056 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5059 +/* SVR4.2 ES/MP ACLs */
5060 +typedef int SMB_ACL_TAG_T;
5061 +typedef int SMB_ACL_TYPE_T;
5062 +typedef ushort *SMB_ACL_PERMSET_T;
5063 +typedef ushort SMB_ACL_PERM_T;
5064 +#define SMB_ACL_READ 4
5065 +#define SMB_ACL_WRITE 2
5066 +#define SMB_ACL_EXECUTE 1
5068 +/* Types of ACLs. */
5069 +#define SMB_ACL_USER USER
5070 +#define SMB_ACL_USER_OBJ USER_OBJ
5071 +#define SMB_ACL_GROUP GROUP
5072 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5073 +#define SMB_ACL_OTHER OTHER_OBJ
5074 +#define SMB_ACL_MASK CLASS_OBJ
5076 +typedef struct SMB_ACL_T {
5080 + struct acl acl[1];
5083 +typedef struct acl *SMB_ACL_ENTRY_T;
5085 +#define SMB_ACL_FIRST_ENTRY 0
5086 +#define SMB_ACL_NEXT_ENTRY 1
5088 +#define SMB_ACL_TYPE_ACCESS 0
5089 +#define SMB_ACL_TYPE_DEFAULT 1
5091 +#elif defined(HAVE_HPUX_ACLS)
5094 + * Based on the Solaris & UnixWare code.
5098 +#include <sys/aclv.h>
5100 +/* SVR4.2 ES/MP ACLs */
5101 +typedef int SMB_ACL_TAG_T;
5102 +typedef int SMB_ACL_TYPE_T;
5103 +typedef ushort *SMB_ACL_PERMSET_T;
5104 +typedef ushort SMB_ACL_PERM_T;
5105 +#define SMB_ACL_READ 4
5106 +#define SMB_ACL_WRITE 2
5107 +#define SMB_ACL_EXECUTE 1
5109 +/* Types of ACLs. */
5110 +#define SMB_ACL_USER USER
5111 +#define SMB_ACL_USER_OBJ USER_OBJ
5112 +#define SMB_ACL_GROUP GROUP
5113 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5114 +#define SMB_ACL_OTHER OTHER_OBJ
5115 +#define SMB_ACL_MASK CLASS_OBJ
5117 +typedef struct SMB_ACL_T {
5121 + struct acl acl[1];
5124 +typedef struct acl *SMB_ACL_ENTRY_T;
5126 +#define SMB_ACL_FIRST_ENTRY 0
5127 +#define SMB_ACL_NEXT_ENTRY 1
5129 +#define SMB_ACL_TYPE_ACCESS 0
5130 +#define SMB_ACL_TYPE_DEFAULT 1
5132 +#elif defined(HAVE_IRIX_ACLS)
5134 +#define SMB_ACL_TAG_T acl_tag_t
5135 +#define SMB_ACL_TYPE_T acl_type_t
5136 +#define SMB_ACL_PERMSET_T acl_permset_t
5137 +#define SMB_ACL_PERM_T acl_perm_t
5138 +#define SMB_ACL_READ ACL_READ
5139 +#define SMB_ACL_WRITE ACL_WRITE
5140 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5142 +/* Types of ACLs. */
5143 +#define SMB_ACL_USER ACL_USER
5144 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5145 +#define SMB_ACL_GROUP ACL_GROUP
5146 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5147 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5148 +#define SMB_ACL_MASK ACL_MASK
5150 +typedef struct SMB_ACL_T {
5156 +#define SMB_ACL_ENTRY_T acl_entry_t
5158 +#define SMB_ACL_FIRST_ENTRY 0
5159 +#define SMB_ACL_NEXT_ENTRY 1
5161 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5162 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5164 +#elif defined(HAVE_AIX_ACLS)
5166 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5168 +#include "/usr/include/acl.h"
5170 +typedef uint *SMB_ACL_PERMSET_T;
5172 +struct acl_entry_link{
5173 + struct acl_entry_link *prevp;
5174 + struct new_acl_entry *entryp;
5175 + struct acl_entry_link *nextp;
5179 +struct new_acl_entry{
5180 + unsigned short ace_len;
5181 + unsigned short ace_type;
5182 + unsigned int ace_access;
5183 + struct ace_id ace_id[1];
5186 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5187 +#define SMB_ACL_T struct acl_entry_link*
5189 +#define SMB_ACL_TAG_T unsigned short
5190 +#define SMB_ACL_TYPE_T int
5191 +#define SMB_ACL_PERM_T uint
5192 +#define SMB_ACL_READ S_IRUSR
5193 +#define SMB_ACL_WRITE S_IWUSR
5194 +#define SMB_ACL_EXECUTE S_IXUSR
5196 +/* Types of ACLs. */
5197 +#define SMB_ACL_USER ACEID_USER
5198 +#define SMB_ACL_USER_OBJ 3
5199 +#define SMB_ACL_GROUP ACEID_GROUP
5200 +#define SMB_ACL_GROUP_OBJ 4
5201 +#define SMB_ACL_OTHER 5
5202 +#define SMB_ACL_MASK 6
5205 +#define SMB_ACL_FIRST_ENTRY 1
5206 +#define SMB_ACL_NEXT_ENTRY 2
5208 +#define SMB_ACL_TYPE_ACCESS 0
5209 +#define SMB_ACL_TYPE_DEFAULT 1
5211 +#else /* No ACLs. */
5213 +/* No ACLS - fake it. */
5214 +#define SMB_ACL_TAG_T int
5215 +#define SMB_ACL_TYPE_T int
5216 +#define SMB_ACL_PERMSET_T mode_t
5217 +#define SMB_ACL_PERM_T mode_t
5218 +#define SMB_ACL_READ S_IRUSR
5219 +#define SMB_ACL_WRITE S_IWUSR
5220 +#define SMB_ACL_EXECUTE S_IXUSR
5222 +/* Types of ACLs. */
5223 +#define SMB_ACL_USER 0
5224 +#define SMB_ACL_USER_OBJ 1
5225 +#define SMB_ACL_GROUP 2
5226 +#define SMB_ACL_GROUP_OBJ 3
5227 +#define SMB_ACL_OTHER 4
5228 +#define SMB_ACL_MASK 5
5230 +typedef struct SMB_ACL_T {
5234 +typedef struct SMB_ACL_ENTRY_T {
5236 +} *SMB_ACL_ENTRY_T;
5238 +#define SMB_ACL_FIRST_ENTRY 0
5239 +#define SMB_ACL_NEXT_ENTRY 1
5241 +#define SMB_ACL_TYPE_ACCESS 0
5242 +#define SMB_ACL_TYPE_DEFAULT 1
5244 +#endif /* No ACLs. */
5245 +#endif /* _SMB_ACLS_H */
5246 --- orig/testsuite/default-acls-obey.test 2005-10-15 16:08:45
5247 +++ testsuite/default-acls-obey.test 2005-10-15 16:08:45
5251 +# This program is distributable under the terms of the GNU GPL see
5254 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5256 +. $srcdir/testsuite/rsync.fns
5260 +$RSYNC --help | grep -q "ACLs" || test_skipped "Rsync is configured without ACL support"
5261 +setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5263 +echo "File!" >"$scratchdir/file"
5264 +echo "#!/bin/bash" >"$scratchdir/program"
5265 +chmod 666 "$scratchdir/file"
5266 +chmod 777 "$scratchdir/program"
5268 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5270 + todir="$scratchdir/$1"
5272 + setfacl -k "$todir"
5273 + chmod g-s "$todir" ### Don't let directory setgid interfere
5274 + [ "$2" ] && setfacl -dm "$2" "$todir"
5275 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5276 + # even though the directory itself is outside the transfer
5277 + $RSYNC -rvv "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5278 + [ `stat --format=%a "$todir/to"` == $4 ] || test_fail "Target $1: to should have $4 permissions"
5279 + [ `stat --format=%a "$todir/to/file"` == $3 ] || test_fail "Target $1: to/file should have $3 permissions"
5280 + [ `stat --format=%a "$todir/to/program"` == $4 ] || test_fail "Target $1: to/program should have $4 permissions"
5281 + # Make sure get_local_name doesn't mess us up when transferring only one file
5282 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5283 + [ `stat --format=%a "$todir/to/anotherfile"` == $3 ] || test_fail "Target $1: to/anotherfile should have $3 permissions"
5286 +# Test some target directories
5288 +testit da777 u::rwx,g::rwx,o::rwx 666 777
5289 +testit da775 u::rwx,g::rwx,o::r-x 664 775
5290 +testit da750 u::rwx,g::r-x,o::--- 640 750
5291 +testit da770mask u::rwx,g::---,m::rwx,o::--- 660 770
5292 +testit noda1 '' 600 700
5294 +testit noda2 '' 666 777
5296 +testit noda3 '' 644 755
5300 --- orig/uidlist.c 2006-01-25 17:15:13
5301 +++ uidlist.c 2006-01-25 17:45:21
5304 extern int preserve_uid;
5305 extern int preserve_gid;
5306 +extern int preserve_acls;
5307 extern int numeric_ids;
5310 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5314 - if (preserve_uid) {
5315 + if (preserve_uid || preserve_acls) {
5317 /* we send sequences of uid/byte-length/name */
5318 for (list = uidlist; list; list = list->next) {
5319 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5323 - if (preserve_gid) {
5324 + if (preserve_gid || preserve_acls) {
5326 for (list = gidlist; list; list = list->next) {
5328 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5332 - if (preserve_uid && !numeric_ids) {
5333 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5334 /* read the uid list */
5335 while ((id = read_int(f)) != 0) {
5336 int len = read_byte(f);
5337 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5341 - if (preserve_gid && !numeric_ids) {
5342 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5343 /* read the gid list */
5344 while ((id = read_int(f)) != 0) {
5345 int len = read_byte(f);
5346 @@ -336,6 +337,18 @@ void recv_uid_list(int f, struct file_li
5350 +#ifdef SUPPORT_ACLS
5351 + if (preserve_acls && !numeric_ids) {
5353 + /* The enumerations don't return 0 except to flag the last
5354 + * entry, since uidlist doesn't munge 0 anyway. */
5355 + while ((id = next_acl_uid(flist)) != 0)
5356 + acl_uid_map(match_uid(id));
5357 + while ((id = next_acl_gid(flist)) != 0)
5358 + acl_gid_map(match_gid(id));
5360 +#endif /* SUPPORT_ACLS */
5362 /* Now convert all the uids/gids from sender values to our values. */
5363 if (am_root && preserve_uid && !numeric_ids) {
5364 for (i = 0; i < flist->count; i++)