Annotation of embedaddon/rsync/compat.c, revision 1.1.1.4
1.1 misho 1: /*
2: * Compatibility routines for older rsync protocol versions.
3: *
4: * Copyright (C) Andrew Tridgell 1996
5: * Copyright (C) Paul Mackerras 1996
1.1.1.4 ! misho 6: * Copyright (C) 2004-2020 Wayne Davison
1.1 misho 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"
1.1.1.4 ! misho 23: #include "itypes.h"
1.1 misho 24:
25: extern int am_server;
26: extern int am_sender;
27: extern int local_server;
28: extern int inplace;
29: extern int recurse;
30: extern int use_qsort;
31: extern int allow_inc_recurse;
1.1.1.2 misho 32: extern int preallocate_files;
1.1 misho 33: extern int append_mode;
34: extern int fuzzy_basis;
35: extern int read_batch;
1.1.1.4 ! misho 36: extern int write_batch;
1.1 misho 37: extern int delay_updates;
38: extern int checksum_seed;
39: extern int basis_dir_cnt;
40: extern int prune_empty_dirs;
41: extern int protocol_version;
1.1.1.4 ! misho 42: extern int detect_renamed;
1.1 misho 43: extern int protect_args;
44: extern int preserve_uid;
45: extern int preserve_gid;
1.1.1.4 ! misho 46: extern int preserve_atimes;
! 47: extern int preserve_crtimes;
1.1 misho 48: extern int preserve_acls;
49: extern int preserve_xattrs;
1.1.1.4 ! misho 50: extern int preserve_fileflags;
! 51: extern int xfer_flags_as_varint;
1.1 misho 52: extern int need_messages_from_generator;
53: extern int delete_mode, delete_before, delete_during, delete_after;
1.1.1.4 ! misho 54: extern int do_compression;
! 55: extern int do_compression_level;
1.1 misho 56: extern char *shell_cmd;
57: extern char *partial_dir;
58: extern char *files_from;
59: extern char *filesfrom_host;
1.1.1.4 ! misho 60: extern const char *checksum_choice;
! 61: extern const char *compress_choice;
1.1.1.2 misho 62: extern filter_rule_list filter_list;
1.1 misho 63: extern int need_unsorted_flist;
64: #ifdef ICONV_OPTION
65: extern iconv_t ic_send, ic_recv;
66: extern char *iconv_opt;
67: #endif
1.1.1.4 ! misho 68: extern struct name_num_obj valid_checksums;
! 69:
! 70: int remote_protocol = 0;
! 71: int file_extra_cnt = 0; /* count of file-list extras that everyone gets */
! 72: int inc_recurse = 0;
! 73: int compat_flags = 0;
! 74: int use_safe_inc_flist = 0;
! 75: int want_xattr_optim = 0;
! 76: int proper_seed_order = 0;
! 77: int inplace_partial = 0;
! 78: int do_negotiated_strings = 0;
! 79: int xmit_id0_names = 0;
1.1 misho 80:
81: /* These index values are for the file-list's extra-attribute array. */
1.1.1.4 ! misho 82: int pathname_ndx, depth_ndx, atimes_ndx, crtimes_ndx, uid_ndx, gid_ndx, fileflags_ndx, acls_ndx, xattrs_ndx, unsort_ndx;
1.1 misho 83:
84: int receiver_symlink_times = 0; /* receiver can set the time on a symlink */
85: int sender_symlink_iconv = 0; /* sender should convert symlink content */
86:
87: #ifdef ICONV_OPTION
88: int filesfrom_convert = 0;
89: #endif
90:
1.1.1.4 ! misho 91: #define MAX_NSTR_STRLEN 256
! 92:
! 93: struct name_num_obj valid_compressions = {
! 94: "compress", NULL, NULL, 0, 0, {
! 95: #ifdef SUPPORT_ZSTD
! 96: { CPRES_ZSTD, "zstd", NULL },
! 97: #endif
! 98: #ifdef SUPPORT_LZ4
! 99: { CPRES_LZ4, "lz4", NULL },
! 100: #endif
! 101: { CPRES_ZLIBX, "zlibx", NULL },
! 102: { CPRES_ZLIB, "zlib", NULL },
! 103: { CPRES_NONE, "none", NULL },
! 104: { 0, NULL, NULL }
! 105: }
! 106: };
! 107:
1.1 misho 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)
1.1.1.3 misho 112: #define CF_AVOID_XATTR_OPTIM (1<<4)
113: #define CF_CHKSUM_SEED_FIX (1<<5)
1.1.1.4 ! misho 114: #define CF_INPLACE_PARTIAL_DIR (1<<6)
! 115: #define CF_VARINT_FLIST_FLAGS (1<<7)
! 116: #define CF_ID0_NAMES (1<<8)
1.1 misho 117:
118: static const char *client_info;
119:
120: /* The server makes sure that if either side only supports a pre-release
121: * version of a protocol, that both sides must speak a compatible version
122: * of that protocol for it to be advertised as available. */
123: static void check_sub_protocol(void)
124: {
125: char *dot;
126: int their_protocol, their_sub;
127: #if SUBPROTOCOL_VERSION != 0
128: int our_sub = protocol_version < PROTOCOL_VERSION ? 0 : SUBPROTOCOL_VERSION;
129: #else
130: int our_sub = 0;
131: #endif
132:
133: /* client_info starts with VER.SUB string if client is a pre-release. */
134: if (!(their_protocol = atoi(client_info))
135: || !(dot = strchr(client_info, '.'))
136: || !(their_sub = atoi(dot+1))) {
137: #if SUBPROTOCOL_VERSION != 0
138: if (our_sub)
139: protocol_version--;
140: #endif
141: return;
142: }
143:
144: if (their_protocol < protocol_version) {
145: if (their_sub)
146: protocol_version = their_protocol - 1;
147: return;
148: }
149:
150: if (their_protocol > protocol_version)
151: their_sub = 0; /* 0 == final version of older protocol */
152: if (their_sub != our_sub)
153: protocol_version--;
154: }
155:
156: void set_allow_inc_recurse(void)
157: {
158: client_info = shell_cmd ? shell_cmd : "";
159:
160: if (!recurse || use_qsort)
161: allow_inc_recurse = 0;
162: else if (!am_sender
163: && (delete_before || delete_after
1.1.1.4 ! misho 164: || detect_renamed
1.1 misho 165: || delay_updates || prune_empty_dirs))
166: allow_inc_recurse = 0;
167: else if (am_server && !local_server
168: && (strchr(client_info, 'i') == NULL))
169: allow_inc_recurse = 0;
170: }
171:
1.1.1.4 ! misho 172: void parse_compress_choice(int final_call)
! 173: {
! 174: if (valid_compressions.negotiated_name)
! 175: do_compression = 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: do_compression = nni->num;
! 183: if (am_server)
! 184: validate_choice_vs_env(NSTR_COMPRESS, do_compression, -1);
! 185: } else if (do_compression)
! 186: do_compression = CPRES_ZLIB;
! 187: else
! 188: do_compression = CPRES_NONE;
! 189:
! 190: if (do_compression != CPRES_NONE && final_call)
! 191: init_compression_level(); /* There's a chance this might turn compression off! */
! 192:
! 193: if (do_compression == CPRES_NONE)
! 194: compress_choice = NULL;
! 195:
! 196: /* Snag the compression name for both write_batch's option output & the following debug output. */
! 197: if (valid_compressions.negotiated_name)
! 198: compress_choice = valid_compressions.negotiated_name;
! 199: else if (compress_choice == NULL) {
! 200: struct name_num_item *nni = get_nni_by_num(&valid_compressions, do_compression);
! 201: compress_choice = nni ? nni->name : "UNKNOWN";
! 202: }
! 203:
! 204: if (final_call && DEBUG_GTE(NSTR, am_server ? 3 : 1)
! 205: && (do_compression != CPRES_NONE || do_compression_level != CLVL_NOT_SPECIFIED)) {
! 206: rprintf(FINFO, "%s%s compress: %s (level %d)\n",
! 207: am_server ? "Server" : "Client",
! 208: valid_compressions.negotiated_name ? " negotiated" : "",
! 209: compress_choice, do_compression_level);
! 210: }
! 211: }
! 212:
! 213: struct name_num_item *get_nni_by_name(struct name_num_obj *nno, const char *name, int len)
! 214: {
! 215: struct name_num_item *nni;
! 216:
! 217: if (len < 0)
! 218: len = strlen(name);
! 219:
! 220: for (nni = nno->list; nni->name; nni++) {
! 221: if (strncasecmp(name, nni->name, len) == 0 && nni->name[len] == '\0')
! 222: return nni;
! 223: }
! 224:
! 225: return NULL;
! 226: }
! 227:
! 228: struct name_num_item *get_nni_by_num(struct name_num_obj *nno, int num)
! 229: {
! 230: struct name_num_item *nni;
! 231:
! 232: for (nni = nno->list; nni->name; nni++) {
! 233: if (num == nni->num)
! 234: return nni;
! 235: }
! 236:
! 237: return NULL;
! 238: }
! 239:
! 240: static void init_nno_saw(struct name_num_obj *nno, int val)
! 241: {
! 242: struct name_num_item *nni;
! 243: int cnt;
! 244:
! 245: if (!nno->saw_len) {
! 246: for (nni = nno->list; nni->name; nni++) {
! 247: if (nni->num >= nno->saw_len)
! 248: nno->saw_len = nni->num + 1;
! 249: }
! 250: }
! 251:
! 252: if (!nno->saw) {
! 253: nno->saw = new_array0(uchar, nno->saw_len);
! 254:
! 255: /* We'll take this opportunity to make sure that the main_name values are set right. */
! 256: for (cnt = 1, nni = nno->list; nni->name; nni++, cnt++) {
! 257: if (nno->saw[nni->num])
! 258: nni->main_name = nno->list[nno->saw[nni->num]-1].name;
! 259: else
! 260: nno->saw[nni->num] = cnt;
! 261: }
! 262: }
! 263:
! 264: memset(nno->saw, val, nno->saw_len);
! 265: }
! 266:
! 267: /* Simplify the user-provided string so that it contains valid names without any duplicates.
! 268: * It also sets the "saw" flags to a 1-relative count of which name was seen first. */
! 269: static int parse_nni_str(struct name_num_obj *nno, const char *from, char *tobuf, int tobuf_len)
! 270: {
! 271: char *to = tobuf, *tok = NULL;
! 272: int saw_tok = 0, cnt = 0;
! 273:
! 274: while (1) {
! 275: int at_space = isSpace(from);
! 276: char ch = *from++;
! 277: if (ch == '&')
! 278: ch = '\0';
! 279: if (!ch || at_space) {
! 280: if (tok) {
! 281: struct name_num_item *nni = get_nni_by_name(nno, tok, to - tok);
! 282: if (nni && !nno->saw[nni->num]) {
! 283: nno->saw[nni->num] = ++cnt;
! 284: if (nni->main_name) {
! 285: to = tok + strlcpy(tok, nni->main_name, tobuf_len - (tok - tobuf));
! 286: if (to - tobuf >= tobuf_len) {
! 287: to = tok - 1;
! 288: break;
! 289: }
! 290: }
! 291: } else
! 292: to = tok - (tok != tobuf);
! 293: saw_tok = 1;
! 294: tok = NULL;
! 295: }
! 296: if (!ch)
! 297: break;
! 298: continue;
! 299: }
! 300: if (!tok) {
! 301: if (to != tobuf)
! 302: *to++ = ' ';
! 303: tok = to;
! 304: }
! 305: if (to - tobuf >= tobuf_len - 1) {
! 306: to = tok - (tok != tobuf);
! 307: break;
! 308: }
! 309: *to++ = ch;
! 310: }
! 311: *to = '\0';
! 312:
! 313: if (saw_tok && to == tobuf)
! 314: return strlcpy(tobuf, "INVALID", MAX_NSTR_STRLEN);
! 315:
! 316: return to - tobuf;
! 317: }
! 318:
! 319: /* This routine is always called with a tmpbuf of MAX_NSTR_STRLEN length, but the
! 320: * buffer may be pre-populated with a "len" length string to use OR a len of -1
! 321: * to tell us to read a string from the fd. */
! 322: static void recv_negotiate_str(int f_in, struct name_num_obj *nno, char *tmpbuf, int len)
! 323: {
! 324: struct name_num_item *ret = NULL;
! 325:
! 326: if (len < 0)
! 327: len = read_vstring(f_in, tmpbuf, MAX_NSTR_STRLEN);
! 328:
! 329: if (DEBUG_GTE(NSTR, am_server ? 3 : 2)) {
! 330: if (am_server)
! 331: rprintf(FINFO, "Client %s list (on server): %s\n", nno->type, tmpbuf);
! 332: else
! 333: rprintf(FINFO, "Server %s list (on client): %s\n", nno->type, tmpbuf);
! 334: }
! 335:
! 336: if (len > 0) {
! 337: struct name_num_item *nni;
! 338: int best = nno->saw_len; /* We want best == 1 from the client list, so start with a big number. */
! 339: char *space, *tok = tmpbuf;
! 340: while (tok) {
! 341: while (*tok == ' ') tok++; /* Should be unneeded... */
! 342: if (!*tok)
! 343: break;
! 344: if ((space = strchr(tok, ' ')) != NULL)
! 345: *space = '\0';
! 346: nni = get_nni_by_name(nno, tok, -1);
! 347: if (space) {
! 348: *space = ' ';
! 349: tok = space + 1;
! 350: } else
! 351: tok = NULL;
! 352: if (!nni || !nno->saw[nni->num] || best <= nno->saw[nni->num])
! 353: continue;
! 354: ret = nni;
! 355: best = nno->saw[nni->num];
! 356: if (best == 1 || am_server) /* The server side stops at the first acceptable client choice */
! 357: break;
! 358: }
! 359: if (ret) {
! 360: free(nno->saw);
! 361: nno->saw = NULL;
! 362: nno->negotiated_name = ret->main_name ? ret->main_name : ret->name;
! 363: nno->negotiated_num = ret->num;
! 364: return;
! 365: }
! 366: }
! 367:
! 368: if (!am_server || !do_negotiated_strings) {
! 369: char *cp = tmpbuf;
! 370: int j;
! 371: rprintf(FERROR, "Failed to negotiate a %s choice.\n", nno->type);
! 372: rprintf(FERROR, "%s list: %s\n", am_server ? "Client" : "Server", tmpbuf);
! 373: /* Recreate our original list from the saw values. This can't overflow our huge
! 374: * buffer because we don't have enough valid entries to get anywhere close. */
! 375: for (j = 1, *cp = '\0'; j <= nno->saw_len; j++) {
! 376: struct name_num_item *nni;
! 377: for (nni = nno->list; nni->name; nni++) {
! 378: if (nno->saw[nni->num] == j) {
! 379: *cp++ = ' ';
! 380: cp += strlcpy(cp, nni->name, MAX_NSTR_STRLEN - (cp - tmpbuf));
! 381: break;
! 382: }
! 383: }
! 384: }
! 385: if (!*tmpbuf)
! 386: strlcpy(cp, " INVALID", MAX_NSTR_STRLEN);
! 387: rprintf(FERROR, "%s list:%s\n", am_server ? "Server" : "Client", tmpbuf);
! 388: }
! 389:
! 390: exit_cleanup(RERR_UNSUPPORTED);
! 391: }
! 392:
! 393: static const char *getenv_nstr(int ntype)
! 394: {
! 395: const char *env_str = getenv(ntype == NSTR_COMPRESS ? "RSYNC_COMPRESS_LIST" : "RSYNC_CHECKSUM_LIST");
! 396:
! 397: /* When writing a batch file, we always negotiate an old-style choice. */
! 398: if (write_batch)
! 399: env_str = ntype == NSTR_COMPRESS ? "zlib" : protocol_version >= 30 ? "md5" : "md4";
! 400:
! 401: if (am_server && env_str) {
! 402: char *cp = strchr(env_str, '&');
! 403: if (cp)
! 404: env_str = cp + 1;
! 405: }
! 406:
! 407: return env_str;
! 408: }
! 409:
! 410: void validate_choice_vs_env(int ntype, int num1, int num2)
! 411: {
! 412: struct name_num_obj *nno = ntype == NSTR_COMPRESS ? &valid_compressions : &valid_checksums;
! 413: const char *list_str = getenv_nstr(ntype);
! 414: char tmpbuf[MAX_NSTR_STRLEN];
! 415:
! 416: if (!list_str)
! 417: return;
! 418:
! 419: while (isSpace(list_str)) list_str++;
! 420:
! 421: if (!*list_str)
! 422: return;
! 423:
! 424: init_nno_saw(nno, 0);
! 425: parse_nni_str(nno, list_str, tmpbuf, MAX_NSTR_STRLEN);
! 426:
! 427: if (ntype == NSTR_CHECKSUM) /* If "md4" is in the env list, all the old MD4 choices are OK too. */
! 428: nno->saw[CSUM_MD4_ARCHAIC] = nno->saw[CSUM_MD4_BUSTED] = nno->saw[CSUM_MD4_OLD] = nno->saw[CSUM_MD4];
! 429:
! 430: if (!nno->saw[num1] || (num2 >= 0 && !nno->saw[num2])) {
! 431: rprintf(FERROR, "Your --%s-choice value (%s) was refused by the server.\n",
! 432: ntype == NSTR_COMPRESS ? "compress" : "checksum",
! 433: ntype == NSTR_COMPRESS ? compress_choice : checksum_choice);
! 434: exit_cleanup(RERR_UNSUPPORTED);
! 435: }
! 436:
! 437: free(nno->saw);
! 438: nno->saw = NULL;
! 439: }
! 440:
! 441: /* The saw buffer is initialized and used to store ordinal values from 1 to N
! 442: * for the order of the args in the array. If dup_markup == '\0', duplicates
! 443: * are removed otherwise the char is prefixed to the duplicate term and, if it
! 444: * is an opening paren/bracket/brace, the matching closing char is suffixed.
! 445: * "none" is removed on the client side unless dup_markup != '\0'. */
! 446: int get_default_nno_list(struct name_num_obj *nno, char *to_buf, int to_buf_len, char dup_markup)
! 447: {
! 448: struct name_num_item *nni;
! 449: int len = 0, cnt = 0;
! 450: char delim = '\0', post_delim;
! 451:
! 452: switch (dup_markup) {
! 453: case '(': post_delim = ')'; break;
! 454: case '[': post_delim = ']'; break;
! 455: case '{': post_delim = '}'; break;
! 456: default: post_delim = '\0'; break;
! 457: }
! 458:
! 459: init_nno_saw(nno, 0);
! 460:
! 461: for (nni = nno->list, len = 0; nni->name; nni++) {
! 462: if (nni->main_name) {
! 463: if (!dup_markup)
! 464: continue;
! 465: delim = dup_markup;
! 466: }
! 467: if (nni->num == 0 && !am_server && !dup_markup)
! 468: continue;
! 469: if (len)
! 470: to_buf[len++]= ' ';
! 471: if (delim) {
! 472: to_buf[len++]= delim;
! 473: delim = post_delim;
! 474: }
! 475: len += strlcpy(to_buf+len, nni->name, to_buf_len - len);
! 476: if (len >= to_buf_len - 3)
! 477: exit_cleanup(RERR_UNSUPPORTED); /* IMPOSSIBLE... */
! 478: if (delim) {
! 479: to_buf[len++]= delim;
! 480: delim = '\0';
! 481: }
! 482: nno->saw[nni->num] = ++cnt;
! 483: }
! 484:
! 485: return len;
! 486: }
! 487:
! 488: static void send_negotiate_str(int f_out, struct name_num_obj *nno, int ntype)
! 489: {
! 490: char tmpbuf[MAX_NSTR_STRLEN];
! 491: const char *list_str = getenv_nstr(ntype);
! 492: int len;
! 493:
! 494: if (list_str && *list_str) {
! 495: init_nno_saw(nno, 0);
! 496: len = parse_nni_str(nno, list_str, tmpbuf, MAX_NSTR_STRLEN);
! 497: list_str = tmpbuf;
! 498: } else
! 499: list_str = NULL;
! 500:
! 501: if (!list_str || !*list_str)
! 502: len = get_default_nno_list(nno, tmpbuf, MAX_NSTR_STRLEN, '\0');
! 503:
! 504: if (DEBUG_GTE(NSTR, am_server ? 3 : 2)) {
! 505: if (am_server)
! 506: rprintf(FINFO, "Server %s list (on server): %s\n", nno->type, tmpbuf);
! 507: else
! 508: rprintf(FINFO, "Client %s list (on client): %s\n", nno->type, tmpbuf);
! 509: }
! 510:
! 511: /* Each side sends their list of valid names to the other side and then both sides
! 512: * pick the first name in the client's list that is also in the server's list. */
! 513: if (do_negotiated_strings)
! 514: write_vstring(f_out, tmpbuf, len);
! 515: }
! 516:
! 517: static void negotiate_the_strings(int f_in, int f_out)
! 518: {
! 519: /* We send all the negotiation strings before we start to read them to help avoid a slow startup. */
! 520:
! 521: if (!checksum_choice)
! 522: send_negotiate_str(f_out, &valid_checksums, NSTR_CHECKSUM);
! 523:
! 524: if (do_compression && !compress_choice)
! 525: send_negotiate_str(f_out, &valid_compressions, NSTR_COMPRESS);
! 526:
! 527: if (valid_checksums.saw) {
! 528: char tmpbuf[MAX_NSTR_STRLEN];
! 529: int len;
! 530: if (do_negotiated_strings)
! 531: len = -1;
! 532: else
! 533: len = strlcpy(tmpbuf, protocol_version >= 30 ? "md5" : "md4", MAX_NSTR_STRLEN);
! 534: recv_negotiate_str(f_in, &valid_checksums, tmpbuf, len);
! 535: }
! 536:
! 537: if (valid_compressions.saw) {
! 538: char tmpbuf[MAX_NSTR_STRLEN];
! 539: int len;
! 540: if (do_negotiated_strings)
! 541: len = -1;
! 542: else
! 543: len = strlcpy(tmpbuf, "zlib", MAX_NSTR_STRLEN);
! 544: recv_negotiate_str(f_in, &valid_compressions, tmpbuf, len);
! 545: }
! 546:
! 547: /* If the other side is too old to negotiate, the above steps just made sure that
! 548: * the env didn't disallow the old algorithm. Mark things as non-negotiated. */
! 549: if (!do_negotiated_strings)
! 550: valid_checksums.negotiated_name = valid_compressions.negotiated_name = NULL;
! 551: }
! 552:
1.1 misho 553: void setup_protocol(int f_out,int f_in)
554: {
1.1.1.4 ! misho 555: assert(file_extra_cnt == 0);
! 556: assert(EXTRA64_CNT == 2 || EXTRA64_CNT == 1);
! 557:
! 558: /* All int64 values must be set first so that they are guaranteed to be
! 559: * aligned for direct int64-pointer memory access. */
! 560: if (preserve_atimes)
! 561: atimes_ndx = (file_extra_cnt += EXTRA64_CNT);
! 562: if (preserve_crtimes)
! 563: crtimes_ndx = (file_extra_cnt += EXTRA64_CNT);
! 564: if (am_sender) /* This is most likely in the in64 union as well. */
! 565: pathname_ndx = (file_extra_cnt += PTR_EXTRA_CNT);
1.1 misho 566: else
1.1.1.4 ! misho 567: depth_ndx = ++file_extra_cnt;
1.1 misho 568: if (preserve_uid)
569: uid_ndx = ++file_extra_cnt;
570: if (preserve_gid)
571: gid_ndx = ++file_extra_cnt;
1.1.1.4 ! misho 572: if (preserve_fileflags || (force_change && !am_sender))
! 573: fileflags_ndx = ++file_extra_cnt;
1.1 misho 574: if (preserve_acls && !am_sender)
575: acls_ndx = ++file_extra_cnt;
576: if (preserve_xattrs)
577: xattrs_ndx = ++file_extra_cnt;
578:
579: if (am_server)
580: set_allow_inc_recurse();
581:
582: if (remote_protocol == 0) {
583: if (am_server && !local_server)
584: check_sub_protocol();
585: if (!read_batch)
586: write_int(f_out, protocol_version);
587: remote_protocol = read_int(f_in);
588: if (protocol_version > remote_protocol)
589: protocol_version = remote_protocol;
590: }
591: if (read_batch && remote_protocol > protocol_version) {
592: rprintf(FERROR, "The protocol version in the batch file is too new (%d > %d).\n",
593: remote_protocol, protocol_version);
594: exit_cleanup(RERR_PROTOCOL);
595: }
596:
1.1.1.2 misho 597: if (DEBUG_GTE(PROTO, 1)) {
1.1 misho 598: rprintf(FINFO, "(%s) Protocol versions: remote=%d, negotiated=%d\n",
599: am_server? "Server" : "Client", remote_protocol, protocol_version);
600: }
601: if (remote_protocol < MIN_PROTOCOL_VERSION
602: || remote_protocol > MAX_PROTOCOL_VERSION) {
603: rprintf(FERROR,"protocol version mismatch -- is your shell clean?\n");
604: rprintf(FERROR,"(see the rsync man page for an explanation)\n");
605: exit_cleanup(RERR_PROTOCOL);
606: }
607: if (remote_protocol < OLD_PROTOCOL_VERSION) {
608: rprintf(FINFO,"%s is very old version of rsync, upgrade recommended.\n",
609: am_server? "Client" : "Server");
610: }
611: if (protocol_version < MIN_PROTOCOL_VERSION) {
612: rprintf(FERROR, "--protocol must be at least %d on the %s.\n",
613: MIN_PROTOCOL_VERSION, am_server? "Server" : "Client");
614: exit_cleanup(RERR_PROTOCOL);
615: }
616: if (protocol_version > PROTOCOL_VERSION) {
617: rprintf(FERROR, "--protocol must be no more than %d on the %s.\n",
618: PROTOCOL_VERSION, am_server? "Server" : "Client");
619: exit_cleanup(RERR_PROTOCOL);
620: }
621: if (read_batch)
622: check_batch_flags();
623:
1.1.1.2 misho 624: #ifndef SUPPORT_PREALLOCATION
625: if (preallocate_files && !am_sender) {
626: rprintf(FERROR, "preallocation is not supported on this %s\n",
627: am_server ? "Server" : "Client");
628: exit_cleanup(RERR_SYNTAX);
629: }
630: #endif
631:
1.1 misho 632: if (protocol_version < 30) {
633: if (append_mode == 1)
634: append_mode = 2;
635: if (preserve_acls && !local_server) {
636: rprintf(FERROR,
1.1.1.4 ! misho 637: "--acls requires protocol 30 or higher"
! 638: " (negotiated %d).\n",
! 639: protocol_version);
1.1 misho 640: exit_cleanup(RERR_PROTOCOL);
641: }
642: if (preserve_xattrs && !local_server) {
643: rprintf(FERROR,
1.1.1.4 ! misho 644: "--xattrs requires protocol 30 or higher"
! 645: " (negotiated %d).\n",
! 646: protocol_version);
1.1 misho 647: exit_cleanup(RERR_PROTOCOL);
648: }
649: }
650:
651: if (delete_mode && !(delete_before+delete_during+delete_after)) {
652: if (protocol_version < 30)
653: delete_before = 1;
654: else
655: delete_during = 1;
656: }
657:
658: if (protocol_version < 29) {
659: if (fuzzy_basis) {
660: rprintf(FERROR,
1.1.1.4 ! misho 661: "--fuzzy requires protocol 29 or higher"
! 662: " (negotiated %d).\n",
! 663: protocol_version);
1.1 misho 664: exit_cleanup(RERR_PROTOCOL);
665: }
666:
667: if (basis_dir_cnt && inplace) {
668: rprintf(FERROR,
1.1.1.4 ! misho 669: "%s with --inplace requires protocol 29 or higher"
! 670: " (negotiated %d).\n",
! 671: alt_dest_opt(0), protocol_version);
1.1 misho 672: exit_cleanup(RERR_PROTOCOL);
673: }
674:
675: if (basis_dir_cnt > 1) {
676: rprintf(FERROR,
1.1.1.4 ! misho 677: "Using more than one %s option requires protocol"
! 678: " 29 or higher (negotiated %d).\n",
! 679: alt_dest_opt(0), protocol_version);
1.1 misho 680: exit_cleanup(RERR_PROTOCOL);
681: }
682:
683: if (prune_empty_dirs) {
684: rprintf(FERROR,
1.1.1.4 ! misho 685: "--prune-empty-dirs requires protocol 29 or higher"
! 686: " (negotiated %d).\n",
! 687: protocol_version);
1.1 misho 688: exit_cleanup(RERR_PROTOCOL);
689: }
690: } else if (protocol_version >= 30) {
691: if (am_server) {
692: compat_flags = allow_inc_recurse ? CF_INC_RECURSE : 0;
693: #ifdef CAN_SET_SYMLINK_TIMES
694: compat_flags |= CF_SYMLINK_TIMES;
695: #endif
696: #ifdef ICONV_OPTION
697: compat_flags |= CF_SYMLINK_ICONV;
698: #endif
699: if (local_server || strchr(client_info, 'f') != NULL)
700: compat_flags |= CF_SAFE_FLIST;
1.1.1.3 misho 701: if (local_server || strchr(client_info, 'x') != NULL)
702: compat_flags |= CF_AVOID_XATTR_OPTIM;
703: if (local_server || strchr(client_info, 'C') != NULL)
704: compat_flags |= CF_CHKSUM_SEED_FIX;
1.1.1.4 ! misho 705: if (local_server || strchr(client_info, 'I') != NULL)
! 706: compat_flags |= CF_INPLACE_PARTIAL_DIR;
! 707: if (local_server || strchr(client_info, 'u') != NULL)
! 708: compat_flags |= CF_ID0_NAMES;
! 709: if (local_server || strchr(client_info, 'v') != NULL) {
! 710: do_negotiated_strings = 1;
! 711: compat_flags |= CF_VARINT_FLIST_FLAGS;
! 712: }
! 713: if (strchr(client_info, 'V') != NULL) { /* Support a pre-release 'V' that got superseded */
! 714: if (!write_batch)
! 715: compat_flags |= CF_VARINT_FLIST_FLAGS;
! 716: write_byte(f_out, compat_flags);
! 717: } else
! 718: write_varint(f_out, compat_flags);
! 719: } else { /* read_varint() is compatible with the older write_byte() when the 0x80 bit isn't on. */
! 720: compat_flags = read_varint(f_in);
! 721: if (compat_flags & CF_VARINT_FLIST_FLAGS)
! 722: do_negotiated_strings = 1;
! 723: }
1.1 misho 724: /* The inc_recurse var MUST be set to 0 or 1. */
725: inc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;
1.1.1.3 misho 726: want_xattr_optim = protocol_version >= 31 && !(compat_flags & CF_AVOID_XATTR_OPTIM);
727: proper_seed_order = compat_flags & CF_CHKSUM_SEED_FIX ? 1 : 0;
1.1.1.4 ! misho 728: xfer_flags_as_varint = compat_flags & CF_VARINT_FLIST_FLAGS ? 1 : 0;
! 729: xmit_id0_names = compat_flags & CF_ID0_NAMES ? 1 : 0;
! 730: if (!xfer_flags_as_varint && preserve_crtimes) {
! 731: fprintf(stderr, "Both rsync versions must be at least 3.2.0 for --crtimes.\n");
! 732: exit_cleanup(RERR_PROTOCOL);
! 733: }
! 734: if (!xfer_flags_as_varint && preserve_fileflags) {
! 735: fprintf(stderr, "Both rsync versions must be at least 3.2.0 for --fileflags.\n");
! 736: exit_cleanup(RERR_PROTOCOL);
! 737: }
1.1 misho 738: if (am_sender) {
739: receiver_symlink_times = am_server
740: ? strchr(client_info, 'L') != NULL
741: : !!(compat_flags & CF_SYMLINK_TIMES);
742: }
743: #ifdef CAN_SET_SYMLINK_TIMES
744: else
745: receiver_symlink_times = 1;
746: #endif
747: #ifdef ICONV_OPTION
748: sender_symlink_iconv = iconv_opt && (am_server
749: ? local_server || strchr(client_info, 's') != NULL
750: : !!(compat_flags & CF_SYMLINK_ICONV));
751: #endif
752: if (inc_recurse && !allow_inc_recurse) {
753: /* This should only be able to happen in a batch. */
754: fprintf(stderr,
1.1.1.4 ! misho 755: "Incompatible options specified for inc-recursive %s.\n",
! 756: read_batch ? "batch file" : "connection");
1.1 misho 757: exit_cleanup(RERR_SYNTAX);
758: }
1.1.1.2 misho 759: use_safe_inc_flist = (compat_flags & CF_SAFE_FLIST) || protocol_version >= 31;
1.1 misho 760: need_messages_from_generator = 1;
1.1.1.4 ! misho 761: if (compat_flags & CF_INPLACE_PARTIAL_DIR)
! 762: inplace_partial = 1;
1.1 misho 763: #ifdef CAN_SET_SYMLINK_TIMES
764: } else if (!am_sender) {
765: receiver_symlink_times = 1;
766: #endif
767: }
768:
1.1.1.4 ! misho 769: if (read_batch)
! 770: do_negotiated_strings = 0;
! 771:
1.1 misho 772: if (need_unsorted_flist && (!am_sender || inc_recurse))
773: unsort_ndx = ++file_extra_cnt;
774:
775: if (partial_dir && *partial_dir != '/' && (!am_server || local_server)) {
1.1.1.2 misho 776: int rflags = FILTRULE_NO_PREFIXES | FILTRULE_DIRECTORY;
1.1 misho 777: if (!am_sender || protocol_version >= 30)
1.1.1.2 misho 778: rflags |= FILTRULE_PERISHABLE;
779: parse_filter_str(&filter_list, partial_dir, rule_template(rflags), 0);
1.1 misho 780: }
781:
782:
783: #ifdef ICONV_OPTION
784: if (protect_args && files_from) {
785: if (am_sender)
786: filesfrom_convert = filesfrom_host && ic_send != (iconv_t)-1;
787: else
788: filesfrom_convert = !filesfrom_host && ic_recv != (iconv_t)-1;
789: }
790: #endif
791:
1.1.1.4 ! misho 792: negotiate_the_strings(f_in, f_out);
! 793:
1.1 misho 794: if (am_server) {
795: if (!checksum_seed)
1.1.1.3 misho 796: checksum_seed = time(NULL) ^ (getpid() << 6);
1.1 misho 797: write_int(f_out, checksum_seed);
798: } else {
799: checksum_seed = read_int(f_in);
800: }
1.1.1.4 ! misho 801:
! 802: parse_checksum_choice(1); /* Sets checksum_type & xfersum_type */
! 803: parse_compress_choice(1); /* Sets do_compression */
! 804:
! 805: if (write_batch && !am_server)
! 806: write_batch_shell_file();
! 807:
! 808: init_flist();
1.1 misho 809: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>