]> granicus.if.org Git - pdns/commitdiff
API: honor SOA-EDIT-API when handling set-ptr
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Wed, 13 Apr 2016 20:19:29 +0000 (22:19 +0200)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Wed, 13 Apr 2016 21:20:00 +0000 (23:20 +0200)
pdns/ws-auth.cc

index 3fd11b9673c5e71bec1fe282aab4475aba0ef195..6ea92e465c1241df44d6b21b970bded7dfc3163e 100644 (file)
@@ -1060,11 +1060,35 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
     if (!B.getAuth(&fakePacket, &sd, rr.qname))
       throw ApiException("Could not find domain for PTR '"+rr.qname.toString()+"' requested for '"+rr.content+"' (while saving)");
 
-    sd.db->startTransaction(rr.qname);
+    string soa_edit_api_kind;
+    string soa_edit_kind;
+    bool soa_changed = false;
+    DNSResourceRecord soarr;
+    sd.db->getDomainMetadataOne(sd.qname, "SOA-EDIT-API", soa_edit_api_kind);
+    sd.db->getDomainMetadataOne(sd.qname, "SOA-EDIT", soa_edit_kind);
+    if (!soa_edit_api_kind.empty()) {
+      soarr.qname = sd.qname;
+      soarr.content = serializeSOAData(sd);
+      soarr.qtype = "SOA";
+      soarr.domain_id = sd.domain_id;
+      soarr.auth = 1;
+      soarr.ttl = sd.ttl;
+      increaseSOARecord(soarr, soa_edit_api_kind, soa_edit_kind);
+      // fixup dots after serializeSOAData/increaseSOARecord
+      soarr.content = makeBackendRecordContent(soarr.qtype, soarr.content);
+      soa_changed = true;
+    }
+
+    sd.db->startTransaction(sd.qname);
     if (!sd.db->replaceRRSet(sd.domain_id, rr.qname, rr.qtype, vector<DNSResourceRecord>(1, rr))) {
       sd.db->abortTransaction();
       throw ApiException("PTR-Hosting backend for "+rr.qname.toString()+"/"+rr.qtype.getName()+" does not support editing records.");
     }
+
+    if (soa_changed) {
+      sd.db->replaceRRSet(sd.domain_id, soarr.qname, soarr.qtype, vector<DNSResourceRecord>(1, soarr));
+    }
+
     sd.db->commitTransaction();
     PC.purgeExact(rr.qname);
   }