GUACAMOLE-527: Clean up memory and logging.

This commit is contained in:
Nick Couchman 2018-04-06 06:47:35 -04:00 committed by Nick Couchman
parent ec4315dfbe
commit 42044e4279
4 changed files with 18 additions and 8 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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 =

View File

@ -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);