summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@g10code.com>2015-03-28 17:23:56 +0100
committerNeal H. Walfield <neal@g10code.com>2015-03-31 11:58:41 +0200
commit348c520040a31f5c322183c0654a34978e2baf6f (patch)
tree2916b77e0c22088efe56d1b6a97fd2c48c695f9c
parentgpg: Only use the last specified keyserver. (diff)
downloadgnupg2-348c520040a31f5c322183c0654a34978e2baf6f.tar.xz
gnupg2-348c520040a31f5c322183c0654a34978e2baf6f.zip
dirmngr: Better encapsulate the keyservers variable.
* dirmngr/dirmngr.h (struct server_control_s): Move field keyservers from here... * dirmngr/server.c (struct server_local_s): ... to here. Update users. * dirmngr/ks-action.h (ks_action_resolve): Add argument keyservers. (ks_action_search): Likewise. (ks_action_get): Likewise. (ks_action_put): Likewise. * dirmngr/ks-action.c (ks_action_resolve): Add argument keyservers. Use it instead of ctrl->keyservers. (ks_action_search): Likewise. (ks_action_get): Likewise. (ks_action_put): Likewise. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>
-rw-r--r--dirmngr/dirmngr.h3
-rw-r--r--dirmngr/ks-action.c21
-rw-r--r--dirmngr/ks-action.h11
-rw-r--r--dirmngr/server.c36
4 files changed, 41 insertions, 30 deletions
diff --git a/dirmngr/dirmngr.h b/dirmngr/dirmngr.h
index 3dd16a348..320d178fd 100644
--- a/dirmngr/dirmngr.h
+++ b/dirmngr/dirmngr.h
@@ -1,6 +1,6 @@
/* dirmngr.h - Common definitions for the dirmngr
* Copyright (C) 2002 Klarälvdalens Datakonsult AB
- * Copyright (C) 2004 g10 Code GmbH
+ * Copyright (C) 2004, 2015 g10 Code GmbH
* Copyright (C) 2014 Werner Koch
*
* This file is part of GnuPG.
@@ -174,7 +174,6 @@ struct server_control_s
response. */
int audit_events; /* Send audit events to client. */
- uri_item_t keyservers; /* List of keyservers. */
};
diff --git a/dirmngr/ks-action.c b/dirmngr/ks-action.c
index 6cfb598e4..c76aaaa2d 100644
--- a/dirmngr/ks-action.c
+++ b/dirmngr/ks-action.c
@@ -1,7 +1,7 @@
/* ks-action.c - OpenPGP keyserver actions
* Copyright (C) 2011 Free Software Foundation, Inc.
* Copyright (C) 2011, 2014 Werner Koch
- * Copyright (C) 2015 g10 Code GmbH
+ * Copyright (C) 2015 g10 Code GmbH
*
* This file is part of GnuPG.
*
@@ -105,13 +105,13 @@ ks_action_help (ctrl_t ctrl, const char *url)
/* Resolve all host names. This is useful for looking at the status
of configured keyservers. */
gpg_error_t
-ks_action_resolve (ctrl_t ctrl)
+ks_action_resolve (ctrl_t ctrl, uri_item_t keyservers)
{
gpg_error_t err = 0;
int any_server = 0;
uri_item_t uri;
- for (uri = ctrl->keyservers; !err && uri; uri = uri->next)
+ for (uri = keyservers; !err && uri; uri = uri->next)
{
if (uri->parsed_uri->is_http)
{
@@ -131,7 +131,8 @@ ks_action_resolve (ctrl_t ctrl)
/* Search all configured keyservers for keys matching PATTERNS and
write the result to the provided output stream. */
gpg_error_t
-ks_action_search (ctrl_t ctrl, strlist_t patterns, estream_t outfp)
+ks_action_search (ctrl_t ctrl, uri_item_t keyservers,
+ strlist_t patterns, estream_t outfp)
{
gpg_error_t err = 0;
int any_server = 0;
@@ -147,7 +148,7 @@ ks_action_search (ctrl_t ctrl, strlist_t patterns, estream_t outfp)
errors - it might not be the best idea to ignore an error from
one server and silently continue with another server. For now we
stop at the first error. */
- for (uri = ctrl->keyservers; !err && uri; uri = uri->next)
+ for (uri = keyservers; !err && uri; uri = uri->next)
{
int is_http = uri->parsed_uri->is_http;
int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0
@@ -179,7 +180,8 @@ ks_action_search (ctrl_t ctrl, strlist_t patterns, estream_t outfp)
/* Get the requested keys (matching PATTERNS) using all configured
keyservers and write the result to the provided output stream. */
gpg_error_t
-ks_action_get (ctrl_t ctrl, strlist_t patterns, estream_t outfp)
+ks_action_get (ctrl_t ctrl, uri_item_t keyservers,
+ strlist_t patterns, estream_t outfp)
{
gpg_error_t err = 0;
gpg_error_t first_err = 0;
@@ -198,7 +200,7 @@ ks_action_get (ctrl_t ctrl, strlist_t patterns, estream_t outfp)
keyservers might not all be fully synced thus it is not clear
whether the first keyserver has the freshest copy of the key.
Need to think about a better strategy. */
- for (uri = ctrl->keyservers; !err && uri; uri = uri->next)
+ for (uri = keyservers; !err && uri; uri = uri->next)
{
int is_http = uri->parsed_uri->is_http;
int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0
@@ -311,7 +313,8 @@ ks_action_fetch (ctrl_t ctrl, const char *url, estream_t outfp)
KEYID; done'. This function may modify DATA and INFO. If this is
a problem, then the caller should create a copy. */
gpg_error_t
-ks_action_put (ctrl_t ctrl, void *data, size_t datalen,
+ks_action_put (ctrl_t ctrl, uri_item_t keyservers,
+ void *data, size_t datalen,
void *info, size_t infolen)
{
gpg_error_t err = 0;
@@ -319,7 +322,7 @@ ks_action_put (ctrl_t ctrl, void *data, size_t datalen,
int any_server = 0;
uri_item_t uri;
- for (uri = ctrl->keyservers; !err && uri; uri = uri->next)
+ for (uri = keyservers; !err && uri; uri = uri->next)
{
int is_http = uri->parsed_uri->is_http;
int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0
diff --git a/dirmngr/ks-action.h b/dirmngr/ks-action.h
index 2def3dce1..c373bf9fd 100644
--- a/dirmngr/ks-action.h
+++ b/dirmngr/ks-action.h
@@ -22,11 +22,14 @@
#define DIRMNGR_KS_ACTION_H 1
gpg_error_t ks_action_help (ctrl_t ctrl, const char *url);
-gpg_error_t ks_action_resolve (ctrl_t ctrl);
-gpg_error_t ks_action_search (ctrl_t ctrl, strlist_t patterns, estream_t outfp);
-gpg_error_t ks_action_get (ctrl_t ctrl, strlist_t patterns, estream_t outfp);
+gpg_error_t ks_action_resolve (ctrl_t ctrl, uri_item_t keyservers);
+gpg_error_t ks_action_search (ctrl_t ctrl, uri_item_t keyservers,
+ strlist_t patterns, estream_t outfp);
+gpg_error_t ks_action_get (ctrl_t ctrl, uri_item_t keyservers,
+ strlist_t patterns, estream_t outfp);
gpg_error_t ks_action_fetch (ctrl_t ctrl, const char *url, estream_t outfp);
-gpg_error_t ks_action_put (ctrl_t ctrl, void *data, size_t datalen,
+gpg_error_t ks_action_put (ctrl_t ctrl, uri_item_t keyservers,
+ void *data, size_t datalen,
void *info, size_t infolen);
diff --git a/dirmngr/server.c b/dirmngr/server.c
index deae85ca1..506b137c1 100644
--- a/dirmngr/server.c
+++ b/dirmngr/server.c
@@ -1,8 +1,7 @@
/* server.c - LDAP and Keyserver access server
* Copyright (C) 2002 Klarälvdalens Datakonsult AB
- * Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2011 g10 Code GmbH
+ * Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2011, 2015 g10 Code GmbH
* Copyright (C) 2014 Werner Koch
- * Copyright (C) 2015 g10 Code GmbH
*
* This file is part of GnuPG.
*
@@ -76,6 +75,9 @@ struct server_local_s
/* Per-session LDAP servers. */
ldap_server_t ldapservers;
+ /* Per-session list of keyservers. */
+ uri_item_t keyservers;
+
/* If this flag is set to true this dirmngr process will be
terminated after the end of this session. */
int stopme;
@@ -113,12 +115,15 @@ get_ldapservers_from_ctrl (ctrl_t ctrl)
void
release_ctrl_keyservers (ctrl_t ctrl)
{
- while (ctrl->keyservers)
+ if (! ctrl->server_local)
+ return;
+
+ while (ctrl->server_local->keyservers)
{
- uri_item_t tmp = ctrl->keyservers->next;
- http_release_parsed_uri (ctrl->keyservers->parsed_uri);
- xfree (ctrl->keyservers);
- ctrl->keyservers = tmp;
+ uri_item_t tmp = ctrl->server_local->keyservers->next;
+ http_release_parsed_uri (ctrl->server_local->keyservers->parsed_uri);
+ xfree (ctrl->server_local->keyservers);
+ ctrl->server_local->keyservers = tmp;
}
}
@@ -127,7 +132,6 @@ release_ctrl_keyservers (ctrl_t ctrl)
/* Helper to print a message while leaving a command. */
static gpg_error_t
leave_cmd (assuan_context_t ctx, gpg_error_t err)
-
{
if (err)
{
@@ -1476,7 +1480,7 @@ cmd_keyserver (assuan_context_t ctx, char *line)
if (resolve_flag)
{
- err = ks_action_resolve (ctrl);
+ err = ks_action_resolve (ctrl, ctrl->server_local->keyservers);
if (err)
goto leave;
}
@@ -1540,15 +1544,15 @@ cmd_keyserver (assuan_context_t ctx, char *line)
release_ctrl_keyservers (ctrl);
if (add_flag)
{
- item->next = ctrl->keyservers;
- ctrl->keyservers = item;
+ item->next = ctrl->server_local->keyservers;
+ ctrl->server_local->keyservers = item;
}
if (!add_flag && !clear_flag && !help_flag) /* List configured keyservers. */
{
uri_item_t u;
- for (u=ctrl->keyservers; u; u = u->next)
+ for (u=ctrl->server_local->keyservers; u; u = u->next)
dirmngr_status (ctrl, "KEYSERVER", u->uri, NULL);
}
err = 0;
@@ -1606,7 +1610,8 @@ cmd_ks_search (assuan_context_t ctx, char *line)
err = set_error (GPG_ERR_ASS_GENERAL, "error setting up a data stream");
else
{
- err = ks_action_search (ctrl, list, outfp);
+ err = ks_action_search (ctrl, ctrl->server_local->keyservers,
+ list, outfp);
es_fclose (outfp);
}
@@ -1667,7 +1672,7 @@ cmd_ks_get (assuan_context_t ctx, char *line)
err = set_error (GPG_ERR_ASS_GENERAL, "error setting up a data stream");
else
{
- err = ks_action_get (ctrl, list, outfp);
+ err = ks_action_get (ctrl, ctrl->server_local->keyservers, list, outfp);
es_fclose (outfp);
}
@@ -1762,7 +1767,8 @@ cmd_ks_put (assuan_context_t ctx, char *line)
}
/* Send the key. */
- err = ks_action_put (ctrl, value, valuelen, info, infolen);
+ err = ks_action_put (ctrl, ctrl->server_local->keyservers,
+ value, valuelen, info, infolen);
leave:
xfree (info);