#include <unistd.h>
#include <sys/types.h>
+#include <mutex>
+#include <unordered_set>
#include <vector>
#include "channel.h"
int getAppDefinedPrivilegeDescription(uid_t uid, const std::string &privilege, std::string &appName, std::string &pkgName, std::string &license);
- void setupAccessToRunUserDir(uid_t uid);
+ bool setupAccessToRunUserDir(uid_t uid);
// Objects below have to be accessed under a mutex each time - need to be thread safe at usage
+ std::unordered_set<uid_t> m_runUserUidsConfigured;
+ std::mutex m_runUserUidMutex;
Cynara m_cynara; // added api mutex
SmackRules m_smackRules; // seems to work out of the box, assuming that libsmack can be used from many threads at once
PrivilegeDb m_privilegeDb; // added api mutex -> if one thread only does RW ScopedTransactions (from service_impl), its okay
// would have ie. one common group and ACL should be configured to give ccess to the /run/user/<ID>
// path for that group. Proper solution would probably include modifications around systemd
// or adding separate service for doing that before security-manager starts setting up
- // user processes with PUIDs, also dynamic addition of new users has to be considered just in case.
+ // user processes with PUIDs.
std::vector<uid_t> listOfUsers;
m_cynaraAdmin.listUsers(listOfUsers);
+
for (auto &uid : listOfUsers)
- setupAccessToRunUserDir(uid);
+ if (setupAccessToRunUserDir(uid))
+ m_runUserUidsConfigured.insert(uid);
}
}
}
// root:/run/user> ls -lZ
// total 0
// drwxr-x--- 8 owner system_share * 260 Feb 14 18:37 5001
-void ServiceImpl::setupAccessToRunUserDir(uid_t uid)
+bool ServiceImpl::setupAccessToRunUserDir(uid_t uid)
{
try {
std::string path = TizenPlatformConfig::makePath(TZ_SYS_RUN, "user", std::to_string(uid));
struct stat statbuf;
if (stat(path.c_str(), &statbuf) == -1) {
LogErrno("Error getting file status on path: " << path);
- return;
+ return false;
}
other_mode |= statbuf.st_mode;
if (-1 == chmod(path.c_str(), other_mode)) {
LogErrno("Error in setting up /run/user/<uid> path for path: " << path << " - chmod failed!");
+ return false;
}
} catch (...) {
LogError("Error in setting up /run/user/<uid> path for uid: " << uid);
+ return false;
}
+ return true;
}
int ServiceImpl::validatePolicy(const Credentials &creds, policy_entry &policyEntry, CynaraAdminPolicy &cyap)
m_cynaraAdmin.userRemove(uidDeleted);
+ if (!smack_simple_check()) {
+ std::lock_guard<std::mutex> lock(m_runUserUidMutex);
+ m_runUserUidsConfigured.erase(uidDeleted);
+ }
return ret;
}
typedef std::map<std::string, std::vector<std::string>> AppsAllowedPrivilegesMap;
gid_t authorsGId;
if (m_privilegeDb.GetAuthorGId(pkgName, authorsGId))
allowedGroups.emplace_back(authorsGId);
+
+ std::lock_guard<std::mutex> lock(m_runUserUidMutex);
+ if (m_runUserUidsConfigured.find(creds.uid) == m_runUserUidsConfigured.end()) {
+ LogWarning("App launched for uid " << creds.uid << ", need to configure access to /run/user/<UID>");
+ if (setupAccessToRunUserDir(creds.uid))
+ m_runUserUidsConfigured.insert(creds.uid);
+ }
}
std::vector<std::string> allowedPrivileges;