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 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
694 + if (mode & S_ISVTX)
697 + if (mode & S_ISVTX && !(old_mode & S_ISVTX))
700 + /* If setuid or setgid is going off, it's not safe to allow all
701 + * the new ACLs to go into effect before they get cleared. */
702 + if ((old_mode & S_ISUID && !(mode & S_ISUID))
703 + || (old_mode & S_ISGID && !(mode & S_ISGID)))
708 + errfun = "sys_acl_get_entry";
709 + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
711 + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
712 + SMB_ACL_TAG_T tag_type;
713 + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) {
714 + errfun = "sys_acl_get_tag_type";
717 + if (tag_type == SMB_ACL_USER_OBJ)
718 + COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
719 + else if (tag_type == group_id)
720 + COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
721 + else if (tag_type == SMB_ACL_OTHER)
722 + COE2( store_access_in_entry,(mode & 7, entry) );
727 + rprintf(FERROR, "change_sacl_perms: %s(): %s\n",
728 + errfun, strerror(errno));
733 +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
734 + /* Ensure that chmod() will be called to restore any lost setid bits. */
735 + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
736 + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS))
737 + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
740 + /* Return the mode of the file on disk, as we will set them. */
741 + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
744 +static void receive_rsync_acl(rsync_acl *racl, int f)
746 + uchar computed_mask_bits = 0;
747 + ida_list *idal = NULL;
751 + *racl = rsync_acl_initializer;
753 + if (!(count = read_int(f)))
757 + char tag = read_byte(f);
758 + uchar access = read_byte(f);
759 + if (access & ~ (4 | 2 | 1)) {
760 + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
762 + exit_cleanup(RERR_STREAMIO);
766 + if (racl->user_obj != NO_ENTRY) {
767 + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
768 + exit_cleanup(RERR_STREAMIO);
770 + racl->user_obj = access;
773 + idal = &racl->users;
776 + if (racl->group_obj != NO_ENTRY) {
777 + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
778 + exit_cleanup(RERR_STREAMIO);
780 + racl->group_obj = access;
783 + idal = &racl->groups;
786 + if (racl->mask != NO_ENTRY) {
787 + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
788 + exit_cleanup(RERR_STREAMIO);
790 + racl->mask = access;
793 + if (racl->other != NO_ENTRY) {
794 + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
795 + exit_cleanup(RERR_STREAMIO);
797 + racl->other = access;
800 + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
802 + exit_cleanup(RERR_STREAMIO);
804 + expand_ida_list(idal);
805 + ida = &idal->idas[idal->count++];
806 + ida->access = access;
807 + ida->id = read_int(f);
808 + computed_mask_bits |= access;
811 + /* Ensure that these are never unset. */
812 + if (racl->user_obj == NO_ENTRY)
813 + racl->user_obj = 7;
814 + if (racl->group_obj == NO_ENTRY)
815 + racl->group_obj = 0;
816 + if (racl->other == NO_ENTRY)
818 +#ifndef ACLS_NEED_MASK
819 + if (!racl->users.count && !racl->groups.count) {
820 + /* If we, a system without ACLS_NEED_MASK, received a
821 + * superfluous mask, throw it away. */
822 + if (racl->mask != NO_ENTRY) {
823 + /* mask off group perms with it first */
824 + racl->group_obj &= racl->mask;
825 + racl->mask = NO_ENTRY;
829 + if (racl->mask == NO_ENTRY)
830 + racl->mask = computed_mask_bits | racl->group_obj;
833 +/* receive and build the rsync_acl_lists */
834 +void receive_acl(struct file_struct *file, int f)
836 + SMB_ACL_TYPE_T type;
839 + if (S_ISLNK(file->mode))
842 + fname = f_name(file, NULL);
843 + type = SMB_ACL_TYPE_ACCESS;
845 + file_acl_index_list *fileaclidx_list =
846 + file_acl_index_lists(type);
848 + expand_file_acl_index_list(fileaclidx_list);
850 + tag = read_byte(f);
851 + if (tag == 'A' || tag == 'a') {
852 + if (type != SMB_ACL_TYPE_ACCESS) {
853 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
855 + exit_cleanup(RERR_STREAMIO);
857 + } else if (tag == 'D' || tag == 'd') {
858 + if (type == SMB_ACL_TYPE_ACCESS) {
859 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
861 + exit_cleanup(RERR_STREAMIO);
864 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
866 + exit_cleanup(RERR_STREAMIO);
868 + if (tag == 'A' || tag == 'D') {
870 + rsync_acl_list *racl_list = rsync_acl_lists(type);
871 + smb_acl_list *sacl_list = smb_acl_lists(type);
872 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
873 + aclidx = racl_list->count;
874 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
876 + receive_rsync_acl(&racl, f);
877 + expand_rsync_acl_list(racl_list);
878 + racl_list->racls[racl_list->count++] = racl;
879 + expand_smb_acl_list(sacl_list);
880 + sacl_list->sacls[sacl_list->count++] = NULL;
882 + int index = read_int(f);
883 + rsync_acl_list *racl_list = rsync_acl_lists(type);
884 + if ((size_t) index >= racl_list->count) {
885 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
887 + str_acl_type(type),
889 + exit_cleanup(RERR_STREAMIO);
891 + fileaclidx_list->fileaclidxs[fileaclidx_list->count].
893 + fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
896 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
899 +static int file_acl_index_list_sorter(const void *f1, const void *f2)
901 + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
902 + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
903 + return fileaclidx1->file == fileaclidx2->file ? 0 :
904 + fileaclidx1->file < fileaclidx2->file ? -1 : 1;
907 +void sort_file_acl_index_lists()
909 + SMB_ACL_TYPE_T type;
911 + type = SMB_ACL_TYPE_ACCESS;
913 + file_acl_index_list *fileaclidx_list =
914 + file_acl_index_lists(type);
915 + if (!fileaclidx_list->count)
917 + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
918 + sizeof fileaclidx_list->fileaclidxs[0],
919 + &file_acl_index_list_sorter);
920 + } while (BUMP_TYPE(type));
923 +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
924 + const struct file_struct *file) {
925 + int low = 0, high = fileaclidx_list->count;
926 + const struct file_struct *file_mid;
930 + int mid = (high + low) / 2;
931 + file_mid = fileaclidx_list->fileaclidxs[mid].file;
932 + if (file_mid == file)
933 + return fileaclidx_list->fileaclidxs[mid].aclidx;
934 + if (file_mid > file)
938 + } while (low < high);
940 + file_mid = fileaclidx_list->fileaclidxs[low].file;
941 + if (file_mid == file)
942 + return fileaclidx_list->fileaclidxs[low].aclidx;
945 + "find_file_acl_index: can't find entry for file in list\n");
946 + exit_cleanup(RERR_STREAMIO);
950 +/* for duplicating ACLs on backups when using backup_dir */
951 +int dup_acl(const char *orig, const char *bak, mode_t mode)
953 + SMB_ACL_TYPE_T type;
956 + type = SMB_ACL_TYPE_ACCESS;
958 + SMB_ACL_T sacl_orig, sacl_bak;
959 + rsync_acl racl_orig, racl_bak;
960 + if (!(sacl_orig = sys_acl_get_file(orig, type))) {
961 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
962 + orig, str_acl_type(type), strerror(errno));
966 + if (!(sacl_bak = sys_acl_get_file(orig, type))) {
967 + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
968 + bak, str_acl_type(type), strerror(errno));
970 + /* try to forge on through */
972 + if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
974 + goto out_with_sacls;
977 + if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
979 + goto out_with_one_racl;
981 + if (rsync_acls_equal(&racl_orig, &racl_bak))
984 + ; /* presume they're unequal */
986 + if (type == SMB_ACL_TYPE_DEFAULT
987 + && rsync_acl_count_entries(&racl_orig) == 0) {
988 + if (sys_acl_delete_def_file(bak) < 0) {
989 + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
990 + bak, strerror(errno));
993 + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) {
994 + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
995 + bak, str_acl_type(type), strerror(errno));
1000 + rsync_acl_free(&racl_bak);
1001 + out_with_one_racl:
1002 + rsync_acl_free(&racl_orig);
1005 + sys_acl_free_acl(sacl_bak);
1006 + /* out_with_one_sacl: */
1008 + sys_acl_free_acl(sacl_orig);
1009 + } while (BUMP_TYPE(type) && S_ISDIR(mode));
1014 +/* Stuff for redirecting calls to set_acl() from set_file_attrs()
1015 + * for keep_backup(). */
1016 +static const struct file_struct *backup_orig_file = NULL;
1017 +static const char null_string[] = "";
1018 +static const char *backup_orig_fname = null_string;
1019 +static const char *backup_dest_fname = null_string;
1020 +static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
1022 +void push_keep_backup_acl(const struct file_struct *file,
1023 + const char *orig, const char *dest)
1025 + SMB_ACL_TYPE_T type;
1028 + backup_orig_file = file;
1029 + backup_orig_fname = orig;
1030 + backup_dest_fname = dest;
1032 + sacl = &_backup_sacl[0];
1033 + type = SMB_ACL_TYPE_ACCESS;
1035 + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) {
1039 + if (!(*sacl = sys_acl_get_file(orig, type))) {
1041 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1042 + orig, str_acl_type(type),
1045 + } while (BUMP_TYPE(type));
1048 +static int set_keep_backup_acl()
1050 + SMB_ACL_TYPE_T type;
1054 + sacl = &_backup_sacl[0];
1055 + type = SMB_ACL_TYPE_ACCESS;
1058 + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) {
1060 + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
1061 + backup_dest_fname,
1062 + str_acl_type(type),
1066 + } while (BUMP_TYPE(type));
1071 +void cleanup_keep_backup_acl()
1073 + SMB_ACL_TYPE_T type;
1076 + backup_orig_file = NULL;
1077 + backup_orig_fname = null_string;
1078 + backup_dest_fname = null_string;
1080 + sacl = &_backup_sacl[0];
1081 + type = SMB_ACL_TYPE_ACCESS;
1084 + sys_acl_free_acl(*sacl);
1087 + } while (BUMP_TYPE(type));
1090 +/* set ACL on rsync-ed or keep_backup-ed file
1092 + * This sets extended access ACL entries and default ACLs. If convenient,
1093 + * it sets permission bits along with the access ACLs and signals having
1094 + * done so by modifying mode_p, which should point into the stat buffer.
1096 + * returns: 1 for unchanged, 0 for changed, -1 for failed
1097 + * Pass NULL for mode_p to get the return code without changing anything. */
1098 +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p)
1100 + int unchanged = 1;
1101 + SMB_ACL_TYPE_T type;
1103 + if (S_ISLNK(file->mode))
1106 + if (file == backup_orig_file) {
1107 + if (!strcmp(fname, backup_dest_fname))
1108 + return set_keep_backup_acl();
1110 + type = SMB_ACL_TYPE_ACCESS;
1113 + SMB_ACL_T sacl_orig, *sacl_new;
1114 + rsync_acl racl_orig, *racl_new;
1115 + int aclidx = find_file_acl_index(file_acl_index_lists(type), file);
1117 + racl_new = &(rsync_acl_lists(type)->racls[aclidx]);
1118 + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]);
1119 + sacl_orig = sys_acl_get_file(fname, type);
1121 + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1122 + fname, str_acl_type(type), strerror(errno));
1126 + ok = unpack_smb_acl(&racl_orig, sacl_orig);
1127 + sys_acl_free_acl(sacl_orig);
1132 + if (type == SMB_ACL_TYPE_ACCESS)
1133 + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new);
1135 + ok = rsync_acls_equal(&racl_orig, racl_new);
1136 + rsync_acl_free(&racl_orig);
1139 + if (!dry_run && mode_p) {
1140 + if (type == SMB_ACL_TYPE_DEFAULT
1141 + && rsync_acl_count_entries(racl_new) == 0) {
1142 + if (sys_acl_delete_def_file(fname) < 0) {
1143 + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1144 + fname, strerror(errno));
1149 + mode_t cur_mode = *mode_p;
1151 + && !pack_smb_acl(sacl_new, racl_new)) {
1155 + if (type == SMB_ACL_TYPE_ACCESS) {
1156 + cur_mode = change_sacl_perms(*sacl_new, racl_new->mask,
1157 + cur_mode, file->mode);
1158 + if (cur_mode == ~0u)
1161 + if (sys_acl_set_file(fname, type, *sacl_new) < 0) {
1162 + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1163 + fname, str_acl_type(type),
1168 + if (type == SMB_ACL_TYPE_ACCESS)
1169 + *mode_p = cur_mode;
1172 + if (unchanged == 1)
1174 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
1179 +/* Enumeration functions for uid mapping: */
1181 +/* Context -- one and only one. Should be cycled through once on uid
1182 + * mapping and once on gid mapping. */
1183 +static rsync_acl_list *_enum_racl_lists[] = {
1184 + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1187 +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1188 +static size_t enum_racl_index = 0;
1189 +static size_t enum_ida_index = 0;
1191 +/* This returns the next tag_type id from the given acl for the next entry,
1192 + * or it returns 0 if there are no more tag_type ids in the acl. */
1193 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1195 + const ida_list *idal = (tag_type == SMB_ACL_USER ?
1196 + &racl->users : &racl->groups);
1197 + if (enum_ida_index < idal->count) {
1198 + id_access *ida = &idal->idas[enum_ida_index++];
1201 + enum_ida_index = 0;
1205 +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1207 + for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1208 + rsync_acl *racl = &racl_list->racls[enum_racl_index];
1209 + id_t *id = next_ace_id(tag_type, racl);
1213 + enum_racl_index = 0;
1217 +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type)
1219 + for (; *enum_racl_list; enum_racl_list++) {
1220 + id_t *id = next_acl_id(tag_type, *enum_racl_list);
1224 + enum_racl_list = &_enum_racl_lists[0];
1228 +id_t *next_acl_uid()
1230 + return next_acl_list_id(SMB_ACL_USER);
1233 +id_t *next_acl_gid()
1235 + return next_acl_list_id(SMB_ACL_GROUP);
1238 +int default_perms_for_dir(const char *dir)
1247 + perms = ACCESSPERMS & ~orig_umask;
1248 + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1249 + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1250 + if (sacl == NULL) {
1251 + /* Couldn't get an ACL. Darn. */
1254 + /* ACLs are disabled. We could yell at the user to turn them on, but... */
1258 + /* We're doing a dry run, so the containing directory
1259 + * wasn't actually created. Don't worry about it. */
1262 + /* Otherwise fall through. */
1264 + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
1265 + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1271 + ok = unpack_smb_acl(&racl, sacl);
1272 + sys_acl_free_acl(sacl);
1274 + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1278 + /* Apply the permission-bit entries of the default ACL, if any. */
1279 + if (rsync_acl_count_entries(&racl) > 0) {
1280 + perms = rsync_acl_get_perms(&racl);
1282 + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1285 + rsync_acl_free(&racl);
1289 +#endif /* SUPPORT_ACLS */
1292 @@ -28,6 +28,7 @@ extern char *backup_suffix;
1293 extern char *backup_dir;
1296 +extern int preserve_acls;
1297 extern int preserve_devices;
1298 extern int preserve_specials;
1299 extern int preserve_links;
1300 @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath)
1302 do_lchown(fullpath, st.st_uid, st.st_gid);
1303 do_chmod(fullpath, st.st_mode);
1304 +#ifdef SUPPORT_ACLS
1305 + if (preserve_acls)
1306 + dup_acl(end, fullpath, st.st_mode);
1311 @@ -185,6 +190,11 @@ static int keep_backup(char *fname)
1312 if (!(buf = get_backup_name(fname)))
1315 +#ifdef SUPPORT_ACLS
1316 + if (preserve_acls)
1317 + push_keep_backup_acl(file, fname, buf);
1320 /* Check to see if this is a device file, or link */
1321 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1322 || (preserve_specials && IS_SPECIAL(file->mode))) {
1323 @@ -260,6 +270,10 @@ static int keep_backup(char *fname)
1326 set_file_attrs(buf, file, NULL, 0);
1327 +#ifdef SUPPORT_ACLS
1328 + if (preserve_acls)
1329 + cleanup_keep_backup_acl();
1334 --- old/configure.in
1335 +++ new/configure.in
1336 @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
1337 AC_CHECK_LIB(resolv, strcasecmp)
1340 +AC_CHECK_FUNCS(aclsort)
1341 +if test x"$ac_cv_func_aclsort" = x"no"; then
1342 + AC_CHECK_LIB(sec, aclsort)
1345 dnl At the moment we don't test for a broken memcmp(), because all we
1346 dnl need to do is test for equality, not comparison, and it seems that
1347 dnl every platform has a memcmp that can do at least that.
1348 @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
1349 AC_SUBST(CC_SHOBJ_FLAG)
1350 AC_SUBST(BUILD_POPT)
1352 +AC_CHECK_HEADERS(sys/acl.h)
1353 +AC_CHECK_FUNCS(_acl __acl _facl __facl)
1354 +#################################################
1355 +# check for ACL support
1357 +AC_MSG_CHECKING(whether to support ACLs)
1358 +AC_ARG_ENABLE(acl-support,
1359 +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
1360 +[ case "$enableval" in
1363 + case "$host_os" in
1365 + AC_MSG_RESULT(Using UnixWare ACLs)
1366 + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1368 + *solaris*|*cygwin*)
1369 + AC_MSG_RESULT(Using solaris ACLs)
1370 + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1373 + AC_MSG_RESULT(Using HPUX ACLs)
1374 + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1377 + AC_MSG_RESULT(Using IRIX ACLs)
1378 + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1381 + AC_MSG_RESULT(Using AIX ACLs)
1382 + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1385 + AC_MSG_RESULT(Using Tru64 ACLs)
1386 + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1387 + LIBS="$LIBS -lpacl"
1390 + AC_MSG_RESULT(ACLs requested -- running tests)
1391 + AC_CHECK_LIB(acl,acl_get_file)
1392 + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1393 + AC_TRY_LINK([#include <sys/types.h>
1394 +#include <sys/acl.h>],
1395 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1396 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1397 + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1398 + AC_MSG_RESULT(Using posix ACLs)
1399 + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
1400 + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
1401 + AC_TRY_LINK([#include <sys/types.h>
1402 +#include <sys/acl.h>],
1403 +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1404 +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
1405 + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1406 + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1409 + AC_MSG_ERROR(Failed to find ACL support)
1416 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1419 + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1423 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1428 @@ -44,6 +44,7 @@ extern int filesfrom_fd;
1429 extern int one_file_system;
1430 extern int copy_dirlinks;
1431 extern int keep_dirlinks;
1432 +extern int preserve_acls;
1433 extern int preserve_links;
1434 extern int preserve_hard_links;
1435 extern int preserve_devices;
1436 @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam
1437 if (chmod_modes && !S_ISLNK(file->mode))
1438 file->mode = tweak_mode(file->mode, chmod_modes);
1440 +#ifdef SUPPORT_ACLS
1441 + if (preserve_acls && make_acl(file, fname) < 0)
1445 maybe_emit_filelist_progress(flist->count + flist_count_offset);
1447 flist_expand(flist);
1448 @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam
1449 if (file->basename[0]) {
1450 flist->files[flist->count++] = file;
1451 send_file_entry(file, f);
1452 +#ifdef SUPPORT_ACLS
1453 + if (preserve_acls)
1454 + send_acl(file, f);
1457 +#ifdef SUPPORT_ACLS
1458 + /* Cleanup unsent ACL(s). */
1459 + if (preserve_acls)
1460 + send_acl(file, -1);
1465 @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f)
1466 flags |= read_byte(f) << 8;
1467 file = receive_file_entry(flist, flags, f);
1469 +#ifdef SUPPORT_ACLS
1470 + if (preserve_acls)
1471 + receive_acl(file, f);
1474 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1475 stats.total_size += file->length;
1477 @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f)
1479 clean_flist(flist, relative_paths, 1);
1481 +#ifdef SUPPORT_ACLS
1482 + if (preserve_acls)
1483 + sort_file_acl_index_lists();
1487 recv_uid_list(f, flist);
1491 @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1492 extern int max_delete;
1493 extern int force_delete;
1494 extern int one_file_system;
1495 +extern mode_t orig_umask;
1496 extern struct stats stats;
1497 extern dev_t filesystem_dev;
1498 extern char *backup_dir;
1499 @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l
1501 int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
1503 + /* FIXME: Flag ACL changes. */
1506 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
1508 @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i
1509 if (preserve_gid && file->gid != GID_NONE
1510 && st->st_gid != file->gid)
1511 iflags |= ITEM_REPORT_GROUP;
1512 + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */
1514 iflags |= ITEM_IS_NEW;
1516 @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str
1519 static int phase = 0;
1520 +static int dflt_perms;
1522 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1523 * make sure it exists, and has the right permissions/timestamp info. For
1524 @@ -844,6 +849,10 @@ static void recv_generator(char *fname,
1527 need_fuzzy_dirlist = 1;
1528 +#ifdef SUPPORT_ACLS
1529 + if (!preserve_perms)
1530 + dflt_perms = default_perms_for_dir(dn);
1533 parent_dirname = dn;
1535 @@ -871,7 +880,8 @@ static void recv_generator(char *fname,
1536 if (!preserve_perms) {
1537 int exists = statret == 0
1538 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1539 - file->mode = dest_mode(file->mode, st.st_mode, exists);
1540 + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1544 if (S_ISDIR(file->mode)) {
1545 @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi
1546 * notice that and let us know via the redo pipe (or its closing). */
1549 + dflt_perms = (ACCESSPERMS & ~orig_umask);
1551 for (i = 0; i < flist->count; i++) {
1552 struct file_struct *file = flist->files[i];
1554 --- old/lib/sysacls.c
1555 +++ new/lib/sysacls.c
1558 + Unix SMB/CIFS implementation.
1559 + Samba system utilities for ACL support.
1560 + Copyright (C) Jeremy Allison 2000.
1562 + This program is free software; you can redistribute it and/or modify
1563 + it under the terms of the GNU General Public License as published by
1564 + the Free Software Foundation; either version 2 of the License, or
1565 + (at your option) any later version.
1567 + This program is distributed in the hope that it will be useful,
1568 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1569 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1570 + GNU General Public License for more details.
1572 + You should have received a copy of the GNU General Public License
1573 + along with this program; if not, write to the Free Software
1574 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1578 +#include "sysacls.h" /****** ADDED ******/
1580 +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
1581 +void SAFE_FREE(void *mem)
1587 +char *uidtoname(uid_t uid)
1589 + static char idbuf[12];
1590 + struct passwd *pw;
1592 + if ((pw = getpwuid(uid)) == NULL) {
1593 + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1596 + return pw->pw_name;
1598 +/****** EXTRAS -- END ******/
1601 + This file wraps all differing system ACL interfaces into a consistent
1602 + one based on the POSIX interface. It also returns the correct errors
1603 + for older UNIX systems that don't support ACLs.
1605 + The interfaces that each ACL implementation must support are as follows :
1607 + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1608 + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1609 + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1610 + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1611 + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1612 + SMB_ACL_T sys_acl_get_fd(int fd)
1613 + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1614 + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1615 + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1616 + SMB_ACL_T sys_acl_init( int count)
1617 + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1618 + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1619 + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1620 + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1621 + int sys_acl_valid( SMB_ACL_T theacl )
1622 + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1623 + int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1624 + int sys_acl_delete_def_file(const char *path)
1626 + This next one is not POSIX complient - but we *have* to have it !
1627 + More POSIX braindamage.
1629 + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1631 + The generic POSIX free is the following call. We split this into
1632 + several different free functions as we may need to add tag info
1633 + to structures when emulating the POSIX interface.
1635 + int sys_acl_free( void *obj_p)
1637 + The calls we actually use are :
1639 + int sys_acl_free_text(char *text) - free acl_to_text
1640 + int sys_acl_free_acl(SMB_ACL_T posix_acl)
1641 + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
1645 +#if defined(HAVE_POSIX_ACLS)
1647 +/* Identity mapping - easy. */
1649 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1651 + return acl_get_entry( the_acl, entry_id, entry_p);
1654 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1656 + return acl_get_tag_type( entry_d, tag_type_p);
1659 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1661 + return acl_get_permset( entry_d, permset_p);
1664 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1666 + return acl_get_qualifier( entry_d);
1669 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1671 + return acl_get_file( path_p, type);
1674 +SMB_ACL_T sys_acl_get_fd(int fd)
1676 + return acl_get_fd(fd);
1679 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1681 + return acl_clear_perms(permset);
1684 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1686 + return acl_add_perm(permset, perm);
1689 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1691 +#if defined(HAVE_ACL_GET_PERM_NP)
1693 + * Required for TrustedBSD-based ACL implementations where
1694 + * non-POSIX.1e functions are denoted by a _np (non-portable)
1697 + return acl_get_perm_np(permset, perm);
1699 + return acl_get_perm(permset, perm);
1703 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1705 + return acl_to_text( the_acl, plen);
1708 +SMB_ACL_T sys_acl_init( int count)
1710 + return acl_init(count);
1713 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1715 + return acl_create_entry(pacl, pentry);
1718 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1720 + return acl_set_tag_type(entry, tagtype);
1723 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1725 + return acl_set_qualifier(entry, qual);
1728 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1730 + return acl_set_permset(entry, permset);
1733 +int sys_acl_valid( SMB_ACL_T theacl )
1735 + return acl_valid(theacl);
1738 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1740 + return acl_set_file(name, acltype, theacl);
1743 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1745 + return acl_set_fd(fd, theacl);
1748 +int sys_acl_delete_def_file(const char *name)
1750 + return acl_delete_def_file(name);
1753 +int sys_acl_free_text(char *text)
1755 + return acl_free(text);
1758 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1760 + return acl_free(the_acl);
1763 +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
1765 + return acl_free(qual);
1768 +#elif defined(HAVE_TRU64_ACLS)
1770 + * The interface to DEC/Compaq Tru64 UNIX ACLs
1771 + * is based on Draft 13 of the POSIX spec which is
1772 + * slightly different from the Draft 16 interface.
1774 + * Also, some of the permset manipulation functions
1775 + * such as acl_clear_perm() and acl_add_perm() appear
1776 + * to be broken on Tru64 so we have to manipulate
1777 + * the permission bits in the permset directly.
1779 +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1781 + SMB_ACL_ENTRY_T entry;
1783 + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1788 + if ((entry = acl_get_entry(the_acl)) != NULL) {
1793 + return errno ? -1 : 0;
1796 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1798 + return acl_get_tag_type( entry_d, tag_type_p);
1801 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1803 + return acl_get_permset( entry_d, permset_p);
1806 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1808 + return acl_get_qualifier( entry_d);
1811 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1813 + return acl_get_file((char *)path_p, type);
1816 +SMB_ACL_T sys_acl_get_fd(int fd)
1818 + return acl_get_fd(fd, ACL_TYPE_ACCESS);
1821 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1823 + *permset = 0; /* acl_clear_perm() is broken on Tru64 */
1828 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1830 + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1835 + *permset |= perm; /* acl_add_perm() is broken on Tru64 */
1840 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
1842 + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1845 +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
1847 + return acl_to_text( the_acl, plen);
1850 +SMB_ACL_T sys_acl_init( int count)
1852 + return acl_init(count);
1855 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1857 + SMB_ACL_ENTRY_T entry;
1859 + if ((entry = acl_create_entry(pacl)) == NULL) {
1867 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1869 + return acl_set_tag_type(entry, tagtype);
1872 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1874 + return acl_set_qualifier(entry, qual);
1877 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1879 + return acl_set_permset(entry, permset);
1882 +int sys_acl_valid( SMB_ACL_T theacl )
1884 + acl_entry_t entry;
1886 + return acl_valid(theacl, &entry);
1889 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1891 + return acl_set_file((char *)name, acltype, theacl);
1894 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1896 + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1899 +int sys_acl_delete_def_file(const char *name)
1901 + return acl_delete_def_file((char *)name);
1904 +int sys_acl_free_text(char *text)
1907 + * (void) cast and explicit return 0 are for DEC UNIX
1908 + * which just #defines acl_free_text() to be free()
1910 + (void) acl_free_text(text);
1914 +int sys_acl_free_acl(SMB_ACL_T the_acl)
1916 + return acl_free(the_acl);
1919 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
1921 + return acl_free_qualifier(qual, tagtype);
1924 +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1927 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1928 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1932 + * Note that while this code implements sufficient functionality
1933 + * to support the sys_acl_* interfaces it does not provide all
1934 + * of the semantics of the POSIX ACL interfaces.
1936 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1937 + * from a call to sys_acl_get_entry() should not be assumed to be
1938 + * valid after calling any of the following functions, which may
1939 + * reorder the entries in the ACL.
1942 + * sys_acl_set_file()
1943 + * sys_acl_set_fd()
1947 + * The only difference between Solaris and UnixWare / OpenUNIX is
1948 + * that the #defines for the ACL operations have different names
1950 +#if defined(HAVE_UNIXWARE_ACLS)
1952 +#define SETACL ACL_SET
1953 +#define GETACL ACL_GET
1954 +#define GETACLCNT ACL_CNT
1959 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1961 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1966 + if (entry_p == NULL) {
1971 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
1975 + if (acl_d->next < 0) {
1980 + if (acl_d->next >= acl_d->count) {
1984 + *entry_p = &acl_d->acl[acl_d->next++];
1989 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
1991 + *type_p = entry_d->a_type;
1996 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
1998 + *permset_p = &entry_d->a_perm;
2003 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2005 + if (entry_d->a_type != SMB_ACL_USER
2006 + && entry_d->a_type != SMB_ACL_GROUP) {
2011 + return &entry_d->a_id;
2015 + * There is no way of knowing what size the ACL returned by
2016 + * GETACL will be unless you first call GETACLCNT which means
2017 + * making an additional system call.
2019 + * In the hope of avoiding the cost of the additional system
2020 + * call in most cases, we initially allocate enough space for
2021 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2022 + * be too small then we use GETACLCNT to find out the actual
2023 + * size, reallocate the ACL buffer, and then call GETACL again.
2026 +#define INITIAL_ACL_SIZE 16
2028 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2031 + int count; /* # of ACL entries allocated */
2032 + int naccess; /* # of access ACL entries */
2033 + int ndefault; /* # of default ACL entries */
2035 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2040 + count = INITIAL_ACL_SIZE;
2041 + if ((acl_d = sys_acl_init(count)) == NULL) {
2046 + * If there isn't enough space for the ACL entries we use
2047 + * GETACLCNT to determine the actual number of ACL entries
2048 + * reallocate and try again. This is in a loop because it
2049 + * is possible that someone else could modify the ACL and
2050 + * increase the number of entries between the call to
2051 + * GETACLCNT and the call to GETACL.
2053 + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
2054 + && errno == ENOSPC) {
2056 + sys_acl_free_acl(acl_d);
2058 + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
2062 + if ((acl_d = sys_acl_init(count)) == NULL) {
2068 + sys_acl_free_acl(acl_d);
2073 + * calculate the number of access and default ACL entries
2075 + * Note: we assume that the acl() system call returned a
2076 + * well formed ACL which is sorted so that all of the
2077 + * access ACL entries preceed any default ACL entries
2079 + for (naccess = 0; naccess < count; naccess++) {
2080 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2083 + ndefault = count - naccess;
2086 + * if the caller wants the default ACL we have to copy
2087 + * the entries down to the start of the acl[] buffer
2088 + * and mask out the ACL_DEFAULT flag from the type field
2090 + if (type == SMB_ACL_TYPE_DEFAULT) {
2093 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2094 + acl_d->acl[i] = acl_d->acl[j];
2095 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2098 + acl_d->count = ndefault;
2100 + acl_d->count = naccess;
2106 +SMB_ACL_T sys_acl_get_fd(int fd)
2109 + int count; /* # of ACL entries allocated */
2110 + int naccess; /* # of access ACL entries */
2112 + count = INITIAL_ACL_SIZE;
2113 + if ((acl_d = sys_acl_init(count)) == NULL) {
2117 + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2118 + && errno == ENOSPC) {
2120 + sys_acl_free_acl(acl_d);
2122 + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2126 + if ((acl_d = sys_acl_init(count)) == NULL) {
2132 + sys_acl_free_acl(acl_d);
2137 + * calculate the number of access ACL entries
2139 + for (naccess = 0; naccess < count; naccess++) {
2140 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2144 + acl_d->count = naccess;
2149 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2156 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2158 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2159 + && perm != SMB_ACL_EXECUTE) {
2164 + if (permset_d == NULL) {
2169 + *permset_d |= perm;
2174 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2176 + return *permset_d & perm;
2179 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2186 + * use an initial estimate of 20 bytes per ACL entry
2187 + * when allocating memory for the text representation
2191 + maxlen = 20 * acl_d->count;
2192 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2197 + for (i = 0; i < acl_d->count; i++) {
2198 + struct acl *ap = &acl_d->acl[i];
2207 + switch (ap->a_type) {
2209 + * for debugging purposes it's probably more
2210 + * useful to dump unknown tag types rather
2211 + * than just returning an error
2214 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2217 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2222 + case SMB_ACL_USER:
2223 + id = uidtoname(ap->a_id);
2224 + case SMB_ACL_USER_OBJ:
2228 + case SMB_ACL_GROUP:
2229 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2230 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2236 + case SMB_ACL_GROUP_OBJ:
2240 + case SMB_ACL_OTHER:
2244 + case SMB_ACL_MASK:
2250 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2251 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2252 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2255 + /* <tag> : <qualifier> : rwx \n \0 */
2256 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2259 + * If this entry would overflow the buffer
2260 + * allocate enough additional memory for this
2261 + * entry and an estimate of another 20 bytes
2262 + * for each entry still to be processed
2264 + if ((len + nbytes) > maxlen) {
2265 + char *oldtext = text;
2267 + maxlen += nbytes + 20 * (acl_d->count - i);
2269 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2270 + SAFE_FREE(oldtext);
2276 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2277 + len += nbytes - 1;
2286 +SMB_ACL_T sys_acl_init(int count)
2296 + * note that since the definition of the structure pointed
2297 + * to by the SMB_ACL_T includes the first element of the
2298 + * acl[] array, this actually allocates an ACL with room
2299 + * for (count+1) entries
2301 + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2306 + a->size = count + 1;
2314 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2317 + SMB_ACL_ENTRY_T entry_d;
2319 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2324 + if (acl_d->count >= acl_d->size) {
2329 + entry_d = &acl_d->acl[acl_d->count++];
2330 + entry_d->a_type = 0;
2331 + entry_d->a_id = -1;
2332 + entry_d->a_perm = 0;
2333 + *entry_p = entry_d;
2338 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2340 + switch (tag_type) {
2341 + case SMB_ACL_USER:
2342 + case SMB_ACL_USER_OBJ:
2343 + case SMB_ACL_GROUP:
2344 + case SMB_ACL_GROUP_OBJ:
2345 + case SMB_ACL_OTHER:
2346 + case SMB_ACL_MASK:
2347 + entry_d->a_type = tag_type;
2357 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2359 + if (entry_d->a_type != SMB_ACL_GROUP
2360 + && entry_d->a_type != SMB_ACL_USER) {
2365 + entry_d->a_id = *((id_t *)qual_p);
2370 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
2372 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2376 + entry_d->a_perm = *permset_d;
2382 + * sort the ACL and check it for validity
2384 + * if it's a minimal ACL with only 4 entries then we
2385 + * need to recalculate the mask permissions to make
2386 + * sure that they are the same as the GROUP_OBJ
2387 + * permissions as required by the UnixWare acl() system call.
2389 + * (note: since POSIX allows minimal ACLs which only contain
2390 + * 3 entries - ie there is no mask entry - we should, in theory,
2391 + * check for this and add a mask entry if necessary - however
2392 + * we "know" that the caller of this interface always specifies
2393 + * a mask so, in practice "this never happens" (tm) - if it *does*
2394 + * happen aclsort() will fail and return an error and someone will
2395 + * have to fix it ...)
2398 +static int acl_sort(SMB_ACL_T acl_d)
2400 + int fixmask = (acl_d->count <= 4);
2402 + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2409 +int sys_acl_valid(SMB_ACL_T acl_d)
2411 + return acl_sort(acl_d);
2414 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
2417 + struct acl *acl_p;
2419 + struct acl *acl_buf = NULL;
2422 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2427 + if (acl_sort(acl_d) != 0) {
2431 + acl_p = &acl_d->acl[0];
2432 + acl_count = acl_d->count;
2435 + * if it's a directory there is extra work to do
2436 + * since the acl() system call will replace both
2437 + * the access ACLs and the default ACLs (if any)
2439 + if (stat(name, &s) != 0) {
2442 + if (S_ISDIR(s.st_mode)) {
2443 + SMB_ACL_T acc_acl;
2444 + SMB_ACL_T def_acl;
2445 + SMB_ACL_T tmp_acl;
2448 + if (type == SMB_ACL_TYPE_ACCESS) {
2450 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2454 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2457 + if (tmp_acl == NULL) {
2462 + * allocate a temporary buffer for the complete ACL
2464 + acl_count = acc_acl->count + def_acl->count;
2465 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
2467 + if (acl_buf == NULL) {
2468 + sys_acl_free_acl(tmp_acl);
2474 + * copy the access control and default entries into the buffer
2476 + memcpy(&acl_buf[0], &acc_acl->acl[0],
2477 + acc_acl->count * sizeof(acl_buf[0]));
2479 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
2480 + def_acl->count * sizeof(acl_buf[0]));
2483 + * set the ACL_DEFAULT flag on the default entries
2485 + for (i = acc_acl->count; i < acl_count; i++) {
2486 + acl_buf[i].a_type |= ACL_DEFAULT;
2489 + sys_acl_free_acl(tmp_acl);
2491 + } else if (type != SMB_ACL_TYPE_ACCESS) {
2496 + ret = acl(name, SETACL, acl_count, acl_p);
2498 + SAFE_FREE(acl_buf);
2503 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
2505 + if (acl_sort(acl_d) != 0) {
2509 + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2512 +int sys_acl_delete_def_file(const char *path)
2518 + * fetching the access ACL and rewriting it has
2519 + * the effect of deleting the default ACL
2521 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2525 + ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2527 + sys_acl_free_acl(acl_d);
2532 +int sys_acl_free_text(char *text)
2538 +int sys_acl_free_acl(SMB_ACL_T acl_d)
2544 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
2549 +#elif defined(HAVE_HPUX_ACLS)
2553 + * Based on the Solaris/SCO code - with modifications.
2557 + * Note that while this code implements sufficient functionality
2558 + * to support the sys_acl_* interfaces it does not provide all
2559 + * of the semantics of the POSIX ACL interfaces.
2561 + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2562 + * from a call to sys_acl_get_entry() should not be assumed to be
2563 + * valid after calling any of the following functions, which may
2564 + * reorder the entries in the ACL.
2567 + * sys_acl_set_file()
2568 + * sys_acl_set_fd()
2571 +/* This checks if the POSIX ACL system call is defined */
2572 +/* which basically corresponds to whether JFS 3.3 or */
2573 +/* higher is installed. If acl() was called when it */
2574 +/* isn't defined, it causes the process to core dump */
2575 +/* so it is important to check this and avoid acl() */
2576 +/* calls if it isn't there. */
2578 +static BOOL hpux_acl_call_presence(void)
2581 + shl_t handle = NULL;
2584 + static BOOL already_checked=0;
2586 + if(already_checked)
2590 + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2592 + if(ret_val != 0) {
2593 + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2594 + ret_val, errno, strerror(errno)));
2595 + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2599 + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2601 + already_checked = True;
2605 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
2607 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2612 + if (entry_p == NULL) {
2617 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
2621 + if (acl_d->next < 0) {
2626 + if (acl_d->next >= acl_d->count) {
2630 + *entry_p = &acl_d->acl[acl_d->next++];
2635 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
2637 + *type_p = entry_d->a_type;
2642 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
2644 + *permset_p = &entry_d->a_perm;
2649 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
2651 + if (entry_d->a_type != SMB_ACL_USER
2652 + && entry_d->a_type != SMB_ACL_GROUP) {
2657 + return &entry_d->a_id;
2661 + * There is no way of knowing what size the ACL returned by
2662 + * ACL_GET will be unless you first call ACL_CNT which means
2663 + * making an additional system call.
2665 + * In the hope of avoiding the cost of the additional system
2666 + * call in most cases, we initially allocate enough space for
2667 + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2668 + * be too small then we use ACL_CNT to find out the actual
2669 + * size, reallocate the ACL buffer, and then call ACL_GET again.
2672 +#define INITIAL_ACL_SIZE 16
2674 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
2677 + int count; /* # of ACL entries allocated */
2678 + int naccess; /* # of access ACL entries */
2679 + int ndefault; /* # of default ACL entries */
2681 + if(hpux_acl_call_presence() == False) {
2682 + /* Looks like we don't have the acl() system call on HPUX.
2683 + * May be the system doesn't have the latest version of JFS.
2688 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2693 + count = INITIAL_ACL_SIZE;
2694 + if ((acl_d = sys_acl_init(count)) == NULL) {
2699 + * If there isn't enough space for the ACL entries we use
2700 + * ACL_CNT to determine the actual number of ACL entries
2701 + * reallocate and try again. This is in a loop because it
2702 + * is possible that someone else could modify the ACL and
2703 + * increase the number of entries between the call to
2704 + * ACL_CNT and the call to ACL_GET.
2706 + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2708 + sys_acl_free_acl(acl_d);
2710 + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2714 + if ((acl_d = sys_acl_init(count)) == NULL) {
2720 + sys_acl_free_acl(acl_d);
2725 + * calculate the number of access and default ACL entries
2727 + * Note: we assume that the acl() system call returned a
2728 + * well formed ACL which is sorted so that all of the
2729 + * access ACL entries preceed any default ACL entries
2731 + for (naccess = 0; naccess < count; naccess++) {
2732 + if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2735 + ndefault = count - naccess;
2738 + * if the caller wants the default ACL we have to copy
2739 + * the entries down to the start of the acl[] buffer
2740 + * and mask out the ACL_DEFAULT flag from the type field
2742 + if (type == SMB_ACL_TYPE_DEFAULT) {
2745 + for (i = 0, j = naccess; i < ndefault; i++, j++) {
2746 + acl_d->acl[i] = acl_d->acl[j];
2747 + acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2750 + acl_d->count = ndefault;
2752 + acl_d->count = naccess;
2758 +SMB_ACL_T sys_acl_get_fd(int fd)
2761 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2764 + files_struct *fsp = file_find_fd(fd);
2766 + if (fsp == NULL) {
2772 + * We know we're in the same conn context. So we
2773 + * can use the relative path.
2776 + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
2779 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
2786 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2788 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2789 + && perm != SMB_ACL_EXECUTE) {
2794 + if (permset_d == NULL) {
2799 + *permset_d |= perm;
2804 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
2806 + return *permset_d & perm;
2809 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
2816 + * use an initial estimate of 20 bytes per ACL entry
2817 + * when allocating memory for the text representation
2821 + maxlen = 20 * acl_d->count;
2822 + if ((text = SMB_MALLOC(maxlen)) == NULL) {
2827 + for (i = 0; i < acl_d->count; i++) {
2828 + struct acl *ap = &acl_d->acl[i];
2837 + switch (ap->a_type) {
2839 + * for debugging purposes it's probably more
2840 + * useful to dump unknown tag types rather
2841 + * than just returning an error
2844 + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
2847 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2852 + case SMB_ACL_USER:
2853 + id = uidtoname(ap->a_id);
2854 + case SMB_ACL_USER_OBJ:
2858 + case SMB_ACL_GROUP:
2859 + if ((gr = getgrgid(ap->a_id)) == NULL) {
2860 + slprintf(idbuf, sizeof(idbuf)-1, "%ld",
2866 + case SMB_ACL_GROUP_OBJ:
2870 + case SMB_ACL_OTHER:
2874 + case SMB_ACL_MASK:
2880 + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2881 + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2882 + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2885 + /* <tag> : <qualifier> : rwx \n \0 */
2886 + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2889 + * If this entry would overflow the buffer
2890 + * allocate enough additional memory for this
2891 + * entry and an estimate of another 20 bytes
2892 + * for each entry still to be processed
2894 + if ((len + nbytes) > maxlen) {
2895 + char *oldtext = text;
2897 + maxlen += nbytes + 20 * (acl_d->count - i);
2899 + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
2906 + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
2907 + len += nbytes - 1;
2916 +SMB_ACL_T sys_acl_init(int count)
2926 + * note that since the definition of the structure pointed
2927 + * to by the SMB_ACL_T includes the first element of the
2928 + * acl[] array, this actually allocates an ACL with room
2929 + * for (count+1) entries
2931 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
2936 + a->size = count + 1;
2944 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
2947 + SMB_ACL_ENTRY_T entry_d;
2949 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2954 + if (acl_d->count >= acl_d->size) {
2959 + entry_d = &acl_d->acl[acl_d->count++];
2960 + entry_d->a_type = 0;
2961 + entry_d->a_id = -1;
2962 + entry_d->a_perm = 0;
2963 + *entry_p = entry_d;
2968 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
2970 + switch (tag_type) {
2971 + case SMB_ACL_USER:
2972 + case SMB_ACL_USER_OBJ:
2973 + case SMB_ACL_GROUP:
2974 + case SMB_ACL_GROUP_OBJ:
2975 + case SMB_ACL_OTHER:
2976 + case SMB_ACL_MASK:
2977 + entry_d->a_type = tag_type;
2987 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
2989 + if (entry_d->a_type != SMB_ACL_GROUP
2990 + && entry_d->a_type != SMB_ACL_USER) {
2995 + entry_d->a_id = *((id_t *)qual_p);
3000 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3002 + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3006 + entry_d->a_perm = *permset_d;
3011 +/* Structure to capture the count for each type of ACE. */
3013 +struct hpux_acl_types {
3017 + int n_def_user_obj;
3022 + int n_def_group_obj;
3026 + int n_def_other_obj;
3029 + int n_def_class_obj;
3031 + int n_illegal_obj;
3035 + * Counts the different number of objects in a given array of ACL
3039 + * acl_count - Count of ACLs in the array of ACL strucutres.
3040 + * aclp - Array of ACL structures.
3041 + * acl_type_count - Pointer to acl_types structure. Should already be
3045 + * acl_type_count - This structure is filled up with counts of various
3049 +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
3053 + memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
3055 + for(i=0;i<acl_count;i++) {
3056 + switch(aclp[i].a_type) {
3058 + acl_type_count->n_user++;
3061 + acl_type_count->n_user_obj++;
3063 + case DEF_USER_OBJ:
3064 + acl_type_count->n_def_user_obj++;
3067 + acl_type_count->n_group++;
3070 + acl_type_count->n_group_obj++;
3072 + case DEF_GROUP_OBJ:
3073 + acl_type_count->n_def_group_obj++;
3076 + acl_type_count->n_other_obj++;
3078 + case DEF_OTHER_OBJ:
3079 + acl_type_count->n_def_other_obj++;
3082 + acl_type_count->n_class_obj++;
3084 + case DEF_CLASS_OBJ:
3085 + acl_type_count->n_def_class_obj++;
3088 + acl_type_count->n_def_user++;
3091 + acl_type_count->n_def_group++;
3094 + acl_type_count->n_illegal_obj++;
3100 +/* swap_acl_entries: Swaps two ACL entries.
3102 + * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3105 +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3107 + struct acl temp_acl;
3109 + temp_acl.a_type = aclp0->a_type;
3110 + temp_acl.a_id = aclp0->a_id;
3111 + temp_acl.a_perm = aclp0->a_perm;
3113 + aclp0->a_type = aclp1->a_type;
3114 + aclp0->a_id = aclp1->a_id;
3115 + aclp0->a_perm = aclp1->a_perm;
3117 + aclp1->a_type = temp_acl.a_type;
3118 + aclp1->a_id = temp_acl.a_id;
3119 + aclp1->a_perm = temp_acl.a_perm;
3122 +/* prohibited_duplicate_type
3123 + * Identifies if given ACL type can have duplicate entries or
3126 + * Inputs: acl_type - ACL Type.
3132 + * True - If the ACL type matches any of the prohibited types.
3133 + * False - If the ACL type doesn't match any of the prohibited types.
3136 +static BOOL hpux_prohibited_duplicate_type(int acl_type)
3138 + switch(acl_type) {
3149 +/* get_needed_class_perm
3150 + * Returns the permissions of a ACL structure only if the ACL
3151 + * type matches one of the pre-determined types for computing
3152 + * CLASS_OBJ permissions.
3154 + * Inputs: aclp - Pointer to ACL structure.
3157 +static int hpux_get_needed_class_perm(struct acl *aclp)
3159 + switch(aclp->a_type) {
3163 + case DEF_USER_OBJ:
3165 + case DEF_GROUP_OBJ:
3167 + case DEF_CLASS_OBJ:
3168 + case DEF_OTHER_OBJ:
3169 + return aclp->a_perm;
3175 +/* acl_sort for HPUX.
3176 + * Sorts the array of ACL structures as per the description in
3177 + * aclsort man page. Refer to aclsort man page for more details
3181 + * acl_count - Count of ACLs in the array of ACL structures.
3182 + * calclass - If this is not zero, then we compute the CLASS_OBJ
3184 + * aclp - Array of ACL structures.
3188 + * aclp - Sorted array of ACL structures.
3192 + * Returns 0 for success -1 for failure. Prints a message to the Samba
3193 + * debug log in case of failure.
3196 +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3198 +#if !defined(HAVE_HPUX_ACLSORT)
3200 + * The aclsort() system call is availabe on the latest HPUX General
3201 + * Patch Bundles. So for HPUX, we developed our version of acl_sort
3202 + * function. Because, we don't want to update to a new
3203 + * HPUX GR bundle just for aclsort() call.
3206 + struct hpux_acl_types acl_obj_count;
3207 + int n_class_obj_perm = 0;
3211 + DEBUG(10,("Zero acl count passed. Returning Success\n"));
3215 + if(aclp == NULL) {
3216 + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3220 + /* Count different types of ACLs in the ACLs array */
3222 + hpux_count_obj(acl_count, aclp, &acl_obj_count);
3224 + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3225 + * CLASS_OBJ and OTHER_OBJ
3228 + if( (acl_obj_count.n_user_obj != 1) ||
3229 + (acl_obj_count.n_group_obj != 1) ||
3230 + (acl_obj_count.n_class_obj != 1) ||
3231 + (acl_obj_count.n_other_obj != 1)
3233 + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3234 +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3238 + /* If any of the default objects are present, there should be only
3239 + * one of them each.
3242 + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3243 + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
3244 + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3245 +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3249 + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3252 + * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3253 + * same ACL type, sort by ACL id.
3255 + * I am using the trival kind of sorting method here because, performance isn't
3256 + * really effected by the ACLs feature. More over there aren't going to be more
3257 + * than 17 entries on HPUX.
3260 + for(i=0; i<acl_count;i++) {
3261 + for (j=i+1; j<acl_count; j++) {
3262 + if( aclp[i].a_type > aclp[j].a_type ) {
3263 + /* ACL entries out of order, swap them */
3265 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3267 + } else if ( aclp[i].a_type == aclp[j].a_type ) {
3269 + /* ACL entries of same type, sort by id */
3271 + if(aclp[i].a_id > aclp[j].a_id) {
3272 + hpux_swap_acl_entries((aclp+i), (aclp+j));
3273 + } else if (aclp[i].a_id == aclp[j].a_id) {
3274 + /* We have a duplicate entry. */
3275 + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
3276 + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3277 + aclp[i].a_type, aclp[i].a_id));
3286 + /* set the class obj permissions to the computed one. */
3288 + int n_class_obj_index = -1;
3290 + for(i=0;i<acl_count;i++) {
3291 + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3293 + if(aclp[i].a_type == CLASS_OBJ)
3294 + n_class_obj_index = i;
3296 + aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3301 + return aclsort(acl_count, calclass, aclp);
3306 + * sort the ACL and check it for validity
3308 + * if it's a minimal ACL with only 4 entries then we
3309 + * need to recalculate the mask permissions to make
3310 + * sure that they are the same as the GROUP_OBJ
3311 + * permissions as required by the UnixWare acl() system call.
3313 + * (note: since POSIX allows minimal ACLs which only contain
3314 + * 3 entries - ie there is no mask entry - we should, in theory,
3315 + * check for this and add a mask entry if necessary - however
3316 + * we "know" that the caller of this interface always specifies
3317 + * a mask so, in practice "this never happens" (tm) - if it *does*
3318 + * happen aclsort() will fail and return an error and someone will
3319 + * have to fix it ...)
3322 +static int acl_sort(SMB_ACL_T acl_d)
3324 + int fixmask = (acl_d->count <= 4);
3326 + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3333 +int sys_acl_valid(SMB_ACL_T acl_d)
3335 + return acl_sort(acl_d);
3338 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3341 + struct acl *acl_p;
3343 + struct acl *acl_buf = NULL;
3346 + if(hpux_acl_call_presence() == False) {
3347 + /* Looks like we don't have the acl() system call on HPUX.
3348 + * May be the system doesn't have the latest version of JFS.
3354 + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3359 + if (acl_sort(acl_d) != 0) {
3363 + acl_p = &acl_d->acl[0];
3364 + acl_count = acl_d->count;
3367 + * if it's a directory there is extra work to do
3368 + * since the acl() system call will replace both
3369 + * the access ACLs and the default ACLs (if any)
3371 + if (stat(name, &s) != 0) {
3374 + if (S_ISDIR(s.st_mode)) {
3375 + SMB_ACL_T acc_acl;
3376 + SMB_ACL_T def_acl;
3377 + SMB_ACL_T tmp_acl;
3380 + if (type == SMB_ACL_TYPE_ACCESS) {
3382 + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3386 + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3389 + if (tmp_acl == NULL) {
3394 + * allocate a temporary buffer for the complete ACL
3396 + acl_count = acc_acl->count + def_acl->count;
3397 + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
3399 + if (acl_buf == NULL) {
3400 + sys_acl_free_acl(tmp_acl);
3406 + * copy the access control and default entries into the buffer
3408 + memcpy(&acl_buf[0], &acc_acl->acl[0],
3409 + acc_acl->count * sizeof(acl_buf[0]));
3411 + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
3412 + def_acl->count * sizeof(acl_buf[0]));
3415 + * set the ACL_DEFAULT flag on the default entries
3417 + for (i = acc_acl->count; i < acl_count; i++) {
3418 + acl_buf[i].a_type |= ACL_DEFAULT;
3421 + sys_acl_free_acl(tmp_acl);
3423 + } else if (type != SMB_ACL_TYPE_ACCESS) {
3428 + ret = acl(name, ACL_SET, acl_count, acl_p);
3437 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3440 + * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3443 + files_struct *fsp = file_find_fd(fd);
3445 + if (fsp == NULL) {
3450 + if (acl_sort(acl_d) != 0) {
3455 + * We know we're in the same conn context. So we
3456 + * can use the relative path.
3459 + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
3462 +int sys_acl_delete_def_file(const char *path)
3468 + * fetching the access ACL and rewriting it has
3469 + * the effect of deleting the default ACL
3471 + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3475 + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3477 + sys_acl_free_acl(acl_d);
3482 +int sys_acl_free_text(char *text)
3488 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3494 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3499 +#elif defined(HAVE_IRIX_ACLS)
3501 +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3503 + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3508 + if (entry_p == NULL) {
3513 + if (entry_id == SMB_ACL_FIRST_ENTRY) {
3517 + if (acl_d->next < 0) {
3522 + if (acl_d->next >= acl_d->aclp->acl_cnt) {
3526 + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3531 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
3533 + *type_p = entry_d->ae_tag;
3538 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3540 + *permset_p = entry_d;
3545 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
3547 + if (entry_d->ae_tag != SMB_ACL_USER
3548 + && entry_d->ae_tag != SMB_ACL_GROUP) {
3553 + return &entry_d->ae_id;
3556 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
3560 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3564 + if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
3569 + a->freeaclp = True;
3573 +SMB_ACL_T sys_acl_get_fd(int fd)
3577 + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
3581 + if ((a->aclp = acl_get_fd(fd)) == NULL) {
3586 + a->freeaclp = True;
3590 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
3592 + permset_d->ae_perm = 0;
3597 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3599 + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3600 + && perm != SMB_ACL_EXECUTE) {
3605 + if (permset_d == NULL) {
3610 + permset_d->ae_perm |= perm;
3615 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
3617 + return permset_d->ae_perm & perm;
3620 +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
3622 + return acl_to_text(acl_d->aclp, len_p);
3625 +SMB_ACL_T sys_acl_init(int count)
3634 + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
3640 + a->freeaclp = False;
3641 + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
3642 + a->aclp->acl_cnt = 0;
3648 +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
3651 + SMB_ACL_ENTRY_T entry_d;
3653 + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3658 + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3663 + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3664 + entry_d->ae_tag = 0;
3665 + entry_d->ae_id = 0;
3666 + entry_d->ae_perm = 0;
3667 + *entry_p = entry_d;
3672 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
3674 + switch (tag_type) {
3675 + case SMB_ACL_USER:
3676 + case SMB_ACL_USER_OBJ:
3677 + case SMB_ACL_GROUP:
3678 + case SMB_ACL_GROUP_OBJ:
3679 + case SMB_ACL_OTHER:
3680 + case SMB_ACL_MASK:
3681 + entry_d->ae_tag = tag_type;
3691 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
3693 + if (entry_d->ae_tag != SMB_ACL_GROUP
3694 + && entry_d->ae_tag != SMB_ACL_USER) {
3699 + entry_d->ae_id = *((id_t *)qual_p);
3704 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
3706 + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3710 + entry_d->ae_perm = permset_d->ae_perm;
3715 +int sys_acl_valid(SMB_ACL_T acl_d)
3717 + return acl_valid(acl_d->aclp);
3720 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
3722 + return acl_set_file(name, type, acl_d->aclp);
3725 +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
3727 + return acl_set_fd(fd, acl_d->aclp);
3730 +int sys_acl_delete_def_file(const char *name)
3732 + return acl_delete_def_file(name);
3735 +int sys_acl_free_text(char *text)
3737 + return acl_free(text);
3740 +int sys_acl_free_acl(SMB_ACL_T acl_d)
3742 + if (acl_d->freeaclp) {
3743 + acl_free(acl_d->aclp);
3749 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
3754 +#elif defined(HAVE_AIX_ACLS)
3756 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3758 +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
3760 + struct acl_entry_link *link;
3761 + struct new_acl_entry *entry;
3764 + DEBUG(10,("This is the count: %d\n",theacl->count));
3766 + /* Check if count was previously set to -1. *
3767 + * If it was, that means we reached the end *
3768 + * of the acl last time. */
3769 + if(theacl->count == -1)
3773 + /* To get to the next acl, traverse linked list until index *
3774 + * of acl matches the count we are keeping. This count is *
3775 + * incremented each time we return an acl entry. */
3777 + for(keep_going = 0; keep_going < theacl->count; keep_going++)
3778 + link = link->nextp;
3780 + entry = *entry_p = link->entryp;
3782 + DEBUG(10,("*entry_p is %d\n",entry_p));
3783 + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3785 + /* Increment count */
3787 + if(link->nextp == NULL)
3788 + theacl->count = -1;
3793 +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
3795 + /* Initialize tag type */
3798 + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3800 + /* Depending on what type of entry we have, *
3801 + * return tag type. */
3802 + switch(entry_d->ace_id->id_type) {
3804 + *tag_type_p = SMB_ACL_USER;
3807 + *tag_type_p = SMB_ACL_GROUP;
3810 + case SMB_ACL_USER_OBJ:
3811 + case SMB_ACL_GROUP_OBJ:
3812 + case SMB_ACL_OTHER:
3813 + *tag_type_p = entry_d->ace_id->id_type;
3823 +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
3825 + DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3826 + *permset_p = &entry_d->ace_access;
3827 + DEBUG(10,("**permset_p is %d\n",**permset_p));
3828 + if(!(**permset_p & S_IXUSR) &&
3829 + !(**permset_p & S_IWUSR) &&
3830 + !(**permset_p & S_IRUSR) &&
3831 + (**permset_p != 0))
3834 + DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
3838 +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
3840 + return(entry_d->ace_id->id_data);
3843 +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
3845 + struct acl *file_acl = (struct acl *)NULL;
3846 + struct acl_entry *acl_entry;
3847 + struct new_acl_entry *new_acl_entry;
3848 + struct ace_id *idp;
3849 + struct acl_entry_link *acl_entry_link;
3850 + struct acl_entry_link *acl_entry_link_head;
3855 + /* AIX has no DEFAULT */
3856 + if ( type == SMB_ACL_TYPE_DEFAULT )
3859 + /* Get the acl using statacl */
3861 + DEBUG(10,("Entering sys_acl_get_file\n"));
3862 + DEBUG(10,("path_p is %s\n",path_p));
3864 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
3866 + if(file_acl == NULL) {
3868 + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
3872 + memset(file_acl,0,BUFSIZ);
3874 + rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
3876 + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
3877 + SAFE_FREE(file_acl);
3881 + DEBUG(10,("Got facl and returned it\n"));
3883 + /* Point to the first acl entry in the acl */
3884 + acl_entry = file_acl->acl_ext;
3886 + /* Begin setting up the head of the linked list *
3887 + * that will be used for the storing the acl *
3888 + * in a way that is useful for the posix_acls.c *
3891 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
3892 + if(acl_entry_link_head == NULL)
3895 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3896 + if(acl_entry_link->entryp == NULL) {
3897 + SAFE_FREE(file_acl);
3899 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3903 + DEBUG(10,("acl_entry is %d\n",acl_entry));
3904 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3906 + /* Check if the extended acl bit is on. *
3907 + * If it isn't, do not show the *
3908 + * contents of the acl since AIX intends *
3909 + * the extended info to remain unused */
3911 + if(file_acl->acl_mode & S_IXACL){
3912 + /* while we are not pointing to the very end */
3913 + while(acl_entry < acl_last(file_acl)) {
3914 + /* before we malloc anything, make sure this is */
3915 + /* a valid acl entry and one that we want to map */
3916 + idp = id_nxt(acl_entry->ace_id);
3917 + if((acl_entry->ace_type == ACC_SPECIFY ||
3918 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3919 + acl_entry = acl_nxt(acl_entry);
3923 + idp = acl_entry->ace_id;
3925 + /* Check if this is the first entry in the linked list. *
3926 + * The first entry needs to keep prevp pointing to NULL *
3927 + * and already has entryp allocated. */
3929 + if(acl_entry_link_head->count != 0) {
3930 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
3932 + if(acl_entry_link->nextp == NULL) {
3933 + SAFE_FREE(file_acl);
3935 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3939 + acl_entry_link->nextp->prevp = acl_entry_link;
3940 + acl_entry_link = acl_entry_link->nextp;
3941 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
3942 + if(acl_entry_link->entryp == NULL) {
3943 + SAFE_FREE(file_acl);
3945 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
3948 + acl_entry_link->nextp = NULL;
3951 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3953 + /* Don't really need this since all types are going *
3954 + * to be specified but, it's better than leaving it 0 */
3956 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
3958 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3960 + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
3962 + /* The access in the acl entries must be left shifted by *
3963 + * three bites, because they will ultimately be compared *
3964 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
3966 + switch(acl_entry->ace_type){
3969 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3970 + acl_entry_link->entryp->ace_access <<= 6;
3971 + acl_entry_link_head->count++;
3974 + /* Since there is no way to return a DENY acl entry *
3975 + * change to PERMIT and then shift. */
3976 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3977 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3978 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3979 + acl_entry_link->entryp->ace_access <<= 6;
3980 + acl_entry_link_head->count++;
3986 + DEBUG(10,("acl_entry = %d\n",acl_entry));
3987 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
3989 + acl_entry = acl_nxt(acl_entry);
3991 + } /* end of if enabled */
3993 + /* Since owner, group, other acl entries are not *
3994 + * part of the acl entries in an acl, they must *
3995 + * be dummied up to become part of the list. */
3997 + for( i = 1; i < 4; i++) {
3998 + DEBUG(10,("i is %d\n",i));
3999 + if(acl_entry_link_head->count != 0) {
4000 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4001 + if(acl_entry_link->nextp == NULL) {
4002 + SAFE_FREE(file_acl);
4004 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4008 + acl_entry_link->nextp->prevp = acl_entry_link;
4009 + acl_entry_link = acl_entry_link->nextp;
4010 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4011 + if(acl_entry_link->entryp == NULL) {
4012 + SAFE_FREE(file_acl);
4014 + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
4019 + acl_entry_link->nextp = NULL;
4021 + new_acl_entry = acl_entry_link->entryp;
4022 + idp = new_acl_entry->ace_id;
4024 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4025 + new_acl_entry->ace_type = ACC_PERMIT;
4026 + idp->id_len = sizeof(struct ace_id);
4027 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4028 + memset(idp->id_data,0,sizeof(uid_t));
4032 + new_acl_entry->ace_access = file_acl->g_access << 6;
4033 + idp->id_type = SMB_ACL_GROUP_OBJ;
4037 + new_acl_entry->ace_access = file_acl->o_access << 6;
4038 + idp->id_type = SMB_ACL_OTHER;
4042 + new_acl_entry->ace_access = file_acl->u_access << 6;
4043 + idp->id_type = SMB_ACL_USER_OBJ;
4051 + acl_entry_link_head->count++;
4052 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4055 + acl_entry_link_head->count = 0;
4056 + SAFE_FREE(file_acl);
4058 + return(acl_entry_link_head);
4061 +SMB_ACL_T sys_acl_get_fd(int fd)
4063 + struct acl *file_acl = (struct acl *)NULL;
4064 + struct acl_entry *acl_entry;
4065 + struct new_acl_entry *new_acl_entry;
4066 + struct ace_id *idp;
4067 + struct acl_entry_link *acl_entry_link;
4068 + struct acl_entry_link *acl_entry_link_head;
4073 + /* Get the acl using fstatacl */
4075 + DEBUG(10,("Entering sys_acl_get_fd\n"));
4076 + DEBUG(10,("fd is %d\n",fd));
4077 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4079 + if(file_acl == NULL) {
4081 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4085 + memset(file_acl,0,BUFSIZ);
4087 + rc = fstatacl(fd,0,file_acl,BUFSIZ);
4089 + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
4090 + SAFE_FREE(file_acl);
4094 + DEBUG(10,("Got facl and returned it\n"));
4096 + /* Point to the first acl entry in the acl */
4098 + acl_entry = file_acl->acl_ext;
4099 + /* Begin setting up the head of the linked list *
4100 + * that will be used for the storing the acl *
4101 + * in a way that is useful for the posix_acls.c *
4104 + acl_entry_link_head = acl_entry_link = sys_acl_init(0);
4105 + if(acl_entry_link_head == NULL){
4106 + SAFE_FREE(file_acl);
4110 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4112 + if(acl_entry_link->entryp == NULL) {
4114 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4115 + SAFE_FREE(file_acl);
4119 + DEBUG(10,("acl_entry is %d\n",acl_entry));
4120 + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
4122 + /* Check if the extended acl bit is on. *
4123 + * If it isn't, do not show the *
4124 + * contents of the acl since AIX intends *
4125 + * the extended info to remain unused */
4127 + if(file_acl->acl_mode & S_IXACL){
4128 + /* while we are not pointing to the very end */
4129 + while(acl_entry < acl_last(file_acl)) {
4130 + /* before we malloc anything, make sure this is */
4131 + /* a valid acl entry and one that we want to map */
4133 + idp = id_nxt(acl_entry->ace_id);
4134 + if((acl_entry->ace_type == ACC_SPECIFY ||
4135 + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4136 + acl_entry = acl_nxt(acl_entry);
4140 + idp = acl_entry->ace_id;
4142 + /* Check if this is the first entry in the linked list. *
4143 + * The first entry needs to keep prevp pointing to NULL *
4144 + * and already has entryp allocated. */
4146 + if(acl_entry_link_head->count != 0) {
4147 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4148 + if(acl_entry_link->nextp == NULL) {
4150 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4151 + SAFE_FREE(file_acl);
4154 + acl_entry_link->nextp->prevp = acl_entry_link;
4155 + acl_entry_link = acl_entry_link->nextp;
4156 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4157 + if(acl_entry_link->entryp == NULL) {
4159 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4160 + SAFE_FREE(file_acl);
4164 + acl_entry_link->nextp = NULL;
4167 + acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4169 + /* Don't really need this since all types are going *
4170 + * to be specified but, it's better than leaving it 0 */
4172 + acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4173 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4175 + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
4177 + /* The access in the acl entries must be left shifted by *
4178 + * three bites, because they will ultimately be compared *
4179 + * to S_IRUSR, S_IWUSR, and S_IXUSR. */
4181 + switch(acl_entry->ace_type){
4184 + acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4185 + acl_entry_link->entryp->ace_access <<= 6;
4186 + acl_entry_link_head->count++;
4189 + /* Since there is no way to return a DENY acl entry *
4190 + * change to PERMIT and then shift. */
4191 + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4192 + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4193 + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4194 + acl_entry_link->entryp->ace_access <<= 6;
4195 + acl_entry_link_head->count++;
4201 + DEBUG(10,("acl_entry = %d\n",acl_entry));
4202 + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
4204 + acl_entry = acl_nxt(acl_entry);
4206 + } /* end of if enabled */
4208 + /* Since owner, group, other acl entries are not *
4209 + * part of the acl entries in an acl, they must *
4210 + * be dummied up to become part of the list. */
4212 + for( i = 1; i < 4; i++) {
4213 + DEBUG(10,("i is %d\n",i));
4214 + if(acl_entry_link_head->count != 0){
4215 + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
4216 + if(acl_entry_link->nextp == NULL) {
4218 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4219 + SAFE_FREE(file_acl);
4223 + acl_entry_link->nextp->prevp = acl_entry_link;
4224 + acl_entry_link = acl_entry_link->nextp;
4225 + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
4227 + if(acl_entry_link->entryp == NULL) {
4228 + SAFE_FREE(file_acl);
4230 + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
4235 + acl_entry_link->nextp = NULL;
4237 + new_acl_entry = acl_entry_link->entryp;
4238 + idp = new_acl_entry->ace_id;
4240 + new_acl_entry->ace_len = sizeof(struct acl_entry);
4241 + new_acl_entry->ace_type = ACC_PERMIT;
4242 + idp->id_len = sizeof(struct ace_id);
4243 + DEBUG(10,("idp->id_len = %d\n",idp->id_len));
4244 + memset(idp->id_data,0,sizeof(uid_t));
4248 + new_acl_entry->ace_access = file_acl->g_access << 6;
4249 + idp->id_type = SMB_ACL_GROUP_OBJ;
4253 + new_acl_entry->ace_access = file_acl->o_access << 6;
4254 + idp->id_type = SMB_ACL_OTHER;
4258 + new_acl_entry->ace_access = file_acl->u_access << 6;
4259 + idp->id_type = SMB_ACL_USER_OBJ;
4266 + acl_entry_link_head->count++;
4267 + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4270 + acl_entry_link_head->count = 0;
4271 + SAFE_FREE(file_acl);
4273 + return(acl_entry_link_head);
4276 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
4278 + *permset = *permset & ~0777;
4282 +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4285 + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4289 + DEBUG(10,("This is the permset now: %d\n",*permset));
4293 +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
4298 +SMB_ACL_T sys_acl_init( int count)
4300 + struct acl_entry_link *theacl = NULL;
4302 + DEBUG(10,("Entering sys_acl_init\n"));
4304 + theacl = SMB_MALLOC_P(struct acl_entry_link);
4305 + if(theacl == NULL) {
4307 + DEBUG(0,("Error in sys_acl_init is %d\n",errno));
4311 + theacl->count = 0;
4312 + theacl->nextp = NULL;
4313 + theacl->prevp = NULL;
4314 + theacl->entryp = NULL;
4315 + DEBUG(10,("Exiting sys_acl_init\n"));
4319 +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
4321 + struct acl_entry_link *theacl;
4322 + struct acl_entry_link *acl_entryp;
4323 + struct acl_entry_link *temp_entry;
4326 + DEBUG(10,("Entering the sys_acl_create_entry\n"));
4328 + theacl = acl_entryp = *pacl;
4330 + /* Get to the end of the acl before adding entry */
4332 + for(counting=0; counting < theacl->count; counting++){
4333 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4334 + temp_entry = acl_entryp;
4335 + acl_entryp = acl_entryp->nextp;
4338 + if(theacl->count != 0){
4339 + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
4340 + if(acl_entryp == NULL) {
4342 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4346 + DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4347 + acl_entryp->prevp = temp_entry;
4348 + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4351 + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
4352 + if(*pentry == NULL) {
4354 + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
4358 + memset(*pentry,0,sizeof(struct new_acl_entry));
4359 + acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
4360 + acl_entryp->entryp->ace_type = ACC_PERMIT;
4361 + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
4362 + acl_entryp->nextp = NULL;
4364 + DEBUG(10,("Exiting sys_acl_create_entry\n"));
4368 +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
4370 + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4371 + entry->ace_id->id_type = tagtype;
4372 + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4373 + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4376 +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
4378 + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
4379 + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
4380 + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
4384 +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
4386 + DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
4387 + if(!(*permset & S_IXUSR) &&
4388 + !(*permset & S_IWUSR) &&
4389 + !(*permset & S_IRUSR) &&
4393 + entry->ace_access = *permset;
4394 + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4395 + DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
4399 +int sys_acl_valid( SMB_ACL_T theacl )
4402 + int group_obj = 0;
4403 + int other_obj = 0;
4404 + struct acl_entry_link *acl_entry;
4406 + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
4407 + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4408 + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4409 + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4412 + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
4414 + if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4420 +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
4422 + struct acl_entry_link *acl_entry_link = NULL;
4423 + struct acl *file_acl = NULL;
4424 + struct acl *file_acl_temp = NULL;
4425 + struct acl_entry *acl_entry = NULL;
4426 + struct ace_id *ace_id = NULL;
4433 + DEBUG(10,("Entering sys_acl_set_file\n"));
4434 + DEBUG(10,("File name is %s\n",name));
4436 + /* AIX has no default ACL */
4437 + if(acltype == SMB_ACL_TYPE_DEFAULT)
4440 + acl_length = BUFSIZ;
4441 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4443 + if(file_acl == NULL) {
4445 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4449 + memset(file_acl,0,BUFSIZ);
4451 + file_acl->acl_len = ACL_SIZ;
4452 + file_acl->acl_mode = S_IXACL;
4454 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4455 + acl_entry_link->entryp->ace_access >>= 6;
4456 + id_type = acl_entry_link->entryp->ace_id->id_type;
4459 + case SMB_ACL_USER_OBJ:
4460 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4462 + case SMB_ACL_GROUP_OBJ:
4463 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4465 + case SMB_ACL_OTHER:
4466 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4468 + case SMB_ACL_MASK:
4472 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4473 + acl_length += sizeof(struct acl_entry);
4474 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4475 + if(file_acl_temp == NULL) {
4476 + SAFE_FREE(file_acl);
4478 + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
4482 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4483 + SAFE_FREE(file_acl);
4484 + file_acl = file_acl_temp;
4487 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4488 + file_acl->acl_len += sizeof(struct acl_entry);
4489 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4490 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4492 + /* In order to use this, we'll need to wait until we can get denies */
4493 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4494 + acl_entry->ace_type = ACC_SPECIFY; */
4496 + acl_entry->ace_type = ACC_SPECIFY;
4498 + ace_id = acl_entry->ace_id;
4500 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4501 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4502 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4503 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4504 + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
4507 + rc = chacl(name,file_acl,file_acl->acl_len);
4508 + DEBUG(10,("errno is %d\n",errno));
4509 + DEBUG(10,("return code is %d\n",rc));
4510 + SAFE_FREE(file_acl);
4511 + DEBUG(10,("Exiting the sys_acl_set_file\n"));
4515 +int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
4517 + struct acl_entry_link *acl_entry_link = NULL;
4518 + struct acl *file_acl = NULL;
4519 + struct acl *file_acl_temp = NULL;
4520 + struct acl_entry *acl_entry = NULL;
4521 + struct ace_id *ace_id = NULL;
4527 + DEBUG(10,("Entering sys_acl_set_fd\n"));
4528 + acl_length = BUFSIZ;
4529 + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
4531 + if(file_acl == NULL) {
4533 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4537 + memset(file_acl,0,BUFSIZ);
4539 + file_acl->acl_len = ACL_SIZ;
4540 + file_acl->acl_mode = S_IXACL;
4542 + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
4543 + acl_entry_link->entryp->ace_access >>= 6;
4544 + id_type = acl_entry_link->entryp->ace_id->id_type;
4545 + DEBUG(10,("The id_type is %d\n",id_type));
4548 + case SMB_ACL_USER_OBJ:
4549 + file_acl->u_access = acl_entry_link->entryp->ace_access;
4551 + case SMB_ACL_GROUP_OBJ:
4552 + file_acl->g_access = acl_entry_link->entryp->ace_access;
4554 + case SMB_ACL_OTHER:
4555 + file_acl->o_access = acl_entry_link->entryp->ace_access;
4557 + case SMB_ACL_MASK:
4561 + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4562 + acl_length += sizeof(struct acl_entry);
4563 + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
4564 + if(file_acl_temp == NULL) {
4565 + SAFE_FREE(file_acl);
4567 + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
4571 + memcpy(file_acl_temp,file_acl,file_acl->acl_len);
4572 + SAFE_FREE(file_acl);
4573 + file_acl = file_acl_temp;
4576 + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
4577 + file_acl->acl_len += sizeof(struct acl_entry);
4578 + acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4579 + acl_entry->ace_access = acl_entry_link->entryp->ace_access;
4581 + /* In order to use this, we'll need to wait until we can get denies */
4582 + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4583 + acl_entry->ace_type = ACC_SPECIFY; */
4585 + acl_entry->ace_type = ACC_SPECIFY;
4587 + ace_id = acl_entry->ace_id;
4589 + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4590 + DEBUG(10,("The id type is %d\n",ace_id->id_type));
4591 + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
4592 + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4593 + memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
4596 + rc = fchacl(fd,file_acl,file_acl->acl_len);
4597 + DEBUG(10,("errno is %d\n",errno));
4598 + DEBUG(10,("return code is %d\n",rc));
4599 + SAFE_FREE(file_acl);
4600 + DEBUG(10,("Exiting sys_acl_set_fd\n"));
4604 +int sys_acl_delete_def_file(const char *name)
4606 + /* AIX has no default ACL */
4610 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4612 + return(*permset & perm);
4615 +int sys_acl_free_text(char *text)
4620 +int sys_acl_free_acl(SMB_ACL_T posix_acl)
4622 + struct acl_entry_link *acl_entry_link;
4624 + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4625 + SAFE_FREE(acl_entry_link->prevp->entryp);
4626 + SAFE_FREE(acl_entry_link->prevp);
4629 + SAFE_FREE(acl_entry_link->prevp->entryp);
4630 + SAFE_FREE(acl_entry_link->prevp);
4631 + SAFE_FREE(acl_entry_link->entryp);
4632 + SAFE_FREE(acl_entry_link);
4637 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
4642 +#else /* No ACLs. */
4644 +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
4650 +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
4656 +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
4662 +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
4668 +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
4671 + return (SMB_ACL_T)NULL;
4674 +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
4677 + return (SMB_ACL_T)NULL;
4680 +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
4686 +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
4692 +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
4695 + return (permset & perm) ? 1 : 0;
4698 +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
4704 +int sys_acl_free_text(UNUSED(char *text))
4710 +SMB_ACL_T sys_acl_init(UNUSED(int count))
4716 +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
4722 +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
4728 +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
4734 +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
4740 +int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
4746 +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
4752 +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
4758 +int sys_acl_delete_def_file(UNUSED(const char *name))
4764 +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
4770 +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
4776 +#endif /* No ACLs. */
4778 +/************************************************************************
4779 + Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4781 +************************************************************************/
4783 +int no_acl_syscall_error(int err)
4785 +#if defined(ENOSYS)
4786 + if (err == ENOSYS) {
4790 +#if defined(ENOTSUP)
4791 + if (err == ENOTSUP) {
4797 --- old/lib/sysacls.h
4798 +++ new/lib/sysacls.h
4800 +#define SMB_MALLOC(cnt) new_array(char, cnt)
4801 +#define SMB_MALLOC_P(obj) new_array(obj, 1)
4802 +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4803 +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
4804 +#define slprintf snprintf
4806 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4807 +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4808 +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4809 +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4810 +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4811 +SMB_ACL_T sys_acl_get_fd(int fd);
4812 +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4813 +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4814 +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4815 +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4816 +SMB_ACL_T sys_acl_init(int count);
4817 +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4818 +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4819 +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4820 +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4821 +int sys_acl_valid(SMB_ACL_T theacl);
4822 +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4823 +int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4824 +int sys_acl_delete_def_file(const char *name);
4825 +int sys_acl_free_text(char *text);
4826 +int sys_acl_free_acl(SMB_ACL_T the_acl);
4827 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
4830 @@ -58,7 +58,7 @@ BEGIN {
4834 -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4835 +!/^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/ {
4841 @@ -45,6 +45,7 @@ int copy_dirlinks = 0;
4843 int preserve_links = 0;
4844 int preserve_hard_links = 0;
4845 +int preserve_acls = 0;
4846 int preserve_perms = 0;
4847 int preserve_executability = 0;
4848 int preserve_devices = 0;
4849 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
4850 char const *got_socketpair = "no ";
4851 char const *have_inplace = "no ";
4852 char const *hardlinks = "no ";
4853 + char const *acls = "no ";
4854 char const *links = "no ";
4855 char const *ipv6 = "no ";
4856 STRUCT_STAT *dumstat;
4857 @@ -210,6 +212,10 @@ static void print_rsync_version(enum log
4861 +#ifdef SUPPORT_ACLS
4865 #ifdef SUPPORT_LINKS
4868 @@ -223,9 +229,9 @@ static void print_rsync_version(enum log
4869 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
4870 rprintf(f, "<http://rsync.samba.org/>\n");
4871 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
4872 - "%shard links, %ssymlinks, batchfiles,\n",
4873 + "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
4874 (int) (sizeof (OFF_T) * 8),
4875 - got_socketpair, hardlinks, links);
4876 + got_socketpair, hardlinks, acls, links);
4878 /* Note that this field may not have type ino_t. It depends
4879 * on the complicated interaction between largefile feature
4880 @@ -295,6 +301,9 @@ void usage(enum logcode F)
4881 rprintf(F," -H, --hard-links preserve hard links\n");
4882 rprintf(F," -p, --perms preserve permissions\n");
4883 rprintf(F," -E, --executability preserve the file's executability\n");
4884 +#ifdef SUPPORT_ACLS
4885 + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
4887 rprintf(F," --chmod=CHMOD change destination permissions\n");
4888 rprintf(F," -o, --owner preserve owner (super-user only)\n");
4889 rprintf(F," -g, --group preserve group\n");
4890 @@ -410,6 +419,9 @@ static struct poptOption long_options[]
4891 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4892 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4893 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
4894 + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4895 + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4896 + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4897 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4898 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4899 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4900 @@ -1068,6 +1080,23 @@ int parse_arguments(int *argc, const cha
4905 +#ifdef SUPPORT_ACLS
4906 + preserve_acls = preserve_perms = 1;
4909 + /* FIXME: this should probably be ignored with a
4910 + * warning and then countermeasures taken to
4911 + * restrict group and other access in the presence
4912 + * of any more restrictive ACLs, but this is safe
4914 + snprintf(err_buf,sizeof(err_buf),
4915 + "ACLs are not supported on this %s\n",
4916 + am_server ? "server" : "client");
4922 /* A large opt value means that set_refuse_options()
4923 * turned this option off. */
4924 @@ -1511,6 +1540,10 @@ void server_options(char **args,int *arg
4926 if (preserve_hard_links)
4928 +#ifdef SUPPORT_ACLS
4929 + if (preserve_acls)
4930 + argstr[x++] = 'A';
4937 @@ -46,6 +46,7 @@ extern int keep_partial;
4938 extern int checksum_seed;
4940 extern int delay_updates;
4941 +extern mode_t orig_umask;
4942 extern struct stats stats;
4943 extern char *log_format;
4944 extern char *tmpdir;
4945 @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
4946 int itemizing = am_daemon ? daemon_log_format_has_i
4947 : !am_server && log_format_has_i;
4948 int max_phase = protocol_version >= 29 ? 2 : 1;
4949 + int dflt_perms = (ACCESSPERMS & ~orig_umask);
4950 +#ifdef SUPPORT_ACLS
4951 + char *parent_dirname = "";
4956 @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
4957 * mode based on the local permissions and some heuristics. */
4958 if (!preserve_perms) {
4959 int exists = fd1 != -1;
4960 - file->mode = dest_mode(file->mode, st.st_mode, exists);
4961 +#ifdef SUPPORT_ACLS
4962 + char *dn = file->dirname ? file->dirname : ".";
4963 + if (parent_dirname != dn
4964 + && strcmp(parent_dirname, dn) != 0) {
4965 + dflt_perms = default_perms_for_dir(dn);
4966 + parent_dirname = dn;
4969 + file->mode = dest_mode(file->mode, st.st_mode,
4970 + dflt_perms, exists);
4973 /* We now check to see if we are writing file "inplace" */
4979 extern int daemon_log_format_has_i;
4980 +extern int preserve_acls;
4981 extern int preserve_perms;
4982 extern int preserve_executability;
4983 extern int preserve_times;
4984 @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s)
4986 /* This is only called when we aren't preserving permissions. Figure out what
4987 * the permissions should be and return them merged back into the mode. */
4988 -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4989 +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
4992 /* If the file already exists, we'll return the local permissions,
4993 * possibly tweaked by the --executability option. */
4994 @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode
4995 cur_mode |= (cur_mode & 0444) >> 2;
4998 - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
4999 + cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
5000 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
5001 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
5002 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
5003 @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
5007 +#ifdef SUPPORT_ACLS
5008 + /* It's OK to call set_acl() now, even for a dir, as the generator
5009 + * will enable owner-writability using chmod, if necessary.
5011 + * If set_acl changes permission bits in the process of setting
5012 + * an access ACL, it changes st->st_mode so we know whether we
5013 + * need to chmod. */
5014 + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
5019 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
5020 - int ret = do_chmod(fname, file->mode);
5021 + mode_t mode = file->mode;
5022 + int ret = do_chmod(fname, mode);
5024 rsyserr(FERROR, errno,
5025 "failed to set permissions on %s",
5028 @@ -658,6 +658,20 @@ struct chmod_mode_struct;
5030 #define UNUSED(x) x __attribute__((__unused__))
5032 +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
5033 + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
5034 +#define SUPPORT_ACLS 1
5037 +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
5038 +#define ACLS_NEED_MASK 1
5041 +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
5042 +#include <sys/acl.h>
5044 +#include "smb_acls.h"
5048 /* We have replacement versions of these if they're missing. */
5051 @@ -321,6 +321,7 @@ to the detailed description below for a
5052 -H, --hard-links preserve hard links
5053 -p, --perms preserve permissions
5054 -E, --executability preserve executability
5055 + -A, --acls preserve ACLs (implies -p) [non-standard]
5056 --chmod=CHMOD change destination permissions
5057 -o, --owner preserve owner (super-user only)
5058 -g, --group preserve group
5059 @@ -742,7 +743,9 @@ quote(itemize(
5060 permissions, though the bf(--executability) option might change just
5061 the execute permission for the file.
5062 it() New files get their "normal" permission bits set to the source
5063 - file's permissions masked with the receiving end's umask setting, and
5064 + file's permissions masked with the receiving directory's default
5065 + permissions (either the receiving process's umask, or the permissions
5066 + specified via the destination directory's default ACL), and
5067 their special permission bits disabled except in the case where a new
5068 directory inherits a setgid bit from its parent directory.
5070 @@ -773,9 +776,11 @@ The preservation of the destination's se
5071 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
5072 versions erroneously preserved the three special permission bits for
5073 newly-created files when bf(--perms) was off, while overriding the
5074 -destination's setgid bit setting on a newly-created directory. (Keep in
5075 -mind that it is the version of the receiving rsync that affects this
5077 +destination's setgid bit setting on a newly-created directory. Default ACL
5078 +observance was added to the ACL patch for rsync 2.6.7, so older (or
5079 +non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
5080 +(Keep in mind that it is the version of the receiving rsync that affects
5083 dit(bf(-E, --executability)) This option causes rsync to preserve the
5084 executability (or non-executability) of regular files when bf(--perms) is
5085 @@ -793,6 +798,10 @@ quote(itemize(
5087 If bf(--perms) is enabled, this option is ignored.
5089 +dit(bf(-A, --acls)) This option causes rsync to update the destination
5090 +ACLs to be the same as the source ACLs. This nonstandard option only
5091 +works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5093 dit(bf(--chmod)) This option tells rsync to apply one or more
5094 comma-separated "chmod" strings to the permission of the files in the
5095 transfer. The resulting value is treated as though it was the permissions
5100 + Unix SMB/Netbios implementation.
5102 + Portable SMB ACL interface
5103 + Copyright (C) Jeremy Allison 2000
5105 + This program is free software; you can redistribute it and/or modify
5106 + it under the terms of the GNU General Public License as published by
5107 + the Free Software Foundation; either version 2 of the License, or
5108 + (at your option) any later version.
5110 + This program is distributed in the hope that it will be useful,
5111 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5112 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5113 + GNU General Public License for more details.
5115 + You should have received a copy of the GNU General Public License
5116 + along with this program; if not, write to the Free Software
5117 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5120 +#ifndef _SMB_ACLS_H
5121 +#define _SMB_ACLS_H
5123 +#if defined HAVE_POSIX_ACLS
5125 +/* This is an identity mapping (just remove the SMB_). */
5127 +#define SMB_ACL_TAG_T acl_tag_t
5128 +#define SMB_ACL_TYPE_T acl_type_t
5129 +#define SMB_ACL_PERMSET_T acl_permset_t
5130 +#define SMB_ACL_PERM_T acl_perm_t
5131 +#define SMB_ACL_READ ACL_READ
5132 +#define SMB_ACL_WRITE ACL_WRITE
5133 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5135 +/* Types of ACLs. */
5136 +#define SMB_ACL_USER ACL_USER
5137 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5138 +#define SMB_ACL_GROUP ACL_GROUP
5139 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5140 +#define SMB_ACL_OTHER ACL_OTHER
5141 +#define SMB_ACL_MASK ACL_MASK
5143 +#define SMB_ACL_T acl_t
5145 +#define SMB_ACL_ENTRY_T acl_entry_t
5147 +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5148 +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5150 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5151 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5153 +#elif defined HAVE_TRU64_ACLS
5155 +/* This is for DEC/Compaq Tru64 UNIX */
5157 +#define SMB_ACL_TAG_T acl_tag_t
5158 +#define SMB_ACL_TYPE_T acl_type_t
5159 +#define SMB_ACL_PERMSET_T acl_permset_t
5160 +#define SMB_ACL_PERM_T acl_perm_t
5161 +#define SMB_ACL_READ ACL_READ
5162 +#define SMB_ACL_WRITE ACL_WRITE
5163 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5165 +/* Types of ACLs. */
5166 +#define SMB_ACL_USER ACL_USER
5167 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5168 +#define SMB_ACL_GROUP ACL_GROUP
5169 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5170 +#define SMB_ACL_OTHER ACL_OTHER
5171 +#define SMB_ACL_MASK ACL_MASK
5173 +#define SMB_ACL_T acl_t
5175 +#define SMB_ACL_ENTRY_T acl_entry_t
5177 +#define SMB_ACL_FIRST_ENTRY 0
5178 +#define SMB_ACL_NEXT_ENTRY 1
5180 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5181 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5183 +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
5185 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5186 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5189 +/* SVR4.2 ES/MP ACLs */
5190 +typedef int SMB_ACL_TAG_T;
5191 +typedef int SMB_ACL_TYPE_T;
5192 +typedef ushort *SMB_ACL_PERMSET_T;
5193 +typedef ushort SMB_ACL_PERM_T;
5194 +#define SMB_ACL_READ 4
5195 +#define SMB_ACL_WRITE 2
5196 +#define SMB_ACL_EXECUTE 1
5198 +/* Types of ACLs. */
5199 +#define SMB_ACL_USER USER
5200 +#define SMB_ACL_USER_OBJ USER_OBJ
5201 +#define SMB_ACL_GROUP GROUP
5202 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5203 +#define SMB_ACL_OTHER OTHER_OBJ
5204 +#define SMB_ACL_MASK CLASS_OBJ
5206 +typedef struct SMB_ACL_T {
5210 + struct acl acl[1];
5213 +typedef struct acl *SMB_ACL_ENTRY_T;
5215 +#define SMB_ACL_FIRST_ENTRY 0
5216 +#define SMB_ACL_NEXT_ENTRY 1
5218 +#define SMB_ACL_TYPE_ACCESS 0
5219 +#define SMB_ACL_TYPE_DEFAULT 1
5222 +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS
5225 +#elif defined HAVE_HPUX_ACLS
5228 + * Based on the Solaris & UnixWare code.
5232 +#include <sys/aclv.h>
5234 +/* SVR4.2 ES/MP ACLs */
5235 +typedef int SMB_ACL_TAG_T;
5236 +typedef int SMB_ACL_TYPE_T;
5237 +typedef ushort *SMB_ACL_PERMSET_T;
5238 +typedef ushort SMB_ACL_PERM_T;
5239 +#define SMB_ACL_READ 4
5240 +#define SMB_ACL_WRITE 2
5241 +#define SMB_ACL_EXECUTE 1
5243 +/* Types of ACLs. */
5244 +#define SMB_ACL_USER USER
5245 +#define SMB_ACL_USER_OBJ USER_OBJ
5246 +#define SMB_ACL_GROUP GROUP
5247 +#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5248 +#define SMB_ACL_OTHER OTHER_OBJ
5249 +#define SMB_ACL_MASK CLASS_OBJ
5251 +typedef struct SMB_ACL_T {
5255 + struct acl acl[1];
5258 +typedef struct acl *SMB_ACL_ENTRY_T;
5260 +#define SMB_ACL_FIRST_ENTRY 0
5261 +#define SMB_ACL_NEXT_ENTRY 1
5263 +#define SMB_ACL_TYPE_ACCESS 0
5264 +#define SMB_ACL_TYPE_DEFAULT 1
5266 +#elif defined HAVE_IRIX_ACLS
5268 +#define SMB_ACL_TAG_T acl_tag_t
5269 +#define SMB_ACL_TYPE_T acl_type_t
5270 +#define SMB_ACL_PERMSET_T acl_permset_t
5271 +#define SMB_ACL_PERM_T acl_perm_t
5272 +#define SMB_ACL_READ ACL_READ
5273 +#define SMB_ACL_WRITE ACL_WRITE
5274 +#define SMB_ACL_EXECUTE ACL_EXECUTE
5276 +/* Types of ACLs. */
5277 +#define SMB_ACL_USER ACL_USER
5278 +#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5279 +#define SMB_ACL_GROUP ACL_GROUP
5280 +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5281 +#define SMB_ACL_OTHER ACL_OTHER_OBJ
5282 +#define SMB_ACL_MASK ACL_MASK
5284 +typedef struct SMB_ACL_T {
5290 +#define SMB_ACL_ENTRY_T acl_entry_t
5292 +#define SMB_ACL_FIRST_ENTRY 0
5293 +#define SMB_ACL_NEXT_ENTRY 1
5295 +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5296 +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5298 +#elif defined HAVE_AIX_ACLS
5300 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5302 +#include "/usr/include/acl.h"
5304 +typedef uint *SMB_ACL_PERMSET_T;
5306 +struct acl_entry_link{
5307 + struct acl_entry_link *prevp;
5308 + struct new_acl_entry *entryp;
5309 + struct acl_entry_link *nextp;
5313 +struct new_acl_entry{
5314 + unsigned short ace_len;
5315 + unsigned short ace_type;
5316 + unsigned int ace_access;
5317 + struct ace_id ace_id[1];
5320 +#define SMB_ACL_ENTRY_T struct new_acl_entry*
5321 +#define SMB_ACL_T struct acl_entry_link*
5323 +#define SMB_ACL_TAG_T unsigned short
5324 +#define SMB_ACL_TYPE_T int
5325 +#define SMB_ACL_PERM_T uint
5326 +#define SMB_ACL_READ S_IRUSR
5327 +#define SMB_ACL_WRITE S_IWUSR
5328 +#define SMB_ACL_EXECUTE S_IXUSR
5330 +/* Types of ACLs. */
5331 +#define SMB_ACL_USER ACEID_USER
5332 +#define SMB_ACL_USER_OBJ 3
5333 +#define SMB_ACL_GROUP ACEID_GROUP
5334 +#define SMB_ACL_GROUP_OBJ 4
5335 +#define SMB_ACL_OTHER 5
5336 +#define SMB_ACL_MASK 6
5339 +#define SMB_ACL_FIRST_ENTRY 1
5340 +#define SMB_ACL_NEXT_ENTRY 2
5342 +#define SMB_ACL_TYPE_ACCESS 0
5343 +#define SMB_ACL_TYPE_DEFAULT 1
5345 +#else /* No ACLs. */
5347 +/* No ACLS - fake it. */
5348 +#define SMB_ACL_TAG_T int
5349 +#define SMB_ACL_TYPE_T int
5350 +#define SMB_ACL_PERMSET_T mode_t
5351 +#define SMB_ACL_PERM_T mode_t
5352 +#define SMB_ACL_READ S_IRUSR
5353 +#define SMB_ACL_WRITE S_IWUSR
5354 +#define SMB_ACL_EXECUTE S_IXUSR
5356 +/* Types of ACLs. */
5357 +#define SMB_ACL_USER 0
5358 +#define SMB_ACL_USER_OBJ 1
5359 +#define SMB_ACL_GROUP 2
5360 +#define SMB_ACL_GROUP_OBJ 3
5361 +#define SMB_ACL_OTHER 4
5362 +#define SMB_ACL_MASK 5
5364 +typedef struct SMB_ACL_T {
5368 +typedef struct SMB_ACL_ENTRY_T {
5370 +} *SMB_ACL_ENTRY_T;
5372 +#define SMB_ACL_FIRST_ENTRY 0
5373 +#define SMB_ACL_NEXT_ENTRY 1
5375 +#define SMB_ACL_TYPE_ACCESS 0
5376 +#define SMB_ACL_TYPE_DEFAULT 1
5378 +#endif /* No ACLs. */
5379 +#endif /* _SMB_ACLS_H */
5380 --- old/testsuite/default-acls.test
5381 +++ new/testsuite/default-acls.test
5385 +# This program is distributable under the terms of the GNU GPL see
5388 +# Test that rsync obeys default ACLs. -- Matt McCutchen
5390 +. $srcdir/testsuite/rsync.fns
5392 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
5393 +case "$setfacl_nodef" in
5394 +*-k*) opts='-dm u::7,g::5,o:5' ;;
5395 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
5397 +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5399 +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
5401 + todir="$scratchdir/$1"
5403 + $setfacl_nodef "$todir"
5405 + case "$setfacl_nodef" in
5406 + *-k*) opts="-dm $2" ;;
5407 + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`"
5409 + setfacl $opts "$todir"
5411 + # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5412 + # even though the directory itself is outside the transfer
5413 + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
5414 + check_perms "$todir/to" $4 "Target $1"
5415 + check_perms "$todir/to/dir" $4 "Target $1"
5416 + check_perms "$todir/to/file" $3 "Target $1"
5417 + check_perms "$todir/to/program" $4 "Target $1"
5418 + # Make sure get_local_name doesn't mess us up when transferring only one file
5419 + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
5420 + check_perms "$todir/to/anotherfile" $3 "Target $1"
5421 + # Make sure we obey default ACLs when not transferring a regular file
5422 + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
5423 + check_perms "$todir/to/anotherdir" $4 "Target $1"
5426 +mkdir "$scratchdir/dir"
5427 +echo "File!" >"$scratchdir/file"
5428 +echo "#!/bin/sh" >"$scratchdir/program"
5429 +chmod 777 "$scratchdir/dir"
5430 +chmod 666 "$scratchdir/file"
5431 +chmod 777 "$scratchdir/program"
5433 +# Test some target directories
5435 +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx
5436 +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x
5437 +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x---
5438 +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx---
5439 +testit noda1 '' rw------- rwx------
5441 +testit noda2 '' rw-rw-rw- rwxrwxrwx
5443 +testit noda3 '' rw-r--r-- rwxr-xr-x
5451 extern int preserve_uid;
5452 extern int preserve_gid;
5453 +extern int preserve_acls;
5454 extern int numeric_ids;
5457 @@ -274,7 +275,7 @@ void send_uid_list(int f)
5461 - if (preserve_uid) {
5462 + if (preserve_uid || preserve_acls) {
5464 /* we send sequences of uid/byte-length/name */
5465 for (list = uidlist; list; list = list->next) {
5466 @@ -291,7 +292,7 @@ void send_uid_list(int f)
5470 - if (preserve_gid) {
5471 + if (preserve_gid || preserve_acls) {
5473 for (list = gidlist; list; list = list->next) {
5475 @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5479 - if (preserve_uid && !numeric_ids) {
5480 + if ((preserve_uid || preserve_acls) && !numeric_ids) {
5481 /* read the uid list */
5482 while ((id = read_int(f)) != 0) {
5483 int len = read_byte(f);
5484 @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5488 - if (preserve_gid && !numeric_ids) {
5489 + if ((preserve_gid || preserve_acls) && !numeric_ids) {
5490 /* read the gid list */
5491 while ((id = read_int(f)) != 0) {
5492 int len = read_byte(f);
5493 @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li
5497 +#ifdef SUPPORT_ACLS
5498 + if (preserve_acls && !numeric_ids) {
5500 + while ((id = next_acl_uid(flist)) != NULL)
5501 + *id = match_uid(*id);
5502 + while ((id = next_acl_gid(flist)) != NULL)
5503 + *id = match_gid(*id);
5507 /* Now convert all the uids/gids from sender values to our values. */
5508 if (am_root && preserve_uid && !numeric_ids) {
5509 for (i = 0; i < flist->count; i++)