2013-12-29 04:53:12 +00:00
|
|
|
/*
|
2015-11-02 23:55:52 +00:00
|
|
|
* Copyright (C) 2015 Glyptodon LLC
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2011-12-30 08:10:28 +00:00
|
|
|
*
|
2013-12-29 04:53:12 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "client.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "rdp.h"
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "rdp_keymap.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "user.h"
|
2014-01-01 22:44:28 +00:00
|
|
|
|
2015-07-11 05:12:30 +00:00
|
|
|
#ifdef ENABLE_COMMON_SSH
|
2016-03-01 05:50:00 +00:00
|
|
|
#include <guac_sftp.h>
|
|
|
|
#include <guac_ssh.h>
|
|
|
|
#include <guac_ssh_user.h>
|
2015-07-11 05:12:30 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-21 21:30:24 +00:00
|
|
|
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
|
|
|
|
#include "rdp_disp.h"
|
|
|
|
#endif
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
#include <freerdp/cache/cache.h>
|
2013-07-19 04:52:40 +00:00
|
|
|
#include <freerdp/channels/channels.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <guacamole/client.h>
|
|
|
|
#include <guacamole/socket.h>
|
2013-07-18 16:34:02 +00:00
|
|
|
|
2014-03-31 22:46:49 +00:00
|
|
|
#ifdef HAVE_FREERDP_CLIENT_CLIPRDR_H
|
|
|
|
#include <freerdp/client/cliprdr.h>
|
|
|
|
#else
|
|
|
|
#include "compat/client-cliprdr.h"
|
|
|
|
#endif
|
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#ifdef HAVE_FREERDP_CLIENT_CHANNELS_H
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
#endif
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2014-06-11 01:45:14 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-03-21 17:45:40 +00:00
|
|
|
|
2011-12-30 08:10:28 +00:00
|
|
|
int guac_client_init(guac_client* client, int argc, char** argv) {
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Set client args */
|
|
|
|
client->args = GUAC_RDP_CLIENT_ARGS;
|
2012-12-26 03:36:19 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Alloc client data */
|
|
|
|
guac_rdp_client* rdp_client = calloc(1, sizeof(guac_rdp_client));
|
|
|
|
client->data = rdp_client;
|
2013-08-24 08:17:27 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Init clipboard and shared mouse */
|
|
|
|
rdp_client->clipboard = guac_common_clipboard_alloc(GUAC_RDP_CLIPBOARD_MAX_LENGTH);
|
|
|
|
rdp_client->requested_clipboard_format = CB_FORMAT_TEXT;
|
|
|
|
rdp_client->available_svc = guac_common_list_alloc();
|
2013-08-24 19:37:43 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Recursive attribute for locks */
|
|
|
|
pthread_mutexattr_init(&(rdp_client->attributes));
|
|
|
|
pthread_mutexattr_settype(&(rdp_client->attributes),
|
|
|
|
PTHREAD_MUTEX_RECURSIVE);
|
2013-08-24 19:37:43 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Init RDP lock */
|
|
|
|
pthread_mutex_init(&(rdp_client->rdp_lock), &(rdp_client->attributes));
|
2013-08-24 19:37:43 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Clear keysym state mapping and keymap */
|
|
|
|
memset(rdp_client->keysym_state, 0, sizeof(guac_rdp_keysym_state_map));
|
|
|
|
memset(rdp_client->keymap, 0, sizeof(guac_rdp_static_keymap));
|
2013-08-24 19:30:38 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Set handlers */
|
|
|
|
client->join_handler = guac_rdp_user_join_handler;
|
|
|
|
client->free_handler = guac_rdp_client_free_handler;
|
2013-08-27 04:26:38 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
return 0;
|
2012-02-27 18:36:14 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
}
|
2013-01-23 09:34:51 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
int guac_rdp_client_free_handler(guac_client* client) {
|
2014-11-26 23:23:26 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2012-10-02 21:09:57 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
|
|
|
if (rdp_inst != NULL) {
|
|
|
|
rdpChannels* channels = rdp_inst->context->channels;
|
2011-12-30 08:10:28 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Clean up RDP client */
|
|
|
|
freerdp_channels_close(channels, rdp_inst);
|
|
|
|
freerdp_channels_free(channels);
|
|
|
|
freerdp_disconnect(rdp_inst);
|
|
|
|
freerdp_clrconv_free(((rdp_freerdp_context*) rdp_inst->context)->clrconv);
|
|
|
|
cache_free(rdp_inst->context->cache);
|
|
|
|
freerdp_free(rdp_inst);
|
2012-10-02 21:09:57 +00:00
|
|
|
}
|
2012-08-31 11:07:05 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Clean up filesystem, if allocated */
|
|
|
|
if (rdp_client->filesystem != NULL)
|
|
|
|
guac_rdp_fs_free(rdp_client->filesystem);
|
2015-11-03 23:41:28 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
#ifdef ENABLE_COMMON_SSH
|
|
|
|
/* Free SFTP filesystem, if loaded */
|
|
|
|
if (rdp_client->sftp_filesystem)
|
|
|
|
guac_common_ssh_destroy_sftp_filesystem(rdp_client->sftp_filesystem);
|
2015-11-03 23:41:28 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free SFTP session */
|
|
|
|
if (rdp_client->sftp_session)
|
|
|
|
guac_common_ssh_destroy_session(rdp_client->sftp_session);
|
2015-11-03 21:29:41 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free SFTP user */
|
|
|
|
if (rdp_client->sftp_user)
|
|
|
|
guac_common_ssh_destroy_user(rdp_client->sftp_user);
|
2015-11-03 21:29:41 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_ssh_uninit();
|
2015-11-03 21:29:41 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
#ifdef HAVE_FREERDP_DISPLAY_UPDATE_SUPPORT
|
|
|
|
/* Free display update module */
|
|
|
|
guac_rdp_disp_free(rdp_client->disp);
|
2015-07-11 04:55:28 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free SVC list */
|
|
|
|
guac_common_list_free(rdp_client->available_svc);
|
2014-07-21 16:12:17 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free parsed settings */
|
|
|
|
if (rdp_client->settings != NULL)
|
|
|
|
guac_rdp_settings_free(rdp_client->settings);
|
2014-07-21 16:12:17 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Free client data */
|
|
|
|
guac_common_clipboard_free(rdp_client->clipboard);
|
|
|
|
guac_common_display_free(rdp_client->display);
|
|
|
|
free(rdp_client);
|
2011-12-30 08:10:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|