Added per-user context to usage of tzplatform-config.
Change-Id: I20b145169d056bbbd3683713167c9b9655bdcbbd
int user_labels_file_watch;
bool fresh;
std::string user_label_file_path;
+ std::string global_label_file_path;
app_labels_monitor() : inotify(-1), global_labels_file_watch(-1), user_labels_file_watch(-1),
fresh(true) {}
};
}
int ret;
lib_retcode ret_lib;
- const std::string globalFile =
- PermissibleSet::getPerrmissibleFileLocation(SM_APP_INSTALL_GLOBAL);
- const std::string userFile =
- PermissibleSet::getPerrmissibleFileLocation(SM_APP_INSTALL_LOCAL);
*monitor = nullptr;
LogError("Bad memory allocation for app_labels_monitor");
return SECURITY_MANAGER_ERROR_MEMORY;
}
+
+ uid_t uid = getuid();
+ const std::string globalFile =
+ PermissibleSet::getPerrmissibleFileLocation(uid, SM_APP_INSTALL_GLOBAL);
+ const std::string userFile =
+ PermissibleSet::getPerrmissibleFileLocation(uid, SM_APP_INSTALL_LOCAL);
+
+
ret = inotify_init();
if (ret == -1) {
LogError("Inotify init failed: " << GetErrnoString(errno));
return ret_lib;
}
m->user_label_file_path = userFile;
+ m->global_label_file_path = globalFile;
*monitor = m.release();
return SECURITY_MANAGER_SUCCESS;
});
LogWarning("Error input param \"monitor\"");
return SECURITY_MANAGER_ERROR_INPUT_PARAM;
}
- const std::string globalFile =
- PermissibleSet::getPerrmissibleFileLocation(SM_APP_INSTALL_GLOBAL);
if (monitor->inotify == -1 || monitor->global_labels_file_watch == -1 ||
monitor->user_labels_file_watch == -1) {
if (monitor->fresh) {
monitor->fresh = false;
- return apply_relabel_list(globalFile, monitor->user_label_file_path);
+ return apply_relabel_list(monitor->global_label_file_path,
+ monitor->user_label_file_path);
}
int avail;
((event.wd == monitor->global_labels_file_watch) ||
(event.wd == monitor->user_labels_file_watch))
){
- lib_retcode r = apply_relabel_list(globalFile, monitor->user_label_file_path);
+ lib_retcode r = apply_relabel_list(monitor->global_label_file_path,
+ monitor->user_label_file_path);
if (r != SECURITY_MANAGER_SUCCESS)
return r;
break;
* Return path to file with current list of application names
* installed globally or locally for the user.
*
+ * @param[in] uid identifier of the user whose application it should be
* @param[in] installationType type of installation (global or local)
* @return path to file with names
*/
-std::string getPerrmissibleFileLocation(int installationType);
+std::string getPerrmissibleFileLocation(uid_t uid, int installationType);
/**
* Update permissable file with current content of database
* @throws FileLockError
* @param[in] installationType type of installation (global or local)
* @return resulting true on success
*/
-void updatePermissibleFile(const uid_t uid, const int installationType);
+void updatePermissibleFile(uid_t uid, int installationType);
/**
* Read names from a file into a vector
* @throws FileLockError
std::string ctxGetEnv(enum tzplatform_variable id);
+ std::string ctxMakePath(enum tzplatform_variable id, const std::string &p);
+
+ std::string ctxMakePath(enum tzplatform_variable id, const std::string &p1, const std::string &p2);
+
+ std::string ctxMakePath(enum tzplatform_variable id, const std::string &p1, const std::string &p2, const std::string &p3);
+
+
static std::string getEnv(enum tzplatform_variable id);
static std::string makePath(enum tzplatform_variable id, const std::string &p);
static std::string makePath(enum tzplatform_variable id, const std::string &p1, const std::string &p2);
- static std::string makePath(enum tzplatform_variable id, const std::string &p1, const std::string &p2, const std::string p3);
+ static std::string makePath(enum tzplatform_variable id, const std::string &p1, const std::string &p2, const std::string &p3);
static uid_t getUid(enum tzplatform_variable id);
#include <security-manager-types.h>
#include <tzplatform_config.h>
+#include "tzplatform-config.h"
+
typedef std::unique_ptr<FILE, int (*)(FILE *)> filePtr;
namespace SecurityManager {
return file;
}
-std::string getPerrmissibleFileLocation(int installationType)
+std::string getPerrmissibleFileLocation(uid_t uid, int installationType)
{
+ TizenPlatformConfig tpc(uid);
if ((installationType == SM_APP_INSTALL_GLOBAL)
|| (installationType == SM_APP_INSTALL_PRELOADED))
- return tzplatform_mkpath(TZ_SYS_RW_APP, Config::APPS_NAME_FILE.c_str());
- return tzplatform_mkpath(TZ_USER_APP, Config::APPS_NAME_FILE.c_str());
-
+ return tpc.ctxMakePath(TZ_SYS_RW_APP, Config::APPS_NAME_FILE.c_str());
+ else
+ return tpc.ctxMakePath(TZ_USER_APP, Config::APPS_NAME_FILE.c_str());
}
static void markPermissibleFileValid(int fd, const std::string &nameFile, bool valid)
void updatePermissibleFile(uid_t uid, int installationType)
{
- std::string nameFile = getPerrmissibleFileLocation(installationType);
+ std::string nameFile = getPerrmissibleFileLocation(uid, installationType);
filePtr file = openAndLockNameFile(nameFile, "w");
markPermissibleFileValid(fileno(file.get()), nameFile, false);
std::vector<std::string> appNames;
return validate(tzplatform_context_getenv(m_ctx, id));
}
+std::string TizenPlatformConfig::ctxMakePath(enum tzplatform_variable id,
+ const std::string &p)
+{
+ return validate(tzplatform_context_mkpath(m_ctx, id, p.c_str()));
+}
+
+std::string TizenPlatformConfig::ctxMakePath(enum tzplatform_variable id,
+ const std::string &p1, const std::string &p2)
+{
+ return validate(tzplatform_context_mkpath3(m_ctx, id, p1.c_str(), p2.c_str()));
+}
+
+std::string TizenPlatformConfig::ctxMakePath(enum tzplatform_variable id,
+ const std::string &p1, const std::string &p2, const std::string &p3)
+{
+ return validate(tzplatform_context_mkpath4(m_ctx, id, p1.c_str(), p2.c_str(), p3.c_str()));
+}
+
std::string TizenPlatformConfig::getEnv(enum tzplatform_variable id)
{
return validate(tzplatform_getenv(id));
}
std::string TizenPlatformConfig::makePath(enum tzplatform_variable id,
- const std::string &p1, const std::string &p2, const std::string p3)
+ const std::string &p1, const std::string &p2, const std::string &p3)
{
return validate(tzplatform_mkpath4(id, p1.c_str(), p2.c_str(), p3.c_str()));
}