{"public_ro", SECURITY_MANAGER_PATH_PUBLIC_RO},
{"rw_others_ro", SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO},
{"trusted_rw", SECURITY_MANAGER_PATH_TRUSTED_RW},
+ {"rw_sensitive", SECURITY_MANAGER_PATH_RW_SENSITIVE},
};
static std::map <std::string, enum security_manager_user_type> user_type_map = {
("path,p", po::value< std::vector<std::string> >()->multitoken(),
"path for setting smack labels (may occur more than once).\n"
"Format: --path <path> <path type>\n"
- " where <path type> is: \trw, ro, public_ro, rw_others_ro, trusted_rw\n"
+ " where <path type> is: \trw, ro, public_ro, rw_others_ro, trusted_rw, rw_sensitive\n"
" ('trusted rw' requires author id)\n"
"example:\n"
" \t--path=/home/user/app rw")
#include <sys/types.h>
#include <vector>
+#include <set>
#include "credentials.h"
#include "cynara.h"
void getPkgLabels(const std::string &pkgName, SmackRules::Labels &pkgsLabels);
- static bool isSharedRO(const pkg_paths& paths);
+ static bool containsPathType(const pkg_paths& paths, const std::set<app_install_path_type> &types);
int squashDropPrivateSharing(const std::string &ownerAppName,
const std::string &targetAppName,
int validatePolicy(const Credentials &creds, policy_entry &policyEntry, CynaraAdminPolicy &cyap);
+ int registerSensitiveDirs(const pkg_paths &paths,
+ int installType,
+ const std::string &pkgName,
+ uid_t uid);
+
Cynara m_cynara;
PrivilegeDb m_priviligeDb;
CynaraAdmin m_cynaraAdmin;
}
}
-bool ServiceImpl::isSharedRO(const pkg_paths& paths)
+bool ServiceImpl::containsPathType(const pkg_paths &paths, const std::set<app_install_path_type> &types)
{
for (const auto& pkgPath : paths) {
auto pathType = static_cast<app_install_path_type>(pkgPath.second);
- if (pathType == SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO)
+ if (types.find(pathType) != types.end())
return true;
}
PermissibleSet::updatePermissibleFile(uid, type, labelsForUser);
}
+int ServiceImpl::registerSensitiveDirs(const pkg_paths &paths,
+ int installType,
+ const std::string &pkgName,
+ uid_t uid)
+{
+ for (const auto &path : paths) {
+ if (path.second != SECURITY_MANAGER_PATH_RW_SENSITIVE)
+ continue;
+
+ /*
+ * Sensitive(RW) directories do not make sense for global installation.
+ * The app should store data in user's home dir (locally)
+ */
+ if (installType == SM_APP_INSTALL_GLOBAL || installType == SM_APP_INSTALL_PRELOADED) {
+ LogError("Registering sensitive directory for global app is not allowed");
+ return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+ }
+
+ // directories will be automatically removed from db upon pkg removal
+ m_priviligeDb.AddSensitiveDir(pkgName, uid, path.first);
+ }
+ return SECURITY_MANAGER_SUCCESS;
+}
+
int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req)
{
SmackRules::Labels pkgLabels;
SmackRules::PkgsLabels pkgsProcessLabels;
int authorId;
std::vector<PkgInfo> pkgsInfo;
- bool hasSharedRO = isSharedRO(req.pkgPaths);
+ bool hasSharedRO = containsPathType(req.pkgPaths, {SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO} );
try {
setRequestDefaultValues(req.uid, req.installationType);
m_priviligeDb.GetPackagesInfo(pkgsInfo);
getPkgsProcessLabels(pkgsInfo, pkgsProcessLabels);
+ for (const auto &path : req.pkgPaths) {
+ if (path.second == SECURITY_MANAGER_PATH_RW_SENSITIVE) {
+ LogError("Sensitive paths not supported in APP_INSTALL request."
+ "Use PATHS_REGISTER.");
+ return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+ }
+ }
+
// WTF? Why this commit is here? Shouldn't it be at the end of this function?
trans.commit();
LogDebug("Application installation commited to database");
}
try {
- if (isSharedRO(req.pkgPaths)) {
+ if (containsPathType(req.pkgPaths, {SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO, SECURITY_MANAGER_PATH_RW_SENSITIVE})) {
ScopedTransaction trans(m_priviligeDb);
+ if (!m_priviligeDb.PkgNameExists(req.pkgName)) {
+ LogError("No such package: " << req.pkgName);
+ return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+ }
+
+ int ret = registerSensitiveDirs(req.pkgPaths, req.installationType, req.pkgName, req.uid);
+ if (ret != SECURITY_MANAGER_SUCCESS)
+ return ret;
+
if (!m_priviligeDb.IsPackageSharedRO(req.pkgName)) {
m_priviligeDb.SetSharedROPackage(req.pkgName);