Skip to content

Commit 2f1fec7

Browse files
committed
import pdnssec rectifyZone() from master
1 parent 71232aa commit 2f1fec7

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

pdns/pdnssec.cc

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,19 @@ bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
178178
if(!B.getSOA(zone, sd)) {
179179
cerr<<"No SOA known for '"<<zone<<"', is such a zone in the database?"<<endl;
180180
return false;
181-
}
181+
}
182182
sd.db->list(zone, sd.domain_id);
183183

184184
DNSResourceRecord rr;
185-
set<string> qnames, nsset, dsnames, nonterm, insnonterm, delnonterm;
185+
set<string> qnames, nsset, dsnames, insnonterm, delnonterm;
186+
map<string,bool> nonterm;
186187
bool doent=true;
187-
188+
188189
while(sd.db->get(rr)) {
189190
if (rr.qtype.getCode())
190191
{
191192
qnames.insert(rr.qname);
192-
if(rr.qtype.getCode() == QType::NS && !pdns_iequals(rr.qname, zone))
193+
if(rr.qtype.getCode() == QType::NS && !pdns_iequals(rr.qname, zone))
193194
nsset.insert(rr.qname);
194195
if(rr.qtype.getCode() == QType::DS)
195196
dsnames.insert(rr.qname);
@@ -202,21 +203,25 @@ bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
202203
NSEC3PARAMRecordContent ns3pr;
203204
bool narrow;
204205
bool haveNSEC3=dk.getNSEC3PARAM(zone, &ns3pr, &narrow);
206+
bool isOptOut=(haveNSEC3 && ns3pr.d_flags);
205207
if(sd.db->doesDNSSEC())
206208
{
207-
if(!haveNSEC3)
209+
if(!haveNSEC3)
208210
cerr<<"Adding NSEC ordering information "<<endl;
209-
else if(!narrow)
210-
cerr<<"Adding NSEC3 hashed ordering information for '"<<zone<<"'"<<endl;
211-
else
211+
else if(!narrow) {
212+
if(!isOptOut)
213+
cerr<<"Adding NSEC3 hashed ordering information for '"<<zone<<"'"<<endl;
214+
else
215+
cerr<<"Adding NSEC3 opt-out hashed ordering information for '"<<zone<<"'"<<endl;
216+
} else
212217
cerr<<"Erasing NSEC3 ordering since we are narrow, only setting 'auth' fields"<<endl;
213218
}
214219
else
215220
cerr<<"Non DNSSEC zone, only adding empty non-terminals"<<endl;
216-
221+
217222
if(doTransaction)
218223
sd.db->startTransaction("", -1);
219-
224+
220225
bool realrr=true;
221226
string hashed;
222227

@@ -239,14 +244,17 @@ bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
239244

240245
if(haveNSEC3)
241246
{
242-
if(!narrow) {
247+
if(!narrow && (realrr || !isOptOut || nonterm.find(qname)->second)) {
243248
hashed=toLower(toBase32Hex(hashQNameWithSalt(ns3pr.d_iterations, ns3pr.d_salt, qname)));
244249
if(g_verbose)
245250
cerr<<"'"<<qname<<"' -> '"<< hashed <<"'"<<endl;
246251
sd.db->updateDNSSECOrderAndAuthAbsolute(sd.domain_id, qname, hashed, auth);
247252
}
248-
else
253+
else {
254+
if(!realrr)
255+
auth=false;
249256
sd.db->nullifyDNSSECOrderNameAndUpdateAuth(sd.domain_id, qname, auth);
257+
}
250258
}
251259
else // NSEC
252260
{
@@ -260,33 +268,39 @@ bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
260268
if (dsnames.count(qname))
261269
sd.db->setDNSSECAuthOnDsRecord(sd.domain_id, qname);
262270
if (!auth || nsset.count(qname)) {
263-
if(haveNSEC3 && ns3pr.d_flags)
271+
if(isOptOut)
264272
sd.db->nullifyDNSSECOrderNameAndAuth(sd.domain_id, qname, "NS");
265273
sd.db->nullifyDNSSECOrderNameAndAuth(sd.domain_id, qname, "A");
266274
sd.db->nullifyDNSSECOrderNameAndAuth(sd.domain_id, qname, "AAAA");
267275
}
268276

269-
if(auth && doent)
277+
if(doent)
270278
{
271279
shorter=qname;
272280
while(!pdns_iequals(shorter, zone) && chopOff(shorter))
273281
{
274-
if(!qnames.count(shorter) && !nonterm.count(shorter))
282+
if(!qnames.count(shorter))
275283
{
276284
if(!(maxent))
277285
{
278-
cerr<<"Zone '"<<zone<<"' has too many empty non terminals."<<endl;
286+
if (!::arg().asNum("max-ent-entries"))
287+
cerr<<"Zone '"<<zone<<"' has too many empty non terminals."<<endl;
279288
insnonterm.clear();
280289
delnonterm.clear();
281290
doent=false;
282291
break;
283292
}
284-
nonterm.insert(shorter);
285-
if (!delnonterm.count(shorter))
293+
294+
if (!delnonterm.count(shorter) && !nonterm.count(shorter))
286295
insnonterm.insert(shorter);
287296
else
288297
delnonterm.erase(shorter);
289-
--maxent;
298+
299+
if (!nonterm.count(shorter)) {
300+
nonterm.insert(pair<string, bool>(shorter, auth));
301+
--maxent;
302+
} else if (auth)
303+
nonterm[shorter]=true;
290304
}
291305
}
292306
}
@@ -303,7 +317,11 @@ bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
303317
if(doent)
304318
{
305319
realrr=false;
306-
qnames=nonterm;
320+
qnames.clear();
321+
pair<string,bool> nt;
322+
BOOST_FOREACH(nt, nonterm){
323+
qnames.insert(nt.first);
324+
}
307325
goto dononterm;
308326
}
309327
}

0 commit comments

Comments
 (0)