2011-08-18 12:06:32 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-18 12:06:32 +04:00
|
|
|
* RDP Server Peer
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
2015-01-13 19:09:36 +03:00
|
|
|
* Copyright 2014 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2023-02-09 10:48:11 +03:00
|
|
|
* Copyright 2023 Armin Novak <anovak@thincast.com>
|
|
|
|
* Copyright 2023 Thincast Technologies GmbH
|
2011-08-18 12:06:32 +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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2023-10-16 13:59:19 +03:00
|
|
|
#include "settings.h"
|
|
|
|
|
2021-08-24 15:14:37 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-11-22 04:22:41 +04:00
|
|
|
#include <winpr/crt.h>
|
2014-11-12 22:06:34 +03:00
|
|
|
#include <winpr/winsock.h>
|
2012-11-22 04:22:41 +04:00
|
|
|
|
2013-07-19 01:15:10 +04:00
|
|
|
#include "info.h"
|
2022-10-21 11:31:14 +03:00
|
|
|
#include "display.h"
|
2012-11-22 04:22:41 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2021-09-23 15:52:03 +03:00
|
|
|
#include <freerdp/streamdump.h>
|
2023-01-16 12:56:10 +03:00
|
|
|
#include <freerdp/redirection.h>
|
2023-02-03 13:53:49 +03:00
|
|
|
#include <freerdp/crypto/certificate.h>
|
2012-02-17 09:58:30 +04:00
|
|
|
|
2017-05-31 12:31:36 +03:00
|
|
|
#include "rdp.h"
|
2011-08-18 12:06:32 +04:00
|
|
|
#include "peer.h"
|
2022-11-24 15:24:26 +03:00
|
|
|
#include "multitransport.h"
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.peer")
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_pdu(freerdp_peer* client, wStream* s);
|
2022-10-21 11:31:14 +03:00
|
|
|
|
2016-10-13 23:02:25 +03:00
|
|
|
static HANDLE freerdp_peer_virtual_channel_open(freerdp_peer* client, const char* name,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 flags)
|
2014-10-11 00:11:42 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 index = 0;
|
2014-10-11 00:11:42 +04:00
|
|
|
BOOL joined = FALSE;
|
|
|
|
rdpMcsChannel* mcsChannel = NULL;
|
|
|
|
rdpPeerChannel* peerChannel = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpMcs* mcs = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
|
|
|
WINPR_ASSERT(name);
|
|
|
|
mcs = client->context->rdp->mcs;
|
|
|
|
WINPR_ASSERT(mcs);
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
if (flags & WTS_CHANNEL_OPTION_DYNAMIC)
|
|
|
|
return NULL; /* not yet supported */
|
|
|
|
|
2023-06-21 12:58:28 +03:00
|
|
|
const size_t length = strnlen(name, 9);
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
if (length > 8)
|
|
|
|
return NULL; /* SVC maximum name length is 8 */
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (; index < mcs->channelCount; index++)
|
2014-10-11 00:11:42 +04:00
|
|
|
{
|
|
|
|
mcsChannel = &(mcs->channels[index]);
|
|
|
|
|
|
|
|
if (!mcsChannel->joined)
|
|
|
|
continue;
|
|
|
|
|
2015-02-23 17:24:43 +03:00
|
|
|
if (_strnicmp(name, mcsChannel->Name, length) == 0)
|
2014-10-11 00:11:42 +04:00
|
|
|
{
|
|
|
|
joined = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!joined)
|
|
|
|
return NULL; /* channel is not joined */
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
peerChannel = (rdpPeerChannel*)mcsChannel->handle;
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
if (peerChannel)
|
|
|
|
{
|
|
|
|
/* channel is already open */
|
2019-11-06 17:24:51 +03:00
|
|
|
return (HANDLE)peerChannel;
|
2014-10-11 00:11:42 +04:00
|
|
|
}
|
|
|
|
|
2023-12-16 22:52:11 +03:00
|
|
|
peerChannel = server_channel_common_new(client, index, mcsChannel->ChannelId, 128, NULL, name);
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
if (peerChannel)
|
|
|
|
{
|
|
|
|
peerChannel->channelFlags = flags;
|
|
|
|
peerChannel->mcsChannel = mcsChannel;
|
2019-11-06 17:24:51 +03:00
|
|
|
mcsChannel->handle = (void*)peerChannel;
|
2014-10-11 00:11:42 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return (HANDLE)peerChannel;
|
2014-10-11 00:11:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL freerdp_peer_virtual_channel_close(freerdp_peer* client, HANDLE hChannel)
|
|
|
|
{
|
|
|
|
rdpMcsChannel* mcsChannel = NULL;
|
|
|
|
rdpPeerChannel* peerChannel = NULL;
|
|
|
|
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
2014-10-11 00:11:42 +04:00
|
|
|
if (!hChannel)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
peerChannel = (rdpPeerChannel*)hChannel;
|
2014-10-11 00:11:42 +04:00
|
|
|
mcsChannel = peerChannel->mcsChannel;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(mcsChannel);
|
2014-10-11 00:11:42 +04:00
|
|
|
mcsChannel->handle = NULL;
|
2023-12-16 22:52:11 +03:00
|
|
|
server_channel_common_free(peerChannel);
|
2014-10-11 00:11:42 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-04 16:42:42 +03:00
|
|
|
static int freerdp_peer_virtual_channel_write(freerdp_peer* client, HANDLE hChannel,
|
|
|
|
const BYTE* buffer, UINT32 length)
|
2014-10-11 00:11:42 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
|
|
|
UINT32 flags = 0;
|
|
|
|
UINT32 chunkSize = 0;
|
|
|
|
UINT32 maxChunkSize = 0;
|
|
|
|
UINT32 totalLength = 0;
|
|
|
|
rdpPeerChannel* peerChannel = NULL;
|
|
|
|
rdpMcsChannel* mcsChannel = NULL;
|
|
|
|
rdpRdp* rdp = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(rdp->settings);
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
if (!hChannel)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
peerChannel = (rdpPeerChannel*)hChannel;
|
2014-11-08 02:06:14 +03:00
|
|
|
mcsChannel = peerChannel->mcsChannel;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(peerChannel);
|
|
|
|
WINPR_ASSERT(mcsChannel);
|
2014-10-11 00:11:42 +04:00
|
|
|
if (peerChannel->channelFlags & WTS_CHANNEL_OPTION_DYNAMIC)
|
|
|
|
return -1; /* not yet supported */
|
|
|
|
|
2023-11-02 18:41:00 +03:00
|
|
|
maxChunkSize = rdp->settings->VCChunkSize;
|
2014-10-11 00:11:42 +04:00
|
|
|
totalLength = length;
|
|
|
|
flags = CHANNEL_FLAG_FIRST;
|
|
|
|
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
s = rdp_send_stream_init(rdp);
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2015-03-26 19:09:47 +03:00
|
|
|
if (!s)
|
|
|
|
return -1;
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
if (length > maxChunkSize)
|
|
|
|
{
|
2023-11-02 18:41:00 +03:00
|
|
|
chunkSize = rdp->settings->VCChunkSize;
|
2014-10-11 00:11:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chunkSize = length;
|
|
|
|
flags |= CHANNEL_FLAG_LAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mcsChannel->options & CHANNEL_OPTION_SHOW_PROTOCOL)
|
|
|
|
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, totalLength);
|
|
|
|
Stream_Write_UINT32(s, flags);
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, chunkSize))
|
2015-03-26 19:09:47 +03:00
|
|
|
{
|
|
|
|
Stream_Release(s);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2014-10-11 00:11:42 +04:00
|
|
|
Stream_Write(s, buffer, chunkSize);
|
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!rdp_send(rdp, s, peerChannel->channelId))
|
2015-03-26 19:09:47 +03:00
|
|
|
return -1;
|
2014-10-11 00:11:42 +04:00
|
|
|
|
|
|
|
buffer += chunkSize;
|
|
|
|
length -= chunkSize;
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static void* freerdp_peer_virtual_channel_get_data(freerdp_peer* client, HANDLE hChannel)
|
2014-10-11 01:19:38 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpPeerChannel* peerChannel = (rdpPeerChannel*)hChannel;
|
2014-10-11 01:19:38 +04:00
|
|
|
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
2014-10-11 01:19:38 +04:00
|
|
|
if (!hChannel)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return peerChannel->extra;
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static int freerdp_peer_virtual_channel_set_data(freerdp_peer* client, HANDLE hChannel, void* data)
|
2014-10-11 01:19:38 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpPeerChannel* peerChannel = (rdpPeerChannel*)hChannel;
|
2014-10-11 01:19:38 +04:00
|
|
|
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
2014-10-11 01:19:38 +04:00
|
|
|
if (!hChannel)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
peerChannel->extra = data;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-03-18 11:23:00 +03:00
|
|
|
static BOOL freerdp_peer_set_state(freerdp_peer* client, CONNECTION_STATE state)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
2022-03-18 12:57:47 +03:00
|
|
|
return rdp_server_transition_to_state(client->context->rdp, state);
|
2022-03-18 11:23:00 +03:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_initialize(freerdp_peer* client)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
|
|
|
settings = rdp->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2014-03-26 02:13:08 +04:00
|
|
|
settings->ServerMode = TRUE;
|
|
|
|
settings->FrameAcknowledge = 0;
|
|
|
|
settings->LocalConnection = client->local;
|
2023-02-06 11:50:54 +03:00
|
|
|
|
|
|
|
const rdpCertificate* cert =
|
|
|
|
freerdp_settings_get_pointer(settings, FreeRDP_RdpServerCertificate);
|
|
|
|
if (!cert)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Missing server certificate, can not continue.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-05-22 22:02:44 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_RdpSecurity))
|
2023-02-06 11:50:54 +03:00
|
|
|
{
|
2023-05-22 22:02:44 +03:00
|
|
|
|
|
|
|
if (!freerdp_certificate_is_rdp_security_compatible(cert))
|
|
|
|
{
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, FALSE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_UseRdpSecurityLayer, FALSE))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-02-06 11:50:54 +03:00
|
|
|
}
|
2023-05-22 22:02:44 +03:00
|
|
|
|
2023-11-17 12:22:06 +03:00
|
|
|
nego_set_RCG_supported(rdp->nego, settings->RemoteCredentialGuard);
|
2022-11-15 16:19:54 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_INITIAL))
|
|
|
|
return FALSE;
|
2014-03-26 02:13:08 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2021-08-24 16:04:58 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpTransport* transport = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
|
|
|
|
|
|
|
transport = client->context->rdp->transport;
|
|
|
|
WINPR_ASSERT(transport);
|
2016-10-27 18:43:09 +03:00
|
|
|
transport_get_fds(transport, rfds, rcount);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
2021-08-24 16:04:58 +03:00
|
|
|
#endif
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2016-10-28 19:28:10 +03:00
|
|
|
static HANDLE freerdp_peer_get_event_handle(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
HANDLE hEvent = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpTransport* transport = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
|
|
|
|
|
|
|
transport = client->context->rdp->transport;
|
2021-09-06 12:01:36 +03:00
|
|
|
hEvent = transport_get_front_bio(transport);
|
2016-10-28 19:28:10 +03:00
|
|
|
return hEvent;
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:43:09 +03:00
|
|
|
static DWORD freerdp_peer_get_event_handles(freerdp_peer* client, HANDLE* events, DWORD count)
|
2013-07-21 06:34:05 +04:00
|
|
|
{
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
2016-10-29 08:18:17 +03:00
|
|
|
return transport_get_event_handles(client->context->rdp->transport, events, count);
|
2013-07-21 06:34:05 +04:00
|
|
|
}
|
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
static BOOL freerdp_peer_check_fds(freerdp_peer* peer)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int status = 0;
|
|
|
|
rdpRdp* rdp = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(peer->context);
|
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
rdp = peer->context->rdp;
|
2011-08-18 19:15:28 +04:00
|
|
|
status = rdp_check_fds(rdp);
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
if (status < 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_data_pdu(freerdp_peer* client, wStream* s, UINT16 totalLength)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE type = 0;
|
|
|
|
UINT16 length = 0;
|
|
|
|
UINT32 share_id = 0;
|
|
|
|
BYTE compressed_type = 0;
|
|
|
|
UINT16 compressed_len = 0;
|
|
|
|
rdpUpdate* update = NULL;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
2023-06-26 11:33:19 +03:00
|
|
|
rdpRdp* rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2021-08-24 15:14:37 +03:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
update = client->context->update;
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
|
2023-06-26 11:33:19 +03:00
|
|
|
if (!rdp_read_share_data_header(rdp, s, &length, &type, &share_id, &compressed_type,
|
|
|
|
&compressed_len))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2013-09-06 02:53:55 +04:00
|
|
|
#ifdef WITH_DEBUG_RDP
|
2023-06-26 11:33:19 +03:00
|
|
|
WLog_Print(rdp->log, WLOG_DEBUG, "recv %s Data PDU (0x%02" PRIX8 "), length: %" PRIu16 "",
|
2023-05-22 21:54:46 +03:00
|
|
|
data_pdu_type_to_string(type), type, length);
|
2013-09-06 02:53:55 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case DATA_PDU_TYPE_SYNCHRONIZE:
|
2023-06-26 11:33:19 +03:00
|
|
|
if (!rdp_recv_client_synchronize_pdu(rdp, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_CONTROL:
|
2023-06-26 11:33:19 +03:00
|
|
|
if (!rdp_server_accept_client_control_pdu(rdp, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2011-08-21 19:20:37 +04:00
|
|
|
break;
|
|
|
|
|
2012-02-07 16:38:27 +04:00
|
|
|
case DATA_PDU_TYPE_INPUT:
|
2023-06-26 11:33:19 +03:00
|
|
|
if (!input_recv(rdp->input, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-21 19:20:37 +04:00
|
|
|
case DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST:
|
2023-06-26 11:33:19 +03:00
|
|
|
if (!rdp_server_accept_client_persistent_key_list_pdu(rdp, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-21 19:20:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_FONT_LIST:
|
2023-06-26 11:33:19 +03:00
|
|
|
if (!rdp_server_accept_client_font_list_pdu(rdp, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_CONTINUE; // State changed, trigger rerun
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2011-08-26 14:14:34 +04:00
|
|
|
case DATA_PDU_TYPE_SHUTDOWN_REQUEST:
|
2023-06-26 11:33:19 +03:00
|
|
|
mcs_send_disconnect_provider_ultimatum(rdp->mcs);
|
2023-01-26 16:51:09 +03:00
|
|
|
WLog_WARN(TAG, "disconnect provider ultimatum sent to peer, closing connection");
|
|
|
|
return STATE_RUN_QUIT_SESSION;
|
2011-08-26 14:14:34 +04:00
|
|
|
|
2012-05-11 12:35:11 +04:00
|
|
|
case DATA_PDU_TYPE_FRAME_ACKNOWLEDGE:
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, client->ack_frame_id);
|
2022-03-23 15:18:35 +03:00
|
|
|
IFCALL(update->SurfaceFrameAcknowledge, update->context, client->ack_frame_id);
|
2012-05-11 12:35:11 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
case DATA_PDU_TYPE_REFRESH_RECT:
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!update_read_refresh_rect(update, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SUPPRESS_OUTPUT:
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!update_read_suppress_output(update, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Data PDU type %" PRIu8 "", type);
|
2011-08-21 18:52:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_SUCCESS;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_tpkt_pdu(freerdp_peer* client, wStream* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t rc = STATE_RUN_SUCCESS;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
|
|
|
UINT16 length = 0;
|
|
|
|
UINT16 pduType = 0;
|
|
|
|
UINT16 pduSource = 0;
|
|
|
|
UINT16 channelId = 0;
|
2016-12-02 12:46:43 +03:00
|
|
|
UINT16 securityFlags = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
rdp = client->context->rdp;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2022-03-23 15:18:35 +03:00
|
|
|
|
|
|
|
settings = client->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
2012-01-25 19:30:54 +04:00
|
|
|
|
|
|
|
if (!rdp_read_header(rdp, s, &length, &channelId))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2019-10-28 14:46:18 +03:00
|
|
|
rdp->inPackets++;
|
2022-04-19 15:29:17 +03:00
|
|
|
if (freerdp_shall_disconnect_context(rdp->context))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_SUCCESS;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
if (rdp_get_state(rdp) <= CONNECTION_STATE_LICENSING)
|
|
|
|
{
|
2023-05-22 21:54:46 +03:00
|
|
|
if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2023-01-23 18:19:06 +03:00
|
|
|
if (securityFlags & SEC_ENCRYPT)
|
|
|
|
{
|
|
|
|
if (!rdp_decrypt(rdp, s, &length, securityFlags))
|
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
return rdp_recv_message_channel_pdu(rdp, s, securityFlags);
|
|
|
|
}
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (settings->UseRdpSecurityLayer)
|
2012-01-25 19:30:54 +04:00
|
|
|
{
|
2023-05-22 21:54:46 +03:00
|
|
|
if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
if (securityFlags & SEC_ENCRYPT)
|
|
|
|
{
|
2020-03-09 23:54:34 +03:00
|
|
|
if (!rdp_decrypt(rdp, s, &length, securityFlags))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2012-01-25 19:30:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:06:04 +03:00
|
|
|
if (channelId == MCS_GLOBAL_CHANNEL_ID)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2023-01-23 12:18:50 +03:00
|
|
|
char buffer[256] = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 pduLength = 0;
|
|
|
|
UINT16 remain = 0;
|
2023-05-22 21:54:46 +03:00
|
|
|
if (!rdp_read_share_control_header(rdp, s, &pduLength, &remain, &pduType, &pduSource))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings->PduSource = pduSource;
|
2011-11-19 11:33:49 +04:00
|
|
|
|
2023-01-23 12:18:50 +03:00
|
|
|
WLog_DBG(TAG, "Received %s", pdu_type_to_str(pduType, buffer, sizeof(buffer)));
|
2011-08-21 18:52:37 +04:00
|
|
|
switch (pduType)
|
|
|
|
{
|
|
|
|
case PDU_TYPE_DATA:
|
2022-11-11 14:26:28 +03:00
|
|
|
rc = peer_recv_data_pdu(client, s, pduLength);
|
|
|
|
break;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2013-07-18 23:18:59 +04:00
|
|
|
case PDU_TYPE_CONFIRM_ACTIVE:
|
2020-02-21 11:17:00 +03:00
|
|
|
if (!rdp_server_accept_confirm_active(rdp, s, pduLength))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2013-07-18 23:18:59 +04:00
|
|
|
break;
|
|
|
|
|
2014-11-05 22:32:46 +03:00
|
|
|
case PDU_TYPE_FLOW_RESPONSE:
|
|
|
|
case PDU_TYPE_FLOW_STOP:
|
|
|
|
case PDU_TYPE_FLOW_TEST:
|
2020-04-06 14:01:20 +03:00
|
|
|
if (!Stream_SafeSeek(s, remain))
|
2022-04-19 15:29:17 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Short PDU, need %" PRIuz " bytes, got %" PRIuz, remain,
|
|
|
|
Stream_GetRemainingLength(s));
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2022-04-19 15:29:17 +03:00
|
|
|
}
|
2014-11-05 22:32:46 +03:00
|
|
|
break;
|
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
default:
|
2022-04-19 15:29:17 +03:00
|
|
|
WLog_ERR(TAG, "Client sent unknown pduType %" PRIu16 "", pduType);
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
}
|
2020-02-21 11:17:00 +03:00
|
|
|
else if ((rdp->mcs->messageChannelId > 0) && (channelId == rdp->mcs->messageChannelId))
|
2014-10-28 11:06:04 +03:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!settings->UseRdpSecurityLayer)
|
2022-11-11 14:26:28 +03:00
|
|
|
{
|
2023-05-22 21:54:46 +03:00
|
|
|
if (!rdp_read_security_header(rdp, s, &securityFlags, NULL))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
}
|
2015-06-19 15:47:00 +03:00
|
|
|
|
|
|
|
return rdp_recv_message_channel_pdu(rdp, s, securityFlags);
|
2014-10-28 11:06:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!freerdp_channel_peer_process(client, s, channelId))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2014-10-28 11:06:04 +03:00
|
|
|
}
|
2020-02-20 10:22:19 +03:00
|
|
|
if (!tpkt_ensure_stream_consumed(s, length))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2020-11-19 17:21:49 +03:00
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
return rc;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_handle_auto_detect(freerdp_peer* client, wStream* s)
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t ret = STATE_RUN_FAILED;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
2022-10-21 11:31:14 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
2023-04-24 14:25:56 +03:00
|
|
|
const rdpSettings* settings = client->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect))
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2023-04-24 14:25:56 +03:00
|
|
|
switch (rdp_get_state(rdp))
|
|
|
|
{
|
|
|
|
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST:
|
|
|
|
autodetect_on_connect_time_auto_detect_begin(rdp->autodetect);
|
core/autodetect: Allow overriding connect-time autodetection handling
Currently, FreeRDP-based server implementations can do connect-time
autodetection.
However, without having any control over it.
In order to be able to override the default connect-time autodetection
handling, introduce three new states for the state machine of the
connection sequence and two new callbacks for the autodetect handling.
These are:
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_BEGIN
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_IN_PROGRESS
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_END
- OnConnectTimeAutoDetectBegin()
- OnConnectTimeAutoDetectProgress()
The END state is pretty simple: When the autodetection is finished and
the autodetect state is FREERDP_AUTODETECT_STATE_COMPLETE, transition
into the next state of the connection sequence.
The BEGIN state is entered, when capability-wise network autodetection
is available.
In this state, the OnConnectTimeAutoDetectBegin callback is called, the
server implementation may initialize any related handling here.
If the server implementation determines, that no further handling is
required, it can end the autodetection phase by returning
FREERDP_AUTODETECT_STATE_COMPLETE.
If not, and an autodetection request is sent, it returns
FREERDP_AUTODETECT_STATE_REQUEST.
The state machine of the connection sequence will then switch into the
IN_PROGRESS state.
In the IN_PROGRESS state, any incoming PDU is handled first, then the
OnConnectTimeAutoDetectProgress callback is called.
Like in the BEGIN state, the return value will determine, whether the
state machine of the connection sequence goes into the END state or goes
into (or rather stays) in the IN_PROGRESS state.
2023-04-09 19:34:56 +03:00
|
|
|
switch (autodetect_get_state(rdp->autodetect))
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
core/autodetect: Allow overriding connect-time autodetection handling
Currently, FreeRDP-based server implementations can do connect-time
autodetection.
However, without having any control over it.
In order to be able to override the default connect-time autodetection
handling, introduce three new states for the state machine of the
connection sequence and two new callbacks for the autodetect handling.
These are:
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_BEGIN
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_IN_PROGRESS
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_END
- OnConnectTimeAutoDetectBegin()
- OnConnectTimeAutoDetectProgress()
The END state is pretty simple: When the autodetection is finished and
the autodetect state is FREERDP_AUTODETECT_STATE_COMPLETE, transition
into the next state of the connection sequence.
The BEGIN state is entered, when capability-wise network autodetection
is available.
In this state, the OnConnectTimeAutoDetectBegin callback is called, the
server implementation may initialize any related handling here.
If the server implementation determines, that no further handling is
required, it can end the autodetection phase by returning
FREERDP_AUTODETECT_STATE_COMPLETE.
If not, and an autodetection request is sent, it returns
FREERDP_AUTODETECT_STATE_REQUEST.
The state machine of the connection sequence will then switch into the
IN_PROGRESS state.
In the IN_PROGRESS state, any incoming PDU is handled first, then the
OnConnectTimeAutoDetectProgress callback is called.
Like in the BEGIN state, the return value will determine, whether the
state machine of the connection sequence goes into the END state or goes
into (or rather stays) in the IN_PROGRESS state.
2023-04-09 19:34:56 +03:00
|
|
|
case FREERDP_AUTODETECT_STATE_REQUEST:
|
|
|
|
ret = STATE_RUN_SUCCESS;
|
2023-04-24 14:25:56 +03:00
|
|
|
if (!rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_RESPONSE))
|
|
|
|
return STATE_RUN_FAILED;
|
core/autodetect: Allow overriding connect-time autodetection handling
Currently, FreeRDP-based server implementations can do connect-time
autodetection.
However, without having any control over it.
In order to be able to override the default connect-time autodetection
handling, introduce three new states for the state machine of the
connection sequence and two new callbacks for the autodetect handling.
These are:
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_BEGIN
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_IN_PROGRESS
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_END
- OnConnectTimeAutoDetectBegin()
- OnConnectTimeAutoDetectProgress()
The END state is pretty simple: When the autodetection is finished and
the autodetect state is FREERDP_AUTODETECT_STATE_COMPLETE, transition
into the next state of the connection sequence.
The BEGIN state is entered, when capability-wise network autodetection
is available.
In this state, the OnConnectTimeAutoDetectBegin callback is called, the
server implementation may initialize any related handling here.
If the server implementation determines, that no further handling is
required, it can end the autodetection phase by returning
FREERDP_AUTODETECT_STATE_COMPLETE.
If not, and an autodetection request is sent, it returns
FREERDP_AUTODETECT_STATE_REQUEST.
The state machine of the connection sequence will then switch into the
IN_PROGRESS state.
In the IN_PROGRESS state, any incoming PDU is handled first, then the
OnConnectTimeAutoDetectProgress callback is called.
Like in the BEGIN state, the return value will determine, whether the
state machine of the connection sequence goes into the END state or goes
into (or rather stays) in the IN_PROGRESS state.
2023-04-09 19:34:56 +03:00
|
|
|
break;
|
|
|
|
case FREERDP_AUTODETECT_STATE_COMPLETE:
|
|
|
|
ret = STATE_RUN_CONTINUE; /* Rerun in next state */
|
2023-04-24 14:25:56 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_LICENSING))
|
core/autodetect: Allow overriding connect-time autodetection handling
Currently, FreeRDP-based server implementations can do connect-time
autodetection.
However, without having any control over it.
In order to be able to override the default connect-time autodetection
handling, introduce three new states for the state machine of the
connection sequence and two new callbacks for the autodetect handling.
These are:
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_BEGIN
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_IN_PROGRESS
- CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_END
- OnConnectTimeAutoDetectBegin()
- OnConnectTimeAutoDetectProgress()
The END state is pretty simple: When the autodetection is finished and
the autodetect state is FREERDP_AUTODETECT_STATE_COMPLETE, transition
into the next state of the connection sequence.
The BEGIN state is entered, when capability-wise network autodetection
is available.
In this state, the OnConnectTimeAutoDetectBegin callback is called, the
server implementation may initialize any related handling here.
If the server implementation determines, that no further handling is
required, it can end the autodetection phase by returning
FREERDP_AUTODETECT_STATE_COMPLETE.
If not, and an autodetection request is sent, it returns
FREERDP_AUTODETECT_STATE_REQUEST.
The state machine of the connection sequence will then switch into the
IN_PROGRESS state.
In the IN_PROGRESS state, any incoming PDU is handled first, then the
OnConnectTimeAutoDetectProgress callback is called.
Like in the BEGIN state, the return value will determine, whether the
state machine of the connection sequence goes into the END state or goes
into (or rather stays) in the IN_PROGRESS state.
2023-04-09 19:34:56 +03:00
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
2023-04-24 14:25:56 +03:00
|
|
|
break;
|
|
|
|
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_RESPONSE:
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
if (state_run_success(ret))
|
|
|
|
{
|
|
|
|
autodetect_on_connect_time_auto_detect_progress(rdp->autodetect);
|
|
|
|
switch (autodetect_get_state(rdp->autodetect))
|
|
|
|
{
|
|
|
|
case FREERDP_AUTODETECT_STATE_REQUEST:
|
|
|
|
ret = STATE_RUN_SUCCESS;
|
|
|
|
break;
|
|
|
|
case FREERDP_AUTODETECT_STATE_COMPLETE:
|
|
|
|
ret = STATE_RUN_CONTINUE; /* Rerun in next state */
|
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_LICENSING))
|
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WINPR_ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_LICENSING))
|
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
|
|
|
|
ret = STATE_RUN_CONTINUE; /* Rerun in next state */
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_handle_licensing(freerdp_peer* client, wStream* s)
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t ret = STATE_RUN_FAILED;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
2022-10-21 11:31:14 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
|
|
|
settings = rdp->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
switch (license_get_state(rdp->license))
|
|
|
|
{
|
|
|
|
case LICENSE_STATE_INITIAL:
|
|
|
|
{
|
|
|
|
const BOOL required =
|
|
|
|
freerdp_settings_get_bool(settings, FreeRDP_ServerLicenseRequired);
|
|
|
|
|
|
|
|
if (required)
|
|
|
|
{
|
|
|
|
if (!license_server_configure(rdp->license))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
else if (!license_server_send_request(rdp->license))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (license_send_valid_client_error_packet(rdp))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_CONTINUE; /* Rerun in next state, might be capabilities */
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LICENSE_STATE_COMPLETED:
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_CONTINUE; /* Licensing completed, continue in next state */
|
2022-10-21 11:31:14 +03:00
|
|
|
break;
|
|
|
|
case LICENSE_STATE_ABORTED:
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_fastpath_pdu(freerdp_peer* client, wStream* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
|
|
|
UINT16 length = 0;
|
|
|
|
BOOL rc = 0;
|
|
|
|
rdpFastPath* fastpath = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rdp = client->context->rdp;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
fastpath = rdp->fastpath;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2021-08-24 15:14:37 +03:00
|
|
|
rc = fastpath_read_header_rdp(fastpath, s, &length);
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!rc || (length == 0))
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "incorrect FastPath PDU header length %" PRIu16 "", length);
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, length))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2023-01-24 12:44:46 +03:00
|
|
|
if (!fastpath_decrypt(fastpath, s, &length))
|
|
|
|
return STATE_RUN_FAILED;
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2019-10-28 14:46:18 +03:00
|
|
|
rdp->inPackets++;
|
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
return fastpath_recv_inputs(fastpath, s);
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t peer_recv_pdu(freerdp_peer* client, wStream* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2022-10-21 10:19:29 +03:00
|
|
|
int rc = tpkt_verify_header(s);
|
2022-10-21 11:31:14 +03:00
|
|
|
|
2022-10-21 10:19:29 +03:00
|
|
|
if (rc > 0)
|
2011-10-18 11:10:12 +04:00
|
|
|
return peer_recv_tpkt_pdu(client, s);
|
2022-10-21 10:19:29 +03:00
|
|
|
else if (rc == 0)
|
2011-10-18 11:10:12 +04:00
|
|
|
return peer_recv_fastpath_pdu(client, s);
|
2022-10-21 10:19:29 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_unexpected_client_message(rdpRdp* rdp, UINT32 flag)
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
|
|
|
char buffer[1024] = { 0 };
|
|
|
|
WLog_WARN(TAG, "Unexpected client message in state %s, missing flag %s",
|
|
|
|
rdp_get_state_string(rdp), rdp_finalize_flags_to_str(flag, buffer, sizeof(buffer)));
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_SUCCESS; /* we ignore this as per spec input PDU are already allowed */
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t rdp_peer_handle_state_demand_active(freerdp_peer* client)
|
2022-11-08 14:54:49 +03:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t ret = STATE_RUN_FAILED;
|
2022-11-08 14:54:49 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdpRdp* rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
|
|
|
if (client->Capabilities && !client->Capabilities(client))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "[%s] freerdp_peer::Capabilities() callback failed",
|
|
|
|
rdp_get_state_string(rdp));
|
|
|
|
}
|
|
|
|
else if (!rdp_send_demand_active(rdp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "[%s] rdp_send_demand_active() fail", rdp_get_state_string(rdp));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-15 16:19:54 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp,
|
|
|
|
CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT))
|
|
|
|
return STATE_RUN_FAILED;
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_CONTINUE;
|
2022-11-08 14:54:49 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-08 16:19:16 +03:00
|
|
|
/** \brief Handle server peer state ACTIVE:
|
|
|
|
* On initial run (not connected, not activated) do not read data
|
|
|
|
*
|
|
|
|
* \return -1 in case of an error, 0 if no data needs to be processed, 1 to let
|
|
|
|
* the state machine run again and 2 if peer_recv_pdu must be called.
|
|
|
|
*/
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t rdp_peer_handle_state_active(freerdp_peer* client)
|
2022-11-08 16:19:16 +03:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t ret = STATE_RUN_FAILED;
|
2022-11-08 16:19:16 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdpRdp* rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
|
|
|
if (!client->connected)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* PostConnect should only be called once and should not
|
|
|
|
* be called after a reactivation sequence.
|
|
|
|
*/
|
|
|
|
IFCALLRET(client->PostConnect, client->connected, client);
|
|
|
|
}
|
|
|
|
if (!client->connected)
|
|
|
|
{
|
2023-01-26 16:51:09 +03:00
|
|
|
WLog_ERR(TAG, "PostConnect for peer %p failed", client);
|
2022-12-21 19:22:43 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-11-08 16:19:16 +03:00
|
|
|
}
|
|
|
|
else if (!client->activated)
|
|
|
|
{
|
2022-12-21 19:22:43 +03:00
|
|
|
BOOL activated = TRUE;
|
|
|
|
|
|
|
|
/* Set client->activated TRUE before calling the Activate callback.
|
|
|
|
* the Activate callback might reset the client->activated flag even if it returns success
|
|
|
|
* (e.g. deactivate/reactivate sequence) */
|
|
|
|
client->activated = TRUE;
|
|
|
|
IFCALLRET(client->Activate, activated, client);
|
2022-11-08 16:19:16 +03:00
|
|
|
|
2022-12-21 19:22:43 +03:00
|
|
|
if (!activated)
|
2023-01-26 16:51:09 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Activate for peer %p failed", client);
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2023-01-26 16:51:09 +03:00
|
|
|
}
|
2022-11-08 16:19:16 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2022-11-08 16:19:16 +03:00
|
|
|
}
|
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_ACTIVE;
|
2022-11-08 16:19:16 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_callback_internal(rdpTransport* transport, wStream* s, void* extra)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 SelectedProtocol = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
freerdp_peer* client = (freerdp_peer*)extra;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t ret = STATE_RUN_FAILED;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(transport);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = client->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2022-06-23 10:23:07 +03:00
|
|
|
IFCALL(client->ReachedState, client, rdp_get_state(rdp));
|
2021-09-03 09:17:27 +03:00
|
|
|
switch (rdp_get_state(rdp))
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
|
|
|
case CONNECTION_STATE_INITIAL:
|
2022-11-15 16:19:54 +03:00
|
|
|
if (rdp_server_transition_to_state(rdp, CONNECTION_STATE_NEGO))
|
|
|
|
ret = STATE_RUN_CONTINUE;
|
2022-10-21 11:31:14 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_NEGO:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_nego(rdp, s))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "%s - rdp_server_accept_nego() fail", rdp_get_state_string(rdp));
|
2012-09-16 23:30:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-24 13:22:15 +03:00
|
|
|
SelectedProtocol = nego_get_selected_protocol(rdp->nego);
|
2023-03-07 13:58:28 +03:00
|
|
|
settings->RdstlsSecurity = (SelectedProtocol & PROTOCOL_RDSTLS) ? TRUE : FALSE;
|
2022-03-24 13:22:15 +03:00
|
|
|
settings->NlaSecurity = (SelectedProtocol & PROTOCOL_HYBRID) ? TRUE : FALSE;
|
|
|
|
settings->TlsSecurity = (SelectedProtocol & PROTOCOL_SSL) ? TRUE : FALSE;
|
|
|
|
settings->RdpSecurity = (SelectedProtocol == PROTOCOL_RDP) ? TRUE : FALSE;
|
2012-09-16 23:30:11 +04:00
|
|
|
|
2022-03-24 13:22:15 +03:00
|
|
|
if (SelectedProtocol & PROTOCOL_HYBRID)
|
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
SEC_WINNT_AUTH_IDENTITY_INFO* identity =
|
|
|
|
(SEC_WINNT_AUTH_IDENTITY_INFO*)nego_get_identity(rdp->nego);
|
2022-10-21 11:31:14 +03:00
|
|
|
sspi_CopyAuthIdentity(&client->identity, identity);
|
2022-03-24 13:22:15 +03:00
|
|
|
IFCALLRET(client->Logon, client->authenticated, client, &client->identity,
|
|
|
|
TRUE);
|
|
|
|
nego_free_nla(rdp->nego);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IFCALLRET(client->Logon, client->authenticated, client, &client->identity,
|
|
|
|
FALSE);
|
|
|
|
}
|
2022-11-15 16:19:54 +03:00
|
|
|
if (rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_CREATE_REQUEST))
|
|
|
|
ret = STATE_RUN_SUCCESS;
|
2022-03-24 13:22:15 +03:00
|
|
|
}
|
2011-08-19 13:39:37 +04:00
|
|
|
break;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_NLA:
|
|
|
|
WINPR_ASSERT(FALSE); // TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_MCS_CREATE_REQUEST:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_connect_initial(rdp, s))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2020-02-21 11:17:00 +03:00
|
|
|
WLog_ERR(TAG,
|
2023-01-23 14:03:18 +03:00
|
|
|
"%s - "
|
2020-02-21 11:17:00 +03:00
|
|
|
"rdp_server_accept_mcs_connect_initial() fail",
|
2023-01-23 14:03:18 +03:00
|
|
|
rdp_get_state_string(rdp));
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-03-24 13:22:15 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2011-08-19 22:03:48 +04:00
|
|
|
break;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_MCS_ERECT_DOMAIN:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_erect_domain_request(rdp, s))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2020-02-21 11:17:00 +03:00
|
|
|
WLog_ERR(TAG,
|
2023-01-23 14:03:18 +03:00
|
|
|
"%s - "
|
2020-02-21 11:17:00 +03:00
|
|
|
"rdp_server_accept_mcs_erect_domain_request() fail",
|
2023-01-23 14:03:18 +03:00
|
|
|
rdp_get_state_string(rdp));
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-03-24 13:22:15 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2011-08-19 22:03:48 +04:00
|
|
|
break;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_MCS_ATTACH_USER:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_attach_user_request(rdp, s))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2020-02-21 11:17:00 +03:00
|
|
|
WLog_ERR(TAG,
|
2023-01-23 14:03:18 +03:00
|
|
|
"%s - "
|
2020-02-21 11:17:00 +03:00
|
|
|
"rdp_server_accept_mcs_attach_user_request() fail",
|
2023-01-23 14:03:18 +03:00
|
|
|
rdp_get_state_string(rdp));
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-03-24 13:22:15 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2016-10-13 23:02:25 +03:00
|
|
|
|
2011-08-20 10:05:03 +04:00
|
|
|
break;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_channel_join_request(rdp, s))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2020-02-21 11:17:00 +03:00
|
|
|
WLog_ERR(TAG,
|
2023-01-23 14:03:18 +03:00
|
|
|
"%s - "
|
2020-02-21 11:17:00 +03:00
|
|
|
"rdp_server_accept_mcs_channel_join_request() fail",
|
2023-01-23 14:03:18 +03:00
|
|
|
rdp_get_state_string(rdp));
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-03-24 13:22:15 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2011-08-20 14:22:14 +04:00
|
|
|
break;
|
|
|
|
|
2013-07-18 23:18:59 +04:00
|
|
|
case CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT:
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2023-01-27 11:59:27 +03:00
|
|
|
|
|
|
|
if (!rdp_server_establish_keys(rdp, s))
|
2012-09-16 23:30:11 +04:00
|
|
|
{
|
2023-01-27 11:59:27 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"%s - "
|
|
|
|
"rdp_server_establish_keys() fail",
|
|
|
|
rdp_get_state_string(rdp));
|
|
|
|
ret = STATE_RUN_FAILED;
|
2012-01-25 20:08:10 +04:00
|
|
|
}
|
2023-01-27 11:59:27 +03:00
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
if (state_run_success(ret))
|
2022-03-24 13:22:15 +03:00
|
|
|
{
|
2022-11-15 16:19:54 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE))
|
|
|
|
ret = STATE_RUN_FAILED;
|
|
|
|
else if (Stream_GetRemainingLength(s) > 0)
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_CONTINUE; /* Rerun function */
|
2022-03-24 13:22:15 +03:00
|
|
|
}
|
2013-07-18 23:18:59 +04:00
|
|
|
break;
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2013-07-18 23:18:59 +04:00
|
|
|
case CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE:
|
2023-01-27 16:34:17 +03:00
|
|
|
if (rdp_recv_client_info(rdp, s))
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2023-04-24 14:25:56 +03:00
|
|
|
if (rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST))
|
|
|
|
ret = STATE_RUN_CONTINUE;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-04-24 14:25:56 +03:00
|
|
|
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST:
|
|
|
|
case CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_RESPONSE:
|
2023-01-27 11:59:27 +03:00
|
|
|
ret = peer_recv_handle_auto_detect(client, s);
|
|
|
|
break;
|
|
|
|
|
2013-07-18 23:18:59 +04:00
|
|
|
case CONNECTION_STATE_LICENSING:
|
2022-10-21 11:31:14 +03:00
|
|
|
ret = peer_recv_handle_licensing(client, s);
|
2022-11-11 14:26:28 +03:00
|
|
|
if (ret == STATE_RUN_CONTINUE)
|
2022-11-15 16:19:54 +03:00
|
|
|
{
|
|
|
|
if (!rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST))
|
|
|
|
ret = STATE_RUN_FAILED;
|
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
break;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST:
|
2023-03-06 12:47:24 +03:00
|
|
|
if (settings->SupportMultitransport &&
|
|
|
|
((settings->MultitransportFlags & INITIATE_REQUEST_PROTOCOL_UDPFECR) != 0))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
/* only UDP reliable for now, nobody does lossy UDP (MS-RDPUDP only) these days */
|
|
|
|
ret = multitransport_server_request(rdp->multitransport,
|
|
|
|
INITIATE_REQUEST_PROTOCOL_UDPFECR);
|
|
|
|
switch (ret)
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2022-11-24 15:24:26 +03:00
|
|
|
case STATE_RUN_SUCCESS:
|
|
|
|
rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_RESPONSE);
|
|
|
|
break;
|
|
|
|
case STATE_RUN_CONTINUE:
|
|
|
|
/* mismatch on the supported kind of UDP transports */
|
|
|
|
rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-15 16:19:54 +03:00
|
|
|
if (rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE))
|
|
|
|
ret = STATE_RUN_CONTINUE; /* Rerun, initialize next state */
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
break;
|
|
|
|
case CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_RESPONSE:
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
break;
|
2013-07-18 23:18:59 +04:00
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE:
|
2022-11-08 14:54:49 +03:00
|
|
|
ret = rdp_peer_handle_state_demand_active(client);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT:
|
2023-01-27 11:59:27 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_SupportMonitorLayoutPdu))
|
2013-07-18 23:18:59 +04:00
|
|
|
{
|
2022-10-21 11:31:14 +03:00
|
|
|
MONITOR_DEF* monitors = NULL;
|
|
|
|
|
|
|
|
IFCALL(client->AdjustMonitorsLayout, client);
|
|
|
|
|
|
|
|
/* client supports the monitorLayout PDU, let's send him the monitors if any */
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2022-10-21 11:31:14 +03:00
|
|
|
if (freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount) == 0)
|
2022-03-24 13:22:15 +03:00
|
|
|
{
|
2022-10-21 11:31:14 +03:00
|
|
|
const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
|
|
|
const rdpMonitor primary = { .x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.width = w,
|
|
|
|
.height = h,
|
|
|
|
.is_primary = TRUE,
|
|
|
|
.orig_screen = 0,
|
|
|
|
.attributes = { .physicalWidth = w,
|
|
|
|
.physicalHeight = h,
|
|
|
|
.orientation =
|
|
|
|
ORIENTATION_LANDSCAPE,
|
|
|
|
.desktopScaleFactor = 100,
|
|
|
|
.deviceScaleFactor = 100 } };
|
|
|
|
if (!freerdp_settings_set_pointer_array(settings, FreeRDP_MonitorDefArray, 0,
|
|
|
|
&primary))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
else if (!freerdp_settings_set_uint32(settings, FreeRDP_MonitorCount, 1))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-03-24 13:22:15 +03:00
|
|
|
}
|
2022-11-11 14:26:28 +03:00
|
|
|
if (state_run_failed(ret))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
else if (!display_convert_rdp_monitor_to_monitor_def(
|
|
|
|
settings->MonitorCount, settings->MonitorDefArray, &monitors))
|
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
else if (!freerdp_display_send_monitor_layout(rdp->context, settings->MonitorCount,
|
|
|
|
monitors))
|
2013-07-19 01:15:10 +04:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2013-07-19 01:15:10 +04:00
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_SUCCESS;
|
2022-10-21 11:31:14 +03:00
|
|
|
free(monitors);
|
2024-01-09 18:19:41 +03:00
|
|
|
|
|
|
|
const size_t len = Stream_GetRemainingLength(s);
|
|
|
|
if (!state_run_failed(ret) && (len > 0))
|
|
|
|
ret = STATE_RUN_CONTINUE;
|
2013-07-18 23:18:59 +04:00
|
|
|
}
|
|
|
|
else
|
2023-01-24 12:46:40 +03:00
|
|
|
{
|
2023-01-27 11:59:27 +03:00
|
|
|
const size_t len = Stream_GetRemainingLength(s);
|
|
|
|
if (len > 0)
|
2023-01-24 12:46:40 +03:00
|
|
|
ret = STATE_RUN_CONTINUE;
|
|
|
|
else
|
|
|
|
ret = STATE_RUN_SUCCESS;
|
|
|
|
}
|
2023-08-31 18:21:49 +03:00
|
|
|
if (state_run_success(ret))
|
|
|
|
{
|
|
|
|
if (!rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE))
|
|
|
|
ret = STATE_RUN_FAILED;
|
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE:
|
|
|
|
/**
|
|
|
|
* During reactivation sequence the client might sent some input or channel data
|
|
|
|
* before receiving the Deactivate All PDU. We need to process them as usual.
|
|
|
|
*/
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_FINALIZATION_SYNC:
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
if (rdp_finalize_is_flag_set(rdp, FINALIZE_CS_SYNCHRONIZE_PDU))
|
|
|
|
{
|
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_COOPERATE))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = peer_unexpected_client_message(rdp, FINALIZE_CS_SYNCHRONIZE_PDU);
|
|
|
|
break;
|
|
|
|
case CONNECTION_STATE_FINALIZATION_COOPERATE:
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
if (rdp_finalize_is_flag_set(rdp, FINALIZE_CS_CONTROL_COOPERATE_PDU))
|
|
|
|
{
|
|
|
|
if (!rdp_server_transition_to_state(rdp,
|
|
|
|
CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = peer_unexpected_client_message(rdp, FINALIZE_CS_CONTROL_COOPERATE_PDU);
|
|
|
|
break;
|
|
|
|
case CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL:
|
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
if (rdp_finalize_is_flag_set(rdp, FINALIZE_CS_CONTROL_REQUEST_PDU))
|
|
|
|
{
|
2023-08-31 18:21:49 +03:00
|
|
|
if (!rdp_send_server_control_granted_pdu(rdp))
|
|
|
|
ret = STATE_RUN_FAILED;
|
|
|
|
else if (!rdp_server_transition_to_state(
|
|
|
|
rdp, CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = peer_unexpected_client_message(rdp, FINALIZE_CS_CONTROL_REQUEST_PDU);
|
|
|
|
break;
|
|
|
|
case CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST:
|
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled) &&
|
|
|
|
!rdp_finalize_is_flag_set(rdp, FINALIZE_DEACTIVATE_REACTIVATE))
|
2011-12-18 21:13:09 +04:00
|
|
|
{
|
2022-03-24 13:22:15 +03:00
|
|
|
ret = peer_recv_pdu(client, s);
|
2022-10-21 11:31:14 +03:00
|
|
|
|
|
|
|
if (rdp_finalize_is_flag_set(rdp, FINALIZE_CS_PERSISTENT_KEY_LIST_PDU))
|
2015-05-02 06:26:08 +03:00
|
|
|
{
|
2022-10-21 11:31:14 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp,
|
|
|
|
CONNECTION_STATE_FINALIZATION_FONT_LIST))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2022-10-21 11:31:14 +03:00
|
|
|
else
|
|
|
|
ret = peer_unexpected_client_message(rdp,
|
|
|
|
CONNECTION_STATE_FINALIZATION_FONT_LIST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_FONT_LIST))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-10-21 11:31:14 +03:00
|
|
|
else
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_CONTINUE;
|
2011-12-18 21:13:09 +04:00
|
|
|
}
|
2013-07-18 23:18:59 +04:00
|
|
|
break;
|
2022-10-21 11:31:14 +03:00
|
|
|
case CONNECTION_STATE_FINALIZATION_FONT_LIST:
|
2022-03-24 13:22:15 +03:00
|
|
|
ret = peer_recv_pdu(client, s);
|
2022-11-11 14:26:28 +03:00
|
|
|
if (state_run_success(ret))
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2022-11-08 16:19:16 +03:00
|
|
|
if (rdp_finalize_is_flag_set(rdp, FINALIZE_CS_FONT_LIST_PDU))
|
2022-10-21 11:31:14 +03:00
|
|
|
{
|
2022-11-08 16:19:16 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_ACTIVE))
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_FAILED;
|
2022-11-08 16:19:16 +03:00
|
|
|
update_reset_state(rdp->update);
|
2022-11-11 14:26:28 +03:00
|
|
|
ret = STATE_RUN_CONTINUE;
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
|
|
|
else
|
2022-11-08 16:19:16 +03:00
|
|
|
ret = peer_unexpected_client_message(rdp, FINALIZE_CS_FONT_LIST_PDU);
|
2022-10-21 11:31:14 +03:00
|
|
|
}
|
2011-08-19 05:54:43 +04:00
|
|
|
break;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2022-11-08 16:19:16 +03:00
|
|
|
case CONNECTION_STATE_ACTIVE:
|
|
|
|
ret = rdp_peer_handle_state_active(client);
|
2022-11-11 14:26:28 +03:00
|
|
|
if (ret >= STATE_RUN_ACTIVE)
|
2022-11-08 16:19:16 +03:00
|
|
|
ret = peer_recv_pdu(client, s);
|
|
|
|
break;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
/* States that must not happen in server state machine */
|
|
|
|
case CONNECTION_STATE_FINALIZATION_CLIENT_SYNC:
|
|
|
|
case CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE:
|
|
|
|
case CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL:
|
|
|
|
case CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP:
|
2011-08-18 19:15:28 +04:00
|
|
|
default:
|
2021-09-03 09:17:27 +03:00
|
|
|
WLog_ERR(TAG, "%s state %d", rdp_get_state_string(rdp), rdp_get_state(rdp));
|
2022-03-24 13:22:15 +03:00
|
|
|
break;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2022-03-24 13:22:15 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t peer_recv_callback(rdpTransport* transport, wStream* s, void* extra)
|
2022-03-24 13:22:15 +03:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
char buffer[64] = { 0 };
|
|
|
|
state_run_t rc = STATE_RUN_FAILED;
|
|
|
|
const size_t start = Stream_GetPosition(s);
|
|
|
|
const rdpContext* context = transport_get_context(transport);
|
2024-01-09 18:18:57 +03:00
|
|
|
DWORD level = WLOG_TRACE;
|
|
|
|
static wLog* log = NULL;
|
|
|
|
if (!log)
|
|
|
|
log = WLog_Get(TAG);
|
2022-11-11 14:26:28 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
2022-03-24 13:22:15 +03:00
|
|
|
do
|
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
const rdpRdp* rdp = context->rdp;
|
|
|
|
const char* old = rdp_get_state_string(rdp);
|
|
|
|
|
|
|
|
if (rc == STATE_RUN_TRY_AGAIN)
|
|
|
|
Stream_SetPosition(s, start);
|
|
|
|
rc = peer_recv_callback_internal(transport, s, extra);
|
|
|
|
|
2024-01-09 18:18:57 +03:00
|
|
|
const size_t len = Stream_GetRemainingLength(s);
|
|
|
|
if ((len > 0) && !state_run_continue(rc))
|
|
|
|
level = WLOG_WARN;
|
|
|
|
WLog_Print(log, level,
|
|
|
|
"(server)[%s -> %s] current return %s [%" PRIuz " bytes not processed]", old,
|
|
|
|
rdp_get_state_string(rdp), state_run_result_string(rc, buffer, sizeof(buffer)),
|
|
|
|
len);
|
2022-12-16 15:13:23 +03:00
|
|
|
} while (state_run_continue(rc));
|
2022-03-24 13:22:15 +03:00
|
|
|
|
|
|
|
return rc;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_close(freerdp_peer* client)
|
2012-04-13 11:58:28 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 SelectedProtocol = 0;
|
|
|
|
rdpContext* context = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
2022-03-23 15:18:35 +03:00
|
|
|
|
|
|
|
context = client->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
WINPR_ASSERT(context->rdp);
|
2021-08-24 15:14:37 +03:00
|
|
|
|
2015-02-13 20:25:50 +03:00
|
|
|
/** if negotiation has failed, we're not MCS connected. So don't
|
|
|
|
* send anything else, or some mstsc will consider that as an error
|
|
|
|
*/
|
2022-03-23 15:18:35 +03:00
|
|
|
SelectedProtocol = nego_get_selected_protocol(context->rdp->nego);
|
2018-11-20 18:38:06 +03:00
|
|
|
|
|
|
|
if (SelectedProtocol & PROTOCOL_FAILED_NEGO)
|
2015-02-13 20:25:50 +03:00
|
|
|
return TRUE;
|
|
|
|
|
2012-04-13 11:58:28 +04:00
|
|
|
/**
|
|
|
|
* [MS-RDPBCGR] 1.3.1.4.2 User-Initiated Disconnection Sequence on Server
|
|
|
|
* The server first sends the client a Deactivate All PDU followed by an
|
|
|
|
* optional MCS Disconnect Provider Ultimatum PDU.
|
|
|
|
*/
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!rdp_send_deactivate_all(context->rdp))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-07-18 23:18:59 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (freerdp_settings_get_bool(context->settings, FreeRDP_SupportErrorInfoPdu))
|
2016-10-13 23:02:25 +03:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
rdp_send_error_info(context->rdp);
|
2015-01-13 19:09:36 +03:00
|
|
|
}
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
return mcs_send_disconnect_provider_ultimatum(context->rdp->mcs);
|
2012-04-13 11:58:28 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
static void freerdp_peer_disconnect(freerdp_peer* client)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpTransport* transport = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
2022-03-23 15:18:35 +03:00
|
|
|
|
|
|
|
transport = freerdp_get_transport(client->context);
|
2015-02-15 18:06:17 +03:00
|
|
|
transport_disconnect(transport);
|
2011-10-18 11:10:12 +04:00
|
|
|
}
|
|
|
|
|
2020-03-09 12:33:58 +03:00
|
|
|
static BOOL freerdp_peer_send_channel_data(freerdp_peer* client, UINT16 channelId, const BYTE* data,
|
|
|
|
size_t size)
|
2011-12-10 12:41:29 +04:00
|
|
|
{
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
2020-03-09 12:33:58 +03:00
|
|
|
return rdp_send_channel_data(client->context->rdp, channelId, data, size);
|
2011-12-10 12:41:29 +04:00
|
|
|
}
|
|
|
|
|
2023-01-16 12:56:10 +03:00
|
|
|
static BOOL freerdp_peer_send_server_redirection_pdu(freerdp_peer* peer,
|
|
|
|
const rdpRedirection* redirection)
|
2022-09-27 18:09:53 +03:00
|
|
|
{
|
2023-01-16 12:56:10 +03:00
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(peer->context);
|
2022-09-27 18:09:53 +03:00
|
|
|
|
2023-01-16 12:56:10 +03:00
|
|
|
wStream* s = rdp_send_stream_pdu_init(peer->context->rdp);
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
if (!rdp_write_enhanced_security_redirection_packet(s, redirection))
|
|
|
|
goto fail;
|
|
|
|
if (!rdp_send_pdu(peer->context->rdp, s, PDU_TYPE_SERVER_REDIRECTION, 0))
|
2022-09-27 18:09:53 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-01-17 14:39:29 +03:00
|
|
|
return rdp_reset_runtime_settings(peer->context->rdp);
|
2022-09-27 18:09:53 +03:00
|
|
|
fail:
|
2023-01-16 12:56:10 +03:00
|
|
|
Stream_Release(s);
|
2022-09-27 18:09:53 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-08-26 17:17:51 +03:00
|
|
|
static BOOL freerdp_peer_send_channel_packet(freerdp_peer* client, UINT16 channelId,
|
|
|
|
size_t totalSize, UINT32 flags, const BYTE* data,
|
|
|
|
size_t chunkSize)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
WINPR_ASSERT(client->context->rdp);
|
|
|
|
return rdp_channel_send_packet(client->context->rdp, channelId, totalSize, flags, data,
|
|
|
|
chunkSize);
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:32:14 +04:00
|
|
|
static BOOL freerdp_peer_is_write_blocked(freerdp_peer* peer)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpTransport* transport = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(peer->context);
|
|
|
|
WINPR_ASSERT(peer->context->rdp);
|
|
|
|
WINPR_ASSERT(peer->context->rdp->transport);
|
|
|
|
transport = peer->context->rdp->transport;
|
2015-02-17 18:54:39 +03:00
|
|
|
return transport_is_write_blocked(transport);
|
2014-05-21 19:32:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int freerdp_peer_drain_output_buffer(freerdp_peer* peer)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpTransport* transport = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(peer->context);
|
|
|
|
WINPR_ASSERT(peer->context->rdp);
|
|
|
|
WINPR_ASSERT(peer->context->rdp->transport);
|
|
|
|
transport = peer->context->rdp->transport;
|
2015-02-17 18:54:39 +03:00
|
|
|
return transport_drain_output_buffer(transport);
|
2014-05-21 19:32:14 +04:00
|
|
|
}
|
|
|
|
|
2016-10-13 23:02:25 +03:00
|
|
|
static BOOL freerdp_peer_has_more_to_read(freerdp_peer* peer)
|
|
|
|
{
|
2021-08-24 15:14:37 +03:00
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(peer->context);
|
|
|
|
WINPR_ASSERT(peer->context->rdp);
|
2021-09-06 12:01:36 +03:00
|
|
|
return transport_have_more_bytes_to_read(peer->context->rdp->transport);
|
2016-05-03 18:24:07 +03:00
|
|
|
}
|
|
|
|
|
2019-05-08 15:35:25 +03:00
|
|
|
static LicenseCallbackResult freerdp_peer_nolicense(freerdp_peer* peer, wStream* s)
|
2018-11-01 13:02:54 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
2021-08-24 15:14:37 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(peer->context);
|
|
|
|
|
|
|
|
rdp = peer->context->rdp;
|
2018-11-01 13:02:54 +03:00
|
|
|
|
|
|
|
if (!license_send_valid_client_error_packet(rdp))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "freerdp_peer_nolicense: license_send_valid_client_error_packet() failed");
|
|
|
|
return LICENSE_CB_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LICENSE_CB_COMPLETED;
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
BOOL freerdp_peer_context_new(freerdp_peer* client)
|
2011-10-18 11:10:12 +04:00
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
return freerdp_peer_context_new_ex(client, NULL);
|
2011-10-18 11:10:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_peer_context_free(freerdp_peer* client)
|
|
|
|
{
|
2021-08-24 15:14:37 +03:00
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
IFCALL(client->ContextFree, client, client->context);
|
2014-06-03 16:54:56 +04:00
|
|
|
|
2016-08-27 16:51:29 +03:00
|
|
|
if (client->context)
|
|
|
|
{
|
2021-09-10 10:06:35 +03:00
|
|
|
rdpContext* ctx = client->context;
|
|
|
|
|
2023-03-06 14:53:32 +03:00
|
|
|
CloseHandle(ctx->channelErrorEvent);
|
|
|
|
ctx->channelErrorEvent = NULL;
|
2021-09-10 10:06:35 +03:00
|
|
|
free(ctx->errorDescription);
|
|
|
|
ctx->errorDescription = NULL;
|
|
|
|
rdp_free(ctx->rdp);
|
|
|
|
ctx->rdp = NULL;
|
|
|
|
metrics_free(ctx->metrics);
|
|
|
|
ctx->metrics = NULL;
|
2021-09-23 15:52:03 +03:00
|
|
|
stream_dump_free(ctx->dump);
|
|
|
|
ctx->dump = NULL;
|
2021-09-10 10:06:35 +03:00
|
|
|
free(ctx);
|
2016-08-27 16:51:29 +03:00
|
|
|
}
|
2021-09-17 10:26:18 +03:00
|
|
|
client->context = NULL;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2022-07-05 12:38:52 +03:00
|
|
|
static const char* os_major_type_to_string(UINT16 osMajorType)
|
|
|
|
{
|
|
|
|
switch (osMajorType)
|
|
|
|
{
|
|
|
|
case OSMAJORTYPE_UNSPECIFIED:
|
|
|
|
return "Unspecified platform";
|
|
|
|
case OSMAJORTYPE_WINDOWS:
|
|
|
|
return "Windows platform";
|
|
|
|
case OSMAJORTYPE_OS2:
|
|
|
|
return "OS/2 platform";
|
|
|
|
case OSMAJORTYPE_MACINTOSH:
|
|
|
|
return "Macintosh platform";
|
|
|
|
case OSMAJORTYPE_UNIX:
|
|
|
|
return "UNIX platform";
|
|
|
|
case OSMAJORTYPE_IOS:
|
|
|
|
return "iOS platform";
|
|
|
|
case OSMAJORTYPE_OSX:
|
|
|
|
return "OS X platform";
|
|
|
|
case OSMAJORTYPE_ANDROID:
|
|
|
|
return "Android platform";
|
|
|
|
case OSMAJORTYPE_CHROME_OS:
|
|
|
|
return "Chrome OS platform";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown platform";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* freerdp_peer_os_major_type_string(freerdp_peer* client)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpContext* context = NULL;
|
|
|
|
UINT16 osMajorType = 0;
|
2022-07-05 12:38:52 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
|
|
|
context = client->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
|
|
|
|
osMajorType = freerdp_settings_get_uint32(context->settings, FreeRDP_OsMajorType);
|
|
|
|
|
|
|
|
return os_major_type_to_string(osMajorType);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* os_minor_type_to_string(UINT16 osMinorType)
|
|
|
|
{
|
|
|
|
switch (osMinorType)
|
|
|
|
{
|
|
|
|
case OSMINORTYPE_UNSPECIFIED:
|
|
|
|
return "Unspecified version";
|
|
|
|
case OSMINORTYPE_WINDOWS_31X:
|
|
|
|
return "Windows 3.1x";
|
|
|
|
case OSMINORTYPE_WINDOWS_95:
|
|
|
|
return "Windows 95";
|
|
|
|
case OSMINORTYPE_WINDOWS_NT:
|
|
|
|
return "Windows NT";
|
|
|
|
case OSMINORTYPE_OS2_V21:
|
|
|
|
return "OS/2 2.1";
|
|
|
|
case OSMINORTYPE_POWER_PC:
|
|
|
|
return "PowerPC";
|
|
|
|
case OSMINORTYPE_MACINTOSH:
|
|
|
|
return "Macintosh";
|
|
|
|
case OSMINORTYPE_NATIVE_XSERVER:
|
|
|
|
return "Native X Server";
|
|
|
|
case OSMINORTYPE_PSEUDO_XSERVER:
|
|
|
|
return "Pseudo X Server";
|
|
|
|
case OSMINORTYPE_WINDOWS_RT:
|
|
|
|
return "Windows RT";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown version";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* freerdp_peer_os_minor_type_string(freerdp_peer* client)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpContext* context = NULL;
|
|
|
|
UINT16 osMinorType = 0;
|
2022-07-05 12:38:52 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
|
|
|
context = client->context;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
|
|
|
|
osMinorType = freerdp_settings_get_uint32(context->settings, FreeRDP_OsMinorType);
|
|
|
|
|
|
|
|
return os_minor_type_to_string(osMinorType);
|
|
|
|
}
|
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
freerdp_peer* freerdp_peer_new(int sockfd)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 option_value = 0;
|
|
|
|
socklen_t option_len = 0;
|
2022-10-21 10:59:04 +03:00
|
|
|
freerdp_peer* client = (freerdp_peer*)calloc(1, sizeof(freerdp_peer));
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2014-11-12 22:06:34 +03:00
|
|
|
if (!client)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
option_value = TRUE;
|
|
|
|
option_len = sizeof(option_value);
|
2022-10-21 10:59:04 +03:00
|
|
|
|
|
|
|
if (sockfd >= 0)
|
2024-06-05 16:17:07 +03:00
|
|
|
{
|
|
|
|
if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*)&option_value, option_len) < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2013-07-21 06:34:05 +04:00
|
|
|
if (client)
|
2011-10-30 09:43:04 +04:00
|
|
|
{
|
|
|
|
client->sockfd = sockfd;
|
2013-06-14 05:34:46 +04:00
|
|
|
client->ContextSize = sizeof(rdpContext);
|
2011-10-30 09:43:04 +04:00
|
|
|
client->Initialize = freerdp_peer_initialize;
|
2021-08-24 16:04:58 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
2011-10-30 09:43:04 +04:00
|
|
|
client->GetFileDescriptor = freerdp_peer_get_fds;
|
2021-08-24 16:04:58 +03:00
|
|
|
#endif
|
2016-10-28 19:28:10 +03:00
|
|
|
client->GetEventHandle = freerdp_peer_get_event_handle;
|
2016-10-27 18:43:09 +03:00
|
|
|
client->GetEventHandles = freerdp_peer_get_event_handles;
|
2011-10-30 09:43:04 +04:00
|
|
|
client->CheckFileDescriptor = freerdp_peer_check_fds;
|
2012-04-13 11:58:28 +04:00
|
|
|
client->Close = freerdp_peer_close;
|
2011-10-30 09:43:04 +04:00
|
|
|
client->Disconnect = freerdp_peer_disconnect;
|
2011-12-10 12:41:29 +04:00
|
|
|
client->SendChannelData = freerdp_peer_send_channel_data;
|
2021-08-26 17:17:51 +03:00
|
|
|
client->SendChannelPacket = freerdp_peer_send_channel_packet;
|
2022-09-27 18:09:53 +03:00
|
|
|
client->SendServerRedirection = freerdp_peer_send_server_redirection_pdu;
|
2014-05-21 19:32:14 +04:00
|
|
|
client->IsWriteBlocked = freerdp_peer_is_write_blocked;
|
|
|
|
client->DrainOutputBuffer = freerdp_peer_drain_output_buffer;
|
2016-05-03 18:24:07 +03:00
|
|
|
client->HasMoreToRead = freerdp_peer_has_more_to_read;
|
2014-10-11 00:11:42 +04:00
|
|
|
client->VirtualChannelOpen = freerdp_peer_virtual_channel_open;
|
|
|
|
client->VirtualChannelClose = freerdp_peer_virtual_channel_close;
|
|
|
|
client->VirtualChannelWrite = freerdp_peer_virtual_channel_write;
|
2014-10-11 01:19:38 +04:00
|
|
|
client->VirtualChannelRead = NULL; /* must be defined by server application */
|
|
|
|
client->VirtualChannelGetData = freerdp_peer_virtual_channel_get_data;
|
|
|
|
client->VirtualChannelSetData = freerdp_peer_virtual_channel_set_data;
|
2022-03-18 11:23:00 +03:00
|
|
|
client->SetState = freerdp_peer_set_state;
|
2011-10-30 09:43:04 +04:00
|
|
|
}
|
2011-08-18 12:06:32 +04:00
|
|
|
|
|
|
|
return client;
|
2024-06-05 16:17:07 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
freerdp_peer_free(client);
|
|
|
|
return NULL;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_peer_free(freerdp_peer* client)
|
|
|
|
{
|
2014-05-21 19:32:14 +04:00
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
2022-03-25 15:06:36 +03:00
|
|
|
sspi_FreeAuthIdentity(&client->identity);
|
2024-02-09 18:13:32 +03:00
|
|
|
if (client->sockfd >= 0)
|
|
|
|
closesocket((SOCKET)client->sockfd);
|
2014-05-21 19:32:14 +04:00
|
|
|
free(client);
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
2022-03-23 15:18:35 +03:00
|
|
|
|
2024-01-29 13:34:11 +03:00
|
|
|
static BOOL freerdp_peer_transport_setup(freerdp_peer* client)
|
2022-10-21 10:59:04 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
2022-10-21 10:59:04 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->context);
|
|
|
|
|
|
|
|
rdp = client->context->rdp;
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
|
|
|
if (!transport_attach(rdp->transport, client->sockfd))
|
|
|
|
return FALSE;
|
2024-02-09 18:13:32 +03:00
|
|
|
client->sockfd = -1;
|
2022-10-21 10:59:04 +03:00
|
|
|
|
|
|
|
if (!transport_set_recv_callbacks(rdp->transport, peer_recv_callback, client))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!transport_set_blocking_mode(rdp->transport, FALSE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
BOOL freerdp_peer_context_new_ex(freerdp_peer* client, const rdpSettings* settings)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
|
|
|
rdpContext* context = NULL;
|
2022-03-23 15:18:35 +03:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
if (!client)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-04-21 13:34:18 +03:00
|
|
|
WINPR_ASSERT(client->ContextSize >= sizeof(rdpContext));
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!(context = (rdpContext*)calloc(1, client->ContextSize)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
client->context = context;
|
|
|
|
context->peer = client;
|
|
|
|
context->ServerMode = TRUE;
|
2024-01-24 10:21:47 +03:00
|
|
|
context->log = WLog_Get(TAG);
|
|
|
|
if (!context->log)
|
|
|
|
goto fail;
|
2022-03-23 15:18:35 +03:00
|
|
|
|
|
|
|
if (settings)
|
|
|
|
{
|
|
|
|
context->settings = freerdp_settings_clone(settings);
|
|
|
|
if (!context->settings)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->dump = stream_dump_new();
|
|
|
|
if (!context->dump)
|
|
|
|
goto fail;
|
|
|
|
if (!(context->metrics = metrics_new(context)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!(rdp = rdp_new(context)))
|
|
|
|
goto fail;
|
|
|
|
|
2023-05-22 21:54:46 +03:00
|
|
|
rdp_log_build_warnings(rdp);
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
#if defined(WITH_FREERDP_DEPRECATED)
|
|
|
|
client->update = rdp->update;
|
|
|
|
client->settings = rdp->settings;
|
|
|
|
client->autodetect = rdp->autodetect;
|
|
|
|
#endif
|
|
|
|
context->rdp = rdp;
|
|
|
|
context->input = rdp->input;
|
|
|
|
context->update = rdp->update;
|
|
|
|
context->settings = rdp->settings;
|
|
|
|
context->autodetect = rdp->autodetect;
|
|
|
|
update_register_server_callbacks(rdp->update);
|
|
|
|
autodetect_register_server_callbacks(rdp->autodetect);
|
|
|
|
|
2023-03-06 14:53:32 +03:00
|
|
|
if (!(context->channelErrorEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "CreateEvent failed!");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!(context->errorDescription = calloc(1, 500)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:34:11 +03:00
|
|
|
if (!freerdp_peer_transport_setup(client))
|
2022-03-23 15:18:35 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
client->IsWriteBlocked = freerdp_peer_is_write_blocked;
|
|
|
|
client->DrainOutputBuffer = freerdp_peer_drain_output_buffer;
|
|
|
|
client->HasMoreToRead = freerdp_peer_has_more_to_read;
|
|
|
|
client->LicenseCallback = freerdp_peer_nolicense;
|
|
|
|
IFCALLRET(client->ContextNew, ret, client, client->context);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
goto fail;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
WLog_ERR(TAG, "ContextNew callback failed");
|
|
|
|
freerdp_peer_context_free(client);
|
|
|
|
return FALSE;
|
|
|
|
}
|