[git] GnuPG - branch, master, updated. gnupg-2.2.7-377-gc395f83
by NIIBE Yutaka
cvs at cvs.gnupg.org
Tue Feb 19 06:41:42 CET 2019
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".
The branch, master has been updated
via c395f8315362793409be54aca630ce6e903ea984 (commit)
via 99aa54323f97937613e02d8c2da91544e1fe7bcf (commit)
from ada797f477f923bee36d67c8e49f728ae7adb9e9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c395f8315362793409be54aca630ce6e903ea984
Author: NIIBE Yutaka <gniibe at fsij.org>
Date: Tue Feb 19 14:36:50 2019 +0900
agent: Terminate pinentry process gracefully, by watching socket.
* agent/call-pinentry.c (watch_sock): New.
(do_getpin): Spawn the watching thread.
--
While we don't have npth_cancel (and it's difficult to implement it
correctly), this is a kind of best compromise allowing a thread's
polling when pinentry is active.
GnuPG-bug-id: 2011
Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>
diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c
index 0c8f7dc..34dde37 100644
--- a/agent/call-pinentry.c
+++ b/agent/call-pinentry.c
@@ -942,16 +942,88 @@ build_cmd_setdesc (char *line, size_t linelen, const char *desc)
-/* Ask pinentry to get a pin by "GETPIN" command.
- * FIXME: Support EOF detection of the socket: ctrl->thread_startup.fd
+/* Watch the socket's EOF condition, while checking finish of
+ foreground thread. When EOF condition is detected, terminate
+ the pinentry process behind the assuan pipe.
+ */
+static void *
+watch_sock (void *arg)
+{
+ gnupg_fd_t *p = (gnupg_fd_t *)arg;
+ pid_t pid = assuan_get_pid (entry_ctx);
+
+ while (1)
+ {
+ int err;
+ gnupg_fd_t sock = *p;
+ fd_set fdset;
+ struct timeval timeout = { 0, 500000 };
+
+ if (sock == GNUPG_INVALID_FD)
+ return NULL;
+
+ FD_ZERO (&fdset);
+ FD_SET (FD2INT (sock), &fdset);
+ err = npth_select (FD2INT (sock)+1, &fdset, NULL, NULL, &timeout);
+
+ if (err < 0)
+ {
+ if (errno == EINTR)
+ continue;
+ else
+ return NULL;
+ }
+
+ /* Possibly, it's EOF. */
+ if (err > 0)
+ break;
+ }
+
+ if (pid == (pid_t)(-1))
+ ; /* No pid available can't send a kill. */
+#ifdef HAVE_W32_SYSTEM
+ /* Older versions of assuan set PID to 0 on Windows to indicate an
+ invalid value. */
+ else if (pid != (pid_t) INVALID_HANDLE_VALUE && pid != 0)
+ TerminateProcess ((HANDLE)pid, 1);
+#else
+ else if (pid > 0)
+ kill (pid, SIGINT);
+#endif
+
+ return NULL;
+}
+
+
+/* Ask pinentry to get a pin by "GETPIN" command, spawning a thread
+ detecting the socket's EOF.
*/
static gpg_error_t
do_getpin (ctrl_t ctrl, struct entry_parm_s *parm)
{
- int rc;
+ npth_attr_t tattr;
+ gpg_error_t rc;
+ int err;
+ npth_t thread;
int saveflag = assuan_get_flag (entry_ctx, ASSUAN_CONFIDENTIAL);
+ gnupg_fd_t sock_watched = ctrl->thread_startup.fd;
+
+ err = npth_attr_init (&tattr);
+ if (err)
+ {
+ log_error ("do_getpin: error npth_attr_init: %s\n", strerror (err));
+ return gpg_error_from_errno (err);
+ }
+ npth_attr_setdetachstate (&tattr, NPTH_CREATE_JOINABLE);
+
+ err = npth_create (&thread, &tattr, watch_sock, (void *)&sock_watched);
+ npth_attr_destroy (&tattr);
+ if (err)
+ {
+ log_error ("do_getpin: error spawning thread: %s\n", strerror (err));
+ return gpg_error_from_errno (err);
+ }
- (void)ctrl;
assuan_begin_confidential (entry_ctx);
rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, parm,
inq_quality, entry_ctx,
@@ -968,6 +1040,11 @@ do_getpin (ctrl_t ctrl, struct entry_parm_s *parm)
&& gpg_err_code (rc) == GPG_ERR_CANCELED)
rc = gpg_err_make (gpg_err_source (rc), GPG_ERR_FULLY_CANCELED);
+ sock_watched = GNUPG_INVALID_FD;
+ err = npth_join (thread, NULL);
+ if (err)
+ log_error ("do_getpin: error joining thread: %s\n", strerror (err));
+
return rc;
}
commit 99aa54323f97937613e02d8c2da91544e1fe7bcf
Author: NIIBE Yutaka <gniibe at fsij.org>
Date: Tue Feb 19 13:12:07 2019 +0900
agent: Minor change for pinentry status handling.
* agent/call-pinentry.c (struct entry_parm_s): Add status.
(do_getpin): Use param->status.
(agent_askpin): Copy param->status. to pininfo.
Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>
diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c
index c7ff70a..0c8f7dc 100644
--- a/agent/call-pinentry.c
+++ b/agent/call-pinentry.c
@@ -85,6 +85,7 @@ struct entry_parm_s
int lines;
size_t size;
unsigned char *buffer;
+ int status;
};
@@ -945,19 +946,16 @@ build_cmd_setdesc (char *line, size_t linelen, const char *desc)
* FIXME: Support EOF detection of the socket: ctrl->thread_startup.fd
*/
static gpg_error_t
-do_getpin (ctrl_t ctrl, struct entry_parm_s *parm,
- struct pin_entry_info_s *pininfo)
+do_getpin (ctrl_t ctrl, struct entry_parm_s *parm)
{
int rc;
- unsigned int pinentry_status;
int saveflag = assuan_get_flag (entry_ctx, ASSUAN_CONFIDENTIAL);
(void)ctrl;
assuan_begin_confidential (entry_ctx);
- pinentry_status = 0;
rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, parm,
inq_quality, entry_ctx,
- pinentry_status_cb, &pinentry_status);
+ pinentry_status_cb, &parm->status);
assuan_set_flag (entry_ctx, ASSUAN_CONFIDENTIAL, saveflag);
/* Most pinentries out in the wild return the old Assuan error code
for canceled which gets translated to an assuan Cancel error and
@@ -966,13 +964,10 @@ do_getpin (ctrl_t ctrl, struct entry_parm_s *parm,
rc = gpg_err_make (gpg_err_source (rc), GPG_ERR_CANCELED);
/* Change error code in case the window close button was clicked
to cancel the operation. */
- if ((pinentry_status & PINENTRY_STATUS_CLOSE_BUTTON)
+ if ((parm->status & PINENTRY_STATUS_CLOSE_BUTTON)
&& gpg_err_code (rc) == GPG_ERR_CANCELED)
rc = gpg_err_make (gpg_err_source (rc), GPG_ERR_FULLY_CANCELED);
- if (pininfo)
- pininfo->status = pinentry_status;
-
return rc;
}
@@ -1134,7 +1129,8 @@ agent_askpin (ctrl_t ctrl,
return unlock_pinentry (ctrl, rc);
}
- rc = do_getpin (ctrl, &parm, pininfo);
+ rc = do_getpin (ctrl, &parm);
+ pininfo->status = parm.status;
if (gpg_err_code (rc) == GPG_ERR_ASS_TOO_MUCH_DATA)
errtext = is_pin? L_("PIN too long")
: L_("Passphrase too long");
@@ -1289,7 +1285,7 @@ agent_get_passphrase (ctrl_t ctrl,
if (!parm.buffer)
return unlock_pinentry (ctrl, out_of_core ());
- rc = do_getpin (ctrl, &parm, NULL);
+ rc = do_getpin (ctrl, &parm);
if (rc)
xfree (parm.buffer);
else
-----------------------------------------------------------------------
Summary of changes:
agent/call-pinentry.c | 101 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 87 insertions(+), 14 deletions(-)
hooks/post-receive
--
The GNU Privacy Guard
http://git.gnupg.org
More information about the Gnupg-commits
mailing list