From: Wayne Davison Date: Sun, 14 Jun 2020 01:49:52 +0000 (-0700) Subject: Make -4 & -6 also able to affect an ssh remote shell. X-Git-Tag: v3.2.0pre1~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d1c0f14e16a98ecbf0d11b46e13859076b69ffa;p=thirdparty%2Frsync.git Make -4 & -6 also able to affect an ssh remote shell. --- diff --git a/NEWS.md b/NEWS.md index bfadccde..18a28545 100644 --- a/NEWS.md +++ b/NEWS.md @@ -134,6 +134,9 @@ Protocol: 31 (unchanged) - Made -V the short option for --version. + - Forward -4 & -6 options to the ssh command, making them easier to type than + "--rsh='ssh -4'" (or -6). + ### PACKAGING RELATED: - Add installed binary: /usr/bin/rsync-sll diff --git a/main.c b/main.c index a0b2fbc5..b41a3943 100644 --- a/main.c +++ b/main.c @@ -81,6 +81,7 @@ extern BOOL want_progress_now; extern BOOL shutting_down; extern int backup_dir_len; extern int basis_dir_cnt; +extern int default_af_hint; extern struct stats stats; extern char *stdout_format; extern char *logfile_format; @@ -547,8 +548,13 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in *t++ = '\0'; } - /* check to see if we've already been given '-l user' in - * the remote-shell command */ + /* NOTE: must preserve t == start of command name until the end of the args handling! */ + if ((t = strrchr(cmd, '/')) != NULL) + t++; + else + t = cmd; + + /* Check to see if we've already been given '-l user' in the remote-shell command. */ for (i = 0; i < argc-1; i++) { if (!strcmp(args[i], "-l") && args[i+1][0] != '-') dash_l_set = 1; @@ -566,22 +572,23 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in args[argc++] = "-l"; args[argc++] = user; } +#ifdef AF_INET + if (default_af_hint == AF_INET && strcmp(t, "ssh") == 0) + args[argc++] = "-4"; /* we're using ssh so we can add a -4 option */ +#endif +#ifdef AF_INET6 + if (default_af_hint == AF_INET6 && strcmp(t, "ssh") == 0) + args[argc++] = "-6"; /* we're using ssh so we can add a -6 option */ +#endif args[argc++] = machine; #endif args[argc++] = rsync_path; - if (blocking_io < 0) { - char *cp; - if ((cp = strrchr(cmd, '/')) != NULL) - cp++; - else - cp = cmd; - if (strcmp(cp, "rsh") == 0 || strcmp(cp, "remsh") == 0) - blocking_io = 1; - } + if (blocking_io < 0 && (strcmp(t, "rsh") == 0 || strcmp(t, "remsh") == 0)) + blocking_io = 1; - server_options(args,&argc); + server_options(args, &argc); if (argc >= MAX_ARGS - 2) goto arg_overflow; diff --git a/rsync.1.md b/rsync.1.md index 0af45bda..f611cd6c 100644 --- a/rsync.1.md +++ b/rsync.1.md @@ -3068,13 +3068,21 @@ your home directory (remove the '=' for that). 0. `--ipv4`, `-4` or `--ipv6`, `-6` - Tells rsync to prefer IPv4/IPv6 when creating sockets. This only affects - sockets that rsync has direct control over, such as the outgoing socket - when directly contacting an rsync daemon. See also these options in the - `--daemon` mode section. + Tells rsync to prefer IPv4/IPv6 when creating sockets or running ssh. This + affects sockets that rsync has direct control over, such as the outgoing + socket when directly contacting an rsync daemon, as well as the forwaring + of the `-4` or `-6` option to ssh when rsync can deduce that ssh is being + used as the remote shell. For other remote shells you'll need to specify + the "`--rsh SHELL -4`" option directly (or whatever ipv4/ipv6 hint options + it uses). + + These options also exist in the `--daemon` mode section. If rsync was complied without support for IPv6, the `--ipv6` option will - have no effect. The `--version` output will tell you if this is the case. + have no effect. The `rsync -V` output will contain "no IPv6" if is the + case. + + See also these options in the `--daemon` mode section. 0. `--checksum-seed=NUM` @@ -3184,8 +3192,11 @@ The options allowed when starting an rsync daemon are as follows: using the port, try specifying `--ipv6` or `--ipv4` when starting the daemon). + These options also exist in the regular rsync options section. + If rsync was complied without support for IPv6, the `--ipv6` option will - have no effect. The `--version` output will tell you if this is the case. + have no effect. The `rsync -V` output will contain "no IPv6" if is the + case. 0. `--help`, `-h`