[X2Go-Commits] [x2goclient] 01/01: src/sshmasterconnection.cpp: fix SSH-proxied connections with port numbers of zero.

git-admin at x2go.org git-admin at x2go.org
Fri Aug 18 08:09:23 CEST 2017


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2goclient.

commit 898717ba5b254e7b43145b36c66bea07d3c44ff9
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Fri Aug 18 08:05:59 2017 +0200

    src/sshmasterconnection.cpp: fix SSH-proxied connections with port numbers of zero.
    
    In order to authenticate the remote server, SSH-proxied connections must
    be reset to their remote host and port values after connecting via the
    SSH tunnel.
    
    If the original port value was zero, setting it was skipped, leading to
    connections like $REMOTE_HOST:$PROXY_PORT, which is certainly wrong.
    
    Fetch the inferred port value and set this instead, fixing this issue.
---
 debian/changelog            |  8 ++++++++
 src/sshmasterconnection.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 07f0ed8..8ce225f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -153,6 +153,14 @@ x2goclient (4.1.0.1-0x2go1) UNRELEASED; urgency=medium
       after a session has been suspended/terminated if user name was not
       provided. Do not insert an user name, though, but leave it to
       autodetection by default.
+    - src/sshmasterconnection.cpp: fix SSH-proxied connections with port
+      numbers of zero.
+      In order to authenticate the remote server, SSH-proxied connections must
+      be reset to their remote host and port values after connecting via the
+      SSH tunnel. If the original port value was zero, setting it was skipped,
+      leading to connections like $REMOTE_HOST:$PROXY_PORT, which is certainly
+      wrong. Fetch the inferred port value and set this instead, fixing this
+      issue.
 
   [ Oleksandr Shneyder ]
   * New upstream version (4.1.0.1):
diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index ea34c68..2063ded 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -895,10 +895,54 @@ bool SshMasterConnection::sshConnect()
 //set values for remote host for proper server authentication
     if(useproxy && proxytype==PROXYSSH)
     {
+        x2goDebug << "Connected via proxy, resetting connection values on session to " << tmpBA.data() << ":" << port;
         ssh_options_set ( my_ssh_session, SSH_OPTIONS_HOST, tmpBA.data() );
-        if (port) {
-            ssh_options_set ( my_ssh_session, SSH_OPTIONS_PORT, &port );
+
+        /*
+         * The SSH port might be 0, which indicates to use the default port
+         * or a custom one specified in the config file.
+         * We need to fetch the latter and then set the port unconditionally.
+         *
+         * The tricky part is that we already set a port before (in this case our proxy port.)
+         * There's no way to reset the port for this session to its default value of 0 again,
+         * so we'll need to create a new session, set the hostname
+         * and fetch the inferred port value from there.
+         *
+         * Failure to do so will trigger funny bugs like connecting to the correct remote host,
+         * but at a proxied port value.
+         */
+        int work_port = port;
+
+        /* Oh, yeah, and we don't really support port values of 0 for pre-0.6.0 libssh. Sorry. */
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+        if (!work_port) {
+            ssh_session tmp_session = ssh_new ();
+
+            if (!tmp_session) {
+                QString error_msg = tr ("Cannot create SSH session.");
+#ifdef DEBUG
+                x2goDebug << error_msg;
+#endif
+                return (false);
+            }
+            else {
+                ssh_options_set (tmp_session, SSH_OPTIONS_HOST, tmpBA.data ());
+
+                /* Parse ~/.ssh/config. */
+                if (ssh_options_parse_config (tmp_session, NULL) < 0) {
+                    x2goDebug << "Warning: unable to parse the SSH config file.";
+                }
+
+                unsigned int inferred_port = 0;
+                ssh_options_get_port (tmp_session, &inferred_port);
+                x2goDebug << "Fetched inferred session port: " << inferred_port;
+
+                work_port = inferred_port & 0xFFFF;
+            }
         }
+#endif
+
+        ssh_options_set ( my_ssh_session, SSH_OPTIONS_PORT, &work_port );
     }
 
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git


More information about the x2go-commits mailing list