From f880806d2ed3e0a60888eda59f348014f2b73f2f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 8 Feb 2025 16:16:19 +0100 Subject: Add support for sshexec:// prefix and directory suffix in the destination argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- sshexec.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'sshexec.c') diff --git a/sshexec.c b/sshexec.c index a6db757..67868ee 100644 --- a/sshexec.c +++ b/sshexec.c @@ -131,7 +131,8 @@ main(int argc_unused, char *argv[]) const char *ssh = NULL; struct redirection *redirections = NULL; size_t nredirections = 0; - const char *destination; + char *destination; + char *dest_dir_delim; char **opts, *p; size_t nopts; enum optclass class; @@ -240,6 +241,25 @@ main(int argc_unused, char *argv[]) else if (strchr(*argv, '=')) exitf("%s: the command argument must contain an \'=\'\n", argv0); + if (!strncmp(destination, "sshexec://", sizeof("sshexec://") - 1U)) { + memmove(&destination[sizeof("ssh") - 1U], + &destination[sizeof("sshexec") - 1U], + strlen(&destination[sizeof("sshexec") - 1U]) + 1U); + goto using_ssh_prefix; + } else if (!strncmp(destination, "ssh://", sizeof("ssh://") - 1U)) { + using_ssh_prefix: + dest_dir_delim = strchr(&destination[sizeof("ssh://")], '/'); + } else { + dest_dir_delim = strchr(destination, ':'); + } + if (dest_dir_delim) { + if (dir) + exitf("%s: directory specified both in 'dir' option and in destination operand\n", argv0); + *dest_dir_delim++ = '\0'; + dir = dest_dir_delim; + } +dest_dir_checked: + if (dir) { build_command_asis("cd -- "); build_command_escape(dir); -- cgit v1.2.3-70-g09d2