s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
dns_tlsa.c
Go to the documentation of this file.
1#include "byte.h"
2#include "stralloc.h"
3#include "uint_t.h"
4#include "dns.h"
5#include "logmsg.h"
6
7static char *q = 0;
8
9int dns_tlsa_packet(stralloc *out,const char *buf,unsigned int len)
10{
11 unsigned int pos;
12 char header[12];
13 uint16 datalen;
14 uint16 numanswers;
15 int ranswers = 0;
16
17 if (!stralloc_copys(out,"")) return DNS_MEM;
18
19 pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return DNS_ERR;
20 uint16_unpack_big(header + 6,&numanswers);
21 pos = dns_packet_skipname(buf,len,pos); if (!pos) return DNS_ERR;
22 pos += 4;
23
24 while (numanswers--) {
25 pos = dns_packet_skipname(buf,len,pos); if (!pos) return DNS_ERR;
26 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return DNS_ERR;
27 uint16_unpack_big(header + 8,&datalen);
28 if (byte_equal(header,2,DNS_T_TLSA))
29 if (byte_equal(header + 2,2,DNS_C_IN)) {
30 if (pos + datalen > len) return DNS_ERR;
31 if (!stralloc_catb(out,buf + pos,datalen)) return DNS_MEM;
32 }
33 pos += datalen;
34 ++ranswers;
35 }
36 if (!stralloc_0(out)) return DNS_MEM;
37
38 return ranswers;
39}
40
41int dns_tlsa(stralloc *out,const stralloc *fqdn)
42{
43 int rc = 0;
44
45 if (dns_domain_fromdot(&q,fqdn->s,fqdn->len) <= 0) return DNS_ERR;
46 if (dns_resolve(q,DNS_T_TLSA) >= 0) {
47 if ((rc = dns_tlsa_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen)) < 0) return DNS_ERR;
48 dns_transmit_free(&dns_resolve_tx);
49 dns_domain_free(&q);
50 }
51
52 return rc;
53}
int stralloc_copys(stralloc *, char const *)
int dns_tlsa_packet(stralloc *out, const char *buf, unsigned int len)
Definition: dns_tlsa.c:9
int dns_tlsa(stralloc *out, const stralloc *fqdn)
Definition: dns_tlsa.c:41
stralloc out
Definition: dnscname.c:12
char buf[100+FMT_ULONG]
Definition: hier.c:10