common: New common option no-autostart.

* common/comopt.c (opts): Add "no-autostart".
(parse_comopt): Set it.
* common/comopt.h (comopt): Add no_autostart.

* g10/gpg.c (main): Take care of the new option.
* sm/gpgsm.c (main): Ditto.
* tools/gpg-connect-agent.c (INCLUDED_BY_MAIN_MODULE): Add.
(main): Parse common options and handle new option.
* tools/gpg-card.c (main): Ditto.
(cmd_yubikey): Fix minor error reporting issue.

* common/util.h (GNUPG_MODULE_NAME_CARD): New const.
* common/homedir.c (gnupg_module_name): Support it.
--

Having a global option makes it easier to use disable autostart on a
server which is required to use a remote gpg-agent reliable.
This commit is contained in:
Werner Koch 2022-08-22 12:01:55 +02:00
parent bca00f1fba
commit 203dcc19eb
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
8 changed files with 39 additions and 2 deletions

View File

@ -45,6 +45,7 @@ enum opt_values
oLogFile = 500,
oUseKeyboxd,
oKeyboxdProgram,
oNoAutostart,
oNoop
};
@ -52,6 +53,7 @@ enum opt_values
static gpgrt_opt_t opts[] = {
ARGPARSE_s_s (oLogFile, "log-file", "@"),
ARGPARSE_s_n (oUseKeyboxd, "use-keyboxd", "@"),
ARGPARSE_s_n (oNoAutostart, "no-autostart", "@"),
ARGPARSE_s_s (oKeyboxdProgram, "keyboxd-program", "@"),
ARGPARSE_end ()
@ -60,7 +62,7 @@ static gpgrt_opt_t opts[] = {
/* Parse the common options in the homedir and etc. This needs to be
* called after the gpgrt config directories are. MODULE_ID is one of
* called after the gpgrt config directories are set. MODULE_ID is one of
* the GNUPG_MODULE_NAME_ constants. If verbose is true info about
* the parsing is printed. Note that this function is not
* thread-safe. */
@ -102,6 +104,10 @@ parse_comopt (int module_id, int verbose)
comopt.use_keyboxd = 1;
break;
case oNoAutostart:
comopt.no_autostart = 1;
break;
case oKeyboxdProgram:
comopt.keyboxd_program = pargs.r.ret_str;
break;

View File

@ -40,6 +40,7 @@ struct
{
char *logfile; /* Socket used by daemons for logging. */
int use_keyboxd; /* Use the keyboxd as storage backend. */
int no_autostart; /* Do not start gpg-agent. */
char *keyboxd_program; /* Use this as keyboxd program. */
} comopt;

View File

@ -1592,6 +1592,9 @@ gnupg_module_name (int which)
case GNUPG_MODULE_NAME_GPGCONF:
X(bindir, "tools", "gpgconf");
case GNUPG_MODULE_NAME_CARD:
X(bindir, "tools", "gpg-card");
default:
BUG ();
}

View File

@ -297,6 +297,7 @@ char *_gnupg_socketdir_internal (int skip_checks, unsigned *r_info);
#define GNUPG_MODULE_NAME_GPGV 12
#define GNUPG_MODULE_NAME_KEYBOXD 13
#define GNUPG_MODULE_NAME_TPM2DAEMON 14
#define GNUPG_MODULE_NAME_CARD 15
const char *gnupg_module_name (int which);
void gnupg_module_name_flush_some (void);
void gnupg_set_builddir (const char *newdir);

View File

@ -3784,6 +3784,8 @@ main (int argc, char **argv)
comopt.keyboxd_program = NULL;
}
if (comopt.no_autostart)
opt.autostart = 0;
/* The command --gpgconf-list is pretty simple and may be called
directly after the option parsing. */

View File

@ -1534,6 +1534,9 @@ main ( int argc, char **argv)
comopt.keyboxd_program = NULL;
}
if (comopt.no_autostart)
opt.autostart = 0;
if (pwfd != -1) /* Read the passphrase now. */
read_passphrase_from_fd (pwfd);

View File

@ -43,6 +43,7 @@
#include "../common/server-help.h"
#include "../common/openpgpdefs.h"
#include "../common/tlv.h"
#include "../common/comopt.h"
#include "gpg-card.h"
@ -292,6 +293,17 @@ main (int argc, char **argv)
if (log_get_errorcount (0))
exit (2);
/* Process common component options. */
if (parse_comopt (GNUPG_MODULE_NAME_CARD, opt.debug))
{
gnupg_status_printf (STATUS_FAILURE, "option-parser %u",
gpg_error (GPG_ERR_GENERAL));
exit(2);
}
if (comopt.no_autostart)
opt.autostart = 0;
/* Set defaults for non given options. */
if (!opt.gpg_program)
opt.gpg_program = gnupg_module_name (GNUPG_MODULE_NAME_GPG);
@ -3505,7 +3517,7 @@ cmd_yubikey (card_info_t info, char *argstr)
err = yubikey_commands (info, fp, nwords, words);
err2 = scd_learn (info, 0);
if (err2)
log_error ("Error re-reading card: %s\n", gpg_strerror (err));
log_error ("Error re-reading card: %s\n", gpg_strerror (err2));
leave:
return err;

View File

@ -29,6 +29,7 @@
#include <unistd.h>
#include <assert.h>
#define INCLUDED_BY_MAIN_MODULE 1
#include "../common/i18n.h"
#include "../common/util.h"
#include "../common/asshelp.h"
@ -39,6 +40,7 @@
# include "../common/exechelp.h"
#endif
#include "../common/init.h"
#include "../common/comopt.h"
#define CONTROL_D ('D' - 'A' + 1)
@ -1255,6 +1257,13 @@ main (int argc, char **argv)
if (log_get_errorcount (0))
exit (2);
/* Process common component options. */
if (parse_comopt (GNUPG_MODULE_NAME_CONNECT_AGENT, opt.verbose > 1))
exit(2);
if (comopt.no_autostart)
opt.autostart = 0;
/* --uiserver is a shortcut for a specific raw socket. This comes
in particular handy on Windows. */
if (opt.use_uiserver)