mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-21 10:09:57 +01:00
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:
parent
f26ba14028
commit
d4a32ae5c6
@ -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. */
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
@ -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,12 @@ get_ldapservers_from_ctrl (ctrl_t ctrl)
|
||||
void
|
||||
release_ctrl_keyservers (ctrl_t ctrl)
|
||||
{
|
||||
while (ctrl->keyservers)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1476,7 +1478,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 +1542,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 +1608,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 +1670,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 +1765,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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user