2013-12-29 04:53:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Glyptodon LLC
|
2013-07-27 18:11:14 +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:
|
2013-07-27 18:11:14 +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.
|
2013-07-27 18:11:14 +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.
|
|
|
|
*/
|
|
|
|
|
2013-07-27 18:11:14 +00:00
|
|
|
|
2014-01-01 22:44:28 +00:00
|
|
|
#include "config.h"
|
2013-07-27 18:11:14 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
#include "rdp.h"
|
2013-07-27 18:11:14 +00:00
|
|
|
#include "rdpdr_fs_messages.h"
|
|
|
|
#include "rdpdr_messages.h"
|
|
|
|
#include "rdpdr_service.h"
|
|
|
|
|
|
|
|
#include <freerdp/utils/svc_plugin.h>
|
2014-06-11 01:45:14 +00:00
|
|
|
#include <guacamole/client.h>
|
2015-07-06 01:14:10 +00:00
|
|
|
#include <guacamole/protocol.h>
|
|
|
|
#include <guacamole/socket.h>
|
2014-01-01 22:44:28 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_WINPR
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
#else
|
|
|
|
#include "compat/winpr-stream.h"
|
|
|
|
#endif
|
2013-07-27 18:11:14 +00:00
|
|
|
|
|
|
|
static void guac_rdpdr_device_fs_announce_handler(guac_rdpdr_device* device,
|
|
|
|
wStream* output_stream, int device_id) {
|
|
|
|
|
|
|
|
/* Filesystem header */
|
2014-11-08 00:32:19 +00:00
|
|
|
guac_client_log(device->rdpdr->client, GUAC_LOG_INFO, "Sending filesystem");
|
2013-07-27 18:11:14 +00:00
|
|
|
Stream_Write_UINT32(output_stream, RDPDR_DTYP_FILESYSTEM);
|
|
|
|
Stream_Write_UINT32(output_stream, device_id);
|
|
|
|
Stream_Write(output_stream, "GUAC\0\0\0\0", 8); /* DOS name */
|
|
|
|
|
|
|
|
/* Filesystem data */
|
|
|
|
Stream_Write_UINT32(output_stream, GUAC_FILESYSTEM_NAME_LENGTH);
|
|
|
|
Stream_Write(output_stream, GUAC_FILESYSTEM_NAME, GUAC_FILESYSTEM_NAME_LENGTH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void guac_rdpdr_device_fs_iorequest_handler(guac_rdpdr_device* device,
|
|
|
|
wStream* input_stream, int file_id, int completion_id, int major_func, int minor_func) {
|
|
|
|
|
|
|
|
switch (major_func) {
|
|
|
|
|
|
|
|
/* File open */
|
|
|
|
case IRP_MJ_CREATE:
|
|
|
|
guac_rdpdr_fs_process_create(device, input_stream, completion_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* File close */
|
|
|
|
case IRP_MJ_CLOSE:
|
|
|
|
guac_rdpdr_fs_process_close(device, input_stream, file_id, completion_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* File read */
|
|
|
|
case IRP_MJ_READ:
|
|
|
|
guac_rdpdr_fs_process_read(device, input_stream, file_id, completion_id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* File write */
|
|
|
|
case IRP_MJ_WRITE:
|
|
|
|
guac_rdpdr_fs_process_write(device, input_stream, file_id, completion_id);
|
|
|
|
break;
|
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Device control request (Windows FSCTL_ control codes) */
|
2013-07-27 18:11:14 +00:00
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
2013-07-30 22:25:10 +00:00
|
|
|
guac_rdpdr_fs_process_device_control(device, input_stream, file_id, completion_id);
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Query volume (drive) information */
|
2013-07-27 18:11:14 +00:00
|
|
|
case IRP_MJ_QUERY_VOLUME_INFORMATION:
|
2013-08-01 23:42:38 +00:00
|
|
|
guac_rdpdr_fs_process_volume_info(device, input_stream, file_id, completion_id);
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Set volume (drive) information */
|
2013-07-27 18:11:14 +00:00
|
|
|
case IRP_MJ_SET_VOLUME_INFORMATION:
|
2013-07-30 22:31:42 +00:00
|
|
|
guac_rdpdr_fs_process_set_volume_info(device, input_stream, file_id, completion_id);
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Query file information */
|
2013-07-27 18:11:14 +00:00
|
|
|
case IRP_MJ_QUERY_INFORMATION:
|
2013-07-30 22:31:42 +00:00
|
|
|
guac_rdpdr_fs_process_file_info(device, input_stream, file_id, completion_id);
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Set file information */
|
2013-07-27 18:11:14 +00:00
|
|
|
case IRP_MJ_SET_INFORMATION:
|
2013-07-30 22:31:42 +00:00
|
|
|
guac_rdpdr_fs_process_set_file_info(device, input_stream, file_id, completion_id);
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_DIRECTORY_CONTROL:
|
2013-07-29 19:47:30 +00:00
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Enumerate directory contents */
|
2013-07-29 19:47:30 +00:00
|
|
|
if (minor_func == IRP_MN_QUERY_DIRECTORY)
|
2013-07-30 22:25:10 +00:00
|
|
|
guac_rdpdr_fs_process_query_directory(device, input_stream, file_id, completion_id);
|
2013-07-29 19:47:30 +00:00
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Request notification of changes to directory */
|
2013-07-29 19:47:30 +00:00
|
|
|
else if (minor_func == IRP_MN_NOTIFY_CHANGE_DIRECTORY)
|
2013-07-30 22:25:10 +00:00
|
|
|
guac_rdpdr_fs_process_notify_change_directory(device, input_stream,
|
|
|
|
file_id, completion_id);
|
2013-07-29 19:47:30 +00:00
|
|
|
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-30 22:25:10 +00:00
|
|
|
/* Lock/unlock portions of a file */
|
2013-07-27 18:11:14 +00:00
|
|
|
case IRP_MJ_LOCK_CONTROL:
|
2013-07-30 22:25:10 +00:00
|
|
|
guac_rdpdr_fs_process_lock_control(device, input_stream, file_id, completion_id);
|
2013-07-27 18:11:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-11-08 00:32:19 +00:00
|
|
|
guac_client_log(device->rdpdr->client, GUAC_LOG_ERROR,
|
2013-07-27 18:11:14 +00:00
|
|
|
"Unknown filesystem I/O request function: 0x%x/0x%x",
|
|
|
|
major_func, minor_func);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void guac_rdpdr_device_fs_free_handler(guac_rdpdr_device* device) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void guac_rdpdr_register_fs(guac_rdpdrPlugin* rdpdr) {
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
guac_client* client = rdpdr->client;
|
|
|
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
2013-07-27 18:11:14 +00:00
|
|
|
int id = rdpdr->devices_registered++;
|
|
|
|
|
|
|
|
/* Get new device */
|
|
|
|
guac_rdpdr_device* device = &(rdpdr->devices[id]);
|
|
|
|
|
|
|
|
/* Init device */
|
|
|
|
device->rdpdr = rdpdr;
|
|
|
|
device->device_id = id;
|
|
|
|
device->device_name = "Guacamole Filesystem";
|
|
|
|
|
|
|
|
/* Set handlers */
|
|
|
|
device->announce_handler = guac_rdpdr_device_fs_announce_handler;
|
|
|
|
device->iorequest_handler = guac_rdpdr_device_fs_iorequest_handler;
|
|
|
|
device->free_handler = guac_rdpdr_device_fs_free_handler;
|
|
|
|
|
|
|
|
/* Init data */
|
2016-03-01 05:50:00 +00:00
|
|
|
device->data = rdp_client->filesystem;
|
2013-07-27 18:11:14 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Announce filesystem to owner */
|
|
|
|
guac_client_for_owner(client, guac_rdp_fs_expose, rdp_client->filesystem);
|
2015-07-06 01:14:10 +00:00
|
|
|
|
2013-07-27 18:11:14 +00:00
|
|
|
}
|
|
|
|
|