Skip to content

Commit

Permalink
Address some clang-tidy complaints in pdnsutil.
Browse files Browse the repository at this point in the history
  • Loading branch information
miodvallat committed Jan 17, 2025
1 parent fc4ea15 commit 3339cd6
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions pdns/pdnsutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void loadMainConfig(const std::string& configdir)
::arg().set("max-generate-steps", "Maximum number of $GENERATE steps when loading a zone from a file")="0";
::arg().set("max-include-depth", "Maximum nested $INCLUDE depth when loading a zone from a file")="20";
::arg().setSwitch("upgrade-unknown-types","Transparently upgrade known TYPExxx records. Recommended to keep off, except for PowerDNS upgrades until data sources are cleaned up")="no";
::arg().laxFile(configname.c_str());
::arg().laxFile(configname);

if(!::arg()["load-modules"].empty()) {
vector<string> modules;
Expand Down Expand Up @@ -152,7 +152,7 @@ static void loadMainConfig(const std::string& configdir)
::arg().set("consistent-backends", "Assume individual zones are not divided over backends. Send only ANY lookup operations to the backend to reduce the number of lookups") = "yes";

// Keep this line below all ::arg().set() statements
if (! ::arg().laxFile(configname.c_str()))
if (! ::arg().laxFile(configname))

Check warning on line 155 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
cerr<<"Warning: unable to read configuration file '"<<configname<<"': "<<stringerror()<<endl;

#ifdef HAVE_LIBSODIUM
Expand Down Expand Up @@ -209,7 +209,7 @@ static void dbBench(const std::string& fname)
}
}
if(domains.empty())
domains.push_back("powerdns.com");
domains.emplace_back("powerdns.com");

int n=0;
DNSZoneRecord rr;
Expand Down Expand Up @@ -298,7 +298,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
NSEC3PARAMRecordContent ns3pr;
bool narrow = false;
bool haveNSEC3 = dk.getNSEC3PARAM(zone, &ns3pr, &narrow);
bool isOptOut=(haveNSEC3 && ns3pr.d_flags);
bool isOptOut=(haveNSEC3 && ns3pr.d_flags != 0);

bool isSecure=dk.isSecuredZone(zone);
bool presigned=dk.isPresigned(zone);
Expand Down Expand Up @@ -414,7 +414,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con

ostringstream o;
o<<rr.content;
for(int pleft=parts.size(); pleft < 7; ++pleft) {
for(auto pleft=parts.size(); pleft < 7; ++pleft) {
o<<" 0";
}
rr.content=o.str();
Expand Down Expand Up @@ -522,12 +522,12 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
if (rr.qtype.getCode() != QType::TXT) {
contentstr=toLower(contentstr);
}
if (recordcontents.count(contentstr)) {
if (recordcontents.count(contentstr) != 0) {
cout<<"[Error] Duplicate record found in rrset: '"<<rr.qname<<" IN "<<rr.qtype.toString()<<" "<<rr.content<<"'"<<endl;
numerrors++;
continue;
} else
recordcontents.insert(std::move(contentstr));
}
recordcontents.insert(std::move(contentstr));

content.str("");
content<<rr.qname<<" "<<rr.qtype.toString();
Expand All @@ -536,13 +536,13 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
content<<" ("<<DNSRecordContent::NumberToType(rrc.d_type)<<")";
}
ret = ttl.insert(pair<string, unsigned int>(toLower(content.str()), rr.ttl));
if (ret.second == false && ret.first->second != rr.ttl) {
if (!ret.second && ret.first->second != rr.ttl) {
cout<<"[Error] TTL mismatch in rrset: '"<<rr.qname<<" IN " <<rr.qtype.toString()<<" "<<rr.content<<"' ("<<ret.first->second<<" != "<<rr.ttl<<")"<<endl;
numerrors++;
continue;
}

if (isSecure && isOptOut && (rr.qname.countLabels() && rr.qname.getRawLabels()[0] == "*")) {
if (isSecure && isOptOut && (rr.qname.countLabels() != 0 && rr.qname.getRawLabels()[0] == "*")) {
cout<<"[Warning] wildcard record '"<<rr.qname<<" IN " <<rr.qtype.toString()<<" "<<rr.content<<"' is insecure"<<endl;
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;
numwarnings++;
Expand All @@ -562,7 +562,8 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
cout<<"[Error] SOA record not at apex '"<<rr.qname<<" IN "<<rr.qtype.toString()<<" "<<rr.content<<"' in zone '"<<zone<<"'"<<endl;
numerrors++;
continue;
} else if (rr.qtype.getCode() == QType::DNSKEY) {
}
if (rr.qtype.getCode() == QType::DNSKEY) {
cout<<"[Warning] DNSKEY record not at apex '"<<rr.qname<<" IN "<<rr.qtype.toString()<<" "<<rr.content<<"' in zone '"<<zone<<"', should not be here."<<endl;
numwarnings++;
} else if (rr.qtype.getCode() == QType::NS) {
Expand Down Expand Up @@ -592,7 +593,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
}

if (rr.qtype.getCode() == QType::CNAME) {
if (!cnames.count(rr.qname))
if (cnames.count(rr.qname) == 0)

Check warning on line 596 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
cnames.insert(rr.qname);
else {
cout<<"[Error] Duplicate CNAME found at '"<<rr.qname<<"'"<<endl;
Expand Down Expand Up @@ -639,7 +640,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
}
}

for(auto &i: cnames) {
for(const auto &i: cnames) {

Check warning on line 643 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

variable name 'i' is too short, expected at least 3 characters (readability-identifier-length - Level=Warning)
if (noncnames.find(i) != noncnames.end()) {
cout<<"[Error] CNAME "<<i<<" found, but other records with same label exist."<<endl;
numerrors++;
Expand Down Expand Up @@ -736,7 +737,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
}

for(const auto &qname : checkglue) {
if (!glue.count(qname)) {
if (glue.count(qname) == 0) {
cout<<"[Warning] Missing glue for '"<<qname<<"' in zone '"<<zone<<"'"<<endl;
numwarnings++;
}
Expand Down Expand Up @@ -801,7 +802,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con

bool ok, ds_ns, done;
for( const auto &rr : records ) {
ok = ( rr.auth == 1 );
ok = rr.auth;
ds_ns = false;
done = (suppliedrecords != nullptr || !sd.db->doesDNSSEC());
for( const auto &qname : checkOcclusion ) {
Expand All @@ -812,7 +813,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
if ( done ) {
continue;
}
if( rr.auth == 0 ) {
if(!rr.auth) {
if( rr.qname.isPartOf( qname.first ) && ( qname.first != rr.qname || rr.qtype != QType::DS ) ) {
ok = done = true;
}
Expand Down Expand Up @@ -855,9 +856,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con
}

cout<<"Checked "<<records.size()<<" records of '"<<zone<<"', "<<numerrors<<" errors, "<<numwarnings<<" warnings."<<endl;
if(!numerrors)
return EXIT_SUCCESS;
return EXIT_FAILURE;
return numerrors;

Check warning on line 859 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

narrowing conversion from 'uint64_t' (aka 'unsigned long') to signed type 'int' is implementation-defined (bugprone-narrowing-conversions - Level=Warning)
}

static int checkAllZones(DNSSECKeeper &dk, bool exitOnError)
Expand Down Expand Up @@ -895,12 +894,12 @@ static int checkAllZones(DNSSECKeeper &dk, bool exitOnError)

seenInfos.insert(std::move(di));

if (errors && exitOnError) {
if (errors != 0 && exitOnError) {
return EXIT_FAILURE;
}
}
cout<<"Checked "<<domainInfo.size()<<" zones, "<<errors<<" had errors."<<endl;
if(!errors)
if(errors == 0)

Check warning on line 902 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
return EXIT_SUCCESS;
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -1013,9 +1012,8 @@ static void listKey(DomainInfo const &di, DNSSECKeeper& dk, bool printHeader = t
if (key.first.getKey()->getBits() < 1) {
cout<<"invalid "<<endl;
continue;
} else {
cout<<key.first.getKey()->getBits()<<string(spacelen, ' ');
}
cout<<key.first.getKey()->getBits()<<string(spacelen, ' ');

string algname = DNSSECKeeper::algorithm2name(key.first.getAlgorithm());
spacelen = (algname.length() >= 16) ? 1 : 16 - algname.length();
Expand All @@ -1026,7 +1024,7 @@ static void listKey(DomainInfo const &di, DNSSECKeeper& dk, bool printHeader = t

#ifdef HAVE_P11KIT1
auto stormap = key.first.getKey()->convertToISCVector();
string engine, slot, label = "";
string engine, slot, label;

Check warning on line 1027 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

multiple declarations in a single statement reduces readability (readability-isolate-declaration - Level=Warning)
for (auto const &elem : stormap) {
//cout<<elem.first<<" "<<elem.second<<endl;
if (elem.first == "Engine")
Expand Down Expand Up @@ -1082,10 +1080,10 @@ static int listZone(const DNSName &zone) {
di.backend->list(zone, di.id);
DNSResourceRecord rr;
cout<<"$ORIGIN ."<<endl;
cout.sync_with_stdio(false);
std::ostream::sync_with_stdio(false);

while(di.backend->get(rr)) {
if(rr.qtype.getCode()) {
if(rr.qtype.getCode() != 0) {
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] != '.')
rr.content.append(1, '.');

Expand Down Expand Up @@ -1144,7 +1142,7 @@ class PDNSColors
{
public:
PDNSColors(bool nocolors)
: d_colors(!nocolors && isatty(STDOUT_FILENO) && getenv("NO_COLORS") == nullptr)
: d_colors(!nocolors && isatty(STDOUT_FILENO) != 0 && getenv("NO_COLORS") == nullptr)

Check warning on line 1145 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

function is not thread safe (concurrency-mt-unsafe - Level=Warning)
{
}
[[nodiscard]] string red() const
Expand Down Expand Up @@ -1191,6 +1189,10 @@ static int editZone(const DNSName &zone, const PDNSColors& col) {
struct deleteme {
~deleteme() { unlink(d_name.c_str()); }
deleteme(string name) : d_name(std::move(name)) {}
deleteme(const deleteme &) = delete;
deleteme(deleteme &&) = delete;
deleteme operator=(const deleteme &) = delete;
deleteme operator=(deleteme &&) = delete;
string d_name;
} dm(tmpnam);

Expand All @@ -1211,7 +1213,7 @@ static int editZone(const DNSName &zone, const PDNSColors& col) {
unixDie("Writing zone to temporary file");
DNSResourceRecord rr;
while(di.backend->get(rr)) {
if(!rr.qtype.getCode())
if(rr.qtype.getCode() == 0)

Check warning on line 1216 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
continue;
DNSRecord dr(rr);
pre.push_back(std::move(dr));
Expand All @@ -1233,7 +1235,7 @@ static int editZone(const DNSName &zone, const PDNSColors& col) {
cmdline+="+"+std::to_string(gotoline)+" ";
cmdline += tmpnam;
int err=system(cmdline.c_str());
if(err) {
if(err != 0) {
unixDie("Editing file with: '"+cmdline+"', perhaps set EDITOR variable");
}
cmdline.clear();
Expand Down Expand Up @@ -1270,7 +1272,7 @@ static int editZone(const DNSName &zone, const PDNSColors& col) {
drr.domain_id = di.id;
checkrr.push_back(std::move(drr));
}
if(checkZone(dk, B, zone, &checkrr)) {
if(checkZone(dk, B, zone, &checkrr) != 0) {
reAsk:;
cerr << col.red() << col.bold() << "There was a problem with your zone" << col.rst() << "\nOptions are: (e)dit your changes, (r)etry with original zone, (a)pply change anyhow, (q)uit: " << std::flush;
int c=read1char();
Expand Down Expand Up @@ -1363,7 +1365,7 @@ static int editZone(const DNSName &zone, const PDNSColors& col) {
cerr<<'\n';
if(c=='q')
return(EXIT_SUCCESS);
else if(c=='e')
if(c=='e')

Check warning on line 1368 in pdns/pdnsutil.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

statement should be inside braces (readability-braces-around-statements - Level=Warning)
goto editMore;
else if(c=='r')
goto editAgain;
Expand Down Expand Up @@ -1425,9 +1427,8 @@ static int zonemdVerifyFile(const DNSName& zone, const string& fname) {
if (validationOK) {
cout << "zonemd-verify-file: Verification of ZONEMD record succeeded" << endl;
return EXIT_SUCCESS;
} else {
cerr << "zonemd-verify-file: Verification of ZONEMD record(s) failed" << endl;
}
cerr << "zonemd-verify-file: Verification of ZONEMD record(s) failed" << endl;
}
else {
cerr << "zonemd-verify-file: No suitable ZONEMD record found to verify against" << endl;
Expand Down Expand Up @@ -1470,8 +1471,7 @@ static int loadZone(const DNSName& zone, const string& fname) {
if (rr.qtype == QType::SOA) {
if (haveSOA)
continue;
else
haveSOA = true;
haveSOA = true;
}
try {
DNSRecordContent::make(rr.qtype, QClass::IN, rr.content);
Expand Down Expand Up @@ -1874,7 +1874,7 @@ static void verifyCrypto(const string& zone)

string msg = getMessageForRRSET(qname, rrc, toSign);
cerr<<"Verify: "<<DNSCryptoKeyEngine::makeFromPublicKeyString(drc.d_algorithm, drc.d_key)->verify(msg, rrc.d_signature)<<endl;
if(dsrc.d_digesttype) {
if(dsrc.d_digesttype != 0) {
cerr<<"Calculated DS: "<<apex.toString()<<" IN DS "<<makeDSFromDNSKey(apex, drc, dsrc.d_digesttype).getZoneRepresentation()<<endl;
cerr<<"Original DS: "<<apex.toString()<<" IN DS "<<dsrc.getZoneRepresentation()<<endl;
}
Expand Down Expand Up @@ -2035,7 +2035,7 @@ static bool showZone(DNSSECKeeper& dnsseckeeper, const DNSName& zone, bool expor
struct tm tm;
localtime_r(&di.last_check, &tm);
char buf[80];
if(di.last_check)
if(di.last_check != 0)
strftime(buf, sizeof(buf)-1, "%a %F %H:%M:%S", &tm);
else
strncpy(buf, "Never", sizeof(buf)-1);
Expand Down Expand Up @@ -2366,7 +2366,7 @@ static int testSchema(DNSSECKeeper& dk, const DNSName& zone)
cout<<"Expected one record, got multiple, aborting"<<endl;
return EXIT_FAILURE;
}
int size=rrget.content.size();
auto size=rrget.content.size();
if(size != 302)
{
cout<<"Expected 302 bytes, got "<<size<<", aborting"<<endl;
Expand Down Expand Up @@ -2434,9 +2434,8 @@ static int testSchema(DNSSECKeeper& dk, const DNSName& zone)
if(di.notified_serial != 2147484148) {
cout<<"[-] Set serial 2147484148, got back "<<di.notified_serial<<", aborting"<<endl;
return EXIT_FAILURE;
} else {
cout<<"[+] Big serials work correctly"<<endl;
}
cout<<"[+] Big serials work correctly"<<endl;
cout<<endl;
cout << "End of tests, please remove " << zone << " from zones+records" << endl;

Expand Down

0 comments on commit 3339cd6

Please sign in to comment.