summaryrefslogtreecommitdiffstats
path: root/dns.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2023-08-10 01:10:02 +0200
committermanuel <manuel@mausz.at>2023-08-10 01:10:02 +0200
commit29b6e8b053d21f0a1e722e1c3be38371e7efaf10 (patch)
tree797c10e213875cc41957d949060150db4a661ad8 /dns.c
parentc36bd5f683eea9f6de05fcdda6d65505cbe8c316 (diff)
downloadqmail-29b6e8b053d21f0a1e722e1c3be38371e7efaf10.tar.gz
qmail-29b6e8b053d21f0a1e722e1c3be38371e7efaf10.tar.bz2
qmail-29b6e8b053d21f0a1e722e1c3be38371e7efaf10.zip
add support for querying DNSSEC ad (validated) flag
also migrate from deprecated resolver functions
Diffstat (limited to 'dns.c')
-rw-r--r--dns.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/dns.c b/dns.c
index b4d106c..d43e946 100644
--- a/dns.c
+++ b/dns.c
@@ -5,8 +5,6 @@
5#include <arpa/nameser.h> 5#include <arpa/nameser.h>
6#include <resolv.h> 6#include <resolv.h>
7#include <errno.h> 7#include <errno.h>
8extern int res_query();
9extern int res_search();
10#include "ip.h" 8#include "ip.h"
11#include "ipalloc.h" 9#include "ipalloc.h"
12#include "fmt.h" 10#include "fmt.h"
@@ -24,7 +22,6 @@ static int responsebuflen = 0;
24static int responselen; 22static int responselen;
25static unsigned char *responseend; 23static unsigned char *responseend;
26static unsigned char *responsepos; 24static unsigned char *responsepos;
27static u_long saveresoptions;
28 25
29static int numanswers; 26static int numanswers;
30static char name[MAXDNAME]; 27static char name[MAXDNAME];
@@ -33,16 +30,21 @@ unsigned short pref;
33 30
34static stralloc glue = {0}; 31static stralloc glue = {0};
35 32
36static int (*lookup)() = res_query; 33static struct __res_state dns_res_state;
34static unsigned short dns_res_ad_flag = 0;
37 35
38static int resolve(domain,type) 36static int (*lookup)(res_state statep, const char *dname, int class, int type, unsigned char *answer, int anslen) = res_nquery;
39stralloc *domain; 37
40int type; 38static int resolve(stralloc *domain, int type)
41{ 39{
42 int n; 40 int n;
43 int i; 41 int i;
44 42
45 errno = 0; 43 errno = 0;
44
45 if ((dns_res_state.options & RES_INIT) == 0 && res_ninit(&dns_res_state) < 0)
46 return DNS_MEM;
47
46 if (!stralloc_copy(&glue,domain)) return DNS_MEM; 48 if (!stralloc_copy(&glue,domain)) return DNS_MEM;
47 if (!stralloc_0(&glue)) return DNS_MEM; 49 if (!stralloc_0(&glue)) return DNS_MEM;
48 if (!responsebuflen) 50 if (!responsebuflen)
@@ -50,7 +52,8 @@ int type;
50 responsebuflen = PACKETSZ+1; 52 responsebuflen = PACKETSZ+1;
51 else return DNS_MEM; 53 else return DNS_MEM;
52 54
53 responselen = lookup(glue.s,C_IN,type,response.buf,responsebuflen); 55 dns_res_ad_flag = 0;
56 responselen = lookup(&dns_res_state, glue.s, C_IN, type, response.buf, responsebuflen);
54 if ((responselen >= responsebuflen) || 57 if ((responselen >= responsebuflen) ||
55 (responselen > 0 && (((HEADER *)response.buf)->tc))) 58 (responselen > 0 && (((HEADER *)response.buf)->tc)))
56 { 59 {
@@ -58,10 +61,10 @@ int type;
58 if (alloc_re(&response.buf, responsebuflen, 65536)) 61 if (alloc_re(&response.buf, responsebuflen, 65536))
59 responsebuflen = 65536; 62 responsebuflen = 65536;
60 else return DNS_MEM; 63 else return DNS_MEM;
61 saveresoptions = _res.options; 64 u_long saveresoptions = dns_res_state.options;
62 _res.options |= RES_USEVC; 65 dns_res_state.options |= RES_USEVC;
63 responselen = lookup(glue.s,C_IN,type,response.buf,responsebuflen); 66 responselen = lookup(&dns_res_state, glue.s, C_IN, type, response.buf, responsebuflen);
64 _res.options = saveresoptions; 67 dns_res_state.options = saveresoptions;
65 } 68 }
66 if (responselen <= 0) 69 if (responselen <= 0)
67 { 70 {
@@ -82,9 +85,15 @@ int type;
82 responsepos += QFIXEDSZ; 85 responsepos += QFIXEDSZ;
83 } 86 }
84 numanswers = ntohs(((HEADER *)response.buf)->ancount); 87 numanswers = ntohs(((HEADER *)response.buf)->ancount);
88 dns_res_ad_flag = ((HEADER *)response.buf)->ad;
85 return 0; 89 return 0;
86} 90}
87 91
92short dns_last_query_validated()
93{
94 return dns_res_ad_flag;
95}
96
88static int findname(wanttype) 97static int findname(wanttype)
89int wanttype; 98int wanttype;
90{ 99{
@@ -194,11 +203,9 @@ int wanttype;
194 return 0; 203 return 0;
195} 204}
196 205
197void dns_init(flagsearch) 206void dns_use_search(int use_search)
198int flagsearch;
199{ 207{
200 res_init(); 208 lookup = (use_search) ? res_nsearch : res_nquery;
201 if (flagsearch) lookup = res_search;
202} 209}
203 210
204int dns_cname(sa) 211int dns_cname(sa)
@@ -308,13 +315,14 @@ int pref;
308 ix.pref = pref; 315 ix.pref = pref;
309 if (r == DNS_SOFT) return DNS_SOFT; 316 if (r == DNS_SOFT) return DNS_SOFT;
310 if (r == 1) { 317 if (r == 1) {
311#ifdef IX_FQDN 318#ifdef TLS
312 ix.fqdn = glue.s; 319 ix.fqdn = glue.s;
320 ix.validated = dns_last_query_validated();
313#endif 321#endif
314 if (!ipalloc_append(ia,&ix)) return DNS_MEM; 322 if (!ipalloc_append(ia,&ix)) return DNS_MEM;
315 } 323 }
316 } 324 }
317#ifdef IX_FQDN 325#ifdef TLS
318 glue.s = 0; 326 glue.s = 0;
319#endif 327#endif
320 return 0; 328 return 0;