diff options
| author | manuel <manuel@mausz.at> | 2023-08-10 01:10:02 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2023-08-10 01:10:02 +0200 |
| commit | 29b6e8b053d21f0a1e722e1c3be38371e7efaf10 (patch) | |
| tree | 797c10e213875cc41957d949060150db4a661ad8 | |
| parent | c36bd5f683eea9f6de05fcdda6d65505cbe8c316 (diff) | |
| download | qmail-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.c | 44 | ||||
| -rw-r--r-- | dns.h | 12 | ||||
| -rw-r--r-- | dnscname.c | 1 | ||||
| -rw-r--r-- | dnsfq.c | 2 | ||||
| -rw-r--r-- | dnsip.c | 1 | ||||
| -rw-r--r-- | dnsmxip.c | 4 | ||||
| -rw-r--r-- | dnsptr.c | 1 | ||||
| -rw-r--r-- | dnstlsa.c | 3 | ||||
| -rw-r--r-- | ipalloc.h | 13 | ||||
| -rw-r--r-- | qmail-smtpd.c | 1 |
10 files changed, 45 insertions, 37 deletions
| @@ -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> |
| 8 | extern int res_query(); | ||
| 9 | extern 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; | |||
| 24 | static int responselen; | 22 | static int responselen; |
| 25 | static unsigned char *responseend; | 23 | static unsigned char *responseend; |
| 26 | static unsigned char *responsepos; | 24 | static unsigned char *responsepos; |
| 27 | static u_long saveresoptions; | ||
| 28 | 25 | ||
| 29 | static int numanswers; | 26 | static int numanswers; |
| 30 | static char name[MAXDNAME]; | 27 | static char name[MAXDNAME]; |
| @@ -33,16 +30,21 @@ unsigned short pref; | |||
| 33 | 30 | ||
| 34 | static stralloc glue = {0}; | 31 | static stralloc glue = {0}; |
| 35 | 32 | ||
| 36 | static int (*lookup)() = res_query; | 33 | static struct __res_state dns_res_state; |
| 34 | static unsigned short dns_res_ad_flag = 0; | ||
| 37 | 35 | ||
| 38 | static int resolve(domain,type) | 36 | static int (*lookup)(res_state statep, const char *dname, int class, int type, unsigned char *answer, int anslen) = res_nquery; |
| 39 | stralloc *domain; | 37 | |
| 40 | int type; | 38 | static 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 | ||
| 92 | short dns_last_query_validated() | ||
| 93 | { | ||
| 94 | return dns_res_ad_flag; | ||
| 95 | } | ||
| 96 | |||
| 88 | static int findname(wanttype) | 97 | static int findname(wanttype) |
| 89 | int wanttype; | 98 | int wanttype; |
| 90 | { | 99 | { |
| @@ -194,11 +203,9 @@ int wanttype; | |||
| 194 | return 0; | 203 | return 0; |
| 195 | } | 204 | } |
| 196 | 205 | ||
| 197 | void dns_init(flagsearch) | 206 | void dns_use_search(int use_search) |
| 198 | int flagsearch; | ||
| 199 | { | 207 | { |
| 200 | res_init(); | 208 | lookup = (use_search) ? res_nsearch : res_nquery; |
| 201 | if (flagsearch) lookup = res_search; | ||
| 202 | } | 209 | } |
| 203 | 210 | ||
| 204 | int dns_cname(sa) | 211 | int 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; |
| @@ -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 | ||
| 10 | void dns_init(); | 11 | short dns_last_query_validated(); |
| 11 | int dns_cname(); | 12 | void dns_use_search(int use_search); |
| 12 | int dns_mxip(); | 13 | int dns_cname(stralloc *sa); |
| 13 | int dns_ip(); | 14 | int dns_mxip(ipalloc *ia, stralloc *sa, unsigned long random); |
| 14 | int dns_ptr(); | 15 | int dns_ip(ipalloc *ia, stralloc *sa); |
| 16 | int dns_ptr(stralloc *sa, struct ip_address *ip); | ||
| 15 | int dns_tlsa(stralloc *out, const stralloc *fqdn); | 17 | int dns_tlsa(stralloc *out, const stralloc *fqdn); |
| 16 | 18 | ||
| 17 | #endif | 19 | #endif |
| @@ -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"); |
| @@ -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 | { |
| @@ -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 | { |
| @@ -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); |
| @@ -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"); |
| @@ -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 | } |
| @@ -3,15 +3,14 @@ | |||
| 3 | 3 | ||
| 4 | #include "ip.h" | 4 | #include "ip.h" |
| 5 | 5 | ||
| 6 | struct 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 | ||
| 11 | struct ip_mx { struct ip_address ip; int pref; char *fqdn; } ; | ||
| 12 | #else | ||
| 13 | struct 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 | } |
