mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
Makes parsing of values off of stdin more robust by initializing the buffers initial and checking the returns from scanf. Also, provides for a null domain by using '.' to make it easier to pipe values into xfreerdp.
This commit is contained in:
@@ -871,34 +871,42 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
|
||||
/* username */
|
||||
if (NULL == settings->username) {
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("username: ");
|
||||
scanf("%511s", input);
|
||||
settings->username = xstrdup(input);
|
||||
if (scanf("%511s", input) > 0) {
|
||||
settings->username = xstrdup(input);
|
||||
}
|
||||
}
|
||||
/* password */
|
||||
if (NULL == settings->password) {
|
||||
settings->password = xmalloc(512 * sizeof(char));
|
||||
if (isatty(STDIN_FILENO))
|
||||
freerdp_passphrase_read("password: ", settings->password, 512, settings->from_stdin);
|
||||
else
|
||||
{
|
||||
printf("password: ");
|
||||
scanf("%511s", settings->password);
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("password: ");
|
||||
if (scanf("%511s", input) > 0) {
|
||||
settings->password = xstrdup(input);
|
||||
}
|
||||
}
|
||||
/* domain */
|
||||
if (NULL == settings->domain) {
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("domain (control-D to skip): ");
|
||||
scanf("%511s", input);
|
||||
settings->domain = xstrdup(input);
|
||||
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')) {
|
||||
settings->domain = xstrdup(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* hostname */
|
||||
if (NULL == settings->hostname) {
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("hostname: ");
|
||||
scanf("%511s", input);
|
||||
freerdp_parse_hostname(settings, input);
|
||||
if (scanf("%511s", input) > 0) {
|
||||
freerdp_parse_hostname(settings, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user