Show
Ignore:
Timestamp:
01/06/11 19:57:57 (2 years ago)
Author:
ahu
Message:

make sure that we dnssec-rectify dnssec enabled zones that are slaved from a remote master. Idea by Mathew Hennessy.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/slavecommunicator.cc

    r1717 r1819  
    11/* 
    22    PowerDNS Versatile Database Driven Nameserver 
    3     Copyright (C) 2002-2009  PowerDNS.COM BV 
     3    Copyright (C) 2002-2011  PowerDNS.COM BV 
    44 
    55    This program is free software; you can redistribute it and/or modify 
     
    1818#include "packetcache.hh" 
    1919#include "utility.hh" 
     20#include "dnssecinfra.hh" 
     21#include "dnsseckeeper.hh" 
     22#include "base32.hh" 
    2023#include <errno.h> 
    2124#include "communicator.hh" 
     
    7073 
    7174    UeberBackend *B=dynamic_cast<UeberBackend *>(P.getBackend()); 
     75    NSEC3PARAMRecordContent ns3pr; 
     76    bool narrow; 
     77    DNSSECKeeper dk; 
     78    bool dnssecZone = false; 
     79    if(dk.haveActiveKSKFor(domain)) { 
     80      dnssecZone=true; 
     81      dk.getNSEC3PARAM(domain, &ns3pr, &narrow); 
     82      string hashed; 
     83      if(ns3pr.d_salt.empty())  
     84        cerr<<"Adding NSEC ordering information"<<endl; 
     85      else if(!narrow) 
     86        cerr<<"Adding NSEC3 hashed ordering information for '"<<domain<<"'"<<endl; 
     87      else  
     88        cerr<<"Erasing NSEC3 ordering since we are narrow, only setting 'auth' fields"<<endl; 
     89    } 
    7290 
    7391    if(!B->getDomainInfo(domain, di) || !di.backend) { 
     
    7896 
    7997    Resolver::res_t recs; 
    80  
     98    set<string> nsset, qnames; 
    8199    while(resolver.axfrChunk(recs)) { 
    82100      if(first) { 
     
    85103        first=false; 
    86104      } 
     105       
    87106      for(Resolver::res_t::iterator i=recs.begin();i!=recs.end();++i) { 
    88107        if(!endsOn(i->qname, domain)) {  
     
    90109          continue; 
    91110        } 
     111        if(dnssecZone) { 
     112          if(i->qtype.getCode() == QType::NS && !pdns_iequals(i->qname, domain))  
     113            nsset.insert(i->qname); 
     114          qnames.insert(i->qname); 
     115        }   
    92116        i->domain_id=domain_id; 
    93117        if(i->qtype.getCode()>=1024) 
     
    97121      } 
    98122    } 
     123    if(dnssecZone) { 
     124      string hashed; 
     125      BOOST_FOREACH(const string& qname, qnames) 
     126      { 
     127        string shorter(qname); 
     128        bool auth=true; 
     129        do { 
     130          if(nsset.count(shorter)) {   
     131            auth=false; 
     132            break; 
     133          } 
     134        }while(chopOff(shorter)); 
     135       
     136        if(ns3pr.d_salt.empty()) // NSEC 
     137          di.backend->updateDNSSECOrderAndAuth(domain_id, domain, qname, auth); 
     138        else { 
     139          if(!narrow) { 
     140            hashed=toLower(toBase32Hex(hashQNameWithSalt(ns3pr.d_iterations, ns3pr.d_salt, qname))); 
     141            cerr<<"'"<<qname<<"' -> '"<< hashed <<"'"<<endl; 
     142          } 
     143          di.backend->updateDNSSECOrderAndAuthAbsolute(domain_id, qname, hashed, auth); 
     144        } 
     145      } 
     146    } 
     147     
    99148    di.backend->commitTransaction(); 
    100149    di.backend->setFresh(domain_id);