Fixed rdpdr related warnings

This commit is contained in:
Armin Novak 2021-06-18 10:55:18 +02:00 committed by akallabeth
parent 4dfee30934
commit 8276c145e0
3 changed files with 141 additions and 110 deletions

View File

@ -31,6 +31,7 @@
#include <string.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/stream.h>
#include <freerdp/types.h>
@ -127,7 +128,7 @@ static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr)
return CHANNEL_RC_OK;
}
#elif _WIN32
#elif defined(_WIN32)
BOOL check_path(const char* path)
{
@ -830,7 +831,8 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr)
if (!dev_found)
{
devman_unregister_device(rdpdr->devman, (void*)keys[j]);
ids[0] = keys[j];
WINPR_ASSERT(keys[j] <= UINT32_MAX);
ids[0] = (UINT32)keys[j];
if ((error = rdpdr_send_device_list_remove_request(rdpdr, 1, ids)))
{
@ -1082,13 +1084,14 @@ static UINT rdpdr_send_client_name_request(rdpdrPlugin* rdpdr)
{
wStream* s;
WCHAR* computerNameW = NULL;
size_t computerNameLenW;
int computerNameLenW;
if (!rdpdr->computerName[0])
gethostname(rdpdr->computerName, sizeof(rdpdr->computerName) - 1);
computerNameLenW = ConvertToUnicode(CP_UTF8, 0, rdpdr->computerName, -1, &computerNameW, 0) * 2;
s = Stream_New(NULL, 16 + computerNameLenW + 2);
computerNameLenW = ConvertToUnicode(CP_UTF8, 0, rdpdr->computerName, -1, &computerNameW, 0);
WINPR_ASSERT(computerNameLenW >= 0);
s = Stream_New(NULL, 16U + (size_t)computerNameLenW * 2U + 2U);
if (!s)
{
@ -1101,8 +1104,9 @@ static UINT rdpdr_send_client_name_request(rdpdrPlugin* rdpdr)
Stream_Write_UINT16(s, PAKID_CORE_CLIENT_NAME); /* PacketId (2 bytes) */
Stream_Write_UINT32(s, 1); /* unicodeFlag, 0 for ASCII and 1 for Unicode */
Stream_Write_UINT32(s, 0); /* codePage, must be set to zero */
Stream_Write_UINT32(s, computerNameLenW + 2); /* computerNameLen, including null terminator */
Stream_Write(s, computerNameW, computerNameLenW);
Stream_Write_UINT32(s, (UINT32)computerNameLenW +
2U); /* computerNameLen, including null terminator */
Stream_Write(s, computerNameW, (size_t)computerNameLenW);
Stream_Write_UINT16(s, 0); /* null terminator */
free(computerNameW);
return rdpdr_send(rdpdr, s);
@ -1205,7 +1209,8 @@ static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use
Stream_Seek_UINT8(s);
}
Stream_Write_UINT32(s, data_len);
WINPR_ASSERT(data_len <= UINT32_MAX);
Stream_Write_UINT32(s, (UINT32)data_len);
if (data_len > 0)
Stream_Write(s, Stream_Buffer(device->data), data_len);
@ -1249,7 +1254,7 @@ static UINT dummy_irp_response(rdpdrPlugin* rdpdr, wStream* s)
Stream_Write_UINT16(output, PAKID_CORE_DEVICE_IOCOMPLETION); /* PacketId (2 bytes) */
Stream_Write_UINT32(output, DeviceId); /* DeviceId (4 bytes) */
Stream_Write_UINT32(output, CompletionId); /* CompletionId (4 bytes) */
Stream_Write_UINT32(output, STATUS_UNSUCCESSFUL); /* IoStatus (4 bytes) */
Stream_Write_INT32(output, STATUS_UNSUCCESSFUL); /* IoStatus (4 bytes) */
Stream_Zero(output, 256 - RDPDR_DEVICE_IO_RESPONSE_LENGTH);
// or usage
@ -1702,6 +1707,10 @@ static UINT rdpdr_virtual_channel_event_connected(rdpdrPlugin* rdpdr, LPVOID pDa
{
wObject* obj;
UINT32 status;
WINPR_UNUSED(pData);
WINPR_UNUSED(dataLength);
status = rdpdr->channelEntryPoints.pVirtualChannelOpenEx(rdpdr->InitHandle, &rdpdr->OpenHandle,
rdpdr->channelDef.name,
rdpdr_virtual_channel_open_event_ex);
@ -1848,6 +1857,7 @@ static VOID VCAPITYPE rdpdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LP
/* rdpdr is always built-in */
#define VirtualChannelEntryEx rdpdr_VirtualChannelEntryEx
extern BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID pInitHandle);
BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID pInitHandle)
{
UINT rc;

View File

@ -61,7 +61,7 @@ struct rdpdr_plugin
UINT16 versionMajor;
UINT16 versionMinor;
UINT16 clientID;
UINT32 clientID;
char computerName[256];
UINT32 sequenceId;

View File

@ -60,6 +60,24 @@ static RDPDR_IRP* rdpdr_server_dequeue_irp(RdpdrServerContext* context, UINT32 c
return irp;
}
static UINT rdpdr_seal_send_free_request(RdpdrServerContext* context, wStream* s)
{
BOOL status;
size_t length;
ULONG written;
WINPR_ASSERT(context);
WINPR_ASSERT(s);
Stream_SealLength(s);
length = Stream_Length(s);
WINPR_ASSERT(length <= ULONG_MAX);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
(ULONG)length, &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
/**
* Function description
*
@ -68,9 +86,7 @@ static RDPDR_IRP* rdpdr_server_dequeue_irp(RdpdrServerContext* context, UINT32 c
static UINT rdpdr_server_send_announce_request(RdpdrServerContext* context)
{
wStream* s;
BOOL status;
RDPDR_HEADER header;
ULONG written;
WLog_DBG(TAG, "RdpdrServerSendAnnounceRequest");
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_SERVER_ANNOUNCE;
@ -87,12 +103,7 @@ static UINT rdpdr_server_send_announce_request(RdpdrServerContext* context)
Stream_Write_UINT16(s, context->priv->VersionMajor); /* VersionMajor (2 bytes) */
Stream_Write_UINT16(s, context->priv->VersionMinor); /* VersionMinor (2 bytes) */
Stream_Write_UINT32(s, context->priv->ClientId); /* ClientId (4 bytes) */
Stream_SealLength(s);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -107,6 +118,8 @@ static UINT rdpdr_server_receive_announce_response(RdpdrServerContext* context,
UINT16 VersionMajor;
UINT16 VersionMinor;
WINPR_UNUSED(header);
if (Stream_GetRemainingLength(s) < 8)
{
WLog_ERR(TAG, "not enough data in stream!");
@ -135,6 +148,8 @@ static UINT rdpdr_server_receive_client_name_request(RdpdrServerContext* context
UINT32 UnicodeFlag;
UINT32 ComputerNameLen;
WINPR_UNUSED(header);
if (Stream_GetRemainingLength(s) < 12)
{
WLog_ERR(TAG, "not enough data in stream!");
@ -372,6 +387,10 @@ static UINT rdpdr_server_write_general_capability_set(RdpdrServerContext* contex
static UINT rdpdr_server_read_printer_capability_set(RdpdrServerContext* context, wStream* s,
RDPDR_CAPABILITY_HEADER* header)
{
WINPR_UNUSED(context);
WINPR_UNUSED(header);
WINPR_UNUSED(s);
return CHANNEL_RC_OK;
}
@ -382,7 +401,9 @@ static UINT rdpdr_server_read_printer_capability_set(RdpdrServerContext* context
*/
static UINT rdpdr_server_write_printer_capability_set(RdpdrServerContext* context, wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
RDPDR_CAPABILITY_HEADER header = { 0 };
WINPR_UNUSED(context);
header.CapabilityType = CAP_PRINTER_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = PRINT_CAPABILITY_VERSION_01;
@ -404,6 +425,10 @@ static UINT rdpdr_server_write_printer_capability_set(RdpdrServerContext* contex
static UINT rdpdr_server_read_port_capability_set(RdpdrServerContext* context, wStream* s,
RDPDR_CAPABILITY_HEADER* header)
{
WINPR_UNUSED(context);
WINPR_UNUSED(s);
WINPR_UNUSED(header);
return CHANNEL_RC_OK;
}
@ -414,7 +439,9 @@ static UINT rdpdr_server_read_port_capability_set(RdpdrServerContext* context, w
*/
static UINT rdpdr_server_write_port_capability_set(RdpdrServerContext* context, wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
RDPDR_CAPABILITY_HEADER header = { 0 };
WINPR_UNUSED(context);
header.CapabilityType = CAP_PORT_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = PORT_CAPABILITY_VERSION_01;
@ -436,6 +463,10 @@ static UINT rdpdr_server_write_port_capability_set(RdpdrServerContext* context,
static UINT rdpdr_server_read_drive_capability_set(RdpdrServerContext* context, wStream* s,
RDPDR_CAPABILITY_HEADER* header)
{
WINPR_UNUSED(context);
WINPR_UNUSED(header);
WINPR_UNUSED(s);
return CHANNEL_RC_OK;
}
@ -446,7 +477,10 @@ static UINT rdpdr_server_read_drive_capability_set(RdpdrServerContext* context,
*/
static UINT rdpdr_server_write_drive_capability_set(RdpdrServerContext* context, wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
RDPDR_CAPABILITY_HEADER header = { 0 };
WINPR_UNUSED(context);
header.CapabilityType = CAP_DRIVE_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = DRIVE_CAPABILITY_VERSION_02;
@ -468,6 +502,10 @@ static UINT rdpdr_server_write_drive_capability_set(RdpdrServerContext* context,
static UINT rdpdr_server_read_smartcard_capability_set(RdpdrServerContext* context, wStream* s,
RDPDR_CAPABILITY_HEADER* header)
{
WINPR_UNUSED(context);
WINPR_UNUSED(header);
WINPR_UNUSED(s);
return CHANNEL_RC_OK;
}
@ -483,6 +521,8 @@ static UINT rdpdr_server_write_smartcard_capability_set(RdpdrServerContext* cont
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = SMARTCARD_CAPABILITY_VERSION_01;
WINPR_UNUSED(context);
if (!Stream_EnsureRemainingCapacity(s, header.CapabilityLength))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
@ -500,10 +540,8 @@ static UINT rdpdr_server_write_smartcard_capability_set(RdpdrServerContext* cont
static UINT rdpdr_server_send_core_capability_request(RdpdrServerContext* context)
{
wStream* s;
BOOL status;
RDPDR_HEADER header;
UINT16 numCapabilities;
ULONG written;
UINT error;
WLog_DBG(TAG, "RdpdrServerSendCoreCapabilityRequest");
header.Component = RDPDR_CTYP_CORE;
@ -584,12 +622,7 @@ static UINT rdpdr_server_send_core_capability_request(RdpdrServerContext* contex
}
}
Stream_SealLength(s);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
out:
Stream_Free(s, TRUE);
return error;
@ -608,6 +641,8 @@ static UINT rdpdr_server_receive_core_capability_response(RdpdrServerContext* co
UINT16 numCapabilities;
RDPDR_CAPABILITY_HEADER capabilityHeader;
WINPR_UNUSED(header);
if (Stream_GetRemainingLength(s) < 4)
{
WLog_ERR(TAG, "not enough data in stream!");
@ -696,7 +731,6 @@ static UINT rdpdr_server_receive_core_capability_response(RdpdrServerContext* co
capabilityHeader.CapabilityType);
Stream_Seek(s, capabilityHeader.CapabilityLength - RDPDR_CAPABILITY_HEADER_LENGTH);
return ERROR_INVALID_DATA;
break;
}
}
@ -711,9 +745,7 @@ static UINT rdpdr_server_receive_core_capability_response(RdpdrServerContext* co
static UINT rdpdr_server_send_client_id_confirm(RdpdrServerContext* context)
{
wStream* s;
BOOL status;
RDPDR_HEADER header;
ULONG written;
WLog_DBG(TAG, "RdpdrServerSendClientIdConfirm");
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_CLIENTID_CONFIRM;
@ -730,12 +762,7 @@ static UINT rdpdr_server_send_client_id_confirm(RdpdrServerContext* context)
Stream_Write_UINT16(s, context->priv->VersionMajor); /* VersionMajor (2 bytes) */
Stream_Write_UINT16(s, context->priv->VersionMinor); /* VersionMinor (2 bytes) */
Stream_Write_UINT32(s, context->priv->ClientId); /* ClientId (4 bytes) */
Stream_SealLength(s);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -753,6 +780,8 @@ static UINT rdpdr_server_receive_device_list_announce_request(RdpdrServerContext
char PreferredDosName[9];
UINT32 DeviceDataLength;
WINPR_UNUSED(header);
if (Stream_GetRemainingLength(s) < 4)
{
WLog_ERR(TAG, "not enough data in stream!");
@ -844,6 +873,8 @@ static UINT rdpdr_server_receive_device_list_remove_request(RdpdrServerContext*
UINT32 DeviceType;
UINT32 DeviceId;
WINPR_UNUSED(header);
if (Stream_GetRemainingLength(s) < 4)
{
WLog_ERR(TAG, "not enough data in stream!");
@ -922,6 +953,8 @@ static UINT rdpdr_server_receive_device_io_completion(RdpdrServerContext* contex
RDPDR_IRP* irp;
UINT error = CHANNEL_RC_OK;
WINPR_UNUSED(header);
if (Stream_GetRemainingLength(s) < 12)
{
WLog_ERR(TAG, "not enough data in stream!");
@ -958,9 +991,7 @@ static UINT rdpdr_server_receive_device_io_completion(RdpdrServerContext* contex
static UINT rdpdr_server_send_user_logged_on(RdpdrServerContext* context)
{
wStream* s;
BOOL status;
RDPDR_HEADER header;
ULONG written;
WLog_DBG(TAG, "RdpdrServerSendUserLoggedOn");
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_USER_LOGGEDON;
@ -974,12 +1005,7 @@ static UINT rdpdr_server_send_user_logged_on(RdpdrServerContext* context)
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
Stream_SealLength(s);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -1176,6 +1202,7 @@ static DWORD WINAPI rdpdr_server_thread(LPVOID arg)
while (1)
{
size_t capacity;
BytesReturned = 0;
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
@ -1198,8 +1225,9 @@ static DWORD WINAPI rdpdr_server_thread(LPVOID arg)
if (status == WAIT_OBJECT_0)
break;
capacity = MIN(Stream_Capacity(s), ULONG_MAX);
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0, (PCHAR)Stream_Buffer(s),
Stream_Capacity(s), &BytesReturned))
(ULONG)capacity, &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
error = ERROR_INTERNAL_ERROR;
@ -1320,6 +1348,7 @@ static void rdpdr_server_write_device_iorequest(wStream* s, UINT32 deviceId, UIN
static UINT rdpdr_server_read_file_directory_information(wStream* s,
FILE_DIRECTORY_INFORMATION* fdi)
{
int rc;
UINT32 fileNameLength;
ZeroMemory(fdi, sizeof(FILE_DIRECTORY_INFORMATION));
@ -1331,12 +1360,12 @@ static UINT rdpdr_server_read_file_directory_information(wStream* s,
Stream_Read_UINT32(s, fdi->NextEntryOffset); /* NextEntryOffset (4 bytes) */
Stream_Read_UINT32(s, fdi->FileIndex); /* FileIndex (4 bytes) */
Stream_Read_UINT64(s, fdi->CreationTime.QuadPart); /* CreationTime (8 bytes) */
Stream_Read_UINT64(s, fdi->LastAccessTime.QuadPart); /* LastAccessTime (8 bytes) */
Stream_Read_UINT64(s, fdi->LastWriteTime.QuadPart); /* LastWriteTime (8 bytes) */
Stream_Read_UINT64(s, fdi->ChangeTime.QuadPart); /* ChangeTime (8 bytes) */
Stream_Read_UINT64(s, fdi->EndOfFile.QuadPart); /* EndOfFile (8 bytes) */
Stream_Read_UINT64(s, fdi->AllocationSize.QuadPart); /* AllocationSize (8 bytes) */
Stream_Read_INT64(s, fdi->CreationTime.QuadPart); /* CreationTime (8 bytes) */
Stream_Read_INT64(s, fdi->LastAccessTime.QuadPart); /* LastAccessTime (8 bytes) */
Stream_Read_INT64(s, fdi->LastWriteTime.QuadPart); /* LastWriteTime (8 bytes) */
Stream_Read_INT64(s, fdi->ChangeTime.QuadPart); /* ChangeTime (8 bytes) */
Stream_Read_INT64(s, fdi->EndOfFile.QuadPart); /* EndOfFile (8 bytes) */
Stream_Read_INT64(s, fdi->AllocationSize.QuadPart); /* AllocationSize (8 bytes) */
Stream_Read_UINT32(s, fdi->FileAttributes); /* FileAttributes (4 bytes) */
Stream_Read_UINT32(s, fileNameLength); /* FileNameLength (4 bytes) */
@ -1346,8 +1375,11 @@ static UINT rdpdr_server_read_file_directory_information(wStream* s,
return ERROR_INVALID_DATA;
}
WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)Stream_Pointer(s), fileNameLength / 2, fdi->FileName,
sizeof(fdi->FileName), NULL, NULL);
WINPR_ASSERT(fileNameLength / 2U <= INT_MAX);
WINPR_ASSERT(sizeof(fdi->FileName) < INT_MAX);
rc = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)Stream_Pointer(s), (int)fileNameLength / 2,
fdi->FileName, (int)sizeof(fdi->FileName), NULL, NULL);
WINPR_ASSERT(rc >= 0);
Stream_Seek(s, fileNameLength);
return CHANNEL_RC_OK;
}
@ -1362,9 +1394,7 @@ static UINT rdpdr_server_send_device_create_request(RdpdrServerContext* context,
UINT32 desiredAccess, UINT32 createOptions,
UINT32 createDisposition)
{
UINT32 pathLength;
ULONG written;
BOOL status;
size_t pathLength;
wStream* s;
WLog_DBG(TAG,
"RdpdrServerSendDeviceCreateRequest: deviceId=%" PRIu32
@ -1372,8 +1402,8 @@ static UINT rdpdr_server_send_device_create_request(RdpdrServerContext* context,
" createDisposition=0x%" PRIx32 "",
deviceId, path, desiredAccess, createOptions, createDisposition);
/* Compute the required Unicode size. */
pathLength = (strlen(path) + 1) * sizeof(WCHAR);
s = Stream_New(NULL, 256 + pathLength);
pathLength = (strlen(path) + 1U) * sizeof(WCHAR);
s = Stream_New(NULL, 256U + pathLength);
if (!s)
{
@ -1389,15 +1419,17 @@ static UINT rdpdr_server_send_device_create_request(RdpdrServerContext* context,
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) */
/* Convert the path to Unicode. */
MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR)Stream_Pointer(s), pathLength);
WINPR_ASSERT(pathLength <= UINT32_MAX);
Stream_Write_UINT32(s, (UINT32)pathLength); /* PathLength (4 bytes) */
/* Convert the path to Unicode. */
{
int rc;
WINPR_ASSERT(pathLength <= INT_MAX);
rc = MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR)Stream_Pointer(s), (int)pathLength);
WINPR_ASSERT(rc >= 0);
}
Stream_Seek(s, pathLength);
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -1408,8 +1440,6 @@ static UINT rdpdr_server_send_device_create_request(RdpdrServerContext* context,
static UINT rdpdr_server_send_device_close_request(RdpdrServerContext* context, UINT32 deviceId,
UINT32 fileId, UINT32 completionId)
{
ULONG written;
BOOL status;
wStream* s;
WLog_DBG(TAG, "RdpdrServerSendDeviceCloseRequest: deviceId=%" PRIu32 ", fileId=%" PRIu32 "",
deviceId, fileId);
@ -1423,11 +1453,7 @@ static UINT rdpdr_server_send_device_close_request(RdpdrServerContext* context,
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_CLOSE, 0);
Stream_Zero(s, 32); /* Padding (32 bytes) */
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -1439,8 +1465,6 @@ static UINT rdpdr_server_send_device_read_request(RdpdrServerContext* context, U
UINT32 fileId, UINT32 completionId, UINT32 length,
UINT32 offset)
{
ULONG written;
BOOL status;
wStream* s;
WLog_DBG(TAG,
"RdpdrServerSendDeviceReadRequest: deviceId=%" PRIu32 ", fileId=%" PRIu32
@ -1459,11 +1483,7 @@ static UINT rdpdr_server_send_device_read_request(RdpdrServerContext* context, U
Stream_Write_UINT32(s, offset); /* Offset (8 bytes) */
Stream_Write_UINT32(s, 0);
Stream_Zero(s, 20); /* Padding (20 bytes) */
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -1475,8 +1495,6 @@ static UINT rdpdr_server_send_device_write_request(RdpdrServerContext* context,
UINT32 fileId, UINT32 completionId,
const char* data, UINT32 length, UINT32 offset)
{
ULONG written;
BOOL status;
wStream* s;
WLog_DBG(TAG,
"RdpdrServerSendDeviceWriteRequest: deviceId=%" PRIu32 ", fileId=%" PRIu32
@ -1496,11 +1514,7 @@ static UINT rdpdr_server_send_device_write_request(RdpdrServerContext* context,
Stream_Write_UINT32(s, 0);
Stream_Zero(s, 20); /* Padding (20 bytes) */
Stream_Write(s, data, length); /* WriteData (variable) */
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -1512,9 +1526,7 @@ static UINT rdpdr_server_send_device_query_directory_request(RdpdrServerContext*
UINT32 deviceId, UINT32 fileId,
UINT32 completionId, const char* path)
{
UINT32 pathLength;
ULONG written;
BOOL status;
size_t pathLength;
wStream* s;
WLog_DBG(TAG,
"RdpdrServerSendDeviceQueryDirectoryRequest: deviceId=%" PRIu32 ", fileId=%" PRIu32
@ -1534,21 +1546,21 @@ static UINT rdpdr_server_send_device_query_directory_request(RdpdrServerContext*
IRP_MN_QUERY_DIRECTORY);
Stream_Write_UINT32(s, FileDirectoryInformation); /* FsInformationClass (4 bytes) */
Stream_Write_UINT8(s, path ? 1 : 0); /* InitialQuery (1 byte) */
Stream_Write_UINT32(s, pathLength); /* PathLength (4 bytes) */
WINPR_ASSERT(pathLength <= UINT32_MAX);
Stream_Write_UINT32(s, (UINT32)pathLength); /* PathLength (4 bytes) */
Stream_Zero(s, 23); /* Padding (23 bytes) */
/* Convert the path to Unicode. */
if (pathLength > 0)
{
MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR)Stream_Pointer(s), pathLength);
int rc;
WINPR_ASSERT(pathLength <= INT_MAX);
rc = MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR)Stream_Pointer(s), (int)pathLength);
WINPR_ASSERT(rc >= 0);
Stream_Seek(s, pathLength);
}
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
/**
@ -1560,9 +1572,7 @@ static UINT rdpdr_server_send_device_file_rename_request(RdpdrServerContext* con
UINT32 deviceId, UINT32 fileId,
UINT32 completionId, const char* path)
{
UINT32 pathLength;
ULONG written;
BOOL status;
size_t pathLength;
wStream* s;
WLog_DBG(TAG,
"RdpdrServerSendDeviceFileNameRequest: deviceId=%" PRIu32 ", fileId=%" PRIu32
@ -1581,25 +1591,25 @@ static UINT rdpdr_server_send_device_file_rename_request(RdpdrServerContext* con
rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_SET_INFORMATION,
0);
Stream_Write_UINT32(s, FileRenameInformation); /* FsInformationClass (4 bytes) */
Stream_Write_UINT32(s, pathLength + 6); /* Length (4 bytes) */
WINPR_ASSERT(pathLength <= UINT32_MAX - 6U);
Stream_Write_UINT32(s, (UINT32)pathLength + 6U); /* 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) */
Stream_Write_UINT32(s, (UINT32)pathLength); /* FileNameLength (4 bytes) */
/* Convert the path to Unicode. */
if (pathLength > 0)
{
MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR)Stream_Pointer(s), pathLength);
int rc;
WINPR_ASSERT(pathLength < INT_MAX);
rc = MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR)Stream_Pointer(s), (int)pathLength);
WINPR_ASSERT(rc >= 0);
Stream_Seek(s, pathLength);
}
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR)Stream_Buffer(s),
Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
return rdpdr_seal_send_free_request(context, s);
}
static void rdpdr_server_convert_slashes(char* path, int size)
@ -1626,6 +1636,8 @@ static UINT rdpdr_server_drive_create_directory_callback2(RdpdrServerContext* co
RDPDR_IRP* irp, UINT32 deviceId,
UINT32 completionId, UINT32 ioStatus)
{
WINPR_UNUSED(s);
WLog_DBG(TAG,
"RdpdrServerDriveCreateDirectoryCallback2: deviceId=%" PRIu32 ", completionId=%" PRIu32
", ioStatus=0x%" PRIx32 "",
@ -1737,6 +1749,8 @@ static UINT rdpdr_server_drive_delete_directory_callback2(RdpdrServerContext* co
RDPDR_IRP* irp, UINT32 deviceId,
UINT32 completionId, UINT32 ioStatus)
{
WINPR_UNUSED(s);
WLog_DBG(TAG,
"RdpdrServerDriveDeleteDirectoryCallback2: deviceId=%" PRIu32 ", completionId=%" PRIu32
", ioStatus=0x%" PRIx32 "",
@ -2249,6 +2263,8 @@ static UINT rdpdr_server_drive_close_file_callback(RdpdrServerContext* context,
RDPDR_IRP* irp, UINT32 deviceId,
UINT32 completionId, UINT32 ioStatus)
{
WINPR_UNUSED(s);
WLog_DBG(TAG,
"RdpdrServerDriveCloseFileCallback: deviceId=%" PRIu32 ", completionId=%" PRIu32
", ioStatus=0x%" PRIx32 "",
@ -2307,6 +2323,8 @@ static UINT rdpdr_server_drive_delete_file_callback2(RdpdrServerContext* context
RDPDR_IRP* irp, UINT32 deviceId,
UINT32 completionId, UINT32 ioStatus)
{
WINPR_UNUSED(s);
WLog_DBG(TAG,
"RdpdrServerDriveDeleteFileCallback2: deviceId=%" PRIu32 ", completionId=%" PRIu32
", ioStatus=0x%" PRIx32 "",
@ -2418,6 +2436,9 @@ static UINT rdpdr_server_drive_rename_file_callback3(RdpdrServerContext* context
RDPDR_IRP* irp, UINT32 deviceId,
UINT32 completionId, UINT32 ioStatus)
{
WINPR_UNUSED(context);
WINPR_UNUSED(s);
WLog_DBG(TAG,
"RdpdrServerDriveRenameFileCallback3: deviceId=%" PRIu32 ", completionId=%" PRIu32
", ioStatus=0x%" PRIx32 "",