[git] GPGME - branch, master, updated. gpgme-1.6.0-288-g8c09dd9

by Werner Koch cvs at cvs.gnupg.org
Tue Aug 16 18:56:25 CEST 2016


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 "GnuPG Made Easy".

The branch, master has been updated
       via  8c09dd9989bcd434a8cb5997770cb8414b96bd5c (commit)
       via  b7b0e7b5bfefd51c8092ea54f262b18aebf78128 (commit)
      from  391e55411cda11446ca9de4dd0dc2b54d3e6fff5 (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 8c09dd9989bcd434a8cb5997770cb8414b96bd5c
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Aug 16 18:53:42 2016 +0200

    core: New global flag "require-gnupg".
    
    * src/gpgme.c (gpgme_set_global_flag): Add flag.
    * src/engine.c (engine_minimal_version): New variable.
    (_gpgme_set_engine_minimal_version): New function.
    (gpgme_get_engine_info): Check that flag.
    
    * tests/run-keylist.c (main): New option --require-gnupg.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/NEWS b/NEWS
index e47ec91..ce16687 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_]
 
  * Bindings for Python 3 are now included.
 
+ * New global flag "require-gnupg" to set a minimal gnupg version.
+
  * Interface changes relative to the 1.6.0 release:
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  gpgme_pubkey_algo_string       NEW.
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index 8b0ec52..ac0fffa 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -678,12 +678,12 @@ as early as possible --- even before @code{gpgme_check_version}.  The
 features are identified by the following values for @var{name}:
 
 @table @code
- at item "debug"
+ at item debug
 To enable debugging use the string ``debug'' for @var{name} and
 @var{value} identical to the value used with the environment variable
 @code{GPGME_DEBUG}.
 
- at item "disable-gpgconf"
+ at item disable-gpgconf
 Using this feature with any @var{value} disables the detection of the
 gpgconf program and thus forces GPGME to fallback into the simple
 OpenPGP only mode.  It may be used to force the use of GnuPG-1 on
@@ -691,8 +691,8 @@ systems which have both GPG versions installed.  Note that in general
 the use of @code{gpgme_set_engine_info} is a better way to select a
 specific engine version.
 
- at item "gpgconf-name"
- at itemx "gpg-name"
+ at item gpgconf-name
+ at itemx gpg-name
 Set the name of the gpgconf respective gpg binary.  The defaults are
 @code{GNU/GnuPG/gpgconf} and @code{GNU/GnuPG/gpg}.  Under Unix the
 leading directory part is ignored.  Under Windows the leading
@@ -700,7 +700,13 @@ directory part is used as the default installation directory; the
 @code{.exe} suffix is added by GPGME.  Use forward slashed even under
 Windows.
 
- at item "w32-inst-dir"
+ at item require-gnupg
+Set the mimimum version of the required GnuPG engine.  If that version
+is not met, GPGME fails early instead of trying to use the existant
+version.  The given version must be a string with major, minor, and
+micro number.  Example: "2.1.0".
+
+ at item w32-inst-dir
 On Windows GPGME needs to know its installation directory to find its
 spawn helper.  This is in general no problem because a DLL has this
 information.  Some applications however link statically to GPGME and
diff --git a/src/engine.c b/src/engine.c
index a7c016f..f428034 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -63,6 +63,10 @@ static struct engine_ops *engine_ops[] =
 static gpgme_engine_info_t engine_info;
 DEFINE_STATIC_LOCK (engine_info_lock);
 
+/* If non-NULL, the minimal version required for all engines.  */
+static char *engine_minimal_version;
+
+
 

 /* Get the file name of the engine for PROTOCOL.  */
 static const char *
@@ -178,6 +182,26 @@ _gpgme_engine_info_release (gpgme_engine_info_t info)
 }
 
 
+/* This is an internal function to set a mimimal required version.
+ * This function must only be called by gpgme_set_global_flag.
+ * Returns 0 on success.  */
+int
+_gpgme_set_engine_minimal_version (const char *value)
+{
+  free (engine_minimal_version);
+  if (value)
+    {
+      engine_minimal_version = strdup (value);
+      return !engine_minimal_version;
+    }
+  else
+    {
+      engine_minimal_version = NULL;
+      return 0;
+    }
+}
+
+
 /* Get the information about the configured and installed engines.  A
    pointer to the first engine in the statically allocated linked list
    is returned in *INFO.  If an error occurs, it is returned.  The
@@ -229,6 +253,17 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
           if (!*lastp && !err)
             err = gpg_error_from_syserror ();
 
+          /* Check against the optional minimal engine version.  */
+          if (!err && version && engine_minimal_version
+              && !_gpgme_compare_versions (version, engine_minimal_version))
+            {
+#if GPG_ERROR_VERSION_NUMBER < 0x011900 /* 1.25 */
+              err = gpg_error (GPG_ERR_NO_ENGINE);
+#else
+              err = gpg_error (GPG_ERR_ENGINE_TOO_OLD);
+#endif
+            }
+
           /* Now set the dummy version for pseudo engines.  */
           if (!err && !version)
             {
diff --git a/src/engine.h b/src/engine.h
index 238a21c..b713d96 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -38,6 +38,8 @@ typedef gpgme_error_t (*engine_command_handler_t) (void *priv,
 typedef gpgme_error_t (*engine_assuan_result_cb_t) (void *priv,
                                                     gpgme_error_t result);
 
+/* Helper for gpgme_set_global_flag.  */
+int _gpgme_set_engine_minimal_version (const char *value);
 
 /* Get a deep copy of the engine info and return it in INFO.  */
 gpgme_error_t _gpgme_engine_info_copy (gpgme_engine_info_t *r_info);
diff --git a/src/gpgme.c b/src/gpgme.c
index e0cd9b0..d59f808 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -71,6 +71,8 @@ gpgme_set_global_flag (const char *name, const char *value)
       _gpgme_dirinfo_disable_gpgconf ();
       return 0;
     }
+  else if (!strcmp (name, "require-gnupg"))
+    return _gpgme_set_engine_minimal_version (value);
   else if (!strcmp (name, "gpgconf-name"))
     return _gpgme_set_default_gpgconf_name (value);
   else if (!strcmp (name, "gpg-name"))
diff --git a/tests/run-keylist.c b/tests/run-keylist.c
index fc0f066..cc4c354 100644
--- a/tests/run-keylist.c
+++ b/tests/run-keylist.c
@@ -54,6 +54,7 @@ show_usage (int ex)
          "  --validate       use GPGME_KEYLIST_MODE_VALIDATE\n"
          "  --import         import all keys\n"
          "  --offline        use offline mode\n"
+         "  --require-gnupg  required at least the given GnuPG version\n"
          , stderr);
   exit (ex);
 }
@@ -149,9 +150,16 @@ main (int argc, char **argv)
           offline = 1;
           argc--; argv++;
         }
+      else if (!strcmp (*argv, "--require-gnupg"))
+        {
+          argc--; argv++;
+          if (!argc)
+            show_usage (1);
+          gpgme_set_global_flag ("require-gnupg", *argv);
+          argc--; argv++;
+        }
       else if (!strncmp (*argv, "--", 2))
         show_usage (1);
-
     }
 
   if (argc > 1)

commit b7b0e7b5bfefd51c8092ea54f262b18aebf78128
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Aug 16 18:49:11 2016 +0200

    core: Simplify setting of dummy versions.
    
    * src/engine.c (_gpgme_engine_info_release): Do not assert but free
    FILE_NAME.
    (gpgme_get_engine_info): Provide default for VERSION and REQ_VERSION.
    Use calloc instead of malloc.
    (_gpgme_set_engine_info): Ditto.
    * src/engine-assuan.c (llass_get_version): Return NULL.
    (llass_get_req_version): Ditto.
    * src/engine-spawn.c (engspawn_get_version): Ditto.
    (engspawn_get_req_version): Ditto.
    * src/engine-uiserver.c (uiserver_get_version): Ditto.
    (uiserver_get_req_version): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/engine-assuan.c b/src/engine-assuan.c
index 681be62..c4a84a3 100644
--- a/src/engine-assuan.c
+++ b/src/engine-assuan.c
@@ -131,14 +131,14 @@ llass_get_home_dir (void)
 static char *
 llass_get_version (const char *file_name)
 {
-  return strdup ("1.0.0");
+  return NULL;
 }
 
 
 static const char *
 llass_get_req_version (void)
 {
-  return "1.0.0";
+  return NULL;
 }
 
 

diff --git a/src/engine-spawn.c b/src/engine-spawn.c
index c01b50e..e2ee8ba 100644
--- a/src/engine-spawn.c
+++ b/src/engine-spawn.c
@@ -312,14 +312,14 @@ static char *
 engspawn_get_version (const char *file_name)
 {
   (void)file_name;
-  return strdup ("1.0.0");
+  return NULL;
 }
 
 
 static const char *
 engspawn_get_req_version (void)
 {
-  return "1.0.0";
+  return NULL;
 }
 
 
diff --git a/src/engine-uiserver.c b/src/engine-uiserver.c
index 1869ff3..de12f2b 100644
--- a/src/engine-uiserver.c
+++ b/src/engine-uiserver.c
@@ -123,14 +123,15 @@ static void uiserver_io_event (void *engine,
 static char *
 uiserver_get_version (const char *file_name)
 {
-  return strdup ("1.0.0");
+  (void)file_name;
+  return NULL;
 }
 
 
 static const char *
 uiserver_get_req_version (void)
 {
-  return "1.0.0";
+  return NULL;
 }
 
 

diff --git a/src/engine.c b/src/engine.c
index 4e59ada..a7c016f 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -93,7 +93,8 @@ engine_get_home_dir (gpgme_protocol_t proto)
 
 
 /* Get a malloced string containing the version number of the engine
-   for PROTOCOL.  */
+ * for PROTOCOL.  If this function returns NULL for a valid protocol,
+ * it should be assumed that the engine is a pseudo engine. */
 static char *
 engine_get_version (gpgme_protocol_t proto, const char *file_name)
 {
@@ -107,7 +108,8 @@ engine_get_version (gpgme_protocol_t proto, const char *file_name)
 }
 
 
-/* Get the required version number of the engine for PROTOCOL.  */
+/* Get the required version number of the engine for PROTOCOL.  This
+ * may be NULL. */
 static const char *
 engine_get_req_version (gpgme_protocol_t proto)
 {
@@ -164,8 +166,8 @@ _gpgme_engine_info_release (gpgme_engine_info_t info)
     {
       gpgme_engine_info_t next_info = info->next;
 
-      assert (info->file_name);
-      free (info->file_name);
+      if (info->file_name)
+        free (info->file_name);
       if (info->home_dir)
 	free (info->home_dir);
       if (info->version)
@@ -203,6 +205,7 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
 	{
 	  const char *ofile_name = engine_get_file_name (proto_list[proto]);
 	  const char *ohome_dir  = engine_get_home_dir (proto_list[proto]);
+          char *version = engine_get_version (proto_list[proto], NULL);
 	  char *file_name;
 	  char *home_dir;
 
@@ -222,10 +225,18 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
           else
             home_dir = NULL;
 
-	  *lastp = malloc (sizeof (*engine_info));
+	  *lastp = calloc (1, sizeof (*engine_info));
           if (!*lastp && !err)
             err = gpg_error_from_syserror ();
 
+          /* Now set the dummy version for pseudo engines.  */
+          if (!err && !version)
+            {
+              version = strdup ("1.0.0");
+              if (!version)
+                err = gpg_error_from_syserror ();
+            }
+
 	  if (err)
 	    {
 	      _gpgme_engine_info_release (engine_info);
@@ -235,6 +246,8 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
 		free (file_name);
 	      if (home_dir)
 		free (home_dir);
+	      if (version)
+		free (version);
 
 	      UNLOCK (engine_info_lock);
 	      return err;
@@ -243,8 +256,10 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
 	  (*lastp)->protocol = proto_list[proto];
 	  (*lastp)->file_name = file_name;
 	  (*lastp)->home_dir = home_dir;
-	  (*lastp)->version = engine_get_version (proto_list[proto], NULL);
+	  (*lastp)->version = version;
 	  (*lastp)->req_version = engine_get_req_version (proto_list[proto]);
+	  if (!(*lastp)->req_version)
+            (*lastp)->req_version = "1.0.0"; /* Dummy for pseudo engines. */
 	  (*lastp)->next = NULL;
 	  lastp = &(*lastp)->next;
 	}
@@ -353,6 +368,7 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
 {
   char *new_file_name;
   char *new_home_dir;
+  char *new_version;
 
   /* FIXME: Use some PROTO_MAX definition.  */
   if (proto > DIM (engine_ops))
@@ -401,6 +417,17 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
         new_home_dir = NULL;
     }
 
+  new_version = engine_get_version (proto, new_file_name);
+  if (!new_version)
+    {
+      new_version = strdup ("1.0.0"); /* Fake one for dummy entries.  */
+      if (!new_version)
+        {
+          free (new_file_name);
+          free (new_home_dir);
+        }
+    }
+
   /* Remove the old members.  */
   assert (info->file_name);
   free (info->file_name);
@@ -412,7 +439,7 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
   /* Install the new members.  */
   info->file_name = new_file_name;
   info->home_dir = new_home_dir;
-  info->version = engine_get_version (proto, new_file_name);
+  info->version = new_version;
 
   return 0;
 }
diff --git a/src/version.c b/src/version.c
index 15e5aee..e2f1c35 100644
--- a/src/version.c
+++ b/src/version.c
@@ -124,7 +124,7 @@ parse_version_number (const char *str, int *number)
 /* Parse the version string STR in the format MAJOR.MINOR.MICRO (for
    example, 9.3.2) and return the components in MAJOR, MINOR and MICRO
    as integers.  The function returns the tail of the string that
-   follows the version number.  This might be te empty string if there
+   follows the version number.  This might be the empty string if there
    is nothing following the version number, or a patchlevel.  The
    function returns NULL if the version string is not valid.  */
 static const char *

-----------------------------------------------------------------------

Summary of changes:
 NEWS                  |  2 ++
 doc/gpgme.texi        | 16 +++++++----
 src/engine-assuan.c   |  4 +--
 src/engine-spawn.c    |  4 +--
 src/engine-uiserver.c |  5 ++--
 src/engine.c          | 76 ++++++++++++++++++++++++++++++++++++++++++++++-----
 src/engine.h          |  2 ++
 src/gpgme.c           |  2 ++
 src/version.c         |  2 +-
 tests/run-keylist.c   | 10 ++++++-
 10 files changed, 103 insertions(+), 20 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list