InstallRequest::InstallRequest()
: m_req(nullptr)
, m_tizenVer("3.0")
- , m_appId(nullptr)
- , m_pkgId(nullptr)
, m_uid(false, 0)
{
int result = security_manager_app_inst_req_new(&m_req);
security_manager_app_inst_req_free(m_req);
}
-void InstallRequest::setAppTizenVersion(const char * tizenVer, lib_retcode expectedResult)
+void InstallRequest::setAppTizenVersion(std::string tizenVer, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_set_target_version(m_req, tizenVer);
+ int result = security_manager_app_inst_req_set_target_version(m_req, tizenVer.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting app id returned wrong value."
<< " Tizen version: " << tizenVer << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_tizenVer = std::string(tizenVer);
+ m_tizenVer = std::move(tizenVer);
}
-void InstallRequest::setAppId(const char *appId, lib_retcode expectedResult)
+void InstallRequest::setAppId(std::string appId, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_set_app_id(m_req, appId);
+ int result = security_manager_app_inst_req_set_app_id(m_req, appId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting app id returned wrong value."
<< " App id: " << appId << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_appId = strdup(appId);
+ m_appId = std::move(appId);
}
-void InstallRequest::setPkgId(const char *pkgId, lib_retcode expectedResult)
+void InstallRequest::setPkgId(std::string pkgId, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId);
+ int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting pkg id returned wrong value."
<< " Pkg id: " << pkgId << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_pkgId = strdup(pkgId);
+ m_pkgId = std::move(pkgId);
}
void InstallRequest::addPrivilege(const char *privilege, lib_retcode expectedResult)
m_privileges.push_back(strdup(privilege));
}
-void InstallRequest::addPath(const char *path, app_install_path_type pathType, lib_retcode expectedResult)
+void InstallRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_add_path(m_req, path, pathType);
+ int result = security_manager_app_inst_req_add_path(m_req, path.c_str(), pathType);
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"adding path returned wrong value."
<< " Path: " << path << ";"
<< " Path type: " << pathType << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_paths.push_back(std::pair<std::string, app_install_path_type>(path, pathType));
+ m_paths.emplace_back(std::pair<std::string, app_install_path_type>(std::move(path), pathType));
}
void InstallRequest::setUid(const uid_t uid, lib_retcode expectedResult)
m_uid.second = uid;
}
-void InstallRequest::setAuthorId(const char *authorId, lib_retcode expectedResult)
+void InstallRequest::setAuthorId(std::string authorId, lib_retcode expectedResult)
{
- m_authorId.clear();
- if(authorId)
- m_authorId.assign(authorId);
-
- int result = security_manager_app_inst_req_set_author_id(m_req, authorId);
+ int result = security_manager_app_inst_req_set_author_id(m_req, authorId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting author id returned wrong value."
<< " Author id: " << m_authorId << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
-
+ m_authorId = std::move(authorId);
}
std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
{
- if (request.m_appId != nullptr)
+ if (!request.m_appId.empty())
os << "app id: " << request.m_appId << "; ";
- if (request.m_pkgId != nullptr)
+ if (!request.m_pkgId.empty())
os << "pkg id: " << request.m_pkgId << "; ";
if (!request.m_privileges.empty()) {
os << "privileges: [ " << request.m_privileges[0];
requestInst.setPkgId(sm_pkg_id);
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[0].c_str());
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[1].c_str());
- requestInst.addPath(SM_RW_PATH.c_str(), SECURITY_MANAGER_PATH_RW);
- requestInst.addPath(SM_RO_PATH.c_str(), SECURITY_MANAGER_PATH_RO);
- requestInst.addPath(SM_PUBLIC_RO_PATH.c_str(), SECURITY_MANAGER_PATH_PUBLIC_RO);
+ requestInst.addPath(SM_RW_PATH, SECURITY_MANAGER_PATH_RW);
+ requestInst.addPath(SM_RO_PATH, SECURITY_MANAGER_PATH_RO);
+ requestInst.addPath(SM_PUBLIC_RO_PATH, SECURITY_MANAGER_PATH_PUBLIC_RO);
Api::install(requestInst);
requestInst.setPkgId(sm_pkg_shared_id);
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[0].c_str());
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[1].c_str());
- requestInst.addPath(SM_RW_PATH.c_str(), SECURITY_MANAGER_PATH_RW);
- requestInst.addPath(SM_RO_PATH.c_str(), SECURITY_MANAGER_PATH_RO);
- requestInst.addPath(SM_PUBLIC_RO_PATH.c_str(), SECURITY_MANAGER_PATH_PUBLIC_RO);
- requestInst.addPath(SM_OWNER_RW_OTHERS_RO_PATH.c_str(), SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO);
+ requestInst.addPath(SM_RW_PATH, SECURITY_MANAGER_PATH_RW);
+ requestInst.addPath(SM_RO_PATH, SECURITY_MANAGER_PATH_RO);
+ requestInst.addPath(SM_PUBLIC_RO_PATH, SECURITY_MANAGER_PATH_PUBLIC_RO);
+ requestInst.addPath(SM_OWNER_RW_OTHERS_RO_PATH, SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO);
requestInst.setAppTizenVersion("2.4");
Api::install(requestInst);
}
requestInst.setPkgId(sm_pkg_shared_id);
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[0].c_str());
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[1].c_str());
- requestInst.addPath(SM_OWNER_RW_OTHERS_RO_PATH.c_str(), SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO);
+ requestInst.addPath(SM_OWNER_RW_OTHERS_RO_PATH, SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO);
requestInst.setAppTizenVersion("2.4");
Api::install(requestInst);
}
requestInst.setPkgId(sm_pkg_shared_id);
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[0].c_str());
requestInst.addPrivilege(SM_ALLOWED_PRIVILEGES[1].c_str());
- requestInst.addPath(SM_RW_PATH.c_str(), SECURITY_MANAGER_PATH_RW);
- requestInst.addPath(SM_RO_PATH.c_str(), SECURITY_MANAGER_PATH_RO);
- requestInst.addPath(SM_PUBLIC_RO_PATH.c_str(), SECURITY_MANAGER_PATH_PUBLIC_RO);
- requestInst.addPath(SM_OWNER_RW_OTHERS_RO_PATH.c_str(), SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO);
+ requestInst.addPath(SM_RW_PATH, SECURITY_MANAGER_PATH_RW);
+ requestInst.addPath(SM_RO_PATH, SECURITY_MANAGER_PATH_RO);
+ requestInst.addPath(SM_PUBLIC_RO_PATH, SECURITY_MANAGER_PATH_PUBLIC_RO);
+ requestInst.addPath(SM_OWNER_RW_OTHERS_RO_PATH, SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO);
requestInst.setAppTizenVersion("3.0");
Api::install(requestInst);
// install other apps
for(const auto &app : MANY_APPS_PKGS) {
InstallRequest requestUninst;
- requestUninst.setAppId(app.first.c_str());
+ requestUninst.setAppId(app.first);
Api::uninstall(requestUninst);
};
owner.revokeRules();
owner.createInstallDir();
InstallRequest ownerInst;
- ownerInst.setAppId(owner.getAppId().c_str());
- ownerInst.setPkgId(owner.getPkgId().c_str());
+ ownerInst.setAppId(owner.getAppId());
+ ownerInst.setPkgId(owner.getPkgId());
Api::install(ownerInst);
SharingRequest request;
owner.revokeRules();
owner.createInstallDir();
InstallRequest ownerInst;
- ownerInst.setAppId(owner.getAppId().c_str());
- ownerInst.setPkgId(owner.getPkgId().c_str());
+ ownerInst.setAppId(owner.getAppId());
+ ownerInst.setPkgId(owner.getPkgId());
Api::install(ownerInst);
AppInstallHelper target("secondInstalledApp");
target.revokeRules();
target.createInstallDir();
InstallRequest targetInst;
- targetInst.setAppId(target.getAppId().c_str());
- targetInst.setPkgId(target.getPkgId().c_str());
+ targetInst.setAppId(target.getAppId());
+ targetInst.setPkgId(target.getPkgId());
Api::install(targetInst);
SharingRequest request;
owner.createSharedFile();
InstallRequest ownerReq;
- ownerReq.setAppId(owner.getAppId().c_str());
- ownerReq.setPkgId(owner.getPkgId().c_str());
- ownerReq.addPath(owner.getSharedPath().c_str(), SECURITY_MANAGER_PATH_RW);
+ ownerReq.setAppId(owner.getAppId());
+ ownerReq.setPkgId(owner.getPkgId());
+ ownerReq.addPath(owner.getSharedPath(), SECURITY_MANAGER_PATH_RW);
int result = nftw(owner.getInstallDir().c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
RUNNER_ASSERT_MSG(result == 0, "Unable to remove Smack labels in " << owner.getInstallDir());
Api::install(ownerReq);
InstallRequest targetReq;
- targetReq.setAppId(target.getAppId().c_str());
- targetReq.setPkgId(target.getAppId().c_str());
+ targetReq.setAppId(target.getAppId());
+ targetReq.setPkgId(target.getAppId());
Api::install(targetReq);
SharingRequest share1;
- std::string sharedPath = owner.getSharedPath().c_str();
+ std::string sharedPath = owner.getSharedPath();
share1.setOwnerAppId(owner.getAppId());
share1.setTargetAppId(target.getAppId());
const char *path[] = {sharedPath.c_str()};
owner.createSharedFile();
InstallRequest ownerReq;
- ownerReq.setAppId(owner.getAppId().c_str());
- ownerReq.setPkgId(owner.getPkgId().c_str());
- ownerReq.addPath(owner.getSharedPath().c_str(), SECURITY_MANAGER_PATH_RW);
+ ownerReq.setAppId(owner.getAppId());
+ ownerReq.setPkgId(owner.getPkgId());
+ ownerReq.addPath(owner.getSharedPath(), SECURITY_MANAGER_PATH_RW);
int result = nftw(owner.getInstallDir().c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
RUNNER_ASSERT_MSG(result == 0, "Unable to remove Smack labels in " << owner.getInstallDir());
Api::install(ownerReq);
InstallRequest targetReq;
- targetReq.setAppId(target.getAppId().c_str());
- targetReq.setPkgId(target.getAppId().c_str());
+ targetReq.setAppId(target.getAppId());
+ targetReq.setPkgId(target.getAppId());
Api::install(targetReq);
SharingRequest share1;
- std::string sharedPath = owner.getSharedPath(0).c_str();
+ std::string sharedPath = owner.getSharedPath(0);
share1.setOwnerAppId(owner.getAppId());
share1.setTargetAppId(target.getAppId());
const char *path[] = {sharedPath.c_str()};
owner.createSharedFile(1);
InstallRequest ownerReq;
- ownerReq.setAppId(owner.getAppId().c_str());
- ownerReq.setPkgId(owner.getPkgId().c_str());
- ownerReq.addPath(owner.getSharedPath(0).c_str(), SECURITY_MANAGER_PATH_RW);
- ownerReq.addPath(owner.getSharedPath(1).c_str(), SECURITY_MANAGER_PATH_RW);
+ ownerReq.setAppId(owner.getAppId());
+ ownerReq.setPkgId(owner.getPkgId());
+ ownerReq.addPath(owner.getSharedPath(0), SECURITY_MANAGER_PATH_RW);
+ ownerReq.addPath(owner.getSharedPath(1), SECURITY_MANAGER_PATH_RW);
int result = nftw(owner.getInstallDir().c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
RUNNER_ASSERT_MSG(result == 0, "Unable to remove Smack labels in " << owner.getInstallDir());
Api::install(ownerReq);
InstallRequest targetReq;
- targetReq.setAppId(target.getAppId().c_str());
- targetReq.setPkgId(target.getAppId().c_str());
+ targetReq.setAppId(target.getAppId());
+ targetReq.setPkgId(target.getAppId());
Api::install(targetReq);
SharingRequest share1, share2;
- std::string sharedPath1 = owner.getSharedPath(0).c_str();
- std::string sharedPath2 = owner.getSharedPath(1).c_str();
+ std::string sharedPath1 = owner.getSharedPath(0);
+ std::string sharedPath2 = owner.getSharedPath(1);
share1.setOwnerAppId(owner.getAppId());
share2.setOwnerAppId(owner.getAppId());
share1.setTargetAppId(target.getAppId());
owner.createSharedFile();
InstallRequest ownerReq;
- ownerReq.setAppId(owner.getAppId().c_str());
- ownerReq.setPkgId(owner.getPkgId().c_str());
- ownerReq.addPath(owner.getSharedPath().c_str(), SECURITY_MANAGER_PATH_RW);
+ ownerReq.setAppId(owner.getAppId());
+ ownerReq.setPkgId(owner.getPkgId());
+ ownerReq.addPath(owner.getSharedPath(), SECURITY_MANAGER_PATH_RW);
int result = nftw(owner.getInstallDir().c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
RUNNER_ASSERT_MSG(result == 0, "Unable to remove Smack labels in " << owner.getInstallDir());
Api::install(ownerReq);
for (size_t i = 1; i < helper.size(); i++) {
InstallRequest targetReq;
- targetReq.setAppId(helper[i].getAppId().c_str());
- targetReq.setPkgId(helper[i].getAppId().c_str());
+ targetReq.setAppId(helper[i].getAppId());
+ targetReq.setPkgId(helper[i].getAppId());
Api::install(targetReq);
}
Api::uninstall(ownerReq);
for (size_t i = 1; i < helper.size(); i++) {
InstallRequest targetReq;
- targetReq.setAppId(helper[i].getAppId().c_str());
- targetReq.setPkgId(helper[i].getAppId().c_str());
+ targetReq.setAppId(helper[i].getAppId());
+ targetReq.setPkgId(helper[i].getAppId());
Api::uninstall(targetReq);
}
}
owner.createSharedFile(1);
InstallRequest ownerReq;
- ownerReq.setAppId(owner.getAppId().c_str());
- ownerReq.setPkgId(owner.getPkgId().c_str());
- ownerReq.addPath(owner.getSharedPath(0).c_str(), SECURITY_MANAGER_PATH_RW);
- ownerReq.addPath(owner.getSharedPath(1).c_str(), SECURITY_MANAGER_PATH_RW);
+ ownerReq.setAppId(owner.getAppId());
+ ownerReq.setPkgId(owner.getPkgId());
+ ownerReq.addPath(owner.getSharedPath(0), SECURITY_MANAGER_PATH_RW);
+ ownerReq.addPath(owner.getSharedPath(1), SECURITY_MANAGER_PATH_RW);
int result = nftw(owner.getInstallDir().c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
RUNNER_ASSERT_MSG(result == 0, "Unable to remove Smack labels in " << owner.getInstallDir());
for (size_t i = 1; i < helper.size(); i++) {
InstallRequest targetReq;
- targetReq.setAppId(helper[i].getAppId().c_str());
- targetReq.setPkgId(helper[i].getAppId().c_str());
+ targetReq.setAppId(helper[i].getAppId());
+ targetReq.setPkgId(helper[i].getAppId());
Api::install(targetReq);
}
Api::uninstall(ownerReq);
for (size_t i = 1; i < helper.size(); i++) {
InstallRequest targetReq;
- targetReq.setAppId(helper[i].getAppId().c_str());
- targetReq.setPkgId(helper[i].getAppId().c_str());
+ targetReq.setAppId(helper[i].getAppId());
+ targetReq.setPkgId(helper[i].getAppId());
Api::uninstall(targetReq);
}
}
RUNNER_TEST(security_manager_40_set_wrong_author_id)
{
InstallRequest requestInst;
- requestInst.setAuthorId(NULL, SECURITY_MANAGER_ERROR_INPUT_PARAM);
- requestInst.setAuthorId("", SECURITY_MANAGER_ERROR_INPUT_PARAM);
+
+ RUNNER_ASSERT(SECURITY_MANAGER_ERROR_INPUT_PARAM ==
+ security_manager_app_inst_req_set_author_id(requestInst.get(), NULL));
+
+ RUNNER_ASSERT(SECURITY_MANAGER_ERROR_INPUT_PARAM ==
+ security_manager_app_inst_req_set_author_id(requestInst.get(), ""));
}
RUNNER_TEST(security_manager_41_set_author_id_multiple_times)
std::string authorId = "some-author-id" + std::to_string(i);
InstallRequest requestInst;
- requestInst.setAuthorId(authorId.c_str());
+ requestInst.setAuthorId(authorId);
}
}
// install app with shared/trusted dir
InstallRequest trustingApp;
- trustingApp.setAppId(provider.getAppId().c_str());
- trustingApp.setPkgId(provider.getPkgId().c_str());
+ trustingApp.setAppId(provider.getAppId());
+ trustingApp.setPkgId(provider.getPkgId());
trustingApp.setAuthorId("author id to be overwritten");
trustingApp.setAuthorId(author_id);
trustingApp.addPath(provider.getTrustedDir().c_str(), SECURITY_MANAGER_PATH_TRUSTED_RW);
RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << SM_TRUSTED_PATH);
// check rules
- check_exact_access("System", trusted_label.c_str(), system_access);
- check_exact_access("User", trusted_label.c_str(), system_access);
- check_exact_access(generateAppLabel(provider.getAppId().c_str()), trusted_label, trusted_access);
- check_exact_access(generatePkgLabel(provider.getPkgId().c_str()), trusted_label, "");
+ check_exact_access("System", trusted_label, system_access);
+ check_exact_access("User", trusted_label, system_access);
+ check_exact_access(generateAppLabel(provider.getAppId()), trusted_label, trusted_access);
+ check_exact_access(generatePkgLabel(provider.getPkgId()), trusted_label, "");
// install trusted app
InstallRequest trustedApp;
- trustedApp.setAppId(user.getAppId().c_str());
- trustedApp.setPkgId(user.getPkgId().c_str());
+ trustedApp.setAppId(user.getAppId());
+ trustedApp.setPkgId(user.getPkgId());
trustedApp.setAuthorId(author_id);
Api::install(trustedApp);
// check rules
- check_exact_access(generateAppLabel(user.getAppId().c_str()), trusted_label, trusted_access);
- check_exact_access(generatePkgLabel(user.getPkgId().c_str()), trusted_label, "");
+ check_exact_access(generateAppLabel(user.getAppId()), trusted_label, trusted_access);
+ check_exact_access(generatePkgLabel(user.getPkgId()), trusted_label, "");
// install untrusted app
InstallRequest untrustedApp;
- untrustedApp.setAppId(untrusted.getAppId().c_str());
- untrustedApp.setPkgId(untrusted.getPkgId().c_str());
+ untrustedApp.setAppId(untrusted.getAppId());
+ untrustedApp.setPkgId(untrusted.getPkgId());
Api::install(untrustedApp);
// check rules
- check_exact_access(generateAppLabel(untrusted.getAppId().c_str()), trusted_label, "");
- check_exact_access(generatePkgLabel(untrusted.getPkgId().c_str()), trusted_label, "");
+ check_exact_access(generateAppLabel(untrusted.getAppId()), trusted_label, "");
+ check_exact_access(generatePkgLabel(untrusted.getPkgId()), trusted_label, "");
// uninstall trusting app
Api::uninstall(trustingApp);
// there's still one app with author id, rules should be kept
check_exact_access("System", trusted_label, system_access);
check_exact_access("User", trusted_label, system_access);
- check_exact_access(generateAppLabel(provider.getAppId().c_str()), trusted_label, "");
- check_exact_access(generatePkgLabel(provider.getPkgId().c_str()), trusted_label, "");
- check_exact_access(generateAppLabel(user.getAppId().c_str()), trusted_label, trusted_access);
- check_exact_access(generatePkgLabel(user.getPkgId().c_str()), trusted_label, "");
+ check_exact_access(generateAppLabel(provider.getAppId()), trusted_label, "");
+ check_exact_access(generatePkgLabel(provider.getPkgId()), trusted_label, "");
+ check_exact_access(generateAppLabel(user.getAppId()), trusted_label, trusted_access);
+ check_exact_access(generatePkgLabel(user.getPkgId()), trusted_label, "");
Api::uninstall(trustedApp);
// no more apps with author id
check_exact_access("System", trusted_label, "");
check_exact_access("User", trusted_label, "");
- check_exact_access(generateAppLabel(user.getAppId().c_str()), trusted_label, "");
- check_exact_access(generatePkgLabel(user.getPkgId().c_str()), trusted_label, "");
+ check_exact_access(generateAppLabel(user.getAppId()), trusted_label, "");
+ check_exact_access(generatePkgLabel(user.getPkgId()), trusted_label, "");
Api::uninstall(untrustedApp);
}
// install app with shared/trusted dir but without authors id
InstallRequest app;
- app.setAppId(help.getAppId().c_str());
- app.setPkgId(help.getPkgId().c_str());
- app.addPath(help.getTrustedDir().c_str(),
- SECURITY_MANAGER_PATH_TRUSTED_RW);
+ app.setAppId(help.getAppId());
+ app.setPkgId(help.getPkgId());
+ app.addPath(help.getTrustedDir(), SECURITY_MANAGER_PATH_TRUSTED_RW);
Api::install(app, SECURITY_MANAGER_ERROR_INPUT_PARAM);
}