2 * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "launchpad/step_prepare_execution.hh"
20 #include <bundle_cpp.h>
21 #include <bundle_internal.h>
23 #include <security-manager.h>
24 #include <sys/prctl.h>
25 #include <sys/types.h>
26 #include <trust-anchor.h>
30 #include <app_info.hh>
31 #include <aul_keys.hh>
35 #include "launchpad/log_private.hh"
36 #include "launchpad/thread_control.hh"
40 StepPrepareExecution::StepPrepareExecution() {
42 std::bind(&StepPrepareExecution::EnableExternalPackage, this,
43 std::placeholders::_1),
44 std::bind(&StepPrepareExecution::TrustAnchorLaunch, this,
45 std::placeholders::_1),
46 std::bind(&StepPrepareExecution::MountResourceDirectories, this,
47 std::placeholders::_1),
48 std::bind(&StepPrepareExecution::SecurityManagerPrepareApp, this,
49 std::placeholders::_1),
50 std::bind(&StepPrepareExecution::SetupStdio, this,
51 std::placeholders::_1),
52 std::bind(&StepPrepareExecution::BuxtonUpdateClientLabel, this,
53 std::placeholders::_1),
54 std::bind(&StepPrepareExecution::SetDumpable, this,
55 std::placeholders::_1),
56 std::bind(&StepPrepareExecution::SetProcessName, this,
57 std::placeholders::_1),
58 std::bind(&StepPrepareExecution::WaitTepMount, this,
59 std::placeholders::_1),
60 std::bind(&StepPrepareExecution::PrepareAppSocket, this,
61 std::placeholders::_1),
62 std::bind(&StepPrepareExecution::PrepareIdFile, this,
63 std::placeholders::_1),
67 int StepPrepareExecution::Prepare(AppInfo* app_info) {
68 for (auto& step : steps_) {
69 if (step(app_info) != 0)
76 int StepPrepareExecution::EnableExternalPackage(AppInfo* app_info) {
77 int ret = Util::EnableExternalPackage(app_info);
79 _E("Failed to enable external package. error: %d", ret);
86 int StepPrepareExecution::TrustAnchorLaunch(AppInfo* app_info) {
87 int ret = trust_anchor_launch(app_info->GetPkgId().c_str(),
88 app_info->IsGlobal() ? GLOBAL_USER : getuid());
89 if (ret != TRUST_ANCHOR_ERROR_NONE &&
90 ret != TRUST_ANCHOR_ERROR_NOT_INSTALLED) {
91 _E("trust_anchor_launch() is failed. error: %d", ret);
98 int StepPrepareExecution::MountResourceDirectories(AppInfo* app_info) {
99 int ret = Util::MountResourceDirectories(app_info);
101 _E("Failed to mount resource direstories. error: %d", ret);
108 int StepPrepareExecution::SecurityManagerPrepareApp(AppInfo* app_info) {
109 auto* enabled_light_user = bundle_get_val(app_info->GetBundle().GetHandle(),
110 kAulEnabledLightUser);
111 _W("security_manager_prepare_app2() ++ %s", app_info->GetAppId().c_str());
112 int ret = security_manager_prepare_app2(app_info->GetAppId().c_str(),
114 _W("security_manager_prepare_app2() -- %s", app_info->GetAppId().c_str());
115 if (ret != SECURITY_MANAGER_SUCCESS) {
116 _E("security_manager_prepare_app2() is failed. appid: %s, error: %d",
117 app_info->GetAppId().c_str(), ret);
124 int StepPrepareExecution::SetupStdio(AppInfo* app_info) {
129 int StepPrepareExecution::BuxtonUpdateClientLabel(AppInfo* app_info) {
130 struct buxton_client* client = nullptr;
131 int ret = buxton_open(&client, nullptr, nullptr);
133 _E("buxton_open() is failed. errno: %d", errno);
137 ret = buxton_update_client_label_sync(client);
138 buxton_close(client);
140 _E("buxton_update_client_label_sync() is failed. errno: %d", errno);
147 int StepPrepareExecution::SetDumpable(AppInfo* app_info) {
148 prctl(PR_SET_DUMPABLE, 1);
152 int StepPrepareExecution::SetProcessName(AppInfo* app_info) {
153 char* name = basename(const_cast<char*>(app_info->GetAppPath().c_str()));
154 char process_name[16] = { 0, };
155 snprintf(process_name, sizeof(process_name), "%s", name);
156 prctl(PR_SET_NAME, process_name);
160 int StepPrepareExecution::WaitTepMount(AppInfo* app_info) {
161 int ret = Util::WaitTepMount(app_info);
163 _E("Failed to wait tep mount. error: %d", ret);
170 int StepPrepareExecution::PrepareAppSocket(AppInfo* app_info) {
171 int ret = Util::PrepareAppSocket();
173 _E("Failed to prepare app socket. error: %d", ret);
180 int StepPrepareExecution::PrepareIdFile(AppInfo* app_info) {
181 int ret = Util::PrepareAppIdFile(app_info);
183 _E("Failed to prepare id file. error: %d", ret);
190 } // namespace launchpad