From: Miod Vallat Date: Fri, 17 Jan 2025 14:35:30 +0000 (+0100) Subject: Address some clang-tidy complaints in pdnsutil. X-Git-Tag: dnsdist-2.0.0-alpha1~151^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de3917488bf48de7f17c5c0c59fbd6d406bf118f;p=thirdparty%2Fpdns.git Address some clang-tidy complaints in pdnsutil. --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 0d6beec0fb..67e23192c7 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -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 modules; @@ -152,8 +152,9 @@ 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)) { cerr<<"Warning: unable to read configuration file '"<* suppliedrecords=nullptr) // NOLINTNEXTLINE(readability-function-cognitive-complexity) +static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, const vector* suppliedrecords=nullptr) // NOLINT(readability-function-cognitive-complexity,readability-identifier-length) { - uint64_t numerrors=0, numwarnings=0; + int numerrors=0; + int numwarnings=0; DomainInfo di; try { @@ -298,7 +300,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); @@ -414,7 +416,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con ostringstream o; o<(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: '"<second<<" != "<doesDNSSEC()); for( const auto &qname : checkOcclusion ) { @@ -812,7 +816,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; } @@ -845,7 +849,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con if (seen.count(value) == 0) { seen.insert(value); } - else if (messaged.count(value) <= 0) { + else if (messaged.count(value) == 0) { cout << "[Error] Found duplicate metadata key value pair for zone " << zone << " with key '" << metaData.first << "' and value '" << value << "'" << endl; numerrors++; messaged.insert(value); @@ -855,9 +859,7 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const DNSName& zone, con } cout<<"Checked "<getBits() < 1) { cout<<"invalid "<getBits()<getBits()<= 16) ? 1 : 16 - algname.length(); @@ -1026,7 +1028,9 @@ 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; + string slot; + string label; for (auto const &elem : stormap) { //cout<list(zone, di.id); DNSResourceRecord rr; cout<<"$ORIGIN ."<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, '.'); @@ -1144,7 +1148,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) // NOLINT(concurrency-mt-unsafe) { } [[nodiscard]] string red() const @@ -1191,6 +1195,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); @@ -1211,8 +1219,9 @@ 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) { continue; + } DNSRecord dr(rr); pre.push_back(std::move(dr)); } @@ -1233,7 +1242,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(); @@ -1270,7 +1279,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(); @@ -1363,8 +1372,9 @@ static int editZone(const DNSName &zone, const PDNSColors& col) { cerr<<'\n'; if(c=='q') return(EXIT_SUCCESS); - else if(c=='e') + if(c=='e') { goto editMore; + } else if(c=='r') goto editAgain; else if(changed.empty() || c!='a') @@ -1425,9 +1435,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; @@ -1470,8 +1479,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); @@ -1874,7 +1882,7 @@ static void verifyCrypto(const string& zone) string msg = getMessageForRRSET(qname, rrc, toSign); cerr<<"Verify: "<verify(msg, rrc.d_signature)<