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

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