*/
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);
#include <unistd.h>
#include <sys/types.h>
+#include <dirent.h>
#include <sys/stat.h>
#include <sys/smack.h>
#include <fcntl.h>
return path;
}
-bool SmackRules::installPackageRules(const std::string &pkgId) {
+bool SmackRules::installPackageRules(const std::string &pkgId)
+{
try {
SmackRules smackRules;
std::string path = getPackageRulesFilePath(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) {
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);