aboutsummaryrefslogtreecommitdiffstats
path: root/src/stroke
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-07-19 09:43:11 +0200
committerMartin Willi <martin@revosec.ch>2010-08-04 09:26:21 +0200
commit70789d28a13ac8f2448d97c23df2c7707b11937a (patch)
tree9311848b934b4aa63fc55e1d3945dd439fc25200 /src/stroke
parent62be923683721045c29040b252bbc3de259eb8dd (diff)
downloadstrongswan-70789d28a13ac8f2448d97c23df2c7707b11937a.tar.bz2
strongswan-70789d28a13ac8f2448d97c23df2c7707b11937a.tar.xz
Handle PIN: as a magic keyword for prompt, use getpass() to silently read credentials
Diffstat (limited to 'src/stroke')
-rw-r--r--src/stroke/stroke.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c
index 4fa0f76a8..32e628df1 100644
--- a/src/stroke/stroke.c
+++ b/src/stroke/stroke.c
@@ -56,9 +56,8 @@ static char* push_string(stroke_msg_t *msg, char *string)
static int send_stroke_msg (stroke_msg_t *msg)
{
struct sockaddr_un ctl_addr;
- int sock;
- char buffer[512];
- int byte_count;
+ int sock, byte_count;
+ char buffer[512], *pass;
ctl_addr.sun_family = AF_UNIX;
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)
{
buffer[byte_count] = '\0';
- printf("%s", buffer);
- /* we prompt if we receive the "Passphrase:" magic keyword */
- if (byte_count >= 12 &&
- strcmp(buffer + byte_count - 12, "Passphrase:\n") == 0)
+ /* we prompt if we receive the "Passphrase:"/"PIN:" magic keyword */
+ if ((byte_count >= 12 &&
+ 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)