Remove PrivilegeDb singleton 66/91466/1
authorZbigniew Jasinski <z.jasinski@samsung.com>
Fri, 7 Oct 2016 16:24:37 +0000 (18:24 +0200)
committerZbigniew Jasinski <z.jasinski@samsung.com>
Fri, 7 Oct 2016 16:25:13 +0000 (18:25 +0200)
Change-Id: Iabec786bdcbb403af0b4d402b96509f90c17f9f3
Signed-off-by: Zbigniew Jasinski <z.jasinski@samsung.com>
src/client/CMakeLists.txt
src/common/include/privilege_db.h
src/common/include/service_impl.h
src/common/service_impl.cpp

index 0dd8280203d5c283541ea138f23bd6c08f4aa669..aaaa1cf4bbfa5fb23c6a4d3c870db164a2026bf6 100644 (file)
@@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(
     ${CLIENT_PATH}/include
     ${DPL_PATH}/core/include
     ${DPL_PATH}/log/include
+    ${DPL_PATH}/db/include
     )
 
 SET(CLIENT_SOURCES
index fda42a627808ef038896323bc449a939d7d29563..5750e230358e3a203c72f582a5b9f45769047c05 100644 (file)
@@ -88,13 +88,6 @@ class PrivilegeDb {
      */
 
 private:
-    /**
-     * Constructor
-     * @exception DB::SqlConnection::Exception::IOError on problems with database access
-     *
-     */
-    PrivilegeDb(const std::string &path = std::string(PRIVILEGE_DB_PATH));
-
     /**
      * Wrapper for prepared statement, it will reset statement at destruction.
      */
@@ -176,6 +169,12 @@ public:
     };
 
     ~PrivilegeDb(void);
+    /**
+     * Constructor
+     * @exception DB::SqlConnection::Exception::IOError on problems with database access
+     *
+     */
+    PrivilegeDb(const std::string &path = std::string(PRIVILEGE_DB_PATH));
 
     static PrivilegeDb &getInstance();
 
index 8ff4cffc29c6fc11bf7b749a53f1424044e96009..5d13d664ba71bcd34247c27350616ba2c57a6e85 100644 (file)
@@ -34,6 +34,7 @@
 #include "security-manager.h"
 #include "smack-rules.h"
 #include "protocols.h"
+#include "privilege_db.h"
 
 namespace SecurityManager {
 
@@ -262,12 +263,12 @@ private:
     static bool pathsCheck(const pkg_paths &requestedPaths,
                            const std::vector<std::string> &allowedDirs);
 
-    static int labelPaths(const pkg_paths &paths,
+    int labelPaths(const pkg_paths &paths,
                           const std::string &pkgName,
                           app_install_type installationType,
                           const uid_t &uid);
 
-    static void getPkgLabels(const std::string &pkgName, SmackRules::Labels &pkgsLabels);
+    void getPkgLabels(const std::string &pkgName, SmackRules::Labels &pkgsLabels);
 
     static bool isSharedRO(const pkg_paths& paths);
 
@@ -286,7 +287,18 @@ private:
 
     void updatePermissibleSet(uid_t uid, int type);
 
+    std::string getAppProcessLabel(const std::string &appName, const std::string &pkgName);
+
+    std::string getAppProcessLabel(const std::string &appName);
+
+    bool sharingExists(const std::string &targetAppName, const std::string &path);
+
+    void getPkgsProcessLabels(const std::vector<PkgInfo> &pkgsInfo, SmackRules::PkgsLabels &pkgsLabels);
+
+    int validatePolicy(policy_entry &policyEntry, std::string uidStr, bool &forAdmin, CynaraAdminPolicy &cyap);
+
     Cynara m_cynara;
+    PrivilegeDb m_priviligeDb;
 
 };
 
index eea74bf8b588a4cfe524b6cc8f9aa592a461ef9a..c9ddd57fdc7e4694a50f05ce9e28bcf4d4906d85 100644 (file)
@@ -60,24 +60,50 @@ namespace SecurityManager {
 
 namespace {
 
-static std::string getAppProcessLabel(const std::string &appName, const std::string &pkgName)
+bool fileExists(const std::string &path) {
+    struct stat buffer;
+    return (stat(path.c_str(), &buffer) == 0) && S_ISREG(buffer.st_mode);
+}
+
+class ScopedTransaction {
+public:
+    ScopedTransaction(PrivilegeDb &priviligeDb) : m_isCommited(false), m_priviligeDb(priviligeDb) {
+        m_priviligeDb.BeginTransaction();
+    }
+    ScopedTransaction(const ScopedTransaction &other) = delete;
+    ScopedTransaction& operation(const ScopedTransaction &other) = delete;
+
+    void commit() {
+        m_priviligeDb.CommitTransaction();
+        m_isCommited = true;
+    }
+    ~ScopedTransaction() {
+        if (!m_isCommited) {
+            try {
+                m_priviligeDb.RollbackTransaction();
+            } catch (const SecurityManager::Exception &e) {
+                LogError("Transaction rollback failed: " << e.GetMessage());
+            } catch(...) {
+                LogError("Transaction rollback failed with unknown exception");
+            }
+        }
+    }
+private:
+    bool m_isCommited;
+    PrivilegeDb &m_priviligeDb;
+};
+
+} // end of anonymous namespace
+
+ServiceImpl::ServiceImpl()
 {
-    bool isPkgHybrid = PrivilegeDb::getInstance().IsPackageHybrid(pkgName);
-    return SmackLabels::generateProcessLabel(appName, pkgName, isPkgHybrid);
 }
 
-static std::string getAppProcessLabel(const std::string &appName)
+ServiceImpl::~ServiceImpl()
 {
-    std::string pkgName;
-    PrivilegeDb::getInstance().GetAppPkgName(appName, pkgName);
-    if (pkgName.empty()) {
-        LogWarning("Cannot create label for unknown application: " << appName);
-        return "";
-    }
-    return getAppProcessLabel(appName, pkgName);
 }
 
-static inline int validatePolicy(policy_entry &policyEntry, std::string uidStr, bool &forAdmin, CynaraAdminPolicy &cyap)
+int ServiceImpl::validatePolicy(policy_entry &policyEntry, std::string uidStr, bool &forAdmin, CynaraAdminPolicy &cyap)
 {
     LogDebug("Authenticating and validating policy update request for user with id: " << uidStr);
     LogDebug("[policy_entry] app: " << policyEntry.appName
@@ -164,51 +190,36 @@ static inline int validatePolicy(policy_entry &policyEntry, std::string uidStr,
     return SECURITY_MANAGER_SUCCESS;
 }
 
-bool sharingExists(const std::string &targetAppName, const std::string &path)
+std::string ServiceImpl::getAppProcessLabel(const std::string &appName, const std::string &pkgName)
 {
-    int targetPathCount;
-    PrivilegeDb::getInstance().GetTargetPathSharingCount(targetAppName, path, targetPathCount);
-    return targetPathCount != 0;
-}
-
-bool fileExists(const std::string &path) {
-    struct stat buffer;
-    return (stat(path.c_str(), &buffer) == 0) && S_ISREG(buffer.st_mode);
+    bool isPkgHybrid = m_priviligeDb.IsPackageHybrid(pkgName);
+    return SmackLabels::generateProcessLabel(appName, pkgName, isPkgHybrid);
 }
 
-class ScopedTransaction {
-public:
-    ScopedTransaction() : m_isCommited(false) {
-        PrivilegeDb::getInstance().BeginTransaction();
+std::string ServiceImpl::getAppProcessLabel(const std::string &appName)
+{
+    std::string pkgName;
+    m_priviligeDb.GetAppPkgName(appName, pkgName);
+    if (pkgName.empty()) {
+        LogWarning("Cannot create label for unknown application: " << appName);
+        return "";
     }
-    ScopedTransaction(const ScopedTransaction &other) = delete;
-    ScopedTransaction& operation(const ScopedTransaction &other) = delete;
+    return getAppProcessLabel(appName, pkgName);
+}
 
-    void commit() {
-        PrivilegeDb::getInstance().CommitTransaction();
-        m_isCommited = true;
-    }
-    ~ScopedTransaction() {
-        if (!m_isCommited) {
-            try {
-                PrivilegeDb::getInstance().RollbackTransaction();
-            } catch (const SecurityManager::Exception &e) {
-                LogError("Transaction rollback failed: " << e.GetMessage());
-            } catch(...) {
-                LogError("Transaction rollback failed with unknown exception");
-            }
-        }
-    }
-private:
-    bool m_isCommited;
-};
+bool ServiceImpl::sharingExists(const std::string &targetAppName, const std::string &path)
+{
+    int targetPathCount;
+    m_priviligeDb.GetTargetPathSharingCount(targetAppName, path, targetPathCount);
+    return targetPathCount != 0;
+}
 
-void getPkgsProcessLabels(const std::vector<PkgInfo> &pkgsInfo, SmackRules::PkgsLabels &pkgsLabels)
+void ServiceImpl::getPkgsProcessLabels(const std::vector<PkgInfo> &pkgsInfo, SmackRules::PkgsLabels &pkgsLabels)
 {
     pkgsLabels.resize(pkgsInfo.size());
     for (size_t i = 0; i < pkgsInfo.size(); ++i) {
         pkgsLabels[i].first = pkgsInfo[i].name;
-        PrivilegeDb::getInstance().GetPkgApps(pkgsLabels[i].first, pkgsLabels[i].second);
+        m_priviligeDb.GetPkgApps(pkgsLabels[i].first, pkgsLabels[i].second);
         for (auto &appName : pkgsLabels[i].second) {
             std::string label = SmackLabels::generateProcessLabel(appName, pkgsLabels[i].first,
                                                                   pkgsInfo[i].hybrid);
@@ -217,16 +228,6 @@ void getPkgsProcessLabels(const std::vector<PkgInfo> &pkgsInfo, SmackRules::Pkgs
     }
 }
 
-} // end of anonymous namespace
-
-ServiceImpl::ServiceImpl()
-{
-}
-
-ServiceImpl::~ServiceImpl()
-{
-}
-
 bool ServiceImpl::authenticate(const Credentials &creds, const std::string &privilege)
 {
     if (creds.authenticated)
@@ -391,12 +392,12 @@ int ServiceImpl::labelPaths(const pkg_paths &paths,
         std::string pkgBasePath;
         int authorId;
 
-        if (!PrivilegeDb::getInstance().PkgNameExists(pkgName)) {
+        if (!m_priviligeDb.PkgNameExists(pkgName)) {
             LogError("No such package: " << pkgName);
             return SECURITY_MANAGER_ERROR_INPUT_PARAM;
         }
 
-        PrivilegeDb::getInstance().GetPkgAuthorId(pkgName, authorId);
+        m_priviligeDb.GetPkgAuthorId(pkgName, authorId);
 
         if (!getUserPkgDir(uid, pkgName, installationType, pkgBasePath))
             return SECURITY_MANAGER_ERROR_SERVER_ERROR;
@@ -470,10 +471,10 @@ bool ServiceImpl::isSharedRO(const pkg_paths& paths)
 
 void ServiceImpl::getPkgLabels(const std::string &pkgName, SmackRules::Labels &pkgsLabels)
 {
-    bool isPkgHybrid = PrivilegeDb::getInstance().IsPackageHybrid(pkgName);
+    bool isPkgHybrid = m_priviligeDb.IsPackageHybrid(pkgName);
     if (isPkgHybrid) {
         std::vector<std::string> apps;
-        PrivilegeDb::getInstance().GetPkgApps(pkgName, apps);
+        m_priviligeDb.GetPkgApps(pkgName, apps);
         for (auto &app : apps) {
             auto appLabel = SmackLabels::generateProcessLabel(app, pkgName, isPkgHybrid);
             app = appLabel;
@@ -487,7 +488,7 @@ void ServiceImpl::getPkgLabels(const std::string &pkgName, SmackRules::Labels &p
 void ServiceImpl::updatePermissibleSet(uid_t uid, int type)
 {
     std::vector<std::string> userPkgs;
-    PrivilegeDb::getInstance().GetUserPkgs(uid, userPkgs);
+    m_priviligeDb.GetUserPkgs(uid, userPkgs);
     std::vector<std::string> labelsForUser;
     for (const auto &pkg : userPkgs) {
         std::vector<std::string> pkgLabels;
@@ -529,49 +530,49 @@ int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req)
         LogDebug("Generated install parameters: app label: " << appLabel <<
                  ", pkg label: " << pkgLabel);
 
-        PrivilegeDb::getInstance().BeginTransaction();
+        m_priviligeDb.BeginTransaction();
 
-        PrivilegeDb::getInstance().AddApplication(req.appName, req.pkgName, req.uid,
+        m_priviligeDb.AddApplication(req.appName, req.pkgName, req.uid,
                                                   req.tizenVersion, req.authorName, req.isHybrid);
         /* Get all application ids in the package to generate rules withing the package */
         getPkgLabels(req.pkgName, pkgLabels);
-        PrivilegeDb::getInstance().GetPkgAuthorId(req.pkgName, authorId);
+        m_priviligeDb.GetPkgAuthorId(req.pkgName, authorId);
         CynaraAdmin::getInstance().UpdateAppPolicy(appLabel, cynaraUserStr, req.privileges, isPrivilegePrivacy);
 
         if (hasSharedRO)
-            PrivilegeDb::getInstance().SetSharedROPackage(req.pkgName);
+            m_priviligeDb.SetSharedROPackage(req.pkgName);
 
-        PrivilegeDb::getInstance().GetPackagesInfo(pkgsInfo);
+        m_priviligeDb.GetPackagesInfo(pkgsInfo);
         getPkgsProcessLabels(pkgsInfo, pkgsProcessLabels);
 
         // WTF? Why this commit is here? Shouldn't it be at the end of this function?
-        PrivilegeDb::getInstance().CommitTransaction();
+        m_priviligeDb.CommitTransaction();
         LogDebug("Application installation commited to database");
         updatePermissibleSet(req.uid, req.installationType);
     } catch (const PrivilegeDb::Exception::IOError &e) {
         LogError("Cannot access application database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const PrivilegeDb::Exception::ConstraintError &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Application conflicts with existing one: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_INPUT_PARAM;
     } catch (const PrivilegeDb::Exception::InternalError &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while saving application info to database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const CynaraException::Base &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while setting Cynara rules for application: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const PermissibleSet::PermissibleSetException::Base &e) {
         LogError("Error while updating permissible file: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const SmackException::InvalidLabel &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while generating Smack labels: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const std::bad_alloc &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Memory allocation while setting Cynara rules for application: " << e.what());
         return SECURITY_MANAGER_ERROR_MEMORY;
     }
@@ -635,18 +636,18 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &&req)
     }
 
     try {
-        PrivilegeDb::getInstance().BeginTransaction();
+        m_priviligeDb.BeginTransaction();
         if (req.pkgName.empty())
-            PrivilegeDb::getInstance().GetAppPkgName(req.appName, req.pkgName);
+            m_priviligeDb.GetAppPkgName(req.appName, req.pkgName);
 
         if (req.pkgName.empty()) {
             LogWarning("Application " << req.appName <<
                 " not found in database while uninstalling");
-            PrivilegeDb::getInstance().RollbackTransaction();
+            m_priviligeDb.RollbackTransaction();
             return SECURITY_MANAGER_SUCCESS;
         }
 
-        isPkgHybrid = PrivilegeDb::getInstance().IsPackageHybrid(req.pkgName);
+        isPkgHybrid = m_priviligeDb.IsPackageHybrid(req.pkgName);
         processLabel = getAppProcessLabel(req.appName, req.pkgName);
         LogDebug("Generated uninstall parameters: pkgName=" << req.pkgName
             << " Smack label=" << processLabel);
@@ -654,18 +655,18 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &&req)
         /* Before we remove the app from the database, let's fetch all apps in the package
             that this app belongs to, this will allow us to remove all rules withing the
             package that the app appears in */
-        PrivilegeDb::getInstance().GetPkgAuthorId(req.pkgName, authorId);
+        m_priviligeDb.GetPkgAuthorId(req.pkgName, authorId);
         getPkgLabels(req.pkgName, pkgLabels);
-        PrivilegeDb::getInstance().GetAppVersion(req.appName, req.tizenVersion);
-        PrivilegeDb::getInstance().GetPrivateSharingForOwner(req.appName, asOwnerSharing);
-        PrivilegeDb::getInstance().GetPrivateSharingForTarget(req.appName, asTargetSharing);
+        m_priviligeDb.GetAppVersion(req.appName, req.tizenVersion);
+        m_priviligeDb.GetPrivateSharingForOwner(req.appName, asOwnerSharing);
+        m_priviligeDb.GetPrivateSharingForTarget(req.appName, asTargetSharing);
 
         for (const auto &targetPathsInfo : asOwnerSharing) {
             const auto &targetAppName = targetPathsInfo.first;
             const auto &paths = targetPathsInfo.second;
             // Squash sharing - change counter to 1, so dropPrivatePathSharing will completely clean it
             for (const auto &path : paths) {
-                PrivilegeDb::getInstance().SquashSharing(targetAppName, path);
+                m_priviligeDb.SquashSharing(targetAppName, path);
                 auto targetAppLabel = getAppProcessLabel(targetAppName);
                 int ret = dropOnePrivateSharing(req.appName, req.pkgName, pkgLabels,
                                                 targetAppName, targetAppLabel, path);
@@ -682,10 +683,10 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &&req)
             // Squash sharing - change counter to 1, so dropPrivatePathSharing will completely clean it
             std::string ownerPkgName;
             SmackRules::Labels ownerPkgLabels;
-            PrivilegeDb::getInstance().GetAppPkgName(ownerAppName, ownerPkgName);
+            m_priviligeDb.GetAppPkgName(ownerAppName, ownerPkgName);
             getPkgLabels(ownerPkgName, ownerPkgLabels);
             for (const auto &path : paths) {
-                PrivilegeDb::getInstance().SquashSharing(req.appName, path);
+                m_priviligeDb.SquashSharing(req.appName, path);
                     int ret = dropOnePrivateSharing(ownerAppName, ownerPkgName, ownerPkgLabels,
                                                     req.appName, processLabel, path);
                     if (ret != SECURITY_MANAGER_SUCCESS) {
@@ -695,36 +696,36 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &&req)
                 }
         }
 
-        PrivilegeDb::getInstance().RemoveApplication(req.appName, req.uid, removeApp, removePkg, removeAuthor);
+        m_priviligeDb.RemoveApplication(req.appName, req.uid, removeApp, removePkg, removeAuthor);
 
-        PrivilegeDb::getInstance().GetPackagesInfo(pkgsInfo);
+        m_priviligeDb.GetPackagesInfo(pkgsInfo);
         getPkgsProcessLabels(pkgsInfo, pkgsProcessLabels);
 
         CynaraAdmin::getInstance().UpdateAppPolicy(processLabel, cynaraUserStr,
                                                    std::vector<std::string>(), isPrivilegePrivacy);
-        PrivilegeDb::getInstance().CommitTransaction();
+        m_priviligeDb.CommitTransaction();
         LogDebug("Application uninstallation commited to database");
         updatePermissibleSet(req.uid, req.installationType);
     } catch (const PrivilegeDb::Exception::IOError &e) {
         LogError("Cannot access application database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const PrivilegeDb::Exception::Base &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while removing application info from database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const CynaraException::Base &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while setting Cynara rules for application: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const PermissibleSet::PermissibleSetException::Base &e) {
         LogError("Error while updating permissible file: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const SmackException::InvalidLabel &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while generating Smack labels: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const std::bad_alloc &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Memory allocation while setting Cynara rules for application: " << e.what());
         return SECURITY_MANAGER_ERROR_MEMORY;
     }
@@ -775,7 +776,7 @@ int ServiceImpl::getPkgName(const std::string &appName, std::string &pkgName)
     LogDebug("appName: " << appName);
 
     try {
-        PrivilegeDb::getInstance().GetAppPkgName(appName, pkgName);
+        m_priviligeDb.GetAppPkgName(appName, pkgName);
         if (pkgName.empty()) {
             LogWarning("Application " << appName << " not found in database");
             return SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT;
@@ -816,7 +817,7 @@ int ServiceImpl::getAppGroups(const Credentials &creds, const std::string &appNa
         std::string pidStr = std::to_string(creds.pid);
         for (const auto &privilege : privileges) {
             std::vector<std::string> privGroups;
-            PrivilegeDb::getInstance().GetPrivilegeGroups(privilege, privGroups);
+            m_priviligeDb.GetPrivilegeGroups(privilege, privGroups);
             if (!privGroups.empty()) {
                 LogDebug("Considering privilege " << privilege << " with " <<
                     privGroups.size() << " groups assigned");
@@ -881,7 +882,7 @@ int ServiceImpl::userDelete(const Credentials &creds, uid_t uidDeleted)
     /*Uninstall all user apps*/
     std::vector<std::string> userApps;
     try {
-        PrivilegeDb::getInstance().GetUserApps(uidDeleted, userApps);
+        m_priviligeDb.GetUserApps(uidDeleted, userApps);
         PermissibleSet::removeUserPermissibleFile(uidDeleted);
     } catch (const PrivilegeDb::Exception::Base &e) {
         LogError("Error while getting user apps from database: " << e.DumpToString());
@@ -1050,7 +1051,7 @@ int ServiceImpl::getConfiguredPolicy(const Credentials &creds, bool forAdmin,
                     if (filter.appName == SECURITY_MANAGER_ANY) {
                         // If user requested policy for all apps, we have to demangle pkgName to
                         // set of appNames in case of non-hybrid apps
-                        PrivilegeDb::getInstance().GetPkgApps(pkgName, appNames);
+                        m_priviligeDb.GetPkgApps(pkgName, appNames);
                     } else {
                         // If user requested policy for specific appName, we have to copy
                         // appName from filter for non-hybrid apps
@@ -1154,7 +1155,7 @@ int ServiceImpl::getPolicy(const Credentials &creds, const policy_entry &filter,
                 LogDebug("Limitting Cynara query to app: " << filter.appName);
                 listOfApps.push_back(filter.appName);
             } else {
-                PrivilegeDb::getInstance().GetUserApps(user, listOfApps);
+                m_priviligeDb.GetUserApps(user, listOfApps);
                 LogDebug("Found apps: " << listOfApps.size());
             };
 
@@ -1255,7 +1256,7 @@ int ServiceImpl::policyGetGroups(std::vector<std::string> &groups)
     int ret = SECURITY_MANAGER_SUCCESS;
 
     try {
-        PrivilegeDb::getInstance().GetGroups(groups);
+        m_priviligeDb.GetGroups(groups);
     } catch (const PrivilegeDb::Exception::Base &e) {
         LogError("Error while getting groups from database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
@@ -1299,7 +1300,7 @@ int ServiceImpl::policyGroupsForUid(uid_t uid, std::vector<std::string> &groups)
         }
 
         std::vector<std::pair<std::string, std::string>> group2privVector;
-        PrivilegeDb::getInstance().GetGroupsRelatedPrivileges(group2privVector);
+        m_priviligeDb.GetGroupsRelatedPrivileges(group2privVector);
 
         for (const auto &g2p : group2privVector) {
             CynaraAdmin::getInstance().Check(CYNARA_ADMIN_ANY, uidStr, g2p.second,
@@ -1356,10 +1357,10 @@ int ServiceImpl::dropOnePrivateSharing(
     int errorRet;
     try {
         int targetPathCount, pathCount, ownerTargetCount;
-        PrivilegeDb::getInstance().DropPrivateSharing(ownerAppName, targetAppName, path);
-        PrivilegeDb::getInstance().GetTargetPathSharingCount(targetAppName, path, targetPathCount);
-        PrivilegeDb::getInstance().GetPathSharingCount(path, pathCount);
-        PrivilegeDb::getInstance().GetOwnerTargetSharingCount(ownerAppName, targetAppName, ownerTargetCount);
+        m_priviligeDb.DropPrivateSharing(ownerAppName, targetAppName, path);
+        m_priviligeDb.GetTargetPathSharingCount(targetAppName, path, targetPathCount);
+        m_priviligeDb.GetPathSharingCount(path, pathCount);
+        m_priviligeDb.GetOwnerTargetSharingCount(ownerAppName, targetAppName, ownerTargetCount);
         if (targetPathCount > 0) {
             return SECURITY_MANAGER_SUCCESS;
         }
@@ -1409,13 +1410,13 @@ int ServiceImpl::applyPrivatePathSharing(
             return SECURITY_MANAGER_ERROR_ACCESS_DENIED;
         }
 
-        PrivilegeDb::getInstance().GetAppPkgName(ownerAppName, ownerPkgName);
+        m_priviligeDb.GetAppPkgName(ownerAppName, ownerPkgName);
         if (ownerPkgName.empty()) {
             LogError(ownerAppName << " is not an installed application");
             return SECURITY_MANAGER_ERROR_APP_UNKNOWN;
         }
 
-        PrivilegeDb::getInstance().GetAppPkgName(targetAppName, targetPkgName);
+        m_priviligeDb.GetAppPkgName(targetAppName, targetPkgName);
         if (targetPkgName.empty()) {
             LogError(targetAppName << " is not an installed application");
             return SECURITY_MANAGER_ERROR_APP_UNKNOWN;
@@ -1444,14 +1445,14 @@ int ServiceImpl::applyPrivatePathSharing(
         targetAppLabel = getAppProcessLabel(targetAppName);
         getPkgLabels(ownerPkgName, pkgsLabels);
 
-        ScopedTransaction trans;
+        ScopedTransaction trans(m_priviligeDb);
         for (const auto &path : paths) {
             int targetPathCount, pathCount, ownerTargetCount;
-            PrivilegeDb::getInstance().GetTargetPathSharingCount(targetAppName, path, targetPathCount);
-            PrivilegeDb::getInstance().GetPathSharingCount(path, pathCount);
-            PrivilegeDb::getInstance().GetOwnerTargetSharingCount(ownerAppName, targetAppName, ownerTargetCount);
+            m_priviligeDb.GetTargetPathSharingCount(targetAppName, path, targetPathCount);
+            m_priviligeDb.GetPathSharingCount(path, pathCount);
+            m_priviligeDb.GetOwnerTargetSharingCount(ownerAppName, targetAppName, ownerTargetCount);
             std::string pathLabel = SmackLabels::generateSharedPrivateLabel(ownerPkgName, path);
-            PrivilegeDb::getInstance().ApplyPrivateSharing(ownerAppName, targetAppName, path, pathLabel);
+            m_priviligeDb.ApplyPrivateSharing(ownerAppName, targetAppName, path, pathLabel);
             sharingAdded++;
             if (targetPathCount > 0) {
                 //Nothing to do, only counter needed incrementing
@@ -1505,14 +1506,14 @@ int ServiceImpl::dropPrivatePathSharing(
         }
 
         std::string ownerPkgName;
-        PrivilegeDb::getInstance().GetAppPkgName(ownerAppName, ownerPkgName);
+        m_priviligeDb.GetAppPkgName(ownerAppName, ownerPkgName);
         if (ownerPkgName.empty()) {
             LogError(ownerAppName << " is not an installed application");
             return SECURITY_MANAGER_ERROR_APP_UNKNOWN;
         }
 
         std::string targetPkgName;
-        PrivilegeDb::getInstance().GetAppPkgName(targetAppName, targetPkgName);
+        m_priviligeDb.GetAppPkgName(targetAppName, targetPkgName);
         if (targetPkgName.empty()) {
             LogError(targetAppName << " is not an installed application");
             return SECURITY_MANAGER_ERROR_APP_UNKNOWN;
@@ -1549,7 +1550,7 @@ int ServiceImpl::dropPrivatePathSharing(
         getPkgLabels(ownerPkgName, pkgLabels);
         auto targetAppLabel = getAppProcessLabel(targetAppName, targetPkgName);
 
-        ScopedTransaction trans;
+        ScopedTransaction trans(m_priviligeDb);
         for (const auto &path : paths) {
             int ret = dropOnePrivateSharing(ownerAppName, ownerPkgName, pkgLabels,
                                             targetAppName, targetAppLabel, path);
@@ -1605,28 +1606,28 @@ int ServiceImpl::pathsRegister(const Credentials &creds, path_req req)
 
     try {
         if (isSharedRO(req.pkgPaths)) {
-            PrivilegeDb::getInstance().BeginTransaction();
+            m_priviligeDb.BeginTransaction();
 
-            if (!PrivilegeDb::getInstance().IsPackageSharedRO(req.pkgName)) {
+            if (!m_priviligeDb.IsPackageSharedRO(req.pkgName)) {
 
-                PrivilegeDb::getInstance().SetSharedROPackage(req.pkgName);
+                m_priviligeDb.SetSharedROPackage(req.pkgName);
 
                 SmackRules::PkgsLabels pkgsLabels;
 
                 std::vector<PkgInfo> pkgsInfo;
-                PrivilegeDb::getInstance().GetPackagesInfo(pkgsInfo);
+                m_priviligeDb.GetPackagesInfo(pkgsInfo);
                 getPkgsProcessLabels(pkgsInfo, pkgsLabels);
 
                 SmackRules::generateSharedRORules(pkgsLabels, pkgsInfo);
                 SmackRules::mergeRules();
             }
-            PrivilegeDb::getInstance().CommitTransaction();
+            m_priviligeDb.CommitTransaction();
         }
     } catch (const PrivilegeDb::Exception::IOError &e) {
         LogError("Cannot access application database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     } catch (const PrivilegeDb::Exception::InternalError &e) {
-        PrivilegeDb::getInstance().RollbackTransaction();
+        m_priviligeDb.RollbackTransaction();
         LogError("Error while saving application info to database: " << e.DumpToString());
         return SECURITY_MANAGER_ERROR_SERVER_ERROR;
     }