]> granicus.if.org Git - pdns/commitdiff
API: allow writing to domains.account field
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Sat, 7 Feb 2015 14:20:42 +0000 (15:20 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Sat, 7 Feb 2015 19:48:39 +0000 (20:48 +0100)
modules/gmysqlbackend/gmysqlbackend.cc
modules/gpgsqlbackend/gpgsqlbackend.cc
modules/gsqlite3backend/gsqlite3backend.cc
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/dnsbackend.hh
pdns/ws-auth.cc
regression-tests.api/test_Zones.py

index 6320c31705ed04bb991c6772bb33f3a1a4a2d52d..793ade9afae7ac6068ce9d7f2e3d12bb61642e65 100644 (file)
@@ -72,7 +72,7 @@ public:
     declare(suffix,"supermaster-query","", "select account from supermasters where ip=? and nameserver=?");
     declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=? and account=?");
 
-    declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',?)");
+    declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE',?,?)");
     declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',?,?,?)");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (?,?,?,?,?,?,?,?)");
@@ -92,6 +92,7 @@ public:
 
     declare(suffix,"update-master-query","", "update domains set master=? where name=?");
     declare(suffix,"update-kind-query","", "update domains set type=? where name=?");
+    declare(suffix,"update-account-query","", "update domains set account=? where name=?");
     declare(suffix,"update-serial-query","", "update domains set notified_serial=? where id=?");
     declare(suffix,"update-lastcheck-query","", "update domains set last_check=? where id=?");
     declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=?");
index 25d65e8d30f84bfbc5ba75f40cfb79f4d0ec8d89..74b6e05184512602aaf1a26661aaf995c5559114 100644 (file)
@@ -66,7 +66,7 @@ public:
     declare(suffix,"supermaster-query","", "select account from supermasters where ip=$1 and nameserver=$2");
     declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=$1 and account=$2");
 
-    declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',$1)");
+    declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE',$1,$2)");
     declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',$1,$2,$3)");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ($1,$2,$3,$4,$5,$6,$7,$8)");
@@ -86,6 +86,7 @@ public:
 
     declare(suffix,"update-master-query","", "update domains set master=$1 where name=$2");
     declare(suffix,"update-kind-query","", "update domains set type=$1 where name=$2");
+    declare(suffix,"update-account-query","", "update domains set account=$1 where name=$2");
     declare(suffix,"update-serial-query","", "update domains set notified_serial=$1 where id=$2");
     declare(suffix,"update-lastcheck-query","", "update domains set last_check=$1 where id=$2");
     declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=$1");
index a8bbf231c948cdced42a640ae0b8de2545767e83..3c872620645a37aba6f8fcd030795ce34555396c 100644 (file)
@@ -83,7 +83,7 @@ public:
     declare(suffix, "supermaster-query", "", "select account from supermasters where ip=:ip and nameserver=:nameserver");
     declare(suffix, "supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=:nameserver and account=:account");
 
-    declare(suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE',:domain)");
+    declare(suffix, "insert-zone-query", "", "insert into domains (type,name,account) values('NATIVE',:domain,:account)");
     declare(suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE',:domain,:masters,:account)");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (:content,:ttl,:priority,:qtype,:domain_id,:disabled,:qname,:auth)");
@@ -103,6 +103,7 @@ public:
 
     declare(suffix, "update-master-query", "", "update domains set master=:master where name=:domain");
     declare(suffix, "update-kind-query", "", "update domains set type=:kind where name=:domain");
+    declare(suffix, "update-account-query","", "update domains set account=:account where name=:domain");
     declare(suffix, "update-serial-query", "", "update domains set notified_serial=:serial where id=:domain_id");
     declare(suffix, "update-lastcheck-query", "", "update domains set last_check=:last_check where id=:domain_id");
     declare(suffix, "zone-lastchange-query", "", "select max(change_date) from records where domain_id=:domain_id");
index c45aa2ac4bdcf350f2c28806f184b1094f66ba5b..42b9c17817aa9e20c71c116e9597b19ea50eb16f 100644 (file)
@@ -72,6 +72,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
   d_UpdateKindOfZoneQuery=getArg("update-kind-query");
   d_UpdateSerialOfZoneQuery=getArg("update-serial-query");
   d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
+  d_UpdateAccountOfZoneQuery=getArg("update-account-query");
   d_ZoneLastChangeQuery=getArg("zone-lastchange-query");
   d_InfoOfAllMasterDomainsQuery=getArg("info-all-master-query");
   d_DeleteDomainQuery=getArg("delete-domain-query");
@@ -142,6 +143,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
   d_UpdateKindOfZoneQuery_stmt = NULL;
   d_UpdateSerialOfZoneQuery_stmt = NULL;
   d_UpdateLastCheckofZoneQuery_stmt = NULL;
+  d_UpdateAccountOfZoneQuery_stmt = NULL;
   d_InfoOfAllMasterDomainsQuery_stmt = NULL;
   d_DeleteDomainQuery_stmt = NULL;
   d_DeleteZoneQuery_stmt = NULL;
@@ -270,6 +272,21 @@ bool GSQLBackend::setKind(const string &domain, const DomainInfo::DomainKind kin
   return true;
 }
 
+bool GSQLBackend::setAccount(const string &domain, const string &account)
+{
+  try {
+    d_UpdateAccountOfZoneQuery_stmt->
+            bind("account", account)->
+            bind("domain", toLower(domain))->
+            execute()->
+            reset();
+  }
+  catch (SSqlException &e) {
+    throw PDNSException("GSQLBackend unable to set account of domain \""+domain+"\": "+e.txtReason());
+  }
+  return true;
+}
+
 bool GSQLBackend::getDomainInfo(const string &domain, DomainInfo &di)
 {
   /* fill DomainInfo from database info:
index ed091e110a676c6b61678109b1db4451f1a1423b..b2e8d0fec10e19a57bed197462e3e49711a6496b 100644 (file)
@@ -39,7 +39,7 @@ public:
       d_InfoOfAllSlaveDomainsQuery_stmt = d_db->prepare(d_InfoOfAllSlaveDomainsQuery, 0);
       d_SuperMasterInfoQuery_stmt = d_db->prepare(d_SuperMasterInfoQuery, 2);
       d_GetSuperMasterIPs_stmt = d_db->prepare(d_GetSuperMasterIPs, 2);
-      d_InsertZoneQuery_stmt = d_db->prepare(d_InsertZoneQuery, 1);
+      d_InsertZoneQuery_stmt = d_db->prepare(d_InsertZoneQuery, 2);
       d_InsertSlaveZoneQuery_stmt = d_db->prepare(d_InsertSlaveZoneQuery, 3);
       d_InsertRecordQuery_stmt = d_db->prepare(d_InsertRecordQuery, 8);
       d_InsertEntQuery_stmt = d_db->prepare(d_InsertEntQuery, 3);
@@ -47,6 +47,7 @@ public:
       d_InsertEntOrderQuery_stmt = d_db->prepare(d_InsertEntOrderQuery, 4);
       d_UpdateMasterOfZoneQuery_stmt = d_db->prepare(d_UpdateMasterOfZoneQuery, 2);
       d_UpdateKindOfZoneQuery_stmt = d_db->prepare(d_UpdateKindOfZoneQuery, 2);
+      d_UpdateAccountOfZoneQuery_stmt = d_db->prepare(d_UpdateAccountOfZoneQuery, 2);
       d_UpdateSerialOfZoneQuery_stmt = d_db->prepare(d_UpdateSerialOfZoneQuery, 2);
       d_UpdateLastCheckofZoneQuery_stmt = d_db->prepare(d_UpdateLastCheckofZoneQuery, 2);
       d_InfoOfAllMasterDomainsQuery_stmt = d_db->prepare(d_InfoOfAllMasterDomainsQuery, 0);
@@ -115,6 +116,7 @@ public:
     release(&d_InsertEntOrderQuery_stmt);
     release(&d_UpdateMasterOfZoneQuery_stmt);
     release(&d_UpdateKindOfZoneQuery_stmt);
+    release(&d_UpdateAccountOfZoneQuery_stmt);
     release(&d_UpdateSerialOfZoneQuery_stmt);
     release(&d_UpdateLastCheckofZoneQuery_stmt);
     release(&d_InfoOfAllMasterDomainsQuery_stmt);
@@ -180,6 +182,7 @@ public:
   void setNotified(uint32_t domain_id, uint32_t serial);
   bool setMaster(const string &domain, const string &ip);
   bool setKind(const string &domain, const DomainInfo::DomainKind kind);
+  bool setAccount(const string &domain, const string &account);
 
   virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after);
   bool updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth);
@@ -244,6 +247,7 @@ private:
   string d_InsertEntOrderQuery;
   string d_UpdateMasterOfZoneQuery;
   string d_UpdateKindOfZoneQuery;
+  string d_UpdateAccountOfZoneQuery;
   string d_UpdateSerialOfZoneQuery;
   string d_UpdateLastCheckofZoneQuery;
   string d_InfoOfAllMasterDomainsQuery;
@@ -312,6 +316,7 @@ private:
   SSqlStatement* d_InsertEntOrderQuery_stmt;
   SSqlStatement* d_UpdateMasterOfZoneQuery_stmt;
   SSqlStatement* d_UpdateKindOfZoneQuery_stmt;
+  SSqlStatement* d_UpdateAccountOfZoneQuery_stmt;
   SSqlStatement* d_UpdateSerialOfZoneQuery_stmt;
   SSqlStatement* d_UpdateLastCheckofZoneQuery_stmt;
   SSqlStatement* d_InfoOfAllMasterDomainsQuery_stmt;
index c07a27b05f0a40aa0a728f1d449d2d2b631b3f33..b4122b96e4bca16e76e12804a9dbf09c649b31f9 100644 (file)
@@ -337,6 +337,12 @@ public:
     return false;
   }
 
+  //! Called when the Account of a domain should be changed
+  virtual bool setAccount(const string &domain, const string &account)
+  {
+    return false;
+  }
+
   //! Can be called to seed the getArg() function with a prefix
   void setArgPrefix(const string &prefix);
 
index 828542201d76d6eef91f79bd5e60e41cc463bc53..40a1184480670ca412ecb969ff4d5d48d153a4ac 100644 (file)
@@ -470,6 +470,9 @@ static void updateDomainSettingsFromDocument(const DomainInfo& di, const string&
   if (document["soa_edit"].IsString()) {
     di.backend->setDomainMetadataOne(zonename, "SOA-EDIT", document["soa_edit"].GetString());
   }
+  if (document["account"].IsString()) {
+    di.backend->setAccount(zonename, document["account"].GetString());
+  }
 }
 
 static void apiZoneCryptokeys(HttpRequest* req, HttpResponse* resp) {
index 3daf9ddb314192ddbf0e580f8822ce41cfa5252e..8223c3e7a07d19467797df338d5d893a4d30a33b 100644 (file)
@@ -75,6 +75,15 @@ class AuthZones(ApiTestCase):
         self.assertGreater(soa_serial, payload['serial'])
         self.assertEquals(soa_serial, data['serial'])
 
+    def test_create_zone_with_account(self):
+        # soa_edit_api wins over serial
+        payload, data = self.create_zone(account='anaccount', serial=10)
+        print data
+        for k in ('account', ):
+            self.assertIn(k, data)
+            if k in payload:
+                self.assertEquals(data[k], payload[k])
+
     def test_create_zone_with_records(self):
         name = unique_zone_name()
         records = [