5 #include "dnsseckeeper.hh"
6 #include "dnssecinfra.hh"
11 #include <boost/program_options.hpp>
12 #include <boost/assign/std/vector.hpp>
13 #include <boost/assign/list_of.hpp>
14 #include "dnsbackend.hh"
15 #include "ueberbackend.hh"
16 #include "arguments.hh"
17 #include "auth-packetcache.hh"
18 #include "auth-querycache.hh"
19 #include "zoneparser-tng.hh"
20 #include "signingpipe.hh"
21 #include "dns_random.hh"
23 #include <termios.h> //termios, TCSANOW, ECHO, ICANON
24 #include "opensslsigners.hh"
29 #include "ssqlite3.hh"
30 #include "bind-dnssec.schema.sqlite3.sql.h"
37 namespace po
= boost::program_options
;
38 po::variables_map g_vm
;
40 string s_programname
="pdns";
52 string
humanTime(time_t t
)
57 strftime(ret
, sizeof(ret
)-1, "%c", &tm
); // %h:%M %Y-%m-%d
61 void loadMainConfig(const std::string
& configdir
)
63 ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=configdir
;
64 ::arg().set("default-ttl","Seconds a result is valid if not set otherwise")="3600";
65 ::arg().set("launch","Which backends to launch");
66 ::arg().set("dnssec","if we should do dnssec")="true";
67 ::arg().set("config-name","Name of this virtual configuration - will rename the binary image")=g_vm
["config-name"].as
<string
>();
68 ::arg().setCmd("help","Provide a helpful message");
69 //::arg().laxParse(argc,argv);
71 if(::arg().mustDo("help")) {
72 cout
<<"syntax:"<<endl
<<endl
;
73 cout
<<::arg().helpstring(::arg()["help"])<<endl
;
77 if(::arg()["config-name"]!="")
78 s_programname
+="-"+::arg()["config-name"];
80 string configname
=::arg()["config-dir"]+"/"+s_programname
+".conf";
81 cleanSlashes(configname
);
83 ::arg().set("default-ksk-algorithm","Default KSK algorithm")="ecdsa256";
84 ::arg().set("default-ksk-size","Default KSK size (0 means default)")="0";
85 ::arg().set("default-zsk-algorithm","Default ZSK algorithm")="";
86 ::arg().set("default-zsk-size","Default ZSK size (0 means default)")="0";
87 ::arg().set("default-soa-edit","Default SOA-EDIT value")="";
88 ::arg().set("default-soa-edit-signed","Default SOA-EDIT value for signed zones")="";
89 ::arg().set("max-ent-entries", "Maximum number of empty non-terminals in a zone")="100000";
90 ::arg().set("module-dir","Default directory for modules")=PKGLIBDIR
;
91 ::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom";
92 ::arg().setSwitch("query-logging","Hint backends that queries should be logged")="no";
93 ::arg().set("loglevel","Amount of logging. Higher is more.")="3";
94 ::arg().setSwitch("direct-dnskey","Fetch DNSKEY RRs from backend during DNSKEY synthesis")="no";
95 ::arg().set("max-nsec3-iterations","Limit the number of NSEC3 hash iterations")="500"; // RFC5155 10.3
96 ::arg().set("max-signature-cache-entries", "Maximum number of signatures cache entries")="";
97 ::arg().laxFile(configname
.c_str());
99 L
.toConsole(Logger::Error
); // so we print any errors
100 BackendMakers().launch(::arg()["launch"]); // vrooooom!
101 if(::arg().asNum("loglevel") >= 3) // so you can't kill our errors
102 L
.toConsole((Logger::Urgency
)::arg().asNum("loglevel"));
104 //cerr<<"Backend: "<<::arg()["launch"]<<", '" << ::arg()["gmysql-dbname"] <<"'" <<endl;
106 S
.declare("qsize-q","Number of questions waiting for database attention");
108 ::arg().set("max-cache-entries", "Maximum number of cache entries")="1000000";
109 ::arg().set("cache-ttl","Seconds to store packets in the PacketCache")="20";
110 ::arg().set("negquery-cache-ttl","Seconds to store negative query results in the QueryCache")="60";
111 ::arg().set("query-cache-ttl","Seconds to store query results in the QueryCache")="20";
112 ::arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server";
113 ::arg().set("default-soa-mail","mail address to insert in the SOA record if none set in the backend")="";
114 ::arg().set("soa-refresh-default","Default SOA refresh")="10800";
115 ::arg().set("soa-retry-default","Default SOA retry")="3600";
116 ::arg().set("soa-expire-default","Default SOA expire")="604800";
117 ::arg().set("soa-minimum-ttl","Default SOA minimum ttl")="3600";
118 ::arg().set("chroot","Switch to this chroot jail")="";
119 ::arg().set("dnssec-key-cache-ttl","Seconds to cache DNSSEC keys from the database")="30";
120 ::arg().set("domain-metadata-cache-ttl","Seconds to cache domain metadata from the database")="60";
122 // Keep this line below all ::arg().set() statements
123 if (! ::arg().laxFile(configname
.c_str()))
124 cerr
<<"Warning: unable to read configuration file '"<<configname
<<"'."<<endl
;
126 seedRandom(::arg()["entropy-source"]);
128 if (!::arg()["chroot"].empty()) {
129 if (chroot(::arg()["chroot"].c_str())<0 || chdir("/") < 0) {
130 cerr
<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror (errno
)<<endl
;
138 bool rectifyZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
142 bool ret
= dk
.rectifyZone(zone
, error
, output
, true);
143 if (!output
.empty()) {
146 if (!ret
&& !error
.empty()) {
152 void dbBench(const std::string
& fname
)
154 ::arg().set("query-cache-ttl")="0";
155 ::arg().set("negquery-cache-ttl")="0";
156 UeberBackend
B("default");
158 vector
<string
> domains
;
160 ifstream
ifs(fname
.c_str());
162 cerr
<<"Could not open '"<<fname
<<"' for reading domain names to query"<<endl
;
165 while(getline(ifs
,line
)) {
167 domains
.push_back(line
);
171 domains
.push_back("powerdns.com");
177 unsigned int hits
=0, misses
=0;
178 for(; n
< 10000; ++n
) {
179 DNSName
domain(domains
[random() % domains
.size()]);
180 B
.lookup(QType(QType::NS
), domain
);
184 B
.lookup(QType(QType::A
), DNSName(std::to_string(random()))+domain
);
190 cout
<<0.001*dt
.udiff()/n
<<" millisecond/lookup"<<endl
;
191 cout
<<"Retrieved "<<hits
<<" records, did "<<misses
<<" queries which should have no match"<<endl
;
192 cout
<<"Packet cache reports: "<<S
.read("query-cache-hit")<<" hits (should be 0) and "<<S
.read("query-cache-miss") <<" misses"<<endl
;
195 void rectifyAllZones(DNSSECKeeper
&dk
)
197 UeberBackend
B("default");
198 vector
<DomainInfo
> domainInfo
;
200 B
.getAllDomains(&domainInfo
);
201 for(DomainInfo di
: domainInfo
) {
202 cerr
<<"Rectifying "<<di
.zone
<<": ";
203 rectifyZone(dk
, di
.zone
);
205 cout
<<"Rectified "<<domainInfo
.size()<<" zones."<<endl
;
208 int checkZone(DNSSECKeeper
&dk
, UeberBackend
&B
, const DNSName
& zone
, const vector
<DNSResourceRecord
>* suppliedrecords
=0)
211 if(!B
.getSOAUncached(zone
, sd
)) {
212 cout
<<"[error] No SOA record present, or active, in zone '"<<zone
<<"'"<<endl
;
213 cout
<<"Checked 0 records of '"<<zone
<<"', 1 errors, 0 warnings."<<endl
;
217 NSEC3PARAMRecordContent ns3pr
;
219 bool haveNSEC3
= dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
220 bool isOptOut
=(haveNSEC3
&& ns3pr
.d_flags
);
222 bool isSecure
=dk
.isSecuredZone(zone
);
223 bool presigned
=dk
.isPresigned(zone
);
224 bool validKeys
=dk
.checkKeys(zone
);
226 uint64_t numrecords
=0, numerrors
=0, numwarnings
=0;
229 if(isSecure
&& zone
.wirelength() > 222) {
231 cout
<<"[Error] zone '" << zone
<< "' 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
;
234 vector
<DNSBackend::KeyData
> dbkeyset
;
235 B
.getDomainKeys(zone
, dbkeyset
);
237 for(DNSBackend::KeyData
& kd
: dbkeyset
) {
238 DNSKEYRecordContent dkrc
;
239 shared_ptr
<DNSCryptoKeyEngine
>(DNSCryptoKeyEngine::makeFromISCString(dkrc
, kd
.content
));
241 if(dkrc
.d_algorithm
== 5) {
242 cout
<<"[Warning] zone '"<<zone
<<"' has NSEC3 semantics, but the "<< (kd
.active
? "" : "in" ) <<"active key with id "<<kd
.id
<<" has 'Algorithm: 5'. This should be corrected to 'Algorithm: 7' in the database (or NSEC3 should be disabled)."<<endl
;
250 cout
<<"[Error] zone '" << zone
<< "' has at least one invalid DNS Private Key." << endl
;
253 // Check for delegation in parent zone
254 DNSName
parent(zone
);
255 while(parent
.chopOff()) {
257 if(B
.getSOAUncached(parent
, sd_p
)) {
260 B
.lookup(QType(QType::ANY
), zone
, NULL
, sd_p
.domain_id
);
262 ns
|= (zr
.dr
.d_type
== QType::NS
);
264 cout
<<"[Error] No delegation for zone '"<<zone
<<"' in parent '"<<parent
<<"'"<<endl
;
272 bool hasNsAtApex
= false;
273 set
<DNSName
> tlsas
, cnames
, noncnames
, glue
, checkglue
;
274 set
<pair
<DNSName
, QType
> > recs
, checkOcclusion
;
275 set
<string
> recordcontents
;
276 map
<string
, unsigned int> ttl
;
278 ostringstream content
;
279 pair
<map
<string
, unsigned int>::iterator
,bool> ret
;
281 vector
<DNSResourceRecord
> records
;
282 if(!suppliedrecords
) {
283 DNSResourceRecord drr
;
284 sd
.db
->list(zone
, sd
.domain_id
, g_verbose
);
285 while(sd
.db
->get(drr
)) {
286 records
.push_back(drr
);
290 records
=*suppliedrecords
;
292 for(auto rr
: records
) { // we modify this
293 if(!rr
.qtype
.getCode())
298 if(rr
.qtype
.getCode() == QType::TLSA
)
299 tlsas
.insert(rr
.qname
);
300 if(rr
.qtype
.getCode() == QType::SOA
) {
302 stringtok(parts
, rr
.content
);
306 for(int pleft
=parts
.size(); pleft
< 7; ++pleft
) {
312 if(rr
.qtype
.getCode() == QType::TXT
&& !rr
.content
.empty() && rr
.content
[0]!='"')
313 rr
.content
= "\""+rr
.content
+"\"";
316 shared_ptr
<DNSRecordContent
> drc(DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, rr
.content
));
317 string tmp
=drc
->serialize(rr
.qname
);
318 tmp
= drc
->getZoneRepresentation(true);
319 if (rr
.qtype
.getCode() != QType::AAAA
) {
320 if (!pdns_iequals(tmp
, rr
.content
)) {
321 if(rr
.qtype
.getCode() == QType::SOA
) {
322 tmp
= drc
->getZoneRepresentation(false);
324 if(!pdns_iequals(tmp
, rr
.content
)) {
325 cout
<<"[Warning] Parsed and original record content are not equal: "<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<< " '" << rr
.content
<<"' (Content parsed as '"<<tmp
<<"')"<<endl
;
330 struct in6_addr tmpbuf
;
331 if (inet_pton(AF_INET6
, rr
.content
.c_str(), &tmpbuf
) != 1 || rr
.content
.find('.') != string::npos
) {
332 cout
<<"[Warning] Following record is not a valid IPv6 address: "<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<< " '" << rr
.content
<<"'"<<endl
;
337 catch(std::exception
& e
)
339 cout
<<"[Error] Following record had a problem: \""<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"\""<<endl
;
340 cout
<<"[Error] Error was: "<<e
.what()<<endl
;
345 if(!rr
.qname
.isPartOf(zone
)) {
346 cout
<<"[Error] Record '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
<<"' is out-of-zone."<<endl
;
352 content
<<rr
.qname
<<" "<<rr
.qtype
.getName()<<" "<<rr
.content
;
353 if (recordcontents
.count(toLower(content
.str()))) {
354 cout
<<"[Error] Duplicate record found in rrset: '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"'"<<endl
;
358 recordcontents
.insert(toLower(content
.str()));
361 content
<<rr
.qname
<<" "<<rr
.qtype
.getName();
362 if (rr
.qtype
.getCode() == QType::RRSIG
) {
363 RRSIGRecordContent
rrc(rr
.content
);
364 content
<<" ("<<DNSRecordContent::NumberToType(rrc
.d_type
)<<")";
366 ret
= ttl
.insert(pair
<string
, unsigned int>(toLower(content
.str()), rr
.ttl
));
367 if (ret
.second
== false && ret
.first
->second
!= rr
.ttl
) {
368 cout
<<"[Error] TTL mismatch in rrset: '"<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<<" "<<rr
.content
<<"' ("<<ret
.first
->second
<<" != "<<rr
.ttl
<<")"<<endl
;
373 if (isSecure
&& isOptOut
&& (rr
.qname
.countLabels() && rr
.qname
.getRawLabels()[0] == "*")) {
374 cout
<<"[Warning] wildcard record '"<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<<" "<<rr
.content
<<"' is insecure"<<endl
;
375 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
<<endl
;
380 if (rr
.qtype
.getCode() == QType::NS
) {
382 } else if (rr
.qtype
.getCode() == QType::DS
) {
383 cout
<<"[Warning] DS at apex in zone '"<<zone
<<"', should not be here."<<endl
;
387 if (rr
.qtype
.getCode() == QType::SOA
) {
388 cout
<<"[Error] SOA record not at apex '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
<<"'"<<endl
;
391 } else if (rr
.qtype
.getCode() == QType::DNSKEY
) {
392 cout
<<"[Warning] DNSKEY record not at apex '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
<<"', should not be here."<<endl
;
394 } else if (rr
.qtype
.getCode() == QType::NS
) {
395 if (DNSName(rr
.content
).isPartOf(rr
.qname
)) {
396 checkglue
.insert(DNSName(toLower(rr
.content
)));
398 checkOcclusion
.insert({rr
.qname
, rr
.qtype
});
399 } else if (rr
.qtype
.getCode() == QType::A
|| rr
.qtype
.getCode() == QType::AAAA
) {
400 glue
.insert(rr
.qname
);
401 } else if (rr
.qtype
== QType::DNAME
) {
402 checkOcclusion
.insert({rr
.qname
, rr
.qtype
});
405 if (rr
.qtype
!= QType::NS
&& rr
.qtype
!= QType::DS
&& rr
.qtype
!= QType::DNAME
) {
406 recs
.insert({rr
.qname
, rr
.qtype
});
410 if((rr
.qtype
.getCode() == QType::A
|| rr
.qtype
.getCode() == QType::AAAA
) && !rr
.qname
.isWildcard() && !rr
.qname
.isHostname())
411 cout
<<"[Info] "<<rr
.qname
.toString()<<" record for '"<<rr
.qtype
.getName()<<"' is not a valid hostname."<<endl
;
413 // Check if the DNSNames that should be hostnames, are hostnames
414 if (rr
.qtype
.getCode() == QType::NS
|| rr
.qtype
.getCode() == QType::MX
|| rr
.qtype
.getCode() == QType::SRV
) {
416 if (rr
.qtype
.getCode() == QType::SRV
) {
417 vector
<string
> parts
;
418 stringtok(parts
, rr
.getZoneRepresentation());
419 if (parts
.size() == 4) toCheck
= DNSName(parts
[3]);
420 } else if (rr
.qtype
.getCode() == QType::MX
) {
421 vector
<string
> parts
;
422 stringtok(parts
, rr
.getZoneRepresentation());
423 if (parts
.size() == 2) toCheck
= DNSName(parts
[1]);
425 toCheck
= DNSName(rr
.content
);
429 cout
<<"[Warning] "<<rr
.qtype
.getName()<<" record in zone '"<<zone
<<"': unable to extract hostname from content."<<endl
;
430 else if(!toCheck
.isHostname()) {
431 cout
<<"[Warning] "<<rr
.qtype
.getName()<<" record in zone '"<<zone
<<"' has non-hostname content '"<<toCheck
.toString()<<"'."<<endl
;
436 if (rr
.qtype
.getCode() == QType::CNAME
) {
437 if (!cnames
.count(rr
.qname
))
438 cnames
.insert(rr
.qname
);
440 cout
<<"[Error] Duplicate CNAME found at '"<<rr
.qname
<<"'"<<endl
;
445 if (rr
.qtype
.getCode() == QType::RRSIG
) {
447 cout
<<"[Error] RRSIG found at '"<<rr
.qname
<<"' in non-presigned zone. These do not belong in the database."<<endl
;
452 noncnames
.insert(rr
.qname
);
455 if(rr
.qtype
.getCode() == QType::NSEC
|| rr
.qtype
.getCode() == QType::NSEC3
)
457 cout
<<"[Error] NSEC or NSEC3 found at '"<<rr
.qname
<<"'. These do not belong in the database."<<endl
;
462 if(!presigned
&& rr
.qtype
.getCode() == QType::DNSKEY
)
464 if(::arg().mustDo("direct-dnskey"))
466 if(rr
.ttl
!= sd
.default_ttl
)
468 cout
<<"[Warning] DNSKEY TTL of "<<rr
.ttl
<<" at '"<<rr
.qname
<<"' differs from SOA minimum of "<<sd
.default_ttl
<<endl
;
474 cout
<<"[Warning] DNSKEY at '"<<rr
.qname
<<"' in non-presigned zone will mostly be ignored and can cause problems."<<endl
;
479 if(!suppliedrecords
&& rr
.auth
== 0 && rr
.qtype
.getCode()!=QType::NS
&& rr
.qtype
.getCode()!=QType::A
&& rr
.qtype
.getCode()!=QType::AAAA
)
481 cout
<<"[Error] Following record is auth=0, run pdnsutil rectify-zone?: "<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<< " " << rr
.content
<<endl
;
486 for(auto &i
: cnames
) {
487 if (noncnames
.find(i
) != noncnames
.end()) {
488 cout
<<"[Error] CNAME "<<i
<<" found, but other records with same label exist."<<endl
;
493 for(const auto &i
: tlsas
) {
494 DNSName name
= DNSName(i
);
495 name
.trimToLabels(name
.countLabels()-2);
496 if (cnames
.find(name
) == cnames
.end() && noncnames
.find(name
) == noncnames
.end()) {
497 // No specific record for the name in the TLSA record exists, this
498 // is already worth emitting a warning. Let's see if a wildcard exist.
500 DNSName
wcname(name
);
502 wcname
.prependRawLabel("*");
503 if (cnames
.find(wcname
) != cnames
.end() || noncnames
.find(wcname
) != noncnames
.end()) {
504 cout
<<"A wildcard record exist for '"<<wcname
<<"' and a TLSA record for '"<<i
<<"'.";
506 cout
<<"No record for '"<<name
<<"' exists, but a TLSA record for '"<<i
<<"' does.";
509 cout
<<" A query for '"<<name
<<"' will yield an empty response. This is most likely a mistake, please create records for '"<<name
<<"'."<<endl
;
514 cout
<<"[Error] No NS record at zone apex in zone '"<<zone
<<"'"<<endl
;
518 for(const auto &qname
: checkglue
) {
519 if (!glue
.count(qname
)) {
520 cout
<<"[Warning] Missing glue for '"<<qname
<<"' in zone '"<<zone
<<"'"<<endl
;
525 for(const auto &qname
: checkOcclusion
) {
526 for (const auto &q
: recs
) {
527 if (q
.first
.isPartOf(qname
.first
) && !checkglue
.count(q
.first
)) {
528 cout
<<"[Warning] '"<<q
.first
<<"|"<<q
.second
.getName()<<"' in zone '"<<zone
<<"' is occluded by a ";
529 if (qname
.second
== QType::NS
) {
532 if (qname
.second
== QType::DNAME
) {
535 cout
<<" at '"<<qname
.first
<<"'"<<endl
;
541 cout
<<"Checked "<<numrecords
<<" records of '"<<zone
<<"', "<<numerrors
<<" errors, "<<numwarnings
<<" warnings."<<endl
;
547 int checkAllZones(DNSSECKeeper
&dk
, bool exitOnError
)
549 UeberBackend
B("default");
550 vector
<DomainInfo
> domainInfo
;
552 B
.getAllDomains(&domainInfo
, true);
554 for(auto di
: domainInfo
) {
555 if (checkZone(dk
, B
, di
.zone
) > 0) {
561 cout
<<"Checked "<<domainInfo
.size()<<" zones, "<<errors
<<" had errors."<<endl
;
567 int increaseSerial(const DNSName
& zone
, DNSSECKeeper
&dk
)
569 UeberBackend
B("default");
571 if(!B
.getSOAUncached(zone
, sd
)) {
572 cerr
<<"No SOA for zone '"<<zone
<<"'"<<endl
;
576 if (dk
.isPresigned(zone
)) {
577 cerr
<<"Serial increase of presigned zone '"<<zone
<<"' is not allowed."<<endl
;
582 dk
.getSoaEdit(zone
, soaEditKind
);
584 sd
.db
->lookup(QType(QType::SOA
), zone
);
585 vector
<DNSResourceRecord
> rrs
;
586 DNSResourceRecord rr
;
588 while (sd
.db
->get(rr
)) {
589 if (rr
.qtype
.getCode() == QType::SOA
) {
591 szr
.dr
=DNSRecord(rr
) ;
595 if (rrs
.size() > 1) {
596 cerr
<<rrs
.size()<<" SOA records found for "<<zone
<<"!"<<endl
;
599 if (rrs
.size() < 1) {
600 cerr
<<zone
<<" not found!"<<endl
;
603 if (soaEditKind
.empty()) {
606 else if(pdns_iequals(soaEditKind
,"INCREMENT-WEEKS")) {
609 else if(pdns_iequals(soaEditKind
,"INCEPTION-INCREMENT")) {
610 uint32_t today_serial
= localtime_format_YYYYMMDDSS(time(NULL
), 1);
612 if (sd
.serial
< today_serial
) {
613 sd
.serial
= today_serial
;
620 sd
.serial
= calculateEditSOA(szr
, soaEditKind
) + 1;
622 rrs
[0].content
= serializeSOAData(sd
);
624 sd
.db
->startTransaction(zone
, -1);
626 if (! sd
.db
->replaceRRSet(sd
.domain_id
, zone
, rr
.qtype
, rrs
)) {
627 sd
.db
->abortTransaction();
628 cerr
<<"Backend did not replace SOA record. Backend might not support this operation."<<endl
;
632 if (sd
.db
->doesDNSSEC()) {
633 NSEC3PARAMRecordContent ns3pr
;
635 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
640 ordername
=DNSName(toBase32Hex(hashQNameWithSalt(ns3pr
, zone
))) + zone
;
644 cerr
<<"'"<<rrs
[0].qname
<<"' -> '"<< ordername
<<"'"<<endl
;
645 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, rrs
[0].qname
, ordername
, true);
648 sd
.db
->commitTransaction();
650 cout
<<"SOA serial for zone "<<zone
<<" set to "<<sd
.serial
<<endl
;
654 int deleteZone(const DNSName
&zone
) {
657 if (! B
.getDomainInfo(zone
, di
)) {
658 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
662 if(di
.backend
->deleteDomain(zone
))
665 cerr
<<"Failed to delete domain '"<<zone
<<"'"<<endl
;;
669 void listKey(DomainInfo
const &di
, DNSSECKeeper
& dk
, bool printHeader
= true) {
671 cout
<<"Zone Type Size Algorithm ID Location Keytag"<<endl
;
672 cout
<<"----------------------------------------------------------------------------------"<<endl
;
674 unsigned int spacelen
= 0;
675 for (auto const &key
: dk
.getKeys(di
.zone
)) {
677 if (di
.zone
.toStringNoDot().length() > 29)
678 cout
<<endl
<<string(30, ' ');
680 cout
<<string(30 - di
.zone
.toStringNoDot().length(), ' ');
682 cout
<<DNSSECKeeper::keyTypeToString(key
.second
.keyType
)<<" ";
684 spacelen
= (std::to_string(key
.first
.getKey()->getBits()).length() >= 8) ? 1 : 8 - std::to_string(key
.first
.getKey()->getBits()).length();
685 if (key
.first
.getKey()->getBits() < 1) {
686 cout
<<"invalid "<<endl
;
689 cout
<<key
.first
.getKey()->getBits()<<string(spacelen
, ' ');
692 string algname
= DNSSECKeeper::algorithm2name(key
.first
.d_algorithm
);
693 spacelen
= (algname
.length() >= 13) ? 1 : 13 - algname
.length();
694 cout
<<algname
<<string(spacelen
, ' ');
696 spacelen
= (std::to_string(key
.second
.id
).length() > 5) ? 1 : 5 - std::to_string(key
.second
.id
).length();
697 cout
<<key
.second
.id
<<string(spacelen
, ' ');
700 auto stormap
= key
.first
.getKey()->convertToISCVector();
701 string engine
, slot
, label
= "";
702 for (auto const &elem
: stormap
) {
703 //cout<<elem.first<<" "<<elem.second<<endl;
704 if (elem
.first
== "Engine")
705 engine
= elem
.second
;
706 if (elem
.first
== "Slot")
708 if (elem
.first
== "Label")
711 if (engine
.empty() || slot
.empty()){
714 spacelen
= (engine
.length()+slot
.length()+label
.length()+2 >= 12) ? 1 : 12 - engine
.length()-slot
.length()-label
.length()-2;
715 cout
<<engine
<<","<<slot
<<","<<label
<<string(spacelen
, ' ');
720 cout
<<key
.first
.getDNSKEY().getTag()<<endl
;
724 int listKeys(const string
&zname
, DNSSECKeeper
& dk
){
725 UeberBackend
B("default");
727 if (zname
!= "all") {
729 if(!B
.getDomainInfo(DNSName(zname
), di
)) {
730 cerr
<< "Zone "<<zname
<<" not found."<<endl
;
735 vector
<DomainInfo
> domainInfo
;
736 B
.getAllDomains(&domainInfo
);
737 bool printHeader
= true;
738 for (auto const di
: domainInfo
) {
739 listKey(di
, dk
, printHeader
);
746 int listZone(const DNSName
&zone
) {
750 if (! B
.getDomainInfo(zone
, di
)) {
751 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
754 di
.backend
->list(zone
, di
.id
);
755 DNSResourceRecord rr
;
756 cout
<<"$ORIGIN ."<<endl
;
757 while(di
.backend
->get(rr
)) {
758 if(rr
.qtype
.getCode()) {
759 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] != '.')
760 rr
.content
.append(1, '.');
762 cout
<<rr
.qname
<<"\t"<<rr
.ttl
<<"\tIN\t"<<rr
.qtype
.getName()<<"\t"<<rr
.content
<<endl
;
768 // lovingly copied from http://stackoverflow.com/questions/1798511/how-to-avoid-press-enter-with-any-getchar
771 static struct termios oldt
, newt
;
773 /*tcgetattr gets the parameters of the current terminal
774 STDIN_FILENO will tell tcgetattr that it should write the settings
776 tcgetattr( STDIN_FILENO
, &oldt
);
777 /*now the settings will be copied*/
780 /*ICANON normally takes care that one line at a time will be processed
781 that means it will return if it sees a "\n" or an EOF or an EOL*/
782 newt
.c_lflag
&= ~(ICANON
);
784 /*Those new settings will be set to STDIN
785 TCSANOW tells tcsetattr to change attributes immediately. */
786 tcsetattr( STDIN_FILENO
, TCSANOW
, &newt
);
790 /*restore the old settings*/
791 tcsetattr( STDIN_FILENO
, TCSANOW
, &oldt
);
796 int clearZone(DNSSECKeeper
& dk
, const DNSName
&zone
) {
800 if (! B
.getDomainInfo(zone
, di
)) {
801 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
804 if(!di
.backend
->startTransaction(zone
, di
.id
)) {
805 cerr
<<"Unable to start transaction for load of zone '"<<zone
<<"'"<<endl
;
808 di
.backend
->commitTransaction();
812 int editZone(DNSSECKeeper
& dk
, const DNSName
&zone
) {
816 if (! B
.getDomainInfo(zone
, di
)) {
817 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
820 vector
<DNSRecord
> pre
, post
;
821 char tmpnam
[]="/tmp/pdnsutil-XXXXXX";
822 int tmpfd
=mkstemp(tmpnam
);
824 unixDie("Making temporary filename in "+string(tmpnam
));
826 ~deleteme() { unlink(d_name
.c_str()); }
827 deleteme(string name
) : d_name(name
) {}
831 vector
<DNSResourceRecord
> checkrr
;
833 string editor
="editor";
834 if(auto e
=getenv("EDITOR")) // <3
838 di
.backend
->list(zone
, di
.id
);
839 pre
.clear(); post
.clear();
841 if(tmpfd
< 0 && (tmpfd
=open(tmpnam
, O_WRONLY
| O_TRUNC
, 0600)) < 0)
842 unixDie("Error reopening temporary file "+string(tmpnam
));
843 string
header("; Warning - every name in this file is ABSOLUTE!\n$ORIGIN .\n");
844 if(write(tmpfd
, header
.c_str(), header
.length()) < 0)
845 unixDie("Writing zone to temporary file");
846 DNSResourceRecord rr
;
847 while(di
.backend
->get(rr
)) {
848 if(!rr
.qtype
.getCode())
853 sort(pre
.begin(), pre
.end(), DNSRecord::prettyCompare
);
854 for(const auto& dr
: pre
) {
856 os
<<dr
.d_name
<<"\t"<<dr
.d_ttl
<<"\tIN\t"<<DNSRecordContent::NumberToType(dr
.d_type
)<<"\t"<<dr
.d_content
->getZoneRepresentation(true)<<endl
;
857 if(write(tmpfd
, os
.str().c_str(), os
.str().length()) < 0)
858 unixDie("Writing zone to temporary file");
866 cmdline
+="+"+std::to_string(gotoline
)+" ";
868 int err
=system(cmdline
.c_str());
870 unixDie("Editing file with: '"+cmdline
+"', perhaps set EDITOR variable");
873 ZoneParserTNG
zpt(tmpnam
, g_rootdnsname
);
874 DNSResourceRecord zrr
;
875 map
<pair
<DNSName
,uint16_t>, vector
<DNSRecord
> > grouped
;
876 while(zpt
.get(zrr
)) {
880 grouped
[{dr
.d_name
,dr
.d_type
}].push_back(dr
);
882 catch(std::exception
& e
) {
883 cerr
<<"Problem "<<e
.what()<<" "<<zpt
.getLineOfFile()<<endl
;
884 auto fnum
= zpt
.getLineNumAndFile();
885 gotoline
= fnum
.second
;
889 sort(post
.begin(), post
.end(), DNSRecord::prettyCompare
);
892 for(const DNSRecord
& rr
: post
) {
893 DNSResourceRecord drr
= DNSResourceRecord::fromWire(rr
);
894 drr
.domain_id
= di
.id
;
895 checkrr
.push_back(drr
);
897 if(checkZone(dk
, B
, zone
, &checkrr
)) {
899 cerr
<<"\x1b[31;1mThere was a problem with your zone\x1b[0m\nOptions are: (e)dit your changes, (r)etry with original zone, (a)pply change anyhow, (q)uit: "<<endl
;
915 vector
<DNSRecord
> diff
;
917 map
<pair
<DNSName
,uint16_t>, string
> changed
;
918 set_difference(pre
.cbegin(), pre
.cend(), post
.cbegin(), post
.cend(), back_inserter(diff
), DNSRecord::prettyCompare
);
919 for(const auto& d
: diff
) {
921 str
<<'-'<< d
.d_name
<<" "<<d
.d_ttl
<<" IN "<<DNSRecordContent::NumberToType(d
.d_type
)<<" "<<d
.d_content
->getZoneRepresentation(true)<<endl
;
922 changed
[{d
.d_name
,d
.d_type
}] += str
.str();
926 set_difference(post
.cbegin(), post
.cend(), pre
.cbegin(), pre
.cend(), back_inserter(diff
), DNSRecord::prettyCompare
);
927 for(const auto& d
: diff
) {
930 str
<<'+'<< d
.d_name
<<" "<<d
.d_ttl
<<" IN "<<DNSRecordContent::NumberToType(d
.d_type
)<<" "<<d
.d_content
->getZoneRepresentation(true)<<endl
;
931 changed
[{d
.d_name
,d
.d_type
}]+=str
.str();
933 if (changed
.size() > 0)
934 cout
<<"Detected the following changes:"<<endl
;
935 for(const auto& c
: changed
) {
939 if(changed
.empty()) {
940 cout
<<endl
<<"No changes to apply."<<endl
;
941 return(EXIT_SUCCESS
);
943 cout
<<endl
<<"(a)pply these changes, (e)dit again, (r)etry with original zone, (q)uit: ";
948 return(EXIT_SUCCESS
);
953 else if(changed
.empty() || c
!='a')
956 for(const auto& change
: changed
) {
957 vector
<DNSResourceRecord
> vrr
;
958 for(const DNSRecord
& rr
: grouped
[change
.first
]) {
959 DNSResourceRecord crr
= DNSResourceRecord::fromWire(rr
);
960 crr
.domain_id
= di
.id
;
963 di
.backend
->replaceRRSet(di
.id
, change
.first
.first
, QType(change
.first
.second
), vrr
);
965 rectifyZone(dk
, zone
);
970 int loadZone(DNSName zone
, const string
& fname
) {
974 if (B
.getDomainInfo(zone
, di
)) {
975 cerr
<<"Domain '"<<zone
<<"' exists already, replacing contents"<<endl
;
978 cerr
<<"Creating '"<<zone
<<"'"<<endl
;
979 B
.createDomain(zone
);
981 if(!B
.getDomainInfo(zone
, di
)) {
982 cerr
<<"Domain '"<<zone
<<"' was not created - perhaps backend ("<<::arg()["launch"]<<") does not support storing new zones."<<endl
;
986 DNSBackend
* db
= di
.backend
;
987 ZoneParserTNG
zpt(fname
, zone
);
989 DNSResourceRecord rr
;
990 if(!db
->startTransaction(zone
, di
.id
)) {
991 cerr
<<"Unable to start transaction for load of zone '"<<zone
<<"'"<<endl
;
995 bool haveSOA
= false;
997 if(!rr
.qname
.isPartOf(zone
) && rr
.qname
!=zone
) {
998 cerr
<<"File contains record named '"<<rr
.qname
<<"' which is not part of zone '"<<zone
<<"'"<<endl
;
1001 if (rr
.qtype
== QType::SOA
) {
1007 db
->feedRecord(rr
, DNSName());
1009 db
->commitTransaction();
1010 return EXIT_SUCCESS
;
1013 int createZone(const DNSName
&zone
, const DNSName
& nsname
) {
1016 if (B
.getDomainInfo(zone
, di
)) {
1017 cerr
<<"Domain '"<<zone
<<"' exists already"<<endl
;
1018 return EXIT_FAILURE
;
1020 cerr
<<"Creating empty zone '"<<zone
<<"'"<<endl
;
1021 B
.createDomain(zone
);
1022 if(!B
.getDomainInfo(zone
, di
)) {
1023 cerr
<<"Domain '"<<zone
<<"' was not created!"<<endl
;
1024 return EXIT_FAILURE
;
1027 DNSResourceRecord rr
;
1030 rr
.ttl
= ::arg().asNum("default-ttl");
1033 string soa
= (boost::format("%s %s 1")
1034 % (nsname
.empty() ? ::arg()["default-soa-name"] : nsname
.toString())
1035 % (::arg().isEmpty("default-soa-mail") ? (DNSName("hostmaster.") + zone
).toString() : ::arg()["default-soa-mail"])
1038 fillSOAData(soa
, sd
); // fills out default values for us
1039 rr
.content
= DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, serializeSOAData(sd
))->getZoneRepresentation(true);
1040 rr
.domain_id
= di
.id
;
1041 di
.backend
->startTransaction(zone
, di
.id
);
1042 di
.backend
->feedRecord(rr
, DNSName());
1043 if(!nsname
.empty()) {
1044 cout
<<"Also adding one NS record"<<endl
;
1046 rr
.content
=nsname
.toStringNoDot();
1047 di
.backend
->feedRecord(rr
, DNSName());
1050 di
.backend
->commitTransaction();
1052 return EXIT_SUCCESS
;
1055 int createSlaveZone(const vector
<string
>& cmds
) {
1058 DNSName
zone(cmds
[1]);
1059 if (B
.getDomainInfo(zone
, di
)) {
1060 cerr
<<"Domain '"<<zone
<<"' exists already"<<endl
;
1061 return EXIT_FAILURE
;
1063 vector
<string
> masters
;
1064 for (unsigned i
=2; i
< cmds
.size(); i
++) {
1065 ComboAddress
master(cmds
[i
], 53);
1066 masters
.push_back(master
.toStringWithPort());
1068 cerr
<<"Creating slave zone '"<<zone
<<"', with master(s) '"<<boost::join(masters
, ",")<<"'"<<endl
;
1069 B
.createDomain(zone
);
1070 if(!B
.getDomainInfo(zone
, di
)) {
1071 cerr
<<"Domain '"<<zone
<<"' was not created!"<<endl
;
1072 return EXIT_FAILURE
;
1074 di
.backend
->setKind(zone
, DomainInfo::Slave
);
1075 di
.backend
->setMaster(zone
, boost::join(masters
, ","));
1076 return EXIT_SUCCESS
;
1079 int changeSlaveZoneMaster(const vector
<string
>& cmds
) {
1082 DNSName
zone(cmds
[1]);
1083 if (!B
.getDomainInfo(zone
, di
)) {
1084 cerr
<<"Domain '"<<zone
<<"' doesn't exist"<<endl
;
1085 return EXIT_FAILURE
;
1087 vector
<string
> masters
;
1088 for (unsigned i
=2; i
< cmds
.size(); i
++) {
1089 ComboAddress
master(cmds
[i
], 53);
1090 masters
.push_back(master
.toStringWithPort());
1092 cerr
<<"Updating slave zone '"<<zone
<<"', master(s) to '"<<boost::join(masters
, ",")<<"'"<<endl
;
1094 di
.backend
->setMaster(zone
, boost::join(masters
, ","));
1095 return EXIT_SUCCESS
;
1097 catch (PDNSException
& e
) {
1098 cerr
<<"Setting master for zone '"<<zone
<<"' failed: "<<e
.reason
<<endl
;
1099 return EXIT_FAILURE
;
1103 // add-record ZONE name type [ttl] "content" ["content"]
1104 int addOrReplaceRecord(bool addOrReplace
, const vector
<string
>& cmds
) {
1105 DNSResourceRecord rr
;
1106 vector
<DNSResourceRecord
> newrrs
;
1107 DNSName
zone(cmds
[1]);
1112 name
=DNSName(cmds
[2])+zone
;
1114 rr
.qtype
= DNSRecordContent::TypeToNumber(cmds
[3]);
1115 rr
.ttl
= ::arg().asNum("default-ttl");
1120 if(!B
.getDomainInfo(zone
, di
)) {
1121 cerr
<<"Domain '"<<zone
<<"' does not exist"<<endl
;
1122 return EXIT_FAILURE
;
1125 rr
.domain_id
= di
.id
;
1127 DNSResourceRecord oldrr
;
1128 if(addOrReplace
) { // the 'add' case
1129 di
.backend
->lookup(rr
.qtype
, rr
.qname
, 0, di
.id
);
1131 while(di
.backend
->get(oldrr
))
1132 newrrs
.push_back(oldrr
);
1135 unsigned int contentStart
= 4;
1136 if(cmds
.size() > 5) {
1137 rr
.ttl
=atoi(cmds
[4].c_str());
1138 if(std::to_string(rr
.ttl
)==cmds
[4]) {
1141 else rr
.ttl
= ::arg().asNum("default-ttl");
1144 di
.backend
->lookup(QType(QType::ANY
), rr
.qname
, 0, di
.id
);
1146 if(rr
.qtype
.getCode() == QType::CNAME
) { // this will save us SO many questions
1148 while(di
.backend
->get(oldrr
)) {
1149 if(addOrReplace
|| oldrr
.qtype
.getCode() != QType::CNAME
) // the replace case is ok if we replace one CNAME by the other
1153 cerr
<<"Attempting to add CNAME to "<<rr
.qname
<<" which already had existing records"<<endl
;
1154 return EXIT_FAILURE
;
1158 while(di
.backend
->get(oldrr
)) {
1159 if(oldrr
.qtype
.getCode() == QType::CNAME
)
1163 cerr
<<"Attempting to add record to "<<rr
.qname
<<" which already had a CNAME record"<<endl
;
1164 return EXIT_FAILURE
;
1169 cout
<<"Current records for "<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" will be replaced"<<endl
;
1171 for(auto i
= contentStart
; i
< cmds
.size() ; ++i
) {
1172 rr
.content
= DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, cmds
[i
])->getZoneRepresentation(true);
1174 newrrs
.push_back(rr
);
1178 di
.backend
->replaceRRSet(di
.id
, name
, rr
.qtype
, newrrs
);
1179 // need to be explicit to bypass the ueberbackend cache!
1180 di
.backend
->lookup(rr
.qtype
, name
, 0, di
.id
);
1181 cout
<<"New rrset:"<<endl
;
1182 while(di
.backend
->get(rr
)) {
1183 cout
<<rr
.qname
.toString()<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.ttl
<<" "<<rr
.content
<<endl
;
1185 return EXIT_SUCCESS
;
1188 // delete-rrset zone name type
1189 int deleteRRSet(const std::string
& zone_
, const std::string
& name_
, const std::string
& type_
)
1193 DNSName
zone(zone_
);
1194 if(!B
.getDomainInfo(zone
, di
)) {
1195 cerr
<<"Domain '"<<zone
<<"' does not exist"<<endl
;
1196 return EXIT_FAILURE
;
1203 name
=DNSName(name_
)+zone
;
1205 QType
qt(QType::chartocode(type_
.c_str()));
1206 di
.backend
->replaceRRSet(di
.id
, name
, qt
, vector
<DNSResourceRecord
>());
1207 return EXIT_SUCCESS
;
1210 int listAllZones(const string
&type
="") {
1212 int kindFilter
= -1;
1214 if (toUpper(type
) == "MASTER")
1216 else if (toUpper(type
) == "SLAVE")
1218 else if (toUpper(type
) == "NATIVE")
1221 cerr
<<"Syntax: pdnsutil list-all-zones [master|slave|native]"<<endl
;
1226 UeberBackend
B("default");
1228 vector
<DomainInfo
> domains
;
1229 B
.getAllDomains(&domains
, true);
1232 for (vector
<DomainInfo
>::const_iterator di
=domains
.begin(); di
!= domains
.end(); di
++) {
1233 if (di
->kind
== kindFilter
|| kindFilter
== -1) {
1234 cout
<<di
->zone
<<endl
;
1240 if (kindFilter
!= -1)
1241 cout
<<type
<<" zonecount: "<<count
<<endl
;
1243 cout
<<"All zonecount: "<<count
<<endl
;
1249 bool testAlgorithm(int algo
)
1251 return DNSCryptoKeyEngine::testOne(algo
);
1254 bool testAlgorithms()
1256 return DNSCryptoKeyEngine::testAll();
1259 void testSpeed(DNSSECKeeper
& dk
, const DNSName
& zone
, const string
& remote
, int cores
)
1261 DNSResourceRecord rr
;
1262 rr
.qname
=DNSName("blah")+zone
;
1266 rr
.qclass
= QClass::IN
;
1268 UeberBackend
db("key-only");
1270 if ( ! db
.backends
.size() )
1272 throw runtime_error("No backends available for DNSSEC key storage");
1275 ChunkedSigningPipe
csp(DNSName(zone
), 1, cores
);
1277 vector
<DNSZoneRecord
> signatures
;
1279 unsigned char* octets
= (unsigned char*)&rnd
;
1283 for(unsigned int n
=0; n
< 100000; ++n
) {
1285 snprintf(tmp
, sizeof(tmp
), "%d.%d.%d.%d",
1286 octets
[0], octets
[1], octets
[2], octets
[3]);
1289 snprintf(tmp
, sizeof(tmp
), "r-%u", rnd
);
1290 rr
.qname
=DNSName(tmp
)+zone
;
1292 dzr
.dr
=DNSRecord(rr
);
1294 while(signatures
= csp
.getChunk(), !signatures
.empty())
1297 cerr
<<"Flushing the pipe, "<<csp
.d_signed
<<" signed, "<<csp
.d_queued
<<" queued, "<<csp
.d_outstanding
<<" outstanding"<< endl
;
1298 cerr
<<"Net speed: "<<csp
.d_signed
/ (dt
.udiffNoReset()/1000000.0) << " sigs/s"<<endl
;
1299 while(signatures
= csp
.getChunk(true), !signatures
.empty())
1301 cerr
<<"Done, "<<csp
.d_signed
<<" signed, "<<csp
.d_queued
<<" queued, "<<csp
.d_outstanding
<<" outstanding"<< endl
;
1302 cerr
<<"Net speed: "<<csp
.d_signed
/ (dt
.udiff()/1000000.0) << " sigs/s"<<endl
;
1305 void verifyCrypto(const string
& zone
)
1307 ZoneParserTNG
zpt(zone
);
1308 DNSResourceRecord rr
;
1309 DNSKEYRecordContent drc
;
1310 RRSIGRecordContent rrc
;
1311 DSRecordContent dsrc
;
1312 vector
<shared_ptr
<DNSRecordContent
> > toSign
;
1313 DNSName qname
, apex
;
1314 dsrc
.d_digesttype
=0;
1315 while(zpt
.get(rr
)) {
1316 if(rr
.qtype
.getCode() == QType::DNSKEY
) {
1317 cerr
<<"got DNSKEY!"<<endl
;
1319 drc
= *std::dynamic_pointer_cast
<DNSKEYRecordContent
>(DNSRecordContent::mastermake(QType::DNSKEY
, 1, rr
.content
));
1321 else if(rr
.qtype
.getCode() == QType::RRSIG
) {
1322 cerr
<<"got RRSIG"<<endl
;
1323 rrc
= *std::dynamic_pointer_cast
<RRSIGRecordContent
>(DNSRecordContent::mastermake(QType::RRSIG
, 1, rr
.content
));
1325 else if(rr
.qtype
.getCode() == QType::DS
) {
1326 cerr
<<"got DS"<<endl
;
1327 dsrc
= *std::dynamic_pointer_cast
<DSRecordContent
>(DNSRecordContent::mastermake(QType::DS
, 1, rr
.content
));
1331 toSign
.push_back(DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, rr
.content
));
1335 string msg
= getMessageForRRSET(qname
, rrc
, toSign
);
1336 cerr
<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc
.d_algorithm
, drc
.d_key
)->verify(msg
, rrc
.d_signature
)<<endl
;
1337 if(dsrc
.d_digesttype
) {
1338 cerr
<<"Calculated DS: "<<apex
.toString()<<" IN DS "<<makeDSFromDNSKey(apex
, drc
, dsrc
.d_digesttype
).getZoneRepresentation()<<endl
;
1339 cerr
<<"Original DS: "<<apex
.toString()<<" IN DS "<<dsrc
.getZoneRepresentation()<<endl
;
1342 std::shared_ptr
<DNSCryptoKeyEngine
> key
=DNSCryptoKeyEngine::makeFromISCString(drc
, "Private-key-format: v1.2\n"
1343 "Algorithm: 12 (ECC-GOST)\n"
1344 "GostAsn1: MEUCAQAwHAYGKoUDAgITMBIGByqFAwICIwEGByqFAwICHgEEIgQg/9MiXtXKg9FDXDN/R9CmVhJDyuzRAIgh4tPwCu4NHIs=\n");
1345 string resign
=key
->sign(hash
);
1346 cerr
<<Base64Encode(resign
)<<endl
;
1347 cerr
<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc
.d_algorithm
, drc
.d_key
)->verify(hash
, resign
)<<endl
;
1351 bool disableDNSSECOnZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1353 UeberBackend
B("default");
1356 if (!B
.getDomainInfo(zone
, di
)){
1357 cerr
<< "No such zone in the database" << endl
;
1362 bool ret
= dk
.unSecureZone(zone
, error
, info
);
1364 cerr
<< error
<< endl
;
1369 int setZoneAccount(const DNSName
& zone
, const string
&account
)
1371 UeberBackend
B("default");
1374 if (!B
.getDomainInfo(zone
, di
)){
1375 cerr
<< "No such zone "<<zone
<<" in the database" << endl
;
1376 return EXIT_FAILURE
;
1378 if(!di
.backend
->setAccount(zone
, account
)) {
1379 cerr
<<"Could not find backend willing to accept new zone configuration"<<endl
;
1380 return EXIT_FAILURE
;
1382 return EXIT_SUCCESS
;
1385 int setZoneKind(const DNSName
& zone
, const DomainInfo::DomainKind kind
)
1387 UeberBackend
B("default");
1390 if (!B
.getDomainInfo(zone
, di
)){
1391 cerr
<< "No such zone "<<zone
<<" in the database" << endl
;
1392 return EXIT_FAILURE
;
1394 if(!di
.backend
->setKind(zone
, kind
)) {
1395 cerr
<<"Could not find backend willing to accept new zone configuration"<<endl
;
1396 return EXIT_FAILURE
;
1398 return EXIT_SUCCESS
;
1401 bool showZone(DNSSECKeeper
& dk
, const DNSName
& zone
, bool exportDS
= false)
1403 UeberBackend
B("default");
1406 if (!B
.getDomainInfo(zone
, di
)){
1407 cerr
<< "No such zone in the database" << endl
;
1411 if (!di
.account
.empty()) {
1412 cout
<<"This zone is owned by "<<di
.account
<<endl
;
1415 cout
<<"This is a "<<DomainInfo::getKindString(di
.kind
)<<" zone"<<endl
;
1416 if(di
.kind
== DomainInfo::Master
) {
1417 cout
<<"Last SOA serial number we notified: "<<di
.notified_serial
<<" ";
1419 if(B
.getSOAUncached(zone
, sd
)) {
1420 if(sd
.serial
== di
.notified_serial
)
1424 cout
<<sd
.serial
<<" (serial in the database)"<<endl
;
1427 else if(di
.kind
== DomainInfo::Slave
) {
1428 cout
<<"Master"<<addS(di
.masters
)<<": ";
1429 for(const auto& m
: di
.masters
)
1433 localtime_r(&di
.last_check
, &tm
);
1436 strftime(buf
, sizeof(buf
)-1, "%a %F %H:%M:%S", &tm
);
1438 strncpy(buf
, "Never", sizeof(buf
)-1);
1439 buf
[sizeof(buf
)-1] = '\0';
1440 cout
<<"Last time we got update from master: "<<buf
<<endl
;
1442 if(B
.getSOAUncached(zone
, sd
)) {
1443 cout
<<"SOA serial in database: "<<sd
.serial
<<endl
;
1444 cout
<<"Refresh interval: "<<sd
.refresh
<<" seconds"<<endl
;
1447 cout
<<"No SOA serial found in database"<<endl
;
1451 if(!dk
.isSecuredZone(zone
)) {
1452 auto &outstream
= (exportDS
? cerr
: cout
);
1453 outstream
<< "Zone is not actively secured" << endl
;
1455 // it does not make sense to proceed here, and it might be useful
1456 // for scripts to know that something is odd here
1461 NSEC3PARAMRecordContent ns3pr
;
1463 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
1465 DNSSECKeeper::keyset_t keyset
=dk
.getKeys(zone
);
1468 std::vector
<std::string
> meta
;
1470 if (B
.getDomainMetadata(zone
, "TSIG-ALLOW-AXFR", meta
) && meta
.size() > 0) {
1471 cout
<< "Zone has following allowed TSIG key(s): " << boost::join(meta
, ",") << endl
;
1475 if (B
.getDomainMetadata(zone
, "AXFR-MASTER-TSIG", meta
) && meta
.size() > 0) {
1476 cout
<< "Zone uses following TSIG key(s): " << boost::join(meta
, ",") << endl
;
1479 std::map
<std::string
, std::vector
<std::string
> > metamap
;
1480 if(B
.getAllDomainMetadata(zone
, metamap
)) {
1481 cout
<<"Metadata items: ";
1486 for(const auto& m
: metamap
) {
1487 for(const auto i
: m
.second
)
1488 cout
<< '\t' << m
.first
<<'\t' << i
<<endl
;
1494 if (dk
.isPresigned(zone
)) {
1496 cout
<<"Zone is presigned"<<endl
;
1500 vector
<DNSKEYRecordContent
> keys
;
1503 B
.lookup(QType(QType::DNSKEY
), zone
);
1505 if (zr
.dr
.d_type
!= QType::DNSKEY
) continue;
1506 keys
.push_back(*getRR
<DNSKEYRecordContent
>(zr
.dr
));
1510 cerr
<< "No keys for zone '"<<zone
<<"'."<<endl
;
1516 cout
<<"Zone has NSEC semantics"<<endl
;
1518 cout
<<"Zone has " << (narrow
? "NARROW " : "") <<"hashed NSEC3 semantics, configuration: "<<ns3pr
.getZoneRepresentation()<<endl
;
1519 cout
<< "keys: "<<endl
;
1522 sort(keys
.begin(),keys
.end());
1523 reverse(keys
.begin(),keys
.end());
1525 for(const auto& key
: keys
) {
1526 string algname
= DNSSECKeeper::algorithm2name(key
.d_algorithm
);
1530 std::shared_ptr
<DNSCryptoKeyEngine
> engine(DNSCryptoKeyEngine::makeFromPublicKeyString(key
.d_algorithm
, key
.d_key
)); // throws on unknown algo or bad key
1531 bits
=engine
->getBits();
1533 catch(std::exception
& e
) {
1534 cerr
<<"Could not process key to extract metadata: "<<e
.what()<<endl
;
1537 cout
<< (key
.d_flags
== 257 ? "KSK" : "ZSK") << ", tag = " << key
.getTag() << ", algo = "<<(int)key
.d_algorithm
<< ", bits = " << bits
<< endl
;
1538 cout
<< "DNSKEY = " <<zone
.toString()<<" IN DNSKEY "<< key
.getZoneRepresentation() << "; ( " + algname
+ " ) " <<endl
;
1541 if (shown
) continue;
1544 const std::string
prefix(exportDS
? "" : "DS = ");
1545 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA1
).getZoneRepresentation() << " ; ( SHA1 digest )" << endl
;
1546 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA256
).getZoneRepresentation() << " ; ( SHA256 digest )" << endl
;
1548 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::GOST
).getZoneRepresentation();
1549 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( GOST R 34.11-94 digest )" << endl
;
1554 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA384
).getZoneRepresentation();
1555 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( SHA-384 digest )" << endl
;
1561 else if(keyset
.empty()) {
1562 cerr
<< "No keys for zone '"<<zone
<<"'."<<endl
;
1567 cout
<<"Zone has NSEC semantics"<<endl
;
1569 cout
<<"Zone has " << (narrow
? "NARROW " : "") <<"hashed NSEC3 semantics, configuration: "<<ns3pr
.getZoneRepresentation()<<endl
;
1570 cout
<< "keys: "<<endl
;
1573 for(DNSSECKeeper::keyset_t::value_type value
: keyset
) {
1574 string algname
= DNSSECKeeper::algorithm2name(value
.first
.d_algorithm
);
1576 cout
<<"ID = "<<value
.second
.id
<<" ("<<DNSSECKeeper::keyTypeToString(value
.second
.keyType
)<<")";
1578 if (value
.first
.getKey()->getBits() < 1) {
1579 cerr
<<" <key missing or defunct>" <<endl
;
1583 cout
<<", flags = "<<std::to_string(value
.first
.d_flags
);
1584 cout
<<", tag = "<<value
.first
.getDNSKEY().getTag();
1585 cout
<<", algo = "<<(int)value
.first
.d_algorithm
<<", bits = "<<value
.first
.getKey()->getBits()<<"\t"<<((int)value
.second
.active
== 1 ? " A" : "Ina")<<"ctive ( " + algname
+ " ) "<<endl
;
1589 if (value
.second
.keyType
== DNSSECKeeper::KSK
|| value
.second
.keyType
== DNSSECKeeper::CSK
|| ::arg().mustDo("direct-dnskey")) {
1590 cout
<<DNSSECKeeper::keyTypeToString(value
.second
.keyType
)<<" DNSKEY = "<<zone
.toString()<<" IN DNSKEY "<< value
.first
.getDNSKEY().getZoneRepresentation() << " ; ( " + algname
+ " )" << endl
;
1593 if (value
.second
.keyType
== DNSSECKeeper::KSK
|| value
.second
.keyType
== DNSSECKeeper::CSK
) {
1594 const auto &key
= value
.first
.getDNSKEY();
1595 const std::string
prefix(exportDS
? "" : "DS = ");
1596 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA1
).getZoneRepresentation() << " ; ( SHA1 digest )" << endl
;
1597 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA256
).getZoneRepresentation() << " ; ( SHA256 digest )" << endl
;
1599 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::GOST
).getZoneRepresentation();
1600 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( GOST R 34.11-94 digest )" << endl
;
1605 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA384
).getZoneRepresentation();
1606 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( SHA-384 digest )" << endl
;
1616 bool secureZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1621 // temp var for addKey
1624 string k_algo
= ::arg()["default-ksk-algorithm"];
1625 k_size
= ::arg().asNum("default-ksk-size");
1626 string z_algo
= ::arg()["default-zsk-algorithm"];
1627 z_size
= ::arg().asNum("default-zsk-size");
1630 throw runtime_error("KSK key size must be equal to or greater than 0");
1633 if (k_algo
== "" && z_algo
== "") {
1634 throw runtime_error("Zero algorithms given for KSK+ZSK in total");
1638 throw runtime_error("ZSK key size must be equal to or greater than 0");
1641 if(dk
.isSecuredZone(zone
)) {
1642 cerr
<< "Zone '"<<zone
<<"' already secure, remove keys with pdnsutil remove-zone-key if needed"<<endl
;
1647 UeberBackend
B("default");
1648 if(!B
.getDomainInfo(zone
, di
) || !di
.backend
) { // di.backend and B are mostly identical
1649 cerr
<<"Can't find a zone called '"<<zone
<<"'"<<endl
;
1653 if(di
.kind
== DomainInfo::Slave
)
1655 cerr
<<"Warning! This is a slave domain! If this was a mistake, please run"<<endl
;
1656 cerr
<<"pdnsutil disable-dnssec "<<zone
<<" right now!"<<endl
;
1659 if (k_algo
!= "") { // Add a KSK
1661 cout
<< "Securing zone with key size " << k_size
<< endl
;
1663 cout
<< "Securing zone with default key size" << endl
;
1665 cout
<< "Adding "<<(z_algo
== "" ? "CSK (257)" : "KSK")<<" with algorithm " << k_algo
<< endl
;
1667 int k_real_algo
= DNSSECKeeper::shorthand2algorithm(k_algo
);
1669 if (!dk
.addKey(zone
, true, k_real_algo
, id
, k_size
, true)) {
1670 cerr
<<"No backend was able to secure '"<<zone
<<"', most likely because no DNSSEC"<<endl
;
1671 cerr
<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl
;
1672 cerr
<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl
;
1673 cerr
<<"'gpgsql-dnssec' flag. Also make sure the schema has been updated for DNSSEC!"<<endl
;
1679 cout
<< "Adding "<<(k_algo
== "" ? "CSK (256)" : "ZSK")<<" with algorithm " << z_algo
<< endl
;
1681 int z_real_algo
= DNSSECKeeper::shorthand2algorithm(z_algo
);
1683 if (!dk
.addKey(zone
, false, z_real_algo
, id
, z_size
, true)) {
1684 cerr
<<"No backend was able to secure '"<<zone
<<"', most likely because no DNSSEC"<<endl
;
1685 cerr
<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl
;
1686 cerr
<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl
;
1687 cerr
<<"'gpgsql-dnssec' flag. Also make sure the schema has been updated for DNSSEC!"<<endl
;
1692 if(!dk
.isSecuredZone(zone
)) {
1693 cerr
<<"Failed to secure zone. Is your backend dnssec enabled? (set "<<endl
;
1694 cerr
<<"gsqlite3-dnssec, or gmysql-dnssec etc). Check this first."<<endl
;
1695 cerr
<<"If you run with the BIND backend, make sure you have configured"<<endl
;
1696 cerr
<<"it to use DNSSEC with 'bind-dnssec-db=/path/fname' and"<<endl
;
1697 cerr
<<"'pdnsutil create-bind-db /path/fname'!"<<endl
;
1701 // rectifyZone(dk, zone);
1702 // showZone(dk, zone);
1703 cout
<<"Zone "<<zone
<<" secured"<<endl
;
1707 void testSchema(DNSSECKeeper
& dk
, const DNSName
& zone
)
1709 cout
<<"Note: test-schema will try to create the zone, but it will not remove it."<<endl
;
1710 cout
<<"Please clean up after this."<<endl
;
1712 cout
<<"Constructing UeberBackend"<<endl
;
1713 UeberBackend
B("default");
1714 cout
<<"Picking first backend - if this is not what you want, edit launch line!"<<endl
;
1715 DNSBackend
*db
= B
.backends
[0];
1716 cout
<<"Creating slave domain "<<zone
<<endl
;
1717 db
->createSlaveDomain("127.0.0.1", zone
, "", "_testschema");
1718 cout
<<"Slave domain created"<<endl
;
1721 if(!B
.getDomainInfo(zone
, di
) || !di
.backend
) { // di.backend and B are mostly identical
1722 cout
<<"Can't find domain we just created, aborting"<<endl
;
1726 DNSResourceRecord rr
, rrget
;
1727 cout
<<"Starting transaction to feed records"<<endl
;
1728 db
->startTransaction(zone
, di
.id
);
1730 rr
.qtype
=QType::SOA
;
1735 rr
.content
="ns1.example.com. ahu.example.com. 2012081039 7200 3600 1209600 3600";
1736 cout
<<"Feeding SOA"<<endl
;
1737 db
->feedRecord(rr
, DNSName());
1738 rr
.qtype
=QType::TXT
;
1740 rr
.content
="\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"";
1741 cout
<<"Feeding overlong TXT"<<endl
;
1742 db
->feedRecord(rr
, DNSName());
1743 cout
<<"Committing"<<endl
;
1744 db
->commitTransaction();
1745 cout
<<"Querying TXT"<<endl
;
1746 db
->lookup(QType(QType::TXT
), zone
, NULL
, di
.id
);
1749 DNSResourceRecord rrthrowaway
;
1750 if(db
->get(rrthrowaway
)) // should not touch rr but don't assume anything
1752 cout
<<"Expected one record, got multiple, aborting"<<endl
;
1755 int size
=rrget
.content
.size();
1758 cout
<<"Expected 302 bytes, got "<<size
<<", aborting"<<endl
;
1762 cout
<<"[+] content field is over 255 bytes"<<endl
;
1764 cout
<<"Dropping all records, inserting SOA+2xA"<<endl
;
1765 db
->startTransaction(zone
, di
.id
);
1767 rr
.qtype
=QType::SOA
;
1772 rr
.content
="ns1.example.com. ahu.example.com. 2012081039 7200 3600 1209600 3600";
1773 cout
<<"Feeding SOA"<<endl
;
1774 db
->feedRecord(rr
, DNSName());
1777 rr
.qname
=DNSName("_underscore")+zone
;
1778 rr
.content
="127.0.0.1";
1779 db
->feedRecord(rr
, DNSName());
1781 rr
.qname
=DNSName("bla")+zone
;
1782 cout
<<"Committing"<<endl
;
1783 db
->commitTransaction();
1785 cout
<<"Securing zone"<<endl
;
1786 secureZone(dk
, zone
);
1787 cout
<<"Rectifying zone"<<endl
;
1788 rectifyZone(dk
, zone
);
1789 cout
<<"Checking underscore ordering"<<endl
;
1790 DNSName before
, after
;
1791 db
->getBeforeAndAfterNames(di
.id
, zone
, DNSName("z")+zone
, before
, after
);
1792 cout
<<"got '"<<before
.toString()<<"' < 'z."<<zone
.toString()<<"' < '"<<after
.toString()<<"'"<<endl
;
1793 if(before
!= DNSName("_underscore")+zone
)
1795 cout
<<"before is wrong, got '"<<before
.toString()<<"', expected '_underscore."<<zone
.toString()<<"', aborting"<<endl
;
1800 cout
<<"after is wrong, got '"<<after
.toString()<<"', expected '"<<zone
.toString()<<"', aborting"<<endl
;
1803 cout
<<"[+] ordername sorting is correct for names starting with _"<<endl
;
1805 cout
<<"End of tests, please remove "<<zone
<<" from domains+records"<<endl
;
1808 int addOrSetMeta(const DNSName
& zone
, const string
& kind
, const vector
<string
>& values
, bool clobber
) {
1809 UeberBackend
B("default");
1812 if (!B
.getDomainInfo(zone
, di
)) {
1813 cerr
<< "Invalid zone '" << zone
<< "'" << endl
;
1817 vector
<string
> all_metadata
;
1820 B
.getDomainMetadata(zone
, kind
, all_metadata
);
1823 all_metadata
.insert(all_metadata
.end(), values
.begin(), values
.end());
1825 if (!B
.setDomainMetadata(zone
, kind
, all_metadata
)) {
1826 cerr
<< "Unable to set meta for '" << zone
<< "'" << endl
;
1830 cout
<< "Set '" << zone
<< "' meta " << kind
<< " = " << boost::join(all_metadata
, ", ") << endl
;
1834 int main(int argc
, char** argv
)
1837 po::options_description
desc("Allowed options");
1839 ("help,h", "produce help message")
1840 ("version", "show version")
1841 ("verbose,v", "be verbose")
1842 ("force", "force an action")
1843 ("config-name", po::value
<string
>()->default_value(""), "virtual configuration name")
1844 ("config-dir", po::value
<string
>()->default_value(SYSCONFDIR
), "location of pdns.conf")
1845 ("commands", po::value
<vector
<string
> >());
1847 po::positional_options_description p
;
1848 p
.add("commands", -1);
1849 po::store(po::command_line_parser(argc
, argv
).options(desc
).positional(p
).run(), g_vm
);
1852 vector
<string
> cmds
;
1854 if(g_vm
.count("commands"))
1855 cmds
= g_vm
["commands"].as
<vector
<string
> >();
1857 g_verbose
= g_vm
.count("verbose");
1859 if (g_vm
.count("version")) {
1860 cout
<<"pdnsutil "<<VERSION
<<endl
;
1864 if(cmds
.empty() || g_vm
.count("help") || cmds
[0] == "help") {
1865 cout
<<"Usage: \npdnsutil [options] <command> [params ..]\n"<<endl
;
1866 cout
<<"Commands:"<<endl
;
1867 cout
<<"activate-tsig-key ZONE NAME {master|slave}"<<endl
;
1868 cout
<<" Enable TSIG authenticated AXFR using the key NAME for ZONE"<<endl
;
1869 cout
<<"activate-zone-key ZONE KEY-ID Activate the key with key id KEY-ID in ZONE"<<endl
;
1870 cout
<<"add-record ZONE NAME TYPE [ttl] content"<<endl
;
1871 cout
<<" [content..] Add one or more records to ZONE"<<endl
;
1872 cout
<<"add-zone-key ZONE {zsk|ksk} [BITS] [active|inactive]"<<endl
;
1873 cout
<<" [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384";
1874 #if defined(HAVE_LIBSODIUM) || defined(HAVE_LIBDECAF)
1877 #ifdef HAVE_LIBDECAF
1881 cout
<<" Add a ZSK or KSK to zone and specify algo&bits"<<endl
;
1882 cout
<<"backend-cmd BACKEND CMD [CMD..] Perform one or more backend commands"<<endl
;
1883 cout
<<"b2b-migrate OLD NEW Move all data from one backend to another"<<endl
;
1884 cout
<<"bench-db [filename] Bench database backend with queries, one domain per line"<<endl
;
1885 cout
<<"check-zone ZONE Check a zone for correctness"<<endl
;
1886 cout
<<"check-all-zones [exit-on-error] Check all zones for correctness. Set exit-on-error to exit immediately"<<endl
;
1887 cout
<<" after finding an error in a zone."<<endl
;
1888 cout
<<"clear-zone ZONE Clear all records of a zone, but keep everything else"<<endl
;
1889 cout
<<"create-bind-db FNAME Create DNSSEC db for BIND backend (bind-dnssec-db)"<<endl
;
1890 cout
<<"create-slave-zone ZONE master-ip [master-ip..]"<<endl
;
1891 cout
<<" Create slave zone ZONE with master IP address master-ip"<<endl
;
1892 cout
<<"change-slave-zone-master ZONE master-ip [master-ip..]"<<endl
;
1893 cout
<<" Change slave zone ZONE master IP address to master-ip"<<endl
;
1894 cout
<<"create-zone ZONE [nsname] Create empty zone ZONE"<<endl
;
1895 cout
<<"deactivate-tsig-key ZONE NAME {master|slave}"<<endl
;
1896 cout
<<" Disable TSIG authenticated AXFR using the key NAME for ZONE"<<endl
;
1897 cout
<<"deactivate-zone-key ZONE KEY-ID Deactivate the key with key id KEY-ID in ZONE"<<endl
;
1898 cout
<<"delete-rrset ZONE NAME TYPE Delete named RRSET from zone"<<endl
;
1899 cout
<<"delete-tsig-key NAME Delete TSIG key (warning! will not unmap key!)"<<endl
;
1900 cout
<<"delete-zone ZONE Delete the zone"<<endl
;
1901 cout
<<"disable-dnssec ZONE Deactivate all keys and unset PRESIGNED in ZONE"<<endl
;
1902 cout
<<"edit-zone ZONE Edit zone contents using $EDITOR"<<endl
;
1903 cout
<<"export-zone-dnskey ZONE KEY-ID Export to stdout the public DNSKEY described"<<endl
;
1904 cout
<<"export-zone-ds ZONE Export to stdout all KSK DS records for ZONE"<<endl
;
1905 cout
<<"export-zone-key ZONE KEY-ID Export to stdout the private key described"<<endl
;
1906 cout
<<"generate-tsig-key NAME ALGORITHM Generate new TSIG key"<<endl
;
1907 cout
<<"generate-zone-key {zsk|ksk} [ALGORITHM] [BITS]"<<endl
;
1908 cout
<<" Generate a ZSK or KSK to stdout with specified ALGORITHM and BITS"<<endl
;
1909 cout
<<"get-meta ZONE [KIND ...] Get zone metadata. If no KIND given, lists all known"<<endl
;
1910 cout
<<"hash-zone-record ZONE RNAME Calculate the NSEC3 hash for RNAME in ZONE"<<endl
;
1912 cout
<<"hsm assign ZONE ALGORITHM {ksk|zsk} MODULE SLOT PIN LABEL"<<endl
<<
1913 " Assign a hardware signing module to a ZONE"<<endl
;
1914 cout
<<"hsm create-key ZONE KEY-ID [BITS] Create a key using hardware signing module for ZONE (use assign first)"<<endl
;
1915 cout
<<" BITS defaults to 2048"<<endl
;
1917 cout
<<"increase-serial ZONE Increases the SOA-serial by 1. Uses SOA-EDIT"<<endl
;
1918 cout
<<"import-tsig-key NAME ALGORITHM KEY Import TSIG key"<<endl
;
1919 cout
<<"import-zone-key ZONE FILE Import from a file a private key, ZSK or KSK"<<endl
;
1920 cout
<<" [active|inactive] [ksk|zsk] Defaults to KSK and active"<<endl
;
1921 cout
<<"load-zone ZONE FILE Load ZONE from FILE, possibly creating zone or atomically"<<endl
;
1922 cout
<<" replacing contents"<<endl
;
1923 cout
<<"list-algorithms [with-backend] List all DNSSEC algorithms supported, optionally also listing the crypto library used"<<endl
;
1924 cout
<<"list-keys [ZONE] List DNSSEC keys for ZONE. When ZONE is unset or \"all\", display all keys for all zones"<<endl
;
1925 cout
<<"list-zone ZONE List zone contents"<<endl
;
1926 cout
<<"list-all-zones [master|slave|native]"<<endl
;
1927 cout
<<" List all zone names"<<endl
;;
1928 cout
<<"list-tsig-keys List all TSIG keys"<<endl
;
1929 cout
<<"rectify-zone ZONE [ZONE ..] Fix up DNSSEC fields (order, auth)"<<endl
;
1930 cout
<<"rectify-all-zones Rectify all zones."<<endl
;
1931 cout
<<"remove-zone-key ZONE KEY-ID Remove key with KEY-ID from ZONE"<<endl
;
1932 cout
<<"replace-rrset ZONE NAME TYPE [ttl] Replace named RRSET from zone"<<endl
;
1933 cout
<<" content [content..]"<<endl
;
1934 cout
<<"secure-all-zones [increase-serial] Secure all zones without keys"<<endl
;
1935 cout
<<"secure-zone ZONE [ZONE ..] Add DNSSEC to zone ZONE"<<endl
;
1936 cout
<<"set-kind ZONE KIND Change the kind of ZONE to KIND (master, slave native)"<<endl
;
1937 cout
<<"set-account ZONE ACCOUNT Change the account (owner) of ZONE to ACCOUNT"<<endl
;
1938 cout
<<"set-nsec3 ZONE ['PARAMS' [narrow]] Enable NSEC3 with PARAMS. Optionally narrow"<<endl
;
1939 cout
<<"set-presigned ZONE Use presigned RRSIGs from storage"<<endl
;
1940 cout
<<"set-publish-cdnskey ZONE Enable sending CDNSKEY responses for ZONE"<<endl
;
1941 cout
<<"set-publish-cds ZONE [DIGESTALGOS] Enable sending CDS responses for ZONE, using DIGESTALGOS as signature algorithms"<<endl
;
1942 cout
<<" DIGESTALGOS should be a comma separated list of numbers, is is '1,2' by default"<<endl
;
1943 cout
<<"add-meta ZONE KIND VALUE Add zone metadata, this adds to the existing KIND"<<endl
;
1944 cout
<<" [VALUE ...]"<<endl
;
1945 cout
<<"set-meta ZONE KIND [VALUE] [VALUE] Set zone metadata, optionally providing a value. *No* value clears meta"<<endl
;
1946 cout
<<" Note - this will replace all metadata records of KIND!"<<endl
;
1947 cout
<<"show-zone ZONE Show DNSSEC (public) key details about a zone"<<endl
;
1948 cout
<<"unset-nsec3 ZONE Switch back to NSEC"<<endl
;
1949 cout
<<"unset-presigned ZONE No longer use presigned RRSIGs"<<endl
;
1950 cout
<<"unset-publish-cdnskey ZONE Disable sending CDNSKEY responses for ZONE"<<endl
;
1951 cout
<<"unset-publish-cds ZONE Disable sending CDS responses for ZONE"<<endl
;
1952 cout
<<"test-schema ZONE Test DB schema - will create ZONE"<<endl
;
1957 loadMainConfig(g_vm
["config-dir"].as
<string
>());
1959 #ifdef HAVE_LIBSODIUM
1960 if (sodium_init() == -1) {
1961 cerr
<<"Unable to initialize sodium crypto library"<<endl
;
1968 if (cmds
[0] == "test-algorithm") {
1969 if(cmds
.size() != 2) {
1970 cerr
<< "Syntax: pdnsutil test-algorithm algonum"<<endl
;
1973 if (testAlgorithm(pdns_stou(cmds
[1])))
1978 if(cmds
[0] == "test-algorithms") {
1979 if (testAlgorithms())
1984 if(cmds
[0] == "list-algorithms") {
1985 if((cmds
.size() == 2 && cmds
[1] != "with-backend") || cmds
.size() > 2) {
1986 cerr
<<"Syntax: pdnsutil list-algorithms [with-backend]"<<endl
;
1990 cout
<<"DNSKEY algorithms supported by this installation of PowerDNS:"<<endl
;
1992 auto algosWithBackend
= DNSCryptoKeyEngine::listAllAlgosWithBackend();
1993 for (auto const algoWithBackend
: algosWithBackend
){
1994 string algoName
= DNSSECKeeper::algorithm2name(algoWithBackend
.first
);
1995 cout
<<std::to_string(algoWithBackend
.first
)<<" - "<<algoName
;
1996 if (cmds
.size() == 2 && cmds
[1] == "with-backend")
1997 cout
<<" using "<<algoWithBackend
.second
;
2005 if(cmds
[0] == "create-bind-db") {
2007 if(cmds
.size() != 2) {
2008 cerr
<< "Syntax: pdnsutil create-bind-db FNAME"<<endl
;
2012 SSQLite3
db(cmds
[1], true); // create=ok
2013 vector
<string
> statements
;
2014 stringtok(statements
, sqlCreate
, ";");
2015 for(const string
& statement
: statements
) {
2016 db
.execute(statement
);
2019 catch(SSqlException
& se
) {
2020 throw PDNSException("Error creating database in BIND backend: "+se
.txtReason());
2024 cerr
<<"bind-dnssec-db requires building PowerDNS with SQLite3"<<endl
;
2031 if (cmds
[0] == "test-schema") {
2032 if(cmds
.size() != 2) {
2033 cerr
<< "Syntax: pdnsutil test-schema ZONE"<<endl
;
2036 testSchema(dk
, DNSName(cmds
[1]));
2039 if(cmds
[0] == "rectify-zone") {
2040 if(cmds
.size() < 2) {
2041 cerr
<< "Syntax: pdnsutil rectify-zone ZONE [ZONE..]"<<endl
;
2044 unsigned int exitCode
= 0;
2045 for(unsigned int n
= 1; n
< cmds
.size(); ++n
)
2046 if (!rectifyZone(dk
, DNSName(cmds
[n
])))
2050 else if (cmds
[0] == "rectify-all-zones") {
2051 rectifyAllZones(dk
);
2053 else if(cmds
[0] == "check-zone") {
2054 if(cmds
.size() != 2) {
2055 cerr
<< "Syntax: pdnsutil check-zone ZONE"<<endl
;
2058 UeberBackend
B("default");
2059 exit(checkZone(dk
, B
, DNSName(cmds
[1])));
2061 else if(cmds
[0] == "bench-db") {
2062 dbBench(cmds
.size() > 1 ? cmds
[1] : "");
2064 else if (cmds
[0] == "check-all-zones") {
2065 bool exitOnError
= ((cmds
.size() >= 2 ? cmds
[1] : "") == "exit-on-error");
2066 exit(checkAllZones(dk
, exitOnError
));
2068 else if (cmds
[0] == "list-all-zones") {
2069 if (cmds
.size() > 2) {
2070 cerr
<< "Syntax: pdnsutil list-all-zones [master|slave|native]"<<endl
;
2073 if (cmds
.size() == 2)
2074 return listAllZones(cmds
[1]);
2075 return listAllZones();
2077 else if (cmds
[0] == "test-zone") {
2078 cerr
<< "Did you mean check-zone?"<<endl
;
2081 else if (cmds
[0] == "test-all-zones") {
2082 cerr
<< "Did you mean check-all-zones?"<<endl
;
2086 else if(cmds
[0] == "signing-server" )
2090 else if(cmds
[0] == "signing-slave")
2092 launchSigningService(0);
2095 else if(cmds
[0] == "test-speed") {
2096 if(cmds
.size() < 2) {
2097 cerr
<< "Syntax: pdnsutil test-speed numcores [signing-server]"<<endl
;
2100 testSpeed(dk
, DNSName(cmds
[1]), (cmds
.size() > 3) ? cmds
[3] : "", pdns_stou(cmds
[2]));
2102 else if(cmds
[0] == "verify-crypto") {
2103 if(cmds
.size() != 2) {
2104 cerr
<< "Syntax: pdnsutil verify-crypto FILE"<<endl
;
2107 verifyCrypto(cmds
[1]);
2109 else if(cmds
[0] == "show-zone") {
2110 if(cmds
.size() != 2) {
2111 cerr
<< "Syntax: pdnsutil show-zone ZONE"<<endl
;
2114 if (!showZone(dk
, DNSName(cmds
[1]))) return 1;
2116 else if(cmds
[0] == "export-zone-ds") {
2117 if(cmds
.size() != 2) {
2118 cerr
<< "Syntax: pdnsutil export-zone-ds ZONE"<<endl
;
2121 if (!showZone(dk
, DNSName(cmds
[1]), true)) return 1;
2123 else if(cmds
[0] == "disable-dnssec") {
2124 if(cmds
.size() != 2) {
2125 cerr
<< "Syntax: pdnsutil disable-dnssec ZONE"<<endl
;
2128 DNSName
zone(cmds
[1]);
2129 if(!disableDNSSECOnZone(dk
, zone
)) {
2130 cerr
<< "Cannot disable DNSSEC on " << zone
<< endl
;
2134 else if(cmds
[0] == "activate-zone-key") {
2135 if(cmds
.size() != 3) {
2136 cerr
<< "Syntax: pdnsutil activate-zone-key ZONE KEY-ID"<<endl
;
2139 DNSName
zone(cmds
[1]);
2140 unsigned int id
=atoi(cmds
[2].c_str()); // if you make this pdns_stou, the error gets worse
2143 cerr
<<"Invalid KEY-ID '"<<cmds
[2]<<"'"<<endl
;
2146 if (!dk
.activateKey(zone
, id
)) {
2147 cerr
<<"Activation of key failed"<<endl
;
2152 else if(cmds
[0] == "deactivate-zone-key") {
2153 if(cmds
.size() != 3) {
2154 cerr
<< "Syntax: pdnsutil deactivate-zone-key ZONE KEY-ID"<<endl
;
2157 DNSName
zone(cmds
[1]);
2158 unsigned int id
=pdns_stou(cmds
[2]);
2161 cerr
<<"Invalid KEY-ID"<<endl
;
2164 if (!dk
.deactivateKey(zone
, id
)) {
2165 cerr
<<"Deactivation of key failed"<<endl
;
2170 else if(cmds
[0] == "add-zone-key") {
2171 if(cmds
.size() < 3 ) {
2172 cerr
<< "Syntax: pdnsutil add-zone-key ZONE zsk|ksk [BITS] [active|inactive] [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]"<<endl
;
2175 DNSName
zone(cmds
[1]);
2177 UeberBackend
B("default");
2180 if (!B
.getDomainInfo(zone
, di
)){
2181 cerr
<< "No such zone in the database" << endl
;
2185 // need to get algorithm, bits & ksk or zsk from commandline
2186 bool keyOrZone
=false;
2189 int algorithm
=13; // ecdsa256
2191 for(unsigned int n
=2; n
< cmds
.size(); ++n
) {
2192 if(pdns_iequals(cmds
[n
], "zsk"))
2194 else if(pdns_iequals(cmds
[n
], "ksk"))
2196 else if((tmp_algo
= DNSSECKeeper::shorthand2algorithm(cmds
[n
]))>0) {
2197 algorithm
= tmp_algo
;
2198 } else if(pdns_iequals(cmds
[n
], "active")) {
2200 } else if(pdns_iequals(cmds
[n
], "inactive") || pdns_iequals(cmds
[n
], "passive")) { // 'passive' eventually needs to be removed
2202 } else if(pdns_stou(cmds
[n
])) {
2203 bits
= pdns_stou(cmds
[n
]);
2205 cerr
<<"Unknown algorithm, key flag or size '"<<cmds
[n
]<<"'"<<endl
;
2206 exit(EXIT_FAILURE
);;
2210 if (!dk
.addKey(zone
, keyOrZone
, algorithm
, id
, bits
, active
)) {
2211 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2214 cerr
<<"Added a " << (keyOrZone
? "KSK" : "ZSK")<<" with algorithm = "<<algorithm
<<", active="<<active
<<endl
;
2216 cerr
<<"Requested specific key size of "<<bits
<<" bits"<<endl
;
2218 cerr
<<std::to_string(id
)<<"Key was added, but backend does not support returning of key id"<<endl
;
2219 } else if (id
< -1) {
2220 cerr
<<std::to_string(id
)<<"Key was added, but there was a failure while returning the key id"<<endl
;
2222 cout
<<std::to_string(id
)<<endl
;
2226 else if(cmds
[0] == "remove-zone-key") {
2227 if(cmds
.size() < 3) {
2228 cerr
<<"Syntax: pdnsutil remove-zone-key ZONE KEY-ID"<<endl
;
2231 DNSName
zone(cmds
[1]);
2232 unsigned int id
=pdns_stou(cmds
[2]);
2233 if (!dk
.removeKey(zone
, id
)) {
2234 cerr
<<"Cannot remove key " << id
<< " from " << zone
<<endl
;
2239 else if(cmds
[0] == "delete-zone") {
2240 if(cmds
.size() != 2) {
2241 cerr
<<"Syntax: pdnsutil delete-zone ZONE"<<endl
;
2244 exit(deleteZone(DNSName(cmds
[1])));
2246 else if(cmds
[0] == "create-zone") {
2247 if(cmds
.size() != 2 && cmds
.size()!=3 ) {
2248 cerr
<<"Syntax: pdnsutil create-zone ZONE [nsname]"<<endl
;
2251 exit(createZone(DNSName(cmds
[1]), cmds
.size() > 2 ? DNSName(cmds
[2]): DNSName()));
2253 else if(cmds
[0] == "create-slave-zone") {
2254 if(cmds
.size() < 3 ) {
2255 cerr
<<"Syntax: pdnsutil create-slave-zone ZONE master-ip [master-ip..]"<<endl
;
2258 exit(createSlaveZone(cmds
));
2260 else if(cmds
[0] == "change-slave-zone-master") {
2261 if(cmds
.size() < 3 ) {
2262 cerr
<<"Syntax: pdnsutil change-slave-zone-master ZONE master-ip [master-ip..]"<<endl
;
2265 exit(changeSlaveZoneMaster(cmds
));
2267 else if(cmds
[0] == "add-record") {
2268 if(cmds
.size() < 5) {
2269 cerr
<<"Syntax: pdnsutil add-record ZONE name type [ttl] \"content\" [\"content\"...]"<<endl
;
2272 exit(addOrReplaceRecord(true, cmds
));
2274 else if(cmds
[0] == "replace-rrset") {
2275 if(cmds
.size() < 5) {
2276 cerr
<<"Syntax: pdnsutil replace-record ZONE name type [ttl] \"content\" [\"content\"...]"<<endl
;
2279 exit(addOrReplaceRecord(false , cmds
));
2281 else if(cmds
[0] == "delete-rrset") {
2282 if(cmds
.size() != 4) {
2283 cerr
<<"Syntax: pdnsutil delete-rrset ZONE name type"<<endl
;
2286 exit(deleteRRSet(cmds
[1], cmds
[2], cmds
[3]));
2288 else if(cmds
[0] == "list-zone") {
2289 if(cmds
.size() != 2) {
2290 cerr
<<"Syntax: pdnsutil list-zone ZONE"<<endl
;
2296 exit(listZone(DNSName(cmds
[1])));
2298 else if(cmds
[0] == "edit-zone") {
2299 if(cmds
.size() != 2) {
2300 cerr
<<"Syntax: pdnsutil edit-zone ZONE"<<endl
;
2306 exit(editZone(dk
, DNSName(cmds
[1])));
2308 else if(cmds
[0] == "clear-zone") {
2309 if(cmds
.size() != 2) {
2310 cerr
<<"Syntax: pdnsutil edit-zone ZONE"<<endl
;
2316 exit(clearZone(dk
, DNSName(cmds
[1])));
2318 else if(cmds
[0] == "list-keys") {
2319 if(cmds
.size() > 2) {
2320 cerr
<<"Syntax: pdnsutil list-keys [ZONE]"<<endl
;
2323 string zname
= (cmds
.size() == 2) ? cmds
[1] : "all";
2324 exit(listKeys(zname
, dk
));
2326 else if(cmds
[0] == "load-zone") {
2327 if(cmds
.size() != 3) {
2328 cerr
<<"Syntax: pdnsutil load-zone ZONE FILENAME"<<endl
;
2334 exit(loadZone(DNSName(cmds
[1]), cmds
[2]));
2336 else if(cmds
[0] == "secure-zone") {
2337 if(cmds
.size() < 2) {
2338 cerr
<< "Syntax: pdnsutil secure-zone ZONE"<<endl
;
2341 vector
<DNSName
> mustRectify
;
2342 unsigned int zoneErrors
=0;
2343 for(unsigned int n
= 1; n
< cmds
.size(); ++n
) {
2344 DNSName
zone(cmds
[n
]);
2345 dk
.startTransaction(zone
, -1);
2346 if(secureZone(dk
, zone
)) {
2347 mustRectify
.push_back(zone
);
2351 dk
.commitTransaction();
2354 for(const auto& zone
: mustRectify
)
2355 rectifyZone(dk
, zone
);
2362 else if (cmds
[0] == "secure-all-zones") {
2363 if (cmds
.size() >= 2 && !pdns_iequals(cmds
[1], "increase-serial")) {
2364 cerr
<< "Syntax: pdnsutil secure-all-zones [increase-serial]"<<endl
;
2368 UeberBackend
B("default");
2370 vector
<DomainInfo
> domainInfo
;
2371 B
.getAllDomains(&domainInfo
);
2373 unsigned int zonesSecured
=0, zoneErrors
=0;
2374 for(DomainInfo di
: domainInfo
) {
2375 if(!dk
.isSecuredZone(di
.zone
)) {
2376 cout
<<"Securing "<<di
.zone
<<": ";
2377 if (secureZone(dk
, di
.zone
)) {
2379 if (cmds
.size() == 2) {
2380 if (!increaseSerial(di
.zone
, dk
))
2389 cout
<<"Secured: "<<zonesSecured
<<" zones. Errors: "<<zoneErrors
<<endl
;
2396 else if(cmds
[0]=="set-kind") {
2397 if(cmds
.size() != 3) {
2398 cerr
<<"Syntax: pdnsutil set-kind ZONE KIND"<<endl
;
2400 DNSName
zone(cmds
[1]);
2401 auto kind
=DomainInfo::stringToKind(cmds
[2]);
2402 exit(setZoneKind(zone
, kind
));
2404 else if(cmds
[0]=="set-account") {
2405 if(cmds
.size() != 3) {
2406 cerr
<<"Syntax: pdnsutil set-account ZONE ACCOUNT"<<endl
;
2408 DNSName
zone(cmds
[1]);
2409 exit(setZoneAccount(zone
, cmds
[2]));
2411 else if(cmds
[0]=="set-nsec3") {
2412 if(cmds
.size() < 2) {
2413 cerr
<<"Syntax: pdnsutil set-nsec3 ZONE 'params' [narrow]"<<endl
;
2416 string nsec3params
= cmds
.size() > 2 ? cmds
[2] : "1 0 1 ab";
2417 bool narrow
= cmds
.size() > 3 && cmds
[3]=="narrow";
2418 NSEC3PARAMRecordContent
ns3pr(nsec3params
);
2420 DNSName
zone(cmds
[1]);
2421 if (zone
.wirelength() > 222) {
2422 cerr
<<"Cannot enable NSEC3 for " << zone
<< " as it is too long (" << zone
.wirelength() << " bytes, maximum is 222 bytes)"<<endl
;
2425 if(ns3pr
.d_algorithm
!= 1) {
2426 cerr
<<"NSEC3PARAM algorithm set to '"<<std::to_string(ns3pr
.d_algorithm
)<<"', but '1' is the only valid value"<<endl
;
2427 return EXIT_FAILURE
;
2429 if (! dk
.setNSEC3PARAM(zone
, ns3pr
, narrow
)) {
2430 cerr
<<"Cannot set NSEC3 param for " << zone
<< endl
;
2435 cerr
<<"NSEC3 set, ";
2437 cerr
<<"NSEC3 (opt-out) set, ";
2439 if(dk
.isSecuredZone(zone
))
2440 cerr
<<"please rectify your zone if your backend needs it"<<endl
;
2442 cerr
<<"please secure and rectify your zone."<<endl
;
2446 else if(cmds
[0]=="set-presigned") {
2447 if(cmds
.size() < 2) {
2448 cerr
<<"Syntax: pdnsutil set-presigned ZONE"<<endl
;
2451 if (! dk
.setPresigned(DNSName(cmds
[1]))) {
2452 cerr
<< "Could not set presigned for " << cmds
[1] << " (is DNSSEC enabled in your backend?)" << endl
;
2457 else if(cmds
[0]=="set-publish-cdnskey") {
2458 if(cmds
.size() < 2) {
2459 cerr
<<"Syntax: pdnsutil set-publish-cdnskey ZONE"<<endl
;
2462 if (! dk
.setPublishCDNSKEY(DNSName(cmds
[1]))) {
2463 cerr
<< "Could not set publishing for CDNSKEY records for "<< cmds
[1]<<endl
;
2468 else if(cmds
[0]=="set-publish-cds") {
2469 if(cmds
.size() < 2) {
2470 cerr
<<"Syntax: pdnsutil set-publish-cds ZONE [DIGESTALGOS]"<<endl
;
2474 // If DIGESTALGOS is unset
2475 if(cmds
.size() == 2)
2476 cmds
.push_back("1,2");
2478 if (! dk
.setPublishCDS(DNSName(cmds
[1]), cmds
[2])) {
2479 cerr
<< "Could not set publishing for CDS records for "<< cmds
[1]<<endl
;
2484 else if(cmds
[0]=="unset-presigned") {
2485 if(cmds
.size() < 2) {
2486 cerr
<<"Syntax: pdnsutil unset-presigned ZONE"<<endl
;
2489 if (! dk
.unsetPresigned(DNSName(cmds
[1]))) {
2490 cerr
<< "Could not unset presigned on for " << cmds
[1] << endl
;
2495 else if(cmds
[0]=="unset-publish-cdnskey") {
2496 if(cmds
.size() < 2) {
2497 cerr
<<"Syntax: pdnsutil unset-publish-cdnskey ZONE"<<endl
;
2500 if (! dk
.unsetPublishCDNSKEY(DNSName(cmds
[1]))) {
2501 cerr
<< "Could not unset publishing for CDNSKEY records for "<< cmds
[1]<<endl
;
2506 else if(cmds
[0]=="unset-publish-cds") {
2507 if(cmds
.size() < 2) {
2508 cerr
<<"Syntax: pdnsutil unset-publish-cds ZONE"<<endl
;
2511 if (! dk
.unsetPublishCDS(DNSName(cmds
[1]))) {
2512 cerr
<< "Could not unset publishing for CDS records for "<< cmds
[1]<<endl
;
2517 else if(cmds
[0]=="hash-zone-record") {
2518 if(cmds
.size() < 3) {
2519 cerr
<<"Syntax: pdnsutil hash-zone-record ZONE RNAME"<<endl
;
2522 DNSName
zone(cmds
[1]);
2523 DNSName
record(cmds
[2]);
2524 NSEC3PARAMRecordContent ns3pr
;
2526 if(!dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
)) {
2527 cerr
<<"The '"<<zone
<<"' zone does not use NSEC3"<<endl
;
2531 cerr
<<"The '"<<zone
<<"' zone uses narrow NSEC3, but calculating hash anyhow"<<endl
;
2534 cout
<<toBase32Hex(hashQNameWithSalt(ns3pr
, record
))<<endl
;
2536 else if(cmds
[0]=="unset-nsec3") {
2537 if(cmds
.size() < 2) {
2538 cerr
<<"Syntax: pdnsutil unset-nsec3 ZONE"<<endl
;
2541 if ( ! dk
.unsetNSEC3PARAM(DNSName(cmds
[1]))) {
2542 cerr
<<"Cannot unset NSEC3 param for " << cmds
[1] << endl
;
2547 else if(cmds
[0]=="export-zone-key") {
2548 if(cmds
.size() < 3) {
2549 cerr
<<"Syntax: pdnsutil export-zone-key ZONE KEY-ID"<<endl
;
2553 string zone
=cmds
[1];
2554 unsigned int id
=pdns_stou(cmds
[2]);
2555 DNSSECPrivateKey dpk
=dk
.getKeyById(DNSName(zone
), id
);
2556 cout
<< dpk
.getKey()->convertToISC() <<endl
;
2558 else if(cmds
[0]=="increase-serial") {
2559 if (cmds
.size() < 2) {
2560 cerr
<<"Syntax: pdnsutil increase-serial ZONE"<<endl
;
2563 return increaseSerial(DNSName(cmds
[1]), dk
);
2565 else if(cmds
[0]=="import-zone-key-pem") {
2566 if(cmds
.size() < 4) {
2567 cerr
<<"Syntax: pdnsutil import-zone-key-pem ZONE FILE ALGORITHM {ksk|zsk}"<<endl
;
2570 string zone
=cmds
[1];
2571 string fname
=cmds
[2];
2573 ifstream
ifs(fname
.c_str());
2574 string tmp
, interim
, raw
;
2575 while(getline(ifs
, line
)) {
2581 B64Decode(interim
, raw
);
2582 DNSSECPrivateKey dpk
;
2583 DNSKEYRecordContent drc
;
2584 shared_ptr
<DNSCryptoKeyEngine
> key(DNSCryptoKeyEngine::makeFromPEMString(drc
, raw
));
2587 dpk
.d_algorithm
= pdns_stou(cmds
[3]);
2589 if(dpk
.d_algorithm
== 7)
2590 dpk
.d_algorithm
= 5;
2592 cerr
<<(int)dpk
.d_algorithm
<<endl
;
2594 if(cmds
.size() > 4) {
2595 if(pdns_iequals(cmds
[4], "ZSK"))
2597 else if(pdns_iequals(cmds
[4], "KSK"))
2600 cerr
<<"Unknown key flag '"<<cmds
[4]<<"'"<<endl
;
2605 dpk
.d_flags
= 257; // ksk
2608 if (!dk
.addKey(DNSName(zone
), dpk
, id
)) {
2609 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2613 cerr
<<std::to_string(id
)<<"Key was added, but backend does not support returning of key id"<<endl
;
2614 } else if (id
< -1) {
2615 cerr
<<std::to_string(id
)<<"Key was added, but there was a failure while returning the key id"<<endl
;
2617 cout
<<std::to_string(id
)<<endl
;
2621 else if(cmds
[0]=="import-zone-key") {
2622 if(cmds
.size() < 3) {
2623 cerr
<<"Syntax: pdnsutil import-zone-key ZONE FILE [ksk|zsk] [active|inactive]"<<endl
;
2626 string zone
=cmds
[1];
2627 string fname
=cmds
[2];
2628 DNSSECPrivateKey dpk
;
2629 DNSKEYRecordContent drc
;
2630 shared_ptr
<DNSCryptoKeyEngine
> key(DNSCryptoKeyEngine::makeFromISCFile(drc
, fname
.c_str()));
2632 dpk
.d_algorithm
= drc
.d_algorithm
;
2634 if(dpk
.d_algorithm
== 7)
2635 dpk
.d_algorithm
= 5;
2640 for(unsigned int n
= 3; n
< cmds
.size(); ++n
) {
2641 if(pdns_iequals(cmds
[n
], "ZSK"))
2643 else if(pdns_iequals(cmds
[n
], "KSK"))
2645 else if(pdns_iequals(cmds
[n
], "active"))
2647 else if(pdns_iequals(cmds
[n
], "passive") || pdns_iequals(cmds
[n
], "inactive")) // passive eventually needs to be removed
2650 cerr
<<"Unknown key flag '"<<cmds
[n
]<<"'"<<endl
;
2655 if (!dk
.addKey(DNSName(zone
), dpk
, id
, active
)) {
2656 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2660 cerr
<<std::to_string(id
)<<"Key was added, but backend does not support returning of key id"<<endl
;
2661 } else if (id
< -1) {
2662 cerr
<<std::to_string(id
)<<"Key was added, but there was a failure while returning the key id"<<endl
;
2664 cout
<<std::to_string(id
)<<endl
;
2667 else if(cmds
[0]=="export-zone-dnskey") {
2668 if(cmds
.size() < 3) {
2669 cerr
<<"Syntax: pdnsutil export-zone-dnskey ZONE KEY-ID"<<endl
;
2673 DNSName
zone(cmds
[1]);
2674 unsigned int id
=pdns_stou(cmds
[2]);
2675 DNSSECPrivateKey dpk
=dk
.getKeyById(zone
, id
);
2676 cout
<< zone
<<" IN DNSKEY "<<dpk
.getDNSKEY().getZoneRepresentation() <<endl
;
2678 else if(cmds
[0] == "generate-zone-key") {
2679 if(cmds
.size() < 2 ) {
2680 cerr
<< "Syntax: pdnsutil generate-zone-key zsk|ksk [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384] [bits]"<<endl
;
2683 // need to get algorithm, bits & ksk or zsk from commandline
2684 bool keyOrZone
=false;
2687 int algorithm
=13; // ecdsa256
2688 for(unsigned int n
=1; n
< cmds
.size(); ++n
) {
2689 if(pdns_iequals(cmds
[n
], "zsk"))
2691 else if(pdns_iequals(cmds
[n
], "ksk"))
2693 else if((tmp_algo
= DNSSECKeeper::shorthand2algorithm(cmds
[n
]))>0) {
2694 algorithm
= tmp_algo
;
2695 } else if(pdns_stou(cmds
[n
]))
2696 bits
= pdns_stou(cmds
[n
]);
2698 cerr
<<"Unknown algorithm, key flag or size '"<<cmds
[n
]<<"'"<<endl
;
2702 cerr
<<"Generating a " << (keyOrZone
? "KSK" : "ZSK")<<" with algorithm = "<<algorithm
<<endl
;
2704 cerr
<<"Requesting specific key size of "<<bits
<<" bits"<<endl
;
2706 DNSSECPrivateKey dspk
;
2707 shared_ptr
<DNSCryptoKeyEngine
> dpk(DNSCryptoKeyEngine::make(algorithm
)); // defaults to RSA for now, could be smart w/algorithm! XXX FIXME
2710 bits
= keyOrZone
? 2048 : 1024;
2712 if(algorithm
== 12 || algorithm
== 13 || algorithm
== 15) // ECDSA, GOST, ED25519
2714 else if(algorithm
== 14)
2716 else if(algorithm
== 16) // ED448
2719 throw runtime_error("Can't guess key size for algorithm "+std::to_string(algorithm
));
2725 dspk
.d_algorithm
= algorithm
;
2726 dspk
.d_flags
= keyOrZone
? 257 : 256;
2728 // print key to stdout
2729 cout
<< "Flags: " << dspk
.d_flags
<< endl
<<
2730 dspk
.getKey()->convertToISC() << endl
;
2731 } else if (cmds
[0]=="generate-tsig-key") {
2732 string usage
= "Syntax: " + cmds
[0] + " name (hmac-md5|hmac-sha1|hmac-sha224|hmac-sha256|hmac-sha384|hmac-sha512)";
2733 if (cmds
.size() < 3) {
2734 cerr
<< usage
<< endl
;
2737 DNSName
name(cmds
[1]);
2738 string algo
= cmds
[2];
2743 if (algo
== "hmac-md5") {
2745 } else if (algo
== "hmac-sha1") {
2747 } else if (algo
== "hmac-sha224") {
2749 } else if (algo
== "hmac-sha256") {
2751 } else if (algo
== "hmac-sha384") {
2753 } else if (algo
== "hmac-sha512") {
2756 cerr
<< "Cannot generate key for " << algo
<< endl
;
2757 cerr
<< usage
<< endl
;
2761 cerr
<< "Generating new key with " << klen
<< " bytes" << endl
;
2762 for(size_t i
= 0; i
< klen
; i
+=4) {
2763 *(unsigned int*)(tmpkey
+i
) = dns_random(0xffffffff);
2765 key
= Base64Encode(std::string(tmpkey
, klen
));
2767 UeberBackend
B("default");
2768 if (B
.setTSIGKey(name
, DNSName(algo
), key
)) { // you are feeling bored, put up DNSName(algo) up earlier
2769 cout
<< "Create new TSIG key " << name
<< " " << algo
<< " " << key
<< endl
;
2771 cerr
<< "Failure storing new TSIG key " << name
<< " " << algo
<< " " << key
<< endl
;
2775 } else if (cmds
[0]=="import-tsig-key") {
2776 if (cmds
.size() < 4) {
2777 cerr
<< "Syntax: " << cmds
[0] << " name algorithm key" << endl
;
2780 DNSName
name(cmds
[1]);
2781 string algo
= cmds
[2];
2782 string key
= cmds
[3];
2784 UeberBackend
B("default");
2785 if (B
.setTSIGKey(name
, DNSName(algo
), key
)) {
2786 cout
<< "Imported TSIG key " << name
<< " " << algo
<< endl
;
2788 cerr
<< "Failure importing TSIG key " << name
<< " " << algo
<< endl
;
2792 } else if (cmds
[0]=="delete-tsig-key") {
2793 if (cmds
.size() < 2) {
2794 cerr
<< "Syntax: " << cmds
[0] << " name" << endl
;
2797 DNSName
name(cmds
[1]);
2799 UeberBackend
B("default");
2800 if (B
.deleteTSIGKey(name
)) {
2801 cout
<< "Deleted TSIG key " << name
<< endl
;
2803 cerr
<< "Failure deleting TSIG key " << name
<< endl
;
2807 } else if (cmds
[0]=="list-tsig-keys") {
2808 std::vector
<struct TSIGKey
> keys
;
2809 UeberBackend
B("default");
2810 if (B
.getTSIGKeys(keys
)) {
2811 for(const TSIGKey
&key
: keys
) {
2812 cout
<< key
.name
.toString() << " " << key
.algorithm
.toString() << " " << key
.key
<< endl
;
2816 } else if (cmds
[0]=="activate-tsig-key") {
2818 if (cmds
.size() < 4) {
2819 cerr
<< "Syntax: " << cmds
[0] << " ZONE NAME {master|slave}" << endl
;
2822 DNSName
zname(cmds
[1]);
2823 string name
= cmds
[2];
2824 if (cmds
[3] == "master")
2825 metaKey
= "TSIG-ALLOW-AXFR";
2826 else if (cmds
[3] == "slave")
2827 metaKey
= "AXFR-MASTER-TSIG";
2829 cerr
<< "Invalid parameter '" << cmds
[3] << "', expected master or slave" << endl
;
2832 UeberBackend
B("default");
2833 std::vector
<std::string
> meta
;
2834 if (!B
.getDomainMetadata(zname
, metaKey
, meta
)) {
2835 cerr
<< "Failure enabling TSIG key " << name
<< " for " << zname
<< endl
;
2839 for(std::string tmpname
: meta
) {
2840 if (tmpname
== name
) { found
= true; break; }
2842 if (!found
) meta
.push_back(name
);
2843 if (B
.setDomainMetadata(zname
, metaKey
, meta
)) {
2844 cout
<< "Enabled TSIG key " << name
<< " for " << zname
<< endl
;
2846 cerr
<< "Failure enabling TSIG key " << name
<< " for " << zname
<< endl
;
2850 } else if (cmds
[0]=="deactivate-tsig-key") {
2852 if (cmds
.size() < 4) {
2853 cerr
<< "Syntax: " << cmds
[0] << " ZONE NAME {master|slave}" << endl
;
2856 DNSName
zname(cmds
[1]);
2857 string name
= cmds
[2];
2858 if (cmds
[3] == "master")
2859 metaKey
= "TSIG-ALLOW-AXFR";
2860 else if (cmds
[3] == "slave")
2861 metaKey
= "AXFR-MASTER-TSIG";
2863 cerr
<< "Invalid parameter '" << cmds
[3] << "', expected master or slave" << endl
;
2867 UeberBackend
B("default");
2868 std::vector
<std::string
> meta
;
2869 if (!B
.getDomainMetadata(zname
, metaKey
, meta
)) {
2870 cerr
<< "Failure disabling TSIG key " << name
<< " for " << zname
<< endl
;
2873 std::vector
<std::string
>::iterator iter
= meta
.begin();
2874 for(;iter
!= meta
.end(); iter
++) if (*iter
== name
) break;
2875 if (iter
!= meta
.end()) meta
.erase(iter
);
2876 if (B
.setDomainMetadata(zname
, metaKey
, meta
)) {
2877 cout
<< "Disabled TSIG key " << name
<< " for " << zname
<< endl
;
2879 cerr
<< "Failure disabling TSIG key " << name
<< " for " << zname
<< endl
;
2883 } else if (cmds
[0]=="get-meta") {
2884 UeberBackend
B("default");
2885 if (cmds
.size() < 2) {
2886 cerr
<< "Syntax: " << cmds
[0] << " zone [kind kind ..]" << endl
;
2889 DNSName
zone(cmds
[1]);
2890 vector
<string
> keys
;
2893 if (!B
.getDomainInfo(zone
, di
)) {
2894 cerr
<< "Invalid zone '" << zone
<< "'" << endl
;
2898 if (cmds
.size() > 2) {
2899 keys
.assign(cmds
.begin() + 2, cmds
.end());
2900 std::cout
<< "Metadata for '" << zone
<< "'" << endl
;
2901 for(const string kind
: keys
) {
2902 vector
<string
> meta
;
2904 if (B
.getDomainMetadata(zone
, kind
, meta
)) {
2905 cout
<< kind
<< " = " << boost::join(meta
, ", ") << endl
;
2909 std::map
<std::string
, std::vector
<std::string
> > meta
;
2910 std::cout
<< "Metadata for '" << zone
<< "'" << endl
;
2911 B
.getAllDomainMetadata(zone
, meta
);
2912 for(std::map
<std::string
, std::vector
<std::string
> >::const_iterator each_meta
= meta
.begin(); each_meta
!= meta
.end(); each_meta
++) {
2913 cout
<< each_meta
->first
<< " = " << boost::join(each_meta
->second
, ", ") << endl
;
2918 } else if (cmds
[0]=="set-meta" || cmds
[0]=="add-meta") {
2919 if (cmds
.size() < 3) {
2920 cerr
<< "Syntax: " << cmds
[0] << " ZONE KIND [VALUE VALUE ..]" << endl
;
2923 DNSName
zone(cmds
[1]);
2924 string kind
= cmds
[2];
2925 static vector
<string
> multiMetaWhitelist
= {"ALLOW-AXFR-FROM", "ALLOW-DNSUPDATE-FROM",
2926 "ALSO-NOTIFY", "TSIG-ALLOW-AXFR", "TSIG-ALLOW-DNSUPDATE", "GSS-ALLOW-AXFR-PRINCIPAL",
2928 bool clobber
= true;
2929 if (cmds
[0] == "add-meta") {
2931 if (find(multiMetaWhitelist
.begin(), multiMetaWhitelist
.end(), kind
) == multiMetaWhitelist
.end() && kind
.find("X-") != 0) {
2932 cerr
<<"Refusing to add metadata to single-value metadata "<<kind
<<endl
;
2936 vector
<string
> meta(cmds
.begin() + 3, cmds
.end());
2937 return addOrSetMeta(zone
, kind
, meta
, clobber
);
2938 } else if (cmds
[0]=="hsm") {
2940 UeberBackend
B("default");
2941 if (cmds
[1] == "assign") {
2942 DNSCryptoKeyEngine::storvector_t storvect
;
2944 std::vector
<DNSBackend::KeyData
> keys
;
2946 if (cmds
.size() < 9) {
2947 std::cout
<< "Usage: pdnsutil hsm assign ZONE ALGORITHM {ksk|zsk} MODULE TOKEN PIN LABEL" << std::endl
;
2951 DNSName
zone(cmds
[2]);
2954 if (!B
.getDomainInfo(zone
, di
)) {
2955 cerr
<< "Unable to assign module to unknown zone '" << zone
<< "'" << std::endl
;
2959 int algorithm
= DNSSECKeeper::shorthand2algorithm(cmds
[3]);
2961 cerr
<< "Unable to use unknown algorithm '" << cmds
[3] << "'" << std::endl
;
2966 bool keyOrZone
= (cmds
[4] == "ksk" ? true : false);
2967 string module
= cmds
[5];
2968 string slot
= cmds
[6];
2969 string pin
= cmds
[7];
2970 string label
= cmds
[8];
2972 std::ostringstream iscString
;
2973 iscString
<< "Private-key-format: v1.2" << std::endl
<<
2974 "Algorithm: " << algorithm
<< std::endl
<<
2975 "Engine: " << module
<< std::endl
<<
2976 "Slot: " << slot
<< std::endl
<<
2977 "PIN: " << pin
<< std::endl
<<
2978 "Label: " << label
<< std::endl
;
2980 DNSKEYRecordContent drc
;
2981 DNSSECPrivateKey dpk
;
2982 dpk
.d_flags
= (keyOrZone
? 257 : 256);
2984 shared_ptr
<DNSCryptoKeyEngine
> dke(DNSCryptoKeyEngine::makeFromISCString(drc
, iscString
.str()));
2985 if(!dke
->checkKey()) {
2986 cerr
<< "Invalid DNS Private Key in engine " << module
<< " slot " << slot
<< std::endl
;
2991 // make sure this key isn't being reused.
2992 B
.getDomainKeys(zone
, keys
);
2995 for(DNSBackend::KeyData
& kd
: keys
) {
2996 if (kd
.content
== iscString
.str()) {
2997 // it's this one, I guess...
3004 cerr
<< "You have already assigned this key with ID=" << id
<< std::endl
;
3008 if (!dk
.addKey(zone
, dpk
, id
)) {
3009 cerr
<< "Unable to assign module slot to zone" << std::endl
;
3013 cerr
<< "Module " << module
<< " slot " << slot
<< " assigned to " << zone
<< " with key id " << id
<< endl
;
3016 } else if (cmds
[1] == "create-key") {
3018 if (cmds
.size() < 4) {
3019 cerr
<< "Usage: pdnsutil hsm create-key ZONE KEY-ID [BITS]" << endl
;
3023 DNSName
zone(cmds
[2]);
3027 if (!B
.getDomainInfo(zone
, di
)) {
3028 cerr
<< "Unable to create key for unknown zone '" << zone
<< "'" << std::endl
;
3032 id
= pdns_stou(cmds
[3]);
3033 std::vector
<DNSBackend::KeyData
> keys
;
3034 if (!B
.getDomainKeys(zone
, keys
)) {
3035 cerr
<< "No keys found for zone " << zone
<< std::endl
;
3039 std::shared_ptr
<DNSCryptoKeyEngine
> dke
= nullptr;
3040 // lookup correct key
3041 for(DNSBackend::KeyData
&kd
: keys
) {
3044 DNSKEYRecordContent dkrc
;
3045 dke
= DNSCryptoKeyEngine::makeFromISCString(dkrc
, kd
.content
);
3050 cerr
<< "Could not find key with ID " << id
<< endl
;
3053 if (cmds
.size() > 4) {
3054 bits
= pdns_stou(cmds
[4]);
3057 cerr
<< "Invalid bit size " << bits
<< "given, must be positive integer";
3062 } catch (PDNSException
& e
) {
3063 cerr
<< e
.reason
<< endl
;
3067 cerr
<< "Key of size " << bits
<< " created" << std::endl
;
3071 cerr
<<"PKCS#11 support not enabled"<<endl
;
3074 } else if (cmds
[0] == "b2b-migrate") {
3075 if (cmds
.size() < 3) {
3076 cerr
<<"Usage: b2b-migrate OLD NEW"<<endl
;
3080 DNSBackend
*src
,*tgt
;
3083 for(DNSBackend
*b
: BackendMakers().all()) {
3084 if (b
->getPrefix() == cmds
[1]) src
= b
;
3085 if (b
->getPrefix() == cmds
[2]) tgt
= b
;
3088 cerr
<<"Unknown source backend '"<<cmds
[1]<<"'"<<endl
;
3092 cerr
<<"Unknown target backend '"<<cmds
[2]<<"'"<<endl
;
3096 cout
<<"Moving zone(s) from "<<src
->getPrefix()<<" to "<<tgt
->getPrefix()<<endl
;
3098 vector
<DomainInfo
> domains
;
3100 tgt
->getAllDomains(&domains
, true);
3101 if (domains
.size()>0)
3102 throw PDNSException("Target backend has domain(s), please clean it first");
3104 src
->getAllDomains(&domains
, true);
3106 for(const DomainInfo
& di
: domains
) {
3108 DNSResourceRecord rr
;
3109 cout
<<"Processing '"<<di
.zone
<<"'"<<endl
;
3111 if (!tgt
->createDomain(di
.zone
)) throw PDNSException("Failed to create zone");
3112 tgt
->setKind(di
.zone
, di
.kind
);
3113 tgt
->setAccount(di
.zone
,di
.account
);
3116 for(const string
& master
: di
.masters
) {
3122 tgt
->setMaster(di
.zone
, masters
);
3124 if (!src
->list(di
.zone
, di
.id
, true)) throw PDNSException("Failed to list records");
3126 while(src
->get(rr
)) {
3127 if (!tgt
->feedRecord(rr
, DNSName())) throw PDNSException("Failed to feed record");
3132 if (src
->listComments(di
.id
)) {
3134 while(src
->getComment(c
)) {
3135 tgt
->feedComment(c
);
3141 std::map
<std::string
, std::vector
<std::string
> > meta
;
3142 if (src
->getAllDomainMetadata(di
.zone
, meta
)) {
3143 std::map
<std::string
, std::vector
<std::string
> >::iterator i
;
3144 for(i
=meta
.begin(); i
!= meta
.end(); i
++) {
3145 if (!tgt
->setDomainMetadata(di
.zone
, i
->first
, i
->second
)) throw PDNSException("Failed to feed domain metadata");
3151 // temp var for KeyID
3153 std::vector
<DNSBackend::KeyData
> keys
;
3154 if (src
->getDomainKeys(di
.zone
, keys
)) {
3155 for(const DNSBackend::KeyData
& k
: keys
) {
3156 tgt
->addDomainKey(di
.zone
, k
, keyID
);
3160 cout
<<"Moved "<<nr
<<" record(s), "<<nc
<<" comment(s), "<<nm
<<" metadata(s) and "<<nk
<<" cryptokey(s)"<<endl
;
3165 std::vector
<struct TSIGKey
> tkeys
;
3166 if (src
->getTSIGKeys(tkeys
)) {
3167 for(auto& tk
: tkeys
) {
3168 if (!tgt
->setTSIGKey(tk
.name
, tk
.algorithm
, tk
.key
)) throw PDNSException("Failed to feed TSIG key");
3172 cout
<<"Moved "<<ntk
<<" TSIG key(s)"<<endl
;
3174 cout
<<"Remember to drop the old backend and run rectify-all-zones"<<endl
;
3177 } else if (cmds
[0] == "backend-cmd") {
3178 if (cmds
.size() < 3) {
3179 cerr
<<"Usage: backend-cmd BACKEND CMD [CMD..]"<<endl
;
3186 for(DNSBackend
*b
: BackendMakers().all()) {
3187 if (b
->getPrefix() == cmds
[1]) db
= b
;
3191 cerr
<<"Unknown backend '"<<cmds
[1]<<"'"<<endl
;
3195 for(auto i
=next(begin(cmds
),2); i
!= end(cmds
); ++i
) {
3196 cerr
<<"== "<<*i
<<endl
;
3197 cout
<<db
->directBackendCmd(*i
);
3202 cerr
<<"Unknown command '"<<cmds
[0] <<"'"<< endl
;
3207 catch(PDNSException
& ae
) {
3208 cerr
<<"Error: "<<ae
.reason
<<endl
;
3211 catch(std::exception
& e
) {
3212 cerr
<<"Error: "<<e
.what()<<endl
;
3217 cerr
<<"Caught an unknown exception"<<endl
;