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)
12 diff --git a/acls.c b/acls.c
15 @@ -31,6 +31,7 @@ extern int list_only;
16 extern int orig_umask;
17 extern int numeric_ids;
18 extern int inc_recurse;
19 +extern int protocol_version;
21 /* Flags used to indicate what items are being transmitted for an entry. */
22 #define XMIT_USER_OBJ (1<<0)
23 @@ -107,6 +108,18 @@ static const char *str_acl_type(SMB_ACL_TYPE_T type)
24 return "unknown ACL type!";
27 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
28 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
30 +static int old_count_racl_entries(const rsync_acl *racl)
32 + return racl->names.count
33 + + (racl->user_obj != NO_ENTRY)
34 + + (racl->group_obj != NO_ENTRY)
35 + + (racl->mask_obj != NO_ENTRY)
36 + + (racl->other_obj != NO_ENTRY);
39 static int calc_sacl_entries(const rsync_acl *racl)
41 /* A System ACL always gets user/group/other permission entries. */
42 @@ -554,6 +567,96 @@ int get_acl(const char *fname, stat_x *sxp)
46 +/* === OLD Send functions === */
48 +/* Send the ida list over the file descriptor. */
49 +static void old_send_ida_entries(int f, const ida_entries *idal, char tag_char)
52 + size_t count = idal->count;
53 + for (ida = idal->idas; count--; ida++) {
54 + if (tag_char == 'U') {
55 + if (!(ida->access & NAME_IS_USER))
59 + if (ida->access & NAME_IS_USER)
63 + write_byte(f, tag_char);
64 + write_byte(f, ida->access);
65 + write_int(f, ida->id);
69 +/* Send an rsync ACL over the file descriptor. */
70 +static void old_send_rsync_acl(int f, const rsync_acl *racl)
72 + size_t count = old_count_racl_entries(racl);
73 + write_int(f, count);
74 + if (racl->user_obj != NO_ENTRY) {
76 + write_byte(f, racl->user_obj);
78 + old_send_ida_entries(f, &racl->names, 'U');
79 + if (racl->group_obj != NO_ENTRY) {
81 + write_byte(f, racl->group_obj);
83 + old_send_ida_entries(f, &racl->names, 'G');
84 + if (racl->mask_obj != NO_ENTRY) {
86 + write_byte(f, racl->mask_obj);
88 + if (racl->other_obj != NO_ENTRY) {
90 + write_byte(f, racl->other_obj);
94 +/* Send the ACL from the stat_x structure down the indicated file descriptor.
95 + * This also frees the ACL data. */
96 +void old_send_acl(stat_x *sxp, int f)
98 + SMB_ACL_TYPE_T type;
99 + rsync_acl *racl, *new_racl;
100 + item_list *racl_list;
103 + type = SMB_ACL_TYPE_ACCESS;
104 + racl = sxp->acc_acl;
105 + racl_list = &access_acl_list;
108 + racl = new(rsync_acl);
110 + out_of_memory("send_acl");
111 + *racl = empty_rsync_acl;
112 + if (type == SMB_ACL_TYPE_ACCESS) {
113 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
114 + sxp->acc_acl = racl;
116 + sxp->def_acl = racl;
119 + if ((ndx = find_matching_rsync_acl(racl, type, racl_list)) != -1) {
120 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
123 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
124 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
125 + old_send_rsync_acl(f, racl);
127 + *racl = empty_rsync_acl;
129 + racl = sxp->def_acl;
130 + racl_list = &default_acl_list;
131 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
136 /* === Send functions === */
138 /* Send the ida list over the file descriptor. */
139 @@ -629,6 +732,11 @@ static void send_rsync_acl(rsync_acl *racl, SMB_ACL_TYPE_T type,
140 * This also frees the ACL data. */
141 void send_acl(stat_x *sxp, int f)
143 + if (protocol_version < 30) {
144 + old_send_acl(sxp, f);
149 sxp->acc_acl = create_racl();
150 rsync_acl_fake_perms(sxp->acc_acl, sxp->st.st_mode);
151 @@ -646,6 +754,160 @@ void send_acl(stat_x *sxp, int f)
155 +/* === OLD Receive functions */
157 +static void old_recv_rsync_acl(rsync_acl *racl, int f)
159 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
160 + SMB_ACL_TAG_T tag_type = 0;
161 + uchar computed_mask_bits = 0;
165 + if (!(count = read_int(f)))
169 + char tag = read_byte(f);
170 + uchar access = read_byte(f);
171 + if (access & ~ (4 | 2 | 1)) {
172 + rprintf(FERROR, "old_recv_rsync_acl: bogus permset %o\n",
174 + exit_cleanup(RERR_STREAMIO);
178 + if (racl->user_obj != NO_ENTRY) {
179 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate USER_OBJ entry\n");
180 + exit_cleanup(RERR_STREAMIO);
182 + racl->user_obj = access;
185 + tag_type = SMB_ACL_USER;
188 + if (racl->group_obj != NO_ENTRY) {
189 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate GROUP_OBJ entry\n");
190 + exit_cleanup(RERR_STREAMIO);
192 + racl->group_obj = access;
195 + tag_type = SMB_ACL_GROUP;
198 + if (racl->mask_obj != NO_ENTRY) {
199 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate MASK entry\n");
200 + exit_cleanup(RERR_STREAMIO);
202 + racl->mask_obj = access;
205 + if (racl->other_obj != NO_ENTRY) {
206 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate OTHER entry\n");
207 + exit_cleanup(RERR_STREAMIO);
209 + racl->other_obj = access;
212 + rprintf(FERROR, "old_recv_rsync_acl: unknown tag %c\n",
214 + exit_cleanup(RERR_STREAMIO);
216 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
217 + ida->access = access | (tag_type == SMB_ACL_USER ? NAME_IS_USER : 0);
218 + ida->id = read_int(f);
219 + computed_mask_bits |= access;
222 + /* Transfer the count id_access items out of the temp_ida_list
223 + * into the names ida_entries list in racl. */
224 + if (temp_ida_list.count) {
225 +#ifdef SMB_ACL_NEED_SORT
226 + if (temp_ida_list.count > 1) {
227 + qsort(temp_ida_list.items, temp_ida_list.count,
228 + sizeof (id_access), id_access_sorter);
231 + if (!(racl->names.idas = new_array(id_access, temp_ida_list.count)))
232 + out_of_memory("unpack_smb_acl");
233 + memcpy(racl->names.idas, temp_ida_list.items,
234 + temp_ida_list.count * sizeof (id_access));
236 + racl->names.idas = NULL;
238 + racl->names.count = temp_ida_list.count;
240 + /* Truncate the temporary list now that its idas have been saved. */
241 + temp_ida_list.count = 0;
243 + if (!racl->names.count) {
244 + /* If we received a superfluous mask, throw it away. */
245 + if (racl->mask_obj != NO_ENTRY) {
246 + /* Mask off the group perms with it first. */
247 + racl->group_obj &= racl->mask_obj | NO_ENTRY;
248 + racl->mask_obj = NO_ENTRY;
250 + } else if (racl->mask_obj == NO_ENTRY) /* Must be non-empty with lists. */
251 + racl->mask_obj = (computed_mask_bits | racl->group_obj) & 7;
254 +/* Receive the ACL info the sender has included for this file-list entry. */
255 +void old_recv_acl(struct file_struct *file, int f)
257 + SMB_ACL_TYPE_T type;
258 + item_list *racl_list;
260 + if (S_ISLNK(file->mode))
263 + type = SMB_ACL_TYPE_ACCESS;
264 + racl_list = &access_acl_list;
266 + char tag = read_byte(f);
269 + if (tag == 'A' || tag == 'a') {
270 + if (type != SMB_ACL_TYPE_ACCESS) {
271 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
272 + f_name(file, NULL));
273 + exit_cleanup(RERR_STREAMIO);
275 + } else if (tag == 'D' || tag == 'd') {
276 + if (type == SMB_ACL_TYPE_ACCESS) {
277 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
278 + f_name(file, NULL));
279 + exit_cleanup(RERR_STREAMIO);
282 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
283 + f_name(file, NULL), tag);
284 + exit_cleanup(RERR_STREAMIO);
286 + if (tag == 'A' || tag == 'D') {
288 + ndx = racl_list->count;
289 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
290 + duo_item->racl = empty_rsync_acl;
291 + old_recv_rsync_acl(&duo_item->racl, f);
292 + duo_item->sacl = NULL;
295 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
296 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
297 + f_name(file, NULL), str_acl_type(type), ndx);
298 + exit_cleanup(RERR_STREAMIO);
301 + if (type == SMB_ACL_TYPE_ACCESS)
304 + F_DIR_DEFACL(file) = ndx;
305 + racl_list = &default_acl_list;
306 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
309 /* === Receive functions === */
311 static uint32 recv_acl_access(uchar *name_follows_ptr, int f)
312 @@ -768,6 +1030,11 @@ static int recv_rsync_acl(item_list *racl_list, SMB_ACL_TYPE_T type, int f)
313 /* Receive the ACL info the sender has included for this file-list entry. */
314 void receive_acl(struct file_struct *file, int f)
316 + if (protocol_version < 30) {
317 + old_recv_acl(file, f);
321 F_ACL(file) = recv_rsync_acl(&access_acl_list, SMB_ACL_TYPE_ACCESS, f);
323 if (S_ISDIR(file->mode))
324 diff --git a/compat.c b/compat.c
327 @@ -187,13 +187,6 @@ void setup_protocol(int f_out,int f_in)
328 if (protocol_version < 30) {
329 if (append_mode == 1)
331 - if (preserve_acls && !local_server) {
333 - "--acls requires protocol 30 or higher"
334 - " (negotiated %d).\n",
336 - exit_cleanup(RERR_PROTOCOL);
338 if (preserve_xattrs && !local_server) {
340 "--xattrs requires protocol 30 or higher"