%files test
%{_bindir}/osquery-test
%{_bindir}/vist-test
+%{vist_plugin_dir}/sample
## ViST Plugins - ###########################################################
%package plugins
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
+ADD_SUBDIRECTORY(sample)
+
ADD_SUBDIRECTORY(bluetooth)
ADD_SUBDIRECTORY(wifi)
#ADD_SUBDIRECTORY(usb)
--- /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.
+#
+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)
+
+INSTALL(FILES libvist-plugin-sample.so
+ RENAME sample
+ DESTINATION ${PLUGIN_INSTALL_DIR})
--- /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/sdk/policy-model.hpp>
+#include <vist/sdk/policy-value.hpp>
+#include <vist/sdk/policy-provider.hpp>
+
+#include <vist/logger.hpp>
+
+#include <memory>
+#include <string>
+
+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<int>(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<std::string>(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<SampleIntPolicy>());
+ provider->add(std::make_shared<SampleStrPolicy>());
+
+ return provider;
+}
this->syncPolicyActivated();
}
-/// TODO(sangwan.kwon) Re-design strictest logic
-/// PolicyValue PolicyStorage::strictest(const PolicyValue& policy)
PolicyValue PolicyStorage::strictest(const std::shared_ptr<PolicyModel>& policy)
{
if (this->definitions.find(policy->getName()) == this->definitions.end())
EXPECT_TRUE(manager.policies.size() > 0);
}
-TEST(PolicyCoreTests, policy_set_get) {
+TEST(PolicyCoreTests, policy_set_get_int) {
auto& manager = PolicyManager::Instance();
manager.enroll("testAdmin");
- manager.set("bluetooth", PolicyValue(5), "testAdmin");
+ manager.set("sample-int-policy", PolicyValue(5), "testAdmin");
- auto policy = manager.get("bluetooth");
+ auto policy = manager.get("sample-int-policy");
EXPECT_EQ(static_cast<int>(policy), 5);
manager.enroll("testAdmin1");
- manager.set("bluetooth", PolicyValue(10), "testAdmin1");
+ manager.set("sample-int-policy", PolicyValue(10), "testAdmin1");
/// Manager should return the strongest policy.
- policy = manager.get("bluetooth");
+ policy = manager.get("sample-int-policy");
EXPECT_EQ(static_cast<int>(policy), 10);
manager.disenroll("testAdmin");
manager.disenroll("testAdmin1");
}
+TEST(PolicyCoreTests, policy_set_get_str) {
+ auto& manager = PolicyManager::Instance();
+ manager.enroll("testAdmin");
+ manager.set("sample-str-policy", PolicyValue("AAA"), "testAdmin");
+
+ auto policy = manager.get("sample-str-policy");
+ EXPECT_EQ(static_cast<std::string>(policy), "AAA");
+
+ manager.enroll("testAdmin1");
+ manager.set("sample-str-policy", PolicyValue("BBB"), "testAdmin1");
+
+ /// Manager should return the strongest policy.
+ policy = manager.get("sample-str-policy");
+ EXPECT_EQ(static_cast<std::string>(policy), "AAA");
+
+ manager.disenroll("testAdmin");
+ manager.disenroll("testAdmin1");
+}
+
TEST(PolicyCoreTests, policy_get_all) {
auto& manager = PolicyManager::Instance();
auto policies = manager.getAll();
TEST(PolicyCoreTests, policy_get_policy) {
auto& manager = PolicyManager::Instance();
- const auto& policy = manager.getPolicy("bluetooth");
- EXPECT_EQ(policy->getName(), "bluetooth");
+ const auto& policy = manager.getPolicy("sample-int-policy");
+ EXPECT_EQ(policy->getName(), "sample-int-policy");
bool raised = false;
try {