1 After applying this patch, run these commands for a successful build:
4 ./configure --enable-acl-support
7 This code does not yet itemize changes in ACL information (see --itemize),
8 and it has a bug where some user/group ACL changes might not be propagated
9 from the sender to the receiver if the receiver already has a version of
10 the file that does not need any other attribute updates.
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;
79 +#define NO_ENTRY ((uchar)0x80)
83 + /* These will be NO_ENTRY if there's no such entry. */
90 +static const rsync_acl rsync_acl_initializer =
91 + { {0, 0, NULL}, {0, 0, NULL}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY};
93 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
94 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
96 +/* a few useful calculations */
98 +static int rsync_acl_count_entries(const rsync_acl *racl) {
99 + return racl->users.count + racl->groups.count
100 + + (racl->user_obj != NO_ENTRY)
101 + + (racl->group_obj != NO_ENTRY)
102 + + (racl->mask != NO_ENTRY)
103 + + (racl->other != NO_ENTRY);
106 +static int rsync_acl_get_perms(const rsync_acl *racl) {
107 + /* Note that (NO_ENTRY & 7) is 0. */
108 + return ((racl->user_obj & 7) << 6)
109 + + (((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
110 + + (racl->other & 7);
113 +static void rsync_acl_strip_perms(rsync_acl *racl) {
114 + racl->user_obj = NO_ENTRY;
115 + if (racl->mask == NO_ENTRY)
116 + racl->group_obj = NO_ENTRY;
118 + racl->mask = NO_ENTRY;
119 + racl->other = NO_ENTRY;
122 +static void expand_ida_list(ida_list *idal)
124 + /* First time through, 0 <= 0, so list is expanded. */
125 + if (idal->malloced <= idal->count) {
126 + id_access *new_ptr;
127 + size_t new_size = idal->malloced + 10;
128 + new_ptr = realloc_array(idal->idas, id_access, new_size);
129 + if (verbose >= 4) {
130 + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
131 + (double) new_size * sizeof idal->idas[0],
132 + idal->idas ? "" : " not");
135 + idal->idas = new_ptr;
136 + idal->malloced = new_size;
139 + out_of_memory("expand_ida_list");
143 +static void ida_list_free(ida_list *idal)
148 + idal->malloced = 0;
151 +static void rsync_acl_free(rsync_acl *racl)
153 + ida_list_free(&racl->users);
154 + ida_list_free(&racl->groups);
157 +static int id_access_sorter(const void *r1, const void *r2)
159 + id_access *ida1 = (id_access *)r1;
160 + id_access *ida2 = (id_access *)r2;
161 + id_t rid1 = ida1->id, rid2 = ida2->id;
162 + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
165 +static void sort_ida_list(ida_list *idal)
169 + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0],
170 + &id_access_sorter);
173 +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
175 + SMB_ACL_ENTRY_T entry;
176 + const char *errfun;
179 + *racl = rsync_acl_initializer;
180 + errfun = "sys_acl_get_entry";
181 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
183 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
184 + SMB_ACL_TAG_T tag_type;
185 + SMB_ACL_PERMSET_T permset;
190 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
191 + errfun = "sys_acl_get_tag_type";
194 + if ((rc = sys_acl_get_permset(entry, &permset))) {
195 + errfun = "sys_acl_get_tag_type";
198 + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
199 + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
200 + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
201 + /* continue == done with entry; break == store in given idal */
202 + switch (tag_type) {
203 + case SMB_ACL_USER_OBJ:
204 + if (racl->user_obj == NO_ENTRY)
205 + racl->user_obj = access;
207 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
210 + idal = &racl->users;
212 + case SMB_ACL_GROUP_OBJ:
213 + if (racl->group_obj == NO_ENTRY)
214 + racl->group_obj = access;
216 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
218 + case SMB_ACL_GROUP:
219 + idal = &racl->groups;
222 + if (racl->mask == NO_ENTRY)
223 + racl->mask = access;
225 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
227 + case SMB_ACL_OTHER:
228 + if (racl->other == NO_ENTRY)
229 + racl->other = access;
231 + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
234 + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
237 + if (!(qualifier = sys_acl_get_qualifier(entry))) {
238 + errfun = "sys_acl_get_tag_type";
242 + expand_ida_list(idal);
243 + ida = &idal->idas[idal->count++];
244 + ida->id = *((id_t *)qualifier);
245 + ida->access = access;
246 + sys_acl_free_qualifier(qualifier, tag_type);
249 + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
250 + errfun, strerror(errno));
251 + rsync_acl_free(racl);
255 + sort_ida_list(&racl->users);
256 + sort_ida_list(&racl->groups);
261 +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2)
263 + id_access *ida1, *ida2;
264 + size_t count = ial1->count;
265 + if (count != ial2->count)
269 + for (; count--; ida1++, ida2++) {
270 + if (ida1->access != ida2->access || ida1->id != ida2->id)
276 +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
278 + return (racl1->user_obj == racl2->user_obj
279 + && racl1->group_obj == racl2->group_obj
280 + && racl1->mask == racl2->mask
281 + && racl1->other == racl2->other
282 + && ida_lists_equal(&racl1->users, &racl2->users)
283 + && ida_lists_equal(&racl1->groups, &racl2->groups));
286 +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1, const rsync_acl *racl2)
288 + /* We ignore any differences that chmod() can take care of. */
289 + if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
291 + if (racl1->mask != NO_ENTRY && racl1->group_obj != racl2->group_obj)
293 + return ida_lists_equal(&racl1->users, &racl2->users)
294 + && ida_lists_equal(&racl1->groups, &racl2->groups);
303 +static rsync_acl_list _rsync_acl_lists[] = {
304 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
305 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
308 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
310 + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
311 + : &_rsync_acl_lists[1];
314 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
316 + /* First time through, 0 <= 0, so list is expanded. */
317 + if (racl_list->malloced <= racl_list->count) {
318 + rsync_acl *new_ptr;
320 + if (racl_list->malloced < 1000)
321 + new_size = racl_list->malloced + 1000;
323 + new_size = racl_list->malloced * 2;
324 + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
325 + if (verbose >= 3) {
326 + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
327 + (double) new_size * sizeof racl_list->racls[0],
328 + racl_list->racls ? "" : " not");
331 + racl_list->racls = new_ptr;
332 + racl_list->malloced = new_size;
334 + if (!racl_list->racls)
335 + out_of_memory("expand_rsync_acl_list");
339 +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
340 + const rsync_acl_list *racl_list,
341 + const rsync_acl *racl)
343 + static int access_match = -1, default_match = -1;
344 + int *match = (type == SMB_ACL_TYPE_ACCESS) ?
345 + &access_match : &default_match;
346 + size_t count = racl_list->count;
347 + /* If this is the first time through or we didn't match the last
348 + * time, then start at the end of the list, which should be the
349 + * best place to start hunting. */
351 + *match = racl_list->count - 1;
353 + if (rsync_acls_equal(&racl_list->racls[*match], racl))
356 + *match = racl_list->count - 1;
362 +/* The general strategy with the tag_type <-> character mapping is that
363 + * lowercase implies that no qualifier follows, where uppercase does.
364 + * A similar idiom for the acl type (access or default) itself, but
365 + * lowercase in this instance means there's no ACL following, so the
366 + * ACL is a repeat, so the receiver should reuse the last of the same
368 +static void send_ida_list(int f, const ida_list *idal, uchar tag_char)
371 + size_t count = idal->count;
372 + for (ida = idal->idas; count--; ida++) {
373 + write_byte(f, tag_char);
374 + write_byte(f, ida->access);
375 + write_int(f, ida->id);
376 + /* FIXME: sorta wasteful: we should maybe buffer as
377 + * many ids as max(ACL_USER + ACL_GROUP) objects to
378 + * keep from making so many calls. */
379 + if (tag_char == 'U')
386 +static void send_rsync_acl(int f, const rsync_acl *racl)
388 + size_t count = rsync_acl_count_entries(racl);
389 + write_int(f, count);
390 + if (racl->user_obj != NO_ENTRY) {
391 + write_byte(f, 'u');
392 + write_byte(f, racl->user_obj);
394 + send_ida_list(f, &racl->users, 'U');
395 + if (racl->group_obj != NO_ENTRY) {
396 + write_byte(f, 'g');
397 + write_byte(f, racl->group_obj);
399 + send_ida_list(f, &racl->groups, 'G');
400 + if (racl->mask != NO_ENTRY) {
401 + write_byte(f, 'm');
402 + write_byte(f, racl->mask);
404 + if (racl->other != NO_ENTRY) {
405 + write_byte(f, 'o');
406 + write_byte(f, racl->other);
410 +static rsync_acl _curr_rsync_acls[2];
412 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
414 + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
415 + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
416 + "unknown SMB_ACL_TYPE_T";
419 +/* Generate the ACL(s) for this flist entry;
420 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
421 +int make_acl(const struct file_struct *file, const char *fname)
423 + SMB_ACL_TYPE_T type;
424 + rsync_acl *curr_racl;
426 + if (S_ISLNK(file->mode))
429 + curr_racl = &_curr_rsync_acls[0];
430 + type = SMB_ACL_TYPE_ACCESS;
434 + if ((sacl = sys_acl_get_file(fname, type)) != 0) {
435 + ok = unpack_smb_acl(curr_racl, sacl);
436 + sys_acl_free_acl(sacl);
439 + /* Strip access ACLs of permission-bit entries. */
440 + if (type == SMB_ACL_TYPE_ACCESS)
441 + rsync_acl_strip_perms(curr_racl);
442 + } else if (errno == ENOTSUP) {
443 + /* ACLs are not supported. Leave list empty. */
444 + *curr_racl = rsync_acl_initializer;
446 + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
447 + fname, str_acl_type(type), strerror(errno));
451 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
456 +/* Send the make_acl()-generated ACLs for this flist entry,
457 + * or clean up after an flist entry that's not being sent (f == -1). */
458 +void send_acl(const struct file_struct *file, int f)
460 + SMB_ACL_TYPE_T type;
461 + rsync_acl *curr_racl;
463 + if (S_ISLNK(file->mode))
466 + curr_racl = &_curr_rsync_acls[0];
467 + type = SMB_ACL_TYPE_ACCESS;
470 + rsync_acl_list *racl_list = rsync_acl_lists(type);
472 + rsync_acl_free(curr_racl);
475 + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl))
477 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
478 + write_int(f, index);
479 + rsync_acl_free(curr_racl);
481 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
482 + send_rsync_acl(f, curr_racl);
483 + expand_rsync_acl_list(racl_list);
484 + racl_list->racls[racl_list->count++] = *curr_racl;
487 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
490 +/* The below stuff is only used by the receiver: */
492 +/* structure to hold index to rsync_acl_list member corresponding to
493 + * flist->files[i] */
496 + const struct file_struct *file;
503 + file_acl_index *fileaclidxs;
504 +} file_acl_index_list;
506 +static file_acl_index_list _file_acl_index_lists[] = {
507 + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
508 + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
511 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
513 + return type == SMB_ACL_TYPE_ACCESS ?
514 + &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
517 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
519 + /* First time through, 0 <= 0, so list is expanded. */
520 + if (fileaclidx_list->malloced <= fileaclidx_list->count) {
521 + file_acl_index *new_ptr;
523 + if (fileaclidx_list->malloced < 1000)
524 + new_size = fileaclidx_list->malloced + 1000;
526 + new_size = fileaclidx_list->malloced * 2;
527 + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
528 + if (verbose >= 3) {
529 + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
530 + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
531 + fileaclidx_list->fileaclidxs ? "" : " not");
534 + fileaclidx_list->fileaclidxs = new_ptr;
535 + fileaclidx_list->malloced = new_size;
537 + if (!fileaclidx_list->fileaclidxs)
538 + out_of_memory("expand_file_acl_index_list");
542 +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
550 +static smb_acl_list _smb_acl_lists[] = {
551 + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
552 + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
555 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
557 + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
558 + &_smb_acl_lists[1];
561 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
563 + /* First time through, 0 <= 0, so list is expanded. */
564 + if (sacl_list->malloced <= sacl_list->count) {
565 + SMB_ACL_T *new_ptr;
567 + if (sacl_list->malloced < 1000)
568 + new_size = sacl_list->malloced + 1000;
570 + new_size = sacl_list->malloced * 2;
571 + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
572 + if (verbose >= 3) {
573 + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
574 + (double) new_size * sizeof sacl_list->sacls[0],
575 + sacl_list->sacls ? "" : " not");
578 + sacl_list->sacls = new_ptr;
579 + sacl_list->malloced = new_size;
581 + if (!sacl_list->sacls)
582 + out_of_memory("expand_smb_acl_list");
586 +#define COE(func,args) /* call or error */ \
594 +static BOOL store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
596 + const char *errfun = NULL;
597 + SMB_ACL_PERMSET_T permset;
599 + COE( sys_acl_get_permset,(entry, &permset) );
600 + COE( sys_acl_clear_perms,(permset) );
602 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
604 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
606 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
607 + COE( sys_acl_set_permset,(entry, permset) );
612 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
617 +/* build an SMB_ACL_T corresponding to an rsync_acl */
618 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
622 + const char *errfun = NULL;
623 + SMB_ACL_ENTRY_T entry;
625 + if (!(*smb_acl = sys_acl_init(rsync_acl_count_entries(racl)))) {
626 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
631 + COE( sys_acl_create_entry,(smb_acl, &entry) );
632 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
633 + if (!store_access_in_entry(racl->user_obj, entry))
636 + for (ida = racl->users.idas, count = racl->users.count;
638 + COE( sys_acl_create_entry,(smb_acl, &entry) );
639 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
640 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
641 + if (!store_access_in_entry(ida->access, entry))
645 + COE( sys_acl_create_entry,(smb_acl, &entry) );
646 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
647 + if (!store_access_in_entry(racl->group_obj, entry))
650 + for (ida = racl->groups.idas, count = racl->groups.count;
652 + COE( sys_acl_create_entry,(smb_acl, &entry) );
653 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) );
654 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
655 + if (!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 + if (!store_access_in_entry(racl->mask, entry))
665 + COE( sys_acl_create_entry,(smb_acl, &entry) );
666 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
667 + if (!store_access_in_entry(racl->other, entry))
671 + if (sys_acl_valid(*smb_acl) < 0)
672 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
678 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
681 + sys_acl_free_acl(*smb_acl);
685 +static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode)
687 + SMB_ACL_ENTRY_T entry;
688 + int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ;
689 + const char *errfun;
692 + if (S_ISDIR(mode)) {
693 + /* If the sticky bit is going on, it's not safe to allow all
694 + * the new ACLs to go into effect before it gets set. */
695 + if (!(old_mode & S_ISVTX) && mode & S_ISVTX)
698 + /* If setuid or setgid is going off, it's not safe to allow all
699 + * the new ACLs to go into effect before they get cleared. */
700 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
701 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
705 + errfun = "sys_acl_get_entry";
706 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
708 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
709 + SMB_ACL_TAG_T tag_type;
710 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
711 + errfun = "sys_acl_get_tag_type";
714 + if (tag_type == SMB_ACL_USER_OBJ)
715 + store_access_in_entry((mode >> 6) & 7, entry);
716 + else if (tag_type == group_id)
717 + store_access_in_entry((mode >> 3) & 7, entry);
718 + else if (tag_type == SMB_ACL_OTHER)
719 + store_access_in_entry(mode & 7, entry);
722 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
723 + errfun, strerror(errno));
726 + /* return the mode of the file on disk, as we set them */
727 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
730 +static void receive_rsync_acl(rsync_acl *racl, int f)
732 + uchar computed_mask_bits = 0;
733 + ida_list *idal = NULL;
737 + *racl = rsync_acl_initializer;
739 + if (!(count = read_int(f)))
743 + uchar tag = read_byte(f);
744 + uchar access = read_byte(f);
745 + if (access & ~ (4 | 2 | 1)) {
746 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
748 + exit_cleanup(RERR_STREAMIO);
752 + if (racl->user_obj != NO_ENTRY) {
753 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
754 + exit_cleanup(RERR_STREAMIO);
756 + racl->user_obj = access;
759 + idal = &racl->users;
762 + if (racl->group_obj != NO_ENTRY) {
763 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
764 + exit_cleanup(RERR_STREAMIO);
766 + racl->group_obj = access;
769 + idal = &racl->groups;
772 + if (racl->mask != NO_ENTRY) {
773 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
774 + exit_cleanup(RERR_STREAMIO);
776 + racl->mask = access;
779 + if (racl->other != NO_ENTRY) {
780 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
781 + exit_cleanup(RERR_STREAMIO);
783 + racl->other = access;
786 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
788 + exit_cleanup(RERR_STREAMIO);
790 + expand_ida_list(idal);
791 + ida = &idal->idas[idal->count++];
792 + ida->access = access;
793 + ida->id = read_int(f);
794 + computed_mask_bits |= access;
797 + /* Ensure that these are never unset. */
798 + if (racl->user_obj == NO_ENTRY)
799 + racl->user_obj = 7;
800 + if (racl->group_obj == NO_ENTRY)
801 + racl->group_obj = 0;
802 + if (racl->other == NO_ENTRY)
804 +#ifndef ACLS_NEED_MASK
805 + if (!racl->users.count && !racl->groups.count) {
806 + /* If we, a system without ACLS_NEED_MASK, received a
807 + * superfluous mask, throw it away. */
808 + if (racl->mask != NO_ENTRY) {
809 + /* mask off group perms with it first */
810 + racl->group_obj &= racl->mask;
811 + racl->mask = NO_ENTRY;
815 + if (racl->mask == NO_ENTRY)
816 + racl->mask = computed_mask_bits | racl->group_obj;
819 +/* receive and build the rsync_acl_lists */
820 +void receive_acl(struct file_struct *file, int f)
822 + SMB_ACL_TYPE_T type;
825 + if (S_ISLNK(file->mode))
828 + fname = f_name(file, NULL);
829 + type = SMB_ACL_TYPE_ACCESS;
831 + file_acl_index_list *fileaclidx_list =
832 + file_acl_index_lists(type);
834 + expand_file_acl_index_list(fileaclidx_list);
836 + tag = read_byte(f);
837 + if (tag == 'A' || tag == 'a') {
838 + if (type != SMB_ACL_TYPE_ACCESS) {
839 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
841 + exit_cleanup(RERR_STREAMIO);
843 + } else if (tag == 'D' || tag == 'd') {
844 + if (type == SMB_ACL_TYPE_ACCESS) {
845 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
847 + exit_cleanup(RERR_STREAMIO);
850 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
852 + exit_cleanup(RERR_STREAMIO);
854 + if (tag == 'A' || tag == 'D') {
856 + rsync_acl_list *racl_list = rsync_acl_lists(type);
857 + smb_acl_list *sacl_list = smb_acl_lists(type);
858 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
859 + aclidx = racl_list->count;
860 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
862 + receive_rsync_acl(&racl, f);
863 + expand_rsync_acl_list(racl_list);
864 + racl_list->racls[racl_list->count++] = racl;
865 + expand_smb_acl_list(sacl_list);
866 + sacl_list->sacls[sacl_list->count++] = NULL;
868 + int index = read_int(f);
869 + rsync_acl_list *racl_list = rsync_acl_lists(type);
870 + if ((size_t) index >= racl_list->count) {
871 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
873 + str_acl_type(type),
875 + exit_cleanup(RERR_STREAMIO);
877 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
879 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
882 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
885 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
887 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
888 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
889 + return fileaclidx1->file == fileaclidx2->file ? 0 :
890 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
893 +void sort_file_acl_index_lists()
895 + SMB_ACL_TYPE_T type;
897 + type = SMB_ACL_TYPE_ACCESS;
899 + file_acl_index_list *fileaclidx_list =
900 + file_acl_index_lists(type);
901 + if (!fileaclidx_list->count)
903 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
904 + sizeof fileaclidx_list->fileaclidxs[0],
905 + &file_acl_index_list_sorter);
906 + } while (BUMP_TYPE(type));
909 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
910 + const struct file_struct *file) {
911 + int low = 0, high = fileaclidx_list->count;
912 + const struct file_struct *file_mid;
916 + int mid = (high + low) / 2;
917 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
918 + if (file_mid == file)
919 + return fileaclidx_list->fileaclidxs[mid].aclidx;
920 + if (file_mid > file)
924 + } while (low < high);
926 + file_mid = fileaclidx_list->fileaclidxs[low].file;
927 + if (file_mid == file)
928 + return fileaclidx_list->fileaclidxs[low].aclidx;
931 + "find_file_acl_index: can't find entry for file in list\n");
932 + exit_cleanup(RERR_STREAMIO);
936 +/* for duplicating ACLs on backups when using backup_dir */
937 +int dup_acl(const char *orig, const char *bak, mode_t mode)
939 + SMB_ACL_TYPE_T type;
942 + type = SMB_ACL_TYPE_ACCESS;
944 + SMB_ACL_T sacl_orig, sacl_bak;
945 + rsync_acl racl_orig, racl_bak;
946 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
947 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
948 + orig, str_acl_type(type), strerror(errno));
952 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
953 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
954 + bak, str_acl_type(type), strerror(errno));
956 + /* try to forge on through */
958 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
960 + goto out_with_sacls;
963 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
965 + goto out_with_one_racl;
967 + if (rsync_acls_equal(&racl_orig, &racl_bak))
970 + ; /* presume they're unequal */
972 + if (type == SMB_ACL_TYPE_DEFAULT
973 + && rsync_acl_count_entries(&racl_orig) == 0) {
974 + if (sys_acl_delete_def_file(bak) < 0) {
975 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
976 + bak, strerror(errno));
979 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
980 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
981 + bak, str_acl_type(type), strerror(errno));
986 + rsync_acl_free(&racl_bak);
988 + rsync_acl_free(&racl_orig);
991 + sys_acl_free_acl(sacl_bak);
992 + /* out_with_one_sacl: */
994 + sys_acl_free_acl(sacl_orig);
995 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1000 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1001 + * for keep_backup(). */
1002 +static const struct file_struct *backup_orig_file = NULL;
1003 +static const char null_string[] = "";
1004 +static const char *backup_orig_fname = null_string;
1005 +static const char *backup_dest_fname = null_string;
1006 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1008 +void push_keep_backup_acl(const struct file_struct *file,
1009 + const char *orig, const char *dest)
1011 + SMB_ACL_TYPE_T type;
1014 + backup_orig_file = file;
1015 + backup_orig_fname = orig;
1016 + backup_dest_fname = dest;
1018 + sacl = &_backup_sacl[0];
1019 + type = SMB_ACL_TYPE_ACCESS;
1021 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1025 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1027 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1028 + orig, str_acl_type(type),
1031 + } while (BUMP_TYPE(type));
1034 +static int set_keep_backup_acl()
1036 + SMB_ACL_TYPE_T type;
1040 + sacl = &_backup_sacl[0];
1041 + type = SMB_ACL_TYPE_ACCESS;
1044 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1046 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1047 + backup_dest_fname,
1048 + str_acl_type(type),
1052 + } while (BUMP_TYPE(type));
1057 +void cleanup_keep_backup_acl()
1059 + SMB_ACL_TYPE_T type;
1062 + backup_orig_file = NULL;
1063 + backup_orig_fname = null_string;
1064 + backup_dest_fname = null_string;
1066 + sacl = &_backup_sacl[0];
1067 + type = SMB_ACL_TYPE_ACCESS;
1070 + sys_acl_free_acl(*sacl);
1073 + } while (BUMP_TYPE(type));
1076 +/* set ACL on rsync-ed or keep_backup-ed file
1078 + * This sets extended access ACL entries and default ACLs. If convenient,
1079 + * it sets permission bits along with the access ACLs and signals having
1080 + * done so by modifying p_mode, which should point into the stat buffer.
1082 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1083 + * Pass NULL for p_mode to get the return code without changing anything. */
1084 +int set_acl(const char *fname, const struct file_struct *file, mode_t *p_mode)
1086 + int unchanged = 1;
1087 + SMB_ACL_TYPE_T type;
1089 + if (S_ISLNK(file->mode))
1092 + if (file == backup_orig_file) {
1093 + if (!strcmp(fname, backup_dest_fname))
1094 + return set_keep_backup_acl();
1096 + type = SMB_ACL_TYPE_ACCESS;
1099 + SMB_ACL_T sacl_orig, *sacl_new;
1100 + rsync_acl racl_orig, *racl_new;
1101 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1103 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1104 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1105 + sacl_orig = sys_acl_get_file(fname, type);
1107 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1108 + fname, str_acl_type(type), strerror(errno));
1112 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1113 + sys_acl_free_acl(sacl_orig);
1118 + if (type == SMB_ACL_TYPE_ACCESS)
1119 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new);
1121 + ok = rsync_acls_equal(&racl_orig, racl_new);
1122 + rsync_acl_free(&racl_orig);
1125 + if (!dry_run && p_mode) {
1126 + if (type == SMB_ACL_TYPE_DEFAULT
1127 + && rsync_acl_count_entries(racl_new) == 0) {
1128 + if (sys_acl_delete_def_file(fname) < 0) {
1129 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1130 + fname, strerror(errno));
1135 + mode_t cur_mode = *p_mode;
1137 + && !pack_smb_acl(sacl_new, racl_new)) {
1141 + if (type == SMB_ACL_TYPE_ACCESS) {
1142 + cur_mode = change_sacl_perms(*sacl_new, racl_new->mask,
1143 + cur_mode, file->mode);
1145 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1146 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1147 + fname, str_acl_type(type),
1152 + if (type == SMB_ACL_TYPE_ACCESS)
1153 + *p_mode = cur_mode;
1156 + if (unchanged == 1)
1158 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1163 +/* Enumeration functions for uid mapping: */
1165 +/* Context -- one and only one. Should be cycled through once on uid
1166 + * mapping and once on gid mapping. */
1167 +static rsync_acl_list *_enum_racl_lists[] = {
1168 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1171 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1172 +static size_t enum_racl_index = 0;
1173 +static size_t enum_ida_index = 0;
1175 +/* This returns the next tag_type id from the given acl for the next entry,
1176 + * or it returns 0 if there are no more tag_type ids in the acl. */
1177 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1179 + const ida_list *idal = (tag_type == SMB_ACL_USER ?
1180 + &racl->users : &racl->groups);
1181 + if (enum_ida_index < idal->count) {
1182 + id_access *ida = &idal->idas[enum_ida_index++];
1185 + enum_ida_index = 0;
1189 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1191 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1192 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1193 + id_t *id = next_ace_id(tag_type, racl);
1197 + enum_racl_index = 0;
1201 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1203 + for (; *enum_racl_list; enum_racl_list++) {
1204 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1208 + enum_racl_list = &_enum_racl_lists[0];
1212 +id_t *next_acl_uid()
1214 + return next_acl_list_id(SMB_ACL_USER);
1217 +id_t *next_acl_gid()
1219 + return next_acl_list_id(SMB_ACL_GROUP);
1222 +int default_perms_for_dir(const char *dir)
1231 + perms = ACCESSPERMS & ~orig_umask;
1232 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1233 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1234 + if (sacl == NULL) {
1235 + /* Couldn't get an ACL. Darn. */
1238 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1242 + /* We're doing a dry run, so the containing directory
1243 + * wasn't actually created. Don't worry about it. */
1246 + /* Otherwise fall through. */
1248 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1249 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1255 + ok = unpack_smb_acl(&racl, sacl);
1256 + sys_acl_free_acl(sacl);
1258 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1262 + /* Apply the permission-bit entries of the default ACL, if any. */
1263 + if (rsync_acl_count_entries(&racl) > 0) {
1264 + perms = rsync_acl_get_perms(&racl);
1266 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1269 + rsync_acl_free(&racl);
1273 +#endif /* SUPPORT_ACLS */
1276 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1277 extern char *backup_dir;
1280 +extern int preserve_acls;
1281 extern int preserve_devices;
1282 extern int preserve_specials;
1283 extern int preserve_links;
1284 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1286 do_lchown(fullpath, st.st_uid, st.st_gid);
1287 do_chmod(fullpath, st.st_mode);
1288 +#ifdef SUPPORT_ACLS
1289 + if (preserve_acls)
1290 + dup_acl(end, fullpath, st.st_mode);
1295 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1296 if (!(buf = get_backup_name(fname)))
1299 +#ifdef SUPPORT_ACLS
1300 + if (preserve_acls)
1301 + push_keep_backup_acl(file, fname, buf);
1304 /* Check to see if this is a device file, or link */
1305 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1306 || (preserve_specials && IS_SPECIAL(file->mode))) {
1307 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1310 set_file_attrs(buf, file, NULL, 0);
1311 +#ifdef SUPPORT_ACLS
1312 + if (preserve_acls)
1313 + cleanup_keep_backup_acl();
1318 --- old/configure.in
1319 +++ new/configure.in
1320 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1321 AC_CHECK_LIB(resolv, strcasecmp)
1324 +AC_CHECK_FUNCS(aclsort)
1325 +if test x"$ac_cv_func_aclsort" = x"no"; then
1326 + AC_CHECK_LIB(sec, aclsort)
1329 dnl At the moment we don't test for a broken memcmp(), because all we
1330 dnl need to do is test for equality, not comparison, and it seems that
1331 dnl every platform has a memcmp that can do at least that.
1332 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1333 AC_SUBST(CC_SHOBJ_FLAG)
1334 AC_SUBST(BUILD_POPT)
1336 +AC_CHECK_HEADERS(sys/acl.h)
1337 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1338 +#################################################
1339 +# check for ACL support
1341 +AC_MSG_CHECKING(whether to support ACLs)
1342 +AC_ARG_ENABLE(acl-support,
1343 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1344 +[ case "$enableval" in
1347 + case "$host_os" in
1349 + AC_MSG_RESULT(Using UnixWare ACLs)
1350 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1353 + AC_MSG_RESULT(Using solaris ACLs)
1354 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1357 + AC_MSG_RESULT(Using HPUX ACLs)
1358 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1361 + AC_MSG_RESULT(Using IRIX ACLs)
1362 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1365 + AC_MSG_RESULT(Using AIX ACLs)
1366 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1369 + AC_MSG_RESULT(Using Tru64 ACLs)
1370 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1371 + LIBS="$LIBS -lpacl"
1374 + AC_MSG_RESULT(ACLs requested -- running tests)
1375 + AC_CHECK_LIB(acl,acl_get_file)
1376 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1377 + AC_TRY_LINK([#include <sys/types.h>
1378 +#include <sys/acl.h>],
1379 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1380 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1381 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1382 + AC_MSG_RESULT(Using posix ACLs)
1383 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1384 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1385 + AC_TRY_LINK([#include <sys/types.h>
1386 +#include <sys/acl.h>],
1387 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1388 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1389 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1390 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1393 + AC_MSG_ERROR(Failed to find ACL support)
1400 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1403 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1407 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1412 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1413 extern int one_file_system;
1414 extern int copy_dirlinks;
1415 extern int keep_dirlinks;
1416 +extern int preserve_acls;
1417 extern int preserve_links;
1418 extern int preserve_hard_links;
1419 extern int preserve_devices;
1420 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1421 if (chmod_modes && !S_ISLNK(file->mode))
1422 file->mode = tweak_mode(file->mode, chmod_modes);
1424 +#ifdef SUPPORT_ACLS
1425 + if (preserve_acls && make_acl(file, fname) < 0)
1429 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1431 flist_expand(flist);
1432 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1433 if (file->basename[0]) {
1434 flist->files[flist->count++] = file;
1435 send_file_entry(file, f);
1436 +#ifdef SUPPORT_ACLS
1437 + if (preserve_acls)
1438 + send_acl(file, f);
1441 +#ifdef SUPPORT_ACLS
1442 + /* Cleanup unsent ACL(s). */
1443 + if (preserve_acls)
1444 + send_acl(file, -1);
1449 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1450 flags |= read_byte(f) << 8;
1451 file = receive_file_entry(flist, flags, f);
1453 +#ifdef SUPPORT_ACLS
1454 + if (preserve_acls)
1455 + receive_acl(file, f);
1458 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1459 stats.total_size += file->length;
1461 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1463 clean_flist(flist, relative_paths, 1);
1465 +#ifdef SUPPORT_ACLS
1466 + if (preserve_acls)
1467 + sort_file_acl_index_lists();
1471 recv_uid_list(f, flist);
1475 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1476 extern int max_delete;
1477 extern int force_delete;
1478 extern int one_file_system;
1479 +extern mode_t orig_umask;
1480 extern struct stats stats;
1481 extern dev_t filesystem_dev;
1482 extern char *backup_dir;
1483 @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l
1485 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1487 + /* FIXME: Flag ACL changes. */
1490 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1492 @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i
1493 if (preserve_gid && file->gid != GID_NONE
1494 && st->st_gid != file->gid)
1495 iflags |= ITEM_REPORT_GROUP;
1496 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1498 iflags |= ITEM_IS_NEW;
1500 @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str
1503 static int phase = 0;
1504 +static int dflt_perms;
1506 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1507 * make sure it exists, and has the right permissions/timestamp info. For
1508 @@ -844,6 +849,10 @@ static void recv_generator(char *fname,
1511 need_fuzzy_dirlist = 1;
1512 +#ifdef SUPPORT_ACLS
1513 + if (!preserve_perms)
1514 + dflt_perms = default_perms_for_dir(dn);
1517 parent_dirname = dn;
1519 @@ -871,7 +880,8 @@ static void recv_generator(char *fname,
1520 if (!preserve_perms) {
1521 int exists = statret == 0
1522 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1523 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1524 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1528 if (S_ISDIR(file->mode)) {
1529 @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi
1530 * notice that and let us know via the redo pipe (or its closing). */
1533 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1535 for (i = 0; i < flist->count; i++) {
1536 struct file_struct *file = flist->files[i];
1538 --- old/lib/sysacls.c
1539 +++ new/lib/sysacls.c
1542 + Unix SMB/CIFS implementation.
1543 + Samba system utilities for ACL support.
1544 + Copyright (C) Jeremy Allison 2000.
1546 + This program is free software; you can redistribute it and/or modify
1547 + it under the terms of the GNU General Public License as published by
1548 + the Free Software Foundation; either version 2 of the License, or
1549 + (at your option) any later version.
1551 + This program is distributed in the hope that it will be useful,
1552 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1553 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1554 + GNU General Public License for more details.
1556 + You should have received a copy of the GNU General Public License
1557 + along with this program; if not, write to the Free Software
1558 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1562 +#include "sysacls.h" /****** ADDED ******/
1564 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1565 +void SAFE_FREE(void *mem)
1571 +char *uidtoname(uid_t uid)
1573 + static char idbuf[12];
1574 + struct passwd *pw;
1576 + if ((pw = getpwuid(uid)) == NULL) {
1577 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1580 + return pw->pw_name;
1582 +/****** EXTRAS -- END ******/
1585 + This file wraps all differing system ACL interfaces into a consistent
1586 + one based on the POSIX interface. It also returns the correct errors
1587 + for older UNIX systems that don't support ACLs.
1589 + The interfaces that each ACL implementation must support are as follows :
1591 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1592 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1593 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1594 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1595 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1596 + SMB_ACL_T sys_acl_get_fd(int fd)
1597 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1598 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1599 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1600 + SMB_ACL_T sys_acl_init( int count)
1601 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1602 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1603 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1604 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1605 + int sys_acl_valid( SMB_ACL_T theacl )
1606 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1607 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1608 + int sys_acl_delete_def_file(const char *path)
1610 + This next one is not POSIX complient - but we *have* to have it !
1611 + More POSIX braindamage.
1613 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1615 + The generic POSIX free is the following call. We split this into
1616 + several different free functions as we may need to add tag info
1617 + to structures when emulating the POSIX interface.
1619 + int sys_acl_free( void *obj_p)
1621 + The calls we actually use are :
1623 + int sys_acl_free_text(char *text) - free acl_to_text
1624 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1625 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1629 +#if defined(HAVE_POSIX_ACLS)
1631 +/* Identity mapping - easy. */
1633 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1635 + return acl_get_entry( the_acl, entry_id, entry_p);
1638 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1640 + return acl_get_tag_type( entry_d, tag_type_p);
1643 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1645 + return acl_get_permset( entry_d, permset_p);
1648 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1650 + return acl_get_qualifier( entry_d);
1653 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1655 + return acl_get_file( path_p, type);
1658 +SMB_ACL_T sys_acl_get_fd(int fd)
1660 + return acl_get_fd(fd);
1663 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1665 + return acl_clear_perms(permset);
1668 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1670 + return acl_add_perm(permset, perm);
1673 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1675 +#if defined(HAVE_ACL_GET_PERM_NP)
1677 + * Required for TrustedBSD-based ACL implementations where
1678 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1681 + return acl_get_perm_np(permset, perm);
1683 + return acl_get_perm(permset, perm);
1687 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1689 + return acl_to_text( the_acl, plen);
1692 +SMB_ACL_T sys_acl_init( int count)
1694 + return acl_init(count);
1697 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1699 + return acl_create_entry(pacl, pentry);
1702 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1704 + return acl_set_tag_type(entry, tagtype);
1707 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1709 + return acl_set_qualifier(entry, qual);
1712 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1714 + return acl_set_permset(entry, permset);
1717 +int sys_acl_valid( SMB_ACL_T theacl )
1719 + return acl_valid(theacl);
1722 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1724 + return acl_set_file(name, acltype, theacl);
1727 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1729 + return acl_set_fd(fd, theacl);
1732 +int sys_acl_delete_def_file(const char *name)
1734 + return acl_delete_def_file(name);
1737 +int sys_acl_free_text(char *text)
1739 + return acl_free(text);
1742 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1744 + return acl_free(the_acl);
1747 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1749 + return acl_free(qual);
1752 +#elif defined(HAVE_TRU64_ACLS)
1754 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1755 + * is based on Draft 13 of the POSIX spec which is
1756 + * slightly different from the Draft 16 interface.
1758 + * Also, some of the permset manipulation functions
1759 + * such as acl_clear_perm() and acl_add_perm() appear
1760 + * to be broken on Tru64 so we have to manipulate
1761 + * the permission bits in the permset directly.
1763 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1765 + SMB_ACL_ENTRY_T entry;
1767 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1772 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1777 + return errno ? -1 : 0;
1780 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1782 + return acl_get_tag_type( entry_d, tag_type_p);
1785 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1787 + return acl_get_permset( entry_d, permset_p);
1790 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1792 + return acl_get_qualifier( entry_d);
1795 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1797 + return acl_get_file((char *)path_p, type);
1800 +SMB_ACL_T sys_acl_get_fd(int fd)
1802 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1805 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1807 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1812 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1814 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1819 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1824 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1826 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1829 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1831 + return acl_to_text( the_acl, plen);
1834 +SMB_ACL_T sys_acl_init( int count)
1836 + return acl_init(count);
1839 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1841 + SMB_ACL_ENTRY_T entry;
1843 + if ((entry = acl_create_entry(pacl)) == NULL) {
1851 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1853 + return acl_set_tag_type(entry, tagtype);
1856 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1858 + return acl_set_qualifier(entry, qual);
1861 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1863 + return acl_set_permset(entry, permset);
1866 +int sys_acl_valid( SMB_ACL_T theacl )
1868 + acl_entry_t entry;
1870 + return acl_valid(theacl, &entry);
1873 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1875 + return acl_set_file((char *)name, acltype, theacl);
1878 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1880 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1883 +int sys_acl_delete_def_file(const char *name)
1885 + return acl_delete_def_file((char *)name);
1888 +int sys_acl_free_text(char *text)
1891 + * (void) cast and explicit return 0 are for DEC UNIX
1892 + * which just #defines acl_free_text() to be free()
1894 + (void) acl_free_text(text);
1898 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1900 + return acl_free(the_acl);
1903 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1905 + return acl_free_qualifier(qual, tagtype);
1908 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1911 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1912 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1916 + * Note that while this code implements sufficient functionality
1917 + * to support the sys_acl_* interfaces it does not provide all
1918 + * of the semantics of the POSIX ACL interfaces.
1920 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1921 + * from a call to sys_acl_get_entry() should not be assumed to be
1922 + * valid after calling any of the following functions, which may
1923 + * reorder the entries in the ACL.
1926 + * sys_acl_set_file()
1927 + * sys_acl_set_fd()
1931 + * The only difference between Solaris and UnixWare / OpenUNIX is
1932 + * that the #defines for the ACL operations have different names
1934 +#if defined(HAVE_UNIXWARE_ACLS)
1936 +#define SETACL ACL_SET
1937 +#define GETACL ACL_GET
1938 +#define GETACLCNT ACL_CNT
1943 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1945 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1950 + if (entry_p == NULL) {
1955 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1959 + if (acl_d->next < 0) {
1964 + if (acl_d->next >= acl_d->count) {
1968 + *entry_p = &acl_d->acl[acl_d->next++];
1973 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1975 + *type_p = entry_d->a_type;
1980 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1982 + *permset_p = &entry_d->a_perm;
1987 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1989 + if (entry_d->a_type != SMB_ACL_USER
1990 + && entry_d->a_type != SMB_ACL_GROUP) {
1995 + return &entry_d->a_id;
1999 + * There is no way of knowing what size the ACL returned by
2000 + * GETACL will be unless you first call GETACLCNT which means
2001 + * making an additional system call.
2003 + * In the hope of avoiding the cost of the additional system
2004 + * call in most cases, we initially allocate enough space for
2005 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2006 + * be too small then we use GETACLCNT to find out the actual
2007 + * size, reallocate the ACL buffer, and then call GETACL again.
2010 +#define INITIAL_ACL_SIZE 16
2012 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2015 + int count; /* # of ACL entries allocated */
2016 + int naccess; /* # of access ACL entries */
2017 + int ndefault; /* # of default ACL entries */
2019 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2024 + count = INITIAL_ACL_SIZE;
2025 + if ((acl_d = sys_acl_init(count)) == NULL) {
2030 + * If there isn't enough space for the ACL entries we use
2031 + * GETACLCNT to determine the actual number of ACL entries
2032 + * reallocate and try again. This is in a loop because it
2033 + * is possible that someone else could modify the ACL and
2034 + * increase the number of entries between the call to
2035 + * GETACLCNT and the call to GETACL.
2037 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2038 + && errno == ENOSPC) {
2040 + sys_acl_free_acl(acl_d);
2042 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2046 + if ((acl_d = sys_acl_init(count)) == NULL) {
2052 + sys_acl_free_acl(acl_d);
2057 + * calculate the number of access and default ACL entries
2059 + * Note: we assume that the acl() system call returned a
2060 + * well formed ACL which is sorted so that all of the
2061 + * access ACL entries preceed any default ACL entries
2063 + for (naccess = 0; naccess < count; naccess++) {
2064 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2067 + ndefault = count - naccess;
2070 + * if the caller wants the default ACL we have to copy
2071 + * the entries down to the start of the acl[] buffer
2072 + * and mask out the ACL_DEFAULT flag from the type field
2074 + if (type == SMB_ACL_TYPE_DEFAULT) {
2077 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2078 + acl_d->acl[i] = acl_d->acl[j];
2079 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2082 + acl_d->count = ndefault;
2084 + acl_d->count = naccess;
2090 +SMB_ACL_T sys_acl_get_fd(int fd)
2093 + int count; /* # of ACL entries allocated */
2094 + int naccess; /* # of access ACL entries */
2096 + count = INITIAL_ACL_SIZE;
2097 + if ((acl_d = sys_acl_init(count)) == NULL) {
2101 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2102 + && errno == ENOSPC) {
2104 + sys_acl_free_acl(acl_d);
2106 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2110 + if ((acl_d = sys_acl_init(count)) == NULL) {
2116 + sys_acl_free_acl(acl_d);
2121 + * calculate the number of access ACL entries
2123 + for (naccess = 0; naccess < count; naccess++) {
2124 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2128 + acl_d->count = naccess;
2133 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2140 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2142 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2143 + && perm != SMB_ACL_EXECUTE) {
2148 + if (permset_d == NULL) {
2153 + *permset_d |= perm;
2158 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2160 + return *permset_d & perm;
2163 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2170 + * use an initial estimate of 20 bytes per ACL entry
2171 + * when allocating memory for the text representation
2175 + maxlen = 20 * acl_d->count;
2176 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2181 + for (i = 0; i < acl_d->count; i++) {
2182 + struct acl *ap = &acl_d->acl[i];
2183 + struct passwd *pw;
2192 + switch (ap->a_type) {
2194 + * for debugging purposes it's probably more
2195 + * useful to dump unknown tag types rather
2196 + * than just returning an error
2199 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2202 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2207 + case SMB_ACL_USER:
2208 + id = uidtoname(ap->a_id);
2209 + case SMB_ACL_USER_OBJ:
2213 + case SMB_ACL_GROUP:
2214 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2215 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2221 + case SMB_ACL_GROUP_OBJ:
2225 + case SMB_ACL_OTHER:
2229 + case SMB_ACL_MASK:
2235 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2236 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2237 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2240 + /* <tag> : <qualifier> : rwx \n \0 */
2241 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2244 + * If this entry would overflow the buffer
2245 + * allocate enough additional memory for this
2246 + * entry and an estimate of another 20 bytes
2247 + * for each entry still to be processed
2249 + if ((len + nbytes) > maxlen) {
2250 + char *oldtext = text;
2252 + maxlen += nbytes + 20 * (acl_d->count - i);
2254 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2255 + SAFE_FREE(oldtext);
2261 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2262 + len += nbytes - 1;
2271 +SMB_ACL_T sys_acl_init(int count)
2281 + * note that since the definition of the structure pointed
2282 + * to by the SMB_ACL_T includes the first element of the
2283 + * acl[] array, this actually allocates an ACL with room
2284 + * for (count+1) entries
2286 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2291 + a->size = count + 1;
2299 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2302 + SMB_ACL_ENTRY_T entry_d;
2304 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2309 + if (acl_d->count >= acl_d->size) {
2314 + entry_d = &acl_d->acl[acl_d->count++];
2315 + entry_d->a_type = 0;
2316 + entry_d->a_id = -1;
2317 + entry_d->a_perm = 0;
2318 + *entry_p = entry_d;
2323 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2325 + switch (tag_type) {
2326 + case SMB_ACL_USER:
2327 + case SMB_ACL_USER_OBJ:
2328 + case SMB_ACL_GROUP:
2329 + case SMB_ACL_GROUP_OBJ:
2330 + case SMB_ACL_OTHER:
2331 + case SMB_ACL_MASK:
2332 + entry_d->a_type = tag_type;
2342 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2344 + if (entry_d->a_type != SMB_ACL_GROUP
2345 + && entry_d->a_type != SMB_ACL_USER) {
2350 + entry_d->a_id = *((id_t *)qual_p);
2355 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2357 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2361 + entry_d->a_perm = *permset_d;
2367 + * sort the ACL and check it for validity
2369 + * if it's a minimal ACL with only 4 entries then we
2370 + * need to recalculate the mask permissions to make
2371 + * sure that they are the same as the GROUP_OBJ
2372 + * permissions as required by the UnixWare acl() system call.
2374 + * (note: since POSIX allows minimal ACLs which only contain
2375 + * 3 entries - ie there is no mask entry - we should, in theory,
2376 + * check for this and add a mask entry if necessary - however
2377 + * we "know" that the caller of this interface always specifies
2378 + * a mask so, in practice "this never happens" (tm) - if it *does*
2379 + * happen aclsort() will fail and return an error and someone will
2380 + * have to fix it ...)
2383 +static int acl_sort(SMB_ACL_T acl_d)
2385 + int fixmask = (acl_d->count <= 4);
2387 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2394 +int sys_acl_valid(SMB_ACL_T acl_d)
2396 + return acl_sort(acl_d);
2399 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2402 + struct acl *acl_p;
2404 + struct acl *acl_buf = NULL;
2407 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2412 + if (acl_sort(acl_d) != 0) {
2416 + acl_p = &acl_d->acl[0];
2417 + acl_count = acl_d->count;
2420 + * if it's a directory there is extra work to do
2421 + * since the acl() system call will replace both
2422 + * the access ACLs and the default ACLs (if any)
2424 + if (stat(name, &s) != 0) {
2427 + if (S_ISDIR(s.st_mode)) {
2428 + SMB_ACL_T acc_acl;
2429 + SMB_ACL_T def_acl;
2430 + SMB_ACL_T tmp_acl;
2433 + if (type == SMB_ACL_TYPE_ACCESS) {
2435 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2439 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2442 + if (tmp_acl == NULL) {
2447 + * allocate a temporary buffer for the complete ACL
2449 + acl_count = acc_acl->count + def_acl->count;
2450 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2452 + if (acl_buf == NULL) {
2453 + sys_acl_free_acl(tmp_acl);
2459 + * copy the access control and default entries into the buffer
2461 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2462 + acc_acl->count * sizeof(acl_buf[0]));
2464 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2465 + def_acl->count * sizeof(acl_buf[0]));
2468 + * set the ACL_DEFAULT flag on the default entries
2470 + for (i = acc_acl->count; i < acl_count; i++) {
2471 + acl_buf[i].a_type |= ACL_DEFAULT;
2474 + sys_acl_free_acl(tmp_acl);
2476 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2481 + ret = acl(name, SETACL, acl_count, acl_p);
2483 + SAFE_FREE(acl_buf);
2488 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2490 + if (acl_sort(acl_d) != 0) {
2494 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2497 +int sys_acl_delete_def_file(const char *path)
2503 + * fetching the access ACL and rewriting it has
2504 + * the effect of deleting the default ACL
2506 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2510 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2512 + sys_acl_free_acl(acl_d);
2517 +int sys_acl_free_text(char *text)
2523 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2529 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2534 +#elif defined(HAVE_HPUX_ACLS)
2538 + * Based on the Solaris/SCO code - with modifications.
2542 + * Note that while this code implements sufficient functionality
2543 + * to support the sys_acl_* interfaces it does not provide all
2544 + * of the semantics of the POSIX ACL interfaces.
2546 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2547 + * from a call to sys_acl_get_entry() should not be assumed to be
2548 + * valid after calling any of the following functions, which may
2549 + * reorder the entries in the ACL.
2552 + * sys_acl_set_file()
2553 + * sys_acl_set_fd()
2556 +/* This checks if the POSIX ACL system call is defined */
2557 +/* which basically corresponds to whether JFS 3.3 or */
2558 +/* higher is installed. If acl() was called when it */
2559 +/* isn't defined, it causes the process to core dump */
2560 +/* so it is important to check this and avoid acl() */
2561 +/* calls if it isn't there. */
2563 +static BOOL hpux_acl_call_presence(void)
2566 + shl_t handle = NULL;
2569 + static BOOL already_checked=0;
2571 + if(already_checked)
2575 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2577 + if(ret_val != 0) {
2578 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2579 + ret_val, errno, strerror(errno)));
2580 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2584 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2586 + already_checked = True;
2590 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2592 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2597 + if (entry_p == NULL) {
2602 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2606 + if (acl_d->next < 0) {
2611 + if (acl_d->next >= acl_d->count) {
2615 + *entry_p = &acl_d->acl[acl_d->next++];
2620 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2622 + *type_p = entry_d->a_type;
2627 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2629 + *permset_p = &entry_d->a_perm;
2634 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2636 + if (entry_d->a_type != SMB_ACL_USER
2637 + && entry_d->a_type != SMB_ACL_GROUP) {
2642 + return &entry_d->a_id;
2646 + * There is no way of knowing what size the ACL returned by
2647 + * ACL_GET will be unless you first call ACL_CNT which means
2648 + * making an additional system call.
2650 + * In the hope of avoiding the cost of the additional system
2651 + * call in most cases, we initially allocate enough space for
2652 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2653 + * be too small then we use ACL_CNT to find out the actual
2654 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2657 +#define INITIAL_ACL_SIZE 16
2659 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2662 + int count; /* # of ACL entries allocated */
2663 + int naccess; /* # of access ACL entries */
2664 + int ndefault; /* # of default ACL entries */
2666 + if(hpux_acl_call_presence() == False) {
2667 + /* Looks like we don't have the acl() system call on HPUX.
2668 + * May be the system doesn't have the latest version of JFS.
2673 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2678 + count = INITIAL_ACL_SIZE;
2679 + if ((acl_d = sys_acl_init(count)) == NULL) {
2684 + * If there isn't enough space for the ACL entries we use
2685 + * ACL_CNT to determine the actual number of ACL entries
2686 + * reallocate and try again. This is in a loop because it
2687 + * is possible that someone else could modify the ACL and
2688 + * increase the number of entries between the call to
2689 + * ACL_CNT and the call to ACL_GET.
2691 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2693 + sys_acl_free_acl(acl_d);
2695 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2699 + if ((acl_d = sys_acl_init(count)) == NULL) {
2705 + sys_acl_free_acl(acl_d);
2710 + * calculate the number of access and default ACL entries
2712 + * Note: we assume that the acl() system call returned a
2713 + * well formed ACL which is sorted so that all of the
2714 + * access ACL entries preceed any default ACL entries
2716 + for (naccess = 0; naccess < count; naccess++) {
2717 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2720 + ndefault = count - naccess;
2723 + * if the caller wants the default ACL we have to copy
2724 + * the entries down to the start of the acl[] buffer
2725 + * and mask out the ACL_DEFAULT flag from the type field
2727 + if (type == SMB_ACL_TYPE_DEFAULT) {
2730 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2731 + acl_d->acl[i] = acl_d->acl[j];
2732 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2735 + acl_d->count = ndefault;
2737 + acl_d->count = naccess;
2743 +SMB_ACL_T sys_acl_get_fd(int fd)
2746 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2749 + files_struct *fsp = file_find_fd(fd);
2751 + if (fsp == NULL) {
2757 + * We know we're in the same conn context. So we
2758 + * can use the relative path.
2761 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2764 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2771 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2773 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2774 + && perm != SMB_ACL_EXECUTE) {
2779 + if (permset_d == NULL) {
2784 + *permset_d |= perm;
2789 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2791 + return *permset_d & perm;
2794 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2801 + * use an initial estimate of 20 bytes per ACL entry
2802 + * when allocating memory for the text representation
2806 + maxlen = 20 * acl_d->count;
2807 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2812 + for (i = 0; i < acl_d->count; i++) {
2813 + struct acl *ap = &acl_d->acl[i];
2814 + struct passwd *pw;
2823 + switch (ap->a_type) {
2825 + * for debugging purposes it's probably more
2826 + * useful to dump unknown tag types rather
2827 + * than just returning an error
2830 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2833 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2838 + case SMB_ACL_USER:
2839 + id = uidtoname(ap->a_id);
2840 + case SMB_ACL_USER_OBJ:
2844 + case SMB_ACL_GROUP:
2845 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2846 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2852 + case SMB_ACL_GROUP_OBJ:
2856 + case SMB_ACL_OTHER:
2860 + case SMB_ACL_MASK:
2866 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2867 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2868 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2871 + /* <tag> : <qualifier> : rwx \n \0 */
2872 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2875 + * If this entry would overflow the buffer
2876 + * allocate enough additional memory for this
2877 + * entry and an estimate of another 20 bytes
2878 + * for each entry still to be processed
2880 + if ((len + nbytes) > maxlen) {
2881 + char *oldtext = text;
2883 + maxlen += nbytes + 20 * (acl_d->count - i);
2885 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2892 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2893 + len += nbytes - 1;
2902 +SMB_ACL_T sys_acl_init(int count)
2912 + * note that since the definition of the structure pointed
2913 + * to by the SMB_ACL_T includes the first element of the
2914 + * acl[] array, this actually allocates an ACL with room
2915 + * for (count+1) entries
2917 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2922 + a->size = count + 1;
2930 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2933 + SMB_ACL_ENTRY_T entry_d;
2935 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2940 + if (acl_d->count >= acl_d->size) {
2945 + entry_d = &acl_d->acl[acl_d->count++];
2946 + entry_d->a_type = 0;
2947 + entry_d->a_id = -1;
2948 + entry_d->a_perm = 0;
2949 + *entry_p = entry_d;
2954 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2956 + switch (tag_type) {
2957 + case SMB_ACL_USER:
2958 + case SMB_ACL_USER_OBJ:
2959 + case SMB_ACL_GROUP:
2960 + case SMB_ACL_GROUP_OBJ:
2961 + case SMB_ACL_OTHER:
2962 + case SMB_ACL_MASK:
2963 + entry_d->a_type = tag_type;
2973 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2975 + if (entry_d->a_type != SMB_ACL_GROUP
2976 + && entry_d->a_type != SMB_ACL_USER) {
2981 + entry_d->a_id = *((id_t *)qual_p);
2986 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2988 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2992 + entry_d->a_perm = *permset_d;
2997 +/* Structure to capture the count for each type of ACE. */
2999 +struct hpux_acl_types {
3003 + int n_def_user_obj;
3008 + int n_def_group_obj;
3012 + int n_def_other_obj;
3015 + int n_def_class_obj;
3017 + int n_illegal_obj;
3021 + * Counts the different number of objects in a given array of ACL
3025 + * acl_count - Count of ACLs in the array of ACL strucutres.
3026 + * aclp - Array of ACL structures.
3027 + * acl_type_count - Pointer to acl_types structure. Should already be
3031 + * acl_type_count - This structure is filled up with counts of various
3035 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3039 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3041 + for(i=0;i<acl_count;i++) {
3042 + switch(aclp[i].a_type) {
3044 + acl_type_count->n_user++;
3047 + acl_type_count->n_user_obj++;
3049 + case DEF_USER_OBJ:
3050 + acl_type_count->n_def_user_obj++;
3053 + acl_type_count->n_group++;
3056 + acl_type_count->n_group_obj++;
3058 + case DEF_GROUP_OBJ:
3059 + acl_type_count->n_def_group_obj++;
3062 + acl_type_count->n_other_obj++;
3064 + case DEF_OTHER_OBJ:
3065 + acl_type_count->n_def_other_obj++;
3068 + acl_type_count->n_class_obj++;
3070 + case DEF_CLASS_OBJ:
3071 + acl_type_count->n_def_class_obj++;
3074 + acl_type_count->n_def_user++;
3077 + acl_type_count->n_def_group++;
3080 + acl_type_count->n_illegal_obj++;
3086 +/* swap_acl_entries: Swaps two ACL entries.
3088 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3091 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3093 + struct acl temp_acl;
3095 + temp_acl.a_type = aclp0->a_type;
3096 + temp_acl.a_id = aclp0->a_id;
3097 + temp_acl.a_perm = aclp0->a_perm;
3099 + aclp0->a_type = aclp1->a_type;
3100 + aclp0->a_id = aclp1->a_id;
3101 + aclp0->a_perm = aclp1->a_perm;
3103 + aclp1->a_type = temp_acl.a_type;
3104 + aclp1->a_id = temp_acl.a_id;
3105 + aclp1->a_perm = temp_acl.a_perm;
3108 +/* prohibited_duplicate_type
3109 + * Identifies if given ACL type can have duplicate entries or
3112 + * Inputs: acl_type - ACL Type.
3118 + * True - If the ACL type matches any of the prohibited types.
3119 + * False - If the ACL type doesn't match any of the prohibited types.
3122 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3124 + switch(acl_type) {
3135 +/* get_needed_class_perm
3136 + * Returns the permissions of a ACL structure only if the ACL
3137 + * type matches one of the pre-determined types for computing
3138 + * CLASS_OBJ permissions.
3140 + * Inputs: aclp - Pointer to ACL structure.
3143 +static int hpux_get_needed_class_perm(struct acl *aclp)
3145 + switch(aclp->a_type) {
3149 + case DEF_USER_OBJ:
3151 + case DEF_GROUP_OBJ:
3153 + case DEF_CLASS_OBJ:
3154 + case DEF_OTHER_OBJ:
3155 + return aclp->a_perm;
3161 +/* acl_sort for HPUX.
3162 + * Sorts the array of ACL structures as per the description in
3163 + * aclsort man page. Refer to aclsort man page for more details
3167 + * acl_count - Count of ACLs in the array of ACL structures.
3168 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3170 + * aclp - Array of ACL structures.
3174 + * aclp - Sorted array of ACL structures.
3178 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3179 + * debug log in case of failure.
3182 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3184 +#if !defined(HAVE_HPUX_ACLSORT)
3186 + * The aclsort() system call is availabe on the latest HPUX General
3187 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3188 + * function. Because, we don't want to update to a new
3189 + * HPUX GR bundle just for aclsort() call.
3192 + struct hpux_acl_types acl_obj_count;
3193 + int n_class_obj_perm = 0;
3197 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3201 + if(aclp == NULL) {
3202 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3206 + /* Count different types of ACLs in the ACLs array */
3208 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3210 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3211 + * CLASS_OBJ and OTHER_OBJ
3214 + if( (acl_obj_count.n_user_obj != 1) ||
3215 + (acl_obj_count.n_group_obj != 1) ||
3216 + (acl_obj_count.n_class_obj != 1) ||
3217 + (acl_obj_count.n_other_obj != 1)
3219 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3220 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3224 + /* If any of the default objects are present, there should be only
3225 + * one of them each.
3228 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3229 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3230 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3231 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3235 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3238 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3239 + * same ACL type, sort by ACL id.
3241 + * I am using the trival kind of sorting method here because, performance isn't
3242 + * really effected by the ACLs feature. More over there aren't going to be more
3243 + * than 17 entries on HPUX.
3246 + for(i=0; i<acl_count;i++) {
3247 + for (j=i+1; j<acl_count; j++) {
3248 + if( aclp[i].a_type > aclp[j].a_type ) {
3249 + /* ACL entries out of order, swap them */
3251 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3253 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3255 + /* ACL entries of same type, sort by id */
3257 + if(aclp[i].a_id > aclp[j].a_id) {
3258 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3259 + } else if (aclp[i].a_id == aclp[j].a_id) {
3260 + /* We have a duplicate entry. */
3261 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3262 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3263 + aclp[i].a_type, aclp[i].a_id));
3272 + /* set the class obj permissions to the computed one. */
3274 + int n_class_obj_index = -1;
3276 + for(i=0;i<acl_count;i++) {
3277 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3279 + if(aclp[i].a_type == CLASS_OBJ)
3280 + n_class_obj_index = i;
3282 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3287 + return aclsort(acl_count, calclass, aclp);
3292 + * sort the ACL and check it for validity
3294 + * if it's a minimal ACL with only 4 entries then we
3295 + * need to recalculate the mask permissions to make
3296 + * sure that they are the same as the GROUP_OBJ
3297 + * permissions as required by the UnixWare acl() system call.
3299 + * (note: since POSIX allows minimal ACLs which only contain
3300 + * 3 entries - ie there is no mask entry - we should, in theory,
3301 + * check for this and add a mask entry if necessary - however
3302 + * we "know" that the caller of this interface always specifies
3303 + * a mask so, in practice "this never happens" (tm) - if it *does*
3304 + * happen aclsort() will fail and return an error and someone will
3305 + * have to fix it ...)
3308 +static int acl_sort(SMB_ACL_T acl_d)
3310 + int fixmask = (acl_d->count <= 4);
3312 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3319 +int sys_acl_valid(SMB_ACL_T acl_d)
3321 + return acl_sort(acl_d);
3324 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3327 + struct acl *acl_p;
3329 + struct acl *acl_buf = NULL;
3332 + if(hpux_acl_call_presence() == False) {
3333 + /* Looks like we don't have the acl() system call on HPUX.
3334 + * May be the system doesn't have the latest version of JFS.
3340 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3345 + if (acl_sort(acl_d) != 0) {
3349 + acl_p = &acl_d->acl[0];
3350 + acl_count = acl_d->count;
3353 + * if it's a directory there is extra work to do
3354 + * since the acl() system call will replace both
3355 + * the access ACLs and the default ACLs (if any)
3357 + if (stat(name, &s) != 0) {
3360 + if (S_ISDIR(s.st_mode)) {
3361 + SMB_ACL_T acc_acl;
3362 + SMB_ACL_T def_acl;
3363 + SMB_ACL_T tmp_acl;
3366 + if (type == SMB_ACL_TYPE_ACCESS) {
3368 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3372 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3375 + if (tmp_acl == NULL) {
3380 + * allocate a temporary buffer for the complete ACL
3382 + acl_count = acc_acl->count + def_acl->count;
3383 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3385 + if (acl_buf == NULL) {
3386 + sys_acl_free_acl(tmp_acl);
3392 + * copy the access control and default entries into the buffer
3394 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3395 + acc_acl->count * sizeof(acl_buf[0]));
3397 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3398 + def_acl->count * sizeof(acl_buf[0]));
3401 + * set the ACL_DEFAULT flag on the default entries
3403 + for (i = acc_acl->count; i < acl_count; i++) {
3404 + acl_buf[i].a_type |= ACL_DEFAULT;
3407 + sys_acl_free_acl(tmp_acl);
3409 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3414 + ret = acl(name, ACL_SET, acl_count, acl_p);
3423 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3426 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3429 + files_struct *fsp = file_find_fd(fd);
3431 + if (fsp == NULL) {
3436 + if (acl_sort(acl_d) != 0) {
3441 + * We know we're in the same conn context. So we
3442 + * can use the relative path.
3445 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3448 +int sys_acl_delete_def_file(const char *path)
3454 + * fetching the access ACL and rewriting it has
3455 + * the effect of deleting the default ACL
3457 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3461 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3463 + sys_acl_free_acl(acl_d);
3468 +int sys_acl_free_text(char *text)
3474 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3480 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3485 +#elif defined(HAVE_IRIX_ACLS)
3487 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3489 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3494 + if (entry_p == NULL) {
3499 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3503 + if (acl_d->next < 0) {
3508 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3512 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3517 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3519 + *type_p = entry_d->ae_tag;
3524 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3526 + *permset_p = entry_d;
3531 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3533 + if (entry_d->ae_tag != SMB_ACL_USER
3534 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3539 + return &entry_d->ae_id;
3542 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3546 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3550 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3555 + a->freeaclp = True;
3559 +SMB_ACL_T sys_acl_get_fd(int fd)
3563 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3567 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3572 + a->freeaclp = True;
3576 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3578 + permset_d->ae_perm = 0;
3583 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3585 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3586 + && perm != SMB_ACL_EXECUTE) {
3591 + if (permset_d == NULL) {
3596 + permset_d->ae_perm |= perm;
3601 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3603 + return permset_d->ae_perm & perm;
3606 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3608 + return acl_to_text(acl_d->aclp, len_p);
3611 +SMB_ACL_T sys_acl_init(int count)
3620 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3626 + a->freeaclp = False;
3627 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3628 + a->aclp->acl_cnt = 0;
3634 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3637 + SMB_ACL_ENTRY_T entry_d;
3639 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3644 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3649 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3650 + entry_d->ae_tag = 0;
3651 + entry_d->ae_id = 0;
3652 + entry_d->ae_perm = 0;
3653 + *entry_p = entry_d;
3658 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3660 + switch (tag_type) {
3661 + case SMB_ACL_USER:
3662 + case SMB_ACL_USER_OBJ:
3663 + case SMB_ACL_GROUP:
3664 + case SMB_ACL_GROUP_OBJ:
3665 + case SMB_ACL_OTHER:
3666 + case SMB_ACL_MASK:
3667 + entry_d->ae_tag = tag_type;
3677 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3679 + if (entry_d->ae_tag != SMB_ACL_GROUP
3680 + && entry_d->ae_tag != SMB_ACL_USER) {
3685 + entry_d->ae_id = *((id_t *)qual_p);
3690 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3692 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3696 + entry_d->ae_perm = permset_d->ae_perm;
3701 +int sys_acl_valid(SMB_ACL_T acl_d)
3703 + return acl_valid(acl_d->aclp);
3706 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3708 + return acl_set_file(name, type, acl_d->aclp);
3711 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3713 + return acl_set_fd(fd, acl_d->aclp);
3716 +int sys_acl_delete_def_file(const char *name)
3718 + return acl_delete_def_file(name);
3721 +int sys_acl_free_text(char *text)
3723 + return acl_free(text);
3726 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3728 + if (acl_d->freeaclp) {
3729 + acl_free(acl_d->aclp);
3735 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3740 +#elif defined(HAVE_AIX_ACLS)
3742 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3744 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3746 + struct acl_entry_link *link;
3747 + struct new_acl_entry *entry;
3750 + DEBUG(10,("This is the count: %d\n",theacl->count));
3752 + /* Check if count was previously set to -1. *
3753 + * If it was, that means we reached the end *
3754 + * of the acl last time. */
3755 + if(theacl->count == -1)
3759 + /* To get to the next acl, traverse linked list until index *
3760 + * of acl matches the count we are keeping. This count is *
3761 + * incremented each time we return an acl entry. */
3763 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3764 + link = link->nextp;
3766 + entry = *entry_p = link->entryp;
3768 + DEBUG(10,("*entry_p is %d\n",entry_p));
3769 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3771 + /* Increment count */
3773 + if(link->nextp == NULL)
3774 + theacl->count = -1;
3779 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3781 + /* Initialize tag type */
3784 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3786 + /* Depending on what type of entry we have, *
3787 + * return tag type. */
3788 + switch(entry_d->ace_id->id_type) {
3790 + *tag_type_p = SMB_ACL_USER;
3793 + *tag_type_p = SMB_ACL_GROUP;
3796 + case SMB_ACL_USER_OBJ:
3797 + case SMB_ACL_GROUP_OBJ:
3798 + case SMB_ACL_OTHER:
3799 + *tag_type_p = entry_d->ace_id->id_type;
3809 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3811 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3812 + *permset_p = &entry_d->ace_access;
3813 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3814 + if(!(**permset_p & S_IXUSR) &&
3815 + !(**permset_p & S_IWUSR) &&
3816 + !(**permset_p & S_IRUSR) &&
3817 + (**permset_p != 0))
3820 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3824 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3826 + return(entry_d->ace_id->id_data);
3829 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3831 + struct acl *file_acl = (struct acl *)NULL;
3832 + struct acl_entry *acl_entry;
3833 + struct new_acl_entry *new_acl_entry;
3834 + struct ace_id *idp;
3835 + struct acl_entry_link *acl_entry_link;
3836 + struct acl_entry_link *acl_entry_link_head;
3841 + /* AIX has no DEFAULT */
3842 + if ( type == SMB_ACL_TYPE_DEFAULT )
3845 + /* Get the acl using statacl */
3847 + DEBUG(10,("Entering sys_acl_get_file\n"));
3848 + DEBUG(10,("path_p is %s\n",path_p));
3850 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3852 + if(file_acl == NULL) {
3854 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3858 + memset(file_acl,0,BUFSIZ);
3860 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3862 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3863 + SAFE_FREE(file_acl);
3867 + DEBUG(10,("Got facl and returned it\n"));
3869 + /* Point to the first acl entry in the acl */
3870 + acl_entry = file_acl->acl_ext;
3872 + /* Begin setting up the head of the linked list *
3873 + * that will be used for the storing the acl *
3874 + * in a way that is useful for the posix_acls.c *
3877 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3878 + if(acl_entry_link_head == NULL)
3881 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3882 + if(acl_entry_link->entryp == NULL) {
3883 + SAFE_FREE(file_acl);
3885 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3889 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3890 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3892 + /* Check if the extended acl bit is on. *
3893 + * If it isn't, do not show the *
3894 + * contents of the acl since AIX intends *
3895 + * the extended info to remain unused */
3897 + if(file_acl->acl_mode & S_IXACL){
3898 + /* while we are not pointing to the very end */
3899 + while(acl_entry < acl_last(file_acl)) {
3900 + /* before we malloc anything, make sure this is */
3901 + /* a valid acl entry and one that we want to map */
3902 + idp = id_nxt(acl_entry->ace_id);
3903 + if((acl_entry->ace_type == ACC_SPECIFY ||
3904 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3905 + acl_entry = acl_nxt(acl_entry);
3909 + idp = acl_entry->ace_id;
3911 + /* Check if this is the first entry in the linked list. *
3912 + * The first entry needs to keep prevp pointing to NULL *
3913 + * and already has entryp allocated. */
3915 + if(acl_entry_link_head->count != 0) {
3916 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3918 + if(acl_entry_link->nextp == NULL) {
3919 + SAFE_FREE(file_acl);
3921 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3925 + acl_entry_link->nextp->prevp = acl_entry_link;
3926 + acl_entry_link = acl_entry_link->nextp;
3927 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3928 + if(acl_entry_link->entryp == NULL) {
3929 + SAFE_FREE(file_acl);
3931 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3934 + acl_entry_link->nextp = NULL;
3937 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3939 + /* Don't really need this since all types are going *
3940 + * to be specified but, it's better than leaving it 0 */
3942 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3944 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3946 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3948 + /* The access in the acl entries must be left shifted by *
3949 + * three bites, because they will ultimately be compared *
3950 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3952 + switch(acl_entry->ace_type){
3955 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3956 + acl_entry_link->entryp->ace_access <<= 6;
3957 + acl_entry_link_head->count++;
3960 + /* Since there is no way to return a DENY acl entry *
3961 + * change to PERMIT and then shift. */
3962 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3963 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3964 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3965 + acl_entry_link->entryp->ace_access <<= 6;
3966 + acl_entry_link_head->count++;
3972 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3973 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3975 + acl_entry = acl_nxt(acl_entry);
3977 + } /* end of if enabled */
3979 + /* Since owner, group, other acl entries are not *
3980 + * part of the acl entries in an acl, they must *
3981 + * be dummied up to become part of the list. */
3983 + for( i = 1; i < 4; i++) {
3984 + DEBUG(10,("i is %d\n",i));
3985 + if(acl_entry_link_head->count != 0) {
3986 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3987 + if(acl_entry_link->nextp == NULL) {
3988 + SAFE_FREE(file_acl);
3990 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3994 + acl_entry_link->nextp->prevp = acl_entry_link;
3995 + acl_entry_link = acl_entry_link->nextp;
3996 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3997 + if(acl_entry_link->entryp == NULL) {
3998 + SAFE_FREE(file_acl);
4000 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4005 + acl_entry_link->nextp = NULL;
4007 + new_acl_entry = acl_entry_link->entryp;
4008 + idp = new_acl_entry->ace_id;
4010 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4011 + new_acl_entry->ace_type = ACC_PERMIT;
4012 + idp->id_len = sizeof(struct ace_id);
4013 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4014 + memset(idp->id_data,0,sizeof(uid_t));
4018 + new_acl_entry->ace_access = file_acl->g_access << 6;
4019 + idp->id_type = SMB_ACL_GROUP_OBJ;
4023 + new_acl_entry->ace_access = file_acl->o_access << 6;
4024 + idp->id_type = SMB_ACL_OTHER;
4028 + new_acl_entry->ace_access = file_acl->u_access << 6;
4029 + idp->id_type = SMB_ACL_USER_OBJ;
4037 + acl_entry_link_head->count++;
4038 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4041 + acl_entry_link_head->count = 0;
4042 + SAFE_FREE(file_acl);
4044 + return(acl_entry_link_head);
4047 +SMB_ACL_T sys_acl_get_fd(int fd)
4049 + struct acl *file_acl = (struct acl *)NULL;
4050 + struct acl_entry *acl_entry;
4051 + struct new_acl_entry *new_acl_entry;
4052 + struct ace_id *idp;
4053 + struct acl_entry_link *acl_entry_link;
4054 + struct acl_entry_link *acl_entry_link_head;
4059 + /* Get the acl using fstatacl */
4061 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4062 + DEBUG(10,("fd is %d\n",fd));
4063 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4065 + if(file_acl == NULL) {
4067 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4071 + memset(file_acl,0,BUFSIZ);
4073 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4075 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4076 + SAFE_FREE(file_acl);
4080 + DEBUG(10,("Got facl and returned it\n"));
4082 + /* Point to the first acl entry in the acl */
4084 + acl_entry = file_acl->acl_ext;
4085 + /* Begin setting up the head of the linked list *
4086 + * that will be used for the storing the acl *
4087 + * in a way that is useful for the posix_acls.c *
4090 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4091 + if(acl_entry_link_head == NULL){
4092 + SAFE_FREE(file_acl);
4096 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4098 + if(acl_entry_link->entryp == NULL) {
4100 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4101 + SAFE_FREE(file_acl);
4105 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4106 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4108 + /* Check if the extended acl bit is on. *
4109 + * If it isn't, do not show the *
4110 + * contents of the acl since AIX intends *
4111 + * the extended info to remain unused */
4113 + if(file_acl->acl_mode & S_IXACL){
4114 + /* while we are not pointing to the very end */
4115 + while(acl_entry < acl_last(file_acl)) {
4116 + /* before we malloc anything, make sure this is */
4117 + /* a valid acl entry and one that we want to map */
4119 + idp = id_nxt(acl_entry->ace_id);
4120 + if((acl_entry->ace_type == ACC_SPECIFY ||
4121 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4122 + acl_entry = acl_nxt(acl_entry);
4126 + idp = acl_entry->ace_id;
4128 + /* Check if this is the first entry in the linked list. *
4129 + * The first entry needs to keep prevp pointing to NULL *
4130 + * and already has entryp allocated. */
4132 + if(acl_entry_link_head->count != 0) {
4133 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4134 + if(acl_entry_link->nextp == NULL) {
4136 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4137 + SAFE_FREE(file_acl);
4140 + acl_entry_link->nextp->prevp = acl_entry_link;
4141 + acl_entry_link = acl_entry_link->nextp;
4142 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4143 + if(acl_entry_link->entryp == NULL) {
4145 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4146 + SAFE_FREE(file_acl);
4150 + acl_entry_link->nextp = NULL;
4153 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4155 + /* Don't really need this since all types are going *
4156 + * to be specified but, it's better than leaving it 0 */
4158 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4159 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4161 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4163 + /* The access in the acl entries must be left shifted by *
4164 + * three bites, because they will ultimately be compared *
4165 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4167 + switch(acl_entry->ace_type){
4170 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4171 + acl_entry_link->entryp->ace_access <<= 6;
4172 + acl_entry_link_head->count++;
4175 + /* Since there is no way to return a DENY acl entry *
4176 + * change to PERMIT and then shift. */
4177 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4178 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4179 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4180 + acl_entry_link->entryp->ace_access <<= 6;
4181 + acl_entry_link_head->count++;
4187 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4188 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4190 + acl_entry = acl_nxt(acl_entry);
4192 + } /* end of if enabled */
4194 + /* Since owner, group, other acl entries are not *
4195 + * part of the acl entries in an acl, they must *
4196 + * be dummied up to become part of the list. */
4198 + for( i = 1; i < 4; i++) {
4199 + DEBUG(10,("i is %d\n",i));
4200 + if(acl_entry_link_head->count != 0){
4201 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4202 + if(acl_entry_link->nextp == NULL) {
4204 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4205 + SAFE_FREE(file_acl);
4209 + acl_entry_link->nextp->prevp = acl_entry_link;
4210 + acl_entry_link = acl_entry_link->nextp;
4211 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4213 + if(acl_entry_link->entryp == NULL) {
4214 + SAFE_FREE(file_acl);
4216 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4221 + acl_entry_link->nextp = NULL;
4223 + new_acl_entry = acl_entry_link->entryp;
4224 + idp = new_acl_entry->ace_id;
4226 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4227 + new_acl_entry->ace_type = ACC_PERMIT;
4228 + idp->id_len = sizeof(struct ace_id);
4229 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4230 + memset(idp->id_data,0,sizeof(uid_t));
4234 + new_acl_entry->ace_access = file_acl->g_access << 6;
4235 + idp->id_type = SMB_ACL_GROUP_OBJ;
4239 + new_acl_entry->ace_access = file_acl->o_access << 6;
4240 + idp->id_type = SMB_ACL_OTHER;
4244 + new_acl_entry->ace_access = file_acl->u_access << 6;
4245 + idp->id_type = SMB_ACL_USER_OBJ;
4252 + acl_entry_link_head->count++;
4253 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4256 + acl_entry_link_head->count = 0;
4257 + SAFE_FREE(file_acl);
4259 + return(acl_entry_link_head);
4262 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4264 + *permset = *permset & ~0777;
4268 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4271 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4275 + DEBUG(10,("This is the permset now: %d\n",*permset));
4279 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4284 +SMB_ACL_T sys_acl_init( int count)
4286 + struct acl_entry_link *theacl = NULL;
4288 + DEBUG(10,("Entering sys_acl_init\n"));
4290 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4291 + if(theacl == NULL) {
4293 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4297 + theacl->count = 0;
4298 + theacl->nextp = NULL;
4299 + theacl->prevp = NULL;
4300 + theacl->entryp = NULL;
4301 + DEBUG(10,("Exiting sys_acl_init\n"));
4305 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4307 + struct acl_entry_link *theacl;
4308 + struct acl_entry_link *acl_entryp;
4309 + struct acl_entry_link *temp_entry;
4312 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4314 + theacl = acl_entryp = *pacl;
4316 + /* Get to the end of the acl before adding entry */
4318 + for(counting=0; counting < theacl->count; counting++){
4319 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4320 + temp_entry = acl_entryp;
4321 + acl_entryp = acl_entryp->nextp;
4324 + if(theacl->count != 0){
4325 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4326 + if(acl_entryp == NULL) {
4328 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4332 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4333 + acl_entryp->prevp = temp_entry;
4334 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4337 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4338 + if(*pentry == NULL) {
4340 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4344 + memset(*pentry,0,sizeof(struct new_acl_entry));
4345 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4346 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4347 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4348 + acl_entryp->nextp = NULL;
4350 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4354 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4356 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4357 + entry->ace_id->id_type = tagtype;
4358 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4359 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4362 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4364 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4365 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4366 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4370 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4372 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4373 + if(!(*permset & S_IXUSR) &&
4374 + !(*permset & S_IWUSR) &&
4375 + !(*permset & S_IRUSR) &&
4379 + entry->ace_access = *permset;
4380 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4381 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4385 +int sys_acl_valid( SMB_ACL_T theacl )
4388 + int group_obj = 0;
4389 + int other_obj = 0;
4390 + struct acl_entry_link *acl_entry;
4392 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4393 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4394 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4395 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4398 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4400 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4406 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4408 + struct acl_entry_link *acl_entry_link = NULL;
4409 + struct acl *file_acl = NULL;
4410 + struct acl *file_acl_temp = NULL;
4411 + struct acl_entry *acl_entry = NULL;
4412 + struct ace_id *ace_id = NULL;
4419 + DEBUG(10,("Entering sys_acl_set_file\n"));
4420 + DEBUG(10,("File name is %s\n",name));
4422 + /* AIX has no default ACL */
4423 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4426 + acl_length = BUFSIZ;
4427 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4429 + if(file_acl == NULL) {
4431 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4435 + memset(file_acl,0,BUFSIZ);
4437 + file_acl->acl_len = ACL_SIZ;
4438 + file_acl->acl_mode = S_IXACL;
4440 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4441 + acl_entry_link->entryp->ace_access >>= 6;
4442 + id_type = acl_entry_link->entryp->ace_id->id_type;
4445 + case SMB_ACL_USER_OBJ:
4446 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4448 + case SMB_ACL_GROUP_OBJ:
4449 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4451 + case SMB_ACL_OTHER:
4452 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4454 + case SMB_ACL_MASK:
4458 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4459 + acl_length += sizeof(struct acl_entry);
4460 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4461 + if(file_acl_temp == NULL) {
4462 + SAFE_FREE(file_acl);
4464 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4468 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4469 + SAFE_FREE(file_acl);
4470 + file_acl = file_acl_temp;
4473 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4474 + file_acl->acl_len += sizeof(struct acl_entry);
4475 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4476 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4478 + /* In order to use this, we'll need to wait until we can get denies */
4479 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4480 + acl_entry->ace_type = ACC_SPECIFY; */
4482 + acl_entry->ace_type = ACC_SPECIFY;
4484 + ace_id = acl_entry->ace_id;
4486 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4487 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4488 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4489 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4490 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4493 + rc = chacl(name,file_acl,file_acl->acl_len);
4494 + DEBUG(10,("errno is %d\n",errno));
4495 + DEBUG(10,("return code is %d\n",rc));
4496 + SAFE_FREE(file_acl);
4497 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4501 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4503 + struct acl_entry_link *acl_entry_link = NULL;
4504 + struct acl *file_acl = NULL;
4505 + struct acl *file_acl_temp = NULL;
4506 + struct acl_entry *acl_entry = NULL;
4507 + struct ace_id *ace_id = NULL;
4513 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4514 + acl_length = BUFSIZ;
4515 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4517 + if(file_acl == NULL) {
4519 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4523 + memset(file_acl,0,BUFSIZ);
4525 + file_acl->acl_len = ACL_SIZ;
4526 + file_acl->acl_mode = S_IXACL;
4528 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4529 + acl_entry_link->entryp->ace_access >>= 6;
4530 + id_type = acl_entry_link->entryp->ace_id->id_type;
4531 + DEBUG(10,("The id_type is %d\n",id_type));
4534 + case SMB_ACL_USER_OBJ:
4535 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4537 + case SMB_ACL_GROUP_OBJ:
4538 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4540 + case SMB_ACL_OTHER:
4541 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4543 + case SMB_ACL_MASK:
4547 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4548 + acl_length += sizeof(struct acl_entry);
4549 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4550 + if(file_acl_temp == NULL) {
4551 + SAFE_FREE(file_acl);
4553 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4557 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4558 + SAFE_FREE(file_acl);
4559 + file_acl = file_acl_temp;
4562 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4563 + file_acl->acl_len += sizeof(struct acl_entry);
4564 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4565 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4567 + /* In order to use this, we'll need to wait until we can get denies */
4568 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4569 + acl_entry->ace_type = ACC_SPECIFY; */
4571 + acl_entry->ace_type = ACC_SPECIFY;
4573 + ace_id = acl_entry->ace_id;
4575 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4576 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4577 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4578 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4579 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4582 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4583 + DEBUG(10,("errno is %d\n",errno));
4584 + DEBUG(10,("return code is %d\n",rc));
4585 + SAFE_FREE(file_acl);
4586 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4590 +int sys_acl_delete_def_file(const char *name)
4592 + /* AIX has no default ACL */
4596 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4598 + return(*permset & perm);
4601 +int sys_acl_free_text(char *text)
4606 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4608 + struct acl_entry_link *acl_entry_link;
4610 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4611 + SAFE_FREE(acl_entry_link->prevp->entryp);
4612 + SAFE_FREE(acl_entry_link->prevp);
4615 + SAFE_FREE(acl_entry_link->prevp->entryp);
4616 + SAFE_FREE(acl_entry_link->prevp);
4617 + SAFE_FREE(acl_entry_link->entryp);
4618 + SAFE_FREE(acl_entry_link);
4623 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4628 +#else /* No ACLs. */
4630 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4636 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4642 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4648 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4654 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4657 + return (SMB_ACL_T)NULL;
4660 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4663 + return (SMB_ACL_T)NULL;
4666 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4672 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4678 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4681 + return (permset & perm) ? 1 : 0;
4684 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4690 +int sys_acl_free_text(UNUSED(char *text))
4696 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4702 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4708 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4714 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4720 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4726 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4732 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4738 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4744 +int sys_acl_delete_def_file(UNUSED(const char *name))
4750 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4756 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4762 +#endif /* No ACLs. */
4764 +/************************************************************************
4765 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4767 +************************************************************************/
4769 +int no_acl_syscall_error(int err)
4771 +#if defined(ENOSYS)
4772 + if (err == ENOSYS) {
4776 +#if defined(ENOTSUP)
4777 + if (err == ENOTSUP) {
4783 --- old/lib/sysacls.h
4784 +++ new/lib/sysacls.h
4786 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4787 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4788 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4789 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4790 +#define slprintf snprintf
4792 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4793 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4794 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4795 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4796 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4797 +SMB_ACL_T sys_acl_get_fd(int fd);
4798 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4799 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4800 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4801 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4802 +SMB_ACL_T sys_acl_init(int count);
4803 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4804 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4805 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4806 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4807 +int sys_acl_valid(SMB_ACL_T theacl);
4808 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4809 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4810 +int sys_acl_delete_def_file(const char *name);
4811 +int sys_acl_free_text(char *text);
4812 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4813 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4816 @@ -58,7 +58,7 @@ BEGIN {
4820 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4821 +!/^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/ {
4827 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4829 int preserve_links = 0;
4830 int preserve_hard_links = 0;
4831 +int preserve_acls = 0;
4832 int preserve_perms = 0;
4833 int preserve_executability = 0;
4834 int preserve_devices = 0;
4835 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4836 char const *got_socketpair = "no ";
4837 char const *have_inplace = "no ";
4838 char const *hardlinks = "no ";
4839 + char const *acls = "no ";
4840 char const *links = "no ";
4841 char const *ipv6 = "no ";
4842 STRUCT_STAT *dumstat;
4843 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4847 +#ifdef SUPPORT_ACLS
4851 #ifdef SUPPORT_LINKS
4854 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4855 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4856 rprintf(f, "<http://rsync.samba.org/>\n");
4857 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4858 - "%shard links, %ssymlinks, batchfiles,\n",
4859 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4860 (int) (sizeof (OFF_T) * 8),
4861 - got_socketpair, hardlinks, links);
4862 + got_socketpair, hardlinks, acls, links);
4864 /* Note that this field may not have type ino_t. It depends
4865 * on the complicated interaction between largefile feature
4866 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4867 rprintf(F," -H, --hard-links preserve hard links\n");
4868 rprintf(F," -p, --perms preserve permissions\n");
4869 rprintf(F," -E, --executability preserve the file's executability\n");
4870 +#ifdef SUPPORT_ACLS
4871 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4873 rprintf(F," --chmod=CHMOD change destination permissions\n");
4874 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4875 rprintf(F," -g, --group preserve group\n");
4876 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4877 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4878 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4879 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4880 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4881 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4882 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4883 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4884 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4885 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4886 @@ -1068,6 +1080,23 @@ int parse_arguments(int *argc, const cha
4891 +#ifdef SUPPORT_ACLS
4892 + preserve_acls = preserve_perms = 1;
4895 + /* FIXME: this should probably be ignored with a
4896 + * warning and then countermeasures taken to
4897 + * restrict group and other access in the presence
4898 + * of any more restrictive ACLs, but this is safe
4900 + snprintf(err_buf,sizeof(err_buf),
4901 + "ACLs are not supported on this %s\n",
4902 + am_server ? "server" : "client");
4908 /* A large opt value means that set_refuse_options()
4909 * turned this option off. */
4910 @@ -1511,6 +1540,10 @@ void server_options(char **args,int *arg
4912 if (preserve_hard_links)
4914 +#ifdef SUPPORT_ACLS
4915 + if (preserve_acls)
4916 + argstr[x++] = 'A';
4923 @@ -46,6 +46,7 @@ extern int keep_partial;
4924 extern int checksum_seed;
4926 extern int delay_updates;
4927 +extern mode_t orig_umask;
4928 extern struct stats stats;
4929 extern char *log_format;
4930 extern char *tmpdir;
4931 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4932 int itemizing = am_daemon ? daemon_log_format_has_i
4933 : !am_server && log_format_has_i;
4934 int max_phase = protocol_version >= 29 ? 2 : 1;
4935 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4936 +#ifdef SUPPORT_ACLS
4937 + char *parent_dirname = "";
4942 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
4943 * mode based on the local permissions and some heuristics. */
4944 if (!preserve_perms) {
4945 int exists = fd1 != -1;
4946 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4947 +#ifdef SUPPORT_ACLS
4948 + char *dn = file->dirname ? file->dirname : ".";
4949 + if (parent_dirname != dn
4950 + && strcmp(parent_dirname, dn) != 0) {
4951 + dflt_perms = default_perms_for_dir(dn);
4952 + parent_dirname = dn;
4955 + file->mode = dest_mode(file->mode, st.st_mode,
4956 + dflt_perms, exists);
4959 /* We now check to see if we are writing file "inplace" */
4965 extern int daemon_log_format_has_i;
4966 +extern int preserve_acls;
4967 extern int preserve_perms;
4968 extern int preserve_executability;
4969 extern int preserve_times;
4970 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
4972 /* This is only called when we aren't preserving permissions. Figure out what
4973 * the permissions should be and return them merged back into the mode. */
4974 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4975 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
4978 /* If the file already exists, we'll return the local permissions,
4979 * possibly tweaked by the --executability option. */
4980 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4981 cur_mode |= (cur_mode & 0444) >> 2;
4984 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
4985 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
4986 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
4987 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
4988 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
4989 @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
4993 +#ifdef SUPPORT_ACLS
4994 + /* It's OK to call set_acl() now, even for a dir, as the generator
4995 + * will enable owner-writability using chmod, if necessary.
4997 + * If set_acl changes permission bits in the process of setting
4998 + * an access ACL, it changes st->st_mode so we know whether we
4999 + * need to chmod. */
5000 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5005 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5006 - int ret = do_chmod(fname, file->mode);
5007 + mode_t mode = file->mode;
5008 + int ret = do_chmod(fname, mode);
5010 rsyserr(FERROR, errno,
5011 "failed to set permissions on %s",
5014 @@ -658,6 +658,20 @@ struct chmod_mode_struct;
5016 #define UNUSED(x) x __attribute__((__unused__))
5018 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5019 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5020 +#define SUPPORT_ACLS 1
5023 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5024 +#define ACLS_NEED_MASK 1
5027 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5028 +#include <sys/acl.h>
5030 +#include "smb_acls.h"
5034 /* We have replacement versions of these if they're missing. */
5037 @@ -321,6 +321,7 @@ to the detailed description below for a
5038 -H, --hard-links preserve hard links
5039 -p, --perms preserve permissions
5040 -E, --executability preserve executability
5041 + -A, --acls preserve ACLs (implies -p) [non-standard]
5042 --chmod=CHMOD change destination permissions
5043 -o, --owner preserve owner (super-user only)
5044 -g, --group preserve group
5045 @@ -742,7 +743,9 @@ quote(itemize(
5046 permissions, though the bf(--executability) option might change just
5047 the execute permission for the file.
5048 it() New files get their "normal" permission bits set to the source
5049 - file's permissions masked with the receiving end's umask setting, and
5050 + file's permissions masked with the receiving directory's default
5051 + permissions (either the receiving process's umask, or the permissions
5052 + specified via the destination directory's default ACL), and
5053 their special permission bits disabled except in the case where a new
5054 directory inherits a setgid bit from its parent directory.
5056 @@ -773,9 +776,11 @@ The preservation of the destination's se
5057 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5058 versions erroneously preserved the three special permission bits for
5059 newly-created files when bf(--perms) was off, while overriding the
5060 -destination's setgid bit setting on a newly-created directory. (Keep in
5061 -mind that it is the version of the receiving rsync that affects this
5063 +destination's setgid bit setting on a newly-created directory. Default ACL
5064 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5065 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5066 +(Keep in mind that it is the version of the receiving rsync that affects
5069 dit(bf(-E, --executability)) This option causes rsync to preserve the
5070 executability (or non-executability) of regular files when bf(--perms) is
5071 @@ -793,6 +798,10 @@ quote(itemize(
5073 If bf(--perms) is enabled, this option is ignored.
5075 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5076 +ACLs to be the same as the source ACLs. This nonstandard option only
5077 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5079 dit(bf(--chmod)) This option tells rsync to apply one or more
5080 comma-separated "chmod" strings to the permission of the files in the
5081 transfer. The resulting value is treated as though it was the permissions
5086 + Unix SMB/Netbios implementation.
5088 + Portable SMB ACL interface
5089 + Copyright (C) Jeremy Allison 2000
5091 + This program is free software; you can redistribute it and/or modify
5092 + it under the terms of the GNU General Public License as published by
5093 + the Free Software Foundation; either version 2 of the License, or
5094 + (at your option) any later version.
5096 + This program is distributed in the hope that it will be useful,
5097 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5098 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5099 + GNU General Public License for more details.
5101 + You should have received a copy of the GNU General Public License
5102 + along with this program; if not, write to the Free Software
5103 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5106 +#ifndef _SMB_ACLS_H
5107 +#define _SMB_ACLS_H
5109 +#if defined HAVE_POSIX_ACLS
5111 +/* This is an identity mapping (just remove the SMB_). */
5113 +#define SMB_ACL_TAG_T acl_tag_t
5114 +#define SMB_ACL_TYPE_T acl_type_t
5115 +#define SMB_ACL_PERMSET_T acl_permset_t
5116 +#define SMB_ACL_PERM_T acl_perm_t
5117 +#define SMB_ACL_READ ACL_READ
5118 +#define SMB_ACL_WRITE ACL_WRITE
5119 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5121 +/* Types of ACLs. */
5122 +#define SMB_ACL_USER ACL_USER
5123 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5124 +#define SMB_ACL_GROUP ACL_GROUP
5125 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5126 +#define SMB_ACL_OTHER ACL_OTHER
5127 +#define SMB_ACL_MASK ACL_MASK
5129 +#define SMB_ACL_T acl_t
5131 +#define SMB_ACL_ENTRY_T acl_entry_t
5133 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5134 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5136 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5137 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5139 +#elif defined HAVE_TRU64_ACLS
5141 +/* This is for DEC/Compaq Tru64 UNIX */
5143 +#define SMB_ACL_TAG_T acl_tag_t
5144 +#define SMB_ACL_TYPE_T acl_type_t
5145 +#define SMB_ACL_PERMSET_T acl_permset_t
5146 +#define SMB_ACL_PERM_T acl_perm_t
5147 +#define SMB_ACL_READ ACL_READ
5148 +#define SMB_ACL_WRITE ACL_WRITE
5149 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5151 +/* Types of ACLs. */
5152 +#define SMB_ACL_USER ACL_USER
5153 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5154 +#define SMB_ACL_GROUP ACL_GROUP
5155 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5156 +#define SMB_ACL_OTHER ACL_OTHER
5157 +#define SMB_ACL_MASK ACL_MASK
5159 +#define SMB_ACL_T acl_t
5161 +#define SMB_ACL_ENTRY_T acl_entry_t
5163 +#define SMB_ACL_FIRST_ENTRY 0
5164 +#define SMB_ACL_NEXT_ENTRY 1
5166 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5167 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5169 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5171 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5172 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5175 +/* SVR4.2 ES/MP ACLs */
5176 +typedef int SMB_ACL_TAG_T;
5177 +typedef int SMB_ACL_TYPE_T;
5178 +typedef ushort *SMB_ACL_PERMSET_T;
5179 +typedef ushort SMB_ACL_PERM_T;
5180 +#define SMB_ACL_READ 4
5181 +#define SMB_ACL_WRITE 2
5182 +#define SMB_ACL_EXECUTE 1
5184 +/* Types of ACLs. */
5185 +#define SMB_ACL_USER USER
5186 +#define SMB_ACL_USER_OBJ USER_OBJ
5187 +#define SMB_ACL_GROUP GROUP
5188 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5189 +#define SMB_ACL_OTHER OTHER_OBJ
5190 +#define SMB_ACL_MASK CLASS_OBJ
5192 +typedef struct SMB_ACL_T {
5196 + struct acl acl[1];
5199 +typedef struct acl *SMB_ACL_ENTRY_T;
5201 +#define SMB_ACL_FIRST_ENTRY 0
5202 +#define SMB_ACL_NEXT_ENTRY 1
5204 +#define SMB_ACL_TYPE_ACCESS 0
5205 +#define SMB_ACL_TYPE_DEFAULT 1
5207 +#elif defined HAVE_HPUX_ACLS
5210 + * Based on the Solaris & UnixWare code.
5214 +#include <sys/aclv.h>
5216 +/* SVR4.2 ES/MP ACLs */
5217 +typedef int SMB_ACL_TAG_T;
5218 +typedef int SMB_ACL_TYPE_T;
5219 +typedef ushort *SMB_ACL_PERMSET_T;
5220 +typedef ushort SMB_ACL_PERM_T;
5221 +#define SMB_ACL_READ 4
5222 +#define SMB_ACL_WRITE 2
5223 +#define SMB_ACL_EXECUTE 1
5225 +/* Types of ACLs. */
5226 +#define SMB_ACL_USER USER
5227 +#define SMB_ACL_USER_OBJ USER_OBJ
5228 +#define SMB_ACL_GROUP GROUP
5229 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5230 +#define SMB_ACL_OTHER OTHER_OBJ
5231 +#define SMB_ACL_MASK CLASS_OBJ
5233 +typedef struct SMB_ACL_T {
5237 + struct acl acl[1];
5240 +typedef struct acl *SMB_ACL_ENTRY_T;
5242 +#define SMB_ACL_FIRST_ENTRY 0
5243 +#define SMB_ACL_NEXT_ENTRY 1
5245 +#define SMB_ACL_TYPE_ACCESS 0
5246 +#define SMB_ACL_TYPE_DEFAULT 1
5248 +#elif defined HAVE_IRIX_ACLS
5250 +#define SMB_ACL_TAG_T acl_tag_t
5251 +#define SMB_ACL_TYPE_T acl_type_t
5252 +#define SMB_ACL_PERMSET_T acl_permset_t
5253 +#define SMB_ACL_PERM_T acl_perm_t
5254 +#define SMB_ACL_READ ACL_READ
5255 +#define SMB_ACL_WRITE ACL_WRITE
5256 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5258 +/* Types of ACLs. */
5259 +#define SMB_ACL_USER ACL_USER
5260 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5261 +#define SMB_ACL_GROUP ACL_GROUP
5262 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5263 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5264 +#define SMB_ACL_MASK ACL_MASK
5266 +typedef struct SMB_ACL_T {
5272 +#define SMB_ACL_ENTRY_T acl_entry_t
5274 +#define SMB_ACL_FIRST_ENTRY 0
5275 +#define SMB_ACL_NEXT_ENTRY 1
5277 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5278 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5280 +#elif defined HAVE_AIX_ACLS
5282 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5284 +#include "/usr/include/acl.h"
5286 +typedef uint *SMB_ACL_PERMSET_T;
5288 +struct acl_entry_link{
5289 + struct acl_entry_link *prevp;
5290 + struct new_acl_entry *entryp;
5291 + struct acl_entry_link *nextp;
5295 +struct new_acl_entry{
5296 + unsigned short ace_len;
5297 + unsigned short ace_type;
5298 + unsigned int ace_access;
5299 + struct ace_id ace_id[1];
5302 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5303 +#define SMB_ACL_T struct acl_entry_link*
5305 +#define SMB_ACL_TAG_T unsigned short
5306 +#define SMB_ACL_TYPE_T int
5307 +#define SMB_ACL_PERM_T uint
5308 +#define SMB_ACL_READ S_IRUSR
5309 +#define SMB_ACL_WRITE S_IWUSR
5310 +#define SMB_ACL_EXECUTE S_IXUSR
5312 +/* Types of ACLs. */
5313 +#define SMB_ACL_USER ACEID_USER
5314 +#define SMB_ACL_USER_OBJ 3
5315 +#define SMB_ACL_GROUP ACEID_GROUP
5316 +#define SMB_ACL_GROUP_OBJ 4
5317 +#define SMB_ACL_OTHER 5
5318 +#define SMB_ACL_MASK 6
5321 +#define SMB_ACL_FIRST_ENTRY 1
5322 +#define SMB_ACL_NEXT_ENTRY 2
5324 +#define SMB_ACL_TYPE_ACCESS 0
5325 +#define SMB_ACL_TYPE_DEFAULT 1
5327 +#else /* No ACLs. */
5329 +/* No ACLS - fake it. */
5330 +#define SMB_ACL_TAG_T int
5331 +#define SMB_ACL_TYPE_T int
5332 +#define SMB_ACL_PERMSET_T mode_t
5333 +#define SMB_ACL_PERM_T mode_t
5334 +#define SMB_ACL_READ S_IRUSR
5335 +#define SMB_ACL_WRITE S_IWUSR
5336 +#define SMB_ACL_EXECUTE S_IXUSR
5338 +/* Types of ACLs. */
5339 +#define SMB_ACL_USER 0
5340 +#define SMB_ACL_USER_OBJ 1
5341 +#define SMB_ACL_GROUP 2
5342 +#define SMB_ACL_GROUP_OBJ 3
5343 +#define SMB_ACL_OTHER 4
5344 +#define SMB_ACL_MASK 5
5346 +typedef struct SMB_ACL_T {
5350 +typedef struct SMB_ACL_ENTRY_T {
5352 +} *SMB_ACL_ENTRY_T;
5354 +#define SMB_ACL_FIRST_ENTRY 0
5355 +#define SMB_ACL_NEXT_ENTRY 1
5357 +#define SMB_ACL_TYPE_ACCESS 0
5358 +#define SMB_ACL_TYPE_DEFAULT 1
5360 +#endif /* No ACLs. */
5361 +#endif /* _SMB_ACLS_H */
5362 --- old/testsuite/default-acls.test
5363 +++ new/testsuite/default-acls.test
5367 +# This program is distributable under the terms of the GNU GPL see
5370 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5372 +. $srcdir/testsuite/rsync.fns
5374 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5375 +setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5377 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5379 + todir="$scratchdir/$1"
5381 + # FIXME This doesn't work on solaris...
5382 + setfacl -k "$todir"
5383 + [ "$2" ] && setfacl -dm "$2" "$todir"
5384 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5385 + # even though the directory itself is outside the transfer
5386 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5387 + check_perms "$todir/to" $4 "Target $1"
5388 + check_perms "$todir/to/dir" $4 "Target $1"
5389 + check_perms "$todir/to/file" $3 "Target $1"
5390 + check_perms "$todir/to/program" $4 "Target $1"
5391 + # Make sure get_local_name doesn't mess us up when transferring only one file
5392 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5393 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5394 + # Make sure we obey default ACLs when not transferring a regular file
5395 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5396 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5399 +mkdir "$scratchdir/dir"
5400 +echo "File!" >"$scratchdir/file"
5401 +echo "#!/bin/sh" >"$scratchdir/program"
5402 +chmod 777 "$scratchdir/dir"
5403 +chmod 666 "$scratchdir/file"
5404 +chmod 777 "$scratchdir/program"
5406 +# Test some target directories
5408 +testit da777 u::rwx,g::rwx,o::rwx rw-rw-rw- rwxrwxrwx
5409 +testit da775 u::rwx,g::rwx,o::r-x rw-rw-r-- rwxrwxr-x
5410 +testit da750 u::rwx,g::r-x,o::--- rw-r----- rwxr-x---
5411 +testit da770mask u::rwx,g::---,m::rwx,o::--- rw-rw---- rwxrwx---
5412 +testit noda1 '' rw------- rwx------
5414 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5416 +testit noda3 '' rw-r--r-- rwxr-xr-x
5424 extern int preserve_uid;
5425 extern int preserve_gid;
5426 +extern int preserve_acls;
5427 extern int numeric_ids;
5430 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5434 - if (preserve_uid) {
5435 + if (preserve_uid || preserve_acls) {
5437 /* we send sequences of uid/byte-length/name */
5438 for (list = uidlist; list; list = list->next) {
5439 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5443 - if (preserve_gid) {
5444 + if (preserve_gid || preserve_acls) {
5446 for (list = gidlist; list; list = list->next) {
5448 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5452 - if (preserve_uid && !numeric_ids) {
5453 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5454 /* read the uid list */
5455 while ((id = read_int(f)) != 0) {
5456 int len = read_byte(f);
5457 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5461 - if (preserve_gid && !numeric_ids) {
5462 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5463 /* read the gid list */
5464 while ((id = read_int(f)) != 0) {
5465 int len = read_byte(f);
5466 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5470 +#ifdef SUPPORT_ACLS
5471 + if (preserve_acls && !numeric_ids) {
5473 + while ((id = next_acl_uid(flist)) != NULL)
5474 + *id = match_uid(*id);
5475 + while ((id = next_acl_gid(flist)) != NULL)
5476 + *id = match_gid(*id);
5480 /* Now convert all the uids/gids from sender values to our values. */
5481 if (am_root && preserve_uid && !numeric_ids) {
5482 for (i = 0; i < flist->count; i++)