More compress changes
[rsync.git] / compat.c
1 /*
2  * Compatibility routines for older rsync protocol versions.
3  *
4  * Copyright (C) Andrew Tridgell 1996
5  * Copyright (C) Paul Mackerras 1996
6  * Copyright (C) 2004-2020 Wayne Davison
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, visit the http://fsf.org website.
20  */
21
22 #include "rsync.h"
23
24 extern int am_server;
25 extern int am_sender;
26 extern int local_server;
27 extern int inplace;
28 extern int recurse;
29 extern int use_qsort;
30 extern int allow_inc_recurse;
31 extern int preallocate_files;
32 extern int append_mode;
33 extern int fuzzy_basis;
34 extern int read_batch;
35 extern int write_batch;
36 extern int delay_updates;
37 extern int checksum_seed;
38 extern int basis_dir_cnt;
39 extern int prune_empty_dirs;
40 extern int protocol_version;
41 extern int protect_args;
42 extern int preserve_uid;
43 extern int preserve_gid;
44 extern int preserve_atimes;
45 extern int preserve_acls;
46 extern int preserve_xattrs;
47 extern int xfer_flags_as_varint;
48 extern int need_messages_from_generator;
49 extern int delete_mode, delete_before, delete_during, delete_after;
50 extern int xfersum_type;
51 extern int checksum_type;
52 extern int do_compression;
53 extern char *shell_cmd;
54 extern char *partial_dir;
55 extern char *dest_option;
56 extern char *files_from;
57 extern char *filesfrom_host;
58 extern char *checksum_choice;
59 extern char *compress_choice;
60 extern filter_rule_list filter_list;
61 extern int need_unsorted_flist;
62 #ifdef ICONV_OPTION
63 extern iconv_t ic_send, ic_recv;
64 extern char *iconv_opt;
65 #endif
66 extern struct name_num_obj valid_checksums;
67
68 int remote_protocol = 0;
69 int file_extra_cnt = 0; /* count of file-list extras that everyone gets */
70 int inc_recurse = 0;
71 int compat_flags = 0;
72 int use_safe_inc_flist = 0;
73 int want_xattr_optim = 0;
74 int proper_seed_order = 0;
75 int inplace_partial = 0;
76 int do_negotiated_strings = 0;
77
78 /* These index values are for the file-list's extra-attribute array. */
79 int pathname_ndx, depth_ndx, atimes_ndx, uid_ndx, gid_ndx, acls_ndx, xattrs_ndx, unsort_ndx;
80
81 int receiver_symlink_times = 0; /* receiver can set the time on a symlink */
82 int sender_symlink_iconv = 0;   /* sender should convert symlink content */
83
84 #ifdef ICONV_OPTION
85 int filesfrom_convert = 0;
86 #endif
87
88 #define MAX_NSTR_STRLEN 256
89
90 #define CPRES_NONE 0
91 #define CPRES_ZLIB 1
92 #define CPRES_ZLIBX 2
93
94 struct name_num_obj valid_compressions = {
95         "compress", NULL, NULL, 0, 0, {
96 #ifndef EXTERNAL_ZLIB
97                 { CPRES_ZLIB, "zlib", NULL },
98 #endif
99                 { CPRES_ZLIBX, "zlibx", NULL },
100 #ifdef EXTERNAL_ZLIB
101                 { CPRES_ZLIB, "zlib", NULL },
102 #endif
103                 { CPRES_NONE, "none", NULL },
104                 { 0, NULL, NULL }
105         }
106 };
107
108 #define CF_INC_RECURSE   (1<<0)
109 #define CF_SYMLINK_TIMES (1<<1)
110 #define CF_SYMLINK_ICONV (1<<2)
111 #define CF_SAFE_FLIST    (1<<3)
112 #define CF_AVOID_XATTR_OPTIM (1<<4)
113 #define CF_CHKSUM_SEED_FIX (1<<5)
114 #define CF_INPLACE_PARTIAL_DIR (1<<6)
115 #define CF_VARINT_FLIST_FLAGS (1<<7)
116
117 static const char *client_info;
118
119 /* The server makes sure that if either side only supports a pre-release
120  * version of a protocol, that both sides must speak a compatible version
121  * of that protocol for it to be advertised as available. */
122 static void check_sub_protocol(void)
123 {
124         char *dot;
125         int their_protocol, their_sub;
126 #if SUBPROTOCOL_VERSION != 0
127         int our_sub = protocol_version < PROTOCOL_VERSION ? 0 : SUBPROTOCOL_VERSION;
128 #else
129         int our_sub = 0;
130 #endif
131
132         /* client_info starts with VER.SUB string if client is a pre-release. */
133         if (!(their_protocol = atoi(client_info))
134          || !(dot = strchr(client_info, '.'))
135          || !(their_sub = atoi(dot+1))) {
136 #if SUBPROTOCOL_VERSION != 0
137                 if (our_sub)
138                         protocol_version--;
139 #endif
140                 return;
141         }
142
143         if (their_protocol < protocol_version) {
144                 if (their_sub)
145                         protocol_version = their_protocol - 1;
146                 return;
147         }
148
149         if (their_protocol > protocol_version)
150                 their_sub = 0; /* 0 == final version of older protocol */
151         if (their_sub != our_sub)
152                 protocol_version--;
153 }
154
155 void set_allow_inc_recurse(void)
156 {
157         client_info = shell_cmd ? shell_cmd : "";
158
159         if (!recurse || use_qsort)
160                 allow_inc_recurse = 0;
161         else if (!am_sender
162          && (delete_before || delete_after
163           || delay_updates || prune_empty_dirs))
164                 allow_inc_recurse = 0;
165         else if (am_server && !local_server
166          && (strchr(client_info, 'i') == NULL))
167                 allow_inc_recurse = 0;
168 }
169
170 void parse_compress_choice(int final_call)
171 {
172         int num;
173
174         if (valid_compressions.negotiated_name)
175                 num = valid_compressions.negotiated_num;
176         else if (compress_choice) {
177                 struct name_num_item *nni = get_nni_by_name(&valid_compressions, compress_choice, -1);
178                 if (!nni) {
179                         rprintf(FERROR, "unknown compress name: %s\n", compress_choice);
180                         exit_cleanup(RERR_UNSUPPORTED);
181                 }
182                 num = nni->num;
183         } else
184                 num = CPRES_NONE;
185
186         if (num == CPRES_NONE) {
187                 do_compression = 0;
188                 compress_choice = NULL;
189         } else if (num > 0)
190                 do_compression = num != CPRES_ZLIB ? 2 : 1;
191
192         if (final_call && DEBUG_GTE(NSTR, am_server ? 2 : 1)) {
193                 const char *c_s = am_server ? "Server" : "Client";
194                 if (valid_compressions.negotiated_name)
195                         rprintf(FINFO, "%s negotiated compress: %s\n", c_s, valid_compressions.negotiated_name);
196                 else
197                         rprintf(FINFO, "%s compress: %s\n", c_s, do_compression ? compress_choice : "none");
198         }
199 }
200
201 struct name_num_item *get_nni_by_name(struct name_num_obj *nno, const char *name, int len)
202 {
203         struct name_num_item *nni;
204
205         if (len < 0)
206                 len = strlen(name);
207
208         for (nni = nno->list; nni->name; nni++) {
209                 if (strncasecmp(name, nni->name, len) == 0 && nni->name[len] == '\0')
210                         return nni;
211         }
212
213         return NULL;
214 }
215
216 struct name_num_item *get_nni_by_num(struct name_num_obj *nno, int num)
217 {
218         struct name_num_item *nni;
219
220         for (nni = nno->list; nni->name; nni++) {
221                 if (num == nni->num)
222                         return nni;
223         }
224
225         return NULL;
226 }
227
228 static void init_nno_saw(struct name_num_obj *nno, int val)
229 {
230         struct name_num_item *nni;
231         int cnt;
232
233         if (!nno->saw_len) {
234                 for (nni = nno->list; nni->name; nni++) {
235                         if (nni->num >= nno->saw_len)
236                                 nno->saw_len = nni->num + 1;
237                 }
238         }
239
240         if (!nno->saw) {
241                 if (!(nno->saw = new_array0(uchar, nno->saw_len)))
242                         out_of_memory("init_nno_saw");
243
244                 /* We'll take this opportunity to make sure that the main_name values are set right. */
245                 for (cnt = 1, nni = nno->list; nni->name; nni++, cnt++) {
246                         if (nno->saw[nni->num])
247                                 nni->main_name = nno->list[nno->saw[nni->num]-1].name;
248                         else
249                                 nno->saw[nni->num] = cnt;
250                 }
251         }
252
253         memset(nno->saw, val, nno->saw_len);
254 }
255
256 /* Simplify the user-provided string so that it contains valid names without any duplicates.
257  * It also sets the "saw" flags to a 1-relative count of which name was seen first. */
258 static int parse_nni_str(struct name_num_obj *nno, const char *from, char *tobuf, int tobuf_len)
259 {
260         char *to = tobuf, *tok = NULL;
261         int cnt = 0;
262
263         while (1) {
264                 if (*from == ' ' || !*from) {
265                         if (tok) {
266                                 struct name_num_item *nni = get_nni_by_name(nno, tok, to - tok);
267                                 if (nni && !nno->saw[nni->num]) {
268                                         nno->saw[nni->num] = ++cnt;
269                                         if (nni->main_name && *nni->main_name) {
270                                                 to = tok + strlcpy(tok, nni->main_name, tobuf_len - (tok - tobuf));
271                                                 if (to - tobuf >= tobuf_len) {
272                                                         to = tok - 1;
273                                                         break;
274                                                 }
275                                         }
276                                 } else
277                                         to = tok - (tok != tobuf);
278                                 tok = NULL;
279                         }
280                         if (!*from++)
281                                 break;
282                         continue;
283                 }
284                 if (!tok) {
285                         if (to != tobuf)
286                                 *to++ = ' ';
287                         tok = to;
288                 }
289                 if (to - tobuf >= tobuf_len - 1) {
290                         to = tok - (tok != tobuf);
291                         break;
292                 }
293                 *to++ = *from++;
294         }
295         *to = '\0';
296
297         return to - tobuf;
298 }
299
300 static void recv_negotiate_str(int f_in, struct name_num_obj *nno, char *tmpbuf, int len)
301 {
302         struct name_num_item *ret = NULL;
303
304         if (len < 0)
305                 len = read_vstring(f_in, tmpbuf, MAX_NSTR_STRLEN);
306
307         if (DEBUG_GTE(NSTR, am_server ? 4 : 2)) {
308                 if (am_server)
309                         rprintf(FINFO, "Client %s list (on server): %s\n", nno->type, tmpbuf);
310                 else
311                         rprintf(FINFO, "Server %s list (on client): %s\n", nno->type, tmpbuf);
312         }
313
314         if (len > 0) {
315                 int best = nno->saw_len; /* We want best == 1 from the client list, so start with a big number. */
316                 char *tok;
317                 if (am_server)
318                         init_nno_saw(nno, 1); /* Since we're parsing client names, anything we parse first is #1. */
319                 for (tok = strtok(tmpbuf, " \t"); tok; tok = strtok(NULL, " \t")) {
320                         struct name_num_item *nni = get_nni_by_name(nno, tok, -1);
321                         if (!nni || !nno->saw[nni->num] || best <= nno->saw[nni->num])
322                                 continue;
323                         ret = nni;
324                         best = nno->saw[nni->num];
325                         if (best == 1)
326                                 break;
327                 }
328                 if (ret) {
329                         free(nno->saw);
330                         nno->saw = NULL;
331                         nno->negotiated_name = ret->main_name ? ret->main_name : ret->name;
332                         nno->negotiated_num = ret->num;
333                         return;
334                 }
335         }
336
337         if (!am_server)
338                 rprintf(FERROR, "Failed to negotiate a common %s\n", nno->type);
339         exit_cleanup(RERR_UNSUPPORTED);
340 }
341
342 static void send_negotiate_str(int f_out, struct name_num_obj *nno, const char *env_name)
343 {
344         char tmpbuf[MAX_NSTR_STRLEN];
345         struct name_num_item *nni;
346         const char *list_str = getenv(env_name);
347         int len, fail_if_empty = list_str && strstr(list_str, "FAIL");
348
349         if (!do_negotiated_strings) {
350                 if (!am_server && fail_if_empty) {
351                         rprintf(FERROR, "Remote rsync is too old for %s negotation\n", nno->type);
352                         exit_cleanup(RERR_UNSUPPORTED);
353                 }
354                 return;
355         }
356
357         init_nno_saw(nno, 0);
358
359         if (list_str && *list_str && (!am_server || local_server)) {
360                 len = parse_nni_str(nno, list_str, tmpbuf, MAX_NSTR_STRLEN);
361                 if (fail_if_empty && !len)
362                         len = strlcpy(tmpbuf, "FAIL", MAX_NSTR_STRLEN);
363                 list_str = tmpbuf;
364         } else
365                 list_str = NULL;
366
367         if (!list_str || !*list_str) {
368                 int cnt = 0;
369                 for (nni = nno->list, len = 0; nni->name; nni++) {
370                         if (nni->main_name)
371                                 continue;
372                         if (len)
373                                 tmpbuf[len++]= ' ';
374                         len += strlcpy(tmpbuf+len, nni->name, MAX_NSTR_STRLEN - len);
375                         if (len >= (int)MAX_NSTR_STRLEN - 1)
376                                 exit_cleanup(RERR_UNSUPPORTED); /* IMPOSSIBLE... */
377                         nno->saw[nni->num] = ++cnt;
378                 }
379         }
380
381         if (DEBUG_GTE(NSTR, am_server ? 4 : 2)) {
382                 if (am_server)
383                         rprintf(FINFO, "Server %s list (on server): %s\n", nno->type, tmpbuf);
384                 else
385                         rprintf(FINFO, "Client %s list (on client): %s\n", nno->type, tmpbuf);
386         }
387
388         if (local_server) {
389                 /* A local server doesn't bother to send/recv the strings, it just constructs
390                  * and parses the same string on both sides. */
391                 if (!read_batch)
392                         recv_negotiate_str(-1, nno, tmpbuf, len);
393         } else {
394                 /* Each side sends their list of valid names to the other side and then both sides
395                  * pick the first name in the client's list that is also in the server's list. */
396                 write_vstring(f_out, tmpbuf, len);
397         }
398 }
399
400 static void negotiate_the_strings(int f_in, int f_out)
401 {
402         /* We send all the negotiation strings before we start to read them to help avoid a slow startup. */
403
404         if (!checksum_choice)
405                 send_negotiate_str(f_out, &valid_checksums, "RSYNC_CHECKSUM_LIST");
406
407         if (do_compression && !compress_choice)
408                 send_negotiate_str(f_out, &valid_compressions, "RSYNC_COMPRESS_LIST");
409
410         if (valid_checksums.saw) {
411                 char tmpbuf[MAX_NSTR_STRLEN];
412                 recv_negotiate_str(f_in, &valid_checksums, tmpbuf, -1);
413         }
414         if (valid_checksums.negotiated_name)
415                 xfersum_type = checksum_type = valid_checksums.negotiated_num;
416
417         if (valid_compressions.saw) {
418                 char tmpbuf[MAX_NSTR_STRLEN];
419                 recv_negotiate_str(f_in, &valid_compressions, tmpbuf, -1);
420         }
421 #if 0
422         if (valid_compressions.negotiated_name)
423                 compress_type = valid_checksums.negotiated_num;
424 #endif
425 }
426
427 void setup_protocol(int f_out,int f_in)
428 {
429         assert(file_extra_cnt == 0);
430         assert(EXTRA64_CNT == 2 || EXTRA64_CNT == 1);
431
432         /* All int64 values must be set first so that they are guaranteed to be
433          * aligned for direct int64-pointer memory access. */
434         if (preserve_atimes)
435                 atimes_ndx = (file_extra_cnt += EXTRA64_CNT);
436         if (am_sender) /* This is most likely in the in64 union as well. */
437                 pathname_ndx = (file_extra_cnt += PTR_EXTRA_CNT);
438         else
439                 depth_ndx = ++file_extra_cnt;
440         if (preserve_uid)
441                 uid_ndx = ++file_extra_cnt;
442         if (preserve_gid)
443                 gid_ndx = ++file_extra_cnt;
444         if (preserve_acls && !am_sender)
445                 acls_ndx = ++file_extra_cnt;
446         if (preserve_xattrs)
447                 xattrs_ndx = ++file_extra_cnt;
448
449         if (am_server)
450                 set_allow_inc_recurse();
451
452         if (remote_protocol == 0) {
453                 if (am_server && !local_server)
454                         check_sub_protocol();
455                 if (!read_batch)
456                         write_int(f_out, protocol_version);
457                 remote_protocol = read_int(f_in);
458                 if (protocol_version > remote_protocol)
459                         protocol_version = remote_protocol;
460         }
461         if (read_batch && remote_protocol > protocol_version) {
462                 rprintf(FERROR, "The protocol version in the batch file is too new (%d > %d).\n",
463                         remote_protocol, protocol_version);
464                 exit_cleanup(RERR_PROTOCOL);
465         }
466
467         if (DEBUG_GTE(PROTO, 1)) {
468                 rprintf(FINFO, "(%s) Protocol versions: remote=%d, negotiated=%d\n",
469                         am_server? "Server" : "Client", remote_protocol, protocol_version);
470         }
471         if (remote_protocol < MIN_PROTOCOL_VERSION
472          || remote_protocol > MAX_PROTOCOL_VERSION) {
473                 rprintf(FERROR,"protocol version mismatch -- is your shell clean?\n");
474                 rprintf(FERROR,"(see the rsync man page for an explanation)\n");
475                 exit_cleanup(RERR_PROTOCOL);
476         }
477         if (remote_protocol < OLD_PROTOCOL_VERSION) {
478                 rprintf(FINFO,"%s is very old version of rsync, upgrade recommended.\n",
479                         am_server? "Client" : "Server");
480         }
481         if (protocol_version < MIN_PROTOCOL_VERSION) {
482                 rprintf(FERROR, "--protocol must be at least %d on the %s.\n",
483                         MIN_PROTOCOL_VERSION, am_server? "Server" : "Client");
484                 exit_cleanup(RERR_PROTOCOL);
485         }
486         if (protocol_version > PROTOCOL_VERSION) {
487                 rprintf(FERROR, "--protocol must be no more than %d on the %s.\n",
488                         PROTOCOL_VERSION, am_server? "Server" : "Client");
489                 exit_cleanup(RERR_PROTOCOL);
490         }
491         if (read_batch)
492                 check_batch_flags();
493
494 #ifndef SUPPORT_PREALLOCATION
495         if (preallocate_files && !am_sender) {
496                 rprintf(FERROR, "preallocation is not supported on this %s\n",
497                         am_server ? "Server" : "Client");
498                 exit_cleanup(RERR_SYNTAX);
499         }
500 #endif
501
502         if (protocol_version < 30) {
503                 if (append_mode == 1)
504                         append_mode = 2;
505                 if (preserve_acls && !local_server) {
506                         rprintf(FERROR,
507                             "--acls requires protocol 30 or higher"
508                             " (negotiated %d).\n",
509                             protocol_version);
510                         exit_cleanup(RERR_PROTOCOL);
511                 }
512                 if (preserve_xattrs && !local_server) {
513                         rprintf(FERROR,
514                             "--xattrs requires protocol 30 or higher"
515                             " (negotiated %d).\n",
516                             protocol_version);
517                         exit_cleanup(RERR_PROTOCOL);
518                 }
519         }
520
521         if (delete_mode && !(delete_before+delete_during+delete_after)) {
522                 if (protocol_version < 30)
523                         delete_before = 1;
524                 else
525                         delete_during = 1;
526         }
527
528         if (protocol_version < 29) {
529                 if (fuzzy_basis) {
530                         rprintf(FERROR,
531                             "--fuzzy requires protocol 29 or higher"
532                             " (negotiated %d).\n",
533                             protocol_version);
534                         exit_cleanup(RERR_PROTOCOL);
535                 }
536
537                 if (basis_dir_cnt && inplace) {
538                         rprintf(FERROR,
539                             "%s with --inplace requires protocol 29 or higher"
540                             " (negotiated %d).\n",
541                             dest_option, protocol_version);
542                         exit_cleanup(RERR_PROTOCOL);
543                 }
544
545                 if (basis_dir_cnt > 1) {
546                         rprintf(FERROR,
547                             "Using more than one %s option requires protocol"
548                             " 29 or higher (negotiated %d).\n",
549                             dest_option, protocol_version);
550                         exit_cleanup(RERR_PROTOCOL);
551                 }
552
553                 if (prune_empty_dirs) {
554                         rprintf(FERROR,
555                             "--prune-empty-dirs requires protocol 29 or higher"
556                             " (negotiated %d).\n",
557                             protocol_version);
558                         exit_cleanup(RERR_PROTOCOL);
559                 }
560         } else if (protocol_version >= 30) {
561                 if (am_server) {
562                         compat_flags = allow_inc_recurse ? CF_INC_RECURSE : 0;
563 #ifdef CAN_SET_SYMLINK_TIMES
564                         compat_flags |= CF_SYMLINK_TIMES;
565 #endif
566 #ifdef ICONV_OPTION
567                         compat_flags |= CF_SYMLINK_ICONV;
568 #endif
569                         if (local_server || strchr(client_info, 'f') != NULL)
570                                 compat_flags |= CF_SAFE_FLIST;
571                         if (local_server || strchr(client_info, 'x') != NULL)
572                                 compat_flags |= CF_AVOID_XATTR_OPTIM;
573                         if (local_server || strchr(client_info, 'C') != NULL)
574                                 compat_flags |= CF_CHKSUM_SEED_FIX;
575                         if (local_server || strchr(client_info, 'I') != NULL)
576                                 compat_flags |= CF_INPLACE_PARTIAL_DIR;
577                         if (local_server || strchr(client_info, 'v') != NULL) {
578                                 if (!write_batch || protocol_version >= 30) {
579                                         do_negotiated_strings = 1;
580                                         compat_flags |= CF_VARINT_FLIST_FLAGS;
581                                 }
582                         }
583                         if (strchr(client_info, 'V') != NULL) { /* Support a pre-release 'V' that got superseded */
584                                 if (!write_batch)
585                                         compat_flags |= CF_VARINT_FLIST_FLAGS;
586                                 write_byte(f_out, compat_flags);
587                         } else
588                                 write_varint(f_out, compat_flags);
589                 } else { /* read_varint() is compatible with the older write_byte() when the 0x80 bit isn't on. */
590                         compat_flags = read_varint(f_in);
591                         if  (compat_flags & CF_VARINT_FLIST_FLAGS)
592                                 do_negotiated_strings = 1;
593                 }
594                 /* The inc_recurse var MUST be set to 0 or 1. */
595                 inc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;
596                 want_xattr_optim = protocol_version >= 31 && !(compat_flags & CF_AVOID_XATTR_OPTIM);
597                 proper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;
598                 xfer_flags_as_varint = compat_flags & CF_VARINT_FLIST_FLAGS ? 1 : 0;
599                 if (am_sender) {
600                         receiver_symlink_times = am_server
601                             ? strchr(client_info, 'L') != NULL
602                             : !!(compat_flags & CF_SYMLINK_TIMES);
603                 }
604 #ifdef CAN_SET_SYMLINK_TIMES
605                 else
606                         receiver_symlink_times = 1;
607 #endif
608 #ifdef ICONV_OPTION
609                 sender_symlink_iconv = iconv_opt && (am_server
610                     ? local_server || strchr(client_info, 's') != NULL
611                     : !!(compat_flags & CF_SYMLINK_ICONV));
612 #endif
613                 if (inc_recurse && !allow_inc_recurse) {
614                         /* This should only be able to happen in a batch. */
615                         fprintf(stderr,
616                             "Incompatible options specified for inc-recursive %s.\n",
617                             read_batch ? "batch file" : "connection");
618                         exit_cleanup(RERR_SYNTAX);
619                 }
620                 use_safe_inc_flist = (compat_flags & CF_SAFE_FLIST) || protocol_version >= 31;
621                 need_messages_from_generator = 1;
622                 if (compat_flags & CF_INPLACE_PARTIAL_DIR)
623                         inplace_partial = 1;
624 #ifdef CAN_SET_SYMLINK_TIMES
625         } else if (!am_sender) {
626                 receiver_symlink_times = 1;
627 #endif
628         }
629
630         if (need_unsorted_flist && (!am_sender || inc_recurse))
631                 unsort_ndx = ++file_extra_cnt;
632
633         if (partial_dir && *partial_dir != '/' && (!am_server || local_server)) {
634                 int rflags = FILTRULE_NO_PREFIXES | FILTRULE_DIRECTORY;
635                 if (!am_sender || protocol_version >= 30)
636                         rflags |= FILTRULE_PERISHABLE;
637                 parse_filter_str(&filter_list, partial_dir, rule_template(rflags), 0);
638         }
639
640
641 #ifdef ICONV_OPTION
642         if (protect_args && files_from) {
643                 if (am_sender)
644                         filesfrom_convert = filesfrom_host && ic_send != (iconv_t)-1;
645                 else
646                         filesfrom_convert = !filesfrom_host && ic_recv != (iconv_t)-1;
647         }
648 #endif
649
650         negotiate_the_strings(f_in, f_out);
651
652         if (am_server) {
653                 if (!checksum_seed)
654                         checksum_seed = time(NULL) ^ (getpid() << 6);
655                 write_int(f_out, checksum_seed);
656         } else {
657                 checksum_seed = read_int(f_in);
658         }
659
660         init_flist();
661 }
662
663 void maybe_write_negotiated_strings(int batch_fd)
664 {
665         if (valid_checksums.negotiated_name)
666                 write_vstring(batch_fd, valid_checksums.negotiated_name, strlen(valid_checksums.negotiated_name));
667
668         if (valid_compressions.negotiated_name)
669                 write_vstring(batch_fd, valid_compressions.negotiated_name, strlen(valid_compressions.negotiated_name));
670 }