Refactoring: there will be only one service 22/26922/1
authorRafal Krypa <r.krypa@samsung.com>
Fri, 29 Aug 2014 16:34:49 +0000 (18:34 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Fri, 29 Aug 2014 18:55:42 +0000 (20:55 +0200)
Security-manager started with installer service implementation. It was
created in a way supporting future creation of other services, working
in separate threads and listening on separate sockets. Such design is
however not planned for this project. The installer service recently
began to implement methods not related to installation, which begged for
some refactoring.
Hereby the installer service is renamed as just "service". There will be
a single socket and single service for all security-manager functions.

Change-Id: I40e939ded1b0e20c4e92c86738fb62ea4acd4a50
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
packaging/security-manager.spec
src/client/client-security-manager.cpp
src/common/include/protocols.h
src/common/protocols.cpp
src/server/CMakeLists.txt
src/server/main/server-main.cpp
src/server/service/include/service.h [moved from src/server/service/include/installer.h with 90% similarity]
src/server/service/service.cpp [moved from src/server/service/installer.cpp with 92% similarity]
systemd/CMakeLists.txt
systemd/security-manager.service.in
systemd/security-manager.socket [moved from systemd/security-manager-installer.socket with 77% similarity]

index 4110dda..c4552c9 100644 (file)
@@ -78,7 +78,7 @@ cp app-rules-template.smack %{buildroot}/%{TZ_SYS_SMACK}
 mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants
 mkdir -p %{buildroot}/%{_unitdir}/sockets.target.wants
 ln -s ../security-manager.service %{buildroot}/%{_unitdir}/multi-user.target.wants/security-manager.service
-ln -s ../security-manager-installer.socket %{buildroot}/%{_unitdir}/sockets.target.wants/security-manager-installer.socket
+ln -s ../security-manager.socket %{buildroot}/%{_unitdir}/sockets.target.wants/security-manager.socket
 
 %clean
 rm -rf %{buildroot}
@@ -123,8 +123,8 @@ fi
 %attr(-,root,root) %{_unitdir}/multi-user.target.wants/security-manager.service
 %attr(-,root,root) %{_unitdir}/security-manager.service
 %attr(-,root,root) %{_unitdir}/security-manager.target
-%attr(-,root,root) %{_unitdir}/sockets.target.wants/security-manager-installer.socket
-%attr(-,root,root) %{_unitdir}/security-manager-installer.socket
+%attr(-,root,root) %{_unitdir}/sockets.target.wants/security-manager.socket
+%attr(-,root,root) %{_unitdir}/security-manager.socket
 %attr(-,root,root) %{TZ_SYS_SMACK}/app-rules-template.smack
 %config(noreplace) %attr(0600,root,root) %{TZ_SYS_DB}/.security-manager.db
 %config(noreplace) %attr(0600,root,root) %{TZ_SYS_DB}/.security-manager.db-journal
index 5f84f16..8ddd408 100644 (file)
@@ -128,7 +128,7 @@ int security_manager_app_install(const app_inst_req *p_req)
         Serialization::Serialize(send, p_req->appPaths);
 
         //send buffer to server
-        int retval = sendToServer(SERVICE_SOCKET_INSTALLER, send.Pop(), recv);
+        int retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv);
         if (retval != SECURITY_MANAGER_API_SUCCESS) {
             LogError("Error in sendToServer. Error code: " << retval);
             return SECURITY_MANAGER_ERROR_UNKNOWN;
@@ -166,7 +166,7 @@ int security_manager_app_uninstall(const app_inst_req *p_req)
         Serialization::Serialize(send, p_req->appId);
 
         //send buffer to server
-        int retval = sendToServer(SERVICE_SOCKET_INSTALLER, send.Pop(), recv);
+        int retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv);
         if (retval != SECURITY_MANAGER_API_SUCCESS) {
             LogError("Error in sendToServer. Error code: " << retval);
             return SECURITY_MANAGER_ERROR_UNKNOWN;
@@ -207,7 +207,7 @@ int security_manager_get_app_pkgid(char **pkg_id, const char *app_id)
         Serialization::Serialize(send, std::string(app_id));
 
         //send buffer to server
-        int retval = sendToServer(SERVICE_SOCKET_INSTALLER, send.Pop(), recv);
+        int retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv);
         if (retval != SECURITY_MANAGER_API_SUCCESS) {
             LogDebug("Error in sendToServer. Error code: " << retval);
             return SECURITY_MANAGER_ERROR_UNKNOWN;
index fadc46c..c60f3b1 100644 (file)
@@ -109,7 +109,7 @@ struct app_inst_req {
 
 namespace SecurityManager {
 
-extern char const * const SERVICE_SOCKET_INSTALLER;
+extern char const * const SERVICE_SOCKET;
 
 enum class SecurityModuleCall
 {
index 59bf302..798b9d6 100644 (file)
 namespace SecurityManager {
 
 #define SOCKET_PATH_PREFIX "/run/"
-#define SOCKET_PATH_PREFIX_SECURITY_MANAGER SOCKET_PATH_PREFIX "security-manager/"
 
-char const * const SERVICE_SOCKET_INSTALLER =
-        SOCKET_PATH_PREFIX_SECURITY_MANAGER "security-manager-installer.socket";
+char const * const SERVICE_SOCKET =
+        SOCKET_PATH_PREFIX "security-manager.socket";
 
 } // namespace SecurityManager
 
index 65cc36a..8595111 100644 (file)
@@ -35,9 +35,9 @@ SET(SERVER_SOURCES
     ${SERVER_PATH}/main/generic-socket-manager.cpp
     ${SERVER_PATH}/main/socket-manager.cpp
     ${SERVER_PATH}/main/server-main.cpp
+    ${SERVER_PATH}/service/service.cpp
     ${SERVER_PATH}/service/smack-rules.cpp
     ${SERVER_PATH}/service/smack-labels.cpp
-    ${SERVER_PATH}/service/installer.cpp
     ${SERVER_PATH}/service/cynara.cpp
     ${SERVER_PATH}/db/privilege_db.cpp
     ${DPL_PATH}/core/src/errno_string.cpp
index 6f67efa..16f03ba 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <socket-manager.h>
 
-#include <installer.h>
+#include <service.h>
 
 IMPLEMENT_SAFE_SINGLETON(SecurityManager::Log::LogSystem);
 
@@ -78,7 +78,7 @@ int main(void) {
         LogInfo("Start!");
         SecurityManager::SocketManager manager;
 
-        REGISTER_SOCKET_SERVICE(manager, SecurityManager::InstallerService);
+        REGISTER_SOCKET_SERVICE(manager, SecurityManager::Service);
 
         manager.MainLoop();
     }
similarity index 90%
rename from src/server/service/include/installer.h
rename to src/server/service/include/service.h
index 1a7caf2..13e40ee 100644 (file)
  *  limitations under the License
  */
 /*
- * @file        installer.h
+ * @file        service.h
  * @author      Michal Witanowski <m.witanowski@samsung.com>
  * @author      Rafal Krypa <r.krypa@samsung.com>
- * @brief       Implementation of installer service
+ * @brief       Implementation of security-manager service
  */
 
-#ifndef _SECURITY_MANAGER_INSTALLER_
-#define _SECURITY_MANAGER_INSTALLER_
+#ifndef _SECURITY_MANAGER_SERVICE_
+#define _SECURITY_MANAGER_SERVICE_
 
 #include <service-thread.h>
 #include <generic-socket-manager.h>
 
 namespace SecurityManager {
 
-class InstallerException
+class ServiceException
 {
 public:
     DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
     DECLARE_EXCEPTION_TYPE(Base, InvalidAction)
 };
 
-class InstallerService :
+class Service :
     public SecurityManager::GenericSocketService,
-    public SecurityManager::ServiceThread<InstallerService>
+    public SecurityManager::ServiceThread<Service>
 {
 public:
-    InstallerService();
+    Service();
     ServiceDescriptionVector GetServiceDescription();
 
     DECLARE_THREAD_EVENT(AcceptEvent, accept)
@@ -104,4 +104,4 @@ private:
 
 } // namespace SecurityManager
 
-#endif // _SECURITY_MANAGER_INSTALLER_
+#endif // _SECURITY_MANAGER_SERVICE_
similarity index 92%
rename from src/server/service/installer.cpp
rename to src/server/service/service.cpp
index 3e9f124..664235f 100644 (file)
  *  limitations under the License
  */
 /*
- * @file        installer.cpp
+ * @file        service.cpp
  * @author      Michal Witanowski <m.witanowski@samsung.com>
  * @author      Jacek Bukarewicz <j.bukarewicz@samsung.com>
  * @author      Rafal Krypa <r.krypa@samsung.com>
- * @brief       Implementation of installer service.
+ * @brief       Implementation of security-manager service.
  */
 
 #include <dpl/log/log.h>
@@ -32,7 +32,7 @@
 #include <limits.h>
 #include <cstring>
 
-#include "installer.h"
+#include "service.h"
 #include "protocols.h"
 #include "security-manager.h"
 #include "smack-common.h"
 
 namespace SecurityManager {
 
-const InterfaceID INSTALLER_IFACE = 0;
+const InterfaceID IFACE = 1;
 
 
-InstallerService::InstallerService()
+Service::Service()
 {
 }
 
-GenericSocketService::ServiceDescriptionVector InstallerService::GetServiceDescription()
+GenericSocketService::ServiceDescriptionVector Service::GetServiceDescription()
 {
     return ServiceDescriptionVector {
-        {SERVICE_SOCKET_INSTALLER, "security-manager::installer", INSTALLER_IFACE},
+        {SERVICE_SOCKET, "security-manager", IFACE},
     };
 }
 
-void InstallerService::accept(const AcceptEvent &event)
+void Service::accept(const AcceptEvent &event)
 {
     LogDebug("Accept event. ConnectionID.sock: " << event.connectionID.sock <<
              " ConnectionID.counter: " << event.connectionID.counter <<
@@ -67,7 +67,7 @@ void InstallerService::accept(const AcceptEvent &event)
     info.interfaceID = event.interfaceID;
 }
 
-void InstallerService::write(const WriteEvent &event)
+void Service::write(const WriteEvent &event)
 {
     LogDebug("WriteEvent. ConnectionID: " << event.connectionID.sock <<
              " Size: " << event.size <<
@@ -77,7 +77,7 @@ void InstallerService::write(const WriteEvent &event)
         m_serviceManager->Close(event.connectionID);
 }
 
-void InstallerService::process(const ReadEvent &event)
+void Service::process(const ReadEvent &event)
 {
     LogDebug("Read event for counter: " << event.connectionID.counter);
     auto &info = m_connectionInfoMap[event.connectionID.counter];
@@ -88,7 +88,7 @@ void InstallerService::process(const ReadEvent &event)
     while (processOne(event.connectionID, info.buffer, info.interfaceID));
 }
 
-void InstallerService::close(const CloseEvent &event)
+void Service::close(const CloseEvent &event)
 {
     LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
     m_connectionInfoMap.erase(event.connectionID.counter);
@@ -107,7 +107,7 @@ static bool getPeerUserID(int sock, uid_t *uid) {
     return false;
 }
 
-bool InstallerService::processOne(const ConnectionID &conn, MessageBuffer &buffer,
+bool Service::processOne(const ConnectionID &conn, MessageBuffer &buffer,
                                   InterfaceID interfaceID)
 {
     LogDebug("Iteration begin. Interface = " << interfaceID);
@@ -128,7 +128,7 @@ bool InstallerService::processOne(const ConnectionID &conn, MessageBuffer &buffe
         return false;
     }
 
-    if (INSTALLER_IFACE == interfaceID) {
+    if (IFACE == interfaceID) {
         Try {
             // deserialize API call type
             int call_type_int;
@@ -149,13 +149,13 @@ bool InstallerService::processOne(const ConnectionID &conn, MessageBuffer &buffe
                     break;
                 default:
                     LogError("Invalid call: " << call_type_int);
-                    Throw(InstallerException::InvalidAction);
+                    Throw(ServiceException::InvalidAction);
             }
             // if we reach this point, the protocol is OK
             retval = true;
         } Catch (MessageBuffer::Exception::Base) {
             LogError("Broken protocol.");
-        } Catch (InstallerException::Base) {
+        } Catch (ServiceException::Base) {
             LogError("Broken protocol.");
         } catch (std::exception &e) {
             LogError("STD exception " << e.what());
@@ -235,7 +235,7 @@ static inline bool installRequestAuthCheck(const app_inst_req &req, uid_t uid)
     return true;
 }
 
-bool InstallerService::processAppInstall(MessageBuffer &buffer, MessageBuffer &send, uid_t uid)
+bool Service::processAppInstall(MessageBuffer &buffer, MessageBuffer &send, uid_t uid)
 {
     bool pkgIdIsNew = false;
     std::vector<std::string> addedPermissions;
@@ -332,7 +332,7 @@ error_label:
     return false;
 }
 
-bool InstallerService::processAppUninstall(MessageBuffer &buffer, MessageBuffer &send, uid_t uid)
+bool Service::processAppUninstall(MessageBuffer &buffer, MessageBuffer &send, uid_t uid)
 {
     // deserialize request data
     std::string appId;
@@ -408,7 +408,7 @@ error_label:
     return false;
 }
 
-bool InstallerService::processGetPkgId(MessageBuffer &buffer, MessageBuffer &send)
+bool Service::processGetPkgId(MessageBuffer &buffer, MessageBuffer &send)
 {
     // deserialize request data
     std::string appId;
index 9c2ac54..66af5dd 100644 (file)
@@ -3,7 +3,7 @@ CONFIGURE_FILE(security-manager.service.in security-manager.service @ONLY)
 INSTALL(FILES
     security-manager.service
     security-manager.target
-    security-manager-installer.socket
+    security-manager.socket
     DESTINATION
     ${SYSTEMD_INSTALL_DIR}
 )
index df0b077..de58043 100644 (file)
@@ -5,7 +5,7 @@ Description=Start the security manager
 Type=notify
 ExecStart=@BIN_INSTALL_DIR@/security-manager
 
-Sockets=security-manager-installer.socket
+Sockets=security-manager.socket
 
 [Install]
 WantedBy=multi-user.target
similarity index 77%
rename from systemd/security-manager-installer.socket
rename to systemd/security-manager.socket
index e851c79..c0590ad 100644 (file)
@@ -1,5 +1,5 @@
 [Socket]
-ListenStream=/run/security-manager/security-manager-installer.socket
+ListenStream=/run/security-manager.socket
 SocketMode=0777
 SmackLabelIPIn=*
 SmackLabelIPOut=@