diff --git a/src/common-ssh/common-ssh/ssh.h b/src/common-ssh/common-ssh/ssh.h index d96ce44c..ff8621e9 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 diff --git a/src/common-ssh/ssh.c b/src/common-ssh/ssh.c index 57bc8217..3bff4b39 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; diff --git a/src/protocols/rdp/rdp.c b/src/protocols/rdp/rdp.c index cf9be2ef..bbe76851 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) { diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h index 943155dd..70e909b1 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 /** diff --git a/src/protocols/ssh/ssh.c b/src/protocols/ssh/ssh.c index 2504df92..86c1fdfc 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; diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c index 8678ee29..4410e5f7 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) { diff --git a/src/protocols/vnc/vnc.h b/src/protocols/vnc/vnc.h index 0edbcd47..a09f3ed3 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 /**