GUACAMOLE-527: Clean up memory and logging.

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

Branch: refs/heads/staging/1.0.0
Commit: 42044e42799402898c00ace8ca770c94f6799843
Parents: ec4315d
Author: Nick Couchman <vn...@apache.org>
Authored: Fri Apr 6 06:47:35 2018 -0400
Committer: Nick Couchman <nick_couch...@cotyinc.com>
Committed: Mon Jun 25 08:31:37 2018 -0400

----------------------------------------------------------------------
 src/common-ssh/ssh.c             | 18 ++++++++++--------
 src/protocols/rdp/rdp_settings.c |  3 +++
 src/protocols/ssh/settings.c     |  2 ++
 src/protocols/vnc/settings.c     |  3 +++
 4 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/42044e42/src/common-ssh/ssh.c
----------------------------------------------------------------------
diff --git a/src/common-ssh/ssh.c b/src/common-ssh/ssh.c
index 1327b03..03c4d12 100644
--- a/src/common-ssh/ssh.c
+++ b/src/common-ssh/ssh.c
@@ -520,22 +520,22 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
         return NULL;
     }
 
-    /* Check known_hosts */
-    /* Get known hosts file from user running guacd */
+    /* Check known_hosts, start by getting known_hosts file of user running 
guacd */
     struct passwd *pw = getpwuid(getuid());
-    char *homedir = pw->pw_dir;
-    char *known_hosts = strcat(homedir, "/.ssh/known_hosts");
+    const char *known_hosts = strcat(pw->pw_dir, "/.ssh/known_hosts");
     LIBSSH2_KNOWNHOSTS *ssh_known_hosts = libssh2_knownhost_init(session);
     libssh2_knownhost_readfile(ssh_known_hosts, known_hosts, 
LIBSSH2_KNOWNHOST_FILE_OPENSSH);
 
     /* Add host key provided from settings */
     if (host_key && strcmp(host_key, "") > 0) {
 
-        if (libssh2_knownhost_addc(ssh_known_hosts, hostname, NULL, host_key, 
strlen(host_key),
+        int kh_add = libssh2_knownhost_addc(ssh_known_hosts, hostname, NULL, 
host_key, strlen(host_key),
                 NULL, 0, 
LIBSSH2_KNOWNHOST_TYPE_PLAIN|LIBSSH2_KNOWNHOST_KEYENC_BASE64|
-                         host_key_type, NULL))
-            guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
-                "Failed to add host key to known hosts store for %s", 
hostname);
+                         host_key_type, NULL);
+
+        if (kh_add)
+            guac_client_log(client, GUAC_LOG_WARNING, "Failed to add provided 
host key"
+                    " to known hosts store for %s.  Error was %d", hostname, 
kh_add);
 
     }
 
@@ -556,6 +556,8 @@ guac_common_ssh_session* 
guac_common_ssh_create_session(guac_client* client,
                                          LIBSSH2_KNOWNHOST_KEYENC_RAW,
                                          &host);
 
+    libssh2_knownhost_free(ssh_known_hosts);
+
     switch (kh_check) {
         case LIBSSH2_KNOWNHOST_CHECK_MATCH:
             guac_client_log(client, GUAC_LOG_DEBUG,

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/42044e42/src/protocols/rdp/rdp_settings.c
----------------------------------------------------------------------
diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c
index 78afe37..65e79e6 100644
--- a/src/protocols/rdp/rdp_settings.c
+++ b/src/protocols/rdp/rdp_settings.c
@@ -860,6 +860,8 @@ guac_rdp_settings* guac_rdp_parse_args(guac_user* user,
             settings->sftp_host_key = NULL;
         }
 
+        free(str_host_key_type);
+
     }
 
     /* Port for SFTP connection */
@@ -1039,6 +1041,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) {
     /* Free SFTP settings */
     free(settings->sftp_directory);
     free(settings->sftp_root_directory);
+    free(settings->sftp_host_key);
     free(settings->sftp_hostname);
     free(settings->sftp_passphrase);
     free(settings->sftp_password);

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/42044e42/src/protocols/ssh/settings.c
----------------------------------------------------------------------
diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c
index d49a16c..119d725 100644
--- a/src/protocols/ssh/settings.c
+++ b/src/protocols/ssh/settings.c
@@ -278,6 +278,8 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user,
                     "Ignoring host key.", str_host_key_type);
             settings->host_key = NULL;
         }
+
+        free(str_host_key_type);
     }
 
     settings->username =

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/42044e42/src/protocols/vnc/settings.c
----------------------------------------------------------------------
diff --git a/src/protocols/vnc/settings.c b/src/protocols/vnc/settings.c
index 509a067..5f82b39 100644
--- a/src/protocols/vnc/settings.c
+++ b/src/protocols/vnc/settings.c
@@ -446,6 +446,8 @@ guac_vnc_settings* guac_vnc_parse_args(guac_user* user,
             settings->sftp_host_key = NULL;
         }
 
+        free(str_host_key_type);
+
     }
 
     /* Port for SFTP connection */
@@ -541,6 +543,7 @@ void guac_vnc_settings_free(guac_vnc_settings* settings) {
     /* Free SFTP settings */
     free(settings->sftp_directory);
     free(settings->sftp_root_directory);
+    free(settings->sftp_host_key);
     free(settings->sftp_hostname);
     free(settings->sftp_passphrase);
     free(settings->sftp_password);

Reply via email to