<< " Expected result: " << expectedResult);
}
-std::string getPkgId(const char *appId, lib_retcode expectedResult)
+std::string getPkgId(const std::string &appId, lib_retcode expectedResult)
{
char *pkgId = nullptr;
- int result = security_manager_get_app_pkgid(&pkgId, appId);
+ int result = security_manager_get_app_pkgid(&pkgId, appId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"getting pkg id from app id returned wrong value."
<< " App id: " << appId << ";"
return str;
}
-void setProcessLabel(const char *appId, lib_retcode expectedResult)
+void setProcessLabel(const std::string &appId, lib_retcode expectedResult)
{
- int result = security_manager_set_process_label_from_appid(appId);
+ int result = security_manager_set_process_label_from_appid(appId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting process label from app id returned wrong value."
<< " App id: " << appId << ";"
<< " Expected result: " << expectedResult);
}
-void setProcessGroups(const char *appId, lib_retcode expectedResult)
+void setProcessGroups(const std::string &appId, lib_retcode expectedResult)
{
- int result = security_manager_set_process_groups_from_appid(appId);
+ int result = security_manager_set_process_groups_from_appid(appId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting process groups from app id returned wrong value."
<< " App id: " << appId << ";"
<< " Expected result: " << expectedResult);
}
-void prepareApp(const char *appId, lib_retcode expectedResult)
+void prepareApp(const std::string &appId, lib_retcode expectedResult)
{
- int result = security_manager_prepare_app(appId);
+ int result = security_manager_prepare_app(appId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"preparing app returned wrong value."
<< " App id: " << appId << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- if (pkgId && result == SECURITY_MANAGER_SUCCESS) {
- RUNNER_ASSERT_MSG(pkg_Id != nullptr, "getting pkg and app id did not allocate memory");
- }
-
- if (appId && result == SECURITY_MANAGER_SUCCESS) {
- RUNNER_ASSERT_MSG(app_Id != nullptr, "getting pkg and app id did not allocate memory");
- }
-
if (pkg_Id) {
*pkgId = pkg_Id;
free(pkg_Id);
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- if (pkgId && result == SECURITY_MANAGER_SUCCESS) {
- RUNNER_ASSERT_MSG(pkg_Id != nullptr, "getting pkg and app id did not allocate memory");
+ if (pkg_Id) {
+ *pkgId = pkg_Id;
+ free(pkg_Id);
}
- if (appId && result == SECURITY_MANAGER_SUCCESS) {
- RUNNER_ASSERT_MSG(app_Id != nullptr, "getting pkg and app id did not allocate memory");
+ if (app_Id) {
+ *appId = app_Id;
+ free(app_Id);
}
+}
+
+void getPkgIdByCynaraClient(const std::string &client, std::string *pkgId, std::string *appId,
+ lib_retcode expectedResult)
+{
+ char *pkg_Id = nullptr;
+ char *app_Id = nullptr;
+
+ int result = security_manager_identify_app_from_cynara_client(client.c_str(),
+ pkgId == nullptr ? nullptr : &pkg_Id,
+ appId == nullptr ? nullptr : &app_Id);
+
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "getting pkg id from pid returned wrong value."
+ << " client: " << client << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
if (pkg_Id) {
*pkgId = pkg_Id;
}
}
-void appHasPrivilege(const char *appId, const char *privilege, uid_t user, int &value, lib_retcode expectedResult)
+void appHasPrivilege(const std::string &appId, const std::string &privilege, uid_t user,
+ int &value, lib_retcode expectedResult)
{
- int result = security_manager_app_has_privilege(appId, privilege, user, &value);
+ int result = security_manager_app_has_privilege(appId.c_str(), privilege.c_str(), user, &value);
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"checking application privilege returned wrong result."
<< " Expected result: " << expectedResult);
}
-void getSecurityManagerGroups(char ***groups, size_t *groups_count, lib_retcode expectedResult)
+void getSecurityManagerGroups(gid_t **groups, size_t *groups_count, lib_retcode expectedResult)
{
int result = security_manager_groups_get(groups, groups_count);
RUNNER_ASSERT_MSG(static_cast<lib_retcode>(result) == expectedResult,
<< " Result: " << result << " Expected: " << expectedResult);
}
+void registerPaths(const PathsRequest& req, lib_retcode expectedResult)
+{
+ int result = security_manager_paths_register(req.get());
+ RUNNER_ASSERT_MSG(static_cast<lib_retcode>(result) == expectedResult,
+ "Unexpected result in security_manager_paths_register()" << std::endl
+ << " Result: " << result << " Expected: " << expectedResult);
+}
+
+void labelsMonitorGetFd(const LabelMonitor &monitor, int *fd, lib_retcode expectedResult)
+{
+ int result = security_manager_app_labels_monitor_get_fd(monitor.get(), fd);
+ RUNNER_ASSERT_MSG(static_cast<lib_retcode>(result) == expectedResult,
+ "Unexpected result in security_manager_app_labels_monitor_get_fd()"
+ << std::endl << " Result: " << result << " Expected: "
+ << expectedResult);
+};
+
+void labelsProcess(const LabelMonitor &monitor, lib_retcode expectedResult)
+{
+ int result = security_manager_app_labels_monitor_process(monitor.get());
+ RUNNER_ASSERT_MSG(static_cast<lib_retcode>(result) == expectedResult,
+ "Unexpected result in security_manager_app_labels_monitor_process()"
+ << std::endl << " Result: " << result << " Expected: "
+ << expectedResult);
+}
+
} // namespace Api
} // namespace SecurityManagerTest