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 2005-07-07 23:11:07
15 +++ Makefile.in 2005-07-07 23:11:55
16 @@ -25,15 +25,15 @@ 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/inffast.o zlib/inflate.o zlib/inftrees.o \
26 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
27 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
28 main.o checksum.o match.o syscall.o log.o backup.o
29 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
30 - fileio.o batch.o clientname.o
31 + fileio.o batch.o clientname.o acls.o
32 OBJS3=progress.o pipe.o
33 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
34 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
35 --- orig/acls.c 2005-07-29 02:48:46
36 +++ acls.c 2005-07-29 02:48:46
38 +/* -*- c-file-style: "linux" -*-
39 + Copyright (C) Andrew Tridgell 1996
40 + Copyright (C) Paul Mackerras 1996
42 + This program is free software; you can redistribute it and/or modify
43 + it under the terms of the GNU General Public License as published by
44 + the Free Software Foundation; either version 2 of the License, or
45 + (at your option) any later version.
47 + This program is distributed in the hope that it will be useful,
48 + but WITHOUT ANY WARRANTY; without even the implied warranty of
49 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 + GNU General Public License for more details.
52 + You should have received a copy of the GNU General Public License
53 + along with this program; if not, write to the Free Software
54 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
57 +/* handle passing ACLs between systems */
60 +#include "lib/sysacls.h"
64 +extern int preserve_acls;
71 + SMB_ACL_TAG_T tag_type;
80 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
82 +static void expand_rsync_acl(rsync_acl *racl)
84 + /* First time through, 0 <= 0, so list is expanded.
85 + * (Diabolical, rsync guys!) */
86 + if (racl->malloced <= racl->count) {
88 + size_t new_size = racl->malloced + 10;
89 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
91 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
92 + (double) new_size * sizeof racl->races[0],
93 + racl->races ? "" : " not");
96 + racl->races = new_ptr;
97 + racl->malloced = new_size;
100 + out_of_memory("expand_rsync_acl");
104 +static void rsync_acl_free(rsync_acl *racl)
107 + racl->races = NULL;
109 + racl->malloced = 0;
112 +static int rsync_ace_sorter(const void *r1, const void *r2)
114 + rsync_ace *race1 = (rsync_ace *)r1;
115 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
116 + id_t rid1 = race1->id;
117 + rsync_ace *race2 = (rsync_ace *)r2;
118 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
119 + id_t rid2 = race2->id;
120 + /* start at the extrema */
121 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
123 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
126 + if (rtag1 == SMB_ACL_OTHER)
128 + if (rtag2 == SMB_ACL_OTHER)
130 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
131 + if (rtag1 == SMB_ACL_USER) {
133 + case SMB_ACL_GROUP:
134 + case SMB_ACL_GROUP_OBJ:
135 + case SMB_ACL_OTHER:
139 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
141 + if (rtag2 == SMB_ACL_USER)
143 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
144 + if (rtag1 == SMB_ACL_GROUP_OBJ)
146 + if (rtag2 == SMB_ACL_GROUP_OBJ)
148 + /* only SMB_ACL_GROUPs left */
149 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
152 +static void sort_rsync_acl(rsync_acl *racl)
156 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
157 + &rsync_ace_sorter);
160 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
162 + SMB_ACL_ENTRY_T entry;
164 + const char *errfun;
165 + *racl = rsync_acl_initializer;
166 + errfun = "sys_acl_get_entry";
167 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
169 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
170 + SMB_ACL_PERMSET_T permset;
173 + expand_rsync_acl(racl);
174 + race = &racl->races[racl->count++];
175 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
176 + errfun = "sys_acl_get_tag_type";
179 + if ((rc = sys_acl_get_permset(entry, &permset))) {
180 + errfun = "sys_acl_get_tag_type";
183 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
184 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
185 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
186 + switch (race->tag_type) {
188 + case SMB_ACL_GROUP:
193 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
194 + errfun = "sys_acl_get_tag_type";
198 + race->id = *((id_t *)qualifier);
199 + sys_acl_free_qualifier(qualifier, race->tag_type);
202 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
203 + errfun, strerror(errno));
204 + rsync_acl_free(racl);
207 + sort_rsync_acl(racl);
211 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
213 + rsync_ace *race1, *race2;
214 + size_t count = racl1->count;
215 + if (count != racl2->count)
217 + race1 = racl1->races;
218 + race2 = racl2->races;
219 + for (; count--; race1++, race2++) {
220 + if (race1->tag_type != race2->tag_type
221 + || race1->access != race2->access
222 + || ((race1->tag_type == SMB_ACL_USER
223 + || race1->tag_type == SMB_ACL_GROUP)
224 + && race1->id != race2->id))
236 +static rsync_acl_list _rsync_acl_lists[] = {
237 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
238 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
241 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
243 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
244 + : &_rsync_acl_lists[1];
247 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
249 + /* First time through, 0 <= 0, so list is expanded.
250 + * (Diabolical, rsync guys!) */
251 + if (racl_list->malloced <= racl_list->count) {
252 + rsync_acl *new_ptr;
254 + if (racl_list->malloced < 1000)
255 + new_size = racl_list->malloced + 1000;
257 + new_size = racl_list->malloced * 2;
258 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
259 + if (verbose >= 3) {
260 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
261 + (double) new_size * sizeof racl_list->racls[0],
262 + racl_list->racls ? "" : " not");
265 + racl_list->racls = new_ptr;
266 + racl_list->malloced = new_size;
268 + if (!racl_list->racls)
269 + out_of_memory("expand_rsync_acl_list");
274 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
276 + /* Run this in reverse, so references are freed before referents,
277 + * although not currently necessary. */
278 + while (racl_list->count--) {
279 + rsync_acl *racl = &racl_list->racls[racl_list->count];
281 + rsync_acl_free(racl);
283 + free(racl_list->racls);
284 + racl_list->racls = NULL;
285 + racl_list->malloced = 0;
289 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
290 + const rsync_acl_list *racl_list,
291 + const rsync_acl *racl)
293 + static int access_match = -1, default_match = -1;
294 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
295 + &access_match : &default_match;
296 + size_t count = racl_list->count;
297 + /* If this is the first time through or we didn't match the last
298 + * time, then start at the end of the list, which should be the
299 + * best place to start hunting. */
301 + *match = racl_list->count - 1;
303 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
306 + *match = racl_list->count - 1;
312 +/* The general strategy with the tag_type <-> character mapping is that
313 + * lowercase implies that no qualifier follows, where uppercase does.
314 + * A similar idiom for the acl type (access or default) itself, but
315 + * lowercase in this instance means there's no ACL following, so the
316 + * ACL is a repeat, so the receiver should reuse the last of the same
319 +static void send_rsync_acl(int f, const rsync_acl *racl)
322 + size_t count = racl->count;
323 + write_int(f, count);
324 + for (race = racl->races; count--; race++) {
326 + switch (race->tag_type) {
327 + case SMB_ACL_USER_OBJ:
333 + case SMB_ACL_GROUP_OBJ:
336 + case SMB_ACL_GROUP:
339 + case SMB_ACL_OTHER:
347 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
352 + write_byte(f, race->access);
353 + if (isupper((int)ch)) {
354 + write_int(f, race->id);
355 + /* FIXME: sorta wasteful: we should maybe buffer as
356 + * many ids as max(ACL_USER + ACL_GROUP) objects to
357 + * keep from making so many calls. */
366 +static rsync_acl _curr_rsync_acls[2];
369 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
371 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
372 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
373 + "unknown SMB_ACL_TYPE_T";
376 +/* Generate the ACL(s) for this flist entry;
377 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
379 +BOOL make_acl(const struct file_struct *file, const char *fname)
381 + SMB_ACL_TYPE_T *type,
382 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
383 + rsync_acl *curr_racl;
384 + if (!preserve_acls || S_ISLNK(file->mode))
386 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
387 + type < &types[0] + sizeof types / sizeof types[0]
388 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
389 + type++, curr_racl++) {
392 + *curr_racl = rsync_acl_initializer;
393 + if (!(sacl = sys_acl_get_file(fname, *type))) {
394 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
395 + fname, str_acl_type(*type), strerror(errno));
398 + ok = unpack_smb_acl(curr_racl, sacl);
399 + sys_acl_free_acl(sacl);
406 +/* Send the make_acl()-generated ACLs for this flist entry,
407 + * or clean up after an flist entry that's not being sent (f == -1). */
409 +void send_acl(const struct file_struct *file, int f)
411 + SMB_ACL_TYPE_T *type,
412 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
413 + rsync_acl *curr_racl;
414 + if (!preserve_acls || S_ISLNK(file->mode))
416 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
417 + type < &types[0] + sizeof types / sizeof types[0]
418 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
419 + type++, curr_racl++) {
421 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
423 + rsync_acl_free(curr_racl);
426 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
428 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
429 + write_int(f, index);
430 + rsync_acl_free(curr_racl);
432 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
433 + send_rsync_acl(f, curr_racl);
434 + expand_rsync_acl_list(racl_list);
435 + racl_list->racls[racl_list->count++] = *curr_racl;
440 +/* The below stuff is only used by the receiver: */
442 +/* structure to hold index to rsync_acl_list member corresponding to
443 + * flist->files[i] */
446 + const struct file_struct *file;
453 + file_acl_index *fileaclidxs;
454 +} file_acl_index_list;
456 +static file_acl_index_list _file_acl_index_lists[] = {
457 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
458 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
461 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
463 + return type == SMB_ACL_TYPE_ACCESS ?
464 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
467 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
469 + /* First time through, 0 <= 0, so list is expanded.
470 + * (Diabolical, rsync guys!) */
471 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
472 + file_acl_index *new_ptr;
474 + if (fileaclidx_list->malloced < 1000)
475 + new_size = fileaclidx_list->malloced + 1000;
477 + new_size = fileaclidx_list->malloced * 2;
478 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
479 + if (verbose >= 3) {
480 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
481 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
482 + fileaclidx_list->fileaclidxs ? "" : " not");
485 + fileaclidx_list->fileaclidxs = new_ptr;
486 + fileaclidx_list->malloced = new_size;
488 + if (!fileaclidx_list->fileaclidxs)
489 + out_of_memory("expand_file_acl_index_list");
494 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
496 + free(fileaclidx_list->fileaclidxs);
497 + fileaclidx_list->fileaclidxs = NULL;
498 + fileaclidx_list->malloced = 0;
502 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
510 +static smb_acl_list _smb_acl_lists[] = {
511 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
512 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
515 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
517 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
518 + &_smb_acl_lists[1];
521 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
523 + /* First time through, 0 <= 0, so list is expanded.
524 + * (Diabolical, rsync guys!) */
525 + if (sacl_list->malloced <= sacl_list->count) {
526 + SMB_ACL_T *new_ptr;
528 + if (sacl_list->malloced < 1000)
529 + new_size = sacl_list->malloced + 1000;
531 + new_size = sacl_list->malloced * 2;
532 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
533 + if (verbose >= 3) {
534 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
535 + (double) new_size * sizeof sacl_list->sacls[0],
536 + sacl_list->sacls ? "" : " not");
539 + sacl_list->sacls = new_ptr;
540 + sacl_list->malloced = new_size;
542 + if (!sacl_list->sacls)
543 + out_of_memory("expand_smb_acl_list");
548 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
550 + smb_acl_list *sacl_list = smb_acl_lists(type);
551 + SMB_ACL_T *sacl = sacl_list->sacls;
552 + while (sacl_list->count--) {
554 + sys_acl_free_acl(*sacl++);
556 + free(sacl_list->sacls);
557 + sacl_list->sacls = NULL;
558 + sacl_list->malloced = 0;
562 +/* build an SMB_ACL_T corresponding to an rsync_acl */
563 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
565 + size_t count = racl->count;
566 + rsync_ace *race = racl->races;
567 + const char *errfun = NULL;
568 + *smb_acl = sys_acl_init(count);
570 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
574 + for (; count--; race++) {
575 + SMB_ACL_ENTRY_T entry;
576 + SMB_ACL_PERMSET_T permset;
577 + if (sys_acl_create_entry(smb_acl, &entry)) {
578 + errfun = "sys_acl_create)";
581 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
582 + errfun = "sys_acl_set_tag";
585 + if (race->tag_type == SMB_ACL_USER ||
586 + race->tag_type == SMB_ACL_GROUP)
587 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
588 + errfun = "sys_acl_set_qualfier";
591 + if (sys_acl_get_permset(entry, &permset)) {
592 + errfun = "sys_acl_get_permset";
595 + if (sys_acl_clear_perms(permset)) {
596 + errfun = "sys_acl_clear_perms";
599 + if (race->access & 4)
600 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
601 + errfun = "sys_acl_add_perm";
604 + if (race->access & 2)
605 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
606 + errfun = "sys_acl_add_perm";
609 + if (race->access & 1)
610 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
611 + errfun = "sys_acl_add_perm";
614 + if (sys_acl_set_permset(entry, permset)) {
615 + errfun = "sys_acl_set_permset";
620 + sys_acl_free_acl(*smb_acl);
621 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
628 +static void receive_rsync_acl(rsync_acl *racl, int f)
631 + uchar required_mask_perm = 0;
633 + BOOL saw_mask = False;
634 + BOOL saw_user_obj = False, saw_group_obj = False,
636 + size_t count = read_int(f);
641 + uchar tag = read_byte(f);
642 + expand_rsync_acl(racl);
643 + race = &racl->races[racl->count++];
646 + race->tag_type = SMB_ACL_USER_OBJ;
647 + saw_user_obj = True;
650 + race->tag_type = SMB_ACL_USER;
653 + race->tag_type = SMB_ACL_GROUP_OBJ;
654 + saw_group_obj = True;
657 + race->tag_type = SMB_ACL_GROUP;
660 + race->tag_type = SMB_ACL_OTHER;
664 + race->tag_type = SMB_ACL_MASK;
668 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
670 + exit_cleanup(RERR_STREAMIO);
672 + race->access = read_byte(f);
673 + if (race->access & ~ (4 | 2 | 1)) {
674 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
676 + exit_cleanup(RERR_STREAMIO);
678 + if (race->tag_type == SMB_ACL_USER ||
679 + race->tag_type == SMB_ACL_GROUP) {
680 + race->id = read_int(f);
682 + required_mask_perm |= race->access;
686 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
687 + required_mask_perm |= race->access;
691 + if (!saw_user_obj) {
692 + expand_rsync_acl(racl);
693 + race = &racl->races[racl->count++];
694 + race->tag_type = SMB_ACL_USER_OBJ;
697 + if (!saw_group_obj) {
698 + expand_rsync_acl(racl);
699 + race = &racl->races[racl->count++];
700 + race->tag_type = SMB_ACL_GROUP_OBJ;
704 + expand_rsync_acl(racl);
705 + race = &racl->races[racl->count++];
706 + race->tag_type = SMB_ACL_OTHER;
711 + expand_rsync_acl(racl);
712 + race = &racl->races[racl->count++];
713 + race->tag_type = SMB_ACL_MASK;
714 + race->access = required_mask_perm;
717 + /* If we, a system without ACLS_NEED_MASK, received data from a
718 + * system that has masks, throw away the extraneous CLASS_OBJs. */
719 + if (saw_mask && racl->count == 4) {
720 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
723 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
724 + if (p->tag_type == SMB_ACL_MASK)
726 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
727 + group_obj_race = p;
729 + if (mask_race == NULL || group_obj_race == NULL) {
730 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
731 + "and one's ACL_MASK but missing "
732 + "either it or ACL_GROUP_OBJ, "
733 + "when pruning ACL\n");
735 + /* mask off group perms with it first */
736 + group_obj_race->access &= mask_race->access;
737 + /* dump mask_race; re-slot any followers-on */
739 + if (mask_race != &racl->races[racl->count]) {
740 + *mask_race = racl->races[racl->count];
741 + saw_user_obj = False; /* force re-sort */
747 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
749 + if (!(saw_user_obj && saw_group_obj && saw_other))
751 + sort_rsync_acl(racl);
754 +/* receive and build the rsync_acl_lists */
756 +void receive_acl(struct file_struct *file, int f)
758 + SMB_ACL_TYPE_T *type,
759 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
761 + if (!preserve_acls || S_ISLNK(file->mode))
763 + fname = f_name(file);
764 + for (type = &types[0];
765 + type < &types[0] + sizeof types / sizeof types[0]
766 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
768 + file_acl_index_list *fileaclidx_list =
769 + file_acl_index_lists(*type);
771 + expand_file_acl_index_list(fileaclidx_list);
773 + tag = read_byte(f);
774 + if (tag == 'A' || tag == 'a') {
775 + if (*type != SMB_ACL_TYPE_ACCESS) {
776 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
778 + exit_cleanup(RERR_STREAMIO);
780 + } else if (tag == 'D' || tag == 'd') {
781 + if (*type == SMB_ACL_TYPE_ACCESS) {
782 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
784 + exit_cleanup(RERR_STREAMIO);
787 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
789 + exit_cleanup(RERR_STREAMIO);
791 + if (tag == 'A' || tag == 'D') {
792 + rsync_acl racl = rsync_acl_initializer;
793 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
794 + smb_acl_list *sacl_list = smb_acl_lists(*type);
795 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
796 + aclidx = racl_list->count;
797 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
799 + receive_rsync_acl(&racl, f);
800 + expand_rsync_acl_list(racl_list);
801 + racl_list->racls[racl_list->count++] = racl;
802 + expand_smb_acl_list(sacl_list);
803 + sacl_list->sacls[sacl_list->count++] = NULL;
805 + int index = read_int(f);
806 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
807 + if ((size_t) index >= racl_list->count) {
808 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
810 + str_acl_type(*type),
812 + exit_cleanup(RERR_STREAMIO);
814 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
816 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
822 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
824 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
825 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
826 + return fileaclidx1->file == fileaclidx2->file ? 0 :
827 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
830 +void sort_file_acl_index_lists()
832 + SMB_ACL_TYPE_T *type,
833 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
834 + if (!preserve_acls)
836 + for (type = &types[0];
837 + type < &types[0] + sizeof types / sizeof types[0];
840 + file_acl_index_list *fileaclidx_list =
841 + file_acl_index_lists(*type);
842 + if (!fileaclidx_list->count)
844 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
845 + sizeof fileaclidx_list->fileaclidxs[0],
846 + &file_acl_index_list_sorter);
850 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
851 + const struct file_struct *file) {
852 + int low = 0, high = fileaclidx_list->count;
853 + const struct file_struct *file_mid;
857 + int mid = (high + low) / 2;
858 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
859 + if (file_mid == file)
860 + return fileaclidx_list->fileaclidxs[mid].aclidx;
861 + if (file_mid > file)
865 + } while (low < high);
867 + file_mid = fileaclidx_list->fileaclidxs[low].file;
868 + if (file_mid == file)
869 + return fileaclidx_list->fileaclidxs[low].aclidx;
872 + "find_file_acl_index: can't find entry for file in list\n");
873 + exit_cleanup(RERR_STREAMIO);
877 +/* for duplicating ACLs on backups when using backup_dir */
879 +int dup_acl(const char *orig, const char *bak, mode_t mode)
881 + SMB_ACL_TYPE_T *type,
882 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
884 + if (!preserve_acls)
886 + for (type = &types[0];
887 + type < &types[0] + sizeof types / sizeof types[0]
888 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
890 + SMB_ACL_T sacl_orig, sacl_bak;
891 + rsync_acl racl_orig, racl_bak;
892 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
893 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
894 + orig, str_acl_type(*type), strerror(errno));
898 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
899 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
900 + bak, str_acl_type(*type), strerror(errno));
902 + /* try to forge on through */
904 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
906 + goto out_with_sacls;
909 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
911 + goto out_with_one_racl;
913 + if (rsync_acls_equal(&racl_orig, &racl_bak))
916 + ; /* presume they're unequal */
918 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
919 + if (-1 == sys_acl_delete_def_file(bak)) {
920 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
921 + bak, strerror(errno));
924 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
925 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
926 + bak, str_acl_type(*type), strerror(errno));
931 + rsync_acl_free(&racl_bak);
933 + rsync_acl_free(&racl_orig);
936 + sys_acl_free_acl(sacl_bak);
937 + /* out_with_one_sacl: */
939 + sys_acl_free_acl(sacl_orig);
944 +/* Stuff for redirecting calls to set_acl() from set_perms()
945 + * for keep_backup(). */
946 +static const struct file_struct *backup_orig_file = NULL;
947 +static const char null_string[] = "";
948 +static const char *backup_orig_fname = null_string;
949 +static const char *backup_dest_fname = null_string;
950 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
952 +void push_keep_backup_acl(const struct file_struct *file,
953 + const char *orig, const char *dest)
955 + if (preserve_acls) {
956 + SMB_ACL_TYPE_T *type,
957 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
959 + backup_orig_file = file;
960 + backup_orig_fname = orig;
961 + backup_dest_fname = dest;
962 + for (type = &types[0], sacl = &_backup_sacl[0];
963 + type < &types[0] + sizeof types / sizeof types[0];
965 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
968 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
969 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
970 + orig, str_acl_type(*type),
978 +static int set_keep_backup_acl()
980 + if (preserve_acls) {
981 + SMB_ACL_TYPE_T *type,
982 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
985 + for (type = &types[0], sacl = &_backup_sacl[0];
986 + type < &types[0] + sizeof types / sizeof types[0];
989 + if (-1 == sys_acl_set_file(backup_dest_fname,
992 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
994 + str_acl_type(*type),
1005 +void cleanup_keep_backup_acl()
1007 + if (preserve_acls) {
1008 + SMB_ACL_TYPE_T *type,
1009 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1011 + backup_orig_file = NULL;
1012 + backup_orig_fname = null_string;
1013 + backup_dest_fname = null_string;
1014 + for (type = &types[0], sacl = &_backup_sacl[0];
1015 + type < &types[0] + sizeof types / sizeof types[0];
1018 + sys_acl_free_acl(*sacl);
1024 +/* set ACL on rsync-ed or keep_backup-ed file */
1026 +int set_acl(const char *fname, const struct file_struct *file)
1029 + SMB_ACL_TYPE_T *type,
1030 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1031 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1033 + if (file == backup_orig_file) {
1034 + if (!strcmp(fname, backup_dest_fname))
1035 + return set_keep_backup_acl();
1037 + for (type = &types[0];
1038 + type < &types[0] + sizeof types / sizeof types[0]
1039 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1041 + SMB_ACL_T sacl_orig, *sacl_new;
1042 + rsync_acl racl_orig, *racl_new;
1043 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1046 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1047 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1048 + sacl_orig = sys_acl_get_file(fname, *type);
1050 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1051 + fname, str_acl_type(*type), strerror(errno));
1055 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1056 + sys_acl_free_acl(sacl_orig);
1061 + ok = rsync_acls_equal(&racl_orig, racl_new);
1062 + rsync_acl_free(&racl_orig);
1065 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1066 + if (-1 == sys_acl_delete_def_file(fname)) {
1067 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1068 + fname, strerror(errno));
1074 + if (!pack_smb_acl(sacl_new, racl_new)) {
1078 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1079 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1080 + fname, str_acl_type(*type),
1092 +/* Enumeration functions for uid mapping: */
1094 +/* Context -- one and only one. Should be cycled through once on uid
1095 + * mapping and once on gid mapping. */
1096 +static rsync_acl_list *_enum_racl_lists[] = {
1097 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1100 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1101 +static size_t enum_racl_index = 0;
1102 +static size_t enum_race_index = 0;
1104 +/* This returns the next tag_type id from the given acl for the next entry,
1105 + * or it returns 0 if there are no more tag_type ids in the acl. */
1107 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1109 + for (; enum_race_index < racl->count; enum_race_index++) {
1110 + rsync_ace *race = &racl->races[enum_race_index];
1111 + if (race->tag_type == tag_type)
1114 + enum_race_index = 0;
1118 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1120 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1121 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1122 + id_t id = next_ace_id(tag_type, racl);
1126 + enum_racl_index = 0;
1130 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1132 + for (; *enum_racl_list; enum_racl_list++) {
1133 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1137 + enum_racl_list = &_enum_racl_lists[0];
1141 +id_t next_acl_uid()
1143 + return next_acl_list_id(SMB_ACL_USER);
1146 +id_t next_acl_gid()
1148 + return next_acl_list_id(SMB_ACL_GROUP);
1151 +/* referring to the global context enum_entry, sets the entry's id */
1152 +static void set_acl_id(id_t id)
1154 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1157 +void acl_uid_map(id_t uid)
1162 +void acl_gid_map(id_t gid)
1167 +#endif /* SUPPORT_ACLS */
1168 --- orig/backup.c 2005-06-10 21:33:27
1169 +++ backup.c 2004-10-06 00:13:09
1170 @@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
1172 do_lchown(fullpath, st.st_uid, st.st_gid);
1173 do_chmod(fullpath, st.st_mode);
1174 + (void)DUP_ACL(end, fullpath, st.st_mode);
1178 @@ -187,6 +188,8 @@ static int keep_backup(char *fname)
1179 if (!(buf = get_backup_name(fname)))
1182 + PUSH_KEEP_BACKUP_ACL(file, fname, buf);
1184 /* Check to see if this is a device file, or link */
1185 if (IS_DEVICE(file->mode) && am_root && preserve_devices) {
1187 @@ -261,6 +264,7 @@ static int keep_backup(char *fname)
1190 set_perms(buf, file, NULL, 0);
1191 + CLEANUP_KEEP_BACKUP_ACL();
1195 --- orig/configure.in 2005-07-29 02:47:19
1196 +++ configure.in 2004-08-19 19:53:27
1197 @@ -489,6 +489,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1198 AC_CHECK_LIB(resolv, strcasecmp)
1201 +AC_CHECK_FUNCS(aclsort)
1202 +if test x"$ac_cv_func_aclsort" = x"no"; then
1203 + AC_CHECK_LIB(sec, aclsort)
1206 dnl At the moment we don't test for a broken memcmp(), because all we
1207 dnl need to do is test for equality, not comparison, and it seems that
1208 dnl every platform has a memcmp that can do at least that.
1209 @@ -746,6 +751,77 @@ AC_SUBST(OBJ_RESTORE)
1210 AC_SUBST(CC_SHOBJ_FLAG)
1211 AC_SUBST(BUILD_POPT)
1213 +AC_CHECK_HEADERS(sys/acl.h)
1214 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1215 +#################################################
1216 +# check for ACL support
1218 +AC_MSG_CHECKING(whether to support ACLs)
1219 +AC_ARG_WITH(acl-support,
1220 +[ --with-acl-support Include ACL support (default=no)],
1221 +[ case "$withval" in
1224 + case "$host_os" in
1226 + AC_MSG_RESULT(Using UnixWare ACLs)
1227 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1230 + AC_MSG_RESULT(Using solaris ACLs)
1231 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1234 + AC_MSG_RESULT(Using HPUX ACLs)
1235 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1238 + AC_MSG_RESULT(Using IRIX ACLs)
1239 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1242 + AC_MSG_RESULT(Using AIX ACLs)
1243 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1246 + AC_MSG_RESULT(Using Tru64 ACLs)
1247 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1248 + LIBS="$LIBS -lpacl"
1251 + AC_MSG_RESULT(ACLs requested -- running tests)
1252 + AC_CHECK_LIB(acl,acl_get_file)
1253 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1254 + AC_TRY_LINK([#include <sys/types.h>
1255 +#include <sys/acl.h>],
1256 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1257 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1258 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1259 + AC_MSG_RESULT(Using posix ACLs)
1260 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1261 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1262 + AC_TRY_LINK([#include <sys/types.h>
1263 +#include <sys/acl.h>],
1264 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1265 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1266 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1267 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1270 + AC_MSG_ERROR(Failed to find ACL support)
1277 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1280 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1284 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1287 --- orig/flist.c 2005-07-27 23:31:12
1288 +++ flist.c 2005-07-29 02:49:06
1289 @@ -974,6 +974,8 @@ static struct file_struct *send_file_nam
1290 file = make_file(fname, flist, f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1293 + if (MAKE_ACL(file, fname) < 0)
1296 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1298 @@ -982,6 +984,10 @@ static struct file_struct *send_file_nam
1299 if (file->basename[0]) {
1300 flist->files[flist->count++] = file;
1301 send_file_entry(file, f, base_flags);
1302 + SEND_ACL(file, f);
1304 + /* Cleanup unsent ACL(s). */
1305 + SEND_ACL(file, -1);
1309 @@ -1318,6 +1324,8 @@ struct file_list *recv_file_list(int f)
1310 flags |= read_byte(f) << 8;
1311 file = receive_file_entry(flist, flags, f);
1313 + RECEIVE_ACL(file, f);
1315 if (S_ISREG(file->mode))
1316 stats.total_size += file->length;
1318 @@ -1340,6 +1348,8 @@ struct file_list *recv_file_list(int f)
1320 clean_flist(flist, relative_paths, 1);
1322 + SORT_FILE_ACL_INDEX_LISTS();
1325 /* Now send the uid/gid list. This was introduced in
1326 * protocol version 15 */
1327 --- orig/generator.c 2005-07-28 01:46:25
1328 +++ generator.c 2005-05-12 23:34:00
1329 @@ -725,6 +725,10 @@ static void recv_generator(char *fname,
1330 if (set_perms(fname, file, statret ? NULL : &st, 0)
1331 && verbose && code && f_out != -1)
1332 rprintf(code, "%s/\n", safe_fname(fname));
1333 +#ifdef SUPPORT_ACLS
1335 + SET_ACL(fname, file);
1337 if (delete_during && f_out != -1 && !phase && dry_run < 2
1338 && (file->flags & FLAG_DEL_HERE))
1339 delete_in_dir(the_file_list, fname, file);
1340 --- orig/lib/sysacls.c 2005-05-16 23:27:53
1341 +++ lib/sysacls.c 2005-05-16 23:27:53
1344 + Unix SMB/CIFS implementation.
1345 + Samba system utilities for ACL support.
1346 + Copyright (C) Jeremy Allison 2000.
1348 + This program is free software; you can redistribute it and/or modify
1349 + it under the terms of the GNU General Public License as published by
1350 + the Free Software Foundation; either version 2 of the License, or
1351 + (at your option) any later version.
1353 + This program is distributed in the hope that it will be useful,
1354 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1355 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1356 + GNU General Public License for more details.
1358 + You should have received a copy of the GNU General Public License
1359 + along with this program; if not, write to the Free Software
1360 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1364 +#include "sysacls.h" /****** ADDED ******/
1366 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1367 +void SAFE_FREE(void *mem)
1373 +char *uidtoname(uid_t uid)
1375 + static char idbuf[12];
1376 + struct passwd *pw;
1378 + if ((pw = getpwuid(uid)) == NULL) {
1379 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1382 + return pw->pw_name;
1384 +/****** EXTRAS -- END ******/
1387 + This file wraps all differing system ACL interfaces into a consistent
1388 + one based on the POSIX interface. It also returns the correct errors
1389 + for older UNIX systems that don't support ACLs.
1391 + The interfaces that each ACL implementation must support are as follows :
1393 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1394 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1395 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1396 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1397 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1398 + SMB_ACL_T sys_acl_get_fd(int fd)
1399 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1400 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1401 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1402 + SMB_ACL_T sys_acl_init( int count)
1403 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1404 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1405 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1406 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1407 + int sys_acl_valid( SMB_ACL_T theacl )
1408 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1409 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1410 + int sys_acl_delete_def_file(const char *path)
1412 + This next one is not POSIX complient - but we *have* to have it !
1413 + More POSIX braindamage.
1415 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1417 + The generic POSIX free is the following call. We split this into
1418 + several different free functions as we may need to add tag info
1419 + to structures when emulating the POSIX interface.
1421 + int sys_acl_free( void *obj_p)
1423 + The calls we actually use are :
1425 + int sys_acl_free_text(char *text) - free acl_to_text
1426 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1427 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1431 +#if defined(HAVE_POSIX_ACLS)
1433 +/* Identity mapping - easy. */
1435 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1437 + return acl_get_entry( the_acl, entry_id, entry_p);
1440 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1442 + return acl_get_tag_type( entry_d, tag_type_p);
1445 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1447 + return acl_get_permset( entry_d, permset_p);
1450 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1452 + return acl_get_qualifier( entry_d);
1455 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1457 + return acl_get_file( path_p, type);
1460 +SMB_ACL_T sys_acl_get_fd(int fd)
1462 + return acl_get_fd(fd);
1465 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1467 + return acl_clear_perms(permset);
1470 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1472 + return acl_add_perm(permset, perm);
1475 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1477 +#if defined(HAVE_ACL_GET_PERM_NP)
1479 + * Required for TrustedBSD-based ACL implementations where
1480 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1483 + return acl_get_perm_np(permset, perm);
1485 + return acl_get_perm(permset, perm);
1489 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1491 + return acl_to_text( the_acl, plen);
1494 +SMB_ACL_T sys_acl_init( int count)
1496 + return acl_init(count);
1499 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1501 + return acl_create_entry(pacl, pentry);
1504 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1506 + return acl_set_tag_type(entry, tagtype);
1509 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1511 + return acl_set_qualifier(entry, qual);
1514 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1516 + return acl_set_permset(entry, permset);
1519 +int sys_acl_valid( SMB_ACL_T theacl )
1521 + return acl_valid(theacl);
1524 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1526 + return acl_set_file(name, acltype, theacl);
1529 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1531 + return acl_set_fd(fd, theacl);
1534 +int sys_acl_delete_def_file(const char *name)
1536 + return acl_delete_def_file(name);
1539 +int sys_acl_free_text(char *text)
1541 + return acl_free(text);
1544 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1546 + return acl_free(the_acl);
1549 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1551 + return acl_free(qual);
1554 +#elif defined(HAVE_TRU64_ACLS)
1556 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1557 + * is based on Draft 13 of the POSIX spec which is
1558 + * slightly different from the Draft 16 interface.
1560 + * Also, some of the permset manipulation functions
1561 + * such as acl_clear_perm() and acl_add_perm() appear
1562 + * to be broken on Tru64 so we have to manipulate
1563 + * the permission bits in the permset directly.
1565 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1567 + SMB_ACL_ENTRY_T entry;
1569 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1574 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1579 + return errno ? -1 : 0;
1582 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1584 + return acl_get_tag_type( entry_d, tag_type_p);
1587 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1589 + return acl_get_permset( entry_d, permset_p);
1592 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1594 + return acl_get_qualifier( entry_d);
1597 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1599 + return acl_get_file((char *)path_p, type);
1602 +SMB_ACL_T sys_acl_get_fd(int fd)
1604 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1607 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1609 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1614 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1616 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1621 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1626 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1628 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1631 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1633 + return acl_to_text( the_acl, plen);
1636 +SMB_ACL_T sys_acl_init( int count)
1638 + return acl_init(count);
1641 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1643 + SMB_ACL_ENTRY_T entry;
1645 + if ((entry = acl_create_entry(pacl)) == NULL) {
1653 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1655 + return acl_set_tag_type(entry, tagtype);
1658 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1660 + return acl_set_qualifier(entry, qual);
1663 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1665 + return acl_set_permset(entry, permset);
1668 +int sys_acl_valid( SMB_ACL_T theacl )
1670 + acl_entry_t entry;
1672 + return acl_valid(theacl, &entry);
1675 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1677 + return acl_set_file((char *)name, acltype, theacl);
1680 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1682 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1685 +int sys_acl_delete_def_file(const char *name)
1687 + return acl_delete_def_file((char *)name);
1690 +int sys_acl_free_text(char *text)
1693 + * (void) cast and explicit return 0 are for DEC UNIX
1694 + * which just #defines acl_free_text() to be free()
1696 + (void) acl_free_text(text);
1700 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1702 + return acl_free(the_acl);
1705 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1707 + return acl_free_qualifier(qual, tagtype);
1710 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1713 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1714 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1718 + * Note that while this code implements sufficient functionality
1719 + * to support the sys_acl_* interfaces it does not provide all
1720 + * of the semantics of the POSIX ACL interfaces.
1722 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1723 + * from a call to sys_acl_get_entry() should not be assumed to be
1724 + * valid after calling any of the following functions, which may
1725 + * reorder the entries in the ACL.
1728 + * sys_acl_set_file()
1729 + * sys_acl_set_fd()
1733 + * The only difference between Solaris and UnixWare / OpenUNIX is
1734 + * that the #defines for the ACL operations have different names
1736 +#if defined(HAVE_UNIXWARE_ACLS)
1738 +#define SETACL ACL_SET
1739 +#define GETACL ACL_GET
1740 +#define GETACLCNT ACL_CNT
1745 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1747 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1752 + if (entry_p == NULL) {
1757 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1761 + if (acl_d->next < 0) {
1766 + if (acl_d->next >= acl_d->count) {
1770 + *entry_p = &acl_d->acl[acl_d->next++];
1775 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1777 + *type_p = entry_d->a_type;
1782 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1784 + *permset_p = &entry_d->a_perm;
1789 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1791 + if (entry_d->a_type != SMB_ACL_USER
1792 + && entry_d->a_type != SMB_ACL_GROUP) {
1797 + return &entry_d->a_id;
1801 + * There is no way of knowing what size the ACL returned by
1802 + * GETACL will be unless you first call GETACLCNT which means
1803 + * making an additional system call.
1805 + * In the hope of avoiding the cost of the additional system
1806 + * call in most cases, we initially allocate enough space for
1807 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1808 + * be too small then we use GETACLCNT to find out the actual
1809 + * size, reallocate the ACL buffer, and then call GETACL again.
1812 +#define INITIAL_ACL_SIZE 16
1814 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1817 + int count; /* # of ACL entries allocated */
1818 + int naccess; /* # of access ACL entries */
1819 + int ndefault; /* # of default ACL entries */
1821 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1826 + count = INITIAL_ACL_SIZE;
1827 + if ((acl_d = sys_acl_init(count)) == NULL) {
1832 + * If there isn't enough space for the ACL entries we use
1833 + * GETACLCNT to determine the actual number of ACL entries
1834 + * reallocate and try again. This is in a loop because it
1835 + * is possible that someone else could modify the ACL and
1836 + * increase the number of entries between the call to
1837 + * GETACLCNT and the call to GETACL.
1839 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1840 + && errno == ENOSPC) {
1842 + sys_acl_free_acl(acl_d);
1844 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1848 + if ((acl_d = sys_acl_init(count)) == NULL) {
1854 + sys_acl_free_acl(acl_d);
1859 + * calculate the number of access and default ACL entries
1861 + * Note: we assume that the acl() system call returned a
1862 + * well formed ACL which is sorted so that all of the
1863 + * access ACL entries preceed any default ACL entries
1865 + for (naccess = 0; naccess < count; naccess++) {
1866 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1869 + ndefault = count - naccess;
1872 + * if the caller wants the default ACL we have to copy
1873 + * the entries down to the start of the acl[] buffer
1874 + * and mask out the ACL_DEFAULT flag from the type field
1876 + if (type == SMB_ACL_TYPE_DEFAULT) {
1879 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
1880 + acl_d->acl[i] = acl_d->acl[j];
1881 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
1884 + acl_d->count = ndefault;
1886 + acl_d->count = naccess;
1892 +SMB_ACL_T sys_acl_get_fd(int fd)
1895 + int count; /* # of ACL entries allocated */
1896 + int naccess; /* # of access ACL entries */
1898 + count = INITIAL_ACL_SIZE;
1899 + if ((acl_d = sys_acl_init(count)) == NULL) {
1903 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
1904 + && errno == ENOSPC) {
1906 + sys_acl_free_acl(acl_d);
1908 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
1912 + if ((acl_d = sys_acl_init(count)) == NULL) {
1918 + sys_acl_free_acl(acl_d);
1923 + * calculate the number of access ACL entries
1925 + for (naccess = 0; naccess < count; naccess++) {
1926 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1930 + acl_d->count = naccess;
1935 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
1942 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
1944 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
1945 + && perm != SMB_ACL_EXECUTE) {
1950 + if (permset_d == NULL) {
1955 + *permset_d |= perm;
1960 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
1962 + return *permset_d & perm;
1965 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
1972 + * use an initial estimate of 20 bytes per ACL entry
1973 + * when allocating memory for the text representation
1977 + maxlen = 20 * acl_d->count;
1978 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
1983 + for (i = 0; i < acl_d->count; i++) {
1984 + struct acl *ap = &acl_d->acl[i];
1985 + struct passwd *pw;
1994 + switch (ap->a_type) {
1996 + * for debugging purposes it's probably more
1997 + * useful to dump unknown tag types rather
1998 + * than just returning an error
2001 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2004 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2009 + case SMB_ACL_USER:
2010 + id = uidtoname(ap->a_id);
2011 + case SMB_ACL_USER_OBJ:
2015 + case SMB_ACL_GROUP:
2016 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2017 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2023 + case SMB_ACL_GROUP_OBJ:
2027 + case SMB_ACL_OTHER:
2031 + case SMB_ACL_MASK:
2037 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2038 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2039 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2042 + /* <tag> : <qualifier> : rwx \n \0 */
2043 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2046 + * If this entry would overflow the buffer
2047 + * allocate enough additional memory for this
2048 + * entry and an estimate of another 20 bytes
2049 + * for each entry still to be processed
2051 + if ((len + nbytes) > maxlen) {
2052 + char *oldtext = text;
2054 + maxlen += nbytes + 20 * (acl_d->count - i);
2056 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2057 + SAFE_FREE(oldtext);
2063 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2064 + len += nbytes - 1;
2073 +SMB_ACL_T sys_acl_init(int count)
2083 + * note that since the definition of the structure pointed
2084 + * to by the SMB_ACL_T includes the first element of the
2085 + * acl[] array, this actually allocates an ACL with room
2086 + * for (count+1) entries
2088 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2093 + a->size = count + 1;
2101 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2104 + SMB_ACL_ENTRY_T entry_d;
2106 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2111 + if (acl_d->count >= acl_d->size) {
2116 + entry_d = &acl_d->acl[acl_d->count++];
2117 + entry_d->a_type = 0;
2118 + entry_d->a_id = -1;
2119 + entry_d->a_perm = 0;
2120 + *entry_p = entry_d;
2125 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2127 + switch (tag_type) {
2128 + case SMB_ACL_USER:
2129 + case SMB_ACL_USER_OBJ:
2130 + case SMB_ACL_GROUP:
2131 + case SMB_ACL_GROUP_OBJ:
2132 + case SMB_ACL_OTHER:
2133 + case SMB_ACL_MASK:
2134 + entry_d->a_type = tag_type;
2144 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2146 + if (entry_d->a_type != SMB_ACL_GROUP
2147 + && entry_d->a_type != SMB_ACL_USER) {
2152 + entry_d->a_id = *((id_t *)qual_p);
2157 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2159 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2163 + entry_d->a_perm = *permset_d;
2169 + * sort the ACL and check it for validity
2171 + * if it's a minimal ACL with only 4 entries then we
2172 + * need to recalculate the mask permissions to make
2173 + * sure that they are the same as the GROUP_OBJ
2174 + * permissions as required by the UnixWare acl() system call.
2176 + * (note: since POSIX allows minimal ACLs which only contain
2177 + * 3 entries - ie there is no mask entry - we should, in theory,
2178 + * check for this and add a mask entry if necessary - however
2179 + * we "know" that the caller of this interface always specifies
2180 + * a mask so, in practice "this never happens" (tm) - if it *does*
2181 + * happen aclsort() will fail and return an error and someone will
2182 + * have to fix it ...)
2185 +static int acl_sort(SMB_ACL_T acl_d)
2187 + int fixmask = (acl_d->count <= 4);
2189 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2196 +int sys_acl_valid(SMB_ACL_T acl_d)
2198 + return acl_sort(acl_d);
2201 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2204 + struct acl *acl_p;
2206 + struct acl *acl_buf = NULL;
2209 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2214 + if (acl_sort(acl_d) != 0) {
2218 + acl_p = &acl_d->acl[0];
2219 + acl_count = acl_d->count;
2222 + * if it's a directory there is extra work to do
2223 + * since the acl() system call will replace both
2224 + * the access ACLs and the default ACLs (if any)
2226 + if (stat(name, &s) != 0) {
2229 + if (S_ISDIR(s.st_mode)) {
2230 + SMB_ACL_T acc_acl;
2231 + SMB_ACL_T def_acl;
2232 + SMB_ACL_T tmp_acl;
2235 + if (type == SMB_ACL_TYPE_ACCESS) {
2237 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2241 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2244 + if (tmp_acl == NULL) {
2249 + * allocate a temporary buffer for the complete ACL
2251 + acl_count = acc_acl->count + def_acl->count;
2252 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2254 + if (acl_buf == NULL) {
2255 + sys_acl_free_acl(tmp_acl);
2261 + * copy the access control and default entries into the buffer
2263 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2264 + acc_acl->count * sizeof(acl_buf[0]));
2266 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2267 + def_acl->count * sizeof(acl_buf[0]));
2270 + * set the ACL_DEFAULT flag on the default entries
2272 + for (i = acc_acl->count; i < acl_count; i++) {
2273 + acl_buf[i].a_type |= ACL_DEFAULT;
2276 + sys_acl_free_acl(tmp_acl);
2278 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2283 + ret = acl(name, SETACL, acl_count, acl_p);
2285 + SAFE_FREE(acl_buf);
2290 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2292 + if (acl_sort(acl_d) != 0) {
2296 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2299 +int sys_acl_delete_def_file(const char *path)
2305 + * fetching the access ACL and rewriting it has
2306 + * the effect of deleting the default ACL
2308 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2312 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2314 + sys_acl_free_acl(acl_d);
2319 +int sys_acl_free_text(char *text)
2325 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2331 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2336 +#elif defined(HAVE_HPUX_ACLS)
2340 + * Based on the Solaris/SCO code - with modifications.
2344 + * Note that while this code implements sufficient functionality
2345 + * to support the sys_acl_* interfaces it does not provide all
2346 + * of the semantics of the POSIX ACL interfaces.
2348 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2349 + * from a call to sys_acl_get_entry() should not be assumed to be
2350 + * valid after calling any of the following functions, which may
2351 + * reorder the entries in the ACL.
2354 + * sys_acl_set_file()
2355 + * sys_acl_set_fd()
2358 +/* This checks if the POSIX ACL system call is defined */
2359 +/* which basically corresponds to whether JFS 3.3 or */
2360 +/* higher is installed. If acl() was called when it */
2361 +/* isn't defined, it causes the process to core dump */
2362 +/* so it is important to check this and avoid acl() */
2363 +/* calls if it isn't there. */
2365 +static BOOL hpux_acl_call_presence(void)
2368 + shl_t handle = NULL;
2371 + static BOOL already_checked=0;
2373 + if(already_checked)
2377 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2379 + if(ret_val != 0) {
2380 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2381 + ret_val, errno, strerror(errno)));
2382 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2386 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2388 + already_checked = True;
2392 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2394 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2399 + if (entry_p == NULL) {
2404 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2408 + if (acl_d->next < 0) {
2413 + if (acl_d->next >= acl_d->count) {
2417 + *entry_p = &acl_d->acl[acl_d->next++];
2422 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2424 + *type_p = entry_d->a_type;
2429 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2431 + *permset_p = &entry_d->a_perm;
2436 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2438 + if (entry_d->a_type != SMB_ACL_USER
2439 + && entry_d->a_type != SMB_ACL_GROUP) {
2444 + return &entry_d->a_id;
2448 + * There is no way of knowing what size the ACL returned by
2449 + * ACL_GET will be unless you first call ACL_CNT which means
2450 + * making an additional system call.
2452 + * In the hope of avoiding the cost of the additional system
2453 + * call in most cases, we initially allocate enough space for
2454 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2455 + * be too small then we use ACL_CNT to find out the actual
2456 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2459 +#define INITIAL_ACL_SIZE 16
2461 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2464 + int count; /* # of ACL entries allocated */
2465 + int naccess; /* # of access ACL entries */
2466 + int ndefault; /* # of default ACL entries */
2468 + if(hpux_acl_call_presence() == False) {
2469 + /* Looks like we don't have the acl() system call on HPUX.
2470 + * May be the system doesn't have the latest version of JFS.
2475 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2480 + count = INITIAL_ACL_SIZE;
2481 + if ((acl_d = sys_acl_init(count)) == NULL) {
2486 + * If there isn't enough space for the ACL entries we use
2487 + * ACL_CNT to determine the actual number of ACL entries
2488 + * reallocate and try again. This is in a loop because it
2489 + * is possible that someone else could modify the ACL and
2490 + * increase the number of entries between the call to
2491 + * ACL_CNT and the call to ACL_GET.
2493 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2495 + sys_acl_free_acl(acl_d);
2497 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2501 + if ((acl_d = sys_acl_init(count)) == NULL) {
2507 + sys_acl_free_acl(acl_d);
2512 + * calculate the number of access and default ACL entries
2514 + * Note: we assume that the acl() system call returned a
2515 + * well formed ACL which is sorted so that all of the
2516 + * access ACL entries preceed any default ACL entries
2518 + for (naccess = 0; naccess < count; naccess++) {
2519 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2522 + ndefault = count - naccess;
2525 + * if the caller wants the default ACL we have to copy
2526 + * the entries down to the start of the acl[] buffer
2527 + * and mask out the ACL_DEFAULT flag from the type field
2529 + if (type == SMB_ACL_TYPE_DEFAULT) {
2532 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2533 + acl_d->acl[i] = acl_d->acl[j];
2534 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2537 + acl_d->count = ndefault;
2539 + acl_d->count = naccess;
2545 +SMB_ACL_T sys_acl_get_fd(int fd)
2548 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2551 + files_struct *fsp = file_find_fd(fd);
2553 + if (fsp == NULL) {
2559 + * We know we're in the same conn context. So we
2560 + * can use the relative path.
2563 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2566 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2573 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2575 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2576 + && perm != SMB_ACL_EXECUTE) {
2581 + if (permset_d == NULL) {
2586 + *permset_d |= perm;
2591 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2593 + return *permset_d & perm;
2596 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2603 + * use an initial estimate of 20 bytes per ACL entry
2604 + * when allocating memory for the text representation
2608 + maxlen = 20 * acl_d->count;
2609 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2614 + for (i = 0; i < acl_d->count; i++) {
2615 + struct acl *ap = &acl_d->acl[i];
2616 + struct passwd *pw;
2625 + switch (ap->a_type) {
2627 + * for debugging purposes it's probably more
2628 + * useful to dump unknown tag types rather
2629 + * than just returning an error
2632 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2635 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2640 + case SMB_ACL_USER:
2641 + id = uidtoname(ap->a_id);
2642 + case SMB_ACL_USER_OBJ:
2646 + case SMB_ACL_GROUP:
2647 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2648 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2654 + case SMB_ACL_GROUP_OBJ:
2658 + case SMB_ACL_OTHER:
2662 + case SMB_ACL_MASK:
2668 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2669 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2670 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2673 + /* <tag> : <qualifier> : rwx \n \0 */
2674 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2677 + * If this entry would overflow the buffer
2678 + * allocate enough additional memory for this
2679 + * entry and an estimate of another 20 bytes
2680 + * for each entry still to be processed
2682 + if ((len + nbytes) > maxlen) {
2683 + char *oldtext = text;
2685 + maxlen += nbytes + 20 * (acl_d->count - i);
2687 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2694 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2695 + len += nbytes - 1;
2704 +SMB_ACL_T sys_acl_init(int count)
2714 + * note that since the definition of the structure pointed
2715 + * to by the SMB_ACL_T includes the first element of the
2716 + * acl[] array, this actually allocates an ACL with room
2717 + * for (count+1) entries
2719 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2724 + a->size = count + 1;
2732 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2735 + SMB_ACL_ENTRY_T entry_d;
2737 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2742 + if (acl_d->count >= acl_d->size) {
2747 + entry_d = &acl_d->acl[acl_d->count++];
2748 + entry_d->a_type = 0;
2749 + entry_d->a_id = -1;
2750 + entry_d->a_perm = 0;
2751 + *entry_p = entry_d;
2756 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2758 + switch (tag_type) {
2759 + case SMB_ACL_USER:
2760 + case SMB_ACL_USER_OBJ:
2761 + case SMB_ACL_GROUP:
2762 + case SMB_ACL_GROUP_OBJ:
2763 + case SMB_ACL_OTHER:
2764 + case SMB_ACL_MASK:
2765 + entry_d->a_type = tag_type;
2775 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2777 + if (entry_d->a_type != SMB_ACL_GROUP
2778 + && entry_d->a_type != SMB_ACL_USER) {
2783 + entry_d->a_id = *((id_t *)qual_p);
2788 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2790 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2794 + entry_d->a_perm = *permset_d;
2799 +/* Structure to capture the count for each type of ACE. */
2801 +struct hpux_acl_types {
2805 + int n_def_user_obj;
2810 + int n_def_group_obj;
2814 + int n_def_other_obj;
2817 + int n_def_class_obj;
2819 + int n_illegal_obj;
2823 + * Counts the different number of objects in a given array of ACL
2827 + * acl_count - Count of ACLs in the array of ACL strucutres.
2828 + * aclp - Array of ACL structures.
2829 + * acl_type_count - Pointer to acl_types structure. Should already be
2833 + * acl_type_count - This structure is filled up with counts of various
2837 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2841 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2843 + for(i=0;i<acl_count;i++) {
2844 + switch(aclp[i].a_type) {
2846 + acl_type_count->n_user++;
2849 + acl_type_count->n_user_obj++;
2851 + case DEF_USER_OBJ:
2852 + acl_type_count->n_def_user_obj++;
2855 + acl_type_count->n_group++;
2858 + acl_type_count->n_group_obj++;
2860 + case DEF_GROUP_OBJ:
2861 + acl_type_count->n_def_group_obj++;
2864 + acl_type_count->n_other_obj++;
2866 + case DEF_OTHER_OBJ:
2867 + acl_type_count->n_def_other_obj++;
2870 + acl_type_count->n_class_obj++;
2872 + case DEF_CLASS_OBJ:
2873 + acl_type_count->n_def_class_obj++;
2876 + acl_type_count->n_def_user++;
2879 + acl_type_count->n_def_group++;
2882 + acl_type_count->n_illegal_obj++;
2888 +/* swap_acl_entries: Swaps two ACL entries.
2890 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
2893 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
2895 + struct acl temp_acl;
2897 + temp_acl.a_type = aclp0->a_type;
2898 + temp_acl.a_id = aclp0->a_id;
2899 + temp_acl.a_perm = aclp0->a_perm;
2901 + aclp0->a_type = aclp1->a_type;
2902 + aclp0->a_id = aclp1->a_id;
2903 + aclp0->a_perm = aclp1->a_perm;
2905 + aclp1->a_type = temp_acl.a_type;
2906 + aclp1->a_id = temp_acl.a_id;
2907 + aclp1->a_perm = temp_acl.a_perm;
2910 +/* prohibited_duplicate_type
2911 + * Identifies if given ACL type can have duplicate entries or
2914 + * Inputs: acl_type - ACL Type.
2920 + * True - If the ACL type matches any of the prohibited types.
2921 + * False - If the ACL type doesn't match any of the prohibited types.
2924 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
2926 + switch(acl_type) {
2937 +/* get_needed_class_perm
2938 + * Returns the permissions of a ACL structure only if the ACL
2939 + * type matches one of the pre-determined types for computing
2940 + * CLASS_OBJ permissions.
2942 + * Inputs: aclp - Pointer to ACL structure.
2945 +static int hpux_get_needed_class_perm(struct acl *aclp)
2947 + switch(aclp->a_type) {
2951 + case DEF_USER_OBJ:
2953 + case DEF_GROUP_OBJ:
2955 + case DEF_CLASS_OBJ:
2956 + case DEF_OTHER_OBJ:
2957 + return aclp->a_perm;
2963 +/* acl_sort for HPUX.
2964 + * Sorts the array of ACL structures as per the description in
2965 + * aclsort man page. Refer to aclsort man page for more details
2969 + * acl_count - Count of ACLs in the array of ACL structures.
2970 + * calclass - If this is not zero, then we compute the CLASS_OBJ
2972 + * aclp - Array of ACL structures.
2976 + * aclp - Sorted array of ACL structures.
2980 + * Returns 0 for success -1 for failure. Prints a message to the Samba
2981 + * debug log in case of failure.
2984 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
2986 +#if !defined(HAVE_HPUX_ACLSORT)
2988 + * The aclsort() system call is availabe on the latest HPUX General
2989 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
2990 + * function. Because, we don't want to update to a new
2991 + * HPUX GR bundle just for aclsort() call.
2994 + struct hpux_acl_types acl_obj_count;
2995 + int n_class_obj_perm = 0;
2999 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3003 + if(aclp == NULL) {
3004 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3008 + /* Count different types of ACLs in the ACLs array */
3010 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3012 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3013 + * CLASS_OBJ and OTHER_OBJ
3016 + if( (acl_obj_count.n_user_obj != 1) ||
3017 + (acl_obj_count.n_group_obj != 1) ||
3018 + (acl_obj_count.n_class_obj != 1) ||
3019 + (acl_obj_count.n_other_obj != 1)
3021 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3022 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3026 + /* If any of the default objects are present, there should be only
3027 + * one of them each.
3030 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3031 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3032 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3033 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3037 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3040 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3041 + * same ACL type, sort by ACL id.
3043 + * I am using the trival kind of sorting method here because, performance isn't
3044 + * really effected by the ACLs feature. More over there aren't going to be more
3045 + * than 17 entries on HPUX.
3048 + for(i=0; i<acl_count;i++) {
3049 + for (j=i+1; j<acl_count; j++) {
3050 + if( aclp[i].a_type > aclp[j].a_type ) {
3051 + /* ACL entries out of order, swap them */
3053 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3055 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3057 + /* ACL entries of same type, sort by id */
3059 + if(aclp[i].a_id > aclp[j].a_id) {
3060 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3061 + } else if (aclp[i].a_id == aclp[j].a_id) {
3062 + /* We have a duplicate entry. */
3063 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3064 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3065 + aclp[i].a_type, aclp[i].a_id));
3074 + /* set the class obj permissions to the computed one. */
3076 + int n_class_obj_index = -1;
3078 + for(i=0;i<acl_count;i++) {
3079 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3081 + if(aclp[i].a_type == CLASS_OBJ)
3082 + n_class_obj_index = i;
3084 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3089 + return aclsort(acl_count, calclass, aclp);
3094 + * sort the ACL and check it for validity
3096 + * if it's a minimal ACL with only 4 entries then we
3097 + * need to recalculate the mask permissions to make
3098 + * sure that they are the same as the GROUP_OBJ
3099 + * permissions as required by the UnixWare acl() system call.
3101 + * (note: since POSIX allows minimal ACLs which only contain
3102 + * 3 entries - ie there is no mask entry - we should, in theory,
3103 + * check for this and add a mask entry if necessary - however
3104 + * we "know" that the caller of this interface always specifies
3105 + * a mask so, in practice "this never happens" (tm) - if it *does*
3106 + * happen aclsort() will fail and return an error and someone will
3107 + * have to fix it ...)
3110 +static int acl_sort(SMB_ACL_T acl_d)
3112 + int fixmask = (acl_d->count <= 4);
3114 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3121 +int sys_acl_valid(SMB_ACL_T acl_d)
3123 + return acl_sort(acl_d);
3126 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3129 + struct acl *acl_p;
3131 + struct acl *acl_buf = NULL;
3134 + if(hpux_acl_call_presence() == False) {
3135 + /* Looks like we don't have the acl() system call on HPUX.
3136 + * May be the system doesn't have the latest version of JFS.
3142 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3147 + if (acl_sort(acl_d) != 0) {
3151 + acl_p = &acl_d->acl[0];
3152 + acl_count = acl_d->count;
3155 + * if it's a directory there is extra work to do
3156 + * since the acl() system call will replace both
3157 + * the access ACLs and the default ACLs (if any)
3159 + if (stat(name, &s) != 0) {
3162 + if (S_ISDIR(s.st_mode)) {
3163 + SMB_ACL_T acc_acl;
3164 + SMB_ACL_T def_acl;
3165 + SMB_ACL_T tmp_acl;
3168 + if (type == SMB_ACL_TYPE_ACCESS) {
3170 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3174 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3177 + if (tmp_acl == NULL) {
3182 + * allocate a temporary buffer for the complete ACL
3184 + acl_count = acc_acl->count + def_acl->count;
3185 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3187 + if (acl_buf == NULL) {
3188 + sys_acl_free_acl(tmp_acl);
3194 + * copy the access control and default entries into the buffer
3196 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3197 + acc_acl->count * sizeof(acl_buf[0]));
3199 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3200 + def_acl->count * sizeof(acl_buf[0]));
3203 + * set the ACL_DEFAULT flag on the default entries
3205 + for (i = acc_acl->count; i < acl_count; i++) {
3206 + acl_buf[i].a_type |= ACL_DEFAULT;
3209 + sys_acl_free_acl(tmp_acl);
3211 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3216 + ret = acl(name, ACL_SET, acl_count, acl_p);
3225 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3228 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3231 + files_struct *fsp = file_find_fd(fd);
3233 + if (fsp == NULL) {
3238 + if (acl_sort(acl_d) != 0) {
3243 + * We know we're in the same conn context. So we
3244 + * can use the relative path.
3247 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3250 +int sys_acl_delete_def_file(const char *path)
3256 + * fetching the access ACL and rewriting it has
3257 + * the effect of deleting the default ACL
3259 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3263 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3265 + sys_acl_free_acl(acl_d);
3270 +int sys_acl_free_text(char *text)
3276 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3282 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3287 +#elif defined(HAVE_IRIX_ACLS)
3289 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3291 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3296 + if (entry_p == NULL) {
3301 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3305 + if (acl_d->next < 0) {
3310 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3314 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3319 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3321 + *type_p = entry_d->ae_tag;
3326 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3328 + *permset_p = entry_d;
3333 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3335 + if (entry_d->ae_tag != SMB_ACL_USER
3336 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3341 + return &entry_d->ae_id;
3344 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3348 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3352 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3357 + a->freeaclp = True;
3361 +SMB_ACL_T sys_acl_get_fd(int fd)
3365 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3369 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3374 + a->freeaclp = True;
3378 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3380 + permset_d->ae_perm = 0;
3385 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3387 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3388 + && perm != SMB_ACL_EXECUTE) {
3393 + if (permset_d == NULL) {
3398 + permset_d->ae_perm |= perm;
3403 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3405 + return permset_d->ae_perm & perm;
3408 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3410 + return acl_to_text(acl_d->aclp, len_p);
3413 +SMB_ACL_T sys_acl_init(int count)
3422 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3428 + a->freeaclp = False;
3429 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3430 + a->aclp->acl_cnt = 0;
3436 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3439 + SMB_ACL_ENTRY_T entry_d;
3441 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3446 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3451 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3452 + entry_d->ae_tag = 0;
3453 + entry_d->ae_id = 0;
3454 + entry_d->ae_perm = 0;
3455 + *entry_p = entry_d;
3460 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3462 + switch (tag_type) {
3463 + case SMB_ACL_USER:
3464 + case SMB_ACL_USER_OBJ:
3465 + case SMB_ACL_GROUP:
3466 + case SMB_ACL_GROUP_OBJ:
3467 + case SMB_ACL_OTHER:
3468 + case SMB_ACL_MASK:
3469 + entry_d->ae_tag = tag_type;
3479 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3481 + if (entry_d->ae_tag != SMB_ACL_GROUP
3482 + && entry_d->ae_tag != SMB_ACL_USER) {
3487 + entry_d->ae_id = *((id_t *)qual_p);
3492 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3494 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3498 + entry_d->ae_perm = permset_d->ae_perm;
3503 +int sys_acl_valid(SMB_ACL_T acl_d)
3505 + return acl_valid(acl_d->aclp);
3508 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3510 + return acl_set_file(name, type, acl_d->aclp);
3513 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3515 + return acl_set_fd(fd, acl_d->aclp);
3518 +int sys_acl_delete_def_file(const char *name)
3520 + return acl_delete_def_file(name);
3523 +int sys_acl_free_text(char *text)
3525 + return acl_free(text);
3528 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3530 + if (acl_d->freeaclp) {
3531 + acl_free(acl_d->aclp);
3537 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3542 +#elif defined(HAVE_AIX_ACLS)
3544 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3546 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3548 + struct acl_entry_link *link;
3549 + struct new_acl_entry *entry;
3552 + DEBUG(10,("This is the count: %d\n",theacl->count));
3554 + /* Check if count was previously set to -1. *
3555 + * If it was, that means we reached the end *
3556 + * of the acl last time. */
3557 + if(theacl->count == -1)
3561 + /* To get to the next acl, traverse linked list until index *
3562 + * of acl matches the count we are keeping. This count is *
3563 + * incremented each time we return an acl entry. */
3565 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3566 + link = link->nextp;
3568 + entry = *entry_p = link->entryp;
3570 + DEBUG(10,("*entry_p is %d\n",entry_p));
3571 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3573 + /* Increment count */
3575 + if(link->nextp == NULL)
3576 + theacl->count = -1;
3581 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3583 + /* Initialize tag type */
3586 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3588 + /* Depending on what type of entry we have, *
3589 + * return tag type. */
3590 + switch(entry_d->ace_id->id_type) {
3592 + *tag_type_p = SMB_ACL_USER;
3595 + *tag_type_p = SMB_ACL_GROUP;
3598 + case SMB_ACL_USER_OBJ:
3599 + case SMB_ACL_GROUP_OBJ:
3600 + case SMB_ACL_OTHER:
3601 + *tag_type_p = entry_d->ace_id->id_type;
3611 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3613 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3614 + *permset_p = &entry_d->ace_access;
3615 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3616 + if(!(**permset_p & S_IXUSR) &&
3617 + !(**permset_p & S_IWUSR) &&
3618 + !(**permset_p & S_IRUSR) &&
3619 + (**permset_p != 0))
3622 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3626 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3628 + return(entry_d->ace_id->id_data);
3631 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3633 + struct acl *file_acl = (struct acl *)NULL;
3634 + struct acl_entry *acl_entry;
3635 + struct new_acl_entry *new_acl_entry;
3636 + struct ace_id *idp;
3637 + struct acl_entry_link *acl_entry_link;
3638 + struct acl_entry_link *acl_entry_link_head;
3643 + /* AIX has no DEFAULT */
3644 + if ( type == SMB_ACL_TYPE_DEFAULT )
3647 + /* Get the acl using statacl */
3649 + DEBUG(10,("Entering sys_acl_get_file\n"));
3650 + DEBUG(10,("path_p is %s\n",path_p));
3652 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3654 + if(file_acl == NULL) {
3656 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3660 + memset(file_acl,0,BUFSIZ);
3662 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3664 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3665 + SAFE_FREE(file_acl);
3669 + DEBUG(10,("Got facl and returned it\n"));
3671 + /* Point to the first acl entry in the acl */
3672 + acl_entry = file_acl->acl_ext;
3674 + /* Begin setting up the head of the linked list *
3675 + * that will be used for the storing the acl *
3676 + * in a way that is useful for the posix_acls.c *
3679 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3680 + if(acl_entry_link_head == NULL)
3683 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3684 + if(acl_entry_link->entryp == NULL) {
3685 + SAFE_FREE(file_acl);
3687 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3691 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3692 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3694 + /* Check if the extended acl bit is on. *
3695 + * If it isn't, do not show the *
3696 + * contents of the acl since AIX intends *
3697 + * the extended info to remain unused */
3699 + if(file_acl->acl_mode & S_IXACL){
3700 + /* while we are not pointing to the very end */
3701 + while(acl_entry < acl_last(file_acl)) {
3702 + /* before we malloc anything, make sure this is */
3703 + /* a valid acl entry and one that we want to map */
3704 + idp = id_nxt(acl_entry->ace_id);
3705 + if((acl_entry->ace_type == ACC_SPECIFY ||
3706 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3707 + acl_entry = acl_nxt(acl_entry);
3711 + idp = acl_entry->ace_id;
3713 + /* Check if this is the first entry in the linked list. *
3714 + * The first entry needs to keep prevp pointing to NULL *
3715 + * and already has entryp allocated. */
3717 + if(acl_entry_link_head->count != 0) {
3718 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3720 + if(acl_entry_link->nextp == NULL) {
3721 + SAFE_FREE(file_acl);
3723 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3727 + acl_entry_link->nextp->prevp = acl_entry_link;
3728 + acl_entry_link = acl_entry_link->nextp;
3729 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3730 + if(acl_entry_link->entryp == NULL) {
3731 + SAFE_FREE(file_acl);
3733 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3736 + acl_entry_link->nextp = NULL;
3739 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3741 + /* Don't really need this since all types are going *
3742 + * to be specified but, it's better than leaving it 0 */
3744 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3746 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3748 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3750 + /* The access in the acl entries must be left shifted by *
3751 + * three bites, because they will ultimately be compared *
3752 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3754 + switch(acl_entry->ace_type){
3757 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3758 + acl_entry_link->entryp->ace_access <<= 6;
3759 + acl_entry_link_head->count++;
3762 + /* Since there is no way to return a DENY acl entry *
3763 + * change to PERMIT and then shift. */
3764 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3765 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3766 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3767 + acl_entry_link->entryp->ace_access <<= 6;
3768 + acl_entry_link_head->count++;
3774 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3775 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3777 + acl_entry = acl_nxt(acl_entry);
3779 + } /* end of if enabled */
3781 + /* Since owner, group, other acl entries are not *
3782 + * part of the acl entries in an acl, they must *
3783 + * be dummied up to become part of the list. */
3785 + for( i = 1; i < 4; i++) {
3786 + DEBUG(10,("i is %d\n",i));
3787 + if(acl_entry_link_head->count != 0) {
3788 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3789 + if(acl_entry_link->nextp == NULL) {
3790 + SAFE_FREE(file_acl);
3792 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3796 + acl_entry_link->nextp->prevp = acl_entry_link;
3797 + acl_entry_link = acl_entry_link->nextp;
3798 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3799 + if(acl_entry_link->entryp == NULL) {
3800 + SAFE_FREE(file_acl);
3802 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3807 + acl_entry_link->nextp = NULL;
3809 + new_acl_entry = acl_entry_link->entryp;
3810 + idp = new_acl_entry->ace_id;
3812 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3813 + new_acl_entry->ace_type = ACC_PERMIT;
3814 + idp->id_len = sizeof(struct ace_id);
3815 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3816 + memset(idp->id_data,0,sizeof(uid_t));
3820 + new_acl_entry->ace_access = file_acl->g_access << 6;
3821 + idp->id_type = SMB_ACL_GROUP_OBJ;
3825 + new_acl_entry->ace_access = file_acl->o_access << 6;
3826 + idp->id_type = SMB_ACL_OTHER;
3830 + new_acl_entry->ace_access = file_acl->u_access << 6;
3831 + idp->id_type = SMB_ACL_USER_OBJ;
3839 + acl_entry_link_head->count++;
3840 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3843 + acl_entry_link_head->count = 0;
3844 + SAFE_FREE(file_acl);
3846 + return(acl_entry_link_head);
3849 +SMB_ACL_T sys_acl_get_fd(int fd)
3851 + struct acl *file_acl = (struct acl *)NULL;
3852 + struct acl_entry *acl_entry;
3853 + struct new_acl_entry *new_acl_entry;
3854 + struct ace_id *idp;
3855 + struct acl_entry_link *acl_entry_link;
3856 + struct acl_entry_link *acl_entry_link_head;
3861 + /* Get the acl using fstatacl */
3863 + DEBUG(10,("Entering sys_acl_get_fd\n"));
3864 + DEBUG(10,("fd is %d\n",fd));
3865 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3867 + if(file_acl == NULL) {
3869 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3873 + memset(file_acl,0,BUFSIZ);
3875 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
3877 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
3878 + SAFE_FREE(file_acl);
3882 + DEBUG(10,("Got facl and returned it\n"));
3884 + /* Point to the first acl entry in the acl */
3886 + acl_entry = file_acl->acl_ext;
3887 + /* Begin setting up the head of the linked list *
3888 + * that will be used for the storing the acl *
3889 + * in a way that is useful for the posix_acls.c *
3892 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3893 + if(acl_entry_link_head == NULL){
3894 + SAFE_FREE(file_acl);
3898 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3900 + if(acl_entry_link->entryp == NULL) {
3902 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3903 + SAFE_FREE(file_acl);
3907 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3908 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3910 + /* Check if the extended acl bit is on. *
3911 + * If it isn't, do not show the *
3912 + * contents of the acl since AIX intends *
3913 + * the extended info to remain unused */
3915 + if(file_acl->acl_mode & S_IXACL){
3916 + /* while we are not pointing to the very end */
3917 + while(acl_entry < acl_last(file_acl)) {
3918 + /* before we malloc anything, make sure this is */
3919 + /* a valid acl entry and one that we want to map */
3921 + idp = id_nxt(acl_entry->ace_id);
3922 + if((acl_entry->ace_type == ACC_SPECIFY ||
3923 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3924 + acl_entry = acl_nxt(acl_entry);
3928 + idp = acl_entry->ace_id;
3930 + /* Check if this is the first entry in the linked list. *
3931 + * The first entry needs to keep prevp pointing to NULL *
3932 + * and already has entryp allocated. */
3934 + if(acl_entry_link_head->count != 0) {
3935 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3936 + if(acl_entry_link->nextp == NULL) {
3938 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3939 + SAFE_FREE(file_acl);
3942 + acl_entry_link->nextp->prevp = acl_entry_link;
3943 + acl_entry_link = acl_entry_link->nextp;
3944 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3945 + if(acl_entry_link->entryp == NULL) {
3947 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3948 + SAFE_FREE(file_acl);
3952 + acl_entry_link->nextp = NULL;
3955 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3957 + /* Don't really need this since all types are going *
3958 + * to be specified but, it's better than leaving it 0 */
3960 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3961 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3963 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
3965 + /* The access in the acl entries must be left shifted by *
3966 + * three bites, because they will ultimately be compared *
3967 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3969 + switch(acl_entry->ace_type){
3972 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3973 + acl_entry_link->entryp->ace_access <<= 6;
3974 + acl_entry_link_head->count++;
3977 + /* Since there is no way to return a DENY acl entry *
3978 + * change to PERMIT and then shift. */
3979 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3980 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3981 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3982 + acl_entry_link->entryp->ace_access <<= 6;
3983 + acl_entry_link_head->count++;
3989 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3990 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3992 + acl_entry = acl_nxt(acl_entry);
3994 + } /* end of if enabled */
3996 + /* Since owner, group, other acl entries are not *
3997 + * part of the acl entries in an acl, they must *
3998 + * be dummied up to become part of the list. */
4000 + for( i = 1; i < 4; i++) {
4001 + DEBUG(10,("i is %d\n",i));
4002 + if(acl_entry_link_head->count != 0){
4003 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4004 + if(acl_entry_link->nextp == NULL) {
4006 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4007 + SAFE_FREE(file_acl);
4011 + acl_entry_link->nextp->prevp = acl_entry_link;
4012 + acl_entry_link = acl_entry_link->nextp;
4013 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4015 + if(acl_entry_link->entryp == NULL) {
4016 + SAFE_FREE(file_acl);
4018 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4023 + acl_entry_link->nextp = NULL;
4025 + new_acl_entry = acl_entry_link->entryp;
4026 + idp = new_acl_entry->ace_id;
4028 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4029 + new_acl_entry->ace_type = ACC_PERMIT;
4030 + idp->id_len = sizeof(struct ace_id);
4031 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4032 + memset(idp->id_data,0,sizeof(uid_t));
4036 + new_acl_entry->ace_access = file_acl->g_access << 6;
4037 + idp->id_type = SMB_ACL_GROUP_OBJ;
4041 + new_acl_entry->ace_access = file_acl->o_access << 6;
4042 + idp->id_type = SMB_ACL_OTHER;
4046 + new_acl_entry->ace_access = file_acl->u_access << 6;
4047 + idp->id_type = SMB_ACL_USER_OBJ;
4054 + acl_entry_link_head->count++;
4055 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4058 + acl_entry_link_head->count = 0;
4059 + SAFE_FREE(file_acl);
4061 + return(acl_entry_link_head);
4064 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4066 + *permset = *permset & ~0777;
4070 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4073 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4077 + DEBUG(10,("This is the permset now: %d\n",*permset));
4081 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4086 +SMB_ACL_T sys_acl_init( int count)
4088 + struct acl_entry_link *theacl = NULL;
4090 + DEBUG(10,("Entering sys_acl_init\n"));
4092 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4093 + if(theacl == NULL) {
4095 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4099 + theacl->count = 0;
4100 + theacl->nextp = NULL;
4101 + theacl->prevp = NULL;
4102 + theacl->entryp = NULL;
4103 + DEBUG(10,("Exiting sys_acl_init\n"));
4107 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4109 + struct acl_entry_link *theacl;
4110 + struct acl_entry_link *acl_entryp;
4111 + struct acl_entry_link *temp_entry;
4114 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4116 + theacl = acl_entryp = *pacl;
4118 + /* Get to the end of the acl before adding entry */
4120 + for(counting=0; counting < theacl->count; counting++){
4121 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4122 + temp_entry = acl_entryp;
4123 + acl_entryp = acl_entryp->nextp;
4126 + if(theacl->count != 0){
4127 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4128 + if(acl_entryp == NULL) {
4130 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4134 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4135 + acl_entryp->prevp = temp_entry;
4136 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4139 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4140 + if(*pentry == NULL) {
4142 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4146 + memset(*pentry,0,sizeof(struct new_acl_entry));
4147 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4148 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4149 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4150 + acl_entryp->nextp = NULL;
4152 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4156 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4158 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4159 + entry->ace_id->id_type = tagtype;
4160 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4161 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4164 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4166 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4167 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4168 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4172 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4174 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4175 + if(!(*permset & S_IXUSR) &&
4176 + !(*permset & S_IWUSR) &&
4177 + !(*permset & S_IRUSR) &&
4181 + entry->ace_access = *permset;
4182 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4183 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4187 +int sys_acl_valid( SMB_ACL_T theacl )
4190 + int group_obj = 0;
4191 + int other_obj = 0;
4192 + struct acl_entry_link *acl_entry;
4194 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4195 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4196 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4197 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4200 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4202 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4208 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4210 + struct acl_entry_link *acl_entry_link = NULL;
4211 + struct acl *file_acl = NULL;
4212 + struct acl *file_acl_temp = NULL;
4213 + struct acl_entry *acl_entry = NULL;
4214 + struct ace_id *ace_id = NULL;
4221 + DEBUG(10,("Entering sys_acl_set_file\n"));
4222 + DEBUG(10,("File name is %s\n",name));
4224 + /* AIX has no default ACL */
4225 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4228 + acl_length = BUFSIZ;
4229 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4231 + if(file_acl == NULL) {
4233 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4237 + memset(file_acl,0,BUFSIZ);
4239 + file_acl->acl_len = ACL_SIZ;
4240 + file_acl->acl_mode = S_IXACL;
4242 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4243 + acl_entry_link->entryp->ace_access >>= 6;
4244 + id_type = acl_entry_link->entryp->ace_id->id_type;
4247 + case SMB_ACL_USER_OBJ:
4248 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4250 + case SMB_ACL_GROUP_OBJ:
4251 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4253 + case SMB_ACL_OTHER:
4254 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4256 + case SMB_ACL_MASK:
4260 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4261 + acl_length += sizeof(struct acl_entry);
4262 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4263 + if(file_acl_temp == NULL) {
4264 + SAFE_FREE(file_acl);
4266 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4270 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4271 + SAFE_FREE(file_acl);
4272 + file_acl = file_acl_temp;
4275 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4276 + file_acl->acl_len += sizeof(struct acl_entry);
4277 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4278 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4280 + /* In order to use this, we'll need to wait until we can get denies */
4281 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4282 + acl_entry->ace_type = ACC_SPECIFY; */
4284 + acl_entry->ace_type = ACC_SPECIFY;
4286 + ace_id = acl_entry->ace_id;
4288 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4289 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4290 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4291 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4292 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4295 + rc = chacl(name,file_acl,file_acl->acl_len);
4296 + DEBUG(10,("errno is %d\n",errno));
4297 + DEBUG(10,("return code is %d\n",rc));
4298 + SAFE_FREE(file_acl);
4299 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4303 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4305 + struct acl_entry_link *acl_entry_link = NULL;
4306 + struct acl *file_acl = NULL;
4307 + struct acl *file_acl_temp = NULL;
4308 + struct acl_entry *acl_entry = NULL;
4309 + struct ace_id *ace_id = NULL;
4315 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4316 + acl_length = BUFSIZ;
4317 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4319 + if(file_acl == NULL) {
4321 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4325 + memset(file_acl,0,BUFSIZ);
4327 + file_acl->acl_len = ACL_SIZ;
4328 + file_acl->acl_mode = S_IXACL;
4330 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4331 + acl_entry_link->entryp->ace_access >>= 6;
4332 + id_type = acl_entry_link->entryp->ace_id->id_type;
4333 + DEBUG(10,("The id_type is %d\n",id_type));
4336 + case SMB_ACL_USER_OBJ:
4337 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4339 + case SMB_ACL_GROUP_OBJ:
4340 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4342 + case SMB_ACL_OTHER:
4343 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4345 + case SMB_ACL_MASK:
4349 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4350 + acl_length += sizeof(struct acl_entry);
4351 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4352 + if(file_acl_temp == NULL) {
4353 + SAFE_FREE(file_acl);
4355 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4359 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4360 + SAFE_FREE(file_acl);
4361 + file_acl = file_acl_temp;
4364 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4365 + file_acl->acl_len += sizeof(struct acl_entry);
4366 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4367 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4369 + /* In order to use this, we'll need to wait until we can get denies */
4370 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4371 + acl_entry->ace_type = ACC_SPECIFY; */
4373 + acl_entry->ace_type = ACC_SPECIFY;
4375 + ace_id = acl_entry->ace_id;
4377 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4378 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4379 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4380 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4381 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4384 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4385 + DEBUG(10,("errno is %d\n",errno));
4386 + DEBUG(10,("return code is %d\n",rc));
4387 + SAFE_FREE(file_acl);
4388 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4392 +int sys_acl_delete_def_file(const char *name)
4394 + /* AIX has no default ACL */
4398 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4400 + return(*permset & perm);
4403 +int sys_acl_free_text(char *text)
4408 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4410 + struct acl_entry_link *acl_entry_link;
4412 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4413 + SAFE_FREE(acl_entry_link->prevp->entryp);
4414 + SAFE_FREE(acl_entry_link->prevp);
4417 + SAFE_FREE(acl_entry_link->prevp->entryp);
4418 + SAFE_FREE(acl_entry_link->prevp);
4419 + SAFE_FREE(acl_entry_link->entryp);
4420 + SAFE_FREE(acl_entry_link);
4425 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4430 +#else /* No ACLs. */
4432 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4438 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4444 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4450 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4456 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4459 + return (SMB_ACL_T)NULL;
4462 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4465 + return (SMB_ACL_T)NULL;
4468 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4474 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4480 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4483 + return (permset & perm) ? 1 : 0;
4486 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4492 +int sys_acl_free_text(UNUSED(char *text))
4498 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4504 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4510 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4516 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4522 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4528 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4534 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4540 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4546 +int sys_acl_delete_def_file(UNUSED(const char *name))
4552 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4558 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4564 +#endif /* No ACLs. */
4566 +/************************************************************************
4567 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4569 +************************************************************************/
4571 +int no_acl_syscall_error(int err)
4573 +#if defined(ENOSYS)
4574 + if (err == ENOSYS) {
4578 +#if defined(ENOTSUP)
4579 + if (err == ENOTSUP) {
4585 --- orig/lib/sysacls.h 2005-05-16 23:25:51
4586 +++ lib/sysacls.h 2005-05-16 23:25:51
4588 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4589 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4590 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4591 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4592 +#define slprintf snprintf
4594 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4595 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4596 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4597 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4598 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4599 +SMB_ACL_T sys_acl_get_fd(int fd);
4600 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4601 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4602 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4603 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4604 +SMB_ACL_T sys_acl_init(int count);
4605 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4606 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4607 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4608 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4609 +int sys_acl_valid(SMB_ACL_T theacl);
4610 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4611 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4612 +int sys_acl_delete_def_file(const char *name);
4613 +int sys_acl_free_text(char *text);
4614 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4615 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4616 --- orig/mkproto.awk 2005-02-18 20:16:59
4617 +++ mkproto.awk 2005-02-18 20:18:17
4618 @@ -58,7 +58,7 @@ BEGIN {
4622 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const/ {
4623 +!/^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/ {
4627 --- orig/options.c 2005-07-28 01:46:25
4628 +++ options.c 2005-05-12 23:34:38
4629 @@ -44,6 +44,7 @@ int keep_dirlinks = 0;
4631 int preserve_links = 0;
4632 int preserve_hard_links = 0;
4633 +int preserve_acls = 0;
4634 int preserve_perms = 0;
4635 int preserve_devices = 0;
4636 int preserve_uid = 0;
4637 @@ -182,6 +183,7 @@ static void print_rsync_version(enum log
4638 char const *got_socketpair = "no ";
4639 char const *have_inplace = "no ";
4640 char const *hardlinks = "no ";
4641 + char const *acls = "no ";
4642 char const *links = "no ";
4643 char const *ipv6 = "no ";
4644 STRUCT_STAT *dumstat;
4645 @@ -198,6 +200,10 @@ static void print_rsync_version(enum log
4649 +#ifdef SUPPORT_ACLS
4653 #ifdef SUPPORT_LINKS
4656 @@ -212,9 +218,9 @@ static void print_rsync_version(enum log
4657 "Copyright (C) 1996-2005 by Andrew Tridgell and others\n");
4658 rprintf(f, "<http://rsync.samba.org/>\n");
4659 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4660 - "%shard links, %ssymlinks, batchfiles, \n",
4661 + "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
4662 (int) (sizeof (OFF_T) * 8),
4663 - got_socketpair, hardlinks, links);
4664 + got_socketpair, hardlinks, acls, links);
4666 /* Note that this field may not have type ino_t. It depends
4667 * on the complicated interaction between largefile feature
4668 @@ -285,6 +291,7 @@ void usage(enum logcode F)
4669 rprintf(F," -H, --hard-links preserve hard links\n");
4670 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
4671 rprintf(F," -p, --perms preserve permissions\n");
4672 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4673 rprintf(F," -o, --owner preserve owner (root only)\n");
4674 rprintf(F," -g, --group preserve group\n");
4675 rprintf(F," -D, --devices preserve devices (root only)\n");
4676 @@ -412,6 +419,7 @@ static struct poptOption long_options[]
4677 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
4678 {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
4679 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
4680 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4681 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
4682 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
4683 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
4684 @@ -882,6 +890,24 @@ int parse_arguments(int *argc, const cha
4685 basis_dir[basis_dir_cnt++] = (char *)arg;
4689 +#ifdef SUPPORT_ACLS
4690 + preserve_acls = 1;
4691 + preserve_perms = 1;
4693 + /* FIXME: this should probably be ignored with a
4694 + * warning and then countermeasures taken to
4695 + * restrict group and other access in the presence
4696 + * of any more restrictive ACLs, but this is safe
4698 + snprintf(err_buf,sizeof(err_buf),
4699 + "ACLs are not supported on this %s\n",
4700 + am_server ? "server" : "client");
4702 +#endif /* SUPPORT_ACLS */
4707 /* A large opt value means that set_refuse_options()
4708 * turned this option off. */
4709 @@ -1305,6 +1331,8 @@ void server_options(char **args,int *arg
4711 if (preserve_hard_links)
4713 + if (preserve_acls)
4714 + argstr[x++] = 'A';
4718 --- orig/rsync.c 2005-07-27 23:31:12
4719 +++ rsync.c 2004-07-03 20:11:58
4720 @@ -139,6 +139,14 @@ int set_perms(char *fname,struct file_st
4724 + /* If this is a directory, SET_ACL() will be called on the cleanup
4725 + * receive_generator() pass (if we called it here, we might clobber
4726 + * writability on the directory). Everything else is OK to do now. */
4727 + if (!S_ISDIR(st->st_mode)) {
4728 + if (SET_ACL(fname, file) == 0)
4732 if (verbose > 1 && flags & PERMS_REPORT) {
4733 enum logcode code = daemon_log_format_has_i || dry_run
4735 --- orig/rsync.h 2005-05-03 17:11:01
4736 +++ rsync.h 2005-07-29 02:25:55
4737 @@ -638,6 +638,44 @@ struct stats {
4738 #include "lib/permstring.h"
4739 #include "lib/addrinfo.h"
4741 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4742 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4743 +#define SUPPORT_ACLS 1
4746 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4747 +#define ACLS_NEED_MASK 1
4750 +#ifdef SUPPORT_ACLS
4751 +#ifdef HAVE_SYS_ACL_H
4752 +#include <sys/acl.h>
4754 +#define MAKE_ACL(file, fname) make_acl(file, fname)
4755 +#define SEND_ACL(file, f) send_acl(file, f)
4756 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
4757 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4758 +#define SET_ACL(fname, file) set_acl(fname, file)
4759 +#define NEXT_ACL_UID() next_acl_uid()
4760 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
4761 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4762 + push_keep_backup_acl(file, orig, dest)
4763 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4764 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4765 +#else /* SUPPORT_ACLS */
4766 +#define MAKE_ACL(file, fname) 1 /* checked return value */
4767 +#define SEND_ACL(file, f)
4768 +#define RECEIVE_ACL(file, f)
4769 +#define SORT_FILE_ACL_INDEX_LISTS()
4770 +#define SET_ACL(fname, file) 1 /* checked return value */
4771 +#define NEXT_ACL_UID()
4772 +#define ACL_UID_MAP(uid)
4773 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4774 +#define CLEANUP_KEEP_BACKUP_ACL()
4775 +#define DUP_ACL(src, orig, mode) 1 /* checked return value */
4776 +#endif /* SUPPORT_ACLS */
4777 +#include "smb_acls.h"
4781 /* We have replacement versions of these if they're missing. */
4782 --- orig/rsync.yo 2005-07-29 02:47:20
4783 +++ rsync.yo 2004-07-03 20:11:58
4784 @@ -316,6 +316,7 @@ to the detailed description below for a
4785 -H, --hard-links preserve hard links
4786 -K, --keep-dirlinks treat symlinked dir on receiver as dir
4787 -p, --perms preserve permissions
4788 + -A, --acls preserve ACLs (implies -p) [local option]
4789 -o, --owner preserve owner (root only)
4790 -g, --group preserve group
4791 -D, --devices preserve devices (root only)
4792 @@ -636,6 +637,11 @@ based on the source file's permissions,
4794 (which is the same behavior as other file-copy utilities, such as cp).
4796 +dit(bf(-A, --acls)) This option causes rsync to update the remote
4797 +ACLs to be the same as the local ACLs. This will work only if the
4798 +remote machine's rsync supports this option also. This is a non-standard
4801 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
4802 destination file to be the same as the source file. On most systems,
4803 only the super-user can set file ownership. By default, the preservation
4804 --- orig/smb_acls.h 2004-06-30 00:04:07
4805 +++ smb_acls.h 2004-06-30 00:04:07
4808 + Unix SMB/Netbios implementation.
4810 + Portable SMB ACL interface
4811 + Copyright (C) Jeremy Allison 2000
4813 + This program is free software; you can redistribute it and/or modify
4814 + it under the terms of the GNU General Public License as published by
4815 + the Free Software Foundation; either version 2 of the License, or
4816 + (at your option) any later version.
4818 + This program is distributed in the hope that it will be useful,
4819 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4820 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4821 + GNU General Public License for more details.
4823 + You should have received a copy of the GNU General Public License
4824 + along with this program; if not, write to the Free Software
4825 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4828 +#ifndef _SMB_ACLS_H
4829 +#define _SMB_ACLS_H
4831 +#if defined(HAVE_POSIX_ACLS)
4833 +/* This is an identity mapping (just remove the SMB_). */
4835 +#define SMB_ACL_TAG_T acl_tag_t
4836 +#define SMB_ACL_TYPE_T acl_type_t
4837 +#define SMB_ACL_PERMSET_T acl_permset_t
4838 +#define SMB_ACL_PERM_T acl_perm_t
4839 +#define SMB_ACL_READ ACL_READ
4840 +#define SMB_ACL_WRITE ACL_WRITE
4841 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4843 +/* Types of ACLs. */
4844 +#define SMB_ACL_USER ACL_USER
4845 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4846 +#define SMB_ACL_GROUP ACL_GROUP
4847 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4848 +#define SMB_ACL_OTHER ACL_OTHER
4849 +#define SMB_ACL_MASK ACL_MASK
4851 +#define SMB_ACL_T acl_t
4853 +#define SMB_ACL_ENTRY_T acl_entry_t
4855 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
4856 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
4858 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4859 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4861 +#elif defined(HAVE_TRU64_ACLS)
4863 +/* This is for DEC/Compaq Tru64 UNIX */
4865 +#define SMB_ACL_TAG_T acl_tag_t
4866 +#define SMB_ACL_TYPE_T acl_type_t
4867 +#define SMB_ACL_PERMSET_T acl_permset_t
4868 +#define SMB_ACL_PERM_T acl_perm_t
4869 +#define SMB_ACL_READ ACL_READ
4870 +#define SMB_ACL_WRITE ACL_WRITE
4871 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4873 +/* Types of ACLs. */
4874 +#define SMB_ACL_USER ACL_USER
4875 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4876 +#define SMB_ACL_GROUP ACL_GROUP
4877 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4878 +#define SMB_ACL_OTHER ACL_OTHER
4879 +#define SMB_ACL_MASK ACL_MASK
4881 +#define SMB_ACL_T acl_t
4883 +#define SMB_ACL_ENTRY_T acl_entry_t
4885 +#define SMB_ACL_FIRST_ENTRY 0
4886 +#define SMB_ACL_NEXT_ENTRY 1
4888 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4889 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4891 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
4893 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
4894 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
4897 +/* SVR4.2 ES/MP ACLs */
4898 +typedef int SMB_ACL_TAG_T;
4899 +typedef int SMB_ACL_TYPE_T;
4900 +typedef ushort *SMB_ACL_PERMSET_T;
4901 +typedef ushort SMB_ACL_PERM_T;
4902 +#define SMB_ACL_READ 4
4903 +#define SMB_ACL_WRITE 2
4904 +#define SMB_ACL_EXECUTE 1
4906 +/* Types of ACLs. */
4907 +#define SMB_ACL_USER USER
4908 +#define SMB_ACL_USER_OBJ USER_OBJ
4909 +#define SMB_ACL_GROUP GROUP
4910 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
4911 +#define SMB_ACL_OTHER OTHER_OBJ
4912 +#define SMB_ACL_MASK CLASS_OBJ
4914 +typedef struct SMB_ACL_T {
4918 + struct acl acl[1];
4921 +typedef struct acl *SMB_ACL_ENTRY_T;
4923 +#define SMB_ACL_FIRST_ENTRY 0
4924 +#define SMB_ACL_NEXT_ENTRY 1
4926 +#define SMB_ACL_TYPE_ACCESS 0
4927 +#define SMB_ACL_TYPE_DEFAULT 1
4929 +#elif defined(HAVE_HPUX_ACLS)
4932 + * Based on the Solaris & UnixWare code.
4936 +#include <sys/aclv.h>
4938 +/* SVR4.2 ES/MP ACLs */
4939 +typedef int SMB_ACL_TAG_T;
4940 +typedef int SMB_ACL_TYPE_T;
4941 +typedef ushort *SMB_ACL_PERMSET_T;
4942 +typedef ushort SMB_ACL_PERM_T;
4943 +#define SMB_ACL_READ 4
4944 +#define SMB_ACL_WRITE 2
4945 +#define SMB_ACL_EXECUTE 1
4947 +/* Types of ACLs. */
4948 +#define SMB_ACL_USER USER
4949 +#define SMB_ACL_USER_OBJ USER_OBJ
4950 +#define SMB_ACL_GROUP GROUP
4951 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
4952 +#define SMB_ACL_OTHER OTHER_OBJ
4953 +#define SMB_ACL_MASK CLASS_OBJ
4955 +typedef struct SMB_ACL_T {
4959 + struct acl acl[1];
4962 +typedef struct acl *SMB_ACL_ENTRY_T;
4964 +#define SMB_ACL_FIRST_ENTRY 0
4965 +#define SMB_ACL_NEXT_ENTRY 1
4967 +#define SMB_ACL_TYPE_ACCESS 0
4968 +#define SMB_ACL_TYPE_DEFAULT 1
4970 +#elif defined(HAVE_IRIX_ACLS)
4972 +#define SMB_ACL_TAG_T acl_tag_t
4973 +#define SMB_ACL_TYPE_T acl_type_t
4974 +#define SMB_ACL_PERMSET_T acl_permset_t
4975 +#define SMB_ACL_PERM_T acl_perm_t
4976 +#define SMB_ACL_READ ACL_READ
4977 +#define SMB_ACL_WRITE ACL_WRITE
4978 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4980 +/* Types of ACLs. */
4981 +#define SMB_ACL_USER ACL_USER
4982 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4983 +#define SMB_ACL_GROUP ACL_GROUP
4984 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4985 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
4986 +#define SMB_ACL_MASK ACL_MASK
4988 +typedef struct SMB_ACL_T {
4994 +#define SMB_ACL_ENTRY_T acl_entry_t
4996 +#define SMB_ACL_FIRST_ENTRY 0
4997 +#define SMB_ACL_NEXT_ENTRY 1
4999 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5000 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5002 +#elif defined(HAVE_AIX_ACLS)
5004 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5006 +#include "/usr/include/acl.h"
5008 +typedef uint *SMB_ACL_PERMSET_T;
5010 +struct acl_entry_link{
5011 + struct acl_entry_link *prevp;
5012 + struct new_acl_entry *entryp;
5013 + struct acl_entry_link *nextp;
5017 +struct new_acl_entry{
5018 + unsigned short ace_len;
5019 + unsigned short ace_type;
5020 + unsigned int ace_access;
5021 + struct ace_id ace_id[1];
5024 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5025 +#define SMB_ACL_T struct acl_entry_link*
5027 +#define SMB_ACL_TAG_T unsigned short
5028 +#define SMB_ACL_TYPE_T int
5029 +#define SMB_ACL_PERM_T uint
5030 +#define SMB_ACL_READ S_IRUSR
5031 +#define SMB_ACL_WRITE S_IWUSR
5032 +#define SMB_ACL_EXECUTE S_IXUSR
5034 +/* Types of ACLs. */
5035 +#define SMB_ACL_USER ACEID_USER
5036 +#define SMB_ACL_USER_OBJ 3
5037 +#define SMB_ACL_GROUP ACEID_GROUP
5038 +#define SMB_ACL_GROUP_OBJ 4
5039 +#define SMB_ACL_OTHER 5
5040 +#define SMB_ACL_MASK 6
5043 +#define SMB_ACL_FIRST_ENTRY 1
5044 +#define SMB_ACL_NEXT_ENTRY 2
5046 +#define SMB_ACL_TYPE_ACCESS 0
5047 +#define SMB_ACL_TYPE_DEFAULT 1
5049 +#else /* No ACLs. */
5051 +/* No ACLS - fake it. */
5052 +#define SMB_ACL_TAG_T int
5053 +#define SMB_ACL_TYPE_T int
5054 +#define SMB_ACL_PERMSET_T mode_t
5055 +#define SMB_ACL_PERM_T mode_t
5056 +#define SMB_ACL_READ S_IRUSR
5057 +#define SMB_ACL_WRITE S_IWUSR
5058 +#define SMB_ACL_EXECUTE S_IXUSR
5060 +/* Types of ACLs. */
5061 +#define SMB_ACL_USER 0
5062 +#define SMB_ACL_USER_OBJ 1
5063 +#define SMB_ACL_GROUP 2
5064 +#define SMB_ACL_GROUP_OBJ 3
5065 +#define SMB_ACL_OTHER 4
5066 +#define SMB_ACL_MASK 5
5068 +typedef struct SMB_ACL_T {
5072 +typedef struct SMB_ACL_ENTRY_T {
5074 +} *SMB_ACL_ENTRY_T;
5076 +#define SMB_ACL_FIRST_ENTRY 0
5077 +#define SMB_ACL_NEXT_ENTRY 1
5079 +#define SMB_ACL_TYPE_ACCESS 0
5080 +#define SMB_ACL_TYPE_DEFAULT 1
5082 +#endif /* No ACLs. */
5083 +#endif /* _SMB_ACLS_H */
5084 --- orig/uidlist.c 2005-02-14 00:53:44
5085 +++ uidlist.c 2004-07-03 20:11:58
5088 extern int preserve_uid;
5089 extern int preserve_gid;
5090 +extern int preserve_acls;
5091 extern int numeric_ids;
5094 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5098 - if (preserve_uid) {
5099 + if (preserve_uid || preserve_acls) {
5101 /* we send sequences of uid/byte-length/name */
5102 for (list = uidlist; list; list = list->next) {
5103 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5107 - if (preserve_gid) {
5108 + if (preserve_gid || preserve_acls) {
5110 for (list = gidlist; list; list = list->next) {
5112 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5116 - if (preserve_uid && !numeric_ids) {
5117 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5118 /* read the uid list */
5119 while ((id = read_int(f)) != 0) {
5120 int len = read_byte(f);
5121 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
5125 - if (preserve_gid && !numeric_ids) {
5126 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5127 /* read the gid list */
5128 while ((id = read_int(f)) != 0) {
5129 int len = read_byte(f);
5130 @@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li
5134 +#ifdef SUPPORT_ACLS
5135 + if (preserve_acls && !numeric_ids) {
5137 + /* The enumerations don't return 0 except to flag the last
5138 + * entry, since uidlist doesn't munge 0 anyway. */
5139 + while ((id = next_acl_uid(flist)) != 0)
5140 + acl_uid_map(match_uid(id));
5141 + while ((id = next_acl_gid(flist)) != 0)
5142 + acl_gid_map(match_gid(id));
5144 +#endif /* SUPPORT_ACLS */
5146 /* now convert the uid/gid of all files in the list to the mapped
5148 if (am_root && preserve_uid && !numeric_ids) {