aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common/asshelp.c56
-rw-r--r--common/homedir.c20
-rw-r--r--common/util.h3
3 files changed, 67 insertions, 12 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;
diff --git a/common/homedir.c b/common/homedir.c
index 77622a1d4..e2a117bd7 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -555,9 +555,9 @@ gnupg_cachedir (void)
}
-/* Return the default socket name used by DirMngr. */
+/* Return the system socket name used by DirMngr. */
const char *
-dirmngr_socket_name (void)
+dirmngr_sys_socket_name (void)
{
#ifdef HAVE_W32_SYSTEM
static char *name;
@@ -600,6 +600,22 @@ dirmngr_socket_name (void)
}
+/* Return the user socket name used by DirMngr. If a a user specific
+ dirmngr installation is not supported, NULL is returned. */
+const char *
+dirmngr_user_socket_name (void)
+{
+#ifdef HAVE_W32_SYSTEM
+ return NULL; /* We support only a system service. */
+#else /*!HAVE_W32_SYSTEM*/
+ static char *name;
+
+ if (!name)
+ name = make_filename (default_homedir (), DIRMNGR_SOCK_NAME, NULL);
+ return name;
+#endif /*!HAVE_W32_SYSTEM*/
+}
+
/* Return the file name of a helper tool. WHICH is one of the
GNUPG_MODULE_NAME_foo constants. */
diff --git a/common/util.h b/common/util.h
index c4acb0bd3..4b3cbfc4d 100644
--- a/common/util.h
+++ b/common/util.h
@@ -231,7 +231,8 @@ const char *gnupg_libdir (void);
const char *gnupg_datadir (void);
const char *gnupg_localedir (void);
const char *gnupg_cachedir (void);
-const char *dirmngr_socket_name (void);
+const char *dirmngr_sys_socket_name (void);
+const char *dirmngr_user_socket_name (void);
/* All module names. We also include gpg and gpgsm for the sake for
gpgconf. */