From: Janusz Kozerski Date: Mon, 27 Oct 2014 14:19:56 +0000 (+0100) Subject: Don't remove "User" Smack rules on application uninstall X-Git-Tag: accepted/tizen/common/20141121.095621~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git;a=commitdiff_plain;h=7b0f608e276dda997a8febc8e5b37e8fd807af94 Don't remove "User" Smack rules on application uninstall 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 --- diff --git a/src/server/service/include/smack-rules.h b/src/server/service/include/smack-rules.h index db81631..3adbea0 100644 --- a/src/server/service/include/smack-rules.h +++ b/src/server/service/include/smack-rules.h @@ -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); diff --git a/src/server/service/smack-rules.cpp b/src/server/service/smack-rules.cpp index fd530e3..1b637bd 100644 --- a/src/server/service/smack-rules.cpp +++ b/src/server/service/smack-rules.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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);