From: Christian Hofstaedtler Date: Sat, 7 Feb 2015 14:20:42 +0000 (+0100) Subject: API: allow writing to domains.account field X-Git-Tag: auth-3.4.3~1^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=102602f341042a78a29046dc9eae77770e8ca72a;p=pdns API: allow writing to domains.account field --- diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index 49a1958aa..0c41f23fa 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -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"); diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index a488625ae..549d988fc 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -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"); diff --git a/modules/gsqlite3backend/gsqlite3backend.cc b/modules/gsqlite3backend/gsqlite3backend.cc index ddc44ae98..65bc395ba 100644 --- a/modules/gsqlite3backend/gsqlite3backend.cc +++ b/modules/gsqlite3backend/gsqlite3backend.cc @@ -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"); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index b48e9d163..74435418d 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -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"); diff --git a/pdns/backends/gsql/gsqlbackend.hh b/pdns/backends/gsql/gsqlbackend.hh index e8acf757d..246ce5100 100644 --- a/pdns/backends/gsql/gsqlbackend.hh +++ b/pdns/backends/gsql/gsqlbackend.hh @@ -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; diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index c07a27b05..b4122b96e 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -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); diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 791b8a8e5..734657539 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -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) { diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 4198dd707..a440265c9 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -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 = [