static const std::string DEFAULT_POLICY("");
static const std::string SINGLE_POLICY("single-policy");
static const std::string MULTIPLE_POLICY("multiple-policy");
+static const std::string TEST_AGENT("test-agent");
static const DescriptionsMap POLICY_DESCRIPTIONS = {
DescriptionsPair(DEFAULT_POLICY, {
{ 3002, "Multiple Policy Type 2" },
{ 3003, "Multiple Policy Type 3" },
}),
+ DescriptionsPair(TEST_AGENT, {
+ { 4001, "Test Agent Type 1" }
+ }),
};
+static const std::string TEST_AGENT_TYPE("SecurityCynaraTestsAgentType");
+
static const std::string AGENT_DATA_UNIT_SEPARATOR("\31");
static const std::string AGENT_DATA_RECORD_SEPARATOR("\30");
static const std::string AGENT_DATA_ALLOW("Allow");
--- /dev/null
+# Copyright (c) 2015 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 CMakeLists.txt
+# @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
+
+INCLUDE(FindPkgConfig)
+
+SET(CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT "cynara-test-plugin-test-agent")
+
+PKG_CHECK_MODULES(CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT_DEP
+ REQUIRED
+ cynara-plugin
+ )
+
+INCLUDE_DIRECTORIES(
+ ${CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT_DEP_INCLUDE_DIRS}
+ ${PROJECT_SOURCE_DIR}/tests/cynara-tests/plugins/
+ )
+
+SET(CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT_SOURCES
+ ${PROJECT_SOURCE_DIR}/tests/cynara-tests/plugins/test-agent/plugin.cpp
+ ${PROJECT_SOURCE_DIR}/tests/cynara-tests/plugins/plugins.cpp
+ )
+
+ADD_DEFINITIONS("-fvisibility=default")
+
+ADD_LIBRARY(
+ ${CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT}
+ SHARED
+ ${CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT_SOURCES}
+ )
+
+TARGET_LINK_LIBRARIES(${CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT}
+ ${CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT_DEPS}
+ )
+
+INSTALL(TARGETS ${CYNARA_TARGET_TEST_PLUGIN_TEST_AGENT}
+ DESTINATION /usr/lib/security-tests/cynara-tests/plugins/test-agent/)
--- /dev/null
+/*
+ * Copyright (c) 2015 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 plugin.cpp
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @brief Implementation of cynara test plugin handling communication with test-agent
+ */
+
+#include <new>
+
+#include <cynara-plugin.h>
+#include <BaseCynaraTestPlugin.h>
+#include <plugins.h>
+
+class TestAgentPlugin : public BaseCynaraTestPlugin
+{
+public:
+ TestAgentPlugin() : BaseCynaraTestPlugin(CynaraTestPlugins::TEST_AGENT) {}
+ virtual ~TestAgentPlugin() {}
+
+ virtual Cynara::ServicePluginInterface::PluginStatus check(const std::string &client,
+ const std::string &user,
+ const std::string &privilege,
+ Cynara::PolicyResult &result,
+ Cynara::AgentType &requiredAgent,
+ Cynara::PluginData &pluginData)
+ noexcept
+ {
+ (void) result;
+
+ try {
+ requiredAgent = CynaraTestPlugins::TEST_AGENT_TYPE;
+ pluginData = CynaraTestPlugins::wrapAgentData({client, user, privilege});
+ } catch (...) {
+ return Cynara::ServicePluginInterface::PluginStatus::ERROR;
+ }
+ return Cynara::ServicePluginInterface::PluginStatus::ANSWER_NOTREADY;
+ }
+
+ virtual Cynara::ServicePluginInterface::PluginStatus update(const std::string &client,
+ const std::string &user,
+ const std::string &privilege,
+ const Cynara::PluginData &agentData,
+ Cynara::PolicyResult &result)
+ noexcept
+ {
+ (void) client;
+ (void) user;
+ (void) privilege;
+
+ try {
+ CynaraTestPlugins::AgentDataVector data;
+ if (!CynaraTestPlugins::unwrapAgentData(agentData, data))
+ return Cynara::ServicePluginInterface::PluginStatus::ERROR;
+
+ if (data.size() != 1)
+ return Cynara::ServicePluginInterface::PluginStatus::ERROR;
+
+ if (data[0] == CynaraTestPlugins::AGENT_DATA_ALLOW) {
+ result = Cynara::PolicyResult(Cynara::PredefinedPolicyType::ALLOW);
+ return Cynara::ServicePluginInterface::PluginStatus::SUCCESS;
+ }
+ else if (data[0] == CynaraTestPlugins::AGENT_DATA_DENY) {
+ result = Cynara::PolicyResult(Cynara::PredefinedPolicyType::DENY);
+ return Cynara::ServicePluginInterface::PluginStatus::SUCCESS;
+ }
+ } catch (...) {
+ return Cynara::ServicePluginInterface::PluginStatus::ERROR;
+ }
+ return Cynara::ServicePluginInterface::PluginStatus::ERROR;
+ }
+};
+
+extern "C" {
+Cynara::ExternalPluginInterface *create(void) {
+ return new TestAgentPlugin();
+}
+
+void destroy(Cynara::ExternalPluginInterface *ptr) {
+ delete ptr;
+}
+} // extern "C"