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 based-on: 3b8f8192227b14e708bf535072485e50f4362270
13 diff --git a/acls.c b/acls.c
16 @@ -31,6 +31,7 @@ extern int list_only;
17 extern int orig_umask;
18 extern int numeric_ids;
19 extern int inc_recurse;
20 +extern int protocol_version;
22 /* Flags used to indicate what items are being transmitted for an entry. */
23 #define XMIT_USER_OBJ (1<<0)
24 @@ -110,6 +111,18 @@ static const char *str_acl_type(SMB_ACL_TYPE_T type)
25 return "unknown ACL type!";
28 +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t))
29 +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT)
31 +static int old_count_racl_entries(const rsync_acl *racl)
33 + return racl->names.count
34 + + (racl->user_obj != NO_ENTRY)
35 + + (racl->group_obj != NO_ENTRY)
36 + + (racl->mask_obj != NO_ENTRY)
37 + + (racl->other_obj != NO_ENTRY);
40 static int calc_sacl_entries(const rsync_acl *racl)
42 /* A System ACL always gets user/group/other permission entries. */
43 @@ -555,6 +568,96 @@ int get_acl(const char *fname, stat_x *sxp)
47 +/* === OLD Send functions === */
49 +/* Send the ida list over the file descriptor. */
50 +static void old_send_ida_entries(int f, const ida_entries *idal, char tag_char)
53 + size_t count = idal->count;
54 + for (ida = idal->idas; count--; ida++) {
55 + if (tag_char == 'U') {
56 + if (!(ida->access & NAME_IS_USER))
60 + if (ida->access & NAME_IS_USER)
64 + write_byte(f, tag_char);
65 + write_byte(f, ida->access);
66 + write_int(f, ida->id);
70 +/* Send an rsync ACL over the file descriptor. */
71 +static void old_send_rsync_acl(int f, const rsync_acl *racl)
73 + size_t count = old_count_racl_entries(racl);
74 + write_int(f, count);
75 + if (racl->user_obj != NO_ENTRY) {
77 + write_byte(f, racl->user_obj);
79 + old_send_ida_entries(f, &racl->names, 'U');
80 + if (racl->group_obj != NO_ENTRY) {
82 + write_byte(f, racl->group_obj);
84 + old_send_ida_entries(f, &racl->names, 'G');
85 + if (racl->mask_obj != NO_ENTRY) {
87 + write_byte(f, racl->mask_obj);
89 + if (racl->other_obj != NO_ENTRY) {
91 + write_byte(f, racl->other_obj);
95 +/* Send the ACL from the stat_x structure down the indicated file descriptor.
96 + * This also frees the ACL data. */
97 +void old_send_acl(stat_x *sxp, int f)
99 + SMB_ACL_TYPE_T type;
100 + rsync_acl *racl, *new_racl;
101 + item_list *racl_list;
104 + type = SMB_ACL_TYPE_ACCESS;
105 + racl = sxp->acc_acl;
106 + racl_list = &access_acl_list;
109 + racl = new(rsync_acl);
111 + out_of_memory("send_acl");
112 + *racl = empty_rsync_acl;
113 + if (type == SMB_ACL_TYPE_ACCESS) {
114 + rsync_acl_fake_perms(racl, sxp->st.st_mode);
115 + sxp->acc_acl = racl;
117 + sxp->def_acl = racl;
120 + if ((ndx = find_matching_rsync_acl(racl, type, racl_list)) != -1) {
121 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
124 + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
125 + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
126 + old_send_rsync_acl(f, racl);
128 + *racl = empty_rsync_acl;
130 + racl = sxp->def_acl;
131 + racl_list = &default_acl_list;
132 + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode));
137 /* === Send functions === */
139 /* Send the ida list over the file descriptor. */
140 @@ -630,6 +733,11 @@ static void send_rsync_acl(int f, rsync_acl *racl, SMB_ACL_TYPE_T type,
141 * This also frees the ACL data. */
142 void send_acl(int f, stat_x *sxp)
144 + if (protocol_version < 30) {
145 + old_send_acl(sxp, f);
150 sxp->acc_acl = create_racl();
151 rsync_acl_fake_perms(sxp->acc_acl, sxp->st.st_mode);
152 @@ -647,6 +755,160 @@ void send_acl(int f, stat_x *sxp)
156 +/* === OLD Receive functions */
158 +static void old_recv_rsync_acl(rsync_acl *racl, int f)
160 + static item_list temp_ida_list = EMPTY_ITEM_LIST;
161 + SMB_ACL_TAG_T tag_type = 0;
162 + uchar computed_mask_bits = 0;
166 + if (!(count = read_int(f)))
170 + char tag = read_byte(f);
171 + uchar access = read_byte(f);
172 + if (access & ~ (4 | 2 | 1)) {
173 + rprintf(FERROR, "old_recv_rsync_acl: bogus permset %o\n",
175 + exit_cleanup(RERR_STREAMIO);
179 + if (racl->user_obj != NO_ENTRY) {
180 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate USER_OBJ entry\n");
181 + exit_cleanup(RERR_STREAMIO);
183 + racl->user_obj = access;
186 + tag_type = SMB_ACL_USER;
189 + if (racl->group_obj != NO_ENTRY) {
190 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate GROUP_OBJ entry\n");
191 + exit_cleanup(RERR_STREAMIO);
193 + racl->group_obj = access;
196 + tag_type = SMB_ACL_GROUP;
199 + if (racl->mask_obj != NO_ENTRY) {
200 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate MASK entry\n");
201 + exit_cleanup(RERR_STREAMIO);
203 + racl->mask_obj = access;
206 + if (racl->other_obj != NO_ENTRY) {
207 + rprintf(FERROR, "old_recv_rsync_acl: error: duplicate OTHER entry\n");
208 + exit_cleanup(RERR_STREAMIO);
210 + racl->other_obj = access;
213 + rprintf(FERROR, "old_recv_rsync_acl: unknown tag %c\n",
215 + exit_cleanup(RERR_STREAMIO);
217 + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
218 + ida->access = access | (tag_type == SMB_ACL_USER ? NAME_IS_USER : 0);
219 + ida->id = read_int(f);
220 + computed_mask_bits |= access;
223 + /* Transfer the count id_access items out of the temp_ida_list
224 + * into the names ida_entries list in racl. */
225 + if (temp_ida_list.count) {
226 +#ifdef SMB_ACL_NEED_SORT
227 + if (temp_ida_list.count > 1) {
228 + qsort(temp_ida_list.items, temp_ida_list.count,
229 + sizeof (id_access), id_access_sorter);
232 + if (!(racl->names.idas = new_array(id_access, temp_ida_list.count)))
233 + out_of_memory("unpack_smb_acl");
234 + memcpy(racl->names.idas, temp_ida_list.items,
235 + temp_ida_list.count * sizeof (id_access));
237 + racl->names.idas = NULL;
239 + racl->names.count = temp_ida_list.count;
241 + /* Truncate the temporary list now that its idas have been saved. */
242 + temp_ida_list.count = 0;
244 + if (!racl->names.count) {
245 + /* If we received a superfluous mask, throw it away. */
246 + if (racl->mask_obj != NO_ENTRY) {
247 + /* Mask off the group perms with it first. */
248 + racl->group_obj &= racl->mask_obj | NO_ENTRY;
249 + racl->mask_obj = NO_ENTRY;
251 + } else if (racl->mask_obj == NO_ENTRY) /* Must be non-empty with lists. */
252 + racl->mask_obj = (computed_mask_bits | racl->group_obj) & 7;
255 +/* Receive the ACL info the sender has included for this file-list entry. */
256 +void old_recv_acl(struct file_struct *file, int f)
258 + SMB_ACL_TYPE_T type;
259 + item_list *racl_list;
261 + if (S_ISLNK(file->mode))
264 + type = SMB_ACL_TYPE_ACCESS;
265 + racl_list = &access_acl_list;
267 + char tag = read_byte(f);
270 + if (tag == 'A' || tag == 'a') {
271 + if (type != SMB_ACL_TYPE_ACCESS) {
272 + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
273 + f_name(file, NULL));
274 + exit_cleanup(RERR_STREAMIO);
276 + } else if (tag == 'D' || tag == 'd') {
277 + if (type == SMB_ACL_TYPE_ACCESS) {
278 + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
279 + f_name(file, NULL));
280 + exit_cleanup(RERR_STREAMIO);
283 + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
284 + f_name(file, NULL), tag);
285 + exit_cleanup(RERR_STREAMIO);
287 + if (tag == 'A' || tag == 'D') {
289 + ndx = racl_list->count;
290 + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
291 + duo_item->racl = empty_rsync_acl;
292 + old_recv_rsync_acl(&duo_item->racl, f);
293 + duo_item->sacl = NULL;
296 + if (ndx < 0 || (size_t)ndx >= racl_list->count) {
297 + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
298 + f_name(file, NULL), str_acl_type(type), ndx);
299 + exit_cleanup(RERR_STREAMIO);
302 + if (type == SMB_ACL_TYPE_ACCESS)
305 + F_DIR_DEFACL(file) = ndx;
306 + racl_list = &default_acl_list;
307 + } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
310 /* === Receive functions === */
312 static uint32 recv_acl_access(int f, uchar *name_follows_ptr)
313 @@ -768,6 +1030,11 @@ static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type, mode
314 /* Receive the ACL info the sender has included for this file-list entry. */
315 void receive_acl(int f, struct file_struct *file)
317 + if (protocol_version < 30) {
318 + old_recv_acl(file, f);
322 F_ACL(file) = recv_rsync_acl(f, &access_acl_list, SMB_ACL_TYPE_ACCESS, file->mode);
324 if (S_ISDIR(file->mode))
325 diff --git a/compat.c b/compat.c
328 @@ -192,13 +192,6 @@ void setup_protocol(int f_out,int f_in)
329 if (protocol_version < 30) {
330 if (append_mode == 1)
332 - if (preserve_acls && !local_server) {
334 - "--acls requires protocol 30 or higher"
335 - " (negotiated %d).\n",
337 - exit_cleanup(RERR_PROTOCOL);
339 if (preserve_xattrs && !local_server) {
341 "--xattrs requires protocol 30 or higher"