aboutsummaryrefslogtreecommitdiffstats
path: root/common/asshelp.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-03-12 18:33:30 +0000
committerWerner Koch <[email protected]>2014-03-14 11:36:36 +0000
commit5d321eb00be0774418de1a05678ac0ec44d7193b (patch)
tree6a794d25d31daba2681fec6bb421e1f615e0b88b /common/asshelp.c
parentgpg: Add option --dirmngr-program. (diff)
downloadgnupg-5d321eb00be0774418de1a05678ac0ec44d7193b.tar.gz
gnupg-5d321eb00be0774418de1a05678ac0ec44d7193b.zip
dirmngr: Default to a user socket name and enable autostart.
* common/homedir.c (dirmngr_socket_name): Rename to dirmngr_sys_socket_name. (dirmngr_user_socket_name): New. * common/asshelp.c (start_new_dirmngr): Handle sys and user dirmngr socket. * dirmngr/dirmngr.c (main): Ditto. * dirmngr/server.c (cmd_getinfo): Ditto. * sm/server.c (gpgsm_server): Ditto. * dirmngr/dirmngr-client.c (start_dirmngr): Likewise. * tools/gpgconf.c (main): Print "dirmngr-sys-socket" with --list-dirs. * configure.ac (USE_DIRMNGR_AUTO_START): Set by default.
Diffstat (limited to 'common/asshelp.c')
-rw-r--r--common/asshelp.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/common/asshelp.c b/common/asshelp.c
index b5dde5a46..4763de1b3 100644
--- a/common/asshelp.c
+++ b/common/asshelp.c
@@ -600,19 +600,41 @@ start_new_dirmngr (assuan_context_t *r_ctx,
return err;
}
- sockname = dirmngr_socket_name ();
+ sockname = dirmngr_user_socket_name ();
+ if (sockname)
+ {
+ /* First try the local socket name and only if that fails try
+ the system socket. */
+ err = assuan_socket_connect (ctx, sockname, 0, 0);
+ if (err)
+ sockname = dirmngr_sys_socket_name ();
+ }
+ else
+ sockname = dirmngr_sys_socket_name ();
+
err = assuan_socket_connect (ctx, sockname, 0, 0);
+
#ifdef USE_DIRMNGR_AUTO_START
if (err)
{
lock_spawn_t lock;
- const char *argv[2];
+ const char *argv[4];
+ int try_system_daemon = 0;
+ char *abs_homedir;
+
+ /* No connection: Try start a new Dirmngr. On Windows this will
+ fail because the Dirmngr is expected to be a system service.
+ However on WinCE we don't distinguish users and thus we can
+ start it. */
+
+ /* We prefer to start it as a user daemon. */
+ sockname = dirmngr_user_socket_name ();
+ if (!sockname)
+ {
+ sockname = dirmngr_sys_socket_name ();
+ try_system_daemon = 1;
+ }
- /* With no success try start a new Dirmngr. On most systems
- this will fail because the Dirmngr is expected to be a system
- service. However on Wince we don't distinguish users and
- thus we can start it. A future extension might be to use the
- userv system to start the Dirmngr as a system service. */
if (!dirmngr_program || !*dirmngr_program)
dirmngr_program = gnupg_module_name (GNUPG_MODULE_NAME_DIRMNGR);
@@ -624,6 +646,8 @@ start_new_dirmngr (assuan_context_t *r_ctx,
status_cb (status_cb_arg, STATUS_PROGRESS,
"starting_dirmngr ? 0 0", NULL);
+ abs_homedir = make_filename (homedir, NULL);
+
if (fflush (NULL))
{
gpg_error_t tmperr = gpg_err_make (errsource,
@@ -635,12 +659,25 @@ start_new_dirmngr (assuan_context_t *r_ctx,
}
argv[0] = "--daemon";
- argv[1] = NULL;
+ if (try_system_daemon)
+ argv[1] = NULL;
+ else
+ { /* Try starting as user daemon - dirmngr does this if the
+ home directory is given on the command line. */
+ argv[1] = "--homedir";
+ argv[2] = abs_homedir;
+ argv[3] = NULL;
+ }
+
+ /* On the use of HOMEDIR for locking: Under Windows HOMEDIR is
+ not used thus it does not matter. Under Unix we should
+ TRY_SYSTEM_DAEMON should never be true because
+ dirmngr_user_socket_name() won't return NULL. */
if (!(err = lock_spawning (&lock, homedir, "dirmngr", verbose))
&& assuan_socket_connect (ctx, sockname, 0, 0))
{
- err = gnupg_spawn_process_detached (dirmngr_program, argv,NULL);
+ err = gnupg_spawn_process_detached (dirmngr_program, argv, NULL);
if (err)
log_error ("failed to start the dirmngr '%s': %s\n",
dirmngr_program, gpg_strerror (err));
@@ -671,6 +708,7 @@ start_new_dirmngr (assuan_context_t *r_ctx,
}
unlock_spawning (&lock, "dirmngr");
+ xfree (abs_homedir);
}
#else
(void)homedir;