Coverage Report

Created: 2026-01-09 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/libfreerdp/core/info.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * RDP Client Info
4
 *
5
 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 * Copyright 2015 Thincast Technologies GmbH
7
 * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *     http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21
22
#include <freerdp/config.h>
23
24
#include "settings.h"
25
26
#include <winpr/crt.h>
27
#include <winpr/assert.h>
28
29
#include <freerdp/crypto/crypto.h>
30
#include <freerdp/log.h>
31
#include <freerdp/session.h>
32
#include <stdio.h>
33
34
#include "timezone.h"
35
36
#include "info.h"
37
38
27
#define TAG FREERDP_TAG("core.info")
39
40
202
#define logonInfoV2Size (2 + 4 + 4 + 4 + 4)
41
148
#define logonInfoV2ReservedSize 558
42
101
#define logonInfoV2TotalSize (logonInfoV2Size + logonInfoV2ReservedSize)
43
44
static const char* INFO_TYPE_LOGON_STRINGS[4] = { "Logon Info V1", "Logon Info V2",
45
                                                "Logon Plain Notify", "Logon Extended Info" };
46
47
/* This define limits the length of the strings in the label field. */
48
0
#define MAX_LABEL_LENGTH 40
49
struct info_flags_t
50
{
51
  UINT32 flag;
52
  const char* label;
53
};
54
55
static const struct info_flags_t info_flags[] = {
56
  { INFO_MOUSE, "INFO_MOUSE" },
57
  { INFO_DISABLECTRLALTDEL, "INFO_DISABLECTRLALTDEL" },
58
  { INFO_AUTOLOGON, "INFO_AUTOLOGON" },
59
  { INFO_UNICODE, "INFO_UNICODE" },
60
  { INFO_MAXIMIZESHELL, "INFO_MAXIMIZESHELL" },
61
  { INFO_LOGONNOTIFY, "INFO_LOGONNOTIFY" },
62
  { INFO_COMPRESSION, "INFO_COMPRESSION" },
63
  { INFO_ENABLEWINDOWSKEY, "INFO_ENABLEWINDOWSKEY" },
64
  { INFO_REMOTECONSOLEAUDIO, "INFO_REMOTECONSOLEAUDIO" },
65
  { INFO_FORCE_ENCRYPTED_CS_PDU, "INFO_FORCE_ENCRYPTED_CS_PDU" },
66
  { INFO_RAIL, "INFO_RAIL" },
67
  { INFO_LOGONERRORS, "INFO_LOGONERRORS" },
68
  { INFO_MOUSE_HAS_WHEEL, "INFO_MOUSE_HAS_WHEEL" },
69
  { INFO_PASSWORD_IS_SC_PIN, "INFO_PASSWORD_IS_SC_PIN" },
70
  { INFO_NOAUDIOPLAYBACK, "INFO_NOAUDIOPLAYBACK" },
71
  { INFO_USING_SAVED_CREDS, "INFO_USING_SAVED_CREDS" },
72
  { INFO_AUDIOCAPTURE, "INFO_AUDIOCAPTURE" },
73
  { INFO_VIDEO_DISABLE, "INFO_VIDEO_DISABLE" },
74
  { INFO_HIDEF_RAIL_SUPPORTED, "INFO_HIDEF_RAIL_SUPPORTED" },
75
};
76
77
static BOOL rdp_read_info_null_string(rdpSettings* settings, FreeRDP_Settings_Keys_String id,
78
                                      const char* what, UINT32 flags, wStream* s, size_t cbLen,
79
                                      size_t max)
80
1.59k
{
81
1.59k
  const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
82
83
1.59k
  if (!freerdp_settings_set_string(settings, id, NULL))
84
0
    return FALSE;
85
86
1.59k
  if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLen)))
87
102
    return FALSE;
88
89
1.49k
  if (cbLen > 0)
90
327
  {
91
327
    if ((cbLen > max) || (unicode && ((cbLen % 2) != 0)))
92
179
    {
93
179
      WLog_ERR(TAG, "protocol error: %s has invalid value: %" PRIuz "", what, cbLen);
94
179
      return FALSE;
95
179
    }
96
97
148
    if (unicode)
98
148
    {
99
148
      const WCHAR* domain = Stream_PointerAs(s, WCHAR);
100
148
      if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
101
148
                                                   cbLen / sizeof(WCHAR)))
102
4
      {
103
4
        WLog_ERR(TAG, "protocol error: no data to read for %s [expected %" PRIuz "]", what,
104
4
                 cbLen);
105
4
        return FALSE;
106
4
      }
107
148
    }
108
0
    else
109
0
    {
110
0
      const char* domain = Stream_ConstPointer(s);
111
0
      if (!freerdp_settings_set_string_len(settings, id, domain, cbLen))
112
0
        return FALSE;
113
0
    }
114
148
  }
115
1.31k
  Stream_Seek(s, cbLen);
116
117
1.31k
  return TRUE;
118
1.49k
}
119
120
static char* rdp_info_package_flags_description(UINT32 flags)
121
0
{
122
0
  char* result = NULL;
123
0
  size_t maximum_size = 1 + MAX_LABEL_LENGTH * ARRAYSIZE(info_flags);
124
125
0
  result = calloc(maximum_size, sizeof(char));
126
127
0
  if (!result)
128
0
    return 0;
129
130
0
  for (size_t i = 0; i < ARRAYSIZE(info_flags); i++)
131
0
  {
132
0
    const struct info_flags_t* cur = &info_flags[i];
133
0
    if (cur->flag & flags)
134
0
    {
135
0
      winpr_str_append(cur->label, result, maximum_size, "|");
136
0
    }
137
0
  }
138
139
0
  return result;
140
0
}
141
142
static BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp)
143
0
{
144
0
  BYTE ClientRandom[CLIENT_RANDOM_LENGTH] = { 0 };
145
0
  BYTE AutoReconnectRandom[32] = { 0 };
146
0
  ARC_SC_PRIVATE_PACKET* serverCookie = NULL;
147
0
  ARC_CS_PRIVATE_PACKET* clientCookie = NULL;
148
149
0
  WINPR_ASSERT(rdp);
150
0
  rdpSettings* settings = rdp->settings;
151
0
  WINPR_ASSERT(settings);
152
153
0
  serverCookie = settings->ServerAutoReconnectCookie;
154
0
  clientCookie = settings->ClientAutoReconnectCookie;
155
0
  clientCookie->cbLen = 28;
156
0
  clientCookie->version = serverCookie->version;
157
0
  clientCookie->logonId = serverCookie->logonId;
158
0
  ZeroMemory(clientCookie->securityVerifier, sizeof(clientCookie->securityVerifier));
159
0
  CopyMemory(AutoReconnectRandom, serverCookie->arcRandomBits,
160
0
             sizeof(serverCookie->arcRandomBits));
161
162
0
  if (settings->SelectedProtocol == PROTOCOL_RDP)
163
0
    CopyMemory(ClientRandom, settings->ClientRandom, settings->ClientRandomLength);
164
165
  /* SecurityVerifier = HMAC_MD5(AutoReconnectRandom, ClientRandom) */
166
167
0
  if (!winpr_HMAC(WINPR_MD_MD5, AutoReconnectRandom, 16, ClientRandom, sizeof(ClientRandom),
168
0
                  clientCookie->securityVerifier, sizeof(clientCookie->securityVerifier)))
169
0
    return FALSE;
170
171
0
  return TRUE;
172
0
}
173
174
/**
175
 * Read Server Auto Reconnect Cookie (ARC_SC_PRIVATE_PACKET).
176
 * msdn{cc240540}
177
 */
178
179
static BOOL rdp_read_server_auto_reconnect_cookie(rdpRdp* rdp, wStream* s, logon_info_ex* info)
180
68
{
181
68
  BYTE* p = NULL;
182
68
  ARC_SC_PRIVATE_PACKET* autoReconnectCookie = NULL;
183
68
  rdpSettings* settings = rdp->settings;
184
68
  autoReconnectCookie = settings->ServerAutoReconnectCookie;
185
186
68
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
187
3
    return FALSE;
188
189
65
  Stream_Read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
190
191
65
  if (autoReconnectCookie->cbLen != 28)
192
42
  {
193
42
    WLog_ERR(TAG, "ServerAutoReconnectCookie.cbLen != 28");
194
42
    return FALSE;
195
42
  }
196
197
23
  Stream_Read_UINT32(s, autoReconnectCookie->version);    /* Version (4 bytes) */
198
23
  Stream_Read_UINT32(s, autoReconnectCookie->logonId);    /* LogonId (4 bytes) */
199
23
  Stream_Read(s, autoReconnectCookie->arcRandomBits, 16); /* ArcRandomBits (16 bytes) */
200
23
  p = autoReconnectCookie->arcRandomBits;
201
23
  WLog_DBG(TAG,
202
23
           "ServerAutoReconnectCookie: Version: %" PRIu32 " LogonId: %" PRIu32
203
23
           " SecurityVerifier: "
204
23
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
205
23
           "%02" PRIX8 ""
206
23
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
207
23
           "%02" PRIX8 "",
208
23
           autoReconnectCookie->version, autoReconnectCookie->logonId, p[0], p[1], p[2], p[3],
209
23
           p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
210
23
  info->LogonId = autoReconnectCookie->logonId;
211
23
  CopyMemory(info->ArcRandomBits, p, 16);
212
213
23
  if ((settings->PrintReconnectCookie))
214
0
  {
215
0
    char* base64 = NULL;
216
0
    base64 = crypto_base64_encode((BYTE*)autoReconnectCookie, sizeof(ARC_SC_PRIVATE_PACKET));
217
0
    WLog_INFO(TAG, "Reconnect-cookie: %s", base64);
218
0
    free(base64);
219
0
  }
220
221
23
  return TRUE;
222
65
}
223
224
/**
225
 * Read Client Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).
226
 * msdn{cc240541}
227
 */
228
229
static BOOL rdp_read_client_auto_reconnect_cookie(rdpRdp* rdp, wStream* s)
230
359
{
231
359
  ARC_CS_PRIVATE_PACKET* autoReconnectCookie = NULL;
232
359
  rdpSettings* settings = rdp->settings;
233
359
  autoReconnectCookie = settings->ClientAutoReconnectCookie;
234
235
359
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
236
14
    return FALSE;
237
238
345
  Stream_Read_UINT32(s, autoReconnectCookie->cbLen);         /* cbLen (4 bytes) */
239
345
  Stream_Read_UINT32(s, autoReconnectCookie->version);       /* version (4 bytes) */
240
345
  Stream_Read_UINT32(s, autoReconnectCookie->logonId);       /* LogonId (4 bytes) */
241
345
  Stream_Read(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
242
345
  return TRUE;
243
359
}
244
245
/**
246
 * Write Client Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).
247
 * msdn{cc240541}
248
 */
249
250
static BOOL rdp_write_client_auto_reconnect_cookie(rdpRdp* rdp, wStream* s)
251
0
{
252
0
  BYTE* p = NULL;
253
0
  ARC_CS_PRIVATE_PACKET* autoReconnectCookie = NULL;
254
0
  rdpSettings* settings = NULL;
255
256
0
  WINPR_ASSERT(rdp);
257
258
0
  settings = rdp->settings;
259
0
  WINPR_ASSERT(settings);
260
261
0
  autoReconnectCookie = settings->ClientAutoReconnectCookie;
262
0
  WINPR_ASSERT(autoReconnectCookie);
263
264
0
  p = autoReconnectCookie->securityVerifier;
265
0
  WINPR_ASSERT(p);
266
267
0
  WLog_DBG(TAG,
268
0
           "ClientAutoReconnectCookie: Version: %" PRIu32 " LogonId: %" PRIu32 " ArcRandomBits: "
269
0
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
270
0
           "%02" PRIX8 ""
271
0
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
272
0
           "%02" PRIX8 "",
273
0
           autoReconnectCookie->version, autoReconnectCookie->logonId, p[0], p[1], p[2], p[3],
274
0
           p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
275
0
  if (!Stream_EnsureRemainingCapacity(s, 12ull + 16ull))
276
0
    return FALSE;
277
0
  Stream_Write_UINT32(s, autoReconnectCookie->cbLen);         /* cbLen (4 bytes) */
278
0
  Stream_Write_UINT32(s, autoReconnectCookie->version);       /* version (4 bytes) */
279
0
  Stream_Write_UINT32(s, autoReconnectCookie->logonId);       /* LogonId (4 bytes) */
280
0
  Stream_Write(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier (16 bytes) */
281
0
  return TRUE;
282
0
}
283
284
/*
285
 * Get the cbClientAddress size limit
286
 * see [MS-RDPBCGR] 2.2.1.11.1.1.1 Extended Info Packet (TS_EXTENDED_INFO_PACKET)
287
 */
288
289
static size_t rdp_get_client_address_max_size(const rdpRdp* rdp)
290
586
{
291
586
  UINT32 version = 0;
292
586
  rdpSettings* settings = NULL;
293
294
586
  WINPR_ASSERT(rdp);
295
296
586
  settings = rdp->settings;
297
586
  WINPR_ASSERT(settings);
298
299
586
  version = freerdp_settings_get_uint32(settings, FreeRDP_RdpVersion);
300
586
  if (version < RDP_VERSION_10_0)
301
0
    return 64;
302
586
  return 80;
303
586
}
304
305
/**
306
 * Read Extended Info Packet (TS_EXTENDED_INFO_PACKET).
307
 * msdn{cc240476}
308
 */
309
310
static BOOL rdp_read_extended_info_packet(rdpRdp* rdp, wStream* s)
311
590
{
312
590
  UINT16 clientAddressFamily = 0;
313
590
  UINT16 cbClientAddress = 0;
314
590
  UINT16 cbClientDir = 0;
315
590
  UINT16 cbAutoReconnectLen = 0;
316
317
590
  WINPR_ASSERT(rdp);
318
319
590
  rdpSettings* settings = rdp->settings;
320
590
  WINPR_ASSERT(settings);
321
322
590
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
323
4
    return FALSE;
324
325
586
  Stream_Read_UINT16(s, clientAddressFamily); /* clientAddressFamily (2 bytes) */
326
586
  Stream_Read_UINT16(s, cbClientAddress);     /* cbClientAddress (2 bytes) */
327
328
586
  settings->IPv6Enabled = (clientAddressFamily == ADDRESS_FAMILY_INET6 ? TRUE : FALSE);
329
330
586
  if (!rdp_read_info_null_string(settings, FreeRDP_ClientAddress, "cbClientAddress", INFO_UNICODE,
331
586
                                 s, cbClientAddress, rdp_get_client_address_max_size(rdp)))
332
24
    return FALSE;
333
334
562
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
335
9
    return FALSE;
336
337
553
  Stream_Read_UINT16(s, cbClientDir); /* cbClientDir (2 bytes) */
338
339
  /* cbClientDir is the size in bytes of the character data in the clientDir field.
340
   * This size includes the length of the mandatory null terminator.
341
   * The maximum allowed value is 512 bytes.
342
   * Note: Although according to [MS-RDPBCGR 2.2.1.11.1.1.1] the null terminator
343
   * is mandatory the Microsoft Android client (starting with version 8.1.31.44)
344
   * sets cbClientDir to 0.
345
   */
346
347
553
  if (!rdp_read_info_null_string(settings, FreeRDP_ClientDir, "cbClientDir", INFO_UNICODE, s,
348
553
                                 cbClientDir, 512))
349
18
    return FALSE;
350
351
  /**
352
   * down below all fields are optional but if one field is not present,
353
   * then all of the subsequent fields also MUST NOT be present.
354
   */
355
356
  /* optional: clientTimeZone (172 bytes) */
357
535
  if (Stream_GetRemainingLength(s) == 0)
358
5
    goto end;
359
360
530
  if (!rdp_read_client_time_zone(s, settings))
361
20
    return FALSE;
362
363
  /* optional: clientSessionId (4 bytes), should be set to 0 */
364
510
  if (Stream_GetRemainingLength(s) == 0)
365
3
    goto end;
366
507
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
367
4
    return FALSE;
368
369
503
  Stream_Read_UINT32(s, settings->ClientSessionId);
370
371
  /* optional: performanceFlags (4 bytes) */
372
503
  if (Stream_GetRemainingLength(s) == 0)
373
2
    goto end;
374
375
501
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
376
2
    return FALSE;
377
378
499
  Stream_Read_UINT32(s, settings->PerformanceFlags);
379
499
  freerdp_performance_flags_split(settings);
380
381
  /* optional: cbAutoReconnectLen (2 bytes) */
382
499
  if (Stream_GetRemainingLength(s) == 0)
383
2
    goto end;
384
385
497
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
386
2
    return FALSE;
387
388
495
  Stream_Read_UINT16(s, cbAutoReconnectLen);
389
390
  /* optional: autoReconnectCookie (28 bytes) */
391
  /* must be present if cbAutoReconnectLen is > 0 */
392
495
  if (cbAutoReconnectLen > 0)
393
359
  {
394
359
    if (!rdp_read_client_auto_reconnect_cookie(rdp, s))
395
14
      return FALSE;
396
359
  }
397
398
  /* skip reserved1 and reserved2 fields */
399
481
  if (Stream_GetRemainingLength(s) == 0)
400
6
    goto end;
401
402
475
  if (!Stream_SafeSeek(s, 2))
403
5
    return FALSE;
404
405
470
  if (Stream_GetRemainingLength(s) == 0)
406
3
    goto end;
407
408
467
  if (!Stream_SafeSeek(s, 2))
409
3
    return FALSE;
410
411
464
  if (Stream_GetRemainingLength(s) == 0)
412
2
    goto end;
413
414
462
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
415
2
    return FALSE;
416
417
460
  if (freerdp_settings_get_bool(settings, FreeRDP_SupportDynamicTimeZone))
418
460
  {
419
460
    UINT16 cbDynamicDSTTimeZoneKeyName = 0;
420
421
460
    Stream_Read_UINT16(s, cbDynamicDSTTimeZoneKeyName);
422
423
460
    if (!rdp_read_info_null_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName,
424
460
                                   "cbDynamicDSTTimeZoneKeyName", INFO_UNICODE, s,
425
460
                                   cbDynamicDSTTimeZoneKeyName, 254))
426
243
      return FALSE;
427
428
217
    if (Stream_GetRemainingLength(s) == 0)
429
4
      goto end;
430
431
213
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
432
4
      return FALSE;
433
209
    UINT16 DynamicDaylightTimeDisabled = 0;
434
209
    Stream_Read_UINT16(s, DynamicDaylightTimeDisabled);
435
209
    if (DynamicDaylightTimeDisabled > 1)
436
99
    {
437
99
      WLog_WARN(TAG,
438
99
                "[MS-RDPBCGR] 2.2.1.11.1.1.1 Extended Info Packet "
439
99
                "(TS_EXTENDED_INFO_PACKET)::dynamicDaylightTimeDisabled value %" PRIu16
440
99
                " not allowed in [0,1]",
441
99
                settings->DynamicDaylightTimeDisabled);
442
99
      return FALSE;
443
99
    }
444
110
    if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicDaylightTimeDisabled,
445
110
                                   DynamicDaylightTimeDisabled != 0))
446
0
      return FALSE;
447
110
    DEBUG_TIMEZONE("DynamicTimeZone=%s [%s]",
448
110
                   freerdp_settings_get_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName),
449
110
                   freerdp_settings_get_bool(settings, FreeRDP_DynamicDaylightTimeDisabled)
450
110
                       ? "no-DST"
451
110
                       : "DST");
452
110
  }
453
454
137
end:
455
137
  return TRUE;
456
460
}
457
458
/**
459
 * Write Extended Info Packet (TS_EXTENDED_INFO_PACKET).
460
 * msdn{cc240476}
461
 */
462
463
static BOOL rdp_write_extended_info_packet(rdpRdp* rdp, wStream* s)
464
0
{
465
0
  BOOL ret = FALSE;
466
0
  size_t cbClientAddress = 0;
467
0
  const size_t cbClientAddressMax = rdp_get_client_address_max_size(rdp);
468
0
  WCHAR* clientDir = NULL;
469
0
  size_t cbClientDir = 0;
470
0
  const size_t cbClientDirMax = 512;
471
0
  UINT16 cbAutoReconnectCookie = 0;
472
473
0
  WINPR_ASSERT(rdp);
474
475
0
  rdpSettings* settings = rdp->settings;
476
0
  WINPR_ASSERT(settings);
477
478
0
  UINT16 clientAddressFamily = ADDRESS_FAMILY_INET;
479
0
  if (settings->ConnectChildSession)
480
0
    clientAddressFamily = 0x0000;
481
0
  else if (settings->IPv6Enabled)
482
0
    clientAddressFamily = ADDRESS_FAMILY_INET6;
483
484
0
  WCHAR* clientAddress = ConvertUtf8ToWCharAlloc(settings->ClientAddress, &cbClientAddress);
485
486
0
  if (cbClientAddress > (UINT16_MAX / sizeof(WCHAR)))
487
0
  {
488
0
    WLog_ERR(TAG, "cbClientAddress > UINT16_MAX");
489
0
    goto fail;
490
0
  }
491
492
0
  if (cbClientAddress > 0)
493
0
  {
494
0
    cbClientAddress = (UINT16)(cbClientAddress + 1) * sizeof(WCHAR);
495
0
    if (cbClientAddress > cbClientAddressMax)
496
0
    {
497
0
      WLog_WARN(TAG,
498
0
                "the client address %s [%" PRIuz "] exceeds the limit of %" PRIuz
499
0
                ", truncating.",
500
0
                settings->ClientAddress, cbClientAddress, cbClientAddressMax);
501
502
0
      clientAddress[(cbClientAddressMax / sizeof(WCHAR)) - 1] = '\0';
503
0
      cbClientAddress = cbClientAddressMax;
504
0
    }
505
0
  }
506
507
0
  clientDir = ConvertUtf8ToWCharAlloc(settings->ClientDir, &cbClientDir);
508
0
  if (cbClientDir > (UINT16_MAX / sizeof(WCHAR)))
509
0
  {
510
0
    WLog_ERR(TAG, "cbClientDir > UINT16_MAX");
511
0
    goto fail;
512
0
  }
513
514
0
  if (cbClientDir > 0)
515
0
  {
516
0
    cbClientDir = (UINT16)(cbClientDir + 1) * sizeof(WCHAR);
517
0
    if (cbClientDir > cbClientDirMax)
518
0
    {
519
0
      WLog_WARN(TAG,
520
0
                "the client dir %s [%" PRIuz "] exceeds the limit of %" PRIuz ", truncating.",
521
0
                settings->ClientDir, cbClientDir, cbClientDirMax);
522
523
0
      clientDir[(cbClientDirMax / sizeof(WCHAR)) - 1] = '\0';
524
0
      cbClientDir = cbClientDirMax;
525
0
    }
526
0
  }
527
528
0
  if (settings->ServerAutoReconnectCookie->cbLen > UINT16_MAX)
529
0
  {
530
0
    WLog_ERR(TAG, "ServerAutoreconnectCookie::cbLen > UINT16_MAX");
531
0
    goto fail;
532
0
  }
533
534
0
  cbAutoReconnectCookie = (UINT16)settings->ServerAutoReconnectCookie->cbLen;
535
536
0
  if (!Stream_EnsureRemainingCapacity(s, 4ull + cbClientAddress + 2ull + cbClientDir))
537
0
    goto fail;
538
539
0
  Stream_Write_UINT16(s, clientAddressFamily);     /* clientAddressFamily (2 bytes) */
540
0
  Stream_Write_UINT16(s, (UINT16)cbClientAddress); /* cbClientAddress (2 bytes) */
541
542
0
  Stream_Write(s, clientAddress, cbClientAddress); /* clientAddress */
543
544
0
  Stream_Write_UINT16(s, (UINT16)cbClientDir); /* cbClientDir (2 bytes) */
545
546
0
  Stream_Write(s, clientDir, cbClientDir); /* clientDir */
547
548
0
  if (!rdp_write_client_time_zone(s, settings)) /* clientTimeZone (172 bytes) */
549
0
    goto fail;
550
551
0
  if (!Stream_EnsureRemainingCapacity(s, 10ull))
552
0
    goto fail;
553
554
  /* clientSessionId (4 bytes), should be set to 0 */
555
0
  Stream_Write_UINT32(s, settings->ClientSessionId);
556
0
  freerdp_performance_flags_make(settings);
557
0
  Stream_Write_UINT32(s, settings->PerformanceFlags); /* performanceFlags (4 bytes) */
558
0
  Stream_Write_UINT16(s, cbAutoReconnectCookie);      /* cbAutoReconnectCookie (2 bytes) */
559
560
0
  if (cbAutoReconnectCookie > 0)
561
0
  {
562
0
    if (!rdp_compute_client_auto_reconnect_cookie(rdp))
563
0
      goto fail;
564
0
    if (!rdp_write_client_auto_reconnect_cookie(rdp, s)) /* autoReconnectCookie */
565
0
      goto fail;
566
0
  }
567
568
0
  if (freerdp_settings_get_bool(settings, FreeRDP_SupportDynamicTimeZone))
569
0
  {
570
0
    if (!Stream_EnsureRemainingCapacity(s, 8 + 254 * sizeof(WCHAR)))
571
0
      goto fail;
572
573
0
    Stream_Write_UINT16(s, 0); /* reserved1 (2 bytes) */
574
0
    Stream_Write_UINT16(s, 0); /* reserved2 (2 bytes) */
575
576
0
    size_t rlen = 0;
577
0
    const char* tz = freerdp_settings_get_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName);
578
0
    if (tz)
579
0
      rlen = strnlen(tz, 254);
580
0
    Stream_Write_UINT16(s, (UINT16)rlen * sizeof(WCHAR));
581
0
    if (Stream_Write_UTF16_String_From_UTF8(s, rlen, tz, rlen, FALSE) < 0)
582
0
      goto fail;
583
0
    Stream_Write_UINT16(s, settings->DynamicDaylightTimeDisabled ? 0x01 : 0x00);
584
0
  }
585
586
0
  ret = TRUE;
587
0
fail:
588
0
  free(clientAddress);
589
0
  free(clientDir);
590
0
  return ret;
591
0
}
592
593
static BOOL rdp_read_info_string(rdpSettings* settings, FreeRDP_Settings_Keys_String id,
594
                                 UINT32 flags, wStream* s, size_t cbLenNonNull, size_t max)
595
3.32k
{
596
3.32k
  union
597
3.32k
  {
598
3.32k
    char c;
599
3.32k
    WCHAR w;
600
3.32k
    BYTE b[2];
601
3.32k
  } terminator;
602
603
3.32k
  const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
604
3.32k
  const size_t nullSize = unicode ? sizeof(WCHAR) : sizeof(CHAR);
605
606
3.32k
  if (!freerdp_settings_set_string(settings, id, NULL))
607
0
    return FALSE;
608
609
3.32k
  if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLenNonNull + nullSize)))
610
31
    return FALSE;
611
612
3.29k
  if (cbLenNonNull > 0)
613
240
  {
614
    /* cbDomain is the size in bytes of the character data in the Domain field.
615
     * This size excludes (!) the length of the mandatory null terminator.
616
     * Maximum value including the mandatory null terminator: 512
617
     */
618
240
    if ((cbLenNonNull % 2) || (cbLenNonNull > (max - nullSize)))
619
41
    {
620
41
      WLog_ERR(TAG, "protocol error: invalid value: %" PRIuz "", cbLenNonNull);
621
41
      return FALSE;
622
41
    }
623
624
199
    if (unicode)
625
165
    {
626
165
      const WCHAR* domain = Stream_PointerAs(s, WCHAR);
627
165
      if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
628
165
                                                   cbLenNonNull / sizeof(WCHAR)))
629
17
        return FALSE;
630
165
    }
631
34
    else
632
34
    {
633
34
      const char* domain = Stream_PointerAs(s, char);
634
34
      if (!freerdp_settings_set_string_len(settings, id, domain, cbLenNonNull))
635
0
        return FALSE;
636
34
    }
637
199
  }
638
639
3.23k
  Stream_Seek(s, cbLenNonNull);
640
641
3.23k
  terminator.w = L'\0';
642
3.23k
  Stream_Read(s, terminator.b, nullSize);
643
644
3.23k
  if (terminator.w != L'\0')
645
129
  {
646
129
    WLog_ERR(TAG, "protocol error: Domain must be null terminated");
647
129
    (void)freerdp_settings_set_string(settings, id, NULL);
648
129
    return FALSE;
649
129
  }
650
651
3.10k
  return TRUE;
652
3.23k
}
653
654
/**
655
 * Read Info Packet (TS_INFO_PACKET).
656
 * msdn{cc240475}
657
 */
658
659
static BOOL rdp_read_info_packet(rdpRdp* rdp, wStream* s, UINT16 tpktlength)
660
823
{
661
823
  BOOL smallsize = FALSE;
662
823
  UINT32 flags = 0;
663
823
  UINT16 cbDomain = 0;
664
823
  UINT16 cbUserName = 0;
665
823
  UINT16 cbPassword = 0;
666
823
  UINT16 cbAlternateShell = 0;
667
823
  UINT16 cbWorkingDir = 0;
668
823
  UINT32 CompressionLevel = 0;
669
823
  rdpSettings* settings = rdp->settings;
670
671
823
  if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 18))
672
15
    return FALSE;
673
674
808
  Stream_Read_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes ) */
675
808
  Stream_Read_UINT32(s, flags);                      /* flags (4 bytes) */
676
808
  settings->AudioCapture = ((flags & INFO_AUDIOCAPTURE) ? TRUE : FALSE);
677
808
  settings->AudioPlayback = ((flags & INFO_NOAUDIOPLAYBACK) ? FALSE : TRUE);
678
808
  settings->AutoLogonEnabled = ((flags & INFO_AUTOLOGON) ? TRUE : FALSE);
679
808
  settings->RemoteApplicationMode = ((flags & INFO_RAIL) ? TRUE : FALSE);
680
808
  settings->HiDefRemoteApp = ((flags & INFO_HIDEF_RAIL_SUPPORTED) ? TRUE : FALSE);
681
808
  settings->RemoteConsoleAudio = ((flags & INFO_REMOTECONSOLEAUDIO) ? TRUE : FALSE);
682
808
  settings->CompressionEnabled = ((flags & INFO_COMPRESSION) ? TRUE : FALSE);
683
808
  settings->LogonNotify = ((flags & INFO_LOGONNOTIFY) ? TRUE : FALSE);
684
808
  settings->MouseHasWheel = ((flags & INFO_MOUSE_HAS_WHEEL) ? TRUE : FALSE);
685
808
  settings->DisableCtrlAltDel = ((flags & INFO_DISABLECTRLALTDEL) ? TRUE : FALSE);
686
808
  settings->ForceEncryptedCsPdu = ((flags & INFO_FORCE_ENCRYPTED_CS_PDU) ? TRUE : FALSE);
687
808
  settings->PasswordIsSmartcardPin = ((flags & INFO_PASSWORD_IS_SC_PIN) ? TRUE : FALSE);
688
689
808
  if (flags & INFO_COMPRESSION)
690
134
  {
691
134
    CompressionLevel = ((flags & 0x00001E00) >> 9);
692
134
    settings->CompressionLevel = CompressionLevel;
693
134
  }
694
674
  else
695
674
  {
696
674
    settings->CompressionLevel = 0;
697
674
  }
698
699
  /* RDP 4 and 5 have smaller credential limits */
700
808
  if (settings->RdpVersion < RDP_VERSION_5_PLUS)
701
0
    smallsize = TRUE;
702
703
808
  Stream_Read_UINT16(s, cbDomain);         /* cbDomain (2 bytes) */
704
808
  Stream_Read_UINT16(s, cbUserName);       /* cbUserName (2 bytes) */
705
808
  Stream_Read_UINT16(s, cbPassword);       /* cbPassword (2 bytes) */
706
808
  Stream_Read_UINT16(s, cbAlternateShell); /* cbAlternateShell (2 bytes) */
707
808
  Stream_Read_UINT16(s, cbWorkingDir);     /* cbWorkingDir (2 bytes) */
708
709
808
  if (!rdp_read_info_string(settings, FreeRDP_Domain, flags, s, cbDomain, smallsize ? 52 : 512))
710
146
    return FALSE;
711
712
662
  if (!rdp_read_info_string(settings, FreeRDP_Username, flags, s, cbUserName,
713
662
                            smallsize ? 44 : 512))
714
26
    return FALSE;
715
716
636
  if (!rdp_read_info_string(settings, FreeRDP_Password, flags, s, cbPassword,
717
636
                            smallsize ? 32 : 512))
718
19
    return FALSE;
719
720
617
  if (!rdp_read_info_string(settings, FreeRDP_AlternateShell, flags, s, cbAlternateShell, 512))
721
17
    return FALSE;
722
723
600
  if (!rdp_read_info_string(settings, FreeRDP_ShellWorkingDirectory, flags, s, cbWorkingDir, 512))
724
10
    return FALSE;
725
726
590
  if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
727
590
  {
728
590
    if (!rdp_read_extended_info_packet(rdp, s)) /* extraInfo */
729
453
      return FALSE;
730
590
  }
731
732
137
  const size_t xrem = Stream_GetRemainingLength(s);
733
137
  if (!tpkt_ensure_stream_consumed(rdp->log, s, tpktlength))
734
108
    Stream_Seek(s, xrem);
735
137
  return TRUE;
736
590
}
737
738
/**
739
 * Write Info Packet (TS_INFO_PACKET).
740
 * msdn{cc240475}
741
 */
742
743
static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
744
0
{
745
0
  BOOL ret = FALSE;
746
0
  UINT32 flags = 0;
747
0
  WCHAR* domainW = NULL;
748
0
  size_t cbDomain = 0;
749
0
  WCHAR* userNameW = NULL;
750
0
  size_t cbUserName = 0;
751
0
  WCHAR* passwordW = NULL;
752
0
  size_t cbPassword = 0;
753
0
  WCHAR* alternateShellW = NULL;
754
0
  size_t cbAlternateShell = 0;
755
0
  WCHAR* workingDirW = NULL;
756
0
  size_t cbWorkingDir = 0;
757
0
  BOOL usedPasswordCookie = FALSE;
758
0
  rdpSettings* settings = NULL;
759
760
0
  WINPR_ASSERT(rdp);
761
0
  settings = rdp->settings;
762
0
  WINPR_ASSERT(settings);
763
764
0
  flags = INFO_MOUSE | INFO_UNICODE | INFO_LOGONERRORS | INFO_MAXIMIZESHELL |
765
0
          INFO_ENABLEWINDOWSKEY | INFO_DISABLECTRLALTDEL | INFO_MOUSE_HAS_WHEEL |
766
0
          INFO_FORCE_ENCRYPTED_CS_PDU;
767
768
0
  if (settings->SmartcardLogon)
769
0
  {
770
0
    flags |= INFO_AUTOLOGON;
771
0
    flags |= INFO_PASSWORD_IS_SC_PIN;
772
0
  }
773
774
0
  if (settings->AudioCapture)
775
0
    flags |= INFO_AUDIOCAPTURE;
776
777
0
  if (!settings->AudioPlayback)
778
0
    flags |= INFO_NOAUDIOPLAYBACK;
779
780
0
  if (settings->VideoDisable)
781
0
    flags |= INFO_VIDEO_DISABLE;
782
783
0
  if (settings->AutoLogonEnabled)
784
0
    flags |= INFO_AUTOLOGON;
785
786
0
  if (settings->RemoteApplicationMode)
787
0
  {
788
0
    if (settings->HiDefRemoteApp)
789
0
    {
790
0
      if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
791
0
        flags |= INFO_HIDEF_RAIL_SUPPORTED;
792
0
    }
793
794
0
    flags |= INFO_RAIL;
795
0
  }
796
797
0
  if (settings->RemoteConsoleAudio)
798
0
    flags |= INFO_REMOTECONSOLEAUDIO;
799
800
0
  if (settings->CompressionEnabled)
801
0
  {
802
0
    flags |= INFO_COMPRESSION;
803
0
    flags |= ((settings->CompressionLevel << 9) & 0x00001E00);
804
0
  }
805
806
0
  if (settings->LogonNotify)
807
0
    flags |= INFO_LOGONNOTIFY;
808
809
0
  if (settings->PasswordIsSmartcardPin)
810
0
    flags |= INFO_PASSWORD_IS_SC_PIN;
811
812
0
  {
813
0
    char* flags_description = rdp_info_package_flags_description(flags);
814
815
0
    if (flags_description)
816
0
    {
817
0
      WLog_DBG(TAG, "Client Info Packet Flags = %s", flags_description);
818
0
      free(flags_description);
819
0
    }
820
0
  }
821
822
0
  domainW = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Domain, &cbDomain);
823
0
  if (cbDomain > UINT16_MAX / sizeof(WCHAR))
824
0
  {
825
0
    WLog_ERR(TAG, "cbDomain > UINT16_MAX");
826
0
    goto fail;
827
0
  }
828
0
  cbDomain *= sizeof(WCHAR);
829
830
  /* user name provided by the expert for connecting to the novice computer */
831
0
  userNameW = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Username, &cbUserName);
832
0
  if (cbUserName > UINT16_MAX / sizeof(WCHAR))
833
0
  {
834
0
    WLog_ERR(TAG, "cbUserName > UINT16_MAX");
835
0
    goto fail;
836
0
  }
837
0
  cbUserName *= sizeof(WCHAR);
838
839
0
  {
840
0
    const char* pin = "*";
841
0
    if (!settings->RemoteAssistanceMode)
842
0
    {
843
      /* Ignore redirection password if we´re using smartcard and have the pin as password */
844
0
      if (((flags & INFO_PASSWORD_IS_SC_PIN) == 0) && settings->RedirectionPassword &&
845
0
          (settings->RedirectionPasswordLength > 0))
846
0
      {
847
0
        union
848
0
        {
849
0
          BYTE* bp;
850
0
          WCHAR* wp;
851
0
        } ptrconv;
852
853
0
        if (settings->RedirectionPasswordLength > UINT16_MAX)
854
0
        {
855
0
          WLog_ERR(TAG, "RedirectionPasswordLength > UINT16_MAX");
856
0
          goto fail;
857
0
        }
858
0
        usedPasswordCookie = TRUE;
859
860
0
        ptrconv.bp = settings->RedirectionPassword;
861
0
        passwordW = ptrconv.wp;
862
0
        cbPassword = (UINT16)settings->RedirectionPasswordLength;
863
0
      }
864
0
      else
865
0
        pin = freerdp_settings_get_string(settings, FreeRDP_Password);
866
0
    }
867
868
0
    if (!usedPasswordCookie && pin)
869
0
    {
870
0
      passwordW = ConvertUtf8ToWCharAlloc(pin, &cbPassword);
871
0
      if (cbPassword > UINT16_MAX / sizeof(WCHAR))
872
0
      {
873
0
        WLog_ERR(TAG, "cbPassword > UINT16_MAX");
874
0
        goto fail;
875
0
      }
876
0
      cbPassword = (UINT16)cbPassword * sizeof(WCHAR);
877
0
    }
878
0
  }
879
880
0
  {
881
0
    const char* altShell = NULL;
882
0
    if (!settings->RemoteAssistanceMode)
883
0
      altShell = freerdp_settings_get_string(settings, FreeRDP_AlternateShell);
884
0
    else if (settings->RemoteAssistancePassStub)
885
0
      altShell = "*"; /* This field MUST be filled with "*" */
886
0
    else
887
0
      altShell = freerdp_settings_get_string(settings, FreeRDP_RemoteAssistancePassword);
888
889
0
    if (altShell && strlen(altShell) > 0)
890
0
    {
891
0
      alternateShellW = ConvertUtf8ToWCharAlloc(altShell, &cbAlternateShell);
892
0
      if (!alternateShellW)
893
0
      {
894
0
        WLog_ERR(TAG, "alternateShellW == NULL");
895
0
        goto fail;
896
0
      }
897
0
      if (cbAlternateShell > (UINT16_MAX / sizeof(WCHAR)))
898
0
      {
899
0
        WLog_ERR(TAG, "cbAlternateShell > UINT16_MAX");
900
0
        goto fail;
901
0
      }
902
0
      cbAlternateShell = (UINT16)cbAlternateShell * sizeof(WCHAR);
903
0
    }
904
0
  }
905
906
0
  {
907
0
    FreeRDP_Settings_Keys_String inputId = FreeRDP_RemoteAssistanceSessionId;
908
0
    if (!freerdp_settings_get_bool(settings, FreeRDP_RemoteAssistanceMode))
909
0
      inputId = FreeRDP_ShellWorkingDirectory;
910
911
0
    workingDirW = freerdp_settings_get_string_as_utf16(settings, inputId, &cbWorkingDir);
912
0
  }
913
0
  if (cbWorkingDir > (UINT16_MAX / sizeof(WCHAR)))
914
0
  {
915
0
    WLog_ERR(TAG, "cbWorkingDir > UINT16_MAX");
916
0
    goto fail;
917
0
  }
918
0
  cbWorkingDir = (UINT16)cbWorkingDir * sizeof(WCHAR);
919
920
0
  if (!Stream_EnsureRemainingCapacity(s, 18ull + cbDomain + cbUserName + cbPassword +
921
0
                                             cbAlternateShell + cbWorkingDir + 5 * sizeof(WCHAR)))
922
0
    goto fail;
923
924
0
  Stream_Write_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes) */
925
0
  Stream_Write_UINT32(s, flags);                      /* flags (4 bytes) */
926
0
  Stream_Write_UINT16(s, (UINT16)cbDomain);           /* cbDomain (2 bytes) */
927
0
  Stream_Write_UINT16(s, (UINT16)cbUserName);         /* cbUserName (2 bytes) */
928
0
  Stream_Write_UINT16(s, (UINT16)cbPassword);         /* cbPassword (2 bytes) */
929
0
  Stream_Write_UINT16(s, (UINT16)cbAlternateShell);   /* cbAlternateShell (2 bytes) */
930
0
  Stream_Write_UINT16(s, (UINT16)cbWorkingDir);       /* cbWorkingDir (2 bytes) */
931
932
0
  Stream_Write(s, domainW, cbDomain);
933
934
  /* the mandatory null terminator */
935
0
  Stream_Write_UINT16(s, 0);
936
937
0
  Stream_Write(s, userNameW, cbUserName);
938
939
  /* the mandatory null terminator */
940
0
  Stream_Write_UINT16(s, 0);
941
942
0
  Stream_Write(s, passwordW, cbPassword);
943
944
  /* the mandatory null terminator */
945
0
  Stream_Write_UINT16(s, 0);
946
947
0
  Stream_Write(s, alternateShellW, cbAlternateShell);
948
949
  /* the mandatory null terminator */
950
0
  Stream_Write_UINT16(s, 0);
951
952
0
  Stream_Write(s, workingDirW, cbWorkingDir);
953
954
  /* the mandatory null terminator */
955
0
  Stream_Write_UINT16(s, 0);
956
0
  ret = TRUE;
957
0
fail:
958
0
  free(domainW);
959
0
  free(userNameW);
960
0
  free(alternateShellW);
961
0
  free(workingDirW);
962
963
0
  if (!usedPasswordCookie)
964
0
    free(passwordW);
965
966
0
  if (!ret)
967
0
    return FALSE;
968
969
0
  if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
970
0
    ret = rdp_write_extended_info_packet(rdp, s); /* extraInfo */
971
972
0
  return ret;
973
0
}
974
975
/**
976
 * Read Client Info PDU (CLIENT_INFO_PDU).
977
 * msdn{cc240474}
978
 * @param rdp RDP module
979
 * @param s stream
980
 */
981
982
BOOL rdp_recv_client_info(rdpRdp* rdp, wStream* s)
983
17.2k
{
984
17.2k
  UINT16 length = 0;
985
17.2k
  UINT16 channelId = 0;
986
17.2k
  UINT16 securityFlags = 0;
987
988
17.2k
  WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE);
989
990
17.2k
  if (!rdp_read_header(rdp, s, &length, &channelId))
991
16.4k
    return FALSE;
992
993
843
  if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
994
8
    return FALSE;
995
996
835
  if ((securityFlags & SEC_INFO_PKT) == 0)
997
12
    return FALSE;
998
999
823
  if (rdp->settings->UseRdpSecurityLayer)
1000
0
  {
1001
0
    if (securityFlags & SEC_REDIRECTION_PKT)
1002
0
    {
1003
0
      WLog_ERR(TAG, "Error: SEC_REDIRECTION_PKT unsupported");
1004
0
      return FALSE;
1005
0
    }
1006
1007
0
    if (securityFlags & SEC_ENCRYPT)
1008
0
    {
1009
0
      if (!rdp_decrypt(rdp, s, &length, securityFlags))
1010
0
        return FALSE;
1011
0
    }
1012
0
  }
1013
1014
823
  return rdp_read_info_packet(rdp, s, length);
1015
823
}
1016
1017
/**
1018
 * Send Client Info PDU (CLIENT_INFO_PDU).
1019
 * msdn{cc240474}
1020
 * @param rdp RDP module
1021
 */
1022
1023
BOOL rdp_send_client_info(rdpRdp* rdp)
1024
0
{
1025
0
  UINT16 sec_flags = SEC_INFO_PKT;
1026
0
  wStream* s = NULL;
1027
0
  WINPR_ASSERT(rdp);
1028
0
  s = rdp_send_stream_init(rdp, &sec_flags);
1029
1030
0
  if (!s)
1031
0
  {
1032
0
    WLog_ERR(TAG, "Stream_New failed!");
1033
0
    return FALSE;
1034
0
  }
1035
1036
0
  if (!rdp_write_info_packet(rdp, s))
1037
0
  {
1038
0
    Stream_Release(s);
1039
0
    return FALSE;
1040
0
  }
1041
0
  return rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID, sec_flags);
1042
0
}
1043
1044
static void rdp_free_logon_info(logon_info* info)
1045
728
{
1046
728
  if (!info)
1047
0
    return;
1048
728
  free(info->domain);
1049
728
  free(info->username);
1050
1051
728
  const logon_info empty = { 0 };
1052
728
  *info = empty;
1053
728
}
1054
1055
static BOOL rdp_info_read_string(const char* what, wStream* s, size_t size, size_t max,
1056
                                 BOOL skipMax, char** dst)
1057
938
{
1058
938
  WINPR_ASSERT(dst);
1059
938
  *dst = NULL;
1060
1061
938
  if (size == 0)
1062
601
  {
1063
601
    if (skipMax)
1064
522
      return Stream_SafeSeek(s, max);
1065
79
    return TRUE;
1066
601
  }
1067
1068
337
  if (((size % sizeof(WCHAR)) != 0) || (size > max))
1069
269
  {
1070
269
    WLog_ERR(TAG, "protocol error: invalid %s value: %" PRIu32 "", what, size);
1071
269
    return FALSE;
1072
269
  }
1073
1074
68
  const WCHAR* str = Stream_ConstPointer(s);
1075
68
  if (!Stream_SafeSeek(s, skipMax ? max : size))
1076
2
    return FALSE;
1077
1078
66
  if (str[size / sizeof(WCHAR) - 1])
1079
6
  {
1080
6
    WLog_ERR(TAG, "protocol error: %s must be null terminated", what);
1081
6
    return FALSE;
1082
6
  }
1083
1084
60
  size_t len = 0;
1085
60
  char* rc = ConvertWCharNToUtf8Alloc(str, size / sizeof(WCHAR), &len);
1086
60
  if (!rc)
1087
1
  {
1088
1
    WLog_ERR(TAG, "failed to convert the %s string", what);
1089
1
    free(rc);
1090
1
    return FALSE;
1091
1
  }
1092
1093
59
  *dst = rc;
1094
59
  return TRUE;
1095
60
}
1096
1097
static BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s, logon_info* info)
1098
605
{
1099
605
  UINT32 cbDomain = 0;
1100
605
  UINT32 cbUserName = 0;
1101
1102
605
  WINPR_UNUSED(rdp);
1103
605
  WINPR_ASSERT(info);
1104
1105
605
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
1106
128
    return FALSE;
1107
1108
477
  Stream_Read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */
1109
1110
  /* cbDomain is the size of the Unicode character data (including the mandatory
1111
   * null terminator) in bytes present in the fixed-length (52 bytes) Domain field
1112
   */
1113
477
  if (!rdp_info_read_string("Domain", s, cbDomain, 52, TRUE, &info->domain))
1114
105
    goto fail;
1115
1116
372
  Stream_Read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */
1117
1118
  /* cbUserName is the size of the Unicode character data (including the mandatory
1119
   * null terminator) in bytes present in the fixed-length (512 bytes) UserName field.
1120
   */
1121
372
  if (!rdp_info_read_string("UserName", s, cbUserName, 512, TRUE, &info->username))
1122
164
    goto fail;
1123
1124
208
  Stream_Read_UINT32(s, info->sessionId); /* SessionId (4 bytes) */
1125
208
  WLog_DBG(TAG, "LogonInfoV1: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
1126
208
           info->sessionId, info->username, info->domain);
1127
208
  return TRUE;
1128
269
fail:
1129
269
  return FALSE;
1130
372
}
1131
1132
static BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s, logon_info* info)
1133
123
{
1134
123
  UINT16 Version = 0;
1135
123
  UINT32 Size = 0;
1136
123
  UINT32 cbDomain = 0;
1137
123
  UINT32 cbUserName = 0;
1138
1139
123
  WINPR_ASSERT(rdp);
1140
123
  WINPR_ASSERT(s);
1141
123
  WINPR_ASSERT(info);
1142
1143
123
  WINPR_UNUSED(rdp);
1144
1145
123
  if (!Stream_CheckAndLogRequiredLength(TAG, s, logonInfoV2TotalSize))
1146
11
    return FALSE;
1147
1148
112
  Stream_Read_UINT16(s, Version); /* Version (2 bytes) */
1149
112
  if (Version != SAVE_SESSION_PDU_VERSION_ONE)
1150
11
  {
1151
11
    WLog_WARN(TAG, "LogonInfoV2::Version expected %" PRIu16 " bytes, got %" PRIu16,
1152
11
              SAVE_SESSION_PDU_VERSION_ONE, Version);
1153
11
    return FALSE;
1154
11
  }
1155
1156
101
  Stream_Read_UINT32(s, Size); /* Size (4 bytes) */
1157
1158
  /* [MS-RDPBCGR] 2.2.10.1.1.2 Logon Info Version 2 (TS_LOGON_INFO_VERSION_2)
1159
   * should be logonInfoV2TotalSize
1160
   * but even MS server 2019 sends logonInfoV2Size
1161
   */
1162
101
  if (Size != logonInfoV2TotalSize)
1163
101
  {
1164
101
    if (Size != logonInfoV2Size)
1165
54
    {
1166
54
      WLog_WARN(TAG, "LogonInfoV2::Size expected %" PRIu32 " bytes, got %" PRIu32,
1167
54
                logonInfoV2TotalSize, Size);
1168
54
      return FALSE;
1169
54
    }
1170
101
  }
1171
1172
47
  Stream_Read_UINT32(s, info->sessionId);  /* SessionId (4 bytes) */
1173
47
  Stream_Read_UINT32(s, cbDomain);         /* cbDomain (4 bytes) */
1174
47
  Stream_Read_UINT32(s, cbUserName);       /* cbUserName (4 bytes) */
1175
47
  Stream_Seek(s, logonInfoV2ReservedSize); /* pad (558 bytes) */
1176
1177
  /* cbDomain is the size in bytes of the Unicode character data in the Domain field.
1178
   * The size of the mandatory null terminator is include in this value.
1179
   * Note: Since MS-RDPBCGR 2.2.10.1.1.2 does not mention any size limits we assume
1180
   *       that the maximum value is 52 bytes, according to the fixed size of the
1181
   *       Domain field in the Logon Info Version 1 (TS_LOGON_INFO) structure.
1182
   */
1183
47
  if (!rdp_info_read_string("Domain", s, cbDomain, 52, FALSE, &info->domain))
1184
5
    goto fail;
1185
1186
  /* cbUserName is the size in bytes of the Unicode character data in the UserName field.
1187
   * The size of the mandatory null terminator is include in this value.
1188
   * Note: Since MS-RDPBCGR 2.2.10.1.1.2 does not mention any size limits we assume
1189
   *       that the maximum value is 512 bytes, according to the fixed size of the
1190
   *       Username field in the Logon Info Version 1 (TS_LOGON_INFO) structure.
1191
   */
1192
42
  if (!rdp_info_read_string("UserName", s, cbUserName, 512, FALSE, &info->username))
1193
4
    goto fail;
1194
1195
  /* We´ve seen undocumented padding with windows 11 here.
1196
   * unless it has actual data in it ignore it.
1197
   * if there is unexpected data, print a warning and dump the contents
1198
   */
1199
38
  {
1200
38
    const size_t rem = Stream_GetRemainingLength(s);
1201
38
    if (rem > 0)
1202
37
    {
1203
37
      BOOL warn = FALSE;
1204
37
      const char* str = Stream_ConstPointer(s);
1205
1.61M
      for (size_t x = 0; x < rem; x++)
1206
1.61M
      {
1207
1.61M
        if (str[x] != '\0')
1208
1.21M
          warn = TRUE;
1209
1.61M
      }
1210
37
      if (warn)
1211
27
      {
1212
27
        WLog_WARN(TAG, "unexpected padding of %" PRIuz " bytes, data not '\0'", rem);
1213
27
        winpr_HexDump(TAG, WLOG_TRACE, str, rem);
1214
27
      }
1215
1216
37
      if (!Stream_SafeSeek(s, rem))
1217
0
        goto fail;
1218
37
    }
1219
38
  }
1220
1221
38
  WLog_DBG(TAG, "LogonInfoV2: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
1222
38
           info->sessionId, info->username, info->domain);
1223
38
  return TRUE;
1224
9
fail:
1225
9
  return FALSE;
1226
38
}
1227
1228
static BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s)
1229
21
{
1230
21
  WINPR_UNUSED(rdp);
1231
21
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
1232
7
    return FALSE;
1233
1234
14
  Stream_Seek(s, 576); /* pad (576 bytes) */
1235
14
  WLog_DBG(TAG, "LogonPlainNotify");
1236
14
  return TRUE;
1237
21
}
1238
1239
static BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s, logon_info_ex* info)
1240
97
{
1241
97
  freerdp* instance = NULL;
1242
97
  UINT32 errorNotificationType = 0;
1243
97
  UINT32 errorNotificationData = 0;
1244
1245
97
  WINPR_ASSERT(rdp);
1246
97
  WINPR_ASSERT(rdp->context);
1247
97
  WINPR_ASSERT(s);
1248
97
  WINPR_ASSERT(info);
1249
1250
97
  instance = rdp->context->instance;
1251
97
  WINPR_ASSERT(instance);
1252
1253
97
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1254
1
    return FALSE;
1255
1256
96
  Stream_Read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */
1257
96
  Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */
1258
96
  WLog_DBG(TAG, "LogonErrorInfo: Data: 0x%08" PRIX32 " Type: 0x%08" PRIX32 "",
1259
96
           errorNotificationData, errorNotificationType);
1260
96
  IFCALL(instance->LogonErrorInfo, instance, errorNotificationData, errorNotificationType);
1261
96
  info->ErrorNotificationType = errorNotificationType;
1262
96
  info->ErrorNotificationData = errorNotificationData;
1263
96
  return TRUE;
1264
97
}
1265
1266
static BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, wStream* s, logon_info_ex* info)
1267
188
{
1268
188
  UINT32 cbFieldData = 0;
1269
188
  UINT32 fieldsPresent = 0;
1270
188
  UINT16 Length = 0;
1271
1272
188
  WINPR_ASSERT(rdp);
1273
188
  WINPR_ASSERT(s);
1274
188
  WINPR_ASSERT(info);
1275
1276
188
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1277
2
  {
1278
2
    WLog_WARN(TAG, "received short logon info extended, need 6 bytes, got %" PRIuz,
1279
2
              Stream_GetRemainingLength(s));
1280
2
    return FALSE;
1281
2
  }
1282
1283
186
  Stream_Read_UINT16(s, Length);        /* Length (2 bytes) */
1284
186
  Stream_Read_UINT32(s, fieldsPresent); /* fieldsPresent (4 bytes) */
1285
1286
186
  if ((Length < 6) || (!Stream_CheckAndLogRequiredLength(TAG, s, (Length - 6U))))
1287
19
  {
1288
19
    WLog_WARN(TAG,
1289
19
              "received short logon info extended, need %" PRIu16 " - 6 bytes, got %" PRIuz,
1290
19
              Length, Stream_GetRemainingLength(s));
1291
19
    return FALSE;
1292
19
  }
1293
1294
167
  WLog_DBG(TAG, "LogonInfoExtended: fieldsPresent: 0x%08" PRIX32 "", fieldsPresent);
1295
1296
  /* logonFields */
1297
1298
167
  if (fieldsPresent & LOGON_EX_AUTORECONNECTCOOKIE)
1299
76
  {
1300
76
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1301
1
      return FALSE;
1302
1303
75
    info->haveCookie = TRUE;
1304
75
    Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
1305
1306
75
    if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
1307
7
      return FALSE;
1308
1309
68
    if (!rdp_read_server_auto_reconnect_cookie(rdp, s, info))
1310
45
      return FALSE;
1311
68
  }
1312
1313
114
  if (fieldsPresent & LOGON_EX_LOGONERRORS)
1314
103
  {
1315
103
    info->haveErrorInfo = TRUE;
1316
1317
103
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1318
2
      return FALSE;
1319
1320
101
    Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
1321
1322
101
    if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
1323
4
      return FALSE;
1324
1325
97
    if (!rdp_recv_logon_error_info(rdp, s, info))
1326
1
      return FALSE;
1327
97
  }
1328
1329
107
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 570))
1330
65
    return FALSE;
1331
1332
42
  Stream_Seek(s, 570); /* pad (570 bytes) */
1333
42
  return TRUE;
1334
107
}
1335
1336
BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s)
1337
9.35k
{
1338
9.35k
  UINT32 infoType = 0;
1339
9.35k
  BOOL status = 0;
1340
9.35k
  logon_info logonInfo = { 0 };
1341
9.35k
  logon_info_ex logonInfoEx = { 0 };
1342
9.35k
  rdpContext* context = rdp->context;
1343
9.35k
  rdpUpdate* update = rdp->context->update;
1344
1345
9.35k
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1346
5.93k
    return FALSE;
1347
1348
3.42k
  Stream_Read_UINT32(s, infoType); /* infoType (4 bytes) */
1349
1350
3.42k
  switch (infoType)
1351
3.42k
  {
1352
605
    case INFO_TYPE_LOGON:
1353
605
      status = rdp_recv_logon_info_v1(rdp, s, &logonInfo);
1354
1355
605
      if (status && update->SaveSessionInfo)
1356
0
        status = update->SaveSessionInfo(context, infoType, &logonInfo);
1357
1358
605
      rdp_free_logon_info(&logonInfo);
1359
605
      break;
1360
1361
123
    case INFO_TYPE_LOGON_LONG:
1362
123
      status = rdp_recv_logon_info_v2(rdp, s, &logonInfo);
1363
1364
123
      if (status && update->SaveSessionInfo)
1365
0
        status = update->SaveSessionInfo(context, infoType, &logonInfo);
1366
1367
123
      rdp_free_logon_info(&logonInfo);
1368
123
      break;
1369
1370
21
    case INFO_TYPE_LOGON_PLAIN_NOTIFY:
1371
21
      status = rdp_recv_logon_plain_notify(rdp, s);
1372
1373
21
      if (status && update->SaveSessionInfo)
1374
0
        status = update->SaveSessionInfo(context, infoType, NULL);
1375
1376
21
      break;
1377
1378
188
    case INFO_TYPE_LOGON_EXTENDED_INF:
1379
188
      status = rdp_recv_logon_info_extended(rdp, s, &logonInfoEx);
1380
1381
188
      if (status && update->SaveSessionInfo)
1382
0
        status = update->SaveSessionInfo(context, infoType, &logonInfoEx);
1383
1384
188
      break;
1385
1386
2.48k
    default:
1387
2.48k
      WLog_ERR(TAG, "Unhandled saveSessionInfo type 0x%" PRIx32 "", infoType);
1388
2.48k
      status = TRUE;
1389
2.48k
      break;
1390
3.42k
  }
1391
1392
3.42k
  if (!status)
1393
635
  {
1394
635
    WLog_DBG(TAG, "SaveSessionInfo error: infoType: %s (%" PRIu32 ")",
1395
635
             infoType < 4 ? INFO_TYPE_LOGON_STRINGS[infoType % 4] : "Unknown", infoType);
1396
635
  }
1397
1398
3.42k
  return status;
1399
3.42k
}
1400
1401
static BOOL rdp_write_logon_info_v1(wStream* s, logon_info* info)
1402
0
{
1403
0
  const size_t charLen = 52 / sizeof(WCHAR);
1404
0
  const size_t userCharLen = 512 / sizeof(WCHAR);
1405
1406
0
  size_t sz = 4 + 52 + 4 + 512 + 4;
1407
1408
0
  if (!Stream_EnsureRemainingCapacity(s, sz))
1409
0
    return FALSE;
1410
1411
  /* domain */
1412
0
  {
1413
0
    WINPR_ASSERT(info);
1414
0
    if (!info->domain || !info->username)
1415
0
      return FALSE;
1416
0
    const size_t len = strnlen(info->domain, charLen + 1);
1417
0
    if (len > charLen)
1418
0
      return FALSE;
1419
1420
0
    const size_t wlen = len * sizeof(WCHAR);
1421
0
    if (wlen > UINT32_MAX)
1422
0
      return FALSE;
1423
1424
0
    Stream_Write_UINT32(s, (UINT32)wlen);
1425
0
    if (Stream_Write_UTF16_String_From_UTF8(s, charLen, info->domain, len, TRUE) < 0)
1426
0
      return FALSE;
1427
0
  }
1428
1429
  /* username */
1430
0
  {
1431
0
    const size_t len = strnlen(info->username, userCharLen + 1);
1432
0
    if (len > userCharLen)
1433
0
      return FALSE;
1434
1435
0
    const size_t wlen = len * sizeof(WCHAR);
1436
0
    if (wlen > UINT32_MAX)
1437
0
      return FALSE;
1438
1439
0
    Stream_Write_UINT32(s, (UINT32)wlen);
1440
1441
0
    if (Stream_Write_UTF16_String_From_UTF8(s, userCharLen, info->username, len, TRUE) < 0)
1442
0
      return FALSE;
1443
0
  }
1444
1445
  /* sessionId */
1446
0
  Stream_Write_UINT32(s, info->sessionId);
1447
0
  return TRUE;
1448
0
}
1449
1450
static BOOL rdp_write_logon_info_v2(wStream* s, logon_info* info)
1451
0
{
1452
0
  size_t domainLen = 0;
1453
0
  size_t usernameLen = 0;
1454
1455
0
  if (!Stream_EnsureRemainingCapacity(s, logonInfoV2TotalSize))
1456
0
    return FALSE;
1457
1458
0
  Stream_Write_UINT16(s, SAVE_SESSION_PDU_VERSION_ONE);
1459
  /* [MS-RDPBCGR] 2.2.10.1.1.2 Logon Info Version 2 (TS_LOGON_INFO_VERSION_2)
1460
   * should be logonInfoV2TotalSize
1461
   * but even MS server 2019 sends logonInfoV2Size
1462
   */
1463
0
  Stream_Write_UINT32(s, logonInfoV2Size);
1464
0
  Stream_Write_UINT32(s, info->sessionId);
1465
0
  domainLen = strnlen(info->domain, 256); /* lmcons.h UNLEN */
1466
0
  if (domainLen >= UINT32_MAX / sizeof(WCHAR))
1467
0
    return FALSE;
1468
0
  Stream_Write_UINT32(s, (UINT32)(domainLen + 1) * sizeof(WCHAR));
1469
0
  usernameLen = strnlen(info->username, 256); /* lmcons.h UNLEN */
1470
0
  if (usernameLen >= UINT32_MAX / sizeof(WCHAR))
1471
0
    return FALSE;
1472
0
  Stream_Write_UINT32(s, (UINT32)(usernameLen + 1) * sizeof(WCHAR));
1473
0
  Stream_Seek(s, logonInfoV2ReservedSize);
1474
0
  if (Stream_Write_UTF16_String_From_UTF8(s, domainLen + 1, info->domain, domainLen, TRUE) < 0)
1475
0
    return FALSE;
1476
0
  if (Stream_Write_UTF16_String_From_UTF8(s, usernameLen + 1, info->username, usernameLen, TRUE) <
1477
0
      0)
1478
0
    return FALSE;
1479
0
  return TRUE;
1480
0
}
1481
1482
static BOOL rdp_write_logon_info_plain(wStream* s)
1483
0
{
1484
0
  if (!Stream_EnsureRemainingCapacity(s, 576))
1485
0
    return FALSE;
1486
1487
0
  Stream_Seek(s, 576);
1488
0
  return TRUE;
1489
0
}
1490
1491
static BOOL rdp_write_logon_info_ex(wStream* s, logon_info_ex* info)
1492
0
{
1493
0
  UINT32 FieldsPresent = 0;
1494
0
  UINT16 Size = 2 + 4 + 570;
1495
1496
0
  if (info->haveCookie)
1497
0
  {
1498
0
    FieldsPresent |= LOGON_EX_AUTORECONNECTCOOKIE;
1499
0
    Size += 28;
1500
0
  }
1501
1502
0
  if (info->haveErrorInfo)
1503
0
  {
1504
0
    FieldsPresent |= LOGON_EX_LOGONERRORS;
1505
0
    Size += 8;
1506
0
  }
1507
1508
0
  if (!Stream_EnsureRemainingCapacity(s, Size))
1509
0
    return FALSE;
1510
1511
0
  Stream_Write_UINT16(s, Size);
1512
0
  Stream_Write_UINT32(s, FieldsPresent);
1513
1514
0
  if (info->haveCookie)
1515
0
  {
1516
0
    Stream_Write_UINT32(s, 28);                       /* cbFieldData (4 bytes) */
1517
0
    Stream_Write_UINT32(s, 28);                       /* cbLen (4 bytes) */
1518
0
    Stream_Write_UINT32(s, AUTO_RECONNECT_VERSION_1); /* Version (4 bytes) */
1519
0
    Stream_Write_UINT32(s, info->LogonId);            /* LogonId (4 bytes) */
1520
0
    Stream_Write(s, info->ArcRandomBits, 16);         /* ArcRandomBits (16 bytes) */
1521
0
  }
1522
1523
0
  if (info->haveErrorInfo)
1524
0
  {
1525
0
    Stream_Write_UINT32(s, 8);                           /* cbFieldData (4 bytes) */
1526
0
    Stream_Write_UINT32(s, info->ErrorNotificationType); /* ErrorNotificationType (4 bytes) */
1527
0
    Stream_Write_UINT32(s, info->ErrorNotificationData); /* ErrorNotificationData (4 bytes) */
1528
0
  }
1529
1530
0
  Stream_Seek(s, 570);
1531
0
  return TRUE;
1532
0
}
1533
1534
BOOL rdp_send_save_session_info(rdpContext* context, UINT32 type, void* data)
1535
0
{
1536
0
  UINT16 sec_flags = 0;
1537
0
  wStream* s = NULL;
1538
0
  BOOL status = 0;
1539
0
  rdpRdp* rdp = context->rdp;
1540
0
  s = rdp_data_pdu_init(rdp, &sec_flags);
1541
1542
0
  if (!s)
1543
0
    return FALSE;
1544
1545
0
  Stream_Write_UINT32(s, type);
1546
1547
0
  switch (type)
1548
0
  {
1549
0
    case INFO_TYPE_LOGON:
1550
0
      status = rdp_write_logon_info_v1(s, (logon_info*)data);
1551
0
      break;
1552
1553
0
    case INFO_TYPE_LOGON_LONG:
1554
0
      status = rdp_write_logon_info_v2(s, (logon_info*)data);
1555
0
      break;
1556
1557
0
    case INFO_TYPE_LOGON_PLAIN_NOTIFY:
1558
0
      status = rdp_write_logon_info_plain(s);
1559
0
      break;
1560
1561
0
    case INFO_TYPE_LOGON_EXTENDED_INF:
1562
0
      status = rdp_write_logon_info_ex(s, (logon_info_ex*)data);
1563
0
      break;
1564
1565
0
    default:
1566
0
      WLog_ERR(TAG, "saveSessionInfo type 0x%" PRIx32 " not handled", type);
1567
0
      status = FALSE;
1568
0
      break;
1569
0
  }
1570
1571
0
  if (status)
1572
0
    status =
1573
0
        rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SAVE_SESSION_INFO, rdp->mcs->userId, sec_flags);
1574
0
  else
1575
0
    Stream_Release(s);
1576
1577
0
  return status;
1578
0
}
1579
1580
BOOL rdp_send_server_status_info(rdpContext* context, UINT32 status)
1581
0
{
1582
0
  UINT16 sec_flags = 0;
1583
0
  wStream* s = NULL;
1584
0
  rdpRdp* rdp = context->rdp;
1585
0
  s = rdp_data_pdu_init(rdp, &sec_flags);
1586
1587
0
  if (!s)
1588
0
    return FALSE;
1589
1590
0
  Stream_Write_UINT32(s, status);
1591
0
  return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_STATUS_INFO, rdp->mcs->userId, sec_flags);
1592
0
}