Ignore --protect-args when already sent by client
[rsync.git] / options.c
index 6ba13b7d6ca516a504b0c27f715c28b5ee9c27e6..cb94ef03aba47221410a26f8e0bae5673092d91e 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1281,6 +1281,22 @@ static void create_refuse_error(int which)
        }
 }
 
+/* This is used to make sure that --daemon & --server cannot be aliased to
+ * something else. These options have always disabled popt aliases for the
+ * parsing of a daemon or server command-line, but we have to make sure that
+ * these options cannot vanish so that the alias disabling can take effect. */
+static void popt_unalias(poptContext con, const char *opt)
+{
+       struct poptAlias unalias;
+
+       unalias.longName = opt + 2; /* point past the leading "--" */
+       unalias.shortName = '\0';
+       unalias.argc = 1;
+       unalias.argv = new_array(const char*, 1);
+       unalias.argv[0] = strdup(opt);
+
+       poptAddAlias(con, unalias, 0);
+}
 
 /**
  * Process command line arguments.  Called on both local and remote.
@@ -1297,6 +1313,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
        const char *arg, **argv = *argv_p;
        int argc = *argc_p;
        int opt;
+       int orig_protect_args = protect_args;
 
        if (ref && *ref)
                set_refuse_options(ref);
@@ -1320,8 +1337,11 @@ int parse_arguments(int *argc_p, const char ***argv_p)
        if (pc)
                poptFreeContext(pc);
        pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
-       if (!am_server)
+       if (!am_server) {
                poptReadDefaultConfig(pc, 0);
+               popt_unalias(pc, "--daemon");
+               popt_unalias(pc, "--server");
+       }
 
        while ((opt = poptGetNextOpt(pc)) != -1) {
                /* most options are handled automatically by popt;
@@ -1915,6 +1935,10 @@ int parse_arguments(int *argc_p, const char ***argv_p)
        if (fuzzy_basis > 1)
                fuzzy_basis = basis_dir_cnt + 1;
 
+       /* Don't let the client reset protect_args if it was already processed */
+       if (orig_protect_args == 2 && am_server)
+               protect_args = orig_protect_args;
+
        if (protect_args == 1 && am_server)
                return 1;