Drop socket manager multi service support 37/277737/3
authorKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 12 Jul 2022 14:01:11 +0000 (16:01 +0200)
committerKonrad Lipinski <k.lipinski2@samsung.com>
Thu, 14 Jul 2022 12:31:56 +0000 (14:31 +0200)
That feature has never been used, it's always been dead weight.
Security manager is a single service so that's unlikely to ever change.

Implications:
* no need to store/check interface ID
* one service per socket manager - less bookkeeping, simpler destructor
* socket descriptors now only apply to accepted sockets

Change-Id: I84ce915f0ff6929df45a40a0a8f5cbf7a4214694

src/common/include/connection-info.h
src/common/include/connection.h
src/server/main/include/generic-socket-manager.h
src/server/main/include/socket-manager.h
src/server/main/socket-manager.cpp
src/server/service/base-service.cpp
src/server/service/include/base-service.h
src/server/service/include/service.h
src/server/service/service.cpp

index c784526a0b955da3686e9155254b51b48057c1aa..d604c81db13fd51f48ef804b4e768f7bf750ea48 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
 namespace SecurityManager
 {
     struct ConnectionInfo {
-        ConnectionInfo(InterfaceID inter, Credentials crd)
-          : interfaceID(inter)
-          , creds(std::move(crd))
+        ConnectionInfo(Credentials crd)
+          : creds(std::move(crd))
         {}
 
-        InterfaceID interfaceID;
         Credentials creds;
         MessageBuffer buffer;
     };
index c3562d9d166b38f59153268a698c7167e04cf6ee..759c1e3bb423a8594121bc7c24115dc440fbb1a8 100644 (file)
 
 #include <message-buffer.h>
 
-extern "C" {
-    struct msghdr;
-}
-
 namespace SecurityManager {
 
 typedef std::vector<unsigned char> RawBuffer;
index 5934ae159e1558e983b999affd0e93db6e0a54e9..c916c62d097c367cdfabe2f986a2e3ac5f2331cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
@@ -38,8 +38,6 @@
 
 namespace SecurityManager {
 
-typedef int InterfaceID;
-
 struct ConnectionID {
     int sock;                                 // This is decriptor used for connection
     int counter;                              // Unique handler per socket
@@ -57,31 +55,21 @@ struct GenericSocketService {
     typedef std::string ServiceHandlerPath;
     struct ServiceDescription {
         ServiceDescription(const char *path,
-            const char *smackLabel,
-            InterfaceID interfaceID = 0,
-            bool systemdOnly = false)
+            const char *smackLabel)
           : smackLabel(smackLabel)
-          , interfaceID(interfaceID)
           , serviceHandlerPath(path)
-          , systemdOnly(systemdOnly)
         {}
 
         SmackLabel smackLabel;                 // Smack label for socket
-        InterfaceID interfaceID;               // All data from serviceHandlerPath will be marked with this interfaceHandler
         ServiceHandlerPath serviceHandlerPath; // Path to file
-        bool systemdOnly;
     };
 
-    typedef std::vector<ServiceDescription> ServiceDescriptionVector;
-
     struct AcceptEvent : public GenericEvent {
-        AcceptEvent(ConnectionID connection, InterfaceID interface, Credentials crd)
+        AcceptEvent(ConnectionID connection, Credentials crd)
           : connectionID(connection)
-          , interfaceID(interface)
           , creds(std::move(crd))
         {}
         ConnectionID connectionID;
-        InterfaceID interfaceID;
         Credentials creds;
     };
 
@@ -104,7 +92,7 @@ struct GenericSocketService {
         m_serviceManager = manager;
     }
 
-    virtual ServiceDescriptionVector GetServiceDescription() = 0;
+    virtual const ServiceDescription &GetServiceDescription() const = 0;
     virtual void Event(AcceptEvent &&event) = 0;
     virtual void Event(WriteEvent &&event) = 0;
     virtual void Event(ReadEvent &&event) = 0;
index 9737382fc7ba32ebe6059b6ae69aaef012013b9a..ffcbba0f89b704c8a6e65848d1622e754138dd83 100644 (file)
@@ -57,7 +57,6 @@ public:
 
 protected:
     void CreateDomainSocket(
-        GenericSocketService *service,
         const GenericSocketService::ServiceDescription &desc);
     int CreateDomainSocketHelp(
         const GenericSocketService::ServiceDescription &desc);
@@ -66,7 +65,7 @@ protected:
 
     void ReadyForRead(int sock);
     void ReadyForWrite(int sock);
-    void ReadyForAccept(int sock);
+    void ReadyForAccept();
     bool GotSigTerm() const;
     void ProcessQueue(void);
     void NotifyMe(void);
@@ -75,27 +74,14 @@ protected:
     void RegisterFdForReading(int fd);
 
     struct SocketDescription {
-        bool isListen;
-        bool isOpen;
-        bool isTimeout;
-        InterfaceID interfaceID;
-        GenericSocketService *service;
-        time_t timeout;
+        bool isOpen = false;
+        bool isTimeout = false;
+        time_t timeout = 0;
         RawBuffer rawBuffer;
-        int counter;
-
-        SocketDescription()
-          : isListen(false)
-          , isOpen(false)
-          , isTimeout(false)
-          , interfaceID(-1)
-          , service(NULL)
-          , timeout(0)
-          , counter(-1)
-        {}
+        int counter = -1;
     };
 
-    SocketDescription& CreateDefaultReadSocketDescription(int sock, bool timeout);
+    SocketDescription& CreateDefaultReadSocketDescription(int sock);
 
     typedef std::vector<SocketDescription> SocketDescriptionVector;
 
@@ -113,10 +99,11 @@ protected:
     };
 
     SocketDescriptionVector m_socketDescriptionVector;
+    GenericSocketService *m_service = nullptr;
     fd_set m_readSet;
     fd_set m_writeSet;
     int m_maxDesc = 0;
-    int m_signalFd, m_notifyMe;
+    int m_signalFd, m_listenSock = -1, m_notifyMe;
     int m_counter = 0;
     std::mutex m_eventQueueMutex;
     std::queue<WriteBuffer> m_writeBufferQueue;
index fd945d5c0b227b65c1702ce2e456c28a95b0d87a..673ee33d0e1a7b6087a5d7444539431e820a7aa5 100644 (file)
@@ -26,8 +26,6 @@
  * @brief       Implementation of SocketManager.
  */
 
-#include <set>
-
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/xattr.h>
@@ -69,30 +67,24 @@ void SocketManager::RegisterFdForReading(int fd) {
 }
 
 SocketManager::SocketDescription&
-SocketManager::CreateDefaultReadSocketDescription(int sock, bool timeout)
+SocketManager::CreateDefaultReadSocketDescription(int sock)
 {
     if ((int)m_socketDescriptionVector.size() <= sock)
         m_socketDescriptionVector.resize(sock+20);
 
     auto &desc = m_socketDescriptionVector[sock];
-    desc.isListen = false;
     desc.isOpen = true;
-    desc.interfaceID = 0;
-    desc.service = NULL;
+    desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
     desc.counter = ++m_counter;
 
-    if (timeout) {
-        desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
-        if (false == desc.isTimeout) {
-            Timeout tm;
-            tm.time = desc.timeout;
-            tm.sock = sock;
-            m_timeoutQueue.push(tm);
-        }
+    if (false == desc.isTimeout) {
+        desc.isTimeout = true;
+        Timeout tm;
+        tm.time = desc.timeout;
+        tm.sock = sock;
+        m_timeoutQueue.push(tm);
     }
 
-    desc.isTimeout = timeout;
-
     RegisterFdForReading(sock);
     return desc;
 }
@@ -126,19 +118,9 @@ SocketManager::SocketManager()
 }
 
 SocketManager::~SocketManager() {
-    std::set<GenericSocketService*> serviceMap;
-
-    // Find all services. Set is used to remove duplicates.
-    // In this implementation, services are not able to react in any way.
-    for (size_t i=0; i < m_socketDescriptionVector.size(); ++i)
-        if (m_socketDescriptionVector[i].isOpen)
-            serviceMap.insert(m_socketDescriptionVector[i].service);
-
-    // Time to destroy all services.
-    for (auto it = serviceMap.begin(); it != serviceMap.end(); ++it) {
-        LogDebug("delete " << (void*)(*it));
-        (*it)->Stop();
-        delete *it;
+    if (m_service) {
+        m_service->Stop();
+        delete m_service;
     }
 
     for (size_t i = 0; i < m_socketDescriptionVector.size(); ++i)
@@ -147,13 +129,14 @@ SocketManager::~SocketManager() {
 
     // All service sockets have been closed. Close internal descriptors.
     close(m_signalFd);
+    close(m_listenSock);
     close(m_notifyMe);
 }
 
-void SocketManager::ReadyForAccept(int sock) {
+void SocketManager::ReadyForAccept() {
     struct sockaddr_un clientAddr;
     unsigned int clientLen = sizeof(clientAddr);
-    int client = accept4(sock, (struct sockaddr*) &clientAddr, &clientLen, SOCK_NONBLOCK);
+    int client = accept4(m_listenSock, (struct sockaddr*) &clientAddr, &clientLen, SOCK_NONBLOCK);
 //    LogInfo("Accept on sock: " << sock << " Socket opended: " << client);
     if (-1 == client) {
         int err = errno;
@@ -161,15 +144,12 @@ void SocketManager::ReadyForAccept(int sock) {
         return;
     }
 
-    auto &desc = CreateDefaultReadSocketDescription(client, true);
-    desc.interfaceID = m_socketDescriptionVector[sock].interfaceID;
-    desc.service = m_socketDescriptionVector[sock].service;
+    auto &desc = CreateDefaultReadSocketDescription(client);
 
     GenericSocketService::AcceptEvent event(
         ConnectionID{client, desc.counter},
-        desc.interfaceID,
         Credentials::getCredentialsFromSocket(client));
-    desc.service->Event(std::move(event));
+    m_service->Event(std::move(event));
 }
 
 // true if quit mainloop
@@ -198,11 +178,6 @@ bool SocketManager::GotSigTerm() const {
 }
 
 void SocketManager::ReadyForRead(int sock) {
-    if (m_socketDescriptionVector[sock].isListen) {
-        ReadyForAccept(sock);
-        return;
-    }
-
     GenericSocketService::ReadEvent event;
     event.connectionID.sock = sock;
     event.connectionID.counter = m_socketDescriptionVector[sock].counter;
@@ -218,7 +193,7 @@ void SocketManager::ReadyForRead(int sock) {
         CloseSocket(sock);
     } else if (size >= 0) {
         event.rawBuffer.resize(size);
-        desc.service->Event(std::move(event));
+        m_service->Event(std::move(event));
     } else if (size == -1) {
         int err = errno;
         switch (err) {
@@ -264,7 +239,7 @@ void SocketManager::ReadyForWrite(int sock) {
     event.size = result;
     event.left = desc.rawBuffer.size();
 
-    desc.service->Event(std::move(event));
+    m_service->Event(std::move(event));
 }
 
 void SocketManager::MainLoop() {
@@ -369,6 +344,10 @@ void SocketManager::MainLoop() {
                 return;
             FD_CLR(m_signalFd, &readSet);
         }
+        if (FD_ISSET(m_listenSock, &readSet)) {
+            ReadyForAccept();
+            FD_CLR(m_listenSock, &readSet);
+        }
         if (FD_ISSET(m_notifyMe, &readSet)) {
             eventfd_t dummyValue;
             TEMP_FAILURE_RETRY(eventfd_read(m_notifyMe, &dummyValue));
@@ -394,8 +373,8 @@ int SocketManager::GetSocketFromSystemD(
 {
     int fd;
 
-    // TODO optimalization - do it once in object constructor
-    //                       and remember all information path->sockfd
+    // TODO optimization - do it once in object constructor
+    //                     and remember all information path->sockfd
     int n = sd_listen_fds(0);
 
     LogInfo("sd_listen_fds returns: " << n);
@@ -487,24 +466,14 @@ int SocketManager::CreateDomainSocketHelp(
 }
 
 void SocketManager::CreateDomainSocket(
-    GenericSocketService *service,
     const GenericSocketService::ServiceDescription &desc)
 {
     int sockfd = GetSocketFromSystemD(desc);
-    if (-1 == sockfd) {
-        if (desc.systemdOnly) {
-            LogError("Socket " << desc.serviceHandlerPath << " not provided by systemd.");
-            ThrowMsg(Exception::InitFailed, "Socket " << desc.serviceHandlerPath <<
-                " must be provided by systemd, but it was not.");
-        }
+    if (-1 == sockfd)
         sockfd = CreateDomainSocketHelp(desc);
-    }
 
-    auto &description = CreateDefaultReadSocketDescription(sockfd, false);
-
-    description.isListen = true;
-    description.interfaceID = desc.interfaceID;
-    description.service = service;
+    m_listenSock = sockfd;
+    RegisterFdForReading(sockfd);
 
     LogDebug("Listen on socket: " << sockfd <<
         " Handler: " << desc.serviceHandlerPath.c_str());
@@ -512,21 +481,8 @@ void SocketManager::CreateDomainSocket(
 
 void SocketManager::RegisterSocketService(GenericSocketService *service) {
     service->SetSocketManager(this);
-    auto serviceVector = service->GetServiceDescription();
-    Try {
-        for (auto iter = serviceVector.begin(); iter != serviceVector.end(); ++iter)
-            CreateDomainSocket(service, *iter);
-    } Catch(Exception::Base) {
-        for (int i =0; i < (int)m_socketDescriptionVector.size(); ++i)
-        {
-            auto &desc = m_socketDescriptionVector[i];
-            if (desc.service == service && desc.isOpen) {
-                close(i);
-                desc.isOpen = false;
-            }
-        }
-        ReThrow(Exception::Base);
-    }
+    CreateDomainSocket(service->GetServiceDescription());
+    m_service = service;
 }
 
 void SocketManager::Close(ConnectionID connectionID) {
@@ -618,18 +574,10 @@ void SocketManager::CloseSocket(int sock) {
     GenericSocketService::CloseEvent event;
     event.connectionID.sock = sock;
     event.connectionID.counter = desc.counter;
-    auto service = desc.service;
 
     desc.isOpen = false;
-    desc.service = NULL;
-    desc.interfaceID = -1;
     desc.rawBuffer.clear();
 
-    if (service)
-        service->Event(std::move(event));
-    else
-        LogError("Critical! Service is NULL! This should never happend!");
-
     close(sock);
     FD_CLR(sock, &m_readSet);
     FD_CLR(sock, &m_writeSet);
index 4b51dbc0d68046355476ce195c9ada691ca57446..8450dfd101688948b974b2b779d4f53406f2cd18 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
@@ -47,13 +47,12 @@ BaseService::BaseService(Offline offline)
 void BaseService::accept(AcceptEvent &&event)
 {
     LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock <<
-             " ConnectionID.counter: " << event.connectionID.counter <<
-             " ServiceID: " << event.interfaceID);
+             " ConnectionID.counter: " << event.connectionID.counter);
 
     m_connectionInfoMap.emplace(
         std::make_pair(
             event.connectionID.counter,
-            ConnectionInfo(event.interfaceID, std::move(event.creds))));
+            ConnectionInfo(std::move(event.creds))));
 }
 
 void BaseService::write(WriteEvent &&event)
@@ -74,7 +73,7 @@ void BaseService::process(ReadEvent &&event)
 
     // We can get several requests in one package.
     // Extract and process them all
-    while (processOne(event.connectionID, info.buffer, info.interfaceID));
+    while (processOne(event.connectionID, info.buffer));
 }
 
 void BaseService::close(CloseEvent &&event)
index 35a21d748dc1fad9b86714b13474347d2d7fb857..2ca2d39f0f8a92fc6092ce29b4d24325d48a6f3b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
@@ -50,7 +50,7 @@ class BaseService :
 public:
     using Offline = ServiceImpl::Offline;
     explicit BaseService(Offline offline);
-    virtual ServiceDescriptionVector GetServiceDescription() = 0;
+    virtual const ServiceDescription &GetServiceDescription() const = 0;
 
     DECLARE_THREAD_EVENT(AcceptEvent, accept)
     DECLARE_THREAD_EVENT(WriteEvent, write)
@@ -75,12 +75,10 @@ protected:
      *
      * @param  conn        Socket connection information
      * @param  buffer      Raw received data buffer
-     * @param  interfaceID identifier used to distinguish source socket
      * @return             true on success
      */
     virtual bool processOne(const ConnectionID &conn,
-                            MessageBuffer &buffer,
-                            InterfaceID interfaceID) = 0;
+                            MessageBuffer &buffer) = 0;
 };
 
 } // namespace SecurityManager
index a943642f581d9e0026d07042f1c06ed1456b4879..b5b66d51635f005b086d46e147a74ca42b24a90b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
@@ -48,7 +48,7 @@ class Service :
 public:
     using Offline = BaseService::Offline;
     explicit Service(Offline offline);
-    ServiceDescriptionVector GetServiceDescription();
+    const ServiceDescription &GetServiceDescription() const override;
     void RegisterChannel(Channel channel) {
         serviceImpl.RegisterChannel(std::move(channel));
     }
@@ -59,10 +59,9 @@ private:
      *
      * @param  conn        Socket connection information
      * @param  buffer      Raw received data buffer
-     * @param  interfaceID identifier used to distinguish source socket
      * @return             true on success
      */
-    bool processOne(const ConnectionID &conn, MessageBuffer &buffer, InterfaceID interfaceID);
+    bool processOne(const ConnectionID &conn, MessageBuffer &buffer);
 
 
     /**
index 0457627c1a43e509631adcb33e3fec6500f9a26c..8eea5068c05b5d449960b23cee712c07db3ca932 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
 
 namespace SecurityManager {
 
-const InterfaceID IFACE = 1;
-
 Service::Service(Offline offline) : BaseService(offline) {}
 
-GenericSocketService::ServiceDescriptionVector Service::GetServiceDescription()
+static const GenericSocketService::ServiceDescription serviceDesc{
+    SERVICE_SOCKET,  /* path */
+    "*"              /* smackLabel label (not used, we rely on systemd) */
+};
+
+const GenericSocketService::ServiceDescription &Service::GetServiceDescription() const
 {
-    return ServiceDescriptionVector {
-        {SERVICE_SOCKET,  /* path */
-        "*",   /* smackLabel label (not used, we rely on systemd) */
-        IFACE, /* InterfaceID */
-        false}, /* systemdOnly */
-    };
+    return serviceDesc;
 }
 
-bool Service::processOne(const ConnectionID &conn, MessageBuffer &buffer,
-                                  InterfaceID interfaceID)
+bool Service::processOne(const ConnectionID &conn, MessageBuffer &buffer)
 {
-    LogDebug("Iteration begin. Interface = " << interfaceID);
+    LogDebug("Iteration begin.");
 
     //waiting for all data
     if (!buffer.Ready()) {
@@ -66,145 +63,136 @@ bool Service::processOne(const ConnectionID &conn, MessageBuffer &buffer,
     }
 
     MessageBuffer send;
-    bool retval = false;
-
-    if (IFACE == interfaceID) {
-        Try {
-            Credentials &creds = m_connectionInfoMap.at(conn.counter).creds;
-            // deserialize API call type
-            int call_type_int;
-            Deserialization::Deserialize(buffer, call_type_int);
-            SecurityModuleCall call_type = static_cast<SecurityModuleCall>(call_type_int);
-            LOG_EXECUTION_TIME(SecurityModuleCallToString(call_type), creds);
-            switch (call_type) {
-                case SecurityModuleCall::NOOP:
-                    LogDebug("call_type: SecurityModuleCall::NOOP");
-                    Serialization::Serialize(send, static_cast<int>(SECURITY_MANAGER_SUCCESS));
-                    break;
-                case SecurityModuleCall::APP_INSTALL:
-                    LogDebug("call_type: SecurityModuleCall::APP_INSTALL");
-                    processAppInstall(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::APP_UPDATE:
-                    LogDebug("call_type: SecurityModuleCall::APP_UPDATE");
-                    processAppUpdate(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::APP_UNINSTALL:
-                    LogDebug("call_type: SecurityModuleCall::APP_UNINSTALL");
-                    processAppUninstall(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::APP_GET_PKG_NAME:
-                    LogDebug("call_type: SecurityModuleCall::APP_GET_PKG_NAME");
-                    processGetPkgName(buffer, send);
-                    break;
-                case SecurityModuleCall::USER_ADD:
-                    LogDebug("call_type: SecurityModuleCall::USER_ADD");
-                    processUserAdd(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::USER_DELETE:
-                    LogDebug("call_type: SecurityModuleCall::USER_DELETE");
-                    processUserDelete(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::POLICY_UPDATE:
-                    LogDebug("call_type: SecurityModuleCall::POLICY_UPDATE");
-                    processPolicyUpdate(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::GET_CONF_POLICY_ADMIN:
-                    LogDebug("call_type: SecurityModuleCall::GET_CONF_POLICY_ADMIN");
-                    processGetConfiguredPolicy(buffer, send, creds, true);
-                    break;
-                case SecurityModuleCall::GET_CONF_POLICY_SELF:
-                    LogDebug("call_type: SecurityModuleCall::GET_CONF_POLICY_SELF");
-                    processGetConfiguredPolicy(buffer, send, creds, false);
-                    break;
-                case SecurityModuleCall::GET_POLICY:
-                    LogDebug("call_type: SecurityModuleCall::GET_POLICY");
-                    processGetPolicy(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::POLICY_GET_DESCRIPTIONS:
-                    LogDebug("call_type: SecurityModuleCall::POLICY_GET_DESCRIPTIONS");
-                    processPolicyGetDesc(send);
-                    break;
-                case SecurityModuleCall::GROUPS_GET:
-                    LogDebug("call_type: SecurityModuleCall::GROUPS_GET");
-                    processGetForbiddenAndAllowedGroups(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::GROUPS_FOR_UID:
-                    processGroupsForUid(buffer, send);
-                    break;
-                case SecurityModuleCall::APP_HAS_PRIVILEGE:
-                    LogDebug("call_type: SecurityModuleCall::APP_HAS_PRIVILEGE");
-                    processAppHasPrivilege(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::APP_APPLY_PRIVATE_SHARING:
-                    LogDebug("call_type: SecurityModuleCall::APP_APPLY_PRIVATE_SHARING");
-                    processApplyPrivateSharing(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::APP_DROP_PRIVATE_SHARING:
-                    LogDebug("call_type: SecurityModuleCall::APP_DROP_PRIVATE_SHARING");
-                    processDropPrivateSharing(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::PATHS_REGISTER:
-                    processPathsRegister(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::SHM_APP_NAME:
-                    processShmAppName(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_PROVIDER:
-                    LogDebug("call_type: SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_PROVIDER");
-                    processGetAppDefinedPrivilegeProvider(buffer, send);
-                    break;
-                case SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_LICENSE:
-                    LogDebug("call_type: SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_LICENSE");
-                    processGetAppDefinedPrivilegeLicense(buffer, send);
-                    break;
-                case SecurityModuleCall::GET_CLIENT_PRIVILEGE_LICENSE:
-                    LogDebug("call_type: SecurityModuleCall::GET_CLIENT_PRIVILEGE_PROVIDER");
-                    processGetClientPrivilegeLicense(buffer, send);
-                    break;
-                case SecurityModuleCall::APP_CLEAN_NAMESPACE:
-                    LogDebug("call_type: SecurityModuleCall::APP_CLEAN_NAMESPACE");
-                    processAppCleanNamespace(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::GET_APP_MANIFEST_POLICY:
-                    LogDebug("call_type: SecurityModuleCall::GET_APP_MANIFEST_POLICY");
-                    processAppGetManifestPolicy(buffer, send, creds);
-                    break;
-                case SecurityModuleCall::GET_PROCESS_LABEL:
-                    processGetProcessLabel(buffer, send);
-                    break;
-                case SecurityModuleCall::PREPARE_APP:
-                    prepareApp(buffer, send, creds);
-                    break;
-                default:
-                    LogError("Invalid call: " << call_type_int);
-                    Throw(ServiceException::InvalidAction);
-            }
-            // if we reach this point, the protocol is OK
-            retval = true;
-        } Catch(MessageBuffer::Exception::Base) {
-            LogError("Broken protocol.");
-        } Catch(ServiceException::Base) {
-            LogError("Broken protocol.");
-        } catch (const std::exception &e) {
-            LogError("STD exception " << e.what());
-        } catch (...) {
-            LogError("Unknown exception");
-        }
-    } else {
-        LogError("Wrong interface");
-    }
 
-    if (retval) {
-        //send response
+    Try {
+        Credentials &creds = m_connectionInfoMap.at(conn.counter).creds;
+        // deserialize API call type
+        int call_type_int;
+        Deserialization::Deserialize(buffer, call_type_int);
+        SecurityModuleCall call_type = static_cast<SecurityModuleCall>(call_type_int);
+        LOG_EXECUTION_TIME(SecurityModuleCallToString(call_type), creds);
+        switch (call_type) {
+            case SecurityModuleCall::NOOP:
+                LogDebug("call_type: SecurityModuleCall::NOOP");
+                Serialization::Serialize(send, static_cast<int>(SECURITY_MANAGER_SUCCESS));
+                break;
+            case SecurityModuleCall::APP_INSTALL:
+                LogDebug("call_type: SecurityModuleCall::APP_INSTALL");
+                processAppInstall(buffer, send, creds);
+                break;
+            case SecurityModuleCall::APP_UPDATE:
+                LogDebug("call_type: SecurityModuleCall::APP_UPDATE");
+                processAppUpdate(buffer, send, creds);
+                break;
+            case SecurityModuleCall::APP_UNINSTALL:
+                LogDebug("call_type: SecurityModuleCall::APP_UNINSTALL");
+                processAppUninstall(buffer, send, creds);
+                break;
+            case SecurityModuleCall::APP_GET_PKG_NAME:
+                LogDebug("call_type: SecurityModuleCall::APP_GET_PKG_NAME");
+                processGetPkgName(buffer, send);
+                break;
+            case SecurityModuleCall::USER_ADD:
+                LogDebug("call_type: SecurityModuleCall::USER_ADD");
+                processUserAdd(buffer, send, creds);
+                break;
+            case SecurityModuleCall::USER_DELETE:
+                LogDebug("call_type: SecurityModuleCall::USER_DELETE");
+                processUserDelete(buffer, send, creds);
+                break;
+            case SecurityModuleCall::POLICY_UPDATE:
+                LogDebug("call_type: SecurityModuleCall::POLICY_UPDATE");
+                processPolicyUpdate(buffer, send, creds);
+                break;
+            case SecurityModuleCall::GET_CONF_POLICY_ADMIN:
+                LogDebug("call_type: SecurityModuleCall::GET_CONF_POLICY_ADMIN");
+                processGetConfiguredPolicy(buffer, send, creds, true);
+                break;
+            case SecurityModuleCall::GET_CONF_POLICY_SELF:
+                LogDebug("call_type: SecurityModuleCall::GET_CONF_POLICY_SELF");
+                processGetConfiguredPolicy(buffer, send, creds, false);
+                break;
+            case SecurityModuleCall::GET_POLICY:
+                LogDebug("call_type: SecurityModuleCall::GET_POLICY");
+                processGetPolicy(buffer, send, creds);
+                break;
+            case SecurityModuleCall::POLICY_GET_DESCRIPTIONS:
+                LogDebug("call_type: SecurityModuleCall::POLICY_GET_DESCRIPTIONS");
+                processPolicyGetDesc(send);
+                break;
+            case SecurityModuleCall::GROUPS_GET:
+                LogDebug("call_type: SecurityModuleCall::GROUPS_GET");
+                processGetForbiddenAndAllowedGroups(buffer, send, creds);
+                break;
+            case SecurityModuleCall::GROUPS_FOR_UID:
+                processGroupsForUid(buffer, send);
+                break;
+            case SecurityModuleCall::APP_HAS_PRIVILEGE:
+                LogDebug("call_type: SecurityModuleCall::APP_HAS_PRIVILEGE");
+                processAppHasPrivilege(buffer, send, creds);
+                break;
+            case SecurityModuleCall::APP_APPLY_PRIVATE_SHARING:
+                LogDebug("call_type: SecurityModuleCall::APP_APPLY_PRIVATE_SHARING");
+                processApplyPrivateSharing(buffer, send, creds);
+                break;
+            case SecurityModuleCall::APP_DROP_PRIVATE_SHARING:
+                LogDebug("call_type: SecurityModuleCall::APP_DROP_PRIVATE_SHARING");
+                processDropPrivateSharing(buffer, send, creds);
+                break;
+            case SecurityModuleCall::PATHS_REGISTER:
+                processPathsRegister(buffer, send, creds);
+                break;
+            case SecurityModuleCall::SHM_APP_NAME:
+                processShmAppName(buffer, send, creds);
+                break;
+            case SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_PROVIDER:
+                LogDebug("call_type: SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_PROVIDER");
+                processGetAppDefinedPrivilegeProvider(buffer, send);
+                break;
+            case SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_LICENSE:
+                LogDebug("call_type: SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_LICENSE");
+                processGetAppDefinedPrivilegeLicense(buffer, send);
+                break;
+            case SecurityModuleCall::GET_CLIENT_PRIVILEGE_LICENSE:
+                LogDebug("call_type: SecurityModuleCall::GET_CLIENT_PRIVILEGE_PROVIDER");
+                processGetClientPrivilegeLicense(buffer, send);
+                break;
+            case SecurityModuleCall::APP_CLEAN_NAMESPACE:
+                LogDebug("call_type: SecurityModuleCall::APP_CLEAN_NAMESPACE");
+                processAppCleanNamespace(buffer, send, creds);
+                break;
+            case SecurityModuleCall::GET_APP_MANIFEST_POLICY:
+                LogDebug("call_type: SecurityModuleCall::GET_APP_MANIFEST_POLICY");
+                processAppGetManifestPolicy(buffer, send, creds);
+                break;
+            case SecurityModuleCall::GET_PROCESS_LABEL:
+                processGetProcessLabel(buffer, send);
+                break;
+            case SecurityModuleCall::PREPARE_APP:
+                prepareApp(buffer, send, creds);
+                break;
+            default:
+                LogError("Invalid call: " << call_type_int);
+                Throw(ServiceException::InvalidAction);
+        }
+        // if we reach this point, the protocol is OK
         LogDebug("Writing response to client, size of serialized response: " << send.SerializedSize());
         m_serviceManager->Write(conn, send.Pop());
-    } else {
-        LogError("Closing socket because of error");
-        m_serviceManager->Close(conn);
+        return true;
+    } Catch(MessageBuffer::Exception::Base) {
+        LogError("Broken protocol.");
+    } Catch(ServiceException::Base) {
+        LogError("Broken protocol.");
+    } catch (const std::exception &e) {
+        LogError("STD exception " << e.what());
+    } catch (...) {
+        LogError("Unknown exception");
     }
 
-    return retval;
+    LogError("Closing socket because of error");
+    m_serviceManager->Close(conn);
+
+    return false;
 }
 
 void Service::processAppGetManifestPolicy(MessageBuffer &buffer, MessageBuffer &send, const Credentials &creds)