std::map<int, std::string> d_ocspResponses;
std::unique_ptr<OpenSSLTLSTicketKeysRing> 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};
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 "<<argv[2]<<": "<<stringerror()<<endl;
exit(EXIT_FAILURE);
}
}
uint16_t mlen = htons(pbBuffer.length());
- fwrite(&mlen, 1, sizeof(mlen), fp.get());
- fwrite(pbBuffer.c_str(), 1, pbBuffer.length(), fp.get());
+ fwrite(&mlen, 1, sizeof(mlen), filePtr.get());
+ fwrite(pbBuffer.c_str(), 1, pbBuffer.length(), filePtr.get());
}
}
catch (const std::exception& e) {
std::unique_ptr<DNSCryptoKeyEngine> 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<std::string>{};
std::vector<std::thread> 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<string>().c_str(), "r"));
- if (!fp) {
+ filePtr = pdns::UniqueFilePtr(fopen(g_vm["file"].as<string>().c_str(), "r"));
+ if (!filePtr) {
unixDie("Unable to open "+g_vm["file"].as<string>()+" for input");
}
}
pair<string, string> 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));
{
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<X509, void(*)(X509*)>(PEM_read_X509_AUX(fp.get(), nullptr, nullptr, nullptr), X509_free);
+ auto cert = std::unique_ptr<X509, void(*)(X509*)>(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<X509, void(*)(X509*)>(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<X509, void(*)(X509*)>(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<EVP_PKEY, void(*)(EVP_PKEY*)>(PEM_read_PrivateKey(fp.get(), nullptr, nullptr, nullptr), EVP_PKEY_free);
- fp.reset();
+ auto issuerKey = std::unique_ptr<EVP_PKEY, void(*)(EVP_PKEY*)>(PEM_read_PrivateKey(filePtr.get(), nullptr, nullptr, nullptr), EVP_PKEY_free);
+ filePtr.reset();
auto bs = std::unique_ptr<OCSP_BASICRESP, void(*)(OCSP_BASICRESP*)>(OCSP_BASICRESP_new(), OCSP_BASICRESP_free);
auto thisupd = std::unique_ptr<ASN1_TIME, void(*)(ASN1_TIME*)>(X509_gmtime_adj(nullptr, 0), ASN1_TIME_free);
if (!pair.d_key) {
#if defined(HAVE_SSL_CTX_USE_CERT_AND_KEY)
// If no separate key is given, treat it as a pkcs12 file
- auto fp = pdns::UniqueFilePtr(fopen(pair.d_cert.c_str(), "r"));
- if (!fp) {
+ auto filePtr = pdns::UniqueFilePtr(fopen(pair.d_cert.c_str(), "r"));
+ if (!filePtr) {
throw std::runtime_error("Unable to open file " + pair.d_cert);
}
- auto p12 = std::unique_ptr<PKCS12, void(*)(PKCS12*)>(d2i_PKCS12_fp(fp.get(), nullptr), PKCS12_free);
+ auto p12 = std::unique_ptr<PKCS12, void(*)(PKCS12*)>(d2i_PKCS12_fp(filePtr.get(), nullptr), PKCS12_free);
if (!p12) {
throw std::runtime_error("Unable to open PKCS12 file " + pair.d_cert);
}
return;
}
- auto fp = reinterpret_cast<FILE*>(SSL_CTX_get_ex_data(sslCtx, s_keyLogIndex));
- if (fp == nullptr) {
+ auto filePtr = reinterpret_cast<FILE*>(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 */
if (fd == -1) {
unixDie("Error opening TLS log file '" + logFile + "'");
}
- auto fp = pdns::UniqueFilePtr(fdopen(fd, "a"));
- if (!fp) {
+ auto filePtr = pdns::UniqueFilePtr(fdopen(fd, "a"));
+ if (!filePtr) {
int error = errno; // close might clobber errno
close(fd);
throw std::runtime_error("Error opening TLS log file '" + logFile + "': " + stringerror(error));
}
- SSL_CTX_set_ex_data(ctx.get(), s_keyLogIndex, fp.get());
+ SSL_CTX_set_ex_data(ctx.get(), s_keyLogIndex, filePtr.get());
SSL_CTX_set_keylog_callback(ctx.get(), &libssl_key_log_file_callback);
- return fp;
+ return filePtr;
#else
return pdns::UniqueFilePtr(nullptr);
#endif /* HAVE_SSL_CTX_SET_KEYLOG_CALLBACK */
bool readFileIfThere(const char* fname, std::string* line)
{
line->clear();
- 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)
const auto algorithm = pdns::checked_stoi<unsigned int>(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<DNSCryptoKeyEngine> key{DNSCryptoKeyEngine::makeFromPEMFile(drc, algorithm, *fp, filename)};
+ shared_ptr<DNSCryptoKeyEngine> key{DNSCryptoKeyEngine::makeFromPEMFile(drc, algorithm, *filePtr, filename)};
if (!key) {
cerr << "Could not convert key from PEM to internal format" << endl;
return 1;
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<std::shared_ptr<LockGuarded<ZoneEntry>>>& node) {
+ zones->visit([&ret, now, &filePtr](const SuffixMatchTree<std::shared_ptr<LockGuarded<ZoneEntry>>>& 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());
}
}
});
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
}
/*!
- * 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)
{
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;
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++;
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;
}
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)
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"};
}
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