aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2022-08-02 10:25:23 +0000
committerWerner Koch <[email protected]>2022-08-02 10:25:23 +0000
commit6bc959231802d60694b7677d3537261d9cda1e1d (patch)
tree08697025659274431ebdec3599d36d66cf0f5d0c
parentgpg: For de-vs use SHA-256 instead of SHA-1 as implicit preference. (diff)
downloadgnupg-6bc959231802d60694b7677d3537261d9cda1e1d.tar.gz
gnupg-6bc959231802d60694b7677d3537261d9cda1e1d.zip
gpgconf: Improve registry dumping.
* common/w32-reg.c (read_w32_registry_string): Map REG_DWORD to a string. (read_w32_reg_string): Add arg r_hklm_fallback and change all callers. (show_configs): Indicate whether the HKLM fallback was used. * tools/gpgconf.c (show_other_registry_entries): Fix the Outlook Addin Registry key. Indicate whether the HKLM fallback was used.
-rw-r--r--common/t-w32-reg.c4
-rw-r--r--common/w32-reg.c33
-rw-r--r--common/w32help.h2
-rw-r--r--tools/gpgconf.c20
4 files changed, 44 insertions, 15 deletions
diff --git a/common/t-w32-reg.c b/common/t-w32-reg.c
index 9665003ea..1a44e385c 100644
--- a/common/t-w32-reg.c
+++ b/common/t-w32-reg.c
@@ -56,7 +56,7 @@ test_read_registry (void)
string2 = read_w32_reg_string
("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion"
- "\\Internet Settings:User Agent");
+ "\\Internet Settings:User Agent", NULL);
if (!string2)
fail (1);
fprintf (stderr, "User agent: %s\n", string2);
@@ -76,7 +76,7 @@ main (int argc, char **argv)
{
if (argc > 1)
{
- char *string = read_w32_reg_string (argv[1]);
+ char *string = read_w32_reg_string (argv[1], NULL);
printf ("%s -> %s\n", argv[1], string? string : "(null)");
xfree (string);
}
diff --git a/common/w32-reg.c b/common/w32-reg.c
index 816531fd5..cbaba5696 100644
--- a/common/w32-reg.c
+++ b/common/w32-reg.c
@@ -229,6 +229,19 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
xfree (tmp);
}
}
+ else if (type == REG_DWORD && nbytes == sizeof (DWORD))
+ {
+ char *tmp;
+ DWORD dummy;
+
+ memcpy (&dummy, result, nbytes);
+ tmp = xtryasprintf ("%u", (unsigned int)dummy);
+ if (tmp)
+ {
+ xfree (result);
+ result = tmp;
+ }
+ }
leave:
RegCloseKey (key_handle);
@@ -250,14 +263,19 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
*
* Note that the first backslash and the first colon act as delimiters.
*
- * Returns a malloced string or NULL if not found.
+ * Returns a malloced string or NULL if not found. If R_HKLM_FALLBACK
+ * is not NULL, no class was given, and the result came from HKLM,
+ * true is stored there.
*/
char *
-read_w32_reg_string (const char *key_arg)
+read_w32_reg_string (const char *key_arg, int *r_hklm_fallback)
{
char *key;
char *p1, *p2;
- char *result;
+ char *result, *result2;
+
+ if (r_hklm_fallback)
+ *r_hklm_fallback = 0;
if (!key_arg)
return NULL;
@@ -280,6 +298,15 @@ read_w32_reg_string (const char *key_arg)
*p2++ = 0;
result = read_w32_registry_string (*key? key : NULL, p1, p2);
+ if (result && !*key && r_hklm_fallback)
+ {
+ /* No key given - see whether the result came from HKCU or HKLM. */
+ result2 = read_w32_registry_string ("HKCU", p1, p2);
+ if (result2)
+ xfree (result2);
+ else
+ *r_hklm_fallback = 1;
+ }
xfree (key);
return result;
}
diff --git a/common/w32help.h b/common/w32help.h
index a79081f8e..54e92675b 100644
--- a/common/w32help.h
+++ b/common/w32help.h
@@ -44,7 +44,7 @@ char **w32_parse_commandline (char *cmdline, int globing, int *r_argv,
/*-- w32-reg.c --*/
char *read_w32_registry_string (const char *root,
const char *dir, const char *name );
-char *read_w32_reg_string (const char *key);
+char *read_w32_reg_string (const char *key, int *r_hklm_fallback);
/* Other stuff. */
#ifdef HAVE_W32CE_SYSTEM
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index 13066297e..0fad39a4c 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -1320,7 +1320,7 @@ show_other_registry_entries (estream_t outfp)
{ 1, "HKLM\\Software\\Gpg4win:VS-Desktop-Version" },
{ 1, "\\" GNUPG_REGISTRY_DIR ":HomeDir" },
{ 1, "\\" GNUPG_REGISTRY_DIR ":DefaultLogFile" },
- { 2, "Software\\Microsoft\\Office\\Outlook\\Addins\\GNU.GpgOL"
+ { 2, "\\Software\\Microsoft\\Office\\Outlook\\Addins\\GNU.GpgOL"
":LoadBehavior" },
{ 2, "HKCU\\Software\\Microsoft\\Office\\16.0\\Outlook\\Options\\Mail:"
"ReadAsPlain" },
@@ -1352,6 +1352,7 @@ show_other_registry_entries (estream_t outfp)
int group = 0;
char *namebuf = NULL;
const char *name;
+ int from_hklm;
for (idx=0; (name = names[idx].name); idx++)
{
@@ -1365,7 +1366,7 @@ show_other_registry_entries (estream_t outfp)
name = namebuf;
}
- value = read_w32_reg_string (name);
+ value = read_w32_reg_string (name, &from_hklm);
if (!value)
continue;
@@ -1380,12 +1381,11 @@ show_other_registry_entries (estream_t outfp)
}
if (group == 3)
- es_fprintf (outfp, "### %s=%s\n", names[idx].name, value);
+ es_fprintf (outfp, "### %s=%s%s\n", names[idx].name, value,
+ from_hklm? " [hklm]":"");
else
- es_fprintf (outfp, "### %s\n### ->%s<-\n", name, value);
-
- /* FIXME: We may want to add an indiction whethe found via HKLM
- * or HKCU. */
+ es_fprintf (outfp, "### %s\n### ->%s<-%s\n", name, value,
+ from_hklm? " [hklm]":"");
xfree (value);
}
@@ -1474,14 +1474,16 @@ show_configs (estream_t outfp)
if ((sl->flags & 1))
{
char *p;
+ int from_hklm;
if (!any)
{
any = 1;
es_fprintf (outfp, "###\n### Encountered in config files:\n");
}
- if ((p = read_w32_reg_string (sl->d)))
- es_fprintf (outfp, "### %s ->%s<-\n", sl->d, p);
+ if ((p = read_w32_reg_string (sl->d, &from_hklm)))
+ es_fprintf (outfp, "### %s ->%s<-%s\n", sl->d, p,
+ from_hklm? " [hklm]":"");
else
es_fprintf (outfp, "### %s [not set]\n", sl->d);
xfree (p);