From: Peter van Dijk Date: Fri, 5 Oct 2012 11:26:00 +0000 (+0000) Subject: tinydnsbackend updates: add ignore-bogus-records setting; update tai offset; remove... X-Git-Tag: auth-3.2-rc1~120 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f03f9070d5613a3537613c99df4c1041cdecdcc1;p=pdns tinydnsbackend updates: add ignore-bogus-records setting; update tai offset; remove dnslabel dependency; strip dots on names where necessary; minor optimizations (Ruben d'Arco) git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2762 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/modules/tinydnsbackend/tinydnsbackend.cc b/modules/tinydnsbackend/tinydnsbackend.cc index 9ac79423a..f65afbb6e 100644 --- a/modules/tinydnsbackend/tinydnsbackend.cc +++ b/modules/tinydnsbackend/tinydnsbackend.cc @@ -1,7 +1,6 @@ #include "tinydnsbackend.hh" #include "pdns/lock.hh" #include -#include #include #include #include @@ -60,6 +59,7 @@ TinyDNSBackend::TinyDNSBackend(const string &suffix) setArgPrefix("tinydns"+suffix); d_suffix = suffix; d_locations = mustDo("locations"); + d_ignorebogus = mustDo("ignore-bogus-records"); d_taiepoch = 4611686018427387904ULL + getArgAsNum("tai-adjust"); } @@ -131,7 +131,7 @@ void TinyDNSBackend::getAllDomains(vector *domains) { d_cdbReader->searchAll(); DNSResourceRecord rr; - while (get(rr)) { + while (get(rr)) { if (rr.qtype.getCode() == QType::SOA) { SOAData sd; fillSOAData(rr.content, sd); @@ -151,8 +151,7 @@ void TinyDNSBackend::getAllDomains(vector *domains) { bool TinyDNSBackend::list(const string &target, int domain_id) { d_isAxfr=true; - DNSLabel l(target.c_str()); - string key = l.binary(); + string key = simpleCompress(target); d_cdbReader=new CDB(getArg("dbfile")); return d_cdbReader->searchSuffix(key); } @@ -161,11 +160,10 @@ void TinyDNSBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket d_isAxfr = false; string queryDomain = toLowerCanonic(qdomain); - DNSLabel l(queryDomain.c_str()); - string key=l.binary(); + string key=simpleCompress(queryDomain); DLOG(L< locations = getLocations(); - while(locations.size() > 0) { - string locId = locations.back(); - locations.pop_back(); - - if (recloc[0] == locId[0] && recloc[1] == locId[1]) { - foundLocation = true; - break; + if(d_isAxfr || d_qtype.getCode() == QType::ANY || rr.qtype == d_qtype) { + char locwild = pr.get8BitInt(); + if(locwild != '\075' && (locwild == '\076' || locwild == '\053')) { + if (d_isAxfr && d_locations) { // We skip records with a location in AXFR, unless we disable locations. + continue; + } + char recloc[2]; + recloc[0] = pr.get8BitInt(); + recloc[1] = pr.get8BitInt(); + + if (d_locations) { + bool foundLocation = false; + vector locations = getLocations(); + while(locations.size() > 0) { + string locId = locations.back(); + locations.pop_back(); + + if (recloc[0] == locId[0] && recloc[1] == locId[1]) { + foundLocation = true; + break; + } } + if (!foundLocation) { + continue; + } } - if (!foundLocation) { - continue; - } } - } - if(d_isAxfr || d_qtype.getCode() == QType::ANY || rr.qtype == d_qtype) { - if (d_isAxfr && (val[2] == '\052' || val[2] == '\053' )) { // Keys are not stored with wildcard character, with AXFR we need to add that. key.insert(0, 1, '\052'); key.insert(0, 1, '\001'); } - DNSLabel dnsKey(key.c_str(), key.size()); - rr.qname = dnsKey.human(); - rr.qname = rr.qname.erase(rr.qname.size()-1, 1);// strip the last dot, packethandler needs this. + rr.qname.clear(); + simpleExpandTo(key, 0, rr.qname); + rr.qname = stripDot(rr.qname); // strip the last dot, packethandler needs this. rr.domain_id=-1; // 11:13.21 <@ahu> IT IS ALWAYS AUTH --- well not really because we are just a backend :-) // We could actually do NSEC3-NARROW DNSSEC according to Habbie, if we do, we need to change something ehre. @@ -272,24 +269,33 @@ bool TinyDNSBackend::get(DNSResourceRecord &rr) continue; } } - - DNSRecord dr; - dr.d_class = 1; - dr.d_type = rr.qtype.getCode(); - dr.d_clen = val.size()-pr.d_pos; - DNSRecordContent *drc = DNSRecordContent::mastermake(dr, pr); - - string content = drc->getZoneRepresentation(); - delete drc; - if(rr.qtype.getCode() == QType::MX || rr.qtype.getCode() == QType::SRV) { - vectorparts; - stringtok(parts,content," "); - rr.priority=atoi(parts[0].c_str()); - rr.content=content.substr(parts[0].size()+1); - } else { - rr.content = content; + try { + DNSRecord dr; + dr.d_class = 1; + dr.d_type = rr.qtype.getCode(); + dr.d_clen = val.size()-pr.d_pos; + DNSRecordContent *drc = DNSRecordContent::mastermake(dr, pr); + + string content = drc->getZoneRepresentation(); + cerr<<"CONTENT: "<parts; + stringtok(parts,content," "); + rr.priority=atoi(parts[0].c_str()); + rr.content=content.substr(parts[0].size()+1); + } else { + rr.content = content; + } + } + catch (...) { + if (d_ignorebogus) { + L< NativeYes MasterYes - SlaveNo - SuperslaveNo - AutoserialNo - DNSSECNo + SlaveNo + SuperslaveNo + AutoserialNo + DNSSECNo Multiple instancesYes @@ -17304,8 +17304,8 @@ the data.cdb files without any changes. This adjusts the TAI value if timestamps are used. -These seconds will be added to the start point (1970) and will allow you to adjust for leap seconds. The current default is 10, -but as of june 30th 2012 should be 11. +These seconds will be added to the start point (1970) and will allow you to adjust for leap seconds. The current default is 11. +The last update was on june 30th 2012. @@ -17315,7 +17315,19 @@ These seconds will be added to the start point (1970) and will allow you to adju Tell the TinyDNSBackend to notify all the slave nameservers on startup. This might cause broadcast storms. Default is no. - + + tinydns-ignore-bogus-records + + + The tinydns-data program can create data.cdb files that have bad/corrupt RDATA. + PowerDNS will crash when it tries to read that bad/corrupt data. This option (change to yes), allows you to ignore that bad RDATA + to make PowerDNS operate when bad data is in your CDB file. Be aware that the records are then ignored, where tinydns would + still send out the bogus data. + The option is primarily useful in master mode, as that reads all the packets in the zone to find all the SOA records. + + + + tinydns-locations Enable or Disable location support in the backend. Changing the value to 'no' will make the backend ignore the locations. This then returns all records. When the setting is changed to 'no' an AXFR will also return all the records. With the setting on 'yes' an AXFR will only return records without a location.