More archaic-checksum improvements. This makes the len vars clearer
authorWayne Davison <wayned@samba.org>
Tue, 7 Nov 2017 22:01:13 +0000 (14:01 -0800)
committerWayne Davison <wayned@samba.org>
Tue, 7 Nov 2017 22:01:13 +0000 (14:01 -0800)
and ensures that only the flist code gets the 2-byte digest len.

authenticate.c
checksum.c
flist.c
generator.c
log.c
match.c
receiver.c
t_stub.c
util2.c

index 519429dc6b82708ed61eedc588c2179fdc8068aa..d60ee20b6b53a9351efbdf175f36525ead220de6 100644 (file)
@@ -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);
 }
index 741ad7dfb63a8205db555127f10a36cb0c8c6757..4c9351ce278dc2f7bfa9db18f09a58c568ce010b 100644 (file)
@@ -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 24b3506fcb36287c54991f7a4ab1fb2d2e344129..bedba635e7e03e8679d7fc04daf89432ad0f0c0e 100644 (file)
--- 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;
index af2e2902df053f5989188830bef4e3fd6ec6c796..3d65839b23e935393eb3bdad9724820ff251b3c4 100644 (file)
@@ -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 b145ee1d893904835cd3c9276ec7c9c6fbaf13f3..7b23a2c6497ccf483678d58f1e1ff411a12342e9 100644 (file)
--- 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 ff10310ae317271d7943d5075c521a4a601c703e..280038bfeb1e6fea953f39001a96b7d73a3d63da 100644 (file)
--- 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",
index 3d9bc65f0238312df778e93ee08982b9aaf1cd9b..baae3a919cdd5db81afdb6c6bacd22081ff098e5 100644 (file)
@@ -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;
 }
index fc1ee3b9d61ace0e3a07569dcafdf6c908162d4f..0c49d9cb6fd9a1e7cf39afb4e3f691bed76f35ad 100644 (file)
--- 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 a892e518fff2be9983298635e9791eda618354ed..b1adf8148eaab27419826825c70eeae40fdd89db 100644 (file)
--- 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;