diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 7497aa2b9d4b..48eb6390a0de 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -160,6 +160,7 @@ class DOHAcceptContext std::map d_ocspResponses; std::unique_ptr d_ticketKeys{nullptr}; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) pdns::UniqueFilePtr d_keyLogFile{nullptr}; ClientState* d_cs{nullptr}; time_t d_ticketsKeyRotationDelay{0}; diff --git a/pdns/dnspcap2protobuf.cc b/pdns/dnspcap2protobuf.cc index 0defeb918324..063fbee87095 100644 --- a/pdns/dnspcap2protobuf.cc +++ b/pdns/dnspcap2protobuf.cc @@ -63,8 +63,8 @@ try { PcapPacketReader pr(argv[1]); - auto fp = pdns::UniqueFilePtr(fopen(argv[2], "w")); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(fopen(argv[2], "w")); + if (!filePtr) { cerr<<"Error opening output file "< DNSCryptoKeyEngine::makeFromISCFile(DNSKEYRecordContent& drc, const char* fname) { string sline, isc; - auto fp = pdns::UniqueFilePtr(fopen(fname, "r")); - if(!fp) { + auto filePtr = pdns::UniqueFilePtr(fopen(fname, "r")); + if(!filePtr) { throw runtime_error("Unable to read file '"+string(fname)+"' for generating DNS Private Key"); } - while(stringfgets(fp.get(), sline)) { + while(stringfgets(filePtr.get(), sline)) { isc += sline; } - fp.reset(); + filePtr.reset(); auto dke = makeFromISCString(drc, isc); auto checkKeyErrors = std::vector{}; diff --git a/pdns/dnstcpbench.cc b/pdns/dnstcpbench.cc index ccd6e2346fbf..996dbbd9c579 100644 --- a/pdns/dnstcpbench.cc +++ b/pdns/dnstcpbench.cc @@ -262,24 +262,24 @@ try std::vector workers; workers.reserve(numworkers); - pdns::UniqueFilePtr fp{nullptr}; + pdns::UniqueFilePtr filePtr{nullptr}; if (!g_vm.count("file")) { - fp = pdns::UniqueFilePtr(fdopen(0, "r")); + filePtr = pdns::UniqueFilePtr(fdopen(0, "r")); } else { - fp = pdns::UniqueFilePtr(fopen(g_vm["file"].as().c_str(), "r")); - if (!fp) { + filePtr = pdns::UniqueFilePtr(fopen(g_vm["file"].as().c_str(), "r")); + if (!filePtr) { unixDie("Unable to open "+g_vm["file"].as()+" for input"); } } pair q; string line; - while(stringfgets(fp.get(), line)) { + while(stringfgets(filePtr.get(), line)) { boost::trim_right(line); q=splitField(line, ' '); g_queries.push_back(BenchQuery(q.first, DNSRecordContent::TypeToNumber(q.second))); } - fp.reset(); + filePtr.reset(); for (unsigned int n = 0; n < numworkers; ++n) { workers.push_back(std::thread(worker)); diff --git a/pdns/libssl.cc b/pdns/libssl.cc index b2d848bdbec8..051061468ea7 100644 --- a/pdns/libssl.cc +++ b/pdns/libssl.cc @@ -471,23 +471,23 @@ bool libssl_generate_ocsp_response(const std::string& certFile, const std::strin { const EVP_MD* rmd = EVP_sha256(); - auto fp = pdns::UniqueFilePtr(fopen(certFile.c_str(), "r")); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(fopen(certFile.c_str(), "r")); + if (!filePtr) { throw std::runtime_error("Unable to open '" + certFile + "' when loading the certificate to generate an OCSP response"); } - auto cert = std::unique_ptr(PEM_read_X509_AUX(fp.get(), nullptr, nullptr, nullptr), X509_free); + auto cert = std::unique_ptr(PEM_read_X509_AUX(filePtr.get(), nullptr, nullptr, nullptr), X509_free); - fp = pdns::UniqueFilePtr(fopen(caCert.c_str(), "r")); - if (!fp) { + filePtr = pdns::UniqueFilePtr(fopen(caCert.c_str(), "r")); + if (!filePtr) { throw std::runtime_error("Unable to open '" + caCert + "' when loading the issuer certificate to generate an OCSP response"); } - auto issuer = std::unique_ptr(PEM_read_X509_AUX(fp.get(), nullptr, nullptr, nullptr), X509_free); - fp = pdns::UniqueFilePtr(fopen(caKey.c_str(), "r")); - if (!fp) { + auto issuer = std::unique_ptr(PEM_read_X509_AUX(filePtr.get(), nullptr, nullptr, nullptr), X509_free); + filePtr = pdns::UniqueFilePtr(fopen(caKey.c_str(), "r")); + if (!filePtr) { throw std::runtime_error("Unable to open '" + caKey + "' when loading the issuer key to generate an OCSP response"); } - auto issuerKey = std::unique_ptr(PEM_read_PrivateKey(fp.get(), nullptr, nullptr, nullptr), EVP_PKEY_free); - fp.reset(); + auto issuerKey = std::unique_ptr(PEM_read_PrivateKey(filePtr.get(), nullptr, nullptr, nullptr), EVP_PKEY_free); + filePtr.reset(); auto bs = std::unique_ptr(OCSP_BASICRESP_new(), OCSP_BASICRESP_free); auto thisupd = std::unique_ptr(X509_gmtime_adj(nullptr, 0), ASN1_TIME_free); @@ -939,11 +939,11 @@ std::pair, std::vector(d2i_PKCS12_fp(fp.get(), nullptr), PKCS12_free); + auto p12 = std::unique_ptr(d2i_PKCS12_fp(filePtr.get(), nullptr), PKCS12_free); if (!p12) { throw std::runtime_error("Unable to open PKCS12 file " + pair.d_cert); } @@ -1040,13 +1040,13 @@ static void libssl_key_log_file_callback(const SSL* ssl, const char* line) return; } - auto fp = reinterpret_cast(SSL_CTX_get_ex_data(sslCtx, s_keyLogIndex)); - if (fp == nullptr) { + auto filePtr = reinterpret_cast(SSL_CTX_get_ex_data(sslCtx, s_keyLogIndex)); + if (filePtr == nullptr) { return; } - fprintf(fp, "%s\n", line); - fflush(fp); + fprintf(filePtr, "%s\n", line); + fflush(filePtr); } #endif /* HAVE_SSL_CTX_SET_KEYLOG_CALLBACK */ @@ -1057,17 +1057,17 @@ pdns::UniqueFilePtr libssl_set_key_log_file(std::unique_ptrclear(); - auto fp = pdns::UniqueFilePtr(fopen(fname, "r")); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(fopen(fname, "r")); + if (!filePtr) { return false; } - return stringfgets(fp.get(), *line); + return stringfgets(filePtr.get(), *line); } Regex::Regex(const string &expr) diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index d0c35332fec8..0ec33c30786f 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -3527,14 +3527,14 @@ try const auto algorithm = pdns::checked_stoi(cmds.at(3)); errno = 0; - pdns::UniqueFilePtr fp{std::fopen(filename.c_str(), "r")}; - if (fp == nullptr) { + pdns::UniqueFilePtr filePtr{std::fopen(filename.c_str(), "r")}; + if (filePtr == nullptr) { auto errMsg = pdns::getMessageFromErrno(errno); throw runtime_error("Failed to open PEM file `" + filename + "`: " + errMsg); } DNSKEYRecordContent drc; - shared_ptr key{DNSCryptoKeyEngine::makeFromPEMFile(drc, algorithm, *fp, filename)}; + shared_ptr key{DNSCryptoKeyEngine::makeFromPEMFile(drc, algorithm, *filePtr, filename)}; if (!key) { cerr << "Could not convert key from PEM to internal format" << endl; return 1; diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index 76d39ee021aa..6909445bdb26 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -914,33 +914,33 @@ bool AggressiveNSECCache::getDenial(time_t now, const DNSName& name, const QType return true; } -size_t AggressiveNSECCache::dumpToFile(pdns::UniqueFilePtr& fp, const struct timeval& now) +size_t AggressiveNSECCache::dumpToFile(pdns::UniqueFilePtr& filePtr, const struct timeval& now) { size_t ret = 0; auto zones = d_zones.read_lock(); - zones->visit([&ret, now, &fp](const SuffixMatchTree>>& node) { + zones->visit([&ret, now, &filePtr](const SuffixMatchTree>>& node) { if (!node.d_value) { return; } auto zone = node.d_value->lock(); - fprintf(fp.get(), "; Zone %s\n", zone->d_zone.toString().c_str()); + fprintf(filePtr.get(), "; Zone %s\n", zone->d_zone.toString().c_str()); for (const auto& entry : zone->d_entries) { int64_t ttl = entry.d_ttd - now.tv_sec; try { - fprintf(fp.get(), "%s %" PRId64 " IN %s %s\n", entry.d_owner.toString().c_str(), ttl, zone->d_nsec3 ? "NSEC3" : "NSEC", entry.d_record->getZoneRepresentation().c_str()); + fprintf(filePtr.get(), "%s %" PRId64 " IN %s %s\n", entry.d_owner.toString().c_str(), ttl, zone->d_nsec3 ? "NSEC3" : "NSEC", entry.d_record->getZoneRepresentation().c_str()); for (const auto& signature : entry.d_signatures) { - fprintf(fp.get(), "- RRSIG %s\n", signature->getZoneRepresentation().c_str()); + fprintf(filePtr.get(), "- RRSIG %s\n", signature->getZoneRepresentation().c_str()); } ++ret; } catch (const std::exception& e) { - fprintf(fp.get(), "; Error dumping record from zone %s: %s\n", zone->d_zone.toString().c_str(), e.what()); + fprintf(filePtr.get(), "; Error dumping record from zone %s: %s\n", zone->d_zone.toString().c_str(), e.what()); } catch (...) { - fprintf(fp.get(), "; Error dumping record from zone %s\n", zone->d_zone.toString().c_str()); + fprintf(filePtr.get(), "; Error dumping record from zone %s\n", zone->d_zone.toString().c_str()); } } }); diff --git a/pdns/recursordist/aggressive_nsec.hh b/pdns/recursordist/aggressive_nsec.hh index 75665df1f79d..bd3069daaef4 100644 --- a/pdns/recursordist/aggressive_nsec.hh +++ b/pdns/recursordist/aggressive_nsec.hh @@ -95,7 +95,7 @@ public: static bool isSmallCoveringNSEC3(const DNSName& owner, const std::string& nextHash); void prune(time_t now); - size_t dumpToFile(pdns::UniqueFilePtr& fp, const struct timeval& now); + size_t dumpToFile(pdns::UniqueFilePtr& filePtr, const struct timeval& now); private: struct ZoneEntry diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index cdec13249b40..cb7f7e3cc2a5 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -276,9 +276,9 @@ void NegCache::prune(time_t now, size_t maxEntries) } /*! - * Writes the whole negative cache to fp + * Writes the whole negative cache to fd * - * \param fp A pointer to an open FILE object + * \param fd A pointer to an open FILE object */ size_t NegCache::doDump(int fd, size_t maxCacheEntries, time_t now) { @@ -286,12 +286,12 @@ size_t NegCache::doDump(int fd, size_t maxCacheEntries, time_t now) if (newfd == -1) { return 0; } - auto fp = pdns::UniqueFilePtr(fdopen(newfd, "w")); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); + if (!filePtr) { close(newfd); return 0; } - fprintf(fp.get(), "; negcache dump follows\n;\n"); + fprintf(filePtr.get(), "; negcache dump follows\n;\n"); size_t ret = 0; @@ -301,7 +301,7 @@ size_t NegCache::doDump(int fd, size_t maxCacheEntries, time_t now) for (auto& mc : d_maps) { auto m = mc.lock(); const auto shardSize = m->d_map.size(); - fprintf(fp.get(), "; negcache shard %zu; size %zu\n", shard, shardSize); + fprintf(filePtr.get(), "; negcache shard %zu; size %zu\n", shard, shardSize); min = std::min(min, shardSize); max = std::max(max, shardSize); shard++; @@ -309,21 +309,21 @@ size_t NegCache::doDump(int fd, size_t maxCacheEntries, time_t now) for (const NegCacheEntry& ne : sidx) { ret++; int64_t ttl = ne.d_ttd - now; - fprintf(fp.get(), "%s %" PRId64 " IN %s VIA %s ; (%s) origttl=%" PRIu32 " ss=%hu\n", ne.d_name.toString().c_str(), ttl, ne.d_qtype.toString().c_str(), ne.d_auth.toString().c_str(), vStateToString(ne.d_validationState).c_str(), ne.d_orig_ttl, ne.d_servedStale); + fprintf(filePtr.get(), "%s %" PRId64 " IN %s VIA %s ; (%s) origttl=%" PRIu32 " ss=%hu\n", ne.d_name.toString().c_str(), ttl, ne.d_qtype.toString().c_str(), ne.d_auth.toString().c_str(), vStateToString(ne.d_validationState).c_str(), ne.d_orig_ttl, ne.d_servedStale); for (const auto& rec : ne.authoritySOA.records) { - fprintf(fp.get(), "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.getContent()->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); + fprintf(filePtr.get(), "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.getContent()->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); } for (const auto& sig : ne.authoritySOA.signatures) { - fprintf(fp.get(), "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), ttl, sig.getContent()->getZoneRepresentation().c_str()); + fprintf(filePtr.get(), "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), ttl, sig.getContent()->getZoneRepresentation().c_str()); } for (const auto& rec : ne.DNSSECRecords.records) { - fprintf(fp.get(), "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.getContent()->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); + fprintf(filePtr.get(), "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.getContent()->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str()); } for (const auto& sig : ne.DNSSECRecords.signatures) { - fprintf(fp.get(), "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), ttl, sig.getContent()->getZoneRepresentation().c_str()); + fprintf(filePtr.get(), "%s %" PRId64 " IN RRSIG %s ;\n", sig.d_name.toString().c_str(), ttl, sig.getContent()->getZoneRepresentation().c_str()); } } } - fprintf(fp.get(), "; negcache size: %zu/%zu shards: %zu min/max shard size: %zu/%zu\n", size(), maxCacheEntries, d_maps.size(), min, max); + fprintf(filePtr.get(), "; negcache size: %zu/%zu shards: %zu min/max shard size: %zu/%zu\n", size(), maxCacheEntries, d_maps.size(), min, max); return ret; } diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 2e407cd0a1e9..3ad2f9f5f649 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -326,15 +326,15 @@ static uint64_t dumpAggressiveNSECCache(int fd) if (newfd == -1) { return 0; } - auto fp = pdns::UniqueFilePtr(fdopen(newfd, "w")); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); + if (!filePtr) { return 0; } - fprintf(fp.get(), "; aggressive NSEC cache dump follows\n;\n"); + fprintf(filePtr.get(), "; aggressive NSEC cache dump follows\n;\n"); struct timeval now; Utility::gettimeofday(&now, nullptr); - return g_aggressiveNSECCache->dumpToFile(fp, now); + return g_aggressiveNSECCache->dumpToFile(filePtr, now); } static uint64_t* pleaseDumpEDNSMap(int fd) @@ -480,13 +480,13 @@ static RecursorControlChannel::Answer doDumpRPZ(int s, T begin, T end) return {1, "No RPZ zone named " + zoneName + "\n"}; } - auto fp = pdns::UniqueFilePtr(fdopen(fdw, "w")); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(fdopen(fdw, "w")); + if (!filePtr) { int err = errno; return {1, "converting file descriptor: " + stringerror(err) + "\n"}; } - zone->dump(fp.get()); + zone->dump(filePtr.get()); return {0, "done\n"}; } diff --git a/pdns/recursordist/test-negcache_cc.cc b/pdns/recursordist/test-negcache_cc.cc index 44834b631512..79e7c46bd13f 100644 --- a/pdns/recursordist/test-negcache_cc.cc +++ b/pdns/recursordist/test-negcache_cc.cc @@ -525,20 +525,20 @@ BOOST_AUTO_TEST_CASE(test_dumpToFile) cache.add(genNegCacheEntry(DNSName("www1.powerdns.com"), DNSName("powerdns.com"), now)); cache.add(genNegCacheEntry(DNSName("www2.powerdns.com"), DNSName("powerdns.com"), now)); - auto fp = pdns::UniqueFilePtr(tmpfile()); - if (!fp) { + auto filePtr = pdns::UniqueFilePtr(tmpfile()); + if (!filePtr) { BOOST_FAIL("Temporary file could not be opened"); } - cache.doDump(fileno(fp.get()), 0, now.tv_sec); + cache.doDump(fileno(filePtr.get()), 0, now.tv_sec); - rewind(fp.get()); + rewind(filePtr.get()); char* line = nullptr; size_t len = 0; ssize_t read; for (auto str : expected) { - read = getline(&line, &len, fp.get()); + read = getline(&line, &len, filePtr.get()); if (read == -1) BOOST_FAIL("Unable to read a line from the temp file"); // The clock might have ticked so the 600 becomes 599