]> 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)
committermind04 <mind04@monshouwer.org>
Thu, 26 Feb 2015 19:37:24 +0000 (20:37 +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 49a1958aa69e534f51f9c6c7e3c57c82ba4c3f42..0c41f23fac3ca1e079dd5212d77d1f607dfa1f29 100644 (file)
@@ -72,7 +72,7 @@ public:
     declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver='%s'");
     declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%s'");
 
-    declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE','%s')");
+    declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE','%s','%s')");
     declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s','%d')");
@@ -92,6 +92,7 @@ public:
 
     declare(suffix,"update-master-query","", "update domains set master='%s' where name='%s'");
     declare(suffix,"update-kind-query","", "update domains set type='%s' where name='%s'");
+    declare(suffix,"update-account-query","", "update domains set account='%s' where name='%s'");
     declare(suffix,"update-serial-query","", "update domains set notified_serial=%d where id=%d");
     declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
     declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
index a488625ae5499eb81580c4703305fd189427ae04..549d988fca0b92db5686db3b540916edc8956db2 100644 (file)
@@ -66,7 +66,7 @@ public:
     declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver=E'%s'");
     declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=E'%s' and account=E'%s'");
 
-    declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',E'%s')");
+    declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE',E'%s',E'%s')");
     declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',E'%s',E'%s',E'%s')");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s','%d')");
@@ -86,6 +86,7 @@ public:
 
     declare(suffix,"update-master-query","", "update domains set master='%s' where name='%s'");
     declare(suffix,"update-kind-query","", "update domains set type='%s' where name='%s'");
+    declare(suffix,"update-account-query","", "update domains set account=E'%s' where name=E'%s'");
     declare(suffix,"update-serial-query","", "update domains set notified_serial=%d where id=%d");
     declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
     declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
index ddc44ae98e187746523bc1714f377956fe7586ef..65bc395ba0b8b20d48926ed1db77b80658ce9783 100644 (file)
@@ -82,7 +82,7 @@ public:
     declare( suffix, "supermaster-query", "", "select account from supermasters where ip='%s' and nameserver='%s'");
     declare( suffix, "supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%s'");
 
-    declare( suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE','%s')");
+    declare( suffix, "insert-zone-query", "", "insert into domains (type,name,account) values('NATIVE','%s','%s')");
     declare( suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
 
     declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s',%d)");
@@ -102,6 +102,7 @@ public:
 
     declare( suffix, "update-master-query", "", "update domains set master='%s' where name='%s'");
     declare( suffix, "update-kind-query", "", "update domains set type='%s' where name='%s'");
+    declare( suffix, "update-account-query","", "update domains set account='%s' where name='%s'");
     declare( suffix, "update-serial-query", "", "update domains set notified_serial=%d where id=%d");
     declare( suffix, "update-lastcheck-query", "", "update domains set last_check=%d where id=%d");
     declare (suffix, "zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
index b48e9d163b75a1977303ac591125332a139f0bb7..74435418d7bfeff240f921c477cab300884e86eb 100644 (file)
@@ -127,6 +127,19 @@ bool GSQLBackend::setKind(const string &domain, const DomainInfo::DomainKind kin
   return true;
 }
 
+bool GSQLBackend::setAccount(const string &domain, const string &account)
+{
+  string query = (GSQLformat(d_UpdateAccountOfZoneQuery) % sqlEscape(account) % sqlEscape(toLower(domain))).str();
+
+  try {
+    d_db->doCommand(query);
+  }
+  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:
@@ -293,6 +306,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
   d_InsertEntQuery=getArg("insert-ent-query");
   d_UpdateMasterOfZoneQuery=getArg("update-master-query");
   d_UpdateKindOfZoneQuery=getArg("update-kind-query");
+  d_UpdateAccountOfZoneQuery=getArg("update-account-query");
   d_UpdateSerialOfZoneQuery=getArg("update-serial-query");
   d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
   d_ZoneLastChangeQuery=getArg("zone-lastchange-query");
index e8acf757d1493caab25186a5add1ee529c175508..246ce51001e418a4ccfab6e22a853390f763d76b 100644 (file)
@@ -52,6 +52,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);
@@ -116,6 +117,7 @@ private:
   string d_InsertEntOrderQuery;
   string d_UpdateMasterOfZoneQuery;
   string d_UpdateKindOfZoneQuery;
+  string d_UpdateAccountOfZoneQuery;
   string d_UpdateSerialOfZoneQuery;
   string d_UpdateLastCheckofZoneQuery;
   string d_InfoOfAllMasterDomainsQuery;
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 791b8a8e5631ce7a5110369e437b67c3a9e10b37..7346575392239363fee65a89bd8f35c69c961c8a 100644 (file)
@@ -498,6 +498,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 4198dd707e8bc81bb26c940ddafd54cfb236d16a..a440265c90a4ca416eb7cbaf10dc1b6ffde1d754 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 = [