Coverage Report

Created: 2025-07-01 06:46

/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
0
#define TAG FREERDP_TAG("core.info")
39
40
0
#define logonInfoV2Size (2 + 4 + 4 + 4 + 4)
41
0
#define logonInfoV2ReservedSize 558
42
0
#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
0
{
81
0
  const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
82
83
0
  if (!freerdp_settings_set_string(settings, id, NULL))
84
0
    return FALSE;
85
86
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLen)))
87
0
    return FALSE;
88
89
0
  if (cbLen > 0)
90
0
  {
91
0
    if ((cbLen > max) || (unicode && ((cbLen % 2) != 0)))
92
0
    {
93
0
      WLog_ERR(TAG, "protocol error: %s has invalid value: %" PRIuz "", what, cbLen);
94
0
      return FALSE;
95
0
    }
96
97
0
    if (unicode)
98
0
    {
99
0
      const WCHAR* domain = Stream_PointerAs(s, WCHAR);
100
0
      if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
101
0
                                                   cbLen / sizeof(WCHAR)))
102
0
      {
103
0
        WLog_ERR(TAG, "protocol error: no data to read for %s [expected %" PRIuz "]", what,
104
0
                 cbLen);
105
0
        return FALSE;
106
0
      }
107
0
    }
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
0
  }
115
0
  Stream_Seek(s, cbLen);
116
117
0
  return TRUE;
118
0
}
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
0
{
181
0
  BYTE* p = NULL;
182
0
  ARC_SC_PRIVATE_PACKET* autoReconnectCookie = NULL;
183
0
  rdpSettings* settings = rdp->settings;
184
0
  autoReconnectCookie = settings->ServerAutoReconnectCookie;
185
186
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
187
0
    return FALSE;
188
189
0
  Stream_Read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
190
191
0
  if (autoReconnectCookie->cbLen != 28)
192
0
  {
193
0
    WLog_ERR(TAG, "ServerAutoReconnectCookie.cbLen != 28");
194
0
    return FALSE;
195
0
  }
196
197
0
  Stream_Read_UINT32(s, autoReconnectCookie->version);    /* Version (4 bytes) */
198
0
  Stream_Read_UINT32(s, autoReconnectCookie->logonId);    /* LogonId (4 bytes) */
199
0
  Stream_Read(s, autoReconnectCookie->arcRandomBits, 16); /* ArcRandomBits (16 bytes) */
200
0
  p = autoReconnectCookie->arcRandomBits;
201
0
  WLog_DBG(TAG,
202
0
           "ServerAutoReconnectCookie: Version: %" PRIu32 " LogonId: %" PRIu32
203
0
           " SecurityVerifier: "
204
0
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
205
0
           "%02" PRIX8 ""
206
0
           "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8
207
0
           "%02" PRIX8 "",
208
0
           autoReconnectCookie->version, autoReconnectCookie->logonId, p[0], p[1], p[2], p[3],
209
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]);
210
0
  info->LogonId = autoReconnectCookie->logonId;
211
0
  CopyMemory(info->ArcRandomBits, p, 16);
212
213
0
  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
0
  return TRUE;
222
0
}
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
0
{
231
0
  ARC_CS_PRIVATE_PACKET* autoReconnectCookie = NULL;
232
0
  rdpSettings* settings = rdp->settings;
233
0
  autoReconnectCookie = settings->ClientAutoReconnectCookie;
234
235
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 28))
236
0
    return FALSE;
237
238
0
  Stream_Read_UINT32(s, autoReconnectCookie->cbLen);         /* cbLen (4 bytes) */
239
0
  Stream_Read_UINT32(s, autoReconnectCookie->version);       /* version (4 bytes) */
240
0
  Stream_Read_UINT32(s, autoReconnectCookie->logonId);       /* LogonId (4 bytes) */
241
0
  Stream_Read(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
242
0
  return TRUE;
243
0
}
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
0
{
291
0
  UINT32 version = 0;
292
0
  rdpSettings* settings = NULL;
293
294
0
  WINPR_ASSERT(rdp);
295
296
0
  settings = rdp->settings;
297
0
  WINPR_ASSERT(settings);
298
299
0
  version = freerdp_settings_get_uint32(settings, FreeRDP_RdpVersion);
300
0
  if (version < RDP_VERSION_10_0)
301
0
    return 64;
302
0
  return 80;
303
0
}
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
0
{
312
0
  UINT16 clientAddressFamily = 0;
313
0
  UINT16 cbClientAddress = 0;
314
0
  UINT16 cbClientDir = 0;
315
0
  UINT16 cbAutoReconnectLen = 0;
316
317
0
  WINPR_ASSERT(rdp);
318
319
0
  rdpSettings* settings = rdp->settings;
320
0
  WINPR_ASSERT(settings);
321
322
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
323
0
    return FALSE;
324
325
0
  Stream_Read_UINT16(s, clientAddressFamily); /* clientAddressFamily (2 bytes) */
326
0
  Stream_Read_UINT16(s, cbClientAddress);     /* cbClientAddress (2 bytes) */
327
328
0
  settings->IPv6Enabled = (clientAddressFamily == ADDRESS_FAMILY_INET6 ? TRUE : FALSE);
329
330
0
  if (!rdp_read_info_null_string(settings, FreeRDP_ClientAddress, "cbClientAddress", INFO_UNICODE,
331
0
                                 s, cbClientAddress, rdp_get_client_address_max_size(rdp)))
332
0
    return FALSE;
333
334
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
335
0
    return FALSE;
336
337
0
  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
0
  if (!rdp_read_info_null_string(settings, FreeRDP_ClientDir, "cbClientDir", INFO_UNICODE, s,
348
0
                                 cbClientDir, 512))
349
0
    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
0
  if (Stream_GetRemainingLength(s) == 0)
358
0
    goto end;
359
360
0
  if (!rdp_read_client_time_zone(s, settings))
361
0
    return FALSE;
362
363
  /* optional: clientSessionId (4 bytes), should be set to 0 */
364
0
  if (Stream_GetRemainingLength(s) == 0)
365
0
    goto end;
366
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
367
0
    return FALSE;
368
369
0
  Stream_Read_UINT32(s, settings->ClientSessionId);
370
371
  /* optional: performanceFlags (4 bytes) */
372
0
  if (Stream_GetRemainingLength(s) == 0)
373
0
    goto end;
374
375
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
376
0
    return FALSE;
377
378
0
  Stream_Read_UINT32(s, settings->PerformanceFlags);
379
0
  freerdp_performance_flags_split(settings);
380
381
  /* optional: cbAutoReconnectLen (2 bytes) */
382
0
  if (Stream_GetRemainingLength(s) == 0)
383
0
    goto end;
384
385
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
386
0
    return FALSE;
387
388
0
  Stream_Read_UINT16(s, cbAutoReconnectLen);
389
390
  /* optional: autoReconnectCookie (28 bytes) */
391
  /* must be present if cbAutoReconnectLen is > 0 */
392
0
  if (cbAutoReconnectLen > 0)
393
0
  {
394
0
    if (!rdp_read_client_auto_reconnect_cookie(rdp, s))
395
0
      return FALSE;
396
0
  }
397
398
  /* skip reserved1 and reserved2 fields */
399
0
  if (Stream_GetRemainingLength(s) == 0)
400
0
    goto end;
401
402
0
  if (!Stream_SafeSeek(s, 2))
403
0
    return FALSE;
404
405
0
  if (Stream_GetRemainingLength(s) == 0)
406
0
    goto end;
407
408
0
  if (!Stream_SafeSeek(s, 2))
409
0
    return FALSE;
410
411
0
  if (Stream_GetRemainingLength(s) == 0)
412
0
    goto end;
413
414
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
415
0
    return FALSE;
416
417
0
  if (freerdp_settings_get_bool(settings, FreeRDP_SupportDynamicTimeZone))
418
0
  {
419
0
    UINT16 cbDynamicDSTTimeZoneKeyName = 0;
420
421
0
    Stream_Read_UINT16(s, cbDynamicDSTTimeZoneKeyName);
422
423
0
    if (!rdp_read_info_null_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName,
424
0
                                   "cbDynamicDSTTimeZoneKeyName", INFO_UNICODE, s,
425
0
                                   cbDynamicDSTTimeZoneKeyName, 254))
426
0
      return FALSE;
427
428
0
    if (Stream_GetRemainingLength(s) == 0)
429
0
      goto end;
430
431
0
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
432
0
      return FALSE;
433
0
    UINT16 DynamicDaylightTimeDisabled = 0;
434
0
    Stream_Read_UINT16(s, DynamicDaylightTimeDisabled);
435
0
    if (DynamicDaylightTimeDisabled > 1)
436
0
    {
437
0
      WLog_WARN(TAG,
438
0
                "[MS-RDPBCGR] 2.2.1.11.1.1.1 Extended Info Packet "
439
0
                "(TS_EXTENDED_INFO_PACKET)::dynamicDaylightTimeDisabled value %" PRIu16
440
0
                " not allowed in [0,1]",
441
0
                settings->DynamicDaylightTimeDisabled);
442
0
      return FALSE;
443
0
    }
444
0
    if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicDaylightTimeDisabled,
445
0
                                   DynamicDaylightTimeDisabled != 0))
446
0
      return FALSE;
447
0
    DEBUG_TIMEZONE("DynamicTimeZone=%s [%s]",
448
0
                   freerdp_settings_get_string(settings, FreeRDP_DynamicDSTTimeZoneKeyName),
449
0
                   freerdp_settings_get_bool(settings, FreeRDP_DynamicDaylightTimeDisabled)
450
0
                       ? "no-DST"
451
0
                       : "DST");
452
0
  }
453
454
0
end:
455
0
  return TRUE;
456
0
}
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
0
{
596
0
  union
597
0
  {
598
0
    char c;
599
0
    WCHAR w;
600
0
    BYTE b[2];
601
0
  } terminator;
602
603
0
  const BOOL unicode = (flags & INFO_UNICODE) ? TRUE : FALSE;
604
0
  const size_t nullSize = unicode ? sizeof(WCHAR) : sizeof(CHAR);
605
606
0
  if (!freerdp_settings_set_string(settings, id, NULL))
607
0
    return FALSE;
608
609
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)(cbLenNonNull + nullSize)))
610
0
    return FALSE;
611
612
0
  if (cbLenNonNull > 0)
613
0
  {
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
0
    if ((cbLenNonNull % 2) || (cbLenNonNull > (max - nullSize)))
619
0
    {
620
0
      WLog_ERR(TAG, "protocol error: invalid value: %" PRIuz "", cbLenNonNull);
621
0
      return FALSE;
622
0
    }
623
624
0
    if (unicode)
625
0
    {
626
0
      const WCHAR* domain = Stream_PointerAs(s, WCHAR);
627
0
      if (!freerdp_settings_set_string_from_utf16N(settings, id, domain,
628
0
                                                   cbLenNonNull / sizeof(WCHAR)))
629
0
        return FALSE;
630
0
    }
631
0
    else
632
0
    {
633
0
      const char* domain = Stream_PointerAs(s, char);
634
0
      if (!freerdp_settings_set_string_len(settings, id, domain, cbLenNonNull))
635
0
        return FALSE;
636
0
    }
637
0
  }
638
639
0
  Stream_Seek(s, cbLenNonNull);
640
641
0
  terminator.w = L'\0';
642
0
  Stream_Read(s, terminator.b, nullSize);
643
644
0
  if (terminator.w != L'\0')
645
0
  {
646
0
    WLog_ERR(TAG, "protocol error: Domain must be null terminated");
647
0
    (void)freerdp_settings_set_string(settings, id, NULL);
648
0
    return FALSE;
649
0
  }
650
651
0
  return TRUE;
652
0
}
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
0
{
661
0
  BOOL smallsize = FALSE;
662
0
  UINT32 flags = 0;
663
0
  UINT16 cbDomain = 0;
664
0
  UINT16 cbUserName = 0;
665
0
  UINT16 cbPassword = 0;
666
0
  UINT16 cbAlternateShell = 0;
667
0
  UINT16 cbWorkingDir = 0;
668
0
  UINT32 CompressionLevel = 0;
669
0
  rdpSettings* settings = rdp->settings;
670
671
0
  if (!Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, 18))
672
0
    return FALSE;
673
674
0
  Stream_Read_UINT32(s, settings->KeyboardCodePage); /* CodePage (4 bytes ) */
675
0
  Stream_Read_UINT32(s, flags);                      /* flags (4 bytes) */
676
0
  settings->AudioCapture = ((flags & INFO_AUDIOCAPTURE) ? TRUE : FALSE);
677
0
  settings->AudioPlayback = ((flags & INFO_NOAUDIOPLAYBACK) ? FALSE : TRUE);
678
0
  settings->AutoLogonEnabled = ((flags & INFO_AUTOLOGON) ? TRUE : FALSE);
679
0
  settings->RemoteApplicationMode = ((flags & INFO_RAIL) ? TRUE : FALSE);
680
0
  settings->HiDefRemoteApp = ((flags & INFO_HIDEF_RAIL_SUPPORTED) ? TRUE : FALSE);
681
0
  settings->RemoteConsoleAudio = ((flags & INFO_REMOTECONSOLEAUDIO) ? TRUE : FALSE);
682
0
  settings->CompressionEnabled = ((flags & INFO_COMPRESSION) ? TRUE : FALSE);
683
0
  settings->LogonNotify = ((flags & INFO_LOGONNOTIFY) ? TRUE : FALSE);
684
0
  settings->MouseHasWheel = ((flags & INFO_MOUSE_HAS_WHEEL) ? TRUE : FALSE);
685
0
  settings->DisableCtrlAltDel = ((flags & INFO_DISABLECTRLALTDEL) ? TRUE : FALSE);
686
0
  settings->ForceEncryptedCsPdu = ((flags & INFO_FORCE_ENCRYPTED_CS_PDU) ? TRUE : FALSE);
687
0
  settings->PasswordIsSmartcardPin = ((flags & INFO_PASSWORD_IS_SC_PIN) ? TRUE : FALSE);
688
689
0
  if (flags & INFO_COMPRESSION)
690
0
  {
691
0
    CompressionLevel = ((flags & 0x00001E00) >> 9);
692
0
    settings->CompressionLevel = CompressionLevel;
693
0
  }
694
0
  else
695
0
  {
696
0
    settings->CompressionLevel = 0;
697
0
  }
698
699
  /* RDP 4 and 5 have smaller credential limits */
700
0
  if (settings->RdpVersion < RDP_VERSION_5_PLUS)
701
0
    smallsize = TRUE;
702
703
0
  Stream_Read_UINT16(s, cbDomain);         /* cbDomain (2 bytes) */
704
0
  Stream_Read_UINT16(s, cbUserName);       /* cbUserName (2 bytes) */
705
0
  Stream_Read_UINT16(s, cbPassword);       /* cbPassword (2 bytes) */
706
0
  Stream_Read_UINT16(s, cbAlternateShell); /* cbAlternateShell (2 bytes) */
707
0
  Stream_Read_UINT16(s, cbWorkingDir);     /* cbWorkingDir (2 bytes) */
708
709
0
  if (!rdp_read_info_string(settings, FreeRDP_Domain, flags, s, cbDomain, smallsize ? 52 : 512))
710
0
    return FALSE;
711
712
0
  if (!rdp_read_info_string(settings, FreeRDP_Username, flags, s, cbUserName,
713
0
                            smallsize ? 44 : 512))
714
0
    return FALSE;
715
716
0
  if (!rdp_read_info_string(settings, FreeRDP_Password, flags, s, cbPassword,
717
0
                            smallsize ? 32 : 512))
718
0
    return FALSE;
719
720
0
  if (!rdp_read_info_string(settings, FreeRDP_AlternateShell, flags, s, cbAlternateShell, 512))
721
0
    return FALSE;
722
723
0
  if (!rdp_read_info_string(settings, FreeRDP_ShellWorkingDirectory, flags, s, cbWorkingDir, 512))
724
0
    return FALSE;
725
726
0
  if (settings->RdpVersion >= RDP_VERSION_5_PLUS)
727
0
  {
728
0
    if (!rdp_read_extended_info_packet(rdp, s)) /* extraInfo */
729
0
      return FALSE;
730
0
  }
731
732
0
  const size_t xrem = Stream_GetRemainingLength(s);
733
0
  if (!tpkt_ensure_stream_consumed(rdp->log, s, tpktlength))
734
0
    Stream_Seek(s, xrem);
735
0
  return TRUE;
736
0
}
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
0
{
978
0
  UINT16 length = 0;
979
0
  UINT16 channelId = 0;
980
0
  UINT16 securityFlags = 0;
981
982
0
  WINPR_ASSERT(rdp_get_state(rdp) == CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE);
983
984
0
  if (!rdp_read_header(rdp, s, &length, &channelId))
985
0
    return FALSE;
986
987
0
  if (!rdp_read_security_header(rdp, s, &securityFlags, &length))
988
0
    return FALSE;
989
990
0
  if ((securityFlags & SEC_INFO_PKT) == 0)
991
0
    return FALSE;
992
993
0
  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
0
  return rdp_read_info_packet(rdp, s, length);
1009
0
}
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
0
{
1040
0
  if (!info)
1041
0
    return;
1042
0
  free(info->domain);
1043
0
  free(info->username);
1044
1045
0
  const logon_info empty = { 0 };
1046
0
  *info = empty;
1047
0
}
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
0
{
1052
0
  WINPR_ASSERT(dst);
1053
0
  *dst = NULL;
1054
1055
0
  if (size == 0)
1056
0
  {
1057
0
    if (skipMax)
1058
0
      return Stream_SafeSeek(s, max);
1059
0
    return TRUE;
1060
0
  }
1061
1062
0
  if (((size % sizeof(WCHAR)) != 0) || (size > max))
1063
0
  {
1064
0
    WLog_ERR(TAG, "protocol error: invalid %s value: %" PRIu32 "", what, size);
1065
0
    return FALSE;
1066
0
  }
1067
1068
0
  const WCHAR* str = Stream_ConstPointer(s);
1069
0
  if (!Stream_SafeSeek(s, skipMax ? max : size))
1070
0
    return FALSE;
1071
1072
0
  if (str[size / sizeof(WCHAR) - 1])
1073
0
  {
1074
0
    WLog_ERR(TAG, "protocol error: %s must be null terminated", what);
1075
0
    return FALSE;
1076
0
  }
1077
1078
0
  size_t len = 0;
1079
0
  char* rc = ConvertWCharNToUtf8Alloc(str, size / sizeof(WCHAR), &len);
1080
0
  if (!rc)
1081
0
  {
1082
0
    WLog_ERR(TAG, "failed to convert the %s string", what);
1083
0
    free(rc);
1084
0
    return FALSE;
1085
0
  }
1086
1087
0
  *dst = rc;
1088
0
  return TRUE;
1089
0
}
1090
1091
static BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s, logon_info* info)
1092
0
{
1093
0
  UINT32 cbDomain = 0;
1094
0
  UINT32 cbUserName = 0;
1095
1096
0
  WINPR_UNUSED(rdp);
1097
0
  WINPR_ASSERT(info);
1098
1099
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
1100
0
    return FALSE;
1101
1102
0
  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
0
  if (!rdp_info_read_string("Domain", s, cbDomain, 52, TRUE, &info->domain))
1108
0
    goto fail;
1109
1110
0
  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
0
  if (!rdp_info_read_string("UserName", s, cbUserName, 512, TRUE, &info->username))
1116
0
    goto fail;
1117
1118
0
  Stream_Read_UINT32(s, info->sessionId); /* SessionId (4 bytes) */
1119
0
  WLog_DBG(TAG, "LogonInfoV1: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
1120
0
           info->sessionId, info->username, info->domain);
1121
0
  return TRUE;
1122
0
fail:
1123
0
  return FALSE;
1124
0
}
1125
1126
static BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s, logon_info* info)
1127
0
{
1128
0
  UINT16 Version = 0;
1129
0
  UINT32 Size = 0;
1130
0
  UINT32 cbDomain = 0;
1131
0
  UINT32 cbUserName = 0;
1132
1133
0
  WINPR_ASSERT(rdp);
1134
0
  WINPR_ASSERT(s);
1135
0
  WINPR_ASSERT(info);
1136
1137
0
  WINPR_UNUSED(rdp);
1138
1139
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, logonInfoV2TotalSize))
1140
0
    return FALSE;
1141
1142
0
  Stream_Read_UINT16(s, Version); /* Version (2 bytes) */
1143
0
  if (Version != SAVE_SESSION_PDU_VERSION_ONE)
1144
0
  {
1145
0
    WLog_WARN(TAG, "LogonInfoV2::Version expected %" PRIu16 " bytes, got %" PRIu16,
1146
0
              SAVE_SESSION_PDU_VERSION_ONE, Version);
1147
0
    return FALSE;
1148
0
  }
1149
1150
0
  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
0
  if (Size != logonInfoV2TotalSize)
1157
0
  {
1158
0
    if (Size != logonInfoV2Size)
1159
0
    {
1160
0
      WLog_WARN(TAG, "LogonInfoV2::Size expected %" PRIu32 " bytes, got %" PRIu32,
1161
0
                logonInfoV2TotalSize, Size);
1162
0
      return FALSE;
1163
0
    }
1164
0
  }
1165
1166
0
  Stream_Read_UINT32(s, info->sessionId);  /* SessionId (4 bytes) */
1167
0
  Stream_Read_UINT32(s, cbDomain);         /* cbDomain (4 bytes) */
1168
0
  Stream_Read_UINT32(s, cbUserName);       /* cbUserName (4 bytes) */
1169
0
  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
0
  if (!rdp_info_read_string("Domain", s, cbDomain, 52, FALSE, &info->domain))
1178
0
    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
0
  if (!rdp_info_read_string("UserName", s, cbUserName, 512, FALSE, &info->username))
1187
0
    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
0
  const size_t rem = Stream_GetRemainingLength(s);
1194
0
  if (rem > 0)
1195
0
  {
1196
0
    BOOL warn = FALSE;
1197
0
    const char* str = Stream_ConstPointer(s);
1198
0
    for (size_t x = 0; x < rem; x++)
1199
0
    {
1200
0
      if (str[x] != '\0')
1201
0
        warn = TRUE;
1202
0
    }
1203
0
    if (warn)
1204
0
    {
1205
0
      WLog_WARN(TAG, "unexpected padding of %" PRIuz " bytes, data not '\0'", rem);
1206
0
      winpr_HexDump(TAG, WLOG_TRACE, str, rem);
1207
0
    }
1208
1209
0
    if (!Stream_SafeSeek(s, rem))
1210
0
      goto fail;
1211
0
  }
1212
1213
0
  WLog_DBG(TAG, "LogonInfoV2: SessionId: 0x%08" PRIX32 " UserName: [%s] Domain: [%s]",
1214
0
           info->sessionId, info->username, info->domain);
1215
0
  return TRUE;
1216
0
fail:
1217
0
  return FALSE;
1218
0
}
1219
1220
static BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s)
1221
0
{
1222
0
  WINPR_UNUSED(rdp);
1223
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 576))
1224
0
    return FALSE;
1225
1226
0
  Stream_Seek(s, 576); /* pad (576 bytes) */
1227
0
  WLog_DBG(TAG, "LogonPlainNotify");
1228
0
  return TRUE;
1229
0
}
1230
1231
static BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s, logon_info_ex* info)
1232
0
{
1233
0
  freerdp* instance = NULL;
1234
0
  UINT32 errorNotificationType = 0;
1235
0
  UINT32 errorNotificationData = 0;
1236
1237
0
  WINPR_ASSERT(rdp);
1238
0
  WINPR_ASSERT(rdp->context);
1239
0
  WINPR_ASSERT(s);
1240
0
  WINPR_ASSERT(info);
1241
1242
0
  instance = rdp->context->instance;
1243
0
  WINPR_ASSERT(instance);
1244
1245
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1246
0
    return FALSE;
1247
1248
0
  Stream_Read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */
1249
0
  Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */
1250
0
  WLog_DBG(TAG, "LogonErrorInfo: Data: 0x%08" PRIX32 " Type: 0x%08" PRIX32 "",
1251
0
           errorNotificationData, errorNotificationType);
1252
0
  IFCALL(instance->LogonErrorInfo, instance, errorNotificationData, errorNotificationType);
1253
0
  info->ErrorNotificationType = errorNotificationType;
1254
0
  info->ErrorNotificationData = errorNotificationData;
1255
0
  return TRUE;
1256
0
}
1257
1258
static BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, wStream* s, logon_info_ex* info)
1259
0
{
1260
0
  UINT32 cbFieldData = 0;
1261
0
  UINT32 fieldsPresent = 0;
1262
0
  UINT16 Length = 0;
1263
1264
0
  WINPR_ASSERT(rdp);
1265
0
  WINPR_ASSERT(s);
1266
0
  WINPR_ASSERT(info);
1267
1268
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
1269
0
  {
1270
0
    WLog_WARN(TAG, "received short logon info extended, need 6 bytes, got %" PRIuz,
1271
0
              Stream_GetRemainingLength(s));
1272
0
    return FALSE;
1273
0
  }
1274
1275
0
  Stream_Read_UINT16(s, Length);        /* Length (2 bytes) */
1276
0
  Stream_Read_UINT32(s, fieldsPresent); /* fieldsPresent (4 bytes) */
1277
1278
0
  if ((Length < 6) || (!Stream_CheckAndLogRequiredLength(TAG, s, (Length - 6U))))
1279
0
  {
1280
0
    WLog_WARN(TAG,
1281
0
              "received short logon info extended, need %" PRIu16 " - 6 bytes, got %" PRIuz,
1282
0
              Length, Stream_GetRemainingLength(s));
1283
0
    return FALSE;
1284
0
  }
1285
1286
0
  WLog_DBG(TAG, "LogonInfoExtended: fieldsPresent: 0x%08" PRIX32 "", fieldsPresent);
1287
1288
  /* logonFields */
1289
1290
0
  if (fieldsPresent & LOGON_EX_AUTORECONNECTCOOKIE)
1291
0
  {
1292
0
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1293
0
      return FALSE;
1294
1295
0
    info->haveCookie = TRUE;
1296
0
    Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
1297
1298
0
    if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
1299
0
      return FALSE;
1300
1301
0
    if (!rdp_read_server_auto_reconnect_cookie(rdp, s, info))
1302
0
      return FALSE;
1303
0
  }
1304
1305
0
  if (fieldsPresent & LOGON_EX_LOGONERRORS)
1306
0
  {
1307
0
    info->haveErrorInfo = TRUE;
1308
1309
0
    if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1310
0
      return FALSE;
1311
1312
0
    Stream_Read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
1313
1314
0
    if (!Stream_CheckAndLogRequiredLength(TAG, s, cbFieldData))
1315
0
      return FALSE;
1316
1317
0
    if (!rdp_recv_logon_error_info(rdp, s, info))
1318
0
      return FALSE;
1319
0
  }
1320
1321
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 570))
1322
0
    return FALSE;
1323
1324
0
  Stream_Seek(s, 570); /* pad (570 bytes) */
1325
0
  return TRUE;
1326
0
}
1327
1328
BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s)
1329
0
{
1330
0
  UINT32 infoType = 0;
1331
0
  BOOL status = 0;
1332
0
  logon_info logonInfo = { 0 };
1333
0
  logon_info_ex logonInfoEx = { 0 };
1334
0
  rdpContext* context = rdp->context;
1335
0
  rdpUpdate* update = rdp->context->update;
1336
1337
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
1338
0
    return FALSE;
1339
1340
0
  Stream_Read_UINT32(s, infoType); /* infoType (4 bytes) */
1341
1342
0
  switch (infoType)
1343
0
  {
1344
0
    case INFO_TYPE_LOGON:
1345
0
      status = rdp_recv_logon_info_v1(rdp, s, &logonInfo);
1346
1347
0
      if (status && update->SaveSessionInfo)
1348
0
        status = update->SaveSessionInfo(context, infoType, &logonInfo);
1349
1350
0
      rdp_free_logon_info(&logonInfo);
1351
0
      break;
1352
1353
0
    case INFO_TYPE_LOGON_LONG:
1354
0
      status = rdp_recv_logon_info_v2(rdp, s, &logonInfo);
1355
1356
0
      if (status && update->SaveSessionInfo)
1357
0
        status = update->SaveSessionInfo(context, infoType, &logonInfo);
1358
1359
0
      rdp_free_logon_info(&logonInfo);
1360
0
      break;
1361
1362
0
    case INFO_TYPE_LOGON_PLAIN_NOTIFY:
1363
0
      status = rdp_recv_logon_plain_notify(rdp, s);
1364
1365
0
      if (status && update->SaveSessionInfo)
1366
0
        status = update->SaveSessionInfo(context, infoType, NULL);
1367
1368
0
      break;
1369
1370
0
    case INFO_TYPE_LOGON_EXTENDED_INF:
1371
0
      status = rdp_recv_logon_info_extended(rdp, s, &logonInfoEx);
1372
1373
0
      if (status && update->SaveSessionInfo)
1374
0
        status = update->SaveSessionInfo(context, infoType, &logonInfoEx);
1375
1376
0
      break;
1377
1378
0
    default:
1379
0
      WLog_ERR(TAG, "Unhandled saveSessionInfo type 0x%" PRIx32 "", infoType);
1380
0
      status = TRUE;
1381
0
      break;
1382
0
  }
1383
1384
0
  if (!status)
1385
0
  {
1386
0
    WLog_DBG(TAG, "SaveSessionInfo error: infoType: %s (%" PRIu32 ")",
1387
0
             infoType < 4 ? INFO_TYPE_LOGON_STRINGS[infoType % 4] : "Unknown", infoType);
1388
0
  }
1389
1390
0
  return status;
1391
0
}
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
}