From 92db6036973da786f92634c83a85a5a768bee116 Mon Sep 17 00:00:00 2001 From: Sangwan Kwon Date: Mon, 27 Jul 2020 14:58:55 +0900 Subject: [PATCH] Reorganize directory structure about virtual-table Change-Id: I22a067aa48666157dfe9af37fe370aecc0b18f31 Signed-off-by: Sangwan Kwon --- CMakeLists.txt | 11 + plugins/bluetooth/CMakeLists.txt | 52 ----- plugins/bluetooth/bluetooth-test.cpp | 83 ------- plugins/bluetooth/bluetooth.cpp | 115 ---------- plugins/bluetooth/bluetooth.hpp | 59 ----- plugins/sample/CMakeLists.txt | 31 --- plugins/sample/sample.cpp | 85 ------- plugins/test-util.hpp | 40 ---- plugins/tests.cpp | 22 -- plugins/usb/CMakeLists.txt | 32 --- plugins/usb/usb.cpp | 208 ------------------ plugins/wifi/CMakeLists.txt | 51 ----- plugins/wifi/wifi-test.cpp | 37 ---- plugins/wifi/wifi.cpp | 106 --------- plugins/wifi/wifi.hpp | 60 ----- src/CMakeLists.txt | 8 +- src/vist/service/CMakeLists.txt | 5 +- src/vist/service/vistd.cpp | 6 +- src/vist/table/CMakeLists.txt | 11 +- tables/CMakeLists.txt | 21 ++ .../built-in}/policy-admin.cpp | 0 .../built-in}/policy-admin.hpp | 0 .../policy => tables/built-in}/policy.cpp | 0 .../policy => tables/built-in}/policy.hpp | 0 .../policy/bluetooth/CMakeLists.txt | 2 +- .../policy/bluetooth/policy.cpp | 0 .../policy/bluetooth/policy.hpp | 0 .../policy/bluetooth/table.cpp | 0 .../policy/bluetooth/table.hpp | 0 .../policy/bluetooth/tests/bluetooth.cpp | 0 .../policy/sample/CMakeLists.txt | 0 .../table => tables}/policy/sample/policy.hpp | 0 .../table => tables}/policy/sample/table.cpp | 0 .../table => tables}/policy/sample/table.hpp | 0 34 files changed, 42 insertions(+), 1003 deletions(-) delete mode 100644 plugins/bluetooth/CMakeLists.txt delete mode 100644 plugins/bluetooth/bluetooth-test.cpp delete mode 100644 plugins/bluetooth/bluetooth.cpp delete mode 100644 plugins/bluetooth/bluetooth.hpp delete mode 100644 plugins/sample/CMakeLists.txt delete mode 100644 plugins/sample/sample.cpp delete mode 100644 plugins/test-util.hpp delete mode 100644 plugins/tests.cpp delete mode 100644 plugins/usb/CMakeLists.txt delete mode 100644 plugins/usb/usb.cpp delete mode 100644 plugins/wifi/CMakeLists.txt delete mode 100644 plugins/wifi/wifi-test.cpp delete mode 100644 plugins/wifi/wifi.cpp delete mode 100644 plugins/wifi/wifi.hpp create mode 100644 tables/CMakeLists.txt rename {src/vist/table/policy => tables/built-in}/policy-admin.cpp (100%) rename {src/vist/table/policy => tables/built-in}/policy-admin.hpp (100%) rename {src/vist/table/policy => tables/built-in}/policy.cpp (100%) rename {src/vist/table/policy => tables/built-in}/policy.hpp (100%) rename {src/vist/table => tables}/policy/bluetooth/CMakeLists.txt (96%) rename {src/vist/table => tables}/policy/bluetooth/policy.cpp (100%) rename {src/vist/table => tables}/policy/bluetooth/policy.hpp (100%) rename {src/vist/table => tables}/policy/bluetooth/table.cpp (100%) rename {src/vist/table => tables}/policy/bluetooth/table.hpp (100%) rename {src/vist/table => tables}/policy/bluetooth/tests/bluetooth.cpp (100%) rename {src/vist/table => tables}/policy/sample/CMakeLists.txt (100%) rename {src/vist/table => tables}/policy/sample/policy.hpp (100%) rename {src/vist/table => tables}/policy/sample/table.cpp (100%) rename {src/vist/table => tables}/policy/sample/table.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 995e690..0fd59d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,8 +39,18 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++1z -O2 -DNDEBUG") SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") +SET(VIST_SRCS ${CMAKE_SOURCE_DIR}/src/vist) +SET(VIST_TABLES_SRCS ${CMAKE_SOURCE_DIR}/tables) + +SET(TARGET_OSQUERY_LIB osquery) +SET(TARGET_VIST_CLIENT_LIB vist-client) +SET(TARGET_VIST_COMMON_LIB vist-common) +SET(TARGET_VIST_LIB vist) +SET(TARGET_VIST_POLICY_LIB vist-policy) + ADD_DEFINITIONS("-fPIC") +INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}") INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src") # Suppresse SYSTEM header's warnings: INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_SOURCE_DIR}/src/osquery/include") @@ -50,6 +60,7 @@ ENABLE_TESTING() ADD_SUBDIRECTORY(data) ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(tables) IF(DEFINED GBS_BUILD) ADD_SUBDIRECTORY(systemd) diff --git a/plugins/bluetooth/CMakeLists.txt b/plugins/bluetooth/CMakeLists.txt deleted file mode 100644 index 07a2346..0000000 --- a/plugins/bluetooth/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# 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. -# -SET(TARGET "vist-plugin-bluetooth") -SET(TARGET_TEST ${TARGET}-test) - -SET(PLUGIN_SOURCES "bluetooth.cpp") - -SET(DEPENDENCY bluetooth-api - capi-network-bluetooth) - -PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY}) - -INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS}) - -ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES}) -SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default") -TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES} - vist-common) - -INSTALL(FILES libvist-plugin-bluetooth.so - RENAME bluetooth - DESTINATION ${PLUGIN_INSTALL_DIR}) - -ADD_EXECUTABLE(${TARGET_TEST} ../tests.cpp - bluetooth.cpp - bluetooth-test.cpp) -TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES} - vist-common - vist-client - gtest - pthread) -INSTALL(TARGETS ${TARGET_TEST} - DESTINATION ${CMAKE_INSTALL_BINDIR} - PERMISSIONS OWNER_READ - OWNER_WRITE - OWNER_EXECUTE - GROUP_READ - GROUP_EXECUTE - WORLD_READ - WORLD_EXECUTE) diff --git a/plugins/bluetooth/bluetooth-test.cpp b/plugins/bluetooth/bluetooth-test.cpp deleted file mode 100644 index 1c282a8..0000000 --- a/plugins/bluetooth/bluetooth-test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2019-present 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 "bluetooth.hpp" -#include "../test-util.hpp" - -#include -#include -#include - -#include - -#include - -using namespace vist; - -TEST(BluetoothTests, change_policy_state) -{ - using namespace vist::policy::plugin; - - try { - test::change_policy_state(); - test::change_policy_state(); - test::change_policy_state(); - test::change_policy_state(); - } catch(const vist::Exception& e) { - EXPECT_TRUE(false) << e.what(); - } -} - -TEST(BluetoothTests, get_policies) -{ - auto rows = Query::Execute("SELECT * FROM bluetooth"); - - EXPECT_TRUE(rows.size() == 1); -} - -TEST(BluetoothTests, set_policies) -{ - Query::Execute("INSERT INTO policy_admin (name) VALUES ('vist-plugin-bluetooth-test')"); - - Query::Execute("UPDATE bluetooth SET desktopConnectivity = 3, state = 7"); - Query::Execute("UPDATE bluetooth SET pairing = 2, tethering = 9"); - - auto rows = Query::Execute("SELECT * FROM bluetooth"); - if (rows.size() == 1) { - EXPECT_EQ(rows[0]["state"], "7"); - EXPECT_EQ(rows[0]["desktopConnectivity"], "3"); - EXPECT_EQ(rows[0]["pairing"], "2"); - EXPECT_EQ(rows[0]["tethering"], "9"); - } else { - EXPECT_TRUE(false); - } - - Query::Execute("DELETE FROM policy_admin WHERE name = 'vist-plugin-bluetooth-test'"); -} - -TEST(BluetoothTest, query_builder) -{ - using namespace vist::schema; - - std::string query = BluetoothTable.selectAll(); - EXPECT_EQ(query, "SELECT * FROM bluetooth"); - - query = BluetoothTable.update(Bluetooth::DesktopConnectivity = 3, Bluetooth::State = 7); - EXPECT_EQ(query, "UPDATE bluetooth SET desktopConnectivity = 3, state = 7"); - - query = BluetoothTable.update(Bluetooth::Pairing = 2, Bluetooth::Tethering = 9); - EXPECT_EQ(query, "UPDATE bluetooth SET pairing = 2, tethering = 9"); -} diff --git a/plugins/bluetooth/bluetooth.cpp b/plugins/bluetooth/bluetooth.cpp deleted file mode 100644 index 26b3c41..0000000 --- a/plugins/bluetooth/bluetooth.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 "bluetooth.hpp" - -#include -#include -#include - -#include -#include - -#include - -namespace vist { -namespace policy { -namespace plugin { - -namespace { - -bool failed(auto value) -{ - return value == BLUETOOTH_DPM_RESULT_ACCESS_DENIED || value == BLUETOOTH_DPM_RESULT_FAIL; -} - -auto allowed(int value) -{ - return value ? BLUETOOTH_DPM_ALLOWED : BLUETOOTH_DPM_RESTRICTED; -} - -auto bt_allowed(int value) -{ - return value ? BLUETOOTH_DPM_BT_ALLOWED : BLUETOOTH_DPM_BT_RESTRICTED; -} - -} // anonymous namespace - -void BluetoothState::onChanged(const PolicyValue& value) -{ - auto enable = bt_allowed(value); - auto ret = ::bluetooth_dpm_set_allow_mode(enable); - if (failed(ret)) - THROW(ErrCode::RuntimeError) << "Failed to change bluetooth state: " << ret; - - INFO(VIST_PLUGIN) << "Bluetooth state is changed to " << enable; -} - -void DesktopConnectivity::onChanged(const PolicyValue& value) -{ - auto enable = allowed(value); - auto ret = ::bluetooth_dpm_set_desktop_connectivity_state(enable); - if (failed(ret)) - THROW(ErrCode::RuntimeError) << "Failed to change bt_desktop_connectivity: " << ret; - - INFO(VIST_PLUGIN) << "Bluetooth desktop connectivity state is changed to " << enable; -} - -void Pairing::onChanged(const PolicyValue& value) -{ - auto enable = allowed(value); - auto ret = ::bluetooth_dpm_set_pairing_state(enable); - if (failed(ret)) - THROW(ErrCode::RuntimeError) << "Failed to change bluetooth pairing: " << ret; - - INFO(VIST_PLUGIN) << "Bluetooth pairing state is changed to " << enable; -} - -void Tethering::onChanged(const PolicyValue& value) -{ - auto enable = value; - INFO(VIST_PLUGIN) << "Bluetooth tethering state is changed to " << enable; -} - -Bluetooth::Bluetooth(const std::string& name) : PolicyProvider(name) -{ - if (::bt_initialize() != BT_ERROR_NONE) - THROW(ErrCode::RuntimeError) << "Failed to init bluetooth provider."; -} - -Bluetooth::~Bluetooth() -{ - ::bt_deinitialize(); -} - -// TODO(Sangwan): Add privilege to provider -#define PRIVILEGE "http://tizen.org/privilege/dpm.bluetooth" - -extern "C" PolicyProvider* PolicyFactory() -{ - INFO(VIST_PLUGIN) << "Bluetooth plugin loaded."; - Bluetooth* provider = new Bluetooth("bluetooth"); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - - return provider; -} - -} // namespace plugin -} // namespace policy -} // namespace vist diff --git a/plugins/bluetooth/bluetooth.hpp b/plugins/bluetooth/bluetooth.hpp deleted file mode 100644 index b32bf66..0000000 --- a/plugins/bluetooth/bluetooth.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 -#include -#include - -namespace vist { -namespace policy { -namespace plugin { - -class BluetoothState : public PolicyModel { -public: - BluetoothState() : PolicyModel("bluetooth", PolicyValue(1)) {} - void onChanged(const PolicyValue& value) override; -}; - -class DesktopConnectivity : public PolicyModel { -public: - DesktopConnectivity() : PolicyModel("bluetooth-desktop-connectivity", PolicyValue(1)) {} - void onChanged(const PolicyValue& value) override; -}; - -class Pairing: public PolicyModel { -public: - Pairing() : PolicyModel("bluetooth-pairing", PolicyValue(1)) {} - void onChanged(const PolicyValue& value) override; -}; - -class Tethering: public PolicyModel { -public: - Tethering() : PolicyModel("bluetooth-tethering", PolicyValue(1)) {} - void onChanged(const PolicyValue&); -}; - -class Bluetooth final : public PolicyProvider { -public: - Bluetooth(const std::string& name); - ~Bluetooth(); -}; - -} // namespace plugin -} // namespace policy -} // namespace vist diff --git a/plugins/sample/CMakeLists.txt b/plugins/sample/CMakeLists.txt deleted file mode 100644 index 439fa43..0000000 --- a/plugins/sample/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# 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. -# -SET(TARGET "vist-plugin-sample") - -INCLUDE_DIRECTORIES(SYSTEM) - -ADD_LIBRARY(${TARGET} SHARED sample.cpp) -SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default") -TARGET_LINK_LIBRARIES(${TARGET} vist-common) - -IF(DEFINED GBS_BUILD) - INSTALL(FILES libvist-plugin-sample.so - RENAME sample - DESTINATION ${PLUGIN_INSTALL_DIR}) -ELSE(DEFINED GBS_BUILD) - INSTALL(TARGETS ${TARGET} - RENAME sample - DESTINATION ${PLUGIN_INSTALL_DIR}) -ENDIF(DEFINED GBS_BUILD) diff --git a/plugins/sample/sample.cpp b/plugins/sample/sample.cpp deleted file mode 100644 index 5327fb1..0000000 --- a/plugins/sample/sample.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 -#include -#include - -#include - -#include -#include - -using namespace vist; -using namespace vist::policy; - -class SampleIntPolicy : public PolicyModel { -public: - SampleIntPolicy() : PolicyModel("sample-int-policy", PolicyValue(7)) - { - } - - void onChanged(const PolicyValue& value) override - { - INFO(VIST_PLUGIN) << "sample-int-policy is changed to " - << static_cast(value); - } -}; - -class SampleStrPolicy : public PolicyModel { -public: - SampleStrPolicy() : PolicyModel("sample-str-policy", PolicyValue("TEST")) - { - } - - void onChanged(const PolicyValue& value) override - { - INFO(VIST_PLUGIN) << "sample-str-policy is changed to " - << static_cast(value); - } - - int compare(const PolicyValue& lhs, const PolicyValue& rhs) const override - { - std::string lvalue = lhs; - std::string rvalue = rhs; - - INFO(VIST_PLUGIN) << "Custom compare method is called with [" << lvalue - << "], [" << rvalue << "]"; - - return lvalue.compare(rvalue); - } -}; - -class Sample : public PolicyProvider { -public: - Sample(const std::string& name) : PolicyProvider(name) - { - } - - ~Sample() - { - } -}; - -extern "C" PolicyProvider* PolicyFactory() -{ - INFO(VIST_PLUGIN) << "Sample plugin loaded."; - Sample* provider = new Sample("sample"); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - - return provider; -} diff --git a/plugins/test-util.hpp b/plugins/test-util.hpp deleted file mode 100644 index 06a278e..0000000 --- a/plugins/test-util.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 -#include - -#include - -namespace vist { -namespace test { - -using namespace vist::policy; - -template -void change_policy_state() -{ - std::shared_ptr policy = std::make_shared(); - /// enable policy - policy->onChanged(PolicyValue(1)); - /// disable policy - policy->onChanged(PolicyValue(0)); -} - -} // namespace test -} // namespace vist diff --git a/plugins/tests.cpp b/plugins/tests.cpp deleted file mode 100644 index 0fcfc89..0000000 --- a/plugins/tests.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 - -int main(int argc, char* argv[]) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/plugins/usb/CMakeLists.txt b/plugins/usb/CMakeLists.txt deleted file mode 100644 index cfc1c3f..0000000 --- a/plugins/usb/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# 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. -# -SET(TARGET "dpm-plugin-usb") - -SET(PLUGIN_SOURCES "usb.cpp") - -SET(DEPENDENCY klay) - -PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY}) - -SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") - -ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES}) -SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default") -INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS}) -TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES}) - -INSTALL(FILES libdpm-plugin-usb.so - RENAME usb - DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/plugins/usb/usb.cpp b/plugins/usb/usb.cpp deleted file mode 100644 index 82dac70..0000000 --- a/plugins/usb/usb.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "../dlog.h" - -#define DEVICED_SYSNOTI_INTERFACE \ - "org.tizen.system.deviced", \ - "/Org/Tizen/System/DeviceD/SysNoti", \ - "org.tizen.system.deviced.SysNoti", \ - "control" - -class DebuggingMode : public GlobalPolicy { -public: - DebuggingMode() : GlobalPolicy("usb-debugging") - { - PolicyEventNotifier::create("usb_debugging"); - } - - bool apply(const DataType& value) - { - int enable = value; - PolicyEventNotifier::emit("usb_debugging", enable ? "allowed" : "disallowed"); - return true; - } -}; - -class Tethering : public GlobalPolicy { -public: - Tethering() : GlobalPolicy("usb-tethering") - { - PolicyEventNotifier::create("usb_tethering"); - } - - bool apply(const DataType& value) - { - int enable = value; - PolicyEventNotifier::emit("usb_tethering", enable ? "allowed" : "disallowed"); - return true; - } -}; - -class Client : public GlobalPolicy { -public: - Client() : GlobalPolicy("usb-client") - { - PolicyEventNotifier::create("usb_client"); - sendDbusSignal(); - } - - bool apply(const DataType& value) - { - int ret; - int enable = value; - - try { - std::string pid(std::to_string(::getpid())); - std::string state(std::to_string(enable)); - dbus::Connection &systemDBus = dbus::Connection::getSystem(); - systemDBus.methodcall(DEVICED_SYSNOTI_INTERFACE, - -1, "(i)", "(sisss)", - "control", 3, pid.c_str(), "1", state.c_str()).get("(i)", &ret); - } catch(runtime::Exception& e) { - ERROR(PLUGINS, "Failed to enforce usb client"); - return false; - } - - if (ret == 0) { - PolicyEventNotifier::emit("usb_client", enable ? "allowed" : "disallowed"); - return true; - } - - return false; - } - - void sendDbusSignal(void) - { - int ret; - int enable = get().value; - - try { - std::string pid(std::to_string(::getpid())); - std::string state(std::to_string(enable)); - dbus::Connection &systemDBus = dbus::Connection::getSystem(); - systemDBus.methodcall(DEVICED_SYSNOTI_INTERFACE, - -1, "(i)", "(sisss)", - "control", 3, pid.c_str(), "1", state.c_str()).get("(i)", &ret); - } catch(runtime::Exception& e) { - ERROR(PLUGINS, "Failed to enforce usb client"); - } - } -}; - -class Usb : public AbstractPolicyProvider { -public: - int setDebuggingState(bool enable); - bool getDebuggingState(); - - int setTetheringState(bool enable); - bool getTetheringState(); - - int setClientState(bool enable); - bool getClientState(); - -private: - DebuggingMode debugging; - Tethering tethering; - Client client; -}; - -int Usb::setDebuggingState(bool enable) -{ - try { - debugging.set(enable); - } catch (runtime::Exception& e) { - ERROR(PLUGINS, e.what()); - return -1; - } - - return 0; -} - -bool Usb::getDebuggingState() -{ - return debugging.get(); -} - -int Usb::setTetheringState(bool enable) -{ - try { - tethering.set(enable); - } catch (runtime::Exception& e) { - ERROR(PLUGINS, e.what()); - return -1; - } - - return 0; -} - -bool Usb::getTetheringState() -{ - return tethering.get(); -} - -int Usb::setClientState(bool enable) -{ - try { - client.set(enable); - } catch (runtime::Exception& e) { - ERROR(PLUGINS, e.what()); - return -1; - } - - return 0; -} - -bool Usb::getClientState() -{ - return client.get(); -} - -extern "C" { - -#define PRIVILEGE_USB "http://tizen.org/privilege/dpm.usb" -#define PRIVILEGE_DEBUGGING "http://tizen.org/privilege/dpm.debugging" - -AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context) -{ - INFO(PLUGINS, "Usb plugin loaded"); - Usb *policy = new Usb(); - - context.expose(policy, PRIVILEGE_DEBUGGING, (int)(Usb::setDebuggingState)(bool)); - context.expose(policy, PRIVILEGE_USB, (int)(Usb::setTetheringState)(bool)); - context.expose(policy, PRIVILEGE_USB, (int)(Usb::setClientState)(bool)); - - context.expose(policy, "", (bool)(Usb::getDebuggingState)()); - context.expose(policy, "", (bool)(Usb::getTetheringState)()); - context.expose(policy, "", (bool)(Usb::getClientState)()); - - return policy; -} - -} // extern "C" diff --git a/plugins/wifi/CMakeLists.txt b/plugins/wifi/CMakeLists.txt deleted file mode 100644 index 4a70348..0000000 --- a/plugins/wifi/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# 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. -# -SET(TARGET "vist-plugin-wifi") -SET(TARGET_TEST ${TARGET}-test) - -SET(PLUGIN_SOURCES "wifi.cpp") - -SET(DEPENDENCY klay - capi-network-wifi-manager - capi-network-connection) - -PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY}) - -INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS}) - -ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES}) -SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default") -TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES} - vist-common) -INSTALL(FILES libvist-plugin-wifi.so - RENAME wifi - DESTINATION ${PLUGIN_INSTALL_DIR}) - -ADD_EXECUTABLE(${TARGET_TEST} ../tests.cpp - wifi.cpp - wifi-test.cpp) -TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES} - vist-common - gtest - pthread) -INSTALL(TARGETS ${TARGET_TEST} - DESTINATION ${CMAKE_INSTALL_BINDIR} - PERMISSIONS OWNER_READ - OWNER_WRITE - OWNER_EXECUTE - GROUP_READ - GROUP_EXECUTE - WORLD_READ - WORLD_EXECUTE) diff --git a/plugins/wifi/wifi-test.cpp b/plugins/wifi/wifi-test.cpp deleted file mode 100644 index ca048fd..0000000 --- a/plugins/wifi/wifi-test.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 "wifi.hpp" -#include "../test-util.hpp" - -#include - -#include - -using namespace vist; -using namespace vist::policy::plugin; - -TEST(WifiTests, change_policy_state) -{ - try { - test::change_policy_state(); - test::change_policy_state(); - test::change_policy_state(); - test::change_policy_state(); - } catch(const vist::Exception& e) { - EXPECT_TRUE(false) << e.what(); - } -} diff --git a/plugins/wifi/wifi.cpp b/plugins/wifi/wifi.cpp deleted file mode 100644 index cb169d4..0000000 --- a/plugins/wifi/wifi.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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 "wifi.hpp" - -#include -#include - -#include - -#include - -#define NETCONFIG_INTERFACE \ - "net.netconfig", \ - "/net/netconfig/network", \ - "net.netconfig.network" - -namespace vist { -namespace policy { -namespace plugin { - -void WifiState::onChanged(const PolicyValue& value) -{ - int enable = value; - INFO(VIST_PLUGIN) << "Wifi state is changed to " << enable; - klay::dbus::Connection &systemDBus = klay::dbus::Connection::getSystem(); - systemDBus.methodcall(NETCONFIG_INTERFACE, - "DevicePolicySetWifi", - -1, - "", - "(i)", - enable); -} - -void ProfileChange::onChanged(const PolicyValue& value) -{ - int enable = value; - INFO(VIST_PLUGIN) << "Wifi profile change state is changed to " << enable; - dbus::Connection &systemDBus = dbus::Connection::getSystem(); - systemDBus.methodcall(NETCONFIG_INTERFACE, - "DevicePolicySetWifiProfile", - -1, - "", - "(i)", - enable); -} - -void Hotspot::onChanged(const PolicyValue& value) -{ - int enable = value; - INFO(VIST_PLUGIN) << "Wifi hotspot change state is changed to " << enable; -} - -void SsidRestriction::onChanged(const PolicyValue& value) -{ - int enable = value; - INFO(VIST_PLUGIN) << "Wifi ssid restriction change state is changed to " << enable; -} - -Wifi::Wifi(const std::string& name) : PolicyProvider(name) -{ - int ret = ::wifi_manager_initialize(&handle); - if (ret != WIFI_MANAGER_ERROR_NONE) { - if (ret == WIFI_MANAGER_ERROR_NOT_SUPPORTED) - ERROR("Wifi manager is not supported."); - - THROW(ErrCode::RuntimeError) << "Failed to init WiFi Manager."; - } -} - -Wifi::~Wifi() -{ - ::wifi_manager_deinitialize(handle); -} - -// TODO(Sangwan): Add privilege to provider -#define PRIVILEGE "http://tizen.org/privilege/dpm.wifi" - -extern "C" PolicyProvider* PolicyFactory() -{ - INFO(VIST_PLUGIN) << "Wifi plugin loaded."; - Wifi* provider = new Wifi("wifi"); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - provider->add(std::make_shared()); - - return provider; -} - -} // namespace plugin -} // namespace policy -} // namespace vist diff --git a/plugins/wifi/wifi.hpp b/plugins/wifi/wifi.hpp deleted file mode 100644 index b076cbb..0000000 --- a/plugins/wifi/wifi.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 -#include -#include - -#include - -namespace vist { -namespace policy { -namespace plugin { - -struct WifiState : public PolicyModel { - WifiState() : PolicyModel("wifi", PolicyValue(1)) {} - void onChanged(const PolicyValue& value) override; -}; - -struct ProfileChange : public PolicyModel { - ProfileChange() : PolicyModel("wifi-profile-change", PolicyValue(1)) {} - void onChanged(const PolicyValue& value) override; -}; - -struct Hotspot : public PolicyModel { - Hotspot() : PolicyModel("wifi-hotspot", PolicyValue(1)) {} - void onChanged(const PolicyValue& value) override; -}; - -struct SsidRestriction : public PolicyModel { - SsidRestriction() : PolicyModel("wifi-ssid-restriction", PolicyValue(0)) {} - void onChanged(const PolicyValue& value) override; -}; - -class Wifi final : public PolicyProvider { -public: - Wifi(const std::string& name); - ~Wifi(); - -private: - ::wifi_manager_h handle = nullptr; -}; - -} // namespace plugin -} // namespace policy -} // namespace vist diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8168b5..43477b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2019-present 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. @@ -12,11 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License -SET(TARGET_OSQUERY_LIB osquery) -SET(TARGET_VIST_CLIENT_LIB vist-client) -SET(TARGET_VIST_COMMON_LIB vist-common) -SET(TARGET_VIST_LIB vist) -SET(TARGET_VIST_POLICY_LIB vist-policy) - ADD_SUBDIRECTORY(osquery) ADD_SUBDIRECTORY(vist) diff --git a/src/vist/service/CMakeLists.txt b/src/vist/service/CMakeLists.txt index 983e1d2..b11ed24 100644 --- a/src/vist/service/CMakeLists.txt +++ b/src/vist/service/CMakeLists.txt @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License -ADD_VIST_LIBRARY(vist_core vistd.cpp) +ADD_VIST_LIBRARY(vist_core vistd.cpp + ${VIST_TABLES_SRCS}/built-in/policy-admin.cpp + ${VIST_TABLES_SRCS}/built-in/policy.cpp) + FILE(GLOB CORE_TESTS "tests/*.cpp") ADD_VIST_TEST(${CORE_TESTS}) diff --git a/src/vist/service/vistd.cpp b/src/vist/service/vistd.cpp index c2fffbb..f3a7fdd 100644 --- a/src/vist/service/vistd.cpp +++ b/src/vist/service/vistd.cpp @@ -22,10 +22,10 @@ #include #include #include - #include -#include -#include + +#include +#include #include #include diff --git a/src/vist/table/CMakeLists.txt b/src/vist/table/CMakeLists.txt index e17acc0..354515a 100644 --- a/src/vist/table/CMakeLists.txt +++ b/src/vist/table/CMakeLists.txt @@ -13,13 +13,4 @@ # limitations under the License ## static virtual table -ADD_VIST_LIBRARY(vist_table util.cpp - policy/policy-admin.cpp - policy/policy.cpp) - -## dynamic virtual table -ADD_SUBDIRECTORY(policy/sample) - -IF(DEFINED GBS_BUILD) - ADD_SUBDIRECTORY(policy/bluetooth) -ENDIF(DEFINED GBS_BUILD) +ADD_VIST_LIBRARY(vist_table util.cpp) diff --git a/tables/CMakeLists.txt b/tables/CMakeLists.txt new file mode 100644 index 0000000..7430534 --- /dev/null +++ b/tables/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2020-present 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_SUBDIRECTORY(policy/sample) + +IF(DEFINED GBS_BUILD) + ADD_SUBDIRECTORY(policy/bluetooth) +ENDIF(DEFINED GBS_BUILD) + +# TODO: Add built-in table's TC diff --git a/src/vist/table/policy/policy-admin.cpp b/tables/built-in/policy-admin.cpp similarity index 100% rename from src/vist/table/policy/policy-admin.cpp rename to tables/built-in/policy-admin.cpp diff --git a/src/vist/table/policy/policy-admin.hpp b/tables/built-in/policy-admin.hpp similarity index 100% rename from src/vist/table/policy/policy-admin.hpp rename to tables/built-in/policy-admin.hpp diff --git a/src/vist/table/policy/policy.cpp b/tables/built-in/policy.cpp similarity index 100% rename from src/vist/table/policy/policy.cpp rename to tables/built-in/policy.cpp diff --git a/src/vist/table/policy/policy.hpp b/tables/built-in/policy.hpp similarity index 100% rename from src/vist/table/policy/policy.hpp rename to tables/built-in/policy.hpp diff --git a/src/vist/table/policy/bluetooth/CMakeLists.txt b/tables/policy/bluetooth/CMakeLists.txt similarity index 96% rename from src/vist/table/policy/bluetooth/CMakeLists.txt rename to tables/policy/bluetooth/CMakeLists.txt index 6f63912..d5685bc 100644 --- a/src/vist/table/policy/bluetooth/CMakeLists.txt +++ b/tables/policy/bluetooth/CMakeLists.txt @@ -31,7 +31,7 @@ TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES} INSTALL(TARGETS ${TARGET} DESTINATION ${TABLE_INSTALL_DIR}) ## TEST ############################################# -ADD_EXECUTABLE(${TARGET_TEST} ../../../main/tests.cpp +ADD_EXECUTABLE(${TARGET_TEST} ${VIST_SRCS}/main/tests.cpp policy.cpp table.cpp tests/bluetooth.cpp) diff --git a/src/vist/table/policy/bluetooth/policy.cpp b/tables/policy/bluetooth/policy.cpp similarity index 100% rename from src/vist/table/policy/bluetooth/policy.cpp rename to tables/policy/bluetooth/policy.cpp diff --git a/src/vist/table/policy/bluetooth/policy.hpp b/tables/policy/bluetooth/policy.hpp similarity index 100% rename from src/vist/table/policy/bluetooth/policy.hpp rename to tables/policy/bluetooth/policy.hpp diff --git a/src/vist/table/policy/bluetooth/table.cpp b/tables/policy/bluetooth/table.cpp similarity index 100% rename from src/vist/table/policy/bluetooth/table.cpp rename to tables/policy/bluetooth/table.cpp diff --git a/src/vist/table/policy/bluetooth/table.hpp b/tables/policy/bluetooth/table.hpp similarity index 100% rename from src/vist/table/policy/bluetooth/table.hpp rename to tables/policy/bluetooth/table.hpp diff --git a/src/vist/table/policy/bluetooth/tests/bluetooth.cpp b/tables/policy/bluetooth/tests/bluetooth.cpp similarity index 100% rename from src/vist/table/policy/bluetooth/tests/bluetooth.cpp rename to tables/policy/bluetooth/tests/bluetooth.cpp diff --git a/src/vist/table/policy/sample/CMakeLists.txt b/tables/policy/sample/CMakeLists.txt similarity index 100% rename from src/vist/table/policy/sample/CMakeLists.txt rename to tables/policy/sample/CMakeLists.txt diff --git a/src/vist/table/policy/sample/policy.hpp b/tables/policy/sample/policy.hpp similarity index 100% rename from src/vist/table/policy/sample/policy.hpp rename to tables/policy/sample/policy.hpp diff --git a/src/vist/table/policy/sample/table.cpp b/tables/policy/sample/table.cpp similarity index 100% rename from src/vist/table/policy/sample/table.cpp rename to tables/policy/sample/table.cpp diff --git a/src/vist/table/policy/sample/table.hpp b/tables/policy/sample/table.hpp similarity index 100% rename from src/vist/table/policy/sample/table.hpp rename to tables/policy/sample/table.hpp -- 2.34.1