From d10f45184c4482036c41f4818c84c0725a0c2c94 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 6 Aug 2020 15:32:43 +0200 Subject: [PATCH] gpgconf: New option --chuid. * tools/gpgconf.c (oChUid, opts): New option --chuid. (main): Implement. -- Signed-off-by: Werner Koch --- doc/DETAILS | 2 +- doc/tools.texi | 10 ++++++++++ tools/gpgconf.c | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/DETAILS b/doc/DETAILS index 0a1282d91..94979339f 100644 --- a/doc/DETAILS +++ b/doc/DETAILS @@ -1196,7 +1196,7 @@ pkd:0:1024:B665B1435F4C2 .... FF26ABB: *** MANUFACTURER [] This status returns the Manufactorer ID as the unsigned number N. - For OpenPGP this is weel defined; for other cards this is 0. The + For OpenPGP this is well defined; for other cards this is 0. The name of the manufacturer is also given as ; spaces are not escaped. For PKCS#15 cards is TokenInfo.manufactorerID. diff --git a/doc/tools.texi b/doc/tools.texi index 537c3c72a..3ebec1a98 100644 --- a/doc/tools.texi +++ b/doc/tools.texi @@ -415,6 +415,16 @@ Try to be as quiet as possible. @include opt-homedir.texi +@item --chuid @var{uid} +@opindex chuid +Change the current user to @var{uid} which may either be a number or a +name. This can be used from the root account to get information on +the GnuPG environment of the specified user or to start or kill +daemons. If @var{uid} is not the current UID a standard PATH is set +and the envvar GNUPGHOME is unset. To override the latter the option +@option{--homedir} can be used. This option has currently no effect +on Windows. + @item -n @itemx --dry-run Do not actually change anything. This is currently only implemented diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 3433ed473..e68eecdd7 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -51,6 +51,7 @@ enum cmd_and_opt_values oBuilddir, oStatusFD, oShowSocket, + oChUid, aListComponents, aCheckPrograms, @@ -113,6 +114,7 @@ static gpgrt_opt_t opts[] = { oNull, "null", 0, "@" }, { oNoVerbose, "no-verbose", 0, "@"}, ARGPARSE_s_n (oShowSocket, "show-socket", "@"), + ARGPARSE_s_s (oChUid, "chuid", "@"), ARGPARSE_end(), }; @@ -547,6 +549,7 @@ main (int argc, char **argv) enum cmd_and_opt_values cmd = 0; estream_t outfp = NULL; int show_socket = 0; + const char *changeuser = NULL; early_system_init (); gnupg_reopen_std (GPGCONF_NAME); @@ -579,6 +582,7 @@ main (int argc, char **argv) set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1)); break; case oShowSocket: show_socket = 1; break; + case oChUid: changeuser = pargs.r.ret_str; break; case aListDirs: case aListComponents: @@ -620,6 +624,10 @@ main (int argc, char **argv) fname = argc ? *argv : NULL; + /* If requested switch to the requested user or die. */ + if (changeuser && (err = gnupg_chuid (changeuser, 0))) + gpgconf_failure (err); + /* 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. */