return false;
}
-bool ServiceImpl::getUserPkgDir(const uid_t &uid,
- const std::string &pkgName,
- app_install_type installType,
- std::string &userPkgDir)
+static bool getPath(TizenPlatformConfig &tpc, enum tzplatform_variable id, const std::string &subDir, std::string &path)
+{
+ path = realPath(tpc.ctxGetEnv(id));
+ if (path.empty())
+ return false;
+
+ path += "/" + subDir;
+
+ return true;
+}
+
+int ServiceImpl::getLegalPkgBaseDirs(const uid_t &uid,
+ const std::string &pkgName,
+ app_install_type installType,
+ std::vector<std::string> &legalPkgDirs)
{
TizenPlatformConfig tpc(uid);
- enum tzplatform_variable id;
+ bool isSdAvailable = false;
+ bool isSkelAvailable = false;
+ enum tzplatform_variable baseId;
+ enum tzplatform_variable extendedSdId;
switch (installType) {
case SM_APP_INSTALL_LOCAL:
- id = TZ_USER_APP;
+ isSdAvailable = true;
+ baseId = TZ_USER_APP;
+ extendedSdId = TZ_USER_EXTENDEDSD_APP;
break;
case SM_APP_INSTALL_GLOBAL:
- id = TZ_SYS_RW_APP;
+ isSdAvailable = true;
+ isSkelAvailable = true;
+ baseId = TZ_SYS_RW_APP;
+ extendedSdId = TZ_SYS_EXTENDEDSD_APP;
break;
case SM_APP_INSTALL_PRELOADED:
- id = TZ_SYS_RO_APP;
+ isSkelAvailable = true;
+ baseId = TZ_SYS_RO_APP;
break;
default:
LogError("Unsupported installation type: " << installType);
- return false;
+ return SECURITY_MANAGER_ERROR_INPUT_PARAM;
}
- userPkgDir = std::move(realPath(tpc.ctxGetEnv(id)));
- if (userPkgDir.empty())
- return false;
+ legalPkgDirs.clear();
+
+ std::string basePath;
+ if (!getPath(tpc, baseId, pkgName, basePath)) {
+ LogError("Couldn't generate base path");
+ return SECURITY_MANAGER_ERROR_UNKNOWN;
+ }
- userPkgDir.append("/").append(pkgName);
+ LogDebug("Base path is : " << basePath);
+ legalPkgDirs.push_back(std::move(basePath));
- return true;
+ if (isSdAvailable) {
+ std::string extendedPath;
+ // There might be no external storage
+ if (getPath(tpc, extendedSdId, pkgName, extendedPath))
+ legalPkgDirs.push_back(std::move(extendedPath));
+ }
+
+ if (isSkelAvailable) {
+ std::string skelPkgBasePath;
+ if (!getSkelPkgDir(pkgName, skelPkgBasePath))
+ return SECURITY_MANAGER_ERROR_UNKNOWN;
+ legalPkgDirs.push_back(std::move(skelPkgBasePath));
+ }
+ return SECURITY_MANAGER_SUCCESS;
}
bool ServiceImpl::getSkelPkgDir(const std::string &pkgName,
std::string app = TizenPlatformConfig::getEnv(TZ_USER_APP);
std::string home = TizenPlatformConfig::getEnv(TZ_USER_HOME);
std::string real_skel_dir = std::move(realPath(Config::SKEL_DIR));
- if (app.empty() || home.empty() || real_skel_dir.empty()) {
+ if (real_skel_dir.empty()) {
LogError("Unable to get skel pkg dir.");
return false;
}
const uid_t &uid)
{
try {
- std::string pkgBasePath;
- int authorId;
-
if (!m_privilegeDb.PkgNameExists(pkgName)) {
LogError("No such package: " << pkgName);
return SECURITY_MANAGER_ERROR_INPUT_PARAM;
}
+ int authorId;
m_privilegeDb.GetPkgAuthorId(pkgName, authorId);
- if (!getUserPkgDir(uid, pkgName, installationType, pkgBasePath))
- return SECURITY_MANAGER_ERROR_SERVER_ERROR;
-
- // check if paths are inside
- bool pathsOK;
- if (installationType == SM_APP_INSTALL_LOCAL) {
- pathsOK = pathsCheck(paths, {pkgBasePath});
- } else {
- std::string skelPkgBasePath;
- if (!getSkelPkgDir(pkgName, skelPkgBasePath))
- return SECURITY_MANAGER_ERROR_SERVER_ERROR;
- pathsOK = pathsCheck(paths, {pkgBasePath, skelPkgBasePath});
+ std::vector<std::string> pkgLegalBaseDirs;
+ int ret = getLegalPkgBaseDirs(uid, pkgName, installationType, pkgLegalBaseDirs);
+ if (ret != SECURITY_MANAGER_SUCCESS) {
+ LogError("Failed to generate legal directories for application");
+ return ret;
}
- if (!pathsOK)
- return SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED;
-
- if (containSubDir(pkgBasePath, paths))
- SmackLabels::setupPkgBasePath(pkgBasePath);
+ // check if paths are inside of legal directories
+ if (!pathsCheck(paths, pkgLegalBaseDirs))
+ return SECURITY_MANAGER_ERROR_NOT_PATH_OWNER;
// register paths
for (const auto &pkgPath : paths) {
app_install_path_type pathType = static_cast<app_install_path_type>(pkgPath.second);
SmackLabels::setupPath(pkgName, path, pathType, authorId);
}
+
+ for (const auto &basePath : pkgLegalBaseDirs) {
+ if (containSubDir(basePath, paths)) {
+ SmackLabels::setupPkgBasePath(basePath);
+ }
+ }
+
return SECURITY_MANAGER_SUCCESS;
} catch (const PrivilegeDb::Exception::Base &e) {
LogError("Database error: " << e.DumpToString());