]> granicus.if.org Git - pdns/commitdiff
auth-api: refactor checks of RRsets types while importing them
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 17 May 2018 09:36:55 +0000 (11:36 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 17 May 2018 09:36:55 +0000 (11:36 +0200)
pdns/ws-auth.cc

index 518360e11bc50379d6736651f26cbf51192d54be..63214bddb7bc80dd78ffd12991d2e407ec4f0f96 100644 (file)
@@ -306,7 +306,7 @@ static Json::object getZoneInfo(const DomainInfo& di, DNSSECKeeper *dk) {
   vector<string> masters;
   for(const auto& m : di.masters)
     masters.push_back(m.toStringWithPortExcept(53));
-  
+
   return Json::object {
     // id is the canonical lookup key, which doesn't actually match the name (in some cases)
     { "id", zoneId },
@@ -462,6 +462,12 @@ void productServerStatisticsFetch(map<string,string>& out)
   out["uptime"] = std::to_string(time(0) - s_starttime);
 }
 
+static void validateGatheredRRType(const DNSResourceRecord& rr) {
+  if (rr.qtype.getCode() == QType::OPT || rr.qtype.getCode() == QType::TSIG) {
+    throw ApiException("RRset "+rr.qname.toString()+" IN "+rr.qtype.getName()+": invalid type given");
+  }
+}
+
 static void gatherRecords(const Json container, const DNSName& qname, const QType qtype, const int ttl, vector<DNSResourceRecord>& new_records, vector<DNSResourceRecord>& new_ptrs) {
   UeberBackend B;
   DNSResourceRecord rr;
@@ -469,6 +475,8 @@ static void gatherRecords(const Json container, const DNSName& qname, const QTyp
   rr.qtype = qtype;
   rr.auth = 1;
   rr.ttl = ttl;
+
+  validateGatheredRRType(rr);
   for(auto record : container["records"].array_items()) {
     string content = stringFromJson(record, "content");
     rr.disabled = boolFromJson(record, "disabled");
@@ -1181,6 +1189,7 @@ static void gatherRecordsFromZone(const std::string& zonestring, vector<DNSResou
         continue;
       if(rr.qtype.getCode() == QType::SOA)
         seenSOA=true;
+      validateGatheredRRType(rr);
 
       new_records.push_back(rr);
     }
@@ -1646,10 +1655,6 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
         if (!qname.isPartOf(zonename) && qname != zonename)
           throw ApiException("RRset "+qname.toString()+" IN "+qtype.getName()+": Name is out of zone");
 
-        if (qtype.getCode() == QType::OPT || qtype.getCode() == QType::TSIG) {
-          throw ApiException("RRset "+qname.toString()+" IN "+stringFromJson(rrset, "type")+": invalid type given");
-        }
-
         bool replace_records = rrset["records"].is_array();
         bool replace_comments = rrset["comments"].is_array();