+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-
-/**
- * @file osquery_manager.h
- * @brief Osquery manager C++ API header
- */
-
-
-#pragma once
-
-#include <string>
-#include <map>
-#include <vector>
-#include <functional>
-
-namespace osquery {
-
-using Row = std::map<std::string, std::string>;
-using Rows = std::vector<Row>;
-
-using Callback = std::function<void(const Row&)>;
-
-/// TBD: Consider error handling.
-class OsqueryManager final {
-public:
- /// Query Execution method
- static Rows execute(const std::string& query);
-
- /// Event Subscription method
- static void subscribe(const std::string& table, const Callback& callback);
-
- /// Table information
- static std::vector<std::string> columns(const std::string& table) noexcept;
-};
-
-} // namespace osquery
#pragma once
-#include <string>
#include <map>
#include <stdexcept>
+#include <string>
+#include <vector>
-namespace osquery {
+namespace vist {
/// TBD: Consider error handling.
template <typename T>
std::vector<Property<T>> datas;
};
-} // namespace osquery
+} // namespace vist
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-
-/**
- * @file notification.h
- * @brief Notify to registered stuffs when event-callback called
- */
-
-
-#pragma once
-
-#include <map>
-#include <vector>
-
-#include <osquery_manager.h>
-
-#include <osquery/database.h>
-#include <osquery/status.h>
-#include <osquery/registry.h>
-
-namespace osquery {
-
-using NotifyCallback = Callback;
-
-class Notification final {
-public:
- static Notification& instance();
-
- Status add(const std::string& table, const NotifyCallback& callback);
- Status emit(const std::string& table, const Row& result) const;
-
-public:
- Notification(const Notification&) = delete;
- Notification& operator=(const Notification&) = delete;
-
-private:
- Notification() = default;
- ~Notification() = default;
-
- std::multimap<std::string, NotifyCallback> callbacks;
-};
-
-} // namespace osquery
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(common)
-ADD_SUBDIRECTORY(manager)
ADD_SUBDIRECTORY(notification)
ADD_SUBDIRECTORY(property)
ADD_SUBDIRECTORY(service)
#include "ipc/client.h"
namespace {
- const std::string SOCK_ADDR = "/tmp/.vistd";
+ const std::string SOCK_ADDR = "/tmp/.vist";
} // anonymous namespace
namespace vist {
{
auto& client = ipc::Client::Instance(SOCK_ADDR);
- return client->methodCall<Rows>("Vistd::query", statement);
+ return client->methodCall<Rows>("Vist::query", statement);
}
} // namespace vist
* limitations under the License
*/
-#include "service/vistd.h"
+#include "service/vist.h"
#include <cstdlib>
#include <stdexcept>
+using namespace vist;
+
int main() try
{
- vist::Vistd vistd;
- vistd.start();
-
+ Vist::Instance().start();
return EXIT_SUCCESS;
} catch(const std::exception&)
{
+++ /dev/null
-# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License
-
-ADD_VIST_LIBRARY(manager manager.cpp
- manager_impl.cpp)
-
-FILE(GLOB MANAGER_TESTS "tests/m*.cpp")
-ADD_VIST_TEST(${MANAGER_TESTS})
-
-IF(DEFINED GBS_BUILD)
- FILE(GLOB POLICYD_TESTS "tests/p*.cpp")
- ADD_VIST_TEST(${POLICYD_TESTS})
-ENDIF(DEFINED GBS_BUILD)
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-/*
- * @file manager.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of osquery manager
- */
-
-#include <osquery_manager.h>
-
-#include "manager_impl.h"
-
-namespace osquery {
-
-Rows OsqueryManager::execute(const std::string& query)
-{
- return ManagerImpl::instance().execute(query);
-}
-
-void OsqueryManager::subscribe(const std::string& table, const Callback& callback)
-{
- return ManagerImpl::instance().subscribe(table, callback);
-}
-
-std::vector<std::string> OsqueryManager::columns(const std::string& table) noexcept
-{
- return ManagerImpl::instance().columns(table);
-}
-
-} // namespace osquery
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or ManagerImplied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-/*
- * @file manager_impl.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation of osquery manager's impl
- */
-
-#include "manager_impl.h"
-
-#include <osquery/registry.h>
-#include <osquery/core.h>
-#include <osquery/filesystem/filesystem.h>
-#include <osquery/flags.h>
-#include <osquery/logger.h>
-#include <osquery/notification.h>
-#include <osquery/sql.h>
-#include <osquery/status.h>
-
-#include <gflags/gflags.h>
-
-#include <boost/filesystem/operations.hpp>
-
-#include <functional>
-#include <sstream>
-#include <tuple>
-
-namespace osquery {
-
-ManagerImpl::ManagerImpl()
-{
- auto logDir = Flag::getValue("osquery_log_dir");
- if (!logDir.empty() && !(pathExists(logDir).ok()))
- boost::filesystem::create_directories(logDir);
-
- LOG(INFO) << "Initalize osquery manager. ";
-
- registryAndPluginInit();
-}
-
-ManagerImpl::~ManagerImpl() noexcept
-{
- LOG(INFO) << "Shutdown osquery manager.";
-}
-
-ManagerImpl& ManagerImpl::instance()
-{
- static ManagerImpl instance;
- return instance;
-}
-
-Rows ManagerImpl::execute(const std::string& query)
-{
- LOG(INFO) << "Execute query: " << query;
- osquery::SQL sql(query, true);
- if (!sql.ok()) {
- LOG(ERROR) << "Executing query failed: " << sql.getMessageString();
- return Rows();
- }
-
- return std::move(sql.rows());
-}
-
-void ManagerImpl::subscribe(const std::string& table, const Callback& callback)
-{
- LOG(INFO) << "Subscribe event: " << table;
-
- auto status = Notification::instance().add(table, callback);
- if (!status.ok())
- LOG(ERROR) << "Subscribing event failed: " << status.getCode();
-}
-
-std::vector<std::string> ManagerImpl::columns(const std::string& table) noexcept
-{
- std::stringstream query;
- query << "SELECT * FROM " << table;
-
- TableColumns columns;
- getQueryColumns(query.str(), columns);
-
- // Extract column names
- std::vector<std::string> names;
- for (auto& c : columns)
- names.emplace_back(std::move(std::get<0>(c)));
-
- return names;
-}
-
-} // namespace osquery
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or ManagerImplied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-/*
- * @file manager_impl.h
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @brief Implementation interface of osquery manager
- */
-
-#pragma once
-
-#include <osquery_manager.h>
-
-#include <string>
-#include <vector>
-
-namespace osquery {
-
-/// Singleton class
-class ManagerImpl final {
-public:
- ManagerImpl(const ManagerImpl&) = delete;
- ManagerImpl& operator=(const ManagerImpl&) = delete;
-
- ManagerImpl(ManagerImpl&&) noexcept = default;
- ManagerImpl& operator=(ManagerImpl&&) noexcept = default;
-
- static ManagerImpl& instance();
-
- Rows execute(const std::string& query);
- void subscribe(const std::string& table, const Callback& callback);
-
- std::vector<std::string> columns(const std::string& table) noexcept;
-
-private:
- ManagerImpl();
- ~ManagerImpl() noexcept;
-};
-
-} // namespace osquery
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#include <gtest/gtest.h>
-
-#include <osquery_manager.h>
-
-#include <osquery/notification.h>
-#include <osquery/logger.h>
-
-using namespace osquery;
-
-class ManagerTests : public testing::Test {};
-
-TEST_F(ManagerTests, test_manager_execute) {
- std::string query = "SELECT * FROM time";
- auto rows = OsqueryManager::execute(query);
- EXPECT_EQ(rows.size(), 1);
-
- LOG(INFO) << "[Test] time table rows:";
- LOG(INFO) << "\t hour: " << rows[0]["hour"];
- LOG(INFO) << "\t minutes: " << rows[0]["minutes"];
- LOG(INFO) << "\t seconds: " << rows[0]["seconds"];
-}
-
-TEST_F(ManagerTests, test_manager_subscribe) {
- int called = 0;
- auto callback = [&](const Row& row) {
- LOG(INFO) << "NotifyCallback called:";
- for (const auto& r : row)
- LOG(INFO) << "\t" << r.first << " : " << r.second;
- called++;
- };
-
- OsqueryManager::subscribe("manager_test", callback);
-
- Row row;
- row["foo"] = "bar";
- row["foo2"] = "bar2";
- row["foo3"] = "bar3";
-
- /// Notification trigger
- auto s = Notification::instance().emit("manager_test", row);
-
- EXPECT_TRUE(s.ok());
- EXPECT_EQ(called, 1);
-}
-
-TEST_F(ManagerTests, test_manager_columns) {
- auto columns = OsqueryManager::columns("time");
- EXPECT_TRUE(columns.size() > 0);
-
- LOG(INFO) << "[Test] Enabled columns of time table:";
- for (const auto& c : columns)
- LOG(INFO) << "\t" << c;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#include <gtest/gtest.h>
-
-#include <osquery_manager.h>
-
-#include <osquery/logger.h>
-
-#include <policyd/core/policy-manager.h>
-
-using namespace osquery;
-
-class PolicydTests : public testing::Test {};
-
-TEST_F(PolicydTests, select) {
- std::string query = "SELECT * FROM policy";
- auto rows = OsqueryManager::execute(query);
- EXPECT_TRUE(rows.size() > 0);
-
- LOG(INFO) << "[Test] policy table rows:";
- for (auto& r : rows) {
- LOG(INFO) << "\t name: " << r["name"];
- LOG(INFO) << "\t value: " << r["value"];
- }
-
- query = "SELECT * FROM policy WHERE name = 'bluetooth'";
- rows = OsqueryManager::execute(query);
-
- LOG(INFO) << "[Test] policy table rows with where clause:";
- for (auto& r : rows) {
- LOG(INFO) << "\t name: " << r["name"];
- LOG(INFO) << "\t value: " << r["value"];
- }
-
- EXPECT_EQ(rows.size(), 1);
-}
-
-TEST_F(PolicydTests, update) {
- auto& manager = policyd::PolicyManager::Instance();
- manager.enroll("admin", 0);
-
- std::string query = "SELECT * FROM policy WHERE name = 'bluetooth'";
- auto rows = OsqueryManager::execute(query);
- /// Initial policy value
- EXPECT_EQ(rows[0]["value"], std::to_string(1));
-
- query = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
- rows = OsqueryManager::execute(query);
- EXPECT_EQ(rows.size(), 0);
-
- query = "SELECT * FROM policy WHERE name = 'bluetooth'";
- rows = OsqueryManager::execute(query);
- EXPECT_EQ(rows[0]["value"], std::to_string(3));
-
- manager.disenroll("admin", 0);
-}
* @brief Implementation of notification
*/
+#include "notification.h"
+
#include <mutex>
-#include <osquery/notification.h>
#include <osquery/logger.h>
namespace {
std::mutex mutex;
} // anonymous namespace
-namespace osquery {
+namespace vist {
+
+using namespace osquery;
Notification& Notification::instance()
{
return Status(0, "OK");
}
-} // namespace osquery
+} // namespace vist
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+
+/**
+ * @file notification.h
+ * @brief Notify to registered stuffs when event-callback called
+ */
+
+
+#pragma once
+
+#include <map>
+#include <vector>
+
+#include <osquery/status.h>
+
+namespace vist {
+
+using Row = std::map<std::string, std::string>;
+using Rows = std::vector<Row>;
+
+using Callback = std::function<void(const Row&)>;
+
+using NotifyCallback = Callback;
+
+class Notification final {
+public:
+ static Notification& instance();
+
+ Notification(const Notification&) = delete;
+ Notification& operator=(const Notification&) = delete;
+
+ osquery::Status add(const std::string& table, const NotifyCallback& callback);
+ osquery::Status emit(const std::string& table, const Row& result) const;
+
+private:
+ Notification() = default;
+ ~Notification() = default;
+
+ std::multimap<std::string, NotifyCallback> callbacks;
+};
+
+} // namespace vist
#include <gtest/gtest.h>
-#include <osquery/notification.h>
+#include "../notification.h"
#include <osquery/logger.h>
-using namespace osquery;
+using namespace vist;
class NotificationTests : public testing::Test {};
* @brief Implementation of Property
*/
-#include <osquery_manager.h>
#include <property.h>
#include <schema/time.h>
#include <schema/processes.h>
+#include "../service/vist.h"
+
#include <osquery/logger.h>
#include <tsqb.hxx>
} // anonymous namespace
-namespace osquery {
+namespace vist {
template <typename T>
Property<T>::Property()
{
- auto results = OsqueryManager::execute(db.selectAll<T>());
+ auto results = Vist::Query(db.selectAll<T>());
if (results.size() > 0)
this->data = std::move(results[0]);
}
template <typename T>
Properties<T>::Properties()
{
- auto results = OsqueryManager::execute(db.selectAll<T>());
+ auto results = Vist::Query(db.selectAll<T>());
for (auto& r : results)
this->datas.emplace_back(Property<T>(std::move(r)));
}
template std::string Property<Processes>::at(std::string Processes::*) const;
template std::string Property<Processes>::operator[](std::string Processes::*) const;
-} // namespace osquery
+} // namespace vist
#include <schema/processes.h>
using namespace osquery;
+using namespace vist;
class PropertyTests : public testing::Test {};
# See the License for the specific language governing permissions and
# limitations under the License
-ADD_VIST_LIBRARY(vist_daemon vistd.cpp)
+ADD_VIST_LIBRARY(vist_core vist.cpp)
-FILE(GLOB DAEMON_TESTS "tests/*.cpp")
-ADD_VIST_TEST(${DAEMON_TESTS})
+FILE(GLOB CORE_TESTS "tests/*.cpp")
+ADD_VIST_TEST(${CORE_TESTS})
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include <gtest/gtest.h>
+
+#include "../vist.h"
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+
+#include <policyd/core/policy-manager.h>
+
+using namespace vist;
+
+class CoreTests : public testing::Test {};
+
+TEST_F(CoreTests, query_select) {
+ auto rows = Vist::Query("SELECT * FROM policy");
+
+ EXPECT_TRUE(rows.size() > 0);
+
+ std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
+ rows = Vist::Query(statement);
+
+ EXPECT_EQ(rows.size(), 1);
+ EXPECT_EQ(rows[0]["name"], "bluetooth");
+}
+
+TEST_F(CoreTests, query_update) {
+ auto& manager = policyd::PolicyManager::Instance();
+ manager.enroll("admin", 0);
+
+ std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
+ auto rows = Vist::Query(statement);
+ /// Initial policy value
+ EXPECT_EQ(rows[0]["value"], std::to_string(1));
+
+ statement = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
+ rows = Vist::Query(statement);
+ EXPECT_EQ(rows.size(), 0);
+
+ statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
+ rows = Vist::Query(statement);
+ EXPECT_EQ(rows[0]["value"], std::to_string(3));
+
+ manager.disenroll("admin", 0);
+}
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#include <gtest/gtest.h>
-
-#include "../vistd.h"
-#include "ipc/client.h"
-
-#include <chrono>
-#include <thread>
-
-using namespace vist;
-
-class DaemonTests : public testing::Test {};
-
-TEST_F(DaemonTests, query) {
- Vistd vistd;
- auto rows = vistd.query("SELECT * FROM policy");
-
- EXPECT_TRUE(rows.size() > 0);
-}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include "vist.h"
+#include "ipc/server.h"
+
+#include <stdexcept>
+
+#include <osquery/registry.h>
+#include <osquery/sql.h>
+#include <osquery/status.h>
+
+#define QUERY_RET_TYPE std::vector<std::map<std::string, std::string>>
+
+namespace {
+ const std::string SOCK_ADDR = "/tmp/.vist";
+} // anonymous namespace
+
+namespace vist {
+
+Vist::Vist()
+{
+ osquery::registryAndPluginInit();
+}
+
+void Vist::start()
+{
+ auto& server = ipc::Server::Instance(SOCK_ADDR);
+
+ server->expose(this, "", (QUERY_RET_TYPE)(Vist::query)(std::string));
+ server->start();
+}
+
+Rows Vist::query(const std::string& statement)
+{
+ osquery::SQL sql(statement, true);
+ if (!sql.ok())
+ throw std::runtime_error("Faild to execute query: " + sql.getMessageString());
+
+ return std::move(sql.rows());
+}
+
+} // namespace vist
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace vist {
+
+using Row = std::map<std::string, std::string>;
+using Rows = std::vector<Row>;
+
+class Vist final {
+public:
+ Vist(const Vist&) = delete;
+ Vist& operator=(const Vist&) = delete;
+
+ Vist(Vist&&) = default;
+ Vist& operator=(Vist&&) = default;
+
+ /// Exposed method (API)
+ Rows query(const std::string& statement);
+
+ static Vist& Instance()
+ {
+ static Vist instance;
+ return instance;
+ }
+
+ static Rows Query(const std::string& statement)
+ {
+ return Vist::Instance().query(statement);
+ }
+
+ void start();
+
+private:
+ explicit Vist();
+ ~Vist() = default;
+};
+
+} // namespace vist
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#include "vistd.h"
-#include "ipc/server.h"
-
-#include <stdexcept>
-
-#include <osquery/registry.h>
-#include <osquery/sql.h>
-#include <osquery/status.h>
-
-#define QUERY_RET_TYPE std::vector<std::map<std::string, std::string>>
-
-namespace {
- const std::string SOCK_ADDR = "/tmp/.vistd";
-} // anonymous namespace
-
-namespace vist {
-
-Vistd::Vistd()
-{
- osquery::registryAndPluginInit();
-}
-
-void Vistd::start()
-{
- auto& server = ipc::Server::Instance(SOCK_ADDR);
-
- server->expose(this, "", (QUERY_RET_TYPE)(Vistd::query)(std::string));
- server->start();
-}
-
-Rows Vistd::query(const std::string& statement)
-{
- osquery::SQL sql(statement, true);
- if (!sql.ok())
- throw std::runtime_error("Faild to execute query: " + sql.getMessageString());
-
- return std::move(sql.rows());
-}
-
-} // namespace vist
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#pragma once
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace vist {
-
-using Row = std::map<std::string, std::string>;
-using Rows = std::vector<Row>;
-
-class Vistd final {
-public:
- explicit Vistd();
-
- Rows query(const std::string& statement);
- void start();
-};
-
-} // namespace vist