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) {
100 + return racl->users.count + racl->groups.count
101 + + (racl->user_obj != NO_ENTRY)
102 + + (racl->group_obj != NO_ENTRY)
103 + + (racl->mask != NO_ENTRY)
104 + + (racl->other != NO_ENTRY);
107 +static int rsync_acl_get_perms(const rsync_acl *racl) {
108 + /* Note that (NO_ENTRY & 7) is 0. */
109 + return ((racl->user_obj & 7) << 6)
110 + + (((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
111 + + (racl->other & 7);
114 +static void rsync_acl_strip_perms(rsync_acl *racl) {
115 + racl->user_obj = NO_ENTRY;
116 + if (racl->mask == NO_ENTRY)
117 + racl->group_obj = NO_ENTRY;
119 + racl->mask = NO_ENTRY;
120 + racl->other = NO_ENTRY;
123 +static void expand_ida_list(ida_list *idal)
125 + /* First time through, 0 <= 0, so list is expanded. */
126 + if (idal->malloced <= idal->count) {
127 + id_access *new_ptr;
128 + size_t new_size = idal->malloced + 10;
129 + new_ptr = realloc_array(idal->idas, id_access, new_size);
130 + if (verbose >= 4) {
131 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
132 + (double) new_size * sizeof idal->idas[0],
133 + idal->idas ? "" : " not");
136 + idal->idas = new_ptr;
137 + idal->malloced = new_size;
140 + out_of_memory("expand_ida_list");
144 +static void ida_list_free(ida_list *idal)
149 + idal->malloced = 0;
152 +static void rsync_acl_free(rsync_acl *racl)
154 + ida_list_free(&racl->users);
155 + ida_list_free(&racl->groups);
158 +static int id_access_sorter(const void *r1, const void *r2)
160 + id_access *ida1 = (id_access *)r1;
161 + id_access *ida2 = (id_access *)r2;
162 + id_t rid1 = ida1->id, rid2 = ida2->id;
163 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
166 +static void sort_ida_list(ida_list *idal)
170 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
171 + &id_access_sorter);
174 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
176 + SMB_ACL_ENTRY_T entry;
177 + const char *errfun;
180 + *racl = rsync_acl_initializer;
181 + errfun = "sys_acl_get_entry";
182 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
184 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
185 + SMB_ACL_TAG_T tag_type;
186 + SMB_ACL_PERMSET_T permset;
191 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
192 + errfun = "sys_acl_get_tag_type";
195 + if ((rc = sys_acl_get_permset(entry, &permset))) {
196 + errfun = "sys_acl_get_tag_type";
199 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
200 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
201 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
202 + /* continue == done with entry; break == store in given idal */
203 + switch (tag_type) {
204 + case SMB_ACL_USER_OBJ:
205 + if (racl->user_obj == NO_ENTRY)
206 + racl->user_obj = access;
208 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
211 + idal = &racl->users;
213 + case SMB_ACL_GROUP_OBJ:
214 + if (racl->group_obj == NO_ENTRY)
215 + racl->group_obj = access;
217 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
219 + case SMB_ACL_GROUP:
220 + idal = &racl->groups;
223 + if (racl->mask == NO_ENTRY)
224 + racl->mask = access;
226 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
228 + case SMB_ACL_OTHER:
229 + if (racl->other == NO_ENTRY)
230 + racl->other = access;
232 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
235 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
238 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
239 + errfun = "sys_acl_get_tag_type";
243 + expand_ida_list(idal);
244 + ida = &idal->idas[idal->count++];
245 + ida->id = *((id_t *)qualifier);
246 + ida->access = access;
247 + sys_acl_free_qualifier(qualifier, tag_type);
250 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
251 + errfun, strerror(errno));
252 + rsync_acl_free(racl);
256 + sort_ida_list(&racl->users);
257 + sort_ida_list(&racl->groups);
262 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
264 + id_access *ida1, *ida2;
265 + size_t count = ial1->count;
266 + if (count != ial2->count)
270 + for (; count--; ida1++, ida2++) {
271 + if (ida1->access != ida2->access || ida1->id != ida2->id)
277 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
279 + return (racl1->user_obj == racl2->user_obj
280 + && racl1->group_obj == racl2->group_obj
281 + && racl1->mask == racl2->mask
282 + && racl1->other == racl2->other
283 + && ida_lists_equal(&racl1->users, &racl2->users)
284 + && ida_lists_equal(&racl1->groups, &racl2->groups));
287 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1, const rsync_acl *racl2)
289 + /* We ignore any differences that chmod() can take care of. */
290 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
292 + if (racl1->mask != NO_ENTRY && racl1->group_obj != racl2->group_obj)
294 + return ida_lists_equal(&racl1->users, &racl2->users)
295 + && ida_lists_equal(&racl1->groups, &racl2->groups);
304 +static rsync_acl_list _rsync_acl_lists[] = {
305 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
306 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
309 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
311 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
312 + : &_rsync_acl_lists[1];
315 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
317 + /* First time through, 0 <= 0, so list is expanded. */
318 + if (racl_list->malloced <= racl_list->count) {
319 + rsync_acl *new_ptr;
321 + if (racl_list->malloced < 1000)
322 + new_size = racl_list->malloced + 1000;
324 + new_size = racl_list->malloced * 2;
325 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
326 + if (verbose >= 3) {
327 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
328 + (double) new_size * sizeof racl_list->racls[0],
329 + racl_list->racls ? "" : " not");
332 + racl_list->racls = new_ptr;
333 + racl_list->malloced = new_size;
335 + if (!racl_list->racls)
336 + out_of_memory("expand_rsync_acl_list");
340 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
341 + const rsync_acl_list *racl_list,
342 + const rsync_acl *racl)
344 + static int access_match = -1, default_match = -1;
345 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
346 + &access_match : &default_match;
347 + size_t count = racl_list->count;
348 + /* If this is the first time through or we didn't match the last
349 + * time, then start at the end of the list, which should be the
350 + * best place to start hunting. */
352 + *match = racl_list->count - 1;
354 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
357 + *match = racl_list->count - 1;
363 +/* The general strategy with the tag_type <-> character mapping is that
364 + * lowercase implies that no qualifier follows, where uppercase does.
365 + * A similar idiom for the acl type (access or default) itself, but
366 + * lowercase in this instance means there's no ACL following, so the
367 + * ACL is a repeat, so the receiver should reuse the last of the same
369 +static void send_ida_list(int f, const ida_list *idal, char tag_char)
372 + size_t count = idal->count;
373 + for (ida = idal->idas; count--; ida++) {
374 + write_byte(f, tag_char);
375 + write_byte(f, ida->access);
376 + write_int(f, ida->id);
377 + /* FIXME: sorta wasteful: we should maybe buffer as
378 + * many ids as max(ACL_USER + ACL_GROUP) objects to
379 + * keep from making so many calls. */
380 + if (tag_char == 'U')
387 +static void send_rsync_acl(int f, const rsync_acl *racl)
389 + size_t count = rsync_acl_count_entries(racl);
390 + write_int(f, count);
391 + if (racl->user_obj != NO_ENTRY) {
392 + write_byte(f, 'u');
393 + write_byte(f, racl->user_obj);
395 + send_ida_list(f, &racl->users, 'U');
396 + if (racl->group_obj != NO_ENTRY) {
397 + write_byte(f, 'g');
398 + write_byte(f, racl->group_obj);
400 + send_ida_list(f, &racl->groups, 'G');
401 + if (racl->mask != NO_ENTRY) {
402 + write_byte(f, 'm');
403 + write_byte(f, racl->mask);
405 + if (racl->other != NO_ENTRY) {
406 + write_byte(f, 'o');
407 + write_byte(f, racl->other);
411 +static rsync_acl _curr_rsync_acls[2];
413 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
415 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
416 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
417 + "unknown SMB_ACL_TYPE_T";
420 +/* Generate the ACL(s) for this flist entry;
421 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
422 +int make_acl(const struct file_struct *file, const char *fname)
424 + SMB_ACL_TYPE_T type;
425 + rsync_acl *curr_racl;
427 + if (S_ISLNK(file->mode))
430 + curr_racl = &_curr_rsync_acls[0];
431 + type = SMB_ACL_TYPE_ACCESS;
435 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
436 + ok = unpack_smb_acl(curr_racl, sacl);
437 + sys_acl_free_acl(sacl);
440 + /* Strip access ACLs of permission-bit entries. */
441 + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
442 + rsync_acl_strip_perms(curr_racl);
443 + } else if (errno == ENOTSUP) {
444 + /* ACLs are not supported. Leave list empty. */
445 + *curr_racl = rsync_acl_initializer;
447 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
448 + fname, str_acl_type(type), strerror(errno));
452 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
457 +/* Send the make_acl()-generated ACLs for this flist entry,
458 + * or clean up after an flist entry that's not being sent (f == -1). */
459 +void send_acl(const struct file_struct *file, int f)
461 + SMB_ACL_TYPE_T type;
462 + rsync_acl *curr_racl;
464 + if (S_ISLNK(file->mode))
467 + curr_racl = &_curr_rsync_acls[0];
468 + type = SMB_ACL_TYPE_ACCESS;
471 + rsync_acl_list *racl_list = rsync_acl_lists(type);
473 + rsync_acl_free(curr_racl);
476 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
478 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
479 + write_int(f, index);
480 + rsync_acl_free(curr_racl);
482 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
483 + send_rsync_acl(f, curr_racl);
484 + expand_rsync_acl_list(racl_list);
485 + racl_list->racls[racl_list->count++] = *curr_racl;
488 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
491 +/* The below stuff is only used by the receiver: */
493 +/* structure to hold index to rsync_acl_list member corresponding to
494 + * flist->files[i] */
497 + const struct file_struct *file;
504 + file_acl_index *fileaclidxs;
505 +} file_acl_index_list;
507 +static file_acl_index_list _file_acl_index_lists[] = {
508 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
509 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
512 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
514 + return type == SMB_ACL_TYPE_ACCESS ?
515 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
518 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
520 + /* First time through, 0 <= 0, so list is expanded. */
521 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
522 + file_acl_index *new_ptr;
524 + if (fileaclidx_list->malloced < 1000)
525 + new_size = fileaclidx_list->malloced + 1000;
527 + new_size = fileaclidx_list->malloced * 2;
528 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
529 + if (verbose >= 3) {
530 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
531 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
532 + fileaclidx_list->fileaclidxs ? "" : " not");
535 + fileaclidx_list->fileaclidxs = new_ptr;
536 + fileaclidx_list->malloced = new_size;
538 + if (!fileaclidx_list->fileaclidxs)
539 + out_of_memory("expand_file_acl_index_list");
543 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
551 +static smb_acl_list _smb_acl_lists[] = {
552 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
553 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
556 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
558 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
559 + &_smb_acl_lists[1];
562 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
564 + /* First time through, 0 <= 0, so list is expanded. */
565 + if (sacl_list->malloced <= sacl_list->count) {
566 + SMB_ACL_T *new_ptr;
568 + if (sacl_list->malloced < 1000)
569 + new_size = sacl_list->malloced + 1000;
571 + new_size = sacl_list->malloced * 2;
572 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
573 + if (verbose >= 3) {
574 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
575 + (double) new_size * sizeof sacl_list->sacls[0],
576 + sacl_list->sacls ? "" : " not");
579 + sacl_list->sacls = new_ptr;
580 + sacl_list->malloced = new_size;
582 + if (!sacl_list->sacls)
583 + out_of_memory("expand_smb_acl_list");
587 +#define CALL_OR_ERROR(func,args,str) \
595 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
596 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
598 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
600 + const char *errfun = NULL;
601 + SMB_ACL_PERMSET_T permset;
603 + COE( sys_acl_get_permset,(entry, &permset) );
604 + COE( sys_acl_clear_perms,(permset) );
606 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
608 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
610 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
611 + COE( sys_acl_set_permset,(entry, permset) );
616 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
621 +/* build an SMB_ACL_T corresponding to an rsync_acl */
622 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
626 + const char *errfun = NULL;
627 + SMB_ACL_ENTRY_T entry;
629 + if (!(*smb_acl = sys_acl_init(rsync_acl_count_entries(racl)))) {
630 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
635 + COE( sys_acl_create_entry,(smb_acl, &entry) );
636 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
637 + COE2( store_access_in_entry,(racl->user_obj, entry) );
639 + for (ida = racl->users.idas, count = racl->users.count;
641 + COE( sys_acl_create_entry,(smb_acl, &entry) );
642 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
643 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
644 + COE2( store_access_in_entry,(ida->access, entry) );
647 + COE( sys_acl_create_entry,(smb_acl, &entry) );
648 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
649 + COE2( store_access_in_entry,(racl->group_obj, entry) );
651 + for (ida = racl->groups.idas, count = racl->groups.count;
653 + COE( sys_acl_create_entry,(smb_acl, &entry) );
654 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
655 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
656 + COE2( store_access_in_entry,(ida->access, entry) );
658 + if (racl->mask != NO_ENTRY) {
659 + COE( sys_acl_create_entry,(smb_acl, &entry) );
660 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
661 + COE2( store_access_in_entry,(racl->mask, entry) );
664 + COE( sys_acl_create_entry,(smb_acl, &entry) );
665 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
666 + COE2( store_access_in_entry,(racl->other, entry) );
669 + if (sys_acl_valid(*smb_acl) < 0)
670 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
677 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
680 + sys_acl_free_acl(*smb_acl);
684 +static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode)
686 + SMB_ACL_ENTRY_T entry;
687 + int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ;
688 + const char *errfun;
691 + if (S_ISDIR(mode)) {
692 + /* If the sticky bit is going on, it's not safe to allow all
693 + * the new ACLs to go into effect before it gets set. */
694 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
695 + if (mode & S_ISVTX)
698 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
701 + /* If setuid or setgid is going off, it's not safe to allow all
702 + * the new ACLs to go into effect before they get cleared. */
703 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
704 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
709 + errfun = "sys_acl_get_entry";
710 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
712 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
713 + SMB_ACL_TAG_T tag_type;
714 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
715 + errfun = "sys_acl_get_tag_type";
718 + if (tag_type == SMB_ACL_USER_OBJ)
719 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
720 + else if (tag_type == group_id)
721 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
722 + else if (tag_type == SMB_ACL_OTHER)
723 + COE2( store_access_in_entry,(mode & 7, entry) );
728 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
729 + errfun, strerror(errno));
734 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
735 + /* Ensure that chmod() will be called to restore any lost setid bits. */
736 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
737 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
738 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
741 + /* Return the mode of the file on disk, as we will set them. */
742 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
745 +static void receive_rsync_acl(rsync_acl *racl, int f)
747 + uchar computed_mask_bits = 0;
748 + ida_list *idal = NULL;
752 + *racl = rsync_acl_initializer;
754 + if (!(count = read_int(f)))
758 + char tag = read_byte(f);
759 + uchar access = read_byte(f);
760 + if (access & ~ (4 | 2 | 1)) {
761 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
763 + exit_cleanup(RERR_STREAMIO);
767 + if (racl->user_obj != NO_ENTRY) {
768 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
769 + exit_cleanup(RERR_STREAMIO);
771 + racl->user_obj = access;
774 + idal = &racl->users;
777 + if (racl->group_obj != NO_ENTRY) {
778 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
779 + exit_cleanup(RERR_STREAMIO);
781 + racl->group_obj = access;
784 + idal = &racl->groups;
787 + if (racl->mask != NO_ENTRY) {
788 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
789 + exit_cleanup(RERR_STREAMIO);
791 + racl->mask = access;
794 + if (racl->other != NO_ENTRY) {
795 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
796 + exit_cleanup(RERR_STREAMIO);
798 + racl->other = access;
801 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
803 + exit_cleanup(RERR_STREAMIO);
805 + expand_ida_list(idal);
806 + ida = &idal->idas[idal->count++];
807 + ida->access = access;
808 + ida->id = read_int(f);
809 + computed_mask_bits |= access;
812 + /* Ensure that these are never unset. */
813 + if (racl->user_obj == NO_ENTRY)
814 + racl->user_obj = 7;
815 + if (racl->group_obj == NO_ENTRY)
816 + racl->group_obj = 0;
817 + if (racl->other == NO_ENTRY)
819 +#ifndef ACLS_NEED_MASK
820 + if (!racl->users.count && !racl->groups.count) {
821 + /* If we, a system without ACLS_NEED_MASK, received a
822 + * superfluous mask, throw it away. */
823 + if (racl->mask != NO_ENTRY) {
824 + /* mask off group perms with it first */
825 + racl->group_obj &= racl->mask;
826 + racl->mask = NO_ENTRY;
830 + if (racl->mask == NO_ENTRY)
831 + racl->mask = computed_mask_bits | racl->group_obj;
834 +/* receive and build the rsync_acl_lists */
835 +void receive_acl(struct file_struct *file, int f)
837 + SMB_ACL_TYPE_T type;
840 + if (S_ISLNK(file->mode))
843 + fname = f_name(file, NULL);
844 + type = SMB_ACL_TYPE_ACCESS;
846 + file_acl_index_list *fileaclidx_list =
847 + file_acl_index_lists(type);
849 + expand_file_acl_index_list(fileaclidx_list);
851 + tag = read_byte(f);
852 + if (tag == 'A' || tag == 'a') {
853 + if (type != SMB_ACL_TYPE_ACCESS) {
854 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
856 + exit_cleanup(RERR_STREAMIO);
858 + } else if (tag == 'D' || tag == 'd') {
859 + if (type == SMB_ACL_TYPE_ACCESS) {
860 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
862 + exit_cleanup(RERR_STREAMIO);
865 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
867 + exit_cleanup(RERR_STREAMIO);
869 + if (tag == 'A' || tag == 'D') {
871 + rsync_acl_list *racl_list = rsync_acl_lists(type);
872 + smb_acl_list *sacl_list = smb_acl_lists(type);
873 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
874 + aclidx = racl_list->count;
875 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
877 + receive_rsync_acl(&racl, f);
878 + expand_rsync_acl_list(racl_list);
879 + racl_list->racls[racl_list->count++] = racl;
880 + expand_smb_acl_list(sacl_list);
881 + sacl_list->sacls[sacl_list->count++] = NULL;
883 + int index = read_int(f);
884 + rsync_acl_list *racl_list = rsync_acl_lists(type);
885 + if ((size_t) index >= racl_list->count) {
886 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
888 + str_acl_type(type),
890 + exit_cleanup(RERR_STREAMIO);
892 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
894 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
897 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
900 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
902 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
903 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
904 + return fileaclidx1->file == fileaclidx2->file ? 0 :
905 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
908 +void sort_file_acl_index_lists()
910 + SMB_ACL_TYPE_T type;
912 + type = SMB_ACL_TYPE_ACCESS;
914 + file_acl_index_list *fileaclidx_list =
915 + file_acl_index_lists(type);
916 + if (!fileaclidx_list->count)
918 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
919 + sizeof fileaclidx_list->fileaclidxs[0],
920 + &file_acl_index_list_sorter);
921 + } while (BUMP_TYPE(type));
924 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
925 + const struct file_struct *file) {
926 + int low = 0, high = fileaclidx_list->count;
927 + const struct file_struct *file_mid;
931 + int mid = (high + low) / 2;
932 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
933 + if (file_mid == file)
934 + return fileaclidx_list->fileaclidxs[mid].aclidx;
935 + if (file_mid > file)
939 + } while (low < high);
941 + file_mid = fileaclidx_list->fileaclidxs[low].file;
942 + if (file_mid == file)
943 + return fileaclidx_list->fileaclidxs[low].aclidx;
946 + "find_file_acl_index: can't find entry for file in list\n");
947 + exit_cleanup(RERR_STREAMIO);
951 +/* for duplicating ACLs on backups when using backup_dir */
952 +int dup_acl(const char *orig, const char *bak, mode_t mode)
954 + SMB_ACL_TYPE_T type;
957 + type = SMB_ACL_TYPE_ACCESS;
959 + SMB_ACL_T sacl_orig, sacl_bak;
960 + rsync_acl racl_orig, racl_bak;
961 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
962 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
963 + orig, str_acl_type(type), strerror(errno));
967 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
968 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
969 + bak, str_acl_type(type), strerror(errno));
971 + /* try to forge on through */
973 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
975 + goto out_with_sacls;
978 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
980 + goto out_with_one_racl;
982 + if (rsync_acls_equal(&racl_orig, &racl_bak))
985 + ; /* presume they're unequal */
987 + if (type == SMB_ACL_TYPE_DEFAULT
988 + && rsync_acl_count_entries(&racl_orig) == 0) {
989 + if (sys_acl_delete_def_file(bak) < 0) {
990 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
991 + bak, strerror(errno));
994 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
995 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
996 + bak, str_acl_type(type), strerror(errno));
1001 + rsync_acl_free(&racl_bak);
1002 + out_with_one_racl:
1003 + rsync_acl_free(&racl_orig);
1006 + sys_acl_free_acl(sacl_bak);
1007 + /* out_with_one_sacl: */
1009 + sys_acl_free_acl(sacl_orig);
1010 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1015 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1016 + * for keep_backup(). */
1017 +static const struct file_struct *backup_orig_file = NULL;
1018 +static const char null_string[] = "";
1019 +static const char *backup_orig_fname = null_string;
1020 +static const char *backup_dest_fname = null_string;
1021 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1023 +void push_keep_backup_acl(const struct file_struct *file,
1024 + const char *orig, const char *dest)
1026 + SMB_ACL_TYPE_T type;
1029 + backup_orig_file = file;
1030 + backup_orig_fname = orig;
1031 + backup_dest_fname = dest;
1033 + sacl = &_backup_sacl[0];
1034 + type = SMB_ACL_TYPE_ACCESS;
1036 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1040 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1042 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1043 + orig, str_acl_type(type),
1046 + } while (BUMP_TYPE(type));
1049 +static int set_keep_backup_acl()
1051 + SMB_ACL_TYPE_T type;
1055 + sacl = &_backup_sacl[0];
1056 + type = SMB_ACL_TYPE_ACCESS;
1059 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1061 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1062 + backup_dest_fname,
1063 + str_acl_type(type),
1067 + } while (BUMP_TYPE(type));
1072 +void cleanup_keep_backup_acl()
1074 + SMB_ACL_TYPE_T type;
1077 + backup_orig_file = NULL;
1078 + backup_orig_fname = null_string;
1079 + backup_dest_fname = null_string;
1081 + sacl = &_backup_sacl[0];
1082 + type = SMB_ACL_TYPE_ACCESS;
1085 + sys_acl_free_acl(*sacl);
1088 + } while (BUMP_TYPE(type));
1091 +/* set ACL on rsync-ed or keep_backup-ed file
1093 + * This sets extended access ACL entries and default ACLs. If convenient,
1094 + * it sets permission bits along with the access ACLs and signals having
1095 + * done so by modifying mode_p, which should point into the stat buffer.
1097 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1098 + * Pass NULL for mode_p to get the return code without changing anything. */
1099 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1101 + int unchanged = 1;
1102 + SMB_ACL_TYPE_T type;
1104 + if (S_ISLNK(file->mode))
1107 + if (file == backup_orig_file) {
1108 + if (!strcmp(fname, backup_dest_fname))
1109 + return set_keep_backup_acl();
1111 + type = SMB_ACL_TYPE_ACCESS;
1114 + SMB_ACL_T sacl_orig, *sacl_new;
1115 + rsync_acl racl_orig, *racl_new;
1116 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1118 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1119 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1120 + sacl_orig = sys_acl_get_file(fname, type);
1122 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1123 + fname, str_acl_type(type), strerror(errno));
1127 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1128 + sys_acl_free_acl(sacl_orig);
1133 + if (type == SMB_ACL_TYPE_ACCESS)
1134 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new);
1136 + ok = rsync_acls_equal(&racl_orig, racl_new);
1137 + rsync_acl_free(&racl_orig);
1140 + if (!dry_run && mode_p) {
1141 + if (type == SMB_ACL_TYPE_DEFAULT
1142 + && rsync_acl_count_entries(racl_new) == 0) {
1143 + if (sys_acl_delete_def_file(fname) < 0) {
1144 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1145 + fname, strerror(errno));
1150 + mode_t cur_mode = *mode_p;
1152 + && !pack_smb_acl(sacl_new, racl_new)) {
1156 + if (type == SMB_ACL_TYPE_ACCESS) {
1157 + cur_mode = change_sacl_perms(*sacl_new, racl_new->mask,
1158 + cur_mode, file->mode);
1159 + if (cur_mode == ~0u)
1162 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1163 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1164 + fname, str_acl_type(type),
1169 + if (type == SMB_ACL_TYPE_ACCESS)
1170 + *mode_p = cur_mode;
1173 + if (unchanged == 1)
1175 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1180 +/* Enumeration functions for uid mapping: */
1182 +/* Context -- one and only one. Should be cycled through once on uid
1183 + * mapping and once on gid mapping. */
1184 +static rsync_acl_list *_enum_racl_lists[] = {
1185 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1188 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1189 +static size_t enum_racl_index = 0;
1190 +static size_t enum_ida_index = 0;
1192 +/* This returns the next tag_type id from the given acl for the next entry,
1193 + * or it returns 0 if there are no more tag_type ids in the acl. */
1194 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1196 + const ida_list *idal = (tag_type == SMB_ACL_USER ?
1197 + &racl->users : &racl->groups);
1198 + if (enum_ida_index < idal->count) {
1199 + id_access *ida = &idal->idas[enum_ida_index++];
1202 + enum_ida_index = 0;
1206 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1208 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1209 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1210 + id_t *id = next_ace_id(tag_type, racl);
1214 + enum_racl_index = 0;
1218 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1220 + for (; *enum_racl_list; enum_racl_list++) {
1221 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1225 + enum_racl_list = &_enum_racl_lists[0];
1229 +id_t *next_acl_uid()
1231 + return next_acl_list_id(SMB_ACL_USER);
1234 +id_t *next_acl_gid()
1236 + return next_acl_list_id(SMB_ACL_GROUP);
1239 +int default_perms_for_dir(const char *dir)
1248 + perms = ACCESSPERMS & ~orig_umask;
1249 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1250 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1251 + if (sacl == NULL) {
1252 + /* Couldn't get an ACL. Darn. */
1255 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1259 + /* We're doing a dry run, so the containing directory
1260 + * wasn't actually created. Don't worry about it. */
1263 + /* Otherwise fall through. */
1265 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1266 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1272 + ok = unpack_smb_acl(&racl, sacl);
1273 + sys_acl_free_acl(sacl);
1275 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1279 + /* Apply the permission-bit entries of the default ACL, if any. */
1280 + if (rsync_acl_count_entries(&racl) > 0) {
1281 + perms = rsync_acl_get_perms(&racl);
1283 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1286 + rsync_acl_free(&racl);
1290 +#endif /* SUPPORT_ACLS */
1293 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1294 extern char *backup_dir;
1297 +extern int preserve_acls;
1298 extern int preserve_devices;
1299 extern int preserve_specials;
1300 extern int preserve_links;
1301 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1303 do_lchown(fullpath, st.st_uid, st.st_gid);
1304 do_chmod(fullpath, st.st_mode);
1305 +#ifdef SUPPORT_ACLS
1306 + if (preserve_acls)
1307 + dup_acl(end, fullpath, st.st_mode);
1312 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1313 if (!(buf = get_backup_name(fname)))
1316 +#ifdef SUPPORT_ACLS
1317 + if (preserve_acls)
1318 + push_keep_backup_acl(file, fname, buf);
1321 /* Check to see if this is a device file, or link */
1322 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1323 || (preserve_specials && IS_SPECIAL(file->mode))) {
1324 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1327 set_file_attrs(buf, file, NULL, 0);
1328 +#ifdef SUPPORT_ACLS
1329 + if (preserve_acls)
1330 + cleanup_keep_backup_acl();
1335 --- old/configure.in
1336 +++ new/configure.in
1337 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1338 AC_CHECK_LIB(resolv, strcasecmp)
1341 +AC_CHECK_FUNCS(aclsort)
1342 +if test x"$ac_cv_func_aclsort" = x"no"; then
1343 + AC_CHECK_LIB(sec, aclsort)
1346 dnl At the moment we don't test for a broken memcmp(), because all we
1347 dnl need to do is test for equality, not comparison, and it seems that
1348 dnl every platform has a memcmp that can do at least that.
1349 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1350 AC_SUBST(CC_SHOBJ_FLAG)
1351 AC_SUBST(BUILD_POPT)
1353 +AC_CHECK_HEADERS(sys/acl.h)
1354 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1355 +#################################################
1356 +# check for ACL support
1358 +AC_MSG_CHECKING(whether to support ACLs)
1359 +AC_ARG_ENABLE(acl-support,
1360 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1361 +[ case "$enableval" in
1364 + case "$host_os" in
1366 + AC_MSG_RESULT(Using UnixWare ACLs)
1367 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1369 + *solaris*|*cygwin*)
1370 + AC_MSG_RESULT(Using solaris ACLs)
1371 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1374 + AC_MSG_RESULT(Using HPUX ACLs)
1375 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1378 + AC_MSG_RESULT(Using IRIX ACLs)
1379 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1382 + AC_MSG_RESULT(Using AIX ACLs)
1383 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1386 + AC_MSG_RESULT(Using Tru64 ACLs)
1387 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1388 + LIBS="$LIBS -lpacl"
1391 + AC_MSG_RESULT(ACLs requested -- running tests)
1392 + AC_CHECK_LIB(acl,acl_get_file)
1393 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1394 + AC_TRY_LINK([#include <sys/types.h>
1395 +#include <sys/acl.h>],
1396 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1397 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1398 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1399 + AC_MSG_RESULT(Using posix ACLs)
1400 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1401 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1402 + AC_TRY_LINK([#include <sys/types.h>
1403 +#include <sys/acl.h>],
1404 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1405 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1406 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1407 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1410 + AC_MSG_ERROR(Failed to find ACL support)
1417 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1420 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1424 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1429 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1430 extern int one_file_system;
1431 extern int copy_dirlinks;
1432 extern int keep_dirlinks;
1433 +extern int preserve_acls;
1434 extern int preserve_links;
1435 extern int preserve_hard_links;
1436 extern int preserve_devices;
1437 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1438 if (chmod_modes && !S_ISLNK(file->mode))
1439 file->mode = tweak_mode(file->mode, chmod_modes);
1441 +#ifdef SUPPORT_ACLS
1442 + if (preserve_acls && make_acl(file, fname) < 0)
1446 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1448 flist_expand(flist);
1449 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1450 if (file->basename[0]) {
1451 flist->files[flist->count++] = file;
1452 send_file_entry(file, f);
1453 +#ifdef SUPPORT_ACLS
1454 + if (preserve_acls)
1455 + send_acl(file, f);
1458 +#ifdef SUPPORT_ACLS
1459 + /* Cleanup unsent ACL(s). */
1460 + if (preserve_acls)
1461 + send_acl(file, -1);
1466 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1467 flags |= read_byte(f) << 8;
1468 file = receive_file_entry(flist, flags, f);
1470 +#ifdef SUPPORT_ACLS
1471 + if (preserve_acls)
1472 + receive_acl(file, f);
1475 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1476 stats.total_size += file->length;
1478 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1480 clean_flist(flist, relative_paths, 1);
1482 +#ifdef SUPPORT_ACLS
1483 + if (preserve_acls)
1484 + sort_file_acl_index_lists();
1488 recv_uid_list(f, flist);
1492 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1493 extern int max_delete;
1494 extern int force_delete;
1495 extern int one_file_system;
1496 +extern mode_t orig_umask;
1497 extern struct stats stats;
1498 extern dev_t filesystem_dev;
1499 extern char *backup_dir;
1500 @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l
1502 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1504 + /* FIXME: Flag ACL changes. */
1507 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1509 @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i
1510 if (preserve_gid && file->gid != GID_NONE
1511 && st->st_gid != file->gid)
1512 iflags |= ITEM_REPORT_GROUP;
1513 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1515 iflags |= ITEM_IS_NEW;
1517 @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str
1520 static int phase = 0;
1521 +static int dflt_perms;
1523 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1524 * make sure it exists, and has the right permissions/timestamp info. For
1525 @@ -844,6 +849,10 @@ static void recv_generator(char *fname,
1528 need_fuzzy_dirlist = 1;
1529 +#ifdef SUPPORT_ACLS
1530 + if (!preserve_perms)
1531 + dflt_perms = default_perms_for_dir(dn);
1534 parent_dirname = dn;
1536 @@ -871,7 +880,8 @@ static void recv_generator(char *fname,
1537 if (!preserve_perms) {
1538 int exists = statret == 0
1539 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1540 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1541 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1545 if (S_ISDIR(file->mode)) {
1546 @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi
1547 * notice that and let us know via the redo pipe (or its closing). */
1550 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1552 for (i = 0; i < flist->count; i++) {
1553 struct file_struct *file = flist->files[i];
1555 --- old/lib/sysacls.c
1556 +++ new/lib/sysacls.c
1559 + Unix SMB/CIFS implementation.
1560 + Samba system utilities for ACL support.
1561 + Copyright (C) Jeremy Allison 2000.
1563 + This program is free software; you can redistribute it and/or modify
1564 + it under the terms of the GNU General Public License as published by
1565 + the Free Software Foundation; either version 2 of the License, or
1566 + (at your option) any later version.
1568 + This program is distributed in the hope that it will be useful,
1569 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1570 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1571 + GNU General Public License for more details.
1573 + You should have received a copy of the GNU General Public License
1574 + along with this program; if not, write to the Free Software
1575 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1579 +#include "sysacls.h" /****** ADDED ******/
1581 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1582 +void SAFE_FREE(void *mem)
1588 +char *uidtoname(uid_t uid)
1590 + static char idbuf[12];
1591 + struct passwd *pw;
1593 + if ((pw = getpwuid(uid)) == NULL) {
1594 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1597 + return pw->pw_name;
1599 +/****** EXTRAS -- END ******/
1602 + This file wraps all differing system ACL interfaces into a consistent
1603 + one based on the POSIX interface. It also returns the correct errors
1604 + for older UNIX systems that don't support ACLs.
1606 + The interfaces that each ACL implementation must support are as follows :
1608 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1609 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1610 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1611 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1612 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1613 + SMB_ACL_T sys_acl_get_fd(int fd)
1614 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1615 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1616 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1617 + SMB_ACL_T sys_acl_init( int count)
1618 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1619 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1620 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1621 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1622 + int sys_acl_valid( SMB_ACL_T theacl )
1623 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1624 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1625 + int sys_acl_delete_def_file(const char *path)
1627 + This next one is not POSIX complient - but we *have* to have it !
1628 + More POSIX braindamage.
1630 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1632 + The generic POSIX free is the following call. We split this into
1633 + several different free functions as we may need to add tag info
1634 + to structures when emulating the POSIX interface.
1636 + int sys_acl_free( void *obj_p)
1638 + The calls we actually use are :
1640 + int sys_acl_free_text(char *text) - free acl_to_text
1641 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1642 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1646 +#if defined(HAVE_POSIX_ACLS)
1648 +/* Identity mapping - easy. */
1650 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1652 + return acl_get_entry( the_acl, entry_id, entry_p);
1655 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1657 + return acl_get_tag_type( entry_d, tag_type_p);
1660 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1662 + return acl_get_permset( entry_d, permset_p);
1665 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1667 + return acl_get_qualifier( entry_d);
1670 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1672 + return acl_get_file( path_p, type);
1675 +SMB_ACL_T sys_acl_get_fd(int fd)
1677 + return acl_get_fd(fd);
1680 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1682 + return acl_clear_perms(permset);
1685 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1687 + return acl_add_perm(permset, perm);
1690 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1692 +#if defined(HAVE_ACL_GET_PERM_NP)
1694 + * Required for TrustedBSD-based ACL implementations where
1695 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1698 + return acl_get_perm_np(permset, perm);
1700 + return acl_get_perm(permset, perm);
1704 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1706 + return acl_to_text( the_acl, plen);
1709 +SMB_ACL_T sys_acl_init( int count)
1711 + return acl_init(count);
1714 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1716 + return acl_create_entry(pacl, pentry);
1719 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1721 + return acl_set_tag_type(entry, tagtype);
1724 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1726 + return acl_set_qualifier(entry, qual);
1729 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1731 + return acl_set_permset(entry, permset);
1734 +int sys_acl_valid( SMB_ACL_T theacl )
1736 + return acl_valid(theacl);
1739 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1741 + return acl_set_file(name, acltype, theacl);
1744 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1746 + return acl_set_fd(fd, theacl);
1749 +int sys_acl_delete_def_file(const char *name)
1751 + return acl_delete_def_file(name);
1754 +int sys_acl_free_text(char *text)
1756 + return acl_free(text);
1759 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1761 + return acl_free(the_acl);
1764 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1766 + return acl_free(qual);
1769 +#elif defined(HAVE_TRU64_ACLS)
1771 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1772 + * is based on Draft 13 of the POSIX spec which is
1773 + * slightly different from the Draft 16 interface.
1775 + * Also, some of the permset manipulation functions
1776 + * such as acl_clear_perm() and acl_add_perm() appear
1777 + * to be broken on Tru64 so we have to manipulate
1778 + * the permission bits in the permset directly.
1780 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1782 + SMB_ACL_ENTRY_T entry;
1784 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1789 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1794 + return errno ? -1 : 0;
1797 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1799 + return acl_get_tag_type( entry_d, tag_type_p);
1802 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1804 + return acl_get_permset( entry_d, permset_p);
1807 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1809 + return acl_get_qualifier( entry_d);
1812 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1814 + return acl_get_file((char *)path_p, type);
1817 +SMB_ACL_T sys_acl_get_fd(int fd)
1819 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1822 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1824 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1829 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1831 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1836 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1841 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1843 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1846 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1848 + return acl_to_text( the_acl, plen);
1851 +SMB_ACL_T sys_acl_init( int count)
1853 + return acl_init(count);
1856 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1858 + SMB_ACL_ENTRY_T entry;
1860 + if ((entry = acl_create_entry(pacl)) == NULL) {
1868 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1870 + return acl_set_tag_type(entry, tagtype);
1873 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1875 + return acl_set_qualifier(entry, qual);
1878 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1880 + return acl_set_permset(entry, permset);
1883 +int sys_acl_valid( SMB_ACL_T theacl )
1885 + acl_entry_t entry;
1887 + return acl_valid(theacl, &entry);
1890 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1892 + return acl_set_file((char *)name, acltype, theacl);
1895 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1897 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1900 +int sys_acl_delete_def_file(const char *name)
1902 + return acl_delete_def_file((char *)name);
1905 +int sys_acl_free_text(char *text)
1908 + * (void) cast and explicit return 0 are for DEC UNIX
1909 + * which just #defines acl_free_text() to be free()
1911 + (void) acl_free_text(text);
1915 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1917 + return acl_free(the_acl);
1920 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1922 + return acl_free_qualifier(qual, tagtype);
1925 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1928 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1929 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1933 + * Note that while this code implements sufficient functionality
1934 + * to support the sys_acl_* interfaces it does not provide all
1935 + * of the semantics of the POSIX ACL interfaces.
1937 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1938 + * from a call to sys_acl_get_entry() should not be assumed to be
1939 + * valid after calling any of the following functions, which may
1940 + * reorder the entries in the ACL.
1943 + * sys_acl_set_file()
1944 + * sys_acl_set_fd()
1948 + * The only difference between Solaris and UnixWare / OpenUNIX is
1949 + * that the #defines for the ACL operations have different names
1951 +#if defined(HAVE_UNIXWARE_ACLS)
1953 +#define SETACL ACL_SET
1954 +#define GETACL ACL_GET
1955 +#define GETACLCNT ACL_CNT
1960 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1962 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1967 + if (entry_p == NULL) {
1972 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1976 + if (acl_d->next < 0) {
1981 + if (acl_d->next >= acl_d->count) {
1985 + *entry_p = &acl_d->acl[acl_d->next++];
1990 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1992 + *type_p = entry_d->a_type;
1997 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1999 + *permset_p = &entry_d->a_perm;
2004 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2006 + if (entry_d->a_type != SMB_ACL_USER
2007 + && entry_d->a_type != SMB_ACL_GROUP) {
2012 + return &entry_d->a_id;
2016 + * There is no way of knowing what size the ACL returned by
2017 + * GETACL will be unless you first call GETACLCNT which means
2018 + * making an additional system call.
2020 + * In the hope of avoiding the cost of the additional system
2021 + * call in most cases, we initially allocate enough space for
2022 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2023 + * be too small then we use GETACLCNT to find out the actual
2024 + * size, reallocate the ACL buffer, and then call GETACL again.
2027 +#define INITIAL_ACL_SIZE 16
2029 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2032 + int count; /* # of ACL entries allocated */
2033 + int naccess; /* # of access ACL entries */
2034 + int ndefault; /* # of default ACL entries */
2036 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2041 + count = INITIAL_ACL_SIZE;
2042 + if ((acl_d = sys_acl_init(count)) == NULL) {
2047 + * If there isn't enough space for the ACL entries we use
2048 + * GETACLCNT to determine the actual number of ACL entries
2049 + * reallocate and try again. This is in a loop because it
2050 + * is possible that someone else could modify the ACL and
2051 + * increase the number of entries between the call to
2052 + * GETACLCNT and the call to GETACL.
2054 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2055 + && errno == ENOSPC) {
2057 + sys_acl_free_acl(acl_d);
2059 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2063 + if ((acl_d = sys_acl_init(count)) == NULL) {
2069 + sys_acl_free_acl(acl_d);
2074 + * calculate the number of access and default ACL entries
2076 + * Note: we assume that the acl() system call returned a
2077 + * well formed ACL which is sorted so that all of the
2078 + * access ACL entries preceed any default ACL entries
2080 + for (naccess = 0; naccess < count; naccess++) {
2081 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2084 + ndefault = count - naccess;
2087 + * if the caller wants the default ACL we have to copy
2088 + * the entries down to the start of the acl[] buffer
2089 + * and mask out the ACL_DEFAULT flag from the type field
2091 + if (type == SMB_ACL_TYPE_DEFAULT) {
2094 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2095 + acl_d->acl[i] = acl_d->acl[j];
2096 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2099 + acl_d->count = ndefault;
2101 + acl_d->count = naccess;
2107 +SMB_ACL_T sys_acl_get_fd(int fd)
2110 + int count; /* # of ACL entries allocated */
2111 + int naccess; /* # of access ACL entries */
2113 + count = INITIAL_ACL_SIZE;
2114 + if ((acl_d = sys_acl_init(count)) == NULL) {
2118 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2119 + && errno == ENOSPC) {
2121 + sys_acl_free_acl(acl_d);
2123 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2127 + if ((acl_d = sys_acl_init(count)) == NULL) {
2133 + sys_acl_free_acl(acl_d);
2138 + * calculate the number of access ACL entries
2140 + for (naccess = 0; naccess < count; naccess++) {
2141 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2145 + acl_d->count = naccess;
2150 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2157 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2159 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2160 + && perm != SMB_ACL_EXECUTE) {
2165 + if (permset_d == NULL) {
2170 + *permset_d |= perm;
2175 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2177 + return *permset_d & perm;
2180 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2187 + * use an initial estimate of 20 bytes per ACL entry
2188 + * when allocating memory for the text representation
2192 + maxlen = 20 * acl_d->count;
2193 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2198 + for (i = 0; i < acl_d->count; i++) {
2199 + struct acl *ap = &acl_d->acl[i];
2208 + switch (ap->a_type) {
2210 + * for debugging purposes it's probably more
2211 + * useful to dump unknown tag types rather
2212 + * than just returning an error
2215 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2218 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2223 + case SMB_ACL_USER:
2224 + id = uidtoname(ap->a_id);
2225 + case SMB_ACL_USER_OBJ:
2229 + case SMB_ACL_GROUP:
2230 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2231 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2237 + case SMB_ACL_GROUP_OBJ:
2241 + case SMB_ACL_OTHER:
2245 + case SMB_ACL_MASK:
2251 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2252 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2253 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2256 + /* <tag> : <qualifier> : rwx \n \0 */
2257 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2260 + * If this entry would overflow the buffer
2261 + * allocate enough additional memory for this
2262 + * entry and an estimate of another 20 bytes
2263 + * for each entry still to be processed
2265 + if ((len + nbytes) > maxlen) {
2266 + char *oldtext = text;
2268 + maxlen += nbytes + 20 * (acl_d->count - i);
2270 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2271 + SAFE_FREE(oldtext);
2277 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2278 + len += nbytes - 1;
2287 +SMB_ACL_T sys_acl_init(int count)
2297 + * note that since the definition of the structure pointed
2298 + * to by the SMB_ACL_T includes the first element of the
2299 + * acl[] array, this actually allocates an ACL with room
2300 + * for (count+1) entries
2302 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2307 + a->size = count + 1;
2315 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2318 + SMB_ACL_ENTRY_T entry_d;
2320 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2325 + if (acl_d->count >= acl_d->size) {
2330 + entry_d = &acl_d->acl[acl_d->count++];
2331 + entry_d->a_type = 0;
2332 + entry_d->a_id = -1;
2333 + entry_d->a_perm = 0;
2334 + *entry_p = entry_d;
2339 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2341 + switch (tag_type) {
2342 + case SMB_ACL_USER:
2343 + case SMB_ACL_USER_OBJ:
2344 + case SMB_ACL_GROUP:
2345 + case SMB_ACL_GROUP_OBJ:
2346 + case SMB_ACL_OTHER:
2347 + case SMB_ACL_MASK:
2348 + entry_d->a_type = tag_type;
2358 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2360 + if (entry_d->a_type != SMB_ACL_GROUP
2361 + && entry_d->a_type != SMB_ACL_USER) {
2366 + entry_d->a_id = *((id_t *)qual_p);
2371 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2373 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2377 + entry_d->a_perm = *permset_d;
2383 + * sort the ACL and check it for validity
2385 + * if it's a minimal ACL with only 4 entries then we
2386 + * need to recalculate the mask permissions to make
2387 + * sure that they are the same as the GROUP_OBJ
2388 + * permissions as required by the UnixWare acl() system call.
2390 + * (note: since POSIX allows minimal ACLs which only contain
2391 + * 3 entries - ie there is no mask entry - we should, in theory,
2392 + * check for this and add a mask entry if necessary - however
2393 + * we "know" that the caller of this interface always specifies
2394 + * a mask so, in practice "this never happens" (tm) - if it *does*
2395 + * happen aclsort() will fail and return an error and someone will
2396 + * have to fix it ...)
2399 +static int acl_sort(SMB_ACL_T acl_d)
2401 + int fixmask = (acl_d->count <= 4);
2403 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2410 +int sys_acl_valid(SMB_ACL_T acl_d)
2412 + return acl_sort(acl_d);
2415 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2418 + struct acl *acl_p;
2420 + struct acl *acl_buf = NULL;
2423 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2428 + if (acl_sort(acl_d) != 0) {
2432 + acl_p = &acl_d->acl[0];
2433 + acl_count = acl_d->count;
2436 + * if it's a directory there is extra work to do
2437 + * since the acl() system call will replace both
2438 + * the access ACLs and the default ACLs (if any)
2440 + if (stat(name, &s) != 0) {
2443 + if (S_ISDIR(s.st_mode)) {
2444 + SMB_ACL_T acc_acl;
2445 + SMB_ACL_T def_acl;
2446 + SMB_ACL_T tmp_acl;
2449 + if (type == SMB_ACL_TYPE_ACCESS) {
2451 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2455 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2458 + if (tmp_acl == NULL) {
2463 + * allocate a temporary buffer for the complete ACL
2465 + acl_count = acc_acl->count + def_acl->count;
2466 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2468 + if (acl_buf == NULL) {
2469 + sys_acl_free_acl(tmp_acl);
2475 + * copy the access control and default entries into the buffer
2477 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2478 + acc_acl->count * sizeof(acl_buf[0]));
2480 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2481 + def_acl->count * sizeof(acl_buf[0]));
2484 + * set the ACL_DEFAULT flag on the default entries
2486 + for (i = acc_acl->count; i < acl_count; i++) {
2487 + acl_buf[i].a_type |= ACL_DEFAULT;
2490 + sys_acl_free_acl(tmp_acl);
2492 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2497 + ret = acl(name, SETACL, acl_count, acl_p);
2499 + SAFE_FREE(acl_buf);
2504 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2506 + if (acl_sort(acl_d) != 0) {
2510 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2513 +int sys_acl_delete_def_file(const char *path)
2519 + * fetching the access ACL and rewriting it has
2520 + * the effect of deleting the default ACL
2522 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2526 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2528 + sys_acl_free_acl(acl_d);
2533 +int sys_acl_free_text(char *text)
2539 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2545 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2550 +#elif defined(HAVE_HPUX_ACLS)
2554 + * Based on the Solaris/SCO code - with modifications.
2558 + * Note that while this code implements sufficient functionality
2559 + * to support the sys_acl_* interfaces it does not provide all
2560 + * of the semantics of the POSIX ACL interfaces.
2562 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2563 + * from a call to sys_acl_get_entry() should not be assumed to be
2564 + * valid after calling any of the following functions, which may
2565 + * reorder the entries in the ACL.
2568 + * sys_acl_set_file()
2569 + * sys_acl_set_fd()
2572 +/* This checks if the POSIX ACL system call is defined */
2573 +/* which basically corresponds to whether JFS 3.3 or */
2574 +/* higher is installed. If acl() was called when it */
2575 +/* isn't defined, it causes the process to core dump */
2576 +/* so it is important to check this and avoid acl() */
2577 +/* calls if it isn't there. */
2579 +static BOOL hpux_acl_call_presence(void)
2582 + shl_t handle = NULL;
2585 + static BOOL already_checked=0;
2587 + if(already_checked)
2591 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2593 + if(ret_val != 0) {
2594 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2595 + ret_val, errno, strerror(errno)));
2596 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2600 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2602 + already_checked = True;
2606 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2608 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2613 + if (entry_p == NULL) {
2618 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2622 + if (acl_d->next < 0) {
2627 + if (acl_d->next >= acl_d->count) {
2631 + *entry_p = &acl_d->acl[acl_d->next++];
2636 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2638 + *type_p = entry_d->a_type;
2643 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2645 + *permset_p = &entry_d->a_perm;
2650 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2652 + if (entry_d->a_type != SMB_ACL_USER
2653 + && entry_d->a_type != SMB_ACL_GROUP) {
2658 + return &entry_d->a_id;
2662 + * There is no way of knowing what size the ACL returned by
2663 + * ACL_GET will be unless you first call ACL_CNT which means
2664 + * making an additional system call.
2666 + * In the hope of avoiding the cost of the additional system
2667 + * call in most cases, we initially allocate enough space for
2668 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2669 + * be too small then we use ACL_CNT to find out the actual
2670 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2673 +#define INITIAL_ACL_SIZE 16
2675 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2678 + int count; /* # of ACL entries allocated */
2679 + int naccess; /* # of access ACL entries */
2680 + int ndefault; /* # of default ACL entries */
2682 + if(hpux_acl_call_presence() == False) {
2683 + /* Looks like we don't have the acl() system call on HPUX.
2684 + * May be the system doesn't have the latest version of JFS.
2689 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2694 + count = INITIAL_ACL_SIZE;
2695 + if ((acl_d = sys_acl_init(count)) == NULL) {
2700 + * If there isn't enough space for the ACL entries we use
2701 + * ACL_CNT to determine the actual number of ACL entries
2702 + * reallocate and try again. This is in a loop because it
2703 + * is possible that someone else could modify the ACL and
2704 + * increase the number of entries between the call to
2705 + * ACL_CNT and the call to ACL_GET.
2707 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2709 + sys_acl_free_acl(acl_d);
2711 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2715 + if ((acl_d = sys_acl_init(count)) == NULL) {
2721 + sys_acl_free_acl(acl_d);
2726 + * calculate the number of access and default ACL entries
2728 + * Note: we assume that the acl() system call returned a
2729 + * well formed ACL which is sorted so that all of the
2730 + * access ACL entries preceed any default ACL entries
2732 + for (naccess = 0; naccess < count; naccess++) {
2733 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2736 + ndefault = count - naccess;
2739 + * if the caller wants the default ACL we have to copy
2740 + * the entries down to the start of the acl[] buffer
2741 + * and mask out the ACL_DEFAULT flag from the type field
2743 + if (type == SMB_ACL_TYPE_DEFAULT) {
2746 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2747 + acl_d->acl[i] = acl_d->acl[j];
2748 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2751 + acl_d->count = ndefault;
2753 + acl_d->count = naccess;
2759 +SMB_ACL_T sys_acl_get_fd(int fd)
2762 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2765 + files_struct *fsp = file_find_fd(fd);
2767 + if (fsp == NULL) {
2773 + * We know we're in the same conn context. So we
2774 + * can use the relative path.
2777 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2780 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2787 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2789 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2790 + && perm != SMB_ACL_EXECUTE) {
2795 + if (permset_d == NULL) {
2800 + *permset_d |= perm;
2805 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2807 + return *permset_d & perm;
2810 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2817 + * use an initial estimate of 20 bytes per ACL entry
2818 + * when allocating memory for the text representation
2822 + maxlen = 20 * acl_d->count;
2823 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2828 + for (i = 0; i < acl_d->count; i++) {
2829 + struct acl *ap = &acl_d->acl[i];
2838 + switch (ap->a_type) {
2840 + * for debugging purposes it's probably more
2841 + * useful to dump unknown tag types rather
2842 + * than just returning an error
2845 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2848 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2853 + case SMB_ACL_USER:
2854 + id = uidtoname(ap->a_id);
2855 + case SMB_ACL_USER_OBJ:
2859 + case SMB_ACL_GROUP:
2860 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2861 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2867 + case SMB_ACL_GROUP_OBJ:
2871 + case SMB_ACL_OTHER:
2875 + case SMB_ACL_MASK:
2881 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2882 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2883 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2886 + /* <tag> : <qualifier> : rwx \n \0 */
2887 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2890 + * If this entry would overflow the buffer
2891 + * allocate enough additional memory for this
2892 + * entry and an estimate of another 20 bytes
2893 + * for each entry still to be processed
2895 + if ((len + nbytes) > maxlen) {
2896 + char *oldtext = text;
2898 + maxlen += nbytes + 20 * (acl_d->count - i);
2900 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2907 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2908 + len += nbytes - 1;
2917 +SMB_ACL_T sys_acl_init(int count)
2927 + * note that since the definition of the structure pointed
2928 + * to by the SMB_ACL_T includes the first element of the
2929 + * acl[] array, this actually allocates an ACL with room
2930 + * for (count+1) entries
2932 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2937 + a->size = count + 1;
2945 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2948 + SMB_ACL_ENTRY_T entry_d;
2950 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2955 + if (acl_d->count >= acl_d->size) {
2960 + entry_d = &acl_d->acl[acl_d->count++];
2961 + entry_d->a_type = 0;
2962 + entry_d->a_id = -1;
2963 + entry_d->a_perm = 0;
2964 + *entry_p = entry_d;
2969 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2971 + switch (tag_type) {
2972 + case SMB_ACL_USER:
2973 + case SMB_ACL_USER_OBJ:
2974 + case SMB_ACL_GROUP:
2975 + case SMB_ACL_GROUP_OBJ:
2976 + case SMB_ACL_OTHER:
2977 + case SMB_ACL_MASK:
2978 + entry_d->a_type = tag_type;
2988 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2990 + if (entry_d->a_type != SMB_ACL_GROUP
2991 + && entry_d->a_type != SMB_ACL_USER) {
2996 + entry_d->a_id = *((id_t *)qual_p);
3001 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3003 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3007 + entry_d->a_perm = *permset_d;
3012 +/* Structure to capture the count for each type of ACE. */
3014 +struct hpux_acl_types {
3018 + int n_def_user_obj;
3023 + int n_def_group_obj;
3027 + int n_def_other_obj;
3030 + int n_def_class_obj;
3032 + int n_illegal_obj;
3036 + * Counts the different number of objects in a given array of ACL
3040 + * acl_count - Count of ACLs in the array of ACL strucutres.
3041 + * aclp - Array of ACL structures.
3042 + * acl_type_count - Pointer to acl_types structure. Should already be
3046 + * acl_type_count - This structure is filled up with counts of various
3050 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3054 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3056 + for(i=0;i<acl_count;i++) {
3057 + switch(aclp[i].a_type) {
3059 + acl_type_count->n_user++;
3062 + acl_type_count->n_user_obj++;
3064 + case DEF_USER_OBJ:
3065 + acl_type_count->n_def_user_obj++;
3068 + acl_type_count->n_group++;
3071 + acl_type_count->n_group_obj++;
3073 + case DEF_GROUP_OBJ:
3074 + acl_type_count->n_def_group_obj++;
3077 + acl_type_count->n_other_obj++;
3079 + case DEF_OTHER_OBJ:
3080 + acl_type_count->n_def_other_obj++;
3083 + acl_type_count->n_class_obj++;
3085 + case DEF_CLASS_OBJ:
3086 + acl_type_count->n_def_class_obj++;
3089 + acl_type_count->n_def_user++;
3092 + acl_type_count->n_def_group++;
3095 + acl_type_count->n_illegal_obj++;
3101 +/* swap_acl_entries: Swaps two ACL entries.
3103 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3106 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3108 + struct acl temp_acl;
3110 + temp_acl.a_type = aclp0->a_type;
3111 + temp_acl.a_id = aclp0->a_id;
3112 + temp_acl.a_perm = aclp0->a_perm;
3114 + aclp0->a_type = aclp1->a_type;
3115 + aclp0->a_id = aclp1->a_id;
3116 + aclp0->a_perm = aclp1->a_perm;
3118 + aclp1->a_type = temp_acl.a_type;
3119 + aclp1->a_id = temp_acl.a_id;
3120 + aclp1->a_perm = temp_acl.a_perm;
3123 +/* prohibited_duplicate_type
3124 + * Identifies if given ACL type can have duplicate entries or
3127 + * Inputs: acl_type - ACL Type.
3133 + * True - If the ACL type matches any of the prohibited types.
3134 + * False - If the ACL type doesn't match any of the prohibited types.
3137 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3139 + switch(acl_type) {
3150 +/* get_needed_class_perm
3151 + * Returns the permissions of a ACL structure only if the ACL
3152 + * type matches one of the pre-determined types for computing
3153 + * CLASS_OBJ permissions.
3155 + * Inputs: aclp - Pointer to ACL structure.
3158 +static int hpux_get_needed_class_perm(struct acl *aclp)
3160 + switch(aclp->a_type) {
3164 + case DEF_USER_OBJ:
3166 + case DEF_GROUP_OBJ:
3168 + case DEF_CLASS_OBJ:
3169 + case DEF_OTHER_OBJ:
3170 + return aclp->a_perm;
3176 +/* acl_sort for HPUX.
3177 + * Sorts the array of ACL structures as per the description in
3178 + * aclsort man page. Refer to aclsort man page for more details
3182 + * acl_count - Count of ACLs in the array of ACL structures.
3183 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3185 + * aclp - Array of ACL structures.
3189 + * aclp - Sorted array of ACL structures.
3193 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3194 + * debug log in case of failure.
3197 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3199 +#if !defined(HAVE_HPUX_ACLSORT)
3201 + * The aclsort() system call is availabe on the latest HPUX General
3202 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3203 + * function. Because, we don't want to update to a new
3204 + * HPUX GR bundle just for aclsort() call.
3207 + struct hpux_acl_types acl_obj_count;
3208 + int n_class_obj_perm = 0;
3212 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3216 + if(aclp == NULL) {
3217 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3221 + /* Count different types of ACLs in the ACLs array */
3223 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3225 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3226 + * CLASS_OBJ and OTHER_OBJ
3229 + if( (acl_obj_count.n_user_obj != 1) ||
3230 + (acl_obj_count.n_group_obj != 1) ||
3231 + (acl_obj_count.n_class_obj != 1) ||
3232 + (acl_obj_count.n_other_obj != 1)
3234 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3235 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3239 + /* If any of the default objects are present, there should be only
3240 + * one of them each.
3243 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3244 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3245 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3246 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3250 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3253 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3254 + * same ACL type, sort by ACL id.
3256 + * I am using the trival kind of sorting method here because, performance isn't
3257 + * really effected by the ACLs feature. More over there aren't going to be more
3258 + * than 17 entries on HPUX.
3261 + for(i=0; i<acl_count;i++) {
3262 + for (j=i+1; j<acl_count; j++) {
3263 + if( aclp[i].a_type > aclp[j].a_type ) {
3264 + /* ACL entries out of order, swap them */
3266 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3268 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3270 + /* ACL entries of same type, sort by id */
3272 + if(aclp[i].a_id > aclp[j].a_id) {
3273 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3274 + } else if (aclp[i].a_id == aclp[j].a_id) {
3275 + /* We have a duplicate entry. */
3276 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3277 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3278 + aclp[i].a_type, aclp[i].a_id));
3287 + /* set the class obj permissions to the computed one. */
3289 + int n_class_obj_index = -1;
3291 + for(i=0;i<acl_count;i++) {
3292 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3294 + if(aclp[i].a_type == CLASS_OBJ)
3295 + n_class_obj_index = i;
3297 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3302 + return aclsort(acl_count, calclass, aclp);
3307 + * sort the ACL and check it for validity
3309 + * if it's a minimal ACL with only 4 entries then we
3310 + * need to recalculate the mask permissions to make
3311 + * sure that they are the same as the GROUP_OBJ
3312 + * permissions as required by the UnixWare acl() system call.
3314 + * (note: since POSIX allows minimal ACLs which only contain
3315 + * 3 entries - ie there is no mask entry - we should, in theory,
3316 + * check for this and add a mask entry if necessary - however
3317 + * we "know" that the caller of this interface always specifies
3318 + * a mask so, in practice "this never happens" (tm) - if it *does*
3319 + * happen aclsort() will fail and return an error and someone will
3320 + * have to fix it ...)
3323 +static int acl_sort(SMB_ACL_T acl_d)
3325 + int fixmask = (acl_d->count <= 4);
3327 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3334 +int sys_acl_valid(SMB_ACL_T acl_d)
3336 + return acl_sort(acl_d);
3339 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3342 + struct acl *acl_p;
3344 + struct acl *acl_buf = NULL;
3347 + if(hpux_acl_call_presence() == False) {
3348 + /* Looks like we don't have the acl() system call on HPUX.
3349 + * May be the system doesn't have the latest version of JFS.
3355 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3360 + if (acl_sort(acl_d) != 0) {
3364 + acl_p = &acl_d->acl[0];
3365 + acl_count = acl_d->count;
3368 + * if it's a directory there is extra work to do
3369 + * since the acl() system call will replace both
3370 + * the access ACLs and the default ACLs (if any)
3372 + if (stat(name, &s) != 0) {
3375 + if (S_ISDIR(s.st_mode)) {
3376 + SMB_ACL_T acc_acl;
3377 + SMB_ACL_T def_acl;
3378 + SMB_ACL_T tmp_acl;
3381 + if (type == SMB_ACL_TYPE_ACCESS) {
3383 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3387 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3390 + if (tmp_acl == NULL) {
3395 + * allocate a temporary buffer for the complete ACL
3397 + acl_count = acc_acl->count + def_acl->count;
3398 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3400 + if (acl_buf == NULL) {
3401 + sys_acl_free_acl(tmp_acl);
3407 + * copy the access control and default entries into the buffer
3409 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3410 + acc_acl->count * sizeof(acl_buf[0]));
3412 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3413 + def_acl->count * sizeof(acl_buf[0]));
3416 + * set the ACL_DEFAULT flag on the default entries
3418 + for (i = acc_acl->count; i < acl_count; i++) {
3419 + acl_buf[i].a_type |= ACL_DEFAULT;
3422 + sys_acl_free_acl(tmp_acl);
3424 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3429 + ret = acl(name, ACL_SET, acl_count, acl_p);
3438 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3441 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3444 + files_struct *fsp = file_find_fd(fd);
3446 + if (fsp == NULL) {
3451 + if (acl_sort(acl_d) != 0) {
3456 + * We know we're in the same conn context. So we
3457 + * can use the relative path.
3460 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3463 +int sys_acl_delete_def_file(const char *path)
3469 + * fetching the access ACL and rewriting it has
3470 + * the effect of deleting the default ACL
3472 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3476 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3478 + sys_acl_free_acl(acl_d);
3483 +int sys_acl_free_text(char *text)
3489 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3495 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3500 +#elif defined(HAVE_IRIX_ACLS)
3502 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3504 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3509 + if (entry_p == NULL) {
3514 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3518 + if (acl_d->next < 0) {
3523 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3527 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3532 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3534 + *type_p = entry_d->ae_tag;
3539 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3541 + *permset_p = entry_d;
3546 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3548 + if (entry_d->ae_tag != SMB_ACL_USER
3549 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3554 + return &entry_d->ae_id;
3557 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3561 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3565 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3570 + a->freeaclp = True;
3574 +SMB_ACL_T sys_acl_get_fd(int fd)
3578 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3582 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3587 + a->freeaclp = True;
3591 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3593 + permset_d->ae_perm = 0;
3598 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3600 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3601 + && perm != SMB_ACL_EXECUTE) {
3606 + if (permset_d == NULL) {
3611 + permset_d->ae_perm |= perm;
3616 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3618 + return permset_d->ae_perm & perm;
3621 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3623 + return acl_to_text(acl_d->aclp, len_p);
3626 +SMB_ACL_T sys_acl_init(int count)
3635 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3641 + a->freeaclp = False;
3642 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3643 + a->aclp->acl_cnt = 0;
3649 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3652 + SMB_ACL_ENTRY_T entry_d;
3654 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3659 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3664 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3665 + entry_d->ae_tag = 0;
3666 + entry_d->ae_id = 0;
3667 + entry_d->ae_perm = 0;
3668 + *entry_p = entry_d;
3673 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3675 + switch (tag_type) {
3676 + case SMB_ACL_USER:
3677 + case SMB_ACL_USER_OBJ:
3678 + case SMB_ACL_GROUP:
3679 + case SMB_ACL_GROUP_OBJ:
3680 + case SMB_ACL_OTHER:
3681 + case SMB_ACL_MASK:
3682 + entry_d->ae_tag = tag_type;
3692 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3694 + if (entry_d->ae_tag != SMB_ACL_GROUP
3695 + && entry_d->ae_tag != SMB_ACL_USER) {
3700 + entry_d->ae_id = *((id_t *)qual_p);
3705 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3707 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3711 + entry_d->ae_perm = permset_d->ae_perm;
3716 +int sys_acl_valid(SMB_ACL_T acl_d)
3718 + return acl_valid(acl_d->aclp);
3721 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3723 + return acl_set_file(name, type, acl_d->aclp);
3726 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3728 + return acl_set_fd(fd, acl_d->aclp);
3731 +int sys_acl_delete_def_file(const char *name)
3733 + return acl_delete_def_file(name);
3736 +int sys_acl_free_text(char *text)
3738 + return acl_free(text);
3741 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3743 + if (acl_d->freeaclp) {
3744 + acl_free(acl_d->aclp);
3750 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3755 +#elif defined(HAVE_AIX_ACLS)
3757 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3759 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3761 + struct acl_entry_link *link;
3762 + struct new_acl_entry *entry;
3765 + DEBUG(10,("This is the count: %d\n",theacl->count));
3767 + /* Check if count was previously set to -1. *
3768 + * If it was, that means we reached the end *
3769 + * of the acl last time. */
3770 + if(theacl->count == -1)
3774 + /* To get to the next acl, traverse linked list until index *
3775 + * of acl matches the count we are keeping. This count is *
3776 + * incremented each time we return an acl entry. */
3778 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3779 + link = link->nextp;
3781 + entry = *entry_p = link->entryp;
3783 + DEBUG(10,("*entry_p is %d\n",entry_p));
3784 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3786 + /* Increment count */
3788 + if(link->nextp == NULL)
3789 + theacl->count = -1;
3794 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3796 + /* Initialize tag type */
3799 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3801 + /* Depending on what type of entry we have, *
3802 + * return tag type. */
3803 + switch(entry_d->ace_id->id_type) {
3805 + *tag_type_p = SMB_ACL_USER;
3808 + *tag_type_p = SMB_ACL_GROUP;
3811 + case SMB_ACL_USER_OBJ:
3812 + case SMB_ACL_GROUP_OBJ:
3813 + case SMB_ACL_OTHER:
3814 + *tag_type_p = entry_d->ace_id->id_type;
3824 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3826 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3827 + *permset_p = &entry_d->ace_access;
3828 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3829 + if(!(**permset_p & S_IXUSR) &&
3830 + !(**permset_p & S_IWUSR) &&
3831 + !(**permset_p & S_IRUSR) &&
3832 + (**permset_p != 0))
3835 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3839 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3841 + return(entry_d->ace_id->id_data);
3844 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3846 + struct acl *file_acl = (struct acl *)NULL;
3847 + struct acl_entry *acl_entry;
3848 + struct new_acl_entry *new_acl_entry;
3849 + struct ace_id *idp;
3850 + struct acl_entry_link *acl_entry_link;
3851 + struct acl_entry_link *acl_entry_link_head;
3856 + /* AIX has no DEFAULT */
3857 + if ( type == SMB_ACL_TYPE_DEFAULT )
3860 + /* Get the acl using statacl */
3862 + DEBUG(10,("Entering sys_acl_get_file\n"));
3863 + DEBUG(10,("path_p is %s\n",path_p));
3865 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3867 + if(file_acl == NULL) {
3869 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3873 + memset(file_acl,0,BUFSIZ);
3875 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3877 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3878 + SAFE_FREE(file_acl);
3882 + DEBUG(10,("Got facl and returned it\n"));
3884 + /* Point to the first acl entry in the acl */
3885 + acl_entry = file_acl->acl_ext;
3887 + /* Begin setting up the head of the linked list *
3888 + * that will be used for the storing the acl *
3889 + * in a way that is useful for the posix_acls.c *
3892 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3893 + if(acl_entry_link_head == NULL)
3896 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3897 + if(acl_entry_link->entryp == NULL) {
3898 + SAFE_FREE(file_acl);
3900 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3904 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3905 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3907 + /* Check if the extended acl bit is on. *
3908 + * If it isn't, do not show the *
3909 + * contents of the acl since AIX intends *
3910 + * the extended info to remain unused */
3912 + if(file_acl->acl_mode & S_IXACL){
3913 + /* while we are not pointing to the very end */
3914 + while(acl_entry < acl_last(file_acl)) {
3915 + /* before we malloc anything, make sure this is */
3916 + /* a valid acl entry and one that we want to map */
3917 + idp = id_nxt(acl_entry->ace_id);
3918 + if((acl_entry->ace_type == ACC_SPECIFY ||
3919 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3920 + acl_entry = acl_nxt(acl_entry);
3924 + idp = acl_entry->ace_id;
3926 + /* Check if this is the first entry in the linked list. *
3927 + * The first entry needs to keep prevp pointing to NULL *
3928 + * and already has entryp allocated. */
3930 + if(acl_entry_link_head->count != 0) {
3931 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3933 + if(acl_entry_link->nextp == NULL) {
3934 + SAFE_FREE(file_acl);
3936 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3940 + acl_entry_link->nextp->prevp = acl_entry_link;
3941 + acl_entry_link = acl_entry_link->nextp;
3942 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3943 + if(acl_entry_link->entryp == NULL) {
3944 + SAFE_FREE(file_acl);
3946 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3949 + acl_entry_link->nextp = NULL;
3952 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3954 + /* Don't really need this since all types are going *
3955 + * to be specified but, it's better than leaving it 0 */
3957 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3959 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3961 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3963 + /* The access in the acl entries must be left shifted by *
3964 + * three bites, because they will ultimately be compared *
3965 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3967 + switch(acl_entry->ace_type){
3970 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3971 + acl_entry_link->entryp->ace_access <<= 6;
3972 + acl_entry_link_head->count++;
3975 + /* Since there is no way to return a DENY acl entry *
3976 + * change to PERMIT and then shift. */
3977 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3978 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3979 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3980 + acl_entry_link->entryp->ace_access <<= 6;
3981 + acl_entry_link_head->count++;
3987 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3988 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3990 + acl_entry = acl_nxt(acl_entry);
3992 + } /* end of if enabled */
3994 + /* Since owner, group, other acl entries are not *
3995 + * part of the acl entries in an acl, they must *
3996 + * be dummied up to become part of the list. */
3998 + for( i = 1; i < 4; i++) {
3999 + DEBUG(10,("i is %d\n",i));
4000 + if(acl_entry_link_head->count != 0) {
4001 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4002 + if(acl_entry_link->nextp == NULL) {
4003 + SAFE_FREE(file_acl);
4005 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4009 + acl_entry_link->nextp->prevp = acl_entry_link;
4010 + acl_entry_link = acl_entry_link->nextp;
4011 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4012 + if(acl_entry_link->entryp == NULL) {
4013 + SAFE_FREE(file_acl);
4015 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4020 + acl_entry_link->nextp = NULL;
4022 + new_acl_entry = acl_entry_link->entryp;
4023 + idp = new_acl_entry->ace_id;
4025 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4026 + new_acl_entry->ace_type = ACC_PERMIT;
4027 + idp->id_len = sizeof(struct ace_id);
4028 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4029 + memset(idp->id_data,0,sizeof(uid_t));
4033 + new_acl_entry->ace_access = file_acl->g_access << 6;
4034 + idp->id_type = SMB_ACL_GROUP_OBJ;
4038 + new_acl_entry->ace_access = file_acl->o_access << 6;
4039 + idp->id_type = SMB_ACL_OTHER;
4043 + new_acl_entry->ace_access = file_acl->u_access << 6;
4044 + idp->id_type = SMB_ACL_USER_OBJ;
4052 + acl_entry_link_head->count++;
4053 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4056 + acl_entry_link_head->count = 0;
4057 + SAFE_FREE(file_acl);
4059 + return(acl_entry_link_head);
4062 +SMB_ACL_T sys_acl_get_fd(int fd)
4064 + struct acl *file_acl = (struct acl *)NULL;
4065 + struct acl_entry *acl_entry;
4066 + struct new_acl_entry *new_acl_entry;
4067 + struct ace_id *idp;
4068 + struct acl_entry_link *acl_entry_link;
4069 + struct acl_entry_link *acl_entry_link_head;
4074 + /* Get the acl using fstatacl */
4076 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4077 + DEBUG(10,("fd is %d\n",fd));
4078 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4080 + if(file_acl == NULL) {
4082 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4086 + memset(file_acl,0,BUFSIZ);
4088 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4090 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4091 + SAFE_FREE(file_acl);
4095 + DEBUG(10,("Got facl and returned it\n"));
4097 + /* Point to the first acl entry in the acl */
4099 + acl_entry = file_acl->acl_ext;
4100 + /* Begin setting up the head of the linked list *
4101 + * that will be used for the storing the acl *
4102 + * in a way that is useful for the posix_acls.c *
4105 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4106 + if(acl_entry_link_head == NULL){
4107 + SAFE_FREE(file_acl);
4111 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4113 + if(acl_entry_link->entryp == NULL) {
4115 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4116 + SAFE_FREE(file_acl);
4120 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4121 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4123 + /* Check if the extended acl bit is on. *
4124 + * If it isn't, do not show the *
4125 + * contents of the acl since AIX intends *
4126 + * the extended info to remain unused */
4128 + if(file_acl->acl_mode & S_IXACL){
4129 + /* while we are not pointing to the very end */
4130 + while(acl_entry < acl_last(file_acl)) {
4131 + /* before we malloc anything, make sure this is */
4132 + /* a valid acl entry and one that we want to map */
4134 + idp = id_nxt(acl_entry->ace_id);
4135 + if((acl_entry->ace_type == ACC_SPECIFY ||
4136 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4137 + acl_entry = acl_nxt(acl_entry);
4141 + idp = acl_entry->ace_id;
4143 + /* Check if this is the first entry in the linked list. *
4144 + * The first entry needs to keep prevp pointing to NULL *
4145 + * and already has entryp allocated. */
4147 + if(acl_entry_link_head->count != 0) {
4148 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4149 + if(acl_entry_link->nextp == NULL) {
4151 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4152 + SAFE_FREE(file_acl);
4155 + acl_entry_link->nextp->prevp = acl_entry_link;
4156 + acl_entry_link = acl_entry_link->nextp;
4157 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4158 + if(acl_entry_link->entryp == NULL) {
4160 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4161 + SAFE_FREE(file_acl);
4165 + acl_entry_link->nextp = NULL;
4168 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4170 + /* Don't really need this since all types are going *
4171 + * to be specified but, it's better than leaving it 0 */
4173 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4174 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4176 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4178 + /* The access in the acl entries must be left shifted by *
4179 + * three bites, because they will ultimately be compared *
4180 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4182 + switch(acl_entry->ace_type){
4185 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4186 + acl_entry_link->entryp->ace_access <<= 6;
4187 + acl_entry_link_head->count++;
4190 + /* Since there is no way to return a DENY acl entry *
4191 + * change to PERMIT and then shift. */
4192 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4193 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4194 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4195 + acl_entry_link->entryp->ace_access <<= 6;
4196 + acl_entry_link_head->count++;
4202 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4203 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4205 + acl_entry = acl_nxt(acl_entry);
4207 + } /* end of if enabled */
4209 + /* Since owner, group, other acl entries are not *
4210 + * part of the acl entries in an acl, they must *
4211 + * be dummied up to become part of the list. */
4213 + for( i = 1; i < 4; i++) {
4214 + DEBUG(10,("i is %d\n",i));
4215 + if(acl_entry_link_head->count != 0){
4216 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4217 + if(acl_entry_link->nextp == NULL) {
4219 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4220 + SAFE_FREE(file_acl);
4224 + acl_entry_link->nextp->prevp = acl_entry_link;
4225 + acl_entry_link = acl_entry_link->nextp;
4226 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4228 + if(acl_entry_link->entryp == NULL) {
4229 + SAFE_FREE(file_acl);
4231 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4236 + acl_entry_link->nextp = NULL;
4238 + new_acl_entry = acl_entry_link->entryp;
4239 + idp = new_acl_entry->ace_id;
4241 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4242 + new_acl_entry->ace_type = ACC_PERMIT;
4243 + idp->id_len = sizeof(struct ace_id);
4244 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4245 + memset(idp->id_data,0,sizeof(uid_t));
4249 + new_acl_entry->ace_access = file_acl->g_access << 6;
4250 + idp->id_type = SMB_ACL_GROUP_OBJ;
4254 + new_acl_entry->ace_access = file_acl->o_access << 6;
4255 + idp->id_type = SMB_ACL_OTHER;
4259 + new_acl_entry->ace_access = file_acl->u_access << 6;
4260 + idp->id_type = SMB_ACL_USER_OBJ;
4267 + acl_entry_link_head->count++;
4268 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4271 + acl_entry_link_head->count = 0;
4272 + SAFE_FREE(file_acl);
4274 + return(acl_entry_link_head);
4277 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4279 + *permset = *permset & ~0777;
4283 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4286 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4290 + DEBUG(10,("This is the permset now: %d\n",*permset));
4294 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4299 +SMB_ACL_T sys_acl_init( int count)
4301 + struct acl_entry_link *theacl = NULL;
4303 + DEBUG(10,("Entering sys_acl_init\n"));
4305 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4306 + if(theacl == NULL) {
4308 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4312 + theacl->count = 0;
4313 + theacl->nextp = NULL;
4314 + theacl->prevp = NULL;
4315 + theacl->entryp = NULL;
4316 + DEBUG(10,("Exiting sys_acl_init\n"));
4320 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4322 + struct acl_entry_link *theacl;
4323 + struct acl_entry_link *acl_entryp;
4324 + struct acl_entry_link *temp_entry;
4327 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4329 + theacl = acl_entryp = *pacl;
4331 + /* Get to the end of the acl before adding entry */
4333 + for(counting=0; counting < theacl->count; counting++){
4334 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4335 + temp_entry = acl_entryp;
4336 + acl_entryp = acl_entryp->nextp;
4339 + if(theacl->count != 0){
4340 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4341 + if(acl_entryp == NULL) {
4343 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4347 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4348 + acl_entryp->prevp = temp_entry;
4349 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4352 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4353 + if(*pentry == NULL) {
4355 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4359 + memset(*pentry,0,sizeof(struct new_acl_entry));
4360 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4361 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4362 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4363 + acl_entryp->nextp = NULL;
4365 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4369 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4371 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4372 + entry->ace_id->id_type = tagtype;
4373 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4374 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4377 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4379 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4380 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4381 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4385 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4387 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4388 + if(!(*permset & S_IXUSR) &&
4389 + !(*permset & S_IWUSR) &&
4390 + !(*permset & S_IRUSR) &&
4394 + entry->ace_access = *permset;
4395 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4396 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4400 +int sys_acl_valid( SMB_ACL_T theacl )
4403 + int group_obj = 0;
4404 + int other_obj = 0;
4405 + struct acl_entry_link *acl_entry;
4407 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4408 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4409 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4410 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4413 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4415 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4421 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4423 + struct acl_entry_link *acl_entry_link = NULL;
4424 + struct acl *file_acl = NULL;
4425 + struct acl *file_acl_temp = NULL;
4426 + struct acl_entry *acl_entry = NULL;
4427 + struct ace_id *ace_id = NULL;
4434 + DEBUG(10,("Entering sys_acl_set_file\n"));
4435 + DEBUG(10,("File name is %s\n",name));
4437 + /* AIX has no default ACL */
4438 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4441 + acl_length = BUFSIZ;
4442 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4444 + if(file_acl == NULL) {
4446 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4450 + memset(file_acl,0,BUFSIZ);
4452 + file_acl->acl_len = ACL_SIZ;
4453 + file_acl->acl_mode = S_IXACL;
4455 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4456 + acl_entry_link->entryp->ace_access >>= 6;
4457 + id_type = acl_entry_link->entryp->ace_id->id_type;
4460 + case SMB_ACL_USER_OBJ:
4461 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4463 + case SMB_ACL_GROUP_OBJ:
4464 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4466 + case SMB_ACL_OTHER:
4467 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4469 + case SMB_ACL_MASK:
4473 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4474 + acl_length += sizeof(struct acl_entry);
4475 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4476 + if(file_acl_temp == NULL) {
4477 + SAFE_FREE(file_acl);
4479 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4483 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4484 + SAFE_FREE(file_acl);
4485 + file_acl = file_acl_temp;
4488 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4489 + file_acl->acl_len += sizeof(struct acl_entry);
4490 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4491 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4493 + /* In order to use this, we'll need to wait until we can get denies */
4494 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4495 + acl_entry->ace_type = ACC_SPECIFY; */
4497 + acl_entry->ace_type = ACC_SPECIFY;
4499 + ace_id = acl_entry->ace_id;
4501 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4502 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4503 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4504 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4505 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4508 + rc = chacl(name,file_acl,file_acl->acl_len);
4509 + DEBUG(10,("errno is %d\n",errno));
4510 + DEBUG(10,("return code is %d\n",rc));
4511 + SAFE_FREE(file_acl);
4512 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4516 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4518 + struct acl_entry_link *acl_entry_link = NULL;
4519 + struct acl *file_acl = NULL;
4520 + struct acl *file_acl_temp = NULL;
4521 + struct acl_entry *acl_entry = NULL;
4522 + struct ace_id *ace_id = NULL;
4528 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4529 + acl_length = BUFSIZ;
4530 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4532 + if(file_acl == NULL) {
4534 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4538 + memset(file_acl,0,BUFSIZ);
4540 + file_acl->acl_len = ACL_SIZ;
4541 + file_acl->acl_mode = S_IXACL;
4543 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4544 + acl_entry_link->entryp->ace_access >>= 6;
4545 + id_type = acl_entry_link->entryp->ace_id->id_type;
4546 + DEBUG(10,("The id_type is %d\n",id_type));
4549 + case SMB_ACL_USER_OBJ:
4550 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4552 + case SMB_ACL_GROUP_OBJ:
4553 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4555 + case SMB_ACL_OTHER:
4556 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4558 + case SMB_ACL_MASK:
4562 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4563 + acl_length += sizeof(struct acl_entry);
4564 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4565 + if(file_acl_temp == NULL) {
4566 + SAFE_FREE(file_acl);
4568 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4572 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4573 + SAFE_FREE(file_acl);
4574 + file_acl = file_acl_temp;
4577 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4578 + file_acl->acl_len += sizeof(struct acl_entry);
4579 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4580 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4582 + /* In order to use this, we'll need to wait until we can get denies */
4583 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4584 + acl_entry->ace_type = ACC_SPECIFY; */
4586 + acl_entry->ace_type = ACC_SPECIFY;
4588 + ace_id = acl_entry->ace_id;
4590 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4591 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4592 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4593 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4594 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4597 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4598 + DEBUG(10,("errno is %d\n",errno));
4599 + DEBUG(10,("return code is %d\n",rc));
4600 + SAFE_FREE(file_acl);
4601 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4605 +int sys_acl_delete_def_file(const char *name)
4607 + /* AIX has no default ACL */
4611 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4613 + return(*permset & perm);
4616 +int sys_acl_free_text(char *text)
4621 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4623 + struct acl_entry_link *acl_entry_link;
4625 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4626 + SAFE_FREE(acl_entry_link->prevp->entryp);
4627 + SAFE_FREE(acl_entry_link->prevp);
4630 + SAFE_FREE(acl_entry_link->prevp->entryp);
4631 + SAFE_FREE(acl_entry_link->prevp);
4632 + SAFE_FREE(acl_entry_link->entryp);
4633 + SAFE_FREE(acl_entry_link);
4638 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4643 +#else /* No ACLs. */
4645 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4651 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4657 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4663 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4669 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4672 + return (SMB_ACL_T)NULL;
4675 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4678 + return (SMB_ACL_T)NULL;
4681 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4687 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4693 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4696 + return (permset & perm) ? 1 : 0;
4699 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4705 +int sys_acl_free_text(UNUSED(char *text))
4711 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4717 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4723 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4729 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4735 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4741 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4747 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4753 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4759 +int sys_acl_delete_def_file(UNUSED(const char *name))
4765 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4771 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4777 +#endif /* No ACLs. */
4779 +/************************************************************************
4780 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4782 +************************************************************************/
4784 +int no_acl_syscall_error(int err)
4786 +#if defined(ENOSYS)
4787 + if (err == ENOSYS) {
4791 +#if defined(ENOTSUP)
4792 + if (err == ENOTSUP) {
4798 --- old/lib/sysacls.h
4799 +++ new/lib/sysacls.h
4801 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4802 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4803 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4804 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4805 +#define slprintf snprintf
4807 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4808 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4809 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4810 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4811 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4812 +SMB_ACL_T sys_acl_get_fd(int fd);
4813 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4814 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4815 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4816 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4817 +SMB_ACL_T sys_acl_init(int count);
4818 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4819 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4820 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4821 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4822 +int sys_acl_valid(SMB_ACL_T theacl);
4823 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4824 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4825 +int sys_acl_delete_def_file(const char *name);
4826 +int sys_acl_free_text(char *text);
4827 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4828 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4831 @@ -58,7 +58,7 @@ BEGIN {
4835 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4836 +!/^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/ {
4842 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4844 int preserve_links = 0;
4845 int preserve_hard_links = 0;
4846 +int preserve_acls = 0;
4847 int preserve_perms = 0;
4848 int preserve_executability = 0;
4849 int preserve_devices = 0;
4850 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4851 char const *got_socketpair = "no ";
4852 char const *have_inplace = "no ";
4853 char const *hardlinks = "no ";
4854 + char const *acls = "no ";
4855 char const *links = "no ";
4856 char const *ipv6 = "no ";
4857 STRUCT_STAT *dumstat;
4858 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4862 +#ifdef SUPPORT_ACLS
4866 #ifdef SUPPORT_LINKS
4869 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4870 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4871 rprintf(f, "<http://rsync.samba.org/>\n");
4872 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4873 - "%shard links, %ssymlinks, batchfiles,\n",
4874 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4875 (int) (sizeof (OFF_T) * 8),
4876 - got_socketpair, hardlinks, links);
4877 + got_socketpair, hardlinks, acls, links);
4879 /* Note that this field may not have type ino_t. It depends
4880 * on the complicated interaction between largefile feature
4881 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4882 rprintf(F," -H, --hard-links preserve hard links\n");
4883 rprintf(F," -p, --perms preserve permissions\n");
4884 rprintf(F," -E, --executability preserve the file's executability\n");
4885 +#ifdef SUPPORT_ACLS
4886 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4888 rprintf(F," --chmod=CHMOD change destination permissions\n");
4889 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4890 rprintf(F," -g, --group preserve group\n");
4891 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4892 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4893 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4894 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4895 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4896 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4897 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4898 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4899 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4900 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4901 @@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
4906 +#ifdef SUPPORT_ACLS
4908 + preserve_perms = 1;
4911 + /* FIXME: this should probably be ignored with a
4912 + * warning and then countermeasures taken to
4913 + * restrict group and other access in the presence
4914 + * of any more restrictive ACLs, but this is safe
4916 + snprintf(err_buf,sizeof(err_buf),
4917 + "ACLs are not supported on this %s\n",
4918 + am_server ? "server" : "client");
4924 /* A large opt value means that set_refuse_options()
4925 * turned this option off. */
4926 @@ -1511,6 +1541,10 @@ void server_options(char **args,int *arg
4928 if (preserve_hard_links)
4930 +#ifdef SUPPORT_ACLS
4931 + if (preserve_acls)
4932 + argstr[x++] = 'A';
4939 @@ -46,6 +46,7 @@ extern int keep_partial;
4940 extern int checksum_seed;
4942 extern int delay_updates;
4943 +extern mode_t orig_umask;
4944 extern struct stats stats;
4945 extern char *log_format;
4946 extern char *tmpdir;
4947 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4948 int itemizing = am_daemon ? daemon_log_format_has_i
4949 : !am_server && log_format_has_i;
4950 int max_phase = protocol_version >= 29 ? 2 : 1;
4951 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4952 +#ifdef SUPPORT_ACLS
4953 + char *parent_dirname = "";
4958 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
4959 * mode based on the local permissions and some heuristics. */
4960 if (!preserve_perms) {
4961 int exists = fd1 != -1;
4962 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4963 +#ifdef SUPPORT_ACLS
4964 + char *dn = file->dirname ? file->dirname : ".";
4965 + if (parent_dirname != dn
4966 + && strcmp(parent_dirname, dn) != 0) {
4967 + dflt_perms = default_perms_for_dir(dn);
4968 + parent_dirname = dn;
4971 + file->mode = dest_mode(file->mode, st.st_mode,
4972 + dflt_perms, exists);
4975 /* We now check to see if we are writing file "inplace" */
4981 extern int daemon_log_format_has_i;
4982 +extern int preserve_acls;
4983 extern int preserve_perms;
4984 extern int preserve_executability;
4985 extern int preserve_times;
4986 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
4988 /* This is only called when we aren't preserving permissions. Figure out what
4989 * the permissions should be and return them merged back into the mode. */
4990 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4991 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
4994 /* If the file already exists, we'll return the local permissions,
4995 * possibly tweaked by the --executability option. */
4996 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4997 cur_mode |= (cur_mode & 0444) >> 2;
5000 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
5001 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5002 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5003 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5004 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5005 @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
5009 +#ifdef SUPPORT_ACLS
5010 + /* It's OK to call set_acl() now, even for a dir, as the generator
5011 + * will enable owner-writability using chmod, if necessary.
5013 + * If set_acl changes permission bits in the process of setting
5014 + * an access ACL, it changes st->st_mode so we know whether we
5015 + * need to chmod. */
5016 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5021 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5022 - int ret = do_chmod(fname, file->mode);
5023 + mode_t mode = file->mode;
5024 + int ret = do_chmod(fname, mode);
5026 rsyserr(FERROR, errno,
5027 "failed to set permissions on %s",
5030 @@ -658,6 +658,20 @@ struct chmod_mode_struct;
5032 #define UNUSED(x) x __attribute__((__unused__))
5034 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5035 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5036 +#define SUPPORT_ACLS 1
5039 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5040 +#define ACLS_NEED_MASK 1
5043 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5044 +#include <sys/acl.h>
5046 +#include "smb_acls.h"
5050 /* We have replacement versions of these if they're missing. */
5053 @@ -321,6 +321,7 @@ to the detailed description below for a
5054 -H, --hard-links preserve hard links
5055 -p, --perms preserve permissions
5056 -E, --executability preserve executability
5057 + -A, --acls preserve ACLs (implies -p) [non-standard]
5058 --chmod=CHMOD change destination permissions
5059 -o, --owner preserve owner (super-user only)
5060 -g, --group preserve group
5061 @@ -742,7 +743,9 @@ quote(itemize(
5062 permissions, though the bf(--executability) option might change just
5063 the execute permission for the file.
5064 it() New files get their "normal" permission bits set to the source
5065 - file's permissions masked with the receiving end's umask setting, and
5066 + file's permissions masked with the receiving directory's default
5067 + permissions (either the receiving process's umask, or the permissions
5068 + specified via the destination directory's default ACL), and
5069 their special permission bits disabled except in the case where a new
5070 directory inherits a setgid bit from its parent directory.
5072 @@ -773,9 +776,11 @@ The preservation of the destination's se
5073 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5074 versions erroneously preserved the three special permission bits for
5075 newly-created files when bf(--perms) was off, while overriding the
5076 -destination's setgid bit setting on a newly-created directory. (Keep in
5077 -mind that it is the version of the receiving rsync that affects this
5079 +destination's setgid bit setting on a newly-created directory. Default ACL
5080 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5081 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5082 +(Keep in mind that it is the version of the receiving rsync that affects
5085 dit(bf(-E, --executability)) This option causes rsync to preserve the
5086 executability (or non-executability) of regular files when bf(--perms) is
5087 @@ -793,6 +798,10 @@ quote(itemize(
5089 If bf(--perms) is enabled, this option is ignored.
5091 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5092 +ACLs to be the same as the source ACLs. This nonstandard option only
5093 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5095 dit(bf(--chmod)) This option tells rsync to apply one or more
5096 comma-separated "chmod" strings to the permission of the files in the
5097 transfer. The resulting value is treated as though it was the permissions
5102 + Unix SMB/Netbios implementation.
5104 + Portable SMB ACL interface
5105 + Copyright (C) Jeremy Allison 2000
5107 + This program is free software; you can redistribute it and/or modify
5108 + it under the terms of the GNU General Public License as published by
5109 + the Free Software Foundation; either version 2 of the License, or
5110 + (at your option) any later version.
5112 + This program is distributed in the hope that it will be useful,
5113 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5114 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5115 + GNU General Public License for more details.
5117 + You should have received a copy of the GNU General Public License
5118 + along with this program; if not, write to the Free Software
5119 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5122 +#ifndef _SMB_ACLS_H
5123 +#define _SMB_ACLS_H
5125 +#if defined HAVE_POSIX_ACLS
5127 +/* This is an identity mapping (just remove the SMB_). */
5129 +#define SMB_ACL_TAG_T acl_tag_t
5130 +#define SMB_ACL_TYPE_T acl_type_t
5131 +#define SMB_ACL_PERMSET_T acl_permset_t
5132 +#define SMB_ACL_PERM_T acl_perm_t
5133 +#define SMB_ACL_READ ACL_READ
5134 +#define SMB_ACL_WRITE ACL_WRITE
5135 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5137 +/* Types of ACLs. */
5138 +#define SMB_ACL_USER ACL_USER
5139 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5140 +#define SMB_ACL_GROUP ACL_GROUP
5141 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5142 +#define SMB_ACL_OTHER ACL_OTHER
5143 +#define SMB_ACL_MASK ACL_MASK
5145 +#define SMB_ACL_T acl_t
5147 +#define SMB_ACL_ENTRY_T acl_entry_t
5149 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5150 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5152 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5153 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5155 +#elif defined HAVE_TRU64_ACLS
5157 +/* This is for DEC/Compaq Tru64 UNIX */
5159 +#define SMB_ACL_TAG_T acl_tag_t
5160 +#define SMB_ACL_TYPE_T acl_type_t
5161 +#define SMB_ACL_PERMSET_T acl_permset_t
5162 +#define SMB_ACL_PERM_T acl_perm_t
5163 +#define SMB_ACL_READ ACL_READ
5164 +#define SMB_ACL_WRITE ACL_WRITE
5165 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5167 +/* Types of ACLs. */
5168 +#define SMB_ACL_USER ACL_USER
5169 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5170 +#define SMB_ACL_GROUP ACL_GROUP
5171 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5172 +#define SMB_ACL_OTHER ACL_OTHER
5173 +#define SMB_ACL_MASK ACL_MASK
5175 +#define SMB_ACL_T acl_t
5177 +#define SMB_ACL_ENTRY_T acl_entry_t
5179 +#define SMB_ACL_FIRST_ENTRY 0
5180 +#define SMB_ACL_NEXT_ENTRY 1
5182 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5183 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5185 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5187 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5188 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5191 +/* SVR4.2 ES/MP ACLs */
5192 +typedef int SMB_ACL_TAG_T;
5193 +typedef int SMB_ACL_TYPE_T;
5194 +typedef ushort *SMB_ACL_PERMSET_T;
5195 +typedef ushort SMB_ACL_PERM_T;
5196 +#define SMB_ACL_READ 4
5197 +#define SMB_ACL_WRITE 2
5198 +#define SMB_ACL_EXECUTE 1
5200 +/* Types of ACLs. */
5201 +#define SMB_ACL_USER USER
5202 +#define SMB_ACL_USER_OBJ USER_OBJ
5203 +#define SMB_ACL_GROUP GROUP
5204 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5205 +#define SMB_ACL_OTHER OTHER_OBJ
5206 +#define SMB_ACL_MASK CLASS_OBJ
5208 +typedef struct SMB_ACL_T {
5212 + struct acl acl[1];
5215 +typedef struct acl *SMB_ACL_ENTRY_T;
5217 +#define SMB_ACL_FIRST_ENTRY 0
5218 +#define SMB_ACL_NEXT_ENTRY 1
5220 +#define SMB_ACL_TYPE_ACCESS 0
5221 +#define SMB_ACL_TYPE_DEFAULT 1
5224 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5227 +#elif defined HAVE_HPUX_ACLS
5230 + * Based on the Solaris & UnixWare code.
5234 +#include <sys/aclv.h>
5236 +/* SVR4.2 ES/MP ACLs */
5237 +typedef int SMB_ACL_TAG_T;
5238 +typedef int SMB_ACL_TYPE_T;
5239 +typedef ushort *SMB_ACL_PERMSET_T;
5240 +typedef ushort SMB_ACL_PERM_T;
5241 +#define SMB_ACL_READ 4
5242 +#define SMB_ACL_WRITE 2
5243 +#define SMB_ACL_EXECUTE 1
5245 +/* Types of ACLs. */
5246 +#define SMB_ACL_USER USER
5247 +#define SMB_ACL_USER_OBJ USER_OBJ
5248 +#define SMB_ACL_GROUP GROUP
5249 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5250 +#define SMB_ACL_OTHER OTHER_OBJ
5251 +#define SMB_ACL_MASK CLASS_OBJ
5253 +typedef struct SMB_ACL_T {
5257 + struct acl acl[1];
5260 +typedef struct acl *SMB_ACL_ENTRY_T;
5262 +#define SMB_ACL_FIRST_ENTRY 0
5263 +#define SMB_ACL_NEXT_ENTRY 1
5265 +#define SMB_ACL_TYPE_ACCESS 0
5266 +#define SMB_ACL_TYPE_DEFAULT 1
5268 +#elif defined HAVE_IRIX_ACLS
5270 +#define SMB_ACL_TAG_T acl_tag_t
5271 +#define SMB_ACL_TYPE_T acl_type_t
5272 +#define SMB_ACL_PERMSET_T acl_permset_t
5273 +#define SMB_ACL_PERM_T acl_perm_t
5274 +#define SMB_ACL_READ ACL_READ
5275 +#define SMB_ACL_WRITE ACL_WRITE
5276 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5278 +/* Types of ACLs. */
5279 +#define SMB_ACL_USER ACL_USER
5280 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5281 +#define SMB_ACL_GROUP ACL_GROUP
5282 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5283 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5284 +#define SMB_ACL_MASK ACL_MASK
5286 +typedef struct SMB_ACL_T {
5292 +#define SMB_ACL_ENTRY_T acl_entry_t
5294 +#define SMB_ACL_FIRST_ENTRY 0
5295 +#define SMB_ACL_NEXT_ENTRY 1
5297 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5298 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5300 +#elif defined HAVE_AIX_ACLS
5302 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5304 +#include "/usr/include/acl.h"
5306 +typedef uint *SMB_ACL_PERMSET_T;
5308 +struct acl_entry_link{
5309 + struct acl_entry_link *prevp;
5310 + struct new_acl_entry *entryp;
5311 + struct acl_entry_link *nextp;
5315 +struct new_acl_entry{
5316 + unsigned short ace_len;
5317 + unsigned short ace_type;
5318 + unsigned int ace_access;
5319 + struct ace_id ace_id[1];
5322 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5323 +#define SMB_ACL_T struct acl_entry_link*
5325 +#define SMB_ACL_TAG_T unsigned short
5326 +#define SMB_ACL_TYPE_T int
5327 +#define SMB_ACL_PERM_T uint
5328 +#define SMB_ACL_READ S_IRUSR
5329 +#define SMB_ACL_WRITE S_IWUSR
5330 +#define SMB_ACL_EXECUTE S_IXUSR
5332 +/* Types of ACLs. */
5333 +#define SMB_ACL_USER ACEID_USER
5334 +#define SMB_ACL_USER_OBJ 3
5335 +#define SMB_ACL_GROUP ACEID_GROUP
5336 +#define SMB_ACL_GROUP_OBJ 4
5337 +#define SMB_ACL_OTHER 5
5338 +#define SMB_ACL_MASK 6
5341 +#define SMB_ACL_FIRST_ENTRY 1
5342 +#define SMB_ACL_NEXT_ENTRY 2
5344 +#define SMB_ACL_TYPE_ACCESS 0
5345 +#define SMB_ACL_TYPE_DEFAULT 1
5347 +#else /* No ACLs. */
5349 +/* No ACLS - fake it. */
5350 +#define SMB_ACL_TAG_T int
5351 +#define SMB_ACL_TYPE_T int
5352 +#define SMB_ACL_PERMSET_T mode_t
5353 +#define SMB_ACL_PERM_T mode_t
5354 +#define SMB_ACL_READ S_IRUSR
5355 +#define SMB_ACL_WRITE S_IWUSR
5356 +#define SMB_ACL_EXECUTE S_IXUSR
5358 +/* Types of ACLs. */
5359 +#define SMB_ACL_USER 0
5360 +#define SMB_ACL_USER_OBJ 1
5361 +#define SMB_ACL_GROUP 2
5362 +#define SMB_ACL_GROUP_OBJ 3
5363 +#define SMB_ACL_OTHER 4
5364 +#define SMB_ACL_MASK 5
5366 +typedef struct SMB_ACL_T {
5370 +typedef struct SMB_ACL_ENTRY_T {
5372 +} *SMB_ACL_ENTRY_T;
5374 +#define SMB_ACL_FIRST_ENTRY 0
5375 +#define SMB_ACL_NEXT_ENTRY 1
5377 +#define SMB_ACL_TYPE_ACCESS 0
5378 +#define SMB_ACL_TYPE_DEFAULT 1
5380 +#endif /* No ACLs. */
5381 +#endif /* _SMB_ACLS_H */
5382 --- old/testsuite/default-acls.test
5383 +++ new/testsuite/default-acls.test
5387 +# This program is distributable under the terms of the GNU GPL see
5390 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5392 +. $srcdir/testsuite/rsync.fns
5394 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5395 +case "$setfacl_nodef" in
5396 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5397 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5399 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5401 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5403 + todir="$scratchdir/$1"
5405 + $setfacl_nodef "$todir"
5407 + case "$setfacl_nodef" in
5408 + *-k*) opts="-dm $2" ;;
5409 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5411 + setfacl $opts "$todir"
5413 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5414 + # even though the directory itself is outside the transfer
5415 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5416 + check_perms "$todir/to" $4 "Target $1"
5417 + check_perms "$todir/to/dir" $4 "Target $1"
5418 + check_perms "$todir/to/file" $3 "Target $1"
5419 + check_perms "$todir/to/program" $4 "Target $1"
5420 + # Make sure get_local_name doesn't mess us up when transferring only one file
5421 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5422 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5423 + # Make sure we obey default ACLs when not transferring a regular file
5424 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5425 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5428 +mkdir "$scratchdir/dir"
5429 +echo "File!" >"$scratchdir/file"
5430 +echo "#!/bin/sh" >"$scratchdir/program"
5431 +chmod 777 "$scratchdir/dir"
5432 +chmod 666 "$scratchdir/file"
5433 +chmod 777 "$scratchdir/program"
5435 +# Test some target directories
5437 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5438 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5439 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5440 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5441 +testit noda1 '' rw------- rwx------
5443 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5445 +testit noda3 '' rw-r--r-- rwxr-xr-x
5453 extern int preserve_uid;
5454 extern int preserve_gid;
5455 +extern int preserve_acls;
5456 extern int numeric_ids;
5459 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5463 - if (preserve_uid) {
5464 + if (preserve_uid || preserve_acls) {
5466 /* we send sequences of uid/byte-length/name */
5467 for (list = uidlist; list; list = list->next) {
5468 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5472 - if (preserve_gid) {
5473 + if (preserve_gid || preserve_acls) {
5475 for (list = gidlist; list; list = list->next) {
5477 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5481 - if (preserve_uid && !numeric_ids) {
5482 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5483 /* read the uid list */
5484 while ((id = read_int(f)) != 0) {
5485 int len = read_byte(f);
5486 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5490 - if (preserve_gid && !numeric_ids) {
5491 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5492 /* read the gid list */
5493 while ((id = read_int(f)) != 0) {
5494 int len = read_byte(f);
5495 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5499 +#ifdef SUPPORT_ACLS
5500 + if (preserve_acls && !numeric_ids) {
5502 + while ((id = next_acl_uid(flist)) != NULL)
5503 + *id = match_uid(*id);
5504 + while ((id = next_acl_gid(flist)) != NULL)
5505 + *id = match_gid(*id);
5509 /* Now convert all the uids/gids from sender values to our values. */
5510 if (am_root && preserve_uid && !numeric_ids) {
5511 for (i = 0; i < flist->count; i++)