summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2016-11-16 16:23:56 -0800
committerGrant Limberg <grant.limberg@zerotier.com>2016-11-16 16:23:56 -0800
commitb4bacd50a1ae70d53d16aef6880aa1fc6870bd8c (patch)
tree21fd07022eff4a5debd4cc37da02f22660348237 /osdep
parent6445337a32f5470e84bb9b139c25697e22d492f6 (diff)
parent3c248ec61a732f539dcf0c9ea3d92ae8f42b62fe (diff)
downloadinfinitytier-b4bacd50a1ae70d53d16aef6880aa1fc6870bd8c.tar.gz
infinitytier-b4bacd50a1ae70d53d16aef6880aa1fc6870bd8c.zip
Merge branch 'dev' into systemtray
Diffstat (limited to 'osdep')
-rw-r--r--osdep/BlockingQueue.hpp64
-rw-r--r--osdep/LinuxDropPrivileges.cpp4
2 files changed, 66 insertions, 2 deletions
diff --git a/osdep/BlockingQueue.hpp b/osdep/BlockingQueue.hpp
new file mode 100644
index 00000000..6172f4da
--- /dev/null
+++ b/osdep/BlockingQueue.hpp
@@ -0,0 +1,64 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ZT_BLOCKINGQUEUE_HPP
+#define ZT_BLOCKINGQUEUE_HPP
+
+#include <queue>
+#include <mutex>
+#include <condition_variable>
+
+namespace ZeroTier {
+
+/**
+ * Simple C++11 thread-safe queue
+ *
+ * Do not use in node/ since we have not gone C++11 there yet.
+ */
+template <class T>
+class BlockingQueue
+{
+public:
+ BlockingQueue(void) {}
+
+ inline void post(T t)
+ {
+ std::lock_guard<std::mutex> lock(m);
+ q.push(t);
+ c.notify_one();
+ }
+
+ inline T get(void)
+ {
+ std::unique_lock<std::mutex> lock(m);
+ while(q.empty())
+ c.wait(lock);
+ T val = q.front();
+ q.pop();
+ return val;
+ }
+
+private:
+ std::queue<T> q;
+ mutable std::mutex m;
+ std::condition_variable c;
+};
+
+} // namespace ZeroTier
+
+#endif
diff --git a/osdep/LinuxDropPrivileges.cpp b/osdep/LinuxDropPrivileges.cpp
index dab85bd8..e2688e65 100644
--- a/osdep/LinuxDropPrivileges.cpp
+++ b/osdep/LinuxDropPrivileges.cpp
@@ -102,6 +102,8 @@ void dropPrivileges(std::string homeDir) {
return;
}
+ createOwnedHomedir(homeDir, targetUser);
+
if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_RAW, 0, 0) < 0) {
// Kernel has no support for ambient capabilities.
notDropping(homeDir);
@@ -113,8 +115,6 @@ void dropPrivileges(std::string homeDir) {
return;
}
- createOwnedHomedir(homeDir, targetUser);
-
if (setCapabilities((1 << CAP_NET_ADMIN) | (1 << CAP_NET_RAW) | (1 << CAP_SETUID) | (1 << CAP_SETGID)) < 0) {
fprintf(stderr, "ERROR: failed to set capabilities (not running as real root?)\n");
exit(1);