1 After applying this patch, run these commands for a successful build:
5 ./configure --with-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 --- orig/Makefile.in 2004-11-02 16:47:15
15 +++ Makefile.in 2004-10-20 06:32:26
16 @@ -25,16 +25,16 @@ VERSION=@VERSION@
20 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
21 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
22 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
23 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
24 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
25 ZLIBOBJ=zlib/deflate.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o \
26 zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
27 zlib/zutil.o zlib/adler32.o
28 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
29 main.o checksum.o match.o syscall.o log.o backup.o
30 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
31 - fileio.o batch.o clientname.o
32 + fileio.o batch.o clientname.o acls.o
33 OBJS3=progress.o pipe.o
34 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
35 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
36 --- orig/acls.c 2005-05-12 23:30:45
37 +++ acls.c 2005-05-12 23:30:45
39 +/* -*- c-file-style: "linux" -*-
40 + Copyright (C) Andrew Tridgell 1996
41 + Copyright (C) Paul Mackerras 1996
43 + This program is free software; you can redistribute it and/or modify
44 + it under the terms of the GNU General Public License as published by
45 + the Free Software Foundation; either version 2 of the License, or
46 + (at your option) any later version.
48 + This program is distributed in the hope that it will be useful,
49 + but WITHOUT ANY WARRANTY; without even the implied warranty of
50 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 + GNU General Public License for more details.
53 + You should have received a copy of the GNU General Public License
54 + along with this program; if not, write to the Free Software
55 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
58 +/* handle passing ACLs between systems */
61 +#include "lib/sysacls.h"
65 +extern int preserve_acls;
72 + SMB_ACL_TAG_T tag_type;
81 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
83 +static void expand_rsync_acl(rsync_acl *racl)
85 + /* first time through, 0 <= 0, so list is expanded:
86 + * diabolical, rsync guys! */
87 + if (racl->malloced <= racl->count) {
89 + size_t new_size = racl->malloced + 10;
90 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
92 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
93 + (double) new_size * sizeof racl->races[0],
94 + racl->races ? "" : " not");
97 + racl->races = new_ptr;
98 + racl->malloced = new_size;
101 + out_of_memory("expand_rsync_acl");
105 +static void rsync_acl_free(rsync_acl *racl)
108 + racl->races = NULL;
110 + racl->malloced = 0;
113 +static int rsync_ace_sorter(const void *r1, const void *r2)
115 + rsync_ace *race1 = (rsync_ace *)r1;
116 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
117 + id_t rid1 = race1->id;
118 + rsync_ace *race2 = (rsync_ace *)r2;
119 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
120 + id_t rid2 = race2->id;
121 + /* start at the extrema */
122 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
124 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
127 + if (rtag1 == SMB_ACL_OTHER)
129 + if (rtag2 == SMB_ACL_OTHER)
131 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
132 + if (rtag1 == SMB_ACL_USER) {
134 + case SMB_ACL_GROUP:
135 + case SMB_ACL_GROUP_OBJ:
136 + case SMB_ACL_OTHER:
140 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
142 + if (rtag2 == SMB_ACL_USER)
144 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
145 + if (rtag1 == SMB_ACL_GROUP_OBJ)
147 + if (rtag2 == SMB_ACL_GROUP_OBJ)
149 + /* only SMB_ACL_GROUPs left */
150 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
153 +static void sort_rsync_acl(rsync_acl *racl)
157 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
158 + &rsync_ace_sorter);
161 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
163 + SMB_ACL_ENTRY_T entry;
165 + const char *errfun;
166 + *racl = rsync_acl_initializer;
167 + errfun = "sys_acl_get_entry";
168 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
170 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
171 + SMB_ACL_PERMSET_T permset;
174 + expand_rsync_acl(racl);
175 + race = &racl->races[racl->count++];
176 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
177 + errfun = "sys_acl_get_tag_type";
180 + if ((rc = sys_acl_get_permset(entry, &permset))) {
181 + errfun = "sys_acl_get_tag_type";
184 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
185 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
186 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
187 + switch (race->tag_type) {
189 + case SMB_ACL_GROUP:
194 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
195 + errfun = "sys_acl_get_tag_type";
199 + race->id = *((id_t *)qualifier);
200 + sys_acl_free_qualifier(qualifier, race->tag_type);
203 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
204 + errfun, strerror(errno));
205 + rsync_acl_free(racl);
208 + sort_rsync_acl(racl);
212 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
214 + rsync_ace *race1, *race2;
215 + size_t count = racl1->count;
216 + if (count != racl2->count)
218 + race1 = racl1->races;
219 + race2 = racl2->races;
220 + for (; count--; race1++, race2++) {
221 + if (race1->tag_type != race2->tag_type
222 + || race1->access != race2->access
223 + || ((race1->tag_type == SMB_ACL_USER
224 + || race1->tag_type == SMB_ACL_GROUP)
225 + && race1->id != race2->id))
237 +static rsync_acl_list _rsync_acl_lists[] = {
238 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
239 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
242 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
244 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
245 + : &_rsync_acl_lists[1];
248 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
250 + /* first time through, 0 <= 0, so list is expanded:
251 + * diabolical, rsync guys! */
252 + if (racl_list->malloced <= racl_list->count) {
253 + rsync_acl *new_ptr;
255 + if (racl_list->malloced < 1000)
256 + new_size = racl_list->malloced + 1000;
258 + new_size = racl_list->malloced * 2;
259 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
260 + if (verbose >= 3) {
261 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
262 + (double) new_size * sizeof racl_list->racls[0],
263 + racl_list->racls ? "" : " not");
266 + racl_list->racls = new_ptr;
267 + racl_list->malloced = new_size;
269 + if (!racl_list->racls)
270 + out_of_memory("expand_rsync_acl_list");
275 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
277 + /* run this in reverse, so references are freed before referents, */
278 + /* although not currently necessary */
279 + while (racl_list->count--) {
280 + rsync_acl *racl = &racl_list->racls[racl_list->count];
282 + rsync_acl_free(racl);
284 + free(racl_list->racls);
285 + racl_list->racls = NULL;
286 + racl_list->malloced = 0;
290 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
291 + const rsync_acl_list *racl_list,
292 + const rsync_acl *racl)
294 + static int access_match = -1, default_match = -1;
295 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
296 + &access_match : &default_match;
297 + size_t count = racl_list->count;
298 + /* if this is the first time through or we didn't match the last
299 + * time, then start at the end of the list, which should be the
300 + * best place to start hunting */
302 + *match = racl_list->count - 1;
304 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
307 + *match = racl_list->count - 1;
313 +/* the general strategy with the tag_type <-> character mapping is that
314 + * lowercase implies that no qualifier follows, where uppercase does.
315 + * same sorta thing for the acl type (access or default) itself, but
316 + * lowercase in this instance means there's no ACL following, so the
317 + * ACL is a repeat, so the receiver should reuse the last of the same
320 +static void send_rsync_acl(int f, const rsync_acl *racl)
323 + size_t count = racl->count;
324 + write_int(f, count);
325 + for (race = racl->races; count--; race++) {
327 + switch (race->tag_type) {
328 + case SMB_ACL_USER_OBJ:
334 + case SMB_ACL_GROUP_OBJ:
337 + case SMB_ACL_GROUP:
340 + case SMB_ACL_OTHER:
348 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
353 + write_byte(f, race->access);
354 + if (isupper((int)ch)) {
355 + write_int(f, race->id);
356 + /* FIXME: sorta wasteful. we should maybe buffer as
357 + * many ids as max(ACL_USER + ACL_GROUP) objects to
358 + * keep from making so many calls */
367 +static rsync_acl _curr_rsync_acls[2];
370 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
372 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
373 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
374 + "unknown SMB_ACL_TYPE_T";
377 +/* generate the ACL(s) for this flist entry;
378 + * ACL(s) are either sent or cleaned-up by send_acl() below */
380 +BOOL make_acl(const struct file_struct *file, const char *fname)
382 + SMB_ACL_TYPE_T *type,
383 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
384 + rsync_acl *curr_racl;
385 + if (!preserve_acls || S_ISLNK(file->mode))
387 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
388 + type < &types[0] + sizeof types / sizeof types[0]
389 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
390 + type++, curr_racl++) {
393 + *curr_racl = rsync_acl_initializer;
394 + if (!(sacl = sys_acl_get_file(fname, *type))) {
395 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
396 + fname, str_acl_type(*type), strerror(errno));
399 + ok = unpack_smb_acl(curr_racl, sacl);
400 + sys_acl_free_acl(sacl);
407 +/* send the make_acl()-generated ACLs for this flist entry,
408 + * or clean up after an flist entry that's not being sent (f == -1) */
410 +void send_acl(const struct file_struct *file, int f)
412 + SMB_ACL_TYPE_T *type,
413 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
414 + rsync_acl *curr_racl;
415 + if (!preserve_acls || S_ISLNK(file->mode))
417 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
418 + type < &types[0] + sizeof types / sizeof types[0]
419 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
420 + type++, curr_racl++) {
422 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
424 + rsync_acl_free(curr_racl);
427 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
429 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
430 + write_int(f, index);
431 + rsync_acl_free(curr_racl);
433 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
434 + send_rsync_acl(f, curr_racl);
435 + expand_rsync_acl_list(racl_list);
436 + racl_list->racls[racl_list->count++] = *curr_racl;
441 +/* the below stuff is only used by the receiver */
443 +/* structure to hold index to rsync_acl_list member corresponding to
444 + * flist->files[i] */
447 + const struct file_struct *file;
454 + file_acl_index *fileaclidxs;
455 +} file_acl_index_list;
457 +static file_acl_index_list _file_acl_index_lists[] = {
458 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
459 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
462 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
464 + return type == SMB_ACL_TYPE_ACCESS ?
465 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
468 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
470 + /* first time through, 0 <= 0, so list is expanded:
471 + * diabolical, rsync guys! */
472 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
473 + file_acl_index *new_ptr;
475 + if (fileaclidx_list->malloced < 1000)
476 + new_size = fileaclidx_list->malloced + 1000;
478 + new_size = fileaclidx_list->malloced * 2;
479 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
480 + if (verbose >= 3) {
481 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
482 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
483 + fileaclidx_list->fileaclidxs ? "" : " not");
486 + fileaclidx_list->fileaclidxs = new_ptr;
487 + fileaclidx_list->malloced = new_size;
489 + if (!fileaclidx_list->fileaclidxs)
490 + out_of_memory("expand_file_acl_index_list");
495 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
497 + free(fileaclidx_list->fileaclidxs);
498 + fileaclidx_list->fileaclidxs = NULL;
499 + fileaclidx_list->malloced = 0;
503 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
511 +static smb_acl_list _smb_acl_lists[] = {
512 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
513 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
516 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
518 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
519 + &_smb_acl_lists[1];
522 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
524 + /* first time through, 0 <= 0, so list is expanded:
525 + * diabolical, rsync guys! */
526 + if (sacl_list->malloced <= sacl_list->count) {
527 + SMB_ACL_T *new_ptr;
529 + if (sacl_list->malloced < 1000)
530 + new_size = sacl_list->malloced + 1000;
532 + new_size = sacl_list->malloced * 2;
533 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
534 + if (verbose >= 3) {
535 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
536 + (double) new_size * sizeof sacl_list->sacls[0],
537 + sacl_list->sacls ? "" : " not");
540 + sacl_list->sacls = new_ptr;
541 + sacl_list->malloced = new_size;
543 + if (!sacl_list->sacls)
544 + out_of_memory("expand_smb_acl_list");
549 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
551 + smb_acl_list *sacl_list = smb_acl_lists(type);
552 + SMB_ACL_T *sacl = sacl_list->sacls;
553 + while (sacl_list->count--) {
555 + sys_acl_free_acl(*sacl++);
557 + free(sacl_list->sacls);
558 + sacl_list->sacls = NULL;
559 + sacl_list->malloced = 0;
563 +/* build an SMB_ACL_T corresponding to an rsync_acl */
564 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
566 + size_t count = racl->count;
567 + rsync_ace *race = racl->races;
568 + const char *errfun = NULL;
569 + *smb_acl = sys_acl_init(count);
571 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
575 + for (; count--; race++) {
576 + SMB_ACL_ENTRY_T entry;
577 + SMB_ACL_PERMSET_T permset;
578 + if (sys_acl_create_entry(smb_acl, &entry)) {
579 + errfun = "sys_acl_create)";
582 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
583 + errfun = "sys_acl_set_tag";
586 + if (race->tag_type == SMB_ACL_USER ||
587 + race->tag_type == SMB_ACL_GROUP)
588 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
589 + errfun = "sys_acl_set_qualfier";
592 + if (sys_acl_get_permset(entry, &permset)) {
593 + errfun = "sys_acl_get_permset";
596 + if (sys_acl_clear_perms(permset)) {
597 + errfun = "sys_acl_clear_perms";
600 + if (race->access & 4)
601 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
602 + errfun = "sys_acl_add_perm";
605 + if (race->access & 2)
606 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
607 + errfun = "sys_acl_add_perm";
610 + if (race->access & 1)
611 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
612 + errfun = "sys_acl_add_perm";
615 + if (sys_acl_set_permset(entry, permset)) {
616 + errfun = "sys_acl_set_permset";
621 + sys_acl_free_acl(*smb_acl);
622 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
629 +static void receive_rsync_acl(rsync_acl *racl, int f)
632 + uchar required_mask_perm = 0;
634 + BOOL saw_mask = False;
635 + BOOL saw_user_obj = False, saw_group_obj = False,
637 + size_t count = read_int(f);
642 + uchar tag = read_byte(f);
643 + expand_rsync_acl(racl);
644 + race = &racl->races[racl->count++];
647 + race->tag_type = SMB_ACL_USER_OBJ;
648 + saw_user_obj = True;
651 + race->tag_type = SMB_ACL_USER;
654 + race->tag_type = SMB_ACL_GROUP_OBJ;
655 + saw_group_obj = True;
658 + race->tag_type = SMB_ACL_GROUP;
661 + race->tag_type = SMB_ACL_OTHER;
665 + race->tag_type = SMB_ACL_MASK;
669 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
671 + exit_cleanup(RERR_STREAMIO);
673 + race->access = read_byte(f);
674 + if (race->access & ~ (4 | 2 | 1)) {
675 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
677 + exit_cleanup(RERR_STREAMIO);
679 + if (race->tag_type == SMB_ACL_USER ||
680 + race->tag_type == SMB_ACL_GROUP) {
681 + race->id = read_int(f);
683 + required_mask_perm |= race->access;
687 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
688 + required_mask_perm |= race->access;
692 + if (!saw_user_obj) {
693 + expand_rsync_acl(racl);
694 + race = &racl->races[racl->count++];
695 + race->tag_type = SMB_ACL_USER_OBJ;
698 + if (!saw_group_obj) {
699 + expand_rsync_acl(racl);
700 + race = &racl->races[racl->count++];
701 + race->tag_type = SMB_ACL_GROUP_OBJ;
705 + expand_rsync_acl(racl);
706 + race = &racl->races[racl->count++];
707 + race->tag_type = SMB_ACL_OTHER;
712 + expand_rsync_acl(racl);
713 + race = &racl->races[racl->count++];
714 + race->tag_type = SMB_ACL_MASK;
715 + race->access = required_mask_perm;
718 + /* If we, a system without ACLS_NEED_MASK, received data from a
719 + * system that has masks, throw away the extraneous CLASS_OBJs. */
720 + if (saw_mask && racl->count == 4) {
721 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
724 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
725 + if (p->tag_type == SMB_ACL_MASK)
727 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
728 + group_obj_race = p;
730 + if (mask_race == NULL || group_obj_race == NULL) {
731 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
732 + "and one's ACL_MASK but missing "
733 + "either it or ACL_GROUP_OBJ, "
734 + "when pruning ACL\n");
736 + /* mask off group perms with it first */
737 + group_obj_race->access &= mask_race->access;
738 + /* dump mask_race; re-slot any followers-on */
740 + if (mask_race != &racl->races[racl->count]) {
741 + *mask_race = racl->races[racl->count];
742 + saw_user_obj = False; /* force re-sort */
748 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
750 + if (!(saw_user_obj && saw_group_obj && saw_other))
752 + sort_rsync_acl(racl);
755 +/* receive and build the rsync_acl_lists */
757 +void receive_acl(struct file_struct *file, int f)
759 + SMB_ACL_TYPE_T *type,
760 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
762 + if (!preserve_acls || S_ISLNK(file->mode))
764 + fname = f_name(file);
765 + for (type = &types[0];
766 + type < &types[0] + sizeof types / sizeof types[0]
767 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
769 + file_acl_index_list *fileaclidx_list =
770 + file_acl_index_lists(*type);
772 + expand_file_acl_index_list(fileaclidx_list);
774 + tag = read_byte(f);
775 + if (tag == 'A' || tag == 'a') {
776 + if (*type != SMB_ACL_TYPE_ACCESS) {
777 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
779 + exit_cleanup(RERR_STREAMIO);
781 + } else if (tag == 'D' || tag == 'd') {
782 + if (*type == SMB_ACL_TYPE_ACCESS) {
783 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
785 + exit_cleanup(RERR_STREAMIO);
788 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
790 + exit_cleanup(RERR_STREAMIO);
792 + if (tag == 'A' || tag == 'D') {
793 + rsync_acl racl = rsync_acl_initializer;
794 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
795 + smb_acl_list *sacl_list = smb_acl_lists(*type);
796 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
797 + aclidx = racl_list->count;
798 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
800 + receive_rsync_acl(&racl, f);
801 + expand_rsync_acl_list(racl_list);
802 + racl_list->racls[racl_list->count++] = racl;
803 + expand_smb_acl_list(sacl_list);
804 + sacl_list->sacls[sacl_list->count++] = NULL;
806 + int index = read_int(f);
807 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
808 + if ((size_t) index >= racl_list->count) {
809 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
811 + str_acl_type(*type),
813 + exit_cleanup(RERR_STREAMIO);
815 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
817 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
823 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
825 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
826 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
827 + return fileaclidx1->file == fileaclidx2->file ? 0 :
828 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
831 +void sort_file_acl_index_lists()
833 + SMB_ACL_TYPE_T *type,
834 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
835 + if (!preserve_acls)
837 + for (type = &types[0];
838 + type < &types[0] + sizeof types / sizeof types[0];
841 + file_acl_index_list *fileaclidx_list =
842 + file_acl_index_lists(*type);
843 + if (!fileaclidx_list->count)
845 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
846 + sizeof fileaclidx_list->fileaclidxs[0],
847 + &file_acl_index_list_sorter);
851 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
852 + const struct file_struct *file) {
853 + int low = 0, high = fileaclidx_list->count;
854 + const struct file_struct *file_mid;
858 + int mid = (high + low) / 2;
859 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
860 + if (file_mid == file)
861 + return fileaclidx_list->fileaclidxs[mid].aclidx;
862 + if (file_mid > file)
866 + } while (low < high);
868 + file_mid = fileaclidx_list->fileaclidxs[low].file;
869 + if (file_mid == file)
870 + return fileaclidx_list->fileaclidxs[low].aclidx;
873 + "find_file_acl_index: can't find entry for file in list\n");
874 + exit_cleanup(RERR_STREAMIO);
878 +/* for duplicating ACLs on backups when using backup_dir */
880 +int dup_acl(const char *orig, const char *bak, mode_t mode)
882 + SMB_ACL_TYPE_T *type,
883 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
885 + if (!preserve_acls)
887 + for (type = &types[0];
888 + type < &types[0] + sizeof types / sizeof types[0]
889 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
891 + SMB_ACL_T sacl_orig, sacl_bak;
892 + rsync_acl racl_orig, racl_bak;
893 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
894 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
895 + orig, str_acl_type(*type), strerror(errno));
899 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
900 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
901 + bak, str_acl_type(*type), strerror(errno));
903 + /* try to forge on through */
905 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
907 + goto out_with_sacls;
910 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
912 + goto out_with_one_racl;
914 + if (rsync_acls_equal(&racl_orig, &racl_bak))
917 + ; /* presume they're unequal */
919 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
920 + if (-1 == sys_acl_delete_def_file(bak)) {
921 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
922 + bak, strerror(errno));
925 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
926 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
927 + bak, str_acl_type(*type), strerror(errno));
932 + rsync_acl_free(&racl_bak);
934 + rsync_acl_free(&racl_orig);
937 + sys_acl_free_acl(sacl_bak);
938 + /* out_with_one_sacl: */
940 + sys_acl_free_acl(sacl_orig);
945 +/* stuff for redirecting calls to set_acl() from set_perms()
946 + * for keep_backup() */
947 +static const struct file_struct *backup_orig_file = NULL;
948 +static const char null_string[] = "";
949 +static const char *backup_orig_fname = null_string;
950 +static const char *backup_dest_fname = null_string;
951 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
953 +void push_keep_backup_acl(const struct file_struct *file,
954 + const char *orig, const char *dest)
956 + if (preserve_acls) {
957 + SMB_ACL_TYPE_T *type,
958 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
960 + backup_orig_file = file;
961 + backup_orig_fname = orig;
962 + backup_dest_fname = dest;
963 + for (type = &types[0], sacl = &_backup_sacl[0];
964 + type < &types[0] + sizeof types / sizeof types[0];
966 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
969 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
970 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
971 + orig, str_acl_type(*type),
979 +static int set_keep_backup_acl()
981 + if (preserve_acls) {
982 + SMB_ACL_TYPE_T *type,
983 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
986 + for (type = &types[0], sacl = &_backup_sacl[0];
987 + type < &types[0] + sizeof types / sizeof types[0];
990 + if (-1 == sys_acl_set_file(backup_dest_fname,
993 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
995 + str_acl_type(*type),
1006 +void cleanup_keep_backup_acl()
1008 + if (preserve_acls) {
1009 + SMB_ACL_TYPE_T *type,
1010 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1012 + backup_orig_file = NULL;
1013 + backup_orig_fname = null_string;
1014 + backup_dest_fname = null_string;
1015 + for (type = &types[0], sacl = &_backup_sacl[0];
1016 + type < &types[0] + sizeof types / sizeof types[0];
1019 + sys_acl_free_acl(*sacl);
1025 +/* set ACL on rsync-ed or keep_backup-ed file */
1027 +int set_acl(const char *fname, const struct file_struct *file)
1030 + SMB_ACL_TYPE_T *type,
1031 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1032 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1034 + if (file == backup_orig_file) {
1035 + if (!strcmp(fname, backup_dest_fname))
1036 + return set_keep_backup_acl();
1038 + for (type = &types[0];
1039 + type < &types[0] + sizeof types / sizeof types[0]
1040 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1042 + SMB_ACL_T sacl_orig, *sacl_new;
1043 + rsync_acl racl_orig, *racl_new;
1044 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1047 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1048 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1049 + sacl_orig = sys_acl_get_file(fname, *type);
1051 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1052 + fname, str_acl_type(*type), strerror(errno));
1056 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1057 + sys_acl_free_acl(sacl_orig);
1062 + ok = rsync_acls_equal(&racl_orig, racl_new);
1063 + rsync_acl_free(&racl_orig);
1066 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1067 + if (-1 == sys_acl_delete_def_file(fname)) {
1068 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1069 + fname, strerror(errno));
1075 + if (!pack_smb_acl(sacl_new, racl_new)) {
1079 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1080 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1081 + fname, str_acl_type(*type),
1093 +/* enumeration functions for uid mapping */
1095 +/* context -- one and only one. should be cycled through once on uid mapping
1096 + * and once on gid mapping */
1097 +static rsync_acl_list *_enum_racl_lists[] = {
1098 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1101 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1102 +static size_t enum_racl_index = 0;
1103 +static size_t enum_race_index = 0;
1105 +/* this returns the next tag_type id from the given acl for the next entry,
1106 + * or it returns 0 if there are no more tag_type ids in the acl */
1108 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1110 + for (; enum_race_index < racl->count; enum_race_index++) {
1111 + rsync_ace *race = &racl->races[enum_race_index];
1112 + if (race->tag_type == tag_type)
1115 + enum_race_index = 0;
1119 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1121 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1122 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1123 + id_t id = next_ace_id(tag_type, racl);
1127 + enum_racl_index = 0;
1131 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1133 + for (; *enum_racl_list; enum_racl_list++) {
1134 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1138 + enum_racl_list = &_enum_racl_lists[0];
1142 +id_t next_acl_uid()
1144 + return next_acl_list_id(SMB_ACL_USER);
1147 +id_t next_acl_gid()
1149 + return next_acl_list_id(SMB_ACL_GROUP);
1152 +/* referring to the global context enum_entry, sets the entry's id */
1153 +static void set_acl_id(id_t id)
1155 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1158 +void acl_uid_map(id_t uid)
1163 +void acl_gid_map(id_t gid)
1168 +#endif /* SUPPORT_ACLS */
1169 --- orig/backup.c 2005-02-22 01:57:58
1170 +++ backup.c 2004-10-06 00:13:09
1171 @@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
1173 do_lchown(fullpath, st.st_uid, st.st_gid);
1174 do_chmod(fullpath, st.st_mode);
1175 + (void)DUP_ACL(end, fullpath, st.st_mode);
1179 @@ -187,6 +188,8 @@ static int keep_backup(char *fname)
1180 if (!(buf = get_backup_name(fname)))
1183 + PUSH_KEEP_BACKUP_ACL(file, fname, buf);
1185 /* Check to see if this is a device file, or link */
1186 if (IS_DEVICE(file->mode)) {
1187 if (am_root && preserve_devices) {
1188 @@ -260,6 +263,7 @@ static int keep_backup(char *fname)
1191 set_perms(buf, file, NULL, 0);
1192 + CLEANUP_KEEP_BACKUP_ACL();
1196 --- orig/configure.in 2005-05-13 22:24:18
1197 +++ configure.in 2004-08-19 19:53:27
1198 @@ -478,6 +478,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1199 AC_CHECK_LIB(resolv, strcasecmp)
1202 +AC_CHECK_FUNCS(aclsort)
1203 +if test x"$ac_cv_func_aclsort" = x"no"; then
1204 + AC_CHECK_LIB(sec, aclsort)
1207 dnl At the moment we don't test for a broken memcmp(), because all we
1208 dnl need to do is test for equality, not comparison, and it seems that
1209 dnl every platform has a memcmp that can do at least that.
1210 @@ -734,6 +739,77 @@ AC_SUBST(OBJ_RESTORE)
1211 AC_SUBST(CC_SHOBJ_FLAG)
1212 AC_SUBST(BUILD_POPT)
1214 +AC_CHECK_HEADERS(sys/acl.h)
1215 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1216 +#################################################
1217 +# check for ACL support
1219 +AC_MSG_CHECKING(whether to support ACLs)
1220 +AC_ARG_WITH(acl-support,
1221 +[ --with-acl-support Include ACL support (default=no)],
1222 +[ case "$withval" in
1225 + case "$host_os" in
1227 + AC_MSG_RESULT(Using UnixWare ACLs)
1228 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1231 + AC_MSG_RESULT(Using solaris ACLs)
1232 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1235 + AC_MSG_RESULT(Using HPUX ACLs)
1236 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1239 + AC_MSG_RESULT(Using IRIX ACLs)
1240 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1243 + AC_MSG_RESULT(Using AIX ACLs)
1244 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1247 + AC_MSG_RESULT(Using Tru64 ACLs)
1248 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1249 + LIBS="$LIBS -lpacl"
1252 + AC_MSG_RESULT(ACLs requested -- running tests)
1253 + AC_CHECK_LIB(acl,acl_get_file)
1254 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1255 + AC_TRY_LINK([#include <sys/types.h>
1256 +#include <sys/acl.h>],
1257 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1258 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1259 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1260 + AC_MSG_RESULT(Using posix ACLs)
1261 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1262 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1263 + AC_TRY_LINK([#include <sys/types.h>
1264 +#include <sys/acl.h>],
1265 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1266 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1267 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1268 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1271 + AC_MSG_ERROR(Failed to find ACL support)
1278 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1281 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1285 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1288 --- orig/flist.c 2005-05-14 19:51:15
1289 +++ flist.c 2005-03-16 02:24:11
1290 @@ -974,6 +974,8 @@ static struct file_struct *send_file_nam
1291 file = make_file(fname, flist, f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1294 + if (!MAKE_ACL(file, fname))
1297 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1299 @@ -982,6 +984,10 @@ static struct file_struct *send_file_nam
1300 if (file->basename[0]) {
1301 flist->files[flist->count++] = file;
1302 send_file_entry(file, f, base_flags);
1303 + SEND_ACL(file, f);
1305 + /* Cleanup unsent ACL(s). */
1306 + SEND_ACL(file, -1);
1310 @@ -1318,6 +1324,8 @@ struct file_list *recv_file_list(int f)
1311 flags |= read_byte(f) << 8;
1312 file = receive_file_entry(flist, flags, f);
1314 + RECEIVE_ACL(file, f);
1316 if (S_ISREG(file->mode))
1317 stats.total_size += file->length;
1319 @@ -1340,6 +1348,8 @@ struct file_list *recv_file_list(int f)
1321 clean_flist(flist, relative_paths, 1);
1323 + SORT_FILE_ACL_INDEX_LISTS();
1326 /* Now send the uid/gid list. This was introduced in
1327 * protocol version 15 */
1328 --- orig/generator.c 2005-05-14 19:51:15
1329 +++ generator.c 2005-05-12 23:34:00
1330 @@ -721,6 +721,10 @@ static void recv_generator(char *fname,
1331 if (set_perms(fname, file, statret ? NULL : &st, 0)
1332 && verbose && code && f_out != -1)
1333 rprintf(code, "%s/\n", safe_fname(fname));
1334 +#ifdef SUPPORT_ACLS
1336 + SET_ACL(fname, file);
1338 if (delete_during && f_out != -1 && !phase && dry_run < 2
1339 && (file->flags & FLAG_DEL_HERE))
1340 delete_in_dir(the_file_list, fname, file);
1341 --- orig/lib/sysacls.c 2005-05-16 23:27:53
1342 +++ lib/sysacls.c 2005-05-16 23:27:53
1345 + Unix SMB/CIFS implementation.
1346 + Samba system utilities for ACL support.
1347 + Copyright (C) Jeremy Allison 2000.
1349 + This program is free software; you can redistribute it and/or modify
1350 + it under the terms of the GNU General Public License as published by
1351 + the Free Software Foundation; either version 2 of the License, or
1352 + (at your option) any later version.
1354 + This program is distributed in the hope that it will be useful,
1355 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1356 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1357 + GNU General Public License for more details.
1359 + You should have received a copy of the GNU General Public License
1360 + along with this program; if not, write to the Free Software
1361 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1365 +#include "sysacls.h" /****** ADDED ******/
1367 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1368 +void SAFE_FREE(void *mem)
1374 +char *uidtoname(uid_t uid)
1376 + static char idbuf[12];
1377 + struct passwd *pw;
1379 + if ((pw = getpwuid(uid)) == NULL) {
1380 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1383 + return pw->pw_name;
1385 +/****** EXTRAS -- END ******/
1388 + This file wraps all differing system ACL interfaces into a consistent
1389 + one based on the POSIX interface. It also returns the correct errors
1390 + for older UNIX systems that don't support ACLs.
1392 + The interfaces that each ACL implementation must support are as follows :
1394 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1395 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1396 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1397 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1398 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1399 + SMB_ACL_T sys_acl_get_fd(int fd)
1400 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1401 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1402 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1403 + SMB_ACL_T sys_acl_init( int count)
1404 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1405 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1406 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1407 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1408 + int sys_acl_valid( SMB_ACL_T theacl )
1409 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1410 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1411 + int sys_acl_delete_def_file(const char *path)
1413 + This next one is not POSIX complient - but we *have* to have it !
1414 + More POSIX braindamage.
1416 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1418 + The generic POSIX free is the following call. We split this into
1419 + several different free functions as we may need to add tag info
1420 + to structures when emulating the POSIX interface.
1422 + int sys_acl_free( void *obj_p)
1424 + The calls we actually use are :
1426 + int sys_acl_free_text(char *text) - free acl_to_text
1427 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1428 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1432 +#if defined(HAVE_POSIX_ACLS)
1434 +/* Identity mapping - easy. */
1436 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1438 + return acl_get_entry( the_acl, entry_id, entry_p);
1441 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1443 + return acl_get_tag_type( entry_d, tag_type_p);
1446 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1448 + return acl_get_permset( entry_d, permset_p);
1451 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1453 + return acl_get_qualifier( entry_d);
1456 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1458 + return acl_get_file( path_p, type);
1461 +SMB_ACL_T sys_acl_get_fd(int fd)
1463 + return acl_get_fd(fd);
1466 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1468 + return acl_clear_perms(permset);
1471 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1473 + return acl_add_perm(permset, perm);
1476 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1478 +#if defined(HAVE_ACL_GET_PERM_NP)
1480 + * Required for TrustedBSD-based ACL implementations where
1481 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1484 + return acl_get_perm_np(permset, perm);
1486 + return acl_get_perm(permset, perm);
1490 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1492 + return acl_to_text( the_acl, plen);
1495 +SMB_ACL_T sys_acl_init( int count)
1497 + return acl_init(count);
1500 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1502 + return acl_create_entry(pacl, pentry);
1505 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1507 + return acl_set_tag_type(entry, tagtype);
1510 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1512 + return acl_set_qualifier(entry, qual);
1515 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1517 + return acl_set_permset(entry, permset);
1520 +int sys_acl_valid( SMB_ACL_T theacl )
1522 + return acl_valid(theacl);
1525 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1527 + return acl_set_file(name, acltype, theacl);
1530 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1532 + return acl_set_fd(fd, theacl);
1535 +int sys_acl_delete_def_file(const char *name)
1537 + return acl_delete_def_file(name);
1540 +int sys_acl_free_text(char *text)
1542 + return acl_free(text);
1545 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1547 + return acl_free(the_acl);
1550 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1552 + return acl_free(qual);
1555 +#elif defined(HAVE_TRU64_ACLS)
1557 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1558 + * is based on Draft 13 of the POSIX spec which is
1559 + * slightly different from the Draft 16 interface.
1561 + * Also, some of the permset manipulation functions
1562 + * such as acl_clear_perm() and acl_add_perm() appear
1563 + * to be broken on Tru64 so we have to manipulate
1564 + * the permission bits in the permset directly.
1566 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1568 + SMB_ACL_ENTRY_T entry;
1570 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1575 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1580 + return errno ? -1 : 0;
1583 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1585 + return acl_get_tag_type( entry_d, tag_type_p);
1588 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1590 + return acl_get_permset( entry_d, permset_p);
1593 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1595 + return acl_get_qualifier( entry_d);
1598 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1600 + return acl_get_file((char *)path_p, type);
1603 +SMB_ACL_T sys_acl_get_fd(int fd)
1605 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1608 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1610 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1615 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1617 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1622 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1627 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1629 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1632 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1634 + return acl_to_text( the_acl, plen);
1637 +SMB_ACL_T sys_acl_init( int count)
1639 + return acl_init(count);
1642 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1644 + SMB_ACL_ENTRY_T entry;
1646 + if ((entry = acl_create_entry(pacl)) == NULL) {
1654 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1656 + return acl_set_tag_type(entry, tagtype);
1659 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1661 + return acl_set_qualifier(entry, qual);
1664 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1666 + return acl_set_permset(entry, permset);
1669 +int sys_acl_valid( SMB_ACL_T theacl )
1671 + acl_entry_t entry;
1673 + return acl_valid(theacl, &entry);
1676 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1678 + return acl_set_file((char *)name, acltype, theacl);
1681 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1683 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1686 +int sys_acl_delete_def_file(const char *name)
1688 + return acl_delete_def_file((char *)name);
1691 +int sys_acl_free_text(char *text)
1694 + * (void) cast and explicit return 0 are for DEC UNIX
1695 + * which just #defines acl_free_text() to be free()
1697 + (void) acl_free_text(text);
1701 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1703 + return acl_free(the_acl);
1706 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1708 + return acl_free_qualifier(qual, tagtype);
1711 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1714 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1715 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1719 + * Note that while this code implements sufficient functionality
1720 + * to support the sys_acl_* interfaces it does not provide all
1721 + * of the semantics of the POSIX ACL interfaces.
1723 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1724 + * from a call to sys_acl_get_entry() should not be assumed to be
1725 + * valid after calling any of the following functions, which may
1726 + * reorder the entries in the ACL.
1729 + * sys_acl_set_file()
1730 + * sys_acl_set_fd()
1734 + * The only difference between Solaris and UnixWare / OpenUNIX is
1735 + * that the #defines for the ACL operations have different names
1737 +#if defined(HAVE_UNIXWARE_ACLS)
1739 +#define SETACL ACL_SET
1740 +#define GETACL ACL_GET
1741 +#define GETACLCNT ACL_CNT
1746 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1748 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1753 + if (entry_p == NULL) {
1758 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1762 + if (acl_d->next < 0) {
1767 + if (acl_d->next >= acl_d->count) {
1771 + *entry_p = &acl_d->acl[acl_d->next++];
1776 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1778 + *type_p = entry_d->a_type;
1783 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1785 + *permset_p = &entry_d->a_perm;
1790 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1792 + if (entry_d->a_type != SMB_ACL_USER
1793 + && entry_d->a_type != SMB_ACL_GROUP) {
1798 + return &entry_d->a_id;
1802 + * There is no way of knowing what size the ACL returned by
1803 + * GETACL will be unless you first call GETACLCNT which means
1804 + * making an additional system call.
1806 + * In the hope of avoiding the cost of the additional system
1807 + * call in most cases, we initially allocate enough space for
1808 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1809 + * be too small then we use GETACLCNT to find out the actual
1810 + * size, reallocate the ACL buffer, and then call GETACL again.
1813 +#define INITIAL_ACL_SIZE 16
1815 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1818 + int count; /* # of ACL entries allocated */
1819 + int naccess; /* # of access ACL entries */
1820 + int ndefault; /* # of default ACL entries */
1822 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1827 + count = INITIAL_ACL_SIZE;
1828 + if ((acl_d = sys_acl_init(count)) == NULL) {
1833 + * If there isn't enough space for the ACL entries we use
1834 + * GETACLCNT to determine the actual number of ACL entries
1835 + * reallocate and try again. This is in a loop because it
1836 + * is possible that someone else could modify the ACL and
1837 + * increase the number of entries between the call to
1838 + * GETACLCNT and the call to GETACL.
1840 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1841 + && errno == ENOSPC) {
1843 + sys_acl_free_acl(acl_d);
1845 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1849 + if ((acl_d = sys_acl_init(count)) == NULL) {
1855 + sys_acl_free_acl(acl_d);
1860 + * calculate the number of access and default ACL entries
1862 + * Note: we assume that the acl() system call returned a
1863 + * well formed ACL which is sorted so that all of the
1864 + * access ACL entries preceed any default ACL entries
1866 + for (naccess = 0; naccess < count; naccess++) {
1867 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1870 + ndefault = count - naccess;
1873 + * if the caller wants the default ACL we have to copy
1874 + * the entries down to the start of the acl[] buffer
1875 + * and mask out the ACL_DEFAULT flag from the type field
1877 + if (type == SMB_ACL_TYPE_DEFAULT) {
1880 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
1881 + acl_d->acl[i] = acl_d->acl[j];
1882 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
1885 + acl_d->count = ndefault;
1887 + acl_d->count = naccess;
1893 +SMB_ACL_T sys_acl_get_fd(int fd)
1896 + int count; /* # of ACL entries allocated */
1897 + int naccess; /* # of access ACL entries */
1899 + count = INITIAL_ACL_SIZE;
1900 + if ((acl_d = sys_acl_init(count)) == NULL) {
1904 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
1905 + && errno == ENOSPC) {
1907 + sys_acl_free_acl(acl_d);
1909 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
1913 + if ((acl_d = sys_acl_init(count)) == NULL) {
1919 + sys_acl_free_acl(acl_d);
1924 + * calculate the number of access ACL entries
1926 + for (naccess = 0; naccess < count; naccess++) {
1927 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1931 + acl_d->count = naccess;
1936 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
1943 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
1945 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
1946 + && perm != SMB_ACL_EXECUTE) {
1951 + if (permset_d == NULL) {
1956 + *permset_d |= perm;
1961 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
1963 + return *permset_d & perm;
1966 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
1973 + * use an initial estimate of 20 bytes per ACL entry
1974 + * when allocating memory for the text representation
1978 + maxlen = 20 * acl_d->count;
1979 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
1984 + for (i = 0; i < acl_d->count; i++) {
1985 + struct acl *ap = &acl_d->acl[i];
1986 + struct passwd *pw;
1995 + switch (ap->a_type) {
1997 + * for debugging purposes it's probably more
1998 + * useful to dump unknown tag types rather
1999 + * than just returning an error
2002 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2005 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2010 + case SMB_ACL_USER:
2011 + id = uidtoname(ap->a_id);
2012 + case SMB_ACL_USER_OBJ:
2016 + case SMB_ACL_GROUP:
2017 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2018 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2024 + case SMB_ACL_GROUP_OBJ:
2028 + case SMB_ACL_OTHER:
2032 + case SMB_ACL_MASK:
2038 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2039 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2040 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2043 + /* <tag> : <qualifier> : rwx \n \0 */
2044 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2047 + * If this entry would overflow the buffer
2048 + * allocate enough additional memory for this
2049 + * entry and an estimate of another 20 bytes
2050 + * for each entry still to be processed
2052 + if ((len + nbytes) > maxlen) {
2053 + char *oldtext = text;
2055 + maxlen += nbytes + 20 * (acl_d->count - i);
2057 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2058 + SAFE_FREE(oldtext);
2064 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2065 + len += nbytes - 1;
2074 +SMB_ACL_T sys_acl_init(int count)
2084 + * note that since the definition of the structure pointed
2085 + * to by the SMB_ACL_T includes the first element of the
2086 + * acl[] array, this actually allocates an ACL with room
2087 + * for (count+1) entries
2089 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2094 + a->size = count + 1;
2102 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2105 + SMB_ACL_ENTRY_T entry_d;
2107 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2112 + if (acl_d->count >= acl_d->size) {
2117 + entry_d = &acl_d->acl[acl_d->count++];
2118 + entry_d->a_type = 0;
2119 + entry_d->a_id = -1;
2120 + entry_d->a_perm = 0;
2121 + *entry_p = entry_d;
2126 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2128 + switch (tag_type) {
2129 + case SMB_ACL_USER:
2130 + case SMB_ACL_USER_OBJ:
2131 + case SMB_ACL_GROUP:
2132 + case SMB_ACL_GROUP_OBJ:
2133 + case SMB_ACL_OTHER:
2134 + case SMB_ACL_MASK:
2135 + entry_d->a_type = tag_type;
2145 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2147 + if (entry_d->a_type != SMB_ACL_GROUP
2148 + && entry_d->a_type != SMB_ACL_USER) {
2153 + entry_d->a_id = *((id_t *)qual_p);
2158 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2160 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2164 + entry_d->a_perm = *permset_d;
2170 + * sort the ACL and check it for validity
2172 + * if it's a minimal ACL with only 4 entries then we
2173 + * need to recalculate the mask permissions to make
2174 + * sure that they are the same as the GROUP_OBJ
2175 + * permissions as required by the UnixWare acl() system call.
2177 + * (note: since POSIX allows minimal ACLs which only contain
2178 + * 3 entries - ie there is no mask entry - we should, in theory,
2179 + * check for this and add a mask entry if necessary - however
2180 + * we "know" that the caller of this interface always specifies
2181 + * a mask so, in practice "this never happens" (tm) - if it *does*
2182 + * happen aclsort() will fail and return an error and someone will
2183 + * have to fix it ...)
2186 +static int acl_sort(SMB_ACL_T acl_d)
2188 + int fixmask = (acl_d->count <= 4);
2190 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2197 +int sys_acl_valid(SMB_ACL_T acl_d)
2199 + return acl_sort(acl_d);
2202 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2205 + struct acl *acl_p;
2207 + struct acl *acl_buf = NULL;
2210 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2215 + if (acl_sort(acl_d) != 0) {
2219 + acl_p = &acl_d->acl[0];
2220 + acl_count = acl_d->count;
2223 + * if it's a directory there is extra work to do
2224 + * since the acl() system call will replace both
2225 + * the access ACLs and the default ACLs (if any)
2227 + if (stat(name, &s) != 0) {
2230 + if (S_ISDIR(s.st_mode)) {
2231 + SMB_ACL_T acc_acl;
2232 + SMB_ACL_T def_acl;
2233 + SMB_ACL_T tmp_acl;
2236 + if (type == SMB_ACL_TYPE_ACCESS) {
2238 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2242 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2245 + if (tmp_acl == NULL) {
2250 + * allocate a temporary buffer for the complete ACL
2252 + acl_count = acc_acl->count + def_acl->count;
2253 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2255 + if (acl_buf == NULL) {
2256 + sys_acl_free_acl(tmp_acl);
2262 + * copy the access control and default entries into the buffer
2264 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2265 + acc_acl->count * sizeof(acl_buf[0]));
2267 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2268 + def_acl->count * sizeof(acl_buf[0]));
2271 + * set the ACL_DEFAULT flag on the default entries
2273 + for (i = acc_acl->count; i < acl_count; i++) {
2274 + acl_buf[i].a_type |= ACL_DEFAULT;
2277 + sys_acl_free_acl(tmp_acl);
2279 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2284 + ret = acl(name, SETACL, acl_count, acl_p);
2286 + SAFE_FREE(acl_buf);
2291 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2293 + if (acl_sort(acl_d) != 0) {
2297 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2300 +int sys_acl_delete_def_file(const char *path)
2306 + * fetching the access ACL and rewriting it has
2307 + * the effect of deleting the default ACL
2309 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2313 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2315 + sys_acl_free_acl(acl_d);
2320 +int sys_acl_free_text(char *text)
2326 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2332 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2337 +#elif defined(HAVE_HPUX_ACLS)
2341 + * Based on the Solaris/SCO code - with modifications.
2345 + * Note that while this code implements sufficient functionality
2346 + * to support the sys_acl_* interfaces it does not provide all
2347 + * of the semantics of the POSIX ACL interfaces.
2349 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2350 + * from a call to sys_acl_get_entry() should not be assumed to be
2351 + * valid after calling any of the following functions, which may
2352 + * reorder the entries in the ACL.
2355 + * sys_acl_set_file()
2356 + * sys_acl_set_fd()
2359 +/* This checks if the POSIX ACL system call is defined */
2360 +/* which basically corresponds to whether JFS 3.3 or */
2361 +/* higher is installed. If acl() was called when it */
2362 +/* isn't defined, it causes the process to core dump */
2363 +/* so it is important to check this and avoid acl() */
2364 +/* calls if it isn't there. */
2366 +static BOOL hpux_acl_call_presence(void)
2369 + shl_t handle = NULL;
2372 + static BOOL already_checked=0;
2374 + if(already_checked)
2378 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2380 + if(ret_val != 0) {
2381 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2382 + ret_val, errno, strerror(errno)));
2383 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2387 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2389 + already_checked = True;
2393 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2395 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2400 + if (entry_p == NULL) {
2405 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2409 + if (acl_d->next < 0) {
2414 + if (acl_d->next >= acl_d->count) {
2418 + *entry_p = &acl_d->acl[acl_d->next++];
2423 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2425 + *type_p = entry_d->a_type;
2430 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2432 + *permset_p = &entry_d->a_perm;
2437 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2439 + if (entry_d->a_type != SMB_ACL_USER
2440 + && entry_d->a_type != SMB_ACL_GROUP) {
2445 + return &entry_d->a_id;
2449 + * There is no way of knowing what size the ACL returned by
2450 + * ACL_GET will be unless you first call ACL_CNT which means
2451 + * making an additional system call.
2453 + * In the hope of avoiding the cost of the additional system
2454 + * call in most cases, we initially allocate enough space for
2455 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2456 + * be too small then we use ACL_CNT to find out the actual
2457 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2460 +#define INITIAL_ACL_SIZE 16
2462 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2465 + int count; /* # of ACL entries allocated */
2466 + int naccess; /* # of access ACL entries */
2467 + int ndefault; /* # of default ACL entries */
2469 + if(hpux_acl_call_presence() == False) {
2470 + /* Looks like we don't have the acl() system call on HPUX.
2471 + * May be the system doesn't have the latest version of JFS.
2476 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2481 + count = INITIAL_ACL_SIZE;
2482 + if ((acl_d = sys_acl_init(count)) == NULL) {
2487 + * If there isn't enough space for the ACL entries we use
2488 + * ACL_CNT to determine the actual number of ACL entries
2489 + * reallocate and try again. This is in a loop because it
2490 + * is possible that someone else could modify the ACL and
2491 + * increase the number of entries between the call to
2492 + * ACL_CNT and the call to ACL_GET.
2494 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2496 + sys_acl_free_acl(acl_d);
2498 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2502 + if ((acl_d = sys_acl_init(count)) == NULL) {
2508 + sys_acl_free_acl(acl_d);
2513 + * calculate the number of access and default ACL entries
2515 + * Note: we assume that the acl() system call returned a
2516 + * well formed ACL which is sorted so that all of the
2517 + * access ACL entries preceed any default ACL entries
2519 + for (naccess = 0; naccess < count; naccess++) {
2520 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2523 + ndefault = count - naccess;
2526 + * if the caller wants the default ACL we have to copy
2527 + * the entries down to the start of the acl[] buffer
2528 + * and mask out the ACL_DEFAULT flag from the type field
2530 + if (type == SMB_ACL_TYPE_DEFAULT) {
2533 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2534 + acl_d->acl[i] = acl_d->acl[j];
2535 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2538 + acl_d->count = ndefault;
2540 + acl_d->count = naccess;
2546 +SMB_ACL_T sys_acl_get_fd(int fd)
2549 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2552 + files_struct *fsp = file_find_fd(fd);
2554 + if (fsp == NULL) {
2560 + * We know we're in the same conn context. So we
2561 + * can use the relative path.
2564 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2567 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2574 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2576 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2577 + && perm != SMB_ACL_EXECUTE) {
2582 + if (permset_d == NULL) {
2587 + *permset_d |= perm;
2592 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2594 + return *permset_d & perm;
2597 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2604 + * use an initial estimate of 20 bytes per ACL entry
2605 + * when allocating memory for the text representation
2609 + maxlen = 20 * acl_d->count;
2610 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2615 + for (i = 0; i < acl_d->count; i++) {
2616 + struct acl *ap = &acl_d->acl[i];
2617 + struct passwd *pw;
2626 + switch (ap->a_type) {
2628 + * for debugging purposes it's probably more
2629 + * useful to dump unknown tag types rather
2630 + * than just returning an error
2633 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2636 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2641 + case SMB_ACL_USER:
2642 + id = uidtoname(ap->a_id);
2643 + case SMB_ACL_USER_OBJ:
2647 + case SMB_ACL_GROUP:
2648 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2649 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2655 + case SMB_ACL_GROUP_OBJ:
2659 + case SMB_ACL_OTHER:
2663 + case SMB_ACL_MASK:
2669 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2670 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2671 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2674 + /* <tag> : <qualifier> : rwx \n \0 */
2675 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2678 + * If this entry would overflow the buffer
2679 + * allocate enough additional memory for this
2680 + * entry and an estimate of another 20 bytes
2681 + * for each entry still to be processed
2683 + if ((len + nbytes) > maxlen) {
2684 + char *oldtext = text;
2686 + maxlen += nbytes + 20 * (acl_d->count - i);
2688 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2695 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2696 + len += nbytes - 1;
2705 +SMB_ACL_T sys_acl_init(int count)
2715 + * note that since the definition of the structure pointed
2716 + * to by the SMB_ACL_T includes the first element of the
2717 + * acl[] array, this actually allocates an ACL with room
2718 + * for (count+1) entries
2720 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2725 + a->size = count + 1;
2733 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2736 + SMB_ACL_ENTRY_T entry_d;
2738 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2743 + if (acl_d->count >= acl_d->size) {
2748 + entry_d = &acl_d->acl[acl_d->count++];
2749 + entry_d->a_type = 0;
2750 + entry_d->a_id = -1;
2751 + entry_d->a_perm = 0;
2752 + *entry_p = entry_d;
2757 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2759 + switch (tag_type) {
2760 + case SMB_ACL_USER:
2761 + case SMB_ACL_USER_OBJ:
2762 + case SMB_ACL_GROUP:
2763 + case SMB_ACL_GROUP_OBJ:
2764 + case SMB_ACL_OTHER:
2765 + case SMB_ACL_MASK:
2766 + entry_d->a_type = tag_type;
2776 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2778 + if (entry_d->a_type != SMB_ACL_GROUP
2779 + && entry_d->a_type != SMB_ACL_USER) {
2784 + entry_d->a_id = *((id_t *)qual_p);
2789 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2791 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2795 + entry_d->a_perm = *permset_d;
2800 +/* Structure to capture the count for each type of ACE. */
2802 +struct hpux_acl_types {
2806 + int n_def_user_obj;
2811 + int n_def_group_obj;
2815 + int n_def_other_obj;
2818 + int n_def_class_obj;
2820 + int n_illegal_obj;
2824 + * Counts the different number of objects in a given array of ACL
2828 + * acl_count - Count of ACLs in the array of ACL strucutres.
2829 + * aclp - Array of ACL structures.
2830 + * acl_type_count - Pointer to acl_types structure. Should already be
2834 + * acl_type_count - This structure is filled up with counts of various
2838 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2842 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2844 + for(i=0;i<acl_count;i++) {
2845 + switch(aclp[i].a_type) {
2847 + acl_type_count->n_user++;
2850 + acl_type_count->n_user_obj++;
2852 + case DEF_USER_OBJ:
2853 + acl_type_count->n_def_user_obj++;
2856 + acl_type_count->n_group++;
2859 + acl_type_count->n_group_obj++;
2861 + case DEF_GROUP_OBJ:
2862 + acl_type_count->n_def_group_obj++;
2865 + acl_type_count->n_other_obj++;
2867 + case DEF_OTHER_OBJ:
2868 + acl_type_count->n_def_other_obj++;
2871 + acl_type_count->n_class_obj++;
2873 + case DEF_CLASS_OBJ:
2874 + acl_type_count->n_def_class_obj++;
2877 + acl_type_count->n_def_user++;
2880 + acl_type_count->n_def_group++;
2883 + acl_type_count->n_illegal_obj++;
2889 +/* swap_acl_entries: Swaps two ACL entries.
2891 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
2894 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
2896 + struct acl temp_acl;
2898 + temp_acl.a_type = aclp0->a_type;
2899 + temp_acl.a_id = aclp0->a_id;
2900 + temp_acl.a_perm = aclp0->a_perm;
2902 + aclp0->a_type = aclp1->a_type;
2903 + aclp0->a_id = aclp1->a_id;
2904 + aclp0->a_perm = aclp1->a_perm;
2906 + aclp1->a_type = temp_acl.a_type;
2907 + aclp1->a_id = temp_acl.a_id;
2908 + aclp1->a_perm = temp_acl.a_perm;
2911 +/* prohibited_duplicate_type
2912 + * Identifies if given ACL type can have duplicate entries or
2915 + * Inputs: acl_type - ACL Type.
2921 + * True - If the ACL type matches any of the prohibited types.
2922 + * False - If the ACL type doesn't match any of the prohibited types.
2925 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
2927 + switch(acl_type) {
2938 +/* get_needed_class_perm
2939 + * Returns the permissions of a ACL structure only if the ACL
2940 + * type matches one of the pre-determined types for computing
2941 + * CLASS_OBJ permissions.
2943 + * Inputs: aclp - Pointer to ACL structure.
2946 +static int hpux_get_needed_class_perm(struct acl *aclp)
2948 + switch(aclp->a_type) {
2952 + case DEF_USER_OBJ:
2954 + case DEF_GROUP_OBJ:
2956 + case DEF_CLASS_OBJ:
2957 + case DEF_OTHER_OBJ:
2958 + return aclp->a_perm;
2964 +/* acl_sort for HPUX.
2965 + * Sorts the array of ACL structures as per the description in
2966 + * aclsort man page. Refer to aclsort man page for more details
2970 + * acl_count - Count of ACLs in the array of ACL structures.
2971 + * calclass - If this is not zero, then we compute the CLASS_OBJ
2973 + * aclp - Array of ACL structures.
2977 + * aclp - Sorted array of ACL structures.
2981 + * Returns 0 for success -1 for failure. Prints a message to the Samba
2982 + * debug log in case of failure.
2985 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
2987 +#if !defined(HAVE_HPUX_ACLSORT)
2989 + * The aclsort() system call is availabe on the latest HPUX General
2990 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
2991 + * function. Because, we don't want to update to a new
2992 + * HPUX GR bundle just for aclsort() call.
2995 + struct hpux_acl_types acl_obj_count;
2996 + int n_class_obj_perm = 0;
3000 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3004 + if(aclp == NULL) {
3005 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3009 + /* Count different types of ACLs in the ACLs array */
3011 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3013 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3014 + * CLASS_OBJ and OTHER_OBJ
3017 + if( (acl_obj_count.n_user_obj != 1) ||
3018 + (acl_obj_count.n_group_obj != 1) ||
3019 + (acl_obj_count.n_class_obj != 1) ||
3020 + (acl_obj_count.n_other_obj != 1)
3022 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3023 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3027 + /* If any of the default objects are present, there should be only
3028 + * one of them each.
3031 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3032 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3033 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3034 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3038 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3041 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3042 + * same ACL type, sort by ACL id.
3044 + * I am using the trival kind of sorting method here because, performance isn't
3045 + * really effected by the ACLs feature. More over there aren't going to be more
3046 + * than 17 entries on HPUX.
3049 + for(i=0; i<acl_count;i++) {
3050 + for (j=i+1; j<acl_count; j++) {
3051 + if( aclp[i].a_type > aclp[j].a_type ) {
3052 + /* ACL entries out of order, swap them */
3054 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3056 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3058 + /* ACL entries of same type, sort by id */
3060 + if(aclp[i].a_id > aclp[j].a_id) {
3061 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3062 + } else if (aclp[i].a_id == aclp[j].a_id) {
3063 + /* We have a duplicate entry. */
3064 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3065 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3066 + aclp[i].a_type, aclp[i].a_id));
3075 + /* set the class obj permissions to the computed one. */
3077 + int n_class_obj_index = -1;
3079 + for(i=0;i<acl_count;i++) {
3080 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3082 + if(aclp[i].a_type == CLASS_OBJ)
3083 + n_class_obj_index = i;
3085 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3090 + return aclsort(acl_count, calclass, aclp);
3095 + * sort the ACL and check it for validity
3097 + * if it's a minimal ACL with only 4 entries then we
3098 + * need to recalculate the mask permissions to make
3099 + * sure that they are the same as the GROUP_OBJ
3100 + * permissions as required by the UnixWare acl() system call.
3102 + * (note: since POSIX allows minimal ACLs which only contain
3103 + * 3 entries - ie there is no mask entry - we should, in theory,
3104 + * check for this and add a mask entry if necessary - however
3105 + * we "know" that the caller of this interface always specifies
3106 + * a mask so, in practice "this never happens" (tm) - if it *does*
3107 + * happen aclsort() will fail and return an error and someone will
3108 + * have to fix it ...)
3111 +static int acl_sort(SMB_ACL_T acl_d)
3113 + int fixmask = (acl_d->count <= 4);
3115 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3122 +int sys_acl_valid(SMB_ACL_T acl_d)
3124 + return acl_sort(acl_d);
3127 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3130 + struct acl *acl_p;
3132 + struct acl *acl_buf = NULL;
3135 + if(hpux_acl_call_presence() == False) {
3136 + /* Looks like we don't have the acl() system call on HPUX.
3137 + * May be the system doesn't have the latest version of JFS.
3143 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3148 + if (acl_sort(acl_d) != 0) {
3152 + acl_p = &acl_d->acl[0];
3153 + acl_count = acl_d->count;
3156 + * if it's a directory there is extra work to do
3157 + * since the acl() system call will replace both
3158 + * the access ACLs and the default ACLs (if any)
3160 + if (stat(name, &s) != 0) {
3163 + if (S_ISDIR(s.st_mode)) {
3164 + SMB_ACL_T acc_acl;
3165 + SMB_ACL_T def_acl;
3166 + SMB_ACL_T tmp_acl;
3169 + if (type == SMB_ACL_TYPE_ACCESS) {
3171 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3175 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3178 + if (tmp_acl == NULL) {
3183 + * allocate a temporary buffer for the complete ACL
3185 + acl_count = acc_acl->count + def_acl->count;
3186 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3188 + if (acl_buf == NULL) {
3189 + sys_acl_free_acl(tmp_acl);
3195 + * copy the access control and default entries into the buffer
3197 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3198 + acc_acl->count * sizeof(acl_buf[0]));
3200 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3201 + def_acl->count * sizeof(acl_buf[0]));
3204 + * set the ACL_DEFAULT flag on the default entries
3206 + for (i = acc_acl->count; i < acl_count; i++) {
3207 + acl_buf[i].a_type |= ACL_DEFAULT;
3210 + sys_acl_free_acl(tmp_acl);
3212 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3217 + ret = acl(name, ACL_SET, acl_count, acl_p);
3226 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3229 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3232 + files_struct *fsp = file_find_fd(fd);
3234 + if (fsp == NULL) {
3239 + if (acl_sort(acl_d) != 0) {
3244 + * We know we're in the same conn context. So we
3245 + * can use the relative path.
3248 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3251 +int sys_acl_delete_def_file(const char *path)
3257 + * fetching the access ACL and rewriting it has
3258 + * the effect of deleting the default ACL
3260 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3264 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3266 + sys_acl_free_acl(acl_d);
3271 +int sys_acl_free_text(char *text)
3277 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3283 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3288 +#elif defined(HAVE_IRIX_ACLS)
3290 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3292 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3297 + if (entry_p == NULL) {
3302 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3306 + if (acl_d->next < 0) {
3311 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3315 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3320 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3322 + *type_p = entry_d->ae_tag;
3327 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3329 + *permset_p = entry_d;
3334 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3336 + if (entry_d->ae_tag != SMB_ACL_USER
3337 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3342 + return &entry_d->ae_id;
3345 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3349 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3353 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3358 + a->freeaclp = True;
3362 +SMB_ACL_T sys_acl_get_fd(int fd)
3366 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3370 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3375 + a->freeaclp = True;
3379 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3381 + permset_d->ae_perm = 0;
3386 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3388 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3389 + && perm != SMB_ACL_EXECUTE) {
3394 + if (permset_d == NULL) {
3399 + permset_d->ae_perm |= perm;
3404 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3406 + return permset_d->ae_perm & perm;
3409 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3411 + return acl_to_text(acl_d->aclp, len_p);
3414 +SMB_ACL_T sys_acl_init(int count)
3423 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3429 + a->freeaclp = False;
3430 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3431 + a->aclp->acl_cnt = 0;
3437 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3440 + SMB_ACL_ENTRY_T entry_d;
3442 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3447 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3452 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3453 + entry_d->ae_tag = 0;
3454 + entry_d->ae_id = 0;
3455 + entry_d->ae_perm = 0;
3456 + *entry_p = entry_d;
3461 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3463 + switch (tag_type) {
3464 + case SMB_ACL_USER:
3465 + case SMB_ACL_USER_OBJ:
3466 + case SMB_ACL_GROUP:
3467 + case SMB_ACL_GROUP_OBJ:
3468 + case SMB_ACL_OTHER:
3469 + case SMB_ACL_MASK:
3470 + entry_d->ae_tag = tag_type;
3480 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3482 + if (entry_d->ae_tag != SMB_ACL_GROUP
3483 + && entry_d->ae_tag != SMB_ACL_USER) {
3488 + entry_d->ae_id = *((id_t *)qual_p);
3493 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3495 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3499 + entry_d->ae_perm = permset_d->ae_perm;
3504 +int sys_acl_valid(SMB_ACL_T acl_d)
3506 + return acl_valid(acl_d->aclp);
3509 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3511 + return acl_set_file(name, type, acl_d->aclp);
3514 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3516 + return acl_set_fd(fd, acl_d->aclp);
3519 +int sys_acl_delete_def_file(const char *name)
3521 + return acl_delete_def_file(name);
3524 +int sys_acl_free_text(char *text)
3526 + return acl_free(text);
3529 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3531 + if (acl_d->freeaclp) {
3532 + acl_free(acl_d->aclp);
3538 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3543 +#elif defined(HAVE_AIX_ACLS)
3545 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3547 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3549 + struct acl_entry_link *link;
3550 + struct new_acl_entry *entry;
3553 + DEBUG(10,("This is the count: %d\n",theacl->count));
3555 + /* Check if count was previously set to -1. *
3556 + * If it was, that means we reached the end *
3557 + * of the acl last time. */
3558 + if(theacl->count == -1)
3562 + /* To get to the next acl, traverse linked list until index *
3563 + * of acl matches the count we are keeping. This count is *
3564 + * incremented each time we return an acl entry. */
3566 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3567 + link = link->nextp;
3569 + entry = *entry_p = link->entryp;
3571 + DEBUG(10,("*entry_p is %d\n",entry_p));
3572 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3574 + /* Increment count */
3576 + if(link->nextp == NULL)
3577 + theacl->count = -1;
3582 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3584 + /* Initialize tag type */
3587 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3589 + /* Depending on what type of entry we have, *
3590 + * return tag type. */
3591 + switch(entry_d->ace_id->id_type) {
3593 + *tag_type_p = SMB_ACL_USER;
3596 + *tag_type_p = SMB_ACL_GROUP;
3599 + case SMB_ACL_USER_OBJ:
3600 + case SMB_ACL_GROUP_OBJ:
3601 + case SMB_ACL_OTHER:
3602 + *tag_type_p = entry_d->ace_id->id_type;
3612 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3614 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3615 + *permset_p = &entry_d->ace_access;
3616 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3617 + if(!(**permset_p & S_IXUSR) &&
3618 + !(**permset_p & S_IWUSR) &&
3619 + !(**permset_p & S_IRUSR) &&
3620 + (**permset_p != 0))
3623 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3627 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3629 + return(entry_d->ace_id->id_data);
3632 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3634 + struct acl *file_acl = (struct acl *)NULL;
3635 + struct acl_entry *acl_entry;
3636 + struct new_acl_entry *new_acl_entry;
3637 + struct ace_id *idp;
3638 + struct acl_entry_link *acl_entry_link;
3639 + struct acl_entry_link *acl_entry_link_head;
3644 + /* AIX has no DEFAULT */
3645 + if ( type == SMB_ACL_TYPE_DEFAULT )
3648 + /* Get the acl using statacl */
3650 + DEBUG(10,("Entering sys_acl_get_file\n"));
3651 + DEBUG(10,("path_p is %s\n",path_p));
3653 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3655 + if(file_acl == NULL) {
3657 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3661 + memset(file_acl,0,BUFSIZ);
3663 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3665 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3666 + SAFE_FREE(file_acl);
3670 + DEBUG(10,("Got facl and returned it\n"));
3672 + /* Point to the first acl entry in the acl */
3673 + acl_entry = file_acl->acl_ext;
3675 + /* Begin setting up the head of the linked list *
3676 + * that will be used for the storing the acl *
3677 + * in a way that is useful for the posix_acls.c *
3680 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3681 + if(acl_entry_link_head == NULL)
3684 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3685 + if(acl_entry_link->entryp == NULL) {
3686 + SAFE_FREE(file_acl);
3688 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3692 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3693 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3695 + /* Check if the extended acl bit is on. *
3696 + * If it isn't, do not show the *
3697 + * contents of the acl since AIX intends *
3698 + * the extended info to remain unused */
3700 + if(file_acl->acl_mode & S_IXACL){
3701 + /* while we are not pointing to the very end */
3702 + while(acl_entry < acl_last(file_acl)) {
3703 + /* before we malloc anything, make sure this is */
3704 + /* a valid acl entry and one that we want to map */
3705 + idp = id_nxt(acl_entry->ace_id);
3706 + if((acl_entry->ace_type == ACC_SPECIFY ||
3707 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3708 + acl_entry = acl_nxt(acl_entry);
3712 + idp = acl_entry->ace_id;
3714 + /* Check if this is the first entry in the linked list. *
3715 + * The first entry needs to keep prevp pointing to NULL *
3716 + * and already has entryp allocated. */
3718 + if(acl_entry_link_head->count != 0) {
3719 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3721 + if(acl_entry_link->nextp == NULL) {
3722 + SAFE_FREE(file_acl);
3724 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3728 + acl_entry_link->nextp->prevp = acl_entry_link;
3729 + acl_entry_link = acl_entry_link->nextp;
3730 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3731 + if(acl_entry_link->entryp == NULL) {
3732 + SAFE_FREE(file_acl);
3734 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3737 + acl_entry_link->nextp = NULL;
3740 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3742 + /* Don't really need this since all types are going *
3743 + * to be specified but, it's better than leaving it 0 */
3745 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3747 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3749 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3751 + /* The access in the acl entries must be left shifted by *
3752 + * three bites, because they will ultimately be compared *
3753 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3755 + switch(acl_entry->ace_type){
3758 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3759 + acl_entry_link->entryp->ace_access <<= 6;
3760 + acl_entry_link_head->count++;
3763 + /* Since there is no way to return a DENY acl entry *
3764 + * change to PERMIT and then shift. */
3765 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3766 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3767 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3768 + acl_entry_link->entryp->ace_access <<= 6;
3769 + acl_entry_link_head->count++;
3775 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3776 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3778 + acl_entry = acl_nxt(acl_entry);
3780 + } /* end of if enabled */
3782 + /* Since owner, group, other acl entries are not *
3783 + * part of the acl entries in an acl, they must *
3784 + * be dummied up to become part of the list. */
3786 + for( i = 1; i < 4; i++) {
3787 + DEBUG(10,("i is %d\n",i));
3788 + if(acl_entry_link_head->count != 0) {
3789 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3790 + if(acl_entry_link->nextp == NULL) {
3791 + SAFE_FREE(file_acl);
3793 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3797 + acl_entry_link->nextp->prevp = acl_entry_link;
3798 + acl_entry_link = acl_entry_link->nextp;
3799 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3800 + if(acl_entry_link->entryp == NULL) {
3801 + SAFE_FREE(file_acl);
3803 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3808 + acl_entry_link->nextp = NULL;
3810 + new_acl_entry = acl_entry_link->entryp;
3811 + idp = new_acl_entry->ace_id;
3813 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3814 + new_acl_entry->ace_type = ACC_PERMIT;
3815 + idp->id_len = sizeof(struct ace_id);
3816 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3817 + memset(idp->id_data,0,sizeof(uid_t));
3821 + new_acl_entry->ace_access = file_acl->g_access << 6;
3822 + idp->id_type = SMB_ACL_GROUP_OBJ;
3826 + new_acl_entry->ace_access = file_acl->o_access << 6;
3827 + idp->id_type = SMB_ACL_OTHER;
3831 + new_acl_entry->ace_access = file_acl->u_access << 6;
3832 + idp->id_type = SMB_ACL_USER_OBJ;
3840 + acl_entry_link_head->count++;
3841 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3844 + acl_entry_link_head->count = 0;
3845 + SAFE_FREE(file_acl);
3847 + return(acl_entry_link_head);
3850 +SMB_ACL_T sys_acl_get_fd(int fd)
3852 + struct acl *file_acl = (struct acl *)NULL;
3853 + struct acl_entry *acl_entry;
3854 + struct new_acl_entry *new_acl_entry;
3855 + struct ace_id *idp;
3856 + struct acl_entry_link *acl_entry_link;
3857 + struct acl_entry_link *acl_entry_link_head;
3862 + /* Get the acl using fstatacl */
3864 + DEBUG(10,("Entering sys_acl_get_fd\n"));
3865 + DEBUG(10,("fd is %d\n",fd));
3866 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3868 + if(file_acl == NULL) {
3870 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3874 + memset(file_acl,0,BUFSIZ);
3876 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
3878 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
3879 + SAFE_FREE(file_acl);
3883 + DEBUG(10,("Got facl and returned it\n"));
3885 + /* Point to the first acl entry in the acl */
3887 + acl_entry = file_acl->acl_ext;
3888 + /* Begin setting up the head of the linked list *
3889 + * that will be used for the storing the acl *
3890 + * in a way that is useful for the posix_acls.c *
3893 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3894 + if(acl_entry_link_head == NULL){
3895 + SAFE_FREE(file_acl);
3899 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3901 + if(acl_entry_link->entryp == NULL) {
3903 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3904 + SAFE_FREE(file_acl);
3908 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3909 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3911 + /* Check if the extended acl bit is on. *
3912 + * If it isn't, do not show the *
3913 + * contents of the acl since AIX intends *
3914 + * the extended info to remain unused */
3916 + if(file_acl->acl_mode & S_IXACL){
3917 + /* while we are not pointing to the very end */
3918 + while(acl_entry < acl_last(file_acl)) {
3919 + /* before we malloc anything, make sure this is */
3920 + /* a valid acl entry and one that we want to map */
3922 + idp = id_nxt(acl_entry->ace_id);
3923 + if((acl_entry->ace_type == ACC_SPECIFY ||
3924 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3925 + acl_entry = acl_nxt(acl_entry);
3929 + idp = acl_entry->ace_id;
3931 + /* Check if this is the first entry in the linked list. *
3932 + * The first entry needs to keep prevp pointing to NULL *
3933 + * and already has entryp allocated. */
3935 + if(acl_entry_link_head->count != 0) {
3936 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3937 + if(acl_entry_link->nextp == NULL) {
3939 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3940 + SAFE_FREE(file_acl);
3943 + acl_entry_link->nextp->prevp = acl_entry_link;
3944 + acl_entry_link = acl_entry_link->nextp;
3945 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3946 + if(acl_entry_link->entryp == NULL) {
3948 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3949 + SAFE_FREE(file_acl);
3953 + acl_entry_link->nextp = NULL;
3956 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3958 + /* Don't really need this since all types are going *
3959 + * to be specified but, it's better than leaving it 0 */
3961 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3962 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3964 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
3966 + /* The access in the acl entries must be left shifted by *
3967 + * three bites, because they will ultimately be compared *
3968 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3970 + switch(acl_entry->ace_type){
3973 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3974 + acl_entry_link->entryp->ace_access <<= 6;
3975 + acl_entry_link_head->count++;
3978 + /* Since there is no way to return a DENY acl entry *
3979 + * change to PERMIT and then shift. */
3980 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3981 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3982 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3983 + acl_entry_link->entryp->ace_access <<= 6;
3984 + acl_entry_link_head->count++;
3990 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3991 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3993 + acl_entry = acl_nxt(acl_entry);
3995 + } /* end of if enabled */
3997 + /* Since owner, group, other acl entries are not *
3998 + * part of the acl entries in an acl, they must *
3999 + * be dummied up to become part of the list. */
4001 + for( i = 1; i < 4; i++) {
4002 + DEBUG(10,("i is %d\n",i));
4003 + if(acl_entry_link_head->count != 0){
4004 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4005 + if(acl_entry_link->nextp == NULL) {
4007 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4008 + SAFE_FREE(file_acl);
4012 + acl_entry_link->nextp->prevp = acl_entry_link;
4013 + acl_entry_link = acl_entry_link->nextp;
4014 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4016 + if(acl_entry_link->entryp == NULL) {
4017 + SAFE_FREE(file_acl);
4019 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4024 + acl_entry_link->nextp = NULL;
4026 + new_acl_entry = acl_entry_link->entryp;
4027 + idp = new_acl_entry->ace_id;
4029 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4030 + new_acl_entry->ace_type = ACC_PERMIT;
4031 + idp->id_len = sizeof(struct ace_id);
4032 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4033 + memset(idp->id_data,0,sizeof(uid_t));
4037 + new_acl_entry->ace_access = file_acl->g_access << 6;
4038 + idp->id_type = SMB_ACL_GROUP_OBJ;
4042 + new_acl_entry->ace_access = file_acl->o_access << 6;
4043 + idp->id_type = SMB_ACL_OTHER;
4047 + new_acl_entry->ace_access = file_acl->u_access << 6;
4048 + idp->id_type = SMB_ACL_USER_OBJ;
4055 + acl_entry_link_head->count++;
4056 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4059 + acl_entry_link_head->count = 0;
4060 + SAFE_FREE(file_acl);
4062 + return(acl_entry_link_head);
4065 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4067 + *permset = *permset & ~0777;
4071 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4074 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4078 + DEBUG(10,("This is the permset now: %d\n",*permset));
4082 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4087 +SMB_ACL_T sys_acl_init( int count)
4089 + struct acl_entry_link *theacl = NULL;
4091 + DEBUG(10,("Entering sys_acl_init\n"));
4093 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4094 + if(theacl == NULL) {
4096 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4100 + theacl->count = 0;
4101 + theacl->nextp = NULL;
4102 + theacl->prevp = NULL;
4103 + theacl->entryp = NULL;
4104 + DEBUG(10,("Exiting sys_acl_init\n"));
4108 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4110 + struct acl_entry_link *theacl;
4111 + struct acl_entry_link *acl_entryp;
4112 + struct acl_entry_link *temp_entry;
4115 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4117 + theacl = acl_entryp = *pacl;
4119 + /* Get to the end of the acl before adding entry */
4121 + for(counting=0; counting < theacl->count; counting++){
4122 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4123 + temp_entry = acl_entryp;
4124 + acl_entryp = acl_entryp->nextp;
4127 + if(theacl->count != 0){
4128 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4129 + if(acl_entryp == NULL) {
4131 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4135 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4136 + acl_entryp->prevp = temp_entry;
4137 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4140 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4141 + if(*pentry == NULL) {
4143 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4147 + memset(*pentry,0,sizeof(struct new_acl_entry));
4148 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4149 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4150 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4151 + acl_entryp->nextp = NULL;
4153 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4157 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4159 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4160 + entry->ace_id->id_type = tagtype;
4161 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4162 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4165 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4167 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4168 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4169 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4173 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4175 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4176 + if(!(*permset & S_IXUSR) &&
4177 + !(*permset & S_IWUSR) &&
4178 + !(*permset & S_IRUSR) &&
4182 + entry->ace_access = *permset;
4183 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4184 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4188 +int sys_acl_valid( SMB_ACL_T theacl )
4191 + int group_obj = 0;
4192 + int other_obj = 0;
4193 + struct acl_entry_link *acl_entry;
4195 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4196 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4197 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4198 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4201 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4203 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4209 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4211 + struct acl_entry_link *acl_entry_link = NULL;
4212 + struct acl *file_acl = NULL;
4213 + struct acl *file_acl_temp = NULL;
4214 + struct acl_entry *acl_entry = NULL;
4215 + struct ace_id *ace_id = NULL;
4222 + DEBUG(10,("Entering sys_acl_set_file\n"));
4223 + DEBUG(10,("File name is %s\n",name));
4225 + /* AIX has no default ACL */
4226 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4229 + acl_length = BUFSIZ;
4230 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4232 + if(file_acl == NULL) {
4234 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4238 + memset(file_acl,0,BUFSIZ);
4240 + file_acl->acl_len = ACL_SIZ;
4241 + file_acl->acl_mode = S_IXACL;
4243 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4244 + acl_entry_link->entryp->ace_access >>= 6;
4245 + id_type = acl_entry_link->entryp->ace_id->id_type;
4248 + case SMB_ACL_USER_OBJ:
4249 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4251 + case SMB_ACL_GROUP_OBJ:
4252 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4254 + case SMB_ACL_OTHER:
4255 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4257 + case SMB_ACL_MASK:
4261 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4262 + acl_length += sizeof(struct acl_entry);
4263 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4264 + if(file_acl_temp == NULL) {
4265 + SAFE_FREE(file_acl);
4267 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4271 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4272 + SAFE_FREE(file_acl);
4273 + file_acl = file_acl_temp;
4276 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4277 + file_acl->acl_len += sizeof(struct acl_entry);
4278 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4279 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4281 + /* In order to use this, we'll need to wait until we can get denies */
4282 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4283 + acl_entry->ace_type = ACC_SPECIFY; */
4285 + acl_entry->ace_type = ACC_SPECIFY;
4287 + ace_id = acl_entry->ace_id;
4289 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4290 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4291 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4292 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4293 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4296 + rc = chacl(name,file_acl,file_acl->acl_len);
4297 + DEBUG(10,("errno is %d\n",errno));
4298 + DEBUG(10,("return code is %d\n",rc));
4299 + SAFE_FREE(file_acl);
4300 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4304 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4306 + struct acl_entry_link *acl_entry_link = NULL;
4307 + struct acl *file_acl = NULL;
4308 + struct acl *file_acl_temp = NULL;
4309 + struct acl_entry *acl_entry = NULL;
4310 + struct ace_id *ace_id = NULL;
4316 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4317 + acl_length = BUFSIZ;
4318 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4320 + if(file_acl == NULL) {
4322 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4326 + memset(file_acl,0,BUFSIZ);
4328 + file_acl->acl_len = ACL_SIZ;
4329 + file_acl->acl_mode = S_IXACL;
4331 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4332 + acl_entry_link->entryp->ace_access >>= 6;
4333 + id_type = acl_entry_link->entryp->ace_id->id_type;
4334 + DEBUG(10,("The id_type is %d\n",id_type));
4337 + case SMB_ACL_USER_OBJ:
4338 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4340 + case SMB_ACL_GROUP_OBJ:
4341 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4343 + case SMB_ACL_OTHER:
4344 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4346 + case SMB_ACL_MASK:
4350 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4351 + acl_length += sizeof(struct acl_entry);
4352 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4353 + if(file_acl_temp == NULL) {
4354 + SAFE_FREE(file_acl);
4356 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4360 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4361 + SAFE_FREE(file_acl);
4362 + file_acl = file_acl_temp;
4365 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4366 + file_acl->acl_len += sizeof(struct acl_entry);
4367 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4368 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4370 + /* In order to use this, we'll need to wait until we can get denies */
4371 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4372 + acl_entry->ace_type = ACC_SPECIFY; */
4374 + acl_entry->ace_type = ACC_SPECIFY;
4376 + ace_id = acl_entry->ace_id;
4378 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4379 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4380 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4381 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4382 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4385 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4386 + DEBUG(10,("errno is %d\n",errno));
4387 + DEBUG(10,("return code is %d\n",rc));
4388 + SAFE_FREE(file_acl);
4389 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4393 +int sys_acl_delete_def_file(const char *name)
4395 + /* AIX has no default ACL */
4399 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4401 + return(*permset & perm);
4404 +int sys_acl_free_text(char *text)
4409 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4411 + struct acl_entry_link *acl_entry_link;
4413 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4414 + SAFE_FREE(acl_entry_link->prevp->entryp);
4415 + SAFE_FREE(acl_entry_link->prevp);
4418 + SAFE_FREE(acl_entry_link->prevp->entryp);
4419 + SAFE_FREE(acl_entry_link->prevp);
4420 + SAFE_FREE(acl_entry_link->entryp);
4421 + SAFE_FREE(acl_entry_link);
4426 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4431 +#else /* No ACLs. */
4433 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4439 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4445 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4451 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4457 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4460 + return (SMB_ACL_T)NULL;
4463 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4466 + return (SMB_ACL_T)NULL;
4469 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4475 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4481 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4484 + return (permset & perm) ? 1 : 0;
4487 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4493 +int sys_acl_free_text(UNUSED(char *text))
4499 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4505 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4511 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4517 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4523 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4529 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4535 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4541 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4547 +int sys_acl_delete_def_file(UNUSED(const char *name))
4553 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4559 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4565 +#endif /* No ACLs. */
4567 +/************************************************************************
4568 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4570 +************************************************************************/
4572 +int no_acl_syscall_error(int err)
4574 +#if defined(ENOSYS)
4575 + if (err == ENOSYS) {
4579 +#if defined(ENOTSUP)
4580 + if (err == ENOTSUP) {
4586 --- orig/lib/sysacls.h 2005-05-16 23:25:51
4587 +++ lib/sysacls.h 2005-05-16 23:25:51
4589 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4590 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4591 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4592 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4593 +#define slprintf snprintf
4595 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4596 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4597 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4598 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4599 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4600 +SMB_ACL_T sys_acl_get_fd(int fd);
4601 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4602 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4603 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4604 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4605 +SMB_ACL_T sys_acl_init(int count);
4606 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4607 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4608 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4609 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4610 +int sys_acl_valid(SMB_ACL_T theacl);
4611 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4612 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4613 +int sys_acl_delete_def_file(const char *name);
4614 +int sys_acl_free_text(char *text);
4615 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4616 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4617 --- orig/mkproto.awk 2005-02-18 20:16:59
4618 +++ mkproto.awk 2005-02-18 20:18:17
4619 @@ -58,7 +58,7 @@ BEGIN {
4623 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const/ {
4624 +!/^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/ {
4628 --- orig/options.c 2005-05-10 15:32:58
4629 +++ options.c 2005-05-12 23:34:38
4630 @@ -44,6 +44,7 @@ int keep_dirlinks = 0;
4632 int preserve_links = 0;
4633 int preserve_hard_links = 0;
4634 +int preserve_acls = 0;
4635 int preserve_perms = 0;
4636 int preserve_devices = 0;
4637 int preserve_uid = 0;
4638 @@ -180,6 +181,7 @@ static void print_rsync_version(enum log
4639 char const *got_socketpair = "no ";
4640 char const *have_inplace = "no ";
4641 char const *hardlinks = "no ";
4642 + char const *acls = "no ";
4643 char const *links = "no ";
4644 char const *ipv6 = "no ";
4645 STRUCT_STAT *dumstat;
4646 @@ -196,6 +198,10 @@ static void print_rsync_version(enum log
4650 +#ifdef SUPPORT_ACLS
4654 #ifdef SUPPORT_LINKS
4657 @@ -210,9 +216,9 @@ static void print_rsync_version(enum log
4658 "Copyright (C) 1996-2005 by Andrew Tridgell and others\n");
4659 rprintf(f, "<http://rsync.samba.org/>\n");
4660 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4661 - "%shard links, %ssymlinks, batchfiles, \n",
4662 + "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
4663 (int) (sizeof (OFF_T) * 8),
4664 - got_socketpair, hardlinks, links);
4665 + got_socketpair, hardlinks, acls, links);
4667 /* Note that this field may not have type ino_t. It depends
4668 * on the complicated interaction between largefile feature
4669 @@ -282,6 +288,7 @@ void usage(enum logcode F)
4670 rprintf(F," -H, --hard-links preserve hard links\n");
4671 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
4672 rprintf(F," -p, --perms preserve permissions\n");
4673 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4674 rprintf(F," -o, --owner preserve owner (root only)\n");
4675 rprintf(F," -g, --group preserve group\n");
4676 rprintf(F," -D, --devices preserve devices (root only)\n");
4677 @@ -409,6 +416,7 @@ static struct poptOption long_options[]
4678 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
4679 {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
4680 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
4681 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4682 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
4683 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
4684 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
4685 @@ -882,6 +890,24 @@ int parse_arguments(int *argc, const cha
4686 basis_dir[basis_dir_cnt++] = (char *)arg;
4690 +#ifdef SUPPORT_ACLS
4691 + preserve_acls = 1;
4692 + preserve_perms = 1;
4694 + /* FIXME: this should probably be ignored with a
4695 + * warning and then countermeasures taken to
4696 + * restrict group and other access in the presence
4697 + * of any more restrictive ACLs, but this is safe
4699 + snprintf(err_buf,sizeof(err_buf),
4700 + "ACLs are not supported on this %s\n",
4701 + am_server ? "server" : "client");
4703 +#endif /* SUPPORT_ACLS */
4708 /* A large opt value means that set_refuse_options()
4709 * turned this option off. */
4710 @@ -1286,6 +1312,8 @@ void server_options(char **args,int *arg
4712 if (preserve_hard_links)
4714 + if (preserve_acls)
4715 + argstr[x++] = 'A';
4719 --- orig/rsync.c 2005-03-16 02:19:30
4720 +++ rsync.c 2004-07-03 20:11:58
4721 @@ -137,6 +137,14 @@ int set_perms(char *fname,struct file_st
4725 + /* If this is a directory, SET_ACL() will be called on the cleanup
4726 + * receive_generator() pass--if we called it here, we might clobber
4727 + * writability on the directory. everything else is OK to do now. */
4728 + if (!S_ISDIR(st->st_mode)) {
4729 + if (SET_ACL(fname, file) == 0)
4733 if (verbose > 1 && flags & PERMS_REPORT) {
4734 enum logcode code = daemon_log_format_has_i || dry_run
4736 --- orig/rsync.h 2005-05-03 17:11:01
4737 +++ rsync.h 2005-05-12 23:32:56
4738 @@ -638,6 +638,44 @@ struct stats {
4739 #include "lib/permstring.h"
4740 #include "lib/addrinfo.h"
4742 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4743 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4744 +#define SUPPORT_ACLS 1
4747 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4748 +#define ACLS_NEED_MASK 1
4751 +#ifdef SUPPORT_ACLS
4752 +#ifdef HAVE_SYS_ACL_H
4753 +#include <sys/acl.h>
4755 +#define MAKE_ACL(file, fname) make_acl(file, fname)
4756 +#define SEND_ACL(file, f) send_acl(file, f)
4757 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
4758 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4759 +#define SET_ACL(fname, file) set_acl(fname, file)
4760 +#define NEXT_ACL_UID() next_acl_uid()
4761 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
4762 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4763 + push_keep_backup_acl(file, orig, dest)
4764 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4765 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4766 +#else /* SUPPORT_ACLS */
4767 +#define MAKE_ACL(file, fname) 1 /* checked return value */
4768 +#define SEND_ACL(file, f)
4769 +#define RECEIVE_ACL(file, f)
4770 +#define SORT_FILE_ACL_INDEX_LISTS()
4771 +#define SET_ACL(fname, file) 0 /* checked return value */
4772 +#define NEXT_ACL_UID()
4773 +#define ACL_UID_MAP(uid)
4774 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4775 +#define CLEANUP_KEEP_BACKUP_ACL()
4776 +#define DUP_ACL(src, orig, mode) 0 /* checked return value */
4777 +#endif /* SUPPORT_ACLS */
4778 +#include "smb_acls.h"
4782 /* We have replacement versions of these if they're missing. */
4783 --- orig/rsync.yo 2005-05-10 23:47:12
4784 +++ rsync.yo 2004-07-03 20:11:58
4785 @@ -317,6 +317,7 @@ to the detailed description below for a
4786 -H, --hard-links preserve hard links
4787 -K, --keep-dirlinks treat symlinked dir on receiver as dir
4788 -p, --perms preserve permissions
4789 + -A, --acls preserve ACLs (implies -p) [local option]
4790 -o, --owner preserve owner (root only)
4791 -g, --group preserve group
4792 -D, --devices preserve devices (root only)
4793 @@ -629,6 +630,11 @@ based on the source file's permissions,
4795 (which is the same behavior as other file-copy utilities, such as cp).
4797 +dit(bf(-A, --acls)) This option causes rsync to update the remote
4798 +ACLs to be the same as the local ACLs. This will work only if the
4799 +remote machine's rsync supports this option also. This is a non-standard
4802 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
4803 destination file to be the same as the source file. On most systems,
4804 only the super-user can set file ownership. By default, the preservation
4805 --- orig/smb_acls.h 2004-06-30 00:04:07
4806 +++ smb_acls.h 2004-06-30 00:04:07
4809 + Unix SMB/Netbios implementation.
4811 + Portable SMB ACL interface
4812 + Copyright (C) Jeremy Allison 2000
4814 + This program is free software; you can redistribute it and/or modify
4815 + it under the terms of the GNU General Public License as published by
4816 + the Free Software Foundation; either version 2 of the License, or
4817 + (at your option) any later version.
4819 + This program is distributed in the hope that it will be useful,
4820 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4821 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4822 + GNU General Public License for more details.
4824 + You should have received a copy of the GNU General Public License
4825 + along with this program; if not, write to the Free Software
4826 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4829 +#ifndef _SMB_ACLS_H
4830 +#define _SMB_ACLS_H
4832 +#if defined(HAVE_POSIX_ACLS)
4834 +/* This is an identity mapping (just remove the SMB_). */
4836 +#define SMB_ACL_TAG_T acl_tag_t
4837 +#define SMB_ACL_TYPE_T acl_type_t
4838 +#define SMB_ACL_PERMSET_T acl_permset_t
4839 +#define SMB_ACL_PERM_T acl_perm_t
4840 +#define SMB_ACL_READ ACL_READ
4841 +#define SMB_ACL_WRITE ACL_WRITE
4842 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4844 +/* Types of ACLs. */
4845 +#define SMB_ACL_USER ACL_USER
4846 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4847 +#define SMB_ACL_GROUP ACL_GROUP
4848 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4849 +#define SMB_ACL_OTHER ACL_OTHER
4850 +#define SMB_ACL_MASK ACL_MASK
4852 +#define SMB_ACL_T acl_t
4854 +#define SMB_ACL_ENTRY_T acl_entry_t
4856 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
4857 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
4859 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4860 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4862 +#elif defined(HAVE_TRU64_ACLS)
4864 +/* This is for DEC/Compaq Tru64 UNIX */
4866 +#define SMB_ACL_TAG_T acl_tag_t
4867 +#define SMB_ACL_TYPE_T acl_type_t
4868 +#define SMB_ACL_PERMSET_T acl_permset_t
4869 +#define SMB_ACL_PERM_T acl_perm_t
4870 +#define SMB_ACL_READ ACL_READ
4871 +#define SMB_ACL_WRITE ACL_WRITE
4872 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4874 +/* Types of ACLs. */
4875 +#define SMB_ACL_USER ACL_USER
4876 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4877 +#define SMB_ACL_GROUP ACL_GROUP
4878 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4879 +#define SMB_ACL_OTHER ACL_OTHER
4880 +#define SMB_ACL_MASK ACL_MASK
4882 +#define SMB_ACL_T acl_t
4884 +#define SMB_ACL_ENTRY_T acl_entry_t
4886 +#define SMB_ACL_FIRST_ENTRY 0
4887 +#define SMB_ACL_NEXT_ENTRY 1
4889 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4890 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4892 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
4894 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
4895 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
4898 +/* SVR4.2 ES/MP ACLs */
4899 +typedef int SMB_ACL_TAG_T;
4900 +typedef int SMB_ACL_TYPE_T;
4901 +typedef ushort *SMB_ACL_PERMSET_T;
4902 +typedef ushort SMB_ACL_PERM_T;
4903 +#define SMB_ACL_READ 4
4904 +#define SMB_ACL_WRITE 2
4905 +#define SMB_ACL_EXECUTE 1
4907 +/* Types of ACLs. */
4908 +#define SMB_ACL_USER USER
4909 +#define SMB_ACL_USER_OBJ USER_OBJ
4910 +#define SMB_ACL_GROUP GROUP
4911 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
4912 +#define SMB_ACL_OTHER OTHER_OBJ
4913 +#define SMB_ACL_MASK CLASS_OBJ
4915 +typedef struct SMB_ACL_T {
4919 + struct acl acl[1];
4922 +typedef struct acl *SMB_ACL_ENTRY_T;
4924 +#define SMB_ACL_FIRST_ENTRY 0
4925 +#define SMB_ACL_NEXT_ENTRY 1
4927 +#define SMB_ACL_TYPE_ACCESS 0
4928 +#define SMB_ACL_TYPE_DEFAULT 1
4930 +#elif defined(HAVE_HPUX_ACLS)
4933 + * Based on the Solaris & UnixWare code.
4937 +#include <sys/aclv.h>
4939 +/* SVR4.2 ES/MP ACLs */
4940 +typedef int SMB_ACL_TAG_T;
4941 +typedef int SMB_ACL_TYPE_T;
4942 +typedef ushort *SMB_ACL_PERMSET_T;
4943 +typedef ushort SMB_ACL_PERM_T;
4944 +#define SMB_ACL_READ 4
4945 +#define SMB_ACL_WRITE 2
4946 +#define SMB_ACL_EXECUTE 1
4948 +/* Types of ACLs. */
4949 +#define SMB_ACL_USER USER
4950 +#define SMB_ACL_USER_OBJ USER_OBJ
4951 +#define SMB_ACL_GROUP GROUP
4952 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
4953 +#define SMB_ACL_OTHER OTHER_OBJ
4954 +#define SMB_ACL_MASK CLASS_OBJ
4956 +typedef struct SMB_ACL_T {
4960 + struct acl acl[1];
4963 +typedef struct acl *SMB_ACL_ENTRY_T;
4965 +#define SMB_ACL_FIRST_ENTRY 0
4966 +#define SMB_ACL_NEXT_ENTRY 1
4968 +#define SMB_ACL_TYPE_ACCESS 0
4969 +#define SMB_ACL_TYPE_DEFAULT 1
4971 +#elif defined(HAVE_IRIX_ACLS)
4973 +#define SMB_ACL_TAG_T acl_tag_t
4974 +#define SMB_ACL_TYPE_T acl_type_t
4975 +#define SMB_ACL_PERMSET_T acl_permset_t
4976 +#define SMB_ACL_PERM_T acl_perm_t
4977 +#define SMB_ACL_READ ACL_READ
4978 +#define SMB_ACL_WRITE ACL_WRITE
4979 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4981 +/* Types of ACLs. */
4982 +#define SMB_ACL_USER ACL_USER
4983 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4984 +#define SMB_ACL_GROUP ACL_GROUP
4985 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4986 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
4987 +#define SMB_ACL_MASK ACL_MASK
4989 +typedef struct SMB_ACL_T {
4995 +#define SMB_ACL_ENTRY_T acl_entry_t
4997 +#define SMB_ACL_FIRST_ENTRY 0
4998 +#define SMB_ACL_NEXT_ENTRY 1
5000 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5001 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5003 +#elif defined(HAVE_AIX_ACLS)
5005 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5007 +#include "/usr/include/acl.h"
5009 +typedef uint *SMB_ACL_PERMSET_T;
5011 +struct acl_entry_link{
5012 + struct acl_entry_link *prevp;
5013 + struct new_acl_entry *entryp;
5014 + struct acl_entry_link *nextp;
5018 +struct new_acl_entry{
5019 + unsigned short ace_len;
5020 + unsigned short ace_type;
5021 + unsigned int ace_access;
5022 + struct ace_id ace_id[1];
5025 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5026 +#define SMB_ACL_T struct acl_entry_link*
5028 +#define SMB_ACL_TAG_T unsigned short
5029 +#define SMB_ACL_TYPE_T int
5030 +#define SMB_ACL_PERM_T uint
5031 +#define SMB_ACL_READ S_IRUSR
5032 +#define SMB_ACL_WRITE S_IWUSR
5033 +#define SMB_ACL_EXECUTE S_IXUSR
5035 +/* Types of ACLs. */
5036 +#define SMB_ACL_USER ACEID_USER
5037 +#define SMB_ACL_USER_OBJ 3
5038 +#define SMB_ACL_GROUP ACEID_GROUP
5039 +#define SMB_ACL_GROUP_OBJ 4
5040 +#define SMB_ACL_OTHER 5
5041 +#define SMB_ACL_MASK 6
5044 +#define SMB_ACL_FIRST_ENTRY 1
5045 +#define SMB_ACL_NEXT_ENTRY 2
5047 +#define SMB_ACL_TYPE_ACCESS 0
5048 +#define SMB_ACL_TYPE_DEFAULT 1
5050 +#else /* No ACLs. */
5052 +/* No ACLS - fake it. */
5053 +#define SMB_ACL_TAG_T int
5054 +#define SMB_ACL_TYPE_T int
5055 +#define SMB_ACL_PERMSET_T mode_t
5056 +#define SMB_ACL_PERM_T mode_t
5057 +#define SMB_ACL_READ S_IRUSR
5058 +#define SMB_ACL_WRITE S_IWUSR
5059 +#define SMB_ACL_EXECUTE S_IXUSR
5061 +/* Types of ACLs. */
5062 +#define SMB_ACL_USER 0
5063 +#define SMB_ACL_USER_OBJ 1
5064 +#define SMB_ACL_GROUP 2
5065 +#define SMB_ACL_GROUP_OBJ 3
5066 +#define SMB_ACL_OTHER 4
5067 +#define SMB_ACL_MASK 5
5069 +typedef struct SMB_ACL_T {
5073 +typedef struct SMB_ACL_ENTRY_T {
5075 +} *SMB_ACL_ENTRY_T;
5077 +#define SMB_ACL_FIRST_ENTRY 0
5078 +#define SMB_ACL_NEXT_ENTRY 1
5080 +#define SMB_ACL_TYPE_ACCESS 0
5081 +#define SMB_ACL_TYPE_DEFAULT 1
5083 +#endif /* No ACLs. */
5084 +#endif /* _SMB_ACLS_H */
5085 --- orig/uidlist.c 2005-02-14 00:53:44
5086 +++ uidlist.c 2004-07-03 20:11:58
5089 extern int preserve_uid;
5090 extern int preserve_gid;
5091 +extern int preserve_acls;
5092 extern int numeric_ids;
5095 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5099 - if (preserve_uid) {
5100 + if (preserve_uid || preserve_acls) {
5102 /* we send sequences of uid/byte-length/name */
5103 for (list = uidlist; list; list = list->next) {
5104 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5108 - if (preserve_gid) {
5109 + if (preserve_gid || preserve_acls) {
5111 for (list = gidlist; list; list = list->next) {
5113 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5117 - if (preserve_uid && !numeric_ids) {
5118 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5119 /* read the uid list */
5120 while ((id = read_int(f)) != 0) {
5121 int len = read_byte(f);
5122 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
5126 - if (preserve_gid && !numeric_ids) {
5127 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5128 /* read the gid list */
5129 while ((id = read_int(f)) != 0) {
5130 int len = read_byte(f);
5131 @@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li
5136 + if (preserve_acls && !numeric_ids) {
5138 + /* the enumerations don't return 0 except to flag the last
5139 + * entry, since uidlist doesn't munge 0 anyway */
5140 + while ((id = next_acl_uid(flist)))
5141 + acl_uid_map(match_uid(id));
5142 + while ((id = next_acl_gid(flist)))
5143 + acl_gid_map(match_gid(id));
5145 +#endif /* SUPPORT_ACLS */
5147 /* now convert the uid/gid of all files in the list to the mapped
5149 if (am_root && preserve_uid && !numeric_ids) {