Skip to content

Commit 032e390

Browse files
author
Peter van Dijk
committed
make pdnssec exit with 1 on some error conditions, closes #677
1 parent 8ad5cc4 commit 032e390

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

pdns/pdnssec.cc

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void loadMainConfig(const std::string& configdir)
163163

164164
// irritatingly enough, rectifyZone needs its own ueberbackend and can't therefore benefit from transactions outside its scope
165165
// I think this has to do with interlocking transactions between B and DK, but unsure.
166-
void rectifyZone(DNSSECKeeper& dk, const std::string& zone)
166+
bool rectifyZone(DNSSECKeeper& dk, const std::string& zone)
167167
{
168168
UeberBackend B("default");
169169
bool doTransaction=true; // but see above
@@ -172,7 +172,7 @@ void rectifyZone(DNSSECKeeper& dk, const std::string& zone)
172172

173173
if(!B.getSOA(zone, sd)) {
174174
cerr<<"No SOA known for '"<<zone<<"', is such a zone in the database?"<<endl;
175-
return;
175+
return false;
176176
}
177177
sd.db->list(zone, sd.domain_id);
178178

@@ -305,6 +305,8 @@ void rectifyZone(DNSSECKeeper& dk, const std::string& zone)
305305

306306
if(doTransaction)
307307
sd.db->commitTransaction();
308+
309+
return true;
308310
}
309311

310312
void rectifyAllZones(DNSSECKeeper &dk)
@@ -557,11 +559,19 @@ void verifyCrypto(const string& zone)
557559
#endif
558560

559561
}
560-
void disableDNSSECOnZone(DNSSECKeeper& dk, const string& zone)
562+
bool disableDNSSECOnZone(DNSSECKeeper& dk, const string& zone)
561563
{
564+
UeberBackend B("default");
565+
DomainInfo di;
566+
567+
if (!B.getDomainInfo(zone, di)){
568+
cerr << "No such zone in the database" << endl;
569+
return false;
570+
}
571+
562572
if(!dk.isSecuredZone(zone)) {
563573
cerr<<"Zone is not secured\n";
564-
return;
574+
return false;
565575
}
566576
DNSSECKeeper::keyset_t keyset=dk.getKeys(zone);
567577

@@ -576,9 +586,18 @@ void disableDNSSECOnZone(DNSSECKeeper& dk, const string& zone)
576586
}
577587
dk.unsetNSEC3PARAM(zone);
578588
dk.unsetPresigned(zone);
589+
return true;
579590
}
580-
void showZone(DNSSECKeeper& dk, const std::string& zone)
591+
bool showZone(DNSSECKeeper& dk, const std::string& zone)
581592
{
593+
UeberBackend B("default");
594+
DomainInfo di;
595+
596+
if (!B.getDomainInfo(zone, di)){
597+
cerr << "No such zone in the database" << endl;
598+
return false;
599+
}
600+
582601
if(!dk.isSecuredZone(zone)) {
583602
cerr<<"Zone is not actively secured\n";
584603
}
@@ -628,6 +647,7 @@ void showZone(DNSSECKeeper& dk, const std::string& zone)
628647
}
629648
}
630649
}
650+
return true;
631651
}
632652

633653
bool secureZone(DNSSECKeeper& dk, const std::string& zone)
@@ -928,8 +948,10 @@ try
928948
cerr << "Syntax: pdnssec rectify-zone ZONE [ZONE..]"<<endl;
929949
return 0;
930950
}
951+
unsigned int exitCode = 0;
931952
for(unsigned int n = 1; n < cmds.size(); ++n)
932-
rectifyZone(dk, cmds[n]);
953+
if (!rectifyZone(dk, cmds[n])) exitCode = 1;
954+
return exitCode;
933955
}
934956
else if (cmds[0] == "rectify-all-zones") {
935957
rectifyAllZones(dk);
@@ -984,15 +1006,16 @@ try
9841006
return 0;
9851007
}
9861008
const string& zone=cmds[1];
987-
showZone(dk, zone);
1009+
if (!showZone(dk, zone)) return 1;
9881010
}
9891011
else if(cmds[0] == "disable-dnssec") {
9901012
if(cmds.size() != 2) {
9911013
cerr << "Syntax: pdnssec disable-dnssec ZONE"<<endl;
9921014
return 0;
9931015
}
9941016
const string& zone=cmds[1];
995-
disableDNSSECOnZone(dk, zone);
1017+
if(!disableDNSSECOnZone(dk, zone))
1018+
return 1;
9961019
}
9971020
else if(cmds[0] == "activate-zone-key") {
9981021
if(cmds.size() != 3) {
@@ -1036,6 +1059,15 @@ try
10361059
return 0;
10371060
}
10381061
const string& zone=cmds[1];
1062+
1063+
UeberBackend B("default");
1064+
DomainInfo di;
1065+
1066+
if (!B.getDomainInfo(zone, di)){
1067+
cerr << "No such zone in the database" << endl;
1068+
return 0;
1069+
}
1070+
10391071
// need to get algorithm, bits & ksk or zsk from commandline
10401072
bool keyOrZone=false;
10411073
int tmp_algo=0;

0 commit comments

Comments
 (0)