diff options
author | Janusz Kozerski <j.kozerski@samsung.com> | 2014-10-27 15:19:56 +0100 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2014-11-03 08:17:57 -0800 |
commit | 7b0f608e276dda997a8febc8e5b37e8fd807af94 (patch) | |
tree | 0399a70562a264ba97399475bb7dce72dbbf3701 | |
parent | bcc0477e684ae4f8f7413b2d56e4d4ed544f573b (diff) | |
download | security-manager-7b0f608e276dda997a8febc8e5b37e8fd807af94.tar.gz security-manager-7b0f608e276dda997a8febc8e5b37e8fd807af94.tar.bz2 security-manager-7b0f608e276dda997a8febc8e5b37e8fd807af94.zip |
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 <j.kozerski@gmail.com>
-rw-r--r-- | src/server/service/include/smack-rules.h | 4 | ||||
-rw-r--r-- | src/server/service/smack-rules.cpp | 37 |
2 files changed, 39 insertions, 2 deletions
diff --git a/src/server/service/include/smack-rules.h b/src/server/service/include/smack-rules.h index db816311..3adbea0e 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 fd530e3f..1b637bdd 100644 --- a/src/server/service/smack-rules.cpp +++ b/src/server/service/smack-rules.cpp @@ -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); |