static int maxNSEC3Iterations=::arg().asNum("max-nsec3-iterations");
if(ns3p) {
- NSEC3PARAMRecordContent* tmp=dynamic_cast<NSEC3PARAMRecordContent*>(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value));
+ std::shared_ptr<NSEC3PARAMRecordContent> tmp=std::dynamic_pointer_cast<NSEC3PARAMRecordContent>(DNSRecordContent::mastermake(QType::NSEC3PARAM, 1, value));
*ns3p = *tmp;
- delete tmp;
if (ns3p->d_iterations > maxNSEC3Iterations) {
ns3p->d_iterations = maxNSEC3Iterations;
dr.d_type = rr.qtype.getCode();
dr.d_clen = val.size()-pr.d_pos;
- DNSRecordContent *drc = DNSRecordContent::mastermake(dr, pr);
+ std::shared_ptr<DNSRecordContent> drc = DNSRecordContent::mastermake(dr, pr);
rr.content = drc->getZoneRepresentation();
DLOG(cerr<<"CONTENT: "<<rr.content<<endl);
- delete drc;
}
catch (...) {
if (d_ignorebogus) {
return ret;
}
-DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr,
+std::shared_ptr<DNSRecordContent> DNSRecordContent::mastermake(const DNSRecord &dr,
PacketReader& pr)
{
uint16_t searchclass = (dr.d_type == QType::OPT) ? 1 : dr.d_class; // class is invalid for OPT
typemap_t::const_iterator i=getTypemap().find(make_pair(searchclass, dr.d_type));
if(i==getTypemap().end() || !i->second) {
- return new UnknownRecordContent(dr, pr);
+ return std::make_shared<UnknownRecordContent>(dr, pr);
}
- return i->second(dr, pr);
+ return std::shared_ptr<DNSRecordContent>(i->second(dr, pr));
}
-DNSRecordContent* DNSRecordContent::mastermake(uint16_t qtype, uint16_t qclass,
+std::shared_ptr<DNSRecordContent> DNSRecordContent::mastermake(uint16_t qtype, uint16_t qclass,
const string& content)
{
zmakermap_t::const_iterator i=getZmakermap().find(make_pair(qclass, qtype));
if(i==getZmakermap().end()) {
- return new UnknownRecordContent(content);
+ return std::make_shared<UnknownRecordContent>(content);
}
- return i->second(content);
+ return std::shared_ptr<DNSRecordContent>(i->second(content));
}
std::unique_ptr<DNSRecordContent> DNSRecordContent::makeunique(uint16_t qtype, uint16_t qclass,
}
-DNSRecordContent* DNSRecordContent::mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t oc) {
+std::shared_ptr<DNSRecordContent> DNSRecordContent::mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t oc) {
// For opcode UPDATE and where the DNSRecord is an answer record, we don't care about content, because this is
// not used within the prerequisite section of RFC2136, so - we can simply use unknownrecordcontent.
// For section 3.2.3, we do need content so we need to get it properly. But only for the correct QClasses.
if (oc == Opcode::Update && dr.d_place == DNSResourceRecord::ANSWER && dr.d_class != 1)
- return new UnknownRecordContent(dr, pr);
+ return std::make_shared<UnknownRecordContent>(dr, pr);
uint16_t searchclass = (dr.d_type == QType::OPT) ? 1 : dr.d_class; // class is invalid for OPT
typemap_t::const_iterator i=getTypemap().find(make_pair(searchclass, dr.d_type));
if(i==getTypemap().end() || !i->second) {
- return new UnknownRecordContent(dr, pr);
+ return std::make_shared<UnknownRecordContent>(dr, pr);
}
- return i->second(dr, pr);
+ return std::shared_ptr<DNSRecordContent>(i->second(dr, pr));
}
d_class = rr.qclass;
d_place = DNSResourceRecord::ANSWER;
d_clen = 0;
- d_content = std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(d_type, rr.qclass, rr.content));
+ d_content = DNSRecordContent::mastermake(d_type, rr.qclass, rr.content);
}
// If you call this and you are not parsing a packet coming from a socket, you are doing it wrong.
}
else {
// cerr<<"parsing RR, query is "<<query<<", place is "<<dr.d_place<<", type is "<<dr.d_type<<", class is "<<dr.d_class<<endl;
- dr.d_content=std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr, pr, d_header.opcode));
+ dr.d_content=DNSRecordContent::mastermake(dr, pr, d_header.opcode);
}
d_answers.push_back(make_pair(dr, pr.d_pos));
d_pos+=consumed;
return dn;
}
- catch(std::range_error& re)
- {
- throw std::out_of_range(string("dnsname issue: ")+re.what());
- }
-
- catch(...)
- {
- throw std::out_of_range("dnsname issue");
- }
+ catch(const std::range_error& re) {
+ throw std::out_of_range(string("dnsname issue: ")+re.what());
+ }
+ catch(...) {
+ throw std::out_of_range("dnsname issue");
+ }
throw PDNSException("PacketReader::getName(): name is empty");
}
class DNSRecordContent
{
public:
- static DNSRecordContent* mastermake(const DNSRecord &dr, PacketReader& pr);
- static DNSRecordContent* mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t opcode);
- static DNSRecordContent* mastermake(uint16_t qtype, uint16_t qclass, const string& zone);
+ static std::shared_ptr<DNSRecordContent> mastermake(const DNSRecord &dr, PacketReader& pr);
+ static std::shared_ptr<DNSRecordContent> mastermake(const DNSRecord &dr, PacketReader& pr, uint16_t opcode);
+ static std::shared_ptr<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(bool noDot=false) const = 0;
});
- d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); });
+ d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = DNSRecordContent::mastermake(dr.d_type, 1, newContent); });
d_lw->writeFunction("pdnslog", [](const std::string& msg, boost::optional<int> loglevel) {
theL() << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<<endl;
string content;
getFromTable(lua, "content", content);
- rr.d_content=shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(rr.d_type, rr.d_class, content));
+ rr.d_content=DNSRecordContent::mastermake(rr.d_type, rr.d_class, content);
if(!getFromTable(lua, "ttl", rr.d_ttl))
rr.d_ttl=3600;
dr.d_ttl=ttl.get_value_or(3600);
dr.d_type = type;
dr.d_place = place;
- dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(type, 1, content));
+ dr.d_content = DNSRecordContent::mastermake(type, 1, content);
records.push_back(dr);
}
},
[](DNSFilterEngine::Policy& pol, const std::string& content) {
// Only CNAMES for now, when we ever add a d_custom_type, there will be pain
- pol.d_custom = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::CNAME, 1, content));
+ pol.d_custom = DNSRecordContent::mastermake(QType::CNAME, 1, content);
}
);
d_lw->registerFunction("getDH", &DNSQuestion::getDH);
});
- d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); });
+ d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = DNSRecordContent::mastermake(dr.d_type, 1, newContent); });
d_lw->registerFunction("addAnswer", &DNSQuestion::addAnswer);
d_lw->registerFunction("addRecord", &DNSQuestion::addRecord);
d_lw->registerFunction("getRecords", &DNSQuestion::getRecords);
}
else
content=mode;
- rr.dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::TXT, 1, "\""+content+"\""));
+ rr.dr.d_content = DNSRecordContent::mastermake(QType::TXT, 1, "\""+content+"\"");
}
else if (target==idserver) {
// modes: disabled, hostname or custom
r->setRcode(RCode::Refused);
return 0;
}
- rr.dr.d_content=shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::TXT, 1, id));
+ rr.dr.d_content=DNSRecordContent::mastermake(QType::TXT, 1, id);
}
else {
r->setRcode(RCode::Refused);
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
if(rr.qtype.getCode() == QType::DNSKEY) {
cerr<<"got DNSKEY!"<<endl;
apex=rr.qname;
- drc = *dynamic_cast<DNSKEYRecordContent*>(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content));
+ drc = *std::dynamic_pointer_cast<DNSKEYRecordContent>(DNSRecordContent::mastermake(QType::DNSKEY, 1, rr.content));
}
else if(rr.qtype.getCode() == QType::RRSIG) {
cerr<<"got RRSIG"<<endl;
- rrc = *dynamic_cast<RRSIGRecordContent*>(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content));
+ rrc = *std::dynamic_pointer_cast<RRSIGRecordContent>(DNSRecordContent::mastermake(QType::RRSIG, 1, rr.content));
}
else if(rr.qtype.getCode() == QType::DS) {
cerr<<"got DS"<<endl;
- dsrc = *dynamic_cast<DSRecordContent*>(DNSRecordContent::mastermake(QType::DS, 1, rr.content));
+ dsrc = *std::dynamic_pointer_cast<DSRecordContent>(DNSRecordContent::mastermake(QType::DS, 1, rr.content));
}
else {
qname = rr.qname;
- toSign.push_back(shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content)));
+ toSign.push_back(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content));
}
}
- string msg = getMessageForRRSET(qname, rrc, toSign);
+ string msg = getMessageForRRSET(qname, rrc, toSign);
cerr<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc.d_algorithm, drc.d_key)->verify(msg, rrc.d_signature)<<endl;
if(dsrc.d_digesttype) {
cerr<<"Calculated DS: "<<apex.toString()<<" IN DS "<<makeDSFromDNSKey(apex, drc, dsrc.d_digesttype).getZoneRepresentation()<<endl;
defpol->d_name = std::make_shared<std::string>(polName);
if(defpol->d_kind == DNSFilterEngine::PolicyKind::Custom) {
defpol->d_custom=
- shared_ptr<DNSRecordContent>(
DNSRecordContent::mastermake(QType::CNAME, 1,
boost::get<string>(constGet(have,"defcontent"))
- )
- );
+ );
if(have.count("defttl"))
defpol->d_ttl = static_cast<int32_t>(boost::get<uint32_t>(constGet(have, "defttl")));
rec.d_type = qtype;
rec.d_ttl = 600;
rec.d_place = DNSResourceRecord::AUTHORITY;
- rec.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(qtype, QClass::IN, content));
+ rec.d_content = DNSRecordContent::mastermake(qtype, QClass::IN, content);
ret.records.push_back(rec);
rec.d_content = std::make_shared<OPTRecordContent>();
}
else {
- rec.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(type, QClass::IN, content));
+ rec.d_content = DNSRecordContent::mastermake(type, QClass::IN, content);
}
records.push_back(rec);
dr.d_ttl=86400;
dr.d_type=QType::SOA;
dr.d_class = 1;
- dr.d_content = std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800"));
+ dr.d_content = DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800");
ad.d_records.insert(dr);
ad.d_records.insert(dr);
dr.d_type=QType::A;
- dr.d_content= std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::A, 1, ip));
+ dr.d_content = DNSRecordContent::mastermake(QType::A, 1, ip);
ad.d_records.insert(dr);
if(newMap->count(dr.d_name)) {
dr.d_place=DNSResourceRecord::ANSWER;
dr.d_ttl=86400;
dr.d_type=QType::SOA;
- dr.d_content=std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800"));
+ dr.d_content=DNSRecordContent::mastermake(QType::SOA, 1, "localhost. root 1 604800 86400 2419200 604800");
ad.d_records.insert(dr);
if(ipparts.size()==4) // otherwise this is a partial zone
for(unsigned int n=1; n < parts.size(); ++n) {
- dr.d_content=std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(QType::PTR, 1, DNSName(parts[n]).toString())); // XXX FIXME DNSNAME PAIN CAN THIS BE RIGHT?
+ dr.d_content=DNSRecordContent::mastermake(QType::PTR, 1, DNSName(parts[n]).toString()); // XXX FIXME DNSNAME PAIN CAN THIS BE RIGHT?
ad.d_records.insert(dr);
}
for(char c='a'; c<= 'm';++c) {
pw.startRecord(DNSName("com"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY);
gtld[0]=c;
- DNSRecordContent* drc = DNSRecordContent::mastermake(QType::NS, 1, gtld);
+ std::unique_ptr<DNSRecordContent> drc = DNSRecordContent::makeunique(QType::NS, 1, gtld);
drc->toPacket(pw);
- delete drc;
}
for(char c='a'; c<= 'k';++c) {
gtld[0]=c;
pw.startRecord(DNSName(gtld), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL);
- DNSRecordContent* drc = DNSRecordContent::mastermake(QType::A, 1, "1.2.3.4");
+ std::unique_ptr<DNSRecordContent> drc = DNSRecordContent::makeunique(QType::A, 1, "1.2.3.4");
drc->toPacket(pw);
- delete drc;
}
pw.startRecord(DNSName("a.gtld-servers.net"), QType::AAAA, 3600, 1, DNSResourceRecord::ADDITIONAL);
- auto aaaarc = DNSRecordContent::mastermake(QType::AAAA, 1, "2001:503:a83e::2:30");
+ auto aaaarc = DNSRecordContent::makeunique(QType::AAAA, 1, "2001:503:a83e::2:30");
aaaarc->toPacket(pw);
- delete aaaarc;
pw.startRecord(DNSName("b.gtld-servers.net"), QType::AAAA, 3600, 1, DNSResourceRecord::ADDITIONAL);
- aaaarc = DNSRecordContent::mastermake(QType::AAAA, 1, "2001:503:231d::2:30");
+ aaaarc = DNSRecordContent::makeunique(QType::AAAA, 1, "2001:503:231d::2:30");
aaaarc->toPacket(pw);
- delete aaaarc;
pw.commit();
// shuffle(records);
for(const auto& rec : records) {
pw.startRecord(rec.qname, rec.qtype.getCode(), rec.ttl, 1, DNSResourceRecord::ADDITIONAL);
- auto drc = DNSRecordContent::mastermake(rec.qtype.getCode(), 1, rec.content);
+ auto drc = DNSRecordContent::makeunique(rec.qtype.getCode(), 1, rec.content);
drc->toPacket(pw);
- delete drc;
}
pw.commit();
void operator()() const
{
- DNSRecordContent*drc = DNSRecordContent::mastermake(QType::A, 1,
- "1.2.3.4");
- delete drc;
+ auto drc = DNSRecordContent::makeunique(QType::A, 1,
+ "1.2.3.4");
}
};
DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), d_type);
for(int records = 0; records < d_records; records++) {
pw.startRecord(DNSName("outpost.ds9a.nl"), d_type);
- DNSRecordContent*drc = DNSRecordContent::mastermake(d_type, 1,
- d_content);
+ auto drc = DNSRecordContent::makeunique(d_type, 1,
+ d_content);
drc->toPacket(pw);
- delete drc;
}
pw.commit();
}
DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::AAAA);
for(int records = 0; records < d_records; records++) {
pw.startRecord(DNSName("outpost.ds9a.nl"), QType::AAAA);
- DNSRecordContent*drc = DNSRecordContent::mastermake(QType::AAAA, 1, "fe80::21d:92ff:fe6d:8441");
+ auto drc = DNSRecordContent::makeunique(QType::AAAA, 1, "fe80::21d:92ff:fe6d:8441");
drc->toPacket(pw);
- delete drc;
}
pw.commit();
}
for(int records = 0; records < d_records; records++) {
pw.startRecord(DNSName("outpost.ds9a.nl"), QType::SOA);
- DNSRecordContent*drc = DNSRecordContent::mastermake(QType::SOA, 1, "a0.org.afilias-nst.info. noc.afilias-nst.info. 2008758137 1800 900 604800 86400");
+ auto drc = DNSRecordContent::makeunique(QType::SOA, 1, "a0.org.afilias-nst.info. noc.afilias-nst.info. 2008758137 1800 900 604800 86400");
drc->toPacket(pw);
- delete drc;
}
pw.commit();
}
DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::A);
pw.startRecord(DNSName("ds9a.nl"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY);
- DNSRecordContent* drc = DNSRecordContent::mastermake(QType::NS, 1, "ns1.ds9a.nl");
+ auto drc = DNSRecordContent::makeunique(QType::NS, 1, "ns1.ds9a.nl");
drc->toPacket(pw);
- delete drc;
pw.startRecord(DNSName("ds9a.nl"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY);
- drc = DNSRecordContent::mastermake(QType::NS, 1, "ns2.ds9a.nl");
+ drc = DNSRecordContent::makeunique(QType::NS, 1, "ns2.ds9a.nl");
drc->toPacket(pw);
- delete drc;
pw.startRecord(DNSName("ns1.ds9a.nl"), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL);
- drc = DNSRecordContent::mastermake(QType::A, 1, "1.2.3.4");
+ drc = DNSRecordContent::makeunique(QType::A, 1, "1.2.3.4");
drc->toPacket(pw);
- delete drc;
pw.startRecord(DNSName("ns2.ds9a.nl"), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL);
- drc = DNSRecordContent::mastermake(QType::A, 1, "4.3.2.1");
+ drc = DNSRecordContent::makeunique(QType::A, 1, "4.3.2.1");
drc->toPacket(pw);
- delete drc;
pw.commit();
return packet;
dr.d_ttl = 86400;
for (const auto& ans : answers) {
dr.d_type = ans.first;
- dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(ans.first, qclass, ans.second));
+ dr.d_content = DNSRecordContent::mastermake(ans.first, qclass, ans.second);
ret.push_back(dr);
}
}
try {
std::string recData;
if (q.getCode() != QType::TSIG) {
- boost::scoped_ptr<DNSRecordContent> rec(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>()));
+ auto rec = DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>());
BOOST_CHECK_MESSAGE(rec != NULL, "mastermake( " << q.getCode() << ", 1, " << val.get<1>() << ") returned NULL");
if (rec == NULL) continue;
// now verify the record (note that this will be same as *zone* value (except for certain QTypes)
if (val.get<2>()) {
bool success=true;
- BOOST_WARN_EXCEPTION( { boost::scoped_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::exception, test_dnsrecords_cc_predicate );
+ BOOST_WARN_EXCEPTION( { auto drc = DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>()); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::exception, test_dnsrecords_cc_predicate );
if (success==false) REC_FAIL_XSUCCESS2(q.getName() << " test #" << n << " has unexpectedly passed"); // a bad record was detected when it was supposed not to be detected
} else {
- BOOST_CHECK_EXCEPTION( { boost::scoped_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::exception, test_dnsrecords_cc_predicate );
+ BOOST_CHECK_EXCEPTION( { auto drc = DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>()); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::exception, test_dnsrecords_cc_predicate );
}
};
}
/** Helper to build a record content as needed. */
static inline string makeRecordContent(const QType& qtype, const string& content, bool noDot) {
// noDot: for backend storage, pass true. for API users, pass false.
- std::unique_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(qtype.getCode(), 1, content));
+ std::unique_ptr<DNSRecordContent> drc(DNSRecordContent::makeunique(qtype.getCode(), QClass::IN, content));
return drc->getZoneRepresentation(noDot);
}