Package: mutt
Version: 1.5.23-3
Severity: wishlist
Tags: patch

Hi!

With recent GnuPG versions, the gpg-agent is always used, and is
started on demand if not already running. It also now uses a stable
socket pathname and as such does not need (and actually ignores) the
GPG_AGENT_INFO environment variable.

I had prepared a patch that uses that socket address also to determine
if the agent is running, but that's actually wrong, because not having
the agent running is a valid configuration and gpg2 will take care of
starting it if needed. So the only sane option with newer gpg2 is to
ignore the environment varialbe altogether. This can cause issues for
people using older gpg, but I'd say that if they are setting
pgp_use_gpg_agent=yes then they should know what they are doing?

In any case I'm attaching both patches, but the correct one to use
is the one that removes the check for the environment variable
(gpg2-agent-always.patch).

Thanks,
Guillem
---
 crypt-gpgme.c |   12 ------------
 pgp.c         |    2 +-
 2 files changed, 1 insertion(+), 13 deletions(-)

--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -4407,21 +4407,9 @@ static void init_common(void)
 }
 
 /* Initialization.  */
-static void init_gpgme (void)
-{
-  /* Make sure that gpg-agent is running.  */
-  if (! getenv ("GPG_AGENT_INFO"))
-    {
-      mutt_error (_("\nUsing GPGME backend, although no gpg-agent is running"));
-      if (mutt_any_key_to_continue (NULL) == -1)
-	mutt_exit(1);
-    }
-}
-
 void pgp_gpgme_init (void)
 {
   init_common();
-  init_gpgme ();
 }
 
 void smime_gpgme_init (void)
--- a/pgp.c
+++ b/pgp.c
@@ -108,7 +108,7 @@ int pgp_use_gpg_agent (void)
 {
   char *tty;
 
-  if (!option (OPTUSEGPGAGENT) || !getenv ("GPG_AGENT_INFO"))
+  if (!option (OPTUSEGPGAGENT))
     return 0;
 
   if ((tty = ttyname(0)))
---
 crypt-gpgme.c |    6 +++++-
 pgp.c         |    8 +++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -4409,8 +4409,12 @@ static void init_common(void)
 /* Initialization.  */
 static void init_gpgme (void)
 {
+  char gpg_agent_socket[STRING];
+
   /* Make sure that gpg-agent is running.  */
-  if (! getenv ("GPG_AGENT_INFO"))
+  snprintf (gpg_agent_socket, sizeof(gpg_agent_socket),
+            "%s/.gnupg/S.gpg-agent", NONULL(Homedir));
+  if (! getenv ("GPG_AGENT_INFO") && access (gpg_agent_socket, F_OK) == -1)
     {
       mutt_error (_("\nUsing GPGME backend, although no gpg-agent is running"));
       if (mutt_any_key_to_continue (NULL) == -1)
--- a/pgp.c
+++ b/pgp.c
@@ -106,9 +106,15 @@ void pgp_forget_passphrase (void)
 
 int pgp_use_gpg_agent (void)
 {
+  char gpg_agent_socket[STRING];
   char *tty;
 
-  if (!option (OPTUSEGPGAGENT) || !getenv ("GPG_AGENT_INFO"))
+  if (!option (OPTUSEGPGAGENT))
+    return 0;
+
+  snprintf (gpg_agent_socket, sizeof(gpg_agent_socket),
+            "%s/.gnupg/S.gpg-agent", NONULL(Homedir));
+  if (!getenv ("GPG_AGENT_INFO") && access (gpg_agent_socket, F_OK) == -1)
     return 0;
 
   if ((tty = ttyname(0)))

Reply via email to