channels/drive: use new improved pattern matcher

This commit is contained in:
Marc-André Moreau 2012-11-03 23:54:54 -04:00
parent 5bf0586078
commit b8383e4c67
3 changed files with 82 additions and 105 deletions

View File

@ -41,7 +41,7 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE winpr
MODULES winpr-crt winpr-synch winpr-thread winpr-interlocked)
MODULES winpr-crt winpr-file winpr-synch winpr-thread winpr-interlocked)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
@ -50,5 +50,3 @@ if(NOT STATIC_CHANNELS)
endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client")

View File

@ -39,6 +39,7 @@
#include <sys/stat.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/stream.h>
@ -61,35 +62,6 @@
#pragma warning(disable: 4244)
#endif
static BOOL drive_file_wildcard_match(const char* pattern, const char* filename)
{
const char *p = pattern, *f = filename;
char c;
/*
* TODO: proper wildcard rules per msft's File System Behavior Overview
* Simple cases for now.
*/
f = filename;
while ((c = *p++))
{
if (c == '*')
{
c = *p++;
if (!c) /* shortcut */
return TRUE;
/* TODO: skip to tail comparison */
}
if (c != *f++)
return FALSE;
}
if (!*f)
return TRUE;
return FALSE;
}
static void drive_file_fix_path(char* path)
{
int i;
@ -222,8 +194,8 @@ static BOOL drive_file_init(DRIVE_FILE* file, UINT32 DesiredAccess, UINT32 Creat
{
file->is_dir = (S_ISDIR(st.st_mode) ? TRUE : FALSE);
#ifndef WIN32
if (st.st_size > (unsigned long)0x07fffffff)
largeFile = TRUE;
if (st.st_size > (unsigned long) 0x07FFFFFFF)
largeFile = TRUE;
#endif
exists = TRUE;
}
@ -232,14 +204,14 @@ static BOOL drive_file_init(DRIVE_FILE* file, UINT32 DesiredAccess, UINT32 Creat
file->is_dir = ((CreateOptions & FILE_DIRECTORY_FILE) ? TRUE : FALSE);
if (file->is_dir)
{
//Should only create the directory if the disposition allows for it
/* Should only create the directory if the disposition allows for it */
if ((CreateDisposition == FILE_OPEN_IF) || (CreateDisposition == FILE_CREATE))
{
if (mkdir(file->fullpath, mode) != 0)
{
file->err = errno;
return TRUE;
}
if (mkdir(file->fullpath, mode) != 0)
{
file->err = errno;
return TRUE;
}
}
}
exists = FALSE;
@ -248,6 +220,7 @@ static BOOL drive_file_init(DRIVE_FILE* file, UINT32 DesiredAccess, UINT32 Creat
if (file->is_dir)
{
file->dir = opendir(file->fullpath);
if (file->dir == NULL)
{
file->err = errno;
@ -279,7 +252,7 @@ static BOOL drive_file_init(DRIVE_FILE* file, UINT32 DesiredAccess, UINT32 Creat
break;
}
if (CreateOptions & FILE_DELETE_ON_CLOSE && DesiredAccess & DELETE)
if ((CreateOptions & FILE_DELETE_ON_CLOSE) && (DesiredAccess & DELETE))
{
file->delete_pending = TRUE;
}
@ -302,6 +275,7 @@ static BOOL drive_file_init(DRIVE_FILE* file, UINT32 DesiredAccess, UINT32 Creat
}
#endif
file->fd = OPEN(file->fullpath, oflag, mode);
if (file->fd == -1)
{
file->err = errno;
@ -336,6 +310,7 @@ void drive_file_free(DRIVE_FILE* file)
{
if (file->fd != -1)
close(file->fd);
if (file->dir != NULL)
closedir(file->dir);
@ -371,9 +346,11 @@ BOOL drive_file_read(DRIVE_FILE* file, BYTE* buffer, UINT32* Length)
return FALSE;
r = read(file->fd, buffer, *Length);
if (r < 0)
return FALSE;
*Length = (UINT32)r;
*Length = (UINT32) r;
return TRUE;
}
@ -388,8 +365,10 @@ BOOL drive_file_write(DRIVE_FILE* file, BYTE* buffer, UINT32 Length)
while (Length > 0)
{
r = write(file->fd, buffer, Length);
if (r == -1)
return FALSE;
Length -= r;
buffer += r;
}
@ -406,6 +385,7 @@ BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, S
stream_write_UINT32(output, 0); /* Length */
return FALSE;
}
switch (FsInformationClass)
{
case FileBasicInformation:
@ -587,9 +567,11 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
if (ent == NULL)
continue;
if (drive_file_wildcard_match(file->pattern, ent->d_name))
if (FilePatternMatchA(ent->d_name, file->pattern))
break;
} while (ent);
}
while (ent);
}
else
{

View File

@ -22,6 +22,7 @@
#define FREERDP_CHANNEL_RDPDR_H
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/interlocked.h>
@ -135,28 +136,30 @@ enum FILE_CREATE_OPTION
/* DR_CREATE_REQ.DesiredAccess [MS-SMB2] */
#ifndef _WIN32
enum FILE_ACCESS
{
FILE_READ_DATA = 0x00000001,
FILE_WRITE_DATA = 0x00000002,
FILE_APPEND_DATA = 0x00000004,
FILE_READ_EA = 0x00000008,
FILE_WRITE_EA = 0x00000010,
FILE_EXECUTE = 0x00000020,
FILE_READ_ATTRIBUTES = 0x00000080,
FILE_WRITE_ATTRIBUTES = 0x00000100,
DELETE = 0x00010000,
READ_CONTROL = 0x00020000,
WRITE_DAC = 0x00040000,
WRITE_OWNER = 0x00080000,
SYNCHRONIZE = 0x00100000,
ACCESS_SYSTEM_SECURITY = 0x01000000,
MAXIMUM_ALLOWED = 0x02000000,
GENERIC_ALL = 0x10000000,
GENERIC_EXECUTE = 0x20000000,
GENERIC_WRITE = 0x40000000,
GENERIC_READ = 0x80000000
};
#if 0
#define FILE_READ_DATA 0x00000001
#define FILE_WRITE_DATA 0x00000002
#define FILE_APPEND_DATA 0x00000004
#define FILE_READ_EA 0x00000008
#define FILE_WRITE_EA 0x00000010
#define FILE_EXECUTE 0x00000020
#define FILE_READ_ATTRIBUTES 0x00000080
#define FILE_WRITE_ATTRIBUTES 0x00000100
#endif
#define DELETE 0x00010000
#define READ_CONTROL 0x00020000
#define WRITE_DAC 0x00040000
#define WRITE_OWNER 0x00080000
#define SYNCHRONIZE 0x00100000
#define ACCESS_SYSTEM_SECURITY 0x01000000
#define MAXIMUM_ALLOWED 0x02000000
#define GENERIC_ALL 0x10000000
#define GENERIC_EXECUTE 0x20000000
#define GENERIC_WRITE 0x40000000
#define GENERIC_READ 0x80000000
#endif
/* DR_CREATE_RSP.Information */
@ -308,22 +311,19 @@ enum RDPDR_PRINTER_ANNOUNCE_FLAG
#ifndef _WIN32
enum FILE_ATTRIBUTE
{
FILE_ATTRIBUTE_ARCHIVE = 0x00000020,
FILE_ATTRIBUTE_COMPRESSED = 0x00000800,
FILE_ATTRIBUTE_DIRECTORY = 0x00000010,
FILE_ATTRIBUTE_ENCRYPTED = 0x00004000,
FILE_ATTRIBUTE_HIDDEN = 0x00000002,
FILE_ATTRIBUTE_NORMAL = 0x00000080,
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000,
FILE_ATTRIBUTE_OFFLINE = 0x00001000,
FILE_ATTRIBUTE_READONLY = 0x00000001,
FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400,
FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200,
FILE_ATTRIBUTE_SYSTEM = 0x00000004,
FILE_ATTRIBUTE_TEMPORARY = 0x00000100
};
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#endif
@ -361,29 +361,26 @@ enum FSCTL_STRUCTURE
#ifndef _WIN32
enum FILE_FS_ATTRIBUTE_INFORMATION
{
FILE_SUPPORTS_USN_JOURNAL = 0x02000000,
FILE_SUPPORTS_OPEN_BY_FILE_ID = 0x01000000,
FILE_SUPPORTS_EXTENDED_ATTRIBUTES = 0x00800000,
FILE_SUPPORTS_HARD_LINKS = 0x00400000,
FILE_SUPPORTS_TRANSACTIONS = 0x00200000,
FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000,
FILE_READ_ONLY_VOLUME = 0x00080000,
FILE_NAMED_STREAMS = 0x00040000,
FILE_SUPPORTS_ENCRYPTION = 0x00020000,
FILE_SUPPORTS_OBJECT_IDS = 0x00010000,
FILE_VOLUME_IS_COMPRESSED = 0x00008000,
FILE_SUPPORTS_REMOTE_STORAGE = 0x00000100,
FILE_SUPPORTS_REPARSE_POINTS = 0x00000080,
FILE_SUPPORTS_SPARSE_FILES = 0x00000040,
FILE_VOLUME_QUOTAS = 0x00000020,
FILE_FILE_COMPRESSION = 0x00000010,
FILE_PERSISTENT_ACLS = 0x00000008,
FILE_UNICODE_ON_DISK = 0x00000004,
FILE_CASE_PRESERVED_NAMES = 0x00000002,
FILE_CASE_SENSITIVE_SEARCH = 0x00000001
};
#define FILE_SUPPORTS_USN_JOURNAL 0x02000000
#define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000
#define FILE_SUPPORTS_HARD_LINKS 0x00400000
#define FILE_SUPPORTS_TRANSACTIONS 0x00200000
#define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000
#define FILE_READ_ONLY_VOLUME 0x00080000
#define FILE_NAMED_STREAMS 0x00040000
#define FILE_SUPPORTS_ENCRYPTION 0x00020000
#define FILE_SUPPORTS_OBJECT_IDS 0x00010000
#define FILE_VOLUME_IS_COMPRESSED 0x00008000
#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
#define FILE_SUPPORTS_SPARSE_FILES 0x00000040
#define FILE_VOLUME_QUOTAS 0x00000020
#define FILE_FILE_COMPRESSION 0x00000010
#define FILE_PERSISTENT_ACLS 0x00000008
#define FILE_UNICODE_ON_DISK 0x00000004
#define FILE_CASE_PRESERVED_NAMES 0x00000002
#define FILE_CASE_SENSITIVE_SEARCH 0x00000001
#endif