From 23f886c039cb074420c41fb556d879a5e5196b98 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 16 Apr 2018 18:57:35 +0200 Subject: [PATCH] rec: Add the possibility to dump RPZ updates to a file --- pdns/rec-lua-conf.cc | 26 +++++++++++++------ pdns/rpzloader.cc | 60 +++++++++++++++++++++++++++++++++++++++++++- pdns/rpzloader.hh | 2 +- 3 files changed, 79 insertions(+), 9 deletions(-) diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index 65a63f94d..b6f843820 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -149,6 +149,7 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly) ComboAddress localAddress; ComboAddress master(master_, 53); size_t zoneIdx; + std::string dumpFile; std::shared_ptr sr = nullptr; try { @@ -189,6 +190,10 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly) if(have.count("seedFile")) { seedFile = boost::get(constGet(have, "seedFile")); } + + if(have.count("dumpFile")) { + dumpFile = boost::get(constGet(have, "dumpFile")); + } } if (localAddress != ComboAddress() && localAddress.sin4.sin_family != master.sin4.sin_family) { @@ -203,13 +208,20 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly) zoneIdx = lci.dfe.addZone(zone); if (!seedFile.empty()) { - sr = loadRPZFromFile(seedFile, zone, defpol, maxTTL); - if (zone->getDomain() != domain) { - throw PDNSException("The RPZ zone " + zoneName + " loaded from the seed file (" + zone->getDomain().toString() + ") does not match the one passed in parameter (" + domain.toString() + ")"); - } + g_log<getDomain().toString() + ") has no SOA record"); + if (zone->getDomain() != domain) { + throw PDNSException("The RPZ zone " + zoneName + " loaded from the seed file (" + zone->getDomain().toString() + ") does not match the one passed in parameter (" + domain.toString() + ")"); + } + + if (sr == nullptr) { + throw PDNSException("The RPZ zone " + zoneName + " loaded from the seed file (" + zone->getDomain().toString() + ") has no SOA record"); + } + } + catch(const std::exception& e) { + g_log<d_numberOfRecords = numberOfRecords; } -void RPZIXFRTracker(const ComboAddress& master, boost::optional defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr zone, const uint16_t axfrTimeout, std::shared_ptr sr, uint64_t configGeneration) +static bool dumpZoneToDisk(const DNSName& zoneName, const std::shared_ptr& newZone, const std::string& dumpZoneFileName) +{ + std::string temp = dumpZoneFileName + "XXXXXX"; + int fd = mkstemp(&temp.at(0)); + if (fd < 0) { + g_log<dump(fp); + } + catch(const std::exception& e) { + g_log< defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr zone, const uint16_t axfrTimeout, std::shared_ptr sr, std::string dumpZoneFileName, uint64_t configGeneration) { bool isPreloaded = sr != nullptr; uint32_t refresh = zone->getRefresh(); @@ -304,6 +354,10 @@ void RPZIXFRTracker(const ComboAddress& master, boost::optionalsetSerial(sr->d_st.serial); setRPZZoneNewState(polName, sr->d_st.serial, zone->size(), true); + + if (!dumpZoneFileName.empty()) { + dumpZoneToDisk(zoneName, zone, dumpZoneFileName); + } } catch(const std::exception& e) { g_log< 0 ? refresh : 10)<<" seconds...)"< loadRPZFromFile(const std::string& fname, std::shared_ptr zone, boost::optional defpol, uint32_t maxTTL); std::shared_ptr loadRPZFromServer(const ComboAddress& master, const DNSName& zoneName, std::shared_ptr zone, boost::optional defpol, uint32_t maxTTL, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout); void RPZRecordToPolicy(const DNSRecord& dr, std::shared_ptr zone, bool addOrRemove, boost::optional defpol, uint32_t maxTTL); -void RPZIXFRTracker(const ComboAddress& master, boost::optional defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr zone, const uint16_t axfrTimeout, shared_ptr sr, uint64_t configGeneration); +void RPZIXFRTracker(const ComboAddress& master, boost::optional defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr zone, const uint16_t axfrTimeout, shared_ptr sr, std::string dumpZoneFileName, uint64_t configGeneration); struct rpzStats { -- 2.50.1