summaryrefslogtreecommitdiffstats
path: root/dirmngr
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2010-08-12 13:43:46 +0200
committerWerner Koch <wk@gnupg.org>2010-08-12 13:43:46 +0200
commitd4d61b87f153f5c0657a5f698983a20b5398cfff (patch)
tree736a4302a4d11f586f47d50a0d40583f1835385e /dirmngr
parentPass on comments from SCD. (diff)
downloadgnupg2-d4d61b87f153f5c0657a5f698983a20b5398cfff.tar.xz
gnupg2-d4d61b87f153f5c0657a5f698983a20b5398cfff.zip
Fix dirmngr problems on CE.
Add new dirmngr commands. Minor other fixes.
Diffstat (limited to 'dirmngr')
-rw-r--r--dirmngr/ChangeLog11
-rw-r--r--dirmngr/crlcache.c6
-rw-r--r--dirmngr/dirmngr.c23
-rw-r--r--dirmngr/dirmngr.h1
-rw-r--r--dirmngr/server.c80
5 files changed, 109 insertions, 12 deletions
diff --git a/dirmngr/ChangeLog b/dirmngr/ChangeLog
index 737ff35fa..8f861c6a0 100644
--- a/dirmngr/ChangeLog
+++ b/dirmngr/ChangeLog
@@ -1,9 +1,18 @@
+2010-08-12 Werner Koch <wk@g10code.com>
+
+ * crlcache.c (update_dir, crl_cache_insert): s/unlink/gnupg_remove/.
+
+ * dirmngr.c (dirmngr_sighup_action): New.
+
+ * server.c (cmd_killdirmngr, cmd_reloaddirmngr): New.
+ (struct server_local_s): Add field STOPME.
+ (start_command_handler): Act on STOPME.
+
2010-08-06 Werner Koch <wk@g10code.com>
* dirmngr.c (JNLIB_NEED_AFLOCAL): Define macro.
(main): Use SUN_LEN macro.
(main) [W32]: Allow EEXIST in addition to EADDRINUSE.
- (JNLIB_NEED_AFLOCAL):
2010-08-05 Werner Koch <wk@g10code.com>
diff --git a/dirmngr/crlcache.c b/dirmngr/crlcache.c
index e08741924..14bffe350 100644
--- a/dirmngr/crlcache.c
+++ b/dirmngr/crlcache.c
@@ -274,7 +274,7 @@ cleanup_cache_dir (int force)
if (okay)
{
log_info (_("removing cache file `%s'\n"), cdbname);
- if (unlink (cdbname))
+ if (gnupg_remove (cdbname))
{
log_error ("failed to remove `%s': %s\n",
cdbname, strerror (errno));
@@ -934,7 +934,7 @@ update_dir (crl_cache_t cache)
#ifdef HAVE_W32_SYSTEM
/* No atomic mv on W32 systems. */
- unlink (fname);
+ gnupg_remove (fname);
#endif
if (rename (tmpfname, fname))
{
@@ -2166,7 +2166,7 @@ crl_cache_insert (ctrl_t ctrl, const char *url, ksba_reader_t reader)
if (opt.verbose)
log_info (_("creating cache file `%s'\n"), newfname);
#ifdef HAVE_W32_SYSTEM
- unlink (newfname);
+ gnupg_remove (newfname);
#endif
if (rename (fname, newfname))
{
diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
index 7aafc48ce..771a58642 100644
--- a/dirmngr/dirmngr.c
+++ b/dirmngr/dirmngr.c
@@ -1578,6 +1578,21 @@ reread_configuration (void)
}
+/* A global function which allows us to trigger the reload stuff from
+ other places. */
+void
+dirmngr_sighup_action (void)
+{
+ log_info (_("SIGHUP received - "
+ "re-reading configuration and flushing caches\n"));
+ reread_configuration ();
+ cert_cache_deinit (0);
+ crl_cache_deinit ();
+ cert_cache_init ();
+ crl_cache_init ();
+}
+
+
/* The signal handler. */
static void
@@ -1587,13 +1602,7 @@ handle_signal (int signo)
{
#ifndef HAVE_W32_SYSTEM
case SIGHUP:
- log_info (_("SIGHUP received - "
- "re-reading configuration and flushing caches\n"));
- reread_configuration ();
- cert_cache_deinit (0);
- crl_cache_deinit ();
- cert_cache_init ();
- crl_cache_init ();
+ dirmngr_sighup_action ();
break;
case SIGUSR1:
diff --git a/dirmngr/dirmngr.h b/dirmngr/dirmngr.h
index 67f2122d9..01478a64f 100644
--- a/dirmngr/dirmngr.h
+++ b/dirmngr/dirmngr.h
@@ -169,6 +169,7 @@ struct server_control_s
/*-- dirmngr.c --*/
void dirmngr_exit( int ); /* Wrapper for exit() */
void dirmngr_init_default_ctrl (ctrl_t ctrl);
+void dirmngr_sighup_action (void);
/*-- server.c --*/
ldap_server_t get_ldapservers_from_ctrl (ctrl_t ctrl);
diff --git a/dirmngr/server.c b/dirmngr/server.c
index 584cae743..1293dbe77 100644
--- a/dirmngr/server.c
+++ b/dirmngr/server.c
@@ -60,6 +60,10 @@ struct server_local_s
/* Per-session LDAP serfver. */
ldap_server_t ldapservers;
+
+ /* If this flag is set to true this dirmngr process will be
+ terminated after the end of this session. */
+ int stopme;
};
@@ -1218,7 +1222,7 @@ static const char hlp_cachecert[] =
"\n"
"Put a certificate into the internal cache. This command might be\n"
"useful if a client knows in advance certificates required for a\n"
- "test and wnats to make sure they get added to the internal cache.\n"
+ "test and wants to make sure they get added to the internal cache.\n"
"It is also helpful for debugging. To get the actual certificate,\n"
"this command immediately inquires it using\n"
"\n"
@@ -1376,6 +1380,75 @@ cmd_getinfo (assuan_context_t ctx, char *line)
}
+
+static const char hlp_killdirmngr[] =
+ "KILLDIRMNGR\n"
+ "\n"
+ "This command allows a user - given sufficient permissions -\n"
+ "to kill this dirmngr process.\n";
+static gpg_error_t
+cmd_killdirmngr (assuan_context_t ctx, char *line)
+{
+ ctrl_t ctrl = assuan_get_pointer (ctx);
+
+ (void)line;
+
+ if (opt.system_daemon)
+ {
+ if (opt.system_service)
+ return set_error (GPG_ERR_NOT_SUPPORTED,
+ "can't do that whilst running as system service");
+#ifndef HAVE_W32_SYSTEM
+ {
+ gpg_err_code_t ec;
+ assuan_peercred_t cred;
+
+ ec = gpg_err_code (assuan_get_peercred (ctx, &cred));
+ if (!ec && cred.uid)
+ ec = GPG_ERR_EPERM; /* Only root may terminate. */
+ if (ec)
+ return set_error (ec, "no permission to kill this process");
+ }
+#endif
+ }
+
+ ctrl->server_local->stopme = 1;
+ return gpg_error (GPG_ERR_EOF);
+}
+
+
+static const char hlp_reloaddirmngr[] =
+ "RELOADDIRMNGR\n"
+ "\n"
+ "This command is an alternative to SIGHUP\n"
+ "to reload the configuration.";
+static gpg_error_t
+cmd_reloaddirmngr (assuan_context_t ctx, char *line)
+{
+ (void)ctx;
+ (void)line;
+
+ if (opt.system_daemon)
+ {
+#ifndef HAVE_W32_SYSTEM
+ {
+ gpg_err_code_t ec;
+ assuan_peercred_t cred;
+
+ ec = gpg_err_code (assuan_get_peercred (ctx, &cred));
+ if (!ec && cred.uid)
+ ec = GPG_ERR_EPERM; /* Only root may terminate. */
+ if (ec)
+ return set_error (ec, "no permission to reload this process");
+ }
+#endif
+ }
+
+ dirmngr_sighup_action ();
+ return 0;
+}
+
+
/* Tell the assuan library about our commands. */
@@ -1397,6 +1470,8 @@ register_commands (assuan_context_t ctx)
{ "CACHECERT", cmd_cachecert, hlp_cachecert },
{ "VALIDATE", cmd_validate, hlp_validate },
{ "GETINFO", cmd_getinfo, hlp_getinfo },
+ { "KILLDIRMNGR",cmd_killdirmngr,hlp_killdirmngr },
+ { "RELOADDIRMNGR",cmd_reloaddirmngr,hlp_reloaddirmngr },
{ NULL, NULL }
};
int i, j, rc;
@@ -1552,6 +1627,9 @@ start_command_handler (assuan_fd_t fd)
ctrl->server_local->assuan_ctx = NULL;
assuan_release (ctx);
+ if (ctrl->server_local->stopme)
+ dirmngr_exit (0);
+
if (ctrl->refcount)
log_error ("oops: connection control structure still referenced (%d)\n",
ctrl->refcount);