FreeRDP
Loading...
Searching...
No Matches
client/common/file.c
1
20#include <freerdp/config.h>
21
22#include <errno.h>
23#include <ctype.h>
24#include <stdlib.h>
25
26#include <winpr/string.h>
27#include <winpr/file.h>
28#include <winpr/cast.h>
29
30#include <freerdp/utils/warnings.h>
31
32#include <freerdp/client.h>
33#include <freerdp/client/file.h>
34#include <freerdp/client/cmdline.h>
35
36#include <freerdp/channels/urbdrc.h>
37#include <freerdp/channels/rdpecam.h>
38#include <freerdp/channels/location.h>
39
50#include <stdio.h>
51#include <string.h>
52
53#include <winpr/wtypes.h>
54#include <winpr/crt.h>
55#include <winpr/path.h>
56#include <freerdp/log.h>
57#define TAG CLIENT_TAG("common")
58
59/*#define DEBUG_CLIENT_FILE 1*/
60
61static const BYTE BOM_UTF16_LE[2] = { 0xFF, 0xFE };
62
63// #define INVALID_INTEGER_VALUE 0xFFFFFFFF
64
65#define RDP_FILE_LINE_FLAG_FORMATTED 0x00000001
66// #define RDP_FILE_LINE_FLAG_STANDARD 0x00000002
67#define RDP_FILE_LINE_FLAG_TYPE_STRING 0x00000010
68#define RDP_FILE_LINE_FLAG_TYPE_INTEGER 0x00000020
69// #define RDP_FILE_LINE_FLAG_TYPE_BINARY 0x00000040
70
71struct rdp_file_line
72{
73 char* name;
74 LPSTR sValue;
75 PBYTE bValue;
76
77 size_t index;
78
79 long iValue;
80 DWORD flags;
81 int valueLength;
82};
83typedef struct rdp_file_line rdpFileLine;
84
85struct rdp_file
86{
87 DWORD UseMultiMon; /* use multimon */
88 LPSTR SelectedMonitors; /* selectedmonitors */
89 DWORD MaximizeToCurrentDisplays; /* maximizetocurrentdisplays */
90 DWORD SingleMonInWindowedMode; /* singlemoninwindowedmode */
91 DWORD ScreenModeId; /* screen mode id */
92 DWORD SpanMonitors; /* span monitors */
93 DWORD SmartSizing; /* smartsizing */
94 DWORD DynamicResolution; /* dynamic resolution */
95 DWORD EnableSuperSpan; /* enablesuperpan */
96 DWORD SuperSpanAccelerationFactor; /* superpanaccelerationfactor */
97
98 DWORD DesktopWidth; /* desktopwidth */
99 DWORD DesktopHeight; /* desktopheight */
100 DWORD DesktopSizeId; /* desktop size id */
101 DWORD SessionBpp; /* session bpp */
102 DWORD DesktopScaleFactor; /* desktopscalefactor */
103
104 DWORD Compression; /* compression */
105 DWORD KeyboardHook; /* keyboardhook */
106 DWORD DisableCtrlAltDel; /* disable ctrl+alt+del */
107
108 DWORD AudioMode; /* audiomode */
109 DWORD AudioQualityMode; /* audioqualitymode */
110 DWORD AudioCaptureMode; /* audiocapturemode */
111 DWORD EncodeRedirectedVideoCapture; /* encode redirected video capture */
112 DWORD RedirectedVideoCaptureEncodingQuality; /* redirected video capture encoding quality */
113 DWORD VideoPlaybackMode; /* videoplaybackmode */
114
115 DWORD ConnectionType; /* connection type */
116
117 DWORD NetworkAutoDetect; /* networkautodetect */
118 DWORD BandwidthAutoDetect; /* bandwidthautodetect */
119
120 DWORD PinConnectionBar; /* pinconnectionbar */
121 DWORD DisplayConnectionBar; /* displayconnectionbar */
122
123 DWORD WorkspaceId; /* workspaceid */
124 DWORD EnableWorkspaceReconnect; /* enableworkspacereconnect */
125
126 DWORD DisableWallpaper; /* disable wallpaper */
127 DWORD AllowFontSmoothing; /* allow font smoothing */
128 DWORD AllowDesktopComposition; /* allow desktop composition */
129 DWORD DisableFullWindowDrag; /* disable full window drag */
130 DWORD DisableMenuAnims; /* disable menu anims */
131 DWORD DisableThemes; /* disable themes */
132 DWORD DisableCursorSetting; /* disable cursor setting */
133
134 DWORD BitmapCacheSize; /* bitmapcachesize */
135 DWORD BitmapCachePersistEnable; /* bitmapcachepersistenable */
136
137 DWORD ServerPort; /* server port */
138
139 LPSTR Username; /* username */
140 LPSTR Domain; /* domain */
141 LPSTR Password; /*password*/
142
143 LPSTR FullAddress; /* full address */
144 LPSTR AlternateFullAddress; /* alternate full address */
145
146 LPSTR UsbDevicesToRedirect; /* usbdevicestoredirect */
147 DWORD RedirectDrives; /* redirectdrives */
148 DWORD RedirectPrinters; /* redirectprinters */
149 DWORD RedirectComPorts; /* redirectcomports */
150 DWORD RedirectLocation; /* redirectlocation */
151 DWORD RedirectSmartCards; /* redirectsmartcards */
152 DWORD RedirectWebauthN; /* redirectwebauthn */
153 LPSTR RedirectCameras; /* camerastoredirect */
154 DWORD RedirectClipboard; /* redirectclipboard */
155 DWORD RedirectPosDevices; /* redirectposdevices */
156 DWORD RedirectDirectX; /* redirectdirectx */
157 DWORD DisablePrinterRedirection; /* disableprinterredirection */
158 DWORD DisableClipboardRedirection; /* disableclipboardredirection */
159
160 DWORD ConnectToConsole; /* connect to console */
161 DWORD AdministrativeSession; /* administrative session */
162 DWORD AutoReconnectionEnabled; /* autoreconnection enabled */
163 DWORD AutoReconnectMaxRetries; /* autoreconnect max retries */
164
165 DWORD PublicMode; /* public mode */
166 DWORD AuthenticationLevel; /* authentication level */
167 DWORD PromptCredentialOnce; /* promptcredentialonce */
168 DWORD PromptForCredentials; /* prompt for credentials */
169 DWORD NegotiateSecurityLayer; /* negotiate security layer */
170 DWORD EnableCredSSPSupport; /* enablecredsspsupport */
171 DWORD EnableRdsAadAuth; /* enablerdsaadauth */
172
173 DWORD RemoteApplicationMode; /* remoteapplicationmode */
174 LPSTR LoadBalanceInfo; /* loadbalanceinfo */
175
176 LPSTR RemoteApplicationName; /* remoteapplicationname */
177 LPSTR RemoteApplicationIcon; /* remoteapplicationicon */
178 LPSTR RemoteApplicationProgram; /* remoteapplicationprogram */
179 LPSTR RemoteApplicationFile; /* remoteapplicationfile */
180 LPSTR RemoteApplicationGuid; /* remoteapplicationguid */
181 LPSTR RemoteApplicationCmdLine; /* remoteapplicationcmdline */
182 DWORD RemoteApplicationExpandCmdLine; /* remoteapplicationexpandcmdline */
183 DWORD RemoteApplicationExpandWorkingDir; /* remoteapplicationexpandworkingdir */
184 DWORD DisableConnectionSharing; /* disableconnectionsharing */
185 DWORD DisableRemoteAppCapsCheck; /* disableremoteappcapscheck */
186
187 LPSTR AlternateShell; /* alternate shell */
188 LPSTR ShellWorkingDirectory; /* shell working directory */
189
190 LPSTR GatewayHostname; /* gatewayhostname */
191 DWORD GatewayUsageMethod; /* gatewayusagemethod */
192 DWORD GatewayProfileUsageMethod; /* gatewayprofileusagemethod */
193 DWORD GatewayCredentialsSource; /* gatewaycredentialssource */
194
195 LPSTR ResourceProvider; /* resourceprovider */
196
197 LPSTR WvdEndpointPool; /* wvd endpoint pool */
198 LPSTR geo; /* geo */
199 LPSTR armpath; /* armpath */
200 LPSTR aadtenantid; /* aadtenantid" */
201 LPSTR diagnosticserviceurl; /* diagnosticserviceurl */
202 LPSTR hubdiscoverygeourl; /* hubdiscoverygeourl" */
203 LPSTR activityhint; /* activityhint */
204
205 DWORD UseRedirectionServerName; /* use redirection server name */
206
207 LPSTR GatewayAccessToken; /* gatewayaccesstoken */
208
209 LPSTR EndpointFedAuthToken; /* endpointfedauth */
210
211 LPSTR DrivesToRedirect; /* drivestoredirect */
212 LPSTR DevicesToRedirect; /* devicestoredirect */
213 LPSTR WinPosStr; /* winposstr */
214
215 LPSTR PreconnectionBlob; /* pcb */
216
217 LPSTR KdcProxyName; /* kdcproxyname */
218 DWORD RdgIsKdcProxy; /* rdgiskdcproxy */
219
220 DWORD align1;
221
222 size_t lineCount;
223 size_t lineSize;
224 rdpFileLine* lines;
225
226 ADDIN_ARGV* args;
227 void* context;
228
229 DWORD flags;
230};
231
232static const char key_str_username[] = "username";
233static const char key_str_domain[] = "domain";
234static const char key_str_password[] = "password";
235static const char key_str_full_address[] = "full address";
236static const char key_str_alternate_full_address[] = "alternate full address";
237static const char key_str_usbdevicestoredirect[] = "usbdevicestoredirect";
238static const char key_str_camerastoredirect[] = "camerastoredirect";
239static const char key_str_loadbalanceinfo[] = "loadbalanceinfo";
240static const char key_str_remoteapplicationname[] = "remoteapplicationname";
241static const char key_str_remoteapplicationicon[] = "remoteapplicationicon";
242static const char key_str_remoteapplicationprogram[] = "remoteapplicationprogram";
243static const char key_str_remoteapplicationfile[] = "remoteapplicationfile";
244static const char key_str_remoteapplicationguid[] = "remoteapplicationguid";
245static const char key_str_remoteapplicationcmdline[] = "remoteapplicationcmdline";
246static const char key_str_alternate_shell[] = "alternate shell";
247static const char key_str_shell_working_directory[] = "shell working directory";
248static const char key_str_gatewayhostname[] = "gatewayhostname";
249static const char key_str_gatewayaccesstoken[] = "gatewayaccesstoken";
250static const char key_str_endpointfedauth[] = "endpointfedauth";
251static const char key_str_resourceprovider[] = "resourceprovider";
252static const char str_resourceprovider_arm[] = "arm";
253static const char key_str_kdcproxyname[] = "kdcproxyname";
254static const char key_str_drivestoredirect[] = "drivestoredirect";
255static const char key_str_devicestoredirect[] = "devicestoredirect";
256static const char key_str_winposstr[] = "winposstr";
257static const char key_str_pcb[] = "pcb";
258static const char key_str_selectedmonitors[] = "selectedmonitors";
259
260static const char key_str_wvd[] = "wvd endpoint pool";
261static const char key_str_geo[] = "geo";
262static const char key_str_armpath[] = "armpath";
263static const char key_str_aadtenantid[] = "aadtenantid";
264
265static const char key_str_diagnosticserviceurl[] = "diagnosticserviceurl";
266static const char key_str_hubdiscoverygeourl[] = "hubdiscoverygeourl";
267
268static const char key_str_activityhint[] = "activityhint";
269
270static const char key_int_rdgiskdcproxy[] = "rdgiskdcproxy";
271static const char key_int_use_redirection_server_name[] = "use redirection server name";
272static const char key_int_gatewaycredentialssource[] = "gatewaycredentialssource";
273static const char key_int_gatewayprofileusagemethod[] = "gatewayprofileusagemethod";
274static const char key_int_gatewayusagemethod[] = "gatewayusagemethod";
275static const char key_int_disableremoteappcapscheck[] = "disableremoteappcapscheck";
276static const char key_int_disableconnectionsharing[] = "disableconnectionsharing";
277static const char key_int_remoteapplicationexpandworkingdir[] = "remoteapplicationexpandworkingdir";
278static const char key_int_remoteapplicationexpandcmdline[] = "remoteapplicationexpandcmdline";
279static const char key_int_remoteapplicationmode[] = "remoteapplicationmode";
280static const char key_int_enablecredsspsupport[] = "enablecredsspsupport";
281static const char key_int_enablerdsaadauth[] = "enablerdsaadauth";
282static const char key_int_negotiate_security_layer[] = "negotiate security layer";
283static const char key_int_prompt_for_credentials[] = "prompt for credentials";
284static const char key_int_promptcredentialonce[] = "promptcredentialonce";
285static const char key_int_authentication_level[] = "authentication level";
286static const char key_int_public_mode[] = "public mode";
287static const char key_int_autoreconnect_max_retries[] = "autoreconnect max retries";
288static const char key_int_autoreconnection_enabled[] = "autoreconnection enabled";
289static const char key_int_administrative_session[] = "administrative session";
290static const char key_int_connect_to_console[] = "connect to console";
291static const char key_int_disableclipboardredirection[] = "disableclipboardredirection";
292static const char key_int_disableprinterredirection[] = "disableprinterredirection";
293static const char key_int_redirectdirectx[] = "redirectdirectx";
294static const char key_int_redirectposdevices[] = "redirectposdevices";
295static const char key_int_redirectclipboard[] = "redirectclipboard";
296static const char key_int_redirectsmartcards[] = "redirectsmartcards";
297static const char key_int_redirectcomports[] = "redirectcomports";
298static const char key_int_redirectlocation[] = "redirectlocation";
299static const char key_int_redirectprinters[] = "redirectprinters";
300static const char key_int_redirectdrives[] = "redirectdrives";
301static const char key_int_server_port[] = "server port";
302static const char key_int_bitmapcachepersistenable[] = "bitmapcachepersistenable";
303static const char key_int_bitmapcachesize[] = "bitmapcachesize";
304static const char key_int_disable_cursor_setting[] = "disable cursor setting";
305static const char key_int_disable_themes[] = "disable themes";
306static const char key_int_disable_menu_anims[] = "disable menu anims";
307static const char key_int_disable_full_window_drag[] = "disable full window drag";
308static const char key_int_allow_desktop_composition[] = "allow desktop composition";
309static const char key_int_allow_font_smoothing[] = "allow font smoothing";
310static const char key_int_disable_wallpaper[] = "disable wallpaper";
311static const char key_int_enableworkspacereconnect[] = "enableworkspacereconnect";
312static const char key_int_workspaceid[] = "workspaceid";
313static const char key_int_displayconnectionbar[] = "displayconnectionbar";
314static const char key_int_pinconnectionbar[] = "pinconnectionbar";
315static const char key_int_bandwidthautodetect[] = "bandwidthautodetect";
316static const char key_int_networkautodetect[] = "networkautodetect";
317static const char key_int_connection_type[] = "connection type";
318static const char key_int_videoplaybackmode[] = "videoplaybackmode";
319static const char key_int_redirected_video_capture_encoding_quality[] =
320 "redirected video capture encoding quality";
321static const char key_int_encode_redirected_video_capture[] = "encode redirected video capture";
322static const char key_int_audiocapturemode[] = "audiocapturemode";
323static const char key_int_audioqualitymode[] = "audioqualitymode";
324static const char key_int_audiomode[] = "audiomode";
325static const char key_int_disable_ctrl_alt_del[] = "disable ctrl+alt+del";
326static const char key_int_keyboardhook[] = "keyboardhook";
327static const char key_int_compression[] = "compression";
328static const char key_int_desktopscalefactor[] = "desktopscalefactor";
329static const char key_int_session_bpp[] = "session bpp";
330static const char key_int_desktop_size_id[] = "desktop size id";
331static const char key_int_desktopheight[] = "desktopheight";
332static const char key_int_desktopwidth[] = "desktopwidth";
333static const char key_int_superpanaccelerationfactor[] = "superpanaccelerationfactor";
334static const char key_int_enablesuperpan[] = "enablesuperpan";
335static const char key_int_dynamic_resolution[] = "dynamic resolution";
336static const char key_int_smart_sizing[] = "smart sizing";
337static const char key_int_span_monitors[] = "span monitors";
338static const char key_int_screen_mode_id[] = "screen mode id";
339static const char key_int_singlemoninwindowedmode[] = "singlemoninwindowedmode";
340static const char key_int_maximizetocurrentdisplays[] = "maximizetocurrentdisplays";
341static const char key_int_use_multimon[] = "use multimon";
342static const char key_int_redirectwebauthn[] = "redirectwebauthn";
343
344WINPR_ATTR_NODISCARD
345static BOOL is_pointer_used(void* ptr)
346{
347 return ~((size_t)ptr) != 0;
348}
349
350WINPR_ATTR_NODISCARD
351static BOOL utils_str_is_empty(const char* str)
352{
353 if (!str)
354 return TRUE;
355 if (strlen(str) == 0)
356 return TRUE;
357 return FALSE;
358}
359
360WINPR_ATTR_NODISCARD
361static SSIZE_T freerdp_client_rdp_file_add_line(rdpFile* file);
362
363WINPR_ATTR_NODISCARD
364static rdpFileLine* freerdp_client_rdp_file_find_line_by_name(const rdpFile* file,
365 const char* name);
366static void freerdp_client_file_string_check_free(LPSTR str);
367
368WINPR_ATTR_NODISCARD
369static BOOL freerdp_client_rdp_file_find_integer_entry(rdpFile* file, const char* name,
370 DWORD** outValue, rdpFileLine** outLine)
371{
372 WINPR_ASSERT(file);
373 WINPR_ASSERT(name);
374 WINPR_ASSERT(outValue);
375 WINPR_ASSERT(outLine);
376
377 *outValue = nullptr;
378 *outLine = nullptr;
379
380 if (_stricmp(name, key_int_use_multimon) == 0)
381 *outValue = &file->UseMultiMon;
382 else if (_stricmp(name, key_int_maximizetocurrentdisplays) == 0)
383 *outValue = &file->MaximizeToCurrentDisplays;
384 else if (_stricmp(name, key_int_singlemoninwindowedmode) == 0)
385 *outValue = &file->SingleMonInWindowedMode;
386 else if (_stricmp(name, key_int_screen_mode_id) == 0)
387 *outValue = &file->ScreenModeId;
388 else if (_stricmp(name, key_int_span_monitors) == 0)
389 *outValue = &file->SpanMonitors;
390 else if (_stricmp(name, key_int_smart_sizing) == 0)
391 *outValue = &file->SmartSizing;
392 else if (_stricmp(name, key_int_dynamic_resolution) == 0)
393 *outValue = &file->DynamicResolution;
394 else if (_stricmp(name, key_int_enablesuperpan) == 0)
395 *outValue = &file->EnableSuperSpan;
396 else if (_stricmp(name, key_int_superpanaccelerationfactor) == 0)
397 *outValue = &file->SuperSpanAccelerationFactor;
398 else if (_stricmp(name, key_int_desktopwidth) == 0)
399 *outValue = &file->DesktopWidth;
400 else if (_stricmp(name, key_int_desktopheight) == 0)
401 *outValue = &file->DesktopHeight;
402 else if (_stricmp(name, key_int_desktop_size_id) == 0)
403 *outValue = &file->DesktopSizeId;
404 else if (_stricmp(name, key_int_session_bpp) == 0)
405 *outValue = &file->SessionBpp;
406 else if (_stricmp(name, key_int_desktopscalefactor) == 0)
407 *outValue = &file->DesktopScaleFactor;
408 else if (_stricmp(name, key_int_compression) == 0)
409 *outValue = &file->Compression;
410 else if (_stricmp(name, key_int_keyboardhook) == 0)
411 *outValue = &file->KeyboardHook;
412 else if (_stricmp(name, key_int_disable_ctrl_alt_del) == 0)
413 *outValue = &file->DisableCtrlAltDel;
414 else if (_stricmp(name, key_int_audiomode) == 0)
415 *outValue = &file->AudioMode;
416 else if (_stricmp(name, key_int_audioqualitymode) == 0)
417 *outValue = &file->AudioQualityMode;
418 else if (_stricmp(name, key_int_audiocapturemode) == 0)
419 *outValue = &file->AudioCaptureMode;
420 else if (_stricmp(name, key_int_encode_redirected_video_capture) == 0)
421 *outValue = &file->EncodeRedirectedVideoCapture;
422 else if (_stricmp(name, key_int_redirected_video_capture_encoding_quality) == 0)
423 *outValue = &file->RedirectedVideoCaptureEncodingQuality;
424 else if (_stricmp(name, key_int_videoplaybackmode) == 0)
425 *outValue = &file->VideoPlaybackMode;
426 else if (_stricmp(name, key_int_connection_type) == 0)
427 *outValue = &file->ConnectionType;
428 else if (_stricmp(name, key_int_networkautodetect) == 0)
429 *outValue = &file->NetworkAutoDetect;
430 else if (_stricmp(name, key_int_bandwidthautodetect) == 0)
431 *outValue = &file->BandwidthAutoDetect;
432 else if (_stricmp(name, key_int_pinconnectionbar) == 0)
433 *outValue = &file->PinConnectionBar;
434 else if (_stricmp(name, key_int_displayconnectionbar) == 0)
435 *outValue = &file->DisplayConnectionBar;
436 else if (_stricmp(name, key_int_workspaceid) == 0)
437 *outValue = &file->WorkspaceId;
438 else if (_stricmp(name, key_int_enableworkspacereconnect) == 0)
439 *outValue = &file->EnableWorkspaceReconnect;
440 else if (_stricmp(name, key_int_disable_wallpaper) == 0)
441 *outValue = &file->DisableWallpaper;
442 else if (_stricmp(name, key_int_allow_font_smoothing) == 0)
443 *outValue = &file->AllowFontSmoothing;
444 else if (_stricmp(name, key_int_allow_desktop_composition) == 0)
445 *outValue = &file->AllowDesktopComposition;
446 else if (_stricmp(name, key_int_disable_full_window_drag) == 0)
447 *outValue = &file->DisableFullWindowDrag;
448 else if (_stricmp(name, key_int_disable_menu_anims) == 0)
449 *outValue = &file->DisableMenuAnims;
450 else if (_stricmp(name, key_int_disable_themes) == 0)
451 *outValue = &file->DisableThemes;
452 else if (_stricmp(name, key_int_disable_cursor_setting) == 0)
453 *outValue = &file->DisableCursorSetting;
454 else if (_stricmp(name, key_int_bitmapcachesize) == 0)
455 *outValue = &file->BitmapCacheSize;
456 else if (_stricmp(name, key_int_bitmapcachepersistenable) == 0)
457 *outValue = &file->BitmapCachePersistEnable;
458 else if (_stricmp(name, key_int_server_port) == 0)
459 *outValue = &file->ServerPort;
460 else if (_stricmp(name, key_int_redirectdrives) == 0)
461 *outValue = &file->RedirectDrives;
462 else if (_stricmp(name, key_int_redirectprinters) == 0)
463 *outValue = &file->RedirectPrinters;
464 else if (_stricmp(name, key_int_redirectcomports) == 0)
465 *outValue = &file->RedirectComPorts;
466 else if (_stricmp(name, key_int_redirectlocation) == 0)
467 *outValue = &file->RedirectLocation;
468 else if (_stricmp(name, key_int_redirectsmartcards) == 0)
469 *outValue = &file->RedirectSmartCards;
470 else if (_stricmp(name, key_int_redirectclipboard) == 0)
471 *outValue = &file->RedirectClipboard;
472 else if (_stricmp(name, key_int_redirectposdevices) == 0)
473 *outValue = &file->RedirectPosDevices;
474 else if (_stricmp(name, key_int_redirectdirectx) == 0)
475 *outValue = &file->RedirectDirectX;
476 else if (_stricmp(name, key_int_disableprinterredirection) == 0)
477 *outValue = &file->DisablePrinterRedirection;
478 else if (_stricmp(name, key_int_disableclipboardredirection) == 0)
479 *outValue = &file->DisableClipboardRedirection;
480 else if (_stricmp(name, key_int_connect_to_console) == 0)
481 *outValue = &file->ConnectToConsole;
482 else if (_stricmp(name, key_int_administrative_session) == 0)
483 *outValue = &file->AdministrativeSession;
484 else if (_stricmp(name, key_int_autoreconnection_enabled) == 0)
485 *outValue = &file->AutoReconnectionEnabled;
486 else if (_stricmp(name, key_int_autoreconnect_max_retries) == 0)
487 *outValue = &file->AutoReconnectMaxRetries;
488 else if (_stricmp(name, key_int_public_mode) == 0)
489 *outValue = &file->PublicMode;
490 else if (_stricmp(name, key_int_authentication_level) == 0)
491 *outValue = &file->AuthenticationLevel;
492 else if (_stricmp(name, key_int_promptcredentialonce) == 0)
493 *outValue = &file->PromptCredentialOnce;
494 else if ((_stricmp(name, key_int_prompt_for_credentials) == 0))
495 *outValue = &file->PromptForCredentials;
496 else if (_stricmp(name, key_int_negotiate_security_layer) == 0)
497 *outValue = &file->NegotiateSecurityLayer;
498 else if (_stricmp(name, key_int_enablecredsspsupport) == 0)
499 *outValue = &file->EnableCredSSPSupport;
500 else if (_stricmp(name, key_int_enablerdsaadauth) == 0)
501 *outValue = &file->EnableRdsAadAuth;
502 else if (_stricmp(name, key_int_remoteapplicationmode) == 0)
503 *outValue = &file->RemoteApplicationMode;
504 else if (_stricmp(name, key_int_remoteapplicationexpandcmdline) == 0)
505 *outValue = &file->RemoteApplicationExpandCmdLine;
506 else if (_stricmp(name, key_int_remoteapplicationexpandworkingdir) == 0)
507 *outValue = &file->RemoteApplicationExpandWorkingDir;
508 else if (_stricmp(name, key_int_disableconnectionsharing) == 0)
509 *outValue = &file->DisableConnectionSharing;
510 else if (_stricmp(name, key_int_disableremoteappcapscheck) == 0)
511 *outValue = &file->DisableRemoteAppCapsCheck;
512 else if (_stricmp(name, key_int_gatewayusagemethod) == 0)
513 *outValue = &file->GatewayUsageMethod;
514 else if (_stricmp(name, key_int_gatewayprofileusagemethod) == 0)
515 *outValue = &file->GatewayProfileUsageMethod;
516 else if (_stricmp(name, key_int_gatewaycredentialssource) == 0)
517 *outValue = &file->GatewayCredentialsSource;
518 else if (_stricmp(name, key_int_use_redirection_server_name) == 0)
519 *outValue = &file->UseRedirectionServerName;
520 else if (_stricmp(name, key_int_rdgiskdcproxy) == 0)
521 *outValue = &file->RdgIsKdcProxy;
522 else if (_stricmp(name, key_int_redirectwebauthn) == 0)
523 *outValue = &file->RedirectWebauthN;
524 else
525 {
526 rdpFileLine* line = freerdp_client_rdp_file_find_line_by_name(file, name);
527 if (!line)
528 return FALSE;
529 if (!(line->flags & RDP_FILE_LINE_FLAG_TYPE_INTEGER))
530 return FALSE;
531
532 *outLine = line;
533 }
534
535 return TRUE;
536}
537
538WINPR_ATTR_NODISCARD
539static BOOL freerdp_client_rdp_file_find_string_entry(rdpFile* file, const char* name,
540 LPSTR** outValue, rdpFileLine** outLine)
541{
542 WINPR_ASSERT(file);
543 WINPR_ASSERT(name);
544 WINPR_ASSERT(outValue);
545 WINPR_ASSERT(outLine);
546
547 *outValue = nullptr;
548 *outLine = nullptr;
549
550 if (_stricmp(name, key_str_username) == 0)
551 *outValue = &file->Username;
552 else if (_stricmp(name, key_str_domain) == 0)
553 *outValue = &file->Domain;
554 else if (_stricmp(name, key_str_password) == 0)
555 *outValue = &file->Password;
556 else if (_stricmp(name, key_str_full_address) == 0)
557 *outValue = &file->FullAddress;
558 else if (_stricmp(name, key_str_alternate_full_address) == 0)
559 *outValue = &file->AlternateFullAddress;
560 else if (_stricmp(name, key_str_usbdevicestoredirect) == 0)
561 *outValue = &file->UsbDevicesToRedirect;
562 else if (_stricmp(name, key_str_camerastoredirect) == 0)
563 *outValue = &file->RedirectCameras;
564 else if (_stricmp(name, key_str_loadbalanceinfo) == 0)
565 *outValue = &file->LoadBalanceInfo;
566 else if (_stricmp(name, key_str_remoteapplicationname) == 0)
567 *outValue = &file->RemoteApplicationName;
568 else if (_stricmp(name, key_str_remoteapplicationicon) == 0)
569 *outValue = &file->RemoteApplicationIcon;
570 else if (_stricmp(name, key_str_remoteapplicationprogram) == 0)
571 *outValue = &file->RemoteApplicationProgram;
572 else if (_stricmp(name, key_str_remoteapplicationfile) == 0)
573 *outValue = &file->RemoteApplicationFile;
574 else if (_stricmp(name, key_str_remoteapplicationguid) == 0)
575 *outValue = &file->RemoteApplicationGuid;
576 else if (_stricmp(name, key_str_remoteapplicationcmdline) == 0)
577 *outValue = &file->RemoteApplicationCmdLine;
578 else if (_stricmp(name, key_str_alternate_shell) == 0)
579 *outValue = &file->AlternateShell;
580 else if (_stricmp(name, key_str_shell_working_directory) == 0)
581 *outValue = &file->ShellWorkingDirectory;
582 else if (_stricmp(name, key_str_gatewayhostname) == 0)
583 *outValue = &file->GatewayHostname;
584 else if (_stricmp(name, key_str_resourceprovider) == 0)
585 *outValue = &file->ResourceProvider;
586 else if (_stricmp(name, key_str_wvd) == 0)
587 *outValue = &file->WvdEndpointPool;
588 else if (_stricmp(name, key_str_geo) == 0)
589 *outValue = &file->geo;
590 else if (_stricmp(name, key_str_armpath) == 0)
591 *outValue = &file->armpath;
592 else if (_stricmp(name, key_str_aadtenantid) == 0)
593 *outValue = &file->aadtenantid;
594 else if (_stricmp(name, key_str_diagnosticserviceurl) == 0)
595 *outValue = &file->diagnosticserviceurl;
596 else if (_stricmp(name, key_str_hubdiscoverygeourl) == 0)
597 *outValue = &file->hubdiscoverygeourl;
598 else if (_stricmp(name, key_str_activityhint) == 0)
599 *outValue = &file->activityhint;
600 else if (_stricmp(name, key_str_gatewayaccesstoken) == 0)
601 *outValue = &file->GatewayAccessToken;
602 else if (_stricmp(name, key_str_endpointfedauth) == 0)
603 *outValue = &file->EndpointFedAuthToken;
604 else if (_stricmp(name, key_str_kdcproxyname) == 0)
605 *outValue = &file->KdcProxyName;
606 else if (_stricmp(name, key_str_drivestoredirect) == 0)
607 *outValue = &file->DrivesToRedirect;
608 else if (_stricmp(name, key_str_devicestoredirect) == 0)
609 *outValue = &file->DevicesToRedirect;
610 else if (_stricmp(name, key_str_winposstr) == 0)
611 *outValue = &file->WinPosStr;
612 else if (_stricmp(name, key_str_pcb) == 0)
613 *outValue = &file->PreconnectionBlob;
614 else if (_stricmp(name, key_str_selectedmonitors) == 0)
615 *outValue = &file->SelectedMonitors;
616 else
617 {
618 rdpFileLine* line = freerdp_client_rdp_file_find_line_by_name(file, name);
619 if (!line)
620 return FALSE;
621 if (!(line->flags & RDP_FILE_LINE_FLAG_TYPE_STRING))
622 return FALSE;
623
624 *outLine = line;
625 }
626
627 return TRUE;
628}
629
630/*
631 * Set an integer in a rdpFile
632 *
633 * @return FALSE if a standard name was set, TRUE for a non-standard name, FALSE on error
634 *
635 */
636WINPR_ATTR_NODISCARD
637static BOOL freerdp_client_rdp_file_set_integer(rdpFile* file, const char* name, long value)
638{
639 DWORD* targetValue = nullptr;
640 rdpFileLine* line = nullptr;
641#ifdef DEBUG_CLIENT_FILE
642 WLog_DBG(TAG, "%s:i:%ld", name, value);
643#endif
644
645 if (value < 0)
646 return FALSE;
647
648 if (!freerdp_client_rdp_file_find_integer_entry(file, name, &targetValue, &line))
649 {
650 SSIZE_T index = freerdp_client_rdp_file_add_line(file);
651 if (index == -1)
652 return FALSE;
653 line = &file->lines[index];
654 }
655
656 if (targetValue)
657 {
658 *targetValue = (DWORD)value;
659 return TRUE;
660 }
661
662 if (line)
663 {
664 free(line->name);
665 line->name = _strdup(name);
666 if (!line->name)
667 {
668 free(line->name);
669 line->name = nullptr;
670 return FALSE;
671 }
672
673 line->iValue = value;
674 line->flags = RDP_FILE_LINE_FLAG_FORMATTED;
675 line->flags |= RDP_FILE_LINE_FLAG_TYPE_INTEGER;
676 line->valueLength = 0;
677 return TRUE;
678 }
679
680 return FALSE;
681}
682
683WINPR_ATTR_NODISCARD
684static BOOL freerdp_client_parse_rdp_file_integer(rdpFile* file, const char* name,
685 const char* value)
686{
687 char* endptr = nullptr;
688 long ivalue = 0;
689 errno = 0;
690 ivalue = strtol(value, &endptr, 0);
691
692 if ((endptr == nullptr) || (errno != 0) || (endptr == value) || (ivalue > INT32_MAX) ||
693 (ivalue < INT32_MIN))
694 {
695 if (file->flags & RDP_FILE_FLAG_PARSE_INT_RELAXED)
696 {
697 WLog_WARN(TAG, "Integer option %s has invalid value %s, using default", name, value);
698 return TRUE;
699 }
700 else
701 {
702 WLog_ERR(TAG, "Failed to convert RDP file integer option %s [value=%s]", name, value);
703 return FALSE;
704 }
705 }
706
707 return freerdp_client_rdp_file_set_integer(file, name, ivalue);
708}
709
717WINPR_ATTR_NODISCARD
718static BOOL freerdp_client_rdp_file_set_string(rdpFile* file, const char* name, const char* value)
719{
720 LPSTR* targetValue = nullptr;
721 rdpFileLine* line = nullptr;
722#ifdef DEBUG_CLIENT_FILE
723 WLog_DBG(TAG, "%s:s:%s", name, value);
724#endif
725
726 if (!name || !value)
727 return FALSE;
728
729 if (!freerdp_client_rdp_file_find_string_entry(file, name, &targetValue, &line))
730 {
731 SSIZE_T index = freerdp_client_rdp_file_add_line(file);
732 if (index == -1)
733 return FALSE;
734 line = &file->lines[index];
735 }
736
737 if (targetValue)
738 {
739 if ((uintptr_t)(*targetValue) != UINTPTR_MAX)
740 free(*targetValue);
741
742 *targetValue = _strdup(value);
743 return ((*targetValue) != nullptr);
744 }
745
746 if (line)
747 {
748 free(line->name);
749 free(line->sValue);
750 line->name = _strdup(name);
751 line->sValue = _strdup(value);
752 if (!line->name || !line->sValue)
753 {
754 free(line->name);
755 free(line->sValue);
756 line->name = nullptr;
757 line->sValue = nullptr;
758 return FALSE;
759 }
760
761 line->flags = RDP_FILE_LINE_FLAG_FORMATTED;
762 line->flags |= RDP_FILE_LINE_FLAG_TYPE_STRING;
763 line->valueLength = 0;
764 return TRUE;
765 }
766
767 return FALSE;
768}
769
770WINPR_ATTR_NODISCARD
771static BOOL freerdp_client_add_option(rdpFile* file, const char* option)
772{
773 return freerdp_addin_argv_add_argument(file->args, option);
774}
775
776WINPR_ATTR_NODISCARD
777static SSIZE_T freerdp_client_rdp_file_add_line(rdpFile* file)
778{
779 SSIZE_T index = (SSIZE_T)file->lineCount;
780
781 while ((file->lineCount + 1) > file->lineSize)
782 {
783 size_t new_size = file->lineCount + 2048;
784 rdpFileLine* new_line = (rdpFileLine*)realloc(file->lines, new_size * sizeof(rdpFileLine));
785
786 if (!new_line)
787 return -1;
788
789 file->lines = new_line;
790 file->lineSize = new_size;
791 }
792
793 ZeroMemory(&(file->lines[file->lineCount]), sizeof(rdpFileLine));
794 file->lines[file->lineCount].index = (size_t)index;
795 (file->lineCount)++;
796 return index;
797}
798
799BOOL freerdp_client_parse_rdp_file_buffer(rdpFile* file, const BYTE* buffer, size_t size)
800{
801 return freerdp_client_parse_rdp_file_buffer_ex(file, buffer, size, nullptr);
802}
803
804WINPR_ATTR_NODISCARD
805static BOOL trim(char** strptr)
806{
807 char* start = nullptr;
808 char* str = nullptr;
809 char* end = nullptr;
810
811 start = str = *strptr;
812 if (!str)
813 return TRUE;
814 if (!(is_pointer_used(str)))
815 return TRUE;
816 end = str + strlen(str) - 1;
817
818 while (isspace(*str))
819 str++;
820
821 while ((end > str) && isspace(*end))
822 end--;
823 end[1] = '\0';
824 if (start == str)
825 *strptr = str;
826 else
827 {
828 *strptr = _strdup(str);
829 free(start);
830 return *strptr != nullptr;
831 }
832
833 return TRUE;
834}
835
836WINPR_ATTR_NODISCARD
837static BOOL trim_strings(rdpFile* file)
838{
839 if (!trim(&file->Username))
840 return FALSE;
841 if (!trim(&file->Domain))
842 return FALSE;
843 if (!trim(&file->AlternateFullAddress))
844 return FALSE;
845 if (!trim(&file->FullAddress))
846 return FALSE;
847 if (!trim(&file->UsbDevicesToRedirect))
848 return FALSE;
849 if (!trim(&file->RedirectCameras))
850 return FALSE;
851 if (!trim(&file->LoadBalanceInfo))
852 return FALSE;
853 if (!trim(&file->GatewayHostname))
854 return FALSE;
855 if (!trim(&file->GatewayAccessToken))
856 return FALSE;
857 if (!trim(&file->EndpointFedAuthToken))
858 return FALSE;
859 if (!trim(&file->RemoteApplicationName))
860 return FALSE;
861 if (!trim(&file->RemoteApplicationIcon))
862 return FALSE;
863 if (!trim(&file->RemoteApplicationProgram))
864 return FALSE;
865 if (!trim(&file->RemoteApplicationFile))
866 return FALSE;
867 if (!trim(&file->RemoteApplicationGuid))
868 return FALSE;
869 if (!trim(&file->RemoteApplicationCmdLine))
870 return FALSE;
871 if (!trim(&file->AlternateShell))
872 return FALSE;
873 if (!trim(&file->ShellWorkingDirectory))
874 return FALSE;
875 if (!trim(&file->DrivesToRedirect))
876 return FALSE;
877 if (!trim(&file->DevicesToRedirect))
878 return FALSE;
879 if (!trim(&file->WinPosStr))
880 return FALSE;
881 if (!trim(&file->PreconnectionBlob))
882 return FALSE;
883 if (!trim(&file->KdcProxyName))
884 return FALSE;
885 if (!trim(&file->SelectedMonitors))
886 return FALSE;
887
888 for (size_t i = 0; i < file->lineCount; ++i)
889 {
890 rdpFileLine* curLine = &file->lines[i];
891 if (curLine->flags & RDP_FILE_LINE_FLAG_TYPE_STRING)
892 {
893 if (!trim(&curLine->sValue))
894 return FALSE;
895 }
896 }
897
898 return TRUE;
899}
900
901WINPR_ATTR_NODISCARD
902static BOOL parse_line(rdpFile* file, char* line, size_t length, rdp_file_fkt_parse parse)
903{
904 if (length <= 1)
905 return TRUE;
906
907 const char* beg = line;
908#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
909#if defined(WITH_EMBEDDED_CLI_IN_RDP_FILES)
910 if (beg[0] == '/')
911 {
912 freerdp_warn_deprecated(WLog_Get(TAG), "Parsing CLI options within an RDP file",
913 "Will be removed in FreeRDP 4.0");
914 if (!freerdp_client_add_option(file, line))
915 return FALSE;
916
917 return TRUE; /* FreeRDP option */
918 }
919#endif
920#endif
921
922 char* d1 = strchr(line, ':');
923
924 if (!d1)
925 return TRUE; /* not first delimiter */
926
927 const char* type = &d1[1];
928 char* d2 = strchr(type, ':');
929
930 if (!d2)
931 return TRUE; /* no second delimiter */
932
933 if ((d2 - d1) != 2)
934 return TRUE; /* improper type length */
935
936 *d1 = 0;
937 *d2 = 0;
938 const char* name = beg;
939 const char* value = &d2[1];
940
941 if (parse && parse(file->context, name, *type, value))
942 return TRUE;
943
944 if (*type == 'i')
945 {
946 /* integer type */
947 return freerdp_client_parse_rdp_file_integer(file, name, value);
948 }
949 if (*type == 's')
950 {
951 /* string type */
952 return freerdp_client_rdp_file_set_string(file, name, value);
953 }
954 if (*type == 'b')
955 {
956 /* binary type */
957 WLog_ERR(TAG, "Unsupported RDP file binary option %s [value=%s]", name, value);
958 }
959
960 return TRUE;
961}
962
963BOOL freerdp_client_parse_rdp_file_buffer_ex(rdpFile* file, const BYTE* buffer, size_t size,
964 rdp_file_fkt_parse parse)
965{
966 BOOL rc = FALSE;
967 char* copy = nullptr;
968
969 if (!file)
970 return FALSE;
971 if (size < 2)
972 return FALSE;
973
974 if ((buffer[0] == BOM_UTF16_LE[0]) && (buffer[1] == BOM_UTF16_LE[1]))
975 {
976 LPCWSTR uc = WINPR_PACKED_ALIGN_CAST(LPCWSTR, (&buffer[2]));
977 const size_t charlen = size / sizeof(WCHAR) - 1;
978 copy = ConvertWCharNToUtf8Alloc(uc, charlen, &size);
979 if (!copy)
980 {
981 WLog_ERR(TAG, "Failed to convert RDP file from UCS2 to UTF8");
982 return FALSE;
983 }
984 }
985 else
986 {
987 copy = calloc(1, size + sizeof(BYTE));
988
989 if (!copy)
990 return FALSE;
991
992 memcpy(copy, buffer, size);
993 }
994
995 char* context = nullptr;
996 char* line = strtok_s(copy, "\r\n", &context);
997
998 while (line)
999 {
1000 const size_t length = strnlen(line, size);
1001
1002 if (!parse_line(file, line, length, parse))
1003 goto fail;
1004
1005 line = strtok_s(nullptr, "\r\n", &context);
1006 }
1007
1008 rc = trim_strings(file);
1009fail:
1010 free(copy);
1011 return rc;
1012}
1013
1014BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name)
1015{
1016 return freerdp_client_parse_rdp_file_ex(file, name, nullptr);
1017}
1018
1019BOOL freerdp_client_parse_rdp_file_ex(rdpFile* file, const char* name, rdp_file_fkt_parse parse)
1020{
1021 BOOL status = 0;
1022 BYTE* buffer = nullptr;
1023 FILE* fp = nullptr;
1024 size_t read_size = 0;
1025 INT64 file_size = 0;
1026 const char* fname = name;
1027
1028 if (!file || !name)
1029 return FALSE;
1030
1031 if (_strnicmp(fname, "file://", 7) == 0)
1032 fname = &name[7];
1033
1034 fp = winpr_fopen(fname, "r");
1035 if (!fp)
1036 {
1037 WLog_ERR(TAG, "Failed to open RDP file %s", name);
1038 return FALSE;
1039 }
1040
1041 if (_fseeki64(fp, 0, SEEK_END) < 0)
1042 goto fail;
1043 file_size = _ftelli64(fp);
1044 if (_fseeki64(fp, 0, SEEK_SET) < 0)
1045 goto fail;
1046
1047 if (file_size < 1)
1048 {
1049 WLog_ERR(TAG, "RDP file %s is empty", name);
1050 goto fail;
1051 }
1052
1053 buffer = (BYTE*)malloc((size_t)file_size + 2);
1054
1055 if (!buffer)
1056 goto fail;
1057
1058 read_size = fread(buffer, (size_t)file_size, 1, fp);
1059
1060 if (!read_size)
1061 {
1062 if (!ferror(fp))
1063 read_size = (size_t)file_size;
1064 }
1065
1066 if (read_size < 1)
1067 {
1068 WLog_ERR(TAG, "Could not read from RDP file %s", name);
1069 goto fail;
1070 }
1071
1072 buffer[file_size] = '\0';
1073 buffer[file_size + 1] = '\0';
1074 status = freerdp_client_parse_rdp_file_buffer_ex(file, buffer, (size_t)file_size, parse);
1075
1076fail:
1077 (void)fclose(fp);
1078 free(buffer);
1079 return status;
1080}
1081
1082static inline void freerdp_client_file_string_reset(char** target)
1083{
1084 WINPR_ASSERT(target);
1085 freerdp_client_file_string_check_free(*target);
1086 *target = (char*)UINTPTR_MAX;
1087}
1088
1089WINPR_ATTR_NODISCARD
1090static inline BOOL FILE_POPULATE_STRING(char** _target, const rdpSettings* _settings,
1091 FreeRDP_Settings_Keys_String _option)
1092{
1093 WINPR_ASSERT(_target);
1094 WINPR_ASSERT(_settings);
1095
1096 const char* str = freerdp_settings_get_string(_settings, _option);
1097 freerdp_client_file_string_reset(_target);
1098 if (str)
1099 {
1100 char* copy = _strdup(str);
1101 if (!copy)
1102 return FALSE;
1103 *_target = copy;
1104 }
1105 return TRUE;
1106}
1107
1108WINPR_ATTR_NODISCARD
1109static char* freerdp_client_channel_args_to_string(const rdpSettings* settings, const char* channel,
1110 const char* option)
1111{
1112 ADDIN_ARGV* args = freerdp_dynamic_channel_collection_find(settings, channel);
1113 const char* filters[] = { option };
1114 if (!args || (args->argc < 2))
1115 return nullptr;
1116
1117 return CommandLineToCommaSeparatedValuesEx(args->argc - 1, args->argv + 1, filters,
1118 ARRAYSIZE(filters));
1119}
1120
1121WINPR_ATTR_NODISCARD
1122static BOOL rdp_opt_duplicate(const rdpSettings* _settings, FreeRDP_Settings_Keys_String _id,
1123 char** _key)
1124{
1125 WINPR_ASSERT(_settings);
1126 WINPR_ASSERT(_key);
1127 const char* tmp = freerdp_settings_get_string(_settings, _id);
1128
1129 if (tmp)
1130 {
1131 *_key = _strdup(tmp);
1132 if (!*_key)
1133 return FALSE;
1134 }
1135
1136 return TRUE;
1137}
1138
1139BOOL freerdp_client_populate_rdp_file_from_settings(rdpFile* file, const rdpSettings* settings)
1140{
1141 FreeRDP_Settings_Keys_String index = FreeRDP_STRING_UNUSED;
1142 UINT32 LoadBalanceInfoLength = 0;
1143 const char* GatewayHostname = nullptr;
1144 char* redirectCameras = nullptr;
1145
1146 if (!file || !settings)
1147 return FALSE;
1148
1149 if (!FILE_POPULATE_STRING(&file->Domain, settings, FreeRDP_Domain) ||
1150 !FILE_POPULATE_STRING(&file->Username, settings, FreeRDP_Username) ||
1151 !FILE_POPULATE_STRING(&file->Password, settings, FreeRDP_Password) ||
1152 !FILE_POPULATE_STRING(&file->FullAddress, settings, FreeRDP_ServerHostname) ||
1153 !FILE_POPULATE_STRING(&file->AlternateFullAddress, settings, FreeRDP_ServerHostname) ||
1154 !FILE_POPULATE_STRING(&file->AlternateShell, settings, FreeRDP_AlternateShell) ||
1155 !FILE_POPULATE_STRING(&file->DrivesToRedirect, settings, FreeRDP_DrivesToRedirect))
1156
1157 return FALSE;
1158 file->ServerPort = freerdp_settings_get_uint32(settings, FreeRDP_ServerPort);
1159
1160 file->DesktopWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1161 file->DesktopHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1162 file->SessionBpp = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
1163 file->DesktopScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
1164 file->DynamicResolution = WINPR_ASSERTING_INT_CAST(
1165 UINT32, freerdp_settings_get_bool(settings, FreeRDP_SupportDisplayControl));
1166 file->VideoPlaybackMode = WINPR_ASSERTING_INT_CAST(
1167 UINT32, freerdp_settings_get_bool(settings, FreeRDP_SupportVideoOptimized));
1168
1169 // TODO file->MaximizeToCurrentDisplays;
1170 // TODO file->SingleMonInWindowedMode;
1171 // TODO file->EncodeRedirectedVideoCapture;
1172 // TODO file->RedirectedVideoCaptureEncodingQuality;
1173 file->ConnectToConsole = WINPR_ASSERTING_INT_CAST(
1174 UINT32, freerdp_settings_get_bool(settings, FreeRDP_ConsoleSession));
1175 file->NegotiateSecurityLayer = WINPR_ASSERTING_INT_CAST(
1176 UINT32, freerdp_settings_get_bool(settings, FreeRDP_NegotiateSecurityLayer));
1177 file->EnableCredSSPSupport =
1178 WINPR_ASSERTING_INT_CAST(UINT32, freerdp_settings_get_bool(settings, FreeRDP_NlaSecurity));
1179 file->EnableRdsAadAuth =
1180 WINPR_ASSERTING_INT_CAST(UINT32, freerdp_settings_get_bool(settings, FreeRDP_AadSecurity));
1181
1182 if (freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode))
1183 index = FreeRDP_RemoteApplicationWorkingDir;
1184 else
1185 index = FreeRDP_ShellWorkingDirectory;
1186 if (!FILE_POPULATE_STRING(&file->ShellWorkingDirectory, settings, index))
1187 return FALSE;
1188 file->ConnectionType = freerdp_settings_get_uint32(settings, FreeRDP_ConnectionType);
1189
1190 file->ScreenModeId = freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) ? 2 : 1;
1191
1192 LoadBalanceInfoLength = freerdp_settings_get_uint32(settings, FreeRDP_LoadBalanceInfoLength);
1193 if (LoadBalanceInfoLength > 0)
1194 {
1195 const BYTE* LoadBalanceInfo =
1196 freerdp_settings_get_pointer(settings, FreeRDP_LoadBalanceInfo);
1197 file->LoadBalanceInfo = calloc(LoadBalanceInfoLength + 1, 1);
1198 if (!file->LoadBalanceInfo)
1199 return FALSE;
1200 memcpy(file->LoadBalanceInfo, LoadBalanceInfo, LoadBalanceInfoLength);
1201 }
1202
1203 if (freerdp_settings_get_bool(settings, FreeRDP_AudioPlayback))
1204 file->AudioMode = AUDIO_MODE_REDIRECT;
1205 else if (freerdp_settings_get_bool(settings, FreeRDP_RemoteConsoleAudio))
1206 file->AudioMode = AUDIO_MODE_PLAY_ON_SERVER;
1207 else
1208 file->AudioMode = AUDIO_MODE_NONE;
1209
1210 /* The gateway hostname should also contain a port specifier unless it is the default port 443
1211 */
1212 GatewayHostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname);
1213 if (GatewayHostname)
1214 {
1215 const UINT32 GatewayPort = freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort);
1216 freerdp_client_file_string_check_free(file->GatewayHostname);
1217 if (GatewayPort == 443)
1218 file->GatewayHostname = _strdup(GatewayHostname);
1219 else
1220 {
1221 int length = _scprintf("%s:%" PRIu32, GatewayHostname, GatewayPort);
1222 if (length < 0)
1223 return FALSE;
1224
1225 file->GatewayHostname = (char*)malloc((size_t)length + 1);
1226 if (!file->GatewayHostname)
1227 return FALSE;
1228
1229 if (sprintf_s(file->GatewayHostname, (size_t)length + 1, "%s:%" PRIu32, GatewayHostname,
1230 GatewayPort) < 0)
1231 return FALSE;
1232 }
1233 if (!file->GatewayHostname)
1234 return FALSE;
1235 }
1236
1237 if (freerdp_settings_get_bool(settings, FreeRDP_GatewayArmTransport))
1238 file->ResourceProvider = _strdup(str_resourceprovider_arm);
1239
1240 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdWvdEndpointPool, &file->WvdEndpointPool))
1241 return FALSE;
1242 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdGeo, &file->geo))
1243 return FALSE;
1244 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdArmpath, &file->armpath))
1245 return FALSE;
1246 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdAadtenantid, &file->aadtenantid))
1247 return FALSE;
1248 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdDiagnosticserviceurl,
1249 &file->diagnosticserviceurl))
1250 return FALSE;
1251 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdHubdiscoverygeourl,
1252 &file->hubdiscoverygeourl))
1253 return FALSE;
1254 if (!rdp_opt_duplicate(settings, FreeRDP_GatewayAvdActivityhint, &file->activityhint))
1255 return FALSE;
1256
1257 file->AudioCaptureMode =
1258 WINPR_ASSERTING_INT_CAST(UINT32, freerdp_settings_get_bool(settings, FreeRDP_AudioCapture));
1259 file->BitmapCachePersistEnable = WINPR_ASSERTING_INT_CAST(
1260 UINT32, freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled));
1261 file->Compression = WINPR_ASSERTING_INT_CAST(
1262 UINT32, freerdp_settings_get_bool(settings, FreeRDP_CompressionEnabled));
1263 file->AuthenticationLevel = freerdp_settings_get_uint32(settings, FreeRDP_AuthenticationLevel);
1264 file->GatewayUsageMethod = freerdp_get_gateway_usage_method(settings);
1265 file->GatewayCredentialsSource =
1266 freerdp_settings_get_uint32(settings, FreeRDP_GatewayCredentialsSource);
1267 file->PromptCredentialOnce = WINPR_ASSERTING_INT_CAST(
1268 UINT32, freerdp_settings_get_bool(settings, FreeRDP_GatewayUseSameCredentials));
1269 file->PromptForCredentials = WINPR_ASSERTING_INT_CAST(
1270 UINT32, freerdp_settings_get_bool(settings, FreeRDP_PromptForCredentials));
1271 file->RemoteApplicationMode = WINPR_ASSERTING_INT_CAST(
1272 UINT32, freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode));
1273 if (!FILE_POPULATE_STRING(&file->GatewayAccessToken, settings, FreeRDP_GatewayAccessToken) ||
1274 !FILE_POPULATE_STRING(&file->EndpointFedAuthToken, settings,
1275 FreeRDP_EndpointFedAuthToken) ||
1276 !FILE_POPULATE_STRING(&file->RemoteApplicationProgram, settings,
1277 FreeRDP_RemoteApplicationProgram) ||
1278 !FILE_POPULATE_STRING(&file->RemoteApplicationName, settings,
1279 FreeRDP_RemoteApplicationName) ||
1280 !FILE_POPULATE_STRING(&file->RemoteApplicationIcon, settings,
1281 FreeRDP_RemoteApplicationIcon) ||
1282 !FILE_POPULATE_STRING(&file->RemoteApplicationFile, settings,
1283 FreeRDP_RemoteApplicationFile) ||
1284 !FILE_POPULATE_STRING(&file->RemoteApplicationGuid, settings,
1285 FreeRDP_RemoteApplicationGuid) ||
1286 !FILE_POPULATE_STRING(&file->RemoteApplicationCmdLine, settings,
1287 FreeRDP_RemoteApplicationCmdLine))
1288 return FALSE;
1289 file->SpanMonitors =
1290 WINPR_ASSERTING_INT_CAST(UINT32, freerdp_settings_get_bool(settings, FreeRDP_SpanMonitors));
1291 file->UseMultiMon =
1292 WINPR_ASSERTING_INT_CAST(UINT32, freerdp_settings_get_bool(settings, FreeRDP_UseMultimon));
1293 file->AllowDesktopComposition = WINPR_ASSERTING_INT_CAST(
1294 UINT32, freerdp_settings_get_bool(settings, FreeRDP_AllowDesktopComposition));
1295 file->AllowFontSmoothing = WINPR_ASSERTING_INT_CAST(
1296 UINT32, freerdp_settings_get_bool(settings, FreeRDP_AllowFontSmoothing));
1297 file->DisableWallpaper = WINPR_ASSERTING_INT_CAST(
1298 UINT32, freerdp_settings_get_bool(settings, FreeRDP_DisableWallpaper));
1299 file->DisableFullWindowDrag = WINPR_ASSERTING_INT_CAST(
1300 UINT32, freerdp_settings_get_bool(settings, FreeRDP_DisableFullWindowDrag));
1301 file->DisableMenuAnims = WINPR_ASSERTING_INT_CAST(
1302 UINT32, freerdp_settings_get_bool(settings, FreeRDP_DisableMenuAnims));
1303 file->DisableThemes = WINPR_ASSERTING_INT_CAST(
1304 UINT32, freerdp_settings_get_bool(settings, FreeRDP_DisableThemes));
1305 file->BandwidthAutoDetect = (freerdp_settings_get_uint32(settings, FreeRDP_ConnectionType) >=
1306 CONNECTION_TYPE_AUTODETECT);
1307 file->NetworkAutoDetect =
1308 freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect) ? 1 : 0;
1309 file->AutoReconnectionEnabled = WINPR_ASSERTING_INT_CAST(
1310 UINT32, freerdp_settings_get_bool(settings, FreeRDP_AutoReconnectionEnabled));
1311 file->RedirectSmartCards = WINPR_ASSERTING_INT_CAST(
1312 UINT32, freerdp_settings_get_bool(settings, FreeRDP_RedirectSmartCards));
1313 file->RedirectWebauthN = WINPR_ASSERTING_INT_CAST(
1314 UINT32, freerdp_settings_get_bool(settings, FreeRDP_RedirectWebAuthN));
1315
1316 redirectCameras =
1317 freerdp_client_channel_args_to_string(settings, RDPECAM_DVC_CHANNEL_NAME, "device:");
1318 if (redirectCameras)
1319 {
1320 char* str =
1321 freerdp_client_channel_args_to_string(settings, RDPECAM_DVC_CHANNEL_NAME, "encode:");
1322 file->EncodeRedirectedVideoCapture = 0;
1323 if (str)
1324 {
1325 unsigned long val = 0;
1326 errno = 0;
1327 val = strtoul(str, nullptr, 0);
1328 if ((val < UINT32_MAX) && (errno == 0))
1329 file->EncodeRedirectedVideoCapture = (UINT32)val;
1330 }
1331 free(str);
1332
1333 str = freerdp_client_channel_args_to_string(settings, RDPECAM_DVC_CHANNEL_NAME, "quality:");
1334 file->RedirectedVideoCaptureEncodingQuality = 0;
1335 if (str)
1336 {
1337 unsigned long val = 0;
1338 errno = 0;
1339 val = strtoul(str, nullptr, 0);
1340 if ((val <= 2) && (errno == 0))
1341 {
1342 file->RedirectedVideoCaptureEncodingQuality = (UINT32)val;
1343 }
1344 }
1345 free(str);
1346
1347 file->RedirectCameras = redirectCameras;
1348 }
1349 else
1350 freerdp_client_file_string_reset(&file->RedirectCameras);
1351
1352#ifdef CHANNEL_URBDRC_CLIENT
1353 char* redirectUsb =
1354 freerdp_client_channel_args_to_string(settings, URBDRC_CHANNEL_NAME, "device:");
1355 if (redirectUsb)
1356 file->UsbDevicesToRedirect = redirectUsb;
1357 else
1358 freerdp_client_file_string_reset(&file->UsbDevicesToRedirect);
1359#endif
1360
1361 file->RedirectClipboard =
1362 freerdp_settings_get_bool(settings, FreeRDP_RedirectClipboard) ? 1 : 0;
1363 file->RedirectPrinters = freerdp_settings_get_bool(settings, FreeRDP_RedirectPrinters) ? 1 : 0;
1364 file->RedirectDrives = freerdp_settings_get_bool(settings, FreeRDP_RedirectDrives) ? 1 : 0;
1365 file->RdgIsKdcProxy = freerdp_settings_get_bool(settings, FreeRDP_KerberosRdgIsProxy) ? 1 : 0;
1366 file->RedirectComPorts = (freerdp_settings_get_bool(settings, FreeRDP_RedirectSerialPorts) ||
1367 freerdp_settings_get_bool(settings, FreeRDP_RedirectParallelPorts));
1368 file->RedirectLocation =
1369 (freerdp_dynamic_channel_collection_find(settings, LOCATION_CHANNEL_NAME) != nullptr);
1370 if (!FILE_POPULATE_STRING(&file->DrivesToRedirect, settings, FreeRDP_DrivesToRedirect) ||
1371 !FILE_POPULATE_STRING(&file->PreconnectionBlob, settings, FreeRDP_PreconnectionBlob) ||
1372 !FILE_POPULATE_STRING(&file->KdcProxyName, settings, FreeRDP_KerberosKdcUrl))
1373 return FALSE;
1374
1375 {
1376 size_t offset = 0;
1377 UINT32 count = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
1378 const UINT32* MonitorIds = freerdp_settings_get_pointer(settings, FreeRDP_MonitorIds);
1379 /* String size: 10 char UINT32 max string length, 1 char separator, one element nullptr */
1380 size_t size = count * (10 + 1) + 1;
1381
1382 char* str = calloc(size, sizeof(char));
1383 for (UINT32 x = 0; x < count; x++)
1384 {
1385 int rc = _snprintf(&str[offset], size - offset, "%" PRIu32 ",", MonitorIds[x]);
1386 if (rc <= 0)
1387 {
1388 free(str);
1389 return FALSE;
1390 }
1391 offset += (size_t)rc;
1392 }
1393 if (offset > 0)
1394 str[offset - 1] = '\0';
1395 freerdp_client_file_string_check_free(file->SelectedMonitors);
1396 file->SelectedMonitors = str;
1397 }
1398
1399 file->KeyboardHook = freerdp_settings_get_uint32(settings, FreeRDP_KeyboardHook);
1400
1401 return TRUE;
1402}
1403
1404BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, BOOL unicode)
1405{
1406 int status = 0;
1407 WCHAR* unicodestr = nullptr;
1408
1409 if (!file || !name)
1410 return FALSE;
1411
1412 const size_t size = freerdp_client_write_rdp_file_buffer(file, nullptr, 0);
1413 if (size == 0)
1414 return FALSE;
1415 char* buffer = calloc(size + 1ULL, sizeof(char));
1416 if (!buffer)
1417 return FALSE;
1418
1419 if (freerdp_client_write_rdp_file_buffer(file, buffer, size + 1) != size)
1420 {
1421 WLog_ERR(TAG, "freerdp_client_write_rdp_file: error writing to output buffer");
1422 free(buffer);
1423 return FALSE;
1424 }
1425
1426 FILE* fp = winpr_fopen(name, "w+b");
1427
1428 if (fp)
1429 {
1430 if (unicode)
1431 {
1432 size_t len = 0;
1433 unicodestr = ConvertUtf8NToWCharAlloc(buffer, size, &len);
1434
1435 if (!unicodestr)
1436 {
1437 free(buffer);
1438 (void)fclose(fp);
1439 return FALSE;
1440 }
1441
1442 /* Write multi-byte header */
1443 if ((fwrite(BOM_UTF16_LE, sizeof(BYTE), 2, fp) != 2) ||
1444 (fwrite(unicodestr, sizeof(WCHAR), len, fp) != len))
1445 {
1446 free(buffer);
1447 free(unicodestr);
1448 (void)fclose(fp);
1449 return FALSE;
1450 }
1451
1452 free(unicodestr);
1453 }
1454 else
1455 {
1456 if (fwrite(buffer, 1, size, fp) != size)
1457 {
1458 free(buffer);
1459 (void)fclose(fp);
1460 return FALSE;
1461 }
1462 }
1463
1464 (void)fflush(fp);
1465 status = fclose(fp);
1466 }
1467
1468 free(buffer);
1469 return (status == 0);
1470}
1471
1472WINPR_ATTR_FORMAT_ARG(3, 4)
1473static SSIZE_T freerdp_client_write_setting_to_buffer(char** buffer, size_t* bufferSize,
1474 WINPR_FORMAT_ARG const char* fmt, ...)
1475{
1476 va_list ap = WINPR_C_ARRAY_INIT;
1477 SSIZE_T len = 0;
1478 char* buf = nullptr;
1479 size_t bufSize = 0;
1480
1481 if (!buffer || !bufferSize || !fmt)
1482 return -1;
1483
1484 buf = *buffer;
1485 bufSize = *bufferSize;
1486
1487 va_start(ap, fmt);
1488 len = vsnprintf(buf, bufSize, fmt, ap);
1489 va_end(ap);
1490 if (len < 0)
1491 return -1;
1492
1493 /* _snprintf doesn't add the ending \0 to its return value */
1494 ++len;
1495
1496 /* we just want to know the size - return it */
1497 if (!buf && !bufSize)
1498 return len;
1499
1500 if (!buf)
1501 return -1;
1502
1503 /* update buffer size and buffer position and replace \0 with \n */
1504 if (bufSize >= (size_t)len)
1505 {
1506 *bufferSize -= (size_t)len;
1507 buf[len - 1] = '\n';
1508 *buffer = buf + len;
1509 }
1510 else
1511 return -1;
1512
1513 return len;
1514}
1515
1516WINPR_ATTR_NODISCARD
1517static SSIZE_T write_int_parameters(const rdpFile* file, char* buffer, size_t size)
1518{
1519 WINPR_ASSERT(file);
1520
1521 struct intentry_t
1522 {
1523 const char* key;
1524 DWORD val;
1525 };
1526 const struct intentry_t settings[] = {
1527 { key_int_use_multimon, file->UseMultiMon },
1528 { key_int_maximizetocurrentdisplays, file->MaximizeToCurrentDisplays },
1529 { key_int_singlemoninwindowedmode, file->SingleMonInWindowedMode },
1530 { key_int_screen_mode_id, file->ScreenModeId },
1531 { key_int_span_monitors, file->SpanMonitors },
1532 { key_int_smart_sizing, file->SmartSizing },
1533 { key_int_dynamic_resolution, file->DynamicResolution },
1534 { key_int_enablesuperpan, file->EnableSuperSpan },
1535 { key_int_superpanaccelerationfactor, file->SuperSpanAccelerationFactor },
1536 { key_int_desktopwidth, file->DesktopWidth },
1537 { key_int_desktopheight, file->DesktopHeight },
1538 { key_int_desktop_size_id, file->DesktopSizeId },
1539 { key_int_session_bpp, file->SessionBpp },
1540 { key_int_desktopscalefactor, file->DesktopScaleFactor },
1541 { key_int_compression, file->Compression },
1542 { key_int_keyboardhook, file->KeyboardHook },
1543 { key_int_disable_ctrl_alt_del, file->DisableCtrlAltDel },
1544 { key_int_audiomode, file->AudioMode },
1545 { key_int_audioqualitymode, file->AudioQualityMode },
1546 { key_int_audiocapturemode, file->AudioCaptureMode },
1547 { key_int_encode_redirected_video_capture, file->EncodeRedirectedVideoCapture },
1548 { key_int_redirected_video_capture_encoding_quality,
1549 file->RedirectedVideoCaptureEncodingQuality },
1550 { key_int_videoplaybackmode, file->VideoPlaybackMode },
1551 { key_int_connection_type, file->ConnectionType },
1552 { key_int_networkautodetect, file->NetworkAutoDetect },
1553 { key_int_bandwidthautodetect, file->BandwidthAutoDetect },
1554 { key_int_pinconnectionbar, file->PinConnectionBar },
1555 { key_int_displayconnectionbar, file->DisplayConnectionBar },
1556 { key_int_workspaceid, file->WorkspaceId },
1557 { key_int_enableworkspacereconnect, file->EnableWorkspaceReconnect },
1558 { key_int_disable_wallpaper, file->DisableWallpaper },
1559 { key_int_allow_font_smoothing, file->AllowFontSmoothing },
1560 { key_int_allow_desktop_composition, file->AllowDesktopComposition },
1561 { key_int_disable_full_window_drag, file->DisableFullWindowDrag },
1562 { key_int_disable_menu_anims, file->DisableMenuAnims },
1563 { key_int_disable_themes, file->DisableThemes },
1564 { key_int_disable_cursor_setting, file->DisableCursorSetting },
1565 { key_int_bitmapcachesize, file->BitmapCacheSize },
1566 { key_int_bitmapcachepersistenable, file->BitmapCachePersistEnable },
1567 { key_int_server_port, file->ServerPort },
1568 { key_int_redirectdrives, file->RedirectDrives },
1569 { key_int_redirectprinters, file->RedirectPrinters },
1570 { key_int_redirectcomports, file->RedirectComPorts },
1571 { key_int_redirectlocation, file->RedirectLocation },
1572 { key_int_redirectsmartcards, file->RedirectSmartCards },
1573 { key_int_redirectclipboard, file->RedirectClipboard },
1574 { key_int_redirectposdevices, file->RedirectPosDevices },
1575 { key_int_redirectdirectx, file->RedirectDirectX },
1576 { key_int_disableprinterredirection, file->DisablePrinterRedirection },
1577 { key_int_disableclipboardredirection, file->DisableClipboardRedirection },
1578 { key_int_connect_to_console, file->ConnectToConsole },
1579 { key_int_administrative_session, file->AdministrativeSession },
1580 { key_int_autoreconnection_enabled, file->AutoReconnectionEnabled },
1581 { key_int_autoreconnect_max_retries, file->AutoReconnectMaxRetries },
1582 { key_int_public_mode, file->PublicMode },
1583 { key_int_authentication_level, file->AuthenticationLevel },
1584 { key_int_promptcredentialonce, file->PromptCredentialOnce },
1585 { key_int_prompt_for_credentials, file->PromptForCredentials },
1586 { key_int_negotiate_security_layer, file->NegotiateSecurityLayer },
1587 { key_int_enablecredsspsupport, file->EnableCredSSPSupport },
1588 { key_int_enablerdsaadauth, file->EnableRdsAadAuth },
1589 { key_int_remoteapplicationmode, file->RemoteApplicationMode },
1590 { key_int_remoteapplicationexpandcmdline, file->RemoteApplicationExpandCmdLine },
1591 { key_int_remoteapplicationexpandworkingdir, file->RemoteApplicationExpandWorkingDir },
1592 { key_int_disableconnectionsharing, file->DisableConnectionSharing },
1593 { key_int_disableremoteappcapscheck, file->DisableRemoteAppCapsCheck },
1594 { key_int_gatewayusagemethod, file->GatewayUsageMethod },
1595 { key_int_gatewayprofileusagemethod, file->GatewayProfileUsageMethod },
1596 { key_int_gatewaycredentialssource, file->GatewayCredentialsSource },
1597 { key_int_use_redirection_server_name, file->UseRedirectionServerName },
1598 { key_int_rdgiskdcproxy, file->RdgIsKdcProxy },
1599 { key_int_redirectwebauthn, file->RedirectWebauthN }
1600 };
1601
1602 SSIZE_T totalSize = 0;
1603 for (size_t x = 0; x < ARRAYSIZE(settings); x++)
1604 {
1605 const struct intentry_t* cur = &settings[x];
1606 if (~cur->val)
1607 {
1608 const SSIZE_T res = freerdp_client_write_setting_to_buffer(
1609 &buffer, &size, "%s:i:%" PRIu32, cur->key, cur->val);
1610 if (res < 0)
1611 return res;
1612 totalSize += res;
1613 }
1614 }
1615
1616 return totalSize;
1617}
1618
1619WINPR_ATTR_NODISCARD
1620static SSIZE_T write_string_parameters(const rdpFile* file, char* buffer, size_t size)
1621{
1622 WINPR_ASSERT(file);
1623
1624 struct strentry_t
1625 {
1626 const char* key;
1627 const char* val;
1628 };
1629 const struct strentry_t settings[] = {
1630 { key_str_username, file->Username },
1631 { key_str_domain, file->Domain },
1632 { key_str_password, file->Password },
1633 { key_str_full_address, file->FullAddress },
1634 { key_str_alternate_full_address, file->AlternateFullAddress },
1635 { key_str_usbdevicestoredirect, file->UsbDevicesToRedirect },
1636 { key_str_camerastoredirect, file->RedirectCameras },
1637 { key_str_loadbalanceinfo, file->LoadBalanceInfo },
1638 { key_str_remoteapplicationname, file->RemoteApplicationName },
1639 { key_str_remoteapplicationicon, file->RemoteApplicationIcon },
1640 { key_str_remoteapplicationprogram, file->RemoteApplicationProgram },
1641 { key_str_remoteapplicationfile, file->RemoteApplicationFile },
1642 { key_str_remoteapplicationguid, file->RemoteApplicationGuid },
1643 { key_str_remoteapplicationcmdline, file->RemoteApplicationCmdLine },
1644 { key_str_alternate_shell, file->AlternateShell },
1645 { key_str_shell_working_directory, file->ShellWorkingDirectory },
1646 { key_str_gatewayhostname, file->GatewayHostname },
1647 { key_str_resourceprovider, file->ResourceProvider },
1648 { key_str_wvd, file->WvdEndpointPool },
1649 { key_str_geo, file->geo },
1650 { key_str_armpath, file->armpath },
1651 { key_str_aadtenantid, file->aadtenantid },
1652 { key_str_diagnosticserviceurl, file->diagnosticserviceurl },
1653 { key_str_hubdiscoverygeourl, file->hubdiscoverygeourl },
1654 { key_str_activityhint, file->activityhint },
1655 { key_str_gatewayaccesstoken, file->GatewayAccessToken },
1656 { key_str_endpointfedauth, file->EndpointFedAuthToken },
1657 { key_str_kdcproxyname, file->KdcProxyName },
1658 { key_str_drivestoredirect, file->DrivesToRedirect },
1659 { key_str_devicestoredirect, file->DevicesToRedirect },
1660 { key_str_winposstr, file->WinPosStr },
1661 { key_str_pcb, file->PreconnectionBlob },
1662 { key_str_selectedmonitors, file->SelectedMonitors }
1663 };
1664
1665 SSIZE_T totalSize = 0;
1666 for (size_t x = 0; x < ARRAYSIZE(settings); x++)
1667 {
1668 const struct strentry_t* cur = &settings[x];
1669 if (~(size_t)(cur->val))
1670 {
1671 const SSIZE_T res = freerdp_client_write_setting_to_buffer(&buffer, &size, "%s:s:%s",
1672 cur->key, cur->val);
1673 if (res < 0)
1674 return res;
1675 totalSize += res;
1676 }
1677 }
1678
1679 return totalSize;
1680}
1681
1682WINPR_ATTR_NODISCARD
1683static SSIZE_T write_custom_parameters(const rdpFile* file, char* buffer, size_t size)
1684{
1685 WINPR_ASSERT(file);
1686
1687 SSIZE_T totalSize = 0;
1688 /* custom parameters */
1689 for (size_t i = 0; i < file->lineCount; ++i)
1690 {
1691 SSIZE_T res = -1;
1692 const rdpFileLine* curLine = &file->lines[i];
1693
1694 if (curLine->flags & RDP_FILE_LINE_FLAG_TYPE_INTEGER)
1695 res = freerdp_client_write_setting_to_buffer(&buffer, &size, "%s:i:%" PRIu32,
1696 curLine->name, (UINT32)curLine->iValue);
1697 else if (curLine->flags & RDP_FILE_LINE_FLAG_TYPE_STRING)
1698 res = freerdp_client_write_setting_to_buffer(&buffer, &size, "%s:s:%s", curLine->name,
1699 curLine->sValue);
1700 if (res < 0)
1701 return res;
1702
1703 totalSize += res;
1704 }
1705 return totalSize;
1706}
1707
1708size_t freerdp_client_write_rdp_file_buffer(const rdpFile* file, char* buffer, size_t size)
1709{
1710 size_t totalSize = 0;
1711
1712 if (!file)
1713 return 0;
1714
1715 /* either buffer and size are null or non-null */
1716 if ((!buffer || !size) && (buffer || size))
1717 return 0;
1718
1719 /* integer parameters */
1720 const SSIZE_T intsize = write_int_parameters(file, buffer, size);
1721 if (intsize < 0)
1722 return 0;
1723 totalSize += (size_t)intsize;
1724 if (buffer)
1725 buffer += intsize;
1726
1727 /* string parameters */
1728 const SSIZE_T stringsize = write_string_parameters(file, buffer, size);
1729 if (stringsize < 0)
1730 return 0;
1731 totalSize += (size_t)stringsize;
1732 if (buffer)
1733 buffer += stringsize;
1734
1735 /* custom parameters */
1736 const SSIZE_T customsize = write_custom_parameters(file, buffer, size);
1737 if (customsize < 0)
1738 return 0;
1739 totalSize += (size_t)customsize;
1740 return totalSize;
1741}
1742
1743WINPR_ATTR_MALLOC(freerdp_addin_argv_free, 1)
1744static ADDIN_ARGV* rdp_file_to_args(const char* channel, const char* values)
1745{
1746 size_t count = 0;
1747 char** p = nullptr;
1748 ADDIN_ARGV* args = freerdp_addin_argv_new(0, nullptr);
1749 if (!args)
1750 return nullptr;
1751 if (!freerdp_addin_argv_add_argument(args, channel))
1752 goto fail;
1753
1754 p = CommandLineParseCommaSeparatedValues(values, &count);
1755 for (size_t x = 0; x < count; x++)
1756 {
1757 BOOL rc = 0;
1758 const char* val = p[x];
1759 const size_t len = strlen(val) + 8;
1760 char* str = calloc(len, sizeof(char));
1761 if (!str)
1762 goto fail;
1763
1764 (void)_snprintf(str, len, "device:%s", val);
1765 rc = freerdp_addin_argv_add_argument(args, str);
1766 free(str);
1767 if (!rc)
1768 goto fail;
1769 }
1770 CommandLineParserFree(p);
1771 return args;
1772
1773fail:
1774 CommandLineParserFree(p);
1775 freerdp_addin_argv_free(args);
1776 return nullptr;
1777}
1778
1779BOOL freerdp_client_populate_settings_from_rdp_file_unchecked(const rdpFile* file,
1780 rdpSettings* settings)
1781{
1782 if (!file || !settings)
1783 return FALSE;
1784
1785 /* Start with connection type.
1786 * This setting initializes certain defaults which might be overridden by later options.
1787 */
1788 if (~file->BandwidthAutoDetect)
1789 {
1790 if (file->BandwidthAutoDetect != 0)
1791 {
1792 if ((~file->NetworkAutoDetect) && (file->NetworkAutoDetect == 0))
1793 {
1794 WLog_WARN(TAG,
1795 "Got networkautodetect:i:%" PRIu32 " and bandwidthautodetect:i:%" PRIu32
1796 ". Correcting to networkautodetect:i:1",
1797 file->NetworkAutoDetect, file->BandwidthAutoDetect);
1798 WLog_WARN(TAG,
1799 "Add networkautodetect:i:1 to your RDP file to eliminate this warning.");
1800 }
1801 }
1802 if (!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect,
1803 (file->BandwidthAutoDetect != 0) ||
1804 (file->NetworkAutoDetect != 0)))
1805 return FALSE;
1806 }
1807
1808 if (~file->NetworkAutoDetect)
1809 {
1810 if (file->NetworkAutoDetect != 0)
1811 {
1812 if ((~file->BandwidthAutoDetect) && (file->BandwidthAutoDetect == 0))
1813 {
1814 WLog_WARN(TAG,
1815 "Got networkautodetect:i:%" PRIu32 " and bandwidthautodetect:i:%" PRIu32
1816 ". Correcting to bandwidthautodetect:i:1",
1817 file->NetworkAutoDetect, file->BandwidthAutoDetect);
1818 WLog_WARN(
1819 TAG, "Add bandwidthautodetect:i:1 to your RDP file to eliminate this warning.");
1820 }
1821 }
1822 if (!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect,
1823 (file->BandwidthAutoDetect != 0) ||
1824 (file->NetworkAutoDetect != 0)))
1825 return FALSE;
1826 }
1827
1828 if (is_pointer_used(file->Domain))
1829 {
1830 if (!freerdp_settings_set_string(settings, FreeRDP_Domain, file->Domain))
1831 return FALSE;
1832 }
1833
1834 if (is_pointer_used(file->Username))
1835 {
1836 char* user = nullptr;
1837 char* domain = nullptr;
1838
1839 if (!freerdp_parse_username(file->Username, &user, &domain))
1840 return FALSE;
1841
1842 if (!freerdp_settings_set_string(settings, FreeRDP_Username, user))
1843 return FALSE;
1844
1845 if (!(is_pointer_used(file->Domain)) && domain)
1846 {
1847 if (!freerdp_settings_set_string(settings, FreeRDP_Domain, domain))
1848 return FALSE;
1849 }
1850
1851 free(user);
1852 free(domain);
1853 }
1854
1855 if (is_pointer_used(file->Password))
1856 {
1857 if (!freerdp_settings_set_string(settings, FreeRDP_Password, file->Password))
1858 return FALSE;
1859 }
1860
1861 {
1862 const char* address = nullptr;
1863
1864 /* With MSTSC alternate full address always wins,
1865 * so mimic this. */
1866 if (is_pointer_used(file->AlternateFullAddress))
1867 address = file->AlternateFullAddress;
1868 else if (is_pointer_used(file->FullAddress))
1869 address = file->FullAddress;
1870
1871 if (address)
1872 {
1873 int port = -1;
1874 char* host = nullptr;
1875
1876 if (!freerdp_parse_hostname(address, &host, &port))
1877 return FALSE;
1878
1879 const BOOL rc = freerdp_settings_set_string(settings, FreeRDP_ServerHostname, host);
1880 free(host);
1881 if (!rc)
1882 return FALSE;
1883
1884 if (port > 0)
1885 {
1886 if (!freerdp_settings_set_uint32(settings, FreeRDP_ServerPort, (UINT32)port))
1887 return FALSE;
1888 }
1889 }
1890 }
1891
1892 if (~file->ServerPort)
1893 {
1894 if (!freerdp_settings_set_uint32(settings, FreeRDP_ServerPort, file->ServerPort))
1895 return FALSE;
1896 }
1897
1898 if (~file->DesktopSizeId)
1899 {
1900 switch (file->DesktopSizeId)
1901 {
1902 case 0:
1903 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 640))
1904 return FALSE;
1905 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 480))
1906 return FALSE;
1907 break;
1908 case 1:
1909 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 800))
1910 return FALSE;
1911 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 600))
1912 return FALSE;
1913 break;
1914 case 2:
1915 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 1024))
1916 return FALSE;
1917 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 768))
1918 return FALSE;
1919 break;
1920 case 3:
1921 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 1280))
1922 return FALSE;
1923 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 1024))
1924 return FALSE;
1925 break;
1926 case 4:
1927 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, 1600))
1928 return FALSE;
1929 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, 1200))
1930 return FALSE;
1931 break;
1932 default:
1933 WLog_WARN(TAG, "Unsupported 'desktop size id' value %" PRIu32, file->DesktopSizeId);
1934 break;
1935 }
1936 }
1937
1938 if (~file->DesktopWidth)
1939 {
1940 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, file->DesktopWidth))
1941 return FALSE;
1942 }
1943
1944 if (~file->DesktopHeight)
1945 {
1946 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, file->DesktopHeight))
1947 return FALSE;
1948 }
1949
1950 if (~file->SessionBpp)
1951 {
1952 if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, file->SessionBpp))
1953 return FALSE;
1954 }
1955
1956 if (~file->ConnectToConsole)
1957 {
1958 if (!freerdp_settings_set_bool(settings, FreeRDP_ConsoleSession,
1959 file->ConnectToConsole != 0))
1960 return FALSE;
1961 }
1962
1963 if (~file->AdministrativeSession)
1964 {
1965 if (!freerdp_settings_set_bool(settings, FreeRDP_ConsoleSession,
1966 file->AdministrativeSession != 0))
1967 return FALSE;
1968 }
1969
1970 if (~file->NegotiateSecurityLayer)
1971 {
1972 if (!freerdp_settings_set_bool(settings, FreeRDP_NegotiateSecurityLayer,
1973 file->NegotiateSecurityLayer != 0))
1974 return FALSE;
1975 }
1976
1977 if (~file->EnableCredSSPSupport)
1978 {
1979 if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity,
1980 file->EnableCredSSPSupport != 0))
1981 return FALSE;
1982 }
1983
1984 if (~file->EnableRdsAadAuth)
1985 {
1986 const BOOL val = file->EnableRdsAadAuth != 0;
1987 if (!freerdp_settings_set_bool(settings, FreeRDP_AadSecurity, val))
1988 return FALSE;
1989 }
1990
1991 if (is_pointer_used(file->AlternateShell))
1992 {
1993 if (!freerdp_settings_set_string(settings, FreeRDP_AlternateShell, file->AlternateShell))
1994 return FALSE;
1995 }
1996
1997 if (is_pointer_used(file->ShellWorkingDirectory))
1998 {
1999 /* ShellWorkingDir is used for either, shell working dir or remote app working dir */
2000 FreeRDP_Settings_Keys_String targetId =
2001 (~file->RemoteApplicationMode && file->RemoteApplicationMode != 0)
2002 ? FreeRDP_RemoteApplicationWorkingDir
2003 : FreeRDP_ShellWorkingDirectory;
2004
2005 if (!freerdp_settings_set_string(settings, targetId, file->ShellWorkingDirectory))
2006 return FALSE;
2007 }
2008
2009 if (~file->ScreenModeId)
2010 {
2023 if (!freerdp_settings_set_bool(settings, FreeRDP_Fullscreen, (file->ScreenModeId == 2)))
2024 return FALSE;
2025 }
2026
2027 if (~(file->SmartSizing))
2028 {
2029 if (!freerdp_settings_set_bool(settings, FreeRDP_SmartSizing, (file->SmartSizing == 1)))
2030 return FALSE;
2040 if (((~(file->DesktopWidth) && ~(file->DesktopHeight)) || ~(file->DesktopSizeId)) &&
2041 (file->SmartSizing == 1))
2042 {
2043 if (!freerdp_settings_set_uint32(settings, FreeRDP_SmartSizingWidth,
2044 file->DesktopWidth))
2045 return FALSE;
2046 if (!freerdp_settings_set_uint32(settings, FreeRDP_SmartSizingHeight,
2047 file->DesktopHeight))
2048 return FALSE;
2049 }
2050 }
2051
2052 if (is_pointer_used(file->LoadBalanceInfo))
2053 {
2054 const size_t len = strlen(file->LoadBalanceInfo);
2055 if (!freerdp_settings_set_pointer_len(settings, FreeRDP_LoadBalanceInfo,
2056 file->LoadBalanceInfo, len))
2057 return FALSE;
2058 }
2059
2060 if (~file->AuthenticationLevel)
2061 {
2076 if (!freerdp_settings_set_uint32(settings, FreeRDP_AuthenticationLevel,
2077 file->AuthenticationLevel))
2078 return FALSE;
2079 }
2080
2081 if (~file->ConnectionType)
2082 {
2083 if (!freerdp_settings_set_uint32(settings, FreeRDP_ConnectionType, file->ConnectionType))
2084 return FALSE;
2085 }
2086
2087 if (~file->AudioMode)
2088 {
2089 switch (file->AudioMode)
2090 {
2091 case AUDIO_MODE_REDIRECT:
2092 if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteConsoleAudio, FALSE))
2093 return FALSE;
2094 if (!freerdp_settings_set_bool(settings, FreeRDP_AudioPlayback, TRUE))
2095 return FALSE;
2096 break;
2097 case AUDIO_MODE_PLAY_ON_SERVER:
2098 if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteConsoleAudio, TRUE))
2099 return FALSE;
2100 if (!freerdp_settings_set_bool(settings, FreeRDP_AudioPlayback, FALSE))
2101 return FALSE;
2102 break;
2103 case AUDIO_MODE_NONE:
2104 default:
2105 if (!freerdp_settings_set_bool(settings, FreeRDP_AudioPlayback, FALSE))
2106 return FALSE;
2107 if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteConsoleAudio, FALSE))
2108 return FALSE;
2109 break;
2110 }
2111 }
2112
2113 if (~file->AudioCaptureMode)
2114 {
2115 if (!freerdp_settings_set_bool(settings, FreeRDP_AudioCapture, file->AudioCaptureMode != 0))
2116 return FALSE;
2117 }
2118
2119 if (~file->Compression)
2120 {
2121 if (!freerdp_settings_set_bool(settings, FreeRDP_CompressionEnabled,
2122 file->Compression != 0))
2123 return FALSE;
2124 }
2125
2126 if (is_pointer_used(file->GatewayHostname))
2127 {
2128 int port = -1;
2129 char* host = nullptr;
2130
2131 if (!freerdp_parse_hostname(file->GatewayHostname, &host, &port))
2132 return FALSE;
2133
2134 const BOOL rc = freerdp_settings_set_string(settings, FreeRDP_GatewayHostname, host);
2135 free(host);
2136 if (!rc)
2137 return FALSE;
2138
2139 if (port > 0)
2140 {
2141 if (!freerdp_settings_set_uint32(settings, FreeRDP_GatewayPort, (UINT32)port))
2142 return FALSE;
2143 }
2144 }
2145
2146 if (is_pointer_used(file->ResourceProvider))
2147 {
2148 if (_stricmp(file->ResourceProvider, str_resourceprovider_arm) == 0)
2149 {
2150 if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayArmTransport, TRUE))
2151 return FALSE;
2152 }
2153 }
2154
2155 if (is_pointer_used(file->WvdEndpointPool))
2156 {
2157 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdWvdEndpointPool,
2158 file->WvdEndpointPool))
2159 return FALSE;
2160 }
2161
2162 if (is_pointer_used(file->geo))
2163 {
2164 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdGeo, file->geo))
2165 return FALSE;
2166 }
2167
2168 if (is_pointer_used(file->armpath))
2169 {
2170 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdArmpath, file->armpath))
2171 return FALSE;
2172 }
2173
2174 if (is_pointer_used(file->aadtenantid))
2175 {
2176 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdAadtenantid,
2177 file->aadtenantid))
2178 return FALSE;
2179 }
2180
2181 if (is_pointer_used(file->diagnosticserviceurl))
2182 {
2183 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdDiagnosticserviceurl,
2184 file->diagnosticserviceurl))
2185 return FALSE;
2186 }
2187
2188 if (is_pointer_used(file->hubdiscoverygeourl))
2189 {
2190 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdHubdiscoverygeourl,
2191 file->hubdiscoverygeourl))
2192 return FALSE;
2193 }
2194
2195 if (is_pointer_used(file->activityhint))
2196 {
2197 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAvdActivityhint,
2198 file->activityhint))
2199 return FALSE;
2200 }
2201
2202 if (is_pointer_used(file->GatewayAccessToken))
2203 {
2204 if (!freerdp_settings_set_string(settings, FreeRDP_GatewayAccessToken,
2205 file->GatewayAccessToken))
2206 return FALSE;
2207 }
2208
2209 if (is_pointer_used(file->EndpointFedAuthToken))
2210 {
2211 if (!freerdp_settings_set_string(settings, FreeRDP_EndpointFedAuthToken,
2212 file->EndpointFedAuthToken))
2213 return FALSE;
2214 }
2215
2216 if (~file->GatewayUsageMethod)
2217 {
2218 if (!freerdp_set_gateway_usage_method(settings, file->GatewayUsageMethod))
2219 return FALSE;
2220 }
2221
2222 if (~file->GatewayCredentialsSource)
2223 {
2224 if (file->GatewayCredentialsSource > 5)
2225 {
2226 WLog_WARN(TAG, "ignoring gatewaycredentialssource value outside range 0..5");
2227 }
2228 else if (!freerdp_settings_set_uint32(settings, FreeRDP_GatewayCredentialsSource,
2229 file->GatewayCredentialsSource))
2230 return FALSE;
2231 }
2232
2233 if (~file->PromptCredentialOnce)
2234 {
2235 if (!freerdp_settings_set_bool(settings, FreeRDP_GatewayUseSameCredentials,
2236 file->PromptCredentialOnce != 0))
2237 return FALSE;
2238 }
2239
2240 if (~file->PromptForCredentials)
2241 {
2242 if (!freerdp_settings_set_bool(settings, FreeRDP_PromptForCredentials,
2243 file->PromptForCredentials != 0))
2244 return FALSE;
2245 }
2246
2247 if (~file->RemoteApplicationMode)
2248 {
2249 if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteApplicationMode,
2250 file->RemoteApplicationMode != 0))
2251 return FALSE;
2252 }
2253
2254 if (is_pointer_used(file->RemoteApplicationProgram))
2255 {
2256 if (!freerdp_settings_set_string(settings, FreeRDP_RemoteApplicationProgram,
2257 file->RemoteApplicationProgram))
2258 return FALSE;
2259 }
2260
2261 if (is_pointer_used(file->RemoteApplicationName))
2262 {
2263 if (!freerdp_settings_set_string(settings, FreeRDP_RemoteApplicationName,
2264 file->RemoteApplicationName))
2265 return FALSE;
2266 }
2267
2268 if (is_pointer_used(file->RemoteApplicationIcon))
2269 {
2270 if (!freerdp_settings_set_string(settings, FreeRDP_RemoteApplicationIcon,
2271 file->RemoteApplicationIcon))
2272 return FALSE;
2273 }
2274
2275 if (is_pointer_used(file->RemoteApplicationFile))
2276 {
2277 if (!freerdp_settings_set_string(settings, FreeRDP_RemoteApplicationFile,
2278 file->RemoteApplicationFile))
2279 return FALSE;
2280 }
2281
2282 if (is_pointer_used(file->RemoteApplicationGuid))
2283 {
2284 if (!freerdp_settings_set_string(settings, FreeRDP_RemoteApplicationGuid,
2285 file->RemoteApplicationGuid))
2286 return FALSE;
2287 }
2288
2289 if (is_pointer_used(file->RemoteApplicationCmdLine))
2290 {
2291 if (!freerdp_settings_set_string(settings, FreeRDP_RemoteApplicationCmdLine,
2292 file->RemoteApplicationCmdLine))
2293 return FALSE;
2294 }
2295
2296 if (~file->SpanMonitors)
2297 {
2298 if (!freerdp_settings_set_bool(settings, FreeRDP_SpanMonitors, file->SpanMonitors != 0))
2299 return FALSE;
2300 }
2301
2302 if (~file->UseMultiMon)
2303 {
2304 if (!freerdp_settings_set_bool(settings, FreeRDP_UseMultimon, file->UseMultiMon != 0))
2305 return FALSE;
2306 }
2307
2308 if (~file->AllowFontSmoothing)
2309 {
2310 if (!freerdp_settings_set_bool(settings, FreeRDP_AllowFontSmoothing,
2311 file->AllowFontSmoothing != 0))
2312 return FALSE;
2313 }
2314
2315 if (~file->DisableWallpaper)
2316 {
2317 if (!freerdp_settings_set_bool(settings, FreeRDP_DisableWallpaper,
2318 file->DisableWallpaper != 0))
2319 return FALSE;
2320 }
2321
2322 if (~file->DisableFullWindowDrag)
2323 {
2324 if (!freerdp_settings_set_bool(settings, FreeRDP_DisableFullWindowDrag,
2325 file->DisableFullWindowDrag != 0))
2326 return FALSE;
2327 }
2328
2329 if (~file->DisableMenuAnims)
2330 {
2331 if (!freerdp_settings_set_bool(settings, FreeRDP_DisableMenuAnims,
2332 file->DisableMenuAnims != 0))
2333 return FALSE;
2334 }
2335
2336 if (~file->DisableThemes)
2337 {
2338 if (!freerdp_settings_set_bool(settings, FreeRDP_DisableThemes, file->DisableThemes != 0))
2339 return FALSE;
2340 }
2341
2342 if (~file->AllowDesktopComposition)
2343 {
2344 if (!freerdp_settings_set_bool(settings, FreeRDP_AllowDesktopComposition,
2345 file->AllowDesktopComposition != 0))
2346 return FALSE;
2347 }
2348
2349 if (~file->BitmapCachePersistEnable)
2350 {
2351 if (!freerdp_settings_set_bool(settings, FreeRDP_BitmapCachePersistEnabled,
2352 file->BitmapCachePersistEnable != 0))
2353 return FALSE;
2354 }
2355
2356 if (~file->DisableRemoteAppCapsCheck)
2357 {
2358 if (!freerdp_settings_set_bool(settings, FreeRDP_DisableRemoteAppCapsCheck,
2359 file->DisableRemoteAppCapsCheck != 0))
2360 return FALSE;
2361 }
2362
2363 if (~file->AutoReconnectionEnabled)
2364 {
2365 if (!freerdp_settings_set_bool(settings, FreeRDP_AutoReconnectionEnabled,
2366 file->AutoReconnectionEnabled != 0))
2367 return FALSE;
2368 }
2369
2370 if (~file->AutoReconnectMaxRetries)
2371 {
2372 if (!freerdp_settings_set_uint32(settings, FreeRDP_AutoReconnectMaxRetries,
2373 file->AutoReconnectMaxRetries))
2374 return FALSE;
2375 }
2376
2377 if (~file->RedirectSmartCards)
2378 {
2379 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectSmartCards,
2380 file->RedirectSmartCards != 0))
2381 return FALSE;
2382 }
2383
2384 if (~file->RedirectWebauthN)
2385 {
2386 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectWebAuthN,
2387 file->RedirectWebauthN != 0))
2388 return FALSE;
2389 }
2390
2391 if (~file->RedirectClipboard)
2392 {
2393 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectClipboard,
2394 file->RedirectClipboard != 0))
2395 return FALSE;
2396 }
2397
2398 if (~file->RedirectPrinters)
2399 {
2400 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectPrinters,
2401 file->RedirectPrinters != 0))
2402 return FALSE;
2403 }
2404
2405 if (~file->RedirectDrives)
2406 {
2407 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectDrives, file->RedirectDrives != 0))
2408 return FALSE;
2409 }
2410
2411 if (~file->RedirectPosDevices)
2412 {
2413 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectSerialPorts,
2414 file->RedirectComPorts != 0) ||
2415 !freerdp_settings_set_bool(settings, FreeRDP_RedirectParallelPorts,
2416 file->RedirectComPorts != 0))
2417 return FALSE;
2418 }
2419
2420 if (~file->RedirectComPorts)
2421 {
2422 if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectSerialPorts,
2423 file->RedirectComPorts != 0) ||
2424 !freerdp_settings_set_bool(settings, FreeRDP_RedirectParallelPorts,
2425 file->RedirectComPorts != 0))
2426 return FALSE;
2427 }
2428
2429 if (~file->RedirectLocation && (file->RedirectLocation != 0))
2430 {
2431 size_t count = 0;
2432
2433 char** ptr = CommandLineParseCommaSeparatedValuesEx(LOCATION_CHANNEL_NAME, nullptr, &count);
2434 const BOOL rc =
2435 freerdp_client_add_dynamic_channel(settings, count, (const char* const*)ptr);
2436 CommandLineParserFree(ptr);
2437 if (!rc)
2438 return FALSE;
2439 }
2440
2441 if (~file->RedirectDirectX)
2442 {
2443 /* What is this?! */
2444 }
2445
2446 if ((is_pointer_used(file->DevicesToRedirect)) && !utils_str_is_empty(file->DevicesToRedirect))
2447 {
2472 if (!freerdp_settings_set_bool(settings, FreeRDP_DeviceRedirection, TRUE))
2473 return FALSE;
2474 }
2475
2476 if ((is_pointer_used(file->DrivesToRedirect)) && !utils_str_is_empty(file->DrivesToRedirect))
2477 {
2478 if (!freerdp_settings_set_string(settings, FreeRDP_DrivesToRedirect,
2479 file->DrivesToRedirect))
2480 return FALSE;
2481 }
2482
2483 if ((is_pointer_used(file->RedirectCameras)) && !utils_str_is_empty(file->RedirectCameras))
2484 {
2485#if defined(CHANNEL_RDPECAM_CLIENT)
2486 union
2487 {
2488 char** c;
2489 const char* const* cc;
2490 } cnv;
2491 ADDIN_ARGV* args = rdp_file_to_args(RDPECAM_DVC_CHANNEL_NAME, file->RedirectCameras);
2492 if (!args)
2493 return FALSE;
2494
2495 BOOL status = TRUE;
2496 if (~file->EncodeRedirectedVideoCapture)
2497 {
2498 char encode[64] = WINPR_C_ARRAY_INIT;
2499 (void)_snprintf(encode, sizeof(encode), "encode:%" PRIu32,
2500 file->EncodeRedirectedVideoCapture);
2501 if (!freerdp_addin_argv_add_argument(args, encode))
2502 status = FALSE;
2503 }
2504 if (~file->RedirectedVideoCaptureEncodingQuality)
2505 {
2506 char quality[64] = WINPR_C_ARRAY_INIT;
2507 (void)_snprintf(quality, sizeof(quality), "quality:%" PRIu32,
2508 file->RedirectedVideoCaptureEncodingQuality);
2509 if (!freerdp_addin_argv_add_argument(args, quality))
2510 status = FALSE;
2511 }
2512
2513 cnv.c = args->argv;
2514 if (status)
2515 status = freerdp_client_add_dynamic_channel(
2516 settings, WINPR_ASSERTING_INT_CAST(size_t, args->argc), cnv.cc);
2517 freerdp_addin_argv_free(args);
2518 if (!status)
2519 return FALSE;
2520#else
2521 WLog_WARN(
2522 TAG,
2523 "This build does not support [MS-RDPECAM] camera redirection channel. Ignoring '%s'",
2524 key_str_camerastoredirect);
2525#endif
2526 }
2527
2528 if ((is_pointer_used(file->UsbDevicesToRedirect)) &&
2529 !utils_str_is_empty(file->UsbDevicesToRedirect))
2530 {
2531#ifdef CHANNEL_URBDRC_CLIENT
2532 union
2533 {
2534 char** c;
2535 const char* const* cc;
2536 } cnv;
2537 ADDIN_ARGV* args = rdp_file_to_args(URBDRC_CHANNEL_NAME, file->UsbDevicesToRedirect);
2538 if (!args)
2539 return FALSE;
2540 cnv.c = args->argv;
2541 const BOOL status = freerdp_client_add_dynamic_channel(
2542 settings, WINPR_ASSERTING_INT_CAST(size_t, args->argc), cnv.cc);
2543 freerdp_addin_argv_free(args);
2544 if (!status)
2545 return FALSE;
2546#else
2547 WLog_WARN(TAG,
2548 "This build does not support [MS-RDPEUSB] usb redirection channel. Ignoring '%s'",
2549 key_str_usbdevicestoredirect);
2550#endif
2551 }
2552
2553 if (~file->KeyboardHook)
2554 {
2555 if (!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardHook, file->KeyboardHook))
2556 return FALSE;
2557 }
2558
2559 if (~(size_t)file->SelectedMonitors)
2560 {
2561 size_t count = 0;
2562 char** ptr = CommandLineParseCommaSeparatedValues(file->SelectedMonitors, &count);
2563 UINT32* list = nullptr;
2564
2565 if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, count))
2566 {
2567 CommandLineParserFree(ptr);
2568 return FALSE;
2569 }
2570 list = freerdp_settings_get_pointer_writable(settings, FreeRDP_MonitorIds);
2571 if (!list && (count > 0))
2572 {
2573 CommandLineParserFree(ptr);
2574 return FALSE;
2575 }
2576 for (size_t x = 0; x < count; x++)
2577 {
2578 unsigned long val = 0;
2579 errno = 0;
2580 val = strtoul(ptr[x], nullptr, 0);
2581 if ((val >= UINT32_MAX) && (errno != 0))
2582 {
2583 CommandLineParserFree(ptr);
2584 return FALSE;
2585 }
2586 list[x] = (UINT32)val;
2587 }
2588 CommandLineParserFree(ptr);
2589 }
2590
2591 if (~file->DynamicResolution)
2592 {
2593 const BOOL val = file->DynamicResolution != 0;
2594 if (!freerdp_settings_set_bool(settings, FreeRDP_SupportDisplayControl, val))
2595 return FALSE;
2596 if (!freerdp_settings_set_bool(settings, FreeRDP_DynamicResolutionUpdate, val))
2597 return FALSE;
2598 }
2599
2600 if (~file->DesktopScaleFactor)
2601 {
2602 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopScaleFactor,
2603 file->DesktopScaleFactor))
2604 return FALSE;
2605 }
2606
2607 if (~file->VideoPlaybackMode)
2608 {
2609 if (file->VideoPlaybackMode != 0)
2610 {
2611 if (!freerdp_settings_set_bool(settings, FreeRDP_SupportGeometryTracking, TRUE) ||
2612 !freerdp_settings_set_bool(settings, FreeRDP_SupportVideoOptimized, TRUE))
2613 return FALSE;
2614 }
2615 else
2616 {
2617 if (!freerdp_settings_set_bool(settings, FreeRDP_SupportVideoOptimized, FALSE))
2618 return FALSE;
2619 }
2620 }
2621 // TODO file->MaximizeToCurrentDisplays;
2622 // TODO file->SingleMonInWindowedMode;
2623 // TODO file->EncodeRedirectedVideoCapture;
2624 // TODO file->RedirectedVideoCaptureEncodingQuality;
2625
2626 if (is_pointer_used(file->PreconnectionBlob))
2627 {
2628 if (!freerdp_settings_set_string(settings, FreeRDP_PreconnectionBlob,
2629 file->PreconnectionBlob) ||
2630 !freerdp_settings_set_bool(settings, FreeRDP_SendPreconnectionPdu, TRUE))
2631 return FALSE;
2632 }
2633
2634 if (is_pointer_used(file->KdcProxyName))
2635 {
2636 if (!freerdp_settings_set_string(settings, FreeRDP_KerberosKdcUrl, file->KdcProxyName))
2637 return FALSE;
2638 }
2639
2640 if (~file->RdgIsKdcProxy)
2641 {
2642 if (!freerdp_settings_set_bool(settings, FreeRDP_KerberosRdgIsProxy,
2643 file->RdgIsKdcProxy != 0))
2644 return FALSE;
2645 }
2646
2647 if (file->args->argc > 1)
2648 {
2649 WCHAR* ConnectionFile =
2650 freerdp_settings_get_string_as_utf16(settings, FreeRDP_ConnectionFile, nullptr);
2651
2652 if (freerdp_client_settings_parse_command_line(settings, file->args->argc, file->args->argv,
2653 FALSE) < 0)
2654 {
2655 free(ConnectionFile);
2656 return FALSE;
2657 }
2658
2659 BOOL rc = freerdp_settings_set_string_from_utf16(settings, FreeRDP_ConnectionFile,
2660 ConnectionFile);
2661 free(ConnectionFile);
2662 if (!rc)
2663 return FALSE;
2664 }
2665
2666 return TRUE;
2667}
2668
2669WINPR_ATTR_NODISCARD
2670static BOOL freerdp_apply_connection_type_from_file(const rdpFile* file, rdpSettings* settings,
2671 UINT32 type)
2672{
2673 struct network_settings
2674 {
2675 FreeRDP_Settings_Keys_Bool id;
2676 BOOL apply;
2677 BOOL value[7];
2678 };
2679 WINPR_ASSERT(file);
2680
2681 const struct network_settings config[] = { { FreeRDP_DisableWallpaper,
2682 (~file->DisableWallpaper) == 0,
2683 { TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE } },
2684 { FreeRDP_AllowFontSmoothing,
2685 (~file->AllowFontSmoothing) == 0,
2686 { FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE } },
2687 { FreeRDP_AllowDesktopComposition,
2688 (~file->AllowDesktopComposition) == 0,
2689 { FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE } },
2690 { FreeRDP_DisableFullWindowDrag,
2691 (~file->DisableFullWindowDrag) == 0,
2692 { TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE } },
2693 { FreeRDP_DisableMenuAnims,
2694 (~file->DisableMenuAnims) == 0,
2695 { TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE } },
2696 { FreeRDP_DisableThemes,
2697 (~file->DisableThemes) == 0,
2698 { TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
2699 FALSE } } };
2700
2701 switch (type)
2702 {
2703 case CONNECTION_TYPE_INVALID:
2704 return TRUE;
2705
2706 case CONNECTION_TYPE_MODEM:
2707 case CONNECTION_TYPE_BROADBAND_LOW:
2708 case CONNECTION_TYPE_BROADBAND_HIGH:
2709 case CONNECTION_TYPE_SATELLITE:
2710 case CONNECTION_TYPE_WAN:
2711 case CONNECTION_TYPE_LAN:
2712 case CONNECTION_TYPE_AUTODETECT:
2713 break;
2714 default:
2715 WLog_WARN(TAG, "Unknown ConnectionType %" PRIu32 ", aborting", type);
2716 return FALSE;
2717 }
2718
2719 for (size_t x = 0; x < ARRAYSIZE(config); x++)
2720 {
2721 const struct network_settings* cur = &config[x];
2722 if (!cur->apply)
2723 continue;
2724
2725 if (!freerdp_settings_set_bool(settings, cur->id, cur->value[type - 1]))
2726 return FALSE;
2727 }
2728 return TRUE;
2729}
2730
2731WINPR_ATTR_NODISCARD
2732static BOOL freerdp_set_connection_type_from_file(const rdpFile* file, rdpSettings* settings,
2733 UINT32 type)
2734{
2735 WINPR_ASSERT(file);
2736 if (!freerdp_settings_set_uint32(settings, FreeRDP_ConnectionType, type))
2737 return FALSE;
2738
2739 switch (type)
2740 {
2741 case CONNECTION_TYPE_INVALID:
2742 case CONNECTION_TYPE_MODEM:
2743 case CONNECTION_TYPE_BROADBAND_LOW:
2744 case CONNECTION_TYPE_SATELLITE:
2745 case CONNECTION_TYPE_BROADBAND_HIGH:
2746 case CONNECTION_TYPE_WAN:
2747 case CONNECTION_TYPE_LAN:
2748 if (!freerdp_apply_connection_type_from_file(file, settings, type))
2749 return FALSE;
2750 break;
2751 case CONNECTION_TYPE_AUTODETECT:
2752 if (!freerdp_apply_connection_type_from_file(file, settings, type))
2753 return FALSE;
2754 /* Automatically activate GFX and RFX codec support */
2755#ifdef WITH_GFX_H264
2756 if (!freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444v2, TRUE) ||
2757 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444, TRUE) ||
2758 !freerdp_settings_set_bool(settings, FreeRDP_GfxH264, TRUE))
2759 return FALSE;
2760#endif
2761 if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE) ||
2762 !freerdp_settings_set_bool(settings, FreeRDP_SupportGraphicsPipeline, TRUE))
2763 return FALSE;
2764 break;
2765 default:
2766 WLog_WARN(TAG, "Unknown ConnectionType %" PRIu32 ", aborting", type);
2767 return FALSE;
2768 }
2769
2770 return TRUE;
2771}
2772
2773BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSettings* settings)
2774{
2775 if (!freerdp_client_populate_settings_from_rdp_file_unchecked(file, settings))
2776 return FALSE;
2777
2778 DWORD type = freerdp_settings_get_uint32(settings, FreeRDP_ConnectionType);
2779 if ((~file->ConnectionType) == 0)
2780 {
2781 if (freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect))
2782 type = CONNECTION_TYPE_AUTODETECT;
2783 }
2784 return freerdp_set_connection_type_from_file(file, settings, type);
2785}
2786
2787WINPR_ATTR_NODISCARD
2788static rdpFileLine* freerdp_client_rdp_file_find_line_by_name(const rdpFile* file, const char* name)
2789{
2790 BOOL bFound = FALSE;
2791 rdpFileLine* line = nullptr;
2792
2793 for (size_t index = 0; index < file->lineCount; index++)
2794 {
2795 line = &(file->lines[index]);
2796
2797 if (line->flags & RDP_FILE_LINE_FLAG_FORMATTED)
2798 {
2799 if (_stricmp(name, line->name) == 0)
2800 {
2801 bFound = TRUE;
2802 break;
2803 }
2804 }
2805 }
2806
2807 return (bFound) ? line : nullptr;
2808}
2816int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, const char* value)
2817{
2818 return freerdp_client_rdp_file_set_string(file, name, value);
2819}
2820
2821const char* freerdp_client_rdp_file_get_string_option(const rdpFile* file, const char* name)
2822{
2823 LPSTR* value = nullptr;
2824 rdpFileLine* line = nullptr;
2825
2826 rdpFile* wfile = WINPR_CAST_CONST_PTR_AWAY(file, rdpFile*);
2827 if (freerdp_client_rdp_file_find_string_entry(wfile, name, &value, &line))
2828 {
2829 if (value && ~(size_t)(*value))
2830 return *value;
2831 if (line)
2832 return line->sValue;
2833 }
2834
2835 return nullptr;
2836}
2837
2838int freerdp_client_rdp_file_set_integer_option(rdpFile* file, const char* name, int value)
2839{
2840 return freerdp_client_rdp_file_set_integer(file, name, value);
2841}
2842
2843int freerdp_client_rdp_file_get_integer_option(const rdpFile* file, const char* name)
2844{
2845 DWORD* value = nullptr;
2846 rdpFileLine* line = nullptr;
2847
2848 rdpFile* wfile = WINPR_CAST_CONST_PTR_AWAY(file, rdpFile*);
2849 if (freerdp_client_rdp_file_find_integer_entry(wfile, name, &value, &line))
2850 {
2851 if (value && ~(*value))
2852 return WINPR_ASSERTING_INT_CAST(int, *value);
2853 if (line)
2854 return (int)line->iValue;
2855 }
2856
2857 return -1;
2858}
2859
2860static void freerdp_client_file_string_check_free(LPSTR str)
2861{
2862 if (is_pointer_used(str))
2863 free(str);
2864}
2865
2866rdpFile* freerdp_client_rdp_file_new(void)
2867{
2868 return freerdp_client_rdp_file_new_ex(0);
2869}
2870
2871rdpFile* freerdp_client_rdp_file_new_ex(DWORD flags)
2872{
2873 rdpFile* file = (rdpFile*)calloc(1, sizeof(rdpFile));
2874
2875 if (!file)
2876 return nullptr;
2877
2878 file->flags = flags;
2879
2880 FillMemory(file, sizeof(rdpFile), 0xFF);
2881 file->lines = nullptr;
2882 file->lineCount = 0;
2883 file->lineSize = 32;
2884 file->GatewayProfileUsageMethod = 1;
2885 file->lines = (rdpFileLine*)calloc(file->lineSize, sizeof(rdpFileLine));
2886
2887 file->args = freerdp_addin_argv_new(0, nullptr);
2888 if (!file->lines || !file->args)
2889 goto fail;
2890
2891 if (!freerdp_client_add_option(file, "freerdp"))
2892 goto fail;
2893
2894 return file;
2895fail:
2896 WINPR_PRAGMA_DIAG_PUSH
2897 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2898 freerdp_client_rdp_file_free(file);
2899 WINPR_PRAGMA_DIAG_POP
2900 return nullptr;
2901}
2902
2903void freerdp_client_rdp_file_free(rdpFile* file)
2904{
2905 if (file)
2906 {
2907 for (size_t i = 0; i < file->lineCount; i++)
2908 {
2909 rdpFileLine* cur = &file->lines[i];
2910 free(cur->name);
2911 free(cur->sValue);
2912 }
2913
2914 free(file->lines);
2915
2916 freerdp_addin_argv_free(file->args);
2917
2918 freerdp_client_file_string_check_free(file->SelectedMonitors);
2919 freerdp_client_file_string_check_free(file->Username);
2920 freerdp_client_file_string_check_free(file->Domain);
2921 freerdp_client_file_string_check_free(file->Password);
2922 freerdp_client_file_string_check_free(file->FullAddress);
2923 freerdp_client_file_string_check_free(file->AlternateFullAddress);
2924 freerdp_client_file_string_check_free(file->UsbDevicesToRedirect);
2925 freerdp_client_file_string_check_free(file->RedirectCameras);
2926 freerdp_client_file_string_check_free(file->LoadBalanceInfo);
2927 freerdp_client_file_string_check_free(file->RemoteApplicationName);
2928 freerdp_client_file_string_check_free(file->RemoteApplicationIcon);
2929 freerdp_client_file_string_check_free(file->RemoteApplicationProgram);
2930 freerdp_client_file_string_check_free(file->RemoteApplicationFile);
2931 freerdp_client_file_string_check_free(file->RemoteApplicationGuid);
2932 freerdp_client_file_string_check_free(file->RemoteApplicationCmdLine);
2933 freerdp_client_file_string_check_free(file->AlternateShell);
2934 freerdp_client_file_string_check_free(file->ShellWorkingDirectory);
2935 freerdp_client_file_string_check_free(file->GatewayHostname);
2936 freerdp_client_file_string_check_free(file->ResourceProvider);
2937 freerdp_client_file_string_check_free(file->WvdEndpointPool);
2938 freerdp_client_file_string_check_free(file->geo);
2939 freerdp_client_file_string_check_free(file->armpath);
2940 freerdp_client_file_string_check_free(file->aadtenantid);
2941 freerdp_client_file_string_check_free(file->diagnosticserviceurl);
2942 freerdp_client_file_string_check_free(file->hubdiscoverygeourl);
2943 freerdp_client_file_string_check_free(file->activityhint);
2944 freerdp_client_file_string_check_free(file->GatewayAccessToken);
2945 freerdp_client_file_string_check_free(file->EndpointFedAuthToken);
2946 freerdp_client_file_string_check_free(file->DrivesToRedirect);
2947 freerdp_client_file_string_check_free(file->DevicesToRedirect);
2948 freerdp_client_file_string_check_free(file->WinPosStr);
2949 freerdp_client_file_string_check_free(file->PreconnectionBlob);
2950 freerdp_client_file_string_check_free(file->KdcProxyName);
2951
2952 free(file);
2953 }
2954}
2955
2956void freerdp_client_rdp_file_set_callback_context(rdpFile* file, void* context)
2957{
2958 file->context = context;
2959}
#define LOCATION_CHANNEL_NAME
WINPR_ATTR_NODISCARD FREERDP_API const void * freerdp_settings_get_pointer(const rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a immutable pointer settings value.
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL val)
Sets a BOOL settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_string_from_utf16(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const WCHAR *param)
Sets a string settings value. The param is converted to UTF-8 and the copy stored.
WINPR_ATTR_NODISCARD FREERDP_API void * freerdp_settings_get_pointer_writable(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a mutable pointer settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.
WINPR_ATTR_NODISCARD 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.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
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.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_set_gateway_usage_method(rdpSettings *settings, UINT32 GatewayUsageMethod)
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_string(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *val)
Sets a string settings value. The param is copied.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.