Commit | Line | Data |
---|---|---|
0f78b815 | 1 | /* |
d1f83bcc | 2 | * Compatibility routines for older rsync protocol versions. |
0f78b815 WD |
3 | * |
4 | * Copyright (C) Andrew Tridgell 1996 | |
5 | * Copyright (C) Paul Mackerras 1996 | |
ba2133d6 | 6 | * Copyright (C) 2004-2007 Wayne Davison |
0f78b815 WD |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify | |
4fd842f9 | 9 | * it under the terms of the GNU General Public License version 3 as |
ba2133d6 | 10 | * published by the Free Software Foundation. |
0f78b815 WD |
11 | * |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
e7c67065 | 17 | * You should have received a copy of the GNU General Public License along |
4fd842f9 | 18 | * with this program; if not, visit the http://fsf.org website. |
0f78b815 | 19 | */ |
4fe159a8 AT |
20 | |
21 | #include "rsync.h" | |
22 | ||
8a9709de | 23 | int remote_protocol = 0; |
99a957d3 | 24 | int file_extra_cnt = 0; /* count of file-list extras that everyone gets */ |
3ea6e0e7 | 25 | int inc_recurse = 0; |
8a9709de | 26 | |
b9f592fb | 27 | extern int verbose; |
aae43eb3 | 28 | extern int am_server; |
771d0add | 29 | extern int am_sender; |
d0c59b0e | 30 | extern int local_server; |
57b12568 | 31 | extern int inplace; |
e4b619b4 | 32 | extern int recurse; |
c8e83946 | 33 | extern int use_qsort; |
5275029d | 34 | extern int allow_inc_recurse; |
e461b9be | 35 | extern int fuzzy_basis; |
b9f592fb | 36 | extern int read_batch; |
771d0add | 37 | extern int max_delete; |
e4b619b4 | 38 | extern int delay_updates; |
aae43eb3 | 39 | extern int checksum_seed; |
57b12568 | 40 | extern int basis_dir_cnt; |
a1cc199b | 41 | extern int prune_empty_dirs; |
8a9709de | 42 | extern int protocol_version; |
99a957d3 WD |
43 | extern int preserve_uid; |
44 | extern int preserve_gid; | |
1c3344a1 | 45 | extern int preserve_acls; |
16edf865 | 46 | extern int preserve_xattrs; |
e4b619b4 WD |
47 | extern int preserve_hard_links; |
48 | extern int need_messages_from_generator; | |
49 | extern int delete_mode, delete_before, delete_during, delete_after; | |
c1289508 WD |
50 | extern int delete_excluded; |
51 | extern int make_backups; | |
486f8cd1 | 52 | extern char *shell_cmd; /* contains VER.SUB string if client is a pre-release */ |
c1289508 WD |
53 | extern char *backup_dir, *backup_suffix; |
54 | extern char *partial_dir; | |
57b12568 | 55 | extern char *dest_option; |
c1289508 | 56 | extern struct filter_list_struct filter_list; |
4fe159a8 | 57 | |
9742b386 WD |
58 | /* These index values are for the file-list's extra-attribute array. */ |
59 | int uid_ndx, gid_ndx, acls_ndx, xattrs_ndx; | |
60 | ||
486f8cd1 WD |
61 | /* The server makes sure that if either side only supports a pre-release |
62 | * version of a protocol, that both sides must speak a compatible version | |
63 | * of that protocol for it to be advertised as available. */ | |
64 | static void check_sub_protocol(void) | |
65 | { | |
66 | char *dot; | |
67 | int their_protocol, their_sub; | |
68 | int our_sub = protocol_version < PROTOCOL_VERSION ? 0 : SUBPROTOCOL_VERSION; | |
69 | ||
70 | if (!shell_cmd || !(dot = strchr(shell_cmd, '.')) | |
71 | || !(their_protocol = atoi(shell_cmd)) | |
72 | || !(their_sub = atoi(dot+1))) { | |
73 | if (our_sub) | |
74 | protocol_version--; | |
75 | return; | |
76 | } | |
77 | ||
78 | if (their_protocol < protocol_version) { | |
79 | if (their_sub) | |
80 | protocol_version = their_protocol - 1; | |
81 | return; | |
82 | } | |
83 | ||
84 | if (their_protocol > protocol_version) | |
85 | their_sub = 0; /* 0 == final version */ | |
86 | if (their_sub != our_sub) | |
87 | protocol_version--; | |
88 | } | |
89 | ||
aae43eb3 | 90 | void setup_protocol(int f_out,int f_in) |
4fe159a8 | 91 | { |
6eee13cf | 92 | if (am_sender) |
99a957d3 | 93 | file_extra_cnt += PTR_EXTRA_LEN; |
6eee13cf | 94 | else |
99a957d3 | 95 | file_extra_cnt++; |
6eee13cf | 96 | if (preserve_uid) |
9742b386 | 97 | uid_ndx = ++file_extra_cnt; |
6eee13cf | 98 | if (preserve_gid) |
9742b386 | 99 | gid_ndx = ++file_extra_cnt; |
1c3344a1 | 100 | if (preserve_acls && !am_sender) |
9742b386 | 101 | acls_ndx = ++file_extra_cnt; |
16edf865 | 102 | if (preserve_xattrs) |
9742b386 | 103 | xattrs_ndx = ++file_extra_cnt; |
6eee13cf | 104 | |
8a9709de | 105 | if (remote_protocol == 0) { |
486f8cd1 WD |
106 | if (am_server && !local_server) |
107 | check_sub_protocol(); | |
aa434321 | 108 | if (!read_batch) |
8a9709de | 109 | write_int(f_out, protocol_version); |
aa434321 | 110 | remote_protocol = read_int(f_in); |
8a9709de WD |
111 | if (protocol_version > remote_protocol) |
112 | protocol_version = remote_protocol; | |
13c5fc0e | 113 | } |
b9f592fb | 114 | if (read_batch && remote_protocol > protocol_version) { |
486f8cd1 | 115 | rprintf(FERROR, "The protocol version in the batch file is too new (%d > %d).\n", |
b9f592fb WD |
116 | remote_protocol, protocol_version); |
117 | exit_cleanup(RERR_PROTOCOL); | |
118 | } | |
aae43eb3 | 119 | |
8a9709de WD |
120 | if (verbose > 3) { |
121 | rprintf(FINFO, "(%s) Protocol versions: remote=%d, negotiated=%d\n", | |
122 | am_server? "Server" : "Client", remote_protocol, protocol_version); | |
123 | } | |
124 | if (remote_protocol < MIN_PROTOCOL_VERSION | |
125 | || remote_protocol > MAX_PROTOCOL_VERSION) { | |
4ccfd96c | 126 | rprintf(FERROR,"protocol version mismatch -- is your shell clean?\n"); |
d310a212 | 127 | rprintf(FERROR,"(see the rsync man page for an explanation)\n"); |
65417579 | 128 | exit_cleanup(RERR_PROTOCOL); |
8a9709de WD |
129 | } |
130 | if (remote_protocol < OLD_PROTOCOL_VERSION) { | |
1b2db7ae | 131 | rprintf(FINFO,"%s is very old version of rsync, upgrade recommended.\n", |
8a9709de WD |
132 | am_server? "Client" : "Server"); |
133 | } | |
134 | if (protocol_version < MIN_PROTOCOL_VERSION) { | |
135 | rprintf(FERROR, "--protocol must be at least %d on the %s.\n", | |
136 | MIN_PROTOCOL_VERSION, am_server? "Server" : "Client"); | |
137 | exit_cleanup(RERR_PROTOCOL); | |
138 | } | |
139 | if (protocol_version > PROTOCOL_VERSION) { | |
140 | rprintf(FERROR, "--protocol must be no more than %d on the %s.\n", | |
141 | PROTOCOL_VERSION, am_server? "Server" : "Client"); | |
142 | exit_cleanup(RERR_PROTOCOL); | |
143 | } | |
1b2db7ae | 144 | |
771d0add WD |
145 | if (protocol_version < 30) { |
146 | if (max_delete == 0 && am_sender) { | |
147 | rprintf(FERROR, | |
148 | "--max-delete=0 requires protocol 30 or higher" | |
149 | " (negotiated %d).\n", | |
150 | protocol_version); | |
151 | exit_cleanup(RERR_PROTOCOL); | |
152 | } | |
01894cf0 | 153 | if (preserve_acls && !local_server) { |
1c3344a1 WD |
154 | rprintf(FERROR, |
155 | "--acls requires protocol 30 or higher" | |
156 | " (negotiated %d).\n", | |
157 | protocol_version); | |
158 | exit_cleanup(RERR_PROTOCOL); | |
159 | } | |
01894cf0 | 160 | if (preserve_xattrs && !local_server) { |
16edf865 WD |
161 | rprintf(FERROR, |
162 | "--xattrs requires protocol 30 or higher" | |
163 | " (negotiated %d).\n", | |
164 | protocol_version); | |
165 | exit_cleanup(RERR_PROTOCOL); | |
166 | } | |
771d0add WD |
167 | } |
168 | ||
e4b619b4 WD |
169 | if (delete_mode && !(delete_before+delete_during+delete_after)) { |
170 | if (protocol_version < 30) | |
171 | delete_before = 1; | |
172 | else | |
173 | delete_during = 1; | |
174 | } | |
175 | ||
a1cc199b WD |
176 | if (protocol_version < 29) { |
177 | if (fuzzy_basis) { | |
178 | rprintf(FERROR, | |
179 | "--fuzzy requires protocol 29 or higher" | |
180 | " (negotiated %d).\n", | |
181 | protocol_version); | |
182 | exit_cleanup(RERR_PROTOCOL); | |
183 | } | |
e461b9be | 184 | |
a1cc199b WD |
185 | if (basis_dir_cnt && inplace) { |
186 | rprintf(FERROR, | |
187 | "%s with --inplace requires protocol 29 or higher" | |
188 | " (negotiated %d).\n", | |
189 | dest_option, protocol_version); | |
190 | exit_cleanup(RERR_PROTOCOL); | |
191 | } | |
57b12568 | 192 | |
a1cc199b WD |
193 | if (basis_dir_cnt > 1) { |
194 | rprintf(FERROR, | |
195 | "Using more than one %s option requires protocol" | |
196 | " 29 or higher (negotiated %d).\n", | |
197 | dest_option, protocol_version); | |
198 | exit_cleanup(RERR_PROTOCOL); | |
199 | } | |
200 | ||
201 | if (prune_empty_dirs) { | |
202 | rprintf(FERROR, | |
203 | "--prune-empty-dirs requires protocol 29 or higher" | |
204 | " (negotiated %d).\n", | |
205 | protocol_version); | |
206 | exit_cleanup(RERR_PROTOCOL); | |
207 | } | |
e4b619b4 | 208 | } else if (protocol_version >= 30) { |
5275029d WD |
209 | if (recurse && allow_inc_recurse && !preserve_hard_links |
210 | && !delete_before && !delete_after && !delay_updates | |
c8e83946 | 211 | && !prune_empty_dirs && !use_qsort) |
3ea6e0e7 | 212 | inc_recurse = 1; |
e4b619b4 | 213 | need_messages_from_generator = 1; |
57b12568 WD |
214 | } |
215 | ||
d0c59b0e | 216 | if (partial_dir && *partial_dir != '/' && (!am_server || local_server)) { |
c1289508 WD |
217 | int flags = MATCHFLG_NO_PREFIXES | MATCHFLG_DIRECTORY; |
218 | if (!am_sender || protocol_version >= 30) | |
219 | flags |= MATCHFLG_PERISHABLE; | |
220 | parse_rule(&filter_list, partial_dir, flags, 0); | |
221 | } | |
222 | ||
bc63ae3f | 223 | if (am_server) { |
b1bf649c | 224 | if (!checksum_seed) |
13c5fc0e | 225 | checksum_seed = time(NULL); |
b1bf649c | 226 | write_int(f_out, checksum_seed); |
bc63ae3f S |
227 | } else { |
228 | checksum_seed = read_int(f_in); | |
13c5fc0e | 229 | } |
4fe159a8 | 230 | } |