aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2015-11-19 12:00:59 +0000
committerJustus Winter <[email protected]>2015-11-19 14:08:42 +0000
commit24db34445abe2ed90e38a556e7a41cc9c5907c44 (patch)
tree05efae78457956b4407850516d273682d83094d3
parentdirmngr: Refactor 'map_host'. (diff)
downloadgnupg-24db34445abe2ed90e38a556e7a41cc9c5907c44.tar.gz
gnupg-24db34445abe2ed90e38a556e7a41cc9c5907c44.zip
irmngr: Refactor 'map_host'.
* dirmngr/ks-engine-hkp.c (add_host): New function. (map_host): Use the new function. Signed-off-by: Justus Winter <[email protected]>
-rw-r--r--dirmngr/ks-engine-hkp.c209
1 files changed, 110 insertions, 99 deletions
diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
index b9eca0e59..d57b5779f 100644
--- a/dirmngr/ks-engine-hkp.c
+++ b/dirmngr/ks-engine-hkp.c
@@ -256,6 +256,115 @@ arecords_is_pool (dns_addrinfo_t aibuf)
}
+/* Add the host AI under the NAME into the HOSTTABLE. Updates the
+ given reference table. */
+static void
+add_host (const char *name, const dns_addrinfo_t ai, int is_pool,
+ int *reftbl, size_t reftblsize, int *refidx)
+{
+ gpg_error_t tmperr;
+ char *tmphost;
+ int idx, tmpidx;
+ int is_numeric = 0;
+ int i;
+
+ idx = find_hostinfo (name);
+
+ if (!is_pool && !is_ip_address (name))
+ {
+ /* This is a hostname but not a pool. Use the name
+ as given without going through resolve_dns_addr. */
+ tmphost = xtrystrdup (name);
+ if (!tmphost)
+ tmperr = gpg_error_from_syserror ();
+ else
+ tmperr = 0;
+ }
+ else
+ {
+ tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
+ DNS_WITHBRACKET, &tmphost);
+ if (tmphost && is_ip_address (tmphost))
+ is_numeric = 1;
+ }
+
+ if (tmperr)
+ {
+ log_info ("resolve_dns_addr failed while checking '%s': %s\n",
+ name, gpg_strerror (tmperr));
+ }
+ else if ((*refidx) + 1 >= reftblsize)
+ {
+ log_error ("resolve_dns_addr for '%s': '%s'"
+ " [index table full - ignored]\n", name, tmphost);
+ }
+ else
+ {
+ if (!is_pool && is_ip_address (name))
+ /* Update the original entry. */
+ tmpidx = idx;
+ else
+ tmpidx = find_hostinfo (tmphost);
+ log_info ("resolve_dns_addr for '%s': '%s'%s\n",
+ name, tmphost,
+ tmpidx == -1? "" : " [already known]");
+
+ if (tmpidx == -1) /* Create a new entry. */
+ tmpidx = create_new_hostinfo (tmphost);
+
+ if (tmpidx == -1)
+ {
+ log_error ("map_host for '%s' problem: %s - '%s'"
+ " [ignored]\n",
+ name, strerror (errno), tmphost);
+ }
+ else /* Set or update the entry. */
+ {
+ char *ipaddr = NULL;
+
+ if (!is_numeric)
+ {
+ xfree (tmphost);
+ tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
+ (DNS_NUMERICHOST
+ | DNS_WITHBRACKET),
+ &tmphost);
+ if (tmperr)
+ log_info ("resolve_dns_addr failed: %s\n",
+ gpg_strerror (tmperr));
+ else
+ {
+ ipaddr = tmphost;
+ tmphost = NULL;
+ }
+ }
+
+ if (ai->family == AF_INET6)
+ {
+ hosttable[tmpidx]->v6 = 1;
+ xfree (hosttable[tmpidx]->v6addr);
+ hosttable[tmpidx]->v6addr = ipaddr;
+ }
+ else if (ai->family == AF_INET)
+ {
+ hosttable[tmpidx]->v4 = 1;
+ xfree (hosttable[tmpidx]->v4addr);
+ hosttable[tmpidx]->v4addr = ipaddr;
+ }
+ else
+ BUG ();
+
+ for (i=0; i < *refidx; i++)
+ if (reftbl[i] == tmpidx)
+ break;
+ if (!(i < *refidx) && tmpidx != idx)
+ reftbl[(*refidx)++] = tmpidx;
+ }
+ }
+ xfree (tmphost);
+}
+
+
/* Map the host name NAME to the actual to be used host name. This
allows us to manage round robin DNS names. We use our own strategy
to choose one of the hosts. For example we skip those hosts which
@@ -346,109 +455,11 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
for (ai = aibuf; ai; ai = ai->next)
{
- gpg_error_t tmperr;
- char *tmphost;
- int tmpidx;
- int is_numeric = 0;
- int i;
-
if (ai->family != AF_INET && ai->family != AF_INET6)
continue;
-
dirmngr_tick (ctrl);
- if (!is_pool && !is_ip_address (name))
- {
- /* This is a hostname but not a pool. Use the name
- as given without going through resolve_dns_addr. */
- tmphost = xtrystrdup (name);
- if (!tmphost)
- tmperr = gpg_error_from_syserror ();
- else
- tmperr = 0;
- }
- else
- {
- tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
- DNS_WITHBRACKET, &tmphost);
- if (tmphost && is_ip_address (tmphost))
- is_numeric = 1;
- }
-
- if (tmperr)
- {
- log_info ("resolve_dns_addr failed while checking '%s': %s\n",
- name, gpg_strerror (tmperr));
- }
- else if (refidx+1 >= reftblsize)
- {
- log_error ("resolve_dns_addr for '%s': '%s'"
- " [index table full - ignored]\n", name, tmphost);
- }
- else
- {
- if (!is_pool && is_ip_address (name))
- /* Update the original entry. */
- tmpidx = idx;
- else
- tmpidx = find_hostinfo (tmphost);
- log_info ("resolve_dns_addr for '%s': '%s'%s\n",
- name, tmphost,
- tmpidx == -1? "" : " [already known]");
-
- if (tmpidx == -1) /* Create a new entry. */
- tmpidx = create_new_hostinfo (tmphost);
-
- if (tmpidx == -1)
- {
- log_error ("map_host for '%s' problem: %s - '%s'"
- " [ignored]\n",
- name, strerror (errno), tmphost);
- }
- else /* Set or update the entry. */
- {
- char *ipaddr = NULL;
-
- if (!is_numeric)
- {
- xfree (tmphost);
- tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
- (DNS_NUMERICHOST
- | DNS_WITHBRACKET),
- &tmphost);
- if (tmperr)
- log_info ("resolve_dns_addr failed: %s\n",
- gpg_strerror (tmperr));
- else
- {
- ipaddr = tmphost;
- tmphost = NULL;
- }
- }
-
- if (ai->family == AF_INET6)
- {
- hosttable[tmpidx]->v6 = 1;
- xfree (hosttable[tmpidx]->v6addr);
- hosttable[tmpidx]->v6addr = ipaddr;
- }
- else if (ai->family == AF_INET)
- {
- hosttable[tmpidx]->v4 = 1;
- xfree (hosttable[tmpidx]->v4addr);
- hosttable[tmpidx]->v4addr = ipaddr;
- }
- else
- BUG ();
-
- for (i=0; i < refidx; i++)
- if (reftbl[i] == tmpidx)
- break;
- if (!(i < refidx) && tmpidx != idx)
- reftbl[refidx++] = tmpidx;
- }
- }
- xfree (tmphost);
+ add_host (name, ai, is_pool, reftbl, reftblsize, &refidx);
}
}
reftbl[refidx] = -1;