Add ServiceType to rmi::Gateway
authorSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 13 Jan 2020 09:01:25 +0000 (18:01 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Tue, 14 Jan 2020 01:57:30 +0000 (10:57 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
12 files changed:
packaging/vist-plugins.manifest
packaging/vist-test.manifest [new file with mode: 0644]
packaging/vist.manifest
packaging/vist.spec
src/vist/CMakeLists.txt
src/vist/rmi/gateway.cpp
src/vist/rmi/gateway.hpp
src/vist/rmi/impl/general/tests/server-client.cpp
src/vist/rmi/impl/ondemand/server.hpp
src/vist/rmi/impl/ondemand/tests/server-client.cpp [deleted file]
src/vist/rmi/tests/rmi.cpp
src/vist/service/vistd.cpp

index 017d22d..97e8c31 100644 (file)
@@ -1,5 +1,5 @@
 <manifest>
- <request>
-    <domain name="_"/>
- </request>
      <request>
+               <domain name="_"/>
      </request>
 </manifest>
diff --git a/packaging/vist-test.manifest b/packaging/vist-test.manifest
new file mode 100644 (file)
index 0000000..d2c3009
--- /dev/null
@@ -0,0 +1,8 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+       <assign>
+               <filesystem path="/usr/bin/vist-test" exec_label="System" />
+       </assign>
+</manifest>
index 017d22d..97e8c31 100644 (file)
@@ -1,5 +1,5 @@
 <manifest>
- <request>
-    <domain name="_"/>
- </request>
      <request>
+               <domain name="_"/>
      </request>
 </manifest>
index 9e0b2f8..2d31756 100644 (file)
@@ -108,8 +108,8 @@ fi
 %license LICENSE-Apache-2.0
 %license LICENSE-GPL-2.0
 %license LICENSE-MIT
-%{_bindir}/vist-cli
-%{_bindir}/vistd
+%attr(-, %{user_name}, %{group_name}) %{_bindir}/vist-cli
+%attr(-, %{user_name}, %{group_name}) %{_bindir}/vistd
 %{_libdir}/libvist-rmi.so
 %{_unitdir}/vist.service
 %{_unitdir}/vist.socket
@@ -130,11 +130,12 @@ Requires: gtest
 Provides internal testcases for ViST implementation.
 
 %files test
+%manifest packaging/%{name}-test.manifest
 %{_bindir}/osquery-test
-%{_bindir}/vist-test
-%{vist_plugin_dir}/sample
+%attr(4755 %{user_name}, %{group_name}) %{_bindir}/vist-test
+%dir %attr(-, %{user_name}, %{group_name}) %{vist_plugin_dir}/sample
 
-## ViST Plugins ###########################################################
+## ViST Plugins #############################################################
 %package plugins
 Summary: Virtaul Security Table (policy modules)
 Group: Security/Other
index 5bab769..b9055a3 100644 (file)
@@ -62,7 +62,7 @@ IF(DEFINED GBS_BUILD)
        TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} ${VIST_COMMON_DEPS_LIBRARIES}
                                                                                                        pthread glog gflags boost_system)
 ELSE(DEFINED GBS_BUILD)
-       TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} pthread glog gflags boost_system)
+       TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} pthread glog gflags boost_system systemd)
 ENDIF(DEFINED GBS_BUILD)
 
 ADD_LIBRARY(${TARGET_VIST_LIB} STATIC ${${TARGET_VIST_LIB}_SRCS})
index 801f6a5..5ecc9ec 100644 (file)
 #include <vist/exception.hpp>
 #include <vist/rmi/message.hpp>
 #include <vist/rmi/impl/server.hpp>
-
-#ifdef TIZEN
-#include <vist/rmi/impl/ondemand/server.hpp>
-#else
 #include <vist/rmi/impl/general/server.hpp>
-#endif
+#include <vist/rmi/impl/ondemand/server.hpp>
 
 #include <memory>
 #include <string>
@@ -36,7 +32,7 @@ using namespace vist::rmi::impl;
 
 class Gateway::Impl {
 public:
-       explicit Impl(Gateway& gateway, const std::string& path)
+       explicit Impl(Gateway& gateway, const std::string& path, Gateway::ServiceType type)
        {
                auto dispatcher = [&gateway](auto& message) -> Message {
                        std::string function = message.signature;
@@ -55,11 +51,15 @@ public:
                        return reply;
                };
 
-#ifdef TIZEN
-               this->server = std::make_unique<ondemand::Server>(path, dispatcher);
-#else
-               this->server = std::make_unique<general::Server>(path, dispatcher);
-#endif
+               switch (type) {
+               case ServiceType::OnDemand:
+                       this->server = std::make_unique<ondemand::Server>(path, dispatcher);
+                       break;
+               case ServiceType::General: /// fall through
+               default:
+                       this->server = std::make_unique<general::Server>(path, dispatcher);
+                       break;
+               }
        }
 
        inline void start(int timeout, std::function<bool()> stopper)
@@ -76,7 +76,8 @@ private:
        std::unique_ptr<interface::Server> server;
 };
 
-Gateway::Gateway(const std::string& path) : pImpl(std::make_unique<Impl>(*this, path))
+Gateway::Gateway(const std::string& path, ServiceType type) :
+       pImpl(std::make_unique<Impl>(*this, path, type))
 {
 }
 
index bef6b19..d63a816 100644 (file)
@@ -30,7 +30,12 @@ namespace rmi {
 
 class VIST_API Gateway final {
 public:
-       explicit Gateway(const std::string& path);
+       enum class ServiceType {
+               General,
+               OnDemand
+       };
+
+       explicit Gateway(const std::string& path, ServiceType type = ServiceType::General);
        ~Gateway();
 
        Gateway(const Gateway&) = delete;
index b8e0407..eae2494 100644 (file)
@@ -45,6 +45,7 @@ std::string response3 = "response argument";
 
 } // anonymous namespace
 
+#ifndef TIZEN
 TEST(ServerClientTests, server)
 {
        std::string sockPath = "vist-test.sock";
@@ -100,3 +101,4 @@ TEST(ServerClientTests, server)
        if (serverThread.joinable())
                serverThread.join();
 }
+#endif
index 154bb10..9b90015 100644 (file)
 #include <vist/rmi/impl/ondemand/connection.hpp>
 #include <vist/rmi/impl/ondemand/mainloop.hpp>
 #include <vist/rmi/impl/ondemand/socket.hpp>
-
-#ifdef TIZEN
 #include <vist/rmi/impl/ondemand/systemd-socket.hpp>
-#endif
 
 #include <vist/exception.hpp>
 #include <vist/logger.hpp>
@@ -43,11 +40,7 @@ class Server : public interface::Server {
 public:
        Server(const std::string& path, const interface::Task& task) :
                interface::Server(path, task),
-#ifdef TIZEN
                socket(SystemdSocket::Create(path))
-#else
-               socket(path)
-#endif
        {
                this->accept(task);
        }
diff --git a/src/vist/rmi/impl/ondemand/tests/server-client.cpp b/src/vist/rmi/impl/ondemand/tests/server-client.cpp
deleted file mode 100644 (file)
index 664f8fd..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- *  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/rmi/message.hpp>
-#include <vist/rmi/impl/ondemand/server.hpp>
-#include <vist/rmi/impl/ondemand/client.hpp>
-
-#include <string>
-#include <thread>
-
-#include <gtest/gtest.h>
-
-using namespace vist::rmi;
-using namespace vist::rmi::impl::ondemand;
-
-namespace {
-
-/// Request variables
-std::string requestSignature = "request signature";
-int request1 = 100;
-bool request2 = true;
-std::string request3 = "request argument";
-
-/// Response variables
-std::string responseSignature = "response signature";
-int response1 = 300;
-bool response2 = false;
-std::string response3 = "response argument";
-
-} // anonymous namespace
-
-TEST(ServerClientTests, ondemand)
-{
-       std::string sockPath = "./vist-test.sock";
-
-       auto task = [&](Message& message) -> Message {
-               EXPECT_EQ(message.signature, requestSignature);
-
-               int recv1;
-               bool recv2;
-               std::string recv3;
-               message.disclose(recv1, recv2, recv3);
-               EXPECT_EQ(request1, recv1);
-               EXPECT_EQ(request2, recv2);
-               EXPECT_EQ(request3, recv3);
-
-               Message reply(Message::Type::Reply, responseSignature);
-               reply.enclose(response1, response2, response3);
-               return reply;
-       };
-
-       Server server(sockPath, task);
-       auto serverThread = std::thread([&]() {
-               server.run();
-       });
-
-       { /// Client configuration
-               auto clientClosure = [&]() {
-                       Client client(sockPath);
-
-                       Message message(Message::Type::MethodCall, requestSignature);
-                       message.enclose(request1, request2, request3);
-
-                       for (int i = 0; i < 3; i++) {
-                               auto reply = client.request(message);
-                               EXPECT_EQ(reply.signature, responseSignature);
-
-                               int recv1;
-                               bool recv2;
-                               std::string recv3;
-                               reply.disclose(recv1, recv2, recv3);
-                               EXPECT_EQ(response1, recv1);
-                               EXPECT_EQ(response2, recv2);
-                               EXPECT_EQ(response3, recv3);
-                       }
-               };
-
-               for (int i = 0; i < 3; i++)
-                       clientClosure();
-       }
-
-       server.stop();
-
-       if (serverThread.joinable())
-               serverThread.join();
-}
index c5de56f..d39fb46 100644 (file)
@@ -54,7 +54,7 @@ TEST(RmiTests, positive)
        std::string sockPath = ("/tmp/test-gateway");
 
        // gateway-side
-       Gateway gateway(sockPath);
+       Gateway gateway(sockPath, Gateway::ServiceType::General);
 
        Foo foo;
        gateway.expose(foo, "Foo::setName", &Foo::setName);
index d32a7bf..b078d97 100644 (file)
@@ -39,7 +39,12 @@ void Vistd::start()
 {
        INFO(VIST) << "Vistd daemon starts.";
 
-       rmi::Gateway gateway(SOCK_ADDR);
+       rmi::Gateway::ServiceType type = rmi::Gateway::ServiceType::General;
+#ifdef TIZEN
+       type = rmi::Gateway::ServiceType::OnDemand;
+#endif
+
+       rmi::Gateway gateway(SOCK_ADDR, type);
        EXPOSE(gateway, *this, &Vistd::query);
 
        auto& pm = policy::PolicyManager::Instance();