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

PowerDNS / pdns / 29501794908

16 Jul 2026 01:20PM UTC coverage: 71.132% (+0.3%) from 70.858%
29501794908

Pull #17742

github

web-flow
Merge 0802d0049 into 169a8a502
Pull Request #17742: auth: minor Lua2 backend improvements

46754 of 82274 branches covered (56.83%)

Branch coverage included in aggregate %.

11 of 29 new or added lines in 1 file covered. (37.93%)

35 existing lines in 13 files now uncovered.

134131 of 172020 relevant lines covered (77.97%)

6538011.39 hits per line

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

47.16
/modules/lua2backend/lua2api2.cc
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
#ifdef HAVE_CONFIG_H
23
#include "config.h"
24
#endif
25
#include "lua2backend.hh"
26

27
Lua2BackendAPIv2::Lua2BackendAPIv2(Logr::log_t slog, const string& suffix)
28
{
20✔
29
  d_slog = slog;
20✔
30
  d_include_path = ::arg()["lua-global-include-dir"];
20✔
31
  setArgPrefix("lua2" + suffix);
20✔
32
  d_debug_log = mustDo("query-logging");
20✔
33
  prepareContext();
20✔
34
  loadFile(getArg("filename"));
20✔
35
}
20✔
36

37
Lua2BackendAPIv2::~Lua2BackendAPIv2()
38
{
16✔
39
  if (f_deinit) {
16!
40
    f_deinit();
×
41
  }
×
42
}
16✔
43

44
void Lua2BackendAPIv2::postPrepareContext()
45
{
20✔
46
  AuthLua4::postPrepareContext();
20✔
47
}
20✔
48

49
void Lua2BackendAPIv2::postLoad()
50
{
20✔
51
  // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks): clang-tidy is adamant readVariable may leak a std::function in LuaContext::Reader(), but only warns for the first readVariable call.
52
  f_lookup = d_lw->readVariable<boost::optional<lookup_call_t>>("dns_lookup").get_value_or(nullptr);
20✔
53
  f_list = d_lw->readVariable<boost::optional<list_call_t>>("dns_list").get_value_or(nullptr);
20✔
54
  f_get_all_domains = d_lw->readVariable<boost::optional<get_all_domains_call_t>>("dns_get_all_domains").get_value_or(nullptr);
20✔
55
  f_get_domaininfo = d_lw->readVariable<boost::optional<get_domaininfo_call_t>>("dns_get_domaininfo").get_value_or(nullptr);
20✔
56
  f_get_domain_metadata = d_lw->readVariable<boost::optional<get_domain_metadata_call_t>>("dns_get_domain_metadata").get_value_or(nullptr);
20✔
57
  f_get_all_domain_metadata = d_lw->readVariable<boost::optional<get_all_domain_metadata_call_t>>("dns_get_all_domain_metadata").get_value_or(nullptr);
20✔
58
  f_get_domain_keys = d_lw->readVariable<boost::optional<get_domain_keys_call_t>>("dns_get_domain_keys").get_value_or(nullptr);
20✔
59
  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(nullptr);
20✔
60
  f_set_notified = d_lw->readVariable<boost::optional<set_notified_call_t>>("dns_set_notified").get_value_or(nullptr);
20✔
61

62
  auto init = d_lw->readVariable<boost::optional<init_call_t>>("dns_init").get_value_or(nullptr);
20✔
63
  if (init) {
20!
64
    init();
×
65
  }
×
66

67
  f_deinit = d_lw->readVariable<boost::optional<deinit_call_t>>("dns_deinit").get_value_or(nullptr);
20✔
68

69
  if (f_lookup == nullptr) {
20!
70
    throw PDNSException("dns_lookup missing");
×
71
  }
×
72

73
  /* see if dnssec support is wanted */
74
  d_dnssec = d_lw->readVariable<boost::optional<bool>>("dns_dnssec").get_value_or(false);
20✔
75
  if (d_dnssec) {
20✔
76
    if (f_get_domain_metadata == nullptr) {
15!
77
      throw PDNSException("dns_dnssec is true but dns_get_domain_metadata is missing");
×
78
    }
×
79
    if (f_get_before_and_after_names_absolute == nullptr) {
15!
80
      throw PDNSException("dns_dnssec is true but dns_get_before_and_after_names_absolute is missing");
×
81
    }
×
82
    /* domain keys is not strictly speaking necessary for dnssec backend */
83
    if (f_get_domain_keys == nullptr) {
15!
84
      SLOG(g_log << Logger::Warning << "dns_get_domain_keys missing - cannot do live signing" << endl,
×
85
           d_slog->info(Logr::Warning, "dns_get_domain_keys missing - cannot perform live signing"));
×
86
    }
×
87
  }
15✔
88
}
20✔
89

90
unsigned int Lua2BackendAPIv2::getCapabilities()
91
{
6✔
92
  unsigned int caps = CAP_DIRECT | CAP_LIST;
6✔
93
  if (d_dnssec) {
6!
94
    caps |= CAP_DNSSEC;
6✔
95
  }
6✔
96
  if (f_get_all_domains != nullptr) {
6!
97
    caps |= CAP_SEARCH;
6✔
98
  }
6✔
99
  return caps;
6✔
100
}
6✔
101

102
void Lua2BackendAPIv2::parseLookup(const lookup_result_t& result)
103
{
29✔
104
  for (const auto& row : result) {
103✔
105
    DNSResourceRecord rec;
103✔
106
    for (const auto& item : row.second) {
448✔
107
      try {
448✔
108
        if (item.first == "type") {
448✔
109
          if (item.second.which() == 1) {
103!
110
            rec.qtype = QType(boost::get<int>(item.second));
×
111
          }
×
112
          else if (item.second.which() == 3) {
103!
113
            rec.qtype = boost::get<string>(item.second);
×
114
          }
×
115
          else { // assuming item.second.which() == 4 here
103✔
116
            rec.qtype = boost::get<QType>(item.second);
103✔
117
          }
103✔
118
        }
103✔
119
        else if (item.first == "name") {
345✔
120
          if (item.second.which() == 3) {
103!
121
            rec.qname = DNSName(boost::get<string>(item.second));
×
122
          }
×
123
          else { // assuming item.second.which() == 2 here
103✔
124
            rec.qname = boost::get<DNSName>(item.second);
103✔
125
          }
103✔
126
        }
103✔
127
        else if (item.first == "domain_id") {
242✔
128
          rec.domain_id = boost::get<int>(item.second);
25✔
129
        }
25✔
130
        else if (item.first == "auth") {
217✔
131
          if (item.second.which() == 1) {
11✔
132
            rec.auth = boost::get<int>(item.second) != 0;
2✔
133
          }
2✔
134
          else { // assuming item.second.which() == 0 here
9✔
135
            rec.auth = boost::get<bool>(item.second);
9✔
136
          }
9✔
137
        }
11✔
138
        else if (item.first == "last_modified") {
206!
139
          rec.last_modified = static_cast<time_t>(boost::get<int>(item.second));
×
140
        }
×
141
        else if (item.first == "ttl") {
206✔
142
          rec.ttl = boost::get<int>(item.second);
103✔
143
        }
103✔
144
        else if (item.first == "content") {
103!
145
          if (item.second.which() == 1) {
103!
146
            rec.setContent(std::to_string(boost::get<int>(item.second)));
×
147
          }
×
148
          else { // assuming item.second.which() == 3 here
103✔
149
            rec.setContent(boost::get<string>(item.second));
103✔
150
          }
103✔
151
        }
103✔
152
        else if (item.first == "scopeMask") {
×
153
          rec.scopeMask = boost::get<int>(item.second);
×
154
        }
×
155
        else {
×
156
          SLOG(g_log << Logger::Warning << "Unsupported key '" << item.first << "' in lookup or list result" << endl,
×
157
               d_slog->info(Logr::Warning, "Unsupported key in lookup or list result", "key", Logging::Loggable(item.first)));
×
158
        }
×
159
      }
448✔
160
      catch (const std::exception& e) {
448✔
NEW
161
        std::stringstream value;
×
NEW
162
        value << item.second;
×
NEW
163
        throw PDNSException("Unable to parse " + item.first + " value (" + value.str() + ") of variant type " + std::to_string(item.second.which()) + " in lookup or list result: " + e.what());
×
UNCOV
164
      }
×
165
    }
448✔
166
    if (d_debug_log) {
103!
167
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << rec.qname << " IN " << rec.qtype.toString() << " " << rec.ttl << " " << rec.getZoneRepresentation() << "'" << endl,
×
168
           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())));
×
169
    }
×
170
    d_result.push_back(std::move(rec));
103✔
171
  }
103✔
172
  if (d_result.empty() && d_debug_log) {
29!
173
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got empty result" << endl,
×
174
         d_slog->info(Logr::Debug, "Got empty result"));
×
175
  }
×
176
}
29✔
177

178
bool Lua2BackendAPIv2::list(const ZoneName& target, domainid_t domain_id, bool /* include_disabled */)
179
{
6✔
180
  if (f_list == nullptr) {
6!
181
    SLOG(g_log << Logger::Error << "[" << getPrefix() << "] dns_list missing - cannot do AXFR" << endl,
×
182
         d_slog->info(Logr::Error, "dns_list missing - cannot perform AXFR"));
×
183
    return false;
×
184
  }
×
185

186
  if (!d_result.empty()) {
6!
187
    throw PDNSException("list attempted while another was running");
×
188
  }
×
189

190
  if (d_debug_log) {
6!
191
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "list" << "(" << "target=" << target << ",domain_id=" << domain_id << ")" << endl,
×
192
         d_slog->info(Logr::Debug, "Calling list", "target", Logging::Loggable(target), "domain id", Logging::Loggable(domain_id)));
×
193
  }
×
194
  list_result_t result = f_list(target.operator const DNSName&(), domain_id);
6✔
195

196
  if (result.which() == 0) {
6!
197
    return false;
×
198
  }
×
199

200
  parseLookup(boost::get<lookup_result_t>(result));
6✔
201

202
  return true;
6✔
203
}
6✔
204

205
void Lua2BackendAPIv2::lookup(const QType& qtype, const DNSName& qname, domainid_t domain_id, DNSPacket* pkt)
206
{
23✔
207
  if (!d_result.empty()) {
23!
208
    throw PDNSException("lookup attempted while another was running");
×
209
  }
×
210

211
  lookup_context_t ctx;
23✔
212
  if (pkt != nullptr) {
23✔
213
    ctx.emplace_back(lookup_context_t::value_type{"source_address", pkt->getInnerRemote().toString()});
5✔
214
    ctx.emplace_back(lookup_context_t::value_type{"real_source_address", pkt->getRealRemote().toString()});
5✔
215
  }
5✔
216

217
  if (d_debug_log) {
23!
218
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "lookup" << "(" << "qtype=" << qtype.toString() << ",qname=" << qname << ",domain_id=" << domain_id << ")" << endl,
×
219
         d_slog->info(Logr::Debug, "Calling lookup", "type", Logging::Loggable(qtype), "name", Logging::Loggable(qname), "domain id", Logging::Loggable(domain_id)));
×
220
  }
×
221
  lookup_result_t result = f_lookup(qtype, qname, domain_id, ctx);
23✔
222
  parseLookup(result);
23✔
223
}
23✔
224

225
bool Lua2BackendAPIv2::get(DNSResourceRecord& drr)
226
{
132✔
227
  if (d_result.empty()) {
132✔
228
    return false;
29✔
229
  }
29✔
230
  drr = std::move(d_result.front());
103✔
231
  d_result.pop_front();
103✔
232
  return true;
103✔
233
}
132✔
234

235
void Lua2BackendAPIv2::lookupEnd()
NEW
236
{
×
NEW
237
  d_result.clear();
×
NEW
238
}
×
239

240
string Lua2BackendAPIv2::directBackendCmd(const string& querystr)
241
{
×
242
  string::size_type pos = querystr.find_first_of(" \t");
×
243
  string cmd = querystr;
×
244
  string par{};
×
245
  if (pos != string::npos) {
×
246
    cmd = querystr.substr(0, pos);
×
247
    par = querystr.substr(pos + 1);
×
248
  }
×
249
  direct_backend_cmd_call_t dbc = d_lw->readVariable<boost::optional<direct_backend_cmd_call_t>>(cmd).get_value_or(nullptr);
×
250
  if (dbc == nullptr) {
×
251
    return cmd + "not found";
×
252
  }
×
253
  if (d_debug_log) {
×
254
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << cmd << "(" << "parameter=" << par << ")" << endl,
×
255
         d_slog->info(Logr::Debug, "Direct backend command", "command", Logging::Loggable(cmd), "parameters", Logging::Loggable(par)));
×
256
  }
×
257
  return dbc(par);
×
258
}
×
259

260
void Lua2BackendAPIv2::setNotified(domainid_t domain_id, uint32_t serial)
261
{
×
262
  if (f_set_notified == nullptr) {
×
263
    return;
×
264
  }
×
265
  if (d_debug_log) {
×
266
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "dns_set_notified" << "(" << "id=" << domain_id << ",serial=" << serial << ")" << endl,
×
267
         d_slog->info(Logr::Debug, "Calling dns_set_notified", "id", Logging::Loggable(domain_id), "serial", Logging::Loggable(serial)));
×
268
  }
×
269
  f_set_notified(domain_id, serial);
×
270
}
×
271

272
void Lua2BackendAPIv2::parseDomainInfo(const domaininfo_result_t& row, DomainInfo& info)
273
{
5✔
274
  info.id = UnknownDomainID;
5✔
275
  for (const auto& item : row) {
10✔
276
    try {
10✔
277
      if (item.first == "account") {
10!
278
        if (item.second.which() == 1) { // should the account name be all-digits...
×
279
          info.account = std::to_string(boost::get<long>(item.second));
×
280
        }
×
281
        else { // assuming item.second.which() == 2 here
×
282
          info.account = boost::get<string>(item.second);
×
283
        }
×
284
      }
×
285
      else if (item.first == "last_check") {
10!
286
        info.last_check = static_cast<time_t>(boost::get<long>(item.second));
×
287
      }
×
288
      else if (item.first == "masters") {
10!
289
        for (const auto& primary : boost::get<vector<string>>(item.second)) {
×
290
          info.primaries.emplace_back(ComboAddress(primary, 53));
×
291
        }
×
292
      }
×
293
      else if (item.first == "id") {
10✔
294
        info.id = static_cast<domainid_t>(boost::get<long>(item.second));
5✔
295
      }
5✔
296
      else if (item.first == "notified_serial") {
5!
297
        info.notified_serial = static_cast<unsigned int>(boost::get<long>(item.second));
×
298
      }
×
299
      else if (item.first == "serial") {
5!
300
        info.serial = static_cast<unsigned int>(boost::get<long>(item.second));
5✔
301
      }
5✔
302
      else if (item.first == "kind") {
×
303
        info.kind = DomainInfo::stringToKind(boost::get<string>(item.second));
×
304
      }
×
305
      else {
×
306
        SLOG(g_log << Logger::Warning << "Unsupported key '" << item.first << "' in domaininfo result" << endl,
×
307
             d_slog->info(Logr::Warning, "Unsupported key in domaininfo result", "key", Logging::Loggable(item.first)));
×
308
      }
×
309
    }
10✔
310
    catch (const std::exception& e) {
10✔
311
      // We can't get a printable version of the contents, because of the
312
      // vector<string> case, which is not OutputStreamable.
NEW
313
      throw PDNSException("Unable to parse " + item.first + " value of variant type " + std::to_string(item.second.which()) + " in domaininfo result: " + e.what());
×
UNCOV
314
    }
×
315
  }
10✔
316
  info.backend = this;
5✔
317
  if (d_debug_log) {
5!
318
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "zone=" << info.zone << ",serial=" << info.serial << ",kind=" << info.getKindString() << "'" << endl,
×
319
         d_slog->info(Logr::Debug, "Got domain info", "zone", Logging::Loggable(info.zone), "serial", Logging::Loggable(info.serial), "kind", Logging::Loggable(info.getKindString())));
×
320
  }
×
321
}
5✔
322

323
bool Lua2BackendAPIv2::getDomainInfo(const ZoneName& domain, DomainInfo& info, bool /* getSerial */)
324
{
6✔
325
  if (f_get_domaininfo == nullptr) {
6✔
326
    // use getAuth instead... but getAuth wraps getSOA which will call
327
    // getDomainInfo if this is a domain variant, so protect against this
328
    // would-be infinite recursion.
329
    if (domain.hasVariant()) {
3!
330
      SLOG(g_log << Logger::Info << "Unable to return domain information for '" << domain.toLogString() << "' due to unimplemented dns_get_domaininfo" << endl,
×
331
           d_slog->info(Logr::Info, "Unable to return domain information due to unimplemented dns_get_domaininfo", "domain", Logging::Loggable(domain)));
×
332
      return false;
×
333
    }
×
334
    SOAData soa;
3✔
335
    if (!getAuth(domain, &soa)) {
3!
336
      return false;
×
337
    }
×
338

339
    info.id = soa.domain_id;
3✔
340
    info.zone = domain;
3✔
341
    info.backend = this;
3✔
342
    info.serial = soa.serial;
3✔
343
    return true;
3✔
344
  }
3✔
345

346
  if (d_debug_log) {
3!
347
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domaininfo" << "(" << "domain=" << domain << ")" << endl,
×
348
         d_slog->info(Logr::Debug, "Calling get_domaininfo", "domain", Logging::Loggable(domain)));
×
349
  }
×
350
  get_domaininfo_result_t result = f_get_domaininfo(domain.operator const DNSName&());
3✔
351

352
  if (result.which() == 0) {
3!
353
    return false;
×
354
  }
×
355

356
  info.zone = domain;
3✔
357
  parseDomainInfo(boost::get<domaininfo_result_t>(result), info);
3✔
358

359
  return true;
3✔
360
}
3✔
361

362
void Lua2BackendAPIv2::getAllDomains(vector<DomainInfo>* domains, bool /* getSerial */, bool /* include_disabled */)
363
{
1✔
364
  if (f_get_all_domains == nullptr) {
1!
365
    return;
×
366
  }
×
367

368
  if (d_debug_log) {
1!
369
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_all_domains" << "(" << "" << ")" << endl,
×
370
         d_slog->info(Logr::Debug, "Calling get_all_domains"));
×
371
  }
×
372
  for (const auto& row : f_get_all_domains()) {
2✔
373
    DomainInfo info;
2✔
374
    info.zone = ZoneName(row.first);
2✔
375
    if (d_debug_log) {
2!
376
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << info.zone << "'" << endl,
×
377
           d_slog->info(Logr::Debug, "Got result", "domain", Logging::Loggable(info.zone)));
×
378
    }
×
379
    parseDomainInfo(row.second, info);
2✔
380
    domains->push_back(std::move(info));
2✔
381
  }
2✔
382
}
1✔
383

384
bool Lua2BackendAPIv2::getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string>>& meta)
385
{
6✔
386
  if (f_get_all_domain_metadata == nullptr) {
6!
387
    return false;
6✔
388
  }
6✔
389

390
  if (d_debug_log) {
×
391
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_all_domain_metadata" << "(" << "name=" << name << ")" << endl,
×
392
         d_slog->info(Logr::Debug, "Calling get_all_domain_metadata", "domain", Logging::Loggable(name)));
×
393
  }
×
394
  get_all_domain_metadata_result_t result = f_get_all_domain_metadata(name.operator const DNSName&());
×
395
  if (result.which() == 0) {
×
396
    return false;
×
397
  }
×
398

399
  for (const auto& row : boost::get<vector<pair<string, domain_metadata_result_t>>>(result)) {
×
400
    meta[row.first].clear();
×
401
    for (const auto& item : row.second) {
×
402
      meta[row.first].push_back(item.second);
×
403
    }
×
404
    if (d_debug_log) {
×
405
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "kind=" << row.first << ",value=" << boost::algorithm::join(meta[row.first], ", ") << "'" << endl,
×
406
           d_slog->info(Logr::Debug, "Got result", "kind", Logging::Loggable(row.first), "value", Logging::Loggable(boost::algorithm::join(meta[row.first], ", "))));
×
407
    }
×
408
  }
×
409

410
  return true;
×
411
}
×
412

413
bool Lua2BackendAPIv2::getDomainMetadata(const ZoneName& name, const std::string& kind, std::vector<std::string>& meta)
414
{
×
415
  if (f_get_domain_metadata == nullptr) {
×
416
    return false;
×
417
  }
×
418

419
  if (d_debug_log) {
×
420
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domain_metadata" << "(" << "name=" << name << ",kind=" << kind << ")" << endl,
×
421
         d_slog->info(Logr::Debug, "Calling get_domain_metadata", "domain", Logging::Loggable(name), "kind", Logging::Loggable(kind)));
×
422
  }
×
423
  get_domain_metadata_result_t result = f_get_domain_metadata(name.operator const DNSName&(), kind);
×
424
  if (result.which() == 0) {
×
425
    return false;
×
426
  }
×
427

428
  meta.clear();
×
429
  for (const auto& item : boost::get<domain_metadata_result_t>(result)) {
×
430
    meta.push_back(item.second);
×
431
  }
×
432

433
  if (d_debug_log) {
×
434
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "value=" << boost::algorithm::join(meta, ", ") << "'" << endl,
×
435
         d_slog->info(Logr::Debug, "Got result", "value", Logging::Loggable(boost::algorithm::join(meta, ", "))));
×
436
  }
×
437
  return true;
×
438
}
×
439

440
bool Lua2BackendAPIv2::getDomainKeys(const ZoneName& name, std::vector<DNSBackend::KeyData>& keys)
441
{
6✔
442
  if (f_get_domain_keys == nullptr) {
6✔
443
    return false;
3✔
444
  }
3✔
445

446
  if (d_debug_log) {
3!
447
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domain_keys" << "(" << "name=" << name << ")" << endl,
×
448
         d_slog->info(Logr::Debug, "Calling get_domain_keys", "domain", Logging::Loggable(name)));
×
449
  }
×
450
  get_domain_keys_result_t result = f_get_domain_keys(name.operator const DNSName&());
3✔
451

452
  if (result.which() == 0) {
3!
453
    return false;
×
454
  }
×
455

456
  for (const auto& row : boost::get<vector<pair<int, keydata_result_t>>>(result)) {
6✔
457
    DNSBackend::KeyData key;
6✔
458
    key.published = true;
6✔
459
    for (const auto& item : row.second) {
24✔
460
      try {
24✔
461
        if (item.first == "content") {
24✔
462
          key.content = boost::get<string>(item.second);
6✔
463
        }
6✔
464
        else if (item.first == "id") {
18✔
465
          key.id = static_cast<unsigned int>(boost::get<int>(item.second));
6✔
466
        }
6✔
467
        else if (item.first == "flags") {
12✔
468
          key.flags = static_cast<unsigned int>(boost::get<int>(item.second));
6✔
469
        }
6✔
470
        else if (item.first == "active") {
6!
471
          if (item.second.which() == 1) {
6!
NEW
472
            key.active = boost::get<int>(item.second) != 0;
×
NEW
473
          }
×
474
          else { // assuming item.second.which() == 0 here
6✔
475
            key.active = boost::get<bool>(item.second);
6✔
476
          }
6✔
477
        }
6✔
478
        else if (item.first == "published") {
×
NEW
479
          if (item.second.which() == 1) {
×
NEW
480
            key.published = boost::get<int>(item.second) != 0;
×
NEW
481
          }
×
NEW
482
          else { // assuming item.second.which() == 0 here
×
NEW
483
            key.published = boost::get<bool>(item.second);
×
NEW
484
          }
×
485
        }
×
486
        else {
×
487
          SLOG(g_log << Logger::Warning << "[" << getPrefix() << "] Unsupported key '" << item.first << "' in keydata result" << endl,
×
488
               d_slog->info(Logr::Warning, "Unsupported key in keydata result", "key", Logging::Loggable(item.first)));
×
489
        }
×
490
      }
24✔
491
      catch (const std::exception& e) {
24✔
NEW
492
        std::stringstream value;
×
NEW
493
        value << item.second;
×
NEW
494
        throw PDNSException("Unable to parse " + item.first + " value (" + value.str() + ") of variant type " + std::to_string(item.second.which()) + " in keydata result: " + e.what());
×
UNCOV
495
      }
×
496
    }
24✔
497
    if (d_debug_log) {
6!
498
      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,
×
499
           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")));
×
500
    }
×
501
    keys.emplace_back(std::move(key));
6✔
502
  }
6✔
503

504
  return true;
3✔
505
}
3✔
506

507
bool Lua2BackendAPIv2::getBeforeAndAfterNamesAbsolute(domainid_t domain_id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
508
{
12✔
509
  if (f_get_before_and_after_names_absolute == nullptr) {
12!
510
    return false;
×
511
  }
×
512

513
  if (d_debug_log) {
12!
514
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_before_and_after_names_absolute" << "(" << "id=<<" << domain_id << ",qname=" << qname << ")" << endl,
×
515
         d_slog->info(Logr::Debug, "Calling get_before_and_after_names_absolute", "id", Logging::Loggable(domain_id), "name", Logging::Loggable(qname)));
×
516
  }
×
517
  get_before_and_after_names_absolute_result_t result = f_get_before_and_after_names_absolute(domain_id, qname);
12✔
518

519
  if (result.which() == 0) {
12!
520
    return false;
×
521
  }
×
522

523
  before_and_after_names_result_t row = boost::get<before_and_after_names_result_t>(result);
12✔
524
  if (row.size() != 3) {
12!
525
    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,
×
526
         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())));
×
527
    return false;
×
528
  }
×
529
  for (const auto& item : row) {
36✔
530
    DNSName value;
36✔
531
    if (item.second.which() == 0) {
36!
532
      value = DNSName(boost::get<string>(item.second));
×
533
    }
×
534
    else {
36✔
535
      value = DNSName(boost::get<DNSName>(item.second));
36✔
536
    }
36✔
537
    if (item.first == "unhashed") {
36✔
538
      unhashed = std::move(value);
12✔
539
    }
12✔
540
    else if (item.first == "before") {
24✔
541
      before = std::move(value);
12✔
542
    }
12✔
543
    else if (item.first == "after") {
12!
544
      after = std::move(value);
12✔
545
    }
12✔
546
    else {
×
547
      SLOG(g_log << Logger::Error << "Invalid result from dns_get_before_and_after_names_absolute, unexpected key " << item.first << endl,
×
548
           d_slog->info(Logr::Error, "Invalid result from dns_get_before_and_after_names_absolute, unexpected key", "key", Logging::Loggable(item.first)));
×
549
      return false;
×
550
    }
×
551
  }
36✔
552

553
  if (d_debug_log) {
12!
554
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "unhashed=" << unhashed << ",before=" << before << ",after=" << after << "'" << endl,
×
555
         d_slog->info(Logr::Debug, "Got result", "unhashed", Logging::Loggable(unhashed), "before", Logging::Loggable(before), "after", Logging::Loggable(after)));
×
556
  }
×
557
  return true;
12✔
558
}
12✔
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

© 2026 Coveralls, Inc