Skip to content

Commit

Permalink
implement rfc7553 - need to figure out escaping semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
ahupowerdns committed Jun 14, 2015
1 parent 9716ccd commit 3bc9bfe
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pdns/dnsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ catch(...)
throw std::out_of_range("xfrBlob out of range");
}

void PacketReader::xfrTarget(string& blob)
{
xfrBlob(blob);
}

void PacketReader::xfrBlobNoSpaces(string& blob, int length) {
xfrBlob(blob, length);
}
Expand Down
1 change: 1 addition & 0 deletions pdns/dnsparser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public:
void xfrBlobNoSpaces(string& blob, int len);
void xfrBlob(string& blob, int length);
void xfrHexBlob(string& blob, bool keepReading=false);
void xfrTarget(string& blob);

static uint16_t get16BitInt(const vector<unsigned char>&content, uint16_t& pos);

Expand Down
11 changes: 10 additions & 1 deletion pdns/dnsrecords.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
PowerDNS Versatile Database Driven Nameserver
Copyright (C) 2005 - 2009 PowerDNS.COM BV
Copyright (C) 2005 - 2015 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -426,6 +426,14 @@ boilerplate_conv(TKEY, QType::TKEY,
)
TKEYRecordContent::TKEYRecordContent() : DNSRecordContent(QType::TKEY) { d_othersize = 0; } // fix CID#1288932

boilerplate_conv(URI, QType::URI,
conv.xfr16BitInt(d_prio);
conv.xfr16BitInt(d_weight);
conv.xfrTarget(d_target);
)
URIRecordContent::URIRecordContent() : DNSRecordContent(QType::URI) {}


uint16_t DNSKEYRecordContent::getTag()
{
string data=this->serialize("");
Expand Down Expand Up @@ -509,6 +517,7 @@ void reportOtherTypes()
DLVRecordContent::report();
DNSRecordContent::regist(QClass::ANY, QType::TSIG, &TSIGRecordContent::make, &TSIGRecordContent::make, "TSIG");
DNSRecordContent::regist(QClass::ANY, QType::TKEY, &TKEYRecordContent::make, &TKEYRecordContent::make, "TKEY");
URIRecordContent::report();
//TSIGRecordContent::report();
OPTRecordContent::report();
EUI48RecordContent::report();
Expand Down
12 changes: 11 additions & 1 deletion pdns/dnsrecords.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
PowerDNS Versatile Database Driven Nameserver
Copyright (C) 2005 - 2010 PowerDNS.COM BV
Copyright (C) 2005 - 2015 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -533,6 +533,16 @@ private:
uint8_t d_eui64[8];
};

class URIRecordContent : public DNSRecordContent
{
public:
URIRecordContent();
includeboilerplate(URI);
uint16_t d_prio;
uint16_t d_weight;
string d_target;
};

class TKEYRecordContent : public DNSRecordContent
{
public:
Expand Down
5 changes: 5 additions & 0 deletions pdns/dnswriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ void DNSPacketWriter::xfrHexBlob(const string& blob, bool keepReading)
xfrBlob(blob);
}

void DNSPacketWriter::xfrTarget(const string& blob, bool keepReading)
{
xfrBlob(blob);
}

void DNSPacketWriter::getRecords(string& records)
{
records.assign(d_content.begin() + d_sor, d_content.end());
Expand Down
1 change: 1 addition & 0 deletions pdns/dnswriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public:
void xfrBlob(const string& blob, int len=-1);
void xfrBlobNoSpaces(const string& blob, int len=-1);
void xfrHexBlob(const string& blob, bool keepReading=false);
void xfrTarget(const string& blob, bool keepReading=false);

uint16_t d_pos;

Expand Down
5 changes: 3 additions & 2 deletions pdns/qtype.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
PowerDNS Versatile Database Driven Nameserver
Copyright (C) 2002 PowerDNS.COM BV
Copyright (C) 2002 - 2015 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
Expand Down Expand Up @@ -81,7 +81,7 @@ public:
#undef DS
enum typeenum {A=1, NS=2, CNAME=5, SOA=6, MR=9, WKS=11, PTR=12, HINFO=13, MINFO=14, MX=15, TXT=16, RP=17, AFSDB=18, SIG=24, KEY=25, AAAA=28, LOC=29, SRV=33, NAPTR=35, KX=36,
CERT=37, A6=38, DNAME=39, OPT=41, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46, NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51,
TLSA=52, SPF=99, EUI48=108, EUI64=109, TKEY=249, TSIG=250, IXFR=251, AXFR=252, MAILB=253, MAILA=254, ANY=255, ADDR=259, ALIAS=260, DLV=32769} types;
TLSA=52, SPF=99, EUI48=108, EUI64=109, TKEY=249, TSIG=250, IXFR=251, AXFR=252, MAILB=253, MAILA=254, ANY=255, URI=256, ADDR=259, ALIAS=260, DLV=32769} types;
typedef pair<string,uint16_t> namenum;
static vector<namenum> names;

Expand Down Expand Up @@ -162,6 +162,7 @@ private:
qtype_insert("MAILB", 253);
qtype_insert("MAILA", 254);
qtype_insert("ANY", 255);
qtype_insert("URI", 256);
qtype_insert("ADDR", 259);
qtype_insert("ALIAS", 260);
qtype_insert("DLV", 32769);
Expand Down
29 changes: 29 additions & 0 deletions pdns/rcpgenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ void RecordTextReader::xfrText(string& val, bool multi)
}
}

void RecordTextReader::xfrTarget(string& val)
{
val.clear();
val.reserve(d_end - d_pos);
skipSpaces();

if(d_string[d_pos]!='"')
throw RecordTextException("Data field in DNS should start with quote (\") at position "+lexical_cast<string>(d_pos)+" of '"+d_string+"'");

while(++d_pos < d_end && d_string[d_pos]!='"') {
if(d_string[d_pos]=='\\' && d_pos+1!=d_end) {
val.append(1, d_string[d_pos++]);
}
val.append(1, d_string[d_pos]);
}
if(d_pos == d_end)
throw RecordTextException("Data field in DNS should end on a quote (\") in '"+d_string+"'");
d_pos++;
}

void RecordTextReader::xfrType(uint16_t& val)
{
skipSpaces();
Expand Down Expand Up @@ -519,6 +539,15 @@ void RecordTextWriter::xfrBlob(const string& val, int)
d_string+=Base64Encode(val);
}

void RecordTextWriter::xfrTarget(const string& val)
{
if(!d_string.empty())
d_string.append(1,' ');

d_string+='"'+val+'"'; // XXX escaping..
}


void RecordTextWriter::xfrHexBlob(const string& val, bool)
{
if(!d_string.empty())
Expand Down
3 changes: 3 additions & 0 deletions pdns/rcpgenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public:
void xfrName(string& val, bool compress=false);
void xfrText(string& val, bool multi=false);
void xfrHexBlob(string& val, bool keepReading=false);
void xfrTarget(string& val);
void xfrBase32HexBlob(string& val);

void xfrBlobNoSpaces(string& val, int len=-1);
Expand Down Expand Up @@ -86,7 +87,9 @@ public:
void xfrText(const string& val, bool multi=false);
void xfrBlobNoSpaces(const string& val, int len=-1);
void xfrBlob(const string& val, int len=-1);

void xfrHexBlob(const string& val, bool keepReading=false);
void xfrTarget(const string& val);
bool eof() { return true; };
private:
string& d_string;
Expand Down
1 change: 1 addition & 0 deletions pdns/test-dnsrecords_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
(CASE_S(QType::TKEY, "gss-tsig. 12345 12345 3 21 4 dGVzdA== 4 dGVzdA==", "\x08gss-tsig\x00\x00\x00\x30\x39\x00\x00\x30\x39\x00\x03\x00\x15\x00\x04test\x00\x04test", false))
/* (CASE_S(QType::ADDR, "zone format", "line format",false)) */
(CASE_S(QType::DLV, "20642 8 2 04443abe7e94c3985196beae5d548c727b044dda5151e60d7cd76a9fd931d00e", "\x50\xa2\x08\x02\x04\x44\x3a\xbe\x7e\x94\xc3\x98\x51\x96\xbe\xae\x5d\x54\x8c\x72\x7b\x04\x4d\xda\x51\x51\xe6\x0d\x7c\xd7\x6a\x9f\xd9\x31\xd0\x0e",false))
(CASE_S(QType::URI, "10 1 \"ftp://ftp1.example.com/public\"", "\x00\x0a\x00\001ftp://ftp1.example.com/public", false))
(CASE_S((QType::typeenum)65226,"\\# 3 414243","\x41\x42\x43",false))
;

Expand Down

0 comments on commit 3bc9bfe

Please sign in to comment.