GUAC-1171: Ensure user and session objects are automatically free'd, and that this is documented.
This commit is contained in:
parent
46ce69a8a9
commit
cdefe52c67
@ -94,7 +94,8 @@ typedef struct guac_common_ssh_sftp_ls_state {
|
||||
* guac_common_ssh_destroy_sftp_filesystem().
|
||||
*
|
||||
* @param session
|
||||
* The session to use to provide SFTP.
|
||||
* The session to use to provide SFTP. This session will automatically be
|
||||
* destroyed when this filesystem is destroyed.
|
||||
*
|
||||
* @param name
|
||||
* The name to send as the name of the filesystem.
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "guac_ssh.h"
|
||||
#include "guac_ssh_key.h"
|
||||
#include "guac_ssh_user.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
#include <libssh2.h>
|
||||
@ -477,8 +478,17 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client,
|
||||
}
|
||||
|
||||
void guac_common_ssh_destroy_session(guac_common_ssh_session* session) {
|
||||
|
||||
/* Disconnect and clean up libssh2 */
|
||||
libssh2_session_disconnect(session->session, "Bye");
|
||||
libssh2_session_free(session->session);
|
||||
|
||||
/* Destroy associated user */
|
||||
if (session->user)
|
||||
guac_common_ssh_destroy_user(session->user);
|
||||
|
||||
/* Free all other data */
|
||||
free(session);
|
||||
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,8 @@ void guac_common_ssh_uninit();
|
||||
* The port to connect to on the given hostname.
|
||||
*
|
||||
* @param user
|
||||
* The user to authenticate as, once connected.
|
||||
* The user to authenticate as, once connected. This user will be
|
||||
* automatically destroyed when this session is destroyed.
|
||||
*
|
||||
* @return
|
||||
* A new SSH session if the connection and authentication succeed, or NULL
|
||||
|
@ -842,8 +842,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
/* Abort if private key cannot be read */
|
||||
if (guac_common_ssh_user_import_key(user,
|
||||
argv[IDX_SFTP_PRIVATE_KEY],
|
||||
argv[IDX_SFTP_PASSPHRASE]))
|
||||
argv[IDX_SFTP_PASSPHRASE])) {
|
||||
guac_common_ssh_destroy_user(user);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -880,6 +882,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
/* Fail if SSH connection does not succeed */
|
||||
if (session == NULL) {
|
||||
/* Already aborted within guac_common_ssh_create_session() */
|
||||
guac_common_ssh_destroy_user(user);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -384,8 +384,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
/* Abort if private key cannot be read */
|
||||
if (guac_common_ssh_user_import_key(user,
|
||||
argv[IDX_SFTP_PRIVATE_KEY],
|
||||
argv[IDX_SFTP_PASSPHRASE]))
|
||||
argv[IDX_SFTP_PASSPHRASE])) {
|
||||
guac_common_ssh_destroy_user(user);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -414,6 +416,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||
/* Fail if SSH connection does not succeed */
|
||||
if (session == NULL) {
|
||||
/* Already aborted within guac_common_ssh_create_session() */
|
||||
guac_common_ssh_destroy_user(user);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user