From 508d17362c2c43ddf95ddc87ae6a8c5f32f35323 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Tue, 22 May 2001 01:44:37 +0000 Subject: [PATCH] 834. [func] Accept (but warn about) master files beginning with an SOA record without an explicit TTL field and lacking a $TTL directive, by using the SOA MINTTL as a default TTL. This is for backwards compatibility with old versions of BIND 8, which accepted such files without warning although they are illegal according to RFC1035. --- CHANGES | 8 ++ bin/tests/master/dns_master_load_4_data | 2 +- bin/tests/master/t_master.c | 7 +- lib/dns/master.c | 117 +++++++++++++----------- 4 files changed, 75 insertions(+), 59 deletions(-) diff --git a/CHANGES b/CHANGES index afd8e62a73..4fbc923128 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,12 @@ + 834. [func] Accept (but warn about) master files beginning with + an SOA record without an explicit TTL field and + lacking a $TTL directive, by using the SOA MINTTL + as a default TTL. This is for backwards compatibility + with old versions of BIND 8, which accepted such + files without warning although they are illegal + according to RFC1035. + 833. [cleanup] Moved dns_soa_*() from to , and extended them to support all the integer-valued fields of the SOA RR. diff --git a/bin/tests/master/dns_master_load_4_data b/bin/tests/master/dns_master_load_4_data index 0d08f0eeea..66ad1ff36a 100644 --- a/bin/tests/master/dns_master_load_4_data +++ b/bin/tests/master/dns_master_load_4_data @@ -9,4 +9,4 @@ # class is the zone's class # expected_result is a text representation of a dns_result_t # -master4.data test in DNS_R_NOTTL +master4.data test in ISC_R_SUCCESS diff --git a/bin/tests/master/t_master.c b/bin/tests/master/t_master.c index 99931ba43d..b5ab8333a5 100644 --- a/bin/tests/master/t_master.c +++ b/bin/tests/master/t_master.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: t_master.c,v 1.29 2001/01/09 21:41:57 bwelling Exp $ */ +/* $Id: t_master.c,v 1.30 2001/05/22 01:44:36 gson Exp $ */ #include @@ -211,8 +211,9 @@ t3() { t_result(result); } -static const char *a4 = "dns_master_loadfile returns DNS_R_NOTTL when the " - "the ttl is not specified"; +static const char *a4 = "dns_master_loadfile accepts broken zone files " + "where the first record has an undefined TTL, " + "as long as it is a SOA"; static void t4() { diff --git a/lib/dns/master.c b/lib/dns/master.c index 164cf70e65..c7b64a612d 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: master.c,v 1.116 2001/05/21 22:49:24 gson Exp $ */ +/* $Id: master.c,v 1.117 2001/05/22 01:44:37 gson Exp $ */ #include @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -740,6 +741,22 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs, return (result); } +static void +limit_ttl(dns_rdatacallbacks_t *callbacks, const char *source, unsigned int line, + isc_uint32_t *ttlp) +{ + if (*ttlp > 0x7fffffffUL) { + (callbacks->warn)(callbacks, + "%s: %s:%lu: " + "$TTL %lu > MAXTTL, " + "setting $TTL to 0", + "dns_master_load", + source, line, + *ttlp); + *ttlp = 0; + } +} + static isc_result_t load(dns_loadctx_t *lctx) { dns_rdataclass_t rdclass; @@ -871,16 +888,7 @@ load(dns_loadctx_t *lctx) { lctx->ttl = 0; } else if (result != ISC_R_SUCCESS) goto insist_and_cleanup; - if (lctx->ttl > 0x7fffffffUL) { - (callbacks->warn)(callbacks, - "%s: %s:%lu: " - "$TTL %lu > MAXTTL, " - "setting $TTL to 0", - "dns_master_load", - source, line, - lctx->ttl); - lctx->ttl = 0; - } + limit_ttl(callbacks, source, line, &lctx->ttl); lctx->default_ttl = lctx->ttl; lctx->default_ttl_known = ISC_TRUE; EXPECTEOL; @@ -1264,38 +1272,9 @@ load(dns_loadctx_t *lctx) { if (dns_ttl_fromtext(&token.value.as_textregion, &lctx->ttl) == ISC_R_SUCCESS) { - if (lctx->ttl > 0x7fffffffUL) { - (callbacks->warn)(callbacks, - "%s: %s:%lu: " - "TTL %lu > MAXTTL, " - "setting TTL to 0", - "dns_master_load", - source, line, lctx->ttl); - lctx->ttl = 0; - } + limit_ttl(callbacks, source, line, &lctx->ttl); lctx->ttl_known = ISC_TRUE; GETTOKEN(lctx->lex, 0, &token, ISC_FALSE); - } else if (!lctx->ttl_known && !lctx->default_ttl_known) { - /* - * BIND 4 / 8 'USE_SOA_MINIMUM' could be set here. - */ - (*callbacks->error)(callbacks, - "%s: %s:%lu: no TTL specified", - "dns_master_load", source, line); - result = DNS_R_NOTTL; - if (MANYERRS(lctx, result)) { - SETRESULT(lctx, result); - lctx->ttl = 0; - } else if (result != ISC_R_SUCCESS) - goto insist_and_cleanup; - } else if (lctx->default_ttl_known) { - lctx->ttl = lctx->default_ttl; - } else if (lctx->warn_1035) { - (*callbacks->warn)(callbacks, - "%s: %s:%lu: " - "using RFC 1035 TTL semantics", - "dns_master_load", source, line); - lctx->warn_1035 = ISC_FALSE; } if (token.type != isc_tokentype_string) { @@ -1373,20 +1352,6 @@ load(dns_loadctx_t *lctx) { if (type == dns_rdatatype_ns && ictx->glue == NULL) current_has_delegation = ISC_TRUE; - if ((lctx->options & DNS_MASTER_AGETTL) != 0) { - /* - * Adjust the TTL for $DATE. If the RR has already - * expired, ignore it without even parsing the rdata - * part (good for performance, bad for catching - * syntax errors). - */ - if (lctx->ttl < ttl_offset) { - read_till_eol = ISC_TRUE; - continue; - } - lctx->ttl -= ttl_offset; - } - /* * Find a rdata structure. */ @@ -1427,6 +1392,48 @@ load(dns_loadctx_t *lctx) { else covers = 0; + if (!lctx->ttl_known && !lctx->default_ttl_known) { + if (type == dns_rdatatype_soa) { + (*callbacks->warn)(callbacks, + "%s:%lu: no TTL specified; " + "using SOA MINTTL instead", + source, line); + lctx->ttl = dns_soa_getminimum(&rdata[rdcount]); + limit_ttl(callbacks, source, line, &lctx->ttl); + lctx->default_ttl = lctx->ttl; + lctx->default_ttl_known = ISC_TRUE; + } else { + (*callbacks->warn)(callbacks, + "%s:%lu: no TTL specified; " + "zone rejected", + source, line); + result = DNS_R_NOTTL; + if (MANYERRS(lctx, result)) { + SETRESULT(lctx, result); + lctx->ttl = 0; + } else { + goto insist_and_cleanup; + } + } + } else if (lctx->default_ttl_known) { + lctx->ttl = lctx->default_ttl; + } else if (lctx->warn_1035) { + (*callbacks->warn)(callbacks, + "%s: %s:%lu: " + "using RFC 1035 TTL semantics", + "dns_master_load", source, line); + lctx->warn_1035 = ISC_FALSE; + } + + if ((lctx->options & DNS_MASTER_AGETTL) != 0) { + /* + * Adjust the TTL for $DATE. If the RR has already + * expired, ignore it. + */ + if (lctx->ttl < ttl_offset) + continue; + lctx->ttl -= ttl_offset; + } /* * Find type in rdatalist.