diff options
author | Werner Koch <[email protected]> | 2022-08-03 07:26:44 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2022-08-03 07:31:44 +0000 |
commit | 5fb2306b97601c2021ecaab5d109c924a1608cce (patch) | |
tree | 8eabbe3196794961b1a7890b6950be0c4ca5c178 /tools/gpgconf.c | |
parent | g13: Remove unused variable. (diff) | |
download | gnupg-5fb2306b97601c2021ecaab5d109c924a1608cce.tar.gz gnupg-5fb2306b97601c2021ecaab5d109c924a1608cce.zip |
gpgconf: Add config file for Windows Registry dumps.
* tools/gpgconf.c (show_registry_entries_from_file): New.
(show_configs): Call it.
* doc/examples/gpgconf.rnames: New.
* doc/Makefile.am (examples): Add it.
Diffstat (limited to 'tools/gpgconf.c')
-rw-r--r-- | tools/gpgconf.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 7c5db792b..83ad947bb 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -1430,8 +1430,78 @@ show_other_registry_entries (estream_t outfp) es_fprintf (outfp, "###\n"); xfree (namebuf); } + + +/* Print registry entries take from a configuration file. */ +static void +show_registry_entries_from_file (estream_t outfp) +{ + gpg_error_t err; + char *fname; + estream_t fp; + char *line = NULL; + size_t length_of_line = 0; + size_t maxlen; + ssize_t len; + char *value = NULL; + int from_hklm; + int any = 0; + + fname = make_filename (gnupg_datadir (), "gpgconf.rnames", NULL); + fp = es_fopen (fname, "r"); + if (!fp) + { + err = gpg_error_from_syserror (); + if (gpg_err_code (err) != GPG_ERR_ENOENT) + log_error ("error opening '%s': %s\n", fname, gpg_strerror (err)); + goto leave; + } + + maxlen = 2048; /* Set limit. */ + while ((len = es_read_line (fp, &line, &length_of_line, &maxlen)) > 0) + { + if (!maxlen) + { + err = gpg_error (GPG_ERR_LINE_TOO_LONG); + log_error ("error reading '%s': %s\n", fname, gpg_strerror (err)); + goto leave; + } + trim_spaces (line); + if (*line == '#') + continue; + + xfree (value); + value = read_w32_reg_string (line, &from_hklm); + if (!value) + continue; + + if (!any) + { + any = 1; + es_fprintf (outfp, "### Taken from gpgconf.rnames:\n"); + } + + es_fprintf (outfp, "### %s\n### ->%s<-%s\n", line, value, + from_hklm? " [hklm]":""); + + } + if (len < 0 || es_ferror (fp)) + { + err = gpg_error_from_syserror (); + log_error ("error reading '%s': %s\n", fname, gpg_strerror (err)); + } + + leave: + if (any) + es_fprintf (outfp, "###\n"); + xfree (value); + xfree (line); + es_fclose (fp); + xfree (fname); +} #endif /*HAVE_W32_SYSTEM*/ + /* Show all config files. */ static void show_configs (estream_t outfp) @@ -1539,6 +1609,7 @@ show_configs (estream_t outfp) if (!any) es_fprintf (outfp, "###\n"); show_other_registry_entries (outfp); + show_registry_entries_from_file (outfp); #endif /*HAVE_W32_SYSTEM*/ free_strlist (list); |