Implement pattern matching in dir search.
This commit is contained in:
parent
c2e1065ea2
commit
7a1b76881f
@ -39,6 +39,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <fnmatch.h>
|
||||||
|
|
||||||
#ifdef ENABLE_WINPR
|
#ifdef ENABLE_WINPR
|
||||||
#include <winpr/stream.h>
|
#include <winpr/stream.h>
|
||||||
@ -109,8 +110,8 @@ static void __guac_rdpdr_fs_translate_path(guac_rdpdr_device* device,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
|
int guac_rdpdr_fs_open(guac_rdpdr_device* device,
|
||||||
int access, int create_disposition) {
|
const char* path, int access, int create_disposition) {
|
||||||
|
|
||||||
guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
|
guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
|
||||||
char real_path[GUAC_RDPDR_FS_MAX_PATH];
|
char real_path[GUAC_RDPDR_FS_MAX_PATH];
|
||||||
@ -205,6 +206,7 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
|
|||||||
file = &(data->files[file_id]);
|
file = &(data->files[file_id]);
|
||||||
file->fd = fd;
|
file->fd = fd;
|
||||||
file->dir = NULL;
|
file->dir = NULL;
|
||||||
|
file->dir_pattern[0] = '\0';
|
||||||
file->absolute_path = strdup(normalized_path);
|
file->absolute_path = strdup(normalized_path);
|
||||||
|
|
||||||
/* Attempt to pull file information */
|
/* Attempt to pull file information */
|
||||||
@ -240,7 +242,6 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data->open_files++;
|
data->open_files++;
|
||||||
|
|
||||||
return file_id;
|
return file_id;
|
||||||
@ -429,3 +430,7 @@ guac_rdpdr_fs_file* guac_rdpdr_fs_get_file(guac_rdpdr_device* device,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int guac_rdpdr_fs_matches(const char* filename, const char* pattern) {
|
||||||
|
return fnmatch(pattern, filename, FNM_NOESCAPE) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -168,6 +168,11 @@ typedef struct guac_rdpdr_fs_file {
|
|||||||
*/
|
*/
|
||||||
struct dirent __dirent;
|
struct dirent __dirent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pattern the check directory contents against, if any.
|
||||||
|
*/
|
||||||
|
char dir_pattern[GUAC_RDPDR_FS_MAX_PATH];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bitwise OR of all associated Windows file attributes.
|
* Bitwise OR of all associated Windows file attributes.
|
||||||
*/
|
*/
|
||||||
@ -264,5 +269,10 @@ const char* guac_rdpdr_fs_read_dir(guac_rdpdr_device* device, int file_id);
|
|||||||
guac_rdpdr_fs_file* guac_rdpdr_fs_get_file(guac_rdpdr_device* device,
|
guac_rdpdr_fs_file* guac_rdpdr_fs_get_file(guac_rdpdr_device* device,
|
||||||
int file_id);
|
int file_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the given filename matches the given pattern.
|
||||||
|
*/
|
||||||
|
int guac_rdpdr_fs_matches(const char* filename, const char* pattern);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -366,37 +366,29 @@ void guac_rdpdr_fs_process_query_directory(guac_rdpdr_device* device, wStream* i
|
|||||||
/* If this is the first query, the path is included after padding */
|
/* If this is the first query, the path is included after padding */
|
||||||
if (initial_query) {
|
if (initial_query) {
|
||||||
|
|
||||||
char path[GUAC_RDPDR_FS_MAX_PATH];
|
|
||||||
|
|
||||||
Stream_Seek(input_stream, 23); /* Padding */
|
Stream_Seek(input_stream, 23); /* Padding */
|
||||||
|
|
||||||
/* FIXME: Validate path length */
|
/* FIXME: Validate path length */
|
||||||
|
|
||||||
/* Convert path to UTF-8 */
|
/* Convert path to UTF-8 */
|
||||||
guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream),
|
guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream),
|
||||||
path, path_length/2 - 1);
|
file->dir_pattern, path_length/2 - 1);
|
||||||
|
|
||||||
/* STUB: path */
|
|
||||||
guac_client_log_info(device->rdpdr->client,
|
|
||||||
"%s: STUB: Unused variable: path (%s)", __func__,
|
|
||||||
path);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If entry exists, call appriate handler to send data */
|
/* Find first matching entry in directory */
|
||||||
entry_name = guac_rdpdr_fs_read_dir(device, file_id);
|
while ((entry_name = guac_rdpdr_fs_read_dir(device, file_id)) != NULL) {
|
||||||
if (entry_name != NULL) {
|
|
||||||
|
|
||||||
int entry_file_id;
|
|
||||||
|
|
||||||
/* Convert to absolute path */
|
/* Convert to absolute path */
|
||||||
char entry_path[GUAC_RDPDR_FS_MAX_PATH];
|
char entry_path[GUAC_RDPDR_FS_MAX_PATH];
|
||||||
if (guac_rdpdr_fs_convert_path(file->absolute_path, entry_name, entry_path))
|
if (guac_rdpdr_fs_convert_path(file->absolute_path,
|
||||||
guac_client_log_info(device->rdpdr->client,
|
entry_name, entry_path) == 0) {
|
||||||
"Conversion failed: parent=\"%s\", name=\"%s\"",
|
|
||||||
file->absolute_path, entry_name); /* FIXME: Return no-more-files */
|
|
||||||
|
|
||||||
else {
|
int entry_file_id;
|
||||||
|
|
||||||
|
/* Pattern defined and match fails, continue with next file */
|
||||||
|
if (guac_rdpdr_fs_matches(entry_path, file->dir_pattern))
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Open directory entry */
|
/* Open directory entry */
|
||||||
entry_file_id = guac_rdpdr_fs_open(device, entry_path,
|
entry_file_id = guac_rdpdr_fs_open(device, entry_path,
|
||||||
|
Loading…
Reference in New Issue
Block a user