GUAC-1038: Add support for running specific commands via SSH (instead of a shell).

This commit is contained in:
Michael Jumper 2015-10-19 15:58:44 -07:00
parent 8a91965b07
commit e8b98abfc4
4 changed files with 33 additions and 3 deletions

View File

@ -57,6 +57,7 @@ const char* GUAC_CLIENT_ARGS[] = {
"enable-agent", "enable-agent",
#endif #endif
"color-scheme", "color-scheme",
"command",
NULL NULL
}; };
@ -122,6 +123,12 @@ enum __SSH_ARGS_IDX {
*/ */
IDX_COLOR_SCHEME, IDX_COLOR_SCHEME,
/**
* The command to run instead if the default shell. If omitted, a normal
* shell session will be created.
*/
IDX_COMMAND,
SSH_ARGS_COUNT SSH_ARGS_COUNT
}; };
@ -178,6 +185,10 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
else else
strcpy(client_data->port, GUAC_SSH_DEFAULT_PORT); strcpy(client_data->port, GUAC_SSH_DEFAULT_PORT);
/* Read command, if any */
if (argv[IDX_COMMAND][0] != 0)
client_data->command = strdup(argv[IDX_COMMAND]);
/* Create terminal */ /* Create terminal */
client_data->term = guac_terminal_create(client, client_data->term = guac_terminal_create(client,
client_data->font_name, client_data->font_size, client_data->font_name, client_data->font_size,

View File

@ -78,6 +78,12 @@ typedef struct ssh_guac_client_data {
*/ */
char key_passphrase[1024]; char key_passphrase[1024];
/**
* The command to run instead of the default shell. If a normal shell
* session is desired, this will be NULL.
*/
char* command;
/** /**
* The name of the font to use for display rendering. * The name of the font to use for display rendering.
*/ */

View File

@ -116,6 +116,9 @@ int ssh_guac_client_free_handler(guac_client* client) {
if (guac_client_data->user != NULL) if (guac_client_data->user != NULL)
guac_common_ssh_destroy_user(guac_client_data->user); guac_common_ssh_destroy_user(guac_client_data->user);
/* Free copied settings */
free(guac_client_data->command);
/* Free generic data struct */ /* Free generic data struct */
free(client->data); free(client->data);

View File

@ -264,9 +264,19 @@ void* ssh_client_thread(void* data) {
return NULL; return NULL;
} }
/* Request shell */ /* If a command is specified, run that instead of a shell */
if (libssh2_channel_shell(client_data->term_channel)) { if (client_data->command != NULL) {
guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR, "Unable to associate shell with PTY."); if (libssh2_channel_exec(client_data->term_channel, client_data->command)) {
guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR,
"Unable to execute command.");
return NULL;
}
}
/* Otherwise, request a shell */
else if (libssh2_channel_shell(client_data->term_channel)) {
guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_ERROR,
"Unable to associate shell with PTY.");
return NULL; return NULL;
} }