summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2021-10-22 17:23:00 +0200
committerWerner Koch <wk@gnupg.org>2021-10-22 17:23:00 +0200
commit2a32501a561a5d70069bcb6e7e87fb949370520e (patch)
tree091750851d4e41e3bd5152112e7fd957f352d8fb
parenta3987e44970505a5540f9702c1e41292c22b69cf (diff)
downloadlibgpg-error-2a32501a561a5d70069bcb6e7e87fb949370520e.tar.gz
core: new internal function _gpgrt_w32_reg_get_string.
* src/w32-reg.c (_gpgrt_w32_reg_query_string): Allow abbreviated root names. (_gpgrt_w32_reg_get_string): New. -- This should eventually be made public. Noet that we have a copy in gnupg.
-rw-r--r--src/gpgrt-int.h1
-rw-r--r--src/w32-reg.c61
2 files changed, 56 insertions, 6 deletions
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index fde5ee4..8ca52c6 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -820,6 +820,7 @@ char *_gpgrt_absfnameconcat (const char *first_part,
char *_gpgrt_w32_reg_query_string (const char *root,
const char *dir,
const char *name);
+char *_gpgrt_w32_reg_get_string (const char *key);
#endif /*HAVE_W32_SYSTEM*/
diff --git a/src/w32-reg.c b/src/w32-reg.c
index 8b1bf8a..d1d2ca6 100644
--- a/src/w32-reg.c
+++ b/src/w32-reg.c
@@ -52,17 +52,17 @@ _gpgrt_w32_reg_query_string (const char *root, const char *dir,
if (!root)
root_key = HKEY_CURRENT_USER;
- else if (!strcmp( root, "HKEY_CLASSES_ROOT"))
+ else if (!strcmp (root, "HKEY_CLASSES_ROOT") || !strcmp (root, "HKCR"))
root_key = HKEY_CLASSES_ROOT;
- else if (!strcmp( root, "HKEY_CURRENT_USER"))
+ else if (!strcmp (root, "HKEY_CURRENT_USER") || !strcmp (root, "HKCU"))
root_key = HKEY_CURRENT_USER;
- else if (!strcmp( root, "HKEY_LOCAL_MACHINE"))
+ else if (!strcmp (root, "HKEY_LOCAL_MACHINE") || !strcmp (root, "HKLM"))
root_key = HKEY_LOCAL_MACHINE;
- else if (!strcmp( root, "HKEY_USERS"))
+ else if (!strcmp (root, "HKEY_USERS") || !strcmp (root, "HKU"))
root_key = HKEY_USERS;
- else if (!strcmp( root, "HKEY_PERFORMANCE_DATA"))
+ else if (!strcmp (root, "HKEY_PERFORMANCE_DATA"))
root_key = HKEY_PERFORMANCE_DATA;
- else if (!strcmp( root, "HKEY_CURRENT_CONFIG"))
+ else if (!strcmp (root, "HKEY_CURRENT_CONFIG") || !strcmp (root, "HKCC"))
root_key = HKEY_CURRENT_CONFIG;
else
return NULL;
@@ -152,3 +152,52 @@ _gpgrt_w32_reg_query_string (const char *root, const char *dir,
RegCloseKey (key_handle);
return result;
}
+
+
+/* Compact version of gpgrt_w32_reg_query_string. This version
+ * expects a single string as key described here using an example:
+ *
+ * HKCU\Software\GNU\GnuPG:HomeDir
+ *
+ * HKCU := the class, other supported classes are HKLM, HKCR, HKU, and
+ * HKCC. If no class is given and the string thus starts with
+ * a backslash HKCU with a fallback to HKLM is used.
+ * Software\GNU\GnuPG := The actual key.
+ * HomeDir := the name of the item. The name is optional to use the default
+ * value.
+ *
+ * Note that the first backslash and the first colon act as delimiters.
+ *
+ * Returns a malloced string or NULL if not found.
+ */
+char *
+_gpgrt_w32_reg_get_string (const char *key_arg)
+{
+ char *key;
+ char *p1, *p2;
+ char *result;
+
+ if (!key_arg)
+ return NULL;
+ key = xtrystrdup (key_arg);
+ if (!key)
+ {
+ _gpgrt_log_info ("warning: malloc failed while reading registry key\n");
+ return NULL;
+ }
+
+ p1 = strchr (key, '\\');
+ if (!p1)
+ {
+ xfree (key);
+ return NULL;
+ }
+ *p1++ = 0;
+ p2 = strchr (p1, ':');
+ if (p2)
+ *p2++ = 0;
+
+ result = _gpgrt_w32_reg_query_string (*key? key : NULL, p1, p2);
+ xfree (key);
+ return result;
+}