%package plugins
Summary: Virtaul Security Table (policy modules)
Group: Security/Other
-## Common
-BuildRequires: pkgconfig(buxton2)
-BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(capi-system-info)
-BuildRequires: pkgconfig(capi-base-common)
-BuildRequires: pkgconfig(klay)
-
## Bluetooth
BuildRequires: pkgconfig(bluetooth-api)
BuildRequires: pkgconfig(capi-network-bluetooth)
## Wifi
+BuildRequires: pkgconfig(klay)
BuildRequires: pkgconfig(capi-network-wifi-manager)
BuildRequires: pkgconfig(capi-network-connection)
Requires: klay
%manifest packaging/%{name}-plugins.manifest
%{vist_plugin_dir}/bluetooth
%{vist_plugin_dir}/wifi
+%{_bindir}/vist-plugin-bluetooth-test
+%{_bindir}/vist-plugin-wifi-test
# 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
- klay)
+ capi-network-bluetooth)
PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES})
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES})
+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
+ 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)
--- /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 "bluetooth.hpp"
+#include "../test-util.hpp"
+
+#include <vist/exception.hpp>
+
+#include <gtest/gtest.h>
+
+using namespace vist;
+using namespace vist::policy::plugin;
+
+TEST(BluetoothTests, change_policy_state)
+{
+ try {
+ test::change_policy_state<BluetoothState>();
+ test::change_policy_state<DesktopConnectivity>();
+ test::change_policy_state<Pairing>();
+ test::change_policy_state<Tethering>();
+ } catch(const vist::Exception<ErrCode>& e) {
+ EXPECT_TRUE(false) << e.what();
+ }
+}
* limitations under the License
*/
+#include "bluetooth.hpp"
+
#include <bluetooth.h>
#include <bluetooth-api.h>
#include <bluetooth_internal.h>
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-provider.hpp>
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
#include <memory>
-#include "../dlog.h"
-
-#define BT_FAILED(ret) \
- (((int)(ret) == BLUETOOTH_DPM_RESULT_ACCESS_DENIED) || \
- ((int)(ret) == BLUETOOTH_DPM_RESULT_FAIL))
-
-#define POLICY_IS_ALLOWED(enable) \
- ((int)(enable) ? BLUETOOTH_DPM_ALLOWED : \
- BLUETOOTH_DPM_RESTRICTED)
-
-#define STATE_CHANGE_IS_ALLOWED(enable) \
- ((int)(enable) ? BLUETOOTH_DPM_BT_ALLOWED : \
- BLUETOOTH_DPM_BT_RESTRICTED)
-
-using namespace vist::policy;
-
-class ModeChange : public PolicyModel {
-public:
- ModeChange() : PolicyModel("bluetooth", PolicyValue(1)) {}
-
- void onChanged(const PolicyValue& value) override
- {
- int ret = ::bluetooth_dpm_set_allow_mode(STATE_CHANGE_IS_ALLOWED(value));
- if (BT_FAILED(ret))
- throw std::runtime_error("Failed to set bluetooth.");
- }
-};
-
-class DesktopConnectivity : public PolicyModel {
-public:
- DesktopConnectivity() :
- PolicyModel("bluetooth-desktop-connectivity", PolicyValue(1)) {}
-
- void onChanged(const PolicyValue& value) override
- {
- int ret = ::bluetooth_dpm_set_desktop_connectivity_state(POLICY_IS_ALLOWED(value));
- if (BT_FAILED(ret))
- throw std::runtime_error("Failed to set bt_desktop_connectivity.");
- }
-};
-
-class Pairing: public PolicyModel {
-public:
- Pairing() : PolicyModel("bluetooth-pairing", PolicyValue(1)) {}
-
- void onChanged(const PolicyValue& value) override
- {
- int ret = ::bluetooth_dpm_set_pairing_state(POLICY_IS_ALLOWED(value));
- if (BT_FAILED(ret))
- throw std::runtime_error("Failed to set bt_pairing.");
- }
-};
-
-class Tethering: public PolicyModel {
-public:
- Tethering() : PolicyModel("bluetooth-tethering", PolicyValue(1)) {}
-
- void onChanged(const PolicyValue&) {}
-};
-
-class Bluetooth : public PolicyProvider {
-public:
- Bluetooth(const std::string& name) : PolicyProvider(name)
- {
- if (::bt_initialize() != BT_ERROR_NONE)
- ERROR(PLUGINS,"Bluetooth framework was not initilaized");
- }
-
- ~Bluetooth()
- {
- ::bt_deinitialize();
- }
-};
+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(PLUGINS, "Bluetooth plugin loaded.");
+ INFO(VIST_PLUGIN) << "Bluetooth plugin loaded.";
Bluetooth* provider = new Bluetooth("bluetooth");
- provider->add(std::make_shared<ModeChange>());
+ provider->add(std::make_shared<BluetoothState>());
provider->add(std::make_shared<DesktopConnectivity>());
provider->add(std::make_shared<Pairing>());
provider->add(std::make_shared<Tethering>());
return provider;
}
+
+} // namespace plugin
+} // namespace policy
+} // 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 <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-provider.hpp>
+#include <vist/sdk/policy-value.hpp>
+
+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
+++ /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 DLogied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#pragma once
-
-#include <klay/audit/logger.h>
-#include <klay/audit/dlog-sink.h>
-
-#define PLUGINS osquery::DLog::getSink()
-
-namespace osquery {
-
-class DLog final {
-public:
- DLog(const DLog&) = delete;
- DLog& operator=(const DLog&) = delete;
-
- DLog(DLog&&) noexcept = default;
- DLog& operator=(DLog&&) noexcept = default;
-
- static inline DLog& instance()
- {
- static DLog dlog;
- return dlog;
- }
-
- static inline audit::LogSink* getSink()
- {
- return DLog::instance().logSink.get();
- }
-
-private:
- DLog()
- {
- auto dlog = new audit::DlogLogSink("VIST_PLUGIN");
- this->logSink.reset(dynamic_cast<audit::LogSink*>(dlog));
- }
- ~DLog() noexcept = default;
-
- std::unique_ptr<audit::LogSink> logSink;
-};
-
-} // 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
+ */
+
+#pragma once
+
+#include <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-value.hpp>
+
+#include <memory>
+
+namespace vist {
+namespace test {
+
+using namespace vist::policy;
+
+template <typename T>
+void change_policy_state()
+{
+ std::shared_ptr<PolicyModel> policy = std::make_shared<T>();
+ /// enable policy
+ policy->onChanged(PolicyValue(1));
+ /// disable policy
+ policy->onChanged(PolicyValue(0));
+}
+
+} // namespace test
+} // 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 <gtest/gtest.h>
+
+int main(int argc, char* argv[]) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
# limitations under the License.
#
SET(TARGET "vist-plugin-wifi")
+SET(TARGET_TEST ${TARGET}-test)
SET(PLUGIN_SOURCES "wifi.cpp")
ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES})
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES})
-
+TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES}
+ vist-common)
INSTALL(FILES libvist-plugin-wifi.so
- RENAME wifi
- DESTINATION ${PLUGIN_INSTALL_DIR})
+ 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)
--- /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 "wifi.hpp"
+#include "../test-util.hpp"
+
+#include <vist/exception.hpp>
+
+#include <gtest/gtest.h>
+
+using namespace vist;
+using namespace vist::policy::plugin;
+
+TEST(WifiTests, change_policy_state)
+{
+ try {
+ test::change_policy_state<WifiState>();
+ test::change_policy_state<ProfileChange>();
+ test::change_policy_state<Hotspot>();
+ test::change_policy_state<SsidRestriction>();
+ } catch(const vist::Exception<ErrCode>& e) {
+ EXPECT_TRUE(false) << e.what();
+ }
+}
* limitations under the License
*/
-#include <arpa/inet.h>
-#include <wifi-manager.h>
+#include "wifi.hpp"
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-provider.hpp>
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
#include <klay/dbus/connection.h>
#include <memory>
-#include "../dlog.h"
-
#define NETCONFIG_INTERFACE \
"net.netconfig", \
"/net/netconfig/network", \
"net.netconfig.network"
-using namespace vist::policy;
-
-class ModeChange : public PolicyModel {
-public:
- ModeChange() : PolicyModel("wifi", PolicyValue(1)) {}
-
- void onChanged(const PolicyValue& value) override
- {
- int enable = value;
- klay::dbus::Connection &systemDBus = klay::dbus::Connection::getSystem();
- systemDBus.methodcall(NETCONFIG_INTERFACE,
- "DevicePolicySetWifi",
- -1,
- "",
- "(i)",
- enable);
- }
-};
-
-class ProfileChange : public PolicyModel {
-public:
- ProfileChange() : PolicyModel("wifi-profile-change", PolicyValue(1)) {}
-
- void onChanged(const PolicyValue& value) override
- {
- int enable = value;
- dbus::Connection &systemDBus = dbus::Connection::getSystem();
- systemDBus.methodcall(NETCONFIG_INTERFACE,
- "DevicePolicySetWifiProfile",
- -1,
- "",
- "(i)",
- enable);
- }
-};
+namespace vist {
+namespace policy {
+namespace plugin {
-class Hotspot : public PolicyModel {
-public:
- Hotspot() : PolicyModel("wifi-hotspot", PolicyValue(1)) {}
+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 onChanged(const PolicyValue&) override
- {
- /// N/A
- }
-};
+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);
+}
-class SsidRestriction : public PolicyModel {
-public:
- SsidRestriction() : PolicyModel("wifi-ssid-restriction", PolicyValue(0)) {}
+void Hotspot::onChanged(const PolicyValue& value)
+{
+ int enable = value;
+ INFO(VIST_PLUGIN) << "Wifi hotspot change state is changed to " << enable;
+}
- void onChanged(const PolicyValue&) override
- {
- /// N/A
- }
-};
-
-class Wifi : public PolicyProvider {
-public:
- 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)
- return;
-
- throw std::runtime_error("WiFi Manager initialization failed.");
- }
- }
+void SsidRestriction::onChanged(const PolicyValue& value)
+{
+ int enable = value;
+ INFO(VIST_PLUGIN) << "Wifi ssid restriction change state is changed to " << enable;
+}
- ~Wifi()
- {
- if (handle == nullptr)
- return;
+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.");
- ::wifi_manager_deinitialize(handle);
+ THROW(ErrCode::RuntimeError) << "Failed to init WiFi Manager.";
}
+}
-private:
- ::wifi_manager_h handle = nullptr;
-};
+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(PLUGINS, "Wifi plugin loaded.");
+ INFO(VIST_PLUGIN) << "Wifi plugin loaded.";
Wifi* provider = new Wifi("wifi");
- provider->add(std::make_shared<ModeChange>());
+ provider->add(std::make_shared<WifiState>());
provider->add(std::make_shared<ProfileChange>());
provider->add(std::make_shared<Hotspot>());
provider->add(std::make_shared<SsidRestriction>());
return provider;
}
+
+} // namespace plugin
+} // namespace policy
+} // 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 <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-provider.hpp>
+#include <vist/sdk/policy-value.hpp>
+
+#include <wifi-manager.h>
+
+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
#include <osquery/tables.h>
#include <vist/policy/api.hpp>
+#include <vist/exception.hpp>
#include <vist/logger.hpp>
namespace osquery {
namespace tables {
+using namespace vist;
+
QueryData genPolicy(QueryContext& context) try {
INFO(VIST) << "Select query about policy table.";
}
return results;
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
} catch (...) {
- ERROR(VIST) << "Failed to select query on policy.";
+ ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
Row r;
r["status"] = "success";
return { r };
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
} catch (...) {
- ERROR(VIST) << "Failed to update query on policy.";
+ ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
#include <osquery/tables.h>
#include <vist/policy/api.hpp>
+#include <vist/exception.hpp>
#include <vist/logger.hpp>
+namespace osquery {
+
namespace {
std::string getValue(std::string&& alias, const std::string& key)
} // anonymous namespace
-namespace osquery {
namespace tables {
+using namespace vist;
+
QueryData genPolicyAdmin(QueryContext& context) try {
INFO(VIST) << "Select query about policy-admin table.";
}
return results;
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
} catch (...) {
- ERROR(VIST) << "Failed to select query on policy-admin.";
+ ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
Row r;
r["status"] = "success";
return { r };
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
} catch (...) {
- ERROR(VIST) << "Failed to insert query on policy-admin.";
+ ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
Row r;
r["status"] = "success";
return { r };
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
} catch (...) {
- ERROR(VIST) << "Failed to delete query on policy-admin.";
+ ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
Row r;
r["status"] = "success";
return { r };
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
} catch (...) {
- ERROR(VIST) << "Failed to insert query on policy-admin.";
+ ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
+
} // namespace tables
} // namespace osquery
#pragma once
+#include <vist/exception.hpp>
+
#include <map>
#include <string>
#include <vector>
inline std::size_t size() const { return rows.size(); }
template<typename Struct, typename Member>
- VirtualRow<T>& filter(Member Struct::*field, const std::string& value)
+ VirtualRow<T>& filter(Member Struct::*field, const std::string& name)
{
for (auto& row : this->rows)
- if (row[field] == value)
+ if (row[field] == name)
return row;
+
+ THROW(ErrCode::RuntimeError) << "Not exist field: " << name;
}
private: