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("resolver","Use this resolver for ALIAS and the internal stub resolver")="no";
84 ::arg().set("default-ksk-algorithm","Default KSK algorithm")="ecdsa256";
85 ::arg().set("default-ksk-size","Default KSK size (0 means default)")="0";
86 ::arg().set("default-zsk-algorithm","Default ZSK algorithm")="";
87 ::arg().set("default-zsk-size","Default ZSK size (0 means default)")="0";
88 ::arg().set("default-soa-edit","Default SOA-EDIT value")="";
89 ::arg().set("default-soa-edit-signed","Default SOA-EDIT value for signed zones")="";
90 ::arg().set("max-ent-entries", "Maximum number of empty non-terminals in a zone")="100000";
91 ::arg().set("module-dir","Default directory for modules")=PKGLIBDIR
;
92 ::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom";
93 ::arg().setSwitch("query-logging","Hint backends that queries should be logged")="no";
94 ::arg().set("loglevel","Amount of logging. Higher is more.")="3";
95 ::arg().setSwitch("direct-dnskey","Fetch DNSKEY RRs from backend during DNSKEY synthesis")="no";
96 ::arg().set("max-nsec3-iterations","Limit the number of NSEC3 hash iterations")="500"; // RFC5155 10.3
97 ::arg().set("max-signature-cache-entries", "Maximum number of signatures cache entries")="";
98 ::arg().laxFile(configname
.c_str());
100 L
.toConsole(Logger::Error
); // so we print any errors
101 BackendMakers().launch(::arg()["launch"]); // vrooooom!
102 if(::arg().asNum("loglevel") >= 3) // so you can't kill our errors
103 L
.toConsole((Logger::Urgency
)::arg().asNum("loglevel"));
105 //cerr<<"Backend: "<<::arg()["launch"]<<", '" << ::arg()["gmysql-dbname"] <<"'" <<endl;
107 S
.declare("qsize-q","Number of questions waiting for database attention");
109 ::arg().set("max-cache-entries", "Maximum number of cache entries")="1000000";
110 ::arg().set("cache-ttl","Seconds to store packets in the PacketCache")="20";
111 ::arg().set("negquery-cache-ttl","Seconds to store negative query results in the QueryCache")="60";
112 ::arg().set("query-cache-ttl","Seconds to store query results in the QueryCache")="20";
113 ::arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server";
114 ::arg().set("default-soa-mail","mail address to insert in the SOA record if none set in the backend")="";
115 ::arg().set("soa-refresh-default","Default SOA refresh")="10800";
116 ::arg().set("soa-retry-default","Default SOA retry")="3600";
117 ::arg().set("soa-expire-default","Default SOA expire")="604800";
118 ::arg().set("soa-minimum-ttl","Default SOA minimum ttl")="3600";
119 ::arg().set("chroot","Switch to this chroot jail")="";
120 ::arg().set("dnssec-key-cache-ttl","Seconds to cache DNSSEC keys from the database")="30";
121 ::arg().set("domain-metadata-cache-ttl","Seconds to cache domain metadata from the database")="60";
123 // Keep this line below all ::arg().set() statements
124 if (! ::arg().laxFile(configname
.c_str()))
125 cerr
<<"Warning: unable to read configuration file '"<<configname
<<"': "<<strerror(errno
)<<endl
;
127 seedRandom(::arg()["entropy-source"]);
129 #ifdef HAVE_LIBSODIUM
130 if (sodium_init() == -1) {
131 cerr
<<"Unable to initialize sodium crypto library"<<endl
;
138 if (!::arg()["chroot"].empty()) {
139 if (chroot(::arg()["chroot"].c_str())<0 || chdir("/") < 0) {
140 cerr
<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror (errno
)<<endl
;
148 bool rectifyZone(DNSSECKeeper
& dk
, const DNSName
& zone
, bool quiet
= false)
152 bool ret
= dk
.rectifyZone(zone
, error
, output
, true);
153 if (!quiet
|| !ret
) {
154 // When quiet, only print output if there was an error
155 if (!output
.empty()) {
158 if (!ret
&& !error
.empty()) {
165 void dbBench(const std::string
& fname
)
167 ::arg().set("query-cache-ttl")="0";
168 ::arg().set("negquery-cache-ttl")="0";
169 UeberBackend
B("default");
171 vector
<string
> domains
;
173 ifstream
ifs(fname
.c_str());
175 cerr
<<"Could not open '"<<fname
<<"' for reading domain names to query"<<endl
;
178 while(getline(ifs
,line
)) {
180 domains
.push_back(line
);
184 domains
.push_back("powerdns.com");
190 unsigned int hits
=0, misses
=0;
191 for(; n
< 10000; ++n
) {
192 DNSName
domain(domains
[random() % domains
.size()]);
193 B
.lookup(QType(QType::NS
), domain
);
197 B
.lookup(QType(QType::A
), DNSName(std::to_string(random()))+domain
);
203 cout
<<0.001*dt
.udiff()/n
<<" millisecond/lookup"<<endl
;
204 cout
<<"Retrieved "<<hits
<<" records, did "<<misses
<<" queries which should have no match"<<endl
;
205 cout
<<"Packet cache reports: "<<S
.read("query-cache-hit")<<" hits (should be 0) and "<<S
.read("query-cache-miss") <<" misses"<<endl
;
208 bool rectifyAllZones(DNSSECKeeper
&dk
, bool quiet
= false)
210 UeberBackend
B("default");
211 vector
<DomainInfo
> domainInfo
;
214 B
.getAllDomains(&domainInfo
);
215 for(DomainInfo di
: domainInfo
) {
217 cerr
<<"Rectifying "<<di
.zone
<<": ";
219 if (!rectifyZone(dk
, di
.zone
, quiet
)) {
224 cout
<<"Rectified "<<domainInfo
.size()<<" zones."<<endl
;
229 int checkZone(DNSSECKeeper
&dk
, UeberBackend
&B
, const DNSName
& zone
, const vector
<DNSResourceRecord
>* suppliedrecords
=0)
232 if(!B
.getSOAUncached(zone
, sd
)) {
233 cout
<<"[error] No SOA record present, or active, in zone '"<<zone
<<"'"<<endl
;
234 cout
<<"Checked 0 records of '"<<zone
<<"', 1 errors, 0 warnings."<<endl
;
238 NSEC3PARAMRecordContent ns3pr
;
240 bool haveNSEC3
= dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
241 bool isOptOut
=(haveNSEC3
&& ns3pr
.d_flags
);
243 bool isSecure
=dk
.isSecuredZone(zone
);
244 bool presigned
=dk
.isPresigned(zone
);
245 bool validKeys
=dk
.checkKeys(zone
);
247 uint64_t numrecords
=0, numerrors
=0, numwarnings
=0;
250 if(isSecure
&& zone
.wirelength() > 222) {
252 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
;
255 vector
<DNSBackend::KeyData
> dbkeyset
;
256 B
.getDomainKeys(zone
, dbkeyset
);
258 for(DNSBackend::KeyData
& kd
: dbkeyset
) {
259 DNSKEYRecordContent dkrc
;
260 shared_ptr
<DNSCryptoKeyEngine
>(DNSCryptoKeyEngine::makeFromISCString(dkrc
, kd
.content
));
262 if(dkrc
.d_algorithm
== DNSSECKeeper::RSASHA1
) {
263 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
;
271 cout
<<"[Error] zone '" << zone
<< "' has at least one invalid DNS Private Key." << endl
;
274 // Check for delegation in parent zone
275 DNSName
parent(zone
);
276 while(parent
.chopOff()) {
278 if(B
.getSOAUncached(parent
, sd_p
)) {
281 B
.lookup(QType(QType::ANY
), zone
, NULL
, sd_p
.domain_id
);
283 ns
|= (zr
.dr
.d_type
== QType::NS
);
285 cout
<<"[Error] No delegation for zone '"<<zone
<<"' in parent '"<<parent
<<"'"<<endl
;
293 bool hasNsAtApex
= false;
294 set
<DNSName
> tlsas
, cnames
, noncnames
, glue
, checkglue
;
295 set
<pair
<DNSName
, QType
> > recs
, checkOcclusion
;
296 set
<string
> recordcontents
;
297 map
<string
, unsigned int> ttl
;
299 ostringstream content
;
300 pair
<map
<string
, unsigned int>::iterator
,bool> ret
;
302 vector
<DNSResourceRecord
> records
;
303 if(!suppliedrecords
) {
304 DNSResourceRecord drr
;
305 sd
.db
->list(zone
, sd
.domain_id
, g_verbose
);
306 while(sd
.db
->get(drr
)) {
307 records
.push_back(drr
);
311 records
=*suppliedrecords
;
313 for(auto rr
: records
) { // we modify this
314 // if(!rr.qtype.getCode()) {
315 // if(rr.content.length()) {
316 // cout<<"[Error] ENT (or unknown type) has content: "<<rr.qname<<" IN " <<rr.qtype.getName()<< " '" << rr.content<<"'"<<endl;
324 if(rr
.qtype
.getCode() == QType::TLSA
)
325 tlsas
.insert(rr
.qname
);
326 if(rr
.qtype
.getCode() == QType::SOA
) {
328 stringtok(parts
, rr
.content
);
332 for(int pleft
=parts
.size(); pleft
< 7; ++pleft
) {
338 if(rr
.qtype
.getCode() == QType::TXT
&& !rr
.content
.empty() && rr
.content
[0]!='"')
339 rr
.content
= "\""+rr
.content
+"\"";
342 shared_ptr
<DNSRecordContent
> drc(DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, rr
.content
));
343 string tmp
=drc
->serialize(rr
.qname
);
344 tmp
= drc
->getZoneRepresentation(true);
345 if (rr
.qtype
.getCode() != QType::AAAA
) {
346 if (!pdns_iequals(tmp
, rr
.content
)) {
347 if(rr
.qtype
.getCode() == QType::SOA
) {
348 tmp
= drc
->getZoneRepresentation(false);
350 if(!pdns_iequals(tmp
, rr
.content
)) {
351 cout
<<"[Warning] Parsed and original record content are not equal: "<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<< " '" << rr
.content
<<"' (Content parsed as '"<<tmp
<<"')"<<endl
;
356 struct in6_addr tmpbuf
;
357 if (inet_pton(AF_INET6
, rr
.content
.c_str(), &tmpbuf
) != 1 || rr
.content
.find('.') != string::npos
) {
358 cout
<<"[Warning] Following record is not a valid IPv6 address: "<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<< " '" << rr
.content
<<"'"<<endl
;
363 catch(std::exception
& e
)
365 cout
<<"[Error] Following record had a problem: \""<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"\""<<endl
;
366 cout
<<"[Error] Error was: "<<e
.what()<<endl
;
371 if(!rr
.qname
.isPartOf(zone
)) {
372 cout
<<"[Error] Record '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
<<"' is out-of-zone."<<endl
;
378 content
<<rr
.qname
<<" "<<rr
.qtype
.getName()<<" "<<rr
.content
;
379 if (recordcontents
.count(toLower(content
.str()))) {
380 cout
<<"[Error] Duplicate record found in rrset: '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"'"<<endl
;
384 recordcontents
.insert(toLower(content
.str()));
387 content
<<rr
.qname
<<" "<<rr
.qtype
.getName();
388 if (rr
.qtype
.getCode() == QType::RRSIG
) {
389 RRSIGRecordContent
rrc(rr
.content
);
390 content
<<" ("<<DNSRecordContent::NumberToType(rrc
.d_type
)<<")";
392 ret
= ttl
.insert(pair
<string
, unsigned int>(toLower(content
.str()), rr
.ttl
));
393 if (ret
.second
== false && ret
.first
->second
!= rr
.ttl
) {
394 cout
<<"[Error] TTL mismatch in rrset: '"<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<<" "<<rr
.content
<<"' ("<<ret
.first
->second
<<" != "<<rr
.ttl
<<")"<<endl
;
399 if (isSecure
&& isOptOut
&& (rr
.qname
.countLabels() && rr
.qname
.getRawLabels()[0] == "*")) {
400 cout
<<"[Warning] wildcard record '"<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<<" "<<rr
.content
<<"' is insecure"<<endl
;
401 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
;
406 if (rr
.qtype
.getCode() == QType::NS
) {
408 } else if (rr
.qtype
.getCode() == QType::DS
) {
409 cout
<<"[Warning] DS at apex in zone '"<<zone
<<"', should not be here."<<endl
;
413 if (rr
.qtype
.getCode() == QType::SOA
) {
414 cout
<<"[Error] SOA record not at apex '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
<<"'"<<endl
;
417 } else if (rr
.qtype
.getCode() == QType::DNSKEY
) {
418 cout
<<"[Warning] DNSKEY record not at apex '"<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.content
<<"' in zone '"<<zone
<<"', should not be here."<<endl
;
420 } else if (rr
.qtype
.getCode() == QType::NS
) {
421 if (DNSName(rr
.content
).isPartOf(rr
.qname
)) {
422 checkglue
.insert(DNSName(toLower(rr
.content
)));
424 checkOcclusion
.insert({rr
.qname
, rr
.qtype
});
425 } else if (rr
.qtype
.getCode() == QType::A
|| rr
.qtype
.getCode() == QType::AAAA
) {
426 glue
.insert(rr
.qname
);
427 } else if (rr
.qtype
== QType::DNAME
) {
428 checkOcclusion
.insert({rr
.qname
, rr
.qtype
});
431 if (rr
.qtype
!= QType::NS
&& rr
.qtype
!= QType::DS
&& rr
.qtype
!= QType::DNAME
) {
432 recs
.insert({rr
.qname
, rr
.qtype
});
436 if((rr
.qtype
.getCode() == QType::A
|| rr
.qtype
.getCode() == QType::AAAA
) && !rr
.qname
.isWildcard() && !rr
.qname
.isHostname())
437 cout
<<"[Info] "<<rr
.qname
.toString()<<" record for '"<<rr
.qtype
.getName()<<"' is not a valid hostname."<<endl
;
439 // Check if the DNSNames that should be hostnames, are hostnames
440 if (rr
.qtype
.getCode() == QType::NS
|| rr
.qtype
.getCode() == QType::MX
|| rr
.qtype
.getCode() == QType::SRV
) {
442 if (rr
.qtype
.getCode() == QType::SRV
) {
443 vector
<string
> parts
;
444 stringtok(parts
, rr
.getZoneRepresentation());
445 if (parts
.size() == 4) toCheck
= DNSName(parts
[3]);
446 } else if (rr
.qtype
.getCode() == QType::MX
) {
447 vector
<string
> parts
;
448 stringtok(parts
, rr
.getZoneRepresentation());
449 if (parts
.size() == 2) toCheck
= DNSName(parts
[1]);
451 toCheck
= DNSName(rr
.content
);
455 cout
<<"[Warning] "<<rr
.qtype
.getName()<<" record in zone '"<<zone
<<"': unable to extract hostname from content."<<endl
;
456 else if(!toCheck
.isHostname()) {
457 cout
<<"[Warning] "<<rr
.qtype
.getName()<<" record in zone '"<<zone
<<"' has non-hostname content '"<<toCheck
.toString()<<"'."<<endl
;
462 if (rr
.qtype
.getCode() == QType::CNAME
) {
463 if (!cnames
.count(rr
.qname
))
464 cnames
.insert(rr
.qname
);
466 cout
<<"[Error] Duplicate CNAME found at '"<<rr
.qname
<<"'"<<endl
;
471 if (rr
.qtype
.getCode() == QType::RRSIG
) {
473 cout
<<"[Error] RRSIG found at '"<<rr
.qname
<<"' in non-presigned zone. These do not belong in the database."<<endl
;
478 noncnames
.insert(rr
.qname
);
481 if(rr
.qtype
.getCode() == QType::NSEC
|| rr
.qtype
.getCode() == QType::NSEC3
)
483 cout
<<"[Error] NSEC or NSEC3 found at '"<<rr
.qname
<<"'. These do not belong in the database."<<endl
;
488 if(!presigned
&& rr
.qtype
.getCode() == QType::DNSKEY
)
490 if(::arg().mustDo("direct-dnskey"))
492 if(rr
.ttl
!= sd
.default_ttl
)
494 cout
<<"[Warning] DNSKEY TTL of "<<rr
.ttl
<<" at '"<<rr
.qname
<<"' differs from SOA minimum of "<<sd
.default_ttl
<<endl
;
500 cout
<<"[Warning] DNSKEY at '"<<rr
.qname
<<"' in non-presigned zone will mostly be ignored and can cause problems."<<endl
;
505 if(!suppliedrecords
&& rr
.auth
== 0 && rr
.qtype
.getCode()!=QType::NS
&& rr
.qtype
.getCode()!=QType::A
&& rr
.qtype
.getCode()!=QType::AAAA
)
507 cout
<<"[Error] Following record is auth=0, run pdnsutil rectify-zone?: "<<rr
.qname
<<" IN " <<rr
.qtype
.getName()<< " " << rr
.content
<<endl
;
512 for(auto &i
: cnames
) {
513 if (noncnames
.find(i
) != noncnames
.end()) {
514 cout
<<"[Error] CNAME "<<i
<<" found, but other records with same label exist."<<endl
;
519 for(const auto &i
: tlsas
) {
520 DNSName name
= DNSName(i
);
521 name
.trimToLabels(name
.countLabels()-2);
522 if (cnames
.find(name
) == cnames
.end() && noncnames
.find(name
) == noncnames
.end()) {
523 // No specific record for the name in the TLSA record exists, this
524 // is already worth emitting a warning. Let's see if a wildcard exist.
526 DNSName
wcname(name
);
528 wcname
.prependRawLabel("*");
529 if (cnames
.find(wcname
) != cnames
.end() || noncnames
.find(wcname
) != noncnames
.end()) {
530 cout
<<"A wildcard record exist for '"<<wcname
<<"' and a TLSA record for '"<<i
<<"'.";
532 cout
<<"No record for '"<<name
<<"' exists, but a TLSA record for '"<<i
<<"' does.";
535 cout
<<" A query for '"<<name
<<"' will yield an empty response. This is most likely a mistake, please create records for '"<<name
<<"'."<<endl
;
540 cout
<<"[Error] No NS record at zone apex in zone '"<<zone
<<"'"<<endl
;
544 for(const auto &qname
: checkglue
) {
545 if (!glue
.count(qname
)) {
546 cout
<<"[Warning] Missing glue for '"<<qname
<<"' in zone '"<<zone
<<"'"<<endl
;
551 for(const auto &qname
: checkOcclusion
) {
552 for (const auto &q
: recs
) {
553 if (q
.first
.isPartOf(qname
.first
) && !checkglue
.count(q
.first
)) {
554 cout
<<"[Warning] '"<<q
.first
<<"|"<<q
.second
.getName()<<"' in zone '"<<zone
<<"' is occluded by a ";
555 if (qname
.second
== QType::NS
) {
558 if (qname
.second
== QType::DNAME
) {
561 cout
<<" at '"<<qname
.first
<<"'"<<endl
;
567 cout
<<"Checked "<<numrecords
<<" records of '"<<zone
<<"', "<<numerrors
<<" errors, "<<numwarnings
<<" warnings."<<endl
;
573 int checkAllZones(DNSSECKeeper
&dk
, bool exitOnError
)
575 UeberBackend
B("default");
576 vector
<DomainInfo
> domainInfo
;
578 B
.getAllDomains(&domainInfo
, true);
580 for(auto di
: domainInfo
) {
581 if (checkZone(dk
, B
, di
.zone
) > 0) {
587 cout
<<"Checked "<<domainInfo
.size()<<" zones, "<<errors
<<" had errors."<<endl
;
593 int increaseSerial(const DNSName
& zone
, DNSSECKeeper
&dk
)
595 UeberBackend
B("default");
597 if(!B
.getSOAUncached(zone
, sd
)) {
598 cerr
<<"No SOA for zone '"<<zone
<<"'"<<endl
;
602 if (dk
.isPresigned(zone
)) {
603 cerr
<<"Serial increase of presigned zone '"<<zone
<<"' is not allowed."<<endl
;
608 dk
.getSoaEdit(zone
, soaEditKind
);
610 DNSResourceRecord rr
;
611 makeIncreasedSOARecord(sd
, "SOA-EDIT-INCREASE", soaEditKind
, rr
);
613 sd
.db
->startTransaction(zone
, -1);
615 if (!sd
.db
->replaceRRSet(sd
.domain_id
, zone
, rr
.qtype
, vector
<DNSResourceRecord
>(1, rr
))) {
616 sd
.db
->abortTransaction();
617 cerr
<<"Backend did not replace SOA record. Backend might not support this operation."<<endl
;
621 if (sd
.db
->doesDNSSEC()) {
622 NSEC3PARAMRecordContent ns3pr
;
624 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
629 ordername
=DNSName(toBase32Hex(hashQNameWithSalt(ns3pr
, zone
))) + zone
;
633 cerr
<<"'"<<rr
.qname
<<"' -> '"<< ordername
<<"'"<<endl
;
634 sd
.db
->updateDNSSECOrderNameAndAuth(sd
.domain_id
, rr
.qname
, ordername
, true);
637 sd
.db
->commitTransaction();
639 cout
<<"SOA serial for zone "<<zone
<<" set to "<<sd
.serial
<<endl
;
643 int deleteZone(const DNSName
&zone
) {
646 if (! B
.getDomainInfo(zone
, di
)) {
647 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
651 if(di
.backend
->deleteDomain(zone
))
654 cerr
<<"Failed to delete domain '"<<zone
<<"'"<<endl
;;
658 void listKey(DomainInfo
const &di
, DNSSECKeeper
& dk
, bool printHeader
= true) {
660 cout
<<"Zone Type Size Algorithm ID Location Keytag"<<endl
;
661 cout
<<"----------------------------------------------------------------------------------"<<endl
;
663 unsigned int spacelen
= 0;
664 for (auto const &key
: dk
.getKeys(di
.zone
)) {
666 if (di
.zone
.toStringNoDot().length() > 29)
667 cout
<<endl
<<string(30, ' ');
669 cout
<<string(30 - di
.zone
.toStringNoDot().length(), ' ');
671 cout
<<DNSSECKeeper::keyTypeToString(key
.second
.keyType
)<<" ";
673 spacelen
= (std::to_string(key
.first
.getKey()->getBits()).length() >= 8) ? 1 : 8 - std::to_string(key
.first
.getKey()->getBits()).length();
674 if (key
.first
.getKey()->getBits() < 1) {
675 cout
<<"invalid "<<endl
;
678 cout
<<key
.first
.getKey()->getBits()<<string(spacelen
, ' ');
681 string algname
= DNSSECKeeper::algorithm2name(key
.first
.d_algorithm
);
682 spacelen
= (algname
.length() >= 13) ? 1 : 13 - algname
.length();
683 cout
<<algname
<<string(spacelen
, ' ');
685 spacelen
= (std::to_string(key
.second
.id
).length() > 5) ? 1 : 5 - std::to_string(key
.second
.id
).length();
686 cout
<<key
.second
.id
<<string(spacelen
, ' ');
689 auto stormap
= key
.first
.getKey()->convertToISCVector();
690 string engine
, slot
, label
= "";
691 for (auto const &elem
: stormap
) {
692 //cout<<elem.first<<" "<<elem.second<<endl;
693 if (elem
.first
== "Engine")
694 engine
= elem
.second
;
695 if (elem
.first
== "Slot")
697 if (elem
.first
== "Label")
700 if (engine
.empty() || slot
.empty()){
703 spacelen
= (engine
.length()+slot
.length()+label
.length()+2 >= 12) ? 1 : 12 - engine
.length()-slot
.length()-label
.length()-2;
704 cout
<<engine
<<","<<slot
<<","<<label
<<string(spacelen
, ' ');
709 cout
<<key
.first
.getDNSKEY().getTag()<<endl
;
713 int listKeys(const string
&zname
, DNSSECKeeper
& dk
){
714 UeberBackend
B("default");
716 if (zname
!= "all") {
718 if(!B
.getDomainInfo(DNSName(zname
), di
)) {
719 cerr
<< "Zone "<<zname
<<" not found."<<endl
;
724 vector
<DomainInfo
> domainInfo
;
725 B
.getAllDomains(&domainInfo
);
726 bool printHeader
= true;
727 for (auto const di
: domainInfo
) {
728 listKey(di
, dk
, printHeader
);
735 int listZone(const DNSName
&zone
) {
739 if (! B
.getDomainInfo(zone
, di
)) {
740 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
743 di
.backend
->list(zone
, di
.id
);
744 DNSResourceRecord rr
;
745 cout
<<"$ORIGIN ."<<endl
;
746 while(di
.backend
->get(rr
)) {
747 if(rr
.qtype
.getCode()) {
748 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] != '.')
749 rr
.content
.append(1, '.');
751 cout
<<rr
.qname
<<"\t"<<rr
.ttl
<<"\tIN\t"<<rr
.qtype
.getName()<<"\t"<<rr
.content
<<endl
;
757 // lovingly copied from http://stackoverflow.com/questions/1798511/how-to-avoid-press-enter-with-any-getchar
760 static struct termios oldt
, newt
;
762 /*tcgetattr gets the parameters of the current terminal
763 STDIN_FILENO will tell tcgetattr that it should write the settings
765 tcgetattr( STDIN_FILENO
, &oldt
);
766 /*now the settings will be copied*/
769 /*ICANON normally takes care that one line at a time will be processed
770 that means it will return if it sees a "\n" or an EOF or an EOL*/
771 newt
.c_lflag
&= ~(ICANON
);
773 /*Those new settings will be set to STDIN
774 TCSANOW tells tcsetattr to change attributes immediately. */
775 tcsetattr( STDIN_FILENO
, TCSANOW
, &newt
);
779 /*restore the old settings*/
780 tcsetattr( STDIN_FILENO
, TCSANOW
, &oldt
);
785 int clearZone(DNSSECKeeper
& dk
, const DNSName
&zone
) {
789 if (! B
.getDomainInfo(zone
, di
)) {
790 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
793 if(!di
.backend
->startTransaction(zone
, di
.id
)) {
794 cerr
<<"Unable to start transaction for load of zone '"<<zone
<<"'"<<endl
;
797 di
.backend
->commitTransaction();
801 int editZone(DNSSECKeeper
& dk
, const DNSName
&zone
) {
805 if (! B
.getDomainInfo(zone
, di
)) {
806 cerr
<<"Domain '"<<zone
<<"' not found!"<<endl
;
809 vector
<DNSRecord
> pre
, post
;
810 char tmpnam
[]="/tmp/pdnsutil-XXXXXX";
811 int tmpfd
=mkstemp(tmpnam
);
813 unixDie("Making temporary filename in "+string(tmpnam
));
815 ~deleteme() { unlink(d_name
.c_str()); }
816 deleteme(string name
) : d_name(name
) {}
820 vector
<DNSResourceRecord
> checkrr
;
822 string editor
="editor";
823 if(auto e
=getenv("EDITOR")) // <3
827 di
.backend
->list(zone
, di
.id
);
828 pre
.clear(); post
.clear();
830 if(tmpfd
< 0 && (tmpfd
=open(tmpnam
, O_WRONLY
| O_TRUNC
, 0600)) < 0)
831 unixDie("Error reopening temporary file "+string(tmpnam
));
832 string
header("; Warning - every name in this file is ABSOLUTE!\n$ORIGIN .\n");
833 if(write(tmpfd
, header
.c_str(), header
.length()) < 0)
834 unixDie("Writing zone to temporary file");
835 DNSResourceRecord rr
;
836 while(di
.backend
->get(rr
)) {
837 if(!rr
.qtype
.getCode())
842 sort(pre
.begin(), pre
.end(), DNSRecord::prettyCompare
);
843 for(const auto& dr
: pre
) {
845 os
<<dr
.d_name
<<"\t"<<dr
.d_ttl
<<"\tIN\t"<<DNSRecordContent::NumberToType(dr
.d_type
)<<"\t"<<dr
.d_content
->getZoneRepresentation(true)<<endl
;
846 if(write(tmpfd
, os
.str().c_str(), os
.str().length()) < 0)
847 unixDie("Writing zone to temporary file");
855 cmdline
+="+"+std::to_string(gotoline
)+" ";
857 int err
=system(cmdline
.c_str());
859 unixDie("Editing file with: '"+cmdline
+"', perhaps set EDITOR variable");
862 ZoneParserTNG
zpt(tmpnam
, g_rootdnsname
);
863 DNSResourceRecord zrr
;
864 map
<pair
<DNSName
,uint16_t>, vector
<DNSRecord
> > grouped
;
865 while(zpt
.get(zrr
)) {
869 grouped
[{dr
.d_name
,dr
.d_type
}].push_back(dr
);
871 catch(std::exception
& e
) {
872 cerr
<<"Problem "<<e
.what()<<" "<<zpt
.getLineOfFile()<<endl
;
873 auto fnum
= zpt
.getLineNumAndFile();
874 gotoline
= fnum
.second
;
878 sort(post
.begin(), post
.end(), DNSRecord::prettyCompare
);
881 for(const DNSRecord
& rr
: post
) {
882 DNSResourceRecord drr
= DNSResourceRecord::fromWire(rr
);
883 drr
.domain_id
= di
.id
;
884 checkrr
.push_back(drr
);
886 if(checkZone(dk
, B
, zone
, &checkrr
)) {
888 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
;
904 vector
<DNSRecord
> diff
;
906 map
<pair
<DNSName
,uint16_t>, string
> changed
;
907 set_difference(pre
.cbegin(), pre
.cend(), post
.cbegin(), post
.cend(), back_inserter(diff
), DNSRecord::prettyCompare
);
908 for(const auto& d
: diff
) {
910 str
<<"\033[0;31m-"<< d
.d_name
<<" "<<d
.d_ttl
<<" IN "<<DNSRecordContent::NumberToType(d
.d_type
)<<" "<<d
.d_content
->getZoneRepresentation(true)<<"\033[0m"<<endl
;
911 changed
[{d
.d_name
,d
.d_type
}] += str
.str();
915 set_difference(post
.cbegin(), post
.cend(), pre
.cbegin(), pre
.cend(), back_inserter(diff
), DNSRecord::prettyCompare
);
916 for(const auto& d
: diff
) {
919 str
<<"\033[0;32m+"<< d
.d_name
<<" "<<d
.d_ttl
<<" IN "<<DNSRecordContent::NumberToType(d
.d_type
)<<" "<<d
.d_content
->getZoneRepresentation(true)<<"\033[0m"<<endl
;
920 changed
[{d
.d_name
,d
.d_type
}]+=str
.str();
922 if (changed
.size() > 0)
923 cout
<<"Detected the following changes:"<<endl
;
924 for(const auto& c
: changed
) {
928 if(changed
.empty()) {
929 cout
<<endl
<<"No changes to apply."<<endl
;
930 return(EXIT_SUCCESS
);
932 cout
<<endl
<<"(a)pply these changes, (e)dit again, (r)etry with original zone, (q)uit: ";
937 return(EXIT_SUCCESS
);
942 else if(changed
.empty() || c
!='a')
945 for(const auto& change
: changed
) {
946 vector
<DNSResourceRecord
> vrr
;
947 for(const DNSRecord
& rr
: grouped
[change
.first
]) {
948 DNSResourceRecord crr
= DNSResourceRecord::fromWire(rr
);
949 crr
.domain_id
= di
.id
;
952 di
.backend
->replaceRRSet(di
.id
, change
.first
.first
, QType(change
.first
.second
), vrr
);
954 rectifyZone(dk
, zone
);
959 int loadZone(DNSName zone
, const string
& fname
) {
963 if (B
.getDomainInfo(zone
, di
)) {
964 cerr
<<"Domain '"<<zone
<<"' exists already, replacing contents"<<endl
;
967 cerr
<<"Creating '"<<zone
<<"'"<<endl
;
968 B
.createDomain(zone
);
970 if(!B
.getDomainInfo(zone
, di
)) {
971 cerr
<<"Domain '"<<zone
<<"' was not created - perhaps backend ("<<::arg()["launch"]<<") does not support storing new zones."<<endl
;
975 DNSBackend
* db
= di
.backend
;
976 ZoneParserTNG
zpt(fname
, zone
);
978 DNSResourceRecord rr
;
979 if(!db
->startTransaction(zone
, di
.id
)) {
980 cerr
<<"Unable to start transaction for load of zone '"<<zone
<<"'"<<endl
;
984 bool haveSOA
= false;
986 if(!rr
.qname
.isPartOf(zone
) && rr
.qname
!=zone
) {
987 cerr
<<"File contains record named '"<<rr
.qname
<<"' which is not part of zone '"<<zone
<<"'"<<endl
;
990 if (rr
.qtype
== QType::SOA
) {
996 db
->feedRecord(rr
, DNSName());
998 db
->commitTransaction();
1002 int createZone(const DNSName
&zone
, const DNSName
& nsname
) {
1005 if (B
.getDomainInfo(zone
, di
)) {
1006 cerr
<<"Domain '"<<zone
<<"' exists already"<<endl
;
1007 return EXIT_FAILURE
;
1009 cerr
<<"Creating empty zone '"<<zone
<<"'"<<endl
;
1010 B
.createDomain(zone
);
1011 if(!B
.getDomainInfo(zone
, di
)) {
1012 cerr
<<"Domain '"<<zone
<<"' was not created!"<<endl
;
1013 return EXIT_FAILURE
;
1016 DNSResourceRecord rr
;
1019 rr
.ttl
= ::arg().asNum("default-ttl");
1022 string soa
= (boost::format("%s %s 1")
1023 % (nsname
.empty() ? ::arg()["default-soa-name"] : nsname
.toString())
1024 % (::arg().isEmpty("default-soa-mail") ? (DNSName("hostmaster.") + zone
).toString() : ::arg()["default-soa-mail"])
1027 fillSOAData(soa
, sd
); // fills out default values for us
1028 rr
.content
= makeSOAContent(sd
)->getZoneRepresentation(true);
1029 rr
.domain_id
= di
.id
;
1030 di
.backend
->startTransaction(zone
, di
.id
);
1031 di
.backend
->feedRecord(rr
, DNSName());
1032 if(!nsname
.empty()) {
1033 cout
<<"Also adding one NS record"<<endl
;
1035 rr
.content
=nsname
.toStringNoDot();
1036 di
.backend
->feedRecord(rr
, DNSName());
1039 di
.backend
->commitTransaction();
1041 return EXIT_SUCCESS
;
1044 int createSlaveZone(const vector
<string
>& cmds
) {
1047 DNSName
zone(cmds
[1]);
1048 if (B
.getDomainInfo(zone
, di
)) {
1049 cerr
<<"Domain '"<<zone
<<"' exists already"<<endl
;
1050 return EXIT_FAILURE
;
1052 vector
<string
> masters
;
1053 for (unsigned i
=2; i
< cmds
.size(); i
++) {
1054 ComboAddress
master(cmds
[i
], 53);
1055 masters
.push_back(master
.toStringWithPort());
1057 cerr
<<"Creating slave zone '"<<zone
<<"', with master(s) '"<<boost::join(masters
, ",")<<"'"<<endl
;
1058 B
.createDomain(zone
);
1059 if(!B
.getDomainInfo(zone
, di
)) {
1060 cerr
<<"Domain '"<<zone
<<"' was not created!"<<endl
;
1061 return EXIT_FAILURE
;
1063 di
.backend
->setKind(zone
, DomainInfo::Slave
);
1064 di
.backend
->setMaster(zone
, boost::join(masters
, ","));
1065 return EXIT_SUCCESS
;
1068 int changeSlaveZoneMaster(const vector
<string
>& cmds
) {
1071 DNSName
zone(cmds
[1]);
1072 if (!B
.getDomainInfo(zone
, di
)) {
1073 cerr
<<"Domain '"<<zone
<<"' doesn't exist"<<endl
;
1074 return EXIT_FAILURE
;
1076 vector
<string
> masters
;
1077 for (unsigned i
=2; i
< cmds
.size(); i
++) {
1078 ComboAddress
master(cmds
[i
], 53);
1079 masters
.push_back(master
.toStringWithPort());
1081 cerr
<<"Updating slave zone '"<<zone
<<"', master(s) to '"<<boost::join(masters
, ",")<<"'"<<endl
;
1083 di
.backend
->setMaster(zone
, boost::join(masters
, ","));
1084 return EXIT_SUCCESS
;
1086 catch (PDNSException
& e
) {
1087 cerr
<<"Setting master for zone '"<<zone
<<"' failed: "<<e
.reason
<<endl
;
1088 return EXIT_FAILURE
;
1092 // add-record ZONE name type [ttl] "content" ["content"]
1093 int addOrReplaceRecord(bool addOrReplace
, const vector
<string
>& cmds
) {
1094 DNSResourceRecord rr
;
1095 vector
<DNSResourceRecord
> newrrs
;
1096 DNSName
zone(cmds
[1]);
1101 name
=DNSName(cmds
[2])+zone
;
1103 rr
.qtype
= DNSRecordContent::TypeToNumber(cmds
[3]);
1104 rr
.ttl
= ::arg().asNum("default-ttl");
1109 if(!B
.getDomainInfo(zone
, di
)) {
1110 cerr
<<"Domain '"<<zone
<<"' does not exist"<<endl
;
1111 return EXIT_FAILURE
;
1114 rr
.domain_id
= di
.id
;
1116 DNSResourceRecord oldrr
;
1117 if(addOrReplace
) { // the 'add' case
1118 di
.backend
->lookup(rr
.qtype
, rr
.qname
, 0, di
.id
);
1120 while(di
.backend
->get(oldrr
))
1121 newrrs
.push_back(oldrr
);
1124 unsigned int contentStart
= 4;
1125 if(cmds
.size() > 5) {
1126 rr
.ttl
=atoi(cmds
[4].c_str());
1127 if(std::to_string(rr
.ttl
)==cmds
[4]) {
1130 else rr
.ttl
= ::arg().asNum("default-ttl");
1133 di
.backend
->lookup(QType(QType::ANY
), rr
.qname
, 0, di
.id
);
1135 if(rr
.qtype
.getCode() == QType::CNAME
) { // this will save us SO many questions
1137 while(di
.backend
->get(oldrr
)) {
1138 if(addOrReplace
|| oldrr
.qtype
.getCode() != QType::CNAME
) // the replace case is ok if we replace one CNAME by the other
1142 cerr
<<"Attempting to add CNAME to "<<rr
.qname
<<" which already had existing records"<<endl
;
1143 return EXIT_FAILURE
;
1147 while(di
.backend
->get(oldrr
)) {
1148 if(oldrr
.qtype
.getCode() == QType::CNAME
)
1152 cerr
<<"Attempting to add record to "<<rr
.qname
<<" which already had a CNAME record"<<endl
;
1153 return EXIT_FAILURE
;
1158 cout
<<"Current records for "<<rr
.qname
<<" IN "<<rr
.qtype
.getName()<<" will be replaced"<<endl
;
1160 for(auto i
= contentStart
; i
< cmds
.size() ; ++i
) {
1161 rr
.content
= DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, cmds
[i
])->getZoneRepresentation(true);
1163 newrrs
.push_back(rr
);
1167 di
.backend
->replaceRRSet(di
.id
, name
, rr
.qtype
, newrrs
);
1168 // need to be explicit to bypass the ueberbackend cache!
1169 di
.backend
->lookup(rr
.qtype
, name
, 0, di
.id
);
1170 cout
<<"New rrset:"<<endl
;
1171 while(di
.backend
->get(rr
)) {
1172 cout
<<rr
.qname
.toString()<<" IN "<<rr
.qtype
.getName()<<" "<<rr
.ttl
<<" "<<rr
.content
<<endl
;
1174 return EXIT_SUCCESS
;
1177 // delete-rrset zone name type
1178 int deleteRRSet(const std::string
& zone_
, const std::string
& name_
, const std::string
& type_
)
1182 DNSName
zone(zone_
);
1183 if(!B
.getDomainInfo(zone
, di
)) {
1184 cerr
<<"Domain '"<<zone
<<"' does not exist"<<endl
;
1185 return EXIT_FAILURE
;
1192 name
=DNSName(name_
)+zone
;
1194 QType
qt(QType::chartocode(type_
.c_str()));
1195 di
.backend
->replaceRRSet(di
.id
, name
, qt
, vector
<DNSResourceRecord
>());
1196 return EXIT_SUCCESS
;
1199 int listAllZones(const string
&type
="") {
1201 int kindFilter
= -1;
1203 if (toUpper(type
) == "MASTER")
1205 else if (toUpper(type
) == "SLAVE")
1207 else if (toUpper(type
) == "NATIVE")
1210 cerr
<<"Syntax: pdnsutil list-all-zones [master|slave|native]"<<endl
;
1215 UeberBackend
B("default");
1217 vector
<DomainInfo
> domains
;
1218 B
.getAllDomains(&domains
, true);
1221 for (vector
<DomainInfo
>::const_iterator di
=domains
.begin(); di
!= domains
.end(); di
++) {
1222 if (di
->kind
== kindFilter
|| kindFilter
== -1) {
1223 cout
<<di
->zone
<<endl
;
1229 if (kindFilter
!= -1)
1230 cout
<<type
<<" zonecount: "<<count
<<endl
;
1232 cout
<<"All zonecount: "<<count
<<endl
;
1238 bool testAlgorithm(int algo
)
1240 return DNSCryptoKeyEngine::testOne(algo
);
1243 bool testAlgorithms()
1245 return DNSCryptoKeyEngine::testAll();
1248 void testSpeed(DNSSECKeeper
& dk
, const DNSName
& zone
, const string
& remote
, int cores
)
1250 DNSResourceRecord rr
;
1251 rr
.qname
=DNSName("blah")+zone
;
1255 rr
.qclass
= QClass::IN
;
1257 UeberBackend
db("key-only");
1259 if ( ! db
.backends
.size() )
1261 throw runtime_error("No backends available for DNSSEC key storage");
1264 ChunkedSigningPipe
csp(DNSName(zone
), 1, cores
);
1266 vector
<DNSZoneRecord
> signatures
;
1268 unsigned char* octets
= (unsigned char*)&rnd
;
1272 for(unsigned int n
=0; n
< 100000; ++n
) {
1274 snprintf(tmp
, sizeof(tmp
), "%d.%d.%d.%d",
1275 octets
[0], octets
[1], octets
[2], octets
[3]);
1278 snprintf(tmp
, sizeof(tmp
), "r-%u", rnd
);
1279 rr
.qname
=DNSName(tmp
)+zone
;
1281 dzr
.dr
=DNSRecord(rr
);
1283 while(signatures
= csp
.getChunk(), !signatures
.empty())
1286 cerr
<<"Flushing the pipe, "<<csp
.d_signed
<<" signed, "<<csp
.d_queued
<<" queued, "<<csp
.d_outstanding
<<" outstanding"<< endl
;
1287 cerr
<<"Net speed: "<<csp
.d_signed
/ (dt
.udiffNoReset()/1000000.0) << " sigs/s"<<endl
;
1288 while(signatures
= csp
.getChunk(true), !signatures
.empty())
1290 cerr
<<"Done, "<<csp
.d_signed
<<" signed, "<<csp
.d_queued
<<" queued, "<<csp
.d_outstanding
<<" outstanding"<< endl
;
1291 cerr
<<"Net speed: "<<csp
.d_signed
/ (dt
.udiff()/1000000.0) << " sigs/s"<<endl
;
1294 void verifyCrypto(const string
& zone
)
1296 ZoneParserTNG
zpt(zone
);
1297 DNSResourceRecord rr
;
1298 DNSKEYRecordContent drc
;
1299 RRSIGRecordContent rrc
;
1300 DSRecordContent dsrc
;
1301 vector
<shared_ptr
<DNSRecordContent
> > toSign
;
1302 DNSName qname
, apex
;
1303 dsrc
.d_digesttype
=0;
1304 while(zpt
.get(rr
)) {
1305 if(rr
.qtype
.getCode() == QType::DNSKEY
) {
1306 cerr
<<"got DNSKEY!"<<endl
;
1308 drc
= *std::dynamic_pointer_cast
<DNSKEYRecordContent
>(DNSRecordContent::mastermake(QType::DNSKEY
, 1, rr
.content
));
1310 else if(rr
.qtype
.getCode() == QType::RRSIG
) {
1311 cerr
<<"got RRSIG"<<endl
;
1312 rrc
= *std::dynamic_pointer_cast
<RRSIGRecordContent
>(DNSRecordContent::mastermake(QType::RRSIG
, 1, rr
.content
));
1314 else if(rr
.qtype
.getCode() == QType::DS
) {
1315 cerr
<<"got DS"<<endl
;
1316 dsrc
= *std::dynamic_pointer_cast
<DSRecordContent
>(DNSRecordContent::mastermake(QType::DS
, 1, rr
.content
));
1320 toSign
.push_back(DNSRecordContent::mastermake(rr
.qtype
.getCode(), 1, rr
.content
));
1324 string msg
= getMessageForRRSET(qname
, rrc
, toSign
);
1325 cerr
<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc
.d_algorithm
, drc
.d_key
)->verify(msg
, rrc
.d_signature
)<<endl
;
1326 if(dsrc
.d_digesttype
) {
1327 cerr
<<"Calculated DS: "<<apex
.toString()<<" IN DS "<<makeDSFromDNSKey(apex
, drc
, dsrc
.d_digesttype
).getZoneRepresentation()<<endl
;
1328 cerr
<<"Original DS: "<<apex
.toString()<<" IN DS "<<dsrc
.getZoneRepresentation()<<endl
;
1331 std::shared_ptr
<DNSCryptoKeyEngine
> key
=DNSCryptoKeyEngine::makeFromISCString(drc
, "Private-key-format: v1.2\n"
1332 "Algorithm: 12 (ECC-GOST)\n"
1333 "GostAsn1: MEUCAQAwHAYGKoUDAgITMBIGByqFAwICIwEGByqFAwICHgEEIgQg/9MiXtXKg9FDXDN/R9CmVhJDyuzRAIgh4tPwCu4NHIs=\n");
1334 string resign
=key
->sign(hash
);
1335 cerr
<<Base64Encode(resign
)<<endl
;
1336 cerr
<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc
.d_algorithm
, drc
.d_key
)->verify(hash
, resign
)<<endl
;
1340 bool disableDNSSECOnZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1342 UeberBackend
B("default");
1345 if (!B
.getDomainInfo(zone
, di
)){
1346 cerr
<< "No such zone in the database" << endl
;
1351 bool ret
= dk
.unSecureZone(zone
, error
, info
);
1353 cerr
<< error
<< endl
;
1358 int setZoneAccount(const DNSName
& zone
, const string
&account
)
1360 UeberBackend
B("default");
1363 if (!B
.getDomainInfo(zone
, di
)){
1364 cerr
<< "No such zone "<<zone
<<" in the database" << endl
;
1365 return EXIT_FAILURE
;
1367 if(!di
.backend
->setAccount(zone
, account
)) {
1368 cerr
<<"Could not find backend willing to accept new zone configuration"<<endl
;
1369 return EXIT_FAILURE
;
1371 return EXIT_SUCCESS
;
1374 int setZoneKind(const DNSName
& zone
, const DomainInfo::DomainKind kind
)
1376 UeberBackend
B("default");
1379 if (!B
.getDomainInfo(zone
, di
)){
1380 cerr
<< "No such zone "<<zone
<<" in the database" << endl
;
1381 return EXIT_FAILURE
;
1383 if(!di
.backend
->setKind(zone
, kind
)) {
1384 cerr
<<"Could not find backend willing to accept new zone configuration"<<endl
;
1385 return EXIT_FAILURE
;
1387 return EXIT_SUCCESS
;
1390 bool showZone(DNSSECKeeper
& dk
, const DNSName
& zone
, bool exportDS
= false)
1392 UeberBackend
B("default");
1395 if (!B
.getDomainInfo(zone
, di
)){
1396 cerr
<< "No such zone in the database" << endl
;
1400 if (!di
.account
.empty()) {
1401 cout
<<"This zone is owned by "<<di
.account
<<endl
;
1404 cout
<<"This is a "<<DomainInfo::getKindString(di
.kind
)<<" zone"<<endl
;
1405 if(di
.kind
== DomainInfo::Master
) {
1406 cout
<<"Last SOA serial number we notified: "<<di
.notified_serial
<<" ";
1408 if(B
.getSOAUncached(zone
, sd
)) {
1409 if(sd
.serial
== di
.notified_serial
)
1413 cout
<<sd
.serial
<<" (serial in the database)"<<endl
;
1416 else if(di
.kind
== DomainInfo::Slave
) {
1417 cout
<<"Master"<<addS(di
.masters
)<<": ";
1418 for(const auto& m
: di
.masters
)
1422 localtime_r(&di
.last_check
, &tm
);
1425 strftime(buf
, sizeof(buf
)-1, "%a %F %H:%M:%S", &tm
);
1427 strncpy(buf
, "Never", sizeof(buf
)-1);
1428 buf
[sizeof(buf
)-1] = '\0';
1429 cout
<<"Last time we got update from master: "<<buf
<<endl
;
1431 if(B
.getSOAUncached(zone
, sd
)) {
1432 cout
<<"SOA serial in database: "<<sd
.serial
<<endl
;
1433 cout
<<"Refresh interval: "<<sd
.refresh
<<" seconds"<<endl
;
1436 cout
<<"No SOA serial found in database"<<endl
;
1440 if(!dk
.isSecuredZone(zone
)) {
1441 auto &outstream
= (exportDS
? cerr
: cout
);
1442 outstream
<< "Zone is not actively secured" << endl
;
1444 // it does not make sense to proceed here, and it might be useful
1445 // for scripts to know that something is odd here
1450 NSEC3PARAMRecordContent ns3pr
;
1452 bool haveNSEC3
=dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
);
1454 DNSSECKeeper::keyset_t keyset
=dk
.getKeys(zone
);
1457 std::vector
<std::string
> meta
;
1459 if (B
.getDomainMetadata(zone
, "TSIG-ALLOW-AXFR", meta
) && meta
.size() > 0) {
1460 cout
<< "Zone has following allowed TSIG key(s): " << boost::join(meta
, ",") << endl
;
1464 if (B
.getDomainMetadata(zone
, "AXFR-MASTER-TSIG", meta
) && meta
.size() > 0) {
1465 cout
<< "Zone uses following TSIG key(s): " << boost::join(meta
, ",") << endl
;
1468 std::map
<std::string
, std::vector
<std::string
> > metamap
;
1469 if(B
.getAllDomainMetadata(zone
, metamap
)) {
1470 cout
<<"Metadata items: ";
1475 for(const auto& m
: metamap
) {
1476 for(const auto i
: m
.second
)
1477 cout
<< '\t' << m
.first
<<'\t' << i
<<endl
;
1483 if (dk
.isPresigned(zone
)) {
1485 cout
<<"Zone is presigned"<<endl
;
1489 vector
<DNSKEYRecordContent
> keys
;
1492 B
.lookup(QType(QType::DNSKEY
), zone
);
1494 if (zr
.dr
.d_type
!= QType::DNSKEY
) continue;
1495 keys
.push_back(*getRR
<DNSKEYRecordContent
>(zr
.dr
));
1499 cerr
<< "No keys for zone '"<<zone
<<"'."<<endl
;
1505 cout
<<"Zone has NSEC semantics"<<endl
;
1507 cout
<<"Zone has " << (narrow
? "NARROW " : "") <<"hashed NSEC3 semantics, configuration: "<<ns3pr
.getZoneRepresentation()<<endl
;
1508 cout
<< "keys: "<<endl
;
1511 sort(keys
.begin(),keys
.end());
1512 reverse(keys
.begin(),keys
.end());
1514 for(const auto& key
: keys
) {
1515 string algname
= DNSSECKeeper::algorithm2name(key
.d_algorithm
);
1519 std::shared_ptr
<DNSCryptoKeyEngine
> engine(DNSCryptoKeyEngine::makeFromPublicKeyString(key
.d_algorithm
, key
.d_key
)); // throws on unknown algo or bad key
1520 bits
=engine
->getBits();
1522 catch(std::exception
& e
) {
1523 cerr
<<"Could not process key to extract metadata: "<<e
.what()<<endl
;
1526 cout
<< (key
.d_flags
== 257 ? "KSK" : "ZSK") << ", tag = " << key
.getTag() << ", algo = "<<(int)key
.d_algorithm
<< ", bits = " << bits
<< endl
;
1527 cout
<< "DNSKEY = " <<zone
.toString()<<" IN DNSKEY "<< key
.getZoneRepresentation() << "; ( " + algname
+ " ) " <<endl
;
1530 if (shown
) continue;
1533 const std::string
prefix(exportDS
? "" : "DS = ");
1534 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA1
).getZoneRepresentation() << " ; ( SHA1 digest )" << endl
;
1535 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA256
).getZoneRepresentation() << " ; ( SHA256 digest )" << endl
;
1537 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::GOST
).getZoneRepresentation();
1538 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( GOST R 34.11-94 digest )" << endl
;
1543 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA384
).getZoneRepresentation();
1544 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( SHA-384 digest )" << endl
;
1550 else if(keyset
.empty()) {
1551 cerr
<< "No keys for zone '"<<zone
<<"'."<<endl
;
1556 cout
<<"Zone has NSEC semantics"<<endl
;
1558 cout
<<"Zone has " << (narrow
? "NARROW " : "") <<"hashed NSEC3 semantics, configuration: "<<ns3pr
.getZoneRepresentation()<<endl
;
1559 cout
<< "keys: "<<endl
;
1562 for(DNSSECKeeper::keyset_t::value_type value
: keyset
) {
1563 string algname
= DNSSECKeeper::algorithm2name(value
.first
.d_algorithm
);
1565 cout
<<"ID = "<<value
.second
.id
<<" ("<<DNSSECKeeper::keyTypeToString(value
.second
.keyType
)<<")";
1567 if (value
.first
.getKey()->getBits() < 1) {
1568 cerr
<<" <key missing or defunct>" <<endl
;
1572 cout
<<", flags = "<<std::to_string(value
.first
.d_flags
);
1573 cout
<<", tag = "<<value
.first
.getDNSKEY().getTag();
1574 cout
<<", algo = "<<(int)value
.first
.d_algorithm
<<", bits = "<<value
.first
.getKey()->getBits()<<"\t"<<((int)value
.second
.active
== 1 ? " A" : "Ina")<<"ctive ( " + algname
+ " ) "<<endl
;
1578 if (value
.second
.keyType
== DNSSECKeeper::KSK
|| value
.second
.keyType
== DNSSECKeeper::CSK
|| ::arg().mustDo("direct-dnskey")) {
1579 cout
<<DNSSECKeeper::keyTypeToString(value
.second
.keyType
)<<" DNSKEY = "<<zone
.toString()<<" IN DNSKEY "<< value
.first
.getDNSKEY().getZoneRepresentation() << " ; ( " + algname
+ " )" << endl
;
1582 if (value
.second
.keyType
== DNSSECKeeper::KSK
|| value
.second
.keyType
== DNSSECKeeper::CSK
) {
1583 const auto &key
= value
.first
.getDNSKEY();
1584 const std::string
prefix(exportDS
? "" : "DS = ");
1585 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA1
).getZoneRepresentation() << " ; ( SHA1 digest )" << endl
;
1586 cout
<<prefix
<<zone
.toString()<<" IN DS "<<makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA256
).getZoneRepresentation() << " ; ( SHA256 digest )" << endl
;
1588 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::GOST
).getZoneRepresentation();
1589 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( GOST R 34.11-94 digest )" << endl
;
1594 string output
=makeDSFromDNSKey(zone
, key
, DNSSECKeeper::SHA384
).getZoneRepresentation();
1595 cout
<<prefix
<<zone
.toString()<<" IN DS "<<output
<< " ; ( SHA-384 digest )" << endl
;
1605 bool secureZone(DNSSECKeeper
& dk
, const DNSName
& zone
)
1610 // temp var for addKey
1613 string k_algo
= ::arg()["default-ksk-algorithm"];
1614 k_size
= ::arg().asNum("default-ksk-size");
1615 string z_algo
= ::arg()["default-zsk-algorithm"];
1616 z_size
= ::arg().asNum("default-zsk-size");
1619 throw runtime_error("KSK key size must be equal to or greater than 0");
1622 if (k_algo
== "" && z_algo
== "") {
1623 throw runtime_error("Zero algorithms given for KSK+ZSK in total");
1627 throw runtime_error("ZSK key size must be equal to or greater than 0");
1630 if(dk
.isSecuredZone(zone
)) {
1631 cerr
<< "Zone '"<<zone
<<"' already secure, remove keys with pdnsutil remove-zone-key if needed"<<endl
;
1636 UeberBackend
B("default");
1637 if(!B
.getDomainInfo(zone
, di
) || !di
.backend
) { // di.backend and B are mostly identical
1638 cerr
<<"Can't find a zone called '"<<zone
<<"'"<<endl
;
1642 if(di
.kind
== DomainInfo::Slave
)
1644 cerr
<<"Warning! This is a slave domain! If this was a mistake, please run"<<endl
;
1645 cerr
<<"pdnsutil disable-dnssec "<<zone
<<" right now!"<<endl
;
1648 if (k_algo
!= "") { // Add a KSK
1650 cout
<< "Securing zone with key size " << k_size
<< endl
;
1652 cout
<< "Securing zone with default key size" << endl
;
1654 cout
<< "Adding "<<(z_algo
== "" ? "CSK (257)" : "KSK")<<" with algorithm " << k_algo
<< endl
;
1656 int k_real_algo
= DNSSECKeeper::shorthand2algorithm(k_algo
);
1658 if (!dk
.addKey(zone
, true, k_real_algo
, id
, k_size
, true)) {
1659 cerr
<<"No backend was able to secure '"<<zone
<<"', most likely because no DNSSEC"<<endl
;
1660 cerr
<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl
;
1661 cerr
<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl
;
1662 cerr
<<"'gpgsql-dnssec' flag. Also make sure the schema has been updated for DNSSEC!"<<endl
;
1668 cout
<< "Adding "<<(k_algo
== "" ? "CSK (256)" : "ZSK")<<" with algorithm " << z_algo
<< endl
;
1670 int z_real_algo
= DNSSECKeeper::shorthand2algorithm(z_algo
);
1672 if (!dk
.addKey(zone
, false, z_real_algo
, id
, z_size
, true)) {
1673 cerr
<<"No backend was able to secure '"<<zone
<<"', most likely because no DNSSEC"<<endl
;
1674 cerr
<<"capable backends are loaded, or because the backends have DNSSEC disabled."<<endl
;
1675 cerr
<<"For the Generic SQL backends, set the 'gsqlite3-dnssec', 'gmysql-dnssec' or"<<endl
;
1676 cerr
<<"'gpgsql-dnssec' flag. Also make sure the schema has been updated for DNSSEC!"<<endl
;
1681 if(!dk
.isSecuredZone(zone
)) {
1682 cerr
<<"Failed to secure zone. Is your backend dnssec enabled? (set "<<endl
;
1683 cerr
<<"gsqlite3-dnssec, or gmysql-dnssec etc). Check this first."<<endl
;
1684 cerr
<<"If you run with the BIND backend, make sure you have configured"<<endl
;
1685 cerr
<<"it to use DNSSEC with 'bind-dnssec-db=/path/fname' and"<<endl
;
1686 cerr
<<"'pdnsutil create-bind-db /path/fname'!"<<endl
;
1690 // rectifyZone(dk, zone);
1691 // showZone(dk, zone);
1692 cout
<<"Zone "<<zone
<<" secured"<<endl
;
1696 void testSchema(DNSSECKeeper
& dk
, const DNSName
& zone
)
1698 cout
<<"Note: test-schema will try to create the zone, but it will not remove it."<<endl
;
1699 cout
<<"Please clean up after this."<<endl
;
1701 cout
<<"Constructing UeberBackend"<<endl
;
1702 UeberBackend
B("default");
1703 cout
<<"Picking first backend - if this is not what you want, edit launch line!"<<endl
;
1704 DNSBackend
*db
= B
.backends
[0];
1705 cout
<<"Creating slave domain "<<zone
<<endl
;
1706 db
->createSlaveDomain("127.0.0.1", zone
, "", "_testschema");
1707 cout
<<"Slave domain created"<<endl
;
1710 if(!B
.getDomainInfo(zone
, di
) || !di
.backend
) { // di.backend and B are mostly identical
1711 cout
<<"Can't find domain we just created, aborting"<<endl
;
1715 DNSResourceRecord rr
, rrget
;
1716 cout
<<"Starting transaction to feed records"<<endl
;
1717 db
->startTransaction(zone
, di
.id
);
1719 rr
.qtype
=QType::SOA
;
1724 rr
.content
="ns1.example.com. ahu.example.com. 2012081039 7200 3600 1209600 3600";
1725 cout
<<"Feeding SOA"<<endl
;
1726 db
->feedRecord(rr
, DNSName());
1727 rr
.qtype
=QType::TXT
;
1729 rr
.content
="\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"";
1730 cout
<<"Feeding overlong TXT"<<endl
;
1731 db
->feedRecord(rr
, DNSName());
1732 cout
<<"Committing"<<endl
;
1733 db
->commitTransaction();
1734 cout
<<"Querying TXT"<<endl
;
1735 db
->lookup(QType(QType::TXT
), zone
, NULL
, di
.id
);
1738 DNSResourceRecord rrthrowaway
;
1739 if(db
->get(rrthrowaway
)) // should not touch rr but don't assume anything
1741 cout
<<"Expected one record, got multiple, aborting"<<endl
;
1744 int size
=rrget
.content
.size();
1747 cout
<<"Expected 302 bytes, got "<<size
<<", aborting"<<endl
;
1751 cout
<<"[+] content field is over 255 bytes"<<endl
;
1753 cout
<<"Dropping all records, inserting SOA+2xA"<<endl
;
1754 db
->startTransaction(zone
, di
.id
);
1756 rr
.qtype
=QType::SOA
;
1761 rr
.content
="ns1.example.com. ahu.example.com. 2012081039 7200 3600 1209600 3600";
1762 cout
<<"Feeding SOA"<<endl
;
1763 db
->feedRecord(rr
, DNSName());
1766 rr
.qname
=DNSName("_underscore")+zone
;
1767 rr
.content
="127.0.0.1";
1768 db
->feedRecord(rr
, DNSName());
1770 rr
.qname
=DNSName("bla")+zone
;
1771 cout
<<"Committing"<<endl
;
1772 db
->commitTransaction();
1774 cout
<<"Securing zone"<<endl
;
1775 secureZone(dk
, zone
);
1776 cout
<<"Rectifying zone"<<endl
;
1777 rectifyZone(dk
, zone
);
1778 cout
<<"Checking underscore ordering"<<endl
;
1779 DNSName before
, after
;
1780 db
->getBeforeAndAfterNames(di
.id
, zone
, DNSName("z")+zone
, before
, after
);
1781 cout
<<"got '"<<before
.toString()<<"' < 'z."<<zone
.toString()<<"' < '"<<after
.toString()<<"'"<<endl
;
1782 if(before
!= DNSName("_underscore")+zone
)
1784 cout
<<"before is wrong, got '"<<before
.toString()<<"', expected '_underscore."<<zone
.toString()<<"', aborting"<<endl
;
1789 cout
<<"after is wrong, got '"<<after
.toString()<<"', expected '"<<zone
.toString()<<"', aborting"<<endl
;
1792 cout
<<"[+] ordername sorting is correct for names starting with _"<<endl
;
1794 cout
<<"End of tests, please remove "<<zone
<<" from domains+records"<<endl
;
1797 int addOrSetMeta(const DNSName
& zone
, const string
& kind
, const vector
<string
>& values
, bool clobber
) {
1798 UeberBackend
B("default");
1801 if (!B
.getDomainInfo(zone
, di
)) {
1802 cerr
<< "Invalid zone '" << zone
<< "'" << endl
;
1806 vector
<string
> all_metadata
;
1809 B
.getDomainMetadata(zone
, kind
, all_metadata
);
1812 all_metadata
.insert(all_metadata
.end(), values
.begin(), values
.end());
1814 if (!B
.setDomainMetadata(zone
, kind
, all_metadata
)) {
1815 cerr
<< "Unable to set meta for '" << zone
<< "'" << endl
;
1819 cout
<< "Set '" << zone
<< "' meta " << kind
<< " = " << boost::join(all_metadata
, ", ") << endl
;
1823 int main(int argc
, char** argv
)
1826 po::options_description
desc("Allowed options");
1828 ("help,h", "produce help message")
1829 ("version", "show version")
1830 ("verbose,v", "be verbose")
1831 ("force", "force an action")
1832 ("config-name", po::value
<string
>()->default_value(""), "virtual configuration name")
1833 ("config-dir", po::value
<string
>()->default_value(SYSCONFDIR
), "location of pdns.conf")
1834 ("commands", po::value
<vector
<string
> >());
1836 po::positional_options_description p
;
1837 p
.add("commands", -1);
1838 po::store(po::command_line_parser(argc
, argv
).options(desc
).positional(p
).run(), g_vm
);
1841 vector
<string
> cmds
;
1843 if(g_vm
.count("commands"))
1844 cmds
= g_vm
["commands"].as
<vector
<string
> >();
1846 g_verbose
= g_vm
.count("verbose");
1848 if (g_vm
.count("version")) {
1849 cout
<<"pdnsutil "<<VERSION
<<endl
;
1853 if(cmds
.empty() || g_vm
.count("help") || cmds
[0] == "help") {
1854 cout
<<"Usage: \npdnsutil [options] <command> [params ..]\n"<<endl
;
1855 cout
<<"Commands:"<<endl
;
1856 cout
<<"activate-tsig-key ZONE NAME {master|slave}"<<endl
;
1857 cout
<<" Enable TSIG authenticated AXFR using the key NAME for ZONE"<<endl
;
1858 cout
<<"activate-zone-key ZONE KEY-ID Activate the key with key id KEY-ID in ZONE"<<endl
;
1859 cout
<<"add-record ZONE NAME TYPE [ttl] content"<<endl
;
1860 cout
<<" [content..] Add one or more records to ZONE"<<endl
;
1861 cout
<<"add-zone-key ZONE {zsk|ksk} [BITS] [active|inactive]"<<endl
;
1862 cout
<<" [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384";
1863 #if defined(HAVE_LIBSODIUM) || defined(HAVE_LIBDECAF)
1866 #ifdef HAVE_LIBDECAF
1870 cout
<<" Add a ZSK or KSK to zone and specify algo&bits"<<endl
;
1871 cout
<<"backend-cmd BACKEND CMD [CMD..] Perform one or more backend commands"<<endl
;
1872 cout
<<"b2b-migrate OLD NEW Move all data from one backend to another"<<endl
;
1873 cout
<<"bench-db [filename] Bench database backend with queries, one domain per line"<<endl
;
1874 cout
<<"check-zone ZONE Check a zone for correctness"<<endl
;
1875 cout
<<"check-all-zones [exit-on-error] Check all zones for correctness. Set exit-on-error to exit immediately"<<endl
;
1876 cout
<<" after finding an error in a zone."<<endl
;
1877 cout
<<"clear-zone ZONE Clear all records of a zone, but keep everything else"<<endl
;
1878 cout
<<"create-bind-db FNAME Create DNSSEC db for BIND backend (bind-dnssec-db)"<<endl
;
1879 cout
<<"create-slave-zone ZONE master-ip [master-ip..]"<<endl
;
1880 cout
<<" Create slave zone ZONE with master IP address master-ip"<<endl
;
1881 cout
<<"change-slave-zone-master ZONE master-ip [master-ip..]"<<endl
;
1882 cout
<<" Change slave zone ZONE master IP address to master-ip"<<endl
;
1883 cout
<<"create-zone ZONE [nsname] Create empty zone ZONE"<<endl
;
1884 cout
<<"deactivate-tsig-key ZONE NAME {master|slave}"<<endl
;
1885 cout
<<" Disable TSIG authenticated AXFR using the key NAME for ZONE"<<endl
;
1886 cout
<<"deactivate-zone-key ZONE KEY-ID Deactivate the key with key id KEY-ID in ZONE"<<endl
;
1887 cout
<<"delete-rrset ZONE NAME TYPE Delete named RRSET from zone"<<endl
;
1888 cout
<<"delete-tsig-key NAME Delete TSIG key (warning! will not unmap key!)"<<endl
;
1889 cout
<<"delete-zone ZONE Delete the zone"<<endl
;
1890 cout
<<"disable-dnssec ZONE Deactivate all keys and unset PRESIGNED in ZONE"<<endl
;
1891 cout
<<"edit-zone ZONE Edit zone contents using $EDITOR"<<endl
;
1892 cout
<<"export-zone-dnskey ZONE KEY-ID Export to stdout the public DNSKEY described"<<endl
;
1893 cout
<<"export-zone-ds ZONE Export to stdout all KSK DS records for ZONE"<<endl
;
1894 cout
<<"export-zone-key ZONE KEY-ID Export to stdout the private key described"<<endl
;
1895 cout
<<"generate-tsig-key NAME ALGORITHM Generate new TSIG key"<<endl
;
1896 cout
<<"generate-zone-key {zsk|ksk} [ALGORITHM] [BITS]"<<endl
;
1897 cout
<<" Generate a ZSK or KSK to stdout with specified ALGORITHM and BITS"<<endl
;
1898 cout
<<"get-meta ZONE [KIND ...] Get zone metadata. If no KIND given, lists all known"<<endl
;
1899 cout
<<"hash-zone-record ZONE RNAME Calculate the NSEC3 hash for RNAME in ZONE"<<endl
;
1901 cout
<<"hsm assign ZONE ALGORITHM {ksk|zsk} MODULE SLOT PIN LABEL"<<endl
<<
1902 " Assign a hardware signing module to a ZONE"<<endl
;
1903 cout
<<"hsm create-key ZONE KEY-ID [BITS] Create a key using hardware signing module for ZONE (use assign first)"<<endl
;
1904 cout
<<" BITS defaults to 2048"<<endl
;
1906 cout
<<"increase-serial ZONE Increases the SOA-serial by 1. Uses SOA-EDIT"<<endl
;
1907 cout
<<"import-tsig-key NAME ALGORITHM KEY Import TSIG key"<<endl
;
1908 cout
<<"import-zone-key ZONE FILE Import from a file a private key, ZSK or KSK"<<endl
;
1909 cout
<<" [active|inactive] [ksk|zsk] Defaults to KSK and active"<<endl
;
1910 cout
<<"load-zone ZONE FILE Load ZONE from FILE, possibly creating zone or atomically"<<endl
;
1911 cout
<<" replacing contents"<<endl
;
1912 cout
<<"list-algorithms [with-backend] List all DNSSEC algorithms supported, optionally also listing the crypto library used"<<endl
;
1913 cout
<<"list-keys [ZONE] List DNSSEC keys for ZONE. When ZONE is unset or \"all\", display all keys for all zones"<<endl
;
1914 cout
<<"list-zone ZONE List zone contents"<<endl
;
1915 cout
<<"list-all-zones [master|slave|native]"<<endl
;
1916 cout
<<" List all zone names"<<endl
;;
1917 cout
<<"list-tsig-keys List all TSIG keys"<<endl
;
1918 cout
<<"rectify-zone ZONE [ZONE ..] Fix up DNSSEC fields (order, auth)"<<endl
;
1919 cout
<<"rectify-all-zones [quiet] Rectify all zones. Optionally quiet output with errors only"<<endl
;
1920 cout
<<"remove-zone-key ZONE KEY-ID Remove key with KEY-ID from ZONE"<<endl
;
1921 cout
<<"replace-rrset ZONE NAME TYPE [ttl] Replace named RRSET from zone"<<endl
;
1922 cout
<<" content [content..]"<<endl
;
1923 cout
<<"secure-all-zones [increase-serial] Secure all zones without keys"<<endl
;
1924 cout
<<"secure-zone ZONE [ZONE ..] Add DNSSEC to zone ZONE"<<endl
;
1925 cout
<<"set-kind ZONE KIND Change the kind of ZONE to KIND (master, slave native)"<<endl
;
1926 cout
<<"set-account ZONE ACCOUNT Change the account (owner) of ZONE to ACCOUNT"<<endl
;
1927 cout
<<"set-nsec3 ZONE ['PARAMS' [narrow]] Enable NSEC3 with PARAMS. Optionally narrow"<<endl
;
1928 cout
<<"set-presigned ZONE Use presigned RRSIGs from storage"<<endl
;
1929 cout
<<"set-publish-cdnskey ZONE Enable sending CDNSKEY responses for ZONE"<<endl
;
1930 cout
<<"set-publish-cds ZONE [DIGESTALGOS] Enable sending CDS responses for ZONE, using DIGESTALGOS as signature algorithms"<<endl
;
1931 cout
<<" DIGESTALGOS should be a comma separated list of numbers, is is '1,2' by default"<<endl
;
1932 cout
<<"add-meta ZONE KIND VALUE Add zone metadata, this adds to the existing KIND"<<endl
;
1933 cout
<<" [VALUE ...]"<<endl
;
1934 cout
<<"set-meta ZONE KIND [VALUE] [VALUE] Set zone metadata, optionally providing a value. *No* value clears meta"<<endl
;
1935 cout
<<" Note - this will replace all metadata records of KIND!"<<endl
;
1936 cout
<<"show-zone ZONE Show DNSSEC (public) key details about a zone"<<endl
;
1937 cout
<<"unset-nsec3 ZONE Switch back to NSEC"<<endl
;
1938 cout
<<"unset-presigned ZONE No longer use presigned RRSIGs"<<endl
;
1939 cout
<<"unset-publish-cdnskey ZONE Disable sending CDNSKEY responses for ZONE"<<endl
;
1940 cout
<<"unset-publish-cds ZONE Disable sending CDS responses for ZONE"<<endl
;
1941 cout
<<"test-schema ZONE Test DB schema - will create ZONE"<<endl
;
1946 loadMainConfig(g_vm
["config-dir"].as
<string
>());
1948 if (cmds
[0] == "test-algorithm") {
1949 if(cmds
.size() != 2) {
1950 cerr
<< "Syntax: pdnsutil test-algorithm algonum"<<endl
;
1953 if (testAlgorithm(pdns_stou(cmds
[1])))
1958 if(cmds
[0] == "test-algorithms") {
1959 if (testAlgorithms())
1964 if(cmds
[0] == "list-algorithms") {
1965 if((cmds
.size() == 2 && cmds
[1] != "with-backend") || cmds
.size() > 2) {
1966 cerr
<<"Syntax: pdnsutil list-algorithms [with-backend]"<<endl
;
1970 cout
<<"DNSKEY algorithms supported by this installation of PowerDNS:"<<endl
;
1972 auto algosWithBackend
= DNSCryptoKeyEngine::listAllAlgosWithBackend();
1973 for (auto const algoWithBackend
: algosWithBackend
){
1974 string algoName
= DNSSECKeeper::algorithm2name(algoWithBackend
.first
);
1975 cout
<<std::to_string(algoWithBackend
.first
)<<" - "<<algoName
;
1976 if (cmds
.size() == 2 && cmds
[1] == "with-backend")
1977 cout
<<" using "<<algoWithBackend
.second
;
1985 if(cmds
[0] == "create-bind-db") {
1987 if(cmds
.size() != 2) {
1988 cerr
<< "Syntax: pdnsutil create-bind-db FNAME"<<endl
;
1992 SSQLite3
db(cmds
[1], true); // create=ok
1993 vector
<string
> statements
;
1994 stringtok(statements
, sqlCreate
, ";");
1995 for(const string
& statement
: statements
) {
1996 db
.execute(statement
);
1999 catch(SSqlException
& se
) {
2000 throw PDNSException("Error creating database in BIND backend: "+se
.txtReason());
2004 cerr
<<"bind-dnssec-db requires building PowerDNS with SQLite3"<<endl
;
2011 if (cmds
[0] == "test-schema") {
2012 if(cmds
.size() != 2) {
2013 cerr
<< "Syntax: pdnsutil test-schema ZONE"<<endl
;
2016 testSchema(dk
, DNSName(cmds
[1]));
2019 if(cmds
[0] == "rectify-zone") {
2020 if(cmds
.size() < 2) {
2021 cerr
<< "Syntax: pdnsutil rectify-zone ZONE [ZONE..]"<<endl
;
2024 unsigned int exitCode
= 0;
2025 for(unsigned int n
= 1; n
< cmds
.size(); ++n
)
2026 if (!rectifyZone(dk
, DNSName(cmds
[n
])))
2030 else if (cmds
[0] == "rectify-all-zones") {
2031 bool quiet
= (cmds
.size() >= 2 && cmds
[1] == "quiet");
2032 if (!rectifyAllZones(dk
, quiet
)) {
2036 else if(cmds
[0] == "check-zone") {
2037 if(cmds
.size() != 2) {
2038 cerr
<< "Syntax: pdnsutil check-zone ZONE"<<endl
;
2041 UeberBackend
B("default");
2042 exit(checkZone(dk
, B
, DNSName(cmds
[1])));
2044 else if(cmds
[0] == "bench-db") {
2045 dbBench(cmds
.size() > 1 ? cmds
[1] : "");
2047 else if (cmds
[0] == "check-all-zones") {
2048 bool exitOnError
= ((cmds
.size() >= 2 ? cmds
[1] : "") == "exit-on-error");
2049 exit(checkAllZones(dk
, exitOnError
));
2051 else if (cmds
[0] == "list-all-zones") {
2052 if (cmds
.size() > 2) {
2053 cerr
<< "Syntax: pdnsutil list-all-zones [master|slave|native]"<<endl
;
2056 if (cmds
.size() == 2)
2057 return listAllZones(cmds
[1]);
2058 return listAllZones();
2060 else if (cmds
[0] == "test-zone") {
2061 cerr
<< "Did you mean check-zone?"<<endl
;
2064 else if (cmds
[0] == "test-all-zones") {
2065 cerr
<< "Did you mean check-all-zones?"<<endl
;
2069 else if(cmds
[0] == "signing-server" )
2073 else if(cmds
[0] == "signing-slave")
2075 launchSigningService(0);
2078 else if(cmds
[0] == "test-speed") {
2079 if(cmds
.size() < 2) {
2080 cerr
<< "Syntax: pdnsutil test-speed numcores [signing-server]"<<endl
;
2083 testSpeed(dk
, DNSName(cmds
[1]), (cmds
.size() > 3) ? cmds
[3] : "", pdns_stou(cmds
[2]));
2085 else if(cmds
[0] == "verify-crypto") {
2086 if(cmds
.size() != 2) {
2087 cerr
<< "Syntax: pdnsutil verify-crypto FILE"<<endl
;
2090 verifyCrypto(cmds
[1]);
2092 else if(cmds
[0] == "show-zone") {
2093 if(cmds
.size() != 2) {
2094 cerr
<< "Syntax: pdnsutil show-zone ZONE"<<endl
;
2097 if (!showZone(dk
, DNSName(cmds
[1]))) return 1;
2099 else if(cmds
[0] == "export-zone-ds") {
2100 if(cmds
.size() != 2) {
2101 cerr
<< "Syntax: pdnsutil export-zone-ds ZONE"<<endl
;
2104 if (!showZone(dk
, DNSName(cmds
[1]), true)) return 1;
2106 else if(cmds
[0] == "disable-dnssec") {
2107 if(cmds
.size() != 2) {
2108 cerr
<< "Syntax: pdnsutil disable-dnssec ZONE"<<endl
;
2111 DNSName
zone(cmds
[1]);
2112 if(!disableDNSSECOnZone(dk
, zone
)) {
2113 cerr
<< "Cannot disable DNSSEC on " << zone
<< endl
;
2117 else if(cmds
[0] == "activate-zone-key") {
2118 if(cmds
.size() != 3) {
2119 cerr
<< "Syntax: pdnsutil activate-zone-key ZONE KEY-ID"<<endl
;
2122 DNSName
zone(cmds
[1]);
2123 unsigned int id
=atoi(cmds
[2].c_str()); // if you make this pdns_stou, the error gets worse
2126 cerr
<<"Invalid KEY-ID '"<<cmds
[2]<<"'"<<endl
;
2129 if (!dk
.activateKey(zone
, id
)) {
2130 cerr
<<"Activation of key failed"<<endl
;
2135 else if(cmds
[0] == "deactivate-zone-key") {
2136 if(cmds
.size() != 3) {
2137 cerr
<< "Syntax: pdnsutil deactivate-zone-key ZONE KEY-ID"<<endl
;
2140 DNSName
zone(cmds
[1]);
2141 unsigned int id
=pdns_stou(cmds
[2]);
2144 cerr
<<"Invalid KEY-ID"<<endl
;
2147 if (!dk
.deactivateKey(zone
, id
)) {
2148 cerr
<<"Deactivation of key failed"<<endl
;
2153 else if(cmds
[0] == "add-zone-key") {
2154 if(cmds
.size() < 3 ) {
2155 cerr
<< "Syntax: pdnsutil add-zone-key ZONE zsk|ksk [BITS] [active|inactive] [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384]"<<endl
;
2158 DNSName
zone(cmds
[1]);
2160 UeberBackend
B("default");
2163 if (!B
.getDomainInfo(zone
, di
)){
2164 cerr
<< "No such zone in the database" << endl
;
2168 // need to get algorithm, bits & ksk or zsk from commandline
2169 bool keyOrZone
=false;
2172 int algorithm
=DNSSECKeeper::ECDSA256
;
2174 for(unsigned int n
=2; n
< cmds
.size(); ++n
) {
2175 if(pdns_iequals(cmds
[n
], "zsk"))
2177 else if(pdns_iequals(cmds
[n
], "ksk"))
2179 else if((tmp_algo
= DNSSECKeeper::shorthand2algorithm(cmds
[n
]))>0) {
2180 algorithm
= tmp_algo
;
2181 } else if(pdns_iequals(cmds
[n
], "active")) {
2183 } else if(pdns_iequals(cmds
[n
], "inactive") || pdns_iequals(cmds
[n
], "passive")) { // 'passive' eventually needs to be removed
2185 } else if(pdns_stou(cmds
[n
])) {
2186 bits
= pdns_stou(cmds
[n
]);
2188 cerr
<<"Unknown algorithm, key flag or size '"<<cmds
[n
]<<"'"<<endl
;
2189 exit(EXIT_FAILURE
);;
2193 if (!dk
.addKey(zone
, keyOrZone
, algorithm
, id
, bits
, active
)) {
2194 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2197 cerr
<<"Added a " << (keyOrZone
? "KSK" : "ZSK")<<" with algorithm = "<<algorithm
<<", active="<<active
<<endl
;
2199 cerr
<<"Requested specific key size of "<<bits
<<" bits"<<endl
;
2201 cerr
<<std::to_string(id
)<<"Key was added, but backend does not support returning of key id"<<endl
;
2202 } else if (id
< -1) {
2203 cerr
<<std::to_string(id
)<<"Key was added, but there was a failure while returning the key id"<<endl
;
2205 cout
<<std::to_string(id
)<<endl
;
2209 else if(cmds
[0] == "remove-zone-key") {
2210 if(cmds
.size() < 3) {
2211 cerr
<<"Syntax: pdnsutil remove-zone-key ZONE KEY-ID"<<endl
;
2214 DNSName
zone(cmds
[1]);
2215 unsigned int id
=pdns_stou(cmds
[2]);
2216 if (!dk
.removeKey(zone
, id
)) {
2217 cerr
<<"Cannot remove key " << id
<< " from " << zone
<<endl
;
2222 else if(cmds
[0] == "delete-zone") {
2223 if(cmds
.size() != 2) {
2224 cerr
<<"Syntax: pdnsutil delete-zone ZONE"<<endl
;
2227 exit(deleteZone(DNSName(cmds
[1])));
2229 else if(cmds
[0] == "create-zone") {
2230 if(cmds
.size() != 2 && cmds
.size()!=3 ) {
2231 cerr
<<"Syntax: pdnsutil create-zone ZONE [nsname]"<<endl
;
2234 exit(createZone(DNSName(cmds
[1]), cmds
.size() > 2 ? DNSName(cmds
[2]): DNSName()));
2236 else if(cmds
[0] == "create-slave-zone") {
2237 if(cmds
.size() < 3 ) {
2238 cerr
<<"Syntax: pdnsutil create-slave-zone ZONE master-ip [master-ip..]"<<endl
;
2241 exit(createSlaveZone(cmds
));
2243 else if(cmds
[0] == "change-slave-zone-master") {
2244 if(cmds
.size() < 3 ) {
2245 cerr
<<"Syntax: pdnsutil change-slave-zone-master ZONE master-ip [master-ip..]"<<endl
;
2248 exit(changeSlaveZoneMaster(cmds
));
2250 else if(cmds
[0] == "add-record") {
2251 if(cmds
.size() < 5) {
2252 cerr
<<"Syntax: pdnsutil add-record ZONE name type [ttl] \"content\" [\"content\"...]"<<endl
;
2255 exit(addOrReplaceRecord(true, cmds
));
2257 else if(cmds
[0] == "replace-rrset") {
2258 if(cmds
.size() < 5) {
2259 cerr
<<"Syntax: pdnsutil replace-rrset ZONE name type [ttl] \"content\" [\"content\"...]"<<endl
;
2262 exit(addOrReplaceRecord(false , cmds
));
2264 else if(cmds
[0] == "delete-rrset") {
2265 if(cmds
.size() != 4) {
2266 cerr
<<"Syntax: pdnsutil delete-rrset ZONE name type"<<endl
;
2269 exit(deleteRRSet(cmds
[1], cmds
[2], cmds
[3]));
2271 else if(cmds
[0] == "list-zone") {
2272 if(cmds
.size() != 2) {
2273 cerr
<<"Syntax: pdnsutil list-zone ZONE"<<endl
;
2279 exit(listZone(DNSName(cmds
[1])));
2281 else if(cmds
[0] == "edit-zone") {
2282 if(cmds
.size() != 2) {
2283 cerr
<<"Syntax: pdnsutil edit-zone ZONE"<<endl
;
2289 exit(editZone(dk
, DNSName(cmds
[1])));
2291 else if(cmds
[0] == "clear-zone") {
2292 if(cmds
.size() != 2) {
2293 cerr
<<"Syntax: pdnsutil edit-zone ZONE"<<endl
;
2299 exit(clearZone(dk
, DNSName(cmds
[1])));
2301 else if(cmds
[0] == "list-keys") {
2302 if(cmds
.size() > 2) {
2303 cerr
<<"Syntax: pdnsutil list-keys [ZONE]"<<endl
;
2306 string zname
= (cmds
.size() == 2) ? cmds
[1] : "all";
2307 exit(listKeys(zname
, dk
));
2309 else if(cmds
[0] == "load-zone") {
2310 if(cmds
.size() != 3) {
2311 cerr
<<"Syntax: pdnsutil load-zone ZONE FILENAME"<<endl
;
2317 exit(loadZone(DNSName(cmds
[1]), cmds
[2]));
2319 else if(cmds
[0] == "secure-zone") {
2320 if(cmds
.size() < 2) {
2321 cerr
<< "Syntax: pdnsutil secure-zone ZONE"<<endl
;
2324 vector
<DNSName
> mustRectify
;
2325 unsigned int zoneErrors
=0;
2326 for(unsigned int n
= 1; n
< cmds
.size(); ++n
) {
2327 DNSName
zone(cmds
[n
]);
2328 dk
.startTransaction(zone
, -1);
2329 if(secureZone(dk
, zone
)) {
2330 mustRectify
.push_back(zone
);
2334 dk
.commitTransaction();
2337 for(const auto& zone
: mustRectify
)
2338 rectifyZone(dk
, zone
);
2345 else if (cmds
[0] == "secure-all-zones") {
2346 if (cmds
.size() >= 2 && !pdns_iequals(cmds
[1], "increase-serial")) {
2347 cerr
<< "Syntax: pdnsutil secure-all-zones [increase-serial]"<<endl
;
2351 UeberBackend
B("default");
2353 vector
<DomainInfo
> domainInfo
;
2354 B
.getAllDomains(&domainInfo
);
2356 unsigned int zonesSecured
=0, zoneErrors
=0;
2357 for(DomainInfo di
: domainInfo
) {
2358 if(!dk
.isSecuredZone(di
.zone
)) {
2359 cout
<<"Securing "<<di
.zone
<<": ";
2360 if (secureZone(dk
, di
.zone
)) {
2362 if (cmds
.size() == 2) {
2363 if (!increaseSerial(di
.zone
, dk
))
2372 cout
<<"Secured: "<<zonesSecured
<<" zones. Errors: "<<zoneErrors
<<endl
;
2379 else if(cmds
[0]=="set-kind") {
2380 if(cmds
.size() != 3) {
2381 cerr
<<"Syntax: pdnsutil set-kind ZONE KIND"<<endl
;
2383 DNSName
zone(cmds
[1]);
2384 auto kind
=DomainInfo::stringToKind(cmds
[2]);
2385 exit(setZoneKind(zone
, kind
));
2387 else if(cmds
[0]=="set-account") {
2388 if(cmds
.size() != 3) {
2389 cerr
<<"Syntax: pdnsutil set-account ZONE ACCOUNT"<<endl
;
2391 DNSName
zone(cmds
[1]);
2392 exit(setZoneAccount(zone
, cmds
[2]));
2394 else if(cmds
[0]=="set-nsec3") {
2395 if(cmds
.size() < 2) {
2396 cerr
<<"Syntax: pdnsutil set-nsec3 ZONE 'params' [narrow]"<<endl
;
2399 string nsec3params
= cmds
.size() > 2 ? cmds
[2] : "1 0 1 ab";
2400 bool narrow
= cmds
.size() > 3 && cmds
[3]=="narrow";
2401 NSEC3PARAMRecordContent
ns3pr(nsec3params
);
2403 DNSName
zone(cmds
[1]);
2404 if (zone
.wirelength() > 222) {
2405 cerr
<<"Cannot enable NSEC3 for " << zone
<< " as it is too long (" << zone
.wirelength() << " bytes, maximum is 222 bytes)"<<endl
;
2408 if(ns3pr
.d_algorithm
!= 1) {
2409 cerr
<<"NSEC3PARAM algorithm set to '"<<std::to_string(ns3pr
.d_algorithm
)<<"', but '1' is the only valid value"<<endl
;
2410 return EXIT_FAILURE
;
2412 if (! dk
.setNSEC3PARAM(zone
, ns3pr
, narrow
)) {
2413 cerr
<<"Cannot set NSEC3 param for " << zone
<< endl
;
2418 cerr
<<"NSEC3 set, ";
2420 cerr
<<"NSEC3 (opt-out) set, ";
2422 if(dk
.isSecuredZone(zone
))
2423 cerr
<<"please rectify your zone if your backend needs it"<<endl
;
2425 cerr
<<"please secure and rectify your zone."<<endl
;
2429 else if(cmds
[0]=="set-presigned") {
2430 if(cmds
.size() < 2) {
2431 cerr
<<"Syntax: pdnsutil set-presigned ZONE"<<endl
;
2434 if (! dk
.setPresigned(DNSName(cmds
[1]))) {
2435 cerr
<< "Could not set presigned for " << cmds
[1] << " (is DNSSEC enabled in your backend?)" << endl
;
2440 else if(cmds
[0]=="set-publish-cdnskey") {
2441 if(cmds
.size() < 2) {
2442 cerr
<<"Syntax: pdnsutil set-publish-cdnskey ZONE"<<endl
;
2445 if (! dk
.setPublishCDNSKEY(DNSName(cmds
[1]))) {
2446 cerr
<< "Could not set publishing for CDNSKEY records for "<< cmds
[1]<<endl
;
2451 else if(cmds
[0]=="set-publish-cds") {
2452 if(cmds
.size() < 2) {
2453 cerr
<<"Syntax: pdnsutil set-publish-cds ZONE [DIGESTALGOS]"<<endl
;
2457 // If DIGESTALGOS is unset
2458 if(cmds
.size() == 2)
2459 cmds
.push_back("1,2");
2461 if (! dk
.setPublishCDS(DNSName(cmds
[1]), cmds
[2])) {
2462 cerr
<< "Could not set publishing for CDS records for "<< cmds
[1]<<endl
;
2467 else if(cmds
[0]=="unset-presigned") {
2468 if(cmds
.size() < 2) {
2469 cerr
<<"Syntax: pdnsutil unset-presigned ZONE"<<endl
;
2472 if (! dk
.unsetPresigned(DNSName(cmds
[1]))) {
2473 cerr
<< "Could not unset presigned on for " << cmds
[1] << endl
;
2478 else if(cmds
[0]=="unset-publish-cdnskey") {
2479 if(cmds
.size() < 2) {
2480 cerr
<<"Syntax: pdnsutil unset-publish-cdnskey ZONE"<<endl
;
2483 if (! dk
.unsetPublishCDNSKEY(DNSName(cmds
[1]))) {
2484 cerr
<< "Could not unset publishing for CDNSKEY records for "<< cmds
[1]<<endl
;
2489 else if(cmds
[0]=="unset-publish-cds") {
2490 if(cmds
.size() < 2) {
2491 cerr
<<"Syntax: pdnsutil unset-publish-cds ZONE"<<endl
;
2494 if (! dk
.unsetPublishCDS(DNSName(cmds
[1]))) {
2495 cerr
<< "Could not unset publishing for CDS records for "<< cmds
[1]<<endl
;
2500 else if(cmds
[0]=="hash-zone-record") {
2501 if(cmds
.size() < 3) {
2502 cerr
<<"Syntax: pdnsutil hash-zone-record ZONE RNAME"<<endl
;
2505 DNSName
zone(cmds
[1]);
2506 DNSName
record(cmds
[2]);
2507 NSEC3PARAMRecordContent ns3pr
;
2509 if(!dk
.getNSEC3PARAM(zone
, &ns3pr
, &narrow
)) {
2510 cerr
<<"The '"<<zone
<<"' zone does not use NSEC3"<<endl
;
2514 cerr
<<"The '"<<zone
<<"' zone uses narrow NSEC3, but calculating hash anyhow"<<endl
;
2517 cout
<<toBase32Hex(hashQNameWithSalt(ns3pr
, record
))<<endl
;
2519 else if(cmds
[0]=="unset-nsec3") {
2520 if(cmds
.size() < 2) {
2521 cerr
<<"Syntax: pdnsutil unset-nsec3 ZONE"<<endl
;
2524 if ( ! dk
.unsetNSEC3PARAM(DNSName(cmds
[1]))) {
2525 cerr
<<"Cannot unset NSEC3 param for " << cmds
[1] << endl
;
2530 else if(cmds
[0]=="export-zone-key") {
2531 if(cmds
.size() < 3) {
2532 cerr
<<"Syntax: pdnsutil export-zone-key ZONE KEY-ID"<<endl
;
2536 string zone
=cmds
[1];
2537 unsigned int id
=pdns_stou(cmds
[2]);
2538 DNSSECPrivateKey dpk
=dk
.getKeyById(DNSName(zone
), id
);
2539 cout
<< dpk
.getKey()->convertToISC() <<endl
;
2541 else if(cmds
[0]=="increase-serial") {
2542 if (cmds
.size() < 2) {
2543 cerr
<<"Syntax: pdnsutil increase-serial ZONE"<<endl
;
2546 return increaseSerial(DNSName(cmds
[1]), dk
);
2548 else if(cmds
[0]=="import-zone-key-pem") {
2549 if(cmds
.size() < 4) {
2550 cerr
<<"Syntax: pdnsutil import-zone-key-pem ZONE FILE ALGORITHM {ksk|zsk}"<<endl
;
2553 string zone
=cmds
[1];
2554 string fname
=cmds
[2];
2556 ifstream
ifs(fname
.c_str());
2557 string tmp
, interim
, raw
;
2558 while(getline(ifs
, line
)) {
2564 B64Decode(interim
, raw
);
2565 DNSSECPrivateKey dpk
;
2566 DNSKEYRecordContent drc
;
2567 shared_ptr
<DNSCryptoKeyEngine
> key(DNSCryptoKeyEngine::makeFromPEMString(drc
, raw
));
2570 dpk
.d_algorithm
= pdns_stou(cmds
[3]);
2572 if(dpk
.d_algorithm
== DNSSECKeeper::RSASHA1NSEC3SHA1
)
2573 dpk
.d_algorithm
= DNSSECKeeper::RSASHA1
;
2575 cerr
<<(int)dpk
.d_algorithm
<<endl
;
2577 if(cmds
.size() > 4) {
2578 if(pdns_iequals(cmds
[4], "ZSK"))
2580 else if(pdns_iequals(cmds
[4], "KSK"))
2583 cerr
<<"Unknown key flag '"<<cmds
[4]<<"'"<<endl
;
2588 dpk
.d_flags
= 257; // ksk
2591 if (!dk
.addKey(DNSName(zone
), dpk
, id
)) {
2592 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2596 cerr
<<std::to_string(id
)<<"Key was added, but backend does not support returning of key id"<<endl
;
2597 } else if (id
< -1) {
2598 cerr
<<std::to_string(id
)<<"Key was added, but there was a failure while returning the key id"<<endl
;
2600 cout
<<std::to_string(id
)<<endl
;
2604 else if(cmds
[0]=="import-zone-key") {
2605 if(cmds
.size() < 3) {
2606 cerr
<<"Syntax: pdnsutil import-zone-key ZONE FILE [ksk|zsk] [active|inactive]"<<endl
;
2609 string zone
=cmds
[1];
2610 string fname
=cmds
[2];
2611 DNSSECPrivateKey dpk
;
2612 DNSKEYRecordContent drc
;
2613 shared_ptr
<DNSCryptoKeyEngine
> key(DNSCryptoKeyEngine::makeFromISCFile(drc
, fname
.c_str()));
2615 dpk
.d_algorithm
= drc
.d_algorithm
;
2617 if(dpk
.d_algorithm
== DNSSECKeeper::RSASHA1NSEC3SHA1
)
2618 dpk
.d_algorithm
= DNSSECKeeper::RSASHA1
;
2623 for(unsigned int n
= 3; n
< cmds
.size(); ++n
) {
2624 if(pdns_iequals(cmds
[n
], "ZSK"))
2626 else if(pdns_iequals(cmds
[n
], "KSK"))
2628 else if(pdns_iequals(cmds
[n
], "active"))
2630 else if(pdns_iequals(cmds
[n
], "passive") || pdns_iequals(cmds
[n
], "inactive")) // passive eventually needs to be removed
2633 cerr
<<"Unknown key flag '"<<cmds
[n
]<<"'"<<endl
;
2638 if (!dk
.addKey(DNSName(zone
), dpk
, id
, active
)) {
2639 cerr
<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<<endl
;
2643 cerr
<<std::to_string(id
)<<"Key was added, but backend does not support returning of key id"<<endl
;
2644 } else if (id
< -1) {
2645 cerr
<<std::to_string(id
)<<"Key was added, but there was a failure while returning the key id"<<endl
;
2647 cout
<<std::to_string(id
)<<endl
;
2650 else if(cmds
[0]=="export-zone-dnskey") {
2651 if(cmds
.size() < 3) {
2652 cerr
<<"Syntax: pdnsutil export-zone-dnskey ZONE KEY-ID"<<endl
;
2656 DNSName
zone(cmds
[1]);
2657 unsigned int id
=pdns_stou(cmds
[2]);
2658 DNSSECPrivateKey dpk
=dk
.getKeyById(zone
, id
);
2659 cout
<< zone
<<" IN DNSKEY "<<dpk
.getDNSKEY().getZoneRepresentation() <<endl
;
2661 else if(cmds
[0] == "generate-zone-key") {
2662 if(cmds
.size() < 2 ) {
2663 cerr
<< "Syntax: pdnsutil generate-zone-key zsk|ksk [rsasha1|rsasha256|rsasha512|gost|ecdsa256|ecdsa384] [bits]"<<endl
;
2666 // need to get algorithm, bits & ksk or zsk from commandline
2667 bool keyOrZone
=false;
2670 int algorithm
=DNSSECKeeper::ECDSA256
;
2671 for(unsigned int n
=1; n
< cmds
.size(); ++n
) {
2672 if(pdns_iequals(cmds
[n
], "zsk"))
2674 else if(pdns_iequals(cmds
[n
], "ksk"))
2676 else if((tmp_algo
= DNSSECKeeper::shorthand2algorithm(cmds
[n
]))>0) {
2677 algorithm
= tmp_algo
;
2678 } else if(pdns_stou(cmds
[n
]))
2679 bits
= pdns_stou(cmds
[n
]);
2681 cerr
<<"Unknown algorithm, key flag or size '"<<cmds
[n
]<<"'"<<endl
;
2685 cerr
<<"Generating a " << (keyOrZone
? "KSK" : "ZSK")<<" with algorithm = "<<algorithm
<<endl
;
2687 cerr
<<"Requesting specific key size of "<<bits
<<" bits"<<endl
;
2689 DNSSECPrivateKey dspk
;
2690 shared_ptr
<DNSCryptoKeyEngine
> dpk(DNSCryptoKeyEngine::make(algorithm
)); // defaults to RSA for now, could be smart w/algorithm! XXX FIXME
2693 bits
= keyOrZone
? 2048 : 1024;
2695 if(algorithm
== DNSSECKeeper::ECCGOST
|| algorithm
== DNSSECKeeper::ECDSA256
|| algorithm
== DNSSECKeeper::ED25519
)
2697 else if(algorithm
== DNSSECKeeper::ECDSA384
)
2699 else if(algorithm
== DNSSECKeeper::ED448
)
2702 throw runtime_error("Can not guess key size for algorithm "+std::to_string(algorithm
));
2708 dspk
.d_algorithm
= algorithm
;
2709 dspk
.d_flags
= keyOrZone
? 257 : 256;
2711 // print key to stdout
2712 cout
<< "Flags: " << dspk
.d_flags
<< endl
<<
2713 dspk
.getKey()->convertToISC() << endl
;
2714 } else if (cmds
[0]=="generate-tsig-key") {
2715 string usage
= "Syntax: " + cmds
[0] + " name (hmac-md5|hmac-sha1|hmac-sha224|hmac-sha256|hmac-sha384|hmac-sha512)";
2716 if (cmds
.size() < 3) {
2717 cerr
<< usage
<< endl
;
2720 DNSName
name(cmds
[1]);
2721 string algo
= cmds
[2];
2726 if (algo
== "hmac-md5") {
2728 } else if (algo
== "hmac-sha1") {
2730 } else if (algo
== "hmac-sha224") {
2732 } else if (algo
== "hmac-sha256") {
2734 } else if (algo
== "hmac-sha384") {
2736 } else if (algo
== "hmac-sha512") {
2739 cerr
<< "Cannot generate key for " << algo
<< endl
;
2740 cerr
<< usage
<< endl
;
2744 cerr
<< "Generating new key with " << klen
<< " bytes" << endl
;
2745 for(size_t i
= 0; i
< klen
; i
+=4) {
2746 *(unsigned int*)(tmpkey
+i
) = dns_random(0xffffffff);
2748 key
= Base64Encode(std::string(tmpkey
, klen
));
2750 UeberBackend
B("default");
2751 if (B
.setTSIGKey(name
, DNSName(algo
), key
)) { // you are feeling bored, put up DNSName(algo) up earlier
2752 cout
<< "Create new TSIG key " << name
<< " " << algo
<< " " << key
<< endl
;
2754 cerr
<< "Failure storing new TSIG key " << name
<< " " << algo
<< " " << key
<< endl
;
2758 } else if (cmds
[0]=="import-tsig-key") {
2759 if (cmds
.size() < 4) {
2760 cerr
<< "Syntax: " << cmds
[0] << " name algorithm key" << endl
;
2763 DNSName
name(cmds
[1]);
2764 string algo
= cmds
[2];
2765 string key
= cmds
[3];
2767 UeberBackend
B("default");
2768 if (B
.setTSIGKey(name
, DNSName(algo
), key
)) {
2769 cout
<< "Imported TSIG key " << name
<< " " << algo
<< endl
;
2771 cerr
<< "Failure importing TSIG key " << name
<< " " << algo
<< endl
;
2775 } else if (cmds
[0]=="delete-tsig-key") {
2776 if (cmds
.size() < 2) {
2777 cerr
<< "Syntax: " << cmds
[0] << " name" << endl
;
2780 DNSName
name(cmds
[1]);
2782 UeberBackend
B("default");
2783 if (B
.deleteTSIGKey(name
)) {
2784 cout
<< "Deleted TSIG key " << name
<< endl
;
2786 cerr
<< "Failure deleting TSIG key " << name
<< endl
;
2790 } else if (cmds
[0]=="list-tsig-keys") {
2791 std::vector
<struct TSIGKey
> keys
;
2792 UeberBackend
B("default");
2793 if (B
.getTSIGKeys(keys
)) {
2794 for(const TSIGKey
&key
: keys
) {
2795 cout
<< key
.name
.toString() << " " << key
.algorithm
.toString() << " " << key
.key
<< endl
;
2799 } else if (cmds
[0]=="activate-tsig-key") {
2801 if (cmds
.size() < 4) {
2802 cerr
<< "Syntax: " << cmds
[0] << " ZONE NAME {master|slave}" << endl
;
2805 DNSName
zname(cmds
[1]);
2806 string name
= cmds
[2];
2807 if (cmds
[3] == "master")
2808 metaKey
= "TSIG-ALLOW-AXFR";
2809 else if (cmds
[3] == "slave")
2810 metaKey
= "AXFR-MASTER-TSIG";
2812 cerr
<< "Invalid parameter '" << cmds
[3] << "', expected master or slave" << endl
;
2815 UeberBackend
B("default");
2816 std::vector
<std::string
> meta
;
2817 if (!B
.getDomainMetadata(zname
, metaKey
, meta
)) {
2818 cerr
<< "Failure enabling TSIG key " << name
<< " for " << zname
<< endl
;
2822 for(std::string tmpname
: meta
) {
2823 if (tmpname
== name
) { found
= true; break; }
2825 if (!found
) meta
.push_back(name
);
2826 if (B
.setDomainMetadata(zname
, metaKey
, meta
)) {
2827 cout
<< "Enabled TSIG key " << name
<< " for " << zname
<< endl
;
2829 cerr
<< "Failure enabling TSIG key " << name
<< " for " << zname
<< endl
;
2833 } else if (cmds
[0]=="deactivate-tsig-key") {
2835 if (cmds
.size() < 4) {
2836 cerr
<< "Syntax: " << cmds
[0] << " ZONE NAME {master|slave}" << endl
;
2839 DNSName
zname(cmds
[1]);
2840 string name
= cmds
[2];
2841 if (cmds
[3] == "master")
2842 metaKey
= "TSIG-ALLOW-AXFR";
2843 else if (cmds
[3] == "slave")
2844 metaKey
= "AXFR-MASTER-TSIG";
2846 cerr
<< "Invalid parameter '" << cmds
[3] << "', expected master or slave" << endl
;
2850 UeberBackend
B("default");
2851 std::vector
<std::string
> meta
;
2852 if (!B
.getDomainMetadata(zname
, metaKey
, meta
)) {
2853 cerr
<< "Failure disabling TSIG key " << name
<< " for " << zname
<< endl
;
2856 std::vector
<std::string
>::iterator iter
= meta
.begin();
2857 for(;iter
!= meta
.end(); iter
++) if (*iter
== name
) break;
2858 if (iter
!= meta
.end()) meta
.erase(iter
);
2859 if (B
.setDomainMetadata(zname
, metaKey
, meta
)) {
2860 cout
<< "Disabled TSIG key " << name
<< " for " << zname
<< endl
;
2862 cerr
<< "Failure disabling TSIG key " << name
<< " for " << zname
<< endl
;
2866 } else if (cmds
[0]=="get-meta") {
2867 UeberBackend
B("default");
2868 if (cmds
.size() < 2) {
2869 cerr
<< "Syntax: " << cmds
[0] << " zone [kind kind ..]" << endl
;
2872 DNSName
zone(cmds
[1]);
2873 vector
<string
> keys
;
2876 if (!B
.getDomainInfo(zone
, di
)) {
2877 cerr
<< "Invalid zone '" << zone
<< "'" << endl
;
2881 if (cmds
.size() > 2) {
2882 keys
.assign(cmds
.begin() + 2, cmds
.end());
2883 std::cout
<< "Metadata for '" << zone
<< "'" << endl
;
2884 for(const string kind
: keys
) {
2885 vector
<string
> meta
;
2887 if (B
.getDomainMetadata(zone
, kind
, meta
)) {
2888 cout
<< kind
<< " = " << boost::join(meta
, ", ") << endl
;
2892 std::map
<std::string
, std::vector
<std::string
> > meta
;
2893 std::cout
<< "Metadata for '" << zone
<< "'" << endl
;
2894 B
.getAllDomainMetadata(zone
, meta
);
2895 for(std::map
<std::string
, std::vector
<std::string
> >::const_iterator each_meta
= meta
.begin(); each_meta
!= meta
.end(); each_meta
++) {
2896 cout
<< each_meta
->first
<< " = " << boost::join(each_meta
->second
, ", ") << endl
;
2901 } else if (cmds
[0]=="set-meta" || cmds
[0]=="add-meta") {
2902 if (cmds
.size() < 3) {
2903 cerr
<< "Syntax: " << cmds
[0] << " ZONE KIND [VALUE VALUE ..]" << endl
;
2906 DNSName
zone(cmds
[1]);
2907 string kind
= cmds
[2];
2908 static vector
<string
> multiMetaWhitelist
= {"ALLOW-AXFR-FROM", "ALLOW-DNSUPDATE-FROM",
2909 "ALSO-NOTIFY", "TSIG-ALLOW-AXFR", "TSIG-ALLOW-DNSUPDATE", "GSS-ALLOW-AXFR-PRINCIPAL",
2911 bool clobber
= true;
2912 if (cmds
[0] == "add-meta") {
2914 if (find(multiMetaWhitelist
.begin(), multiMetaWhitelist
.end(), kind
) == multiMetaWhitelist
.end() && kind
.find("X-") != 0) {
2915 cerr
<<"Refusing to add metadata to single-value metadata "<<kind
<<endl
;
2919 vector
<string
> meta(cmds
.begin() + 3, cmds
.end());
2920 return addOrSetMeta(zone
, kind
, meta
, clobber
);
2921 } else if (cmds
[0]=="hsm") {
2923 UeberBackend
B("default");
2924 if (cmds
.size() < 2) {
2925 cerr
<< "Missing sub-command for pdnsutil hsm"<< std::endl
;
2927 } else if (cmds
[1] == "assign") {
2928 DNSCryptoKeyEngine::storvector_t storvect
;
2930 std::vector
<DNSBackend::KeyData
> keys
;
2932 if (cmds
.size() < 9) {
2933 std::cout
<< "Usage: pdnsutil hsm assign ZONE ALGORITHM {ksk|zsk} MODULE TOKEN PIN LABEL (PUBLABEL)" << std::endl
;
2937 DNSName
zone(cmds
[2]);
2940 if (!B
.getDomainInfo(zone
, di
)) {
2941 cerr
<< "Unable to assign module to unknown zone '" << zone
<< "'" << std::endl
;
2945 int algorithm
= DNSSECKeeper::shorthand2algorithm(cmds
[3]);
2947 cerr
<< "Unable to use unknown algorithm '" << cmds
[3] << "'" << std::endl
;
2952 bool keyOrZone
= (cmds
[4] == "ksk" ? true : false);
2953 string module
= cmds
[5];
2954 string slot
= cmds
[6];
2955 string pin
= cmds
[7];
2956 string label
= cmds
[8];
2958 if (cmds
.size() > 9)
2959 pub_label
= cmds
[9];
2963 std::ostringstream iscString
;
2964 iscString
<< "Private-key-format: v1.2" << std::endl
<<
2965 "Algorithm: " << algorithm
<< std::endl
<<
2966 "Engine: " << module
<< std::endl
<<
2967 "Slot: " << slot
<< std::endl
<<
2968 "PIN: " << pin
<< std::endl
<<
2969 "Label: " << label
<< std::endl
<<
2970 "PubLabel: " << pub_label
<< std::endl
;
2972 DNSKEYRecordContent drc
;
2973 DNSSECPrivateKey dpk
;
2974 dpk
.d_flags
= (keyOrZone
? 257 : 256);
2976 shared_ptr
<DNSCryptoKeyEngine
> dke(DNSCryptoKeyEngine::makeFromISCString(drc
, iscString
.str()));
2977 if(!dke
->checkKey()) {
2978 cerr
<< "Invalid DNS Private Key in engine " << module
<< " slot " << slot
<< std::endl
;
2983 // make sure this key isn't being reused.
2984 B
.getDomainKeys(zone
, keys
);
2987 for(DNSBackend::KeyData
& kd
: keys
) {
2988 if (kd
.content
== iscString
.str()) {
2989 // it's this one, I guess...
2996 cerr
<< "You have already assigned this key with ID=" << id
<< std::endl
;
3000 if (!dk
.addKey(zone
, dpk
, id
)) {
3001 cerr
<< "Unable to assign module slot to zone" << std::endl
;
3005 cerr
<< "Module " << module
<< " slot " << slot
<< " assigned to " << zone
<< " with key id " << id
<< endl
;
3008 } else if (cmds
[1] == "create-key") {
3010 if (cmds
.size() < 4) {
3011 cerr
<< "Usage: pdnsutil hsm create-key ZONE KEY-ID [BITS]" << endl
;
3015 DNSName
zone(cmds
[2]);
3019 if (!B
.getDomainInfo(zone
, di
)) {
3020 cerr
<< "Unable to create key for unknown zone '" << zone
<< "'" << std::endl
;
3024 id
= pdns_stou(cmds
[3]);
3025 std::vector
<DNSBackend::KeyData
> keys
;
3026 if (!B
.getDomainKeys(zone
, keys
)) {
3027 cerr
<< "No keys found for zone " << zone
<< std::endl
;
3031 std::shared_ptr
<DNSCryptoKeyEngine
> dke
= nullptr;
3032 // lookup correct key
3033 for(DNSBackend::KeyData
&kd
: keys
) {
3036 DNSKEYRecordContent dkrc
;
3037 dke
= DNSCryptoKeyEngine::makeFromISCString(dkrc
, kd
.content
);
3042 cerr
<< "Could not find key with ID " << id
<< endl
;
3045 if (cmds
.size() > 4) {
3046 bits
= pdns_stou(cmds
[4]);
3049 cerr
<< "Invalid bit size " << bits
<< "given, must be positive integer";
3054 } catch (PDNSException
& e
) {
3055 cerr
<< e
.reason
<< endl
;
3059 cerr
<< "Key of size " << bits
<< " created" << std::endl
;
3063 cerr
<<"PKCS#11 support not enabled"<<endl
;
3066 } else if (cmds
[0] == "b2b-migrate") {
3067 if (cmds
.size() < 3) {
3068 cerr
<<"Usage: b2b-migrate OLD NEW"<<endl
;
3072 DNSBackend
*src
,*tgt
;
3075 for(DNSBackend
*b
: BackendMakers().all()) {
3076 if (b
->getPrefix() == cmds
[1]) src
= b
;
3077 if (b
->getPrefix() == cmds
[2]) tgt
= b
;
3080 cerr
<<"Unknown source backend '"<<cmds
[1]<<"'"<<endl
;
3084 cerr
<<"Unknown target backend '"<<cmds
[2]<<"'"<<endl
;
3088 cout
<<"Moving zone(s) from "<<src
->getPrefix()<<" to "<<tgt
->getPrefix()<<endl
;
3090 vector
<DomainInfo
> domains
;
3092 tgt
->getAllDomains(&domains
, true);
3093 if (domains
.size()>0)
3094 throw PDNSException("Target backend has domain(s), please clean it first");
3096 src
->getAllDomains(&domains
, true);
3098 for(const DomainInfo
& di
: domains
) {
3100 DNSResourceRecord rr
;
3101 cout
<<"Processing '"<<di
.zone
<<"'"<<endl
;
3103 if (!tgt
->createDomain(di
.zone
)) throw PDNSException("Failed to create zone");
3104 tgt
->setKind(di
.zone
, di
.kind
);
3105 tgt
->setAccount(di
.zone
,di
.account
);
3108 for(const string
& master
: di
.masters
) {
3114 tgt
->setMaster(di
.zone
, masters
);
3116 if (!src
->list(di
.zone
, di
.id
, true)) throw PDNSException("Failed to list records");
3118 while(src
->get(rr
)) {
3119 if (!tgt
->feedRecord(rr
, DNSName())) throw PDNSException("Failed to feed record");
3124 if (src
->listComments(di
.id
)) {
3126 while(src
->getComment(c
)) {
3127 tgt
->feedComment(c
);
3133 std::map
<std::string
, std::vector
<std::string
> > meta
;
3134 if (src
->getAllDomainMetadata(di
.zone
, meta
)) {
3135 std::map
<std::string
, std::vector
<std::string
> >::iterator i
;
3136 for(i
=meta
.begin(); i
!= meta
.end(); i
++) {
3137 if (!tgt
->setDomainMetadata(di
.zone
, i
->first
, i
->second
)) throw PDNSException("Failed to feed domain metadata");
3143 // temp var for KeyID
3145 std::vector
<DNSBackend::KeyData
> keys
;
3146 if (src
->getDomainKeys(di
.zone
, keys
)) {
3147 for(const DNSBackend::KeyData
& k
: keys
) {
3148 tgt
->addDomainKey(di
.zone
, k
, keyID
);
3152 cout
<<"Moved "<<nr
<<" record(s), "<<nc
<<" comment(s), "<<nm
<<" metadata(s) and "<<nk
<<" cryptokey(s)"<<endl
;
3157 std::vector
<struct TSIGKey
> tkeys
;
3158 if (src
->getTSIGKeys(tkeys
)) {
3159 for(auto& tk
: tkeys
) {
3160 if (!tgt
->setTSIGKey(tk
.name
, tk
.algorithm
, tk
.key
)) throw PDNSException("Failed to feed TSIG key");
3164 cout
<<"Moved "<<ntk
<<" TSIG key(s)"<<endl
;
3166 cout
<<"Remember to drop the old backend and run rectify-all-zones"<<endl
;
3169 } else if (cmds
[0] == "backend-cmd") {
3170 if (cmds
.size() < 3) {
3171 cerr
<<"Usage: backend-cmd BACKEND CMD [CMD..]"<<endl
;
3178 for(DNSBackend
*b
: BackendMakers().all()) {
3179 if (b
->getPrefix() == cmds
[1]) db
= b
;
3183 cerr
<<"Unknown backend '"<<cmds
[1]<<"'"<<endl
;
3187 for(auto i
=next(begin(cmds
),2); i
!= end(cmds
); ++i
) {
3188 cerr
<<"== "<<*i
<<endl
;
3189 cout
<<db
->directBackendCmd(*i
);
3194 cerr
<<"Unknown command '"<<cmds
[0] <<"'"<< endl
;
3199 catch(PDNSException
& ae
) {
3200 cerr
<<"Error: "<<ae
.reason
<<endl
;
3203 catch(std::exception
& e
) {
3204 cerr
<<"Error: "<<e
.what()<<endl
;
3209 cerr
<<"Caught an unknown exception"<<endl
;