Check for EVP_MD_CTX_copy in crypto lib instead of MD5_Init.
[rsync.git] / options.c
index e7a9fcaee43513c00abfe074d12631992be3e4f8..d38bbe8db344fceb3f068b9f8b35067ec74d8624 100644 (file)
--- a/options.c
+++ b/options.c
@@ -27,6 +27,8 @@
 extern int module_id;
 extern int local_server;
 extern int sanitize_paths;
+extern int trust_sender_args;
+extern int trust_sender_filter;
 extern unsigned int module_dirlen;
 extern filter_rule_list filter_list;
 extern filter_rule_list daemon_filter_list;
@@ -64,6 +66,7 @@ int preserve_atimes = 0;
 int preserve_crtimes = 0;
 int omit_dir_times = 0;
 int omit_link_times = 0;
+int trust_sender = 0;
 int update_only = 0;
 int open_noatime = 0;
 int cvs_exclude = 0;
@@ -785,9 +788,12 @@ static struct poptOption long_options[] = {
   {"no-from0",         0,  POPT_ARG_VAL,    &eol_nulls, 0, 0, 0},
   {"old-args",         0,  POPT_ARG_NONE,   0, OPT_OLD_ARGS, 0, 0},
   {"no-old-args",      0,  POPT_ARG_VAL,    &old_style_args, 0, 0, 0},
-  {"protect-args",    's', POPT_ARG_VAL,    &protect_args, 1, 0, 0},
+  {"secluded-args",   's', POPT_ARG_VAL,    &protect_args, 1, 0, 0},
+  {"no-secluded-args", 0,  POPT_ARG_VAL,    &protect_args, 0, 0, 0},
+  {"protect-args",     0,  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},
+  {"trust-sender",     0,  POPT_ARG_VAL,    &trust_sender, 1, 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 },
   {"usermap",          0,  POPT_ARG_STRING, 0, OPT_USERMAP, 0, 0 },
@@ -946,7 +952,7 @@ static void set_refuse_options(void)
                if (!am_daemon
                 || op->shortName == 'e' /* Required for compatibility flags */
                 || op->shortName == '0' /* --from0 just modifies --files-from, so refuse that instead (or not) */
-                || op->shortName == 's' /* --protect-args is always OK */
+                || op->shortName == 's' /* --secluded-args is always OK */
                 || op->shortName == 'n' /* --dry-run is always OK */
                 || strcmp("iconv", longName) == 0
                 || strcmp("no-iconv", longName) == 0
@@ -1920,7 +1926,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                saw_stderr_opt = 1;
 
        if (version_opt_cnt) {
-               print_rsync_version(FINFO);
+               print_rsync_version(version_opt_cnt > 1 && !am_server ? FNONE : FINFO);
                exit_cleanup(0);
        }
 
@@ -1945,7 +1951,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
        } else if (old_style_args) {
                if (protect_args > 0) {
                        snprintf(err_buf, sizeof err_buf,
-                                "--protect-args conflicts with --old-args.\n");
+                                "--secluded-args conflicts with --old-args.\n");
                        return 0;
                }
                protect_args = 0;
@@ -1957,7 +1963,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                else if ((arg = getenv("RSYNC_PROTECT_ARGS")) != NULL && *arg)
                        protect_args = atoi(arg) ? 1 : 0;
                else {
-#ifdef RSYNC_USE_PROTECTED_ARGS
+#ifdef RSYNC_USE_SECLUDED_ARGS
                        protect_args = 1;
 #else
                        protect_args = 0;
@@ -2465,6 +2471,11 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                }
        }
 
+       if (trust_sender || am_server || read_batch)
+               trust_sender_args = trust_sender_filter = 1;
+       else if (old_style_args || filesfrom_host != NULL)
+               trust_sender_args = 1;
+
        am_starting_up = 0;
 
        return 1;
@@ -2499,7 +2510,9 @@ char *safe_arg(const char *opt, const char *arg)
        char *ret;
        if (!protect_args && old_style_args < 2 && (!old_style_args || (!is_filename_arg && opt != SPLIT_ARG_WHEN_OLD))) {
                const char *f;
-               if (!old_style_args && *arg == '~' && (relative_paths || !strchr(arg, '/'))) {
+               if (!trust_sender_args && *arg == '~'
+                && ((relative_paths && !strstr(arg, "/./"))
+                 || !strchr(arg, '/'))) {
                        extras++;
                        escape_leading_tilde = 1;
                }