2011-07-30 22:12:28 +00:00
|
|
|
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is libguac-client-ssh.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Michael Jumper.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2011-12-30 22:34:04 +00:00
|
|
|
* James Muehlner <dagger10k@users.sourceforge.net>
|
2011-07-30 22:12:28 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-05-18 03:20:51 +00:00
|
|
|
#include <unistd.h>
|
2013-05-18 03:47:05 +00:00
|
|
|
#include <pthread.h>
|
2011-08-01 20:31:48 +00:00
|
|
|
|
2011-11-26 23:35:45 +00:00
|
|
|
#include <guacamole/socket.h>
|
2011-07-30 22:12:28 +00:00
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/client.h>
|
2013-05-18 03:20:51 +00:00
|
|
|
#include <guacamole/error.h>
|
2011-07-30 22:12:28 +00:00
|
|
|
|
2013-05-18 03:28:26 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "guac_handlers.h"
|
2012-12-09 08:35:37 +00:00
|
|
|
#include "terminal.h"
|
2013-04-09 21:02:52 +00:00
|
|
|
#include "blank.h"
|
2013-03-29 10:14:08 +00:00
|
|
|
#include "ibar.h"
|
2013-05-18 03:47:05 +00:00
|
|
|
#include "ssh_client.h"
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-05-26 06:50:13 +00:00
|
|
|
#define GUAC_SSH_DEFAULT_FONT_NAME "monospace"
|
|
|
|
#define GUAC_SSH_DEFAULT_FONT_SIZE 12
|
|
|
|
#define GUAC_SSH_DEFAULT_PORT 22
|
|
|
|
|
2011-08-01 03:51:19 +00:00
|
|
|
/* Client plugin arguments */
|
|
|
|
const char* GUAC_CLIENT_ARGS[] = {
|
|
|
|
"hostname",
|
2013-05-26 06:15:55 +00:00
|
|
|
"port",
|
2013-05-10 04:43:46 +00:00
|
|
|
"username",
|
2011-08-01 20:31:48 +00:00
|
|
|
"password",
|
2013-05-26 06:50:13 +00:00
|
|
|
"font-name",
|
|
|
|
"font-size",
|
2013-10-18 22:37:16 +00:00
|
|
|
"enable-sftp",
|
2013-10-30 22:46:13 +00:00
|
|
|
"private-key",
|
|
|
|
"passphrase",
|
2011-08-01 03:51:19 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-05-26 06:15:55 +00:00
|
|
|
enum __SSH_ARGS_IDX {
|
2013-05-26 06:50:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The hostname to connect to. Required.
|
|
|
|
*/
|
2013-05-26 06:15:55 +00:00
|
|
|
IDX_HOSTNAME,
|
2013-05-26 06:50:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The port to connect to. Optional.
|
|
|
|
*/
|
2013-05-26 06:15:55 +00:00
|
|
|
IDX_PORT,
|
2013-05-26 06:50:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the user to login as. Optional.
|
|
|
|
*/
|
2013-05-26 06:15:55 +00:00
|
|
|
IDX_USERNAME,
|
2013-05-26 06:50:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The password to use when logging in. Optional.
|
|
|
|
*/
|
2013-05-26 06:15:55 +00:00
|
|
|
IDX_PASSWORD,
|
2013-05-26 06:50:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the font to use within the terminal.
|
|
|
|
*/
|
|
|
|
IDX_FONT_NAME,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The size of the font to use within the terminal, in points.
|
|
|
|
*/
|
|
|
|
IDX_FONT_SIZE,
|
|
|
|
|
2013-10-18 22:37:16 +00:00
|
|
|
/**
|
|
|
|
* Whether SFTP should be enabled.
|
|
|
|
*/
|
|
|
|
IDX_ENABLE_SFTP,
|
|
|
|
|
2013-10-30 22:46:13 +00:00
|
|
|
/**
|
|
|
|
* The private key to use for authentication, if any.
|
|
|
|
*/
|
|
|
|
IDX_PRIVATE_KEY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The passphrase required to decrypt the private key, if any.
|
|
|
|
*/
|
|
|
|
IDX_PASSPHRASE,
|
|
|
|
|
2013-05-26 06:15:55 +00:00
|
|
|
SSH_ARGS_COUNT
|
|
|
|
};
|
|
|
|
|
2011-07-30 22:12:28 +00:00
|
|
|
int guac_client_init(guac_client* client, int argc, char** argv) {
|
|
|
|
|
2011-11-26 23:35:45 +00:00
|
|
|
guac_socket* socket = client->socket;
|
2011-08-01 03:51:19 +00:00
|
|
|
|
|
|
|
ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data));
|
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
/* Init client data */
|
2011-08-01 03:51:19 +00:00
|
|
|
client->data = client_data;
|
2013-05-26 07:17:31 +00:00
|
|
|
client_data->mod_alt =
|
|
|
|
client_data->mod_ctrl =
|
|
|
|
client_data->mod_shift = 0;
|
2011-12-30 22:34:04 +00:00
|
|
|
client_data->clipboard_data = NULL;
|
2013-05-20 17:27:53 +00:00
|
|
|
client_data->term_channel = NULL;
|
2011-08-01 03:51:19 +00:00
|
|
|
|
2013-05-26 06:15:55 +00:00
|
|
|
if (argc != SSH_ARGS_COUNT) {
|
2013-05-20 08:23:21 +00:00
|
|
|
guac_client_log_error(client, "Wrong number of arguments");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read parameters */
|
2013-05-26 06:50:13 +00:00
|
|
|
strcpy(client_data->hostname, argv[IDX_HOSTNAME]);
|
|
|
|
strcpy(client_data->username, argv[IDX_USERNAME]);
|
|
|
|
strcpy(client_data->password, argv[IDX_PASSWORD]);
|
|
|
|
|
2013-10-31 06:19:11 +00:00
|
|
|
/* Init public key auth information */
|
2013-10-30 22:46:13 +00:00
|
|
|
client_data->key = NULL;
|
2013-10-31 06:19:11 +00:00
|
|
|
strcpy(client_data->key_base64, argv[IDX_PRIVATE_KEY]);
|
|
|
|
strcpy(client_data->key_passphrase, argv[IDX_PASSPHRASE]);
|
2013-10-30 22:46:13 +00:00
|
|
|
|
2013-05-26 06:50:13 +00:00
|
|
|
/* Read font name */
|
|
|
|
if (argv[IDX_FONT_NAME][0] != 0)
|
|
|
|
strcpy(client_data->font_name, argv[IDX_FONT_NAME]);
|
|
|
|
else
|
|
|
|
strcpy(client_data->font_name, GUAC_SSH_DEFAULT_FONT_NAME );
|
|
|
|
|
|
|
|
/* Read font size */
|
|
|
|
if (argv[IDX_FONT_SIZE][0] != 0)
|
|
|
|
client_data->font_size = atoi(argv[IDX_FONT_SIZE]);
|
|
|
|
else
|
|
|
|
client_data->font_size = GUAC_SSH_DEFAULT_FONT_SIZE;
|
|
|
|
|
2013-10-18 22:37:16 +00:00
|
|
|
/* Parse SFTP enable */
|
|
|
|
client_data->enable_sftp = strcmp(argv[IDX_ENABLE_SFTP], "true") == 0;
|
|
|
|
client_data->sftp_session = NULL;
|
2013-10-19 05:05:03 +00:00
|
|
|
client_data->sftp_ssh_session = NULL;
|
2013-10-28 21:11:04 +00:00
|
|
|
strcpy(client_data->sftp_upload_path, ".");
|
2013-10-18 22:37:16 +00:00
|
|
|
|
2013-05-26 06:50:13 +00:00
|
|
|
/* Read port */
|
|
|
|
if (argv[IDX_PORT][0] != 0)
|
|
|
|
client_data->port = atoi(argv[IDX_PORT]);
|
|
|
|
else
|
|
|
|
client_data->port = GUAC_SSH_DEFAULT_PORT;
|
|
|
|
|
|
|
|
/* Create terminal */
|
|
|
|
client_data->term = guac_terminal_create(client,
|
|
|
|
client_data->font_name, client_data->font_size,
|
|
|
|
client->info.optimal_width, client->info.optimal_height);
|
2013-05-20 08:23:21 +00:00
|
|
|
|
2013-08-23 21:10:51 +00:00
|
|
|
/* Fail if terminal init failed */
|
|
|
|
if (client_data->term == NULL) {
|
|
|
|
guac_error = GUAC_STATUS_BAD_STATE;
|
|
|
|
guac_error_message = "Terminal initialization failed";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-09 21:02:52 +00:00
|
|
|
/* Set up I-bar pointer */
|
2013-04-09 21:09:41 +00:00
|
|
|
client_data->ibar_cursor = guac_ssh_create_ibar(client);
|
2013-04-09 20:54:23 +00:00
|
|
|
|
2013-04-09 21:02:52 +00:00
|
|
|
/* Set up blank pointer */
|
|
|
|
client_data->blank_cursor = guac_ssh_create_blank(client);
|
|
|
|
|
2013-05-26 06:15:55 +00:00
|
|
|
/* Send initial name */
|
|
|
|
guac_protocol_send_name(socket, client_data->hostname);
|
2011-08-01 03:51:19 +00:00
|
|
|
|
2013-04-09 21:09:41 +00:00
|
|
|
/* Initialize pointer */
|
|
|
|
client_data->current_cursor = client_data->blank_cursor;
|
|
|
|
guac_ssh_set_cursor(client, client_data->current_cursor);
|
2013-03-29 10:14:08 +00:00
|
|
|
|
2011-11-26 23:35:45 +00:00
|
|
|
guac_socket_flush(socket);
|
2011-08-01 03:51:19 +00:00
|
|
|
|
2013-05-18 03:20:51 +00:00
|
|
|
/* Set basic handlers */
|
|
|
|
client->handle_messages = ssh_guac_client_handle_messages;
|
2011-12-30 22:34:04 +00:00
|
|
|
client->clipboard_handler = ssh_guac_client_clipboard_handler;
|
2013-05-18 03:20:51 +00:00
|
|
|
client->key_handler = ssh_guac_client_key_handler;
|
|
|
|
client->mouse_handler = ssh_guac_client_mouse_handler;
|
|
|
|
client->size_handler = ssh_guac_client_size_handler;
|
|
|
|
client->free_handler = ssh_guac_client_free_handler;
|
2011-08-01 03:51:19 +00:00
|
|
|
|
2013-05-18 03:58:47 +00:00
|
|
|
/* Start client thread */
|
|
|
|
if (pthread_create(&(client_data->client_thread), NULL, ssh_client_thread, (void*) client)) {
|
|
|
|
guac_client_log_error(client, "Unable to SSH client thread");
|
2013-05-18 03:47:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-30 22:12:28 +00:00
|
|
|
/* Success */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|