summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--dns.c44
-rw-r--r--dns.h12
-rw-r--r--dnscname.c1
-rw-r--r--dnsfq.c2
-rw-r--r--dnsip.c1
-rw-r--r--dnsmxip.c4
-rw-r--r--dnsptr.c1
-rw-r--r--dnstlsa.c3
-rw-r--r--ipalloc.h13
-rw-r--r--qmail-smtpd.c1
10 files changed, 45 insertions, 37 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;
diff --git a/dns.h b/dns.h
index 08534a2..615162d 100644
--- a/dns.h
+++ b/dns.h
@@ -2,16 +2,18 @@
2#define DNS_H 2#define DNS_H
3 3
4#include "stralloc.h" 4#include "stralloc.h"
5#include "ipalloc.h"
5 6
6#define DNS_SOFT -1 7#define DNS_SOFT -1
7#define DNS_HARD -2 8#define DNS_HARD -2
8#define DNS_MEM -3 9#define DNS_MEM -3
9 10
10void dns_init(); 11short dns_last_query_validated();
11int dns_cname(); 12void dns_use_search(int use_search);
12int dns_mxip(); 13int dns_cname(stralloc *sa);
13int dns_ip(); 14int dns_mxip(ipalloc *ia, stralloc *sa, unsigned long random);
14int dns_ptr(); 15int dns_ip(ipalloc *ia, stralloc *sa);
16int dns_ptr(stralloc *sa, struct ip_address *ip);
15int dns_tlsa(stralloc *out, const stralloc *fqdn); 17int dns_tlsa(stralloc *out, const stralloc *fqdn);
16 18
17#endif 19#endif
diff --git a/dnscname.c b/dnscname.c
index 37a95c5..16e6553 100644
--- a/dnscname.c
+++ b/dnscname.c
@@ -17,7 +17,6 @@ char **argv;
17 if (!stralloc_copys(&sa,argv[1])) 17 if (!stralloc_copys(&sa,argv[1]))
18 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); } 18 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); }
19 19
20 dns_init(0);
21 dnsdoe(dns_cname(&sa)); 20 dnsdoe(dns_cname(&sa));
22 substdio_putflush(subfdout,sa.s,sa.len); 21 substdio_putflush(subfdout,sa.s,sa.len);
23 substdio_putsflush(subfdout,"\n"); 22 substdio_putsflush(subfdout,"\n");
diff --git a/dnsfq.c b/dnsfq.c
index b7619b9..e93a9c6 100644
--- a/dnsfq.c
+++ b/dnsfq.c
@@ -19,7 +19,7 @@ char **argv;
19 if (!stralloc_copys(&sa,argv[1])) 19 if (!stralloc_copys(&sa,argv[1]))
20 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); } 20 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); }
21 21
22 dns_init(1); 22 dns_use_search(1);
23 dnsdoe(dns_ip(&ia,&sa)); 23 dnsdoe(dns_ip(&ia,&sa));
24 if (ia.len <= 0) 24 if (ia.len <= 0)
25 { 25 {
diff --git a/dnsip.c b/dnsip.c
index e7b671c..81f02f7 100644
--- a/dnsip.c
+++ b/dnsip.c
@@ -23,7 +23,6 @@ char **argv;
23 if (!stralloc_copys(&sa,argv[1])) 23 if (!stralloc_copys(&sa,argv[1]))
24 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); } 24 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); }
25 25
26 dns_init(0);
27 dnsdoe(dns_ip(&ia,&sa)); 26 dnsdoe(dns_ip(&ia,&sa));
28 for (j = 0;j < ia.len;++j) 27 for (j = 0;j < ia.len;++j)
29 { 28 {
diff --git a/dnsmxip.c b/dnsmxip.c
index de40aa5..a58d6b3 100644
--- a/dnsmxip.c
+++ b/dnsmxip.c
@@ -28,13 +28,15 @@ char **argv;
28 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); } 28 { substdio_putsflush(subfderr,"out of memory\n"); _exit(111); }
29 29
30 r = now() + getpid(); 30 r = now() + getpid();
31 dns_init(0);
32 dnsdoe(dns_mxip(&ia,&sa,r)); 31 dnsdoe(dns_mxip(&ia,&sa,r));
33 for (j = 0;j < ia.len;++j) 32 for (j = 0;j < ia.len;++j)
34 { 33 {
35 substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].ip)); 34 substdio_put(subfdout,temp,ip_fmt(temp,&ia.ix[j].ip));
36 substdio_puts(subfdout," "); 35 substdio_puts(subfdout," ");
37 substdio_put(subfdout,temp,fmt_ulong(temp,(unsigned long) ia.ix[j].pref)); 36 substdio_put(subfdout,temp,fmt_ulong(temp,(unsigned long) ia.ix[j].pref));
37#ifdef TLS
38 substdio_puts(subfdout,ia.ix[j].validated ? " validated" : "");
39#endif
38 substdio_putsflush(subfdout,"\n"); 40 substdio_putsflush(subfdout,"\n");
39 } 41 }
40 _exit(0); 42 _exit(0);
diff --git a/dnsptr.c b/dnsptr.c
index 6a92fe0..d23bf3a 100644
--- a/dnsptr.c
+++ b/dnsptr.c
@@ -19,7 +19,6 @@ char **argv;
19 19
20 ip_scan(argv[1],&ip); 20 ip_scan(argv[1],&ip);
21 21
22 dns_init(0);
23 dnsdoe(dns_ptr(&sa,&ip)); 22 dnsdoe(dns_ptr(&sa,&ip));
24 substdio_putflush(subfdout,sa.s,sa.len); 23 substdio_putflush(subfdout,sa.s,sa.len);
25 substdio_putsflush(subfdout,"\n"); 24 substdio_putsflush(subfdout,"\n");
diff --git a/dnstlsa.c b/dnstlsa.c
index ef4235e..2ea99e4 100644
--- a/dnstlsa.c
+++ b/dnstlsa.c
@@ -58,7 +58,6 @@ void main(int argc, char **argv)
58 substdio_putsflush(subfdout, "\n"); 58 substdio_putsflush(subfdout, "\n");
59 } 59 }
60 60
61 dns_init(0);
62 dnsdoe(dns_tlsa(&out, &sa)); 61 dnsdoe(dns_tlsa(&out, &sa));
63 62
64 int pos = 0; 63 int pos = 0;
@@ -90,6 +89,8 @@ void main(int argc, char **argv)
90 substdio_put(subfdout, "0123456789abcdef" + (ch >> 4), 1); 89 substdio_put(subfdout, "0123456789abcdef" + (ch >> 4), 1);
91 substdio_put(subfdout, "0123456789abcdef" + (ch & 0x0F), 1); 90 substdio_put(subfdout, "0123456789abcdef" + (ch & 0x0F), 1);
92 } 91 }
92
93 substdio_puts(subfdout, dns_last_query_validated() ? " [dnssec validated]" : " [no dnssec validated]");
93 substdio_putsflush(subfdout, "\n"); 94 substdio_putsflush(subfdout, "\n");
94 pos += rrlen; 95 pos += rrlen;
95 } 96 }
diff --git a/ipalloc.h b/ipalloc.h
index bf9d060..641c3db 100644
--- a/ipalloc.h
+++ b/ipalloc.h
@@ -3,15 +3,14 @@
3 3
4#include "ip.h" 4#include "ip.h"
5 5
6struct ip_mx {
7 struct ip_address ip;
8 int pref;
6#ifdef TLS 9#ifdef TLS
7# define IX_FQDN 1 10 char *fqdn;
8#endif 11 unsigned short validated;
9
10#ifdef IX_FQDN
11struct ip_mx { struct ip_address ip; int pref; char *fqdn; } ;
12#else
13struct ip_mx { struct ip_address ip; int pref; } ;
14#endif 12#endif
13};
15 14
16#include "gen_alloc.h" 15#include "gen_alloc.h"
17 16
diff --git a/qmail-smtpd.c b/qmail-smtpd.c
index 0d3b16d..c4b498e 100644
--- a/qmail-smtpd.c
+++ b/qmail-smtpd.c
@@ -522,7 +522,6 @@ int mfcheck()
522 j = byte_rchr(addr.s,addr.len,'@') + 1; 522 j = byte_rchr(addr.s,addr.len,'@') + 1;
523 if (j < addr.len) { 523 if (j < addr.len) {
524 stralloc_copys(&sa, addr.s + j); 524 stralloc_copys(&sa, addr.s + j);
525 dns_init(0);
526 j = dns_mxip(&ia,&sa,random); 525 j = dns_mxip(&ia,&sa,random);
527 if (j < 0) return j; 526 if (j < 0) return j;
528 } 527 }