]> granicus.if.org Git - pdns/commitdiff
pdnssec check-all-zones: allow exit on first error
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 21 Jul 2015 10:04:26 +0000 (12:04 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 6 Aug 2015 15:58:48 +0000 (17:58 +0200)
Closes #518.

Furthermore, `pdnssec check-zone` and `pdnssec check-all-zones` now
exits with 1 when one or more errors have been found and 0 when the/all
zone(s) are OK.

pdns/pdnssec.cc

index b619701a46c90f5cf05847a0a21c2da46ae7f835..53013ab20a92e12276c0dbf30f13c4658769ed15 100644 (file)
@@ -626,22 +626,29 @@ int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone)
   }
 
   cout<<"Checked "<<numrecords<<" records of '"<<zone.toString()<<"', "<<numerrors<<" errors, "<<numwarnings<<" warnings."<<endl;
-  return numerrors;
+  if(!numerrors)
+    return 0;
+  return 1;
 }
 
-int checkAllZones(DNSSECKeeper &dk
+int checkAllZones(DNSSECKeeper &dk, bool exitOnError)
 {
   UeberBackend B("default");
   vector<DomainInfo> domainInfo;
 
   B.getAllDomains(&domainInfo, true);
   int errors=0;
-  BOOST_FOREACH(DomainInfo di, domainInfo) {
-    if (checkZone(dk, B, di.zone) > 0) 
-       errors++;
+  for(auto di : domainInfo) {
+    if (checkZone(dk, B, di.zone) > 0) {
+      errors++;
+      if(exitOnError)
+        return 1;
+    }
   }
   cout<<"Checked "<<domainInfo.size()<<" zones, "<<errors<<" had errors."<<endl;
-  return 0;
+  if(!errors)
+    return 0;
+  return 1;
 }
 
 int increaseSerial(const DNSName& zone, DNSSECKeeper &dk)
@@ -1285,7 +1292,8 @@ try
     cerr<<"b2b-migrate old new                Move all data from one backend to another"<<endl;
     cerr<<"bench-db [filename]                Bench database backend with queries, one domain per line"<<endl;
     cerr<<"check-zone ZONE                    Check a zone for correctness"<<endl;
-    cerr<<"check-all-zones                    Check all zones for correctness"<<endl;
+    cerr<<"check-all-zones [exit-on-error]    Check all zones for correctness. Set exit-on-error to exit immediately"<<endl;
+    cerr<<"                                   after finding an error in a zone."<<endl;
     cerr<<"create-bind-db FNAME               Create DNSSEC db for BIND backend (bind-dnssec-db)"<<endl;
     cerr<<"create-zone ZONE                   Create empty zone ZONE"<<endl;
     cerr<<"deactivate-tsig-key ZONE NAME [master|slave]"<<endl;
@@ -1410,7 +1418,8 @@ try
     dbBench(cmds.size() > 1 ? cmds[1] : "");
   }
   else if (cmds[0] == "check-all-zones") {
-    exit(checkAllZones(dk));
+    bool exitOnError = (cmds[1] == "exit-on-error");
+    exit(checkAllZones(dk, exitOnError));
   }
   else if (cmds[0] == "list-all-zones") {
     if (cmds.size() > 2) {