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.

271 lines
8.5 KiB

  1. commit 416e719bea4f5466c8dd2b34cac0059b6ff84ff3
  2. Author: Wayne Davison <wayned@samba.org>
  3. Date: Tue Nov 7 14:01:13 2017 -0800
  4. More archaic-checksum improvements. This makes the len vars clearer
  5. and ensures that only the flist code gets the 2-byte digest len.
  6. diff --git a/authenticate.c b/authenticate.c
  7. index 519429d..d60ee20 100644
  8. --- a/authenticate.c
  9. +++ b/authenticate.c
  10. @@ -74,8 +74,6 @@ static void gen_challenge(const char *addr, char *challenge)
  11. sum_init(-1, 0);
  12. sum_update(input, sizeof input);
  13. len = sum_end(digest);
  14. - if (len == 2) /* The archaic checksum is 2 bytes, but sum_end() filled in the full MD4 checksum for us. */
  15. - len = MD4_DIGEST_LEN;
  16. base64_encode(digest, len, challenge, 0);
  17. }
  18. @@ -91,8 +89,6 @@ static void generate_hash(const char *in, const char *challenge, char *out)
  19. sum_update(in, strlen(in));
  20. sum_update(challenge, strlen(challenge));
  21. len = sum_end(buf);
  22. - if (len == 2) /* The archaic checksum is 2 bytes, but sum_end() filled in the full MD4 checksum for us. */
  23. - len = MD4_DIGEST_LEN;
  24. base64_encode(buf, len, out, 0);
  25. }
  26. diff --git a/checksum.c b/checksum.c
  27. index 741ad7d..4c9351c 100644
  28. --- a/checksum.c
  29. +++ b/checksum.c
  30. @@ -73,13 +73,15 @@ int parse_csum_name(const char *name, int len)
  31. exit_cleanup(RERR_UNSUPPORTED);
  32. }
  33. -int csum_len_for_type(int cst)
  34. +int csum_len_for_type(int cst, int flist_csum)
  35. {
  36. switch (cst) {
  37. case CSUM_NONE:
  38. return 1;
  39. case CSUM_MD4_ARCHAIC:
  40. - return 2;
  41. + /* The oldest checksum code is rather weird: the file-list code only sent
  42. + * 2-byte checksums, but all other checksums were full MD4 length. */
  43. + return flist_csum ? 2 : MD4_DIGEST_LEN;
  44. case CSUM_MD4:
  45. case CSUM_MD4_OLD:
  46. case CSUM_MD4_BUSTED:
  47. @@ -361,5 +363,5 @@ int sum_end(char *sum)
  48. exit_cleanup(RERR_UNSUPPORTED);
  49. }
  50. - return csum_len_for_type(cursum_type);
  51. + return csum_len_for_type(cursum_type, 0);
  52. }
  53. diff --git a/flist.c b/flist.c
  54. index 24b3506..bedba63 100644
  55. --- a/flist.c
  56. +++ b/flist.c
  57. @@ -91,7 +91,7 @@ extern iconv_t ic_send, ic_recv;
  58. #define PTR_SIZE (sizeof (struct file_struct *))
  59. int io_error;
  60. -int checksum_len;
  61. +int flist_csum_len;
  62. dev_t filesystem_dev; /* used to implement -x */
  63. struct file_list *cur_flist, *first_flist, *dir_flist;
  64. @@ -141,7 +141,7 @@ void init_flist(void)
  65. (int)FILE_STRUCT_LEN, (int)EXTRA_LEN);
  66. }
  67. parse_checksum_choice(); /* Sets checksum_type && xfersum_type */
  68. - checksum_len = csum_len_for_type(checksum_type);
  69. + flist_csum_len = csum_len_for_type(checksum_type, 1);
  70. show_filelist_progress = INFO_GTE(FLIST, 1) && xfer_dirs && !am_server && !inc_recurse;
  71. }
  72. @@ -638,7 +638,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
  73. /* Prior to 28, we sent a useless set of nulls. */
  74. sum = empty_sum;
  75. }
  76. - write_buf(f, sum, checksum_len);
  77. + write_buf(f, sum, flist_csum_len);
  78. }
  79. #ifdef SUPPORT_HARD_LINKS
  80. @@ -1094,9 +1094,9 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
  81. }
  82. if (first_hlink_ndx >= flist->ndx_start) {
  83. struct file_struct *first = flist->files[first_hlink_ndx - flist->ndx_start];
  84. - memcpy(bp, F_SUM(first), checksum_len);
  85. + memcpy(bp, F_SUM(first), flist_csum_len);
  86. } else
  87. - read_buf(f, bp, checksum_len);
  88. + read_buf(f, bp, flist_csum_len);
  89. }
  90. #ifdef SUPPORT_ACLS
  91. @@ -1384,7 +1384,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
  92. }
  93. if (sender_keeps_checksum && S_ISREG(st.st_mode))
  94. - memcpy(F_SUM(file), tmp_sum, checksum_len);
  95. + memcpy(F_SUM(file), tmp_sum, flist_csum_len);
  96. if (unsort_ndx)
  97. F_NDX(file) = stats.num_dirs;
  98. diff --git a/generator.c b/generator.c
  99. index af2e290..3d65839 100644
  100. --- a/generator.c
  101. +++ b/generator.c
  102. @@ -74,7 +74,7 @@ extern int protocol_version;
  103. extern int file_total;
  104. extern int fuzzy_basis;
  105. extern int always_checksum;
  106. -extern int checksum_len;
  107. +extern int flist_csum_len;
  108. extern char *partial_dir;
  109. extern int compare_dest;
  110. extern int copy_dest;
  111. @@ -583,7 +583,7 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
  112. if (always_checksum > 0 && S_ISREG(st->st_mode)) {
  113. char sum[MAX_DIGEST_LEN];
  114. file_checksum(fn, st, sum);
  115. - return memcmp(sum, F_SUM(file), checksum_len) == 0;
  116. + return memcmp(sum, F_SUM(file), flist_csum_len) == 0;
  117. }
  118. if (size_only > 0)
  119. diff --git a/log.c b/log.c
  120. index b145ee1..7b23a2c 100644
  121. --- a/log.c
  122. +++ b/log.c
  123. @@ -673,14 +673,15 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
  124. n = NULL;
  125. if (S_ISREG(file->mode)) {
  126. if (always_checksum && canonical_checksum(checksum_type))
  127. - n = sum_as_hex(checksum_type, F_SUM(file));
  128. + n = sum_as_hex(checksum_type, F_SUM(file), 1);
  129. else if (iflags & ITEM_TRANSFER && canonical_checksum(xfersum_type))
  130. - n = sum_as_hex(xfersum_type, sender_file_sum);
  131. + n = sum_as_hex(xfersum_type, sender_file_sum, 0);
  132. }
  133. if (!n) {
  134. - int checksum_len = csum_len_for_type(always_checksum ? checksum_type : xfersum_type);
  135. - memset(buf2, ' ', checksum_len*2);
  136. - buf2[checksum_len*2] = '\0';
  137. + int sum_len = csum_len_for_type(always_checksum ? checksum_type : xfersum_type,
  138. + always_checksum);
  139. + memset(buf2, ' ', sum_len*2);
  140. + buf2[sum_len*2] = '\0';
  141. n = buf2;
  142. }
  143. break;
  144. diff --git a/match.c b/match.c
  145. index ff10310..280038b 100644
  146. --- a/match.c
  147. +++ b/match.c
  148. @@ -360,7 +360,7 @@ static void hash_search(int f,struct sum_struct *s,
  149. **/
  150. void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
  151. {
  152. - int checksum_len;
  153. + int sum_len;
  154. last_match = 0;
  155. false_alarms = 0;
  156. @@ -409,22 +409,22 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
  157. matched(f, s, buf, len, -1);
  158. }
  159. - checksum_len = sum_end(sender_file_sum);
  160. + sum_len = sum_end(sender_file_sum);
  161. /* If we had a read error, send a bad checksum. We use all bits
  162. * off as long as the checksum doesn't happen to be that, in
  163. * which case we turn the last 0 bit into a 1. */
  164. if (buf && buf->status != 0) {
  165. int i;
  166. - for (i = 0; i < checksum_len && sender_file_sum[i] == 0; i++) {}
  167. - memset(sender_file_sum, 0, checksum_len);
  168. - if (i == checksum_len)
  169. + for (i = 0; i < sum_len && sender_file_sum[i] == 0; i++) {}
  170. + memset(sender_file_sum, 0, sum_len);
  171. + if (i == sum_len)
  172. sender_file_sum[i-1]++;
  173. }
  174. if (DEBUG_GTE(DELTASUM, 2))
  175. rprintf(FINFO,"sending file_sum\n");
  176. - write_buf(f, sender_file_sum, checksum_len);
  177. + write_buf(f, sender_file_sum, sum_len);
  178. if (DEBUG_GTE(DELTASUM, 2)) {
  179. rprintf(FINFO, "false_alarms=%d hash_hits=%d matches=%d\n",
  180. diff --git a/receiver.c b/receiver.c
  181. index 3d9bc65..baae3a9 100644
  182. --- a/receiver.c
  183. +++ b/receiver.c
  184. @@ -236,7 +236,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
  185. static char file_sum1[MAX_DIGEST_LEN];
  186. struct map_struct *mapbuf;
  187. struct sum_struct sum;
  188. - int checksum_len;
  189. + int sum_len;
  190. int32 len;
  191. OFF_T offset = 0;
  192. OFF_T offset2;
  193. @@ -388,15 +388,15 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
  194. if (INFO_GTE(PROGRESS, 1))
  195. end_progress(total_size);
  196. - checksum_len = sum_end(file_sum1);
  197. + sum_len = sum_end(file_sum1);
  198. if (mapbuf)
  199. unmap_file(mapbuf);
  200. - read_buf(f_in, sender_file_sum, checksum_len);
  201. + read_buf(f_in, sender_file_sum, sum_len);
  202. if (DEBUG_GTE(DELTASUM, 2))
  203. rprintf(FINFO,"got file_sum\n");
  204. - if (fd != -1 && memcmp(file_sum1, sender_file_sum, checksum_len) != 0)
  205. + if (fd != -1 && memcmp(file_sum1, sender_file_sum, sum_len) != 0)
  206. return 0;
  207. return 1;
  208. }
  209. diff --git a/t_stub.c b/t_stub.c
  210. index fc1ee3b..0c49d9c 100644
  211. --- a/t_stub.c
  212. +++ b/t_stub.c
  213. @@ -98,7 +98,7 @@ filter_rule_list daemon_filter_list;
  214. return "tester";
  215. }
  216. - int csum_len_for_type(int cst)
  217. + int csum_len_for_type(int cst, int flg)
  218. {
  219. - return cst ? 16 : 1;
  220. + return cst || !flg ? 16 : 1;
  221. }
  222. diff --git a/util2.c b/util2.c
  223. index a892e51..b1adf81 100644
  224. --- a/util2.c
  225. +++ b/util2.c
  226. @@ -77,18 +77,18 @@ void *_realloc_array(void *ptr, unsigned int size, size_t num)
  227. return realloc(ptr, size * num);
  228. }
  229. -const char *sum_as_hex(int csum_type, const char *sum)
  230. +const char *sum_as_hex(int csum_type, const char *sum, int flist_csum)
  231. {
  232. static char buf[MAX_DIGEST_LEN*2+1];
  233. int i, x1, x2;
  234. - int checksum_len = csum_len_for_type(csum_type);
  235. - char *c = buf + checksum_len*2;
  236. + int sum_len = csum_len_for_type(csum_type, flist_csum);
  237. + char *c = buf + sum_len*2;
  238. assert(c - buf < (int)sizeof buf);
  239. *c = '\0';
  240. - for (i = checksum_len; --i >= 0; ) {
  241. + for (i = sum_len; --i >= 0; ) {
  242. x1 = CVAL(sum, i);
  243. x2 = x1 >> 4;
  244. x1 &= 0xF;