mirror of https://github.com/FreeRDP/FreeRDP
Cleanups (#7239)
* Use freerdp_settings_* for shadow and sample server * Added freerdp_peer_set_local_and_hostname * Code cleanups and WINPR_ASSERT * Code cleanups * Use CHANNEL_NAME_LEN where appropriate * Use temporary variables in loop instead of direct array access
This commit is contained in:
parent
5afa592244
commit
617293e0d3
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <winpr/sspi.h>
|
||||
#include <winpr/ntlm.h>
|
||||
#include <winpr/winsock.h>
|
||||
|
||||
typedef BOOL (*psPeerContextNew)(freerdp_peer* peer, rdpContext* context);
|
||||
typedef void (*psPeerContextFree)(freerdp_peer* peer, rdpContext* context);
|
||||
|
@ -145,6 +146,8 @@ extern "C"
|
|||
|
||||
FREERDP_API freerdp_peer* freerdp_peer_new(int sockfd);
|
||||
FREERDP_API void freerdp_peer_free(freerdp_peer* client);
|
||||
FREERDP_API BOOL freerdp_peer_set_local_and_hostname(freerdp_peer* client,
|
||||
const struct sockaddr_storage* peer_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -57,13 +57,14 @@ BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, const BYTE* data, size_
|
|||
UINT32 flags;
|
||||
size_t chunkSize;
|
||||
rdpMcs* mcs = rdp->mcs;
|
||||
rdpMcsChannel* channel = NULL;
|
||||
const rdpMcsChannel* channel = NULL;
|
||||
|
||||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
if (mcs->channels[i].ChannelId == channelId)
|
||||
const rdpMcsChannel* cur = &mcs->channels[i];
|
||||
if (cur->ChannelId == channelId)
|
||||
{
|
||||
channel = &mcs->channels[i];
|
||||
channel = cur;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ static CHANNEL_OPEN_DATA* freerdp_channels_find_channel_open_data_by_name(rdpCha
|
|||
{
|
||||
pChannelOpenData = &channels->openDataList[index];
|
||||
|
||||
if (strncmp(name, pChannelOpenData->name, CHANNEL_NAME_LEN) == 0)
|
||||
if (strncmp(name, pChannelOpenData->name, CHANNEL_NAME_LEN + 1) == 0)
|
||||
return pChannelOpenData;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,6 @@ static CHANNEL_OPEN_DATA* freerdp_channels_find_channel_open_data_by_name(rdpCha
|
|||
static rdpMcsChannel* freerdp_channels_find_channel_by_name(rdpRdp* rdp, const char* name)
|
||||
{
|
||||
UINT32 index;
|
||||
rdpMcsChannel* channel = NULL;
|
||||
rdpMcs* mcs = NULL;
|
||||
|
||||
if (!rdp)
|
||||
|
@ -76,9 +75,9 @@ static rdpMcsChannel* freerdp_channels_find_channel_by_name(rdpRdp* rdp, const c
|
|||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
channel = &mcs->channels[index];
|
||||
rdpMcsChannel* channel = &mcs->channels[index];
|
||||
|
||||
if (strncmp(name, channel->Name, CHANNEL_NAME_LEN) == 0)
|
||||
if (strncmp(name, channel->Name, CHANNEL_NAME_LEN + 1) == 0)
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
@ -471,9 +470,11 @@ BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* cdat
|
|||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
if (mcs->channels[index].ChannelId == channelId)
|
||||
rdpMcsChannel* cur = &mcs->channels[index];
|
||||
|
||||
if (cur->ChannelId == channelId)
|
||||
{
|
||||
channel = &mcs->channels[index];
|
||||
channel = cur;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -837,8 +838,9 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelInitEx(
|
|||
|
||||
if (settings->ChannelCount < CHANNEL_MAX_COUNT)
|
||||
{
|
||||
CHANNEL_DEF* channel = &settings->ChannelDefArray[settings->ChannelCount];
|
||||
strncpy(channel->name, pChannelDef->name, 7);
|
||||
CHANNEL_DEF* channel = freerdp_settings_get_pointer_array_writable(
|
||||
settings, FreeRDP_ChannelDefArray, settings->ChannelCount);
|
||||
strncpy(channel->name, pChannelDef->name, CHANNEL_NAME_LEN);
|
||||
channel->options = pChannelDef->options;
|
||||
settings->ChannelCount++;
|
||||
}
|
||||
|
@ -928,8 +930,9 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelInit(LPVOID* ppInitHandle, PCHANNEL_
|
|||
|
||||
if (settings->ChannelCount < CHANNEL_MAX_COUNT)
|
||||
{
|
||||
channel = &settings->ChannelDefArray[settings->ChannelCount];
|
||||
strncpy(channel->name, pChannelDef->name, 7);
|
||||
channel = freerdp_settings_get_pointer_array_writable(settings, FreeRDP_ChannelDefArray,
|
||||
settings->ChannelCount);
|
||||
strncpy(channel->name, pChannelDef->name, CHANNEL_NAME_LEN);
|
||||
channel->options = pChannelDef->options;
|
||||
settings->ChannelCount++;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/stream.h>
|
||||
#include <winpr/wtsapi.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/constants.h>
|
||||
|
@ -52,7 +53,7 @@ typedef struct rdp_channel_client_data CHANNEL_CLIENT_DATA;
|
|||
|
||||
struct rdp_channel_open_data
|
||||
{
|
||||
char name[8];
|
||||
char name[CHANNEL_NAME_LEN + 1];
|
||||
int OpenHandle;
|
||||
int options;
|
||||
int flags;
|
||||
|
|
|
@ -908,7 +908,8 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
|
|||
{
|
||||
if (mcs->channelCount > 0)
|
||||
{
|
||||
if (!mcs_send_channel_join_request(mcs, mcs->channels[0].ChannelId))
|
||||
const rdpMcsChannel* cur = &mcs->channels[0];
|
||||
if (!mcs_send_channel_join_request(mcs, cur->ChannelId))
|
||||
return FALSE;
|
||||
|
||||
allJoined = FALSE;
|
||||
|
@ -924,7 +925,8 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
|
|||
|
||||
if (mcs->channelCount > 0)
|
||||
{
|
||||
if (!mcs_send_channel_join_request(mcs, mcs->channels[0].ChannelId))
|
||||
const rdpMcsChannel* cur = &mcs->channels[0];
|
||||
if (!mcs_send_channel_join_request(mcs, cur->ChannelId))
|
||||
return FALSE;
|
||||
|
||||
allJoined = FALSE;
|
||||
|
@ -934,19 +936,21 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
|
|||
{
|
||||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
if (mcs->channels[i].joined)
|
||||
rdpMcsChannel* cur = &mcs->channels[i];
|
||||
if (cur->joined)
|
||||
continue;
|
||||
|
||||
if (mcs->channels[i].ChannelId != channelId)
|
||||
if (cur->ChannelId != channelId)
|
||||
return FALSE;
|
||||
|
||||
mcs->channels[i].joined = TRUE;
|
||||
cur->joined = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i + 1 < mcs->channelCount)
|
||||
{
|
||||
if (!mcs_send_channel_join_request(mcs, mcs->channels[i + 1].ChannelId))
|
||||
const rdpMcsChannel* cur = &mcs->channels[i + 1];
|
||||
if (!mcs_send_channel_join_request(mcs, cur->ChannelId))
|
||||
return FALSE;
|
||||
|
||||
allJoined = FALSE;
|
||||
|
@ -1327,7 +1331,8 @@ BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, wStream* s)
|
|||
|
||||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
WLog_INFO(TAG, " %s", mcs->channels[i].Name);
|
||||
rdpMcsChannel* cur = &mcs->channels[i];
|
||||
WLog_INFO(TAG, " %s", cur->Name);
|
||||
}
|
||||
|
||||
if (!mcs_send_connect_response(mcs))
|
||||
|
@ -1380,10 +1385,11 @@ BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, wStream* s)
|
|||
|
||||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
if (mcs->channels[i].ChannelId == channelId)
|
||||
mcs->channels[i].joined = TRUE;
|
||||
rdpMcsChannel* cur = &mcs->channels[i];
|
||||
if (cur->ChannelId == channelId)
|
||||
cur->joined = TRUE;
|
||||
|
||||
if (!mcs->channels[i].joined)
|
||||
if (!cur->joined)
|
||||
allJoined = FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1584,9 +1584,10 @@ BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
|
|||
* of seven ANSI characters that uniquely identify the channel.
|
||||
* - options: a 32-bit, unsigned integer. Channel option flags
|
||||
*/
|
||||
Stream_Read(s, mcs->channels[i].Name, 8); /* name (8 bytes) */
|
||||
rdpMcsChannel* channel = &mcs->channels[i];
|
||||
Stream_Read(s, channel->Name, CHANNEL_NAME_LEN + 1); /* name (8 bytes) */
|
||||
|
||||
if (!memchr(mcs->channels[i].Name, 0, 8))
|
||||
if (!memchr(channel->Name, 0, CHANNEL_NAME_LEN + 1))
|
||||
{
|
||||
WLog_ERR(
|
||||
TAG,
|
||||
|
@ -1594,8 +1595,8 @@ BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
Stream_Read_UINT32(s, mcs->channels[i].options); /* options (4 bytes) */
|
||||
mcs->channels[i].ChannelId = mcs->baseChannelId++;
|
||||
Stream_Read_UINT32(s, channel->options); /* options (4 bytes) */
|
||||
channel->ChannelId = mcs->baseChannelId++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -1624,8 +1625,9 @@ BOOL gcc_write_client_network_data(wStream* s, const rdpMcs* mcs)
|
|||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
/* CHANNEL_DEF */
|
||||
Stream_Write(s, mcs->channels[i].Name, 8); /* name (8 bytes) */
|
||||
Stream_Write_UINT32(s, mcs->channels[i].options); /* options (4 bytes) */
|
||||
rdpMcsChannel* channel = &mcs->channels[i];
|
||||
Stream_Write(s, channel->Name, CHANNEL_NAME_LEN + 1); /* name (8 bytes) */
|
||||
Stream_Write_UINT32(s, channel->options); /* options (4 bytes) */
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -1662,8 +1664,9 @@ BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs)
|
|||
|
||||
for (i = 0; i < parsedChannelCount; i++)
|
||||
{
|
||||
rdpMcsChannel* channel = &mcs->channels[i];
|
||||
Stream_Read_UINT16(s, channelId); /* channelId */
|
||||
mcs->channels[i].ChannelId = channelId;
|
||||
channel->ChannelId = channelId;
|
||||
}
|
||||
|
||||
if (channelCount % 2 == 1)
|
||||
|
@ -1685,7 +1688,8 @@ BOOL gcc_write_server_network_data(wStream* s, const rdpMcs* mcs)
|
|||
|
||||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
Stream_Write_UINT16(s, mcs->channels[i].ChannelId);
|
||||
const rdpMcsChannel* channel = &mcs->channels[i];
|
||||
Stream_Write_UINT16(s, channel->ChannelId);
|
||||
}
|
||||
|
||||
if (mcs->channelCount % 2 == 1)
|
||||
|
|
|
@ -295,16 +295,49 @@ static DWORD freerdp_listener_get_event_handles(freerdp_listener* instance, HAND
|
|||
return listener->num_sockfds;
|
||||
}
|
||||
|
||||
BOOL freerdp_peer_set_local_and_hostname(freerdp_peer* client,
|
||||
const struct sockaddr_storage* peer_addr)
|
||||
{
|
||||
void* sin_addr = NULL;
|
||||
const BYTE localhost6_bytes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
|
||||
WINPR_ASSERT(client);
|
||||
WINPR_ASSERT(peer_addr);
|
||||
|
||||
if (peer_addr->ss_family == AF_INET)
|
||||
{
|
||||
sin_addr = &(((struct sockaddr_in*)&peer_addr)->sin_addr);
|
||||
|
||||
if ((*(UINT32*)sin_addr) == 0x0100007f)
|
||||
client->local = TRUE;
|
||||
}
|
||||
else if (peer_addr->ss_family == AF_INET6)
|
||||
{
|
||||
sin_addr = &(((struct sockaddr_in6*)&peer_addr)->sin6_addr);
|
||||
|
||||
if (memcmp(sin_addr, localhost6_bytes, 16) == 0)
|
||||
client->local = TRUE;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
else if (peer_addr->ss_family == AF_UNIX)
|
||||
client->local = TRUE;
|
||||
#endif
|
||||
|
||||
if (sin_addr)
|
||||
inet_ntop(peer_addr->ss_family, sin_addr, client->hostname, sizeof(client->hostname));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
|
||||
{
|
||||
int i;
|
||||
void* sin_addr;
|
||||
int peer_sockfd;
|
||||
freerdp_peer* client = NULL;
|
||||
int peer_addr_size;
|
||||
struct sockaddr_storage peer_addr;
|
||||
rdpListener* listener = (rdpListener*)instance->listener;
|
||||
static const BYTE localhost6_bytes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
BOOL peer_accepted;
|
||||
|
||||
if (listener->num_sockfds < 1)
|
||||
|
@ -345,31 +378,12 @@ static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
sin_addr = NULL;
|
||||
|
||||
if (peer_addr.ss_family == AF_INET)
|
||||
if (!freerdp_peer_set_local_and_hostname(client, &peer_addr))
|
||||
{
|
||||
sin_addr = &(((struct sockaddr_in*)&peer_addr)->sin_addr);
|
||||
|
||||
if ((*(UINT32*)sin_addr) == 0x0100007f)
|
||||
client->local = TRUE;
|
||||
closesocket((SOCKET)peer_sockfd);
|
||||
freerdp_peer_free(client);
|
||||
return FALSE;
|
||||
}
|
||||
else if (peer_addr.ss_family == AF_INET6)
|
||||
{
|
||||
sin_addr = &(((struct sockaddr_in6*)&peer_addr)->sin6_addr);
|
||||
|
||||
if (memcmp(sin_addr, localhost6_bytes, 16) == 0)
|
||||
client->local = TRUE;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
else if (peer_addr.ss_family == AF_UNIX)
|
||||
client->local = TRUE;
|
||||
|
||||
#endif
|
||||
|
||||
if (sin_addr)
|
||||
inet_ntop(peer_addr.ss_family, sin_addr, client->hostname, sizeof(client->hostname));
|
||||
|
||||
IFCALLRET(instance->PeerAccepted, peer_accepted, instance, client);
|
||||
|
||||
|
|
|
@ -218,8 +218,12 @@ static int mcs_initialize_client_channels(rdpMcs* mcs, rdpSettings* settings)
|
|||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
CopyMemory(mcs->channels[index].Name, settings->ChannelDefArray[index].name, 8);
|
||||
mcs->channels[index].options = settings->ChannelDefArray[index].options;
|
||||
const CHANNEL_DEF* defchannel =
|
||||
freerdp_settings_get_pointer_array(settings, FreeRDP_ChannelDefArray, index);
|
||||
rdpMcsChannel* cur = &mcs->channels[index];
|
||||
WINPR_ASSERT(defchannel);
|
||||
CopyMemory(cur->Name, defchannel->name, CHANNEL_NAME_LEN);
|
||||
cur->options = defchannel->options;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -31,6 +31,7 @@ typedef struct rdp_mcs rdpMcs;
|
|||
#include <freerdp/types.h>
|
||||
|
||||
#include <winpr/stream.h>
|
||||
#include <winpr/wtsapi.h>
|
||||
|
||||
#define MCS_BASE_CHANNEL_ID 1001
|
||||
#define MCS_GLOBAL_CHANNEL_ID 1003
|
||||
|
@ -118,7 +119,7 @@ typedef struct
|
|||
|
||||
struct rdp_mcs_channel
|
||||
{
|
||||
char Name[8];
|
||||
char Name[CHANNEL_NAME_LEN + 1];
|
||||
UINT32 options;
|
||||
int ChannelId;
|
||||
BOOL joined;
|
||||
|
|
|
@ -67,13 +67,16 @@ static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm,
|
|||
int count;
|
||||
BOOL found = FALSE;
|
||||
rdpPeerChannel* channel = NULL;
|
||||
|
||||
WINPR_ASSERT(vcm);
|
||||
|
||||
ArrayList_Lock(vcm->dynamicVirtualChannels);
|
||||
count = ArrayList_Count(vcm->dynamicVirtualChannels);
|
||||
|
||||
for (index = 0; index < count; index++)
|
||||
{
|
||||
channel = (rdpPeerChannel*)ArrayList_GetItem(vcm->dynamicVirtualChannels, index);
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
if (channel->channelId == ChannelId)
|
||||
{
|
||||
found = TRUE;
|
||||
|
@ -89,6 +92,8 @@ static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer,
|
|||
{
|
||||
BYTE* buffer;
|
||||
wtsChannelMessage* messageCtx;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
messageCtx = (wtsChannelMessage*)malloc(sizeof(wtsChannelMessage) + Length);
|
||||
|
||||
if (!messageCtx)
|
||||
|
@ -107,6 +112,8 @@ static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Le
|
|||
BYTE* buffer;
|
||||
UINT32 length;
|
||||
UINT16 channelId;
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(channel->vcm);
|
||||
buffer = Buffer;
|
||||
length = Length;
|
||||
channelId = channel->channelId;
|
||||
|
@ -116,6 +123,8 @@ static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Le
|
|||
|
||||
static int wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
|
||||
{
|
||||
WINPR_ASSERT(s);
|
||||
WINPR_ASSERT(val);
|
||||
switch (cbLen)
|
||||
{
|
||||
case 0:
|
||||
|
@ -145,6 +154,8 @@ static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT
|
|||
{
|
||||
UINT16 Version;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(channel->vcm);
|
||||
if (length < 3)
|
||||
return FALSE;
|
||||
|
||||
|
@ -159,6 +170,8 @@ static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s
|
|||
{
|
||||
UINT32 CreationStatus;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(s);
|
||||
if (length < 4)
|
||||
return FALSE;
|
||||
|
||||
|
@ -183,6 +196,8 @@ static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int
|
|||
UINT32 length)
|
||||
{
|
||||
int value;
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(s);
|
||||
value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
|
||||
|
||||
if (value == 0)
|
||||
|
@ -206,6 +221,8 @@ static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 le
|
|||
{
|
||||
BOOL ret = FALSE;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(s);
|
||||
if (channel->dvc_total_length > 0)
|
||||
{
|
||||
if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
|
||||
|
@ -236,6 +253,7 @@ static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 le
|
|||
|
||||
static void wts_read_drdynvc_close_response(rdpPeerChannel* channel)
|
||||
{
|
||||
WINPR_ASSERT(channel);
|
||||
DEBUG_DVC("ChannelId %" PRIu32 " close response", channel->channelId);
|
||||
channel->dvc_open_state = DVC_OPEN_STATE_CLOSED;
|
||||
MessageQueue_PostQuit(channel->queue, 0);
|
||||
|
@ -250,6 +268,10 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
|
|||
int cbChId;
|
||||
UINT32 ChannelId;
|
||||
rdpPeerChannel* dvc;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(channel->vcm);
|
||||
|
||||
length = Stream_GetPosition(channel->receiveData);
|
||||
|
||||
if (length < 1)
|
||||
|
@ -316,6 +338,7 @@ static int wts_write_variable_uint(wStream* s, UINT32 val)
|
|||
{
|
||||
int cb;
|
||||
|
||||
WINPR_ASSERT(s);
|
||||
if (val <= 0xFF)
|
||||
{
|
||||
cb = 0;
|
||||
|
@ -339,6 +362,9 @@ static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId)
|
|||
{
|
||||
BYTE* bm;
|
||||
int cbChId;
|
||||
|
||||
WINPR_ASSERT(s);
|
||||
|
||||
Stream_GetPointer(s, bm);
|
||||
Stream_Seek_UINT8(s);
|
||||
cbChId = wts_write_variable_uint(s, ChannelId);
|
||||
|
@ -348,6 +374,10 @@ static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId)
|
|||
static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId, const char* ChannelName)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
WINPR_ASSERT(s);
|
||||
WINPR_ASSERT(ChannelName);
|
||||
|
||||
wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
|
||||
len = strlen(ChannelName) + 1;
|
||||
|
||||
|
@ -365,6 +395,8 @@ static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, con
|
|||
const size_t size = (size_t)s;
|
||||
const size_t totalSize = (size_t)t;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
WINPR_ASSERT(channel->vcm);
|
||||
WINPR_UNUSED(channelId);
|
||||
|
||||
if (flags & CHANNEL_FLAG_FIRST)
|
||||
|
@ -404,13 +436,20 @@ static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const
|
|||
size_t size, UINT32 flags, size_t totalSize)
|
||||
{
|
||||
UINT32 i;
|
||||
rdpMcs* mcs = client->context->rdp->mcs;
|
||||
rdpMcs* mcs;
|
||||
|
||||
WINPR_ASSERT(client);
|
||||
WINPR_ASSERT(client->context);
|
||||
WINPR_ASSERT(client->context->rdp);
|
||||
mcs = client->context->rdp->mcs;
|
||||
WINPR_ASSERT(mcs);
|
||||
|
||||
for (i = 0; i < mcs->channelCount; i++)
|
||||
{
|
||||
if (mcs->channels[i].ChannelId == channelId)
|
||||
rdpMcsChannel* cur = &mcs->channels[i];
|
||||
if (cur->ChannelId == channelId)
|
||||
{
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*)mcs->channels[i].handle;
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle;
|
||||
|
||||
if (channel)
|
||||
return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize);
|
||||
|
@ -426,6 +465,10 @@ void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int*
|
|||
{
|
||||
void* fd;
|
||||
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
||||
WINPR_ASSERT(vcm);
|
||||
WINPR_ASSERT(fds);
|
||||
WINPR_ASSERT(fds_count);
|
||||
|
||||
fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
|
||||
|
||||
if (fd)
|
||||
|
@ -455,6 +498,8 @@ static BOOL WTSVirtualChannelManagerOpen(WTSVirtualChannelManager* vcm)
|
|||
if (!vcm)
|
||||
return FALSE;
|
||||
|
||||
WINPR_ASSERT(vcm->client);
|
||||
|
||||
if ((vcm->drdynvc_state == DRDYNVC_STATE_NONE) && vcm->client->activated)
|
||||
{
|
||||
rdpPeerChannel* channel;
|
||||
|
@ -527,6 +572,7 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
|
|||
HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
|
||||
{
|
||||
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
||||
WINPR_ASSERT(vcm);
|
||||
return MessageQueue_Event(vcm->queue);
|
||||
}
|
||||
|
||||
|
@ -534,16 +580,16 @@ static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* ch
|
|||
{
|
||||
UINT32 index;
|
||||
|
||||
if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN))
|
||||
if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1))
|
||||
return NULL;
|
||||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
if (mcs->channels[index].joined)
|
||||
rdpMcsChannel* mchannel = &mcs->channels[index];
|
||||
if (mchannel->joined)
|
||||
{
|
||||
if (_strnicmp(mcs->channels[index].Name, channel_name,
|
||||
strnlen(channel_name, CHANNEL_NAME_LEN)) == 0)
|
||||
return &mcs->channels[index];
|
||||
if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0)
|
||||
return mchannel;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,11 +603,13 @@ static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 cha
|
|||
if (!mcs || !channel_id)
|
||||
return NULL;
|
||||
|
||||
WINPR_ASSERT(mcs->channels);
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
if (mcs->channels[index].joined)
|
||||
rdpMcsChannel* mchannel = &mcs->channels[index];
|
||||
if (mchannel->joined)
|
||||
{
|
||||
if (mcs->channels[index].ChannelId == channel_id)
|
||||
if (mchannel->ChannelId == channel_id)
|
||||
return &mcs->channels[index];
|
||||
}
|
||||
}
|
||||
|
@ -600,6 +648,7 @@ BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
|
|||
BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
|
||||
{
|
||||
WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer;
|
||||
WINPR_ASSERT(vcm);
|
||||
return vcm->drdynvc_state;
|
||||
}
|
||||
|
||||
|
@ -607,6 +656,7 @@ UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
|
|||
{
|
||||
rdpMcsChannel* channel;
|
||||
|
||||
WINPR_ASSERT(channel_name);
|
||||
if (!client || !client->context || !client->context->rdp)
|
||||
return 0;
|
||||
|
||||
|
@ -622,6 +672,7 @@ BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, v
|
|||
{
|
||||
rdpMcsChannel* channel;
|
||||
|
||||
WINPR_ASSERT(channel_name);
|
||||
if (!client || !client->context || !client->context->rdp)
|
||||
return FALSE;
|
||||
|
||||
|
@ -654,6 +705,7 @@ void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name)
|
|||
{
|
||||
rdpMcsChannel* channel;
|
||||
|
||||
WINPR_ASSERT(channel_name);
|
||||
if (!client || !client->context || !client->context->rdp)
|
||||
return NULL;
|
||||
|
||||
|
@ -704,7 +756,9 @@ char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count)
|
|||
if (!client || !client->context || !count)
|
||||
return NULL;
|
||||
|
||||
WINPR_ASSERT(client->context->rdp);
|
||||
mcs = client->context->rdp->mcs;
|
||||
WINPR_ASSERT(mcs);
|
||||
*count = mcs->channelCount;
|
||||
|
||||
names = (char**)calloc(mcs->channelCount, sizeof(char*));
|
||||
|
@ -712,7 +766,10 @@ char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count)
|
|||
return NULL;
|
||||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
names[index] = mcs->channels[index].Name;
|
||||
{
|
||||
rdpMcsChannel* mchannel = &mcs->channels[index];
|
||||
names[index] = mchannel->Name;
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
@ -1068,6 +1125,9 @@ static rdpPeerChannel* channel_new(WTSVirtualChannelManager* vcm, freerdp_peer*
|
|||
wObject queueCallbacks = { 0 };
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1, sizeof(rdpPeerChannel));
|
||||
|
||||
WINPR_ASSERT(vcm);
|
||||
WINPR_ASSERT(client);
|
||||
|
||||
if (!channel)
|
||||
goto fail;
|
||||
|
||||
|
@ -1098,7 +1158,7 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
|
|||
size_t length;
|
||||
UINT32 index;
|
||||
rdpMcs* mcs;
|
||||
BOOL joined = FALSE;
|
||||
rdpMcsChannel* joined_channel = NULL;
|
||||
freerdp_peer* client;
|
||||
rdpPeerChannel* channel;
|
||||
WTSVirtualChannelManager* vcm;
|
||||
|
@ -1123,31 +1183,31 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
|
|||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
if (mcs->channels[index].joined &&
|
||||
(strncmp(mcs->channels[index].Name, pVirtualName, length) == 0))
|
||||
rdpMcsChannel* mchannel = &mcs->channels[index];
|
||||
if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0))
|
||||
{
|
||||
joined = TRUE;
|
||||
joined_channel = mchannel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!joined)
|
||||
if (!joined_channel)
|
||||
{
|
||||
SetLastError(ERROR_NOT_FOUND);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
channel = (rdpPeerChannel*)mcs->channels[index].handle;
|
||||
channel = (rdpPeerChannel*)joined_channel->handle;
|
||||
|
||||
if (!channel)
|
||||
{
|
||||
channel = channel_new(vcm, client, mcs->channels[index].ChannelId, index,
|
||||
channel = channel_new(vcm, client, joined_channel->ChannelId, index,
|
||||
RDP_PEER_CHANNEL_TYPE_SVC, client->settings->VirtualChannelChunkSize);
|
||||
|
||||
if (!channel)
|
||||
goto fail;
|
||||
|
||||
mcs->channels[index].handle = channel;
|
||||
joined_channel->handle = channel;
|
||||
}
|
||||
|
||||
hChannelHandle = (HANDLE)channel;
|
||||
|
@ -1188,7 +1248,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
|
|||
|
||||
for (index = 0; index < mcs->channelCount; index++)
|
||||
{
|
||||
if (mcs->channels[index].joined && (strncmp(mcs->channels[index].Name, "drdynvc", 7) == 0))
|
||||
rdpMcsChannel* mchannel = &mcs->channels[index];
|
||||
if (mchannel->joined && (strncmp(mchannel->Name, "drdynvc", CHANNEL_NAME_LEN + 1) == 0))
|
||||
{
|
||||
joined = TRUE;
|
||||
break;
|
||||
|
@ -1248,19 +1309,27 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
|
|||
{
|
||||
wStream* s;
|
||||
rdpMcs* mcs;
|
||||
WTSVirtualChannelManager* vcm;
|
||||
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
||||
BOOL ret = TRUE;
|
||||
|
||||
if (channel)
|
||||
{
|
||||
vcm = channel->vcm;
|
||||
WTSVirtualChannelManager* vcm = channel->vcm;
|
||||
|
||||
WINPR_ASSERT(vcm);
|
||||
WINPR_ASSERT(vcm->client);
|
||||
WINPR_ASSERT(vcm->client->context);
|
||||
WINPR_ASSERT(vcm->client->context->rdp);
|
||||
mcs = vcm->client->context->rdp->mcs;
|
||||
|
||||
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
||||
{
|
||||
if (channel->index < mcs->channelCount)
|
||||
mcs->channels[channel->index].handle = NULL;
|
||||
{
|
||||
rdpMcsChannel* cur = &mcs->channels[channel->index];
|
||||
cur->handle = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1309,6 +1378,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut,
|
|||
wtsChannelMessage* messageCtx;
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
|
||||
if (!MessageQueue_Peek(channel->queue, &message, FALSE))
|
||||
{
|
||||
SetLastError(ERROR_NO_DATA);
|
||||
|
@ -1361,6 +1432,7 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
|
|||
if (!channel)
|
||||
return FALSE;
|
||||
|
||||
WINPR_ASSERT(channel->vcm);
|
||||
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
|
||||
{
|
||||
length = Length;
|
||||
|
@ -1384,7 +1456,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
|
|||
else
|
||||
{
|
||||
first = TRUE;
|
||||
|
||||
WINPR_ASSERT(channel->client);
|
||||
WINPR_ASSERT(channel->client->settings);
|
||||
while (Length > 0)
|
||||
{
|
||||
s = Stream_New(NULL, channel->client->settings->VirtualChannelChunkSize);
|
||||
|
@ -1447,12 +1520,14 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CL
|
|||
{
|
||||
void* pfd;
|
||||
BOOL bval;
|
||||
void* fds[10];
|
||||
void* fds[10] = { 0 };
|
||||
HANDLE hEvent;
|
||||
int fds_count = 0;
|
||||
BOOL status = FALSE;
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle;
|
||||
ZeroMemory(fds, sizeof(fds));
|
||||
|
||||
WINPR_ASSERT(channel);
|
||||
|
||||
hEvent = MessageQueue_Event(channel->queue);
|
||||
|
||||
switch ((UINT32)WtsVirtualClass)
|
||||
|
|
|
@ -791,12 +791,9 @@ static DWORD WINAPI test_peer_mainloop(LPVOID arg)
|
|||
}
|
||||
|
||||
/* Initialize the real server settings here */
|
||||
client->settings->CertificateFile = _strdup("server.crt");
|
||||
client->settings->PrivateKeyFile = _strdup("server.key");
|
||||
client->settings->RdpKeyFile = _strdup("server.key");
|
||||
|
||||
if (!client->settings->CertificateFile || !client->settings->PrivateKeyFile ||
|
||||
!client->settings->RdpKeyFile)
|
||||
if (!freerdp_settings_set_string(client->settings, FreeRDP_CertificateFile, "server.crt") ||
|
||||
!freerdp_settings_set_string(client->settings, FreeRDP_PrivateKeyFile, "server.key") ||
|
||||
!freerdp_settings_set_string(client->settings, FreeRDP_RdpKeyFile, "server.key"))
|
||||
{
|
||||
WLog_ERR(TAG, "Memory allocation failed (strdup)");
|
||||
freerdp_peer_free(client);
|
||||
|
|
|
@ -195,13 +195,13 @@ static BOOL shadow_client_context_new(freerdp_peer* peer, rdpContext* context)
|
|||
settings->DrawAllowDynamicColorFidelity = TRUE;
|
||||
settings->CompressionLevel = PACKET_COMPR_TYPE_RDP6;
|
||||
|
||||
if (!(settings->CertificateFile = _strdup(server->CertificateFile)))
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_CertificateFile, server->CertificateFile))
|
||||
goto fail_cert_file;
|
||||
|
||||
if (!(settings->PrivateKeyFile = _strdup(server->PrivateKeyFile)))
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_PrivateKeyFile, server->PrivateKeyFile))
|
||||
goto fail_privkey_file;
|
||||
|
||||
if (!(settings->RdpKeyFile = _strdup(settings->PrivateKeyFile)))
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_RdpKeyFile, server->PrivateKeyFile))
|
||||
goto fail_rdpkey_file;
|
||||
if (server->ipcSocket && (strncmp(bind_address, server->ipcSocket,
|
||||
strnlen(bind_address, sizeof(bind_address))) != 0))
|
||||
|
@ -243,14 +243,11 @@ fail_message_queue:
|
|||
fail_open_server:
|
||||
DeleteCriticalSection(&(client->lock));
|
||||
fail_client_lock:
|
||||
free(settings->RdpKeyFile);
|
||||
settings->RdpKeyFile = NULL;
|
||||
freerdp_settings_set_string(settings, FreeRDP_RdpKeyFile, NULL);
|
||||
fail_rdpkey_file:
|
||||
free(settings->PrivateKeyFile);
|
||||
settings->PrivateKeyFile = NULL;
|
||||
freerdp_settings_set_string(settings, FreeRDP_PrivateKeyFile, NULL);
|
||||
fail_privkey_file:
|
||||
free(settings->CertificateFile);
|
||||
settings->CertificateFile = NULL;
|
||||
freerdp_settings_set_string(settings, FreeRDP_CertificateFile, NULL);
|
||||
fail_cert_file:
|
||||
return FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue