Coverage Report

Created: 2024-09-08 06:20

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