mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
dirmngr: Change internal SRV lookup API.
* dirmngr/dns-stuff.c (get_dns_srv): Add args SERVICE and PROTO. * dirmngr/http.c (connect_server): Simplify SRV lookup. * dirmngr/ks-engine-hkp.c (map_host): Ditto. * dirmngr/t-dns-stuff.c (main): Adjust for changed get_dns_srv. -- This new API is more convenient because it includes commonly used code. Note that right now http.c's SRV record code is not used. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
9fa94aa107
commit
16078f3dee
@ -1740,17 +1740,37 @@ getsrv_standard (const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Note that we do not return NONAME but simply store 0 at R_COUNT. */
|
/* Query a SRV record for SERVICE and PROTO for NAME. If SERVICE is
|
||||||
|
* NULL, NAME is expected to contain the full query name. Note that
|
||||||
|
* we do not return NONAME but simply store 0 at R_COUNT. On error an
|
||||||
|
* error code is returned and 0 stored at R_COUNT. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
get_dns_srv (const char *name, struct srventry **list, unsigned int *r_count)
|
get_dns_srv (const char *name, const char *service, const char *proto,
|
||||||
|
struct srventry **list, unsigned int *r_count)
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
|
char *namebuffer = NULL;
|
||||||
unsigned int srvcount;
|
unsigned int srvcount;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
*list = NULL;
|
*list = NULL;
|
||||||
*r_count = 0;
|
*r_count = 0;
|
||||||
srvcount = 0;
|
srvcount = 0;
|
||||||
|
|
||||||
|
/* If SERVICE is given construct the query from it and PROTO. */
|
||||||
|
if (service)
|
||||||
|
{
|
||||||
|
namebuffer = xtryasprintf ("_%s._%s.%s",
|
||||||
|
service, proto? proto:"tcp", name);
|
||||||
|
if (!namebuffer)
|
||||||
|
{
|
||||||
|
err = gpg_error_from_syserror ();
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
name = namebuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_LIBDNS
|
#ifdef USE_LIBDNS
|
||||||
if (!standard_resolver)
|
if (!standard_resolver)
|
||||||
{
|
{
|
||||||
@ -1852,6 +1872,7 @@ get_dns_srv (const char *name, struct srventry **list, unsigned int *r_count)
|
|||||||
}
|
}
|
||||||
if (!err)
|
if (!err)
|
||||||
*r_count = srvcount;
|
*r_count = srvcount;
|
||||||
|
xfree (namebuffer);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ gpg_error_t get_dns_cert (const char *name, int want_certtype,
|
|||||||
|
|
||||||
/* Return an array of SRV records. */
|
/* Return an array of SRV records. */
|
||||||
gpg_error_t get_dns_srv (const char *name,
|
gpg_error_t get_dns_srv (const char *name,
|
||||||
|
const char *service, const char *proto,
|
||||||
struct srventry **list, unsigned int *r_count);
|
struct srventry **list, unsigned int *r_count);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2362,30 +2362,12 @@ connect_server (const char *server, unsigned short port,
|
|||||||
/* Do the SRV thing */
|
/* Do the SRV thing */
|
||||||
if (srvtag)
|
if (srvtag)
|
||||||
{
|
{
|
||||||
/* We're using SRV, so append the tags. */
|
err = get_dns_srv (server, srvtag, NULL, &serverlist, &srvcount);
|
||||||
if (1 + strlen (srvtag) + 6 + strlen (server) + 1
|
|
||||||
<= DIMof (struct srventry, target))
|
|
||||||
{
|
|
||||||
char *srvname = xtrymalloc (DIMof (struct srventry, target));
|
|
||||||
|
|
||||||
if (!srvname) /* Out of core */
|
|
||||||
{
|
|
||||||
serverlist = NULL;
|
|
||||||
srvcount = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stpcpy (stpcpy (stpcpy (stpcpy (srvname,"_"), srvtag),
|
|
||||||
"._tcp."), server);
|
|
||||||
err = get_dns_srv (srvname, &serverlist, &srvcount);
|
|
||||||
if (err)
|
if (err)
|
||||||
log_info ("getting SRV '%s' failed: %s\n",
|
log_info ("getting '%s' SRV for '%s' failed: %s\n",
|
||||||
srvname, gpg_strerror (err));
|
srvtag, server, gpg_strerror (err));
|
||||||
xfree (srvname);
|
|
||||||
/* Note that on error SRVCOUNT is zero. */
|
/* Note that on error SRVCOUNT is zero. */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!serverlist)
|
if (!serverlist)
|
||||||
{
|
{
|
||||||
|
@ -426,7 +426,6 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
|
|||||||
int refidx;
|
int refidx;
|
||||||
int is_pool = 0;
|
int is_pool = 0;
|
||||||
char *cname;
|
char *cname;
|
||||||
char *srvrecord;
|
|
||||||
struct srventry *srvs;
|
struct srventry *srvs;
|
||||||
unsigned int srvscount;
|
unsigned int srvscount;
|
||||||
|
|
||||||
@ -448,16 +447,7 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect,
|
|||||||
if (!is_ip_address (name))
|
if (!is_ip_address (name))
|
||||||
{
|
{
|
||||||
/* Check for SRV records. */
|
/* Check for SRV records. */
|
||||||
srvrecord = xtryasprintf ("_hkp._tcp.%s", name);
|
err = get_dns_srv (name, "hkp", NULL, &srvs, &srvscount);
|
||||||
if (srvrecord == NULL)
|
|
||||||
{
|
|
||||||
err = gpg_error_from_syserror ();
|
|
||||||
xfree (reftbl);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = get_dns_srv (srvrecord, &srvs, &srvscount);
|
|
||||||
xfree (srvrecord);
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
xfree (reftbl);
|
xfree (reftbl);
|
||||||
|
@ -235,7 +235,7 @@ main (int argc, char **argv)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
err = get_dns_srv (name? name : "_hkp._tcp.wwwkeys.pgp.net",
|
err = get_dns_srv (name? name : "_hkp._tcp.wwwkeys.pgp.net",
|
||||||
&srv, &count);
|
NULL, NULL, &srv, &count);
|
||||||
if (err)
|
if (err)
|
||||||
printf ("get_dns_srv failed: %s <%s>\n",
|
printf ("get_dns_srv failed: %s <%s>\n",
|
||||||
gpg_strerror (err), gpg_strsource (err));
|
gpg_strerror (err), gpg_strsource (err));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user