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.
(cherry picked from commit 7a002270d8
)
This commit is contained in:
parent
b0d569626c
commit
10abb71b5b
@ -726,7 +726,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 = xstrdup(input);
|
||||
}
|
||||
@ -736,11 +736,13 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
|
||||
{
|
||||
settings->password = xmalloc(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;
|
||||
@ -753,7 +755,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 */
|
||||
@ -762,6 +764,11 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
|
||||
settings->domain = xstrdup(input);
|
||||
}
|
||||
}
|
||||
if (feof(stdin))
|
||||
{
|
||||
printf("\n");
|
||||
clearerr(stdin);
|
||||
}
|
||||
}
|
||||
/* hostname */
|
||||
if (NULL == settings->hostname)
|
||||
@ -769,7 +776,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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user