]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Set RSYNC_PORT in the env for a daemon-over-rsh connection.
authorWayne Davison <wayned@samba.org>
Mon, 6 Apr 2020 02:32:40 +0000 (19:32 -0700)
committerWayne Davison <wayned@samba.org>
Mon, 6 Apr 2020 02:34:27 +0000 (19:34 -0700)
Fixes bug #14163.

clientserver.c
main.c
options.c
rsync.yo

index 2f8f2f254430b38a0d3635e972137a7ce5c6139e..692a4047ab998cf530795e0eefda5974a6da3ca1 100644 (file)
@@ -487,7 +487,7 @@ static void set_env_str(const char *var, const char *str)
 }
 
 #ifdef HAVE_PUTENV
-static void set_env_num(const char *var, long num)
+void set_env_num(const char *var, long num)
 {
        char *mem;
        if (asprintf(&mem, "%s=%ld", var, num) < 0)
diff --git a/main.c b/main.c
index b594ab82829d6838ddedfd211814451ce2efa590..1328c504098760a9b959a6e2395ee6cc16be0de6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1359,7 +1359,7 @@ static int start_client(int argc, char *argv[])
 {
        char *p, *shell_machine = NULL, *shell_user = NULL;
        char **remote_argv;
-       int remote_argc;
+       int remote_argc, env_port = rsync_port;
        int f_in, f_out;
        int ret;
        pid_t pid;
@@ -1425,6 +1425,7 @@ static int start_client(int argc, char *argv[])
                                        exit_cleanup(RERR_SYNTAX);
                                }
                                shell_machine = NULL;
+                               rsync_port = 0;
                        } else { /* hostspec was found, so dest is remote */
                                argv[argc] = path;
                                if (rsync_port)
@@ -1439,6 +1440,7 @@ static int start_client(int argc, char *argv[])
                }
                remote_argv = argv += argc - 1;
                remote_argc = argc = 1;
+               rsync_port = 0;
        }
 
        if (!rsync_port && remote_argc && !**remote_argv) /* Turn an empty arg into a dot dir. */
@@ -1485,6 +1487,11 @@ static int start_client(int argc, char *argv[])
                }
        }
 
+       if (rsync_port < 0)
+               rsync_port = RSYNC_PORT;
+       else
+               env_port = rsync_port;
+
        if (daemon_over_rsh < 0)
                return start_socket_client(shell_machine, remote_argc, remote_argv, argc, argv);
 
@@ -1515,6 +1522,11 @@ static int start_client(int argc, char *argv[])
                        NS(remote_argv[0]));
        }
 
+#ifdef HAVE_PUTENV
+       if (daemon_over_rsh)
+               set_env_num("RSYNC_PORT", env_port);
+#endif
+
        pid = do_cmd(shell_cmd, shell_machine, shell_user, remote_argv, remote_argc,
                     &f_in, &f_out);
 
index 96e5ffba82bdfc472212170184e9b29bc49c9b30..2db357e272727c76e3a090f6240a844c54687bdc 100644 (file)
--- a/options.c
+++ b/options.c
@@ -2926,7 +2926,7 @@ char *check_for_hostspec(char *s, char **host_ptr, int *port_ptr)
                *host_ptr = parse_hostspec(s + strlen(URL_PREFIX), &path, port_ptr);
                if (*host_ptr) {
                        if (!*port_ptr)
-                               *port_ptr = RSYNC_PORT;
+                               *port_ptr = -1; /* -1 indicates they want the default */
                        return path;
                }
        }
index 7137861493ff464345a6be22bbe4658e9b8598c6..bcb33a79b328b7f0f64ab6511e6b571b67298287 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -1594,6 +1594,15 @@ shell connection, rather than through a direct socket connection to a
 running rsync daemon on the remote host.  See the section "USING
 RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION" above.
 
+Beginning with rsync 3.1.4, the RSYNC_PORT environment variable will be
+set when a daemon connection is being made via a remote-shell
+connection.  It is set to 0 if the default daemon port is being assumed,
+or it is set to the value of the rsync port that was specified via
+either the bf(--port) option or a non-empty port value in an rsync://
+URL.  This allows the script to discern if a non-default port is being
+requested, allowing for things such as an SSL or stunnel helper script
+to connect to a default or alternate port.
+
 Command-line arguments are permitted in COMMAND provided that COMMAND is
 presented to rsync as a single argument.  You must use spaces (not tabs
 or other whitespace) to separate the command and args from each other,