1 This patch adds backward-compatibility support for the --acls option.
2 Since the main release has never had ACL support, the trunk doesn't
3 need this code. If you want to make rsync 3.0.x communicate with an
4 older (patched) release, use this.
6 To use this patch, run these commands for a successful build:
8 patch -p1 <patches/acls.diff
9 ./configure (optional if already run)
14 @@ -98,6 +98,18 @@ static const char *str_acl_type(SMB_ACL_
15 : "unknown SMB_ACL_TYPE_T";
18 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
19 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
21 +static int old_count_racl_entries(const rsync_acl *racl)
23 + return racl->names.count
24 + + (racl->user_obj != NO_ENTRY)
25 + + (racl->group_obj != NO_ENTRY)
26 + + (racl->mask_obj != NO_ENTRY)
27 + + (racl->other_obj != NO_ENTRY);
30 static int calc_sacl_entries(const rsync_acl *racl)
32 /* A System ACL always gets user/group/other permission entries. */
33 @@ -522,6 +534,96 @@ int get_acl(const char *fname, statx *sx
37 +/* === OLD Send functions === */
39 +/* Send the ida list over the file descriptor. */
40 +static void old_send_ida_entries(int f, const ida_entries *idal, char tag_char)
43 + size_t count = idal->count;
44 + for (ida = idal->idas; count--; ida++) {
45 + if (tag_char == 'U') {
46 + if (!(ida->access & NAME_IS_USER))
50 + if (ida->access & NAME_IS_USER)
54 + write_byte(f, tag_char);
55 + write_byte(f, ida->access);
56 + write_int(f, ida->id);
60 +/* Send an rsync ACL over the file descriptor. */
61 +static void old_send_rsync_acl(int f, const rsync_acl *racl)
63 + size_t count = old_count_racl_entries(racl);
64 + write_int(f, count);
65 + if (racl->user_obj != NO_ENTRY) {
67 + write_byte(f, racl->user_obj);
69 + old_send_ida_entries(f, &racl->names, 'U');
70 + if (racl->group_obj != NO_ENTRY) {
72 + write_byte(f, racl->group_obj);
74 + old_send_ida_entries(f, &racl->names, 'G');
75 + if (racl->mask_obj != NO_ENTRY) {
77 + write_byte(f, racl->mask_obj);
79 + if (racl->other_obj != NO_ENTRY) {
81 + write_byte(f, racl->other_obj);
85 +/* Send the ACL from the statx structure down the indicated file descriptor.
86 + * This also frees the ACL data. */
87 +void old_send_acl(statx *sxp, int f)
89 + SMB_ACL_TYPE_T type;
90 + rsync_acl *racl, *new_racl;
91 + item_list *racl_list;
94 + type = SMB_ACL_TYPE_ACCESS;
95 + racl = sxp->acc_acl;
96 + racl_list = &access_acl_list;
99 + racl = new(rsync_acl);
101 + out_of_memory("send_acl");
102 + *racl = empty_rsync_acl;
103 + if (type == SMB_ACL_TYPE_ACCESS) {
104 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
105 + sxp->acc_acl = racl;
107 + sxp->def_acl = racl;
110 + if ((ndx = find_matching_rsync_acl(racl, type, racl_list)) != -1) {
111 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
114 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
115 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
116 + old_send_rsync_acl(f, racl);
118 + *racl = empty_rsync_acl;
120 + racl = sxp->def_acl;
121 + racl_list = &default_acl_list;
122 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
127 /* === Send functions === */
129 /* The general strategy with the tag_type <-> character mapping is that
130 @@ -604,6 +706,11 @@ static void send_rsync_acl(rsync_acl *ra
131 * This also frees the ACL data. */
132 void send_acl(statx *sxp, int f)
134 + if (protocol_version < 30) {
135 + old_send_acl(sxp, f);
140 sxp->acc_acl = create_racl();
141 rsync_acl_fake_perms(sxp->acc_acl, sxp->st.st_mode);
142 @@ -621,6 +728,160 @@ void send_acl(statx *sxp, int f)
146 +/* === OLD Receive functions */
148 +static void old_recv_rsync_acl(rsync_acl *racl, int f)
150 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
151 + SMB_ACL_TAG_T tag_type = 0;
152 + uchar computed_mask_bits = 0;
156 + if (!(count = read_int(f)))
160 + char tag = read_byte(f);
161 + uchar access = read_byte(f);
162 + if (access & ~ (4 | 2 | 1)) {
163 + rprintf(FERROR, "old_recv_rsync_acl: bogus permset %o\n",
165 + exit_cleanup(RERR_STREAMIO);
169 + if (racl->user_obj != NO_ENTRY) {
170 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate USER_OBJ entry\n");
171 + exit_cleanup(RERR_STREAMIO);
173 + racl->user_obj = access;
176 + tag_type = SMB_ACL_USER;
179 + if (racl->group_obj != NO_ENTRY) {
180 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate GROUP_OBJ entry\n");
181 + exit_cleanup(RERR_STREAMIO);
183 + racl->group_obj = access;
186 + tag_type = SMB_ACL_GROUP;
189 + if (racl->mask_obj != NO_ENTRY) {
190 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate MASK entry\n");
191 + exit_cleanup(RERR_STREAMIO);
193 + racl->mask_obj = access;
196 + if (racl->other_obj != NO_ENTRY) {
197 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate OTHER entry\n");
198 + exit_cleanup(RERR_STREAMIO);
200 + racl->other_obj = access;
203 + rprintf(FERROR, "old_recv_rsync_acl: unknown tag %c\n",
205 + exit_cleanup(RERR_STREAMIO);
207 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
208 + ida->access = access | (tag_type == SMB_ACL_USER ? NAME_IS_USER : 0);
209 + ida->id = read_int(f);
210 + computed_mask_bits |= access;
213 + /* Transfer the count id_access items out of the temp_ida_list
214 + * into the names ida_entries list in racl. */
215 + if (temp_ida_list.count) {
216 +#ifdef SMB_ACL_NEED_SORT
217 + if (temp_ida_list.count > 1) {
218 + qsort(temp_ida_list.items, temp_ida_list.count,
219 + sizeof (id_access), id_access_sorter);
222 + if (!(racl->names.idas = new_array(id_access, temp_ida_list.count)))
223 + out_of_memory("unpack_smb_acl");
224 + memcpy(racl->names.idas, temp_ida_list.items,
225 + temp_ida_list.count * sizeof (id_access));
227 + racl->names.idas = NULL;
229 + racl->names.count = temp_ida_list.count;
231 + /* Truncate the temporary list now that its idas have been saved. */
232 + temp_ida_list.count = 0;
234 + if (!racl->names.count) {
235 + /* If we received a superfluous mask, throw it away. */
236 + if (racl->mask_obj != NO_ENTRY) {
237 + /* Mask off the group perms with it first. */
238 + racl->group_obj &= racl->mask_obj | NO_ENTRY;
239 + racl->mask_obj = NO_ENTRY;
241 + } else if (racl->mask_obj == NO_ENTRY) /* Must be non-empty with lists. */
242 + racl->mask_obj = (computed_mask_bits | racl->group_obj) & 7;
245 +/* Receive the ACL info the sender has included for this file-list entry. */
246 +void old_recv_acl(struct file_struct *file, int f)
248 + SMB_ACL_TYPE_T type;
249 + item_list *racl_list;
251 + if (S_ISLNK(file->mode))
254 + type = SMB_ACL_TYPE_ACCESS;
255 + racl_list = &access_acl_list;
257 + char tag = read_byte(f);
260 + if (tag == 'A' || tag == 'a') {
261 + if (type != SMB_ACL_TYPE_ACCESS) {
262 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
263 + f_name(file, NULL));
264 + exit_cleanup(RERR_STREAMIO);
266 + } else if (tag == 'D' || tag == 'd') {
267 + if (type == SMB_ACL_TYPE_ACCESS) {
268 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
269 + f_name(file, NULL));
270 + exit_cleanup(RERR_STREAMIO);
273 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
274 + f_name(file, NULL), tag);
275 + exit_cleanup(RERR_STREAMIO);
277 + if (tag == 'A' || tag == 'D') {
279 + ndx = racl_list->count;
280 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
281 + duo_item->racl = empty_rsync_acl;
282 + old_recv_rsync_acl(&duo_item->racl, f);
283 + duo_item->sacl = NULL;
286 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
287 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
288 + f_name(file, NULL), str_acl_type(type), ndx);
289 + exit_cleanup(RERR_STREAMIO);
292 + if (type == SMB_ACL_TYPE_ACCESS)
295 + F_DIR_DEFACL(file) = ndx;
296 + racl_list = &default_acl_list;
297 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
300 /* === Receive functions === */
302 static uint32 recv_acl_access(uchar *name_follows_ptr, int f)
303 @@ -738,6 +999,11 @@ static int recv_rsync_acl(item_list *rac
304 /* Receive the ACL info the sender has included for this file-list entry. */
305 void receive_acl(struct file_struct *file, int f)
307 + if (protocol_version < 30) {
308 + old_recv_acl(file, f);
312 F_ACL(file) = recv_rsync_acl(&access_acl_list, SMB_ACL_TYPE_ACCESS, f);
314 if (S_ISDIR(file->mode))
317 @@ -163,13 +163,6 @@ void setup_protocol(int f_out,int f_in)
318 if (protocol_version < 30) {
319 if (append_mode == 1)
321 - if (preserve_acls && !local_server) {
323 - "--acls requires protocol 30 or higher"
324 - " (negotiated %d).\n",
326 - exit_cleanup(RERR_PROTOCOL);
328 if (preserve_xattrs && !local_server) {
330 "--xattrs requires protocol 30 or higher"