aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h aes/dns_random.cc \
randomhelper.cc namespaces.hh nsecrecords.cc base32.cc dbdnsseckeeper.cc dnssecinfra.cc \
dnsseckeeper.hh dnssecinfra.hh base32.hh dns.cc dnssecsigner.cc polarrsakeyinfra.cc md5.cc \
-md5.hh signingpipe.cc signingpipe.hh
+md5.hh signingpipe.cc signingpipe.hh dnslabeltext.cc
#
pdns_server_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ -Lext/polarssl/library
backends/gsql/gsqlbackend.cc \
backends/gsql/gsqlbackend.hh backends/gsql/ssql.hh zoneparser-tng.cc \
dynlistener.cc dns.cc randombackend.cc dnssecsigner.cc polarrsakeyinfra.cc md5.cc \
- signingpipe.cc
+ signingpipe.cc dnslabeltext.cc
pdnssec_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ -Lext/polarssl/library/ $(BOOST_PROGRAM_OPTIONS_LDFLAGS)
pdnssec_LDADD= -lpolarssl $(BOOST_PROGRAM_OPTIONS_LIBS)
endif
-sdig_SOURCES=sdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \
+sdig_SOURCES=sdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \
logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc
-toysdig_SOURCES=toysdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \
+toysdig_SOURCES=toysdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \
logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc dnslabel.cc dnslabel.hh
-#tcptorture_SOURCES=tcptorture.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \
+#tcptorture_SOURCES=tcptorture.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
# misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \
# logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc
-tsig_tests_SOURCES=tsig-tests.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \
+tsig_tests_SOURCES=tsig-tests.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \
logger.cc statbag.cc qtype.cc sillyrecords.cc md5.cc
-speedtest_SOURCES=speedtest.cc dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnswriter.hh \
+speedtest_SOURCES=speedtest.cc dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \
qtype.cc sillyrecords.cc logger.cc statbag.cc nsecrecords.cc base32.cc
dnswasher_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@
dnsbulktest_SOURCES=dnsbulktest.cc misc.cc unix_utility.cc qtype.cc logger.cc statbag.cc dnsparser.cc \
- dnsrecords.cc dnswriter.cc rcpgenerator.cc base32.cc base64.cc sillyrecords.cc nsecrecords.cc
+ dnsrecords.cc dnswriter.cc dnslabeltext.cc rcpgenerator.cc base32.cc base64.cc sillyrecords.cc nsecrecords.cc
dnsbulktest_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@
dnsscan_SOURCES=dnsscan.cc misc.cc qtype.cc anadns.hh \
logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc dnsparser.hh \
- rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
+ rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh \
unix_utility.cc utility.hh
dnslog_SOURCES=dnslog.cc misc.cc qtype.cc anadns.hh \
logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc dnsparser.hh \
- rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
+ rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh \
unix_utility.cc utility.hh
#socketbench_SOURCES=socketbench.cc qtype.cc misc.cc unix_utility.cc\
dnsreplay_SOURCES=dnsreplay.cc misc.cc qtype.cc anadns.hh \
logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc dnsparser.hh \
- rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
+ rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh \
unix_utility.cc utility.hh sillyrecords.cc nsecrecords.cc base32.cc
dnsreplay_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_PROGRAM_OPTIONS_LDFLAGS)
dnsreplay_LDADD= $(BOOST_PROGRAM_OPTIONS_LIBS)
nproxy_SOURCES=nproxy.cc dnsparser.cc dnsrecords.cc dnsparser.hh \
- rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
+ rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh \
sillyrecords.cc selectmplexer.cc mplexer.hh
nproxy_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_PROGRAM_OPTIONS_LDFLAGS)
nproxy_LDADD= $(BOOST_PROGRAM_OPTIONS_LIBS)
notify_SOURCES=notify.cc dnsparser.cc dnsrecords.cc dnsparser.hh \
- rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
+ rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh \
sillyrecords.cc selectmplexer.cc nsecrecords.cc base32.cc misc.cc unix_utility.cc \
logger.cc qtype.cc statbag.cc
dnsscope_SOURCES=dnsscope.cc misc.cc unix_utility.cc qtype.cc \
logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc \
- base64.cc base64.hh dnswriter.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
+ base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
utility.hh dnsparser.hh sillyrecords.cc nsecrecords.cc base32.cc
dnsscope_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@
dnsgram_SOURCES=dnsgram.cc misc.cc unix_utility.cc qtype.cc \
logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc \
- base64.cc base64.hh dnswriter.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
+ base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
utility.hh dnsparser.hh sillyrecords.cc nsecrecords.cc base32.cc
dnsdemog_SOURCES=dnsdemog.cc misc.cc unix_utility.cc qtype.cc \
logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc \
- base64.cc base64.hh dnswriter.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
+ base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
utility.hh dnsparser.hh sillyrecords.cc
rec_control_SOURCES=rec_channel.cc rec_channel.hh rec_control.cc arguments.cc arguments.hh misc.cc qtype.cc \
pdns_recursor_SOURCES=syncres.cc resolver.hh misc.cc unix_utility.cc qtype.cc \
logger.cc statbag.cc arguments.cc lwres.cc pdns_recursor.cc reczones.cc lwres.hh \
mtasker.hh syncres.hh recursor_cache.cc recursor_cache.hh dnsparser.cc \
-dnswriter.cc dnswriter.hh dnsrecords.cc dnsrecords.hh rcpgenerator.cc rcpgenerator.hh \
+dnswriter.cc dnslabeltext.cc dnswriter.hh dnsrecords.cc dnsrecords.hh rcpgenerator.cc rcpgenerator.hh \
base64.cc base64.hh zoneparser-tng.cc zoneparser-tng.hh rec_channel.cc rec_channel.hh \
rec_channel_rec.cc selectmplexer.cc epollmplexer.cc sillyrecords.cc htimer.cc htimer.hh \
aes/dns_random.cc aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c \
pdns_control_INCLUDES=path.hh
pdns_control_LDFLAGS=@THREADFLAGS@
-# binpatch_SOURCES=binpatch.cc
-
-
+dnslabeltext.cc: dnslabeltext.rl
+ ragel dnslabeltext.rl -o dnslabeltext.cc
+
\ No newline at end of file
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string>
+#include "namespaces.hh"
+
+%%{
+ machine dnstext;
+ write data;
+}%%
+
+namespace {
+void appendSplit(vector<string>& ret, string& segment, char c)
+{
+ if(segment.size()>254) {
+ ret.push_back(segment);
+ segment.clear();
+ }
+ segment.append(1, c);
+}
+}
+
+vector<string> segmentDNSText(const string& input )
+{
+ const char *p = input.c_str(), *pe = input.c_str() + input.length();
+ const char* eof = pe;
+ int cs;
+ char val = 0;
+
+ string segment;
+ vector<string> ret;
+
+ %%{
+ action segmentEnd {
+ ret.push_back(segment);
+ segment.clear();
+ }
+ action segmentBegin {
+ segment.clear();
+ }
+
+ action reportEscaped {
+ char c = *fpc;
+ appendSplit(ret, segment, c);
+ }
+ action reportEscapedNumber {
+ char c = *fpc;
+ val *= 10;
+ val += c-'0';
+
+ }
+ action doneEscapedNumber {
+ appendSplit(ret, segment, val);
+ val=0;
+ }
+
+ action reportPlain {
+ appendSplit(ret, segment, *(fpc));
+ }
+
+ escaped = '\\' ((["\\]@reportEscaped) | ([0-9]{3}$reportEscapedNumber%doneEscapedNumber));
+ plain = (print-'\\'-'"') $ reportPlain;
+ labelElement = escaped | plain;
+
+
+ main := (('"' labelElement* '"' space?) >segmentBegin %segmentEnd)+;
+
+ # Initialize and execute.
+ write init;
+ write exec;
+ }%%
+
+ if ( cs < dnstext_first_final ) {
+ throw runtime_error("Unable to parse DNS TXT '"+input+"'");
+ }
+
+ return ret;
+};
+
+#if 0
+int main()
+{
+ //char blah[]="\"blah\" \"bleh\" \"bloeh\\\"bleh\" \"\\97enzo\"";
+ char blah[]="\"v=spf1 ip4:67.106.74.128/25 ip4:63.138.42.224/28 ip4:65.204.46.224/27 \\013\\010ip4:66.104.217.176/28 \\013\\010ip4:209.48.147.0/27 ~all\"";
+ //char blah[]="\"abc \\097\\098 def\"";
+ printf("Input: '%s'\n", blah);
+ vector<string> res=dnstext(blah);
+ cerr<<res.size()<<" segments"<<endl;
+ cerr<<res[0]<<endl;
+}
+#endif
#include "dnswriter.hh"
#include "misc.hh"
#include "dnsparser.hh"
-#include <boost/tokenizer.hpp>
-#include <boost/algorithm/string.hpp>
+#include <boost/foreach.hpp>
#include <limits.h>
DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& content, const string& qname, uint16_t qtype, uint16_t qclass, uint8_t opcode)
d_record.push_back(val);
}
+
+/* input:
+ "" -> 0
+ "blah" -> 4blah
+ "blah" "blah" -> output 4blah4blah
+ "verylongstringlongerthan256....characters" \xffverylongstring\x23characters (autosplit)
+ "blah\"blah" -> 9blah"blah
+ "blah\97" -> 5blahb
+ */
void DNSPacketWriter::xfrText(const string& text, bool)
{
- using boost::escaped_list_separator;
- using boost::tokenizer;
-
- escaped_list_separator<char> sep('\\', ' ' , '"');
- tokenizer<escaped_list_separator<char> > tok(text, sep);
-
- tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin();
-
- if(beg==tok.end()) {
+ if(text.empty()) {
d_record.push_back(0);
+ return;
+ }
+ vector<string> segments = segmentDNSText(text);
+ BOOST_FOREACH(const string& str, segments) {
+ d_record.push_back(str.length());
+ d_record.insert(d_record.end(), str.c_str(), str.c_str() + str.length());
}
- else
- for(; beg!=tok.end(); ++beg){
- if(beg->empty())
- d_record.push_back(0);
- else
- for (unsigned int i = 0; i < beg->length(); i += 0xff){
- d_record.push_back(std::min((string::size_type)0xffU, beg->length()-i));
- const uint8_t* ptr=(uint8_t*)(beg->c_str()) + i;
- d_record.insert(d_record.end(), ptr, ptr+ std::min((string::size_type)0xffU, beg->length()-i));
- }
- }
}
DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& lmap, const string& label)