4 #include "dnsseckeeper.hh"
5 #include "dnssecinfra.hh"
10 #include <boost/program_options.hpp>
11 #include <boost/assign/std/vector.hpp>
12 #include <boost/assign/list_of.hpp>
13 #include "dnsbackend.hh"
14 #include "ueberbackend.hh"
15 #include "arguments.hh"
16 #include "packetcache.hh"
17 #include "zoneparser-tng.hh"
18 #include "signingpipe.hh"
19 #include "dns_random.hh"
25 #include "ssqlite3.hh"
26 #include "bind-dnssec.schema.sqlite3.sql.h"
32 namespace po
= boost::program_options
;
33 po::variables_map g_vm
;
35 string s_programname
="pdns";
47 string
humanTime(time_t t
)
52 strftime(ret
, sizeof(ret
)-1, "%c", &tm
); // %h:%M %Y-%m-%d
56 static void algorithm2name(uint8_t algo
, string
&name
) {
59 name
= "Reserved"; return;
61 name
= "RSAMD5"; return;
69 name
= "RSASHA1"; return;
71 name
= "DSA-NSEC3-SHA1"; return;
73 name
= "RSASHA1-NSEC3-SHA1"; return;
75 name
= "RSASHA256"; return;
77 name
= "Reserved"; return;
79 name
= "RSASHA512"; return;
81 name
= "Reserved"; return;
83 name
= "ECC-GOST"; return;
85 name
= "ECDSAP256SHA256"; return;
87 name
= "ECDSAP384SHA384"; return;
89 name
= "ED25519SHA512"; return;
91 name
= "INDIRECT"; return;
93 name
= "PRIVATEDNS"; return;
95 name
= "PRIVATEOID"; return;
97 name
= "Unallocated/Reserved"; return;
101 static int shorthand2algorithm(const string
&algorithm
)
103 if (!algorithm
.compare("rsamd5")) return 1;
104 if (!algorithm
.compare("dh")) return 2;
105 if (!algorithm
.compare("dsa")) return 3;
106 if (!algorithm
.compare("ecc")) return 4;
107 if (!algorithm
.compare("rsasha1")) return 5;
108 if (!algorithm
.compare("rsasha256")) return 8;
109 if (!algorithm
.compare("rsasha512")) return 10;
110 if (!algorithm
.compare("gost")) return 12;
111 if (!algorithm
.compare("ecdsa256")) return 13;
112 if (!algorithm
.compare("ecdsa384")) return 14;
113 if (!algorithm
.compare("experimental-ed25519")) return 250;
117 void loadMainConfig(const std::string
& configdir
)
119 ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=configdir
;
120 ::arg().set("default-ttl","Seconds a result is valid if not set otherwise")="3600";
121 ::arg().set("launch","Which backends to launch");
122 ::arg().set("dnssec","if we should do dnssec")="true";
123 ::arg().set("config-name","Name of this virtual configuration - will rename the binary image")=g_vm
["config-name"].as
<string
>();
124 ::arg().setCmd("help","Provide a helpful message");
125 //::arg().laxParse(argc,argv);
127 if(::arg().mustDo("help")) {
128 cout
<<"syntax:"<<endl
<<endl
;
129 cout
<<::arg().helpstring(::arg()["help"])<<endl
;
133 if(::arg()["config-name"]!="")
134 s_programname
+="-"+::arg()["config-name"];
136 string configname
=::arg()["config-dir"]+"/"+s_programname
+".conf";
137 cleanSlashes(configname
);
139 ::arg().set("default-ksk-algorithms","Default KSK algorithms")="";
140 ::arg().set("default-ksk-size","Default KSK size (0 means default)")="0";
141 ::arg().set("default-zsk-algorithms","Default ZSK algorithms")="rsasha256";
142 ::arg().set("default-zsk-size","Default ZSK size (0 means default)")="0";
143 ::arg().set("default-soa-edit","Default SOA-EDIT value")="";
144 ::arg().set("default-soa-edit-signed","Default SOA-EDIT value for signed zones")="";
145 ::arg().set("max-ent-entries", "Maximum number of empty non-terminals in a zone")="100000";
146 ::arg().set("module-dir","Default directory for modules")=PKGLIBDIR
;
147 ::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom";
148 ::arg().setSwitch("query-logging","Hint backends that queries should be logged")="no";
149 ::arg().set("loglevel","Amount of logging. Higher is more.")="0";
150 ::arg().setSwitch("direct-dnskey","Fetch DNSKEY RRs from backend during DNSKEY synthesis")="no";
151 ::arg().set("max-nsec3-iterations","Limit the number of NSEC3 hash iterations")="500"; // RFC5155 10.3
152 ::arg().set("max-signature-cache-entries", "Maximum number of signatures cache entries")="";
153 ::arg().laxFile(configname
.c_str());
155 L
.toConsole(Logger::Error
); // so we print any errors
156 BackendMakers().launch(::arg()["launch"]); // vrooooom!
157 L
.toConsole((Logger::Urgency
)(::arg().asNum("loglevel")));
158 ::arg().laxFile(configname
.c_str());
159 //cerr<<"Backend: "<<::arg()["launch"]<<", '" << ::arg()["gmysql-dbname"] <<"'" <<endl;
161 S
.declare("qsize-q","Number of questions waiting for database attention");
163 S
.declare("deferred-cache-inserts","Amount of cache inserts that were deferred because of maintenance");
164 S
.declare("deferred-cache-lookup","Amount of cache lookups that were deferred because of maintenance");
166 S
.declare("query-cache-hit","Number of hits on the query cache");
167 S
.declare("query-cache-miss","Number of misses on the query cache");
168 ::arg().set("max-cache-entries", "Maximum number of cache entries")="1000000";
169 ::arg().set("recursor","If recursion is desired, IP address of a recursing nameserver")="no";
170 ::arg().set("recursive-cache-ttl","Seconds to store packets for recursive queries in the PacketCache")="10";
171 ::arg().set("cache-ttl","Seconds to store packets in the PacketCache")="20";
172 ::arg().set("negquery-cache-ttl","Seconds to store negative query results in the QueryCache")="60";
173 ::arg().set("query-cache-ttl","Seconds to store query results in the QueryCache")="20";
174 ::arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server";
175 ::arg().set("default-soa-mail","mail address to insert in the SOA record if none set in the backend")="";
176 ::arg().set("soa-refresh-default","Default SOA refresh")="10800";
177 ::arg().set("soa-retry-default","Default SOA retry")="3600";
178 ::arg().set("soa-expire-default","Default SOA expire")="604800";
179 ::arg().set("soa-minimum-ttl","Default SOA minimum ttl")="3600";
184 // irritatingly enough, rectifyZone needs its own ueberbackend and can't therefore benefit from transactions outside its scope
185 // I think this has to do with interlocking transactions between B and DK, but unsure.
186 bool rectifyZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
188 if(dk
.isPresigned(zone
)){
189 cerr
<<"Rectify presigned zone '"<<zone
.toString()<<"' is not allowed/necessary."<<endl
;
193 UeberBackend
B("default");
194 bool doTransaction
=true; // but see above
197 if(!B
.getSOAUncached(zone
, sd
)) {
198 cerr
<<"No SOA known for '"<<zone
.toString()<<"', is such a zone in the database?"<<endl
;
201 sd
.db
->list(zone
, sd
.domain_id
);
203 DNSResourceRecord rr
;
204 set
<DNSName
> qnames
, nsset
, dsnames
, insnonterm
, delnonterm
;
205 map
<DNSName
,bool> nonterm
;
208 while(sd
.db
->get(rr
)) {
209 if (rr
.qtype
.getCode())
211 qnames
.insert(rr
.qname
);
212 if(rr
.qtype
.getCode() == QType::NS
&& rr
.qname
!= zone
)
213 nsset
.insert(rr
.qname
);
214 if(rr
.qtype
.getCode() == QType::DS
)
215 dsnames
.insert(rr
.qname
);
219 delnonterm
.insert(rr
.qname
);
222 NSEC3PARAMRecordContent ns3pr
;
224 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
225 bool isOptOut
=(haveNSEC3
&& ns3pr
.d_flags
);
226 if(sd
.db
->doesDNSSEC())
229 cerr
<<"Adding NSEC ordering information "<<endl
;
232 cerr
<<"Adding NSEC3 hashed ordering information for '"<<zone
.toString()<<"'"<<endl
;
234 cerr
<<"Adding NSEC3 opt-out hashed ordering information for '"<<zone
.toString()<<"'"<<endl
;
236 cerr
<<"Erasing NSEC3 ordering since we are narrow, only setting 'auth' fields"<<endl
;
239 cerr
<<"Non DNSSEC zone, only adding empty non-terminals"<<endl
;
242 sd
.db
->startTransaction(zone
, -1);
245 uint32_t maxent
= ::arg().asNum("max-ent-entries");
248 for (const auto& qname
: qnames
)
256 if(nsset
.count(shorter
)) {
260 } while(shorter
.chopOff());
263 if(haveNSEC3
) // NSEC3
265 if(!narrow
&& (realrr
|| !isOptOut
|| nonterm
.find(qname
)->second
))
266 ordername
=DNSName(toBase32Hex(hashQNameWithSalt(ns3pr
, qname
))) + zone
;
270 else if (realrr
) // NSEC
274 cerr
<<"'"<<qname
.toString()<<"' -> '"<< ordername
.toString() <<"'"<<endl
;
275 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, zone
, qname
, ordername
, auth
);
279 if (dsnames
.count(qname
))
280 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, zone
, qname
, ordername
, true, QType::DS
);
281 if (!auth
|| nsset
.count(qname
)) {
284 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, zone
, qname
, ordername
, false, QType::NS
);
285 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, zone
, qname
, ordername
, false, QType::A
);
286 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, zone
, qname
, ordername
, false, QType::AAAA
);
292 while(shorter
!=zone
&& shorter
.chopOff())
294 if(!qnames
.count(shorter
))
298 cerr
<<"Zone '"<<zone
.toString()<<"' has too many empty non terminals."<<endl
;
305 if (!delnonterm
.count(shorter
) && !nonterm
.count(shorter
))
306 insnonterm
.insert(shorter
);
308 delnonterm
.erase(shorter
);
310 if (!nonterm
.count(shorter
)) {
311 nonterm
.insert(pair
<DNSName
, bool>(shorter
, auth
));
314 nonterm
[shorter
]=true;
323 //cerr<<"Total: "<<nonterm.size()<<" Insert: "<<insnonterm.size()<<" Delete: "<<delnonterm.size()<<endl;
324 if(!insnonterm
.empty() || !delnonterm
.empty() || !doent
)
326 sd
.db
->updateEmptyNonTerminals(sd
.domain_id
, zone
, insnonterm
, delnonterm
, !doent
);
332 for(const auto& nt
: nonterm
){
333 qnames
.insert(nt
.first
);
340 sd
.db
->commitTransaction();
345 void dbBench(const std::string
& fname
)
347 ::arg().set("query-cache-ttl")="0";
348 ::arg().set("negquery-cache-ttl")="0";
349 UeberBackend
B("default");
351 vector
<string
> domains
;
353 ifstream
ifs(fname
.c_str());
355 cerr
<<"Could not open '"<<fname
<<"' for reading domain names to query"<<endl
;
358 while(getline(ifs
,line
)) {
360 domains
.push_back(line
);
364 domains
.push_back("powerdns.com");
367 DNSResourceRecord rr
;
370 unsigned int hits
=0, misses
=0;
371 for(; n
< 10000; ++n
) {
372 DNSName
domain(domains
[random() % domains
.size()]);
373 B
.lookup(QType(QType::NS
), domain
);
377 B
.lookup(QType(QType::A
), DNSName(std::to_string(random()))+domain
);
383 cout
<<0.001*dt
.udiff()/n
<<" millisecond/lookup"<<endl
;
384 cout
<<"Retrieved "<<hits
<<" records, did "<<misses
<<" queries which should have no match"<<endl
;
385 cout
<<"Packet cache reports: "<<S
.read("query-cache-hit")<<" hits (should be 0) and "<<S
.read("query-cache-miss") <<" misses"<<endl
;
388 void rectifyAllZones(DNSSECKeeper
&dk
)
390 UeberBackend
B("default");
391 vector
<DomainInfo
> domainInfo
;
393 B
.getAllDomains(&domainInfo
);
394 for(DomainInfo di
: domainInfo
) {
395 cerr
<<"Rectifying "<<di
.zone
.toString()<<": ";
396 rectifyZone(dk
, di
.zone
);
398 cout
<<"Rectified "<<domainInfo
.size()<<" zones."<<endl
;
401 int checkZone(DNSSECKeeper
&dk
, UeberBackend
&B
, const DNSName
& zone
)
404 if(!B
.getSOAUncached(zone
, sd
)) {
405 cout
<<"[error] No SOA record present, or active, in zone '"<<zone
.toString()<<"'"<<endl
;
406 cout
<<"Checked 0 records of '"<<zone
.toString()<<"', 1 errors, 0 warnings."<<endl
;
410 NSEC3PARAMRecordContent ns3pr
;
412 bool haveNSEC3
= dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
413 bool isOptOut
=(haveNSEC3
&& ns3pr
.d_flags
);
415 bool isSecure
=dk
.isSecuredZone(zone
);
416 bool presigned
=dk
.isPresigned(zone
);
418 DNSResourceRecord rr
;
419 uint64_t numrecords
=0, numerrors
=0, numwarnings
=0;
421 if (haveNSEC3
&& isSecure
&& zone
.wirelength() > 222) {
423 cerr
<<"[Error] zone '" << zone
.toStringNoDot() << "' has NSEC3 semantics but is too long to have the hash prepended. Zone name is " << zone
.wirelength() << " bytes long, whereas the maximum is 222 bytes." << endl
;
426 // Check for delegation in parent zone
427 DNSName
parent(zone
);
428 while(parent
.chopOff()) {
430 if(B
.getSOAUncached(parent
, sd_p
)) {
432 DNSResourceRecord rr
;
433 B
.lookup(QType(QType::ANY
), zone
, NULL
, sd_p
.domain_id
);
435 ns
|= (rr
.qtype
== QType::NS
);
437 cerr
<<"[Error] No delegation for zone '"<<zone
.toString()<<"' in parent '"<<parent
.toString()<<"'"<<endl
;
445 bool hasNsAtApex
= false;
446 set
<DNSName
> tlsas
, cnames
, noncnames
, glue
, checkglue
;
448 map
<string
, unsigned int> ttl
;
450 ostringstream content
;
451 pair
<map
<string
, unsigned int>::iterator
,bool> ret
;
453 sd
.db
->list(zone
, sd
.domain_id
, true);
455 while(sd
.db
->get(rr
)) {
456 if(!rr
.qtype
.getCode())
461 if(rr
.qtype
.getCode() == QType::TLSA
)
462 tlsas
.insert(rr
.qname
);
463 if(rr
.qtype
.getCode() == QType::SOA
) {
465 stringtok(parts
, rr
.content
);
469 for(int pleft
=parts
.size(); pleft
< 7; ++pleft
) {
475 if(rr
.qtype
.getCode() == QType::TXT
&& !rr
.content
.empty() && rr
.content
[0]!='"')
476 rr
.content
= "\""+rr
.content
+"\"";
479 shared_ptr
<DNSRecordContent
> drc(DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, rr
.content
));
480 string tmp
=drc
->serialize(rr
.qname
);
481 tmp
= drc
->getZoneRepresentation(true);
482 if (rr
.qtype
.getCode() != QType::AAAA
) {
483 if (!pdns_iequals(tmp
, rr
.content
)) {
484 cout
<<"[Warning] Parsed and original record content are not equal: "<<rr
.qname
.toString()<<" IN " <<rr
.qtype
.getName()<< " '" << rr
.content
<<"' (Content parsed as '"<<tmp
<<"')"<<endl
;
488 struct in6_addr tmpbuf
;
489 if (inet_pton(AF_INET6
, rr
.content
.c_str(), &tmpbuf
) != 1 || rr
.content
.find('.') != string::npos
) {
490 cout
<<"[Warning] Following record is not a valid IPv6 address: "<<rr
.qname
.toString()<<" IN " <<rr
.qtype
.getName()<< " '" << rr
.content
<<"'"<<endl
;
495 catch(std::exception
& e
)
497 cout
<<"[Error] Following record had a problem: "<<rr
.qname
.toString()<<" IN " <<rr
.qtype
.getName()<< " " << rr
.content
<<endl
;
498 cout
<<"[Error] Error was: "<<e
.what()<<endl
;
503 if(!rr
.qname
.isPartOf(zone
)) {
504 cout
<<"[Warning] Record '"<<rr
.qname
.toString()<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
.toString()<<"' is out-of-zone."<<endl
;
510 content
<<rr
.qname
.toString()<<" "<<rr
.qtype
.getName()<<" "<<rr
.content
;
511 if (records
.count(toLower(content
.str()))) {
512 cout
<<"[Error] Duplicate record found in rrset: '"<<rr
.qname
.toString()<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"'"<<endl
;
516 records
.insert(toLower(content
.str()));
519 content
<<rr
.qname
.toString()<<" "<<rr
.qtype
.getName();
520 if (rr
.qtype
.getCode() == QType::RRSIG
) {
521 RRSIGRecordContent
rrc(rr
.content
);
522 content
<<" ("<<DNSRecordContent::NumberToType(rrc
.d_type
)<<")";
524 ret
= ttl
.insert(pair
<string
, unsigned int>(toLower(content
.str()), rr
.ttl
));
525 if (ret
.second
== false && ret
.first
->second
!= rr
.ttl
) {
526 cout
<<"[Error] TTL mismatch in rrset: '"<<rr
.qname
.toString()<<" IN " <<rr
.qtype
.getName()<<" "<<rr
.content
<<"' ("<<ret
.first
->second
<<" != "<<rr
.ttl
<<")"<<endl
;
531 if (isSecure
&& isOptOut
&& (rr
.qname
.countLabels() && rr
.qname
.getRawLabels()[0] == "*")) {
532 cout
<<"[Warning] wildcard record '"<<rr
.qname
.toString()<<" IN " <<rr
.qtype
.getName()<<" "<<rr
.content
<<"' is insecure"<<endl
;
533 cout
<<"[Info] Wildcard records in opt-out zones are insecure. Disable the opt-out flag for this zone to avoid this warning. Command: pdnsutil set-nsec3 "<<zone
.toString()<<endl
;
538 if (rr
.qtype
.getCode() == QType::NS
) {
540 } else if (rr
.qtype
.getCode() == QType::DS
) {
541 cout
<<"[Warning] DS at apex in zone '"<<zone
.toString()<<"', should not be here."<<endl
;
545 if (rr
.qtype
.getCode() == QType::SOA
) {
546 cout
<<"[Error] SOA record not at apex '"<<rr
.qname
.toString()<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
.toString()<<"'"<<endl
;
549 } else if (rr
.qtype
.getCode() == QType::DNSKEY
) {
550 cout
<<"[Warning] DNSKEY record not at apex '"<<rr
.qname
.toString()<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
.toString()<<"', should not be here."<<endl
;
552 } else if (rr
.qtype
.getCode() == QType::NS
&& DNSName(rr
.content
).isPartOf(rr
.qname
)) {
553 checkglue
.insert(DNSName(toLower(rr
.content
)));
554 } else if (rr
.qtype
.getCode() == QType::A
|| rr
.qtype
.getCode() == QType::AAAA
) {
555 glue
.insert(rr
.qname
);
559 if (rr
.qtype
.getCode() == QType::CNAME
) {
560 if (!cnames
.count(rr
.qname
))
561 cnames
.insert(rr
.qname
);
563 cout
<<"[Error] Duplicate CNAME found at '"<<rr
.qname
.toString()<<"'"<<endl
;
568 if (rr
.qtype
.getCode() == QType::RRSIG
) {
570 cout
<<"[Error] RRSIG found at '"<<rr
.qname
.toString()<<"' in non-presigned zone. These do not belong in the database."<<endl
;
575 noncnames
.insert(rr
.qname
);
578 if(rr
.qtype
.getCode() == QType::NSEC
|| rr
.qtype
.getCode() == QType::NSEC3
)
580 cout
<<"[Error] NSEC or NSEC3 found at '"<<rr
.qname
.toString()<<"'. These do not belong in the database."<<endl
;
585 if(!presigned
&& rr
.qtype
.getCode() == QType::DNSKEY
)
587 if(::arg().mustDo("direct-dnskey"))
589 if(rr
.ttl
!= sd
.default_ttl
)
591 cout
<<"[Warning] DNSKEY TTL of "<<rr
.ttl
<<" at '"<<rr
.qname
.toString()<<"' differs from SOA minimum of "<<sd
.default_ttl
<<endl
;
597 cout
<<"[Warning] DNSKEY at '"<<rr
.qname
.toString()<<"' in non-presigned zone will mostly be ignored and can cause problems."<<endl
;
602 // if (rr.qname[rr.qname.size()-1] == '.') {
603 // cout<<"[Error] Record '"<<rr.qname.toString()<<"' has a trailing dot. PowerDNS will ignore this record!"<<endl;
607 if ( (rr
.qtype
.getCode() == QType::NS
|| rr
.qtype
.getCode() == QType::SRV
|| rr
.qtype
.getCode() == QType::MX
|| rr
.qtype
.getCode() == QType::CNAME
|| rr
.qtype
.getCode() == QType::DNAME
) &&
608 rr
.content
[rr
.content
.size()-1] == '.') {
609 cout
<<"[Warning] The record "<<rr
.qname
.toString()<<" with type "<<rr
.qtype
.getName()<<" has a trailing dot in the content ("<<rr
.content
<<"). Your backend might not work well with this."<<endl
;
613 if(rr
.auth
== 0 && rr
.qtype
.getCode()!=QType::NS
&& rr
.qtype
.getCode()!=QType::A
&& rr
.qtype
.getCode()!=QType::AAAA
)
615 cout
<<"[Error] Following record is auth=0, run pdnsutil rectify-zone?: "<<rr
.qname
.toString()<<" IN " <<rr
.qtype
.getName()<< " " << rr
.content
<<endl
;
620 for(auto &i
: cnames
) {
621 if (noncnames
.find(i
) != noncnames
.end()) {
622 cout
<<"[Error] CNAME "<<i
.toString()<<" found, but other records with same label exist."<<endl
;
627 for(const auto &i
: tlsas
) {
628 DNSName name
= DNSName(i
);
629 name
.trimToLabels(name
.getRawLabels().size()-2);
630 if (cnames
.find(name
) == cnames
.end() && noncnames
.find(name
) == noncnames
.end()) {
631 // No specific record for the name in the TLSA record exists, this
632 // is already worth emitting a warning. Let's see if a wildcard exist.
634 DNSName
wcname(name
);
636 wcname
.prependRawLabel("*");
637 if (cnames
.find(wcname
) != cnames
.end() || noncnames
.find(wcname
) != noncnames
.end()) {
638 cout
<<"A wildcard record exist for '"<<wcname
.toString()<<"' and a TLSA record for '"<<i
.toString()<<"'.";
640 cout
<<"No record for '"<<name
.toString()<<"' exists, but a TLSA record for '"<<i
.toString()<<"' does.";
643 cout
<<" A query for '"<<name
.toString()<<"' will yield an empty response. This is most likely a mistake, please create records for '"<<name
.toString()<<"'."<<endl
;
648 cout
<<"[Error] No NS record at zone apex in zone '"<<zone
.toString()<<"'"<<endl
;
652 for(const auto &qname
: checkglue
) {
653 if (!glue
.count(qname
)) {
654 cerr
<<"[Warning] Missing glue for '"<<qname
.toString()<<"' in zone '"<<zone
.toString()<<"'"<<endl
;
659 cout
<<"Checked "<<numrecords
<<" records of '"<<zone
.toString()<<"', "<<numerrors
<<" errors, "<<numwarnings
<<" warnings."<<endl
;
665 int checkAllZones(DNSSECKeeper
&dk
, bool exitOnError
)
667 UeberBackend
B("default");
668 vector
<DomainInfo
> domainInfo
;
670 B
.getAllDomains(&domainInfo
, true);
672 for(auto di
: domainInfo
) {
673 if (checkZone(dk
, B
, di
.zone
) > 0) {
679 cout
<<"Checked "<<domainInfo
.size()<<" zones, "<<errors
<<" had errors."<<endl
;
685 int increaseSerial(const DNSName
& zone
, DNSSECKeeper
&dk
)
687 UeberBackend
B("default");
689 if(!B
.getSOAUncached(zone
, sd
)) {
690 cout
<<"No SOA for zone '"<<zone
.toString()<<"'"<<endl
;
694 if (dk
.isPresigned(zone
)) {
695 cerr
<<"Serial increase of presigned zone '"<<zone
<<"' is not allowed."<<endl
;
700 dk
.getSoaEdit(zone
, soaEditKind
);
702 sd
.db
->lookup(QType(QType::SOA
), zone
);
703 vector
<DNSResourceRecord
> rrs
;
704 DNSResourceRecord rr
;
705 while (sd
.db
->get(rr
)) {
706 if (rr
.qtype
.getCode() == QType::SOA
)
710 if (rrs
.size() > 1) {
711 cerr
<<rrs
.size()<<" SOA records found for "<<zone
.toString()<<"!"<<endl
;
714 if (rrs
.size() < 1) {
715 cerr
<<zone
.toString()<<" not found!"<<endl
;
718 if (soaEditKind
.empty()) {
721 else if(pdns_iequals(soaEditKind
,"INCREMENT-WEEKS")) {
724 else if(pdns_iequals(soaEditKind
,"INCEPTION-INCREMENT")) {
725 uint32_t today_serial
= localtime_format_YYYYMMDDSS(time(NULL
), 1);
727 if (sd
.serial
< today_serial
) {
728 sd
.serial
= today_serial
;
735 sd
.serial
= calculateEditSOA(sd
, soaEditKind
) + 1;
737 rrs
[0].content
= serializeSOAData(sd
);
739 sd
.db
->startTransaction(zone
, -1);
741 if (! sd
.db
->replaceRRSet(sd
.domain_id
, zone
, rr
.qtype
, rrs
)) {
742 sd
.db
->abortTransaction();
743 cerr
<<"Backend did not replace SOA record. Backend might not support this operation."<<endl
;
747 if (sd
.db
->doesDNSSEC()) {
748 NSEC3PARAMRecordContent ns3pr
;
750 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
755 ordername
=DNSName(toBase32Hex(hashQNameWithSalt(ns3pr
, zone
))) + zone
;
759 cerr
<<"'"<<rrs
[0].qname
.toString()<<"' -> '"<< ordername
.toString() <<"'"<<endl
;
760 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, zone
, rrs
[0].qname
, ordername
, true);
763 sd
.db
->commitTransaction();
765 cout
<<"SOA serial for zone "<<zone
.toString()<<" set to "<<sd
.serial
<<endl
;
769 int deleteZone(const DNSName
&zone
) {
772 if (! B
.getDomainInfo(zone
, di
)) {
773 cerr
<<"Domain '"<<zone
.toString()<<"' not found!"<<endl
;
777 if(di
.backend
->deleteDomain(zone
))
780 cerr
<<"Failed to delete domain '"<<zone
.toString()<<"'"<<endl
;;
784 void listKey(DomainInfo
const &di
, DNSSECKeeper
& dk
, bool printHeader
= true) {
786 cout
<<"Zone Type Size Algorithm ID Location Keytag"<<endl
;
787 cout
<<"----------------------------------------------------------------------------------"<<endl
;
789 unsigned int spacelen
= 0;
790 for (auto const &key
: dk
.getKeys(di
.zone
)) {
791 cout
<<di
.zone
.toStringNoDot();
792 if (di
.zone
.toStringNoDot().length() > 29)
793 cout
<<endl
<<string(30, ' ');
795 cout
<<string(30 - di
.zone
.toStringNoDot().length(), ' ');
797 cout
<<(key
.second
.keyOrZone
? "KSK" : "ZSK")<<" ";
799 spacelen
= (std::to_string(key
.first
.getKey()->getBits()).length() >= 8) ? 1 : 8 - std::to_string(key
.first
.getKey()->getBits()).length();
800 if (key
.first
.getKey()->getBits() < 1) {
801 cout
<<"invalid "<<endl
;
804 cout
<<key
.first
.getKey()->getBits()<<string(spacelen
, ' ');
808 algorithm2name(key
.first
.d_algorithm
, algname
);
809 spacelen
= (algname
.length() >= 13) ? 1 : 13 - algname
.length();
810 cout
<<algname
<<string(spacelen
, ' ');
812 spacelen
= (std::to_string(key
.second
.id
).length() > 5) ? 1 : 5 - std::to_string(key
.second
.id
).length();
813 cout
<<key
.second
.id
<<string(spacelen
, ' ');
816 auto stormap
= key
.first
.getKey()->convertToISCVector();
817 string engine
, slot
, label
= "";
818 for (auto const &elem
: stormap
) {
819 //cout<<elem.first<<" "<<elem.second<<endl;
820 if (elem
.first
== "Engine")
821 engine
= elem
.second
;
822 if (elem
.first
== "Slot")
824 if (elem
.first
== "Label")
827 if (engine
.empty() || slot
.empty()){
830 spacelen
= (engine
.length()+slot
.length()+label
.length()+2 >= 12) ? 1 : 12 - engine
.length()-slot
.length()-label
.length()-2;
831 cout
<<engine
<<","<<slot
<<","<<label
<<string(spacelen
, ' ');
836 cout
<<key
.first
.getDNSKEY().getTag()<<endl
;
840 bool listKeys(const string
&zname
, DNSSECKeeper
& dk
){
841 UeberBackend
B("default");
843 if (zname
!= "all") {
845 if(!B
.getDomainInfo(DNSName(zname
), di
)) {
846 cerr
<< "Zone "<<zname
<<" not found."<<endl
;
851 vector
<DomainInfo
> domainInfo
;
852 B
.getAllDomains(&domainInfo
);
853 bool printHeader
= true;
854 for (auto const di
: domainInfo
) {
855 listKey(di
, dk
, printHeader
);
862 int listZone(const DNSName
&zone
) {
866 if (! B
.getDomainInfo(zone
, di
)) {
867 cerr
<<"Domain '"<<zone
.toString()<<"' not found!"<<endl
;
870 di
.backend
->list(zone
, di
.id
);
871 DNSResourceRecord rr
;
872 while(di
.backend
->get(rr
)) {
873 if(rr
.qtype
.getCode()) {
874 if ( (rr
.qtype
.getCode() == QType::NS
|| rr
.qtype
.getCode() == QType::SRV
|| rr
.qtype
.getCode() == QType::MX
|| rr
.qtype
.getCode() == QType::CNAME
) && !rr
.content
.empty() && rr
.content
[rr
.content
.size()-1] != '.')
875 rr
.content
.append(1, '.');
877 cout
<<rr
.qname
.toString()<<"\t"<<rr
.ttl
<<"\tIN\t"<<rr
.qtype
.getName()<<"\t"<<rr
.content
<<endl
;
883 int loadZone(DNSName zone
, const string
& fname
) {
887 if (B
.getDomainInfo(zone
, di
)) {
888 cerr
<<"Domain '"<<zone
.toString()<<"' exists already, replacing contents"<<endl
;
891 cerr
<<"Creating '"<<zone
.toString()<<"'"<<endl
;
892 B
.createDomain(zone
);
894 if(!B
.getDomainInfo(zone
, di
)) {
895 cerr
<<"Domain '"<<zone
.toString()<<"' was not created - perhaps backend ("<<::arg()["launch"]<<") does not support storing new zones."<<endl
;
899 DNSBackend
* db
= di
.backend
;
900 ZoneParserTNG
zpt(fname
, zone
);
902 DNSResourceRecord rr
;
903 if(!db
->startTransaction(zone
, di
.id
)) {
904 cerr
<<"Unable to start transaction for load of zone '"<<zone
.toString()<<"'"<<endl
;
909 if(!rr
.qname
.isPartOf(zone
) && rr
.qname
!=zone
) {
910 cerr
<<"File contains record named '"<<rr
.qname
.toString()<<"' which is not part of zone '"<<zone
.toString()<<"'"<<endl
;
915 db
->commitTransaction();
919 int createZone(const DNSName
&zone
) {
922 if (B
.getDomainInfo(zone
, di
)) {
923 cerr
<<"Domain '"<<zone
.toString()<<"' exists already"<<endl
;
926 cerr
<<"Creating '"<<zone
.toString()<<"'"<<endl
;
927 B
.createDomain(zone
);
929 if(!B
.getDomainInfo(zone
, di
)) {
930 cerr
<<"Domain '"<<zone
.toString()<<"' was not created!"<<endl
;
937 int listAllZones(const string
&type
="") {
941 if (toUpper(type
) == "MASTER")
943 else if (toUpper(type
) == "SLAVE")
945 else if (toUpper(type
) == "NATIVE")
948 cerr
<<"Syntax: pdnsutil list-all-zones [master|slave|native]"<<endl
;
953 UeberBackend
B("default");
955 vector
<DomainInfo
> domains
;
956 B
.getAllDomains(&domains
);
959 for (vector
<DomainInfo
>::const_iterator di
=domains
.begin(); di
!= domains
.end(); di
++) {
960 if (di
->kind
== kindFilter
|| kindFilter
== -1) {
961 cout
<<di
->zone
.toString()<<endl
;
966 if (kindFilter
!= -1)
967 cout
<<type
<<" zonecount:"<<count
<<endl
;
969 cout
<<"All zonecount:"<<count
<<endl
;
973 bool testAlgorithm(int algo
)
975 return DNSCryptoKeyEngine::testOne(algo
);
978 bool testAlgorithms()
980 return DNSCryptoKeyEngine::testAll();
983 void testSpeed(DNSSECKeeper
& dk
, const DNSName
& zone
, const string
& remote
, int cores
)
985 DNSResourceRecord rr
;
986 rr
.qname
=DNSName("blah")+zone
;
990 rr
.qclass
= QClass::IN
;
991 rr
.d_place
=DNSResourceRecord::ANSWER
;
993 UeberBackend
db("key-only");
995 if ( ! db
.backends
.size() )
997 throw runtime_error("No backends available for DNSSEC key storage");
1000 ChunkedSigningPipe
csp(DNSName(zone
), 1, remote
, cores
);
1002 vector
<DNSResourceRecord
> signatures
;
1004 unsigned char* octets
= (unsigned char*)&rnd
;
1008 for(unsigned int n
=0; n
< 100000; ++n
) {
1010 snprintf(tmp
, sizeof(tmp
), "%d.%d.%d.%d",
1011 octets
[0], octets
[1], octets
[2], octets
[3]);
1014 snprintf(tmp
, sizeof(tmp
), "r-%u", rnd
);
1015 rr
.qname
=DNSName(tmp
)+zone
;
1018 while(signatures
= csp
.getChunk(), !signatures
.empty())
1021 cerr
<<"Flushing the pipe, "<<csp
.d_signed
<<" signed, "<<csp
.d_queued
<<" queued, "<<csp
.d_outstanding
<<" outstanding"<< endl
;
1022 cerr
<<"Net speed: "<<csp
.d_signed
/ (dt
.udiffNoReset()/1000000.0) << " sigs/s"<<endl
;
1023 while(signatures
= csp
.getChunk(true), !signatures
.empty())
1025 cerr
<<"Done, "<<csp
.d_signed
<<" signed, "<<csp
.d_queued
<<" queued, "<<csp
.d_outstanding
<<" outstanding"<< endl
;
1026 cerr
<<"Net speed: "<<csp
.d_signed
/ (dt
.udiff()/1000000.0) << " sigs/s"<<endl
;
1029 void verifyCrypto(const string
& zone
)
1031 ZoneParserTNG
zpt(zone
);
1032 DNSResourceRecord rr
;
1033 DNSKEYRecordContent drc
;
1034 RRSIGRecordContent rrc
;
1035 DSRecordContent dsrc
;
1036 vector
<shared_ptr
<DNSRecordContent
> > toSign
;
1037 DNSName qname
, apex
;
1038 dsrc
.d_digesttype
=0;
1039 while(zpt
.get(rr
)) {
1040 if(rr
.qtype
.getCode() == QType::DNSKEY
) {
1041 cerr
<<"got DNSKEY!"<<endl
;
1043 drc
= *dynamic_cast<DNSKEYRecordContent
*>(DNSRecordContent::mastermake(QType::DNSKEY
, 1, rr
.content
));
1045 else if(rr
.qtype
.getCode() == QType::RRSIG
) {
1046 cerr
<<"got RRSIG"<<endl
;
1047 rrc
= *dynamic_cast<RRSIGRecordContent
*>(DNSRecordContent::mastermake(QType::RRSIG
, 1, rr
.content
));
1049 else if(rr
.qtype
.getCode() == QType::DS
) {
1050 cerr
<<"got DS"<<endl
;
1051 dsrc
= *dynamic_cast<DSRecordContent
*>(DNSRecordContent::mastermake(QType::DS
, 1, rr
.content
));
1055 toSign
.push_back(shared_ptr
<DNSRecordContent
>(DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, rr
.content
)));
1059 string msg
= getMessageForRRSET(qname
, rrc
, toSign
);
1060 cerr
<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc
.d_algorithm
, drc
.d_key
)->verify(msg
, rrc
.d_signature
)<<endl
;
1061 if(dsrc
.d_digesttype
) {
1062 cerr
<<"Calculated DS: "<<apex
.toString()<<" IN DS "<<makeDSFromDNSKey(apex
, drc
, dsrc
.d_digesttype
).getZoneRepresentation()<<endl
;
1063 cerr
<<"Original DS: "<<apex
.toString()<<" IN DS "<<dsrc
.getZoneRepresentation()<<endl
;
1066 DNSCryptoKeyEngine
*key
=DNSCryptoKeyEngine::makeFromISCString(drc
, "Private-key-format: v1.2\n"
1067 "Algorithm: 12 (ECC-GOST)\n"
1068 "GostAsn1: MEUCAQAwHAYGKoUDAgITMBIGByqFAwICIwEGByqFAwICHgEEIgQg/9MiXtXKg9FDXDN/R9CmVhJDyuzRAIgh4tPwCu4NHIs=\n");
1069 string resign
=key
->sign(hash
);
1070 cerr
<<Base64Encode(resign
)<<endl
;
1071 cerr
<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc
.d_algorithm
, drc
.d_key
)->verify(hash
, resign
)<<endl
;
1075 bool disableDNSSECOnZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1077 UeberBackend
B("default");
1080 if (!B
.getDomainInfo(zone
, di
)){
1081 cerr
<< "No such zone in the database" << endl
;
1085 if(!dk
.isSecuredZone(zone
)) {
1086 cerr
<<"Zone is not secured"<<endl
;
1089 DNSSECKeeper::keyset_t keyset
=dk
.getKeys(zone
);
1091 if(keyset
.empty()) {
1092 cerr
<< "No keys for zone '"<<zone
.toString()<<"'."<<endl
;
1095 for(DNSSECKeeper::keyset_t::value_type value
: keyset
) {
1096 dk
.deactivateKey(zone
, value
.second
.id
);
1097 dk
.removeKey(zone
, value
.second
.id
);
1100 dk
.unsetNSEC3PARAM(zone
);
1101 dk
.unsetPresigned(zone
);
1104 bool showZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1106 UeberBackend
B("default");
1108 std::vector
<std::string
> meta
;
1110 if (!B
.getDomainInfo(zone
, di
)){
1111 cerr
<< "No such zone in the database" << endl
;
1115 if(!dk
.isSecuredZone(zone
)) {
1116 cerr
<<"Zone is not actively secured"<<endl
;
1118 NSEC3PARAMRecordContent ns3pr
;
1120 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
1122 DNSSECKeeper::keyset_t keyset
=dk
.getKeys(zone
);
1123 if (B
.getDomainMetadata(zone
, "TSIG-ALLOW-AXFR", meta
) && meta
.size() > 0) {
1124 cerr
<< "Zone has following allowed TSIG key(s): " << boost::join(meta
, ",") << endl
;
1128 if (B
.getDomainMetadata(zone
, "AXFR-MASTER-TSIG", meta
) && meta
.size() > 0) {
1129 cerr
<< "Zone uses following TSIG key(s): " << boost::join(meta
, ",") << endl
;
1132 cout
<<"Zone is " << (dk
.isPresigned(zone
) ? "" : "not ") << "presigned"<<endl
;
1134 if(keyset
.empty()) {
1135 cerr
<< "No keys for zone '"<<zone
.toString()<<"'."<<endl
;
1139 cout
<<"Zone has NSEC semantics"<<endl
;
1141 cout
<<"Zone has " << (narrow
? "NARROW " : "") <<"hashed NSEC3 semantics, configuration: "<<ns3pr
.getZoneRepresentation()<<endl
;
1143 cout
<< "keys: "<<endl
;
1144 for(DNSSECKeeper::keyset_t::value_type value
: keyset
) {
1146 algorithm2name(value
.first
.d_algorithm
, algname
);
1147 if (value
.first
.getKey()->getBits() < 1) {
1148 cout
<<"ID = "<<value
.second
.id
<<" ("<<(value
.second
.keyOrZone
? "KSK" : "ZSK")<<") <key missing or defunct>" <<endl
;
1151 cout
<<"ID = "<<value
.second
.id
<<" ("<<(value
.second
.keyOrZone
? "KSK" : "ZSK")<<"), tag = "<<value
.first
.getDNSKEY().getTag();
1152 cout
<<", algo = "<<(int)value
.first
.d_algorithm
<<", bits = "<<value
.first
.getKey()->getBits()<<"\t"<<((int)value
.second
.active
== 1 ? " A" : "Ina")<<"ctive ( " + algname
+ " ) "<<endl
;
1153 if(value
.second
.keyOrZone
|| ::arg().mustDo("direct-dnskey") || 1)
1154 cout
<<(value
.second
.keyOrZone
? "KSK" : "ZSK")<<" DNSKEY = "<<zone
.toString()<<" IN DNSKEY "<< value
.first
.getDNSKEY().getZoneRepresentation() << " ; ( " + algname
+ " )" << endl
;
1155 if(value
.second
.keyOrZone
|| 1) {
1156 cout
<<"DS = "<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, value
.first
.getDNSKEY(), 1).getZoneRepresentation() << " ; ( SHA1 digest )" << endl
;
1157 cout
<<"DS = "<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, value
.first
.getDNSKEY(), 2).getZoneRepresentation() << " ; ( SHA256 digest )" << endl
;
1159 string output
=makeDSFromDNSKey(zone
, value
.first
.getDNSKEY(), 3).getZoneRepresentation();
1160 cout
<<"DS = "<<zone
.toString()<<" IN DS "<< output
<< " ; ( GOST R 34.11-94 digest )" << endl
;
1166 string output
=makeDSFromDNSKey(zone
, value
.first
.getDNSKEY(), 4).getZoneRepresentation();
1167 cout
<<"DS = "<<zone
.toString()<<" IN DS "<< output
<< " ; ( SHA-384 digest )" << endl
;
1179 bool secureZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1182 vector
<string
> k_algos
;
1183 vector
<string
> z_algos
;
1187 stringtok(k_algos
, ::arg()["default-ksk-algorithms"], " ,");
1188 k_size
= ::arg().asNum("default-ksk-size");
1189 stringtok(z_algos
, ::arg()["default-zsk-algorithms"], " ,");
1190 z_size
= ::arg().asNum("default-zsk-size");
1193 throw runtime_error("KSK key size must be equal to or greater than 0");
1196 if (k_algos
.size() < 1 && z_algos
.size() < 1) {
1197 throw runtime_error("Zero algorithms given for KSK+ZSK in total");
1201 throw runtime_error("ZSK key size must be equal to or greater than 0");
1204 if(dk
.isSecuredZone(zone
)) {
1205 cerr
<< "Zone '"<<zone
.toString()<<"' already secure, remove keys with pdnsutil remove-zone-key if needed"<<endl
;
1210 UeberBackend
B("default");
1211 if(!B
.getDomainInfo(zone
, di
) || !di
.backend
) { // di.backend and B are mostly identical
1212 cout
<<"Can't find a zone called '"<<zone
.toString()<<"'"<<endl
;
1216 if(di
.kind
== DomainInfo::Slave
)
1218 cout
<<"Warning! This is a slave domain! If this was a mistake, please run"<<endl
;
1219 cout
<<"pdnsutil disable-dnssec "<<zone
.toString()<<" right now!"<<endl
;
1223 cout
<< "Securing zone with key size " << k_size
<< endl
;
1225 cout
<< "Securing zone with default key size" << endl
;
1228 DNSSECKeeper::keyset_t zskset
=dk
.getKeys(zone
, false);
1230 if(!zskset
.empty()) {
1231 cerr
<<"There were ZSKs already for zone '"<<zone
.toString()<<"', no need to add more"<<endl
;
1235 for(auto &k_algo
: k_algos
) {
1236 cout
<< "Adding KSK with algorithm " << k_algo
<< endl
;
1238 int algo
= shorthand2algorithm(k_algo
);
1240 if(!dk
.addKey(zone
, true, algo
, k_size
, true)) {
1241 cerr
<<"No backend was able to secure '"<<zone
.toString()<<"', most likely because no DNSSEC"<<endl
;
1242 cerr
<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl
;
1243 cerr
<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl
;
1244 cerr
<<"'gpgsql-dnssec' flag. Also make sure the schema has been updated for DNSSEC!"<<endl
;
1249 for(auto &z_algo
: z_algos
)
1251 cout
<< "Adding ZSK with algorithm " << z_algo
<< endl
;
1253 int algo
= shorthand2algorithm(z_algo
);
1255 if(!dk
.addKey(zone
, false, algo
, z_size
, true)) {
1256 cerr
<<"No backend was able to secure '"<<zone
.toString()<<"', most likely because no DNSSEC"<<endl
;
1257 cerr
<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl
;
1258 cerr
<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl
;
1259 cerr
<<"'gpgsql-dnssec' flag. Also make sure the schema has been updated for DNSSEC!"<<endl
;
1264 if(!dk
.isSecuredZone(zone
)) {
1265 cerr
<<"Failed to secure zone. Is your backend dnssec enabled? (set "<<endl
;
1266 cerr
<<"gsqlite3-dnssec, or gmysql-dnssec etc). Check this first."<<endl
;
1267 cerr
<<"If you run with the BIND backend, make sure you have configured"<<endl
;
1268 cerr
<<"it to use DNSSEC with 'bind-dnssec-db=/path/fname' and"<<endl
;
1269 cerr
<<"'pdnsutil create-bind-db /path/fname'!"<<endl
;
1273 // rectifyZone(dk, zone);
1274 // showZone(dk, zone);
1275 cout
<<"Zone "<<zone
.toString()<<" secured"<<endl
;
1279 void testSchema(DNSSECKeeper
& dk
, const DNSName
& zone
)
1281 cout
<<"Note: test-schema will try to create the zone, but it will not remove it."<<endl
;
1282 cout
<<"Please clean up after this."<<endl
;
1284 cout
<<"Constructing UeberBackend"<<endl
;
1285 UeberBackend
B("default");
1286 cout
<<"Picking first backend - if this is not what you want, edit launch line!"<<endl
;
1287 DNSBackend
*db
= B
.backends
[0];
1288 cout
<<"Creating slave domain "<<zone
.toString()<<endl
;
1289 db
->createSlaveDomain("127.0.0.1", zone
, "", "_testschema");
1290 cout
<<"Slave domain created"<<endl
;
1293 if(!B
.getDomainInfo(zone
, di
) || !di
.backend
) { // di.backend and B are mostly identical
1294 cout
<<"Can't find domain we just created, aborting"<<endl
;
1298 DNSResourceRecord rr
, rrget
;
1299 cout
<<"Starting transaction to feed records"<<endl
;
1300 db
->startTransaction(zone
, di
.id
);
1302 rr
.qtype
=QType::SOA
;
1307 rr
.content
="ns1.example.com. ahu.example.com. 2012081039 7200 3600 1209600 3600";
1308 cout
<<"Feeding SOA"<<endl
;
1310 rr
.qtype
=QType::TXT
;
1312 rr
.content
="\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"";
1313 cout
<<"Feeding overlong TXT"<<endl
;
1315 cout
<<"Committing"<<endl
;
1316 db
->commitTransaction();
1317 cout
<<"Querying TXT"<<endl
;
1318 db
->lookup(QType(QType::TXT
), zone
, NULL
, di
.id
);
1321 DNSResourceRecord rrthrowaway
;
1322 if(db
->get(rrthrowaway
)) // should not touch rr but don't assume anything
1324 cout
<<"Expected one record, got multiple, aborting"<<endl
;
1327 int size
=rrget
.content
.size();
1330 cout
<<"Expected 302 bytes, got "<<size
<<", aborting"<<endl
;
1334 cout
<<"[+] content field is over 255 bytes"<<endl
;
1336 cout
<<"Dropping all records, inserting SOA+2xA"<<endl
;
1337 db
->startTransaction(zone
, di
.id
);
1339 rr
.qtype
=QType::SOA
;
1344 rr
.content
="ns1.example.com. ahu.example.com. 2012081039 7200 3600 1209600 3600";
1345 cout
<<"Feeding SOA"<<endl
;
1349 rr
.qname
=DNSName("_underscore")+zone
;
1350 rr
.content
="127.0.0.1";
1353 rr
.qname
=DNSName("bla")+zone
;
1354 cout
<<"Committing"<<endl
;
1355 db
->commitTransaction();
1357 cout
<<"Securing zone"<<endl
;
1358 secureZone(dk
, zone
);
1359 cout
<<"Rectifying zone"<<endl
;
1360 rectifyZone(dk
, zone
);
1361 cout
<<"Checking underscore ordering"<<endl
;
1362 DNSName before
, after
;
1363 db
->getBeforeAndAfterNames(di
.id
, zone
, DNSName("z")+zone
, before
, after
);
1364 cout
<<"got '"<<before
.toString()<<"' < 'z."<<zone
.toString()<<"' < '"<<after
.toString()<<"'"<<endl
;
1365 if(before
!= DNSName("_underscore")+zone
)
1367 cout
<<"before is wrong, got '"<<before
.toString()<<"', expected '_underscore."<<zone
.toString()<<"', aborting"<<endl
;
1372 cout
<<"after is wrong, got '"<<after
.toString()<<"', expected '"<<zone
.toString()<<"', aborting"<<endl
;
1375 cout
<<"[+] ordername sorting is correct for names starting with _"<<endl
;
1377 cout
<<"End of tests, please remove "<<zone
.toString()<<" from domains+records"<<endl
;
1380 int main(int argc
, char** argv
)
1383 po::options_description
desc("Allowed options");
1385 ("help,h", "produce help message")
1386 ("verbose,v", "be verbose")
1387 ("force", "force an action")
1388 ("config-name", po::value
<string
>()->default_value(""), "virtual configuration name")
1389 ("config-dir", po::value
<string
>()->default_value(SYSCONFDIR
), "location of pdns.conf")
1390 ("commands", po::value
<vector
<string
> >());
1392 po::positional_options_description p
;
1393 p
.add("commands", -1);
1394 po::store(po::command_line_parser(argc
, argv
).options(desc
).positional(p
).run(), g_vm
);
1397 vector
<string
> cmds
;
1399 if(g_vm
.count("commands"))
1400 cmds
= g_vm
["commands"].as
<vector
<string
> >();
1402 g_verbose
= g_vm
.count("verbose");
1404 if(cmds
.empty() || g_vm
.count("help")) {
1405 cerr
<<"Usage: \npdnsutil [options] <command> [params ..]\n"<<endl
;
1406 cerr
<<"Commands:"<<endl
;
1407 cerr
<<"activate-tsig-key ZONE NAME {master|slave}"<<endl
;
1408 cerr
<<" Enable TSIG key for a zone"<<endl
;
1409 cerr
<<"activate-zone-key ZONE KEY-ID Activate the key with key id KEY-ID in ZONE"<<endl
;
1410 cerr
<<"add-zone-key ZONE {zsk|ksk} [BITS] [active|inactive]"<<endl
;
1411 cerr
<<" [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384";
1412 #ifdef HAVE_LIBSODIUM
1413 cerr
<<"|experimental-ed25519";
1416 cerr
<<" Add a ZSK or KSK to zone and specify algo&bits"<<endl
;
1417 cerr
<<"backend-cmd BACKEND CMD [CMD..] Perform one or more backend commands"<<endl
;
1418 cerr
<<"b2b-migrate OLD NEW Move all data from one backend to another"<<endl
;
1419 cerr
<<"bench-db [filename] Bench database backend with queries, one domain per line"<<endl
;
1420 cerr
<<"check-zone ZONE Check a zone for correctness"<<endl
;
1421 cerr
<<"check-all-zones [exit-on-error] Check all zones for correctness. Set exit-on-error to exit immediately"<<endl
;
1422 cerr
<<" after finding an error in a zone."<<endl
;
1423 cerr
<<"create-bind-db FNAME Create DNSSEC db for BIND backend (bind-dnssec-db)"<<endl
;
1424 cerr
<<"create-zone ZONE Create empty zone ZONE"<<endl
;
1425 cerr
<<"deactivate-tsig-key ZONE NAME {master|slave}"<<endl
;
1426 cerr
<<" Disable TSIG key for a zone"<<endl
;
1427 cerr
<<"deactivate-zone-key ZONE KEY-ID Deactivate the key with key id KEY-ID in ZONE"<<endl
;
1428 cerr
<<"delete-tsig-key NAME Delete TSIG key (warning! will not unmap key!)"<<endl
;
1429 cerr
<<"delete-zone ZONE Delete the zone"<<endl
;
1430 cerr
<<"disable-dnssec ZONE Deactivate all keys and unset PRESIGNED in ZONE"<<endl
;
1431 cerr
<<"export-zone-dnskey ZONE KEY-ID Export to stdout the public DNSKEY described"<<endl
;
1432 cerr
<<"export-zone-key ZONE KEY-ID Export to stdout the private key described"<<endl
;
1433 cerr
<<"generate-tsig-key NAME ALGORITHM Generate new TSIG key"<<endl
;
1434 cerr
<<"generate-zone-key {zsk|ksk} [ALGORITHM] [BITS]"<<endl
;
1435 cerr
<<" Generate a ZSK or KSK to stdout with specified ALGORITHM and BITS"<<endl
;
1436 cerr
<<"get-meta ZONE [KIND ...] Get zone metadata. If no KIND given, lists all known"<<endl
;
1437 cerr
<<"hash-zone-record ZONE RNAME Calculate the NSEC3 hash for RNAME in ZONE"<<endl
;
1439 cerr
<<"hsm assign ZONE ALGORITHM {ksk|zsk} MODULE SLOT PIN LABEL"<<endl
<<
1440 " Assign a hardware signing module to a ZONE"<<endl
;
1441 cerr
<<"hsm create-key ZONE KEY-ID [BITS] Create a key using hardware signing module for ZONE (use assign first)"<<endl
;
1442 cerr
<<" BITS defaults to 2048"<<endl
;
1444 cerr
<<"increase-serial ZONE Increases the SOA-serial by 1. Uses SOA-EDIT"<<endl
;
1445 cerr
<<"import-tsig-key NAME ALGORITHM KEY Import TSIG key"<<endl
;
1446 cerr
<<"import-zone-key ZONE FILE Import from a file a private key, ZSK or KSK"<<endl
;
1447 cerr
<<" [active|inactive] [ksk|zsk] Defaults to KSK and active"<<endl
;
1448 cerr
<<"load-zone ZONE FILE Load ZONE from FILE, possibly creating zone or atomically"<<endl
;
1449 cerr
<<" replacing contents"<<endl
;
1450 cerr
<<"list-keys [ZONE] List DNSSEC keys for ZONE. When ZONE is unset or \"all\", display all keys for all zones"<<endl
;
1451 cerr
<<"list-zone ZONE List zone contents"<<endl
;
1452 cerr
<<"list-all-zones [master|slave|native]"<<endl
;
1453 cerr
<<" List all zone names"<<endl
;;
1454 cerr
<<"list-tsig-keys List all TSIG keys"<<endl
;
1455 cerr
<<"rectify-zone ZONE [ZONE ..] Fix up DNSSEC fields (order, auth)"<<endl
;
1456 cerr
<<"rectify-all-zones Rectify all zones."<<endl
;
1457 cerr
<<"remove-zone-key ZONE KEY-ID Remove key with KEY-ID from ZONE"<<endl
;
1458 cerr
<<"secure-all-zones [increase-serial] Secure all zones without keys."<<endl
;
1459 cerr
<<"secure-zone ZONE [ZONE ..] Add KSK and two ZSKs for ZONE"<<endl
;
1460 cerr
<<"set-nsec3 ZONE ['PARAMS' [narrow]] Enable NSEC3 with PARAMS. Optionally narrow"<<endl
;
1461 cerr
<<"set-presigned ZONE Use presigned RRSIGs from storage"<<endl
;
1462 cerr
<<"set-publish-cdnskey ZONE Enable sending CDNSKEY responses for ZONE"<<endl
;
1463 cerr
<<"set-publish-cds ZONE [DIGESTALGOS] Enable sending CDS responses for ZONE, using DIGESTALGOS as signature algirithms"<<endl
;
1464 cerr
<<" DIGESTALGOS should be a comma separated list of numbers, is is '1,2' by default"<<endl
;
1465 cerr
<<"set-meta ZONE KIND [VALUE ..]"<<endl
;
1466 cerr
<<" Set zone metadata, optionally providing a value. Empty clears meta."<<endl
;
1467 cerr
<<"show-zone ZONE Show DNSSEC (public) key details about a zone"<<endl
;
1468 cerr
<<"unset-nsec3 ZONE Switch back to NSEC"<<endl
;
1469 cerr
<<"unset-presigned ZONE No longer use presigned RRSIGs"<<endl
;
1470 cerr
<<"unset-publish-cdnskey ZONE Disable sending CDNSKEY responses for ZONE"<<endl
;
1471 cerr
<<"unset-publish-cds ZONE Disable sending CDS responses for ZONE"<<endl
;
1472 cerr
<<"test-schema ZONE Test DB schema - will create ZONE"<<endl
;
1477 #ifdef HAVE_LIBSODIUM
1478 if (sodium_init() == -1) {
1479 cerr
<<"Unable to initialize sodium crypto library"<<endl
;
1484 if (cmds
[0] == "test-algorithm") {
1485 if(cmds
.size() != 2) {
1486 cerr
<< "Syntax: pdnsutil test-algorithm algonum"<<endl
;
1489 if (testAlgorithm(pdns_stou(cmds
[1])))
1494 if(cmds
[0] == "test-algorithms") {
1495 if (testAlgorithms())
1500 loadMainConfig(g_vm
["config-dir"].as
<string
>());
1503 if(cmds
[0] == "create-bind-db") {
1505 if(cmds
.size() != 2) {
1506 cerr
<< "Syntax: pdnsutil create-bind-db FNAME"<<endl
;
1510 SSQLite3
db(cmds
[1], true); // create=ok
1511 vector
<string
> statements
;
1512 stringtok(statements
, sqlCreate
, ";");
1513 for(const string
& statement
: statements
) {
1514 db
.execute(statement
);
1517 catch(SSqlException
& se
) {
1518 throw PDNSException("Error creating database in BIND backend: "+se
.txtReason());
1522 cerr
<<"bind-dnssec-db requires building PowerDNS with SQLite3"<<endl
;
1529 if (cmds
[0] == "test-schema") {
1530 if(cmds
.size() != 2) {
1531 cerr
<< "Syntax: pdnsutil test-schema ZONE"<<endl
;
1534 testSchema(dk
, DNSName(cmds
[1]));
1537 if(cmds
[0] == "rectify-zone") {
1538 if(cmds
.size() < 2) {
1539 cerr
<< "Syntax: pdnsutil rectify-zone ZONE [ZONE..]"<<endl
;
1542 unsigned int exitCode
= 0;
1543 for(unsigned int n
= 1; n
< cmds
.size(); ++n
)
1544 if (!rectifyZone(dk
, DNSName(cmds
[n
])))
1548 else if (cmds
[0] == "rectify-all-zones") {
1549 rectifyAllZones(dk
);
1551 else if(cmds
[0] == "check-zone") {
1552 if(cmds
.size() != 2) {
1553 cerr
<< "Syntax: pdnsutil check-zone ZONE"<<endl
;
1556 UeberBackend
B("default");
1557 exit(checkZone(dk
, B
, DNSName(cmds
[1])));
1559 else if(cmds
[0] == "bench-db") {
1560 dbBench(cmds
.size() > 1 ? cmds
[1] : "");
1562 else if (cmds
[0] == "check-all-zones") {
1563 bool exitOnError
= (cmds
[1] == "exit-on-error");
1564 exit(checkAllZones(dk
, exitOnError
));
1566 else if (cmds
[0] == "list-all-zones") {
1567 if (cmds
.size() > 2) {
1568 cerr
<< "Syntax: pdnsutil list-all-zones [master|slave|native]"<<endl
;
1571 if (cmds
.size() == 2)
1572 return listAllZones(cmds
[1]);
1573 return listAllZones();
1575 else if (cmds
[0] == "test-zone") {
1576 cerr
<< "Did you mean check-zone?"<<endl
;
1579 else if (cmds
[0] == "test-all-zones") {
1580 cerr
<< "Did you mean check-all-zones?"<<endl
;
1584 else if(cmds
[0] == "signing-server" )
1588 else if(cmds
[0] == "signing-slave")
1590 launchSigningService(0);
1593 else if(cmds
[0] == "test-speed") {
1594 if(cmds
.size() < 2) {
1595 cerr
<< "Syntax: pdnsutil test-speed numcores [signing-server]"<<endl
;
1598 testSpeed(dk
, DNSName(cmds
[1]), (cmds
.size() > 3) ? cmds
[3] : "", pdns_stou(cmds
[2]));
1600 else if(cmds
[0] == "verify-crypto") {
1601 if(cmds
.size() != 2) {
1602 cerr
<< "Syntax: pdnsutil verify-crypto FILE"<<endl
;
1605 verifyCrypto(cmds
[1]);
1608 else if(cmds
[0] == "show-zone") {
1609 if(cmds
.size() != 2) {
1610 cerr
<< "Syntax: pdnsutil show-zone ZONE"<<endl
;
1613 if (!showZone(dk
, DNSName(cmds
[1]))) return 1;
1615 else if(cmds
[0] == "disable-dnssec") {
1616 if(cmds
.size() != 2) {
1617 cerr
<< "Syntax: pdnsutil disable-dnssec ZONE"<<endl
;
1620 DNSName
zone(cmds
[1]);
1621 if(!disableDNSSECOnZone(dk
, zone
)) {
1622 cerr
<< "Cannot disable DNSSEC on " << zone
<< endl
;
1626 else if(cmds
[0] == "activate-zone-key") {
1627 if(cmds
.size() != 3) {
1628 cerr
<< "Syntax: pdnsutil activate-zone-key ZONE KEY-ID"<<endl
;
1631 DNSName
zone(cmds
[1]);
1632 unsigned int id
=pdns_stou(cmds
[2]);
1635 cerr
<<"Invalid KEY-ID"<<endl
;
1638 if (!dk
.activateKey(zone
, id
)) {
1639 cerr
<<"Activation of key failed"<<endl
;
1644 else if(cmds
[0] == "deactivate-zone-key") {
1645 if(cmds
.size() != 3) {
1646 cerr
<< "Syntax: pdnsutil deactivate-zone-key ZONE KEY-ID"<<endl
;
1649 DNSName
zone(cmds
[1]);
1650 unsigned int id
=pdns_stou(cmds
[2]);
1653 cerr
<<"Invalid KEY-ID"<<endl
;
1656 if (!dk
.deactivateKey(zone
, id
)) {
1657 cerr
<<"Deactivation of key failed"<<endl
;
1662 else if(cmds
[0] == "add-zone-key") {
1663 if(cmds
.size() < 3 ) {
1664 cerr
<< "Syntax: pdnsutil add-zone-key ZONE zsk|ksk [bits] [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]"<<endl
;
1667 DNSName
zone(cmds
[1]);
1669 UeberBackend
B("default");
1672 if (!B
.getDomainInfo(zone
, di
)){
1673 cerr
<< "No such zone in the database" << endl
;
1677 // need to get algorithm, bits & ksk or zsk from commandline
1678 bool keyOrZone
=false;
1683 for(unsigned int n
=2; n
< cmds
.size(); ++n
) {
1684 if(pdns_iequals(cmds
[n
], "zsk"))
1686 else if(pdns_iequals(cmds
[n
], "ksk"))
1688 else if((tmp_algo
= shorthand2algorithm(cmds
[n
]))>0) {
1689 algorithm
= tmp_algo
;
1690 } else if(pdns_iequals(cmds
[n
], "active")) {
1692 } else if(pdns_iequals(cmds
[n
], "inactive") || pdns_iequals(cmds
[n
], "passive")) { // 'passive' eventually needs to be removed
1694 } else if(pdns_stou(cmds
[n
])) {
1695 bits
= pdns_stou(cmds
[n
]);
1697 cerr
<<"Unknown algorithm, key flag or size '"<<cmds
[n
]<<"'"<<endl
;
1698 exit(EXIT_FAILURE
);;
1701 if(!dk
.addKey(zone
, keyOrZone
, algorithm
, bits
, active
)) {
1702 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
1706 cerr
<<"Added a " << (keyOrZone
? "KSK" : "ZSK")<<" with algorithm = "<<algorithm
<<", active="<<active
<<endl
;
1708 cerr
<<"Requested specific key size of "<<bits
<<" bits"<<endl
;
1711 else if(cmds
[0] == "remove-zone-key") {
1712 if(cmds
.size() < 3) {
1713 cerr
<<"Syntax: pdnsutil remove-zone-key ZONE KEY-ID"<<endl
;
1716 DNSName
zone(cmds
[1]);
1717 unsigned int id
=pdns_stou(cmds
[2]);
1718 if (!dk
.removeKey(zone
, id
)) {
1719 cerr
<<"Cannot remove key " << id
<< " from " << zone
<<endl
;
1724 else if(cmds
[0] == "delete-zone") {
1725 if(cmds
.size() != 2) {
1726 cerr
<<"Syntax: pdnsutil delete-zone ZONE"<<endl
;
1729 exit(deleteZone(DNSName(cmds
[1])));
1731 else if(cmds
[0] == "create-zone") {
1732 if(cmds
.size() != 2) {
1733 cerr
<<"Syntax: pdnsutil create-zone ZONE"<<endl
;
1736 exit(createZone(DNSName(cmds
[1])));
1738 else if(cmds
[0] == "list-zone") {
1739 if(cmds
.size() != 2) {
1740 cerr
<<"Syntax: pdnsutil list-zone ZONE"<<endl
;
1746 exit(listZone(DNSName(cmds
[1])));
1748 else if(cmds
[0] == "list-keys") {
1749 if(cmds
.size() > 2) {
1750 cerr
<<"Syntax: pdnsutil list-keys [ZONE]"<<endl
;
1753 string zname
= (cmds
.size() == 2) ? cmds
[1] : "all";
1754 exit(listKeys(zname
, dk
));
1756 else if(cmds
[0] == "load-zone") {
1757 if(cmds
.size() != 3) {
1758 cerr
<<"Syntax: pdnsutil load-zone ZONE FILENAME"<<endl
;
1764 exit(loadZone(DNSName(cmds
[1]), cmds
[2]));
1766 else if(cmds
[0] == "secure-zone") {
1767 if(cmds
.size() < 2) {
1768 cerr
<< "Syntax: pdnsutil secure-zone ZONE"<<endl
;
1771 vector
<DNSName
> mustRectify
;
1772 unsigned int zoneErrors
=0;
1773 for(unsigned int n
= 1; n
< cmds
.size(); ++n
) {
1774 DNSName
zone(cmds
[n
]);
1775 dk
.startTransaction(zone
, -1);
1776 if(secureZone(dk
, zone
)) {
1777 mustRectify
.push_back(zone
);
1781 dk
.commitTransaction();
1784 for(const auto& zone
: mustRectify
)
1785 rectifyZone(dk
, zone
);
1792 else if (cmds
[0] == "secure-all-zones") {
1793 if (cmds
.size() >= 2 && !pdns_iequals(cmds
[1], "increase-serial")) {
1794 cerr
<< "Syntax: pdnsutil secure-all-zones [increase-serial]"<<endl
;
1798 UeberBackend
B("default");
1800 vector
<DomainInfo
> domainInfo
;
1801 B
.getAllDomains(&domainInfo
);
1803 unsigned int zonesSecured
=0, zoneErrors
=0;
1804 for(DomainInfo di
: domainInfo
) {
1805 if(!dk
.isSecuredZone(di
.zone
)) {
1806 cout
<<"Securing "<<di
.zone
.toString()<<": ";
1807 if (secureZone(dk
, di
.zone
)) {
1809 if (cmds
.size() == 2) {
1810 if (!increaseSerial(di
.zone
, dk
))
1819 cout
<<"Secured: "<<zonesSecured
<<" zones. Errors: "<<zoneErrors
<<endl
;
1826 else if(cmds
[0]=="set-nsec3") {
1827 if(cmds
.size() < 2) {
1828 cerr
<<"Syntax: pdnsutil set-nsec3 ZONE 'params' [narrow]"<<endl
;
1831 string nsec3params
= cmds
.size() > 2 ? cmds
[2] : "1 0 1 ab";
1832 bool narrow
= cmds
.size() > 3 && cmds
[3]=="narrow";
1833 NSEC3PARAMRecordContent
ns3pr(nsec3params
);
1835 DNSName
zone(cmds
[1]);
1836 if (zone
.wirelength() > 222) {
1837 cerr
<<"Cannot enable NSEC3 for " << zone
.toString() << " as it is too long (" << zone
.wirelength() << " bytes, maximum is 222 bytes)"<<endl
;
1840 if (! dk
.setNSEC3PARAM(zone
, ns3pr
, narrow
)) {
1841 cerr
<<"Cannot set NSEC3 param for " << zone
.toString() << endl
;
1846 cerr
<<"NSEC3 set, ";
1848 cerr
<<"NSEC3 (opt-out) set, ";
1850 if(dk
.isSecuredZone(zone
))
1851 cerr
<<"please rectify your zone if your backend needs it"<<endl
;
1853 cerr
<<"please secure and rectify your zone."<<endl
;
1857 else if(cmds
[0]=="set-presigned") {
1858 if(cmds
.size() < 2) {
1859 cerr
<<"Syntax: pdnsutil set-presigned ZONE"<<endl
;
1862 if (! dk
.setPresigned(DNSName(cmds
[1]))) {
1863 cerr
<< "Could not set presigned on for " << cmds
[1] << endl
;
1868 else if(cmds
[0]=="set-publish-cdnskey") {
1869 if(cmds
.size() < 2) {
1870 cerr
<<"Syntax: pdnsutil set-publish-cdnskey ZONE"<<endl
;
1873 if (! dk
.setPublishCDNSKEY(DNSName(cmds
[1]))) {
1874 cerr
<< "Could not set publishing for CDNSKEY records for "<< cmds
[1]<<endl
;
1879 else if(cmds
[0]=="set-publish-cds") {
1880 if(cmds
.size() < 2) {
1881 cerr
<<"Syntax: pdnsutil set-publish-cds ZONE [DIGESTALGOS]"<<endl
;
1885 // If DIGESTALGOS is unset
1886 if(cmds
.size() == 2)
1887 cmds
.push_back("1,2");
1889 if (! dk
.setPublishCDS(DNSName(cmds
[1]), cmds
[2])) {
1890 cerr
<< "Could not set publishing for CDS records for "<< cmds
[1]<<endl
;
1895 else if(cmds
[0]=="unset-presigned") {
1896 if(cmds
.size() < 2) {
1897 cerr
<<"Syntax: pdnsutil unset-presigned ZONE"<<endl
;
1900 if (! dk
.unsetPresigned(DNSName(cmds
[1]))) {
1901 cerr
<< "Could not unset presigned on for " << cmds
[1] << endl
;
1906 else if(cmds
[0]=="unset-publish-cdnskey") {
1907 if(cmds
.size() < 2) {
1908 cerr
<<"Syntax: pdnsutil unset-publish-cdnskey ZONE"<<endl
;
1911 if (! dk
.unsetPublishCDNSKEY(DNSName(cmds
[1]))) {
1912 cerr
<< "Could not unset publishing for CDNSKEY records for "<< cmds
[1]<<endl
;
1917 else if(cmds
[0]=="unset-publish-cds") {
1918 if(cmds
.size() < 2) {
1919 cerr
<<"Syntax: pdnsutil unset-publish-cds ZONE"<<endl
;
1922 if (! dk
.unsetPublishCDS(DNSName(cmds
[1]))) {
1923 cerr
<< "Could not unset publishing for CDS records for "<< cmds
[1]<<endl
;
1928 else if(cmds
[0]=="hash-zone-record") {
1929 if(cmds
.size() < 3) {
1930 cerr
<<"Syntax: pdnsutil hash-zone-record ZONE RNAME"<<endl
;
1933 DNSName
zone(cmds
[1]);
1934 DNSName
record(cmds
[2]);
1935 NSEC3PARAMRecordContent ns3pr
;
1937 if(!dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
)) {
1938 cerr
<<"The '"<<zone
.toString()<<"' zone does not use NSEC3"<<endl
;
1942 cerr
<<"The '"<<zone
.toString()<<"' zone uses narrow NSEC3, but calculating hash anyhow"<<endl
;
1945 cout
<<toBase32Hex(hashQNameWithSalt(ns3pr
, record
))<<endl
;
1947 else if(cmds
[0]=="unset-nsec3") {
1948 if(cmds
.size() < 2) {
1949 cerr
<<"Syntax: pdnsutil unset-nsec3 ZONE"<<endl
;
1952 if ( ! dk
.unsetNSEC3PARAM(DNSName(cmds
[1]))) {
1953 cerr
<<"Cannot unset NSEC3 param for " << cmds
[1] << endl
;
1958 else if(cmds
[0]=="export-zone-key") {
1959 if(cmds
.size() < 3) {
1960 cerr
<<"Syntax: pdnsutil export-zone-key ZONE KEY-ID"<<endl
;
1964 string zone
=cmds
[1];
1965 unsigned int id
=pdns_stou(cmds
[2]);
1966 DNSSECPrivateKey dpk
=dk
.getKeyById(DNSName(zone
), id
);
1967 cout
<< dpk
.getKey()->convertToISC() <<endl
;
1969 else if(cmds
[0]=="increase-serial") {
1970 if (cmds
.size() < 2) {
1971 cerr
<<"Syntax: pdnsutil increase-serial ZONE"<<endl
;
1974 return increaseSerial(DNSName(cmds
[1]), dk
);
1976 else if(cmds
[0]=="import-zone-key-pem") {
1977 if(cmds
.size() < 4) {
1978 cerr
<<"Syntax: pdnsutil import-zone-key-pem ZONE FILE ALGORITHM {ksk|zsk}"<<endl
;
1981 string zone
=cmds
[1];
1982 string fname
=cmds
[2];
1984 ifstream
ifs(fname
.c_str());
1985 string tmp
, interim
, raw
;
1986 while(getline(ifs
, line
)) {
1992 B64Decode(interim
, raw
);
1993 DNSSECPrivateKey dpk
;
1994 DNSKEYRecordContent drc
;
1995 shared_ptr
<DNSCryptoKeyEngine
> key(DNSCryptoKeyEngine::makeFromPEMString(drc
, raw
));
1998 dpk
.d_algorithm
= pdns_stou(cmds
[3]);
2000 if(dpk
.d_algorithm
== 7)
2001 dpk
.d_algorithm
= 5;
2003 cerr
<<(int)dpk
.d_algorithm
<<endl
;
2005 if(cmds
.size() > 4) {
2006 if(pdns_iequals(cmds
[4], "ZSK"))
2008 else if(pdns_iequals(cmds
[4], "KSK"))
2011 cerr
<<"Unknown key flag '"<<cmds
[4]<<"'"<<endl
;
2016 dpk
.d_flags
= 257; // ksk
2018 if(!dk
.addKey(DNSName(zone
), dpk
)) {
2019 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2024 else if(cmds
[0]=="import-zone-key") {
2025 if(cmds
.size() < 3) {
2026 cerr
<<"Syntax: pdnsutil import-zone-key ZONE FILE [ksk|zsk] [active|inactive]"<<endl
;
2029 string zone
=cmds
[1];
2030 string fname
=cmds
[2];
2031 DNSSECPrivateKey dpk
;
2032 DNSKEYRecordContent drc
;
2033 shared_ptr
<DNSCryptoKeyEngine
> key(DNSCryptoKeyEngine::makeFromISCFile(drc
, fname
.c_str()));
2035 dpk
.d_algorithm
= drc
.d_algorithm
;
2037 if(dpk
.d_algorithm
== 7)
2038 dpk
.d_algorithm
= 5;
2043 for(unsigned int n
= 3; n
< cmds
.size(); ++n
) {
2044 if(pdns_iequals(cmds
[n
], "ZSK"))
2046 else if(pdns_iequals(cmds
[n
], "KSK"))
2048 else if(pdns_iequals(cmds
[n
], "active"))
2050 else if(pdns_iequals(cmds
[n
], "passive") || pdns_iequals(cmds
[n
], "inactive")) // passive eventually needs to be removed
2053 cerr
<<"Unknown key flag '"<<cmds
[n
]<<"'"<<endl
;
2057 if(!dk
.addKey(DNSName(zone
), dpk
, active
)) {
2058 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2062 else if(cmds
[0]=="export-zone-dnskey") {
2063 if(cmds
.size() < 3) {
2064 cerr
<<"Syntax: pdnsutil export-zone-dnskey ZONE KEY-ID"<<endl
;
2068 DNSName
zone(cmds
[1]);
2069 unsigned int id
=pdns_stou(cmds
[2]);
2070 DNSSECPrivateKey dpk
=dk
.getKeyById(zone
, id
);
2071 cout
<< zone
<<" IN DNSKEY "<<dpk
.getDNSKEY().getZoneRepresentation() <<endl
;
2072 if(dpk
.d_flags
== 257) {
2073 cout
<< zone
<< " IN DS "<<makeDSFromDNSKey(zone
, dpk
.getDNSKEY(), 1).getZoneRepresentation() << endl
;
2074 cout
<< zone
<< " IN DS "<<makeDSFromDNSKey(zone
, dpk
.getDNSKEY(), 2).getZoneRepresentation() << endl
;
2077 else if(cmds
[0] == "generate-zone-key") {
2078 if(cmds
.size() < 2 ) {
2079 cerr
<< "Syntax: pdnsutil generate-zone-key zsk|ksk [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384] [bits]"<<endl
;
2082 // need to get algorithm, bits & ksk or zsk from commandline
2083 bool keyOrZone
=false;
2087 for(unsigned int n
=1; n
< cmds
.size(); ++n
) {
2088 if(pdns_iequals(cmds
[n
], "zsk"))
2090 else if(pdns_iequals(cmds
[n
], "ksk"))
2092 else if((tmp_algo
= shorthand2algorithm(cmds
[n
]))>0) {
2093 algorithm
= tmp_algo
;
2094 } else if(pdns_stou(cmds
[n
]))
2095 bits
= pdns_stou(cmds
[n
]);
2097 cerr
<<"Unknown algorithm, key flag or size '"<<cmds
[n
]<<"'"<<endl
;
2101 cerr
<<"Generating a " << (keyOrZone
? "KSK" : "ZSK")<<" with algorithm = "<<algorithm
<<endl
;
2103 cerr
<<"Requesting specific key size of "<<bits
<<" bits"<<endl
;
2105 DNSSECPrivateKey dspk
;
2106 shared_ptr
<DNSCryptoKeyEngine
> dpk(DNSCryptoKeyEngine::make(algorithm
)); // defaults to RSA for now, could be smart w/algorithm! XXX FIXME
2109 bits
= keyOrZone
? 2048 : 1024;
2111 if(algorithm
== 12 || algorithm
== 13 || algorithm
== 250) // ECDSA, GOST, ED25519
2113 else if(algorithm
== 14)
2116 throw runtime_error("Can't guess key size for algorithm "+std::to_string(algorithm
));
2122 dspk
.d_algorithm
= algorithm
;
2123 dspk
.d_flags
= keyOrZone
? 257 : 256;
2125 // print key to stdout
2126 cout
<< "Flags: " << dspk
.d_flags
<< endl
<<
2127 dspk
.getKey()->convertToISC() << endl
;
2128 } else if (cmds
[0]=="generate-tsig-key") {
2129 if (cmds
.size() < 3) {
2130 cerr
<< "Syntax: " << cmds
[0] << " name (hmac-md5|hmac-sha1|hmac-sha224|hmac-sha256|hmac-sha384|hmac-sha512)" << endl
;
2133 DNSName
name(cmds
[1]);
2134 string algo
= cmds
[2];
2139 if (algo
== "hmac-md5") {
2141 } else if (algo
== "hmac-sha1") {
2143 } else if (algo
== "hmac-sha224") {
2145 } else if (algo
== "hmac-sha256") {
2147 } else if (algo
== "hmac-sha384") {
2149 } else if (algo
== "hmac-sha512") {
2152 cerr
<< "Cannot generate key for " << algo
<< endl
;
2156 cerr
<< "Generating new key with " << klen
<< " bytes (this can take a while)" << endl
;
2157 seedRandom(::arg()["entropy-source"]);
2158 for(size_t i
= 0; i
< klen
; i
+=4) {
2159 *(unsigned int*)(tmpkey
+i
) = dns_random(0xffffffff);
2161 key
= Base64Encode(std::string(tmpkey
, klen
));
2163 UeberBackend
B("default");
2164 if (B
.setTSIGKey(name
, DNSName(algo
), key
)) { // you are feeling bored, put up DNSName(algo) up earlier
2165 cout
<< "Create new TSIG key " << name
<< " " << algo
<< " " << key
<< endl
;
2167 cout
<< "Failure storing new TSIG key " << name
<< " " << algo
<< " " << key
<< endl
;
2171 } else if (cmds
[0]=="import-tsig-key") {
2172 if (cmds
.size() < 4) {
2173 cerr
<< "Syntax: " << cmds
[0] << " name algorithm key" << endl
;
2176 DNSName
name(cmds
[1]);
2177 string algo
= cmds
[2];
2178 string key
= cmds
[3];
2180 UeberBackend
B("default");
2181 if (B
.setTSIGKey(name
, DNSName(algo
), key
)) {
2182 cout
<< "Imported TSIG key " << name
<< " " << algo
<< endl
;
2184 cout
<< "Failure importing TSIG key " << name
<< " " << algo
<< endl
;
2188 } else if (cmds
[0]=="delete-tsig-key") {
2189 if (cmds
.size() < 2) {
2190 cerr
<< "Syntax: " << cmds
[0] << " name" << endl
;
2193 DNSName
name(cmds
[1]);
2195 UeberBackend
B("default");
2196 if (B
.deleteTSIGKey(name
)) {
2197 cout
<< "Deleted TSIG key " << name
<< endl
;
2199 cout
<< "Failure deleting TSIG key " << name
<< endl
;
2203 } else if (cmds
[0]=="list-tsig-keys") {
2204 std::vector
<struct TSIGKey
> keys
;
2205 UeberBackend
B("default");
2206 if (B
.getTSIGKeys(keys
)) {
2207 for(const struct TSIGKey
&key
: keys
) {
2208 cout
<< key
.name
.toString() << " " << key
.algorithm
.toString() << " " << key
.key
<< endl
;
2212 } else if (cmds
[0]=="activate-tsig-key") {
2214 if (cmds
.size() < 4) {
2215 cerr
<< "Syntax: " << cmds
[0] << " ZONE NAME {master|slave}" << endl
;
2218 DNSName
zname(cmds
[1]);
2219 string name
= cmds
[2];
2220 if (cmds
[3] == "master")
2221 metaKey
= "TSIG-ALLOW-AXFR";
2222 else if (cmds
[3] == "slave")
2223 metaKey
= "AXFR-MASTER-TSIG";
2225 cerr
<< "Invalid parameter '" << cmds
[3] << "', expected master or slave" << endl
;
2228 UeberBackend
B("default");
2229 std::vector
<std::string
> meta
;
2230 if (!B
.getDomainMetadata(zname
, metaKey
, meta
)) {
2231 cout
<< "Failure enabling TSIG key " << name
<< " for " << zname
<< endl
;
2235 for(std::string tmpname
: meta
) {
2236 if (tmpname
== name
) { found
= true; break; }
2238 if (!found
) meta
.push_back(name
);
2239 if (B
.setDomainMetadata(zname
, metaKey
, meta
)) {
2240 cout
<< "Enabled TSIG key " << name
<< " for " << zname
<< endl
;
2242 cout
<< "Failure enabling TSIG key " << name
<< " for " << zname
<< endl
;
2246 } else if (cmds
[0]=="deactivate-tsig-key") {
2248 if (cmds
.size() < 4) {
2249 cerr
<< "Syntax: " << cmds
[0] << " ZONE NAME {master|slave}" << endl
;
2252 DNSName
zname(cmds
[1]);
2253 string name
= cmds
[2];
2254 if (cmds
[3] == "master")
2255 metaKey
= "TSIG-ALLOW-AXFR";
2256 else if (cmds
[3] == "slave")
2257 metaKey
= "AXFR-MASTER-TSIG";
2259 cerr
<< "Invalid parameter '" << cmds
[3] << "', expected master or slave" << endl
;
2263 UeberBackend
B("default");
2264 std::vector
<std::string
> meta
;
2265 if (!B
.getDomainMetadata(zname
, metaKey
, meta
)) {
2266 cout
<< "Failure disabling TSIG key " << name
<< " for " << zname
<< endl
;
2269 std::vector
<std::string
>::iterator iter
= meta
.begin();
2270 for(;iter
!= meta
.end(); iter
++) if (*iter
== name
) break;
2271 if (iter
!= meta
.end()) meta
.erase(iter
);
2272 if (B
.setDomainMetadata(zname
, metaKey
, meta
)) {
2273 cout
<< "Disabled TSIG key " << name
<< " for " << zname
<< endl
;
2275 cout
<< "Failure disabling TSIG key " << name
<< " for " << zname
<< endl
;
2279 } else if (cmds
[0]=="get-meta") {
2280 UeberBackend
B("default");
2281 if (cmds
.size() < 2) {
2282 cerr
<< "Syntax: " << cmds
[0] << " zone [kind kind ..]" << endl
;
2285 DNSName
zone(cmds
[1]);
2286 vector
<string
> keys
;
2289 if (!B
.getDomainInfo(zone
, di
)) {
2290 cerr
<< "Invalid zone '" << zone
<< "'" << endl
;
2294 if (cmds
.size() > 2) {
2295 keys
.assign(cmds
.begin() + 2, cmds
.end());
2296 std::cout
<< "Metadata for '" << zone
<< "'" << endl
;
2297 for(const string kind
: keys
) {
2298 vector
<string
> meta
;
2300 if (B
.getDomainMetadata(zone
, kind
, meta
)) {
2301 cout
<< kind
<< " = " << boost::join(meta
, ", ") << endl
;
2305 std::map
<std::string
, std::vector
<std::string
> > meta
;
2306 std::cout
<< "Metadata for '" << zone
<< "'" << endl
;
2307 B
.getAllDomainMetadata(zone
, meta
);
2308 for(std::map
<std::string
, std::vector
<std::string
> >::const_iterator each_meta
= meta
.begin(); each_meta
!= meta
.end(); each_meta
++) {
2309 cout
<< each_meta
->first
<< " = " << boost::join(each_meta
->second
, ", ") << endl
;
2314 } else if (cmds
[0]=="set-meta") {
2315 UeberBackend
B("default");
2316 if (cmds
.size() < 3) {
2317 cerr
<< "Syntax: " << cmds
[0] << " zone kind [value value ..]" << endl
;
2320 DNSName
zone(cmds
[1]);
2321 string kind
= cmds
[2];
2322 vector
<string
> meta(cmds
.begin() + 3, cmds
.end());
2324 if (!B
.setDomainMetadata(zone
, kind
, meta
)) {
2325 cerr
<< "Unable to set meta for '" << zone
<< "'" << endl
;
2328 cout
<< "Set '" << zone
.toStringNoDot() << "' meta " << kind
<< " = " << boost::join(meta
, ", ") << endl
;
2330 } else if (cmds
[0]=="hsm") {
2332 UeberBackend
B("default");
2333 if (cmds
[1] == "assign") {
2334 DNSCryptoKeyEngine::storvector_t storvect
;
2336 std::vector
<DNSBackend::KeyData
> keys
;
2338 if (cmds
.size() < 9) {
2339 std::cout
<< "Usage: pdnsutil hsm assign ZONE ALGORITHM {ksk|zsk} MODULE TOKEN PIN LABEL" << std::endl
;
2343 DNSName
zone(cmds
[2]);
2346 if (!B
.getDomainInfo(zone
, di
)) {
2347 cerr
<< "Unable to assign module to unknown zone '" << zone
<< "'" << std::endl
;
2351 int algorithm
= shorthand2algorithm(cmds
[3]);
2353 cerr
<< "Unable to use unknown algorithm '" << cmds
[3] << "'" << std::endl
;
2358 bool keyOrZone
= (cmds
[4] == "ksk" ? true : false);
2359 string module
= cmds
[5];
2360 string slot
= cmds
[6];
2361 string pin
= cmds
[7];
2362 string label
= cmds
[8];
2364 std::ostringstream iscString
;
2365 iscString
<< "Private-key-format: v1.2" << std::endl
<<
2366 "Algorithm: " << algorithm
<< std::endl
<<
2367 "Engine: " << module
<< std::endl
<<
2368 "Slot: " << slot
<< std::endl
<<
2369 "PIN: " << pin
<< std::endl
<<
2370 "Label: " << label
<< std::endl
;
2372 DNSKEYRecordContent drc
;
2373 DNSSECPrivateKey dpk
;
2374 dpk
.d_flags
= (keyOrZone
? 257 : 256);
2375 dpk
.setKey(shared_ptr
<DNSCryptoKeyEngine
>(DNSCryptoKeyEngine::makeFromISCString(drc
, iscString
.str())));
2377 // make sure this key isn't being reused.
2378 B
.getDomainKeys(zone
, 0, keys
);
2381 for(DNSBackend::KeyData
& kd
: keys
) {
2382 if (kd
.content
== iscString
.str()) {
2383 // it's this one, I guess...
2390 cerr
<< "You have already assigned this key with ID=" << id
<< std::endl
;
2394 if (!(id
= dk
.addKey(zone
, dpk
))) {
2395 cerr
<< "Unable to assign module slot to zone" << std::endl
;
2399 // figure out key id.
2401 B
.getDomainKeys(zone
, 0, keys
);
2403 // validate which one got the key...
2404 for(DNSBackend::KeyData
& kd
: keys
) {
2405 if (kd
.content
== iscString
.str()) {
2406 // it's this one, I guess...
2412 cerr
<< "Module " << module
<< " slot " << slot
<< " assigned to " << zone
<< " with key id " << id
<< endl
;
2415 } else if (cmds
[1] == "create-key") {
2417 if (cmds
.size() < 4) {
2418 cerr
<< "Usage: pdnsutil hsm create-key ZONE KEY-ID [BITS]" << endl
;
2422 DNSName
zone(cmds
[2]);
2426 if (!B
.getDomainInfo(zone
, di
)) {
2427 cerr
<< "Unable to create key for unknown zone '" << zone
<< "'" << std::endl
;
2431 id
= pdns_stou(cmds
[3]);
2432 std::vector
<DNSBackend::KeyData
> keys
;
2433 if (!B
.getDomainKeys(zone
, 0, keys
)) {
2434 cerr
<< "No keys found for zone " << zone
<< std::endl
;
2438 DNSCryptoKeyEngine
*dke
= NULL
;
2439 // lookup correct key
2440 for(DNSBackend::KeyData
&kd
: keys
) {
2443 DNSKEYRecordContent dkrc
;
2444 dke
= DNSCryptoKeyEngine::makeFromISCString(dkrc
, kd
.content
);
2449 cerr
<< "Could not find key with ID " << id
<< endl
;
2452 if (cmds
.size() > 4) {
2453 bits
= pdns_stou(cmds
[4]);
2456 cerr
<< "Invalid bit size " << bits
<< "given, must be positive integer";
2461 } catch (PDNSException
& e
) {
2462 cerr
<< e
.reason
<< endl
;
2466 cerr
<< "Key of size " << bits
<< " created" << std::endl
;
2470 cerr
<<"PKCS#11 support not enabled"<<endl
;
2473 } else if (cmds
[0] == "b2b-migrate") {
2474 if (cmds
.size() < 3) {
2475 cerr
<<"Usage: b2b-migrate OLD NEW"<<endl
;
2479 DNSBackend
*src
,*tgt
;
2482 for(DNSBackend
*b
: BackendMakers().all()) {
2483 if (b
->getPrefix() == cmds
[1]) src
= b
;
2484 if (b
->getPrefix() == cmds
[2]) tgt
= b
;
2487 cerr
<<"Unknown source backend '"<<cmds
[1]<<"'"<<endl
;
2491 cerr
<<"Unknown target backend '"<<cmds
[2]<<"'"<<endl
;
2495 cout
<<"Moving zone(s) from "<<src
->getPrefix()<<" to "<<tgt
->getPrefix()<<endl
;
2497 vector
<DomainInfo
> domains
;
2499 tgt
->getAllDomains(&domains
, true);
2500 if (domains
.size()>0)
2501 throw PDNSException("Target backend has domain(s), please clean it first");
2503 src
->getAllDomains(&domains
, true);
2505 for(const DomainInfo
& di
: domains
) {
2507 DNSResourceRecord rr
;
2508 cout
<<"Processing '"<<di
.zone
.toString()<<"'"<<endl
;
2510 if (!tgt
->createDomain(di
.zone
)) throw PDNSException("Failed to create zone");
2511 tgt
->setKind(di
.zone
, di
.kind
);
2512 tgt
->setAccount(di
.zone
,di
.account
);
2513 for(const string
& master
: di
.masters
) {
2514 tgt
->setMaster(di
.zone
, master
);
2517 if (!src
->list(di
.zone
, di
.id
, true)) throw PDNSException("Failed to list records");
2519 while(src
->get(rr
)) {
2520 if (!tgt
->feedRecord(rr
)) throw PDNSException("Failed to feed record");
2525 if (src
->listComments(di
.id
)) {
2527 while(src
->getComment(c
)) {
2528 tgt
->feedComment(c
);
2534 std::map
<std::string
, std::vector
<std::string
> > meta
;
2535 if (src
->getAllDomainMetadata(di
.zone
, meta
)) {
2536 std::map
<std::string
, std::vector
<std::string
> >::iterator i
;
2537 for(i
=meta
.begin(); i
!= meta
.end(); i
++) {
2538 if (!tgt
->setDomainMetadata(di
.zone
, i
->first
, i
->second
)) throw PDNSException("Failed to feed domain metadata");
2544 std::vector
<DNSBackend::KeyData
> keys
;
2545 if (src
->getDomainKeys(di
.zone
, 0, keys
)) {
2546 for(const DNSBackend::KeyData
& k
: keys
) {
2547 tgt
->addDomainKey(di
.zone
, k
);
2551 cout
<<"Moved "<<nr
<<" record(s), "<<nc
<<" comment(s), "<<nm
<<" metadata(s) and "<<nk
<<" cryptokey(s)"<<endl
;
2556 std::vector
<struct TSIGKey
> tkeys
;
2557 if (src
->getTSIGKeys(tkeys
)) {
2558 for(const struct TSIGKey
& tk
: tkeys
) {
2559 if (!tgt
->setTSIGKey(tk
.name
, tk
.algorithm
, tk
.key
)) throw PDNSException("Failed to feed TSIG key");
2563 cout
<<"Moved "<<ntk
<<" TSIG key(s)"<<endl
;
2565 cout
<<"Remember to drop the old backend and run rectify-all-zones"<<endl
;
2568 } else if (cmds
[0] == "backend-cmd") {
2569 if (cmds
.size() < 3) {
2570 cerr
<<"Usage: backend-cmd BACKEND CMD [CMD..]"<<endl
;
2577 for(DNSBackend
*b
: BackendMakers().all()) {
2578 if (b
->getPrefix() == cmds
[1]) db
= b
;
2582 cerr
<<"Unknown backend '"<<cmds
[1]<<"'"<<endl
;
2586 for(auto i
=next(begin(cmds
),2); i
!= end(cmds
); ++i
) {
2587 cerr
<<"== "<<*i
<<endl
;
2588 cout
<<db
->directBackendCmd(*i
);
2593 cerr
<<"Unknown command '"<<cmds
[0] <<"'"<< endl
;
2598 catch(PDNSException
& ae
) {
2599 cerr
<<"Error: "<<ae
.reason
<<endl
;
2602 catch(std::exception
& e
) {
2603 cerr
<<"Error: "<<e
.what()<<endl
;
2608 cerr
<<"Caught an unknown exception"<<endl
;