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

PowerDNS / pdns / 29271067186

13 Jul 2026 05:35PM UTC coverage: 71.155%. First build
29271067186

Pull #17731

github

web-flow
Merge 4e01dd661 into 4422d2aa1
Pull Request #17731: auth: Lua2 backend: more robust script results parsing

46752 of 82254 branches covered (56.84%)

Branch coverage included in aggregate %.

222 of 434 new or added lines in 1 file covered. (51.15%)

134155 of 171989 relevant lines covered (78.0%)

6275870.86 hits per line

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

46.84
/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();
×
NEW
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 for this particular case and none of the other readVariable calls.
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!
NEW
64
    init();
×
NEW
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!
NEW
70
    throw PDNSException("dns_lookup missing");
×
NEW
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!
NEW
77
      throw PDNSException("dns_dnssec is true but dns_get_domain_metadata is missing");
×
NEW
78
    }
×
79
    if (f_get_before_and_after_names_absolute == nullptr) {
15!
NEW
80
      throw PDNSException("dns_dnssec is true but dns_get_before_and_after_names_absolute is missing");
×
NEW
81
    }
×
82
    /* domain keys is not strictly speaking necessary for dnssec backend */
83
    if (f_get_domain_keys == nullptr) {
15!
NEW
84
      SLOG(g_log << Logger::Warning << "dns_get_domain_keys missing - cannot do live signing" << endl,
×
NEW
85
           d_slog->info(Logr::Warning, "dns_get_domain_keys missing - cannot perform live signing"));
×
NEW
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) {
437✔
107
      try {
437✔
108
        if (item.first == "type") {
437✔
109
          if (item.second.which() == 1) {
103!
NEW
110
            rec.qtype = QType(boost::get<int>(item.second));
×
NEW
111
          }
×
112
          else if (item.second.which() == 3) {
103!
NEW
113
            rec.qtype = boost::get<string>(item.second);
×
NEW
114
          }
×
115
          else if (item.second.which() == 4) {
103!
116
            rec.qtype = boost::get<QType>(item.second);
103✔
117
          }
103✔
NEW
118
          else {
×
NEW
119
            throw PDNSException("Unsupported value for type");
×
NEW
120
          }
×
121
        }
103✔
122
        else if (item.first == "name") {
334✔
123
          if (item.second.which() == 3) {
103!
NEW
124
            rec.qname = DNSName(boost::get<string>(item.second));
×
NEW
125
          }
×
126
          else { // assuming item.second.which() == 2 here
103✔
127
            rec.qname = boost::get<DNSName>(item.second);
103✔
128
          }
103✔
129
        }
103✔
130
        else if (item.first == "domain_id") {
231✔
131
          rec.domain_id = boost::get<int>(item.second);
25✔
132
        }
25✔
133
        else if (item.first == "auth") {
206!
NEW
134
          rec.auth = boost::get<bool>(item.second);
×
NEW
135
        }
×
136
        else if (item.first == "last_modified") {
206!
NEW
137
          rec.last_modified = static_cast<time_t>(boost::get<int>(item.second));
×
NEW
138
        }
×
139
        else if (item.first == "ttl") {
206✔
140
          rec.ttl = boost::get<int>(item.second);
103✔
141
        }
103✔
142
        else if (item.first == "content") {
103!
143
          if (item.second.which() == 1) {
103!
NEW
144
            rec.setContent(std::to_string(boost::get<int>(item.second)));
×
NEW
145
          }
×
146
          else { // assuming item.second.which() == 3 here
103✔
147
            rec.setContent(boost::get<string>(item.second));
103✔
148
          }
103✔
149
        }
103✔
NEW
150
        else if (item.first == "scopeMask") {
×
NEW
151
          rec.scopeMask = boost::get<int>(item.second);
×
NEW
152
        }
×
NEW
153
        else {
×
NEW
154
          SLOG(g_log << Logger::Warning << "Unsupported key '" << item.first << "' in lookup or list result" << endl,
×
NEW
155
               d_slog->info(Logr::Warning, "Unsupported key in lookup or list result", "key", Logging::Loggable(item.first)));
×
NEW
156
        }
×
157
      }
437✔
158
      catch (const std::exception& e) {
437✔
NEW
159
        throw PDNSException("Unable to parse " + item.first + " value in lookup or list result: " + e.what());
×
NEW
160
      }
×
161
    }
437✔
162
    if (d_debug_log) {
103!
NEW
163
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << rec.qname << " IN " << rec.qtype.toString() << " " << rec.ttl << " " << rec.getZoneRepresentation() << "'" << endl,
×
NEW
164
           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())));
×
NEW
165
    }
×
166
    d_result.push_back(std::move(rec));
103✔
167
  }
103✔
168
  if (d_result.empty() && d_debug_log) {
29!
NEW
169
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got empty result" << endl,
×
NEW
170
         d_slog->info(Logr::Debug, "Got empty result"));
×
NEW
171
  }
×
172
}
29✔
173

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

182
  if (!d_result.empty()) {
6!
NEW
183
    throw PDNSException("list attempted while another was running");
×
NEW
184
  }
×
185

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

192
  if (result.which() == 0) {
6!
NEW
193
    return false;
×
NEW
194
  }
×
195

196
  parseLookup(boost::get<lookup_result_t>(result));
6✔
197

198
  return true;
6✔
199
}
6✔
200

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

207
  lookup_context_t ctx;
23✔
208
  if (pkt != nullptr) {
23✔
209
    ctx.emplace_back(lookup_context_t::value_type{"source_address", pkt->getInnerRemote().toString()});
5✔
210
    ctx.emplace_back(lookup_context_t::value_type{"real_source_address", pkt->getRealRemote().toString()});
5✔
211
  }
5✔
212

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

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

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

251
void Lua2BackendAPIv2::setNotified(domainid_t domain_id, uint32_t serial)
NEW
252
{
×
NEW
253
  if (f_set_notified == nullptr) {
×
NEW
254
    return;
×
NEW
255
  }
×
NEW
256
  if (d_debug_log) {
×
NEW
257
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "dns_set_notified" << "(" << "id=" << domain_id << ",serial=" << serial << ")" << endl,
×
NEW
258
         d_slog->info(Logr::Debug, "Calling dns_set_notified", "id", Logging::Loggable(domain_id), "serial", Logging::Loggable(serial)));
×
NEW
259
  }
×
NEW
260
  f_set_notified(domain_id, serial);
×
NEW
261
}
×
262

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

312
bool Lua2BackendAPIv2::getDomainInfo(const ZoneName& domain, DomainInfo& info, bool /* getSerial */)
313
{
6✔
314
  if (f_get_domaininfo == nullptr) {
6✔
315
    // use getAuth instead... but getAuth wraps getSOA which will call
316
    // getDomainInfo if this is a domain variant, so protect against this
317
    // would-be infinite recursion.
318
    if (domain.hasVariant()) {
3!
NEW
319
      SLOG(g_log << Logger::Info << "Unable to return domain information for '" << domain.toLogString() << "' due to unimplemented dns_get_domaininfo" << endl,
×
NEW
320
           d_slog->info(Logr::Info, "Unable to return domain information due to unimplemented dns_get_domaininfo", "domain", Logging::Loggable(domain)));
×
NEW
321
      return false;
×
NEW
322
    }
×
323
    SOAData soa;
3✔
324
    if (!getAuth(domain, &soa)) {
3!
NEW
325
      return false;
×
NEW
326
    }
×
327

328
    info.id = soa.domain_id;
3✔
329
    info.zone = domain;
3✔
330
    info.backend = this;
3✔
331
    info.serial = soa.serial;
3✔
332
    return true;
3✔
333
  }
3✔
334

335
  if (d_debug_log) {
3!
NEW
336
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domaininfo" << "(" << "domain=" << domain << ")" << endl,
×
NEW
337
         d_slog->info(Logr::Debug, "Calling get_domaininfo", "domain", Logging::Loggable(domain)));
×
NEW
338
  }
×
339
  get_domaininfo_result_t result = f_get_domaininfo(domain.operator const DNSName&());
3✔
340

341
  if (result.which() == 0) {
3!
NEW
342
    return false;
×
NEW
343
  }
×
344

345
  info.zone = domain;
3✔
346
  parseDomainInfo(boost::get<domaininfo_result_t>(result), info);
3✔
347

348
  return true;
3✔
349
}
3✔
350

351
void Lua2BackendAPIv2::getAllDomains(vector<DomainInfo>* domains, bool /* getSerial */, bool /* include_disabled */)
352
{
1✔
353
  if (f_get_all_domains == nullptr) {
1!
NEW
354
    return;
×
NEW
355
  }
×
356

357
  if (d_debug_log) {
1!
NEW
358
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_all_domains" << "(" << "" << ")" << endl,
×
NEW
359
         d_slog->info(Logr::Debug, "Calling get_all_domains"));
×
NEW
360
  }
×
361
  for (const auto& row : f_get_all_domains()) {
2✔
362
    DomainInfo info;
2✔
363
    info.zone = ZoneName(row.first);
2✔
364
    if (d_debug_log) {
2!
NEW
365
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << info.zone << "'" << endl,
×
NEW
366
           d_slog->info(Logr::Debug, "Got result", "domain", Logging::Loggable(info.zone)));
×
NEW
367
    }
×
368
    parseDomainInfo(row.second, info);
2✔
369
    domains->push_back(std::move(info));
2✔
370
  }
2✔
371
}
1✔
372

373
bool Lua2BackendAPIv2::getAllDomainMetadata(const ZoneName& name, std::map<std::string, std::vector<std::string>>& meta)
374
{
6✔
375
  if (f_get_all_domain_metadata == nullptr) {
6!
376
    return false;
6✔
377
  }
6✔
378

NEW
379
  if (d_debug_log) {
×
NEW
380
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_all_domain_metadata" << "(" << "name=" << name << ")" << endl,
×
NEW
381
         d_slog->info(Logr::Debug, "Calling get_all_domain_metadata", "domain", Logging::Loggable(name)));
×
NEW
382
  }
×
NEW
383
  get_all_domain_metadata_result_t result = f_get_all_domain_metadata(name.operator const DNSName&());
×
NEW
384
  if (result.which() == 0) {
×
NEW
385
    return false;
×
NEW
386
  }
×
387

NEW
388
  for (const auto& row : boost::get<vector<pair<string, domain_metadata_result_t>>>(result)) {
×
NEW
389
    meta[row.first].clear();
×
NEW
390
    for (const auto& item : row.second) {
×
NEW
391
      meta[row.first].push_back(item.second);
×
NEW
392
    }
×
NEW
393
    if (d_debug_log) {
×
NEW
394
      SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "kind=" << row.first << ",value=" << boost::algorithm::join(meta[row.first], ", ") << "'" << endl,
×
NEW
395
           d_slog->info(Logr::Debug, "Got result", "kind", Logging::Loggable(row.first), "value", Logging::Loggable(boost::algorithm::join(meta[row.first], ", "))));
×
NEW
396
    }
×
NEW
397
  }
×
398

NEW
399
  return true;
×
NEW
400
}
×
401

402
bool Lua2BackendAPIv2::getDomainMetadata(const ZoneName& name, const std::string& kind, std::vector<std::string>& meta)
NEW
403
{
×
NEW
404
  if (f_get_domain_metadata == nullptr) {
×
NEW
405
    return false;
×
NEW
406
  }
×
407

NEW
408
  if (d_debug_log) {
×
NEW
409
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domain_metadata" << "(" << "name=" << name << ",kind=" << kind << ")" << endl,
×
NEW
410
         d_slog->info(Logr::Debug, "Calling get_domain_metadata", "domain", Logging::Loggable(name), "kind", Logging::Loggable(kind)));
×
NEW
411
  }
×
NEW
412
  get_domain_metadata_result_t result = f_get_domain_metadata(name.operator const DNSName&(), kind);
×
NEW
413
  if (result.which() == 0) {
×
NEW
414
    return false;
×
NEW
415
  }
×
416

NEW
417
  meta.clear();
×
NEW
418
  for (const auto& item : boost::get<domain_metadata_result_t>(result)) {
×
NEW
419
    meta.push_back(item.second);
×
NEW
420
  }
×
421

NEW
422
  if (d_debug_log) {
×
NEW
423
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "value=" << boost::algorithm::join(meta, ", ") << "'" << endl,
×
NEW
424
         d_slog->info(Logr::Debug, "Got result", "value", Logging::Loggable(boost::algorithm::join(meta, ", "))));
×
NEW
425
  }
×
NEW
426
  return true;
×
NEW
427
}
×
428

429
bool Lua2BackendAPIv2::getDomainKeys(const ZoneName& name, std::vector<DNSBackend::KeyData>& keys)
430
{
6✔
431
  if (f_get_domain_keys == nullptr) {
6✔
432
    return false;
3✔
433
  }
3✔
434

435
  if (d_debug_log) {
3!
NEW
436
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_domain_keys" << "(" << "name=" << name << ")" << endl,
×
NEW
437
         d_slog->info(Logr::Debug, "Calling get_domain_keys", "domain", Logging::Loggable(name)));
×
NEW
438
  }
×
439
  get_domain_keys_result_t result = f_get_domain_keys(name.operator const DNSName&());
3✔
440

441
  if (result.which() == 0) {
3!
NEW
442
    return false;
×
NEW
443
  }
×
444

445
  for (const auto& row : boost::get<vector<pair<int, keydata_result_t>>>(result)) {
6✔
446
    DNSBackend::KeyData key;
6✔
447
    key.published = true;
6✔
448
    for (const auto& item : row.second) {
24✔
449
      try {
24✔
450
        if (item.first == "content") {
24✔
451
          key.content = boost::get<string>(item.second);
6✔
452
        }
6✔
453
        else if (item.first == "id") {
18✔
454
          key.id = static_cast<unsigned int>(boost::get<int>(item.second));
6✔
455
        }
6✔
456
        else if (item.first == "flags") {
12✔
457
          key.flags = static_cast<unsigned int>(boost::get<int>(item.second));
6✔
458
        }
6✔
459
        else if (item.first == "active") {
6!
460
          key.active = boost::get<bool>(item.second);
6✔
461
        }
6✔
NEW
462
        else if (item.first == "published") {
×
NEW
463
          key.published = boost::get<bool>(item.second);
×
NEW
464
        }
×
NEW
465
        else {
×
NEW
466
          SLOG(g_log << Logger::Warning << "[" << getPrefix() << "] Unsupported key '" << item.first << "' in keydata result" << endl,
×
NEW
467
               d_slog->info(Logr::Warning, "Unsupported key in keydata result", "key", Logging::Loggable(item.first)));
×
NEW
468
        }
×
469
      }
24✔
470
      catch (const std::exception& e) {
24✔
NEW
471
        throw PDNSException("Unable to parse " + item.first + " value in keydata result: " + e.what());
×
NEW
472
      }
×
473
    }
24✔
474
    if (d_debug_log) {
6!
NEW
475
      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
476
           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")));
×
NEW
477
    }
×
478
    keys.emplace_back(std::move(key));
6✔
479
  }
6✔
480

481
  return true;
3✔
482
}
3✔
483

484
bool Lua2BackendAPIv2::getBeforeAndAfterNamesAbsolute(domainid_t domain_id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
485
{
12✔
486
  if (f_get_before_and_after_names_absolute == nullptr) {
12!
NEW
487
    return false;
×
NEW
488
  }
×
489

490
  if (d_debug_log) {
12!
NEW
491
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Calling " << "get_before_and_after_names_absolute" << "(" << "id=<<" << domain_id << ",qname=" << qname << ")" << endl,
×
NEW
492
         d_slog->info(Logr::Debug, "Calling get_before_and_after_names_absolute", "id", Logging::Loggable(domain_id), "name", Logging::Loggable(qname)));
×
NEW
493
  }
×
494
  get_before_and_after_names_absolute_result_t result = f_get_before_and_after_names_absolute(domain_id, qname);
12✔
495

496
  if (result.which() == 0) {
12!
NEW
497
    return false;
×
NEW
498
  }
×
499

500
  before_and_after_names_result_t row = boost::get<before_and_after_names_result_t>(result);
12✔
501
  if (row.size() != 3) {
12!
NEW
502
    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
503
         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())));
×
NEW
504
    return false;
×
NEW
505
  }
×
506
  for (const auto& item : row) {
36✔
507
    DNSName value;
36✔
508
    if (item.second.which() == 0) {
36!
NEW
509
      value = DNSName(boost::get<string>(item.second));
×
NEW
510
    }
×
511
    else {
36✔
512
      value = DNSName(boost::get<DNSName>(item.second));
36✔
513
    }
36✔
514
    if (item.first == "unhashed") {
36✔
515
      unhashed = std::move(value);
12✔
516
    }
12✔
517
    else if (item.first == "before") {
24✔
518
      before = std::move(value);
12✔
519
    }
12✔
520
    else if (item.first == "after") {
12!
521
      after = std::move(value);
12✔
522
    }
12✔
NEW
523
    else {
×
NEW
524
      SLOG(g_log << Logger::Error << "Invalid result from dns_get_before_and_after_names_absolute, unexpected key " << item.first << endl,
×
NEW
525
           d_slog->info(Logr::Error, "Invalid result from dns_get_before_and_after_names_absolute, unexpected key", "key", Logging::Loggable(item.first)));
×
NEW
526
      return false;
×
NEW
527
    }
×
528
  }
36✔
529

530
  if (d_debug_log) {
12!
NEW
531
    SLOG(g_log << Logger::Debug << "[" << getPrefix() << "] Got result " << "'" << "unhashed=" << unhashed << ",before=" << before << ",after=" << after << "'" << endl,
×
NEW
532
         d_slog->info(Logr::Debug, "Got result", "unhashed", Logging::Loggable(unhashed), "before", Logging::Loggable(before), "after", Logging::Loggable(after)));
×
NEW
533
  }
×
534
  return true;
12✔
535
}
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