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