diff options
author | Werner Koch <[email protected]> | 2019-08-06 12:28:08 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2019-08-06 12:57:07 +0000 |
commit | 0611f548bcd3c772084d6c3111dc88a09a67f65a (patch) | |
tree | d78e418c5a4ecdb6ed504cf9082e78cf266837b5 /common/asshelp.c | |
parent | common: Remove code duplication for service starting. (diff) | |
download | gnupg-0611f548bcd3c772084d6c3111dc88a09a67f65a.tar.gz gnupg-0611f548bcd3c772084d6c3111dc88a09a67f65a.zip |
tools: New option --keyboxd for gpg-connect-agent.
* configure.ac: New option --keyboxd-pgm.
(KEYBOXD_NAME, KEYBOXD_DISP_NAME): New ac_defines.
* common/util.h: Add substitutes for new error codes.
(GNUPG_MODULE_NAME_KEYBOXD): New.
* common/homedir.c (gnupg_module_name): Support
GNUPG_MODULE_NAME_KEYBOXD.
* common/asshelp.c (SECS_TO_WAIT_FOR_KEYBOXD): New.
(wait_for_sock): Support keyboxd.
(start_new_service): Ditto.
(start_new_keyboxd): New.
* tools/gpg-connect-agent.c: New options --keyboxd and
--keyboxd-program.
(start_agent): Implement new option.
--
This change allows us to test the new keyboxd using our standard
helper. It also provides the necessary code to start keyboxd on the
fly.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/asshelp.c')
-rw-r--r-- | common/asshelp.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/common/asshelp.c b/common/asshelp.c index 84bc546e2..a5724fad5 100644 --- a/common/asshelp.c +++ b/common/asshelp.c @@ -56,9 +56,11 @@ operation after we started them before giving up. */ #ifdef HAVE_W32CE_SYSTEM # define SECS_TO_WAIT_FOR_AGENT 30 +# define SECS_TO_WAIT_FOR_KEYBOXD 30 # define SECS_TO_WAIT_FOR_DIRMNGR 30 #else # define SECS_TO_WAIT_FOR_AGENT 5 +# define SECS_TO_WAIT_FOR_KEYBOXD 5 # define SECS_TO_WAIT_FOR_DIRMNGR 5 #endif @@ -308,17 +310,14 @@ unlock_spawning (lock_spawn_t *lock, const char *name) } -/* Helper for start_new_gpg_agent and start_new_dirmngr. - * Values for WHICH are: - * 0 - Start gpg-agent - * 1 - Start dirmngr - * SECS give the number of seconds to wait. SOCKNAME is the name of +/* Helper to start a service. + * SECS gives the number of seconds to wait. SOCKNAME is the name of * the socket to connect. VERBOSE is the usual verbose flag. CTX is * the assuan context. DID_SUCCESS_MSG will be set to 1 if a success * messages has been printed. */ static gpg_error_t -wait_for_sock (int secs, int which, const char *sockname, +wait_for_sock (int secs, int module_name_id, const char *sockname, int verbose, assuan_context_t ctx, int *did_success_msg) { gpg_error_t err = 0; @@ -343,8 +342,10 @@ wait_for_sock (int secs, int which, const char *sockname, /* next_sleep_us); */ if (secsleft < lastalert) { - log_info (which == 1? + log_info (module_name_id == GNUPG_MODULE_NAME_DIRMNGR? _("waiting for the dirmngr to come up ... (%ds)\n"): + module_name_id == GNUPG_MODULE_NAME_KEYBOXD? + _("waiting for the keyboxd to come up ... (%ds)\n"): _("waiting for the agent to come up ... (%ds)\n"), secsleft); lastalert = secsleft; @@ -357,8 +358,10 @@ wait_for_sock (int secs, int which, const char *sockname, { if (verbose) { - log_info (which == 1? + log_info (module_name_id == GNUPG_MODULE_NAME_DIRMNGR? _("connection to the dirmngr established\n"): + module_name_id == GNUPG_MODULE_NAME_KEYBOXD? + _("connection to the keyboxd established\n"): _("connection to the agent established\n")); *did_success_msg = 1; } @@ -429,6 +432,14 @@ start_new_service (assuan_context_t *r_ctx, no_service_err = GPG_ERR_NO_DIRMNGR; seconds_to_wait = SECS_TO_WAIT_FOR_DIRMNGR; break; + case GNUPG_MODULE_NAME_KEYBOXD: + sockname = make_filename (gnupg_socketdir (), KEYBOXD_SOCK_NAME, NULL); + lock_name = "keyboxd"; + printed_name = "keyboxd"; + status_start_line = "starting_keyboxd ? 0 0"; + no_service_err = GPG_ERR_NO_KEYBOXD; + seconds_to_wait = SECS_TO_WAIT_FOR_KEYBOXD; + break; default: err = gpg_error (GPG_ERR_INV_ARG); assuan_release (ctx); @@ -520,7 +531,7 @@ start_new_service (assuan_context_t *r_ctx, printed_name, program? program : program_name, gpg_strerror (err)); else - err = wait_for_sock (seconds_to_wait, 0, + err = wait_for_sock (seconds_to_wait, module_name_id, sockname, verbose, ctx, &did_success_msg); } @@ -599,6 +610,25 @@ start_new_gpg_agent (assuan_context_t *r_ctx, supporting it, start it up if needed and if AUTOSTART is true. Returns a new assuan context at R_CTX or an error code. */ gpg_error_t +start_new_keyboxd (assuan_context_t *r_ctx, + gpg_err_source_t errsource, + const char *keyboxd_program, + int autostart, int verbose, int debug, + gpg_error_t (*status_cb)(ctrl_t, int, ...), + ctrl_t status_cb_arg) +{ + return start_new_service (r_ctx, GNUPG_MODULE_NAME_KEYBOXD, + errsource, keyboxd_program, + NULL, NULL, NULL, + autostart, verbose, debug, + status_cb, status_cb_arg); +} + + +/* Try to connect to the dirmngr via a socket. On platforms + supporting it, start it up if needed and if AUTOSTART is true. + Returns a new assuan context at R_CTX or an error code. */ +gpg_error_t start_new_dirmngr (assuan_context_t *r_ctx, gpg_err_source_t errsource, const char *dirmngr_program, |