From: Adam Malinowski Date: Mon, 15 Sep 2014 12:47:22 +0000 (+0200) Subject: Add agent socket & dummy agent protocol X-Git-Tag: submit/R4/20141115.054144~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F27925%2F10;p=platform%2Fcore%2Fsecurity%2Fcynara.git Add agent socket & dummy agent protocol This change introduces new systemd based socket and protocol for communication with agents. Protocol does not contain any agent specific frame information for now. Change-Id: I83e2211a25fd93792a46a64c1df519efb1cedfed --- diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 743f2a7..8a3e298 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -287,6 +287,7 @@ mkdir -p %{buildroot}/%{tests_dir}/empty_db cp -a db* %{buildroot}/%{tests_dir} ln -s ../cynara.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/cynara.socket ln -s ../cynara-admin.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/cynara-admin.socket +ln -s ../cynara-agent.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/cynara-agent.socket %pre id -g %{group_name} > /dev/null 2>&1 @@ -425,6 +426,8 @@ fi %attr(-,root,root) /usr/lib/systemd/system/cynara.socket %attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/cynara-admin.socket %attr(-,root,root) /usr/lib/systemd/system/cynara-admin.socket +%attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/cynara-agent.socket +%attr(-,root,root) /usr/lib/systemd/system/cynara-agent.socket %dir %attr(700,cynara,cynara) %{state_path} %files -n libcynara-client diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 98f5133..72b7d7f 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -31,6 +31,7 @@ SET(COMMON_SOURCES ${COMMON_PATH}/log/log.cpp ${COMMON_PATH}/plugin/PluginManager.cpp ${COMMON_PATH}/protocol/ProtocolAdmin.cpp + ${COMMON_PATH}/protocol/ProtocolAgent.cpp ${COMMON_PATH}/protocol/ProtocolClient.cpp ${COMMON_PATH}/protocol/ProtocolFrame.cpp ${COMMON_PATH}/protocol/ProtocolFrameHeader.cpp diff --git a/src/common/common.h b/src/common/common.h index 5d93cdc..95ff89c 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -32,5 +32,4 @@ #include "types/PolicyTypeExtension.h" - #endif /* COMMON_H */ diff --git a/src/common/config/PathConfig.cpp b/src/common/config/PathConfig.cpp index a5a603b..f2799a1 100644 --- a/src/common/config/PathConfig.cpp +++ b/src/common/config/PathConfig.cpp @@ -47,6 +47,7 @@ const std::string clientPath("/run/cynara/"); namespace SocketPath { const std::string client(clientPath + "cynara.socket"); const std::string admin(clientPath + "cynara-admin.socket"); +const std::string agent(clientPath + "cynara-agent.socket"); } // namespace SocketPath namespace StoragePath { diff --git a/src/common/config/PathConfig.h b/src/common/config/PathConfig.h index 27b10c2..2f5836a 100644 --- a/src/common/config/PathConfig.h +++ b/src/common/config/PathConfig.h @@ -35,6 +35,7 @@ extern const std::string clientPath; namespace SocketPath { extern const std::string client; extern const std::string admin; +extern const std::string agent; } // namespace SocketPath namespace StoragePath { diff --git a/src/common/protocol/ProtocolAgent.cpp b/src/common/protocol/ProtocolAgent.cpp new file mode 100644 index 0000000..f4d26a1 --- /dev/null +++ b/src/common/protocol/ProtocolAgent.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014 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 src/common/protocol/ProtocolAgent.cpp + * @author Adam Malinowski + * @version 1.0 + * @brief This file implements protocol class for communication with agent + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include "ProtocolAgent.h" + +namespace Cynara { + +ProtocolAgent::ProtocolAgent() { +} + +ProtocolAgent::~ProtocolAgent() { +} + +ProtocolPtr ProtocolAgent::clone(void) { + return std::make_shared(); +} + +RequestPtr ProtocolAgent::extractRequestFromBuffer(BinaryQueuePtr bufferQueue) { + ProtocolFrameSerializer::deserializeHeader(m_frameHeader, bufferQueue); + + if (m_frameHeader.isFrameComplete()) { + ProtocolOpCode opCode; + + m_frameHeader.resetState(); + ProtocolDeserialization::deserialize(m_frameHeader, opCode); + LOGD("Deserialized opCode [%" PRIu8 "]", opCode); + switch (opCode) { + default: + throw InvalidProtocolException(InvalidProtocolException::WrongOpCode); + break; + } + } + + return nullptr; +} + +ResponsePtr ProtocolAgent::extractResponseFromBuffer(BinaryQueuePtr bufferQueue) { + ProtocolFrameSerializer::deserializeHeader(m_frameHeader, bufferQueue); + + if (m_frameHeader.isFrameComplete()) { + ProtocolOpCode opCode; + + m_frameHeader.resetState(); + ProtocolDeserialization::deserialize(m_frameHeader, opCode); + LOGD("Deserialized opCode [%" PRIu8 "]", opCode); + switch (opCode) { + default: + throw InvalidProtocolException(InvalidProtocolException::WrongOpCode); + break; + } + } + + return nullptr; +} + +} // namespace Cynara diff --git a/src/common/protocol/ProtocolAgent.h b/src/common/protocol/ProtocolAgent.h new file mode 100644 index 0000000..68baf46 --- /dev/null +++ b/src/common/protocol/ProtocolAgent.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014 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 src/common/protocol/ProtocolAgent.h + * @author Adam Malinowski + * @version 1.0 + * @brief This file defines protocol class for communication with agent + */ + +#ifndef SRC_COMMON_PROTOCOL_PROTOCOLAGENT_H_ +#define SRC_COMMON_PROTOCOL_PROTOCOLAGENT_H_ + +#include +#include +#include + +#include "Protocol.h" + +namespace Cynara { + +class ProtocolAgent : public Protocol { +public: + ProtocolAgent(); + virtual ~ProtocolAgent(); + + virtual ProtocolPtr clone(void); + + virtual RequestPtr extractRequestFromBuffer(BinaryQueuePtr bufferQueue); + virtual ResponsePtr extractResponseFromBuffer(BinaryQueuePtr bufferQueue); +}; + +} // namespace Cynara + +#endif /* SRC_COMMON_PROTOCOL_PROTOCOLAGENT_H_ */ diff --git a/src/service/sockets/SocketManager.cpp b/src/service/sockets/SocketManager.cpp index 3161dc7..e454271 100644 --- a/src/service/sockets/SocketManager.cpp +++ b/src/service/sockets/SocketManager.cpp @@ -45,6 +45,7 @@ #include #include
#include +#include #include #include #include @@ -72,11 +73,14 @@ void SocketManager::init(void) { LOGI("SocketManger init start"); const mode_t clientSocketUMask(0); const mode_t adminSocketUMask(0077); + const mode_t agentSocketUMask(0); createDomainSocket(std::make_shared(), PathConfig::SocketPath::client, clientSocketUMask, true); createDomainSocket(std::make_shared(), PathConfig::SocketPath::admin, adminSocketUMask, false); + createDomainSocket(std::make_shared(), PathConfig::SocketPath::agent, + agentSocketUMask, false); createSignalSocket(std::make_shared()); LOGI("SocketManger init done"); } diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index 8fc27e7..a540263 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -21,6 +21,7 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/cynara.target ${CMAKE_SOURCE_DIR}/systemd/cynara.socket ${CMAKE_SOURCE_DIR}/systemd/cynara-admin.socket + ${CMAKE_SOURCE_DIR}/systemd/cynara-agent.socket DESTINATION lib/systemd/system ) diff --git a/systemd/cynara-agent.socket b/systemd/cynara-agent.socket new file mode 100644 index 0000000..96fc54a --- /dev/null +++ b/systemd/cynara-agent.socket @@ -0,0 +1,14 @@ +[Socket] +ListenStream=/run/cynara/cynara-agent.socket +SocketMode=0060 +SmackLabelIPIn=* +SmackLabelIPOut=@ + +Service=cynara.service + +[Unit] +Wants=cynara.target +Before=cynara.target + +[Install] +WantedBy=sockets.target diff --git a/systemd/cynara.service b/systemd/cynara.service index 847a294..99176fa 100644 --- a/systemd/cynara.service +++ b/systemd/cynara.service @@ -12,6 +12,7 @@ Restart=always Sockets=cynara.socket Sockets=cynara-admin.socket +Sockets=cynara-agent.socket UMask=0000 User=cynara