2014-03-02 17:56:47 +00:00
|
|
|
/*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
2014-03-02 17:56:47 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-03-02 17:56:47 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-03-02 17:56:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2014-03-02 18:38:31 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "guac_list.h"
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "rdp.h"
|
2014-03-02 17:56:47 +00:00
|
|
|
#include "rdp_svc.h"
|
|
|
|
|
2014-03-02 20:38:28 +00:00
|
|
|
#include <freerdp/utils/svc_plugin.h>
|
2014-03-02 17:56:47 +00:00
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
|
|
|
#ifdef ENABLE_WINPR
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
#else
|
|
|
|
#include "compat/winpr-stream.h"
|
|
|
|
#endif
|
|
|
|
|
2014-06-11 01:45:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-03-02 17:56:47 +00:00
|
|
|
guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name) {
|
2014-03-02 18:09:32 +00:00
|
|
|
|
|
|
|
guac_rdp_svc* svc = malloc(sizeof(guac_rdp_svc));
|
|
|
|
|
2014-03-02 18:38:31 +00:00
|
|
|
/* Init SVC */
|
2014-03-02 18:09:32 +00:00
|
|
|
svc->client = client;
|
2014-03-02 20:38:28 +00:00
|
|
|
svc->plugin = NULL;
|
2014-03-02 18:09:32 +00:00
|
|
|
svc->output_pipe = NULL;
|
|
|
|
|
2014-03-06 19:48:52 +00:00
|
|
|
/* Warn about name length */
|
|
|
|
if (strnlen(name, GUAC_RDP_SVC_MAX_LENGTH+1) > GUAC_RDP_SVC_MAX_LENGTH)
|
2014-11-08 00:32:19 +00:00
|
|
|
guac_client_log(client, GUAC_LOG_INFO,
|
2014-03-06 19:48:52 +00:00
|
|
|
"Static channel name \"%s\" exceeds maximum of %i characters "
|
|
|
|
"and will be truncated",
|
|
|
|
name, GUAC_RDP_SVC_MAX_LENGTH);
|
|
|
|
|
|
|
|
/* Init name */
|
|
|
|
strncpy(svc->name, name, GUAC_RDP_SVC_MAX_LENGTH);
|
|
|
|
svc->name[GUAC_RDP_SVC_MAX_LENGTH] = '\0';
|
|
|
|
|
2014-03-02 18:09:32 +00:00
|
|
|
return svc;
|
2014-03-02 17:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_free_svc(guac_rdp_svc* svc) {
|
2014-03-02 18:09:32 +00:00
|
|
|
free(svc);
|
2014-03-02 17:56:47 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:09:42 +00:00
|
|
|
void guac_rdp_svc_send_pipe(guac_socket* socket, guac_rdp_svc* svc) {
|
|
|
|
|
|
|
|
/* Send pipe instruction for the SVC's output stream */
|
|
|
|
guac_protocol_send_pipe(socket, svc->output_pipe,
|
|
|
|
"application/octet-stream", svc->name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdp_svc_send_pipes(guac_user* user) {
|
|
|
|
|
|
|
|
guac_client* client = user->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
|
|
|
|
|
|
|
guac_common_list_lock(rdp_client->available_svc);
|
|
|
|
|
|
|
|
/* Send pipe for each allocated SVC's output stream */
|
|
|
|
guac_common_list_element* current = rdp_client->available_svc->head;
|
|
|
|
while (current != NULL) {
|
|
|
|
guac_rdp_svc_send_pipe(user->socket, (guac_rdp_svc*) current->data);
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
guac_common_list_unlock(rdp_client->available_svc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-02 17:56:47 +00:00
|
|
|
void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc) {
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2014-03-02 18:38:31 +00:00
|
|
|
|
|
|
|
/* Add to list of available SVC */
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_list_lock(rdp_client->available_svc);
|
|
|
|
guac_common_list_add(rdp_client->available_svc, svc);
|
|
|
|
guac_common_list_unlock(rdp_client->available_svc);
|
2014-03-02 18:38:31 +00:00
|
|
|
|
2014-03-02 17:56:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-02 18:46:38 +00:00
|
|
|
guac_rdp_svc* guac_rdp_get_svc(guac_client* client, const char* name) {
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2014-03-02 18:46:38 +00:00
|
|
|
guac_common_list_element* current;
|
|
|
|
guac_rdp_svc* found = NULL;
|
|
|
|
|
|
|
|
/* For each available SVC */
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_list_lock(rdp_client->available_svc);
|
|
|
|
current = rdp_client->available_svc->head;
|
2014-03-02 18:46:38 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
|
|
|
|
/* If name matches, found */
|
|
|
|
guac_rdp_svc* current_svc = (guac_rdp_svc*) current->data;
|
|
|
|
if (strcmp(current_svc->name, name) == 0) {
|
|
|
|
found = current_svc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
|
|
|
|
}
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_list_unlock(rdp_client->available_svc);
|
2014-03-02 18:46:38 +00:00
|
|
|
|
|
|
|
return found;
|
|
|
|
|
2014-03-02 17:56:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-02 19:24:06 +00:00
|
|
|
guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, const char* name) {
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2014-03-02 19:24:06 +00:00
|
|
|
guac_common_list_element* current;
|
|
|
|
guac_rdp_svc* found = NULL;
|
|
|
|
|
|
|
|
/* For each available SVC */
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_list_lock(rdp_client->available_svc);
|
|
|
|
current = rdp_client->available_svc->head;
|
2014-03-02 19:24:06 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
|
|
|
|
/* If name matches, remove entry */
|
|
|
|
guac_rdp_svc* current_svc = (guac_rdp_svc*) current->data;
|
|
|
|
if (strcmp(current_svc->name, name) == 0) {
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_list_remove(rdp_client->available_svc, current);
|
2014-03-02 19:24:06 +00:00
|
|
|
found = current_svc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
|
|
|
|
}
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_common_list_unlock(rdp_client->available_svc);
|
2014-03-02 19:24:06 +00:00
|
|
|
|
|
|
|
/* Return removed entry, if any */
|
|
|
|
return found;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-02 20:38:28 +00:00
|
|
|
void guac_rdp_svc_write(guac_rdp_svc* svc, void* data, int length) {
|
|
|
|
|
|
|
|
wStream* output_stream;
|
|
|
|
|
|
|
|
/* Do not write of plugin not associated */
|
|
|
|
if (svc->plugin == NULL) {
|
2014-11-08 00:32:19 +00:00
|
|
|
guac_client_log(svc->client, GUAC_LOG_ERROR,
|
2014-03-02 20:38:28 +00:00
|
|
|
"Channel \"%s\" output dropped.",
|
|
|
|
svc->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build packet */
|
|
|
|
output_stream = Stream_New(NULL, length);
|
|
|
|
Stream_Write(output_stream, data, length);
|
|
|
|
|
|
|
|
/* Send packet */
|
|
|
|
svc_plugin_send(svc->plugin, output_stream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|