Skip to content

Commit

Permalink
Auth: Adapt to QType class changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredmorcos committed Jul 4, 2024
1 parent 02dac74 commit 49414ec
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion modules/bindbackend/bindbackend2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ void Bind2Backend::doEmptyNonTerminals(std::shared_ptr<recordstorage_t>& records
}

DNSResourceRecord rr;
rr.qtype = "#0";
rr.qtype = QType::fromString("#0");
rr.content = "";
rr.ttl = 0;
for (auto& nt : nonterm) {
Expand Down
2 changes: 1 addition & 1 deletion modules/geoipbackend/geoipbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ bool GeoIPBackend::loadDomain(const YAML::Node& domain, std::uint32_t domainID,
}
else {
string qtype = boost::to_upper_copy(rec->first.as<string>());
rr.qtype = qtype;
rr.qtype = QType::fromString(qtype);
}
rr.has_weight = false;
rr.weight = 100;
Expand Down
2 changes: 1 addition & 1 deletion modules/ldapbackend/ldapbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void LdapBackend::extract_entry_results(const DNSName& domain, const DNSResult&
attrname = attribute.first;
// extract qtype string from ldap attribute name by removing the 'Record' suffix.
qstr = attrname.substr(0, attrname.length() - 6);
qt = toUpper(qstr);
qt = QType::fromString(qstr);

for (const auto& value : attribute.second) {
if (qtype != qt && qtype != QType::ANY) {
Expand Down
2 changes: 1 addition & 1 deletion modules/lua2backend/lua2api2.hh
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public:
if (item.second.which() == 1)
rec.qtype = QType(boost::get<int>(item.second));
else if (item.second.which() == 3)
rec.qtype = boost::get<string>(item.second);
rec.qtype = QType::fromString(boost::get<string>(item.second));
else if (item.second.which() == 4)
rec.qtype = boost::get<QType>(item.second);
else
Expand Down
2 changes: 1 addition & 1 deletion modules/pipebackend/pipebackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ bool PipeBackend::get(DNSResourceRecord& r)
r.auth = true;
}
r.qname = DNSName(parts[1 + extraFields]);
r.qtype = parts[3 + extraFields];
r.qtype = QType::fromString(parts[3 + extraFields]);
pdns::checked_stoi_into(r.ttl, parts[4 + extraFields]);
pdns::checked_stoi_into(r.domain_id, parts[5 + extraFields]);

Expand Down
4 changes: 2 additions & 2 deletions modules/remotebackend/remotebackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ bool RemoteBackend::get(DNSResourceRecord& rr)
return false;
}

rr.qtype = stringFromJson(d_result["result"][d_index], "qtype");
rr.qtype = QType::fromString(stringFromJson(d_result["result"][d_index], "qtype"));
rr.qname = DNSName(stringFromJson(d_result["result"][d_index], "qname"));
rr.qclass = QClass::IN;
rr.content = stringFromJson(d_result["result"][d_index], "content");
Expand Down Expand Up @@ -853,7 +853,7 @@ bool RemoteBackend::searchRecords(const string& pattern, size_t maxResults, vect

for (const auto& row : answer["result"].array_items()) {
DNSResourceRecord rr;
rr.qtype = stringFromJson(row, "qtype");
rr.qtype = QType::fromString(stringFromJson(row, "qtype"));
rr.qname = DNSName(stringFromJson(row, "qname"));
rr.qclass = QClass::IN;
rr.content = stringFromJson(row, "content");
Expand Down
4 changes: 2 additions & 2 deletions pdns/backends/gsql/gsqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,7 @@ void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r)
else
r.qname=DNSName(row[6]);

r.qtype=row[3];
r.qtype = QType::fromString(row[3]);

if (d_upgradeContent && DNSRecordContent::isUnknownType(row[3]) && DNSRecordContent::isRegisteredType(r.qtype, r.qclass)) {
r.content = DNSRecordContent::upgradeContent(r.qname, r.qtype, row[0]);
Expand Down Expand Up @@ -2324,7 +2324,7 @@ void GSQLBackend::extractComment(SSqlStatement::row_t& row, Comment& comment)
{
pdns::checked_stoi_into(comment.domain_id, row[0]);
comment.qname = DNSName(row[1]);
comment.qtype = row[2];
comment.qtype = QType::fromString(row[2]);
pdns::checked_stoi_into(comment.modified_at, row[3]);
comment.account = std::move(row[4]);
comment.content = std::move(row[5]);
Expand Down
4 changes: 2 additions & 2 deletions pdns/lua-auth4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void AuthLua4::postPrepareContext() {
d_lw->registerFunction<DNSPacket, void()>("clearRecords",[](DNSPacket &p){p.clearRecords();});
d_lw->registerFunction<DNSPacket, void(DNSRecord&, bool)>("addRecord", [](DNSPacket &p, DNSRecord &dr, bool auth) { DNSZoneRecord dzr; dzr.dr = dr; dzr.auth = auth; p.addRecord(std::move(dzr)); });
d_lw->registerFunction<DNSPacket, void(const vector<pair<unsigned int, DNSRecord> >&)>("addRecords", [](DNSPacket &p, const vector<pair<unsigned int, DNSRecord> >& records){ for(const auto &dr: records){ DNSZoneRecord dzr; dzr.dr = std::get<1>(dr); dzr.auth = true; p.addRecord(std::move(dzr)); }});
d_lw->registerFunction<DNSPacket, void(unsigned int, const DNSName&, const std::string&)>("setQuestion", [](DNSPacket &p, unsigned int opcode, const DNSName &name, const string &type){ QType qtype; qtype = type; p.setQuestion(static_cast<int>(opcode), name, static_cast<int>(qtype.getCode())); });
d_lw->registerFunction<DNSPacket, void(unsigned int, const DNSName&, const std::string&)>("setQuestion", [](DNSPacket &packet, unsigned int opcode, const DNSName &name, const string &type){ QType qtype; qtype = QType::fromString(type); packet.setQuestion(static_cast<int>(opcode), name, static_cast<int>(qtype.getCode())); });
d_lw->registerFunction<DNSPacket, bool()>("isEmpty", [](DNSPacket &p){return p.isEmpty();});
d_lw->registerFunction<DNSPacket, std::shared_ptr<DNSPacket>()>("replyPacket",[](DNSPacket& p){ return p.replyPacket();});
d_lw->registerFunction<DNSPacket, bool()>("hasEDNSSubnet", [](DNSPacket &p){return p.hasEDNSSubnet();});
Expand All @@ -70,7 +70,7 @@ void AuthLua4::postPrepareContext() {
d_lw->registerMember<DNSPacket, DNSName>("qdomainzone", [](const DNSPacket &p) -> DNSName { return p.qdomainzone; }, [](DNSPacket &p, const DNSName& name) { p.qdomainzone = name; });

d_lw->registerMember<DNSPacket, std::string>("d_peer_principal", [](const DNSPacket &p) -> std::string { return p.d_peer_principal; }, [](DNSPacket &p, const std::string &princ) { p.d_peer_principal = princ; });
d_lw->registerMember<DNSPacket, const std::string>("qtype", [](const DNSPacket &p) -> const std::string { return p.qtype.toString(); }, [](DNSPacket &p, const std::string &type) { p.qtype = type; });
d_lw->registerMember<DNSPacket, const std::string>("qtype", [](const DNSPacket &packet) -> std::string { return packet.qtype.toString(); }, [](DNSPacket &packet, const std::string &type) { packet.qtype = QType::fromString(type); });
/* End of DNSPacket */


Expand Down
6 changes: 3 additions & 3 deletions pdns/lua-base4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void BaseLua4::prepareContext() {
d_lw->writeFunction("newDRR", [](const DNSName& qname, const string& qtype, const unsigned int ttl, const string& content, boost::optional<int> domain_id, boost::optional<int> auth){
auto drr = DNSResourceRecord();
drr.qname = qname;
drr.qtype = qtype;
drr.qtype = QType::fromString(qtype);
drr.ttl = ttl;
drr.setContent(content);
if (domain_id)
Expand Down Expand Up @@ -177,7 +177,7 @@ void BaseLua4::prepareContext() {
d_lw->registerFunction<bool(cas_t::*)(const ComboAddress&)>("check",[](const cas_t& cas, const ComboAddress&ca) { return cas.count(ca)>0; });

// QType
d_lw->writeFunction("newQType", [](const string& s) { QType q; q = s; return q; });
d_lw->writeFunction("newQType", [](const string& newQType) { QType qType; qType = QType::fromString(newQType); return qType; });
d_lw->registerFunction("getCode", &QType::getCode);
d_lw->registerFunction("getName", &QType::toString);
d_lw->registerEqFunction<bool(QType::*)(const QType&)>([](const QType& a, const QType& b){ return a == b;}); // operator overloading confuses LuaContext
Expand Down Expand Up @@ -216,7 +216,7 @@ void BaseLua4::prepareContext() {
d_lw->registerFunction("match", (bool (NetmaskGroup::*)(const ComboAddress&) const)&NetmaskGroup::match);

// DNSRecord
d_lw->writeFunction("newDR", [](const DNSName& name, const std::string& type, unsigned int ttl, const std::string& content, int place) { QType qtype; qtype = type; auto dr = DNSRecord(); dr.d_name = name; dr.d_type = qtype.getCode(); dr.d_ttl = ttl; dr.setContent(shared_ptr<DNSRecordContent>(DNSRecordContent::make(dr.d_type, QClass::IN, content))); dr.d_place = static_cast<DNSResourceRecord::Place>(place); return dr; });
d_lw->writeFunction("newDR", [](const DNSName& name, const std::string& type, unsigned int ttl, const std::string& content, int place) { QType qtype; qtype = QType::fromString(type); auto dnsRecord = DNSRecord(); dnsRecord.d_name = name; dnsRecord.d_type = qtype.getCode(); dnsRecord.d_ttl = ttl; dnsRecord.setContent(shared_ptr<DNSRecordContent>(DNSRecordContent::make(dnsRecord.d_type, QClass::IN, content))); dnsRecord.d_place = static_cast<DNSResourceRecord::Place>(place); return dnsRecord; });
d_lw->registerMember("name", &DNSRecord::d_name);
d_lw->registerMember("type", &DNSRecord::d_type);
d_lw->registerMember("ttl", &DNSRecord::d_ttl);
Expand Down
7 changes: 4 additions & 3 deletions pdns/pdnsutil.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "dnsrecords.hh"
#include "qtype.hh"
#include <boost/smart_ptr/make_shared_array.hpp>
#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -1497,7 +1498,7 @@ static int createZone(const DNSName &zone, const DNSName& nsname) {
rr.qname = zone;
rr.auth = true;
rr.ttl = ::arg().asNum("default-ttl");
rr.qtype = "SOA";
rr.qtype = QType::fromString("SOA");

string soa = ::arg()["default-soa-content"];
boost::replace_all(soa, "@", zone.toStringNoDot());
Expand Down Expand Up @@ -1735,9 +1736,9 @@ static int deleteRRSet(const std::string& zone_, const std::string& name_, const
else
name=DNSName(name_)+zone;

QType qt(QType::chartocode(type_.c_str()));
QType qType(QType::fromString(type_));
di.backend->startTransaction(zone, -1);
di.backend->replaceRRSet(di.id, name, qt, vector<DNSResourceRecord>());
di.backend->replaceRRSet(di.id, name, qType, vector<DNSResourceRecord>());
di.backend->commitTransaction();
return EXIT_SUCCESS;
}
Expand Down
30 changes: 15 additions & 15 deletions pdns/test-dnsrecords_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ BOOST_AUTO_TEST_SUITE(test_dnsrecords_cc)

BOOST_AUTO_TEST_CASE(test_record_types) {
// tuple contains <type, user value, zone representation, line value, broken>
typedef boost::tuple<QType::typeenum, std::string, std::string, std::string, broken_marker> case_t;
typedef std::list<case_t> cases_t;
using case_t = boost::tuple<QType::QTypeEnum, std::string, std::string, std::string, broken_marker>;
using cases_t = std::list<case_t>;
MRRecordContent::report();
IPSECKEYRecordContent::report();
KXRecordContent::report();
Expand Down Expand Up @@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
(CASE_S(QType::CAA, "0 issue \"aaaaaaa\"", "\x00\x05\x69\x73\x73\x75\x65\x61\x61\x61\x61\x61\x61\x61"))
(CASE_S(QType::CAA, "0 issue \"aaaaaaa.aaa\"", "\x00\x05\x69\x73\x73\x75\x65\x61\x61\x61\x61\x61\x61\x61\x2e\x61\x61\x61"))
(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"))
(CASE_S((QType::typeenum)65226,"\\# 3 414243","\x41\x42\x43"))
(CASE_S((QType::QTypeEnum)65226,"\\# 3 414243","\x41\x42\x43"))

;

Expand Down Expand Up @@ -349,8 +349,8 @@ BOOST_AUTO_TEST_CASE(test_record_types_bad_values) {
enum class case_type_t { zone, wire };

// qtype, value, zone/wire format, broken
typedef boost::tuple<const QType::typeenum, const std::string, case_type_t, broken_marker> case_t;
typedef std::list<case_t> cases_t;
using case_t = boost::tuple<const QType::QTypeEnum, const std::string, case_type_t, broken_marker>;
using cases_t = std::list<case_t>;

#define ZONE_CASE(type, input) case_t(type, BINARY(input), case_type_t::zone, broken_marker::WORKING)
#define WIRE_CASE(type, input) case_t(type, BINARY(input), case_type_t::wire, broken_marker::WORKING)
Expand Down Expand Up @@ -471,27 +471,27 @@ BOOST_AUTO_TEST_CASE(test_opt_record_out) {
// special record test, because Unknown record types are the worst
BOOST_AUTO_TEST_CASE(test_unknown_records_in) {

auto validUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\# 1 42");
auto validUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\# 1 42");

// we need at least two parts
BOOST_CHECK_THROW(auto notEnoughPartsUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\#"), MOADNSException);
BOOST_CHECK_THROW(auto notEnoughPartsUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\#"), MOADNSException);

// two parts are OK when the RDATA size is 0, not OK otherwise
auto validEmptyUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\# 0");
BOOST_CHECK_THROW(auto twoPartsNotZeroUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\# 1"), MOADNSException);
auto validEmptyUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\# 0");
BOOST_CHECK_THROW(auto twoPartsNotZeroUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\# 1"), MOADNSException);

// the first part has to be "\#"
BOOST_CHECK_THROW(auto invalidFirstPartUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\$ 0"), MOADNSException);
BOOST_CHECK_THROW(auto invalidFirstPartUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\$ 0"), MOADNSException);

// RDATA length is not even
BOOST_CHECK_THROW(auto unevenUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\# 1 A"), MOADNSException);
BOOST_CHECK_THROW(auto unevenUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\# 1 A"), MOADNSException);

// RDATA length is not equal to the expected size
BOOST_CHECK_THROW(auto wrongRDATASizeUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\# 2 AA"), MOADNSException);
BOOST_CHECK_THROW(auto wrongRDATASizeUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\# 2 AA"), MOADNSException);

// RDATA is invalid (invalid hex value)
try {
auto invalidRDATAUnknown = DNSRecordContent::make(static_cast<QType::typeenum>(65534), QClass::IN, "\\# 1 JJ");
auto invalidRDATAUnknown = DNSRecordContent::make(static_cast<QType::QTypeEnum>(65534), QClass::IN, "\\# 1 JJ");
// we should not reach that code
BOOST_CHECK(false);
// but if we do let's see what we got (likely what was left over on the stack)
Expand Down Expand Up @@ -596,7 +596,7 @@ BOOST_AUTO_TEST_CASE(test_nsec_records_types) {
auto nsecContent = std::dynamic_pointer_cast<NSECRecordContent>(validNSEC);
BOOST_REQUIRE(nsecContent);

for (const auto type : { QType::A, QType::MX, QType::RRSIG, QType::NSEC, static_cast<QType::typeenum>(1234) }) {
for (const auto type : { QType::A, QType::MX, QType::RRSIG, QType::NSEC, static_cast<QType::QTypeEnum>(1234) }) {
BOOST_CHECK(nsecContent->isSet(type));
}
BOOST_CHECK_EQUAL(nsecContent->isSet(QType::NSEC3), false);
Expand Down Expand Up @@ -648,7 +648,7 @@ BOOST_AUTO_TEST_CASE(test_nsec3_records_types) {
auto nsec3Content = std::dynamic_pointer_cast<NSEC3RecordContent>(validNSEC3);
BOOST_REQUIRE(nsec3Content);

for (const auto type : { QType::A, QType::MX, QType::RRSIG, QType::NSEC3, static_cast<QType::typeenum>(1234), static_cast<QType::typeenum>(65535) }) {
for (const auto type : { QType::A, QType::MX, QType::RRSIG, QType::NSEC3, static_cast<QType::QTypeEnum>(1234), static_cast<QType::QTypeEnum>(65535) }) {
BOOST_CHECK(nsec3Content->isSet(type));
}
BOOST_CHECK_EQUAL(nsec3Content->isSet(QType::NSEC), false);
Expand Down
8 changes: 4 additions & 4 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
qType = QType::ANY;
}
else {
qType = req->getvars["rrset_type"];
qType = QType::fromString(req->getvars["rrset_type"]);
}
domainInfo.backend->lookup(qType, DNSName(req->getvars["rrset_name"]), static_cast<int>(domainInfo.id));
}
Expand Down Expand Up @@ -1908,7 +1908,7 @@ static void apiServerZonesPOST(HttpRequest* req, HttpResponse* resp)
DNSName qname = apiNameToDNSName(stringFromJson(rrset, "name"));
apiCheckQNameAllowedCharacters(qname.toString());
QType qtype;
qtype = stringFromJson(rrset, "type");
qtype = QType::fromString(stringFromJson(rrset, "type"));
if (qtype.getCode() == 0) {
throw ApiException("RRset " + qname.toString() + " IN " + stringFromJson(rrset, "type") + ": unknown type given");
}
Expand Down Expand Up @@ -2124,7 +2124,7 @@ static void apiServerZoneDetailPUT(HttpRequest* req, HttpResponse* resp)
DNSName qname = apiNameToDNSName(stringFromJson(rrset, "name"));
apiCheckQNameAllowedCharacters(qname.toString());
QType qtype;
qtype = stringFromJson(rrset, "type");
qtype = QType::fromString(stringFromJson(rrset, "type"));
if (qtype.getCode() == 0) {
throw ApiException("RRset " + qname.toString() + " IN " + stringFromJson(rrset, "type") + ": unknown type given");
}
Expand Down Expand Up @@ -2337,7 +2337,7 @@ static void patchZone(UeberBackend& backend, const DNSName& zonename, DomainInfo
DNSName qname = apiNameToDNSName(stringFromJson(rrset, "name"));
apiCheckQNameAllowedCharacters(qname.toString());
QType qtype;
qtype = stringFromJson(rrset, "type");
qtype = QType::fromString(stringFromJson(rrset, "type"));
if (qtype.getCode() == 0) {
throw ApiException("RRset " + qname.toString() + " IN " + stringFromJson(rrset, "type") + ": unknown type given");
}
Expand Down

0 comments on commit 49414ec

Please sign in to comment.