From 90fa03e1c4853bab92b4ddd35ba21ca418fdc550 Mon Sep 17 00:00:00 2001 From: lutao Date: Tue, 4 Jul 2023 14:46:29 +0800 Subject: [PATCH] rm transitto Signed-off-by: lutao --- bundle.json | 9 +- transitto/BUILD.gn | 76 ------------- transitto/transitto.cpp | 202 ----------------------------------- transitto/transitto_test.cpp | 34 ------ 4 files changed, 1 insertion(+), 320 deletions(-) delete mode 100644 transitto/BUILD.gn delete mode 100644 transitto/transitto.cpp delete mode 100644 transitto/transitto_test.cpp diff --git a/bundle.json b/bundle.json index 85960c121..c5d8b48ca 100644 --- a/bundle.json +++ b/bundle.json @@ -27,9 +27,7 @@ "components": [ "ability_runtime", "ability_base", - "bounds_checking_function", "bundle_framework", - "common", "common_event_service", "c_utils", "faultloggerd", @@ -40,9 +38,7 @@ "init", "napi", "safwk", - "samgr", - "selinux_adapter", - "zlib" + "samgr" ], "third_party": [ "bounds_checking_function", @@ -52,8 +48,6 @@ "libunwind", "openssl", "protobuf", - "selinux", - "utils", "zlib" ] }, @@ -65,7 +59,6 @@ "//developtools/profiler/host/smartperf/client/:SmartPerf", "//developtools/profiler/host/smartperf/client/client_command_fps/:GP_daemon_fps", "//developtools/profiler/hiebpf:hiebpf_tool", - "//developtools/profiler/transitto:transitto_tool", "//developtools/profiler/timestamps:timestamps_tool" ], "inner_kits": [ diff --git a/transitto/BUILD.gn b/transitto/BUILD.gn deleted file mode 100644 index d6b521fe3..000000000 --- a/transitto/BUILD.gn +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (C) 2023 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//developtools/profiler/device/base/config.gni") - -ohos_executable("transitto") { - sources = [ "transitto.cpp" ] - - include_dirs = [ "//third_party/json/include" ] - defines = [] - cflags_cc = [ "-std=c++20" ] - - external_deps = [ - "ability_base:want", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - deps = [] - - if (build_selinux) { - include_dirs += [ "//third_party/selinux/libselinux/include" ] - deps += [ "//third_party/selinux:libselinux" ] - defines += [ "SUPPORT_SELINUX_TRANSITTO" ] - external_deps += [ - "selinux_adapter:libload_policy", - "selinux_adapter:librestorecon", - ] - } - - install_images = [ "system" ] - - install_enable = true - subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" - part_name = "${OHOS_PROFILER_PART_NAME}" -} - -ohos_executable("transitto_test") { - sources = [ "transitto_test.cpp" ] - - include_dirs = [] - defines = [] - cflags_cc = [ "-std=c++20" ] - - external_deps = [ "c_utils:utils" ] - - deps = [] - - subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" - part_name = "${OHOS_PROFILER_PART_NAME}" -} - -group("transitto_tool") { - deps = [ ":transitto" ] -} - -group("transitto_tool_test") { - deps = [ ":transitto_test" ] -} diff --git a/transitto/transitto.cpp b/transitto/transitto.cpp deleted file mode 100644 index ccbfb2daf..000000000 --- a/transitto/transitto.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef SUPPORT_SELINUX_TRANSITTO -#include -#include -#endif - -#include "bundle_mgr_interface.h" -#include "bundle_mgr_proxy.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" -#include "system_ability_manager_proxy.h" -#include "hilog/log.h" - -using namespace std; - -constexpr OHOS::HiviewDFX::HiLogLabel TRANS_LOG_LABLE = { LOG_CORE, 0xD002D0C, "TRANSITTO" }; - -static bool GetApplicationInfo(const string& bundleName, int& uid) -{ - OHOS::sptr systemAbilityManager = - OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (systemAbilityManager == nullptr) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail to get system abilityManger."); - return false; - } - - OHOS::sptr remoteObject = - systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (remoteObject == nullptr) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail to get bundle service."); - return false; - } - - OHOS::sptr bundleMgrProxy = - OHOS::iface_cast(remoteObject); - if (bundleMgrProxy == nullptr) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail to get bundle proxy."); - return false; - } - - OHOS::HiviewDFX::HiLog::Info(TRANS_LOG_LABLE, "start to get ApplicationInfo"); - // 0: GET_BASIC_APPLICATION_INFO - uid = bundleMgrProxy->GetUidByDebugBundleName(bundleName, OHOS::AppExecFwk::Constants::ANY_USERID); - if (uid < 0) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail to get application info, uid is %{public}d.", uid); - return false; - } - OHOS::HiviewDFX::HiLog::Info(TRANS_LOG_LABLE, "get ApplicationInfo success uid is %{private}d.", uid); - return true; -} - -static bool ChangeUidGid(int uid, int gid) -{ - OHOS::HiviewDFX::HiLog::Info(TRANS_LOG_LABLE, "start change uid gid."); - if (setresgid(gid, gid, gid) < 0) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail set gid, errno is %{publci}d.", errno); - return false; - } - - if (setresuid(uid, uid, uid) < 0) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail set uid, errno is %{publci}d.", errno); - return false; - } - return true; -} - -static void InitEnv(int uid) -{ - OHOS::HiviewDFX::HiLog::Info(TRANS_LOG_LABLE, "start set env."); - - unsetenv("IFS"); - - passwd* pw = getpwuid(uid); - if (pw != nullptr) { - setenv("LOGNAME", pw->pw_name, 1); - setenv("SHELL", pw->pw_shell, 1); - setenv("USER", pw->pw_name, 1); - } else { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail to getpwuid, errno is %{public}d.", errno); - } - return; -} - -static bool SetSelinux() -{ - OHOS::HiviewDFX::HiLog::Info(TRANS_LOG_LABLE, "start change selinux context."); - string seContext = "u:r:transitto_hap:s0"; -#ifdef SUPPORT_SELINUX_TRANSITTO - if (setcon(seContext.c_str()) != 0) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "fail to set selinux context, errno is %{public}d.", errno); - return false; - } -#endif - OHOS::HiviewDFX::HiLog::Info(TRANS_LOG_LABLE, "change selinux context successfully."); - return true; -} - -static void Help() -{ - cout << "\ntransitto is a debuggable tool. your command can transit to the domain of debuggable bundle.\n" - "usage:\n" - "transitto \n" << endl; -} - -static bool CheckValid(int argc, char** argv) -{ - if (argc <= 1) { - cout << "argc is empty" << endl; - Help(); - return false; - } - - string secCom = argv[1]; - if (argc == 2 && (secCom == "-h" || secCom == "--help")) { - Help(); - return false; - } - - uid_t oldUid = getuid(); - // 0, root, 2000 shell - if (oldUid != 0 && oldUid != 2000) { - cout << "only root or shell can run this object" << endl; - Help(); - return false; - } - return true; -} - -int main(int argc, char* argv[]) -{ - if (!CheckValid(argc, argv)) { - return -1; - } - - string bundleName = argv[1]; - int* bundleUidPtr = static_cast(mmap(nullptr, sizeof(int), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)); - if (bundleUidPtr == MAP_FAILED || bundleUidPtr == nullptr) { - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "mmap fail."); - return -1; - } - *bundleUidPtr = -1; - - int pid = fork(); // for security_bounded_transition single thread - if (pid == 0) { - int uid = -1; - GetApplicationInfo(bundleName, uid); - *bundleUidPtr = uid; - _exit(0); - } else { - wait(nullptr); - } - - int uid = *bundleUidPtr; - munmap(bundleUidPtr, sizeof(int)); - - string commod = (argc > 2) ? argv[2] : ""; // 2 com - // normal_hap uid = 200000 * usrid + bundleid % 200000, userid is 100 or 0(shared) - if (uid <= 20000000 || !ChangeUidGid(uid, uid) || !SetSelinux()) { // 20000000 is uid offset - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, "uid is %{public}d.", uid); - return -1; - } - - InitEnv(uid); - if (argc > 2 && execvp(argv[2], argv + 2) < 0) { // 2: offset - OHOS::HiviewDFX::HiLog::Error(TRANS_LOG_LABLE, - "fail to execvp, com is %{public}s, errno %{public}d.", argv[2], errno); // 2: offset - return -1; - } - - execlp("/system/bin/sh", "sh", nullptr); - return 0; -} \ No newline at end of file diff --git a/transitto/transitto_test.cpp b/transitto/transitto_test.cpp deleted file mode 100644 index 350265a0f..000000000 --- a/transitto/transitto_test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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 -#include - -using namespace std; -int main(int argc, char* argv[]) -{ - cout << "argc is " << argc << endl; - for (int i = 0; i < argc; i++) { - cout << "argv " << i << " is " << argv[i] << endl; - } - - cout << "begin to sleep 100s" << endl; - fflush(stdout); - sleep(100); // 100 : 100s - return 0; -} \ No newline at end of file