From 00a503eb4ceda15d9f98410307f1ae1caf09045d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 3 Apr 2020 22:00:22 +0200 Subject: [PATCH] Add ScopedAppLauncher Needed to check smack rules while app is running Change-Id: I6ef63fc76dd27fb6119245541dc2fd9544ff98fe --- src/security-manager-tests/CMakeLists.txt | 1 + .../common/scoped_app_launcher.cpp | 51 ++++++++++++++++++++++ .../common/scoped_app_launcher.h | 32 ++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/security-manager-tests/common/scoped_app_launcher.cpp create mode 100644 src/security-manager-tests/common/scoped_app_launcher.h diff --git a/src/security-manager-tests/CMakeLists.txt b/src/security-manager-tests/CMakeLists.txt index cf08aa4..57ed71f 100644 --- a/src/security-manager-tests/CMakeLists.txt +++ b/src/security-manager-tests/CMakeLists.txt @@ -58,6 +58,7 @@ SET(SEC_MGR_SOURCES ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/policy_configuration.cpp ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/sm_commons.cpp ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/template_parser.cpp + ${PROJECT_SOURCE_DIR}/src/security-manager-tests/common/scoped_app_launcher.cpp ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_client.cpp ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_admin.cpp ${PROJECT_SOURCE_DIR}/src/cynara-tests/plugins/plugins.cpp diff --git a/src/security-manager-tests/common/scoped_app_launcher.cpp b/src/security-manager-tests/common/scoped_app_launcher.cpp new file mode 100644 index 0000000..8647535 --- /dev/null +++ b/src/security-manager-tests/common/scoped_app_launcher.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +using namespace SecurityManagerTest; + +ScopedAppLauncher::ScopedAppLauncher(const AppInstallHelper& app) +{ + SynchronizationPipe syncPipe; + + m_pid = fork(); + RUNNER_ASSERT_ERRNO_MSG(m_pid >= 0, "Fork failed"); + if (m_pid != 0) { + m_syncPipe.claimParentEp(); + m_syncPipe.wait(); + } else { + m_syncPipe.claimChildEp(); + + RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(app.getUID(), app.getGID()) == 0, + "launcher failed"); + Api::prepareAppCandidate(); + Api::prepareApp(app.getAppId().c_str()); + + m_syncPipe.post(); + m_syncPipe.wait(); + exit(0); + } +} + +ScopedAppLauncher::~ScopedAppLauncher() +{ + m_syncPipe.post(); + waitPid(m_pid); +} diff --git a/src/security-manager-tests/common/scoped_app_launcher.h b/src/security-manager-tests/common/scoped_app_launcher.h new file mode 100644 index 0000000..496df68 --- /dev/null +++ b/src/security-manager-tests/common/scoped_app_launcher.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include + +class ScopedAppLauncher final { +public: + ScopedAppLauncher(const AppInstallHelper& app); + ~ScopedAppLauncher(); + + ScopedAppLauncher(const ScopedAppLauncher&) = delete; + ScopedAppLauncher& operator=(const ScopedAppLauncher&) = delete; + +private: + SynchronizationPipe m_syncPipe; + pid_t m_pid; +}; -- 2.7.4