From 67c4425d361ccfc207150f3fc178f09f5f2ccdeb Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Tue, 9 Feb 2016 17:39:10 +0100 Subject: [PATCH] Allow root-zones as '.' in the SQL backends Allow importing a root-zone through zone2sql as well. This also fixes slaving the root with the bind backend and dnssec. --- .../authoritative/backend-generic-sql.md | 3 ++ pdns/backends/gsql/gsqlbackend.cc | 4 +- pdns/backends/gsql/ssql.hh | 2 +- pdns/zone2sql.cc | 44 ++++++++++--------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/docs/markdown/authoritative/backend-generic-sql.md b/docs/markdown/authoritative/backend-generic-sql.md index 5cd920d774..6bcc02e78b 100644 --- a/docs/markdown/authoritative/backend-generic-sql.md +++ b/docs/markdown/authoritative/backend-generic-sql.md @@ -8,6 +8,9 @@ backend is needed to cover all needs. a '.' in PowerDNS storage! If a trailing '.' is present it will inevitably cause problems, problems that may be hard to debug. +**Note**: Since 4.0.0, a root zone or record should have a name of '.' (no quotes). +This is the only exception to the 'no terminating dot in SQL storage' rule. + # Basic functionality All domains in the generic SQL backends have a 'type' field that describes the [mode of operation](modes-of-operation.md). diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index bcba0baef3..9463180856 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -1032,7 +1032,7 @@ bool GSQLBackend::list(const DNSName &target, int domain_id, bool include_disabl bool GSQLBackend::listSubZone(const DNSName &zone, int domain_id) { if (!isOurDomain(nullptr, domain_id)) return false; - string wildzone = "%." + stripDot(zone.toString()); // tolower()? + string wildzone = "%." + toLower(zone.toStringNoDot()); try { d_query_name = "list-subzone-query"; @@ -1118,7 +1118,7 @@ bool GSQLBackend::createDomain(const DNSName &domain, const string &type, const reset(); } catch(SSqlException &e) { - throw DBException("Database error trying to insert new domain '"+domain.toString()+"': "+ e.txtReason()); + throw DBException("Database error trying to insert new domain '"+domain.toStringRootDot()+"': "+ e.txtReason()); } return true; } diff --git a/pdns/backends/gsql/ssql.hh b/pdns/backends/gsql/ssql.hh index 3b43b24710..17ea9727ee 100644 --- a/pdns/backends/gsql/ssql.hh +++ b/pdns/backends/gsql/ssql.hh @@ -47,7 +47,7 @@ public: virtual SSqlStatement* bind(const string& name, unsigned long long value)=0; virtual SSqlStatement* bind(const string& name, const std::string& value)=0; SSqlStatement* bind(const string& name, const DNSName& value) { - return bind(name, toLower(value.toStringNoDot())); + return bind(name, toLower(value.toStringRootDot())); } virtual SSqlStatement* bindNull(const string& name)=0; virtual SSqlStatement* execute()=0;; diff --git a/pdns/zone2sql.cc b/pdns/zone2sql.cc index eefee92525..bbfed777dc 100644 --- a/pdns/zone2sql.cc +++ b/pdns/zone2sql.cc @@ -110,16 +110,17 @@ static void startNewTransaction() cout<<"BEGIN TRANSACTION;"< *masters = 0) { +static void emitDomain(const DNSName& domain, const vector *masters = 0) { + string iDomain = domain.toStringRootDot(); if(!::arg().mustDo("slave")) { if(g_mode==POSTGRES || g_mode==MYSQL || g_mode==SQLITE) { - cout<<"insert into domains (name,type) values ("< *masters = 0) for(const string& mstr : *masters) { mstrs.append(mstr); mstrs.append(1, ' '); - } + } } if (mstrs.empty()) - cout<<"insert into domains (name,type) values ("< *masters = 0) } bool g_doJSONComments; -static void emitRecord(const string& zoneName, const DNSName &DNSqname, const string &qtype, const string &ocontent, int ttl, const string& comment="") +static void emitRecord(const DNSName& zoneName, const DNSName &DNSqname, const string &qtype, const string &ocontent, int ttl, const string& comment="") { - string qname = stripDot(DNSqname.toString()); + string qname = DNSqname.toStringRootDot(); + string zname = zoneName.toStringRootDot(); int prio=0; int disabled=0; string recordcomment; @@ -182,7 +184,7 @@ static void emitRecord(const string& zoneName, const DNSName &DNSqname, const st } bool auth = true; - if(qtype == "NS" && !pdns_iequals(qname, zoneName)) { + if(qtype == "NS" && !pdns_iequals(qname, zname)) { auth=false; } @@ -191,36 +193,36 @@ static void emitRecord(const string& zoneName, const DNSName &DNSqname, const st sqlstr(toLower(qname))<<", "<< sqlstr(qtype)<<", "<< sqlstr(stripDotContent(content))<<", "<name.toStringNoDot(), &(i->masters)); + emitDomain(i->name, &(i->masters)); ZoneParserTNG zpt(i->filename, i->name, BP.getDirectory()); DNSResourceRecord rr; @@ -383,7 +385,7 @@ try if(rr.qtype.getCode() == QType::SOA) seenSOA=true; - emitRecord(i->name.toStringNoDot(), rr.qname, rr.qtype.getName(), rr.content, rr.ttl, comment); + emitRecord(i->name, rr.qname, rr.qtype.getName(), rr.content, rr.ttl, comment); } num_domainsdone++; } @@ -424,7 +426,7 @@ try seenSOA=true; if(!haveEmittedZone) { if(!zpt.getZoneName().empty()){ - emitDomain(zpt.getZoneName().toStringNoDot()); + emitDomain(zpt.getZoneName()); haveEmittedZone = true; } else { // We have no zonename yet, don't emit @@ -432,7 +434,7 @@ try } } - emitRecord(zpt.getZoneName().toStringNoDot(), rr.qname, rr.qtype.getName(), rr.content, rr.ttl, comment); + emitRecord(zpt.getZoneName(), rr.qname, rr.qtype.getName(), rr.content, rr.ttl, comment); } num_domainsdone=1; } -- 2.47.2