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.

100 lines
3.1 KiB

  1. commit 7b8a4ecd6ff9cdf4e5d3850ebf822f1e989255b3
  2. Author: Wayne Davison <wayned@samba.org>
  3. Date: Tue Oct 24 15:40:37 2017 -0700
  4. Handle archaic checksums properly.
  5. diff --git a/checksum.c b/checksum.c
  6. index 8b38833..9382694 100644
  7. --- a/checksum.c
  8. +++ b/checksum.c
  9. @@ -27,7 +27,7 @@ extern int proper_seed_order;
  10. extern char *checksum_choice;
  11. #define CSUM_NONE 0
  12. -#define CSUM_ARCHAIC 1
  13. +#define CSUM_MD4_ARCHAIC 1
  14. #define CSUM_MD4_BUSTED 2
  15. #define CSUM_MD4_OLD 3
  16. #define CSUM_MD4 4
  17. @@ -60,7 +60,7 @@ int parse_csum_name(const char *name, int len)
  18. return CSUM_MD4_OLD;
  19. if (protocol_version >= 21)
  20. return CSUM_MD4_BUSTED;
  21. - return CSUM_ARCHAIC;
  22. + return CSUM_MD4_ARCHAIC;
  23. }
  24. if (len == 3 && strncasecmp(name, "md4", 3) == 0)
  25. return CSUM_MD4;
  26. @@ -78,7 +78,7 @@ int csum_len_for_type(int cst)
  27. switch (cst) {
  28. case CSUM_NONE:
  29. return 1;
  30. - case CSUM_ARCHAIC:
  31. + case CSUM_MD4_ARCHAIC:
  32. return 2;
  33. case CSUM_MD4:
  34. case CSUM_MD4_OLD:
  35. @@ -143,7 +143,8 @@ void get_checksum2(char *buf, int32 len, char *sum)
  36. }
  37. case CSUM_MD4:
  38. case CSUM_MD4_OLD:
  39. - case CSUM_MD4_BUSTED: {
  40. + case CSUM_MD4_BUSTED:
  41. + case CSUM_MD4_ARCHAIC: {
  42. int32 i;
  43. static char *buf1;
  44. static int32 len1;
  45. @@ -174,7 +175,7 @@ void get_checksum2(char *buf, int32 len, char *sum)
  46. * are multiples of 64. This is fixed by calling mdfour_update()
  47. * even when there are no more bytes.
  48. */
  49. - if (len - i > 0 || xfersum_type != CSUM_MD4_BUSTED)
  50. + if (len - i > 0 || xfersum_type > CSUM_MD4_BUSTED)
  51. mdfour_update(&m, (uchar *)(buf1+i), len-i);
  52. mdfour_result(&m, (uchar *)sum);
  53. @@ -217,6 +218,7 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
  54. case CSUM_MD4:
  55. case CSUM_MD4_OLD:
  56. case CSUM_MD4_BUSTED:
  57. + case CSUM_MD4_ARCHAIC:
  58. mdfour_begin(&m);
  59. for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
  60. @@ -229,7 +231,7 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
  61. * are multiples of 64. This is fixed by calling mdfour_update()
  62. * even when there are no more bytes. */
  63. remainder = (int32)(len - i);
  64. - if (remainder > 0 || checksum_type != CSUM_MD4_BUSTED)
  65. + if (remainder > 0 || checksum_type > CSUM_MD4_BUSTED)
  66. mdfour_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder);
  67. mdfour_result(&m, (uchar *)sum);
  68. @@ -265,6 +267,7 @@ void sum_init(int csum_type, int seed)
  69. break;
  70. case CSUM_MD4_OLD:
  71. case CSUM_MD4_BUSTED:
  72. + case CSUM_MD4_ARCHAIC:
  73. mdfour_begin(&md);
  74. sumresidue = 0;
  75. SIVAL(s, 0, seed);
  76. @@ -321,6 +324,10 @@ void sum_update(const char *p, int32 len)
  77. }
  78. }
  79. +/* NOTE: all the callers of sum_end() pass in a pointer to a buffer that is
  80. + * MAX_DIGEST_LEN in size, so even if the csum-len is shorter that that (i.e.
  81. + * CSUM_MD4_ARCHAIC), we don't have to worry about limiting the data we write
  82. + * into the "sum" buffer. */
  83. int sum_end(char *sum)
  84. {
  85. switch (cursum_type) {
  86. @@ -333,6 +340,7 @@ int sum_end(char *sum)
  87. mdfour_result(&md, (uchar *)sum);
  88. break;
  89. case CSUM_MD4_BUSTED:
  90. + case CSUM_MD4_ARCHAIC:
  91. if (sumresidue)
  92. mdfour_update(&md, (uchar *)md.buffer, sumresidue);
  93. mdfour_result(&md, (uchar *)sum);