Cleanup unnecessary osquery code 00/240300/1
authorSangwan Kwon <sangwan.kwon@samsung.com>
Wed, 5 Aug 2020 06:39:27 +0000 (15:39 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Wed, 5 Aug 2020 06:39:27 +0000 (15:39 +0900)
Change-Id: I58e8249f934e3347c6696f08aa3d8a7f5d33fe54
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
34 files changed:
CMakeLists.txt
src/osquery/CMakeLists.txt
src/osquery/core/CMakeLists.txt
src/osquery/core/sql/scheduled_query.cpp [deleted file]
src/osquery/core/sql/scheduled_query.h [deleted file]
src/osquery/include/osquery/core.h
src/osquery/include/osquery/query.h
src/osquery/utils/CMakeLists.txt
src/osquery/utils/attribute.h [deleted file]
src/osquery/utils/base64.cpp [deleted file]
src/osquery/utils/base64.h [deleted file]
src/osquery/utils/chars.cpp [deleted file]
src/osquery/utils/chars.h [deleted file]
src/osquery/utils/conversions/join.h [deleted file]
src/osquery/utils/conversions/tests/join.cpp [deleted file]
src/osquery/utils/error/error.h
src/osquery/utils/macros/macros.h [deleted file]
src/osquery/utils/mutex.h
src/osquery/utils/status/status.h
src/osquery/utils/status/tests/status.cpp
src/osquery/utils/system/env.h [deleted file]
src/osquery/utils/system/errno.h [deleted file]
src/osquery/utils/system/filepath.h [deleted file]
src/osquery/utils/system/posix/env.cpp [deleted file]
src/osquery/utils/system/posix/errno.cpp [deleted file]
src/osquery/utils/system/posix/errno.h [deleted file]
src/osquery/utils/system/posix/filepath.cpp [deleted file]
src/osquery/utils/system/posix/tests/errno.cpp [deleted file]
src/osquery/utils/system/posix/time.cpp [deleted file]
src/osquery/utils/system/tests/cpu.cpp [deleted file]
src/osquery/utils/system/tests/errno.cpp [deleted file]
src/osquery/utils/system/tests/time.cpp [deleted file]
src/osquery/utils/system/time.cpp [deleted file]
src/osquery/utils/system/time.h [deleted file]

index 0fd59d2ad814bda2d7e9fc077cbea4e9b3a8f380..a188cc18393958a77d63dcb584b65972d8ea9fc3 100644 (file)
@@ -28,11 +28,6 @@ IF(NOT CMAKE_BUILD_TYPE)
        SET(CMAKE_BUILD_TYPE "DEBUG")
 ENDIF(NOT CMAKE_BUILD_TYPE)
 
-message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
-message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
-message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
-message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
-
 SET(CMAKE_CXX_FLAGS_DEBUG   "-g -std=c++1z -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
 SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++1z -O2 -DNDEBUG")
 
index 216fd9231dbeb4eee16b6a24280f83242d12d6e7..64aa02e43e1c2334cf27c224517bbc19d633e98e 100644 (file)
@@ -23,7 +23,6 @@ ADD_OSQUERY_LINK(glog
                                 dl
                                 boost_regex
                                 boost_system
-                                boost_thread
                                 boost_filesystem
                                 sqlite3)
 
index 94163380a88f7689033e03920a6e9bd2da68bb85..7707d15745481788b237179ae476b29ed12311d6 100644 (file)
@@ -17,8 +17,7 @@ ADD_OSQUERY_LIBRARY(osquery_core tables.cpp
                                                                 plugins/plugin.cpp
                                                                 plugins/sql.cpp
                                                                 sql/column.cpp
-                                                                sql/diff_results.cpp
-                                                                sql/scheduled_query.cpp)
+                                                                sql/diff_results.cpp)
 
 FILE(GLOB OSQUERY_CORE_TESTS "tests/*.cpp")
 ADD_OSQUERY_TEST(${OSQUERY_SQL_TESTS})
diff --git a/src/osquery/core/sql/scheduled_query.cpp b/src/osquery/core/sql/scheduled_query.cpp
deleted file mode 100644 (file)
index c2847a3..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include "scheduled_query.h"
diff --git a/src/osquery/core/sql/scheduled_query.h b/src/osquery/core/sql/scheduled_query.h
deleted file mode 100644 (file)
index 8dd928a..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-#include <map>
-
-#include <osquery/utils/only_movable.h>
-
-namespace osquery {
-
-/**
- * @brief Represents the relevant parameters of a scheduled query.
- *
- * Within the context of osqueryd, a scheduled query may have many relevant
- * attributes. Those attributes are represented in this data structure.
- */
-struct ScheduledQuery : private only_movable {
-       /// Name of the pack containing query
-       std::string pack_name;
-
-       /// Name of the query
-       std::string name;
-
-       /// The SQL query.
-       std::string query;
-
-       /// Owner of the query
-       std::string oncall;
-
-       /// How often the query should be executed, in second.
-       size_t interval{0};
-
-       /// A temporary splayed internal.
-       size_t splayed_interval{0};
-
-       /**
-        * @brief Queries are blacklisted based on logic in the configuration.
-        *
-        * Most calls to inspect scheduled queries will abstract away the blacklisting
-        * concept and only return non-blacklisted queries. The config may be asked
-        * to return all queries, thus it is important to capture this optional data.
-        */
-       bool blacklisted{false};
-
-       /// Set of query options.
-       std::map<std::string, bool> options;
-
-       ScheduledQuery(const std::string& pack_name,
-                                  const std::string& name,
-                                  const std::string& query)
-               : pack_name(pack_name), name(name), query(query) {}
-       ScheduledQuery() = default;
-       ScheduledQuery(ScheduledQuery&&) = default;
-       ScheduledQuery& operator=(ScheduledQuery&&) = default;
-
-       /// equals operator
-       bool operator==(const ScheduledQuery& comp) const
-       {
-               return (comp.query == query) && (comp.interval == interval);
-       }
-
-       /// not equals operator
-       bool operator!=(const ScheduledQuery& comp) const
-       {
-               return !(*this == comp);
-       }
-};
-
-} // namespace osquery
index 95f074e509cf7a75cd7d276cbc3bd0856e80cb57..8cc3c4f4e60691cdf4fce8e6adb8271c347aa618 100644 (file)
@@ -10,8 +10,6 @@
 
 #include <string>
 
-#include <osquery/utils/macros/macros.h>
-
 /// A configuration error is catastrophic and should exit the watcher.
 #define EXIT_CATASTROPHIC 78
 
index 4dfa95ceb98c473a6e8b6b90302fbb5c5c1951cd..5b412709db965fc87e2a22039263f7e000037a63 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <osquery/core.h>
 #include <osquery/core/sql/diff_results.h>
-#include <osquery/core/sql/scheduled_query.h>
 
 namespace osquery {
 
@@ -78,18 +77,6 @@ public:
  */
 class Query {
 public:
-       /**
-        * @brief Constructor which sets up necessary parameters of a Query object.
-        *
-        * Given a query, this constructor calculates the value of columnFamily_,
-        * which can be accessed via the getColumnFamilyName getter method.
-        *
-        * @param name The query name.
-        * @param q a SheduledQuery struct.
-        */
-       explicit Query(std::string name, const ScheduledQuery& q)
-               : query_(q.query), name_(std::move(name)) {}
-
        /**
         * @brief Serialize the data in RocksDB into a useful data structure
         *
index 29c2a694ab2f823005c47ad253bb4166e6411fa7..189b23f92589c5d678df93bc18d17ae605109053 100644 (file)
 #  See the License for the specific language governing permissions and
 #  limitations under the License
 
-ADD_OSQUERY_LIBRARY(osquery_utils base64.cpp
-                                                                 chars.cpp
-                                                                 only_movable.cpp
+ADD_OSQUERY_LIBRARY(osquery_utils only_movable.cpp
                                                                  status/status.cpp
-                                                                 system/time.cpp
-                                                                 system/posix/env.cpp
-                                                                 system/posix/errno.cpp
-                                                                 system/posix/filepath.cpp
-                                                                 system/posix/time.cpp
                                                                  conversions/tryto.cpp
                                                                  conversions/split.cpp)
 
diff --git a/src/osquery/utils/attribute.h b/src/osquery/utils/attribute.h
deleted file mode 100644 (file)
index dca1b59..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#if __cplusplus >= 201703L
-#define OSQUERY_NODISCARD [[nodiscard]]
-#else
-#if defined(POSIX)
-#define OSQUERY_NODISCARD __attribute__((warn_unused_result))
-#elif defined(WIDOWS) && defined(_MSC_VER) && _MSC_VER >= 1700
-#define OSQUERY_NODISCARD _Check_return_
-#else
-#define OSQUERY_NODISCARD
-#endif
-#endif
diff --git a/src/osquery/utils/base64.cpp b/src/osquery/utils/base64.cpp
deleted file mode 100644 (file)
index b5e3154..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include "base64.h"
-
-#include <boost/algorithm/string.hpp>
-#include <boost/archive/iterators/base64_from_binary.hpp>
-#include <boost/archive/iterators/binary_from_base64.hpp>
-#include <boost/archive/iterators/transform_width.hpp>
-
-#include <vist/logger.hpp>
-
-namespace bai = boost::archive::iterators;
-
-namespace osquery {
-
-namespace base64 {
-
-namespace {
-
-typedef bai::binary_from_base64<const char*> base64_str;
-typedef bai::transform_width<base64_str, 8, 6> base64_dec;
-typedef bai::transform_width<std::string::const_iterator, 6, 8> base64_enc;
-typedef bai::base64_from_binary<base64_enc> it_base64;
-
-} // namespace
-
-std::string decode(std::string encoded)
-{
-       boost::erase_all(encoded, "\r\n");
-       boost::erase_all(encoded, "\n");
-       boost::trim_right_if(encoded, boost::is_any_of("="));
-
-       if (encoded.empty()) {
-               return encoded;
-       }
-
-       try {
-               return std::string(base64_dec(encoded.data()),
-                                                  base64_dec(encoded.data() + encoded.size()));
-       } catch (const boost::archive::iterators::dataflow_exception& e) {
-               INFO(OSQUERY) << "Could not base64 decode string: " << e.what();
-               return "";
-       }
-}
-
-std::string encode(const std::string& unencoded)
-{
-       if (unencoded.empty()) {
-               return unencoded;
-       }
-
-       size_t writePaddChars = (3U - unencoded.length() % 3U) % 3U;
-       try {
-               auto encoded =
-                       std::string(it_base64(unencoded.begin()), it_base64(unencoded.end()));
-               encoded.append(std::string(writePaddChars, '='));
-               return encoded;
-       } catch (const boost::archive::iterators::dataflow_exception& e) {
-               INFO(OSQUERY) << "Could not base64 decode string: " << e.what();
-               return "";
-       }
-}
-
-} // namespace base64
-} // namespace osquery
diff --git a/src/osquery/utils/base64.h b/src/osquery/utils/base64.h
deleted file mode 100644 (file)
index aba99d3..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-
-namespace osquery {
-
-namespace base64 {
-
-/**
- * @brief Decode a base64 encoded string.
- *
- * @param encoded The encode base64 string.
- * @return Decoded string.
- */
-std::string decode(std::string encoded);
-
-/**
- * @brief Encode a  string.
- *
- * @param A string to encode.
- * @return Encoded string.
- */
-std::string encode(const std::string& unencoded);
-
-} // namespace base64
-
-} // namespace osquery
diff --git a/src/osquery/utils/chars.cpp b/src/osquery/utils/chars.cpp
deleted file mode 100644 (file)
index 85d2fda..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <string>
-#include <cstddef>
-
-#include <vist/logger.hpp>
-
-#include <osquery/utils/chars.h>
-#include <osquery/utils/conversions/tryto.h>
-
-namespace osquery {
-
-bool isPrintable(const std::string& check)
-{
-       for (const unsigned char ch : check) {
-               if (ch >= 0x7F || ch <= 0x1F) {
-                       return false;
-               }
-       }
-       return true;
-}
-
-size_t utf8StringSize(const std::string& str)
-{
-       size_t res = 0;
-       std::string::const_iterator it = str.begin();
-       for (; it != str.end(); incUtf8StringIterator(it, str.end())) {
-               res++;
-       }
-
-       return res;
-}
-
-std::string unescapeUnicode(const std::string& escaped)
-{
-       if (escaped.size() < 6) {
-               return escaped;
-       }
-
-       std::string unescaped;
-       unescaped.reserve(escaped.size());
-       for (size_t i = 0; i < escaped.size(); ++i) {
-               if (i < escaped.size() - 5 && '\\' == escaped[i] && 'u' == escaped[i + 1]) {
-                       // Assume 2-byte wide unicode.
-                       auto const exp = tryTo<long>(escaped.substr(i + 2, 4), 16);
-                       if (exp.isError()) {
-                               WARN(OSQUERY) << "Unescaping a string with length: " << escaped.size()
-                                                         << " failed at: " << i;
-                               return "";
-                       }
-                       long const value = exp.get();
-                       if (value < 255) {
-                               unescaped += static_cast<char>(value);
-                               i += 5;
-                               continue;
-                       }
-               } else if (i < escaped.size() - 1 && '\\' == escaped[i] &&
-                                  '\\' == escaped[i + 1]) {
-                       // In the case of \\users 'sers' is not a unicode character
-                       // If we see \\ we should skip them and we do this by adding
-                       // an extra jump forward.
-                       unescaped += escaped[i];
-                       ++i;
-               }
-               unescaped += escaped[i];
-       }
-       return unescaped;
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/chars.h b/src/osquery/utils/chars.h
deleted file mode 100644 (file)
index 0df4433..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-
-namespace osquery {
-
-/**
- * @brief Check if a string is ASCII printable
- *
- * @param A string to check.
- * @return If the string is printable.
- */
-bool isPrintable(const std::string& check);
-
-/**
- * @brief In-line helper function for use with utf8StringSize
- */
-template <typename _Iterator1, typename _Iterator2>
-size_t incUtf8StringIterator(_Iterator1& it, const _Iterator2& last)
-{
-       if (it == last) {
-               return 0;
-       }
-
-       size_t res = 1;
-       for (++it; last != it; ++it, ++res) {
-               unsigned char c = *it;
-               if (!(c & 0x80) || ((c & 0xC0) == 0xC0)) {
-                       break;
-               }
-       }
-
-       return res;
-}
-
-/**
- * @brief Get the length of a UTF-8 string
- *
- * @param str The UTF-8 string
- *
- * @return the length of the string
- */
-size_t utf8StringSize(const std::string& str);
-
-/// Safely convert unicode escaped ASCII.
-std::string unescapeUnicode(const std::string& escaped);
-
-} // namespace osquery
diff --git a/src/osquery/utils/conversions/join.h b/src/osquery/utils/conversions/join.h
deleted file mode 100644 (file)
index 7e73613..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-
-#include <boost/algorithm/string.hpp>
-
-namespace osquery {
-
-/**
- * @brief Join a vector of strings inserting a token string between elements
- *
- * @param s the vector of strings to be joined.
- * @param tok a token glue string to be inserted between elements.
- *
- * @return the joined string.
- */
-template <typename SequenceType>
-inline std::string join(const SequenceType& s, const std::string& tok)
-{
-       return boost::algorithm::join(s, tok);
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/conversions/tests/join.cpp b/src/osquery/utils/conversions/tests/join.cpp
deleted file mode 100644 (file)
index 0cb5f3d..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <string>
-
-#include <gtest/gtest.h>
-
-#include <osquery/utils/conversions/join.h>
-
-namespace osquery {
-
-class ConversionsTests : public testing::Test {};
-
-TEST_F(ConversionsTests, test_join)
-{
-       std::vector<std::string> content = {
-               "one", "two", "three",
-       };
-       EXPECT_EQ(join(content, ", "), "one, two, three");
-}
-
-}
index 5ef55334a69624bdc9a61dd5d6c1288220ee623d..27649c78a48e5df410522a8338229ada5c83839d 100644 (file)
@@ -8,7 +8,6 @@
 
 #pragma once
 
-#include <osquery/utils/attribute.h>
 #include <osquery/utils/conversions/to.h>
 
 #include <memory>
@@ -137,7 +136,7 @@ inline std::ostream& operator<<(std::ostream& out, const ErrorBase& error)
 }
 
 template <typename ErrorCodeEnumType, typename OtherErrorCodeEnumType>
-OSQUERY_NODISCARD Error<ErrorCodeEnumType> createError(
+[[nodiscard]] Error<ErrorCodeEnumType> createError(
        ErrorCodeEnumType error_code,
        Error<OtherErrorCodeEnumType> underlying_error)
 {
@@ -148,7 +147,7 @@ OSQUERY_NODISCARD Error<ErrorCodeEnumType> createError(
 }
 
 template <typename ErrorCodeEnumType>
-OSQUERY_NODISCARD Error<ErrorCodeEnumType> createError(
+[[nodiscard]] Error<ErrorCodeEnumType> createError(
        ErrorCodeEnumType error_code)
 {
        return Error<ErrorCodeEnumType>(error_code);
diff --git a/src/osquery/utils/macros/macros.h b/src/osquery/utils/macros/macros.h
deleted file mode 100644 (file)
index 375fa11..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-// clang-format off
-#ifndef STR
-#define STR_OF(x) #x
-#define STR(x) STR_OF(x)
-#endif
-
-#ifdef WIN32
-#define STR_EX(...) __VA_ARGS__
-#else
-#define STR_EX(x) x
-#endif
-#define CONCAT(x, y) STR(STR_EX(x)STR_EX(y))
-
-#ifdef WIN32
-#define USED_SYMBOL
-#define EXPORT_FUNCTION __declspec(dllexport)
-#else
-#define USED_SYMBOL __attribute__((used))
-#define EXPORT_FUNCTION
-#endif
-// clang-format on
index 6684f46379f6e78ab983b3353c95e02d4303c438..ea7e572f240a7ca8168d2981f9a22c1aa59c4256 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <mutex>
 #include <shared_mutex>
-#include <boost/thread/recursive_mutex.hpp>
 
 namespace osquery {
 
@@ -29,10 +28,4 @@ using RecursiveMutex = std::recursive_mutex;
 /// Helper alias for write locking a recursive mutex.
 using RecursiveLock = std::unique_lock<std::recursive_mutex>;
 
-/// Helper alias for upgrade locking a mutex.
-using UpgradeLock = boost::upgrade_lock<Mutex>;
-
-/// Helper alias for write locking an upgrade lock.
-using WriteUpgradeLock = boost::upgrade_to_unique_lock<Mutex>;
-
 } // namespace osquery
index d0bcb263de50e98216e12f24d96530b7eb8ca369..9dead616d960f573f614bff9358e2ecf10dabcaa 100644 (file)
@@ -9,7 +9,6 @@
 #pragma once
 
 #include <osquery/utils/error/error.h>
-#include <osquery/utils/expected/expected.h>
 #include <sstream>
 #include <string>
 
@@ -170,13 +169,4 @@ private:
 
 ::std::ostream& operator<<(::std::ostream& os, const Status& s);
 
-template <typename ToType, typename ValueType, typename ErrorCodeEnumType>
-inline
-typename std::enable_if<std::is_same<ToType, Status>::value, Status>::type
-to(const Expected<ValueType, ErrorCodeEnumType>& expected)
-{
-       return expected ? Status::success()
-                  : Status::failure(expected.getError().getMessage());
-}
-
 } // namespace osquery
index 5b4211e01a47cf62e96c96f0919a23fae62dc6c1..5782b740c4087aabbaacf7356b0d7663c866cc79 100644 (file)
@@ -84,34 +84,4 @@ TEST_F(StatusTests, test_failure_with_success_code)
 #endif
 }
 
-namespace {
-
-enum class TestError {
-       Semantic = 1,
-};
-
-bool stringContains(const std::string& where, const std::string& what)
-{
-       return boost::contains(where, what);
-};
-
-} // namespace
-
-TEST_F(StatusTests, test_expected_to_status_failure)
-{
-       const auto expected = Expected<std::string, TestError>(
-                                                         TestError::Semantic, "The ultimate failure reason");
-       auto s = to<Status>(expected);
-       EXPECT_FALSE(s.ok());
-       EXPECT_PRED2(stringContains, s.toString(), "The ultimate failure reason");
-}
-
-TEST_F(StatusTests, test_expected_to_status_success)
-{
-       const auto expected =
-               Expected<std::string, TestError>("This is not a failure");
-       auto s = to<Status>(expected);
-       EXPECT_TRUE(s.ok());
-       EXPECT_EQ(s, Status::success());
-}
 }
diff --git a/src/osquery/utils/system/env.h b/src/osquery/utils/system/env.h
deleted file mode 100644 (file)
index 5a5e62d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-#include <boost/optional.hpp>
-
-
-namespace osquery {
-
-/// Set the environment variable name with value value.
-bool setEnvVar(const std::string& name, const std::string& value);
-
-/// Unsets the environment variable specified by name.
-bool unsetEnvVar(const std::string& name);
-
-/**
- * @brief Returns the value of the specified environment variable name.
- *
- * If the environment variable does not exist, boost::none is returned.
- */
-boost::optional<std::string> getEnvVar(const std::string& name);
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/errno.h b/src/osquery/utils/system/errno.h
deleted file mode 100644 (file)
index 66298c8..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-
-namespace osquery {
-
-/// Returns a C++ string explaining the errnum
-std::string platformStrerr(int errnum);
-
-}
diff --git a/src/osquery/utils/system/filepath.h b/src/osquery/utils/system/filepath.h
deleted file mode 100644 (file)
index d7a118a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <string>
-
-namespace osquery {
-
-/// Safer way to do realpath
-const std::string canonicalize_file_name(const char* name);
-
-}
diff --git a/src/osquery/utils/system/posix/env.cpp b/src/osquery/utils/system/posix/env.cpp
deleted file mode 100644 (file)
index 6e878bc..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <osquery/utils/system/env.h>
-
-#include <string>
-#include <boost/optional.hpp>
-
-#include <stdlib.h>
-
-
-namespace osquery {
-
-bool setEnvVar(const std::string& name, const std::string& value)
-{
-       auto ret = ::setenv(name.c_str(), value.c_str(), 1);
-       return (ret == 0);
-}
-
-bool unsetEnvVar(const std::string& name)
-{
-       auto ret = ::unsetenv(name.c_str());
-       return (ret == 0);
-}
-
-boost::optional<std::string> getEnvVar(const std::string& name)
-{
-       char* value = ::getenv(name.c_str());
-       if (value) {
-               return std::string(value);
-       }
-       return boost::none;
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/posix/errno.cpp b/src/osquery/utils/system/posix/errno.cpp
deleted file mode 100644 (file)
index d86ce2e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <osquery/utils/system/errno.h>
-#include <osquery/utils/system/posix/errno.h>
-
-#include <string.h>
-
-#include <unordered_map>
-
-namespace osquery {
-
-std::string platformStrerr(int errnum)
-{
-       return ::strerror(errnum);
-}
-
-namespace impl {
-
-PosixError toPosixSystemError(int from_errno)
-{
-       static auto const table = std::unordered_map<int, PosixError> {
-               {EPERM, PosixError::PERM},     {ENOENT, PosixError::NOENT},
-               {ESRCH, PosixError::SRCH},     {EINTR, PosixError::INTR},
-               {EIO, PosixError::IO},         {ENXIO, PosixError::NXIO},
-               {E2BIG, PosixError::T_BIG},    {ENOEXEC, PosixError::NOEXEC},
-               {EBADF, PosixError::BADF},     {ECHILD, PosixError::CHILD},
-               {EAGAIN, PosixError::AGAIN},   {ENOMEM, PosixError::NOMEM},
-               {EACCES, PosixError::ACCES},   {EFAULT, PosixError::FAULT},
-               {ENOTBLK, PosixError::NOTBLK}, {EBUSY, PosixError::BUSY},
-               {EEXIST, PosixError::EXIST},   {EXDEV, PosixError::XDEV},
-               {ENODEV, PosixError::NODEV},   {ENOTDIR, PosixError::NOTDIR},
-               {EISDIR, PosixError::ISDIR},   {EINVAL, PosixError::INVAL},
-               {ENFILE, PosixError::NFILE},   {EMFILE, PosixError::MFILE},
-               {ENOTTY, PosixError::NOTTY},   {ETXTBSY, PosixError::TXTBSY},
-               {EFBIG, PosixError::FBIG},     {ENOSPC, PosixError::NOSPC},
-               {ESPIPE, PosixError::SPIPE},   {EROFS, PosixError::ROFS},
-               {EMLINK, PosixError::MLINK},   {EPIPE, PosixError::PIPE},
-               {EDOM, PosixError::DOM},       {ERANGE, PosixError::RANGE},
-       };
-       auto const it = table.find(from_errno);
-       if (it == table.end()) {
-               return PosixError::Unknown;
-       }
-       return it->second;
-}
-
-} // namespace impl
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/posix/errno.h b/src/osquery/utils/system/posix/errno.h
deleted file mode 100644 (file)
index 43eb0af..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- *  Copyright (c) 2018-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <errno.h>
-
-#include <type_traits>
-
-namespace osquery {
-
-enum class PosixError {
-       Unknown = 0,
-       PERM = EPERM,
-       NOENT = ENOENT,
-       SRCH = ESRCH,
-       INTR = EINTR,
-       IO = EIO,
-       NXIO = ENXIO,
-       T_BIG = E2BIG,
-       NOEXEC = ENOEXEC,
-       BADF = EBADF,
-       CHILD = ECHILD,
-       AGAIN = EAGAIN,
-       NOMEM = ENOMEM,
-       ACCES = EACCES,
-       FAULT = EFAULT,
-       NOTBLK = ENOTBLK,
-       BUSY = EBUSY,
-       EXIST = EEXIST,
-       XDEV = EXDEV,
-       NODEV = ENODEV,
-       NOTDIR = ENOTDIR,
-       ISDIR = EISDIR,
-       INVAL = EINVAL,
-       NFILE = ENFILE,
-       MFILE = EMFILE,
-       NOTTY = ENOTTY,
-       TXTBSY = ETXTBSY,
-       FBIG = EFBIG,
-       NOSPC = ENOSPC,
-       SPIPE = ESPIPE,
-       ROFS = EROFS,
-       MLINK = EMLINK,
-       PIPE = EPIPE,
-       DOM = EDOM,
-       RANGE = ERANGE,
-};
-
-namespace impl {
-
-PosixError toPosixSystemError(int from_errno);
-
-}
-
-template <typename ToType>
-inline typename std::enable_if<std::is_same<ToType, PosixError>::value,
-          PosixError>::type
-          to(int from_errno)
-{
-       return impl::toPosixSystemError(from_errno);
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/posix/filepath.cpp b/src/osquery/utils/system/posix/filepath.cpp
deleted file mode 100644 (file)
index 0a8c51a..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <osquery/utils/system/filepath.h>
-
-#include <climits>
-#include <cstdlib>
-#include <cstring>
-#include <string>
-
-namespace osquery {
-
-const std::string canonicalize_file_name(const char* name)
-{
-#ifdef PATH_MAX
-       // On supported platforms where PATH_MAX is defined we can pass null
-       // as buffer, and allow libc to alloced space
-       // On centos/ubuntu libc will use realloc so we will be able to resolve
-       // any path
-       // On darwin libc will allocate PATH_MAX buffer for us
-       char* resolved = realpath(name, nullptr);
-       std::string result = (resolved == nullptr) ? name : resolved;
-       free(resolved);
-#else
-#warning PATH_MAX is undefined, please read comment below
-       // PATH_MAX is not defined, very likely it's not officially supported
-       // os, our best guess is _PC_PATH_MAX if available
-       // In case of failure fallback to "safe" buffer of 8K
-
-       long int path_max = pathconf(name, _PC_PATH_MAX);
-       if (path_max <= 0) {
-               path_max = 8 * 1024;
-       }
-       char* buffer = static_cast<char*>(malloc(path_max));
-       char* resolved = realpath(name, buffer);
-       std::string result = (resolved == nullptr) ? name : resolved;
-       free(buffer);
-#endif
-       return result;
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/posix/tests/errno.cpp b/src/osquery/utils/system/posix/tests/errno.cpp
deleted file mode 100644 (file)
index c08d045..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- *  Copyright (c) 2018-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <string>
-
-#include <gtest/gtest.h>
-
-#include <osquery/utils/system/posix/errno.h>
-
-namespace osquery {
-namespace {
-
-class PosixErrnoTests : public testing::Test {};
-
-TEST_F(PosixErrnoTests, to)
-{
-       EXPECT_EQ(PosixError::Unknown, to<PosixError>(0));
-       EXPECT_EQ(PosixError::Unknown, to<PosixError>(-1));
-       EXPECT_EQ(PosixError::Unknown, to<PosixError>(98765));
-       EXPECT_EQ(PosixError::Unknown, to<PosixError>(987654));
-
-       EXPECT_EQ(PosixError::PIPE, to<PosixError>(EPIPE));
-       EXPECT_EQ(PosixError::DOM, to<PosixError>(EDOM));
-       EXPECT_EQ(PosixError::RANGE, to<PosixError>(ERANGE));
-       EXPECT_EQ(PosixError::T_BIG, to<PosixError>(E2BIG));
-}
-
-} // namespace
-} // namespace osquery
diff --git a/src/osquery/utils/system/posix/time.cpp b/src/osquery/utils/system/posix/time.cpp
deleted file mode 100644 (file)
index 24fbfa1..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <osquery/utils/system/time.h>
-
-#include <string.h>
-
-namespace osquery {
-
-std::string platformAsctime(const struct tm* timeptr)
-{
-       if (timeptr == nullptr) {
-               return "";
-       }
-
-       // Manual says at least 26 characters.
-       char buffer[32] = {0};
-       return ::asctime_r(timeptr, buffer);
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/tests/cpu.cpp b/src/osquery/utils/system/tests/cpu.cpp
deleted file mode 100644 (file)
index 84e0532..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
diff --git a/src/osquery/utils/system/tests/errno.cpp b/src/osquery/utils/system/tests/errno.cpp
deleted file mode 100644 (file)
index d50e445..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- *  Copyright (c) 2018-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
diff --git a/src/osquery/utils/system/tests/time.cpp b/src/osquery/utils/system/tests/time.cpp
deleted file mode 100644 (file)
index c668362..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <gtest/gtest.h>
-
-#include <osquery/utils/system/time.h>
-
-namespace osquery {
-
-class TimeTests : public testing::Test {};
-
-TEST_F(TimeTests, test_asciitime)
-{
-       const std::time_t epoch = 1491518994;
-       const std::string expected = "Thu Apr  6 22:49:54 2017 UTC";
-
-       auto const result = std::gmtime(&epoch);
-
-       EXPECT_EQ(expected, toAsciiTime(result));
-}
-
-TEST_F(TimeTests, test_asciitimeutc)
-{
-       const std::time_t epoch = 1491518994;
-       const std::string expected = "Thu Apr  6 22:49:54 2017 UTC";
-
-       auto const result = std::localtime(&epoch);
-
-       EXPECT_EQ(expected, toAsciiTimeUTC(result));
-}
-}
diff --git a/src/osquery/utils/system/time.cpp b/src/osquery/utils/system/time.cpp
deleted file mode 100644 (file)
index f45ae5c..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#include <osquery/utils/system/time.h>
-
-#include <boost/algorithm/string/trim.hpp>
-
-#include <cstring>
-#include <ctime>
-
-namespace osquery {
-
-std::string toAsciiTime(const struct tm* tm_time)
-{
-       if (tm_time == nullptr) {
-               return "";
-       }
-
-       auto time_str = platformAsctime(tm_time);
-       boost::algorithm::trim(time_str);
-       return time_str + " UTC";
-}
-
-std::string toAsciiTimeUTC(const struct tm* tm_time)
-{
-       size_t epoch = toUnixTime(tm_time);
-       struct tm tptr;
-
-       std::memset(&tptr, 0, sizeof(tptr));
-
-       if (epoch == (size_t) -1) {
-               return "";
-       }
-
-#ifdef OSQUERY_WINDOWS
-       _gmtime64_s(&tptr, (time_t*)&epoch);
-#else
-       gmtime_r((time_t*)&epoch, &tptr);
-#endif
-       return toAsciiTime(&tptr);
-}
-
-std::string getAsciiTime()
-{
-       auto result = std::time(nullptr);
-
-       struct tm now;
-#ifdef OSQUERY_WINDOWS
-       _gmtime64_s(&now, &result);
-#else
-       gmtime_r(&result, &now);
-#endif
-
-       return toAsciiTime(&now);
-}
-
-size_t toUnixTime(const struct tm* tm_time)
-{
-       struct tm result;
-       std::memset(&result, 0, sizeof(result));
-
-       std::memcpy(&result, tm_time, sizeof(result));
-       return mktime(&result);
-}
-
-size_t getUnixTime()
-{
-       std::time_t ut = std::time(nullptr);
-       return ut < 0 ? 0 : ut;
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/system/time.h b/src/osquery/utils/system/time.h
deleted file mode 100644 (file)
index 774c4e5..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- *  Copyright (c) 2014-present, Facebook, Inc.
- *  All rights reserved.
- *
- *  This source code is licensed in accordance with the terms specified in
- *  the LICENSE file found in the root directory of this source tree.
- */
-
-#pragma once
-
-#include <ctime>
-#include <string>
-
-namespace osquery {
-
-/// Returns the ASCII version of the timeptr as a C++ string
-std::string platformAsctime(const struct tm* timeptr);
-
-/**
- * @brief Converts struct tm to a size_t
- *
- * @param tm_time the time/date to convert to UNIX epoch time
- *
- * @return an int representing the UNIX epoch time of the struct tm
- */
-size_t toUnixTime(const struct tm* tm_time);
-
-/**
- * @brief Getter for the current UNIX time.
- *
- * @return an int representing the amount of seconds since the UNIX epoch
- */
-size_t getUnixTime();
-
-/**
- * @brief Converts a struct tm into a human-readable format. This expected the
- * struct tm to be already in UTC time/
- *
- * @param tm_time the time/date to convert to ASCII
- *
- * @return the data/time of tm_time in the format: "Wed Sep 21 10:27:52 2011"
- */
-std::string toAsciiTime(const struct tm* tm_time);
-
-/**
- * @brief Converts a struct tm to ASCII time UTC by converting the tm_time to
- * epoch and then running gmtime() on the new epoch
- *
- * @param tm_time the local time/date to covert to UTC ASCII time
- *
- * @return the data/time of tm_time in the format: "Wed Sep 21 10:27:52 2011"
- */
-std::string toAsciiTimeUTC(const struct tm* tm_time);
-
-/**
- * @brief Getter for the current time, in a human-readable format.
- *
- * @return the current date/time in the format: "Wed Sep 21 10:27:52 2011"
- */
-std::string getAsciiTime();
-
-}