See the --acls (-A) option in the revised man page for a note on using this
latest ACL-enabling patch to send files to an older ACL-enabled rsync.
-This code does not yet itemize changes in ACL information (see --itemize).
+TODO items:
+
+- The -i option does not yet itemize changes in ACL information.
+
+- The --link-dest option might link together two files that differ just
+ in their ACL info, and if that happens the file in the --link-dest dir
+ would get its ACLs updated.
--- old/Makefile.in
+++ new/Makefile.in
popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
--- old/acls.c
+++ new/acls.c
-@@ -0,0 +1,1264 @@
+@@ -0,0 +1,1293 @@
+/* -*- c-file-style: "linux" -*-
+ Copyright (C) Andrew Tridgell 1996
+ Copyright (C) Paul Mackerras 1996
+ id_access *idas;
+} ida_list;
+
-+#define NO_ENTRY ((uchar)0x80)
++#define ACL_NO_ENTRY ((uchar)0x80)
+typedef struct {
+ ida_list users;
+ ida_list groups;
-+ /* These will be NO_ENTRY if there's no such entry. */
++ /* These will be ACL_NO_ENTRY if there's no such entry. */
+ uchar user_obj;
+ uchar group_obj;
+ uchar mask;
+ uchar other;
+} rsync_acl;
+
-+static const rsync_acl rsync_acl_initializer =
-+ { {0, 0, NULL}, {0, 0, NULL}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY};
++static const rsync_acl rsync_acl_initializer = {
++ {0, 0, NULL}, {0, 0, NULL},
++ ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY, ACL_NO_ENTRY
++};
+
+#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
+#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
+
+/* a few useful calculations */
+
-+static int rsync_acl_count_entries(const rsync_acl *racl)
++static int count_racl_entries(const rsync_acl *racl)
+{
+ return racl->users.count + racl->groups.count
-+ + (racl->user_obj != NO_ENTRY)
-+ + (racl->group_obj != NO_ENTRY)
-+ + (racl->mask != NO_ENTRY)
-+ + (racl->other != NO_ENTRY);
++ + (racl->user_obj != ACL_NO_ENTRY)
++ + (racl->group_obj != ACL_NO_ENTRY)
++ + (racl->mask != ACL_NO_ENTRY)
++ + (racl->other != ACL_NO_ENTRY);
++}
++
++static int calc_sacl_entries(const rsync_acl *racl)
++{
++ return racl->users.count + racl->groups.count
++#ifdef ACLS_NEED_MASK
++ + 4;
++#else
++ + (racl->mask != ACL_NO_ENTRY) + 3;
++#endif
+}
+
+static int rsync_acl_get_perms(const rsync_acl *racl)
+{
-+ /* Note that (NO_ENTRY & 7) is 0. */
++ /* Note that (ACL_NO_ENTRY & 7) is 0. */
+ return ((racl->user_obj & 7) << 6)
-+ + (((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
++ + (((racl->mask != ACL_NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3)
+ + (racl->other & 7);
+}
+
+static void rsync_acl_strip_perms(rsync_acl *racl)
+{
-+ racl->user_obj = NO_ENTRY;
-+ if (racl->mask == NO_ENTRY)
-+ racl->group_obj = NO_ENTRY;
++ racl->user_obj = ACL_NO_ENTRY;
++ if (racl->mask == ACL_NO_ENTRY)
++ racl->group_obj = ACL_NO_ENTRY;
+ else
-+ racl->mask = NO_ENTRY;
-+ racl->other = NO_ENTRY;
++ racl->mask = ACL_NO_ENTRY;
++ racl->other = ACL_NO_ENTRY;
+}
+
+static void expand_ida_list(ida_list *idal)
+ /* continue == done with entry; break == store in given idal */
+ switch (tag_type) {
+ case SMB_ACL_USER_OBJ:
-+ if (racl->user_obj == NO_ENTRY)
++ if (racl->user_obj == ACL_NO_ENTRY)
+ racl->user_obj = access;
+ else
+ rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
+ idal = &racl->users;
+ break;
+ case SMB_ACL_GROUP_OBJ:
-+ if (racl->group_obj == NO_ENTRY)
++ if (racl->group_obj == ACL_NO_ENTRY)
+ racl->group_obj = access;
+ else
+ rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
+ idal = &racl->groups;
+ break;
+ case SMB_ACL_MASK:
-+ if (racl->mask == NO_ENTRY)
++ if (racl->mask == ACL_NO_ENTRY)
+ racl->mask = access;
+ else
+ rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
+ continue;
+ case SMB_ACL_OTHER:
-+ if (racl->other == NO_ENTRY)
++ if (racl->other == ACL_NO_ENTRY)
+ racl->other = access;
+ else
+ rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
+static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1, const rsync_acl *racl2)
+{
+ /* We ignore any differences that chmod() can take care of. */
-+ if ((racl1->mask ^ racl2->mask) & NO_ENTRY)
++ if ((racl1->mask ^ racl2->mask) & ACL_NO_ENTRY)
+ return False;
-+ if (racl1->mask != NO_ENTRY && racl1->group_obj != racl2->group_obj)
++ if (racl1->mask != ACL_NO_ENTRY && racl1->group_obj != racl2->group_obj)
+ return False;
+ return ida_lists_equal(&racl1->users, &racl2->users)
+ && ida_lists_equal(&racl1->groups, &racl2->groups);
+
+static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
+{
-+ return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
-+ : &_rsync_acl_lists[1];
++ return &_rsync_acl_lists[type != SMB_ACL_TYPE_ACCESS];
+}
+
+static void expand_rsync_acl_list(rsync_acl_list *racl_list)
+ const rsync_acl *racl)
+{
+ static int access_match = -1, default_match = -1;
-+ int *match = (type == SMB_ACL_TYPE_ACCESS) ?
-+ &access_match : &default_match;
++ int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
+ size_t count = racl_list->count;
++
+ /* If this is the first time through or we didn't match the last
+ * time, then start at the end of the list, which should be the
+ * best place to start hunting. */
+ if (!(*match)--)
+ *match = racl_list->count - 1;
+ }
++
+ *match = -1;
+ return *match;
+}
+
+static void send_rsync_acl(int f, const rsync_acl *racl)
+{
-+ size_t count = rsync_acl_count_entries(racl);
++ size_t count = count_racl_entries(racl);
+ write_int(f, count);
-+ if (racl->user_obj != NO_ENTRY) {
++ if (racl->user_obj != ACL_NO_ENTRY) {
+ write_byte(f, 'u');
+ write_byte(f, racl->user_obj);
+ }
+ send_ida_list(f, &racl->users, 'U');
-+ if (racl->group_obj != NO_ENTRY) {
++ if (racl->group_obj != ACL_NO_ENTRY) {
+ write_byte(f, 'g');
+ write_byte(f, racl->group_obj);
+ }
+ send_ida_list(f, &racl->groups, 'G');
-+ if (racl->mask != NO_ENTRY) {
++ if (racl->mask != ACL_NO_ENTRY) {
+ write_byte(f, 'm');
+ write_byte(f, racl->mask);
+ }
-+ if (racl->other != NO_ENTRY) {
++ if (racl->other != ACL_NO_ENTRY) {
+ write_byte(f, 'o');
+ write_byte(f, racl->other);
+ }
+
+static const char *str_acl_type(SMB_ACL_TYPE_T type)
+{
-+ return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
-+ type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
-+ "unknown SMB_ACL_TYPE_T";
++ return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
++ : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
++ : "unknown SMB_ACL_TYPE_T";
+}
+
+/* Generate the ACL(s) for this flist entry;
+ sys_acl_free_acl(sacl);
+ if (!ok)
+ return -1;
-+#ifdef ACLS_NEED_MASK
-+ /* Don't ever send a redundant mask value. */
-+ if (!racl->users.count && !racl->groups.count
-+ && racl->group == racl->mask)
-+ racl->mask = NO_ENTRY;
-+#endif
++ /* Avoid sending a redundant group/mask value. */
++ if (curr_racl->group_obj == curr_racl->mask
++ && (preserve_acls == 1
++ || (!curr_racl->users.count
++ && !curr_racl->groups.count)))
++ curr_racl->mask = ACL_NO_ENTRY;
+ /* Strip access ACLs of permission-bit entries. */
+ if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1)
+ rsync_acl_strip_perms(curr_racl);
+typedef struct {
+ size_t count;
+ size_t malloced;
-+ file_acl_index *fileaclidxs;
++ file_acl_index *fais;
+} file_acl_index_list;
+
+static file_acl_index_list _file_acl_index_lists[] = {
-+ {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
-+ {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
++ {0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
++ {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
+};
+
+static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
+{
-+ return type == SMB_ACL_TYPE_ACCESS ?
-+ &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
++ return &_file_acl_index_lists[type != SMB_ACL_TYPE_ACCESS];
+}
+
-+static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
++static void expand_file_acl_index_list(file_acl_index_list *flst)
+{
+ /* First time through, 0 <= 0, so list is expanded. */
-+ if (fileaclidx_list->malloced <= fileaclidx_list->count) {
++ if (flst->malloced <= flst->count) {
+ file_acl_index *new_ptr;
+ size_t new_size;
-+ if (fileaclidx_list->malloced < 1000)
-+ new_size = fileaclidx_list->malloced + 1000;
++
++ if (flst->malloced < 1000)
++ new_size = flst->malloced + 1000;
+ else
-+ new_size = fileaclidx_list->malloced * 2;
-+ new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
++ new_size = flst->malloced * 2;
++ new_ptr = realloc_array(flst->fais, file_acl_index, new_size);
+ if (verbose >= 3) {
+ rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
-+ (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
-+ fileaclidx_list->fileaclidxs ? "" : " not");
++ (double) new_size * sizeof flst->fais[0],
++ flst->fais ? "" : " not");
+ }
+
-+ fileaclidx_list->fileaclidxs = new_ptr;
-+ fileaclidx_list->malloced = new_size;
++ flst->fais = new_ptr;
++ flst->malloced = new_size;
+
-+ if (!fileaclidx_list->fileaclidxs)
++ if (!flst->fais)
+ out_of_memory("expand_file_acl_index_list");
+ }
+}
+
+static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
+{
-+ return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
-+ &_smb_acl_lists[1];
++ return &_smb_acl_lists[type != SMB_ACL_TYPE_ACCESS];
+}
+
+static void expand_smb_acl_list(smb_acl_list *sacl_list)
+ const char *errfun = NULL;
+ SMB_ACL_ENTRY_T entry;
+
-+ if (!(*smb_acl = sys_acl_init(rsync_acl_count_entries(racl)))) {
++ if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
+ rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n",
+ strerror(errno));
+ return False;
+
+ COE( sys_acl_create_entry,(smb_acl, &entry) );
+ COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) );
-+ COE2( store_access_in_entry,(racl->user_obj, entry) );
++ COE2( store_access_in_entry,(racl->user_obj & 7, entry) );
+
+ for (ida = racl->users.idas, count = racl->users.count;
+ count--; ida++) {
+
+ COE( sys_acl_create_entry,(smb_acl, &entry) );
+ COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) );
-+ COE2( store_access_in_entry,(racl->group_obj, entry) );
++ COE2( store_access_in_entry,(racl->group_obj & 7, entry) );
+
+ for (ida = racl->groups.idas, count = racl->groups.count;
+ count--; ida++) {
+ COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) );
+ COE2( store_access_in_entry,(ida->access, entry) );
+ }
-+ if (racl->mask != NO_ENTRY) {
++#ifndef ACLS_NEED_MASK
++ if (racl->mask != ACL_NO_ENTRY) {
++#endif
+ COE( sys_acl_create_entry,(smb_acl, &entry) );
+ COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) );
+ COE2( store_access_in_entry,(racl->mask, entry) );
++#ifndef ACLS_NEED_MASK
+ }
++#endif
+
+ COE( sys_acl_create_entry,(smb_acl, &entry) );
+ COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) );
-+ COE2( store_access_in_entry,(racl->other, entry) );
++ COE2( store_access_in_entry,(racl->other & 7, entry) );
+
+#ifdef DEBUG
+ if (sys_acl_valid(*smb_acl) < 0)
+ return False;
+}
+
-+static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode)
++static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
+{
+ SMB_ACL_ENTRY_T entry;
-+ int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ;
+ const char *errfun;
+ int rc;
+
+ errfun = "sys_acl_get_tag_type";
+ break;
+ }
-+ if (tag_type == SMB_ACL_USER_OBJ)
++ switch (tag_type) {
++ case SMB_ACL_USER_OBJ:
+ COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
-+ else if (tag_type == group_id)
++ break;
++ case SMB_ACL_GROUP_OBJ:
++ /* group is only empty when identical to group perms. */
++ if (racl->group_obj != ACL_NO_ENTRY)
++ break;
++ COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
++ break;
++ case SMB_ACL_MASK:
++#ifndef ACLS_NEED_MASK
++ /* mask is only empty when we don't need it. */
++ if (racl->mask == ACL_NO_ENTRY)
++ break;
++#endif
+ COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
-+ else if (tag_type == SMB_ACL_OTHER)
++ break;
++ case SMB_ACL_OTHER:
+ COE2( store_access_in_entry,(mode & 7, entry) );
++ break;
++ }
+ }
+ if (rc) {
+ error_exit:
+ return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
+}
+
-+static void receive_rsync_acl(rsync_acl *racl, int f)
++static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type)
+{
+ uchar computed_mask_bits = 0;
+ ida_list *idal = NULL;
+ }
+ switch (tag) {
+ case 'u':
-+ if (racl->user_obj != NO_ENTRY) {
++ if (racl->user_obj != ACL_NO_ENTRY) {
+ rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n");
+ exit_cleanup(RERR_STREAMIO);
+ }
+ idal = &racl->users;
+ break;
+ case 'g':
-+ if (racl->group_obj != NO_ENTRY) {
++ if (racl->group_obj != ACL_NO_ENTRY) {
+ rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n");
+ exit_cleanup(RERR_STREAMIO);
+ }
+ idal = &racl->groups;
+ break;
+ case 'm':
-+ if (racl->mask != NO_ENTRY) {
++ if (racl->mask != ACL_NO_ENTRY) {
+ rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n");
+ exit_cleanup(RERR_STREAMIO);
+ }
+ racl->mask = access;
+ continue;
+ case 'o':
-+ if (racl->other != NO_ENTRY) {
++ if (racl->other != ACL_NO_ENTRY) {
+ rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n");
+ exit_cleanup(RERR_STREAMIO);
+ }
+ computed_mask_bits |= access;
+ }
+
-+ /* Ensure that these are never unset. */
-+ if (racl->user_obj == NO_ENTRY)
-+ racl->user_obj = 7;
-+ if (racl->group_obj == NO_ENTRY)
-+ racl->group_obj = 0;
-+ if (racl->other == NO_ENTRY)
-+ racl->other = 0;
++ if (type == SMB_ACL_TYPE_DEFAULT) {
++ /* Ensure that these are never unset. */
++ if (racl->user_obj == ACL_NO_ENTRY)
++ racl->user_obj = 7;
++ if (racl->group_obj == ACL_NO_ENTRY)
++ racl->group_obj = 0;
++ if (racl->other == ACL_NO_ENTRY)
++ racl->other = 0;
++ }
+#ifndef ACLS_NEED_MASK
+ if (!racl->users.count && !racl->groups.count) {
+ /* If we, a system without ACLS_NEED_MASK, received a
+ * superfluous mask, throw it away. */
-+ if (racl->mask != NO_ENTRY) {
++ if (racl->mask != ACL_NO_ENTRY) {
+ /* mask off group perms with it first */
-+ racl->group_obj &= racl->mask;
-+ racl->mask = NO_ENTRY;
++ racl->group_obj &= racl->mask | ACL_NO_ENTRY;
++ racl->mask = ACL_NO_ENTRY;
+ }
+ } else
+#endif
-+ if (racl->mask == NO_ENTRY)
-+ racl->mask = computed_mask_bits | racl->group_obj;
++ if (racl->mask == ACL_NO_ENTRY) /* Always non-empty when needed. */
++ racl->mask = computed_mask_bits | (racl->group_obj & 7);
+}
+
+/* receive and build the rsync_acl_lists */
+ fname = f_name(file, NULL);
+ type = SMB_ACL_TYPE_ACCESS;
+ do {
-+ file_acl_index_list *fileaclidx_list =
-+ file_acl_index_lists(type);
+ char tag;
-+ expand_file_acl_index_list(fileaclidx_list);
++ file_acl_index_list *flst = file_acl_index_lists(type);
++
++ expand_file_acl_index_list(flst);
+
+ tag = read_byte(f);
+ if (tag == 'A' || tag == 'a') {
+ rsync_acl racl;
+ rsync_acl_list *racl_list = rsync_acl_lists(type);
+ smb_acl_list *sacl_list = smb_acl_lists(type);
-+ fileaclidx_list->fileaclidxs[fileaclidx_list->count].
-+ aclidx = racl_list->count;
-+ fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
-+ file = file;
-+ receive_rsync_acl(&racl, f);
++ flst->fais[flst->count].aclidx = racl_list->count;
++ flst->fais[flst->count++].file = file;
++ receive_rsync_acl(&racl, f, type);
+ expand_rsync_acl_list(racl_list);
+ racl_list->racls[racl_list->count++] = racl;
+ expand_smb_acl_list(sacl_list);
+ index);
+ exit_cleanup(RERR_STREAMIO);
+ }
-+ fileaclidx_list->fileaclidxs[fileaclidx_list->count].
-+ aclidx = index;
-+ fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
-+ file = file;
++ flst->fais[flst->count].aclidx = index;
++ flst->fais[flst->count++].file = file;
+ }
+ } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
+}
+{
+ const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
+ const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
-+ return fileaclidx1->file == fileaclidx2->file ? 0 :
-+ fileaclidx1->file < fileaclidx2->file ? -1 : 1;
++ return fileaclidx1->file == fileaclidx2->file ? 0
++ : fileaclidx1->file < fileaclidx2->file ? -1 : 1;
+}
+
+void sort_file_acl_index_lists()
+
+ type = SMB_ACL_TYPE_ACCESS;
+ do {
-+ file_acl_index_list *fileaclidx_list =
-+ file_acl_index_lists(type);
-+ if (!fileaclidx_list->count)
++ file_acl_index_list *flst = file_acl_index_lists(type);
++
++ if (!flst->count)
+ continue;
-+ qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
-+ sizeof fileaclidx_list->fileaclidxs[0],
++
++ qsort(flst->fais, flst->count, sizeof flst->fais[0],
+ &file_acl_index_list_sorter);
+ } while (BUMP_TYPE(type));
+}
+
-+static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
-+ const struct file_struct *file) {
-+ int low = 0, high = fileaclidx_list->count;
++static int find_file_acl_index(const file_acl_index_list *flst,
++ const struct file_struct *file)
++{
++ int low = 0, high = flst->count;
+ const struct file_struct *file_mid;
++
+ if (!high--)
+ return -1;
+ do {
+ int mid = (high + low) / 2;
-+ file_mid = fileaclidx_list->fileaclidxs[mid].file;
++ file_mid = flst->fais[mid].file;
+ if (file_mid == file)
-+ return fileaclidx_list->fileaclidxs[mid].aclidx;
++ return flst->fais[mid].aclidx;
+ if (file_mid > file)
+ high = mid - 1;
+ else
+ low = mid + 1;
+ } while (low < high);
+ if (low == high) {
-+ file_mid = fileaclidx_list->fileaclidxs[low].file;
++ file_mid = flst->fais[low].file;
+ if (file_mid == file)
-+ return fileaclidx_list->fileaclidxs[low].aclidx;
++ return flst->fais[low].aclidx;
+ }
+ rprintf(FERROR,
+ "find_file_acl_index: can't find entry for file in list\n");
+ ; /* presume they're unequal */
+ }
+ if (type == SMB_ACL_TYPE_DEFAULT
-+ && rsync_acl_count_entries(&racl_orig) == 0) {
++ && racl_orig.user_obj == ACL_NO_ENTRY) {
+ if (sys_acl_delete_def_file(bak) < 0) {
+ rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
+ bak, strerror(errno));
+ continue;
+ if (!dry_run && mode_p) {
+ if (type == SMB_ACL_TYPE_DEFAULT
-+ && rsync_acl_count_entries(racl_new) == 0) {
++ && racl_new->user_obj == ACL_NO_ENTRY) {
+ if (sys_acl_delete_def_file(fname) < 0) {
+ rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
+ fname, strerror(errno));
+ continue;
+ }
+ if (type == SMB_ACL_TYPE_ACCESS) {
-+ cur_mode = change_sacl_perms(*sacl_new, racl_new->mask,
++ cur_mode = change_sacl_perms(*sacl_new, racl_new,
+ cur_mode, file->mode);
+ if (cur_mode == ~0u)
+ continue;
+ * or it returns 0 if there are no more tag_type ids in the acl. */
+static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
+{
-+ const ida_list *idal = (tag_type == SMB_ACL_USER ?
-+ &racl->users : &racl->groups);
++ const ida_list *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
+ if (enum_ida_index < idal->count) {
+ id_access *ida = &idal->idas[enum_ida_index++];
+ return &ida->id;
+ }
+
+ /* Apply the permission-bit entries of the default ACL, if any. */
-+ if (rsync_acl_count_entries(&racl) > 0) {
++ if (racl.user_obj != ACL_NO_ENTRY) {
+ perms = rsync_acl_get_perms(&racl);
+ if (verbose > 2)
+ rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
dnl At the moment we don't test for a broken memcmp(), because all we
dnl need to do is test for equality, not comparison, and it seems that
dnl every platform has a memcmp that can do at least that.
-@@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
+@@ -738,6 +743,78 @@ AC_SUBST(OBJ_RESTORE)
AC_SUBST(CC_SHOBJ_FLAG)
AC_SUBST(BUILD_POPT)
+#include <sys/acl.h>],
+[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
+samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
++ AC_MSG_CHECKING(ACL test results)
+ if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
+ AC_MSG_RESULT(Using posix ACLs)
+ AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
int preserve_perms = 0;
int preserve_executability = 0;
int preserve_devices = 0;
-@@ -194,6 +195,7 @@ static void print_rsync_version(enum log
+@@ -192,6 +193,7 @@ static void print_rsync_version(enum log
char const *got_socketpair = "no ";
char const *have_inplace = "no ";
char const *hardlinks = "no ";
char const *links = "no ";
char const *ipv6 = "no ";
STRUCT_STAT *dumstat;
-@@ -210,6 +212,10 @@ static void print_rsync_version(enum log
+@@ -208,6 +210,10 @@ static void print_rsync_version(enum log
hardlinks = "";
#endif
#ifdef SUPPORT_LINKS
links = "";
#endif
-@@ -223,9 +229,9 @@ static void print_rsync_version(enum log
+@@ -221,9 +227,9 @@ static void print_rsync_version(enum log
rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
rprintf(f, "<http://rsync.samba.org/>\n");
rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
/* Note that this field may not have type ino_t. It depends
* on the complicated interaction between largefile feature
-@@ -295,6 +301,9 @@ void usage(enum logcode F)
+@@ -293,6 +299,9 @@ void usage(enum logcode F)
rprintf(F," -H, --hard-links preserve hard links\n");
rprintf(F," -p, --perms preserve permissions\n");
rprintf(F," -E, --executability preserve the file's executability\n");
rprintf(F," --chmod=CHMOD change destination permissions\n");
rprintf(F," -o, --owner preserve owner (super-user only)\n");
rprintf(F," -g, --group preserve group\n");
-@@ -410,6 +419,9 @@ static struct poptOption long_options[]
+@@ -408,6 +417,9 @@ static struct poptOption long_options[]
{"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
{"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
{"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
{"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
{"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
-@@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
+@@ -1066,6 +1078,24 @@ int parse_arguments(int *argc, const cha
usage(FINFO);
exit_cleanup(0);
default:
/* A large opt value means that set_refuse_options()
* turned this option off. */
-@@ -1511,6 +1541,10 @@ void server_options(char **args,int *arg
+@@ -1508,6 +1538,10 @@ void server_options(char **args,int *arg
if (preserve_hard_links)
argstr[x++] = 'H';
if (daemon_chmod_modes && !S_ISLNK(flist_mode))
cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
-@@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
+@@ -203,6 +205,17 @@ int set_file_attrs(char *fname, struct f
updated = 1;
}
+
#ifdef HAVE_CHMOD
if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
-- int ret = do_chmod(fname, file->mode);
-+ mode_t mode = file->mode;
-+ int ret = do_chmod(fname, mode);
- if (ret < 0) {
- rsyserr(FERROR, errno,
- "failed to set permissions on %s",
+ int ret = do_chmod(fname, file->mode);
--- old/rsync.h
+++ new/rsync.h
-@@ -660,6 +660,20 @@ struct chmod_mode_struct;
+@@ -661,6 +661,20 @@ struct chmod_mode_struct;
#define UNUSED(x) x __attribute__((__unused__))
+
+#endif /* No ACLs. */
+#endif /* _SMB_ACLS_H */
+--- old/testsuite/acls.test
++++ new/testsuite/acls.test
+@@ -0,0 +1,34 @@
++#! /bin/sh
++
++# This program is distributable under the terms of the GNU GPL (see
++# COPYING).
++
++# Test that rsync handles basic ACL preservation.
++
++. $srcdir/testsuite/rsync.fns
++
++$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
++case "$setfacl_nodef" in
++true) test_skipped "I don't know how to use your setfacl command" ;;
++esac
++
++makepath "$fromdir/foo"
++echo something >"$fromdir/file1"
++echo else >"$fromdir/file2"
++
++files='foo file1 file2'
++
++setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
++setfacl -m u:0:5 "$fromdir/file1"
++setfacl -m u:0:5 "$fromdir/file2"
++
++$RSYNC -avvA "$fromdir/" "$todir/"
++
++cd "$fromdir"
++getfacl $files >"$scratchdir/acls.txt"
++
++cd "$todir"
++getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
++
++# The script would have aborted on error, so getting here means we've won.
++exit 0
--- old/testsuite/default-acls.test
+++ new/testsuite/default-acls.test
-@@ -0,0 +1,64 @@
+@@ -0,0 +1,65 @@
+#! /bin/sh
+
-+# This program is distributable under the terms of the GNU GPL see
++# This program is distributable under the terms of the GNU GPL (see
+# COPYING).
+
+# Test that rsync obeys default ACLs. -- Matt McCutchen
+
+$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
+case "$setfacl_nodef" in
++true) test_skipped "I don't know how to use your setfacl command" ;;
+*-k*) opts='-dm u::7,g::5,o:5' ;;
+*) opts='-m d:u::7,d:g::5,d:o:5' ;;
+esac