GUACAMOLE-203: Expand SSH keepalives to cover SFTP connections for other 
protocols.


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/e7fc8a0d
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/e7fc8a0d
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/e7fc8a0d

Branch: refs/heads/master
Commit: e7fc8a0d98aeef29ee7e2d5ff9b7520bdf42dc32
Parents: 9993684
Author: Nick Couchman <[email protected]>
Authored: Wed May 31 20:17:00 2017 -0400
Committer: Nick Couchman <[email protected]>
Committed: Wed May 31 21:03:09 2017 -0400

----------------------------------------------------------------------
 src/common-ssh/common-ssh/ssh.h | 2 +-
 src/common-ssh/ssh.c            | 6 +++++-
 src/protocols/rdp/rdp.c         | 2 +-
 src/protocols/rdp/rdp.h         | 5 +++++
 src/protocols/ssh/ssh.c         | 8 ++------
 src/protocols/vnc/vnc.c         | 2 +-
 src/protocols/vnc/vnc.h         | 5 +++++
 7 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/common-ssh/common-ssh/ssh.h
----------------------------------------------------------------------
diff --git a/src/common-ssh/common-ssh/ssh.h b/src/common-ssh/common-ssh/ssh.h
index d96ce44..ff8621e 100644
--- a/src/common-ssh/common-ssh/ssh.h
+++ b/src/common-ssh/common-ssh/ssh.h
@@ -98,7 +98,7 @@ void guac_common_ssh_uninit();
  *     if the connection or authentication were not successful.
  */
 guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client,
-        const char* hostname, const char* port, guac_common_ssh_user* user);
+        const char* hostname, const char* port, guac_common_ssh_user* user, 
const int keepalive);
 
 /**
  * Disconnects and destroys the given SSH session, freeing all associated

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/common-ssh/ssh.c
----------------------------------------------------------------------
diff --git a/src/common-ssh/ssh.c b/src/common-ssh/ssh.c
index 57bc821..3bff4b3 100644
--- a/src/common-ssh/ssh.c
+++ b/src/common-ssh/ssh.c
@@ -414,7 +414,7 @@ static int 
guac_common_ssh_authenticate(guac_common_ssh_session* common_session)
 }
 
 guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client,
-        const char* hostname, const char* port, guac_common_ssh_user* user) {
+        const char* hostname, const char* port, guac_common_ssh_user* user, 
const int keepalive) {
 
     int retval;
 
@@ -532,6 +532,10 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
         return NULL;
     }
 
+    /* Configure session keepalive */
+    if (keepalive > 0)
+        libssh2_keepalive_config(common_session->session, 1, keepalive);
+
     /* Return created session */
     return common_session;
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/protocols/rdp/rdp.c
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c
index cf9be2e..bbe7685 100644
--- a/src/protocols/rdp/rdp.c
+++ b/src/protocols/rdp/rdp.c
@@ -977,7 +977,7 @@ void* guac_rdp_client_thread(void* data) {
         /* Attempt SSH connection */
         rdp_client->sftp_session =
             guac_common_ssh_create_session(client, settings->sftp_hostname,
-                    settings->sftp_port, rdp_client->sftp_user);
+                    settings->sftp_port, rdp_client->sftp_user, 
rdp_client->sftp_keepalive);
 
         /* Fail if SSH connection does not succeed */
         if (rdp_client->sftp_session == NULL) {

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/protocols/rdp/rdp.h
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h
index 943155d..70e909b 100644
--- a/src/protocols/rdp/rdp.h
+++ b/src/protocols/rdp/rdp.h
@@ -141,6 +141,11 @@ typedef struct guac_rdp_client {
      * An SFTP-based filesystem.
      */
     guac_common_ssh_sftp_filesystem* sftp_filesystem;
+
+    /**
+     * A keepalive interval for SFTP connections.
+     */
+    int sftp_keepalive;
 #endif
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/protocols/ssh/ssh.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c
index 2504df9..86c1fdf 100644
--- a/src/protocols/ssh/ssh.c
+++ b/src/protocols/ssh/ssh.c
@@ -218,16 +218,12 @@ void* ssh_client_thread(void* data) {
 
     /* Open SSH session */
     ssh_client->session = guac_common_ssh_create_session(client,
-            settings->hostname, settings->port, ssh_client->user);
+            settings->hostname, settings->port, ssh_client->user, 
settings->server_alive_interval);
     if (ssh_client->session == NULL) {
         /* Already aborted within guac_common_ssh_create_session() */
         return NULL;
     }
 
-    /* Set keepalive configuration for session */
-    if (settings->server_alive_interval > 0)
-        libssh2_keepalive_config(ssh_client->session->session, 1, 
settings->server_alive_interval);
-
     pthread_mutex_init(&ssh_client->term_channel_lock, NULL);
 
     /* Open channel for terminal */
@@ -262,7 +258,7 @@ void* ssh_client_thread(void* data) {
         guac_client_log(client, GUAC_LOG_DEBUG, "Reconnecting for SFTP...");
         ssh_client->sftp_session =
             guac_common_ssh_create_session(client, settings->hostname,
-                    settings->port, ssh_client->user);
+                    settings->port, ssh_client->user, 
settings->server_alive_interval);
         if (ssh_client->sftp_session == NULL) {
             /* Already aborted within guac_common_ssh_create_session() */
             return NULL;

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/protocols/vnc/vnc.c
----------------------------------------------------------------------
diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c
index 8678ee2..4410e5f 100644
--- a/src/protocols/vnc/vnc.c
+++ b/src/protocols/vnc/vnc.c
@@ -261,7 +261,7 @@ void* guac_vnc_client_thread(void* data) {
         /* Attempt SSH connection */
         vnc_client->sftp_session =
             guac_common_ssh_create_session(client, settings->sftp_hostname,
-                    settings->sftp_port, vnc_client->sftp_user);
+                    settings->sftp_port, vnc_client->sftp_user, 
vnc_client->sftp_keepalive);
 
         /* Fail if SSH connection does not succeed */
         if (vnc_client->sftp_session == NULL) {

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/e7fc8a0d/src/protocols/vnc/vnc.h
----------------------------------------------------------------------
diff --git a/src/protocols/vnc/vnc.h b/src/protocols/vnc/vnc.h
index 0edbcd4..a09f3ed 100644
--- a/src/protocols/vnc/vnc.h
+++ b/src/protocols/vnc/vnc.h
@@ -108,6 +108,11 @@ typedef struct guac_vnc_client {
      * An SFTP-based filesystem.
      */
     guac_common_ssh_sftp_filesystem* sftp_filesystem;
+
+    /**
+     * The interval at which to send SSH keepalive messages for SFTP.
+     */
+    int sftp_keepalive;
 #endif
 
     /**

Reply via email to