]> granicus.if.org Git - pdns/commitdiff
teach getZoneRepresentation to optionally skip the trailing dot on non-root names
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 27 Nov 2015 15:55:03 +0000 (16:55 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 30 Nov 2015 14:26:06 +0000 (15:26 +0100)
12 files changed:
pdns/dns.hh
pdns/dnsparser.cc
pdns/dnsparser.hh
pdns/dnsrecords.cc
pdns/dnsrecords.hh
pdns/dnswriter.cc
pdns/dnswriter.hh
pdns/nsecrecords.cc
pdns/pdnsutil.cc
pdns/rcpgenerator.cc
pdns/rcpgenerator.hh
pdns/sillyrecords.cc

index 24e40aa92f83cc8f86ab8b2bcc871941ede9a54a..ae0a2033dd9d6ec288359f1dc1152f56dc2e06a7 100644 (file)
@@ -77,7 +77,7 @@ public:
   enum Place : uint8_t {QUESTION=0, ANSWER=1, AUTHORITY=2, ADDITIONAL=3}; //!< Type describing the positioning of a DNSResourceRecord within, say, a DNSPacket
 
   void setContent(const string& content);
-  string getZoneRepresentation() const;
+  string getZoneRepresentation(bool noDot=false) const;
 
   // data
   DNSName qname; //!< the name of this record, for example: www.powerdns.com
index 5589ad8ff705d3634f7c1185b5ef821cc579c9f6..03d4b1338c2d89d96a50f63fb3e8e066f5c1e5dd 100644 (file)
@@ -59,7 +59,7 @@ public:
     d_record.insert(d_record.end(), out.begin(), out.end());
   }
 
-  string getZoneRepresentation() const override
+  string getZoneRepresentation(bool noDot) const override
   {
     ostringstream str;
     str<<"\\# "<<(unsigned int)d_record.size()<<" ";
index b03600f21160c4d9d2c31a853563dfae4d4f04e8..50e24105063c8132a11cf8804c8086a404a7aaa4 100644 (file)
@@ -120,7 +120,7 @@ public:
   }
 
 
-  void xfrName(DNSName &name, bool compress=false)
+  void xfrName(DNSName &name, bool compress=false, bool noDot=false)
   {
     name=getName();
   }
@@ -165,7 +165,7 @@ public:
   static DNSRecordContent* mastermake(uint16_t qtype, uint16_t qclass, const string& zone);
   static std::unique_ptr<DNSRecordContent> makeunique(uint16_t qtype, uint16_t qclass, const string& content);
 
-  virtual std::string getZoneRepresentation() const = 0;
+  virtual std::string getZoneRepresentation(bool noDot=false) const = 0;
   virtual ~DNSRecordContent() {}
   virtual void toPacket(DNSPacketWriter& pw)=0;
   virtual string serialize(const DNSName& qname, bool canonic=false, bool lowerCase=false) // it would rock if this were const, but it is too hard
index 4829a1a54e0de32013493081a25f786236bef169..8684c2d75f17ea729af5cf6298918bee51c9c429 100644 (file)
@@ -42,15 +42,18 @@ void DNSResourceRecord::setContent(const string &cont) {
   }
 }
 
-string DNSResourceRecord::getZoneRepresentation() const {
+string DNSResourceRecord::getZoneRepresentation(bool noDot) const {
   ostringstream ret;
   switch(qtype.getCode()) {
     case QType::SRV:
     case QType::MX:
     case QType::CNAME:
     case QType::NS:
-      if (*(content.rbegin()) != '.')
-        ret<<content<<".";
+      if (*(content.rbegin()) != '.') {
+        ret<<content;
+        if(!noDot)
+          ret<<".";
+      }
       break;
     default:
       ret<<content;
@@ -407,7 +410,7 @@ void EUI48RecordContent::toPacket(DNSPacketWriter& pw)
     string blob(d_eui48, d_eui48+6);
     pw.xfrBlob(blob); 
 }
-string EUI48RecordContent::getZoneRepresentation() const
+string EUI48RecordContent::getZoneRepresentation(bool noDot) const
 {
     char tmp[18]; 
     snprintf(tmp,18,"%02x-%02x-%02x-%02x-%02x-%02x", 
@@ -451,7 +454,7 @@ void EUI64RecordContent::toPacket(DNSPacketWriter& pw)
     string blob(d_eui64, d_eui64+8);
     pw.xfrBlob(blob);
 }
-string EUI64RecordContent::getZoneRepresentation() const
+string EUI64RecordContent::getZoneRepresentation(bool noDot) const
 {
     char tmp[24]; 
     snprintf(tmp,24,"%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
index f7eb2441b6477268bb6c8931009d2d99ee06606d..cc38d1b05d61136d60cba28036d1f7f0d37c14b7 100644 (file)
   static void unreport(void);                                                                    \
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);                          \
   static DNSRecordContent* make(const string& zonedata);                                         \
-  string getZoneRepresentation() const override;                                                 \
+  string getZoneRepresentation(bool noDot=false) const override;                                 \
   void toPacket(DNSPacketWriter& pw) override;                                                   \
   uint16_t getType() const override { return QType::RNAME; }                                   \
-  template<class Convertor> void xfrPacket(Convertor& conv);
+  template<class Convertor> void xfrPacket(Convertor& conv, bool noDot=false);
 
 class NAPTRRecordContent : public DNSRecordContent
 {
@@ -469,7 +469,7 @@ public:
 
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& content);
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
   uint16_t getType() const override
   {
@@ -490,7 +490,7 @@ public:
 
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& content);
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
   uint8_t d_algorithm, d_flags;
@@ -521,7 +521,7 @@ public:
 
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& content);
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
   uint16_t getType() const override
@@ -547,7 +547,7 @@ public:
 
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& content);
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
   uint8_t d_version, d_size, d_horizpre, d_vertpre;
@@ -571,7 +571,7 @@ public:
 
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& content);
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
 
   uint32_t d_ip;
@@ -586,7 +586,7 @@ public:
   static void report(void);
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& zone); // FIXME400: DNSName& zone?
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
   uint16_t getType() const override { return QType::EUI48; }
 private:
@@ -601,7 +601,7 @@ public:
   static void report(void);
   static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
   static DNSRecordContent* make(const string& zone); // FIXME400: DNSName& zone?
-  string getZoneRepresentation() const override;
+  string getZoneRepresentation(bool noDot=false) const override;
   void toPacket(DNSPacketWriter& pw) override;
   uint16_t getType() const override { return QType::EUI64; }
 private:
@@ -674,10 +674,10 @@ RNAME##RecordContent::RNAME##RecordContent(const string& zoneData)
   }                                                                                               \
 }                                                                                                  \
                                                                                                    \
-string RNAME##RecordContent::getZoneRepresentation() const                                         \
+string RNAME##RecordContent::getZoneRepresentation(bool noDot) const                               \
 {                                                                                                  \
   string ret;                                                                                      \
-  RecordTextWriter rtw(ret);                                                                       \
+  RecordTextWriter rtw(ret, noDot);                                                                       \
   const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw);                                         \
   return ret;                                                                                      \
 }                                                                                                  
@@ -686,7 +686,7 @@ string RNAME##RecordContent::getZoneRepresentation() const
 #define boilerplate_conv(RNAME, TYPE, CONV)                       \
 boilerplate(RNAME, TYPE)                                          \
 template<class Convertor>                                         \
-void RNAME##RecordContent::xfrPacket(Convertor& conv)             \
+void RNAME##RecordContent::xfrPacket(Convertor& conv, bool noDot) \
 {                                                                 \
   CONV;                                                           \
   if (conv.eof() == false) throw MOADNSException("All data was not consumed"); \
index dc03874bef82abcff6aadcf55e34a4df514f5d75..d7e58374ab96b137e9951ee20e4425ca32bfe974 100644 (file)
@@ -203,7 +203,7 @@ DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& nmap, const DNSN
 // }
 
 // this is the absolute hottest function in the pdns recursor
-void DNSPacketWriter::xfrName(const DNSName& name, bool compress)
+void DNSPacketWriter::xfrName(const DNSName& name, bool compress, bool)
 {
   //cerr<<"xfrName: name=["<<name.toString()<<"] compress="<<compress<<endl;
   // string label = d_lowerCase ? toLower(Label) : Label;
index da40920e69f2aa9960813ccede702e2383a6adb8..c5554ef7e47eadfb004730e1449d928753751c79 100644 (file)
@@ -86,7 +86,7 @@ public:
 
   void xfr8BitInt(uint8_t val);
 
-  void xfrName(const DNSName& label, bool compress=false);
+  void xfrName(const DNSName& label, bool compress=false, bool noDot=false);
   void xfrText(const string& text, bool multi=false);
   void xfrBlob(const string& blob, int len=-1);
   void xfrBlobNoSpaces(const string& blob, int len=-1);
index 1bfe97dafd2948d3880406a6187c26a02db397f2..5aaf2d0b0ca4952f98208a0cea1d6097a750c35b 100644 (file)
@@ -94,7 +94,7 @@ NSECRecordContent::DNSRecordContent* NSECRecordContent::make(const DNSRecord &dr
   return ret;
 }
 
-string NSECRecordContent::getZoneRepresentation() const
+string NSECRecordContent::getZoneRepresentation(bool noDot) const
 {
   string ret;
   RecordTextWriter rtw(ret);
@@ -227,7 +227,7 @@ NSEC3RecordContent::DNSRecordContent* NSEC3RecordContent::make(const DNSRecord &
   return ret;
 }
 
-string NSEC3RecordContent::getZoneRepresentation() const
+string NSEC3RecordContent::getZoneRepresentation(bool noDot) const
 {
   string ret;
   RecordTextWriter rtw(ret);
@@ -288,7 +288,7 @@ NSEC3PARAMRecordContent::DNSRecordContent* NSEC3PARAMRecordContent::make(const D
   return ret;
 }
 
-string NSEC3PARAMRecordContent::getZoneRepresentation() const
+string NSEC3PARAMRecordContent::getZoneRepresentation(bool noDot) const
 {
   string ret;
   RecordTextWriter rtw(ret);
index 4e60842a3af6e1ad5048861f8891ebf49c80f994..927658412d5be0c9218f16bc1f13c9600f0ec664 100644 (file)
@@ -478,7 +478,7 @@ int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone)
     try {
       shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content));
       string tmp=drc->serialize(rr.qname);
-      tmp = drc->getZoneRepresentation();
+      tmp = drc->getZoneRepresentation(true);
       if (rr.qtype.getCode() != QType::AAAA) {
         if (!pdns_iequals(tmp, rr.content)) {
           cout<<"[Warning] Parsed and original record content are not equal: "<<rr.qname.toString()<<" IN " <<rr.qtype.getName()<< " '" << rr.content<<"' (Content parsed as '"<<tmp<<"')"<<endl;
index 8d6f6448b1e00d5807eaa53040357776ad446cc7..30390108dd3e10bc1e70793cac6b8956c0addea2 100644 (file)
@@ -188,7 +188,7 @@ void RecordTextReader::xfr8BitInt(uint8_t &val)
 }
 
 // this code should leave all the escapes around 
-void RecordTextReader::xfrName(DNSName& val, bool
+void RecordTextReader::xfrName(DNSName& val, bool, bool)
 {
   skipSpaces();
   string sval;
@@ -398,9 +398,10 @@ void RecordTextReader::skipSpaces()
 }
 
 
-RecordTextWriter::RecordTextWriter(string& str) : d_string(str)
+RecordTextWriter::RecordTextWriter(string& str, bool noDot) : d_string(str)
 {
   d_string.clear();
+  d_nodot=noDot;
 }
 
 void RecordTextWriter::xfr48BitInt(const uint64_t& val)
@@ -503,12 +504,21 @@ void RecordTextWriter::xfr8BitInt(const uint8_t& val)
 }
 
 // should not mess with the escapes
-void RecordTextWriter::xfrName(const DNSName& val, bool)
+void RecordTextWriter::xfrName(const DNSName& val, bool, bool noDot)
 {
   if(!d_string.empty())
     d_string.append(1,' ');
   
-  d_string+=val.toString();
+  if(d_nodot) {
+    if(val.isRoot())
+      d_string+=".";
+    else
+      d_string+=val.toStringNoDot();
+  }
+  else
+  {
+    d_string+=val.toString();
+  }
 }
 
 void RecordTextWriter::xfrBlobNoSpaces(const string& val, int size)
index 2c14eca6e7808d8e8a7f3beb97f743c272725c8c..f5af2ea640d2ca600c94a4b6d59abb12049a3ff6 100644 (file)
@@ -52,7 +52,7 @@ public:
   void xfrIP6(std::string& val);
   void xfrTime(uint32_t& val);
 
-  void xfrName(DNSName& val, bool compress=false);
+  void xfrName(DNSName& val, bool compress=false, bool noDot=false);
   void xfrText(string& val, bool multi=false);
   void xfrHexBlob(string& val, bool keepReading=false);
   void xfrBase32HexBlob(string& val);
@@ -72,7 +72,7 @@ private:
 class RecordTextWriter
 {
 public:
-  RecordTextWriter(string& str);
+  RecordTextWriter(string& str, bool noDot=false);
   void xfr48BitInt(const uint64_t& val);
   void xfr32BitInt(const uint32_t& val);
   void xfr16BitInt(const uint16_t& val);
@@ -83,7 +83,7 @@ public:
   void xfrBase32HexBlob(const string& val);
 
   void xfrType(const uint16_t& val);
-  void xfrName(const DNSName& val, bool compress=false);
+  void xfrName(const DNSName& val, bool compress=false, bool noDot=false);
   void xfrText(const string& val, bool multi=false);
   void xfrBlobNoSpaces(const string& val, int len=-1);
   void xfrBlob(const string& val, int len=-1);
@@ -91,5 +91,6 @@ public:
   bool eof() { return true; };
 private:
   string& d_string;
+  bool d_nodot;
 };
 #endif
index 3a4109dfae86cce4efe5d178248fd7d3b744a42a..b2a7ea18844d59352e7c40604187154c27a74137 100644 (file)
@@ -290,7 +290,7 @@ LOCRecordContent::LOCRecordContent(const string& content, const string& zone)
 }
 
 
-string LOCRecordContent::getZoneRepresentation() const
+string LOCRecordContent::getZoneRepresentation(bool noDot) const
 {
   // convert d_version, d_size, d_horiz/vertpre, d_latitude, d_longitude, d_altitude to:
   // 51 59 00.000 N 5 55 00.000 E 4.00m 1.00m 10000.00m 10.00m