]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/tkey.cc
Merge pull request #8223 from PowerDNS/omoerbeek-patch-1
[thirdparty/pdns.git] / pdns / tkey.cc
index f0d3c88b52d259ffdecc3bdbbd17003f6a4268af..b8d9ce893e3fda1908350760bb4c908cc0c55f6a 100644 (file)
@@ -6,35 +6,33 @@
 void PacketHandler::tkeyHandler(DNSPacket *p, DNSPacket *r) {
   TKEYRecordContent tkey_in;
   std::shared_ptr<TKEYRecordContent> tkey_out(new TKEYRecordContent());
-  string label;
+  DNSName name;
   bool sign = false;
 
-  if (!p->getTKEYRecord(&tkey_in, &label)) {
-    L<<Logger::Error<<"TKEY request but no TKEY RR found"<<endl;
+  if (!p->getTKEYRecord(&tkey_in, &name)) {
+    g_log<<Logger::Error<<"TKEY request but no TKEY RR found"<<endl;
     r->setRcode(RCode::FormErr);
     return;
   }
 
-  // retain original label for response
+  // retain original name for response
   tkey_out->d_error = 0;
   tkey_out->d_mode = tkey_in.d_mode;
   tkey_out->d_algo = tkey_in.d_algo;
   tkey_out->d_inception = time((time_t*)NULL);
   tkey_out->d_expiration = tkey_out->d_inception+15;
 
-  GssContext ctx(label);
+  GssContext ctx(name);
 
   if (tkey_in.d_mode == 3) { // establish context
-    if (tkey_in.d_algo == "gss-tsig.") {
+    if (tkey_in.d_algo == DNSName("gss-tsig.")) {
       std::vector<std::string> meta;
-      string tmpLabel = toLowerCanonic(label);
-      bool ok = true;
-      while(ok) {
-        if (B.getDomainMetadata(tmpLabel, "GSS-ACCEPTOR-PRINCIPAL", meta) && meta.size()>0) {
+      DNSName tmpName(name);
+      do {
+        if (B.getDomainMetadata(tmpName, "GSS-ACCEPTOR-PRINCIPAL", meta) && meta.size()>0) {
           break;
         }
-        ok = chopOff(tmpLabel);
-      }
+      } while(tmpName.chopOff());
 
       if (meta.size()>0) {
         ctx.setLocalPrincipal(meta[0]);
@@ -73,31 +71,28 @@ void PacketHandler::tkeyHandler(DNSPacket *p, DNSPacket *r) {
   tkey_out->d_keysize = tkey_out->d_key.size();
   tkey_out->d_othersize = tkey_out->d_other.size();
 
-  DNSRecord rec;
-  rec.d_label = label;
-  rec.d_ttl = 0;
-  rec.d_type = QType::TKEY;
-  rec.d_class = QClass::ANY;
-  rec.d_content = tkey_out;
+  DNSZoneRecord zrr;
 
-  DNSResourceRecord rr(rec);
-  rr.qclass = QClass::ANY;
-  rr.qtype = QType::TKEY;
-  rr.d_place = DNSResourceRecord::ANSWER;
-  r->addRecord(rr);
+  zrr.dr.d_name = name;
+  zrr.dr.d_ttl = 0;
+  zrr.dr.d_type = QType::TKEY;
+  zrr.dr.d_class = QClass::ANY;
+  zrr.dr.d_content = tkey_out;
+  zrr.dr.d_place = DNSResourceRecord::ANSWER;
+  r->addRecord(zrr);
 
   if (sign)
   {
     TSIGRecordContent trc;
-    trc.d_algoName = "gss-tsig";
+    trc.d_algoName = DNSName("gss-tsig");
     trc.d_time = tkey_out->d_inception;
     trc.d_fudge = 300;
     trc.d_mac = "";
     trc.d_origID = p->d.id;
     trc.d_eRcode = 0;
     trc.d_otherData = "";
-    // this should cause it to lookup label context
-    r->setTSIGDetails(trc, label, label, "", false);
+    // this should cause it to lookup name context
+    r->setTSIGDetails(trc, name, name.toStringNoDot(), "", false);
   }
 
   r->commitD();