openwrt-packages/net/rsync/patches/011-more-archaic-checksum-i...

272 lines
8.5 KiB
Diff

commit 416e719bea4f5466c8dd2b34cac0059b6ff84ff3
Author: Wayne Davison <wayned@samba.org>
Date: Tue Nov 7 14:01:13 2017 -0800
More archaic-checksum improvements. This makes the len vars clearer
and ensures that only the flist code gets the 2-byte digest len.
diff --git a/authenticate.c b/authenticate.c
index 519429d..d60ee20 100644
--- a/authenticate.c
+++ b/authenticate.c
@@ -74,8 +74,6 @@ static void gen_challenge(const char *addr, char *challenge)
sum_init(-1, 0);
sum_update(input, sizeof input);
len = sum_end(digest);
- if (len == 2) /* The archaic checksum is 2 bytes, but sum_end() filled in the full MD4 checksum for us. */
- len = MD4_DIGEST_LEN;
base64_encode(digest, len, challenge, 0);
}
@@ -91,8 +89,6 @@ static void generate_hash(const char *in, const char *challenge, char *out)
sum_update(in, strlen(in));
sum_update(challenge, strlen(challenge));
len = sum_end(buf);
- if (len == 2) /* The archaic checksum is 2 bytes, but sum_end() filled in the full MD4 checksum for us. */
- len = MD4_DIGEST_LEN;
base64_encode(buf, len, out, 0);
}
diff --git a/checksum.c b/checksum.c
index 741ad7d..4c9351c 100644
--- a/checksum.c
+++ b/checksum.c
@@ -73,13 +73,15 @@ int parse_csum_name(const char *name, int len)
exit_cleanup(RERR_UNSUPPORTED);
}
-int csum_len_for_type(int cst)
+int csum_len_for_type(int cst, int flist_csum)
{
switch (cst) {
case CSUM_NONE:
return 1;
case CSUM_MD4_ARCHAIC:
- return 2;
+ /* The oldest checksum code is rather weird: the file-list code only sent
+ * 2-byte checksums, but all other checksums were full MD4 length. */
+ return flist_csum ? 2 : MD4_DIGEST_LEN;
case CSUM_MD4:
case CSUM_MD4_OLD:
case CSUM_MD4_BUSTED:
@@ -361,5 +363,5 @@ int sum_end(char *sum)
exit_cleanup(RERR_UNSUPPORTED);
}
- return csum_len_for_type(cursum_type);
+ return csum_len_for_type(cursum_type, 0);
}
diff --git a/flist.c b/flist.c
index 24b3506..bedba63 100644
--- a/flist.c
+++ b/flist.c
@@ -91,7 +91,7 @@ extern iconv_t ic_send, ic_recv;
#define PTR_SIZE (sizeof (struct file_struct *))
int io_error;
-int checksum_len;
+int flist_csum_len;
dev_t filesystem_dev; /* used to implement -x */
struct file_list *cur_flist, *first_flist, *dir_flist;
@@ -141,7 +141,7 @@ void init_flist(void)
(int)FILE_STRUCT_LEN, (int)EXTRA_LEN);
}
parse_checksum_choice(); /* Sets checksum_type && xfersum_type */
- checksum_len = csum_len_for_type(checksum_type);
+ flist_csum_len = csum_len_for_type(checksum_type, 1);
show_filelist_progress = INFO_GTE(FLIST, 1) && xfer_dirs && !am_server && !inc_recurse;
}
@@ -638,7 +638,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
/* Prior to 28, we sent a useless set of nulls. */
sum = empty_sum;
}
- write_buf(f, sum, checksum_len);
+ write_buf(f, sum, flist_csum_len);
}
#ifdef SUPPORT_HARD_LINKS
@@ -1094,9 +1094,9 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
}
if (first_hlink_ndx >= flist->ndx_start) {
struct file_struct *first = flist->files[first_hlink_ndx - flist->ndx_start];
- memcpy(bp, F_SUM(first), checksum_len);
+ memcpy(bp, F_SUM(first), flist_csum_len);
} else
- read_buf(f, bp, checksum_len);
+ read_buf(f, bp, flist_csum_len);
}
#ifdef SUPPORT_ACLS
@@ -1384,7 +1384,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
}
if (sender_keeps_checksum && S_ISREG(st.st_mode))
- memcpy(F_SUM(file), tmp_sum, checksum_len);
+ memcpy(F_SUM(file), tmp_sum, flist_csum_len);
if (unsort_ndx)
F_NDX(file) = stats.num_dirs;
diff --git a/generator.c b/generator.c
index af2e290..3d65839 100644
--- a/generator.c
+++ b/generator.c
@@ -74,7 +74,7 @@ extern int protocol_version;
extern int file_total;
extern int fuzzy_basis;
extern int always_checksum;
-extern int checksum_len;
+extern int flist_csum_len;
extern char *partial_dir;
extern int compare_dest;
extern int copy_dest;
@@ -583,7 +583,7 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
if (always_checksum > 0 && S_ISREG(st->st_mode)) {
char sum[MAX_DIGEST_LEN];
file_checksum(fn, st, sum);
- return memcmp(sum, F_SUM(file), checksum_len) == 0;
+ return memcmp(sum, F_SUM(file), flist_csum_len) == 0;
}
if (size_only > 0)
diff --git a/log.c b/log.c
index b145ee1..7b23a2c 100644
--- a/log.c
+++ b/log.c
@@ -673,14 +673,15 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
n = NULL;
if (S_ISREG(file->mode)) {
if (always_checksum && canonical_checksum(checksum_type))
- n = sum_as_hex(checksum_type, F_SUM(file));
+ n = sum_as_hex(checksum_type, F_SUM(file), 1);
else if (iflags & ITEM_TRANSFER && canonical_checksum(xfersum_type))
- n = sum_as_hex(xfersum_type, sender_file_sum);
+ n = sum_as_hex(xfersum_type, sender_file_sum, 0);
}
if (!n) {
- int checksum_len = csum_len_for_type(always_checksum ? checksum_type : xfersum_type);
- memset(buf2, ' ', checksum_len*2);
- buf2[checksum_len*2] = '\0';
+ int sum_len = csum_len_for_type(always_checksum ? checksum_type : xfersum_type,
+ always_checksum);
+ memset(buf2, ' ', sum_len*2);
+ buf2[sum_len*2] = '\0';
n = buf2;
}
break;
diff --git a/match.c b/match.c
index ff10310..280038b 100644
--- a/match.c
+++ b/match.c
@@ -360,7 +360,7 @@ static void hash_search(int f,struct sum_struct *s,
**/
void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
{
- int checksum_len;
+ int sum_len;
last_match = 0;
false_alarms = 0;
@@ -409,22 +409,22 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
matched(f, s, buf, len, -1);
}
- checksum_len = sum_end(sender_file_sum);
+ sum_len = sum_end(sender_file_sum);
/* If we had a read error, send a bad checksum. We use all bits
* off as long as the checksum doesn't happen to be that, in
* which case we turn the last 0 bit into a 1. */
if (buf && buf->status != 0) {
int i;
- for (i = 0; i < checksum_len && sender_file_sum[i] == 0; i++) {}
- memset(sender_file_sum, 0, checksum_len);
- if (i == checksum_len)
+ for (i = 0; i < sum_len && sender_file_sum[i] == 0; i++) {}
+ memset(sender_file_sum, 0, sum_len);
+ if (i == sum_len)
sender_file_sum[i-1]++;
}
if (DEBUG_GTE(DELTASUM, 2))
rprintf(FINFO,"sending file_sum\n");
- write_buf(f, sender_file_sum, checksum_len);
+ write_buf(f, sender_file_sum, sum_len);
if (DEBUG_GTE(DELTASUM, 2)) {
rprintf(FINFO, "false_alarms=%d hash_hits=%d matches=%d\n",
diff --git a/receiver.c b/receiver.c
index 3d9bc65..baae3a9 100644
--- a/receiver.c
+++ b/receiver.c
@@ -236,7 +236,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
static char file_sum1[MAX_DIGEST_LEN];
struct map_struct *mapbuf;
struct sum_struct sum;
- int checksum_len;
+ int sum_len;
int32 len;
OFF_T offset = 0;
OFF_T offset2;
@@ -388,15 +388,15 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
if (INFO_GTE(PROGRESS, 1))
end_progress(total_size);
- checksum_len = sum_end(file_sum1);
+ sum_len = sum_end(file_sum1);
if (mapbuf)
unmap_file(mapbuf);
- read_buf(f_in, sender_file_sum, checksum_len);
+ read_buf(f_in, sender_file_sum, sum_len);
if (DEBUG_GTE(DELTASUM, 2))
rprintf(FINFO,"got file_sum\n");
- if (fd != -1 && memcmp(file_sum1, sender_file_sum, checksum_len) != 0)
+ if (fd != -1 && memcmp(file_sum1, sender_file_sum, sum_len) != 0)
return 0;
return 1;
}
diff --git a/t_stub.c b/t_stub.c
index fc1ee3b..0c49d9c 100644
--- a/t_stub.c
+++ b/t_stub.c
@@ -98,7 +98,7 @@ filter_rule_list daemon_filter_list;
return "tester";
}
- int csum_len_for_type(int cst)
+ int csum_len_for_type(int cst, int flg)
{
- return cst ? 16 : 1;
+ return cst || !flg ? 16 : 1;
}
diff --git a/util2.c b/util2.c
index a892e51..b1adf81 100644
--- a/util2.c
+++ b/util2.c
@@ -77,18 +77,18 @@ void *_realloc_array(void *ptr, unsigned int size, size_t num)
return realloc(ptr, size * num);
}
-const char *sum_as_hex(int csum_type, const char *sum)
+const char *sum_as_hex(int csum_type, const char *sum, int flist_csum)
{
static char buf[MAX_DIGEST_LEN*2+1];
int i, x1, x2;
- int checksum_len = csum_len_for_type(csum_type);
- char *c = buf + checksum_len*2;
+ int sum_len = csum_len_for_type(csum_type, flist_csum);
+ char *c = buf + sum_len*2;
assert(c - buf < (int)sizeof buf);
*c = '\0';
- for (i = checksum_len; --i >= 0; ) {
+ for (i = sum_len; --i >= 0; ) {
x1 = CVAL(sum, i);
x2 = x1 >> 4;
x1 &= 0xF;