aboutsummaryrefslogtreecommitdiffstats
path: root/dirmngr/dns-stuff.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-01-08 17:04:59 +0000
committerWerner Koch <[email protected]>2017-01-08 17:04:59 +0000
commit16078f3deea5b82ea26e2f01dbd3ef3a5ce25410 (patch)
treea8da190a48cb319aaab1d25a35e0ba060fd51194 /dirmngr/dns-stuff.c
parentdirmngr: Strip root zone suffix from libdns SRV results. (diff)
downloadgnupg-16078f3deea5b82ea26e2f01dbd3ef3a5ce25410.tar.gz
gnupg-16078f3deea5b82ea26e2f01dbd3ef3a5ce25410.zip
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 <[email protected]>
Diffstat (limited to 'dirmngr/dns-stuff.c')
-rw-r--r--dirmngr/dns-stuff.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c
index 028b065ab..a8713eb44 100644
--- a/dirmngr/dns-stuff.c
+++ b/dirmngr/dns-stuff.c
@@ -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
-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;
+ char *namebuffer = NULL;
unsigned int srvcount;
int i;
*list = NULL;
*r_count = 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
if (!standard_resolver)
{
@@ -1852,6 +1872,7 @@ get_dns_srv (const char *name, struct srventry **list, unsigned int *r_count)
}
if (!err)
*r_count = srvcount;
+ xfree (namebuffer);
return err;
}