libfreerdp-client: fix command-line parsing with .rdp file
This commit is contained in:
parent
d2b9d9f9d5
commit
10f1a898ef
@ -113,7 +113,7 @@ int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv
|
||||
|
||||
if (settings->ConnectionFile)
|
||||
{
|
||||
return freerdp_client_parse_connection_file(context, settings->ConnectionFile);
|
||||
status = freerdp_client_parse_connection_file(context, settings->ConnectionFile);
|
||||
}
|
||||
|
||||
return status;
|
||||
@ -134,35 +134,37 @@ int freerdp_client_parse_connection_file(rdpContext* context, const char* filena
|
||||
int freerdp_client_parse_connection_file_buffer(rdpContext* context, BYTE* buffer, size_t size)
|
||||
{
|
||||
rdpFile* file;
|
||||
int status = -1;
|
||||
int status = -1;
|
||||
|
||||
file = freerdp_client_rdp_file_new();
|
||||
if (freerdp_client_parse_rdp_file_buffer(file, buffer, size)
|
||||
&& freerdp_client_populate_settings_from_rdp_file(file, context->settings))
|
||||
{
|
||||
status = 0;
|
||||
}
|
||||
|
||||
if (freerdp_client_parse_rdp_file_buffer(file, buffer, size)
|
||||
&& freerdp_client_populate_settings_from_rdp_file(file, context->settings))
|
||||
{
|
||||
status = 0;
|
||||
}
|
||||
|
||||
freerdp_client_rdp_file_free(file);
|
||||
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
int freerdp_client_write_connection_file(rdpContext* context, const char* filename, BOOL unicode)
|
||||
{
|
||||
rdpFile* file;
|
||||
int status = -1;
|
||||
rdpFile* file;
|
||||
int status = -1;
|
||||
|
||||
file = freerdp_client_rdp_file_new();
|
||||
if (freerdp_client_populate_rdp_file_from_settings(file, context->settings))
|
||||
{
|
||||
if (freerdp_client_write_rdp_file(file, filename, unicode))
|
||||
{
|
||||
status = 0;
|
||||
}
|
||||
}
|
||||
file = freerdp_client_rdp_file_new();
|
||||
|
||||
freerdp_client_rdp_file_free(file);
|
||||
if (freerdp_client_populate_rdp_file_from_settings(file, context->settings))
|
||||
{
|
||||
if (freerdp_client_write_rdp_file(file, filename, unicode))
|
||||
{
|
||||
status = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
freerdp_client_rdp_file_free(file);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -856,6 +856,26 @@ int freerdp_map_keyboard_layout_name_to_id(char* name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int freerdp_detect_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv)
|
||||
{
|
||||
int length;
|
||||
|
||||
if (index == 1)
|
||||
{
|
||||
length = strlen(argv[index]);
|
||||
|
||||
if (length > 4)
|
||||
{
|
||||
if (_stricmp(&(argv[index])[length - 4], ".rdp") == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, int* count)
|
||||
{
|
||||
int status;
|
||||
@ -869,7 +889,10 @@ int freerdp_detect_windows_style_command_line_syntax(int argc, char** argv, int*
|
||||
*count = 0;
|
||||
detect_status = 0;
|
||||
CommandLineClearArgumentsA(args);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, NULL, NULL, NULL);
|
||||
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags,
|
||||
NULL, freerdp_detect_command_line_pre_filter, NULL);
|
||||
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
@ -904,7 +927,10 @@ int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, int* c
|
||||
*count = 0;
|
||||
detect_status = 0;
|
||||
CommandLineClearArgumentsA(args);
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, NULL, NULL, NULL);
|
||||
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags,
|
||||
NULL, freerdp_detect_command_line_pre_filter, NULL);
|
||||
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
@ -949,9 +975,10 @@ BOOL freerdp_client_detect_command_line(int argc, char** argv, DWORD* flags)
|
||||
*flags = COMMAND_LINE_SEPARATOR_COLON;
|
||||
*flags |= COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SIGIL_PLUS_MINUS;
|
||||
}
|
||||
/* Ignore legacy parsing in case there is an error in the command line. */
|
||||
else if (old_cli_status >= 0)
|
||||
{
|
||||
/* Ignore legacy parsing in case there is an error in the command line. */
|
||||
|
||||
if ((old_cli_status == 1) || ((old_cli_count > posix_cli_count) && (old_cli_status != -1)))
|
||||
{
|
||||
*flags = COMMAND_LINE_SEPARATOR_SPACE;
|
||||
@ -1046,8 +1073,10 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin
|
||||
else
|
||||
{
|
||||
CommandLineClearArgumentsA(args);
|
||||
|
||||
status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, settings,
|
||||
freerdp_client_command_line_pre_filter, freerdp_client_command_line_post_filter);
|
||||
|
||||
if (status < 0)
|
||||
return status;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
|
||||
#define DEBUG_CLIENT_FILE 1
|
||||
//#define DEBUG_CLIENT_FILE 1
|
||||
|
||||
static BYTE BOM_UTF16_LE[2] = { 0xFF, 0xFE };
|
||||
static WCHAR CR_LF_STR_W[] = { '\r', '\n', '\0' };
|
||||
@ -679,12 +679,13 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
|
||||
freerdp_parse_username(file->Username, &user, &domain);
|
||||
freerdp_set_param_string(settings, FreeRDP_Username, user);
|
||||
|
||||
if (domain != NULL)
|
||||
if (domain)
|
||||
freerdp_set_param_string(settings, FreeRDP_Domain, domain);
|
||||
|
||||
if (user)
|
||||
free(user);
|
||||
if(domain)
|
||||
|
||||
if (domain)
|
||||
free(domain);
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,11 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
int count;
|
||||
int length;
|
||||
int index;
|
||||
BOOL match, found, argument = FALSE;
|
||||
BOOL notescaped = FALSE;
|
||||
BOOL match;
|
||||
BOOL found;
|
||||
BOOL argument;
|
||||
BOOL escaped;
|
||||
BOOL notescaped;
|
||||
char* sigil;
|
||||
int sigil_length;
|
||||
int sigil_index;
|
||||
@ -71,6 +74,12 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
|
||||
status = 0;
|
||||
|
||||
match = FALSE;
|
||||
found = FALSE;
|
||||
argument = FALSE;
|
||||
escaped = TRUE;
|
||||
notescaped = FALSE;
|
||||
|
||||
if (!argv)
|
||||
return status;
|
||||
|
||||
@ -82,12 +91,14 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
BOOL escaped = TRUE;
|
||||
index = i;
|
||||
|
||||
escaped = TRUE;
|
||||
|
||||
if (preFilter)
|
||||
{
|
||||
count = preFilter(context, i, argc, argv);
|
||||
|
||||
if (count < 0)
|
||||
{
|
||||
status = COMMAND_LINE_ERROR;
|
||||
@ -96,7 +107,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
i += count;
|
||||
i += (count - 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -136,6 +147,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
{
|
||||
if (notescaped)
|
||||
return COMMAND_LINE_ERROR;
|
||||
|
||||
sigil_length = 0;
|
||||
escaped = FALSE;
|
||||
notescaped = TRUE;
|
||||
@ -144,7 +156,7 @@ int CommandLineParseArgumentsA(int argc, LPCSTR* argv, COMMAND_LINE_ARGUMENT_A*
|
||||
{
|
||||
return COMMAND_LINE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if ((sigil_length > 0) || (flags & COMMAND_LINE_SIGIL_NONE) ||
|
||||
(flags & COMMAND_LINE_SIGIL_NOT_ESCAPED))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user