From 96c4943a5bd070772d8be7bb7db8548840af5f8f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 25 Nov 2019 11:39:56 +0100 Subject: [PATCH] agent: Improve --debug-pinentry diagnostics * agent/call-pinentry.c (atfork_cb): Factor code out to ... (atfork_core): new. -- We convey certain envvars directly via the environment to Pinentry and thus they don't show up in the Assuan logging. Because we better don't call a logging function in an atfork handle, this patch splits the code up and uses the same code to display what was done in at fork after the connection has been established. Signed-off-by: Werner Koch (cherry picked from commit c8783b3a204b371d44b8953429652101cf2e4d1b) --- agent/call-pinentry.c | 54 ++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index aaf2af6ab..b0b5bcb92 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -191,6 +191,37 @@ unlock_pinentry (ctrl_t ctrl, gpg_error_t rc) } +/* Helper for at_fork_cb which can also be called by the parent to + * show shich envvars will be set. */ +static void +atfork_core (ctrl_t ctrl, int debug_mode) +{ + int iterator = 0; + const char *name, *assname, *value; + + while ((name = session_env_list_stdenvnames (&iterator, &assname))) + { + /* For all new envvars (!ASSNAME) and the two medium old ones + * which do have an assuan name but are conveyed using + * environment variables, update the environment of the forked + * process. */ + if (!assname + || !strcmp (name, "XAUTHORITY") + || !strcmp (name, "PINENTRY_USER_DATA")) + { + value = session_env_getenv (ctrl->session_env, name); + if (value) + { + if (debug_mode) + log_debug ("pinentry: atfork used setenv(%s,%s)\n",name,value); + else + gnupg_setenv (name, value, 1); + } + } + } +} + + /* To make sure we leave no secrets in our image after forking of the pinentry, we use this callback. */ static void @@ -200,26 +231,8 @@ atfork_cb (void *opaque, int where) if (!where) { - int iterator = 0; - const char *name, *assname, *value; - gcry_control (GCRYCTL_TERM_SECMEM); - - while ((name = session_env_list_stdenvnames (&iterator, &assname))) - { - /* For all new envvars (!ASSNAME) and the two medium old - ones which do have an assuan name but are conveyed using - environment variables, update the environment of the - forked process. */ - if (!assname - || !strcmp (name, "XAUTHORITY") - || !strcmp (name, "PINENTRY_USER_DATA")) - { - value = session_env_getenv (ctrl->session_env, name); - if (value) - gnupg_setenv (name, value, 1); - } - } + atfork_core (ctrl, 0); } } @@ -406,6 +419,9 @@ start_pinentry (ctrl_t ctrl) if (DBG_IPC) log_debug ("connection to PIN entry established\n"); + if (opt.debug_pinentry) + atfork_core (ctrl, 1); + value = session_env_getenv (ctrl->session_env, "PINENTRY_USER_DATA"); if (value != NULL) {