1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-10 23:49:50 +02: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 82b39fe254
commit 5ccfc2101a
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -247,10 +247,10 @@ gpgconf_write_status (int no, const char *format, ...)
static void static void
list_dirs (estream_t fp, char **names, int special) list_dirs (estream_t fp, char **names, int show_config_mode)
{ {
static struct { static struct {
const char *name; const char *name; /* If NULL only a file check will be done. */
const char *(*fnc)(void); const char *(*fnc)(void);
const char *extra; const char *extra;
} list[] = { } list[] = {
@ -266,12 +266,13 @@ list_dirs (estream_t fp, char **names, int special)
{ "agent-extra-socket", gnupg_socketdir, GPG_AGENT_EXTRA_SOCK_NAME }, { "agent-extra-socket", gnupg_socketdir, GPG_AGENT_EXTRA_SOCK_NAME },
{ "agent-browser-socket",gnupg_socketdir, GPG_AGENT_BROWSER_SOCK_NAME }, { "agent-browser-socket",gnupg_socketdir, GPG_AGENT_BROWSER_SOCK_NAME },
{ "agent-socket", gnupg_socketdir, GPG_AGENT_SOCK_NAME }, { "agent-socket", gnupg_socketdir, GPG_AGENT_SOCK_NAME },
{ NULL, gnupg_socketdir, "S.uiserver" },
{ "homedir", gnupg_homedir, NULL } { "homedir", gnupg_homedir, NULL }
}; };
int idx, j; int idx, j;
char *tmp; char *tmp;
const char *s; const char *s;
gpg_error_t err;
for (idx = 0; idx < DIM (list); idx++) for (idx = 0; idx < DIM (list); idx++)
{ {
@ -283,7 +284,10 @@ list_dirs (estream_t fp, char **names, int special)
} }
else else
tmp = NULL; tmp = NULL;
if (!names)
if (!list[idx].name)
;
else if (!names)
es_fprintf (fp, "%s:%s\n", list[idx].name, gc_percent_escape (s)); es_fprintf (fp, "%s:%s\n", list[idx].name, gc_percent_escape (s));
else else
{ {
@ -295,6 +299,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); xfree (tmp);
} }
@ -325,7 +346,7 @@ list_dirs (estream_t fp, char **names, int special)
} }
es_fflush (fp); es_fflush (fp);
if (special) if (show_config_mode)
es_fprintf (fp, "\n" es_fprintf (fp, "\n"
"### Note: homedir taken from registry key %s%s\\%s:%s\n" "### Note: homedir taken from registry key %s%s\\%s:%s\n"
"\n", "\n",
@ -343,7 +364,7 @@ list_dirs (estream_t fp, char **names, int special)
{ {
xfree (tmp); xfree (tmp);
es_fflush (fp); es_fflush (fp);
if (special) if (show_config_mode)
es_fprintf (fp, "\n" es_fprintf (fp, "\n"
"### Note: registry key %s without value in HKCU or HKLM\n" "### Note: registry key %s without value in HKCU or HKLM\n"
"\n", GNUPG_REGISTRY_DIR); "\n", GNUPG_REGISTRY_DIR);
@ -353,7 +374,7 @@ list_dirs (estream_t fp, char **names, int special)
} }
#else /*!HAVE_W32_SYSTEM*/ #else /*!HAVE_W32_SYSTEM*/
(void)special; (void)show_config_mode;
#endif /*!HAVE_W32_SYSTEM*/ #endif /*!HAVE_W32_SYSTEM*/
} }
@ -1235,7 +1256,7 @@ show_versions (estream_t fp)
/* Copy data from file SRC to DST. Returns 0 on success or an error /* 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 * 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. */ * indicates a registry entry. */
static gpg_error_t static gpg_error_t
my_copy_file (estream_t src, estream_t dst, strlist_t *listp) my_copy_file (estream_t src, estream_t dst, strlist_t *listp)