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

PowerDNS / pdns / 15903936406

26 Jun 2025 02:00PM UTC coverage: 65.386% (-0.3%) from 65.652%
15903936406

Pull #15669

github

web-flow
Merge 63f450344 into d74120e51
Pull Request #15669: Increase zone serial number after zone key operations

41453 of 91850 branches covered (45.13%)

Branch coverage included in aggregate %.

23 of 26 new or added lines in 1 file covered. (88.46%)

616 existing lines in 23 files now uncovered.

126273 of 164666 relevant lines covered (76.68%)

5988606.35 hits per line

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

60.2
/modules/bindbackend/bindbackend2.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
 * MERCHANTABILITY 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

23
#ifdef HAVE_CONFIG_H
24
#include "config.h"
25
#endif
26
#include <cerrno>
27
#include <string>
28
#include <set>
29
#include <sys/types.h>
30
#include <sys/stat.h>
31
#include <unistd.h>
32
#include <fstream>
33
#include <fcntl.h>
34
#include <sstream>
35
#include <boost/algorithm/string.hpp>
36
#include <system_error>
37
#include <unordered_map>
38
#include <unordered_set>
39

40
#include "pdns/dnsseckeeper.hh"
41
#include "pdns/dnssecinfra.hh"
42
#include "pdns/base32.hh"
43
#include "pdns/namespaces.hh"
44
#include "pdns/dns.hh"
45
#include "pdns/dnsbackend.hh"
46
#include "bindbackend2.hh"
47
#include "pdns/dnspacket.hh"
48
#include "pdns/zoneparser-tng.hh"
49
#include "pdns/bindparserclasses.hh"
50
#include "pdns/logger.hh"
51
#include "pdns/arguments.hh"
52
#include "pdns/qtype.hh"
53
#include "pdns/misc.hh"
54
#include "pdns/dynlistener.hh"
55
#include "pdns/lock.hh"
56
#include "pdns/auth-zonecache.hh"
57
#include "pdns/auth-caches.hh"
58

59
/*
60
   All instances of this backend share one s_state, which is indexed by zone name and zone id.
61
   The s_state is protected by a read/write lock, and the goal it to only interact with it briefly.
62
   When a query comes in, we take a read lock and COPY the best zone to answer from s_state (BB2DomainInfo object)
63
   All answers are served from this copy.
64

65
   To interact with s_state, use safeGetBBDomainInfo (search on name or id), safePutBBDomainInfo (to update)
66
   or safeRemoveBBDomainInfo. These all lock as they should.
67

68
   Several functions need to traverse s_state to get data for the rest of PowerDNS. When doing so,
69
   you need to manually take the lock (read).
70

71
   Parsing zones happens with parseZone(), which fills a BB2DomainInfo object. This can then be stored with safePutBBDomainInfo.
72

73
   Finally, the BB2DomainInfo contains all records as a LookButDontTouch object. This makes sure you only look, but don't touch, since
74
   the records might be in use in other places.
75
*/
76

77
SharedLockGuarded<Bind2Backend::state_t> Bind2Backend::s_state;
78
int Bind2Backend::s_first = 1;
79
bool Bind2Backend::s_ignore_broken_records = false;
80

81
std::mutex Bind2Backend::s_autosecondary_config_lock; // protects writes to config file
82
std::mutex Bind2Backend::s_startup_lock;
83
string Bind2Backend::s_binddirectory;
84

85
BB2DomainInfo::BB2DomainInfo()
86
{
15,015✔
87
  d_loaded = false;
15,015✔
88
  d_lastcheck = 0;
15,015✔
89
  d_checknow = false;
15,015✔
90
  d_status = "Unknown";
15,015✔
91
}
15,015✔
92

93
void BB2DomainInfo::setCheckInterval(time_t seconds)
94
{
2,665✔
95
  d_checkinterval = seconds;
2,665✔
96
}
2,665✔
97

98
bool BB2DomainInfo::current()
99
{
4,103✔
100
  if (d_checknow) {
4,103✔
101
    return false;
6✔
102
  }
6✔
103

104
  if (!d_checkinterval)
4,097!
105
    return true;
4,097✔
106

107
  if (time(nullptr) - d_lastcheck < d_checkinterval)
×
108
    return true;
×
109

110
  if (d_filename.empty())
×
111
    return true;
×
112

113
  return (getCtime() == d_ctime);
×
114
}
×
115

116
time_t BB2DomainInfo::getCtime()
117
{
×
118
  struct stat buf;
×
119

120
  if (d_filename.empty() || stat(d_filename.c_str(), &buf) < 0)
×
121
    return 0;
×
122
  d_lastcheck = time(nullptr);
×
123
  return buf.st_ctime;
×
124
}
×
125

126
void BB2DomainInfo::setCtime()
127
{
2,671✔
128
  struct stat buf;
2,671✔
129
  if (stat(d_filename.c_str(), &buf) < 0)
2,671!
130
    return;
×
131
  d_ctime = buf.st_ctime;
2,671✔
132
}
2,671✔
133

134
// NOLINTNEXTLINE(readability-identifier-length)
135
bool Bind2Backend::safeGetBBDomainInfo(domainid_t id, BB2DomainInfo* bbd)
136
{
11,165✔
137
  auto state = s_state.read_lock();
11,165✔
138
  state_t::const_iterator iter = state->find(id);
11,165✔
139
  if (iter == state->end()) {
11,165!
140
    return false;
×
141
  }
×
142
  *bbd = *iter;
11,165✔
143
  return true;
11,165✔
144
}
11,165✔
145

146
bool Bind2Backend::safeGetBBDomainInfo(const ZoneName& name, BB2DomainInfo* bbd)
147
{
3,853✔
148
  auto state = s_state.read_lock();
3,853✔
149
  const auto& nameindex = boost::multi_index::get<NameTag>(*state);
3,853✔
150
  auto iter = nameindex.find(name);
3,853✔
151
  if (iter == nameindex.end()) {
3,853✔
152
    return false;
2,806✔
153
  }
2,806✔
154
  *bbd = *iter;
1,047✔
155
  return true;
1,047✔
156
}
3,853✔
157

158
bool Bind2Backend::safeRemoveBBDomainInfo(const ZoneName& name)
159
{
×
160
  auto state = s_state.write_lock();
×
161
  using nameindex_t = state_t::index<NameTag>::type;
×
162
  nameindex_t& nameindex = boost::multi_index::get<NameTag>(*state);
×
163

164
  nameindex_t::iterator iter = nameindex.find(name);
×
165
  if (iter == nameindex.end()) {
×
166
    return false;
×
167
  }
×
168
  nameindex.erase(iter);
×
169
  return true;
×
170
}
×
171

172
void Bind2Backend::safePutBBDomainInfo(const BB2DomainInfo& bbd)
173
{
2,815✔
174
  auto state = s_state.write_lock();
2,815✔
175
  replacing_insert(*state, bbd);
2,815✔
176
}
2,815✔
177

178
// NOLINTNEXTLINE(readability-identifier-length)
179
void Bind2Backend::setNotified(domainid_t id, uint32_t serial)
180
{
×
181
  BB2DomainInfo bbd;
×
182
  if (!safeGetBBDomainInfo(id, &bbd))
×
183
    return;
×
184
  bbd.d_lastnotified = serial;
×
185
  safePutBBDomainInfo(bbd);
×
186
}
×
187

188
// NOLINTNEXTLINE(readability-identifier-length)
189
void Bind2Backend::setLastCheck(domainid_t domain_id, time_t lastcheck)
190
{
72✔
191
  BB2DomainInfo bbd;
72✔
192
  if (safeGetBBDomainInfo(domain_id, &bbd)) {
72!
193
    bbd.d_lastcheck = lastcheck;
72✔
194
    safePutBBDomainInfo(bbd);
72✔
195
  }
72✔
196
}
72✔
197

198
void Bind2Backend::setStale(domainid_t domain_id)
199
{
×
200
  Bind2Backend::setLastCheck(domain_id, 0);
×
201
}
×
202

203
void Bind2Backend::setFresh(domainid_t domain_id)
204
{
72✔
205
  Bind2Backend::setLastCheck(domain_id, time(nullptr));
72✔
206
}
72✔
207

208
bool Bind2Backend::startTransaction(const ZoneName& qname, domainid_t domainId)
209
{
221✔
210
  if (domainId == UnknownDomainID) {
221✔
211
    d_transaction_tmpname.clear();
149✔
212
    d_transaction_id = UnknownDomainID;
149✔
213
    // No support for domain contents deletion
214
    return false;
149✔
215
  }
149✔
216
  if (domainId == 0) {
72!
217
    throw DBException("domain_id 0 is invalid for this backend.");
×
218
  }
×
219

220
  d_transaction_id = domainId;
72✔
221
  d_transaction_qname = qname;
72✔
222
  BB2DomainInfo bbd;
72✔
223
  if (safeGetBBDomainInfo(domainId, &bbd)) {
72!
224
    d_transaction_tmpname = bbd.d_filename + "XXXXXX";
72✔
225
    int fd = mkstemp(&d_transaction_tmpname.at(0));
72✔
226
    if (fd == -1) {
72!
227
      throw DBException("Unable to create a unique temporary zonefile '" + d_transaction_tmpname + "': " + stringerror());
×
228
    }
×
229

230
    d_of = std::make_unique<ofstream>(d_transaction_tmpname);
72✔
231
    if (!*d_of) {
72!
232
      unlink(d_transaction_tmpname.c_str());
×
233
      close(fd);
×
234
      fd = -1;
×
235
      d_of.reset();
×
236
      throw DBException("Unable to open temporary zonefile '" + d_transaction_tmpname + "': " + stringerror());
×
237
    }
×
238
    close(fd);
72✔
239
    fd = -1;
72✔
240

241
    *d_of << "; Written by PowerDNS, don't edit!" << endl;
72✔
242
    *d_of << "; Zone '" << bbd.d_name << "' retrieved from primary " << endl
72✔
243
          << "; at " << nowTime() << endl; // insert primary info here again
72✔
244

245
    return true;
72✔
246
  }
72✔
247
  return false;
×
248
}
72✔
249

250
bool Bind2Backend::commitTransaction()
251
{
221✔
252
  // d_transaction_id is only set to a valid domain id if we are actually
253
  // setting up a replacement zone file with the updated data.
254
  if (d_transaction_id == UnknownDomainID) {
221✔
255
    return false;
149✔
256
  }
149✔
257
  d_of.reset();
72✔
258

259
  BB2DomainInfo bbd;
72✔
260
  if (safeGetBBDomainInfo(d_transaction_id, &bbd)) {
72!
261
    if (rename(d_transaction_tmpname.c_str(), bbd.d_filename.c_str()) < 0)
72!
262
      throw DBException("Unable to commit (rename to: '" + bbd.d_filename + "') AXFRed zone: " + stringerror());
×
263
    queueReloadAndStore(bbd.d_id);
72✔
264
  }
72✔
265

266
  d_transaction_id = UnknownDomainID;
72✔
267

268
  return true;
72✔
269
}
72✔
270

271
bool Bind2Backend::abortTransaction()
272
{
×
273
  // d_transaction_id is only set to a valid domain id if we are actually
274
  // setting up a replacement zone file with the updated data.
275
  if (d_transaction_id != UnknownDomainID) {
×
276
    unlink(d_transaction_tmpname.c_str());
×
277
    d_of.reset();
×
278
    d_transaction_id = UnknownDomainID;
×
279
  }
×
280

281
  return true;
×
282
}
×
283

284
bool Bind2Backend::feedRecord(const DNSResourceRecord& rr, const DNSName& /* ordername */, bool /* ordernameIsNSEC3 */)
285
{
202,785✔
286
  if (d_transaction_id == UnknownDomainID) {
202,785!
287
    throw DBException("Bind2Backend::feedRecord() called outside of transaction");
×
288
  }
×
289

290
  string qname;
202,785✔
291
  if (d_transaction_qname.empty()) {
202,785!
292
    qname = rr.qname.toString();
×
293
  }
×
294
  else if (rr.qname.isPartOf(d_transaction_qname)) {
202,785!
295
    if (rr.qname == d_transaction_qname.operator const DNSName&()) {
202,785✔
296
      qname = "@";
633✔
297
    }
633✔
298
    else {
202,152✔
299
      DNSName relName = rr.qname.makeRelative(d_transaction_qname);
202,152✔
300
      qname = relName.toStringNoDot();
202,152✔
301
    }
202,152✔
302
  }
202,785✔
303
  else {
×
304
    throw DBException("out-of-zone data '" + rr.qname.toLogString() + "' during AXFR of zone '" + d_transaction_qname.toLogString() + "'");
×
305
  }
×
306

307
  shared_ptr<DNSRecordContent> drc(DNSRecordContent::make(rr.qtype.getCode(), QClass::IN, rr.content));
202,785✔
308
  string content = drc->getZoneRepresentation();
202,785✔
309

310
  // SOA needs stripping too! XXX FIXME - also, this should not be here I think
311
  switch (rr.qtype.getCode()) {
202,785✔
312
  case QType::MX:
56✔
313
  case QType::SRV:
76✔
314
  case QType::CNAME:
208✔
315
  case QType::DNAME:
212✔
316
  case QType::NS:
432✔
317
    stripDomainSuffix(&content, d_transaction_qname.toString());
432✔
318
    // fallthrough
319
  default:
202,785✔
320
    if (d_of && *d_of) {
202,785!
321
      *d_of << qname << "\t" << rr.ttl << "\t" << rr.qtype.toString() << "\t" << content << endl;
202,785✔
322
    }
202,785✔
323
  }
202,785✔
324
  return true;
202,785✔
325
}
202,785✔
326

327
void Bind2Backend::getUpdatedPrimaries(vector<DomainInfo>& changedDomains, std::unordered_set<DNSName>& /* catalogs */, CatalogHashMap& /* catalogHashes */)
328
{
×
329
  vector<DomainInfo> consider;
×
330
  {
×
331
    auto state = s_state.read_lock();
×
332

333
    for (const auto& i : *state) {
×
334
      if (i.d_kind != DomainInfo::Primary && this->alsoNotify.empty() && i.d_also_notify.empty())
×
335
        continue;
×
336

337
      DomainInfo di;
×
338
      di.id = i.d_id;
×
339
      di.zone = i.d_name;
×
340
      di.last_check = i.d_lastcheck;
×
341
      di.notified_serial = i.d_lastnotified;
×
342
      di.backend = this;
×
343
      di.kind = DomainInfo::Primary;
×
344
      consider.push_back(std::move(di));
×
345
    }
×
346
  }
×
347

348
  SOAData soadata;
×
349
  for (DomainInfo& di : consider) {
×
350
    soadata.serial = 0;
×
351
    try {
×
352
      this->getSOA(di.zone, di.id, soadata); // we might not *have* a SOA yet, but this might trigger a load of it
×
353
    }
×
354
    catch (...) {
×
355
      continue;
×
356
    }
×
357
    if (di.notified_serial != soadata.serial) {
×
358
      BB2DomainInfo bbd;
×
359
      if (safeGetBBDomainInfo(di.id, &bbd)) {
×
360
        bbd.d_lastnotified = soadata.serial;
×
361
        safePutBBDomainInfo(bbd);
×
362
      }
×
363
      if (di.notified_serial) { // don't do notification storm on startup
×
364
        di.serial = soadata.serial;
×
365
        changedDomains.push_back(std::move(di));
×
366
      }
×
367
    }
×
368
  }
×
369
}
×
370

371
void Bind2Backend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, bool /* include_disabled */)
372
{
36✔
373
  SOAData soadata;
36✔
374

375
  // prevent deadlock by using getSOA() later on
376
  {
36✔
377
    auto state = s_state.read_lock();
36✔
378
    domains->reserve(state->size());
36✔
379

380
    for (const auto& i : *state) {
196✔
381
      DomainInfo di;
185✔
382
      di.id = i.d_id;
185✔
383
      di.zone = i.d_name;
185✔
384
      di.last_check = i.d_lastcheck;
185✔
385
      di.kind = i.d_kind;
185✔
386
      di.primaries = i.d_primaries;
185✔
387
      di.backend = this;
185✔
388
      domains->push_back(std::move(di));
185✔
389
    };
185✔
390
  }
36✔
391

392
  if (getSerial) {
36✔
393
    for (DomainInfo& di : *domains) {
299✔
394
      // do not corrupt di if domain supplied by another backend.
395
      if (di.backend != this)
299!
396
        continue;
299✔
397
      try {
×
398
        this->getSOA(di.zone, di.id, soadata);
×
399
      }
×
400
      catch (...) {
×
401
        continue;
×
402
      }
×
403
      di.serial = soadata.serial;
×
404
    }
×
405
  }
10✔
406
}
36✔
407

408
void Bind2Backend::getUnfreshSecondaryInfos(vector<DomainInfo>* unfreshDomains)
409
{
8✔
410
  vector<DomainInfo> domains;
8✔
411
  {
8✔
412
    auto state = s_state.read_lock();
8✔
413
    domains.reserve(state->size());
8✔
414
    for (const auto& i : *state) {
72✔
415
      if (i.d_kind != DomainInfo::Secondary)
72!
416
        continue;
×
417
      DomainInfo sd;
72✔
418
      sd.id = i.d_id;
72✔
419
      sd.zone = i.d_name;
72✔
420
      sd.primaries = i.d_primaries;
72✔
421
      sd.last_check = i.d_lastcheck;
72✔
422
      sd.backend = this;
72✔
423
      sd.kind = DomainInfo::Secondary;
72✔
424
      domains.push_back(std::move(sd));
72✔
425
    }
72✔
426
  }
8✔
427
  unfreshDomains->reserve(domains.size());
8✔
428

429
  for (DomainInfo& sd : domains) {
72✔
430
    SOAData soadata;
72✔
431
    soadata.refresh = 0;
72✔
432
    soadata.serial = 0;
72✔
433
    try {
72✔
434
      getSOA(sd.zone, sd.id, soadata); // we might not *have* a SOA yet
72✔
435
    }
72✔
436
    catch (...) {
72✔
437
    }
72✔
438
    sd.serial = soadata.serial;
72✔
439
    // coverity[store_truncates_time_t]
440
    if (sd.last_check + soadata.refresh < (unsigned int)time(nullptr))
72!
441
      unfreshDomains->push_back(std::move(sd));
72✔
442
  }
72✔
443
}
8✔
444

445
bool Bind2Backend::getDomainInfo(const ZoneName& domain, DomainInfo& info, bool getSerial)
446
{
574✔
447
  BB2DomainInfo bbd;
574✔
448
  if (!safeGetBBDomainInfo(domain, &bbd))
574✔
449
    return false;
129✔
450

451
  info.id = bbd.d_id;
445✔
452
  info.zone = domain;
445✔
453
  info.primaries = bbd.d_primaries;
445✔
454
  info.last_check = bbd.d_lastcheck;
445✔
455
  info.backend = this;
445✔
456
  info.kind = bbd.d_kind;
445✔
457
  info.serial = 0;
445✔
458
  if (getSerial) {
445✔
459
    try {
135✔
460
      SOAData sd;
135✔
461
      sd.serial = 0;
135✔
462

463
      getSOA(bbd.d_name, bbd.d_id, sd); // we might not *have* a SOA yet
135✔
464
      info.serial = sd.serial;
135✔
465
    }
135✔
466
    catch (...) {
135✔
467
    }
72✔
468
  }
135✔
469

470
  return true;
445✔
471
}
445✔
472

473
void Bind2Backend::alsoNotifies(const ZoneName& domain, set<string>* ips)
474
{
1✔
475
  // combine global list with local list
476
  for (const auto& i : this->alsoNotify) {
1!
477
    (*ips).insert(i);
×
478
  }
×
479
  // check metadata too if available
480
  vector<string> meta;
1✔
481
  if (getDomainMetadata(domain, "ALSO-NOTIFY", meta)) {
1!
482
    for (const auto& str : meta) {
×
483
      (*ips).insert(str);
×
484
    }
×
485
  }
×
486
  auto state = s_state.read_lock();
1✔
487
  for (const auto& i : *state) {
1!
488
    if (i.d_name == domain) {
×
489
      for (const auto& it : i.d_also_notify) {
×
490
        (*ips).insert(it);
×
491
      }
×
492
      return;
×
493
    }
×
494
  }
×
495
}
1✔
496

497
// only parses, does NOT add to s_state!
498
void Bind2Backend::parseZoneFile(BB2DomainInfo* bbd)
499
{
2,737✔
500
  NSEC3PARAMRecordContent ns3pr;
2,737✔
501
  bool nsec3zone = false;
2,737✔
502
  if (d_hybrid) {
2,737!
503
    DNSSECKeeper dk;
×
504
    nsec3zone = dk.getNSEC3PARAM(bbd->d_name, &ns3pr);
×
505
  }
×
506
  else
2,737✔
507
    nsec3zone = getNSEC3PARAMuncached(bbd->d_name, &ns3pr);
2,737✔
508

509
  auto records = std::make_shared<recordstorage_t>();
2,737✔
510
  ZoneParserTNG zpt(bbd->d_filename, bbd->d_name, s_binddirectory, d_upgradeContent);
2,737✔
511
  zpt.setMaxGenerateSteps(::arg().asNum("max-generate-steps"));
2,737✔
512
  zpt.setMaxIncludes(::arg().asNum("max-include-depth"));
2,737✔
513
  DNSResourceRecord rr;
2,737✔
514
  string hashed;
2,737✔
515
  while (zpt.get(rr)) {
3,277,123✔
516
    if (rr.qtype.getCode() == QType::NSEC || rr.qtype.getCode() == QType::NSEC3 || rr.qtype.getCode() == QType::NSEC3PARAM)
3,274,386!
517
      continue; // we synthesise NSECs on demand
×
518

519
    insertRecord(records, bbd->d_name, rr.qname, rr.qtype, rr.content, rr.ttl, "");
3,274,386✔
520
  }
3,274,386✔
521
  fixupOrderAndAuth(records, bbd->d_name, nsec3zone, ns3pr);
2,737✔
522
  doEmptyNonTerminals(records, bbd->d_name, nsec3zone, ns3pr);
2,737✔
523
  bbd->setCtime();
2,737✔
524
  bbd->d_loaded = true;
2,737✔
525
  bbd->d_checknow = false;
2,737✔
526
  bbd->d_status = "parsed into memory at " + nowTime();
2,737✔
527
  bbd->d_records = LookButDontTouch<recordstorage_t>(std::move(records));
2,737✔
528
  bbd->d_nsec3zone = nsec3zone;
2,737✔
529
  bbd->d_nsec3param = std::move(ns3pr);
2,737✔
530
}
2,737✔
531

532
/** THIS IS AN INTERNAL FUNCTION! It does moadnsparser prio impedance matching
533
    Much of the complication is due to the efforts to benefit from std::string reference counting copy on write semantics */
534
void Bind2Backend::insertRecord(std::shared_ptr<recordstorage_t>& records, const ZoneName& zoneName, const DNSName& qname, const QType& qtype, const string& content, int ttl, const std::string& hashed, const bool* auth)
535
{
3,279,002✔
536
  Bind2DNSRecord bdr;
3,279,002✔
537
  bdr.qname = qname;
3,279,002✔
538

539
  if (zoneName.empty())
3,279,002!
540
    ;
×
541
  else if (bdr.qname.isPartOf(zoneName))
3,279,002✔
542
    bdr.qname.makeUsRelative(zoneName);
3,278,700✔
543
  else {
302✔
544
    string msg = "Trying to insert non-zone data, name='" + bdr.qname.toLogString() + "', qtype=" + qtype.toString() + ", zone='" + zoneName.toLogString() + "'";
302✔
545
    if (s_ignore_broken_records) {
302!
546
      g_log << Logger::Warning << msg << " ignored" << endl;
302✔
547
      return;
302✔
548
    }
302✔
549
    throw PDNSException(std::move(msg));
×
550
  }
302✔
551

552
  //  bdr.qname.swap(bdr.qname);
553

554
  if (!records->empty() && bdr.qname == boost::prior(records->end())->qname)
3,278,700✔
555
    bdr.qname = boost::prior(records->end())->qname;
8,914✔
556

557
  bdr.qname = bdr.qname;
3,278,700✔
558
  bdr.qtype = qtype.getCode();
3,278,700✔
559
  bdr.content = content;
3,278,700✔
560
  bdr.nsec3hash = hashed;
3,278,700✔
561

562
  if (auth != nullptr) // Set auth on empty non-terminals
3,278,700✔
563
    bdr.auth = *auth;
4,616✔
564
  else
3,274,084✔
565
    bdr.auth = true;
3,274,084✔
566

567
  bdr.ttl = ttl;
3,278,700✔
568
  records->insert(std::move(bdr));
3,278,700✔
569
}
3,278,700✔
570

571
string Bind2Backend::DLReloadNowHandler(const vector<string>& parts, Utility::pid_t /* ppid */)
572
{
×
573
  ostringstream ret;
×
574

575
  for (auto i = parts.begin() + 1; i < parts.end(); ++i) {
×
576
    BB2DomainInfo bbd;
×
577
    ZoneName zone(*i);
×
578
    if (safeGetBBDomainInfo(zone, &bbd)) {
×
579
      Bind2Backend bb2;
×
580
      bb2.queueReloadAndStore(bbd.d_id);
×
581
      if (!safeGetBBDomainInfo(zone, &bbd)) // Read the *new* domain status
×
582
        ret << *i << ": [missing]\n";
×
583
      else
×
584
        ret << *i << ": " << (bbd.d_wasRejectedLastReload ? "[rejected]" : "") << "\t" << bbd.d_status << "\n";
×
585
      purgeAuthCaches(zone.toString() + "$");
×
586
      DNSSECKeeper::clearMetaCache(zone);
×
587
    }
×
588
    else
×
589
      ret << *i << " no such domain\n";
×
590
  }
×
591
  if (ret.str().empty())
×
592
    ret << "no domains reloaded";
×
593
  return ret.str();
×
594
}
×
595

596
string Bind2Backend::DLDomStatusHandler(const vector<string>& parts, Utility::pid_t /* ppid */)
597
{
28✔
598
  ostringstream ret;
28✔
599

600
  if (parts.size() > 1) {
28!
601
    for (auto i = parts.begin() + 1; i < parts.end(); ++i) {
×
602
      BB2DomainInfo bbd;
×
603
      if (safeGetBBDomainInfo(ZoneName(*i), &bbd)) {
×
604
        ret << *i << ": " << (bbd.d_loaded ? "" : "[rejected]") << "\t" << bbd.d_status << "\n";
×
605
      }
×
606
      else {
×
607
        ret << *i << " no such domain\n";
×
608
      }
×
609
    }
×
610
  }
×
611
  else {
28✔
612
    auto state = s_state.read_lock();
28✔
613
    for (const auto& i : *state) {
252✔
614
      ret << i.d_name << ": " << (i.d_loaded ? "" : "[rejected]") << "\t" << i.d_status << "\n";
252✔
615
    }
252✔
616
  }
28✔
617

618
  if (ret.str().empty())
28!
619
    ret << "no domains passed";
×
620

621
  return ret.str();
28✔
622
}
28✔
623

624
static void printDomainExtendedStatus(ostringstream& ret, const BB2DomainInfo& info)
625
{
×
626
  ret << info.d_name << ": " << std::endl;
×
627
  ret << "\t Status: " << info.d_status << std::endl;
×
628
  ret << "\t Internal ID: " << info.d_id << std::endl;
×
629
  ret << "\t On-disk file: " << info.d_filename << " (" << info.d_ctime << ")" << std::endl;
×
630
  ret << "\t Kind: ";
×
631
  switch (info.d_kind) {
×
632
  case DomainInfo::Primary:
×
633
    ret << "Primary";
×
634
    break;
×
635
  case DomainInfo::Secondary:
×
636
    ret << "Secondary";
×
637
    break;
×
638
  default:
×
639
    ret << "Native";
×
640
  }
×
641
  ret << std::endl;
×
642
  ret << "\t Primaries: " << std::endl;
×
643
  for (const auto& primary : info.d_primaries) {
×
644
    ret << "\t\t - " << primary.toStringWithPort() << std::endl;
×
645
  }
×
646
  ret << "\t Also Notify: " << std::endl;
×
647
  for (const auto& also : info.d_also_notify) {
×
648
    ret << "\t\t - " << also << std::endl;
×
649
  }
×
650
  ret << "\t Number of records: " << info.d_records.getEntriesCount() << std::endl;
×
651
  ret << "\t Loaded: " << info.d_loaded << std::endl;
×
652
  ret << "\t Check now: " << info.d_checknow << std::endl;
×
653
  ret << "\t Check interval: " << info.getCheckInterval() << std::endl;
×
654
  ret << "\t Last check: " << info.d_lastcheck << std::endl;
×
655
  ret << "\t Last notified: " << info.d_lastnotified << std::endl;
×
656
}
×
657

658
string Bind2Backend::DLDomExtendedStatusHandler(const vector<string>& parts, Utility::pid_t /* ppid */)
659
{
×
660
  ostringstream ret;
×
661

662
  if (parts.size() > 1) {
×
663
    for (auto i = parts.begin() + 1; i < parts.end(); ++i) {
×
664
      BB2DomainInfo bbd;
×
665
      if (safeGetBBDomainInfo(ZoneName(*i), &bbd)) {
×
666
        printDomainExtendedStatus(ret, bbd);
×
667
      }
×
668
      else {
×
669
        ret << *i << " no such domain" << std::endl;
×
670
      }
×
671
    }
×
672
  }
×
673
  else {
×
674
    auto rstate = s_state.read_lock();
×
675
    for (const auto& state : *rstate) {
×
676
      printDomainExtendedStatus(ret, state);
×
677
    }
×
678
  }
×
679

680
  if (ret.str().empty()) {
×
681
    ret << "no domains passed" << std::endl;
×
682
  }
×
683

684
  return ret.str();
×
685
}
×
686

687
string Bind2Backend::DLListRejectsHandler(const vector<string>& /* parts */, Utility::pid_t /* ppid */)
688
{
×
689
  ostringstream ret;
×
690
  auto rstate = s_state.read_lock();
×
691
  for (const auto& i : *rstate) {
×
692
    if (!i.d_loaded)
×
693
      ret << i.d_name << "\t" << i.d_status << endl;
×
694
  }
×
695
  return ret.str();
×
696
}
×
697

698
string Bind2Backend::DLAddDomainHandler(const vector<string>& parts, Utility::pid_t /* ppid */)
699
{
12✔
700
  if (parts.size() < 3)
12!
701
    return "ERROR: Domain name and zone filename are required";
×
702

703
  ZoneName domainname(parts[1]);
12✔
704
  const string& filename = parts[2];
12✔
705
  BB2DomainInfo bbd;
12✔
706
  if (safeGetBBDomainInfo(domainname, &bbd))
12✔
707
    return "Already loaded";
6✔
708

709
  if (!boost::starts_with(filename, "/") && ::arg()["chroot"].empty())
6!
710
    return "Unable to load zone " + domainname.toLogString() + " from " + filename + " as the filename is not absolute.";
×
711

712
  struct stat buf;
6✔
713
  if (stat(filename.c_str(), &buf) != 0)
6!
714
    return "Unable to load zone " + domainname.toLogString() + " from " + filename + ": " + strerror(errno);
×
715

716
  Bind2Backend bb2; // createdomainentry needs access to our configuration
6✔
717
  bbd = bb2.createDomainEntry(domainname, filename);
6✔
718
  bbd.d_filename = filename;
6✔
719
  bbd.d_checknow = true;
6✔
720
  bbd.d_loaded = true;
6✔
721
  bbd.d_lastcheck = 0;
6✔
722
  bbd.d_status = "parsing into memory";
6✔
723
  bbd.setCtime();
6✔
724

725
  safePutBBDomainInfo(bbd);
6✔
726

727
  g_zoneCache.add(domainname, bbd.d_id); // make new zone visible
6✔
728

729
  g_log << Logger::Warning << "Zone " << domainname << " loaded" << endl;
6✔
730
  return "Loaded zone " + domainname.toLogString() + " from " + filename;
6✔
731
}
6✔
732

733
Bind2Backend::Bind2Backend(const string& suffix, bool loadZones)
734
{
1,810✔
735
  d_getAllDomainMetadataQuery_stmt = nullptr;
1,810✔
736
  d_getDomainMetadataQuery_stmt = nullptr;
1,810✔
737
  d_deleteDomainMetadataQuery_stmt = nullptr;
1,810✔
738
  d_insertDomainMetadataQuery_stmt = nullptr;
1,810✔
739
  d_getDomainKeysQuery_stmt = nullptr;
1,810✔
740
  d_deleteDomainKeyQuery_stmt = nullptr;
1,810✔
741
  d_insertDomainKeyQuery_stmt = nullptr;
1,810✔
742
  d_GetLastInsertedKeyIdQuery_stmt = nullptr;
1,810✔
743
  d_activateDomainKeyQuery_stmt = nullptr;
1,810✔
744
  d_deactivateDomainKeyQuery_stmt = nullptr;
1,810✔
745
  d_getTSIGKeyQuery_stmt = nullptr;
1,810✔
746
  d_setTSIGKeyQuery_stmt = nullptr;
1,810✔
747
  d_deleteTSIGKeyQuery_stmt = nullptr;
1,810✔
748
  d_getTSIGKeysQuery_stmt = nullptr;
1,810✔
749

750
  setArgPrefix("bind" + suffix);
1,810✔
751
  d_logprefix = "[bind" + suffix + "backend]";
1,810✔
752
  d_hybrid = mustDo("hybrid");
1,810✔
753
  if (d_hybrid && g_zoneCache.isEnabled()) {
1,810!
754
    throw PDNSException("bind-hybrid and the zone cache currently interoperate badly. Please disable the zone cache or stop using bind-hybrid");
×
755
  }
×
756

757
  d_transaction_id = UnknownDomainID;
1,810✔
758
  s_ignore_broken_records = mustDo("ignore-broken-records");
1,810✔
759
  d_upgradeContent = ::arg().mustDo("upgrade-unknown-types");
1,810✔
760

761
  if (!loadZones && d_hybrid)
1,810!
762
    return;
×
763

764
  std::lock_guard<std::mutex> l(s_startup_lock);
1,810✔
765

766
  setupDNSSEC();
1,810✔
767
  if (s_first == 0) {
1,810✔
768
    return;
1,322✔
769
  }
1,322✔
770

771
  if (loadZones) {
488✔
772
    loadConfig();
211✔
773
    s_first = 0;
211✔
774
  }
211✔
775

776
  DynListener::registerFunc("BIND-RELOAD-NOW", &DLReloadNowHandler, "bindbackend: reload domains", "<domains>");
488✔
777
  DynListener::registerFunc("BIND-DOMAIN-STATUS", &DLDomStatusHandler, "bindbackend: list status of all domains", "[domains]");
488✔
778
  DynListener::registerFunc("BIND-DOMAIN-EXTENDED-STATUS", &DLDomExtendedStatusHandler, "bindbackend: list the extended status of all domains", "[domains]");
488✔
779
  DynListener::registerFunc("BIND-LIST-REJECTS", &DLListRejectsHandler, "bindbackend: list rejected domains");
488✔
780
  DynListener::registerFunc("BIND-ADD-ZONE", &DLAddDomainHandler, "bindbackend: add zone", "<domain> <filename>");
488✔
781
}
488✔
782

783
Bind2Backend::~Bind2Backend()
784
{
1,696✔
785
  freeStatements();
1,696✔
786
} // deallocate statements
1,696✔
787

788
void Bind2Backend::rediscover(string* status)
789
{
×
790
  loadConfig(status);
×
791
}
×
792

793
void Bind2Backend::reload()
794
{
×
795
  auto state = s_state.write_lock();
×
796
  for (const auto& i : *state) {
×
797
    i.d_checknow = true; // being a bit cheeky here, don't index state_t on this (mutable)
×
798
  }
×
799
}
×
800

801
void Bind2Backend::fixupOrderAndAuth(std::shared_ptr<recordstorage_t>& records, const ZoneName& zoneName, bool nsec3zone, const NSEC3PARAMRecordContent& ns3pr)
802
{
2,665✔
803
  bool skip;
2,665✔
804
  DNSName shorter;
2,665✔
805
  set<DNSName> nssets, dssets;
2,665✔
806

807
  for (const auto& bdr : *records) {
3,274,084✔
808
    if (!bdr.qname.isRoot() && bdr.qtype == QType::NS)
3,274,084✔
809
      nssets.insert(bdr.qname);
3,010✔
810
    else if (bdr.qtype == QType::DS)
3,271,074✔
811
      dssets.insert(bdr.qname);
499✔
812
  }
3,274,084✔
813

814
  for (auto iter = records->begin(); iter != records->end(); iter++) {
3,276,749✔
815
    skip = false;
3,274,084✔
816
    shorter = iter->qname;
3,274,084✔
817

818
    if (!iter->qname.isRoot() && shorter.chopOff() && !iter->qname.isRoot()) {
3,274,084!
819
      do {
3,272,541✔
820
        if (nssets.count(shorter) != 0u) {
3,272,541✔
821
          skip = true;
1,359✔
822
          break;
1,359✔
823
        }
1,359✔
824
      } while (shorter.chopOff() && !iter->qname.isRoot());
3,272,541!
825
    }
3,262,953✔
826

827
    iter->auth = (!skip && (iter->qtype == QType::DS || iter->qtype == QType::RRSIG || (nssets.count(iter->qname) == 0u)));
3,274,084✔
828

829
    if (!skip && nsec3zone && iter->qtype != QType::RRSIG && (iter->auth || (iter->qtype == QType::NS && (ns3pr.d_flags == 0u)) || (dssets.count(iter->qname) != 0u))) {
3,274,084✔
830
      Bind2DNSRecord bdr = *iter;
1,439,445✔
831
      bdr.nsec3hash = toBase32Hex(hashQNameWithSalt(ns3pr, bdr.qname + zoneName.operator const DNSName&()));
1,439,445✔
832
      records->replace(iter, bdr);
1,439,445✔
833
    }
1,439,445✔
834

835
    // cerr<<iter->qname<<"\t"<<QType(iter->qtype).toString()<<"\t"<<iter->nsec3hash<<"\t"<<iter->auth<<endl;
836
  }
3,274,084✔
837
}
2,665✔
838

839
void Bind2Backend::doEmptyNonTerminals(std::shared_ptr<recordstorage_t>& records, const ZoneName& zoneName, bool nsec3zone, const NSEC3PARAMRecordContent& ns3pr)
840
{
2,665✔
841
  bool auth = false;
2,665✔
842
  DNSName shorter;
2,665✔
843
  std::unordered_set<DNSName> qnames;
2,665✔
844
  std::unordered_map<DNSName, bool> nonterm;
2,665✔
845

846
  uint32_t maxent = ::arg().asNum("max-ent-entries");
2,665✔
847

848
  for (const auto& bdr : *records)
2,665✔
849
    qnames.insert(bdr.qname);
3,274,084✔
850

851
  for (const auto& bdr : *records) {
3,274,084✔
852

853
    if (!bdr.auth && bdr.qtype == QType::NS)
3,274,084✔
854
      auth = (!nsec3zone || (ns3pr.d_flags == 0u));
3,010✔
855
    else
3,271,074✔
856
      auth = bdr.auth;
3,271,074✔
857

858
    shorter = bdr.qname;
3,274,084✔
859
    while (shorter.chopOff()) {
6,547,984✔
860
      if (qnames.count(shorter) == 0u) {
3,273,900✔
861
        if (!(maxent)) {
9,422!
862
          g_log << Logger::Error << "Zone '" << zoneName << "' has too many empty non terminals." << endl;
×
863
          return;
×
864
        }
×
865

866
        if (nonterm.count(shorter) == 0u) {
9,422✔
867
          nonterm.emplace(shorter, auth);
4,616✔
868
          --maxent;
4,616✔
869
        }
4,616✔
870
        else if (auth)
4,806✔
871
          nonterm[shorter] = true;
4,710✔
872
      }
9,422✔
873
    }
3,273,900✔
874
  }
3,274,084✔
875

876
  DNSResourceRecord rr;
2,665✔
877
  rr.qtype = "#0";
2,665✔
878
  rr.content = "";
2,665✔
879
  rr.ttl = 0;
2,665✔
880
  for (auto& nt : nonterm) {
4,617✔
881
    string hashed;
4,616✔
882
    rr.qname = nt.first + zoneName.operator const DNSName&();
4,616✔
883
    if (nsec3zone && nt.second)
4,616✔
884
      hashed = toBase32Hex(hashQNameWithSalt(ns3pr, rr.qname));
1,782✔
885
    insertRecord(records, zoneName, rr.qname, rr.qtype, rr.content, rr.ttl, hashed, &nt.second);
4,616✔
886

887
    // cerr<<rr.qname<<"\t"<<rr.qtype.toString()<<"\t"<<hashed<<"\t"<<nt.second<<endl;
888
  }
4,616✔
889
}
2,665✔
890

891
void Bind2Backend::loadConfig(string* status) // NOLINT(readability-function-cognitive-complexity) 13379 https://github.com/PowerDNS/pdns/issues/13379 Habbie: zone2sql.cc, bindbackend2.cc: reduce complexity
892
{
211✔
893
  static domainid_t domain_id = 1;
211✔
894

895
  if (!getArg("config").empty()) {
211!
896
    BindParser BP;
211✔
897
    try {
211✔
898
      BP.parse(getArg("config"));
211✔
899
    }
211✔
900
    catch (PDNSException& ae) {
211✔
901
      g_log << Logger::Error << "Error parsing bind configuration: " << ae.reason << endl;
×
902
      throw;
×
903
    }
×
904

905
    vector<BindDomainInfo> domains = BP.getDomains();
211✔
906
    this->alsoNotify = BP.getAlsoNotify();
211✔
907

908
    s_binddirectory = BP.getDirectory();
211✔
909
    //    ZP.setDirectory(d_binddirectory);
910

911
    g_log << Logger::Warning << d_logprefix << " Parsing " << domains.size() << " domain(s), will report when done" << endl;
211✔
912

913
    set<ZoneName> oldnames;
211✔
914
    set<ZoneName> newnames;
211✔
915
    {
211✔
916
      auto state = s_state.read_lock();
211✔
917
      for (const BB2DomainInfo& bbd : *state) {
211!
918
        oldnames.insert(bbd.d_name);
×
919
      }
×
920
    }
211✔
921
    int rejected = 0;
211✔
922
    int newdomains = 0;
211✔
923

924
    struct stat st;
211✔
925

926
    for (auto& domain : domains) {
2,691✔
927
      if (stat(domain.filename.c_str(), &st) == 0) {
2,659✔
928
        domain.d_dev = st.st_dev;
2,587✔
929
        domain.d_ino = st.st_ino;
2,587✔
930
      }
2,587✔
931
    }
2,659✔
932

933
    sort(domains.begin(), domains.end()); // put stuff in inode order
211✔
934
    for (const auto& domain : domains) {
2,691✔
935
      if (!(domain.hadFileDirective)) {
2,659!
936
        g_log << Logger::Warning << d_logprefix << " Zone '" << domain.name << "' has no 'file' directive set in " << getArg("config") << endl;
×
937
        rejected++;
×
938
        continue;
×
939
      }
×
940

941
      if (domain.type.empty()) {
2,659!
942
        g_log << Logger::Notice << d_logprefix << " Zone '" << domain.name << "' has no type specified, assuming 'native'" << endl;
×
943
      }
×
944
      if (domain.type != "primary" && domain.type != "secondary" && domain.type != "native" && !domain.type.empty() && domain.type != "master" && domain.type != "slave") {
2,659!
945
        g_log << Logger::Warning << d_logprefix << " Warning! Skipping zone '" << domain.name << "' because type '" << domain.type << "' is invalid" << endl;
×
946
        rejected++;
×
947
        continue;
×
948
      }
×
949

950
      BB2DomainInfo bbd;
2,659✔
951
      bool isNew = false;
2,659✔
952

953
      if (!safeGetBBDomainInfo(domain.name, &bbd)) {
2,659!
954
        isNew = true;
2,659✔
955
        bbd.d_id = domain_id++;
2,659✔
956
        bbd.setCheckInterval(getArgAsNum("check-interval"));
2,659✔
957
        bbd.d_lastnotified = 0;
2,659✔
958
        bbd.d_loaded = false;
2,659✔
959
      }
2,659✔
960

961
      // overwrite what we knew about the domain
962
      bbd.d_name = domain.name;
2,659✔
963
      bool filenameChanged = (bbd.d_filename != domain.filename);
2,659✔
964
      bool addressesChanged = (bbd.d_primaries != domain.primaries || bbd.d_also_notify != domain.alsoNotify);
2,659!
965
      bbd.d_filename = domain.filename;
2,659✔
966
      bbd.d_primaries = domain.primaries;
2,659✔
967
      bbd.d_also_notify = domain.alsoNotify;
2,659✔
968

969
      DomainInfo::DomainKind kind = DomainInfo::Native;
2,659✔
970
      if (domain.type == "primary" || domain.type == "master") {
2,659!
971
        kind = DomainInfo::Primary;
2,587✔
972
      }
2,587✔
973
      if (domain.type == "secondary" || domain.type == "slave") {
2,659!
974
        kind = DomainInfo::Secondary;
72✔
975
      }
72✔
976

977
      bool kindChanged = (bbd.d_kind != kind);
2,659✔
978
      bbd.d_kind = kind;
2,659✔
979

980
      newnames.insert(bbd.d_name);
2,659✔
981
      if (filenameChanged || !bbd.d_loaded || !bbd.current()) {
2,659!
982
        g_log << Logger::Info << d_logprefix << " parsing '" << domain.name << "' from file '" << domain.filename << "'" << endl;
2,659✔
983

984
        try {
2,659✔
985
          parseZoneFile(&bbd);
2,659✔
986
        }
2,659✔
987
        catch (PDNSException& ae) {
2,659✔
988
          ostringstream msg;
×
989
          msg << " error at " + nowTime() + " parsing '" << domain.name << "' from file '" << domain.filename << "': " << ae.reason;
×
990

991
          if (status != nullptr)
×
992
            *status += msg.str();
×
993
          bbd.d_status = msg.str();
×
994

995
          g_log << Logger::Warning << d_logprefix << msg.str() << endl;
×
996
          rejected++;
×
997
        }
×
998
        catch (std::system_error& ae) {
2,659✔
999
          ostringstream msg;
72✔
1000
          if (ae.code().value() == ENOENT && isNew && domain.type == "slave")
72!
1001
            msg << " error at " + nowTime() << " no file found for new secondary domain '" << domain.name << "'. Has not been AXFR'd yet";
×
1002
          else
72✔
1003
            msg << " error at " + nowTime() + " parsing '" << domain.name << "' from file '" << domain.filename << "': " << ae.what();
72✔
1004

1005
          if (status != nullptr)
72!
1006
            *status += msg.str();
×
1007
          bbd.d_status = msg.str();
72✔
1008
          g_log << Logger::Warning << d_logprefix << msg.str() << endl;
72✔
1009
          rejected++;
72✔
1010
        }
72✔
1011
        catch (std::exception& ae) {
2,659✔
1012
          ostringstream msg;
×
1013
          msg << " error at " + nowTime() + " parsing '" << domain.name << "' from file '" << domain.filename << "': " << ae.what();
×
1014

1015
          if (status != nullptr)
×
1016
            *status += msg.str();
×
1017
          bbd.d_status = msg.str();
×
1018

1019
          g_log << Logger::Warning << d_logprefix << msg.str() << endl;
×
1020
          rejected++;
×
1021
        }
×
1022
        safePutBBDomainInfo(bbd);
2,659✔
1023
      }
2,659✔
1024
      else if (addressesChanged || kindChanged) {
×
1025
        safePutBBDomainInfo(bbd);
×
1026
      }
×
1027
    }
2,659✔
1028
    vector<ZoneName> diff;
211✔
1029

1030
    set_difference(oldnames.begin(), oldnames.end(), newnames.begin(), newnames.end(), back_inserter(diff));
211✔
1031
    unsigned int remdomains = diff.size();
211✔
1032

1033
    for (const ZoneName& name : diff) {
211!
1034
      safeRemoveBBDomainInfo(name);
×
1035
    }
×
1036

1037
    // count number of entirely new domains
1038
    diff.clear();
211✔
1039
    set_difference(newnames.begin(), newnames.end(), oldnames.begin(), oldnames.end(), back_inserter(diff));
211✔
1040
    newdomains = diff.size();
211✔
1041

1042
    ostringstream msg;
211✔
1043
    msg << " Done parsing domains, " << rejected << " rejected, " << newdomains << " new, " << remdomains << " removed";
211✔
1044
    if (status != nullptr)
211!
1045
      *status = msg.str();
×
1046

1047
    g_log << Logger::Error << d_logprefix << msg.str() << endl;
211✔
1048
  }
211✔
1049
}
211✔
1050

1051
// NOLINTNEXTLINE(readability-identifier-length)
1052
void Bind2Backend::queueReloadAndStore(domainid_t id)
1053
{
78✔
1054
  BB2DomainInfo bbold;
78✔
1055
  try {
78✔
1056
    if (!safeGetBBDomainInfo(id, &bbold))
78!
1057
      return;
×
1058
    bbold.d_checknow = false;
78✔
1059
    BB2DomainInfo bbnew(bbold);
78✔
1060
    /* make sure that nothing will be able to alter the existing records,
1061
       we will load them from the zone file instead */
1062
    bbnew.d_records = LookButDontTouch<recordstorage_t>();
78✔
1063
    parseZoneFile(&bbnew);
78✔
1064
    bbnew.d_wasRejectedLastReload = false;
78✔
1065
    safePutBBDomainInfo(bbnew);
78✔
1066
    g_log << Logger::Warning << "Zone '" << bbnew.d_name << "' (" << bbnew.d_filename << ") reloaded" << endl;
78✔
1067
  }
78✔
1068
  catch (PDNSException& ae) {
78✔
1069
    ostringstream msg;
×
1070
    msg << " error at " + nowTime() + " parsing '" << bbold.d_name << "' from file '" << bbold.d_filename << "': " << ae.reason;
×
1071
    g_log << Logger::Warning << "Error parsing '" << bbold.d_name << "' from file '" << bbold.d_filename << "': " << ae.reason << endl;
×
1072
    bbold.d_status = msg.str();
×
1073
    bbold.d_lastcheck = time(nullptr);
×
1074
    bbold.d_wasRejectedLastReload = true;
×
1075
    safePutBBDomainInfo(bbold);
×
1076
  }
×
1077
  catch (std::exception& ae) {
78✔
1078
    ostringstream msg;
×
1079
    msg << " error at " + nowTime() + " parsing '" << bbold.d_name << "' from file '" << bbold.d_filename << "': " << ae.what();
×
1080
    g_log << Logger::Warning << "Error parsing '" << bbold.d_name << "' from file '" << bbold.d_filename << "': " << ae.what() << endl;
×
1081
    bbold.d_status = msg.str();
×
1082
    bbold.d_lastcheck = time(nullptr);
×
1083
    bbold.d_wasRejectedLastReload = true;
×
1084
    safePutBBDomainInfo(bbold);
×
1085
  }
×
1086
}
78✔
1087

1088
bool Bind2Backend::findBeforeAndAfterUnhashed(std::shared_ptr<const recordstorage_t>& records, const DNSName& qname, DNSName& /* unhashed */, DNSName& before, DNSName& after)
1089
{
2,706✔
1090
  // for(const auto& record: *records)
1091
  //   cerr<<record.qname<<"\t"<<makeHexDump(record.qname.toDNSString())<<endl;
1092

1093
  recordstorage_t::const_iterator iterBefore, iterAfter;
2,706✔
1094

1095
  iterBefore = iterAfter = records->upper_bound(qname.makeLowerCase());
2,706✔
1096

1097
  if (iterBefore != records->begin())
2,706!
1098
    --iterBefore;
2,706✔
1099
  while ((!iterBefore->auth && iterBefore->qtype != QType::NS) || !iterBefore->qtype)
3,270✔
1100
    --iterBefore;
564✔
1101
  before = iterBefore->qname;
2,706✔
1102

1103
  if (iterAfter == records->end()) {
2,706✔
1104
    iterAfter = records->begin();
376✔
1105
  }
376✔
1106
  else {
2,330✔
1107
    while ((!iterAfter->auth && iterAfter->qtype != QType::NS) || !iterAfter->qtype) {
3,494✔
1108
      ++iterAfter;
1,164✔
1109
      if (iterAfter == records->end()) {
1,164!
1110
        iterAfter = records->begin();
×
1111
        break;
×
1112
      }
×
1113
    }
1,164✔
1114
  }
2,330✔
1115
  after = iterAfter->qname;
2,706✔
1116

1117
  return true;
2,706✔
1118
}
2,706✔
1119

1120
// NOLINTNEXTLINE(readability-identifier-length)
1121
bool Bind2Backend::getBeforeAndAfterNamesAbsolute(domainid_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after)
1122
{
7,027✔
1123
  BB2DomainInfo bbd;
7,027✔
1124
  if (!safeGetBBDomainInfo(id, &bbd))
7,027!
1125
    return false;
×
1126

1127
  shared_ptr<const recordstorage_t> records = bbd.d_records.get();
7,027✔
1128
  if (!bbd.d_nsec3zone) {
7,027✔
1129
    return findBeforeAndAfterUnhashed(records, qname, unhashed, before, after);
2,706✔
1130
  }
2,706✔
1131
  else {
4,321✔
1132
    const auto& hashindex = boost::multi_index::get<NSEC3Tag>(*records);
4,321✔
1133

1134
    // for(auto iter = first; iter != hashindex.end(); iter++)
1135
    //  cerr<<iter->nsec3hash<<endl;
1136

1137
    auto first = hashindex.upper_bound("");
4,321✔
1138
    auto iter = hashindex.upper_bound(qname.toStringNoDot());
4,321✔
1139

1140
    if (iter == hashindex.end()) {
4,321✔
1141
      --iter;
343✔
1142
      before = DNSName(iter->nsec3hash);
343✔
1143
      after = DNSName(first->nsec3hash);
343✔
1144
    }
343✔
1145
    else {
3,978✔
1146
      after = DNSName(iter->nsec3hash);
3,978✔
1147
      if (iter != first)
3,978✔
1148
        --iter;
3,891✔
1149
      else
87✔
1150
        iter = --hashindex.end();
87✔
1151
      before = DNSName(iter->nsec3hash);
3,978✔
1152
    }
3,978✔
1153
    unhashed = iter->qname + bbd.d_name.operator const DNSName&();
4,321✔
1154

1155
    return true;
4,321✔
1156
  }
4,321✔
1157
}
7,027✔
1158

1159
void Bind2Backend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* /* pkt_p */)
1160
{
4,112✔
1161
  d_handle.reset();
4,112✔
1162

1163
  static bool mustlog = ::arg().mustDo("query-logging");
4,112✔
1164

1165
  bool found = false;
4,112✔
1166
  ZoneName domain;
4,112✔
1167
  BB2DomainInfo bbd;
4,112✔
1168

1169
  if (mustlog)
4,112!
1170
    g_log << Logger::Warning << "Lookup for '" << qtype.toString() << "' of '" << qname << "' within zoneID " << zoneId << endl;
×
1171

1172
  if (zoneId != UnknownDomainID) {
4,112✔
1173
    if ((found = (safeGetBBDomainInfo(zoneId, &bbd) && qname.isPartOf(bbd.d_name)))) {
3,513!
1174
      domain = std::move(bbd.d_name);
3,513✔
1175
    }
3,513✔
1176
  }
3,513✔
1177
  else {
599✔
1178
    domain = ZoneName(qname);
599✔
1179
    do {
602✔
1180
      found = safeGetBBDomainInfo(domain, &bbd);
602✔
1181
    } while (!found && qtype != QType::SOA && domain.chopOff());
602✔
1182
  }
599✔
1183

1184
  if (!found) {
4,112✔
1185
    if (mustlog)
9!
1186
      g_log << Logger::Warning << "Found no authoritative zone for '" << qname << "' and/or id " << zoneId << endl;
×
1187
    d_handle.d_list = false;
9✔
1188
    return;
9✔
1189
  }
9✔
1190

1191
  if (mustlog)
4,103!
1192
    g_log << Logger::Warning << "Found a zone '" << domain << "' (with id " << bbd.d_id << ") that might contain data " << endl;
×
1193

1194
  d_handle.id = bbd.d_id;
4,103✔
1195
  d_handle.qname = qname.makeRelative(domain); // strip domain name
4,103✔
1196
  d_handle.qtype = qtype;
4,103✔
1197
  d_handle.domain = std::move(domain);
4,103✔
1198

1199
  if (!bbd.current()) {
4,103✔
1200
    g_log << Logger::Warning << "Zone '" << d_handle.domain << "' (" << bbd.d_filename << ") needs reloading" << endl;
6✔
1201
    queueReloadAndStore(bbd.d_id);
6✔
1202
    if (!safeGetBBDomainInfo(d_handle.domain, &bbd))
6!
1203
      throw DBException("Zone '" + bbd.d_name.toLogString() + "' (" + bbd.d_filename + ") gone after reload"); // if we don't throw here, we crash for some reason
×
1204
  }
6✔
1205

1206
  if (!bbd.d_loaded) {
4,103✔
1207
    d_handle.reset();
216✔
1208
    throw DBException("Zone for '" + d_handle.domain.toLogString() + "' in '" + bbd.d_filename + "' not loaded (file missing, corrupt or primary dead)"); // fsck
216✔
1209
  }
216✔
1210

1211
  d_handle.d_records = bbd.d_records.get();
3,887✔
1212

1213
  if (d_handle.d_records->empty())
3,887!
1214
    DLOG(g_log << "Query with no results" << endl);
×
1215

1216
  d_handle.mustlog = mustlog;
3,887✔
1217

1218
  const auto& hashedidx = boost::multi_index::get<UnorderedNameTag>(*d_handle.d_records);
3,887✔
1219
  auto range = hashedidx.equal_range(d_handle.qname);
3,887✔
1220

1221
  d_handle.d_list = false;
3,887✔
1222
  d_handle.d_iter = range.first;
3,887✔
1223
  d_handle.d_end_iter = range.second;
3,887✔
1224
}
3,887✔
1225

1226
Bind2Backend::handle::handle()
1227
{
1,810✔
1228
  mustlog = false;
1,810✔
1229
}
1,810✔
1230

1231
bool Bind2Backend::get(DNSResourceRecord& r)
1232
{
197,869✔
1233
  if (!d_handle.d_records) {
197,869✔
1234
    if (d_handle.mustlog)
9!
1235
      g_log << Logger::Warning << "There were no answers" << endl;
×
1236
    return false;
9✔
1237
  }
9✔
1238

1239
  if (!d_handle.get(r)) {
197,860✔
1240
    if (d_handle.mustlog)
4,218!
1241
      g_log << Logger::Warning << "End of answers" << endl;
×
1242

1243
    d_handle.reset();
4,218✔
1244

1245
    return false;
4,218✔
1246
  }
4,218✔
1247
  if (d_handle.mustlog)
193,642!
1248
    g_log << Logger::Warning << "Returning: '" << r.qtype.toString() << "' of '" << r.qname << "', content: '" << r.content << "'" << endl;
×
1249
  return true;
193,642✔
1250
}
197,860✔
1251

1252
bool Bind2Backend::handle::get(DNSResourceRecord& r)
1253
{
197,860✔
1254
  if (d_list)
197,860✔
1255
    return get_list(r);
188,900✔
1256
  else
8,960✔
1257
    return get_normal(r);
8,960✔
1258
}
197,860✔
1259

1260
void Bind2Backend::handle::reset()
1261
{
8,877✔
1262
  d_records.reset();
8,877✔
1263
  qname.clear();
8,877✔
1264
  mustlog = false;
8,877✔
1265
}
8,877✔
1266

1267
//#define DLOG(x) x
1268
bool Bind2Backend::handle::get_normal(DNSResourceRecord& r)
1269
{
8,960✔
1270
  DLOG(g_log << "Bind2Backend get() was called for " << qtype.toString() << " record for '" << qname << "' - " << d_records->size() << " available in total!" << endl);
8,960✔
1271

1272
  if (d_iter == d_end_iter) {
8,960✔
1273
    return false;
3,887✔
1274
  }
3,887✔
1275

1276
  while (d_iter != d_end_iter && !(qtype.getCode() == QType::ANY || (d_iter)->qtype == qtype.getCode())) {
7,806!
1277
    DLOG(g_log << Logger::Warning << "Skipped " << qname << "/" << QType(d_iter->qtype).toString() << ": '" << d_iter->content << "'" << endl);
2,733✔
1278
    d_iter++;
2,733✔
1279
  }
2,733✔
1280
  if (d_iter == d_end_iter) {
5,073!
1281
    return false;
×
1282
  }
×
1283
  DLOG(g_log << "Bind2Backend get() returning a rr with a " << QType(d_iter->qtype).getCode() << endl);
5,073✔
1284

1285
  const DNSName& domainName(domain);
5,073✔
1286
  r.qname = qname.empty() ? domainName : (qname + domainName);
5,073!
1287
  r.domain_id = id;
5,073✔
1288
  r.content = (d_iter)->content;
5,073✔
1289
  //  r.domain_id=(d_iter)->domain_id;
1290
  r.qtype = (d_iter)->qtype;
5,073✔
1291
  r.ttl = (d_iter)->ttl;
5,073✔
1292

1293
  //if(!d_iter->auth && r.qtype.getCode() != QType::A && r.qtype.getCode()!=QType::AAAA && r.qtype.getCode() != QType::NS)
1294
  //  cerr<<"Warning! Unauth response for qtype "<< r.qtype.toString() << " for '"<<r.qname<<"'"<<endl;
1295
  r.auth = d_iter->auth;
5,073✔
1296

1297
  d_iter++;
5,073✔
1298

1299
  return true;
5,073✔
1300
}
5,073✔
1301

1302
bool Bind2Backend::list(const ZoneName& /* target */, domainid_t domainId, bool /* include_disabled */)
1303
{
331✔
1304
  BB2DomainInfo bbd;
331✔
1305

1306
  if (!safeGetBBDomainInfo(domainId, &bbd)) {
331!
1307
    return false;
×
1308
  }
×
1309

1310
  d_handle.reset();
331✔
1311
  DLOG(g_log << "Bind2Backend constructing handle for list of " << domainId << endl);
331✔
1312

1313
  if (!bbd.d_loaded) {
331!
1314
    throw PDNSException("zone was not loaded, perhaps because of: " + bbd.d_status);
×
1315
  }
×
1316

1317
  d_handle.d_records = bbd.d_records.get(); // give it a copy, which will stay around
331✔
1318
  d_handle.d_qname_iter = d_handle.d_records->begin();
331✔
1319
  d_handle.d_qname_end = d_handle.d_records->end(); // iter now points to a vector of pointers to vector<BBResourceRecords>
331✔
1320

1321
  d_handle.id = domainId;
331✔
1322
  d_handle.domain = bbd.d_name;
331✔
1323
  d_handle.d_list = true;
331✔
1324
  return true;
331✔
1325
}
331✔
1326

1327
bool Bind2Backend::handle::get_list(DNSResourceRecord& r)
1328
{
188,900✔
1329
  if (d_qname_iter != d_qname_end) {
188,900✔
1330
    const DNSName& domainName(domain);
188,569✔
1331
    r.qname = d_qname_iter->qname.empty() ? domainName : (d_qname_iter->qname + domainName);
188,569!
1332
    r.domain_id = id;
188,569✔
1333
    r.content = (d_qname_iter)->content;
188,569✔
1334
    r.qtype = (d_qname_iter)->qtype;
188,569✔
1335
    r.ttl = (d_qname_iter)->ttl;
188,569✔
1336
    r.auth = d_qname_iter->auth;
188,569✔
1337
    d_qname_iter++;
188,569✔
1338
    return true;
188,569✔
1339
  }
188,569✔
1340
  return false;
331✔
1341
}
188,900✔
1342

1343
bool Bind2Backend::autoPrimariesList(std::vector<AutoPrimary>& primaries)
1344
{
×
1345
  if (getArg("autoprimary-config").empty())
×
1346
    return false;
×
1347

1348
  ifstream c_if(getArg("autoprimaries"), std::ios::in);
×
1349
  if (!c_if) {
×
1350
    g_log << Logger::Error << "Unable to open autoprimaries file for read: " << stringerror() << endl;
×
1351
    return false;
×
1352
  }
×
1353

1354
  string line, sip, saccount;
×
1355
  while (getline(c_if, line)) {
×
1356
    std::istringstream ii(line);
×
1357
    ii >> sip;
×
1358
    if (!sip.empty()) {
×
1359
      ii >> saccount;
×
1360
      primaries.emplace_back(sip, "", saccount);
×
1361
    }
×
1362
  }
×
1363

1364
  c_if.close();
×
1365
  return true;
×
1366
}
×
1367

1368
bool Bind2Backend::autoPrimaryBackend(const string& ipAddress, const ZoneName& /* domain */, const vector<DNSResourceRecord>& /* nsset */, string* /* nameserver */, string* account, DNSBackend** backend)
1369
{
×
1370
  // Check whether we have a configfile available.
1371
  if (getArg("autoprimary-config").empty())
×
1372
    return false;
×
1373

1374
  ifstream c_if(getArg("autoprimaries").c_str(), std::ios::in); // this was nocreate?
×
1375
  if (!c_if) {
×
1376
    g_log << Logger::Error << "Unable to open autoprimaries file for read: " << stringerror() << endl;
×
1377
    return false;
×
1378
  }
×
1379

1380
  // Format:
1381
  // <ip> <accountname>
1382
  string line, sip, saccount;
×
1383
  while (getline(c_if, line)) {
×
1384
    std::istringstream ii(line);
×
1385
    ii >> sip;
×
1386
    if (sip == ipAddress) {
×
1387
      ii >> saccount;
×
1388
      break;
×
1389
    }
×
1390
  }
×
1391
  c_if.close();
×
1392

1393
  if (sip != ipAddress) { // ip not found in authorization list - reject
×
1394
    return false;
×
1395
  }
×
1396

1397
  // ip authorized as autoprimary - accept
1398
  *backend = this;
×
1399
  if (saccount.length() > 0)
×
1400
    *account = saccount.c_str();
×
1401

1402
  return true;
×
1403
}
×
1404

1405
BB2DomainInfo Bind2Backend::createDomainEntry(const ZoneName& domain, const string& filename)
1406
{
6✔
1407
  domainid_t newid = 1;
6✔
1408
  { // Find a free zone id nr.
6✔
1409
    auto state = s_state.read_lock();
6✔
1410
    if (!state->empty()) {
6!
1411
      // older (1.53) versions of boost have an expression for s_state.rbegin()
1412
      // that is ambiguous in C++17. So construct it explicitly
1413
      newid = boost::make_reverse_iterator(state->end())->d_id + 1;
6✔
1414
    }
6✔
1415
  }
6✔
1416

1417
  BB2DomainInfo bbd;
6✔
1418
  bbd.d_kind = DomainInfo::Native;
6✔
1419
  bbd.d_id = newid;
6✔
1420
  bbd.d_records = std::make_shared<recordstorage_t>();
6✔
1421
  bbd.d_name = domain;
6✔
1422
  bbd.setCheckInterval(getArgAsNum("check-interval"));
6✔
1423
  bbd.d_filename = filename;
6✔
1424

1425
  return bbd;
6✔
1426
}
6✔
1427

1428
bool Bind2Backend::createSecondaryDomain(const string& ipAddress, const ZoneName& domain, const string& /* nameserver */, const string& account)
1429
{
×
1430
  string filename = getArg("autoprimary-destdir") + '/' + domain.toStringNoDot();
×
1431

1432
  g_log << Logger::Warning << d_logprefix
×
1433
        << " Writing bind config zone statement for superslave zone '" << domain
×
1434
        << "' from autoprimary " << ipAddress << endl;
×
1435

1436
  {
×
1437
    std::lock_guard<std::mutex> l2(s_autosecondary_config_lock);
×
1438

1439
    ofstream c_of(getArg("autoprimary-config").c_str(), std::ios::app);
×
1440
    if (!c_of) {
×
1441
      g_log << Logger::Error << "Unable to open autoprimary configfile for append: " << stringerror() << endl;
×
1442
      throw DBException("Unable to open autoprimary configfile for append: " + stringerror());
×
1443
    }
×
1444

1445
    c_of << endl;
×
1446
    c_of << "# AutoSecondary zone '" << domain.toString() << "' (added: " << nowTime() << ") (account: " << account << ')' << endl;
×
1447
    c_of << "zone \"" << domain.toStringNoDot() << "\" {" << endl;
×
1448
    c_of << "\ttype secondary;" << endl;
×
1449
    c_of << "\tfile \"" << filename << "\";" << endl;
×
1450
    c_of << "\tprimaries { " << ipAddress << "; };" << endl;
×
1451
    c_of << "};" << endl;
×
1452
    c_of.close();
×
1453
  }
×
1454

1455
  BB2DomainInfo bbd = createDomainEntry(domain, filename);
×
1456
  bbd.d_kind = DomainInfo::Secondary;
×
1457
  bbd.d_primaries.emplace_back(ComboAddress(ipAddress, 53));
×
1458
  bbd.setCtime();
×
1459
  safePutBBDomainInfo(bbd);
×
1460

1461
  return true;
×
1462
}
×
1463

1464
bool Bind2Backend::searchRecords(const string& pattern, size_t maxResults, vector<DNSResourceRecord>& result)
UNCOV
1465
{
×
UNCOV
1466
  SimpleMatch sm(pattern, true);
×
UNCOV
1467
  static bool mustlog = ::arg().mustDo("query-logging");
×
UNCOV
1468
  if (mustlog)
×
1469
    g_log << Logger::Warning << "Search for pattern '" << pattern << "'" << endl;
×
1470

UNCOV
1471
  {
×
UNCOV
1472
    auto state = s_state.read_lock();
×
1473

UNCOV
1474
    for (const auto& i : *state) {
×
1475
      BB2DomainInfo h;
×
1476
      if (!safeGetBBDomainInfo(i.d_id, &h)) {
×
1477
        continue;
×
1478
      }
×
1479

1480
      if (!h.d_loaded) {
×
1481
        continue;
×
1482
      }
×
1483

1484
      shared_ptr<const recordstorage_t> rhandle = h.d_records.get();
×
1485

1486
      for (recordstorage_t::const_iterator ri = rhandle->begin(); result.size() < maxResults && ri != rhandle->end(); ri++) {
×
1487
        const DNSName& domainName(i.d_name);
×
1488
        DNSName name = ri->qname.empty() ? domainName : (ri->qname + domainName);
×
1489
        if (sm.match(name) || sm.match(ri->content)) {
×
1490
          DNSResourceRecord r;
×
1491
          r.qname = std::move(name);
×
1492
          r.domain_id = i.d_id;
×
1493
          r.content = ri->content;
×
1494
          r.qtype = ri->qtype;
×
1495
          r.ttl = ri->ttl;
×
1496
          r.auth = ri->auth;
×
1497
          result.push_back(std::move(r));
×
1498
        }
×
1499
      }
×
1500
    }
×
UNCOV
1501
  }
×
1502

UNCOV
1503
  return true;
×
UNCOV
1504
}
×
1505

1506
class Bind2Factory : public BackendFactory
1507
{
1508
public:
1509
  Bind2Factory() :
1510
    BackendFactory("bind") {}
5,118✔
1511

1512
  void declareArguments(const string& suffix = "") override
1513
  {
379✔
1514
    declare(suffix, "ignore-broken-records", "Ignore records that are out-of-bound for the zone.", "no");
379✔
1515
    declare(suffix, "config", "Location of named.conf", "");
379✔
1516
    declare(suffix, "check-interval", "Interval for zonefile changes", "0");
379✔
1517
    declare(suffix, "autoprimary-config", "Location of (part of) named.conf where pdns can write zone-statements to", "");
379✔
1518
    declare(suffix, "autoprimaries", "List of IP-addresses of autoprimaries", "");
379✔
1519
    declare(suffix, "autoprimary-destdir", "Destination directory for newly added secondary zones", ::arg()["config-dir"]);
379✔
1520
    declare(suffix, "dnssec-db", "Filename to store & access our DNSSEC metadatabase, empty for none", "");
379✔
1521
    declare(suffix, "dnssec-db-journal-mode", "SQLite3 journal mode", "WAL");
379✔
1522
    declare(suffix, "hybrid", "Store DNSSEC metadata in other backend", "no");
379✔
1523
  }
379✔
1524

1525
  DNSBackend* make(const string& suffix = "") override
1526
  {
1,070✔
1527
    assertEmptySuffix(suffix);
1,070✔
1528
    return new Bind2Backend(suffix);
1,070✔
1529
  }
1,070✔
1530

1531
  DNSBackend* makeMetadataOnly(const string& suffix = "") override
1532
  {
734✔
1533
    assertEmptySuffix(suffix);
734✔
1534
    return new Bind2Backend(suffix, false);
734✔
1535
  }
734✔
1536

1537
private:
1538
  void assertEmptySuffix(const string& suffix)
1539
  {
1,804✔
1540
    if (!suffix.empty())
1,804!
1541
      throw PDNSException("launch= suffixes are not supported on the bindbackend");
×
1542
  }
1,804✔
1543
};
1544

1545
//! Magic class that is activated when the dynamic library is loaded
1546
class Bind2Loader
1547
{
1548
public:
1549
  Bind2Loader()
1550
  {
5,118✔
1551
    BackendMakers().report(std::make_unique<Bind2Factory>());
5,118✔
1552
    g_log << Logger::Info << "[bind2backend] This is the bind backend version " << VERSION
5,118✔
1553
#ifndef REPRODUCIBLE
5,118✔
1554
          << " (" __DATE__ " " __TIME__ ")"
5,118✔
1555
#endif
5,118✔
1556
#ifdef HAVE_SQLITE3
5,118✔
1557
          << " (with bind-dnssec-db support)"
5,118✔
1558
#endif
5,118✔
1559
          << " reporting" << endl;
5,118✔
1560
  }
5,118✔
1561
};
1562
static Bind2Loader bind2loader;
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