1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 See the --acls (-A) option in the revised man page for a note on using this
8 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
12 - The -i option does not yet itemize changes in ACL information.
14 - The --link-dest option might link together two files that differ just
15 in their ACL info, and if that happens the file in the --link-dest dir
16 would get its ACLs updated.
20 @@ -25,15 +25,15 @@ VERSION=@VERSION@
24 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
25 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
26 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
27 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
28 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
29 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
30 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
31 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
32 main.o checksum.o match.o syscall.o log.o backup.o
33 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
34 - fileio.o batch.o clientname.o chmod.o
35 + fileio.o batch.o clientname.o chmod.o acls.o
36 OBJS3=progress.o pipe.o
37 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
38 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
42 +/* -*- c-file-style: "linux" -*-
43 + Copyright (C) Andrew Tridgell 1996
44 + Copyright (C) Paul Mackerras 1996
45 + Copyright (C) Matt McCutchen 2006
46 + Copyright (C) Wayne Davison 2006
48 + This program is free software; you can redistribute it and/or modify
49 + it under the terms of the GNU General Public License as published by
50 + the Free Software Foundation; either version 2 of the License, or
51 + (at your option) any later version.
53 + This program is distributed in the hope that it will be useful,
54 + but WITHOUT ANY WARRANTY; without even the implied warranty of
55 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 + GNU General Public License for more details.
58 + You should have received a copy of the GNU General Public License
59 + along with this program; if not, write to the Free Software
60 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
63 +/* handle passing ACLs between systems */
66 +#include "lib/sysacls.h"
72 +extern int orig_umask;
73 +extern int preserve_acls;
86 +#define ACL_NO_ENTRY ((uchar)0x80)
90 + /* These will be ACL_NO_ENTRY if there's no such entry. */
97 +static const rsync_acl rsync_acl_initializer = {
98 + {0, 0, NULL}, {0, 0, NULL},
99 + ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY
102 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
103 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
105 +/* a few useful calculations */
107 +static int count_racl_entries(const rsync_acl *racl)
109 + return racl->users.count + racl->groups.count
110 + + (racl->user_obj != ACL_NO_ENTRY)
111 + + (racl->group_obj != ACL_NO_ENTRY)
112 + + (racl->mask != ACL_NO_ENTRY)
113 + + (racl->other != ACL_NO_ENTRY);
116 +static int calc_sacl_entries(const rsync_acl *racl)
118 + return racl->users.count + racl->groups.count
119 +#ifdef ACLS_NEED_MASK
122 + + (racl->mask != ACL_NO_ENTRY) + 3;
126 +static int rsync_acl_get_perms(const rsync_acl *racl)
128 + /* Note that (ACL_NO_ENTRY & 7) is 0. */
129 + return ((racl->user_obj & 7) << 6)
130 + + (((racl->mask != ACL_NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
131 + + (racl->other & 7);
134 +static void rsync_acl_strip_perms(rsync_acl *racl)
136 + racl->user_obj = ACL_NO_ENTRY;
137 + if (racl->mask == ACL_NO_ENTRY)
138 + racl->group_obj = ACL_NO_ENTRY;
140 + racl->mask = ACL_NO_ENTRY;
141 + racl->other = ACL_NO_ENTRY;
144 +static void expand_ida_list(ida_list *idal)
146 + /* First time through, 0 <= 0, so list is expanded. */
147 + if (idal->malloced <= idal->count) {
148 + id_access *new_ptr;
149 + size_t new_size = idal->malloced + 10;
150 + new_ptr = realloc_array(idal->idas, id_access, new_size);
151 + if (verbose >= 4) {
152 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
153 + (double) new_size * sizeof idal->idas[0],
154 + idal->idas ? "" : " not");
157 + idal->idas = new_ptr;
158 + idal->malloced = new_size;
161 + out_of_memory("expand_ida_list");
165 +static void ida_list_free(ida_list *idal)
170 + idal->malloced = 0;
173 +static void rsync_acl_free(rsync_acl *racl)
175 + ida_list_free(&racl->users);
176 + ida_list_free(&racl->groups);
179 +static int id_access_sorter(const void *r1, const void *r2)
181 + id_access *ida1 = (id_access *)r1;
182 + id_access *ida2 = (id_access *)r2;
183 + id_t rid1 = ida1->id, rid2 = ida2->id;
184 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
187 +static void sort_ida_list(ida_list *idal)
191 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
192 + &id_access_sorter);
195 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
197 + SMB_ACL_ENTRY_T entry;
198 + const char *errfun;
201 + *racl = rsync_acl_initializer;
202 + errfun = "sys_acl_get_entry";
203 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
205 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
206 + SMB_ACL_TAG_T tag_type;
207 + SMB_ACL_PERMSET_T permset;
212 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
213 + errfun = "sys_acl_get_tag_type";
216 + if ((rc = sys_acl_get_permset(entry, &permset))) {
217 + errfun = "sys_acl_get_tag_type";
220 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
221 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
222 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
223 + /* continue == done with entry; break == store in given idal */
224 + switch (tag_type) {
225 + case SMB_ACL_USER_OBJ:
226 + if (racl->user_obj == ACL_NO_ENTRY)
227 + racl->user_obj = access;
229 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
232 + idal = &racl->users;
234 + case SMB_ACL_GROUP_OBJ:
235 + if (racl->group_obj == ACL_NO_ENTRY)
236 + racl->group_obj = access;
238 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
240 + case SMB_ACL_GROUP:
241 + idal = &racl->groups;
244 + if (racl->mask == ACL_NO_ENTRY)
245 + racl->mask = access;
247 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
249 + case SMB_ACL_OTHER:
250 + if (racl->other == ACL_NO_ENTRY)
251 + racl->other = access;
253 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
256 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
259 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
260 + errfun = "sys_acl_get_tag_type";
264 + expand_ida_list(idal);
265 + ida = &idal->idas[idal->count++];
266 + ida->id = *((id_t *)qualifier);
267 + ida->access = access;
268 + sys_acl_free_qualifier(qualifier, tag_type);
271 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
272 + errfun, strerror(errno));
273 + rsync_acl_free(racl);
277 + sort_ida_list(&racl->users);
278 + sort_ida_list(&racl->groups);
283 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
285 + id_access *ida1, *ida2;
286 + size_t count = ial1->count;
287 + if (count != ial2->count)
291 + for (; count--; ida1++, ida2++) {
292 + if (ida1->access != ida2->access || ida1->id != ida2->id)
298 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
300 + return (racl1->user_obj == racl2->user_obj
301 + && racl1->group_obj == racl2->group_obj
302 + && racl1->mask == racl2->mask
303 + && racl1->other == racl2->other
304 + && ida_lists_equal(&racl1->users, &racl2->users)
305 + && ida_lists_equal(&racl1->groups, &racl2->groups));
308 +/* The first parameter will always be a fully-populated rsync_acl.
309 + * The second parameter will usually be a condensed rsync_acl, which means
310 + * that it might have several of its access objects set to ACL_NO_ENTRY. */
311 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1,
312 + const rsync_acl *racl2, mode_t m)
314 + /* We ignore any differences that chmod() can take care of. */
315 + if ((racl1->mask ^ racl2->mask) & ACL_NO_ENTRY)
317 + if (racl1->mask != ACL_NO_ENTRY) {
318 + /* A condensed rsync_acl with a mask can only have no
319 + * group_obj when it was identical to the mask. This
320 + * means that it was also identical to the group attrs
321 + * from the mode. */
322 + if (racl2->group_obj == ACL_NO_ENTRY) {
323 + if (racl1->group_obj != ((m >> 3) & 7))
325 + } else if (racl1->group_obj != racl2->group_obj)
328 + return ida_lists_equal(&racl1->users, &racl2->users)
329 + && ida_lists_equal(&racl1->groups, &racl2->groups);
338 +static rsync_acl_list _rsync_acl_lists[] = {
339 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
340 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
343 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
345 + return &_rsync_acl_lists[type != SMB_ACL_TYPE_ACCESS];
348 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
350 + /* First time through, 0 <= 0, so list is expanded. */
351 + if (racl_list->malloced <= racl_list->count) {
352 + rsync_acl *new_ptr;
354 + if (racl_list->malloced < 1000)
355 + new_size = racl_list->malloced + 1000;
357 + new_size = racl_list->malloced * 2;
358 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
359 + if (verbose >= 3) {
360 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
361 + (double) new_size * sizeof racl_list->racls[0],
362 + racl_list->racls ? "" : " not");
365 + racl_list->racls = new_ptr;
366 + racl_list->malloced = new_size;
368 + if (!racl_list->racls)
369 + out_of_memory("expand_rsync_acl_list");
373 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
374 + const rsync_acl_list *racl_list,
375 + const rsync_acl *racl)
377 + static int access_match = -1, default_match = -1;
378 + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
379 + size_t count = racl_list->count;
381 + /* If this is the first time through or we didn't match the last
382 + * time, then start at the end of the list, which should be the
383 + * best place to start hunting. */
385 + *match = racl_list->count - 1;
387 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
390 + *match = racl_list->count - 1;
397 +/* The general strategy with the tag_type <-> character mapping is that
398 + * lowercase implies that no qualifier follows, where uppercase does.
399 + * A similar idiom for the acl type (access or default) itself, but
400 + * lowercase in this instance means there's no ACL following, so the
401 + * ACL is a repeat, so the receiver should reuse the last of the same
403 +static void send_ida_list(int f, const ida_list *idal, char tag_char)
406 + size_t count = idal->count;
407 + for (ida = idal->idas; count--; ida++) {
408 + write_byte(f, tag_char);
409 + write_byte(f, ida->access);
410 + write_int(f, ida->id);
411 + /* FIXME: sorta wasteful: we should maybe buffer as
412 + * many ids as max(ACL_USER + ACL_GROUP) objects to
413 + * keep from making so many calls. */
414 + if (tag_char == 'U')
421 +static void send_rsync_acl(int f, const rsync_acl *racl)
423 + size_t count = count_racl_entries(racl);
424 + write_int(f, count);
425 + if (racl->user_obj != ACL_NO_ENTRY) {
426 + write_byte(f, 'u');
427 + write_byte(f, racl->user_obj);
429 + send_ida_list(f, &racl->users, 'U');
430 + if (racl->group_obj != ACL_NO_ENTRY) {
431 + write_byte(f, 'g');
432 + write_byte(f, racl->group_obj);
434 + send_ida_list(f, &racl->groups, 'G');
435 + if (racl->mask != ACL_NO_ENTRY) {
436 + write_byte(f, 'm');
437 + write_byte(f, racl->mask);
439 + if (racl->other != ACL_NO_ENTRY) {
440 + write_byte(f, 'o');
441 + write_byte(f, racl->other);
445 +static rsync_acl _curr_rsync_acls[2];
447 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
449 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
450 + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
451 + : "unknown SMB_ACL_TYPE_T";
454 +/* Generate the ACL(s) for this flist entry;
455 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
456 +int make_acl(const struct file_struct *file, const char *fname)
458 + SMB_ACL_TYPE_T type;
459 + rsync_acl *curr_racl;
461 + if (S_ISLNK(file->mode))
464 + curr_racl = &_curr_rsync_acls[0];
465 + type = SMB_ACL_TYPE_ACCESS;
469 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
470 + ok = unpack_smb_acl(curr_racl, sacl);
471 + sys_acl_free_acl(sacl);
474 + /* Avoid sending a redundant group/mask value. */
475 + if (curr_racl->group_obj == curr_racl->mask
476 + && (preserve_acls == 1
477 + || (!curr_racl->users.count
478 + && !curr_racl->groups.count)))
479 + curr_racl->mask = ACL_NO_ENTRY;
480 + /* Strip access ACLs of permission-bit entries. */
481 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
482 + rsync_acl_strip_perms(curr_racl);
483 + } else if (errno == ENOTSUP) {
484 + /* ACLs are not supported. Leave list empty. */
485 + *curr_racl = rsync_acl_initializer;
487 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
488 + fname, str_acl_type(type), strerror(errno));
492 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
497 +/* Send the make_acl()-generated ACLs for this flist entry,
498 + * or clean up after an flist entry that's not being sent (f == -1). */
499 +void send_acl(const struct file_struct *file, int f)
501 + SMB_ACL_TYPE_T type;
502 + rsync_acl *curr_racl;
504 + if (S_ISLNK(file->mode))
507 + curr_racl = &_curr_rsync_acls[0];
508 + type = SMB_ACL_TYPE_ACCESS;
511 + rsync_acl_list *racl_list = rsync_acl_lists(type);
513 + rsync_acl_free(curr_racl);
516 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
518 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
519 + write_int(f, index);
520 + rsync_acl_free(curr_racl);
522 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
523 + send_rsync_acl(f, curr_racl);
524 + expand_rsync_acl_list(racl_list);
525 + racl_list->racls[racl_list->count++] = *curr_racl;
528 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
531 +/* The below stuff is only used by the receiver: */
533 +/* structure to hold index to rsync_acl_list member corresponding to
534 + * flist->files[i] */
537 + const struct file_struct *file;
544 + file_acl_index *fais;
545 +} file_acl_index_list;
547 +static file_acl_index_list _file_acl_index_lists[] = {
548 + {0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
549 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
552 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
554 + return &_file_acl_index_lists[type != SMB_ACL_TYPE_ACCESS];
557 +static void expand_file_acl_index_list(file_acl_index_list *flst)
559 + /* First time through, 0 <= 0, so list is expanded. */
560 + if (flst->malloced <= flst->count) {
561 + file_acl_index *new_ptr;
564 + if (flst->malloced < 1000)
565 + new_size = flst->malloced + 1000;
567 + new_size = flst->malloced * 2;
568 + new_ptr = realloc_array(flst->fais, file_acl_index, new_size);
569 + if (verbose >= 3) {
570 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
571 + (double) new_size * sizeof flst->fais[0],
572 + flst->fais ? "" : " not");
575 + flst->fais = new_ptr;
576 + flst->malloced = new_size;
579 + out_of_memory("expand_file_acl_index_list");
583 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
591 +static smb_acl_list _smb_acl_lists[] = {
592 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
593 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
596 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
598 + return &_smb_acl_lists[type != SMB_ACL_TYPE_ACCESS];
601 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
603 + /* First time through, 0 <= 0, so list is expanded. */
604 + if (sacl_list->malloced <= sacl_list->count) {
605 + SMB_ACL_T *new_ptr;
607 + if (sacl_list->malloced < 1000)
608 + new_size = sacl_list->malloced + 1000;
610 + new_size = sacl_list->malloced * 2;
611 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
612 + if (verbose >= 3) {
613 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
614 + (double) new_size * sizeof sacl_list->sacls[0],
615 + sacl_list->sacls ? "" : " not");
618 + sacl_list->sacls = new_ptr;
619 + sacl_list->malloced = new_size;
621 + if (!sacl_list->sacls)
622 + out_of_memory("expand_smb_acl_list");
626 +#define CALL_OR_ERROR(func,args,str) \
634 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
635 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
637 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
639 + const char *errfun = NULL;
640 + SMB_ACL_PERMSET_T permset;
642 + COE( sys_acl_get_permset,(entry, &permset) );
643 + COE( sys_acl_clear_perms,(permset) );
645 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
647 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
649 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
650 + COE( sys_acl_set_permset,(entry, permset) );
655 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
660 +/* build an SMB_ACL_T corresponding to an rsync_acl */
661 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
665 + const char *errfun = NULL;
666 + SMB_ACL_ENTRY_T entry;
668 + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
669 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
674 + COE( sys_acl_create_entry,(smb_acl, &entry) );
675 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
676 + COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
678 + for (ida = racl->users.idas, count = racl->users.count;
680 + COE( sys_acl_create_entry,(smb_acl, &entry) );
681 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
682 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
683 + COE2( store_access_in_entry,(ida->access, entry) );
686 + COE( sys_acl_create_entry,(smb_acl, &entry) );
687 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
688 + COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
690 + for (ida = racl->groups.idas, count = racl->groups.count;
692 + COE( sys_acl_create_entry,(smb_acl, &entry) );
693 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
694 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
695 + COE2( store_access_in_entry,(ida->access, entry) );
697 +#ifndef ACLS_NEED_MASK
698 + if (racl->mask != ACL_NO_ENTRY) {
700 + COE( sys_acl_create_entry,(smb_acl, &entry) );
701 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
702 + COE2( store_access_in_entry,(racl->mask, entry) );
703 +#ifndef ACLS_NEED_MASK
707 + COE( sys_acl_create_entry,(smb_acl, &entry) );
708 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
709 + COE2( store_access_in_entry,(racl->other & 7, entry) );
712 + if (sys_acl_valid(*smb_acl) < 0)
713 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
720 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
723 + sys_acl_free_acl(*smb_acl);
727 +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
729 + SMB_ACL_ENTRY_T entry;
730 + const char *errfun;
733 + if (S_ISDIR(mode)) {
734 + /* If the sticky bit is going on, it's not safe to allow all
735 + * the new ACLs to go into effect before it gets set. */
736 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
737 + if (mode & S_ISVTX)
740 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
743 + /* If setuid or setgid is going off, it's not safe to allow all
744 + * the new ACLs to go into effect before they get cleared. */
745 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
746 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
751 + errfun = "sys_acl_get_entry";
752 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
754 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
755 + SMB_ACL_TAG_T tag_type;
756 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
757 + errfun = "sys_acl_get_tag_type";
760 + switch (tag_type) {
761 + case SMB_ACL_USER_OBJ:
762 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
764 + case SMB_ACL_GROUP_OBJ:
765 + /* group is only empty when identical to group perms. */
766 + if (racl->group_obj != ACL_NO_ENTRY)
768 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
771 +#ifndef ACLS_NEED_MASK
772 + /* mask is only empty when we don't need it. */
773 + if (racl->mask == ACL_NO_ENTRY)
776 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
778 + case SMB_ACL_OTHER:
779 + COE2( store_access_in_entry,(mode & 7, entry) );
786 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
787 + errfun, strerror(errno));
792 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
793 + /* Ensure that chmod() will be called to restore any lost setid bits. */
794 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
795 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
796 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
799 + /* Return the mode of the file on disk, as we will set them. */
800 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
803 +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
805 + uchar computed_mask_bits = 0;
806 + ida_list *idal = NULL;
810 + *racl = rsync_acl_initializer;
812 + if (!(count = read_int(f)))
816 + char tag = read_byte(f);
817 + uchar access = read_byte(f);
818 + if (access & ~ (4 | 2 | 1)) {
819 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
821 + exit_cleanup(RERR_STREAMIO);
825 + if (racl->user_obj != ACL_NO_ENTRY) {
826 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
827 + exit_cleanup(RERR_STREAMIO);
829 + racl->user_obj = access;
832 + idal = &racl->users;
835 + if (racl->group_obj != ACL_NO_ENTRY) {
836 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
837 + exit_cleanup(RERR_STREAMIO);
839 + racl->group_obj = access;
842 + idal = &racl->groups;
845 + if (racl->mask != ACL_NO_ENTRY) {
846 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
847 + exit_cleanup(RERR_STREAMIO);
849 + racl->mask = access;
852 + if (racl->other != ACL_NO_ENTRY) {
853 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
854 + exit_cleanup(RERR_STREAMIO);
856 + racl->other = access;
859 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
861 + exit_cleanup(RERR_STREAMIO);
863 + expand_ida_list(idal);
864 + ida = &idal->idas[idal->count++];
865 + ida->access = access;
866 + ida->id = read_int(f);
867 + computed_mask_bits |= access;
870 + if (type == SMB_ACL_TYPE_DEFAULT) {
871 + /* Ensure that these are never unset. */
872 + if (racl->user_obj == ACL_NO_ENTRY)
873 + racl->user_obj = 7;
874 + if (racl->group_obj == ACL_NO_ENTRY)
875 + racl->group_obj = 0;
876 + if (racl->other == ACL_NO_ENTRY)
879 +#ifndef ACLS_NEED_MASK
880 + if (!racl->users.count && !racl->groups.count) {
881 + /* If we, a system without ACLS_NEED_MASK, received a
882 + * superfluous mask, throw it away. */
883 + if (racl->mask != ACL_NO_ENTRY) {
884 + /* mask off group perms with it first */
885 + racl->group_obj &= racl->mask | ACL_NO_ENTRY;
886 + racl->mask = ACL_NO_ENTRY;
890 + if (racl->mask == ACL_NO_ENTRY) /* Always non-empty when needed. */
891 + racl->mask = computed_mask_bits | (racl->group_obj & 7);
894 +/* receive and build the rsync_acl_lists */
895 +void receive_acl(struct file_struct *file, int f)
897 + SMB_ACL_TYPE_T type;
900 + if (S_ISLNK(file->mode))
903 + fname = f_name(file, NULL);
904 + type = SMB_ACL_TYPE_ACCESS;
907 + file_acl_index_list *flst = file_acl_index_lists(type);
909 + expand_file_acl_index_list(flst);
911 + tag = read_byte(f);
912 + if (tag == 'A' || tag == 'a') {
913 + if (type != SMB_ACL_TYPE_ACCESS) {
914 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
916 + exit_cleanup(RERR_STREAMIO);
918 + } else if (tag == 'D' || tag == 'd') {
919 + if (type == SMB_ACL_TYPE_ACCESS) {
920 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
922 + exit_cleanup(RERR_STREAMIO);
925 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
927 + exit_cleanup(RERR_STREAMIO);
929 + if (tag == 'A' || tag == 'D') {
931 + rsync_acl_list *racl_list = rsync_acl_lists(type);
932 + smb_acl_list *sacl_list = smb_acl_lists(type);
933 + flst->fais[flst->count].aclidx = racl_list->count;
934 + flst->fais[flst->count++].file = file;
935 + receive_rsync_acl(&racl, f, type);
936 + expand_rsync_acl_list(racl_list);
937 + racl_list->racls[racl_list->count++] = racl;
938 + expand_smb_acl_list(sacl_list);
939 + sacl_list->sacls[sacl_list->count++] = NULL;
941 + int index = read_int(f);
942 + rsync_acl_list *racl_list = rsync_acl_lists(type);
943 + if ((size_t) index >= racl_list->count) {
944 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
946 + str_acl_type(type),
948 + exit_cleanup(RERR_STREAMIO);
950 + flst->fais[flst->count].aclidx = index;
951 + flst->fais[flst->count++].file = file;
953 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
956 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
958 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
959 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
960 + return fileaclidx1->file == fileaclidx2->file ? 0
961 + : fileaclidx1->file < fileaclidx2->file ? -1 : 1;
964 +void sort_file_acl_index_lists()
966 + SMB_ACL_TYPE_T type;
968 + type = SMB_ACL_TYPE_ACCESS;
970 + file_acl_index_list *flst = file_acl_index_lists(type);
975 + qsort(flst->fais, flst->count, sizeof flst->fais[0],
976 + &file_acl_index_list_sorter);
977 + } while (BUMP_TYPE(type));
980 +static int find_file_acl_index(const file_acl_index_list *flst,
981 + const struct file_struct *file)
983 + int low = 0, high = flst->count;
984 + const struct file_struct *file_mid;
989 + int mid = (high + low) / 2;
990 + file_mid = flst->fais[mid].file;
991 + if (file_mid == file)
992 + return flst->fais[mid].aclidx;
993 + if (file_mid > file)
997 + } while (low < high);
999 + file_mid = flst->fais[low].file;
1000 + if (file_mid == file)
1001 + return flst->fais[low].aclidx;
1004 + "find_file_acl_index: can't find entry for file in list\n");
1005 + exit_cleanup(RERR_STREAMIO);
1009 +/* for duplicating ACLs on backups when using backup_dir */
1010 +int dup_acl(const char *orig, const char *bak, mode_t mode)
1012 + SMB_ACL_TYPE_T type;
1015 + type = SMB_ACL_TYPE_ACCESS;
1017 + SMB_ACL_T sacl_orig, sacl_bak;
1018 + rsync_acl racl_orig, racl_bak;
1019 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
1020 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
1021 + orig, str_acl_type(type), strerror(errno));
1025 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
1026 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
1027 + bak, str_acl_type(type), strerror(errno));
1029 + /* try to forge on through */
1031 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
1033 + goto out_with_sacls;
1036 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
1038 + goto out_with_one_racl;
1040 + if (rsync_acls_equal(&racl_orig, &racl_bak))
1041 + goto out_with_all;
1043 + ; /* presume they're unequal */
1045 + if (type == SMB_ACL_TYPE_DEFAULT
1046 + && racl_orig.user_obj == ACL_NO_ENTRY) {
1047 + if (sys_acl_delete_def_file(bak) < 0) {
1048 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
1049 + bak, strerror(errno));
1052 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
1053 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
1054 + bak, str_acl_type(type), strerror(errno));
1059 + rsync_acl_free(&racl_bak);
1060 + out_with_one_racl:
1061 + rsync_acl_free(&racl_orig);
1064 + sys_acl_free_acl(sacl_bak);
1066 + sys_acl_free_acl(sacl_orig);
1067 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1072 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1073 + * for keep_backup(). */
1074 +static const struct file_struct *backup_orig_file = NULL;
1075 +static const char null_string[] = "";
1076 +static const char *backup_orig_fname = null_string;
1077 +static const char *backup_dest_fname = null_string;
1078 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1080 +void push_keep_backup_acl(const struct file_struct *file,
1081 + const char *orig, const char *dest)
1083 + SMB_ACL_TYPE_T type;
1086 + backup_orig_file = file;
1087 + backup_orig_fname = orig;
1088 + backup_dest_fname = dest;
1090 + sacl = &_backup_sacl[0];
1091 + type = SMB_ACL_TYPE_ACCESS;
1093 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1097 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1099 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1100 + orig, str_acl_type(type),
1103 + } while (BUMP_TYPE(type));
1106 +static int set_keep_backup_acl()
1108 + SMB_ACL_TYPE_T type;
1112 + sacl = &_backup_sacl[0];
1113 + type = SMB_ACL_TYPE_ACCESS;
1116 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1118 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1119 + backup_dest_fname,
1120 + str_acl_type(type),
1124 + } while (BUMP_TYPE(type));
1129 +void cleanup_keep_backup_acl()
1131 + SMB_ACL_TYPE_T type;
1134 + backup_orig_file = NULL;
1135 + backup_orig_fname = null_string;
1136 + backup_dest_fname = null_string;
1138 + sacl = &_backup_sacl[0];
1139 + type = SMB_ACL_TYPE_ACCESS;
1142 + sys_acl_free_acl(*sacl);
1145 + } while (BUMP_TYPE(type));
1148 +/* set ACL on rsync-ed or keep_backup-ed file
1150 + * This sets extended access ACL entries and default ACLs. If convenient,
1151 + * it sets permission bits along with the access ACLs and signals having
1152 + * done so by modifying mode_p, which should point into the stat buffer.
1154 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1155 + * Pass NULL for mode_p to get the return code without changing anything. */
1156 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1158 + int unchanged = 1;
1159 + SMB_ACL_TYPE_T type;
1161 + if (S_ISLNK(file->mode))
1164 + if (file == backup_orig_file) {
1165 + if (!strcmp(fname, backup_dest_fname))
1166 + return set_keep_backup_acl();
1168 + type = SMB_ACL_TYPE_ACCESS;
1171 + SMB_ACL_T sacl_orig, *sacl_new;
1172 + rsync_acl racl_orig, *racl_new;
1173 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1175 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1176 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1177 + sacl_orig = sys_acl_get_file(fname, type);
1179 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1180 + fname, str_acl_type(type), strerror(errno));
1184 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1185 + sys_acl_free_acl(sacl_orig);
1190 + if (type == SMB_ACL_TYPE_ACCESS)
1191 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new, file->mode);
1193 + ok = rsync_acls_equal(&racl_orig, racl_new);
1194 + rsync_acl_free(&racl_orig);
1197 + if (!dry_run && mode_p) {
1198 + if (type == SMB_ACL_TYPE_DEFAULT
1199 + && racl_new->user_obj == ACL_NO_ENTRY) {
1200 + if (sys_acl_delete_def_file(fname) < 0) {
1201 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1202 + fname, strerror(errno));
1207 + mode_t cur_mode = *mode_p;
1209 + && !pack_smb_acl(sacl_new, racl_new)) {
1213 + if (type == SMB_ACL_TYPE_ACCESS) {
1214 + cur_mode = change_sacl_perms(*sacl_new, racl_new,
1215 + cur_mode, file->mode);
1216 + if (cur_mode == ~0u)
1219 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1220 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1221 + fname, str_acl_type(type),
1226 + if (type == SMB_ACL_TYPE_ACCESS)
1227 + *mode_p = cur_mode;
1230 + if (unchanged == 1)
1232 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1237 +/* Enumeration functions for uid mapping: */
1239 +/* Context -- one and only one. Should be cycled through once on uid
1240 + * mapping and once on gid mapping. */
1241 +static rsync_acl_list *_enum_racl_lists[] = {
1242 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1245 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1246 +static size_t enum_racl_index = 0;
1247 +static size_t enum_ida_index = 0;
1249 +/* This returns the next tag_type id from the given acl for the next entry,
1250 + * or it returns 0 if there are no more tag_type ids in the acl. */
1251 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1253 + const ida_list *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
1254 + if (enum_ida_index < idal->count) {
1255 + id_access *ida = &idal->idas[enum_ida_index++];
1258 + enum_ida_index = 0;
1262 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1264 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1265 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1266 + id_t *id = next_ace_id(tag_type, racl);
1270 + enum_racl_index = 0;
1274 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1276 + for (; *enum_racl_list; enum_racl_list++) {
1277 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1281 + enum_racl_list = &_enum_racl_lists[0];
1285 +id_t *next_acl_uid()
1287 + return next_acl_list_id(SMB_ACL_USER);
1290 +id_t *next_acl_gid()
1292 + return next_acl_list_id(SMB_ACL_GROUP);
1295 +int default_perms_for_dir(const char *dir)
1304 + perms = ACCESSPERMS & ~orig_umask;
1305 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1306 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1307 + if (sacl == NULL) {
1308 + /* Couldn't get an ACL. Darn. */
1311 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1315 + /* We're doing a dry run, so the containing directory
1316 + * wasn't actually created. Don't worry about it. */
1319 + /* Otherwise fall through. */
1321 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1322 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1328 + ok = unpack_smb_acl(&racl, sacl);
1329 + sys_acl_free_acl(sacl);
1331 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1335 + /* Apply the permission-bit entries of the default ACL, if any. */
1336 + if (racl.user_obj != ACL_NO_ENTRY) {
1337 + perms = rsync_acl_get_perms(&racl);
1339 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1342 + rsync_acl_free(&racl);
1346 +#endif /* SUPPORT_ACLS */
1349 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1350 extern char *backup_dir;
1353 +extern int preserve_acls;
1354 extern int preserve_devices;
1355 extern int preserve_specials;
1356 extern int preserve_links;
1357 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1359 do_lchown(fullpath, st.st_uid, st.st_gid);
1360 do_chmod(fullpath, st.st_mode);
1361 +#ifdef SUPPORT_ACLS
1362 + if (preserve_acls)
1363 + dup_acl(end, fullpath, st.st_mode);
1368 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1369 if (!(buf = get_backup_name(fname)))
1372 +#ifdef SUPPORT_ACLS
1373 + if (preserve_acls)
1374 + push_keep_backup_acl(file, fname, buf);
1377 /* Check to see if this is a device file, or link */
1378 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1379 || (preserve_specials && IS_SPECIAL(file->mode))) {
1380 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1383 set_file_attrs(buf, file, NULL, 0);
1384 +#ifdef SUPPORT_ACLS
1385 + if (preserve_acls)
1386 + cleanup_keep_backup_acl();
1391 --- old/configure.in
1392 +++ new/configure.in
1393 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1394 AC_CHECK_LIB(resolv, strcasecmp)
1397 +AC_CHECK_FUNCS(aclsort)
1398 +if test x"$ac_cv_func_aclsort" = x"no"; then
1399 + AC_CHECK_LIB(sec, aclsort)
1402 dnl At the moment we don't test for a broken memcmp(), because all we
1403 dnl need to do is test for equality, not comparison, and it seems that
1404 dnl every platform has a memcmp that can do at least that.
1405 @@ -746,6 +751,78 @@ AC_SUBST(OBJ_RESTORE)
1406 AC_SUBST(CC_SHOBJ_FLAG)
1407 AC_SUBST(BUILD_POPT)
1409 +AC_CHECK_HEADERS(sys/acl.h)
1410 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1411 +#################################################
1412 +# check for ACL support
1414 +AC_MSG_CHECKING(whether to support ACLs)
1415 +AC_ARG_ENABLE(acl-support,
1416 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1417 +[ case "$enableval" in
1420 + case "$host_os" in
1422 + AC_MSG_RESULT(Using UnixWare ACLs)
1423 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1425 + *solaris*|*cygwin*)
1426 + AC_MSG_RESULT(Using solaris ACLs)
1427 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1430 + AC_MSG_RESULT(Using HPUX ACLs)
1431 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1434 + AC_MSG_RESULT(Using IRIX ACLs)
1435 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1438 + AC_MSG_RESULT(Using AIX ACLs)
1439 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1442 + AC_MSG_RESULT(Using Tru64 ACLs)
1443 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1444 + LIBS="$LIBS -lpacl"
1447 + AC_MSG_RESULT(ACLs requested -- running tests)
1448 + AC_CHECK_LIB(acl,acl_get_file)
1449 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1450 + AC_TRY_LINK([#include <sys/types.h>
1451 +#include <sys/acl.h>],
1452 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1453 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1454 + AC_MSG_CHECKING(ACL test results)
1455 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1456 + AC_MSG_RESULT(Using posix ACLs)
1457 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1458 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1459 + AC_TRY_LINK([#include <sys/types.h>
1460 +#include <sys/acl.h>],
1461 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1462 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1463 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1464 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1467 + AC_MSG_ERROR(Failed to find ACL support)
1474 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1477 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1481 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1486 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1487 extern int one_file_system;
1488 extern int copy_dirlinks;
1489 extern int keep_dirlinks;
1490 +extern int preserve_acls;
1491 extern int preserve_links;
1492 extern int preserve_hard_links;
1493 extern int preserve_devices;
1494 @@ -965,6 +966,11 @@ static struct file_struct *send_file_nam
1495 if (chmod_modes && !S_ISLNK(file->mode))
1496 file->mode = tweak_mode(file->mode, chmod_modes);
1498 +#ifdef SUPPORT_ACLS
1499 + if (preserve_acls && make_acl(file, fname) < 0)
1503 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1505 flist_expand(flist);
1506 @@ -972,6 +978,16 @@ static struct file_struct *send_file_nam
1507 if (file->basename[0]) {
1508 flist->files[flist->count++] = file;
1509 send_file_entry(file, f);
1510 +#ifdef SUPPORT_ACLS
1511 + if (preserve_acls)
1512 + send_acl(file, f);
1515 +#ifdef SUPPORT_ACLS
1516 + /* Cleanup unsent ACL(s). */
1517 + if (preserve_acls)
1518 + send_acl(file, -1);
1523 @@ -1360,6 +1376,11 @@ struct file_list *recv_file_list(int f)
1524 flags |= read_byte(f) << 8;
1525 file = receive_file_entry(flist, flags, f);
1527 +#ifdef SUPPORT_ACLS
1528 + if (preserve_acls)
1529 + receive_acl(file, f);
1532 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1533 stats.total_size += file->length;
1535 @@ -1382,6 +1403,11 @@ struct file_list *recv_file_list(int f)
1537 clean_flist(flist, relative_paths, 1);
1539 +#ifdef SUPPORT_ACLS
1540 + if (preserve_acls)
1541 + sort_file_acl_index_lists();
1545 recv_uid_list(f, flist);
1549 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1550 extern int max_delete;
1551 extern int force_delete;
1552 extern int one_file_system;
1553 +extern mode_t orig_umask;
1554 extern struct stats stats;
1555 extern dev_t filesystem_dev;
1556 extern char *backup_dir;
1557 @@ -319,6 +320,8 @@ static void do_delete_pass(struct file_l
1559 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1561 + /* FIXME: Flag ACL changes. */
1564 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1566 @@ -353,6 +356,7 @@ void itemize(struct file_struct *file, i
1567 if (preserve_gid && file->gid != GID_NONE
1568 && st->st_gid != file->gid)
1569 iflags |= ITEM_REPORT_GROUP;
1570 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1572 iflags |= ITEM_IS_NEW;
1574 @@ -769,6 +773,7 @@ static int try_dests_non(struct file_str
1577 static int phase = 0;
1578 +static int dflt_perms;
1580 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1581 * make sure it exists, and has the right permissions/timestamp info. For
1582 @@ -860,6 +865,10 @@ static void recv_generator(char *fname,
1585 need_fuzzy_dirlist = 1;
1586 +#ifdef SUPPORT_ACLS
1587 + if (!preserve_perms)
1588 + dflt_perms = default_perms_for_dir(dn);
1591 parent_dirname = dn;
1593 @@ -887,7 +896,8 @@ static void recv_generator(char *fname,
1594 if (!preserve_perms) {
1595 int exists = statret == 0
1596 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1597 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1598 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1602 if (S_ISDIR(file->mode)) {
1603 @@ -1366,6 +1376,8 @@ void generate_files(int f_out, struct fi
1604 * notice that and let us know via the redo pipe (or its closing). */
1607 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1609 for (i = 0; i < flist->count; i++) {
1610 struct file_struct *file = flist->files[i];
1612 --- old/lib/sysacls.c
1613 +++ new/lib/sysacls.c
1616 + Unix SMB/CIFS implementation.
1617 + Samba system utilities for ACL support.
1618 + Copyright (C) Jeremy Allison 2000.
1620 + This program is free software; you can redistribute it and/or modify
1621 + it under the terms of the GNU General Public License as published by
1622 + the Free Software Foundation; either version 2 of the License, or
1623 + (at your option) any later version.
1625 + This program is distributed in the hope that it will be useful,
1626 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1627 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1628 + GNU General Public License for more details.
1630 + You should have received a copy of the GNU General Public License
1631 + along with this program; if not, write to the Free Software
1632 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1636 +#include "sysacls.h" /****** ADDED ******/
1638 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1639 +void SAFE_FREE(void *mem)
1645 +char *uidtoname(uid_t uid)
1647 + static char idbuf[12];
1648 + struct passwd *pw;
1650 + if ((pw = getpwuid(uid)) == NULL) {
1651 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1654 + return pw->pw_name;
1656 +/****** EXTRAS -- END ******/
1659 + This file wraps all differing system ACL interfaces into a consistent
1660 + one based on the POSIX interface. It also returns the correct errors
1661 + for older UNIX systems that don't support ACLs.
1663 + The interfaces that each ACL implementation must support are as follows :
1665 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1666 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1667 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1668 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1669 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1670 + SMB_ACL_T sys_acl_get_fd(int fd)
1671 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1672 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1673 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1674 + SMB_ACL_T sys_acl_init( int count)
1675 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1676 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1677 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1678 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1679 + int sys_acl_valid( SMB_ACL_T theacl )
1680 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1681 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1682 + int sys_acl_delete_def_file(const char *path)
1684 + This next one is not POSIX complient - but we *have* to have it !
1685 + More POSIX braindamage.
1687 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1689 + The generic POSIX free is the following call. We split this into
1690 + several different free functions as we may need to add tag info
1691 + to structures when emulating the POSIX interface.
1693 + int sys_acl_free( void *obj_p)
1695 + The calls we actually use are :
1697 + int sys_acl_free_text(char *text) - free acl_to_text
1698 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1699 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1703 +#if defined(HAVE_POSIX_ACLS)
1705 +/* Identity mapping - easy. */
1707 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1709 + return acl_get_entry( the_acl, entry_id, entry_p);
1712 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1714 + return acl_get_tag_type( entry_d, tag_type_p);
1717 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1719 + return acl_get_permset( entry_d, permset_p);
1722 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1724 + return acl_get_qualifier( entry_d);
1727 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1729 + return acl_get_file( path_p, type);
1732 +SMB_ACL_T sys_acl_get_fd(int fd)
1734 + return acl_get_fd(fd);
1737 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1739 + return acl_clear_perms(permset);
1742 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1744 + return acl_add_perm(permset, perm);
1747 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1749 +#if defined(HAVE_ACL_GET_PERM_NP)
1751 + * Required for TrustedBSD-based ACL implementations where
1752 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1755 + return acl_get_perm_np(permset, perm);
1757 + return acl_get_perm(permset, perm);
1761 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1763 + return acl_to_text( the_acl, plen);
1766 +SMB_ACL_T sys_acl_init( int count)
1768 + return acl_init(count);
1771 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1773 + return acl_create_entry(pacl, pentry);
1776 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1778 + return acl_set_tag_type(entry, tagtype);
1781 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1783 + return acl_set_qualifier(entry, qual);
1786 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1788 + return acl_set_permset(entry, permset);
1791 +int sys_acl_valid( SMB_ACL_T theacl )
1793 + return acl_valid(theacl);
1796 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1798 + return acl_set_file(name, acltype, theacl);
1801 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1803 + return acl_set_fd(fd, theacl);
1806 +int sys_acl_delete_def_file(const char *name)
1808 + return acl_delete_def_file(name);
1811 +int sys_acl_free_text(char *text)
1813 + return acl_free(text);
1816 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1818 + return acl_free(the_acl);
1821 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1823 + return acl_free(qual);
1826 +#elif defined(HAVE_TRU64_ACLS)
1828 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1829 + * is based on Draft 13 of the POSIX spec which is
1830 + * slightly different from the Draft 16 interface.
1832 + * Also, some of the permset manipulation functions
1833 + * such as acl_clear_perm() and acl_add_perm() appear
1834 + * to be broken on Tru64 so we have to manipulate
1835 + * the permission bits in the permset directly.
1837 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1839 + SMB_ACL_ENTRY_T entry;
1841 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1846 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1851 + return errno ? -1 : 0;
1854 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1856 + return acl_get_tag_type( entry_d, tag_type_p);
1859 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1861 + return acl_get_permset( entry_d, permset_p);
1864 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1866 + return acl_get_qualifier( entry_d);
1869 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1871 + return acl_get_file((char *)path_p, type);
1874 +SMB_ACL_T sys_acl_get_fd(int fd)
1876 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1879 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1881 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1886 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1888 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1893 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1898 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1900 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1903 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1905 + return acl_to_text( the_acl, plen);
1908 +SMB_ACL_T sys_acl_init( int count)
1910 + return acl_init(count);
1913 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1915 + SMB_ACL_ENTRY_T entry;
1917 + if ((entry = acl_create_entry(pacl)) == NULL) {
1925 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1927 + return acl_set_tag_type(entry, tagtype);
1930 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1932 + return acl_set_qualifier(entry, qual);
1935 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1937 + return acl_set_permset(entry, permset);
1940 +int sys_acl_valid( SMB_ACL_T theacl )
1942 + acl_entry_t entry;
1944 + return acl_valid(theacl, &entry);
1947 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1949 + return acl_set_file((char *)name, acltype, theacl);
1952 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1954 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1957 +int sys_acl_delete_def_file(const char *name)
1959 + return acl_delete_def_file((char *)name);
1962 +int sys_acl_free_text(char *text)
1965 + * (void) cast and explicit return 0 are for DEC UNIX
1966 + * which just #defines acl_free_text() to be free()
1968 + (void) acl_free_text(text);
1972 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1974 + return acl_free(the_acl);
1977 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1979 + return acl_free_qualifier(qual, tagtype);
1982 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1985 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1986 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1990 + * Note that while this code implements sufficient functionality
1991 + * to support the sys_acl_* interfaces it does not provide all
1992 + * of the semantics of the POSIX ACL interfaces.
1994 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1995 + * from a call to sys_acl_get_entry() should not be assumed to be
1996 + * valid after calling any of the following functions, which may
1997 + * reorder the entries in the ACL.
2000 + * sys_acl_set_file()
2001 + * sys_acl_set_fd()
2005 + * The only difference between Solaris and UnixWare / OpenUNIX is
2006 + * that the #defines for the ACL operations have different names
2008 +#if defined(HAVE_UNIXWARE_ACLS)
2010 +#define SETACL ACL_SET
2011 +#define GETACL ACL_GET
2012 +#define GETACLCNT ACL_CNT
2017 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2019 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2024 + if (entry_p == NULL) {
2029 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2033 + if (acl_d->next < 0) {
2038 + if (acl_d->next >= acl_d->count) {
2042 + *entry_p = &acl_d->acl[acl_d->next++];
2047 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2049 + *type_p = entry_d->a_type;
2054 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2056 + *permset_p = &entry_d->a_perm;
2061 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2063 + if (entry_d->a_type != SMB_ACL_USER
2064 + && entry_d->a_type != SMB_ACL_GROUP) {
2069 + return &entry_d->a_id;
2073 + * There is no way of knowing what size the ACL returned by
2074 + * GETACL will be unless you first call GETACLCNT which means
2075 + * making an additional system call.
2077 + * In the hope of avoiding the cost of the additional system
2078 + * call in most cases, we initially allocate enough space for
2079 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2080 + * be too small then we use GETACLCNT to find out the actual
2081 + * size, reallocate the ACL buffer, and then call GETACL again.
2084 +#define INITIAL_ACL_SIZE 16
2086 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2089 + int count; /* # of ACL entries allocated */
2090 + int naccess; /* # of access ACL entries */
2091 + int ndefault; /* # of default ACL entries */
2093 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2098 + count = INITIAL_ACL_SIZE;
2099 + if ((acl_d = sys_acl_init(count)) == NULL) {
2104 + * If there isn't enough space for the ACL entries we use
2105 + * GETACLCNT to determine the actual number of ACL entries
2106 + * reallocate and try again. This is in a loop because it
2107 + * is possible that someone else could modify the ACL and
2108 + * increase the number of entries between the call to
2109 + * GETACLCNT and the call to GETACL.
2111 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2112 + && errno == ENOSPC) {
2114 + sys_acl_free_acl(acl_d);
2116 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2120 + if ((acl_d = sys_acl_init(count)) == NULL) {
2126 + sys_acl_free_acl(acl_d);
2131 + * calculate the number of access and default ACL entries
2133 + * Note: we assume that the acl() system call returned a
2134 + * well formed ACL which is sorted so that all of the
2135 + * access ACL entries preceed any default ACL entries
2137 + for (naccess = 0; naccess < count; naccess++) {
2138 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2141 + ndefault = count - naccess;
2144 + * if the caller wants the default ACL we have to copy
2145 + * the entries down to the start of the acl[] buffer
2146 + * and mask out the ACL_DEFAULT flag from the type field
2148 + if (type == SMB_ACL_TYPE_DEFAULT) {
2151 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2152 + acl_d->acl[i] = acl_d->acl[j];
2153 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2156 + acl_d->count = ndefault;
2158 + acl_d->count = naccess;
2164 +SMB_ACL_T sys_acl_get_fd(int fd)
2167 + int count; /* # of ACL entries allocated */
2168 + int naccess; /* # of access ACL entries */
2170 + count = INITIAL_ACL_SIZE;
2171 + if ((acl_d = sys_acl_init(count)) == NULL) {
2175 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2176 + && errno == ENOSPC) {
2178 + sys_acl_free_acl(acl_d);
2180 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2184 + if ((acl_d = sys_acl_init(count)) == NULL) {
2190 + sys_acl_free_acl(acl_d);
2195 + * calculate the number of access ACL entries
2197 + for (naccess = 0; naccess < count; naccess++) {
2198 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2202 + acl_d->count = naccess;
2207 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2214 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2216 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2217 + && perm != SMB_ACL_EXECUTE) {
2222 + if (permset_d == NULL) {
2227 + *permset_d |= perm;
2232 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2234 + return *permset_d & perm;
2237 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2244 + * use an initial estimate of 20 bytes per ACL entry
2245 + * when allocating memory for the text representation
2249 + maxlen = 20 * acl_d->count;
2250 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2255 + for (i = 0; i < acl_d->count; i++) {
2256 + struct acl *ap = &acl_d->acl[i];
2265 + switch (ap->a_type) {
2267 + * for debugging purposes it's probably more
2268 + * useful to dump unknown tag types rather
2269 + * than just returning an error
2272 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2275 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2280 + case SMB_ACL_USER:
2281 + id = uidtoname(ap->a_id);
2282 + case SMB_ACL_USER_OBJ:
2286 + case SMB_ACL_GROUP:
2287 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2288 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2294 + case SMB_ACL_GROUP_OBJ:
2298 + case SMB_ACL_OTHER:
2302 + case SMB_ACL_MASK:
2308 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2309 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2310 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2313 + /* <tag> : <qualifier> : rwx \n \0 */
2314 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2317 + * If this entry would overflow the buffer
2318 + * allocate enough additional memory for this
2319 + * entry and an estimate of another 20 bytes
2320 + * for each entry still to be processed
2322 + if ((len + nbytes) > maxlen) {
2323 + char *oldtext = text;
2325 + maxlen += nbytes + 20 * (acl_d->count - i);
2327 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2328 + SAFE_FREE(oldtext);
2334 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2335 + len += nbytes - 1;
2344 +SMB_ACL_T sys_acl_init(int count)
2354 + * note that since the definition of the structure pointed
2355 + * to by the SMB_ACL_T includes the first element of the
2356 + * acl[] array, this actually allocates an ACL with room
2357 + * for (count+1) entries
2359 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2364 + a->size = count + 1;
2372 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2375 + SMB_ACL_ENTRY_T entry_d;
2377 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2382 + if (acl_d->count >= acl_d->size) {
2387 + entry_d = &acl_d->acl[acl_d->count++];
2388 + entry_d->a_type = 0;
2389 + entry_d->a_id = -1;
2390 + entry_d->a_perm = 0;
2391 + *entry_p = entry_d;
2396 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2398 + switch (tag_type) {
2399 + case SMB_ACL_USER:
2400 + case SMB_ACL_USER_OBJ:
2401 + case SMB_ACL_GROUP:
2402 + case SMB_ACL_GROUP_OBJ:
2403 + case SMB_ACL_OTHER:
2404 + case SMB_ACL_MASK:
2405 + entry_d->a_type = tag_type;
2415 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2417 + if (entry_d->a_type != SMB_ACL_GROUP
2418 + && entry_d->a_type != SMB_ACL_USER) {
2423 + entry_d->a_id = *((id_t *)qual_p);
2428 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2430 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2434 + entry_d->a_perm = *permset_d;
2440 + * sort the ACL and check it for validity
2442 + * if it's a minimal ACL with only 4 entries then we
2443 + * need to recalculate the mask permissions to make
2444 + * sure that they are the same as the GROUP_OBJ
2445 + * permissions as required by the UnixWare acl() system call.
2447 + * (note: since POSIX allows minimal ACLs which only contain
2448 + * 3 entries - ie there is no mask entry - we should, in theory,
2449 + * check for this and add a mask entry if necessary - however
2450 + * we "know" that the caller of this interface always specifies
2451 + * a mask so, in practice "this never happens" (tm) - if it *does*
2452 + * happen aclsort() will fail and return an error and someone will
2453 + * have to fix it ...)
2456 +static int acl_sort(SMB_ACL_T acl_d)
2458 + int fixmask = (acl_d->count <= 4);
2460 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2467 +int sys_acl_valid(SMB_ACL_T acl_d)
2469 + return acl_sort(acl_d);
2472 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2475 + struct acl *acl_p;
2477 + struct acl *acl_buf = NULL;
2480 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2485 + if (acl_sort(acl_d) != 0) {
2489 + acl_p = &acl_d->acl[0];
2490 + acl_count = acl_d->count;
2493 + * if it's a directory there is extra work to do
2494 + * since the acl() system call will replace both
2495 + * the access ACLs and the default ACLs (if any)
2497 + if (stat(name, &s) != 0) {
2500 + if (S_ISDIR(s.st_mode)) {
2501 + SMB_ACL_T acc_acl;
2502 + SMB_ACL_T def_acl;
2503 + SMB_ACL_T tmp_acl;
2506 + if (type == SMB_ACL_TYPE_ACCESS) {
2508 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2512 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2515 + if (tmp_acl == NULL) {
2520 + * allocate a temporary buffer for the complete ACL
2522 + acl_count = acc_acl->count + def_acl->count;
2523 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2525 + if (acl_buf == NULL) {
2526 + sys_acl_free_acl(tmp_acl);
2532 + * copy the access control and default entries into the buffer
2534 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2535 + acc_acl->count * sizeof(acl_buf[0]));
2537 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2538 + def_acl->count * sizeof(acl_buf[0]));
2541 + * set the ACL_DEFAULT flag on the default entries
2543 + for (i = acc_acl->count; i < acl_count; i++) {
2544 + acl_buf[i].a_type |= ACL_DEFAULT;
2547 + sys_acl_free_acl(tmp_acl);
2549 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2554 + ret = acl(name, SETACL, acl_count, acl_p);
2556 + SAFE_FREE(acl_buf);
2561 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2563 + if (acl_sort(acl_d) != 0) {
2567 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2570 +int sys_acl_delete_def_file(const char *path)
2576 + * fetching the access ACL and rewriting it has
2577 + * the effect of deleting the default ACL
2579 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2583 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2585 + sys_acl_free_acl(acl_d);
2590 +int sys_acl_free_text(char *text)
2596 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2602 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2607 +#elif defined(HAVE_HPUX_ACLS)
2611 + * Based on the Solaris/SCO code - with modifications.
2615 + * Note that while this code implements sufficient functionality
2616 + * to support the sys_acl_* interfaces it does not provide all
2617 + * of the semantics of the POSIX ACL interfaces.
2619 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2620 + * from a call to sys_acl_get_entry() should not be assumed to be
2621 + * valid after calling any of the following functions, which may
2622 + * reorder the entries in the ACL.
2625 + * sys_acl_set_file()
2626 + * sys_acl_set_fd()
2629 +/* This checks if the POSIX ACL system call is defined */
2630 +/* which basically corresponds to whether JFS 3.3 or */
2631 +/* higher is installed. If acl() was called when it */
2632 +/* isn't defined, it causes the process to core dump */
2633 +/* so it is important to check this and avoid acl() */
2634 +/* calls if it isn't there. */
2636 +static BOOL hpux_acl_call_presence(void)
2639 + shl_t handle = NULL;
2642 + static BOOL already_checked=0;
2644 + if(already_checked)
2648 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2650 + if(ret_val != 0) {
2651 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2652 + ret_val, errno, strerror(errno)));
2653 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2657 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2659 + already_checked = True;
2663 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2665 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2670 + if (entry_p == NULL) {
2675 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2679 + if (acl_d->next < 0) {
2684 + if (acl_d->next >= acl_d->count) {
2688 + *entry_p = &acl_d->acl[acl_d->next++];
2693 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2695 + *type_p = entry_d->a_type;
2700 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2702 + *permset_p = &entry_d->a_perm;
2707 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2709 + if (entry_d->a_type != SMB_ACL_USER
2710 + && entry_d->a_type != SMB_ACL_GROUP) {
2715 + return &entry_d->a_id;
2719 + * There is no way of knowing what size the ACL returned by
2720 + * ACL_GET will be unless you first call ACL_CNT which means
2721 + * making an additional system call.
2723 + * In the hope of avoiding the cost of the additional system
2724 + * call in most cases, we initially allocate enough space for
2725 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2726 + * be too small then we use ACL_CNT to find out the actual
2727 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2730 +#define INITIAL_ACL_SIZE 16
2732 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2735 + int count; /* # of ACL entries allocated */
2736 + int naccess; /* # of access ACL entries */
2737 + int ndefault; /* # of default ACL entries */
2739 + if(hpux_acl_call_presence() == False) {
2740 + /* Looks like we don't have the acl() system call on HPUX.
2741 + * May be the system doesn't have the latest version of JFS.
2746 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2751 + count = INITIAL_ACL_SIZE;
2752 + if ((acl_d = sys_acl_init(count)) == NULL) {
2757 + * If there isn't enough space for the ACL entries we use
2758 + * ACL_CNT to determine the actual number of ACL entries
2759 + * reallocate and try again. This is in a loop because it
2760 + * is possible that someone else could modify the ACL and
2761 + * increase the number of entries between the call to
2762 + * ACL_CNT and the call to ACL_GET.
2764 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2766 + sys_acl_free_acl(acl_d);
2768 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2772 + if ((acl_d = sys_acl_init(count)) == NULL) {
2778 + sys_acl_free_acl(acl_d);
2783 + * calculate the number of access and default ACL entries
2785 + * Note: we assume that the acl() system call returned a
2786 + * well formed ACL which is sorted so that all of the
2787 + * access ACL entries preceed any default ACL entries
2789 + for (naccess = 0; naccess < count; naccess++) {
2790 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2793 + ndefault = count - naccess;
2796 + * if the caller wants the default ACL we have to copy
2797 + * the entries down to the start of the acl[] buffer
2798 + * and mask out the ACL_DEFAULT flag from the type field
2800 + if (type == SMB_ACL_TYPE_DEFAULT) {
2803 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2804 + acl_d->acl[i] = acl_d->acl[j];
2805 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2808 + acl_d->count = ndefault;
2810 + acl_d->count = naccess;
2816 +SMB_ACL_T sys_acl_get_fd(int fd)
2819 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2822 + files_struct *fsp = file_find_fd(fd);
2824 + if (fsp == NULL) {
2830 + * We know we're in the same conn context. So we
2831 + * can use the relative path.
2834 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2837 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2844 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2846 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2847 + && perm != SMB_ACL_EXECUTE) {
2852 + if (permset_d == NULL) {
2857 + *permset_d |= perm;
2862 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2864 + return *permset_d & perm;
2867 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2874 + * use an initial estimate of 20 bytes per ACL entry
2875 + * when allocating memory for the text representation
2879 + maxlen = 20 * acl_d->count;
2880 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2885 + for (i = 0; i < acl_d->count; i++) {
2886 + struct acl *ap = &acl_d->acl[i];
2895 + switch (ap->a_type) {
2897 + * for debugging purposes it's probably more
2898 + * useful to dump unknown tag types rather
2899 + * than just returning an error
2902 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2905 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2910 + case SMB_ACL_USER:
2911 + id = uidtoname(ap->a_id);
2912 + case SMB_ACL_USER_OBJ:
2916 + case SMB_ACL_GROUP:
2917 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2918 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2924 + case SMB_ACL_GROUP_OBJ:
2928 + case SMB_ACL_OTHER:
2932 + case SMB_ACL_MASK:
2938 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2939 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2940 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2943 + /* <tag> : <qualifier> : rwx \n \0 */
2944 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2947 + * If this entry would overflow the buffer
2948 + * allocate enough additional memory for this
2949 + * entry and an estimate of another 20 bytes
2950 + * for each entry still to be processed
2952 + if ((len + nbytes) > maxlen) {
2953 + char *oldtext = text;
2955 + maxlen += nbytes + 20 * (acl_d->count - i);
2957 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2964 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2965 + len += nbytes - 1;
2974 +SMB_ACL_T sys_acl_init(int count)
2984 + * note that since the definition of the structure pointed
2985 + * to by the SMB_ACL_T includes the first element of the
2986 + * acl[] array, this actually allocates an ACL with room
2987 + * for (count+1) entries
2989 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2994 + a->size = count + 1;
3002 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3005 + SMB_ACL_ENTRY_T entry_d;
3007 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3012 + if (acl_d->count >= acl_d->size) {
3017 + entry_d = &acl_d->acl[acl_d->count++];
3018 + entry_d->a_type = 0;
3019 + entry_d->a_id = -1;
3020 + entry_d->a_perm = 0;
3021 + *entry_p = entry_d;
3026 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3028 + switch (tag_type) {
3029 + case SMB_ACL_USER:
3030 + case SMB_ACL_USER_OBJ:
3031 + case SMB_ACL_GROUP:
3032 + case SMB_ACL_GROUP_OBJ:
3033 + case SMB_ACL_OTHER:
3034 + case SMB_ACL_MASK:
3035 + entry_d->a_type = tag_type;
3045 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3047 + if (entry_d->a_type != SMB_ACL_GROUP
3048 + && entry_d->a_type != SMB_ACL_USER) {
3053 + entry_d->a_id = *((id_t *)qual_p);
3058 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3060 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3064 + entry_d->a_perm = *permset_d;
3069 +/* Structure to capture the count for each type of ACE. */
3071 +struct hpux_acl_types {
3075 + int n_def_user_obj;
3080 + int n_def_group_obj;
3084 + int n_def_other_obj;
3087 + int n_def_class_obj;
3089 + int n_illegal_obj;
3093 + * Counts the different number of objects in a given array of ACL
3097 + * acl_count - Count of ACLs in the array of ACL strucutres.
3098 + * aclp - Array of ACL structures.
3099 + * acl_type_count - Pointer to acl_types structure. Should already be
3103 + * acl_type_count - This structure is filled up with counts of various
3107 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3111 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3113 + for(i=0;i<acl_count;i++) {
3114 + switch(aclp[i].a_type) {
3116 + acl_type_count->n_user++;
3119 + acl_type_count->n_user_obj++;
3121 + case DEF_USER_OBJ:
3122 + acl_type_count->n_def_user_obj++;
3125 + acl_type_count->n_group++;
3128 + acl_type_count->n_group_obj++;
3130 + case DEF_GROUP_OBJ:
3131 + acl_type_count->n_def_group_obj++;
3134 + acl_type_count->n_other_obj++;
3136 + case DEF_OTHER_OBJ:
3137 + acl_type_count->n_def_other_obj++;
3140 + acl_type_count->n_class_obj++;
3142 + case DEF_CLASS_OBJ:
3143 + acl_type_count->n_def_class_obj++;
3146 + acl_type_count->n_def_user++;
3149 + acl_type_count->n_def_group++;
3152 + acl_type_count->n_illegal_obj++;
3158 +/* swap_acl_entries: Swaps two ACL entries.
3160 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3163 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3165 + struct acl temp_acl;
3167 + temp_acl.a_type = aclp0->a_type;
3168 + temp_acl.a_id = aclp0->a_id;
3169 + temp_acl.a_perm = aclp0->a_perm;
3171 + aclp0->a_type = aclp1->a_type;
3172 + aclp0->a_id = aclp1->a_id;
3173 + aclp0->a_perm = aclp1->a_perm;
3175 + aclp1->a_type = temp_acl.a_type;
3176 + aclp1->a_id = temp_acl.a_id;
3177 + aclp1->a_perm = temp_acl.a_perm;
3180 +/* prohibited_duplicate_type
3181 + * Identifies if given ACL type can have duplicate entries or
3184 + * Inputs: acl_type - ACL Type.
3190 + * True - If the ACL type matches any of the prohibited types.
3191 + * False - If the ACL type doesn't match any of the prohibited types.
3194 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3196 + switch(acl_type) {
3207 +/* get_needed_class_perm
3208 + * Returns the permissions of a ACL structure only if the ACL
3209 + * type matches one of the pre-determined types for computing
3210 + * CLASS_OBJ permissions.
3212 + * Inputs: aclp - Pointer to ACL structure.
3215 +static int hpux_get_needed_class_perm(struct acl *aclp)
3217 + switch(aclp->a_type) {
3221 + case DEF_USER_OBJ:
3223 + case DEF_GROUP_OBJ:
3225 + case DEF_CLASS_OBJ:
3226 + case DEF_OTHER_OBJ:
3227 + return aclp->a_perm;
3233 +/* acl_sort for HPUX.
3234 + * Sorts the array of ACL structures as per the description in
3235 + * aclsort man page. Refer to aclsort man page for more details
3239 + * acl_count - Count of ACLs in the array of ACL structures.
3240 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3242 + * aclp - Array of ACL structures.
3246 + * aclp - Sorted array of ACL structures.
3250 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3251 + * debug log in case of failure.
3254 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3256 +#if !defined(HAVE_HPUX_ACLSORT)
3258 + * The aclsort() system call is availabe on the latest HPUX General
3259 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3260 + * function. Because, we don't want to update to a new
3261 + * HPUX GR bundle just for aclsort() call.
3264 + struct hpux_acl_types acl_obj_count;
3265 + int n_class_obj_perm = 0;
3269 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3273 + if(aclp == NULL) {
3274 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3278 + /* Count different types of ACLs in the ACLs array */
3280 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3282 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3283 + * CLASS_OBJ and OTHER_OBJ
3286 + if( (acl_obj_count.n_user_obj != 1) ||
3287 + (acl_obj_count.n_group_obj != 1) ||
3288 + (acl_obj_count.n_class_obj != 1) ||
3289 + (acl_obj_count.n_other_obj != 1)
3291 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3292 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3296 + /* If any of the default objects are present, there should be only
3297 + * one of them each.
3300 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3301 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3302 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3303 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3307 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3310 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3311 + * same ACL type, sort by ACL id.
3313 + * I am using the trival kind of sorting method here because, performance isn't
3314 + * really effected by the ACLs feature. More over there aren't going to be more
3315 + * than 17 entries on HPUX.
3318 + for(i=0; i<acl_count;i++) {
3319 + for (j=i+1; j<acl_count; j++) {
3320 + if( aclp[i].a_type > aclp[j].a_type ) {
3321 + /* ACL entries out of order, swap them */
3323 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3325 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3327 + /* ACL entries of same type, sort by id */
3329 + if(aclp[i].a_id > aclp[j].a_id) {
3330 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3331 + } else if (aclp[i].a_id == aclp[j].a_id) {
3332 + /* We have a duplicate entry. */
3333 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3334 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3335 + aclp[i].a_type, aclp[i].a_id));
3344 + /* set the class obj permissions to the computed one. */
3346 + int n_class_obj_index = -1;
3348 + for(i=0;i<acl_count;i++) {
3349 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3351 + if(aclp[i].a_type == CLASS_OBJ)
3352 + n_class_obj_index = i;
3354 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3359 + return aclsort(acl_count, calclass, aclp);
3364 + * sort the ACL and check it for validity
3366 + * if it's a minimal ACL with only 4 entries then we
3367 + * need to recalculate the mask permissions to make
3368 + * sure that they are the same as the GROUP_OBJ
3369 + * permissions as required by the UnixWare acl() system call.
3371 + * (note: since POSIX allows minimal ACLs which only contain
3372 + * 3 entries - ie there is no mask entry - we should, in theory,
3373 + * check for this and add a mask entry if necessary - however
3374 + * we "know" that the caller of this interface always specifies
3375 + * a mask so, in practice "this never happens" (tm) - if it *does*
3376 + * happen aclsort() will fail and return an error and someone will
3377 + * have to fix it ...)
3380 +static int acl_sort(SMB_ACL_T acl_d)
3382 + int fixmask = (acl_d->count <= 4);
3384 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3391 +int sys_acl_valid(SMB_ACL_T acl_d)
3393 + return acl_sort(acl_d);
3396 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3399 + struct acl *acl_p;
3401 + struct acl *acl_buf = NULL;
3404 + if(hpux_acl_call_presence() == False) {
3405 + /* Looks like we don't have the acl() system call on HPUX.
3406 + * May be the system doesn't have the latest version of JFS.
3412 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3417 + if (acl_sort(acl_d) != 0) {
3421 + acl_p = &acl_d->acl[0];
3422 + acl_count = acl_d->count;
3425 + * if it's a directory there is extra work to do
3426 + * since the acl() system call will replace both
3427 + * the access ACLs and the default ACLs (if any)
3429 + if (stat(name, &s) != 0) {
3432 + if (S_ISDIR(s.st_mode)) {
3433 + SMB_ACL_T acc_acl;
3434 + SMB_ACL_T def_acl;
3435 + SMB_ACL_T tmp_acl;
3438 + if (type == SMB_ACL_TYPE_ACCESS) {
3440 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3444 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3447 + if (tmp_acl == NULL) {
3452 + * allocate a temporary buffer for the complete ACL
3454 + acl_count = acc_acl->count + def_acl->count;
3455 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3457 + if (acl_buf == NULL) {
3458 + sys_acl_free_acl(tmp_acl);
3464 + * copy the access control and default entries into the buffer
3466 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3467 + acc_acl->count * sizeof(acl_buf[0]));
3469 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3470 + def_acl->count * sizeof(acl_buf[0]));
3473 + * set the ACL_DEFAULT flag on the default entries
3475 + for (i = acc_acl->count; i < acl_count; i++) {
3476 + acl_buf[i].a_type |= ACL_DEFAULT;
3479 + sys_acl_free_acl(tmp_acl);
3481 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3486 + ret = acl(name, ACL_SET, acl_count, acl_p);
3495 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3498 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3501 + files_struct *fsp = file_find_fd(fd);
3503 + if (fsp == NULL) {
3508 + if (acl_sort(acl_d) != 0) {
3513 + * We know we're in the same conn context. So we
3514 + * can use the relative path.
3517 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3520 +int sys_acl_delete_def_file(const char *path)
3526 + * fetching the access ACL and rewriting it has
3527 + * the effect of deleting the default ACL
3529 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3533 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3535 + sys_acl_free_acl(acl_d);
3540 +int sys_acl_free_text(char *text)
3546 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3552 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3557 +#elif defined(HAVE_IRIX_ACLS)
3559 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3561 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3566 + if (entry_p == NULL) {
3571 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3575 + if (acl_d->next < 0) {
3580 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3584 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3589 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3591 + *type_p = entry_d->ae_tag;
3596 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3598 + *permset_p = entry_d;
3603 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3605 + if (entry_d->ae_tag != SMB_ACL_USER
3606 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3611 + return &entry_d->ae_id;
3614 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3618 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3622 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3627 + a->freeaclp = True;
3631 +SMB_ACL_T sys_acl_get_fd(int fd)
3635 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3639 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3644 + a->freeaclp = True;
3648 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3650 + permset_d->ae_perm = 0;
3655 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3657 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3658 + && perm != SMB_ACL_EXECUTE) {
3663 + if (permset_d == NULL) {
3668 + permset_d->ae_perm |= perm;
3673 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3675 + return permset_d->ae_perm & perm;
3678 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3680 + return acl_to_text(acl_d->aclp, len_p);
3683 +SMB_ACL_T sys_acl_init(int count)
3692 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3698 + a->freeaclp = False;
3699 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3700 + a->aclp->acl_cnt = 0;
3706 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3709 + SMB_ACL_ENTRY_T entry_d;
3711 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3716 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3721 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3722 + entry_d->ae_tag = 0;
3723 + entry_d->ae_id = 0;
3724 + entry_d->ae_perm = 0;
3725 + *entry_p = entry_d;
3730 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3732 + switch (tag_type) {
3733 + case SMB_ACL_USER:
3734 + case SMB_ACL_USER_OBJ:
3735 + case SMB_ACL_GROUP:
3736 + case SMB_ACL_GROUP_OBJ:
3737 + case SMB_ACL_OTHER:
3738 + case SMB_ACL_MASK:
3739 + entry_d->ae_tag = tag_type;
3749 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3751 + if (entry_d->ae_tag != SMB_ACL_GROUP
3752 + && entry_d->ae_tag != SMB_ACL_USER) {
3757 + entry_d->ae_id = *((id_t *)qual_p);
3762 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3764 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3768 + entry_d->ae_perm = permset_d->ae_perm;
3773 +int sys_acl_valid(SMB_ACL_T acl_d)
3775 + return acl_valid(acl_d->aclp);
3778 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3780 + return acl_set_file(name, type, acl_d->aclp);
3783 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3785 + return acl_set_fd(fd, acl_d->aclp);
3788 +int sys_acl_delete_def_file(const char *name)
3790 + return acl_delete_def_file(name);
3793 +int sys_acl_free_text(char *text)
3795 + return acl_free(text);
3798 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3800 + if (acl_d->freeaclp) {
3801 + acl_free(acl_d->aclp);
3807 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3812 +#elif defined(HAVE_AIX_ACLS)
3814 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3816 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3818 + struct acl_entry_link *link;
3819 + struct new_acl_entry *entry;
3822 + DEBUG(10,("This is the count: %d\n",theacl->count));
3824 + /* Check if count was previously set to -1. *
3825 + * If it was, that means we reached the end *
3826 + * of the acl last time. */
3827 + if(theacl->count == -1)
3831 + /* To get to the next acl, traverse linked list until index *
3832 + * of acl matches the count we are keeping. This count is *
3833 + * incremented each time we return an acl entry. */
3835 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3836 + link = link->nextp;
3838 + entry = *entry_p = link->entryp;
3840 + DEBUG(10,("*entry_p is %d\n",entry_p));
3841 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3843 + /* Increment count */
3845 + if(link->nextp == NULL)
3846 + theacl->count = -1;
3851 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3853 + /* Initialize tag type */
3856 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3858 + /* Depending on what type of entry we have, *
3859 + * return tag type. */
3860 + switch(entry_d->ace_id->id_type) {
3862 + *tag_type_p = SMB_ACL_USER;
3865 + *tag_type_p = SMB_ACL_GROUP;
3868 + case SMB_ACL_USER_OBJ:
3869 + case SMB_ACL_GROUP_OBJ:
3870 + case SMB_ACL_OTHER:
3871 + *tag_type_p = entry_d->ace_id->id_type;
3881 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3883 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3884 + *permset_p = &entry_d->ace_access;
3885 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3886 + if(!(**permset_p & S_IXUSR) &&
3887 + !(**permset_p & S_IWUSR) &&
3888 + !(**permset_p & S_IRUSR) &&
3889 + (**permset_p != 0))
3892 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3896 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3898 + return(entry_d->ace_id->id_data);
3901 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3903 + struct acl *file_acl = (struct acl *)NULL;
3904 + struct acl_entry *acl_entry;
3905 + struct new_acl_entry *new_acl_entry;
3906 + struct ace_id *idp;
3907 + struct acl_entry_link *acl_entry_link;
3908 + struct acl_entry_link *acl_entry_link_head;
3913 + /* AIX has no DEFAULT */
3914 + if ( type == SMB_ACL_TYPE_DEFAULT )
3917 + /* Get the acl using statacl */
3919 + DEBUG(10,("Entering sys_acl_get_file\n"));
3920 + DEBUG(10,("path_p is %s\n",path_p));
3922 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3924 + if(file_acl == NULL) {
3926 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3930 + memset(file_acl,0,BUFSIZ);
3932 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3934 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3935 + SAFE_FREE(file_acl);
3939 + DEBUG(10,("Got facl and returned it\n"));
3941 + /* Point to the first acl entry in the acl */
3942 + acl_entry = file_acl->acl_ext;
3944 + /* Begin setting up the head of the linked list *
3945 + * that will be used for the storing the acl *
3946 + * in a way that is useful for the posix_acls.c *
3949 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3950 + if(acl_entry_link_head == NULL)
3953 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3954 + if(acl_entry_link->entryp == NULL) {
3955 + SAFE_FREE(file_acl);
3957 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3961 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3962 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3964 + /* Check if the extended acl bit is on. *
3965 + * If it isn't, do not show the *
3966 + * contents of the acl since AIX intends *
3967 + * the extended info to remain unused */
3969 + if(file_acl->acl_mode & S_IXACL){
3970 + /* while we are not pointing to the very end */
3971 + while(acl_entry < acl_last(file_acl)) {
3972 + /* before we malloc anything, make sure this is */
3973 + /* a valid acl entry and one that we want to map */
3974 + idp = id_nxt(acl_entry->ace_id);
3975 + if((acl_entry->ace_type == ACC_SPECIFY ||
3976 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3977 + acl_entry = acl_nxt(acl_entry);
3981 + idp = acl_entry->ace_id;
3983 + /* Check if this is the first entry in the linked list. *
3984 + * The first entry needs to keep prevp pointing to NULL *
3985 + * and already has entryp allocated. */
3987 + if(acl_entry_link_head->count != 0) {
3988 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3990 + if(acl_entry_link->nextp == NULL) {
3991 + SAFE_FREE(file_acl);
3993 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3997 + acl_entry_link->nextp->prevp = acl_entry_link;
3998 + acl_entry_link = acl_entry_link->nextp;
3999 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4000 + if(acl_entry_link->entryp == NULL) {
4001 + SAFE_FREE(file_acl);
4003 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4006 + acl_entry_link->nextp = NULL;
4009 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4011 + /* Don't really need this since all types are going *
4012 + * to be specified but, it's better than leaving it 0 */
4014 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4016 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4018 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
4020 + /* The access in the acl entries must be left shifted by *
4021 + * three bites, because they will ultimately be compared *
4022 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4024 + switch(acl_entry->ace_type){
4027 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4028 + acl_entry_link->entryp->ace_access <<= 6;
4029 + acl_entry_link_head->count++;
4032 + /* Since there is no way to return a DENY acl entry *
4033 + * change to PERMIT and then shift. */
4034 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4035 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4036 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4037 + acl_entry_link->entryp->ace_access <<= 6;
4038 + acl_entry_link_head->count++;
4044 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4045 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4047 + acl_entry = acl_nxt(acl_entry);
4049 + } /* end of if enabled */
4051 + /* Since owner, group, other acl entries are not *
4052 + * part of the acl entries in an acl, they must *
4053 + * be dummied up to become part of the list. */
4055 + for( i = 1; i < 4; i++) {
4056 + DEBUG(10,("i is %d\n",i));
4057 + if(acl_entry_link_head->count != 0) {
4058 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4059 + if(acl_entry_link->nextp == NULL) {
4060 + SAFE_FREE(file_acl);
4062 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4066 + acl_entry_link->nextp->prevp = acl_entry_link;
4067 + acl_entry_link = acl_entry_link->nextp;
4068 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4069 + if(acl_entry_link->entryp == NULL) {
4070 + SAFE_FREE(file_acl);
4072 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4077 + acl_entry_link->nextp = NULL;
4079 + new_acl_entry = acl_entry_link->entryp;
4080 + idp = new_acl_entry->ace_id;
4082 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4083 + new_acl_entry->ace_type = ACC_PERMIT;
4084 + idp->id_len = sizeof(struct ace_id);
4085 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4086 + memset(idp->id_data,0,sizeof(uid_t));
4090 + new_acl_entry->ace_access = file_acl->g_access << 6;
4091 + idp->id_type = SMB_ACL_GROUP_OBJ;
4095 + new_acl_entry->ace_access = file_acl->o_access << 6;
4096 + idp->id_type = SMB_ACL_OTHER;
4100 + new_acl_entry->ace_access = file_acl->u_access << 6;
4101 + idp->id_type = SMB_ACL_USER_OBJ;
4109 + acl_entry_link_head->count++;
4110 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4113 + acl_entry_link_head->count = 0;
4114 + SAFE_FREE(file_acl);
4116 + return(acl_entry_link_head);
4119 +SMB_ACL_T sys_acl_get_fd(int fd)
4121 + struct acl *file_acl = (struct acl *)NULL;
4122 + struct acl_entry *acl_entry;
4123 + struct new_acl_entry *new_acl_entry;
4124 + struct ace_id *idp;
4125 + struct acl_entry_link *acl_entry_link;
4126 + struct acl_entry_link *acl_entry_link_head;
4131 + /* Get the acl using fstatacl */
4133 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4134 + DEBUG(10,("fd is %d\n",fd));
4135 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4137 + if(file_acl == NULL) {
4139 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4143 + memset(file_acl,0,BUFSIZ);
4145 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4147 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4148 + SAFE_FREE(file_acl);
4152 + DEBUG(10,("Got facl and returned it\n"));
4154 + /* Point to the first acl entry in the acl */
4156 + acl_entry = file_acl->acl_ext;
4157 + /* Begin setting up the head of the linked list *
4158 + * that will be used for the storing the acl *
4159 + * in a way that is useful for the posix_acls.c *
4162 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4163 + if(acl_entry_link_head == NULL){
4164 + SAFE_FREE(file_acl);
4168 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4170 + if(acl_entry_link->entryp == NULL) {
4172 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4173 + SAFE_FREE(file_acl);
4177 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4178 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4180 + /* Check if the extended acl bit is on. *
4181 + * If it isn't, do not show the *
4182 + * contents of the acl since AIX intends *
4183 + * the extended info to remain unused */
4185 + if(file_acl->acl_mode & S_IXACL){
4186 + /* while we are not pointing to the very end */
4187 + while(acl_entry < acl_last(file_acl)) {
4188 + /* before we malloc anything, make sure this is */
4189 + /* a valid acl entry and one that we want to map */
4191 + idp = id_nxt(acl_entry->ace_id);
4192 + if((acl_entry->ace_type == ACC_SPECIFY ||
4193 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4194 + acl_entry = acl_nxt(acl_entry);
4198 + idp = acl_entry->ace_id;
4200 + /* Check if this is the first entry in the linked list. *
4201 + * The first entry needs to keep prevp pointing to NULL *
4202 + * and already has entryp allocated. */
4204 + if(acl_entry_link_head->count != 0) {
4205 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4206 + if(acl_entry_link->nextp == NULL) {
4208 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4209 + SAFE_FREE(file_acl);
4212 + acl_entry_link->nextp->prevp = acl_entry_link;
4213 + acl_entry_link = acl_entry_link->nextp;
4214 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4215 + if(acl_entry_link->entryp == NULL) {
4217 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4218 + SAFE_FREE(file_acl);
4222 + acl_entry_link->nextp = NULL;
4225 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4227 + /* Don't really need this since all types are going *
4228 + * to be specified but, it's better than leaving it 0 */
4230 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4231 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4233 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4235 + /* The access in the acl entries must be left shifted by *
4236 + * three bites, because they will ultimately be compared *
4237 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4239 + switch(acl_entry->ace_type){
4242 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4243 + acl_entry_link->entryp->ace_access <<= 6;
4244 + acl_entry_link_head->count++;
4247 + /* Since there is no way to return a DENY acl entry *
4248 + * change to PERMIT and then shift. */
4249 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4250 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4251 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4252 + acl_entry_link->entryp->ace_access <<= 6;
4253 + acl_entry_link_head->count++;
4259 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4260 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4262 + acl_entry = acl_nxt(acl_entry);
4264 + } /* end of if enabled */
4266 + /* Since owner, group, other acl entries are not *
4267 + * part of the acl entries in an acl, they must *
4268 + * be dummied up to become part of the list. */
4270 + for( i = 1; i < 4; i++) {
4271 + DEBUG(10,("i is %d\n",i));
4272 + if(acl_entry_link_head->count != 0){
4273 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4274 + if(acl_entry_link->nextp == NULL) {
4276 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4277 + SAFE_FREE(file_acl);
4281 + acl_entry_link->nextp->prevp = acl_entry_link;
4282 + acl_entry_link = acl_entry_link->nextp;
4283 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4285 + if(acl_entry_link->entryp == NULL) {
4286 + SAFE_FREE(file_acl);
4288 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4293 + acl_entry_link->nextp = NULL;
4295 + new_acl_entry = acl_entry_link->entryp;
4296 + idp = new_acl_entry->ace_id;
4298 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4299 + new_acl_entry->ace_type = ACC_PERMIT;
4300 + idp->id_len = sizeof(struct ace_id);
4301 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4302 + memset(idp->id_data,0,sizeof(uid_t));
4306 + new_acl_entry->ace_access = file_acl->g_access << 6;
4307 + idp->id_type = SMB_ACL_GROUP_OBJ;
4311 + new_acl_entry->ace_access = file_acl->o_access << 6;
4312 + idp->id_type = SMB_ACL_OTHER;
4316 + new_acl_entry->ace_access = file_acl->u_access << 6;
4317 + idp->id_type = SMB_ACL_USER_OBJ;
4324 + acl_entry_link_head->count++;
4325 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4328 + acl_entry_link_head->count = 0;
4329 + SAFE_FREE(file_acl);
4331 + return(acl_entry_link_head);
4334 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4336 + *permset = *permset & ~0777;
4340 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4343 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4347 + DEBUG(10,("This is the permset now: %d\n",*permset));
4351 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4356 +SMB_ACL_T sys_acl_init( int count)
4358 + struct acl_entry_link *theacl = NULL;
4360 + DEBUG(10,("Entering sys_acl_init\n"));
4362 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4363 + if(theacl == NULL) {
4365 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4369 + theacl->count = 0;
4370 + theacl->nextp = NULL;
4371 + theacl->prevp = NULL;
4372 + theacl->entryp = NULL;
4373 + DEBUG(10,("Exiting sys_acl_init\n"));
4377 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4379 + struct acl_entry_link *theacl;
4380 + struct acl_entry_link *acl_entryp;
4381 + struct acl_entry_link *temp_entry;
4384 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4386 + theacl = acl_entryp = *pacl;
4388 + /* Get to the end of the acl before adding entry */
4390 + for(counting=0; counting < theacl->count; counting++){
4391 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4392 + temp_entry = acl_entryp;
4393 + acl_entryp = acl_entryp->nextp;
4396 + if(theacl->count != 0){
4397 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4398 + if(acl_entryp == NULL) {
4400 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4404 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4405 + acl_entryp->prevp = temp_entry;
4406 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4409 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4410 + if(*pentry == NULL) {
4412 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4416 + memset(*pentry,0,sizeof(struct new_acl_entry));
4417 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4418 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4419 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4420 + acl_entryp->nextp = NULL;
4422 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4426 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4428 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4429 + entry->ace_id->id_type = tagtype;
4430 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4431 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4434 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4436 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4437 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4438 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4442 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4444 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4445 + if(!(*permset & S_IXUSR) &&
4446 + !(*permset & S_IWUSR) &&
4447 + !(*permset & S_IRUSR) &&
4451 + entry->ace_access = *permset;
4452 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4453 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4457 +int sys_acl_valid( SMB_ACL_T theacl )
4460 + int group_obj = 0;
4461 + int other_obj = 0;
4462 + struct acl_entry_link *acl_entry;
4464 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4465 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4466 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4467 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4470 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4472 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4478 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4480 + struct acl_entry_link *acl_entry_link = NULL;
4481 + struct acl *file_acl = NULL;
4482 + struct acl *file_acl_temp = NULL;
4483 + struct acl_entry *acl_entry = NULL;
4484 + struct ace_id *ace_id = NULL;
4491 + DEBUG(10,("Entering sys_acl_set_file\n"));
4492 + DEBUG(10,("File name is %s\n",name));
4494 + /* AIX has no default ACL */
4495 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4498 + acl_length = BUFSIZ;
4499 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4501 + if(file_acl == NULL) {
4503 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4507 + memset(file_acl,0,BUFSIZ);
4509 + file_acl->acl_len = ACL_SIZ;
4510 + file_acl->acl_mode = S_IXACL;
4512 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4513 + acl_entry_link->entryp->ace_access >>= 6;
4514 + id_type = acl_entry_link->entryp->ace_id->id_type;
4517 + case SMB_ACL_USER_OBJ:
4518 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4520 + case SMB_ACL_GROUP_OBJ:
4521 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4523 + case SMB_ACL_OTHER:
4524 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4526 + case SMB_ACL_MASK:
4530 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4531 + acl_length += sizeof(struct acl_entry);
4532 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4533 + if(file_acl_temp == NULL) {
4534 + SAFE_FREE(file_acl);
4536 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4540 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4541 + SAFE_FREE(file_acl);
4542 + file_acl = file_acl_temp;
4545 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4546 + file_acl->acl_len += sizeof(struct acl_entry);
4547 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4548 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4550 + /* In order to use this, we'll need to wait until we can get denies */
4551 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4552 + acl_entry->ace_type = ACC_SPECIFY; */
4554 + acl_entry->ace_type = ACC_SPECIFY;
4556 + ace_id = acl_entry->ace_id;
4558 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4559 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4560 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4561 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4562 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4565 + rc = chacl(name,file_acl,file_acl->acl_len);
4566 + DEBUG(10,("errno is %d\n",errno));
4567 + DEBUG(10,("return code is %d\n",rc));
4568 + SAFE_FREE(file_acl);
4569 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4573 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4575 + struct acl_entry_link *acl_entry_link = NULL;
4576 + struct acl *file_acl = NULL;
4577 + struct acl *file_acl_temp = NULL;
4578 + struct acl_entry *acl_entry = NULL;
4579 + struct ace_id *ace_id = NULL;
4585 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4586 + acl_length = BUFSIZ;
4587 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4589 + if(file_acl == NULL) {
4591 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4595 + memset(file_acl,0,BUFSIZ);
4597 + file_acl->acl_len = ACL_SIZ;
4598 + file_acl->acl_mode = S_IXACL;
4600 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4601 + acl_entry_link->entryp->ace_access >>= 6;
4602 + id_type = acl_entry_link->entryp->ace_id->id_type;
4603 + DEBUG(10,("The id_type is %d\n",id_type));
4606 + case SMB_ACL_USER_OBJ:
4607 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4609 + case SMB_ACL_GROUP_OBJ:
4610 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4612 + case SMB_ACL_OTHER:
4613 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4615 + case SMB_ACL_MASK:
4619 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4620 + acl_length += sizeof(struct acl_entry);
4621 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4622 + if(file_acl_temp == NULL) {
4623 + SAFE_FREE(file_acl);
4625 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4629 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4630 + SAFE_FREE(file_acl);
4631 + file_acl = file_acl_temp;
4634 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4635 + file_acl->acl_len += sizeof(struct acl_entry);
4636 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4637 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4639 + /* In order to use this, we'll need to wait until we can get denies */
4640 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4641 + acl_entry->ace_type = ACC_SPECIFY; */
4643 + acl_entry->ace_type = ACC_SPECIFY;
4645 + ace_id = acl_entry->ace_id;
4647 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4648 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4649 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4650 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4651 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4654 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4655 + DEBUG(10,("errno is %d\n",errno));
4656 + DEBUG(10,("return code is %d\n",rc));
4657 + SAFE_FREE(file_acl);
4658 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4662 +int sys_acl_delete_def_file(const char *name)
4664 + /* AIX has no default ACL */
4668 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4670 + return(*permset & perm);
4673 +int sys_acl_free_text(char *text)
4678 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4680 + struct acl_entry_link *acl_entry_link;
4682 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4683 + SAFE_FREE(acl_entry_link->prevp->entryp);
4684 + SAFE_FREE(acl_entry_link->prevp);
4687 + SAFE_FREE(acl_entry_link->prevp->entryp);
4688 + SAFE_FREE(acl_entry_link->prevp);
4689 + SAFE_FREE(acl_entry_link->entryp);
4690 + SAFE_FREE(acl_entry_link);
4695 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4700 +#else /* No ACLs. */
4702 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4708 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4714 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4720 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4726 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4729 + return (SMB_ACL_T)NULL;
4732 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4735 + return (SMB_ACL_T)NULL;
4738 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4744 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4750 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4753 + return (permset & perm) ? 1 : 0;
4756 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4762 +int sys_acl_free_text(UNUSED(char *text))
4768 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4774 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4780 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4786 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4792 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4798 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4804 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4810 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4816 +int sys_acl_delete_def_file(UNUSED(const char *name))
4822 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4828 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4834 +#endif /* No ACLs. */
4836 +/************************************************************************
4837 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4839 +************************************************************************/
4841 +int no_acl_syscall_error(int err)
4843 +#if defined(ENOSYS)
4844 + if (err == ENOSYS) {
4848 +#if defined(ENOTSUP)
4849 + if (err == ENOTSUP) {
4855 --- old/lib/sysacls.h
4856 +++ new/lib/sysacls.h
4858 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4859 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4860 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4861 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4862 +#define slprintf snprintf
4864 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4865 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4866 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4867 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4868 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4869 +SMB_ACL_T sys_acl_get_fd(int fd);
4870 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4871 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4872 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4873 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4874 +SMB_ACL_T sys_acl_init(int count);
4875 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4876 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4877 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4878 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4879 +int sys_acl_valid(SMB_ACL_T theacl);
4880 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4881 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4882 +int sys_acl_delete_def_file(const char *name);
4883 +int sys_acl_free_text(char *text);
4884 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4885 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4888 @@ -58,7 +58,7 @@ BEGIN {
4892 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4893 +!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4899 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4901 int preserve_links = 0;
4902 int preserve_hard_links = 0;
4903 +int preserve_acls = 0;
4904 int preserve_perms = 0;
4905 int preserve_executability = 0;
4906 int preserve_devices = 0;
4907 @@ -192,6 +193,7 @@ static void print_rsync_version(enum log
4908 char const *got_socketpair = "no ";
4909 char const *have_inplace = "no ";
4910 char const *hardlinks = "no ";
4911 + char const *acls = "no ";
4912 char const *links = "no ";
4913 char const *ipv6 = "no ";
4914 STRUCT_STAT *dumstat;
4915 @@ -208,6 +210,10 @@ static void print_rsync_version(enum log
4919 +#ifdef SUPPORT_ACLS
4923 #ifdef SUPPORT_LINKS
4926 @@ -221,9 +227,9 @@ static void print_rsync_version(enum log
4927 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4928 rprintf(f, "<http://rsync.samba.org/>\n");
4929 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4930 - "%shard links, %ssymlinks, batchfiles,\n",
4931 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4932 (int) (sizeof (OFF_T) * 8),
4933 - got_socketpair, hardlinks, links);
4934 + got_socketpair, hardlinks, acls, links);
4936 /* Note that this field may not have type ino_t. It depends
4937 * on the complicated interaction between largefile feature
4938 @@ -293,6 +299,9 @@ void usage(enum logcode F)
4939 rprintf(F," -H, --hard-links preserve hard links\n");
4940 rprintf(F," -p, --perms preserve permissions\n");
4941 rprintf(F," -E, --executability preserve the file's executability\n");
4942 +#ifdef SUPPORT_ACLS
4943 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4945 rprintf(F," --chmod=CHMOD change destination permissions\n");
4946 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4947 rprintf(F," -g, --group preserve group\n");
4948 @@ -408,6 +417,9 @@ static struct poptOption long_options[]
4949 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4950 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4951 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4952 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4953 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4954 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4955 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4956 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4957 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4958 @@ -1066,6 +1078,24 @@ int parse_arguments(int *argc, const cha
4963 +#ifdef SUPPORT_ACLS
4965 + preserve_perms = 1;
4968 + /* FIXME: this should probably be ignored with a
4969 + * warning and then countermeasures taken to
4970 + * restrict group and other access in the presence
4971 + * of any more restrictive ACLs, but this is safe
4973 + snprintf(err_buf,sizeof(err_buf),
4974 + "ACLs are not supported on this %s\n",
4975 + am_server ? "server" : "client");
4981 /* A large opt value means that set_refuse_options()
4982 * turned this option off. */
4983 @@ -1508,6 +1538,10 @@ void server_options(char **args,int *arg
4985 if (preserve_hard_links)
4987 +#ifdef SUPPORT_ACLS
4988 + if (preserve_acls)
4989 + argstr[x++] = 'A';
4996 @@ -46,6 +46,7 @@ extern int keep_partial;
4997 extern int checksum_seed;
4999 extern int delay_updates;
5000 +extern mode_t orig_umask;
5001 extern struct stats stats;
5002 extern char *log_format;
5003 extern char *tmpdir;
5004 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
5005 int itemizing = am_daemon ? daemon_log_format_has_i
5006 : !am_server && log_format_has_i;
5007 int max_phase = protocol_version >= 29 ? 2 : 1;
5008 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
5009 +#ifdef SUPPORT_ACLS
5010 + char *parent_dirname = "";
5015 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
5016 * mode based on the local permissions and some heuristics. */
5017 if (!preserve_perms) {
5018 int exists = fd1 != -1;
5019 - file->mode = dest_mode(file->mode, st.st_mode, exists);
5020 +#ifdef SUPPORT_ACLS
5021 + char *dn = file->dirname ? file->dirname : ".";
5022 + if (parent_dirname != dn
5023 + && strcmp(parent_dirname, dn) != 0) {
5024 + dflt_perms = default_perms_for_dir(dn);
5025 + parent_dirname = dn;
5028 + file->mode = dest_mode(file->mode, st.st_mode,
5029 + dflt_perms, exists);
5032 /* We now check to see if we are writing file "inplace" */
5038 extern int daemon_log_format_has_i;
5039 +extern int preserve_acls;
5040 extern int preserve_perms;
5041 extern int preserve_executability;
5042 extern int preserve_times;
5043 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
5045 /* This is only called when we aren't preserving permissions. Figure out what
5046 * the permissions should be and return them merged back into the mode. */
5047 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5048 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5051 /* If the file already exists, we'll return the local permissions,
5052 * possibly tweaked by the --executability option. */
5053 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
5054 cur_mode |= (cur_mode & 0444) >> 2;
5057 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5058 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5059 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5060 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5061 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5062 @@ -203,6 +205,17 @@ int set_file_attrs(char *fname, struct f
5066 +#ifdef SUPPORT_ACLS
5067 + /* It's OK to call set_acl() now, even for a dir, as the generator
5068 + * will enable owner-writability using chmod, if necessary.
5070 + * If set_acl changes permission bits in the process of setting
5071 + * an access ACL, it changes st->st_mode so we know whether we
5072 + * need to chmod. */
5073 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5078 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5079 int ret = do_chmod(fname, file->mode);
5082 @@ -660,6 +660,20 @@ struct chmod_mode_struct;
5084 #define UNUSED(x) x __attribute__((__unused__))
5086 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5087 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5088 +#define SUPPORT_ACLS 1
5091 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5092 +#define ACLS_NEED_MASK 1
5095 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5096 +#include <sys/acl.h>
5098 +#include "smb_acls.h"
5102 /* We have replacement versions of these if they're missing. */
5105 @@ -321,6 +321,7 @@ to the detailed description below for a
5106 -H, --hard-links preserve hard links
5107 -p, --perms preserve permissions
5108 -E, --executability preserve executability
5109 + -A, --acls preserve ACLs (implies -p) [non-standard]
5110 --chmod=CHMOD change destination permissions
5111 -o, --owner preserve owner (super-user only)
5112 -g, --group preserve group
5113 @@ -742,7 +743,9 @@ quote(itemize(
5114 permissions, though the bf(--executability) option might change just
5115 the execute permission for the file.
5116 it() New files get their "normal" permission bits set to the source
5117 - file's permissions masked with the receiving end's umask setting, and
5118 + file's permissions masked with the receiving directory's default
5119 + permissions (either the receiving process's umask, or the permissions
5120 + specified via the destination directory's default ACL), and
5121 their special permission bits disabled except in the case where a new
5122 directory inherits a setgid bit from its parent directory.
5124 @@ -773,9 +776,11 @@ The preservation of the destination's se
5125 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5126 versions erroneously preserved the three special permission bits for
5127 newly-created files when bf(--perms) was off, while overriding the
5128 -destination's setgid bit setting on a newly-created directory. (Keep in
5129 -mind that it is the version of the receiving rsync that affects this
5131 +destination's setgid bit setting on a newly-created directory. Default ACL
5132 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5133 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5134 +(Keep in mind that it is the version of the receiving rsync that affects
5137 dit(bf(-E, --executability)) This option causes rsync to preserve the
5138 executability (or non-executability) of regular files when bf(--perms) is
5139 @@ -793,6 +798,15 @@ quote(itemize(
5141 If bf(--perms) is enabled, this option is ignored.
5143 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5144 +ACLs to be the same as the source ACLs. This nonstandard option only
5145 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5147 +Note also that an optimization of the ACL-sending protocol used by this
5148 +version makes it incompatible with sending files to an older ACL-enabled
5149 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5150 +doubling is not needed when pulling files from an older rsync.
5152 dit(bf(--chmod)) This option tells rsync to apply one or more
5153 comma-separated "chmod" strings to the permission of the files in the
5154 transfer. The resulting value is treated as though it was the permissions
5159 + Unix SMB/Netbios implementation.
5161 + Portable SMB ACL interface
5162 + Copyright (C) Jeremy Allison 2000
5164 + This program is free software; you can redistribute it and/or modify
5165 + it under the terms of the GNU General Public License as published by
5166 + the Free Software Foundation; either version 2 of the License, or
5167 + (at your option) any later version.
5169 + This program is distributed in the hope that it will be useful,
5170 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5171 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5172 + GNU General Public License for more details.
5174 + You should have received a copy of the GNU General Public License
5175 + along with this program; if not, write to the Free Software
5176 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5179 +#ifndef _SMB_ACLS_H
5180 +#define _SMB_ACLS_H
5182 +#if defined HAVE_POSIX_ACLS
5184 +/* This is an identity mapping (just remove the SMB_). */
5186 +#define SMB_ACL_TAG_T acl_tag_t
5187 +#define SMB_ACL_TYPE_T acl_type_t
5188 +#define SMB_ACL_PERMSET_T acl_permset_t
5189 +#define SMB_ACL_PERM_T acl_perm_t
5190 +#define SMB_ACL_READ ACL_READ
5191 +#define SMB_ACL_WRITE ACL_WRITE
5192 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5194 +/* Types of ACLs. */
5195 +#define SMB_ACL_USER ACL_USER
5196 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5197 +#define SMB_ACL_GROUP ACL_GROUP
5198 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5199 +#define SMB_ACL_OTHER ACL_OTHER
5200 +#define SMB_ACL_MASK ACL_MASK
5202 +#define SMB_ACL_T acl_t
5204 +#define SMB_ACL_ENTRY_T acl_entry_t
5206 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5207 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5209 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5210 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5212 +#elif defined HAVE_TRU64_ACLS
5214 +/* This is for DEC/Compaq Tru64 UNIX */
5216 +#define SMB_ACL_TAG_T acl_tag_t
5217 +#define SMB_ACL_TYPE_T acl_type_t
5218 +#define SMB_ACL_PERMSET_T acl_permset_t
5219 +#define SMB_ACL_PERM_T acl_perm_t
5220 +#define SMB_ACL_READ ACL_READ
5221 +#define SMB_ACL_WRITE ACL_WRITE
5222 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5224 +/* Types of ACLs. */
5225 +#define SMB_ACL_USER ACL_USER
5226 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5227 +#define SMB_ACL_GROUP ACL_GROUP
5228 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5229 +#define SMB_ACL_OTHER ACL_OTHER
5230 +#define SMB_ACL_MASK ACL_MASK
5232 +#define SMB_ACL_T acl_t
5234 +#define SMB_ACL_ENTRY_T acl_entry_t
5236 +#define SMB_ACL_FIRST_ENTRY 0
5237 +#define SMB_ACL_NEXT_ENTRY 1
5239 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5240 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5242 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5244 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5245 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5248 +/* SVR4.2 ES/MP ACLs */
5249 +typedef int SMB_ACL_TAG_T;
5250 +typedef int SMB_ACL_TYPE_T;
5251 +typedef ushort *SMB_ACL_PERMSET_T;
5252 +typedef ushort SMB_ACL_PERM_T;
5253 +#define SMB_ACL_READ 4
5254 +#define SMB_ACL_WRITE 2
5255 +#define SMB_ACL_EXECUTE 1
5257 +/* Types of ACLs. */
5258 +#define SMB_ACL_USER USER
5259 +#define SMB_ACL_USER_OBJ USER_OBJ
5260 +#define SMB_ACL_GROUP GROUP
5261 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5262 +#define SMB_ACL_OTHER OTHER_OBJ
5263 +#define SMB_ACL_MASK CLASS_OBJ
5265 +typedef struct SMB_ACL_T {
5269 + struct acl acl[1];
5272 +typedef struct acl *SMB_ACL_ENTRY_T;
5274 +#define SMB_ACL_FIRST_ENTRY 0
5275 +#define SMB_ACL_NEXT_ENTRY 1
5277 +#define SMB_ACL_TYPE_ACCESS 0
5278 +#define SMB_ACL_TYPE_DEFAULT 1
5281 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5284 +#elif defined HAVE_HPUX_ACLS
5287 + * Based on the Solaris & UnixWare code.
5291 +#include <sys/aclv.h>
5293 +/* SVR4.2 ES/MP ACLs */
5294 +typedef int SMB_ACL_TAG_T;
5295 +typedef int SMB_ACL_TYPE_T;
5296 +typedef ushort *SMB_ACL_PERMSET_T;
5297 +typedef ushort SMB_ACL_PERM_T;
5298 +#define SMB_ACL_READ 4
5299 +#define SMB_ACL_WRITE 2
5300 +#define SMB_ACL_EXECUTE 1
5302 +/* Types of ACLs. */
5303 +#define SMB_ACL_USER USER
5304 +#define SMB_ACL_USER_OBJ USER_OBJ
5305 +#define SMB_ACL_GROUP GROUP
5306 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5307 +#define SMB_ACL_OTHER OTHER_OBJ
5308 +#define SMB_ACL_MASK CLASS_OBJ
5310 +typedef struct SMB_ACL_T {
5314 + struct acl acl[1];
5317 +typedef struct acl *SMB_ACL_ENTRY_T;
5319 +#define SMB_ACL_FIRST_ENTRY 0
5320 +#define SMB_ACL_NEXT_ENTRY 1
5322 +#define SMB_ACL_TYPE_ACCESS 0
5323 +#define SMB_ACL_TYPE_DEFAULT 1
5325 +#elif defined HAVE_IRIX_ACLS
5327 +#define SMB_ACL_TAG_T acl_tag_t
5328 +#define SMB_ACL_TYPE_T acl_type_t
5329 +#define SMB_ACL_PERMSET_T acl_permset_t
5330 +#define SMB_ACL_PERM_T acl_perm_t
5331 +#define SMB_ACL_READ ACL_READ
5332 +#define SMB_ACL_WRITE ACL_WRITE
5333 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5335 +/* Types of ACLs. */
5336 +#define SMB_ACL_USER ACL_USER
5337 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5338 +#define SMB_ACL_GROUP ACL_GROUP
5339 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5340 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5341 +#define SMB_ACL_MASK ACL_MASK
5343 +typedef struct SMB_ACL_T {
5349 +#define SMB_ACL_ENTRY_T acl_entry_t
5351 +#define SMB_ACL_FIRST_ENTRY 0
5352 +#define SMB_ACL_NEXT_ENTRY 1
5354 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5355 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5357 +#elif defined HAVE_AIX_ACLS
5359 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5361 +#include "/usr/include/acl.h"
5363 +typedef uint *SMB_ACL_PERMSET_T;
5365 +struct acl_entry_link{
5366 + struct acl_entry_link *prevp;
5367 + struct new_acl_entry *entryp;
5368 + struct acl_entry_link *nextp;
5372 +struct new_acl_entry{
5373 + unsigned short ace_len;
5374 + unsigned short ace_type;
5375 + unsigned int ace_access;
5376 + struct ace_id ace_id[1];
5379 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5380 +#define SMB_ACL_T struct acl_entry_link*
5382 +#define SMB_ACL_TAG_T unsigned short
5383 +#define SMB_ACL_TYPE_T int
5384 +#define SMB_ACL_PERM_T uint
5385 +#define SMB_ACL_READ S_IRUSR
5386 +#define SMB_ACL_WRITE S_IWUSR
5387 +#define SMB_ACL_EXECUTE S_IXUSR
5389 +/* Types of ACLs. */
5390 +#define SMB_ACL_USER ACEID_USER
5391 +#define SMB_ACL_USER_OBJ 3
5392 +#define SMB_ACL_GROUP ACEID_GROUP
5393 +#define SMB_ACL_GROUP_OBJ 4
5394 +#define SMB_ACL_OTHER 5
5395 +#define SMB_ACL_MASK 6
5398 +#define SMB_ACL_FIRST_ENTRY 1
5399 +#define SMB_ACL_NEXT_ENTRY 2
5401 +#define SMB_ACL_TYPE_ACCESS 0
5402 +#define SMB_ACL_TYPE_DEFAULT 1
5404 +#else /* No ACLs. */
5406 +/* No ACLS - fake it. */
5407 +#define SMB_ACL_TAG_T int
5408 +#define SMB_ACL_TYPE_T int
5409 +#define SMB_ACL_PERMSET_T mode_t
5410 +#define SMB_ACL_PERM_T mode_t
5411 +#define SMB_ACL_READ S_IRUSR
5412 +#define SMB_ACL_WRITE S_IWUSR
5413 +#define SMB_ACL_EXECUTE S_IXUSR
5415 +/* Types of ACLs. */
5416 +#define SMB_ACL_USER 0
5417 +#define SMB_ACL_USER_OBJ 1
5418 +#define SMB_ACL_GROUP 2
5419 +#define SMB_ACL_GROUP_OBJ 3
5420 +#define SMB_ACL_OTHER 4
5421 +#define SMB_ACL_MASK 5
5423 +typedef struct SMB_ACL_T {
5427 +typedef struct SMB_ACL_ENTRY_T {
5429 +} *SMB_ACL_ENTRY_T;
5431 +#define SMB_ACL_FIRST_ENTRY 0
5432 +#define SMB_ACL_NEXT_ENTRY 1
5434 +#define SMB_ACL_TYPE_ACCESS 0
5435 +#define SMB_ACL_TYPE_DEFAULT 1
5437 +#endif /* No ACLs. */
5438 +#endif /* _SMB_ACLS_H */
5439 --- old/testsuite/acls.test
5440 +++ new/testsuite/acls.test
5444 +# This program is distributable under the terms of the GNU GPL (see
5447 +# Test that rsync handles basic ACL preservation.
5449 +. $srcdir/testsuite/rsync.fns
5451 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5452 +case "$setfacl_nodef" in
5453 +true) test_skipped "I don't know how to use your setfacl command" ;;
5456 +makepath "$fromdir/foo"
5457 +echo something >"$fromdir/file1"
5458 +echo else >"$fromdir/file2"
5460 +files='foo file1 file2'
5462 +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
5463 +setfacl -m u:0:5 "$fromdir/file1"
5464 +setfacl -m u:0:5 "$fromdir/file2"
5466 +$RSYNC -avvA "$fromdir/" "$todir/"
5469 +getfacl $files >"$scratchdir/acls.txt"
5472 +getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
5474 +# The script would have aborted on error, so getting here means we've won.
5476 --- old/testsuite/default-acls.test
5477 +++ new/testsuite/default-acls.test
5481 +# This program is distributable under the terms of the GNU GPL (see
5484 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5486 +. $srcdir/testsuite/rsync.fns
5488 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5489 +case "$setfacl_nodef" in
5490 +true) test_skipped "I don't know how to use your setfacl command" ;;
5491 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5492 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5494 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5496 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5498 + todir="$scratchdir/$1"
5500 + $setfacl_nodef "$todir"
5502 + case "$setfacl_nodef" in
5503 + *-k*) opts="-dm $2" ;;
5504 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5506 + setfacl $opts "$todir"
5508 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5509 + # even though the directory itself is outside the transfer
5510 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5511 + check_perms "$todir/to" $4 "Target $1"
5512 + check_perms "$todir/to/dir" $4 "Target $1"
5513 + check_perms "$todir/to/file" $3 "Target $1"
5514 + check_perms "$todir/to/program" $4 "Target $1"
5515 + # Make sure get_local_name doesn't mess us up when transferring only one file
5516 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5517 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5518 + # Make sure we obey default ACLs when not transferring a regular file
5519 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5520 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5523 +mkdir "$scratchdir/dir"
5524 +echo "File!" >"$scratchdir/file"
5525 +echo "#!/bin/sh" >"$scratchdir/program"
5526 +chmod 777 "$scratchdir/dir"
5527 +chmod 666 "$scratchdir/file"
5528 +chmod 777 "$scratchdir/program"
5530 +# Test some target directories
5532 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5533 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5534 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5535 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5536 +testit noda1 '' rw------- rwx------
5538 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5540 +testit noda3 '' rw-r--r-- rwxr-xr-x
5548 extern int preserve_uid;
5549 extern int preserve_gid;
5550 +extern int preserve_acls;
5551 extern int numeric_ids;
5554 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5558 - if (preserve_uid) {
5559 + if (preserve_uid || preserve_acls) {
5561 /* we send sequences of uid/byte-length/name */
5562 for (list = uidlist; list; list = list->next) {
5563 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5567 - if (preserve_gid) {
5568 + if (preserve_gid || preserve_acls) {
5570 for (list = gidlist; list; list = list->next) {
5572 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5576 - if (preserve_uid && !numeric_ids) {
5577 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5578 /* read the uid list */
5579 while ((id = read_int(f)) != 0) {
5580 int len = read_byte(f);
5581 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5585 - if (preserve_gid && !numeric_ids) {
5586 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5587 /* read the gid list */
5588 while ((id = read_int(f)) != 0) {
5589 int len = read_byte(f);
5590 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5594 +#ifdef SUPPORT_ACLS
5595 + if (preserve_acls && !numeric_ids) {
5597 + while ((id = next_acl_uid(flist)) != NULL)
5598 + *id = match_uid(*id);
5599 + while ((id = next_acl_gid(flist)) != NULL)
5600 + *id = match_gid(*id);
5604 /* Now convert all the uids/gids from sender values to our values. */
5605 if (am_root && preserve_uid && !numeric_ids) {
5606 for (i = 0; i < flist->count; i++)