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, char 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 CALL_OR_ERROR(func,args,str) \
594 +#define COE(func,args) CALL_OR_ERROR(func,args,#func)
595 +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
597 +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
599 + const char *errfun = NULL;
600 + SMB_ACL_PERMSET_T permset;
602 + COE( sys_acl_get_permset,(entry, &permset) );
603 + COE( sys_acl_clear_perms,(permset) );
605 + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
607 + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) );
609 + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) );
610 + COE( sys_acl_set_permset,(entry, permset) );
615 + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun,
620 +/* build an SMB_ACL_T corresponding to an rsync_acl */
621 +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
625 + const char *errfun = NULL;
626 + SMB_ACL_ENTRY_T entry;
628 + if (!(*smb_acl = sys_acl_init(rsync_acl_count_entries(racl)))) {
629 + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
634 + COE( sys_acl_create_entry,(smb_acl, &entry) );
635 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
636 + COE2( store_access_in_entry,(racl->user_obj, entry) );
638 + for (ida = racl->users.idas, count = racl->users.count;
640 + COE( sys_acl_create_entry,(smb_acl, &entry) );
641 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) );
642 + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
643 + COE2( store_access_in_entry,(ida->access, entry) );
646 + COE( sys_acl_create_entry,(smb_acl, &entry) );
647 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
648 + COE2( 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 + COE2( store_access_in_entry,(ida->access, entry) );
657 + if (racl->mask != NO_ENTRY) {
658 + COE( sys_acl_create_entry,(smb_acl, &entry) );
659 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
660 + COE2( store_access_in_entry,(racl->mask, entry) );
663 + COE( sys_acl_create_entry,(smb_acl, &entry) );
664 + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
665 + COE2( store_access_in_entry,(racl->other, entry) );
668 + if (sys_acl_valid(*smb_acl) < 0)
669 + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
676 + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
679 + sys_acl_free_acl(*smb_acl);
683 +static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode)
685 + SMB_ACL_ENTRY_T entry;
686 + int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ;
687 + const char *errfun;
690 + if (S_ISDIR(mode)) {
691 + /* If the sticky bit is going on, it's not safe to allow all
692 + * the new ACLs to go into effect before it gets set. */
693 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
696 + /* If setuid or setgid is going off, it's not safe to allow all
697 + * the new ACLs to go into effect before they get cleared. */
698 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
699 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
703 + errfun = "sys_acl_get_entry";
704 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
706 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
707 + SMB_ACL_TAG_T tag_type;
708 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
709 + errfun = "sys_acl_get_tag_type";
712 + if (tag_type == SMB_ACL_USER_OBJ)
713 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
714 + else if (tag_type == group_id)
715 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
716 + else if (tag_type == SMB_ACL_OTHER)
717 + COE2( store_access_in_entry,(mode & 7, entry) );
722 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
723 + errfun, strerror(errno));
728 + /* Return the mode of the file on disk, as we will set them. */
729 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
732 +static void receive_rsync_acl(rsync_acl *racl, int f)
734 + uchar computed_mask_bits = 0;
735 + ida_list *idal = NULL;
739 + *racl = rsync_acl_initializer;
741 + if (!(count = read_int(f)))
745 + char tag = read_byte(f);
746 + uchar access = read_byte(f);
747 + if (access & ~ (4 | 2 | 1)) {
748 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
750 + exit_cleanup(RERR_STREAMIO);
754 + if (racl->user_obj != NO_ENTRY) {
755 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
756 + exit_cleanup(RERR_STREAMIO);
758 + racl->user_obj = access;
761 + idal = &racl->users;
764 + if (racl->group_obj != NO_ENTRY) {
765 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
766 + exit_cleanup(RERR_STREAMIO);
768 + racl->group_obj = access;
771 + idal = &racl->groups;
774 + if (racl->mask != NO_ENTRY) {
775 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
776 + exit_cleanup(RERR_STREAMIO);
778 + racl->mask = access;
781 + if (racl->other != NO_ENTRY) {
782 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
783 + exit_cleanup(RERR_STREAMIO);
785 + racl->other = access;
788 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
790 + exit_cleanup(RERR_STREAMIO);
792 + expand_ida_list(idal);
793 + ida = &idal->idas[idal->count++];
794 + ida->access = access;
795 + ida->id = read_int(f);
796 + computed_mask_bits |= access;
799 + /* Ensure that these are never unset. */
800 + if (racl->user_obj == NO_ENTRY)
801 + racl->user_obj = 7;
802 + if (racl->group_obj == NO_ENTRY)
803 + racl->group_obj = 0;
804 + if (racl->other == NO_ENTRY)
806 +#ifndef ACLS_NEED_MASK
807 + if (!racl->users.count && !racl->groups.count) {
808 + /* If we, a system without ACLS_NEED_MASK, received a
809 + * superfluous mask, throw it away. */
810 + if (racl->mask != NO_ENTRY) {
811 + /* mask off group perms with it first */
812 + racl->group_obj &= racl->mask;
813 + racl->mask = NO_ENTRY;
817 + if (racl->mask == NO_ENTRY)
818 + racl->mask = computed_mask_bits | racl->group_obj;
821 +/* receive and build the rsync_acl_lists */
822 +void receive_acl(struct file_struct *file, int f)
824 + SMB_ACL_TYPE_T type;
827 + if (S_ISLNK(file->mode))
830 + fname = f_name(file, NULL);
831 + type = SMB_ACL_TYPE_ACCESS;
833 + file_acl_index_list *fileaclidx_list =
834 + file_acl_index_lists(type);
836 + expand_file_acl_index_list(fileaclidx_list);
838 + tag = read_byte(f);
839 + if (tag == 'A' || tag == 'a') {
840 + if (type != SMB_ACL_TYPE_ACCESS) {
841 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
843 + exit_cleanup(RERR_STREAMIO);
845 + } else if (tag == 'D' || tag == 'd') {
846 + if (type == SMB_ACL_TYPE_ACCESS) {
847 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
849 + exit_cleanup(RERR_STREAMIO);
852 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
854 + exit_cleanup(RERR_STREAMIO);
856 + if (tag == 'A' || tag == 'D') {
858 + rsync_acl_list *racl_list = rsync_acl_lists(type);
859 + smb_acl_list *sacl_list = smb_acl_lists(type);
860 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
861 + aclidx = racl_list->count;
862 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
864 + receive_rsync_acl(&racl, f);
865 + expand_rsync_acl_list(racl_list);
866 + racl_list->racls[racl_list->count++] = racl;
867 + expand_smb_acl_list(sacl_list);
868 + sacl_list->sacls[sacl_list->count++] = NULL;
870 + int index = read_int(f);
871 + rsync_acl_list *racl_list = rsync_acl_lists(type);
872 + if ((size_t) index >= racl_list->count) {
873 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
875 + str_acl_type(type),
877 + exit_cleanup(RERR_STREAMIO);
879 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
881 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
884 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
887 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
889 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
890 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
891 + return fileaclidx1->file == fileaclidx2->file ? 0 :
892 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
895 +void sort_file_acl_index_lists()
897 + SMB_ACL_TYPE_T type;
899 + type = SMB_ACL_TYPE_ACCESS;
901 + file_acl_index_list *fileaclidx_list =
902 + file_acl_index_lists(type);
903 + if (!fileaclidx_list->count)
905 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
906 + sizeof fileaclidx_list->fileaclidxs[0],
907 + &file_acl_index_list_sorter);
908 + } while (BUMP_TYPE(type));
911 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
912 + const struct file_struct *file) {
913 + int low = 0, high = fileaclidx_list->count;
914 + const struct file_struct *file_mid;
918 + int mid = (high + low) / 2;
919 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
920 + if (file_mid == file)
921 + return fileaclidx_list->fileaclidxs[mid].aclidx;
922 + if (file_mid > file)
926 + } while (low < high);
928 + file_mid = fileaclidx_list->fileaclidxs[low].file;
929 + if (file_mid == file)
930 + return fileaclidx_list->fileaclidxs[low].aclidx;
933 + "find_file_acl_index: can't find entry for file in list\n");
934 + exit_cleanup(RERR_STREAMIO);
938 +/* for duplicating ACLs on backups when using backup_dir */
939 +int dup_acl(const char *orig, const char *bak, mode_t mode)
941 + SMB_ACL_TYPE_T type;
944 + type = SMB_ACL_TYPE_ACCESS;
946 + SMB_ACL_T sacl_orig, sacl_bak;
947 + rsync_acl racl_orig, racl_bak;
948 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
949 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
950 + orig, str_acl_type(type), strerror(errno));
954 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
955 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
956 + bak, str_acl_type(type), strerror(errno));
958 + /* try to forge on through */
960 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
962 + goto out_with_sacls;
965 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
967 + goto out_with_one_racl;
969 + if (rsync_acls_equal(&racl_orig, &racl_bak))
972 + ; /* presume they're unequal */
974 + if (type == SMB_ACL_TYPE_DEFAULT
975 + && rsync_acl_count_entries(&racl_orig) == 0) {
976 + if (sys_acl_delete_def_file(bak) < 0) {
977 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
978 + bak, strerror(errno));
981 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
982 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
983 + bak, str_acl_type(type), strerror(errno));
988 + rsync_acl_free(&racl_bak);
990 + rsync_acl_free(&racl_orig);
993 + sys_acl_free_acl(sacl_bak);
994 + /* out_with_one_sacl: */
996 + sys_acl_free_acl(sacl_orig);
997 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1002 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1003 + * for keep_backup(). */
1004 +static const struct file_struct *backup_orig_file = NULL;
1005 +static const char null_string[] = "";
1006 +static const char *backup_orig_fname = null_string;
1007 +static const char *backup_dest_fname = null_string;
1008 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1010 +void push_keep_backup_acl(const struct file_struct *file,
1011 + const char *orig, const char *dest)
1013 + SMB_ACL_TYPE_T type;
1016 + backup_orig_file = file;
1017 + backup_orig_fname = orig;
1018 + backup_dest_fname = dest;
1020 + sacl = &_backup_sacl[0];
1021 + type = SMB_ACL_TYPE_ACCESS;
1023 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1027 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1029 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1030 + orig, str_acl_type(type),
1033 + } while (BUMP_TYPE(type));
1036 +static int set_keep_backup_acl()
1038 + SMB_ACL_TYPE_T type;
1042 + sacl = &_backup_sacl[0];
1043 + type = SMB_ACL_TYPE_ACCESS;
1046 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1048 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1049 + backup_dest_fname,
1050 + str_acl_type(type),
1054 + } while (BUMP_TYPE(type));
1059 +void cleanup_keep_backup_acl()
1061 + SMB_ACL_TYPE_T type;
1064 + backup_orig_file = NULL;
1065 + backup_orig_fname = null_string;
1066 + backup_dest_fname = null_string;
1068 + sacl = &_backup_sacl[0];
1069 + type = SMB_ACL_TYPE_ACCESS;
1072 + sys_acl_free_acl(*sacl);
1075 + } while (BUMP_TYPE(type));
1078 +/* set ACL on rsync-ed or keep_backup-ed file
1080 + * This sets extended access ACL entries and default ACLs. If convenient,
1081 + * it sets permission bits along with the access ACLs and signals having
1082 + * done so by modifying p_mode, which should point into the stat buffer.
1084 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1085 + * Pass NULL for p_mode to get the return code without changing anything. */
1086 +int set_acl(const char *fname, const struct file_struct *file, mode_t *p_mode)
1088 + int unchanged = 1;
1089 + SMB_ACL_TYPE_T type;
1091 + if (S_ISLNK(file->mode))
1094 + if (file == backup_orig_file) {
1095 + if (!strcmp(fname, backup_dest_fname))
1096 + return set_keep_backup_acl();
1098 + type = SMB_ACL_TYPE_ACCESS;
1101 + SMB_ACL_T sacl_orig, *sacl_new;
1102 + rsync_acl racl_orig, *racl_new;
1103 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1105 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1106 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1107 + sacl_orig = sys_acl_get_file(fname, type);
1109 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1110 + fname, str_acl_type(type), strerror(errno));
1114 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1115 + sys_acl_free_acl(sacl_orig);
1120 + if (type == SMB_ACL_TYPE_ACCESS)
1121 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new);
1123 + ok = rsync_acls_equal(&racl_orig, racl_new);
1124 + rsync_acl_free(&racl_orig);
1127 + if (!dry_run && p_mode) {
1128 + if (type == SMB_ACL_TYPE_DEFAULT
1129 + && rsync_acl_count_entries(racl_new) == 0) {
1130 + if (sys_acl_delete_def_file(fname) < 0) {
1131 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1132 + fname, strerror(errno));
1137 + mode_t cur_mode = *p_mode;
1139 + && !pack_smb_acl(sacl_new, racl_new)) {
1143 + if (type == SMB_ACL_TYPE_ACCESS) {
1144 + cur_mode = change_sacl_perms(*sacl_new, racl_new->mask,
1145 + cur_mode, file->mode);
1146 + if (cur_mode == ~0u)
1149 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1150 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1151 + fname, str_acl_type(type),
1156 + if (type == SMB_ACL_TYPE_ACCESS)
1157 + *p_mode = cur_mode;
1160 + if (unchanged == 1)
1162 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1167 +/* Enumeration functions for uid mapping: */
1169 +/* Context -- one and only one. Should be cycled through once on uid
1170 + * mapping and once on gid mapping. */
1171 +static rsync_acl_list *_enum_racl_lists[] = {
1172 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1175 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1176 +static size_t enum_racl_index = 0;
1177 +static size_t enum_ida_index = 0;
1179 +/* This returns the next tag_type id from the given acl for the next entry,
1180 + * or it returns 0 if there are no more tag_type ids in the acl. */
1181 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1183 + const ida_list *idal = (tag_type == SMB_ACL_USER ?
1184 + &racl->users : &racl->groups);
1185 + if (enum_ida_index < idal->count) {
1186 + id_access *ida = &idal->idas[enum_ida_index++];
1189 + enum_ida_index = 0;
1193 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1195 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1196 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1197 + id_t *id = next_ace_id(tag_type, racl);
1201 + enum_racl_index = 0;
1205 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1207 + for (; *enum_racl_list; enum_racl_list++) {
1208 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1212 + enum_racl_list = &_enum_racl_lists[0];
1216 +id_t *next_acl_uid()
1218 + return next_acl_list_id(SMB_ACL_USER);
1221 +id_t *next_acl_gid()
1223 + return next_acl_list_id(SMB_ACL_GROUP);
1226 +int default_perms_for_dir(const char *dir)
1235 + perms = ACCESSPERMS & ~orig_umask;
1236 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1237 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1238 + if (sacl == NULL) {
1239 + /* Couldn't get an ACL. Darn. */
1242 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1246 + /* We're doing a dry run, so the containing directory
1247 + * wasn't actually created. Don't worry about it. */
1250 + /* Otherwise fall through. */
1252 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1253 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1259 + ok = unpack_smb_acl(&racl, sacl);
1260 + sys_acl_free_acl(sacl);
1262 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1266 + /* Apply the permission-bit entries of the default ACL, if any. */
1267 + if (rsync_acl_count_entries(&racl) > 0) {
1268 + perms = rsync_acl_get_perms(&racl);
1270 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1273 + rsync_acl_free(&racl);
1277 +#endif /* SUPPORT_ACLS */
1280 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1281 extern char *backup_dir;
1284 +extern int preserve_acls;
1285 extern int preserve_devices;
1286 extern int preserve_specials;
1287 extern int preserve_links;
1288 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1290 do_lchown(fullpath, st.st_uid, st.st_gid);
1291 do_chmod(fullpath, st.st_mode);
1292 +#ifdef SUPPORT_ACLS
1293 + if (preserve_acls)
1294 + dup_acl(end, fullpath, st.st_mode);
1299 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1300 if (!(buf = get_backup_name(fname)))
1303 +#ifdef SUPPORT_ACLS
1304 + if (preserve_acls)
1305 + push_keep_backup_acl(file, fname, buf);
1308 /* Check to see if this is a device file, or link */
1309 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1310 || (preserve_specials && IS_SPECIAL(file->mode))) {
1311 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1314 set_file_attrs(buf, file, NULL, 0);
1315 +#ifdef SUPPORT_ACLS
1316 + if (preserve_acls)
1317 + cleanup_keep_backup_acl();
1322 --- old/configure.in
1323 +++ new/configure.in
1324 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1325 AC_CHECK_LIB(resolv, strcasecmp)
1328 +AC_CHECK_FUNCS(aclsort)
1329 +if test x"$ac_cv_func_aclsort" = x"no"; then
1330 + AC_CHECK_LIB(sec, aclsort)
1333 dnl At the moment we don't test for a broken memcmp(), because all we
1334 dnl need to do is test for equality, not comparison, and it seems that
1335 dnl every platform has a memcmp that can do at least that.
1336 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1337 AC_SUBST(CC_SHOBJ_FLAG)
1338 AC_SUBST(BUILD_POPT)
1340 +AC_CHECK_HEADERS(sys/acl.h)
1341 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1342 +#################################################
1343 +# check for ACL support
1345 +AC_MSG_CHECKING(whether to support ACLs)
1346 +AC_ARG_ENABLE(acl-support,
1347 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1348 +[ case "$enableval" in
1351 + case "$host_os" in
1353 + AC_MSG_RESULT(Using UnixWare ACLs)
1354 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1357 + AC_MSG_RESULT(Using solaris ACLs)
1358 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1361 + AC_MSG_RESULT(Using HPUX ACLs)
1362 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1365 + AC_MSG_RESULT(Using IRIX ACLs)
1366 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1369 + AC_MSG_RESULT(Using AIX ACLs)
1370 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1373 + AC_MSG_RESULT(Using Tru64 ACLs)
1374 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1375 + LIBS="$LIBS -lpacl"
1378 + AC_MSG_RESULT(ACLs requested -- running tests)
1379 + AC_CHECK_LIB(acl,acl_get_file)
1380 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1381 + AC_TRY_LINK([#include <sys/types.h>
1382 +#include <sys/acl.h>],
1383 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1384 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1385 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1386 + AC_MSG_RESULT(Using posix ACLs)
1387 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1388 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1389 + AC_TRY_LINK([#include <sys/types.h>
1390 +#include <sys/acl.h>],
1391 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1392 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1393 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1394 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1397 + AC_MSG_ERROR(Failed to find ACL support)
1404 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1407 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1411 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1416 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1417 extern int one_file_system;
1418 extern int copy_dirlinks;
1419 extern int keep_dirlinks;
1420 +extern int preserve_acls;
1421 extern int preserve_links;
1422 extern int preserve_hard_links;
1423 extern int preserve_devices;
1424 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1425 if (chmod_modes && !S_ISLNK(file->mode))
1426 file->mode = tweak_mode(file->mode, chmod_modes);
1428 +#ifdef SUPPORT_ACLS
1429 + if (preserve_acls && make_acl(file, fname) < 0)
1433 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1435 flist_expand(flist);
1436 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1437 if (file->basename[0]) {
1438 flist->files[flist->count++] = file;
1439 send_file_entry(file, f);
1440 +#ifdef SUPPORT_ACLS
1441 + if (preserve_acls)
1442 + send_acl(file, f);
1445 +#ifdef SUPPORT_ACLS
1446 + /* Cleanup unsent ACL(s). */
1447 + if (preserve_acls)
1448 + send_acl(file, -1);
1453 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1454 flags |= read_byte(f) << 8;
1455 file = receive_file_entry(flist, flags, f);
1457 +#ifdef SUPPORT_ACLS
1458 + if (preserve_acls)
1459 + receive_acl(file, f);
1462 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1463 stats.total_size += file->length;
1465 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1467 clean_flist(flist, relative_paths, 1);
1469 +#ifdef SUPPORT_ACLS
1470 + if (preserve_acls)
1471 + sort_file_acl_index_lists();
1475 recv_uid_list(f, flist);
1479 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1480 extern int max_delete;
1481 extern int force_delete;
1482 extern int one_file_system;
1483 +extern mode_t orig_umask;
1484 extern struct stats stats;
1485 extern dev_t filesystem_dev;
1486 extern char *backup_dir;
1487 @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l
1489 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1491 + /* FIXME: Flag ACL changes. */
1494 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1496 @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i
1497 if (preserve_gid && file->gid != GID_NONE
1498 && st->st_gid != file->gid)
1499 iflags |= ITEM_REPORT_GROUP;
1500 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1502 iflags |= ITEM_IS_NEW;
1504 @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str
1507 static int phase = 0;
1508 +static int dflt_perms;
1510 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1511 * make sure it exists, and has the right permissions/timestamp info. For
1512 @@ -844,6 +849,10 @@ static void recv_generator(char *fname,
1515 need_fuzzy_dirlist = 1;
1516 +#ifdef SUPPORT_ACLS
1517 + if (!preserve_perms)
1518 + dflt_perms = default_perms_for_dir(dn);
1521 parent_dirname = dn;
1523 @@ -871,7 +880,8 @@ static void recv_generator(char *fname,
1524 if (!preserve_perms) {
1525 int exists = statret == 0
1526 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1527 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1528 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1532 if (S_ISDIR(file->mode)) {
1533 @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi
1534 * notice that and let us know via the redo pipe (or its closing). */
1537 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1539 for (i = 0; i < flist->count; i++) {
1540 struct file_struct *file = flist->files[i];
1542 --- old/lib/sysacls.c
1543 +++ new/lib/sysacls.c
1546 + Unix SMB/CIFS implementation.
1547 + Samba system utilities for ACL support.
1548 + Copyright (C) Jeremy Allison 2000.
1550 + This program is free software; you can redistribute it and/or modify
1551 + it under the terms of the GNU General Public License as published by
1552 + the Free Software Foundation; either version 2 of the License, or
1553 + (at your option) any later version.
1555 + This program is distributed in the hope that it will be useful,
1556 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1557 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1558 + GNU General Public License for more details.
1560 + You should have received a copy of the GNU General Public License
1561 + along with this program; if not, write to the Free Software
1562 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1566 +#include "sysacls.h" /****** ADDED ******/
1568 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1569 +void SAFE_FREE(void *mem)
1575 +char *uidtoname(uid_t uid)
1577 + static char idbuf[12];
1578 + struct passwd *pw;
1580 + if ((pw = getpwuid(uid)) == NULL) {
1581 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1584 + return pw->pw_name;
1586 +/****** EXTRAS -- END ******/
1589 + This file wraps all differing system ACL interfaces into a consistent
1590 + one based on the POSIX interface. It also returns the correct errors
1591 + for older UNIX systems that don't support ACLs.
1593 + The interfaces that each ACL implementation must support are as follows :
1595 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1596 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1597 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1598 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1599 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1600 + SMB_ACL_T sys_acl_get_fd(int fd)
1601 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1602 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1603 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1604 + SMB_ACL_T sys_acl_init( int count)
1605 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1606 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1607 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1608 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1609 + int sys_acl_valid( SMB_ACL_T theacl )
1610 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1611 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1612 + int sys_acl_delete_def_file(const char *path)
1614 + This next one is not POSIX complient - but we *have* to have it !
1615 + More POSIX braindamage.
1617 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1619 + The generic POSIX free is the following call. We split this into
1620 + several different free functions as we may need to add tag info
1621 + to structures when emulating the POSIX interface.
1623 + int sys_acl_free( void *obj_p)
1625 + The calls we actually use are :
1627 + int sys_acl_free_text(char *text) - free acl_to_text
1628 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1629 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1633 +#if defined(HAVE_POSIX_ACLS)
1635 +/* Identity mapping - easy. */
1637 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1639 + return acl_get_entry( the_acl, entry_id, entry_p);
1642 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1644 + return acl_get_tag_type( entry_d, tag_type_p);
1647 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1649 + return acl_get_permset( entry_d, permset_p);
1652 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1654 + return acl_get_qualifier( entry_d);
1657 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1659 + return acl_get_file( path_p, type);
1662 +SMB_ACL_T sys_acl_get_fd(int fd)
1664 + return acl_get_fd(fd);
1667 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1669 + return acl_clear_perms(permset);
1672 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1674 + return acl_add_perm(permset, perm);
1677 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1679 +#if defined(HAVE_ACL_GET_PERM_NP)
1681 + * Required for TrustedBSD-based ACL implementations where
1682 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1685 + return acl_get_perm_np(permset, perm);
1687 + return acl_get_perm(permset, perm);
1691 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1693 + return acl_to_text( the_acl, plen);
1696 +SMB_ACL_T sys_acl_init( int count)
1698 + return acl_init(count);
1701 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1703 + return acl_create_entry(pacl, pentry);
1706 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1708 + return acl_set_tag_type(entry, tagtype);
1711 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1713 + return acl_set_qualifier(entry, qual);
1716 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1718 + return acl_set_permset(entry, permset);
1721 +int sys_acl_valid( SMB_ACL_T theacl )
1723 + return acl_valid(theacl);
1726 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1728 + return acl_set_file(name, acltype, theacl);
1731 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1733 + return acl_set_fd(fd, theacl);
1736 +int sys_acl_delete_def_file(const char *name)
1738 + return acl_delete_def_file(name);
1741 +int sys_acl_free_text(char *text)
1743 + return acl_free(text);
1746 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1748 + return acl_free(the_acl);
1751 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1753 + return acl_free(qual);
1756 +#elif defined(HAVE_TRU64_ACLS)
1758 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1759 + * is based on Draft 13 of the POSIX spec which is
1760 + * slightly different from the Draft 16 interface.
1762 + * Also, some of the permset manipulation functions
1763 + * such as acl_clear_perm() and acl_add_perm() appear
1764 + * to be broken on Tru64 so we have to manipulate
1765 + * the permission bits in the permset directly.
1767 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1769 + SMB_ACL_ENTRY_T entry;
1771 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1776 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1781 + return errno ? -1 : 0;
1784 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1786 + return acl_get_tag_type( entry_d, tag_type_p);
1789 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1791 + return acl_get_permset( entry_d, permset_p);
1794 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1796 + return acl_get_qualifier( entry_d);
1799 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1801 + return acl_get_file((char *)path_p, type);
1804 +SMB_ACL_T sys_acl_get_fd(int fd)
1806 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1809 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1811 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1816 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1818 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1823 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1828 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1830 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1833 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1835 + return acl_to_text( the_acl, plen);
1838 +SMB_ACL_T sys_acl_init( int count)
1840 + return acl_init(count);
1843 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1845 + SMB_ACL_ENTRY_T entry;
1847 + if ((entry = acl_create_entry(pacl)) == NULL) {
1855 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1857 + return acl_set_tag_type(entry, tagtype);
1860 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1862 + return acl_set_qualifier(entry, qual);
1865 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1867 + return acl_set_permset(entry, permset);
1870 +int sys_acl_valid( SMB_ACL_T theacl )
1872 + acl_entry_t entry;
1874 + return acl_valid(theacl, &entry);
1877 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1879 + return acl_set_file((char *)name, acltype, theacl);
1882 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1884 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1887 +int sys_acl_delete_def_file(const char *name)
1889 + return acl_delete_def_file((char *)name);
1892 +int sys_acl_free_text(char *text)
1895 + * (void) cast and explicit return 0 are for DEC UNIX
1896 + * which just #defines acl_free_text() to be free()
1898 + (void) acl_free_text(text);
1902 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1904 + return acl_free(the_acl);
1907 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1909 + return acl_free_qualifier(qual, tagtype);
1912 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1915 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1916 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1920 + * Note that while this code implements sufficient functionality
1921 + * to support the sys_acl_* interfaces it does not provide all
1922 + * of the semantics of the POSIX ACL interfaces.
1924 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1925 + * from a call to sys_acl_get_entry() should not be assumed to be
1926 + * valid after calling any of the following functions, which may
1927 + * reorder the entries in the ACL.
1930 + * sys_acl_set_file()
1931 + * sys_acl_set_fd()
1935 + * The only difference between Solaris and UnixWare / OpenUNIX is
1936 + * that the #defines for the ACL operations have different names
1938 +#if defined(HAVE_UNIXWARE_ACLS)
1940 +#define SETACL ACL_SET
1941 +#define GETACL ACL_GET
1942 +#define GETACLCNT ACL_CNT
1947 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1949 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1954 + if (entry_p == NULL) {
1959 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1963 + if (acl_d->next < 0) {
1968 + if (acl_d->next >= acl_d->count) {
1972 + *entry_p = &acl_d->acl[acl_d->next++];
1977 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1979 + *type_p = entry_d->a_type;
1984 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1986 + *permset_p = &entry_d->a_perm;
1991 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
1993 + if (entry_d->a_type != SMB_ACL_USER
1994 + && entry_d->a_type != SMB_ACL_GROUP) {
1999 + return &entry_d->a_id;
2003 + * There is no way of knowing what size the ACL returned by
2004 + * GETACL will be unless you first call GETACLCNT which means
2005 + * making an additional system call.
2007 + * In the hope of avoiding the cost of the additional system
2008 + * call in most cases, we initially allocate enough space for
2009 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2010 + * be too small then we use GETACLCNT to find out the actual
2011 + * size, reallocate the ACL buffer, and then call GETACL again.
2014 +#define INITIAL_ACL_SIZE 16
2016 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2019 + int count; /* # of ACL entries allocated */
2020 + int naccess; /* # of access ACL entries */
2021 + int ndefault; /* # of default ACL entries */
2023 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2028 + count = INITIAL_ACL_SIZE;
2029 + if ((acl_d = sys_acl_init(count)) == NULL) {
2034 + * If there isn't enough space for the ACL entries we use
2035 + * GETACLCNT to determine the actual number of ACL entries
2036 + * reallocate and try again. This is in a loop because it
2037 + * is possible that someone else could modify the ACL and
2038 + * increase the number of entries between the call to
2039 + * GETACLCNT and the call to GETACL.
2041 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2042 + && errno == ENOSPC) {
2044 + sys_acl_free_acl(acl_d);
2046 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2050 + if ((acl_d = sys_acl_init(count)) == NULL) {
2056 + sys_acl_free_acl(acl_d);
2061 + * calculate the number of access and default ACL entries
2063 + * Note: we assume that the acl() system call returned a
2064 + * well formed ACL which is sorted so that all of the
2065 + * access ACL entries preceed any default ACL entries
2067 + for (naccess = 0; naccess < count; naccess++) {
2068 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2071 + ndefault = count - naccess;
2074 + * if the caller wants the default ACL we have to copy
2075 + * the entries down to the start of the acl[] buffer
2076 + * and mask out the ACL_DEFAULT flag from the type field
2078 + if (type == SMB_ACL_TYPE_DEFAULT) {
2081 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2082 + acl_d->acl[i] = acl_d->acl[j];
2083 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2086 + acl_d->count = ndefault;
2088 + acl_d->count = naccess;
2094 +SMB_ACL_T sys_acl_get_fd(int fd)
2097 + int count; /* # of ACL entries allocated */
2098 + int naccess; /* # of access ACL entries */
2100 + count = INITIAL_ACL_SIZE;
2101 + if ((acl_d = sys_acl_init(count)) == NULL) {
2105 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2106 + && errno == ENOSPC) {
2108 + sys_acl_free_acl(acl_d);
2110 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2114 + if ((acl_d = sys_acl_init(count)) == NULL) {
2120 + sys_acl_free_acl(acl_d);
2125 + * calculate the number of access ACL entries
2127 + for (naccess = 0; naccess < count; naccess++) {
2128 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2132 + acl_d->count = naccess;
2137 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2144 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2146 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2147 + && perm != SMB_ACL_EXECUTE) {
2152 + if (permset_d == NULL) {
2157 + *permset_d |= perm;
2162 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2164 + return *permset_d & perm;
2167 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2174 + * use an initial estimate of 20 bytes per ACL entry
2175 + * when allocating memory for the text representation
2179 + maxlen = 20 * acl_d->count;
2180 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2185 + for (i = 0; i < acl_d->count; i++) {
2186 + struct acl *ap = &acl_d->acl[i];
2187 + struct passwd *pw;
2196 + switch (ap->a_type) {
2198 + * for debugging purposes it's probably more
2199 + * useful to dump unknown tag types rather
2200 + * than just returning an error
2203 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2206 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2211 + case SMB_ACL_USER:
2212 + id = uidtoname(ap->a_id);
2213 + case SMB_ACL_USER_OBJ:
2217 + case SMB_ACL_GROUP:
2218 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2219 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2225 + case SMB_ACL_GROUP_OBJ:
2229 + case SMB_ACL_OTHER:
2233 + case SMB_ACL_MASK:
2239 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2240 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2241 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2244 + /* <tag> : <qualifier> : rwx \n \0 */
2245 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2248 + * If this entry would overflow the buffer
2249 + * allocate enough additional memory for this
2250 + * entry and an estimate of another 20 bytes
2251 + * for each entry still to be processed
2253 + if ((len + nbytes) > maxlen) {
2254 + char *oldtext = text;
2256 + maxlen += nbytes + 20 * (acl_d->count - i);
2258 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2259 + SAFE_FREE(oldtext);
2265 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2266 + len += nbytes - 1;
2275 +SMB_ACL_T sys_acl_init(int count)
2285 + * note that since the definition of the structure pointed
2286 + * to by the SMB_ACL_T includes the first element of the
2287 + * acl[] array, this actually allocates an ACL with room
2288 + * for (count+1) entries
2290 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2295 + a->size = count + 1;
2303 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2306 + SMB_ACL_ENTRY_T entry_d;
2308 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2313 + if (acl_d->count >= acl_d->size) {
2318 + entry_d = &acl_d->acl[acl_d->count++];
2319 + entry_d->a_type = 0;
2320 + entry_d->a_id = -1;
2321 + entry_d->a_perm = 0;
2322 + *entry_p = entry_d;
2327 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2329 + switch (tag_type) {
2330 + case SMB_ACL_USER:
2331 + case SMB_ACL_USER_OBJ:
2332 + case SMB_ACL_GROUP:
2333 + case SMB_ACL_GROUP_OBJ:
2334 + case SMB_ACL_OTHER:
2335 + case SMB_ACL_MASK:
2336 + entry_d->a_type = tag_type;
2346 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2348 + if (entry_d->a_type != SMB_ACL_GROUP
2349 + && entry_d->a_type != SMB_ACL_USER) {
2354 + entry_d->a_id = *((id_t *)qual_p);
2359 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2361 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2365 + entry_d->a_perm = *permset_d;
2371 + * sort the ACL and check it for validity
2373 + * if it's a minimal ACL with only 4 entries then we
2374 + * need to recalculate the mask permissions to make
2375 + * sure that they are the same as the GROUP_OBJ
2376 + * permissions as required by the UnixWare acl() system call.
2378 + * (note: since POSIX allows minimal ACLs which only contain
2379 + * 3 entries - ie there is no mask entry - we should, in theory,
2380 + * check for this and add a mask entry if necessary - however
2381 + * we "know" that the caller of this interface always specifies
2382 + * a mask so, in practice "this never happens" (tm) - if it *does*
2383 + * happen aclsort() will fail and return an error and someone will
2384 + * have to fix it ...)
2387 +static int acl_sort(SMB_ACL_T acl_d)
2389 + int fixmask = (acl_d->count <= 4);
2391 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2398 +int sys_acl_valid(SMB_ACL_T acl_d)
2400 + return acl_sort(acl_d);
2403 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2406 + struct acl *acl_p;
2408 + struct acl *acl_buf = NULL;
2411 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2416 + if (acl_sort(acl_d) != 0) {
2420 + acl_p = &acl_d->acl[0];
2421 + acl_count = acl_d->count;
2424 + * if it's a directory there is extra work to do
2425 + * since the acl() system call will replace both
2426 + * the access ACLs and the default ACLs (if any)
2428 + if (stat(name, &s) != 0) {
2431 + if (S_ISDIR(s.st_mode)) {
2432 + SMB_ACL_T acc_acl;
2433 + SMB_ACL_T def_acl;
2434 + SMB_ACL_T tmp_acl;
2437 + if (type == SMB_ACL_TYPE_ACCESS) {
2439 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2443 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2446 + if (tmp_acl == NULL) {
2451 + * allocate a temporary buffer for the complete ACL
2453 + acl_count = acc_acl->count + def_acl->count;
2454 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2456 + if (acl_buf == NULL) {
2457 + sys_acl_free_acl(tmp_acl);
2463 + * copy the access control and default entries into the buffer
2465 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2466 + acc_acl->count * sizeof(acl_buf[0]));
2468 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2469 + def_acl->count * sizeof(acl_buf[0]));
2472 + * set the ACL_DEFAULT flag on the default entries
2474 + for (i = acc_acl->count; i < acl_count; i++) {
2475 + acl_buf[i].a_type |= ACL_DEFAULT;
2478 + sys_acl_free_acl(tmp_acl);
2480 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2485 + ret = acl(name, SETACL, acl_count, acl_p);
2487 + SAFE_FREE(acl_buf);
2492 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2494 + if (acl_sort(acl_d) != 0) {
2498 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2501 +int sys_acl_delete_def_file(const char *path)
2507 + * fetching the access ACL and rewriting it has
2508 + * the effect of deleting the default ACL
2510 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2514 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2516 + sys_acl_free_acl(acl_d);
2521 +int sys_acl_free_text(char *text)
2527 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2533 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
2538 +#elif defined(HAVE_HPUX_ACLS)
2542 + * Based on the Solaris/SCO code - with modifications.
2546 + * Note that while this code implements sufficient functionality
2547 + * to support the sys_acl_* interfaces it does not provide all
2548 + * of the semantics of the POSIX ACL interfaces.
2550 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2551 + * from a call to sys_acl_get_entry() should not be assumed to be
2552 + * valid after calling any of the following functions, which may
2553 + * reorder the entries in the ACL.
2556 + * sys_acl_set_file()
2557 + * sys_acl_set_fd()
2560 +/* This checks if the POSIX ACL system call is defined */
2561 +/* which basically corresponds to whether JFS 3.3 or */
2562 +/* higher is installed. If acl() was called when it */
2563 +/* isn't defined, it causes the process to core dump */
2564 +/* so it is important to check this and avoid acl() */
2565 +/* calls if it isn't there. */
2567 +static BOOL hpux_acl_call_presence(void)
2570 + shl_t handle = NULL;
2573 + static BOOL already_checked=0;
2575 + if(already_checked)
2579 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2581 + if(ret_val != 0) {
2582 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2583 + ret_val, errno, strerror(errno)));
2584 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2588 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2590 + already_checked = True;
2594 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2596 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2601 + if (entry_p == NULL) {
2606 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2610 + if (acl_d->next < 0) {
2615 + if (acl_d->next >= acl_d->count) {
2619 + *entry_p = &acl_d->acl[acl_d->next++];
2624 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2626 + *type_p = entry_d->a_type;
2631 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2633 + *permset_p = &entry_d->a_perm;
2638 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2640 + if (entry_d->a_type != SMB_ACL_USER
2641 + && entry_d->a_type != SMB_ACL_GROUP) {
2646 + return &entry_d->a_id;
2650 + * There is no way of knowing what size the ACL returned by
2651 + * ACL_GET will be unless you first call ACL_CNT which means
2652 + * making an additional system call.
2654 + * In the hope of avoiding the cost of the additional system
2655 + * call in most cases, we initially allocate enough space for
2656 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2657 + * be too small then we use ACL_CNT to find out the actual
2658 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2661 +#define INITIAL_ACL_SIZE 16
2663 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2666 + int count; /* # of ACL entries allocated */
2667 + int naccess; /* # of access ACL entries */
2668 + int ndefault; /* # of default ACL entries */
2670 + if(hpux_acl_call_presence() == False) {
2671 + /* Looks like we don't have the acl() system call on HPUX.
2672 + * May be the system doesn't have the latest version of JFS.
2677 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2682 + count = INITIAL_ACL_SIZE;
2683 + if ((acl_d = sys_acl_init(count)) == NULL) {
2688 + * If there isn't enough space for the ACL entries we use
2689 + * ACL_CNT to determine the actual number of ACL entries
2690 + * reallocate and try again. This is in a loop because it
2691 + * is possible that someone else could modify the ACL and
2692 + * increase the number of entries between the call to
2693 + * ACL_CNT and the call to ACL_GET.
2695 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2697 + sys_acl_free_acl(acl_d);
2699 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2703 + if ((acl_d = sys_acl_init(count)) == NULL) {
2709 + sys_acl_free_acl(acl_d);
2714 + * calculate the number of access and default ACL entries
2716 + * Note: we assume that the acl() system call returned a
2717 + * well formed ACL which is sorted so that all of the
2718 + * access ACL entries preceed any default ACL entries
2720 + for (naccess = 0; naccess < count; naccess++) {
2721 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2724 + ndefault = count - naccess;
2727 + * if the caller wants the default ACL we have to copy
2728 + * the entries down to the start of the acl[] buffer
2729 + * and mask out the ACL_DEFAULT flag from the type field
2731 + if (type == SMB_ACL_TYPE_DEFAULT) {
2734 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2735 + acl_d->acl[i] = acl_d->acl[j];
2736 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2739 + acl_d->count = ndefault;
2741 + acl_d->count = naccess;
2747 +SMB_ACL_T sys_acl_get_fd(int fd)
2750 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2753 + files_struct *fsp = file_find_fd(fd);
2755 + if (fsp == NULL) {
2761 + * We know we're in the same conn context. So we
2762 + * can use the relative path.
2765 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2768 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2775 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2777 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2778 + && perm != SMB_ACL_EXECUTE) {
2783 + if (permset_d == NULL) {
2788 + *permset_d |= perm;
2793 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2795 + return *permset_d & perm;
2798 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2805 + * use an initial estimate of 20 bytes per ACL entry
2806 + * when allocating memory for the text representation
2810 + maxlen = 20 * acl_d->count;
2811 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2816 + for (i = 0; i < acl_d->count; i++) {
2817 + struct acl *ap = &acl_d->acl[i];
2818 + struct passwd *pw;
2827 + switch (ap->a_type) {
2829 + * for debugging purposes it's probably more
2830 + * useful to dump unknown tag types rather
2831 + * than just returning an error
2834 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2837 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2842 + case SMB_ACL_USER:
2843 + id = uidtoname(ap->a_id);
2844 + case SMB_ACL_USER_OBJ:
2848 + case SMB_ACL_GROUP:
2849 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2850 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2856 + case SMB_ACL_GROUP_OBJ:
2860 + case SMB_ACL_OTHER:
2864 + case SMB_ACL_MASK:
2870 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2871 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2872 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2875 + /* <tag> : <qualifier> : rwx \n \0 */
2876 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2879 + * If this entry would overflow the buffer
2880 + * allocate enough additional memory for this
2881 + * entry and an estimate of another 20 bytes
2882 + * for each entry still to be processed
2884 + if ((len + nbytes) > maxlen) {
2885 + char *oldtext = text;
2887 + maxlen += nbytes + 20 * (acl_d->count - i);
2889 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2896 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2897 + len += nbytes - 1;
2906 +SMB_ACL_T sys_acl_init(int count)
2916 + * note that since the definition of the structure pointed
2917 + * to by the SMB_ACL_T includes the first element of the
2918 + * acl[] array, this actually allocates an ACL with room
2919 + * for (count+1) entries
2921 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2926 + a->size = count + 1;
2934 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2937 + SMB_ACL_ENTRY_T entry_d;
2939 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2944 + if (acl_d->count >= acl_d->size) {
2949 + entry_d = &acl_d->acl[acl_d->count++];
2950 + entry_d->a_type = 0;
2951 + entry_d->a_id = -1;
2952 + entry_d->a_perm = 0;
2953 + *entry_p = entry_d;
2958 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2960 + switch (tag_type) {
2961 + case SMB_ACL_USER:
2962 + case SMB_ACL_USER_OBJ:
2963 + case SMB_ACL_GROUP:
2964 + case SMB_ACL_GROUP_OBJ:
2965 + case SMB_ACL_OTHER:
2966 + case SMB_ACL_MASK:
2967 + entry_d->a_type = tag_type;
2977 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2979 + if (entry_d->a_type != SMB_ACL_GROUP
2980 + && entry_d->a_type != SMB_ACL_USER) {
2985 + entry_d->a_id = *((id_t *)qual_p);
2990 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2992 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2996 + entry_d->a_perm = *permset_d;
3001 +/* Structure to capture the count for each type of ACE. */
3003 +struct hpux_acl_types {
3007 + int n_def_user_obj;
3012 + int n_def_group_obj;
3016 + int n_def_other_obj;
3019 + int n_def_class_obj;
3021 + int n_illegal_obj;
3025 + * Counts the different number of objects in a given array of ACL
3029 + * acl_count - Count of ACLs in the array of ACL strucutres.
3030 + * aclp - Array of ACL structures.
3031 + * acl_type_count - Pointer to acl_types structure. Should already be
3035 + * acl_type_count - This structure is filled up with counts of various
3039 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3043 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3045 + for(i=0;i<acl_count;i++) {
3046 + switch(aclp[i].a_type) {
3048 + acl_type_count->n_user++;
3051 + acl_type_count->n_user_obj++;
3053 + case DEF_USER_OBJ:
3054 + acl_type_count->n_def_user_obj++;
3057 + acl_type_count->n_group++;
3060 + acl_type_count->n_group_obj++;
3062 + case DEF_GROUP_OBJ:
3063 + acl_type_count->n_def_group_obj++;
3066 + acl_type_count->n_other_obj++;
3068 + case DEF_OTHER_OBJ:
3069 + acl_type_count->n_def_other_obj++;
3072 + acl_type_count->n_class_obj++;
3074 + case DEF_CLASS_OBJ:
3075 + acl_type_count->n_def_class_obj++;
3078 + acl_type_count->n_def_user++;
3081 + acl_type_count->n_def_group++;
3084 + acl_type_count->n_illegal_obj++;
3090 +/* swap_acl_entries: Swaps two ACL entries.
3092 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3095 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3097 + struct acl temp_acl;
3099 + temp_acl.a_type = aclp0->a_type;
3100 + temp_acl.a_id = aclp0->a_id;
3101 + temp_acl.a_perm = aclp0->a_perm;
3103 + aclp0->a_type = aclp1->a_type;
3104 + aclp0->a_id = aclp1->a_id;
3105 + aclp0->a_perm = aclp1->a_perm;
3107 + aclp1->a_type = temp_acl.a_type;
3108 + aclp1->a_id = temp_acl.a_id;
3109 + aclp1->a_perm = temp_acl.a_perm;
3112 +/* prohibited_duplicate_type
3113 + * Identifies if given ACL type can have duplicate entries or
3116 + * Inputs: acl_type - ACL Type.
3122 + * True - If the ACL type matches any of the prohibited types.
3123 + * False - If the ACL type doesn't match any of the prohibited types.
3126 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3128 + switch(acl_type) {
3139 +/* get_needed_class_perm
3140 + * Returns the permissions of a ACL structure only if the ACL
3141 + * type matches one of the pre-determined types for computing
3142 + * CLASS_OBJ permissions.
3144 + * Inputs: aclp - Pointer to ACL structure.
3147 +static int hpux_get_needed_class_perm(struct acl *aclp)
3149 + switch(aclp->a_type) {
3153 + case DEF_USER_OBJ:
3155 + case DEF_GROUP_OBJ:
3157 + case DEF_CLASS_OBJ:
3158 + case DEF_OTHER_OBJ:
3159 + return aclp->a_perm;
3165 +/* acl_sort for HPUX.
3166 + * Sorts the array of ACL structures as per the description in
3167 + * aclsort man page. Refer to aclsort man page for more details
3171 + * acl_count - Count of ACLs in the array of ACL structures.
3172 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3174 + * aclp - Array of ACL structures.
3178 + * aclp - Sorted array of ACL structures.
3182 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3183 + * debug log in case of failure.
3186 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3188 +#if !defined(HAVE_HPUX_ACLSORT)
3190 + * The aclsort() system call is availabe on the latest HPUX General
3191 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3192 + * function. Because, we don't want to update to a new
3193 + * HPUX GR bundle just for aclsort() call.
3196 + struct hpux_acl_types acl_obj_count;
3197 + int n_class_obj_perm = 0;
3201 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3205 + if(aclp == NULL) {
3206 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3210 + /* Count different types of ACLs in the ACLs array */
3212 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3214 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3215 + * CLASS_OBJ and OTHER_OBJ
3218 + if( (acl_obj_count.n_user_obj != 1) ||
3219 + (acl_obj_count.n_group_obj != 1) ||
3220 + (acl_obj_count.n_class_obj != 1) ||
3221 + (acl_obj_count.n_other_obj != 1)
3223 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3224 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3228 + /* If any of the default objects are present, there should be only
3229 + * one of them each.
3232 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3233 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3234 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3235 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3239 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3242 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3243 + * same ACL type, sort by ACL id.
3245 + * I am using the trival kind of sorting method here because, performance isn't
3246 + * really effected by the ACLs feature. More over there aren't going to be more
3247 + * than 17 entries on HPUX.
3250 + for(i=0; i<acl_count;i++) {
3251 + for (j=i+1; j<acl_count; j++) {
3252 + if( aclp[i].a_type > aclp[j].a_type ) {
3253 + /* ACL entries out of order, swap them */
3255 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3257 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3259 + /* ACL entries of same type, sort by id */
3261 + if(aclp[i].a_id > aclp[j].a_id) {
3262 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3263 + } else if (aclp[i].a_id == aclp[j].a_id) {
3264 + /* We have a duplicate entry. */
3265 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3266 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3267 + aclp[i].a_type, aclp[i].a_id));
3276 + /* set the class obj permissions to the computed one. */
3278 + int n_class_obj_index = -1;
3280 + for(i=0;i<acl_count;i++) {
3281 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3283 + if(aclp[i].a_type == CLASS_OBJ)
3284 + n_class_obj_index = i;
3286 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3291 + return aclsort(acl_count, calclass, aclp);
3296 + * sort the ACL and check it for validity
3298 + * if it's a minimal ACL with only 4 entries then we
3299 + * need to recalculate the mask permissions to make
3300 + * sure that they are the same as the GROUP_OBJ
3301 + * permissions as required by the UnixWare acl() system call.
3303 + * (note: since POSIX allows minimal ACLs which only contain
3304 + * 3 entries - ie there is no mask entry - we should, in theory,
3305 + * check for this and add a mask entry if necessary - however
3306 + * we "know" that the caller of this interface always specifies
3307 + * a mask so, in practice "this never happens" (tm) - if it *does*
3308 + * happen aclsort() will fail and return an error and someone will
3309 + * have to fix it ...)
3312 +static int acl_sort(SMB_ACL_T acl_d)
3314 + int fixmask = (acl_d->count <= 4);
3316 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3323 +int sys_acl_valid(SMB_ACL_T acl_d)
3325 + return acl_sort(acl_d);
3328 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3331 + struct acl *acl_p;
3333 + struct acl *acl_buf = NULL;
3336 + if(hpux_acl_call_presence() == False) {
3337 + /* Looks like we don't have the acl() system call on HPUX.
3338 + * May be the system doesn't have the latest version of JFS.
3344 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3349 + if (acl_sort(acl_d) != 0) {
3353 + acl_p = &acl_d->acl[0];
3354 + acl_count = acl_d->count;
3357 + * if it's a directory there is extra work to do
3358 + * since the acl() system call will replace both
3359 + * the access ACLs and the default ACLs (if any)
3361 + if (stat(name, &s) != 0) {
3364 + if (S_ISDIR(s.st_mode)) {
3365 + SMB_ACL_T acc_acl;
3366 + SMB_ACL_T def_acl;
3367 + SMB_ACL_T tmp_acl;
3370 + if (type == SMB_ACL_TYPE_ACCESS) {
3372 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3376 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3379 + if (tmp_acl == NULL) {
3384 + * allocate a temporary buffer for the complete ACL
3386 + acl_count = acc_acl->count + def_acl->count;
3387 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3389 + if (acl_buf == NULL) {
3390 + sys_acl_free_acl(tmp_acl);
3396 + * copy the access control and default entries into the buffer
3398 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3399 + acc_acl->count * sizeof(acl_buf[0]));
3401 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3402 + def_acl->count * sizeof(acl_buf[0]));
3405 + * set the ACL_DEFAULT flag on the default entries
3407 + for (i = acc_acl->count; i < acl_count; i++) {
3408 + acl_buf[i].a_type |= ACL_DEFAULT;
3411 + sys_acl_free_acl(tmp_acl);
3413 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3418 + ret = acl(name, ACL_SET, acl_count, acl_p);
3427 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3430 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3433 + files_struct *fsp = file_find_fd(fd);
3435 + if (fsp == NULL) {
3440 + if (acl_sort(acl_d) != 0) {
3445 + * We know we're in the same conn context. So we
3446 + * can use the relative path.
3449 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3452 +int sys_acl_delete_def_file(const char *path)
3458 + * fetching the access ACL and rewriting it has
3459 + * the effect of deleting the default ACL
3461 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3465 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3467 + sys_acl_free_acl(acl_d);
3472 +int sys_acl_free_text(char *text)
3478 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3484 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3489 +#elif defined(HAVE_IRIX_ACLS)
3491 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3493 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3498 + if (entry_p == NULL) {
3503 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3507 + if (acl_d->next < 0) {
3512 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3516 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3521 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3523 + *type_p = entry_d->ae_tag;
3528 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3530 + *permset_p = entry_d;
3535 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3537 + if (entry_d->ae_tag != SMB_ACL_USER
3538 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3543 + return &entry_d->ae_id;
3546 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3550 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3554 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3559 + a->freeaclp = True;
3563 +SMB_ACL_T sys_acl_get_fd(int fd)
3567 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3571 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3576 + a->freeaclp = True;
3580 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3582 + permset_d->ae_perm = 0;
3587 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3589 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3590 + && perm != SMB_ACL_EXECUTE) {
3595 + if (permset_d == NULL) {
3600 + permset_d->ae_perm |= perm;
3605 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3607 + return permset_d->ae_perm & perm;
3610 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3612 + return acl_to_text(acl_d->aclp, len_p);
3615 +SMB_ACL_T sys_acl_init(int count)
3624 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3630 + a->freeaclp = False;
3631 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3632 + a->aclp->acl_cnt = 0;
3638 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3641 + SMB_ACL_ENTRY_T entry_d;
3643 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3648 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3653 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3654 + entry_d->ae_tag = 0;
3655 + entry_d->ae_id = 0;
3656 + entry_d->ae_perm = 0;
3657 + *entry_p = entry_d;
3662 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3664 + switch (tag_type) {
3665 + case SMB_ACL_USER:
3666 + case SMB_ACL_USER_OBJ:
3667 + case SMB_ACL_GROUP:
3668 + case SMB_ACL_GROUP_OBJ:
3669 + case SMB_ACL_OTHER:
3670 + case SMB_ACL_MASK:
3671 + entry_d->ae_tag = tag_type;
3681 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3683 + if (entry_d->ae_tag != SMB_ACL_GROUP
3684 + && entry_d->ae_tag != SMB_ACL_USER) {
3689 + entry_d->ae_id = *((id_t *)qual_p);
3694 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3696 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3700 + entry_d->ae_perm = permset_d->ae_perm;
3705 +int sys_acl_valid(SMB_ACL_T acl_d)
3707 + return acl_valid(acl_d->aclp);
3710 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3712 + return acl_set_file(name, type, acl_d->aclp);
3715 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3717 + return acl_set_fd(fd, acl_d->aclp);
3720 +int sys_acl_delete_def_file(const char *name)
3722 + return acl_delete_def_file(name);
3725 +int sys_acl_free_text(char *text)
3727 + return acl_free(text);
3730 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3732 + if (acl_d->freeaclp) {
3733 + acl_free(acl_d->aclp);
3739 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3744 +#elif defined(HAVE_AIX_ACLS)
3746 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3748 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3750 + struct acl_entry_link *link;
3751 + struct new_acl_entry *entry;
3754 + DEBUG(10,("This is the count: %d\n",theacl->count));
3756 + /* Check if count was previously set to -1. *
3757 + * If it was, that means we reached the end *
3758 + * of the acl last time. */
3759 + if(theacl->count == -1)
3763 + /* To get to the next acl, traverse linked list until index *
3764 + * of acl matches the count we are keeping. This count is *
3765 + * incremented each time we return an acl entry. */
3767 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3768 + link = link->nextp;
3770 + entry = *entry_p = link->entryp;
3772 + DEBUG(10,("*entry_p is %d\n",entry_p));
3773 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3775 + /* Increment count */
3777 + if(link->nextp == NULL)
3778 + theacl->count = -1;
3783 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3785 + /* Initialize tag type */
3788 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3790 + /* Depending on what type of entry we have, *
3791 + * return tag type. */
3792 + switch(entry_d->ace_id->id_type) {
3794 + *tag_type_p = SMB_ACL_USER;
3797 + *tag_type_p = SMB_ACL_GROUP;
3800 + case SMB_ACL_USER_OBJ:
3801 + case SMB_ACL_GROUP_OBJ:
3802 + case SMB_ACL_OTHER:
3803 + *tag_type_p = entry_d->ace_id->id_type;
3813 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3815 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3816 + *permset_p = &entry_d->ace_access;
3817 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3818 + if(!(**permset_p & S_IXUSR) &&
3819 + !(**permset_p & S_IWUSR) &&
3820 + !(**permset_p & S_IRUSR) &&
3821 + (**permset_p != 0))
3824 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3828 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3830 + return(entry_d->ace_id->id_data);
3833 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3835 + struct acl *file_acl = (struct acl *)NULL;
3836 + struct acl_entry *acl_entry;
3837 + struct new_acl_entry *new_acl_entry;
3838 + struct ace_id *idp;
3839 + struct acl_entry_link *acl_entry_link;
3840 + struct acl_entry_link *acl_entry_link_head;
3845 + /* AIX has no DEFAULT */
3846 + if ( type == SMB_ACL_TYPE_DEFAULT )
3849 + /* Get the acl using statacl */
3851 + DEBUG(10,("Entering sys_acl_get_file\n"));
3852 + DEBUG(10,("path_p is %s\n",path_p));
3854 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3856 + if(file_acl == NULL) {
3858 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3862 + memset(file_acl,0,BUFSIZ);
3864 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3866 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3867 + SAFE_FREE(file_acl);
3871 + DEBUG(10,("Got facl and returned it\n"));
3873 + /* Point to the first acl entry in the acl */
3874 + acl_entry = file_acl->acl_ext;
3876 + /* Begin setting up the head of the linked list *
3877 + * that will be used for the storing the acl *
3878 + * in a way that is useful for the posix_acls.c *
3881 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3882 + if(acl_entry_link_head == NULL)
3885 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3886 + if(acl_entry_link->entryp == NULL) {
3887 + SAFE_FREE(file_acl);
3889 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3893 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3894 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3896 + /* Check if the extended acl bit is on. *
3897 + * If it isn't, do not show the *
3898 + * contents of the acl since AIX intends *
3899 + * the extended info to remain unused */
3901 + if(file_acl->acl_mode & S_IXACL){
3902 + /* while we are not pointing to the very end */
3903 + while(acl_entry < acl_last(file_acl)) {
3904 + /* before we malloc anything, make sure this is */
3905 + /* a valid acl entry and one that we want to map */
3906 + idp = id_nxt(acl_entry->ace_id);
3907 + if((acl_entry->ace_type == ACC_SPECIFY ||
3908 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3909 + acl_entry = acl_nxt(acl_entry);
3913 + idp = acl_entry->ace_id;
3915 + /* Check if this is the first entry in the linked list. *
3916 + * The first entry needs to keep prevp pointing to NULL *
3917 + * and already has entryp allocated. */
3919 + if(acl_entry_link_head->count != 0) {
3920 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3922 + if(acl_entry_link->nextp == NULL) {
3923 + SAFE_FREE(file_acl);
3925 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3929 + acl_entry_link->nextp->prevp = acl_entry_link;
3930 + acl_entry_link = acl_entry_link->nextp;
3931 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3932 + if(acl_entry_link->entryp == NULL) {
3933 + SAFE_FREE(file_acl);
3935 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3938 + acl_entry_link->nextp = NULL;
3941 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3943 + /* Don't really need this since all types are going *
3944 + * to be specified but, it's better than leaving it 0 */
3946 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3948 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3950 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3952 + /* The access in the acl entries must be left shifted by *
3953 + * three bites, because they will ultimately be compared *
3954 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3956 + switch(acl_entry->ace_type){
3959 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3960 + acl_entry_link->entryp->ace_access <<= 6;
3961 + acl_entry_link_head->count++;
3964 + /* Since there is no way to return a DENY acl entry *
3965 + * change to PERMIT and then shift. */
3966 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3967 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3968 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3969 + acl_entry_link->entryp->ace_access <<= 6;
3970 + acl_entry_link_head->count++;
3976 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3977 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3979 + acl_entry = acl_nxt(acl_entry);
3981 + } /* end of if enabled */
3983 + /* Since owner, group, other acl entries are not *
3984 + * part of the acl entries in an acl, they must *
3985 + * be dummied up to become part of the list. */
3987 + for( i = 1; i < 4; i++) {
3988 + DEBUG(10,("i is %d\n",i));
3989 + if(acl_entry_link_head->count != 0) {
3990 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3991 + if(acl_entry_link->nextp == NULL) {
3992 + SAFE_FREE(file_acl);
3994 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3998 + acl_entry_link->nextp->prevp = acl_entry_link;
3999 + acl_entry_link = acl_entry_link->nextp;
4000 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4001 + if(acl_entry_link->entryp == NULL) {
4002 + SAFE_FREE(file_acl);
4004 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4009 + acl_entry_link->nextp = NULL;
4011 + new_acl_entry = acl_entry_link->entryp;
4012 + idp = new_acl_entry->ace_id;
4014 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4015 + new_acl_entry->ace_type = ACC_PERMIT;
4016 + idp->id_len = sizeof(struct ace_id);
4017 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4018 + memset(idp->id_data,0,sizeof(uid_t));
4022 + new_acl_entry->ace_access = file_acl->g_access << 6;
4023 + idp->id_type = SMB_ACL_GROUP_OBJ;
4027 + new_acl_entry->ace_access = file_acl->o_access << 6;
4028 + idp->id_type = SMB_ACL_OTHER;
4032 + new_acl_entry->ace_access = file_acl->u_access << 6;
4033 + idp->id_type = SMB_ACL_USER_OBJ;
4041 + acl_entry_link_head->count++;
4042 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4045 + acl_entry_link_head->count = 0;
4046 + SAFE_FREE(file_acl);
4048 + return(acl_entry_link_head);
4051 +SMB_ACL_T sys_acl_get_fd(int fd)
4053 + struct acl *file_acl = (struct acl *)NULL;
4054 + struct acl_entry *acl_entry;
4055 + struct new_acl_entry *new_acl_entry;
4056 + struct ace_id *idp;
4057 + struct acl_entry_link *acl_entry_link;
4058 + struct acl_entry_link *acl_entry_link_head;
4063 + /* Get the acl using fstatacl */
4065 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4066 + DEBUG(10,("fd is %d\n",fd));
4067 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4069 + if(file_acl == NULL) {
4071 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4075 + memset(file_acl,0,BUFSIZ);
4077 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4079 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4080 + SAFE_FREE(file_acl);
4084 + DEBUG(10,("Got facl and returned it\n"));
4086 + /* Point to the first acl entry in the acl */
4088 + acl_entry = file_acl->acl_ext;
4089 + /* Begin setting up the head of the linked list *
4090 + * that will be used for the storing the acl *
4091 + * in a way that is useful for the posix_acls.c *
4094 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4095 + if(acl_entry_link_head == NULL){
4096 + SAFE_FREE(file_acl);
4100 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4102 + if(acl_entry_link->entryp == NULL) {
4104 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4105 + SAFE_FREE(file_acl);
4109 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4110 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4112 + /* Check if the extended acl bit is on. *
4113 + * If it isn't, do not show the *
4114 + * contents of the acl since AIX intends *
4115 + * the extended info to remain unused */
4117 + if(file_acl->acl_mode & S_IXACL){
4118 + /* while we are not pointing to the very end */
4119 + while(acl_entry < acl_last(file_acl)) {
4120 + /* before we malloc anything, make sure this is */
4121 + /* a valid acl entry and one that we want to map */
4123 + idp = id_nxt(acl_entry->ace_id);
4124 + if((acl_entry->ace_type == ACC_SPECIFY ||
4125 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4126 + acl_entry = acl_nxt(acl_entry);
4130 + idp = acl_entry->ace_id;
4132 + /* Check if this is the first entry in the linked list. *
4133 + * The first entry needs to keep prevp pointing to NULL *
4134 + * and already has entryp allocated. */
4136 + if(acl_entry_link_head->count != 0) {
4137 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4138 + if(acl_entry_link->nextp == NULL) {
4140 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4141 + SAFE_FREE(file_acl);
4144 + acl_entry_link->nextp->prevp = acl_entry_link;
4145 + acl_entry_link = acl_entry_link->nextp;
4146 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4147 + if(acl_entry_link->entryp == NULL) {
4149 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4150 + SAFE_FREE(file_acl);
4154 + acl_entry_link->nextp = NULL;
4157 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4159 + /* Don't really need this since all types are going *
4160 + * to be specified but, it's better than leaving it 0 */
4162 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4163 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4165 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4167 + /* The access in the acl entries must be left shifted by *
4168 + * three bites, because they will ultimately be compared *
4169 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4171 + switch(acl_entry->ace_type){
4174 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4175 + acl_entry_link->entryp->ace_access <<= 6;
4176 + acl_entry_link_head->count++;
4179 + /* Since there is no way to return a DENY acl entry *
4180 + * change to PERMIT and then shift. */
4181 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4182 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4183 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4184 + acl_entry_link->entryp->ace_access <<= 6;
4185 + acl_entry_link_head->count++;
4191 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4192 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4194 + acl_entry = acl_nxt(acl_entry);
4196 + } /* end of if enabled */
4198 + /* Since owner, group, other acl entries are not *
4199 + * part of the acl entries in an acl, they must *
4200 + * be dummied up to become part of the list. */
4202 + for( i = 1; i < 4; i++) {
4203 + DEBUG(10,("i is %d\n",i));
4204 + if(acl_entry_link_head->count != 0){
4205 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4206 + if(acl_entry_link->nextp == NULL) {
4208 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4209 + SAFE_FREE(file_acl);
4213 + acl_entry_link->nextp->prevp = acl_entry_link;
4214 + acl_entry_link = acl_entry_link->nextp;
4215 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4217 + if(acl_entry_link->entryp == NULL) {
4218 + SAFE_FREE(file_acl);
4220 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4225 + acl_entry_link->nextp = NULL;
4227 + new_acl_entry = acl_entry_link->entryp;
4228 + idp = new_acl_entry->ace_id;
4230 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4231 + new_acl_entry->ace_type = ACC_PERMIT;
4232 + idp->id_len = sizeof(struct ace_id);
4233 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4234 + memset(idp->id_data,0,sizeof(uid_t));
4238 + new_acl_entry->ace_access = file_acl->g_access << 6;
4239 + idp->id_type = SMB_ACL_GROUP_OBJ;
4243 + new_acl_entry->ace_access = file_acl->o_access << 6;
4244 + idp->id_type = SMB_ACL_OTHER;
4248 + new_acl_entry->ace_access = file_acl->u_access << 6;
4249 + idp->id_type = SMB_ACL_USER_OBJ;
4256 + acl_entry_link_head->count++;
4257 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4260 + acl_entry_link_head->count = 0;
4261 + SAFE_FREE(file_acl);
4263 + return(acl_entry_link_head);
4266 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4268 + *permset = *permset & ~0777;
4272 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4275 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4279 + DEBUG(10,("This is the permset now: %d\n",*permset));
4283 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4288 +SMB_ACL_T sys_acl_init( int count)
4290 + struct acl_entry_link *theacl = NULL;
4292 + DEBUG(10,("Entering sys_acl_init\n"));
4294 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4295 + if(theacl == NULL) {
4297 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4301 + theacl->count = 0;
4302 + theacl->nextp = NULL;
4303 + theacl->prevp = NULL;
4304 + theacl->entryp = NULL;
4305 + DEBUG(10,("Exiting sys_acl_init\n"));
4309 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4311 + struct acl_entry_link *theacl;
4312 + struct acl_entry_link *acl_entryp;
4313 + struct acl_entry_link *temp_entry;
4316 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4318 + theacl = acl_entryp = *pacl;
4320 + /* Get to the end of the acl before adding entry */
4322 + for(counting=0; counting < theacl->count; counting++){
4323 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4324 + temp_entry = acl_entryp;
4325 + acl_entryp = acl_entryp->nextp;
4328 + if(theacl->count != 0){
4329 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4330 + if(acl_entryp == NULL) {
4332 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4336 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4337 + acl_entryp->prevp = temp_entry;
4338 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4341 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4342 + if(*pentry == NULL) {
4344 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4348 + memset(*pentry,0,sizeof(struct new_acl_entry));
4349 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4350 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4351 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4352 + acl_entryp->nextp = NULL;
4354 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4358 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4360 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4361 + entry->ace_id->id_type = tagtype;
4362 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4363 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4366 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4368 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4369 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4370 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4374 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4376 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4377 + if(!(*permset & S_IXUSR) &&
4378 + !(*permset & S_IWUSR) &&
4379 + !(*permset & S_IRUSR) &&
4383 + entry->ace_access = *permset;
4384 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4385 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4389 +int sys_acl_valid( SMB_ACL_T theacl )
4392 + int group_obj = 0;
4393 + int other_obj = 0;
4394 + struct acl_entry_link *acl_entry;
4396 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4397 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4398 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4399 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4402 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4404 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4410 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4412 + struct acl_entry_link *acl_entry_link = NULL;
4413 + struct acl *file_acl = NULL;
4414 + struct acl *file_acl_temp = NULL;
4415 + struct acl_entry *acl_entry = NULL;
4416 + struct ace_id *ace_id = NULL;
4423 + DEBUG(10,("Entering sys_acl_set_file\n"));
4424 + DEBUG(10,("File name is %s\n",name));
4426 + /* AIX has no default ACL */
4427 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4430 + acl_length = BUFSIZ;
4431 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4433 + if(file_acl == NULL) {
4435 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4439 + memset(file_acl,0,BUFSIZ);
4441 + file_acl->acl_len = ACL_SIZ;
4442 + file_acl->acl_mode = S_IXACL;
4444 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4445 + acl_entry_link->entryp->ace_access >>= 6;
4446 + id_type = acl_entry_link->entryp->ace_id->id_type;
4449 + case SMB_ACL_USER_OBJ:
4450 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4452 + case SMB_ACL_GROUP_OBJ:
4453 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4455 + case SMB_ACL_OTHER:
4456 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4458 + case SMB_ACL_MASK:
4462 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4463 + acl_length += sizeof(struct acl_entry);
4464 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4465 + if(file_acl_temp == NULL) {
4466 + SAFE_FREE(file_acl);
4468 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4472 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4473 + SAFE_FREE(file_acl);
4474 + file_acl = file_acl_temp;
4477 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4478 + file_acl->acl_len += sizeof(struct acl_entry);
4479 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4480 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4482 + /* In order to use this, we'll need to wait until we can get denies */
4483 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4484 + acl_entry->ace_type = ACC_SPECIFY; */
4486 + acl_entry->ace_type = ACC_SPECIFY;
4488 + ace_id = acl_entry->ace_id;
4490 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4491 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4492 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4493 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4494 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4497 + rc = chacl(name,file_acl,file_acl->acl_len);
4498 + DEBUG(10,("errno is %d\n",errno));
4499 + DEBUG(10,("return code is %d\n",rc));
4500 + SAFE_FREE(file_acl);
4501 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4505 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4507 + struct acl_entry_link *acl_entry_link = NULL;
4508 + struct acl *file_acl = NULL;
4509 + struct acl *file_acl_temp = NULL;
4510 + struct acl_entry *acl_entry = NULL;
4511 + struct ace_id *ace_id = NULL;
4517 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4518 + acl_length = BUFSIZ;
4519 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4521 + if(file_acl == NULL) {
4523 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4527 + memset(file_acl,0,BUFSIZ);
4529 + file_acl->acl_len = ACL_SIZ;
4530 + file_acl->acl_mode = S_IXACL;
4532 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4533 + acl_entry_link->entryp->ace_access >>= 6;
4534 + id_type = acl_entry_link->entryp->ace_id->id_type;
4535 + DEBUG(10,("The id_type is %d\n",id_type));
4538 + case SMB_ACL_USER_OBJ:
4539 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4541 + case SMB_ACL_GROUP_OBJ:
4542 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4544 + case SMB_ACL_OTHER:
4545 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4547 + case SMB_ACL_MASK:
4551 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4552 + acl_length += sizeof(struct acl_entry);
4553 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4554 + if(file_acl_temp == NULL) {
4555 + SAFE_FREE(file_acl);
4557 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4561 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4562 + SAFE_FREE(file_acl);
4563 + file_acl = file_acl_temp;
4566 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4567 + file_acl->acl_len += sizeof(struct acl_entry);
4568 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4569 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4571 + /* In order to use this, we'll need to wait until we can get denies */
4572 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4573 + acl_entry->ace_type = ACC_SPECIFY; */
4575 + acl_entry->ace_type = ACC_SPECIFY;
4577 + ace_id = acl_entry->ace_id;
4579 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4580 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4581 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4582 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4583 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4586 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4587 + DEBUG(10,("errno is %d\n",errno));
4588 + DEBUG(10,("return code is %d\n",rc));
4589 + SAFE_FREE(file_acl);
4590 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4594 +int sys_acl_delete_def_file(const char *name)
4596 + /* AIX has no default ACL */
4600 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4602 + return(*permset & perm);
4605 +int sys_acl_free_text(char *text)
4610 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4612 + struct acl_entry_link *acl_entry_link;
4614 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4615 + SAFE_FREE(acl_entry_link->prevp->entryp);
4616 + SAFE_FREE(acl_entry_link->prevp);
4619 + SAFE_FREE(acl_entry_link->prevp->entryp);
4620 + SAFE_FREE(acl_entry_link->prevp);
4621 + SAFE_FREE(acl_entry_link->entryp);
4622 + SAFE_FREE(acl_entry_link);
4627 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4632 +#else /* No ACLs. */
4634 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4640 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4646 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4652 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4658 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4661 + return (SMB_ACL_T)NULL;
4664 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4667 + return (SMB_ACL_T)NULL;
4670 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4676 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4682 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4685 + return (permset & perm) ? 1 : 0;
4688 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4694 +int sys_acl_free_text(UNUSED(char *text))
4700 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4706 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4712 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4718 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4724 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4730 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4736 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4742 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4748 +int sys_acl_delete_def_file(UNUSED(const char *name))
4754 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4760 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4766 +#endif /* No ACLs. */
4768 +/************************************************************************
4769 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4771 +************************************************************************/
4773 +int no_acl_syscall_error(int err)
4775 +#if defined(ENOSYS)
4776 + if (err == ENOSYS) {
4780 +#if defined(ENOTSUP)
4781 + if (err == ENOTSUP) {
4787 --- old/lib/sysacls.h
4788 +++ new/lib/sysacls.h
4790 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4791 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4792 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4793 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4794 +#define slprintf snprintf
4796 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4797 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4798 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4799 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4800 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4801 +SMB_ACL_T sys_acl_get_fd(int fd);
4802 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4803 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4804 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4805 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4806 +SMB_ACL_T sys_acl_init(int count);
4807 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4808 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4809 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4810 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4811 +int sys_acl_valid(SMB_ACL_T theacl);
4812 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4813 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4814 +int sys_acl_delete_def_file(const char *name);
4815 +int sys_acl_free_text(char *text);
4816 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4817 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4820 @@ -58,7 +58,7 @@ BEGIN {
4824 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4825 +!/^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/ {
4831 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4833 int preserve_links = 0;
4834 int preserve_hard_links = 0;
4835 +int preserve_acls = 0;
4836 int preserve_perms = 0;
4837 int preserve_executability = 0;
4838 int preserve_devices = 0;
4839 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4840 char const *got_socketpair = "no ";
4841 char const *have_inplace = "no ";
4842 char const *hardlinks = "no ";
4843 + char const *acls = "no ";
4844 char const *links = "no ";
4845 char const *ipv6 = "no ";
4846 STRUCT_STAT *dumstat;
4847 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4851 +#ifdef SUPPORT_ACLS
4855 #ifdef SUPPORT_LINKS
4858 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4859 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4860 rprintf(f, "<http://rsync.samba.org/>\n");
4861 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4862 - "%shard links, %ssymlinks, batchfiles,\n",
4863 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4864 (int) (sizeof (OFF_T) * 8),
4865 - got_socketpair, hardlinks, links);
4866 + got_socketpair, hardlinks, acls, links);
4868 /* Note that this field may not have type ino_t. It depends
4869 * on the complicated interaction between largefile feature
4870 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4871 rprintf(F," -H, --hard-links preserve hard links\n");
4872 rprintf(F," -p, --perms preserve permissions\n");
4873 rprintf(F," -E, --executability preserve the file's executability\n");
4874 +#ifdef SUPPORT_ACLS
4875 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4877 rprintf(F," --chmod=CHMOD change destination permissions\n");
4878 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4879 rprintf(F," -g, --group preserve group\n");
4880 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4881 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4882 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4883 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4884 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4885 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4886 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4887 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4888 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4889 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4890 @@ -1068,6 +1080,23 @@ int parse_arguments(int *argc, const cha
4895 +#ifdef SUPPORT_ACLS
4896 + preserve_acls = preserve_perms = 1;
4899 + /* FIXME: this should probably be ignored with a
4900 + * warning and then countermeasures taken to
4901 + * restrict group and other access in the presence
4902 + * of any more restrictive ACLs, but this is safe
4904 + snprintf(err_buf,sizeof(err_buf),
4905 + "ACLs are not supported on this %s\n",
4906 + am_server ? "server" : "client");
4912 /* A large opt value means that set_refuse_options()
4913 * turned this option off. */
4914 @@ -1511,6 +1540,10 @@ void server_options(char **args,int *arg
4916 if (preserve_hard_links)
4918 +#ifdef SUPPORT_ACLS
4919 + if (preserve_acls)
4920 + argstr[x++] = 'A';
4927 @@ -46,6 +46,7 @@ extern int keep_partial;
4928 extern int checksum_seed;
4930 extern int delay_updates;
4931 +extern mode_t orig_umask;
4932 extern struct stats stats;
4933 extern char *log_format;
4934 extern char *tmpdir;
4935 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4936 int itemizing = am_daemon ? daemon_log_format_has_i
4937 : !am_server && log_format_has_i;
4938 int max_phase = protocol_version >= 29 ? 2 : 1;
4939 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4940 +#ifdef SUPPORT_ACLS
4941 + char *parent_dirname = "";
4946 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
4947 * mode based on the local permissions and some heuristics. */
4948 if (!preserve_perms) {
4949 int exists = fd1 != -1;
4950 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4951 +#ifdef SUPPORT_ACLS
4952 + char *dn = file->dirname ? file->dirname : ".";
4953 + if (parent_dirname != dn
4954 + && strcmp(parent_dirname, dn) != 0) {
4955 + dflt_perms = default_perms_for_dir(dn);
4956 + parent_dirname = dn;
4959 + file->mode = dest_mode(file->mode, st.st_mode,
4960 + dflt_perms, exists);
4963 /* We now check to see if we are writing file "inplace" */
4969 extern int daemon_log_format_has_i;
4970 +extern int preserve_acls;
4971 extern int preserve_perms;
4972 extern int preserve_executability;
4973 extern int preserve_times;
4974 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
4976 /* This is only called when we aren't preserving permissions. Figure out what
4977 * the permissions should be and return them merged back into the mode. */
4978 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4979 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
4982 /* If the file already exists, we'll return the local permissions,
4983 * possibly tweaked by the --executability option. */
4984 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4985 cur_mode |= (cur_mode & 0444) >> 2;
4988 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
4989 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
4990 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
4991 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
4992 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
4993 @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
4997 +#ifdef SUPPORT_ACLS
4998 + /* It's OK to call set_acl() now, even for a dir, as the generator
4999 + * will enable owner-writability using chmod, if necessary.
5001 + * If set_acl changes permission bits in the process of setting
5002 + * an access ACL, it changes st->st_mode so we know whether we
5003 + * need to chmod. */
5004 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5009 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5010 - int ret = do_chmod(fname, file->mode);
5011 + mode_t mode = file->mode;
5012 + int ret = do_chmod(fname, mode);
5014 rsyserr(FERROR, errno,
5015 "failed to set permissions on %s",
5018 @@ -658,6 +658,20 @@ struct chmod_mode_struct;
5020 #define UNUSED(x) x __attribute__((__unused__))
5022 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5023 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5024 +#define SUPPORT_ACLS 1
5027 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5028 +#define ACLS_NEED_MASK 1
5031 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5032 +#include <sys/acl.h>
5034 +#include "smb_acls.h"
5038 /* We have replacement versions of these if they're missing. */
5041 @@ -321,6 +321,7 @@ to the detailed description below for a
5042 -H, --hard-links preserve hard links
5043 -p, --perms preserve permissions
5044 -E, --executability preserve executability
5045 + -A, --acls preserve ACLs (implies -p) [non-standard]
5046 --chmod=CHMOD change destination permissions
5047 -o, --owner preserve owner (super-user only)
5048 -g, --group preserve group
5049 @@ -742,7 +743,9 @@ quote(itemize(
5050 permissions, though the bf(--executability) option might change just
5051 the execute permission for the file.
5052 it() New files get their "normal" permission bits set to the source
5053 - file's permissions masked with the receiving end's umask setting, and
5054 + file's permissions masked with the receiving directory's default
5055 + permissions (either the receiving process's umask, or the permissions
5056 + specified via the destination directory's default ACL), and
5057 their special permission bits disabled except in the case where a new
5058 directory inherits a setgid bit from its parent directory.
5060 @@ -773,9 +776,11 @@ The preservation of the destination's se
5061 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5062 versions erroneously preserved the three special permission bits for
5063 newly-created files when bf(--perms) was off, while overriding the
5064 -destination's setgid bit setting on a newly-created directory. (Keep in
5065 -mind that it is the version of the receiving rsync that affects this
5067 +destination's setgid bit setting on a newly-created directory. Default ACL
5068 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5069 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5070 +(Keep in mind that it is the version of the receiving rsync that affects
5073 dit(bf(-E, --executability)) This option causes rsync to preserve the
5074 executability (or non-executability) of regular files when bf(--perms) is
5075 @@ -793,6 +798,10 @@ quote(itemize(
5077 If bf(--perms) is enabled, this option is ignored.
5079 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5080 +ACLs to be the same as the source ACLs. This nonstandard option only
5081 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5083 dit(bf(--chmod)) This option tells rsync to apply one or more
5084 comma-separated "chmod" strings to the permission of the files in the
5085 transfer. The resulting value is treated as though it was the permissions
5090 + Unix SMB/Netbios implementation.
5092 + Portable SMB ACL interface
5093 + Copyright (C) Jeremy Allison 2000
5095 + This program is free software; you can redistribute it and/or modify
5096 + it under the terms of the GNU General Public License as published by
5097 + the Free Software Foundation; either version 2 of the License, or
5098 + (at your option) any later version.
5100 + This program is distributed in the hope that it will be useful,
5101 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5102 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5103 + GNU General Public License for more details.
5105 + You should have received a copy of the GNU General Public License
5106 + along with this program; if not, write to the Free Software
5107 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5110 +#ifndef _SMB_ACLS_H
5111 +#define _SMB_ACLS_H
5113 +#if defined HAVE_POSIX_ACLS
5115 +/* This is an identity mapping (just remove the SMB_). */
5117 +#define SMB_ACL_TAG_T acl_tag_t
5118 +#define SMB_ACL_TYPE_T acl_type_t
5119 +#define SMB_ACL_PERMSET_T acl_permset_t
5120 +#define SMB_ACL_PERM_T acl_perm_t
5121 +#define SMB_ACL_READ ACL_READ
5122 +#define SMB_ACL_WRITE ACL_WRITE
5123 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5125 +/* Types of ACLs. */
5126 +#define SMB_ACL_USER ACL_USER
5127 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5128 +#define SMB_ACL_GROUP ACL_GROUP
5129 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5130 +#define SMB_ACL_OTHER ACL_OTHER
5131 +#define SMB_ACL_MASK ACL_MASK
5133 +#define SMB_ACL_T acl_t
5135 +#define SMB_ACL_ENTRY_T acl_entry_t
5137 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5138 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5140 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5141 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5143 +#elif defined HAVE_TRU64_ACLS
5145 +/* This is for DEC/Compaq Tru64 UNIX */
5147 +#define SMB_ACL_TAG_T acl_tag_t
5148 +#define SMB_ACL_TYPE_T acl_type_t
5149 +#define SMB_ACL_PERMSET_T acl_permset_t
5150 +#define SMB_ACL_PERM_T acl_perm_t
5151 +#define SMB_ACL_READ ACL_READ
5152 +#define SMB_ACL_WRITE ACL_WRITE
5153 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5155 +/* Types of ACLs. */
5156 +#define SMB_ACL_USER ACL_USER
5157 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5158 +#define SMB_ACL_GROUP ACL_GROUP
5159 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5160 +#define SMB_ACL_OTHER ACL_OTHER
5161 +#define SMB_ACL_MASK ACL_MASK
5163 +#define SMB_ACL_T acl_t
5165 +#define SMB_ACL_ENTRY_T acl_entry_t
5167 +#define SMB_ACL_FIRST_ENTRY 0
5168 +#define SMB_ACL_NEXT_ENTRY 1
5170 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5171 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5173 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5175 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5176 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5179 +/* SVR4.2 ES/MP ACLs */
5180 +typedef int SMB_ACL_TAG_T;
5181 +typedef int SMB_ACL_TYPE_T;
5182 +typedef ushort *SMB_ACL_PERMSET_T;
5183 +typedef ushort SMB_ACL_PERM_T;
5184 +#define SMB_ACL_READ 4
5185 +#define SMB_ACL_WRITE 2
5186 +#define SMB_ACL_EXECUTE 1
5188 +/* Types of ACLs. */
5189 +#define SMB_ACL_USER USER
5190 +#define SMB_ACL_USER_OBJ USER_OBJ
5191 +#define SMB_ACL_GROUP GROUP
5192 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5193 +#define SMB_ACL_OTHER OTHER_OBJ
5194 +#define SMB_ACL_MASK CLASS_OBJ
5196 +typedef struct SMB_ACL_T {
5200 + struct acl acl[1];
5203 +typedef struct acl *SMB_ACL_ENTRY_T;
5205 +#define SMB_ACL_FIRST_ENTRY 0
5206 +#define SMB_ACL_NEXT_ENTRY 1
5208 +#define SMB_ACL_TYPE_ACCESS 0
5209 +#define SMB_ACL_TYPE_DEFAULT 1
5211 +#elif defined HAVE_HPUX_ACLS
5214 + * Based on the Solaris & UnixWare code.
5218 +#include <sys/aclv.h>
5220 +/* SVR4.2 ES/MP ACLs */
5221 +typedef int SMB_ACL_TAG_T;
5222 +typedef int SMB_ACL_TYPE_T;
5223 +typedef ushort *SMB_ACL_PERMSET_T;
5224 +typedef ushort SMB_ACL_PERM_T;
5225 +#define SMB_ACL_READ 4
5226 +#define SMB_ACL_WRITE 2
5227 +#define SMB_ACL_EXECUTE 1
5229 +/* Types of ACLs. */
5230 +#define SMB_ACL_USER USER
5231 +#define SMB_ACL_USER_OBJ USER_OBJ
5232 +#define SMB_ACL_GROUP GROUP
5233 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5234 +#define SMB_ACL_OTHER OTHER_OBJ
5235 +#define SMB_ACL_MASK CLASS_OBJ
5237 +typedef struct SMB_ACL_T {
5241 + struct acl acl[1];
5244 +typedef struct acl *SMB_ACL_ENTRY_T;
5246 +#define SMB_ACL_FIRST_ENTRY 0
5247 +#define SMB_ACL_NEXT_ENTRY 1
5249 +#define SMB_ACL_TYPE_ACCESS 0
5250 +#define SMB_ACL_TYPE_DEFAULT 1
5252 +#elif defined HAVE_IRIX_ACLS
5254 +#define SMB_ACL_TAG_T acl_tag_t
5255 +#define SMB_ACL_TYPE_T acl_type_t
5256 +#define SMB_ACL_PERMSET_T acl_permset_t
5257 +#define SMB_ACL_PERM_T acl_perm_t
5258 +#define SMB_ACL_READ ACL_READ
5259 +#define SMB_ACL_WRITE ACL_WRITE
5260 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5262 +/* Types of ACLs. */
5263 +#define SMB_ACL_USER ACL_USER
5264 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5265 +#define SMB_ACL_GROUP ACL_GROUP
5266 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5267 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5268 +#define SMB_ACL_MASK ACL_MASK
5270 +typedef struct SMB_ACL_T {
5276 +#define SMB_ACL_ENTRY_T acl_entry_t
5278 +#define SMB_ACL_FIRST_ENTRY 0
5279 +#define SMB_ACL_NEXT_ENTRY 1
5281 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5282 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5284 +#elif defined HAVE_AIX_ACLS
5286 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5288 +#include "/usr/include/acl.h"
5290 +typedef uint *SMB_ACL_PERMSET_T;
5292 +struct acl_entry_link{
5293 + struct acl_entry_link *prevp;
5294 + struct new_acl_entry *entryp;
5295 + struct acl_entry_link *nextp;
5299 +struct new_acl_entry{
5300 + unsigned short ace_len;
5301 + unsigned short ace_type;
5302 + unsigned int ace_access;
5303 + struct ace_id ace_id[1];
5306 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5307 +#define SMB_ACL_T struct acl_entry_link*
5309 +#define SMB_ACL_TAG_T unsigned short
5310 +#define SMB_ACL_TYPE_T int
5311 +#define SMB_ACL_PERM_T uint
5312 +#define SMB_ACL_READ S_IRUSR
5313 +#define SMB_ACL_WRITE S_IWUSR
5314 +#define SMB_ACL_EXECUTE S_IXUSR
5316 +/* Types of ACLs. */
5317 +#define SMB_ACL_USER ACEID_USER
5318 +#define SMB_ACL_USER_OBJ 3
5319 +#define SMB_ACL_GROUP ACEID_GROUP
5320 +#define SMB_ACL_GROUP_OBJ 4
5321 +#define SMB_ACL_OTHER 5
5322 +#define SMB_ACL_MASK 6
5325 +#define SMB_ACL_FIRST_ENTRY 1
5326 +#define SMB_ACL_NEXT_ENTRY 2
5328 +#define SMB_ACL_TYPE_ACCESS 0
5329 +#define SMB_ACL_TYPE_DEFAULT 1
5331 +#else /* No ACLs. */
5333 +/* No ACLS - fake it. */
5334 +#define SMB_ACL_TAG_T int
5335 +#define SMB_ACL_TYPE_T int
5336 +#define SMB_ACL_PERMSET_T mode_t
5337 +#define SMB_ACL_PERM_T mode_t
5338 +#define SMB_ACL_READ S_IRUSR
5339 +#define SMB_ACL_WRITE S_IWUSR
5340 +#define SMB_ACL_EXECUTE S_IXUSR
5342 +/* Types of ACLs. */
5343 +#define SMB_ACL_USER 0
5344 +#define SMB_ACL_USER_OBJ 1
5345 +#define SMB_ACL_GROUP 2
5346 +#define SMB_ACL_GROUP_OBJ 3
5347 +#define SMB_ACL_OTHER 4
5348 +#define SMB_ACL_MASK 5
5350 +typedef struct SMB_ACL_T {
5354 +typedef struct SMB_ACL_ENTRY_T {
5356 +} *SMB_ACL_ENTRY_T;
5358 +#define SMB_ACL_FIRST_ENTRY 0
5359 +#define SMB_ACL_NEXT_ENTRY 1
5361 +#define SMB_ACL_TYPE_ACCESS 0
5362 +#define SMB_ACL_TYPE_DEFAULT 1
5364 +#endif /* No ACLs. */
5365 +#endif /* _SMB_ACLS_H */
5366 --- old/testsuite/default-acls.test
5367 +++ new/testsuite/default-acls.test
5371 +# This program is distributable under the terms of the GNU GPL see
5374 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5376 +. $srcdir/testsuite/rsync.fns
5378 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5379 +setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5381 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5383 + todir="$scratchdir/$1"
5385 + # FIXME This doesn't work on solaris...
5386 + setfacl -k "$todir"
5387 + [ "$2" ] && setfacl -dm "$2" "$todir"
5388 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5389 + # even though the directory itself is outside the transfer
5390 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5391 + check_perms "$todir/to" $4 "Target $1"
5392 + check_perms "$todir/to/dir" $4 "Target $1"
5393 + check_perms "$todir/to/file" $3 "Target $1"
5394 + check_perms "$todir/to/program" $4 "Target $1"
5395 + # Make sure get_local_name doesn't mess us up when transferring only one file
5396 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5397 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5398 + # Make sure we obey default ACLs when not transferring a regular file
5399 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5400 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5403 +mkdir "$scratchdir/dir"
5404 +echo "File!" >"$scratchdir/file"
5405 +echo "#!/bin/sh" >"$scratchdir/program"
5406 +chmod 777 "$scratchdir/dir"
5407 +chmod 666 "$scratchdir/file"
5408 +chmod 777 "$scratchdir/program"
5410 +# Test some target directories
5412 +testit da777 u::rwx,g::rwx,o::rwx rw-rw-rw- rwxrwxrwx
5413 +testit da775 u::rwx,g::rwx,o::r-x rw-rw-r-- rwxrwxr-x
5414 +testit da750 u::rwx,g::r-x,o::--- rw-r----- rwxr-x---
5415 +testit da770mask u::rwx,g::---,m::rwx,o::--- rw-rw---- rwxrwx---
5416 +testit noda1 '' rw------- rwx------
5418 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5420 +testit noda3 '' rw-r--r-- rwxr-xr-x
5428 extern int preserve_uid;
5429 extern int preserve_gid;
5430 +extern int preserve_acls;
5431 extern int numeric_ids;
5434 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5438 - if (preserve_uid) {
5439 + if (preserve_uid || preserve_acls) {
5441 /* we send sequences of uid/byte-length/name */
5442 for (list = uidlist; list; list = list->next) {
5443 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5447 - if (preserve_gid) {
5448 + if (preserve_gid || preserve_acls) {
5450 for (list = gidlist; list; list = list->next) {
5452 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5456 - if (preserve_uid && !numeric_ids) {
5457 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5458 /* read the uid list */
5459 while ((id = read_int(f)) != 0) {
5460 int len = read_byte(f);
5461 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5465 - if (preserve_gid && !numeric_ids) {
5466 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5467 /* read the gid list */
5468 while ((id = read_int(f)) != 0) {
5469 int len = read_byte(f);
5470 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5474 +#ifdef SUPPORT_ACLS
5475 + if (preserve_acls && !numeric_ids) {
5477 + while ((id = next_acl_uid(flist)) != NULL)
5478 + *id = match_uid(*id);
5479 + while ((id = next_acl_gid(flist)) != NULL)
5480 + *id = match_gid(*id);
5484 /* Now convert all the uids/gids from sender values to our values. */
5485 if (am_root && preserve_uid && !numeric_ids) {
5486 for (i = 0; i < flist->count; i++)