From: Miek Gieben Date: Wed, 21 Dec 2005 09:15:55 +0000 (+0000) Subject: allow zones that don't start with a SOA record X-Git-Tag: release-1.1.0~502 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b61474fe943b95660f65043db61ee458e72a66d9;p=thirdparty%2Fldns.git allow zones that don't start with a SOA record --- diff --git a/examples/ldns-read-zone.c b/examples/ldns-read-zone.c index 9dc8e84f..7669b6ca 100644 --- a/examples/ldns-read-zone.c +++ b/examples/ldns-read-zone.c @@ -13,7 +13,7 @@ main(int argc, char **argv) { char *filename; FILE *fp; - ldns_zone *z; + ldns_zone *z = NULL; int line_nr = 0; int c; bool sort = false; @@ -50,7 +50,6 @@ main(int argc, char **argv) z = ldns_zone_new_frm_fp_l(fp, NULL, 0, LDNS_RR_CLASS_IN, &line_nr); - if (z) { if (sort) { ldns_zone_sort(z); diff --git a/zone.c b/zone.c index 0cd1ab72..ea237b23 100644 --- a/zone.c +++ b/zone.c @@ -163,61 +163,40 @@ ldns_zone_new_frm_fp_l(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c ldns_rr *last_rr = NULL; ldns_rdf *my_origin = NULL; ldns_rdf *my_prev; - uint8_t i; + bool soa_seen = false; /* 2 soa are an error */ newzone = ldns_zone_new(); my_origin = origin; my_ttl = ttl; my_class = c; - /* read until we got a soa, all crap above is discarded - * except $directives - */ - if (origin) { my_origin = ldns_rdf_clone(origin); /* also set the prev */ my_prev = ldns_rdf_clone(origin); } - i = 0; - do { - rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, &my_prev, line_nr); - i++; - } while (!rr && i <= 9); - - if (i > 9) { - /* there is a lot of crap here, bail out before somebody gets - * hurt */ - if (rr) { - ldns_rr_free(rr); - } - if (my_origin) { - ldns_rdf_free(my_origin); - } - ldns_zone_deep_free(newzone); - return NULL; - } - - if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) { - /* first rr MUST be the soa */ - ldns_rr_free(rr); - if (my_origin) { - ldns_rdf_free(my_origin); - } - ldns_zone_deep_free(newzone); - return NULL; - } - - ldns_zone_set_soa(newzone, rr); - + /* read it as root */ if (!my_origin) { - my_origin = ldns_rdf_clone(ldns_rr_owner(rr)); + my_origin = ldns_dname_new_frm_str("."); } while(!feof(fp)) { rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, &my_prev, line_nr); if (rr) { + if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) { + if (soa_seen) { + /* second SOA + * LDNS_STATUS_SOA? */ + ldns_zone_deep_free(newzone); + return NULL; + } + soa_seen = true; + ldns_zone_set_soa(newzone, rr); + continue; + } + + /* a normal RR - as sofar the DNS is normal */ last_rr = rr; if (!ldns_zone_push_rr(newzone, rr)) { dprintf("%s", "error pushing rr\n");