2011-08-05 20:12:16 +04:00
|
|
|
/**
|
2012-10-09 05:00:07 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-05 20:12:16 +04:00
|
|
|
* File System Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
2012-10-09 05:00:07 +04:00
|
|
|
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-08-05 20:12:16 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-18 13:52:49 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
#define __USE_LARGEFILE64
|
|
|
|
#define _LARGEFILE_SOURCE
|
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-19 17:43:04 +04:00
|
|
|
#include <errno.h>
|
2011-08-05 20:12:16 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-10-03 05:52:27 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-09-23 21:54:14 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/thread.h>
|
2013-10-17 23:56:56 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-10-03 05:52:27 +04:00
|
|
|
#include <winpr/interlocked.h>
|
2013-10-18 01:06:51 +04:00
|
|
|
#include <winpr/collections.h>
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
#include <freerdp/channels/rdpdr.h>
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
#include "drive_file.h"
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
typedef struct _DRIVE_DEVICE DRIVE_DEVICE;
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
struct _DRIVE_DEVICE
|
2011-08-05 20:12:16 +04:00
|
|
|
{
|
|
|
|
DEVICE device;
|
|
|
|
|
|
|
|
char* path;
|
2013-10-18 01:06:51 +04:00
|
|
|
wListDictionary* files;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2012-09-23 21:54:14 +04:00
|
|
|
HANDLE thread;
|
2013-11-04 06:01:36 +04:00
|
|
|
wMessageQueue* IrpQueue;
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2012-04-18 13:52:49 +04:00
|
|
|
DEVMAN* devman;
|
|
|
|
};
|
2011-10-19 17:43:04 +04:00
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static UINT32 drive_map_posix_err(int fs_errno)
|
2011-10-19 17:43:04 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 rc;
|
2011-10-19 17:43:04 +04:00
|
|
|
|
|
|
|
/* try to return NTSTATUS version of error code */
|
2012-10-03 05:52:27 +04:00
|
|
|
|
2011-10-19 17:43:04 +04:00
|
|
|
switch (fs_errno)
|
|
|
|
{
|
|
|
|
case EPERM:
|
|
|
|
case EACCES:
|
|
|
|
rc = STATUS_ACCESS_DENIED;
|
|
|
|
break;
|
|
|
|
case ENOENT:
|
|
|
|
rc = STATUS_NO_SUCH_FILE;
|
|
|
|
break;
|
|
|
|
case EBUSY:
|
|
|
|
rc = STATUS_DEVICE_BUSY;
|
|
|
|
break;
|
|
|
|
case EEXIST:
|
|
|
|
rc = STATUS_OBJECT_NAME_COLLISION;
|
|
|
|
break;
|
|
|
|
case EISDIR:
|
|
|
|
rc = STATUS_FILE_IS_A_DIRECTORY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rc = STATUS_UNSUCCESSFUL;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2011-10-19 17:43:04 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* drive, UINT32 id)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2013-10-18 01:06:51 +04:00
|
|
|
DRIVE_FILE* file = NULL;
|
|
|
|
void* key = (void*) (size_t) id;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = (DRIVE_FILE*) ListDictionary_GetItemValue(drive->files, key);
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2013-10-18 01:06:51 +04:00
|
|
|
return file;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
int status;
|
2013-10-18 01:06:51 +04:00
|
|
|
void* key;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 FileId;
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE Information;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 DesiredAccess;
|
|
|
|
UINT32 CreateDisposition;
|
|
|
|
UINT32 CreateOptions;
|
|
|
|
UINT32 PathLength;
|
2013-10-18 01:06:51 +04:00
|
|
|
char* path = NULL;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, DesiredAccess);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(irp->input, 16); /* AllocationSize(8), FileAttributes(4), SharedAccess(4) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, CreateDisposition);
|
|
|
|
Stream_Read_UINT32(irp->input, CreateOptions);
|
|
|
|
Stream_Read_UINT32(irp->input, PathLength);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input),
|
2012-12-17 08:34:07 +04:00
|
|
|
PathLength / 2, &path, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (status < 1)
|
|
|
|
path = (char*) calloc(1, 1);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
FileId = irp->devman->id_sequence++;
|
2012-04-18 13:52:49 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_file_new(drive->path, path, FileId,
|
2011-08-07 07:21:42 +04:00
|
|
|
DesiredAccess, CreateDisposition, CreateOptions);
|
|
|
|
|
2013-10-18 01:06:51 +04:00
|
|
|
if (!file)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
FileId = 0;
|
|
|
|
Information = 0;
|
|
|
|
}
|
2011-10-19 17:43:04 +04:00
|
|
|
else if (file->err)
|
|
|
|
{
|
|
|
|
FileId = 0;
|
|
|
|
Information = 0;
|
|
|
|
|
2012-10-06 02:30:14 +04:00
|
|
|
/* map errno to windows result */
|
2012-11-03 03:59:07 +04:00
|
|
|
irp->IoStatus = drive_map_posix_err(file->err);
|
|
|
|
drive_file_free(file);
|
2011-10-19 17:43:04 +04:00
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
else
|
|
|
|
{
|
2013-10-18 01:06:51 +04:00
|
|
|
key = (void*) (size_t) file->id;
|
2013-11-04 04:10:33 +04:00
|
|
|
ListDictionary_Add(drive->files, key, file);
|
2013-10-18 01:06:51 +04:00
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
switch (CreateDisposition)
|
|
|
|
{
|
|
|
|
case FILE_SUPERSEDE:
|
|
|
|
case FILE_OPEN:
|
|
|
|
case FILE_CREATE:
|
|
|
|
case FILE_OVERWRITE:
|
|
|
|
Information = FILE_SUPERSEDED;
|
|
|
|
break;
|
|
|
|
case FILE_OPEN_IF:
|
|
|
|
Information = FILE_OPENED;
|
|
|
|
break;
|
|
|
|
case FILE_OVERWRITE_IF:
|
|
|
|
Information = FILE_OVERWRITTEN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Information = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, FileId);
|
|
|
|
Stream_Write_UINT8(irp->output, Information);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(path);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_close(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2013-10-18 01:06:51 +04:00
|
|
|
void* key;
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_get_file_by_id(drive, irp->FileId);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-10-18 01:06:51 +04:00
|
|
|
key = (void*) (size_t) irp->FileId;
|
|
|
|
|
|
|
|
if (!file)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-04 04:10:33 +04:00
|
|
|
ListDictionary_Remove(drive->files, key);
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_file_free(file);
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Zero(irp->output, 5); /* Padding(5) */
|
2011-08-07 11:17:06 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Length;
|
|
|
|
UINT64 Offset;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* buffer = NULL;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, Length);
|
|
|
|
Stream_Read_UINT64(irp->input, Offset);
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_get_file_by_id(drive, irp->FileId);
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-10-18 01:06:51 +04:00
|
|
|
if (!file)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
Length = 0;
|
|
|
|
}
|
2012-11-03 03:59:07 +04:00
|
|
|
else if (!drive_file_seek(file, Offset))
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
Length = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
buffer = (BYTE*) malloc(Length);
|
2013-10-18 01:06:51 +04:00
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
if (!drive_file_read(file, buffer, &Length))
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
2012-10-09 07:21:26 +04:00
|
|
|
free(buffer);
|
2011-08-07 09:11:52 +04:00
|
|
|
buffer = NULL;
|
|
|
|
Length = 0;
|
|
|
|
}
|
2011-08-07 11:17:06 +04:00
|
|
|
else
|
|
|
|
{
|
2013-10-17 23:56:56 +04:00
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
}
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, Length);
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2011-08-07 09:11:52 +04:00
|
|
|
if (Length > 0)
|
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(irp->output, (int) Length);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(irp->output, buffer, Length);
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(buffer);
|
2011-08-07 11:17:06 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_write(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Length;
|
|
|
|
UINT64 Offset;
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, Length);
|
|
|
|
Stream_Read_UINT64(irp->input, Offset);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(irp->input, 20); /* Padding */
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_get_file_by_id(drive, irp->FileId);
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-10-17 23:56:56 +04:00
|
|
|
if (!file)
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
Length = 0;
|
|
|
|
}
|
2012-11-03 03:59:07 +04:00
|
|
|
else if (!drive_file_seek(file, Offset))
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
Length = 0;
|
|
|
|
}
|
2013-04-30 06:35:15 +04:00
|
|
|
else if (!drive_file_write(file, Stream_Pointer(irp->input), Length))
|
2011-08-07 09:11:52 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
Length = 0;
|
|
|
|
}
|
2011-08-07 11:17:06 +04:00
|
|
|
else
|
|
|
|
{
|
2013-10-17 23:56:56 +04:00
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
}
|
2011-08-07 09:11:52 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, Length);
|
|
|
|
Stream_Write_UINT8(irp->output, 0); /* Padding */
|
2011-08-07 11:17:06 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_query_information(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 11:17:06 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 FsInformationClass;
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, FsInformationClass);
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_get_file_by_id(drive, irp->FileId);
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2013-10-17 23:56:56 +04:00
|
|
|
if (!file)
|
2011-08-07 11:17:06 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2012-11-03 03:59:07 +04:00
|
|
|
else if (!drive_file_query_information(file, FsInformationClass, irp->output))
|
2011-08-07 11:17:06 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-17 23:56:56 +04:00
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 FsInformationClass;
|
|
|
|
UINT32 Length;
|
2011-08-07 20:23:36 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, FsInformationClass);
|
|
|
|
Stream_Read_UINT32(irp->input, Length);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(irp->input, 24); /* Padding */
|
2011-08-07 20:23:36 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_get_file_by_id(drive, irp->FileId);
|
2011-08-07 20:23:36 +04:00
|
|
|
|
2013-10-17 23:56:56 +04:00
|
|
|
if (!file)
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2012-11-03 03:59:07 +04:00
|
|
|
else if (!drive_file_set_information(file, FsInformationClass, Length, irp->input))
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-17 23:56:56 +04:00
|
|
|
|
2011-08-07 20:23:36 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 03:19:40 +03:00
|
|
|
if (file && file->is_dir && !dir_empty(file->fullpath))
|
2014-08-18 12:00:34 +04:00
|
|
|
irp->IoStatus = STATUS_DIRECTORY_NOT_EMPTY;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, Length);
|
2011-08-07 20:23:36 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 11:17:06 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 FsInformationClass;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* output = irp->output;
|
2012-04-18 13:52:49 +04:00
|
|
|
struct STATVFS svfst;
|
|
|
|
struct STAT st;
|
2012-09-24 03:49:13 +04:00
|
|
|
char* volumeLabel = {"FREERDP"};
|
2012-09-23 21:54:14 +04:00
|
|
|
char* diskType = {"FAT32"};
|
2013-01-11 00:30:32 +04:00
|
|
|
WCHAR* outStr = NULL;
|
2012-09-24 03:49:13 +04:00
|
|
|
int length;
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, FsInformationClass);
|
2011-08-07 11:17:06 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
STATVFS(drive->path, &svfst);
|
|
|
|
STAT(drive->path, &st);
|
2012-04-18 13:52:49 +04:00
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
switch (FsInformationClass)
|
|
|
|
{
|
|
|
|
case FileFsVolumeInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232108.aspx */
|
2013-10-23 14:16:27 +04:00
|
|
|
length = ConvertToUnicode(sys_code_page, 0, volumeLabel, -1, &outStr, 0) * 2;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 17 + length); /* Length */
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(output, 17 + length);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* VolumeCreationTime */
|
2013-04-25 18:30:33 +04:00
|
|
|
#ifdef ANDROID
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, svfst.f_fsid.__val[0]); /* VolumeSerialNumber */
|
2013-04-25 18:30:33 +04:00
|
|
|
#else
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, svfst.f_fsid); /* VolumeSerialNumber */
|
2013-04-25 18:30:33 +04:00
|
|
|
#endif
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, length); /* VolumeLabelLength */
|
|
|
|
Stream_Write_UINT8(output, 0); /* SupportsObjects */
|
2012-04-18 13:52:49 +04:00
|
|
|
/* Reserved(1), MUST NOT be added! */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(output, outStr, length); /* VolumeLabel (Unicode) */
|
2012-10-09 07:21:26 +04:00
|
|
|
free(outStr);
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsSizeInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232107.aspx */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 24); /* Length */
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(output, 24);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */
|
|
|
|
Stream_Write_UINT64(output, svfst.f_bavail); /* AvailableAllocationUnits */
|
|
|
|
Stream_Write_UINT32(output, 1); /* SectorsPerAllocationUnit */
|
|
|
|
Stream_Write_UINT32(output, svfst.f_bsize); /* BytesPerSector */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsAttributeInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232101.aspx */
|
2013-10-23 14:16:27 +04:00
|
|
|
length = ConvertToUnicode(sys_code_page, 0, diskType, -1, &outStr, 0) * 2;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 12 + length); /* Length */
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(output, 12 + length);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output,
|
2012-04-18 13:52:49 +04:00
|
|
|
FILE_CASE_SENSITIVE_SEARCH |
|
|
|
|
FILE_CASE_PRESERVED_NAMES |
|
2011-08-07 11:17:06 +04:00
|
|
|
FILE_UNICODE_ON_DISK); /* FileSystemAttributes */
|
2013-04-25 18:30:33 +04:00
|
|
|
#ifdef ANDROID
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 255); /* MaximumComponentNameLength */
|
2013-04-25 18:30:33 +04:00
|
|
|
#else
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, svfst.f_namemax/*510*/); /* MaximumComponentNameLength */
|
2013-04-25 18:30:33 +04:00
|
|
|
#endif
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, length); /* FileSystemNameLength */
|
|
|
|
Stream_Write(output, outStr, length); /* FileSystemName (Unicode) */
|
2012-10-09 07:21:26 +04:00
|
|
|
free(outStr);
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsFullSizeInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232104.aspx */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 32); /* Length */
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(output, 32);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */
|
|
|
|
Stream_Write_UINT64(output, svfst.f_bavail); /* CallerAvailableAllocationUnits */
|
|
|
|
Stream_Write_UINT64(output, svfst.f_bfree); /* AvailableAllocationUnits */
|
|
|
|
Stream_Write_UINT32(output, 1); /* SectorsPerAllocationUnit */
|
|
|
|
Stream_Write_UINT32(output, svfst.f_bsize); /* BytesPerSector */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FileFsDeviceInformation:
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc232109.aspx */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 8); /* Length */
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(output, 8);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, FILE_DEVICE_DISK); /* DeviceType */
|
|
|
|
Stream_Write_UINT32(output, 0); /* Characteristics */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
irp->Complete(irp);
|
2011-08-07 09:11:52 +04:00
|
|
|
}
|
|
|
|
|
2013-02-05 16:21:25 +04:00
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc241518.aspx */
|
2013-02-20 03:15:28 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_silent_ignore(DRIVE_DEVICE* drive, IRP* irp)
|
2013-02-05 16:21:25 +04:00
|
|
|
{
|
|
|
|
UINT32 FsInformationClass;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* output = irp->output;
|
2013-02-05 16:21:25 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, FsInformationClass);
|
2013-02-05 16:21:25 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(output, 0); /* Length */
|
2013-02-05 16:21:25 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 15:24:29 +04:00
|
|
|
{
|
2013-01-16 04:14:03 +04:00
|
|
|
char* path = NULL;
|
2012-12-17 08:34:07 +04:00
|
|
|
int status;
|
2012-11-03 03:59:07 +04:00
|
|
|
DRIVE_FILE* file;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE InitialQuery;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 PathLength;
|
|
|
|
UINT32 FsInformationClass;
|
2011-08-07 15:24:29 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(irp->input, FsInformationClass);
|
|
|
|
Stream_Read_UINT8(irp->input, InitialQuery);
|
|
|
|
Stream_Read_UINT32(irp->input, PathLength);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(irp->input, 23); /* Padding */
|
2011-08-07 15:24:29 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input),
|
2012-12-17 08:34:07 +04:00
|
|
|
PathLength / 2, &path, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if (status < 1)
|
|
|
|
path = (char*) calloc(1, 1);
|
2011-08-07 15:24:29 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
file = drive_get_file_by_id(drive, irp->FileId);
|
2011-08-07 15:24:29 +04:00
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, 0); /* Length */
|
2011-08-07 15:24:29 +04:00
|
|
|
}
|
2012-11-03 03:59:07 +04:00
|
|
|
else if (!drive_file_query_directory(file, FsInformationClass, InitialQuery, path, irp->output))
|
2011-08-07 15:24:29 +04:00
|
|
|
{
|
|
|
|
irp->IoStatus = STATUS_NO_MORE_FILES;
|
|
|
|
}
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(path);
|
2011-08-07 15:24:29 +04:00
|
|
|
|
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_directory_control(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 15:24:29 +04:00
|
|
|
{
|
|
|
|
switch (irp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_QUERY_DIRECTORY:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_query_directory(drive, irp);
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: /* TODO */
|
|
|
|
irp->Discard(irp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
irp->IoStatus = STATUS_NOT_SUPPORTED;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, 0); /* Length */
|
2011-08-07 15:24:29 +04:00
|
|
|
irp->Complete(irp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp_device_control(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 20:23:36 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(irp->output, 0); /* OutputBufferLength */
|
2011-08-07 20:23:36 +04:00
|
|
|
irp->Complete(irp);
|
|
|
|
}
|
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
static void drive_process_irp(DRIVE_DEVICE* drive, IRP* irp)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2012-10-07 01:49:56 +04:00
|
|
|
irp->IoStatus = STATUS_SUCCESS;
|
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
switch (irp->MajorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MJ_CREATE:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_create(drive, irp);
|
2011-08-07 07:21:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_CLOSE:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_close(drive, irp);
|
2011-08-07 07:21:42 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 09:11:52 +04:00
|
|
|
case IRP_MJ_READ:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_read(drive, irp);
|
2011-08-07 09:11:52 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MJ_WRITE:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_write(drive, irp);
|
2011-08-07 09:11:52 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
case IRP_MJ_QUERY_INFORMATION:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_query_information(drive, irp);
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 20:23:36 +04:00
|
|
|
case IRP_MJ_SET_INFORMATION:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_set_information(drive, irp);
|
2011-08-07 20:23:36 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 11:17:06 +04:00
|
|
|
case IRP_MJ_QUERY_VOLUME_INFORMATION:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_query_volume_information(drive, irp);
|
2011-08-07 11:17:06 +04:00
|
|
|
break;
|
|
|
|
|
2013-10-17 23:56:56 +04:00
|
|
|
case IRP_MJ_LOCK_CONTROL:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_silent_ignore(drive, irp);
|
2013-02-05 16:21:25 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 15:24:29 +04:00
|
|
|
case IRP_MJ_DIRECTORY_CONTROL:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_directory_control(drive, irp);
|
2011-08-07 15:24:29 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 20:23:36 +04:00
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
2013-11-04 04:10:33 +04:00
|
|
|
drive_process_irp_device_control(drive, irp);
|
2011-08-07 20:23:36 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-07 07:21:42 +04:00
|
|
|
default:
|
|
|
|
irp->IoStatus = STATUS_NOT_SUPPORTED;
|
|
|
|
irp->Complete(irp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static void* drive_thread_func(void* arg)
|
2011-08-07 07:21:42 +04:00
|
|
|
{
|
2014-02-12 07:34:33 +04:00
|
|
|
IRP* irp;
|
|
|
|
wMessage message;
|
|
|
|
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) arg;
|
2013-11-04 04:10:33 +04:00
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (!MessageQueue_Wait(drive->IrpQueue))
|
|
|
|
break;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
if (!MessageQueue_Peek(drive->IrpQueue, &message, TRUE))
|
|
|
|
break;
|
2013-11-04 04:10:33 +04:00
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
irp = (IRP*) message.wParam;
|
2013-11-04 06:01:36 +04:00
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
if (irp)
|
|
|
|
drive_process_irp(drive, irp);
|
|
|
|
}
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
2011-08-07 07:21:42 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static void drive_irp_request(DEVICE* device, IRP* irp)
|
2011-08-05 20:12:16 +04:00
|
|
|
{
|
2013-11-04 04:10:33 +04:00
|
|
|
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
|
2013-11-04 06:01:36 +04:00
|
|
|
MessageQueue_Post(drive->IrpQueue, NULL, 0, (void*) irp, NULL);
|
2011-08-05 20:12:16 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
static void drive_free(DEVICE* device)
|
2011-08-05 20:12:16 +04:00
|
|
|
{
|
2013-11-04 04:10:33 +04:00
|
|
|
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
|
|
|
|
|
2015-05-23 23:47:18 +03:00
|
|
|
if (MessageQueue_PostQuit(drive->IrpQueue, 0))
|
|
|
|
WaitForSingleObject(drive->thread, INFINITE);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
CloseHandle(drive->thread);
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
ListDictionary_Free(drive->files);
|
2014-12-03 22:17:27 +03:00
|
|
|
MessageQueue_Free(drive->IrpQueue);
|
|
|
|
|
|
|
|
Stream_Free(drive->device.data, TRUE);
|
2012-11-18 09:08:03 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
free(drive);
|
2011-08-05 20:12:16 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 03:59:07 +04:00
|
|
|
void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)
|
2011-08-05 20:12:16 +04:00
|
|
|
{
|
2012-10-03 04:17:57 +04:00
|
|
|
int i, length;
|
2013-11-04 04:10:33 +04:00
|
|
|
DRIVE_DEVICE* drive;
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2012-10-02 11:02:17 +04:00
|
|
|
#ifdef WIN32
|
2012-10-02 19:16:40 +04:00
|
|
|
/*
|
|
|
|
* We cannot enter paths like c:\ because : is an arg separator
|
|
|
|
* thus, paths are entered as c+\ and the + is substituted here
|
|
|
|
*/
|
2013-02-15 04:38:45 +04:00
|
|
|
if (path[1] == '+')
|
2012-10-02 11:02:17 +04:00
|
|
|
{
|
2013-02-15 04:38:45 +04:00
|
|
|
if ((path[0]>='a' && path[0]<='z') || (path[0]>='A' && path[0]<='Z'))
|
2012-10-02 11:02:17 +04:00
|
|
|
{
|
|
|
|
path[1] = ':';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-05 20:12:16 +04:00
|
|
|
|
|
|
|
if (name[0] && path[0])
|
|
|
|
{
|
2013-11-04 04:10:33 +04:00
|
|
|
drive = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE));
|
|
|
|
ZeroMemory(drive, sizeof(DRIVE_DEVICE));
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
drive->device.type = RDPDR_DTYP_FILESYSTEM;
|
|
|
|
drive->device.name = name;
|
|
|
|
drive->device.IRPRequest = drive_irp_request;
|
|
|
|
drive->device.Free = drive_free;
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2014-02-10 10:06:11 +04:00
|
|
|
length = (int) strlen(name);
|
2013-11-04 04:10:33 +04:00
|
|
|
drive->device.data = Stream_New(NULL, length + 1);
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2012-09-24 03:49:13 +04:00
|
|
|
for (i = 0; i <= length; i++)
|
2013-11-04 04:10:33 +04:00
|
|
|
Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
drive->path = path;
|
2013-10-18 01:06:51 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
drive->files = ListDictionary_New(TRUE);
|
2014-04-18 20:26:04 +04:00
|
|
|
ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;
|
2011-08-05 20:12:16 +04:00
|
|
|
|
2013-11-12 18:18:18 +04:00
|
|
|
drive->IrpQueue = MessageQueue_New(NULL);
|
2013-11-04 04:10:33 +04:00
|
|
|
drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive);
|
2011-08-07 07:21:42 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
ResumeThread(drive->thread);
|
2011-08-05 20:12:16 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-02 11:02:17 +04:00
|
|
|
|
2012-10-09 06:53:05 +04:00
|
|
|
#ifdef STATIC_CHANNELS
|
2012-11-03 03:59:07 +04:00
|
|
|
#define DeviceServiceEntry drive_DeviceServiceEntry
|
2012-10-02 11:02:17 +04:00
|
|
|
#endif
|
2012-10-08 06:53:24 +04:00
|
|
|
|
2013-10-23 14:16:27 +04:00
|
|
|
UINT sys_code_page = 0;
|
|
|
|
|
2012-11-01 07:04:31 +04:00
|
|
|
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
2012-10-02 11:02:17 +04:00
|
|
|
{
|
2012-11-09 04:01:52 +04:00
|
|
|
RDPDR_DRIVE* drive;
|
2012-10-02 11:02:17 +04:00
|
|
|
#ifdef WIN32
|
2012-10-03 04:17:57 +04:00
|
|
|
char* dev;
|
|
|
|
int len;
|
2012-10-02 11:02:17 +04:00
|
|
|
char devlist[512], buf[512];
|
|
|
|
#endif
|
|
|
|
|
2012-11-09 04:01:52 +04:00
|
|
|
drive = (RDPDR_DRIVE*) pEntryPoints->device;
|
2012-10-02 11:02:17 +04:00
|
|
|
|
|
|
|
#ifndef WIN32
|
2013-02-15 04:38:45 +04:00
|
|
|
|
2013-10-23 14:16:27 +04:00
|
|
|
sys_code_page = CP_UTF8;
|
2013-02-18 15:39:17 +04:00
|
|
|
if (strcmp(drive->Path, "*") == 0)
|
2013-02-15 04:38:45 +04:00
|
|
|
{
|
|
|
|
/* all drives */
|
|
|
|
|
2013-02-18 15:39:17 +04:00
|
|
|
free(drive->Path);
|
|
|
|
drive->Path = _strdup("/");
|
2013-02-15 04:38:45 +04:00
|
|
|
}
|
2013-02-18 15:39:17 +04:00
|
|
|
else if (strcmp(drive->Path, "%") == 0)
|
2013-02-15 04:38:45 +04:00
|
|
|
{
|
|
|
|
char* home_env = NULL;
|
|
|
|
|
|
|
|
/* home directory */
|
|
|
|
|
|
|
|
home_env = getenv("HOME");
|
2013-02-18 15:39:17 +04:00
|
|
|
free(drive->Path);
|
2013-02-15 04:38:45 +04:00
|
|
|
|
|
|
|
if (home_env)
|
2013-02-18 15:39:17 +04:00
|
|
|
drive->Path = _strdup(home_env);
|
2013-02-15 04:38:45 +04:00
|
|
|
else
|
2013-02-18 15:39:17 +04:00
|
|
|
drive->Path = _strdup("/");
|
2013-02-15 04:38:45 +04:00
|
|
|
}
|
|
|
|
|
2014-02-12 07:34:33 +04:00
|
|
|
drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
2013-02-15 04:38:45 +04:00
|
|
|
|
2012-10-02 11:02:17 +04:00
|
|
|
#else
|
2013-10-23 14:16:27 +04:00
|
|
|
sys_code_page = GetACP();
|
2014-02-12 07:34:33 +04:00
|
|
|
/* Special case: path[0] == '*' -> export all drives */
|
2012-10-02 19:11:11 +04:00
|
|
|
/* Special case: path[0] == '%' -> user home dir */
|
2014-02-12 07:34:33 +04:00
|
|
|
if (strcmp(drive->Path, "%") == 0)
|
2012-10-02 11:02:17 +04:00
|
|
|
{
|
|
|
|
_snprintf(buf, sizeof(buf), "%s\\", getenv("USERPROFILE"));
|
2013-02-18 15:39:17 +04:00
|
|
|
drive_register_drive_path(pEntryPoints, drive->Name, _strdup(buf));
|
2012-10-02 11:02:17 +04:00
|
|
|
}
|
2013-02-18 15:39:17 +04:00
|
|
|
else if (strcmp(drive->Path, "*") == 0)
|
2012-10-02 11:02:17 +04:00
|
|
|
{
|
2012-10-02 19:11:11 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Enumerate all devices: */
|
|
|
|
GetLogicalDriveStringsA(sizeof(devlist) - 1, devlist);
|
|
|
|
|
|
|
|
for (dev = devlist, i = 0; *dev; dev += 4, i++)
|
2012-10-02 11:02:17 +04:00
|
|
|
{
|
2012-10-02 19:11:11 +04:00
|
|
|
if (*dev > 'B')
|
2014-02-12 07:34:33 +04:00
|
|
|
{
|
2012-10-02 19:11:11 +04:00
|
|
|
/* Suppress disk drives A and B to avoid pesty messages */
|
2013-11-07 20:43:22 +04:00
|
|
|
len = _snprintf(buf, sizeof(buf) - 4, "%s", drive->Name);
|
2012-10-02 19:11:11 +04:00
|
|
|
buf[len] = '_';
|
|
|
|
buf[len + 1] = dev[0];
|
|
|
|
buf[len + 2] = 0;
|
|
|
|
buf[len + 3] = 0;
|
2012-11-03 03:59:07 +04:00
|
|
|
drive_register_drive_path(pEntryPoints, _strdup(buf), _strdup(dev));
|
2012-10-02 11:02:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-12 07:34:33 +04:00
|
|
|
else
|
|
|
|
{
|
2013-02-18 15:39:17 +04:00
|
|
|
drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
|
2012-10-02 11:02:17 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-02-12 07:34:33 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|