]> granicus.if.org Git - mutt/commitdiff
Always use the gpgme_new wrapper in crypt-gpgme.
authorWerner Koch <wk@gnupg.org>
Mon, 3 Dec 2018 07:41:54 +0000 (08:41 +0100)
committerKevin McCarthy <kevin@8t8.us>
Wed, 5 Dec 2018 03:15:07 +0000 (19:15 -0800)
The wrapper is much more convenient and there is no need to sometimes
use gpgme_new directly.  The perceived advantage on not bailing out in
an out-of-core condition is not realistic because other small amounts
of memory are allocated all over mutt anyway and thus function will
terminate the process as well.

This patch also changes the minimum version of gpgme to 1.4.0.  This
is so that we can always pass NULL to functions like gpgme_release.
Further 1.4.0 has new functions which we may soon like to use.

configure.ac
crypt-gpgme.c

index 8ab8b0c324388208c4481f64f179cbb618c44bb1..892de59fc33fa9426b9288c7c5d3b3d67f22db9d 100644 (file)
@@ -129,11 +129,11 @@ AC_ARG_ENABLE(gpgme, AS_HELP_STRING([--enable-gpgme],[Enable GPGME support]),
 
 if test x"$enable_gpgme" = xyes; then
    AC_MSG_RESULT(yes)
-   AM_PATH_GPGME(1.2.0, AC_DEFINE(CRYPT_BACKEND_GPGME, 1,
+   AM_PATH_GPGME(1.4.0, AC_DEFINE(CRYPT_BACKEND_GPGME, 1,
                 [Defined, if GPGME support is enabled]),
                 [gpgme_found=no])
    if test x"$gpgme_found" = xno; then
-      AC_MSG_ERROR([*** GPGME not found or version is older than 1.2 ***])
+      AC_MSG_ERROR([*** GPGME not found or version is older than 1.4 ***])
    else
       MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS crypt-gpgme.o crypt-mod-pgp-gpgme.o crypt-mod-smime-gpgme.o"
    fi
index 554883571473908e7b7aa7ab4d256153f4dd4ea1..ab0e2eec4210ec552847b21324638908794bc002 100644 (file)
@@ -61,6 +61,7 @@
 # include <sys/resource.h>
 #endif
 
+
 /*
  * Helper macros.
  */
@@ -644,57 +645,50 @@ static gpgme_key_t *create_recipient_set (const char *keylist,
   gpgme_key_t key = NULL;
   gpgme_ctx_t context = NULL;
 
-  err = gpgme_new (&context);
-  if (! err)
-    err = gpgme_set_protocol (context, protocol);
-
-  if (! err)
-    {
-      s = keylist;
-      do {
-       while (*s == ' ')
-         s++;
-       for (i=0; *s && *s != ' ' && i < sizeof(buf)-1;)
-         buf[i++] = *s++;
-       buf[i] = 0;
-       if (*buf)
-         {
-           if (i>1 && buf[i-1] == '!')
-             {
-               /* The user selected to override the validity of that
-                  key. */
-               buf[i-1] = 0;
-
-               err = gpgme_get_key (context, buf, &key, 0);
-               if (! err)
-                 key->uids->validity = GPGME_VALIDITY_FULL;
-               buf[i-1] = '!';
-             }
-           else
-             err = gpgme_get_key (context, buf, &key, 0);
+  context = create_gpgme_context ((protocol == GPGME_PROTOCOL_CMS));
+  s = keylist;
+  do {
+    while (*s == ' ')
+      s++;
+    for (i=0; *s && *s != ' ' && i < sizeof(buf)-1;)
+      buf[i++] = *s++;
+    buf[i] = 0;
+    if (*buf)
+      {
+        if (i>1 && buf[i-1] == '!')
+          {
+            /* The user selected to override the validity of that
+               key. */
+            buf[i-1] = 0;
+
+            err = gpgme_get_key (context, buf, &key, 0);
+            if (! err)
+              key->uids->validity = GPGME_VALIDITY_FULL;
+            buf[i-1] = '!';
+          }
+        else
+          err = gpgme_get_key (context, buf, &key, 0);
 
-            safe_realloc (&rset, sizeof (*rset) * (rset_n + 1));
-           if (! err)
-              rset[rset_n++] = key;
-           else
-             {
-               mutt_error (_("error adding recipient `%s': %s\n"),
-                           buf, gpgme_strerror (err));
-                rset[rset_n] = NULL;
-                free_recipient_set (&rset);
-               gpgme_release (context);
-               return NULL;
+        safe_realloc (&rset, sizeof (*rset) * (rset_n + 1));
+        if (! err)
+          rset[rset_n++] = key;
+        else
+          {
+            mutt_error (_("error adding recipient `%s': %s\n"),
+                        buf, gpgme_strerror (err));
+            rset[rset_n] = NULL;
+            free_recipient_set (&rset);
+            gpgme_release (context);
+            return NULL;
              }
-         }
-      } while (*s);
-    }
+      }
+  } while (*s);
 
   /* NULL terminate.  */
   safe_realloc (&rset, sizeof (*rset) * (rset_n + 1));
   rset[rset_n++] = NULL;
 
-  if (context)
-    gpgme_release (context);
+  gpgme_release (context);
 
   return rset;
 }
@@ -2048,11 +2042,11 @@ static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun)
   int rc = -1;
   time_t tt;
 
-  if ((err = gpgme_new (&tmpctx)) != GPG_ERR_NO_ERROR)
-  {
-    dprint (1, (debugfile, "Error creating GPGME context\n"));
-    return rc;
-  }
+#if GPGME_VERSION_NUMBER >= 0x010900 /* 1.9.0 */
+
+#endif
+
+  tmpctx = create_gpgme_context (0);
 
   if (dryrun)
   {
@@ -3717,15 +3711,7 @@ verify_key (crypt_key_t *key)
 
   print_key_info (key->kobj, fp);
 
-  err = gpgme_new (&listctx);
-  if (err)
-    {
-      fprintf (fp, "Internal error: can't create gpgme context: %s\n",
-               gpgme_strerror (err));
-      goto leave;
-    }
-  if ((key->flags & KEYFLAG_ISX509))
-      gpgme_set_protocol (listctx, GPGME_PROTOCOL_CMS);
+  listctx = create_gpgme_context ((key->flags & KEYFLAG_ISX509));
 
   k = key->kobj;
   gpgme_key_ref (k);
@@ -3840,14 +3826,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret)
   if (!pattern)
     return NULL;
 
-  err = gpgme_new (&ctx);
-  if (err)
-    {
-      mutt_error (_("gpgme_new failed: %s"), gpgme_strerror (err));
-      FREE (&pattern);
-      return NULL;
-    }
-
+  ctx = create_gpgme_context (0);
   db = NULL;
   kend = &db;