22 #include <freerdp/config.h>
26 #include <freerdp/crypto/certificate.h>
30 #include <winpr/crt.h>
31 #include <winpr/file.h>
32 #include <winpr/path.h>
33 #include <winpr/sysinfo.h>
34 #include <winpr/registry.h>
35 #include <winpr/wtsapi.h>
37 #include <freerdp/settings.h>
38 #include <freerdp/build-config.h>
40 #include "../crypto/certificate.h"
41 #include "../crypto/privatekey.h"
42 #include "capabilities.h"
44 #define TAG FREERDP_TAG("settings")
48 #pragma warning(disable : 4244)
51 static const char client_dll[] =
"C:\\Windows\\System32\\mstscax.dll";
53 #define SERVER_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Server"
54 #define CLIENT_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\Client"
55 #define BITMAP_CACHE_KEY CLIENT_KEY "\\BitmapCacheV2"
56 #define GLYPH_CACHE_KEY CLIENT_KEY "\\GlyphCache"
57 #define POINTER_CACHE_KEY CLIENT_KEY "\\PointerCache"
67 static const char* bounds2str(
const struct bounds_t* bounds,
char* buffer,
size_t len)
70 (void)_snprintf(buffer, len,
"{%dx%d-%dx%d}", bounds->x, bounds->y, bounds->x + bounds->width,
71 bounds->y + bounds->height);
75 static struct bounds_t union_rect(const struct bounds_t* a,
const struct bounds_t* b)
80 struct bounds_t u = *a;
86 const INT32 rightA = a->x + a->width;
87 const INT32 rightB = b->x + b->width;
88 const INT32 right = MAX(rightA, rightB);
89 u.width = right - u.x;
91 const INT32 bottomA = a->y + a->height;
92 const INT32 bottomB = b->y + b->height;
93 const INT32 bottom = MAX(bottomA, bottomB);
94 u.height = bottom - u.y;
99 static BOOL intersect_rects(
const struct bounds_t* r1,
const struct bounds_t* r2)
104 const INT32 left = MAX(r1->x, r2->x);
105 const INT32 top = MAX(r1->y, r2->y);
106 const INT32 right = MIN(r1->x + r1->width, r2->x + r2->width);
107 const INT32 bottom = MIN(r1->y + r1->height, r2->y + r2->height);
109 return (left < right) && (top < bottom);
112 static BOOL align_rects(
const struct bounds_t* r1,
const struct bounds_t* r2)
117 const INT32 left = MAX(r1->x, r2->x);
118 const INT32 top = MAX(r1->y, r2->y);
119 const INT32 right = MIN(r1->x + r1->width, r2->x + r2->width);
120 const INT32 bottom = MIN(r1->y + r1->height, r2->y + r2->height);
122 return (left == right) || (top == bottom);
125 static BOOL settings_reg_query_dword_val(HKEY hKey,
const TCHAR* sub, DWORD* value)
130 dwSize =
sizeof(DWORD);
131 if (RegQueryValueEx(hKey, sub, NULL, &dwType, (BYTE*)value, &dwSize) != ERROR_SUCCESS)
133 if (dwType != REG_DWORD)
139 static BOOL settings_reg_query_word_val(HKEY hKey,
const TCHAR* sub, UINT16* value)
143 if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
146 if (dwValue > UINT16_MAX)
149 *value = (UINT16)dwValue;
153 static BOOL settings_reg_query_bool_val(HKEY hKey,
const TCHAR* sub, BOOL* value)
157 if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
159 *value = dwValue != 0;
163 static BOOL settings_reg_query_dword(rdpSettings* settings, FreeRDP_Settings_Keys_UInt32
id,
164 HKEY hKey,
const TCHAR* sub)
168 if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
174 static BOOL settings_reg_query_bool(rdpSettings* settings, FreeRDP_Settings_Keys_Bool
id, HKEY hKey,
179 if (!settings_reg_query_dword_val(hKey, sub, &dwValue))
185 static void settings_client_load_hkey_local_machine(rdpSettings* settings)
189 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, CLIENT_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
191 if (status == ERROR_SUCCESS)
193 settings_reg_query_dword(settings, FreeRDP_DesktopWidth, hKey, _T(
"DesktopWidth"));
194 settings_reg_query_dword(settings, FreeRDP_DesktopHeight, hKey, _T(
"DesktopHeight"));
195 settings_reg_query_bool(settings, FreeRDP_Fullscreen, hKey, _T(
"Fullscreen"));
196 settings_reg_query_dword(settings, FreeRDP_ColorDepth, hKey, _T(
"ColorDepth"));
197 settings_reg_query_dword(settings, FreeRDP_KeyboardType, hKey, _T(
"KeyboardType"));
198 settings_reg_query_dword(settings, FreeRDP_KeyboardSubType, hKey, _T(
"KeyboardSubType"));
199 settings_reg_query_dword(settings, FreeRDP_KeyboardFunctionKey, hKey,
200 _T(
"KeyboardFunctionKeys"));
201 settings_reg_query_dword(settings, FreeRDP_KeyboardLayout, hKey, _T(
"KeyboardLayout"));
202 settings_reg_query_bool(settings, FreeRDP_ExtSecurity, hKey, _T(
"ExtSecurity"));
203 settings_reg_query_bool(settings, FreeRDP_NlaSecurity, hKey, _T(
"NlaSecurity"));
204 settings_reg_query_bool(settings, FreeRDP_TlsSecurity, hKey, _T(
"TlsSecurity"));
205 settings_reg_query_bool(settings, FreeRDP_RdpSecurity, hKey, _T(
"RdpSecurity"));
206 settings_reg_query_bool(settings, FreeRDP_MstscCookieMode, hKey, _T(
"MstscCookieMode"));
207 settings_reg_query_dword(settings, FreeRDP_CookieMaxLength, hKey, _T(
"CookieMaxLength"));
208 settings_reg_query_bool(settings, FreeRDP_BitmapCacheEnabled, hKey, _T(
"BitmapCache"));
209 settings_reg_query_dword(settings, FreeRDP_OffscreenSupportLevel, hKey,
210 _T(
"OffscreenBitmapCache"));
211 settings_reg_query_dword(settings, FreeRDP_OffscreenCacheSize, hKey,
212 _T(
"OffscreenBitmapCacheSize"));
213 settings_reg_query_dword(settings, FreeRDP_OffscreenCacheEntries, hKey,
214 _T(
"OffscreenBitmapCacheEntries"));
219 RegOpenKeyExA(HKEY_LOCAL_MACHINE, BITMAP_CACHE_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
221 if (status == ERROR_SUCCESS)
223 settings_reg_query_dword(settings, FreeRDP_BitmapCacheV2NumCells, hKey, _T(
"NumCells"));
224 for (
unsigned x = 0; x < 5; x++)
227 TCHAR numentries[64] = { 0 };
228 TCHAR persist[64] = { 0 };
230 (void)_sntprintf(numentries, ARRAYSIZE(numentries), _T(
"Cell%uNumEntries"), x);
231 (void)_sntprintf(persist, ARRAYSIZE(persist), _T(
"Cell%uPersistent"), x);
232 if (!settings_reg_query_dword_val(hKey, numentries, &val) ||
233 !settings_reg_query_bool_val(hKey, persist, &cache.persistent) ||
234 !freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, x,
236 WLog_WARN(TAG,
"Failed to load registry keys to settings!");
237 cache.numEntries = val;
240 settings_reg_query_bool(settings, FreeRDP_AllowCacheWaitingList, hKey,
241 _T(
"AllowCacheWaitingList"));
246 RegOpenKeyExA(HKEY_LOCAL_MACHINE, GLYPH_CACHE_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
248 if (status == ERROR_SUCCESS)
251 UINT32 GlyphSupportLevel = 0;
252 settings_reg_query_dword(settings, FreeRDP_GlyphSupportLevel, hKey, _T(
"SupportLevel"));
256 TCHAR numentries[64] = { 0 };
257 TCHAR maxsize[64] = { 0 };
258 (void)_sntprintf(numentries, ARRAYSIZE(numentries), _T(
"Cache%uNumEntries"), x);
259 (void)_sntprintf(maxsize, ARRAYSIZE(maxsize), _T(
"Cache%uMaxCellSize"), x);
261 settings_reg_query_word_val(hKey, numentries, &cache.cacheEntries);
262 settings_reg_query_word_val(hKey, maxsize, &cache.cacheMaximumCellSize);
263 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_GlyphCache, x, &cache))
264 WLog_WARN(TAG,
"Failed to store GlyphCache %" PRIuz, x);
268 settings_reg_query_word_val(hKey, _T(
"FragCacheNumEntries"), &cache.cacheEntries);
269 settings_reg_query_word_val(hKey, _T(
"FragCacheMaxCellSize"),
270 &cache.cacheMaximumCellSize);
271 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_FragCache, x, &cache))
272 WLog_WARN(TAG,
"Failed to store FragCache");
278 WLog_WARN(TAG,
"Failed to load registry keys to settings!");
282 RegOpenKeyExA(HKEY_LOCAL_MACHINE, POINTER_CACHE_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
284 if (status == ERROR_SUCCESS)
286 settings_reg_query_dword(settings, FreeRDP_LargePointerFlag, hKey, _T(
"LargePointer"));
287 settings_reg_query_dword(settings, FreeRDP_PointerCacheSize, hKey, _T(
"PointerCacheSize"));
288 settings_reg_query_dword(settings, FreeRDP_ColorPointerCacheSize, hKey,
289 _T(
"ColorPointerCacheSize"));
294 static void settings_server_load_hkey_local_machine(rdpSettings* settings)
299 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, SERVER_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
301 if (status != ERROR_SUCCESS)
304 settings_reg_query_bool(settings, FreeRDP_ExtSecurity, hKey, _T(
"ExtSecurity"));
305 settings_reg_query_bool(settings, FreeRDP_NlaSecurity, hKey, _T(
"NlaSecurity"));
306 settings_reg_query_bool(settings, FreeRDP_TlsSecurity, hKey, _T(
"TlsSecurity"));
307 settings_reg_query_dword(settings, FreeRDP_TlsSecLevel, hKey, _T(
"TlsSecLevel"));
308 settings_reg_query_bool(settings, FreeRDP_RdpSecurity, hKey, _T(
"RdpSecurity"));
313 static void settings_load_hkey_local_machine(rdpSettings* settings)
316 settings_server_load_hkey_local_machine(settings);
318 settings_client_load_hkey_local_machine(settings);
321 static BOOL settings_init_computer_name(rdpSettings* settings)
323 CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1] = { 0 };
324 DWORD nSize = ARRAYSIZE(computerName);
326 if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
334 void freerdp_settings_print_warnings(
const rdpSettings* settings)
337 if (level != GLYPH_SUPPORT_NONE)
339 char buffer[32] = { 0 };
340 WLog_WARN(TAG,
"[experimental] enabled GlyphSupportLevel %s, expect visual artefacts!",
341 freerdp_settings_glyph_level_string(level, buffer,
sizeof(buffer)));
345 static BOOL monitor_operlaps(
const rdpSettings* settings, UINT32 orig, UINT32 start, UINT32 count,
348 const struct bounds_t rect1 = {
349 .x = compare->x, .y = compare->y, .width = compare->width, .height = compare->height
351 for (UINT32 x = start; x < count; x++)
354 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
355 const struct bounds_t rect2 = {
356 .x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
359 if (intersect_rects(&rect1, &rect2))
361 char buffer1[32] = { 0 };
362 char buffer2[32] = { 0 };
364 WLog_ERR(TAG,
"Monitor %" PRIu32
" and %" PRIu32
" are overlapping:", orig, x);
365 WLog_ERR(TAG,
"%s overlapps with %s", bounds2str(&rect1, buffer1,
sizeof(buffer1)),
366 bounds2str(&rect2, buffer2,
sizeof(buffer2)));
369 "Mulitimonitor mode requested, but local layout has gaps or overlapping areas!");
371 "Please reconfigure your local monitor setup so that there are no gaps or "
372 "overlapping areas!");
379 static BOOL monitor_has_gaps(
const rdpSettings* settings, UINT32 start, UINT32 count,
382 const struct bounds_t rect1 = {
383 .x = compare->x, .y = compare->y, .width = compare->width, .height = compare->height
386 BOOL hasNeighbor = FALSE;
387 for (UINT32 i = 0; i < count; i++)
393 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, i);
395 const struct bounds_t rect2 = {
396 .x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
398 if (align_rects(&rect1, &rect2))
409 "Monitor configuration has gaps! Monitor %" PRIu32
" does not have any neighbor",
416 static void alloc_free(UINT32** ptr)
421 WINPR_ATTR_MALLOC(alloc_free, 1)
422 static UINT32** alloc_array(
size_t count)
425 BYTE* array = calloc(count *
sizeof(uintptr_t), count *
sizeof(UINT32));
426 UINT32** dst = (UINT32**)array;
427 UINT32* val = (UINT32*)(array + count *
sizeof(uintptr_t));
428 for (
size_t x = 0; x < count; x++)
442 static BOOL find_path_exists_with_dijkstra(UINT32** graph,
size_t count, UINT32 start)
447 WINPR_ASSERT(start < count);
449 UINT32** cost = alloc_array(count);
452 UINT32* distance = calloc(count,
sizeof(UINT32));
453 WINPR_ASSERT(distance);
455 UINT32* visited = calloc(count,
sizeof(UINT32));
456 WINPR_ASSERT(visited);
458 UINT32* parent = calloc(count,
sizeof(UINT32));
459 WINPR_ASSERT(parent);
461 for (
size_t x = 0; x < count; x++)
463 for (
size_t y = 0; y < count; y++)
465 if (graph[x][y] == 0)
466 cost[x][y] = UINT32_MAX;
468 cost[x][y] = graph[x][y];
472 for (UINT32 x = 0; x < count; x++)
474 distance[x] = cost[start][x];
483 UINT32 nextnode = UINT32_MAX;
484 while (pos < count - 1)
486 UINT32 mindistance = UINT32_MAX;
488 for (UINT32 x = 0; x < count; x++)
490 if ((distance[x] < mindistance) && !visited[x])
492 mindistance = distance[x];
497 visited[nextnode] = 1;
499 for (
size_t y = 0; y < count; y++)
503 UINT32 dist = mindistance + cost[nextnode][y];
504 if (dist < distance[y])
507 parent[y] = nextnode;
515 for (
size_t x = 0; x < count; x++)
519 if (distance[x] == UINT32_MAX)
521 WLog_ERR(TAG,
"monitor %" PRIu32
" not connected with monitor %" PRIuz, start, x);
535 static BOOL freerdp_settings_client_monitors_have_gaps(
const rdpSettings* settings)
542 UINT32** graph = alloc_array(count);
545 for (UINT32 x = 0; x < count; x++)
548 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
549 if (monitor_has_gaps(settings, x, count, monitor, graph))
553 rc = !find_path_exists_with_dijkstra(graph, count, 0);
561 static void log_monitor(UINT32 idx,
const rdpMonitor* monitor, wLog* log, DWORD level)
563 WINPR_ASSERT(monitor);
565 WLog_Print(log, level,
566 "[%" PRIu32
"] [%s] {%dx%d-%dx%d} [%" PRIu32
"] {%" PRIu32
"x%" PRIu32
567 ", orientation: %" PRIu32
", desktopScale: %" PRIu32
", deviceScale: %" PRIu32
"}",
568 idx, monitor->is_primary ?
"primary" :
" ", monitor->x, monitor->y,
569 monitor->width, monitor->height, monitor->orig_screen,
570 monitor->attributes.physicalWidth, monitor->attributes.physicalHeight,
571 monitor->attributes.orientation, monitor->attributes.desktopScaleFactor,
572 monitor->attributes.deviceScaleFactor);
575 static void log_monitor_configuration(
const rdpSettings* settings, wLog* log, DWORD level)
578 WLog_Print(log, level,
"[BEGIN] MonitorDefArray[%" PRIu32
"]", count);
579 for (UINT32 x = 0; x < count; x++)
582 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
583 log_monitor(x, monitor, log, level);
585 WLog_Print(log, level,
"[END] MonitorDefArray[%" PRIu32
"]", count);
588 static BOOL freerdp_settings_client_monitors_overlap(
const rdpSettings* settings)
591 for (UINT32 x = 0; x < count; x++)
594 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
595 if (monitor_operlaps(settings, x, x + 1, count, monitor))
604 static BOOL freerdp_settings_client_monitors_check_primary_and_origin(
const rdpSettings* settings)
607 BOOL havePrimary = FALSE;
608 BOOL foundOrigin = FALSE;
611 struct bounds_t bounds = { 0 };
615 WLog_WARN(TAG,
"Monitor configuration empty.");
619 for (UINT32 x = 0; x < count; x++)
622 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x);
623 struct bounds_t cur = {
624 .x = monitor->x, .y = monitor->y, .width = monitor->width, .height = monitor->height
627 bounds = union_rect(&bounds, &cur);
629 if (monitor->is_primary)
633 WLog_ERR(TAG,
"Monitor configuration contains multiple primary monitors!");
639 if ((monitor->x == 0) && (monitor->y == 0))
643 WLog_ERR(TAG,
"Monitor configuration does have multiple origin 0/0");
650 if ((bounds.width > 32766) || (bounds.width < 200))
653 "Monitor configuration virtual desktop width must be 200 <= %" PRId32
" <= 32766",
657 if ((bounds.height > 32766) || (bounds.height < 200))
660 "Monitor configuration virtual desktop height must be 200 <= %" PRId32
" <= 32766",
667 WLog_ERR(TAG,
"Monitor configuration does not contain a primary monitor!");
672 WLog_ERR(TAG,
"Monitor configuration must start at 0/0 for first monitor!");
679 BOOL freerdp_settings_check_client_after_preconnect(
const rdpSettings* settings)
681 wLog* log = WLog_Get(TAG);
683 log_monitor_configuration(settings, log, WLOG_DEBUG);
684 if (freerdp_settings_client_monitors_overlap(settings))
686 if (freerdp_settings_client_monitors_have_gaps(settings))
688 if (!freerdp_settings_client_monitors_check_primary_and_origin(settings))
692 DWORD level = WLOG_ERROR;
693 WLog_Print(log, level,
"Invalid or unsupported monitor configuration detected");
694 WLog_Print(log, level,
"Check if the configuration is valid.");
695 WLog_Print(log, level,
696 "If you suspect a bug create a new issue at "
697 "https://github.com/FreeRDP/FreeRDP/issues/new");
700 "Provide at least the following log lines detailing your monitor configuration:");
701 log_monitor_configuration(settings, log, level);
707 BOOL freerdp_settings_set_default_order_support(rdpSettings* settings)
713 ZeroMemory(OrderSupport, 32);
714 OrderSupport[NEG_DSTBLT_INDEX] = TRUE;
715 OrderSupport[NEG_PATBLT_INDEX] = TRUE;
716 OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
717 OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE;
718 OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE;
719 OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE;
720 OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE;
721 OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE;
722 OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE;
723 OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE;
724 OrderSupport[NEG_LINETO_INDEX] = TRUE;
725 OrderSupport[NEG_POLYLINE_INDEX] = TRUE;
726 OrderSupport[NEG_MEMBLT_INDEX] =
728 OrderSupport[NEG_MEM3BLT_INDEX] =
730 OrderSupport[NEG_MEMBLT_V2_INDEX] =
732 OrderSupport[NEG_MEM3BLT_V2_INDEX] =
734 OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
735 OrderSupport[NEG_GLYPH_INDEX_INDEX] =
737 OrderSupport[NEG_FAST_INDEX_INDEX] =
739 OrderSupport[NEG_FAST_GLYPH_INDEX] =
741 OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
742 OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
743 OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
744 OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
748 BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count)
750 WINPR_ASSERT(settings);
751 WINPR_ASSERT(count > 0);
752 WINPR_ASSERT(count == 32);
754 freerdp_capability_buffer_free(settings);
755 WINPR_ASSERT(settings->ReceivedCapabilitiesSize == 0);
757 settings->ReceivedCapabilitiesSize = count;
758 void* tmp = realloc(settings->ReceivedCapabilities, count *
sizeof(BYTE));
761 memset(tmp, 0, count *
sizeof(BYTE));
762 settings->ReceivedCapabilities = tmp;
764 tmp = realloc((
void*)settings->ReceivedCapabilityData, count *
sizeof(BYTE*));
767 memset(tmp, 0, count *
sizeof(BYTE*));
768 settings->ReceivedCapabilityData = (BYTE**)tmp;
770 tmp = realloc(settings->ReceivedCapabilityDataSizes, count *
sizeof(UINT32));
773 memset(tmp, 0, count *
sizeof(UINT32));
774 settings->ReceivedCapabilityDataSizes = tmp;
776 return (settings->ReceivedCapabilities && settings->ReceivedCapabilityData &&
777 settings->ReceivedCapabilityDataSizes);
780 #if !defined(WITH_FULL_CONFIG_PATH)
781 static char* freerdp_settings_get_legacy_config_path(
void)
783 char product[
sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
785 for (
size_t i = 0; i <
sizeof(product); i++)
786 product[i] = (
char)tolower(FREERDP_PRODUCT_STRING[i]);
788 return GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
798 #if !defined(WITH_FULL_CONFIG_PATH)
799 if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING) == 0)
800 return freerdp_settings_get_legacy_config_path();
803 char* base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING);
805 path = GetCombinedPath(base, FREERDP_PRODUCT_STRING);
813 char* issuers[] = {
"FreeRDP",
"FreeRDP-licenser" };
815 const BOOL remote = (flags & FREERDP_SETTINGS_REMOTE_MODE) != 0 ? TRUE : FALSE;
816 rdpSettings* settings = (rdpSettings*)calloc(1,
sizeof(rdpSettings));
821 if (!server && !remote)
824 "a85cf173-4192-42f8-81fa-777a763e6e2c"))
827 "login.microsoftonline.com"))
838 ORIENTATION_LANDSCAPE))
846 SURFCMDS_SET_SURFACE_BITS | SURFCMDS_STREAM_SURFACE_BITS |
847 SURFCMDS_FRAME_MARKER))
854 TS_CAPS_PROTOCOLVERSION))
858 CLIPRDR_FLAG_DEFAULT_MASK))
863 "FreeRDP-licensing-server"))
867 if (!freerdp_server_license_issuers_copy(settings, issuers, ARRAYSIZE(issuers)))
871 RNS_UD_32BPP_SUPPORT | RNS_UD_24BPP_SUPPORT |
872 RNS_UD_16BPP_SUPPORT | RNS_UD_15BPP_SUPPORT))
882 settings, FreeRDP_RemoteApplicationSupportMask,
883 RAIL_LEVEL_SUPPORTED | RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED |
884 RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED | RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED |
885 RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED |
886 RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED | RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED |
887 RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED) ||
890 NEGOTIATE_ORDER_SUPPORT | ZERO_BOUNDS_DELTA_SUPPORT |
891 COLOR_INDEX_SUPPORT) ||
914 DEFAULT_COOKIE_MAX_LENGTH) ||
922 KEYBOARD_HOOK_FULLSCREEN_ONLY) ||
941 CONNECTION_TYPE_AUTODETECT) ||
983 TRANSPORT_TYPE_UDP_FECR))
988 if (!settings_init_computer_name(settings))
994 if (!freerdp_capability_buffer_allocate(settings, 32))
998 char tmp[32] = { 0 };
1027 (LARGE_POINTER_FLAG_96x96 | LARGE_POINTER_FLAG_384x384)) ||
1038 settings->BitmapCacheV2CellInfo =
1041 if (!settings->BitmapCacheV2CellInfo)
1046 cache.numEntries = 600;
1047 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 0,
1049 !freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 1, &cache))
1051 cache.numEntries = 2048;
1052 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 2,
1054 !freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 4, &cache))
1056 cache.numEntries = 4096;
1057 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, 3, &cache))
1067 if (!settings->GlyphCache)
1072 if (!settings->FragCache)
1075 for (
size_t x = 0; x < 10; x++)
1078 cache.cacheEntries = 254;
1083 cache.cacheMaximumCellSize = 4;
1087 cache.cacheMaximumCellSize = 8;
1090 cache.cacheMaximumCellSize = 16;
1093 cache.cacheMaximumCellSize = 32;
1096 cache.cacheMaximumCellSize = 64;
1099 cache.cacheMaximumCellSize = 128;
1102 cache.cacheMaximumCellSize = 256;
1105 cache.cacheMaximumCellSize = 256;
1111 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_GlyphCache, x, &cache))
1116 cache.cacheEntries = 256;
1117 cache.cacheMaximumCellSize = 256;
1118 if (!freerdp_settings_set_pointer_array(settings, FreeRDP_FragCache, 0, &cache))
1129 WINDOW_LEVEL_SUPPORTED | WINDOW_LEVEL_SUPPORTED_EX) ||
1133 (server && !remote) ? CHANNEL_CHUNK_MAX_LENGTH
1134 : CHANNEL_CHUNK_LENGTH) ||
1138 server ? 0 : 608299) ||
1181 if (!settings->ClientTimeZone)
1184 if (!settings->ServerMode)
1191 GetTimeZoneInformation(tz);
1192 GetDynamicTimeZoneInformation(&dynamic);
1195 dynamic.TimeZoneKeyName,
1196 ARRAYSIZE(dynamic.TimeZoneKeyName)))
1200 dynamic.DynamicDaylightTimeDisabled))
1219 path = GetKnownPath(KNOWN_PATH_HOME);
1230 char* action = GetCombinedPath(config,
"action.sh");
1240 settings_load_hkey_local_machine(settings);
1246 settings->OrderSupport = calloc(1, 32);
1253 if (!settings->OrderSupport)
1256 if (!freerdp_settings_set_default_order_support(settings))
1262 const FreeRDP_Settings_Keys_Bool keys[] = { FreeRDP_SupportGraphicsPipeline,
1263 FreeRDP_SupportStatusInfoPdu,
1264 FreeRDP_SupportErrorInfoPdu,
1265 FreeRDP_SupportAsymetricKeys };
1267 for (
size_t x = 0; x < ARRAYSIZE(keys); x++)
1281 WINPR_PRAGMA_DIAG_PUSH
1282 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
1284 WINPR_PRAGMA_DIAG_POP
1288 static void freerdp_settings_free_internal(rdpSettings* settings)
1290 freerdp_server_license_issuers_free(settings);
1291 freerdp_target_net_addresses_free(settings);
1292 freerdp_device_collection_free(settings);
1293 freerdp_static_channel_collection_free(settings);
1294 freerdp_dynamic_channel_collection_free(settings);
1296 freerdp_capability_buffer_free(settings);
1299 freerdp_settings_free_keys(settings, TRUE);
1307 freerdp_settings_free_internal(settings);
1311 static BOOL freerdp_settings_int_buffer_copy(rdpSettings* _settings,
const rdpSettings* settings)
1315 if (!_settings || !settings)
1320 FreeRDP_Settings_Keys_UInt32 lenKey;
1321 FreeRDP_Settings_Keys_Pointer pointerKey;
1324 PointerDefs pointerDefs[] = {
1326 { FreeRDP_LoadBalanceInfoLength, FreeRDP_LoadBalanceInfo },
1327 { FreeRDP_ServerRandomLength, FreeRDP_ServerRandom },
1328 { FreeRDP_ClientRandomLength, FreeRDP_ClientRandom },
1329 { FreeRDP_ServerCertificateLength, FreeRDP_ServerCertificate },
1330 { FreeRDP_ChannelDefArraySize, FreeRDP_ChannelDefArray },
1331 { FreeRDP_NumMonitorIds, FreeRDP_MonitorIds },
1332 { FreeRDP_BitmapCacheV2NumCells, FreeRDP_BitmapCacheV2CellInfo },
1333 { FreeRDP_RedirectionPasswordLength, FreeRDP_RedirectionPassword },
1334 { FreeRDP_RedirectionTsvUrlLength, FreeRDP_RedirectionTsvUrl },
1335 { FreeRDP_RedirectionGuidLength, FreeRDP_RedirectionGuid },
1336 { FreeRDP_MonitorDefArraySize, FreeRDP_MonitorDefArray }
1339 for (
size_t i = 0; i < ARRAYSIZE(pointerDefs); i++)
1341 const PointerDefs* keys = &pointerDefs[i];
1349 if (!freerdp_server_license_issuers_copy(_settings, settings->ServerLicenseProductIssuers,
1350 settings->ServerLicenseProductIssuersCount))
1353 if (settings->RdpServerCertificate)
1355 rdpCertificate* cert = freerdp_certificate_clone(settings->RdpServerCertificate);
1367 if (settings->RdpServerRsaKey)
1369 rdpPrivateKey* key = freerdp_key_clone(settings->RdpServerRsaKey);
1385 _settings->OrderSupport = malloc(32);
1386 if (!_settings->OrderSupport)
1389 if (!freerdp_capability_buffer_copy(_settings, settings))
1391 CopyMemory(_settings->OrderSupport, settings->OrderSupport, 32);
1393 const UINT32 glyphCacheCount = 10;
1400 const UINT32 fragCacheCount = 1;
1407 _settings, FreeRDP_ClientAutoReconnectCookie,
1411 _settings, FreeRDP_ServerAutoReconnectCookie,
1421 if (!freerdp_target_net_adresses_reset(_settings, nrports))
1424 for (UINT32 i = 0; i < nrports; i++)
1426 const char* address =
1427 freerdp_settings_get_pointer_array(settings, FreeRDP_TargetNetAddresses, i);
1428 const UINT32* port =
1429 freerdp_settings_get_pointer_array(settings, FreeRDP_TargetNetPorts, i);
1430 if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_TargetNetAddresses, i, address))
1432 if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_TargetNetPorts, i, port))
1447 for (
size_t index = 0; index < count; index++)
1450 freerdp_settings_get_pointer_array(settings, FreeRDP_DeviceArray, index);
1451 if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_DeviceArray, index, argv))
1466 for (
size_t index = 0; index < count; index++)
1469 freerdp_settings_get_pointer_array(settings, FreeRDP_StaticChannelArray, index);
1470 if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_StaticChannelArray, index,
1486 for (
size_t index = 0; index < count; index++)
1489 freerdp_settings_get_pointer_array(settings, FreeRDP_DynamicChannelArray, index);
1490 if (!freerdp_settings_set_pointer_array(_settings, FreeRDP_DynamicChannelArray, index,
1507 if (!settings || !_settings)
1511 freerdp_settings_free_internal(_settings);
1514 rc = freerdp_settings_clone_keys(_settings, settings);
1516 _settings->LoadBalanceInfo = NULL;
1517 _settings->ServerRandom = NULL;
1518 _settings->ClientRandom = NULL;
1519 _settings->ServerCertificate = NULL;
1520 _settings->RdpServerCertificate = NULL;
1521 _settings->RdpServerRsaKey = NULL;
1522 _settings->ChannelDefArray = NULL;
1523 _settings->MonitorDefArray = NULL;
1524 _settings->MonitorIds = NULL;
1525 _settings->OrderSupport = NULL;
1526 _settings->BitmapCacheV2CellInfo = NULL;
1527 _settings->GlyphCache = NULL;
1528 _settings->FragCache = NULL;
1529 _settings->ClientAutoReconnectCookie = NULL;
1530 _settings->ServerAutoReconnectCookie = NULL;
1531 _settings->ClientTimeZone = NULL;
1532 _settings->RedirectionPassword = NULL;
1533 _settings->RedirectionTsvUrl = NULL;
1534 _settings->TargetNetAddresses = NULL;
1535 _settings->TargetNetPorts = NULL;
1536 _settings->RedirectionGuid = NULL;
1537 _settings->DeviceArray = NULL;
1538 _settings->StaticChannelArray = NULL;
1539 _settings->DynamicChannelArray = NULL;
1540 _settings->ReceivedCapabilities = NULL;
1541 _settings->ReceivedCapabilityData = NULL;
1542 _settings->ReceivedCapabilityDataSizes = NULL;
1544 _settings->ServerLicenseProductIssuersCount = 0;
1545 _settings->ServerLicenseProductIssuers = NULL;
1551 if (!freerdp_settings_int_buffer_copy(_settings, settings))
1555 freerdp_settings_free_internal(_settings);
1561 rdpSettings* _settings = (rdpSettings*)calloc(1,
sizeof(rdpSettings));
1568 WINPR_PRAGMA_DIAG_PUSH
1569 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
1571 WINPR_PRAGMA_DIAG_POP
1575 #pragma warning(pop)
1578 static void zfree(WCHAR* str,
size_t len)
1581 memset(str, 0, len *
sizeof(WCHAR));
1585 BOOL identity_set_from_settings_with_pwd(SEC_WINNT_AUTH_IDENTITY* identity,
1586 const rdpSettings* settings,
1587 FreeRDP_Settings_Keys_String UserId,
1588 FreeRDP_Settings_Keys_String DomainId,
1589 const WCHAR* Password,
size_t pwdLen)
1591 WINPR_ASSERT(identity);
1592 WINPR_ASSERT(settings);
1595 size_t DomainLen = 0;
1600 const int rc = sspi_SetAuthIdentityWithLengthW(identity, Username, UserLen, Domain, DomainLen,
1602 zfree(Username, UserLen);
1603 zfree(Domain, DomainLen);
1610 FreeRDP_Settings_Keys_String UserId,
1611 FreeRDP_Settings_Keys_String DomainId,
1612 FreeRDP_Settings_Keys_String PwdId)
1614 WINPR_ASSERT(identity);
1615 WINPR_ASSERT(settings);
1622 identity_set_from_settings_with_pwd(identity, settings, UserId, DomainId, Password, PwdLen);
1623 zfree(Password, PwdLen);
1628 const rdpSettings* settings,
1629 FreeRDP_Settings_Keys_String userId,
1630 FreeRDP_Settings_Keys_String domainId,
1631 FreeRDP_Settings_Keys_String pwdId,
const BYTE* certSha1,
1636 LPWSTR marshalledCredentials = NULL;
1638 memcpy(certInfo.rgbHashOfCert, certSha1, MIN(sha1len,
sizeof(certInfo.rgbHashOfCert)));
1640 if (!CredMarshalCredentialW(CertCredential, &certInfo, &marshalledCredentials))
1642 WLog_ERR(TAG,
"error marshalling cert credentials");
1648 const int rc = sspi_SetAuthIdentityWithLengthW(
1649 identity, marshalledCredentials, _wcslen(marshalledCredentials), NULL, 0, Password, pwdLen);
1650 zfree(Password, pwdLen);
1651 CredFree(marshalledCredentials);
1656 if (!identity_set_from_settings(identity, settings, userId, domainId, pwdId))
1662 const char* freerdp_settings_glyph_level_string(UINT32 level,
char* buffer,
size_t size)
1664 const char* str =
"GLYPH_SUPPORT_UNKNOWN";
1667 case GLYPH_SUPPORT_NONE:
1668 str =
"GLYPH_SUPPORT_NONE";
1670 case GLYPH_SUPPORT_PARTIAL:
1671 str =
"GLYPH_SUPPORT_PARTIAL";
1673 case GLYPH_SUPPORT_FULL:
1674 str =
"GLYPH_SUPPORT_FULL";
1676 case GLYPH_SUPPORT_ENCODE:
1677 str =
"GLYPH_SUPPORT_ENCODE";
1683 (void)_snprintf(buffer, size,
"%s[0x%08" PRIx32
"]", str, level);
1687 BOOL freerdp_target_net_adresses_reset(rdpSettings* settings,
size_t size)
1689 freerdp_target_net_addresses_free(settings);
1693 if (!freerdp_settings_set_pointer_len_(settings, FreeRDP_TargetNetPorts,
1694 FreeRDP_UINT32_UNUSED, NULL, size,
sizeof(UINT32)))
1696 if (!freerdp_settings_set_pointer_len_(settings, FreeRDP_TargetNetAddresses,
1697 FreeRDP_TargetNetAddressCount, NULL, size,
1704 BOOL freerdp_settings_enforce_monitor_exists(rdpSettings* settings)
1710 const BOOL useMonitors = fullscreen || multimon;
1724 if (!useMonitors || (count == 0))
1730 const UINT16 orientation =
1732 const UINT32 desktopScaleFactor =
1734 const UINT32 deviceScaleFactor =
1741 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, 0);
1746 WINPR_ASSERT(width <= INT32_MAX);
1747 monitor->width = (INT32)width;
1748 WINPR_ASSERT(height <= INT32_MAX);
1749 monitor->height = (INT32)height;
1750 monitor->is_primary = TRUE;
1751 monitor->orig_screen = 0;
1752 monitor->attributes.physicalWidth = pwidth;
1753 monitor->attributes.physicalHeight = pheight;
1754 monitor->attributes.orientation = orientation;
1755 monitor->attributes.desktopScaleFactor = desktopScaleFactor;
1756 monitor->attributes.deviceScaleFactor = deviceScaleFactor;
1758 else if (fullscreen || (multimon && (count == 1)))
1763 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, 0);
1768 monitor->is_primary = TRUE;
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_string(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param)
Sets a string settings value. The param is copied.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API const void * freerdp_settings_get_pointer(const rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a immutable pointer settings value.
FREERDP_API BOOL freerdp_settings_set_string_from_utf16N(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const WCHAR *param, size_t length)
Sets a string settings value. The param is converted to UTF-8 and the copy stored.
rdpSettings * freerdp_settings_new(DWORD flags)
creates a new setting struct
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API BOOL freerdp_settings_set_pointer_len(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id, const void *data, size_t len)
Set a pointer to value data.
char * freerdp_settings_get_config_path(void)
return the configuration directory for the library
void freerdp_settings_free(rdpSettings *settings)
Free a settings struct with all data in it.
#define FREERDP_SETTINGS_SERVER_MODE
FREERDP_API UINT16 freerdp_settings_get_uint16(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt16 id)
Returns a UINT16 settings value.
BOOL freerdp_settings_copy(rdpSettings *_settings, const rdpSettings *settings)
Deep copies settings from src to dst.
rdpSettings * freerdp_settings_clone(const rdpSettings *settings)
Creates a deep copy of settings.
FREERDP_API WCHAR * freerdp_settings_get_string_as_utf16(const rdpSettings *settings, FreeRDP_Settings_Keys_String id, size_t *pCharLen)
Return an allocated UTF16 string.
FREERDP_API BOOL freerdp_settings_set_string_len(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param, size_t len)
Sets a string settings value. The param is copied.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_uint16(rdpSettings *settings, FreeRDP_Settings_Keys_UInt16 id, UINT16 param)
Sets a UINT16 settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.
FREERDP_API void * freerdp_settings_get_pointer_writable(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a mutable pointer settings value.