Repository: incubator-guacamole-server
Updated Branches:
  refs/heads/master 4e8096093 -> afb554a01


GUACAMOLE-396: Fixing ssh socket for IPv6 address

Root Cause:
In the ssh library of guacd, the TCP socket for connecting to ssh server is 
created with AF_INET. So it does not support IPv6 address.

Solution:
When guacd creates the socket for ssh in guac_common_ssh_create_session(), stop 
using hard coded AF_INET for socket() call, use the address family which is 
returned from getaddrinfo().

Test:
- Connected successfully via ssh connections with IPv4 and IPv6 hosts.
- No connection error in guacd logs.
- Simulated a connection failure with specifying a ssh server which does not 
exist. guacd worked well in this case.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/f5597016
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/f5597016
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/f5597016

Branch: refs/heads/master
Commit: f559701645f6bf49aa384a5b5f80ae1e73280245
Parents: 4e80960
Author: James <10353316+san...@users.noreply.github.com>
Authored: Mon Sep 25 16:57:33 2017 -0700
Committer: sanhex <san...@gmail.com>
Committed: Tue Sep 26 17:19:18 2017 -0700

----------------------------------------------------------------------
 src/common-ssh/ssh.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f5597016/src/common-ssh/ssh.c
----------------------------------------------------------------------
diff --git a/src/common-ssh/ssh.c b/src/common-ssh/ssh.c
index cec3d53..d3e1e42 100644
--- a/src/common-ssh/ssh.c
+++ b/src/common-ssh/ssh.c
@@ -431,20 +431,11 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
         .ai_protocol = IPPROTO_TCP
     };
 
-    /* Get socket */
-    fd = socket(AF_INET, SOCK_STREAM, 0);
-    if (fd < 0) {
-        guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
-                "Unable to create socket: %s", strerror(errno));
-        return NULL;
-    }
-
     /* Get addresses connection */
     if ((retval = getaddrinfo(hostname, port, &hints, &addresses))) {
         guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
                 "Error parsing given address or port: %s",
                 gai_strerror(retval));
-        close(fd);
         return NULL;
     }
 
@@ -461,6 +452,14 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
             guac_client_log(client, GUAC_LOG_DEBUG,
                     "Unable to resolve host: %s", gai_strerror(retval));
 
+        /* Get socket */
+        fd = socket(current_address->ai_family, SOCK_STREAM, 0);
+        if (fd < 0) {
+            guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
+                    "Unable to create socket: %s", strerror(errno));
+            return NULL;
+        }
+
         /* Connect */
         if (connect(fd, current_address->ai_addr,
                         current_address->ai_addrlen) == 0) {
@@ -475,11 +474,11 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
         }
 
         /* Otherwise log information regarding bind failure */
-        else
-            guac_client_log(client, GUAC_LOG_DEBUG, "Unable to connect to "
-                    "host %s, port %s: %s",
-                    connected_address, connected_port, strerror(errno));
+        guac_client_log(client, GUAC_LOG_DEBUG, "Unable to connect to "
+                "host %s, port %s: %s",
+                connected_address, connected_port, strerror(errno));
 
+        close(fd);
         current_address = current_address->ai_next;
 
     }
@@ -491,7 +490,6 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
     if (current_address == NULL) {
         guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_NOT_FOUND,
                 "Unable to connect to any addresses.");
-        close(fd);
         return NULL;
     }
 

Reply via email to