core, w32: Add w64 handling for regkeys
authorAndre Heinecke <aheinecke@intevation.de>
Thu, 17 May 2018 15:41:53 +0000 (17:41 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Thu, 17 May 2018 15:46:12 +0000 (17:46 +0200)
* src/w32-util.c (_gpgme_get_gpg_path): Use new defines.
(GNUPG_REGKEY_2): x64 aware regkey as used by GnuPG in Gpg4win 2.x
(GNUPG_REGKEY_3): x64 aware regkey as used by GnuPG in Gpg4win 3.x
(_gpgme_get_gpgconf_path): Use new regkeys. Add another fallback.

--
This should fix more "unsupported protocol" issues if Gpg4win /
GnuPG is installed in a non standard path on 64bit systems.

The regkey handling is similar to that of gpgex and gpgol.

GnuPG-Bug-Id: T3988

src/w32-util.c

index 5b02c7e..30dd081 100644 (file)
 # define F_OK 0
 #endif
 
+/* The Registry key used by GNUPG.  */
+#ifdef _WIN64
+# define GNUPG_REGKEY_2  "Software\\Wow6432Node\\GNU\\GnuPG"
+#else
+# define GNUPG_REGKEY_2  "Software\\GNU\\GnuPG"
+#endif
+#ifdef _WIN64
+# define GNUPG_REGKEY_3  "Software\\Wow6432Node\\GnuPG"
+#else
+# define GNUPG_REGKEY_3  "Software\\GnuPG"
+#endif
 
 DEFINE_STATIC_LOCK (get_path_lock);
 
@@ -513,7 +524,7 @@ _gpgme_get_gpg_path (void)
       char *dir;
 
       dir = read_w32_registry_string ("HKEY_LOCAL_MACHINE",
-                                      "Software\\GNU\\GnuPG",
+                                      GNUPG_REGKEY_2,
                                       "Install Directory");
       if (dir)
         {
@@ -568,12 +579,12 @@ _gpgme_get_gpgconf_path (void)
       char *dir;
 
       dir = read_w32_registry_string (NULL,
-                                      "Software\\GNU\\GnuPG",
+                                      GNUPG_REGKEY_2,
                                       "Install Directory");
       if (!dir)
         {
           char *tmp = read_w32_registry_string (NULL,
-                                                "Software\\GnuPG",
+                                                GNUPG_REGKEY_3,
                                                 "Install Directory");
           if (tmp)
             {
@@ -596,6 +607,14 @@ _gpgme_get_gpgconf_path (void)
       gpgconf = find_program_at_standard_place ("GNU\\GnuPG\\gpgconf.exe");
     }
 
+  /* 5. Try to find gpgconf.exe relative to us.  */
+  if (!gpgconf && inst_dir)
+    {
+      char *dir = _gpgme_strconcat (inst_dir, "\\..\\..\\GnuPG\\bin");
+      gpgconf = find_program_in_dir (dir, name);
+      free (dir);
+    }
+
   /* 5. Print a debug message if not found.  */
   if (!gpgconf)
     _gpgme_debug (DEBUG_ENGINE, "_gpgme_get_gpgconf_path: '%s' not found",name);