diff options
Diffstat (limited to 'tools/gpgconf.c')
-rw-r--r-- | tools/gpgconf.c | 163 |
1 files changed, 144 insertions, 19 deletions
diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 80a4062..1b3f2be 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -46,6 +46,12 @@ enum cmd_and_opt_values oRuntime = 'r', oComponent = 'c', oNull = '0', + aListDirs = 'L', + aKill = 'K', + aReload = 'R', + aShowVersions = 'V', + aShowConfigs = 'X', + oNoVerbose = 500, oHomedir, oBuilddir, @@ -61,15 +67,10 @@ enum cmd_and_opt_values aListConfig, aCheckConfig, aQuerySWDB, - aListDirs, aLaunch, - aKill, aCreateSocketDir, aRemoveSocketDir, - aApplyProfile, - aReload, - aShowConfigs, - aShowVersions + aApplyProfile }; @@ -100,8 +101,8 @@ static ARGPARSE_OPTS opts[] = { aKill, "kill", 256, N_("kill a given component")}, { aCreateSocketDir, "create-socketdir", 256, "@"}, { aRemoveSocketDir, "remove-socketdir", 256, "@"}, - ARGPARSE_c (aShowVersions, "show-versions", "@"), - ARGPARSE_c (aShowConfigs, "show-configs", "@"), + ARGPARSE_c (aShowVersions, "show-versions", ""), + ARGPARSE_c (aShowConfigs, "show-configs", ""), { 301, NULL, 0, N_("@\nOptions:\n ") }, @@ -608,7 +609,7 @@ main (int argc, char **argv) early_system_init (); gnupg_reopen_std (GPGCONF_NAME); set_strusage (my_strusage); - log_set_prefix (GPGCONF_NAME, GPGRT_LOG_WITH_PREFIX); + log_set_prefix (GPGCONF_NAME, GPGRT_LOG_WITH_PREFIX|GPGRT_LOG_NO_REGISTRY); /* Make sure that our subsystems are ready. */ i18n_init(); @@ -678,6 +679,12 @@ main (int argc, char **argv) fname = argc ? *argv : NULL; + /* Set the configuraton directories for use by gpgrt_argparser. We + * don't have a configuration file for this program but we have code + * which reads the component's config files. */ + gnupg_set_confdir (GNUPG_CONFDIR_SYS, gnupg_sysconfdir ()); + gnupg_set_confdir (GNUPG_CONFDIR_USER, gnupg_homedir ()); + switch (cmd) { case aListComponents: @@ -1035,8 +1042,43 @@ get_revision_from_blurb (const char *blurb, int *r_len) static void show_version_gnupg (estream_t fp, const char *prefix) { + char *fname, *p; + size_t n; + estream_t verfp; + char line[100]; + es_fprintf (fp, "%s%sGnuPG %s (%s)\n%s%s\n", prefix, *prefix?"":"* ", - strusage (13), BUILD_REVISION, prefix, gpgrt_strusage (17)); + strusage (13), BUILD_REVISION, prefix, strusage (17)); + + /* Show the GnuPG VS-Desktop version in --show-configs mode */ + if (prefix && *prefix == '#') + { + fname = make_filename (gnupg_bindir (), NULL); + n = strlen (fname); + if (n > 10 && (!ascii_strcasecmp (fname + n - 10, "/GnuPG/bin") + || !ascii_strcasecmp (fname + n - 10, "\\GnuPG\\bin"))) + { + /* Append VERSION to the ../../ direcory. Note that VERSION + * is only 7 bytes and thus fits. */ + strcpy (fname + n - 9, "VERSION"); + verfp = es_fopen (fname, "r"); + if (!verfp) + es_fprintf (fp, "%s[VERSION file not found]\n", prefix); + else if (!es_fgets (line, sizeof line, verfp)) + es_fprintf (fp, "%s[VERSION file is empty]\n", prefix); + else + { + trim_spaces (line); + for (p=line; *p; p++) + if (*p < ' ' || *p > '~' || *p == '[') + *p = '?'; + es_fprintf (fp, "%s%s\n", prefix, line); + } + es_fclose (verfp); + } + xfree (fname); + } + #ifdef HAVE_W32_SYSTEM { OSVERSIONINFO osvi = { sizeof (osvi) }; @@ -1277,7 +1319,8 @@ show_other_registry_entries (estream_t outfp) { 1, "HKLM\\Software\\Gpg4win:Desktop-Version" }, { 1, "HKLM\\Software\\Gpg4win:VS-Desktop-Version" }, { 1, "\\" GNUPG_REGISTRY_DIR ":HomeDir" }, - { 2, "Software\\Microsoft\\Office\\Outlook\\Addins\\GNU.GpgOL" + { 1, "\\" GNUPG_REGISTRY_DIR ":DefaultLogFile" }, + { 2, "\\Software\\Microsoft\\Office\\Outlook\\Addins\\GNU.GpgOL" ":LoadBehavior" }, { 2, "HKCU\\Software\\Microsoft\\Office\\16.0\\Outlook\\Options\\Mail:" "ReadAsPlain" }, @@ -1309,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++) { @@ -1322,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; @@ -1337,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); } @@ -1350,8 +1393,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) @@ -1374,6 +1487,15 @@ show_configs (estream_t outfp) show_version_gnupg (outfp, "### "); es_fprintf (outfp, "### Libgcrypt %s\n", gcry_check_version (NULL)); es_fprintf (outfp, "### GpgRT %s\n", gpg_error_check_version (NULL)); +#ifdef HAVE_W32_SYSTEM + es_fprintf (outfp, "### Codepages:"); + if (GetConsoleCP () != GetConsoleOutputCP ()) + es_fprintf (outfp, " %u/%u", GetConsoleCP (), GetConsoleOutputCP ()); + else + es_fprintf (outfp, " %u", GetConsoleCP ()); + es_fprintf (outfp, " %u", GetACP ()); + es_fprintf (outfp, " %u\n", GetOEMCP ()); +#endif es_fprintf (outfp, "###\n\n"); list_dirs (outfp, NULL, 1); @@ -1422,14 +1544,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); @@ -1438,6 +1562,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); |