Add enable-sftp option, init/free SFTP as needed.
This commit is contained in:
parent
271f7fbb2f
commit
02fece0a29
@ -65,6 +65,7 @@ const char* GUAC_CLIENT_ARGS[] = {
|
|||||||
"password",
|
"password",
|
||||||
"font-name",
|
"font-name",
|
||||||
"font-size",
|
"font-size",
|
||||||
|
"enable-sftp",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -100,6 +101,11 @@ enum __SSH_ARGS_IDX {
|
|||||||
*/
|
*/
|
||||||
IDX_FONT_SIZE,
|
IDX_FONT_SIZE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether SFTP should be enabled.
|
||||||
|
*/
|
||||||
|
IDX_ENABLE_SFTP,
|
||||||
|
|
||||||
SSH_ARGS_COUNT
|
SSH_ARGS_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,6 +145,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
|||||||
else
|
else
|
||||||
client_data->font_size = GUAC_SSH_DEFAULT_FONT_SIZE;
|
client_data->font_size = GUAC_SSH_DEFAULT_FONT_SIZE;
|
||||||
|
|
||||||
|
/* Parse SFTP enable */
|
||||||
|
client_data->enable_sftp = strcmp(argv[IDX_ENABLE_SFTP], "true") == 0;
|
||||||
|
client_data->sftp_session = NULL;
|
||||||
|
|
||||||
/* Read port */
|
/* Read port */
|
||||||
if (argv[IDX_PORT][0] != 0)
|
if (argv[IDX_PORT][0] != 0)
|
||||||
client_data->port = atoi(argv[IDX_PORT]);
|
client_data->port = atoi(argv[IDX_PORT]);
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
|
#include <libssh/sftp.h>
|
||||||
|
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
@ -80,6 +81,11 @@ typedef struct ssh_guac_client_data {
|
|||||||
*/
|
*/
|
||||||
int font_size;
|
int font_size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether SFTP is enabled.
|
||||||
|
*/
|
||||||
|
bool enable_sftp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SSH client thread.
|
* The SSH client thread.
|
||||||
*/
|
*/
|
||||||
@ -90,6 +96,11 @@ typedef struct ssh_guac_client_data {
|
|||||||
*/
|
*/
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SFTP session, used for file transfers.
|
||||||
|
*/
|
||||||
|
sftp_session sftp_session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SSH terminal channel, used by the SSH client thread.
|
* SSH terminal channel, used by the SSH client thread.
|
||||||
*/
|
*/
|
||||||
|
@ -430,6 +430,10 @@ int ssh_guac_client_free_handler(guac_client* client) {
|
|||||||
/* Free channels */
|
/* Free channels */
|
||||||
ssh_channel_free(guac_client_data->term_channel);
|
ssh_channel_free(guac_client_data->term_channel);
|
||||||
|
|
||||||
|
/* Clean up SFTP */
|
||||||
|
if (guac_client_data->sftp_session)
|
||||||
|
sftp_free(guac_client_data->sftp_session);
|
||||||
|
|
||||||
/* Free session */
|
/* Free session */
|
||||||
ssh_free(guac_client_data->session);
|
ssh_free(guac_client_data->session);
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include <guacamole/socket.h>
|
#include <guacamole/socket.h>
|
||||||
|
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
|
#include <libssh/sftp.h>
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -206,6 +207,30 @@ void* ssh_client_thread(void* data) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Start SFTP session as well, if enabled */
|
||||||
|
if (client_data->enable_sftp) {
|
||||||
|
|
||||||
|
/* Request SFTP */
|
||||||
|
client_data->sftp_session = sftp_new(client_data->session);
|
||||||
|
if (client_data->sftp_session == NULL) {
|
||||||
|
guac_protocol_send_error(socket, "Unable to start SFTP session..",
|
||||||
|
GUAC_PROTOCOL_STATUS_INTERNAL_ERROR);
|
||||||
|
guac_socket_flush(socket);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Init SFTP */
|
||||||
|
if (sftp_init(client_data->sftp_session) != SSH_OK) {
|
||||||
|
guac_protocol_send_error(socket, "Unable to initialize SFTP session.",
|
||||||
|
GUAC_PROTOCOL_STATUS_INTERNAL_ERROR);
|
||||||
|
guac_socket_flush(socket);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
guac_client_log_info(client, "SFTP session initialized");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Request PTY */
|
/* Request PTY */
|
||||||
if (channel_request_pty_size(client_data->term_channel, "linux",
|
if (channel_request_pty_size(client_data->term_channel, "linux",
|
||||||
client_data->term->term_width, client_data->term->term_height) != SSH_OK) {
|
client_data->term->term_width, client_data->term->term_height) != SSH_OK) {
|
||||||
|
Loading…
Reference in New Issue
Block a user