]> granicus.if.org Git - pdns/commitdiff
API: create slave zones completely empty
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 20 May 2014 15:22:53 +0000 (17:22 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 20 May 2014 15:26:07 +0000 (17:26 +0200)
We should not insert a SOA record, as this would cause serving
of NXDOMAIN until the domain has been slaved.

Fixes #1425.

modules/gmysqlbackend/gmysqlbackend.cc
modules/goraclebackend/goraclebackend.cc
modules/gpgsqlbackend/gpgsqlbackend.cc
modules/gsqlite3backend/gsqlite3backend.cc
pdns/ws-auth.cc
regression-tests.api/test_Zones.py

index d156a9ab66ea9ded605296e60b2232b93da2b63c..50abc56908fe1bce49f639ca10cde3d6d2e29f2d 100644 (file)
@@ -117,7 +117,7 @@ public:
     declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
     declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
 
-    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=0 OR %d)");
+    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR %d");
 
     declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
     declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')");
index bfcd109654e78fcdd94e1521bbd54ed4edb3a1ae..741dbe7a2f7e1dc2c9b4c856182185eed0e6717a 100644 (file)
@@ -124,7 +124,7 @@ public:
     declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
     declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
 
-    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=0 OR 1=%d)");
+    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR 1=%d");
 
     declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,\"comment\" FROM comments WHERE domain_id=%d");
     declare(suffix, "insert-comment-query", "", "INSERT INTO comments (id, domain_id, name, type, modified_at, account, \"comment\") VALUES (comments_id_sequence.nextval, %d, '%s', '%s', %d, '%s', '%s')");
index 2041f83973f28925b7cbc8d247c8cae84a92ce93..64b08f43a2a35362f0f180bb78cffdad813d1316 100644 (file)
@@ -113,7 +113,7 @@ public:
     declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
     declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
 
-    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=false OR %d::bool)");
+    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR %d::bool");
 
     declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
     declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, E'%s', E'%s', %d, E'%s', E'%s')");
index 83ffea148a4b40fb269986c5ba14afc3e971fd42..deb9b52b4a055a7d1d99d2141d96df9260d07689 100644 (file)
@@ -127,7 +127,7 @@ public:
     declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
     declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
 
-    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=0 OR %d)");
+    declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR %d");
 
     declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
     declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')");
index 2c5bb967318f2b4f2054c1a26097a393b5107d7d..4b120807e5585d1830f2e98a04244bec81988409 100644 (file)
@@ -523,7 +523,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
     rr.ttl = ::arg().asNum("default-ttl");
     rr.priority = 0;
 
-    if (!have_soa) {
+    if (!have_soa && zonekind != DomainInfo::Slave) {
       // synthesize a SOA record so the zone "really" exists
 
       SOAData sd;
index 955bcdae7ef586c1c75e42c0b4cc58ef7646ffa3..988876c407a8286d264195b4d7b0a18c7625e05b 100644 (file)
@@ -157,6 +157,27 @@ class AuthZones(ApiTestCase):
         for k in ('name', 'masters', 'kind'):
             self.assertIn(k, data)
             self.assertEquals(data[k], payload[k])
+        print "payload:", payload
+        print "data:", data
+        # Because slave zones don't get a SOA, we need to test that they'll show up in the zone list.
+        r = self.session.get(self.url("/servers/localhost/zones"))
+        zonelist = r.json()
+        print "zonelist:", zonelist
+        self.assertIn(payload['name'], [zone['name'] for zone in zonelist])
+        # Also test that fetching the zone works.
+        r = self.session.get(self.url("/servers/localhost/zones/" + data['id']))
+        data = r.json()
+        print "zone (fetched):", data
+        for k in ('name', 'masters', 'kind'):
+            self.assertIn(k, data)
+            self.assertEquals(data[k], payload[k])
+        self.assertEqual(data['serial'], 0)
+        self.assertEqual(data['records'], [])
+
+    def test_delete_slave_zone(self):
+        payload, data = self.create_zone(kind='Slave', nameservers=None, masters=['127.0.0.2'])
+        r = self.session.delete(self.url("/servers/localhost/zones/" + data['id']))
+        r.raise_for_status()
 
     def test_get_zone_with_symbols(self):
         payload, data = self.create_zone(name='foo/bar.'+unique_zone_name())