hardend channel drive
This commit is contained in:
parent
0bf222ec50
commit
d3d60520e5
@ -5,6 +5,8 @@
|
||||
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2010-2011 Vic Lee
|
||||
* Copyright 2012 Gerald Richter
|
||||
* Copyright 2015 Thincast Technologies GmbH
|
||||
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -96,6 +98,11 @@ static char* drive_file_combine_fullpath(const char* base_path, const char* path
|
||||
char* fullpath;
|
||||
|
||||
fullpath = (char*) malloc(strlen(base_path) + strlen(path) + 1);
|
||||
if (!fullpath)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed!");
|
||||
return NULL;
|
||||
}
|
||||
strcpy(fullpath, base_path);
|
||||
strcat(fullpath, path);
|
||||
drive_file_fix_path(fullpath);
|
||||
@ -127,6 +134,11 @@ static BOOL drive_file_remove_dir(const char* path)
|
||||
}
|
||||
|
||||
p = (char*) malloc(strlen(path) + strlen(pdirent->d_name) + 2);
|
||||
if (!p)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed!");
|
||||
return FALSE;
|
||||
}
|
||||
sprintf(p, "%s/%s", path, pdirent->d_name);
|
||||
|
||||
if (STAT(p, &st) != 0)
|
||||
@ -299,8 +311,12 @@ DRIVE_FILE* drive_file_new(const char* base_path, const char* path, UINT32 id,
|
||||
{
|
||||
DRIVE_FILE* file;
|
||||
|
||||
file = (DRIVE_FILE*) malloc(sizeof(DRIVE_FILE));
|
||||
ZeroMemory(file, sizeof(DRIVE_FILE));
|
||||
file = (DRIVE_FILE*) calloc(1, sizeof(DRIVE_FILE));
|
||||
if (!file)
|
||||
{
|
||||
WLog_ERR(TAG, "calloc failed!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file->id = id;
|
||||
file->basepath = (char*) base_path;
|
||||
@ -583,9 +599,18 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
FileNameLength / 2, &s, 0, NULL, NULL);
|
||||
|
||||
if (status < 1)
|
||||
s = (char*) calloc(1, 1);
|
||||
if (!(s = (char*) calloc(1, 1)))
|
||||
{
|
||||
WLog_ERR(TAG, "calloc failed!");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fullpath = drive_file_combine_fullpath(file->basepath, s);
|
||||
if (!fullpath)
|
||||
{
|
||||
WLog_ERR(TAG, "drive_file_combine_fullpath failed!");
|
||||
return FALSE;
|
||||
}
|
||||
free(s);
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -636,7 +661,13 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
|
||||
free(file->pattern);
|
||||
|
||||
if (path[0])
|
||||
file->pattern = _strdup(strrchr(path, '\\') + 1);
|
||||
{
|
||||
if (!(file->pattern = _strdup(strrchr(path, '\\') + 1)))
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
file->pattern = NULL;
|
||||
}
|
||||
@ -670,6 +701,11 @@ BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYT
|
||||
|
||||
memset(&st, 0, sizeof(struct STAT));
|
||||
ent_path = (WCHAR*) malloc(strlen(file->fullpath) + strlen(ent->d_name) + 2);
|
||||
if (!ent_path)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed!");
|
||||
return FALSE;
|
||||
}
|
||||
sprintf((char*) ent_path, "%s/%s", file->fullpath, ent->d_name);
|
||||
|
||||
if (STAT((char*) ent_path, &st) != 0)
|
||||
|
@ -5,6 +5,8 @@
|
||||
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2010-2011 Vic Lee
|
||||
* Copyright 2012 Gerald Richter
|
||||
* Copyright 2015 Thincast Technologies GmbH
|
||||
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -24,6 +26,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <freerdp/channels/log.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
@ -90,6 +93,8 @@ typedef UINT32 mode_t;
|
||||
(_f->delete_pending ? FILE_ATTRIBUTE_TEMPORARY : 0) | \
|
||||
(st.st_mode & S_IWUSR ? 0 : FILE_ATTRIBUTE_READONLY))
|
||||
|
||||
#define TAG CHANNELS_TAG("drive.client")
|
||||
|
||||
typedef struct _DRIVE_FILE DRIVE_FILE;
|
||||
|
||||
struct _DRIVE_FILE
|
||||
|
@ -4,6 +4,8 @@
|
||||
*
|
||||
* Copyright 2010-2011 Vic Lee
|
||||
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2015 Thincast Technologies GmbH
|
||||
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -104,7 +106,7 @@ static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* drive, UINT32 id)
|
||||
return file;
|
||||
}
|
||||
|
||||
static void drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
int status;
|
||||
void* key;
|
||||
@ -127,7 +129,15 @@ static void drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
|
||||
PathLength / 2, &path, 0, NULL, NULL);
|
||||
|
||||
if (status < 1)
|
||||
{
|
||||
path = (char*) calloc(1, 1);
|
||||
if (!path)
|
||||
{
|
||||
WLog_ERR(TAG, "calloc failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FileId = irp->devman->id_sequence++;
|
||||
|
||||
@ -152,7 +162,12 @@ static void drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
|
||||
else
|
||||
{
|
||||
key = (void*) (size_t) file->id;
|
||||
ListDictionary_Add(drive->files, key, file);
|
||||
if (!ListDictionary_Add(drive->files, key, file))
|
||||
{
|
||||
WLog_ERR(TAG, "ListDictionary_Add failed!");
|
||||
free(path);
|
||||
return ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
switch (CreateDisposition)
|
||||
{
|
||||
@ -179,10 +194,10 @@ static void drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
|
||||
|
||||
free(path);
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_close(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_close(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
void* key;
|
||||
DRIVE_FILE* file;
|
||||
@ -203,10 +218,10 @@ static void drive_process_irp_close(DRIVE_DEVICE* drive, IRP* irp)
|
||||
|
||||
Stream_Zero(irp->output, 5); /* Padding(5) */
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
DRIVE_FILE* file;
|
||||
UINT32 Length;
|
||||
@ -231,6 +246,11 @@ static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp)
|
||||
else
|
||||
{
|
||||
buffer = (BYTE*) malloc(Length);
|
||||
if (!buffer)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed!");
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
if (!drive_file_read(file, buffer, &Length))
|
||||
{
|
||||
@ -239,26 +259,26 @@ static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp)
|
||||
buffer = NULL;
|
||||
Length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Stream_Write_UINT32(irp->output, Length);
|
||||
|
||||
if (Length > 0)
|
||||
{
|
||||
Stream_EnsureRemainingCapacity(irp->output, (int) Length);
|
||||
if (!Stream_EnsureRemainingCapacity(irp->output, (int) Length))
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
return ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
Stream_Write(irp->output, buffer, Length);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_write(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_write(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
DRIVE_FILE* file;
|
||||
UINT32 Length;
|
||||
@ -285,18 +305,14 @@ static void drive_process_irp_write(DRIVE_DEVICE* drive, IRP* irp)
|
||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||
Length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Stream_Write_UINT32(irp->output, Length);
|
||||
Stream_Write_UINT8(irp->output, 0); /* Padding */
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_query_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_query_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
DRIVE_FILE* file;
|
||||
UINT32 FsInformationClass;
|
||||
@ -313,15 +329,11 @@ static void drive_process_irp_query_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
DRIVE_FILE* file;
|
||||
UINT32 FsInformationClass;
|
||||
@ -341,20 +353,16 @@ static void drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (file && file->is_dir && !dir_empty(file->fullpath))
|
||||
irp->IoStatus = STATUS_DIRECTORY_NOT_EMPTY;
|
||||
|
||||
Stream_Write_UINT32(irp->output, Length);
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
UINT32 FsInformationClass;
|
||||
wStream* output = irp->output;
|
||||
@ -376,7 +384,13 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP*
|
||||
/* http://msdn.microsoft.com/en-us/library/cc232108.aspx */
|
||||
length = ConvertToUnicode(sys_code_page, 0, volumeLabel, -1, &outStr, 0) * 2;
|
||||
Stream_Write_UINT32(output, 17 + length); /* Length */
|
||||
Stream_EnsureRemainingCapacity(output, 17 + length);
|
||||
if (!Stream_EnsureRemainingCapacity(output, 17 + length))
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
free(outStr);
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
|
||||
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* VolumeCreationTime */
|
||||
#ifdef ANDROID
|
||||
Stream_Write_UINT32(output, svfst.f_fsid.__val[0]); /* VolumeSerialNumber */
|
||||
@ -393,7 +407,11 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP*
|
||||
case FileFsSizeInformation:
|
||||
/* http://msdn.microsoft.com/en-us/library/cc232107.aspx */
|
||||
Stream_Write_UINT32(output, 24); /* Length */
|
||||
Stream_EnsureRemainingCapacity(output, 24);
|
||||
if (!Stream_EnsureRemainingCapacity(output, 24))
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
Stream_Write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */
|
||||
Stream_Write_UINT64(output, svfst.f_bavail); /* AvailableAllocationUnits */
|
||||
Stream_Write_UINT32(output, 1); /* SectorsPerAllocationUnit */
|
||||
@ -404,7 +422,11 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP*
|
||||
/* http://msdn.microsoft.com/en-us/library/cc232101.aspx */
|
||||
length = ConvertToUnicode(sys_code_page, 0, diskType, -1, &outStr, 0) * 2;
|
||||
Stream_Write_UINT32(output, 12 + length); /* Length */
|
||||
Stream_EnsureRemainingCapacity(output, 12 + length);
|
||||
if (!Stream_EnsureRemainingCapacity(output, 12 + length))
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
Stream_Write_UINT32(output,
|
||||
FILE_CASE_SENSITIVE_SEARCH |
|
||||
FILE_CASE_PRESERVED_NAMES |
|
||||
@ -422,7 +444,11 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP*
|
||||
case FileFsFullSizeInformation:
|
||||
/* http://msdn.microsoft.com/en-us/library/cc232104.aspx */
|
||||
Stream_Write_UINT32(output, 32); /* Length */
|
||||
Stream_EnsureRemainingCapacity(output, 32);
|
||||
if (!Stream_EnsureRemainingCapacity(output, 32))
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
Stream_Write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */
|
||||
Stream_Write_UINT64(output, svfst.f_bavail); /* CallerAvailableAllocationUnits */
|
||||
Stream_Write_UINT64(output, svfst.f_bfree); /* AvailableAllocationUnits */
|
||||
@ -433,7 +459,11 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP*
|
||||
case FileFsDeviceInformation:
|
||||
/* http://msdn.microsoft.com/en-us/library/cc232109.aspx */
|
||||
Stream_Write_UINT32(output, 8); /* Length */
|
||||
Stream_EnsureRemainingCapacity(output, 8);
|
||||
if (!Stream_EnsureRemainingCapacity(output, 8))
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
Stream_Write_UINT32(output, FILE_DEVICE_DISK); /* DeviceType */
|
||||
Stream_Write_UINT32(output, 0); /* Characteristics */
|
||||
break;
|
||||
@ -444,12 +474,12 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP*
|
||||
break;
|
||||
}
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
/* http://msdn.microsoft.com/en-us/library/cc241518.aspx */
|
||||
|
||||
static void drive_process_irp_silent_ignore(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_silent_ignore(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
UINT32 FsInformationClass;
|
||||
wStream* output = irp->output;
|
||||
@ -458,10 +488,10 @@ static void drive_process_irp_silent_ignore(DRIVE_DEVICE* drive, IRP* irp)
|
||||
|
||||
Stream_Write_UINT32(output, 0); /* Length */
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
char* path = NULL;
|
||||
int status;
|
||||
@ -479,7 +509,11 @@ static void drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp)
|
||||
PathLength / 2, &path, 0, NULL, NULL);
|
||||
|
||||
if (status < 1)
|
||||
path = (char*) calloc(1, 1);
|
||||
if (!(path = (char*) calloc(1, 1)))
|
||||
{
|
||||
WLog_ERR(TAG, "calloc failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
|
||||
file = drive_get_file_by_id(drive, irp->FileId);
|
||||
|
||||
@ -495,86 +529,89 @@ static void drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp)
|
||||
|
||||
free(path);
|
||||
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp_directory_control(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_directory_control(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
switch (irp->MinorFunction)
|
||||
{
|
||||
case IRP_MN_QUERY_DIRECTORY:
|
||||
drive_process_irp_query_directory(drive, irp);
|
||||
return drive_process_irp_query_directory(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: /* TODO */
|
||||
irp->Discard(irp);
|
||||
return irp->Discard(irp);
|
||||
break;
|
||||
|
||||
default:
|
||||
irp->IoStatus = STATUS_NOT_SUPPORTED;
|
||||
Stream_Write_UINT32(irp->output, 0); /* Length */
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
break;
|
||||
}
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
static void drive_process_irp_device_control(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp_device_control(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
Stream_Write_UINT32(irp->output, 0); /* OutputBufferLength */
|
||||
irp->Complete(irp);
|
||||
return irp->Complete(irp);
|
||||
}
|
||||
|
||||
static void drive_process_irp(DRIVE_DEVICE* drive, IRP* irp)
|
||||
static WIN32ERROR drive_process_irp(DRIVE_DEVICE* drive, IRP* irp)
|
||||
{
|
||||
irp->IoStatus = STATUS_SUCCESS;
|
||||
WIN32ERROR error;
|
||||
|
||||
switch (irp->MajorFunction)
|
||||
{
|
||||
case IRP_MJ_CREATE:
|
||||
drive_process_irp_create(drive, irp);
|
||||
error = drive_process_irp_create(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_CLOSE:
|
||||
drive_process_irp_close(drive, irp);
|
||||
error = drive_process_irp_close(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_READ:
|
||||
drive_process_irp_read(drive, irp);
|
||||
error = drive_process_irp_read(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_WRITE:
|
||||
drive_process_irp_write(drive, irp);
|
||||
error = drive_process_irp_write(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_QUERY_INFORMATION:
|
||||
drive_process_irp_query_information(drive, irp);
|
||||
error = drive_process_irp_query_information(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_SET_INFORMATION:
|
||||
drive_process_irp_set_information(drive, irp);
|
||||
error = drive_process_irp_set_information(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_QUERY_VOLUME_INFORMATION:
|
||||
drive_process_irp_query_volume_information(drive, irp);
|
||||
error = drive_process_irp_query_volume_information(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_LOCK_CONTROL:
|
||||
drive_process_irp_silent_ignore(drive, irp);
|
||||
error = drive_process_irp_silent_ignore(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_DIRECTORY_CONTROL:
|
||||
drive_process_irp_directory_control(drive, irp);
|
||||
error = drive_process_irp_directory_control(drive, irp);
|
||||
break;
|
||||
|
||||
case IRP_MJ_DEVICE_CONTROL:
|
||||
drive_process_irp_device_control(drive, irp);
|
||||
error = drive_process_irp_device_control(drive, irp);
|
||||
break;
|
||||
|
||||
default:
|
||||
irp->IoStatus = STATUS_NOT_SUPPORTED;
|
||||
irp->Complete(irp);
|
||||
error = irp->Complete(irp);
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static void* drive_thread_func(void* arg)
|
||||
@ -582,6 +619,7 @@ static void* drive_thread_func(void* arg)
|
||||
IRP* irp;
|
||||
wMessage message;
|
||||
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) arg;
|
||||
WIN32ERROR error;
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -597,17 +635,23 @@ static void* drive_thread_func(void* arg)
|
||||
irp = (IRP*) message.wParam;
|
||||
|
||||
if (irp)
|
||||
drive_process_irp(drive, irp);
|
||||
if ((error = drive_process_irp(drive, irp)))
|
||||
{
|
||||
WLog_ERR(TAG, "drive_process_irp failed with error %lu!", error);
|
||||
ExitThread((DWORD)error);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ExitThread(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void drive_irp_request(DEVICE* device, IRP* irp)
|
||||
static WIN32ERROR drive_irp_request(DEVICE* device, IRP* irp)
|
||||
{
|
||||
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
|
||||
MessageQueue_Post(drive->IrpQueue, NULL, 0, (void*) irp, NULL);
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
static void drive_free(DEVICE* device)
|
||||
@ -627,10 +671,11 @@ static void drive_free(DEVICE* device)
|
||||
free(drive);
|
||||
}
|
||||
|
||||
void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)
|
||||
WIN32ERROR drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)
|
||||
{
|
||||
int i, length;
|
||||
DRIVE_DEVICE* drive;
|
||||
WIN32ERROR error;
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
@ -648,8 +693,12 @@ void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char*
|
||||
|
||||
if (name[0] && path[0])
|
||||
{
|
||||
drive = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE));
|
||||
ZeroMemory(drive, sizeof(DRIVE_DEVICE));
|
||||
drive = (DRIVE_DEVICE*) calloc(1, sizeof(DRIVE_DEVICE));
|
||||
if (!drive)
|
||||
{
|
||||
WLog_ERR(TAG, "calloc failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
|
||||
drive->device.type = RDPDR_DTYP_FILESYSTEM;
|
||||
drive->device.name = name;
|
||||
@ -658,6 +707,12 @@ void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char*
|
||||
|
||||
length = (int) strlen(name);
|
||||
drive->device.data = Stream_New(NULL, length + 1);
|
||||
if (!drive->device.data)
|
||||
{
|
||||
WLog_ERR(TAG, "Stream_New failed!");
|
||||
error = CHANNEL_RC_NO_MEMORY;
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
for (i = 0; i <= length; i++)
|
||||
Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);
|
||||
@ -665,15 +720,42 @@ void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char*
|
||||
drive->path = path;
|
||||
|
||||
drive->files = ListDictionary_New(TRUE);
|
||||
if (!drive->files)
|
||||
{
|
||||
WLog_ERR(TAG, "ListDictionary_New failed!");
|
||||
error = CHANNEL_RC_NO_MEMORY;
|
||||
goto out_error;
|
||||
}
|
||||
ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;
|
||||
|
||||
drive->IrpQueue = MessageQueue_New(NULL);
|
||||
drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL);
|
||||
if (!drive->IrpQueue)
|
||||
{
|
||||
WLog_ERR(TAG, "ListDictionary_New failed!");
|
||||
error = CHANNEL_RC_NO_MEMORY;
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive);
|
||||
if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive)))
|
||||
{
|
||||
WLog_ERR(TAG, "RegisterDevice failed with error %lu!", error);
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (!(drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "CreateThread failed!");
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
ResumeThread(drive->thread);
|
||||
}
|
||||
return CHANNEL_RC_OK;
|
||||
out_error:
|
||||
MessageQueue_Free(drive->IrpQueue);
|
||||
ListDictionary_Free(drive->files);
|
||||
free(drive);
|
||||
return error;
|
||||
}
|
||||
|
||||
#ifdef STATIC_CHANNELS
|
||||
@ -682,13 +764,16 @@ void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char*
|
||||
|
||||
UINT sys_code_page = 0;
|
||||
|
||||
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
WIN32ERROR DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
{
|
||||
RDPDR_DRIVE* drive;
|
||||
WIN32ERROR error;
|
||||
#ifdef WIN32
|
||||
char* dev;
|
||||
int len;
|
||||
char devlist[512], buf[512];
|
||||
char *bufdup;
|
||||
char *devdup;
|
||||
#endif
|
||||
|
||||
drive = (RDPDR_DRIVE*) pEntryPoints->device;
|
||||
@ -702,6 +787,11 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
|
||||
free(drive->Path);
|
||||
drive->Path = _strdup("/");
|
||||
if (!drive->Path)
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
else if (strcmp(drive->Path, "%") == 0)
|
||||
{
|
||||
@ -713,12 +803,26 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
free(drive->Path);
|
||||
|
||||
if (home_env)
|
||||
{
|
||||
drive->Path = _strdup(home_env);
|
||||
if (!drive->Path)
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
drive->Path = _strdup("/");
|
||||
if (!drive->Path)
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
||||
error = drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
||||
|
||||
#else
|
||||
sys_code_page = GetACP();
|
||||
@ -727,7 +831,14 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
if (strcmp(drive->Path, "%") == 0)
|
||||
{
|
||||
_snprintf(buf, sizeof(buf), "%s\\", getenv("USERPROFILE"));
|
||||
drive_register_drive_path(pEntryPoints, drive->Name, _strdup(buf));
|
||||
free(drive->Path);
|
||||
drive->Path = _strdup(buf);
|
||||
if (!drive->Path)
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
error = drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
||||
}
|
||||
else if (strcmp(drive->Path, "*") == 0)
|
||||
{
|
||||
@ -746,15 +857,29 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
buf[len + 1] = dev[0];
|
||||
buf[len + 2] = 0;
|
||||
buf[len + 3] = 0;
|
||||
drive_register_drive_path(pEntryPoints, _strdup(buf), _strdup(dev));
|
||||
if (!(bufdup = _strdup(buf)))
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
if (!(devdup = _strdup(dev)))
|
||||
{
|
||||
WLog_ERR(TAG, "_strdup failed!");
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
|
||||
if ((error = drive_register_drive_path(pEntryPoints, bufdup, devdup)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
||||
error = drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user