You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

650 lines
20 KiB

  1. commit a5a7d3a297b836387b0ac677383bdddaf2ac3598
  2. Author: Wayne Davison <wayned@samba.org>
  3. Date: Sun May 1 16:32:45 2016 -0700
  4. Add --checksum-choice option to choose the checksum algorithms.
  5. diff --git a/authenticate.c b/authenticate.c
  6. index 5f125de..d60ee20 100644
  7. --- a/authenticate.c
  8. +++ b/authenticate.c
  9. @@ -71,7 +71,7 @@ static void gen_challenge(const char *addr, char *challenge)
  10. SIVAL(input, 20, tv.tv_usec);
  11. SIVAL(input, 24, getpid());
  12. - sum_init(0);
  13. + sum_init(-1, 0);
  14. sum_update(input, sizeof input);
  15. len = sum_end(digest);
  16. @@ -85,7 +85,7 @@ static void generate_hash(const char *in, const char *challenge, char *out)
  17. char buf[MAX_DIGEST_LEN];
  18. int len;
  19. - sum_init(0);
  20. + sum_init(-1, 0);
  21. sum_update(in, strlen(in));
  22. sum_update(challenge, strlen(challenge));
  23. len = sum_end(buf);
  24. diff --git a/checksum.c b/checksum.c
  25. index bac775d..8b38833 100644
  26. --- a/checksum.c
  27. +++ b/checksum.c
  28. @@ -24,6 +24,76 @@
  29. extern int checksum_seed;
  30. extern int protocol_version;
  31. extern int proper_seed_order;
  32. +extern char *checksum_choice;
  33. +
  34. +#define CSUM_NONE 0
  35. +#define CSUM_ARCHAIC 1
  36. +#define CSUM_MD4_BUSTED 2
  37. +#define CSUM_MD4_OLD 3
  38. +#define CSUM_MD4 4
  39. +#define CSUM_MD5 5
  40. +
  41. +int xfersum_type = 0; /* used for the file transfer checksums */
  42. +int checksum_type = 0; /* used for the pre-transfer (--checksum) checksums */
  43. +
  44. +/* Returns 1 if --whole-file must be enabled. */
  45. +int parse_checksum_choice(void)
  46. +{
  47. + char *cp = checksum_choice ? strchr(checksum_choice, ',') : NULL;
  48. + if (cp) {
  49. + xfersum_type = parse_csum_name(checksum_choice, cp - checksum_choice);
  50. + checksum_type = parse_csum_name(cp+1, -1);
  51. + } else
  52. + xfersum_type = checksum_type = parse_csum_name(checksum_choice, -1);
  53. + return xfersum_type == CSUM_NONE;
  54. +}
  55. +
  56. +int parse_csum_name(const char *name, int len)
  57. +{
  58. + if (len < 0 && name)
  59. + len = strlen(name);
  60. +
  61. + if (!name || (len == 4 && strncasecmp(name, "auto", 4) == 0)) {
  62. + if (protocol_version >= 30)
  63. + return CSUM_MD5;
  64. + if (protocol_version >= 27)
  65. + return CSUM_MD4_OLD;
  66. + if (protocol_version >= 21)
  67. + return CSUM_MD4_BUSTED;
  68. + return CSUM_ARCHAIC;
  69. + }
  70. + if (len == 3 && strncasecmp(name, "md4", 3) == 0)
  71. + return CSUM_MD4;
  72. + if (len == 3 && strncasecmp(name, "md5", 3) == 0)
  73. + return CSUM_MD5;
  74. + if (len == 4 && strncasecmp(name, "none", 4) == 0)
  75. + return CSUM_NONE;
  76. +
  77. + rprintf(FERROR, "unknown checksum name: %s\n", name);
  78. + exit_cleanup(RERR_UNSUPPORTED);
  79. +}
  80. +
  81. +int csum_len_for_type(int cst)
  82. +{
  83. + switch (cst) {
  84. + case CSUM_NONE:
  85. + return 1;
  86. + case CSUM_ARCHAIC:
  87. + return 2;
  88. + case CSUM_MD4:
  89. + case CSUM_MD4_OLD:
  90. + case CSUM_MD4_BUSTED:
  91. + return MD4_DIGEST_LEN;
  92. + case CSUM_MD5:
  93. + return MD5_DIGEST_LEN;
  94. + }
  95. + return 0;
  96. +}
  97. +
  98. +int canonical_checksum(int csum_type)
  99. +{
  100. + return csum_type >= CSUM_MD4 ? 1 : 0;
  101. +}
  102. /*
  103. a simple 32 bit checksum that can be upadted from either end
  104. @@ -47,12 +117,12 @@ uint32 get_checksum1(char *buf1, int32 len)
  105. return (s1 & 0xffff) + (s2 << 16);
  106. }
  107. -
  108. void get_checksum2(char *buf, int32 len, char *sum)
  109. {
  110. md_context m;
  111. - if (protocol_version >= 30) {
  112. + switch (xfersum_type) {
  113. + case CSUM_MD5: {
  114. uchar seedbuf[4];
  115. md5_begin(&m);
  116. if (proper_seed_order) {
  117. @@ -69,7 +139,11 @@ void get_checksum2(char *buf, int32 len, char *sum)
  118. }
  119. }
  120. md5_result(&m, (uchar *)sum);
  121. - } else {
  122. + break;
  123. + }
  124. + case CSUM_MD4:
  125. + case CSUM_MD4_OLD:
  126. + case CSUM_MD4_BUSTED: {
  127. int32 i;
  128. static char *buf1;
  129. static int32 len1;
  130. @@ -100,10 +174,12 @@ void get_checksum2(char *buf, int32 len, char *sum)
  131. * are multiples of 64. This is fixed by calling mdfour_update()
  132. * even when there are no more bytes.
  133. */
  134. - if (len - i > 0 || protocol_version >= 27)
  135. + if (len - i > 0 || xfersum_type != CSUM_MD4_BUSTED)
  136. mdfour_update(&m, (uchar *)(buf1+i), len-i);
  137. mdfour_result(&m, (uchar *)sum);
  138. + break;
  139. + }
  140. }
  141. }
  142. @@ -123,7 +199,8 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
  143. buf = map_file(fd, len, MAX_MAP_SIZE, CSUM_CHUNK);
  144. - if (protocol_version >= 30) {
  145. + switch (checksum_type) {
  146. + case CSUM_MD5:
  147. md5_begin(&m);
  148. for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
  149. @@ -136,7 +213,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
  150. md5_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder);
  151. md5_result(&m, (uchar *)sum);
  152. - } else {
  153. + break;
  154. + case CSUM_MD4:
  155. + case CSUM_MD4_OLD:
  156. + case CSUM_MD4_BUSTED:
  157. mdfour_begin(&m);
  158. for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
  159. @@ -149,10 +229,14 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
  160. * are multiples of 64. This is fixed by calling mdfour_update()
  161. * even when there are no more bytes. */
  162. remainder = (int32)(len - i);
  163. - if (remainder > 0 || protocol_version >= 27)
  164. + if (remainder > 0 || checksum_type != CSUM_MD4_BUSTED)
  165. mdfour_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder);
  166. mdfour_result(&m, (uchar *)sum);
  167. + break;
  168. + default:
  169. + rprintf(FERROR, "invalid checksum-choice for the --checksum option (%d)\n", checksum_type);
  170. + exit_cleanup(RERR_UNSUPPORTED);
  171. }
  172. close(fd);
  173. @@ -161,18 +245,33 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
  174. static int32 sumresidue;
  175. static md_context md;
  176. +static int cursum_type;
  177. -void sum_init(int seed)
  178. +void sum_init(int csum_type, int seed)
  179. {
  180. char s[4];
  181. - if (protocol_version >= 30)
  182. + if (csum_type < 0)
  183. + csum_type = parse_csum_name(NULL, 0);
  184. + cursum_type = csum_type;
  185. +
  186. + switch (csum_type) {
  187. + case CSUM_MD5:
  188. md5_begin(&md);
  189. - else {
  190. + break;
  191. + case CSUM_MD4:
  192. + mdfour_begin(&md);
  193. + sumresidue = 0;
  194. + break;
  195. + case CSUM_MD4_OLD:
  196. + case CSUM_MD4_BUSTED:
  197. mdfour_begin(&md);
  198. sumresidue = 0;
  199. SIVAL(s, 0, seed);
  200. sum_update(s, 4);
  201. + break;
  202. + case CSUM_NONE:
  203. + break;
  204. }
  205. }
  206. @@ -186,13 +285,17 @@ void sum_init(int seed)
  207. **/
  208. void sum_update(const char *p, int32 len)
  209. {
  210. - if (protocol_version >= 30) {
  211. + switch (cursum_type) {
  212. + case CSUM_MD5:
  213. md5_update(&md, (uchar *)p, len);
  214. - } else {
  215. + break;
  216. + case CSUM_MD4:
  217. + case CSUM_MD4_OLD:
  218. + case CSUM_MD4_BUSTED:
  219. if (len + sumresidue < CSUM_CHUNK) {
  220. memcpy(md.buffer + sumresidue, p, len);
  221. sumresidue += len;
  222. - return;
  223. + break;
  224. }
  225. if (sumresidue) {
  226. @@ -212,20 +315,32 @@ void sum_update(const char *p, int32 len)
  227. sumresidue = len;
  228. if (sumresidue)
  229. memcpy(md.buffer, p, sumresidue);
  230. + break;
  231. + case CSUM_NONE:
  232. + break;
  233. }
  234. }
  235. int sum_end(char *sum)
  236. {
  237. - if (protocol_version >= 30) {
  238. + switch (cursum_type) {
  239. + case CSUM_MD5:
  240. md5_result(&md, (uchar *)sum);
  241. - return MD5_DIGEST_LEN;
  242. - } else {
  243. - if (sumresidue || protocol_version >= 27)
  244. + break;
  245. + case CSUM_MD4:
  246. + case CSUM_MD4_OLD:
  247. + mdfour_update(&md, (uchar *)md.buffer, sumresidue);
  248. + mdfour_result(&md, (uchar *)sum);
  249. + break;
  250. + case CSUM_MD4_BUSTED:
  251. + if (sumresidue)
  252. mdfour_update(&md, (uchar *)md.buffer, sumresidue);
  253. -
  254. mdfour_result(&md, (uchar *)sum);
  255. -
  256. - return MD4_DIGEST_LEN;
  257. + break;
  258. + case CSUM_NONE:
  259. + *sum = '\0';
  260. + break;
  261. }
  262. +
  263. + return csum_len_for_type(cursum_type);
  264. }
  265. diff --git a/compat.c b/compat.c
  266. index c792312..505cb7f 100644
  267. --- a/compat.c
  268. +++ b/compat.c
  269. @@ -338,4 +338,6 @@ void setup_protocol(int f_out,int f_in)
  270. } else {
  271. checksum_seed = read_int(f_in);
  272. }
  273. +
  274. + init_flist();
  275. }
  276. diff --git a/flist.c b/flist.c
  277. index c1e48b3..acb95f7 100644
  278. --- a/flist.c
  279. +++ b/flist.c
  280. @@ -33,6 +33,7 @@ extern int am_sender;
  281. extern int am_generator;
  282. extern int inc_recurse;
  283. extern int always_checksum;
  284. +extern int checksum_type;
  285. extern int module_id;
  286. extern int ignore_errors;
  287. extern int numeric_ids;
  288. @@ -137,9 +138,8 @@ void init_flist(void)
  289. rprintf(FINFO, "FILE_STRUCT_LEN=%d, EXTRA_LEN=%d\n",
  290. (int)FILE_STRUCT_LEN, (int)EXTRA_LEN);
  291. }
  292. - checksum_len = protocol_version < 21 ? 2
  293. - : protocol_version < 30 ? MD4_DIGEST_LEN
  294. - : MD5_DIGEST_LEN;
  295. + parse_checksum_choice(); /* Sets checksum_type && xfersum_type */
  296. + checksum_len = csum_len_for_type(checksum_type);
  297. }
  298. static int show_filelist_p(void)
  299. diff --git a/log.c b/log.c
  300. index 24256de..f7da1e5 100644
  301. --- a/log.c
  302. +++ b/log.c
  303. @@ -31,12 +31,13 @@ extern int am_generator;
  304. extern int local_server;
  305. extern int quiet;
  306. extern int module_id;
  307. -extern int checksum_len;
  308. extern int allow_8bit_chars;
  309. extern int protocol_version;
  310. extern int always_checksum;
  311. extern int preserve_times;
  312. extern int msgs2stderr;
  313. +extern int xfersum_type;
  314. +extern int checksum_type;
  315. extern int stdout_format_has_i;
  316. extern int stdout_format_has_o_or_i;
  317. extern int logfile_format_has_i;
  318. @@ -46,6 +47,7 @@ extern int64 total_data_written;
  319. extern int64 total_data_read;
  320. extern mode_t orig_umask;
  321. extern char *auth_user;
  322. +extern char *checksum_choice;
  323. extern char *stdout_format;
  324. extern char *logfile_format;
  325. extern char *logfile_name;
  326. @@ -669,13 +671,15 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
  327. n = buf2;
  328. break;
  329. case 'C':
  330. - if (protocol_version >= 30
  331. - && (iflags & ITEM_TRANSFER
  332. - || (always_checksum && S_ISREG(file->mode)))) {
  333. - const char *sum = iflags & ITEM_TRANSFER
  334. - ? sender_file_sum : F_SUM(file);
  335. - n = sum_as_hex(sum);
  336. - } else {
  337. + n = NULL;
  338. + if (S_ISREG(file->mode)) {
  339. + if (always_checksum && canonical_checksum(checksum_type))
  340. + n = sum_as_hex(checksum_type, F_SUM(file));
  341. + else if (iflags & ITEM_TRANSFER && canonical_checksum(xfersum_type))
  342. + n = sum_as_hex(xfersum_type, sender_file_sum);
  343. + }
  344. + if (!n) {
  345. + int checksum_len = csum_len_for_type(always_checksum ? checksum_type : xfersum_type);
  346. memset(buf2, ' ', checksum_len*2);
  347. buf2[checksum_len*2] = '\0';
  348. n = buf2;
  349. diff --git a/main.c b/main.c
  350. index 3132aa9..3908ccf 100644
  351. --- a/main.c
  352. +++ b/main.c
  353. @@ -1595,8 +1595,6 @@ int main(int argc,char *argv[])
  354. * that implement getcwd that way "pwd" can't be found after chroot. */
  355. change_dir(NULL, CD_NORMAL);
  356. - init_flist();
  357. -
  358. if ((write_batch || read_batch) && !am_server) {
  359. if (write_batch)
  360. write_batch_shell_file(orig_argc, orig_argv, argc);
  361. diff --git a/match.c b/match.c
  362. index b15f2eb..ff10310 100644
  363. --- a/match.c
  364. +++ b/match.c
  365. @@ -24,7 +24,7 @@
  366. extern int checksum_seed;
  367. extern int append_mode;
  368. -extern int checksum_len;
  369. +extern int xfersum_type;
  370. int updating_basis_file;
  371. char sender_file_sum[MAX_DIGEST_LEN];
  372. @@ -360,13 +360,15 @@ static void hash_search(int f,struct sum_struct *s,
  373. **/
  374. void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
  375. {
  376. + int checksum_len;
  377. +
  378. last_match = 0;
  379. false_alarms = 0;
  380. hash_hits = 0;
  381. matches = 0;
  382. data_transfer = 0;
  383. - sum_init(checksum_seed);
  384. + sum_init(xfersum_type, checksum_seed);
  385. if (append_mode > 0) {
  386. if (append_mode == 2) {
  387. @@ -407,8 +409,7 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
  388. matched(f, s, buf, len, -1);
  389. }
  390. - if (sum_end(sender_file_sum) != checksum_len)
  391. - overflow_exit("checksum_len"); /* Impossible... */
  392. + checksum_len = sum_end(sender_file_sum);
  393. /* If we had a read error, send a bad checksum. We use all bits
  394. * off as long as the checksum doesn't happen to be that, in
  395. diff --git a/options.c b/options.c
  396. index 4a5cdc8..308443b 100644
  397. --- a/options.c
  398. +++ b/options.c
  399. @@ -182,6 +182,7 @@ char *dest_option = NULL;
  400. static int remote_option_alloc = 0;
  401. int remote_option_cnt = 0;
  402. const char **remote_options = NULL;
  403. +const char *checksum_choice = NULL;
  404. int quiet = 0;
  405. int output_motd = 1;
  406. @@ -721,6 +722,7 @@ void usage(enum logcode F)
  407. #endif
  408. rprintf(F," -n, --dry-run perform a trial run with no changes made\n");
  409. rprintf(F," -W, --whole-file copy files whole (without delta-xfer algorithm)\n");
  410. + rprintf(F," --checksum-choice=STR choose the checksum algorithms\n");
  411. rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
  412. rprintf(F," -B, --block-size=SIZE force a fixed checksum block-size\n");
  413. rprintf(F," -e, --rsh=COMMAND specify the remote shell to use\n");
  414. @@ -953,6 +955,7 @@ static struct poptOption long_options[] = {
  415. {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
  416. {"whole-file", 'W', POPT_ARG_VAL, &whole_file, 1, 0, 0 },
  417. {"no-whole-file", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
  418. + {"checksum-choice", 0, POPT_ARG_STRING, &checksum_choice, 0, 0, 0 },
  419. {"no-W", 0, POPT_ARG_VAL, &whole_file, 0, 0, 0 },
  420. {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
  421. {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
  422. @@ -1814,6 +1817,15 @@ int parse_arguments(int *argc_p, const char ***argv_p)
  423. }
  424. }
  425. + if (checksum_choice && strcmp(checksum_choice, "auto") != 0 && strcmp(checksum_choice, "auto,auto") != 0) {
  426. + /* Call this early to verify the args and figure out if we need to force
  427. + * --whole-file. Note that the parse function will get called again later,
  428. + * just in case an "auto" choice needs to know the protocol_version. */
  429. + if (parse_checksum_choice())
  430. + whole_file = 1;
  431. + } else
  432. + checksum_choice = NULL;
  433. +
  434. if (human_readable > 1 && argc == 2 && !am_server) {
  435. /* Allow the old meaning of 'h' (--help) on its own. */
  436. usage(FINFO);
  437. @@ -2597,6 +2609,12 @@ void server_options(char **args, int *argc_p)
  438. args[ac++] = arg;
  439. }
  440. + if (checksum_choice) {
  441. + if (asprintf(&arg, "--checksum-choice=%s", checksum_choice) < 0)
  442. + goto oom;
  443. + args[ac++] = arg;
  444. + }
  445. +
  446. if (am_sender) {
  447. if (max_delete > 0) {
  448. if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
  449. diff --git a/receiver.c b/receiver.c
  450. index 4ea4c09..f9b97dd 100644
  451. --- a/receiver.c
  452. +++ b/receiver.c
  453. @@ -48,11 +48,11 @@ extern int append_mode;
  454. extern int sparse_files;
  455. extern int preallocate_files;
  456. extern int keep_partial;
  457. -extern int checksum_len;
  458. extern int checksum_seed;
  459. extern int inplace;
  460. extern int allowed_lull;
  461. extern int delay_updates;
  462. +extern int xfersum_type;
  463. extern mode_t orig_umask;
  464. extern struct stats stats;
  465. extern char *tmpdir;
  466. @@ -234,6 +234,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
  467. static char file_sum1[MAX_DIGEST_LEN];
  468. struct map_struct *mapbuf;
  469. struct sum_struct sum;
  470. + int checksum_len;
  471. int32 len;
  472. OFF_T offset = 0;
  473. OFF_T offset2;
  474. @@ -269,7 +270,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
  475. } else
  476. mapbuf = NULL;
  477. - sum_init(checksum_seed);
  478. + sum_init(xfersum_type, checksum_seed);
  479. if (append_mode > 0) {
  480. OFF_T j;
  481. @@ -393,8 +394,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
  482. exit_cleanup(RERR_FILEIO);
  483. }
  484. - if (sum_end(file_sum1) != checksum_len)
  485. - overflow_exit("checksum_len"); /* Impossible... */
  486. + checksum_len = sum_end(file_sum1);
  487. if (mapbuf)
  488. unmap_file(mapbuf);
  489. diff --git a/rsync.yo b/rsync.yo
  490. index 8971828..0ec5e55 100644
  491. --- a/rsync.yo
  492. +++ b/rsync.yo
  493. @@ -380,6 +380,7 @@ to the detailed description below for a complete description. verb(
  494. --preallocate allocate dest files before writing
  495. -n, --dry-run perform a trial run with no changes made
  496. -W, --whole-file copy files whole (w/o delta-xfer algorithm)
  497. + --checksum-choice=STR choose the checksum algorithms
  498. -x, --one-file-system don't cross filesystem boundaries
  499. -B, --block-size=SIZE force a fixed checksum block-size
  500. -e, --rsh=COMMAND specify the remote shell to use
  501. @@ -1280,14 +1281,27 @@ the "bytes sent", "bytes received", "literal data", and "matched data"
  502. statistics are too small, and the "speedup" value is equivalent to a run
  503. where no file transfers were needed.
  504. -dit(bf(-W, --whole-file)) With this option rsync's delta-transfer algorithm
  505. -is not used and the whole file is sent as-is instead. The transfer may be
  506. +dit(bf(-W, --whole-file)) This option disables rsync's delta-transfer algorithm,
  507. +which causes all transferred files to be sent whole. The transfer may be
  508. faster if this option is used when the bandwidth between the source and
  509. destination machines is higher than the bandwidth to disk (especially when the
  510. "disk" is actually a networked filesystem). This is the default when both
  511. the source and destination are specified as local paths, but only if no
  512. batch-writing option is in effect.
  513. +dit(bf(--checksum-choice=STR)) This option overrides the checksum algoriths.
  514. +If one algorithm name is specified, it is used for both the transfer checksums
  515. +and (assuming bf(--checksum) is specifed) the pre-transfer checksumming. If two
  516. +comma-separated names are supplied, the first name affects the transfer
  517. +checksums, and the second name affects the pre-transfer checksumming.
  518. +
  519. +The algorithm choices are "auto", "md4", "md5", and "none". If "none" is
  520. +specified for the first name, the bf(--whole-file) option is forced on and no
  521. +checksum verification is performed on the transferred data. If "none" is
  522. +specified for the second name, the bf(--checksum) option cannot be used. The
  523. +"auto" option is the default, where rsync bases its algorithm choice on the
  524. +protocol version (for backward compatibility with older rsync versions).
  525. +
  526. dit(bf(-x, --one-file-system)) This tells rsync to avoid crossing a
  527. filesystem boundary when recursing. This does not limit the user's ability
  528. to specify items to copy from multiple filesystems, just rsync's recursion
  529. diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo
  530. index 1813354..64156ae 100644
  531. --- a/rsyncd.conf.yo
  532. +++ b/rsyncd.conf.yo
  533. @@ -656,7 +656,7 @@ quote(itemization(
  534. it() %b the number of bytes actually transferred
  535. it() %B the permission bits of the file (e.g. rwxrwxrwt)
  536. it() %c the total size of the block checksums received for the basis file (only when sending)
  537. - it() %C the full-file MD5 checksum if bf(--checksum) is enabled or a file was transferred (only for protocol 30 or above).
  538. + it() %C the full-file checksum if it is known for the file. For older rsync protocols/versions, the checksum was salted, and is thus not a useful value (and is not displayed when that is the case). For the checksum to output for a file, either the bf(--checksum) option must be in-effect or the file must have been transferred without a salted checksum being used. See the bf(--checksum-choice) option for a way to choose the algorithm.
  539. it() %f the filename (long form on sender; no trailing "/")
  540. it() %G the gid of the file (decimal) or "DEFAULT"
  541. it() %h the remote host name (only available for a daemon)
  542. diff --git a/t_stub.c b/t_stub.c
  543. index 6002250..26951a6 100644
  544. --- a/t_stub.c
  545. +++ b/t_stub.c
  546. @@ -25,7 +25,6 @@ int modify_window = 0;
  547. int preallocate_files = 0;
  548. int protect_args = 0;
  549. int module_id = -1;
  550. -int checksum_len = 0;
  551. int relative_paths = 0;
  552. int module_dirlen = 0;
  553. int preserve_acls = 0;
  554. @@ -97,3 +96,8 @@ filter_rule_list daemon_filter_list;
  555. {
  556. return "tester";
  557. }
  558. +
  559. + int csum_len_for_type(int cst)
  560. +{
  561. + return cst ? 16 : 1;
  562. +}
  563. diff --git a/util2.c b/util2.c
  564. index cc368af..a892e51 100644
  565. --- a/util2.c
  566. +++ b/util2.c
  567. @@ -25,8 +25,6 @@
  568. #include "itypes.h"
  569. #include "inums.h"
  570. -extern int checksum_len;
  571. -
  572. /**
  573. * Sleep for a specified number of milliseconds.
  574. *
  575. @@ -79,10 +77,11 @@ void *_realloc_array(void *ptr, unsigned int size, size_t num)
  576. return realloc(ptr, size * num);
  577. }
  578. -const char *sum_as_hex(const char *sum)
  579. +const char *sum_as_hex(int csum_type, const char *sum)
  580. {
  581. static char buf[MAX_DIGEST_LEN*2+1];
  582. int i, x1, x2;
  583. + int checksum_len = csum_len_for_type(csum_type);
  584. char *c = buf + checksum_len*2;
  585. assert(c - buf < (int)sizeof buf);
  586. diff --git a/xattrs.c b/xattrs.c
  587. index 57833e5..6a77a0b 100644
  588. --- a/xattrs.c
  589. +++ b/xattrs.c
  590. @@ -258,7 +258,7 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
  591. if (datum_len > MAX_FULL_DATUM) {
  592. /* For large datums, we store a flag and a checksum. */
  593. name_offset = 1 + MAX_DIGEST_LEN;
  594. - sum_init(checksum_seed);
  595. + sum_init(-1, checksum_seed);
  596. sum_update(ptr, datum_len);
  597. free(ptr);
  598. @@ -821,7 +821,7 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
  599. goto still_abbrev;
  600. }
  601. - sum_init(checksum_seed);
  602. + sum_init(-1, checksum_seed);
  603. sum_update(ptr, len);
  604. sum_end(sum);
  605. if (memcmp(sum, rxas[i].datum + 1, MAX_DIGEST_LEN) != 0) {