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

gpgconf: Enhance --list-dirs.

* tools/gpgconf.c (main) <aListDir>: Factor code out to ...
(list_dirs): new.  Rewrite to use a table.  Allow selection of a
items.  Add "agent-ssh-socket".
--

This change makes the use of gpgconf in scripts easier.  For example,
to set the envvar with the name of the socket used by ssh, it is now
possible to do this:

  SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"

which guarantees that the right name is used.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-07-11 13:05:37 +02:00
parent e32c575e0f
commit 7732b33288
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 64 additions and 40 deletions

View File

@ -815,7 +815,7 @@ it by adding this to your init script:
@example
unset SSH_AGENT_PID
if [ "$@{gnupg_SSH_AUTH_SOCK_by:-0@}" -ne $$ ]; then
export SSH_AUTH_SOCK="$@{HOME@}/.gnupg/S.gpg-agent.ssh"
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
@end example
@end cartouche

View File

@ -280,7 +280,7 @@ Check the options for the component @var{component}.
Update all configuration files with values taken from the global
configuration file (usually @file{/etc/gnupg/gpgconf.conf}).
@item --list-dirs
@item --list-dirs [@var{names}]
Lists the directories used by @command{gpgconf}. One directory is
listed per line, and each line consists of a colon-separated list where
the first field names the directory type (for example @code{sysconfdir})
@ -288,7 +288,9 @@ and the second field contains the percent-escaped directory. Although
they are not directories, the socket file names used by
@command{gpg-agent} and @command{dirmngr} are printed as well. Note
that the socket file names and the @code{homedir} lines are the default
names and they may be overridden by command line switches.
names and they may be overridden by command line switches. If
@var{names} are given only the directories or file names specified by
the list names are printed without any escaping.
@item --list-config [@var{filename}]
List the global configuration file in a colon separated format. If

View File

@ -147,6 +147,64 @@ get_outfp (estream_t *fp)
}
static void
list_dirs (estream_t fp, char **names)
{
static struct {
const char *name;
const char *(*fnc)(void);
const char *extra;
int special;
} list[] = {
{ "sysconfdir", gnupg_sysconfdir, NULL },
{ "bindir", gnupg_bindir, NULL },
{ "libexecdir", gnupg_libexecdir, NULL },
{ "libdir", gnupg_libdir, NULL },
{ "datadir", gnupg_datadir, NULL },
{ "localedir", gnupg_localedir, NULL },
{ "dirmngr-socket", dirmngr_user_socket_name, NULL, 1 },
{ "dirmngr-socket", dirmngr_sys_socket_name, NULL, 2 },
{ "dirmngr-sys-socket", dirmngr_sys_socket_name, NULL, 1 },
{ "agent-ssh-socket", gnupg_socketdir, GPG_AGENT_SSH_SOCK_NAME },
{ "agent-socket", gnupg_socketdir, GPG_AGENT_SOCK_NAME },
{ "homedir", gnupg_homedir, NULL }
};
int idx, j;
char *tmp;
const char *s;
for (idx = 0; idx < DIM (list); idx++)
{
if (list[idx].special == 1 && dirmngr_user_socket_name ())
;
else if (list[idx].special == 2 && !dirmngr_user_socket_name ())
;
else if (list[idx].special == 1 || list[idx].special == 2)
continue;
s = list[idx].fnc ();
if (list[idx].extra)
{
tmp = make_filename (s, list[idx].extra, NULL);
s = tmp;
}
else
tmp = NULL;
if (!names)
es_fprintf (fp, "%s:%s\n", list[idx].name, gc_percent_escape (s));
else
{
for (j=0; names[j]; j++)
if (!strcmp (names[j], list[idx].name))
es_fprintf (fp, "%s\n", s);
}
xfree (tmp);
}
}
/* gpgconf main. */
int
main (int argc, char **argv)
@ -357,43 +415,7 @@ main (int argc, char **argv)
case aListDirs:
/* Show the system configuration directories for gpgconf. */
get_outfp (&outfp);
es_fprintf (outfp, "sysconfdir:%s\n",
gc_percent_escape (gnupg_sysconfdir ()));
es_fprintf (outfp, "bindir:%s\n",
gc_percent_escape (gnupg_bindir ()));
es_fprintf (outfp, "libexecdir:%s\n",
gc_percent_escape (gnupg_libexecdir ()));
es_fprintf (outfp, "libdir:%s\n",
gc_percent_escape (gnupg_libdir ()));
es_fprintf (outfp, "datadir:%s\n",
gc_percent_escape (gnupg_datadir ()));
es_fprintf (outfp, "localedir:%s\n",
gc_percent_escape (gnupg_localedir ()));
if (dirmngr_user_socket_name ())
{
es_fprintf (outfp, "dirmngr-socket:%s\n",
gc_percent_escape (dirmngr_user_socket_name ()));
es_fprintf (outfp, "dirmngr-sys-socket:%s\n",
gc_percent_escape (dirmngr_sys_socket_name ()));
}
else
{
es_fprintf (outfp, "dirmngr-socket:%s\n",
gc_percent_escape (dirmngr_sys_socket_name ()));
}
{
char *tmp = make_filename (gnupg_socketdir (),
GPG_AGENT_SOCK_NAME, NULL);
es_fprintf (outfp, "agent-socket:%s\n", gc_percent_escape (tmp));
xfree (tmp);
}
{
char *tmp = xstrdup (gnupg_homedir ());
es_fprintf (outfp, "homedir:%s\n", gc_percent_escape (tmp));
xfree (tmp);
}
list_dirs (outfp, argc? argv : NULL);
break;
case aCreateSocketDir: