Blame SOURCES/rsync-3.1.3-cve-2022-29154.patch

31ff15
diff --git a/exclude.c b/exclude.c
31ff15
index 7989fb3..13c4253 100644
31ff15
--- a/exclude.c
31ff15
+++ b/exclude.c
31ff15
@@ -24,18 +24,26 @@
31ff15
 
31ff15
 extern int am_server;
31ff15
 extern int am_sender;
31ff15
+extern int am_generator;
31ff15
 extern int eol_nulls;
31ff15
 extern int io_error;
31ff15
+extern int xfer_dirs;
31ff15
+extern int recurse;
31ff15
 extern int local_server;
31ff15
 extern int prune_empty_dirs;
31ff15
 extern int ignore_perishable;
31ff15
+extern int old_style_args;
31ff15
+extern int relative_paths;
31ff15
 extern int delete_mode;
31ff15
 extern int delete_excluded;
31ff15
 extern int cvs_exclude;
31ff15
 extern int sanitize_paths;
31ff15
 extern int protocol_version;
31ff15
+extern int read_batch;
31ff15
+extern int list_only;
31ff15
 extern int module_id;
31ff15
 
31ff15
+extern char *filesfrom_host;
31ff15
 extern char curr_dir[MAXPATHLEN];
31ff15
 extern unsigned int curr_dir_len;
31ff15
 extern unsigned int module_dirlen;
31ff15
@@ -43,8 +51,10 @@ extern unsigned int module_dirlen;
31ff15
 filter_rule_list filter_list = { .debug_type = "" };
31ff15
 filter_rule_list cvs_filter_list = { .debug_type = " [global CVS]" };
31ff15
 filter_rule_list daemon_filter_list = { .debug_type = " [daemon]" };
31ff15
+filter_rule_list implied_filter_list = { .debug_type = " [implied]" };
31ff15
 
31ff15
 int saw_xattr_filter = 0;
31ff15
+int trust_sender_filter = 0;
31ff15
 
31ff15
 /* Need room enough for ":MODS " prefix plus some room to grow. */
31ff15
 #define MAX_RULE_PREFIX (16)
31ff15
@@ -293,6 +303,233 @@ static void add_rule(filter_rule_list *listp, const char *pat, unsigned int pat_
31ff15
 	}
31ff15
 }
31ff15
 
31ff15
+/* If the wildcards failed, the remote shell might give us a file matching the literal
31ff15
+ * wildcards.  Since "*" & "?" already match themselves, this just needs to deal with
31ff15
+ * failed "[foo]" idioms.
31ff15
+ */
31ff15
+static void maybe_add_literal_brackets_rule(filter_rule const *based_on, int arg_len)
31ff15
+{
31ff15
+	filter_rule *rule;
31ff15
+	const char *arg = based_on->pattern, *cp;
31ff15
+	char *p;
31ff15
+	int cnt = 0;
31ff15
+
31ff15
+	if (arg_len < 0)
31ff15
+		arg_len = strlen(arg);
31ff15
+
31ff15
+	for (cp = arg; *cp; cp++) {
31ff15
+		if (*cp == '\\' && cp[1]) {
31ff15
+			cp++;
31ff15
+		} else if (*cp == '[')
31ff15
+			cnt++;
31ff15
+	}
31ff15
+	if (!cnt)
31ff15
+		return;
31ff15
+
31ff15
+	rule = new0(filter_rule);
31ff15
+	rule->rflags = based_on->rflags;
31ff15
+	rule->u.slash_cnt = based_on->u.slash_cnt;
31ff15
+	p = rule->pattern = new_array(char, arg_len + cnt + 1);
31ff15
+	for (cp = arg; *cp; ) {
31ff15
+		if (*cp == '\\' && cp[1]) {
31ff15
+			*p++ = *cp++;
31ff15
+		} else if (*cp == '[')
31ff15
+			*p++ = '\\';
31ff15
+		*p++ = *cp++;
31ff15
+	}
31ff15
+	*p++ = '\0';
31ff15
+
31ff15
+	rule->next = implied_filter_list.head;
31ff15
+	implied_filter_list.head = rule;
31ff15
+	if (DEBUG_GTE(FILTER, 3)) {
31ff15
+		rprintf(FINFO, "[%s] add_implied_include(%s%s)\n", who_am_i(), rule->pattern,
31ff15
+			rule->rflags & FILTRULE_DIRECTORY ? "/" : "");
31ff15
+	}
31ff15
+}
31ff15
+
31ff15
+static char *partial_string_buf = NULL;
31ff15
+static int partial_string_len = 0;
31ff15
+void implied_include_partial_string(const char *s_start, const char *s_end)
31ff15
+{
31ff15
+	partial_string_len = s_end - s_start;
31ff15
+	if (partial_string_len <= 0 || partial_string_len >= MAXPATHLEN) { /* too-large should be impossible... */
31ff15
+		partial_string_len = 0;
31ff15
+		return;
31ff15
+	}
31ff15
+	if (!partial_string_buf)
31ff15
+		partial_string_buf = new_array(char, MAXPATHLEN);
31ff15
+	memcpy(partial_string_buf, s_start, partial_string_len);
31ff15
+}
31ff15
+
31ff15
+void free_implied_include_partial_string()
31ff15
+{
31ff15
+	if (partial_string_buf) {
31ff15
+		free(partial_string_buf);
31ff15
+		partial_string_buf = NULL;
31ff15
+	}
31ff15
+	partial_string_len = 0; /* paranoia */
31ff15
+}
31ff15
+
31ff15
+/* Each arg the client sends to the remote sender turns into an implied include
31ff15
+ * that the receiver uses to validate the file list from the sender. */
31ff15
+void add_implied_include(const char *arg, int skip_daemon_module)
31ff15
+{
31ff15
+	filter_rule *rule;
31ff15
+	int arg_len, saw_wild = 0, saw_live_open_brkt = 0, backslash_cnt = 0;
31ff15
+	int slash_cnt = 1; /* We know we're adding a leading slash. */
31ff15
+	const char *cp;
31ff15
+	char *p;
31ff15
+	if (am_server || old_style_args || list_only || read_batch || filesfrom_host != NULL)
31ff15
+		return;
31ff15
+	if (partial_string_len) {
31ff15
+		arg_len = strlen(arg);
31ff15
+		if (partial_string_len + arg_len >= MAXPATHLEN) {
31ff15
+			partial_string_len = 0;
31ff15
+			return; /* Should be impossible... */
31ff15
+		}
31ff15
+		memcpy(partial_string_buf + partial_string_len, arg, arg_len + 1);
31ff15
+		partial_string_len = 0;
31ff15
+		arg = partial_string_buf;
31ff15
+	}
31ff15
+	if (skip_daemon_module) {
31ff15
+		if ((cp = strchr(arg, '/')) != NULL)
31ff15
+			arg = cp + 1;
31ff15
+		else
31ff15
+			arg = "";
31ff15
+	}
31ff15
+	if (relative_paths) {
31ff15
+		if ((cp = strstr(arg, "/./")) != NULL)
31ff15
+			arg = cp + 3;
31ff15
+	} else if ((cp = strrchr(arg, '/')) != NULL) {
31ff15
+		arg = cp + 1;
31ff15
+	}
31ff15
+	if (*arg == '.' && arg[1] == '\0')
31ff15
+		arg++;
31ff15
+	arg_len = strlen(arg);
31ff15
+	if (arg_len) {
31ff15
+		if (strpbrk(arg, "*[?")) {
31ff15
+			/* We need to add room to escape backslashes if wildcard chars are present. */
31ff15
+			for (cp = arg; (cp = strchr(cp, '\\')) != NULL; cp++)
31ff15
+				arg_len++;
31ff15
+			saw_wild = 1;
31ff15
+		}
31ff15
+		arg_len++; /* Leave room for the prefixed slash */
31ff15
+		rule = new0(filter_rule);
31ff15
+		if (!implied_filter_list.head)
31ff15
+			implied_filter_list.head = implied_filter_list.tail = rule;
31ff15
+		else {
31ff15
+			rule->next = implied_filter_list.head;
31ff15
+			implied_filter_list.head = rule;
31ff15
+		}
31ff15
+		rule->rflags = FILTRULE_INCLUDE + (saw_wild ? FILTRULE_WILD : 0);
31ff15
+		p = rule->pattern = new_array(char, arg_len + 1);
31ff15
+		*p++ = '/';
31ff15
+		for (cp = arg; *cp; ) {
31ff15
+			switch (*cp) {
31ff15
+			  case '\\':
31ff15
+				if (cp[1] == ']') {
31ff15
+					if (!saw_wild)
31ff15
+						cp++; /* A \] in a non-wild filter causes a problem, so drop the \ . */
31ff15
+				} else if (!strchr("*[?", cp[1])) {
31ff15
+					backslash_cnt++;
31ff15
+					if (saw_wild)
31ff15
+						*p++ = '\\';
31ff15
+				}
31ff15
+				*p++ = *cp++;
31ff15
+				break;
31ff15
+			  case '/':
31ff15
+				if (p[-1] == '/') { /* This is safe because of the initial slash. */
31ff15
+					cp++;
31ff15
+					break;
31ff15
+				}
31ff15
+				if (relative_paths) {
31ff15
+					filter_rule const *ent;
31ff15
+					int found = 0;
31ff15
+					*p = '\0';
31ff15
+					for (ent = implied_filter_list.head; ent; ent = ent->next) {
31ff15
+						if (ent != rule && strcmp(ent->pattern, rule->pattern) == 0) {
31ff15
+							found = 1;
31ff15
+							break;
31ff15
+						}
31ff15
+					}
31ff15
+					if (!found) {
31ff15
+						filter_rule *R_rule = new0(filter_rule);
31ff15
+						R_rule->rflags = FILTRULE_INCLUDE | FILTRULE_DIRECTORY;
31ff15
+						/* Check if our sub-path has wildcards or escaped backslashes */
31ff15
+						if (saw_wild && strpbrk(rule->pattern, "*[?\\"))
31ff15
+							R_rule->rflags |= FILTRULE_WILD;
31ff15
+						R_rule->pattern = strdup(rule->pattern);
31ff15
+						R_rule->u.slash_cnt = slash_cnt;
31ff15
+						R_rule->next = implied_filter_list.head;
31ff15
+						implied_filter_list.head = R_rule;
31ff15
+						if (DEBUG_GTE(FILTER, 3)) {
31ff15
+							rprintf(FINFO, "[%s] add_implied_include(%s/)\n",
31ff15
+								who_am_i(), R_rule->pattern);
31ff15
+						}
31ff15
+						if (saw_live_open_brkt)
31ff15
+							maybe_add_literal_brackets_rule(R_rule, -1);
31ff15
+					}
31ff15
+				}
31ff15
+				slash_cnt++;
31ff15
+				*p++ = *cp++;
31ff15
+				break;
31ff15
+			  case '[':
31ff15
+				saw_live_open_brkt = 1;
31ff15
+				*p++ = *cp++;
31ff15
+				break;
31ff15
+			  default:
31ff15
+				*p++ = *cp++;
31ff15
+				break;
31ff15
+			}
31ff15
+		}
31ff15
+		*p = '\0';
31ff15
+		rule->u.slash_cnt = slash_cnt;
31ff15
+		arg = rule->pattern;
31ff15
+		arg_len = p - arg; /* We recompute it due to backslash weirdness. */
31ff15
+		if (DEBUG_GTE(FILTER, 3))
31ff15
+			rprintf(FINFO, "[%s] add_implied_include(%s)\n", who_am_i(), rule->pattern);
31ff15
+		if (saw_live_open_brkt)
31ff15
+			maybe_add_literal_brackets_rule(rule, arg_len);
31ff15
+	}
31ff15
+
31ff15
+	if (recurse || xfer_dirs) {
31ff15
+		/* Now create a rule with an added "/" & "**" or "*" at the end */
31ff15
+		rule = new0(filter_rule);
31ff15
+		rule->rflags = FILTRULE_INCLUDE | FILTRULE_WILD;
31ff15
+		if (recurse)
31ff15
+			rule->rflags |= FILTRULE_WILD2;
31ff15
+		/* We must leave enough room for / * * \0. */
31ff15
+		if (!saw_wild && backslash_cnt) {
31ff15
+			/* We are appending a wildcard, so now the backslashes need to be escaped. */
31ff15
+			p = rule->pattern = new_array(char, arg_len + backslash_cnt + 3 + 1);
31ff15
+			for (cp = arg; *cp; ) {
31ff15
+				if (*cp == '\\')
31ff15
+					*p++ = '\\';
31ff15
+				*p++ = *cp++;
31ff15
+			}
31ff15
+		} else {
31ff15
+			p = rule->pattern = new_array(char, arg_len + 3 + 1);
31ff15
+			if (arg_len) {
31ff15
+				memcpy(p, arg, arg_len);
31ff15
+				p += arg_len;
31ff15
+			}
31ff15
+		}
31ff15
+		if (p[-1] != '/')
31ff15
+			*p++ = '/';
31ff15
+		*p++ = '*';
31ff15
+		if (recurse)
31ff15
+			*p++ = '*';
31ff15
+		*p = '\0';
31ff15
+		rule->u.slash_cnt = slash_cnt + 1;
31ff15
+		rule->next = implied_filter_list.head;
31ff15
+		implied_filter_list.head = rule;
31ff15
+		if (DEBUG_GTE(FILTER, 3))
31ff15
+			rprintf(FINFO, "[%s] add_implied_include(%s)\n", who_am_i(), rule->pattern);
31ff15
+		if (saw_live_open_brkt)
31ff15
+			maybe_add_literal_brackets_rule(rule, p - rule->pattern);
31ff15
+	}
31ff15
+}
31ff15
+
31ff15
 /* This frees any non-inherited items, leaving just inherited items on the list. */
31ff15
 static void pop_filter_list(filter_rule_list *listp)
31ff15
 {
31ff15
@@ -709,11 +946,12 @@ static void report_filter_result(enum logcode code, char const *name,
31ff15
 				 filter_rule const *ent,
31ff15
 				 int name_flags, const char *type)
31ff15
 {
31ff15
+	int log_level = am_sender || am_generator ? 1 : 3;
31ff15
+
31ff15
 	/* If a trailing slash is present to match only directories,
31ff15
 	 * then it is stripped out by add_rule().  So as a special
31ff15
-	 * case we add it back in here. */
31ff15
-
31ff15
-	if (DEBUG_GTE(FILTER, 1)) {
31ff15
+	 * case we add it back in the log output. */
31ff15
+	if (DEBUG_GTE(FILTER, log_level)) {
31ff15
 		static char *actions[2][2]
31ff15
 		    = { {"show", "hid"}, {"risk", "protect"} };
31ff15
 		const char *w = who_am_i();
31ff15
@@ -721,7 +959,7 @@ static void report_filter_result(enum logcode code, char const *name,
31ff15
 			      : name_flags & NAME_IS_DIR ? "directory"
31ff15
 			      : "file";
31ff15
 		rprintf(code, "[%s] %sing %s %s because of pattern %s%s%s\n",
31ff15
-		    w, actions[*w!='s'][!(ent->rflags & FILTRULE_INCLUDE)],
31ff15
+		    w, actions[*w=='g'][!(ent->rflags & FILTRULE_INCLUDE)],
31ff15
 		    t, name, ent->pattern,
31ff15
 		    ent->rflags & FILTRULE_DIRECTORY ? "/" : "", type);
31ff15
 	}
31ff15
@@ -894,6 +1132,7 @@ static filter_rule *parse_rule_tok(const char **rulestr_ptr,
31ff15
 		}
31ff15
 		switch (ch) {
31ff15
 		case ':':
31ff15
+			trust_sender_filter = 1;
31ff15
 			rule->rflags |= FILTRULE_PERDIR_MERGE
31ff15
 				      | FILTRULE_FINISH_SETUP;
31ff15
 			/* FALL THROUGH */
31ff15
diff --git a/flist.c b/flist.c
31ff15
index 499440c..630d685 100644
31ff15
--- a/flist.c
31ff15
+++ b/flist.c
31ff15
@@ -70,6 +70,7 @@ extern int need_unsorted_flist;
31ff15
 extern int sender_symlink_iconv;
31ff15
 extern int output_needs_newline;
31ff15
 extern int sender_keeps_checksum;
31ff15
+extern int trust_sender_filter;
31ff15
 extern int unsort_ndx;
31ff15
 extern uid_t our_uid;
31ff15
 extern struct stats stats;
31ff15
@@ -80,8 +81,7 @@ extern char curr_dir[MAXPATHLEN];
31ff15
 
31ff15
 extern struct chmod_mode_struct *chmod_modes;
31ff15
 
31ff15
-extern filter_rule_list filter_list;
31ff15
-extern filter_rule_list daemon_filter_list;
31ff15
+extern filter_rule_list filter_list, implied_filter_list, daemon_filter_list;
31ff15
 
31ff15
 #ifdef ICONV_OPTION
31ff15
 extern int filesfrom_convert;
31ff15
@@ -904,6 +904,19 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
31ff15
 		exit_cleanup(RERR_UNSUPPORTED);
31ff15
 	}
31ff15
 
31ff15
+	if (*thisname != '.' || thisname[1] != '\0') {
31ff15
+		int filt_flags = S_ISDIR(mode) ? NAME_IS_DIR : NAME_IS_FILE;
31ff15
+		if (!trust_sender_filter /* a per-dir filter rule means we must trust the sender's filtering */
31ff15
+		 && filter_list.head && check_filter(&filter_list, FINFO, thisname, filt_flags) < 0) {
31ff15
+			rprintf(FERROR, "ERROR: rejecting excluded file-list name: %s\n", thisname);
31ff15
+			exit_cleanup(RERR_PROTOCOL);
31ff15
+		}
31ff15
+		if (implied_filter_list.head && check_filter(&implied_filter_list, FINFO, thisname, filt_flags) <= 0) {
31ff15
+			rprintf(FERROR, "ERROR: rejecting unrequested file-list name: %s\n", thisname);
31ff15
+			exit_cleanup(RERR_PROTOCOL);
31ff15
+		}
31ff15
+	}
31ff15
+
31ff15
 	if (inc_recurse && S_ISDIR(mode)) {
31ff15
 		if (one_file_system) {
31ff15
 			/* Room to save the dir's device for -x */
31ff15
diff --git a/io.c b/io.c
31ff15
index 59105ba..3aea50f 100644
31ff15
--- a/io.c
31ff15
+++ b/io.c
31ff15
@@ -374,6 +374,7 @@ static void forward_filesfrom_data(void)
31ff15
 			free_xbuf(&ff_xb);
31ff15
 			if (ff_reenable_multiplex >= 0)
31ff15
 				io_start_multiplex_out(ff_reenable_multiplex);
31ff15
+			free_implied_include_partial_string();
31ff15
 		}
31ff15
 		return;
31ff15
 	}
31ff15
@@ -415,6 +416,7 @@ static void forward_filesfrom_data(void)
31ff15
 		while (s != eob) {
31ff15
 			if (*s++ == '\0') {
31ff15
 				ff_xb.len = s - sob - 1;
31ff15
+				add_implied_include(sob, 0);
31ff15
 				if (iconvbufs(ic_send, &ff_xb, &iobuf.out, flags) < 0)
31ff15
 					exit_cleanup(RERR_PROTOCOL); /* impossible? */
31ff15
 				write_buf(iobuf.out_fd, s-1, 1); /* Send the '\0'. */
31ff15
@@ -430,6 +432,7 @@ static void forward_filesfrom_data(void)
31ff15
 			ff_lastchar = '\0';
31ff15
 		else {
31ff15
 			/* Handle a partial string specially, saving any incomplete chars. */
31ff15
+			implied_include_partial_string(sob, s);
31ff15
 			flags &= ~ICB_INCLUDE_INCOMPLETE;
31ff15
 			if (iconvbufs(ic_send, &ff_xb, &iobuf.out, flags) < 0) {
31ff15
 				if (errno == E2BIG)
31ff15
@@ -446,13 +449,17 @@ static void forward_filesfrom_data(void)
31ff15
 		char *f = ff_xb.buf + ff_xb.pos;
31ff15
 		char *t = ff_xb.buf;
31ff15
 		char *eob = f + len;
31ff15
+		char *cur = t;
31ff15
 		/* Eliminate any multi-'\0' runs. */
31ff15
 		while (f != eob) {
31ff15
 			if (!(*t++ = *f++)) {
31ff15
+				add_implied_include(cur, 0);
31ff15
+				cur = t;
31ff15
 				while (f != eob && *f == '\0')
31ff15
 					f++;
31ff15
 			}
31ff15
 		}
31ff15
+		implied_include_partial_string(cur, t);
31ff15
 		ff_lastchar = f[-1];
31ff15
 		if ((len = t - ff_xb.buf) != 0) {
31ff15
 			/* This will not circle back to perform_io() because we only get
31ff15
diff --git a/main.c b/main.c
31ff15
index 6113563..abe2ebf 100644
31ff15
--- a/main.c
31ff15
+++ b/main.c
31ff15
@@ -42,6 +42,7 @@ extern int output_needs_newline;
31ff15
 extern int need_messages_from_generator;
31ff15
 extern int kluge_around_eof;
31ff15
 extern int got_xfer_error;
31ff15
+extern int old_style_args;
31ff15
 extern int msgs2stderr;
31ff15
 extern int module_id;
31ff15
 extern int read_only;
31ff15
@@ -78,6 +79,7 @@ extern BOOL flist_receiving_enabled;
31ff15
 extern BOOL shutting_down;
31ff15
 extern int backup_dir_len;
31ff15
 extern int basis_dir_cnt;
31ff15
+extern int trust_sender_filter;
31ff15
 extern struct stats stats;
31ff15
 extern char *stdout_format;
31ff15
 extern char *logfile_format;
31ff15
@@ -93,7 +95,7 @@ extern char curr_dir[MAXPATHLEN];
31ff15
 extern char backup_dir_buf[MAXPATHLEN];
31ff15
 extern char *basis_dir[MAX_BASIS_DIRS+1];
31ff15
 extern struct file_list *first_flist;
31ff15
-extern filter_rule_list daemon_filter_list;
31ff15
+extern filter_rule_list daemon_filter_list, implied_filter_list;
31ff15
 
31ff15
 uid_t our_uid;
31ff15
 gid_t our_gid;
31ff15
@@ -503,11 +505,7 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
31ff15
 				rprintf(FERROR, "internal: args[] overflowed in do_cmd()\n");
31ff15
 				exit_cleanup(RERR_SYNTAX);
31ff15
 			}
31ff15
-			if (**remote_argv == '-') {
31ff15
-				if (asprintf(args + argc++, "./%s", *remote_argv++) < 0)
31ff15
-					out_of_memory("do_cmd");
31ff15
-			} else
31ff15
-				args[argc++] = *remote_argv++;
31ff15
+			args[argc++] = safe_arg(NULL, *remote_argv++);
31ff15
 			remote_argc--;
31ff15
 		}
31ff15
 	}
31ff15
@@ -534,6 +532,7 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
31ff15
 #ifdef ICONV_CONST
31ff15
 		setup_iconv();
31ff15
 #endif
31ff15
+		trust_sender_filter = 1;
31ff15
 	} else if (local_server) {
31ff15
 		/* If the user didn't request --[no-]whole-file, force
31ff15
 		 * it on, but only if we're not batch processing. */
31ff15
@@ -943,6 +942,7 @@ static int do_recv(int f_in, int f_out, char *local_name)
31ff15
 	}
31ff15
 
31ff15
 	am_generator = 1;
31ff15
+	implied_filter_list.head = implied_filter_list.tail = NULL;
31ff15
 	flist_receiving_enabled = True;
31ff15
 
31ff15
 	io_end_multiplex_in(MPLX_SWITCHING);
31ff15
@@ -1340,6 +1340,10 @@ static int start_client(int argc, char *argv[])
31ff15
 		remote_argc = argc = 1;
31ff15
 	}
31ff15
 
31ff15
+	/* A local transfer doesn't unbackslash anything, so leave the args alone. */
31ff15
+	if (local_server)
31ff15
+		old_style_args = 2;
31ff15
+
31ff15
 	if (!rsync_port && remote_argc && !**remote_argv) /* Turn an empty arg into a dot dir. */
31ff15
 		*remote_argv = ".";
31ff15
 
31ff15
@@ -1358,6 +1362,8 @@ static int start_client(int argc, char *argv[])
31ff15
 		char *dummy_host;
31ff15
 		int dummy_port = rsync_port;
31ff15
 		int i;
31ff15
+		if (filesfrom_fd < 0)
31ff15
+			add_implied_include(remote_argv[0], daemon_over_rsh);
31ff15
 		/* For remote source, any extra source args must have either
31ff15
 		 * the same hostname or an empty hostname. */
31ff15
 		for (i = 1; i < remote_argc; i++) {
31ff15
@@ -1381,6 +1387,7 @@ static int start_client(int argc, char *argv[])
31ff15
 			if (!rsync_port && !*arg) /* Turn an empty arg into a dot dir. */
31ff15
 				arg = ".";
31ff15
 			remote_argv[i] = arg;
31ff15
+			add_implied_include(arg, daemon_over_rsh);
31ff15
 		}
31ff15
 	}
31ff15
 
31ff15
diff --git a/receiver.c b/receiver.c
31ff15
index d6a48f1..c0aa893 100644
31ff15
--- a/receiver.c
31ff15
+++ b/receiver.c
31ff15
@@ -577,10 +577,13 @@ int recv_files(int f_in, int f_out, char *local_name)
31ff15
 		if (DEBUG_GTE(RECV, 1))
31ff15
 			rprintf(FINFO, "recv_files(%s)\n", fname);
31ff15
 
31ff15
-		if (daemon_filter_list.head && (*fname != '.' || fname[1] != '\0')
31ff15
-		 && check_filter(&daemon_filter_list, FLOG, fname, 0) < 0) {
31ff15
-			rprintf(FERROR, "attempt to hack rsync failed.\n");
31ff15
-			exit_cleanup(RERR_PROTOCOL);
31ff15
+		if (daemon_filter_list.head && (*fname != '.' || fname[1] != '\0')) {
31ff15
+			int filt_flags = S_ISDIR(file->mode) ? NAME_IS_DIR : NAME_IS_FILE;
31ff15
+			if (check_filter(&daemon_filter_list, FLOG, fname, filt_flags) < 0) {
31ff15
+				rprintf(FERROR, "ERROR: rejecting file transfer request for daemon excluded file: %s\n",
31ff15
+					fname);
31ff15
+				exit_cleanup(RERR_PROTOCOL);
31ff15
+			}
31ff15
 		}
31ff15
 
31ff15
 #ifdef SUPPORT_XATTRS
31ff15
diff --git a/options.c b/options.c
31ff15
index 43e8257..aaf8cc9 100644
31ff15
--- a/options.c
31ff15
+++ b/options.c
31ff15
@@ -99,6 +99,7 @@ int filesfrom_fd = -1;
31ff15
 char *filesfrom_host = NULL;
31ff15
 int eol_nulls = 0;
31ff15
 int protect_args = -1;
31ff15
+int old_style_args = -1;
31ff15
 int human_readable = 1;
31ff15
 int recurse = 0;
31ff15
 int allow_inc_recurse = 1;
31ff15
@@ -277,7 +278,7 @@ static struct output_struct debug_words[COUNT_DEBUG+1] = {
31ff15
 	DEBUG_WORD(DELTASUM, W_SND|W_REC, "Debug delta-transfer checksumming (levels 1-4)"),
31ff15
 	DEBUG_WORD(DUP, W_REC, "Debug weeding of duplicate names"),
31ff15
 	DEBUG_WORD(EXIT, W_CLI|W_SRV, "Debug exit events (levels 1-3)"),
31ff15
-	DEBUG_WORD(FILTER, W_SND|W_REC, "Debug filter actions (levels 1-2)"),
31ff15
+	DEBUG_WORD(FILTER, W_SND|W_REC, "Debug filter actions (levels 1-3)"),
31ff15
 	DEBUG_WORD(FLIST, W_SND|W_REC, "Debug file-list operations (levels 1-4)"),
31ff15
 	DEBUG_WORD(FUZZY, W_REC, "Debug fuzzy scoring (levels 1-2)"),
31ff15
 	DEBUG_WORD(GENR, W_REC, "Debug generator functions"),
31ff15
@@ -824,7 +825,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
31ff15
       OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
31ff15
       OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
31ff15
       OPT_NO_D, OPT_APPEND, OPT_NO_ICONV, OPT_INFO, OPT_DEBUG,
31ff15
-      OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN, OPT_BWLIMIT,
31ff15
+      OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN, OPT_BWLIMIT, OPT_OLD_ARGS,
31ff15
       OPT_SERVER, OPT_REFUSED_BASE = 9000};
31ff15
 
31ff15
 static struct poptOption long_options[] = {
31ff15
@@ -1011,6 +1012,8 @@ static struct poptOption long_options[] = {
31ff15
   {"files-from",       0,  POPT_ARG_STRING, &files_from, 0, 0, 0 },
31ff15
   {"from0",           '0', POPT_ARG_VAL,    &eol_nulls, 1, 0, 0},
31ff15
   {"no-from0",         0,  POPT_ARG_VAL,    &eol_nulls, 0, 0, 0},
31ff15
+  {"old-args",         0,  POPT_ARG_NONE,   0, OPT_OLD_ARGS, 0, 0},
31ff15
+  {"no-old-args",      0,  POPT_ARG_VAL,    &old_style_args, 0, 0, 0},
31ff15
   {"protect-args",    's', POPT_ARG_VAL,    &protect_args, 1, 0, 0},
31ff15
   {"no-protect-args",  0,  POPT_ARG_VAL,    &protect_args, 0, 0, 0},
31ff15
   {"no-s",             0,  POPT_ARG_VAL,    &protect_args, 0, 0, 0},
31ff15
@@ -1577,6 +1580,13 @@ int parse_arguments(int *argc_p, const char ***argv_p)
31ff15
 			do_compression++;
31ff15
 			break;
31ff15
 
31ff15
+		case OPT_OLD_ARGS:
31ff15
+			if (old_style_args <= 0)
31ff15
+				old_style_args = 1;
31ff15
+			else
31ff15
+				old_style_args++;
31ff15
+			break;
31ff15
+
31ff15
 		case 'M':
31ff15
 			arg = poptGetOptArg(pc);
31ff15
 			if (*arg != '-') {
31ff15
@@ -1829,6 +1839,21 @@ int parse_arguments(int *argc_p, const char ***argv_p)
31ff15
 		}
31ff15
 	}
31ff15
 
31ff15
+	if (old_style_args < 0) {
31ff15
+		if (!am_server && protect_args <= 0 && (arg = getenv("RSYNC_OLD_ARGS")) != NULL && *arg) {
31ff15
+			protect_args = 0;
31ff15
+			old_style_args = atoi(arg);
31ff15
+		} else
31ff15
+			old_style_args = 0;
31ff15
+	} else if (old_style_args) {
31ff15
+		if (protect_args > 0) {
31ff15
+			snprintf(err_buf, sizeof err_buf,
31ff15
+				 "--protect-args conflicts with --old-args.\n");
31ff15
+			return 0;
31ff15
+		}
31ff15
+		protect_args = 0;
31ff15
+	}
31ff15
+
31ff15
 	if (protect_args < 0) {
31ff15
 		if (am_server)
31ff15
 			protect_args = 0;
31ff15
@@ -2381,6 +2406,71 @@ int parse_arguments(int *argc_p, const char ***argv_p)
31ff15
 }
31ff15
 
31ff15
 
31ff15
+static char SPLIT_ARG_WHEN_OLD[1];
31ff15
+
31ff15
+/**
31ff15
+ * Do backslash quoting of any weird chars in "arg", append the resulting
31ff15
+ * string to the end of the "opt" (which gets a "=" appended if it is not
31ff15
+ * an empty or NULL string), and return the (perhaps malloced) result.
31ff15
+ * If opt is NULL, arg is considered a filename arg that allows wildcards.
31ff15
+ * If it is "" or any other value, it is considered an option.
31ff15
+ **/
31ff15
+char *safe_arg(const char *opt, const char *arg)
31ff15
+{
31ff15
+#define SHELL_CHARS "!#$&;|<>(){}\"' \t\\"
31ff15
+#define WILD_CHARS  "*?[]" /* We don't allow remote brace expansion */
31ff15
+	BOOL is_filename_arg = !opt;
31ff15
+	char *escapes = is_filename_arg ? SHELL_CHARS : WILD_CHARS SHELL_CHARS;
31ff15
+	BOOL escape_leading_dash = is_filename_arg && *arg == '-';
31ff15
+	BOOL escape_leading_tilde = 0;
31ff15
+	int len1 = opt && *opt ? strlen(opt) + 1 : 0;
31ff15
+	int len2 = strlen(arg);
31ff15
+	int extras = escape_leading_dash ? 2 : 0;
31ff15
+	char *ret;
31ff15
+	if (!protect_args && old_style_args < 2 && (!old_style_args || (!is_filename_arg && opt != SPLIT_ARG_WHEN_OLD))) {
31ff15
+		const char *f;
31ff15
+		if (!old_style_args && *arg == '~' && (relative_paths || !strchr(arg, '/'))) {
31ff15
+			extras++;
31ff15
+			escape_leading_tilde = 1;
31ff15
+		}
31ff15
+		for (f = arg; *f; f++) {
31ff15
+			if (strchr(escapes, *f))
31ff15
+				extras++;
31ff15
+		}
31ff15
+	}
31ff15
+	if (!len1 && !extras)
31ff15
+		return (char*)arg;
31ff15
+	ret = new_array(char, len1 + len2 + extras + 1);
31ff15
+	if (len1) {
31ff15
+		memcpy(ret, opt, len1-1);
31ff15
+		ret[len1-1] = '=';
31ff15
+	}
31ff15
+	if (escape_leading_dash) {
31ff15
+		ret[len1++] = '.';
31ff15
+		ret[len1++] = '/';
31ff15
+		extras -= 2;
31ff15
+	}
31ff15
+	if (!extras)
31ff15
+		memcpy(ret + len1, arg, len2);
31ff15
+	else {
31ff15
+		const char *f = arg;
31ff15
+		char *t = ret + len1;
31ff15
+		if (escape_leading_tilde)
31ff15
+			*t++ = '\\';
31ff15
+		while (*f) {
31ff15
+                        if (*f == '\\') {
31ff15
+				if (!is_filename_arg || !strchr(WILD_CHARS, f[1]))
31ff15
+					*t++ = '\\';
31ff15
+			} else if (strchr(escapes, *f))
31ff15
+				*t++ = '\\';
31ff15
+			*t++ = *f++;
31ff15
+		}
31ff15
+	}
31ff15
+	ret[len1+len2+extras] = '\0';
31ff15
+	return ret;
31ff15
+}
31ff15
+
31ff15
+
31ff15
 /**
31ff15
  * Construct a filtered list of options to pass through from the
31ff15
  * client to the server.
31ff15
@@ -2556,9 +2646,7 @@ void server_options(char **args, int *argc_p)
31ff15
 			set++;
31ff15
 		else
31ff15
 			set = iconv_opt;
31ff15
-		if (asprintf(&arg, "--iconv=%s", set) < 0)
31ff15
-			goto oom;
31ff15
-		args[ac++] = arg;
31ff15
+		args[ac++] = safe_arg("--iconv", set);
31ff15
 	}
31ff15
 #endif
31ff15
 
31ff15
@@ -2625,23 +2713,17 @@ void server_options(char **args, int *argc_p)
31ff15
 	}
31ff15
 
31ff15
 	if (backup_dir) {
31ff15
+		/* This split idiom allows for ~/path expansion via the shell. */
31ff15
 		args[ac++] = "--backup-dir";
31ff15
-		args[ac++] = backup_dir;
31ff15
+		args[ac++] = safe_arg("", backup_dir);
31ff15
 	}
31ff15
 
31ff15
 	/* Only send --suffix if it specifies a non-default value. */
31ff15
-	if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
31ff15
-		/* We use the following syntax to avoid weirdness with '~'. */
31ff15
-		if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
31ff15
-			goto oom;
31ff15
-		args[ac++] = arg;
31ff15
-	}
31ff15
+	if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0)
31ff15
+		args[ac++] = safe_arg("--suffix", backup_suffix);
31ff15
 
31ff15
-	if (checksum_choice) {
31ff15
-		if (asprintf(&arg, "--checksum-choice=%s", checksum_choice) < 0)
31ff15
-			goto oom;
31ff15
-		args[ac++] = arg;
31ff15
-	}
31ff15
+	if (checksum_choice)
31ff15
+		args[ac++] = safe_arg("--checksum-choice", checksum_choice);
31ff15
 
31ff15
 	if (am_sender) {
31ff15
 		if (max_delete > 0) {
31ff15
@@ -2650,14 +2732,10 @@ void server_options(char **args, int *argc_p)
31ff15
 			args[ac++] = arg;
31ff15
 		} else if (max_delete == 0)
31ff15
 			args[ac++] = "--max-delete=-1";
31ff15
-		if (min_size >= 0) {
31ff15
-			args[ac++] = "--min-size";
31ff15
-			args[ac++] = min_size_arg;
31ff15
-		}
31ff15
-		if (max_size >= 0) {
31ff15
-			args[ac++] = "--max-size";
31ff15
-			args[ac++] = max_size_arg;
31ff15
-		}
31ff15
+		if (min_size >= 0)
31ff15
+			args[ac++] = safe_arg("--min-size", min_size_arg);
31ff15
+		if (max_size >= 0)
31ff15
+			args[ac++] = safe_arg("--max-size", max_size_arg);
31ff15
 		if (delete_before)
31ff15
 			args[ac++] = "--delete-before";
31ff15
 		else if (delete_during == 2)
31ff15
@@ -2681,11 +2759,8 @@ void server_options(char **args, int *argc_p)
31ff15
 		if (do_stats)
31ff15
 			args[ac++] = "--stats";
31ff15
 	} else {
31ff15
-		if (skip_compress) {
31ff15
-			if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
31ff15
-				goto oom;
31ff15
-			args[ac++] = arg;
31ff15
-		}
31ff15
+		if (skip_compress)
31ff15
+			args[ac++] = safe_arg("--skip-compress", skip_compress);
31ff15
 	}
31ff15
 
31ff15
 	/* --delete-missing-args needs the cooperation of both sides, but
31ff15
@@ -2711,7 +2786,7 @@ void server_options(char **args, int *argc_p)
31ff15
 	if (partial_dir && am_sender) {
31ff15
 		if (partial_dir != tmp_partialdir) {
31ff15
 			args[ac++] = "--partial-dir";
31ff15
-			args[ac++] = partial_dir;
31ff15
+			args[ac++] = safe_arg("", partial_dir);
31ff15
 		}
31ff15
 		if (delay_updates)
31ff15
 			args[ac++] = "--delay-updates";
31ff15
@@ -2734,17 +2809,11 @@ void server_options(char **args, int *argc_p)
31ff15
 		args[ac++] = "--use-qsort";
31ff15
 
31ff15
 	if (am_sender) {
31ff15
-		if (usermap) {
31ff15
-			if (asprintf(&arg, "--usermap=%s", usermap) < 0)
31ff15
-				goto oom;
31ff15
-			args[ac++] = arg;
31ff15
-		}
31ff15
+		if (usermap)
31ff15
+			args[ac++] = safe_arg("--usermap", usermap);
31ff15
 
31ff15
-		if (groupmap) {
31ff15
-			if (asprintf(&arg, "--groupmap=%s", groupmap) < 0)
31ff15
-				goto oom;
31ff15
-			args[ac++] = arg;
31ff15
-		}
31ff15
+		if (groupmap)
31ff15
+			args[ac++] = safe_arg("--groupmap", groupmap);
31ff15
 
31ff15
 		if (ignore_existing)
31ff15
 			args[ac++] = "--ignore-existing";
31ff15
@@ -2755,7 +2824,7 @@ void server_options(char **args, int *argc_p)
31ff15
 
31ff15
 		if (tmpdir) {
31ff15
 			args[ac++] = "--temp-dir";
31ff15
-			args[ac++] = tmpdir;
31ff15
+			args[ac++] = safe_arg("", tmpdir);
31ff15
 		}
31ff15
 
31ff15
 		if (basis_dir[0]) {
31ff15
@@ -2765,7 +2834,7 @@ void server_options(char **args, int *argc_p)
31ff15
 			 */
31ff15
 			for (i = 0; i < basis_dir_cnt; i++) {
31ff15
 				args[ac++] = dest_option;
31ff15
-				args[ac++] = basis_dir[i];
31ff15
+				args[ac++] = safe_arg("", basis_dir[i]);
31ff15
 			}
31ff15
 		}
31ff15
 	}
31ff15
@@ -2790,7 +2859,7 @@ void server_options(char **args, int *argc_p)
31ff15
 	if (files_from && (!am_sender || filesfrom_host)) {
31ff15
 		if (filesfrom_host) {
31ff15
 			args[ac++] = "--files-from";
31ff15
-			args[ac++] = files_from;
31ff15
+			args[ac++] = safe_arg("", files_from);
31ff15
 			if (eol_nulls)
31ff15
 				args[ac++] = "--from0";
31ff15
 		} else {
31ff15
@@ -2830,7 +2899,7 @@ void server_options(char **args, int *argc_p)
31ff15
 			exit_cleanup(RERR_SYNTAX);
31ff15
 		}
31ff15
 		for (j = 1; j <= remote_option_cnt; j++)
31ff15
-			args[ac++] = (char*)remote_options[j];
31ff15
+			args[ac++] = safe_arg(SPLIT_ARG_WHEN_OLD, remote_options[j]);
31ff15
 	}
31ff15
 
31ff15
 	*argc_p = ac;
31ff15
diff --git a/clientserver.c b/clientserver.c
31ff15
index e2e2dc0..c18c024 100644
31ff15
--- a/clientserver.c
31ff15
+++ b/clientserver.c
31ff15
@@ -45,6 +45,7 @@ extern int protocol_version;
31ff15
 extern int io_timeout;
31ff15
 extern int no_detach;
31ff15
 extern int write_batch;
31ff15
+extern int old_style_args;
31ff15
 extern int default_af_hint;
31ff15
 extern int logfile_format_has_i;
31ff15
 extern int logfile_format_has_o_or_i;
31ff15
@@ -255,20 +256,45 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
31ff15
 
31ff15
 	sargs[sargc++] = ".";
31ff15
 
31ff15
+	if (!old_style_args)
31ff15
+		snprintf(line, sizeof line, " %.*s/", modlen, modname);
31ff15
+
31ff15
 	while (argc > 0) {
31ff15
 		if (sargc >= MAX_ARGS - 1) {
31ff15
 		  arg_overflow:
31ff15
 			rprintf(FERROR, "internal: args[] overflowed in do_cmd()\n");
31ff15
 			exit_cleanup(RERR_SYNTAX);
31ff15
 		}
31ff15
-		if (strncmp(*argv, modname, modlen) == 0
31ff15
-		 && argv[0][modlen] == '\0')
31ff15
+		if (strncmp(*argv, modname, modlen) == 0 && argv[0][modlen] == '\0')
31ff15
 			sargs[sargc++] = modname; /* we send "modname/" */
31ff15
-		else if (**argv == '-') {
31ff15
-			if (asprintf(sargs + sargc++, "./%s", *argv) < 0)
31ff15
-				out_of_memory("start_inband_exchange");
31ff15
-		} else
31ff15
-			sargs[sargc++] = *argv;
31ff15
+		else {
31ff15
+			char *arg = *argv;
31ff15
+			int extra_chars = *arg == '-' ? 2 : 0; /* a leading dash needs a "./" prefix. */
31ff15
+			/* If --old-args was not specified, make sure that the arg won't split at a mod name! */
31ff15
+			if (!old_style_args && (p = strstr(arg, line)) != NULL) {
31ff15
+				do {
31ff15
+					extra_chars += 2;
31ff15
+				} while ((p = strstr(p+1, line)) != NULL);
31ff15
+			}
31ff15
+			if (extra_chars) {
31ff15
+				char *f = arg;
31ff15
+				char *t = arg = new_array(char, strlen(arg) + extra_chars + 1);
31ff15
+				if (*f == '-') {
31ff15
+					*t++ = '.';
31ff15
+					*t++ = '/';
31ff15
+				}
31ff15
+				while (*f) {
31ff15
+					if (*f == ' ' && strncmp(f, line, modlen+2) == 0) {
31ff15
+						*t++ = '[';
31ff15
+						*t++ = *f++;
31ff15
+						*t++ = ']';
31ff15
+					} else
31ff15
+						*t++ = *f++;
31ff15
+				}
31ff15
+				*t = '\0';
31ff15
+			}
31ff15
+			sargs[sargc++] = arg;
31ff15
+		}
31ff15
 		argv++;
31ff15
 		argc--;
31ff15
 	}
31ff15
diff --git a/rsync.1 b/rsync.1
31ff15
index cf2f573..839f5ad 100644
31ff15
--- a/rsync.1
31ff15
+++ b/rsync.1
31ff15
@@ -197,7 +197,7 @@ or with the hostname omitted.  For instance, all these work:
31ff15
 .br 
31ff15
 \f(CWrsync \-av host::modname/file{1,2} host::modname/file3 /dest/\fP
31ff15
 .br 
31ff15
-\f(CWrsync \-av host::modname/file1 ::modname/file{3,4}\fP
31ff15
+\f(CWrsync \-av host::modname/file1 ::modname/file{3,4} /dest/\fP
31ff15
 .RE
31ff15
 
31ff15
 .PP 
31ff15
@@ -211,18 +211,23 @@ examples:
31ff15
 .RE
31ff15
 
31ff15
 .PP 
31ff15
-This word\-splitting still works (by default) in the latest rsync, but is
31ff15
-not as easy to use as the first method.
31ff15
-.PP 
31ff15
-If you need to transfer a filename that contains whitespace, you can either
31ff15
-specify the \fB\-\-protect\-args\fP (\fB\-s\fP) option, or you\(cq\&ll need to escape
31ff15
-the whitespace in a way that the remote shell will understand.  For
31ff15
-instance:
31ff15
-.PP 
31ff15
-.RS 
31ff15
-\f(CWrsync \-av host:'\&file\e name\e with\e spaces'\& /dest\fP
31ff15
+Starting this version of rsync, filenames are passed to a remote shell
31ff15
+in such a way as to preserve the characters you give it.
31ff15
+Thus, if you ask for a file with spaces in the name, that's what the
31ff15
+remote rsync looks for:
31ff15
+.PP
31ff15
+.RS
31ff15
+\f(CWrsync \-aiv host:'\&a simple file.pdf'\& /dest/\fP
31ff15
 .RE
31ff15
 
31ff15
+.PP 
31ff15
+If you use scripts that have been written to manually apply extra quoting to
31ff15
+the remote rsync args (or to require remote arg splitting), you can ask rsync
31ff15
+to let your script handle the extra escaping.  This is done by either adding
31ff15
+the \fB\-\-old\-args\fP option to the rsync runs in the script (which requires
31ff15
+a new rsync) or exporting \fBRSYNC_OLD_ARGS\fP=1 and \fBRSYNC_PROTECT_ARGS\fP=0
31ff15
+(which works with old or new rsync versions).
31ff15
+
31ff15
 .PP 
31ff15
 .SH "CONNECTING TO AN RSYNC DAEMON"
31ff15
 
31ff15
@@ -429,6 +434,7 @@ to the detailed description below for a complete description.
31ff15
      \-\-append                append data onto shorter files
31ff15
      \-\-append\-verify         \-\-append w/old data in file checksum
31ff15
  \-d, \-\-dirs                  transfer directories without recursing
31ff15
+      \-\-old\-dirs, \-\-old\-d works like --dirs when talking to old rsync
31ff15
  \-l, \-\-links                 copy symlinks as symlinks
31ff15
  \-L, \-\-copy\-links            transform symlink into referent file/dir
31ff15
      \-\-copy\-unsafe\-links     only \(dq\&unsafe\(dq\& symlinks are transformed
31ff15
@@ -511,6 +517,7 @@ to the detailed description below for a complete description.
31ff15
      \-\-include\-from=FILE     read include patterns from FILE
31ff15
      \-\-files\-from=FILE       read list of source\-file names from FILE
31ff15
  \-0, \-\-from0                 all *from/filter files are delimited by 0s
31ff15
+     \-\-old\-args              disable the modern arg-protection idiom
31ff15
  \-s, \-\-protect\-args          no space\-splitting; wildcard chars only
31ff15
      \-\-address=ADDRESS       bind address for outgoing socket to daemon
31ff15
      \-\-port=PORT             specify double\-colon alternate port number
31ff15
@@ -1857,10 +1864,10 @@ Be cautious using this, as it is possible to toggle an option that will cause
31ff15
 rsync to have a different idea about what data to expect next over the socket,
31ff15
 and that will make it fail in a cryptic fashion.
31ff15
 .IP 
31ff15
-Note that it is best to use a separate \fB\-\-remote\-option\fP for each option you
31ff15
-want to pass.  This makes your useage compatible with the \fB\-\-protect\-args\fP
31ff15
-option.  If that option is off, any spaces in your remote options will be split
31ff15
-by the remote shell unless you take steps to protect them.
31ff15
+Note that you should use a separate \fB\-M\fP for each remote option you
31ff15
+want to pass. On older rsync versions, the presence of any spaces in the
31ff15
+remote-option arg could cause it to be split into separate remote args, but
31ff15
+this requires the use of \fB\-\-old\-args\fP in this version of rsync.
31ff15
 .IP 
31ff15
 When performing a local transfer, the \(dq\&local\(dq\& side is the sender and the
31ff15
 \(dq\&remote\(dq\& side is the receiver.
31ff15
@@ -2054,32 +2061,64 @@ merged files specified in a \fB\-\-filter\fP rule.
31ff15
 It does not affect \fB\-\-cvs\-exclude\fP (since all names read from a .cvsignore
31ff15
 file are split on whitespace).
31ff15
 .IP 
31ff15
+.IP "\fB\-\-old\-args\fP"
31ff15
+This option tells rsync to stop trying to protect the arg values from
31ff15
+unintended word-splitting or other misinterpretation by using its new
31ff15
+backslash-escape idiom.  The newest default is for remote filenames to only
31ff15
+allow wildcards characters to be interpretated by the shell while
31ff15
+protecting other shell-interpreted characters (and the args of options get
31ff15
+even wildcards escaped).  The only active wildcard characters on the remote
31ff15
+side are: `*`, `?`, `[`, & `]`.
31ff15
+.IP
31ff15
+If you have a script that wants to use old-style arg splitting in the
31ff15
+filenames, specify this option once.  If the remote shell has a problem
31ff15
+with any backslash escapes, specify the option twice.
31ff15
+.IP
31ff15
+You may also control this setting via the RSYNC_OLD_ARGS environment
31ff15
+variable.  If it has the value "1", rsync will default to a single-option
31ff15
+setting.  If it has the value "2" (or more), rsync will default to a
31ff15
+repeated-option setting.  If it is "0", you'll get the default escaping
31ff15
+behavior.  The environment is always overridden by manually specified
31ff15
+positive or negative options (the negative is \fB\-\-no\-old\-args\fP).
31ff15
+.IP
31ff15
+Note that this option also disables the extra safety check added in this
31ff15
+version of rsync,
31ff15
+that ensures that a remote sender isn't including extra top-level items in
31ff15
+the file-list that you didn't request.  This side-effect is necessary
31ff15
+because we can't know for sure what names to expect when the remote shell
31ff15
+is interpreting the args.
31ff15
+.IP
31ff15
+This option conflicts with the \fB\-\-protect\-args\fP option.
31ff15
+.IP
31ff15
 .IP "\fB\-s, \-\-protect\-args\fP"
31ff15
-This option sends all filenames and most options to
31ff15
-the remote rsync without allowing the remote shell to interpret them.  This
31ff15
-means that spaces are not split in names, and any non\-wildcard special
31ff15
-characters are not translated (such as ~, $, ;, &, etc.).  Wildcards are
31ff15
-expanded on the remote host by rsync (instead of the shell doing it).
31ff15
+This option sends all filenames and most options to the remote rsync
31ff15
+without allowing the remote shell to interpret them.  Wildcards are
31ff15
+expanded on the remote host by rsync instead of the shell doing it.
31ff15
+.IP
31ff15
+This is similar to the new-style backslash-escaping of args that was added
31ff15
+in this version of rsync, but supports some extra features and doesn't
31ff15
+rely on backslash escaping in the remote shell.
31ff15
 .IP 
31ff15
 If you use this option with \fB\-\-iconv\fP, the args related to the remote
31ff15
 side will also be translated
31ff15
 from the local to the remote character\-set.  The translation happens before
31ff15
 wild\-cards are expanded.  See also the \fB\-\-files\-from\fP option.
31ff15
 .IP 
31ff15
-You may also control this option via the RSYNC_PROTECT_ARGS environment
31ff15
-variable.  If this variable has a non\-zero value, this option will be enabled
31ff15
+You may also control this setting via the RSYNC_PROTECT_ARGS environment
31ff15
+variable.  If it has a non-zero value, this setting will be enabled
31ff15
 by default, otherwise it will be disabled by default.  Either state is
31ff15
 overridden by a manually specified positive or negative version of this option
31ff15
 (note that \fB\-\-no\-s\fP and \fB\-\-no\-protect\-args\fP are the negative versions).
31ff15
-Since this option was first introduced in 3.0.0, you\(cq\&ll need to make sure it\(cq\&s
31ff15
-disabled if you ever need to interact with a remote rsync that is older than
31ff15
-that.
31ff15
-.IP 
31ff15
-Rsync can also be configured (at build time) to have this option enabled by
31ff15
-default (with is overridden by both the environment and the command\-line).
31ff15
-This option will eventually become a new default setting at some
31ff15
-as\-yet\-undetermined point in the future.
31ff15
+This environment variable is also superseded by a non-zero \fBRSYNC_OLD_ARGS\fP export.
31ff15
 .IP 
31ff15
+You may need to disable this option when interacting with an older rsync
31ff15
+(one prior to 3.0.0).
31ff15
+.IP
31ff15
+This option conflicts with the \fB\-\-old\-args\fP option.
31ff15
+.IP
31ff15
+Note that this option is incompatible with the use of the restricted rsync
31ff15
+script (`rrsync`) since it hides options from the script's inspection.
31ff15
+.IP
31ff15
 .IP "\fB\-T, \-\-temp\-dir=DIR\fP"
31ff15
 This option instructs rsync to use DIR as a
31ff15
 scratch directory when creating temporary copies of the files transferred
31ff15
@@ -2371,7 +2410,11 @@ as a super\-user (see also the \fB\-\-fake\-super\fP option).  For the \fB\-\-gr
31ff15
 option to have any effect, the \fB\-g\fP (\fB\-\-groups\fP) option must be used
31ff15
 (or implied), and the receiver will need to have permissions to set that
31ff15
 group.
31ff15
-.IP 
31ff15
+.IP
31ff15
+An older rsync client may need to use \fB\-\-protect\-args\fP (\fB\-s\fP)
31ff15
+to avoid a complaint about wildcard characters, but a modern rsync handles
31ff15
+this automatically.
31ff15
+.IP
31ff15
 .IP "\fB\-\-chown=USER:GROUP\fP"
31ff15
 This option forces all files to be owned by USER
31ff15
 with group GROUP.  This is a simpler interface than using \fB\-\-usermap\fP and
31ff15
@@ -2382,6 +2425,10 @@ be omitted, but if USER is empty, a leading colon must be supplied.
31ff15
 .IP 
31ff15
 If you specify \(dq\&\-\-chown=foo:bar, this is exactly the same as specifying
31ff15
 \(dq\&\-\-usermap=*:foo \-\-groupmap=*:bar\(dq\&, only easier.
31ff15
+.IP
31ff15
+An older rsync client may need to use \fB\-\-protect\-args\fP (\fB\-s\fP) to avoid a
31ff15
+complaint about wildcard characters, but a modern rsync handles this
31ff15
+automatically.
31ff15
 .IP 
31ff15
 .IP "\fB\-\-timeout=TIMEOUT\fP"
31ff15
 This option allows you to set a maximum I/O
31ff15
@@ -3983,10 +4030,24 @@ more details.
31ff15
 .IP "\fBRSYNC_ICONV\fP"
31ff15
 Specify a default \fB\-\-iconv\fP setting using this
31ff15
 environment variable. (First supported in 3.0.0.)
31ff15
+.IP "\fBRSYNC_OLD_ARGS\fP"
31ff15
+Specify a "1" if you want the \fB\-\-old\-args\fP option to be enabled by default,
31ff15
+a "2" (or more) if you want it to be enabled in the option-repeated state,
31ff15
+or a "0" to make sure that it is disabled by default. When this environment
31ff15
+variable is set to a non-zero value, it supersedes the \fBRSYNC_PROTECT_ARGS\fP
31ff15
+variable.
31ff15
+.IP
31ff15
+This variable is ignored if \fB\-\-old\-args\fP, \fB\-\-no\-old\-args\fP, or
31ff15
+\fB\-\-protect\-args\fP is specified on the command line.
31ff15
 .IP "\fBRSYNC_PROTECT_ARGS\fP"
31ff15
 Specify a non\-zero numeric value if you want the
31ff15
 \fB\-\-protect\-args\fP option to be enabled by default, or a zero value to make
31ff15
 sure that it is disabled by default. (First supported in 3.1.0.)
31ff15
+.IP
31ff15
+This variable is ignored if \fB\-\-protect\-args\fP, \fB\-\-no\-protect\-args\fP,
31ff15
+or \fB\-\-old\-args\fP is specified on the command line.
31ff15
+.IP
31ff15
+This variable is ignored if \fBRSYNC_OLD_ARGS\fP is set to a non-zero value.
31ff15
 .IP "\fBRSYNC_RSH\fP"
31ff15
 The RSYNC_RSH environment variable allows you to
31ff15
 override the default shell used as the transport for rsync.  Command line