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