Coverage Report

Created: 2025-08-26 06:37

/src/FreeRDP/libfreerdp/core/info.c
Line
Count
Source (jump to first uncovered line)
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
24
#define TAG FREERDP_TAG("core.info")
39
40
210
#define logonInfoV2Size (2 + 4 + 4 + 4 + 4)
41
146
#define logonInfoV2ReservedSize 558
42
105
#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
2.28k
{
81
2.28k
  const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
82
83
2.28k
  if (!freerdp_settings_set_string(settings, id, NULL))
84
0
    return FALSE;
85
86
2.28k
  if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLen)))
87
178
    return FALSE;
88
89
2.10k
  if (cbLen > 0)
90
409
  {
91
409
    if ((cbLen > max) || (unicode && ((cbLen % 2) != 0)))
92
209
    {
93
209
      WLog_ERR(TAG, "protocol error: %s has invalid value: %" PRIuz "", what, cbLen);
94
209
      return FALSE;
95
209
    }
96
97
200
    if (unicode)
98
200
    {
99
200
      const WCHAR* domain = Stream_PointerAs(s, WCHAR);
100
200
      if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
101
200
                                                   cbLen / sizeof(WCHAR)))
102
12
      {
103
12
        WLog_ERR(TAG, "protocol error: no data to read for %s [expected %" PRIuz "]", what,
104
12
                 cbLen);
105
12
        return FALSE;
106
12
      }
107
200
    }
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
200
  }
115
1.88k
  Stream_Seek(s, cbLen);
116
117
1.88k
  return TRUE;
118
2.10k
}
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
114
{
181
114
  BYTE* p = NULL;
182
114
  ARC_SC_PRIVATE_PACKET* autoReconnectCookie = NULL;
183
114
  rdpSettings* settings = rdp->settings;
184
114
  autoReconnectCookie = settings->ServerAutoReconnectCookie;
185
186
114
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
187
5
    return FALSE;
188
189
109
  Stream_Read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
190
191
109
  if (autoReconnectCookie->cbLen != 28)
192
59
  {
193
59
    WLog_ERR(TAG, "ServerAutoReconnectCookie.cbLen != 28");
194
59
    return FALSE;
195
59
  }
196
197
50
  Stream_Read_UINT32(s, autoReconnectCookie->version);    /* Version (4 bytes) */
198
50
  Stream_Read_UINT32(s, autoReconnectCookie->logonId);    /* LogonId (4 bytes) */
199
50
  Stream_Read(s, autoReconnectCookie->arcRandomBits, 16); /* ArcRandomBits (16 bytes) */
200
50
  p = autoReconnectCookie->arcRandomBits;
201
50
  WLog_DBG(TAG,
202
50
           "ServerAutoReconnectCookie: Version: %" PRIu32 " LogonId: %" PRIu32
203
50
           " SecurityVerifier: "
204
50
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
205
50
           "%02" PRIX8 ""
206
50
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
207
50
           "%02" PRIX8 "",
208
50
           autoReconnectCookie->version, autoReconnectCookie->logonId, p[0], p[1], p[2], p[3],
209
50
           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
50
  info->LogonId = autoReconnectCookie->logonId;
211
50
  CopyMemory(info->ArcRandomBits, p, 16);
212
213
50
  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
50
  return TRUE;
222
109
}
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
562
{
231
562
  ARC_CS_PRIVATE_PACKET* autoReconnectCookie = NULL;
232
562
  rdpSettings* settings = rdp->settings;
233
562
  autoReconnectCookie = settings->ClientAutoReconnectCookie;
234
235
562
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
236
13
    return FALSE;
237
238
549
  Stream_Read_UINT32(s, autoReconnectCookie->cbLen);         /* cbLen (4 bytes) */
239
549
  Stream_Read_UINT32(s, autoReconnectCookie->version);       /* version (4 bytes) */
240
549
  Stream_Read_UINT32(s, autoReconnectCookie->logonId);       /* LogonId (4 bytes) */
241
549
  Stream_Read(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
242
549
  return TRUE;
243
562
}
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
821
{
291
821
  UINT32 version = 0;
292
821
  rdpSettings* settings = NULL;
293
294
821
  WINPR_ASSERT(rdp);
295
296
821
  settings = rdp->settings;
297
821
  WINPR_ASSERT(settings);
298
299
821
  version = freerdp_settings_get_uint32(settings, FreeRDP_RdpVersion);
300
821
  if (version < RDP_VERSION_10_0)
301
0
    return 64;
302
821
  return 80;
303
821
}
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
827
{
312
827
  UINT16 clientAddressFamily = 0;
313
827
  UINT16 cbClientAddress = 0;
314
827
  UINT16 cbClientDir = 0;
315
827
  UINT16 cbAutoReconnectLen = 0;
316
317
827
  WINPR_ASSERT(rdp);
318
319
827
  rdpSettings* settings = rdp->settings;
320
827
  WINPR_ASSERT(settings);
321
322
827
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
323
6
    return FALSE;
324
325
821
  Stream_Read_UINT16(s, clientAddressFamily); /* clientAddressFamily (2 bytes) */
326
821
  Stream_Read_UINT16(s, cbClientAddress);     /* cbClientAddress (2 bytes) */
327
328
821
  settings->IPv6Enabled = (clientAddressFamily == ADDRESS_FAMILY_INET6 ? TRUE : FALSE);
329
330
821
  if (!rdp_read_info_null_string(settings, FreeRDP_ClientAddress, "cbClientAddress", INFO_UNICODE,
331
821
                                 s, cbClientAddress, rdp_get_client_address_max_size(rdp)))
332
33
    return FALSE;
333
334
788
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
335
6
    return FALSE;
336
337
782
  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
782
  if (!rdp_read_info_null_string(settings, FreeRDP_ClientDir, "cbClientDir", INFO_UNICODE, s,
348
782
                                 cbClientDir, 512))
349
17
    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
765
  if (Stream_GetRemainingLength(s) == 0)
358
10
    goto end;
359
360
755
  if (!rdp_read_client_time_zone(s, settings))
361
24
    return FALSE;
362
363
  /* optional: clientSessionId (4 bytes), should be set to 0 */
364
731
  if (Stream_GetRemainingLength(s) == 0)
365
2
    goto end;
366
729
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
367
5
    return FALSE;
368
369
724
  Stream_Read_UINT32(s, settings->ClientSessionId);
370
371
  /* optional: performanceFlags (4 bytes) */
372
724
  if (Stream_GetRemainingLength(s) == 0)
373
2
    goto end;
374
375
722
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
376
3
    return FALSE;
377
378
719
  Stream_Read_UINT32(s, settings->PerformanceFlags);
379
719
  freerdp_performance_flags_split(settings);
380
381
  /* optional: cbAutoReconnectLen (2 bytes) */
382
719
  if (Stream_GetRemainingLength(s) == 0)
383
2
    goto end;
384
385
717
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
386
3
    return FALSE;
387
388
714
  Stream_Read_UINT16(s, cbAutoReconnectLen);
389
390
  /* optional: autoReconnectCookie (28 bytes) */
391
  /* must be present if cbAutoReconnectLen is > 0 */
392
714
  if (cbAutoReconnectLen > 0)
393
562
  {
394
562
    if (!rdp_read_client_auto_reconnect_cookie(rdp, s))
395
13
      return FALSE;
396
562
  }
397
398
  /* skip reserved1 and reserved2 fields */
399
701
  if (Stream_GetRemainingLength(s) == 0)
400
4
    goto end;
401
402
697
  if (!Stream_SafeSeek(s, 2))
403
4
    return FALSE;
404
405
693
  if (Stream_GetRemainingLength(s) == 0)
406
2
    goto end;
407
408
691
  if (!Stream_SafeSeek(s, 2))
409
2
    return FALSE;
410
411
689
  if (Stream_GetRemainingLength(s) == 0)
412
2
    goto end;
413
414
687
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
415
3
    return FALSE;
416
417
684
  if (freerdp_settings_get_bool(settings, FreeRDP_SupportDynamicTimeZone))
418
684
  {
419
684
    UINT16 cbDynamicDSTTimeZoneKeyName = 0;
420
421
684
    Stream_Read_UINT16(s, cbDynamicDSTTimeZoneKeyName);
422
423
684
    if (!rdp_read_info_null_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName,
424
684
                                   "cbDynamicDSTTimeZoneKeyName", INFO_UNICODE, s,
425
684
                                   cbDynamicDSTTimeZoneKeyName, 254))
426
349
      return FALSE;
427
428
335
    if (Stream_GetRemainingLength(s) == 0)
429
3
      goto end;
430
431
332
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
432
4
      return FALSE;
433
328
    UINT16 DynamicDaylightTimeDisabled = 0;
434
328
    Stream_Read_UINT16(s, DynamicDaylightTimeDisabled);
435
328
    if (DynamicDaylightTimeDisabled > 1)
436
198
    {
437
198
      WLog_WARN(TAG,
438
198
                "[MS-RDPBCGR] 2.2.1.11.1.1.1 Extended Info Packet "
439
198
                "(TS_EXTENDED_INFO_PACKET)::dynamicDaylightTimeDisabled value %" PRIu16
440
198
                " not allowed in [0,1]",
441
198
                settings->DynamicDaylightTimeDisabled);
442
198
      return FALSE;
443
198
    }
444
130
    if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicDaylightTimeDisabled,
445
130
                                   DynamicDaylightTimeDisabled != 0))
446
0
      return FALSE;
447
130
    DEBUG_TIMEZONE("DynamicTimeZone=%s [%s]",
448
130
                   freerdp_settings_get_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName),
449
130
                   freerdp_settings_get_bool(settings, FreeRDP_DynamicDaylightTimeDisabled)
450
130
                       ? "no-DST"
451
130
                       : "DST");
452
130
  }
453
454
157
end:
455
157
  return TRUE;
456
684
}
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
4.50k
{
596
4.50k
  union
597
4.50k
  {
598
4.50k
    char c;
599
4.50k
    WCHAR w;
600
4.50k
    BYTE b[2];
601
4.50k
  } terminator;
602
603
4.50k
  const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
604
4.50k
  const size_t nullSize = unicode ? sizeof(WCHAR) : sizeof(CHAR);
605
606
4.50k
  if (!freerdp_settings_set_string(settings, id, NULL))
607
0
    return FALSE;
608
609
4.50k
  if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLenNonNull + nullSize)))
610
47
    return FALSE;
611
612
4.45k
  if (cbLenNonNull > 0)
613
236
  {
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
236
    if ((cbLenNonNull % 2) || (cbLenNonNull > (max - nullSize)))
619
25
    {
620
25
      WLog_ERR(TAG, "protocol error: invalid value: %" PRIuz "", cbLenNonNull);
621
25
      return FALSE;
622
25
    }
623
624
211
    if (unicode)
625
175
    {
626
175
      const WCHAR* domain = Stream_PointerAs(s, WCHAR);
627
175
      if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
628
175
                                                   cbLenNonNull / sizeof(WCHAR)))
629
34
        return FALSE;
630
175
    }
631
36
    else
632
36
    {
633
36
      const char* domain = Stream_PointerAs(s, char);
634
36
      if (!freerdp_settings_set_string_len(settings, id, domain, cbLenNonNull))
635
0
        return FALSE;
636
36
    }
637
211
  }
638
639
4.39k
  Stream_Seek(s, cbLenNonNull);
640
641
4.39k
  terminator.w = L'\0';
642
4.39k
  Stream_Read(s, terminator.b, nullSize);
643
644
4.39k
  if (terminator.w != L'\0')
645
142
  {
646
142
    WLog_ERR(TAG, "protocol error: Domain must be null terminated");
647
142
    (void)freerdp_settings_set_string(settings, id, NULL);
648
142
    return FALSE;
649
142
  }
650
651
4.25k
  return TRUE;
652
4.39k
}
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
1.09k
{
661
1.09k
  BOOL smallsize = FALSE;
662
1.09k
  UINT32 flags = 0;
663
1.09k
  UINT16 cbDomain = 0;
664
1.09k
  UINT16 cbUserName = 0;
665
1.09k
  UINT16 cbPassword = 0;
666
1.09k
  UINT16 cbAlternateShell = 0;
667
1.09k
  UINT16 cbWorkingDir = 0;
668
1.09k
  UINT32 CompressionLevel = 0;
669
1.09k
  rdpSettings* settings = rdp->settings;
670
671
1.09k
  if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 18))
672
15
    return FALSE;
673
674
1.07k
  Stream_Read_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes ) */
675
1.07k
  Stream_Read_UINT32(s, flags);                      /* flags (4 bytes) */
676
1.07k
  settings->AudioCapture = ((flags & INFO_AUDIOCAPTURE) ? TRUE : FALSE);
677
1.07k
  settings->AudioPlayback = ((flags & INFO_NOAUDIOPLAYBACK) ? FALSE : TRUE);
678
1.07k
  settings->AutoLogonEnabled = ((flags & INFO_AUTOLOGON) ? TRUE : FALSE);
679
1.07k
  settings->RemoteApplicationMode = ((flags & INFO_RAIL) ? TRUE : FALSE);
680
1.07k
  settings->HiDefRemoteApp = ((flags & INFO_HIDEF_RAIL_SUPPORTED) ? TRUE : FALSE);
681
1.07k
  settings->RemoteConsoleAudio = ((flags & INFO_REMOTECONSOLEAUDIO) ? TRUE : FALSE);
682
1.07k
  settings->CompressionEnabled = ((flags & INFO_COMPRESSION) ? TRUE : FALSE);
683
1.07k
  settings->LogonNotify = ((flags & INFO_LOGONNOTIFY) ? TRUE : FALSE);
684
1.07k
  settings->MouseHasWheel = ((flags & INFO_MOUSE_HAS_WHEEL) ? TRUE : FALSE);
685
1.07k
  settings->DisableCtrlAltDel = ((flags & INFO_DISABLECTRLALTDEL) ? TRUE : FALSE);
686
1.07k
  settings->ForceEncryptedCsPdu = ((flags & INFO_FORCE_ENCRYPTED_CS_PDU) ? TRUE : FALSE);
687
1.07k
  settings->PasswordIsSmartcardPin = ((flags & INFO_PASSWORD_IS_SC_PIN) ? TRUE : FALSE);
688
689
1.07k
  if (flags & INFO_COMPRESSION)
690
151
  {
691
151
    CompressionLevel = ((flags & 0x00001E00) >> 9);
692
151
    settings->CompressionLevel = CompressionLevel;
693
151
  }
694
924
  else
695
924
  {
696
924
    settings->CompressionLevel = 0;
697
924
  }
698
699
  /* RDP 4 and 5 have smaller credential limits */
700
1.07k
  if (settings->RdpVersion < RDP_VERSION_5_PLUS)
701
0
    smallsize = TRUE;
702
703
1.07k
  Stream_Read_UINT16(s, cbDomain);         /* cbDomain (2 bytes) */
704
1.07k
  Stream_Read_UINT16(s, cbUserName);       /* cbUserName (2 bytes) */
705
1.07k
  Stream_Read_UINT16(s, cbPassword);       /* cbPassword (2 bytes) */
706
1.07k
  Stream_Read_UINT16(s, cbAlternateShell); /* cbAlternateShell (2 bytes) */
707
1.07k
  Stream_Read_UINT16(s, cbWorkingDir);     /* cbWorkingDir (2 bytes) */
708
709
1.07k
  if (!rdp_read_info_string(settings, FreeRDP_Domain, flags, s, cbDomain, smallsize ? 52 : 512))
710
188
    return FALSE;
711
712
887
  if (!rdp_read_info_string(settings, FreeRDP_Username, flags, s, cbUserName,
713
887
                            smallsize ? 44 : 512))
714
30
    return FALSE;
715
716
857
  if (!rdp_read_info_string(settings, FreeRDP_Password, flags, s, cbPassword,
717
857
                            smallsize ? 32 : 512))
718
9
    return FALSE;
719
720
848
  if (!rdp_read_info_string(settings, FreeRDP_AlternateShell, flags, s, cbAlternateShell, 512))
721
13
    return FALSE;
722
723
835
  if (!rdp_read_info_string(settings, FreeRDP_ShellWorkingDirectory, flags, s, cbWorkingDir, 512))
724
8
    return FALSE;
725
726
827
  if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
727
827
  {
728
827
    if (!rdp_read_extended_info_packet(rdp, s)) /* extraInfo */
729
670
      return FALSE;
730
827
  }
731
732
157
  const size_t xrem = Stream_GetRemainingLength(s);
733
157
  if (!tpkt_ensure_stream_consumed(rdp->log, s, tpktlength))
734
128
    Stream_Seek(s, xrem);
735
157
  return TRUE;
736
827
}
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
  const char* pin = "*";
840
0
  if (!settings->RemoteAssistanceMode)
841
0
  {
842
    /* Ignore redirection password if we´re using smartcard and have the pin as password */
843
0
    if (((flags & INFO_PASSWORD_IS_SC_PIN) == 0) && settings->RedirectionPassword &&
844
0
        (settings->RedirectionPasswordLength > 0))
845
0
    {
846
0
      union
847
0
      {
848
0
        BYTE* bp;
849
0
        WCHAR* wp;
850
0
      } ptrconv;
851
852
0
      if (settings->RedirectionPasswordLength > UINT16_MAX)
853
0
      {
854
0
        WLog_ERR(TAG, "RedirectionPasswordLength > UINT16_MAX");
855
0
        goto fail;
856
0
      }
857
0
      usedPasswordCookie = TRUE;
858
859
0
      ptrconv.bp = settings->RedirectionPassword;
860
0
      passwordW = ptrconv.wp;
861
0
      cbPassword = (UINT16)settings->RedirectionPasswordLength;
862
0
    }
863
0
    else
864
0
      pin = freerdp_settings_get_string(settings, FreeRDP_Password);
865
0
  }
866
867
0
  if (!usedPasswordCookie && pin)
868
0
  {
869
0
    passwordW = ConvertUtf8ToWCharAlloc(pin, &cbPassword);
870
0
    if (cbPassword > UINT16_MAX / sizeof(WCHAR))
871
0
    {
872
0
      WLog_ERR(TAG, "cbPassword > UINT16_MAX");
873
0
      goto fail;
874
0
    }
875
0
    cbPassword = (UINT16)cbPassword * sizeof(WCHAR);
876
0
  }
877
878
0
  const char* altShell = NULL;
879
0
  if (!settings->RemoteAssistanceMode)
880
0
    altShell = freerdp_settings_get_string(settings, FreeRDP_AlternateShell);
881
0
  else if (settings->RemoteAssistancePassStub)
882
0
    altShell = "*"; /* This field MUST be filled with "*" */
883
0
  else
884
0
    altShell = freerdp_settings_get_string(settings, FreeRDP_RemoteAssistancePassword);
885
886
0
  if (altShell && strlen(altShell) > 0)
887
0
  {
888
0
    alternateShellW = ConvertUtf8ToWCharAlloc(altShell, &cbAlternateShell);
889
0
    if (!alternateShellW)
890
0
    {
891
0
      WLog_ERR(TAG, "alternateShellW == NULL");
892
0
      goto fail;
893
0
    }
894
0
    if (cbAlternateShell > (UINT16_MAX / sizeof(WCHAR)))
895
0
    {
896
0
      WLog_ERR(TAG, "cbAlternateShell > UINT16_MAX");
897
0
      goto fail;
898
0
    }
899
0
    cbAlternateShell = (UINT16)cbAlternateShell * sizeof(WCHAR);
900
0
  }
901
902
0
  FreeRDP_Settings_Keys_String inputId = FreeRDP_RemoteAssistanceSessionId;
903
0
  if (!freerdp_settings_get_bool(settings, FreeRDP_RemoteAssistanceMode))
904
0
    inputId = FreeRDP_ShellWorkingDirectory;
905
906
0
  workingDirW = freerdp_settings_get_string_as_utf16(settings, inputId, &cbWorkingDir);
907
0
  if (cbWorkingDir > (UINT16_MAX / sizeof(WCHAR)))
908
0
  {
909
0
    WLog_ERR(TAG, "cbWorkingDir > UINT16_MAX");
910
0
    goto fail;
911
0
  }
912
0
  cbWorkingDir = (UINT16)cbWorkingDir * sizeof(WCHAR);
913
914
0
  if (!Stream_EnsureRemainingCapacity(s, 18ull + cbDomain + cbUserName + cbPassword +
915
0
                                             cbAlternateShell + cbWorkingDir + 5 * sizeof(WCHAR)))
916
0
    goto fail;
917
918
0
  Stream_Write_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes) */
919
0
  Stream_Write_UINT32(s, flags);                      /* flags (4 bytes) */
920
0
  Stream_Write_UINT16(s, (UINT16)cbDomain);           /* cbDomain (2 bytes) */
921
0
  Stream_Write_UINT16(s, (UINT16)cbUserName);         /* cbUserName (2 bytes) */
922
0
  Stream_Write_UINT16(s, (UINT16)cbPassword);         /* cbPassword (2 bytes) */
923
0
  Stream_Write_UINT16(s, (UINT16)cbAlternateShell);   /* cbAlternateShell (2 bytes) */
924
0
  Stream_Write_UINT16(s, (UINT16)cbWorkingDir);       /* cbWorkingDir (2 bytes) */
925
926
0
  Stream_Write(s, domainW, cbDomain);
927
928
  /* the mandatory null terminator */
929
0
  Stream_Write_UINT16(s, 0);
930
931
0
  Stream_Write(s, userNameW, cbUserName);
932
933
  /* the mandatory null terminator */
934
0
  Stream_Write_UINT16(s, 0);
935
936
0
  Stream_Write(s, passwordW, cbPassword);
937
938
  /* the mandatory null terminator */
939
0
  Stream_Write_UINT16(s, 0);
940
941
0
  Stream_Write(s, alternateShellW, cbAlternateShell);
942
943
  /* the mandatory null terminator */
944
0
  Stream_Write_UINT16(s, 0);
945
946
0
  Stream_Write(s, workingDirW, cbWorkingDir);
947
948
  /* the mandatory null terminator */
949
0
  Stream_Write_UINT16(s, 0);
950
0
  ret = TRUE;
951
0
fail:
952
0
  free(domainW);
953
0
  free(userNameW);
954
0
  free(alternateShellW);
955
0
  free(workingDirW);
956
957
0
  if (!usedPasswordCookie)
958
0
    free(passwordW);
959
960
0
  if (!ret)
961
0
    return FALSE;
962
963
0
  if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
964
0
    ret = rdp_write_extended_info_packet(rdp, s); /* extraInfo */
965
966
0
  return ret;
967
0
}
968
969
/**
970
 * Read Client Info PDU (CLIENT_INFO_PDU).
971
 * msdn{cc240474}
972
 * @param rdp RDP module
973
 * @param s stream
974
 */
975
976
BOOL rdp_recv_client_info(rdpRdp* rdp, wStream* s)
977
18.3k
{
978
18.3k
  UINT16 length = 0;
979
18.3k
  UINT16 channelId = 0;
980
18.3k
  UINT16 securityFlags = 0;
981
982
18.3k
  WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE);
983
984
18.3k
  if (!rdp_read_header(rdp, s, &length, &channelId))
985
17.2k
    return FALSE;
986
987
1.11k
  if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
988
8
    return FALSE;
989
990
1.10k
  if ((securityFlags & SEC_INFO_PKT) == 0)
991
17
    return FALSE;
992
993
1.09k
  if (rdp->settings->UseRdpSecurityLayer)
994
0
  {
995
0
    if (securityFlags & SEC_REDIRECTION_PKT)
996
0
    {
997
0
      WLog_ERR(TAG, "Error: SEC_REDIRECTION_PKT unsupported");
998
0
      return FALSE;
999
0
    }
1000
1001
0
    if (securityFlags & SEC_ENCRYPT)
1002
0
    {
1003
0
      if (!rdp_decrypt(rdp, s, &length, securityFlags))
1004
0
        return FALSE;
1005
0
    }
1006
0
  }
1007
1008
1.09k
  return rdp_read_info_packet(rdp, s, length);
1009
1.09k
}
1010
1011
/**
1012
 * Send Client Info PDU (CLIENT_INFO_PDU).
1013
 * msdn{cc240474}
1014
 * @param rdp RDP module
1015
 */
1016
1017
BOOL rdp_send_client_info(rdpRdp* rdp)
1018
0
{
1019
0
  UINT16 sec_flags = SEC_INFO_PKT;
1020
0
  wStream* s = NULL;
1021
0
  WINPR_ASSERT(rdp);
1022
0
  s = rdp_send_stream_init(rdp, &sec_flags);
1023
1024
0
  if (!s)
1025
0
  {
1026
0
    WLog_ERR(TAG, "Stream_New failed!");
1027
0
    return FALSE;
1028
0
  }
1029
1030
0
  if (!rdp_write_info_packet(rdp, s))
1031
0
  {
1032
0
    Stream_Release(s);
1033
0
    return FALSE;
1034
0
  }
1035
0
  return rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID, sec_flags);
1036
0
}
1037
1038
static void rdp_free_logon_info(logon_info* info)
1039
834
{
1040
834
  if (!info)
1041
0
    return;
1042
834
  free(info->domain);
1043
834
  free(info->username);
1044
1045
834
  const logon_info empty = { 0 };
1046
834
  *info = empty;
1047
834
}
1048
1049
static BOOL rdp_info_read_string(const char* what, wStream* s, size_t size, size_t max,
1050
                                 BOOL skipMax, char** dst)
1051
1.03k
{
1052
1.03k
  WINPR_ASSERT(dst);
1053
1.03k
  *dst = NULL;
1054
1055
1.03k
  if (size == 0)
1056
665
  {
1057
665
    if (skipMax)
1058
599
      return Stream_SafeSeek(s, max);
1059
66
    return TRUE;
1060
665
  }
1061
1062
368
  if (((size % sizeof(WCHAR)) != 0) || (size > max))
1063
315
  {
1064
315
    WLog_ERR(TAG, "protocol error: invalid %s value: %" PRIu32 "", what, size);
1065
315
    return FALSE;
1066
315
  }
1067
1068
53
  const WCHAR* str = Stream_ConstPointer(s);
1069
53
  if (!Stream_SafeSeek(s, skipMax ? max : size))
1070
2
    return FALSE;
1071
1072
51
  if (str[size / sizeof(WCHAR) - 1])
1073
2
  {
1074
2
    WLog_ERR(TAG, "protocol error: %s must be null terminated", what);
1075
2
    return FALSE;
1076
2
  }
1077
1078
49
  size_t len = 0;
1079
49
  char* rc = ConvertWCharNToUtf8Alloc(str, size / sizeof(WCHAR), &len);
1080
49
  if (!rc)
1081
1
  {
1082
1
    WLog_ERR(TAG, "failed to convert the %s string", what);
1083
1
    free(rc);
1084
1
    return FALSE;
1085
1
  }
1086
1087
48
  *dst = rc;
1088
48
  return TRUE;
1089
49
}
1090
1091
static BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s, logon_info* info)
1092
680
{
1093
680
  UINT32 cbDomain = 0;
1094
680
  UINT32 cbUserName = 0;
1095
1096
680
  WINPR_UNUSED(rdp);
1097
680
  WINPR_ASSERT(info);
1098
1099
680
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
1100
147
    return FALSE;
1101
1102
533
  Stream_Read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */
1103
1104
  /* cbDomain is the size of the Unicode character data (including the mandatory
1105
   * null terminator) in bytes present in the fixed-length (52 bytes) Domain field
1106
   */
1107
533
  if (!rdp_info_read_string("Domain", s, cbDomain, 52, TRUE, &info->domain))
1108
109
    goto fail;
1109
1110
424
  Stream_Read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */
1111
1112
  /* cbUserName is the size of the Unicode character data (including the mandatory
1113
   * null terminator) in bytes present in the fixed-length (512 bytes) UserName field.
1114
   */
1115
424
  if (!rdp_info_read_string("UserName", s, cbUserName, 512, TRUE, &info->username))
1116
202
    goto fail;
1117
1118
222
  Stream_Read_UINT32(s, info->sessionId); /* SessionId (4 bytes) */
1119
222
  WLog_DBG(TAG, "LogonInfoV1: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
1120
222
           info->sessionId, info->username, info->domain);
1121
222
  return TRUE;
1122
311
fail:
1123
311
  return FALSE;
1124
424
}
1125
1126
static BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s, logon_info* info)
1127
154
{
1128
154
  UINT16 Version = 0;
1129
154
  UINT32 Size = 0;
1130
154
  UINT32 cbDomain = 0;
1131
154
  UINT32 cbUserName = 0;
1132
1133
154
  WINPR_ASSERT(rdp);
1134
154
  WINPR_ASSERT(s);
1135
154
  WINPR_ASSERT(info);
1136
1137
154
  WINPR_UNUSED(rdp);
1138
1139
154
  if (!Stream_CheckAndLogRequiredLength(TAG, s, logonInfoV2TotalSize))
1140
20
    return FALSE;
1141
1142
134
  Stream_Read_UINT16(s, Version); /* Version (2 bytes) */
1143
134
  if (Version != SAVE_SESSION_PDU_VERSION_ONE)
1144
29
  {
1145
29
    WLog_WARN(TAG, "LogonInfoV2::Version expected %" PRIu16 " bytes, got %" PRIu16,
1146
29
              SAVE_SESSION_PDU_VERSION_ONE, Version);
1147
29
    return FALSE;
1148
29
  }
1149
1150
105
  Stream_Read_UINT32(s, Size); /* Size (4 bytes) */
1151
1152
  /* [MS-RDPBCGR] 2.2.10.1.1.2 Logon Info Version 2 (TS_LOGON_INFO_VERSION_2)
1153
   * should be logonInfoV2TotalSize
1154
   * but even MS server 2019 sends logonInfoV2Size
1155
   */
1156
105
  if (Size != logonInfoV2TotalSize)
1157
105
  {
1158
105
    if (Size != logonInfoV2Size)
1159
64
    {
1160
64
      WLog_WARN(TAG, "LogonInfoV2::Size expected %" PRIu32 " bytes, got %" PRIu32,
1161
64
                logonInfoV2TotalSize, Size);
1162
64
      return FALSE;
1163
64
    }
1164
105
  }
1165
1166
41
  Stream_Read_UINT32(s, info->sessionId);  /* SessionId (4 bytes) */
1167
41
  Stream_Read_UINT32(s, cbDomain);         /* cbDomain (4 bytes) */
1168
41
  Stream_Read_UINT32(s, cbUserName);       /* cbUserName (4 bytes) */
1169
41
  Stream_Seek(s, logonInfoV2ReservedSize); /* pad (558 bytes) */
1170
1171
  /* cbDomain is the size in bytes of the Unicode character data in the Domain field.
1172
   * The size of the mandatory null terminator is include in this value.
1173
   * Note: Since MS-RDPBCGR 2.2.10.1.1.2 does not mention any size limits we assume
1174
   *       that the maximum value is 52 bytes, according to the fixed size of the
1175
   *       Domain field in the Logon Info Version 1 (TS_LOGON_INFO) structure.
1176
   */
1177
41
  if (!rdp_info_read_string("Domain", s, cbDomain, 52, FALSE, &info->domain))
1178
6
    goto fail;
1179
1180
  /* cbUserName is the size in bytes of the Unicode character data in the UserName field.
1181
   * The size of the mandatory null terminator is include in this value.
1182
   * Note: Since MS-RDPBCGR 2.2.10.1.1.2 does not mention any size limits we assume
1183
   *       that the maximum value is 512 bytes, according to the fixed size of the
1184
   *       Username field in the Logon Info Version 1 (TS_LOGON_INFO) structure.
1185
   */
1186
35
  if (!rdp_info_read_string("UserName", s, cbUserName, 512, FALSE, &info->username))
1187
3
    goto fail;
1188
1189
  /* We´ve seen undocumented padding with windows 11 here.
1190
   * unless it has actual data in it ignore it.
1191
   * if there is unexpected data, print a warning and dump the contents
1192
   */
1193
32
  const size_t rem = Stream_GetRemainingLength(s);
1194
32
  if (rem > 0)
1195
31
  {
1196
31
    BOOL warn = FALSE;
1197
31
    const char* str = Stream_ConstPointer(s);
1198
1.80M
    for (size_t x = 0; x < rem; x++)
1199
1.80M
    {
1200
1.80M
      if (str[x] != '\0')
1201
1.50M
        warn = TRUE;
1202
1.80M
    }
1203
31
    if (warn)
1204
24
    {
1205
24
      WLog_WARN(TAG, "unexpected padding of %" PRIuz " bytes, data not '\0'", rem);
1206
24
      winpr_HexDump(TAG, WLOG_TRACE, str, rem);
1207
24
    }
1208
1209
31
    if (!Stream_SafeSeek(s, rem))
1210
0
      goto fail;
1211
31
  }
1212
1213
32
  WLog_DBG(TAG, "LogonInfoV2: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
1214
32
           info->sessionId, info->username, info->domain);
1215
32
  return TRUE;
1216
9
fail:
1217
9
  return FALSE;
1218
32
}
1219
1220
static BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s)
1221
14
{
1222
14
  WINPR_UNUSED(rdp);
1223
14
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
1224
4
    return FALSE;
1225
1226
10
  Stream_Seek(s, 576); /* pad (576 bytes) */
1227
10
  WLog_DBG(TAG, "LogonPlainNotify");
1228
10
  return TRUE;
1229
14
}
1230
1231
static BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s, logon_info_ex* info)
1232
119
{
1233
119
  freerdp* instance = NULL;
1234
119
  UINT32 errorNotificationType = 0;
1235
119
  UINT32 errorNotificationData = 0;
1236
1237
119
  WINPR_ASSERT(rdp);
1238
119
  WINPR_ASSERT(rdp->context);
1239
119
  WINPR_ASSERT(s);
1240
119
  WINPR_ASSERT(info);
1241
1242
119
  instance = rdp->context->instance;
1243
119
  WINPR_ASSERT(instance);
1244
1245
119
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1246
2
    return FALSE;
1247
1248
117
  Stream_Read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */
1249
117
  Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */
1250
117
  WLog_DBG(TAG, "LogonErrorInfo: Data: 0x%08" PRIX32 " Type: 0x%08" PRIX32 "",
1251
117
           errorNotificationData, errorNotificationType);
1252
117
  IFCALL(instance->LogonErrorInfo, instance, errorNotificationData, errorNotificationType);
1253
117
  info->ErrorNotificationType = errorNotificationType;
1254
117
  info->ErrorNotificationData = errorNotificationData;
1255
117
  return TRUE;
1256
119
}
1257
1258
static BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, wStream* s, logon_info_ex* info)
1259
287
{
1260
287
  UINT32 cbFieldData = 0;
1261
287
  UINT32 fieldsPresent = 0;
1262
287
  UINT16 Length = 0;
1263
1264
287
  WINPR_ASSERT(rdp);
1265
287
  WINPR_ASSERT(s);
1266
287
  WINPR_ASSERT(info);
1267
1268
287
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1269
2
  {
1270
2
    WLog_WARN(TAG, "received short logon info extended, need 6 bytes, got %" PRIuz,
1271
2
              Stream_GetRemainingLength(s));
1272
2
    return FALSE;
1273
2
  }
1274
1275
285
  Stream_Read_UINT16(s, Length);        /* Length (2 bytes) */
1276
285
  Stream_Read_UINT32(s, fieldsPresent); /* fieldsPresent (4 bytes) */
1277
1278
285
  if ((Length < 6) || (!Stream_CheckAndLogRequiredLength(TAG, s, (Length - 6U))))
1279
31
  {
1280
31
    WLog_WARN(TAG,
1281
31
              "received short logon info extended, need %" PRIu16 " - 6 bytes, got %" PRIuz,
1282
31
              Length, Stream_GetRemainingLength(s));
1283
31
    return FALSE;
1284
31
  }
1285
1286
254
  WLog_DBG(TAG, "LogonInfoExtended: fieldsPresent: 0x%08" PRIX32 "", fieldsPresent);
1287
1288
  /* logonFields */
1289
1290
254
  if (fieldsPresent & LOGON_EX_AUTORECONNECTCOOKIE)
1291
152
  {
1292
152
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1293
1
      return FALSE;
1294
1295
151
    info->haveCookie = TRUE;
1296
151
    Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
1297
1298
151
    if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
1299
37
      return FALSE;
1300
1301
114
    if (!rdp_read_server_auto_reconnect_cookie(rdp, s, info))
1302
64
      return FALSE;
1303
114
  }
1304
1305
152
  if (fieldsPresent & LOGON_EX_LOGONERRORS)
1306
136
  {
1307
136
    info->haveErrorInfo = TRUE;
1308
1309
136
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1310
1
      return FALSE;
1311
1312
135
    Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
1313
1314
135
    if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
1315
16
      return FALSE;
1316
1317
119
    if (!rdp_recv_logon_error_info(rdp, s, info))
1318
2
      return FALSE;
1319
119
  }
1320
1321
133
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 570))
1322
77
    return FALSE;
1323
1324
56
  Stream_Seek(s, 570); /* pad (570 bytes) */
1325
56
  return TRUE;
1326
133
}
1327
1328
BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s)
1329
9.78k
{
1330
9.78k
  UINT32 infoType = 0;
1331
9.78k
  BOOL status = 0;
1332
9.78k
  logon_info logonInfo = { 0 };
1333
9.78k
  logon_info_ex logonInfoEx = { 0 };
1334
9.78k
  rdpContext* context = rdp->context;
1335
9.78k
  rdpUpdate* update = rdp->context->update;
1336
1337
9.78k
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1338
5.94k
    return FALSE;
1339
1340
3.83k
  Stream_Read_UINT32(s, infoType); /* infoType (4 bytes) */
1341
1342
3.83k
  switch (infoType)
1343
3.83k
  {
1344
680
    case INFO_TYPE_LOGON:
1345
680
      status = rdp_recv_logon_info_v1(rdp, s, &logonInfo);
1346
1347
680
      if (status && update->SaveSessionInfo)
1348
0
        status = update->SaveSessionInfo(context, infoType, &logonInfo);
1349
1350
680
      rdp_free_logon_info(&logonInfo);
1351
680
      break;
1352
1353
154
    case INFO_TYPE_LOGON_LONG:
1354
154
      status = rdp_recv_logon_info_v2(rdp, s, &logonInfo);
1355
1356
154
      if (status && update->SaveSessionInfo)
1357
0
        status = update->SaveSessionInfo(context, infoType, &logonInfo);
1358
1359
154
      rdp_free_logon_info(&logonInfo);
1360
154
      break;
1361
1362
14
    case INFO_TYPE_LOGON_PLAIN_NOTIFY:
1363
14
      status = rdp_recv_logon_plain_notify(rdp, s);
1364
1365
14
      if (status && update->SaveSessionInfo)
1366
0
        status = update->SaveSessionInfo(context, infoType, NULL);
1367
1368
14
      break;
1369
1370
287
    case INFO_TYPE_LOGON_EXTENDED_INF:
1371
287
      status = rdp_recv_logon_info_extended(rdp, s, &logonInfoEx);
1372
1373
287
      if (status && update->SaveSessionInfo)
1374
0
        status = update->SaveSessionInfo(context, infoType, &logonInfoEx);
1375
1376
287
      break;
1377
1378
2.70k
    default:
1379
2.70k
      WLog_ERR(TAG, "Unhandled saveSessionInfo type 0x%" PRIx32 "", infoType);
1380
2.70k
      status = TRUE;
1381
2.70k
      break;
1382
3.83k
  }
1383
1384
3.83k
  if (!status)
1385
815
  {
1386
815
    WLog_DBG(TAG, "SaveSessionInfo error: infoType: %s (%" PRIu32 ")",
1387
815
             infoType < 4 ? INFO_TYPE_LOGON_STRINGS[infoType % 4] : "Unknown", infoType);
1388
815
  }
1389
1390
3.83k
  return status;
1391
3.83k
}
1392
1393
static BOOL rdp_write_logon_info_v1(wStream* s, logon_info* info)
1394
0
{
1395
0
  const size_t charLen = 52 / sizeof(WCHAR);
1396
0
  const size_t userCharLen = 512 / sizeof(WCHAR);
1397
1398
0
  size_t sz = 4 + 52 + 4 + 512 + 4;
1399
1400
0
  if (!Stream_EnsureRemainingCapacity(s, sz))
1401
0
    return FALSE;
1402
1403
  /* domain */
1404
0
  {
1405
0
    WINPR_ASSERT(info);
1406
0
    if (!info->domain || !info->username)
1407
0
      return FALSE;
1408
0
    const size_t len = strnlen(info->domain, charLen + 1);
1409
0
    if (len > charLen)
1410
0
      return FALSE;
1411
1412
0
    const size_t wlen = len * sizeof(WCHAR);
1413
0
    if (wlen > UINT32_MAX)
1414
0
      return FALSE;
1415
1416
0
    Stream_Write_UINT32(s, (UINT32)wlen);
1417
0
    if (Stream_Write_UTF16_String_From_UTF8(s, charLen, info->domain, len, TRUE) < 0)
1418
0
      return FALSE;
1419
0
  }
1420
1421
  /* username */
1422
0
  {
1423
0
    const size_t len = strnlen(info->username, userCharLen + 1);
1424
0
    if (len > userCharLen)
1425
0
      return FALSE;
1426
1427
0
    const size_t wlen = len * sizeof(WCHAR);
1428
0
    if (wlen > UINT32_MAX)
1429
0
      return FALSE;
1430
1431
0
    Stream_Write_UINT32(s, (UINT32)wlen);
1432
1433
0
    if (Stream_Write_UTF16_String_From_UTF8(s, userCharLen, info->username, len, TRUE) < 0)
1434
0
      return FALSE;
1435
0
  }
1436
1437
  /* sessionId */
1438
0
  Stream_Write_UINT32(s, info->sessionId);
1439
0
  return TRUE;
1440
0
}
1441
1442
static BOOL rdp_write_logon_info_v2(wStream* s, logon_info* info)
1443
0
{
1444
0
  size_t domainLen = 0;
1445
0
  size_t usernameLen = 0;
1446
1447
0
  if (!Stream_EnsureRemainingCapacity(s, logonInfoV2TotalSize))
1448
0
    return FALSE;
1449
1450
0
  Stream_Write_UINT16(s, SAVE_SESSION_PDU_VERSION_ONE);
1451
  /* [MS-RDPBCGR] 2.2.10.1.1.2 Logon Info Version 2 (TS_LOGON_INFO_VERSION_2)
1452
   * should be logonInfoV2TotalSize
1453
   * but even MS server 2019 sends logonInfoV2Size
1454
   */
1455
0
  Stream_Write_UINT32(s, logonInfoV2Size);
1456
0
  Stream_Write_UINT32(s, info->sessionId);
1457
0
  domainLen = strnlen(info->domain, 256); /* lmcons.h UNLEN */
1458
0
  if (domainLen >= UINT32_MAX / sizeof(WCHAR))
1459
0
    return FALSE;
1460
0
  Stream_Write_UINT32(s, (UINT32)(domainLen + 1) * sizeof(WCHAR));
1461
0
  usernameLen = strnlen(info->username, 256); /* lmcons.h UNLEN */
1462
0
  if (usernameLen >= UINT32_MAX / sizeof(WCHAR))
1463
0
    return FALSE;
1464
0
  Stream_Write_UINT32(s, (UINT32)(usernameLen + 1) * sizeof(WCHAR));
1465
0
  Stream_Seek(s, logonInfoV2ReservedSize);
1466
0
  if (Stream_Write_UTF16_String_From_UTF8(s, domainLen + 1, info->domain, domainLen, TRUE) < 0)
1467
0
    return FALSE;
1468
0
  if (Stream_Write_UTF16_String_From_UTF8(s, usernameLen + 1, info->username, usernameLen, TRUE) <
1469
0
      0)
1470
0
    return FALSE;
1471
0
  return TRUE;
1472
0
}
1473
1474
static BOOL rdp_write_logon_info_plain(wStream* s)
1475
0
{
1476
0
  if (!Stream_EnsureRemainingCapacity(s, 576))
1477
0
    return FALSE;
1478
1479
0
  Stream_Seek(s, 576);
1480
0
  return TRUE;
1481
0
}
1482
1483
static BOOL rdp_write_logon_info_ex(wStream* s, logon_info_ex* info)
1484
0
{
1485
0
  UINT32 FieldsPresent = 0;
1486
0
  UINT16 Size = 2 + 4 + 570;
1487
1488
0
  if (info->haveCookie)
1489
0
  {
1490
0
    FieldsPresent |= LOGON_EX_AUTORECONNECTCOOKIE;
1491
0
    Size += 28;
1492
0
  }
1493
1494
0
  if (info->haveErrorInfo)
1495
0
  {
1496
0
    FieldsPresent |= LOGON_EX_LOGONERRORS;
1497
0
    Size += 8;
1498
0
  }
1499
1500
0
  if (!Stream_EnsureRemainingCapacity(s, Size))
1501
0
    return FALSE;
1502
1503
0
  Stream_Write_UINT16(s, Size);
1504
0
  Stream_Write_UINT32(s, FieldsPresent);
1505
1506
0
  if (info->haveCookie)
1507
0
  {
1508
0
    Stream_Write_UINT32(s, 28);                       /* cbFieldData (4 bytes) */
1509
0
    Stream_Write_UINT32(s, 28);                       /* cbLen (4 bytes) */
1510
0
    Stream_Write_UINT32(s, AUTO_RECONNECT_VERSION_1); /* Version (4 bytes) */
1511
0
    Stream_Write_UINT32(s, info->LogonId);            /* LogonId (4 bytes) */
1512
0
    Stream_Write(s, info->ArcRandomBits, 16);         /* ArcRandomBits (16 bytes) */
1513
0
  }
1514
1515
0
  if (info->haveErrorInfo)
1516
0
  {
1517
0
    Stream_Write_UINT32(s, 8);                           /* cbFieldData (4 bytes) */
1518
0
    Stream_Write_UINT32(s, info->ErrorNotificationType); /* ErrorNotificationType (4 bytes) */
1519
0
    Stream_Write_UINT32(s, info->ErrorNotificationData); /* ErrorNotificationData (4 bytes) */
1520
0
  }
1521
1522
0
  Stream_Seek(s, 570);
1523
0
  return TRUE;
1524
0
}
1525
1526
BOOL rdp_send_save_session_info(rdpContext* context, UINT32 type, void* data)
1527
0
{
1528
0
  UINT16 sec_flags = 0;
1529
0
  wStream* s = NULL;
1530
0
  BOOL status = 0;
1531
0
  rdpRdp* rdp = context->rdp;
1532
0
  s = rdp_data_pdu_init(rdp, &sec_flags);
1533
1534
0
  if (!s)
1535
0
    return FALSE;
1536
1537
0
  Stream_Write_UINT32(s, type);
1538
1539
0
  switch (type)
1540
0
  {
1541
0
    case INFO_TYPE_LOGON:
1542
0
      status = rdp_write_logon_info_v1(s, (logon_info*)data);
1543
0
      break;
1544
1545
0
    case INFO_TYPE_LOGON_LONG:
1546
0
      status = rdp_write_logon_info_v2(s, (logon_info*)data);
1547
0
      break;
1548
1549
0
    case INFO_TYPE_LOGON_PLAIN_NOTIFY:
1550
0
      status = rdp_write_logon_info_plain(s);
1551
0
      break;
1552
1553
0
    case INFO_TYPE_LOGON_EXTENDED_INF:
1554
0
      status = rdp_write_logon_info_ex(s, (logon_info_ex*)data);
1555
0
      break;
1556
1557
0
    default:
1558
0
      WLog_ERR(TAG, "saveSessionInfo type 0x%" PRIx32 " not handled", type);
1559
0
      status = FALSE;
1560
0
      break;
1561
0
  }
1562
1563
0
  if (status)
1564
0
    status =
1565
0
        rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SAVE_SESSION_INFO, rdp->mcs->userId, sec_flags);
1566
0
  else
1567
0
    Stream_Release(s);
1568
1569
0
  return status;
1570
0
}
1571
1572
BOOL rdp_send_server_status_info(rdpContext* context, UINT32 status)
1573
0
{
1574
0
  UINT16 sec_flags = 0;
1575
0
  wStream* s = NULL;
1576
0
  rdpRdp* rdp = context->rdp;
1577
0
  s = rdp_data_pdu_init(rdp, &sec_flags);
1578
1579
0
  if (!s)
1580
0
    return FALSE;
1581
1582
0
  Stream_Write_UINT32(s, status);
1583
0
  return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_STATUS_INFO, rdp->mcs->userId, sec_flags);
1584
0
}