xfreerdp: Read passwords using passphrase_read if none is specified

This commit is contained in:
Shea Levy 2011-09-24 19:08:16 -04:00
parent 9d59747dc9
commit a56bdea4c5

View File

@ -41,6 +41,7 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/semaphore.h>
#include <freerdp/utils/event.h>
#include <freerdp/utils/passphrase.h>
#include <freerdp/plugins/cliprdr.h>
#include <freerdp/rail.h>
@ -834,63 +835,15 @@ int main(int argc, char* argv[])
if (instance->settings->password == NULL)
{
int status;
char* password;
int pipe_ends[2];
struct termios term_flags;
const int password_size = 512;
const size_t password_size = 512;
password = xmalloc(password_size * sizeof(char));
instance->settings->password = xmalloc(password_size * sizeof(char));
printf("Password: ");
/* Turn off ECHO on stdin, but still echo newlines */
if (tcgetattr(fileno(stdin), &term_flags) != 0)
if(freerdp_passphrase_read("Password: ", instance->settings->password, password_size) == NULL)
{
perror(strerror(errno));
perror("xfreerdp");
exit(errno);
}
if (pipe(pipe_ends) != 0)
{
perror(strerror(errno));
exit(errno);
}
switch (fork())
{
case -1:
perror(strerror(errno));
exit(errno);
case 0:
close(pipe_ends[0]);
term_flags.c_lflag &= ~ECHO;
term_flags.c_lflag |= ECHONL;
tcsetattr(fileno(stdin), TCSAFLUSH, &term_flags);
fgets(password, password_size - 1, stdin);
write(pipe_ends[1], password, strlen(password));
close(pipe_ends[1]);
exit(EXIT_SUCCESS);
default:
wait(&status);
if (tcsetattr(fileno(stdin), TCSADRAIN, &term_flags) != 0)
{
tcsetattr(fileno(stdin), TCSANOW, &term_flags);
perror(strerror(errno));
exit(errno);
}
break;
}
close(pipe_ends[1]);
read(pipe_ends[0], password, password_size);
close(pipe_ends[0]);
*(password + strlen(password) - 1) = '\0';
xfree(instance->settings->password);
instance->settings->password = password;
}
data = (struct thread_data*) xzalloc(sizeof(struct thread_data));