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