BuildRequires: zip
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: pkgconfig(libsystemd-journal)
+BuildRequires: pkgconfig(cynara-plugin)
+BuildRequires: pkgconfig(cynara-agent)
+
%{?systemd_requires}
%if !%{defined build_type}
# @file CMakeLists.txt
# @author Adam Malinowski <a.malinowsk2@partner.samsung.com>
#
+PKG_CHECK_MODULES(COMMON_DEP
+ REQUIRED
+ cynara-plugin
+ cynara-agent
+ )
SET(ASKUSER_COMMON_VERSION_MAJOR 0)
SET(ASKUSER_COMMON_VERSION ${ASKUSER_COMMON_VERSION_MAJOR}.0.1)
SET(COMMON_PATH ${ASKUSER_PATH}/common)
+INCLUDE_DIRECTORIES(
+ ${COMMON_DEP_INCLUDE_DIRS}
+ ${COMMON_PATH}
+ )
+
SET(COMMON_SOURCES
${COMMON_PATH}/log/log.cpp
+ ${COMMON_PATH}/translator/Translator.cpp
+ ${COMMON_PATH}/types/AgentErrorMsg.cpp
)
ADD_DEFINITIONS("-fvisibility=default")
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co.
+ *
+ * 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 Translator.cpp
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Implementation of Translator methods
+ */
+
+#include "Translator.h"
+
+#include <types/AgentErrorMsg.h>
+
+#include <limits>
+#include <stdexcept>
+#include <sstream>
+
+namespace AskUser {
+namespace Translator {
+namespace Agent {
+
+RequestData dataToRequest(const Cynara::PluginData &data) {
+ std::stringstream stream(data);
+ std::size_t strSize;
+ std::string members[3];
+
+ for (auto &member : members) {
+ stream >> strSize;
+ std::vector<char> buffer(strSize, '\0');
+ char separator;
+ //Consume separator
+ stream.read(&separator, 1);
+ stream.read(buffer.data(), strSize);
+ //read doesn't append null
+ member.assign(buffer.begin(), buffer.end());
+ }
+ return RequestData{members[0], members[1], members[2]};
+}
+
+Cynara::PluginData answerToData(Cynara::PolicyType answer, const std::string &errMsg) {
+ if (errMsg.empty())
+ return std::to_string(answer);
+ else
+ return errMsg;
+}
+
+} //namespace Agent
+
+namespace Plugin {
+
+Cynara::PolicyType dataToAnswer(const Cynara::PluginData &data) {
+ // data is an error string
+ if (data == AgentErrorMsg::Error || data == AgentErrorMsg::Timeout)
+ return Cynara::PredefinedPolicyType::DENY;
+ // data is policy type
+ long long policyType;
+ try {
+ policyType = std::stoll(data);
+ } catch (const std::exception &e) {
+ throw TranslateErrorException("Could not convert response to PolicyType : " +
+ data);
+ }
+ auto maxPolicyType = std::numeric_limits<Cynara::PolicyType>::max();
+ if (policyType > maxPolicyType) {
+ throw TranslateErrorException("Value of response exceeds max value of PolicyType : "
+ + std::to_string(policyType));
+ }
+ return static_cast<Cynara::PolicyType>(policyType);
+}
+
+Cynara::PluginData requestToData(const std::string &client,
+ const std::string &user,
+ const std::string &privilege)
+{
+ const char separator = ' ';
+ return std::to_string(client.length()) + separator + client + separator
+ + std::to_string(user.length()) + separator + user + separator
+ + std::to_string(privilege.length()) + separator + privilege + separator;
+}
+
+} //namespace Plugin
+} //namespace Translator
+} //namespace AskUser
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co.
+ *
+ * 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 Translator.h
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Definition of Translator methods and TranslateErrorException class
+ */
+
+#pragma once
+
+#include <types/RequestData.h>
+#include <types/SupportedTypes.h>
+#include <cynara-plugin.h>
+
+#include <exception>
+#include <string>
+
+namespace AskUser {
+namespace Translator {
+
+class TranslateErrorException : std::exception {
+public:
+ TranslateErrorException(const std::string &msg) : m_what(msg) {};
+ virtual const char* what() const noexcept {
+ return m_what.c_str();
+ }
+private:
+ std::string m_what;
+};
+
+namespace Agent {
+ RequestData dataToRequest(const Cynara::PluginData &data);
+ Cynara::PluginData answerToData(Cynara::PolicyType answer, const std::string &errMsg);
+} // namespace Agent
+
+namespace Plugin {
+ Cynara::PolicyType dataToAnswer(const Cynara::PluginData &data);
+ Cynara::PluginData requestToData(const std::string &client,
+ const std::string &user,
+ const std::string &privilege);
+} // namespace Plugin
+
+} // namespace Translator
+} // namespace AskUser
+
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co.
+ *
+ * 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 AgentErrorMsg.cpp
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Definition of agent error messages passed to cynara plugin
+ */
+
+#include "AgentErrorMsg.h"
+
+namespace AskUser {
+namespace AgentErrorMsg {
+
+const std::string Error = "ERROR";
+const std::string Timeout = "TIMEOUT";
+
+} // namespace AgentErrorMsg
+} // namespace AskUser
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co.
+ *
+ * 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 AgentErrorMsg.h
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Agent error messages passed to cynara plugin
+ */
+
+#pragma once
+
+#include <string>
+
+namespace AskUser {
+namespace AgentErrorMsg {
+
+extern const std::string Error;
+extern const std::string Timeout;
+
+} // namespace AgentErrorMsg
+} // namespace AskUser
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co.
+ *
+ * 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 RequestData.h
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Definition of RequestData structure
+ */
+
+#pragma once
+
+#include <string>
+
+namespace AskUser {
+
+struct RequestData {
+ std::string client;
+ std::string user;
+ std::string privilege;
+};
+
+} // namespace AskUser
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co.
+ *
+ * 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 SupportedTypes.h
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Definition of plugin supported types and agent type
+ */
+
+#pragma once
+
+#include <types/PolicyType.h>
+
+namespace AskUser {
+namespace SupportedTypes {
+
+namespace Agent {
+const char* const AgentType = "AskUser";
+} //namespace Agent
+
+namespace Service {
+const Cynara::PolicyType ASK_USER = 10;
+} //namespace Service
+
+namespace Client {
+const Cynara::PolicyType ALLOW_ONCE = 11;
+const Cynara::PolicyType ALLOW_PER_SESSION = 12;
+const Cynara::PolicyType ALLOW_PER_LIFE = 13;
+} //namespace Client
+
+} //namespace SupportedTypes
+} //namespace AskUser