2 * Compatibility routines for older rsync protocol versions.
4 * Copyright (C) Andrew Tridgell 1996
5 * Copyright (C) Paul Mackerras 1996
6 * Copyright (C) 2004-2022 Wayne Davison
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.
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.
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.
28 extern int local_server
;
32 extern int allow_inc_recurse
;
33 extern int preallocate_files
;
34 extern int append_mode
;
35 extern int fuzzy_basis
;
36 extern int read_batch
;
37 extern int write_batch
;
38 extern int delay_updates
;
39 extern int checksum_seed
;
40 extern int basis_dir_cnt
;
41 extern int prune_empty_dirs
;
42 extern int protocol_version
;
43 extern int protect_args
;
44 extern int preserve_uid
;
45 extern int preserve_gid
;
46 extern int preserve_atimes
;
47 extern int preserve_crtimes
;
48 extern int preserve_acls
;
49 extern int preserve_xattrs
;
50 extern int xfer_flags_as_varint
;
51 extern int need_messages_from_generator
;
52 extern int delete_mode
, delete_before
, delete_during
, delete_after
;
53 extern int do_compression
;
54 extern int do_compression_level
;
55 extern int saw_stderr_opt
;
56 extern int msgs2stderr
;
57 extern char *shell_cmd
;
58 extern char *partial_dir
;
59 extern char *files_from
;
60 extern char *filesfrom_host
;
61 extern const char *checksum_choice
;
62 extern const char *compress_choice
;
63 extern char *daemon_auth_choices
;
64 extern filter_rule_list filter_list
;
65 extern int need_unsorted_flist
;
67 extern iconv_t ic_send
, ic_recv
;
68 extern char *iconv_opt
;
70 extern struct name_num_obj valid_checksums
, valid_auth_checksums
;
72 extern struct name_num_item
*xfer_sum_nni
;
74 int remote_protocol
= 0;
75 int file_extra_cnt
= 0; /* count of file-list extras that everyone gets */
78 int use_safe_inc_flist
= 0;
79 int want_xattr_optim
= 0;
80 int proper_seed_order
= 0;
81 int inplace_partial
= 0;
82 int do_negotiated_strings
= 0;
83 int xmit_id0_names
= 0;
85 struct name_num_item
*xattr_sum_nni
;
86 int xattr_sum_len
= 0;
88 /* These index values are for the file-list's extra-attribute array. */
89 int pathname_ndx
, depth_ndx
, atimes_ndx
, crtimes_ndx
, uid_ndx
, gid_ndx
, acls_ndx
, xattrs_ndx
, unsort_ndx
;
91 int receiver_symlink_times
= 0; /* receiver can set the time on a symlink */
92 int sender_symlink_iconv
= 0; /* sender should convert symlink content */
95 int filesfrom_convert
= 0;
98 #define MAX_NSTR_STRLEN 256
100 struct name_num_item valid_compressions_items
[] = {
102 { CPRES_ZSTD
, 0, "zstd", NULL
},
105 { CPRES_LZ4
, 0, "lz4", NULL
},
107 { CPRES_ZLIBX
, 0, "zlibx", NULL
},
108 { CPRES_ZLIB
, 0, "zlib", NULL
},
109 { CPRES_NONE
, 0, "none", NULL
},
113 struct name_num_obj valid_compressions
= {
114 "compress", NULL
, 0, 0, valid_compressions_items
117 #define CF_INC_RECURSE (1<<0)
118 #define CF_SYMLINK_TIMES (1<<1)
119 #define CF_SYMLINK_ICONV (1<<2)
120 #define CF_SAFE_FLIST (1<<3)
121 #define CF_AVOID_XATTR_OPTIM (1<<4)
122 #define CF_CHKSUM_SEED_FIX (1<<5)
123 #define CF_INPLACE_PARTIAL_DIR (1<<6)
124 #define CF_VARINT_FLIST_FLAGS (1<<7)
125 #define CF_ID0_NAMES (1<<8)
127 static const char *client_info
;
129 /* The server makes sure that if either side only supports a pre-release
130 * version of a protocol, that both sides must speak a compatible version
131 * of that protocol for it to be advertised as available. */
132 static void check_sub_protocol(void)
135 int their_protocol
, their_sub
;
136 int our_sub
= get_subprotocol_version();
138 /* client_info starts with VER.SUB string if client is a pre-release. */
139 if (!(their_protocol
= atoi(client_info
))
140 || !(dot
= strchr(client_info
, '.'))
141 || !(their_sub
= atoi(dot
+1))) {
142 #if SUBPROTOCOL_VERSION != 0
149 if (their_protocol
< protocol_version
) {
151 protocol_version
= their_protocol
- 1;
155 if (their_protocol
> protocol_version
)
156 their_sub
= 0; /* 0 == final version of older protocol */
157 if (their_sub
!= our_sub
)
161 void set_allow_inc_recurse(void)
164 client_info
= shell_cmd
? shell_cmd
: "";
165 else if (am_server
) {
167 maybe_add_e_option(buf
, sizeof buf
);
168 client_info
= *buf
? strdup(buf
+1) : ""; /* The +1 skips the leading "e". */
171 if (!recurse
|| use_qsort
)
172 allow_inc_recurse
= 0;
174 && (delete_before
|| delete_after
175 || delay_updates
|| prune_empty_dirs
))
176 allow_inc_recurse
= 0;
177 else if (am_server
&& strchr(client_info
, 'i') == NULL
)
178 allow_inc_recurse
= 0;
181 void parse_compress_choice(int final_call
)
183 if (valid_compressions
.negotiated_nni
)
184 do_compression
= valid_compressions
.negotiated_nni
->num
;
185 else if (compress_choice
) {
186 struct name_num_item
*nni
= get_nni_by_name(&valid_compressions
, compress_choice
, -1);
188 rprintf(FERROR
, "unknown compress name: %s\n", compress_choice
);
189 exit_cleanup(RERR_UNSUPPORTED
);
191 do_compression
= nni
->num
;
193 validate_choice_vs_env(NSTR_COMPRESS
, do_compression
, -1);
194 } else if (do_compression
)
195 do_compression
= CPRES_ZLIB
;
197 do_compression
= CPRES_NONE
;
199 if (do_compression
!= CPRES_NONE
&& final_call
)
200 init_compression_level(); /* There's a chance this might turn compression off! */
202 if (do_compression
== CPRES_NONE
)
203 compress_choice
= NULL
;
205 /* Snag the compression name for both write_batch's option output & the following debug output. */
206 if (valid_compressions
.negotiated_nni
)
207 compress_choice
= valid_compressions
.negotiated_nni
->name
;
208 else if (compress_choice
== NULL
) {
209 struct name_num_item
*nni
= get_nni_by_num(&valid_compressions
, do_compression
);
210 compress_choice
= nni
? nni
->name
: "UNKNOWN";
213 if (final_call
&& DEBUG_GTE(NSTR
, am_server
? 3 : 1)
214 && (do_compression
!= CPRES_NONE
|| do_compression_level
!= CLVL_NOT_SPECIFIED
)) {
215 rprintf(FINFO
, "%s%s compress: %s (level %d)\n",
216 am_server
? "Server" : "Client",
217 valid_compressions
.negotiated_nni
? " negotiated" : "",
218 compress_choice
, do_compression_level
);
222 struct name_num_item
*get_nni_by_name(struct name_num_obj
*nno
, const char *name
, int len
)
224 struct name_num_item
*nni
;
229 for (nni
= nno
->list
; nni
->name
; nni
++) {
230 if (nni
->num
== CSUM_gone
)
232 if (strncasecmp(name
, nni
->name
, len
) == 0 && nni
->name
[len
] == '\0')
239 struct name_num_item
*get_nni_by_num(struct name_num_obj
*nno
, int num
)
241 struct name_num_item
*nni
;
243 for (nni
= nno
->list
; nni
->name
; nni
++) {
251 static void init_nno_saw(struct name_num_obj
*nno
, int val
)
253 struct name_num_item
*nni
;
257 for (nni
= nno
->list
; nni
->name
; nni
++) {
258 if (nni
->num
>= nno
->saw_len
)
259 nno
->saw_len
= nni
->num
+ 1;
264 nno
->saw
= new_array0(uchar
, nno
->saw_len
);
266 /* We'll take this opportunity to set the main_nni values for duplicates. */
267 for (cnt
= 1, nni
= nno
->list
; nni
->name
; nni
++, cnt
++) {
268 if (nni
->num
== CSUM_gone
)
270 if (nno
->saw
[nni
->num
])
271 nni
->main_nni
= &nno
->list
[nno
->saw
[nni
->num
]-1];
273 nno
->saw
[nni
->num
] = cnt
;
277 memset(nno
->saw
, val
, nno
->saw_len
);
280 /* Simplify the user-provided string so that it contains valid names without any duplicates.
281 * It also sets the "saw" flags to a 1-relative count of which name was seen first. */
282 static int parse_nni_str(struct name_num_obj
*nno
, const char *from
, char *tobuf
, int tobuf_len
)
284 char *to
= tobuf
, *tok
= NULL
;
285 int saw_tok
= 0, cnt
= 0;
288 int at_space
= isSpace(from
);
292 if (!ch
|| at_space
) {
294 struct name_num_item
*nni
= get_nni_by_name(nno
, tok
, to
- tok
);
295 if (nni
&& !nno
->saw
[nni
->num
]) {
296 nno
->saw
[nni
->num
] = ++cnt
;
298 to
= tok
+ strlcpy(tok
, nni
->main_nni
->name
, tobuf_len
- (tok
- tobuf
));
299 if (to
- tobuf
>= tobuf_len
) {
305 to
= tok
- (tok
!= tobuf
);
318 if (to
- tobuf
>= tobuf_len
- 1) {
319 to
= tok
- (tok
!= tobuf
);
326 if (saw_tok
&& to
== tobuf
)
327 return strlcpy(tobuf
, "INVALID", MAX_NSTR_STRLEN
);
332 static int parse_negotiate_str(struct name_num_obj
*nno
, char *tmpbuf
)
334 struct name_num_item
*nni
, *ret
= NULL
;
335 int best
= nno
->saw_len
; /* We want best == 1 from the client list, so start with a big number. */
336 char *space
, *tok
= tmpbuf
;
338 while (*tok
== ' ') tok
++; /* Should be unneeded... */
341 if ((space
= strchr(tok
, ' ')) != NULL
)
343 nni
= get_nni_by_name(nno
, tok
, -1);
349 if (!nni
|| !nno
->saw
[nni
->num
] || best
<= nno
->saw
[nni
->num
])
352 best
= nno
->saw
[nni
->num
];
353 if (best
== 1 || am_server
) /* The server side stops at the first acceptable client choice */
359 nno
->negotiated_nni
= ret
->main_nni
? ret
->main_nni
: ret
;
365 /* This routine is always called with a tmpbuf of MAX_NSTR_STRLEN length, but the
366 * buffer may be pre-populated with a "len" length string to use OR a len of -1
367 * to tell us to read a string from the fd. */
368 static void recv_negotiate_str(int f_in
, struct name_num_obj
*nno
, char *tmpbuf
, int len
)
371 len
= read_vstring(f_in
, tmpbuf
, MAX_NSTR_STRLEN
);
373 if (DEBUG_GTE(NSTR
, am_server
? 3 : 2)) {
375 rprintf(FINFO
, "Client %s list (on server): %s\n", nno
->type
, tmpbuf
);
377 rprintf(FINFO
, "Server %s list (on client): %s\n", nno
->type
, tmpbuf
);
380 if (len
> 0 && parse_negotiate_str(nno
, tmpbuf
))
383 if (!am_server
|| !do_negotiated_strings
) {
386 rprintf(FERROR
, "Failed to negotiate a %s choice.\n", nno
->type
);
387 rprintf(FERROR
, "%s list: %s\n", am_server
? "Client" : "Server", tmpbuf
);
388 /* Recreate our original list from the saw values. This can't overflow our huge
389 * buffer because we don't have enough valid entries to get anywhere close. */
390 for (j
= 1, *cp
= '\0'; j
<= nno
->saw_len
; j
++) {
391 struct name_num_item
*nni
;
392 for (nni
= nno
->list
; nni
->name
; nni
++) {
393 if (nno
->saw
[nni
->num
] == j
) {
395 cp
+= strlcpy(cp
, nni
->name
, MAX_NSTR_STRLEN
- (cp
- tmpbuf
));
401 strlcpy(cp
, " INVALID", MAX_NSTR_STRLEN
);
402 rprintf(FERROR
, "%s list:%s\n", am_server
? "Server" : "Client", tmpbuf
);
405 exit_cleanup(RERR_UNSUPPORTED
);
408 static const char *getenv_nstr(int ntype
)
410 const char *env_str
= getenv(ntype
== NSTR_COMPRESS
? "RSYNC_COMPRESS_LIST" : "RSYNC_CHECKSUM_LIST");
412 /* When writing a batch file, we always negotiate an old-style choice. */
414 env_str
= ntype
== NSTR_COMPRESS
? "zlib" : protocol_version
>= 30 ? "md5" : "md4";
416 if (am_server
&& env_str
) {
417 char *cp
= strchr(env_str
, '&');
425 void validate_choice_vs_env(int ntype
, int num1
, int num2
)
427 struct name_num_obj
*nno
= ntype
== NSTR_COMPRESS
? &valid_compressions
: &valid_checksums
;
428 const char *list_str
= getenv_nstr(ntype
);
429 char tmpbuf
[MAX_NSTR_STRLEN
];
434 while (isSpace(list_str
)) list_str
++;
439 init_nno_saw(nno
, 0);
440 parse_nni_str(nno
, list_str
, tmpbuf
, MAX_NSTR_STRLEN
);
442 if (ntype
== NSTR_CHECKSUM
) /* If "md4" is in the env list, all the old MD4 choices are OK too. */
443 nno
->saw
[CSUM_MD4_ARCHAIC
] = nno
->saw
[CSUM_MD4_BUSTED
] = nno
->saw
[CSUM_MD4_OLD
] = nno
->saw
[CSUM_MD4
];
445 if (!nno
->saw
[num1
] || (num2
>= 0 && !nno
->saw
[num2
])) {
446 rprintf(FERROR
, "Your --%s-choice value (%s) was refused by the server.\n",
447 ntype
== NSTR_COMPRESS
? "compress" : "checksum",
448 ntype
== NSTR_COMPRESS
? compress_choice
: checksum_choice
);
449 exit_cleanup(RERR_UNSUPPORTED
);
456 /* The saw buffer is initialized and used to store ordinal values from 1 to N
457 * for the order of the args in the array. If dup_markup == '\0', duplicates
458 * are removed otherwise the char is prefixed to the duplicate term and, if it
459 * is an opening paren/bracket/brace, the matching closing char is suffixed.
460 * "none" is removed on the client side unless dup_markup != '\0'. */
461 int get_default_nno_list(struct name_num_obj
*nno
, char *to_buf
, int to_buf_len
, char dup_markup
)
463 struct name_num_item
*nni
;
464 int len
= 0, cnt
= 0;
465 char delim
= '\0', post_delim
;
467 switch (dup_markup
) {
468 case '(': post_delim
= ')'; break;
469 case '[': post_delim
= ']'; break;
470 case '{': post_delim
= '}'; break;
471 default: post_delim
= '\0'; break;
474 init_nno_saw(nno
, 0);
476 for (nni
= nno
->list
, len
= 0; nni
->name
; nni
++) {
477 if (nni
->num
== CSUM_gone
)
480 if (!dup_markup
|| nni
->main_nni
->num
== CSUM_gone
)
484 if (nni
->num
== 0 && !am_server
&& !dup_markup
)
489 to_buf
[len
++]= delim
;
492 len
+= strlcpy(to_buf
+len
, nni
->name
, to_buf_len
- len
);
493 if (len
>= to_buf_len
- 3)
494 exit_cleanup(RERR_UNSUPPORTED
); /* IMPOSSIBLE... */
496 to_buf
[len
++]= delim
;
499 nno
->saw
[nni
->num
] = ++cnt
;
505 static void send_negotiate_str(int f_out
, struct name_num_obj
*nno
, int ntype
)
507 char tmpbuf
[MAX_NSTR_STRLEN
];
508 const char *list_str
= getenv_nstr(ntype
);
511 if (list_str
&& *list_str
) {
512 init_nno_saw(nno
, 0);
513 len
= parse_nni_str(nno
, list_str
, tmpbuf
, MAX_NSTR_STRLEN
);
518 if (!list_str
|| !*list_str
)
519 len
= get_default_nno_list(nno
, tmpbuf
, MAX_NSTR_STRLEN
, '\0');
521 if (DEBUG_GTE(NSTR
, am_server
? 3 : 2)) {
523 rprintf(FINFO
, "Server %s list (on server): %s\n", nno
->type
, tmpbuf
);
525 rprintf(FINFO
, "Client %s list (on client): %s\n", nno
->type
, tmpbuf
);
528 /* Each side sends their list of valid names to the other side and then both sides
529 * pick the first name in the client's list that is also in the server's list. */
530 if (do_negotiated_strings
)
531 write_vstring(f_out
, tmpbuf
, len
);
534 static void negotiate_the_strings(int f_in
, int f_out
)
536 /* We send all the negotiation strings before we start to read them to help avoid a slow startup. */
538 init_checksum_choices();
540 if (!checksum_choice
)
541 send_negotiate_str(f_out
, &valid_checksums
, NSTR_CHECKSUM
);
543 if (do_compression
&& !compress_choice
)
544 send_negotiate_str(f_out
, &valid_compressions
, NSTR_COMPRESS
);
546 if (valid_checksums
.saw
) {
547 char tmpbuf
[MAX_NSTR_STRLEN
];
549 if (do_negotiated_strings
)
552 len
= strlcpy(tmpbuf
, protocol_version
>= 30 ? "md5" : "md4", MAX_NSTR_STRLEN
);
553 recv_negotiate_str(f_in
, &valid_checksums
, tmpbuf
, len
);
556 if (valid_compressions
.saw
) {
557 char tmpbuf
[MAX_NSTR_STRLEN
];
559 if (do_negotiated_strings
)
562 len
= strlcpy(tmpbuf
, "zlib", MAX_NSTR_STRLEN
);
563 recv_negotiate_str(f_in
, &valid_compressions
, tmpbuf
, len
);
566 /* If the other side is too old to negotiate, the above steps just made sure that
567 * the env didn't disallow the old algorithm. Mark things as non-negotiated. */
568 if (!do_negotiated_strings
)
569 valid_checksums
.negotiated_nni
= valid_compressions
.negotiated_nni
= NULL
;
572 void setup_protocol(int f_out
,int f_in
)
574 assert(file_extra_cnt
== 0);
575 assert(EXTRA64_CNT
== 2 || EXTRA64_CNT
== 1);
577 /* All int64 values must be set first so that they are guaranteed to be
578 * aligned for direct int64-pointer memory access. */
580 atimes_ndx
= (file_extra_cnt
+= EXTRA64_CNT
);
581 if (preserve_crtimes
)
582 crtimes_ndx
= (file_extra_cnt
+= EXTRA64_CNT
);
583 if (am_sender
) /* This is most likely in the file_extras64 union as well. */
584 pathname_ndx
= (file_extra_cnt
+= PTR_EXTRA_CNT
);
586 depth_ndx
= ++file_extra_cnt
;
588 uid_ndx
= ++file_extra_cnt
;
590 gid_ndx
= ++file_extra_cnt
;
591 if (preserve_acls
&& !am_sender
)
592 acls_ndx
= ++file_extra_cnt
;
594 xattrs_ndx
= ++file_extra_cnt
;
597 set_allow_inc_recurse();
599 if (remote_protocol
== 0) {
600 if (am_server
&& !local_server
)
601 check_sub_protocol();
603 write_int(f_out
, protocol_version
);
604 remote_protocol
= read_int(f_in
);
605 if (protocol_version
> remote_protocol
)
606 protocol_version
= remote_protocol
;
608 if (read_batch
&& remote_protocol
> protocol_version
) {
609 rprintf(FERROR
, "The protocol version in the batch file is too new (%d > %d).\n",
610 remote_protocol
, protocol_version
);
611 exit_cleanup(RERR_PROTOCOL
);
614 if (DEBUG_GTE(PROTO
, 1)) {
615 rprintf(FINFO
, "(%s) Protocol versions: remote=%d, negotiated=%d\n",
616 am_server
? "Server" : "Client", remote_protocol
, protocol_version
);
618 if (remote_protocol
< MIN_PROTOCOL_VERSION
619 || remote_protocol
> MAX_PROTOCOL_VERSION
) {
620 rprintf(FERROR
,"protocol version mismatch -- is your shell clean?\n");
621 rprintf(FERROR
,"(see the rsync manpage for an explanation)\n");
622 exit_cleanup(RERR_PROTOCOL
);
624 if (remote_protocol
< OLD_PROTOCOL_VERSION
) {
625 rprintf(FINFO
,"%s is very old version of rsync, upgrade recommended.\n",
626 am_server
? "Client" : "Server");
628 if (protocol_version
< MIN_PROTOCOL_VERSION
) {
629 rprintf(FERROR
, "--protocol must be at least %d on the %s.\n",
630 MIN_PROTOCOL_VERSION
, am_server
? "Server" : "Client");
631 exit_cleanup(RERR_PROTOCOL
);
633 if (protocol_version
> PROTOCOL_VERSION
) {
634 rprintf(FERROR
, "--protocol must be no more than %d on the %s.\n",
635 PROTOCOL_VERSION
, am_server
? "Server" : "Client");
636 exit_cleanup(RERR_PROTOCOL
);
641 if (!saw_stderr_opt
&& protocol_version
<= 28 && am_server
)
642 msgs2stderr
= 0; /* The client side may not have stderr setup for us. */
644 #ifndef SUPPORT_PREALLOCATION
645 if (preallocate_files
&& !am_sender
) {
646 rprintf(FERROR
, "preallocation is not supported on this %s\n",
647 am_server
? "Server" : "Client");
648 exit_cleanup(RERR_SYNTAX
);
652 if (protocol_version
< 30) {
653 if (append_mode
== 1)
655 if (preserve_acls
&& !local_server
) {
657 "--acls requires protocol 30 or higher"
658 " (negotiated %d).\n",
660 exit_cleanup(RERR_PROTOCOL
);
662 if (preserve_xattrs
&& !local_server
) {
664 "--xattrs requires protocol 30 or higher"
665 " (negotiated %d).\n",
667 exit_cleanup(RERR_PROTOCOL
);
671 if (delete_mode
&& !(delete_before
+delete_during
+delete_after
)) {
672 if (protocol_version
< 30)
678 if (protocol_version
< 29) {
681 "--fuzzy requires protocol 29 or higher"
682 " (negotiated %d).\n",
684 exit_cleanup(RERR_PROTOCOL
);
687 if (basis_dir_cnt
&& inplace
) {
689 "%s with --inplace requires protocol 29 or higher"
690 " (negotiated %d).\n",
691 alt_dest_opt(0), protocol_version
);
692 exit_cleanup(RERR_PROTOCOL
);
695 if (basis_dir_cnt
> 1) {
697 "Using more than one %s option requires protocol"
698 " 29 or higher (negotiated %d).\n",
699 alt_dest_opt(0), protocol_version
);
700 exit_cleanup(RERR_PROTOCOL
);
703 if (prune_empty_dirs
) {
705 "--prune-empty-dirs requires protocol 29 or higher"
706 " (negotiated %d).\n",
708 exit_cleanup(RERR_PROTOCOL
);
710 } else if (protocol_version
>= 30) {
712 compat_flags
= allow_inc_recurse
? CF_INC_RECURSE
: 0;
713 #ifdef CAN_SET_SYMLINK_TIMES
714 compat_flags
|= CF_SYMLINK_TIMES
;
717 compat_flags
|= CF_SYMLINK_ICONV
;
719 if (strchr(client_info
, 'f') != NULL
)
720 compat_flags
|= CF_SAFE_FLIST
;
721 if (strchr(client_info
, 'x') != NULL
)
722 compat_flags
|= CF_AVOID_XATTR_OPTIM
;
723 if (strchr(client_info
, 'C') != NULL
)
724 compat_flags
|= CF_CHKSUM_SEED_FIX
;
725 if (strchr(client_info
, 'I') != NULL
)
726 compat_flags
|= CF_INPLACE_PARTIAL_DIR
;
727 if (strchr(client_info
, 'u') != NULL
)
728 compat_flags
|= CF_ID0_NAMES
;
729 if (strchr(client_info
, 'v') != NULL
) {
730 do_negotiated_strings
= 1;
731 compat_flags
|= CF_VARINT_FLIST_FLAGS
;
733 if (strchr(client_info
, 'V') != NULL
) { /* Support a pre-release 'V' that got superseded */
735 compat_flags
|= CF_VARINT_FLIST_FLAGS
;
736 write_byte(f_out
, compat_flags
);
738 write_varint(f_out
, compat_flags
);
739 } else { /* read_varint() is compatible with the older write_byte() when the 0x80 bit isn't on. */
740 compat_flags
= read_varint(f_in
);
741 if (compat_flags
& CF_VARINT_FLIST_FLAGS
)
742 do_negotiated_strings
= 1;
744 /* The inc_recurse var MUST be set to 0 or 1. */
745 inc_recurse
= compat_flags
& CF_INC_RECURSE
? 1 : 0;
746 want_xattr_optim
= protocol_version
>= 31 && !(compat_flags
& CF_AVOID_XATTR_OPTIM
);
747 proper_seed_order
= compat_flags
& CF_CHKSUM_SEED_FIX
? 1 : 0;
748 xfer_flags_as_varint
= compat_flags
& CF_VARINT_FLIST_FLAGS
? 1 : 0;
749 xmit_id0_names
= compat_flags
& CF_ID0_NAMES
? 1 : 0;
750 if (!xfer_flags_as_varint
&& preserve_crtimes
) {
751 fprintf(stderr
, "Both rsync versions must be at least 3.2.0 for --crtimes.\n");
752 exit_cleanup(RERR_PROTOCOL
);
755 receiver_symlink_times
= am_server
756 ? strchr(client_info
, 'L') != NULL
757 : !!(compat_flags
& CF_SYMLINK_TIMES
);
759 #ifdef CAN_SET_SYMLINK_TIMES
761 receiver_symlink_times
= 1;
764 sender_symlink_iconv
= iconv_opt
&& (am_server
765 ? strchr(client_info
, 's') != NULL
766 : !!(compat_flags
& CF_SYMLINK_ICONV
));
768 if (inc_recurse
&& !allow_inc_recurse
) {
769 /* This should only be able to happen in a batch. */
771 "Incompatible options specified for inc-recursive %s.\n",
772 read_batch
? "batch file" : "connection");
773 exit_cleanup(RERR_SYNTAX
);
775 use_safe_inc_flist
= (compat_flags
& CF_SAFE_FLIST
) || protocol_version
>= 31;
776 need_messages_from_generator
= 1;
777 if (compat_flags
& CF_INPLACE_PARTIAL_DIR
)
779 #ifdef CAN_SET_SYMLINK_TIMES
780 } else if (!am_sender
) {
781 receiver_symlink_times
= 1;
786 do_negotiated_strings
= 0;
788 if (need_unsorted_flist
&& (!am_sender
|| inc_recurse
))
789 unsort_ndx
= ++file_extra_cnt
;
791 if (partial_dir
&& *partial_dir
!= '/' && (!am_server
|| local_server
)) {
792 int rflags
= FILTRULE_NO_PREFIXES
| FILTRULE_DIRECTORY
;
793 if (!am_sender
|| protocol_version
>= 30)
794 rflags
|= FILTRULE_PERISHABLE
;
795 parse_filter_str(&filter_list
, partial_dir
, rule_template(rflags
), 0);
800 if (protect_args
&& files_from
) {
802 filesfrom_convert
= filesfrom_host
&& ic_send
!= (iconv_t
)-1;
804 filesfrom_convert
= !filesfrom_host
&& ic_recv
!= (iconv_t
)-1;
808 negotiate_the_strings(f_in
, f_out
);
812 checksum_seed
= time(NULL
) ^ (getpid() << 6);
813 write_int(f_out
, checksum_seed
);
815 checksum_seed
= read_int(f_in
);
818 parse_checksum_choice(1); /* Sets file_sum_nni & xfer_sum_nni */
819 parse_compress_choice(1); /* Sets do_compression */
821 /* TODO in the future allow this algorithm to be chosen somehow, but it can't get too
822 * long or the size starts to cause a problem in the xattr abbrev/non-abbrev code. */
823 xattr_sum_nni
= parse_csum_name(NULL
, 0);
824 xattr_sum_len
= csum_len_for_type(xattr_sum_nni
->num
, 0);
826 if (write_batch
&& !am_server
)
827 write_batch_shell_file();
832 void output_daemon_greeting(int f_out
, int am_client
)
834 char tmpbuf
[MAX_NSTR_STRLEN
];
835 int our_sub
= get_subprotocol_version();
837 init_checksum_choices();
839 get_default_nno_list(&valid_auth_checksums
, tmpbuf
, MAX_NSTR_STRLEN
, '\0');
841 io_printf(f_out
, "@RSYNCD: %d.%d %s\n", protocol_version
, our_sub
, tmpbuf
);
843 if (am_client
&& DEBUG_GTE(NSTR
, 2))
844 rprintf(FINFO
, "Client %s list (on client): %s\n", valid_auth_checksums
.type
, tmpbuf
);
847 void negotiate_daemon_auth(int f_out
, int am_client
)
849 char tmpbuf
[MAX_NSTR_STRLEN
];
850 int save_am_server
= am_server
;
856 if (daemon_auth_choices
)
857 strlcpy(tmpbuf
, daemon_auth_choices
, MAX_NSTR_STRLEN
);
859 strlcpy(tmpbuf
, protocol_version
>= 30 ? "md5" : "md4", MAX_NSTR_STRLEN
);
864 recv_negotiate_str(-1, &valid_auth_checksums
, tmpbuf
, strlen(tmpbuf
));
865 if (DEBUG_GTE(NSTR
, 1)) {
866 rprintf(FINFO
, "Client negotiated %s: %s\n", valid_auth_checksums
.type
,
867 valid_auth_checksums
.negotiated_nni
->name
);
870 if (!parse_negotiate_str(&valid_auth_checksums
, tmpbuf
)) {
871 get_default_nno_list(&valid_auth_checksums
, tmpbuf
, MAX_NSTR_STRLEN
, '\0');
872 io_printf(f_out
, "@ERROR: your client does not support one of our daemon-auth checksums: %s\n",
874 exit_cleanup(RERR_UNSUPPORTED
);
877 am_server
= save_am_server
;
878 if (md4_is_old
&& valid_auth_checksums
.negotiated_nni
->num
== CSUM_MD4
) {
879 valid_auth_checksums
.negotiated_nni
->num
= CSUM_MD4_OLD
;
880 valid_auth_checksums
.negotiated_nni
->flags
= 0;
884 int get_subprotocol_version()
886 #if SUBPROTOCOL_VERSION != 0
887 return protocol_version
< PROTOCOL_VERSION
? 0 : SUBPROTOCOL_VERSION
;