1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
|
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* 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.
*/
#include <freerdp/config.h>
#include "settings.h"
#include <winpr/assert.h>
#include "activation.h"
#include "display.h"
#define TAG FREERDP_TAG("core.activation")
static BOOL rdp_recv_client_font_list_pdu(wStream* s);
static BOOL rdp_recv_client_persistent_key_list_pdu(wStream* s);
static BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp);
static BOOL rdp_write_synchronize_pdu(wStream* s, const rdpSettings* settings)
{
const UINT32 PduSource = freerdp_settings_get_uint32(settings, FreeRDP_PduSource);
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 4))
return FALSE;
Stream_Write_UINT16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */
Stream_Write_UINT16(s, PduSource); /* targetUser (2 bytes) */
return TRUE;
}
static BOOL rdp_recv_sync_pdu(rdpRdp* rdp, wStream* s, const char* what)
{
UINT16 msgType = 0;
UINT16 targetUser = 0;
WINPR_UNUSED(rdp);
if (!Stream_CheckAndLogRequiredLengthEx(TAG, WLOG_WARN, s, 4, 1, "%s(%s:%" PRIuz ") %s",
__func__, __FILE__, (size_t)__LINE__, what))
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;
}
BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, wStream* s)
{
if (!rdp_recv_sync_pdu(rdp, s, "[MS-RDPBCGR] 2.2.1.19 Server Synchronize PDU"))
return FALSE;
return rdp_finalize_set_flag(rdp, FINALIZE_SC_SYNCHRONIZE_PDU);
}
BOOL rdp_send_server_synchronize_pdu(rdpRdp* rdp)
{
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
WINPR_ASSERT(rdp);
if (!rdp_write_synchronize_pdu(s, rdp->settings))
{
Stream_Free(s, TRUE);
return FALSE;
}
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId);
}
BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, wStream* s)
{
if (!rdp_recv_sync_pdu(rdp, s, "[MS-RDPBCGR] 2.2.1.14 Client Synchronize PDU"))
return FALSE;
return rdp_finalize_set_flag(rdp, FINALIZE_CS_SYNCHRONIZE_PDU);
}
BOOL rdp_send_client_synchronize_pdu(rdpRdp* rdp)
{
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
WINPR_ASSERT(rdp);
if (!rdp_write_synchronize_pdu(s, rdp->settings))
{
Stream_Free(s, TRUE);
return FALSE;
}
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId);
}
static BOOL rdp_recv_control_pdu(wStream* s, UINT16* action, UINT16* grantId, UINT32* controlId)
{
WINPR_ASSERT(s);
WINPR_ASSERT(action);
WINPR_ASSERT(grantId);
WINPR_ASSERT(controlId);
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
return FALSE;
Stream_Read_UINT16(s, *action); /* action (2 bytes) */
Stream_Read_UINT16(s, *grantId); /* grantId (2 bytes) */
Stream_Read_UINT32(s, *controlId); /* controlId (4 bytes) */
return TRUE;
}
static BOOL rdp_write_client_control_pdu(wStream* s, UINT16 action, UINT16 grantId,
UINT32 controlId)
{
WINPR_ASSERT(s);
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
return FALSE;
Stream_Write_UINT16(s, action); /* action (2 bytes) */
Stream_Write_UINT16(s, grantId); /* grantId (2 bytes) */
Stream_Write_UINT32(s, controlId); /* controlId (4 bytes) */
return TRUE;
}
BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, wStream* s)
{
UINT16 action = 0;
UINT16 grantId = 0;
UINT32 controlId = 0;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (!rdp_recv_control_pdu(s, &action, &grantId, &controlId))
return FALSE;
switch (action)
{
case CTRLACTION_COOPERATE:
return rdp_finalize_set_flag(rdp, FINALIZE_SC_CONTROL_COOPERATE_PDU);
case CTRLACTION_GRANTED_CONTROL:
rdp->resendFocus = TRUE;
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)));
return FALSE;
}
}
}
BOOL rdp_send_server_control_cooperate_pdu(rdpRdp* rdp)
{
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
{
Stream_Free(s, TRUE);
return FALSE;
}
Stream_Write_UINT16(s, CTRLACTION_COOPERATE); /* action (2 bytes) */
Stream_Write_UINT16(s, 0); /* grantId (2 bytes) */
Stream_Write_UINT32(s, 0); /* controlId (4 bytes) */
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
}
BOOL rdp_send_server_control_granted_pdu(rdpRdp* rdp)
{
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
{
Stream_Free(s, TRUE);
return FALSE;
}
WINPR_ASSERT(rdp->mcs);
Stream_Write_UINT16(s, CTRLACTION_GRANTED_CONTROL); /* action (2 bytes) */
Stream_Write_UINT16(s, rdp->mcs->userId); /* grantId (2 bytes) */
Stream_Write_UINT32(s, 0x03EA); /* controlId (4 bytes) */
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
}
BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action)
{
wStream* s = rdp_data_pdu_init(rdp);
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;
}
if (!s)
return FALSE;
if (!rdp_write_client_control_pdu(s, action, GrantId, ControlId))
{
Stream_Free(s, TRUE);
return FALSE;
}
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
}
static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s,
const RDP_BITMAP_PERSISTENT_INFO* info)
{
WINPR_ASSERT(s);
WINPR_ASSERT(info);
if (!Stream_EnsureRemainingCapacity(s, 24))
return FALSE;
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) */
Stream_Write_UINT8(s, PERSIST_FIRST_PDU | PERSIST_LAST_PDU); /* bBitMask (1 byte) */
Stream_Write_UINT8(s, 0); /* pad1 (1 byte) */
Stream_Write_UINT16(s, 0); /* pad3 (2 bytes) */
/* entries */
if (!Stream_EnsureRemainingCapacity(s, info->keyCount * 8ull))
return FALSE;
for (UINT32 index = 0; index < info->keyCount; index++)
{
const UINT32 key1 = (UINT32)info->keyList[index];
const UINT32 key2 = (UINT32)(info->keyList[index] >> 32);
Stream_Write_UINT32(s, key1);
Stream_Write_UINT32(s, key2);
}
return TRUE;
}
static UINT32 rdp_load_persistent_key_list(rdpRdp* rdp, UINT64** pKeyList)
{
int count = 0;
int status = 0;
UINT32 keyCount = 0;
UINT64* keyList = NULL;
rdpPersistentCache* persistent = NULL;
rdpSettings* settings = rdp->settings;
*pKeyList = NULL;
if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled))
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;
for (int index = 0; index < count; index++)
{
PERSISTENT_CACHE_ENTRY cacheEntry = { 0 };
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;
}
BOOL rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp)
{
UINT32 keyMaxFrag = 2042;
UINT64* keyList = NULL;
RDP_BITMAP_PERSISTENT_INFO info = { 0 };
rdpSettings* settings = rdp->settings;
UINT32 keyCount = rdp_load_persistent_key_list(rdp, &keyList);
WLog_DBG(TAG, "Persistent Key List: TotalKeyCount: %" PRIu32 " MaxKeyFrag: %" PRIu32, keyCount,
keyMaxFrag);
// 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;
WLog_DBG(TAG, "persistentKeyList count: %" PRIu32, info.keyCount);
WLog_DBG(TAG,
"numEntriesCache: [0]: %" PRIu16 " [1]: %" PRIu16 " [2]: %" PRIu16 " [3]: %" PRIu16
" [4]: %" PRIu16,
info.numEntriesCache0, info.numEntriesCache1, info.numEntriesCache2,
info.numEntriesCache3, info.numEntriesCache4);
WLog_DBG(TAG,
"totalEntriesCache: [0]: %" PRIu16 " [1]: %" PRIu16 " [2]: %" PRIu16 " [3]: %" PRIu16
" [4]: %" PRIu16,
info.totalEntriesCache0, info.totalEntriesCache1, info.totalEntriesCache2,
info.totalEntriesCache3, info.totalEntriesCache4);
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
{
free(keyList);
return FALSE;
}
if (!rdp_write_client_persistent_key_list_pdu(s, &info))
{
Stream_Free(s, TRUE);
free(keyList);
return FALSE;
}
WINPR_ASSERT(rdp->mcs);
free(keyList);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->userId);
}
BOOL rdp_recv_client_font_list_pdu(wStream* s)
{
WINPR_ASSERT(s);
/* 2.2.1.18 Client Font List PDU */
if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
return FALSE;
return Stream_SafeSeek(s, 8);
}
BOOL rdp_recv_client_persistent_key_list_pdu(wStream* s)
{
BYTE flags = 0;
size_t count = 0;
size_t total = 0;
UINT16 cache = 0;
WINPR_ASSERT(s);
/* 2.2.1.17.1 Persistent Key List PDU Data (TS_BITMAPCACHE_PERSISTENT_LIST_PDU) */
if (!Stream_CheckAndLogRequiredLength(TAG, s, 21))
{
WLog_ERR(TAG, "short TS_BITMAPCACHE_PERSISTENT_LIST_PDU, need 21 bytes, got %" PRIuz,
Stream_GetRemainingLength(s));
return FALSE;
}
/* Read numEntriesCacheX for variable length data in PDU */
for (size_t x = 0; x < 5; x++)
{
Stream_Read_UINT16(s, cache);
count += cache;
}
/* Skip totalEntriesCacheX */
for (size_t x = 0; x < 5; x++)
{
UINT16 tmp = 0;
Stream_Read_UINT16(s, tmp);
total += tmp;
}
if (total > 262144)
{
WLog_ERR(TAG,
"TS_BITMAPCACHE_PERSISTENT_LIST_PDU::totalEntriesCacheX exceeds 262144 entries");
return FALSE;
}
Stream_Read_UINT8(s, flags);
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;
}
/* Skip padding */
if (!Stream_SafeSeek(s, 3))
{
WLog_ERR(TAG, "short TS_BITMAPCACHE_PERSISTENT_LIST_PDU, need 3 bytes, got %" PRIuz,
Stream_GetRemainingLength(s));
return FALSE;
}
/* Skip actual entries sent by client */
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;
}
static BOOL rdp_write_client_font_list_pdu(wStream* s, UINT16 flags)
{
WINPR_ASSERT(s);
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
return FALSE;
Stream_Write_UINT16(s, 0); /* numberFonts (2 bytes) */
Stream_Write_UINT16(s, 0); /* totalNumFonts (2 bytes) */
Stream_Write_UINT16(s, flags); /* listFlags (2 bytes) */
Stream_Write_UINT16(s, 50); /* entrySize (2 bytes) */
return TRUE;
}
BOOL rdp_send_client_font_list_pdu(rdpRdp* rdp, UINT16 flags)
{
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
if (!rdp_write_client_font_list_pdu(s, flags))
{
Stream_Free(s, TRUE);
return FALSE;
}
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->userId);
}
BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s)
{
UINT16 numberEntries = 0;
UINT16 totalNumEntries = 0;
UINT16 mapFlags = 0;
UINT16 entrySize = 0;
WINPR_ASSERT(rdp);
WINPR_ASSERT(rdp->settings);
WINPR_ASSERT(s);
WINPR_ASSERT(!freerdp_settings_get_bool(rdp->settings, FreeRDP_ServerMode));
/* 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) */
if (mapFlags != (FONTLIST_FIRST | FONTLIST_LAST))
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
WLog_WARN(TAG,
"[MS-RDPBCGR] 2.2.1.22.1 Font Map PDU Data (TS_FONT_MAP_PDU) paylaod size is "
"0 instead of 8");
return rdp_finalize_set_flag(rdp, FINALIZE_SC_FONT_MAP_PDU);
}
BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp)
{
wStream* s = rdp_data_pdu_init(rdp);
if (!s)
return FALSE;
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 8))
{
Stream_Free(s, TRUE);
return FALSE;
}
Stream_Write_UINT16(s, 0); /* numberEntries (2 bytes) */
Stream_Write_UINT16(s, 0); /* totalNumEntries (2 bytes) */
Stream_Write_UINT16(s, FONTLIST_FIRST | FONTLIST_LAST); /* mapFlags (2 bytes) */
Stream_Write_UINT16(s, 4); /* entrySize (2 bytes) */
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_MAP, rdp->mcs->userId);
}
BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)
{
UINT16 lengthSourceDescriptor = 0;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (rdp_get_state(rdp) == CONNECTION_STATE_ACTIVE)
{
if (!rdp_finalize_set_flag(rdp, FINALIZE_DEACTIVATE_REACTIVATE))
return FALSE;
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);
}
/*
* Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain
* the following fields.
*/
WINPR_ASSERT(rdp->settings);
if (Stream_GetRemainingLength(s) > 0)
{
do
{
UINT32 ShareId = 0;
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
break;
Stream_Read_UINT32(s, ShareId); /* shareId (4 bytes) */
if (!freerdp_settings_set_uint32(rdp->settings, FreeRDP_ShareId, ShareId))
return FALSE;
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
break;
Stream_Read_UINT16(s, lengthSourceDescriptor); /* lengthSourceDescriptor (2 bytes) */
if (!Stream_CheckAndLogRequiredLength(TAG, s, lengthSourceDescriptor))
break;
Stream_Seek(s, lengthSourceDescriptor); /* sourceDescriptor (should be 0x00) */
} while (0);
}
return rdp_client_transition_to_state(rdp,
CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE);
}
BOOL rdp_send_deactivate_all(rdpRdp* rdp)
{
wStream* s = rdp_send_stream_pdu_init(rdp);
BOOL status = FALSE;
if (!s)
return FALSE;
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 7))
goto fail;
WINPR_ASSERT(rdp->settings);
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) */
WINPR_ASSERT(rdp->mcs);
status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId);
fail:
Stream_Release(s);
return status;
}
BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s)
{
UINT16 action = 0;
UINT16 GrantId = 0;
UINT32 ControlId = 0;
const CONNECTION_STATE state = rdp_get_state(rdp);
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (!rdp_recv_control_pdu(s, &action, &GrantId, &ControlId))
return FALSE;
switch (action)
{
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);
return FALSE;
}
}
return TRUE;
}
BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s)
{
rdpSettings* settings = NULL;
freerdp_peer* peer = NULL;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
settings = rdp->settings;
WINPR_ASSERT(settings);
WINPR_ASSERT(rdp->context);
peer = rdp->context->peer;
WINPR_ASSERT(peer);
if (!rdp_recv_client_font_list_pdu(s))
return FALSE;
rdp_finalize_set_flag(rdp, FINALIZE_CS_FONT_LIST_PDU);
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP))
return FALSE;
if (!rdp_send_server_font_map_pdu(rdp))
return FALSE;
if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_ACTIVE))
return FALSE;
return TRUE;
}
BOOL rdp_server_accept_client_persistent_key_list_pdu(rdpRdp* rdp, wStream* s)
{
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (!rdp_recv_client_persistent_key_list_pdu(s))
return FALSE;
rdp_finalize_set_flag(rdp, FINALIZE_CS_PERSISTENT_KEY_LIST_PDU);
// TODO: Actually do something with this
return TRUE;
}
const char* rdp_ctrlaction_string(UINT16 action, char* buffer, size_t size)
{
const char* actstr = NULL;
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;
}
|