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, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',0,'%s','%d')");
+ 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','%d')");
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, "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, "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','%d')");
+ 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','%d')");
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, "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, "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','%d')");
+ 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','%d')");
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, "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, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,disabled,name,auth) values (null,'%d',0,'%s','%d')");
+ 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','%d')");
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'");
return true; // XXX FIXME this API should not return 'true' I think -ahu
}
-bool GSQLBackend::feedEnts(int domain_id, set<string>& nonterm)
+bool GSQLBackend::feedEnts(int domain_id, map<string,bool>& nonterm)
{
- string output;
- BOOST_FOREACH(const string qname, nonterm) {
- output = (boost::format(d_InsertEntQuery) % domain_id % toLower(sqlEscape(qname))).str();
+ string query;
+ pair<string,bool> nt;
+
+ BOOST_FOREACH(nt, nonterm) {
+
+ if (!d_dnssecQueries)
+ query = (boost::format(d_InsertEntQuery)
+ % domain_id
+ % toLower(sqlEscape(nt.first))
+ ).str();
+ else
+ query = (boost::format(d_InsertEntQuery)
+ % domain_id
+ % toLower(sqlEscape(nt.first))
+ % 1
+ ).str();
try {
- d_db->doCommand(output.c_str());
+ d_db->doCommand(query);
}
catch (SSqlException &e) {
throw PDNSException("GSQLBackend unable to feed empty non-terminal: "+e.txtReason());
return true;
}
-bool GSQLBackend::feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow)
+bool GSQLBackend::feedEnts3(int domain_id, const string &domain, map<string,bool> &nonterm, unsigned int times, const string &salt, bool narrow)
{
if(!d_dnssecQueries)
return false;
- string ordername, output;
- BOOST_FOREACH(const string qname, nonterm) {
- if(narrow) {
- output = (boost::format(d_InsertEntQuery) % domain_id % toLower(sqlEscape(qname))).str();
+ string ordername, query;
+ pair<string,bool> nt;
+
+ BOOST_FOREACH(nt, nonterm) {
+
+ if(narrow || !nt.second) {
+ query = (boost::format(d_InsertEntQuery)
+ % domain_id
+ % toLower(sqlEscape(nt.first))
+ % nt.second
+ ).str();
} else {
- ordername=toBase32Hex(hashQNameWithSalt(times, salt, qname));
- output = (boost::format(d_InsertEntOrderQuery) % domain_id % toLower(sqlEscape(qname)) % toLower(sqlEscape(ordername))).str();
+ ordername=toBase32Hex(hashQNameWithSalt(times, salt, nt.first));
+ query = (boost::format(d_InsertEntOrderQuery)
+ % domain_id
+ % toLower(sqlEscape(nt.first))
+ % toLower(sqlEscape(ordername))
+ % nt.second
+ ).str();
}
try {
- d_db->doCommand(output.c_str());
+ d_db->doCommand(query);
}
catch (SSqlException &e) {
throw PDNSException("GSQLBackend unable to feed empty non-terminal: "+e.txtReason());
bool commitTransaction();
bool abortTransaction();
bool feedRecord(const DNSResourceRecord &r, string *ordername=0);
- bool feedEnts(int domain_id, set<string>& nonterm);
- bool feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow);
+ bool feedEnts(int domain_id, map<string,bool>& nonterm);
+ bool feedEnts3(int domain_id, const string &domain, map<string,bool> &nonterm, unsigned int times, const string &salt, bool narrow);
bool createDomain(const string &domain);
bool createSlaveDomain(const string &ip, const string &domain, const string &nameserver, const string &account);
bool deleteDomain(const string &domain);
{
return false; // no problem!
}
- virtual bool feedEnts(int domain_id, set<string> &nonterm)
+ virtual bool feedEnts(int domain_id, map<string,bool> &nonterm)
{
return false;
}
- virtual bool feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow)
+ virtual bool feedEnts3(int domain_id, const string &domain, map<string,bool> &nonterm, unsigned int times, const string &salt, bool narrow)
{
return false;
}
bool doent=true;
uint32_t maxent = ::arg().asNum("max-ent-entries");
string ordername, shorter;
- set<string> nonterm, rrterm;
+ set<string> rrterm;
+ map<string,bool> nonterm;
BOOST_FOREACH(DNSResourceRecord& rr, rrs) {
rrterm.clear();
do {
if(doent) {
- if (!qnames.count(shorter) && !nonterm.count(shorter) && !rrterm.count(shorter))
+ if (!qnames.count(shorter))
rrterm.insert(shorter);
}
- if(nsset.count(shorter) && rr.qtype.getCode() != QType::DS) {
+ if(nsset.count(shorter) && rr.qtype.getCode() != QType::DS)
rr.auth=false;
- break;
- }
+
if (pdns_iequals(shorter, domain)) // stop at apex
break;
}while(chopOff(shorter));
- // Insert ents for auth rrs
- if(doent && rr.auth) {
- nonterm.insert(rrterm.begin(), rrterm.end());
+ // Insert ents
+ if(doent && !rrterm.empty()) {
+ bool auth;
+ if (!rr.auth && rr.qtype.getCode() == QType::NS) {
+ ordername=toBase32Hex(hashQNameWithSalt(ns3pr.d_iterations, ns3pr.d_salt, rr.qname));
+ auth=(!gotOptOutFlag || secured.count(ordername));
+ } else
+ auth=rr.auth;
+
+ BOOST_FOREACH(const string nt, rrterm){
+ if (!nonterm.count(nt))
+ nonterm.insert(pair<string, bool>(nt, auth));
+ else if (auth)
+ nonterm[nt]=true;
+ }
+
if(nonterm.size() > maxent) {
L<<Logger::Error<<"AXFR zone "<<domain<<" has too many empty non terminals."<<endl;
nonterm.clear();