From: Sangwan Kwon Date: Fri, 24 Apr 2020 07:47:01 +0000 (+0900) Subject: Remove utils X-Git-Tag: submit/tizen/20200810.073515~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f091eeedcbc33e14d9117c3beaf594ea796722f;p=platform%2Fcore%2Fsecurity%2Fvist.git Remove utils Signed-off-by: Sangwan Kwon --- diff --git a/src/osquery/logger/logger.cpp b/src/osquery/logger/logger.cpp index a5d04a3..5b16351 100644 --- a/src/osquery/logger/logger.cpp +++ b/src/osquery/logger/logger.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -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& BufferedLogSink::dump() { diff --git a/src/osquery/sql/tests/sql_test_utils.h b/src/osquery/sql/tests/sql_test_utils.h index c7b1255..6660bed 100644 --- a/src/osquery/sql/tests/sql_test_utils.h +++ b/src/osquery/sql/tests/sql_test_utils.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace osquery { diff --git a/src/osquery/sql/tests/sqlite_util_tests.cpp b/src/osquery/sql/tests/sqlite_util_tests.cpp index 59120ad..f78550d 100644 --- a/src/osquery/sql/tests/sqlite_util_tests.cpp +++ b/src/osquery/sql/tests/sqlite_util_tests.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include @@ -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()); } { diff --git a/src/osquery/sql/virtual_sqlite_table.cpp b/src/osquery/sql/virtual_sqlite_table.cpp index 40ba0b8..bde8fb0 100644 --- a/src/osquery/sql/virtual_sqlite_table.cpp +++ b/src/osquery/sql/virtual_sqlite_table.cpp @@ -10,8 +10,6 @@ #include #include -#include - #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, diff --git a/src/osquery/tests/test_util.cpp b/src/osquery/tests/test_util.cpp index 6764643..39b93fa 100644 --- a/src/osquery/tests/test_util.cpp +++ b/src/osquery/tests/test_util.cpp @@ -26,7 +26,6 @@ #include #include -#include 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(); diff --git a/src/osquery/utils/CMakeLists.txt b/src/osquery/utils/CMakeLists.txt index 40b114f..74a17dd 100644 --- a/src/osquery/utils/CMakeLists.txt +++ b/src/osquery/utils/CMakeLists.txt @@ -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 index 1c88673..0000000 --- a/src/osquery/utils/config/default_paths.cpp +++ /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 index bb5d3df..0000000 --- a/src/osquery/utils/config/default_paths.h +++ /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 index 00fcd02..0000000 --- a/src/osquery/utils/enum_class_hash.h +++ /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 - -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 std::enable_if::value, std::size_t>::type - operator()(EnumClassType t) const { - return static_cast(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 index 675d004..0000000 --- a/src/osquery/utils/info/platform_type.cpp +++ /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 - -namespace osquery { - -const std::string kSDKPlatform = OSQUERY_PLATFORM; - -/// Helper method for platform type detection. -bool isPlatform(PlatformType a, const PlatformType& t) { - return (static_cast(t) & static_cast(a)) != 0; -} - -PlatformType operator|(PlatformType a, PlatformType b) { - return static_cast(static_cast(a) | static_cast(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 index 7124bed..0000000 --- a/src/osquery/utils/info/platform_type.h +++ /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 - -#include -#include - -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(0u -#ifdef POSIX - | static_cast(PlatformType::TYPE_POSIX) -#endif -#ifdef WINDOWS - | static_cast(PlatformType::TYPE_WINDOWS) -#endif -#ifdef BSD - | static_cast(PlatformType::TYPE_BSD) -#endif -#ifdef LINUX - | static_cast(PlatformType::TYPE_LINUX) -#endif -#ifdef DARWIN - | static_cast(PlatformType::TYPE_OSX) -#endif -#ifdef FREEBSD - | static_cast(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 index 4054e9e..0000000 --- a/src/osquery/utils/info/version.cpp +++ /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 -#include - -#include -#include - -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 index cd6f54a..0000000 --- a/src/osquery/utils/info/version.h +++ /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 - -#include - -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 index de0a78f..0000000 --- a/src/osquery/utils/map_take.h +++ /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 -#include - -#include - -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 -struct IsMap : std::false_type {}; - -template -struct IsMap> : std::true_type {}; - -template -struct IsMap> : 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 -inline typename std::enable_if::value, - Expected>::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 -inline typename std::enable_if::value, - Expected>::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 index be80b8c..0000000 --- a/src/osquery/utils/scope_guard.h +++ /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 - -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 -class Guard final { - public: - explicit Guard(FinalRoutineType final_routine) - : final_routine_(std::move(final_routine)) {} - - ~Guard() { - final_routine_(); - } - - private: - FinalRoutineType final_routine_; -}; - -template -inline auto create(FinalRoutineType&& final_routine) { - return Guard(std::forward(final_routine)); -} - -} // namespace scope_guard - -} // namespace osquery