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; return NULL;
} }
/* Check known_hosts */ /* Check known_hosts, start by getting known_hosts file of user running guacd */
/* Get known hosts file from user running guacd */
struct passwd *pw = getpwuid(getuid()); struct passwd *pw = getpwuid(getuid());
char *homedir = pw->pw_dir; const char *known_hosts = strcat(pw->pw_dir, "/.ssh/known_hosts");
char *known_hosts = strcat(homedir, "/.ssh/known_hosts");
LIBSSH2_KNOWNHOSTS *ssh_known_hosts = libssh2_knownhost_init(session); LIBSSH2_KNOWNHOSTS *ssh_known_hosts = libssh2_knownhost_init(session);
libssh2_knownhost_readfile(ssh_known_hosts, known_hosts, LIBSSH2_KNOWNHOST_FILE_OPENSSH); libssh2_knownhost_readfile(ssh_known_hosts, known_hosts, LIBSSH2_KNOWNHOST_FILE_OPENSSH);
/* Add host key provided from settings */ /* Add host key provided from settings */
if (host_key && strcmp(host_key, "") > 0) { 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| NULL, 0, LIBSSH2_KNOWNHOST_TYPE_PLAIN|LIBSSH2_KNOWNHOST_KEYENC_BASE64|
host_key_type, NULL)) 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); 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, LIBSSH2_KNOWNHOST_KEYENC_RAW,
&host); &host);
libssh2_knownhost_free(ssh_known_hosts);
switch (kh_check) { switch (kh_check) {
case LIBSSH2_KNOWNHOST_CHECK_MATCH: case LIBSSH2_KNOWNHOST_CHECK_MATCH:
guac_client_log(client, GUAC_LOG_DEBUG, 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; settings->sftp_host_key = NULL;
} }
free(str_host_key_type);
} }
/* Port for SFTP connection */ /* Port for SFTP connection */
@ -1039,6 +1041,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) {
/* Free SFTP settings */ /* Free SFTP settings */
free(settings->sftp_directory); free(settings->sftp_directory);
free(settings->sftp_root_directory); free(settings->sftp_root_directory);
free(settings->sftp_host_key);
free(settings->sftp_hostname); free(settings->sftp_hostname);
free(settings->sftp_passphrase); free(settings->sftp_passphrase);
free(settings->sftp_password); 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); "Ignoring host key.", str_host_key_type);
settings->host_key = NULL; settings->host_key = NULL;
} }
free(str_host_key_type);
} }
settings->username = settings->username =

View File

@ -446,6 +446,8 @@ guac_vnc_settings* guac_vnc_parse_args(guac_user* user,
settings->sftp_host_key = NULL; settings->sftp_host_key = NULL;
} }
free(str_host_key_type);
} }
/* Port for SFTP connection */ /* Port for SFTP connection */
@ -541,6 +543,7 @@ void guac_vnc_settings_free(guac_vnc_settings* settings) {
/* Free SFTP settings */ /* Free SFTP settings */
free(settings->sftp_directory); free(settings->sftp_directory);
free(settings->sftp_root_directory); free(settings->sftp_root_directory);
free(settings->sftp_host_key);
free(settings->sftp_hostname); free(settings->sftp_hostname);
free(settings->sftp_passphrase); free(settings->sftp_passphrase);
free(settings->sftp_password); free(settings->sftp_password);