2 * FreeRDP: A Remote Desktop Protocol Implementation
3 * FreeRDP Client Command-Line Interface
5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include <winpr/crt.h>
27 #include <winpr/cmdline.h>
29 #include <freerdp/addin.h>
30 #include <freerdp/settings.h>
31 #include <freerdp/client/channels.h>
32 #include <freerdp/crypto/crypto.h>
33 #include <freerdp/locale/keyboard.h>
36 #include <freerdp/client/cmdline.h>
37 #include <freerdp/version.h>
39 #include "compatibility.h"
41 #include <freerdp/log.h>
42 #define TAG CLIENT_TAG("common.cmdline")
44 COMMAND_LINE_ARGUMENT_A args[] =
46 { "v", COMMAND_LINE_VALUE_REQUIRED, "<server>[:port]", NULL, NULL, -1, NULL, "Server hostname" },
47 { "port", COMMAND_LINE_VALUE_REQUIRED, "<number>", NULL, NULL, -1, NULL, "Server port" },
48 { "w", COMMAND_LINE_VALUE_REQUIRED, "<width>", "1024", NULL, -1, NULL, "Width" },
49 { "h", COMMAND_LINE_VALUE_REQUIRED, "<height>", "768", NULL, -1, NULL, "Height" },
50 { "size", COMMAND_LINE_VALUE_REQUIRED, "<width>x<height> or <percent>%", "1024x768", NULL, -1, NULL, "Screen size" },
51 { "f", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Fullscreen mode" },
52 { "bpp", COMMAND_LINE_VALUE_REQUIRED, "<depth>", "16", NULL, -1, NULL, "Session bpp (color depth)" },
53 { "kbd", COMMAND_LINE_VALUE_REQUIRED, "0x<layout id> or <layout name>", NULL, NULL, -1, NULL, "Keyboard layout" },
54 { "kbd-list", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT, NULL, NULL, NULL, -1, NULL, "List keyboard layouts" },
55 { "kbd-type", COMMAND_LINE_VALUE_REQUIRED, "<type id>", NULL, NULL, -1, NULL, "Keyboard type" },
56 { "kbd-subtype", COMMAND_LINE_VALUE_REQUIRED, "<subtype id>", NULL, NULL, -1, NULL, "Keyboard subtype" },
57 { "kbd-fn-key", COMMAND_LINE_VALUE_REQUIRED, "<function key count>", NULL, NULL, -1, NULL, "Keyboard function key count" },
58 { "admin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "console", "Admin (or console) session" },
59 { "restricted-admin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "restrictedAdmin", "Restricted admin mode" },
60 { "pth", COMMAND_LINE_VALUE_REQUIRED, "<password hash>", NULL, NULL, -1, "pass-the-hash", "Pass the hash (restricted admin mode)" },
61 { "client-hostname", COMMAND_LINE_VALUE_REQUIRED, "<name>", NULL, NULL, -1, NULL, "Client Hostname to send to server" },
62 { "multimon", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "Use multiple monitors" },
63 { "span", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "Span screen over multiple monitors" },
64 { "workarea", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Use available work area" },
65 { "monitors", COMMAND_LINE_VALUE_REQUIRED, "<0,1,2...>", NULL, NULL, -1, NULL, "Select monitors to use" },
66 { "monitor-list", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT, NULL, NULL, NULL, -1, NULL, "List detected monitors" },
67 { "t", COMMAND_LINE_VALUE_REQUIRED, "<title>", NULL, NULL, -1, "title", "Window title" },
68 { "decorations", COMMAND_LINE_VALUE_BOOL, NULL, NULL, BoolValueTrue, -1, NULL, "Window decorations" },
69 { "smart-sizing", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Scale remote desktop to window size" },
70 { "a", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, "addin", "Addin" },
71 { "vc", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Static virtual channel" },
72 { "dvc", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Dynamic virtual channel" },
73 { "u", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\]<user> or <user>[@<domain>]", NULL, NULL, -1, NULL, "Username" },
74 { "p", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL, "Password" },
75 { "d", COMMAND_LINE_VALUE_REQUIRED, "<domain>", NULL, NULL, -1, NULL, "Domain" },
76 { "g", COMMAND_LINE_VALUE_OPTIONAL, "<gateway>[:port]", NULL, NULL, -1, NULL, "Gateway Hostname" },
77 { "gu", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\]<user> or <user>[@<domain>]", NULL, NULL, -1, NULL, "Gateway username" },
78 { "gp", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL, "Gateway password" },
79 { "gd", COMMAND_LINE_VALUE_REQUIRED, "<domain>", NULL, NULL, -1, NULL, "Gateway domain" },
80 { "gateway-usage-method", COMMAND_LINE_VALUE_REQUIRED, "<direct|detect>", NULL, NULL, -1, NULL, "Gateway usage method" },
81 { "load-balance-info", COMMAND_LINE_VALUE_REQUIRED, "<info string>", NULL, NULL, -1, NULL, "Load balance info" },
82 { "app", COMMAND_LINE_VALUE_REQUIRED, "<executable path> or <||alias>", NULL, NULL, -1, NULL, "Remote application program" },
83 { "app-name", COMMAND_LINE_VALUE_REQUIRED, "<app name>", NULL, NULL, -1, NULL, "Remote application name for user interface" },
84 { "app-icon", COMMAND_LINE_VALUE_REQUIRED, "<icon path>", NULL, NULL, -1, NULL, "Remote application icon for user interface" },
85 { "app-cmd", COMMAND_LINE_VALUE_REQUIRED, "<parameters>", NULL, NULL, -1, NULL, "Remote application command-line parameters" },
86 { "app-file", COMMAND_LINE_VALUE_REQUIRED, "<file name>", NULL, NULL, -1, NULL, "File to open with remote application" },
87 { "app-guid", COMMAND_LINE_VALUE_REQUIRED, "<app guid>", NULL, NULL, -1, NULL, "Remote application GUID" },
88 { "compression", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, "z", "Compression" },
89 { "compression-level", COMMAND_LINE_VALUE_REQUIRED, "<level>", NULL, NULL, -1, NULL, "Compression level (0,1,2)" },
90 { "shell", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Alternate shell" },
91 { "shell-dir", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Shell working directory" },
92 { "sound", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, "audio", "Audio output (sound)" },
93 { "microphone", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, "mic", "Audio input (microphone)" },
94 { "audio-mode", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Audio output mode" },
95 { "multimedia", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, "mmr", "Redirect multimedia (video)" },
96 { "network", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Network connection type" },
97 { "drive", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Redirect drive" },
98 { "drives", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Redirect all drives" },
99 { "home-drive", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Redirect home drive" },
100 { "clipboard", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Redirect clipboard" },
101 { "serial", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, "tty", "Redirect serial device" },
102 { "parallel", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "Redirect parallel device" },
103 { "smartcard", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "Redirect smartcard device" },
104 { "printer", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "Redirect printer device" },
105 { "usb", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Redirect USB device" },
106 { "multitouch", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Redirect multitouch input" },
107 { "gestures", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Consume multitouch input locally" },
108 { "echo", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "echo", "Echo channel" },
109 { "disp", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Display control" },
110 { "fonts", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Smooth fonts (ClearType)" },
111 { "aero", COMMAND_LINE_VALUE_BOOL, NULL, NULL, BoolValueFalse, -1, NULL, "Desktop composition" },
112 { "window-drag", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Full window drag" },
113 { "menu-anims", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Menu animations" },
114 { "themes", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "Themes" },
115 { "wallpaper", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "Wallpaper" },
116 { "gdi", COMMAND_LINE_VALUE_REQUIRED, "<sw|hw>", NULL, NULL, -1, NULL, "GDI rendering" },
117 { "gfx", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "RDP8 graphics pipeline (experimental)" },
118 { "gfx-thin-client", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "RDP8 graphics pipeline thin client mode" },
119 { "gfx-small-cache", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "RDP8 graphics pipeline small cache mode" },
120 { "gfx-progressive", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "RDP8 graphics pipeline progressive codec" },
121 { "gfx-h264", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "RDP8.1 graphics pipeline H264 codec" },
122 { "rfx", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "RemoteFX" },
123 { "rfx-mode", COMMAND_LINE_VALUE_REQUIRED, "<image|video>", NULL, NULL, -1, NULL, "RemoteFX mode" },
124 { "frame-ack", COMMAND_LINE_VALUE_REQUIRED, "<number>", NULL, NULL, -1, NULL, "Frame acknowledgement" },
125 { "nsc", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "nscodec", "NSCodec" },
126 { "jpeg", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "JPEG codec" },
127 { "jpeg-quality", COMMAND_LINE_VALUE_REQUIRED, "<percentage>", NULL, NULL, -1, NULL, "JPEG quality" },
128 { "nego", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "protocol security negotiation" },
129 { "sec", COMMAND_LINE_VALUE_REQUIRED, "<rdp|tls|nla|ext>", NULL, NULL, -1, NULL, "force specific protocol security" },
130 { "sec-rdp", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "rdp protocol security" },
131 { "sec-tls", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "tls protocol security" },
132 { "sec-nla", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "nla protocol security" },
133 { "sec-ext", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "nla extended protocol security" },
134 { "tls-ciphers", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "List of permitted openssl ciphers - see ciphers(1)" },
135 { "tls-ciphers-netmon", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Use tls ciphers that netmon can parse" },
136 { "cert-name", COMMAND_LINE_VALUE_REQUIRED, "<name>", NULL, NULL, -1, NULL, "certificate name" },
137 { "cert-ignore", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "ignore certificate" },
138 { "pcb", COMMAND_LINE_VALUE_REQUIRED, "<blob>", NULL, NULL, -1, NULL, "Preconnection Blob" },
139 { "pcid", COMMAND_LINE_VALUE_REQUIRED, "<id>", NULL, NULL, -1, NULL, "Preconnection Id" },
140 { "spn-class", COMMAND_LINE_VALUE_REQUIRED, "<service class>", NULL, NULL, -1, NULL, "SPN authentication service class" },
141 { "credentials-delegation", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Disable credentials delegation" },
142 { "vmconnect", COMMAND_LINE_VALUE_OPTIONAL, "<vmid>", NULL, NULL, -1, NULL, "Hyper-V console (use port 2179, disable negotiation)" },
143 { "authentication", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "authentication (hack!)" },
144 { "encryption", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "encryption (hack!)" },
145 { "grab-keyboard", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "grab keyboard" },
146 { "toggle-fullscreen", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "Alt+Ctrl+Enter toggles fullscreen" },
147 { "mouse-motion", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "mouse-motion" },
148 { "parent-window", COMMAND_LINE_VALUE_REQUIRED, "<window id>", NULL, NULL, -1, NULL, "Parent window id" },
149 { "bitmap-cache", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "bitmap cache" },
150 { "offscreen-cache", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "offscreen bitmap cache" },
151 { "glyph-cache", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "glyph cache" },
152 { "codec-cache", COMMAND_LINE_VALUE_REQUIRED, "<rfx|nsc|jpeg>", NULL, NULL, -1, NULL, "bitmap codec cache" },
153 { "fast-path", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "fast-path input/output" },
154 { "max-fast-path-size", COMMAND_LINE_VALUE_OPTIONAL, "<size>", NULL, NULL, -1, NULL, "maximum fast-path update size" },
155 { "async-input", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous input" },
156 { "async-update", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous update" },
157 { "async-transport", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous transport (unstable)" },
158 { "async-channels", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous channels (unstable)" },
159 { "wm-class", COMMAND_LINE_VALUE_REQUIRED, "<class name>", NULL, NULL, -1, NULL, "set the WM_CLASS hint for the window instance" },
160 { "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1, NULL, "print version" },
161 { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?", "print help" },
162 { "play-rfx", COMMAND_LINE_VALUE_REQUIRED, "<pcap file>", NULL, NULL, -1, NULL, "Replay rfx pcap file" },
163 { "auth-only", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Authenticate only." },
164 { "auto-reconnect", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Automatic reconnection" },
165 { "reconnect-cookie", COMMAND_LINE_VALUE_REQUIRED, "<base64 cookie>", NULL, NULL, -1, NULL, "Pass base64 reconnect cookie to the connection" },
166 { "print-reconnect-cookie", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Print base64 reconnect cookie after connecting" },
167 { "heartbeat", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Support heartbeat PDUs" },
168 { "multitransport", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Support multitransport protocol" },
169 { "assistance", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL, "Remote assistance password" },
170 { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
173 int freerdp_client_print_version()
175 printf("This is FreeRDP version %s (git %s)\n", FREERDP_VERSION_FULL, GIT_REVISION);
179 int freerdp_client_print_command_line_help(int argc, char** argv)
183 COMMAND_LINE_ARGUMENT_A* arg;
186 printf("FreeRDP - A Free Remote Desktop Protocol Implementation\n");
187 printf("See www.freerdp.com for more information\n");
190 printf("Usage: %s [file] [options] [/v:<server>[:port]]\n", argv[0]);
194 printf(" /flag (enables flag)\n");
195 printf(" /option:<value> (specifies option with value)\n");
196 printf(" +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')\n");
203 if (arg->Flags & COMMAND_LINE_VALUE_FLAG)
206 printf("%-20s", arg->Name);
207 printf("\t%s\n", arg->Text);
209 else if ((arg->Flags & COMMAND_LINE_VALUE_REQUIRED) || (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL))
215 length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2);
216 str = (char*) malloc(length + 1);
217 sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format);
218 printf("%-20s", str);
223 printf("%-20s", arg->Name);
226 printf("\t%s\n", arg->Text);
228 else if (arg->Flags & COMMAND_LINE_VALUE_BOOL)
230 length = (int) strlen(arg->Name) + 32;
231 str = (char*) malloc(length + 1);
232 sprintf_s(str, length + 1, "%s (default:%s)", arg->Name,
233 arg->Default ? "on" : "off");
235 printf(" %s", arg->Default ? "-" : "+");
237 printf("%-20s", str);
240 printf("\t%s\n", arg->Text);
243 while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
247 printf("Examples:\n");
248 printf(" xfreerdp connection.rdp /p:Pwd123! /f\n");
249 printf(" xfreerdp /u:CONTOSO\\JohnDoe /p:Pwd123! /v:rdp.contoso.com\n");
250 printf(" xfreerdp /u:JohnDoe /p:Pwd123! /w:1366 /h:768 /v:192.168.1.100:4489\n");
251 printf(" xfreerdp /u:JohnDoe /p:Pwd123! /vmconnect:C824F53E-95D2-46C6-9A18-23A5BB403532 /v:192.168.1.100\n");
254 printf("Clipboard Redirection: +clipboard\n");
257 printf("Drive Redirection: /drive:home,/home/user\n");
258 printf("Smartcard Redirection: /smartcard:<device>\n");
259 printf("Serial Port Redirection: /serial:<name>,<device>,[SerCx2|SerCx|Serial],[permissive]\n");
260 printf("Serial Port Redirection: /serial:COM1,/dev/ttyS0\n");
261 printf("Parallel Port Redirection: /parallel:<device>\n");
262 printf("Printer Redirection: /printer:<device>,<driver>\n");
265 printf("Audio Output Redirection: /sound:sys:alsa\n");
266 printf("Audio Input Redirection: /microphone:sys:alsa\n");
269 printf("Multimedia Redirection: /multimedia:sys:alsa\n");
270 printf("USB Device Redirection: /usb:id,dev:054c:0268\n");
273 printf("More documentation is coming, in the meantime consult source files\n");
279 int freerdp_client_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv)
284 rdpSettings* settings;
286 length = (int) strlen(argv[index]);
290 if (_stricmp(&(argv[index])[length - 4], ".rdp") == 0)
292 settings = (rdpSettings*) context;
293 settings->ConnectionFile = _strdup(argv[index]);
301 if (_stricmp(&(argv[index])[length - 13], ".msrcIncident") == 0)
303 settings = (rdpSettings*) context;
304 settings->AssistanceFile = _strdup(argv[index]);
314 int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params)
316 if (strcmp(params[0], "drive") == 0)
323 settings->DeviceRedirection = TRUE;
325 drive = (RDPDR_DRIVE*) calloc(1, sizeof(RDPDR_DRIVE));
330 drive->Type = RDPDR_DTYP_FILESYSTEM;
333 drive->Name = _strdup(params[1]);
336 drive->Path = _strdup(params[2]);
338 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) drive);
342 else if (strcmp(params[0], "printer") == 0)
344 RDPDR_PRINTER* printer;
349 settings->RedirectPrinters = TRUE;
350 settings->DeviceRedirection = TRUE;
354 printer = (RDPDR_PRINTER*) calloc(1, sizeof(RDPDR_PRINTER));
359 printer->Type = RDPDR_DTYP_PRINT;
362 printer->Name = _strdup(params[1]);
365 printer->DriverName = _strdup(params[2]);
367 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer);
372 else if (strcmp(params[0], "smartcard") == 0)
374 RDPDR_SMARTCARD* smartcard;
379 settings->RedirectSmartCards = TRUE;
380 settings->DeviceRedirection = TRUE;
384 smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD));
389 smartcard->Type = RDPDR_DTYP_SMARTCARD;
392 smartcard->Name = _strdup(params[1]);
395 smartcard->Path = _strdup(params[2]);
397 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard);
402 else if (strcmp(params[0], "serial") == 0)
404 RDPDR_SERIAL* serial;
409 settings->RedirectSerialPorts = TRUE;
410 settings->DeviceRedirection = TRUE;
412 serial = (RDPDR_SERIAL*) calloc(1, sizeof(RDPDR_SERIAL));
417 serial->Type = RDPDR_DTYP_SERIAL;
420 serial->Name = _strdup(params[1]);
423 serial->Path = _strdup(params[2]);
426 serial->Driver = _strdup(params[3]);
429 serial->Permissive = _strdup(params[4]);
431 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) serial);
435 else if (strcmp(params[0], "parallel") == 0)
437 RDPDR_PARALLEL* parallel;
442 settings->RedirectParallelPorts = TRUE;
443 settings->DeviceRedirection = TRUE;
445 parallel = (RDPDR_PARALLEL*) calloc(1, sizeof(RDPDR_PARALLEL));
450 parallel->Type = RDPDR_DTYP_PARALLEL;
453 parallel->Name = _strdup(params[1]);
456 parallel->Path = _strdup(params[2]);
458 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) parallel);
466 int freerdp_client_add_static_channel(rdpSettings* settings, int count, char** params)
471 args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV));
474 args->argv = (char**) malloc(sizeof(char*) * args->argc);
476 for (index = 0; index < args->argc; index++)
477 args->argv[index] = _strdup(params[index]);
479 freerdp_static_channel_collection_add(settings, args);
484 int freerdp_client_add_dynamic_channel(rdpSettings* settings, int count, char** params)
489 args = (ADDIN_ARGV*) malloc(sizeof(ADDIN_ARGV));
492 args->argv = (char**) malloc(sizeof(char*) * args->argc);
494 for (index = 0; index < args->argc; index++)
495 args->argv[index] = _strdup(params[index]);
497 freerdp_dynamic_channel_collection_add(settings, args);
502 static char** freerdp_command_line_parse_comma_separated_values(char* list, int* count)
512 assert(NULL != count);
518 for (index = 0; list[index]; index++)
519 nCommas += (list[index] == ',') ? 1 : 0;
522 p = (char**) malloc(sizeof(char*) * (nArgs + 1));
523 ZeroMemory(p, sizeof(char*) * (nArgs + 1));
529 for (index = 1; index < nArgs; index++)
531 p[index] = strchr(p[index - 1], ',');
536 p[index] = str + strlen(str);
543 static char** freerdp_command_line_parse_comma_separated_values_offset(char* list, int* count)
547 p = freerdp_command_line_parse_comma_separated_values(list, count);
549 p = (char**) realloc(p, sizeof(char*) * (*count + 1));
550 MoveMemory(&p[1], p, sizeof(char*) * *count);
556 int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg)
558 rdpSettings* settings = (rdpSettings*) context;
560 CommandLineSwitchStart(arg)
562 CommandLineSwitchCase(arg, "a")
567 p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
569 if (freerdp_client_add_device_channel(settings, count, p) > 0)
571 settings->DeviceRedirection = TRUE;
576 CommandLineSwitchCase(arg, "vc")
581 p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
583 freerdp_client_add_static_channel(settings, count, p);
587 CommandLineSwitchCase(arg, "dvc")
592 p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
594 freerdp_client_add_dynamic_channel(settings, count, p);
598 CommandLineSwitchCase(arg, "drive")
603 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
606 freerdp_client_add_device_channel(settings, count, p);
610 CommandLineSwitchCase(arg, "serial")
615 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
618 freerdp_client_add_device_channel(settings, count, p);
622 CommandLineSwitchCase(arg, "parallel")
627 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
630 freerdp_client_add_device_channel(settings, count, p);
634 CommandLineSwitchCase(arg, "smartcard")
639 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
642 freerdp_client_add_device_channel(settings, count, p);
646 CommandLineSwitchCase(arg, "printer")
648 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
653 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
656 freerdp_client_add_device_channel(settings, count, p);
668 freerdp_client_add_device_channel(settings, count, p);
671 CommandLineSwitchCase(arg, "usb")
676 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
679 freerdp_client_add_dynamic_channel(settings, count, p);
683 CommandLineSwitchCase(arg, "multitouch")
685 settings->MultiTouchInput = TRUE;
687 CommandLineSwitchCase(arg, "gestures")
689 settings->MultiTouchGestures = TRUE;
691 CommandLineSwitchCase(arg, "echo")
693 settings->SupportEchoChannel = TRUE;
695 CommandLineSwitchCase(arg, "disp")
697 settings->SupportDisplayControl = TRUE;
699 CommandLineSwitchCase(arg, "sound")
701 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
706 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
709 freerdp_client_add_static_channel(settings, count, p);
721 freerdp_client_add_static_channel(settings, count, p);
724 CommandLineSwitchCase(arg, "microphone")
726 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
731 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
734 freerdp_client_add_dynamic_channel(settings, count, p);
746 freerdp_client_add_dynamic_channel(settings, count, p);
749 CommandLineSwitchCase(arg, "multimedia")
751 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
756 p = freerdp_command_line_parse_comma_separated_values_offset(arg->Value, &count);
759 freerdp_client_add_dynamic_channel(settings, count, p);
771 freerdp_client_add_dynamic_channel(settings, count, p);
774 CommandLineSwitchCase(arg, "heartbeat")
776 settings->SupportHeartbeatPdu = TRUE;
778 CommandLineSwitchCase(arg, "multitransport")
780 settings->SupportMultitransport = TRUE;
781 settings->MultitransportFlags = (TRANSPORT_TYPE_UDP_FECR | TRANSPORT_TYPE_UDP_FECL | TRANSPORT_TYPE_UDP_PREFERRED);
784 CommandLineSwitchEnd(arg)
789 int freerdp_parse_username(char* username, char** user, char** domain)
794 p = strchr(username, '\\');
798 length = (int) (p - username);
799 *domain = (char*) malloc(length + 1);
800 strncpy(*domain, username, length);
801 (*domain)[length] = '\0';
802 *user = _strdup(&p[1]);
806 /* Do not break up the name for '@'; both credSSP and the
807 * ClientInfo PDU expect 'user@corp.net' to be transmitted
808 * as username 'user@corp.net', domain empty.
810 *user = _strdup(username);
817 int freerdp_parse_hostname(char* hostname, char** host, int* port)
822 p = strrchr(hostname, ':');
826 length = (p - hostname);
827 *host = (char*) malloc(length + 1);
832 CopyMemory(*host, hostname, length);
833 (*host)[length] = '\0';
838 *host = _strdup(hostname);
849 int freerdp_set_connection_type(rdpSettings* settings, int type)
851 settings->ConnectionType = type;
853 if (type == CONNECTION_TYPE_MODEM)
855 settings->DisableWallpaper = TRUE;
856 settings->AllowFontSmoothing = FALSE;
857 settings->AllowDesktopComposition = FALSE;
858 settings->DisableFullWindowDrag = TRUE;
859 settings->DisableMenuAnims = TRUE;
860 settings->DisableThemes = TRUE;
862 else if (type == CONNECTION_TYPE_BROADBAND_LOW)
864 settings->DisableWallpaper = TRUE;
865 settings->AllowFontSmoothing = FALSE;
866 settings->AllowDesktopComposition = FALSE;
867 settings->DisableFullWindowDrag = TRUE;
868 settings->DisableMenuAnims = TRUE;
869 settings->DisableThemes = FALSE;
871 else if (type == CONNECTION_TYPE_SATELLITE)
873 settings->DisableWallpaper = TRUE;
874 settings->AllowFontSmoothing = FALSE;
875 settings->AllowDesktopComposition = TRUE;
876 settings->DisableFullWindowDrag = TRUE;
877 settings->DisableMenuAnims = TRUE;
878 settings->DisableThemes = FALSE;
880 else if (type == CONNECTION_TYPE_BROADBAND_HIGH)
882 settings->DisableWallpaper = TRUE;
883 settings->AllowFontSmoothing = FALSE;
884 settings->AllowDesktopComposition = TRUE;
885 settings->DisableFullWindowDrag = TRUE;
886 settings->DisableMenuAnims = TRUE;
887 settings->DisableThemes = FALSE;
889 else if (type == CONNECTION_TYPE_WAN)
891 settings->DisableWallpaper = FALSE;
892 settings->AllowFontSmoothing = TRUE;
893 settings->AllowDesktopComposition = TRUE;
894 settings->DisableFullWindowDrag = FALSE;
895 settings->DisableMenuAnims = FALSE;
896 settings->DisableThemes = FALSE;
898 else if (type == CONNECTION_TYPE_LAN)
900 settings->DisableWallpaper = FALSE;
901 settings->AllowFontSmoothing = TRUE;
902 settings->AllowDesktopComposition = TRUE;
903 settings->DisableFullWindowDrag = FALSE;
904 settings->DisableMenuAnims = FALSE;
905 settings->DisableThemes = FALSE;
907 else if (type == CONNECTION_TYPE_AUTODETECT)
909 settings->DisableWallpaper = FALSE;
910 settings->AllowFontSmoothing = TRUE;
911 settings->AllowDesktopComposition = TRUE;
912 settings->DisableFullWindowDrag = FALSE;
913 settings->DisableMenuAnims = FALSE;
914 settings->DisableThemes = FALSE;
916 settings->NetworkAutoDetect = TRUE;
922 int freerdp_map_keyboard_layout_name_to_id(char* name)
926 RDP_KEYBOARD_LAYOUT* layouts;
928 layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD);
929 for (i = 0; layouts[i].code; i++)
931 if (_stricmp(layouts[i].name, name) == 0)
932 id = layouts[i].code;
939 layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
940 for (i = 0; layouts[i].code; i++)
942 if (_stricmp(layouts[i].name, name) == 0)
943 id = layouts[i].code;
950 layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
951 for (i = 0; layouts[i].code; i++)
953 if (_stricmp(layouts[i].name, name) == 0)
954 id = layouts[i].code;
964 int freerdp_detect_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv)
970 length = (int) strlen(argv[index]);
974 if (_stricmp(&(argv[index])[length - 4], ".rdp") == 0)
984 int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, int* count)
989 COMMAND_LINE_ARGUMENT_A* arg;
991 flags = COMMAND_LINE_SEPARATOR_COLON;
992 flags |= COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SIGIL_PLUS_MINUS;
996 CommandLineClearArgumentsA(args);
998 status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags,
999 NULL, freerdp_detect_command_line_pre_filter, NULL);
1008 if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
1013 while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
1015 if ((status <= COMMAND_LINE_ERROR) && (status >= COMMAND_LINE_ERROR_LAST))
1018 return detect_status;
1021 int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, int* count)
1026 COMMAND_LINE_ARGUMENT_A* arg;
1028 flags = COMMAND_LINE_SEPARATOR_SPACE;
1029 flags |= COMMAND_LINE_SIGIL_DASH | COMMAND_LINE_SIGIL_DOUBLE_DASH;
1030 flags |= COMMAND_LINE_SIGIL_ENABLE_DISABLE;
1034 CommandLineClearArgumentsA(args);
1036 status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags,
1037 NULL, freerdp_detect_command_line_pre_filter, NULL);
1046 if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
1051 while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
1053 if ((status <= COMMAND_LINE_ERROR) && (status >= COMMAND_LINE_ERROR_LAST))
1056 return detect_status;
1059 BOOL freerdp_client_detect_command_line(int argc, char** argv, DWORD* flags)
1063 int posix_cli_status;
1064 int posix_cli_count;
1065 int windows_cli_status;
1066 int windows_cli_count;
1067 BOOL compatibility = FALSE;
1069 windows_cli_status = freerdp_detect_windows_style_command_line_syntax(argc, argv, &windows_cli_count);
1070 posix_cli_status = freerdp_detect_posix_style_command_line_syntax(argc, argv, &posix_cli_count);
1071 old_cli_status = freerdp_detect_old_command_line_syntax(argc, argv, &old_cli_count);
1073 /* Default is POSIX syntax */
1074 *flags = COMMAND_LINE_SEPARATOR_SPACE;
1075 *flags |= COMMAND_LINE_SIGIL_DASH | COMMAND_LINE_SIGIL_DOUBLE_DASH;
1076 *flags |= COMMAND_LINE_SIGIL_ENABLE_DISABLE;
1078 if (posix_cli_status <= COMMAND_LINE_STATUS_PRINT)
1079 return compatibility;
1081 if (windows_cli_count >= posix_cli_count)
1083 *flags = COMMAND_LINE_SEPARATOR_COLON;
1084 *flags |= COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SIGIL_PLUS_MINUS;
1086 else if (old_cli_status >= 0)
1088 /* Ignore legacy parsing in case there is an error in the command line. */
1090 if ((old_cli_status == 1) || ((old_cli_count > posix_cli_count) && (old_cli_status != -1)))
1092 *flags = COMMAND_LINE_SEPARATOR_SPACE;
1093 *flags |= COMMAND_LINE_SIGIL_DASH | COMMAND_LINE_SIGIL_DOUBLE_DASH;
1095 compatibility = TRUE;
1099 WLog_DBG(TAG, "windows: %d/%d posix: %d/%d compat: %d/%d", windows_cli_status, windows_cli_count,
1100 posix_cli_status, posix_cli_count, old_cli_status, old_cli_count);
1102 return compatibility;
1105 int freerdp_client_settings_command_line_status_print(rdpSettings* settings, int status, int argc, char** argv)
1107 COMMAND_LINE_ARGUMENT_A* arg;
1109 if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
1111 freerdp_client_print_version();
1112 return COMMAND_LINE_STATUS_PRINT_VERSION;
1114 else if (status == COMMAND_LINE_STATUS_PRINT)
1116 arg = CommandLineFindArgumentA(args, "kbd-list");
1118 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
1121 RDP_KEYBOARD_LAYOUT* layouts;
1123 layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD);
1124 printf("\nKeyboard Layouts\n");
1125 for (i = 0; layouts[i].code; i++)
1126 printf("0x%08X\t%s\n", (int) layouts[i].code, layouts[i].name);
1129 layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
1130 printf("\nKeyboard Layout Variants\n");
1131 for (i = 0; layouts[i].code; i++)
1132 printf("0x%08X\t%s\n", (int) layouts[i].code, layouts[i].name);
1135 layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
1136 printf("\nKeyboard Input Method Editors (IMEs)\n");
1137 for (i = 0; layouts[i].code; i++)
1138 printf("0x%08X\t%s\n", (int) layouts[i].code, layouts[i].name);
1144 arg = CommandLineFindArgumentA(args, "monitor-list");
1146 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
1148 settings->ListMonitors = TRUE;
1151 return COMMAND_LINE_STATUS_PRINT;
1153 else if (status < 0)
1155 freerdp_client_print_command_line_help(argc, argv);
1156 return COMMAND_LINE_STATUS_PRINT_HELP;
1162 int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, int argc, char** argv)
1170 COMMAND_LINE_ARGUMENT_A* arg;
1172 compatibility = freerdp_client_detect_command_line(argc, argv, &flags);
1176 WLog_WARN(TAG, "Using deprecated command-line interface!");
1177 return freerdp_client_parse_old_command_line_arguments(argc, argv, settings);
1181 CommandLineClearArgumentsA(args);
1183 status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, settings,
1184 freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter);
1190 arg = CommandLineFindArgumentA(args, "v");
1196 if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
1199 CommandLineSwitchStart(arg)
1201 CommandLineSwitchCase(arg, "v")
1203 p = strchr(arg->Value, '[');
1207 p = strchr(arg->Value, ':');
1210 length = (int) (p - arg->Value);
1211 settings->ServerPort = atoi(&p[1]);
1212 settings->ServerHostname = (char*) malloc(length + 1);
1213 strncpy(settings->ServerHostname, arg->Value, length);
1214 settings->ServerHostname[length] = '\0';
1218 settings->ServerHostname = _strdup(arg->Value);
1223 char *p2 = strchr(arg->Value, ']');
1224 /* not a valid [] ipv6 addr found */
1229 settings->ServerHostname = (char*) malloc(length);
1230 strncpy(settings->ServerHostname, p+1, length-1);
1231 if (*(p2 + 1) == ':')
1233 settings->ServerPort = atoi(&p2[2]);
1235 printf("hostname %s port %d\n", settings->ServerHostname, settings->ServerPort);
1238 CommandLineSwitchCase(arg, "spn-class")
1240 settings->AuthenticationServiceClass = _strdup(arg->Value);
1242 CommandLineSwitchCase(arg, "credentials-delegation")
1244 settings->DisableCredentialsDelegation = arg->Value ? FALSE : TRUE;
1246 CommandLineSwitchCase(arg, "vmconnect")
1248 settings->ServerPort = 2179;
1249 settings->NegotiateSecurityLayer = FALSE;
1251 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
1253 settings->SendPreconnectionPdu = TRUE;
1254 settings->PreconnectionBlob = _strdup(arg->Value);
1257 CommandLineSwitchCase(arg, "w")
1259 settings->DesktopWidth = atoi(arg->Value);
1261 CommandLineSwitchCase(arg, "h")
1263 settings->DesktopHeight = atoi(arg->Value);
1265 CommandLineSwitchCase(arg, "size")
1267 str = _strdup(arg->Value);
1269 p = strchr(str, 'x');
1274 settings->DesktopWidth = atoi(str);
1275 settings->DesktopHeight = atoi(&p[1]);
1279 p = strchr(str, '%');
1282 settings->PercentScreen = atoi(str);
1288 CommandLineSwitchCase(arg, "f")
1290 settings->Fullscreen = TRUE;
1292 CommandLineSwitchCase(arg, "multimon")
1294 settings->UseMultimon = TRUE;
1296 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
1298 if (_stricmp(arg->Value, "force") == 0)
1300 settings->ForceMultimon = TRUE;
1304 CommandLineSwitchCase(arg, "span")
1306 settings->SpanMonitors = TRUE;
1308 CommandLineSwitchCase(arg, "workarea")
1310 settings->Workarea = TRUE;
1312 CommandLineSwitchCase(arg, "monitors")
1314 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
1320 p = freerdp_command_line_parse_comma_separated_values(arg->Value, &count);
1322 settings->NumMonitorIds = (UINT32) count;
1323 settings->MonitorIds = (UINT32*) malloc(sizeof(UINT32) * settings->NumMonitorIds);
1325 for (i = 0; i < settings->NumMonitorIds; i++)
1327 settings->MonitorIds[i] = atoi(p[i]);
1333 CommandLineSwitchCase(arg, "monitor-list")
1335 settings->ListMonitors = TRUE;
1337 CommandLineSwitchCase(arg, "t")
1339 settings->WindowTitle = _strdup(arg->Value);
1341 CommandLineSwitchCase(arg, "decorations")
1343 settings->Decorations = arg->Value ? TRUE : FALSE;
1345 CommandLineSwitchCase(arg, "smart-sizing")
1347 settings->SmartSizing = arg->Value ? TRUE : FALSE;
1349 CommandLineSwitchCase(arg, "bpp")
1351 settings->ColorDepth = atoi(arg->Value);
1353 CommandLineSwitchCase(arg, "admin")
1355 settings->ConsoleSession = TRUE;
1357 CommandLineSwitchCase(arg, "restricted-admin")
1359 settings->ConsoleSession = TRUE;
1360 settings->RestrictedAdminModeRequired = TRUE;
1362 CommandLineSwitchCase(arg, "pth")
1364 settings->ConsoleSession = TRUE;
1365 settings->RestrictedAdminModeRequired = TRUE;
1366 settings->PasswordHash = _strdup(arg->Value);
1368 CommandLineSwitchCase(arg, "client-hostname")
1370 settings->ClientHostname = _strdup(arg->Value);
1372 CommandLineSwitchCase(arg, "kbd")
1374 unsigned long int id;
1377 id = strtoul(arg->Value, &pEnd, 16);
1379 if (pEnd != (arg->Value + strlen(arg->Value)))
1384 id = (unsigned long int) freerdp_map_keyboard_layout_name_to_id(arg->Value);
1388 WLog_ERR(TAG, "Could not identify keyboard layout: %s", arg->Value);
1392 settings->KeyboardLayout = (UINT32) id;
1394 CommandLineSwitchCase(arg, "kbd-type")
1396 settings->KeyboardType = atoi(arg->Value);
1398 CommandLineSwitchCase(arg, "kbd-subtype")
1400 settings->KeyboardSubType = atoi(arg->Value);
1402 CommandLineSwitchCase(arg, "kbd-fn-key")
1404 settings->KeyboardFunctionKey = atoi(arg->Value);
1406 CommandLineSwitchCase(arg, "u")
1411 freerdp_parse_username(arg->Value, &user, &domain);
1413 settings->Username = user;
1414 settings->Domain = domain;
1416 CommandLineSwitchCase(arg, "d")
1418 settings->Domain = _strdup(arg->Value);
1420 CommandLineSwitchCase(arg, "p")
1422 settings->Password = _strdup(arg->Value);
1424 CommandLineSwitchCase(arg, "g")
1426 if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
1428 p = strchr(arg->Value, ':');
1432 length = (int) (p - arg->Value);
1433 settings->GatewayPort = atoi(&p[1]);
1434 settings->GatewayHostname = (char*) malloc(length + 1);
1435 strncpy(settings->GatewayHostname, arg->Value, length);
1436 settings->GatewayHostname[length] = '\0';
1440 settings->GatewayHostname = _strdup(arg->Value);
1445 settings->GatewayHostname = _strdup(settings->ServerHostname);
1448 settings->GatewayEnabled = TRUE;
1449 settings->GatewayUseSameCredentials = TRUE;
1451 freerdp_set_gateway_usage_method(settings, TSC_PROXY_MODE_DETECT);
1453 CommandLineSwitchCase(arg, "gu")
1458 freerdp_parse_username(arg->Value, &user, &domain);
1460 settings->GatewayUsername = user;
1461 settings->GatewayDomain = domain;
1463 settings->GatewayUseSameCredentials = FALSE;
1465 CommandLineSwitchCase(arg, "gd")
1467 settings->GatewayDomain = _strdup(arg->Value);
1468 settings->GatewayUseSameCredentials = FALSE;
1470 CommandLineSwitchCase(arg, "gp")
1472 settings->GatewayPassword = _strdup(arg->Value);
1473 settings->GatewayUseSameCredentials = FALSE;
1475 CommandLineSwitchCase(arg, "gateway-usage-method")
1480 type = strtol(arg->Value, &pEnd, 10);
1484 if (_stricmp(arg->Value, "none") == 0)
1485 type = TSC_PROXY_MODE_NONE_DIRECT;
1486 else if (_stricmp(arg->Value, "direct") == 0)
1487 type = TSC_PROXY_MODE_DIRECT;
1488 else if (_stricmp(arg->Value, "detect") == 0)
1489 type = TSC_PROXY_MODE_DETECT;
1490 else if (_stricmp(arg->Value, "default") == 0)
1491 type = TSC_PROXY_MODE_DEFAULT;
1494 freerdp_set_gateway_usage_method(settings, (UINT32) type);
1496 CommandLineSwitchCase(arg, "app")
1498 settings->RemoteApplicationProgram = _strdup(arg->Value);
1500 settings->RemoteApplicationMode = TRUE;
1501 settings->RemoteAppLanguageBarSupported = TRUE;
1502 settings->Workarea = TRUE;
1503 settings->DisableWallpaper = TRUE;
1504 settings->DisableFullWindowDrag = TRUE;
1506 CommandLineSwitchCase(arg, "load-balance-info")
1508 settings->LoadBalanceInfo = (BYTE*) _strdup(arg->Value);
1509 settings->LoadBalanceInfoLength = (UINT32) strlen((char*) settings->LoadBalanceInfo);
1511 CommandLineSwitchCase(arg, "app-name")
1513 settings->RemoteApplicationName = _strdup(arg->Value);
1515 CommandLineSwitchCase(arg, "app-icon")
1517 settings->RemoteApplicationIcon = _strdup(arg->Value);
1519 CommandLineSwitchCase(arg, "app-cmd")
1521 settings->RemoteApplicationCmdLine = _strdup(arg->Value);
1523 CommandLineSwitchCase(arg, "app-file")
1525 settings->RemoteApplicationFile = _strdup(arg->Value);
1527 CommandLineSwitchCase(arg, "app-guid")
1529 settings->RemoteApplicationGuid = _strdup(arg->Value);
1531 CommandLineSwitchCase(arg, "compression")
1533 settings->CompressionEnabled = arg->Value ? TRUE : FALSE;
1535 CommandLineSwitchCase(arg, "compression-level")
1537 settings->CompressionLevel = atoi(arg->Value);
1539 CommandLineSwitchCase(arg, "drives")
1541 settings->RedirectDrives = arg->Value ? TRUE : FALSE;
1543 CommandLineSwitchCase(arg, "home-drive")
1545 settings->RedirectHomeDrive = arg->Value ? TRUE : FALSE;
1547 CommandLineSwitchCase(arg, "clipboard")
1549 settings->RedirectClipboard = arg->Value ? TRUE : FALSE;
1551 CommandLineSwitchCase(arg, "shell")
1553 settings->AlternateShell = _strdup(arg->Value);
1555 CommandLineSwitchCase(arg, "shell-dir")
1557 settings->ShellWorkingDirectory = _strdup(arg->Value);
1559 CommandLineSwitchCase(arg, "audio-mode")
1563 mode = atoi(arg->Value);
1565 if (mode == AUDIO_MODE_REDIRECT)
1567 settings->AudioPlayback = TRUE;
1569 else if (mode == AUDIO_MODE_PLAY_ON_SERVER)
1571 settings->RemoteConsoleAudio = TRUE;
1573 else if (mode == AUDIO_MODE_NONE)
1575 settings->AudioPlayback = FALSE;
1576 settings->RemoteConsoleAudio = FALSE;
1579 CommandLineSwitchCase(arg, "network")
1584 type = strtol(arg->Value, &pEnd, 10);
1588 if (_stricmp(arg->Value, "modem") == 0)
1589 type = CONNECTION_TYPE_MODEM;
1590 else if (_stricmp(arg->Value, "broadband") == 0)
1591 type = CONNECTION_TYPE_BROADBAND_HIGH;
1592 else if (_stricmp(arg->Value, "broadband-low") == 0)
1593 type = CONNECTION_TYPE_BROADBAND_LOW;
1594 else if (_stricmp(arg->Value, "broadband-high") == 0)
1595 type = CONNECTION_TYPE_BROADBAND_HIGH;
1596 else if (_stricmp(arg->Value, "wan") == 0)
1597 type = CONNECTION_TYPE_WAN;
1598 else if (_stricmp(arg->Value, "lan") == 0)
1599 type = CONNECTION_TYPE_LAN;
1600 else if ((_stricmp(arg->Value, "autodetect") == 0) ||
1601 (_stricmp(arg->Value, "auto") == 0) ||
1602 (_stricmp(arg->Value, "detect") == 0))
1604 type = CONNECTION_TYPE_AUTODETECT;
1608 freerdp_set_connection_type(settings, type);
1610 CommandLineSwitchCase(arg, "fonts")
1612 settings->AllowFontSmoothing = arg->Value ? TRUE : FALSE;
1614 CommandLineSwitchCase(arg, "wallpaper")
1616 settings->DisableWallpaper = arg->Value ? FALSE : TRUE;
1618 CommandLineSwitchCase(arg, "window-drag")
1620 settings->DisableFullWindowDrag = arg->Value ? FALSE : TRUE;
1622 CommandLineSwitchCase(arg, "menu-anims")
1624 settings->DisableMenuAnims = arg->Value ? FALSE : TRUE;
1626 CommandLineSwitchCase(arg, "themes")
1628 settings->DisableThemes = arg->Value ? FALSE : TRUE;
1630 CommandLineSwitchCase(arg, "aero")
1632 settings->AllowDesktopComposition = arg->Value ? TRUE : FALSE;
1634 CommandLineSwitchCase(arg, "gdi")
1636 if (_stricmp(arg->Value, "sw") == 0)
1637 settings->SoftwareGdi = TRUE;
1638 else if (_stricmp(arg->Value, "hw") == 0)
1639 settings->SoftwareGdi = FALSE;
1641 CommandLineSwitchCase(arg, "gfx")
1643 settings->SupportGraphicsPipeline = TRUE;
1645 CommandLineSwitchCase(arg, "gfx-thin-client")
1647 settings->GfxThinClient = arg->Value ? TRUE : FALSE;
1648 settings->SupportGraphicsPipeline = TRUE;
1650 CommandLineSwitchCase(arg, "gfx-small-cache")
1652 settings->GfxSmallCache = arg->Value ? TRUE : FALSE;
1653 settings->SupportGraphicsPipeline = TRUE;
1655 CommandLineSwitchCase(arg, "gfx-progressive")
1657 settings->GfxProgressive = arg->Value ? TRUE : FALSE;
1658 settings->GfxThinClient = settings->GfxProgressive ? FALSE : TRUE;
1659 settings->SupportGraphicsPipeline = TRUE;
1661 CommandLineSwitchCase(arg, "gfx-h264")
1663 settings->GfxH264 = arg->Value ? TRUE : FALSE;
1664 settings->SupportGraphicsPipeline = TRUE;
1666 CommandLineSwitchCase(arg, "rfx")
1668 settings->RemoteFxCodec = TRUE;
1669 settings->FastPathOutput = TRUE;
1670 settings->ColorDepth = 32;
1671 settings->LargePointerFlag = TRUE;
1672 settings->FrameMarkerCommandEnabled = TRUE;
1674 CommandLineSwitchCase(arg, "rfx-mode")
1676 if (strcmp(arg->Value, "video") == 0)
1677 settings->RemoteFxCodecMode = 0x00;
1678 else if (strcmp(arg->Value, "image") == 0)
1679 settings->RemoteFxCodecMode = 0x02;
1681 CommandLineSwitchCase(arg, "frame-ack")
1683 settings->FrameAcknowledge = atoi(arg->Value);
1685 CommandLineSwitchCase(arg, "nsc")
1687 settings->NSCodec = TRUE;
1688 settings->FastPathOutput = TRUE;
1689 settings->ColorDepth = 32;
1690 settings->LargePointerFlag = TRUE;
1691 settings->FrameMarkerCommandEnabled = TRUE;
1693 CommandLineSwitchCase(arg, "jpeg")
1695 settings->JpegCodec = TRUE;
1696 settings->JpegQuality = 75;
1698 CommandLineSwitchCase(arg, "jpeg-quality")
1700 settings->JpegQuality = atoi(arg->Value) % 100;
1702 CommandLineSwitchCase(arg, "nego")
1704 settings->NegotiateSecurityLayer = arg->Value ? TRUE : FALSE;
1706 CommandLineSwitchCase(arg, "pcb")
1708 settings->SendPreconnectionPdu = TRUE;
1709 settings->PreconnectionBlob = _strdup(arg->Value);
1711 CommandLineSwitchCase(arg, "pcid")
1713 settings->SendPreconnectionPdu = TRUE;
1714 settings->PreconnectionId = atoi(arg->Value);
1716 CommandLineSwitchCase(arg, "sec")
1718 if (strcmp("rdp", arg->Value) == 0) /* Standard RDP */
1720 settings->RdpSecurity = TRUE;
1721 settings->TlsSecurity = FALSE;
1722 settings->NlaSecurity = FALSE;
1723 settings->ExtSecurity = FALSE;
1724 settings->DisableEncryption = TRUE;
1725 settings->EncryptionMethods = ENCRYPTION_METHOD_40BIT | ENCRYPTION_METHOD_56BIT| ENCRYPTION_METHOD_128BIT | ENCRYPTION_METHOD_FIPS;
1726 settings->EncryptionLevel = ENCRYPTION_LEVEL_CLIENT_COMPATIBLE;
1728 else if (strcmp("tls", arg->Value) == 0) /* TLS */
1730 settings->RdpSecurity = FALSE;
1731 settings->TlsSecurity = TRUE;
1732 settings->NlaSecurity = FALSE;
1733 settings->ExtSecurity = FALSE;
1735 else if (strcmp("nla", arg->Value) == 0) /* NLA */
1737 settings->RdpSecurity = FALSE;
1738 settings->TlsSecurity = FALSE;
1739 settings->NlaSecurity = TRUE;
1740 settings->ExtSecurity = FALSE;
1742 else if (strcmp("ext", arg->Value) == 0) /* NLA Extended */
1744 settings->RdpSecurity = FALSE;
1745 settings->TlsSecurity = FALSE;
1746 settings->NlaSecurity = FALSE;
1747 settings->ExtSecurity = TRUE;
1751 WLog_ERR(TAG, "unknown protocol security: %s", arg->Value);
1754 CommandLineSwitchCase(arg, "sec-rdp")
1756 settings->RdpSecurity = arg->Value ? TRUE : FALSE;
1758 CommandLineSwitchCase(arg, "sec-tls")
1760 settings->TlsSecurity = arg->Value ? TRUE : FALSE;
1762 CommandLineSwitchCase(arg, "sec-nla")
1764 settings->NlaSecurity = arg->Value ? TRUE : FALSE;
1766 CommandLineSwitchCase(arg, "sec-ext")
1768 settings->ExtSecurity = arg->Value ? TRUE : FALSE;
1770 CommandLineSwitchCase(arg, "tls-ciphers")
1772 settings->PermittedTLSCiphers = _strdup(arg->Value);
1774 CommandLineSwitchCase(arg, "tls-ciphers-netmon")
1776 settings->PermittedTLSCiphers = arg->Value ? _strdup("ALL:!ECDH") : NULL;
1778 CommandLineSwitchCase(arg, "cert-name")
1780 settings->CertificateName = _strdup(arg->Value);
1782 CommandLineSwitchCase(arg, "cert-ignore")
1784 settings->IgnoreCertificate = TRUE;
1786 CommandLineSwitchCase(arg, "authentication")
1788 settings->Authentication = arg->Value ? TRUE : FALSE;
1790 CommandLineSwitchCase(arg, "encryption")
1792 settings->DisableEncryption = arg->Value ? FALSE : TRUE;
1794 CommandLineSwitchCase(arg, "grab-keyboard")
1796 settings->GrabKeyboard = arg->Value ? TRUE : FALSE;
1798 CommandLineSwitchCase(arg, "toggle-fullscreen")
1800 settings->ToggleFullscreen = arg->Value ? TRUE : FALSE;
1802 CommandLineSwitchCase(arg, "mouse-motion")
1804 settings->MouseMotion = arg->Value ? TRUE : FALSE;
1806 CommandLineSwitchCase(arg, "parent-window")
1808 settings->ParentWindowId = strtol(arg->Value, NULL, 0);
1810 CommandLineSwitchCase(arg, "bitmap-cache")
1812 settings->BitmapCacheEnabled = arg->Value ? TRUE : FALSE;
1814 CommandLineSwitchCase(arg, "offscreen-cache")
1816 settings->OffscreenSupportLevel = arg->Value ? TRUE : FALSE;
1818 CommandLineSwitchCase(arg, "glyph-cache")
1820 settings->GlyphSupportLevel = arg->Value ? GLYPH_SUPPORT_FULL : GLYPH_SUPPORT_NONE;
1822 CommandLineSwitchCase(arg, "codec-cache")
1824 settings->BitmapCacheV3Enabled = TRUE;
1826 if (strcmp(arg->Value, "rfx") == 0)
1828 settings->RemoteFxCodec = TRUE;
1830 else if (strcmp(arg->Value, "nsc") == 0)
1832 settings->NSCodec = TRUE;
1834 else if (strcmp(arg->Value, "jpeg") == 0)
1836 settings->JpegCodec = TRUE;
1838 if (settings->JpegQuality == 0)
1839 settings->JpegQuality = 75;
1842 CommandLineSwitchCase(arg, "fast-path")
1844 settings->FastPathInput = arg->Value ? TRUE : FALSE;
1845 settings->FastPathOutput = arg->Value ? TRUE : FALSE;
1847 CommandLineSwitchCase(arg, "max-fast-path-size")
1849 settings->MultifragMaxRequestSize = atoi(arg->Value);
1851 CommandLineSwitchCase(arg, "async-input")
1853 settings->AsyncInput = arg->Value ? TRUE : FALSE;
1855 CommandLineSwitchCase(arg, "async-update")
1857 settings->AsyncUpdate = arg->Value ? TRUE : FALSE;
1859 CommandLineSwitchCase(arg, "async-channels")
1861 settings->AsyncChannels = arg->Value ? TRUE : FALSE;
1863 CommandLineSwitchCase(arg, "async-transport")
1865 settings->AsyncTransport = arg->Value ? TRUE : FALSE;
1867 CommandLineSwitchCase(arg, "wm-class")
1869 settings->WmClass = _strdup(arg->Value);
1871 CommandLineSwitchCase(arg, "play-rfx")
1873 settings->PlayRemoteFxFile = _strdup(arg->Value);
1874 settings->PlayRemoteFx = TRUE;
1876 CommandLineSwitchCase(arg, "auth-only")
1878 settings->AuthenticationOnly = arg->Value ? TRUE : FALSE;
1880 CommandLineSwitchCase(arg, "auto-reconnect")
1882 settings->AutoReconnectionEnabled = arg->Value ? TRUE : FALSE;
1884 CommandLineSwitchCase(arg, "reconnect-cookie")
1888 crypto_base64_decode((const char *) (arg->Value), (int) strlen(arg->Value),
1890 if ((base64 != NULL) && (length == sizeof(ARC_SC_PRIVATE_PACKET)))
1892 memcpy(settings->ServerAutoReconnectCookie, base64, length);
1897 WLog_ERR(TAG, "reconnect-cookie: invalid base64 '%s'", arg->Value);
1900 CommandLineSwitchCase(arg, "print-reconnect-cookie")
1902 settings->PrintReconnectCookie = arg->Value ? TRUE : FALSE;
1904 CommandLineSwitchCase(arg, "assistance")
1906 settings->RemoteAssistanceMode = TRUE;
1907 settings->RemoteAssistancePassword = _strdup(arg->Value);
1909 CommandLineSwitchDefault(arg)
1913 CommandLineSwitchEnd(arg)
1915 while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
1917 freerdp_performance_flags_make(settings);
1919 if (settings->SupportGraphicsPipeline)
1921 settings->FastPathOutput = TRUE;
1922 settings->ColorDepth = 32;
1923 settings->LargePointerFlag = TRUE;
1924 settings->FrameMarkerCommandEnabled = TRUE;
1927 arg = CommandLineFindArgumentA(args, "port");
1929 if (arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT)
1931 settings->ServerPort = atoi(arg->Value);
1934 arg = CommandLineFindArgumentA(args, "p");
1936 if (arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT)
1938 FillMemory(arg->Value, strlen(arg->Value), '*');
1941 arg = CommandLineFindArgumentA(args, "gp");
1943 if (arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT)
1945 FillMemory(arg->Value, strlen(arg->Value), '*');
1951 int freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings, char* name, void* data)
1955 entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC);
1959 if (freerdp_channels_client_load(channels, settings, entry, data) == 0)
1961 WLog_INFO(TAG, "loading channel %s", name);
1969 int freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings)
1974 if ((freerdp_static_channel_collection_find(settings, "rdpsnd")) ||
1975 (freerdp_dynamic_channel_collection_find(settings, "tsmf")))
1977 settings->DeviceRedirection = TRUE; /* rdpsnd requires rdpdr to be registered */
1978 settings->AudioPlayback = TRUE; /* Both rdpsnd and tsmf require this flag to be set */
1981 if (freerdp_dynamic_channel_collection_find(settings, "audin"))
1983 settings->AudioCapture = TRUE;
1986 if (settings->NetworkAutoDetect ||
1987 settings->SupportHeartbeatPdu ||
1988 settings->SupportMultitransport)
1990 settings->DeviceRedirection = TRUE; /* these RDP8 features require rdpdr to be registered */
1993 if (settings->RedirectDrives || settings->RedirectHomeDrive || settings->RedirectSerialPorts
1994 || settings->RedirectSmartCards || settings->RedirectPrinters)
1996 settings->DeviceRedirection = TRUE; /* All of these features require rdpdr */
1999 if (settings->RedirectDrives)
2001 if (!freerdp_device_collection_find(settings, "drive"))
2005 params[0] = "drive";
2006 params[1] = "media";
2009 freerdp_client_add_device_channel(settings, 3, (char**) params);
2013 if (settings->RedirectHomeDrive)
2015 if (!freerdp_device_collection_find(settings, "drive"))
2019 params[0] = "drive";
2023 freerdp_client_add_device_channel(settings, 3, (char**) params);
2027 if (settings->DeviceRedirection)
2029 freerdp_client_load_static_channel_addin(channels, settings, "rdpdr", settings);
2031 if (!freerdp_static_channel_collection_find(settings, "rdpsnd"))
2035 params[0] = "rdpsnd";
2036 params[1] = "sys:fake";
2038 freerdp_client_add_static_channel(settings, 2, (char**) params);
2042 if (settings->RedirectSmartCards)
2044 RDPDR_SMARTCARD* smartcard;
2046 smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD));
2051 smartcard->Type = RDPDR_DTYP_SMARTCARD;
2052 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard);
2055 if (settings->RedirectPrinters)
2057 RDPDR_PRINTER* printer;
2059 printer = (RDPDR_PRINTER*) calloc(1, sizeof(RDPDR_PRINTER));
2064 printer->Type = RDPDR_DTYP_PRINT;
2065 freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer);
2068 if (settings->RedirectClipboard)
2070 if (!freerdp_static_channel_collection_find(settings, "cliprdr"))
2074 params[0] = "cliprdr";
2076 freerdp_client_add_static_channel(settings, 1, (char**) params);
2080 if (settings->LyncRdpMode)
2082 settings->EncomspVirtualChannel = TRUE;
2083 settings->RemdeskVirtualChannel = TRUE;
2084 settings->CompressionEnabled = FALSE;
2087 if (settings->RemoteAssistanceMode)
2089 settings->EncomspVirtualChannel = TRUE;
2090 settings->RemdeskVirtualChannel = TRUE;
2093 if (settings->EncomspVirtualChannel)
2094 freerdp_client_load_static_channel_addin(channels, settings, "encomsp", settings);
2096 if (settings->RemdeskVirtualChannel)
2097 freerdp_client_load_static_channel_addin(channels, settings, "remdesk", settings);
2099 for (index = 0; index < settings->StaticChannelCount; index++)
2101 args = settings->StaticChannelArray[index];
2102 freerdp_client_load_static_channel_addin(channels, settings, args->argv[0], args);
2105 if (settings->RemoteApplicationMode)
2107 freerdp_client_load_static_channel_addin(channels, settings, "rail", settings);
2110 if (settings->MultiTouchInput)
2118 freerdp_client_add_dynamic_channel(settings, count, p);
2121 if (settings->SupportGraphicsPipeline)
2129 freerdp_client_add_dynamic_channel(settings, count, p);
2132 if (settings->SupportEchoChannel)
2140 freerdp_client_add_dynamic_channel(settings, count, p);
2143 if (settings->SupportDisplayControl)
2151 freerdp_client_add_dynamic_channel(settings, count, p);
2154 if (settings->DynamicChannelCount)
2155 settings->SupportDynamicChannels = TRUE;
2157 if (settings->SupportDynamicChannels)
2159 freerdp_client_load_static_channel_addin(channels, settings, "drdynvc", settings);