Let template manager throw for configuration errors 88/231888/2
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 24 Apr 2020 15:08:33 +0000 (17:08 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 5 May 2020 11:10:55 +0000 (13:10 +0200)
Change-Id: Iec25cd08ae5cff6ef721b77022d07f734898f773

src/common/include/smack-rules.h
src/common/include/template-manager.h
src/common/smack-rules.cpp
src/common/template-manager.cpp

index 35f6d8dc528b8be25b4a885f9fd082feac2b2259..53e7402a672886f9c3ed6db0b314c88e1f35275f 100644 (file)
@@ -38,9 +38,7 @@ namespace SecurityManager {
 
 class SmackRules {
 public:
-    SmackRules() : m_templateMgr(POLICY_INSTALL_DIR) {
-        m_templateMgr.init();
-    }
+    SmackRules();
 
     /**
      * Install package-specific smack rules plus add rules for specified external apps.
index 684490280114787c73cee41acd216634d6256ed8..bb6aba9ca9b0c563a28fe9bd332aa3e48f100443 100644 (file)
 #include <map>
 #include <string>
 
+#include <dpl/exception.h>
 #include <smack-common.h>
 
 #include "config-file.h"
 
 namespace SecurityManager {
 
+class TemplateManagerException {
+public:
+    DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
+    DECLARE_EXCEPTION_TYPE(Base, ConfigFileError)
+    DECLARE_EXCEPTION_TYPE(Base, ConfigParseError)
+};
+
 class TemplateManager {
 public:
     explicit TemplateManager(const std::string &rootDir) : m_rootDir(rootDir){}
index c20586524fc2b47c235c4cab5303b5e061d1715c..68aac2ff1412ecdde9f32700e7687a62df070c68 100644 (file)
@@ -74,6 +74,14 @@ const std::string SMACK_APP_PATH_USER_PERMS = "rwxat";
 
 } // namespace anonymous
 
+SmackRules::SmackRules() : m_templateMgr(POLICY_INSTALL_DIR) {
+    try {
+        m_templateMgr.init();
+    } catch (TemplateManagerException::Base &e) {
+        LogError("Error loading template files: " << e.DumpToString());
+    }
+}
+
 void SmackRules::addFromTemplate(
     SmackAccesses &rules,
     TemplateManager::Type type,
index 3f6cc09255522bbc51ff817e1b3ffe2544962774..605d9ee2fba37bd5a27b9283cb15e30764685a3d 100644 (file)
@@ -57,8 +57,10 @@ void TemplateManager::init()
         loadFiles();
     } catch (FS::Exception::Base &e) {
         LogError("Error loading config files: " << e.DumpToString());
+        Throw(TemplateManagerException::ConfigFileError);
     } catch (SmackException::FileError &e) {
         LogError("Error parsing config files: " << e.DumpToString());
+        Throw(TemplateManagerException::ConfigParseError);
     }
 }