From 2b596b2b853e5a3a07d210781bc7a6368362279e Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 10 Dec 2007 19:50:53 -0500 Subject: [PATCH] Fixed OPTION TIMEOUT=N. The pinentry process will terminate after the set amount of seconds and the command will return GPG_ERR_TIMEOUT. --- src/pinentry.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/pinentry.c b/src/pinentry.c index f29b0ed4..b48c143e 100644 --- a/src/pinentry.c +++ b/src/pinentry.c @@ -40,6 +40,9 @@ typedef struct { void *buf; } membuf_t; +static struct client_s *global_client; +static gint send_fd; + static gpg_error_t set_pinentry_strings(struct pinentry_s *pin, int which); /* Borrowed from libassuan 1.0.4 svn 277 */ @@ -213,7 +216,7 @@ static gpg_error_t launch_pinentry(struct pinentry_s *pin) if (rc) return _assuan_error(rc); - //pin->pid = assuan_get_pid(ctx); + pin->pid = assuan_get_pid(ctx); pin->ctx = ctx; return set_pinentry_strings(pin, 0); } @@ -320,6 +323,27 @@ static gpg_error_t getpin(struct pinentry_s *pin, gchar **result, int which) return error; } +static void catchsig(gint sig) +{ + pinentry_key_s pk; + + switch (sig) { + case SIGALRM: + if (global_client->pinentry->pid) { + kill(SIGTERM, global_client->pinentry->pid); + global_client->pinentry->pid = 0; + } + + memset(&pk, 0, sizeof(pk)); + pk.error = GPG_ERR_TIMEOUT; + pth_write(send_fd, &pk, sizeof(pk)); + cleanup_pinentry(global_client->pinentry); + free_client(global_client); + _exit(1); + break; + } +} + gpg_error_t pinentry_fork(assuan_context_t ctx) { struct client_s *client = assuan_get_pointer(ctx); @@ -344,7 +368,11 @@ gpg_error_t pinentry_fork(assuan_context_t ctx) close(p[1]); return send_error(ctx, error); case 0: + signal(SIGALRM, catchsig); close(p[0]); + send_fd = p[1]; + global_client = client; + alarm(client->pinentry->timeout); pk.error = getpin(client->pinentry, &result, 0); cleanup_pinentry(client->pinentry); free_client(client); @@ -390,7 +418,7 @@ void cleanup_pinentry(struct pinentry_s *pin) if (!pin) return; - if (pin->ctx) + if (pin->ctx && pin->pid) pinentry_disconnect(pin); xfree(pin->ttyname); -- 2.11.4.GIT