2011-07-25 21:52:48 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-25 21:52:48 +04:00
|
|
|
* Activation Sequence
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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-09-06 12:39:26 +03:00
|
|
|
#include <winpr/assert.h>
|
|
|
|
|
2011-07-25 21:52:48 +04:00
|
|
|
#include "activation.h"
|
2019-05-20 14:05:32 +03:00
|
|
|
#include "display.h"
|
2011-07-25 21:52:48 +04:00
|
|
|
|
2020-02-20 19:26:27 +03:00
|
|
|
#define TAG FREERDP_TAG("core.activation")
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL rdp_recv_client_font_list_pdu(wStream* s);
|
2020-11-19 17:21:49 +03:00
|
|
|
static BOOL rdp_recv_client_persistent_key_list_pdu(wStream* s);
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp);
|
2011-07-25 21:52:48 +04:00
|
|
|
|
2021-09-06 12:39:26 +03:00
|
|
|
static BOOL rdp_write_synchronize_pdu(wStream* s, const rdpSettings* settings)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2022-10-21 10:28:53 +03:00
|
|
|
const UINT32 PduSource = freerdp_settings_get_uint32(settings, FreeRDP_PduSource);
|
2021-09-06 12:39:26 +03:00
|
|
|
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 4))
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2022-10-21 10:28:53 +03:00
|
|
|
Stream_Write_UINT16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, PduSource); /* targetUser (2 bytes) */
|
2020-11-19 17:21:49 +03:00
|
|
|
return TRUE;
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2022-10-21 15:13:50 +03:00
|
|
|
static BOOL rdp_recv_sync_pdu(rdpRdp* rdp, wStream* s, const char* what)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 msgType = 0;
|
|
|
|
UINT16 targetUser = 0;
|
2022-10-21 15:13:50 +03:00
|
|
|
|
|
|
|
WINPR_UNUSED(rdp);
|
2023-01-24 16:53:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthEx(TAG, WLOG_WARN, s, 4, 1, "%s(%s:%" PRIuz ") %s",
|
2023-07-27 10:02:03 +03:00
|
|
|
__func__, __FILE__, (size_t)__LINE__, what))
|
2022-10-21 15:13:50 +03:00
|
|
|
return FALSE;
|
|
|
|
Stream_Read_UINT16(s, msgType);
|
|
|
|
if (msgType != SYNCMSGTYPE_SYNC)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "%s: Invalid messageType=0x%04" PRIx16 ", expected 0x%04" PRIx16, what,
|
|
|
|
msgType, SYNCMSGTYPE_SYNC);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
Stream_Read_UINT16(s, targetUser);
|
|
|
|
WLog_VRB(TAG, "%s: targetUser=0x%04" PRIx16, what, targetUser);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2022-10-21 15:13:50 +03:00
|
|
|
if (!rdp_recv_sync_pdu(rdp, s, "[MS-RDPBCGR] 2.2.1.19 Server Synchronize PDU"))
|
|
|
|
return FALSE;
|
2022-06-23 10:59:24 +03:00
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_SC_SYNCHRONIZE_PDU);
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_server_synchronize_pdu(rdpRdp* rdp)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!rdp_write_synchronize_pdu(s, rdp->settings))
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId);
|
2011-08-21 17:48:42 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, wStream* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2022-10-21 15:13:50 +03:00
|
|
|
if (!rdp_recv_sync_pdu(rdp, s, "[MS-RDPBCGR] 2.2.1.14 Client Synchronize PDU"))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2022-10-21 10:28:53 +03:00
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_CS_SYNCHRONIZE_PDU);
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_client_synchronize_pdu(rdpRdp* rdp)
|
2011-08-21 17:48:42 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!rdp_write_synchronize_pdu(s, rdp->settings))
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId);
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
static BOOL rdp_recv_control_pdu(wStream* s, UINT16* action, UINT16* grantId, UINT32* controlId)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(action);
|
2022-10-21 10:45:39 +03:00
|
|
|
WINPR_ASSERT(grantId);
|
|
|
|
WINPR_ASSERT(controlId);
|
2021-09-06 12:39:26 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
Stream_Read_UINT16(s, *action); /* action (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, *grantId); /* grantId (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, *controlId); /* controlId (4 bytes) */
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
static BOOL rdp_write_client_control_pdu(wStream* s, UINT16 action, UINT16 grantId,
|
|
|
|
UINT32 controlId)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(s);
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2022-10-21 10:45:39 +03:00
|
|
|
Stream_Write_UINT16(s, action); /* action (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, grantId); /* grantId (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, controlId); /* controlId (4 bytes) */
|
2020-11-19 17:21:49 +03:00
|
|
|
return TRUE;
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 action = 0;
|
|
|
|
UINT16 grantId = 0;
|
|
|
|
UINT32 controlId = 0;
|
2011-07-25 21:52:48 +04:00
|
|
|
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
if (!rdp_recv_control_pdu(s, &action, &grantId, &controlId))
|
2013-01-12 17:37:21 +04:00
|
|
|
return FALSE;
|
2011-07-25 21:52:48 +04:00
|
|
|
|
2011-12-19 00:15:48 +04:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CTRLACTION_COOPERATE:
|
2022-06-23 10:59:24 +03:00
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_SC_CONTROL_COOPERATE_PDU);
|
2011-12-19 00:15:48 +04:00
|
|
|
|
|
|
|
case CTRLACTION_GRANTED_CONTROL:
|
2013-04-15 14:14:09 +04:00
|
|
|
rdp->resendFocus = TRUE;
|
2022-06-23 10:59:24 +03:00
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_SC_CONTROL_GRANTED_PDU);
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
char buffer[128] = { 0 };
|
|
|
|
WLog_WARN(TAG, "Unexpected control PDU %s",
|
|
|
|
rdp_ctrlaction_string(action, buffer, sizeof(buffer)));
|
2022-10-21 10:45:39 +03:00
|
|
|
|
|
|
|
return FALSE;
|
2022-06-23 10:59:24 +03:00
|
|
|
}
|
2011-12-19 00:15:48 +04:00
|
|
|
}
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_server_control_cooperate_pdu(rdpRdp* rdp)
|
2011-08-21 17:48:42 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
|
2020-11-19 17:21:49 +03:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, CTRLACTION_COOPERATE); /* action (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 0); /* grantId (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0); /* controlId (4 bytes) */
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
|
2011-08-21 17:48:42 +04:00
|
|
|
}
|
|
|
|
|
2023-08-31 18:21:49 +03:00
|
|
|
BOOL rdp_send_server_control_granted_pdu(rdpRdp* rdp)
|
2011-08-21 17:48:42 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
|
2020-11-19 17:21:49 +03:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, CTRLACTION_GRANTED_CONTROL); /* action (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, rdp->mcs->userId); /* grantId (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0x03EA); /* controlId (4 bytes) */
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
|
2011-08-21 17:48:42 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2022-10-21 10:45:39 +03:00
|
|
|
UINT16 GrantId = 0;
|
|
|
|
UINT16 ControlId = 0;
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CTRLACTION_COOPERATE:
|
|
|
|
case CTRLACTION_REQUEST_CONTROL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Invalid client control PDU::action 0x%04" PRIx16 ", not allowed by client",
|
|
|
|
action);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2022-10-21 10:45:39 +03:00
|
|
|
if (!rdp_write_client_control_pdu(s, action, GrantId, ControlId))
|
2020-11-19 17:21:49 +03:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2024-01-24 09:58:22 +03:00
|
|
|
static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s,
|
|
|
|
const RDP_BITMAP_PERSISTENT_INFO* info)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(s);
|
2022-05-30 23:32:23 +03:00
|
|
|
WINPR_ASSERT(info);
|
2021-09-06 12:39:26 +03:00
|
|
|
|
2022-09-12 11:21:42 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 24))
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2022-05-30 23:32:23 +03:00
|
|
|
|
|
|
|
Stream_Write_UINT16(s, info->numEntriesCache0); /* numEntriesCache0 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->numEntriesCache1); /* numEntriesCache1 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->numEntriesCache2); /* numEntriesCache2 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->numEntriesCache3); /* numEntriesCache3 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->numEntriesCache4); /* numEntriesCache4 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->totalEntriesCache0); /* totalEntriesCache0 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->totalEntriesCache1); /* totalEntriesCache1 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->totalEntriesCache2); /* totalEntriesCache2 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->totalEntriesCache3); /* totalEntriesCache3 (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, info->totalEntriesCache4); /* totalEntriesCache4 (2 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, PERSIST_FIRST_PDU | PERSIST_LAST_PDU); /* bBitMask (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0); /* pad1 (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, 0); /* pad3 (2 bytes) */
|
|
|
|
/* entries */
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2022-11-15 16:19:54 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, info->keyCount * 8ull))
|
2022-09-12 11:21:42 +03:00
|
|
|
return FALSE;
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2022-12-05 10:58:38 +03:00
|
|
|
for (UINT32 index = 0; index < info->keyCount; index++)
|
2022-05-30 23:32:23 +03:00
|
|
|
{
|
2022-12-05 10:58:38 +03:00
|
|
|
const UINT32 key1 = (UINT32)info->keyList[index];
|
|
|
|
const UINT32 key2 = (UINT32)(info->keyList[index] >> 32);
|
2022-05-30 23:32:23 +03:00
|
|
|
Stream_Write_UINT32(s, key1);
|
|
|
|
Stream_Write_UINT32(s, key2);
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
return TRUE;
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2022-06-20 16:54:46 +03:00
|
|
|
static UINT32 rdp_load_persistent_key_list(rdpRdp* rdp, UINT64** pKeyList)
|
2022-05-30 23:32:23 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int count = 0;
|
|
|
|
int status = 0;
|
|
|
|
UINT32 keyCount = 0;
|
2022-05-30 23:32:23 +03:00
|
|
|
UINT64* keyList = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpPersistentCache* persistent = NULL;
|
2022-05-30 23:32:23 +03:00
|
|
|
rdpSettings* settings = rdp->settings;
|
|
|
|
|
|
|
|
*pKeyList = NULL;
|
|
|
|
|
2023-01-09 17:56:20 +03:00
|
|
|
if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled))
|
2022-05-30 23:32:23 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!settings->BitmapCachePersistFile)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
persistent = persistent_cache_new();
|
|
|
|
|
|
|
|
if (!persistent)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
status = persistent_cache_open(persistent, settings->BitmapCachePersistFile, FALSE, 0);
|
|
|
|
|
|
|
|
if (status < 1)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
count = persistent_cache_get_count(persistent);
|
|
|
|
|
|
|
|
keyCount = (UINT32)count;
|
|
|
|
keyList = (UINT64*)malloc(keyCount * sizeof(UINT64));
|
|
|
|
|
|
|
|
if (!keyList)
|
|
|
|
goto error;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (int index = 0; index < count; index++)
|
2022-05-30 23:32:23 +03:00
|
|
|
{
|
2022-11-15 16:19:54 +03:00
|
|
|
PERSISTENT_CACHE_ENTRY cacheEntry = { 0 };
|
2022-09-12 11:21:42 +03:00
|
|
|
|
2022-05-30 23:32:23 +03:00
|
|
|
if (persistent_cache_read_entry(persistent, &cacheEntry) < 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
keyList[index] = cacheEntry.key64;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pKeyList = keyList;
|
|
|
|
|
|
|
|
persistent_cache_free(persistent);
|
|
|
|
return keyCount;
|
|
|
|
error:
|
|
|
|
persistent_cache_free(persistent);
|
|
|
|
free(keyList);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2022-05-30 23:32:23 +03:00
|
|
|
UINT32 keyMaxFrag = 2042;
|
|
|
|
UINT64* keyList = NULL;
|
2024-01-24 09:58:22 +03:00
|
|
|
RDP_BITMAP_PERSISTENT_INFO info = { 0 };
|
2022-05-30 23:32:23 +03:00
|
|
|
rdpSettings* settings = rdp->settings;
|
2024-01-24 09:58:22 +03:00
|
|
|
UINT32 keyCount = rdp_load_persistent_key_list(rdp, &keyList);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2022-09-29 15:55:27 +03:00
|
|
|
WLog_DBG(TAG, "Persistent Key List: TotalKeyCount: %" PRIu32 " MaxKeyFrag: %" PRIu32, keyCount,
|
|
|
|
keyMaxFrag);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
|
|
|
// MS-RDPBCGR recommends sending no more than 169 entries at once.
|
|
|
|
// In practice, sending more than 2042 entries at once triggers an error.
|
|
|
|
// It should be possible to advertise the entire client bitmap cache
|
|
|
|
// by sending multiple persistent key list PDUs, but the current code
|
|
|
|
// only bothers sending a single, smaller list of entries instead.
|
|
|
|
|
|
|
|
if (keyCount > keyMaxFrag)
|
|
|
|
keyCount = keyMaxFrag;
|
|
|
|
|
|
|
|
info.totalEntriesCache0 = settings->BitmapCacheV2CellInfo[0].numEntries;
|
|
|
|
info.totalEntriesCache1 = settings->BitmapCacheV2CellInfo[1].numEntries;
|
|
|
|
info.totalEntriesCache2 = settings->BitmapCacheV2CellInfo[2].numEntries;
|
|
|
|
info.totalEntriesCache3 = settings->BitmapCacheV2CellInfo[3].numEntries;
|
|
|
|
info.totalEntriesCache4 = settings->BitmapCacheV2CellInfo[4].numEntries;
|
|
|
|
|
|
|
|
info.numEntriesCache0 = MIN(keyCount, info.totalEntriesCache0);
|
|
|
|
keyCount -= info.numEntriesCache0;
|
|
|
|
info.numEntriesCache1 = MIN(keyCount, info.totalEntriesCache1);
|
|
|
|
keyCount -= info.numEntriesCache1;
|
|
|
|
info.numEntriesCache2 = MIN(keyCount, info.totalEntriesCache2);
|
|
|
|
keyCount -= info.numEntriesCache2;
|
|
|
|
info.numEntriesCache3 = MIN(keyCount, info.totalEntriesCache3);
|
|
|
|
keyCount -= info.numEntriesCache3;
|
|
|
|
info.numEntriesCache4 = MIN(keyCount, info.totalEntriesCache4);
|
|
|
|
keyCount -= info.numEntriesCache4;
|
|
|
|
|
|
|
|
info.totalEntriesCache0 = info.numEntriesCache0;
|
|
|
|
info.totalEntriesCache1 = info.numEntriesCache1;
|
|
|
|
info.totalEntriesCache2 = info.numEntriesCache2;
|
|
|
|
info.totalEntriesCache3 = info.numEntriesCache3;
|
|
|
|
info.totalEntriesCache4 = info.numEntriesCache4;
|
|
|
|
|
|
|
|
keyCount = info.totalEntriesCache0 + info.totalEntriesCache1 + info.totalEntriesCache2 +
|
|
|
|
info.totalEntriesCache3 + info.totalEntriesCache4;
|
|
|
|
|
|
|
|
info.keyCount = keyCount;
|
|
|
|
info.keyList = keyList;
|
|
|
|
|
2022-09-29 15:55:27 +03:00
|
|
|
WLog_DBG(TAG, "persistentKeyList count: %" PRIu32, info.keyCount);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2022-09-29 15:55:27 +03:00
|
|
|
WLog_DBG(TAG,
|
|
|
|
"numEntriesCache: [0]: %" PRIu16 " [1]: %" PRIu16 " [2]: %" PRIu16 " [3]: %" PRIu16
|
|
|
|
" [4]: %" PRIu16,
|
|
|
|
info.numEntriesCache0, info.numEntriesCache1, info.numEntriesCache2,
|
|
|
|
info.numEntriesCache3, info.numEntriesCache4);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2022-09-29 15:55:27 +03:00
|
|
|
WLog_DBG(TAG,
|
|
|
|
"totalEntriesCache: [0]: %" PRIu16 " [1]: %" PRIu16 " [2]: %" PRIu16 " [3]: %" PRIu16
|
|
|
|
" [4]: %" PRIu16,
|
2022-09-12 11:21:42 +03:00
|
|
|
info.totalEntriesCache0, info.totalEntriesCache1, info.totalEntriesCache2,
|
|
|
|
info.totalEntriesCache3, info.totalEntriesCache4);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
2024-01-24 10:21:47 +03:00
|
|
|
{
|
|
|
|
free(keyList);
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2024-01-24 10:21:47 +03:00
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
|
2022-05-30 23:32:23 +03:00
|
|
|
if (!rdp_write_client_persistent_key_list_pdu(s, &info))
|
2020-11-19 17:21:49 +03:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2024-01-24 10:21:47 +03:00
|
|
|
free(keyList);
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2022-05-30 23:32:23 +03:00
|
|
|
free(keyList);
|
|
|
|
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->userId);
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_client_font_list_pdu(wStream* s)
|
2011-08-21 19:20:37 +04:00
|
|
|
{
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(s);
|
2020-11-19 17:21:49 +03:00
|
|
|
/* 2.2.1.18 Client Font List PDU */
|
2022-10-21 10:45:39 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
return Stream_SafeSeek(s, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL rdp_recv_client_persistent_key_list_pdu(wStream* s)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE flags = 0;
|
2020-11-19 17:21:49 +03:00
|
|
|
size_t count = 0;
|
2021-11-30 11:28:40 +03:00
|
|
|
size_t total = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 cache = 0;
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
/* 2.2.1.17.1 Persistent Key List PDU Data (TS_BITMAPCACHE_PERSISTENT_LIST_PDU) */
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 21))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "short TS_BITMAPCACHE_PERSISTENT_LIST_PDU, need 21 bytes, got %" PRIuz,
|
|
|
|
Stream_GetRemainingLength(s));
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2022-04-19 15:29:17 +03:00
|
|
|
}
|
2020-11-19 17:21:49 +03:00
|
|
|
/* Read numEntriesCacheX for variable length data in PDU */
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < 5; x++)
|
2020-11-19 17:21:49 +03:00
|
|
|
{
|
|
|
|
Stream_Read_UINT16(s, cache);
|
|
|
|
count += cache;
|
|
|
|
}
|
2011-08-21 19:20:37 +04:00
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
/* Skip totalEntriesCacheX */
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < 5; x++)
|
2021-11-30 11:28:40 +03:00
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
UINT16 tmp = 0;
|
2021-11-30 11:28:40 +03:00
|
|
|
Stream_Read_UINT16(s, tmp);
|
|
|
|
total += tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total > 262144)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"TS_BITMAPCACHE_PERSISTENT_LIST_PDU::totalEntriesCacheX exceeds 262144 entries");
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2021-11-30 11:28:40 +03:00
|
|
|
}
|
2020-11-19 17:21:49 +03:00
|
|
|
|
|
|
|
Stream_Read_UINT8(s, flags);
|
2021-11-30 11:28:40 +03:00
|
|
|
if ((flags & ~(PERSIST_LAST_PDU | PERSIST_FIRST_PDU)) != 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"TS_BITMAPCACHE_PERSISTENT_LIST_PDU::bBitMask has an invalid value of 0x%02" PRIx8,
|
|
|
|
flags);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-11-19 17:21:49 +03:00
|
|
|
|
|
|
|
/* Skip padding */
|
|
|
|
if (!Stream_SafeSeek(s, 3))
|
2022-04-19 15:29:17 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "short TS_BITMAPCACHE_PERSISTENT_LIST_PDU, need 3 bytes, got %" PRIuz,
|
|
|
|
Stream_GetRemainingLength(s));
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2022-04-19 15:29:17 +03:00
|
|
|
}
|
2020-11-19 17:21:49 +03:00
|
|
|
/* Skip actual entries sent by client */
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_SafeSeek(s, count * sizeof(UINT64)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"short TS_BITMAPCACHE_PERSISTENT_LIST_PDU, need %" PRIuz " bytes, got %" PRIuz,
|
|
|
|
count * sizeof(UINT64), Stream_GetRemainingLength(s));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2011-08-21 19:20:37 +04:00
|
|
|
}
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
static BOOL rdp_write_client_font_list_pdu(wStream* s, UINT16 flags)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
|
2020-11-19 17:21:49 +03:00
|
|
|
return FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 0); /* numberFonts (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0); /* totalNumFonts (2 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, flags); /* listFlags (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 50); /* entrySize (2 bytes) */
|
2020-11-19 17:21:49 +03:00
|
|
|
return TRUE;
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL rdp_send_client_font_list_pdu(rdpRdp* rdp, UINT16 flags)
|
2011-07-25 21:52:48 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
if (!rdp_write_client_font_list_pdu(s, flags))
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->userId);
|
2011-07-25 21:52:48 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s)
|
2012-01-09 01:02:59 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 numberEntries = 0;
|
|
|
|
UINT16 totalNumEntries = 0;
|
|
|
|
UINT16 mapFlags = 0;
|
|
|
|
UINT16 entrySize = 0;
|
2022-11-04 11:38:53 +03:00
|
|
|
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(rdp->settings);
|
|
|
|
WINPR_ASSERT(s);
|
2022-10-21 10:45:39 +03:00
|
|
|
WINPR_ASSERT(!freerdp_settings_get_bool(rdp->settings, FreeRDP_ServerMode));
|
2021-09-06 12:39:26 +03:00
|
|
|
|
2022-11-04 11:47:22 +03:00
|
|
|
/* Do not fail here, see https://github.com/FreeRDP/FreeRDP/issues/925 */
|
|
|
|
if (Stream_CheckAndLogRequiredLength(TAG, s, 8))
|
|
|
|
{
|
|
|
|
Stream_Read_UINT16(s, numberEntries); /* numberEntries (2 bytes) */
|
|
|
|
if (numberEntries != 0)
|
|
|
|
WLog_WARN(
|
|
|
|
TAG,
|
|
|
|
"[MS-RDPBCGR] 2.2.1.22.1 Font Map PDU Data (TS_FONT_MAP_PDU)::numberEntries != 0 "
|
|
|
|
"[%" PRIu16 "]",
|
|
|
|
numberEntries);
|
|
|
|
Stream_Read_UINT16(s, totalNumEntries); /* totalNumEntries (2 bytes) */
|
|
|
|
if (totalNumEntries != 0)
|
|
|
|
WLog_WARN(
|
|
|
|
TAG,
|
|
|
|
"[MS-RDPBCGR] 2.2.1.22.1 Font Map PDU Data (TS_FONT_MAP_PDU)::totalNumEntries != "
|
|
|
|
"0 [%" PRIu16 "]",
|
|
|
|
totalNumEntries);
|
|
|
|
Stream_Read_UINT16(s, mapFlags); /* mapFlags (2 bytes) */
|
2022-11-08 13:31:20 +03:00
|
|
|
if (mapFlags != (FONTLIST_FIRST | FONTLIST_LAST))
|
2022-11-04 11:47:22 +03:00
|
|
|
WLog_WARN(
|
|
|
|
TAG,
|
|
|
|
"[MS-RDPBCGR] 2.2.1.22.1 Font Map PDU Data (TS_FONT_MAP_PDU)::mapFlags != 0x0003 "
|
|
|
|
"(FONTLIST_FIRST | FONTLIST_LAST) "
|
|
|
|
"[0x%04" PRIx16 "]",
|
|
|
|
mapFlags);
|
|
|
|
Stream_Read_UINT16(s, entrySize); /* entrySize (2 bytes) */
|
|
|
|
if (entrySize != 4)
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"[MS-RDPBCGR] 2.2.1.22.1 Font Map PDU Data (TS_FONT_MAP_PDU)::entrySize != 4 "
|
|
|
|
"[%" PRIu16 "]",
|
|
|
|
entrySize);
|
|
|
|
}
|
|
|
|
else
|
2022-11-04 11:38:53 +03:00
|
|
|
WLog_WARN(TAG,
|
2022-11-04 11:47:22 +03:00
|
|
|
"[MS-RDPBCGR] 2.2.1.22.1 Font Map PDU Data (TS_FONT_MAP_PDU) paylaod size is "
|
|
|
|
"0 instead of 8");
|
2012-01-09 01:02:59 +04:00
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_SC_FONT_MAP_PDU);
|
2012-01-09 01:02:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp)
|
2011-08-21 19:20:37 +04:00
|
|
|
{
|
2020-11-19 17:21:49 +03:00
|
|
|
wStream* s = rdp_data_pdu_init(rdp);
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
|
2020-11-19 17:21:49 +03:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 0); /* numberEntries (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0); /* totalNumEntries (2 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, FONTLIST_FIRST | FONTLIST_LAST); /* mapFlags (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 4); /* entrySize (2 bytes) */
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_MAP, rdp->mcs->userId);
|
2011-08-21 19:20:37 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)
|
2011-07-29 01:44:09 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 lengthSourceDescriptor = 0;
|
2011-07-29 01:44:09 +04:00
|
|
|
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2021-09-03 09:17:27 +03:00
|
|
|
if (rdp_get_state(rdp) == CONNECTION_STATE_ACTIVE)
|
2022-06-23 10:59:24 +03:00
|
|
|
{
|
|
|
|
if (!rdp_finalize_set_flag(rdp, FINALIZE_DEACTIVATE_REACTIVATE))
|
|
|
|
return FALSE;
|
2022-10-21 10:53:24 +03:00
|
|
|
|
|
|
|
rdp->was_deactivated = TRUE;
|
|
|
|
rdp->deactivated_height = freerdp_settings_get_uint32(rdp->settings, FreeRDP_DesktopHeight);
|
|
|
|
rdp->deactivated_width = freerdp_settings_get_uint32(rdp->settings, FreeRDP_DesktopWidth);
|
2022-06-23 10:59:24 +03:00
|
|
|
}
|
2013-07-20 05:52:28 +04:00
|
|
|
|
2012-02-07 01:34:16 +04:00
|
|
|
/*
|
|
|
|
* Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain
|
|
|
|
* the following fields.
|
|
|
|
*/
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->settings);
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) > 0)
|
2012-02-07 01:34:16 +04:00
|
|
|
{
|
2013-05-15 23:54:33 +04:00
|
|
|
do
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 ShareId = 0;
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2013-01-15 02:40:34 +04:00
|
|
|
break;
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
Stream_Read_UINT32(s, ShareId); /* shareId (4 bytes) */
|
|
|
|
if (!freerdp_settings_set_uint32(rdp->settings, FreeRDP_ShareId, ShareId))
|
|
|
|
return FALSE;
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2013-01-15 02:40:34 +04:00
|
|
|
break;
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, lengthSourceDescriptor); /* lengthSourceDescriptor (2 bytes) */
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, lengthSourceDescriptor))
|
2013-01-15 02:40:34 +04:00
|
|
|
break;
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, lengthSourceDescriptor); /* sourceDescriptor (should be 0x00) */
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (0);
|
2012-02-07 01:34:16 +04:00
|
|
|
}
|
2011-07-29 01:44:09 +04:00
|
|
|
|
2022-11-08 13:54:03 +03:00
|
|
|
return rdp_client_transition_to_state(rdp,
|
|
|
|
CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE);
|
2011-07-29 01:44:09 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_deactivate_all(rdpRdp* rdp)
|
2011-09-06 13:19:16 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = rdp_send_stream_pdu_init(rdp);
|
2020-11-19 17:21:49 +03:00
|
|
|
BOOL status = FALSE;
|
2011-09-06 13:19:16 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
if (!s)
|
2015-03-23 19:25:23 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 7))
|
2020-11-19 17:21:49 +03:00
|
|
|
goto fail;
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->settings);
|
2022-10-21 10:45:39 +03:00
|
|
|
const UINT32 ShareId = freerdp_settings_get_uint32(rdp->settings, FreeRDP_ShareId);
|
|
|
|
Stream_Write_UINT32(s, ShareId); /* shareId (4 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->mcs);
|
2014-02-14 02:06:33 +04:00
|
|
|
status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId);
|
2020-11-19 17:21:49 +03:00
|
|
|
fail:
|
2018-10-02 14:18:13 +03:00
|
|
|
Stream_Release(s);
|
2013-05-15 23:54:33 +04:00
|
|
|
return status;
|
2011-09-06 13:19:16 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s)
|
2011-08-21 19:20:37 +04:00
|
|
|
{
|
2022-10-21 10:45:39 +03:00
|
|
|
UINT16 action = 0;
|
|
|
|
UINT16 GrantId = 0;
|
|
|
|
UINT32 ControlId = 0;
|
|
|
|
const CONNECTION_STATE state = rdp_get_state(rdp);
|
2011-08-21 19:20:37 +04:00
|
|
|
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
if (!rdp_recv_control_pdu(s, &action, &GrantId, &ControlId))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2022-10-21 10:45:39 +03:00
|
|
|
switch (action)
|
2011-08-21 19:20:37 +04:00
|
|
|
{
|
2022-10-21 10:45:39 +03:00
|
|
|
|
|
|
|
case CTRLACTION_REQUEST_CONTROL:
|
|
|
|
if (!rdp_finalize_is_flag_set(rdp, FINALIZE_CS_CONTROL_COOPERATE_PDU))
|
|
|
|
{
|
|
|
|
char abuffer[128] = { 0 };
|
|
|
|
char buffer[1024] = { 0 };
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Received action=%s with GrantId=0x%04" PRIx16 ", ControlId=0x%08" PRIx32
|
|
|
|
" in unexpected state %s [missing %s]",
|
|
|
|
rdp_ctrlaction_string(action, abuffer, sizeof(abuffer)), GrantId,
|
|
|
|
ControlId, rdp_state_string(state),
|
|
|
|
rdp_finalize_flags_to_str(FINALIZE_CS_CONTROL_COOPERATE_PDU, buffer,
|
|
|
|
sizeof(buffer)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((GrantId != 0) || (ControlId != 0))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Received CTRLACTION_COOPERATE with GrantId=0x%04" PRIx16
|
|
|
|
" != 0x00, ControlId=0x%08" PRIx32 " != 0x00",
|
|
|
|
GrantId, ControlId);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_CS_CONTROL_REQUEST_PDU);
|
|
|
|
case CTRLACTION_COOPERATE:
|
|
|
|
if (!rdp_finalize_is_flag_set(rdp, FINALIZE_CS_SYNCHRONIZE_PDU))
|
|
|
|
{
|
|
|
|
char abuffer[128] = { 0 };
|
|
|
|
char buffer[1024] = { 0 };
|
|
|
|
WLog_WARN(
|
|
|
|
TAG,
|
|
|
|
"Received action=%s with GrantId=0x%04" PRIx16 ", ControlId=0x%08" PRIx32
|
|
|
|
" in unexpected state %s [missing %s]",
|
|
|
|
rdp_ctrlaction_string(action, abuffer, sizeof(abuffer)), GrantId, ControlId,
|
|
|
|
rdp_state_string(state),
|
|
|
|
rdp_finalize_flags_to_str(FINALIZE_CS_SYNCHRONIZE_PDU, buffer, sizeof(buffer)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((GrantId != 0) || (ControlId != 0))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Received CTRLACTION_COOPERATE with GrantId=0x%04" PRIx16
|
|
|
|
" != 0x00, ControlId=0x%08" PRIx32 " != 0x00",
|
|
|
|
GrantId, ControlId);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return rdp_finalize_set_flag(rdp, FINALIZE_CS_CONTROL_COOPERATE_PDU);
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
char abuffer[128] = { 0 };
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Received unexpected action=%s with GrantId=0x%04" PRIx16
|
|
|
|
", ControlId=0x%08" PRIx32,
|
|
|
|
rdp_ctrlaction_string(action, abuffer, sizeof(abuffer)), GrantId, ControlId);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2022-10-21 10:45:39 +03:00
|
|
|
}
|
2011-08-21 19:20:37 +04:00
|
|
|
}
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-21 19:20:37 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s)
|
2011-08-21 19:20:37 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
freerdp_peer* peer = NULL;
|
2021-09-06 12:39:26 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
settings = rdp->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
WINPR_ASSERT(rdp->context);
|
|
|
|
peer = rdp->context->peer;
|
|
|
|
WINPR_ASSERT(peer);
|
2016-01-20 18:54:15 +03:00
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
if (!rdp_recv_client_font_list_pdu(s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2022-10-21 11:31:14 +03:00
|
|
|
rdp_finalize_set_flag(rdp, FINALIZE_CS_FONT_LIST_PDU);
|
2013-05-15 23:54:33 +04:00
|
|
|
|
2022-11-15 16:19:54 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-08-21 19:20:37 +04:00
|
|
|
if (!rdp_send_server_font_map_pdu(rdp))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 19:20:37 +04:00
|
|
|
|
2022-03-18 12:57:47 +03:00
|
|
|
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_ACTIVE))
|
2013-12-08 23:43:11 +04:00
|
|
|
return FALSE;
|
2013-07-18 23:18:59 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-21 19:20:37 +04:00
|
|
|
}
|
2020-11-19 17:21:49 +03:00
|
|
|
|
|
|
|
BOOL rdp_server_accept_client_persistent_key_list_pdu(rdpRdp* rdp, wStream* s)
|
|
|
|
{
|
2021-09-06 12:39:26 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
if (!rdp_recv_client_persistent_key_list_pdu(s))
|
|
|
|
return FALSE;
|
|
|
|
|
2022-10-21 11:31:14 +03:00
|
|
|
rdp_finalize_set_flag(rdp, FINALIZE_CS_PERSISTENT_KEY_LIST_PDU);
|
2020-11-19 17:21:49 +03:00
|
|
|
// TODO: Actually do something with this
|
|
|
|
return TRUE;
|
|
|
|
}
|
2022-06-23 10:59:24 +03:00
|
|
|
|
|
|
|
const char* rdp_ctrlaction_string(UINT16 action, char* buffer, size_t size)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
const char* actstr = NULL;
|
2022-06-23 10:59:24 +03:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CTRLACTION_COOPERATE:
|
|
|
|
actstr = "CTRLACTION_COOPERATE";
|
|
|
|
break;
|
|
|
|
case CTRLACTION_DETACH:
|
|
|
|
actstr = "CTRLACTION_DETACH";
|
|
|
|
break;
|
|
|
|
case CTRLACTION_GRANTED_CONTROL:
|
|
|
|
actstr = "CTRLACTION_GRANTED_CONTROL";
|
|
|
|
break;
|
|
|
|
case CTRLACTION_REQUEST_CONTROL:
|
|
|
|
actstr = "CTRLACTION_REQUEST_CONTROL";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
actstr = "CTRLACTION_UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_snprintf(buffer, size, "%s [0x%04" PRIx16 "]", actstr, action);
|
|
|
|
return buffer;
|
|
|
|
}
|