From: Miod Vallat Date: Wed, 15 Jan 2025 09:24:17 +0000 (+0100) Subject: Throw a few bones to clang-tidy. X-Git-Tag: dnsdist-2.0.0-alpha1~167^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ed5097f4618ef6dcacc8baa5cf483208cd5ea6a;p=thirdparty%2Fpdns.git Throw a few bones to clang-tidy. --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index a447d03b35..386464cb46 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -2483,8 +2483,9 @@ static int testAlgorithm(vector& cmds) cerr << "Syntax: pdnsutil test-algorithm algonum"<(cmds.at(1)))) + if (testAlgorithm(pdns::checked_stoi(cmds.at(1)))) { return 0; + } return 1; } @@ -2514,8 +2515,9 @@ static int ipEncrypt(vector& cmds) static int testAlgorithms([[maybe_unused]] vector& cmds) { - if (testAlgorithms()) + if (testAlgorithms()) { return 0; + } return 1; } @@ -2532,8 +2534,9 @@ static int listAlgorithms(vector& cmds) for (const auto& algoWithBackend : algosWithBackend){ string algoName = DNSSECKeeper::algorithm2name(algoWithBackend.first); cout<& cmds) return 0; } try { - SSQLite3 db(cmds.at(1), "", true); // create=ok + SSQLite3 db(cmds.at(1), "", true); // create=ok //NOLINT(readability-identifier-length) vector statements; - stringtok(statements, sqlCreate, ";"); + stringtok(statements, static_cast(sqlCreate), ";"); for(const string& statement : statements) { db.execute(statement); } @@ -2613,8 +2616,9 @@ static int zonemdVerifyFile(vector& cmds) cerr<<"Syntax: pdnsutil zonemd-verify-file ZONE FILENAME"<& cmds) cerr << "Syntax: pdnsutil test-schema ZONE"<& cmds) cerr << "Syntax: pdnsutil rectify-zone ZONE [ZONE..]"<& cmds) { bool quiet = (cmds.size() >= 2 && cmds.at(1) == "quiet"); - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) if (!rectifyAllZones(dk, quiet)) { return 1; } @@ -2661,8 +2667,8 @@ static int checkZone(vector& cmds) cerr << "Syntax: pdnsutil check-zone ZONE"<& cmds) static int checkAllZones(vector& cmds) { bool exitOnError = ((cmds.size() >= 2 ? cmds.at(1) : "") == "exit-on-error"); - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) return checkAllZones(dk, exitOnError); } @@ -2685,8 +2691,9 @@ static int listAllZones(vector& cmds) cerr << "Syntax: pdnsutil list-all-zones [primary|secondary|native|producer|consumer]" << endl; return 0; } - if (cmds.size() == 2) + if (cmds.size() == 2) { return listAllZones(cmds.at(1)); + } return listAllZones(); } @@ -2737,9 +2744,10 @@ static int showZone(vector& cmds) cerr << "Syntax: pdnsutil show-zone ZONE"<& cmds) cerr << "Syntax: pdnsutil export-zone-ds ZONE"<& cmds) cerr << "Syntax: pdnsutil disable-dnssec ZONE"<& cmds) return 0; } DNSName zone(cmds.at(1)); + // NOLINTNEXTLINE(readability-identifier-length) unsigned int id = atoi(cmds.at(2).c_str()); // if you make this pdns::checked_stoi, the error gets worse - if(!id) + if(id == 0) { cerr << "Invalid KEY-ID '" << cmds.at(2) << "'" << endl; return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) try { dk.getKeyById(zone, id); } catch (std::exception& e) { @@ -2804,13 +2814,13 @@ static int deactivateZoneKey(vector& cmds) return 0; } DNSName zone(cmds.at(1)); - auto id = pdns::checked_stoi(cmds.at(2)); - if(!id) + auto id = pdns::checked_stoi(cmds.at(2)); // NOLINT(readability-identifier-length) + if(id == 0) { cerr<<"Invalid KEY-ID"<& cmds) return 0; } DNSName zone(cmds.at(1)); + // NOLINTNEXTLINE(readability-identifier-length) unsigned int id = atoi(cmds.at(2).c_str()); // if you make this pdns::checked_stoi, the error gets worse - if(!id) + if(id == 0) { cerr << "Invalid KEY-ID '" << cmds.at(2) << "'" << endl; return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) try { dk.getKeyById(zone, id); } catch (std::exception& e) { @@ -2858,13 +2869,14 @@ static int unpublishZoneKey(vector& cmds) return 0; } DNSName zone(cmds.at(1)); + // NOLINTNEXTLINE(readability-identifier-length) unsigned int id = atoi(cmds.at(2).c_str()); // if you make this pdns::checked_stoi, the error gets worse - if(!id) + if(id == 0) { cerr << "Invalid KEY-ID '" << cmds.at(2) << "'" << endl; return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) try { dk.getKeyById(zone, id); } catch (std::exception& e) { @@ -2973,9 +2985,9 @@ static int removeZoneKey(vector& cmds) cerr<<"Syntax: pdnsutil remove-zone-key ZONE KEY-ID"<(cmds.at(2)); + auto id = pdns::checked_stoi(cmds.at(2)); // NOLINT(readability-identifier-length) if (!dk.removeKey(zone, id)) { cerr<<"Cannot remove key " << id << " from " << zone <& cmds) cerr << "Syntax: pdnsutil create-secondary-zone ZONE primary-ip [primary-ip..]" << endl; return 0; } - UeberBackend B; - DomainInfo di; + UeberBackend B; // NOLINT(readability-identifier-length) + DomainInfo di; // NOLINT(readability-identifier-length) DNSName zone(cmds.at(1)); if (B.getDomainInfo(zone, di)) { cerr << "Zone '" << zone << "' exists already" << endl; @@ -3033,8 +3045,8 @@ static int changeSecondaryZonePrimary(vector& cmds) cerr << "Syntax: pdnsutil change-secondary-zone-primary ZONE primary-ip [primary-ip..]" << endl; return 0; } - UeberBackend B; - DomainInfo di; + UeberBackend B; // NOLINT(readability-identifier-length) + DomainInfo di; // NOLINT(readability-identifier-length) DNSName zone(cmds.at(1)); if (!B.getDomainInfo(zone, di)) { cerr << "Zone '" << zone << "' doesn't exist" << endl; @@ -3111,8 +3123,9 @@ static int listZone(vector& cmds) cerr<<"Syntax: pdnsutil list-zone ZONE"<& cmds) cerr<<"Syntax: pdnsutil edit-zone ZONE"<& cmds) cerr<<"Syntax: pdnsutil clear-zone ZONE"<& cmds) cerr<<"Syntax: pdnsutil list-keys [ZONE]"<& cmds) cerr<<"Syntax: pdnsutil load-zone ZONE FILENAME [ZONE FILENAME] .."<& cmds) cerr << "Syntax: pdnsutil secure-zone ZONE"< mustRectify; unsigned int zoneErrors=0; - for(unsigned int n = 1; n < cmds.size(); ++n) { + for(unsigned int n = 1; n < cmds.size(); ++n) { // NOLINT(readability-identifier-length) DNSName zone(cmds.at(n)); dk.startTransaction(zone, -1); if(secureZone(dk, zone)) { @@ -3192,10 +3210,11 @@ static int secureZone(vector& cmds) dk.commitTransaction(); } - for(const auto& zone : mustRectify) + for(const auto& zone : mustRectify) { rectifyZone(dk, zone); + } - if (zoneErrors) { + if (zoneErrors != 0) { return 1; } return 0; @@ -3208,23 +3227,26 @@ static int secureAllZones(vector& cmds) return 0; } - DNSSECKeeper dk; - UeberBackend B("default"); + DNSSECKeeper dk; //NOLINT(readability-identifier-length) + UeberBackend B("default"); // NOLINT(readability-identifier-length) vector domainInfo; B.getAllDomains(&domainInfo, false, false); - unsigned int zonesSecured=0, zoneErrors=0; - for(const DomainInfo& di : domainInfo) { + unsigned int zonesSecured=0; + unsigned int zoneErrors=0; + for(const DomainInfo& di : domainInfo) { // NOLINT(readability-identifier-length) if(!dk.isSecuredZone(di.zone)) { cout<<"Securing "<& cmds) cout<<"Secured: "<& cmds) DNSName zone(cmds.at(1)); set values; - for (unsigned int n = 4; n < cmds.size(); ++n) { + for (unsigned int n = 4; n < cmds.size(); ++n) { // NOLINT(readability-identifier-length) if (!cmds.at(n).empty()) { values.insert(cmds.at(n)); } @@ -3328,7 +3350,7 @@ static int setNsec3(vector& cmds) bool narrow = cmds.size() > 3 && cmds.at(3) == "narrow"; NSEC3PARAMRecordContent ns3pr(nsec3params); - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) DNSName zone(cmds.at(1)); if (zone.wirelength() > 222) { cerr<<"Cannot enable NSEC3 for " << zone << " as it is too long (" << zone.wirelength() << " bytes, maximum is 222 bytes)"<& cmds) return 1; } - if (!ns3pr.d_flags) + if (ns3pr.d_flags == 0) { cerr<<"NSEC3 set, "; - else + } + else { cerr<<"NSEC3 (opt-out) set, "; + } - if(dk.isSecuredZone(zone)) + if(dk.isSecuredZone(zone)) { cerr<<"Done, please rectify your zone if your backend needs it (or reload it if you are using the bindbackend)"<& cmds) cerr<<"Syntax: pdnsutil set-presigned ZONE"<& cmds) cerr<<"Syntax: pdnsutil set-publish-cdnskey ZONE [delete]"<& cmds) } // If DIGESTALGOS is unset - if(cmds.size() == 2) - cmds.push_back("2"); + if(cmds.size() == 2) { + cmds.emplace_back("2"); + } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) if (!dk.setPublishCDS(DNSName(cmds.at(1)), cmds.at(2))) { cerr << "Could not set publishing for CDS records for " << cmds.at(1) << endl; return 1; @@ -3409,7 +3436,7 @@ static int unsetPresigned(vector& cmds) cerr<<"Syntax: pdnsutil unset-presigned ZONE"<& cmds) cerr<<"Syntax: pdnsutil unset-publish-cdnskey ZONE"<& cmds) cerr<<"Syntax: pdnsutil unset-publish-cds ZONE"<& cmds) cerr<<"Syntax: pdnsutil hash-zone-record ZONE RNAME"<& cmds) cerr<<"Syntax: pdnsutil unset-nsec3 ZONE"<& cmds) return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) string zone = cmds.at(1); - auto id = pdns::checked_stoi(cmds.at(2)); + auto id = pdns::checked_stoi(cmds.at(2)); // NOLINT(readability-identifier-length) DNSSECPrivateKey dpk = dk.getKeyById(DNSName(zone), id); cout << dpk.getKey()->convertToISC() << endl; return 0; @@ -3506,9 +3533,9 @@ static int exportZoneKeyPEM(vector& cmds) return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) string zone = cmds.at(1); - auto id = pdns::checked_stoi(cmds.at(2)); + auto id = pdns::checked_stoi(cmds.at(2)); // NOLINT(readability-identifier-length) DNSSECPrivateKey dpk = dk.getKeyById(DNSName(zone), id); dpk.getKey()->convertToPEMFile(*stdout); return 0; @@ -3520,7 +3547,7 @@ static int increaseSerial(vector& cmds) cerr << "Syntax: pdnsutil increase-serial ZONE" << endl; return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) return increaseSerial(DNSName(cmds.at(1)), dk); } @@ -3577,8 +3604,8 @@ static int importZoneKeyPEM(vector& cmds) } dpk.setKey(key, flags, algo); - DNSSECKeeper dk; - int64_t id{-1}; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) + int64_t id{-1}; // NOLINT(readability-identifier-length) if (!dk.addKey(DNSName(zone), dpk, id)) { cerr << "Adding key failed, perhaps DNSSEC not enabled in configuration?" << endl; return 1; @@ -3611,19 +3638,25 @@ static int importZoneKey(vector& cmds) bool active=true; bool published=true; - for(unsigned int n = 3; n < cmds.size(); ++n) { - if (pdns_iequals(cmds.at(n), "ZSK")) + for(unsigned int n = 3; n < cmds.size(); ++n) { // NOLINT(readability-identifier-length) + if (pdns_iequals(cmds.at(n), "ZSK")) { flags = 256; - else if (pdns_iequals(cmds.at(n), "KSK")) + } + else if (pdns_iequals(cmds.at(n), "KSK")) { flags = 257; - else if (pdns_iequals(cmds.at(n), "active")) + } + else if (pdns_iequals(cmds.at(n), "active")) { active = true; - else if (pdns_iequals(cmds.at(n), "passive") || pdns_iequals(cmds.at(n), "inactive")) // passive eventually needs to be removed + } + else if (pdns_iequals(cmds.at(n), "passive") || pdns_iequals(cmds.at(n), "inactive")) { // passive eventually needs to be removed active = false; - else if (pdns_iequals(cmds.at(n), "published")) + } + else if (pdns_iequals(cmds.at(n), "published")) { published = true; - else if (pdns_iequals(cmds.at(n), "unpublished")) + } + else if (pdns_iequals(cmds.at(n), "unpublished")) { published = false; + } else { cerr << "Unknown key flag '" << cmds.at(n) << "'" << endl; return 1; @@ -3637,8 +3670,8 @@ static int importZoneKey(vector& cmds) } dpk.setKey(key, flags, algo); - DNSSECKeeper dk; - int64_t id{-1}; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) + int64_t id{-1}; // NOLINT(readability-identifier-length) if (!dk.addKey(DNSName(zone), dpk, id, active, published)) { cerr<<"Adding key failed, perhaps DNSSEC not enabled in configuration?"<& cmds) return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) DNSName zone(cmds.at(1)); - auto id = pdns::checked_stoi(cmds.at(2)); + auto id = pdns::checked_stoi(cmds.at(2)); // NOLINT(readability-identifier-length) DNSSECPrivateKey dpk=dk.getKeyById(zone, id); cout << zone<<" IN DNSKEY "<& cmds) int tmp_algo=0; int bits=0; int algorithm=DNSSECKeeper::ECDSA256; - for(unsigned int n=1; n < cmds.size(); ++n) { - if (pdns_iequals(cmds.at(n), "zsk")) + for(unsigned int n=1; n < cmds.size(); ++n) { // NOLINT(readability-identifier-length) + if (pdns_iequals(cmds.at(n), "zsk")) { keyOrZone = false; - else if (pdns_iequals(cmds.at(n), "ksk")) + } + else if (pdns_iequals(cmds.at(n), "ksk")) { keyOrZone = true; + } else if ((tmp_algo = DNSSECKeeper::shorthand2algorithm(cmds.at(n))) > 0) { algorithm = tmp_algo; } - else if (pdns::checked_stoi(cmds.at(n)) != 0) + else if (pdns::checked_stoi(cmds.at(n)) != 0) { pdns::checked_stoi_into(bits, cmds.at(n)); + } else { cerr << "Unknown algorithm, key flag or size '" << cmds.at(n) << "'" << endl; return 0; } } cerr<<"Generating a " << (keyOrZone ? "KSK" : "ZSK")<<" with algorithm = "< dpk(DNSCryptoKeyEngine::make(algorithm)); - if(!bits) { - if(algorithm <= 10) + if(bits == 0) { + if(algorithm <= 10) { bits = keyOrZone ? 2048 : 1024; + } else { - if(algorithm == DNSSECKeeper::ECCGOST || algorithm == DNSSECKeeper::ECDSA256 || algorithm == DNSSECKeeper::ED25519) + if(algorithm == DNSSECKeeper::ECCGOST || algorithm == DNSSECKeeper::ECDSA256 || algorithm == DNSSECKeeper::ED25519) { bits = 256; - else if(algorithm == DNSSECKeeper::ECDSA384) + } + else if(algorithm == DNSSECKeeper::ECDSA384) { bits = 384; - else if(algorithm == DNSSECKeeper::ED448) + } + else if(algorithm == DNSSECKeeper::ED448) { bits = 456; + } else { throw runtime_error("Can not guess key size for algorithm "+std::to_string(algorithm)); } @@ -3748,7 +3789,7 @@ static int generateTSIGKey(vector& cmds) return 1; } - UeberBackend B("default"); + UeberBackend B("default"); // NOLINT(readability-identifier-length) if (B.setTSIGKey(name, DNSName(algo), key)) { // you are feeling bored, put up DNSName(algo) up earlier cout << "Create new TSIG key " << name << " " << algo << " " << key << endl; } else { @@ -3768,7 +3809,7 @@ static int importTSIGKey(vector& cmds) string algo = cmds.at(2); string key = cmds.at(3); - UeberBackend B("default"); + UeberBackend B("default"); // NOLINT(readability-identifier-length) if (B.setTSIGKey(name, DNSName(algo), key)) { cout << "Imported TSIG key " << name << " " << algo << endl; } @@ -3787,7 +3828,7 @@ static int deleteTSIGKey(vector& cmds) } DNSName name(cmds.at(1)); - UeberBackend B("default"); + UeberBackend B("default"); // NOLINT(readability-identifier-length) if (B.deleteTSIGKey(name)) { cout << "Deleted TSIG key " << name << endl; } @@ -3801,7 +3842,7 @@ static int deleteTSIGKey(vector& cmds) static int listTSIGKeys([[maybe_unused]] vector& cmds) { std::vector keys; - UeberBackend B("default"); + UeberBackend B("default"); // NOLINT(readability-identifier-length) if (B.getTSIGKeys(keys)) { for (const TSIGKey& key : keys) { cout << key.name.toString() << " " << key.algorithm.toString() << " " << key.key << endl; @@ -3819,16 +3860,18 @@ static int activateTSIGKey(vector& cmds) } DNSName zname(cmds.at(1)); string name = cmds.at(2); - if (cmds.at(3) == "primary" || cmds.at(3) == "producer") + if (cmds.at(3) == "primary" || cmds.at(3) == "producer") { metaKey = "TSIG-ALLOW-AXFR"; - else if (cmds.at(3) == "secondary" || cmds.at(3) == "consumer") + } + else if (cmds.at(3) == "secondary" || cmds.at(3) == "consumer") { metaKey = "AXFR-MASTER-TSIG"; + } else { cerr << "Invalid parameter '" << cmds.at(3) << "', expected primary or secondary type" << endl; return 1; } - UeberBackend B("default"); - DomainInfo di; + UeberBackend B("default"); // NOLINT(readability-identifier-length) + DomainInfo di; // NOLINT(readability-identifier-length) if (!B.getDomainInfo(zname, di)) { cerr << "Zone '" << zname << "' does not exist" << endl; return 1; @@ -3845,8 +3888,9 @@ static int activateTSIGKey(vector& cmds) break; } } - if (!found) + if (!found) { meta.push_back(name); + } if (B.setDomainMetadata(zname, metaKey, meta)) { cout << "Enabled TSIG key " << name << " for " << zname << endl; } @@ -3866,17 +3910,19 @@ static int deactivateTSIGKey(vector& cmds) } DNSName zname(cmds.at(1)); string name = cmds.at(2); - if (cmds.at(3) == "primary" || cmds.at(3) == "producer") + if (cmds.at(3) == "primary" || cmds.at(3) == "producer") { metaKey = "TSIG-ALLOW-AXFR"; - else if (cmds.at(3) == "secondary" || cmds.at(3) == "consumer") + } + else if (cmds.at(3) == "secondary" || cmds.at(3) == "consumer") { metaKey = "AXFR-MASTER-TSIG"; + } else { cerr << "Invalid parameter '" << cmds.at(3) << "', expected primary or secondary type" << endl; return 1; } - UeberBackend B("default"); - DomainInfo di; + UeberBackend B("default"); // NOLINT(readability-identifier-length) + DomainInfo di; // NOLINT(readability-identifier-length) if (!B.getDomainInfo(zname, di)) { cerr << "Zone '" << zname << "' does not exist" << endl; return 1; @@ -3886,12 +3932,15 @@ static int deactivateTSIGKey(vector& cmds) cerr << "Failure disabling TSIG key " << name << " for " << zname << endl; return 1; } - std::vector::iterator iter = meta.begin(); - for (; iter != meta.end(); ++iter) - if (*iter == name) + auto iter = meta.begin(); + for (; iter != meta.end(); ++iter) { + if (*iter == name) { break; - if (iter != meta.end()) + } + } + if (iter != meta.end()) { meta.erase(iter); + } if (B.setDomainMetadata(zname, metaKey, meta)) { cout << "Disabled TSIG key " << name << " for " << zname << endl; } @@ -3904,7 +3953,7 @@ static int deactivateTSIGKey(vector& cmds) static int getMeta(vector& cmds) { - UeberBackend B("default"); + UeberBackend B("default"); // NOLINT(readability-identifier-length) if (cmds.size() < 2) { cerr << "Syntax: " << cmds.at(0) << " zone [kind kind ..]" << endl; return 1; @@ -3912,7 +3961,7 @@ static int getMeta(vector& cmds) DNSName zone(cmds.at(1)); vector keys; - DomainInfo di; + DomainInfo di; // NOLINT(readability-identifier-length) if (!B.getDomainInfo(zone, di)) { cerr << "Invalid zone '" << zone << "'" << endl; return 1; @@ -3966,7 +4015,7 @@ static int setMeta(vector& cmds) static int HSMAssign(vector& cmds) { DNSCryptoKeyEngine::storvector_t storvect; - DomainInfo di; + DomainInfo di; // NOLINT(readability-identifier-length) std::vector keys; if (cmds.size() < 9) { @@ -3974,7 +4023,7 @@ static int HSMAssign(vector& cmds) return 1; } - UeberBackend B("default"); + UeberBackend B("default"); // NOLINT(readability-identifier-length) DNSName zone(cmds.at(2)); // verify zone @@ -3989,16 +4038,18 @@ static int HSMAssign(vector& cmds) return 1; } - bool keyOrZone = (cmds.at(4) == "ksk" ? true : false); + bool keyOrZone = cmds.at(4) == "ksk"; string module = cmds.at(5); string slot = cmds.at(6); string pin = cmds.at(7); string label = cmds.at(8); string pub_label; - if (cmds.size() > 9) + if (cmds.size() > 9) { pub_label = cmds.at(9); - else + } + else { pub_label = label; + } std::ostringstream iscString; iscString << "Private-key-format: v1.2" << std::endl << @@ -4022,8 +4073,8 @@ static int HSMAssign(vector& cmds) // make sure this key isn't being reused. B.getDomainKeys(zone, keys); - int64_t id{-1}; - for(DNSBackend::KeyData& kd : keys) { + int64_t id{-1}; // NOLINT(readability-identifier-length) + for(DNSBackend::KeyData& kd : keys) { // NOLINT(readability-identifier-length) if (kd.content == iscString.str()) { // it's this one, I guess... id = kd.id; @@ -4036,7 +4087,7 @@ static int HSMAssign(vector& cmds) return 1; } - DNSSECKeeper dk; + DNSSECKeeper dk; //NOLINT(readability-identifier-length) if (!dk.addKey(zone, dpk, id)) { cerr << "Unable to assign module slot to zone" << std::endl; return 1; @@ -4053,10 +4104,10 @@ static int HSMCreateKey(vector& cmds) cerr << "Usage: pdnsutil hsm create-key ZONE KEY-ID [BITS]" << endl; return 1; } - UeberBackend B("default"); - DomainInfo di; + UeberBackend B("default"); // NOLINT(readability-identifier-length) + DomainInfo di; // NOLINT(readability-identifier-length) DNSName zone(cmds.at(2)); - unsigned int id; + unsigned int id{0}; // NOLINT(readability-identifier-length) int bits = 2048; // verify zone if (!B.getDomainInfo(zone, di)) { @@ -4073,7 +4124,7 @@ static int HSMCreateKey(vector& cmds) std::unique_ptr dke = nullptr; // lookup correct key - for(DNSBackend::KeyData &kd : keys) { + for(DNSBackend::KeyData &kd : keys) { // NOLINT(readability-identifier-length) if (kd.id == id) { // found our key. DNSKEYRecordContent dkrc; @@ -4111,12 +4162,13 @@ static int HSM([[maybe_unused]] vector& cmds) cerr << "Missing sub-command for pdnsutil hsm"<< std::endl; return 0; } - else if (cmds.at(1) == "assign") { + if (cmds.at(1) == "assign") { return HSMAssign(cmds); } - else if (cmds.at(1) == "create-key") { + if (cmds.at(1) == "create-key") { return HSMCreateKey(cmds); } + cerr<<"Unknown hsm sub-command '"<& cmds) vector domains; tgt->getAllDomains(&domains, false, true); - if (!domains.empty()) + if (!domains.empty()) { throw PDNSException("Target backend has zone(s), please clean it first"); + } src->getAllDomains(&domains, false, true); // iterate zones - for(const DomainInfo& di: domains) { - size_t nr,nc,nm,nk; + for(const DomainInfo& di: domains) { // NOLINT(readability-identifier-length) + size_t nr{0}; // NOLINT(readability-identifier-length) + size_t nc{0}; // NOLINT(readability-identifier-length) + size_t nm{0}; // NOLINT(readability-identifier-length) + size_t nk{0}; // NOLINT(readability-identifier-length) DomainInfo di_new; - DNSResourceRecord rr; + DNSResourceRecord rr; // NOLINT(readability-identifier-length) cout<<"Processing '"<createDomain(di.zone, di.kind, di.primaries, di.account)) + if (!tgt->createDomain(di.zone, di.kind, di.primaries, di.account)) { throw PDNSException("Failed to create zone"); - if (!tgt->getDomainInfo(di.zone, di_new)) throw PDNSException("Failed to create zone"); + } + if (!tgt->getDomainInfo(di.zone, di_new)) { + throw PDNSException("Failed to create zone"); + } // move records - if (!src->list(di.zone, di.id, true)) throw PDNSException("Failed to list records"); + // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) + if (!src->list(di.zone, di.id, true)) { + throw PDNSException("Failed to list records"); + } nr=0; + // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) tgt->startTransaction(di.zone, di_new.id); while(src->get(rr)) { + // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) rr.domain_id = di_new.id; - if (!tgt->feedRecord(rr, DNSName())) throw PDNSException("Failed to feed record"); + if (!tgt->feedRecord(rr, DNSName())) { + throw PDNSException("Failed to feed record"); + } nr++; } // move comments nc=0; if (src->listComments(di.id)) { - Comment c; + Comment c; // NOLINT(readability-identifier-length) while(src->getComment(c)) { + // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions) c.domain_id = di_new.id; if (!tgt->feedComment(c)) { throw PDNSException("Target backend does not support comments - remove them first"); @@ -4204,19 +4271,20 @@ static int B2BMigrate(vector& cmds) nm=0; std::map > meta; if (src->getAllDomainMetadata(di.zone, meta)) { - for (const auto& i : meta) { - if (!tgt->setDomainMetadata(di.zone, i.first, i.second)) + for (const auto& i : meta) { // NOLINT(readability-identifier-length) + if (!tgt->setDomainMetadata(di.zone, i.first, i.second)) { throw PDNSException("Failed to feed zone metadata"); + } nm++; } } // move keys nk=0; // temp var for KeyID - int64_t keyID; + int64_t keyID{-1}; std::vector keys; if (src->getDomainKeys(di.zone, keys)) { - for(const DNSBackend::KeyData& k: keys) { + for(const DNSBackend::KeyData& k: keys) { // NOLINT(readability-identifier-length) tgt->addDomainKey(di.zone, k, keyID); nk++; } @@ -4229,8 +4297,10 @@ static int B2BMigrate(vector& cmds) // move tsig keys std::vector tkeys; if (src->getTSIGKeys(tkeys)) { - for(auto& tk: tkeys) { - if (!tgt->setTSIGKey(tk.name, tk.algorithm, tk.key)) throw PDNSException("Failed to feed TSIG key"); + for(auto& tk: tkeys) { // NOLINT(readability-identifier-length) + if (!tgt->setTSIGKey(tk.name, tk.algorithm, tk.key)) { + throw PDNSException("Failed to feed TSIG key"); + } ntk++; } } @@ -4428,24 +4498,25 @@ try ("no-colors", "do not use colors in output") ("commands", po::value >()); - po::positional_options_description p; + po::positional_options_description p; // NOLINT(readability-identifier-length) p.add("commands", -1); po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), g_vm); po::notify(g_vm); vector cmds; - if(g_vm.count("commands")) + if(g_vm.count("commands") != 0) { cmds = g_vm["commands"].as >(); + } - g_verbose = g_vm.count("verbose"); + g_verbose = g_vm.count("verbose") != 0; - if (g_vm.count("version")) { + if (g_vm.count("version") != 0) { cout<<"pdnsutil "< [params ..]\n" << endl; cout << "Commands:" << endl; @@ -4569,9 +4640,9 @@ try loadMainConfig(g_vm["config-dir"].as()); - auto it = commands.find(cmds.at(0)); - if (it != commands.end()) { - auto [initRequired, handler] = it->second; + auto iter = commands.find(cmds.at(0)); + if (iter != commands.end()) { + auto [initRequired, handler] = iter->second; if (initRequired) { reportAllTypes(); }