From: Christian Hofstaedtler Date: Fri, 31 Jan 2014 17:23:00 +0000 (+0100) Subject: Implement "disabled" records for GSQL backends X-Git-Tag: rec-3.6.0-rc1~210^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cea2635091b7e39891187d52e38cb464bc71283b;p=pdns Implement "disabled" records for GSQL backends --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 003ce9d76..eb8fbe98a 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -290,7 +290,7 @@ void Bind2Backend::getUpdatedMasters(vector *changedDomains) } } -void Bind2Backend::getAllDomains(vector *domains) { +void Bind2Backend::getAllDomains(vector *domains, bool include_disabled) { SOAData soadata; shared_ptr state = getState(); @@ -1215,7 +1215,7 @@ bool Bind2Backend::handle::get_normal(DNSResourceRecord &r) return true; } -bool Bind2Backend::list(const string &target, int id) +bool Bind2Backend::list(const string &target, int id, bool include_disabled) { shared_ptr state = s_state; if(!state->id_zone_map.count(id)) diff --git a/modules/bindbackend/bindbackend2.hh b/modules/bindbackend/bindbackend2.hh index 31853be34..0c7eba68f 100644 --- a/modules/bindbackend/bindbackend2.hh +++ b/modules/bindbackend/bindbackend2.hh @@ -134,9 +134,9 @@ public: // DNSSEC virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after); void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1); - bool list(const string &target, int id); + bool list(const string &target, int id, bool include_disabled=false); bool get(DNSResourceRecord &); - void getAllDomains(vector *domains); + void getAllDomains(vector *domains, bool include_disabled=false); static DNSBackend *maker(); static pthread_mutex_t s_startup_lock; diff --git a/modules/geobackend/geobackend.cc b/modules/geobackend/geobackend.cc index 08bd27d2c..c3d27b2ed 100644 --- a/modules/geobackend/geobackend.cc +++ b/modules/geobackend/geobackend.cc @@ -118,7 +118,7 @@ void GeoBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket *pk i_answers = answers.begin(); } -bool GeoBackend::list(const string &target, int domain_id) { +bool GeoBackend::list(const string &target, int domain_id, bool include_disabled) { answers.clear(); queueNSRecords(zoneName); answerLocalhostRecord("localhost."+zoneName, NULL); diff --git a/modules/geobackend/geobackend.hh b/modules/geobackend/geobackend.hh index 4170f8bde..5509982cb 100644 --- a/modules/geobackend/geobackend.hh +++ b/modules/geobackend/geobackend.hh @@ -34,7 +34,7 @@ public: ~GeoBackend(); virtual void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1); - virtual bool list(const string &target, int domain_id); + virtual bool list(const string &target, int domain_id, bool include_disabled=false); virtual bool get(DNSResourceRecord &r); virtual bool getSOA(const string &name, SOAData &soadata, DNSPacket *p=0); diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index 30b129279..f96adffb9 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -50,41 +50,41 @@ public: declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no"); - string record_query = "SELECT content,ttl,prio,type,domain_id,name FROM records WHERE 1"; - string record_auth_query = "SELECT content,ttl,prio,type,domain_id,name,auth FROM records WHERE 1"; + string record_query = "SELECT content,ttl,prio,type,domain_id,disabled,name FROM records WHERE"; + string record_auth_query = "SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE"; - declare(suffix, "basic-query", "Basic query", record_query+" and type='%s' and name='%s'"); - declare(suffix, "id-query", "Basic with ID query", record_query+" and type='%s' and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-query", "Wildcard query", record_query+" and type='%s' and name like '%s'"); - declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" and type='%s' and name like '%s' and domain_id='%d'"); + declare(suffix, "basic-query", "Basic query", record_query+" disabled=0 and type='%s' and name='%s'"); + declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-query", "Wildcard query", record_query+" disabled=0 and type='%s' and name like '%s'"); + declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'"); - declare(suffix, "any-query", "Any query", record_query+" and name='%s'"); - declare(suffix, "any-id-query", "Any with ID query", record_query+" and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" and name like '%s'"); - declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" and name like '%s' and domain_id='%d'"); + declare(suffix, "any-query", "Any query", record_query+" disabled=0 and name='%s'"); + declare(suffix, "any-id-query", "Any with ID query", record_query+" disabled=0 and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" disabled=0 and name like '%s'"); + declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=0 and name like '%s' and domain_id='%d'"); - declare(suffix, "list-query", "AXFR query", record_query+" and domain_id='%d'"); - declare(suffix, "list-subzone-query", "Subzone listing", record_query+" and (name='%s' OR name like '%s') and domain_id='%d'"); + declare(suffix, "list-query", "AXFR query", record_query+" (disabled=0 OR %d) and domain_id='%d'"); + declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id='%d'"); declare(suffix,"remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null"); - declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type) values ('%d','%s',null)"); + declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled) values ('%d','%s',null,0)"); declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null"); // and now with auth - declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" and type='%s' and name='%s'"); - declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" and type='%s' and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" and type='%s' and name like '%s'"); - declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" and type='%s' and name like '%s' and domain_id='%d'"); + declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" disabled=0 and type='%s' and name='%s'"); + declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" disabled=0 and type='%s' and name like '%s'"); + declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'"); - declare(suffix, "any-query-auth", "Any query", record_auth_query+" and name='%s'"); - declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" and name like '%s'"); - declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" and name like '%s' and domain_id='%d'"); + declare(suffix, "any-query-auth", "Any query", record_auth_query+" disabled=0 and name='%s'"); + declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" disabled=0 and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" disabled=0 and name like '%s'"); + declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" disabled=0 and name like '%s' and domain_id='%d'"); - declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" and domain_id='%d' order by name, type"); - declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" and (name='%s' OR name like '%s') and domain_id='%d'"); + declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" (disabled=0 OR %d) and domain_id='%d' order by name, type"); + declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id='%d'"); - declare(suffix,"insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,auth) values ('%d','%s',null,'1')"); + declare(suffix, "insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,0,'1')"); declare(suffix,"master-zone-query","Data", "select master from domains where name='%s' and type='SLAVE'"); @@ -97,22 +97,22 @@ public: declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE','%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,name) values ('%s',%d,%d,'%s',%d,'%s')"); - declare(suffix,"insert-record-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,auth) values ('%s',%d,%d,'%s',%d,'%s','%d')"); - declare(suffix,"insert-record-order-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,ordername,auth) values ('%s',%d,%d,'%s',%d,'%s','%s','%d')"); - declare(suffix,"insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,name) values (null,'%d','%s')"); - declare(suffix,"insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,auth) values (null,'%d','%s','1')"); - declare(suffix,"insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,ordername,auth) values (null,'%d','%s','%s','1')"); + declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name) values ('%s',%d,%d,'%s',%d,%d,'%s')"); + declare(suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s','%d')"); + declare(suffix, "insert-record-order-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values ('%s',%d,%d,'%s',%d,%d,'%s','%s','%d')"); + declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name) values (null,'%d',0,'%s')"); + declare(suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',0,'%s','1')"); + declare(suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',0,'%s','%s','1')"); - declare(suffix,"get-order-first-query","DNSSEC Ordering Query, first", "select ordername, name from records where domain_id=%d and ordername is not null order by 1 asc limit 1"); - declare(suffix,"get-order-before-query","DNSSEC Ordering Query, before", "select ordername, name from records where ordername <= '%s' and domain_id=%d and ordername is not null order by 1 desc limit 1"); - declare(suffix,"get-order-after-query","DNSSEC Ordering Query, after", "select min(ordername) from records where ordername > '%s' and domain_id=%d and ordername is not null"); - declare(suffix,"get-order-last-query","DNSSEC Ordering Query, last", "select ordername, name from records where ordername != '' and domain_id=%d and ordername is not null order by 1 desc limit 1"); - declare(suffix,"set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s',auth=%d where name='%s' and domain_id='%d'"); - declare(suffix,"set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS'"); + declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, first", "select ordername, name from records where domain_id=%d and disabled=0 and ordername is not null order by 1 asc limit 1"); + declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select ordername, name from records where ordername <= '%s' and domain_id=%d and disabled=0 and ordername is not null order by 1 desc limit 1"); + declare(suffix, "get-order-after-query", "DNSSEC Ordering Query, after", "select min(ordername) from records where ordername > '%s' and domain_id=%d and disabled=0 and ordername is not null"); + declare(suffix, "get-order-last-query", "DNSSEC Ordering Query, last", "select ordername, name from records where ordername != '' and domain_id=%d and disabled=0 and ordername is not null order by 1 desc limit 1"); + declare(suffix, "set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s',auth=%d where name='%s' and domain_id='%d' and disabled=0"); + declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS' and disabled=0"); - declare(suffix,"nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s'"); - declare(suffix,"nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d'"); + declare(suffix, "nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s' and disabled=0"); + declare(suffix, "nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d' and disabled=0"); 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'"); @@ -140,7 +140,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'"); + 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)"); } DNSBackend *make(const string &suffix="") diff --git a/modules/gmysqlbackend/no-dnssec.schema.mysql.sql b/modules/gmysqlbackend/no-dnssec.schema.mysql.sql index d2ed72cdc..c58283c24 100644 --- a/modules/gmysqlbackend/no-dnssec.schema.mysql.sql +++ b/modules/gmysqlbackend/no-dnssec.schema.mysql.sql @@ -20,6 +20,7 @@ CREATE TABLE records ( ttl INT DEFAULT NULL, prio INT DEFAULT NULL, change_date INT DEFAULT NULL, + disabled INT DEFAULT NULL, primary key(id) ) Engine=InnoDB; diff --git a/modules/goraclebackend/goracle-schema.sql b/modules/goraclebackend/goracle-schema.sql index 981cb84a4..31796f300 100644 --- a/modules/goraclebackend/goracle-schema.sql +++ b/modules/goraclebackend/goracle-schema.sql @@ -22,6 +22,7 @@ CREATE TABLE records ( ttl INT DEFAULT NULL, prio INT DEFAULT NULL, change_date INT DEFAULT NULL, + disabled INT DEFAULT NULL, ordername VARCHAR(255) DEFAULT NULL, auth INT DEFAULT NULL, primary key (id) diff --git a/modules/goraclebackend/goraclebackend.cc b/modules/goraclebackend/goraclebackend.cc index bb99d53f4..d7c8c2c55 100644 --- a/modules/goraclebackend/goraclebackend.cc +++ b/modules/goraclebackend/goraclebackend.cc @@ -57,41 +57,41 @@ public: declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no"); - string record_query = "SELECT content,ttl,prio,type,domain_id,name FROM records WHERE 1"; - string record_auth_query = "SELECT content,ttl,prio,type,domain_id,name,auth FROM records WHERE 1"; + string record_query = "SELECT content,ttl,prio,type,domain_id,name FROM records WHERE"; + string record_auth_query = "SELECT content,ttl,prio,type,domain_id,name,auth FROM records WHERE"; - declare(suffix, "basic-query", "Basic query", record_query+" and type='%s' and name='%s'"); - declare(suffix, "id-query", "Basic with ID query", record_query+" and type='%s' and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-query", "Wildcard query", record_query+" and type='%s' and name like '%s'"); - declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" and type='%s' and name like '%s' and domain_id='%d'"); + declare(suffix, "basic-query", "Basic query", record_query+" disabled=0 and type='%s' and name='%s'"); + declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-query", "Wildcard query", record_query+" disabled=0 and type='%s' and name like '%s'"); + declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'"); - declare(suffix, "any-query", "Any query", record_query+" and name='%s'"); - declare(suffix, "any-id-query", "Any with ID query", record_query+" and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" and name like '%s'"); - declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" and name like '%s' and domain_id='%d'"); + declare(suffix, "any-query", "Any query", record_query+" disabled=0 and name='%s'"); + declare(suffix, "any-id-query", "Any with ID query", record_query+" disabled=0 and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" disabled=0 and name like '%s'"); + declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=0 and name like '%s' and domain_id='%d'"); - declare(suffix, "list-query", "AXFR query", record_query+" and domain_id='%d'"); - declare(suffix, "list-subzone-query", "Subzone listing", record_query+" and (name='%s' OR name like '%s') and domain_id='%d'"); + declare(suffix, "list-query", "AXFR query", record_query+" (disabled=0 OR %d) and domain_id='%d'"); + declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id='%d'"); declare(suffix,"remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null"); - declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (id,domain_id,name,type) values (records_id_sequence.nextval,'%d','%s',null)"); + declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (id,domain_id,name,type,disabled) values (records_id_sequence.nextval,'%d','%s',null,0)"); declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null"); // and now with auth - declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" and type='%s' and name='%s'"); - declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" and type='%s' and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" and type='%s' and name like '%s'"); - declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" and type='%s' and name like '%s' and domain_id='%d'"); + declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" disabled=0 and type='%s' and name='%s'"); + declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" disabled=0 and type='%s' and name like '%s'"); + declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'"); - declare(suffix, "any-query-auth", "Any query", record_auth_query+" and name='%s'"); - declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" and name like '%s'"); - declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" and name like '%s' and domain_id='%d'"); + declare(suffix, "any-query-auth", "Any query", record_auth_query+" disabled=0 and name='%s'"); + declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" disabled=0 and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" disabled=0 and name like '%s'"); + declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" disabled=0 and name like '%s' and domain_id='%d'"); - declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" and domain_id='%d' order by name, type"); - declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" and (name='%s' OR name like '%s') and domain_id='%d'"); + declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" (disabled=0 OR %d) and domain_id='%d' order by name, type"); + declare(suffix, "list-subzone-query-auth", "Subzone listing", record_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id='%d'"); - declare(suffix,"insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (id,domain_id,name,type,auth) values (records_id_sequence.nextval,'%d','%s',null,'1')"); + declare(suffix, "insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (id,domain_id,name,type,disabled,auth) values (records_id_sequence.nextval,'%d','%s',null,0,'1')"); declare(suffix,"master-zone-query","Data", "select master from domains where name='%s' and type='SLAVE'"); @@ -103,22 +103,22 @@ public: declare(suffix,"insert-zone-query","", "insert into domains (id, type, name) values(domain_id_sequence.nextval, 'NATIVE','%s')"); declare(suffix,"insert-slave-query","", "insert into domains (id, type,name,master,account) values(domain_id_sequence.nextval, 'SLAVE','%s','%s','%s')"); - declare(suffix,"insert-record-query","", "insert into records (id, content,ttl,prio,type,domain_id,name) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,'%s')"); - declare(suffix,"insert-record-query-auth","", "insert into records (id, content,ttl,prio,type,domain_id,name,auth) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,'%s','%d')"); - declare(suffix,"insert-record-order-query-auth","", "insert into records (id, content,ttl,prio,type,domain_id,name,ordername,auth) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,'%s','%s ','%d')"); - declare(suffix,"insert-ent-query", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,name) values (records_id_sequence.nextval, null,'%d','%s')"); - declare(suffix,"insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,name,auth) values (records_id_sequence.nextval, null,'%d','%s','1')"); - declare(suffix,"insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,name,ordername,auth) values (records_id_sequence.nextval, null,'%d','%s','%s','1')"); + declare(suffix, "insert-record-query", "", "insert into records (id, content,ttl,prio,type,domain_id,disabled,name) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,%d,'%s')"); + declare(suffix, "insert-record-query-auth", "", "insert into records (id, content,ttl,prio,type,domain_id,disabled,name,auth) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,%d,'%s','%d')"); + declare(suffix, "insert-record-order-query-auth", "", "insert into records (id, content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,%d,'%s','%s ','%d')"); + declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,disabled,name) values (records_id_sequence.nextval, null,'%d',0,'%s')"); + declare(suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,disabled,name,auth) values (records_id_sequence.nextval, null,'%d',0,'%s','1')"); + declare(suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,disabled,name,ordername,auth) values (records_id_sequence.nextval, null,'%d',0,'%s','%s','1')"); - declare(suffix,"get-order-first-query","DNSSEC Ordering Query, first", "select trim(ordername),name from records where domain_id=%d and ordername is not null and rownum=1 order by ordername asc"); - declare(suffix,"get-order-before-query","DNSSEC Ordering Query, before", "select trim(ordername), name from records where ordername <= '%s ' and domain_id=%d and ordername is not null and rownum=1 order by ordername desc"); - declare(suffix,"get-order-after-query","DNSSEC Ordering Query, after", "select trim(min(ordername)) from records where ordername > '%s ' and domain_id=%d and ordername is not null"); - declare(suffix,"get-order-last-query","DNSSEC Ordering Query, last", "select trim(ordername), name from records where ordername != ' ' and domain_id=%d and ordername is not null and rownum=1 order by ordername desc"); - declare(suffix,"set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s ',auth=%d where name='%s' and domain_id='%d'"); - declare(suffix,"set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS'"); + declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, first", "select trim(ordername),name from records where disabled=0 and domain_id=%d and ordername is not null and rownum=1 order by ordername asc"); + declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select trim(ordername), name from records where disabled=0 and ordername <= '%s ' and domain_id=%d and ordername is not null and rownum=1 order by ordername desc"); + declare(suffix, "get-order-after-query", "DNSSEC Ordering Query, after", "select trim(min(ordername)) from records where disabled=0 and ordername > '%s ' and domain_id=%d and ordername is not null"); + declare(suffix, "get-order-last-query", "DNSSEC Ordering Query, last", "select trim(ordername), name from records where disabled=0 and ordername != ' ' and domain_id=%d and ordername is not null and rownum=1 order by ordername desc"); + declare(suffix, "set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s ',auth=%d where name='%s' and domain_id='%d' and disabled=0"); + declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS' and disabled=0"); - declare(suffix,"nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s'"); - declare(suffix,"nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d'"); + declare(suffix, "nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s' and disabled=0"); + declare(suffix, "nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d' and disabled=0"); 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'"); @@ -146,7 +146,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'"); + 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)"); } DNSBackend* make(const string &suffix="") { diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index 5f389a05e..7f20221e1 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -46,41 +46,41 @@ public: declare(suffix,"dnssec","Assume DNSSEC Schema is in place","no"); - string record_query = "SELECT content,ttl,prio,type,domain_id,name FROM records WHERE 1"; - string record_auth_query = "SELECT content,ttl,prio,type,domain_id,name,auth::int FROM records WHERE 1"; + string record_query = "SELECT content,ttl,prio,type,domain_id,disabled::int,name FROM records WHERE"; + string record_auth_query = "SELECT content,ttl,prio,type,domain_id,disabled::int,name,auth::int FROM records WHERE"; - declare(suffix, "basic-query", "Basic query", record_query+" and type='%s' and name=E'%s'"); - declare(suffix, "id-query", "Basic with ID query", record_query+" and type='%s' and name=E'%s' and domain_id=%d"); - declare(suffix, "wildcard-query", "Wildcard query", record_query+" and type='%s' and name like E'%s'"); - declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" and type='%s' and name like E'%s' and domain_id='%d'"); + declare(suffix, "basic-query", "Basic query", record_query+" disabled=false and type='%s' and name=E'%s'"); + declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=false and type='%s' and name=E'%s' and domain_id=%d"); + declare(suffix, "wildcard-query", "Wildcard query", record_query+" disabled=false and type='%s' and name like E'%s'"); + declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" disabled=false and type='%s' and name like E'%s' and domain_id='%d'"); - declare(suffix, "any-query", "Any query", record_query+" and name=E'%s'"); - declare(suffix, "any-id-query", "Any with ID query", record_query+" and name=E'%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" and name like E'%s'"); - declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" and name like E'%s' and domain_id='%d'"); + declare(suffix, "any-query", "Any query", record_query+" disabled=false and name=E'%s'"); + declare(suffix, "any-id-query", "Any with ID query", record_query+" disabled=false and name=E'%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" disabled=false and name like E'%s'"); + declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=false and name like E'%s' and domain_id='%d'"); - declare(suffix, "list-query", "AXFR query", record_query+" and domain_id='%d'"); - declare(suffix, "list-subzone-query", "Subzone listing", record_query+" and (name=E'%s' OR name like E'%s') and domain_id='%d'"); + declare(suffix, "list-query", "AXFR query", record_query+" (disabled=false OR %d::bool) and domain_id='%d'"); + declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=false and (name=E'%s' OR name like E'%s') and domain_id='%d'"); declare(suffix,"remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null"); - declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type) values ('%d','%s',null)"); + declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled) values ('%d','%s',null,false)"); declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null"); // and now with auth - declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" and type='%s' and name=E'%s'"); - declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" and type='%s' and name=E'%s' and domain_id=%d"); - declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" and type='%s' and name like E'%s'"); - declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" and type='%s' and name like E'%s' and domain_id='%d'"); + declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" disabled=false and type='%s' and name=E'%s'"); + declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" disabled=false and type='%s' and name=E'%s' and domain_id=%d"); + declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" disabled=false and type='%s' and name like E'%s'"); + declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" disabled=false and type='%s' and name like E'%s' and domain_id='%d'"); - declare(suffix, "any-query-auth", "Any query", record_auth_query+" and name=E'%s'"); - declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" and name=E'%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" and name like E'%s'"); - declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" and name like E'%s' and domain_id='%d'"); + declare(suffix, "any-query-auth", "Any query", record_auth_query+" disabled=false and name=E'%s'"); + declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" disabled=false and name=E'%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" disabled=false and name like E'%s'"); + declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" disabled=false and name like E'%s' and domain_id='%d'"); - declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" and domain_id='%d' order by name, type"); - declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" and (name=E'%s' OR name like E'%s') and domain_id='%d'"); + declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" (disabled=false OR %d::bool) and domain_id='%d' order by name, type"); + declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" disabled=false and (name=E'%s' OR name like E'%s') and domain_id='%d'"); - declare(suffix,"insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,auth) values ('%d','%s',null,true)"); + declare(suffix, "insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,false,true)"); declare(suffix,"master-zone-query","Data", "select master from domains where name=E'%s' and type='SLAVE'"); @@ -92,22 +92,22 @@ public: declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',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,name) values (E'%s',%d,%d,'%s',%d,E'%s')"); - declare(suffix,"insert-record-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,auth) values (E'%s',%d,%d,'%s',%d,E'%s','%d')"); - declare(suffix,"insert-record-order-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,ordername,auth) values (E'%s',%d,%d,'%s',%d,E'%s',E'%s','%d')"); - declare(suffix,"insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,name) values (null,'%d',E'%s')"); - declare(suffix,"insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,auth) values (null,'%d',E'%s',true)"); - declare(suffix,"insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,ordername,auth) values (null,'%d',E'%s',E'%s',true)"); + declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s')"); + declare(suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s','%d')"); + declare(suffix, "insert-record-order-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s',E'%s','%d')"); + declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name) values (null,'%d',false,E'%s')"); + declare(suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',false,E'%s',true)"); + declare(suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',false,E'%s',E'%s',true)"); - declare(suffix,"get-order-first-query","DNSSEC Ordering Query, last", "select ordername, name from records where domain_id=%d and ordername is not null order by 1 using ~<~ limit 1"); - declare(suffix,"get-order-before-query","DNSSEC Ordering Query, before", "select ordername, name from records where ordername ~<=~ E'%s' and domain_id=%d and ordername is not null order by 1 using ~>~ limit 1"); - declare(suffix,"get-order-after-query","DNSSEC Ordering Query, after", "select ordername from records where ordername ~>~ E'%s' and domain_id=%d and ordername is not null order by 1 using ~<~ limit 1"); - declare(suffix,"get-order-last-query","DNSSEC Ordering Query, last", "select ordername, name from records where ordername != '' and domain_id=%d and ordername is not null order by 1 using ~>~ limit 1"); - declare(suffix,"set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername=E'%s',auth=%d::bool where name=E'%s' and domain_id='%d'"); - declare(suffix,"set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=true where domain_id='%d' and name='%s' and type='DS'"); + declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, last", "select ordername, name from records where disabled=false and domain_id=%d and ordername is not null order by 1 using ~<~ limit 1"); + declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select ordername, name from records where disabled=false and ordername ~<=~ E'%s' and domain_id=%d and ordername is not null order by 1 using ~>~ limit 1"); + declare(suffix, "get-order-after-query", "DNSSEC Ordering Query, after", "select ordername from records where disabled=false and ordername ~>~ E'%s' and domain_id=%d and ordername is not null order by 1 using ~<~ limit 1"); + declare(suffix, "get-order-last-query", "DNSSEC Ordering Query, last", "select ordername, name from records where disabled=false and ordername != '' and domain_id=%d and ordername is not null order by 1 using ~>~ limit 1"); + declare(suffix, "set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername=E'%s',auth=%d::bool where name=E'%s' and domain_id='%d' and disabled=false"); + declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=true where domain_id='%d' and name='%s' and type='DS' and disabled=false"); - declare(suffix,"nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d::bool where domain_id='%d' and name='%s'"); - declare(suffix,"nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=false where name=E'%s' and type=E'%s' and domain_id='%d'"); + declare(suffix, "nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d::bool where domain_id='%d' and name='%s' and disabled=false"); + declare(suffix, "nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=false where name=E'%s' and type=E'%s' and domain_id='%d' and disabled=false"); 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'"); @@ -135,7 +135,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'"); + 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)"); } DNSBackend *make(const string &suffix="") diff --git a/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql b/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql index c48e1d769..53d9ec56a 100644 --- a/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql +++ b/modules/gpgsqlbackend/no-dnssec.schema.pgsql.sql @@ -19,6 +19,7 @@ CREATE TABLE records ( ttl INT DEFAULT NULL, prio INT DEFAULT NULL, change_date INT DEFAULT NULL, + disabled BOOL DEFAULT NULL, CONSTRAINT domain_exists FOREIGN KEY(domain_id) REFERENCES domains(id) ON DELETE CASCADE, diff --git a/modules/gsqlite3backend/gsqlite3backend.cc b/modules/gsqlite3backend/gsqlite3backend.cc index f1de2080b..0c3336b81 100644 --- a/modules/gsqlite3backend/gsqlite3backend.cc +++ b/modules/gsqlite3backend/gsqlite3backend.cc @@ -58,51 +58,51 @@ public: declare( suffix, "database", "Filename of the SQLite3 database", "powerdns.sqlite" ); declare( suffix, "pragma-synchronous", "Set this to 0 for blazing speed", "" ); - string record_query = "SELECT content,ttl,prio,type,domain_id,name FROM records WHERE 1"; - string record_auth_query = "SELECT content,ttl,prio,type,domain_id,name,auth FROM records WHERE 1"; + string record_query = "SELECT content,ttl,prio,type,domain_id,disabled,name FROM records WHERE"; + string record_auth_query = "SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE"; - declare(suffix, "basic-query", "Basic query", record_query+" and type='%s' and name='%s'"); - declare(suffix, "id-query", "Basic with ID query", record_query+" and type='%s' and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-query", "Wildcard query", record_query+" and type='%s' and name like '%s'"); - declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" and type='%s' and name like '%s' and domain_id=%d"); + declare(suffix, "basic-query", "Basic query", record_query+" disabled=0 and type='%s' and name='%s'"); + declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-query", "Wildcard query", record_query+" disabled=0 and type='%s' and name like '%s'"); + declare(suffix, "wildcard-id-query", "Wildcard with ID query", record_query+" disabled=0 and type='%s' and name like '%s' and domain_id=%d"); - declare(suffix, "any-query", "Any query", record_query+" and name='%s'"); - declare(suffix, "any-id-query", "Any with ID query", record_query+" and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" and name like '%s'"); - declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" and name like '%s' and domain_id=%d"); + declare(suffix, "any-query", "Any query", record_query+" disabled=0 and name='%s'"); + declare(suffix, "any-id-query", "Any with ID query", record_query+" disabled=0 and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query", "Wildcard ANY query", record_query+" disabled=0 and name like '%s'"); + declare(suffix, "wildcard-any-id-query", "Wildcard ANY with ID query", record_query+" disabled=0 and name like '%s' and domain_id=%d"); - declare(suffix, "list-query", "AXFR query", record_query+" and domain_id=%d"); - declare(suffix, "list-subzone-query", "Subzone listing", record_query+" and (name='%s' OR name like '%s') and domain_id=%d"); + declare(suffix, "list-query", "AXFR query", record_query+" (disabled=0 OR %d) and domain_id=%d"); + declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id=%d"); declare(suffix,"remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null"); - declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type) values ('%d','%s',null)"); + declare(suffix,"insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled) values ('%d','%s',null,0)"); declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null"); // and now with auth - declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" and type='%s' and name='%s'"); - declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" and type='%s' and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" and type='%s' and name like '%s'"); - declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" and type='%s' and name like '%s' and domain_id='%d'"); + declare(suffix, "basic-query-auth", "Basic query", record_auth_query+" disabled=0 and type='%s' and name='%s'"); + declare(suffix, "id-query-auth", "Basic with ID query", record_auth_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-query-auth", "Wildcard query", record_auth_query+" disabled=0 and type='%s' and name like '%s'"); + declare(suffix, "wildcard-id-query-auth", "Wildcard with ID query", record_auth_query+" disabled=0 and type='%s' and name like '%s' and domain_id='%d'"); - declare(suffix, "any-query-auth", "Any query", record_auth_query+" and name='%s'"); - declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" and name='%s' and domain_id=%d"); - declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" and name like '%s'"); - declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" and name like '%s' and domain_id='%d'"); + declare(suffix, "any-query-auth", "Any query", record_auth_query+" disabled=0 and name='%s'"); + declare(suffix, "any-id-query-auth", "Any with ID query", record_auth_query+" disabled=0 and name='%s' and domain_id=%d"); + declare(suffix, "wildcard-any-query-auth", "Wildcard ANY query", record_auth_query+" disabled=0 and name like '%s'"); + declare(suffix, "wildcard-any-id-query-auth", "Wildcard ANY with ID query", record_auth_query+" disabled=0 and name like '%s' and domain_id='%d'"); - declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" and domain_id='%d' order by name, type"); - declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" and (name='%s' OR name like '%s') and domain_id=%d"); + declare(suffix, "list-query-auth", "AXFR query", record_auth_query+" (disabled=0 OR %d) and domain_id='%d' order by name, type"); + declare(suffix, "list-subzone-query-auth", "Subzone listing", record_auth_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id=%d"); - declare(suffix,"insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,auth) values ('%d','%s',null,'1')"); + declare(suffix, "insert-empty-non-terminal-query-auth", "insert empty non-terminal in zone", "insert into records (domain_id,name,type,disabled,auth) values ('%d','%s',null,0,'1')"); - declare(suffix,"get-order-first-query","DNSSEC Ordering Query, first", "select ordername, name from records where domain_id=%d and ordername is not null order by 1 asc limit 1"); - declare(suffix,"get-order-before-query","DNSSEC Ordering Query, before", "select ordername, name from records where ordername <= '%s' and domain_id=%d and ordername is not null order by 1 desc limit 1"); - declare(suffix,"get-order-after-query","DNSSEC Ordering Query, after", "select min(ordername) from records where ordername > '%s' and domain_id=%d and ordername is not null"); - declare(suffix,"get-order-last-query","DNSSEC Ordering Query, last", "select ordername, name from records where ordername != '' and domain_id=%d and ordername is not null order by 1 desc limit 1"); - declare(suffix,"set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s',auth=%d where name='%s' and domain_id='%d'"); - - declare(suffix,"nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s'"); - declare(suffix,"nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d'"); - declare(suffix,"set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS'"); + declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, first", "select ordername, name from records where disabled=0 and domain_id=%d and ordername is not null order by 1 asc limit 1"); + declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select ordername, name from records where disabled=0 and ordername <= '%s' and domain_id=%d and ordername is not null order by 1 desc limit 1"); + declare(suffix, "get-order-after-query", "DNSSEC Ordering Query, after", "select min(ordername) from records where disabled=0 and ordername > '%s' and domain_id=%d and ordername is not null"); + declare(suffix, "get-order-last-query", "DNSSEC Ordering Query, last", "select ordername, name from records where disabled=0 and ordername != '' and domain_id=%d and ordername is not null order by 1 desc limit 1"); + declare(suffix, "set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s',auth=%d where name='%s' and domain_id='%d' and disabled=0"); + + declare(suffix, "nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s' and disabled=0"); + declare(suffix, "nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d' and disabled=0"); + declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS' and disabled=0"); declare( suffix, "master-zone-query", "Data", "select master from domains where name='%s' and type='SLAVE'"); @@ -114,12 +114,12 @@ public: declare( suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE','%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,name) values ('%s',%d,%d,'%s',%d,'%s')"); - declare( suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,name,auth) values ('%s',%d,%d,'%s',%d,'%s',%d)"); - declare( suffix, "insert-record-order-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,ordername,auth) values ('%s',%d,%d,'%s',%d,'%s','%s','%d')"); - declare( suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,name) values (null,'%d','%s')"); - declare( suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,auth) values (null,'%d','%s','1')"); - declare( suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,ordername,auth) values (null,'%d','%s','%s','1')"); + declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name) values ('%s',%d,%d,'%s',%d,%d,'%s')"); + declare(suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s',%d)"); + declare(suffix, "insert-record-order-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values ('%s',%d,%d,%d,'%s','%s',%d,'%s','%d')"); + declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name) values (null,'%d',0,'%s')"); + declare(suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',0,'%s','1')"); + declare(suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,ordername,auth) values (null,'%d',0,'%s','%s','1')"); 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'"); @@ -148,7 +148,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'"); + 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)"); } //! Constructs a new gSQLite3Backend object. diff --git a/modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql b/modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql index a6f13b966..81aed15bc 100644 --- a/modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql +++ b/modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql @@ -18,7 +18,8 @@ CREATE TABLE records ( content VARCHAR(65535) DEFAULT NULL, ttl INTEGER DEFAULT NULL, prio INTEGER DEFAULT NULL, - change_date INTEGER DEFAULT NULL + change_date INTEGER DEFAULT NULL, + disabled BOOLEAN DEFAULT NULL ); CREATE INDEX rec_name_index ON records(name); diff --git a/modules/luabackend/luabackend.hh b/modules/luabackend/luabackend.hh index 0e8654d55..5409ebee3 100644 --- a/modules/luabackend/luabackend.hh +++ b/modules/luabackend/luabackend.hh @@ -33,7 +33,7 @@ public: LUABackend(const string &suffix=""); ~LUABackend(); - bool list(const string &target, int domain_id); + bool list(const string &target, int domain_id, bool include_disabled=false); void lookup(const QType &qtype, const string &qname, DNSPacket *p, int domain_id); bool get(DNSResourceRecord &rr); //! fills the soadata struct with the SOA details. Returns false if there is no SOA. diff --git a/modules/luabackend/minimal.cc b/modules/luabackend/minimal.cc index 3229b3d93..3c7072331 100644 --- a/modules/luabackend/minimal.cc +++ b/modules/luabackend/minimal.cc @@ -58,7 +58,7 @@ LUABackend::~LUABackend() { lua_close(lua); } -bool LUABackend::list(const string &target, int domain_id) { +bool LUABackend::list(const string &target, int domain_id, bool include_disabled) { if (logging) L << Logger::Info << backend_name << "(list) BEGIN" << endl; diff --git a/modules/mydnsbackend/mydnsbackend.cc b/modules/mydnsbackend/mydnsbackend.cc index 12bb07984..e4e6d769e 100644 --- a/modules/mydnsbackend/mydnsbackend.cc +++ b/modules/mydnsbackend/mydnsbackend.cc @@ -81,7 +81,7 @@ void MyDNSBackend::Query(const string &query) { } } -bool MyDNSBackend::list(const string &target, int zoneId) { +bool MyDNSBackend::list(const string &target, int zoneId, bool include_disabled) { string query; string sname; SSql::row_t rrow; diff --git a/modules/mydnsbackend/mydnsbackend.hh b/modules/mydnsbackend/mydnsbackend.hh index 1d9f867d9..5caa80be9 100644 --- a/modules/mydnsbackend/mydnsbackend.hh +++ b/modules/mydnsbackend/mydnsbackend.hh @@ -15,7 +15,7 @@ public: ~MyDNSBackend(); void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1); - bool list(const string &target, int domain_id); + bool list(const string &target, int domain_id, bool include_disabled=false); bool get(DNSResourceRecord &r); bool getSOA(const string& name, SOAData& soadata, DNSPacket*); diff --git a/modules/opendbxbackend/odbxbackend.cc b/modules/opendbxbackend/odbxbackend.cc index 1361dd2d1..a098f9ff0 100644 --- a/modules/opendbxbackend/odbxbackend.cc +++ b/modules/opendbxbackend/odbxbackend.cc @@ -231,7 +231,7 @@ bool OdbxBackend::getSOA( const string& domain, SOAData& sd, DNSPacket* p ) -bool OdbxBackend::list( const string& target, int zoneid ) +bool OdbxBackend::list( const string& target, int zoneid, bool include_disabled ) { try { diff --git a/modules/opendbxbackend/odbxbackend.hh b/modules/opendbxbackend/odbxbackend.hh index bc9a29aa2..54d016d76 100644 --- a/modules/opendbxbackend/odbxbackend.hh +++ b/modules/opendbxbackend/odbxbackend.hh @@ -77,7 +77,7 @@ public: void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 ); bool getSOA( const string& domain, SOAData& sd, DNSPacket* p ); - bool list( const string& target, int domain_id ); + bool list( const string& target, int domain_id, bool include_disabled=false ); bool get( DNSResourceRecord& rr ); bool startTransaction( const string& domain, int domain_id ); diff --git a/modules/oraclebackend/oraclebackend.cc b/modules/oraclebackend/oraclebackend.cc index 524e725dd..f07eecc0b 100644 --- a/modules/oraclebackend/oraclebackend.cc +++ b/modules/oraclebackend/oraclebackend.cc @@ -931,7 +931,7 @@ OracleBackend::setNotified (uint32_t zoneId, uint32_t serial) } bool -OracleBackend::list (const string &domain, int zoneId) +OracleBackend::list (const string &domain, int zoneId, bool include_disabled) { sword rc; diff --git a/modules/pipebackend/pipebackend.cc b/modules/pipebackend/pipebackend.cc index 4b5ee77bb..00a14f621 100644 --- a/modules/pipebackend/pipebackend.cc +++ b/modules/pipebackend/pipebackend.cc @@ -146,7 +146,7 @@ void PipeBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt_ d_qname=qname; } -bool PipeBackend::list(const string &target, int inZoneId) +bool PipeBackend::list(const string &target, int inZoneId, bool include_disabled) { try { d_disavow=false; diff --git a/modules/pipebackend/pipebackend.hh b/modules/pipebackend/pipebackend.hh index 6123d2771..07bc3995c 100644 --- a/modules/pipebackend/pipebackend.hh +++ b/modules/pipebackend/pipebackend.hh @@ -37,7 +37,7 @@ public: PipeBackend(const string &suffix=""); ~PipeBackend(); void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1); - bool list(const string &target, int domain_id); + bool list(const string &target, int domain_id, bool include_disabled=false); bool get(DNSResourceRecord &r); static DNSBackend *maker(); diff --git a/modules/randombackend/randombackend.cc b/modules/randombackend/randombackend.cc index 43395673f..3dc25ff7a 100644 --- a/modules/randombackend/randombackend.cc +++ b/modules/randombackend/randombackend.cc @@ -38,7 +38,7 @@ public: d_ourname=getArg("hostname"); } - bool list(const string &target, int id) { + bool list(const string &target, int id, bool include_disabled) { return false; // we don't support AXFR } diff --git a/modules/remotebackend/remotebackend.cc b/modules/remotebackend/remotebackend.cc index 7a63d94b6..36cdc5b03 100644 --- a/modules/remotebackend/remotebackend.cc +++ b/modules/remotebackend/remotebackend.cc @@ -207,7 +207,7 @@ void RemoteBackend::lookup(const QType &qtype, const std::string &qdomain, DNSPa d_index = 0; } -bool RemoteBackend::list(const std::string &target, int domain_id) { +bool RemoteBackend::list(const std::string &target, int domain_id, bool include_disabled) { rapidjson::Document query; rapidjson::Value parameters; diff --git a/modules/remotebackend/remotebackend.hh b/modules/remotebackend/remotebackend.hh index b2ed52098..bcbd42908 100644 --- a/modules/remotebackend/remotebackend.hh +++ b/modules/remotebackend/remotebackend.hh @@ -130,7 +130,7 @@ class RemoteBackend : public DNSBackend void lookup(const QType &qtype, const std::string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1); bool get(DNSResourceRecord &rr); - bool list(const std::string &target, int domain_id); + bool list(const std::string &target, int domain_id, bool include_disabled=false); virtual bool getDomainMetadata(const std::string& name, const std::string& kind, std::vector& meta); virtual bool getDomainKeys(const std::string& name, unsigned int kind, std::vector& keys); diff --git a/modules/tinydnsbackend/tinydnsbackend.cc b/modules/tinydnsbackend/tinydnsbackend.cc index 34091386e..8d7274f8a 100644 --- a/modules/tinydnsbackend/tinydnsbackend.cc +++ b/modules/tinydnsbackend/tinydnsbackend.cc @@ -126,7 +126,7 @@ void TinyDNSBackend::setNotified(uint32_t id, uint32_t serial) { s_domainInfo[d_suffix] = *domains; } -void TinyDNSBackend::getAllDomains(vector *domains) { +void TinyDNSBackend::getAllDomains(vector *domains, bool include_disabled) { d_isAxfr=true; d_dnspacket = NULL; @@ -152,7 +152,7 @@ void TinyDNSBackend::getAllDomains(vector *domains) { } } -bool TinyDNSBackend::list(const string &target, int domain_id) { +bool TinyDNSBackend::list(const string &target, int domain_id, bool include_disabled) { d_isAxfr=true; string key = simpleCompress(target); d_cdbReader=new CDB(getArg("dbfile")); diff --git a/modules/tinydnsbackend/tinydnsbackend.hh b/modules/tinydnsbackend/tinydnsbackend.hh index 390c7f514..526b759fc 100644 --- a/modules/tinydnsbackend/tinydnsbackend.hh +++ b/modules/tinydnsbackend/tinydnsbackend.hh @@ -48,9 +48,9 @@ public: // Methods for simple operation TinyDNSBackend(const string &suffix); void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1); - bool list(const string &target, int domain_id); + bool list(const string &target, int domain_id, bool include_disabled=false); bool get(DNSResourceRecord &rr); - void getAllDomains(vector *domains); + void getAllDomains(vector *domains, bool include_disabled=false); //Master mode operation void getUpdatedMasters(vector* domains); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 8f8f816ca..8805e407d 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -838,11 +838,12 @@ void GSQLBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt_ d_qname=qname; } -bool GSQLBackend::list(const string &target, int domain_id ) +bool GSQLBackend::list(const string &target, int domain_id, bool include_disabled) { DLOG(L<<"GSQLBackend constructing handle for list of domain id '"< *domains) +void GSQLBackend::getAllDomains(vector *domains, bool include_disabled) { DLOG(L<<"GSQLBackend retrieving all domains."<doQuery(d_getAllDomainsQuery.c_str()); + d_db->doQuery(query); } catch (SSqlException &e) { throw PDNSException("Database error trying to retrieve all domains:" + e.txtReason()); @@ -1036,15 +1038,17 @@ bool GSQLBackend::get(DNSResourceRecord &r) if(!d_qname.empty()) r.qname=d_qname; else - r.qname=row[5]; + r.qname=row[6]; r.qtype=row[3]; r.last_modified=0; if(d_dnssecQueries) - r.auth = !row[6].empty() && row[6][0]=='1'; + r.auth = !row[7].empty() && row[7][0]=='1'; else r.auth = 1; - + + r.disabled = !row[5].empty() && row[5][0]=='1'; + r.domain_id=atoi(row[4].c_str()); return true; } @@ -1086,6 +1090,7 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord &r, string *ordername) % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id + % (int)r.disabled % toLower(sqlEscape(r.qname)) % sqlEscape(*ordername) % (int)r.auth @@ -1097,6 +1102,7 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord &r, string *ordername) % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id + % (int)r.disabled % toLower(sqlEscape(r.qname)) % (int)r.auth ).str(); @@ -1107,6 +1113,7 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord &r, string *ordername) % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id + % (int)r.disabled % toLower(sqlEscape(r.qname)) ).str(); } diff --git a/pdns/backends/gsql/gsqlbackend.hh b/pdns/backends/gsql/gsqlbackend.hh index efc417512..9049571c7 100644 --- a/pdns/backends/gsql/gsqlbackend.hh +++ b/pdns/backends/gsql/gsqlbackend.hh @@ -28,9 +28,9 @@ public: virtual string sqlEscape(const string &name); void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1); - bool list(const string &target, int domain_id); + bool list(const string &target, int domain_id, bool include_disabled=false); bool get(DNSResourceRecord &r); - void getAllDomains(vector *domains); + void getAllDomains(vector *domains, bool include_disabled=false); bool isMaster(const string &domain, const string &ip); void alsoNotifies(const string &domain, set *ips); bool startTransaction(const string &domain, int domain_id=-1); diff --git a/pdns/dns.hh b/pdns/dns.hh index 47ec216cc..f0099aa59 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -73,7 +73,7 @@ public: class DNSResourceRecord { public: - DNSResourceRecord() : qclass(1), priority(0), signttl(0), last_modified(0), d_place(ANSWER), auth(1), scopeMask(0) {}; + DNSResourceRecord() : qclass(1), priority(0), signttl(0), last_modified(0), d_place(ANSWER), auth(1), disabled(0), scopeMask(0) {}; DNSResourceRecord(const struct DNSRecord&); ~DNSResourceRecord(){}; @@ -96,6 +96,7 @@ public: Place d_place; //!< This specifies where a record goes within the packet bool auth; + bool disabled; uint8_t scopeMask; template @@ -112,6 +113,7 @@ public: ar & last_modified; ar & d_place; ar & auth; + ar & disabled; } bool operator==(const DNSResourceRecord& rhs); diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index f279e02c6..c305cfba6 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -112,7 +112,7 @@ public: if the backend does not consider itself responsible for the id passed. \param domain_id ID of which a list is requested */ - virtual bool list(const string &target, int domain_id)=0; + virtual bool list(const string &target, int domain_id, bool include_disabled=false)=0; virtual ~DNSBackend(){}; @@ -136,7 +136,7 @@ public: virtual bool getDomainMetadata(const string& name, const std::string& kind, std::vector& meta) { return false; } virtual bool setDomainMetadata(const string& name, const std::string& kind, const std::vector& meta) {return false;} - virtual void getAllDomains(vector *domains) { } + virtual void getAllDomains(vector *domains, bool include_disabled=false) { } /** Determines if we are authoritative for a zone, and at what level */ virtual bool getAuth(DNSPacket *p, SOAData *sd, const string &target, int *zoneId, const int best_match_len); diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 66e4f5b62..798db95e2 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -84,6 +84,7 @@ bool DNSResourceRecord::operator==(const DNSResourceRecord& rhs) DNSResourceRecord::DNSResourceRecord(const DNSRecord &p) { auth=true; + disabled=false; qname = p.d_label; if(!qname.empty()) boost::erase_tail(qname, 1); // strip . diff --git a/pdns/docs/pdns.xml b/pdns/docs/pdns.xml index 296986b62..2ae16212d 100644 --- a/pdns/docs/pdns.xml +++ b/pdns/docs/pdns.xml @@ -12473,6 +12473,37 @@ create index recordorder on records (domain_id, ordername text_pattern_ops); + From PowerDNS Authoritative Server 3.3.1 to 3.4 + + + If you are coming from 2.9.x, please also read , , and and . + + + + An GSQL Backend schema change is necessary for new features. + For MySQL: + +ALTER TABLE records ADD disabled BOOLEAN; +UPDATE records SET disabled=0; + + For PostgreSQL: + +ALTER TABLE records ADD disabled BOOLEAN; +UPDATE records SET disabled=false; + + For SQLite 3: + +ALTER TABLE records ADD disabled BOOLEAN; +UPDATE records SET disabled=0; + + For Oracle: + +ALTER TABLE records ADD disabled INT; +UPDATE records SET disabled=0; + + + + Serving authoritative DNSSEC data @@ -17661,6 +17692,7 @@ authoritative). AutoserialYes (v3.1 and up) CaseAll lower DNSSECYes (set gmysql-dnssec or gpgsql-dnssec) + Disabled dataYes (v3.4 and up) Module name < 2.9.3pgmysql Module name > 2.9.2gmysql and gpgsql Launch namegmysql and gpgsql2 and gpgsql @@ -17833,6 +17865,14 @@ insert into domains (id,name,type) values (domains_id_sequence.nextval,'example. + + disabled + + + If set to true, this record is hidden from DNS clients, but can still be modified from the REST API. See . (Available since version 3.4.) + + + Please note that the names of the fields are not relevant, but the order is! @@ -18230,6 +18270,16 @@ insert into domains (id,name,type) values (domains_id_sequence.nextval,'example. Make sure that the assigned id in the domains table matches the domain_id field in the records table! + Disabled data + + PowerDNS understands the notion of disabled records. They are marked by setting "disabled" to 1 (for PostgreSQL: true). + By extension, when the SOA record for a domain is disabled, the entire domain is considered to be disabled. + + + Effects: the record (or domain, respectively) will not be visible to DNS clients. The REST API will still see the record (or domain). + Even if a domain is disabled, slaving still works. Slaving considers a disabled domain to have a serial of 0; this implies that a slaved domain will not stay disabled. + + Oracle backend @@ -22265,6 +22315,9 @@ static RandomLoader randomloader; bool authUsed for DNSSEC operations. See and more specifically . It is also useful to check out the rectifyZone() in pdnssec.cc + + bool disabledIf set, this record is not to be served to DNS clients. Backends should not make these records available to PowerDNS unless indicated otherwise. + @@ -22345,11 +22398,12 @@ static RandomLoader randomloader; - bool list(int domain_id) + bool list(int domain_id, bool include_disabled=false) Initiates a list of the indicated domain. Records should then be made available via the get() method. Need not include the SOA record. If it is, PDNS will not get confused. + If include_disabled is given as true, records that are configured but should not be served to DNS clients must also be made available. Should return false if the backend does not consider itself authoritative for this zone. diff --git a/pdns/json.cc b/pdns/json.cc index de37bcf62..b60cf2e3a 100644 --- a/pdns/json.cc +++ b/pdns/json.cc @@ -54,6 +54,16 @@ string stringFromJson(const Value& container, const char* key, const string& def } } +bool boolFromJson(const rapidjson::Value& container, const char* key) +{ + const Value& val = container[key]; + if (val.IsBool()) { + return val.GetBool(); + } else { + throw JsonException("Key '" + string(key) + "' not present or not a Bool"); + } +} + string makeStringFromDocument(const Document& doc) { StringBuffer output; diff --git a/pdns/json.hh b/pdns/json.hh index 17021b850..b79503938 100644 --- a/pdns/json.hh +++ b/pdns/json.hh @@ -33,6 +33,7 @@ int intFromJson(const rapidjson::Value& container, const char* key); int intFromJson(const rapidjson::Value& container, const char* key, const int default_value); std::string stringFromJson(const rapidjson::Value& container, const char* key); std::string stringFromJson(const rapidjson::Value& container, const char* key, const std::string& default_value); +bool boolFromJson(const rapidjson::Value& container, const char* key); class JsonException : public std::runtime_error { diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index 420693163..603159444 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -617,11 +617,11 @@ void UeberBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt d_handle.parent=this; } -void UeberBackend::getAllDomains(vector *domains) { +void UeberBackend::getAllDomains(vector *domains, bool include_disabled) { check_op_requests(); for (vector::iterator i = backends.begin(); i != backends.end(); ++i ) { - (*i)->getAllDomains(domains); + (*i)->getAllDomains(domains, include_disabled); } } @@ -653,7 +653,7 @@ bool UeberBackend::get(DNSResourceRecord &rr) return true; } -bool UeberBackend::list(const string &target, int domain_id) +bool UeberBackend::list(const string &target, int domain_id, bool include_disabled) { L< *domains); + void getAllDomains(vector *domains, bool include_disabled=false); static DNSBackend *maker(const map &); static void closeDynListener(); diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 1db1a30f6..693560153 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -302,7 +302,7 @@ static void fillZone(const string& zonename, HttpResponse* resp) { DNSResourceRecord rr; Value records; records.SetArray(); - di.backend->list(zonename, di.id); + di.backend->list(zonename, di.id, true); // incl. disabled while(di.backend->get(rr)) { if (!rr.qtype.getCode()) continue; // skip empty non-terminals @@ -315,6 +315,7 @@ static void fillZone(const string& zonename, HttpResponse* resp) { object.AddMember("type", jtype, doc.GetAllocator()); object.AddMember("ttl", rr.ttl, doc.GetAllocator()); object.AddMember("priority", rr.priority, doc.GetAllocator()); + object.AddMember("disabled", rr.disabled, doc.GetAllocator()); Value jcontent(rr.content.c_str(), doc.GetAllocator()); // copy object.AddMember("content", jcontent, doc.GetAllocator()); records.PushBack(object, doc.GetAllocator()); @@ -412,7 +413,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) { throw HttpMethodNotAllowedException(); vector domains; - B.getAllDomains(&domains); + B.getAllDomains(&domains, true); // incl. disabled Document doc; doc.SetArray(); @@ -500,11 +501,6 @@ static void apiServerZoneRRset(HttpRequest* req, HttpResponse* resp) { if(!B.getDomainInfo(zonename, di)) throw ApiException("Could not find domain '"+zonename+"'"); - SOAData sd; - sd.db = (DNSBackend*)-1; - if(!B.getSOA(zonename, sd) || !sd.db) - throw ApiException("Could not find domain '"+zonename+"'"); - Document document; req->json(document); @@ -516,7 +512,7 @@ static void apiServerZoneRRset(HttpRequest* req, HttpResponse* resp) { if (changetype == "DELETE") { // delete all matching qname/qtype RRs - sd.db->replaceRRSet(sd.domain_id, qname, qtype, vector()); + di.backend->replaceRRSet(di.id, qname, qtype, vector()); } else if (changetype == "REPLACE") { DNSResourceRecord rr; @@ -527,10 +523,11 @@ static void apiServerZoneRRset(HttpRequest* req, HttpResponse* resp) { rr.qname = stringFromJson(record, "name"); rr.content = stringFromJson(record, "content"); rr.qtype = stringFromJson(record, "type"); - rr.domain_id = sd.domain_id; + rr.domain_id = di.id; rr.auth = 1; rr.ttl = intFromJson(record, "ttl"); rr.priority = intFromJson(record, "priority"); + rr.disabled = boolFromJson(record, "disabled"); rrset.push_back(rr); @@ -547,9 +544,9 @@ static void apiServerZoneRRset(HttpRequest* req, HttpResponse* resp) { } } // Actually store the change. - sd.db->startTransaction(qname); - sd.db->replaceRRSet(sd.domain_id, qname, qtype, rrset); - sd.db->commitTransaction(); + di.backend->startTransaction(qname); + di.backend->replaceRRSet(di.id, qname, qtype, rrset); + di.backend->commitTransaction(); } else throw ApiException("Changetype not understood"); diff --git a/pdns/zone2sql.cc b/pdns/zone2sql.cc index 3d5546071..5bcf7fbfc 100644 --- a/pdns/zone2sql.cc +++ b/pdns/zone2sql.cc @@ -166,50 +166,50 @@ static void emitRecord(const string& zoneName, const string &qname, const string if(g_mode==MYSQL || g_mode==SQLITE) { if(!g_doDNSSEC) { - cout<<"insert into records (domain_id, name,type,content,ttl,prio) select id ,"<< + cout<<"insert into records (domain_id, name, type,content,ttl,prio,disabled) select id ,"<< sqlstr(toLower(stripDot(qname)))<<", "<< sqlstr(qtype)<<", "<< - sqlstr(stripDotContent(content))<<", "<