]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use new domainid_t type for domain ids. 15474/head
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 25 Apr 2025 13:16:17 +0000 (15:16 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 5 May 2025 04:58:05 +0000 (06:58 +0200)
Also use UnknownDomainID instead of -1.

Update all users, remove casts and lint conversion annotations.

33 files changed:
docs/appendices/backend-writers-guide.rst
modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh
modules/geoipbackend/geoipbackend.cc
modules/geoipbackend/geoipbackend.hh
modules/ldapbackend/ldapbackend.hh
modules/ldapbackend/native.cc
modules/ldapbackend/primary.cc
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh
modules/lua2backend/lua2api2.hh
modules/pipebackend/pipebackend.cc
modules/pipebackend/pipebackend.hh
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh
modules/tinydnsbackend/tinydnsbackend.cc
modules/tinydnsbackend/tinydnsbackend.hh
pdns/auth-primarycommunicator.cc
pdns/auth-secondarycommunicator.cc
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/comment.hh
pdns/dbdnsseckeeper.cc
pdns/dns.hh
pdns/dnsbackend.cc
pdns/dnsbackend.hh
pdns/dnsparser.hh
pdns/dnsseckeeper.hh
pdns/packethandler.cc
pdns/pdnsutil.cc
pdns/rfc2136handler.cc
pdns/test-ueberbackend_cc.cc
pdns/ws-auth.cc

index 7fd50f2a2580442b8369bf55d8daf3ca8326ff88..13c2d4284e86c3ea167e844ac9a37baac0e590ef 100644 (file)
@@ -67,8 +67,8 @@ following methods are relevant:
         {
         public:
         virtual unsigned int getCapabilities()=0;
-        virtual void lookup(const QType &qtype, const string &qdomain, int zoneId=-1, DNSPacket *pkt_p=nullptr)=0;
-        virtual bool list(const string &target, int domain_id)=0;
+        virtual void lookup(const QType &qtype, const string &qdomain, domainid_t zoneId=UnknownDomainID, DNSPacket *pkt_p=nullptr)=0;
+        virtual bool list(const string &target, domainid_t domain_id)=0;
         virtual bool get(DNSResourceRecord &r)=0;
         virtual bool getSOA(const string &name, SOAData &soadata);
         };
@@ -164,12 +164,12 @@ furthermore, only about its A record:
     public:
       unsigned int getCapabilities() override { return 0; }
 
-      bool list(const string &target, int id)
+      bool list(const string &target, domainid_t id)
       {
         return false; // we don't support pdnsutil list-zone or AXFR
       }
 
-      void lookup(const QType &type, const string &qdomain, int zoneId, DNSPacket *p)
+      void lookup(const QType &type, const string &qdomain, domainid_t zoneId, DNSPacket *p)
       {
         if(type.getCode()!=QType::A || qdomain!="random.powerdns.com")  // we only know about random.powerdns.com A
           d_answer="";                                                  // no answer
@@ -292,7 +292,7 @@ Classes
 
   Time To Live of this record
 
-.. cpp:member:: int DNSResourceRecord::domain_id
+.. cpp:member:: domainid_t DNSResourceRecord::domain_id
 
   ID of the domain this record belongs to
 
@@ -336,7 +336,7 @@ Classes
 
   Minimum acceptable value for TTL
 
-.. cpp:member:: int SOAData::domain_id
+.. cpp:member:: domainid_t SOAData::domain_id
 
   The ID of the domain within this backend. Must be filled!
 
@@ -355,7 +355,7 @@ Methods
 * `CAP_DNSSEC`     Backend implements :ref:`backend-dnssec`.
 * `CAP_LIST`       Backend implements `list`, for AXFR or `pdnsutil list-zone`
 
-.. cpp:function:: void DNSBackend::lookup(const QType &qtype, const string &qdomain, int zoneId=-1, DNSPacket *pkt=nullptr)
+.. cpp:function:: void DNSBackend::lookup(const QType &qtype, const string &qdomain, domainid_t zoneId=UnknownDomainID, DNSPacket *pkt=nullptr)
 
   This function is used to initiate a straight lookup for a record of name
   'qdomain' and type 'qtype'. A QType can be converted into an integer by
@@ -392,7 +392,7 @@ Methods
   It is legal to return here, and have the first call to ``get()`` return
   false. This is interpreted as 'no data'.
 
-.. cpp:function:: bool DNSBackend::list(int domain_id, bool include_disabled=false)
+.. cpp:function:: bool DNSBackend::list(domainid_t domain_id, bool include_disabled=false)
 
   Initiates a list of the indicated domain. Records should then be made
   available via the ``get()`` method. Need not include the SOA record. If
@@ -563,12 +563,12 @@ The following excerpt from the DNSBackend shows the relevant functions:
                /* ... */
                virtual bool getDomainInfo(const string &domain, DomainInfo &di, bool getSerial = true);
                virtual bool isPrimary(const ComboAddress& ipAddress);
-               virtual bool startTransaction(const string &qname, int id);
+               virtual bool startTransaction(const string &qname, domainid_t id);
                virtual bool commitTransaction();
                virtual bool abortTransaction();
                virtual bool feedRecord(const DNSResourceRecord &rr, const DNSName &ordername, bool ordernameIsNSEC3 = false);
                virtual void getUnfreshSecondaryInfos(vector<DomainInfo>* domains);
-               virtual void setFresh(uint32_t id);
+               virtual void setFresh(domainid_t id);
                /* ... */
          }
 
@@ -576,7 +576,7 @@ The mentioned DomainInfo struct looks like this:
 
 .. cpp:struct:: DomainInfo
 
-.. cpp:member:: uint32_t DomainInfo::id
+.. cpp:member:: domainid_t DomainInfo::id
 
   ID of this zone within this backend
 
@@ -633,11 +633,13 @@ this zone.
   backend considers itself authoritative for the named zone, ``di`` should
   be filled out, and 'true' be returned. Otherwise return false.
 
-.. cpp:function:: bool DomainInfo::startTransaction(const string &qname, int id)
+.. cpp:function:: bool DomainInfo::startTransaction(const string &qname, domainid_t id)
 
   When called, the backend should start a transaction that can be
   committed or rolled back atomically later on. In SQL terms, this
-  function should **BEGIN** a transaction and **DELETE** all records.
+  function should **BEGIN** a transaction, and **DELETE** all records for
+  the domain matching the given ``id``, unless its value is
+  ``UnknownDomainID``.
 
 .. cpp:function:: bool DomainInfo::feedRecord(const DNSResourceRecord &rr, const DNSName &ordername, bool ordernameIsNSEC3)
 
@@ -651,7 +653,7 @@ this zone.
 
   Abort changes. In SQL terms, execute **ABORT**.
 
-.. cpp:function:: bool DomainInfo::setFresh()
+.. cpp:function:: bool DomainInfo::setFresh(domainid_t id)
 
   Indicate that a domain has either been updated or refreshed without the
   need for a retransfer. This causes the domain to vanish from the vector
@@ -729,7 +731,7 @@ The following excerpt from the DNSBackend shows the relevant functions:
           public:
                /* ... */
            virtual void getUpdatedPrimaries(vector<DomainInfo>* domains, std::unordered_set<DNSName> &catalogs, CatalogHashMap &catalogHashes);
-           virtual void setNotified(uint32_t id, uint32_t serial);
+           virtual void setNotified(domainid_t id, uint32_t serial);
                /* ... */
          }
 
@@ -745,7 +747,7 @@ this zone.
   When called, the backend should examine its list of primary domains and
   add any changed ones to the :cpp:class:`DomainInfo` vector.
 
-.. cpp:function:: void DNSBackend::setNotified(uint32_t domain_id, uint32_t serial)
+.. cpp:function:: void DNSBackend::setNotified(domainid_t domain_id, uint32_t serial)
 
   Indicate that notifications have been queued for this domain and that it
   need not be considered 'updated' anymore.
@@ -763,20 +765,20 @@ other update/remove functionality at a later stage.
     class DNSBackend {
     public:
       /* ... */
-      virtual bool startTransaction(const DNSName &qname, int id);
+      virtual bool startTransaction(const DNSName &qname, domainid_t id);
       virtual bool commitTransaction();
       virtual bool abortTransaction();
       virtual bool feedRecord(const DNSResourceRecord &rr, DNSName &ordername, bool ordernameIsNSEC3);
-      virtual bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
-      virtual bool listSubZone(const DNSName &zone, int domain_id);
+      virtual bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+      virtual bool listSubZone(const DNSName &zone, domainid_t domain_id);
       /* ... */
     }
 
-.. cpp:function:: virtual bool DNSBackend::startTransaction(const DNSName &qname, int id)
+.. cpp:function:: virtual bool DNSBackend::startTransaction(const DNSName &qname, domainid_t id)
 
   See :cpp:func:`above <DNSBackend::beginTransaction>`. Please
-  note that this function now receives a negative number (-1), which
-  indicates that the current zone data should NOT be deleted.
+  note that if this function receives ``UnknownDomainID`` as the ``id``,
+  the current zone data should NOT be deleted.
 
 .. cpp:function:: virtual bool DNSBackend::commitTransaction()
 
@@ -793,7 +795,7 @@ other update/remove functionality at a later stage.
   Please keep in mind that the zone is not empty because
   ``startTransaction()`` was called differently.
 
-.. cpp:function:: virtual bool DNSBackend::listSubZone(const DNSName &name, int domain_id)
+.. cpp:function:: virtual bool DNSBackend::listSubZone(const DNSName &name, domainid_t domain_id)
 
   This method is needed for rectification of a zone after NS-records have
   been added. For DNSSEC, we need to know which records are below the
@@ -808,7 +810,7 @@ other update/remove functionality at a later stage.
   ENT-records in PowerDNS. Make sure it returns every record in the tree
   below the given record.
 
-.. cpp:function:: virtual bool DNSBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+.. cpp:function:: virtual bool DNSBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
 
   This method should remove all the records with ``qname`` of type ``qt``.
   ``qt`` might also be ANY, which means all the records with that
@@ -887,13 +889,13 @@ In order for a backend to support DNSSEC, quite a few number of additional opera
       virtual unsigned int getCapabilities();
 
       /* ... */
-      virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after);
+      virtual bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after);
 
       /* update operations */
-      virtual bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY);
-      virtual bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove);
-      virtual bool feedEnts(int domain_id, map<DNSName,bool> &nonterm);
-      virtual bool feedEnts3(int domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow);
+      virtual bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY);
+      virtual bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove);
+      virtual bool feedEnts(domainid_t domain_id, map<DNSName,bool> &nonterm);
+      virtual bool feedEnts3(domainid_t domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow);
 
       /* keys management */
       virtual bool getDomainKeys(const DNSName& name, std::vector<KeyData>& keys);
@@ -910,24 +912,24 @@ In order for a backend to support DNSSEC, quite a few number of additional opera
 In addition to these methods, the return value of `getCapabilities` must
 contain `CAP_DNSSEC` if that backend supports DNSSEC.
 
-.. cpp:function:: virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+.. cpp:function:: virtual bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
 
   Asks the names before and after qname for NSEC and NSEC3. The qname will be hashed when using NSEC3. Care must be taken to handle wrap-around when qname is the first or last in the ordered list of zone names.
   Please note that in case the requested name is present in the zone, it should be returned as the "before" name.
 
-.. cpp:function:: virtual bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY)
+.. cpp:function:: virtual bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY)
 
   Updates the ordername and auth fields.
 
-.. cpp:function:: virtual bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
+.. cpp:function:: virtual bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
 
   Updates ENT after a zone has been rectified. If 'remove' is false, 'erase' contains a list of ENTs to remove from the zone before adding any. Otherwise all ENTs should be removed from the zone before adding any. 'insert' contains the list of ENTs to add to the zone after the removals have been done.
 
-.. cpp:function:: virtual bool feedEnts(int domain_id, map<DNSName,bool> &nonterm)
+.. cpp:function:: virtual bool feedEnts(domainid_t domain_id, map<DNSName,bool> &nonterm)
 
   This method is used by ``pdnsutil rectify-zone`` to populate missing non-terminals. This is used when you have, say, record like _sip._upd.example.com, but no _udp.example.com. PowerDNS requires that there exists a non-terminal in between, and this instructs you to add one.
 
-.. cpp:function:: virtual bool feedEnts3(int domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+.. cpp:function:: virtual bool feedEnts3(domainid_t domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
 
   Same as feedEnts, but provides NSEC3 hashing parameters.
 
@@ -982,7 +984,7 @@ Below, we'll show the class definitions of each (with some details omitted, but
 
   struct DNSZoneRecord
   {
-    int domain_id{-1};
+    domainid_t domain_id{UnknownDomainID};
     uint8_t scopeMask{0};
     int signttl{0};
     DNSName wildcardname;
@@ -1061,7 +1063,7 @@ It is subclassed for all supported types:
   class DNSResourceRecord
   {
   public:
-    DNSResourceRecord() : last_modified(0), ttl(0), signttl(0), domain_id(-1), qclass(1), scopeMask(0), auth(true), disabled(false) {};
+    DNSResourceRecord() : last_modified(0), ttl(0), signttl(0), domain_id(UnknownDomainID), qclass(1), scopeMask(0), auth(true), disabled(false) {};
     static DNSResourceRecord fromWire(const DNSRecord& d);
 
     void setContent(const string& content);
@@ -1075,7 +1077,7 @@ It is subclassed for all supported types:
     uint32_t ttl; //!< Time To Live of this record
     uint32_t signttl; //!< If non-zero, use this TTL as original TTL in the RRSIG
 
-    int domain_id; //!< If a backend implements this, the domain_id of the zone this record is in
+    domainid_t domain_id; //!< If a backend implements this, the domain_id of the zone this record is in
     QType qtype; //!< qtype of this record, ie A, CNAME, MX etc
     uint16_t qclass; //!< class of this record
 
index 9b0f1fc075c01714be48f3b92f82941a12e82304..3cd05868dab3296664d1983ba013ba59119c333d 100644 (file)
@@ -131,7 +131,8 @@ void BB2DomainInfo::setCtime()
   d_ctime = buf.st_ctime;
 }
 
-bool Bind2Backend::safeGetBBDomainInfo(int id, BB2DomainInfo* bbd)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool Bind2Backend::safeGetBBDomainInfo(domainid_t id, BB2DomainInfo* bbd)
 {
   auto state = s_state.read_lock();
   state_t::const_iterator iter = state->find(id);
@@ -174,7 +175,8 @@ void Bind2Backend::safePutBBDomainInfo(const BB2DomainInfo& bbd)
   replacing_insert(*state, bbd);
 }
 
-void Bind2Backend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void Bind2Backend::setNotified(domainid_t id, uint32_t serial)
 {
   BB2DomainInfo bbd;
   if (!safeGetBBDomainInfo(id, &bbd))
@@ -183,7 +185,8 @@ void Bind2Backend::setNotified(uint32_t id, uint32_t serial)
   safePutBBDomainInfo(bbd);
 }
 
-void Bind2Backend::setLastCheck(uint32_t domain_id, time_t lastcheck)
+// NOLINTNEXTLINE(readability-identifier-length)
+void Bind2Backend::setLastCheck(domainid_t domain_id, time_t lastcheck)
 {
   BB2DomainInfo bbd;
   if (safeGetBBDomainInfo(domain_id, &bbd)) {
@@ -192,21 +195,22 @@ void Bind2Backend::setLastCheck(uint32_t domain_id, time_t lastcheck)
   }
 }
 
-void Bind2Backend::setStale(uint32_t domain_id)
+void Bind2Backend::setStale(domainid_t domain_id)
 {
-  setLastCheck(domain_id, 0);
+  Bind2Backend::setLastCheck(domain_id, 0);
 }
 
-void Bind2Backend::setFresh(uint32_t domain_id)
+void Bind2Backend::setFresh(domainid_t domain_id)
 {
-  setLastCheck(domain_id, time(nullptr));
+  Bind2Backend::setLastCheck(domain_id, time(nullptr));
 }
 
-bool Bind2Backend::startTransaction(const ZoneName& qname, int domainId)
+bool Bind2Backend::startTransaction(const ZoneName& qname, domainid_t domainId)
 {
-  if (domainId < 0) {
+  if (domainId == UnknownDomainID) {
     d_transaction_tmpname.clear();
-    d_transaction_id = domainId;
+    d_transaction_id = UnknownDomainID;
+    // No support for domain contents deletion
     return false;
   }
   if (domainId == 0) {
@@ -245,8 +249,9 @@ bool Bind2Backend::startTransaction(const ZoneName& qname, int domainId)
 
 bool Bind2Backend::commitTransaction()
 {
-  if (d_transaction_id < 0)
+  if (d_transaction_id == UnknownDomainID) {
     return false;
+  }
   d_of.reset();
 
   BB2DomainInfo bbd;
@@ -256,7 +261,7 @@ bool Bind2Backend::commitTransaction()
     queueReloadAndStore(bbd.d_id);
   }
 
-  d_transaction_id = 0;
+  d_transaction_id = UnknownDomainID;
 
   return true;
 }
@@ -266,10 +271,10 @@ bool Bind2Backend::abortTransaction()
   // -1 = dnssec speciality
   // 0  = invalid transact
   // >0 = actual transaction
-  if (d_transaction_id > 0) {
+  if (d_transaction_id != UnknownDomainID) {
     unlink(d_transaction_tmpname.c_str());
     d_of.reset();
-    d_transaction_id = 0;
+    d_transaction_id = UnknownDomainID;
   }
 
   return true;
@@ -277,7 +282,7 @@ bool Bind2Backend::abortTransaction()
 
 bool Bind2Backend::feedRecord(const DNSResourceRecord& rr, const DNSName& /* ordername */, bool /* ordernameIsNSEC3 */)
 {
-  if (d_transaction_id < 1) {
+  if (d_transaction_id == UnknownDomainID) {
     throw DBException("Bind2Backend::feedRecord() called outside of transaction");
   }
 
@@ -748,7 +753,7 @@ Bind2Backend::Bind2Backend(const string& suffix, bool loadZones)
     throw PDNSException("bind-hybrid and the zone cache currently interoperate badly. Please disable the zone cache or stop using bind-hybrid");
   }
 
-  d_transaction_id = 0;
+  d_transaction_id = UnknownDomainID;
   s_ignore_broken_records = mustDo("ignore-broken-records");
   d_upgradeContent = ::arg().mustDo("upgrade-unknown-types");
 
@@ -1042,7 +1047,8 @@ void Bind2Backend::loadConfig(string* status) // NOLINT(readability-function-cog
   }
 }
 
-void Bind2Backend::queueReloadAndStore(unsigned int id)
+// NOLINTNEXTLINE(readability-identifier-length)
+void Bind2Backend::queueReloadAndStore(domainid_t id)
 {
   BB2DomainInfo bbold;
   try {
@@ -1110,7 +1116,8 @@ bool Bind2Backend::findBeforeAndAfterUnhashed(std::shared_ptr<const recordstorag
   return true;
 }
 
-bool Bind2Backend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool Bind2Backend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
 {
   BB2DomainInfo bbd;
   if (!safeGetBBDomainInfo(id, &bbd))
@@ -1148,7 +1155,7 @@ bool Bind2Backend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qn
   }
 }
 
-void Bind2Backend::lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* /* pkt_p */)
+void Bind2Backend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* /* pkt_p */)
 {
   d_handle.reset();
 
@@ -1161,7 +1168,7 @@ void Bind2Backend::lookup(const QType& qtype, const DNSName& qname, int zoneId,
   if (mustlog)
     g_log << Logger::Warning << "Lookup for '" << qtype.toString() << "' of '" << qname << "' within zoneID " << zoneId << endl;
 
-  if (zoneId >= 0) {
+  if (zoneId != UnknownDomainID) {
     if ((found = (safeGetBBDomainInfo(zoneId, &bbd) && qname.isPartOf(bbd.d_name)))) {
       domain = std::move(bbd.d_name);
     }
@@ -1291,7 +1298,7 @@ bool Bind2Backend::handle::get_normal(DNSResourceRecord& r)
   return true;
 }
 
-bool Bind2Backend::list(const ZoneName& /* target */, int domainId, bool /* include_disabled */)
+bool Bind2Backend::list(const ZoneName& /* target */, domainid_t domainId, bool /* include_disabled */)
 {
   BB2DomainInfo bbd;
 
@@ -1396,7 +1403,7 @@ bool Bind2Backend::autoPrimaryBackend(const string& ipAddress, const ZoneName& /
 
 BB2DomainInfo Bind2Backend::createDomainEntry(const ZoneName& domain, const string& filename)
 {
-  int newid = 1;
+  domainid_t newid = 1;
   { // Find a free zone id nr.
     auto state = s_state.read_lock();
     if (!state->empty()) {
index f4ba903d1b663d38c1e65d11d90cba2d6561a905..6fe202ef9c6c532042248e19c8ef19c30f2fa86a 100644 (file)
@@ -187,19 +187,19 @@ public:
   bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial = true) override;
   time_t getCtime(const string& fname);
   // DNSSEC
-  bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
-  void lookup(const QType&, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override;
-  bool list(const ZoneName& target, int domainId, bool include_disabled = false) override;
+  bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+  void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* p = nullptr) override;
+  bool list(const ZoneName& target, domainid_t domainId, bool include_disabled = false) override;
   bool get(DNSResourceRecord&) override;
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled = false) override;
 
   static DNSBackend* maker();
   static std::mutex s_startup_lock;
 
-  void setStale(uint32_t domain_id) override;
-  void setFresh(uint32_t domain_id) override;
-  void setNotified(uint32_t id, uint32_t serial) override;
-  bool startTransaction(const ZoneName& qname, int domainId) override;
+  void setStale(domainid_t domain_id) override;
+  void setFresh(domainid_t domain_id) override;
+  void setNotified(domainid_t id, uint32_t serial) override;
+  bool startTransaction(const ZoneName& qname, domainid_t domainId) override;
   bool feedRecord(const DNSResourceRecord& rr, const DNSName& ordername, bool ordernameIsNSEC3 = false) override;
   bool commitTransaction() override;
   bool abortTransaction() override;
@@ -242,13 +242,13 @@ private:
   void setupDNSSEC();
   void setupStatements();
   void freeStatements();
-  static bool safeGetBBDomainInfo(int id, BB2DomainInfo* bbd);
+  static bool safeGetBBDomainInfo(domainid_t id, BB2DomainInfo* bbd);
   static void safePutBBDomainInfo(const BB2DomainInfo& bbd);
   static bool safeGetBBDomainInfo(const ZoneName& name, BB2DomainInfo* bbd);
   static bool safeRemoveBBDomainInfo(const ZoneName& name);
   shared_ptr<SSQLite3> d_dnssecdb;
   bool getNSEC3PARAM(const ZoneName& name, NSEC3PARAMRecordContent* ns3p);
-  void setLastCheck(uint32_t domain_id, time_t lastcheck);
+  static void setLastCheck(domainid_t domain_id, time_t lastcheck);
   bool getNSEC3PARAMuncached(const ZoneName& name, NSEC3PARAMRecordContent* ns3p);
   class handle
   {
@@ -269,7 +269,7 @@ private:
     DNSName qname;
     ZoneName domain;
 
-    int id{-1};
+    domainid_t id{UnknownDomainID};
     QType qtype;
     bool d_list{false};
     bool mustlog{false};
@@ -304,14 +304,14 @@ private:
   handle d_handle;
   static string s_binddirectory; //!< this is used to store the 'directory' setting of the bind configuration
   static int s_first; //!< this is raised on construction to prevent multiple instances of us being generated
-  int d_transaction_id;
+  domainid_t d_transaction_id;
   static bool s_ignore_broken_records;
   bool d_hybrid;
   bool d_upgradeContent;
 
   BB2DomainInfo createDomainEntry(const ZoneName& domain, const string& filename); //!< does not insert in s_state
 
-  void queueReloadAndStore(unsigned int id);
+  void queueReloadAndStore(domainid_t id);
   static bool findBeforeAndAfterUnhashed(std::shared_ptr<const recordstorage_t>& records, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after);
   static void insertRecord(std::shared_ptr<recordstorage_t>& records, const ZoneName& zoneName, const DNSName& qname, const QType& qtype, const string& content, int ttl, const std::string& hashed = string(), const bool* auth = nullptr);
   void reload() override;
index a7360b1b2656ddb3800ca348c0f0b180078279e2..6381d04f2df62c663e94cdde4f857e82052a63a1 100644 (file)
@@ -56,7 +56,7 @@ struct GeoIPService
 
 struct GeoIPDomain
 {
-  std::uint32_t id{};
+  domainid_t id{};
   ZoneName domain;
   int ttl{};
   map<DNSName, GeoIPService> services;
@@ -130,7 +130,7 @@ static bool validateMappingLookupFormats(const vector<string>& formats)
 static vector<GeoIPDNSResourceRecord> makeDNSResourceRecord(GeoIPDomain& dom, DNSName name)
 {
   GeoIPDNSResourceRecord resourceRecord;
-  resourceRecord.domain_id = static_cast<int>(dom.id);
+  resourceRecord.domain_id = dom.id;
   resourceRecord.ttl = dom.ttl;
   resourceRecord.qname = std::move(name);
   resourceRecord.qtype = QType(0); // empty non terminal
@@ -215,7 +215,7 @@ void GeoIPBackend::setupNetmasks(const YAML::Node& domain, GeoIPDomain& dom)
   }
 }
 
-bool GeoIPBackend::loadDomain(const YAML::Node& domain, std::uint32_t domainID, GeoIPDomain& dom)
+bool GeoIPBackend::loadDomain(const YAML::Node& domain, domainid_t domainID, GeoIPDomain& dom)
 {
   try {
     dom.id = domainID;
@@ -229,7 +229,7 @@ bool GeoIPBackend::loadDomain(const YAML::Node& domain, std::uint32_t domainID,
       for (auto item = recs->second.begin(); item != recs->second.end(); item++) {
         auto rec = item->begin();
         GeoIPDNSResourceRecord rr;
-        rr.domain_id = static_cast<int>(dom.id);
+        rr.domain_id = dom.id;
         rr.ttl = dom.ttl;
         rr.qname = qname.operator const DNSName&();
         if (rec->first.IsNull()) {
@@ -493,7 +493,7 @@ bool GeoIPBackend::lookup_static(const GeoIPDomain& dom, const DNSName& search,
   return false;
 };
 
-void GeoIPBackend::lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p)
+void GeoIPBackend::lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p)
 {
   ReadLock rl(&s_state_lock);
   const GeoIPDomain* dom;
@@ -505,8 +505,9 @@ void GeoIPBackend::lookup(const QType& qtype, const DNSName& qdomain, int zoneId
 
   d_result.clear();
 
-  if (zoneId > -1 && zoneId < static_cast<int>(s_domains.size()))
+  if (zoneId >= 0 && zoneId < static_cast<domainid_t>(s_domains.size())) {
     dom = &(s_domains[zoneId]);
+  }
   else {
     for (const GeoIPDomain& i : s_domains) { // this is arguably wrong, we should probably find the most specific match
       if (qdomain.isPartOf(i.domain)) {
index a60c785cd73ef71b614f683070d83210bb6b84b3..cd0af1f8dd1dbbb04e71f66fe28d04fc9b21faa3 100644 (file)
@@ -64,8 +64,8 @@ public:
     return caps;
   }
 
-  void lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p = nullptr) override;
-  bool list(const ZoneName& /* target */, int /* domain_id */, bool /* include_disabled */ = false) override { return false; } // not supported
+  void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
+  bool list(const ZoneName& /* target */, domainid_t /* domain_id */, bool /* include_disabled */ = false) override { return false; } // not supported
   bool get(DNSResourceRecord& r) override;
   void reload() override;
   void rediscover(string* status = nullptr) override;
@@ -92,7 +92,7 @@ private:
   bool hasDNSSECkey(const ZoneName& name);
   bool lookup_static(const GeoIPDomain& dom, const DNSName& search, const QType& qtype, const DNSName& qdomain, const Netmask& addr, GeoIPNetmask& gl);
   void setupNetmasks(const YAML::Node& domain, GeoIPDomain& dom);
-  bool loadDomain(const YAML::Node& domain, std::uint32_t domainID, GeoIPDomain& dom);
+  bool loadDomain(const YAML::Node& domain, domainid_t domainID, GeoIPDomain& dom);
   void loadDomainsFromDirectory(const std::string& dir, vector<GeoIPDomain>& domains);
   vector<DNSResourceRecord> d_result;
   vector<GeoIPInterface> d_files;
index 970d4019b6e1ae783bbd4e663a25f2146d04dbdc..e5d61ce2ccf03a95e3c0eb025ecdccc71b47fd29 100644 (file)
@@ -82,15 +82,15 @@ class LdapBackend : public DNSBackend
   PowerLDAP* d_pldap;
   LdapAuthenticator* d_authenticator;
 
-  bool (LdapBackend::*d_list_fcnt)(const ZoneName&, int);
-  void (LdapBackend::*d_lookup_fcnt)(const QType&, const DNSName&, DNSPacket*, int);
+  bool (LdapBackend::*d_list_fcnt)(const ZoneName&, domainid_t);
+  void (LdapBackend::*d_lookup_fcnt)(const QType&, const DNSName&, DNSPacket*, domainid_t);
 
-  bool list_simple(const ZoneName& target, int domain_id);
-  bool list_strict(const ZoneName& target, int domain_id);
+  bool list_simple(const ZoneName& target, domainid_t domain_id);
+  bool list_strict(const ZoneName& target, domainid_t domain_id);
 
-  void lookup_simple(const QType& qtype, const DNSName& qdomain, DNSPacket* p, int zoneid);
-  void lookup_strict(const QType& qtype, const DNSName& qdomain, DNSPacket* p, int zoneid);
-  void lookup_tree(const QType& qtype, const DNSName& qdomain, DNSPacket* p, int zoneid);
+  void lookup_simple(const QType& qtype, const DNSName& qname, DNSPacket* p, domainid_t zoneid);
+  void lookup_strict(const QType& qtype, const DNSName& qname, DNSPacket* p, domainid_t zoneid);
+  void lookup_tree(const QType& qtype, const DNSName& qname, DNSPacket* p, domainid_t zoneid);
 
   bool reconnect();
 
@@ -111,13 +111,13 @@ public:
 
   // Native backend
   unsigned int getCapabilities() override { return CAP_LIST; }
-  bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
-  void lookup(const QType& qtype, const DNSName& qdomain, int zoneid, DNSPacket* p = nullptr) override;
+  bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
+  void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneid, DNSPacket* dnspkt = nullptr) override;
   bool get(DNSResourceRecord& rr) override;
 
   bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial = true) override;
 
   // Primary backend
   void getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
-  void setNotified(uint32_t id, uint32_t serial) override;
+  void setNotified(domainid_t id, uint32_t serial) override;
 };
index 427083105bb40d00195f634b6f4307cfd65db3a5..6e8ffb1674e4bcbb1869b931c007219b1d9acd28 100644 (file)
@@ -84,7 +84,7 @@ static const char* ldap_attrany[] = { // NOLINT(cppcoreguidelines-avoid-c-arrays
   "PdnsRecordOrdername",
   nullptr};
 
-bool LdapBackend::list(const ZoneName& target, int domain_id, bool /* include_disabled */)
+bool LdapBackend::list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */)
 {
   try {
     d_in_list = true;
@@ -117,7 +117,7 @@ bool LdapBackend::list(const ZoneName& target, int domain_id, bool /* include_di
   return false;
 }
 
-bool LdapBackend::list_simple(const ZoneName& target, int /* domain_id */)
+bool LdapBackend::list_simple(const ZoneName& target, domainid_t /* domain_id */)
 {
   string dn;
   string filter;
@@ -152,7 +152,7 @@ bool LdapBackend::list_simple(const ZoneName& target, int /* domain_id */)
   return true;
 }
 
-bool LdapBackend::list_strict(const ZoneName& target, int domain_id)
+bool LdapBackend::list_strict(const ZoneName& target, domainid_t domain_id)
 {
   if (target.isPartOf(DNSName("in-addr.arpa")) || target.isPartOf(DNSName("ip6.arpa"))) {
     g_log << Logger::Warning << d_myname << " Request for reverse zone AXFR, but this is not supported in strict mode" << endl;
@@ -162,7 +162,7 @@ bool LdapBackend::list_strict(const ZoneName& target, int domain_id)
   return list_simple(target, domain_id);
 }
 
-void LdapBackend::lookup(const QType& qtype, const DNSName& qname, int zoneid, DNSPacket* dnspkt)
+void LdapBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneid, DNSPacket* dnspkt)
 {
   try {
     d_in_list = false;
@@ -196,7 +196,7 @@ void LdapBackend::lookup(const QType& qtype, const DNSName& qname, int zoneid, D
   }
 }
 
-void LdapBackend::lookup_simple(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, int /* zoneid */)
+void LdapBackend::lookup_simple(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, domainid_t /* zoneid */)
 {
   string filter, attr, qesc;
   const char** attributes = ldap_attrany + 1; // skip associatedDomain
@@ -218,7 +218,7 @@ void LdapBackend::lookup_simple(const QType& qtype, const DNSName& qname, DNSPac
   d_search = d_pldap->search(getArg("basedn"), LDAP_SCOPE_SUBTREE, filter, attributes);
 }
 
-void LdapBackend::lookup_strict(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, int /* zoneid */)
+void LdapBackend::lookup_strict(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, domainid_t /* zoneid */)
 {
   int len;
   vector<string> parts;
@@ -260,7 +260,7 @@ void LdapBackend::lookup_strict(const QType& qtype, const DNSName& qname, DNSPac
   d_search = d_pldap->search(getArg("basedn"), LDAP_SCOPE_SUBTREE, filter, attributes);
 }
 
-void LdapBackend::lookup_tree(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, int /* zoneid */)
+void LdapBackend::lookup_tree(const QType& qtype, const DNSName& qname, DNSPacket* /* dnspkt */, domainid_t /* zoneid */)
 {
   string filter, attr, qesc, dn;
   const char** attributes = ldap_attrany + 1; // skip associatedDomain
@@ -424,7 +424,7 @@ bool LdapBackend::getDomainInfo(const ZoneName& domain, DomainInfo& info, bool /
     fillSOAData(result["sOARecord"][0], sd);
 
     if (result.count("PdnsDomainId") && !result["PdnsDomainId"].empty())
-      info.id = std::stoi(result["PdnsDomainId"][0]);
+      info.id = static_cast<domainid_t>(std::stoll(result["PdnsDomainId"][0]));
     else
       info.id = 0;
 
index 5f21acf89054517e509216a45c5de67e2269c576..14d8bda044e875d0fce24090ba4d4e4d5217b359 100644 (file)
@@ -71,7 +71,8 @@ void LdapBackend::getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordere
   }
 }
 
-void LdapBackend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void LdapBackend::setNotified(domainid_t id, uint32_t serial)
 {
   string filter;
   PowerLDAP::SearchResult::Ptr search;
index e0e9aacadb00156ec906e750024f007bc88c1217..a9b7e25f82e8152441fefb3adffa1c8d304704a1 100644 (file)
@@ -900,7 +900,7 @@ namespace serialization
     ar & g.last_check;
     ar & g.account;
     ar & g.primaries;
-    ar & g.id;
+    ar& static_cast<uint32_t>(g.id);
     ar & g.notified_serial;
     ar & g.kind;
     ar & g.options;
@@ -914,7 +914,9 @@ namespace serialization
     ar & g.last_check;
     ar & g.account;
     ar & g.primaries;
-    ar & g.id;
+    uint32_t domainId{0};
+    ar & domainId;
+    g.id = static_cast<domainid_t>(domainId);
     ar & g.notified_serial;
     ar & g.kind;
     if (version >= 1) {
@@ -1068,7 +1070,7 @@ static std::shared_ptr<DNSRecordContent> deserializeContentZR(uint16_t qtype, co
 #define StringView string
 #endif
 
-void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, uint32_t domain_id, uint16_t qtype)
+void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, domainid_t domain_id, uint16_t qtype)
 {
   compoundOrdername co;
   string match = co(domain_id);
@@ -1098,11 +1100,11 @@ void LMDBBackend::deleteDomainRecords(RecordsRWTransaction& txn, uint32_t domain
 
 */
 
-bool LMDBBackend::startTransaction(const ZoneName& domain, int domain_id)
+bool LMDBBackend::startTransaction(const ZoneName& domain, domainid_t domain_id)
 {
   // cout <<"startTransaction("<<domain<<", "<<domain_id<<")"<<endl;
-  int real_id = domain_id;
-  if (real_id < 0) {
+  domainid_t real_id = domain_id;
+  if (real_id == UnknownDomainID) {
     auto rotxn = d_tdomains->getROTransaction();
     DomainInfo di;
     real_id = rotxn.get<0>(domain, di);
@@ -1118,8 +1120,8 @@ bool LMDBBackend::startTransaction(const ZoneName& domain, int domain_id)
 
   d_transactiondomain = domain;
   d_transactiondomainid = real_id;
-  if (domain_id >= 0) {
-    deleteDomainRecords(*d_rwtxn, domain_id);
+  if (domain_id != UnknownDomainID) {
+    LMDBBackend::deleteDomainRecords(*d_rwtxn, domain_id);
   }
 
   return true;
@@ -1188,7 +1190,7 @@ bool LMDBBackend::feedRecord(const DNSResourceRecord& r, const DNSName& ordernam
   return true;
 }
 
-bool LMDBBackend::feedEnts(int domain_id, map<DNSName, bool>& nonterm)
+bool LMDBBackend::feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm)
 {
   LMDBResourceRecord lrr;
   lrr.ttl = 0;
@@ -1204,7 +1206,7 @@ bool LMDBBackend::feedEnts(int domain_id, map<DNSName, bool>& nonterm)
   return true;
 }
 
-bool LMDBBackend::feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+bool LMDBBackend::feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
 {
   string ser;
   DNSName ordername;
@@ -1237,7 +1239,8 @@ bool LMDBBackend::feedEnts3(int domain_id, const DNSName& domain, map<DNSName, b
 }
 
 // might be called within a transaction, might also be called alone
-bool LMDBBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool LMDBBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
 {
   // zonk qname/qtype within domain_id (go through qname, check domain_id && qtype)
   shared_ptr<RecordsRWTransaction> txn;
@@ -1284,7 +1287,8 @@ bool LMDBBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const Q
   return true;
 }
 
-bool LMDBBackend::replaceComments([[maybe_unused]] const uint32_t domain_id, [[maybe_unused]] const DNSName& qname, [[maybe_unused]] const QType& qt, const vector<Comment>& comments)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool LMDBBackend::replaceComments([[maybe_unused]] domainid_t domain_id, [[maybe_unused]] const DNSName& qname, [[maybe_unused]] const QType& qt, const vector<Comment>& comments)
 {
   // if the vector is empty, good, that's what we do here (LMDB does not store comments)
   // if it's not, report failure
@@ -1292,7 +1296,8 @@ bool LMDBBackend::replaceComments([[maybe_unused]] const uint32_t domain_id, [[m
 }
 
 // tempting to templatize these two functions but the pain is not worth it
-std::shared_ptr<LMDBBackend::RecordsRWTransaction> LMDBBackend::getRecordsRWTransaction(uint32_t id)
+// NOLINTNEXTLINE(readability-identifier-length)
+std::shared_ptr<LMDBBackend::RecordsRWTransaction> LMDBBackend::getRecordsRWTransaction(domainid_t id)
 {
   auto& shard = d_trecords[id % s_shards];
   if (!shard.env) {
@@ -1306,7 +1311,8 @@ std::shared_ptr<LMDBBackend::RecordsRWTransaction> LMDBBackend::getRecordsRWTran
   return ret;
 }
 
-std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTransaction(uint32_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn)
+// NOLINTNEXTLINE(readability-identifier-length)
+std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTransaction(domainid_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn)
 {
   auto& shard = d_trecords[id % s_shards];
   if (!shard.env) {
@@ -1403,7 +1409,7 @@ bool LMDBBackend::deleteDomain(const ZoneName& domain)
   return true;
 }
 
-bool LMDBBackend::list(const ZoneName& target, int /* id */, bool include_disabled)
+bool LMDBBackend::list(const ZoneName& target, domainid_t /* id */, bool include_disabled)
 {
   d_includedisabled = include_disabled;
 
@@ -1440,7 +1446,7 @@ bool LMDBBackend::list(const ZoneName& target, int /* id */, bool include_disabl
   return true;
 }
 
-void LMDBBackend::lookupInternal(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* /* p */, bool include_disabled)
+void LMDBBackend::lookupInternal(const QType& type, const DNSName& qdomain, domainid_t zoneId, DNSPacket* /* p */, bool include_disabled)
 {
   if (d_dolog) {
     g_log << Logger::Warning << "Got lookup for " << qdomain << "|" << type.toString() << " in zone " << zoneId << endl;
@@ -1451,13 +1457,13 @@ void LMDBBackend::lookupInternal(const QType& type, const DNSName& qdomain, int
 
   ZoneName hunt(qdomain);
   DomainInfo di;
-  if (zoneId < 0) {
+  if (zoneId == UnknownDomainID) {
     auto rotxn = d_tdomains->getROTransaction();
 
     do {
       zoneId = rotxn.get<0>(hunt, di);
-    } while (!zoneId && type != QType::SOA && hunt.chopOff());
-    if (zoneId <= 0) {
+    } while (zoneId == 0 && type != QType::SOA && hunt.chopOff());
+    if (zoneId == 0) {
       //      cout << "Did not find zone for "<< qdomain<<endl;
       d_getcursor.reset();
       return;
@@ -1659,7 +1665,8 @@ int LMDBBackend::genChangeDomain(const ZoneName& domain, const std::function<voi
   return true;
 }
 
-int LMDBBackend::genChangeDomain(uint32_t id, const std::function<void(DomainInfo&)>& func)
+// NOLINTNEXTLINE(readability-identifier-length)
+int LMDBBackend::genChangeDomain(domainid_t id, const std::function<void(DomainInfo&)>& func)
 {
   DomainInfo di;
 
@@ -1812,14 +1819,14 @@ void LMDBBackend::getUnfreshSecondaryInfos(vector<DomainInfo>* domains)
   });
 }
 
-void LMDBBackend::setStale(uint32_t domain_id)
+void LMDBBackend::setStale(domainid_t domain_id)
 {
   genChangeDomain(domain_id, [](DomainInfo& di) {
     di.last_check = 0;
   });
 }
 
-void LMDBBackend::setFresh(uint32_t domain_id)
+void LMDBBackend::setFresh(domainid_t domain_id)
 {
   genChangeDomain(domain_id, [](DomainInfo& di) {
     di.last_check = time(nullptr);
@@ -1855,7 +1862,7 @@ void LMDBBackend::getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::u
   });
 }
 
-void LMDBBackend::setNotified(uint32_t domain_id, uint32_t serial)
+void LMDBBackend::setNotified(domainid_t domain_id, uint32_t serial)
 {
   genChangeDomain(domain_id, [serial](DomainInfo& di) {
     di.notified_serial = serial;
@@ -2071,7 +2078,8 @@ bool LMDBBackend::unpublishDomainKey(const ZoneName& name, unsigned int keyId)
   return true;
 }
 
-bool LMDBBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-function-cognitive-complexity,readability-identifier-length)
+bool LMDBBackend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
 {
   //  cout << __PRETTY_FUNCTION__<< ": "<<id <<", "<<qname << " " << unhashed<<endl;
 
@@ -2290,7 +2298,7 @@ bool LMDBBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qna
   return true;
 }
 
-bool LMDBBackend::getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zonenameU, const DNSName& qname, DNSName& before, DNSName& after)
+bool LMDBBackend::getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonenameU, const DNSName& qname, DNSName& before, DNSName& after)
 {
   ZoneName zonename = zonenameU.makeLowerCase();
   //  cout << __PRETTY_FUNCTION__<< ": "<<domainId <<", "<<zonename << ", '"<<qname<<"'"<<endl;
@@ -2414,7 +2422,7 @@ bool LMDBBackend::getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zone
   return true;
 }
 
-bool LMDBBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
+bool LMDBBackend::updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
 {
   //  cout << __PRETTY_FUNCTION__<< ": "<< domain_id <<", '"<<qname <<"', '"<<ordername<<"', "<<auth<< ", " << qtype << endl;
   shared_ptr<RecordsRWTransaction> txn;
@@ -2523,7 +2531,7 @@ bool LMDBBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName
   return false;
 }
 
-bool LMDBBackend::updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
+bool LMDBBackend::updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
 {
   // cout << __PRETTY_FUNCTION__<< ": "<< domain_id << ", insert.size() "<<insert.size()<<", "<<erase.size()<<", " <<remove<<endl;
 
@@ -2541,7 +2549,7 @@ bool LMDBBackend::updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& inse
 
   // if remove is set, all ENTs should be removed & nothing else should be done
   if (remove) {
-    deleteDomainRecords(*txn, domain_id, 0);
+    LMDBBackend::deleteDomainRecords(*txn, domain_id, 0);
   }
   else {
     DomainInfo di;
@@ -2784,10 +2792,10 @@ string LMDBBackend::directBackendCmd(const string& query)
         return "can only refresh in the domains index\n";
       }
 
-      uint32_t id = 0;
+      domainid_t id = 0; // NOLINT(readability-identifier-length)
 
       try {
-        id = pdns::checked_stoi<uint32_t>(argv[3]);
+        pdns::checked_stoi_into(id, argv[3]);
       }
       catch (const std::out_of_range& e) {
         return "ID out of range\n";
index fb3ed1e927346073871102e35046e5a3c10166ab..df598aefa4237d58f592f94c5932b3623228a891 100644 (file)
@@ -69,34 +69,34 @@ public:
   ~LMDBBackend();
 
   unsigned int getCapabilities() override { return CAP_DNSSEC | CAP_DIRECT | CAP_LIST | CAP_CREATE; }
-  bool list(const ZoneName& target, int domainId, bool include_disabled) override;
+  bool list(const ZoneName& target, domainid_t domainId, bool include_disabled) override;
 
   bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getserial = true) override;
   bool createDomain(const ZoneName& domain, const DomainInfo::DomainKind kind, const vector<ComboAddress>& primaries, const string& account) override;
 
-  bool startTransaction(const ZoneName& domain, int domain_id = -1) override;
+  bool startTransaction(const ZoneName& domain, domainid_t domain_id = UnknownDomainID) override;
   bool commitTransaction() override;
   bool abortTransaction() override;
   bool feedRecord(const DNSResourceRecord& r, const DNSName& ordername, bool ordernameIsNSEC3 = false) override;
-  bool feedEnts(int domain_id, map<DNSName, bool>& nonterm) override;
-  bool feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
-  bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
-  bool replaceComments(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
+  bool feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm) override;
+  bool feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
+  bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
+  bool replaceComments(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
 
   void getAllDomains(vector<DomainInfo>* domains, bool doSerial, bool include_disabled) override;
-  void lookup(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override { lookupInternal(type, qdomain, zoneId, p, false); }
-  void APILookup(const QType& type, const DNSName& qdomain, int zoneId, bool include_disabled = false) override { lookupInternal(type, qdomain, zoneId, nullptr, include_disabled); }
+  void lookup(const QType& type, const DNSName& qdomain, domainid_t zoneId, DNSPacket* p = nullptr) override { lookupInternal(type, qdomain, zoneId, p, false); }
+  void APILookup(const QType& type, const DNSName& qdomain, domainid_t zoneId, bool include_disabled = false) override { lookupInternal(type, qdomain, zoneId, nullptr, include_disabled); }
   bool get(DNSResourceRecord& rr) override;
   bool get(DNSZoneRecord& dzr) override;
 
   // secondary support
   void getUnfreshSecondaryInfos(vector<DomainInfo>* domains) override;
-  void setStale(uint32_t domain_id) override;
-  void setFresh(uint32_t domain_id) override;
+  void setStale(domainid_t domain_id) override;
+  void setFresh(domainid_t domain_id) override;
 
   // primary support
   void getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
-  void setNotified(uint32_t id, uint32_t serial) override;
+  void setNotified(domainid_t id, uint32_t serial) override;
 
   // catalog zones
   bool getCatalogMembers(const ZoneName& catalog, vector<CatalogInfo>& members, CatalogInfo::CatalogType type) override;
@@ -143,13 +143,13 @@ public:
 
   // DNSSEC
 
-  bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+  bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
 
-  bool getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after) override;
+  bool getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after) override;
 
-  bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype = QType::ANY) override;
+  bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype = QType::ANY) override;
 
-  bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove) override;
+  bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove) override;
 
   // other
   string directBackendCmd(const string& query) override;
@@ -190,11 +190,11 @@ private:
       return operator()(rr.domain_id, rr.qname, rr.qtype.getCode());
     }
 
-    static uint32_t getDomainID(const string_view& key)
+    static domainid_t getDomainID(const string_view& key)
     {
       uint32_t ret;
       memcpy(&ret, &key[0], sizeof(ret));
-      return ntohl(ret);
+      return static_cast<domainid_t>(ntohl(ret));
     }
 
     static DNSName getQName(const string_view& key)
@@ -310,15 +310,15 @@ private:
   shared_ptr<RecordsROTransaction> d_rotxn; // for lookup and list
   shared_ptr<RecordsRWTransaction> d_rwtxn; // for feedrecord within begin/aborttransaction
   bool d_txnorder{false}; // whether d_rotxn is more recent than d_rwtxn
-  std::shared_ptr<RecordsRWTransaction> getRecordsRWTransaction(uint32_t id);
-  std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(uint32_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn = nullptr);
+  std::shared_ptr<RecordsRWTransaction> getRecordsRWTransaction(domainid_t id);
+  std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(domainid_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn = nullptr);
   int genChangeDomain(const ZoneName& domain, const std::function<void(DomainInfo&)>& func);
-  int genChangeDomain(uint32_t id, const std::function<void(DomainInfo&)>& func);
-  void deleteDomainRecords(RecordsRWTransaction& txn, uint32_t domain_id, uint16_t qtype = QType::ANY);
+  int genChangeDomain(domainid_t id, const std::function<void(DomainInfo&)>& func);
+  static void deleteDomainRecords(RecordsRWTransaction& txn, domainid_t domain_id, uint16_t qtype = QType::ANY);
 
   void getAllDomainsFiltered(vector<DomainInfo>* domains, const std::function<bool(DomainInfo&)>& allow);
 
-  void lookupInternal(const QType& type, const DNSName& qdomain, int zoneId, DNSPacket* p, bool include_disabled);
+  void lookupInternal(const QType& type, const DNSName& qdomain, domainid_t zoneId, DNSPacket* p, bool include_disabled);
   bool getSerial(DomainInfo& di);
 
   bool get_list(DNSZoneRecord& rr);
@@ -333,7 +333,7 @@ private:
   bool d_includedisabled;
 
   ZoneName d_transactiondomain;
-  uint32_t d_transactiondomainid;
+  domainid_t d_transactiondomainid;
   bool d_dolog;
   bool d_random_ids;
   bool d_handle_dups;
index 05882eaee8431ad71a61b0f87e93dc1775b2de5f..18742000b73dbfe29d33ada81ca64b9dc5b502f8 100644 (file)
@@ -35,10 +35,10 @@ private:
   typedef std::vector<std::pair<string, string>> lookup_context_t;
 
   typedef std::vector<std::pair<int, std::vector<std::pair<string, boost::variant<bool, int, DNSName, string, QType>>>>> lookup_result_t;
-  typedef std::function<lookup_result_t(const QType& qtype, const DNSName& qname, int domain_id, const lookup_context_t& ctx)> lookup_call_t;
+  typedef std::function<lookup_result_t(const QType& qtype, const DNSName& qname, domainid_t domain_id, const lookup_context_t& ctx)> lookup_call_t;
 
   typedef boost::variant<bool, lookup_result_t> list_result_t;
-  typedef std::function<list_result_t(const DNSName& qname, int domain_id)> list_call_t;
+  typedef std::function<list_result_t(const DNSName& qname, domainid_t domain_id)> list_call_t;
 
   typedef vector<pair<string, boost::variant<bool, long, string, vector<string>>>> domaininfo_result_t;
   typedef boost::variant<bool, domaininfo_result_t> get_domaininfo_result_t;
@@ -58,9 +58,9 @@ private:
 
   typedef std::vector<std::pair<string, boost::variant<string, DNSName>>> before_and_after_names_result_t;
   typedef boost::variant<bool, before_and_after_names_result_t> get_before_and_after_names_absolute_result_t;
-  typedef std::function<get_before_and_after_names_absolute_result_t(int id, const DNSName& qname)> get_before_and_after_names_absolute_call_t;
+  typedef std::function<get_before_and_after_names_absolute_result_t(domainid_t id, const DNSName& qname)> get_before_and_after_names_absolute_call_t;
 
-  typedef std::function<void(int, long)> set_notified_call_t;
+  typedef std::function<void(domainid_t, long)> set_notified_call_t;
 
   typedef std::function<string(const string& cmd)> direct_backend_cmd_call_t;
 
@@ -183,7 +183,7 @@ public:
       g_log << Logger::Debug << "[" << getPrefix() << "] Got empty result" << endl;
   }
 
-  bool list(const ZoneName& target, int domain_id, bool /* include_disabled */ = false) override
+  bool list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */ = false) override
   {
     if (f_list == nullptr) {
       g_log << Logger::Error << "[" << getPrefix() << "] dns_list missing - cannot do AXFR" << endl;
@@ -204,7 +204,7 @@ public:
     return true;
   }
 
-  void lookup(const QType& qtype, const DNSName& qname, int domain_id, DNSPacket* p = nullptr) override
+  void lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket* p = nullptr) override
   {
     if (d_result.size() != 0)
       throw PDNSException("lookup attempted while another was running");
@@ -246,12 +246,12 @@ public:
     return f(par);
   }
 
-  void setNotified(uint32_t id, uint32_t serial) override
+  void setNotified(domainid_t id, uint32_t serial) override
   {
     if (f_set_notified == NULL)
       return;
-    logCall("dns_set_notified", "id=" << static_cast<int>(id) << ",serial=" << serial);
-    f_set_notified(static_cast<int>(id), serial);
+    logCall("dns_set_notified", "id=" << id << ",serial=" << serial);
+    f_set_notified(id, serial);
   }
 
   void parseDomainInfo(const domaininfo_result_t& row, DomainInfo& di)
@@ -265,7 +265,7 @@ public:
         for (const auto& primary : boost::get<vector<string>>(item.second))
           di.primaries.push_back(ComboAddress(primary, 53));
       else if (item.first == "id")
-        di.id = static_cast<int>(boost::get<long>(item.second));
+        di.id = static_cast<domainid_t>(boost::get<long>(item.second));
       else if (item.first == "notified_serial")
         di.notified_serial = static_cast<unsigned int>(boost::get<long>(item.second));
       else if (item.first == "serial")
@@ -393,7 +393,7 @@ public:
     return true;
   }
 
-  bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override
+  bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override
   {
     if (f_get_before_and_after_names_absolute == nullptr)
       return false;
index 0f80cc916b55133aaa63d03a069a2da6e8528946..753bf96e1974bb23405d1b8123da3eb676d7ce06 100644 (file)
 #include <arpa/inet.h>
 #include "pipebackend.hh"
 
+// The following requirement guarantees UnknownDomainID will get output as "-1"
+// for compatibility.
+static_assert(std::is_signed<domainid_t>::value);
+
 static const char* kBackendId = "[PIPEBackend]";
 
 CoWrapper::CoWrapper(const string& command, int timeout, int abiVersion)
@@ -152,7 +156,7 @@ void PipeBackend::cleanup()
   d_abiVersion = 0;
 }
 
-void PipeBackend::lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* pkt_p)
+void PipeBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p)
 {
   try {
     launch();
@@ -195,7 +199,7 @@ void PipeBackend::lookup(const QType& qtype, const DNSName& qname, int zoneId, D
   d_qname = qname;
 }
 
-bool PipeBackend::list(const ZoneName& target, int domain_id, bool /* include_disabled */)
+bool PipeBackend::list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */)
 {
   try {
     launch();
index a2d270bc8eab51e8f53412a3fd121859a08b82c9..dd75e6c3da3f6ea3b00595df769d8f735539b638 100644 (file)
@@ -52,8 +52,8 @@ public:
   ~PipeBackend() override;
 
   unsigned int getCapabilities() override { return CAP_DIRECT | CAP_LIST; }
-  void lookup(const QType&, const DNSName& qdomain, int zoneId, DNSPacket* p = nullptr) override;
-  bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
+  void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
+  bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
   bool get(DNSResourceRecord& r) override;
   string directBackendCmd(const string& query) override;
   static DNSBackend* maker();
index 53804e34ab9f28d006fa4c0b560b0d0358a26318..84939731101e1a4704b6661b20e6fd104fc7c2bd 100644 (file)
 #endif
 #include "remotebackend.hh"
 
+// The following requirement guarantees UnknownDomainID will get output as "-1"
+// in the Json data for compatibility.
+static_assert(std::is_signed<domainid_t>::value);
+
+// The following requirement is a consequency of JsonInt not able to store
+// anything larger than "int".
+static_assert(sizeof(domainid_t) <= sizeof(int));
+
 static const char* kBackendId = "[RemoteBackend]";
 
 /**
@@ -193,7 +201,7 @@ int RemoteBackend::build()
  * The functions here are just remote json stubs that send and receive the method call
  * data is mainly left alone, some defaults are assumed.
  */
-void RemoteBackend::lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p)
+void RemoteBackend::lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p)
 {
   if (d_index != -1) {
     throw PDNSException("Attempt to lookup while one running");
@@ -226,7 +234,7 @@ void RemoteBackend::lookup(const QType& qtype, const DNSName& qdomain, int zoneI
 }
 
 // Similar to lookup above, but passes an extra include_disabled parameter.
-void RemoteBackend::APILookup(const QType& qtype, const DNSName& qdomain, int zoneId, bool include_disabled)
+void RemoteBackend::APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, bool include_disabled)
 {
   if (d_index != -1) {
     throw PDNSException("Attempt to lookup while one running");
@@ -252,7 +260,7 @@ void RemoteBackend::APILookup(const QType& qtype, const DNSName& qdomain, int zo
   d_index = 0;
 }
 
-bool RemoteBackend::list(const ZoneName& target, int domain_id, bool include_disabled)
+bool RemoteBackend::list(const ZoneName& target, domainid_t domain_id, bool include_disabled)
 {
   if (d_index != -1) {
     throw PDNSException("Attempt to lookup while one running");
@@ -284,7 +292,7 @@ bool RemoteBackend::get(DNSResourceRecord& rr)
   rr.qclass = QClass::IN;
   rr.content = stringFromJson(d_result["result"][d_index], "content");
   rr.ttl = d_result["result"][d_index]["ttl"].int_value();
-  rr.domain_id = intFromJson(d_result["result"][d_index], "domain_id", -1);
+  rr.domain_id = static_cast<domainid_t>(intFromJson(d_result["result"][d_index], "domain_id", UnknownDomainID));
   if (d_dnssec) {
     rr.auth = (intFromJson(d_result["result"][d_index], "auth", 1) != 0);
   }
@@ -302,7 +310,8 @@ bool RemoteBackend::get(DNSResourceRecord& rr)
   return true;
 }
 
-bool RemoteBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool RemoteBackend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
 {
   // no point doing dnssec if it's not supported
   if (!d_dnssec) {
@@ -311,7 +320,7 @@ bool RemoteBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& q
 
   Json query = Json::object{
     {"method", "getBeforeAndAfterNamesAbsolute"},
-    {"parameters", Json::object{{"id", Json(static_cast<double>(id))}, {"qname", qname.toString()}}}};
+    {"parameters", Json::object{{"id", Json(id)}, {"qname", qname.toString()}}}};
   Json answer;
 
   if (!this->send(query) || !this->recv(answer)) {
@@ -621,7 +630,7 @@ bool RemoteBackend::getTSIGKeys(std::vector<struct TSIGKey>& keys)
 
 void RemoteBackend::parseDomainInfo(const Json& obj, DomainInfo& di)
 {
-  di.id = intFromJson(obj, "id", -1);
+  di.id = static_cast<domainid_t>(intFromJson(obj, "id", UnknownDomainID));
   di.zone = ZoneName(stringFromJson(obj, "zone"));
   for (const auto& primary : obj["masters"].array_items()) {
     di.primaries.emplace_back(primary.string_value(), 53);
@@ -666,11 +675,12 @@ bool RemoteBackend::getDomainInfo(const ZoneName& domain, DomainInfo& info, bool
   return true;
 }
 
-void RemoteBackend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void RemoteBackend::setNotified(domainid_t id, uint32_t serial)
 {
   Json query = Json::object{
     {"method", "setNotified"},
-    {"parameters", Json::object{{"id", static_cast<double>(id)}, {"serial", static_cast<double>(serial)}}}};
+    {"parameters", Json::object{{"id", id}, {"serial", static_cast<double>(serial)}}}};
 
   Json answer;
   if (!this->send(query) || !this->recv(answer)) {
@@ -730,7 +740,7 @@ bool RemoteBackend::createSecondaryDomain(const string& ipAddress, const ZoneNam
   return this->send(query) && this->recv(answer);
 }
 
-bool RemoteBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qtype, const vector<DNSResourceRecord>& rrset)
+bool RemoteBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qtype, const vector<DNSResourceRecord>& rrset)
 {
   Json::array json_rrset;
   for (const auto& rr : rrset) {
@@ -745,7 +755,7 @@ bool RemoteBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const
 
   Json query = Json::object{
     {"method", "replaceRRSet"},
-    {"parameters", Json::object{{"domain_id", static_cast<double>(domain_id)}, {"qname", qname.toString()}, {"qtype", qtype.toString()}, {"trxid", static_cast<double>(d_trxid)}, {"rrset", json_rrset}}}};
+    {"parameters", Json::object{{"domain_id", domain_id}, {"qname", qname.toString()}, {"qtype", qtype.toString()}, {"trxid", static_cast<double>(d_trxid)}, {"rrset", json_rrset}}}};
 
   Json answer;
   return this->send(query) && this->recv(answer);
@@ -764,7 +774,7 @@ bool RemoteBackend::feedRecord(const DNSResourceRecord& rr, const DNSName& order
   return this->send(query) && this->recv(answer); // XXX FIXME this API should not return 'true' I think -ahu
 }
 
-bool RemoteBackend::feedEnts(int domain_id, map<DNSName, bool>& nonterm)
+bool RemoteBackend::feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm)
 {
   Json::array nts;
 
@@ -783,7 +793,7 @@ bool RemoteBackend::feedEnts(int domain_id, map<DNSName, bool>& nonterm)
   return this->send(query) && this->recv(answer);
 }
 
-bool RemoteBackend::feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+bool RemoteBackend::feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
 {
   Json::array nts;
 
@@ -802,7 +812,7 @@ bool RemoteBackend::feedEnts3(int domain_id, const DNSName& domain, map<DNSName,
   return this->send(query) && this->recv(answer);
 }
 
-bool RemoteBackend::startTransaction(const ZoneName& domain, int domain_id)
+bool RemoteBackend::startTransaction(const ZoneName& domain, domainid_t domain_id)
 {
   this->d_trxid = time((time_t*)nullptr);
 
@@ -889,7 +899,7 @@ bool RemoteBackend::searchRecords(const string& pattern, size_t maxResults, vect
     rr.qclass = QClass::IN;
     rr.content = stringFromJson(row, "content");
     rr.ttl = row["ttl"].int_value();
-    rr.domain_id = intFromJson(row, "domain_id", -1);
+    rr.domain_id = static_cast<domainid_t>(intFromJson(row, "domain_id", UnknownDomainID));
     if (d_dnssec) {
       rr.auth = (intFromJson(row, "auth", 1) != 0);
     }
@@ -977,11 +987,11 @@ void RemoteBackend::getUnfreshSecondaryInfos(vector<DomainInfo>* domains)
   }
 }
 
-void RemoteBackend::setStale(uint32_t domain_id)
+void RemoteBackend::setStale(domainid_t domain_id)
 {
   Json query = Json::object{
     {"method", "setStale"},
-    {"parameters", Json::object{{"id", static_cast<double>(domain_id)}}}};
+    {"parameters", Json::object{{"id", domain_id}}}};
 
   Json answer;
   if (!this->send(query) || !this->recv(answer)) {
@@ -989,11 +999,11 @@ void RemoteBackend::setStale(uint32_t domain_id)
   }
 }
 
-void RemoteBackend::setFresh(uint32_t domain_id)
+void RemoteBackend::setFresh(domainid_t domain_id)
 {
   Json query = Json::object{
     {"method", "setFresh"},
-    {"parameters", Json::object{{"id", static_cast<double>(domain_id)}}}};
+    {"parameters", Json::object{{"id", domain_id}}}};
 
   Json answer;
   if (!this->send(query) || !this->recv(answer)) {
index e429a78b8fdd216f9888ec9c200157e4e332e5d3..4e6774093921af2e13d6ea690362f6b34eae91c1 100644 (file)
@@ -168,16 +168,16 @@ public:
   ~RemoteBackend() override;
 
   unsigned int getCapabilities() override;
-  void lookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, DNSPacket* pkt_p = nullptr) override;
-  void APILookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, bool include_disabled = false) override;
+  void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, DNSPacket* pkt_p = nullptr) override;
+  void APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, bool include_disabled = false) override;
   bool get(DNSResourceRecord& rr) override;
-  bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
+  bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
 
   bool getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string>>& meta) override;
   bool getDomainMetadata(const ZoneName& name, const std::string& kind, std::vector<std::string>& meta) override;
   bool getDomainKeys(const ZoneName& name, std::vector<DNSBackend::KeyData>& keys) override;
   bool getTSIGKey(const DNSName& name, DNSName& algorithm, std::string& content) override;
-  bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+  bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
   bool setDomainMetadata(const ZoneName& name, const string& kind, const std::vector<std::basic_string<char>>& meta) override;
   bool removeDomainKey(const ZoneName& name, unsigned int keyId) override;
   bool addDomainKey(const ZoneName& name, const KeyData& key, int64_t& keyId) override;
@@ -186,14 +186,14 @@ public:
   bool publishDomainKey(const ZoneName& name, unsigned int keyId) override;
   bool unpublishDomainKey(const ZoneName& name, unsigned int keyId) override;
   bool getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial = true) override;
-  void setNotified(uint32_t id, uint32_t serial) override;
+  void setNotified(domainid_t id, uint32_t serial) override;
   bool autoPrimaryBackend(const string& ipAddress, const ZoneName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** ddb) override;
   bool createSecondaryDomain(const string& ipAddress, const ZoneName& domain, const string& nameserver, const string& account) override;
-  bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
+  bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
   bool feedRecord(const DNSResourceRecord& r, const DNSName& ordername, bool ordernameIsNSEC3 = false) override;
-  bool feedEnts(int domain_id, map<DNSName, bool>& nonterm) override;
-  bool feedEnts3(int domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
-  bool startTransaction(const ZoneName& domain, int domain_id) override;
+  bool feedEnts(domainid_t domain_id, map<DNSName, bool>& nonterm) override;
+  bool feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
+  bool startTransaction(const ZoneName& domain, domainid_t domain_id) override;
   bool commitTransaction() override;
   bool abortTransaction() override;
   bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content) override;
@@ -205,8 +205,8 @@ public:
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
   void getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
   void getUnfreshSecondaryInfos(vector<DomainInfo>* domains) override;
-  void setStale(uint32_t domain_id) override;
-  void setFresh(uint32_t domain_id) override;
+  void setStale(domainid_t domain_id) override;
+  void setFresh(domainid_t domain_id) override;
 
   static DNSBackend* maker();
 
index ec9664e4a146da7bfe1f5615eeaf272ef5b6235d..41c842752fbcd773578b4d6277589646e6d6fd63 100644 (file)
@@ -28,7 +28,7 @@
 #include <utility>
 
 static string backendname = "[TinyDNSBackend] ";
-uint32_t TinyDNSBackend::s_lastId;
+domainid_t TinyDNSBackend::s_lastId;
 LockGuarded<TinyDNSBackend::TDI_suffix_t> TinyDNSBackend::s_domainInfo;
 
 vector<string> TinyDNSBackend::getLocations()
@@ -131,7 +131,8 @@ void TinyDNSBackend::getUpdatedPrimaries(vector<DomainInfo>& retDomains, std::un
   }
 }
 
-void TinyDNSBackend::setNotified(uint32_t id, uint32_t serial)
+// NOLINTNEXTLINE(readability-identifier-length)
+void TinyDNSBackend::setNotified(domainid_t id, uint32_t serial)
 {
   auto domainInfo = s_domainInfo.lock();
   if (!domainInfo->count(d_suffix)) {
@@ -171,7 +172,7 @@ void TinyDNSBackend::getAllDomains_locked(vector<DomainInfo>* domains, bool getS
   while (get(rr)) {
     if (rr.qtype.getCode() == QType::SOA && dupcheck.insert(rr.qname).second) {
       DomainInfo di;
-      di.id = -1; // Will be overridden by caller
+      di.id = UnknownDomainID; // Will be overridden by caller
       di.backend = this;
       di.zone = ZoneName(rr.qname);
       di.kind = DomainInfo::Primary;
@@ -240,7 +241,7 @@ bool TinyDNSBackend::getDomainInfo(const ZoneName& domain, DomainInfo& di, bool
   return found;
 }
 
-bool TinyDNSBackend::list(const ZoneName& target, int /* domain_id */, bool /* include_disabled */)
+bool TinyDNSBackend::list(const ZoneName& target, domainid_t /* domain_id */, bool /* include_disabled */)
 {
   d_isAxfr = true;
   d_isGetDomains = false;
@@ -256,7 +257,7 @@ bool TinyDNSBackend::list(const ZoneName& target, int /* domain_id */, bool /* i
   return d_cdbReader->searchSuffix(key);
 }
 
-void TinyDNSBackend::lookup(const QType& qtype, const DNSName& qdomain, int /* zoneId */, DNSPacket* pkt_p)
+void TinyDNSBackend::lookup(const QType& qtype, const DNSName& qdomain, domainid_t /* zoneId */, DNSPacket* pkt_p)
 {
   d_isAxfr = false;
   d_isGetDomains = false;
index b7477c7ebb7c2db3f3f8cf6b86a5cf60be920795..9b1df972770f21e587cd7d3072db18864518ddb0 100644 (file)
@@ -38,7 +38,7 @@ using namespace ::boost::multi_index;
 
 struct TinyDomainInfo
 {
-  uint32_t id;
+  domainid_t id;
   uint32_t notified_serial;
   ZoneName zone;
 
@@ -69,15 +69,15 @@ public:
   TinyDNSBackend(const string& suffix);
 
   unsigned int getCapabilities() override { return CAP_LIST; }
-  void lookup(const QType& qtype, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p = nullptr) override;
-  bool list(const ZoneName& target, int domain_id, bool include_disabled = false) override;
+  void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
+  bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
   bool get(DNSResourceRecord& rr) override;
   bool getDomainInfo(const ZoneName& domain, DomainInfo& di, bool getSerial = true) override;
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
 
   // Primary mode operation
   void getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
-  void setNotified(uint32_t id, uint32_t serial) override;
+  void setNotified(domainid_t id, uint32_t serial) override;
 
 private:
   //TypeDefs
@@ -91,7 +91,7 @@ private:
     TinyDomainInfo,
     indexed_by<
       hashed_unique<tag<tag_zone>, member<TinyDomainInfo, ZoneName, &TinyDomainInfo::zone>>,
-      hashed_unique<tag<tag_domainid>, member<TinyDomainInfo, uint32_t, &TinyDomainInfo::id>>>>
+      hashed_unique<tag<tag_domainid>, member<TinyDomainInfo, domainid_t, &TinyDomainInfo::id>>>>
     TDI_t;
   typedef map<string, TDI_t> TDI_suffix_t;
   typedef TDI_t::index<tag_zone>::type TDIByZone_t;
@@ -115,5 +115,5 @@ private:
 
   // Statics
   static LockGuarded<TDI_suffix_t> s_domainInfo;
-  static uint32_t s_lastId; // used to give a domain an id.
+  static domainid_t s_lastId; // used to give a domain an id.
 };
index 9f76d8913bda7eedf17c9f196761d3e34042fe07..6e35c3a0076487659fb67d0bcd52a767f39edbe4 100644 (file)
@@ -53,7 +53,6 @@ void CommunicatorClass::queueNotifyDomain(const DomainInfo& di, UeberBackend* B)
 
   try {
     if (d_onlyNotify.size()) {
-      // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
       B->lookup(QType(QType::NS), di.zone.operator const DNSName&(), di.id);
       while (B->get(rr))
         nsset.insert(getRR<NSRecordContent>(rr.dr)->getNS());
@@ -170,7 +169,7 @@ void CommunicatorClass::getUpdatedProducers(UeberBackend* B, vector<DomainInfo>&
 
         DNSResourceRecord rr;
         makeIncreasedSOARecord(sd, "EPOCH", "", rr);
-        di.backend->startTransaction(ZoneName(sd.qname), -1);
+        di.backend->startTransaction(ZoneName(sd.qname), UnknownDomainID);
         if (!di.backend->replaceRRSet(di.id, rr.qname, rr.qtype, vector<DNSResourceRecord>(1, rr))) {
           di.backend->abortTransaction();
           throw PDNSException("backend hosting producer zone '" + sd.qname.toLogString() + "' does not support editing records");
index 05a3679fe134ee5b6d5e76b2025085daa67819fb..2463d5d803ed9ea2a9b544e45a1629cfe0cf5539 100644 (file)
@@ -479,12 +479,11 @@ void CommunicatorClass::ixfrSuck(const ZoneName& domain, const TSIGTriplet& tsig
       for (const auto& x : add)
         grouped[{ZoneName(x.d_name), x.d_type}].second.push_back(x);
 
-      di.backend->startTransaction(domain, -1);
+      di.backend->startTransaction(domain, UnknownDomainID);
       for (const auto& g : grouped) {
         vector<DNSRecord> rrset;
         {
           DNSZoneRecord zrr;
-          // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
           di.backend->lookup(QType(g.first.second), g.first.first.operator const DNSName&() + domain.operator const DNSName&(), di.id);
           while (di.backend->get(zrr)) {
             zrr.dr.d_name.makeUsRelative(domain);
@@ -946,7 +945,6 @@ void CommunicatorClass::suck(const ZoneName& domain, const ComboAddress& remote,
     // Insert empty non-terminals
     if (doent && !nonterm.empty()) {
       if (zs.isNSEC3) {
-        // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
         di.backend->feedEnts3(zs.domain_id, domain.operator const DNSName&(), nonterm, zs.ns3pr, zs.isNarrow);
       }
       else
@@ -1316,7 +1314,6 @@ void CommunicatorClass::secondaryRefresh(PacketHandler* P)
     SOAData sd;
     try {
       // Use UeberBackend cache for SOA. Cache gets cleared after AXFR/IXFR.
-      // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
       B->lookup(QType(QType::SOA), di.zone.operator const DNSName&(), di.id, nullptr);
       DNSZoneRecord zr;
       hasSOA = B->get(zr);
@@ -1340,7 +1337,6 @@ void CommunicatorClass::secondaryRefresh(PacketHandler* P)
     else if (hasSOA && theirserial == ourserial) {
       uint32_t maxExpire = 0, maxInception = 0;
       if (checkSignatures && dk.isPresigned(di.zone)) {
-        // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
         B->lookup(QType(QType::RRSIG), di.zone.operator const DNSName&(), di.id); // can't use DK before we are done with this lookup!
         DNSZoneRecord zr;
         while (B->get(zr)) {
index 10aea8ed5f524a7869687b56c51943ce0dd26937..6d12caf937267073477514d4d3e2a03362556b6b 100644 (file)
@@ -208,7 +208,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
   d_SearchCommentsQuery_stmt = nullptr;
 }
 
-void GSQLBackend::setNotified(uint32_t domain_id, uint32_t serial)
+void GSQLBackend::setNotified(domainid_t domain_id, uint32_t serial)
 {
   try {
     reconnectIfNeeded();
@@ -226,7 +226,7 @@ void GSQLBackend::setNotified(uint32_t domain_id, uint32_t serial)
   }
 }
 
-void GSQLBackend::setLastCheck(uint32_t domain_id, time_t lastcheck)
+void GSQLBackend::setLastCheck(domainid_t domain_id, time_t lastcheck)
 {
   try {
     reconnectIfNeeded();
@@ -243,12 +243,12 @@ void GSQLBackend::setLastCheck(uint32_t domain_id, time_t lastcheck)
   }
 }
 
-void GSQLBackend::setStale(uint32_t domain_id)
+void GSQLBackend::setStale(domainid_t domain_id)
 {
   setLastCheck(domain_id, 0);
 }
 
-void GSQLBackend::setFresh(uint32_t domain_id)
+void GSQLBackend::setFresh(domainid_t domain_id)
 {
   setLastCheck(domain_id, time(nullptr));
 }
@@ -731,7 +731,7 @@ bool GSQLBackend::getCatalogMembers(const ZoneName& catalog, vector<CatalogInfo>
   return true;
 }
 
-bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
+bool GSQLBackend::updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype)
 {
   if(!d_dnssecQueries)
     return false;
@@ -812,7 +812,7 @@ bool GSQLBackend::updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName
   return true;
 }
 
-bool GSQLBackend::updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
+bool GSQLBackend::updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert, set<DNSName>& erase, bool remove)
 {
   if(remove) {
     try {
@@ -880,7 +880,8 @@ unsigned int GSQLBackend::getCapabilities()
   return caps;
 }
 
-bool GSQLBackend::getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool GSQLBackend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
 {
   if(!d_dnssecQueries)
     return false;
@@ -1406,13 +1407,13 @@ bool GSQLBackend::setDomainMetadata(const ZoneName& name, const std::string& kin
   return true;
 }
 
-void GSQLBackend::lookup(const QType& qtype, const DNSName& qname, int domain_id, DNSPacket* /* pkt_p */)
+void GSQLBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket* /* pkt_p */)
 {
   try {
     reconnectIfNeeded();
 
     if(qtype.getCode()!=QType::ANY) {
-      if(domain_id < 0) {
+      if(domain_id == UnknownDomainID) {
         d_query_name = "basic-query";
         d_query_stmt = &d_NoIdQuery_stmt;
         // clang-format off
@@ -1432,7 +1433,7 @@ void GSQLBackend::lookup(const QType& qtype, const DNSName& qname, int domain_id
       }
     } else {
       // qtype==ANY
-      if(domain_id < 0) {
+      if(domain_id == UnknownDomainID) {
         d_query_name = "any-query";
         d_query_stmt = &d_ANYNoIdQuery_stmt;
         // clang-format off
@@ -1461,7 +1462,7 @@ void GSQLBackend::lookup(const QType& qtype, const DNSName& qname, int domain_id
   d_qname=qname;
 }
 
-void GSQLBackend::APILookup(const QType& qtype, const DNSName& qname, int domain_id, bool include_disabled)
+void GSQLBackend::APILookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, bool include_disabled)
 {
   try {
     reconnectIfNeeded();
@@ -1499,7 +1500,7 @@ void GSQLBackend::APILookup(const QType& qtype, const DNSName& qname, int domain
   d_qname=qname;
 }
 
-bool GSQLBackend::list(const ZoneName &target, int domain_id, bool include_disabled)
+bool GSQLBackend::list(const ZoneName &target, domainid_t domain_id, bool include_disabled)
 {
   DLOG(g_log<<"GSQLBackend constructing handle for list of domain id '"<<domain_id<<"'"<<endl);
 
@@ -1525,7 +1526,7 @@ bool GSQLBackend::list(const ZoneName &target, int domain_id, bool include_disab
   return true;
 }
 
-bool GSQLBackend::listSubZone(const ZoneName &zone, int domain_id) {
+bool GSQLBackend::listSubZone(const ZoneName &zone, domainid_t domain_id) {
 
   string wildzone = "%." + zone.makeLowerCase().toStringNoDot();
 
@@ -1878,7 +1879,8 @@ void GSQLBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, boo
   }
 }
 
-bool GSQLBackend::replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool GSQLBackend::replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset)
 {
   try {
     reconnectIfNeeded();
@@ -1991,7 +1993,7 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord& r, const DNSName& ordernam
   return true; // XXX FIXME this API should not return 'true' I think -ahu
 }
 
-bool GSQLBackend::feedEnts(int domain_id, map<DNSName,bool>& nonterm)
+bool GSQLBackend::feedEnts(domainid_t domain_id, map<DNSName,bool>& nonterm)
 {
   for(const auto& nt: nonterm) {
     try {
@@ -2014,7 +2016,7 @@ bool GSQLBackend::feedEnts(int domain_id, map<DNSName,bool>& nonterm)
   return true;
 }
 
-bool GSQLBackend::feedEnts3(int domain_id, const DNSName& /* domain */, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
+bool GSQLBackend::feedEnts3(domainid_t domain_id, const DNSName& /* domain */, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow)
 {
   if(!d_dnssecQueries)
       return false;
@@ -2056,7 +2058,7 @@ bool GSQLBackend::feedEnts3(int domain_id, const DNSName& /* domain */, map<DNSN
   return true;
 }
 
-bool GSQLBackend::startTransaction(const ZoneName &domain, int domain_id)
+bool GSQLBackend::startTransaction(const ZoneName &domain, domainid_t domain_id)
 {
   try {
     reconnectIfNeeded();
@@ -2066,7 +2068,7 @@ bool GSQLBackend::startTransaction(const ZoneName &domain, int domain_id)
     }
     d_db->startTransaction();
     d_inTransaction = true;
-    if(domain_id >= 0) {
+    if(domain_id != UnknownDomainID) {
       // clang-format off
       d_DeleteZoneQuery_stmt->
         bind("domain_id", domain_id)->
@@ -2109,7 +2111,7 @@ bool GSQLBackend::abortTransaction()
   return true;
 }
 
-bool GSQLBackend::listComments(const uint32_t domain_id)
+bool GSQLBackend::listComments(const domainid_t domain_id)
 {
   try {
     reconnectIfNeeded();
@@ -2183,7 +2185,8 @@ bool GSQLBackend::feedComment(const Comment& comment)
   return true;
 }
 
-bool GSQLBackend::replaceComments(const uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments)
+// NOLINTNEXTLINE(readability-identifier-length)
+bool GSQLBackend::replaceComments(const domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments)
 {
   try {
     reconnectIfNeeded();
index 1b492c524ee4a4e513a76f932db9d021b12cbe6b..6829f05ed5e8c64cce32e0288d5216b1b89fec26 100644 (file)
@@ -199,17 +199,17 @@ protected:
 
 public:
   unsigned int getCapabilities() override;
-  void lookup(const QType &, const DNSName &qdomain, int zoneId, DNSPacket *p=nullptr) override;
-  void APILookup(const QType &qtype, const DNSName &qname, int domain_id, bool include_disabled = false) override;
-  bool list(const ZoneName &target, int domain_id, bool include_disabled=false) override;
+  void lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket *p=nullptr) override;
+  void APILookup(const QType &qtype, const DNSName &qname, domainid_t domain_id, bool include_disabled = false) override;
+  bool list(const ZoneName &target, domainid_t domain_id, bool include_disabled=false) override;
   bool get(DNSResourceRecord &r) override;
   void getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool include_disabled) override;
-  bool startTransaction(const ZoneName &domain, int domain_id=-1) override;
+  bool startTransaction(const ZoneName &domain, domainid_t domain_id=UnknownDomainID) override;
   bool commitTransaction() override;
   bool abortTransaction() override;
   bool feedRecord(const DNSResourceRecord &r, const DNSName &ordername, bool ordernameIsNSEC3=false) override;
-  bool feedEnts(int domain_id, map<DNSName,bool>& nonterm) override;
-  bool feedEnts3(int domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
+  bool feedEnts(domainid_t domain_id, map<DNSName,bool>& nonterm) override;
+  bool feedEnts3(domainid_t domain_id, const DNSName &domain, map<DNSName,bool> &nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
   bool createDomain(const ZoneName& domain, const DomainInfo::DomainKind kind, const vector<ComboAddress>& primaries, const string& account) override;
   bool createSecondaryDomain(const string& ipAddress, const ZoneName& domain, const string& nameserver, const string& account) override;
   bool deleteDomain(const ZoneName &domain) override;
@@ -217,26 +217,26 @@ public:
   bool autoPrimaryRemove(const AutoPrimary& primary) override;
   bool autoPrimariesList(std::vector<AutoPrimary>& primaries) override;
   bool autoPrimaryBackend(const string& ipAddress, const ZoneName& domain, const vector<DNSResourceRecord>& nsset, string* nameserver, string* account, DNSBackend** db) override;
-  void setStale(uint32_t domain_id) override;
-  void setFresh(uint32_t domain_id) override;
+  void setStale(domainid_t domain_id) override;
+  void setFresh(domainid_t domain_id) override;
   void getUnfreshSecondaryInfos(vector<DomainInfo>* domains) override;
   void getUpdatedPrimaries(vector<DomainInfo>& updatedDomains, std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes) override;
   bool getCatalogMembers(const ZoneName& catalog, vector<CatalogInfo>& members, CatalogInfo::CatalogType type) override;
   bool getDomainInfo(const ZoneName &domain, DomainInfo &info, bool getSerial=true) override;
-  void setNotified(uint32_t domain_id, uint32_t serial) override;
+  void setNotified(domainid_t domain_id, uint32_t serial) override;
   bool setPrimaries(const ZoneName& domain, const vector<ComboAddress>& primaries) override;
   bool setKind(const ZoneName &domain, const DomainInfo::DomainKind kind) override;
   bool setOptions(const ZoneName& domain, const string& options) override;
   bool setCatalog(const ZoneName& domain, const ZoneName& catalog) override;
   bool setAccount(const ZoneName &domain, const string &account) override;
 
-  bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
-  bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t=QType::ANY) override;
+  bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
+  bool updateDNSSECOrderNameAndAuth(domainid_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t=QType::ANY) override;
 
-  bool updateEmptyNonTerminals(uint32_t domain_id, set<DNSName>& insert ,set<DNSName>& erase, bool remove) override;
+  bool updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& insert ,set<DNSName>& erase, bool remove) override;
 
-  bool replaceRRSet(uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
-  bool listSubZone(const ZoneName &zone, int domain_id) override;
+  bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
+  bool listSubZone(const ZoneName &zone, domainid_t domain_id) override;
   bool addDomainKey(const ZoneName& name, const KeyData& key, int64_t& id) override;
   bool getDomainKeys(const ZoneName& name, std::vector<KeyData>& keys) override;
   bool getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string> >& meta) override;
@@ -254,10 +254,10 @@ public:
   bool deleteTSIGKey(const DNSName& name) override;
   bool getTSIGKeys(std::vector< struct TSIGKey > &keys) override;
 
-  bool listComments(const uint32_t domain_id) override;
+  bool listComments(const domainid_t domain_id) override;
   bool getComment(Comment& comment) override;
   bool feedComment(const Comment& comment) override;
-  bool replaceComments(const uint32_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
+  bool replaceComments(const domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
   string directBackendCmd(const string &query) override;
   bool searchRecords(const string &pattern, size_t maxResults, vector<DNSResourceRecord>& result) override;
   bool searchComments(const string &pattern, size_t maxResults, vector<Comment>& result) override;
@@ -266,7 +266,7 @@ protected:
   string pattern2SQLPattern(const string& pattern);
   void extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& rr);
   void extractComment(SSqlStatement::row_t& row, Comment& c);
-  void setLastCheck(uint32_t domain_id, time_t lastcheck);
+  void setLastCheck(domainid_t domain_id, time_t lastcheck);
   bool isConnectionUsable() {
     if (d_db) {
       return d_db->isConnectionUsable();
index b121e1c5166f307d0d375598c83948c9ed4bea73..f802e131c5e0fb14d18b4e15cd9b63877b7e5cf8 100644 (file)
@@ -33,6 +33,6 @@ public:
   string account; //!< account last updating this comment
   string content; //!< The actual comment. Example: blah blah
 
-  int domain_id{0};
+  domainid_t domain_id{0};
   QType qtype; //!< qtype of the associated RRset, ie A, CNAME, MX etc
 };
index 908fe8e09137a05065c202c3950ada8b57997433..77c70bfc103b3f058e1f8dad717b91a366411cf1 100644 (file)
@@ -835,7 +835,7 @@ bool DNSSECKeeper::rectifyZone(const ZoneName& zone, string& error, string& info
   }
 
   if (doTransaction)
-    sd.db->startTransaction(zone, -1);
+    sd.db->startTransaction(zone, UnknownDomainID);
 
   bool realrr=true;
   bool doent=true;
index b8dd761673c2311932af6a56f9f05c69a1df2dca..b12559dfcbfd74d6126388190d79b5bd38385201 100644 (file)
@@ -52,6 +52,13 @@ public:
   static std::string to_s(uint8_t opcode);
 };
 
+// This needs to be a signed type, so that serialization of UnknownDomainID
+// as text is "-1", for compatibility with the remote and pipe backends.
+// See static_assert there for details.
+using domainid_t = int32_t;
+
+constexpr domainid_t UnknownDomainID{-1};
+
 //! This class represents a resource record
 class DNSResourceRecord
 {
@@ -83,7 +90,7 @@ public:
   uint32_t ttl{}; //!< Time To Live of this record
   uint32_t signttl{}; //!< If non-zero, use this TTL as original TTL in the RRSIG
 
-  int domain_id{-1}; //!< If a backend implements this, the domain_id of the zone this record is in
+  domainid_t domain_id{UnknownDomainID}; //!< If a backend implements this, the domain_id of the zone this record is in
   QType qtype; //!< qtype of this record, ie A, CNAME, MX etc
   uint16_t qclass{1}; //!< class of this record
 
index 50b83a5f336ee130277af41655353b631eea4024..24fb970e2de21b9b485803fc0aa00d0548e2b8cd 100644 (file)
@@ -68,7 +68,7 @@ int DNSBackend::getArgAsNum(const string& key)
 }
 
 // Default API lookup has no support for disabled records and simply wraps lookup()
-void DNSBackend::APILookup(const QType& qtype, const DNSName& qdomain, int zoneId, bool /* include_disabled */)
+void DNSBackend::APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, bool /* include_disabled */)
 {
   lookup(qtype, qdomain, zoneId, nullptr);
 }
@@ -306,7 +306,7 @@ bool DNSBackend::get(DNSZoneRecord& zoneRecord)
   return true;
 }
 
-bool DNSBackend::getBeforeAndAfterNames(uint32_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after)
+bool DNSBackend::getBeforeAndAfterNames(domainid_t domainId, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after)
 {
   DNSName unhashed;
   bool ret = this->getBeforeAndAfterNamesAbsolute(domainId, qname.makeRelative(zonename).makeLowerCase(), unhashed, before, after);
index 246d1a36c3dc7b7f7b4797e85247df5c47c2828e..99d03776f757eafb519b688088b02d2c5e7e382c 100644 (file)
@@ -62,7 +62,7 @@ struct DomainInfo
   vector<ComboAddress> primaries;
   DNSBackend* backend{};
 
-  uint32_t id{};
+  domainid_t id{};
   uint32_t notified_serial{};
 
   bool receivedNotify{};
@@ -168,8 +168,8 @@ public:
   virtual unsigned int getCapabilities() = 0;
 
   //! lookup() initiates a lookup. A lookup without results should not throw!
-  virtual void lookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, DNSPacket* pkt_p = nullptr) = 0;
-  virtual void APILookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, bool include_disabled = false);
+  virtual void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, DNSPacket* pkt_p = nullptr) = 0;
+  virtual void APILookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId = UnknownDomainID, bool include_disabled = false);
   virtual bool get(DNSResourceRecord&) = 0; //!< retrieves one DNSResource record, returns false if no more were available
   virtual bool get(DNSZoneRecord& zoneRecord);
 
@@ -178,19 +178,19 @@ public:
       if the backend does not consider itself responsible for the id passed.
       \param domain_id ID of which a list is requested
   */
-  virtual bool list(const ZoneName& target, int domain_id, bool include_disabled = false) = 0;
+  virtual bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) = 0;
 
   virtual ~DNSBackend() = default;
 
   //! fills the soadata struct with the SOA details. Returns false if there is no SOA.
   virtual bool getSOA(const ZoneName& domain, SOAData& soaData);
 
-  virtual bool replaceRRSet(uint32_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<DNSResourceRecord>& /* rrset */)
+  virtual bool replaceRRSet(domainid_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<DNSResourceRecord>& /* rrset */)
   {
     return false;
   }
 
-  virtual bool listSubZone(const ZoneName& /* zone */, int /* domain_id */)
+  virtual bool listSubZone(const ZoneName& /* zone */, domainid_t /* domain_id */)
   {
     return false;
   }
@@ -248,19 +248,19 @@ public:
   virtual bool getTSIGKeys(std::vector<struct TSIGKey>& /* keys */) { return false; }
   virtual bool deleteTSIGKey(const DNSName& /* name */) { return false; }
 
-  virtual bool getBeforeAndAfterNamesAbsolute(uint32_t /* id */, const DNSName& qname, DNSName& /* unhashed */, DNSName& /* before */, DNSName& /* after */)
+  virtual bool getBeforeAndAfterNamesAbsolute(domainid_t /* id */, const DNSName& qname, DNSName& /* unhashed */, DNSName& /* before */, DNSName& /* after */)
   {
     throw PDNSException("DNSSEC operation invoked on non-DNSSEC capable backend, qname: '" + qname.toLogString() + "'");
   }
 
-  virtual bool getBeforeAndAfterNames(uint32_t /* id */, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after);
+  virtual bool getBeforeAndAfterNames(domainid_t /* id */, const ZoneName& zonename, const DNSName& qname, DNSName& before, DNSName& after);
 
-  virtual bool updateDNSSECOrderNameAndAuth(uint32_t /* domain_id */, const DNSName& /* qname */, const DNSName& /* ordername */, bool /* auth */, const uint16_t /* qtype */ = QType::ANY)
+  virtual bool updateDNSSECOrderNameAndAuth(domainid_t /* domain_id */, const DNSName& /* qname */, const DNSName& /* ordername */, bool /* auth */, const uint16_t /* qtype */ = QType::ANY)
   {
     return false;
   }
 
-  virtual bool updateEmptyNonTerminals(uint32_t /* domain_id */, set<DNSName>& /* insert */, set<DNSName>& /* erase */, bool /* remove */)
+  virtual bool updateEmptyNonTerminals(domainid_t /* domain_id */, set<DNSName>& /* insert */, set<DNSName>& /* erase */, bool /* remove */)
   {
     return false;
   }
@@ -273,7 +273,7 @@ public:
   // end DNSSEC
 
   // comments support
-  virtual bool listComments(uint32_t /* domain_id */)
+  virtual bool listComments(domainid_t /* domain_id */)
   {
     return false; // unsupported by this backend
   }
@@ -288,18 +288,18 @@ public:
     return false;
   }
 
-  virtual bool replaceComments(const uint32_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<Comment>& /* comments */)
+  virtual bool replaceComments(const domainid_t /* domain_id */, const DNSName& /* qname */, const QType& /* qt */, const vector<Comment>& /* comments */)
   {
     return false;
   }
 
   //! returns true if primary ip is primary for domain name.
   //! starts the transaction for updating domain qname, destroying all
-  //! existing data for that domain if id is >= 0. In this case, the id MUST
-  //! match the DomainInfo information for qname, or very bad things will
-  //! happen.
+  //! existing data for that domain if id is != UnknownDomainID. In this case,
+  //! the id MUST match the DomainInfo information for qname, or very bad things
+  //! will happen.
   //! FIXME: replace this with a bool to make this a less error-prone interface.
-  virtual bool startTransaction(const ZoneName& /* qname */, int /* id */ = -1)
+  virtual bool startTransaction(const ZoneName& /* qname */, domainid_t /* id */ = UnknownDomainID)
   {
     return false;
   }
@@ -334,11 +334,11 @@ public:
   {
     return false; // no problem!
   }
-  virtual bool feedEnts(int /* domain_id */, map<DNSName, bool>& /* nonterm */)
+  virtual bool feedEnts(domainid_t /* domain_id */, map<DNSName, bool>& /* nonterm */)
   {
     return false;
   }
-  virtual bool feedEnts3(int /* domain_id */, const DNSName& /* domain */, map<DNSName, bool>& /* nonterm */, const NSEC3PARAMRecordContent& /* ns3prc */, bool /* narrow */)
+  virtual bool feedEnts3(domainid_t /* domain_id */, const DNSName& /* domain */, map<DNSName, bool>& /* nonterm */, const NSEC3PARAMRecordContent& /* ns3prc */, bool /* narrow */)
   {
     return false;
   }
@@ -373,17 +373,17 @@ public:
   }
 
   //! Called by PowerDNS to inform a backend that a domain need to be checked for freshness
-  virtual void setStale(uint32_t /* domain_id */)
+  virtual void setStale(domainid_t /* domain_id */)
   {
   }
 
   //! Called by PowerDNS to inform a backend that a domain has been checked for freshness
-  virtual void setFresh(uint32_t /* domain_id */)
+  virtual void setFresh(domainid_t /* domain_id */)
   {
   }
 
   //! Called by PowerDNS to inform a backend that the changes in the domain have been reported to secondaries
-  virtual void setNotified(uint32_t /* id */, uint32_t /* serial */)
+  virtual void setNotified(domainid_t /* id */, uint32_t /* serial */)
   {
   }
 
@@ -548,7 +548,7 @@ public:
 struct SOAData
 {
   SOAData() :
-    domain_id(-1) {};
+    domain_id(UnknownDomainID) {};
 
   DNSName qname;
   DNSName nameserver;
@@ -560,7 +560,7 @@ struct SOAData
   uint32_t expire{};
   uint32_t minimum{};
   DNSBackend* db{};
-  int domain_id{};
+  domainid_t domain_id{};
 
   [[nodiscard]] uint32_t getNegativeTTL() const { return min(ttl, minimum); }
 };
index 8b3264dcea47d6bb7d08a9e2d4a1a14201337c63..947ba6c77c5193d3233a920245ee6f9c32fad333 100644 (file)
@@ -444,7 +444,7 @@ public:
 
 struct DNSZoneRecord
 {
-  int domain_id{-1};
+  domainid_t domain_id{UnknownDomainID};
   uint8_t scopeMask{0};
   int signttl{0};
   DNSName wildcardname;
index 05e3f76d16695c86dc62756b46769f74fcacf6f5..d2bdd492047c4124333edc28bce1a0a1a686e639 100644 (file)
@@ -223,7 +223,7 @@ public:
   bool TSIGGrantsAccess(const ZoneName& zone, const DNSName& keyname);
   bool getTSIGForAccess(const ZoneName& zone, const ComboAddress& primary, DNSName* keyname);
 
-  void startTransaction(const ZoneName& zone, int zone_id)
+  void startTransaction(const ZoneName& zone, domainid_t zone_id)
   {
     (*d_keymetadb->backends.begin())->startTransaction(zone, zone_id);
   }
index ed8f530a1554ced904612405cf3a94f025fc10d4..fc799117396ef88c5b2387a5515b31c396587b14 100644 (file)
@@ -1115,7 +1115,6 @@ int PacketHandler::tryAutoPrimarySynchronous(const DNSPacket& p, const DNSName&
       g_log << Logger::Error << "Failed to create " << zonename << " for potential autoprimary " << remote << endl;
       return RCode::ServFail;
     }
-    // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
     g_zoneCache.add(zonename, di.id);
     if (tsigkeyname.empty() == false) {
       vector<string> meta;
index 7559a3b75d5842a7939e635c030e05773cbdeddb..9ec564d4434af5775234a2d2874c60a39819ba3b 100644 (file)
@@ -908,7 +908,7 @@ static int checkAllZones(DNSSECKeeper &dk, bool exitOnError)
     DomainInfo,
     indexed_by<
       ordered_non_unique< member<DomainInfo,ZoneName,&DomainInfo::zone>, CanonZoneNameCompare >,
-      ordered_non_unique< member<DomainInfo,uint32_t,&DomainInfo::id> >
+      ordered_non_unique< member<DomainInfo,domainid_t,&DomainInfo::id> >
     >
   > seenInfos;
   auto& seenNames = seenInfos.get<0>();
@@ -979,7 +979,7 @@ static int increaseSerial(const ZoneName& zone, DNSSECKeeper &dsk)
   DNSResourceRecord rr;
   makeIncreasedSOARecord(sd, "SOA-EDIT-INCREASE", soaEditKind, rr);
 
-  sd.db->startTransaction(zone, -1);
+  sd.db->startTransaction(zone, UnknownDomainID);
 
   auto rrs = vector<DNSResourceRecord>{rr};
   if (!sd.db->replaceRRSet(sd.domain_id, zone.operator const DNSName&(), rr.qtype, rrs)) {
@@ -1018,7 +1018,7 @@ static int deleteZone(const ZoneName &zone) {
     return EXIT_FAILURE;
   }
 
-  di.backend->startTransaction(zone, -1);
+  di.backend->startTransaction(zone, UnknownDomainID);
   try {
     if(di.backend->deleteDomain(zone)) {
       di.backend->commitTransaction();
@@ -1477,7 +1477,7 @@ static int editZone(const ZoneName &zone, const PDNSColors& col) {
   else if(changed.empty() || c!='a')
     goto reAsk2;
 
-  di.backend->startTransaction(zone, -1);
+  di.backend->startTransaction(zone, UnknownDomainID);
   for(const auto& change : changed) {
     vector<DNSResourceRecord> vrr;
     for(const DNSRecord& rr : grouped[change.first]) {
@@ -1706,7 +1706,7 @@ static int addOrReplaceRecord(bool isAdd, const vector<string>& cmds) {
     }
   }
 
-  di.backend->startTransaction(zone, -1);
+  di.backend->startTransaction(zone, UnknownDomainID);
 
   // Enforce that CNAME records can not be mixed with any other.
   // If we add a CNAME: there should be no existing records except for one
@@ -1856,7 +1856,7 @@ static int deleteRRSet(const std::string& zone_, const std::string& name_, const
     name=DNSName(name_)+zone.operator const DNSName&();
 
   QType qt(QType::chartocode(type_.c_str()));
-  di.backend->startTransaction(zone, -1);
+  di.backend->startTransaction(zone, UnknownDomainID);
   di.backend->replaceRRSet(di.id, name, qt, vector<DNSResourceRecord>());
   di.backend->commitTransaction();
   return EXIT_SUCCESS;
@@ -2265,7 +2265,6 @@ static bool showZone(DNSSECKeeper& dnsseckeeper, const ZoneName& zone, bool expo
     vector<DNSKEYRecordContent> keys;
     DNSZoneRecord zr;
 
-    // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
     di.backend->lookup(QType(QType::DNSKEY), zone.operator const DNSName&(), di.id );
     while(di.backend->get(zr)) {
       keys.push_back(*getRR<DNSKEYRecordContent>(zr.dr));
@@ -2520,7 +2519,6 @@ static int testSchema(DNSSECKeeper& dsk, const ZoneName& zone)
   cout<<"Committing"<<endl;
   db->commitTransaction();
   cout<<"Querying TXT"<<endl;
-  // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
   db->lookup(QType(QType::TXT), zone.operator const DNSName&(), di.id);
   if(db->get(rrget))
   {
@@ -3357,7 +3355,7 @@ static int secureZone(vector<string>& cmds, const std::string_view synopsis)
   unsigned int zoneErrors=0;
   for(unsigned int n = 1; n < cmds.size(); ++n) { // NOLINT(readability-identifier-length)
     ZoneName zone(cmds.at(n));
-    dk.startTransaction(zone, -1);
+    dk.startTransaction(zone, UnknownDomainID);
     if(secureZone(dk, zone)) {
       mustRectify.push_back(std::move(zone));
     } else {
@@ -4368,17 +4366,14 @@ static int B2BMigrate(vector<string>& cmds, const std::string_view synopsis)
       throw PDNSException("Failed to create zone");
     }
     // move records
-    // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
     if (!src->list(di.zone, di.id, true)) {
       throw PDNSException("Failed to list records");
     }
     nr=0;
 
-    // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
     tgt->startTransaction(di.zone, di_new.id);
 
     while(src->get(rr)) {
-      // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
       rr.domain_id = di_new.id;
       if (!tgt->feedRecord(rr, DNSName())) {
         throw PDNSException("Failed to feed record");
@@ -4394,7 +4389,6 @@ static int B2BMigrate(vector<string>& cmds, const std::string_view synopsis)
       }
       Comment c; // NOLINT(readability-identifier-length)
       while(src->getComment(c)) {
-        // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
         c.domain_id = di_new.id;
         if (!tgt->feedComment(c)) {
           throw PDNSException("Failed to feed zone comments");
index 23a970060383644cbd40f010189fcbf76330ca89..30ca1b917c3d75f76578613e12d01abba0910271 100644 (file)
@@ -277,7 +277,6 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
             break;
 
           bool foundShorter = false;
-          // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
           di->backend->lookup(QType(QType::ANY), shorter.operator const DNSName&(), di->id);
           while (di->backend->get(rec)) {
             if (rec.qname == rr->d_name && rec.qtype == QType::DS)
@@ -339,7 +338,6 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
         DLOG(g_log<<msgPrefix<<"Going to fix auth flags below "<<rr->d_name<<endl);
         insnonterm.clear(); // No ENT's are needed below delegates (auth=0)
         vector<DNSName> qnames;
-        // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
         di->backend->listSubZone(ZoneName(rr->d_name), di->id);
         while(di->backend->get(rec)) {
           if (rec.qtype.getCode() && rec.qtype.getCode() != QType::DS && rr->d_name != rec.qname) // Skip ENT, DS and our already corrected record.
@@ -439,7 +437,6 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
       // If we've removed a delegate, we need to reset ordername/auth for some records.
       if (rrType == QType::NS && rr->d_name != di->zone.operator const DNSName&()) { 
         vector<DNSName> belowOldDelegate, nsRecs, updateAuthFlag;
-        // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
         di->backend->listSubZone(ZoneName(rr->d_name), di->id);
         while (di->backend->get(rec)) {
           if (rec.qtype.getCode()) // skip ENT records, they are always auth=false
@@ -481,7 +478,6 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
       // on that level. If so, we must insert an ENT record.
       // We take extra care here to not 'include' the record that we just deleted. Some backends will still return it as they only reload on a commit.
       bool foundDeeper = false, foundOtherWithSameName = false;
-      // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
       di->backend->listSubZone(ZoneName(rr->d_name), di->id);
       while (di->backend->get(rec)) {
         if (rec.qname == rr->d_name && !count(recordsToDelete.begin(), recordsToDelete.end(), rec))
@@ -793,7 +789,7 @@ int PacketHandler::processUpdate(DNSPacket& packet) { // NOLINT(readability-func
 
   std::lock_guard<std::mutex> l(s_rfc2136lock); //TODO: i think this lock can be per zone, not for everything
   g_log<<Logger::Info<<msgPrefix<<"starting transaction."<<endl;
-  if (!di.backend->startTransaction(zonename, -1)) { // Not giving the domain_id means that we do not delete the existing records.
+  if (!di.backend->startTransaction(zonename, UnknownDomainID)) { // Not giving the domain_id means that we do not delete the existing records.
     g_log<<Logger::Error<<msgPrefix<<"Backend for domain "<<zonename<<" does not support transaction. Can't do Update packet."<<endl;
     return RCode::NotImp;
   }
@@ -971,7 +967,6 @@ int PacketHandler::processUpdate(DNSPacket& packet) { // NOLINT(readability-func
     if (nsRRtoDelete.size()) {
       vector<DNSResourceRecord> nsRRInZone;
       DNSResourceRecord rec;
-      // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
       di.backend->lookup(QType(QType::NS), di.zone.operator const DNSName&(), di.id);
       while (di.backend->get(rec)) {
         nsRRInZone.push_back(rec);
index 50d22b9318b52b3ef7d6941999481ecb2b265d9f..4181c22b4089b09f8006d85a123824bab3829e1e 100644 (file)
@@ -55,12 +55,12 @@ public:
 
   struct SimpleDNSZone
   {
-    SimpleDNSZone(ZoneName name, uint64_t domainId): d_records(std::make_shared<RecordStorage>()), d_name(std::move(name)), d_id(domainId)
+    SimpleDNSZone(ZoneName name, domainid_t domainId): d_records(std::make_shared<RecordStorage>()), d_name(std::move(name)), d_id(domainId)
     {
     }
     std::shared_ptr<RecordStorage> d_records;
     ZoneName d_name;
-    uint64_t d_id;
+    domainid_t d_id;
   };
 
   struct HashedNameTag {};
@@ -69,7 +69,7 @@ public:
   typedef multi_index_container<
     SimpleDNSZone,
     indexed_by <
-      ordered_unique<tag<IDTag>, member<SimpleDNSZone, uint64_t, &SimpleDNSZone::d_id> >,
+      ordered_unique<tag<IDTag>, member<SimpleDNSZone, domainid_t, &SimpleDNSZone::d_id> >,
       hashed_unique<tag<HashedNameTag>, member<SimpleDNSZone, ZoneName, &SimpleDNSZone::d_name> >
       >
     > ZoneStorage;
@@ -103,18 +103,18 @@ public:
 
   // Initialize our backend ID from the suffix, skipping the '-' that DNSBackend adds there
   SimpleBackend(const std::string& suffix) :
-    d_suffix(suffix), d_backendId(pdns::checked_stoi<decltype(d_backendId)>(suffix.substr(1)))
+    d_suffix(suffix), d_backendId(pdns::checked_stoi<domainid_t>(suffix.substr(1)))
   {
   }
 
   unsigned int getCapabilities() override { return CAP_LIST; }
 
-  bool findZone(const ZoneName& qdomain, int zoneId, std::shared_ptr<RecordStorage>& records, uint64_t& currentZoneId) const
+  bool findZone(const ZoneName& qdomain, domainid_t zoneId, std::shared_ptr<RecordStorage>& records, domainid_t& currentZoneId) const
   {
-    currentZoneId = -1;
+    currentZoneId = UnknownDomainID;
     records.reset();
 
-    if (zoneId != -1) {
+    if (zoneId != UnknownDomainID) {
       const auto& idx = boost::multi_index::get<IDTag>(s_zones.at(d_backendId));
       auto it = idx.find(zoneId);
       if (it == idx.end()) {
@@ -136,7 +136,7 @@ public:
     return true;
   }
 
-  void lookup(const QType& qtype, const DNSName& qdomain, int zoneId = -1, DNSPacket *pkt_p = nullptr) override
+  void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket *pkt_p) override
   {
     d_currentScopeMask = 0;
     findZone(ZoneName(qdomain), zoneId, d_records, d_currentZone);
@@ -189,7 +189,7 @@ public:
     return true;
   }
 
-  bool list(const ZoneName& target, int zoneId, bool /* include_disabled */ = false) override
+  bool list(const ZoneName& target, domainid_t zoneId, bool /* include_disabled */) override
   {
     findZone(target, zoneId, d_records, d_currentZone);
 
@@ -228,16 +228,16 @@ public:
   }
 
   /* this is not thread-safe */
-  static std::unordered_map<uint64_t, ZoneStorage> s_zones;
-  static std::unordered_map<uint64_t, MetaDataStorage> s_metadata;
+  static std::unordered_map<domainid_t, ZoneStorage> s_zones;
+  static std::unordered_map<domainid_t, MetaDataStorage> s_metadata;
 
 protected:
   std::string d_suffix;
   std::shared_ptr<RecordStorage> d_records{nullptr};
   RecordStorage::index<OrderedNameTypeTag>::type::const_iterator d_iter;
   RecordStorage::index<OrderedNameTypeTag>::type::const_iterator d_end;
-  const uint64_t d_backendId;
-  uint64_t d_currentZone{0};
+  const domainid_t d_backendId; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
+  domainid_t d_currentZone{0}; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
   uint8_t d_currentScopeMask{0};
 };
 
@@ -257,8 +257,8 @@ public:
     if (target.isPartOf(best)) {
       /* return the best SOA right away */
       std::shared_ptr<RecordStorage> records;
-      uint64_t zoneId;
-      if (!findZone(best, -1, records, zoneId)) {
+      domainid_t zoneId{0};
+      if (!findZone(best, UnknownDomainID, records, zoneId)) {
         return false;
       }
 
@@ -299,8 +299,8 @@ public:
   }
 };
 
-std::unordered_map<uint64_t, SimpleBackend::ZoneStorage> SimpleBackend::s_zones;
-std::unordered_map<uint64_t, SimpleBackend::MetaDataStorage> SimpleBackend::s_metadata;
+std::unordered_map<domainid_t, SimpleBackend::ZoneStorage> SimpleBackend::s_zones;
+std::unordered_map<domainid_t, SimpleBackend::MetaDataStorage> SimpleBackend::s_metadata;
 
 class SimpleBackendFactory : public BackendFactory
 {
@@ -429,7 +429,8 @@ static void testWithoutThenWithZoneCache(std::function<void(UeberBackend& ub)> f
 
 BOOST_FIXTURE_TEST_SUITE(test_ueberbackend_cc, UeberBackendSetupArgFixture)
 
-static std::vector<DNSZoneRecord> getRecords(UeberBackend& ub, const DNSName& name, uint16_t qtype, int zoneId, const DNSPacket* pkt)
+// NOLINTNEXTLINE(readability-identifier-length)
+static std::vector<DNSZoneRecord> getRecords(UeberBackend& ub, const DNSName& name, uint16_t qtype, domainid_t zoneId, const DNSPacket* pkt)
 {
   std::vector<DNSZoneRecord> result;
 
@@ -444,7 +445,7 @@ static std::vector<DNSZoneRecord> getRecords(UeberBackend& ub, const DNSName& na
   return result;
 }
 
-static void checkRecordExists(const std::vector<DNSZoneRecord>& records, const DNSName& name, uint16_t type, int zoneId, uint8_t scopeMask, bool auth)
+static void checkRecordExists(const std::vector<DNSZoneRecord>& records, const DNSName& name, uint16_t type, domainid_t zoneId, uint8_t scopeMask, bool auth)
 {
   BOOST_REQUIRE_GE(records.size(), 1U);
   for (const auto& record : records) {
@@ -475,30 +476,30 @@ BOOST_AUTO_TEST_CASE(test_simple) {
 
     auto testFunction = [](UeberBackend& ub) -> void {
     {
-      // test SOA with unknown zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+      // test SOA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
     }
 
     {
-      // test ANY with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+      // test ANY with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 2U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
       checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
     }
 
     {
-      // test AAAA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+      // test AAAA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
     }
 
     {
-      // test NODATA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+      // test NODATA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 0U);
     }
 
@@ -588,46 +589,46 @@ BOOST_AUTO_TEST_CASE(test_multi_backends_separate_zones) {
 
     auto testFunction = [](UeberBackend& ub) -> void {
     {
-      // test SOA with unknown zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+      // test SOA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
 
-      records = getRecords(ub, DNSName("powerdns.org."), QType::SOA, -1, nullptr);
+      records = getRecords(ub, DNSName("powerdns.org."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.org."), QType::SOA, 2, 0, true);
     }
 
     {
-      // test ANY with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+      // test ANY with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 2U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
       checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
 
-      records = getRecords(ub, DNSName("powerdns.org."), QType::ANY, -1, nullptr);
+      records = getRecords(ub, DNSName("powerdns.org."), QType::ANY, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 2U);
       checkRecordExists(records, DNSName("powerdns.org."), QType::SOA, 2, 0, true);
       checkRecordExists(records, DNSName("powerdns.org."), QType::AAAA, 2, 0, true);
     }
 
     {
-      // test AAAA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+      // test AAAA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
 
-      records = getRecords(ub, DNSName("powerdns.org."), QType::AAAA, -1, nullptr);
+      records = getRecords(ub, DNSName("powerdns.org."), QType::AAAA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.org."), QType::AAAA, 2, 0, true);
     }
 
     {
-      // test NODATA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+      // test NODATA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 0U);
 
-      records = getRecords(ub, DNSName("powerdns.org."), QType::PTR, -1, nullptr);
+      records = getRecords(ub, DNSName("powerdns.org."), QType::PTR, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 0U);
     }
 
@@ -733,15 +734,15 @@ BOOST_AUTO_TEST_CASE(test_multi_backends_overlay) {
 
     auto testFunction = [](UeberBackend& ub) -> void {
     {
-      // test SOA with unknown zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+      // test SOA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
     }
 
     {
-      // test ANY with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+      // test ANY with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
       // /!\ only 3 records are returned since we don't allow spreading the same name over several backends
       BOOST_REQUIRE_EQUAL(records.size(), 3U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
@@ -751,16 +752,16 @@ BOOST_AUTO_TEST_CASE(test_multi_backends_overlay) {
     }
 
     {
-      // test AAAA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+      // test AAAA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
       // /!\ the AAAA will be found on an exact search, but not on an ANY one
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
     }
 
     {
-      // test NODATA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+      // test NODATA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 0U);
     }
 
@@ -860,15 +861,15 @@ BOOST_AUTO_TEST_CASE(test_multi_backends_overlay_name) {
 
     auto testFunction = [](UeberBackend& ub) -> void {
     {
-      // test SOA with unknown zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+      // test SOA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
     }
 
     {
-      // test ANY with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+      // test ANY with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 5U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 1, 0, true);
       checkRecordExists(records, DNSName("powerdns.com."), QType::NS, 1, 0, true);
@@ -877,15 +878,15 @@ BOOST_AUTO_TEST_CASE(test_multi_backends_overlay_name) {
     }
 
     {
-      // test AAAA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, -1, nullptr);
+      // test AAAA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::AAAA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::AAAA, 1, 0, true);
     }
 
     {
-      // test NODATA with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, -1, nullptr);
+      // test NODATA with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::PTR, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 0U);
     }
 
@@ -984,19 +985,19 @@ BOOST_AUTO_TEST_CASE(test_child_zone) {
 
     auto testFunction = [](UeberBackend& ub) -> void {
     {
-      // test SOA with unknown zone id == -1
-      auto records = getRecords(ub, DNSName("com."), QType::SOA, -1, nullptr);
+      // test SOA with unknown zone id
+      auto records = getRecords(ub, DNSName("com."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("com."), QType::SOA, 1, 0, true);
 
-      records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, -1, nullptr);
+      records = getRecords(ub, DNSName("powerdns.com."), QType::SOA, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 1U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 2, 0, true);
     }
 
     {
-      // test ANY with zone id == -1
-      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, -1, nullptr);
+      // test ANY with unknown zone id
+      auto records = getRecords(ub, DNSName("powerdns.com."), QType::ANY, UnknownDomainID, nullptr);
       BOOST_REQUIRE_EQUAL(records.size(), 3U);
       checkRecordExists(records, DNSName("powerdns.com."), QType::SOA, 2, 0, true);
       checkRecordExists(records, DNSName("powerdns.com."), QType::NS, 2, 0, true);
index fc3d54b22c5c60fa065b546d0b2a4bcfc6844606..295cecbb7fdbc4a39a69230c654dcffd0554920c 100644 (file)
@@ -1997,7 +1997,7 @@ static void apiServerZonesPOST(HttpRequest* req, HttpResponse* resp)
     throw ApiException("Creating domain '" + zonename.toString() + "' failed: lookup of domain ID failed");
   }
 
-  domainInfo.backend->startTransaction(zonename, static_cast<int>(domainInfo.id));
+  domainInfo.backend->startTransaction(zonename, domainInfo.id);
 
   // will be overridden by updateDomainSettingsFromDocument, if given in document.
   domainInfo.backend->setDomainMetadataOne(zonename, "SOA-EDIT-API", "DEFAULT");
@@ -2144,7 +2144,7 @@ static void apiServerZoneDetailPUT(HttpRequest* req, HttpResponse* resp)
 
     checkNewRecords(new_records, zoneData.zoneName);
 
-    zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, static_cast<int>(zoneData.domainInfo.id));
+    zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, zoneData.domainInfo.id);
     for (auto& resourceRecord : new_records) {
       resourceRecord.domain_id = static_cast<int>(zoneData.domainInfo.id);
       zoneData.domainInfo.backend->feedRecord(resourceRecord, DNSName());
@@ -2160,7 +2160,7 @@ static void apiServerZoneDetailPUT(HttpRequest* req, HttpResponse* resp)
   }
   else {
     // avoid deleting current zone contents
-    zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, -1);
+    zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, UnknownDomainID);
   }
 
   // updateDomainSettingsFromDocument will rectify the zone and update SOA serial.
@@ -2179,7 +2179,7 @@ static void apiServerZoneDetailDELETE(HttpRequest* req, HttpResponse* resp)
 
   // delete domain
 
-  zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, -1);
+  zoneData.domainInfo.backend->startTransaction(zoneData.zoneName, UnknownDomainID);
   try {
     if (!zoneData.domainInfo.backend->deleteDomain(zoneData.zoneName)) {
       throw ApiException("Deleting domain '" + zoneData.zoneName.toString() + "' failed: backend delete failed/unsupported");