From 66d34461cb7bffc972068cdcc43beaabe8f0eb5f Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 24 Jan 2016 15:59:22 +0100 Subject: [PATCH] implement pdnsutil create-zone zone nsname, add-record, delete-rrset, replace-rrset --- pdns/pdnsutil.cc | 151 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 140 insertions(+), 11 deletions(-) diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 02abec4a7a..7b56b91f06 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -919,16 +919,15 @@ int loadZone(DNSName zone, const string& fname) { return 0; } -int createZone(const DNSName &zone) { +int createZone(const DNSName &zone, const DNSName& nsname) { UeberBackend B; DomainInfo di; if (B.getDomainInfo(zone, di)) { cerr<<"Domain '"<startTransaction(zone, di.id); di.backend->feedRecord(rr); + if(!nsname.empty()) { + cout<<"Also adding one NS record"<feedRecord(rr); + } + di.backend->commitTransaction(); return 1; } +// add-record ZONE name type [ttl] "content" ["content"] +int addOrReplaceRecord(bool addOrReplace, const vector& cmds) { + DNSResourceRecord rr; + vector newrrs; + DNSName zone(cmds[1]); + DNSName name; + if(cmds[2]=="@") + name=zone; + else + name=DNSName(cmds[2])+zone; + + rr.qtype = DNSRecordContent::TypeToNumber(cmds[3]); + rr.ttl = ::arg().asNum("default-ttl"); + + UeberBackend B; + DomainInfo di; + + if(!B.getDomainInfo(zone, di)) { + cerr<<"Domain '"< 5) { + rr.ttl=atoi(cmds[4].c_str()); + if(std::to_string(rr.ttl)==cmds[4]) { + contentStart++; + } + else rr.ttl = ::arg().asNum("default-ttl"); + } + + for(auto i = contentStart ; i < cmds.size() ; ++i) { + rr.content = DNSRecordContent::mastermake(rr.qtype.getCode(), 1, cmds[i])->getZoneRepresentation(true); + newrrs.push_back(rr); + } + + B.lookup(QType(QType::ANY), rr.qname, 0, di.id); + bool found=false; + if(rr.qtype.getCode() == QType::CNAME) { // this will save us SO many questions + + while(B.get(rr)) { + if(addOrReplace || rr.qtype.getCode() != QType::CNAME) // the replace case is ok if we replace one CNAME by the other + found=true; + } + if(found) { + cerr<<"Attempting to add CNAME to "<replaceRRSet(di.id, name, rr.qtype, newrrs); + + return 1; +} + +// delete-rrset zone name type +int deleteRRSet(const std::string& zone_, const std::string& name_, const std::string& type_) +{ + UeberBackend B; + DomainInfo di; + DNSName zone(zone_); + if(!B.getDomainInfo(zone, di)) { + cerr<<"Domain '"<replaceRRSet(di.id, name, qt, vector()); + return 0; +} int listAllZones(const string &type="") { @@ -985,9 +1088,9 @@ int listAllZones(const string &type="") { } if (kindFilter != -1) - cout< 2 ? DNSName(cmds[2]): DNSName())); + } + else if(cmds[0] == "add-record") { + if(cmds.size() < 5) { + cerr<<"Syntax: pdnsutil add-record ZONE name type [ttl] \"content\" [\"content\"...]"<