]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
More strict ENABLE_GSS_TSIG #ifdefs and checking of g_doGSSTSIG.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 2 Sep 2022 10:39:32 +0000 (12:39 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 2 Sep 2022 12:22:48 +0000 (14:22 +0200)
In some (low level) code, g_doGSSTSIG cannot be used as the code is shared betwen various executables,
but the functionality should be conditional in the higher level processing.

This is a bit tricky to get right, so carefull checks needed.

pdns/auth-main.cc
pdns/auth-main.hh
pdns/distributor.hh
pdns/dnspacket.cc
pdns/gss_context.hh
pdns/packethandler.cc
pdns/rfc2136handler.cc
pdns/tcpreceiver.cc
pdns/test-distributor_hh.cc
pdns/tkey.cc

index 0d7f13335d20610a2498b146e99b4cf6533c3386..0d52c79328d19b0b164a77b3043628a01c20a503 100644 (file)
@@ -109,7 +109,9 @@ int g_luaRecordExecLimit;
 time_t g_luaHealthChecksInterval{5};
 time_t g_luaHealthChecksExpireDelay{3600};
 #endif
+#ifdef ENABLE_GSS_TSIG
 bool g_doGssTSIG;
+#endif
 typedef Distributor<DNSPacket, DNSPacket, PacketHandler> DNSDistributor;
 
 ArgvMap theArg;
@@ -326,7 +328,9 @@ void declareArguments()
   ::arg().setSwitch("consistent-backends", "Assume individual zones are not divided over backends. Send only ANY lookup operations to the backend to reduce the number of lookups") = "yes";
 
   ::arg().set("rng", "Specify the random number generator to use. Valid values are auto,sodium,openssl,getrandom,arc4random,urandom.") = "auto";
+#ifdef ENABLE_GSS_TSIG
   ::arg().setSwitch("enable-gss-tsig", "Enable GSS TSIG processing") = "no";
+#endif
   ::arg().setDefaults();
 }
 
@@ -699,7 +703,9 @@ void mainthread()
   g_luaHealthChecksInterval = ::arg().asNum("lua-health-checks-interval");
   g_luaHealthChecksExpireDelay = ::arg().asNum("lua-health-checks-expire-delay");
 #endif
+#ifdef ENABLE_GSS_TSIG
   g_doGssTSIG = ::arg().mustDo("enable-gss-tsig");
+#endif
 
   DNSPacket::s_udpTruncationThreshold = std::max(512, ::arg().asNum("udp-truncation-threshold"));
   DNSPacket::s_doEDNSSubnetProcessing = ::arg().mustDo("edns-subnet-processing");
index de840cc0d426f711104e51af426198f1e63de1df..83fb0c8f4af2d48b26f716bfad5e93427c691397 100644 (file)
@@ -60,5 +60,4 @@ extern bool g_doLuaRecord;
 extern bool g_LuaRecordSharedState;
 extern time_t g_luaHealthChecksInterval;
 extern time_t g_luaHealthChecksExpireDelay;
-extern bool g_doGssTSIG;
 #endif // HAVE_LUA_RECORDS
index bba617cbcacb9cc24509e93e6d42408d10b1589c..2f52454ac435cccd120c2690b53f4a3625875d80 100644 (file)
@@ -38,6 +38,7 @@
 #include "arguments.hh"
 #include <atomic>
 #include "statbag.hh"
+#include "gss_context.hh"
 
 extern StatBag S;
 
@@ -249,7 +250,7 @@ retry:
 
       QD->callback(a, QD->start);
 #ifdef ENABLE_GSS_TSIG
-      if (a != nullptr) {
+      if (g_doGssTSIG && a != nullptr) {
         QD->Q.cleanupGSS(a->d.rcode);
       }
 #endif
@@ -315,7 +316,7 @@ retry:
   }
   callback(a, start);
 #ifdef ENABLE_GSS_TSIG
-  if (a != nullptr) {
+  if (g_doGssTSIG && a != nullptr) {
     q.cleanupGSS(a->d.rcode);
   }
 #endif
index aa43d337e1744668384976d36803b1987e062494..1a7de51ed55231c9e062e8ff4cbbf8187933123c 100644 (file)
@@ -763,6 +763,8 @@ const DNSName& DNSPacket::getTSIGKeyname() const {
 #ifdef ENABLE_GSS_TSIG
 void DNSPacket::cleanupGSS(int rcode)
 {
+  // We cannot check g_doGssTSIG here, as this code is also included in other executables
+  // than pdns_server.
   if (rcode != RCode::NoError && d_tsig_algo == TSIG_GSS && !getTSIGKeyname().empty()) {
     GssContext ctx(getTSIGKeyname());
     ctx.destroy();
index 659df9d2f0766290b22179201d1ff2763187e941..4c746befab51d86730d36a8ffdda6f7ee30b4777 100644 (file)
@@ -32,6 +32,7 @@
 #ifdef ENABLE_GSS_TSIG
 #include <gssapi/gssapi.h>
 #include <gssapi/gssapi_krb5.h>
+extern bool g_doGssTSIG;
 #endif
 
 //! Generic errors
index d74efbd1dd43b34490f6e99b368cd071886b01b5..f24f7f3988500b3839ac1f937d2055ac4af46905 100644 (file)
@@ -1379,12 +1379,14 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
       return r;
     } else {
       getTSIGHashEnum(trc.d_algoName, p.d_tsig_algo);
+#ifdef ENABLE_GSS_TSIG
       if (g_doGssTSIG && p.d_tsig_algo == TSIG_GSS) {
         GssContext gssctx(keyname);
         if (!gssctx.getPeerPrincipal(p.d_peer_principal)) {
           g_log<<Logger::Warning<<"Failed to extract peer principal from GSS context with keyname '"<<keyname<<"'"<<endl;
         }
       }
+#endif
     }
     p.setTSIGDetails(trc, keyname, secret, trc.d_mac); // this will get copied by replyPacket()
     noCache=true;
index 3692857e85316972acf6c4b1b513b2e56138fdd7..80b8fa308169528fff3ffcb376b47c3cb2fce3be 100644 (file)
@@ -695,7 +695,7 @@ int PacketHandler::processUpdate(DNSPacket& p) {
         g_log<<Logger::Error<<msgPrefix<<"TSIG key required, but packet does not contain key. Sending REFUSED"<<endl;
         return RCode::Refused;
       }
-
+#ifdef ENABLE_GSS_TSIG
       if (g_doGssTSIG && p.d_tsig_algo == TSIG_GSS) {
         GssName inputname(p.d_peer_principal); // match against principal since GSS requires that
         for(const auto& key: tsigKeys) {
@@ -704,7 +704,10 @@ int PacketHandler::processUpdate(DNSPacket& p) {
             break;
           }
         }
-      } else {
+      }
+      else
+#endif
+        {
         for(const auto& key: tsigKeys) {
           if (inputkey == DNSName(key)) { // because checkForCorrectTSIG has already been performed earlier on, if the name of the key matches with the domain given it is valid.
             validKey=true;
index 81fb0097f2ab7e403b9f24e70c6331774906bae8..47a1c29ba159efd67f3886bcc92041079ea3cbf7 100644 (file)
@@ -411,7 +411,9 @@ void TCPNameserver::doConnection(int fd)
 
       sendPacket(reply, fd);
 #ifdef ENABLE_GSS_TSIG
-      packet->cleanupGSS(reply->d.rcode);
+      if (g_doGssTSIG) {
+        packet->cleanupGSS(reply->d.rcode);
+      }
 #endif
     }
   }
@@ -459,15 +461,18 @@ bool TCPNameserver::canDoAXFR(std::unique_ptr<DNSPacket>& q, bool isAXFR, std::u
       return false;
     } else {
       getTSIGHashEnum(trc.d_algoName, q->d_tsig_algo);
+#ifdef ENABLE_GSS_TSIG
       if (g_doGssTSIG && q->d_tsig_algo == TSIG_GSS) {
         GssContext gssctx(keyname);
         if (!gssctx.getPeerPrincipal(q->d_peer_principal)) {
           g_log<<Logger::Warning<<"Failed to extract peer principal from GSS context with keyname '"<<keyname<<"'"<<endl;
         }
       }
+#endif
     }
 
     DNSSECKeeper dk(packetHandler->getBackend());
+#ifdef ENABLE_GSS_TSIG
     if (g_doGssTSIG && q->d_tsig_algo == TSIG_GSS) {
       vector<string> princs;
       packetHandler->getBackend()->getDomainMetadata(q->qdomain, "GSS-ALLOW-AXFR-PRINCIPAL", princs);
@@ -480,6 +485,7 @@ bool TCPNameserver::canDoAXFR(std::unique_ptr<DNSPacket>& q, bool isAXFR, std::u
       g_log<<Logger::Warning<<"AXFR of domain '"<<q->qdomain<<"' denied: TSIG signed request with principal '"<<q->d_peer_principal<<"' and algorithm 'gss-tsig' is not permitted"<<endl;
       return false;
     }
+#endif
     if(!dk.TSIGGrantsAccess(q->qdomain, keyname)) {
       g_log<<Logger::Warning<<logPrefix<<"denied: key with name '"<<keyname<<"' and algorithm '"<<getTSIGAlgoName(q->d_tsig_algo)<<"' does not grant access"<<endl;
       return false;
index 61cdf43a3263903f8e282a803b7692615931a451..d094668c3942db49e064c1a60149d83f955593ab 100644 (file)
@@ -8,7 +8,9 @@
 #include <boost/test/unit_test.hpp>
 #include "distributor.hh"
 #include "dnspacket.hh"
-#include "namespaces.hh" 
+#include "namespaces.hh"
+
+bool g_doGssTSIG = false;
 
 BOOST_AUTO_TEST_SUITE(test_distributor_hh)
 
index 143ff69ae944f58124f2c0aacec40dd24e2a1247..f7f439afa4c4635fb0dff3fa7088b7d97bb5161b 100644 (file)
@@ -32,6 +32,7 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
   tkey_out->d_expiration = tkey_out->d_inception+15;
 
   if (tkey_in.d_mode == 3) { // establish context
+#ifdef ENABLE_GSS_TSIG
     if (g_doGssTSIG) {
       if (tkey_in.d_algo == DNSName("gss-tsig.")) {
         std::vector<std::string> meta;
@@ -59,7 +60,9 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
       } else {
         tkey_out->d_error = 21; // BADALGO
       }
-    } else {
+    } else
+#endif
+      {
       tkey_out->d_error = 21; // BADALGO
 #ifdef ENABLE_GSS_TSIG
       g_log<<Logger::Error<<"GSS-TSIG request but feature not enabled by enable-gss-tsigs setting"<<endl;