[SCM] The rsync repository. - branch master updated

Rsync CVS commit messages rsync-cvs at lists.samba.org
Mon May 2 00:07:14 UTC 2016


The branch, master has been updated
       via  a5a7d3a Add --checksum-choice option to choose the checksum algorithms.
       via  4fc7887 Tweak indentation only.
      from  b973bff If a backup fails (e.g. full disk) rsync should fail. Fixes bug 11668.

https://git.samba.org/?p=rsync.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a5a7d3a297b836387b0ac677383bdddaf2ac3598
Author: Wayne Davison <wayned at samba.org>
Date:   Sun May 1 16:32:45 2016 -0700

    Add --checksum-choice option to choose the checksum algorithms.

commit 4fc78878e01451d6465e2072f3f0653182f885c1
Author: Wayne Davison <wayned at samba.org>
Date:   Sun May 1 16:29:34 2016 -0700

    Tweak indentation only.

-----------------------------------------------------------------------

Summary of changes:
 NEWS           |  16 ++++-
 authenticate.c |   4 +-
 checksum.c     | 196 +++++++++++++++++++++++++++++++++++++++++++++------------
 compat.c       |   2 +
 flist.c        |   6 +-
 log.c          |  20 +++---
 main.c         |   2 -
 match.c        |   9 +--
 options.c      |  18 ++++++
 receiver.c     |   8 +--
 rsync.yo       |  18 +++++-
 rsyncd.conf.yo |   2 +-
 t_stub.c       |   6 +-
 util2.c        |   5 +-
 xattrs.c       |   4 +-
 15 files changed, 241 insertions(+), 75 deletions(-)


Changeset truncated at 500 lines:

diff --git a/NEWS b/NEWS
index bffdeb7..67047d2 100644
--- a/NEWS
+++ b/NEWS
@@ -4,9 +4,21 @@ Changes since 3.1.2:
 
   BUG FIXES:
 
-    - ...
+    - Don't output about a new backup dir with appropriate info verbosity.
+    - Fixed some issues with the sort functions in support/rsyncstats.
+    - Added a way to specify group names that contain spaces in daemon config.
+    - If a backup fails (e.g. full disk) rsync exits with an error.
+    - Avoid invalid output in the summary if either the start or end time had
+      an error.
 
   ENHANCEMENTS:
 
-    - Add the ability for rsync to compare nanosecond times in its file-check
+    - Added the ability for rsync to compare nanosecond times in its file-check
       comparisons.  Also added a short-option (-@) for --modify-window.
+    - Added the --checksum-choice=NAME[,NAME] option to choose the checksum
+      algorithms.
+
+  DEVELOPER RELATED:
+
+    - Tweak the "make" output when yodl isn't around to create the man pages.
+    - Changed an obsolete compile macro in configure.
diff --git a/authenticate.c b/authenticate.c
index 5f125de..d60ee20 100644
--- a/authenticate.c
+++ b/authenticate.c
@@ -71,7 +71,7 @@ static void gen_challenge(const char *addr, char *challenge)
 	SIVAL(input, 20, tv.tv_usec);
 	SIVAL(input, 24, getpid());
 
-	sum_init(0);
+	sum_init(-1, 0);
 	sum_update(input, sizeof input);
 	len = sum_end(digest);
 
@@ -85,7 +85,7 @@ static void generate_hash(const char *in, const char *challenge, char *out)
 	char buf[MAX_DIGEST_LEN];
 	int len;
 
-	sum_init(0);
+	sum_init(-1, 0);
 	sum_update(in, strlen(in));
 	sum_update(challenge, strlen(challenge));
 	len = sum_end(buf);
diff --git a/checksum.c b/checksum.c
index 6ebb56b..8b38833 100644
--- a/checksum.c
+++ b/checksum.c
@@ -24,6 +24,76 @@
 extern int checksum_seed;
 extern int protocol_version;
 extern int proper_seed_order;
+extern char *checksum_choice;
+
+#define CSUM_NONE 0
+#define CSUM_ARCHAIC 1
+#define CSUM_MD4_BUSTED 2
+#define CSUM_MD4_OLD 3
+#define CSUM_MD4 4
+#define CSUM_MD5 5
+
+int xfersum_type = 0; /* used for the file transfer checksums */
+int checksum_type = 0; /* used for the pre-transfer (--checksum) checksums */
+
+/* Returns 1 if --whole-file must be enabled. */
+int parse_checksum_choice(void)
+{
+	char *cp = checksum_choice ? strchr(checksum_choice, ',') : NULL;
+	if (cp) {
+		xfersum_type = parse_csum_name(checksum_choice, cp - checksum_choice);
+		checksum_type = parse_csum_name(cp+1, -1);
+	} else
+		xfersum_type = checksum_type = parse_csum_name(checksum_choice, -1);
+	return xfersum_type == CSUM_NONE;
+}
+
+int parse_csum_name(const char *name, int len)
+{
+	if (len < 0 && name)
+		len = strlen(name);
+
+	if (!name || (len == 4 && strncasecmp(name, "auto", 4) == 0)) {
+		if (protocol_version >= 30)
+			return CSUM_MD5;
+		if (protocol_version >= 27)
+			return CSUM_MD4_OLD;
+		if (protocol_version >= 21)
+			return CSUM_MD4_BUSTED;
+		return CSUM_ARCHAIC;
+	}
+	if (len == 3 && strncasecmp(name, "md4", 3) == 0)
+		return CSUM_MD4;
+	if (len == 3 && strncasecmp(name, "md5", 3) == 0)
+		return CSUM_MD5;
+	if (len == 4 && strncasecmp(name, "none", 4) == 0)
+		return CSUM_NONE;
+
+	rprintf(FERROR, "unknown checksum name: %s\n", name);
+	exit_cleanup(RERR_UNSUPPORTED);
+}
+
+int csum_len_for_type(int cst)
+{
+	switch (cst) {
+	  case CSUM_NONE:
+		return 1;
+	  case CSUM_ARCHAIC:
+		return 2;
+	  case CSUM_MD4:
+	  case CSUM_MD4_OLD:
+	  case CSUM_MD4_BUSTED:
+		return MD4_DIGEST_LEN;
+	  case CSUM_MD5:
+		return MD5_DIGEST_LEN;
+	}
+	return 0;
+}
+
+int canonical_checksum(int csum_type)
+{
+    return csum_type >= CSUM_MD4 ? 1 : 0;
+}
 
 /*
   a simple 32 bit checksum that can be upadted from either end
@@ -47,12 +117,12 @@ uint32 get_checksum1(char *buf1, int32 len)
     return (s1 & 0xffff) + (s2 << 16);
 }
 
-
 void get_checksum2(char *buf, int32 len, char *sum)
 {
 	md_context m;
 
-	if (protocol_version >= 30) {
+	switch (xfersum_type) {
+	  case CSUM_MD5: {
 		uchar seedbuf[4];
 		md5_begin(&m);
 		if (proper_seed_order) {
@@ -69,7 +139,11 @@ void get_checksum2(char *buf, int32 len, char *sum)
 			}
 		}
 		md5_result(&m, (uchar *)sum);
-	} else {
+		break;
+	  }
+	  case CSUM_MD4:
+	  case CSUM_MD4_OLD:
+	  case CSUM_MD4_BUSTED: {
 		int32 i;
 		static char *buf1;
 		static int32 len1;
@@ -100,10 +174,12 @@ void get_checksum2(char *buf, int32 len, char *sum)
 		 * are multiples of 64.  This is fixed by calling mdfour_update()
 		 * even when there are no more bytes.
 		 */
-		if (len - i > 0 || protocol_version >= 27)
+		if (len - i > 0 || xfersum_type != CSUM_MD4_BUSTED)
 			mdfour_update(&m, (uchar *)(buf1+i), len-i);
 
 		mdfour_result(&m, (uchar *)sum);
+		break;
+	  }
 	}
 }
 
@@ -123,7 +199,8 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
 
 	buf = map_file(fd, len, MAX_MAP_SIZE, CSUM_CHUNK);
 
-	if (protocol_version >= 30) {
+	switch (checksum_type) {
+	  case CSUM_MD5:
 		md5_begin(&m);
 
 		for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
@@ -136,7 +213,10 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
 			md5_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder);
 
 		md5_result(&m, (uchar *)sum);
-	} else {
+		break;
+	  case CSUM_MD4:
+	  case CSUM_MD4_OLD:
+	  case CSUM_MD4_BUSTED:
 		mdfour_begin(&m);
 
 		for (i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) {
@@ -149,10 +229,14 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
 		 * are multiples of 64.  This is fixed by calling mdfour_update()
 		 * even when there are no more bytes. */
 		remainder = (int32)(len - i);
-		if (remainder > 0 || protocol_version >= 27)
+		if (remainder > 0 || checksum_type != CSUM_MD4_BUSTED)
 			mdfour_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder);
 
 		mdfour_result(&m, (uchar *)sum);
+		break;
+	  default:
+		rprintf(FERROR, "invalid checksum-choice for the --checksum option (%d)\n", checksum_type);
+		exit_cleanup(RERR_UNSUPPORTED);
 	}
 
 	close(fd);
@@ -161,18 +245,33 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
 
 static int32 sumresidue;
 static md_context md;
+static int cursum_type;
 
-void sum_init(int seed)
+void sum_init(int csum_type, int seed)
 {
 	char s[4];
 
-	if (protocol_version >= 30)
+	if (csum_type < 0)
+		csum_type = parse_csum_name(NULL, 0);
+	cursum_type = csum_type;
+
+	switch (csum_type) {
+	  case CSUM_MD5:
 		md5_begin(&md);
-	else {
+		break;
+	  case CSUM_MD4:
+		mdfour_begin(&md);
+		sumresidue = 0;
+		break;
+	  case CSUM_MD4_OLD:
+	  case CSUM_MD4_BUSTED:
 		mdfour_begin(&md);
 		sumresidue = 0;
 		SIVAL(s, 0, seed);
 		sum_update(s, 4);
+		break;
+	  case CSUM_NONE:
+		break;
 	}
 }
 
@@ -186,47 +285,62 @@ void sum_init(int seed)
  **/
 void sum_update(const char *p, int32 len)
 {
-	if (protocol_version >= 30) {
+	switch (cursum_type) {
+	  case CSUM_MD5:
 		md5_update(&md, (uchar *)p, len);
-		return;
-	}
+		break;
+	  case CSUM_MD4:
+	  case CSUM_MD4_OLD:
+	  case CSUM_MD4_BUSTED:
+		if (len + sumresidue < CSUM_CHUNK) {
+			memcpy(md.buffer + sumresidue, p, len);
+			sumresidue += len;
+			break;
+		}
 
-	if (len + sumresidue < CSUM_CHUNK) {
-		memcpy(md.buffer + sumresidue, p, len);
-		sumresidue += len;
-		return;
-	}
+		if (sumresidue) {
+			int32 i = CSUM_CHUNK - sumresidue;
+			memcpy(md.buffer + sumresidue, p, i);
+			mdfour_update(&md, (uchar *)md.buffer, CSUM_CHUNK);
+			len -= i;
+			p += i;
+		}
 
-	if (sumresidue) {
-		int32 i = CSUM_CHUNK - sumresidue;
-		memcpy(md.buffer + sumresidue, p, i);
-		mdfour_update(&md, (uchar *)md.buffer, CSUM_CHUNK);
-		len -= i;
-		p += i;
-	}
+		while (len >= CSUM_CHUNK) {
+			mdfour_update(&md, (uchar *)p, CSUM_CHUNK);
+			len -= CSUM_CHUNK;
+			p += CSUM_CHUNK;
+		}
 
-	while (len >= CSUM_CHUNK) {
-		mdfour_update(&md, (uchar *)p, CSUM_CHUNK);
-		len -= CSUM_CHUNK;
-		p += CSUM_CHUNK;
+		sumresidue = len;
+		if (sumresidue)
+			memcpy(md.buffer, p, sumresidue);
+		break;
+	  case CSUM_NONE:
+		break;
 	}
-
-	sumresidue = len;
-	if (sumresidue)
-		memcpy(md.buffer, p, sumresidue);
 }
 
 int sum_end(char *sum)
 {
-	if (protocol_version >= 30) {
+	switch (cursum_type) {
+	  case CSUM_MD5:
 		md5_result(&md, (uchar *)sum);
-		return MD5_DIGEST_LEN;
-	}
-
-	if (sumresidue || protocol_version >= 27)
+		break;
+	  case CSUM_MD4:
+	  case CSUM_MD4_OLD:
 		mdfour_update(&md, (uchar *)md.buffer, sumresidue);
+		mdfour_result(&md, (uchar *)sum);
+		break;
+	  case CSUM_MD4_BUSTED:
+		if (sumresidue)
+			mdfour_update(&md, (uchar *)md.buffer, sumresidue);
+		mdfour_result(&md, (uchar *)sum);
+		break;
+	  case CSUM_NONE:
+		*sum = '\0';
+		break;
+	}
 
-	mdfour_result(&md, (uchar *)sum);
-
-	return MD4_DIGEST_LEN;
+	return csum_len_for_type(cursum_type);
 }
diff --git a/compat.c b/compat.c
index c792312..505cb7f 100644
--- a/compat.c
+++ b/compat.c
@@ -338,4 +338,6 @@ void setup_protocol(int f_out,int f_in)
 	} else {
 		checksum_seed = read_int(f_in);
 	}
+
+	init_flist();
 }
diff --git a/flist.c b/flist.c
index c1e48b3..acb95f7 100644
--- a/flist.c
+++ b/flist.c
@@ -33,6 +33,7 @@ extern int am_sender;
 extern int am_generator;
 extern int inc_recurse;
 extern int always_checksum;
+extern int checksum_type;
 extern int module_id;
 extern int ignore_errors;
 extern int numeric_ids;
@@ -137,9 +138,8 @@ void init_flist(void)
 		rprintf(FINFO, "FILE_STRUCT_LEN=%d, EXTRA_LEN=%d\n",
 			(int)FILE_STRUCT_LEN, (int)EXTRA_LEN);
 	}
-	checksum_len = protocol_version < 21 ? 2
-		     : protocol_version < 30 ? MD4_DIGEST_LEN
-		     : MD5_DIGEST_LEN;
+	parse_checksum_choice(); /* Sets checksum_type && xfersum_type */
+	checksum_len = csum_len_for_type(checksum_type);
 }
 
 static int show_filelist_p(void)
diff --git a/log.c b/log.c
index 24256de..f7da1e5 100644
--- a/log.c
+++ b/log.c
@@ -31,12 +31,13 @@ extern int am_generator;
 extern int local_server;
 extern int quiet;
 extern int module_id;
-extern int checksum_len;
 extern int allow_8bit_chars;
 extern int protocol_version;
 extern int always_checksum;
 extern int preserve_times;
 extern int msgs2stderr;
+extern int xfersum_type;
+extern int checksum_type;
 extern int stdout_format_has_i;
 extern int stdout_format_has_o_or_i;
 extern int logfile_format_has_i;
@@ -46,6 +47,7 @@ extern int64 total_data_written;
 extern int64 total_data_read;
 extern mode_t orig_umask;
 extern char *auth_user;
+extern char *checksum_choice;
 extern char *stdout_format;
 extern char *logfile_format;
 extern char *logfile_name;
@@ -669,13 +671,15 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
 			n = buf2;
 			break;
 		case 'C':
-			if (protocol_version >= 30
-			 && (iflags & ITEM_TRANSFER
-			  || (always_checksum && S_ISREG(file->mode)))) {
-				const char *sum = iflags & ITEM_TRANSFER
-						? sender_file_sum : F_SUM(file);
-				n = sum_as_hex(sum);
-			} else {
+			n = NULL;
+			if (S_ISREG(file->mode)) {
+				if (always_checksum && canonical_checksum(checksum_type))
+					n = sum_as_hex(checksum_type, F_SUM(file));
+				else if (iflags & ITEM_TRANSFER && canonical_checksum(xfersum_type))
+					n = sum_as_hex(xfersum_type, sender_file_sum);
+			}
+			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';
 				n = buf2;
diff --git a/main.c b/main.c
index 3132aa9..3908ccf 100644
--- a/main.c
+++ b/main.c
@@ -1595,8 +1595,6 @@ int main(int argc,char *argv[])
 	 * that implement getcwd that way "pwd" can't be found after chroot. */
 	change_dir(NULL, CD_NORMAL);
 
-	init_flist();
-
 	if ((write_batch || read_batch) && !am_server) {
 		if (write_batch)
 			write_batch_shell_file(orig_argc, orig_argv, argc);
diff --git a/match.c b/match.c
index b15f2eb..ff10310 100644
--- a/match.c
+++ b/match.c
@@ -24,7 +24,7 @@
 
 extern int checksum_seed;
 extern int append_mode;
-extern int checksum_len;
+extern int xfersum_type;
 
 int updating_basis_file;
 char sender_file_sum[MAX_DIGEST_LEN];
@@ -360,13 +360,15 @@ 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;
+
 	last_match = 0;
 	false_alarms = 0;
 	hash_hits = 0;
 	matches = 0;
 	data_transfer = 0;
 
-	sum_init(checksum_seed);
+	sum_init(xfersum_type, checksum_seed);
 
 	if (append_mode > 0) {
 		if (append_mode == 2) {
@@ -407,8 +409,7 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
 		matched(f, s, buf, len, -1);
 	}
 
-	if (sum_end(sender_file_sum) != checksum_len)
-		overflow_exit("checksum_len"); /* Impossible... */
+	checksum_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
diff --git a/options.c b/options.c
index 4a5cdc8..308443b 100644
--- a/options.c
+++ b/options.c
@@ -182,6 +182,7 @@ char *dest_option = NULL;
 static int remote_option_alloc = 0;
 int remote_option_cnt = 0;
 const char **remote_options = NULL;
+const char *checksum_choice = NULL;
 
 int quiet = 0;
 int output_motd = 1;
@@ -721,6 +722,7 @@ void usage(enum logcode F)
 #endif
   rprintf(F," -n, --dry-run               perform a trial run with no changes made\n");
   rprintf(F," -W, --whole-file            copy files whole (without delta-xfer algorithm)\n");
+  rprintf(F,"     --checksum-choice=STR   choose the checksum algorithms\n");
   rprintf(F," -x, --one-file-system       don't cross filesystem boundaries\n");
   rprintf(F," -B, --block-size=SIZE       force a fixed checksum block-size\n");
   rprintf(F," -e, --rsh=COMMAND           specify the remote shell to use\n");


-- 
The rsync repository.



More information about the rsync-cvs mailing list