From da053126675cd26bbbc522c67dcd7050e1a91bc4 Mon Sep 17 00:00:00 2001 From: Damien Debin Date: Thu, 1 Feb 2024 13:57:46 +0100 Subject: [PATCH] Don't strip username from `jumphost`, add it if it's missing ; fix bug when connecting with two different usernames for server and jumphost ; fix command line parsing bug when including username in jumphost. (#614) --- src/terminal/SshSetupHandler.cpp | 2 +- src/terminal/TerminalClientMain.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/terminal/SshSetupHandler.cpp b/src/terminal/SshSetupHandler.cpp index 956138796..03027ed32 100644 --- a/src/terminal/SshSetupHandler.cpp +++ b/src/terminal/SshSetupHandler.cpp @@ -60,7 +60,7 @@ string SshSetupHandler::SetupSsh(const string& user, const string& host, if (!jumphost.empty()) { ssh_args = { "-J", - SSH_USER_PREFIX + jumphost, + jumphost, }; } diff --git a/src/terminal/TerminalClientMain.cpp b/src/terminal/TerminalClientMain.cpp index dd1cf05f3..eba509c92 100644 --- a/src/terminal/TerminalClientMain.cpp +++ b/src/terminal/TerminalClientMain.cpp @@ -259,11 +259,7 @@ int main(int argc, char** argv) { string proxyjump = string(sshConfigOptions.ProxyJump); size_t colonIndex = proxyjump.find(":"); if (colonIndex != string::npos) { - string userhostpair = proxyjump.substr(0, colonIndex); - size_t atIndex = userhostpair.find("@"); - if (atIndex != string::npos) { - jumphost = userhostpair.substr(atIndex + 1); - } + jumphost = proxyjump.substr(0, colonIndex); } else { jumphost = proxyjump; } @@ -275,7 +271,13 @@ int main(int argc, char** argv) { if (!jumphost.empty()) { is_jumphost = true; LOG(INFO) << "Setting port to jumphost port"; - socketEndpoint.set_name(jumphost); + size_t atIndex = jumphost.find("@"); + if (atIndex != string::npos) { + socketEndpoint.set_name(jumphost.substr(atIndex + 1)); + } else { + socketEndpoint.set_name(jumphost); + jumphost = username + "@" + jumphost; + } socketEndpoint.set_port(result["jport"].as()); } else { socketEndpoint.set_name(destinationHost);