1 After applying this patch, run these commands for a successful build:
5 ./configure --with-acl-support
9 The program currently complains when the --acls (-A) option is used to copy
10 from a disk that doesn't support ACLs. This should be changed to silently
11 notice that no ACLs are available to copy. Of course, trying to write out
12 ACLs to a non-ACL-supporting disk should complain.
14 --- orig/Makefile.in 2004-11-03 11:56:03
15 +++ Makefile.in 2004-10-20 06:32:26
16 @@ -25,16 +25,16 @@ VERSION=@VERSION@
20 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
21 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
22 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
23 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
24 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
25 ZLIBOBJ=zlib/deflate.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o \
26 zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
27 zlib/zutil.o zlib/adler32.o
28 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
29 main.o checksum.o match.o syscall.o log.o backup.o
30 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
31 - fileio.o batch.o clientname.o
32 + fileio.o batch.o clientname.o acls.o
33 OBJS3=progress.o pipe.o
34 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
35 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
36 --- orig/acls.c 2004-10-20 06:36:04
37 +++ acls.c 2004-10-20 06:36:04
39 +/* -*- c-file-style: "linux" -*-
40 + Copyright (C) Andrew Tridgell 1996
41 + Copyright (C) Paul Mackerras 1996
43 + This program is free software; you can redistribute it and/or modify
44 + it under the terms of the GNU General Public License as published by
45 + the Free Software Foundation; either version 2 of the License, or
46 + (at your option) any later version.
48 + This program is distributed in the hope that it will be useful,
49 + but WITHOUT ANY WARRANTY; without even the implied warranty of
50 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 + GNU General Public License for more details.
53 + You should have received a copy of the GNU General Public License
54 + along with this program; if not, write to the Free Software
55 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
58 +/* handle passing ACLs between systems */
61 +#include "lib/sysacls.h"
65 +extern int preserve_acls;
72 + SMB_ACL_TAG_T tag_type;
81 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
83 +static void expand_rsync_acl(rsync_acl *racl)
85 + /* first time through, 0 <= 0, so list is expanded:
86 + * diabolical, rsync guys! */
87 + if (racl->malloced <= racl->count) {
89 + size_t new_size = racl->malloced + 10;
90 + new_ptr = realloc_array(racl->races, rsync_ace, new_size);
92 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
93 + (double) new_size * sizeof racl->races[0],
94 + racl->races ? "" : " not");
97 + racl->races = new_ptr;
98 + racl->malloced = new_size;
101 + out_of_memory("expand_rsync_acl");
105 +static void rsync_acl_free(rsync_acl *racl)
108 + racl->races = NULL;
110 + racl->malloced = 0;
113 +static int rsync_ace_sorter(const void *r1, const void *r2)
115 + rsync_ace *race1 = (rsync_ace *)r1;
116 + SMB_ACL_TAG_T rtag1 = race1->tag_type;
117 + id_t rid1 = race1->id;
118 + rsync_ace *race2 = (rsync_ace *)r2;
119 + SMB_ACL_TAG_T rtag2 = race2->tag_type;
120 + id_t rid2 = race2->id;
121 + /* start at the extrema */
122 + if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
124 + if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
127 + if (rtag1 == SMB_ACL_OTHER)
129 + if (rtag2 == SMB_ACL_OTHER)
131 + /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
132 + if (rtag1 == SMB_ACL_USER) {
134 + case SMB_ACL_GROUP:
135 + case SMB_ACL_GROUP_OBJ:
136 + case SMB_ACL_OTHER:
140 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
142 + if (rtag2 == SMB_ACL_USER)
144 + /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
145 + if (rtag1 == SMB_ACL_GROUP_OBJ)
147 + if (rtag2 == SMB_ACL_GROUP_OBJ)
149 + /* only SMB_ACL_GROUPs left */
150 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
153 +static void sort_rsync_acl(rsync_acl *racl)
157 + qsort((void **)racl->races, racl->count, sizeof racl->races[0],
158 + &rsync_ace_sorter);
161 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
163 + SMB_ACL_ENTRY_T entry;
165 + const char *errfun;
166 + *racl = rsync_acl_initializer;
167 + errfun = "sys_acl_get_entry";
168 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
170 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
171 + SMB_ACL_PERMSET_T permset;
174 + expand_rsync_acl(racl);
175 + race = &racl->races[racl->count++];
176 + if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
177 + errfun = "sys_acl_get_tag_type";
180 + if ((rc = sys_acl_get_permset(entry, &permset))) {
181 + errfun = "sys_acl_get_tag_type";
184 + race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
185 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
186 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
187 + switch (race->tag_type) {
189 + case SMB_ACL_GROUP:
194 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
195 + errfun = "sys_acl_get_tag_type";
199 + race->id = *((id_t *)qualifier);
200 + sys_acl_free_qualifier(qualifier, race->tag_type);
203 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
204 + errfun, strerror(errno));
205 + rsync_acl_free(racl);
208 + sort_rsync_acl(racl);
212 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
214 + rsync_ace *race1, *race2;
215 + size_t count = racl1->count;
216 + if (count != racl2->count)
218 + race1 = racl1->races;
219 + race2 = racl2->races;
220 + for (; count--; race1++, race2++) {
221 + if (race1->tag_type != race2->tag_type
222 + || race1->access != race2->access
223 + || ((race1->tag_type == SMB_ACL_USER
224 + || race1->tag_type == SMB_ACL_GROUP)
225 + && race1->id != race2->id))
237 +static rsync_acl_list _rsync_acl_lists[] = {
238 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
239 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
242 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
244 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
245 + : &_rsync_acl_lists[1];
248 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
250 + /* first time through, 0 <= 0, so list is expanded:
251 + * diabolical, rsync guys! */
252 + if (racl_list->malloced <= racl_list->count) {
253 + rsync_acl *new_ptr;
255 + if (racl_list->malloced < 1000)
256 + new_size = racl_list->malloced + 1000;
258 + new_size = racl_list->malloced * 2;
259 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
260 + if (verbose >= 3) {
261 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
262 + (double) new_size * sizeof racl_list->racls[0],
263 + racl_list->racls ? "" : " not");
266 + racl_list->racls = new_ptr;
267 + racl_list->malloced = new_size;
269 + if (!racl_list->racls)
270 + out_of_memory("expand_rsync_acl_list");
275 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
277 + /* run this in reverse, so references are freed before referents, */
278 + /* although not currently necessary */
279 + while (racl_list->count--) {
280 + rsync_acl *racl = &racl_list->racls[racl_list->count];
282 + rsync_acl_free(racl);
284 + free(racl_list->racls);
285 + racl_list->racls = NULL;
286 + racl_list->malloced = 0;
290 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
291 + const rsync_acl_list *racl_list,
292 + const rsync_acl *racl)
294 + static int access_match = -1, default_match = -1;
295 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
296 + &access_match : &default_match;
297 + size_t count = racl_list->count;
298 + /* if this is the first time through or we didn't match the last
299 + * time, then start at the end of the list, which should be the
300 + * best place to start hunting */
302 + *match = racl_list->count - 1;
304 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
307 + *match = racl_list->count - 1;
313 +/* the general strategy with the tag_type <-> character mapping is that
314 + * lowercase implies that no qualifier follows, where uppercase does.
315 + * same sorta thing for the acl type (access or default) itself, but
316 + * lowercase in this instance means there's no ACL following, so the
317 + * ACL is a repeat, so the receiver should reuse the last of the same
320 +static void send_rsync_acl(int f, const rsync_acl *racl)
323 + size_t count = racl->count;
324 + write_int(f, count);
325 + for (race = racl->races; count--; race++) {
327 + switch (race->tag_type) {
328 + case SMB_ACL_USER_OBJ:
334 + case SMB_ACL_GROUP_OBJ:
337 + case SMB_ACL_GROUP:
340 + case SMB_ACL_OTHER:
348 + "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
353 + write_byte(f, race->access);
354 + if (isupper((int)ch)) {
355 + write_int(f, race->id);
356 + /* FIXME: sorta wasteful. we should maybe buffer as
357 + * many ids as max(ACL_USER + ACL_GROUP) objects to
358 + * keep from making so many calls */
367 +static rsync_acl _curr_rsync_acls[2];
370 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
372 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
373 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
374 + "unknown SMB_ACL_TYPE_T";
377 +/* generate the ACL(s) for this flist entry;
378 + * ACL(s) are either sent or cleaned-up by send_acl() below */
380 +BOOL make_acl(const struct file_struct *file, const char *fname)
382 + SMB_ACL_TYPE_T *type,
383 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
384 + rsync_acl *curr_racl;
385 + if (!preserve_acls || S_ISLNK(file->mode))
387 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
388 + type < &types[0] + sizeof types / sizeof types[0]
389 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
390 + type++, curr_racl++) {
393 + *curr_racl = rsync_acl_initializer;
394 + if (!(sacl = sys_acl_get_file(fname, *type))) {
395 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
396 + fname, str_acl_type(*type), strerror(errno));
399 + ok = unpack_smb_acl(curr_racl, sacl);
400 + sys_acl_free_acl(sacl);
407 +/* send the make_acl()-generated ACLs for this flist entry,
408 + * or clean up after an flist entry that's not being sent (f == -1) */
410 +void send_acl(const struct file_struct *file, int f)
412 + SMB_ACL_TYPE_T *type,
413 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
414 + rsync_acl *curr_racl;
415 + if (!preserve_acls || S_ISLNK(file->mode))
417 + for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
418 + type < &types[0] + sizeof types / sizeof types[0]
419 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
420 + type++, curr_racl++) {
422 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
424 + rsync_acl_free(curr_racl);
427 + if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
429 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
430 + write_int(f, index);
431 + rsync_acl_free(curr_racl);
433 + write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
434 + send_rsync_acl(f, curr_racl);
435 + expand_rsync_acl_list(racl_list);
436 + racl_list->racls[racl_list->count++] = *curr_racl;
441 +/* the below stuff is only used by the receiver */
443 +/* structure to hold index to rsync_acl_list member corresponding to
444 + * flist->files[i] */
447 + const struct file_struct *file;
454 + file_acl_index *fileaclidxs;
455 +} file_acl_index_list;
457 +static file_acl_index_list _file_acl_index_lists[] = {
458 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
459 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
462 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
464 + return type == SMB_ACL_TYPE_ACCESS ?
465 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
468 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
470 + /* first time through, 0 <= 0, so list is expanded:
471 + * diabolical, rsync guys! */
472 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
473 + file_acl_index *new_ptr;
475 + if (fileaclidx_list->malloced < 1000)
476 + new_size = fileaclidx_list->malloced + 1000;
478 + new_size = fileaclidx_list->malloced * 2;
479 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
480 + if (verbose >= 3) {
481 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
482 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
483 + fileaclidx_list->fileaclidxs ? "" : " not");
486 + fileaclidx_list->fileaclidxs = new_ptr;
487 + fileaclidx_list->malloced = new_size;
489 + if (!fileaclidx_list->fileaclidxs)
490 + out_of_memory("expand_file_acl_index_list");
495 +static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
497 + free(fileaclidx_list->fileaclidxs);
498 + fileaclidx_list->fileaclidxs = NULL;
499 + fileaclidx_list->malloced = 0;
503 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
511 +static smb_acl_list _smb_acl_lists[] = {
512 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
513 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
516 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
518 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
519 + &_smb_acl_lists[1];
522 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
524 + /* first time through, 0 <= 0, so list is expanded:
525 + * diabolical, rsync guys! */
526 + if (sacl_list->malloced <= sacl_list->count) {
527 + SMB_ACL_T *new_ptr;
529 + if (sacl_list->malloced < 1000)
530 + new_size = sacl_list->malloced + 1000;
532 + new_size = sacl_list->malloced * 2;
533 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
534 + if (verbose >= 3) {
535 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
536 + (double) new_size * sizeof sacl_list->sacls[0],
537 + sacl_list->sacls ? "" : " not");
540 + sacl_list->sacls = new_ptr;
541 + sacl_list->malloced = new_size;
543 + if (!sacl_list->sacls)
544 + out_of_memory("expand_smb_acl_list");
549 +static void free_smb_acl_list(SMB_ACL_TYPE_T type)
551 + smb_acl_list *sacl_list = smb_acl_lists(type);
552 + SMB_ACL_T *sacl = sacl_list->sacls;
553 + while (sacl_list->count--) {
555 + sys_acl_free_acl(*sacl++);
557 + free(sacl_list->sacls);
558 + sacl_list->sacls = NULL;
559 + sacl_list->malloced = 0;
563 +/* build an SMB_ACL_T corresponding to an rsync_acl */
564 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
566 + size_t count = racl->count;
567 + rsync_ace *race = racl->races;
568 + const char *errfun = NULL;
569 + *smb_acl = sys_acl_init(count);
571 + rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
575 + for (; count--; race++) {
576 + SMB_ACL_ENTRY_T entry;
577 + SMB_ACL_PERMSET_T permset;
578 + if (sys_acl_create_entry(smb_acl, &entry)) {
579 + errfun = "sys_acl_create)";
582 + if (sys_acl_set_tag_type(entry, race->tag_type)) {
583 + errfun = "sys_acl_set_tag";
586 + if (race->tag_type == SMB_ACL_USER ||
587 + race->tag_type == SMB_ACL_GROUP)
588 + if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
589 + errfun = "sys_acl_set_qualfier";
592 + if (sys_acl_get_permset(entry, &permset)) {
593 + errfun = "sys_acl_get_permset";
596 + if (sys_acl_clear_perms(permset)) {
597 + errfun = "sys_acl_clear_perms";
600 + if (race->access & 4)
601 + if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
602 + errfun = "sys_acl_add_perm";
605 + if (race->access & 2)
606 + if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
607 + errfun = "sys_acl_add_perm";
610 + if (race->access & 1)
611 + if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
612 + errfun = "sys_acl_add_perm";
615 + if (sys_acl_set_permset(entry, permset)) {
616 + errfun = "sys_acl_set_permset";
621 + sys_acl_free_acl(*smb_acl);
622 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
629 +static void receive_rsync_acl(rsync_acl *racl, int f)
632 + uchar required_mask_perm = 0;
634 + BOOL saw_mask = False;
635 + BOOL saw_user_obj = False, saw_group_obj = False,
637 + size_t count = read_int(f);
642 + uchar tag = read_byte(f);
643 + expand_rsync_acl(racl);
644 + race = &racl->races[racl->count++];
647 + race->tag_type = SMB_ACL_USER_OBJ;
648 + saw_user_obj = True;
651 + race->tag_type = SMB_ACL_USER;
654 + race->tag_type = SMB_ACL_GROUP_OBJ;
655 + saw_group_obj = True;
658 + race->tag_type = SMB_ACL_GROUP;
661 + race->tag_type = SMB_ACL_OTHER;
665 + race->tag_type = SMB_ACL_MASK;
669 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
671 + exit_cleanup(RERR_STREAMIO);
673 + race->access = read_byte(f);
674 + if (race->access & ~ (4 | 2 | 1)) {
675 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
677 + exit_cleanup(RERR_STREAMIO);
679 + if (race->tag_type == SMB_ACL_USER ||
680 + race->tag_type == SMB_ACL_GROUP) {
681 + race->id = read_int(f);
683 + required_mask_perm |= race->access;
687 + else if (race->tag_type == SMB_ACL_GROUP_OBJ)
688 + required_mask_perm |= race->access;
692 + if (!saw_user_obj) {
693 + expand_rsync_acl(racl);
694 + race = &racl->races[racl->count++];
695 + race->tag_type = SMB_ACL_USER_OBJ;
698 + if (!saw_group_obj) {
699 + expand_rsync_acl(racl);
700 + race = &racl->races[racl->count++];
701 + race->tag_type = SMB_ACL_GROUP_OBJ;
705 + expand_rsync_acl(racl);
706 + race = &racl->races[racl->count++];
707 + race->tag_type = SMB_ACL_OTHER;
712 + expand_rsync_acl(racl);
713 + race = &racl->races[racl->count++];
714 + race->tag_type = SMB_ACL_MASK;
715 + race->access = required_mask_perm;
718 + /* If we, a system without ACLS_NEED_MASK, received data from a
719 + * system that has masks, throw away the extraneous CLASS_OBJs. */
720 + if (saw_mask && racl->count == 4) {
721 + rsync_ace *group_obj_race = NULL, *mask_race = NULL;
724 + for (i = 0, p = racl->races; i < racl->count; i++, p++) {
725 + if (p->tag_type == SMB_ACL_MASK)
727 + else if (p->tag_type == SMB_ACL_GROUP_OBJ)
728 + group_obj_race = p;
730 + if (mask_race == NULL || group_obj_race == NULL) {
731 + rprintf(FERROR, "receive_rsync_acl: have four ACES "
732 + "and one's ACL_MASK but missing "
733 + "either it or ACL_GROUP_OBJ, "
734 + "when pruning ACL\n");
736 + /* mask off group perms with it first */
737 + group_obj_race->access &= mask_race->access;
738 + /* dump mask_race; re-slot any followers-on */
740 + if (mask_race != &racl->races[racl->count]) {
741 + *mask_race = racl->races[racl->count];
742 + saw_user_obj = False; /* force re-sort */
748 + if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
750 + if (!(saw_user_obj && saw_group_obj && saw_other))
752 + sort_rsync_acl(racl);
755 +/* receive and build the rsync_acl_lists */
757 +void receive_acl(struct file_struct *file, int f)
759 + SMB_ACL_TYPE_T *type,
760 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
762 + if (!preserve_acls || S_ISLNK(file->mode))
764 + fname = f_name(file);
765 + for (type = &types[0];
766 + type < &types[0] + sizeof types / sizeof types[0]
767 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
769 + file_acl_index_list *fileaclidx_list =
770 + file_acl_index_lists(*type);
772 + expand_file_acl_index_list(fileaclidx_list);
774 + tag = read_byte(f);
775 + if (tag == 'A' || tag == 'a') {
776 + if (*type != SMB_ACL_TYPE_ACCESS) {
777 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
779 + exit_cleanup(RERR_STREAMIO);
781 + } else if (tag == 'D' || tag == 'd') {
782 + if (*type == SMB_ACL_TYPE_ACCESS) {
783 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
785 + exit_cleanup(RERR_STREAMIO);
788 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
790 + exit_cleanup(RERR_STREAMIO);
792 + if (tag == 'A' || tag == 'D') {
793 + rsync_acl racl = rsync_acl_initializer;
794 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
795 + smb_acl_list *sacl_list = smb_acl_lists(*type);
796 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
797 + aclidx = racl_list->count;
798 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
800 + receive_rsync_acl(&racl, f);
801 + expand_rsync_acl_list(racl_list);
802 + racl_list->racls[racl_list->count++] = racl;
803 + expand_smb_acl_list(sacl_list);
804 + sacl_list->sacls[sacl_list->count++] = NULL;
806 + int index = read_int(f);
807 + rsync_acl_list *racl_list = rsync_acl_lists(*type);
808 + if ((size_t) index >= racl_list->count) {
809 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
811 + str_acl_type(*type),
813 + exit_cleanup(RERR_STREAMIO);
815 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
817 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
823 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
825 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
826 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
827 + return fileaclidx1->file == fileaclidx2->file ? 0 :
828 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
831 +void sort_file_acl_index_lists()
833 + SMB_ACL_TYPE_T *type,
834 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
835 + if (!preserve_acls)
837 + for (type = &types[0];
838 + type < &types[0] + sizeof types / sizeof types[0];
841 + file_acl_index_list *fileaclidx_list =
842 + file_acl_index_lists(*type);
843 + if (!fileaclidx_list->count)
845 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
846 + sizeof fileaclidx_list->fileaclidxs[0],
847 + &file_acl_index_list_sorter);
851 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
852 + const struct file_struct *file) {
853 + int low = 0, high = fileaclidx_list->count;
854 + const struct file_struct *file_mid;
858 + int mid = (high + low) / 2;
859 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
860 + if (file_mid == file)
861 + return fileaclidx_list->fileaclidxs[mid].aclidx;
862 + if (file_mid > file)
866 + } while (low < high);
868 + file_mid = fileaclidx_list->fileaclidxs[low].file;
869 + if (file_mid == file)
870 + return fileaclidx_list->fileaclidxs[low].aclidx;
873 + "find_file_acl_index: can't find entry for file in list\n");
874 + exit_cleanup(RERR_STREAMIO);
878 +/* for duplicating ACLs on backups when using backup_dir */
880 +int dup_acl(const char *orig, const char *bak, mode_t mode)
882 + SMB_ACL_TYPE_T *type,
883 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
885 + if (!preserve_acls)
887 + for (type = &types[0];
888 + type < &types[0] + sizeof types / sizeof types[0]
889 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
891 + SMB_ACL_T sacl_orig, sacl_bak;
892 + rsync_acl racl_orig, racl_bak;
893 + if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
894 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
895 + orig, str_acl_type(*type), strerror(errno));
899 + if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
900 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
901 + bak, str_acl_type(*type), strerror(errno));
903 + /* try to forge on through */
905 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
907 + goto out_with_sacls;
910 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
912 + goto out_with_one_racl;
914 + if (rsync_acls_equal(&racl_orig, &racl_bak))
917 + ; /* presume they're unequal */
919 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
920 + if (-1 == sys_acl_delete_def_file(bak)) {
921 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
922 + bak, strerror(errno));
925 + } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
926 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
927 + bak, str_acl_type(*type), strerror(errno));
932 + rsync_acl_free(&racl_bak);
934 + rsync_acl_free(&racl_orig);
937 + sys_acl_free_acl(sacl_bak);
938 + /* out_with_one_sacl: */
940 + sys_acl_free_acl(sacl_orig);
945 +/* stuff for redirecting calls to set_acl() from set_perms()
946 + * for keep_backup() */
947 +static const struct file_struct *backup_orig_file = NULL;
948 +static const char null_string[] = "";
949 +static const char *backup_orig_fname = null_string;
950 +static const char *backup_dest_fname = null_string;
951 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
953 +void push_keep_backup_acl(const struct file_struct *file,
954 + const char *orig, const char *dest)
956 + if (preserve_acls) {
957 + SMB_ACL_TYPE_T *type,
958 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
960 + backup_orig_file = file;
961 + backup_orig_fname = orig;
962 + backup_dest_fname = dest;
963 + for (type = &types[0], sacl = &_backup_sacl[0];
964 + type < &types[0] + sizeof types / sizeof types[0];
966 + if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
969 + if (!(*sacl = sys_acl_get_file(orig, *type))) {
970 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
971 + orig, str_acl_type(*type),
979 +static int set_keep_backup_acl()
981 + if (preserve_acls) {
982 + SMB_ACL_TYPE_T *type,
983 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
986 + for (type = &types[0], sacl = &_backup_sacl[0];
987 + type < &types[0] + sizeof types / sizeof types[0];
990 + if (-1 == sys_acl_set_file(backup_dest_fname,
993 + rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
995 + str_acl_type(*type),
1006 +void cleanup_keep_backup_acl()
1008 + if (preserve_acls) {
1009 + SMB_ACL_TYPE_T *type,
1010 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1012 + backup_orig_file = NULL;
1013 + backup_orig_fname = null_string;
1014 + backup_dest_fname = null_string;
1015 + for (type = &types[0], sacl = &_backup_sacl[0];
1016 + type < &types[0] + sizeof types / sizeof types[0];
1019 + sys_acl_free_acl(*sacl);
1025 +/* set ACL on rsync-ed or keep_backup-ed file */
1027 +int set_acl(const char *fname, const struct file_struct *file)
1030 + SMB_ACL_TYPE_T *type,
1031 + types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1032 + if (dry_run || !preserve_acls || S_ISLNK(file->mode))
1034 + if (file == backup_orig_file) {
1035 + if (!strcmp(fname, backup_dest_fname))
1036 + return set_keep_backup_acl();
1038 + for (type = &types[0];
1039 + type < &types[0] + sizeof types / sizeof types[0]
1040 + && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1042 + SMB_ACL_T sacl_orig, *sacl_new;
1043 + rsync_acl racl_orig, *racl_new;
1044 + int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1047 + racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1048 + sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1049 + sacl_orig = sys_acl_get_file(fname, *type);
1051 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1052 + fname, str_acl_type(*type), strerror(errno));
1056 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1057 + sys_acl_free_acl(sacl_orig);
1062 + ok = rsync_acls_equal(&racl_orig, racl_new);
1063 + rsync_acl_free(&racl_orig);
1066 + if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1067 + if (-1 == sys_acl_delete_def_file(fname)) {
1068 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1069 + fname, strerror(errno));
1075 + if (!pack_smb_acl(sacl_new, racl_new)) {
1079 + if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1080 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1081 + fname, str_acl_type(*type),
1093 +/* enumeration functions for uid mapping */
1095 +/* context -- one and only one. should be cycled through once on uid mapping
1096 + * and once on gid mapping */
1097 +static rsync_acl_list *_enum_racl_lists[] = {
1098 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1101 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1102 +static size_t enum_racl_index = 0;
1103 +static size_t enum_race_index = 0;
1105 +/* this returns the next tag_type id from the given acl for the next entry,
1106 + * or it returns 0 if there are no more tag_type ids in the acl */
1108 +static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1110 + for (; enum_race_index < racl->count; enum_race_index++) {
1111 + rsync_ace *race = &racl->races[enum_race_index];
1112 + if (race->tag_type == tag_type)
1115 + enum_race_index = 0;
1119 +static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1121 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1122 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1123 + id_t id = next_ace_id(tag_type, racl);
1127 + enum_racl_index = 0;
1131 +static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1133 + for (; *enum_racl_list; enum_racl_list++) {
1134 + id_t id = next_acl_id(tag_type, *enum_racl_list);
1138 + enum_racl_list = &_enum_racl_lists[0];
1142 +id_t next_acl_uid()
1144 + return next_acl_list_id(SMB_ACL_USER);
1147 +id_t next_acl_gid()
1149 + return next_acl_list_id(SMB_ACL_GROUP);
1152 +/* referring to the global context enum_entry, sets the entry's id */
1153 +static void set_acl_id(id_t id)
1155 + (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1158 +void acl_uid_map(id_t uid)
1163 +void acl_gid_map(id_t gid)
1168 +#endif /* SUPPORT_ACLS */
1169 --- orig/backup.c 2005-02-14 02:45:09
1170 +++ backup.c 2004-10-06 00:13:09
1171 @@ -121,6 +121,7 @@ static int make_bak_dir(char *fullpath)
1173 do_lchown(fullpath, st.st_uid, st.st_gid);
1174 do_chmod(fullpath, st.st_mode);
1175 + (void)DUP_ACL(end, fullpath, st.st_mode);
1179 @@ -173,6 +174,8 @@ static int keep_backup(char *fname)
1180 if (!(buf = get_backup_name(fname)))
1183 + PUSH_KEEP_BACKUP_ACL(file, fname, buf);
1185 /* Check to see if this is a device file, or link */
1186 if (IS_DEVICE(file->mode)) {
1187 if (am_root && preserve_devices) {
1188 @@ -246,6 +249,7 @@ static int keep_backup(char *fname)
1191 set_perms(buf, file, NULL, 0);
1192 + CLEANUP_KEEP_BACKUP_ACL();
1196 --- orig/configure.in 2005-01-28 23:01:08
1197 +++ configure.in 2004-08-19 19:53:27
1198 @@ -467,6 +467,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1199 AC_CHECK_LIB(resolv, strcasecmp)
1202 +AC_CHECK_FUNCS(aclsort)
1203 +if test x"$ac_cv_func_aclsort" = x"no"; then
1204 + AC_CHECK_LIB(sec, aclsort)
1207 dnl At the moment we don't test for a broken memcmp(), because all we
1208 dnl need to do is test for equality, not comparison, and it seems that
1209 dnl every platform has a memcmp that can do at least that.
1210 @@ -713,6 +718,77 @@ AC_SUBST(OBJ_RESTORE)
1211 AC_SUBST(CC_SHOBJ_FLAG)
1212 AC_SUBST(BUILD_POPT)
1214 +AC_CHECK_HEADERS(sys/acl.h)
1215 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1216 +#################################################
1217 +# check for ACL support
1219 +AC_MSG_CHECKING(whether to support ACLs)
1220 +AC_ARG_WITH(acl-support,
1221 +[ --with-acl-support Include ACL support (default=no)],
1222 +[ case "$withval" in
1225 + case "$host_os" in
1227 + AC_MSG_RESULT(Using UnixWare ACLs)
1228 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1231 + AC_MSG_RESULT(Using solaris ACLs)
1232 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1235 + AC_MSG_RESULT(Using HPUX ACLs)
1236 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1239 + AC_MSG_RESULT(Using IRIX ACLs)
1240 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1243 + AC_MSG_RESULT(Using AIX ACLs)
1244 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1247 + AC_MSG_RESULT(Using Tru64 ACLs)
1248 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1249 + LIBS="$LIBS -lpacl"
1252 + AC_MSG_RESULT(ACLs requested -- running tests)
1253 + AC_CHECK_LIB(acl,acl_get_file)
1254 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1255 + AC_TRY_LINK([#include <sys/types.h>
1256 +#include <sys/acl.h>],
1257 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1258 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1259 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1260 + AC_MSG_RESULT(Using posix ACLs)
1261 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1262 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1263 + AC_TRY_LINK([#include <sys/types.h>
1264 +#include <sys/acl.h>],
1265 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1266 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1267 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1268 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1271 + AC_MSG_ERROR(Failed to find ACL support)
1278 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1281 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1285 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1288 --- orig/flist.c 2005-02-14 02:45:10
1289 +++ flist.c 2005-02-14 02:45:34
1290 @@ -978,6 +978,8 @@ void send_file_name(int f, struct file_l
1291 file = make_file(fname, flist, f == -2 ? SERVER_FILTERS : ALL_FILTERS);
1294 + if (!MAKE_ACL(file, fname))
1297 maybe_emit_filelist_progress(flist);
1299 @@ -986,6 +988,10 @@ void send_file_name(int f, struct file_l
1300 if (file->basename[0]) {
1301 flist->files[flist->count++] = file;
1302 send_file_entry(file, f, base_flags);
1303 + SEND_ACL(file, f);
1305 + /* Cleanup unsent ACL(s). */
1306 + SEND_ACL(file, -1);
1309 if (recursive && S_ISDIR(file->mode)
1310 @@ -1296,6 +1302,8 @@ struct file_list *recv_file_list(int f)
1311 flags |= read_byte(f) << 8;
1312 file = receive_file_entry(flist, flags, f);
1314 + RECEIVE_ACL(file, f);
1316 if (S_ISREG(file->mode))
1317 stats.total_size += file->length;
1319 @@ -1318,6 +1326,8 @@ struct file_list *recv_file_list(int f)
1321 clean_flist(flist, relative_paths, 1);
1323 + SORT_FILE_ACL_INDEX_LISTS();
1326 /* Now send the uid/gid list. This was introduced in
1327 * protocol version 15 */
1328 --- orig/generator.c 2005-02-18 20:17:34
1329 +++ generator.c 2005-01-30 10:09:44
1330 @@ -451,6 +451,10 @@ static void recv_generator(char *fname,
1331 if (set_perms(fname, file, statret ? NULL : &st, 0)
1332 && verbose && protocol_version < 29 && f_out != -1)
1333 rprintf(FINFO, "%s/\n", safe_fname(fname));
1336 + SET_ACL(fname, file);
1338 if (delete_during && f_out != -1 && csum_length != SUM_LENGTH
1339 && (file->flags & FLAG_DEL_HERE))
1340 delete_in_dir(flist, fname, file);
1341 --- orig/lib/sysacls.c 2004-10-20 15:35:58
1342 +++ lib/sysacls.c 2004-10-20 15:35:58
1345 + Unix SMB/CIFS implementation.
1346 + Samba system utilities for ACL support.
1347 + Copyright (C) Jeremy Allison 2000.
1349 + This program is free software; you can redistribute it and/or modify
1350 + it under the terms of the GNU General Public License as published by
1351 + the Free Software Foundation; either version 2 of the License, or
1352 + (at your option) any later version.
1354 + This program is distributed in the hope that it will be useful,
1355 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1356 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1357 + GNU General Public License for more details.
1359 + You should have received a copy of the GNU General Public License
1360 + along with this program; if not, write to the Free Software
1361 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1365 +#include "sysacls.h"
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;
1386 + This file wraps all differing system ACL interfaces into a consistent
1387 + one based on the POSIX interface. It also returns the correct errors
1388 + for older UNIX systems that don't support ACLs.
1390 + The interfaces that each ACL implementation must support are as follows :
1392 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1393 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1394 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1395 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1396 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1397 + SMB_ACL_T sys_acl_get_fd(int fd)
1398 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1399 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1400 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1401 + SMB_ACL_T sys_acl_init( int count)
1402 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1403 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1404 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1405 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1406 + int sys_acl_valid( SMB_ACL_T theacl )
1407 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1408 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1409 + int sys_acl_delete_def_file(const char *path)
1411 + This next one is not POSIX complient - but we *have* to have it !
1412 + More POSIX braindamage.
1414 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1416 + The generic POSIX free is the following call. We split this into
1417 + several different free functions as we may need to add tag info
1418 + to structures when emulating the POSIX interface.
1420 + int sys_acl_free( void *obj_p)
1422 + The calls we actually use are :
1424 + int sys_acl_free_text(char *text) - free acl_to_text
1425 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1426 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1430 +#if defined(HAVE_POSIX_ACLS)
1432 +/* Identity mapping - easy. */
1434 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1436 + return acl_get_entry( the_acl, entry_id, entry_p);
1439 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1441 + return acl_get_tag_type( entry_d, tag_type_p);
1444 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1446 + return acl_get_permset( entry_d, permset_p);
1449 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1451 + return acl_get_qualifier( entry_d);
1454 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1456 + return acl_get_file( path_p, type);
1459 +SMB_ACL_T sys_acl_get_fd(int fd)
1461 + return acl_get_fd(fd);
1464 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1466 + return acl_clear_perms(permset);
1469 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1471 + return acl_add_perm(permset, perm);
1474 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1476 +#if defined(HAVE_ACL_GET_PERM_NP)
1478 + * Required for TrustedBSD-based ACL implementations where
1479 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1482 + return acl_get_perm_np(permset, perm);
1484 + return acl_get_perm(permset, perm);
1488 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1490 + return acl_to_text( the_acl, plen);
1493 +SMB_ACL_T sys_acl_init( int count)
1495 + return acl_init(count);
1498 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1500 + return acl_create_entry(pacl, pentry);
1503 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1505 + return acl_set_tag_type(entry, tagtype);
1508 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1510 + return acl_set_qualifier(entry, qual);
1513 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1515 + return acl_set_permset(entry, permset);
1518 +int sys_acl_valid( SMB_ACL_T theacl )
1520 + return acl_valid(theacl);
1523 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1525 + return acl_set_file(name, acltype, theacl);
1528 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1530 + return acl_set_fd(fd, theacl);
1533 +int sys_acl_delete_def_file(const char *name)
1535 + return acl_delete_def_file(name);
1538 +int sys_acl_free_text(char *text)
1540 + return acl_free(text);
1543 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1545 + return acl_free(the_acl);
1548 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1550 + return acl_free(qual);
1553 +#elif defined(HAVE_TRU64_ACLS)
1555 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1556 + * is based on Draft 13 of the POSIX spec which is
1557 + * slightly different from the Draft 16 interface.
1559 + * Also, some of the permset manipulation functions
1560 + * such as acl_clear_perm() and acl_add_perm() appear
1561 + * to be broken on Tru64 so we have to manipulate
1562 + * the permission bits in the permset directly.
1564 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1566 + SMB_ACL_ENTRY_T entry;
1568 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1573 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1578 + return errno ? -1 : 0;
1581 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1583 + return acl_get_tag_type( entry_d, tag_type_p);
1586 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1588 + return acl_get_permset( entry_d, permset_p);
1591 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1593 + return acl_get_qualifier( entry_d);
1596 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1598 + return acl_get_file((char *)path_p, type);
1601 +SMB_ACL_T sys_acl_get_fd(int fd)
1603 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1606 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1608 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1613 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1615 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1620 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1625 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1627 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1630 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1632 + return acl_to_text( the_acl, plen);
1635 +SMB_ACL_T sys_acl_init( int count)
1637 + return acl_init(count);
1640 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1642 + SMB_ACL_ENTRY_T entry;
1644 + if ((entry = acl_create_entry(pacl)) == NULL) {
1652 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1654 + return acl_set_tag_type(entry, tagtype);
1657 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1659 + return acl_set_qualifier(entry, qual);
1662 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1664 + return acl_set_permset(entry, permset);
1667 +int sys_acl_valid( SMB_ACL_T theacl )
1669 + acl_entry_t entry;
1671 + return acl_valid(theacl, &entry);
1674 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1676 + return acl_set_file((char *)name, acltype, theacl);
1679 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1681 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1684 +int sys_acl_delete_def_file(const char *name)
1686 + return acl_delete_def_file((char *)name);
1689 +int sys_acl_free_text(char *text)
1692 + * (void) cast and explicit return 0 are for DEC UNIX
1693 + * which just #defines acl_free_text() to be free()
1695 + (void) acl_free_text(text);
1699 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1701 + return acl_free(the_acl);
1704 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1706 + return acl_free_qualifier(qual, tagtype);
1709 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1712 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1713 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1717 + * Note that while this code implements sufficient functionality
1718 + * to support the sys_acl_* interfaces it does not provide all
1719 + * of the semantics of the POSIX ACL interfaces.
1721 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1722 + * from a call to sys_acl_get_entry() should not be assumed to be
1723 + * valid after calling any of the following functions, which may
1724 + * reorder the entries in the ACL.
1727 + * sys_acl_set_file()
1728 + * sys_acl_set_fd()
1732 + * The only difference between Solaris and UnixWare / OpenUNIX is
1733 + * that the #defines for the ACL operations have different names
1735 +#if defined(HAVE_UNIXWARE_ACLS)
1737 +#define SETACL ACL_SET
1738 +#define GETACL ACL_GET
1739 +#define GETACLCNT ACL_CNT
1744 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1746 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1751 + if (entry_p == NULL) {
1756 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1760 + if (acl_d->next < 0) {
1765 + if (acl_d->next >= acl_d->count) {
1769 + *entry_p = &acl_d->acl[acl_d->next++];
1774 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1776 + *type_p = entry_d->a_type;
1781 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1783 + *permset_p = &entry_d->a_perm;
1788 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1790 + if (entry_d->a_type != SMB_ACL_USER
1791 + && entry_d->a_type != SMB_ACL_GROUP) {
1796 + return &entry_d->a_id;
1800 + * There is no way of knowing what size the ACL returned by
1801 + * GETACL will be unless you first call GETACLCNT which means
1802 + * making an additional system call.
1804 + * In the hope of avoiding the cost of the additional system
1805 + * call in most cases, we initially allocate enough space for
1806 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1807 + * be too small then we use GETACLCNT to find out the actual
1808 + * size, reallocate the ACL buffer, and then call GETACL again.
1811 +#define INITIAL_ACL_SIZE 16
1813 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
1816 + int count; /* # of ACL entries allocated */
1817 + int naccess; /* # of access ACL entries */
1818 + int ndefault; /* # of default ACL entries */
1820 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1825 + count = INITIAL_ACL_SIZE;
1826 + if ((acl_d = sys_acl_init(count)) == NULL) {
1831 + * If there isn't enough space for the ACL entries we use
1832 + * GETACLCNT to determine the actual number of ACL entries
1833 + * reallocate and try again. This is in a loop because it
1834 + * is possible that someone else could modify the ACL and
1835 + * increase the number of entries between the call to
1836 + * GETACLCNT and the call to GETACL.
1838 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1839 + && errno == ENOSPC) {
1841 + sys_acl_free_acl(acl_d);
1843 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1847 + if ((acl_d = sys_acl_init(count)) == NULL) {
1853 + sys_acl_free_acl(acl_d);
1858 + * calculate the number of access and default ACL entries
1860 + * Note: we assume that the acl() system call returned a
1861 + * well formed ACL which is sorted so that all of the
1862 + * access ACL entries preceed any default ACL entries
1864 + for (naccess = 0; naccess < count; naccess++) {
1865 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1868 + ndefault = count - naccess;
1871 + * if the caller wants the default ACL we have to copy
1872 + * the entries down to the start of the acl[] buffer
1873 + * and mask out the ACL_DEFAULT flag from the type field
1875 + if (type == SMB_ACL_TYPE_DEFAULT) {
1878 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
1879 + acl_d->acl[i] = acl_d->acl[j];
1880 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
1883 + acl_d->count = ndefault;
1885 + acl_d->count = naccess;
1891 +SMB_ACL_T sys_acl_get_fd(int fd)
1894 + int count; /* # of ACL entries allocated */
1895 + int naccess; /* # of access ACL entries */
1897 + count = INITIAL_ACL_SIZE;
1898 + if ((acl_d = sys_acl_init(count)) == NULL) {
1902 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
1903 + && errno == ENOSPC) {
1905 + sys_acl_free_acl(acl_d);
1907 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
1911 + if ((acl_d = sys_acl_init(count)) == NULL) {
1917 + sys_acl_free_acl(acl_d);
1922 + * calculate the number of access ACL entries
1924 + for (naccess = 0; naccess < count; naccess++) {
1925 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1929 + acl_d->count = naccess;
1934 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
1941 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
1943 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
1944 + && perm != SMB_ACL_EXECUTE) {
1949 + if (permset_d == NULL) {
1954 + *permset_d |= perm;
1959 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
1961 + return *permset_d & perm;
1964 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
1971 + * use an initial estimate of 20 bytes per ACL entry
1972 + * when allocating memory for the text representation
1976 + maxlen = 20 * acl_d->count;
1977 + if ((text = malloc(maxlen)) == NULL) {
1982 + for (i = 0; i < acl_d->count; i++) {
1983 + struct acl *ap = &acl_d->acl[i];
1984 + struct passwd *pw;
1993 + switch (ap->a_type) {
1995 + * for debugging purposes it's probably more
1996 + * useful to dump unknown tag types rather
1997 + * than just returning an error
2000 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2003 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2008 + case SMB_ACL_USER:
2009 + id = uidtoname(ap->a_id);
2010 + case SMB_ACL_USER_OBJ:
2014 + case SMB_ACL_GROUP:
2015 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2016 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2022 + case SMB_ACL_GROUP_OBJ:
2026 + case SMB_ACL_OTHER:
2030 + case SMB_ACL_MASK:
2036 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2037 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2038 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2041 + /* <tag> : <qualifier> : rwx \n \0 */
2042 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2045 + * If this entry would overflow the buffer
2046 + * allocate enough additional memory for this
2047 + * entry and an estimate of another 20 bytes
2048 + * for each entry still to be processed
2050 + if ((len + nbytes) > maxlen) {
2051 + char *oldtext = text;
2053 + maxlen += nbytes + 20 * (acl_d->count - i);
2055 + if ((text = Realloc(oldtext, maxlen)) == NULL) {
2056 + SAFE_FREE(oldtext);
2062 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2063 + len += nbytes - 1;
2072 +SMB_ACL_T sys_acl_init(int count)
2082 + * note that since the definition of the structure pointed
2083 + * to by the SMB_ACL_T includes the first element of the
2084 + * acl[] array, this actually allocates an ACL with room
2085 + * for (count+1) entries
2087 + if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
2092 + a->size = count + 1;
2100 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2103 + SMB_ACL_ENTRY_T entry_d;
2105 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2110 + if (acl_d->count >= acl_d->size) {
2115 + entry_d = &acl_d->acl[acl_d->count++];
2116 + entry_d->a_type = 0;
2117 + entry_d->a_id = -1;
2118 + entry_d->a_perm = 0;
2119 + *entry_p = entry_d;
2124 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2126 + switch (tag_type) {
2127 + case SMB_ACL_USER:
2128 + case SMB_ACL_USER_OBJ:
2129 + case SMB_ACL_GROUP:
2130 + case SMB_ACL_GROUP_OBJ:
2131 + case SMB_ACL_OTHER:
2132 + case SMB_ACL_MASK:
2133 + entry_d->a_type = tag_type;
2143 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2145 + if (entry_d->a_type != SMB_ACL_GROUP
2146 + && entry_d->a_type != SMB_ACL_USER) {
2151 + entry_d->a_id = *((id_t *)qual_p);
2156 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2158 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2162 + entry_d->a_perm = *permset_d;
2168 + * sort the ACL and check it for validity
2170 + * if it's a minimal ACL with only 4 entries then we
2171 + * need to recalculate the mask permissions to make
2172 + * sure that they are the same as the GROUP_OBJ
2173 + * permissions as required by the UnixWare acl() system call.
2175 + * (note: since POSIX allows minimal ACLs which only contain
2176 + * 3 entries - ie there is no mask entry - we should, in theory,
2177 + * check for this and add a mask entry if necessary - however
2178 + * we "know" that the caller of this interface always specifies
2179 + * a mask so, in practice "this never happens" (tm) - if it *does*
2180 + * happen aclsort() will fail and return an error and someone will
2181 + * have to fix it ...)
2184 +static int acl_sort(SMB_ACL_T acl_d)
2186 + int fixmask = (acl_d->count <= 4);
2188 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2195 +int sys_acl_valid(SMB_ACL_T acl_d)
2197 + return acl_sort(acl_d);
2200 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2203 + struct acl *acl_p;
2205 + struct acl *acl_buf = NULL;
2208 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2213 + if (acl_sort(acl_d) != 0) {
2217 + acl_p = &acl_d->acl[0];
2218 + acl_count = acl_d->count;
2221 + * if it's a directory there is extra work to do
2222 + * since the acl() system call will replace both
2223 + * the access ACLs and the default ACLs (if any)
2225 + if (stat(name, &s) != 0) {
2228 + if (S_ISDIR(s.st_mode)) {
2229 + SMB_ACL_T acc_acl;
2230 + SMB_ACL_T def_acl;
2231 + SMB_ACL_T tmp_acl;
2234 + if (type == SMB_ACL_TYPE_ACCESS) {
2236 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2240 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2243 + if (tmp_acl == NULL) {
2248 + * allocate a temporary buffer for the complete ACL
2250 + acl_count = acc_acl->count + def_acl->count;
2251 + acl_p = acl_buf = malloc(acl_count * sizeof(acl_buf[0]));
2253 + if (acl_buf == NULL) {
2254 + sys_acl_free_acl(tmp_acl);
2260 + * copy the access control and default entries into the buffer
2262 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2263 + acc_acl->count * sizeof(acl_buf[0]));
2265 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2266 + def_acl->count * sizeof(acl_buf[0]));
2269 + * set the ACL_DEFAULT flag on the default entries
2271 + for (i = acc_acl->count; i < acl_count; i++) {
2272 + acl_buf[i].a_type |= ACL_DEFAULT;
2275 + sys_acl_free_acl(tmp_acl);
2277 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2282 + ret = acl(name, SETACL, acl_count, acl_p);
2284 + SAFE_FREE(acl_buf);
2289 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2291 + if (acl_sort(acl_d) != 0) {
2295 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2298 +int sys_acl_delete_def_file(const char *path)
2304 + * fetching the access ACL and rewriting it has
2305 + * the effect of deleting the default ACL
2307 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2311 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2313 + sys_acl_free_acl(acl_d);
2318 +int sys_acl_free_text(char *text)
2324 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2330 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2335 +#elif defined(HAVE_HPUX_ACLS)
2339 + * Based on the Solaris/SCO code - with modifications.
2343 + * Note that while this code implements sufficient functionality
2344 + * to support the sys_acl_* interfaces it does not provide all
2345 + * of the semantics of the POSIX ACL interfaces.
2347 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2348 + * from a call to sys_acl_get_entry() should not be assumed to be
2349 + * valid after calling any of the following functions, which may
2350 + * reorder the entries in the ACL.
2353 + * sys_acl_set_file()
2354 + * sys_acl_set_fd()
2357 +/* This checks if the POSIX ACL system call is defined */
2358 +/* which basically corresponds to whether JFS 3.3 or */
2359 +/* higher is installed. If acl() was called when it */
2360 +/* isn't defined, it causes the process to core dump */
2361 +/* so it is important to check this and avoid acl() */
2362 +/* calls if it isn't there. */
2364 +static BOOL hpux_acl_call_presence(void)
2367 + shl_t handle = NULL;
2370 + static BOOL already_checked=0;
2372 + if(already_checked)
2376 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2378 + if(ret_val != 0) {
2379 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2380 + ret_val, errno, strerror(errno)));
2381 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2385 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2387 + already_checked = True;
2391 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2393 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2398 + if (entry_p == NULL) {
2403 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2407 + if (acl_d->next < 0) {
2412 + if (acl_d->next >= acl_d->count) {
2416 + *entry_p = &acl_d->acl[acl_d->next++];
2421 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2423 + *type_p = entry_d->a_type;
2428 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2430 + *permset_p = &entry_d->a_perm;
2435 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2437 + if (entry_d->a_type != SMB_ACL_USER
2438 + && entry_d->a_type != SMB_ACL_GROUP) {
2443 + return &entry_d->a_id;
2447 + * There is no way of knowing what size the ACL returned by
2448 + * ACL_GET will be unless you first call ACL_CNT which means
2449 + * making an additional system call.
2451 + * In the hope of avoiding the cost of the additional system
2452 + * call in most cases, we initially allocate enough space for
2453 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2454 + * be too small then we use ACL_CNT to find out the actual
2455 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2458 +#define INITIAL_ACL_SIZE 16
2460 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2463 + int count; /* # of ACL entries allocated */
2464 + int naccess; /* # of access ACL entries */
2465 + int ndefault; /* # of default ACL entries */
2467 + if(hpux_acl_call_presence() == False) {
2468 + /* Looks like we don't have the acl() system call on HPUX.
2469 + * May be the system doesn't have the latest version of JFS.
2474 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2479 + count = INITIAL_ACL_SIZE;
2480 + if ((acl_d = sys_acl_init(count)) == NULL) {
2485 + * If there isn't enough space for the ACL entries we use
2486 + * ACL_CNT to determine the actual number of ACL entries
2487 + * reallocate and try again. This is in a loop because it
2488 + * is possible that someone else could modify the ACL and
2489 + * increase the number of entries between the call to
2490 + * ACL_CNT and the call to ACL_GET.
2492 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2494 + sys_acl_free_acl(acl_d);
2496 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2500 + if ((acl_d = sys_acl_init(count)) == NULL) {
2506 + sys_acl_free_acl(acl_d);
2511 + * calculate the number of access and default ACL entries
2513 + * Note: we assume that the acl() system call returned a
2514 + * well formed ACL which is sorted so that all of the
2515 + * access ACL entries preceed any default ACL entries
2517 + for (naccess = 0; naccess < count; naccess++) {
2518 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2521 + ndefault = count - naccess;
2524 + * if the caller wants the default ACL we have to copy
2525 + * the entries down to the start of the acl[] buffer
2526 + * and mask out the ACL_DEFAULT flag from the type field
2528 + if (type == SMB_ACL_TYPE_DEFAULT) {
2531 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2532 + acl_d->acl[i] = acl_d->acl[j];
2533 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2536 + acl_d->count = ndefault;
2538 + acl_d->count = naccess;
2544 +SMB_ACL_T sys_acl_get_fd(int fd)
2547 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2550 + files_struct *fsp = file_find_fd(fd);
2552 + if (fsp == NULL) {
2558 + * We know we're in the same conn context. So we
2559 + * can use the relative path.
2562 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2565 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2572 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2574 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2575 + && perm != SMB_ACL_EXECUTE) {
2580 + if (permset_d == NULL) {
2585 + *permset_d |= perm;
2590 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2592 + return *permset_d & perm;
2595 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2602 + * use an initial estimate of 20 bytes per ACL entry
2603 + * when allocating memory for the text representation
2607 + maxlen = 20 * acl_d->count;
2608 + if ((text = malloc(maxlen)) == NULL) {
2613 + for (i = 0; i < acl_d->count; i++) {
2614 + struct acl *ap = &acl_d->acl[i];
2615 + struct passwd *pw;
2624 + switch (ap->a_type) {
2626 + * for debugging purposes it's probably more
2627 + * useful to dump unknown tag types rather
2628 + * than just returning an error
2631 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2634 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2639 + case SMB_ACL_USER:
2640 + id = uidtoname(ap->a_id);
2641 + case SMB_ACL_USER_OBJ:
2645 + case SMB_ACL_GROUP:
2646 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2647 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2653 + case SMB_ACL_GROUP_OBJ:
2657 + case SMB_ACL_OTHER:
2661 + case SMB_ACL_MASK:
2667 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2668 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2669 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2672 + /* <tag> : <qualifier> : rwx \n \0 */
2673 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2676 + * If this entry would overflow the buffer
2677 + * allocate enough additional memory for this
2678 + * entry and an estimate of another 20 bytes
2679 + * for each entry still to be processed
2681 + if ((len + nbytes) > maxlen) {
2682 + char *oldtext = text;
2684 + maxlen += nbytes + 20 * (acl_d->count - i);
2686 + if ((text = Realloc(oldtext, maxlen)) == NULL) {
2693 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2694 + len += nbytes - 1;
2703 +SMB_ACL_T sys_acl_init(int count)
2713 + * note that since the definition of the structure pointed
2714 + * to by the SMB_ACL_T includes the first element of the
2715 + * acl[] array, this actually allocates an ACL with room
2716 + * for (count+1) entries
2718 + if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
2723 + a->size = count + 1;
2731 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2734 + SMB_ACL_ENTRY_T entry_d;
2736 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2741 + if (acl_d->count >= acl_d->size) {
2746 + entry_d = &acl_d->acl[acl_d->count++];
2747 + entry_d->a_type = 0;
2748 + entry_d->a_id = -1;
2749 + entry_d->a_perm = 0;
2750 + *entry_p = entry_d;
2755 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2757 + switch (tag_type) {
2758 + case SMB_ACL_USER:
2759 + case SMB_ACL_USER_OBJ:
2760 + case SMB_ACL_GROUP:
2761 + case SMB_ACL_GROUP_OBJ:
2762 + case SMB_ACL_OTHER:
2763 + case SMB_ACL_MASK:
2764 + entry_d->a_type = tag_type;
2774 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2776 + if (entry_d->a_type != SMB_ACL_GROUP
2777 + && entry_d->a_type != SMB_ACL_USER) {
2782 + entry_d->a_id = *((id_t *)qual_p);
2787 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2789 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2793 + entry_d->a_perm = *permset_d;
2798 +/* Structure to capture the count for each type of ACE. */
2800 +struct hpux_acl_types {
2804 + int n_def_user_obj;
2809 + int n_def_group_obj;
2813 + int n_def_other_obj;
2816 + int n_def_class_obj;
2818 + int n_illegal_obj;
2822 + * Counts the different number of objects in a given array of ACL
2826 + * acl_count - Count of ACLs in the array of ACL strucutres.
2827 + * aclp - Array of ACL structures.
2828 + * acl_type_count - Pointer to acl_types structure. Should already be
2832 + * acl_type_count - This structure is filled up with counts of various
2836 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2840 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
2842 + for(i=0;i<acl_count;i++) {
2843 + switch(aclp[i].a_type) {
2845 + acl_type_count->n_user++;
2848 + acl_type_count->n_user_obj++;
2850 + case DEF_USER_OBJ:
2851 + acl_type_count->n_def_user_obj++;
2854 + acl_type_count->n_group++;
2857 + acl_type_count->n_group_obj++;
2859 + case DEF_GROUP_OBJ:
2860 + acl_type_count->n_def_group_obj++;
2863 + acl_type_count->n_other_obj++;
2865 + case DEF_OTHER_OBJ:
2866 + acl_type_count->n_def_other_obj++;
2869 + acl_type_count->n_class_obj++;
2871 + case DEF_CLASS_OBJ:
2872 + acl_type_count->n_def_class_obj++;
2875 + acl_type_count->n_def_user++;
2878 + acl_type_count->n_def_group++;
2881 + acl_type_count->n_illegal_obj++;
2887 +/* swap_acl_entries: Swaps two ACL entries.
2889 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
2892 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
2894 + struct acl temp_acl;
2896 + temp_acl.a_type = aclp0->a_type;
2897 + temp_acl.a_id = aclp0->a_id;
2898 + temp_acl.a_perm = aclp0->a_perm;
2900 + aclp0->a_type = aclp1->a_type;
2901 + aclp0->a_id = aclp1->a_id;
2902 + aclp0->a_perm = aclp1->a_perm;
2904 + aclp1->a_type = temp_acl.a_type;
2905 + aclp1->a_id = temp_acl.a_id;
2906 + aclp1->a_perm = temp_acl.a_perm;
2909 +/* prohibited_duplicate_type
2910 + * Identifies if given ACL type can have duplicate entries or
2913 + * Inputs: acl_type - ACL Type.
2919 + * True - If the ACL type matches any of the prohibited types.
2920 + * False - If the ACL type doesn't match any of the prohibited types.
2923 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
2925 + switch(acl_type) {
2936 +/* get_needed_class_perm
2937 + * Returns the permissions of a ACL structure only if the ACL
2938 + * type matches one of the pre-determined types for computing
2939 + * CLASS_OBJ permissions.
2941 + * Inputs: aclp - Pointer to ACL structure.
2944 +static int hpux_get_needed_class_perm(struct acl *aclp)
2946 + switch(aclp->a_type) {
2950 + case DEF_USER_OBJ:
2952 + case DEF_GROUP_OBJ:
2954 + case DEF_CLASS_OBJ:
2955 + case DEF_OTHER_OBJ:
2956 + return aclp->a_perm;
2962 +/* acl_sort for HPUX.
2963 + * Sorts the array of ACL structures as per the description in
2964 + * aclsort man page. Refer to aclsort man page for more details
2968 + * acl_count - Count of ACLs in the array of ACL structures.
2969 + * calclass - If this is not zero, then we compute the CLASS_OBJ
2971 + * aclp - Array of ACL structures.
2975 + * aclp - Sorted array of ACL structures.
2979 + * Returns 0 for success -1 for failure. Prints a message to the Samba
2980 + * debug log in case of failure.
2983 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
2985 +#if !defined(HAVE_HPUX_ACLSORT)
2987 + * The aclsort() system call is availabe on the latest HPUX General
2988 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
2989 + * function. Because, we don't want to update to a new
2990 + * HPUX GR bundle just for aclsort() call.
2993 + struct hpux_acl_types acl_obj_count;
2994 + int n_class_obj_perm = 0;
2998 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3002 + if(aclp == NULL) {
3003 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3007 + /* Count different types of ACLs in the ACLs array */
3009 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3011 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3012 + * CLASS_OBJ and OTHER_OBJ
3015 + if( (acl_obj_count.n_user_obj != 1) ||
3016 + (acl_obj_count.n_group_obj != 1) ||
3017 + (acl_obj_count.n_class_obj != 1) ||
3018 + (acl_obj_count.n_other_obj != 1)
3020 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3021 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3025 + /* If any of the default objects are present, there should be only
3026 + * one of them each.
3029 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3030 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3031 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3032 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3036 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3039 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3040 + * same ACL type, sort by ACL id.
3042 + * I am using the trival kind of sorting method here because, performance isn't
3043 + * really effected by the ACLs feature. More over there aren't going to be more
3044 + * than 17 entries on HPUX.
3047 + for(i=0; i<acl_count;i++) {
3048 + for (j=i+1; j<acl_count; j++) {
3049 + if( aclp[i].a_type > aclp[j].a_type ) {
3050 + /* ACL entries out of order, swap them */
3052 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3054 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3056 + /* ACL entries of same type, sort by id */
3058 + if(aclp[i].a_id > aclp[j].a_id) {
3059 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3060 + } else if (aclp[i].a_id == aclp[j].a_id) {
3061 + /* We have a duplicate entry. */
3062 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3063 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3064 + aclp[i].a_type, aclp[i].a_id));
3073 + /* set the class obj permissions to the computed one. */
3075 + int n_class_obj_index = -1;
3077 + for(i=0;i<acl_count;i++) {
3078 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3080 + if(aclp[i].a_type == CLASS_OBJ)
3081 + n_class_obj_index = i;
3083 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3088 + return aclsort(acl_count, calclass, aclp);
3093 + * sort the ACL and check it for validity
3095 + * if it's a minimal ACL with only 4 entries then we
3096 + * need to recalculate the mask permissions to make
3097 + * sure that they are the same as the GROUP_OBJ
3098 + * permissions as required by the UnixWare acl() system call.
3100 + * (note: since POSIX allows minimal ACLs which only contain
3101 + * 3 entries - ie there is no mask entry - we should, in theory,
3102 + * check for this and add a mask entry if necessary - however
3103 + * we "know" that the caller of this interface always specifies
3104 + * a mask so, in practice "this never happens" (tm) - if it *does*
3105 + * happen aclsort() will fail and return an error and someone will
3106 + * have to fix it ...)
3109 +static int acl_sort(SMB_ACL_T acl_d)
3111 + int fixmask = (acl_d->count <= 4);
3113 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3120 +int sys_acl_valid(SMB_ACL_T acl_d)
3122 + return acl_sort(acl_d);
3125 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3128 + struct acl *acl_p;
3130 + struct acl *acl_buf = NULL;
3133 + if(hpux_acl_call_presence() == False) {
3134 + /* Looks like we don't have the acl() system call on HPUX.
3135 + * May be the system doesn't have the latest version of JFS.
3141 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3146 + if (acl_sort(acl_d) != 0) {
3150 + acl_p = &acl_d->acl[0];
3151 + acl_count = acl_d->count;
3154 + * if it's a directory there is extra work to do
3155 + * since the acl() system call will replace both
3156 + * the access ACLs and the default ACLs (if any)
3158 + if (stat(name, &s) != 0) {
3161 + if (S_ISDIR(s.st_mode)) {
3162 + SMB_ACL_T acc_acl;
3163 + SMB_ACL_T def_acl;
3164 + SMB_ACL_T tmp_acl;
3167 + if (type == SMB_ACL_TYPE_ACCESS) {
3169 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3173 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3176 + if (tmp_acl == NULL) {
3181 + * allocate a temporary buffer for the complete ACL
3183 + acl_count = acc_acl->count + def_acl->count;
3184 + acl_p = acl_buf = malloc(acl_count * sizeof(acl_buf[0]));
3186 + if (acl_buf == NULL) {
3187 + sys_acl_free_acl(tmp_acl);
3193 + * copy the access control and default entries into the buffer
3195 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3196 + acc_acl->count * sizeof(acl_buf[0]));
3198 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3199 + def_acl->count * sizeof(acl_buf[0]));
3202 + * set the ACL_DEFAULT flag on the default entries
3204 + for (i = acc_acl->count; i < acl_count; i++) {
3205 + acl_buf[i].a_type |= ACL_DEFAULT;
3208 + sys_acl_free_acl(tmp_acl);
3210 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3215 + ret = acl(name, ACL_SET, acl_count, acl_p);
3224 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3227 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3230 + files_struct *fsp = file_find_fd(fd);
3232 + if (fsp == NULL) {
3237 + if (acl_sort(acl_d) != 0) {
3242 + * We know we're in the same conn context. So we
3243 + * can use the relative path.
3246 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3249 +int sys_acl_delete_def_file(const char *path)
3255 + * fetching the access ACL and rewriting it has
3256 + * the effect of deleting the default ACL
3258 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3262 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3264 + sys_acl_free_acl(acl_d);
3269 +int sys_acl_free_text(char *text)
3275 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3281 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3286 +#elif defined(HAVE_IRIX_ACLS)
3288 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3290 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3295 + if (entry_p == NULL) {
3300 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3304 + if (acl_d->next < 0) {
3309 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3313 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3318 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3320 + *type_p = entry_d->ae_tag;
3325 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3327 + *permset_p = entry_d;
3332 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3334 + if (entry_d->ae_tag != SMB_ACL_USER
3335 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3340 + return &entry_d->ae_id;
3343 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3347 + if ((a = malloc(sizeof(*a))) == NULL) {
3351 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3356 + a->freeaclp = True;
3360 +SMB_ACL_T sys_acl_get_fd(int fd)
3364 + if ((a = malloc(sizeof(*a))) == NULL) {
3368 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3373 + a->freeaclp = True;
3377 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3379 + permset_d->ae_perm = 0;
3384 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3386 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3387 + && perm != SMB_ACL_EXECUTE) {
3392 + if (permset_d == NULL) {
3397 + permset_d->ae_perm |= perm;
3402 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3404 + return permset_d->ae_perm & perm;
3407 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3409 + return acl_to_text(acl_d->aclp, len_p);
3412 +SMB_ACL_T sys_acl_init(int count)
3421 + if ((a = malloc(sizeof(*a) + sizeof(struct acl))) == NULL) {
3427 + a->freeaclp = False;
3428 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3429 + a->aclp->acl_cnt = 0;
3435 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3438 + SMB_ACL_ENTRY_T entry_d;
3440 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3445 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3450 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3451 + entry_d->ae_tag = 0;
3452 + entry_d->ae_id = 0;
3453 + entry_d->ae_perm = 0;
3454 + *entry_p = entry_d;
3459 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3461 + switch (tag_type) {
3462 + case SMB_ACL_USER:
3463 + case SMB_ACL_USER_OBJ:
3464 + case SMB_ACL_GROUP:
3465 + case SMB_ACL_GROUP_OBJ:
3466 + case SMB_ACL_OTHER:
3467 + case SMB_ACL_MASK:
3468 + entry_d->ae_tag = tag_type;
3478 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3480 + if (entry_d->ae_tag != SMB_ACL_GROUP
3481 + && entry_d->ae_tag != SMB_ACL_USER) {
3486 + entry_d->ae_id = *((id_t *)qual_p);
3491 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3493 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3497 + entry_d->ae_perm = permset_d->ae_perm;
3502 +int sys_acl_valid(SMB_ACL_T acl_d)
3504 + return acl_valid(acl_d->aclp);
3507 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3509 + return acl_set_file(name, type, acl_d->aclp);
3512 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3514 + return acl_set_fd(fd, acl_d->aclp);
3517 +int sys_acl_delete_def_file(const char *name)
3519 + return acl_delete_def_file(name);
3522 +int sys_acl_free_text(char *text)
3524 + return acl_free(text);
3527 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3529 + if (acl_d->freeaclp) {
3530 + acl_free(acl_d->aclp);
3536 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3541 +#elif defined(HAVE_AIX_ACLS)
3543 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3545 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3547 + struct acl_entry_link *link;
3548 + struct new_acl_entry *entry;
3551 + DEBUG(10,("This is the count: %d\n",theacl->count));
3553 + /* Check if count was previously set to -1. *
3554 + * If it was, that means we reached the end *
3555 + * of the acl last time. */
3556 + if(theacl->count == -1)
3560 + /* To get to the next acl, traverse linked list until index *
3561 + * of acl matches the count we are keeping. This count is *
3562 + * incremented each time we return an acl entry. */
3564 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3565 + link = link->nextp;
3567 + entry = *entry_p = link->entryp;
3569 + DEBUG(10,("*entry_p is %d\n",entry_p));
3570 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3572 + /* Increment count */
3574 + if(link->nextp == NULL)
3575 + theacl->count = -1;
3580 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3582 + /* Initialize tag type */
3585 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3587 + /* Depending on what type of entry we have, *
3588 + * return tag type. */
3589 + switch(entry_d->ace_id->id_type) {
3591 + *tag_type_p = SMB_ACL_USER;
3594 + *tag_type_p = SMB_ACL_GROUP;
3597 + case SMB_ACL_USER_OBJ:
3598 + case SMB_ACL_GROUP_OBJ:
3599 + case SMB_ACL_OTHER:
3600 + *tag_type_p = entry_d->ace_id->id_type;
3610 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3612 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3613 + *permset_p = &entry_d->ace_access;
3614 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3615 + if(!(**permset_p & S_IXUSR) &&
3616 + !(**permset_p & S_IWUSR) &&
3617 + !(**permset_p & S_IRUSR) &&
3618 + (**permset_p != 0))
3621 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3625 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3627 + return(entry_d->ace_id->id_data);
3630 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3632 + struct acl *file_acl = (struct acl *)NULL;
3633 + struct acl_entry *acl_entry;
3634 + struct new_acl_entry *new_acl_entry;
3635 + struct ace_id *idp;
3636 + struct acl_entry_link *acl_entry_link;
3637 + struct acl_entry_link *acl_entry_link_head;
3642 + /* Get the acl using statacl */
3644 + DEBUG(10,("Entering sys_acl_get_file\n"));
3645 + DEBUG(10,("path_p is %s\n",path_p));
3647 + file_acl = (struct acl *)malloc(BUFSIZ);
3649 + if(file_acl == NULL) {
3651 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3655 + memset(file_acl,0,BUFSIZ);
3657 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3659 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3660 + SAFE_FREE(file_acl);
3664 + DEBUG(10,("Got facl and returned it\n"));
3666 + /* Point to the first acl entry in the acl */
3667 + acl_entry = file_acl->acl_ext;
3669 + /* Begin setting up the head of the linked list *
3670 + * that will be used for the storing the acl *
3671 + * in a way that is useful for the posix_acls.c *
3674 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3675 + if(acl_entry_link_head == NULL)
3678 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
3679 + if(acl_entry_link->entryp == NULL) {
3680 + SAFE_FREE(file_acl);
3682 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3686 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3687 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3689 + /* Check if the extended acl bit is on. *
3690 + * If it isn't, do not show the *
3691 + * contents of the acl since AIX intends *
3692 + * the extended info to remain unused */
3694 + if(file_acl->acl_mode & S_IXACL){
3695 + /* while we are not pointing to the very end */
3696 + while(acl_entry < acl_last(file_acl)) {
3697 + /* before we malloc anything, make sure this is */
3698 + /* a valid acl entry and one that we want to map */
3699 + idp = id_nxt(acl_entry->ace_id);
3700 + if((acl_entry->ace_type == ACC_SPECIFY ||
3701 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3702 + acl_entry = acl_nxt(acl_entry);
3706 + idp = acl_entry->ace_id;
3708 + /* Check if this is the first entry in the linked list. *
3709 + * The first entry needs to keep prevp pointing to NULL *
3710 + * and already has entryp allocated. */
3712 + if(acl_entry_link_head->count != 0) {
3713 + acl_entry_link->nextp = (struct acl_entry_link *)
3714 + malloc(sizeof(struct acl_entry_link));
3716 + if(acl_entry_link->nextp == NULL) {
3717 + SAFE_FREE(file_acl);
3719 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3723 + acl_entry_link->nextp->prevp = acl_entry_link;
3724 + acl_entry_link = acl_entry_link->nextp;
3725 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
3726 + if(acl_entry_link->entryp == NULL) {
3727 + SAFE_FREE(file_acl);
3729 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3732 + acl_entry_link->nextp = NULL;
3735 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3737 + /* Don't really need this since all types are going *
3738 + * to be specified but, it's better than leaving it 0 */
3740 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3742 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3744 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3746 + /* The access in the acl entries must be left shifted by *
3747 + * three bites, because they will ultimately be compared *
3748 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3750 + switch(acl_entry->ace_type){
3753 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3754 + acl_entry_link->entryp->ace_access <<= 6;
3755 + acl_entry_link_head->count++;
3758 + /* Since there is no way to return a DENY acl entry *
3759 + * change to PERMIT and then shift. */
3760 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3761 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3762 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3763 + acl_entry_link->entryp->ace_access <<= 6;
3764 + acl_entry_link_head->count++;
3770 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3771 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3773 + acl_entry = acl_nxt(acl_entry);
3775 + } /* end of if enabled */
3777 + /* Since owner, group, other acl entries are not *
3778 + * part of the acl entries in an acl, they must *
3779 + * be dummied up to become part of the list. */
3781 + for( i = 1; i < 4; i++) {
3782 + DEBUG(10,("i is %d\n",i));
3783 + if(acl_entry_link_head->count != 0) {
3784 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
3785 + if(acl_entry_link->nextp == NULL) {
3786 + SAFE_FREE(file_acl);
3788 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3792 + acl_entry_link->nextp->prevp = acl_entry_link;
3793 + acl_entry_link = acl_entry_link->nextp;
3794 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
3795 + if(acl_entry_link->entryp == NULL) {
3796 + SAFE_FREE(file_acl);
3798 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3803 + acl_entry_link->nextp = NULL;
3805 + new_acl_entry = acl_entry_link->entryp;
3806 + idp = new_acl_entry->ace_id;
3808 + new_acl_entry->ace_len = sizeof(struct acl_entry);
3809 + new_acl_entry->ace_type = ACC_PERMIT;
3810 + idp->id_len = sizeof(struct ace_id);
3811 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
3812 + memset(idp->id_data,0,sizeof(uid_t));
3816 + new_acl_entry->ace_access = file_acl->g_access << 6;
3817 + idp->id_type = SMB_ACL_GROUP_OBJ;
3821 + new_acl_entry->ace_access = file_acl->o_access << 6;
3822 + idp->id_type = SMB_ACL_OTHER;
3826 + new_acl_entry->ace_access = file_acl->u_access << 6;
3827 + idp->id_type = SMB_ACL_USER_OBJ;
3835 + acl_entry_link_head->count++;
3836 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3839 + acl_entry_link_head->count = 0;
3840 + SAFE_FREE(file_acl);
3842 + return(acl_entry_link_head);
3845 +SMB_ACL_T sys_acl_get_fd(int fd)
3847 + struct acl *file_acl = (struct acl *)NULL;
3848 + struct acl_entry *acl_entry;
3849 + struct new_acl_entry *new_acl_entry;
3850 + struct ace_id *idp;
3851 + struct acl_entry_link *acl_entry_link;
3852 + struct acl_entry_link *acl_entry_link_head;
3857 + /* Get the acl using fstatacl */
3859 + DEBUG(10,("Entering sys_acl_get_fd\n"));
3860 + DEBUG(10,("fd is %d\n",fd));
3861 + file_acl = (struct acl *)malloc(BUFSIZ);
3863 + if(file_acl == NULL) {
3865 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3869 + memset(file_acl,0,BUFSIZ);
3871 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
3873 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
3874 + SAFE_FREE(file_acl);
3878 + DEBUG(10,("Got facl and returned it\n"));
3880 + /* Point to the first acl entry in the acl */
3882 + acl_entry = file_acl->acl_ext;
3883 + /* Begin setting up the head of the linked list *
3884 + * that will be used for the storing the acl *
3885 + * in a way that is useful for the posix_acls.c *
3888 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3889 + if(acl_entry_link_head == NULL){
3890 + SAFE_FREE(file_acl);
3894 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
3896 + if(acl_entry_link->entryp == NULL) {
3898 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3899 + SAFE_FREE(file_acl);
3903 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3904 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3906 + /* Check if the extended acl bit is on. *
3907 + * If it isn't, do not show the *
3908 + * contents of the acl since AIX intends *
3909 + * the extended info to remain unused */
3911 + if(file_acl->acl_mode & S_IXACL){
3912 + /* while we are not pointing to the very end */
3913 + while(acl_entry < acl_last(file_acl)) {
3914 + /* before we malloc anything, make sure this is */
3915 + /* a valid acl entry and one that we want to map */
3917 + idp = id_nxt(acl_entry->ace_id);
3918 + if((acl_entry->ace_type == ACC_SPECIFY ||
3919 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3920 + acl_entry = acl_nxt(acl_entry);
3924 + idp = acl_entry->ace_id;
3926 + /* Check if this is the first entry in the linked list. *
3927 + * The first entry needs to keep prevp pointing to NULL *
3928 + * and already has entryp allocated. */
3930 + if(acl_entry_link_head->count != 0) {
3931 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
3932 + if(acl_entry_link->nextp == NULL) {
3934 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3935 + SAFE_FREE(file_acl);
3938 + acl_entry_link->nextp->prevp = acl_entry_link;
3939 + acl_entry_link = acl_entry_link->nextp;
3940 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
3941 + if(acl_entry_link->entryp == NULL) {
3943 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
3944 + SAFE_FREE(file_acl);
3948 + acl_entry_link->nextp = NULL;
3951 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3953 + /* Don't really need this since all types are going *
3954 + * to be specified but, it's better than leaving it 0 */
3956 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3957 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3959 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
3961 + /* The access in the acl entries must be left shifted by *
3962 + * three bites, because they will ultimately be compared *
3963 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3965 + switch(acl_entry->ace_type){
3968 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3969 + acl_entry_link->entryp->ace_access <<= 6;
3970 + acl_entry_link_head->count++;
3973 + /* Since there is no way to return a DENY acl entry *
3974 + * change to PERMIT and then shift. */
3975 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3976 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3977 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3978 + acl_entry_link->entryp->ace_access <<= 6;
3979 + acl_entry_link_head->count++;
3985 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3986 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3988 + acl_entry = acl_nxt(acl_entry);
3990 + } /* end of if enabled */
3992 + /* Since owner, group, other acl entries are not *
3993 + * part of the acl entries in an acl, they must *
3994 + * be dummied up to become part of the list. */
3996 + for( i = 1; i < 4; i++) {
3997 + DEBUG(10,("i is %d\n",i));
3998 + if(acl_entry_link_head->count != 0){
3999 + acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
4000 + if(acl_entry_link->nextp == NULL) {
4002 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4003 + SAFE_FREE(file_acl);
4007 + acl_entry_link->nextp->prevp = acl_entry_link;
4008 + acl_entry_link = acl_entry_link->nextp;
4009 + acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
4011 + if(acl_entry_link->entryp == NULL) {
4012 + SAFE_FREE(file_acl);
4014 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4019 + acl_entry_link->nextp = NULL;
4021 + new_acl_entry = acl_entry_link->entryp;
4022 + idp = new_acl_entry->ace_id;
4024 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4025 + new_acl_entry->ace_type = ACC_PERMIT;
4026 + idp->id_len = sizeof(struct ace_id);
4027 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4028 + memset(idp->id_data,0,sizeof(uid_t));
4032 + new_acl_entry->ace_access = file_acl->g_access << 6;
4033 + idp->id_type = SMB_ACL_GROUP_OBJ;
4037 + new_acl_entry->ace_access = file_acl->o_access << 6;
4038 + idp->id_type = SMB_ACL_OTHER;
4042 + new_acl_entry->ace_access = file_acl->u_access << 6;
4043 + idp->id_type = SMB_ACL_USER_OBJ;
4050 + acl_entry_link_head->count++;
4051 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4054 + acl_entry_link_head->count = 0;
4055 + SAFE_FREE(file_acl);
4057 + return(acl_entry_link_head);
4060 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4062 + *permset = *permset & ~0777;
4066 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4069 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4073 + DEBUG(10,("This is the permset now: %d\n",*permset));
4077 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4082 +SMB_ACL_T sys_acl_init( int count)
4084 + struct acl_entry_link *theacl = NULL;
4086 + DEBUG(10,("Entering sys_acl_init\n"));
4088 + theacl = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
4089 + if(theacl == NULL) {
4091 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4095 + theacl->count = 0;
4096 + theacl->nextp = NULL;
4097 + theacl->prevp = NULL;
4098 + theacl->entryp = NULL;
4099 + DEBUG(10,("Exiting sys_acl_init\n"));
4103 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4105 + struct acl_entry_link *theacl;
4106 + struct acl_entry_link *acl_entryp;
4107 + struct acl_entry_link *temp_entry;
4110 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4112 + theacl = acl_entryp = *pacl;
4114 + /* Get to the end of the acl before adding entry */
4116 + for(counting=0; counting < theacl->count; counting++){
4117 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4118 + temp_entry = acl_entryp;
4119 + acl_entryp = acl_entryp->nextp;
4122 + if(theacl->count != 0){
4123 + temp_entry->nextp = acl_entryp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
4124 + if(acl_entryp == NULL) {
4126 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4130 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4131 + acl_entryp->prevp = temp_entry;
4132 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4135 + *pentry = acl_entryp->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
4136 + if(*pentry == NULL) {
4138 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4142 + memset(*pentry,0,sizeof(struct new_acl_entry));
4143 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4144 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4145 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4146 + acl_entryp->nextp = NULL;
4148 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4152 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4154 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4155 + entry->ace_id->id_type = tagtype;
4156 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4157 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4160 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4162 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4163 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4164 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4168 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4170 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4171 + if(!(*permset & S_IXUSR) &&
4172 + !(*permset & S_IWUSR) &&
4173 + !(*permset & S_IRUSR) &&
4177 + entry->ace_access = *permset;
4178 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4179 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4183 +int sys_acl_valid( SMB_ACL_T theacl )
4186 + int group_obj = 0;
4187 + int other_obj = 0;
4188 + struct acl_entry_link *acl_entry;
4190 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4191 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4192 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4193 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4196 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4198 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4204 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4206 + struct acl_entry_link *acl_entry_link = NULL;
4207 + struct acl *file_acl = NULL;
4208 + struct acl *file_acl_temp = NULL;
4209 + struct acl_entry *acl_entry = NULL;
4210 + struct ace_id *ace_id = NULL;
4217 + DEBUG(10,("Entering sys_acl_set_file\n"));
4218 + DEBUG(10,("File name is %s\n",name));
4220 + /* AIX has no default ACL */
4221 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4224 + acl_length = BUFSIZ;
4225 + file_acl = (struct acl *)malloc(BUFSIZ);
4227 + if(file_acl == NULL) {
4229 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4233 + memset(file_acl,0,BUFSIZ);
4235 + file_acl->acl_len = ACL_SIZ;
4236 + file_acl->acl_mode = S_IXACL;
4238 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4239 + acl_entry_link->entryp->ace_access >>= 6;
4240 + id_type = acl_entry_link->entryp->ace_id->id_type;
4243 + case SMB_ACL_USER_OBJ:
4244 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4246 + case SMB_ACL_GROUP_OBJ:
4247 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4249 + case SMB_ACL_OTHER:
4250 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4252 + case SMB_ACL_MASK:
4256 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4257 + acl_length += sizeof(struct acl_entry);
4258 + file_acl_temp = (struct acl *)malloc(acl_length);
4259 + if(file_acl_temp == NULL) {
4260 + SAFE_FREE(file_acl);
4262 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4266 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4267 + SAFE_FREE(file_acl);
4268 + file_acl = file_acl_temp;
4271 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4272 + file_acl->acl_len += sizeof(struct acl_entry);
4273 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4274 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4276 + /* In order to use this, we'll need to wait until we can get denies */
4277 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4278 + acl_entry->ace_type = ACC_SPECIFY; */
4280 + acl_entry->ace_type = ACC_SPECIFY;
4282 + ace_id = acl_entry->ace_id;
4284 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4285 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4286 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4287 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4288 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4291 + rc = chacl(name,file_acl,file_acl->acl_len);
4292 + DEBUG(10,("errno is %d\n",errno));
4293 + DEBUG(10,("return code is %d\n",rc));
4294 + SAFE_FREE(file_acl);
4295 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4299 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4301 + struct acl_entry_link *acl_entry_link = NULL;
4302 + struct acl *file_acl = NULL;
4303 + struct acl *file_acl_temp = NULL;
4304 + struct acl_entry *acl_entry = NULL;
4305 + struct ace_id *ace_id = NULL;
4311 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4312 + acl_length = BUFSIZ;
4313 + file_acl = (struct acl *)malloc(BUFSIZ);
4315 + if(file_acl == NULL) {
4317 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4321 + memset(file_acl,0,BUFSIZ);
4323 + file_acl->acl_len = ACL_SIZ;
4324 + file_acl->acl_mode = S_IXACL;
4326 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4327 + acl_entry_link->entryp->ace_access >>= 6;
4328 + id_type = acl_entry_link->entryp->ace_id->id_type;
4329 + DEBUG(10,("The id_type is %d\n",id_type));
4332 + case SMB_ACL_USER_OBJ:
4333 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4335 + case SMB_ACL_GROUP_OBJ:
4336 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4338 + case SMB_ACL_OTHER:
4339 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4341 + case SMB_ACL_MASK:
4345 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4346 + acl_length += sizeof(struct acl_entry);
4347 + file_acl_temp = (struct acl *)malloc(acl_length);
4348 + if(file_acl_temp == NULL) {
4349 + SAFE_FREE(file_acl);
4351 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4355 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4356 + SAFE_FREE(file_acl);
4357 + file_acl = file_acl_temp;
4360 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4361 + file_acl->acl_len += sizeof(struct acl_entry);
4362 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4363 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4365 + /* In order to use this, we'll need to wait until we can get denies */
4366 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4367 + acl_entry->ace_type = ACC_SPECIFY; */
4369 + acl_entry->ace_type = ACC_SPECIFY;
4371 + ace_id = acl_entry->ace_id;
4373 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4374 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4375 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4376 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4377 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4380 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4381 + DEBUG(10,("errno is %d\n",errno));
4382 + DEBUG(10,("return code is %d\n",rc));
4383 + SAFE_FREE(file_acl);
4384 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4388 +int sys_acl_delete_def_file(const char *name)
4390 + /* AIX has no default ACL */
4394 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4396 + return(*permset & perm);
4399 +int sys_acl_free_text(char *text)
4404 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4406 + struct acl_entry_link *acl_entry_link;
4408 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4409 + SAFE_FREE(acl_entry_link->prevp->entryp);
4410 + SAFE_FREE(acl_entry_link->prevp);
4413 + SAFE_FREE(acl_entry_link->prevp->entryp);
4414 + SAFE_FREE(acl_entry_link->prevp);
4415 + SAFE_FREE(acl_entry_link->entryp);
4416 + SAFE_FREE(acl_entry_link);
4421 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4426 +#else /* No ACLs. */
4428 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
4434 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
4440 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
4446 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
4452 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
4455 + return (SMB_ACL_T)NULL;
4458 +SMB_ACL_T sys_acl_get_fd(int fd)
4461 + return (SMB_ACL_T)NULL;
4464 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4470 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4476 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4479 + return (permset & perm) ? 1 : 0;
4482 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
4488 +int sys_acl_free_text(char *text)
4494 +SMB_ACL_T sys_acl_init( int count)
4500 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4506 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4512 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4518 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4524 +int sys_acl_valid( SMB_ACL_T theacl )
4530 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4536 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4542 +int sys_acl_delete_def_file(const char *name)
4548 +int sys_acl_free_acl(SMB_ACL_T the_acl)
4554 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4560 +#endif /* No ACLs. */
4561 --- orig/lib/sysacls.h 2004-10-20 15:31:22
4562 +++ lib/sysacls.h 2004-10-20 15:31:22
4564 +#define Realloc(mem, cnt) realloc_array((mem), char, (cnt))
4565 +#define slprintf snprintf
4567 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4568 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4569 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4570 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4571 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4572 +SMB_ACL_T sys_acl_get_fd(int fd);
4573 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4574 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4575 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4576 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4577 +SMB_ACL_T sys_acl_init(int count);
4578 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4579 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4580 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4581 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4582 +int sys_acl_valid(SMB_ACL_T theacl);
4583 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4584 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4585 +int sys_acl_delete_def_file(const char *name);
4586 +int sys_acl_free_text(char *text);
4587 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4588 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4589 --- orig/mkproto.awk 2005-02-18 20:17:35
4590 +++ mkproto.awk 2005-02-18 20:18:17
4591 @@ -58,7 +58,7 @@ BEGIN {
4595 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const/ {
4596 +!/^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/ {
4600 --- orig/options.c 2005-02-18 18:02:45
4601 +++ options.c 2005-02-14 02:46:05
4602 @@ -44,6 +44,7 @@ int keep_dirlinks = 0;
4604 int preserve_links = 0;
4605 int preserve_hard_links = 0;
4606 +int preserve_acls = 0;
4607 int preserve_perms = 0;
4608 int preserve_devices = 0;
4609 int preserve_uid = 0;
4610 @@ -169,6 +170,7 @@ static void print_rsync_version(enum log
4611 char const *got_socketpair = "no ";
4612 char const *have_inplace = "no ";
4613 char const *hardlinks = "no ";
4614 + char const *acls = "no ";
4615 char const *links = "no ";
4616 char const *ipv6 = "no ";
4617 STRUCT_STAT *dumstat;
4618 @@ -185,6 +187,10 @@ static void print_rsync_version(enum log
4622 +#ifdef SUPPORT_ACLS
4626 #ifdef SUPPORT_LINKS
4629 @@ -199,9 +205,9 @@ static void print_rsync_version(enum log
4630 "Copyright (C) 1996-2005 by Andrew Tridgell and others\n");
4631 rprintf(f, "<http://rsync.samba.org/>\n");
4632 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4633 - "%shard links, %ssymlinks, batchfiles, \n",
4634 + "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
4635 (int) (sizeof (OFF_T) * 8),
4636 - got_socketpair, hardlinks, links);
4637 + got_socketpair, hardlinks, acls, links);
4639 /* Note that this field may not have type ino_t. It depends
4640 * on the complicated interaction between largefile feature
4641 @@ -271,6 +277,7 @@ void usage(enum logcode F)
4642 rprintf(F," -H, --hard-links preserve hard links\n");
4643 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
4644 rprintf(F," -p, --perms preserve permissions\n");
4645 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4646 rprintf(F," -o, --owner preserve owner (root only)\n");
4647 rprintf(F," -g, --group preserve group\n");
4648 rprintf(F," -D, --devices preserve devices (root only)\n");
4649 @@ -392,6 +399,7 @@ static struct poptOption long_options[]
4650 {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
4651 {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
4652 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
4653 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4654 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
4655 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
4656 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
4657 @@ -837,6 +845,24 @@ int parse_arguments(int *argc, const cha
4658 basis_dir[basis_dir_cnt++] = (char *)arg;
4663 + preserve_acls = 1;
4664 + preserve_perms = 1;
4666 + /* FIXME: this should probably be ignored with a
4667 + * warning and then countermeasures taken to
4668 + * restrict group and other access in the presence
4669 + * of any more restrictive ACLs, but this is safe
4671 + snprintf(err_buf,sizeof(err_buf),
4672 + "ACLs are not supported on this %s\n",
4673 + am_server ? "server" : "client");
4675 +#endif /* SUPPORT_ACLS */
4680 /* A large opt value means that set_refuse_options()
4681 * turned this option off. */
4682 @@ -1226,6 +1252,8 @@ void server_options(char **args,int *arg
4684 if (preserve_hard_links)
4686 + if (preserve_acls)
4687 + argstr[x++] = 'A';
4691 --- orig/rsync.c 2005-02-14 02:45:10
4692 +++ rsync.c 2004-07-03 20:11:58
4693 @@ -238,6 +238,14 @@ int set_perms(char *fname,struct file_st
4697 + /* If this is a directory, SET_ACL() will be called on the cleanup
4698 + * receive_generator() pass--if we called it here, we might clobber
4699 + * writability on the directory. everything else is OK to do now. */
4700 + if (!S_ISDIR(st->st_mode)) {
4701 + if (SET_ACL(fname, file) == 0)
4705 if (verbose > 1 && flags & PERMS_REPORT) {
4707 rprintf(FINFO, "%s\n", safe_fname(fname));
4708 --- orig/rsync.h 2005-02-16 17:08:13
4709 +++ rsync.h 2004-07-03 20:11:58
4710 @@ -625,6 +625,40 @@ struct stats {
4711 #include "lib/permstring.h"
4712 #include "lib/addrinfo.h"
4714 +#define SUPPORT_ACLS HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4715 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4717 +#define ACLS_NEED_MASK HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4721 +#include <sys/acl.h>
4723 +#define MAKE_ACL(file, fname) make_acl(file, fname)
4724 +#define SEND_ACL(file, f) send_acl(file, f)
4725 +#define RECEIVE_ACL(file, f) receive_acl(file, f)
4726 +#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4727 +#define SET_ACL(fname, file) set_acl(fname, file)
4728 +#define NEXT_ACL_UID() next_acl_uid()
4729 +#define ACL_UID_MAP(uid) acl_uid_map(uid)
4730 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4731 + push_keep_backup_acl(file, orig, dest)
4732 +#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4733 +#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4734 +#else /* SUPPORT_ACLS */
4735 +#define MAKE_ACL(file, fname) 1 /* checked return value */
4736 +#define SEND_ACL(file, f)
4737 +#define RECEIVE_ACL(file, f)
4738 +#define SORT_FILE_ACL_INDEX_LISTS()
4739 +#define SET_ACL(fname, file) 0 /* checked return value */
4740 +#define NEXT_ACL_UID()
4741 +#define ACL_UID_MAP(uid)
4742 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4743 +#define CLEANUP_KEEP_BACKUP_ACL()
4744 +#define DUP_ACL(src, orig, mode) 0 /* checked return value */
4745 +#endif /* SUPPORT_ACLS */
4746 +#include "smb_acls.h"
4750 /* We have replacement versions of these if they're missing. */
4751 --- orig/rsync.yo 2005-02-18 20:17:35
4752 +++ rsync.yo 2004-07-03 20:11:58
4753 @@ -317,6 +317,7 @@ to the detailed description below for a
4754 -H, --hard-links preserve hard links
4755 -K, --keep-dirlinks treat symlinked dir on receiver as dir
4756 -p, --perms preserve permissions
4757 + -A, --acls preserve ACLs (implies -p) [local option]
4758 -o, --owner preserve owner (root only)
4759 -g, --group preserve group
4760 -D, --devices preserve devices (root only)
4761 @@ -624,6 +625,11 @@ source file's permissions and the umask
4762 other files (including updated files) retain their existing permissions
4763 (which is the same behavior as other file-copy utilities, such as cp).
4765 +dit(bf(-A, --acls)) This option causes rsync to update the remote
4766 +ACLs to be the same as the local ACLs. This will work only if the
4767 +remote machine's rsync supports this option also. This is a non-standard
4770 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
4771 destination file to be the same as the source file. On most systems,
4772 only the super-user can set file ownership. By default, the preservation
4773 --- orig/smb_acls.h 2004-06-30 00:04:07
4774 +++ smb_acls.h 2004-06-30 00:04:07
4777 + Unix SMB/Netbios implementation.
4779 + Portable SMB ACL interface
4780 + Copyright (C) Jeremy Allison 2000
4782 + This program is free software; you can redistribute it and/or modify
4783 + it under the terms of the GNU General Public License as published by
4784 + the Free Software Foundation; either version 2 of the License, or
4785 + (at your option) any later version.
4787 + This program is distributed in the hope that it will be useful,
4788 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4789 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4790 + GNU General Public License for more details.
4792 + You should have received a copy of the GNU General Public License
4793 + along with this program; if not, write to the Free Software
4794 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4797 +#ifndef _SMB_ACLS_H
4798 +#define _SMB_ACLS_H
4800 +#if defined(HAVE_POSIX_ACLS)
4802 +/* This is an identity mapping (just remove the SMB_). */
4804 +#define SMB_ACL_TAG_T acl_tag_t
4805 +#define SMB_ACL_TYPE_T acl_type_t
4806 +#define SMB_ACL_PERMSET_T acl_permset_t
4807 +#define SMB_ACL_PERM_T acl_perm_t
4808 +#define SMB_ACL_READ ACL_READ
4809 +#define SMB_ACL_WRITE ACL_WRITE
4810 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4812 +/* Types of ACLs. */
4813 +#define SMB_ACL_USER ACL_USER
4814 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4815 +#define SMB_ACL_GROUP ACL_GROUP
4816 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4817 +#define SMB_ACL_OTHER ACL_OTHER
4818 +#define SMB_ACL_MASK ACL_MASK
4820 +#define SMB_ACL_T acl_t
4822 +#define SMB_ACL_ENTRY_T acl_entry_t
4824 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
4825 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
4827 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4828 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4830 +#elif defined(HAVE_TRU64_ACLS)
4832 +/* This is for DEC/Compaq Tru64 UNIX */
4834 +#define SMB_ACL_TAG_T acl_tag_t
4835 +#define SMB_ACL_TYPE_T acl_type_t
4836 +#define SMB_ACL_PERMSET_T acl_permset_t
4837 +#define SMB_ACL_PERM_T acl_perm_t
4838 +#define SMB_ACL_READ ACL_READ
4839 +#define SMB_ACL_WRITE ACL_WRITE
4840 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4842 +/* Types of ACLs. */
4843 +#define SMB_ACL_USER ACL_USER
4844 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4845 +#define SMB_ACL_GROUP ACL_GROUP
4846 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4847 +#define SMB_ACL_OTHER ACL_OTHER
4848 +#define SMB_ACL_MASK ACL_MASK
4850 +#define SMB_ACL_T acl_t
4852 +#define SMB_ACL_ENTRY_T acl_entry_t
4854 +#define SMB_ACL_FIRST_ENTRY 0
4855 +#define SMB_ACL_NEXT_ENTRY 1
4857 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4858 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4860 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
4862 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
4863 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
4866 +/* SVR4.2 ES/MP ACLs */
4867 +typedef int SMB_ACL_TAG_T;
4868 +typedef int SMB_ACL_TYPE_T;
4869 +typedef ushort *SMB_ACL_PERMSET_T;
4870 +typedef ushort SMB_ACL_PERM_T;
4871 +#define SMB_ACL_READ 4
4872 +#define SMB_ACL_WRITE 2
4873 +#define SMB_ACL_EXECUTE 1
4875 +/* Types of ACLs. */
4876 +#define SMB_ACL_USER USER
4877 +#define SMB_ACL_USER_OBJ USER_OBJ
4878 +#define SMB_ACL_GROUP GROUP
4879 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
4880 +#define SMB_ACL_OTHER OTHER_OBJ
4881 +#define SMB_ACL_MASK CLASS_OBJ
4883 +typedef struct SMB_ACL_T {
4887 + struct acl acl[1];
4890 +typedef struct acl *SMB_ACL_ENTRY_T;
4892 +#define SMB_ACL_FIRST_ENTRY 0
4893 +#define SMB_ACL_NEXT_ENTRY 1
4895 +#define SMB_ACL_TYPE_ACCESS 0
4896 +#define SMB_ACL_TYPE_DEFAULT 1
4898 +#elif defined(HAVE_HPUX_ACLS)
4901 + * Based on the Solaris & UnixWare code.
4905 +#include <sys/aclv.h>
4907 +/* SVR4.2 ES/MP ACLs */
4908 +typedef int SMB_ACL_TAG_T;
4909 +typedef int SMB_ACL_TYPE_T;
4910 +typedef ushort *SMB_ACL_PERMSET_T;
4911 +typedef ushort SMB_ACL_PERM_T;
4912 +#define SMB_ACL_READ 4
4913 +#define SMB_ACL_WRITE 2
4914 +#define SMB_ACL_EXECUTE 1
4916 +/* Types of ACLs. */
4917 +#define SMB_ACL_USER USER
4918 +#define SMB_ACL_USER_OBJ USER_OBJ
4919 +#define SMB_ACL_GROUP GROUP
4920 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
4921 +#define SMB_ACL_OTHER OTHER_OBJ
4922 +#define SMB_ACL_MASK CLASS_OBJ
4924 +typedef struct SMB_ACL_T {
4928 + struct acl acl[1];
4931 +typedef struct acl *SMB_ACL_ENTRY_T;
4933 +#define SMB_ACL_FIRST_ENTRY 0
4934 +#define SMB_ACL_NEXT_ENTRY 1
4936 +#define SMB_ACL_TYPE_ACCESS 0
4937 +#define SMB_ACL_TYPE_DEFAULT 1
4939 +#elif defined(HAVE_IRIX_ACLS)
4941 +#define SMB_ACL_TAG_T acl_tag_t
4942 +#define SMB_ACL_TYPE_T acl_type_t
4943 +#define SMB_ACL_PERMSET_T acl_permset_t
4944 +#define SMB_ACL_PERM_T acl_perm_t
4945 +#define SMB_ACL_READ ACL_READ
4946 +#define SMB_ACL_WRITE ACL_WRITE
4947 +#define SMB_ACL_EXECUTE ACL_EXECUTE
4949 +/* Types of ACLs. */
4950 +#define SMB_ACL_USER ACL_USER
4951 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
4952 +#define SMB_ACL_GROUP ACL_GROUP
4953 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
4954 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
4955 +#define SMB_ACL_MASK ACL_MASK
4957 +typedef struct SMB_ACL_T {
4963 +#define SMB_ACL_ENTRY_T acl_entry_t
4965 +#define SMB_ACL_FIRST_ENTRY 0
4966 +#define SMB_ACL_NEXT_ENTRY 1
4968 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
4969 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
4971 +#elif defined(HAVE_AIX_ACLS)
4973 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
4975 +#include "/usr/include/acl.h"
4977 +typedef uint *SMB_ACL_PERMSET_T;
4979 +struct acl_entry_link{
4980 + struct acl_entry_link *prevp;
4981 + struct new_acl_entry *entryp;
4982 + struct acl_entry_link *nextp;
4986 +struct new_acl_entry{
4987 + unsigned short ace_len;
4988 + unsigned short ace_type;
4989 + unsigned int ace_access;
4990 + struct ace_id ace_id[1];
4993 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
4994 +#define SMB_ACL_T struct acl_entry_link*
4996 +#define SMB_ACL_TAG_T unsigned short
4997 +#define SMB_ACL_TYPE_T int
4998 +#define SMB_ACL_PERM_T uint
4999 +#define SMB_ACL_READ S_IRUSR
5000 +#define SMB_ACL_WRITE S_IWUSR
5001 +#define SMB_ACL_EXECUTE S_IXUSR
5003 +/* Types of ACLs. */
5004 +#define SMB_ACL_USER ACEID_USER
5005 +#define SMB_ACL_USER_OBJ 3
5006 +#define SMB_ACL_GROUP ACEID_GROUP
5007 +#define SMB_ACL_GROUP_OBJ 4
5008 +#define SMB_ACL_OTHER 5
5009 +#define SMB_ACL_MASK 6
5012 +#define SMB_ACL_FIRST_ENTRY 1
5013 +#define SMB_ACL_NEXT_ENTRY 2
5015 +#define SMB_ACL_TYPE_ACCESS 0
5016 +#define SMB_ACL_TYPE_DEFAULT 1
5018 +#else /* No ACLs. */
5020 +/* No ACLS - fake it. */
5021 +#define SMB_ACL_TAG_T int
5022 +#define SMB_ACL_TYPE_T int
5023 +#define SMB_ACL_PERMSET_T mode_t
5024 +#define SMB_ACL_PERM_T mode_t
5025 +#define SMB_ACL_READ S_IRUSR
5026 +#define SMB_ACL_WRITE S_IWUSR
5027 +#define SMB_ACL_EXECUTE S_IXUSR
5029 +/* Types of ACLs. */
5030 +#define SMB_ACL_USER 0
5031 +#define SMB_ACL_USER_OBJ 1
5032 +#define SMB_ACL_GROUP 2
5033 +#define SMB_ACL_GROUP_OBJ 3
5034 +#define SMB_ACL_OTHER 4
5035 +#define SMB_ACL_MASK 5
5037 +typedef struct SMB_ACL_T {
5041 +typedef struct SMB_ACL_ENTRY_T {
5043 +} *SMB_ACL_ENTRY_T;
5045 +#define SMB_ACL_FIRST_ENTRY 0
5046 +#define SMB_ACL_NEXT_ENTRY 1
5048 +#define SMB_ACL_TYPE_ACCESS 0
5049 +#define SMB_ACL_TYPE_DEFAULT 1
5051 +#endif /* No ACLs. */
5052 +#endif /* _SMB_ACLS_H */
5053 --- orig/uidlist.c 2005-02-14 02:45:11
5054 +++ uidlist.c 2004-07-03 20:11:58
5057 extern int preserve_uid;
5058 extern int preserve_gid;
5059 +extern int preserve_acls;
5060 extern int numeric_ids;
5063 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5067 - if (preserve_uid) {
5068 + if (preserve_uid || preserve_acls) {
5070 /* we send sequences of uid/byte-length/name */
5071 for (list = uidlist; list; list = list->next) {
5072 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5076 - if (preserve_gid) {
5077 + if (preserve_gid || preserve_acls) {
5079 for (list = gidlist; list; list = list->next) {
5081 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5085 - if (preserve_uid && !numeric_ids) {
5086 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5087 /* read the uid list */
5088 while ((id = read_int(f)) != 0) {
5089 int len = read_byte(f);
5090 @@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
5094 - if (preserve_gid && !numeric_ids) {
5095 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5096 /* read the gid list */
5097 while ((id = read_int(f)) != 0) {
5098 int len = read_byte(f);
5099 @@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li
5104 + if (preserve_acls && !numeric_ids) {
5106 + /* the enumerations don't return 0 except to flag the last
5107 + * entry, since uidlist doesn't munge 0 anyway */
5108 + while ((id = next_acl_uid(flist)))
5109 + acl_uid_map(match_uid(id));
5110 + while ((id = next_acl_gid(flist)))
5111 + acl_gid_map(match_gid(id));
5113 +#endif /* SUPPORT_ACLS */
5115 /* now convert the uid/gid of all files in the list to the mapped
5117 if (am_root && preserve_uid && !numeric_ids) {