2013-08-19 02:09:12 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Device Redirection Virtual Channel Extension
|
|
|
|
*
|
2014-12-28 05:17:34 +03:00
|
|
|
* Copyright 2014 Dell Software <Mike.McDonald@software.dell.com>
|
2013-08-19 02:09:12 +04:00
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-06-03 14:38:47 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2013-08-19 02:09:12 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2014-12-28 05:17:34 +03:00
|
|
|
#include <winpr/nt.h>
|
2013-08-19 02:09:12 +04:00
|
|
|
#include <winpr/print.h>
|
|
|
|
#include <winpr/stream.h>
|
|
|
|
|
2014-08-11 11:12:01 +04:00
|
|
|
#include <freerdp/channels/log.h>
|
2013-08-19 02:09:12 +04:00
|
|
|
#include "rdpdr_main.h"
|
|
|
|
|
2014-08-18 19:23:03 +04:00
|
|
|
#define TAG "rdpdr.server"
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
static UINT32 g_ClientId = 0;
|
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
static RDPDR_IRP* rdpdr_server_irp_new()
|
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = (RDPDR_IRP*) calloc(1, sizeof(RDPDR_IRP));
|
|
|
|
return irp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpdr_server_irp_free(RDPDR_IRP* irp)
|
|
|
|
{
|
|
|
|
free(irp);
|
|
|
|
}
|
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
static BOOL rdpdr_server_enqueue_irp(RdpdrServerContext* context,
|
|
|
|
RDPDR_IRP* irp)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
return ListDictionary_Add(context->priv->IrpList,
|
|
|
|
(void*)(size_t) irp->CompletionId, irp);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
static RDPDR_IRP* rdpdr_server_dequeue_irp(RdpdrServerContext* context,
|
|
|
|
UINT32 completionId)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
2016-09-26 13:12:37 +03:00
|
|
|
irp = (RDPDR_IRP*) ListDictionary_Remove(context->priv->IrpList,
|
|
|
|
(void*)(size_t) completionId);
|
2014-12-28 05:17:34 +03:00
|
|
|
return irp;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_announce_request(RdpdrServerContext* context)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
wStream* s;
|
2013-08-19 02:09:12 +04:00
|
|
|
BOOL status;
|
|
|
|
RDPDR_HEADER header;
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "RdpdrServerSendAnnounceRequest");
|
2013-08-19 02:09:12 +04:00
|
|
|
header.Component = RDPDR_CTYP_CORE;
|
|
|
|
header.PacketId = PAKID_CORE_SERVER_ANNOUNCE;
|
|
|
|
s = Stream_New(NULL, RDPDR_HEADER_LENGTH + 8);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
context->priv->VersionMajor); /* VersionMajor (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
context->priv->VersionMinor); /* VersionMinor (2 bytes) */
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT32(s, context->priv->ClientId); /* ClientId (4 bytes) */
|
|
|
|
Stream_SealLength(s);
|
2015-04-23 00:33:42 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2015-07-30 16:49:21 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_announce_response(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
UINT32 ClientId;
|
|
|
|
UINT16 VersionMajor;
|
|
|
|
UINT16 VersionMinor;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, VersionMajor); /* VersionMajor (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, VersionMinor); /* VersionMinor (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ClientId); /* ClientId (4 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"Client Announce Response: VersionMajor: 0x%08"PRIX16" VersionMinor: 0x%04"PRIX16" ClientId: 0x%08"PRIX32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
VersionMajor, VersionMinor, ClientId);
|
2013-08-19 04:27:50 +04:00
|
|
|
context->priv->ClientId = ClientId;
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_client_name_request(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
UINT32 UnicodeFlag;
|
|
|
|
UINT32 ComputerNameLen;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT32(s, UnicodeFlag); /* UnicodeFlag (4 bytes) */
|
|
|
|
Stream_Seek_UINT32(s); /* CodePage (4 bytes), MUST be set to zero */
|
|
|
|
Stream_Read_UINT32(s, ComputerNameLen); /* ComputerNameLen (4 bytes) */
|
2017-07-19 10:41:58 +03:00
|
|
|
/* UnicodeFlag is either 0 or 1, the other 31 bits must be ignored.
|
|
|
|
*/
|
|
|
|
UnicodeFlag = UnicodeFlag & 0x00000001;
|
2015-06-03 14:38:47 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
/**
|
|
|
|
* Caution: ComputerNameLen is given *bytes*,
|
|
|
|
* not in characters, including the NULL terminator!
|
|
|
|
*/
|
|
|
|
|
2016-03-03 18:21:12 +03:00
|
|
|
if (UnicodeFlag)
|
|
|
|
{
|
|
|
|
if ((ComputerNameLen % 2) || ComputerNameLen > 512 || ComputerNameLen < 2)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "invalid unicode computer name length: %"PRIu32"", ComputerNameLen);
|
2016-03-03 18:21:12 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ComputerNameLen > 256 || ComputerNameLen < 1)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "invalid ascii computer name length: %"PRIu32"", ComputerNameLen);
|
2016-03-03 18:21:12 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < ComputerNameLen)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ComputerName must be null terminated, check if it really is */
|
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (Stream_Pointer(s)[ComputerNameLen - 1] ||
|
|
|
|
(UnicodeFlag && Stream_Pointer(s)[ComputerNameLen - 2]))
|
2016-03-03 18:21:12 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "computer name must be null terminated");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
2013-08-19 20:21:40 +04:00
|
|
|
if (context->priv->ClientComputerName)
|
|
|
|
{
|
|
|
|
free(context->priv->ClientComputerName);
|
|
|
|
context->priv->ClientComputerName = NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
if (UnicodeFlag)
|
|
|
|
{
|
2016-03-03 18:21:12 +03:00
|
|
|
if (ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), -1,
|
2016-09-26 13:12:37 +03:00
|
|
|
&(context->priv->ClientComputerName), 0, NULL, NULL) < 1)
|
2016-03-03 18:21:12 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to convert client computer name");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
context->priv->ClientComputerName = _strdup((char*) Stream_Pointer(s));
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2016-03-03 18:21:12 +03:00
|
|
|
if (!context->priv->ClientComputerName)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to duplicate client computer name");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Seek(s, ComputerNameLen);
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "ClientComputerName: %s", context->priv->ClientComputerName);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_capability_set_header(wStream* s,
|
|
|
|
RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, header->CapabilityType); /* CapabilityType (2 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Read_UINT16(s,
|
|
|
|
header->CapabilityLength); /* CapabilityLength (2 bytes) */
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT32(s, header->Version); /* Version (4 bytes) */
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_write_capability_set_header(wStream* s,
|
|
|
|
RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-05-21 23:50:29 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 8))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT16(s, header->CapabilityType); /* CapabilityType (2 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
header->CapabilityLength); /* CapabilityLength (2 bytes) */
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT32(s, header->Version); /* Version (4 bytes) */
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_general_capability_set(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
UINT32 ioCode1;
|
|
|
|
UINT32 extraFlags1;
|
|
|
|
UINT32 extendedPdu;
|
|
|
|
UINT16 VersionMajor;
|
|
|
|
UINT16 VersionMinor;
|
|
|
|
UINT32 SpecialTypeDeviceCap;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 32)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Seek_UINT32(s); /* osType (4 bytes), ignored on receipt */
|
|
|
|
Stream_Seek_UINT32(s); /* osVersion (4 bytes), unused and must be set to zero */
|
|
|
|
Stream_Read_UINT16(s, VersionMajor); /* protocolMajorVersion (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, VersionMinor); /* protocolMinorVersion (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, ioCode1); /* ioCode1 (4 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Seek_UINT32(
|
|
|
|
s); /* ioCode2 (4 bytes), must be set to zero, reserved for future use */
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT32(s, extendedPdu); /* extendedPdu (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, extraFlags1); /* extraFlags1 (4 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Seek_UINT32(
|
|
|
|
s); /* extraFlags2 (4 bytes), must be set to zero, reserved for future use */
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2015-04-23 00:33:42 +03:00
|
|
|
if (header->Version == GENERAL_CAPABILITY_VERSION_02)
|
|
|
|
{
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Read_UINT32(s,
|
|
|
|
SpecialTypeDeviceCap); /* SpecialTypeDeviceCap (4 bytes) */
|
2015-04-23 00:33:42 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
context->priv->UserLoggedOnPdu = (extendedPdu & RDPDR_USER_LOGGEDON_PDU) ?
|
|
|
|
TRUE : FALSE;
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_write_general_capability_set(RdpdrServerContext*
|
|
|
|
context, wStream* s)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
UINT32 ioCode1;
|
|
|
|
UINT32 extendedPdu;
|
|
|
|
UINT32 extraFlags1;
|
|
|
|
UINT32 SpecialTypeDeviceCap;
|
|
|
|
RDPDR_CAPABILITY_HEADER header;
|
2015-03-26 19:09:47 +03:00
|
|
|
header.CapabilityType = CAP_GENERAL_TYPE;
|
2013-08-19 02:09:12 +04:00
|
|
|
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH + 36;
|
|
|
|
header.Version = GENERAL_CAPABILITY_VERSION_02;
|
|
|
|
ioCode1 = 0;
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_CREATE; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_CLEANUP; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_CLOSE; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_READ; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_WRITE; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_FLUSH_BUFFERS; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_SHUTDOWN; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_DEVICE_CONTROL; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_QUERY_VOLUME_INFORMATION; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_SET_VOLUME_INFORMATION; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_QUERY_INFORMATION; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_SET_INFORMATION; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_DIRECTORY_CONTROL; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_LOCK_CONTROL; /* always set */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_QUERY_SECURITY; /* optional */
|
|
|
|
ioCode1 |= RDPDR_IRP_MJ_SET_SECURITY; /* optional */
|
|
|
|
extendedPdu = 0;
|
|
|
|
extendedPdu |= RDPDR_CLIENT_DISPLAY_NAME_PDU; /* always set */
|
|
|
|
extendedPdu |= RDPDR_DEVICE_REMOVE_PDUS; /* optional */
|
2013-08-19 04:27:50 +04:00
|
|
|
|
|
|
|
if (context->priv->UserLoggedOnPdu)
|
|
|
|
extendedPdu |= RDPDR_USER_LOGGEDON_PDU; /* optional */
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
extraFlags1 = 0;
|
|
|
|
extraFlags1 |= ENABLE_ASYNCIO; /* optional */
|
|
|
|
SpecialTypeDeviceCap = 0;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, header.CapabilityLength))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
rdpdr_server_write_capability_set_header(s, &header);
|
|
|
|
Stream_Write_UINT32(s, 0); /* osType (4 bytes), ignored on receipt */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
0); /* osVersion (4 bytes), unused and must be set to zero */
|
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
context->priv->VersionMajor); /* protocolMajorVersion (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
context->priv->VersionMinor); /* protocolMinorVersion (2 bytes) */
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT32(s, ioCode1); /* ioCode1 (4 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
0); /* ioCode2 (4 bytes), must be set to zero, reserved for future use */
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT32(s, extendedPdu); /* extendedPdu (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, extraFlags1); /* extraFlags1 (4 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
0); /* extraFlags2 (4 bytes), must be set to zero, reserved for future use */
|
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
SpecialTypeDeviceCap); /* SpecialTypeDeviceCap (4 bytes) */
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_printer_capability_set(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_write_printer_capability_set(RdpdrServerContext*
|
|
|
|
context, wStream* s)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
RDPDR_CAPABILITY_HEADER header;
|
|
|
|
header.CapabilityType = CAP_PRINTER_TYPE;
|
|
|
|
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
|
|
|
|
header.Version = PRINT_CAPABILITY_VERSION_01;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, header.CapabilityLength))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return rdpdr_server_write_capability_set_header(s, &header);
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_port_capability_set(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_write_port_capability_set(RdpdrServerContext* context,
|
|
|
|
wStream* s)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
RDPDR_CAPABILITY_HEADER header;
|
|
|
|
header.CapabilityType = CAP_PORT_TYPE;
|
|
|
|
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
|
|
|
|
header.Version = PORT_CAPABILITY_VERSION_01;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, header.CapabilityLength))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return rdpdr_server_write_capability_set_header(s, &header);
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_drive_capability_set(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_write_drive_capability_set(RdpdrServerContext* context,
|
|
|
|
wStream* s)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
RDPDR_CAPABILITY_HEADER header;
|
|
|
|
header.CapabilityType = CAP_DRIVE_TYPE;
|
|
|
|
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
|
|
|
|
header.Version = DRIVE_CAPABILITY_VERSION_02;
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, header.CapabilityLength))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return rdpdr_server_write_capability_set_header(s, &header);
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_smartcard_capability_set(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_write_smartcard_capability_set(
|
|
|
|
RdpdrServerContext* context, wStream* s)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
RDPDR_CAPABILITY_HEADER header;
|
|
|
|
header.CapabilityType = CAP_SMARTCARD_TYPE;
|
|
|
|
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
|
|
|
|
header.Version = SMARTCARD_CAPABILITY_VERSION_01;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, header.CapabilityLength))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return rdpdr_server_write_capability_set_header(s, &header);
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_send_core_capability_request(RdpdrServerContext*
|
|
|
|
context)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
wStream* s;
|
2013-08-19 02:09:12 +04:00
|
|
|
BOOL status;
|
|
|
|
RDPDR_HEADER header;
|
|
|
|
UINT16 numCapabilities;
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2015-05-21 21:33:38 +03:00
|
|
|
WLog_DBG(TAG, "RdpdrServerSendCoreCapabilityRequest");
|
2013-08-19 02:09:12 +04:00
|
|
|
header.Component = RDPDR_CTYP_CORE;
|
|
|
|
header.PacketId = PAKID_CORE_SERVER_CAPABILITY;
|
2014-12-28 05:17:34 +03:00
|
|
|
numCapabilities = 1;
|
|
|
|
|
|
|
|
if (context->supportsDrives)
|
|
|
|
numCapabilities++;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsPorts)
|
|
|
|
numCapabilities++;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsPrinters)
|
|
|
|
numCapabilities++;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsSmartcards)
|
|
|
|
numCapabilities++;
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
s = Stream_New(NULL, RDPDR_HEADER_LENGTH + 512);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, numCapabilities); /* numCapabilities (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0); /* Padding (2 bytes) */
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_write_general_capability_set(context, s)))
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_write_general_capability_set failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsDrives)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_write_drive_capability_set(context, s)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_write_drive_capability_set failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
2015-05-22 21:14:57 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsPorts)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_write_port_capability_set(context, s)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_write_port_capability_set failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
2015-05-22 21:14:57 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsPrinters)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_write_printer_capability_set(context, s)))
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_write_printer_capability_set failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
2015-05-22 21:14:57 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsSmartcards)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_write_smartcard_capability_set(context, s)))
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_write_printer_capability_set failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_SealLength(s);
|
2014-12-28 05:17:34 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-03-26 19:09:47 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2015-07-30 16:49:21 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_core_capability_response(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
int i;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2013-08-19 02:09:12 +04:00
|
|
|
UINT16 numCapabilities;
|
|
|
|
RDPDR_CAPABILITY_HEADER capabilityHeader;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Read_UINT16(s, numCapabilities); /* numCapabilities (2 bytes) */
|
|
|
|
Stream_Seek_UINT16(s); /* Padding (2 bytes) */
|
|
|
|
|
|
|
|
for (i = 0; i < numCapabilities; i++)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((status = rdpdr_server_read_capability_set_header(s, &capabilityHeader)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_read_capability_set_header failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
status);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status;
|
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
switch (capabilityHeader.CapabilityType)
|
|
|
|
{
|
|
|
|
case CAP_GENERAL_TYPE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((status = rdpdr_server_read_general_capability_set(context, s,
|
|
|
|
&capabilityHeader)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_read_general_capability_set failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
status);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case CAP_PRINTER_TYPE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((status = rdpdr_server_read_printer_capability_set(context, s,
|
|
|
|
&capabilityHeader)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_read_printer_capability_set failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
status);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case CAP_PORT_TYPE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((status = rdpdr_server_read_port_capability_set(context, s,
|
|
|
|
&capabilityHeader)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_read_port_capability_set failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
status);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case CAP_DRIVE_TYPE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((status = rdpdr_server_read_drive_capability_set(context, s,
|
|
|
|
&capabilityHeader)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_read_drive_capability_set failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
status);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case CAP_SMARTCARD_TYPE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((status = rdpdr_server_read_smartcard_capability_set(context, s,
|
|
|
|
&capabilityHeader)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_read_smartcard_capability_set failed with error %"PRIu32"!", status);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "Unknown capabilityType %"PRIu16"", capabilityHeader.CapabilityType);
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Seek(s, capabilityHeader.CapabilityLength -
|
|
|
|
RDPDR_CAPABILITY_HEADER_LENGTH);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_client_id_confirm(RdpdrServerContext* context)
|
2013-08-19 04:27:50 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
wStream* s;
|
2013-08-19 04:27:50 +04:00
|
|
|
BOOL status;
|
|
|
|
RDPDR_HEADER header;
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2015-05-21 21:33:38 +03:00
|
|
|
WLog_DBG(TAG, "RdpdrServerSendClientIdConfirm");
|
2013-08-19 04:27:50 +04:00
|
|
|
header.Component = RDPDR_CTYP_CORE;
|
|
|
|
header.PacketId = PAKID_CORE_CLIENTID_CONFIRM;
|
|
|
|
s = Stream_New(NULL, RDPDR_HEADER_LENGTH + 8);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
context->priv->VersionMajor); /* VersionMajor (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s,
|
|
|
|
context->priv->VersionMinor); /* VersionMinor (2 bytes) */
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Write_UINT32(s, context->priv->ClientId); /* ClientId (4 bytes) */
|
|
|
|
Stream_SealLength(s);
|
2015-04-23 00:33:42 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2015-07-30 16:49:21 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2013-08-19 04:27:50 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_device_list_announce_request(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
|
2013-08-19 04:27:50 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
UINT32 DeviceCount;
|
|
|
|
UINT32 DeviceType;
|
|
|
|
UINT32 DeviceId;
|
|
|
|
char PreferredDosName[9];
|
|
|
|
UINT32 DeviceDataLength;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Read_UINT32(s, DeviceCount); /* DeviceCount (4 bytes) */
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "DeviceCount: %"PRIu32"", DeviceCount);
|
2013-08-19 04:27:50 +04:00
|
|
|
|
|
|
|
for (i = 0; i < DeviceCount; i++)
|
|
|
|
{
|
2014-12-28 05:17:34 +03:00
|
|
|
ZeroMemory(PreferredDosName, sizeof(PreferredDosName));
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 20)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Read_UINT32(s, DeviceType); /* DeviceType (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, DeviceId); /* DeviceId (4 bytes) */
|
|
|
|
Stream_Read(s, PreferredDosName, 8); /* PreferredDosName (8 bytes) */
|
|
|
|
Stream_Read_UINT32(s, DeviceDataLength); /* DeviceDataLength (4 bytes) */
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < DeviceDataLength)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "Device %d Name: %s Id: 0x%08"PRIX32" DataLength: %"PRIu32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
i, PreferredDosName, DeviceId, DeviceDataLength);
|
2013-08-19 04:27:50 +04:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
switch (DeviceType)
|
2013-08-19 04:27:50 +04:00
|
|
|
{
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsDrives)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnDriveCreate, context, DeviceId, PreferredDosName);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
case RDPDR_DTYP_PRINT:
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsPrinters)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnPrinterCreate, context, DeviceId, PreferredDosName);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
case RDPDR_DTYP_SERIAL:
|
2014-12-28 05:17:34 +03:00
|
|
|
case RDPDR_DTYP_PARALLEL:
|
|
|
|
if (context->supportsPorts)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnPortCreate, context, DeviceId, PreferredDosName);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
|
|
|
if (context->supportsSmartcards)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnSmartcardCreate, context, DeviceId, PreferredDosName);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Seek(s, DeviceDataLength);
|
|
|
|
}
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_device_list_remove_request(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
UINT32 DeviceCount;
|
|
|
|
UINT32 DeviceType;
|
|
|
|
UINT32 DeviceId;
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, DeviceCount); /* DeviceCount (4 bytes) */
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "DeviceCount: %"PRIu32"", DeviceCount);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
for (i = 0; i < DeviceCount; i++)
|
|
|
|
{
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, DeviceId); /* DeviceId (4 bytes) */
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "Device %d Id: 0x%08"PRIX32"", i, DeviceId);
|
2014-12-28 05:17:34 +03:00
|
|
|
DeviceType = 0; /* TODO: Save the device type on the announce request. */
|
|
|
|
|
|
|
|
switch (DeviceType)
|
|
|
|
{
|
|
|
|
case RDPDR_DTYP_FILESYSTEM:
|
|
|
|
if (context->supportsDrives)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnDriveDelete, context, DeviceId);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
case RDPDR_DTYP_PRINT:
|
|
|
|
if (context->supportsPrinters)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnPrinterDelete, context, DeviceId);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RDPDR_DTYP_SERIAL:
|
2013-08-19 04:27:50 +04:00
|
|
|
case RDPDR_DTYP_PARALLEL:
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsPorts)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnPortDelete, context, DeviceId);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
case RDPDR_DTYP_SMARTCARD:
|
2014-12-28 05:17:34 +03:00
|
|
|
if (context->supportsSmartcards)
|
|
|
|
{
|
|
|
|
IFCALL(context->OnSmartcardDelete, context, DeviceId);
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
2013-08-19 04:27:50 +04:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_device_io_completion(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_HEADER* header)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 deviceId;
|
|
|
|
UINT32 completionId;
|
|
|
|
UINT32 ioStatus;
|
|
|
|
RDPDR_IRP* irp;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, deviceId);
|
|
|
|
Stream_Read_UINT32(s, completionId);
|
|
|
|
Stream_Read_UINT32(s, ioStatus);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "deviceId=%"PRIu32", completionId=0x%"PRIx32", ioStatus=0x%"PRIx32"", deviceId,
|
2016-09-26 13:12:37 +03:00
|
|
|
completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
irp = rdpdr_server_dequeue_irp(context, completionId);
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "IRP not found for completionId=0x%"PRIx32"", completionId);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Invoke the callback. */
|
|
|
|
if (irp->Callback)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
error = (*irp->Callback)(context, s, irp, deviceId, completionId, ioStatus);
|
2013-08-19 04:27:50 +04:00
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
2013-08-19 04:27:50 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_user_logged_on(RdpdrServerContext* context)
|
2013-08-19 04:27:50 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
wStream* s;
|
2013-08-19 04:27:50 +04:00
|
|
|
BOOL status;
|
|
|
|
RDPDR_HEADER header;
|
2014-05-28 19:04:24 +04:00
|
|
|
ULONG written;
|
2015-05-21 21:33:38 +03:00
|
|
|
WLog_DBG(TAG, "RdpdrServerSendUserLoggedOn");
|
2013-08-19 04:27:50 +04:00
|
|
|
header.Component = RDPDR_CTYP_CORE;
|
|
|
|
header.PacketId = PAKID_CORE_USER_LOGGEDON;
|
|
|
|
s = Stream_New(NULL, RDPDR_HEADER_LENGTH);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
|
|
|
|
Stream_SealLength(s);
|
2015-04-23 00:33:42 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2013-08-19 04:27:50 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2015-07-30 16:49:21 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2013-08-19 04:27:50 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_receive_pdu(RdpdrServerContext* context, wStream* s,
|
|
|
|
RDPDR_HEADER* header)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "RdpdrServerReceivePdu: Component: 0x%04"PRIX16" PacketId: 0x%04"PRIX16"",
|
2016-09-26 13:12:37 +03:00
|
|
|
header->Component, header->PacketId);
|
2014-08-18 19:23:03 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
if (header->Component == RDPDR_CTYP_CORE)
|
|
|
|
{
|
|
|
|
switch (header->PacketId)
|
|
|
|
{
|
|
|
|
case PAKID_CORE_CLIENTID_CONFIRM:
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_receive_announce_response(context, s, header)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_receive_announce_response failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_CLIENT_NAME:
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_receive_client_name_request(context, s, header)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_receive_client_name_request failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((error = rdpdr_server_send_core_capability_request(context)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_send_core_capability_request failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_send_client_id_confirm(context)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_send_client_id_confirm failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_CLIENT_CAPABILITY:
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_receive_core_capability_response(context, s, header)))
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_receive_core_capability_response failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2013-08-19 04:27:50 +04:00
|
|
|
|
|
|
|
if (context->priv->UserLoggedOnPdu)
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((error = rdpdr_server_send_user_logged_on(context)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_send_user_logged_on failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2014-08-18 19:23:03 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_DEVICELIST_ANNOUNCE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((error = rdpdr_server_receive_device_list_announce_request(context, s,
|
|
|
|
header)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_receive_device_list_announce_request failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_DEVICE_REPLY:
|
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_DEVICE_IOREQUEST:
|
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_DEVICE_IOCOMPLETION:
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_receive_device_io_completion(context, s, header)))
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_receive_device_io_completion failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_CORE_DEVICELIST_REMOVE:
|
2016-09-26 13:12:37 +03:00
|
|
|
if ((error = rdpdr_server_receive_device_list_remove_request(context, s,
|
|
|
|
header)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_receive_device_io_completion failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (header->Component == RDPDR_CTYP_PRN)
|
|
|
|
{
|
|
|
|
switch (header->PacketId)
|
|
|
|
{
|
|
|
|
case PAKID_PRN_CACHE_DATA:
|
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
case PAKID_PRN_USING_XPS:
|
|
|
|
break;
|
2014-08-18 21:34:47 +04:00
|
|
|
|
2013-08-19 02:09:12 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_WARN(TAG, "Unknown RDPDR_HEADER.Component: 0x%04"PRIX16"", header->Component);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
static void* rdpdr_server_thread(void* arg)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
wStream* s;
|
2013-08-19 02:09:12 +04:00
|
|
|
DWORD status;
|
|
|
|
DWORD nCount;
|
2014-08-18 21:34:47 +04:00
|
|
|
void* buffer;
|
2013-08-19 02:09:12 +04:00
|
|
|
HANDLE events[8];
|
|
|
|
RDPDR_HEADER header;
|
|
|
|
HANDLE ChannelEvent;
|
2013-08-21 02:06:19 +04:00
|
|
|
DWORD BytesReturned;
|
2014-08-18 21:34:47 +04:00
|
|
|
RdpdrServerContext* context;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-08-18 21:34:47 +04:00
|
|
|
context = (RdpdrServerContext*) arg;
|
2013-08-19 02:09:12 +04:00
|
|
|
buffer = NULL;
|
|
|
|
BytesReturned = 0;
|
|
|
|
ChannelEvent = NULL;
|
|
|
|
s = Stream_New(NULL, 4096);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
2015-07-15 10:50:35 +03:00
|
|
|
error = CHANNEL_RC_NO_MEMORY;
|
|
|
|
goto out;
|
2015-06-03 14:38:47 +03:00
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle,
|
|
|
|
&buffer, &BytesReturned) == TRUE)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
if (BytesReturned == sizeof(HANDLE))
|
|
|
|
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
|
|
|
|
|
|
|
|
WTSFreeMemory(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
nCount = 0;
|
|
|
|
events[nCount++] = ChannelEvent;
|
|
|
|
events[nCount++] = context->priv->StopEvent;
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_send_announce_request(context)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_send_announce_request failed with error %"PRIu32"!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-07-15 10:50:35 +03:00
|
|
|
goto out_stream;
|
2015-06-03 14:38:47 +03:00
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2013-08-19 20:21:40 +04:00
|
|
|
BytesReturned = 0;
|
2013-08-19 02:09:12 +04:00
|
|
|
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
|
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %"PRIu32"!", error);
|
2016-09-26 13:12:37 +03:00
|
|
|
goto out_stream;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WaitForSingleObject(context->priv->StopEvent, 0);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
error = GetLastError();
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", error);
|
2016-09-26 13:12:37 +03:00
|
|
|
goto out_stream;
|
|
|
|
}
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
if (status == WAIT_OBJECT_0)
|
2013-08-19 02:09:12 +04:00
|
|
|
break;
|
|
|
|
|
2014-07-14 16:00:38 +04:00
|
|
|
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
|
2016-09-26 13:12:37 +03:00
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
|
2015-07-15 10:50:35 +03:00
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2014-07-14 16:00:38 +04:00
|
|
|
break;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (BytesReturned >= RDPDR_HEADER_LENGTH)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
Stream_SetPosition(s, 0);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_SetLength(s, BytesReturned);
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
while (Stream_GetRemainingLength(s) >= RDPDR_HEADER_LENGTH)
|
|
|
|
{
|
|
|
|
Stream_Read_UINT16(s, header.Component); /* Component (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
|
2015-05-22 21:14:57 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_receive_pdu(context, s, &header)))
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_receive_pdu failed with error %"PRIu32"!", error);
|
2015-07-15 10:50:35 +03:00
|
|
|
goto out_stream;
|
2015-06-03 14:38:47 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
out_stream:
|
2013-08-19 02:09:12 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2015-07-15 10:50:35 +03:00
|
|
|
out:
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && context->rdpcontext)
|
2016-09-26 13:12:37 +03:00
|
|
|
setChannelError(context->rdpcontext, error,
|
|
|
|
"rdpdr_server_thread reported an error");
|
2015-07-15 10:50:35 +03:00
|
|
|
|
|
|
|
ExitThread((DWORD) error);
|
2013-08-19 02:09:12 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_start(RdpdrServerContext* context)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm,
|
|
|
|
WTS_CURRENT_SESSION, "rdpdr");
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
if (!context->priv->ChannelHandle)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelOpen failed!");
|
|
|
|
return CHANNEL_RC_BAD_CHANNEL;
|
|
|
|
}
|
2015-05-21 23:50:29 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!(context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CreateEvent failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!(context->priv->Thread = CreateThread(NULL, 0,
|
2016-09-26 13:12:37 +03:00
|
|
|
(LPTHREAD_START_ROUTINE) rdpdr_server_thread, (void*) context, 0, NULL)))
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CreateThread failed!");
|
|
|
|
CloseHandle(context->priv->StopEvent);
|
|
|
|
context->priv->StopEvent = NULL;
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_stop(RdpdrServerContext* context)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
UINT error;
|
|
|
|
|
2015-05-21 23:50:29 +03:00
|
|
|
if (context->priv->StopEvent)
|
|
|
|
{
|
|
|
|
SetEvent(context->priv->StopEvent);
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2015-07-30 16:49:21 +03:00
|
|
|
if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
|
2016-09-26 13:12:37 +03:00
|
|
|
{
|
|
|
|
error = GetLastError();
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", error);
|
2016-09-26 13:12:37 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:50:29 +03:00
|
|
|
CloseHandle(context->priv->Thread);
|
|
|
|
context->priv->Thread = NULL;
|
|
|
|
CloseHandle(context->priv->StopEvent);
|
|
|
|
context->priv->StopEvent = NULL;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
static void rdpdr_server_write_device_iorequest(
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 fileId,
|
|
|
|
UINT32 completionId,
|
|
|
|
UINT32 majorFunction,
|
|
|
|
UINT32 minorFunction)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Write_UINT16(s, RDPDR_CTYP_CORE); /* Component (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, PAKID_CORE_DEVICE_IOREQUEST); /* PacketId (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, deviceId); /* DeviceId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, fileId); /* FileId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, completionId); /* CompletionId (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, majorFunction); /* MajorFunction (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, minorFunction); /* MinorFunction (4 bytes) */
|
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_read_file_directory_information(wStream* s,
|
|
|
|
FILE_DIRECTORY_INFORMATION* fdi)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 fileNameLength;
|
|
|
|
ZeroMemory(fdi, sizeof(FILE_DIRECTORY_INFORMATION));
|
2013-08-19 02:09:12 +04:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 64)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, fdi->NextEntryOffset); /* NextEntryOffset (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, fdi->FileIndex); /* FileIndex (4 bytes) */
|
|
|
|
Stream_Read_UINT64(s, fdi->CreationTime); /* CreationTime (8 bytes) */
|
|
|
|
Stream_Read_UINT64(s, fdi->LastAccessTime); /* LastAccessTime (8 bytes) */
|
|
|
|
Stream_Read_UINT64(s, fdi->LastWriteTime); /* LastWriteTime (8 bytes) */
|
|
|
|
Stream_Read_UINT64(s, fdi->ChangeTime); /* ChangeTime (8 bytes) */
|
|
|
|
Stream_Read_UINT64(s, fdi->EndOfFile); /* EndOfFile (8 bytes) */
|
|
|
|
Stream_Read_UINT64(s, fdi->AllocationSize); /* AllocationSize (8 bytes) */
|
|
|
|
Stream_Read_UINT32(s, fdi->FileAttributes); /* FileAttributes (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, fileNameLength); /* FileNameLength (4 bytes) */
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < fileNameLength)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) Stream_Pointer(s), fileNameLength / 2,
|
|
|
|
fdi->FileName, sizeof(fdi->FileName), NULL, NULL);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Seek(s, fileNameLength);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_device_create_request(
|
2016-09-26 13:12:37 +03:00
|
|
|
RdpdrServerContext* context,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 completionId,
|
|
|
|
const char* path,
|
|
|
|
UINT32 desiredAccess,
|
|
|
|
UINT32 createOptions,
|
|
|
|
UINT32 createDisposition)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
UINT32 pathLength;
|
2014-12-28 05:17:34 +03:00
|
|
|
ULONG written;
|
|
|
|
BOOL status;
|
|
|
|
wStream* s;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerSendDeviceCreateRequest: deviceId=%"PRIu32", path=%s, desiredAccess=0x%"PRIx32" createOptions=0x%"PRIx32" createDisposition=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, path, desiredAccess, createOptions, createDisposition);
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Compute the required Unicode size. */
|
2014-12-28 05:17:34 +03:00
|
|
|
pathLength = (strlen(path) + 1) * sizeof(WCHAR);
|
|
|
|
s = Stream_New(NULL, 256 + pathLength);
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpdr_server_write_device_iorequest(s, deviceId, 0, completionId, IRP_MJ_CREATE,
|
|
|
|
0);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Write_UINT32(s, desiredAccess); /* DesiredAccess (4 bytes) */
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Write_UINT32(s, 0); /* AllocationSize (8 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0);
|
|
|
|
Stream_Write_UINT32(s, 0); /* FileAttributes (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 3); /* SharedAccess (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, createDisposition); /* CreateDisposition (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, createOptions); /* CreateOptions (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pathLength); /* PathLength (4 bytes) */
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Convert the path to Unicode. */
|
2016-09-26 13:12:37 +03:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s),
|
|
|
|
pathLength);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Seek(s, pathLength);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_SealLength(s);
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_device_close_request(
|
2016-09-26 13:12:37 +03:00
|
|
|
RdpdrServerContext* context,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 fileId,
|
|
|
|
UINT32 completionId)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
ULONG written;
|
|
|
|
BOOL status;
|
|
|
|
wStream* s;
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "RdpdrServerSendDeviceCloseRequest: deviceId=%"PRIu32", fileId=%"PRIu32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, fileId);
|
2014-12-28 05:17:34 +03:00
|
|
|
s = Stream_New(NULL, 128);
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
|
|
|
|
IRP_MJ_CLOSE, 0);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Zero(s, 32); /* Padding (32 bytes) */
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_SealLength(s);
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_device_read_request(
|
2016-09-26 13:12:37 +03:00
|
|
|
RdpdrServerContext* context,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 fileId,
|
|
|
|
UINT32 completionId,
|
|
|
|
UINT32 length,
|
|
|
|
UINT32 offset)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
ULONG written;
|
|
|
|
BOOL status;
|
|
|
|
wStream* s;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerSendDeviceReadRequest: deviceId=%"PRIu32", fileId=%"PRIu32", length=%"PRIu32", offset=%"PRIu32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, fileId, length, offset);
|
2014-12-28 05:17:34 +03:00
|
|
|
s = Stream_New(NULL, 128);
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
|
|
|
|
IRP_MJ_READ, 0);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Write_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, offset); /* Offset (8 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0);
|
|
|
|
Stream_Zero(s, 20); /* Padding (20 bytes) */
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_SealLength(s);
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_device_write_request(
|
2016-09-26 13:12:37 +03:00
|
|
|
RdpdrServerContext* context,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 fileId,
|
|
|
|
UINT32 completionId,
|
|
|
|
const char* data,
|
|
|
|
UINT32 length,
|
|
|
|
UINT32 offset)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
ULONG written;
|
|
|
|
BOOL status;
|
|
|
|
wStream* s;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerSendDeviceWriteRequest: deviceId=%"PRIu32", fileId=%"PRIu32", length=%"PRIu32", offset=%"PRIu32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, fileId, length, offset);
|
2014-12-28 05:17:34 +03:00
|
|
|
s = Stream_New(NULL, 64 + length);
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
|
|
|
|
IRP_MJ_WRITE, 0);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Write_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, offset); /* Offset (8 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0);
|
|
|
|
Stream_Zero(s, 20); /* Padding (20 bytes) */
|
|
|
|
Stream_Write(s, data, length); /* WriteData (variable) */
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_SealLength(s);
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_device_query_directory_request(
|
2016-09-26 13:12:37 +03:00
|
|
|
RdpdrServerContext* context,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 fileId,
|
|
|
|
UINT32 completionId,
|
|
|
|
const char* path)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
UINT32 pathLength;
|
2014-12-28 05:17:34 +03:00
|
|
|
ULONG written;
|
|
|
|
BOOL status;
|
|
|
|
wStream* s;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerSendDeviceQueryDirectoryRequest: deviceId=%"PRIu32", fileId=%"PRIu32", path=%s",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, fileId, path);
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Compute the required Unicode size. */
|
2014-12-28 05:17:34 +03:00
|
|
|
pathLength = path ? (strlen(path) + 1) * sizeof(WCHAR) : 0;
|
|
|
|
s = Stream_New(NULL, 64 + pathLength);
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
|
|
|
|
IRP_MJ_DIRECTORY_CONTROL, IRP_MN_QUERY_DIRECTORY);
|
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
FileDirectoryInformation); /* FsInformationClass (4 bytes) */
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Write_UINT8(s, path ? 1 : 0); /* InitialQuery (1 byte) */
|
|
|
|
Stream_Write_UINT32(s, pathLength); /* PathLength (4 bytes) */
|
|
|
|
Stream_Zero(s, 23); /* Padding (23 bytes) */
|
|
|
|
|
|
|
|
/* Convert the path to Unicode. */
|
|
|
|
if (pathLength > 0)
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s),
|
|
|
|
pathLength);
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Seek(s, pathLength);
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_SealLength(s);
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2016-09-26 13:12:37 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT rdpdr_server_send_device_file_rename_request(
|
2016-09-26 13:12:37 +03:00
|
|
|
RdpdrServerContext* context,
|
|
|
|
UINT32 deviceId,
|
|
|
|
UINT32 fileId,
|
|
|
|
UINT32 completionId,
|
|
|
|
const char* path)
|
2014-12-31 02:41:21 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
UINT32 pathLength;
|
2014-12-31 02:41:21 +03:00
|
|
|
ULONG written;
|
|
|
|
BOOL status;
|
|
|
|
wStream* s;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerSendDeviceFileNameRequest: deviceId=%"PRIu32", fileId=%"PRIu32", path=%s",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, fileId, path);
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Compute the required Unicode size. */
|
|
|
|
pathLength = path ? (strlen(path) + 1) * sizeof(WCHAR) : 0;
|
|
|
|
s = Stream_New(NULL, 64 + pathLength);
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
if (!s)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2015-05-21 21:33:38 +03:00
|
|
|
|
2016-09-26 13:12:37 +03:00
|
|
|
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
|
|
|
|
IRP_MJ_SET_INFORMATION, 0);
|
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
FileRenameInformation); /* FsInformationClass (4 bytes) */
|
2014-12-31 02:41:21 +03:00
|
|
|
Stream_Write_UINT32(s, pathLength + 6); /* Length (4 bytes) */
|
|
|
|
Stream_Zero(s, 24); /* Padding (24 bytes) */
|
|
|
|
/* RDP_FILE_RENAME_INFORMATION */
|
|
|
|
Stream_Write_UINT8(s, 0); /* ReplaceIfExists (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* RootDirectory (1 byte) */
|
|
|
|
Stream_Write_UINT32(s, pathLength); /* FileNameLength (4 bytes) */
|
|
|
|
|
|
|
|
/* Convert the path to Unicode. */
|
|
|
|
if (pathLength > 0)
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s),
|
|
|
|
pathLength);
|
2014-12-31 02:41:21 +03:00
|
|
|
Stream_Seek(s, pathLength);
|
|
|
|
}
|
|
|
|
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_SealLength(s);
|
2016-09-26 13:12:37 +03:00
|
|
|
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
|
|
|
|
(PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
|
2015-05-21 21:33:38 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2015-06-03 14:38:47 +03:00
|
|
|
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
static void rdpdr_server_convert_slashes(char* path, int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; (i < size) && (path[i] != '\0'); i++)
|
|
|
|
{
|
|
|
|
if (path[i] == '/')
|
|
|
|
path[i] = '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Create Directory
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_create_directory_callback2(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
|
|
|
|
UINT32 completionId, UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveCreateDirectoryCallback2: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Invoke the create directory completion routine. */
|
|
|
|
context->OnDriveCreateDirectoryComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_create_directory_callback1(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
|
|
|
|
UINT32 completionId, UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 fileId;
|
|
|
|
UINT8 information;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveCreateDirectoryCallback1: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
if (ioStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Invoke the create directory completion routine. */
|
|
|
|
context->OnDriveCreateDirectoryComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
|
|
|
|
Stream_Read_UINT8(s, information); /* Information (1 byte) */
|
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_create_directory_callback2;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to close the file */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_close_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_create_directory(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, const char* path)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_create_directory_callback1;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
strncpy(irp->PathName, path, sizeof(irp->PathName));
|
|
|
|
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the file. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_create_request(context, deviceId,
|
|
|
|
irp->CompletionId, irp->PathName,
|
|
|
|
FILE_READ_DATA | SYNCHRONIZE,
|
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_CREATE);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Delete Directory
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_delete_directory_callback2(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
|
|
|
|
UINT32 completionId, UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveDeleteDirectoryCallback2: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Invoke the delete directory completion routine. */
|
|
|
|
context->OnDriveDeleteDirectoryComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_delete_directory_callback1(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
|
|
|
|
UINT32 completionId, UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 fileId;
|
|
|
|
UINT8 information;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveDeleteDirectoryCallback1: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
if (ioStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Invoke the delete directory completion routine. */
|
|
|
|
context->OnDriveDeleteFileComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
|
|
|
|
Stream_Read_UINT8(s, information); /* Information (1 byte) */
|
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_delete_directory_callback2;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to close the file */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_close_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_delete_directory(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, const char* path)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_delete_directory_callback1;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
strncpy(irp->PathName, path, sizeof(irp->PathName));
|
|
|
|
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the file. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_create_request(context, deviceId,
|
|
|
|
irp->CompletionId, irp->PathName,
|
|
|
|
DELETE | SYNCHRONIZE, FILE_DIRECTORY_FILE | FILE_DELETE_ON_CLOSE |
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Query Directory
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_query_directory_callback2(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
|
|
|
|
UINT32 completionId, UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-12-28 05:17:34 +03:00
|
|
|
UINT32 length;
|
2015-05-21 23:08:46 +03:00
|
|
|
FILE_DIRECTORY_INFORMATION fdi;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveQueryDirectoryCallback2: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
if (length > 0)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
if ((error = rdpdr_server_read_file_directory_information(s, &fdi)))
|
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"rdpdr_server_read_file_directory_information failed with error %"PRIu32"!", error);
|
2015-06-03 14:38:47 +03:00
|
|
|
return error;
|
|
|
|
}
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
Stream_Seek(s, 1); /* Padding (1 byte) */
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
if (ioStatus == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Invoke the query directory completion routine. */
|
2016-09-26 13:12:37 +03:00
|
|
|
context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus,
|
|
|
|
length > 0 ? &fdi : NULL);
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_query_directory_callback2;
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Send a request to query the directory. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_query_directory_request(context, irp->DeviceId,
|
|
|
|
irp->FileId, irp->CompletionId, NULL);
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Invoke the query directory completion routine. */
|
2016-09-26 13:12:37 +03:00
|
|
|
context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus,
|
|
|
|
NULL);
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_query_directory_callback1(
|
|
|
|
RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
|
|
|
|
UINT32 completionId, UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 fileId;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveQueryDirectoryCallback1: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
if (ioStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Invoke the query directory completion routine. */
|
2016-09-26 13:12:37 +03:00
|
|
|
context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus,
|
|
|
|
NULL);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, fileId);
|
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_query_directory_callback2;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
strcat(irp->PathName, "\\*.*");
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Send a request to query the directory. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_query_directory_request(context, deviceId,
|
|
|
|
fileId, irp->CompletionId, irp->PathName);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_query_directory(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, const char* path)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_query_directory_callback1;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
strncpy(irp->PathName, path, sizeof(irp->PathName));
|
|
|
|
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the directory. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_create_request(context, deviceId,
|
|
|
|
irp->CompletionId, irp->PathName,
|
|
|
|
FILE_READ_DATA | SYNCHRONIZE,
|
|
|
|
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Open File
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_open_file_callback(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 fileId;
|
|
|
|
UINT8 information;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveOpenFileCallback: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
|
|
|
|
Stream_Read_UINT8(s, information); /* Information (1 byte) */
|
|
|
|
/* Invoke the open file completion routine. */
|
2016-09-26 13:12:37 +03:00
|
|
|
context->OnDriveOpenFileComplete(context, irp->CallbackData, ioStatus, deviceId,
|
|
|
|
fileId);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_open_file(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, const char* path, UINT32 desiredAccess,
|
|
|
|
UINT32 createDisposition)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_open_file_callback;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
strncpy(irp->PathName, path, sizeof(irp->PathName));
|
|
|
|
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the file. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_create_request(context, deviceId,
|
|
|
|
irp->CompletionId, irp->PathName,
|
|
|
|
desiredAccess | SYNCHRONIZE, FILE_SYNCHRONOUS_IO_NONALERT, createDisposition);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Read File
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_read_file_callback(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 length;
|
|
|
|
char* buffer = NULL;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveReadFileCallback: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
2015-05-21 23:08:46 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < length)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
if (length > 0)
|
|
|
|
{
|
|
|
|
buffer = (char*) Stream_Pointer(s);
|
|
|
|
Stream_Seek(s, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invoke the read file completion routine. */
|
2016-09-26 13:12:37 +03:00
|
|
|
context->OnDriveReadFileComplete(context, irp->CallbackData, ioStatus, buffer,
|
|
|
|
length);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_read_file(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, UINT32 fileId, UINT32 length,
|
|
|
|
UINT32 offset)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_read_file_callback;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the directory. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_read_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId, length, offset);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Write File
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_write_file_callback(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 length;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveWriteFileCallback: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
Stream_Seek(s, 1); /* Padding (1 byte) */
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < length)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Invoke the write file completion routine. */
|
|
|
|
context->OnDriveWriteFileComplete(context, irp->CallbackData, ioStatus, length);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_write_file(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, UINT32 fileId, const char* buffer,
|
|
|
|
UINT32 length, UINT32 offset)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_write_file_callback;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the directory. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_write_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId, buffer, length, offset);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Close File
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_close_file_callback(RdpdrServerContext* context,
|
|
|
|
wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveCloseFileCallback: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Invoke the close file completion routine. */
|
|
|
|
context->OnDriveCloseFileComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_close_file(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, UINT32 fileId)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_close_file_callback;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the directory. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_close_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
* Drive Delete File
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_delete_file_callback2(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveDeleteFileCallback2: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
/* Invoke the delete file completion routine. */
|
|
|
|
context->OnDriveDeleteFileComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_delete_file_callback1(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
UINT32 fileId;
|
|
|
|
UINT8 information;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveDeleteFileCallback1: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
if (ioStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Invoke the close file completion routine. */
|
|
|
|
context->OnDriveDeleteFileComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-28 05:17:34 +03:00
|
|
|
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
|
|
|
|
Stream_Read_UINT8(s, information); /* Information (1 byte) */
|
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_delete_file_callback2;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to close the file */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_close_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_delete_file(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, const char* path)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_delete_file_callback1;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
strncpy(irp->PathName, path, sizeof(irp->PathName));
|
|
|
|
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
|
|
|
/* Send a request to open the file. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_create_request(context, deviceId,
|
|
|
|
irp->CompletionId, irp->PathName,
|
|
|
|
FILE_READ_DATA | SYNCHRONIZE,
|
|
|
|
FILE_DELETE_ON_CLOSE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
/*************************************************
|
|
|
|
* Drive Rename File
|
|
|
|
************************************************/
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_rename_file_callback3(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-31 02:41:21 +03:00
|
|
|
{
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveRenameFileCallback3: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-31 02:41:21 +03:00
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_rename_file_callback2(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-31 02:41:21 +03:00
|
|
|
{
|
|
|
|
UINT32 length;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveRenameFileCallback2: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-31 02:41:21 +03:00
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
|
|
|
|
Stream_Seek(s, 1); /* Padding (1 byte) */
|
|
|
|
/* Invoke the rename file completion routine. */
|
|
|
|
context->OnDriveRenameFileComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_rename_file_callback3;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-31 02:41:21 +03:00
|
|
|
|
|
|
|
/* Send a request to close the file */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_close_request(context, deviceId, irp->FileId,
|
|
|
|
irp->CompletionId);
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_rename_file_callback1(RdpdrServerContext*
|
|
|
|
context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
|
|
|
|
UINT32 ioStatus)
|
2014-12-31 02:41:21 +03:00
|
|
|
{
|
|
|
|
UINT32 fileId;
|
|
|
|
UINT8 information;
|
2016-09-26 13:12:37 +03:00
|
|
|
WLog_DBG(TAG,
|
2016-12-14 00:47:08 +03:00
|
|
|
"RdpdrServerDriveRenameFileCallback1: deviceId=%"PRIu32", completionId=%"PRIu32", ioStatus=0x%"PRIx32"",
|
2016-09-26 13:12:37 +03:00
|
|
|
deviceId, completionId, ioStatus);
|
2014-12-31 02:41:21 +03:00
|
|
|
|
|
|
|
if (ioStatus != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Invoke the rename file completion routine. */
|
|
|
|
context->OnDriveRenameFileComplete(context, irp->CallbackData, ioStatus);
|
|
|
|
/* Destroy the IRP. */
|
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:08:46 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "not enough data in stream!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2015-05-21 23:08:46 +03:00
|
|
|
|
2014-12-31 02:41:21 +03:00
|
|
|
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
|
|
|
|
Stream_Read_UINT8(s, information); /* Information (1 byte) */
|
|
|
|
/* Setup the IRP. */
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_rename_file_callback2;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
irp->FileId = fileId;
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-31 02:41:21 +03:00
|
|
|
|
|
|
|
/* Send a request to rename the file */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_file_rename_request(context, deviceId, fileId,
|
|
|
|
irp->CompletionId, irp->ExtraBuffer);
|
2014-12-31 02:41:21 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-09-26 13:12:37 +03:00
|
|
|
static UINT rdpdr_server_drive_rename_file(RdpdrServerContext* context,
|
|
|
|
void* callbackData, UINT32 deviceId, const char* oldPath, const char* newPath)
|
2014-12-28 05:17:34 +03:00
|
|
|
{
|
2014-12-31 02:41:21 +03:00
|
|
|
RDPDR_IRP* irp;
|
|
|
|
irp = rdpdr_server_irp_new();
|
2015-05-21 21:33:38 +03:00
|
|
|
|
|
|
|
if (!irp)
|
2015-06-03 14:38:47 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rdpdr_server_irp_new failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-12-31 02:41:21 +03:00
|
|
|
|
|
|
|
irp->CompletionId = context->priv->NextCompletionId++;
|
|
|
|
irp->Callback = rdpdr_server_drive_rename_file_callback1;
|
|
|
|
irp->CallbackData = callbackData;
|
|
|
|
irp->DeviceId = deviceId;
|
|
|
|
strncpy(irp->PathName, oldPath, sizeof(irp->PathName));
|
|
|
|
strncpy(irp->ExtraBuffer, newPath, sizeof(irp->ExtraBuffer));
|
|
|
|
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
|
|
|
|
rdpdr_server_convert_slashes(irp->ExtraBuffer, sizeof(irp->ExtraBuffer));
|
|
|
|
|
2015-06-03 14:38:47 +03:00
|
|
|
if (!rdpdr_server_enqueue_irp(context, irp))
|
2015-05-21 23:50:29 +03:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "rdpdr_server_enqueue_irp failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
rdpdr_server_irp_free(irp);
|
2015-06-03 14:38:47 +03:00
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-21 23:50:29 +03:00
|
|
|
}
|
2014-12-31 02:41:21 +03:00
|
|
|
|
|
|
|
/* Send a request to open the file. */
|
2016-09-26 13:12:37 +03:00
|
|
|
return rdpdr_server_send_device_create_request(context, deviceId,
|
|
|
|
irp->CompletionId, irp->PathName,
|
|
|
|
FILE_READ_DATA | SYNCHRONIZE, FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
|
2014-12-28 05:17:34 +03:00
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
RdpdrServerContext* rdpdr_server_context_new(HANDLE vcm)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
RdpdrServerContext* context;
|
2015-05-21 21:33:38 +03:00
|
|
|
context = (RdpdrServerContext*) calloc(1, sizeof(RdpdrServerContext));
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
context->vcm = vcm;
|
|
|
|
context->Start = rdpdr_server_start;
|
|
|
|
context->Stop = rdpdr_server_stop;
|
2014-12-28 05:17:34 +03:00
|
|
|
context->DriveCreateDirectory = rdpdr_server_drive_create_directory;
|
|
|
|
context->DriveDeleteDirectory = rdpdr_server_drive_delete_directory;
|
|
|
|
context->DriveQueryDirectory = rdpdr_server_drive_query_directory;
|
|
|
|
context->DriveOpenFile = rdpdr_server_drive_open_file;
|
|
|
|
context->DriveReadFile = rdpdr_server_drive_read_file;
|
|
|
|
context->DriveWriteFile = rdpdr_server_drive_write_file;
|
|
|
|
context->DriveCloseFile = rdpdr_server_drive_close_file;
|
|
|
|
context->DriveDeleteFile = rdpdr_server_drive_delete_file;
|
|
|
|
context->DriveRenameFile = rdpdr_server_drive_rename_file;
|
2015-05-21 21:33:38 +03:00
|
|
|
context->priv = (RdpdrServerPrivate*) calloc(1, sizeof(RdpdrServerPrivate));
|
2013-08-19 02:09:12 +04:00
|
|
|
|
2015-05-21 23:50:29 +03:00
|
|
|
if (!context->priv)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
free(context);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-12-28 05:17:34 +03:00
|
|
|
|
2015-05-21 23:50:29 +03:00
|
|
|
context->priv->VersionMajor = RDPDR_VERSION_MAJOR;
|
|
|
|
context->priv->VersionMinor = RDPDR_VERSION_MINOR_RDP6X;
|
|
|
|
context->priv->ClientId = g_ClientId++;
|
|
|
|
context->priv->UserLoggedOnPdu = TRUE;
|
|
|
|
context->priv->NextCompletionId = 1;
|
|
|
|
context->priv->IrpList = ListDictionary_New(TRUE);
|
|
|
|
|
|
|
|
if (!context->priv->IrpList)
|
|
|
|
{
|
2015-06-03 14:38:47 +03:00
|
|
|
WLog_ERR(TAG, "ListDictionary_New failed!");
|
2015-05-21 23:50:29 +03:00
|
|
|
free(context->priv);
|
|
|
|
free(context);
|
|
|
|
return NULL;
|
2013-08-19 02:09:12 +04:00
|
|
|
}
|
|
|
|
}
|
2015-06-03 14:38:47 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
}
|
2013-08-19 02:09:12 +04:00
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
void rdpdr_server_context_free(RdpdrServerContext* context)
|
2013-08-19 02:09:12 +04:00
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
if (context->priv)
|
|
|
|
{
|
2014-12-28 05:17:34 +03:00
|
|
|
ListDictionary_Free(context->priv->IrpList);
|
2013-08-19 02:09:12 +04:00
|
|
|
free(context->priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(context);
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 18:40:48 +03:00
|
|
|
|