Remove utils
authorSangwan Kwon <sangwan.kwon@samsung.com>
Fri, 24 Apr 2020 07:47:01 +0000 (16:47 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Tue, 28 Apr 2020 07:13:55 +0000 (16:13 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
15 files changed:
src/osquery/logger/logger.cpp
src/osquery/sql/tests/sql_test_utils.h
src/osquery/sql/tests/sqlite_util_tests.cpp
src/osquery/sql/virtual_sqlite_table.cpp
src/osquery/tests/test_util.cpp
src/osquery/utils/CMakeLists.txt
src/osquery/utils/config/default_paths.cpp [deleted file]
src/osquery/utils/config/default_paths.h [deleted file]
src/osquery/utils/enum_class_hash.h [deleted file]
src/osquery/utils/info/platform_type.cpp [deleted file]
src/osquery/utils/info/platform_type.h [deleted file]
src/osquery/utils/info/version.cpp [deleted file]
src/osquery/utils/info/version.h [deleted file]
src/osquery/utils/map_take.h [deleted file]
src/osquery/utils/scope_guard.h [deleted file]

index a5d04a3..5b16351 100644 (file)
@@ -22,7 +22,6 @@
 #include <osquery/registry_factory.h>
 
 #include <osquery/utils/conversions/split.h>
-#include <osquery/utils/info/platform_type.h>
 #include <osquery/utils/json/json.h>
 #include <osquery/utils/system/time.h>
 
@@ -232,12 +231,7 @@ void BufferedLogSink::WaitTillSent() {
     senders.pop();
   }
 
-  if (!isPlatform(PlatformType::TYPE_WINDOWS)) {
-    first.wait();
-  } else {
-    // Windows is locking by scheduling an async on the main thread.
-    first.wait_for(std::chrono::microseconds(100));
-  }
+  first.wait();
 }
 
 std::vector<StatusLogLine>& BufferedLogSink::dump() {
index c7b1255..6660bed 100644 (file)
@@ -3,7 +3,6 @@
 #include <osquery/registry_interface.h>
 #include <osquery/sql.h>
 #include <osquery/sql/sqlite_util.h>
-#include <osquery/utils/info/platform_type.h>
 
 namespace osquery {
 
index 59120ad..f78550d 100644 (file)
@@ -11,7 +11,6 @@
 #include <osquery/sql.h>
 #include <osquery/sql/sqlite_util.h>
 #include <osquery/sql/tests/sql_test_utils.h>
-#include <osquery/utils/info/platform_type.h>
 
 #include <gtest/gtest.h>
 
@@ -179,10 +178,8 @@ TEST_F(SQLiteUtilTests, test_affected_tables) {
 TEST_F(SQLiteUtilTests, test_table_attributes_event_based) {
   {
     SQLInternal sql_internal("select * from process_events");
-    if (!isPlatform(PlatformType::TYPE_WINDOWS)) {
-      EXPECT_TRUE(sql_internal.getStatus().ok());
-      EXPECT_TRUE(sql_internal.eventBased());
-    }
+    EXPECT_TRUE(sql_internal.getStatus().ok());
+    EXPECT_TRUE(sql_internal.eventBased());
   }
 
   {
index 40ba0b8..bde8fb0 100644 (file)
@@ -10,8 +10,6 @@
 #include <osquery/logger.h>
 #include <osquery/sql.h>
 
-#include <osquery/utils/info/platform_type.h>
-
 #include "osquery/sql/dynamic_table_row.h"
 #include "osquery/sql/sqlite_util.h"
 
@@ -23,15 +21,7 @@ namespace errc = boost::system::errc;
 namespace osquery {
 
 const char* getSystemVFS(bool respect_locking) {
-  if (respect_locking) {
-    return nullptr;
-  }
-  if (isPlatform(PlatformType::TYPE_POSIX)) {
-    return "unix-none";
-  } else if (isPlatform(PlatformType::TYPE_WINDOWS)) {
-    return "win32-none";
-  }
-  return nullptr;
+  return "unix-none";
 }
 
 Status genSqliteTableRow(sqlite3_stmt* stmt,
index 6764643..39b93fa 100644 (file)
@@ -26,7 +26,6 @@
 #include <osquery/utils/conversions/tryto.h>
 
 #include <osquery/tests/test_util.h>
-#include <osquery/utils/info/platform_type.h>
 
 namespace fs = boost::filesystem;
 
@@ -44,16 +43,8 @@ std::string kTestDataPath{"../../../tools/tests/"};
 using chrono_clock = std::chrono::high_resolution_clock;
 
 void initTesting() {
-  if (osquery::isPlatform(PlatformType::TYPE_OSX)) {
-    kTestWorkingDirectory = "/private/tmp/osquery-tests";
-  } else {
-    kTestWorkingDirectory =
-        (fs::temp_directory_path() / "osquery-tests").string();
-  }
-
-  if (osquery::isPlatform(PlatformType::TYPE_WINDOWS)) {
-    kTestDataPath = "../" + kTestDataPath;
-  }
+  kTestWorkingDirectory =
+     (fs::temp_directory_path() / "osquery-tests").string();
 
   registryAndPluginInit();
 
index 40b114f..74a17dd 100644 (file)
@@ -21,8 +21,6 @@ ADD_OSQUERY_LIBRARY(osquery_utils base64.cpp
                                                                  system/posix/errno.cpp
                                                                  system/posix/filepath.cpp
                                                                  system/posix/time.cpp
-                                                                 info/platform_type.cpp
-                                                                 config/default_paths.cpp
                                                                  conversions/tryto.cpp
                                                                  conversions/split.cpp
                                                                  json/json.cpp)
diff --git a/src/osquery/utils/config/default_paths.cpp b/src/osquery/utils/config/default_paths.cpp
deleted file mode 100644 (file)
index 1c88673..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 "default_paths.h"
diff --git a/src/osquery/utils/config/default_paths.h b/src/osquery/utils/config/default_paths.h
deleted file mode 100644 (file)
index bb5d3df..0000000
+++ /dev/null
@@ -1,50 +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.
- */
-
-/**
- * @brief A series of platform-specific home folders.
- *
- * There are several platform-specific folders where osquery reads and writes
- * content. Most of the variance is due to legacy support.
- *
- * OSQUERY_HOME: Configuration, flagfile, extensions and module autoload.
- * OSQUERY_DB_HOME: Location of RocksDB persistent storage.
- * OSQUERY_LOG_HOME: Location of log data when the filesystem plugin is used.
- */
-
-#pragma once
-
-#if defined(__linux__)
-#define OSQUERY_HOME "/etc/osquery/"
-#define OSQUERY_DB_HOME "/var/osquery/"
-#define OSQUERY_SOCKET OSQUERY_DB_HOME
-#define OSQUERY_PIDFILE "/var/run/"
-#define OSQUERY_LOG_HOME "/var/log/osquery/"
-#define OSQUERY_CERTS_HOME "/usr/share/osquery/certs/"
-#elif defined(WIN32)
-#define OSQUERY_HOME "\\Program Files\\osquery\\"
-#define OSQUERY_DB_HOME OSQUERY_HOME
-#define OSQUERY_SOCKET "\\\\.\\pipe\\"
-#define OSQUERY_PIDFILE OSQUERY_DB_HOME
-#define OSQUERY_LOG_HOME OSQUERY_HOME "log\\"
-#define OSQUERY_CERTS_HOME OSQUERY_HOME "certs\\"
-#elif defined(FREEBSD)
-#define OSQUERY_HOME "/var/db/osquery/"
-#define OSQUERY_DB_HOME OSQUERY_HOME
-#define OSQUERY_SOCKET "/var/run/"
-#define OSQUERY_PIDFILE "/var/run/"
-#define OSQUERY_LOG_HOME "/var/log/osquery/"
-#define OSQUERY_CERTS_HOME "/etc/ssl/"
-#else
-#define OSQUERY_HOME "/var/osquery/"
-#define OSQUERY_DB_HOME OSQUERY_HOME
-#define OSQUERY_SOCKET OSQUERY_DB_HOME
-#define OSQUERY_PIDFILE OSQUERY_DB_HOME
-#define OSQUERY_LOG_HOME "/var/log/osquery/"
-#define OSQUERY_CERTS_HOME OSQUERY_HOME "certs/"
-#endif
diff --git a/src/osquery/utils/enum_class_hash.h b/src/osquery/utils/enum_class_hash.h
deleted file mode 100644 (file)
index 00fcd02..0000000
+++ /dev/null
@@ -1,28 +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 <type_traits>
-
-namespace osquery {
-
-/**
- * This is just a ad-hoc fix up to handle libc++ and libstdc++ bug:
- * http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
- * Eventually it will be removed.
- */
-struct EnumClassHash {
-  template <typename EnumClassType>
-  typename std::enable_if<std::is_enum<EnumClassType>::value, std::size_t>::type
-  operator()(EnumClassType t) const {
-    return static_cast<std::size_t>(t);
-  }
-};
-
-} // namespace osquery
diff --git a/src/osquery/utils/info/platform_type.cpp b/src/osquery/utils/info/platform_type.cpp
deleted file mode 100644 (file)
index 675d004..0000000
+++ /dev/null
@@ -1,24 +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/info/platform_type.h>
-
-namespace osquery {
-
-const std::string kSDKPlatform = OSQUERY_PLATFORM;
-
-/// Helper method for platform type detection.
-bool isPlatform(PlatformType a, const PlatformType& t) {
-  return (static_cast<int>(t) & static_cast<int>(a)) != 0;
-}
-
-PlatformType operator|(PlatformType a, PlatformType b) {
-  return static_cast<PlatformType>(static_cast<int>(a) | static_cast<int>(b));
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/info/platform_type.h b/src/osquery/utils/info/platform_type.h
deleted file mode 100644 (file)
index 7124bed..0000000
+++ /dev/null
@@ -1,86 +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 <osquery/utils/info/version.h>
-#include <osquery/utils/macros/macros.h>
-
-namespace osquery {
-
-/**
- * @brief A helpful runtime-detection enumeration of platform configurations.
- *
- * CMake, or the build tooling, will generate a OSQUERY_PLATFORM_MASK and pass
- * it to the library compile only.
- */
-enum class PlatformType {
-  TYPE_POSIX = 0x01,
-  TYPE_WINDOWS = 0x02,
-  TYPE_BSD = 0x04,
-  TYPE_LINUX = 0x08,
-  TYPE_OSX = 0x10,
-  TYPE_FREEBSD = 0x20,
-};
-
-/// The build-defined set of platform types.
-constexpr PlatformType kPlatformType = static_cast<PlatformType>(0u
-#ifdef POSIX
-    | static_cast<unsigned>(PlatformType::TYPE_POSIX)
-#endif
-#ifdef WINDOWS
-    | static_cast<unsigned>(PlatformType::TYPE_WINDOWS)
-#endif
-#ifdef BSD
-    | static_cast<unsigned>(PlatformType::TYPE_BSD)
-#endif
-#ifdef LINUX
-    | static_cast<unsigned>(PlatformType::TYPE_LINUX)
-#endif
-#ifdef DARWIN
-    | static_cast<unsigned>(PlatformType::TYPE_OSX)
-#endif
-#ifdef FREEBSD
-    | static_cast<unsigned>(PlatformType::TYPE_FREEBSD)
-#endif
-);
-
-bool isPlatform(PlatformType a, const PlatformType& t = kPlatformType);
-
-PlatformType operator|(PlatformType a, PlatformType b);
-
-/**
- * @brief Platform specific code isolation and define-based conditionals.
- *
- * The following preprocessor defines are expected to be available for all
- * osquery code. Please use them sparingly and prefer the run-time detection
- * methods first. See the %PlatformType class and %isPlatform method.
- *
- * OSQUERY_BUILD_PLATFORM: For Linux, this is the distro name, for OS X this is
- *   darwin, and on Windows it is windows. The set of potential values comes
- *   the ./tools/platform scripts and may be overridden.
- * OSQUERY_BUILD_DISTRO: For Linux, this is the version, for OS X this is the
- *   version (10.10, 10.11, 10.12), for Windows this is Win10.
- * OSQUERY_PLATFORM: available as kSDKPlatform, a OSQUERY_BUILD_PLATFORM string.
- */
-#if !defined(OSQUERY_BUILD_PLATFORM)
-#error The build must define OSQUERY_BUILD_PLATFORM.
-#endif
-
-#if !defined(OSQUERY_BUILD_DISTRO)
-#error The build must define OSQUERY_BUILD_DISTRO.
-#endif
-
-#define OSQUERY_PLATFORM STR(OSQUERY_BUILD_PLATFORM)
-
-/// Identifies the build platform of either the core extension.
-extern const std::string kSDKPlatform;
-
-} // namespace osquery
diff --git a/src/osquery/utils/info/version.cpp b/src/osquery/utils/info/version.cpp
deleted file mode 100644 (file)
index 4054e9e..0000000
+++ /dev/null
@@ -1,50 +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/info/version.h>
-#include <osquery/utils/conversions/split.h>
-
-#include <stdexcept>
-#include <stdexcept>
-
-namespace osquery {
-
-const std::string kVersion = STR(OSQUERY_VERSION);
-const std::string kSDKVersion = STR(OSQUERY_BUILD_SDK_VERSION);
-
-bool versionAtLeast(const std::string& v, const std::string& sdk) {
-  if (v == "0.0.0" || sdk == "0.0.0") {
-    // This is a please-pass check.
-    return true;
-  }
-
-  auto required_version = split(v, ".");
-  auto build_version = split(sdk, ".");
-
-  size_t index = 0;
-  for (const auto& chunk : build_version) {
-    if (required_version.size() <= index) {
-      return true;
-    }
-    try {
-      if (std::stoi(chunk) < std::stoi(required_version[index])) {
-        return false;
-      } else if (std::stoi(chunk) > std::stoi(required_version[index])) {
-        return true;
-      }
-    } catch (const std::invalid_argument& /* e */) {
-      if (chunk.compare(required_version[index]) < 0) {
-        return false;
-      }
-    }
-    index++;
-  }
-  return true;
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/info/version.h b/src/osquery/utils/info/version.h
deleted file mode 100644 (file)
index cd6f54a..0000000
+++ /dev/null
@@ -1,52 +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 <osquery/utils/macros/macros.h>
-
-namespace osquery {
-
-#if !defined(OSQUERY_VERSION)
-#error The build must define OSQUERY_VERSION.
-#endif
-
-#if !defined(OSQUERY_BUILD_VERSION)
-#warning The build should define OSQUERY_BUILD_VERSION.
-#define OSQUERY_BUILD_VERSION 1.0.0-unknown
-#endif
-
-#if !defined(OSQUERY_BUILD_SDK_VERSION)
-#error The build must define OSQUERY_BUILD_SDK_VERSION.
-#endif
-
-#define OSQUERY_SDK_VERSION STR(OSQUERY_BUILD_SDK_VERSION)
-
-/// The version of osquery
-extern const std::string kVersion;
-
-/// The osquery SDK version
-extern const std::string kSDKVersion;
-
-/**
- * @brief Compare osquery SDK/extension/core version strings.
- *
- * SDK versions are in major.minor.patch-commit-hash form. We provide a helper
- * method for performing version comparisons to allow gating and compatibility
- * checks throughout the code.
- *
- * @param v version to check
- * @param sdk (optional) the SDK version to check against.
- * return true if the input version is at least the SDK version.
- */
-bool versionAtLeast(const std::string& v,
-                    const std::string& version = kVersion);
-
-} // namespace osquery
diff --git a/src/osquery/utils/map_take.h b/src/osquery/utils/map_take.h
deleted file mode 100644 (file)
index de0a78f..0000000
+++ /dev/null
@@ -1,110 +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 <map>
-#include <unordered_map>
-
-#include <osquery/utils/expected/expected.h>
-
-namespace osquery {
-
-/**
- * Helper functions to look up in key-value tables.
- *
- * There are several reasons for using this code:
- *   1. To reduce amount of code and increase the readability of it.
- *      Instead of verbose piece of code such as:
- *      @code{.cpp}
- *        auto takenValue = ValueType{};
- *        auto const it = table.find("key");
- *        if (it != table.end()) {
- *          takenValue = it->second;
- *        }
- *      @endcode
- *      Have more short and simple:
- *      @code{.cpp}
- *        auto const takenValue = tryTakeCopy(table, "key").takeOr(ValueType{});
- *      @endcode
- *
- *   2. To avoid nonoptimal code with two exactly the same lookups, e.g.:
- *      @code{.cpp}
- *        auto takenValue = table.count(key) ? table.at(key) : ValueType{};
- *      @endcode
- *
- *   3. To reduce the possibility of dangerous misstypes such as:
- *      @code{.cpp}
- *        auto takenValue = table.count("key") ? table.at("KeY") : ValueType{};
- *      @endcode
- */
-
-enum class MapTakeError {
-  NoSuchKey = 1,
-};
-
-namespace impl {
-
-template <typename T>
-struct IsMap : std::false_type {};
-
-template <typename... TemplateArgs>
-struct IsMap<std::map<TemplateArgs...>> : std::true_type {};
-
-template <typename... TemplateArgs>
-struct IsMap<std::unordered_map<TemplateArgs...>> : std::true_type {};
-
-} // namespace impl
-
-/**
- * @brief Take out object from the table by key
- *
- * @param table to look up (std::map or std::unordered_map)
- * @param key to look up by in the table
- *
- * @return Expected object with value if such key exists in the table,
- * otherwise Error of type MapTakeError
- */
-template <typename MapType,
-          typename KeyType = typename MapType::key_type,
-          typename ValueType = typename MapType::mapped_type>
-inline typename std::enable_if<impl::IsMap<MapType>::value,
-                               Expected<ValueType, MapTakeError>>::type
-tryTake(MapType& table, const KeyType& key) {
-  auto it = table.find(key);
-  if (it == table.end()) {
-    return createError(MapTakeError::NoSuchKey) << "no such key in the table";
-  }
-  auto item = std::move(it->second);
-  table.erase(it);
-  return item;
-}
-
-/**
- * @brief Take object copy from the table by key
- *
- * @param table to look up (std::map or std::unordered_map)
- * @param key to look up by in the table
- *
- * @return Expected object with value if such key exists in the table,
- * otherwise Error of type MapTakeError
- */
-template <typename MapType,
-          typename KeyType = typename MapType::key_type,
-          typename ValueType = typename MapType::mapped_type>
-inline typename std::enable_if<impl::IsMap<MapType>::value,
-                               Expected<ValueType, MapTakeError>>::type
-tryTakeCopy(MapType const& from, KeyType const& key) {
-  auto const it = from.find(key);
-  if (it == from.end()) {
-    return createError(MapTakeError::NoSuchKey) << "no such key in the table";
-  }
-  return it->second;
-}
-
-} // namespace osquery
diff --git a/src/osquery/utils/scope_guard.h b/src/osquery/utils/scope_guard.h
deleted file mode 100644 (file)
index be80b8c..0000000
+++ /dev/null
@@ -1,57 +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 <utility>
-
-namespace osquery {
-
-namespace scope_guard {
-/**
- * The RAII based scope guard class.
- *
- * To be sure that resources are always released/removed/closed/verified/stoped
- * in face of multiple return statements from the function.
- *
- * It takes functor object by value during the construction. It is going to be
- * called once and only once during the destruction of Guard object.
- *
- * There is helper function to create the object of guard.
- * @code{.cpp}
- *   {
- *     auto const manager = scope_guard::create(
- *       [&file_path]() { fs::remove(file_path); }
- *     );
- *       ...
- *     // it will be removed at the end of scope
- *   }
- * @endcode
- */
-template <typename FinalRoutineType>
-class Guard final {
- public:
-  explicit Guard(FinalRoutineType final_routine)
-      : final_routine_(std::move(final_routine)) {}
-
-  ~Guard() {
-    final_routine_();
-  }
-
- private:
-  FinalRoutineType final_routine_;
-};
-
-template <typename FinalRoutineType>
-inline auto create(FinalRoutineType&& final_routine) {
-  return Guard<FinalRoutineType>(std::forward<FinalRoutineType>(final_routine));
-}
-
-} // namespace scope_guard
-
-} // namespace osquery