1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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.
This commit is contained in:
Werner Koch 2024-03-18 11:14:19 +01:00
parent 122803bf1a
commit 759adb2493
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -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)