*/
#include "rsync.h"
+#include "ifuncs.h"
#include <popt.h>
#include "zlib/zlib.h"
int filesfrom_fd = -1;
char *filesfrom_host = NULL;
int eol_nulls = 0;
+int protect_args = 0;
int human_readable = 0;
int recurse = 0;
int allow_inc_recurse = 1;
rprintf(F," --include-from=FILE read include patterns from FILE\n");
rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
+ rprintf(F," -s, --protect-args no space-splitting; only wildcard special-chars\n");
rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
rprintf(F," --port=PORT specify double-colon alternate port number\n");
rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
{"no-r", 0, POPT_ARG_VAL, &recurse, 0, 0, 0 },
{"inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
{"no-inc-recursive", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
- {"ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
- {"no-ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
+ {"i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 1, 0, 0 },
+ {"no-i-r", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 },
{"dirs", 'd', POPT_ARG_VAL, &xfer_dirs, 2, 0, 0 },
{"no-dirs", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
{"no-d", 0, POPT_ARG_VAL, &xfer_dirs, 0, 0, 0 },
{"no-R", 0, POPT_ARG_VAL, &relative_paths, 0, 0, 0 },
{"implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
{"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
+ {"i-d", 0, POPT_ARG_VAL, &implied_dirs, 1, 0, 0 },
+ {"no-i-d", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
{"chmod", 0, POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
{"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
{"size-only", 0, POPT_ARG_NONE, &size_only, 0, 0, 0 },
{"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
{"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
{"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
+ {"protect-args", 's', POPT_ARG_VAL, &protect_args, 1, 0, 0},
+ {"no-protect-args", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
+ {"no-s", 0, POPT_ARG_VAL, &protect_args, 0, 0, 0},
{"numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 1, 0, 0 },
{"no-numeric-ids", 0, POPT_ARG_VAL, &numeric_ids, 0, 0, 0 },
{"timeout", 0, POPT_ARG_INT, &io_timeout, 0, 0, 0 },
**/
int parse_arguments(int *argc_p, const char ***argv_p, int frommain)
{
- poptContext pc;
+ static poptContext pc;
char *ref = lp_refuse_options(module_id);
const char *arg, **argv = *argv_p;
int argc = *argc_p;
set_refuse_options("log-file*");
#ifdef ICONV_OPTION
- if (!am_daemon && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
+ if (!am_daemon && !protect_args && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
iconv_opt = strdup(arg);
#endif
/* The context leaks in case of an error, but if there's a
* problem we always exit anyhow. */
- pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0);
- poptReadDefaultConfig(pc, 0);
+ if (pc)
+ poptFreeContext(pc);
+ pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
+ if (!am_server)
+ poptReadDefaultConfig(pc, 0);
while ((opt = poptGetNextOpt(pc)) != -1) {
/* most options are handled automatically by popt;
if (sanitize_paths)
arg = sanitize_path(NULL, arg, NULL, 0, NULL);
if (server_filter_list.head) {
+ int rej;
char *cp = strdup(arg);
if (!cp)
out_of_memory("parse_arguments");
if (!*cp)
goto options_rejected;
clean_fname(cp, 1);
- if (check_filter(&server_filter_list, cp, 0) < 0)
- goto options_rejected;
+ rej = check_filter(&server_filter_list, cp, 0) < 0;
free(cp);
+ if (rej)
+ goto options_rejected;
}
parse_filter_file(&filter_list, arg,
opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,
}
#ifdef ICONV_OPTION
- if (iconv_opt) {
+ if (iconv_opt && protect_args != 2) {
if (!am_server && strcmp(iconv_opt, "-") == 0)
iconv_opt = NULL;
else
need_unsorted_flist = 1;
}
+ setup_iconv();
#endif
+ if (protect_args == 1) {
+ if (!frommain)
+ protect_args = 0;
+ else if (am_server)
+ return 1;
+ }
+
#ifndef SUPPORT_LINKS
if (preserve_links && !am_sender) {
snprintf(err_buf, sizeof err_buf,
x = 1;
argstr[0] = '-';
+
+ if (protect_args)
+ argstr[x++] = 's';
+
for (i = 0; i < verbose; i++)
argstr[x++] = 'v';
if (x != 1)
args[ac++] = argstr;
+#ifdef ICONV_OPTION
+ if (iconv_opt) {
+ char *set = strchr(iconv_opt, ',');
+ if (set)
+ set++;
+ else
+ set = iconv_opt;
+ if (asprintf(&arg, "--iconv=%s", set) < 0)
+ goto oom;
+ args[ac++] = arg;
+ }
+#endif
+
+ if (protect_args) /* initial args break here */
+ args[ac++] = NULL;
+
if (list_only > 1)
args[ac++] = "--list-only";
args[ac++] = "--log-format=X";
}
-#ifdef ICONV_OPTION
- if (iconv_opt) {
- char *set = strchr(iconv_opt, ',');
- if (set)
- set++;
- else
- set = iconv_opt;
- if (asprintf(&arg, "--iconv=%s", set) < 0)
- goto oom;
- args[ac++] = arg;
- }
-#endif
-
if (block_size) {
if (asprintf(&arg, "-B%lu", block_size) < 0)
goto oom;
goto oom;
args[ac++] = arg;
} else if (max_delete == 0)
- args[ac++] = "--max_delete=-1";
+ args[ac++] = "--max-delete=-1";
if (min_size) {
args[ac++] = "--min-size";
args[ac++] = min_size_arg;
args[ac++] = "--numeric-ids";
if (!allow_inc_recurse)
- args[ac++] = "--no-ir";
+ args[ac++] = "--no-i-r";
if (am_sender) {
if (ignore_existing)
if (!relative_paths)
args[ac++] = "--no-relative";
}
- if (relative_paths && !implied_dirs && !am_sender)
+ /* It's OK that this checks the upper-bound of the protocol_version. */
+ if (relative_paths && !implied_dirs && (!am_sender || protocol_version >= 30))
args[ac++] = "--no-implied-dirs";
if (fuzzy_basis && am_sender)