• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 20620434726

31 Dec 2025 01:55PM UTC coverage: 72.639% (-0.7%) from 73.336%
20620434726

Pull #16693

github

web-flow
Merge 75adbd9e6 into 256926769
Pull Request #16693: auth: plumbing for structured logging

39004 of 65428 branches covered (59.61%)

Branch coverage included in aggregate %.

804 of 2391 new or added lines in 58 files covered. (33.63%)

376 existing lines in 43 files now uncovered.

129164 of 166085 relevant lines covered (77.77%)

5086166.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.62
/modules/lua2backend/lua2api2.hh
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTAPILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
#pragma once
23
#include "boost/algorithm/string/join.hpp"
24
#include "pdns/arguments.hh"
25

26
#include "pdns/dnsbackend.hh"
27
#include "pdns/lua-auth4.hh"
28

29
class Lua2BackendAPIv2 : public DNSBackend, AuthLua4
30
{
31
private:
32
  typedef std::function<void()> init_call_t;
33
  typedef std::function<void()> deinit_call_t;
34

35
  typedef std::vector<std::pair<string, string>> lookup_context_t;
36

37
  typedef std::vector<std::pair<int, std::vector<std::pair<string, boost::variant<bool, int, DNSName, string, QType>>>>> lookup_result_t;
38
  typedef std::function<lookup_result_t(const QType& qtype, const DNSName& qname, domainid_t domain_id, const lookup_context_t& ctx)> lookup_call_t;
39

40
  typedef boost::variant<bool, lookup_result_t> list_result_t;
41
  typedef std::function<list_result_t(const DNSName& qname, domainid_t domain_id)> list_call_t;
42

43
  typedef vector<pair<string, boost::variant<bool, long, string, vector<string>>>> domaininfo_result_t;
44
  typedef boost::variant<bool, domaininfo_result_t> get_domaininfo_result_t;
45
  typedef vector<pair<DNSName, domaininfo_result_t>> get_all_domains_result_t;
46
  typedef std::function<get_domaininfo_result_t(const DNSName& domain)> get_domaininfo_call_t;
47
  typedef std::function<get_all_domains_result_t()> get_all_domains_call_t;
48

49
  typedef vector<pair<int, string>> domain_metadata_result_t;
50
  typedef boost::variant<bool, domain_metadata_result_t> get_domain_metadata_result_t;
51
  typedef boost::variant<bool, vector<pair<string, domain_metadata_result_t>>> get_all_domain_metadata_result_t;
52
  typedef std::function<get_domain_metadata_result_t(const DNSName& domain, const string& kind)> get_domain_metadata_call_t;
53
  typedef std::function<get_all_domain_metadata_result_t(const DNSName& domain)> get_all_domain_metadata_call_t;
54

55
  typedef vector<pair<string, boost::variant<bool, int, string>>> keydata_result_t;
56
  typedef boost::variant<bool, vector<pair<int, keydata_result_t>>> get_domain_keys_result_t;
57
  typedef std::function<get_domain_keys_result_t(const DNSName& domain)> get_domain_keys_call_t;
58

59
  typedef std::vector<std::pair<string, boost::variant<string, DNSName>>> before_and_after_names_result_t;
60
  typedef boost::variant<bool, before_and_after_names_result_t> get_before_and_after_names_absolute_result_t;
61
  typedef std::function<get_before_and_after_names_absolute_result_t(domainid_t id, const DNSName& qname)> get_before_and_after_names_absolute_call_t;
62

63
  typedef std::function<void(domainid_t, long)> set_notified_call_t;
64

65
  typedef std::function<string(const string& cmd)> direct_backend_cmd_call_t;
66

67
public:
68
  Lua2BackendAPIv2(std::shared_ptr<Logr::Logger> slog, const string& suffix)
69
  {
21✔
70
    d_slog = slog;
21✔
71
    d_include_path = ::arg()["lua-global-include-dir"];
21✔
72
    setArgPrefix("lua2" + suffix);
21✔
73
    d_debug_log = mustDo("query-logging");
21✔
74
    prepareContext();
21✔
75
    loadFile(getArg("filename"));
21✔
76
  }
21✔
77

78
  ~Lua2BackendAPIv2() override;
79

80
  void postPrepareContext() override
81
  {
21✔
82
    AuthLua4::postPrepareContext();
21✔
83
  }
21✔
84

85
  void postLoad() override
86
  {
21✔
87
    f_lookup = d_lw->readVariable<boost::optional<lookup_call_t>>("dns_lookup").get_value_or(0);
21✔
88
    f_list = d_lw->readVariable<boost::optional<list_call_t>>("dns_list").get_value_or(0);
21✔
89
    f_get_all_domains = d_lw->readVariable<boost::optional<get_all_domains_call_t>>("dns_get_all_domains").get_value_or(0);
21✔
90
    f_get_domaininfo = d_lw->readVariable<boost::optional<get_domaininfo_call_t>>("dns_get_domaininfo").get_value_or(0);
21✔
91
    f_get_domain_metadata = d_lw->readVariable<boost::optional<get_domain_metadata_call_t>>("dns_get_domain_metadata").get_value_or(0);
21✔
92
    f_get_all_domain_metadata = d_lw->readVariable<boost::optional<get_all_domain_metadata_call_t>>("dns_get_all_domain_metadata").get_value_or(0);
21✔
93
    f_get_domain_keys = d_lw->readVariable<boost::optional<get_domain_keys_call_t>>("dns_get_domain_keys").get_value_or(0);
21✔
94
    f_get_before_and_after_names_absolute = d_lw->readVariable<boost::optional<get_before_and_after_names_absolute_call_t>>("dns_get_before_and_after_names_absolute").get_value_or(0);
21✔
95
    f_set_notified = d_lw->readVariable<boost::optional<set_notified_call_t>>("dns_set_notified").get_value_or(0);
21✔
96

97
    auto init = d_lw->readVariable<boost::optional<init_call_t>>("dns_init").get_value_or(0);
21✔
98
    if (init) {
21!
99
      init();
×
100
    }
×
101

102
    f_deinit = d_lw->readVariable<boost::optional<deinit_call_t>>("dns_deinit").get_value_or(0);
21✔
103

104
    if (f_lookup == nullptr) {
21!
105
      throw PDNSException("dns_lookup missing");
×
106
    }
×
107

108
    /* see if dnssec support is wanted */
109
    d_dnssec = d_lw->readVariable<boost::optional<bool>>("dns_dnssec").get_value_or(false);
21✔
110
    if (d_dnssec) {
21✔
111
      if (f_get_domain_metadata == nullptr) {
15!
112
        throw PDNSException("dns_dnssec is true but dns_get_domain_metadata is missing");
×
113
      }
×
114
      if (f_get_before_and_after_names_absolute == nullptr) {
15!
115
        throw PDNSException("dns_dnssec is true but dns_get_before_and_after_names_absolute is missing");
×
116
      }
×
117
      /* domain keys is not strictly speaking necessary for dnssec backend */
118
      if (f_get_domain_keys == nullptr) {
15!
NEW
119
        SLOG(g_log << Logger::Warning << "dns_get_domain_keys missing - cannot do live signing" << endl,
×
NEW
120
             d_slog->info(Logr::Warning, "dns_get_domain_keys missing - cannot perform live signing"));
×
UNCOV
121
      }
×
122
    }
15✔
123
  }
21✔
124

125
  unsigned int getCapabilities() override
126
  {
6✔
127
    unsigned int caps = CAP_DIRECT | CAP_LIST;
6✔
128
    if (d_dnssec) {
6!
129
      caps |= CAP_DNSSEC;
6✔
130
    }
6✔
131
    if (f_get_all_domains != nullptr) {
6!
132
      caps |= CAP_SEARCH;
6✔
133
    }
6✔
134
    return caps;
6✔
135
  }
6✔
136

137
  void parseLookup(const lookup_result_t& result)
138
  {
29✔
139
    for (const auto& row : result) {
103✔
140
      DNSResourceRecord rec;
103✔
141
      for (const auto& item : row.second) {
437✔
142
        if (item.first == "type") {
437✔
143
          if (item.second.which() == 1) {
103!
144
            rec.qtype = QType(boost::get<int>(item.second));
×
145
          }
×
146
          else if (item.second.which() == 3) {
103!
147
            rec.qtype = boost::get<string>(item.second);
×
148
          }
×
149
          else if (item.second.which() == 4) {
103!
150
            rec.qtype = boost::get<QType>(item.second);
103✔
151
          }
103✔
152
          else {
×
153
            throw PDNSException("Unsupported value for type");
×
154
          }
×
155
        }
103✔
156
        else if (item.first == "name") {
334✔
157
          if (item.second.which() == 3) {
103!
158
            rec.qname = DNSName(boost::get<string>(item.second));
×
159
          }
×
160
          else if (item.second.which() == 2) {
103!
161
            rec.qname = boost::get<DNSName>(item.second);
103✔
162
          }
103✔
163
          else {
×
164
            throw PDNSException("Unsupported value for name");
×
165
          }
×
166
        }
103✔
167
        else if (item.first == "domain_id") {
231✔
168
          rec.domain_id = boost::get<int>(item.second);
25✔
169
        }
25✔
170
        else if (item.first == "auth") {
206!
171
          rec.auth = boost::get<bool>(item.second);
×
172
        }
×
173
        else if (item.first == "last_modified") {
206!
174
          rec.last_modified = static_cast<time_t>(boost::get<int>(item.second));
×
175
        }
×
176
        else if (item.first == "ttl") {
206✔
177
          rec.ttl = boost::get<int>(item.second);
103✔
178
        }
103✔
179
        else if (item.first == "content") {
103!
180
          rec.setContent(boost::get<string>(item.second));
103✔
181
        }
103✔
182
        else if (item.first == "scopeMask") {
×
183
          rec.scopeMask = boost::get<int>(item.second);
×
184
        }
×
185
        else {
×
NEW
186
          SLOG(g_log << Logger::Warning << "Unsupported key '" << item.first << "' in lookup or list result" << endl,
×
NEW
187
               d_slog->info(Logr::Warning, "Unsupported kep in lookup or list result", "key", Logging::Loggable(item.first)));
×
UNCOV
188
        }
×
189
      }
437✔
190
      if (d_debug_log) {
103!
NEW
191
        SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << rec.qname << " IN " << rec.qtype.toString() << " " << rec.ttl << " " << rec.getZoneRepresentation() << "'" << endl,
×
NEW
192
             d_slog->info(Logr::Debug, "Got result", "name", Logging::Loggable(rec.qname), "type", Logging::Loggable(rec.qtype), "ttl", Logging::Loggable(rec.ttl), "data", Logging::Loggable(rec.getZoneRepresentation())));
×
UNCOV
193
      }
×
194
      d_result.push_back(rec);
103✔
195
    }
103✔
196
    if (d_result.empty() && d_debug_log) {
29!
NEW
197
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got empty result" << endl,
×
NEW
198
           d_slog->info(Logr::Debug, "Got empty result"));
×
UNCOV
199
    }
×
200
  }
29✔
201

202
  bool list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */ = false) override
203
  {
6✔
204
    if (f_list == nullptr) {
6!
NEW
205
      SLOG(g_log << Logger::Error << "[" << getPrefix() << "] dns_list missing - cannot do AXFR" << endl,
×
NEW
206
           d_slog->info(Logr::Error, "dns_list missing - cannot perform AXFR"));
×
207
      return false;
×
208
    }
×
209

210
    if (d_result.size() != 0) {
6!
211
      throw PDNSException("list attempted while another was running");
×
212
    }
×
213

214
    if (d_debug_log) {
6!
NEW
215
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "list" << "(" << "target=" << target << ",domain_id=" << domain_id << ")" << endl,
×
NEW
216
           d_slog->info(Logr::Debug, "Calling list", "target", Logging::Loggable(target), "domain id", Logging::Loggable(domain_id)));
×
UNCOV
217
    }
×
218
    list_result_t result = f_list(target.operator const DNSName&(), domain_id);
6✔
219

220
    if (result.which() == 0) {
6!
221
      return false;
×
222
    }
×
223

224
    parseLookup(boost::get<lookup_result_t>(result));
6✔
225

226
    return true;
6✔
227
  }
6✔
228

229
  void lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket* p = nullptr) override
230
  {
23✔
231
    if (d_result.size() != 0) {
23!
232
      throw PDNSException("lookup attempted while another was running");
×
233
    }
×
234

235
    lookup_context_t ctx;
23✔
236
    if (p != NULL) {
23✔
237
      ctx.emplace_back(lookup_context_t::value_type{"source_address", p->getInnerRemote().toString()});
5✔
238
      ctx.emplace_back(lookup_context_t::value_type{"real_source_address", p->getRealRemote().toString()});
5✔
239
    }
5✔
240

241
    if (d_debug_log) {
23!
NEW
242
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "lookup" << "(" << "qtype=" << qtype.toString() << ",qname=" << qname << ",domain_id=" << domain_id << ")" << endl,
×
NEW
243
           d_slog->info(Logr::Debug, "Calling lookup", "type", Logging::Loggable(qtype), "name", Logging::Loggable(qname), "domain id", Logging::Loggable(domain_id)));
×
UNCOV
244
    }
×
245
    lookup_result_t result = f_lookup(qtype, qname, domain_id, ctx);
23✔
246
    parseLookup(result);
23✔
247
  }
23✔
248

249
  bool get(DNSResourceRecord& rr) override
250
  {
132✔
251
    if (d_result.size() == 0) {
132✔
252
      return false;
29✔
253
    }
29✔
254
    rr = std::move(d_result.front());
103✔
255
    d_result.pop_front();
103✔
256
    return true;
103✔
257
  }
132✔
258

259
  string directBackendCmd(const string& querystr) override
260
  {
×
261
    string::size_type pos = querystr.find_first_of(" \t");
×
262
    string cmd = querystr;
×
263
    string par = "";
×
264
    if (pos != string::npos) {
×
265
      cmd = querystr.substr(0, pos);
×
266
      par = querystr.substr(pos + 1);
×
267
    }
×
268
    direct_backend_cmd_call_t f = d_lw->readVariable<boost::optional<direct_backend_cmd_call_t>>(cmd).get_value_or(0);
×
269
    if (f == nullptr) {
×
270
      return cmd + "not found";
×
271
    }
×
272
    if (d_debug_log) {
×
NEW
273
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << cmd << "(" << "parameter=" << par << ")" << endl,
×
NEW
274
           d_slog->info(Logr::Debug, "Direct backend command", "command", Logging::Loggable(cmd), "parameters", Logging::Loggable(par)));
×
275
    }
×
276
    return f(par);
×
277
  }
×
278

279
  void setNotified(domainid_t id, uint32_t serial) override
280
  {
×
281
    if (f_set_notified == NULL) {
×
282
      return;
×
283
    }
×
284
    if (d_debug_log) {
×
NEW
285
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "dns_set_notified" << "(" << "id=" << id << ",serial=" << serial << ")" << endl,
×
NEW
286
           d_slog->info(Logr::Debug, "Calling dns_set_notified", "id", Logging::Loggable(id), "serial", Logging::Loggable(serial)));
×
287
    }
×
288
    f_set_notified(id, serial);
×
289
  }
×
290

291
  void parseDomainInfo(const domaininfo_result_t& row, DomainInfo& di)
292
  {
5✔
293
    di.id = UnknownDomainID;
5✔
294
    for (const auto& item : row) {
10✔
295
      if (item.first == "account") {
10!
296
        di.account = boost::get<string>(item.second);
×
297
      }
×
298
      else if (item.first == "last_check") {
10!
299
        di.last_check = static_cast<time_t>(boost::get<long>(item.second));
×
300
      }
×
301
      else if (item.first == "masters") {
10!
302
        for (const auto& primary : boost::get<vector<string>>(item.second)) {
×
303
          di.primaries.push_back(ComboAddress(primary, 53));
×
304
        }
×
305
      }
×
306
      else if (item.first == "id") {
10✔
307
        di.id = static_cast<domainid_t>(boost::get<long>(item.second));
5✔
308
      }
5✔
309
      else if (item.first == "notified_serial") {
5!
310
        di.notified_serial = static_cast<unsigned int>(boost::get<long>(item.second));
×
311
      }
×
312
      else if (item.first == "serial") {
5!
313
        di.serial = static_cast<unsigned int>(boost::get<long>(item.second));
5✔
314
      }
5✔
315
      else if (item.first == "kind") {
×
316
        di.kind = DomainInfo::stringToKind(boost::get<string>(item.second));
×
317
      }
×
318
      else {
×
NEW
319
        SLOG(g_log << Logger::Warning << "Unsupported key '" << item.first << "' in domaininfo result" << endl,
×
NEW
320
             d_slog->info(Logr::Warning, "Unsupported key in domaininfo result", "key", Logging::Loggable(item.first)));
×
UNCOV
321
      }
×
322
    }
10✔
323
    di.backend = this;
5✔
324
    if (d_debug_log) {
5!
NEW
325
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "zone=" << di.zone << ",serial=" << di.serial << ",kind=" << di.getKindString() << "'" << endl,
×
NEW
326
           d_slog->info(Logr::Debug, "Got domain info", "zone", Logging::Loggable(di.zone), "serial", Logging::Loggable(di.serial), "kind", Logging::Loggable(di.getKindString())));
×
UNCOV
327
    }
×
328
  }
5✔
329

330
  bool getDomainInfo(const ZoneName& domain, DomainInfo& di, bool /* getSerial */ = true) override
331
  {
6✔
332
    if (f_get_domaininfo == nullptr) {
6✔
333
      // use getAuth instead... but getAuth wraps getSOA which will call
334
      // getDomainInfo if this is a domain variant, so protect against this
335
      // would-be infinite recursion.
336
      if (domain.hasVariant()) {
3!
NEW
337
        SLOG(g_log << Logger::Info << "Unable to return domain information for '" << domain.toLogString() << "' due to unimplemented dns_get_domaininfo" << endl,
×
NEW
338
             d_slog->info(Logr::Info, "Unable to return domain information due to unimplemented dns_get_domaininfo", "domain", Logging::Loggable(domain)));
×
339
        return false;
×
340
      }
×
341
      SOAData sd;
3✔
342
      if (!getAuth(domain, &sd)) {
3!
343
        return false;
×
344
      }
×
345

346
      di.id = sd.domain_id;
3✔
347
      di.zone = domain;
3✔
348
      di.backend = this;
3✔
349
      di.serial = sd.serial;
3✔
350
      return true;
3✔
351
    }
3✔
352

353
    if (d_debug_log) {
3!
NEW
354
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domaininfo" << "(" << "domain=" << domain << ")" << endl,
×
NEW
355
           d_slog->info(Logr::Debug, "Calling get_domaininfo", "domain", Logging::Loggable(domain)));
×
UNCOV
356
    }
×
357
    get_domaininfo_result_t result = f_get_domaininfo(domain.operator const DNSName&());
3✔
358

359
    if (result.which() == 0) {
3!
360
      return false;
×
361
    }
×
362

363
    di.zone = domain;
3✔
364
    parseDomainInfo(boost::get<domaininfo_result_t>(result), di);
3✔
365

366
    return true;
3✔
367
  }
3✔
368

369
  void getAllDomains(vector<DomainInfo>* domains, bool /* getSerial */, bool /* include_disabled */) override
370
  {
1✔
371
    if (f_get_all_domains == nullptr) {
1!
372
      return;
×
373
    }
×
374

375
    if (d_debug_log) {
1!
NEW
376
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_all_domains" << "(" << "" << ")" << endl,
×
NEW
377
           d_slog->info(Logr::Debug, "Calling get_all_domains"));
×
UNCOV
378
    }
×
379
    for (const auto& row : f_get_all_domains()) {
2✔
380
      DomainInfo di;
2✔
381
      di.zone = ZoneName(row.first);
2✔
382
      if (d_debug_log) {
2!
NEW
383
        SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << di.zone << "'" << endl,
×
NEW
384
             d_slog->info(Logr::Debug, "Got result", "domain", Logging::Loggable(di.zone)));
×
UNCOV
385
      }
×
386
      parseDomainInfo(row.second, di);
2✔
387
      domains->push_back(di);
2✔
388
    }
2✔
389
  }
1✔
390

391
  bool getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string>>& meta) override
392
  {
6✔
393
    if (f_get_all_domain_metadata == nullptr) {
6!
394
      return false;
6✔
395
    }
6✔
396

397
    if (d_debug_log) {
×
NEW
398
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_all_domain_metadata" << "(" << "name=" << name << ")" << endl,
×
NEW
399
           d_slog->info(Logr::Debug, "Calling get_all_domain_metadata", "domain", Logging::Loggable(name)));
×
400
    }
×
401
    get_all_domain_metadata_result_t result = f_get_all_domain_metadata(name.operator const DNSName&());
×
402
    if (result.which() == 0) {
×
403
      return false;
×
404
    }
×
405

406
    for (const auto& row : boost::get<vector<pair<string, domain_metadata_result_t>>>(result)) {
×
407
      meta[row.first].clear();
×
408
      for (const auto& item : row.second) {
×
409
        meta[row.first].push_back(item.second);
×
410
      }
×
411
      if (d_debug_log) {
×
NEW
412
        SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "kind=" << row.first << ",value=" << boost::algorithm::join(meta[row.first], ", ") << "'" << endl,
×
NEW
413
             d_slog->info(Logr::Debug, "Got result", "kind", Logging::Loggable(row.first), "value", Logging::Loggable(boost::algorithm::join(meta[row.first], ", "))));
×
414
      }
×
415
    }
×
416

417
    return true;
×
418
  }
×
419

420
  bool getDomainMetadata(const ZoneName& name, const std::string& kind, std::vector<std::string>& meta) override
421
  {
×
422
    if (f_get_domain_metadata == nullptr) {
×
423
      return false;
×
424
    }
×
425

426
    if (d_debug_log) {
×
NEW
427
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domain_metadata" << "(" << "name=" << name << ",kind=" << kind << ")" << endl,
×
NEW
428
           d_slog->info(Logr::Debug, "Calling get_domain_metadata", "domain", Logging::Loggable(name), "kind", Logging::Loggable(kind)));
×
429
    }
×
430
    get_domain_metadata_result_t result = f_get_domain_metadata(name.operator const DNSName&(), kind);
×
431
    if (result.which() == 0) {
×
432
      return false;
×
433
    }
×
434

435
    meta.clear();
×
436
    for (const auto& item : boost::get<domain_metadata_result_t>(result)) {
×
437
      meta.push_back(item.second);
×
438
    }
×
439

440
    if (d_debug_log) {
×
NEW
441
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "value=" << boost::algorithm::join(meta, ", ") << "'" << endl,
×
NEW
442
           d_slog->info(Logr::Debug, "Got result", "value", Logging::Loggable(boost::algorithm::join(meta, ", "))));
×
443
    }
×
444
    return true;
×
445
  }
×
446

447
  bool getDomainKeys(const ZoneName& name, std::vector<DNSBackend::KeyData>& keys) override
448
  {
6✔
449
    if (f_get_domain_keys == nullptr) {
6✔
450
      return false;
3✔
451
    }
3✔
452

453
    if (d_debug_log) {
3!
NEW
454
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domain_keys" << "(" << "name=" << name << ")" << endl,
×
NEW
455
           d_slog->info(Logr::Debug, "Calling get_domain_keys", "domain", Logging::Loggable(name)));
×
UNCOV
456
    }
×
457
    get_domain_keys_result_t result = f_get_domain_keys(name.operator const DNSName&());
3✔
458

459
    if (result.which() == 0) {
3!
460
      return false;
×
461
    }
×
462

463
    for (const auto& row : boost::get<vector<pair<int, keydata_result_t>>>(result)) {
6✔
464
      DNSBackend::KeyData key;
6✔
465
      key.published = true;
6✔
466
      for (const auto& item : row.second) {
24✔
467
        if (item.first == "content") {
24✔
468
          key.content = boost::get<string>(item.second);
6✔
469
        }
6✔
470
        else if (item.first == "id") {
18✔
471
          key.id = static_cast<unsigned int>(boost::get<int>(item.second));
6✔
472
        }
6✔
473
        else if (item.first == "flags") {
12✔
474
          key.flags = static_cast<unsigned int>(boost::get<int>(item.second));
6✔
475
        }
6✔
476
        else if (item.first == "active") {
6!
477
          key.active = boost::get<bool>(item.second);
6✔
478
        }
6✔
479
        else if (item.first == "published") {
×
480
          key.published = boost::get<bool>(item.second);
×
481
        }
×
482
        else {
×
NEW
483
          SLOG(g_log << Logger::Warning << "[" << getPrefix() << "] Unsupported key '" << item.first << "' in keydata result" << endl,
×
NEW
484
               d_slog->info(Logr::Warning, "Unsupported key in keydata result", "key", Logging::Loggable(item.first)));
×
UNCOV
485
        }
×
486
      }
24✔
487
      if (d_debug_log) {
6!
NEW
488
        SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "id=" << key.id << ",flags=" << key.flags << ",active=" << (key.active ? "true" : "false") << ",published=" << (key.published ? "true" : "false") << "'" << endl,
×
NEW
489
             d_slog->info(Logr::Debug, "Got result", "id", Logging::Loggable(key.id), "flags", Logging::Loggable(key.flags), "active", Logging::Loggable(key.active ? "true" : "false"), "published", Logging::Loggable(key.published ? "true" : "false")));
×
UNCOV
490
      }
×
491
      keys.emplace_back(std::move(key));
6✔
492
    }
6✔
493

494
    return true;
3✔
495
  }
3✔
496

497
  bool getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override
498
  {
12✔
499
    if (f_get_before_and_after_names_absolute == nullptr) {
12!
500
      return false;
×
501
    }
×
502

503
    if (d_debug_log) {
12!
NEW
504
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_before_and_after_names_absolute" << "(" << "id=<<" << id << ",qname=" << qname << ")" << endl,
×
NEW
505
           d_slog->info(Logr::Debug, "Calling get_before_and_after_names_absolute", "id", Logging::Loggable(id), "name", Logging::Loggable(qname)));
×
UNCOV
506
    }
×
507
    get_before_and_after_names_absolute_result_t result = f_get_before_and_after_names_absolute(id, qname);
12✔
508

509
    if (result.which() == 0) {
12!
510
      return false;
×
511
    }
×
512

513
    before_and_after_names_result_t row = boost::get<before_and_after_names_result_t>(result);
12✔
514
    if (row.size() != 3) {
12!
NEW
515
      SLOG(g_log << Logger::Error << "Invalid result from dns_get_before_and_after_names_absolute, expected array with 3 items, got " << row.size() << "item(s)" << endl,
×
NEW
516
           d_slog->info(Logr::Error, "Invalid result from dns_get_before_and_after_names_absolute, expected array with 3 rows", "rows returned", Logging::Loggable(row.size())));
×
517
      return false;
×
518
    }
×
519
    for (const auto& item : row) {
36✔
520
      DNSName value;
36✔
521
      if (item.second.which() == 0) {
36!
522
        value = DNSName(boost::get<string>(item.second));
×
523
      }
×
524
      else {
36✔
525
        value = DNSName(boost::get<DNSName>(item.second));
36✔
526
      }
36✔
527
      if (item.first == "unhashed") {
36✔
528
        unhashed = value;
12✔
529
      }
12✔
530
      else if (item.first == "before") {
24✔
531
        before = value;
12✔
532
      }
12✔
533
      else if (item.first == "after") {
12!
534
        after = value;
12✔
535
      }
12✔
536
      else {
×
NEW
537
        SLOG(g_log << Logger::Error << "Invalid result from dns_get_before_and_after_names_absolute, unexpected key " << item.first << endl,
×
NEW
538
             d_slog->info(Logr::Error, "Invalid result from dns_get_before_and_after_names_absolute, unexpected key", "key", Logging::Loggable(item.first)));
×
539
        return false;
×
540
      }
×
541
    }
36✔
542

543
    if (d_debug_log) {
12!
NEW
544
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "unhashed=" << unhashed << ",before=" << before << ",after=" << after << "'" << endl,
×
NEW
545
           d_slog->info(Logr::Debug, "Got result", "unhashed", Logging::Loggable(unhashed), "before", Logging::Loggable(before), "after", Logging::Loggable(after)));
×
UNCOV
546
    }
×
547
    return true;
12✔
548
  }
12✔
549

550
private:
551
  std::list<DNSResourceRecord> d_result;
552
  bool d_debug_log{false};
553
  bool d_dnssec{false};
554

555
  lookup_call_t f_lookup;
556
  list_call_t f_list;
557

558
  get_domaininfo_call_t f_get_domaininfo;
559
  get_all_domains_call_t f_get_all_domains;
560

561
  get_domain_metadata_call_t f_get_domain_metadata;
562
  get_all_domain_metadata_call_t f_get_all_domain_metadata;
563

564
  get_domain_keys_call_t f_get_domain_keys;
565

566
  get_before_and_after_names_absolute_call_t f_get_before_and_after_names_absolute;
567

568
  set_notified_call_t f_set_notified;
569

570
  deinit_call_t f_deinit;
571
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc