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>
This commit is contained in:
Neal H. Walfield 2015-03-28 17:23:56 +01:00
parent f26ba14028
commit 348c520040
4 changed files with 41 additions and 30 deletions

View File

@ -1,6 +1,6 @@
/* dirmngr.h - Common definitions for the dirmngr /* dirmngr.h - Common definitions for the dirmngr
* Copyright (C) 2002 Klarälvdalens Datakonsult AB * 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 * Copyright (C) 2014 Werner Koch
* *
* This file is part of GnuPG. * This file is part of GnuPG.
@ -174,7 +174,6 @@ struct server_control_s
response. */ response. */
int audit_events; /* Send audit events to client. */ int audit_events; /* Send audit events to client. */
uri_item_t keyservers; /* List of keyservers. */
}; };

View File

@ -1,7 +1,7 @@
/* ks-action.c - OpenPGP keyserver actions /* ks-action.c - OpenPGP keyserver actions
* Copyright (C) 2011 Free Software Foundation, Inc. * Copyright (C) 2011 Free Software Foundation, Inc.
* Copyright (C) 2011, 2014 Werner Koch * Copyright (C) 2011, 2014 Werner Koch
* Copyright (C) 2015 g10 Code GmbH * Copyright (C) 2015 g10 Code GmbH
* *
* This file is part of GnuPG. * 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 /* Resolve all host names. This is useful for looking at the status
of configured keyservers. */ of configured keyservers. */
gpg_error_t gpg_error_t
ks_action_resolve (ctrl_t ctrl) ks_action_resolve (ctrl_t ctrl, uri_item_t keyservers)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
int any_server = 0; int any_server = 0;
uri_item_t uri; 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) 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 /* Search all configured keyservers for keys matching PATTERNS and
write the result to the provided output stream. */ write the result to the provided output stream. */
gpg_error_t 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; gpg_error_t err = 0;
int any_server = 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 errors - it might not be the best idea to ignore an error from
one server and silently continue with another server. For now we one server and silently continue with another server. For now we
stop at the first error. */ 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_http = uri->parsed_uri->is_http;
int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0 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 /* Get the requested keys (matching PATTERNS) using all configured
keyservers and write the result to the provided output stream. */ keyservers and write the result to the provided output stream. */
gpg_error_t 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 err = 0;
gpg_error_t first_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 keyservers might not all be fully synced thus it is not clear
whether the first keyserver has the freshest copy of the key. whether the first keyserver has the freshest copy of the key.
Need to think about a better strategy. */ 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_http = uri->parsed_uri->is_http;
int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0 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 KEYID; done'. This function may modify DATA and INFO. If this is
a problem, then the caller should create a copy. */ a problem, then the caller should create a copy. */
gpg_error_t 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) void *info, size_t infolen)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
@ -319,7 +322,7 @@ ks_action_put (ctrl_t ctrl, void *data, size_t datalen,
int any_server = 0; int any_server = 0;
uri_item_t uri; 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_http = uri->parsed_uri->is_http;
int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0 int is_ldap = (strcmp (uri->parsed_uri->scheme, "ldap") == 0

View File

@ -22,11 +22,14 @@
#define DIRMNGR_KS_ACTION_H 1 #define DIRMNGR_KS_ACTION_H 1
gpg_error_t ks_action_help (ctrl_t ctrl, const char *url); 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_resolve (ctrl_t ctrl, uri_item_t keyservers);
gpg_error_t ks_action_search (ctrl_t ctrl, strlist_t patterns, estream_t outfp); gpg_error_t ks_action_search (ctrl_t ctrl, uri_item_t keyservers,
gpg_error_t ks_action_get (ctrl_t ctrl, strlist_t patterns, estream_t outfp); 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_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); void *info, size_t infolen);

View File

@ -1,8 +1,7 @@
/* server.c - LDAP and Keyserver access server /* server.c - LDAP and Keyserver access server
* Copyright (C) 2002 Klarälvdalens Datakonsult AB * 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) 2014 Werner Koch
* Copyright (C) 2015 g10 Code GmbH
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -76,6 +75,9 @@ struct server_local_s
/* Per-session LDAP servers. */ /* Per-session LDAP servers. */
ldap_server_t ldapservers; 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 /* If this flag is set to true this dirmngr process will be
terminated after the end of this session. */ terminated after the end of this session. */
int stopme; int stopme;
@ -113,12 +115,15 @@ get_ldapservers_from_ctrl (ctrl_t ctrl)
void void
release_ctrl_keyservers (ctrl_t ctrl) 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; uri_item_t tmp = ctrl->server_local->keyservers->next;
http_release_parsed_uri (ctrl->keyservers->parsed_uri); http_release_parsed_uri (ctrl->server_local->keyservers->parsed_uri);
xfree (ctrl->keyservers); xfree (ctrl->server_local->keyservers);
ctrl->keyservers = tmp; ctrl->server_local->keyservers = tmp;
} }
} }
@ -127,7 +132,6 @@ release_ctrl_keyservers (ctrl_t ctrl)
/* Helper to print a message while leaving a command. */ /* Helper to print a message while leaving a command. */
static gpg_error_t static gpg_error_t
leave_cmd (assuan_context_t ctx, gpg_error_t err) leave_cmd (assuan_context_t ctx, gpg_error_t err)
{ {
if (err) if (err)
{ {
@ -1476,7 +1480,7 @@ cmd_keyserver (assuan_context_t ctx, char *line)
if (resolve_flag) if (resolve_flag)
{ {
err = ks_action_resolve (ctrl); err = ks_action_resolve (ctrl, ctrl->server_local->keyservers);
if (err) if (err)
goto leave; goto leave;
} }
@ -1540,15 +1544,15 @@ cmd_keyserver (assuan_context_t ctx, char *line)
release_ctrl_keyservers (ctrl); release_ctrl_keyservers (ctrl);
if (add_flag) if (add_flag)
{ {
item->next = ctrl->keyservers; item->next = ctrl->server_local->keyservers;
ctrl->keyservers = item; ctrl->server_local->keyservers = item;
} }
if (!add_flag && !clear_flag && !help_flag) /* List configured keyservers. */ if (!add_flag && !clear_flag && !help_flag) /* List configured keyservers. */
{ {
uri_item_t u; 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); dirmngr_status (ctrl, "KEYSERVER", u->uri, NULL);
} }
err = 0; 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"); err = set_error (GPG_ERR_ASS_GENERAL, "error setting up a data stream");
else else
{ {
err = ks_action_search (ctrl, list, outfp); err = ks_action_search (ctrl, ctrl->server_local->keyservers,
list, outfp);
es_fclose (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"); err = set_error (GPG_ERR_ASS_GENERAL, "error setting up a data stream");
else else
{ {
err = ks_action_get (ctrl, list, outfp); err = ks_action_get (ctrl, ctrl->server_local->keyservers, list, outfp);
es_fclose (outfp); es_fclose (outfp);
} }
@ -1762,7 +1767,8 @@ cmd_ks_put (assuan_context_t ctx, char *line)
} }
/* Send the key. */ /* 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: leave:
xfree (info); xfree (info);