]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Switch to `pdns::UniqueFilePtr`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 18 Mar 2024 09:22:12 +0000 (10:22 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 18 Mar 2024 09:26:58 +0000 (10:26 +0100)
12 files changed:
modules/pipebackend/coprocess.cc
modules/pipebackend/coprocess.hh
modules/remotebackend/pipeconnector.cc
modules/remotebackend/remotebackend.hh
pdns/dnspcap.cc
pdns/dnspcap.hh
pdns/dnspcap2protobuf.cc
pdns/dnssecinfra.cc
pdns/dnssecinfra.hh
pdns/dnstcpbench.cc
pdns/ixfrutils.cc
pdns/pdnsutil.cc

index 632e50c663a41f7324a400a704d8d82c4d38d67a..88be0220949d2ebc8c899596d1b1c051426317c4 100644 (file)
@@ -233,7 +233,7 @@ UnixRemote::UnixRemote(const string& path)
   if (connect(d_fd, (struct sockaddr*)&remote, sizeof(remote)) < 0)
     unixDie("Unable to connect to remote '" + path + "' using UNIX domain socket");
 
-  d_fp = std::unique_ptr<FILE, int (*)(FILE*)>(fdopen(d_fd, "r"), fclose);
+  d_fp = pdns::UniqueFilePtr(fdopen(d_fd, "r"));
 }
 
 void UnixRemote::send(const string& line)
index c9185132abf4ba4e25c6a112887829a693d6dead..244d91750f8e85f4a92574949fed139ebe087e16 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <string>
 
+#include "pdns/misc.hh"
 #include "pdns/namespaces.hh"
 
 class CoRemote
@@ -67,6 +68,6 @@ public:
 
 private:
   int d_fd;
-  std::unique_ptr<FILE, int (*)(FILE*)> d_fp{nullptr, fclose};
+  pdns::UniqueFilePtr d_fp{nullptr};
 };
 bool isUnixSocket(const string& fname);
index cc90a441978fc7bc9e93adf9bc72707515bd06a1..21055c073423e7620274903f61e2129fb9209fa5 100644 (file)
@@ -96,7 +96,7 @@ void PipeConnector::launch()
     setCloseOnExec(d_fd1[1]);
     close(d_fd2[1]);
     setCloseOnExec(d_fd2[0]);
-    if (!(d_fp = std::unique_ptr<FILE, int (*)(FILE*)>(fdopen(d_fd2[0], "r"), fclose))) {
+    if (!(d_fp = pdns::UniqueFilePtr(fdopen(d_fd2[0], "r")))) {
       throw PDNSException("Unable to associate a file pointer with pipe: " + stringerror());
     }
     if (d_timeout != 0) {
index a435465173944cbd901be27a0971567e22f3443a..69c80b102011bb3447064f0eec9e59c9707a320f 100644 (file)
@@ -158,7 +158,7 @@ private:
   int d_fd1[2]{}, d_fd2[2]{};
   int d_pid;
   int d_timeout;
-  std::unique_ptr<FILE, int (*)(FILE*)> d_fp{nullptr, fclose};
+  pdns::UniqueFilePtr d_fp{nullptr};
 };
 
 class RemoteBackend : public DNSBackend
index c72c3d7538a75c6d0a46cf02980e837030825323..d0d07450211d1c7b383bbd5f7363956ee7537048 100644 (file)
@@ -30,7 +30,7 @@
 #include "namespaces.hh"
 PcapPacketReader::PcapPacketReader(const string& fname) : d_fname(fname)
 {
-  d_fp = std::unique_ptr<FILE, int(*)(FILE*)>(fopen(fname.c_str(), "r"), fclose);
+  d_fp = pdns::UniqueFilePtr(fopen(fname.c_str(), "r"));
   if (!d_fp) {
     unixDie("Unable to open file " + fname);
   }
@@ -235,7 +235,7 @@ PcapPacketWriter::PcapPacketWriter(const string& fname, const PcapPacketReader&
 
 PcapPacketWriter::PcapPacketWriter(const string& fname) : d_fname(fname)
 {
-  d_fp = std::unique_ptr<FILE, int(*)(FILE*)>(fopen(fname.c_str(),"w"), fclose);
+  d_fp = pdns::UniqueFilePtr(fopen(fname.c_str(),"w"));
 
   if (!d_fp) {
     unixDie("Unable to open file");
index bdeb17676c93591dcb181a7aac6e202bfcf53329..aba0d8205460fa7bc7bdd7a10d315d7c3e84d0ad 100644 (file)
@@ -87,7 +87,7 @@ public:
     }
   };
 
-  PcapPacketReader(const string& fname); 
+  PcapPacketReader(const string& fname);
 
   template<typename T>
   void checkedFread(T* ptr)
@@ -118,17 +118,17 @@ public:
   char *d_buffer;
   size_t d_bufsize;
 private:
-  std::unique_ptr<FILE, int(*)(FILE*)> d_fp{nullptr, fclose};
+  pdns::UniqueFilePtr d_fp{nullptr};
   string d_fname;
   unsigned int d_skipMediaHeader;
 };
 
 class PcapPacketWriter
 {
-public: 
+public:
   PcapPacketWriter(const string& fname, const PcapPacketReader& ppr);
   PcapPacketWriter(const string& fname);
-  
+
   void write();
   void setPPR(const PcapPacketReader& ppr) { d_ppr = &ppr; }
 
@@ -136,6 +136,6 @@ private:
   string d_fname;
   const PcapPacketReader* d_ppr{nullptr};
 
-  std::unique_ptr<FILE, int(*)(FILE*)> d_fp{nullptr, fclose};
+  pdns::UniqueFilePtr d_fp{nullptr};
   bool d_first{true};
-}; 
+};
index e5ff300d3d0f3374cca1c1f90eb53101be7cb250..0defeb9183244dd2f82c5d43fc9ccee9b68a2478 100644 (file)
@@ -63,7 +63,7 @@ try {
 
   PcapPacketReader pr(argv[1]);
 
-  auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(fopen(argv[2], "w"), fclose);
+  auto fp = pdns::UniqueFilePtr(fopen(argv[2], "w"));
   if (!fp) {
     cerr<<"Error opening output file "<<argv[2]<<": "<<stringerror()<<endl;
     exit(EXIT_FAILURE);
index 9024b04502637ef0dbe9af619a332b836ffa1b7f..84e872e44c662d47741223f327430bd1c1ccafe4 100644 (file)
@@ -53,7 +53,7 @@ using namespace boost::assign;
 std::unique_ptr<DNSCryptoKeyEngine> DNSCryptoKeyEngine::makeFromISCFile(DNSKEYRecordContent& drc, const char* fname)
 {
   string sline, isc;
-  auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(fopen(fname, "r"), fclose);
+  auto fp = pdns::UniqueFilePtr(fopen(fname, "r"));
   if(!fp) {
     throw runtime_error("Unable to read file '"+string(fname)+"' for generating DNS Private Key");
   }
index 617a9c7df03fc97be6e785d6299a8ce71cf18ed1..9614ee1373d0e0cf3f1de8d48bd39bfb8ea1cdd5 100644 (file)
@@ -66,7 +66,7 @@ class DNSCryptoKeyEngine
     void createFromPEMString(DNSKEYRecordContent& drc, const std::string& contents)
     {
       // NOLINTNEXTLINE(*-cast): POSIX APIs.
-      unique_ptr<std::FILE, decltype(&std::fclose)> inputFile{fmemopen(const_cast<char*>(contents.data()), contents.length(), "r"), &std::fclose};
+      pdns::UniqueFilePtr inputFile{fmemopen(const_cast<char*>(contents.data()), contents.length(), "r")};
       createFromPEMFile(drc, *inputFile);
     }
 
@@ -89,7 +89,7 @@ class DNSCryptoKeyEngine
 
       std::string output{};
       output.resize(buflen);
-      unique_ptr<std::FILE, decltype(&std::fclose)> outputFile{fmemopen(output.data(), output.length() - 1, "w"), &std::fclose};
+      pdns::UniqueFilePtr outputFile{fmemopen(output.data(), output.length() - 1, "w")};
       convertToPEMFile(*outputFile);
       std::fflush(outputFile.get());
       output.resize(std::ftell(outputFile.get()));
index 32df39a8530bd73845e334c8f5f6dc40a395f74d..ccd6e2346fbf9982d224914a13f50f1ad42ef3fb 100644 (file)
@@ -262,12 +262,12 @@ try
   std::vector<std::thread> workers;
   workers.reserve(numworkers);
 
-  std::unique_ptr<FILE, int(*)(FILE*)> fp{nullptr, fclose};
+  pdns::UniqueFilePtr fp{nullptr};
   if (!g_vm.count("file")) {
-    fp = std::unique_ptr<FILE, int(*)(FILE*)>(fdopen(0, "r"), fclose);
+    fp = pdns::UniqueFilePtr(fdopen(0, "r"));
   }
   else {
-    fp = std::unique_ptr<FILE, int(*)(FILE*)>(fopen(g_vm["file"].as<string>().c_str(), "r"), fclose);
+    fp = pdns::UniqueFilePtr(fopen(g_vm["file"].as<string>().c_str(), "r"));
     if (!fp) {
       unixDie("Unable to open "+g_vm["file"].as<string>()+" for input");
     }
index 5aa5912ed2d88d4a7dba87c985c7362d9167c8e4..40b6b2495d7465caf4b4f863160a20b729d30d0e 100644 (file)
@@ -134,7 +134,7 @@ void writeZoneToDisk(const records_t& records, const DNSName& zone, const std::s
   /* ensure that the partial zone file will only be accessible by the current user, not even
      by other users in the same group, and certainly not by other users. */
   umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
-  auto filePtr = std::unique_ptr<FILE, int(*)(FILE*)>(fopen((fname+".partial").c_str(), "w"), fclose);
+  auto filePtr = pdns::UniqueFilePtr(fopen((fname+".partial").c_str(), "w"));
   if (!filePtr) {
     throw runtime_error("Unable to open file '"+fname+".partial' for writing: "+stringerror());
   }
index 15d241682e78651bd8c9d70beafcb3526551981e..d0c35332fec8a46588cc1586aa4f182e8e4f4d1e 100644 (file)
@@ -3527,7 +3527,7 @@ try
     const auto algorithm = pdns::checked_stoi<unsigned int>(cmds.at(3));
 
     errno = 0;
-    std::unique_ptr<std::FILE, decltype(&std::fclose)> fp{std::fopen(filename.c_str(), "r"), &std::fclose};
+    pdns::UniqueFilePtr fp{std::fopen(filename.c_str(), "r")};
     if (fp == nullptr) {
       auto errMsg = pdns::getMessageFromErrno(errno);
       throw runtime_error("Failed to open PEM file `" + filename + "`: " + errMsg);