1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-22 19:58:29 +01:00

Allow to run the test without a running agent.

Add new gpg-agent commands.
This commit is contained in:
Werner Koch 2010-05-11 17:52:00 +00:00
parent bf761927c9
commit ce9be10163
11 changed files with 102 additions and 38 deletions

3
NEWS
View File

@ -7,6 +7,9 @@ Noteworthy changes in version 2.0.16 (unreleased)
option --use-standard-socket may now be used to use this feature by option --use-standard-socket may now be used to use this feature by
default. default.
* The gpg-agent commands KILLAGENT and RELOADAGENT are now available
on all platforms.
* Minor bug fixes. * Minor bug fixes.

View File

@ -1,3 +1,12 @@
2010-05-11 Werner Koch <wk@g10code.com>
* agent.h (opt): Add field USE_STANDARD_SOCKET.
* gpg-agent.c (use_standard_socket): Remove. Use new option instead.
* command.c (cmd_killagent, cmd_reloadagent): Provide command also
for non-W32 platforms.
(cmd_getinfo): New subcommands std_session_env and std_startup_env.
2010-05-04 Werner Koch <wk@g10code.com> 2010-05-04 Werner Koch <wk@g10code.com>
* gpg-agent.c (main): Add command --use-standard-socket-p. * gpg-agent.c (main): Add command --use-standard-socket-p.

View File

@ -61,6 +61,8 @@ struct
char *startup_lc_ctype; char *startup_lc_ctype;
char *startup_lc_messages; char *startup_lc_messages;
/* True if we are listening on the standard socket. */
int use_standard_socket;
const char *pinentry_program; /* Filename of the program to start as const char *pinentry_program; /* Filename of the program to start as
pinentry. */ pinentry. */

View File

@ -59,10 +59,8 @@ struct server_local_s
char *keydesc; /* Allocated description for the next key char *keydesc; /* Allocated description for the next key
operation. */ operation. */
int pause_io_logging; /* Used to suppress I/O logging during a command */ int pause_io_logging; /* Used to suppress I/O logging during a command */
#ifdef HAVE_W32_SYSTEM
int stopme; /* If set to true the agent will be terminated after int stopme; /* If set to true the agent will be terminated after
the end of this session. */ the end of this session. */
#endif
int allow_pinentry_notify; /* Set if pinentry notifications should int allow_pinentry_notify; /* Set if pinentry notifications should
be done. */ be done. */
}; };
@ -1590,12 +1588,11 @@ cmd_updatestartuptty (assuan_context_t ctx, char *line)
#ifdef HAVE_W32_SYSTEM
static const char hlp_killagent[] = static const char hlp_killagent[] =
"KILLAGENT\n" "KILLAGENT\n"
"\n" "\n"
"Under Windows we start the agent on the fly. Thus it also make\n" "If the agent has been started using a standard socket\n"
"sense to allow a client to stop the agent."; "we allow a client to stop the agent.";
static gpg_error_t static gpg_error_t
cmd_killagent (assuan_context_t ctx, char *line) cmd_killagent (assuan_context_t ctx, char *line)
{ {
@ -1603,6 +1600,9 @@ cmd_killagent (assuan_context_t ctx, char *line)
(void)line; (void)line;
if (!opt.use_standard_socket)
return set_error (GPG_ERR_NOT_SUPPORTED, "no --use-standard-socket");
ctrl->server_local->stopme = 1; ctrl->server_local->stopme = 1;
return gpg_error (GPG_ERR_EOF); return gpg_error (GPG_ERR_EOF);
} }
@ -1611,8 +1611,8 @@ cmd_killagent (assuan_context_t ctx, char *line)
static const char hlp_reloadagent[] = static const char hlp_reloadagent[] =
"RELOADAGENT\n" "RELOADAGENT\n"
"\n" "\n"
"As signals are inconvenient under Windows, we provide this command\n" "This command is an alternative to SIGHUP\n"
"to allow reloading of the configuration."; "to reload the configuration.";
static gpg_error_t static gpg_error_t
cmd_reloadagent (assuan_context_t ctx, char *line) cmd_reloadagent (assuan_context_t ctx, char *line)
{ {
@ -1622,7 +1622,6 @@ cmd_reloadagent (assuan_context_t ctx, char *line)
agent_sighup_action (); agent_sighup_action ();
return 0; return 0;
} }
#endif /*HAVE_W32_SYSTEM*/
@ -1637,11 +1636,14 @@ static const char hlp_getinfo[] =
" socket_name - Return the name of the socket.\n" " socket_name - Return the name of the socket.\n"
" ssh_socket_name - Return the name of the ssh socket.\n" " ssh_socket_name - Return the name of the ssh socket.\n"
" scd_running - Return OK if the SCdaemon is already running.\n" " scd_running - Return OK if the SCdaemon is already running.\n"
" std_session_env - List the standard session environment.\n"
" std_startup_env - List the standard startup environment.\n"
" cmd_has_option\n" " cmd_has_option\n"
" - Returns OK if the command CMD implements the option OPT."; " - Returns OK if the command CMD implements the option OPT.";
static gpg_error_t static gpg_error_t
cmd_getinfo (assuan_context_t ctx, char *line) cmd_getinfo (assuan_context_t ctx, char *line)
{ {
ctrl_t ctrl = assuan_get_pointer (ctx);
int rc = 0; int rc = 0;
if (!strcmp (line, "version")) if (!strcmp (line, "version"))
@ -1685,6 +1687,34 @@ cmd_getinfo (assuan_context_t ctx, char *line)
snprintf (numbuf, sizeof numbuf, "%lu", get_standard_s2k_count ()); snprintf (numbuf, sizeof numbuf, "%lu", get_standard_s2k_count ());
rc = assuan_send_data (ctx, numbuf, strlen (numbuf)); rc = assuan_send_data (ctx, numbuf, strlen (numbuf));
} }
else if (!strcmp (line, "std_session_env")
|| !strcmp (line, "std_startup_env"))
{
int iterator;
const char *name, *value;
char *string;
iterator = 0;
while ((name = session_env_list_stdenvnames (&iterator, NULL)))
{
value = session_env_getenv_or_default
(line[5] == 't'? opt.startup_env:ctrl->session_env, name, NULL);
if (value)
{
string = xtryasprintf ("%s=%s", name, value);
if (!string)
rc = gpg_error_from_syserror ();
else
{
rc = assuan_send_data (ctx, string, strlen (string)+1);
if (!rc)
rc = assuan_send_data (ctx, NULL, 0);
}
if (rc)
break;
}
}
}
else if (!strncmp (line, "cmd_has_option", 14) else if (!strncmp (line, "cmd_has_option", 14)
&& (line[14] == ' ' || line[14] == '\t' || !line[14])) && (line[14] == ' ' || line[14] == '\t' || !line[14]))
{ {
@ -1881,10 +1911,8 @@ register_commands (assuan_context_t ctx)
{ "GETVAL", cmd_getval, hlp_getval }, { "GETVAL", cmd_getval, hlp_getval },
{ "PUTVAL", cmd_putval, hlp_putval }, { "PUTVAL", cmd_putval, hlp_putval },
{ "UPDATESTARTUPTTY", cmd_updatestartuptty, hlp_updatestartuptty }, { "UPDATESTARTUPTTY", cmd_updatestartuptty, hlp_updatestartuptty },
#ifdef HAVE_W32_SYSTEM
{ "KILLAGENT", cmd_killagent, hlp_killagent }, { "KILLAGENT", cmd_killagent, hlp_killagent },
{ "RELOADAGENT", cmd_reloadagent,hlp_reloadagent }, { "RELOADAGENT", cmd_reloadagent,hlp_reloadagent },
#endif
{ "GETINFO", cmd_getinfo, hlp_getinfo }, { "GETINFO", cmd_getinfo, hlp_getinfo },
{ NULL } { NULL }
}; };
@ -1991,10 +2019,8 @@ start_command_handler (ctrl_t ctrl, gnupg_fd_t listen_fd, gnupg_fd_t fd)
/* Cleanup. */ /* Cleanup. */
assuan_release (ctx); assuan_release (ctx);
#ifdef HAVE_W32_SYSTEM
if (ctrl->server_local->stopme) if (ctrl->server_local->stopme)
agent_exit (0); agent_exit (0);
#endif
xfree (ctrl->server_local); xfree (ctrl->server_local);
ctrl->server_local = NULL; ctrl->server_local = NULL;
} }

View File

@ -217,9 +217,6 @@ static int shutdown_pending;
/* Counter for the currently running own socket checks. */ /* Counter for the currently running own socket checks. */
static int check_own_socket_running; static int check_own_socket_running;
/* True if we are listening on the standard socket. */
static int use_standard_socket;
/* It is possible that we are currently running under setuid permissions */ /* It is possible that we are currently running under setuid permissions */
static int maybe_setuid = 1; static int maybe_setuid = 1;
@ -631,8 +628,8 @@ main (int argc, char **argv )
/* Set default options. */ /* Set default options. */
parse_rereadable_options (NULL, 0); /* Reset them to default values. */ parse_rereadable_options (NULL, 0); /* Reset them to default values. */
#ifdef USE_STANDARD_SOCKET #ifdef USE_STANDARD_SOCKET
use_standard_socket = 1; /* Under Windows we always use a standard opt.use_standard_socket = 1; /* Under Windows we always use a standard
socket. */ socket. */
#endif #endif
shell = getenv ("SHELL"); shell = getenv ("SHELL");
@ -783,8 +780,8 @@ main (int argc, char **argv )
case oXauthority: default_xauthority = xstrdup (pargs.r.ret_str); case oXauthority: default_xauthority = xstrdup (pargs.r.ret_str);
break; break;
case oUseStandardSocket: use_standard_socket = 1; break; case oUseStandardSocket: opt.use_standard_socket = 1; break;
case oNoUseStandardSocket: use_standard_socket = 0; break; case oNoUseStandardSocket: opt.use_standard_socket = 0; break;
case oFakedSystemTime: case oFakedSystemTime:
{ {
@ -862,7 +859,7 @@ main (int argc, char **argv )
} }
if (gpgconf_list == 3) if (gpgconf_list == 3)
agent_exit (!use_standard_socket); agent_exit (!opt.use_standard_socket);
if (gpgconf_list == 2) if (gpgconf_list == 2)
agent_exit (0); agent_exit (0);
if (gpgconf_list) if (gpgconf_list)
@ -1437,7 +1434,7 @@ create_socket_name (char *standard_name, char *template)
{ {
char *name, *p; char *name, *p;
if (use_standard_socket) if (opt.use_standard_socket)
name = make_filename (opt.homedir, standard_name, NULL); name = make_filename (opt.homedir, standard_name, NULL);
else else
{ {
@ -1500,7 +1497,7 @@ create_server_socket (char *name, int is_ssh, assuan_sock_nonce_t *nonce)
strcpy (serv_addr->sun_path, name); strcpy (serv_addr->sun_path, name);
len = SUN_LEN (serv_addr); len = SUN_LEN (serv_addr);
rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len); rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
if (use_standard_socket && rc == -1 && errno == EADDRINUSE) if (opt.use_standard_socket && rc == -1 && errno == EADDRINUSE)
{ {
/* Check whether a gpg-agent is already running on the standard /* Check whether a gpg-agent is already running on the standard
socket. We do this test only if this is not the ssh socket. socket. We do this test only if this is not the ssh socket.
@ -1533,7 +1530,7 @@ create_server_socket (char *name, int is_ssh, assuan_sock_nonce_t *nonce)
gpg_strerror (gpg_error_from_errno (errno))); gpg_strerror (gpg_error_from_errno (errno)));
assuan_sock_close (fd); assuan_sock_close (fd);
if (use_standard_socket) if (opt.use_standard_socket)
*name = 0; /* Inhibit removal of the socket by cleanup(). */ *name = 0; /* Inhibit removal of the socket by cleanup(). */
agent_exit (2); agent_exit (2);
} }
@ -2170,7 +2167,7 @@ check_own_socket (void)
char *sockname; char *sockname;
pth_attr_t tattr; pth_attr_t tattr;
if (!use_standard_socket) if (!opt.use_standard_socket)
return; /* This check makes only sense in standard socket mode. */ return; /* This check makes only sense in standard socket mode. */
if (check_own_socket_running || shutdown_pending) if (check_own_socket_running || shutdown_pending)

View File

@ -433,8 +433,9 @@ named @file{S.gpg-agent}, located in the home directory, and not create
a random socket below a temporary directory. Tools connecting to a random socket below a temporary directory. Tools connecting to
@command{gpg-agent} should first try to connect to the socket given in @command{gpg-agent} should first try to connect to the socket given in
environment variable @var{GPG_AGENT_INFO} and then fall back to this environment variable @var{GPG_AGENT_INFO} and then fall back to this
socket. This option may not be used if the home directory is mounted as socket. This option may not be used if the home directory is mounted on
a remote file system. Note, that @option{--use-standard-socket} is the a remote file system which does not support special files like fifos or
sockets. Note, that @option{--use-standard-socket} is the
default on Windows systems. The default may be changed at build time. default on Windows systems. The default may be changed at build time.
It is possible to test at runtime whether the agent has been configured It is possible to test at runtime whether the agent has been configured
for use with the standard socket by issuing the command for use with the standard socket by issuing the command

View File

@ -30,7 +30,7 @@ SUBDIRS = ${openpgp} . pkits
GPGSM = ../sm/gpgsm GPGSM = ../sm/gpgsm
# Note that we need to use /bin/pwd so that we don't get into trouble # Note that we need to use /bin/pwd so that we don't get into trouble
# if the shell used for inittests would uses an internal version of # if the shell used for inittests would use an internal version of
# pwd which handles symlinks differently. # pwd which handles symlinks differently.
TESTS_ENVIRONMENT = GNUPGHOME=`/bin/pwd` GPG_AGENT_INFO= LC_ALL=C \ TESTS_ENVIRONMENT = GNUPGHOME=`/bin/pwd` GPG_AGENT_INFO= LC_ALL=C \
GPGSM=$(GPGSM) $(srcdir)/runtest GPGSM=$(GPGSM) $(srcdir)/runtest

View File

@ -1,3 +1,13 @@
2010-05-11 Werner Koch <wk@g10code.com>
* genkey1024.test: Use GPG macro.
* gpg-agent.conf.tmpl: New.
* defs.inc: Create gpg-agent.conf
(GNUPGHOME): Set and export.
(GPG_AGENT_INFO): Unset
* Makefile.am (CLEANFILES): Add S.gpg-agent
2009-12-21 Werner Koch <wk@g10code.com> 2009-12-21 Werner Koch <wk@g10code.com>
* Makefile.am (required_pgms): New. * Makefile.am (required_pgms): New.

View File

@ -40,15 +40,19 @@ TESTS = version.test mds.test \
TEST_FILES = pubring.asc secring.asc plain-1o.asc plain-2o.asc plain-3o.asc \ TEST_FILES = pubring.asc secring.asc plain-1o.asc plain-2o.asc plain-3o.asc \
plain-1.asc plain-2.asc plain-3.asc plain-1-pgp.asc \ plain-1.asc plain-2.asc plain-3.asc plain-1-pgp.asc \
pubring.pkr.asc secring.skr.asc secdemo.asc pubdemo.asc \ pubring.pkr.asc secring.skr.asc secdemo.asc pubdemo.asc \
gpg.conf.tmpl bug537-test.data.asc bug894-test.asc gpg.conf.tmpl gpg-agent.conf.tmpl \
bug537-test.data.asc bug894-test.asc
DATA_FILES = data-500 data-9000 data-32000 data-80000 plain-large DATA_FILES = data-500 data-9000 data-32000 data-80000 plain-large
EXTRA_DIST = defs.inc $(TESTS) $(TEST_FILES) \ EXTRA_DIST = defs.inc $(TESTS) $(TEST_FILES) \
mkdemodirs signdemokey mkdemodirs signdemokey
# Note that removing S.gpg-agent forces a running gpg-agent to
# terminate after some time.
CLEANFILES = prepared.stamp x y yy z out err $(DATA_FILES) \ CLEANFILES = prepared.stamp x y yy z out err $(DATA_FILES) \
plain-1 plain-2 plain-3 trustdb.gpg *.lock .\#lk* \ plain-1 plain-2 plain-3 trustdb.gpg *.lock .\#lk* \
*.test.log gpg_dearmor gpg.conf \ *.test.log gpg_dearmor gpg.conf gpg-agent.conf S.gpg-agent \
pubring.gpg secring.gpg pubring.pkr secring.skr pubring.gpg secring.gpg pubring.pkr secring.skr
DISTCLEANFILES = pubring.gpg~ random_seed DISTCLEANFILES = pubring.gpg~ random_seed

View File

@ -161,14 +161,26 @@ pgmname=`basename $0`
[ -z "$srcdir" ] && fatal "not called from make" [ -z "$srcdir" ] && fatal "not called from make"
# Make sure we have a valid option files even with VPATH builds. # Make sure we have a valid option file even with VPATH builds.
if [ -f ./gpg.conf ]; then for f in gpg.conf gpg-agent.conf; do
: if [ -f ./$f ]; then
elif [ -f $srcdir/gpg.conf.tmpl ]; then :
cat $srcdir/gpg.conf.tmpl >gpg.conf elif [ -f $srcdir/$f.tmpl ]; then
fi cat $srcdir/$f.tmpl >$f
fi
done
GPG="../../g10/gpg2 --no-permission-warning --homedir . " # Always work in the current directory
GNUPGHOME=`pwd`
export GNUPGHOME
# We do not use an external info variable for gpg-agent because we use
# a standard socket in the home directory. This way gpg-agent will be
# started as soon as needed. It is terminated indirectly using a
# Makefile rule.
GPG_AGENT_INFO=
GPG="../../g10/gpg2 --no-permission-warning "
exec 5>&2 2>${pgmname}.log exec 5>&2 2>${pgmname}.log

View File

@ -10,7 +10,7 @@
. $srcdir/defs.inc || exit 3 . $srcdir/defs.inc || exit 3
../../g10/gpg2 --quiet --batch --debug-quick-random --homedir . --gen-key <<EOF $GPG --quiet --batch --debug-quick-random --gen-key <<EOF
Key-Type: DSA Key-Type: DSA
Key-Length: 1024 Key-Length: 1024
Subkey-Type: ELG Subkey-Type: ELG
@ -24,7 +24,7 @@ Passphrase: abc
EOF EOF
if have_pubkey_algo "RSA"; then if have_pubkey_algo "RSA"; then
../../g10/gpg2 --quiet --batch --debug-quick-random --homedir . --gen-key <<EOF $GPG --quiet --batch --debug-quick-random --gen-key <<EOF
Key-Type: RSA Key-Type: RSA
Key-Length: 1024 Key-Length: 1024
Key-Usage: sign,encrypt Key-Usage: sign,encrypt