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.
10 This code does not yet itemize changes in ACL information (see --itemize).
14 @@ -25,15 +25,15 @@ VERSION=@VERSION@
18 -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
19 +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
20 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
21 - lib/permstring.o lib/pool_alloc.o @LIBOBJS@
22 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
23 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
24 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
25 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
26 main.o checksum.o match.o syscall.o log.o backup.o
27 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
28 - fileio.o batch.o clientname.o chmod.o
29 + fileio.o batch.o clientname.o chmod.o acls.o
30 OBJS3=progress.o pipe.o
31 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
32 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
36 +/* -*- c-file-style: "linux" -*-
37 + Copyright (C) Andrew Tridgell 1996
38 + Copyright (C) Paul Mackerras 1996
39 + Copyright (C) Matt McCutchen 2006
40 + Copyright (C) Wayne Davison 2006
42 + This program is free software; you can redistribute it and/or modify
43 + it under the terms of the GNU General Public License as published by
44 + the Free Software Foundation; either version 2 of the License, or
45 + (at your option) any later version.
47 + This program is distributed in the hope that it will be useful,
48 + but WITHOUT ANY WARRANTY; without even the implied warranty of
49 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 + GNU General Public License for more details.
52 + You should have received a copy of the GNU General Public License
53 + along with this program; if not, write to the Free Software
54 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
57 +/* handle passing ACLs between systems */
60 +#include "lib/sysacls.h"
66 +extern int orig_umask;
67 +extern int preserve_acls;
80 +#define NO_ENTRY ((uchar)0x80)
84 + /* These will be NO_ENTRY if there's no such entry. */
91 +static const rsync_acl rsync_acl_initializer =
92 + { {0, 0, NULL}, {0, 0, NULL}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY};
94 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
95 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
97 +/* a few useful calculations */
99 +static int rsync_acl_count_entries(const rsync_acl *racl)
101 + return racl->users.count + racl->groups.count
102 + + (racl->user_obj != NO_ENTRY)
103 + + (racl->group_obj != NO_ENTRY)
104 + + (racl->mask != NO_ENTRY)
105 + + (racl->other != NO_ENTRY);
108 +static int rsync_acl_get_perms(const rsync_acl *racl)
110 + /* Note that (NO_ENTRY & 7) is 0. */
111 + return ((racl->user_obj & 7) << 6)
112 + + (((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
113 + + (racl->other & 7);
116 +static void rsync_acl_strip_perms(rsync_acl *racl)
118 + racl->user_obj = NO_ENTRY;
119 + if (racl->mask == NO_ENTRY)
120 + racl->group_obj = NO_ENTRY;
122 + racl->mask = NO_ENTRY;
123 + racl->other = NO_ENTRY;
126 +static void expand_ida_list(ida_list *idal)
128 + /* First time through, 0 <= 0, so list is expanded. */
129 + if (idal->malloced <= idal->count) {
130 + id_access *new_ptr;
131 + size_t new_size = idal->malloced + 10;
132 + new_ptr = realloc_array(idal->idas, id_access, new_size);
133 + if (verbose >= 4) {
134 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
135 + (double) new_size * sizeof idal->idas[0],
136 + idal->idas ? "" : " not");
139 + idal->idas = new_ptr;
140 + idal->malloced = new_size;
143 + out_of_memory("expand_ida_list");
147 +static void ida_list_free(ida_list *idal)
152 + idal->malloced = 0;
155 +static void rsync_acl_free(rsync_acl *racl)
157 + ida_list_free(&racl->users);
158 + ida_list_free(&racl->groups);
161 +static int id_access_sorter(const void *r1, const void *r2)
163 + id_access *ida1 = (id_access *)r1;
164 + id_access *ida2 = (id_access *)r2;
165 + id_t rid1 = ida1->id, rid2 = ida2->id;
166 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
169 +static void sort_ida_list(ida_list *idal)
173 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
174 + &id_access_sorter);
177 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
179 + SMB_ACL_ENTRY_T entry;
180 + const char *errfun;
183 + *racl = rsync_acl_initializer;
184 + errfun = "sys_acl_get_entry";
185 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
187 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
188 + SMB_ACL_TAG_T tag_type;
189 + SMB_ACL_PERMSET_T permset;
194 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
195 + errfun = "sys_acl_get_tag_type";
198 + if ((rc = sys_acl_get_permset(entry, &permset))) {
199 + errfun = "sys_acl_get_tag_type";
202 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
203 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
204 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
205 + /* continue == done with entry; break == store in given idal */
206 + switch (tag_type) {
207 + case SMB_ACL_USER_OBJ:
208 + if (racl->user_obj == NO_ENTRY)
209 + racl->user_obj = access;
211 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
214 + idal = &racl->users;
216 + case SMB_ACL_GROUP_OBJ:
217 + if (racl->group_obj == NO_ENTRY)
218 + racl->group_obj = access;
220 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
222 + case SMB_ACL_GROUP:
223 + idal = &racl->groups;
226 + if (racl->mask == NO_ENTRY)
227 + racl->mask = access;
229 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
231 + case SMB_ACL_OTHER:
232 + if (racl->other == NO_ENTRY)
233 + racl->other = access;
235 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
238 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
241 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
242 + errfun = "sys_acl_get_tag_type";
246 + expand_ida_list(idal);
247 + ida = &idal->idas[idal->count++];
248 + ida->id = *((id_t *)qualifier);
249 + ida->access = access;
250 + sys_acl_free_qualifier(qualifier, tag_type);
253 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
254 + errfun, strerror(errno));
255 + rsync_acl_free(racl);
259 + sort_ida_list(&racl->users);
260 + sort_ida_list(&racl->groups);
265 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
267 + id_access *ida1, *ida2;
268 + size_t count = ial1->count;
269 + if (count != ial2->count)
273 + for (; count--; ida1++, ida2++) {
274 + if (ida1->access != ida2->access || ida1->id != ida2->id)
280 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
282 + return (racl1->user_obj == racl2->user_obj
283 + && racl1->group_obj == racl2->group_obj
284 + && racl1->mask == racl2->mask
285 + && racl1->other == racl2->other
286 + && ida_lists_equal(&racl1->users, &racl2->users)
287 + && ida_lists_equal(&racl1->groups, &racl2->groups));
290 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1, const rsync_acl *racl2)
292 + /* We ignore any differences that chmod() can take care of. */
293 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
295 + if (racl1->mask != NO_ENTRY && racl1->group_obj != racl2->group_obj)
297 + return ida_lists_equal(&racl1->users, &racl2->users)
298 + && ida_lists_equal(&racl1->groups, &racl2->groups);
307 +static rsync_acl_list _rsync_acl_lists[] = {
308 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
309 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
312 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
314 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
315 + : &_rsync_acl_lists[1];
318 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
320 + /* First time through, 0 <= 0, so list is expanded. */
321 + if (racl_list->malloced <= racl_list->count) {
322 + rsync_acl *new_ptr;
324 + if (racl_list->malloced < 1000)
325 + new_size = racl_list->malloced + 1000;
327 + new_size = racl_list->malloced * 2;
328 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
329 + if (verbose >= 3) {
330 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
331 + (double) new_size * sizeof racl_list->racls[0],
332 + racl_list->racls ? "" : " not");
335 + racl_list->racls = new_ptr;
336 + racl_list->malloced = new_size;
338 + if (!racl_list->racls)
339 + out_of_memory("expand_rsync_acl_list");
343 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
344 + const rsync_acl_list *racl_list,
345 + const rsync_acl *racl)
347 + static int access_match = -1, default_match = -1;
348 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
349 + &access_match : &default_match;
350 + size_t count = racl_list->count;
351 + /* If this is the first time through or we didn't match the last
352 + * time, then start at the end of the list, which should be the
353 + * best place to start hunting. */
355 + *match = racl_list->count - 1;
357 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
360 + *match = racl_list->count - 1;
366 +/* The general strategy with the tag_type <-> character mapping is that
367 + * lowercase implies that no qualifier follows, where uppercase does.
368 + * A similar idiom for the acl type (access or default) itself, but
369 + * lowercase in this instance means there's no ACL following, so the
370 + * ACL is a repeat, so the receiver should reuse the last of the same
372 +static void send_ida_list(int f, const ida_list *idal, char tag_char)
375 + size_t count = idal->count;
376 + for (ida = idal->idas; count--; ida++) {
377 + write_byte(f, tag_char);
378 + write_byte(f, ida->access);
379 + write_int(f, ida->id);
380 + /* FIXME: sorta wasteful: we should maybe buffer as
381 + * many ids as max(ACL_USER + ACL_GROUP) objects to
382 + * keep from making so many calls. */
383 + if (tag_char == 'U')
390 +static void send_rsync_acl(int f, const rsync_acl *racl)
392 + size_t count = rsync_acl_count_entries(racl);
393 + write_int(f, count);
394 + if (racl->user_obj != NO_ENTRY) {
395 + write_byte(f, 'u');
396 + write_byte(f, racl->user_obj);
398 + send_ida_list(f, &racl->users, 'U');
399 + if (racl->group_obj != NO_ENTRY) {
400 + write_byte(f, 'g');
401 + write_byte(f, racl->group_obj);
403 + send_ida_list(f, &racl->groups, 'G');
404 + if (racl->mask != NO_ENTRY) {
405 + write_byte(f, 'm');
406 + write_byte(f, racl->mask);
408 + if (racl->other != NO_ENTRY) {
409 + write_byte(f, 'o');
410 + write_byte(f, racl->other);
414 +static rsync_acl _curr_rsync_acls[2];
416 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
418 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
419 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
420 + "unknown SMB_ACL_TYPE_T";
423 +/* Generate the ACL(s) for this flist entry;
424 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
425 +int make_acl(const struct file_struct *file, const char *fname)
427 + SMB_ACL_TYPE_T type;
428 + rsync_acl *curr_racl;
430 + if (S_ISLNK(file->mode))
433 + curr_racl = &_curr_rsync_acls[0];
434 + type = SMB_ACL_TYPE_ACCESS;
438 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
439 + ok = unpack_smb_acl(curr_racl, sacl);
440 + sys_acl_free_acl(sacl);
443 +#ifdef ACLS_NEED_MASK
444 + /* Don't ever send a redundant mask value. */
445 + if (!racl->users.count && !racl->groups.count
446 + && racl->group == racl->mask)
447 + racl->mask = NO_ENTRY;
449 + /* Strip access ACLs of permission-bit entries. */
450 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
451 + rsync_acl_strip_perms(curr_racl);
452 + } else if (errno == ENOTSUP) {
453 + /* ACLs are not supported. Leave list empty. */
454 + *curr_racl = rsync_acl_initializer;
456 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
457 + fname, str_acl_type(type), strerror(errno));
461 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
466 +/* Send the make_acl()-generated ACLs for this flist entry,
467 + * or clean up after an flist entry that's not being sent (f == -1). */
468 +void send_acl(const struct file_struct *file, int f)
470 + SMB_ACL_TYPE_T type;
471 + rsync_acl *curr_racl;
473 + if (S_ISLNK(file->mode))
476 + curr_racl = &_curr_rsync_acls[0];
477 + type = SMB_ACL_TYPE_ACCESS;
480 + rsync_acl_list *racl_list = rsync_acl_lists(type);
482 + rsync_acl_free(curr_racl);
485 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
487 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
488 + write_int(f, index);
489 + rsync_acl_free(curr_racl);
491 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
492 + send_rsync_acl(f, curr_racl);
493 + expand_rsync_acl_list(racl_list);
494 + racl_list->racls[racl_list->count++] = *curr_racl;
497 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
500 +/* The below stuff is only used by the receiver: */
502 +/* structure to hold index to rsync_acl_list member corresponding to
503 + * flist->files[i] */
506 + const struct file_struct *file;
513 + file_acl_index *fileaclidxs;
514 +} file_acl_index_list;
516 +static file_acl_index_list _file_acl_index_lists[] = {
517 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
518 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
521 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
523 + return type == SMB_ACL_TYPE_ACCESS ?
524 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
527 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
529 + /* First time through, 0 <= 0, so list is expanded. */
530 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
531 + file_acl_index *new_ptr;
533 + if (fileaclidx_list->malloced < 1000)
534 + new_size = fileaclidx_list->malloced + 1000;
536 + new_size = fileaclidx_list->malloced * 2;
537 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
538 + if (verbose >= 3) {
539 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
540 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
541 + fileaclidx_list->fileaclidxs ? "" : " not");
544 + fileaclidx_list->fileaclidxs = new_ptr;
545 + fileaclidx_list->malloced = new_size;
547 + if (!fileaclidx_list->fileaclidxs)
548 + out_of_memory("expand_file_acl_index_list");
552 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
560 +static smb_acl_list _smb_acl_lists[] = {
561 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
562 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
565 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
567 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
568 + &_smb_acl_lists[1];
571 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
573 + /* First time through, 0 <= 0, so list is expanded. */
574 + if (sacl_list->malloced <= sacl_list->count) {
575 + SMB_ACL_T *new_ptr;
577 + if (sacl_list->malloced < 1000)
578 + new_size = sacl_list->malloced + 1000;
580 + new_size = sacl_list->malloced * 2;
581 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
582 + if (verbose >= 3) {
583 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
584 + (double) new_size * sizeof sacl_list->sacls[0],
585 + sacl_list->sacls ? "" : " not");
588 + sacl_list->sacls = new_ptr;
589 + sacl_list->malloced = new_size;
591 + if (!sacl_list->sacls)
592 + out_of_memory("expand_smb_acl_list");
596 +#define CALL_OR_ERROR(func,args,str) \
604 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
605 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
607 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
609 + const char *errfun = NULL;
610 + SMB_ACL_PERMSET_T permset;
612 + COE( sys_acl_get_permset,(entry, &permset) );
613 + COE( sys_acl_clear_perms,(permset) );
615 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
617 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
619 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
620 + COE( sys_acl_set_permset,(entry, permset) );
625 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
630 +/* build an SMB_ACL_T corresponding to an rsync_acl */
631 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
635 + const char *errfun = NULL;
636 + SMB_ACL_ENTRY_T entry;
638 + if (!(*smb_acl = sys_acl_init(rsync_acl_count_entries(racl)))) {
639 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
644 + COE( sys_acl_create_entry,(smb_acl, &entry) );
645 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
646 + COE2( store_access_in_entry,(racl->user_obj, entry) );
648 + for (ida = racl->users.idas, count = racl->users.count;
650 + COE( sys_acl_create_entry,(smb_acl, &entry) );
651 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
652 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
653 + COE2( store_access_in_entry,(ida->access, entry) );
656 + COE( sys_acl_create_entry,(smb_acl, &entry) );
657 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
658 + COE2( store_access_in_entry,(racl->group_obj, entry) );
660 + for (ida = racl->groups.idas, count = racl->groups.count;
662 + COE( sys_acl_create_entry,(smb_acl, &entry) );
663 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
664 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
665 + COE2( store_access_in_entry,(ida->access, entry) );
667 + if (racl->mask != NO_ENTRY) {
668 + COE( sys_acl_create_entry,(smb_acl, &entry) );
669 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
670 + COE2( store_access_in_entry,(racl->mask, entry) );
673 + COE( sys_acl_create_entry,(smb_acl, &entry) );
674 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
675 + COE2( store_access_in_entry,(racl->other, entry) );
678 + if (sys_acl_valid(*smb_acl) < 0)
679 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
686 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
689 + sys_acl_free_acl(*smb_acl);
693 +static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode)
695 + SMB_ACL_ENTRY_T entry;
696 + int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ;
697 + const char *errfun;
700 + if (S_ISDIR(mode)) {
701 + /* If the sticky bit is going on, it's not safe to allow all
702 + * the new ACLs to go into effect before it gets set. */
703 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
704 + if (mode & S_ISVTX)
707 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
710 + /* If setuid or setgid is going off, it's not safe to allow all
711 + * the new ACLs to go into effect before they get cleared. */
712 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
713 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
718 + errfun = "sys_acl_get_entry";
719 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
721 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
722 + SMB_ACL_TAG_T tag_type;
723 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
724 + errfun = "sys_acl_get_tag_type";
727 + if (tag_type == SMB_ACL_USER_OBJ)
728 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
729 + else if (tag_type == group_id)
730 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
731 + else if (tag_type == SMB_ACL_OTHER)
732 + COE2( store_access_in_entry,(mode & 7, entry) );
737 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
738 + errfun, strerror(errno));
743 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
744 + /* Ensure that chmod() will be called to restore any lost setid bits. */
745 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
746 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
747 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
750 + /* Return the mode of the file on disk, as we will set them. */
751 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
754 +static void receive_rsync_acl(rsync_acl *racl, int f)
756 + uchar computed_mask_bits = 0;
757 + ida_list *idal = NULL;
761 + *racl = rsync_acl_initializer;
763 + if (!(count = read_int(f)))
767 + char tag = read_byte(f);
768 + uchar access = read_byte(f);
769 + if (access & ~ (4 | 2 | 1)) {
770 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
772 + exit_cleanup(RERR_STREAMIO);
776 + if (racl->user_obj != NO_ENTRY) {
777 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
778 + exit_cleanup(RERR_STREAMIO);
780 + racl->user_obj = access;
783 + idal = &racl->users;
786 + if (racl->group_obj != NO_ENTRY) {
787 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
788 + exit_cleanup(RERR_STREAMIO);
790 + racl->group_obj = access;
793 + idal = &racl->groups;
796 + if (racl->mask != NO_ENTRY) {
797 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
798 + exit_cleanup(RERR_STREAMIO);
800 + racl->mask = access;
803 + if (racl->other != NO_ENTRY) {
804 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
805 + exit_cleanup(RERR_STREAMIO);
807 + racl->other = access;
810 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
812 + exit_cleanup(RERR_STREAMIO);
814 + expand_ida_list(idal);
815 + ida = &idal->idas[idal->count++];
816 + ida->access = access;
817 + ida->id = read_int(f);
818 + computed_mask_bits |= access;
821 + /* Ensure that these are never unset. */
822 + if (racl->user_obj == NO_ENTRY)
823 + racl->user_obj = 7;
824 + if (racl->group_obj == NO_ENTRY)
825 + racl->group_obj = 0;
826 + if (racl->other == NO_ENTRY)
828 +#ifndef ACLS_NEED_MASK
829 + if (!racl->users.count && !racl->groups.count) {
830 + /* If we, a system without ACLS_NEED_MASK, received a
831 + * superfluous mask, throw it away. */
832 + if (racl->mask != NO_ENTRY) {
833 + /* mask off group perms with it first */
834 + racl->group_obj &= racl->mask;
835 + racl->mask = NO_ENTRY;
839 + if (racl->mask == NO_ENTRY)
840 + racl->mask = computed_mask_bits | racl->group_obj;
843 +/* receive and build the rsync_acl_lists */
844 +void receive_acl(struct file_struct *file, int f)
846 + SMB_ACL_TYPE_T type;
849 + if (S_ISLNK(file->mode))
852 + fname = f_name(file, NULL);
853 + type = SMB_ACL_TYPE_ACCESS;
855 + file_acl_index_list *fileaclidx_list =
856 + file_acl_index_lists(type);
858 + expand_file_acl_index_list(fileaclidx_list);
860 + tag = read_byte(f);
861 + if (tag == 'A' || tag == 'a') {
862 + if (type != SMB_ACL_TYPE_ACCESS) {
863 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
865 + exit_cleanup(RERR_STREAMIO);
867 + } else if (tag == 'D' || tag == 'd') {
868 + if (type == SMB_ACL_TYPE_ACCESS) {
869 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
871 + exit_cleanup(RERR_STREAMIO);
874 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
876 + exit_cleanup(RERR_STREAMIO);
878 + if (tag == 'A' || tag == 'D') {
880 + rsync_acl_list *racl_list = rsync_acl_lists(type);
881 + smb_acl_list *sacl_list = smb_acl_lists(type);
882 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
883 + aclidx = racl_list->count;
884 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
886 + receive_rsync_acl(&racl, f);
887 + expand_rsync_acl_list(racl_list);
888 + racl_list->racls[racl_list->count++] = racl;
889 + expand_smb_acl_list(sacl_list);
890 + sacl_list->sacls[sacl_list->count++] = NULL;
892 + int index = read_int(f);
893 + rsync_acl_list *racl_list = rsync_acl_lists(type);
894 + if ((size_t) index >= racl_list->count) {
895 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
897 + str_acl_type(type),
899 + exit_cleanup(RERR_STREAMIO);
901 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
903 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
906 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
909 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
911 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
912 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
913 + return fileaclidx1->file == fileaclidx2->file ? 0 :
914 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
917 +void sort_file_acl_index_lists()
919 + SMB_ACL_TYPE_T type;
921 + type = SMB_ACL_TYPE_ACCESS;
923 + file_acl_index_list *fileaclidx_list =
924 + file_acl_index_lists(type);
925 + if (!fileaclidx_list->count)
927 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
928 + sizeof fileaclidx_list->fileaclidxs[0],
929 + &file_acl_index_list_sorter);
930 + } while (BUMP_TYPE(type));
933 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
934 + const struct file_struct *file) {
935 + int low = 0, high = fileaclidx_list->count;
936 + const struct file_struct *file_mid;
940 + int mid = (high + low) / 2;
941 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
942 + if (file_mid == file)
943 + return fileaclidx_list->fileaclidxs[mid].aclidx;
944 + if (file_mid > file)
948 + } while (low < high);
950 + file_mid = fileaclidx_list->fileaclidxs[low].file;
951 + if (file_mid == file)
952 + return fileaclidx_list->fileaclidxs[low].aclidx;
955 + "find_file_acl_index: can't find entry for file in list\n");
956 + exit_cleanup(RERR_STREAMIO);
960 +/* for duplicating ACLs on backups when using backup_dir */
961 +int dup_acl(const char *orig, const char *bak, mode_t mode)
963 + SMB_ACL_TYPE_T type;
966 + type = SMB_ACL_TYPE_ACCESS;
968 + SMB_ACL_T sacl_orig, sacl_bak;
969 + rsync_acl racl_orig, racl_bak;
970 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
971 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
972 + orig, str_acl_type(type), strerror(errno));
976 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
977 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
978 + bak, str_acl_type(type), strerror(errno));
980 + /* try to forge on through */
982 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
984 + goto out_with_sacls;
987 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
989 + goto out_with_one_racl;
991 + if (rsync_acls_equal(&racl_orig, &racl_bak))
994 + ; /* presume they're unequal */
996 + if (type == SMB_ACL_TYPE_DEFAULT
997 + && rsync_acl_count_entries(&racl_orig) == 0) {
998 + if (sys_acl_delete_def_file(bak) < 0) {
999 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
1000 + bak, strerror(errno));
1003 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
1004 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
1005 + bak, str_acl_type(type), strerror(errno));
1010 + rsync_acl_free(&racl_bak);
1011 + out_with_one_racl:
1012 + rsync_acl_free(&racl_orig);
1015 + sys_acl_free_acl(sacl_bak);
1016 + /* out_with_one_sacl: */
1018 + sys_acl_free_acl(sacl_orig);
1019 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1024 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1025 + * for keep_backup(). */
1026 +static const struct file_struct *backup_orig_file = NULL;
1027 +static const char null_string[] = "";
1028 +static const char *backup_orig_fname = null_string;
1029 +static const char *backup_dest_fname = null_string;
1030 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1032 +void push_keep_backup_acl(const struct file_struct *file,
1033 + const char *orig, const char *dest)
1035 + SMB_ACL_TYPE_T type;
1038 + backup_orig_file = file;
1039 + backup_orig_fname = orig;
1040 + backup_dest_fname = dest;
1042 + sacl = &_backup_sacl[0];
1043 + type = SMB_ACL_TYPE_ACCESS;
1045 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1049 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1051 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1052 + orig, str_acl_type(type),
1055 + } while (BUMP_TYPE(type));
1058 +static int set_keep_backup_acl()
1060 + SMB_ACL_TYPE_T type;
1064 + sacl = &_backup_sacl[0];
1065 + type = SMB_ACL_TYPE_ACCESS;
1068 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1070 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1071 + backup_dest_fname,
1072 + str_acl_type(type),
1076 + } while (BUMP_TYPE(type));
1081 +void cleanup_keep_backup_acl()
1083 + SMB_ACL_TYPE_T type;
1086 + backup_orig_file = NULL;
1087 + backup_orig_fname = null_string;
1088 + backup_dest_fname = null_string;
1090 + sacl = &_backup_sacl[0];
1091 + type = SMB_ACL_TYPE_ACCESS;
1094 + sys_acl_free_acl(*sacl);
1097 + } while (BUMP_TYPE(type));
1100 +/* set ACL on rsync-ed or keep_backup-ed file
1102 + * This sets extended access ACL entries and default ACLs. If convenient,
1103 + * it sets permission bits along with the access ACLs and signals having
1104 + * done so by modifying mode_p, which should point into the stat buffer.
1106 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1107 + * Pass NULL for mode_p to get the return code without changing anything. */
1108 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1110 + int unchanged = 1;
1111 + SMB_ACL_TYPE_T type;
1113 + if (S_ISLNK(file->mode))
1116 + if (file == backup_orig_file) {
1117 + if (!strcmp(fname, backup_dest_fname))
1118 + return set_keep_backup_acl();
1120 + type = SMB_ACL_TYPE_ACCESS;
1123 + SMB_ACL_T sacl_orig, *sacl_new;
1124 + rsync_acl racl_orig, *racl_new;
1125 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1127 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1128 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1129 + sacl_orig = sys_acl_get_file(fname, type);
1131 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1132 + fname, str_acl_type(type), strerror(errno));
1136 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1137 + sys_acl_free_acl(sacl_orig);
1142 + if (type == SMB_ACL_TYPE_ACCESS)
1143 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new);
1145 + ok = rsync_acls_equal(&racl_orig, racl_new);
1146 + rsync_acl_free(&racl_orig);
1149 + if (!dry_run && mode_p) {
1150 + if (type == SMB_ACL_TYPE_DEFAULT
1151 + && rsync_acl_count_entries(racl_new) == 0) {
1152 + if (sys_acl_delete_def_file(fname) < 0) {
1153 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1154 + fname, strerror(errno));
1159 + mode_t cur_mode = *mode_p;
1161 + && !pack_smb_acl(sacl_new, racl_new)) {
1165 + if (type == SMB_ACL_TYPE_ACCESS) {
1166 + cur_mode = change_sacl_perms(*sacl_new, racl_new->mask,
1167 + cur_mode, file->mode);
1168 + if (cur_mode == ~0u)
1171 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1172 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1173 + fname, str_acl_type(type),
1178 + if (type == SMB_ACL_TYPE_ACCESS)
1179 + *mode_p = cur_mode;
1182 + if (unchanged == 1)
1184 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1189 +/* Enumeration functions for uid mapping: */
1191 +/* Context -- one and only one. Should be cycled through once on uid
1192 + * mapping and once on gid mapping. */
1193 +static rsync_acl_list *_enum_racl_lists[] = {
1194 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1197 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1198 +static size_t enum_racl_index = 0;
1199 +static size_t enum_ida_index = 0;
1201 +/* This returns the next tag_type id from the given acl for the next entry,
1202 + * or it returns 0 if there are no more tag_type ids in the acl. */
1203 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1205 + const ida_list *idal = (tag_type == SMB_ACL_USER ?
1206 + &racl->users : &racl->groups);
1207 + if (enum_ida_index < idal->count) {
1208 + id_access *ida = &idal->idas[enum_ida_index++];
1211 + enum_ida_index = 0;
1215 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1217 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1218 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1219 + id_t *id = next_ace_id(tag_type, racl);
1223 + enum_racl_index = 0;
1227 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1229 + for (; *enum_racl_list; enum_racl_list++) {
1230 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1234 + enum_racl_list = &_enum_racl_lists[0];
1238 +id_t *next_acl_uid()
1240 + return next_acl_list_id(SMB_ACL_USER);
1243 +id_t *next_acl_gid()
1245 + return next_acl_list_id(SMB_ACL_GROUP);
1248 +int default_perms_for_dir(const char *dir)
1257 + perms = ACCESSPERMS & ~orig_umask;
1258 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1259 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1260 + if (sacl == NULL) {
1261 + /* Couldn't get an ACL. Darn. */
1264 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1268 + /* We're doing a dry run, so the containing directory
1269 + * wasn't actually created. Don't worry about it. */
1272 + /* Otherwise fall through. */
1274 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1275 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1281 + ok = unpack_smb_acl(&racl, sacl);
1282 + sys_acl_free_acl(sacl);
1284 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1288 + /* Apply the permission-bit entries of the default ACL, if any. */
1289 + if (rsync_acl_count_entries(&racl) > 0) {
1290 + perms = rsync_acl_get_perms(&racl);
1292 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1295 + rsync_acl_free(&racl);
1299 +#endif /* SUPPORT_ACLS */
1302 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1303 extern char *backup_dir;
1306 +extern int preserve_acls;
1307 extern int preserve_devices;
1308 extern int preserve_specials;
1309 extern int preserve_links;
1310 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1312 do_lchown(fullpath, st.st_uid, st.st_gid);
1313 do_chmod(fullpath, st.st_mode);
1314 +#ifdef SUPPORT_ACLS
1315 + if (preserve_acls)
1316 + dup_acl(end, fullpath, st.st_mode);
1321 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1322 if (!(buf = get_backup_name(fname)))
1325 +#ifdef SUPPORT_ACLS
1326 + if (preserve_acls)
1327 + push_keep_backup_acl(file, fname, buf);
1330 /* Check to see if this is a device file, or link */
1331 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1332 || (preserve_specials && IS_SPECIAL(file->mode))) {
1333 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1336 set_file_attrs(buf, file, NULL, 0);
1337 +#ifdef SUPPORT_ACLS
1338 + if (preserve_acls)
1339 + cleanup_keep_backup_acl();
1344 --- old/configure.in
1345 +++ new/configure.in
1346 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1347 AC_CHECK_LIB(resolv, strcasecmp)
1350 +AC_CHECK_FUNCS(aclsort)
1351 +if test x"$ac_cv_func_aclsort" = x"no"; then
1352 + AC_CHECK_LIB(sec, aclsort)
1355 dnl At the moment we don't test for a broken memcmp(), because all we
1356 dnl need to do is test for equality, not comparison, and it seems that
1357 dnl every platform has a memcmp that can do at least that.
1358 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1359 AC_SUBST(CC_SHOBJ_FLAG)
1360 AC_SUBST(BUILD_POPT)
1362 +AC_CHECK_HEADERS(sys/acl.h)
1363 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1364 +#################################################
1365 +# check for ACL support
1367 +AC_MSG_CHECKING(whether to support ACLs)
1368 +AC_ARG_ENABLE(acl-support,
1369 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1370 +[ case "$enableval" in
1373 + case "$host_os" in
1375 + AC_MSG_RESULT(Using UnixWare ACLs)
1376 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1378 + *solaris*|*cygwin*)
1379 + AC_MSG_RESULT(Using solaris ACLs)
1380 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1383 + AC_MSG_RESULT(Using HPUX ACLs)
1384 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1387 + AC_MSG_RESULT(Using IRIX ACLs)
1388 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1391 + AC_MSG_RESULT(Using AIX ACLs)
1392 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1395 + AC_MSG_RESULT(Using Tru64 ACLs)
1396 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1397 + LIBS="$LIBS -lpacl"
1400 + AC_MSG_RESULT(ACLs requested -- running tests)
1401 + AC_CHECK_LIB(acl,acl_get_file)
1402 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1403 + AC_TRY_LINK([#include <sys/types.h>
1404 +#include <sys/acl.h>],
1405 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1406 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1407 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1408 + AC_MSG_RESULT(Using posix ACLs)
1409 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1410 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1411 + AC_TRY_LINK([#include <sys/types.h>
1412 +#include <sys/acl.h>],
1413 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1414 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1415 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1416 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1419 + AC_MSG_ERROR(Failed to find ACL support)
1426 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1429 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1433 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1438 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1439 extern int one_file_system;
1440 extern int copy_dirlinks;
1441 extern int keep_dirlinks;
1442 +extern int preserve_acls;
1443 extern int preserve_links;
1444 extern int preserve_hard_links;
1445 extern int preserve_devices;
1446 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1447 if (chmod_modes && !S_ISLNK(file->mode))
1448 file->mode = tweak_mode(file->mode, chmod_modes);
1450 +#ifdef SUPPORT_ACLS
1451 + if (preserve_acls && make_acl(file, fname) < 0)
1455 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1457 flist_expand(flist);
1458 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1459 if (file->basename[0]) {
1460 flist->files[flist->count++] = file;
1461 send_file_entry(file, f);
1462 +#ifdef SUPPORT_ACLS
1463 + if (preserve_acls)
1464 + send_acl(file, f);
1467 +#ifdef SUPPORT_ACLS
1468 + /* Cleanup unsent ACL(s). */
1469 + if (preserve_acls)
1470 + send_acl(file, -1);
1475 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1476 flags |= read_byte(f) << 8;
1477 file = receive_file_entry(flist, flags, f);
1479 +#ifdef SUPPORT_ACLS
1480 + if (preserve_acls)
1481 + receive_acl(file, f);
1484 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1485 stats.total_size += file->length;
1487 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1489 clean_flist(flist, relative_paths, 1);
1491 +#ifdef SUPPORT_ACLS
1492 + if (preserve_acls)
1493 + sort_file_acl_index_lists();
1497 recv_uid_list(f, flist);
1501 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1502 extern int max_delete;
1503 extern int force_delete;
1504 extern int one_file_system;
1505 +extern mode_t orig_umask;
1506 extern struct stats stats;
1507 extern dev_t filesystem_dev;
1508 extern char *backup_dir;
1509 @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l
1511 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1513 + /* FIXME: Flag ACL changes. */
1516 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1518 @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i
1519 if (preserve_gid && file->gid != GID_NONE
1520 && st->st_gid != file->gid)
1521 iflags |= ITEM_REPORT_GROUP;
1522 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1524 iflags |= ITEM_IS_NEW;
1526 @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str
1529 static int phase = 0;
1530 +static int dflt_perms;
1532 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1533 * make sure it exists, and has the right permissions/timestamp info. For
1534 @@ -844,6 +849,10 @@ static void recv_generator(char *fname,
1537 need_fuzzy_dirlist = 1;
1538 +#ifdef SUPPORT_ACLS
1539 + if (!preserve_perms)
1540 + dflt_perms = default_perms_for_dir(dn);
1543 parent_dirname = dn;
1545 @@ -871,7 +880,8 @@ static void recv_generator(char *fname,
1546 if (!preserve_perms) {
1547 int exists = statret == 0
1548 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1549 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1550 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1554 if (S_ISDIR(file->mode)) {
1555 @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi
1556 * notice that and let us know via the redo pipe (or its closing). */
1559 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1561 for (i = 0; i < flist->count; i++) {
1562 struct file_struct *file = flist->files[i];
1564 --- old/lib/sysacls.c
1565 +++ new/lib/sysacls.c
1568 + Unix SMB/CIFS implementation.
1569 + Samba system utilities for ACL support.
1570 + Copyright (C) Jeremy Allison 2000.
1572 + This program is free software; you can redistribute it and/or modify
1573 + it under the terms of the GNU General Public License as published by
1574 + the Free Software Foundation; either version 2 of the License, or
1575 + (at your option) any later version.
1577 + This program is distributed in the hope that it will be useful,
1578 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1579 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1580 + GNU General Public License for more details.
1582 + You should have received a copy of the GNU General Public License
1583 + along with this program; if not, write to the Free Software
1584 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1588 +#include "sysacls.h" /****** ADDED ******/
1590 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1591 +void SAFE_FREE(void *mem)
1597 +char *uidtoname(uid_t uid)
1599 + static char idbuf[12];
1600 + struct passwd *pw;
1602 + if ((pw = getpwuid(uid)) == NULL) {
1603 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1606 + return pw->pw_name;
1608 +/****** EXTRAS -- END ******/
1611 + This file wraps all differing system ACL interfaces into a consistent
1612 + one based on the POSIX interface. It also returns the correct errors
1613 + for older UNIX systems that don't support ACLs.
1615 + The interfaces that each ACL implementation must support are as follows :
1617 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1618 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1619 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1620 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1621 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1622 + SMB_ACL_T sys_acl_get_fd(int fd)
1623 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1624 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1625 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1626 + SMB_ACL_T sys_acl_init( int count)
1627 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1628 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1629 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1630 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1631 + int sys_acl_valid( SMB_ACL_T theacl )
1632 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1633 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1634 + int sys_acl_delete_def_file(const char *path)
1636 + This next one is not POSIX complient - but we *have* to have it !
1637 + More POSIX braindamage.
1639 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1641 + The generic POSIX free is the following call. We split this into
1642 + several different free functions as we may need to add tag info
1643 + to structures when emulating the POSIX interface.
1645 + int sys_acl_free( void *obj_p)
1647 + The calls we actually use are :
1649 + int sys_acl_free_text(char *text) - free acl_to_text
1650 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1651 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1655 +#if defined(HAVE_POSIX_ACLS)
1657 +/* Identity mapping - easy. */
1659 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1661 + return acl_get_entry( the_acl, entry_id, entry_p);
1664 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1666 + return acl_get_tag_type( entry_d, tag_type_p);
1669 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1671 + return acl_get_permset( entry_d, permset_p);
1674 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1676 + return acl_get_qualifier( entry_d);
1679 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1681 + return acl_get_file( path_p, type);
1684 +SMB_ACL_T sys_acl_get_fd(int fd)
1686 + return acl_get_fd(fd);
1689 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1691 + return acl_clear_perms(permset);
1694 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1696 + return acl_add_perm(permset, perm);
1699 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1701 +#if defined(HAVE_ACL_GET_PERM_NP)
1703 + * Required for TrustedBSD-based ACL implementations where
1704 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1707 + return acl_get_perm_np(permset, perm);
1709 + return acl_get_perm(permset, perm);
1713 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1715 + return acl_to_text( the_acl, plen);
1718 +SMB_ACL_T sys_acl_init( int count)
1720 + return acl_init(count);
1723 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1725 + return acl_create_entry(pacl, pentry);
1728 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1730 + return acl_set_tag_type(entry, tagtype);
1733 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1735 + return acl_set_qualifier(entry, qual);
1738 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1740 + return acl_set_permset(entry, permset);
1743 +int sys_acl_valid( SMB_ACL_T theacl )
1745 + return acl_valid(theacl);
1748 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1750 + return acl_set_file(name, acltype, theacl);
1753 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1755 + return acl_set_fd(fd, theacl);
1758 +int sys_acl_delete_def_file(const char *name)
1760 + return acl_delete_def_file(name);
1763 +int sys_acl_free_text(char *text)
1765 + return acl_free(text);
1768 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1770 + return acl_free(the_acl);
1773 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1775 + return acl_free(qual);
1778 +#elif defined(HAVE_TRU64_ACLS)
1780 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1781 + * is based on Draft 13 of the POSIX spec which is
1782 + * slightly different from the Draft 16 interface.
1784 + * Also, some of the permset manipulation functions
1785 + * such as acl_clear_perm() and acl_add_perm() appear
1786 + * to be broken on Tru64 so we have to manipulate
1787 + * the permission bits in the permset directly.
1789 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1791 + SMB_ACL_ENTRY_T entry;
1793 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1798 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1803 + return errno ? -1 : 0;
1806 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1808 + return acl_get_tag_type( entry_d, tag_type_p);
1811 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1813 + return acl_get_permset( entry_d, permset_p);
1816 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1818 + return acl_get_qualifier( entry_d);
1821 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1823 + return acl_get_file((char *)path_p, type);
1826 +SMB_ACL_T sys_acl_get_fd(int fd)
1828 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1831 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1833 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1838 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1840 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1845 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1850 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1852 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1855 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1857 + return acl_to_text( the_acl, plen);
1860 +SMB_ACL_T sys_acl_init( int count)
1862 + return acl_init(count);
1865 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1867 + SMB_ACL_ENTRY_T entry;
1869 + if ((entry = acl_create_entry(pacl)) == NULL) {
1877 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1879 + return acl_set_tag_type(entry, tagtype);
1882 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1884 + return acl_set_qualifier(entry, qual);
1887 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1889 + return acl_set_permset(entry, permset);
1892 +int sys_acl_valid( SMB_ACL_T theacl )
1894 + acl_entry_t entry;
1896 + return acl_valid(theacl, &entry);
1899 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1901 + return acl_set_file((char *)name, acltype, theacl);
1904 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1906 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1909 +int sys_acl_delete_def_file(const char *name)
1911 + return acl_delete_def_file((char *)name);
1914 +int sys_acl_free_text(char *text)
1917 + * (void) cast and explicit return 0 are for DEC UNIX
1918 + * which just #defines acl_free_text() to be free()
1920 + (void) acl_free_text(text);
1924 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1926 + return acl_free(the_acl);
1929 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1931 + return acl_free_qualifier(qual, tagtype);
1934 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1937 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1938 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1942 + * Note that while this code implements sufficient functionality
1943 + * to support the sys_acl_* interfaces it does not provide all
1944 + * of the semantics of the POSIX ACL interfaces.
1946 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1947 + * from a call to sys_acl_get_entry() should not be assumed to be
1948 + * valid after calling any of the following functions, which may
1949 + * reorder the entries in the ACL.
1952 + * sys_acl_set_file()
1953 + * sys_acl_set_fd()
1957 + * The only difference between Solaris and UnixWare / OpenUNIX is
1958 + * that the #defines for the ACL operations have different names
1960 +#if defined(HAVE_UNIXWARE_ACLS)
1962 +#define SETACL ACL_SET
1963 +#define GETACL ACL_GET
1964 +#define GETACLCNT ACL_CNT
1969 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1971 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1976 + if (entry_p == NULL) {
1981 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1985 + if (acl_d->next < 0) {
1990 + if (acl_d->next >= acl_d->count) {
1994 + *entry_p = &acl_d->acl[acl_d->next++];
1999 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2001 + *type_p = entry_d->a_type;
2006 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2008 + *permset_p = &entry_d->a_perm;
2013 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2015 + if (entry_d->a_type != SMB_ACL_USER
2016 + && entry_d->a_type != SMB_ACL_GROUP) {
2021 + return &entry_d->a_id;
2025 + * There is no way of knowing what size the ACL returned by
2026 + * GETACL will be unless you first call GETACLCNT which means
2027 + * making an additional system call.
2029 + * In the hope of avoiding the cost of the additional system
2030 + * call in most cases, we initially allocate enough space for
2031 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2032 + * be too small then we use GETACLCNT to find out the actual
2033 + * size, reallocate the ACL buffer, and then call GETACL again.
2036 +#define INITIAL_ACL_SIZE 16
2038 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2041 + int count; /* # of ACL entries allocated */
2042 + int naccess; /* # of access ACL entries */
2043 + int ndefault; /* # of default ACL entries */
2045 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2050 + count = INITIAL_ACL_SIZE;
2051 + if ((acl_d = sys_acl_init(count)) == NULL) {
2056 + * If there isn't enough space for the ACL entries we use
2057 + * GETACLCNT to determine the actual number of ACL entries
2058 + * reallocate and try again. This is in a loop because it
2059 + * is possible that someone else could modify the ACL and
2060 + * increase the number of entries between the call to
2061 + * GETACLCNT and the call to GETACL.
2063 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2064 + && errno == ENOSPC) {
2066 + sys_acl_free_acl(acl_d);
2068 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2072 + if ((acl_d = sys_acl_init(count)) == NULL) {
2078 + sys_acl_free_acl(acl_d);
2083 + * calculate the number of access and default ACL entries
2085 + * Note: we assume that the acl() system call returned a
2086 + * well formed ACL which is sorted so that all of the
2087 + * access ACL entries preceed any default ACL entries
2089 + for (naccess = 0; naccess < count; naccess++) {
2090 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2093 + ndefault = count - naccess;
2096 + * if the caller wants the default ACL we have to copy
2097 + * the entries down to the start of the acl[] buffer
2098 + * and mask out the ACL_DEFAULT flag from the type field
2100 + if (type == SMB_ACL_TYPE_DEFAULT) {
2103 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2104 + acl_d->acl[i] = acl_d->acl[j];
2105 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2108 + acl_d->count = ndefault;
2110 + acl_d->count = naccess;
2116 +SMB_ACL_T sys_acl_get_fd(int fd)
2119 + int count; /* # of ACL entries allocated */
2120 + int naccess; /* # of access ACL entries */
2122 + count = INITIAL_ACL_SIZE;
2123 + if ((acl_d = sys_acl_init(count)) == NULL) {
2127 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2128 + && errno == ENOSPC) {
2130 + sys_acl_free_acl(acl_d);
2132 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2136 + if ((acl_d = sys_acl_init(count)) == NULL) {
2142 + sys_acl_free_acl(acl_d);
2147 + * calculate the number of access ACL entries
2149 + for (naccess = 0; naccess < count; naccess++) {
2150 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2154 + acl_d->count = naccess;
2159 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2166 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2168 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2169 + && perm != SMB_ACL_EXECUTE) {
2174 + if (permset_d == NULL) {
2179 + *permset_d |= perm;
2184 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2186 + return *permset_d & perm;
2189 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2196 + * use an initial estimate of 20 bytes per ACL entry
2197 + * when allocating memory for the text representation
2201 + maxlen = 20 * acl_d->count;
2202 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2207 + for (i = 0; i < acl_d->count; i++) {
2208 + struct acl *ap = &acl_d->acl[i];
2217 + switch (ap->a_type) {
2219 + * for debugging purposes it's probably more
2220 + * useful to dump unknown tag types rather
2221 + * than just returning an error
2224 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2227 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2232 + case SMB_ACL_USER:
2233 + id = uidtoname(ap->a_id);
2234 + case SMB_ACL_USER_OBJ:
2238 + case SMB_ACL_GROUP:
2239 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2240 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2246 + case SMB_ACL_GROUP_OBJ:
2250 + case SMB_ACL_OTHER:
2254 + case SMB_ACL_MASK:
2260 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2261 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2262 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2265 + /* <tag> : <qualifier> : rwx \n \0 */
2266 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2269 + * If this entry would overflow the buffer
2270 + * allocate enough additional memory for this
2271 + * entry and an estimate of another 20 bytes
2272 + * for each entry still to be processed
2274 + if ((len + nbytes) > maxlen) {
2275 + char *oldtext = text;
2277 + maxlen += nbytes + 20 * (acl_d->count - i);
2279 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2280 + SAFE_FREE(oldtext);
2286 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2287 + len += nbytes - 1;
2296 +SMB_ACL_T sys_acl_init(int count)
2306 + * note that since the definition of the structure pointed
2307 + * to by the SMB_ACL_T includes the first element of the
2308 + * acl[] array, this actually allocates an ACL with room
2309 + * for (count+1) entries
2311 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2316 + a->size = count + 1;
2324 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2327 + SMB_ACL_ENTRY_T entry_d;
2329 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2334 + if (acl_d->count >= acl_d->size) {
2339 + entry_d = &acl_d->acl[acl_d->count++];
2340 + entry_d->a_type = 0;
2341 + entry_d->a_id = -1;
2342 + entry_d->a_perm = 0;
2343 + *entry_p = entry_d;
2348 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2350 + switch (tag_type) {
2351 + case SMB_ACL_USER:
2352 + case SMB_ACL_USER_OBJ:
2353 + case SMB_ACL_GROUP:
2354 + case SMB_ACL_GROUP_OBJ:
2355 + case SMB_ACL_OTHER:
2356 + case SMB_ACL_MASK:
2357 + entry_d->a_type = tag_type;
2367 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2369 + if (entry_d->a_type != SMB_ACL_GROUP
2370 + && entry_d->a_type != SMB_ACL_USER) {
2375 + entry_d->a_id = *((id_t *)qual_p);
2380 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2382 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2386 + entry_d->a_perm = *permset_d;
2392 + * sort the ACL and check it for validity
2394 + * if it's a minimal ACL with only 4 entries then we
2395 + * need to recalculate the mask permissions to make
2396 + * sure that they are the same as the GROUP_OBJ
2397 + * permissions as required by the UnixWare acl() system call.
2399 + * (note: since POSIX allows minimal ACLs which only contain
2400 + * 3 entries - ie there is no mask entry - we should, in theory,
2401 + * check for this and add a mask entry if necessary - however
2402 + * we "know" that the caller of this interface always specifies
2403 + * a mask so, in practice "this never happens" (tm) - if it *does*
2404 + * happen aclsort() will fail and return an error and someone will
2405 + * have to fix it ...)
2408 +static int acl_sort(SMB_ACL_T acl_d)
2410 + int fixmask = (acl_d->count <= 4);
2412 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2419 +int sys_acl_valid(SMB_ACL_T acl_d)
2421 + return acl_sort(acl_d);
2424 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2427 + struct acl *acl_p;
2429 + struct acl *acl_buf = NULL;
2432 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2437 + if (acl_sort(acl_d) != 0) {
2441 + acl_p = &acl_d->acl[0];
2442 + acl_count = acl_d->count;
2445 + * if it's a directory there is extra work to do
2446 + * since the acl() system call will replace both
2447 + * the access ACLs and the default ACLs (if any)
2449 + if (stat(name, &s) != 0) {
2452 + if (S_ISDIR(s.st_mode)) {
2453 + SMB_ACL_T acc_acl;
2454 + SMB_ACL_T def_acl;
2455 + SMB_ACL_T tmp_acl;
2458 + if (type == SMB_ACL_TYPE_ACCESS) {
2460 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2464 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2467 + if (tmp_acl == NULL) {
2472 + * allocate a temporary buffer for the complete ACL
2474 + acl_count = acc_acl->count + def_acl->count;
2475 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2477 + if (acl_buf == NULL) {
2478 + sys_acl_free_acl(tmp_acl);
2484 + * copy the access control and default entries into the buffer
2486 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2487 + acc_acl->count * sizeof(acl_buf[0]));
2489 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2490 + def_acl->count * sizeof(acl_buf[0]));
2493 + * set the ACL_DEFAULT flag on the default entries
2495 + for (i = acc_acl->count; i < acl_count; i++) {
2496 + acl_buf[i].a_type |= ACL_DEFAULT;
2499 + sys_acl_free_acl(tmp_acl);
2501 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2506 + ret = acl(name, SETACL, acl_count, acl_p);
2508 + SAFE_FREE(acl_buf);
2513 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2515 + if (acl_sort(acl_d) != 0) {
2519 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2522 +int sys_acl_delete_def_file(const char *path)
2528 + * fetching the access ACL and rewriting it has
2529 + * the effect of deleting the default ACL
2531 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2535 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2537 + sys_acl_free_acl(acl_d);
2542 +int sys_acl_free_text(char *text)
2548 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2554 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2559 +#elif defined(HAVE_HPUX_ACLS)
2563 + * Based on the Solaris/SCO code - with modifications.
2567 + * Note that while this code implements sufficient functionality
2568 + * to support the sys_acl_* interfaces it does not provide all
2569 + * of the semantics of the POSIX ACL interfaces.
2571 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2572 + * from a call to sys_acl_get_entry() should not be assumed to be
2573 + * valid after calling any of the following functions, which may
2574 + * reorder the entries in the ACL.
2577 + * sys_acl_set_file()
2578 + * sys_acl_set_fd()
2581 +/* This checks if the POSIX ACL system call is defined */
2582 +/* which basically corresponds to whether JFS 3.3 or */
2583 +/* higher is installed. If acl() was called when it */
2584 +/* isn't defined, it causes the process to core dump */
2585 +/* so it is important to check this and avoid acl() */
2586 +/* calls if it isn't there. */
2588 +static BOOL hpux_acl_call_presence(void)
2591 + shl_t handle = NULL;
2594 + static BOOL already_checked=0;
2596 + if(already_checked)
2600 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2602 + if(ret_val != 0) {
2603 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2604 + ret_val, errno, strerror(errno)));
2605 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2609 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2611 + already_checked = True;
2615 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2617 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2622 + if (entry_p == NULL) {
2627 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2631 + if (acl_d->next < 0) {
2636 + if (acl_d->next >= acl_d->count) {
2640 + *entry_p = &acl_d->acl[acl_d->next++];
2645 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2647 + *type_p = entry_d->a_type;
2652 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2654 + *permset_p = &entry_d->a_perm;
2659 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2661 + if (entry_d->a_type != SMB_ACL_USER
2662 + && entry_d->a_type != SMB_ACL_GROUP) {
2667 + return &entry_d->a_id;
2671 + * There is no way of knowing what size the ACL returned by
2672 + * ACL_GET will be unless you first call ACL_CNT which means
2673 + * making an additional system call.
2675 + * In the hope of avoiding the cost of the additional system
2676 + * call in most cases, we initially allocate enough space for
2677 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2678 + * be too small then we use ACL_CNT to find out the actual
2679 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2682 +#define INITIAL_ACL_SIZE 16
2684 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2687 + int count; /* # of ACL entries allocated */
2688 + int naccess; /* # of access ACL entries */
2689 + int ndefault; /* # of default ACL entries */
2691 + if(hpux_acl_call_presence() == False) {
2692 + /* Looks like we don't have the acl() system call on HPUX.
2693 + * May be the system doesn't have the latest version of JFS.
2698 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2703 + count = INITIAL_ACL_SIZE;
2704 + if ((acl_d = sys_acl_init(count)) == NULL) {
2709 + * If there isn't enough space for the ACL entries we use
2710 + * ACL_CNT to determine the actual number of ACL entries
2711 + * reallocate and try again. This is in a loop because it
2712 + * is possible that someone else could modify the ACL and
2713 + * increase the number of entries between the call to
2714 + * ACL_CNT and the call to ACL_GET.
2716 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2718 + sys_acl_free_acl(acl_d);
2720 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2724 + if ((acl_d = sys_acl_init(count)) == NULL) {
2730 + sys_acl_free_acl(acl_d);
2735 + * calculate the number of access and default ACL entries
2737 + * Note: we assume that the acl() system call returned a
2738 + * well formed ACL which is sorted so that all of the
2739 + * access ACL entries preceed any default ACL entries
2741 + for (naccess = 0; naccess < count; naccess++) {
2742 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2745 + ndefault = count - naccess;
2748 + * if the caller wants the default ACL we have to copy
2749 + * the entries down to the start of the acl[] buffer
2750 + * and mask out the ACL_DEFAULT flag from the type field
2752 + if (type == SMB_ACL_TYPE_DEFAULT) {
2755 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2756 + acl_d->acl[i] = acl_d->acl[j];
2757 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2760 + acl_d->count = ndefault;
2762 + acl_d->count = naccess;
2768 +SMB_ACL_T sys_acl_get_fd(int fd)
2771 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2774 + files_struct *fsp = file_find_fd(fd);
2776 + if (fsp == NULL) {
2782 + * We know we're in the same conn context. So we
2783 + * can use the relative path.
2786 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2789 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2796 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2798 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2799 + && perm != SMB_ACL_EXECUTE) {
2804 + if (permset_d == NULL) {
2809 + *permset_d |= perm;
2814 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2816 + return *permset_d & perm;
2819 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2826 + * use an initial estimate of 20 bytes per ACL entry
2827 + * when allocating memory for the text representation
2831 + maxlen = 20 * acl_d->count;
2832 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2837 + for (i = 0; i < acl_d->count; i++) {
2838 + struct acl *ap = &acl_d->acl[i];
2847 + switch (ap->a_type) {
2849 + * for debugging purposes it's probably more
2850 + * useful to dump unknown tag types rather
2851 + * than just returning an error
2854 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2857 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2862 + case SMB_ACL_USER:
2863 + id = uidtoname(ap->a_id);
2864 + case SMB_ACL_USER_OBJ:
2868 + case SMB_ACL_GROUP:
2869 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2870 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2876 + case SMB_ACL_GROUP_OBJ:
2880 + case SMB_ACL_OTHER:
2884 + case SMB_ACL_MASK:
2890 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2891 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2892 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2895 + /* <tag> : <qualifier> : rwx \n \0 */
2896 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2899 + * If this entry would overflow the buffer
2900 + * allocate enough additional memory for this
2901 + * entry and an estimate of another 20 bytes
2902 + * for each entry still to be processed
2904 + if ((len + nbytes) > maxlen) {
2905 + char *oldtext = text;
2907 + maxlen += nbytes + 20 * (acl_d->count - i);
2909 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2916 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2917 + len += nbytes - 1;
2926 +SMB_ACL_T sys_acl_init(int count)
2936 + * note that since the definition of the structure pointed
2937 + * to by the SMB_ACL_T includes the first element of the
2938 + * acl[] array, this actually allocates an ACL with room
2939 + * for (count+1) entries
2941 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2946 + a->size = count + 1;
2954 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2957 + SMB_ACL_ENTRY_T entry_d;
2959 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2964 + if (acl_d->count >= acl_d->size) {
2969 + entry_d = &acl_d->acl[acl_d->count++];
2970 + entry_d->a_type = 0;
2971 + entry_d->a_id = -1;
2972 + entry_d->a_perm = 0;
2973 + *entry_p = entry_d;
2978 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2980 + switch (tag_type) {
2981 + case SMB_ACL_USER:
2982 + case SMB_ACL_USER_OBJ:
2983 + case SMB_ACL_GROUP:
2984 + case SMB_ACL_GROUP_OBJ:
2985 + case SMB_ACL_OTHER:
2986 + case SMB_ACL_MASK:
2987 + entry_d->a_type = tag_type;
2997 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2999 + if (entry_d->a_type != SMB_ACL_GROUP
3000 + && entry_d->a_type != SMB_ACL_USER) {
3005 + entry_d->a_id = *((id_t *)qual_p);
3010 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3012 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3016 + entry_d->a_perm = *permset_d;
3021 +/* Structure to capture the count for each type of ACE. */
3023 +struct hpux_acl_types {
3027 + int n_def_user_obj;
3032 + int n_def_group_obj;
3036 + int n_def_other_obj;
3039 + int n_def_class_obj;
3041 + int n_illegal_obj;
3045 + * Counts the different number of objects in a given array of ACL
3049 + * acl_count - Count of ACLs in the array of ACL strucutres.
3050 + * aclp - Array of ACL structures.
3051 + * acl_type_count - Pointer to acl_types structure. Should already be
3055 + * acl_type_count - This structure is filled up with counts of various
3059 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3063 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3065 + for(i=0;i<acl_count;i++) {
3066 + switch(aclp[i].a_type) {
3068 + acl_type_count->n_user++;
3071 + acl_type_count->n_user_obj++;
3073 + case DEF_USER_OBJ:
3074 + acl_type_count->n_def_user_obj++;
3077 + acl_type_count->n_group++;
3080 + acl_type_count->n_group_obj++;
3082 + case DEF_GROUP_OBJ:
3083 + acl_type_count->n_def_group_obj++;
3086 + acl_type_count->n_other_obj++;
3088 + case DEF_OTHER_OBJ:
3089 + acl_type_count->n_def_other_obj++;
3092 + acl_type_count->n_class_obj++;
3094 + case DEF_CLASS_OBJ:
3095 + acl_type_count->n_def_class_obj++;
3098 + acl_type_count->n_def_user++;
3101 + acl_type_count->n_def_group++;
3104 + acl_type_count->n_illegal_obj++;
3110 +/* swap_acl_entries: Swaps two ACL entries.
3112 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3115 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3117 + struct acl temp_acl;
3119 + temp_acl.a_type = aclp0->a_type;
3120 + temp_acl.a_id = aclp0->a_id;
3121 + temp_acl.a_perm = aclp0->a_perm;
3123 + aclp0->a_type = aclp1->a_type;
3124 + aclp0->a_id = aclp1->a_id;
3125 + aclp0->a_perm = aclp1->a_perm;
3127 + aclp1->a_type = temp_acl.a_type;
3128 + aclp1->a_id = temp_acl.a_id;
3129 + aclp1->a_perm = temp_acl.a_perm;
3132 +/* prohibited_duplicate_type
3133 + * Identifies if given ACL type can have duplicate entries or
3136 + * Inputs: acl_type - ACL Type.
3142 + * True - If the ACL type matches any of the prohibited types.
3143 + * False - If the ACL type doesn't match any of the prohibited types.
3146 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3148 + switch(acl_type) {
3159 +/* get_needed_class_perm
3160 + * Returns the permissions of a ACL structure only if the ACL
3161 + * type matches one of the pre-determined types for computing
3162 + * CLASS_OBJ permissions.
3164 + * Inputs: aclp - Pointer to ACL structure.
3167 +static int hpux_get_needed_class_perm(struct acl *aclp)
3169 + switch(aclp->a_type) {
3173 + case DEF_USER_OBJ:
3175 + case DEF_GROUP_OBJ:
3177 + case DEF_CLASS_OBJ:
3178 + case DEF_OTHER_OBJ:
3179 + return aclp->a_perm;
3185 +/* acl_sort for HPUX.
3186 + * Sorts the array of ACL structures as per the description in
3187 + * aclsort man page. Refer to aclsort man page for more details
3191 + * acl_count - Count of ACLs in the array of ACL structures.
3192 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3194 + * aclp - Array of ACL structures.
3198 + * aclp - Sorted array of ACL structures.
3202 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3203 + * debug log in case of failure.
3206 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3208 +#if !defined(HAVE_HPUX_ACLSORT)
3210 + * The aclsort() system call is availabe on the latest HPUX General
3211 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3212 + * function. Because, we don't want to update to a new
3213 + * HPUX GR bundle just for aclsort() call.
3216 + struct hpux_acl_types acl_obj_count;
3217 + int n_class_obj_perm = 0;
3221 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3225 + if(aclp == NULL) {
3226 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3230 + /* Count different types of ACLs in the ACLs array */
3232 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3234 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3235 + * CLASS_OBJ and OTHER_OBJ
3238 + if( (acl_obj_count.n_user_obj != 1) ||
3239 + (acl_obj_count.n_group_obj != 1) ||
3240 + (acl_obj_count.n_class_obj != 1) ||
3241 + (acl_obj_count.n_other_obj != 1)
3243 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3244 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3248 + /* If any of the default objects are present, there should be only
3249 + * one of them each.
3252 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3253 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3254 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3255 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3259 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3262 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3263 + * same ACL type, sort by ACL id.
3265 + * I am using the trival kind of sorting method here because, performance isn't
3266 + * really effected by the ACLs feature. More over there aren't going to be more
3267 + * than 17 entries on HPUX.
3270 + for(i=0; i<acl_count;i++) {
3271 + for (j=i+1; j<acl_count; j++) {
3272 + if( aclp[i].a_type > aclp[j].a_type ) {
3273 + /* ACL entries out of order, swap them */
3275 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3277 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3279 + /* ACL entries of same type, sort by id */
3281 + if(aclp[i].a_id > aclp[j].a_id) {
3282 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3283 + } else if (aclp[i].a_id == aclp[j].a_id) {
3284 + /* We have a duplicate entry. */
3285 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3286 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3287 + aclp[i].a_type, aclp[i].a_id));
3296 + /* set the class obj permissions to the computed one. */
3298 + int n_class_obj_index = -1;
3300 + for(i=0;i<acl_count;i++) {
3301 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3303 + if(aclp[i].a_type == CLASS_OBJ)
3304 + n_class_obj_index = i;
3306 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3311 + return aclsort(acl_count, calclass, aclp);
3316 + * sort the ACL and check it for validity
3318 + * if it's a minimal ACL with only 4 entries then we
3319 + * need to recalculate the mask permissions to make
3320 + * sure that they are the same as the GROUP_OBJ
3321 + * permissions as required by the UnixWare acl() system call.
3323 + * (note: since POSIX allows minimal ACLs which only contain
3324 + * 3 entries - ie there is no mask entry - we should, in theory,
3325 + * check for this and add a mask entry if necessary - however
3326 + * we "know" that the caller of this interface always specifies
3327 + * a mask so, in practice "this never happens" (tm) - if it *does*
3328 + * happen aclsort() will fail and return an error and someone will
3329 + * have to fix it ...)
3332 +static int acl_sort(SMB_ACL_T acl_d)
3334 + int fixmask = (acl_d->count <= 4);
3336 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3343 +int sys_acl_valid(SMB_ACL_T acl_d)
3345 + return acl_sort(acl_d);
3348 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3351 + struct acl *acl_p;
3353 + struct acl *acl_buf = NULL;
3356 + if(hpux_acl_call_presence() == False) {
3357 + /* Looks like we don't have the acl() system call on HPUX.
3358 + * May be the system doesn't have the latest version of JFS.
3364 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3369 + if (acl_sort(acl_d) != 0) {
3373 + acl_p = &acl_d->acl[0];
3374 + acl_count = acl_d->count;
3377 + * if it's a directory there is extra work to do
3378 + * since the acl() system call will replace both
3379 + * the access ACLs and the default ACLs (if any)
3381 + if (stat(name, &s) != 0) {
3384 + if (S_ISDIR(s.st_mode)) {
3385 + SMB_ACL_T acc_acl;
3386 + SMB_ACL_T def_acl;
3387 + SMB_ACL_T tmp_acl;
3390 + if (type == SMB_ACL_TYPE_ACCESS) {
3392 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3396 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3399 + if (tmp_acl == NULL) {
3404 + * allocate a temporary buffer for the complete ACL
3406 + acl_count = acc_acl->count + def_acl->count;
3407 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3409 + if (acl_buf == NULL) {
3410 + sys_acl_free_acl(tmp_acl);
3416 + * copy the access control and default entries into the buffer
3418 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3419 + acc_acl->count * sizeof(acl_buf[0]));
3421 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3422 + def_acl->count * sizeof(acl_buf[0]));
3425 + * set the ACL_DEFAULT flag on the default entries
3427 + for (i = acc_acl->count; i < acl_count; i++) {
3428 + acl_buf[i].a_type |= ACL_DEFAULT;
3431 + sys_acl_free_acl(tmp_acl);
3433 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3438 + ret = acl(name, ACL_SET, acl_count, acl_p);
3447 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3450 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3453 + files_struct *fsp = file_find_fd(fd);
3455 + if (fsp == NULL) {
3460 + if (acl_sort(acl_d) != 0) {
3465 + * We know we're in the same conn context. So we
3466 + * can use the relative path.
3469 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3472 +int sys_acl_delete_def_file(const char *path)
3478 + * fetching the access ACL and rewriting it has
3479 + * the effect of deleting the default ACL
3481 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3485 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3487 + sys_acl_free_acl(acl_d);
3492 +int sys_acl_free_text(char *text)
3498 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3504 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3509 +#elif defined(HAVE_IRIX_ACLS)
3511 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3513 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3518 + if (entry_p == NULL) {
3523 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3527 + if (acl_d->next < 0) {
3532 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3536 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3541 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3543 + *type_p = entry_d->ae_tag;
3548 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3550 + *permset_p = entry_d;
3555 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3557 + if (entry_d->ae_tag != SMB_ACL_USER
3558 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3563 + return &entry_d->ae_id;
3566 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3570 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3574 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3579 + a->freeaclp = True;
3583 +SMB_ACL_T sys_acl_get_fd(int fd)
3587 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3591 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3596 + a->freeaclp = True;
3600 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3602 + permset_d->ae_perm = 0;
3607 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3609 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3610 + && perm != SMB_ACL_EXECUTE) {
3615 + if (permset_d == NULL) {
3620 + permset_d->ae_perm |= perm;
3625 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3627 + return permset_d->ae_perm & perm;
3630 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3632 + return acl_to_text(acl_d->aclp, len_p);
3635 +SMB_ACL_T sys_acl_init(int count)
3644 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3650 + a->freeaclp = False;
3651 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3652 + a->aclp->acl_cnt = 0;
3658 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3661 + SMB_ACL_ENTRY_T entry_d;
3663 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3668 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3673 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3674 + entry_d->ae_tag = 0;
3675 + entry_d->ae_id = 0;
3676 + entry_d->ae_perm = 0;
3677 + *entry_p = entry_d;
3682 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3684 + switch (tag_type) {
3685 + case SMB_ACL_USER:
3686 + case SMB_ACL_USER_OBJ:
3687 + case SMB_ACL_GROUP:
3688 + case SMB_ACL_GROUP_OBJ:
3689 + case SMB_ACL_OTHER:
3690 + case SMB_ACL_MASK:
3691 + entry_d->ae_tag = tag_type;
3701 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3703 + if (entry_d->ae_tag != SMB_ACL_GROUP
3704 + && entry_d->ae_tag != SMB_ACL_USER) {
3709 + entry_d->ae_id = *((id_t *)qual_p);
3714 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3716 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3720 + entry_d->ae_perm = permset_d->ae_perm;
3725 +int sys_acl_valid(SMB_ACL_T acl_d)
3727 + return acl_valid(acl_d->aclp);
3730 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3732 + return acl_set_file(name, type, acl_d->aclp);
3735 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3737 + return acl_set_fd(fd, acl_d->aclp);
3740 +int sys_acl_delete_def_file(const char *name)
3742 + return acl_delete_def_file(name);
3745 +int sys_acl_free_text(char *text)
3747 + return acl_free(text);
3750 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3752 + if (acl_d->freeaclp) {
3753 + acl_free(acl_d->aclp);
3759 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3764 +#elif defined(HAVE_AIX_ACLS)
3766 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3768 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3770 + struct acl_entry_link *link;
3771 + struct new_acl_entry *entry;
3774 + DEBUG(10,("This is the count: %d\n",theacl->count));
3776 + /* Check if count was previously set to -1. *
3777 + * If it was, that means we reached the end *
3778 + * of the acl last time. */
3779 + if(theacl->count == -1)
3783 + /* To get to the next acl, traverse linked list until index *
3784 + * of acl matches the count we are keeping. This count is *
3785 + * incremented each time we return an acl entry. */
3787 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3788 + link = link->nextp;
3790 + entry = *entry_p = link->entryp;
3792 + DEBUG(10,("*entry_p is %d\n",entry_p));
3793 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3795 + /* Increment count */
3797 + if(link->nextp == NULL)
3798 + theacl->count = -1;
3803 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3805 + /* Initialize tag type */
3808 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3810 + /* Depending on what type of entry we have, *
3811 + * return tag type. */
3812 + switch(entry_d->ace_id->id_type) {
3814 + *tag_type_p = SMB_ACL_USER;
3817 + *tag_type_p = SMB_ACL_GROUP;
3820 + case SMB_ACL_USER_OBJ:
3821 + case SMB_ACL_GROUP_OBJ:
3822 + case SMB_ACL_OTHER:
3823 + *tag_type_p = entry_d->ace_id->id_type;
3833 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3835 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3836 + *permset_p = &entry_d->ace_access;
3837 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3838 + if(!(**permset_p & S_IXUSR) &&
3839 + !(**permset_p & S_IWUSR) &&
3840 + !(**permset_p & S_IRUSR) &&
3841 + (**permset_p != 0))
3844 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3848 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3850 + return(entry_d->ace_id->id_data);
3853 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3855 + struct acl *file_acl = (struct acl *)NULL;
3856 + struct acl_entry *acl_entry;
3857 + struct new_acl_entry *new_acl_entry;
3858 + struct ace_id *idp;
3859 + struct acl_entry_link *acl_entry_link;
3860 + struct acl_entry_link *acl_entry_link_head;
3865 + /* AIX has no DEFAULT */
3866 + if ( type == SMB_ACL_TYPE_DEFAULT )
3869 + /* Get the acl using statacl */
3871 + DEBUG(10,("Entering sys_acl_get_file\n"));
3872 + DEBUG(10,("path_p is %s\n",path_p));
3874 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3876 + if(file_acl == NULL) {
3878 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3882 + memset(file_acl,0,BUFSIZ);
3884 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3886 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3887 + SAFE_FREE(file_acl);
3891 + DEBUG(10,("Got facl and returned it\n"));
3893 + /* Point to the first acl entry in the acl */
3894 + acl_entry = file_acl->acl_ext;
3896 + /* Begin setting up the head of the linked list *
3897 + * that will be used for the storing the acl *
3898 + * in a way that is useful for the posix_acls.c *
3901 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3902 + if(acl_entry_link_head == NULL)
3905 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3906 + if(acl_entry_link->entryp == NULL) {
3907 + SAFE_FREE(file_acl);
3909 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3913 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3914 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3916 + /* Check if the extended acl bit is on. *
3917 + * If it isn't, do not show the *
3918 + * contents of the acl since AIX intends *
3919 + * the extended info to remain unused */
3921 + if(file_acl->acl_mode & S_IXACL){
3922 + /* while we are not pointing to the very end */
3923 + while(acl_entry < acl_last(file_acl)) {
3924 + /* before we malloc anything, make sure this is */
3925 + /* a valid acl entry and one that we want to map */
3926 + idp = id_nxt(acl_entry->ace_id);
3927 + if((acl_entry->ace_type == ACC_SPECIFY ||
3928 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3929 + acl_entry = acl_nxt(acl_entry);
3933 + idp = acl_entry->ace_id;
3935 + /* Check if this is the first entry in the linked list. *
3936 + * The first entry needs to keep prevp pointing to NULL *
3937 + * and already has entryp allocated. */
3939 + if(acl_entry_link_head->count != 0) {
3940 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3942 + if(acl_entry_link->nextp == NULL) {
3943 + SAFE_FREE(file_acl);
3945 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3949 + acl_entry_link->nextp->prevp = acl_entry_link;
3950 + acl_entry_link = acl_entry_link->nextp;
3951 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3952 + if(acl_entry_link->entryp == NULL) {
3953 + SAFE_FREE(file_acl);
3955 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3958 + acl_entry_link->nextp = NULL;
3961 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3963 + /* Don't really need this since all types are going *
3964 + * to be specified but, it's better than leaving it 0 */
3966 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3968 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3970 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3972 + /* The access in the acl entries must be left shifted by *
3973 + * three bites, because they will ultimately be compared *
3974 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3976 + switch(acl_entry->ace_type){
3979 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3980 + acl_entry_link->entryp->ace_access <<= 6;
3981 + acl_entry_link_head->count++;
3984 + /* Since there is no way to return a DENY acl entry *
3985 + * change to PERMIT and then shift. */
3986 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3987 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3988 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3989 + acl_entry_link->entryp->ace_access <<= 6;
3990 + acl_entry_link_head->count++;
3996 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3997 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3999 + acl_entry = acl_nxt(acl_entry);
4001 + } /* end of if enabled */
4003 + /* Since owner, group, other acl entries are not *
4004 + * part of the acl entries in an acl, they must *
4005 + * be dummied up to become part of the list. */
4007 + for( i = 1; i < 4; i++) {
4008 + DEBUG(10,("i is %d\n",i));
4009 + if(acl_entry_link_head->count != 0) {
4010 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4011 + if(acl_entry_link->nextp == NULL) {
4012 + SAFE_FREE(file_acl);
4014 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4018 + acl_entry_link->nextp->prevp = acl_entry_link;
4019 + acl_entry_link = acl_entry_link->nextp;
4020 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4021 + if(acl_entry_link->entryp == NULL) {
4022 + SAFE_FREE(file_acl);
4024 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4029 + acl_entry_link->nextp = NULL;
4031 + new_acl_entry = acl_entry_link->entryp;
4032 + idp = new_acl_entry->ace_id;
4034 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4035 + new_acl_entry->ace_type = ACC_PERMIT;
4036 + idp->id_len = sizeof(struct ace_id);
4037 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4038 + memset(idp->id_data,0,sizeof(uid_t));
4042 + new_acl_entry->ace_access = file_acl->g_access << 6;
4043 + idp->id_type = SMB_ACL_GROUP_OBJ;
4047 + new_acl_entry->ace_access = file_acl->o_access << 6;
4048 + idp->id_type = SMB_ACL_OTHER;
4052 + new_acl_entry->ace_access = file_acl->u_access << 6;
4053 + idp->id_type = SMB_ACL_USER_OBJ;
4061 + acl_entry_link_head->count++;
4062 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4065 + acl_entry_link_head->count = 0;
4066 + SAFE_FREE(file_acl);
4068 + return(acl_entry_link_head);
4071 +SMB_ACL_T sys_acl_get_fd(int fd)
4073 + struct acl *file_acl = (struct acl *)NULL;
4074 + struct acl_entry *acl_entry;
4075 + struct new_acl_entry *new_acl_entry;
4076 + struct ace_id *idp;
4077 + struct acl_entry_link *acl_entry_link;
4078 + struct acl_entry_link *acl_entry_link_head;
4083 + /* Get the acl using fstatacl */
4085 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4086 + DEBUG(10,("fd is %d\n",fd));
4087 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4089 + if(file_acl == NULL) {
4091 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4095 + memset(file_acl,0,BUFSIZ);
4097 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4099 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4100 + SAFE_FREE(file_acl);
4104 + DEBUG(10,("Got facl and returned it\n"));
4106 + /* Point to the first acl entry in the acl */
4108 + acl_entry = file_acl->acl_ext;
4109 + /* Begin setting up the head of the linked list *
4110 + * that will be used for the storing the acl *
4111 + * in a way that is useful for the posix_acls.c *
4114 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4115 + if(acl_entry_link_head == NULL){
4116 + SAFE_FREE(file_acl);
4120 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4122 + if(acl_entry_link->entryp == NULL) {
4124 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4125 + SAFE_FREE(file_acl);
4129 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4130 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4132 + /* Check if the extended acl bit is on. *
4133 + * If it isn't, do not show the *
4134 + * contents of the acl since AIX intends *
4135 + * the extended info to remain unused */
4137 + if(file_acl->acl_mode & S_IXACL){
4138 + /* while we are not pointing to the very end */
4139 + while(acl_entry < acl_last(file_acl)) {
4140 + /* before we malloc anything, make sure this is */
4141 + /* a valid acl entry and one that we want to map */
4143 + idp = id_nxt(acl_entry->ace_id);
4144 + if((acl_entry->ace_type == ACC_SPECIFY ||
4145 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4146 + acl_entry = acl_nxt(acl_entry);
4150 + idp = acl_entry->ace_id;
4152 + /* Check if this is the first entry in the linked list. *
4153 + * The first entry needs to keep prevp pointing to NULL *
4154 + * and already has entryp allocated. */
4156 + if(acl_entry_link_head->count != 0) {
4157 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4158 + if(acl_entry_link->nextp == NULL) {
4160 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4161 + SAFE_FREE(file_acl);
4164 + acl_entry_link->nextp->prevp = acl_entry_link;
4165 + acl_entry_link = acl_entry_link->nextp;
4166 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4167 + if(acl_entry_link->entryp == NULL) {
4169 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4170 + SAFE_FREE(file_acl);
4174 + acl_entry_link->nextp = NULL;
4177 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4179 + /* Don't really need this since all types are going *
4180 + * to be specified but, it's better than leaving it 0 */
4182 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4183 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4185 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4187 + /* The access in the acl entries must be left shifted by *
4188 + * three bites, because they will ultimately be compared *
4189 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4191 + switch(acl_entry->ace_type){
4194 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4195 + acl_entry_link->entryp->ace_access <<= 6;
4196 + acl_entry_link_head->count++;
4199 + /* Since there is no way to return a DENY acl entry *
4200 + * change to PERMIT and then shift. */
4201 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4202 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4203 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4204 + acl_entry_link->entryp->ace_access <<= 6;
4205 + acl_entry_link_head->count++;
4211 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4212 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4214 + acl_entry = acl_nxt(acl_entry);
4216 + } /* end of if enabled */
4218 + /* Since owner, group, other acl entries are not *
4219 + * part of the acl entries in an acl, they must *
4220 + * be dummied up to become part of the list. */
4222 + for( i = 1; i < 4; i++) {
4223 + DEBUG(10,("i is %d\n",i));
4224 + if(acl_entry_link_head->count != 0){
4225 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4226 + if(acl_entry_link->nextp == NULL) {
4228 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4229 + SAFE_FREE(file_acl);
4233 + acl_entry_link->nextp->prevp = acl_entry_link;
4234 + acl_entry_link = acl_entry_link->nextp;
4235 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4237 + if(acl_entry_link->entryp == NULL) {
4238 + SAFE_FREE(file_acl);
4240 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4245 + acl_entry_link->nextp = NULL;
4247 + new_acl_entry = acl_entry_link->entryp;
4248 + idp = new_acl_entry->ace_id;
4250 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4251 + new_acl_entry->ace_type = ACC_PERMIT;
4252 + idp->id_len = sizeof(struct ace_id);
4253 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4254 + memset(idp->id_data,0,sizeof(uid_t));
4258 + new_acl_entry->ace_access = file_acl->g_access << 6;
4259 + idp->id_type = SMB_ACL_GROUP_OBJ;
4263 + new_acl_entry->ace_access = file_acl->o_access << 6;
4264 + idp->id_type = SMB_ACL_OTHER;
4268 + new_acl_entry->ace_access = file_acl->u_access << 6;
4269 + idp->id_type = SMB_ACL_USER_OBJ;
4276 + acl_entry_link_head->count++;
4277 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4280 + acl_entry_link_head->count = 0;
4281 + SAFE_FREE(file_acl);
4283 + return(acl_entry_link_head);
4286 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4288 + *permset = *permset & ~0777;
4292 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4295 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4299 + DEBUG(10,("This is the permset now: %d\n",*permset));
4303 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4308 +SMB_ACL_T sys_acl_init( int count)
4310 + struct acl_entry_link *theacl = NULL;
4312 + DEBUG(10,("Entering sys_acl_init\n"));
4314 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4315 + if(theacl == NULL) {
4317 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4321 + theacl->count = 0;
4322 + theacl->nextp = NULL;
4323 + theacl->prevp = NULL;
4324 + theacl->entryp = NULL;
4325 + DEBUG(10,("Exiting sys_acl_init\n"));
4329 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4331 + struct acl_entry_link *theacl;
4332 + struct acl_entry_link *acl_entryp;
4333 + struct acl_entry_link *temp_entry;
4336 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4338 + theacl = acl_entryp = *pacl;
4340 + /* Get to the end of the acl before adding entry */
4342 + for(counting=0; counting < theacl->count; counting++){
4343 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4344 + temp_entry = acl_entryp;
4345 + acl_entryp = acl_entryp->nextp;
4348 + if(theacl->count != 0){
4349 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4350 + if(acl_entryp == NULL) {
4352 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4356 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4357 + acl_entryp->prevp = temp_entry;
4358 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4361 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4362 + if(*pentry == NULL) {
4364 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4368 + memset(*pentry,0,sizeof(struct new_acl_entry));
4369 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4370 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4371 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4372 + acl_entryp->nextp = NULL;
4374 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4378 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4380 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4381 + entry->ace_id->id_type = tagtype;
4382 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4383 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4386 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4388 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4389 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4390 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4394 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4396 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4397 + if(!(*permset & S_IXUSR) &&
4398 + !(*permset & S_IWUSR) &&
4399 + !(*permset & S_IRUSR) &&
4403 + entry->ace_access = *permset;
4404 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4405 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4409 +int sys_acl_valid( SMB_ACL_T theacl )
4412 + int group_obj = 0;
4413 + int other_obj = 0;
4414 + struct acl_entry_link *acl_entry;
4416 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4417 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4418 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4419 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4422 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4424 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4430 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4432 + struct acl_entry_link *acl_entry_link = NULL;
4433 + struct acl *file_acl = NULL;
4434 + struct acl *file_acl_temp = NULL;
4435 + struct acl_entry *acl_entry = NULL;
4436 + struct ace_id *ace_id = NULL;
4443 + DEBUG(10,("Entering sys_acl_set_file\n"));
4444 + DEBUG(10,("File name is %s\n",name));
4446 + /* AIX has no default ACL */
4447 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4450 + acl_length = BUFSIZ;
4451 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4453 + if(file_acl == NULL) {
4455 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4459 + memset(file_acl,0,BUFSIZ);
4461 + file_acl->acl_len = ACL_SIZ;
4462 + file_acl->acl_mode = S_IXACL;
4464 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4465 + acl_entry_link->entryp->ace_access >>= 6;
4466 + id_type = acl_entry_link->entryp->ace_id->id_type;
4469 + case SMB_ACL_USER_OBJ:
4470 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4472 + case SMB_ACL_GROUP_OBJ:
4473 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4475 + case SMB_ACL_OTHER:
4476 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4478 + case SMB_ACL_MASK:
4482 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4483 + acl_length += sizeof(struct acl_entry);
4484 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4485 + if(file_acl_temp == NULL) {
4486 + SAFE_FREE(file_acl);
4488 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4492 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4493 + SAFE_FREE(file_acl);
4494 + file_acl = file_acl_temp;
4497 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4498 + file_acl->acl_len += sizeof(struct acl_entry);
4499 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4500 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4502 + /* In order to use this, we'll need to wait until we can get denies */
4503 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4504 + acl_entry->ace_type = ACC_SPECIFY; */
4506 + acl_entry->ace_type = ACC_SPECIFY;
4508 + ace_id = acl_entry->ace_id;
4510 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4511 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4512 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4513 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4514 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4517 + rc = chacl(name,file_acl,file_acl->acl_len);
4518 + DEBUG(10,("errno is %d\n",errno));
4519 + DEBUG(10,("return code is %d\n",rc));
4520 + SAFE_FREE(file_acl);
4521 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4525 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4527 + struct acl_entry_link *acl_entry_link = NULL;
4528 + struct acl *file_acl = NULL;
4529 + struct acl *file_acl_temp = NULL;
4530 + struct acl_entry *acl_entry = NULL;
4531 + struct ace_id *ace_id = NULL;
4537 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4538 + acl_length = BUFSIZ;
4539 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4541 + if(file_acl == NULL) {
4543 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4547 + memset(file_acl,0,BUFSIZ);
4549 + file_acl->acl_len = ACL_SIZ;
4550 + file_acl->acl_mode = S_IXACL;
4552 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4553 + acl_entry_link->entryp->ace_access >>= 6;
4554 + id_type = acl_entry_link->entryp->ace_id->id_type;
4555 + DEBUG(10,("The id_type is %d\n",id_type));
4558 + case SMB_ACL_USER_OBJ:
4559 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4561 + case SMB_ACL_GROUP_OBJ:
4562 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4564 + case SMB_ACL_OTHER:
4565 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4567 + case SMB_ACL_MASK:
4571 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4572 + acl_length += sizeof(struct acl_entry);
4573 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4574 + if(file_acl_temp == NULL) {
4575 + SAFE_FREE(file_acl);
4577 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4581 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4582 + SAFE_FREE(file_acl);
4583 + file_acl = file_acl_temp;
4586 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4587 + file_acl->acl_len += sizeof(struct acl_entry);
4588 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4589 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4591 + /* In order to use this, we'll need to wait until we can get denies */
4592 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4593 + acl_entry->ace_type = ACC_SPECIFY; */
4595 + acl_entry->ace_type = ACC_SPECIFY;
4597 + ace_id = acl_entry->ace_id;
4599 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4600 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4601 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4602 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4603 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4606 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4607 + DEBUG(10,("errno is %d\n",errno));
4608 + DEBUG(10,("return code is %d\n",rc));
4609 + SAFE_FREE(file_acl);
4610 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4614 +int sys_acl_delete_def_file(const char *name)
4616 + /* AIX has no default ACL */
4620 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4622 + return(*permset & perm);
4625 +int sys_acl_free_text(char *text)
4630 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4632 + struct acl_entry_link *acl_entry_link;
4634 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4635 + SAFE_FREE(acl_entry_link->prevp->entryp);
4636 + SAFE_FREE(acl_entry_link->prevp);
4639 + SAFE_FREE(acl_entry_link->prevp->entryp);
4640 + SAFE_FREE(acl_entry_link->prevp);
4641 + SAFE_FREE(acl_entry_link->entryp);
4642 + SAFE_FREE(acl_entry_link);
4647 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4652 +#else /* No ACLs. */
4654 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4660 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4666 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4672 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4678 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4681 + return (SMB_ACL_T)NULL;
4684 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4687 + return (SMB_ACL_T)NULL;
4690 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4696 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4702 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4705 + return (permset & perm) ? 1 : 0;
4708 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4714 +int sys_acl_free_text(UNUSED(char *text))
4720 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4726 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4732 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4738 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4744 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4750 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4756 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4762 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4768 +int sys_acl_delete_def_file(UNUSED(const char *name))
4774 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4780 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4786 +#endif /* No ACLs. */
4788 +/************************************************************************
4789 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4791 +************************************************************************/
4793 +int no_acl_syscall_error(int err)
4795 +#if defined(ENOSYS)
4796 + if (err == ENOSYS) {
4800 +#if defined(ENOTSUP)
4801 + if (err == ENOTSUP) {
4807 --- old/lib/sysacls.h
4808 +++ new/lib/sysacls.h
4810 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4811 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4812 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4813 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4814 +#define slprintf snprintf
4816 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4817 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4818 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4819 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4820 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4821 +SMB_ACL_T sys_acl_get_fd(int fd);
4822 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4823 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4824 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4825 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4826 +SMB_ACL_T sys_acl_init(int count);
4827 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4828 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4829 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4830 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4831 +int sys_acl_valid(SMB_ACL_T theacl);
4832 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4833 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4834 +int sys_acl_delete_def_file(const char *name);
4835 +int sys_acl_free_text(char *text);
4836 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4837 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4840 @@ -58,7 +58,7 @@ BEGIN {
4844 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4845 +!/^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/ {
4851 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4853 int preserve_links = 0;
4854 int preserve_hard_links = 0;
4855 +int preserve_acls = 0;
4856 int preserve_perms = 0;
4857 int preserve_executability = 0;
4858 int preserve_devices = 0;
4859 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4860 char const *got_socketpair = "no ";
4861 char const *have_inplace = "no ";
4862 char const *hardlinks = "no ";
4863 + char const *acls = "no ";
4864 char const *links = "no ";
4865 char const *ipv6 = "no ";
4866 STRUCT_STAT *dumstat;
4867 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4871 +#ifdef SUPPORT_ACLS
4875 #ifdef SUPPORT_LINKS
4878 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4879 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4880 rprintf(f, "<http://rsync.samba.org/>\n");
4881 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4882 - "%shard links, %ssymlinks, batchfiles,\n",
4883 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4884 (int) (sizeof (OFF_T) * 8),
4885 - got_socketpair, hardlinks, links);
4886 + got_socketpair, hardlinks, acls, links);
4888 /* Note that this field may not have type ino_t. It depends
4889 * on the complicated interaction between largefile feature
4890 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4891 rprintf(F," -H, --hard-links preserve hard links\n");
4892 rprintf(F," -p, --perms preserve permissions\n");
4893 rprintf(F," -E, --executability preserve the file's executability\n");
4894 +#ifdef SUPPORT_ACLS
4895 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4897 rprintf(F," --chmod=CHMOD change destination permissions\n");
4898 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4899 rprintf(F," -g, --group preserve group\n");
4900 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4901 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4902 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4903 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4904 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4905 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4906 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4907 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4908 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4909 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4910 @@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
4915 +#ifdef SUPPORT_ACLS
4917 + preserve_perms = 1;
4920 + /* FIXME: this should probably be ignored with a
4921 + * warning and then countermeasures taken to
4922 + * restrict group and other access in the presence
4923 + * of any more restrictive ACLs, but this is safe
4925 + snprintf(err_buf,sizeof(err_buf),
4926 + "ACLs are not supported on this %s\n",
4927 + am_server ? "server" : "client");
4933 /* A large opt value means that set_refuse_options()
4934 * turned this option off. */
4935 @@ -1511,6 +1541,10 @@ void server_options(char **args,int *arg
4937 if (preserve_hard_links)
4939 +#ifdef SUPPORT_ACLS
4940 + if (preserve_acls)
4941 + argstr[x++] = 'A';
4948 @@ -46,6 +46,7 @@ extern int keep_partial;
4949 extern int checksum_seed;
4951 extern int delay_updates;
4952 +extern mode_t orig_umask;
4953 extern struct stats stats;
4954 extern char *log_format;
4955 extern char *tmpdir;
4956 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4957 int itemizing = am_daemon ? daemon_log_format_has_i
4958 : !am_server && log_format_has_i;
4959 int max_phase = protocol_version >= 29 ? 2 : 1;
4960 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4961 +#ifdef SUPPORT_ACLS
4962 + char *parent_dirname = "";
4967 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
4968 * mode based on the local permissions and some heuristics. */
4969 if (!preserve_perms) {
4970 int exists = fd1 != -1;
4971 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4972 +#ifdef SUPPORT_ACLS
4973 + char *dn = file->dirname ? file->dirname : ".";
4974 + if (parent_dirname != dn
4975 + && strcmp(parent_dirname, dn) != 0) {
4976 + dflt_perms = default_perms_for_dir(dn);
4977 + parent_dirname = dn;
4980 + file->mode = dest_mode(file->mode, st.st_mode,
4981 + dflt_perms, exists);
4984 /* We now check to see if we are writing file "inplace" */
4990 extern int daemon_log_format_has_i;
4991 +extern int preserve_acls;
4992 extern int preserve_perms;
4993 extern int preserve_executability;
4994 extern int preserve_times;
4995 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
4997 /* This is only called when we aren't preserving permissions. Figure out what
4998 * the permissions should be and return them merged back into the mode. */
4999 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
5000 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
5003 /* If the file already exists, we'll return the local permissions,
5004 * possibly tweaked by the --executability option. */
5005 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
5006 cur_mode |= (cur_mode & 0444) >> 2;
5009 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5010 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5011 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5012 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5013 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5014 @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
5018 +#ifdef SUPPORT_ACLS
5019 + /* It's OK to call set_acl() now, even for a dir, as the generator
5020 + * will enable owner-writability using chmod, if necessary.
5022 + * If set_acl changes permission bits in the process of setting
5023 + * an access ACL, it changes st->st_mode so we know whether we
5024 + * need to chmod. */
5025 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5030 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5031 - int ret = do_chmod(fname, file->mode);
5032 + mode_t mode = file->mode;
5033 + int ret = do_chmod(fname, mode);
5035 rsyserr(FERROR, errno,
5036 "failed to set permissions on %s",
5039 @@ -660,6 +660,20 @@ struct chmod_mode_struct;
5041 #define UNUSED(x) x __attribute__((__unused__))
5043 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5044 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5045 +#define SUPPORT_ACLS 1
5048 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5049 +#define ACLS_NEED_MASK 1
5052 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5053 +#include <sys/acl.h>
5055 +#include "smb_acls.h"
5059 /* We have replacement versions of these if they're missing. */
5062 @@ -321,6 +321,7 @@ to the detailed description below for a
5063 -H, --hard-links preserve hard links
5064 -p, --perms preserve permissions
5065 -E, --executability preserve executability
5066 + -A, --acls preserve ACLs (implies -p) [non-standard]
5067 --chmod=CHMOD change destination permissions
5068 -o, --owner preserve owner (super-user only)
5069 -g, --group preserve group
5070 @@ -742,7 +743,9 @@ quote(itemize(
5071 permissions, though the bf(--executability) option might change just
5072 the execute permission for the file.
5073 it() New files get their "normal" permission bits set to the source
5074 - file's permissions masked with the receiving end's umask setting, and
5075 + file's permissions masked with the receiving directory's default
5076 + permissions (either the receiving process's umask, or the permissions
5077 + specified via the destination directory's default ACL), and
5078 their special permission bits disabled except in the case where a new
5079 directory inherits a setgid bit from its parent directory.
5081 @@ -773,9 +776,11 @@ The preservation of the destination's se
5082 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5083 versions erroneously preserved the three special permission bits for
5084 newly-created files when bf(--perms) was off, while overriding the
5085 -destination's setgid bit setting on a newly-created directory. (Keep in
5086 -mind that it is the version of the receiving rsync that affects this
5088 +destination's setgid bit setting on a newly-created directory. Default ACL
5089 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5090 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5091 +(Keep in mind that it is the version of the receiving rsync that affects
5094 dit(bf(-E, --executability)) This option causes rsync to preserve the
5095 executability (or non-executability) of regular files when bf(--perms) is
5096 @@ -793,6 +798,15 @@ quote(itemize(
5098 If bf(--perms) is enabled, this option is ignored.
5100 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5101 +ACLs to be the same as the source ACLs. This nonstandard option only
5102 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5104 +Note also that an optimization of the ACL-sending protocol used by this
5105 +version makes it incompatible with sending files to an older ACL-enabled
5106 +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
5107 +doubling is not needed when pulling files from an older rsync.
5109 dit(bf(--chmod)) This option tells rsync to apply one or more
5110 comma-separated "chmod" strings to the permission of the files in the
5111 transfer. The resulting value is treated as though it was the permissions
5116 + Unix SMB/Netbios implementation.
5118 + Portable SMB ACL interface
5119 + Copyright (C) Jeremy Allison 2000
5121 + This program is free software; you can redistribute it and/or modify
5122 + it under the terms of the GNU General Public License as published by
5123 + the Free Software Foundation; either version 2 of the License, or
5124 + (at your option) any later version.
5126 + This program is distributed in the hope that it will be useful,
5127 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5128 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5129 + GNU General Public License for more details.
5131 + You should have received a copy of the GNU General Public License
5132 + along with this program; if not, write to the Free Software
5133 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5136 +#ifndef _SMB_ACLS_H
5137 +#define _SMB_ACLS_H
5139 +#if defined HAVE_POSIX_ACLS
5141 +/* This is an identity mapping (just remove the SMB_). */
5143 +#define SMB_ACL_TAG_T acl_tag_t
5144 +#define SMB_ACL_TYPE_T acl_type_t
5145 +#define SMB_ACL_PERMSET_T acl_permset_t
5146 +#define SMB_ACL_PERM_T acl_perm_t
5147 +#define SMB_ACL_READ ACL_READ
5148 +#define SMB_ACL_WRITE ACL_WRITE
5149 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5151 +/* Types of ACLs. */
5152 +#define SMB_ACL_USER ACL_USER
5153 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5154 +#define SMB_ACL_GROUP ACL_GROUP
5155 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5156 +#define SMB_ACL_OTHER ACL_OTHER
5157 +#define SMB_ACL_MASK ACL_MASK
5159 +#define SMB_ACL_T acl_t
5161 +#define SMB_ACL_ENTRY_T acl_entry_t
5163 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5164 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5166 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5167 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5169 +#elif defined HAVE_TRU64_ACLS
5171 +/* This is for DEC/Compaq Tru64 UNIX */
5173 +#define SMB_ACL_TAG_T acl_tag_t
5174 +#define SMB_ACL_TYPE_T acl_type_t
5175 +#define SMB_ACL_PERMSET_T acl_permset_t
5176 +#define SMB_ACL_PERM_T acl_perm_t
5177 +#define SMB_ACL_READ ACL_READ
5178 +#define SMB_ACL_WRITE ACL_WRITE
5179 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5181 +/* Types of ACLs. */
5182 +#define SMB_ACL_USER ACL_USER
5183 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5184 +#define SMB_ACL_GROUP ACL_GROUP
5185 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5186 +#define SMB_ACL_OTHER ACL_OTHER
5187 +#define SMB_ACL_MASK ACL_MASK
5189 +#define SMB_ACL_T acl_t
5191 +#define SMB_ACL_ENTRY_T acl_entry_t
5193 +#define SMB_ACL_FIRST_ENTRY 0
5194 +#define SMB_ACL_NEXT_ENTRY 1
5196 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5197 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5199 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5201 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5202 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5205 +/* SVR4.2 ES/MP ACLs */
5206 +typedef int SMB_ACL_TAG_T;
5207 +typedef int SMB_ACL_TYPE_T;
5208 +typedef ushort *SMB_ACL_PERMSET_T;
5209 +typedef ushort SMB_ACL_PERM_T;
5210 +#define SMB_ACL_READ 4
5211 +#define SMB_ACL_WRITE 2
5212 +#define SMB_ACL_EXECUTE 1
5214 +/* Types of ACLs. */
5215 +#define SMB_ACL_USER USER
5216 +#define SMB_ACL_USER_OBJ USER_OBJ
5217 +#define SMB_ACL_GROUP GROUP
5218 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5219 +#define SMB_ACL_OTHER OTHER_OBJ
5220 +#define SMB_ACL_MASK CLASS_OBJ
5222 +typedef struct SMB_ACL_T {
5226 + struct acl acl[1];
5229 +typedef struct acl *SMB_ACL_ENTRY_T;
5231 +#define SMB_ACL_FIRST_ENTRY 0
5232 +#define SMB_ACL_NEXT_ENTRY 1
5234 +#define SMB_ACL_TYPE_ACCESS 0
5235 +#define SMB_ACL_TYPE_DEFAULT 1
5238 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5241 +#elif defined HAVE_HPUX_ACLS
5244 + * Based on the Solaris & UnixWare code.
5248 +#include <sys/aclv.h>
5250 +/* SVR4.2 ES/MP ACLs */
5251 +typedef int SMB_ACL_TAG_T;
5252 +typedef int SMB_ACL_TYPE_T;
5253 +typedef ushort *SMB_ACL_PERMSET_T;
5254 +typedef ushort SMB_ACL_PERM_T;
5255 +#define SMB_ACL_READ 4
5256 +#define SMB_ACL_WRITE 2
5257 +#define SMB_ACL_EXECUTE 1
5259 +/* Types of ACLs. */
5260 +#define SMB_ACL_USER USER
5261 +#define SMB_ACL_USER_OBJ USER_OBJ
5262 +#define SMB_ACL_GROUP GROUP
5263 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5264 +#define SMB_ACL_OTHER OTHER_OBJ
5265 +#define SMB_ACL_MASK CLASS_OBJ
5267 +typedef struct SMB_ACL_T {
5271 + struct acl acl[1];
5274 +typedef struct acl *SMB_ACL_ENTRY_T;
5276 +#define SMB_ACL_FIRST_ENTRY 0
5277 +#define SMB_ACL_NEXT_ENTRY 1
5279 +#define SMB_ACL_TYPE_ACCESS 0
5280 +#define SMB_ACL_TYPE_DEFAULT 1
5282 +#elif defined HAVE_IRIX_ACLS
5284 +#define SMB_ACL_TAG_T acl_tag_t
5285 +#define SMB_ACL_TYPE_T acl_type_t
5286 +#define SMB_ACL_PERMSET_T acl_permset_t
5287 +#define SMB_ACL_PERM_T acl_perm_t
5288 +#define SMB_ACL_READ ACL_READ
5289 +#define SMB_ACL_WRITE ACL_WRITE
5290 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5292 +/* Types of ACLs. */
5293 +#define SMB_ACL_USER ACL_USER
5294 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5295 +#define SMB_ACL_GROUP ACL_GROUP
5296 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5297 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5298 +#define SMB_ACL_MASK ACL_MASK
5300 +typedef struct SMB_ACL_T {
5306 +#define SMB_ACL_ENTRY_T acl_entry_t
5308 +#define SMB_ACL_FIRST_ENTRY 0
5309 +#define SMB_ACL_NEXT_ENTRY 1
5311 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5312 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5314 +#elif defined HAVE_AIX_ACLS
5316 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5318 +#include "/usr/include/acl.h"
5320 +typedef uint *SMB_ACL_PERMSET_T;
5322 +struct acl_entry_link{
5323 + struct acl_entry_link *prevp;
5324 + struct new_acl_entry *entryp;
5325 + struct acl_entry_link *nextp;
5329 +struct new_acl_entry{
5330 + unsigned short ace_len;
5331 + unsigned short ace_type;
5332 + unsigned int ace_access;
5333 + struct ace_id ace_id[1];
5336 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5337 +#define SMB_ACL_T struct acl_entry_link*
5339 +#define SMB_ACL_TAG_T unsigned short
5340 +#define SMB_ACL_TYPE_T int
5341 +#define SMB_ACL_PERM_T uint
5342 +#define SMB_ACL_READ S_IRUSR
5343 +#define SMB_ACL_WRITE S_IWUSR
5344 +#define SMB_ACL_EXECUTE S_IXUSR
5346 +/* Types of ACLs. */
5347 +#define SMB_ACL_USER ACEID_USER
5348 +#define SMB_ACL_USER_OBJ 3
5349 +#define SMB_ACL_GROUP ACEID_GROUP
5350 +#define SMB_ACL_GROUP_OBJ 4
5351 +#define SMB_ACL_OTHER 5
5352 +#define SMB_ACL_MASK 6
5355 +#define SMB_ACL_FIRST_ENTRY 1
5356 +#define SMB_ACL_NEXT_ENTRY 2
5358 +#define SMB_ACL_TYPE_ACCESS 0
5359 +#define SMB_ACL_TYPE_DEFAULT 1
5361 +#else /* No ACLs. */
5363 +/* No ACLS - fake it. */
5364 +#define SMB_ACL_TAG_T int
5365 +#define SMB_ACL_TYPE_T int
5366 +#define SMB_ACL_PERMSET_T mode_t
5367 +#define SMB_ACL_PERM_T mode_t
5368 +#define SMB_ACL_READ S_IRUSR
5369 +#define SMB_ACL_WRITE S_IWUSR
5370 +#define SMB_ACL_EXECUTE S_IXUSR
5372 +/* Types of ACLs. */
5373 +#define SMB_ACL_USER 0
5374 +#define SMB_ACL_USER_OBJ 1
5375 +#define SMB_ACL_GROUP 2
5376 +#define SMB_ACL_GROUP_OBJ 3
5377 +#define SMB_ACL_OTHER 4
5378 +#define SMB_ACL_MASK 5
5380 +typedef struct SMB_ACL_T {
5384 +typedef struct SMB_ACL_ENTRY_T {
5386 +} *SMB_ACL_ENTRY_T;
5388 +#define SMB_ACL_FIRST_ENTRY 0
5389 +#define SMB_ACL_NEXT_ENTRY 1
5391 +#define SMB_ACL_TYPE_ACCESS 0
5392 +#define SMB_ACL_TYPE_DEFAULT 1
5394 +#endif /* No ACLs. */
5395 +#endif /* _SMB_ACLS_H */
5396 --- old/testsuite/default-acls.test
5397 +++ new/testsuite/default-acls.test
5401 +# This program is distributable under the terms of the GNU GPL see
5404 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5406 +. $srcdir/testsuite/rsync.fns
5408 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5409 +case "$setfacl_nodef" in
5410 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5411 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5413 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5415 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5417 + todir="$scratchdir/$1"
5419 + $setfacl_nodef "$todir"
5421 + case "$setfacl_nodef" in
5422 + *-k*) opts="-dm $2" ;;
5423 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5425 + setfacl $opts "$todir"
5427 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5428 + # even though the directory itself is outside the transfer
5429 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5430 + check_perms "$todir/to" $4 "Target $1"
5431 + check_perms "$todir/to/dir" $4 "Target $1"
5432 + check_perms "$todir/to/file" $3 "Target $1"
5433 + check_perms "$todir/to/program" $4 "Target $1"
5434 + # Make sure get_local_name doesn't mess us up when transferring only one file
5435 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5436 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5437 + # Make sure we obey default ACLs when not transferring a regular file
5438 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5439 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5442 +mkdir "$scratchdir/dir"
5443 +echo "File!" >"$scratchdir/file"
5444 +echo "#!/bin/sh" >"$scratchdir/program"
5445 +chmod 777 "$scratchdir/dir"
5446 +chmod 666 "$scratchdir/file"
5447 +chmod 777 "$scratchdir/program"
5449 +# Test some target directories
5451 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5452 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5453 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5454 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5455 +testit noda1 '' rw------- rwx------
5457 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5459 +testit noda3 '' rw-r--r-- rwxr-xr-x
5467 extern int preserve_uid;
5468 extern int preserve_gid;
5469 +extern int preserve_acls;
5470 extern int numeric_ids;
5473 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5477 - if (preserve_uid) {
5478 + if (preserve_uid || preserve_acls) {
5480 /* we send sequences of uid/byte-length/name */
5481 for (list = uidlist; list; list = list->next) {
5482 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5486 - if (preserve_gid) {
5487 + if (preserve_gid || preserve_acls) {
5489 for (list = gidlist; list; list = list->next) {
5491 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5495 - if (preserve_uid && !numeric_ids) {
5496 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5497 /* read the uid list */
5498 while ((id = read_int(f)) != 0) {
5499 int len = read_byte(f);
5500 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5504 - if (preserve_gid && !numeric_ids) {
5505 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5506 /* read the gid list */
5507 while ((id = read_int(f)) != 0) {
5508 int len = read_byte(f);
5509 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5513 +#ifdef SUPPORT_ACLS
5514 + if (preserve_acls && !numeric_ids) {
5516 + while ((id = next_acl_uid(flist)) != NULL)
5517 + *id = match_uid(*id);
5518 + while ((id = next_acl_gid(flist)) != NULL)
5519 + *id = match_gid(*id);
5523 /* Now convert all the uids/gids from sender values to our values. */
5524 if (am_root && preserve_uid && !numeric_ids) {
5525 for (i = 0; i < flist->count; i++)