X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/ffbffc647bbc66a9196d96cb4b27555e7bcfe71a..27999abab48979c7306a1c335f8e264c6c200457:/options.c diff --git a/options.c b/options.c index 44197821..c868cfe4 100644 --- a/options.c +++ b/options.c @@ -90,6 +90,7 @@ char *files_from = NULL; 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; @@ -397,6 +398,7 @@ void usage(enum logcode F) 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"); @@ -459,8 +461,9 @@ static struct poptOption long_options[] = { {"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 }, + {"no-ir", 0, POPT_ARG_VAL, &allow_inc_recurse, 0, 0, 0 }, /* XXX remove soon */ {"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 }, @@ -512,6 +515,8 @@ static struct poptOption long_options[] = { {"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 }, @@ -591,6 +596,9 @@ static struct poptOption long_options[] = { {"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 }, @@ -858,7 +866,7 @@ static void create_refuse_error(int which) **/ 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; @@ -870,7 +878,7 @@ int parse_arguments(int *argc_p, const char ***argv_p, int frommain) 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 @@ -878,8 +886,11 @@ int parse_arguments(int *argc_p, const char ***argv_p, int frommain) /* 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; @@ -1230,14 +1241,22 @@ int parse_arguments(int *argc_p, const char ***argv_p, int frommain) } #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, @@ -1645,6 +1664,10 @@ void server_options(char **args, int *argc_p) x = 1; argstr[0] = '-'; + + if (protect_args) + argstr[x++] = 's'; + for (i = 0; i < verbose; i++) argstr[x++] = 'v'; @@ -1747,6 +1770,22 @@ void server_options(char **args, int *argc_p) 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"; @@ -1782,19 +1821,6 @@ void server_options(char **args, int *argc_p) 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; @@ -1832,7 +1858,7 @@ void server_options(char **args, int *argc_p) 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; @@ -1904,7 +1930,7 @@ void server_options(char **args, int *argc_p) args[ac++] = "--numeric-ids"; if (!allow_inc_recurse) - args[ac++] = "--no-ir"; + args[ac++] = "--no-ir"; /* XXX change to --no-i-r soon */ if (am_sender) { if (ignore_existing)