Don't remove "User" Smack rules on application uninstall 81/29481/5
authorJanusz Kozerski <j.kozerski@samsung.com>
Mon, 27 Oct 2014 14:19:56 +0000 (15:19 +0100)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 3 Nov 2014 16:17:57 +0000 (08:17 -0800)
Temporary fix.
After app uninstall and remove app rules, all rules from
files in accesses.d directory are re-loaded.

Change-Id: I7786a356108d17ed948abbc615f22286b251c0b3
Signed-off-by: Janusz Kozerski <j.kozerski@gmail.com>
src/server/service/include/smack-rules.h
src/server/service/smack-rules.cpp

index db81631..3adbea0 100644 (file)
@@ -70,6 +70,10 @@ public:
      */
     static bool uninstallPackageRules(const std::string &pkgId);
 
+    /* FIXME: Remove this function if real pkgId instead of "User" label will be used
+     * in generateAppLabel(). */
+    static bool addMissingRulesFix();
+
 private:
     static std::string getPackageRulesFilePath(const std::string &pkgId);
 
index fd530e3..1b637bd 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <unistd.h>
 #include <sys/types.h>
+#include <dirent.h>
 #include <sys/stat.h>
 #include <sys/smack.h>
 #include <fcntl.h>
@@ -205,7 +206,8 @@ std::string SmackRules::getPackageRulesFilePath(const std::string &pkgId)
     return path;
 }
 
-bool SmackRules::installPackageRules(const std::string &pkgId) {
+bool SmackRules::installPackageRules(const std::string &pkgId)
+{
     try {
          SmackRules smackRules;
          std::string path = getPackageRulesFilePath(pkgId);
@@ -232,7 +234,35 @@ bool SmackRules::installPackageRules(const std::string &pkgId) {
      }
 }
 
-bool SmackRules::uninstallPackageRules(const std::string &pkgId) {
+/* FIXME: Remove this function if real pkgId instead of "User" label will be used
+ * in generateAppLabel(). */
+bool SmackRules::addMissingRulesFix()
+{
+    DIR *dir;
+    struct dirent *ent;
+    SmackRules rules;
+    std::string path(tzplatform_mkpath(TZ_SYS_SMACK, "accesses.d"));
+
+    dir = opendir(path.c_str());
+    if (dir != NULL) {
+        while ((ent = readdir(dir))) {
+            if (ent->d_type == DT_REG) {
+                rules.loadFromFile(tzplatform_mkpath3(TZ_SYS_SMACK, "accesses.d/", ent->d_name));
+                // Do not check error here. If this fails we can't do anything anyway.
+            }
+        }
+        rules.apply();
+    }
+    else
+        return false;
+
+    closedir(dir);
+
+    return true;
+}
+
+bool SmackRules::uninstallPackageRules(const std::string &pkgId)
+{
     std::string path = getPackageRulesFilePath(pkgId);
     if (access(path.c_str(), F_OK) == -1) {
         if (errno == ENOENT) {
@@ -261,6 +291,9 @@ bool SmackRules::uninstallPackageRules(const std::string &pkgId) {
             return false;
         }
 
+        // FIXME: Reloading all rules:
+        SmackRules::addMissingRulesFix();
+
         return true;
     } catch (const std::bad_alloc &e) {
         LogError("Out of memory while trying to uninstall smack rules for pkgId: " << pkgId);