Handle PIN: as a magic keyword for prompt, use getpass() to silently read credentials

This commit is contained in:
Martin Willi 2010-07-19 09:43:11 +02:00
parent 62be923683
commit 70789d28a1
2 changed files with 22 additions and 9 deletions

View File

@ -185,6 +185,7 @@ char *whitelist[] = {
"__vsyslog_chk", "__vsyslog_chk",
"getaddrinfo", "getaddrinfo",
"setlocale", "setlocale",
"getpass",
/* ignore dlopen, as we do not dlclose to get proper leak reports */ /* ignore dlopen, as we do not dlclose to get proper leak reports */
"dlopen", "dlopen",
"dlerror", "dlerror",

View File

@ -56,9 +56,8 @@ static char* push_string(stroke_msg_t *msg, char *string)
static int send_stroke_msg (stroke_msg_t *msg) static int send_stroke_msg (stroke_msg_t *msg)
{ {
struct sockaddr_un ctl_addr; struct sockaddr_un ctl_addr;
int sock; int sock, byte_count;
char buffer[512]; char buffer[512], *pass;
int byte_count;
ctl_addr.sun_family = AF_UNIX; ctl_addr.sun_family = AF_UNIX;
strcpy(ctl_addr.sun_path, STROKE_SOCKET); strcpy(ctl_addr.sun_path, STROKE_SOCKET);
@ -90,16 +89,29 @@ static int send_stroke_msg (stroke_msg_t *msg)
while ((byte_count = read(sock, buffer, sizeof(buffer)-1)) > 0) while ((byte_count = read(sock, buffer, sizeof(buffer)-1)) > 0)
{ {
buffer[byte_count] = '\0'; buffer[byte_count] = '\0';
printf("%s", buffer);
/* we prompt if we receive the "Passphrase:" magic keyword */ /* we prompt if we receive the "Passphrase:"/"PIN:" magic keyword */
if (byte_count >= 12 && if ((byte_count >= 12 &&
strcmp(buffer + byte_count - 12, "Passphrase:\n") == 0) strcmp(buffer + byte_count - 12, "Passphrase:\n") == 0) ||
(byte_count >= 5 &&
strcmp(buffer + byte_count - 5, "PIN:\n") == 0))
{ {
if (fgets(buffer, sizeof(buffer), stdin)) /* remove trailing newline */
pass = strrchr(buffer, '\n');
if (pass)
{ {
ignore_result(write(sock, buffer, strlen(buffer))); *pass = ' ';
} }
pass = getpass(buffer);
if (pass)
{
ignore_result(write(sock, pass, strlen(pass)));
ignore_result(write(sock, "\n", 1));
}
}
else
{
printf("%s", buffer);
} }
} }
if (byte_count < 0) if (byte_count < 0)