Coverage Report

Created: 2026-11-10 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/libfreerdp/core/settings.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * RDP Settings
4
 *
5
 * Copyright 2009-2011 Jay Sorg
6
 * Copyright 2023 Armin Novak <anovak@thincast.com>
7
 * Copyright 2023 Thincast Technologies GmbH
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 <freerdp/crypto/certificate.h>
27
28
#include <ctype.h>
29
30
#include <winpr/crt.h>
31
#include <winpr/file.h>
32
#include <winpr/path.h>
33
#include <winpr/sysinfo.h>
34
#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
35
#include <winpr/registry.h>
36
#endif
37
#include <winpr/wtsapi.h>
38
#include <winpr/input.h>
39
40
#include <freerdp/version.h>
41
#include <freerdp/settings.h>
42
#include <freerdp/utils/string.h>
43
#include <freerdp/utils/helpers.h>
44
#include <freerdp/build-config.h>
45
46
#include "../core/utils.h"
47
#include "../crypto/certificate.h"
48
#include "../crypto/privatekey.h"
49
#include "capabilities.h"
50
51
0
#define TAG FREERDP_TAG("settings")
52
53
#ifdef _MSC_VER
54
#pragma warning(push)
55
#pragma warning(disable : 4244)
56
#endif
57
58
static const char client_dll[] = "C:\\Windows\\System32\\mstscax.dll";
59
60
#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
61
24.7k
#define SERVER_KEY "Software\\%s\\Server"
62
326k
#define CLIENT_KEY "Software\\%s\\Client"
63
81.6k
#define BITMAP_CACHE_KEY CLIENT_KEY "\\BitmapCacheV2"
64
81.6k
#define GLYPH_CACHE_KEY CLIENT_KEY "\\GlyphCache"
65
81.6k
#define POINTER_CACHE_KEY CLIENT_KEY "\\PointerCache"
66
#endif
67
68
struct bounds_t
69
{
70
  INT32 x;
71
  INT32 y;
72
  INT32 width;
73
  INT32 height;
74
};
75
76
static const char* bounds2str(const struct bounds_t* bounds, char* buffer, size_t len)
77
0
{
78
0
  WINPR_ASSERT(bounds);
79
0
  (void)_snprintf(buffer, len, "{%dx%d-%dx%d}", bounds->x, bounds->y, bounds->x + bounds->width,
80
0
                  bounds->y + bounds->height);
81
0
  return buffer;
82
0
}
83
84
static struct bounds_t union_rect(const struct bounds_t* a, const struct bounds_t* b)
85
0
{
86
0
  WINPR_ASSERT(a);
87
0
  WINPR_ASSERT(b);
88
89
0
  struct bounds_t u = *a;
90
0
  if (b->x < u.x)
91
0
    u.x = b->x;
92
0
  if (b->y < u.y)
93
0
    u.y = b->y;
94
95
0
  const INT32 rightA = a->x + a->width;
96
0
  const INT32 rightB = b->x + b->width;
97
0
  const INT32 right = MAX(rightA, rightB);
98
0
  u.width = right - u.x;
99
100
0
  const INT32 bottomA = a->y + a->height;
101
0
  const INT32 bottomB = b->y + b->height;
102
0
  const INT32 bottom = MAX(bottomA, bottomB);
103
0
  u.height = bottom - u.y;
104
105
0
  return u;
106
0
}
107
108
static BOOL intersect_rects(const struct bounds_t* r1, const struct bounds_t* r2)
109
0
{
110
0
  WINPR_ASSERT(r1);
111
0
  WINPR_ASSERT(r2);
112
113
0
  const INT32 left = MAX(r1->x, r2->x);
114
0
  const INT32 top = MAX(r1->y, r2->y);
115
0
  const INT32 right = MIN(r1->x + r1->width, r2->x + r2->width);
116
0
  const INT32 bottom = MIN(r1->y + r1->height, r2->y + r2->height);
117
118
0
  return (left < right) && (top < bottom);
119
0
}
120
121
static BOOL align_rects(const struct bounds_t* r1, const struct bounds_t* r2)
122
0
{
123
0
  WINPR_ASSERT(r1);
124
0
  WINPR_ASSERT(r2);
125
126
0
  const INT32 left = MAX(r1->x, r2->x);
127
0
  const INT32 top = MAX(r1->y, r2->y);
128
0
  const INT32 right = MIN(r1->x + r1->width, r2->x + r2->width);
129
0
  const INT32 bottom = MIN(r1->y + r1->height, r2->y + r2->height);
130
131
0
  return (left == right) || (top == bottom);
132
0
}
133
134
#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
135
static BOOL settings_reg_query_dword_val(HKEY hKey, const TCHAR* sub, DWORD* value)
136
0
{
137
0
  DWORD dwType = 0;
138
0
  DWORD dwSize = 0;
139
140
0
  dwSize = sizeof(DWORD);
141
0
  if (RegQueryValueEx(hKey, sub, nullptr, &dwType, (BYTE*)value, &dwSize) != ERROR_SUCCESS)
142
0
    return FALSE;
143
0
  if (dwType != REG_DWORD)
144
0
    return FALSE;
145
146
0
  return TRUE;
147
0
}
148
149
static BOOL settings_reg_query_word_val(HKEY hKey, const TCHAR* sub, UINT16* value)
150
0
{
151
0
  DWORD dwValue = 0;
152
153
0
  if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
154
0
    return FALSE;
155
156
0
  if (dwValue > UINT16_MAX)
157
0
    return FALSE;
158
159
0
  *value = (UINT16)dwValue;
160
0
  return TRUE;
161
0
}
162
163
static BOOL settings_reg_query_bool_val(HKEY hKey, const TCHAR* sub, BOOL* value)
164
0
{
165
0
  DWORD dwValue = 0;
166
167
0
  if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
168
0
    return FALSE;
169
0
  *value = dwValue != 0;
170
0
  return TRUE;
171
0
}
172
173
static BOOL settings_reg_query_dword(rdpSettings* settings, FreeRDP_Settings_Keys_UInt32 id,
174
                                     HKEY hKey, const TCHAR* sub)
175
0
{
176
0
  DWORD dwValue = 0;
177
178
0
  if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
179
0
    return FALSE;
180
181
0
  return freerdp_settings_set_uint32(settings, id, dwValue);
182
0
}
183
184
static BOOL settings_reg_query_bool(rdpSettings* settings, FreeRDP_Settings_Keys_Bool id, HKEY hKey,
185
                                    const TCHAR* sub)
186
0
{
187
0
  DWORD dwValue = 0;
188
189
0
  if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
190
0
    return FALSE;
191
192
0
  return freerdp_settings_set_bool(settings, id, (dwValue != 0));
193
0
}
194
#endif
195
196
static void settings_load_config(rdpSettings* settings, const char* config)
197
81.6k
{
198
81.6k
  WINPR_JSON* json = freerdp_GetJSONConfigFile(TRUE, config);
199
81.6k
  if (!json)
200
81.6k
    return;
201
202
0
  if (!freerdp_settings_apply_from_json(settings, json))
203
0
  {
204
0
    WLog_DBG(TAG, "%s could not be applied. File does not exist or is not valid", config);
205
0
  }
206
0
  WINPR_JSON_Delete(json);
207
0
}
208
209
static void settings_client_load_hkey_local_machine(rdpSettings* settings)
210
81.6k
{
211
81.6k
  const char config[] = "settings-defaults-client.json";
212
81.6k
#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
213
81.6k
  {
214
81.6k
    char* key = freerdp_getApplicatonDetailsRegKey(CLIENT_KEY);
215
81.6k
    if (key)
216
81.6k
    {
217
81.6k
      HKEY hKey = nullptr;
218
81.6k
      const LONG status =
219
81.6k
          RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
220
81.6k
      free(key);
221
222
81.6k
      if (status == ERROR_SUCCESS)
223
0
      {
224
0
        WLog_WARN(TAG, "HKLM.reg is deprecated since 3.33.0. ATTENTION Use %s instead",
225
0
                  config);
226
227
0
        settings_reg_query_dword(settings, FreeRDP_DesktopWidth, hKey, _T("DesktopWidth"));
228
0
        settings_reg_query_dword(settings, FreeRDP_DesktopHeight, hKey,
229
0
                                 _T("DesktopHeight"));
230
0
        settings_reg_query_bool(settings, FreeRDP_Fullscreen, hKey, _T("Fullscreen"));
231
0
        settings_reg_query_dword(settings, FreeRDP_ColorDepth, hKey, _T("ColorDepth"));
232
0
        settings_reg_query_dword(settings, FreeRDP_KeyboardType, hKey, _T("KeyboardType"));
233
0
        settings_reg_query_dword(settings, FreeRDP_KeyboardSubType, hKey,
234
0
                                 _T("KeyboardSubType"));
235
0
        settings_reg_query_dword(settings, FreeRDP_KeyboardFunctionKey, hKey,
236
0
                                 _T("KeyboardFunctionKeys"));
237
0
        settings_reg_query_dword(settings, FreeRDP_KeyboardLayout, hKey,
238
0
                                 _T("KeyboardLayout"));
239
0
        settings_reg_query_bool(settings, FreeRDP_ExtSecurity, hKey, _T("ExtSecurity"));
240
0
        settings_reg_query_bool(settings, FreeRDP_NlaSecurity, hKey, _T("NlaSecurity"));
241
0
        settings_reg_query_bool(settings, FreeRDP_TlsSecurity, hKey, _T("TlsSecurity"));
242
0
        settings_reg_query_bool(settings, FreeRDP_RdpSecurity, hKey, _T("RdpSecurity"));
243
0
        settings_reg_query_bool(settings, FreeRDP_MstscCookieMode, hKey,
244
0
                                _T("MstscCookieMode"));
245
0
        settings_reg_query_dword(settings, FreeRDP_CookieMaxLength, hKey,
246
0
                                 _T("CookieMaxLength"));
247
0
        settings_reg_query_bool(settings, FreeRDP_BitmapCacheEnabled, hKey,
248
0
                                _T("BitmapCache"));
249
0
        settings_reg_query_dword(settings, FreeRDP_OffscreenSupportLevel, hKey,
250
0
                                 _T("OffscreenBitmapCache"));
251
0
        settings_reg_query_dword(settings, FreeRDP_OffscreenCacheSize, hKey,
252
0
                                 _T("OffscreenBitmapCacheSize"));
253
0
        settings_reg_query_dword(settings, FreeRDP_OffscreenCacheEntries, hKey,
254
0
                                 _T("OffscreenBitmapCacheEntries"));
255
0
        RegCloseKey(hKey);
256
0
      }
257
81.6k
    }
258
81.6k
  }
259
81.6k
  {
260
81.6k
    char* key = freerdp_getApplicatonDetailsRegKey(BITMAP_CACHE_KEY);
261
81.6k
    if (key)
262
81.6k
    {
263
81.6k
      HKEY hKey = nullptr;
264
81.6k
      const LONG status =
265
81.6k
          RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
266
81.6k
      free(key);
267
268
81.6k
      if (status == ERROR_SUCCESS)
269
0
      {
270
0
        settings_reg_query_dword(settings, FreeRDP_BitmapCacheV2NumCells, hKey,
271
0
                                 _T("NumCells"));
272
0
        for (unsigned x = 0; x < 5; x++)
273
0
        {
274
0
          DWORD val = 0;
275
0
          TCHAR numentries[64] = WINPR_C_ARRAY_INIT;
276
0
          TCHAR persist[64] = WINPR_C_ARRAY_INIT;
277
0
          BITMAP_CACHE_V2_CELL_INFO cache = WINPR_C_ARRAY_INIT;
278
0
          (void)_sntprintf(numentries, ARRAYSIZE(numentries), _T("Cell%uNumEntries"), x);
279
0
          (void)_sntprintf(persist, ARRAYSIZE(persist), _T("Cell%uPersistent"), x);
280
0
          if (!settings_reg_query_dword_val(hKey, numentries, &val) ||
281
0
              !settings_reg_query_bool_val(hKey, persist, &cache.persistent))
282
0
            continue;
283
284
0
          if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo,
285
0
                                                  x, &cache))
286
0
            WLog_WARN(TAG, "Failed to load registry keys to settings!");
287
0
          cache.numEntries = val;
288
0
        }
289
290
0
        settings_reg_query_bool(settings, FreeRDP_AllowCacheWaitingList, hKey,
291
0
                                _T("AllowCacheWaitingList"));
292
0
        RegCloseKey(hKey);
293
0
      }
294
81.6k
    }
295
81.6k
  }
296
81.6k
  {
297
81.6k
    char* key = freerdp_getApplicatonDetailsRegKey(GLYPH_CACHE_KEY);
298
81.6k
    if (key)
299
81.6k
    {
300
81.6k
      HKEY hKey = nullptr;
301
81.6k
      const LONG status =
302
81.6k
          RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
303
81.6k
      free(key);
304
305
81.6k
      if (status == ERROR_SUCCESS)
306
0
      {
307
0
        unsigned x = 0;
308
0
        UINT32 GlyphSupportLevel = 0;
309
0
        settings_reg_query_dword(settings, FreeRDP_GlyphSupportLevel, hKey,
310
0
                                 _T("SupportLevel"));
311
0
        for (; x < 10; x++)
312
0
        {
313
0
          GLYPH_CACHE_DEFINITION cache = WINPR_C_ARRAY_INIT;
314
0
          TCHAR numentries[64] = WINPR_C_ARRAY_INIT;
315
0
          TCHAR maxsize[64] = WINPR_C_ARRAY_INIT;
316
0
          (void)_sntprintf(numentries, ARRAYSIZE(numentries), _T("Cache%uNumEntries"), x);
317
0
          (void)_sntprintf(maxsize, ARRAYSIZE(maxsize), _T("Cache%uMaxCellSize"), x);
318
319
0
          settings_reg_query_word_val(hKey, numentries, &cache.cacheEntries);
320
0
          settings_reg_query_word_val(hKey, maxsize, &cache.cacheMaximumCellSize);
321
0
          if (!freerdp_settings_set_pointer_array(settings, FreeRDP_GlyphCache, x,
322
0
                                                  &cache))
323
0
            WLog_WARN(TAG, "Failed to store GlyphCache %u", x);
324
0
        }
325
0
        {
326
0
          GLYPH_CACHE_DEFINITION cache = WINPR_C_ARRAY_INIT;
327
0
          settings_reg_query_word_val(hKey, _T("FragCacheNumEntries"),
328
0
                                      &cache.cacheEntries);
329
0
          settings_reg_query_word_val(hKey, _T("FragCacheMaxCellSize"),
330
0
                                      &cache.cacheMaximumCellSize);
331
0
          if (!freerdp_settings_set_pointer_array(settings, FreeRDP_FragCache, x, &cache))
332
0
            WLog_WARN(TAG, "Failed to store FragCache");
333
0
        }
334
335
0
        RegCloseKey(hKey);
336
337
0
        if (!freerdp_settings_set_uint32(settings, FreeRDP_GlyphSupportLevel,
338
0
                                         GlyphSupportLevel))
339
0
          WLog_WARN(TAG, "Failed to load registry keys to settings!");
340
0
      }
341
81.6k
    }
342
81.6k
  }
343
81.6k
  {
344
81.6k
    char* key = freerdp_getApplicatonDetailsRegKey(POINTER_CACHE_KEY);
345
81.6k
    if (key)
346
81.6k
    {
347
81.6k
      HKEY hKey = nullptr;
348
81.6k
      const LONG status =
349
81.6k
          RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
350
81.6k
      free(key);
351
352
81.6k
      if (status == ERROR_SUCCESS)
353
0
      {
354
0
        settings_reg_query_dword(settings, FreeRDP_LargePointerFlag, hKey,
355
0
                                 _T("LargePointer"));
356
0
        settings_reg_query_dword(settings, FreeRDP_PointerCacheSize, hKey,
357
0
                                 _T("PointerCacheSize"));
358
0
        settings_reg_query_dword(settings, FreeRDP_ColorPointerCacheSize, hKey,
359
0
                                 _T("ColorPointerCacheSize"));
360
0
        RegCloseKey(hKey);
361
0
      }
362
81.6k
    }
363
81.6k
  }
364
81.6k
#endif
365
81.6k
  settings_load_config(settings, config);
366
81.6k
}
367
368
static void settings_server_load_hkey_local_machine(rdpSettings* settings)
369
24.7k
{
370
24.7k
  const char config[] = "settings-defaults-server.json";
371
372
24.7k
#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
373
24.7k
  {
374
24.7k
    HKEY hKey = nullptr;
375
376
24.7k
    char* key = freerdp_getApplicatonDetailsRegKey(SERVER_KEY);
377
24.7k
    if (!key)
378
0
      return;
379
380
24.7k
    const LONG status =
381
24.7k
        RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
382
24.7k
    free(key);
383
384
24.7k
    if (status != ERROR_SUCCESS)
385
24.7k
      return;
386
387
0
    WLog_WARN(TAG, "HKLM.reg is deprecated since 3.33.0. ATTENTION Use %s instead", config);
388
389
0
    settings_reg_query_bool(settings, FreeRDP_ExtSecurity, hKey, _T("ExtSecurity"));
390
0
    settings_reg_query_bool(settings, FreeRDP_NlaSecurity, hKey, _T("NlaSecurity"));
391
0
    settings_reg_query_bool(settings, FreeRDP_TlsSecurity, hKey, _T("TlsSecurity"));
392
0
    settings_reg_query_dword(settings, FreeRDP_TlsSecLevel, hKey, _T("TlsSecLevel"));
393
0
    settings_reg_query_bool(settings, FreeRDP_RdpSecurity, hKey, _T("RdpSecurity"));
394
395
0
    RegCloseKey(hKey);
396
0
  }
397
0
#endif
398
399
0
  settings_load_config(settings, config);
400
0
}
401
402
WINPR_ATTR_NODISCARD
403
static BOOL settings_load_hkey_local_machine(rdpSettings* settings)
404
106k
{
405
106k
  const BOOL server = freerdp_settings_get_bool(settings, FreeRDP_ServerMode);
406
106k
  if (server)
407
24.7k
    settings_server_load_hkey_local_machine(settings);
408
81.6k
  else
409
81.6k
    settings_client_load_hkey_local_machine(settings);
410
411
106k
  const BOOL fail = server != freerdp_settings_get_bool(settings, FreeRDP_ServerMode);
412
106k
  if (fail)
413
0
  {
414
0
    WLog_ERR(TAG,
415
0
             "default configuration changed FreeRDP_ServerMode! This is not allowed, aborting");
416
0
  }
417
106k
  return !fail;
418
106k
}
419
420
static BOOL settings_init_computer_name(rdpSettings* settings)
421
106k
{
422
106k
  CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1] = WINPR_C_ARRAY_INIT;
423
106k
  DWORD nSize = ARRAYSIZE(computerName);
424
425
106k
  if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
426
0
    return FALSE;
427
428
106k
  if (!freerdp_settings_set_string(settings, FreeRDP_ComputerName, computerName))
429
0
    return FALSE;
430
106k
  return freerdp_settings_set_string(settings, FreeRDP_ClientHostname, computerName);
431
106k
}
432
433
void freerdp_settings_print_warnings(const rdpSettings* settings)
434
0
{
435
0
  const UINT32 level = freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel);
436
0
  if (level != GLYPH_SUPPORT_NONE)
437
0
  {
438
0
    char buffer[32] = WINPR_C_ARRAY_INIT;
439
0
    WLog_WARN(TAG, "[experimental] enabled GlyphSupportLevel %s, expect visual artefacts!",
440
0
              freerdp_settings_glyph_level_string(level, buffer, sizeof(buffer)));
441
0
  }
442
0
}
443
444
static BOOL monitor_operlaps(const rdpSettings* settings, UINT32 orig, UINT32 start, UINT32 count,
445
                             const rdpMonitor* compare)
446
0
{
447
0
  const struct bounds_t rect1 = {
448
0
    .x = compare->x, .y = compare->y, .width = compare->width, .height = compare->height
449
0
  };
450
0
  for (UINT32 x = start; x < count; x++)
451
0
  {
452
0
    const rdpMonitor* monitor =
453
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
454
0
    const struct bounds_t rect2 = {
455
0
      .x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
456
0
    };
457
458
0
    if (intersect_rects(&rect1, &rect2))
459
0
    {
460
0
      char buffer1[32] = WINPR_C_ARRAY_INIT;
461
0
      char buffer2[32] = WINPR_C_ARRAY_INIT;
462
463
0
      WLog_ERR(TAG, "Monitor %" PRIu32 " and %" PRIu32 " are overlapping:", orig, x);
464
0
      WLog_ERR(TAG, "%s overlapps with %s", bounds2str(&rect1, buffer1, sizeof(buffer1)),
465
0
               bounds2str(&rect2, buffer2, sizeof(buffer2)));
466
0
      WLog_ERR(
467
0
          TAG,
468
0
          "Mulitimonitor mode requested, but local layout has gaps or overlapping areas!");
469
0
      WLog_ERR(TAG,
470
0
               "Please reconfigure your local monitor setup so that there are no gaps or "
471
0
               "overlapping areas!");
472
0
      return TRUE;
473
0
    }
474
0
  }
475
0
  return FALSE;
476
0
}
477
478
static BOOL monitor_has_gaps(const rdpSettings* settings, UINT32 start, UINT32 count,
479
                             const rdpMonitor* compare, UINT32** graph)
480
0
{
481
0
  const struct bounds_t rect1 = {
482
0
    .x = compare->x, .y = compare->y, .width = compare->width, .height = compare->height
483
0
  };
484
485
0
  BOOL hasNeighbor = FALSE;
486
0
  for (UINT32 i = 0; i < count; i++)
487
0
  {
488
0
    if (i == start)
489
0
      continue;
490
491
0
    const rdpMonitor* monitor =
492
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, i);
493
494
0
    const struct bounds_t rect2 = {
495
0
      .x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
496
0
    };
497
0
    if (align_rects(&rect1, &rect2))
498
0
    {
499
0
      hasNeighbor = TRUE;
500
0
      graph[start][i] = 1;
501
0
      graph[i][start] = 1;
502
0
    }
503
0
  }
504
505
0
  if (!hasNeighbor)
506
0
  {
507
0
    WLog_ERR(TAG,
508
0
             "Monitor configuration has gaps! Monitor %" PRIu32 " does not have any neighbor",
509
0
             start);
510
0
  }
511
512
0
  return !hasNeighbor;
513
0
}
514
515
static void alloc_free(UINT32** ptr)
516
0
{
517
0
  free((void*)ptr);
518
0
}
519
520
WINPR_ATTR_MALLOC(alloc_free, 1)
521
WINPR_ATTR_NODISCARD
522
static UINT32** alloc_array(size_t count)
523
0
{
524
  // NOLINTNEXTLINE(clang-analyzer-unix.MallocSizeof)
525
0
  BYTE* array = calloc(count * sizeof(uintptr_t), count * sizeof(UINT32));
526
0
  UINT32** dst = WINPR_PACKED_ALIGN_CAST(UINT32**, array);
527
0
  UINT32* val = WINPR_PACKED_ALIGN_CAST(UINT32*, (array + count * sizeof(uintptr_t)));
528
0
  for (size_t x = 0; x < count; x++)
529
0
    dst[x] = &val[x];
530
531
0
  return dst;
532
0
}
533
534
/* Monitors in the array need to:
535
 *
536
 * 1. be connected to another monitor (edges touch but don't overlap or have gaps)
537
 * 2. all monitors need to be connected so there are no separate groups.
538
 *
539
 * So, what we do here is we use dijkstra algorithm to find a path from any start node
540
 * (lazy as we are we always use the first in the array) to each other node.
541
 */
542
static BOOL find_path_exists_with_dijkstra(UINT32** graph, size_t count, UINT32 start)
543
0
{
544
0
  if (count < 1)
545
0
    return FALSE;
546
547
0
  WINPR_ASSERT(start < count);
548
549
0
  UINT32** cost = alloc_array(count);
550
0
  WINPR_ASSERT(cost);
551
552
0
  UINT32* distance = calloc(count, sizeof(UINT32));
553
0
  WINPR_ASSERT(distance);
554
555
0
  UINT32* visited = calloc(count, sizeof(UINT32));
556
0
  WINPR_ASSERT(visited);
557
558
0
  UINT32* parent = calloc(count, sizeof(UINT32));
559
0
  WINPR_ASSERT(parent);
560
561
0
  for (size_t x = 0; x < count; x++)
562
0
  {
563
0
    for (size_t y = 0; y < count; y++)
564
0
    {
565
0
      if (graph[x][y] == 0)
566
0
        cost[x][y] = UINT32_MAX;
567
0
      else
568
0
        cost[x][y] = graph[x][y];
569
0
    }
570
0
  }
571
572
0
  for (UINT32 x = 0; x < count; x++)
573
0
  {
574
0
    distance[x] = cost[start][x];
575
0
    parent[x] = start;
576
0
    visited[x] = 0;
577
0
  }
578
579
0
  distance[start] = 0;
580
0
  visited[start] = 1;
581
582
0
  size_t pos = 1;
583
0
  UINT32 nextnode = UINT32_MAX;
584
0
  while (pos < count - 1)
585
0
  {
586
0
    UINT32 mindistance = UINT32_MAX;
587
588
0
    for (UINT32 x = 0; x < count; x++)
589
0
    {
590
0
      if ((distance[x] < mindistance) && !visited[x])
591
0
      {
592
0
        mindistance = distance[x];
593
0
        nextnode = x;
594
0
      }
595
0
    }
596
597
0
    visited[nextnode] = 1;
598
599
0
    for (size_t y = 0; y < count; y++)
600
0
    {
601
0
      if (!visited[y])
602
0
      {
603
0
        UINT32 dist = mindistance + cost[nextnode][y];
604
0
        if (dist < distance[y])
605
0
        {
606
0
          distance[y] = dist;
607
0
          parent[y] = nextnode;
608
0
        }
609
0
      }
610
0
    }
611
0
    pos++;
612
0
  }
613
614
0
  BOOL rc = TRUE;
615
0
  for (size_t x = 0; x < count; x++)
616
0
  {
617
0
    if (x != start)
618
0
    {
619
0
      if (distance[x] == UINT32_MAX)
620
0
      {
621
0
        WLog_ERR(TAG, "monitor %" PRIu32 " not connected with monitor %" PRIuz, start, x);
622
0
        rc = FALSE;
623
0
        break;
624
0
      }
625
0
    }
626
0
  }
627
0
  alloc_free(cost);
628
0
  free(distance);
629
0
  free(visited);
630
0
  free(parent);
631
632
0
  return rc;
633
0
}
634
635
static BOOL freerdp_settings_client_monitors_have_gaps(const rdpSettings* settings)
636
0
{
637
0
  BOOL rc = TRUE;
638
0
  const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
639
0
  if (count <= 1)
640
0
    return FALSE;
641
642
0
  UINT32** graph = alloc_array(count);
643
0
  WINPR_ASSERT(graph);
644
645
0
  for (UINT32 x = 0; x < count; x++)
646
0
  {
647
0
    const rdpMonitor* monitor =
648
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
649
0
    if (monitor_has_gaps(settings, x, count, monitor, graph))
650
0
      goto fail;
651
0
  }
652
653
0
  rc = !find_path_exists_with_dijkstra(graph, count, 0);
654
655
0
fail:
656
0
  alloc_free(graph);
657
658
0
  return rc;
659
0
}
660
661
static void log_monitor(UINT32 idx, const rdpMonitor* monitor, wLog* log, DWORD level)
662
0
{
663
0
  WINPR_ASSERT(monitor);
664
665
0
  WLog_Print(log, level,
666
0
             "[%" PRIu32 "] [%s] {%dx%d-%dx%d} [%" PRIu32 "] {%" PRIu32 "x%" PRIu32
667
0
             ", orientation: %s [%" PRIu32 "], desktopScale: %" PRIu32 ", deviceScale: %" PRIu32
668
0
             "}",
669
0
             idx, monitor->is_primary ? "primary" : "       ", monitor->x, monitor->y,
670
0
             monitor->width, monitor->height, monitor->orig_screen,
671
0
             monitor->attributes.physicalWidth, monitor->attributes.physicalHeight,
672
0
             freerdp_desktop_rotation_flags_to_string(monitor->attributes.orientation),
673
0
             monitor->attributes.orientation, monitor->attributes.desktopScaleFactor,
674
0
             monitor->attributes.deviceScaleFactor);
675
0
}
676
677
static void log_monitor_configuration(const rdpSettings* settings, wLog* log, DWORD level)
678
0
{
679
0
  const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
680
0
  WLog_Print(log, level, "[BEGIN] MonitorDefArray[%" PRIu32 "]", count);
681
0
  for (UINT32 x = 0; x < count; x++)
682
0
  {
683
0
    const rdpMonitor* monitor =
684
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
685
0
    log_monitor(x, monitor, log, level);
686
0
  }
687
0
  WLog_Print(log, level, "[END] MonitorDefArray[%" PRIu32 "]", count);
688
0
}
689
690
static BOOL freerdp_settings_client_monitors_overlap(const rdpSettings* settings)
691
0
{
692
0
  const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
693
0
  for (UINT32 x = 0; x < count; x++)
694
0
  {
695
0
    const rdpMonitor* monitor =
696
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
697
0
    if (monitor_operlaps(settings, x, x + 1, count, monitor))
698
0
      return TRUE;
699
0
  }
700
0
  return FALSE;
701
0
}
702
703
/* See [MS-RDPBCGR] 2.2.1.3.6.1 for details on limits
704
 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/c3964b39-3d54-4ae1-a84a-ceaed311e0f6
705
 */
706
static BOOL freerdp_settings_client_monitors_check_primary_and_origin(const rdpSettings* settings)
707
0
{
708
0
  const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
709
0
  BOOL havePrimary = FALSE;
710
0
  BOOL foundOrigin = FALSE;
711
0
  BOOL primaryIsOrigin = FALSE;
712
0
  BOOL rc = TRUE;
713
714
0
  struct bounds_t bounds = WINPR_C_ARRAY_INIT;
715
716
0
  if (count == 0)
717
0
  {
718
0
    WLog_WARN(TAG, "Monitor configuration empty.");
719
0
    return TRUE;
720
0
  }
721
722
0
  for (UINT32 x = 0; x < count; x++)
723
0
  {
724
0
    const rdpMonitor* monitor =
725
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
726
0
    struct bounds_t cur = {
727
0
      .x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
728
0
    };
729
730
0
    bounds = union_rect(&bounds, &cur);
731
732
0
    if (monitor->is_primary)
733
0
    {
734
0
      if (havePrimary)
735
0
      {
736
0
        WLog_ERR(TAG, "Monitor configuration contains multiple primary monitors!");
737
0
        rc = FALSE;
738
0
      }
739
0
      havePrimary = TRUE;
740
0
    }
741
742
0
    if ((monitor->x == 0) && (monitor->y == 0))
743
0
    {
744
0
      if (foundOrigin)
745
0
      {
746
0
        WLog_ERR(TAG, "Monitor configuration does have multiple origin 0/0");
747
0
        rc = FALSE;
748
0
      }
749
0
      foundOrigin = TRUE;
750
0
      primaryIsOrigin = monitor->is_primary != 0;
751
0
    }
752
0
  }
753
754
0
  if ((bounds.width > 32766) || (bounds.width < 200))
755
0
  {
756
0
    WLog_ERR(TAG,
757
0
             "Monitor configuration virtual desktop width must be 200 <= %" PRId32 " <= 32766",
758
0
             bounds.width);
759
0
    rc = FALSE;
760
0
  }
761
0
  if ((bounds.height > 32766) || (bounds.height < 200))
762
0
  {
763
0
    WLog_ERR(TAG,
764
0
             "Monitor configuration virtual desktop height must be 200 <= %" PRId32 " <= 32766",
765
0
             bounds.height);
766
0
    rc = FALSE;
767
0
  }
768
769
0
  if (!havePrimary)
770
0
  {
771
0
    WLog_ERR(TAG, "Monitor configuration does not contain a primary monitor!");
772
0
    rc = FALSE;
773
0
  }
774
0
  if (!foundOrigin)
775
0
  {
776
0
    WLog_ERR(TAG, "Monitor configuration must start at 0/0 for first monitor!");
777
0
    rc = FALSE;
778
0
  }
779
0
  if (!primaryIsOrigin)
780
0
  {
781
0
    WLog_ERR(TAG, "Monitor configuration must start at 0/0 for primary monitor!");
782
0
    rc = FALSE;
783
0
  }
784
785
0
  return rc;
786
0
}
787
788
BOOL freerdp_settings_check_client_after_preconnect(const rdpSettings* settings)
789
0
{
790
0
  wLog* log = WLog_Get(TAG);
791
0
  BOOL rc = TRUE;
792
0
  log_monitor_configuration(settings, log, WLOG_DEBUG);
793
0
  if (freerdp_settings_client_monitors_overlap(settings))
794
0
    rc = FALSE;
795
0
  if (freerdp_settings_client_monitors_have_gaps(settings))
796
0
    rc = FALSE;
797
0
  if (!freerdp_settings_client_monitors_check_primary_and_origin(settings))
798
0
    rc = FALSE;
799
0
  if (!rc)
800
0
  {
801
0
    DWORD level = WLOG_ERROR;
802
0
    WLog_Print(log, level, "Invalid or unsupported monitor configuration detected");
803
0
    WLog_Print(log, level, "Check if the configuration is valid.");
804
0
    WLog_Print(log, level,
805
0
               "If you suspect a bug create a new issue at "
806
0
               "https://github.com/FreeRDP/FreeRDP/issues/new");
807
0
    WLog_Print(
808
0
        log, level,
809
0
        "Provide at least the following log lines detailing your monitor configuration:");
810
0
    log_monitor_configuration(settings, log, level);
811
0
    return FALSE;
812
0
  }
813
814
0
  if (freerdp_settings_get_bool(settings, FreeRDP_GatewayEnabled))
815
0
  {
816
0
    const char* host = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname);
817
0
    if (!host)
818
0
    {
819
0
      WLog_Print(log, WLOG_ERROR,
820
0
                 "Inconsistent settings: Gateway support enabled, but no gateway provided.");
821
0
      return FALSE;
822
0
    }
823
0
  }
824
0
  return TRUE;
825
0
}
826
827
BOOL freerdp_settings_set_default_order_support(rdpSettings* settings)
828
106k
{
829
106k
  BYTE* OrderSupport = freerdp_settings_get_pointer_writable(settings, FreeRDP_OrderSupport);
830
106k
  if (!OrderSupport)
831
0
    return FALSE;
832
833
106k
  ZeroMemory(OrderSupport, 32);
834
106k
  OrderSupport[NEG_DSTBLT_INDEX] = TRUE;
835
106k
  OrderSupport[NEG_PATBLT_INDEX] = TRUE;
836
106k
  OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
837
106k
  OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE;
838
106k
  OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE;
839
106k
  OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE;
840
106k
  OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE;
841
106k
  OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE;
842
106k
  OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE;
843
106k
  OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE;
844
106k
  OrderSupport[NEG_LINETO_INDEX] = TRUE;
845
106k
  OrderSupport[NEG_POLYLINE_INDEX] = TRUE;
846
106k
  OrderSupport[NEG_MEMBLT_INDEX] =
847
106k
      freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
848
106k
  OrderSupport[NEG_MEM3BLT_INDEX] =
849
106k
      freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
850
106k
  OrderSupport[NEG_MEMBLT_V2_INDEX] =
851
106k
      freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
852
106k
  OrderSupport[NEG_MEM3BLT_V2_INDEX] =
853
106k
      freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheEnabled) ? 1 : 0;
854
106k
  OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
855
106k
  OrderSupport[NEG_GLYPH_INDEX_INDEX] =
856
106k
      freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel) != GLYPH_SUPPORT_NONE;
857
106k
  OrderSupport[NEG_FAST_INDEX_INDEX] =
858
106k
      freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel) != GLYPH_SUPPORT_NONE;
859
106k
  OrderSupport[NEG_FAST_GLYPH_INDEX] =
860
106k
      freerdp_settings_get_uint32(settings, FreeRDP_GlyphSupportLevel) != GLYPH_SUPPORT_NONE;
861
106k
  OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
862
106k
  OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
863
106k
  OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
864
106k
  OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
865
106k
  return TRUE;
866
106k
}
867
868
char* freerdp_settings_get_config_path(void)
869
81.6k
{
870
81.6k
  return freerdp_GetConfigFilePath(FALSE, "");
871
81.6k
}
872
873
rdpSettings* freerdp_settings_new(DWORD flags)
874
106k
{
875
106k
  const BOOL server = ((flags & FREERDP_SETTINGS_SERVER_MODE) != 0);
876
106k
  const BOOL remote = ((flags & FREERDP_SETTINGS_REMOTE_MODE) != 0);
877
106k
  rdpSettings* settings = (rdpSettings*)calloc(1, sizeof(rdpSettings));
878
879
106k
  if (!settings)
880
0
    return nullptr;
881
882
106k
  {
883
106k
    const char* vendor = freerdp_getApplicationDetailsVendor();
884
106k
    const char* product = freerdp_getApplicationDetailsProduct();
885
106k
    const char* details = freerdp_getApplicationDetailsString();
886
106k
    char* issuer1 = nullptr;
887
106k
    char* issuer2 = nullptr;
888
106k
    char* issuer3 = nullptr;
889
106k
    size_t len = 0;
890
106k
    (void)winpr_asprintf(&issuer1, &len, "%s-licenser", freerdp_getApplicationDetailsString());
891
106k
    (void)winpr_asprintf(&issuer2, &len, "%s-licenser", freerdp_getApplicationDetailsVendor());
892
106k
    (void)winpr_asprintf(&issuer3, &len, "%s-licenser", freerdp_getApplicationDetailsProduct());
893
894
106k
    char* issuers[] = { WINPR_CAST_CONST_PTR_AWAY(vendor, char*),
895
106k
                      WINPR_CAST_CONST_PTR_AWAY(product, char*),
896
106k
                      WINPR_CAST_CONST_PTR_AWAY(details, char*),
897
106k
                      issuer1,
898
106k
                      issuer2,
899
106k
                      issuer3 };
900
901
106k
    const BOOL res = freerdp_server_license_issuers_copy(settings, issuers, ARRAYSIZE(issuers));
902
106k
    free(issuer1);
903
106k
    free(issuer2);
904
106k
    free(issuer3);
905
106k
    if (!res)
906
0
      goto out_fail;
907
106k
  }
908
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_RdstlsEnabledModes, UINT32_MAX))
909
0
    goto out_fail;
910
106k
  if (!server && !remote)
911
74.4k
  {
912
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayHttpUserAgent,
913
74.4k
                                     FREERDP_USER_AGENT))
914
0
      goto out_fail;
915
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayHttpMsUserAgent,
916
74.4k
                                     FREERDP_USER_AGENT))
917
0
      goto out_fail;
918
919
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayHttpReferer, ""))
920
0
      goto out_fail;
921
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdAccessTokenFormat,
922
74.4k
                                     "ms-appx-web%%3a%%2f%%2fMicrosoft.AAD.BrokerPlugin%%2f%s"))
923
0
      goto out_fail;
924
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdAccessAadFormat,
925
74.4k
                                     "https%%3A%%2F%%2F%s%%2F%s%%2Foauth2%%2Fnativeclient"))
926
0
      goto out_fail;
927
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdScope,
928
74.4k
                                     "https%3A%2F%2Fwww.wvd.microsoft.com%2F.default%20openid%"
929
74.4k
                                     "20profile%20offline_access"))
930
931
0
      goto out_fail;
932
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdClientID,
933
74.4k
                                     "a85cf173-4192-42f8-81fa-777a763e6e2c"))
934
0
      goto out_fail;
935
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAzureActiveDirectory,
936
74.4k
                                     "login.microsoftonline.com"))
937
0
      goto out_fail;
938
74.4k
    if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdAadtenantid, "common"))
939
0
      goto out_fail;
940
74.4k
    if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayAvdUseTenantid, FALSE))
941
0
      goto out_fail;
942
74.4k
    if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopPhysicalWidth, 1000))
943
0
      goto out_fail;
944
74.4k
    if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopPhysicalHeight, 1000))
945
0
      goto out_fail;
946
74.4k
    if (!freerdp_settings_set_uint16(settings, FreeRDP_DesktopOrientation,
947
74.4k
                                     ORIENTATION_LANDSCAPE))
948
0
      goto out_fail;
949
74.4k
    if (!freerdp_settings_set_uint32(settings, FreeRDP_DeviceScaleFactor, 100))
950
0
      goto out_fail;
951
74.4k
    if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopScaleFactor, 100))
952
0
      goto out_fail;
953
74.4k
  }
954
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_SurfaceCommandsSupported,
955
106k
                                   SURFCMDS_SET_SURFACE_BITS | SURFCMDS_STREAM_SURFACE_BITS |
956
106k
                                       SURFCMDS_FRAME_MARKER))
957
0
    goto out_fail;
958
959
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_RemoteFxRlgrMode, RLGR3))
960
0
    goto out_fail;
961
962
106k
  if (!freerdp_settings_set_uint16(settings, FreeRDP_CapsProtocolVersion,
963
106k
                                   TS_CAPS_PROTOCOLVERSION))
964
0
    goto out_fail;
965
966
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_ClipboardFeatureMask,
967
106k
                                   CLIPRDR_FLAG_DEFAULT_MASK))
968
0
    goto out_fail;
969
106k
  if (!freerdp_settings_set_string(settings, FreeRDP_ServerLicenseCompanyName,
970
106k
                                   freerdp_getApplicationDetailsVendor()))
971
0
    goto out_fail;
972
973
106k
  {
974
106k
    size_t len = 0;
975
106k
    char* val = nullptr;
976
106k
    (void)winpr_asprintf(&val, &len, "%s-licensing-server",
977
106k
                         freerdp_getApplicationDetailsProduct());
978
106k
    if (!val)
979
0
      goto out_fail;
980
981
106k
    const BOOL rc =
982
106k
        freerdp_settings_set_string(settings, FreeRDP_ServerLicenseProductName, val);
983
106k
    free(val);
984
106k
    if (!rc)
985
0
      goto out_fail;
986
106k
  }
987
988
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_ServerLicenseProductVersion, 1))
989
0
    goto out_fail;
990
991
106k
  if (!freerdp_settings_set_uint16(settings, FreeRDP_SupportedColorDepths,
992
106k
                                   RNS_UD_32BPP_SUPPORT | RNS_UD_24BPP_SUPPORT |
993
106k
                                       RNS_UD_16BPP_SUPPORT | RNS_UD_15BPP_SUPPORT))
994
0
    goto out_fail;
995
996
106k
  const UINT32 railflags = TS_RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE |
997
106k
                           TS_RAIL_CLIENTSTATUS_ZORDER_SYNC |
998
106k
                           TS_RAIL_CLIENTSTATUS_WINDOW_RESIZE_MARGIN_SUPPORTED |
999
106k
                           TS_RAIL_CLIENTSTATUS_APPBAR_REMOTING_SUPPORTED |
1000
106k
                           TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED |
1001
106k
                           TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED;
1002
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppFeatureFlags, railflags))
1003
0
    goto out_fail;
1004
1005
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_UnicodeInput, TRUE) ||
1006
106k
      !freerdp_settings_set_bool(settings, FreeRDP_HasHorizontalWheel, TRUE) ||
1007
106k
      !freerdp_settings_set_bool(settings, FreeRDP_HasExtendedMouseEvent, TRUE) ||
1008
106k
      !freerdp_settings_set_bool(settings, FreeRDP_HasQoeEvent, TRUE) ||
1009
106k
      !freerdp_settings_set_bool(settings, FreeRDP_HasRelativeMouseEvent, TRUE) ||
1010
106k
      !freerdp_settings_set_bool(settings, FreeRDP_HiDefRemoteApp, TRUE) ||
1011
106k
      !freerdp_settings_set_uint32(
1012
106k
          settings, FreeRDP_RemoteApplicationSupportMask,
1013
106k
          RAIL_LEVEL_SUPPORTED | RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED |
1014
106k
              RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED | RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED |
1015
106k
              RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED |
1016
106k
              RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED | RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED |
1017
106k
              RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED) ||
1018
106k
      !freerdp_settings_set_uint16(settings, FreeRDP_TextANSICodePage, CP_UTF8) ||
1019
106k
      !freerdp_settings_set_uint16(settings, FreeRDP_OrderSupportFlags,
1020
106k
                                   NEGOTIATE_ORDER_SUPPORT | ZERO_BOUNDS_DELTA_SUPPORT |
1021
106k
                                       COLOR_INDEX_SUPPORT) ||
1022
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SupportHeartbeatPdu, TRUE) ||
1023
106k
      !freerdp_settings_set_bool(settings, FreeRDP_ServerMode, server) ||
1024
106k
      !freerdp_settings_set_bool(settings, FreeRDP_WaitForOutputBufferFlush, TRUE) ||
1025
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_ClusterInfoFlags, REDIRECTION_SUPPORTED) ||
1026
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 1024) ||
1027
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 768) ||
1028
106k
      !freerdp_settings_set_bool(settings, FreeRDP_Workarea, FALSE) ||
1029
106k
      !freerdp_settings_set_bool(settings, FreeRDP_Fullscreen, FALSE) ||
1030
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GrabKeyboard, TRUE) ||
1031
106k
      !freerdp_settings_set_bool(settings, FreeRDP_Decorations, TRUE) ||
1032
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_RdpVersion, RDP_VERSION_10_12) ||
1033
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32) ||
1034
106k
      !freerdp_settings_set_bool(settings, FreeRDP_AadSecurity, FALSE) ||
1035
106k
      !freerdp_settings_set_bool(settings, FreeRDP_ExtSecurity, TRUE) ||
1036
106k
      !freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, TRUE) ||
1037
106k
      !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) ||
1038
106k
      !freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE) ||
1039
106k
      !freerdp_settings_set_bool(settings, FreeRDP_RdstlsSecurity, FALSE) ||
1040
106k
      !freerdp_settings_set_bool(settings, FreeRDP_NegotiateSecurityLayer, TRUE) ||
1041
106k
      !freerdp_settings_set_bool(settings, FreeRDP_RestrictedAdminModeRequired, FALSE) ||
1042
106k
      !freerdp_settings_set_bool(settings, FreeRDP_RestrictedAdminModeSupported, TRUE) ||
1043
106k
      !freerdp_settings_set_bool(settings, FreeRDP_MstscCookieMode, FALSE) ||
1044
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_CookieMaxLength,
1045
106k
                                   DEFAULT_COOKIE_MAX_LENGTH) ||
1046
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_ClientBuild,
1047
106k
                                   18363) || /* Windows 10, Version 1909 */
1048
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_KeyboardType, WINPR_KBD_TYPE_IBM_ENHANCED) ||
1049
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_KeyboardSubType, 0) ||
1050
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_KeyboardFunctionKey, 12) ||
1051
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_KeyboardLayout, 0) ||
1052
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_KeyboardHook,
1053
106k
                                   KEYBOARD_HOOK_FULLSCREEN_ONLY) ||
1054
106k
      !freerdp_settings_set_bool(settings, FreeRDP_UseRdpSecurityLayer, FALSE) ||
1055
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SaltedChecksum, TRUE) ||
1056
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_ServerPort, 3389) ||
1057
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_GatewayPort, 443) ||
1058
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DesktopResize, TRUE) ||
1059
106k
      !freerdp_settings_set_bool(settings, FreeRDP_ToggleFullscreen, TRUE) ||
1060
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_DesktopPosX, UINT32_MAX) ||
1061
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_DesktopPosY, UINT32_MAX) ||
1062
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SoftwareGdi, TRUE) ||
1063
106k
      !freerdp_settings_set_bool(settings, FreeRDP_UnmapButtons, FALSE) ||
1064
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_PerformanceFlags, PERF_FLAG_NONE) ||
1065
106k
      !freerdp_settings_set_bool(settings, FreeRDP_AllowFontSmoothing, TRUE) ||
1066
106k
      !freerdp_settings_set_bool(settings, FreeRDP_AllowDesktopComposition, FALSE) ||
1067
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DisableWallpaper, FALSE) ||
1068
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DisableFullWindowDrag, TRUE) ||
1069
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DisableMenuAnims, TRUE) ||
1070
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DisableThemes, FALSE) ||
1071
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_ConnectionType,
1072
106k
                                   CONNECTION_TYPE_AUTODETECT) ||
1073
106k
      !freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect, TRUE) ||
1074
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_EncryptionMethods, ENCRYPTION_METHOD_NONE) ||
1075
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_EncryptionLevel, ENCRYPTION_LEVEL_NONE) ||
1076
106k
      !freerdp_settings_set_bool(settings, FreeRDP_FIPSMode, FALSE) ||
1077
106k
      !freerdp_settings_set_bool(settings, FreeRDP_CompressionEnabled, TRUE) ||
1078
106k
      !freerdp_settings_set_bool(settings, FreeRDP_LogonNotify, TRUE) ||
1079
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_BrushSupportLevel, BRUSH_COLOR_FULL) ||
1080
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_CompressionLevel, PACKET_COMPR_TYPE_RDP61) ||
1081
106k
      !freerdp_settings_set_bool(settings, FreeRDP_Authentication, TRUE) ||
1082
106k
      !freerdp_settings_set_bool(settings, FreeRDP_AuthenticationOnly, FALSE) ||
1083
106k
      !freerdp_settings_set_bool(settings, FreeRDP_CredentialsFromStdin, FALSE) ||
1084
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DisableCredentialsDelegation, FALSE) ||
1085
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_AuthenticationLevel, 2) ||
1086
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_ChannelCount, 0) ||
1087
106k
      !freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, FALSE) ||
1088
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_KeySpec, AT_KEYEXCHANGE))
1089
0
    goto out_fail;
1090
1091
106k
  if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ChannelDefArray, nullptr,
1092
106k
                                        CHANNEL_MAX_COUNT))
1093
0
    goto out_fail;
1094
1095
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_SupportMonitorLayoutPdu, FALSE))
1096
0
    goto out_fail;
1097
1098
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_MonitorCount, 0))
1099
0
    goto out_fail;
1100
1101
106k
  if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorDefArray, nullptr, 32))
1102
0
    goto out_fail;
1103
1104
106k
  if (!freerdp_settings_set_int32(settings, FreeRDP_MonitorLocalShiftX, 0))
1105
0
    goto out_fail;
1106
1107
106k
  if (!freerdp_settings_set_int32(settings, FreeRDP_MonitorLocalShiftY, 0))
1108
0
    goto out_fail;
1109
1110
106k
  if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, 0))
1111
0
    goto out_fail;
1112
1113
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_MultitransportFlags,
1114
106k
                                   TRANSPORT_TYPE_UDP_FECR))
1115
0
    goto out_fail;
1116
  /* REDIRECTION_VERSION6 needs multitransport advertised. A client uses UDP only when
1117
   * SupportMultitransportUdp is set (/multitransport:udp) and otherwise declines the server's
1118
   * Initiate Multitransport Requests, as a client built without UDP does. */
1119
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_SupportMultitransport, TRUE))
1120
0
    goto out_fail;
1121
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_SupportMultitransportUdp, TRUE))
1122
0
    goto out_fail;
1123
1124
106k
  if (!settings_init_computer_name(settings))
1125
0
    goto out_fail;
1126
1127
106k
  if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RdpServerCertificate, nullptr, 1))
1128
0
    goto out_fail;
1129
1130
106k
  if (!freerdp_capability_buffer_resize(settings, 32, FALSE))
1131
0
    goto out_fail;
1132
1133
106k
  {
1134
106k
    char tmp[32] = WINPR_C_ARRAY_INIT;
1135
106k
    if (!freerdp_settings_set_string_len(settings, FreeRDP_ClientProductId, tmp, sizeof(tmp)))
1136
0
      goto out_fail;
1137
106k
  }
1138
1139
  /* [MS-RDPBCGR] 2.2.7.1.5 Pointer Capability Set (TS_POINTER_CAPABILITYSET)
1140
   *
1141
   * if we are in server mode send a reasonable large cache size,
1142
   * if we are in client mode just set the value to the maximum we want to
1143
   * support and during capability exchange that size will be limited to the
1144
   * sizes the server supports
1145
   *
1146
   * We have chosen 128 cursors in cache which is at worst 128 * 576kB (384x384 pixel cursor with
1147
   * 32bit color depth)
1148
   * */
1149
106k
  if (freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
1150
24.7k
  {
1151
24.7k
    if (!freerdp_settings_set_uint32(settings, FreeRDP_PointerCacheSize, 25) ||
1152
24.7k
        !freerdp_settings_set_uint32(settings, FreeRDP_ColorPointerCacheSize, 25))
1153
0
      goto out_fail;
1154
24.7k
  }
1155
81.6k
  else
1156
81.6k
  {
1157
81.6k
    if (!freerdp_settings_set_uint32(settings, FreeRDP_PointerCacheSize, 128) ||
1158
81.6k
        !freerdp_settings_set_uint32(settings, FreeRDP_ColorPointerCacheSize, 128))
1159
0
      goto out_fail;
1160
81.6k
  }
1161
1162
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_LargePointerFlag,
1163
106k
                                   (LARGE_POINTER_FLAG_96x96 | LARGE_POINTER_FLAG_384x384)) ||
1164
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SoundBeepsEnabled, TRUE) ||
1165
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DrawGdiPlusEnabled, FALSE) ||
1166
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DrawAllowSkipAlpha, TRUE) ||
1167
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DrawAllowColorSubsampling, FALSE) ||
1168
106k
      !freerdp_settings_set_bool(settings, FreeRDP_DrawAllowDynamicColorFidelity, TRUE) ||
1169
106k
      !freerdp_settings_set_bool(settings, FreeRDP_FrameMarkerCommandEnabled, TRUE) ||
1170
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SurfaceFrameMarkerEnabled, TRUE) ||
1171
106k
      !freerdp_settings_set_bool(settings, FreeRDP_AllowCacheWaitingList, TRUE))
1172
0
    goto out_fail;
1173
1174
106k
  const BITMAP_CACHE_V2_CELL_INFO CellInfo[5] = {
1175
106k
    { 600, FALSE }, { 600, FALSE }, { 65536, FALSE }, { 4096, FALSE }, { 2048, FALSE }
1176
106k
  };
1177
106k
  if (!freerdp_settings_set_pointer_len(settings, FreeRDP_BitmapCacheV2CellInfo, CellInfo,
1178
106k
                                        ARRAYSIZE(CellInfo)))
1179
0
    goto out_fail;
1180
1181
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_NoBitmapCompressionHeader, TRUE) ||
1182
106k
      !freerdp_settings_set_bool(settings, FreeRDP_RefreshRect, TRUE) ||
1183
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SuppressOutput, TRUE) ||
1184
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_GlyphSupportLevel, GLYPH_SUPPORT_NONE))
1185
0
    goto out_fail;
1186
106k
  settings->GlyphCache = calloc(10, sizeof(GLYPH_CACHE_DEFINITION));
1187
1188
106k
  if (!settings->GlyphCache)
1189
0
    goto out_fail;
1190
1191
106k
  settings->FragCache = calloc(1, sizeof(GLYPH_CACHE_DEFINITION));
1192
1193
106k
  if (!settings->FragCache)
1194
0
    goto out_fail;
1195
1196
1.16M
  for (size_t x = 0; x < 10; x++)
1197
1.06M
  {
1198
1.06M
    GLYPH_CACHE_DEFINITION cache = WINPR_C_ARRAY_INIT;
1199
1.06M
    cache.cacheEntries = 254;
1200
1.06M
    switch (x)
1201
1.06M
    {
1202
106k
      case 0:
1203
212k
      case 1:
1204
212k
        cache.cacheMaximumCellSize = 4;
1205
212k
        break;
1206
106k
      case 2:
1207
212k
      case 3:
1208
212k
        cache.cacheMaximumCellSize = 8;
1209
212k
        break;
1210
106k
      case 4:
1211
106k
        cache.cacheMaximumCellSize = 16;
1212
106k
        break;
1213
106k
      case 5:
1214
106k
        cache.cacheMaximumCellSize = 32;
1215
106k
        break;
1216
106k
      case 6:
1217
106k
        cache.cacheMaximumCellSize = 64;
1218
106k
        break;
1219
106k
      case 7:
1220
106k
        cache.cacheMaximumCellSize = 128;
1221
106k
        break;
1222
106k
      case 8:
1223
106k
        cache.cacheMaximumCellSize = 256;
1224
106k
        break;
1225
106k
      case 9:
1226
106k
        cache.cacheMaximumCellSize = 256;
1227
106k
        break;
1228
0
      default:
1229
0
        goto out_fail;
1230
1.06M
    }
1231
1232
1.06M
    if (!freerdp_settings_set_pointer_array(settings, FreeRDP_GlyphCache, x, &cache))
1233
0
      goto out_fail;
1234
1.06M
  }
1235
106k
  {
1236
106k
    GLYPH_CACHE_DEFINITION cache = WINPR_C_ARRAY_INIT;
1237
106k
    cache.cacheEntries = 256;
1238
106k
    cache.cacheMaximumCellSize = 256;
1239
106k
    if (!freerdp_settings_set_pointer_array(settings, FreeRDP_FragCache, 0, &cache))
1240
0
      goto out_fail;
1241
106k
  }
1242
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_OffscreenSupportLevel, 0) ||
1243
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_OffscreenCacheSize, 7680) ||
1244
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_OffscreenCacheEntries, 2000) ||
1245
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheSize, 2560) ||
1246
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_DrawNineGridCacheEntries, 256) ||
1247
106k
      !freerdp_settings_set_string(settings, FreeRDP_ClientDir, client_dll) ||
1248
106k
      !freerdp_settings_get_string(settings, FreeRDP_ClientDir) ||
1249
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_RemoteWndSupportLevel,
1250
106k
                                   WINDOW_LEVEL_SUPPORTED | WINDOW_LEVEL_SUPPORTED_EX) ||
1251
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppNumIconCaches, 3) ||
1252
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_RemoteAppNumIconCacheEntries, 12) ||
1253
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_VCChunkSize,
1254
106k
                                   (server && !remote) ? CHANNEL_CHUNK_MAX_LENGTH
1255
106k
                                                       : CHANNEL_CHUNK_LENGTH) ||
1256
      /* [MS-RDPBCGR] 2.2.7.2.7 Large Pointer Capability Set (TS_LARGE_POINTER_CAPABILITYSET)
1257
         requires at least this size */
1258
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_MultifragMaxRequestSize,
1259
106k
                                   server ? 0 : 608299) ||
1260
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayUseSameCredentials, FALSE) ||
1261
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayBypassLocal, FALSE) ||
1262
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayRpcTransport, TRUE) ||
1263
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayHttpTransport, TRUE) ||
1264
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayUdpTransport, TRUE) ||
1265
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayHttpUseWebsockets, TRUE) ||
1266
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayHttpExtAuthSspiNtlm, FALSE) ||
1267
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GatewayArmTransport, FALSE) ||
1268
106k
      !freerdp_settings_set_bool(settings, FreeRDP_FastPathInput, TRUE) ||
1269
106k
      !freerdp_settings_set_bool(settings, FreeRDP_FastPathOutput, TRUE) ||
1270
106k
      !freerdp_settings_set_bool(settings, FreeRDP_LongCredentialsSupported, TRUE) ||
1271
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_FrameAcknowledge, 2) ||
1272
106k
      !freerdp_settings_set_bool(settings, FreeRDP_MouseMotion, TRUE) ||
1273
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_NSCodecColorLossLevel, 3) ||
1274
106k
      !freerdp_settings_set_bool(settings, FreeRDP_NSCodecAllowSubsampling, TRUE) ||
1275
106k
      !freerdp_settings_set_bool(settings, FreeRDP_NSCodecAllowDynamicColorFidelity, TRUE) ||
1276
106k
      !freerdp_settings_set_bool(settings, FreeRDP_AutoReconnectionEnabled, FALSE) ||
1277
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_AutoReconnectMaxRetries, 20) ||
1278
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxThinClient, FALSE) ||
1279
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxSmallCache, TRUE) ||
1280
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressive, FALSE) ||
1281
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressiveV2, FALSE) ||
1282
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxPlanar, TRUE) ||
1283
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxH264, FALSE) ||
1284
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444, FALSE) ||
1285
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxCodecAV1, TRUE) ||
1286
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_GfxCodecAV1Profile, 1) ||
1287
106k
      !freerdp_settings_set_bool(settings, FreeRDP_GfxSendQoeAck, FALSE) ||
1288
106k
      !freerdp_settings_set_bool(settings, FreeRDP_SupportDisplayControl, TRUE))
1289
0
    goto out_fail;
1290
106k
  {
1291
106k
    ARC_CS_PRIVATE_PACKET cookie = WINPR_C_ARRAY_INIT;
1292
106k
    if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ClientAutoReconnectCookie, &cookie,
1293
106k
                                          1))
1294
0
      goto out_fail;
1295
106k
  }
1296
106k
  {
1297
106k
    ARC_SC_PRIVATE_PACKET cookie = WINPR_C_ARRAY_INIT;
1298
106k
    if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ServerAutoReconnectCookie, &cookie,
1299
106k
                                          1))
1300
0
      goto out_fail;
1301
106k
  }
1302
1303
106k
  settings->ClientTimeZone = (LPTIME_ZONE_INFORMATION)calloc(1, sizeof(TIME_ZONE_INFORMATION));
1304
1305
106k
  if (!settings->ClientTimeZone)
1306
0
    goto out_fail;
1307
1308
106k
  if (!settings->ServerMode)
1309
81.6k
  {
1310
81.6k
    DYNAMIC_TIME_ZONE_INFORMATION dynamic = WINPR_C_ARRAY_INIT;
1311
81.6k
    TIME_ZONE_INFORMATION* tz =
1312
81.6k
        freerdp_settings_get_pointer_writable(settings, FreeRDP_ClientTimeZone);
1313
81.6k
    WINPR_ASSERT(tz);
1314
1315
81.6k
    GetTimeZoneInformation(tz);
1316
81.6k
    GetDynamicTimeZoneInformation(&dynamic);
1317
1318
81.6k
    if (!freerdp_settings_set_string_from_utf16N(settings, FreeRDP_DynamicDSTTimeZoneKeyName,
1319
81.6k
                                                 dynamic.TimeZoneKeyName,
1320
81.6k
                                                 ARRAYSIZE(dynamic.TimeZoneKeyName)))
1321
0
      goto out_fail;
1322
1323
81.6k
    if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicDaylightTimeDisabled,
1324
81.6k
                                   dynamic.DynamicDaylightTimeDisabled))
1325
0
      goto out_fail;
1326
81.6k
  }
1327
1328
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_TcpKeepAlive, TRUE) ||
1329
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_TcpKeepAliveRetries, 3) ||
1330
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_TcpKeepAliveDelay, 5) ||
1331
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_TcpKeepAliveInterval, 2) ||
1332
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_TcpAckTimeout, 9000) ||
1333
106k
      !freerdp_settings_set_uint32(settings, FreeRDP_TcpConnectTimeout, 15000))
1334
0
    goto out_fail;
1335
1336
  /* Bound for waiting on a gateway HTTP response (status/header phase and body phase each),
1337
   * separate from FreeRDP_TcpConnectTimeout, which only bounds TCP connection establishment. */
1338
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_GatewayResponseTimeout, 15000))
1339
0
    goto out_fail;
1340
1341
106k
  if (!freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
1342
81.6k
  {
1343
81.6k
    BOOL rc = FALSE;
1344
81.6k
    char* path = nullptr;
1345
81.6k
    if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectClipboard, TRUE))
1346
0
      goto out_fail;
1347
    /* these values are used only by the client part */
1348
81.6k
    path = GetKnownPath(KNOWN_PATH_HOME);
1349
81.6k
    rc = freerdp_settings_set_string(settings, FreeRDP_HomePath, path);
1350
81.6k
    free(path);
1351
1352
81.6k
    if (!rc || !freerdp_settings_get_string(settings, FreeRDP_HomePath))
1353
0
      goto out_fail;
1354
1355
81.6k
    char* config = freerdp_settings_get_config_path();
1356
81.6k
    rc = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, config);
1357
81.6k
    if (rc)
1358
81.6k
    {
1359
81.6k
      char* action = GetCombinedPath(config, "action.sh");
1360
81.6k
      rc = freerdp_settings_set_string(settings, FreeRDP_ActionScript, action);
1361
81.6k
      free(action);
1362
81.6k
    }
1363
1364
81.6k
    free(config);
1365
81.6k
    if (!rc)
1366
0
      goto out_fail;
1367
81.6k
  }
1368
1369
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_SmartcardLogon, FALSE))
1370
0
    goto out_fail;
1371
106k
  if (!freerdp_settings_set_uint32(settings, FreeRDP_TlsSecLevel, FREERDP_TLS_SECLEVEL_112BIT))
1372
0
    goto out_fail;
1373
106k
  settings->OrderSupport = calloc(1, 32);
1374
1375
106k
  if (!freerdp_settings_set_uint16(settings, FreeRDP_TLSMinVersion, TLS1_2_VERSION))
1376
0
    goto out_fail;
1377
106k
  if (!freerdp_settings_set_uint16(settings, FreeRDP_TLSMaxVersion, 0))
1378
0
    goto out_fail;
1379
1380
106k
  if (!settings->OrderSupport)
1381
0
    goto out_fail;
1382
1383
106k
  if (!freerdp_settings_set_default_order_support(settings))
1384
0
    goto out_fail;
1385
1386
106k
  {
1387
106k
    const BOOL enable = freerdp_settings_get_bool(settings, FreeRDP_ServerMode);
1388
106k
    {
1389
106k
      const FreeRDP_Settings_Keys_Bool keys[] = { FreeRDP_SupportGraphicsPipeline,
1390
106k
                                                FreeRDP_SupportStatusInfoPdu,
1391
106k
                                                FreeRDP_SupportErrorInfoPdu,
1392
106k
                                                FreeRDP_SupportAsymetricKeys };
1393
1394
531k
      for (size_t x = 0; x < ARRAYSIZE(keys); x++)
1395
425k
      {
1396
425k
        if (!freerdp_settings_set_bool(settings, keys[x], enable))
1397
0
          goto out_fail;
1398
425k
      }
1399
106k
    }
1400
106k
  }
1401
1402
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_SupportDynamicTimeZone, TRUE))
1403
0
    goto out_fail;
1404
106k
  if (!freerdp_settings_set_bool(settings, FreeRDP_SupportSkipChannelJoin, TRUE))
1405
0
    goto out_fail;
1406
1407
106k
  UUID corrId = WINPR_C_ARRAY_INIT;
1408
106k
  if (UuidCreate(&corrId) != RPC_S_OK)
1409
0
    goto out_fail;
1410
1411
106k
  char buffer[64] = WINPR_C_ARRAY_INIT;
1412
106k
  if (!freerdp_settings_set_string(settings, FreeRDP_CorrelationId,
1413
106k
                                   guid2str(&corrId, buffer, sizeof(buffer))))
1414
0
    goto out_fail;
1415
1416
106k
  if (!settings_load_hkey_local_machine(settings))
1417
0
    goto out_fail;
1418
1419
106k
  return settings;
1420
0
out_fail:
1421
0
  WINPR_PRAGMA_DIAG_PUSH
1422
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
1423
0
  freerdp_settings_free(settings);
1424
0
  WINPR_PRAGMA_DIAG_POP
1425
0
  return nullptr;
1426
106k
}
1427
1428
static void freerdp_settings_free_internal(rdpSettings* settings)
1429
155k
{
1430
155k
  freerdp_server_license_issuers_free(settings);
1431
155k
  freerdp_target_net_addresses_free(settings);
1432
155k
  freerdp_device_collection_free(settings);
1433
155k
  freerdp_static_channel_collection_free(settings);
1434
155k
  freerdp_dynamic_channel_collection_free(settings);
1435
1436
155k
  freerdp_capability_buffer_free(settings);
1437
1438
  /* Free all strings, set other pointers nullptr */
1439
155k
  freerdp_settings_free_keys(settings, TRUE);
1440
155k
}
1441
1442
static void freerdp_settings_free_internal_ensure_reset(rdpSettings* settings)
1443
24.7k
{
1444
24.7k
  settings->ServerLicenseProductIssuersCount = 0;
1445
24.7k
  settings->ServerLicenseProductIssuers = nullptr;
1446
1447
24.7k
  settings->ReceivedCapabilitiesSize = 0;
1448
24.7k
}
1449
1450
void freerdp_settings_free(rdpSettings* settings)
1451
180k
{
1452
180k
  if (!settings)
1453
49.4k
    return;
1454
1455
131k
  freerdp_settings_free_internal(settings);
1456
131k
  free(settings);
1457
131k
}
1458
1459
static BOOL freerdp_settings_int_buffer_copy(rdpSettings* dst, const rdpSettings* settings)
1460
24.7k
{
1461
24.7k
  BOOL rc = FALSE;
1462
1463
24.7k
  if (!dst || !settings)
1464
0
    return FALSE;
1465
1466
24.7k
  typedef struct
1467
24.7k
  {
1468
24.7k
    FreeRDP_Settings_Keys_UInt32 lenKey;
1469
24.7k
    FreeRDP_Settings_Keys_Pointer pointerKey;
1470
24.7k
  } PointerDefs;
1471
1472
24.7k
  PointerDefs pointerDefs[] = {
1473
    /* */
1474
24.7k
    { FreeRDP_LoadBalanceInfoLength, FreeRDP_LoadBalanceInfo },
1475
24.7k
    { FreeRDP_ServerRandomLength, FreeRDP_ServerRandom },
1476
24.7k
    { FreeRDP_ClientRandomLength, FreeRDP_ClientRandom },
1477
24.7k
    { FreeRDP_ServerCertificateLength, FreeRDP_ServerCertificate },
1478
24.7k
    { FreeRDP_ChannelDefArraySize, FreeRDP_ChannelDefArray },
1479
24.7k
    { FreeRDP_NumMonitorIds, FreeRDP_MonitorIds },
1480
24.7k
    { FreeRDP_BitmapCacheV2NumCells, FreeRDP_BitmapCacheV2CellInfo },
1481
24.7k
    { FreeRDP_RedirectionPasswordLength, FreeRDP_RedirectionPassword },
1482
24.7k
    { FreeRDP_RedirectionTsvUrlLength, FreeRDP_RedirectionTsvUrl },
1483
24.7k
    { FreeRDP_RedirectionGuidLength, FreeRDP_RedirectionGuid },
1484
24.7k
    { FreeRDP_MonitorDefArraySize, FreeRDP_MonitorDefArray }
1485
24.7k
  };
1486
1487
296k
  for (size_t i = 0; i < ARRAYSIZE(pointerDefs); i++)
1488
271k
  {
1489
271k
    const PointerDefs* keys = &pointerDefs[i];
1490
271k
    UINT32 n = freerdp_settings_get_uint32(settings, keys->lenKey);
1491
1492
271k
    const void* ptr = freerdp_settings_get_pointer(settings, keys->pointerKey);
1493
271k
    if (!freerdp_settings_set_pointer_len(dst, keys->pointerKey, ptr, n))
1494
0
      goto out_fail;
1495
271k
  }
1496
1497
24.7k
  if (!freerdp_server_license_issuers_copy(dst, settings->ServerLicenseProductIssuers,
1498
24.7k
                                           settings->ServerLicenseProductIssuersCount))
1499
0
    goto out_fail;
1500
1501
24.7k
  if (settings->RdpServerCertificate)
1502
24.7k
  {
1503
24.7k
    rdpCertificate* cert = freerdp_certificate_clone(settings->RdpServerCertificate);
1504
24.7k
    if (!cert)
1505
0
      goto out_fail;
1506
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_RdpServerCertificate, cert, 1))
1507
0
    {
1508
0
      freerdp_certificate_free(cert);
1509
0
      goto out_fail;
1510
0
    }
1511
24.7k
  }
1512
0
  else
1513
0
  {
1514
0
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_RdpServerCertificate, nullptr, 0))
1515
0
      goto out_fail;
1516
0
  }
1517
1518
24.7k
  if (settings->RdpServerRsaKey)
1519
0
  {
1520
0
    rdpPrivateKey* key = freerdp_key_clone(settings->RdpServerRsaKey);
1521
0
    if (!key)
1522
0
      goto out_fail;
1523
0
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_RdpServerRsaKey, key, 1))
1524
0
    {
1525
0
      freerdp_key_free(key);
1526
0
      goto out_fail;
1527
0
    }
1528
0
  }
1529
24.7k
  else
1530
24.7k
  {
1531
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_RdpServerRsaKey, nullptr, 0))
1532
0
      goto out_fail;
1533
24.7k
  }
1534
1535
24.7k
  if (!freerdp_settings_set_uint32(dst, FreeRDP_ChannelCount,
1536
24.7k
                                   freerdp_settings_get_uint32(settings, FreeRDP_ChannelCount)))
1537
0
    goto out_fail;
1538
1539
24.7k
  if (settings->OrderSupport)
1540
24.7k
  {
1541
24.7k
    dst->OrderSupport = calloc(32, sizeof(BYTE));
1542
24.7k
    if (!dst->OrderSupport)
1543
0
      goto out_fail;
1544
1545
24.7k
    CopyMemory(dst->OrderSupport, settings->OrderSupport, 32);
1546
24.7k
  }
1547
1548
24.7k
  if (!freerdp_capability_buffer_copy(dst, settings))
1549
0
    goto out_fail;
1550
1551
24.7k
  {
1552
24.7k
    const UINT32 glyphCacheCount = 10;
1553
24.7k
    const GLYPH_CACHE_DEFINITION* glyphCache =
1554
24.7k
        freerdp_settings_get_pointer(settings, FreeRDP_GlyphCache);
1555
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_GlyphCache, glyphCache, glyphCacheCount))
1556
0
      goto out_fail;
1557
24.7k
  }
1558
1559
24.7k
  {
1560
24.7k
    const UINT32 fragCacheCount = 1;
1561
24.7k
    const GLYPH_CACHE_DEFINITION* fragCache =
1562
24.7k
        freerdp_settings_get_pointer(settings, FreeRDP_FragCache);
1563
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_FragCache, fragCache, fragCacheCount))
1564
0
      goto out_fail;
1565
24.7k
  }
1566
1567
24.7k
  if (!freerdp_settings_set_pointer_len(
1568
24.7k
          dst, FreeRDP_ClientAutoReconnectCookie,
1569
24.7k
          freerdp_settings_get_pointer(settings, FreeRDP_ClientAutoReconnectCookie), 1))
1570
0
    goto out_fail;
1571
24.7k
  if (!freerdp_settings_set_pointer_len(
1572
24.7k
          dst, FreeRDP_ServerAutoReconnectCookie,
1573
24.7k
          freerdp_settings_get_pointer(settings, FreeRDP_ServerAutoReconnectCookie), 1))
1574
0
    goto out_fail;
1575
1576
24.7k
  {
1577
24.7k
    const TIME_ZONE_INFORMATION* tz =
1578
24.7k
        freerdp_settings_get_pointer(settings, FreeRDP_ClientTimeZone);
1579
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_ClientTimeZone, tz, 1))
1580
0
      goto out_fail;
1581
24.7k
  }
1582
1583
24.7k
  {
1584
24.7k
    const UINT32 nrports = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
1585
24.7k
    if (!freerdp_target_net_adresses_reset(dst, nrports))
1586
0
      goto out_fail;
1587
1588
24.7k
    for (UINT32 i = 0; i < nrports; i++)
1589
0
    {
1590
0
      const char* address =
1591
0
          freerdp_settings_get_pointer_array(settings, FreeRDP_TargetNetAddresses, i);
1592
0
      const UINT32* port =
1593
0
          freerdp_settings_get_pointer_array(settings, FreeRDP_TargetNetPorts, i);
1594
1595
0
      if (!freerdp_settings_set_pointer_array(dst, FreeRDP_TargetNetAddresses, i, address))
1596
0
        goto out_fail;
1597
0
      if (!freerdp_settings_set_pointer_array(dst, FreeRDP_TargetNetPorts, i, port))
1598
0
        goto out_fail;
1599
0
    }
1600
24.7k
  }
1601
1602
24.7k
  {
1603
24.7k
    const UINT32 len = freerdp_settings_get_uint32(settings, FreeRDP_DeviceArraySize);
1604
24.7k
    const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_DeviceCount);
1605
1606
24.7k
    if (len < count)
1607
0
      goto out_fail;
1608
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_DeviceArray, nullptr, len))
1609
0
      goto out_fail;
1610
24.7k
    if (!freerdp_settings_set_uint32(dst, FreeRDP_DeviceCount, count))
1611
0
      goto out_fail;
1612
1613
24.7k
    for (size_t index = 0; index < count; index++)
1614
0
    {
1615
0
      const RDPDR_DEVICE* argv =
1616
0
          freerdp_settings_get_pointer_array(settings, FreeRDP_DeviceArray, index);
1617
0
      WINPR_ASSERT(argv);
1618
0
      if (!freerdp_settings_set_pointer_array(dst, FreeRDP_DeviceArray, index, argv))
1619
0
        goto out_fail;
1620
0
    }
1621
24.7k
    WINPR_ASSERT(dst->DeviceArray || (len == 0));
1622
24.7k
    WINPR_ASSERT(len >= count);
1623
24.7k
  }
1624
0
  {
1625
24.7k
    const UINT32 len = freerdp_settings_get_uint32(dst, FreeRDP_StaticChannelArraySize);
1626
24.7k
    const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount);
1627
1628
24.7k
    if (len < count)
1629
0
      goto out_fail;
1630
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_StaticChannelArray, nullptr, len))
1631
0
      goto out_fail;
1632
24.7k
    if (!freerdp_settings_set_uint32(dst, FreeRDP_StaticChannelCount, count))
1633
0
      goto out_fail;
1634
1635
24.7k
    for (size_t index = 0; index < count; index++)
1636
0
    {
1637
0
      const ADDIN_ARGV* argv =
1638
0
          freerdp_settings_get_pointer_array(settings, FreeRDP_StaticChannelArray, index);
1639
0
      WINPR_ASSERT(argv);
1640
0
      if (!freerdp_settings_set_pointer_array(dst, FreeRDP_StaticChannelArray, index, argv))
1641
0
        goto out_fail;
1642
0
    }
1643
24.7k
  }
1644
24.7k
  {
1645
24.7k
    const UINT32 len = freerdp_settings_get_uint32(dst, FreeRDP_DynamicChannelArraySize);
1646
24.7k
    const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount);
1647
1648
24.7k
    if (len < count)
1649
0
      goto out_fail;
1650
24.7k
    if (!freerdp_settings_set_pointer_len(dst, FreeRDP_DynamicChannelArray, nullptr, len))
1651
0
      goto out_fail;
1652
24.7k
    if (!freerdp_settings_set_uint32(dst, FreeRDP_DynamicChannelCount, count))
1653
0
      goto out_fail;
1654
1655
24.7k
    for (size_t index = 0; index < count; index++)
1656
0
    {
1657
0
      const ADDIN_ARGV* argv =
1658
0
          freerdp_settings_get_pointer_array(settings, FreeRDP_DynamicChannelArray, index);
1659
0
      WINPR_ASSERT(argv);
1660
0
      if (!freerdp_settings_set_pointer_array(dst, FreeRDP_DynamicChannelArray, index, argv))
1661
0
        goto out_fail;
1662
0
    }
1663
24.7k
  }
1664
1665
24.7k
  rc = freerdp_settings_set_string(dst, FreeRDP_ActionScript,
1666
24.7k
                                   freerdp_settings_get_string(settings, FreeRDP_ActionScript));
1667
1668
24.7k
out_fail:
1669
24.7k
  return rc;
1670
24.7k
}
1671
1672
BOOL freerdp_settings_copy(rdpSettings* dst, const rdpSettings* src)
1673
24.7k
{
1674
24.7k
  BOOL rc = 0;
1675
1676
24.7k
  if (!dst || !src)
1677
0
    return FALSE;
1678
1679
  /* This is required to free all non string buffers */
1680
24.7k
  freerdp_settings_free_internal(dst);
1681
1682
  /* This copies everything except allocated non string buffers. reset all allocated buffers to
1683
   * nullptr to fix issues during cleanup */
1684
24.7k
  rc = freerdp_settings_clone_keys(dst, src);
1685
24.7k
  if (!rc)
1686
0
    goto out_fail;
1687
24.7k
  freerdp_settings_free_internal_ensure_reset(dst);
1688
1689
  /* Begin copying */
1690
24.7k
  if (!freerdp_settings_int_buffer_copy(dst, src))
1691
0
    goto out_fail;
1692
24.7k
  return TRUE;
1693
0
out_fail:
1694
0
  freerdp_settings_free_internal(dst);
1695
0
  return FALSE;
1696
24.7k
}
1697
1698
rdpSettings* freerdp_settings_clone(const rdpSettings* settings)
1699
24.7k
{
1700
24.7k
  rdpSettings* dst = (rdpSettings*)calloc(1, sizeof(rdpSettings));
1701
1702
24.7k
  if (!freerdp_settings_copy(dst, settings))
1703
0
    goto out_fail;
1704
1705
24.7k
  return dst;
1706
0
out_fail:
1707
0
  WINPR_PRAGMA_DIAG_PUSH
1708
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
1709
0
  freerdp_settings_free(dst);
1710
0
  WINPR_PRAGMA_DIAG_POP
1711
0
  return nullptr;
1712
24.7k
}
1713
#ifdef _MSC_VER
1714
#pragma warning(pop)
1715
#endif
1716
1717
BOOL identity_set_from_settings_with_pwd(SEC_WINNT_AUTH_IDENTITY* identity,
1718
                                         const rdpSettings* settings,
1719
                                         FreeRDP_Settings_Keys_String UserId,
1720
                                         FreeRDP_Settings_Keys_String DomainId,
1721
                                         const WCHAR* Password, size_t pwdLen)
1722
0
{
1723
0
  WINPR_ASSERT(identity);
1724
0
  WINPR_ASSERT(settings);
1725
1726
0
  size_t UserLen = 0;
1727
0
  size_t DomainLen = 0;
1728
1729
0
  WCHAR* Username = freerdp_settings_get_string_as_utf16(settings, UserId, &UserLen);
1730
0
  WCHAR* Domain = freerdp_settings_get_string_as_utf16(settings, DomainId, &DomainLen);
1731
1732
0
  const int rc = sspi_SetAuthIdentityWithLengthW(identity, Username, UserLen, Domain, DomainLen,
1733
0
                                                 Password, pwdLen);
1734
0
  winpr_znfree(Username, UserLen * sizeof(WCHAR));
1735
0
  winpr_znfree(Domain, DomainLen * sizeof(WCHAR));
1736
0
  return (rc >= 0);
1737
0
}
1738
1739
BOOL identity_set_from_settings(SEC_WINNT_AUTH_IDENTITY_W* identity, const rdpSettings* settings,
1740
                                FreeRDP_Settings_Keys_String UserId,
1741
                                FreeRDP_Settings_Keys_String DomainId,
1742
                                FreeRDP_Settings_Keys_String PwdId)
1743
0
{
1744
0
  WINPR_ASSERT(identity);
1745
0
  WINPR_ASSERT(settings);
1746
1747
0
  size_t PwdLen = 0;
1748
1749
0
  WCHAR* Password = freerdp_settings_get_string_as_utf16(settings, PwdId, &PwdLen);
1750
1751
0
  const BOOL rc =
1752
0
      identity_set_from_settings_with_pwd(identity, settings, UserId, DomainId, Password, PwdLen);
1753
0
  winpr_znfree(Password, PwdLen * sizeof(WCHAR));
1754
0
  return rc;
1755
0
}
1756
1757
BOOL identity_set_from_smartcard_hash(SEC_WINNT_AUTH_IDENTITY_W* identity,
1758
                                      const rdpSettings* settings,
1759
                                      FreeRDP_Settings_Keys_String userId,
1760
                                      FreeRDP_Settings_Keys_String domainId,
1761
                                      FreeRDP_Settings_Keys_String pwdId,
1762
                                      WINPR_ATTR_UNUSED const BYTE* certSha1,
1763
                                      WINPR_ATTR_UNUSED size_t sha1len)
1764
0
{
1765
#ifdef _WIN32
1766
  CERT_CREDENTIAL_INFO certInfo = { sizeof(CERT_CREDENTIAL_INFO), WINPR_C_ARRAY_INIT };
1767
  LPWSTR marshalledCredentials = nullptr;
1768
1769
  memcpy(certInfo.rgbHashOfCert, certSha1, MIN(sha1len, sizeof(certInfo.rgbHashOfCert)));
1770
1771
  if (!CredMarshalCredentialW(CertCredential, &certInfo, &marshalledCredentials))
1772
  {
1773
    WLog_ERR(TAG, "error marshalling cert credentials");
1774
    return FALSE;
1775
  }
1776
1777
  size_t pwdLen = 0;
1778
  WCHAR* Password = freerdp_settings_get_string_as_utf16(settings, pwdId, &pwdLen);
1779
  const int rc = sspi_SetAuthIdentityWithLengthW(identity, marshalledCredentials,
1780
                                                 _wcslen(marshalledCredentials), nullptr, 0,
1781
                                                 Password, pwdLen);
1782
  winpr_znfree(Password, pwdLen * sizeof(WCHAR));
1783
  CredFree(marshalledCredentials);
1784
  return (rc >= 0);
1785
#else
1786
0
  return identity_set_from_settings(identity, settings, userId, domainId, pwdId);
1787
0
#endif /* _WIN32 */
1788
0
}
1789
1790
const char* freerdp_settings_glyph_level_string(UINT32 level, char* buffer, size_t size)
1791
0
{
1792
0
  const char* str = "GLYPH_SUPPORT_UNKNOWN";
1793
0
  switch (level)
1794
0
  {
1795
0
    case GLYPH_SUPPORT_NONE:
1796
0
      str = "GLYPH_SUPPORT_NONE";
1797
0
      break;
1798
0
    case GLYPH_SUPPORT_PARTIAL:
1799
0
      str = "GLYPH_SUPPORT_PARTIAL";
1800
0
      break;
1801
0
    case GLYPH_SUPPORT_FULL:
1802
0
      str = "GLYPH_SUPPORT_FULL";
1803
0
      break;
1804
0
    case GLYPH_SUPPORT_ENCODE:
1805
0
      str = "GLYPH_SUPPORT_ENCODE";
1806
0
      break;
1807
0
    default:
1808
0
      break;
1809
0
  }
1810
1811
0
  (void)_snprintf(buffer, size, "%s[0x%08" PRIx32 "]", str, level);
1812
0
  return buffer;
1813
0
}
1814
1815
BOOL freerdp_target_net_adresses_reset(rdpSettings* settings, size_t size)
1816
24.7k
{
1817
24.7k
  freerdp_target_net_addresses_free(settings);
1818
1819
24.7k
  return freerdp_target_net_addresses_resize(settings, size);
1820
24.7k
}
1821
1822
BOOL freerdp_settings_enforce_monitor_exists(rdpSettings* settings)
1823
0
{
1824
0
  const UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
1825
0
  const BOOL fullscreen = freerdp_settings_get_bool(settings, FreeRDP_Fullscreen);
1826
0
  const BOOL multimon = freerdp_settings_get_bool(settings, FreeRDP_UseMultimon);
1827
0
  const BOOL useMonitors = fullscreen || multimon;
1828
1829
0
  const UINT32 size = freerdp_settings_get_uint32(settings, FreeRDP_MonitorDefArraySize);
1830
0
  if (size == 0)
1831
0
  {
1832
0
    if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorDefArray, nullptr, 16))
1833
0
      return FALSE;
1834
0
  }
1835
1836
0
  if (!useMonitors || (count == 0))
1837
0
  {
1838
0
    const UINT32 width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1839
0
    const UINT32 height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1840
0
    const UINT32 pwidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPhysicalWidth);
1841
0
    const UINT32 pheight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPhysicalHeight);
1842
0
    const UINT16 orientation =
1843
0
        freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
1844
0
    const UINT32 desktopScaleFactor =
1845
0
        freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
1846
0
    const UINT32 deviceScaleFactor =
1847
0
        freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
1848
1849
0
    if (!freerdp_settings_set_uint32(settings, FreeRDP_MonitorCount, 1))
1850
0
      return FALSE;
1851
1852
0
    rdpMonitor monitor = WINPR_C_ARRAY_INIT;
1853
0
    monitor.x = 0;
1854
0
    monitor.y = 0;
1855
0
    monitor.width = WINPR_ASSERTING_INT_CAST(int32_t, width);
1856
0
    monitor.height = WINPR_ASSERTING_INT_CAST(int32_t, height);
1857
0
    monitor.is_primary = TRUE;
1858
0
    monitor.orig_screen = 0;
1859
0
    monitor.attributes.physicalWidth = pwidth;
1860
0
    monitor.attributes.physicalHeight = pheight;
1861
0
    monitor.attributes.orientation = orientation;
1862
0
    monitor.attributes.desktopScaleFactor = desktopScaleFactor;
1863
0
    monitor.attributes.deviceScaleFactor = deviceScaleFactor;
1864
0
    if (!freerdp_settings_set_monitor_def_array_sorted(settings, &monitor, 1))
1865
0
      return FALSE;
1866
0
  }
1867
1868
0
  return TRUE;
1869
0
}
1870
1871
void freerdp_settings_sanitize_keyboard_type(wLog* log, rdpSettings* settings, const char* source)
1872
1.58k
{
1873
1.58k
  WINPR_ASSERT(settings);
1874
1875
1.58k
  switch (settings->KeyboardType)
1876
1.58k
  {
1877
2
    case WINPR_KBD_TYPE_IBM_PC_XT:
1878
2
    case WINPR_KBD_TYPE_OLIVETTI_ICO:
1879
14
    case WINPR_KBD_TYPE_IBM_PC_AT:
1880
16
    case WINPR_KBD_TYPE_IBM_ENHANCED:
1881
16
    case WINPR_KBD_TYPE_NOKIA_1050:
1882
16
    case WINPR_KBD_TYPE_NOKIA_9140:
1883
16
    case WINPR_KBD_TYPE_JAPANESE:
1884
16
    case WINPR_KBD_TYPE_KOREAN:
1885
16
      return;
1886
1.56k
    default:
1887
1.56k
      break;
1888
1.58k
  }
1889
1890
1.56k
  if (!log)
1891
0
    log = WLog_Get(TAG);
1892
1.56k
  WLog_Print(log, WLOG_WARN,
1893
1.56k
             "%s: KeyboardType=0x%08" PRIx32
1894
1.56k
             " is not a known WINPR_KBD_TYPE, using WINPR_KBD_TYPE_IBM_ENHANCED instead",
1895
1.56k
             source ? source : "settings", settings->KeyboardType);
1896
1.56k
  settings->KeyboardType = WINPR_KBD_TYPE_IBM_ENHANCED;
1897
1.56k
}
1898
1899
BOOL freerdp_settings_enforce_consistency(rdpSettings* settings)
1900
0
{
1901
0
  if (freerdp_settings_get_bool(settings, FreeRDP_BitmapCacheV3Enabled))
1902
0
  {
1903
0
    settings->OrderSupportFlagsEx |= CACHE_BITMAP_V3_SUPPORT;
1904
0
    settings->OrderSupportFlags |= ORDER_FLAGS_EXTRA_SUPPORT;
1905
0
  }
1906
1907
0
  if (freerdp_settings_get_bool(settings, FreeRDP_FrameMarkerCommandEnabled))
1908
0
  {
1909
0
    settings->OrderSupportFlagsEx |= ALTSEC_FRAME_MARKER_SUPPORT;
1910
0
    settings->OrderSupportFlags |= ORDER_FLAGS_EXTRA_SUPPORT;
1911
0
  }
1912
1913
  /* Try to fix usage mistakes here.
1914
   * When a gateway is requested but no host is given deactivate it.
1915
   * Be loud about this and log warnings.
1916
   */
1917
0
  if (freerdp_settings_get_bool(settings, FreeRDP_GatewayEnabled))
1918
0
  {
1919
0
    const char* host = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname);
1920
0
    if (utils_str_is_empty(host))
1921
0
    {
1922
0
      if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayEnabled, FALSE))
1923
0
        return FALSE;
1924
0
      WLog_WARN(TAG,
1925
0
                "Gateway enabled but GatewayHostname is empty, deactivating gateway support");
1926
0
    }
1927
0
  }
1928
0
  return TRUE;
1929
0
}