]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move the code using libcap to separate files
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 16 Nov 2018 14:49:25 +0000 (15:49 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 5 Dec 2018 11:28:00 +0000 (12:28 +0100)
So we don't have to link every tool against libcap.

12 files changed:
pdns/capabilities.cc [new file with mode: 0644]
pdns/capabilities.hh [new file with mode: 0644]
pdns/dnsdist.hh
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/capabilities.cc [new symlink]
pdns/dnsdistdist/capabilities.hh [new symlink]
pdns/misc.cc
pdns/misc.hh
pdns/pdns_recursor.cc
pdns/recursordist/Makefile.am
pdns/recursordist/capabilities.cc [new symlink]
pdns/recursordist/capabilities.hh [new symlink]

diff --git a/pdns/capabilities.cc b/pdns/capabilities.cc
new file mode 100644 (file)
index 0000000..c269099
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <cstring>
+#include <stdexcept>
+
+#ifdef HAVE_LIBCAP
+#include <sys/capability.h>
+#endif
+
+#include "capabilities.hh"
+
+void dropCapabilities()
+{
+#ifdef HAVE_LIBCAP
+   cap_t caps = cap_get_proc();
+   if (caps != nullptr) {
+     cap_clear(caps);
+
+     if (cap_set_proc(caps) != 0) {
+       cap_free(caps);
+       throw std::runtime_error("Unable to drop capabilities: " + std::string(strerror(errno)));
+     }
+
+     cap_free(caps);
+   }
+#endif /* HAVE_LIBCAP */
+}
diff --git a/pdns/capabilities.hh b/pdns/capabilities.hh
new file mode 100644 (file)
index 0000000..e9499f5
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+
+void dropCapabilities();
index c4ae2bac3ac5021cc9dec6859dbec435745096c9..e36bc323dbe818f95c03fdbf9aa33702cc2347a6 100644 (file)
@@ -35,6 +35,7 @@
 #include <boost/variant.hpp>
 
 #include "bpf-filter.hh"
+#include "capabilities.hh"
 #include "dnscrypt.hh"
 #include "dnsdist-cache.hh"
 #include "dnsdist-dynbpf.hh"
index 50354ece18e622d6a4d9b479d8c4df07c5563d28..9f422a86cdac138ee7dcf8018533a99c021bb05f 100644 (file)
@@ -87,6 +87,7 @@ dnsdist_SOURCES = \
        base64.hh \
        bpf-filter.cc bpf-filter.hh \
        cachecleaner.hh \
+       capabilities.cc capabilities.hh \
        dns.cc dns.hh \
        dnscrypt.cc dnscrypt.hh \
        dnsdist.cc dnsdist.hh \
diff --git a/pdns/dnsdistdist/capabilities.cc b/pdns/dnsdistdist/capabilities.cc
new file mode 120000 (symlink)
index 0000000..1b9c432
--- /dev/null
@@ -0,0 +1 @@
+../capabilities.cc
\ No newline at end of file
diff --git a/pdns/dnsdistdist/capabilities.hh b/pdns/dnsdistdist/capabilities.hh
new file mode 120000 (symlink)
index 0000000..ea9e875
--- /dev/null
@@ -0,0 +1 @@
+../capabilities.hh
\ No newline at end of file
index cd8842ed5d70d2e2f7bd68b58561907f63baee01..196a4bcf4822bd309f069cc0ccb5c49108647503 100644 (file)
 #  include <sched.h>
 #endif
 
-#ifdef HAVE_LIBCAP
-#include <sys/capability.h>
-#endif
-
 bool g_singleThreaded;
 
 size_t writen2(int fd, const void *buf, size_t count)
@@ -1453,20 +1449,3 @@ std::vector<ComboAddress> getResolvers(const std::string& resolvConfPath)
 
   return results;
 }
-
-void dropCapabilities()
-{
-#ifdef HAVE_LIBCAP
-   cap_t caps = cap_get_proc();
-   if (caps != nullptr) {
-     cap_clear(caps);
-
-     if (cap_set_proc(caps) != 0) {
-       cap_free(caps);
-       throw std::runtime_error("Unable to drop capabilities: " + std::string(strerror(errno)));
-     }
-
-     cap_free(caps);
-   }
-#endif /* HAVE_LIBCAP */
-}
index d4420dfa84682064346f33ddf54754629a231780..fcf3c6a51dabe77557ee3b6a8fce01febac1f6e2 100644 (file)
@@ -593,7 +593,6 @@ double DiffTime(const struct timespec& first, const struct timespec& second);
 double DiffTime(const struct timeval& first, const struct timeval& second);
 uid_t strToUID(const string &str);
 gid_t strToGID(const string &str);
-void dropCapabilities();
 
 unsigned int pdns_stou(const std::string& str, size_t * idx = 0, int base = 10);
 
index 83a0548d3c861711f52c41b746cdb1b3170af3aa..ec619fff41708f34aa9503311cf827d601376563 100644 (file)
@@ -67,6 +67,7 @@
 #include "malloctrace.hh"
 #endif
 #include <netinet/tcp.h>
+#include "capabilities.hh"
 #include "dnsparser.hh"
 #include "dnswriter.hh"
 #include "dnsrecords.hh"
index 04b1019ffaf068e6ecdc1c3cae3d8a85f2ce7a54..40056da2cb195c329fe9ed0d7e24a71dbc71786f 100644 (file)
@@ -93,6 +93,7 @@ pdns_recursor_SOURCES = \
        base32.cc base32.hh \
        base64.cc base64.hh \
        cachecleaner.hh \
+       capabilities.cc capabilities.hh \
        comment.hh \
        dns.hh dns.cc \
        dns_random.hh dns_random.cc \
@@ -372,9 +373,6 @@ rec_control_SOURCES = \
        rec_control.cc \
        unix_utility.cc
 
-rec_control_LDADD = \
-       $(LIBCAP_LIBS)
-
 dnslabeltext.cc: dnslabeltext.rl
        $(AM_V_GEN)$(RAGEL) $< -o dnslabeltext.cc
 
diff --git a/pdns/recursordist/capabilities.cc b/pdns/recursordist/capabilities.cc
new file mode 120000 (symlink)
index 0000000..1b9c432
--- /dev/null
@@ -0,0 +1 @@
+../capabilities.cc
\ No newline at end of file
diff --git a/pdns/recursordist/capabilities.hh b/pdns/recursordist/capabilities.hh
new file mode 120000 (symlink)
index 0000000..ea9e875
--- /dev/null
@@ -0,0 +1 @@
+../capabilities.hh
\ No newline at end of file