diff --git a/BUILD.gn b/BUILD.gn index 2c0227e7beda4a1226893f84a588d20b8949f4d6..7aaace9b50ffc52c23842dbf01f11af0c9052950 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -33,13 +33,19 @@ config("appspawn_config") { "${aafwk_path}/frameworks/kits/ability/native/include", "${aafwk_path}/services/abilitymgr/include", "${distributedschedule_path}/services/dtbschedmgr/include", + "//base/security/access_token/interfaces/innerkits/token_setproc/include", + "//base/security/selinux/interfaces/policycoreutils/include", ] } ohos_executable("appspawn") { sources = [ "${appspawn_path}/src/main.cpp" ] configs = [ ":appspawn_config" ] - deps = [ "${appspawn_path}:appspawn_server" ] + deps = [ + "${appspawn_path}:appspawn_server", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + "//base/security/selinux:libload_policy", + ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] install_enable = true diff --git a/interfaces/innerkits/include/client_socket.h b/interfaces/innerkits/include/client_socket.h index 2706a7c31bef2a7a6b966492e579eb6ffaa405cf..7bcb0c7f774b962c13b1184395ac1e4d75e9d6b5 100644 --- a/interfaces/innerkits/include/client_socket.h +++ b/interfaces/innerkits/include/client_socket.h @@ -87,6 +87,7 @@ public: static constexpr int LEN_PROC_NAME = 256; // process name length static constexpr int LEN_SO_PATH = 256; // load so lib static constexpr int MAX_GIDS = 64; + static constexpr int APL_MAX_LEN = 32; struct AppProperty { uint32_t uid; // the UNIX uid that the child process setuid() to after fork() @@ -95,6 +96,8 @@ public: uint32_t gidCount; // the size of gidTable char processName[LEN_PROC_NAME]; // process name char soPath[LEN_SO_PATH]; // so lib path + uint32_t accessTokenId; + char apl[APL_MAX_LEN]; }; private: diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index b4ef590d359acad7d84ccaf87a6bb3bb78a22e58..8f2f62bb164bf17d6b9b065765321d81752181ac 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -35,6 +35,8 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "system_ability_definition.h" +#include "token_setproc.h" +#include "hap_restorecon.h" #include #include @@ -602,6 +604,16 @@ bool AppSpawnServer::SetAppProcProperty(int connectFd, const ClientSocket::AppPr return false; } + ret = SetSelfTokenID(appProperty->accessTokenId); + if (ret != 0) { + HiLog::Error(LABEL, "AppSpawnServer::Failed to set access token id, errno = %{public}d", errno); + } + HapContext hapContext; + ret = hapContext.HapDomainSetcontext(appProperty->apl, appProperty->processName); + if (ret != 0) { + HiLog::Error(LABEL, "AppSpawnServer::Failed to hap domain set context, errno = %{public}d", errno); + } + ret = SetProcessName(longProcName, longProcNameLen, appProperty->processName, strlen(appProperty->processName) + 1); if (FAILED(ret)) { NotifyResToParentProc(fd[1], ret); diff --git a/test/unittest/app_spawn_server_test/BUILD.gn b/test/unittest/app_spawn_server_test/BUILD.gn index 57ed7ac2d04ac04bb7826e761131a18117ae1744..cbfd4c6f55db56ac81fa0afda4063e1b096895f6 100755 --- a/test/unittest/app_spawn_server_test/BUILD.gn +++ b/test/unittest/app_spawn_server_test/BUILD.gn @@ -17,7 +17,10 @@ import("//build/test.gni") ohos_unittest("AppSpawnServerOverrideTest") { module_out_path = "${module_output_path}" - include_dirs = [] + include_dirs = [ + "//base/security/access_token/interfaces/innerkits/token_setproc/include", + "//base/security/selinux/interfaces/policycoreutils/include", + ] sources = [ "${appspawn_path}/src/appspawn_server.cpp", @@ -31,7 +34,11 @@ ohos_unittest("AppSpawnServerOverrideTest") { "app_spawn_server_override_test.cpp", ] - deps = [ "${appspawn_path}/test:appspawn_test_source" ] + deps = [ + "${appspawn_path}/test:appspawn_test_source", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + "//base/security/selinux:libload_policy", + ] external_deps = [ "ability_runtime:app_manager", @@ -49,7 +56,10 @@ ohos_unittest("AppSpawnServerOverrideTest") { ohos_unittest("AppSpawnServerMockTest") { module_out_path = "${module_output_path}" - include_dirs = [] + include_dirs = [ + "//base/security/access_token/interfaces/innerkits/token_setproc/include", + "//base/security/selinux/interfaces/policycoreutils/include", + ] sources = [ "${appspawn_path}/src/appspawn_msg_peer.cpp", @@ -63,7 +73,11 @@ ohos_unittest("AppSpawnServerMockTest") { "app_spawn_server_mock_test.cpp", ] - deps = [ "${appspawn_path}/test:appspawn_test_source" ] + deps = [ + "${appspawn_path}/test:appspawn_test_source", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + "//base/security/selinux:libload_policy", + ] external_deps = [ "ability_runtime:app_manager",