From e5e2ee2aaa8f6441b447f16c806ce2f7329b177d Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Sun, 28 Oct 2012 01:24:07 +0200 Subject: [PATCH 1/3] utils/args: fixed formating --- libfreerdp/utils/args.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/libfreerdp/utils/args.c b/libfreerdp/utils/args.c index 1908d7184..d6b110a89 100644 --- a/libfreerdp/utils/args.c +++ b/libfreerdp/utils/args.c @@ -869,58 +869,72 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, You can prompt for username, password, domain and hostname to avoid disclosing these settings to ps. */ - if (settings->from_stdin) { + if (settings->from_stdin) + { /* username */ - if (NULL == settings->username) { + if (NULL == settings->username) + { char input[512]; input[0] = '\0'; printf("username: "); - if (scanf("%511s", input) > 0) { + if (scanf("%511s", input) > 0) + { settings->username = _strdup(input); } } /* password */ - if (NULL == settings->password) { + if (NULL == settings->password) + { settings->password = malloc(512 * sizeof(char)); if (isatty(STDIN_FILENO)) freerdp_passphrase_read("password: ", settings->password, 512, settings->from_stdin); - else { + else + { printf("password: "); - if (scanf("%511s", settings->password) <= 0) { + if (scanf("%511s", settings->password) <= 0) + { free(settings->password); settings->password = NULL; } } } /* domain */ - if (NULL == settings->domain) { + if (NULL == settings->domain) + { char input[512]; input[0] = '\0'; printf("domain (control-D to skip): "); - if (scanf("%511s", input) > 0) { + if (scanf("%511s", input) > 0) + { /* Try to catch the cases where the string is NULL-ish right at the get go */ - if (input[0] != '\0' && !(input[0] == '.' && input[1] == '\0')) { + if (input[0] != '\0' && !(input[0] == '.' && input[1] == '\0')) + { settings->domain = _strdup(input); } } } /* hostname */ - if (NULL == settings->hostname) { + if (NULL == settings->hostname) + { char input[512]; input[0] = '\0'; printf("hostname: "); - if (scanf("%511s", input) > 0) { + if (scanf("%511s", input) > 0) + { freerdp_parse_hostname(settings, input); } } } /* Must have a hostname. Do you? */ - if (NULL == settings->hostname) { + if (NULL == settings->hostname) + { printf("missing server name\n"); return FREERDP_ARGS_PARSE_FAILURE; - } else { + } + else + { return index; } From 7a002270d87c4b336514df66ca711748508a91d8 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Sun, 28 Oct 2012 01:46:33 +0200 Subject: [PATCH 2/3] util/args: fixed when using --from-stdin - Discard new lines with scanf. - If domain is left empty (STRG+d pressed) clear EOF flag - this fixes an enless loop in xfreerdp on OS X when input is required after a certificate warning. --- libfreerdp/utils/args.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libfreerdp/utils/args.c b/libfreerdp/utils/args.c index d6b110a89..86dea02c9 100644 --- a/libfreerdp/utils/args.c +++ b/libfreerdp/utils/args.c @@ -877,7 +877,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, char input[512]; input[0] = '\0'; printf("username: "); - if (scanf("%511s", input) > 0) + if (scanf("%511s%*c", input) > 0) { settings->username = _strdup(input); } @@ -887,11 +887,13 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, { settings->password = malloc(512 * sizeof(char)); if (isatty(STDIN_FILENO)) + { freerdp_passphrase_read("password: ", settings->password, 512, settings->from_stdin); + } else { printf("password: "); - if (scanf("%511s", settings->password) <= 0) + if (scanf("%511s%*c", settings->password) <= 0) { free(settings->password); settings->password = NULL; @@ -904,7 +906,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, char input[512]; input[0] = '\0'; printf("domain (control-D to skip): "); - if (scanf("%511s", input) > 0) + if (scanf("%511s%*c", input) > 0) { /* Try to catch the cases where the string is NULL-ish right at the get go */ @@ -913,6 +915,11 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, settings->domain = _strdup(input); } } + if (feof(stdin)) + { + printf("\n"); + clearerr(stdin); + } } /* hostname */ if (NULL == settings->hostname) @@ -920,7 +927,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, char input[512]; input[0] = '\0'; printf("hostname: "); - if (scanf("%511s", input) > 0) + if (scanf("%511s%*c", input) > 0) { freerdp_parse_hostname(settings, input); } From 4d870b942199675416093689225cdb123cd51c1d Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Sun, 28 Oct 2012 02:10:07 +0200 Subject: [PATCH 3/3] xfreerdp: fix for endless loop with --from-stdin If --from-stdin was used non-interactive (e.g. in a script echoing connection parameters) xfreerdp looped endlessly when a certificate needed to be trusted because fgets returns eof. Now a hint is printed that xfreerdp should be run without --from-stdin to set the certificate trust. --- client/X11/xfreerdp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/X11/xfreerdp.c b/client/X11/xfreerdp.c index 0bbbf5f0b..e6b486801 100644 --- a/client/X11/xfreerdp.c +++ b/client/X11/xfreerdp.c @@ -848,6 +848,14 @@ BOOL xf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* { printf("Do you trust the above certificate? (Y/N) "); answer = fgetc(stdin); + if (feof(stdin)) + { + printf("\nError: Could not read answer from stdin."); + if (instance->settings->from_stdin) + printf(" - Run without parameter \"--from-stdin\" to set trust."); + printf("\n"); + return FALSE; + } if (answer == 'y' || answer == 'Y') {