* DNSSEC: Yes
* Disabled data: No
* Comments: No
-* Search: No
+* Search: Yes\*
* Views: No
* API: Read-Write
* Multiple instances: Yes
domaininfo. See :ref:`dns_get_domaininfo() <backends_lua2_dns_get_domaininfo>`.
NOTES:
- This function is **optional**, except if you need primary functionality.
+ This function is **optional**, except if you need primary functionality. It
+ is required if you want to be able to search records.
``dns_get_domain_metadata(domain, kind)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* DNSSEC: No
* Disabled data: No
* Comments: No
-* Search: No
+* Search: since version 5.1.0
* Views: No
* API: Read-only
* Multiple Instances: Yes
unsigned int Bind2Backend::getCapabilities()
{
- unsigned int caps = CAP_LIST;
+ unsigned int caps = CAP_LIST | CAP_SEARCH;
if (d_hybrid) {
caps |= CAP_DNSSEC;
}
unsigned int Bind2Backend::getCapabilities()
{
- unsigned int caps = CAP_LIST;
+ unsigned int caps = CAP_LIST | CAP_SEARCH;
if (d_dnssecdb || d_hybrid) {
caps |= CAP_DNSSEC;
}
unsigned int LMDBBackend::getCapabilities()
{
- unsigned int caps = CAP_DNSSEC | CAP_DIRECT | CAP_LIST | CAP_CREATE;
+ unsigned int caps = CAP_DNSSEC | CAP_DIRECT | CAP_LIST | CAP_CREATE | CAP_SEARCH;
if (d_views) {
caps |= CAP_VIEWS;
}
return comments.empty();
}
-bool LMDBBackend::searchRecords(const string& pattern, size_t maxResults, vector<DNSResourceRecord>& result)
-{
- SimpleMatch simpleMatch(pattern, true);
- std::vector<DomainInfo> domains;
- getAllDomains(&domains, false, true);
- for (const auto& info : domains) {
- if (!list(info.zone, info.id, true)) {
- return false;
- }
- DNSResourceRecord rec;
- while (get(rec)) {
- if (maxResults == 0) {
- continue;
- }
- if (simpleMatch.match(rec.qname.toStringNoDot()) || simpleMatch.match(rec.content)) {
- result.emplace_back(rec);
- --maxResults;
- }
- }
- if (maxResults == 0) {
- break;
- }
- }
- return true;
-}
-
// FIXME: this is not very efficient
static DNSName keyUnconv(std::string& instr)
{
bool feedEnts3(domainid_t domain_id, const DNSName& domain, map<DNSName, bool>& nonterm, const NSEC3PARAMRecordContent& ns3prc, bool narrow) override;
bool replaceRRSet(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<DNSResourceRecord>& rrset) override;
bool replaceComments(domainid_t domain_id, const DNSName& qname, const QType& qt, const vector<Comment>& comments) override;
- bool searchRecords(const string& pattern, size_t maxResults, vector<DNSResourceRecord>& result) override;
void viewList(vector<string>& /* result */) override;
void viewListZones(const string& /* view */, vector<ZoneName>& /* result */) override;
if (d_dnssec) {
caps |= CAP_DNSSEC;
}
+ if (f_get_all_domains != nullptr) {
+ caps |= CAP_SEARCH;
+ }
return caps;
}
unsigned int RemoteBackend::getCapabilities()
{
- unsigned int caps = CAP_DIRECT | CAP_LIST;
+ unsigned int caps = CAP_DIRECT | CAP_LIST | CAP_SEARCH;
if (d_dnssec) {
caps |= CAP_DNSSEC;
}
// Methods for simple operation
TinyDNSBackend(const string& suffix);
- unsigned int getCapabilities() override { return CAP_LIST; }
+ unsigned int getCapabilities() override { return CAP_LIST | CAP_SEARCH; }
void lookup(const QType& qtype, const DNSName& qdomain, domainid_t zoneId, DNSPacket* pkt_p = nullptr) override;
bool list(const ZoneName& target, domainid_t domain_id, bool include_disabled = false) override;
bool get(DNSResourceRecord& rr) override;
unsigned int GSQLBackend::getCapabilities()
{
- unsigned int caps = CAP_COMMENTS | CAP_DIRECT | CAP_LIST | CAP_CREATE;
+ unsigned int caps = CAP_COMMENTS | CAP_DIRECT | CAP_LIST | CAP_CREATE | CAP_SEARCH;
if (d_dnssecQueries) {
caps |= CAP_DNSSEC;
}
lookup(qtype, qdomain, zoneId, nullptr);
}
+// Default search logic, for backends which can enumerate their records.
+bool DNSBackend::searchRecords(const string& pattern, size_t maxResults, vector<DNSResourceRecord>& result)
+{
+ // We depend upon working list(), but also getAllDomains(), which is why we
+ // are checking explicitly for CAP_SEARCH in addition to CAP_LIST - the
+ // default getAllDomains() implementation below is not safe to use here.
+ if ((getCapabilities() & (CAP_LIST | CAP_SEARCH)) != (CAP_LIST | CAP_SEARCH)) {
+ return false;
+ }
+
+ SimpleMatch simpleMatch(pattern, true);
+ std::vector<DomainInfo> domains;
+ getAllDomains(&domains, false, true);
+ for (const auto& info : domains) {
+ if (!list(info.zone, info.id, true)) {
+ return false;
+ }
+ DNSResourceRecord rec;
+ while (get(rec)) {
+ if (maxResults == 0) {
+ continue;
+ }
+ if (simpleMatch.match(rec.qname) || simpleMatch.match(rec.content)) {
+ result.emplace_back(rec);
+ --maxResults;
+ }
+ }
+ if (maxResults == 0) {
+ break;
+ }
+ }
+ return true;
+}
+
void BackendFactory::declare(const string& suffix, const string& param, const string& explanation, const string& value)
{
string fullname = d_name + suffix + "-" + param;
CAP_LIST = 1 << 3, // Backend supports record enumeration
CAP_CREATE = 1 << 4, // Backend supports domain creation
CAP_VIEWS = 1 << 5, // Backend supports views
+ CAP_SEARCH = 1 << 6, // Backend supports record search
};
virtual unsigned int getCapabilities() = 0;
}
//! Search for records, returns true if search was done successfully.
- virtual bool searchRecords(const string& /* pattern */, size_t /* maxResults */, vector<DNSResourceRecord>& /* result */)
- {
- return false;
- }
+ virtual bool searchRecords(const string& pattern, size_t maxResults, vector<DNSResourceRecord>& result);
//! Search for comments, returns true if search was done successfully.
virtual bool searchComments(const string& /* pattern */, size_t /* maxResults */, vector<Comment>& /* result */)