Merge pull request #785 from bmiklautz/from-stdin

Cleanup and fixes for --from-stdin parameter
This commit is contained in:
Marc-André Moreau 2012-10-27 19:41:23 -07:00
commit a98f4959a6
2 changed files with 42 additions and 13 deletions

View File

@ -848,6 +848,14 @@ BOOL xf_verify_certificate(freerdp* instance, char* subject, char* issuer, char*
{ {
printf("Do you trust the above certificate? (Y/N) "); printf("Do you trust the above certificate? (Y/N) ");
answer = fgetc(stdin); 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') if (answer == 'y' || answer == 'Y')
{ {

View File

@ -869,58 +869,79 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
You can prompt for username, password, domain and hostname to avoid disclosing You can prompt for username, password, domain and hostname to avoid disclosing
these settings to ps. */ these settings to ps. */
if (settings->from_stdin) { if (settings->from_stdin)
{
/* username */ /* username */
if (NULL == settings->username) { if (NULL == settings->username)
{
char input[512]; char input[512];
input[0] = '\0'; input[0] = '\0';
printf("username: "); printf("username: ");
if (scanf("%511s", input) > 0) { if (scanf("%511s%*c", input) > 0)
{
settings->username = _strdup(input); settings->username = _strdup(input);
} }
} }
/* password */ /* password */
if (NULL == settings->password) { if (NULL == settings->password)
{
settings->password = malloc(512 * sizeof(char)); settings->password = malloc(512 * sizeof(char));
if (isatty(STDIN_FILENO)) if (isatty(STDIN_FILENO))
{
freerdp_passphrase_read("password: ", settings->password, 512, settings->from_stdin); freerdp_passphrase_read("password: ", settings->password, 512, settings->from_stdin);
else { }
else
{
printf("password: "); printf("password: ");
if (scanf("%511s", settings->password) <= 0) { if (scanf("%511s%*c", settings->password) <= 0)
{
free(settings->password); free(settings->password);
settings->password = NULL; settings->password = NULL;
} }
} }
} }
/* domain */ /* domain */
if (NULL == settings->domain) { if (NULL == settings->domain)
{
char input[512]; char input[512];
input[0] = '\0'; input[0] = '\0';
printf("domain (control-D to skip): "); 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 /* Try to catch the cases where the string is NULL-ish right
at the get go */ 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); settings->domain = _strdup(input);
} }
} }
if (feof(stdin))
{
printf("\n");
clearerr(stdin);
}
} }
/* hostname */ /* hostname */
if (NULL == settings->hostname) { if (NULL == settings->hostname)
{
char input[512]; char input[512];
input[0] = '\0'; input[0] = '\0';
printf("hostname: "); printf("hostname: ");
if (scanf("%511s", input) > 0) { if (scanf("%511s%*c", input) > 0)
{
freerdp_parse_hostname(settings, input); freerdp_parse_hostname(settings, input);
} }
} }
} }
/* Must have a hostname. Do you? */ /* Must have a hostname. Do you? */
if (NULL == settings->hostname) { if (NULL == settings->hostname)
{
printf("missing server name\n"); printf("missing server name\n");
return FREERDP_ARGS_PARSE_FAILURE; return FREERDP_ARGS_PARSE_FAILURE;
} else { }
else
{
return index; return index;
} }