]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add code to detect removal and new domains in bindbackend
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 13 Mar 2014 08:08:41 +0000 (09:08 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 13 Mar 2014 08:08:41 +0000 (09:08 +0100)
modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh

index a92ae5b58abdd82df910455fdb0a097f919fe0a5..f2307cbf330594a61f420b967475b721102de175 100644 (file)
@@ -131,6 +131,20 @@ bool Bind2Backend::safeGetBBDomainInfo(const std::string& name, BB2DomainInfo* b
   return true;
 }
 
+bool Bind2Backend::safeRemoveBBDomainInfo(const std::string& name)
+{
+  WriteLock rl(&s_state_lock);
+  typedef state_t::index<NameTag>::type nameindex_t;
+  nameindex_t& nameindex = boost::multi_index::get<NameTag>(s_state);
+
+  nameindex_t::iterator iter = nameindex.find(name);
+  if(iter == nameindex.end())
+    return false;
+  nameindex.erase(iter);
+  return true;
+}
+
+
 void Bind2Backend::safePutBBDomainInfo(const BB2DomainInfo& bbd)
 {
   WriteLock rl(&s_state_lock);
@@ -707,10 +721,16 @@ void Bind2Backend::loadConfig(string* status)
 
     L<<Logger::Warning<<d_logprefix<<" Parsing "<<domains.size()<<" domain(s), will report when done"<<endl;
     
+    set<string> oldnames, newnames;
+    {
+      ReadLock rl(&s_state_lock);
+      BOOST_FOREACH(const BB2DomainInfo& bbd, s_state) {
+        oldnames.insert(bbd.d_name);
+      }
+    }
     int rejected=0;
     int newdomains=0;
 
-    //    random_shuffle(domains.begin(), domains.end());
     struct stat st;
       
     for(vector<BindDomainInfo>::iterator i=domains.begin(); i!=domains.end(); ++i) 
@@ -780,24 +800,25 @@ void Bind2Backend::loadConfig(string* status)
 
     // figure out which domains were new and which vanished
     int remdomains=0;
-    set<string> oldnames, newnames;
-#if 0
-    for(state_t::const_iterator j=state.get()->id_zone_map.begin();j != s_state.get()->id_zone_map.end();++j) {
-      oldnames.insert(j->second.d_name);
-    }
-    for(id_zone_map_t::const_iterator j=staging->id_zone_map.begin(); j!= staging->id_zone_map.end(); ++j) {
-      newnames.insert(j->second.d_name);
+    {
+      ReadLock rl(&s_state_lock);
+      BOOST_FOREACH(const BB2DomainInfo& bbd, s_state) {
+        newnames.insert(bbd.d_name);
+      }
     }
-#endif
     vector<string> diff;
 
     set_difference(oldnames.begin(), oldnames.end(), newnames.begin(), newnames.end(), back_inserter(diff));
     remdomains=diff.size();
+    
+    BOOST_FOREACH(const std::string& name, diff) {
+      safeRemoveBBDomainInfo(name);
+    }
 
     // count number of entirely new domains
-    vector<string> diff2;
-    set_difference(newnames.begin(), newnames.end(), oldnames.begin(), oldnames.end(), back_inserter(diff2));
-    newdomains=diff2.size();
+    diff.clear();
+    set_difference(newnames.begin(), newnames.end(), oldnames.begin(), oldnames.end(), back_inserter(diff));
+    newdomains=diff.size();
 
     ostringstream msg;
     msg<<" Done parsing domains, "<<rejected<<" rejected, "<<newdomains<<" new, "<<remdomains<<" removed"; 
index c5cfc31e0e4db3171369626ec8b0ea0a2d043b9e..cdd257d76385da73fce700c15e0ff6f98f5e4492 100644 (file)
@@ -242,6 +242,7 @@ private:
   static bool safeGetBBDomainInfo(int id, BB2DomainInfo* bbd);
   static void safePutBBDomainInfo(const BB2DomainInfo& bbd);
   static bool safeGetBBDomainInfo(const std::string& name, BB2DomainInfo* bbd);
+  static bool safeRemoveBBDomainInfo(const std::string& name);
   bool GetBBDomainInfo(int id, BB2DomainInfo** bbd);
   shared_ptr<SSQLite3> d_dnssecdb;
   bool getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* ns3p);