From 439cd7c903db25a3fea24e314d44fab2b44b66af Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 2 Aug 2013 17:23:09 -0700 Subject: [PATCH] Move to attributes rather than type. --- src/protocols/rdp/guac_rdpdr/rdpdr_fs.c | 33 ++++++++----- src/protocols/rdp/guac_rdpdr/rdpdr_fs.h | 47 +++++++------------ .../guac_rdpdr/rdpdr_fs_messages_file_info.c | 15 ++---- .../guac_rdpdr/rdpdr_fs_messages_vol_info.c | 4 +- src/protocols/rdp/guac_rdpdr/rdpdr_messages.h | 1 + 5 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c index 4c258fdb..37c360d7 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c @@ -115,6 +115,7 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path, guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; char real_path[GUAC_RDPDR_FS_MAX_PATH]; char normalized_path[GUAC_RDPDR_FS_MAX_PATH]; + char* filename; struct stat file_stat; int fd; @@ -193,14 +194,17 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path, /* Translate normalized path to real path */ __guac_rdpdr_fs_translate_path(device, normalized_path, real_path); - guac_client_log_info(device->rdpdr->client, - "Path virtual=\"%s\" -> normalized=\"%s\", real=\"%s\"", - path, normalized_path, real_path); - /* Open file */ fd = open(real_path, flags, mode); - if (fd == -1) + if (fd == -1) { + guac_client_log_error(device->rdpdr->client, + "Open of real file failed: \"%s\"", real_path); return GUAC_RDPDR_FS_ENOENT; + } + else + guac_client_log_info(device->rdpdr->client, + "Opened real file: \"%s\"", real_path); + /* Get file ID, init file */ file_id = guac_pool_next_int(data->file_id_pool); @@ -209,20 +213,27 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path, file->dir = NULL; file->absolute_path = strdup(normalized_path); + /* Parse out filename */ + filename = file->absolute_path; + while (*filename != '\\' && *filename != '/' && *filename != 0) + filename++; + + file->name = filename; + /* Attempt to pull file information */ if (fstat(fd, &file_stat) == 0) { /* Load size and times */ file->size = file_stat.st_size; - file->ctime = file_stat.st_ctime; - file->mtime = file_stat.st_mtime; - file->atime = file_stat.st_atime; + file->ctime = WINDOWS_TIME(file_stat.st_ctime); + file->mtime = WINDOWS_TIME(file_stat.st_mtime); + file->atime = WINDOWS_TIME(file_stat.st_atime); /* Set type */ if (S_ISDIR(file_stat.st_mode)) - file->type = GUAC_RDPDR_FS_DIRECTORY; + file->attributes = FILE_ATTRIBUTE_DIRECTORY; else - file->type = GUAC_RDPDR_FS_FILE; + file->attributes = FILE_ATTRIBUTE_NORMAL; } @@ -237,7 +248,7 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path, file->ctime = 0; file->mtime = 0; file->atime = 0; - file->type = GUAC_RDPDR_FS_FILE; + file->attributes = FILE_ATTRIBUTE_NORMAL; } diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h index 42aa3cd6..79f0de03 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h @@ -138,38 +138,22 @@ */ #define WINDOWS_TIME(t) ((t - ((uint64_t) 11644473600)) * 10000000) -/** - * Enumeration of all supported file types. - */ -typedef enum guac_rdpdr_fs_file_type { - - /** - * A regular file. - */ - GUAC_RDPDR_FS_FILE, - - /** - * A directory. - */ - GUAC_RDPDR_FS_DIRECTORY - -} guac_rdpdr_fs_file_type; - /** * An arbitrary file on the virtual filesystem of the Guacamole drive. */ typedef struct guac_rdpdr_fs_file { + /** + * The filename of this file. The data of this name is actually stored + * within the absolute_path. + */ + char* name; + /** * The absolute path, including filename, of this file. */ char* absolute_path; - /** - * The type of this file. - */ - guac_rdpdr_fs_file_type type; - /** * Associated local file descriptor. */ @@ -187,25 +171,30 @@ typedef struct guac_rdpdr_fs_file { */ struct dirent __dirent; + /** + * Bitwise OR of all associated Windows file attributes. + */ + int attributes; + /** * The size of this file, in bytes. */ - off_t size; + int size; /** - * The time this file was created, as a UNIX timestamp. + * The time this file was created, as a Windows timestamp. */ - time_t ctime; + uint64_t ctime; /** - * The time this file was last modified, as a UNIX timestamp. + * The time this file was last modified, as a Windows timestamp. */ - time_t mtime; + uint64_t mtime; /** - * The time this file was last accessed, as a UNIX timestamp. + * The time this file was last accessed, as a Windows timestamp. */ - time_t atime; + uint64_t atime; } guac_rdpdr_fs_file; diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c index 8a089b08..65262267 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c @@ -69,16 +69,11 @@ void guac_rdpdr_fs_process_query_basic_info(guac_rdpdr_device* device, wStream* Stream_Write_UINT32(output_stream, STATUS_SUCCESS); Stream_Write_UINT32(output_stream, 18 + GUAC_FILESYSTEM_NAME_LENGTH); - Stream_Write_UINT64(output_stream, WINDOWS_TIME(file->ctime)); /* CreationTime */ - Stream_Write_UINT64(output_stream, WINDOWS_TIME(file->atime)); /* LastAccessTime */ - Stream_Write_UINT64(output_stream, WINDOWS_TIME(file->mtime)); /* LastWriteTime */ - Stream_Write_UINT64(output_stream, WINDOWS_TIME(file->mtime)); /* ChangeTime */ - - /* FileAttributes */ - if (file->type == GUAC_RDPDR_FS_DIRECTORY) - Stream_Write_UINT32(output_stream, FILE_ATTRIBUTE_DIRECTORY); - else - Stream_Write_UINT32(output_stream, FILE_ATTRIBUTE_NORMAL); /* FileAttributes */ + Stream_Write_UINT64(output_stream, file->ctime); /* CreationTime */ + Stream_Write_UINT64(output_stream, file->atime); /* LastAccessTime */ + Stream_Write_UINT64(output_stream, file->mtime); /* LastWriteTime */ + Stream_Write_UINT64(output_stream, file->mtime); /* ChangeTime */ + Stream_Write_UINT32(output_stream, file->attributes); /* FileAttributes */ /* Reserved */ Stream_Write_UINT32(output_stream, 0); diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_vol_info.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_vol_info.c index 8bce110b..52cc88a8 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_vol_info.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_vol_info.c @@ -68,8 +68,8 @@ void guac_rdpdr_fs_process_query_volume_info(guac_rdpdr_device* device, wStream* Stream_Write_UINT32(output_stream, STATUS_SUCCESS); Stream_Write_UINT32(output_stream, 18 + GUAC_FILESYSTEM_NAME_LENGTH); - Stream_Write_UINT64(output_stream, WINDOWS_TIME(file->ctime)); /* VolumeCreationTime */ - Stream_Write(output_stream, "GUAC", 4); /* VolumeSerialNumber */ + Stream_Write_UINT64(output_stream, file->ctime); /* VolumeCreationTime */ + Stream_Write(output_stream, "GUAC", 4); /* VolumeSerialNumber */ Stream_Write_UINT32(output_stream, GUAC_FILESYSTEM_NAME_LENGTH); Stream_Write_UINT8(output_stream, FALSE); /* SupportsObjects */ Stream_Write_UINT8(output_stream, 0); /* Reserved */ diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h b/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h index 918d2bdc..78199fd7 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h @@ -196,6 +196,7 @@ * Status constants. */ #define STATUS_SUCCESS 0x00000000 +#define STATUS_NO_MORE_FILES 0x80000006 #define STATUS_DEVICE_OFF_LINE 0x80000010 #define STATUS_NO_SUCH_FILE 0xC000000F #define STATUS_END_OF_FILE 0xC0000011