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.
This commit is contained in:
parent
e5e2ee2aaa
commit
7a002270d8
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user