2004-03-06 20:11:19 +00:00
|
|
|
/* asshelp.c - Helper functions for Assuan
|
2010-05-03 15:23:10 +00:00
|
|
|
* Copyright (C) 2002, 2004, 2007, 2009, 2010 Free Software Foundation, Inc.
|
2004-03-06 20:11:19 +00:00
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of either
|
2004-03-06 20:11:19 +00:00
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or both in parallel, as here.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
2004-03-06 20:11:19 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2004-03-06 20:11:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
|
2007-06-21 18:44:48 +00:00
|
|
|
#include "i18n.h"
|
2004-03-06 20:11:19 +00:00
|
|
|
#include "util.h"
|
2007-06-21 18:44:48 +00:00
|
|
|
#include "exechelp.h"
|
|
|
|
#include "sysutils.h"
|
2011-02-04 12:57:53 +01:00
|
|
|
#include "status.h"
|
2016-01-08 06:42:29 +01:00
|
|
|
#include "membuf.h"
|
2004-03-06 20:11:19 +00:00
|
|
|
#include "asshelp.h"
|
|
|
|
|
2010-05-03 15:23:10 +00:00
|
|
|
/* The type we use for lock_agent_spawning. */
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2010-08-16 11:03:43 +00:00
|
|
|
# define lock_spawn_t HANDLE
|
2010-05-03 15:23:10 +00:00
|
|
|
#else
|
2010-08-16 11:03:43 +00:00
|
|
|
# define lock_spawn_t dotlock_t
|
2010-05-03 15:23:10 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-23 18:46:41 +00:00
|
|
|
/* The time we wait until the agent or the dirmngr are ready for
|
2011-02-04 12:57:53 +01:00
|
|
|
operation after we started them before giving up. */
|
2022-11-16 10:05:37 +09:00
|
|
|
#define SECS_TO_WAIT_FOR_AGENT 5
|
|
|
|
#define SECS_TO_WAIT_FOR_KEYBOXD 5
|
|
|
|
#define SECS_TO_WAIT_FOR_DIRMNGR 5
|
2010-03-11 12:34:11 +00:00
|
|
|
|
2010-04-14 11:24:02 +00:00
|
|
|
/* A bitfield that specifies the assuan categories to log. This is
|
|
|
|
identical to the default log handler of libassuan. We need to do
|
|
|
|
it ourselves because we use a custom log handler and want to use
|
|
|
|
the same assuan variables to select the categories to log. */
|
|
|
|
static int log_cats;
|
|
|
|
#define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1))))
|
|
|
|
|
2016-09-05 10:55:10 +02:00
|
|
|
/* The assuan log monitor used to temporary inhibit log messages from
|
|
|
|
* assuan. */
|
|
|
|
static int (*my_log_monitor) (assuan_context_t ctx,
|
|
|
|
unsigned int cat,
|
|
|
|
const char *msg);
|
|
|
|
|
2010-04-14 11:24:02 +00:00
|
|
|
|
2010-03-11 12:34:11 +00:00
|
|
|
static int
|
|
|
|
my_libassuan_log_handler (assuan_context_t ctx, void *hook,
|
|
|
|
unsigned int cat, const char *msg)
|
|
|
|
{
|
|
|
|
unsigned int dbgval;
|
|
|
|
|
2010-04-14 11:24:02 +00:00
|
|
|
if (! TEST_LOG_CAT (cat))
|
|
|
|
return 0;
|
|
|
|
|
2010-03-11 12:34:11 +00:00
|
|
|
dbgval = hook? *(unsigned int*)hook : 0;
|
|
|
|
if (!(dbgval & 1024))
|
|
|
|
return 0; /* Assuan debugging is not enabled. */
|
|
|
|
|
2016-09-05 10:55:10 +02:00
|
|
|
if (ctx && my_log_monitor && !my_log_monitor (ctx, cat, msg))
|
|
|
|
return 0; /* Temporary disabled. */
|
|
|
|
|
2010-03-11 12:34:11 +00:00
|
|
|
if (msg)
|
2017-12-11 10:37:30 +01:00
|
|
|
log_string (GPGRT_LOGLVL_DEBUG, msg);
|
2010-03-11 12:34:11 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup libassuan to use our own logging functions. Should be used
|
|
|
|
early at startup. */
|
|
|
|
void
|
2016-09-05 10:55:10 +02:00
|
|
|
setup_libassuan_logging (unsigned int *debug_var_address,
|
|
|
|
int (*log_monitor)(assuan_context_t ctx,
|
|
|
|
unsigned int cat,
|
|
|
|
const char *msg))
|
2010-03-11 12:34:11 +00:00
|
|
|
{
|
2010-04-14 11:24:02 +00:00
|
|
|
char *flagstr;
|
|
|
|
|
|
|
|
flagstr = getenv ("ASSUAN_DEBUG");
|
|
|
|
if (flagstr)
|
|
|
|
log_cats = atoi (flagstr);
|
|
|
|
else /* Default to log the control channel. */
|
|
|
|
log_cats = (1 << (ASSUAN_LOG_CONTROL - 1));
|
2016-09-05 10:55:10 +02:00
|
|
|
my_log_monitor = log_monitor;
|
2010-03-11 12:34:11 +00:00
|
|
|
assuan_set_log_cb (my_libassuan_log_handler, debug_var_address);
|
|
|
|
}
|
|
|
|
|
2016-09-05 10:55:10 +02:00
|
|
|
|
2011-12-13 17:59:00 +01:00
|
|
|
/* Change the Libassuan log categories to those given by NEWCATS.
|
|
|
|
NEWCATS is 0 the default category of ASSUAN_LOG_CONTROL is
|
|
|
|
selected. Note, that setup_libassuan_logging overrides the values
|
|
|
|
given here. */
|
|
|
|
void
|
|
|
|
set_libassuan_log_cats (unsigned int newcats)
|
|
|
|
{
|
|
|
|
if (newcats)
|
|
|
|
log_cats = newcats;
|
|
|
|
else /* Default to log the control channel. */
|
|
|
|
log_cats = (1 << (ASSUAN_LOG_CONTROL - 1));
|
|
|
|
}
|
|
|
|
|
2010-03-11 12:34:11 +00:00
|
|
|
|
|
|
|
|
2004-12-15 14:15:54 +00:00
|
|
|
static gpg_error_t
|
2004-12-18 10:22:10 +00:00
|
|
|
send_one_option (assuan_context_t ctx, gpg_err_source_t errsource,
|
2009-07-07 10:02:41 +00:00
|
|
|
const char *name, const char *value, int use_putenv)
|
2004-12-15 14:15:54 +00:00
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
char *optstr;
|
|
|
|
|
2008-10-20 13:53:23 +00:00
|
|
|
(void)errsource;
|
|
|
|
|
2004-12-15 14:15:54 +00:00
|
|
|
if (!value || !*value)
|
|
|
|
err = 0; /* Avoid sending empty strings. */
|
2011-02-04 12:57:53 +01:00
|
|
|
else if (asprintf (&optstr, "OPTION %s%s=%s",
|
2009-07-07 10:02:41 +00:00
|
|
|
use_putenv? "putenv=":"", name, value) < 0)
|
2006-09-14 16:50:33 +00:00
|
|
|
err = gpg_error_from_syserror ();
|
2004-12-15 14:15:54 +00:00
|
|
|
else
|
|
|
|
{
|
2006-09-06 16:35:52 +00:00
|
|
|
err = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL);
|
2008-05-27 12:03:50 +00:00
|
|
|
xfree (optstr);
|
2004-12-15 14:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 16:03:50 +00:00
|
|
|
/* Send the assuan commands pertaining to the pinentry environment. The
|
2004-12-15 14:15:54 +00:00
|
|
|
OPT_* arguments are optional and may be used to override the
|
2004-03-06 20:11:19 +00:00
|
|
|
defaults taken from the current locale. */
|
|
|
|
gpg_error_t
|
|
|
|
send_pinentry_environment (assuan_context_t ctx,
|
2004-12-18 10:22:10 +00:00
|
|
|
gpg_err_source_t errsource,
|
2004-03-06 20:11:19 +00:00
|
|
|
const char *opt_lc_ctype,
|
2007-11-19 16:03:50 +00:00
|
|
|
const char *opt_lc_messages,
|
2009-07-07 10:02:41 +00:00
|
|
|
session_env_t session_env)
|
|
|
|
|
2004-03-06 20:11:19 +00:00
|
|
|
{
|
2004-12-15 14:15:54 +00:00
|
|
|
gpg_error_t err = 0;
|
2010-03-22 12:46:05 +00:00
|
|
|
#if defined(HAVE_SETLOCALE)
|
2011-02-04 12:57:53 +01:00
|
|
|
char *old_lc = NULL;
|
2010-03-22 12:46:05 +00:00
|
|
|
#endif
|
2004-03-06 20:11:19 +00:00
|
|
|
char *dft_lc = NULL;
|
2009-07-07 10:02:41 +00:00
|
|
|
const char *dft_ttyname;
|
|
|
|
int iterator;
|
|
|
|
const char *name, *assname, *value;
|
|
|
|
int is_default;
|
2004-03-06 20:11:19 +00:00
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
iterator = 0;
|
2009-07-07 10:02:41 +00:00
|
|
|
while ((name = session_env_list_stdenvnames (&iterator, &assname)))
|
2004-03-06 20:11:19 +00:00
|
|
|
{
|
2009-07-07 10:02:41 +00:00
|
|
|
value = session_env_getenv_or_default (session_env, name, NULL);
|
|
|
|
if (!value)
|
|
|
|
continue;
|
2004-12-15 14:15:54 +00:00
|
|
|
|
2009-07-07 10:02:41 +00:00
|
|
|
if (assname)
|
|
|
|
err = send_one_option (ctx, errsource, assname, value, 0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = send_one_option (ctx, errsource, name, value, 1);
|
|
|
|
if (gpg_err_code (err) == GPG_ERR_UNKNOWN_OPTION)
|
|
|
|
err = 0; /* Server too old; can't pass the new envvars. */
|
|
|
|
}
|
2004-12-15 14:15:54 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
2004-12-15 14:15:54 +00:00
|
|
|
|
2009-07-07 10:02:41 +00:00
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
dft_ttyname = session_env_getenv_or_default (session_env, "GPG_TTY",
|
2009-07-07 10:02:41 +00:00
|
|
|
&is_default);
|
|
|
|
if (dft_ttyname && !is_default)
|
|
|
|
dft_ttyname = NULL; /* We need the default value. */
|
2004-12-15 14:15:54 +00:00
|
|
|
|
|
|
|
/* Send the value for LC_CTYPE. */
|
2004-03-06 20:11:19 +00:00
|
|
|
#if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
|
|
|
|
old_lc = setlocale (LC_CTYPE, NULL);
|
|
|
|
if (old_lc)
|
|
|
|
{
|
2008-05-27 12:03:50 +00:00
|
|
|
old_lc = xtrystrdup (old_lc);
|
2004-03-06 20:11:19 +00:00
|
|
|
if (!old_lc)
|
2006-09-14 16:50:33 +00:00
|
|
|
return gpg_error_from_syserror ();
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
dft_lc = setlocale (LC_CTYPE, "");
|
|
|
|
#endif
|
|
|
|
if (opt_lc_ctype || (dft_ttyname && dft_lc))
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
err = send_one_option (ctx, errsource, "lc-ctype",
|
2009-07-07 10:02:41 +00:00
|
|
|
opt_lc_ctype ? opt_lc_ctype : dft_lc, 0);
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
#if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
|
|
|
|
if (old_lc)
|
|
|
|
{
|
|
|
|
setlocale (LC_CTYPE, old_lc);
|
2008-05-27 12:03:50 +00:00
|
|
|
xfree (old_lc);
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-12-15 14:15:54 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Send the value for LC_MESSAGES. */
|
2004-03-06 20:11:19 +00:00
|
|
|
#if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
|
|
|
|
old_lc = setlocale (LC_MESSAGES, NULL);
|
|
|
|
if (old_lc)
|
|
|
|
{
|
2008-05-27 12:03:50 +00:00
|
|
|
old_lc = xtrystrdup (old_lc);
|
2004-03-06 20:11:19 +00:00
|
|
|
if (!old_lc)
|
2006-09-14 16:50:33 +00:00
|
|
|
return gpg_error_from_syserror ();
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
dft_lc = setlocale (LC_MESSAGES, "");
|
|
|
|
#endif
|
|
|
|
if (opt_lc_messages || (dft_ttyname && dft_lc))
|
|
|
|
{
|
2011-02-04 12:57:53 +01:00
|
|
|
err = send_one_option (ctx, errsource, "lc-messages",
|
2009-07-07 10:02:41 +00:00
|
|
|
opt_lc_messages ? opt_lc_messages : dft_lc, 0);
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
#if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
|
|
|
|
if (old_lc)
|
|
|
|
{
|
|
|
|
setlocale (LC_MESSAGES, old_lc);
|
2008-05-27 12:03:50 +00:00
|
|
|
xfree (old_lc);
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-12-15 14:15:54 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2004-03-06 20:11:19 +00:00
|
|
|
|
2004-12-15 14:15:54 +00:00
|
|
|
return 0;
|
2004-03-06 20:11:19 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 18:44:48 +00:00
|
|
|
|
2010-08-16 11:03:43 +00:00
|
|
|
/* Lock a spawning process. The caller needs to provide the address
|
|
|
|
of a variable to store the lock information and the name or the
|
|
|
|
process. */
|
2010-05-03 15:23:10 +00:00
|
|
|
static gpg_error_t
|
2010-12-17 16:55:13 +00:00
|
|
|
lock_spawning (lock_spawn_t *lock, const char *homedir, const char *name,
|
|
|
|
int verbose)
|
2010-05-03 15:23:10 +00:00
|
|
|
{
|
|
|
|
char *fname;
|
2010-12-17 16:55:13 +00:00
|
|
|
(void)verbose;
|
|
|
|
|
2010-05-03 15:23:10 +00:00
|
|
|
*lock = NULL;
|
|
|
|
|
2014-04-15 16:40:48 +02:00
|
|
|
fname = make_absfilename_try
|
2010-08-16 11:03:43 +00:00
|
|
|
(homedir,
|
|
|
|
!strcmp (name, "agent")? "gnupg_spawn_agent_sentinel":
|
|
|
|
!strcmp (name, "dirmngr")? "gnupg_spawn_dirmngr_sentinel":
|
2020-09-23 12:02:50 +02:00
|
|
|
!strcmp (name, "keyboxd")? "gnupg_spawn_keyboxd_sentinel":
|
2010-08-16 11:03:43 +00:00
|
|
|
/* */ "gnupg_spawn_unknown_sentinel",
|
|
|
|
NULL);
|
2010-05-03 15:23:10 +00:00
|
|
|
if (!fname)
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
2011-09-28 15:41:58 +02:00
|
|
|
*lock = dotlock_create (fname, 0);
|
2010-05-03 15:23:10 +00:00
|
|
|
xfree (fname);
|
|
|
|
if (!*lock)
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
|
|
|
/* FIXME: We should use a timeout of 5000 here - however
|
|
|
|
make_dotlock does not yet support values other than -1 and 0. */
|
2011-09-23 14:43:58 +02:00
|
|
|
if (dotlock_take (*lock, -1))
|
2010-05-03 15:23:10 +00:00
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unlock the spawning process. */
|
|
|
|
static void
|
2010-08-16 11:03:43 +00:00
|
|
|
unlock_spawning (lock_spawn_t *lock, const char *name)
|
2010-05-03 15:23:10 +00:00
|
|
|
{
|
|
|
|
if (*lock)
|
|
|
|
{
|
2010-08-16 11:03:43 +00:00
|
|
|
(void)name;
|
2011-09-23 14:43:58 +02:00
|
|
|
dotlock_destroy (*lock);
|
2010-05-03 15:23:10 +00:00
|
|
|
*lock = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:47:48 +01:00
|
|
|
|
2019-09-10 16:05:54 +02:00
|
|
|
/* 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. CONNECT_FLAGS
|
|
|
|
* are the assuan connect flags. DID_SUCCESS_MSG will be set to 1 if
|
|
|
|
* a success messages has been printed.
|
2017-11-15 13:47:48 +01:00
|
|
|
*/
|
2017-11-08 16:15:30 +01:00
|
|
|
static gpg_error_t
|
2019-08-06 14:28:08 +02:00
|
|
|
wait_for_sock (int secs, int module_name_id, const char *sockname,
|
2019-09-10 16:05:54 +02:00
|
|
|
unsigned int connect_flags,
|
2017-11-15 13:47:48 +01:00
|
|
|
int verbose, assuan_context_t ctx, int *did_success_msg)
|
2017-11-08 16:15:30 +01:00
|
|
|
{
|
|
|
|
gpg_error_t err = 0;
|
2017-11-08 16:26:40 +01:00
|
|
|
int target_us = secs * 1000000;
|
|
|
|
int elapsed_us = 0;
|
|
|
|
/*
|
|
|
|
* 977us * 1024 = just a little more than 1s.
|
|
|
|
* so we will double this timeout 10 times in the first
|
|
|
|
* second, and then switch over to 1s checkins.
|
|
|
|
*/
|
|
|
|
int next_sleep_us = 977;
|
|
|
|
int lastalert = secs+1;
|
|
|
|
int secsleft;
|
|
|
|
|
|
|
|
while (elapsed_us < target_us)
|
2017-11-08 16:15:30 +01:00
|
|
|
{
|
|
|
|
if (verbose)
|
2017-11-08 16:26:40 +01:00
|
|
|
{
|
2017-11-15 15:30:21 +01:00
|
|
|
secsleft = (target_us - elapsed_us + 999999)/1000000;
|
|
|
|
/* log_clock ("left=%d last=%d targ=%d elap=%d next=%d\n", */
|
|
|
|
/* secsleft, lastalert, target_us, elapsed_us, */
|
|
|
|
/* next_sleep_us); */
|
2017-11-08 16:26:40 +01:00
|
|
|
if (secsleft < lastalert)
|
|
|
|
{
|
2019-08-06 14:28:08 +02:00
|
|
|
log_info (module_name_id == GNUPG_MODULE_NAME_DIRMNGR?
|
2017-11-15 13:47:48 +01:00
|
|
|
_("waiting for the dirmngr to come up ... (%ds)\n"):
|
2019-08-06 14:28:08 +02:00
|
|
|
module_name_id == GNUPG_MODULE_NAME_KEYBOXD?
|
|
|
|
_("waiting for the keyboxd to come up ... (%ds)\n"):
|
2017-11-15 13:47:48 +01:00
|
|
|
_("waiting for the agent to come up ... (%ds)\n"),
|
|
|
|
secsleft);
|
2017-11-08 16:26:40 +01:00
|
|
|
lastalert = secsleft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gnupg_usleep (next_sleep_us);
|
|
|
|
elapsed_us += next_sleep_us;
|
2019-09-10 16:05:54 +02:00
|
|
|
err = assuan_socket_connect (ctx, sockname, 0, connect_flags);
|
2017-11-08 16:15:30 +01:00
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
{
|
2019-08-06 14:28:08 +02:00
|
|
|
log_info (module_name_id == GNUPG_MODULE_NAME_DIRMNGR?
|
2017-11-15 13:47:48 +01:00
|
|
|
_("connection to the dirmngr established\n"):
|
2019-08-06 14:28:08 +02:00
|
|
|
module_name_id == GNUPG_MODULE_NAME_KEYBOXD?
|
|
|
|
_("connection to the keyboxd established\n"):
|
2017-11-15 13:46:40 +01:00
|
|
|
_("connection to the agent established\n"));
|
2017-11-08 16:15:30 +01:00
|
|
|
*did_success_msg = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-08 16:26:40 +01:00
|
|
|
next_sleep_us *= 2;
|
|
|
|
if (next_sleep_us > 1000000)
|
|
|
|
next_sleep_us = 1000000;
|
2017-11-08 16:15:30 +01:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-11-15 13:47:48 +01:00
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
/* Try to connect to a new service via socket or start it if it is not
|
|
|
|
* running and AUTOSTART is set. Handle the server's initial
|
|
|
|
* greeting. Returns a new assuan context at R_CTX or an error code.
|
|
|
|
* MODULE_NAME_ID is one of:
|
|
|
|
* GNUPG_MODULE_NAME_AGENT
|
|
|
|
* GNUPG_MODULE_NAME_DIRMNGR
|
|
|
|
*/
|
|
|
|
static gpg_error_t
|
|
|
|
start_new_service (assuan_context_t *r_ctx,
|
|
|
|
int module_name_id,
|
|
|
|
gpg_err_source_t errsource,
|
|
|
|
const char *program_name,
|
|
|
|
const char *opt_lc_ctype,
|
|
|
|
const char *opt_lc_messages,
|
|
|
|
session_env_t session_env,
|
2023-08-29 13:18:13 +02:00
|
|
|
unsigned int flags,
|
|
|
|
int verbose, int debug,
|
2019-08-05 09:49:09 +02:00
|
|
|
gpg_error_t (*status_cb)(ctrl_t, int, ...),
|
|
|
|
ctrl_t status_cb_arg)
|
2007-06-21 18:44:48 +00:00
|
|
|
{
|
2014-10-03 11:58:58 +02:00
|
|
|
gpg_error_t err;
|
2007-06-21 18:44:48 +00:00
|
|
|
assuan_context_t ctx;
|
2010-11-23 18:46:41 +00:00
|
|
|
int did_success_msg = 0;
|
2014-10-03 11:58:58 +02:00
|
|
|
char *sockname;
|
2019-08-05 09:49:09 +02:00
|
|
|
const char *printed_name;
|
|
|
|
const char *lock_name;
|
|
|
|
const char *status_start_line;
|
|
|
|
int no_service_err;
|
|
|
|
int seconds_to_wait;
|
2019-09-10 16:05:54 +02:00
|
|
|
unsigned int connect_flags = 0;
|
2014-10-30 09:55:51 +01:00
|
|
|
const char *argv[6];
|
2007-06-21 18:44:48 +00:00
|
|
|
|
|
|
|
*r_ctx = NULL;
|
|
|
|
|
2010-05-03 15:23:10 +00:00
|
|
|
err = assuan_new (&ctx);
|
|
|
|
if (err)
|
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION):
Update to new API (2, 1.1.0).
agent/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-agent.c (parse_rereadable_options): Don't set global assuan
log file (there ain't one anymore).
(main): Update to new API.
(check_own_socket_pid_cb): Return gpg_error_t instead of int.
(check_own_socket_thread, check_for_running_agent): Create assuan
context before connecting to server.
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(write_and_clear_outbuf): Use gpg_error_t instead of
assuan_error_t.
(cmd_geteventcounter, cmd_istrusted, cmd_listtrusted)
(cmd_marktrusted, cmd_havekey, cmd_sigkey, cmd_setkeydesc)
(cmd_sethash, cmd_pksign, cmd_pkdecrypt, cmd_genkey, cmd_readkey)
(cmd_keyinfo, cmd_get_passphrase, cmd_clear_passphrase)
(cmd_get_confirmation, cmd_learn, cmd_passwd)
(cmd_preset_passphrase, cmd_scd, cmd_getval, cmd_putval)
(cmd_updatestartuptty, cmd_killagent, cmd_reloadagent)
(cmd_getinfo, option_handler): Return gpg_error_t instead of int.
(post_cmd_notify): Change type of ERR to gpg_error_t from int.
(io_monitor): Add hook argument. Use symbols for constants.
(register_commands): Change return type of HANDLER to gpg_error_t.
(start_command_handler): Allocate assuan context before starting
server.
* call-pinentry.c: Include "scdaemon.h" before <assuan.h> because
of GPG_ERR_SOURCE_DEFAULT check.
(unlock_pinentry): Call assuan_release instead of
assuan_disconnect.
(getinfo_pid_cb, getpin_cb): Return gpg_error_t instead of int.
(start_pinentry): Allocate assuan context before connecting to
server.
* call-scd.c (membuf_data_cb, learn_status_cb, get_serialno_cb)
(membuf_data_cb, inq_needpin, card_getattr_cb, pass_status_thru)
(pass_data_thru): Change return type to gpg_error_t.
(start_scd): Allocate assuan context before connecting to server.
common/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
starting server.
g10/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* call-agent.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb)
(learn_status_cb, inq_writecert_parms, inq_writekey_parms)
(scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of
int.
* gpg.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(main): Update to new Assuan API.
* server.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys)
(cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t
instead of int.
(register_commands): Allocate assuan context before starting
server.
(gpg_server): Allocate assuan_context before starting server.
scd/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, open_card, cmd_serialno, cmd_lean, cmd_readcert)
(cmd_readkey, cmd_setdata, cmd_pksign, cmd_pkauth, cmd_pkdecrypt)
(cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_lock)
(cmd_unlock, cmd_getinfo, cmd_restart, cmd_disconnect, cmd_apdu)
(cmd_killscd): Return gpg_error_t instead of int.
(scd_command_handler): Allocate assuan context before starting server.
* scdaemon.c (main): Update to new Assuan API.
sm/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Update to new assuan API.
* server.c: Include "gpgsm.h" before <assuan.h> due to check for
GPG_ERR_SOURCE_DEFAULT and assuan.h now including gpg-error.h.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, cmd_listkeys, cmd_dumpkeys)
(cmd_listsecretkeys, cmd_dumpsecretkeys, cmd_genkey)
(cmd_getauditlog, cmd_getinfo): Return gpg_error_t instead of int.
(register_commands): Same for member HANDLER in table.
(gpgsm_server): Allocate assuan context before starting server.
* sm/call-dirmngr.c:
* call-dirmngr.c (prepare_dirmngr): Check for CTX and error before
setting LDAPSERVER.
(start_dirmngr_ext): Allocate assuan context before starting
server.
(inq_certificate, isvalid_status_cb, lookup_cb, lookup_status_cb)
(run_command_cb, run_command_inq_cb, run_command_status_cb):
Return gpg_error_t instead of int.
tools/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-connect-agent.c (getinfo_pid_cb, read_and_print_response)
(main): Update to new Assuan API.
2009-09-23 00:01:25 +00:00
|
|
|
{
|
2010-05-03 15:23:10 +00:00
|
|
|
log_error ("error allocating assuan context: %s\n", gpg_strerror (err));
|
|
|
|
return err;
|
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION):
Update to new API (2, 1.1.0).
agent/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-agent.c (parse_rereadable_options): Don't set global assuan
log file (there ain't one anymore).
(main): Update to new API.
(check_own_socket_pid_cb): Return gpg_error_t instead of int.
(check_own_socket_thread, check_for_running_agent): Create assuan
context before connecting to server.
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(write_and_clear_outbuf): Use gpg_error_t instead of
assuan_error_t.
(cmd_geteventcounter, cmd_istrusted, cmd_listtrusted)
(cmd_marktrusted, cmd_havekey, cmd_sigkey, cmd_setkeydesc)
(cmd_sethash, cmd_pksign, cmd_pkdecrypt, cmd_genkey, cmd_readkey)
(cmd_keyinfo, cmd_get_passphrase, cmd_clear_passphrase)
(cmd_get_confirmation, cmd_learn, cmd_passwd)
(cmd_preset_passphrase, cmd_scd, cmd_getval, cmd_putval)
(cmd_updatestartuptty, cmd_killagent, cmd_reloadagent)
(cmd_getinfo, option_handler): Return gpg_error_t instead of int.
(post_cmd_notify): Change type of ERR to gpg_error_t from int.
(io_monitor): Add hook argument. Use symbols for constants.
(register_commands): Change return type of HANDLER to gpg_error_t.
(start_command_handler): Allocate assuan context before starting
server.
* call-pinentry.c: Include "scdaemon.h" before <assuan.h> because
of GPG_ERR_SOURCE_DEFAULT check.
(unlock_pinentry): Call assuan_release instead of
assuan_disconnect.
(getinfo_pid_cb, getpin_cb): Return gpg_error_t instead of int.
(start_pinentry): Allocate assuan context before connecting to
server.
* call-scd.c (membuf_data_cb, learn_status_cb, get_serialno_cb)
(membuf_data_cb, inq_needpin, card_getattr_cb, pass_status_thru)
(pass_data_thru): Change return type to gpg_error_t.
(start_scd): Allocate assuan context before connecting to server.
common/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
starting server.
g10/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* call-agent.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb)
(learn_status_cb, inq_writecert_parms, inq_writekey_parms)
(scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of
int.
* gpg.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(main): Update to new Assuan API.
* server.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys)
(cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t
instead of int.
(register_commands): Allocate assuan context before starting
server.
(gpg_server): Allocate assuan_context before starting server.
scd/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, open_card, cmd_serialno, cmd_lean, cmd_readcert)
(cmd_readkey, cmd_setdata, cmd_pksign, cmd_pkauth, cmd_pkdecrypt)
(cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_lock)
(cmd_unlock, cmd_getinfo, cmd_restart, cmd_disconnect, cmd_apdu)
(cmd_killscd): Return gpg_error_t instead of int.
(scd_command_handler): Allocate assuan context before starting server.
* scdaemon.c (main): Update to new Assuan API.
sm/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Update to new assuan API.
* server.c: Include "gpgsm.h" before <assuan.h> due to check for
GPG_ERR_SOURCE_DEFAULT and assuan.h now including gpg-error.h.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, cmd_listkeys, cmd_dumpkeys)
(cmd_listsecretkeys, cmd_dumpsecretkeys, cmd_genkey)
(cmd_getauditlog, cmd_getinfo): Return gpg_error_t instead of int.
(register_commands): Same for member HANDLER in table.
(gpgsm_server): Allocate assuan context before starting server.
* sm/call-dirmngr.c:
* call-dirmngr.c (prepare_dirmngr): Check for CTX and error before
setting LDAPSERVER.
(start_dirmngr_ext): Allocate assuan context before starting
server.
(inq_certificate, isvalid_status_cb, lookup_cb, lookup_status_cb)
(run_command_cb, run_command_inq_cb, run_command_status_cb):
Return gpg_error_t instead of int.
tools/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-connect-agent.c (getinfo_pid_cb, read_and_print_response)
(main): Update to new Assuan API.
2009-09-23 00:01:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
switch (module_name_id)
|
2016-06-07 13:48:46 +02:00
|
|
|
{
|
2019-08-05 09:49:09 +02:00
|
|
|
case GNUPG_MODULE_NAME_AGENT:
|
|
|
|
sockname = make_filename (gnupg_socketdir (), GPG_AGENT_SOCK_NAME, NULL);
|
|
|
|
lock_name = "agent";
|
|
|
|
printed_name = "gpg-agent";
|
|
|
|
status_start_line = "starting_agent ? 0 0";
|
|
|
|
no_service_err = GPG_ERR_NO_AGENT;
|
|
|
|
seconds_to_wait = SECS_TO_WAIT_FOR_AGENT;
|
|
|
|
break;
|
|
|
|
case GNUPG_MODULE_NAME_DIRMNGR:
|
|
|
|
sockname = make_filename (gnupg_socketdir (), DIRMNGR_SOCK_NAME, NULL);
|
|
|
|
lock_name = "dirmngr";
|
|
|
|
printed_name = "dirmngr";
|
|
|
|
status_start_line = "starting_dirmngr ? 0 0";
|
|
|
|
no_service_err = GPG_ERR_NO_DIRMNGR;
|
|
|
|
seconds_to_wait = SECS_TO_WAIT_FOR_DIRMNGR;
|
|
|
|
break;
|
2019-08-06 14:28:08 +02:00
|
|
|
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;
|
2019-09-10 16:05:54 +02:00
|
|
|
connect_flags |= ASSUAN_SOCKET_CONNECT_FDPASSING;
|
2019-08-06 14:28:08 +02:00
|
|
|
break;
|
2019-08-05 09:49:09 +02:00
|
|
|
default:
|
|
|
|
err = gpg_error (GPG_ERR_INV_ARG);
|
2016-06-07 13:48:46 +02:00
|
|
|
assuan_release (ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-09-10 16:05:54 +02:00
|
|
|
err = assuan_socket_connect (ctx, sockname, 0, connect_flags);
|
2023-08-29 13:18:13 +02:00
|
|
|
if (err && (flags & ASSHELP_FLAG_AUTOSTART))
|
2007-06-21 18:44:48 +00:00
|
|
|
{
|
2014-10-03 11:58:58 +02:00
|
|
|
char *abs_homedir;
|
|
|
|
lock_spawn_t lock;
|
2014-10-30 09:55:51 +01:00
|
|
|
char *program = NULL;
|
|
|
|
const char *program_arg = NULL;
|
|
|
|
char *p;
|
|
|
|
const char *s;
|
|
|
|
int i;
|
2007-06-21 18:44:48 +00:00
|
|
|
|
2014-10-03 11:58:58 +02:00
|
|
|
/* With no success start a new server. */
|
2019-08-05 09:49:09 +02:00
|
|
|
if (!program_name || !*program_name)
|
|
|
|
program_name = gnupg_module_name (module_name_id);
|
|
|
|
else if ((s=strchr (program_name, '|')) && s[1] == '-' && s[2]=='-')
|
2014-10-30 09:55:51 +01:00
|
|
|
{
|
|
|
|
/* Hack to insert an additional option on the command line. */
|
2019-08-05 09:49:09 +02:00
|
|
|
program = xtrystrdup (program_name);
|
2014-10-30 09:55:51 +01:00
|
|
|
if (!program)
|
|
|
|
{
|
|
|
|
gpg_error_t tmperr = gpg_err_make (errsource,
|
|
|
|
gpg_err_code_from_syserror ());
|
|
|
|
xfree (sockname);
|
|
|
|
assuan_release (ctx);
|
|
|
|
return tmperr;
|
|
|
|
}
|
|
|
|
p = strchr (program, '|');
|
|
|
|
*p++ = 0;
|
|
|
|
program_arg = p;
|
|
|
|
}
|
2007-06-21 18:44:48 +00:00
|
|
|
|
2014-10-03 11:58:58 +02:00
|
|
|
if (verbose)
|
2019-08-05 09:49:09 +02:00
|
|
|
log_info (_("no running %s - starting '%s'\n"),
|
|
|
|
printed_name, program_name);
|
2014-10-03 11:58:58 +02:00
|
|
|
|
|
|
|
if (status_cb)
|
2019-08-05 09:49:09 +02:00
|
|
|
status_cb (status_cb_arg, STATUS_PROGRESS, status_start_line, NULL);
|
2014-10-03 11:58:58 +02:00
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
/* We better pass an absolute home directory to the service just
|
|
|
|
* in case the service does not convert the passed name to an
|
|
|
|
* absolute one (which it should do). */
|
2016-06-07 13:09:00 +02:00
|
|
|
abs_homedir = make_absfilename_try (gnupg_homedir (), NULL);
|
2014-10-03 11:58:58 +02:00
|
|
|
if (!abs_homedir)
|
2007-06-21 18:44:48 +00:00
|
|
|
{
|
2014-10-03 11:58:58 +02:00
|
|
|
gpg_error_t tmperr = gpg_err_make (errsource,
|
|
|
|
gpg_err_code_from_syserror ());
|
2019-08-05 09:49:09 +02:00
|
|
|
log_error ("error building filename: %s\n", gpg_strerror (tmperr));
|
2014-10-03 11:58:58 +02:00
|
|
|
xfree (sockname);
|
|
|
|
assuan_release (ctx);
|
2014-10-30 09:55:51 +01:00
|
|
|
xfree (program);
|
2014-10-03 11:58:58 +02:00
|
|
|
return tmperr;
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2014-10-03 11:58:58 +02:00
|
|
|
if (fflush (NULL))
|
|
|
|
{
|
|
|
|
gpg_error_t tmperr = gpg_err_make (errsource,
|
|
|
|
gpg_err_code_from_syserror ());
|
2019-08-05 09:49:09 +02:00
|
|
|
log_error ("error flushing pending output: %s\n", strerror (errno));
|
2014-10-03 11:58:58 +02:00
|
|
|
xfree (sockname);
|
|
|
|
assuan_release (ctx);
|
|
|
|
xfree (abs_homedir);
|
2014-10-30 09:55:51 +01:00
|
|
|
xfree (program);
|
2014-10-03 11:58:58 +02:00
|
|
|
return tmperr;
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2014-10-30 09:55:51 +01:00
|
|
|
i = 0;
|
|
|
|
argv[i++] = "--homedir";
|
|
|
|
argv[i++] = abs_homedir;
|
2019-08-05 09:49:09 +02:00
|
|
|
if (module_name_id == GNUPG_MODULE_NAME_AGENT)
|
|
|
|
argv[i++] = "--use-standard-socket";
|
2014-10-30 09:55:51 +01:00
|
|
|
if (program_arg)
|
|
|
|
argv[i++] = program_arg;
|
|
|
|
argv[i++] = "--daemon";
|
|
|
|
argv[i++] = NULL;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
if (!(err = lock_spawning (&lock, gnupg_homedir (), lock_name, verbose))
|
2019-09-10 16:05:54 +02:00
|
|
|
&& assuan_socket_connect (ctx, sockname, 0, connect_flags))
|
2014-10-03 11:58:58 +02:00
|
|
|
{
|
2019-07-24 15:32:13 +09:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
common,agent,gpg,dirmngr,g13,scd,tests,tools: New spawn function.
* common/exechelp-posix.c (do_exec, gnupg_spawn_process): Remove.
(check_syscall_func, pre_syscall, post_syscall) : New.
(do_create_socketpair, posix_open_null, call_spawn_cb): New.
(my_exec, spawn_detached, gnupg_spawn_helper): New.
(gnupg_process_spawn, process_kill, gnupg_process_terminate): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_release): New.
(gnupg_process_wait_list): New.
* common/exechelp-w32.c: Add definition of _WIN32_WINNT as 0x600.
(check_syscall_func, pre_syscall, post_syscall): New.
(gnupg_spawn_process): Remove.
(check_windows_version): New.
(spawn_detached, gnupg_spawn_helper, gnupg_process_spawn): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_kill, process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_terminate): New.
(gnupg_process_release, gnupg_process_wait_list): New.
* common/exechelp.h: Re-write for new API.
* common/exectool.c (gnupg_exec_tool_stream): Follow the change.
* common/asshelp.c (start_new_service): Likewise.
* agent/genkey.c (do_check_passphrase_pattern): Likewise.
* dirmngr/ldap-wrapper.c (struct wrapper_context_s): Use PROC.
(destroy_wrapper): Follow the change of API.
(read_log_data): Follow the change of API, use printable_pid.
(ldap_reaper_thread, ldap_wrapper_release_context): Likewise.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Likewise.
* g10/photoid.c (run_with_pipe): Follow the change of API.
(show_photo): Likewise.
* g13/be-encfs.c (run_umount_helper): Likewise.
(run_encfs_tool): Likewise.
* g13/g13.c: Add including ./common/exechelp.h.
* g13/mount.c: Likewise.
* g13/runner.c: Follow the change of API.
* g13/runner.h: Follow the change of API.
* scd/app.c (setup_env): New.
(report_change): Follow the change of API.
* tests/gpgscm/ffi.c (proc_object_finalize): New.
(proc_object_to_string): New.
(proc_wrap, proc_unwrap): New.
(do_spawn_process): Remove.
(do_process_spawn): New.
(setup_std_fds): New.
(do_spawn_process_fd): Remove.
(do_process_spawn_fd): New.
(do_wait_process): Remove.
(do_process_wait): New.
(do_wait_processes): Remove.
* tests/gpgscm/t-child.scm: Follow the change of API.
* tests/gpgscm/tests.scm: Likewise.
* tests/openpgp/defs.scm: Likewise.
* tests/tpm2dtests/defs.scm: Likewise.
* tools/gpg-card.c: Likewise.
* tools/gpgconf-comp.c: Likewise.
* tools/gpgconf.c: Likewise.
* tools/gpgtar-create.c: Likewise.
* tools/gpgtar-extract.c: Likewise.
* tools/gpgtar-list.c: Likewise.
--
GnuPG-bug-id: 6275
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2023-05-11 19:18:21 +09:00
|
|
|
err = gnupg_process_spawn (program? program : program_name, argv,
|
2024-05-31 15:36:39 +09:00
|
|
|
GNUPG_PROCESS_DETACHED, NULL, NULL);
|
2019-09-27 15:44:23 +02:00
|
|
|
#else /*!W32*/
|
common,agent,gpg,dirmngr,g13,scd,tests,tools: New spawn function.
* common/exechelp-posix.c (do_exec, gnupg_spawn_process): Remove.
(check_syscall_func, pre_syscall, post_syscall) : New.
(do_create_socketpair, posix_open_null, call_spawn_cb): New.
(my_exec, spawn_detached, gnupg_spawn_helper): New.
(gnupg_process_spawn, process_kill, gnupg_process_terminate): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_release): New.
(gnupg_process_wait_list): New.
* common/exechelp-w32.c: Add definition of _WIN32_WINNT as 0x600.
(check_syscall_func, pre_syscall, post_syscall): New.
(gnupg_spawn_process): Remove.
(check_windows_version): New.
(spawn_detached, gnupg_spawn_helper, gnupg_process_spawn): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_kill, process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_terminate): New.
(gnupg_process_release, gnupg_process_wait_list): New.
* common/exechelp.h: Re-write for new API.
* common/exectool.c (gnupg_exec_tool_stream): Follow the change.
* common/asshelp.c (start_new_service): Likewise.
* agent/genkey.c (do_check_passphrase_pattern): Likewise.
* dirmngr/ldap-wrapper.c (struct wrapper_context_s): Use PROC.
(destroy_wrapper): Follow the change of API.
(read_log_data): Follow the change of API, use printable_pid.
(ldap_reaper_thread, ldap_wrapper_release_context): Likewise.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Likewise.
* g10/photoid.c (run_with_pipe): Follow the change of API.
(show_photo): Likewise.
* g13/be-encfs.c (run_umount_helper): Likewise.
(run_encfs_tool): Likewise.
* g13/g13.c: Add including ./common/exechelp.h.
* g13/mount.c: Likewise.
* g13/runner.c: Follow the change of API.
* g13/runner.h: Follow the change of API.
* scd/app.c (setup_env): New.
(report_change): Follow the change of API.
* tests/gpgscm/ffi.c (proc_object_finalize): New.
(proc_object_to_string): New.
(proc_wrap, proc_unwrap): New.
(do_spawn_process): Remove.
(do_process_spawn): New.
(setup_std_fds): New.
(do_spawn_process_fd): Remove.
(do_process_spawn_fd): New.
(do_wait_process): Remove.
(do_process_wait): New.
(do_wait_processes): Remove.
* tests/gpgscm/t-child.scm: Follow the change of API.
* tests/gpgscm/tests.scm: Likewise.
* tests/openpgp/defs.scm: Likewise.
* tests/tpm2dtests/defs.scm: Likewise.
* tools/gpg-card.c: Likewise.
* tools/gpgconf-comp.c: Likewise.
* tools/gpgconf.c: Likewise.
* tools/gpgtar-create.c: Likewise.
* tools/gpgtar-extract.c: Likewise.
* tools/gpgtar-list.c: Likewise.
--
GnuPG-bug-id: 6275
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2023-05-11 19:18:21 +09:00
|
|
|
err = gnupg_process_spawn (program? program : program_name, argv,
|
2024-05-31 15:36:39 +09:00
|
|
|
0, NULL, NULL);
|
2019-09-27 15:44:23 +02:00
|
|
|
#endif /*!W32*/
|
2010-05-03 15:23:10 +00:00
|
|
|
if (err)
|
2019-08-05 09:49:09 +02:00
|
|
|
log_error ("failed to start %s '%s': %s\n",
|
|
|
|
printed_name, program? program : program_name,
|
|
|
|
gpg_strerror (err));
|
2014-10-03 11:58:58 +02:00
|
|
|
else
|
2019-08-06 14:28:08 +02:00
|
|
|
err = wait_for_sock (seconds_to_wait, module_name_id,
|
2019-09-10 16:05:54 +02:00
|
|
|
sockname, connect_flags,
|
|
|
|
verbose, ctx, &did_success_msg);
|
2007-06-21 18:44:48 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
unlock_spawning (&lock, lock_name);
|
2014-10-03 11:58:58 +02:00
|
|
|
xfree (abs_homedir);
|
2014-10-30 09:55:51 +01:00
|
|
|
xfree (program);
|
2007-06-21 18:44:48 +00:00
|
|
|
}
|
2014-10-03 11:58:58 +02:00
|
|
|
xfree (sockname);
|
2010-05-03 15:23:10 +00:00
|
|
|
if (err)
|
2007-06-21 18:44:48 +00:00
|
|
|
{
|
2023-08-29 13:18:13 +02:00
|
|
|
if ((flags & ASSHELP_FLAG_AUTOSTART)
|
|
|
|
|| gpg_err_code (err) != GPG_ERR_ASS_CONNECT_FAILED)
|
2019-08-05 09:49:09 +02:00
|
|
|
log_error ("can't connect to the %s: %s\n",
|
|
|
|
printed_name, gpg_strerror (err));
|
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION):
Update to new API (2, 1.1.0).
agent/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-agent.c (parse_rereadable_options): Don't set global assuan
log file (there ain't one anymore).
(main): Update to new API.
(check_own_socket_pid_cb): Return gpg_error_t instead of int.
(check_own_socket_thread, check_for_running_agent): Create assuan
context before connecting to server.
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(write_and_clear_outbuf): Use gpg_error_t instead of
assuan_error_t.
(cmd_geteventcounter, cmd_istrusted, cmd_listtrusted)
(cmd_marktrusted, cmd_havekey, cmd_sigkey, cmd_setkeydesc)
(cmd_sethash, cmd_pksign, cmd_pkdecrypt, cmd_genkey, cmd_readkey)
(cmd_keyinfo, cmd_get_passphrase, cmd_clear_passphrase)
(cmd_get_confirmation, cmd_learn, cmd_passwd)
(cmd_preset_passphrase, cmd_scd, cmd_getval, cmd_putval)
(cmd_updatestartuptty, cmd_killagent, cmd_reloadagent)
(cmd_getinfo, option_handler): Return gpg_error_t instead of int.
(post_cmd_notify): Change type of ERR to gpg_error_t from int.
(io_monitor): Add hook argument. Use symbols for constants.
(register_commands): Change return type of HANDLER to gpg_error_t.
(start_command_handler): Allocate assuan context before starting
server.
* call-pinentry.c: Include "scdaemon.h" before <assuan.h> because
of GPG_ERR_SOURCE_DEFAULT check.
(unlock_pinentry): Call assuan_release instead of
assuan_disconnect.
(getinfo_pid_cb, getpin_cb): Return gpg_error_t instead of int.
(start_pinentry): Allocate assuan context before connecting to
server.
* call-scd.c (membuf_data_cb, learn_status_cb, get_serialno_cb)
(membuf_data_cb, inq_needpin, card_getattr_cb, pass_status_thru)
(pass_data_thru): Change return type to gpg_error_t.
(start_scd): Allocate assuan context before connecting to server.
common/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
starting server.
g10/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* call-agent.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb)
(learn_status_cb, inq_writecert_parms, inq_writekey_parms)
(scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of
int.
* gpg.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(main): Update to new Assuan API.
* server.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys)
(cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t
instead of int.
(register_commands): Allocate assuan context before starting
server.
(gpg_server): Allocate assuan_context before starting server.
scd/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, open_card, cmd_serialno, cmd_lean, cmd_readcert)
(cmd_readkey, cmd_setdata, cmd_pksign, cmd_pkauth, cmd_pkdecrypt)
(cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_lock)
(cmd_unlock, cmd_getinfo, cmd_restart, cmd_disconnect, cmd_apdu)
(cmd_killscd): Return gpg_error_t instead of int.
(scd_command_handler): Allocate assuan context before starting server.
* scdaemon.c (main): Update to new Assuan API.
sm/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Update to new assuan API.
* server.c: Include "gpgsm.h" before <assuan.h> due to check for
GPG_ERR_SOURCE_DEFAULT and assuan.h now including gpg-error.h.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, cmd_listkeys, cmd_dumpkeys)
(cmd_listsecretkeys, cmd_dumpsecretkeys, cmd_genkey)
(cmd_getauditlog, cmd_getinfo): Return gpg_error_t instead of int.
(register_commands): Same for member HANDLER in table.
(gpgsm_server): Allocate assuan context before starting server.
* sm/call-dirmngr.c:
* call-dirmngr.c (prepare_dirmngr): Check for CTX and error before
setting LDAPSERVER.
(start_dirmngr_ext): Allocate assuan context before starting
server.
(inq_certificate, isvalid_status_cb, lookup_cb, lookup_status_cb)
(run_command_cb, run_command_inq_cb, run_command_status_cb):
Return gpg_error_t instead of int.
tools/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-connect-agent.c (getinfo_pid_cb, read_and_print_response)
(main): Update to new Assuan API.
2009-09-23 00:01:25 +00:00
|
|
|
assuan_release (ctx);
|
2019-08-05 09:49:09 +02:00
|
|
|
return gpg_err_make (errsource, no_service_err);
|
2007-06-21 18:44:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 18:46:41 +00:00
|
|
|
if (debug && !did_success_msg)
|
2019-08-05 09:49:09 +02:00
|
|
|
log_debug ("connection to the %s established\n", printed_name);
|
2007-06-21 18:44:48 +00:00
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
if (module_name_id == GNUPG_MODULE_NAME_AGENT)
|
|
|
|
err = assuan_transact (ctx, "RESET",
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
2007-06-21 18:44:48 +00:00
|
|
|
|
2019-08-05 09:49:09 +02:00
|
|
|
if (!err
|
|
|
|
&& module_name_id == GNUPG_MODULE_NAME_AGENT)
|
2014-11-27 20:41:37 +01:00
|
|
|
{
|
|
|
|
err = send_pinentry_environment (ctx, errsource,
|
|
|
|
opt_lc_ctype, opt_lc_messages,
|
|
|
|
session_env);
|
|
|
|
if (gpg_err_code (err) == GPG_ERR_FORBIDDEN
|
|
|
|
&& gpg_err_source (err) == GPG_ERR_SOURCE_GPGAGENT)
|
|
|
|
{
|
2019-08-05 09:49:09 +02:00
|
|
|
/* Check whether the agent is in restricted mode. */
|
2014-11-27 20:41:37 +01:00
|
|
|
if (!assuan_transact (ctx, "GETINFO restricted",
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
if (verbose)
|
2017-11-15 13:46:40 +01:00
|
|
|
log_info (_("connection to the agent is in restricted mode\n"));
|
2014-11-27 20:41:37 +01:00
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-03 15:23:10 +00:00
|
|
|
if (err)
|
2007-06-21 18:44:48 +00:00
|
|
|
{
|
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION):
Update to new API (2, 1.1.0).
agent/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-agent.c (parse_rereadable_options): Don't set global assuan
log file (there ain't one anymore).
(main): Update to new API.
(check_own_socket_pid_cb): Return gpg_error_t instead of int.
(check_own_socket_thread, check_for_running_agent): Create assuan
context before connecting to server.
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(write_and_clear_outbuf): Use gpg_error_t instead of
assuan_error_t.
(cmd_geteventcounter, cmd_istrusted, cmd_listtrusted)
(cmd_marktrusted, cmd_havekey, cmd_sigkey, cmd_setkeydesc)
(cmd_sethash, cmd_pksign, cmd_pkdecrypt, cmd_genkey, cmd_readkey)
(cmd_keyinfo, cmd_get_passphrase, cmd_clear_passphrase)
(cmd_get_confirmation, cmd_learn, cmd_passwd)
(cmd_preset_passphrase, cmd_scd, cmd_getval, cmd_putval)
(cmd_updatestartuptty, cmd_killagent, cmd_reloadagent)
(cmd_getinfo, option_handler): Return gpg_error_t instead of int.
(post_cmd_notify): Change type of ERR to gpg_error_t from int.
(io_monitor): Add hook argument. Use symbols for constants.
(register_commands): Change return type of HANDLER to gpg_error_t.
(start_command_handler): Allocate assuan context before starting
server.
* call-pinentry.c: Include "scdaemon.h" before <assuan.h> because
of GPG_ERR_SOURCE_DEFAULT check.
(unlock_pinentry): Call assuan_release instead of
assuan_disconnect.
(getinfo_pid_cb, getpin_cb): Return gpg_error_t instead of int.
(start_pinentry): Allocate assuan context before connecting to
server.
* call-scd.c (membuf_data_cb, learn_status_cb, get_serialno_cb)
(membuf_data_cb, inq_needpin, card_getattr_cb, pass_status_thru)
(pass_data_thru): Change return type to gpg_error_t.
(start_scd): Allocate assuan context before connecting to server.
common/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* asshelp.c (start_new_gpg_agent): Allocate assuan context before
starting server.
g10/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* call-agent.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(learn_status_cb, dummy_data_cb, get_serialno_cb, default_inq_cb)
(learn_status_cb, inq_writecert_parms, inq_writekey_parms)
(scd_genkey_cb, membuf_data_cb): Return gpg_error_t instead of
int.
* gpg.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(main): Update to new Assuan API.
* server.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, do_listkeys, cmd_listkeys)
(cmd_listsecretkeys, cmd_genkey, cmd_getinfo): Return gpg_error_t
instead of int.
(register_commands): Allocate assuan context before starting
server.
(gpg_server): Allocate assuan_context before starting server.
scd/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* command.c: Include "scdaemon.h" before <assuan.h> because of
GPG_ERR_SOURCE_DEFAULT check.
(option_handler, open_card, cmd_serialno, cmd_lean, cmd_readcert)
(cmd_readkey, cmd_setdata, cmd_pksign, cmd_pkauth, cmd_pkdecrypt)
(cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey)
(cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_lock)
(cmd_unlock, cmd_getinfo, cmd_restart, cmd_disconnect, cmd_apdu)
(cmd_killscd): Return gpg_error_t instead of int.
(scd_command_handler): Allocate assuan context before starting server.
* scdaemon.c (main): Update to new Assuan API.
sm/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Update to new assuan API.
* server.c: Include "gpgsm.h" before <assuan.h> due to check for
GPG_ERR_SOURCE_DEFAULT and assuan.h now including gpg-error.h.
(option_handler, cmd_recipient, cmd_signer, cmd_encrypt)
(cmd_decrypt, cmd_verify, cmd_sign, cmd_import, cmd_export)
(cmd_delkeys, cmd_message, cmd_listkeys, cmd_dumpkeys)
(cmd_listsecretkeys, cmd_dumpsecretkeys, cmd_genkey)
(cmd_getauditlog, cmd_getinfo): Return gpg_error_t instead of int.
(register_commands): Same for member HANDLER in table.
(gpgsm_server): Allocate assuan context before starting server.
* sm/call-dirmngr.c:
* call-dirmngr.c (prepare_dirmngr): Check for CTX and error before
setting LDAPSERVER.
(start_dirmngr_ext): Allocate assuan context before starting
server.
(inq_certificate, isvalid_status_cb, lookup_cb, lookup_status_cb)
(run_command_cb, run_command_inq_cb, run_command_status_cb):
Return gpg_error_t instead of int.
tools/
2009-09-23 Marcus Brinkmann <marcus@g10code.de>
* gpg-connect-agent.c (getinfo_pid_cb, read_and_print_response)
(main): Update to new Assuan API.
2009-09-23 00:01:25 +00:00
|
|
|
assuan_release (ctx);
|
2010-05-03 15:23:10 +00:00
|
|
|
return err;
|
2007-06-21 18:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*r_ctx = ctx;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-16 11:03:43 +00:00
|
|
|
|
Spelling cleanup.
No functional changes, just fixing minor spelling issues.
---
Most of these were identified from the command line by running:
codespell \
--ignore-words-list fpr,stati,keyserver,keyservers,asign,cas,iff,ifset \
--skip '*.po,ChangeLog*,help.*.txt,*.jpg,*.eps,*.pdf,*.png,*.gpg,*.asc' \
doc g13 g10 kbx agent artwork scd tests tools am common dirmngr sm \
NEWS README README.maint TODO
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2020-02-18 09:34:42 -05:00
|
|
|
/* Try to connect to the agent or start a new one. */
|
2019-08-05 09:49:09 +02:00
|
|
|
gpg_error_t
|
|
|
|
start_new_gpg_agent (assuan_context_t *r_ctx,
|
|
|
|
gpg_err_source_t errsource,
|
|
|
|
const char *agent_program,
|
|
|
|
const char *opt_lc_ctype,
|
|
|
|
const char *opt_lc_messages,
|
|
|
|
session_env_t session_env,
|
2023-08-29 13:18:13 +02:00
|
|
|
unsigned int flags,
|
|
|
|
int verbose, int debug,
|
2019-08-05 09:49:09 +02:00
|
|
|
gpg_error_t (*status_cb)(ctrl_t, int, ...),
|
|
|
|
ctrl_t status_cb_arg)
|
|
|
|
{
|
|
|
|
return start_new_service (r_ctx, GNUPG_MODULE_NAME_AGENT,
|
|
|
|
errsource, agent_program,
|
|
|
|
opt_lc_ctype, opt_lc_messages, session_env,
|
2023-08-29 13:18:13 +02:00
|
|
|
flags, verbose, debug,
|
2019-08-05 09:49:09 +02:00
|
|
|
status_cb, status_cb_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-16 11:03:43 +00:00
|
|
|
/* Try to connect to the dirmngr via a socket. On platforms
|
2023-08-29 13:18:13 +02:00
|
|
|
supporting it, start it up if needed and if ASSHELP_FLAG_AUTOSTART is set.
|
2014-11-19 10:31:34 +01:00
|
|
|
Returns a new assuan context at R_CTX or an error code. */
|
2010-08-16 11:03:43 +00:00
|
|
|
gpg_error_t
|
2019-08-06 14:28:08 +02:00
|
|
|
start_new_keyboxd (assuan_context_t *r_ctx,
|
2010-08-16 11:03:43 +00:00
|
|
|
gpg_err_source_t errsource,
|
2019-08-06 14:28:08 +02:00
|
|
|
const char *keyboxd_program,
|
2023-08-29 13:18:13 +02:00
|
|
|
unsigned int flags,
|
|
|
|
int verbose, int debug,
|
2010-08-16 11:03:43 +00:00
|
|
|
gpg_error_t (*status_cb)(ctrl_t, int, ...),
|
|
|
|
ctrl_t status_cb_arg)
|
|
|
|
{
|
2019-08-06 14:28:08 +02:00
|
|
|
return start_new_service (r_ctx, GNUPG_MODULE_NAME_KEYBOXD,
|
|
|
|
errsource, keyboxd_program,
|
|
|
|
NULL, NULL, NULL,
|
2023-08-29 13:18:13 +02:00
|
|
|
flags, verbose, debug,
|
2019-08-06 14:28:08 +02:00
|
|
|
status_cb, status_cb_arg);
|
|
|
|
}
|
2011-02-04 12:57:53 +01:00
|
|
|
|
|
|
|
|
2010-08-16 11:03:43 +00:00
|
|
|
/* Try to connect to the dirmngr via a socket. On platforms
|
2023-08-29 13:18:13 +02:00
|
|
|
supporting it, start it up if needed and if ASSHELP_FLAG_AUTOSTART is set.
|
2014-11-19 10:31:34 +01:00
|
|
|
Returns a new assuan context at R_CTX or an error code. */
|
2010-08-16 11:03:43 +00:00
|
|
|
gpg_error_t
|
|
|
|
start_new_dirmngr (assuan_context_t *r_ctx,
|
|
|
|
gpg_err_source_t errsource,
|
|
|
|
const char *dirmngr_program,
|
2023-08-29 13:18:13 +02:00
|
|
|
unsigned int flags,
|
|
|
|
int verbose, int debug,
|
2010-08-16 11:03:43 +00:00
|
|
|
gpg_error_t (*status_cb)(ctrl_t, int, ...),
|
|
|
|
ctrl_t status_cb_arg)
|
|
|
|
{
|
2019-09-27 15:44:23 +02:00
|
|
|
#ifndef USE_DIRMNGR_AUTO_START
|
2023-08-29 13:18:13 +02:00
|
|
|
flags &= ~ASSHELP_FLAG_AUTOSTART; /* Clear flag. */
|
2019-07-24 15:32:13 +09:00
|
|
|
#endif
|
2019-08-05 09:49:09 +02:00
|
|
|
return start_new_service (r_ctx, GNUPG_MODULE_NAME_DIRMNGR,
|
|
|
|
errsource, dirmngr_program,
|
|
|
|
NULL, NULL, NULL,
|
2023-08-29 13:18:13 +02:00
|
|
|
flags, verbose, debug,
|
2019-08-05 09:49:09 +02:00
|
|
|
status_cb, status_cb_arg);
|
2010-08-16 11:03:43 +00:00
|
|
|
}
|
2016-01-08 06:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Return the version of a server using "GETINFO version". On success
|
|
|
|
0 is returned and R_VERSION receives a malloced string with the
|
|
|
|
version which must be freed by the caller. On error NULL is stored
|
|
|
|
at R_VERSION and an error code returned. Mode is in general 0 but
|
Fix more spelling
* NEWS, acinclude.m4, agent/command-ssh.c, agent/command.c,
agent/gpg-agent.c, agent/keyformat.txt, agent/protect-tool.c,
common/asshelp.c, common/b64enc.c, common/recsel.c, doc/DETAILS,
doc/HACKING, doc/Notes, doc/TRANSLATE, doc/dirmngr.texi,
doc/faq.org, doc/gpg-agent.texi, doc/gpg.texi, doc/gpgsm.texi,
doc/instguide.texi, g10/armor.c, g10/gpg.c, g10/keyedit.c,
g10/mainproc.c, g10/pkclist.c, g10/tofu.c, g13/sh-cmd.c,
g13/sh-dmcrypt.c, kbx/keybox-init.c, m4/pkg.m4, sm/call-dirmngr.c,
sm/gpgsm.c, tests/Makefile.am, tests/gpgscm/Manual.txt,
tests/gpgscm/scheme.c, tests/openpgp/gpgv-forged-keyring.scm,
tests/openpgp/multisig.test, tests/openpgp/verify.scm,
tests/pkits/README, tools/applygnupgdefaults,
tools/gpg-connect-agent.c, tools/mime-maker.c, tools/mime-parser.c:
minor spelling cleanup.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-09-15 14:21:15 -04:00
|
|
|
certain values may be used to modify the used version command:
|
2016-01-08 06:42:29 +01:00
|
|
|
|
|
|
|
MODE == 0 = Use "GETINFO version"
|
|
|
|
MODE == 2 - Use "SCD GETINFO version"
|
|
|
|
*/
|
|
|
|
gpg_error_t
|
|
|
|
get_assuan_server_version (assuan_context_t ctx, int mode, char **r_version)
|
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
membuf_t data;
|
|
|
|
|
|
|
|
init_membuf (&data, 64);
|
|
|
|
err = assuan_transact (ctx,
|
|
|
|
mode == 2? "SCD GETINFO version"
|
|
|
|
/**/ : "GETINFO version",
|
|
|
|
put_membuf_cb, &data,
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
xfree (get_membuf (&data, NULL));
|
|
|
|
*r_version = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
put_membuf (&data, "", 1);
|
|
|
|
*r_version = get_membuf (&data, NULL);
|
|
|
|
if (!*r_version)
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2020-09-01 20:43:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Print a warning if the server's version number is less than our
|
|
|
|
* version number. Returns an error code on a connection problem.
|
2024-05-12 18:09:23 -04:00
|
|
|
* CTX is the Assuan context, SERVERNAME is the name of the server,
|
2020-09-01 20:43:57 +02:00
|
|
|
* STATUS_FUNC and STATUS_FUNC_DATA is a callback to emit status
|
|
|
|
* messages. If PRINT_HINTS is set additional hints are printed. For
|
|
|
|
* MODE see get_assuan_server_version. */
|
|
|
|
gpg_error_t
|
|
|
|
warn_server_version_mismatch (assuan_context_t ctx,
|
|
|
|
const char *servername, int mode,
|
|
|
|
gpg_error_t (*status_func)(ctrl_t ctrl,
|
|
|
|
int status_no,
|
|
|
|
...),
|
|
|
|
void *status_func_ctrl,
|
|
|
|
int print_hints)
|
|
|
|
{
|
|
|
|
gpg_error_t err;
|
|
|
|
char *serverversion;
|
|
|
|
const char *myversion = gpgrt_strusage (13);
|
|
|
|
|
|
|
|
err = get_assuan_server_version (ctx, mode, &serverversion);
|
|
|
|
if (err)
|
|
|
|
log_log (gpg_err_code (err) == GPG_ERR_NOT_SUPPORTED?
|
|
|
|
GPGRT_LOGLVL_INFO : GPGRT_LOGLVL_ERROR,
|
|
|
|
_("error getting version from '%s': %s\n"),
|
|
|
|
servername, gpg_strerror (err));
|
|
|
|
else if (compare_version_strings (serverversion, myversion) < 0)
|
|
|
|
{
|
|
|
|
char *warn;
|
|
|
|
|
|
|
|
warn = xtryasprintf (_("server '%s' is older than us (%s < %s)"),
|
|
|
|
servername, serverversion, myversion);
|
|
|
|
if (!warn)
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_info (_("WARNING: %s\n"), warn);
|
|
|
|
if (print_hints)
|
|
|
|
{
|
|
|
|
log_info (_("Note: Outdated servers may lack important"
|
|
|
|
" security fixes.\n"));
|
|
|
|
log_info (_("Note: Use the command \"%s\" to restart them.\n"),
|
|
|
|
"gpgconf --kill all");
|
|
|
|
}
|
|
|
|
if (status_func)
|
|
|
|
status_func (status_func_ctrl, STATUS_WARNING,
|
|
|
|
"server_version_mismatch 0", warn, NULL);
|
|
|
|
xfree (warn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xfree (serverversion);
|
|
|
|
return err;
|
|
|
|
}
|