Milestone 5: deliver embedded RDP sessions and lifecycle hardening

This commit is contained in:
Keith Smith
2026-03-03 18:59:26 -07:00
parent 230a401386
commit 36006bd4aa
2941 changed files with 724359 additions and 77 deletions

View File

@@ -0,0 +1,26 @@
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP cmake build script
#
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# 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.
define_channel("rdpdr")
if(WITH_CLIENT_CHANNELS)
add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME})
endif()
if(WITH_SERVER_CHANNELS)
add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME})
endif()

View File

@@ -0,0 +1,20 @@
set(OPTION_DEFAULT ON)
set(OPTION_CLIENT_DEFAULT ON)
set(OPTION_SERVER_DEFAULT ON)
define_channel_options(
NAME
"rdpdr"
TYPE
"static"
DESCRIPTION
"Device Redirection Virtual Channel Extension"
SPECIFICATIONS
"[MS-RDPEFS] [MS-RDPEPC] [MS-RDPESC] [MS-RDPESP]"
DEFAULT
${OPTION_DEFAULT}
CLIENT_DEFAULT
${OPTION_CLIENT_DEFAULT}
SERVER_DEFAULT
${OPTION_SERVER_DEFAULT}
)

View File

@@ -0,0 +1,44 @@
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP cmake build script
#
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
# Copyright 2016 Inuvika Inc.
# Copyright 2016 David PHAM-VAN <d.phamvan@inuvika.com>
#
# 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.
define_channel_client("rdpdr")
include(CheckFunctionExists)
check_function_exists(getmntent_r FREERDP_HAVE_GETMNTENT_R)
if(FREERDP_HAVE_GETMNTENT_R)
add_compile_definitions(FREERDP_HAVE_GETMNTENT_R)
endif()
set(${MODULE_PREFIX}_SRCS
irp.c
irp.h
devman.c
devman.h
rdpdr_main.c
rdpdr_main.h
rdpdr_capabilities.c
rdpdr_capabilities.h
)
set(${MODULE_PREFIX}_LIBS winpr freerdp)
if(APPLE AND (NOT IOS))
find_library(CORESERVICES_LIBRARY CoreServices)
list(APPEND ${MODULE_PREFIX}_LIBS ${CORESERVICES_LIBRARY})
endif()
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntryEx")

View File

@@ -0,0 +1,237 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
* Copyright 2016 Armin Novak <armin.novak@gmail.com>
*
* 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.
*/
#include <freerdp/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
#include <freerdp/types.h>
#include <freerdp/addin.h>
#include <freerdp/client/channels.h>
#include <freerdp/channels/log.h>
#include "rdpdr_main.h"
#include "devman.h"
#define TAG CHANNELS_TAG("rdpdr.client")
static void devman_device_free(void* obj)
{
DEVICE* device = (DEVICE*)obj;
if (!device)
return;
if (device->Free)
device->Free(device);
}
DEVMAN* devman_new(rdpdrPlugin* rdpdr)
{
DEVMAN* devman = nullptr;
if (!rdpdr)
return nullptr;
devman = (DEVMAN*)calloc(1, sizeof(DEVMAN));
if (!devman)
{
WLog_Print(rdpdr->log, WLOG_INFO, "calloc failed!");
return nullptr;
}
devman->plugin = (void*)rdpdr;
devman->id_sequence = 1;
devman->devices = ListDictionary_New(TRUE);
if (!devman->devices)
{
WLog_Print(rdpdr->log, WLOG_INFO, "ListDictionary_New failed!");
free(devman);
return nullptr;
}
ListDictionary_ValueObject(devman->devices)->fnObjectFree = devman_device_free;
return devman;
}
void devman_free(DEVMAN* devman)
{
ListDictionary_Free(devman->devices);
free(devman);
}
void devman_unregister_device(DEVMAN* devman, void* key)
{
DEVICE* device = nullptr;
if (!devman || !key)
return;
device = (DEVICE*)ListDictionary_Take(devman->devices, key);
if (device)
devman_device_free(device);
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT devman_register_device(DEVMAN* devman, DEVICE* device)
{
void* key = nullptr;
if (!devman || !device)
return ERROR_INVALID_PARAMETER;
device->id = devman->id_sequence++;
key = (void*)(size_t)device->id;
if (!ListDictionary_Add(devman->devices, key, device))
{
WLog_INFO(TAG, "ListDictionary_Add failed!");
return ERROR_INTERNAL_ERROR;
}
return CHANNEL_RC_OK;
}
DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id)
{
DEVICE* device = nullptr;
void* key = (void*)(size_t)id;
if (!devman)
{
WLog_ERR(TAG, "device manager=nullptr");
return nullptr;
}
device = (DEVICE*)ListDictionary_GetItemValue(devman->devices, key);
if (!device)
WLog_WARN(TAG, "could not find device ID 0x%08" PRIx32, id);
return device;
}
DEVICE* devman_get_device_by_type(DEVMAN* devman, UINT32 type)
{
DEVICE* device = nullptr;
ULONG_PTR* keys = nullptr;
if (!devman)
return nullptr;
ListDictionary_Lock(devman->devices);
const size_t count = ListDictionary_GetKeys(devman->devices, &keys);
for (size_t x = 0; x < count; x++)
{
DEVICE* cur = (DEVICE*)ListDictionary_GetItemValue(devman->devices, (void*)keys[x]);
if (!cur)
continue;
if (cur->type != type)
continue;
device = cur;
break;
}
free(keys);
ListDictionary_Unlock(devman->devices);
return device;
}
static const char DRIVE_SERVICE_NAME[] = "drive";
static const char PRINTER_SERVICE_NAME[] = "printer";
static const char SMARTCARD_SERVICE_NAME[] = "smartcard";
static const char SERIAL_SERVICE_NAME[] = "serial";
static const char PARALLEL_SERVICE_NAME[] = "parallel";
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
UINT devman_load_device_service(DEVMAN* devman, RDPDR_DEVICE* device, rdpContext* rdpcontext)
{
const char* ServiceName = nullptr;
DEVICE_SERVICE_ENTRY_POINTS ep = WINPR_C_ARRAY_INIT;
union
{
const RDPDR_DEVICE* cdp;
RDPDR_DEVICE* dp;
} devconv;
devconv.cdp = device;
if (!devman || !device || !rdpcontext)
return ERROR_INVALID_PARAMETER;
if (device->Type == RDPDR_DTYP_FILESYSTEM)
ServiceName = DRIVE_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_PRINT)
ServiceName = PRINTER_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_SMARTCARD)
ServiceName = SMARTCARD_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_SERIAL)
ServiceName = SERIAL_SERVICE_NAME;
else if (device->Type == RDPDR_DTYP_PARALLEL)
ServiceName = PARALLEL_SERVICE_NAME;
if (!ServiceName)
{
WLog_INFO(TAG, "ServiceName %s did not match!", ServiceName);
return ERROR_INVALID_NAME;
}
if (device->Name)
WLog_INFO(TAG, "Loading device service %s [%s] (static)", ServiceName, device->Name);
else
WLog_INFO(TAG, "Loading device service %s (static)", ServiceName);
PVIRTUALCHANNELENTRY pvce =
freerdp_load_channel_addin_entry(ServiceName, nullptr, "DeviceServiceEntry", 0);
PDEVICE_SERVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PDEVICE_SERVICE_ENTRY);
if (!entry)
{
WLog_INFO(TAG, "freerdp_load_channel_addin_entry failed!");
return ERROR_INTERNAL_ERROR;
}
ep.devman = devman;
ep.RegisterDevice = devman_register_device;
ep.device = devconv.dp;
ep.rdpcontext = rdpcontext;
return entry(&ep);
}

View File

@@ -0,0 +1,47 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
*/
#ifndef FREERDP_CHANNEL_RDPDR_CLIENT_DEVMAN_H
#define FREERDP_CHANNEL_RDPDR_CLIENT_DEVMAN_H
#include <winpr/wtypes.h>
#include "rdpdr_main.h"
FREERDP_LOCAL void devman_unregister_device(DEVMAN* devman, void* key);
FREERDP_LOCAL void devman_free(DEVMAN* devman);
WINPR_ATTR_NODISCARD
FREERDP_LOCAL UINT devman_load_device_service(DEVMAN* devman, RDPDR_DEVICE* device,
rdpContext* rdpcontext);
WINPR_ATTR_NODISCARD
FREERDP_LOCAL DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id);
WINPR_ATTR_NODISCARD
FREERDP_LOCAL DEVICE* devman_get_device_by_type(DEVMAN* devman, UINT32 type);
WINPR_ATTR_MALLOC(devman_free, 1)
WINPR_ATTR_NODISCARD
FREERDP_LOCAL DEVMAN* devman_new(rdpdrPlugin* rdpdr);
#endif /* FREERDP_CHANNEL_RDPDR_CLIENT_DEVMAN_H */

View File

@@ -0,0 +1,159 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
*/
#include <freerdp/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
#include <freerdp/utils/rdpdr_utils.h>
#include "rdpdr_main.h"
#include "devman.h"
#include "irp.h"
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT irp_free(IRP* irp)
{
if (!irp)
return CHANNEL_RC_OK;
if (irp->input)
Stream_Release(irp->input);
if (irp->output)
Stream_Release(irp->output);
winpr_aligned_free(irp);
return CHANNEL_RC_OK;
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT irp_complete(IRP* irp)
{
WINPR_ASSERT(irp);
WINPR_ASSERT(irp->output);
WINPR_ASSERT(irp->devman);
rdpdrPlugin* rdpdr = (rdpdrPlugin*)irp->devman->plugin;
WINPR_ASSERT(rdpdr);
const size_t pos = Stream_GetPosition(irp->output);
Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4);
Stream_Write_INT32(irp->output, irp->IoStatus); /* IoStatus (4 bytes) */
Stream_SetPosition(irp->output, pos);
const UINT error = rdpdr_send(rdpdr, irp->output);
irp->output = nullptr;
irp_free(irp);
return error;
}
IRP* irp_new(DEVMAN* devman, wStreamPool* pool, wStream* s, wLog* log, UINT* error)
{
IRP* irp = nullptr;
DEVICE* device = nullptr;
UINT32 DeviceId = 0;
WINPR_ASSERT(devman);
WINPR_ASSERT(pool);
WINPR_ASSERT(s);
if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
{
if (error)
*error = ERROR_INVALID_DATA;
return nullptr;
}
Stream_Read_UINT32(s, DeviceId); /* DeviceId (4 bytes) */
device = devman_get_device_by_id(devman, DeviceId);
if (!device)
{
if (error)
*error = ERROR_DEV_NOT_EXIST;
return nullptr;
}
irp = (IRP*)winpr_aligned_calloc(1, sizeof(IRP), MEMORY_ALLOCATION_ALIGNMENT);
if (!irp)
{
WLog_Print(log, WLOG_ERROR, "_aligned_malloc failed!");
if (error)
*error = CHANNEL_RC_NO_MEMORY;
return nullptr;
}
Stream_Read_UINT32(s, irp->FileId); /* FileId (4 bytes) */
Stream_Read_UINT32(s, irp->CompletionId); /* CompletionId (4 bytes) */
Stream_Read_UINT32(s, irp->MajorFunction); /* MajorFunction (4 bytes) */
Stream_Read_UINT32(s, irp->MinorFunction); /* MinorFunction (4 bytes) */
Stream_AddRef(s);
irp->input = s;
irp->device = device;
irp->devman = devman;
irp->output = StreamPool_Take(pool, 256);
if (!irp->output)
{
WLog_Print(log, WLOG_ERROR, "Stream_New failed!");
irp_free(irp);
if (error)
*error = CHANNEL_RC_NO_MEMORY;
return nullptr;
}
if (!rdpdr_write_iocompletion_header(irp->output, DeviceId, irp->CompletionId, 0))
{
irp_free(irp);
if (error)
*error = CHANNEL_RC_NO_MEMORY;
return nullptr;
}
irp->Complete = irp_complete;
irp->Discard = irp_free;
irp->thread = nullptr;
irp->cancelled = FALSE;
if (error)
*error = CHANNEL_RC_OK;
return irp;
}

View File

@@ -0,0 +1,31 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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.
*/
#ifndef FREERDP_CHANNEL_RDPDR_CLIENT_IRP_H
#define FREERDP_CHANNEL_RDPDR_CLIENT_IRP_H
#include <winpr/wtypes.h>
#include <winpr/wlog.h>
#include "rdpdr_main.h"
WINPR_ATTR_NODISCARD
FREERDP_LOCAL IRP* irp_new(DEVMAN* devman, wStreamPool* pool, wStream* s, wLog* log, UINT* error);
#endif /* FREERDP_CHANNEL_RDPDR_CLIENT_IRP_H */

View File

@@ -0,0 +1,326 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015-2016 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
*
* 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.
*/
#include <freerdp/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
#include <freerdp/freerdp.h>
#include <freerdp/utils/rdpdr_utils.h>
#include "rdpdr_main.h"
#include "rdpdr_capabilities.h"
#define RDPDR_CAPABILITY_HEADER_LENGTH 8
/* Output device direction general capability set */
static BOOL rdpdr_write_general_capset(rdpdrPlugin* rdpdr, wStream* s)
{
WINPR_ASSERT(rdpdr);
const RDPDR_CAPABILITY_HEADER header = { CAP_GENERAL_TYPE, RDPDR_CAPABILITY_HEADER_LENGTH + 36,
GENERAL_CAPABILITY_VERSION_02 };
const UINT32 ioCode1 = rdpdr->clientIOCode1 & rdpdr->serverIOCode1;
const UINT32 ioCode2 = rdpdr->clientIOCode2 & rdpdr->serverIOCode2;
if (rdpdr_write_capset_header(rdpdr->log, s, &header) != CHANNEL_RC_OK)
return FALSE;
if (!Stream_EnsureRemainingCapacity(s, 36))
return FALSE;
Stream_Write_UINT32(s, rdpdr->clientOsType); /* osType, ignored on receipt */
Stream_Write_UINT32(s, rdpdr->clientOsVersion); /* osVersion, unused and must be set to zero */
Stream_Write_UINT16(s, rdpdr->clientVersionMajor); /* protocolMajorVersion, must be set to 1 */
Stream_Write_UINT16(s, rdpdr->clientVersionMinor); /* protocolMinorVersion */
Stream_Write_UINT32(s, ioCode1); /* ioCode1 */
Stream_Write_UINT32(s, ioCode2); /* ioCode2, must be set to zero, reserved for future use */
Stream_Write_UINT32(s, rdpdr->clientExtendedPDU); /* extendedPDU */
Stream_Write_UINT32(s, rdpdr->clientExtraFlags1); /* extraFlags1 */
Stream_Write_UINT32(
s,
rdpdr->clientExtraFlags2); /* extraFlags2, must be set to zero, reserved for future use */
Stream_Write_UINT32(
s, rdpdr->clientSpecialTypeDeviceCap); /* SpecialTypeDeviceCap, number of special devices to
be redirected before logon */
return TRUE;
}
/* Process device direction general capability set */
static UINT rdpdr_process_general_capset(rdpdrPlugin* rdpdr, wStream* s,
const RDPDR_CAPABILITY_HEADER* header)
{
WINPR_ASSERT(header);
const BOOL gotV1 = header->Version == GENERAL_CAPABILITY_VERSION_01;
const size_t expect = gotV1 ? 32 : 36;
if (header->CapabilityLength != expect)
{
WLog_Print(rdpdr->log, WLOG_ERROR,
"CAP_GENERAL_TYPE::CapabilityLength expected %" PRIuz ", got %" PRIu32, expect,
header->CapabilityLength);
return ERROR_INVALID_DATA;
}
if (!Stream_CheckAndLogRequiredLengthWLog(rdpdr->log, s, expect))
return ERROR_INVALID_DATA;
rdpdr->serverOsType = Stream_Get_UINT32(s); /* osType, ignored on receipt */
rdpdr->serverOsVersion = Stream_Get_UINT32(s); /* osVersion, unused and must be set to zero */
rdpdr->serverVersionMajor = Stream_Get_UINT16(s); /* protocolMajorVersion, must be set to 1 */
rdpdr->serverVersionMinor = Stream_Get_UINT16(s); /* protocolMinorVersion */
rdpdr->serverIOCode1 = Stream_Get_UINT32(s); /* ioCode1 */
rdpdr->serverIOCode2 =
Stream_Get_UINT32(s); /* ioCode2, must be set to zero, reserved for future use */
rdpdr->serverExtendedPDU = Stream_Get_UINT32(s); /* extendedPDU */
rdpdr->serverExtraFlags1 = Stream_Get_UINT32(s); /* extraFlags1 */
rdpdr->serverExtraFlags2 =
Stream_Get_UINT32(s); /* extraFlags2, must be set to zero, reserved for future use */
if (gotV1)
rdpdr->serverSpecialTypeDeviceCap = 0;
else
rdpdr->serverSpecialTypeDeviceCap = Stream_Get_UINT32(
s); /* SpecialTypeDeviceCap, number of special devices to
be redirected before logon */
return CHANNEL_RC_OK;
}
/* Output printer direction capability set */
static BOOL rdpdr_write_printer_capset(rdpdrPlugin* rdpdr, wStream* s)
{
WINPR_UNUSED(rdpdr);
const RDPDR_CAPABILITY_HEADER header = { CAP_PRINTER_TYPE, RDPDR_CAPABILITY_HEADER_LENGTH,
PRINT_CAPABILITY_VERSION_01 };
return rdpdr_write_capset_header(rdpdr->log, s, &header) == CHANNEL_RC_OK;
}
/* Process printer direction capability set */
static UINT rdpdr_process_printer_capset(WINPR_ATTR_UNUSED rdpdrPlugin* rdpdr, wStream* s,
const RDPDR_CAPABILITY_HEADER* header)
{
WINPR_ASSERT(header);
Stream_Seek(s, header->CapabilityLength);
return CHANNEL_RC_OK;
}
/* Output port redirection capability set */
static BOOL rdpdr_write_port_capset(rdpdrPlugin* rdpdr, wStream* s)
{
WINPR_UNUSED(rdpdr);
const RDPDR_CAPABILITY_HEADER header = { CAP_PORT_TYPE, RDPDR_CAPABILITY_HEADER_LENGTH,
PORT_CAPABILITY_VERSION_01 };
return rdpdr_write_capset_header(rdpdr->log, s, &header) == CHANNEL_RC_OK;
}
/* Process port redirection capability set */
static UINT rdpdr_process_port_capset(WINPR_ATTR_UNUSED rdpdrPlugin* rdpdr, wStream* s,
const RDPDR_CAPABILITY_HEADER* header)
{
WINPR_ASSERT(header);
Stream_Seek(s, header->CapabilityLength);
return CHANNEL_RC_OK;
}
/* Output drive redirection capability set */
static BOOL rdpdr_write_drive_capset(rdpdrPlugin* rdpdr, wStream* s)
{
WINPR_UNUSED(rdpdr);
const RDPDR_CAPABILITY_HEADER header = { CAP_DRIVE_TYPE, RDPDR_CAPABILITY_HEADER_LENGTH,
DRIVE_CAPABILITY_VERSION_02 };
return rdpdr_write_capset_header(rdpdr->log, s, &header) == CHANNEL_RC_OK;
}
/* Process drive redirection capability set */
static UINT rdpdr_process_drive_capset(WINPR_ATTR_UNUSED rdpdrPlugin* rdpdr, wStream* s,
const RDPDR_CAPABILITY_HEADER* header)
{
WINPR_ASSERT(header);
Stream_Seek(s, header->CapabilityLength);
return CHANNEL_RC_OK;
}
/* Output smart card redirection capability set */
static BOOL rdpdr_write_smartcard_capset(rdpdrPlugin* rdpdr, wStream* s)
{
WINPR_UNUSED(rdpdr);
const RDPDR_CAPABILITY_HEADER header = { CAP_SMARTCARD_TYPE, RDPDR_CAPABILITY_HEADER_LENGTH,
SMARTCARD_CAPABILITY_VERSION_01 };
return rdpdr_write_capset_header(rdpdr->log, s, &header) == CHANNEL_RC_OK;
}
/* Process smartcard redirection capability set */
static UINT rdpdr_process_smartcard_capset(WINPR_ATTR_UNUSED rdpdrPlugin* rdpdr, wStream* s,
const RDPDR_CAPABILITY_HEADER* header)
{
WINPR_ASSERT(header);
Stream_Seek(s, header->CapabilityLength);
return CHANNEL_RC_OK;
}
UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s)
{
UINT status = CHANNEL_RC_OK;
UINT16 numCapabilities = 0;
if (!rdpdr || !s)
return CHANNEL_RC_NULL_DATA;
if (!rdpdr_state_advance(rdpdr, RDPDR_CHANNEL_STATE_CLIENT_CAPS))
return ERROR_INVALID_STATE;
if (!Stream_CheckAndLogRequiredLengthWLog(rdpdr->log, s, 4))
return ERROR_INVALID_DATA;
Stream_Read_UINT16(s, numCapabilities);
Stream_Seek(s, 2); /* pad (2 bytes) */
memset(rdpdr->capabilities, 0, sizeof(rdpdr->capabilities));
for (UINT16 i = 0; i < numCapabilities; i++)
{
RDPDR_CAPABILITY_HEADER header = WINPR_C_ARRAY_INIT;
UINT error = rdpdr_read_capset_header(rdpdr->log, s, &header);
if (error != CHANNEL_RC_OK)
return error;
switch (header.CapabilityType)
{
case CAP_GENERAL_TYPE:
rdpdr->capabilities[header.CapabilityType] = TRUE;
status = rdpdr_process_general_capset(rdpdr, s, &header);
break;
case CAP_PRINTER_TYPE:
rdpdr->capabilities[header.CapabilityType] = TRUE;
status = rdpdr_process_printer_capset(rdpdr, s, &header);
break;
case CAP_PORT_TYPE:
rdpdr->capabilities[header.CapabilityType] = TRUE;
status = rdpdr_process_port_capset(rdpdr, s, &header);
break;
case CAP_DRIVE_TYPE:
rdpdr->capabilities[header.CapabilityType] = TRUE;
status = rdpdr_process_drive_capset(rdpdr, s, &header);
break;
case CAP_SMARTCARD_TYPE:
rdpdr->capabilities[header.CapabilityType] = TRUE;
status = rdpdr_process_smartcard_capset(rdpdr, s, &header);
break;
default:
break;
}
if (status != CHANNEL_RC_OK)
return status;
}
return CHANNEL_RC_OK;
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
UINT rdpdr_send_capability_response(rdpdrPlugin* rdpdr)
{
WINPR_ASSERT(rdpdr);
WINPR_ASSERT(rdpdr->rdpcontext);
rdpSettings* settings = rdpdr->rdpcontext->settings;
WINPR_ASSERT(settings);
wStream* s = StreamPool_Take(rdpdr->pool, 256);
if (!s)
{
WLog_Print(rdpdr->log, WLOG_ERROR, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
const RDPDR_DEVICE* cdrives =
freerdp_device_collection_find_type(settings, RDPDR_DTYP_FILESYSTEM);
const RDPDR_DEVICE* cserial = freerdp_device_collection_find_type(settings, RDPDR_DTYP_SERIAL);
const RDPDR_DEVICE* cparallel =
freerdp_device_collection_find_type(settings, RDPDR_DTYP_PARALLEL);
const RDPDR_DEVICE* csmart =
freerdp_device_collection_find_type(settings, RDPDR_DTYP_SMARTCARD);
const RDPDR_DEVICE* cprinter = freerdp_device_collection_find_type(settings, RDPDR_DTYP_PRINT);
/* Only send capabilities the server announced */
const BOOL drives = cdrives && rdpdr->capabilities[CAP_DRIVE_TYPE];
const BOOL serial = cserial && rdpdr->capabilities[CAP_PORT_TYPE];
const BOOL parallel = cparallel && rdpdr->capabilities[CAP_PORT_TYPE];
const BOOL smart = csmart && rdpdr->capabilities[CAP_SMARTCARD_TYPE];
const BOOL printer = cprinter && rdpdr->capabilities[CAP_PRINTER_TYPE];
UINT16 count = 1;
if (drives)
count++;
if (serial || parallel)
count++;
if (smart)
count++;
if (printer)
count++;
Stream_Write_UINT16(s, RDPDR_CTYP_CORE);
Stream_Write_UINT16(s, PAKID_CORE_CLIENT_CAPABILITY);
Stream_Write_UINT16(s, count); /* numCapabilities */
Stream_Write_UINT16(s, 0); /* pad */
if (!rdpdr_write_general_capset(rdpdr, s))
goto fail;
if (printer)
{
if (!rdpdr_write_printer_capset(rdpdr, s))
goto fail;
}
if (serial || parallel)
{
if (!rdpdr_write_port_capset(rdpdr, s))
goto fail;
}
if (drives)
{
if (!rdpdr_write_drive_capset(rdpdr, s))
goto fail;
}
if (smart)
{
if (!rdpdr_write_smartcard_capset(rdpdr, s))
goto fail;
}
return rdpdr_send(rdpdr, s);
fail:
Stream_Release(s);
return ERROR_OUTOFMEMORY;
}

View File

@@ -0,0 +1,36 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
*/
#ifndef FREERDP_CHANNEL_RDPDR_CLIENT_CAPABILITIES_H
#define FREERDP_CHANNEL_RDPDR_CLIENT_CAPABILITIES_H
#include <winpr/wtypes.h>
#include "rdpdr_main.h"
WINPR_ATTR_NODISCARD
FREERDP_LOCAL UINT rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* s);
WINPR_ATTR_NODISCARD
FREERDP_LOCAL UINT rdpdr_send_capability_response(rdpdrPlugin* rdpdr);
#endif /* FREERDP_CHANNEL_RDPDR_CLIENT_CAPABILITIES_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,127 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel
*
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
* Copyright 2016 Inuvika Inc.
* Copyright 2016 David PHAM-VAN <d.phamvan@inuvika.com>
*
* 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.
*/
#ifndef FREERDP_CHANNEL_RDPDR_CLIENT_MAIN_H
#define FREERDP_CHANNEL_RDPDR_CLIENT_MAIN_H
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/stream.h>
#include <winpr/collections.h>
#include <freerdp/api.h>
#include <freerdp/svc.h>
#include <freerdp/addin.h>
#include <freerdp/channels/rdpdr.h>
#include <freerdp/client/rdpdr.h>
#include <freerdp/channels/log.h>
#ifdef __MACOSX__
#include <CoreServices/CoreServices.h>
#endif
enum RDPDR_CHANNEL_STATE
{
RDPDR_CHANNEL_STATE_INITIAL = 0,
RDPDR_CHANNEL_STATE_ANNOUNCE,
RDPDR_CHANNEL_STATE_ANNOUNCE_REPLY,
RDPDR_CHANNEL_STATE_NAME_REQUEST,
RDPDR_CHANNEL_STATE_SERVER_CAPS,
RDPDR_CHANNEL_STATE_CLIENT_CAPS,
RDPDR_CHANNEL_STATE_CLIENTID_CONFIRM,
RDPDR_CHANNEL_STATE_READY,
RDPDR_CHANNEL_STATE_USER_LOGGEDON
};
typedef struct
{
CHANNEL_DEF channelDef;
CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints;
enum RDPDR_CHANNEL_STATE state;
HANDLE thread;
wStream* data_in;
void* InitHandle;
DWORD OpenHandle;
wMessageQueue* queue;
DEVMAN* devman;
BOOL ignoreInvalidDevices;
UINT32 serverOsType;
UINT32 serverOsVersion;
UINT16 serverVersionMajor;
UINT16 serverVersionMinor;
UINT32 serverExtendedPDU;
UINT32 serverIOCode1;
UINT32 serverIOCode2;
UINT32 serverExtraFlags1;
UINT32 serverExtraFlags2;
UINT32 serverSpecialTypeDeviceCap;
UINT32 clientOsType;
UINT32 clientOsVersion;
UINT16 clientVersionMajor;
UINT16 clientVersionMinor;
UINT32 clientExtendedPDU;
UINT32 clientIOCode1;
UINT32 clientIOCode2;
UINT32 clientExtraFlags1;
UINT32 clientExtraFlags2;
UINT32 clientSpecialTypeDeviceCap;
UINT32 clientID;
char computerName[256];
UINT32 sequenceId;
BOOL userLoggedOn;
/* hotplug support */
HANDLE hotplugThread;
#ifdef _WIN32
HWND hotplug_wnd;
#endif
#ifndef _WIN32
HANDLE stopEvent;
#endif
rdpContext* rdpcontext;
wStreamPool* pool;
wLog* log;
BOOL async;
BOOL capabilities[6];
BOOL haveClientId;
BOOL haveServerCaps;
RdpdrClientContext context;
} rdpdrPlugin;
WINPR_ATTR_NODISCARD
FREERDP_LOCAL BOOL rdpdr_state_advance(rdpdrPlugin* rdpdr, enum RDPDR_CHANNEL_STATE next);
WINPR_ATTR_NODISCARD
FREERDP_LOCAL UINT rdpdr_send(rdpdrPlugin* rdpdr, wStream* s);
#endif /* FREERDP_CHANNEL_RDPDR_CLIENT_MAIN_H */

View File

@@ -0,0 +1,25 @@
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP cmake build script
#
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# 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.
define_channel_server("rdpdr")
set(${MODULE_PREFIX}_SRCS rdpdr_main.c rdpdr_main.h)
set(${MODULE_PREFIX}_LIBS freerdp)
option(WITH_WCHAR_FILE_DIRECTORY_INFORMATION "Build with WCHAR FILE_DIRECTORY_INFORMATION::FileName" OFF)
add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry")

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,47 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Device Redirection Virtual Channel Extension
*
* Copyright 2014 Dell Software <Mike.McDonald@software.dell.com>
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2015 Thincast Technologies GmbH
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
*/
#ifndef FREERDP_CHANNEL_RDPDR_SERVER_MAIN_H
#define FREERDP_CHANNEL_RDPDR_SERVER_MAIN_H
#include <winpr/collections.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <freerdp/settings.h>
#include <freerdp/server/rdpdr.h>
typedef struct S_RDPDR_IRP
{
UINT32 CompletionId;
UINT32 DeviceId;
UINT32 FileId;
char PathName[256];
char ExtraBuffer[256];
void* CallbackData;
UINT(*Callback)
(RdpdrServerContext* context, wStream* s, struct S_RDPDR_IRP* irp, UINT32 deviceId,
UINT32 completionId, UINT32 ioStatus);
} RDPDR_IRP;
#endif /* FREERDP_CHANNEL_RDPDR_SERVER_MAIN_H */