]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Correctly handle reconnection in several routines. 16225/head
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 9 Oct 2025 08:40:52 +0000 (10:40 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 9 Oct 2025 09:18:53 +0000 (11:18 +0200)
If the search failed with a LDAPNoConnection exception and reconnection
is successful, we would recurse to reiterate the operation, but then would
proceed with the exist logic operating on uninitialized data.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/ldapbackend/native.cc
modules/ldapbackend/primary.cc

index f56496906a27b3da8b51a76ac999d6b63fbf2894..b971d3c2b3f06295ae746d554648174ff53e4e51 100644 (file)
@@ -100,10 +100,10 @@ bool LdapBackend::list(const ZoneName& target, domainid_t domain_id, bool /* inc
   }
   catch (LDAPNoConnection& lnc) {
     g_log << Logger::Warning << d_myname << " Connection to LDAP lost, trying to reconnect" << endl;
-    if (reconnect())
-      this->list(target, domain_id);
-    else
-      throw PDNSException("Failed to reconnect to LDAP server");
+    if (reconnect()) {
+      return this->list(target, domain_id);
+    }
+    throw PDNSException("Failed to reconnect to LDAP server");
   }
   catch (LDAPException& le) {
     g_log << Logger::Error << d_myname << " Unable to get zone " << target << " from LDAP directory: " << le.what() << endl;
@@ -183,10 +183,11 @@ void LdapBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t zo
   }
   catch (LDAPNoConnection& lnc) {
     g_log << Logger::Warning << d_myname << " Connection to LDAP lost, trying to reconnect" << endl;
-    if (reconnect())
+    if (reconnect()) {
       this->lookup(qtype, qname, zoneid, dnspkt);
-    else
-      throw PDNSException("Failed to reconnect to LDAP server");
+      return;
+    }
+    throw PDNSException("Failed to reconnect to LDAP server");
   }
   catch (LDAPException& le) {
     g_log << Logger::Error << d_myname << " Unable to search LDAP directory: " << le.what() << endl;
@@ -413,10 +414,10 @@ bool LdapBackend::getDomainInfo(const ZoneName& domain, DomainInfo& info, bool /
   }
   catch (LDAPNoConnection& lnc) {
     g_log << Logger::Warning << d_myname << " Connection to LDAP lost, trying to reconnect" << endl;
-    if (reconnect())
-      this->getDomainInfo(domain, info);
-    else
-      throw PDNSException("Failed to reconnect to LDAP server");
+    if (reconnect()) {
+      return this->getDomainInfo(domain, info);
+    }
+    throw PDNSException("Failed to reconnect to LDAP server");
   }
   catch (LDAPException& le) {
     g_log << Logger::Error << d_myname << " Unable to search LDAP directory: " << le.what() << endl;
index 14d8bda044e875d0fce24090ba4d4e4d5217b359..d53af02b5a0086a13a0d70ac900cc2a3bbb3c386 100644 (file)
@@ -44,10 +44,10 @@ void LdapBackend::getUpdatedPrimaries(vector<DomainInfo>& domains, std::unordere
   }
   catch (LDAPNoConnection& lnc) {
     g_log << Logger::Warning << d_myname << " Connection to LDAP lost, trying to reconnect" << endl;
-    if (reconnect())
-      this->getUpdatedPrimaries(domains, catalogs, catalogHashes);
-    else
-      throw PDNSException("Failed to reconnect to LDAP server");
+    if (reconnect()) {
+      return this->getUpdatedPrimaries(domains, catalogs, catalogHashes);
+    }
+    throw PDNSException("Failed to reconnect to LDAP server");
   }
   catch (LDAPException& le) {
     g_log << Logger::Error << d_myname << " Unable to search LDAP directory: " << le.what() << endl;
@@ -92,10 +92,11 @@ void LdapBackend::setNotified(domainid_t id, uint32_t serial)
   }
   catch (LDAPNoConnection& lnc) {
     g_log << Logger::Warning << d_myname << " Connection to LDAP lost, trying to reconnect" << endl;
-    if (reconnect())
+    if (reconnect()) {
       this->setNotified(id, serial);
-    else
-      throw PDNSException("Failed to reconnect to LDAP server");
+      return;
+    }
+    throw PDNSException("Failed to reconnect to LDAP server");
   }
   catch (LDAPException& le) {
     g_log << Logger::Error << d_myname << " Unable to search LDAP directory: " << le.what() << endl;
@@ -129,10 +130,11 @@ void LdapBackend::setNotified(domainid_t id, uint32_t serial)
   }
   catch (LDAPNoConnection& lnc) {
     g_log << Logger::Warning << d_myname << " Connection to LDAP lost, trying to reconnect" << endl;
-    if (reconnect())
+    if (reconnect()) {
       this->setNotified(id, serial);
-    else
-      throw PDNSException("Failed to reconnect to LDAP server");
+      return;
+    }
+    throw PDNSException("Failed to reconnect to LDAP server");
   }
   catch (LDAPException& le) {
     g_log << Logger::Error << d_myname << " Unable to search LDAP directory: " << le.what() << endl;