GUAC-911: Replace old GUAC_RDP_DEBUG with calls to guac_client_log().

This commit is contained in:
Michael Jumper 2014-11-12 13:35:25 -08:00
parent c0eb7df97a
commit f18d9ae831
10 changed files with 154 additions and 129 deletions

View File

@ -80,7 +80,6 @@ noinst_HEADERS = \
guac_rdpsnd/rdpsnd_service.h \
guac_svc/svc_service.h \
client.h \
debug.h \
guac_handlers.h \
rdp_bitmap.h \
rdp_cliprdr.h \

View File

@ -189,7 +189,7 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) {
/* Load filesystem if drive enabled */
if (guac_client_data->settings.drive_enabled) {
guac_client_data->filesystem =
guac_rdp_fs_alloc(guac_client_data->settings.drive_path);
guac_rdp_fs_alloc(client, guac_client_data->settings.drive_path);
}
/* If RDPDR required, load it */

View File

@ -1,54 +0,0 @@
/*
* Copyright (C) 2013 Glyptodon LLC
*
* 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:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 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.
*/
#ifndef __GUAC_RDP_DEBUG_H
#define __GUAC_RDP_DEBUG_H
#include "config.h"
#include <stdio.h>
/* Ensure GUAC_RDP_DEBUG_LEVEL is defined to a constant */
#ifndef GUAC_RDP_DEBUG_LEVEL
#define GUAC_RDP_DEBUG_LEVEL 0
#endif
/**
* Prints a message to STDERR using the given printf format string and
* arguments. This will only do anything if the GUAC_RDP_DEBUG_LEVEL
* macro is defined and greater than the given log level.
*
* @param level The desired log level (an integer).
* @param fmt The format to use when printing.
* @param ... Arguments corresponding to conversion specifiers in the format
* string.
*/
#define GUAC_RDP_DEBUG(level, fmt, ...) \
do { \
if (GUAC_RDP_DEBUG_LEVEL >= level) \
fprintf(stderr, "%s:%d: %s(): " fmt "\n", \
__FILE__, __LINE__, __func__, __VA_ARGS__); \
} while (0);
#endif

View File

@ -22,7 +22,6 @@
#include "config.h"
#include "debug.h"
#include "rdpdr_fs_messages_dir_info.h"
#include "rdpdr_fs_messages_file_info.h"
#include "rdpdr_fs_messages.h"
@ -77,11 +76,13 @@ void guac_rdpdr_fs_process_create(guac_rdpdr_device* device,
desired_access, file_attributes,
create_disposition, create_options);
GUAC_RDP_DEBUG(2, "[file_id=%i] "
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] "
"desired_access=0x%x, file_attributes=0x%x, "
"create_disposition=0x%x, create_options=0x%x, path=\"%s\"",
file_id, desired_access, file_attributes, create_disposition,
create_options, path);
__func__, file_id,
desired_access, file_attributes,
create_disposition, create_options, path);
/* If an error occurred, notify server */
if (file_id < 0) {
@ -136,8 +137,9 @@ void guac_rdpdr_fs_process_read(guac_rdpdr_device* device,
Stream_Read_UINT32(input_stream, length);
Stream_Read_UINT64(input_stream, offset);
GUAC_RDP_DEBUG(2, "[file_id=%i] length=%i, offset=%" PRIu64,
file_id, length, (uint64_t) offset);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] length=%i, offset=%" PRIu64,
__func__, file_id, length, (uint64_t) offset);
/* Ensure buffer size does not exceed a safe maximum */
if (length > GUAC_RDP_MAX_READ_BUFFER)
@ -184,8 +186,9 @@ void guac_rdpdr_fs_process_write(guac_rdpdr_device* device,
Stream_Read_UINT64(input_stream, offset);
Stream_Seek(input_stream, 20); /* Padding */
GUAC_RDP_DEBUG(2, "[file_id=%i] length=%i, offset=%" PRIu64,
file_id, length, (uint64_t) offset);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] length=%i, offset=%" PRIu64,
__func__, file_id, length, (uint64_t) offset);
/* Attempt write */
bytes_written = guac_rdp_fs_write((guac_rdp_fs*) device->data, file_id,
@ -217,7 +220,9 @@ void guac_rdpdr_fs_process_close(guac_rdpdr_device* device,
wStream* output_stream;
guac_rdp_fs_file* file;
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
/* Get file */
file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, file_id);
@ -322,7 +327,9 @@ void guac_rdpdr_fs_process_set_volume_info(guac_rdpdr_device* device,
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_NOT_SUPPORTED, 0);
GUAC_RDP_DEBUG(2, "[file_id=%i] Set volume info not supported", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] Set volume info not supported",
__func__, file_id);
svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream);
@ -380,7 +387,9 @@ void guac_rdpdr_fs_process_device_control(guac_rdpdr_device* device,
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_INVALID_PARAMETER, 4);
GUAC_RDP_DEBUG(2, "[file_id=%i] IGNORED", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] IGNORED",
__func__, file_id);
/* No content for now */
Stream_Write_UINT32(output_stream, 0);
@ -392,7 +401,9 @@ void guac_rdpdr_fs_process_device_control(guac_rdpdr_device* device,
void guac_rdpdr_fs_process_notify_change_directory(guac_rdpdr_device* device,
wStream* input_stream, int file_id, int completion_id) {
GUAC_RDP_DEBUG(2, "[file_id=%i] Not implemented", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] Not implemented",
__func__, file_id);
}
@ -428,8 +439,9 @@ void guac_rdpdr_fs_process_query_directory(guac_rdpdr_device* device, wStream* i
}
GUAC_RDP_DEBUG(2, "[file_id=%i] initial_query=%i, dir_pattern=\"%s\"",
file_id, initial_query, file->dir_pattern);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] initial_query=%i, dir_pattern=\"%s\"",
__func__, file_id, initial_query, file->dir_pattern);
/* Find first matching entry in directory */
while ((entry_name = guac_rdp_fs_read_dir((guac_rdp_fs*) device->data,
@ -508,7 +520,9 @@ void guac_rdpdr_fs_process_lock_control(guac_rdpdr_device* device, wStream* inpu
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_NOT_SUPPORTED, 5);
GUAC_RDP_DEBUG(2, "[file_id=%i] Lock not supported", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] Lock not supported",
__func__, file_id);
Stream_Zero(output_stream, 5); /* Padding */

View File

@ -22,7 +22,6 @@
#include "config.h"
#include "debug.h"
#include "rdpdr_service.h"
#include "rdp_fs.h"
#include "rdp_status.h"
@ -57,7 +56,9 @@ void guac_rdpdr_fs_process_query_directory_info(guac_rdpdr_device* device,
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i (entry_name=\"%s\")]", file_id, entry_name);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i (entry_name=\"%s\")]",
__func__, file_id, entry_name);
output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 4 + 64 + utf16_length + 2);
@ -101,7 +102,9 @@ void guac_rdpdr_fs_process_query_full_directory_info(guac_rdpdr_device* device,
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i (entry_name=\"%s\")]", file_id, entry_name);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i (entry_name=\"%s\")]",
__func__, file_id, entry_name);
output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 4 + 68 + utf16_length + 2);
@ -146,7 +149,9 @@ void guac_rdpdr_fs_process_query_both_directory_info(guac_rdpdr_device* device,
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i (entry_name=\"%s\")]", file_id, entry_name);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i (entry_name=\"%s\")]",
__func__, file_id, entry_name);
output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 4 + 69 + 24 + utf16_length + 2);
@ -195,7 +200,9 @@ void guac_rdpdr_fs_process_query_names_info(guac_rdpdr_device* device,
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i (entry_name=\"%s\")]", file_id, entry_name);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i (entry_name=\"%s\")]",
__func__, file_id, entry_name);
output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 4 + 12 + utf16_length + 2);

View File

@ -22,7 +22,6 @@
#include "config.h"
#include "debug.h"
#include "rdpdr_service.h"
#include "rdp_fs.h"
#include "rdp_status.h"
@ -53,7 +52,9 @@ void guac_rdpdr_fs_process_query_basic_info(guac_rdpdr_device* device, wStream*
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 40);
@ -83,7 +84,9 @@ void guac_rdpdr_fs_process_query_standard_info(guac_rdpdr_device* device, wStrea
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
if (file->attributes & FILE_ATTRIBUTE_DIRECTORY)
is_directory = TRUE;
@ -115,7 +118,9 @@ void guac_rdpdr_fs_process_query_attribute_tag_info(guac_rdpdr_device* device,
if (file == NULL)
return;
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
output_stream = guac_rdpdr_new_io_completion(device, completion_id,
STATUS_SUCCESS, 12);
@ -147,7 +152,9 @@ void guac_rdpdr_fs_process_set_rename_info(guac_rdpdr_device* device,
guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), filename_length/2,
destination_path, sizeof(destination_path));
GUAC_RDP_DEBUG(2, "[file_id=%i] destination_path=\"%s\"", file_id, destination_path);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] destination_path=\"%s\"",
__func__, file_id, destination_path);
/* If file moving to \Download folder, start stream, do not move */
if (strncmp(destination_path, "\\Download\\", 10) == 0) {
@ -195,7 +202,9 @@ void guac_rdpdr_fs_process_set_allocation_info(guac_rdpdr_device* device,
/* Read new size */
Stream_Read_UINT64(input_stream, size); /* AllocationSize */
GUAC_RDP_DEBUG(2, "[file_id=%i] size=%" PRIu64, file_id, (uint64_t) size);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] size=%" PRIu64,
__func__, file_id, (uint64_t) size);
/* Truncate file */
result = guac_rdp_fs_truncate((guac_rdp_fs*) device->data, file_id, size);
@ -225,7 +234,9 @@ void guac_rdpdr_fs_process_set_disposition_info(guac_rdpdr_device* device,
output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_SUCCESS, 4);
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
Stream_Write_UINT32(output_stream, length);
@ -243,7 +254,9 @@ void guac_rdpdr_fs_process_set_end_of_file_info(guac_rdpdr_device* device,
/* Read new size */
Stream_Read_UINT64(input_stream, size); /* AllocationSize */
GUAC_RDP_DEBUG(2, "[file_id=%i] size=%" PRIu64, file_id, (uint64_t) size);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] size=%" PRIu64,
__func__, file_id, (uint64_t) size);
/* Truncate file */
result = guac_rdp_fs_truncate((guac_rdp_fs*) device->data, file_id, size);
@ -268,7 +281,9 @@ void guac_rdpdr_fs_process_set_basic_info(guac_rdpdr_device* device,
/* Currently do nothing, just respond */
Stream_Write_UINT32(output_stream, length);
GUAC_RDP_DEBUG(2, "[file_id=%i] IGNORED", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i] IGNORED",
__func__, file_id);
svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream);

View File

@ -22,7 +22,6 @@
#include "config.h"
#include "debug.h"
#include "rdpdr_messages.h"
#include "rdpdr_service.h"
#include "rdp_fs.h"
@ -44,7 +43,9 @@ void guac_rdpdr_fs_process_query_volume_info(guac_rdpdr_device* device,
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_SUCCESS, 21 + GUAC_FILESYSTEM_LABEL_LENGTH);
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
Stream_Write_UINT32(output_stream, 17 + GUAC_FILESYSTEM_LABEL_LENGTH);
Stream_Write_UINT64(output_stream, 0); /* VolumeCreationTime */
@ -67,7 +68,9 @@ void guac_rdpdr_fs_process_query_size_info(guac_rdpdr_device* device, wStream* i
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_SUCCESS, 28);
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
Stream_Write_UINT32(output_stream, 24);
Stream_Write_UINT64(output_stream, info.blocks_total); /* TotalAllocationUnits */
@ -85,7 +88,9 @@ void guac_rdpdr_fs_process_query_device_info(guac_rdpdr_device* device, wStream*
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_SUCCESS, 12);
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
Stream_Write_UINT32(output_stream, 8);
Stream_Write_UINT32(output_stream, FILE_DEVICE_DISK); /* DeviceType */
@ -101,7 +106,9 @@ void guac_rdpdr_fs_process_query_attribute_info(guac_rdpdr_device* device, wStre
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_SUCCESS, 16 + GUAC_FILESYSTEM_NAME_LENGTH);
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
Stream_Write_UINT32(output_stream, 12 + GUAC_FILESYSTEM_NAME_LENGTH);
Stream_Write_UINT32(output_stream,
@ -126,7 +133,9 @@ void guac_rdpdr_fs_process_query_full_size_info(guac_rdpdr_device* device, wStre
wStream* output_stream = guac_rdpdr_new_io_completion(device,
completion_id, STATUS_SUCCESS, 36);
GUAC_RDP_DEBUG(2, "[file_id=%i]", file_id);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: [file_id=%i]",
__func__, file_id);
Stream_Write_UINT32(output_stream, 32);
Stream_Write_UINT64(output_stream, info.blocks_total); /* TotalAllocationUnits */

View File

@ -23,7 +23,6 @@
#include "config.h"
#include "client.h"
#include "debug.h"
#include "rdp_fs.h"
#include "rdp_settings.h"
#include "rdp_stream.h"
@ -261,7 +260,8 @@ void guac_rdpdr_start_download(guac_rdpdr_device* device, const char* path) {
} while (c != '\0');
GUAC_RDP_DEBUG(2, "Initiating download of \"%s\"", path);
guac_client_log(device->rdpdr->client, GUAC_LOG_DEBUG,
"%s: Initiating download of \"%s\"", __func__, path);
/* Begin stream */
guac_protocol_send_file(client->socket, stream,

View File

@ -22,7 +22,6 @@
#include "config.h"
#include "debug.h"
#include "rdp_fs.h"
#include "rdp_status.h"
@ -39,10 +38,11 @@
#include <guacamole/pool.h>
guac_rdp_fs* guac_rdp_fs_alloc(const char* drive_path) {
guac_rdp_fs* guac_rdp_fs_alloc(guac_client* client, const char* drive_path) {
guac_rdp_fs* fs = malloc(sizeof(guac_rdp_fs));
fs->client = client;
fs->drive_path = strdup(drive_path);
fs->file_id_pool = guac_pool_alloc(0);
fs->open_files = 0;
@ -157,14 +157,17 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
int flags = 0;
GUAC_RDP_DEBUG(2, "path=\"%s\", access=0x%x, file_attributes=0x%x, "
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: path=\"%s\", access=0x%x, file_attributes=0x%x, "
"create_disposition=0x%x, create_options=0x%x",
path, access, file_attributes, create_disposition,
create_options);
__func__, path, access, file_attributes,
create_disposition, create_options);
/* If no files available, return too many open */
if (fs->open_files >= GUAC_RDP_FS_MAX_FILES) {
GUAC_RDP_DEBUG(1, "%s", "Failure - too many open files.");
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Too many open files.",
__func__, path);
return GUAC_RDP_FS_ENFILE;
}
@ -174,7 +177,9 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
/* If path is relative, the file does not exist */
else if (path[0] != '\\') {
GUAC_RDP_DEBUG(1, "Failure - path \"%s\" is relative.", path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Access denied - supplied path \"%s\" is relative.",
__func__, path);
return GUAC_RDP_FS_ENOENT;
}
@ -195,18 +200,21 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
/* Normalize path, return no-such-file if invalid */
if (guac_rdp_fs_normalize_path(path, normalized_path)) {
GUAC_RDP_DEBUG(1, "Normalization of path \"%s\" failed.", path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Normalization of path \"%s\" failed.", __func__, path);
return GUAC_RDP_FS_ENOENT;
}
GUAC_RDP_DEBUG(2, "Normalized path \"%s\" to \"%s\".",
path, normalized_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Normalized path \"%s\" to \"%s\".",
__func__, path, normalized_path);
/* Translate normalized path to real path */
__guac_rdp_fs_translate_path(fs, normalized_path, real_path);
GUAC_RDP_DEBUG(2, "Translated path \"%s\" to \"%s\".",
normalized_path, real_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Translated path \"%s\" to \"%s\".",
__func__, normalized_path, real_path);
switch (create_disposition) {
@ -253,7 +261,9 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
/* Create directory */
if (mkdir(real_path, S_IRWXU)) {
if (errno != EEXIST || (flags & O_EXCL)) {
GUAC_RDP_DEBUG(1, "mkdir() failed: %s", strerror(errno));
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: mkdir() failed: %s",
__func__, strerror(errno));
return guac_rdp_fs_get_errorcode(errno);
}
}
@ -263,8 +273,9 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
}
GUAC_RDP_DEBUG(2, "native open: real_path=\"%s\", flags=0x%x",
real_path, flags);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: native open: real_path=\"%s\", flags=0x%x",
__func__, real_path, flags);
/* Open file */
fd = open(real_path, flags, S_IRUSR | S_IWUSR);
@ -277,7 +288,8 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
}
if (fd == -1) {
GUAC_RDP_DEBUG(1, "open() failed: %s", strerror(errno));
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: open() failed: %s", __func__, strerror(errno));
return guac_rdp_fs_get_errorcode(errno);
}
@ -292,7 +304,9 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path,
file->real_path = strdup(real_path);
file->bytes_written = 0;
GUAC_RDP_DEBUG(2, "Opened \"%s\" as file_id=%i", normalized_path, file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Opened \"%s\" as file_id=%i",
__func__, normalized_path, file_id);
/* Attempt to pull file information */
if (fstat(fd, &file_stat) == 0) {
@ -336,7 +350,8 @@ int guac_rdp_fs_read(guac_rdp_fs* fs, int file_id, int offset,
guac_rdp_fs_file* file = guac_rdp_fs_get_file(fs, file_id);
if (file == NULL) {
GUAC_RDP_DEBUG(1, "Read from bad file_id: %i", file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Read from bad file_id: %i", __func__, file_id);
return GUAC_RDP_FS_EINVAL;
}
@ -359,7 +374,8 @@ int guac_rdp_fs_write(guac_rdp_fs* fs, int file_id, int offset,
guac_rdp_fs_file* file = guac_rdp_fs_get_file(fs, file_id);
if (file == NULL) {
GUAC_RDP_DEBUG(1, "Write to bad file_id: %i", file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Write to bad file_id: %i", __func__, file_id);
return GUAC_RDP_FS_EINVAL;
}
@ -384,25 +400,31 @@ int guac_rdp_fs_rename(guac_rdp_fs* fs, int file_id,
guac_rdp_fs_file* file = guac_rdp_fs_get_file(fs, file_id);
if (file == NULL) {
GUAC_RDP_DEBUG(1, "Rename of bad file_id: %i", file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Rename of bad file_id: %i", __func__, file_id);
return GUAC_RDP_FS_EINVAL;
}
/* Normalize path, return no-such-file if invalid */
if (guac_rdp_fs_normalize_path(new_path, normalized_path)) {
GUAC_RDP_DEBUG(1, "Normalization of path \"%s\" failed.", new_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Normalization of path \"%s\" failed.",
__func__, new_path);
return GUAC_RDP_FS_ENOENT;
}
/* Translate normalized path to real path */
__guac_rdp_fs_translate_path(fs, normalized_path, real_path);
GUAC_RDP_DEBUG(2, "Renaming \"%s\" -> \"%s\"", file->real_path, real_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Renaming \"%s\" -> \"%s\"",
__func__, file->real_path, real_path);
/* Perform rename */
if (rename(file->real_path, real_path)) {
GUAC_RDP_DEBUG(1, "rename() failed: \"%s\" -> \"%s\"",
file->real_path, real_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: rename() failed: \"%s\" -> \"%s\"",
__func__, file->real_path, real_path);
return guac_rdp_fs_get_errorcode(errno);
}
@ -415,21 +437,24 @@ int guac_rdp_fs_delete(guac_rdp_fs* fs, int file_id) {
/* Get file */
guac_rdp_fs_file* file = guac_rdp_fs_get_file(fs, file_id);
if (file == NULL) {
GUAC_RDP_DEBUG(1, "Delete of bad file_id: %i", file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Delete of bad file_id: %i", __func__, file_id);
return GUAC_RDP_FS_EINVAL;
}
/* If directory, attempt removal */
if (file->attributes & FILE_ATTRIBUTE_DIRECTORY) {
if (rmdir(file->real_path)) {
GUAC_RDP_DEBUG(1, "rmdir() failed: \"%s\"", file->real_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: rmdir() failed: \"%s\"", __func__, file->real_path);
return guac_rdp_fs_get_errorcode(errno);
}
}
/* Otherwise, attempt deletion */
else if (unlink(file->real_path)) {
GUAC_RDP_DEBUG(1, "unlink() failed: \"%s\"", file->real_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: unlink() failed: \"%s\"", __func__, file->real_path);
return guac_rdp_fs_get_errorcode(errno);
}
@ -442,14 +467,16 @@ int guac_rdp_fs_truncate(guac_rdp_fs* fs, int file_id, int length) {
/* Get file */
guac_rdp_fs_file* file = guac_rdp_fs_get_file(fs, file_id);
if (file == NULL) {
GUAC_RDP_DEBUG(1, "Delete of bad file_id: %i", file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Delete of bad file_id: %i", __func__, file_id);
return GUAC_RDP_FS_EINVAL;
}
/* Attempt truncate */
if (ftruncate(file->fd, length)) {
GUAC_RDP_DEBUG(1, "ftruncate() to %i bytes failed: \"%s\"",
length, file->real_path);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: ftruncate() to %i bytes failed: \"%s\"",
__func__, length, file->real_path);
return guac_rdp_fs_get_errorcode(errno);
}
@ -461,15 +488,17 @@ void guac_rdp_fs_close(guac_rdp_fs* fs, int file_id) {
guac_rdp_fs_file* file = guac_rdp_fs_get_file(fs, file_id);
if (file == NULL) {
GUAC_RDP_DEBUG(2, "Ignoring close for bad file_id: %i",
file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Ignoring close for bad file_id: %i",
__func__, file_id);
return;
}
file = &(fs->files[file_id]);
GUAC_RDP_DEBUG(2, "Closed \"%s\" (file_id=%i)",
file->absolute_path, file_id);
guac_client_log(fs->client, GUAC_LOG_DEBUG,
"%s: Closed \"%s\" (file_id=%i)",
__func__, file->absolute_path, file_id);
/* Close directory, if open */
if (file->dir != NULL)

View File

@ -37,6 +37,7 @@
#include "config.h"
#include <guacamole/client.h>
#include <guacamole/pool.h>
#include <dirent.h>
@ -266,6 +267,11 @@ typedef struct guac_rdp_fs_file {
*/
typedef struct guac_rdp_fs {
/**
* The controlling client.
*/
guac_client* client;
/**
* The root of the filesystem.
*/
@ -313,7 +319,7 @@ typedef struct guac_rdp_fs_info {
/**
* Allocates a new filesystem given a root path.
*/
guac_rdp_fs* guac_rdp_fs_alloc(const char* drive_path);
guac_rdp_fs* guac_rdp_fs_alloc(guac_client* client, const char* drive_path);
/**
* Frees the given filesystem.