summaryrefslogtreecommitdiffstats
path: root/tools/gpgconf.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2024-03-18 11:14:19 +0100
committerWerner Koch <wk@gnupg.org>2024-03-18 11:14:19 +0100
commit759adb249310abff30e707c0800c9910de97a6dd (patch)
tree321f81b4c31cf7dd24451d810c5269a6b4457281 /tools/gpgconf.c
parentgpg: Make sure a DECRYPTION_OKAY is never issued for a bad OCB tag. (diff)
downloadgnupg2-759adb249310abff30e707c0800c9910de97a6dd.tar.xz
gnupg2-759adb249310abff30e707c0800c9910de97a6dd.zip
gpgconf: Check readability of some files with -X
* tools/gpgconf.c (list_dirs): Rename arg from special to show_config_mode. Add "S.Uiserver" test and test existsing files for readability.
Diffstat (limited to 'tools/gpgconf.c')
-rw-r--r--tools/gpgconf.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index 6a5add42b..0515aa807 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -260,10 +260,10 @@ gpgconf_write_status (int no, const char *format, ...)
static void
-list_dirs (estream_t fp, char **names, int special)
+list_dirs (estream_t fp, char **names, int show_config_mode)
{
static struct {
- const char *name;
+ const char *name; /* If NULL only a file check will be done. */
const char *(*fnc)(void);
const char *extra;
} list[] = {
@@ -280,12 +280,13 @@ list_dirs (estream_t fp, char **names, int special)
{ "agent-extra-socket", gnupg_socketdir, GPG_AGENT_EXTRA_SOCK_NAME },
{ "agent-browser-socket",gnupg_socketdir, GPG_AGENT_BROWSER_SOCK_NAME },
{ "agent-socket", gnupg_socketdir, GPG_AGENT_SOCK_NAME },
+ { NULL, gnupg_socketdir, "S.uiserver" },
{ "homedir", gnupg_homedir, NULL }
};
int idx, j;
char *tmp;
const char *s;
-
+ gpg_error_t err;
for (idx = 0; idx < DIM (list); idx++)
{
@@ -297,7 +298,10 @@ list_dirs (estream_t fp, char **names, int special)
}
else
tmp = NULL;
- if (!names)
+
+ if (!list[idx].name)
+ ;
+ else if (!names)
es_fprintf (fp, "%s:%s\n", list[idx].name, gc_percent_escape (s));
else
{
@@ -309,6 +313,23 @@ list_dirs (estream_t fp, char **names, int special)
}
}
+ /* In show config mode check that the socket files are accessible. */
+ if (list[idx].extra && show_config_mode)
+ {
+ estream_t tmpfp;
+
+ tmpfp = es_fopen (s, "rb");
+ if (tmpfp)
+ es_fclose (tmpfp); /* All fine - we can read that file. */
+ else if ((err=gpg_error_from_syserror ()) == GPG_ERR_ENOENT
+ || err == GPG_ERR_ENXIO)
+ ; /* No such file/ No such device or address - this is okay. */
+ else
+ es_fprintf (fp,
+ "### Warning: error reading existing file '%s': %s\n",
+ s, gpg_strerror (err));
+ }
+
xfree (tmp);
}
@@ -339,7 +360,7 @@ list_dirs (estream_t fp, char **names, int special)
}
es_fflush (fp);
- if (special)
+ if (show_config_mode)
es_fprintf (fp, "\n"
"### Note: homedir taken from registry key %s%s\\%s:%s\n"
"\n",
@@ -357,7 +378,7 @@ list_dirs (estream_t fp, char **names, int special)
{
xfree (tmp);
es_fflush (fp);
- if (special)
+ if (show_config_mode)
es_fprintf (fp, "\n"
"### Note: registry %s without value in HKCU or HKLM\n"
"\n", GNUPG_REGISTRY_DIR);
@@ -367,7 +388,7 @@ list_dirs (estream_t fp, char **names, int special)
}
#else /*!HAVE_W32_SYSTEM*/
- (void)special;
+ (void)show_config_mode;
#endif /*!HAVE_W32_SYSTEM*/
}
@@ -1342,7 +1363,7 @@ show_versions (estream_t fp)
/* Copy data from file SRC to DST. Returns 0 on success or an error
* code on failure. If LISTP is not NULL, that strlist is updated
- * with the variabale or registry key names detected. Flag bit 0
+ * with the variable or registry key names detected. Flag bit 0
* indicates a registry entry. */
static gpg_error_t
my_copy_file (estream_t src, estream_t dst, strlist_t *listp)