From 4bf4c6184dadfcc82acd1cb13abb598f71ec8390 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:29:15 +0000 Subject: [PATCH 01/15] update BUILD.gn. --- BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BUILD.gn b/BUILD.gn index b9397ed3d..1a7fc27f6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,6 +19,7 @@ group("accesstoken_build_module") { deps = [ "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "//base/security/access_token/interfaces/innerkits/nativetoken:libaccesstoken_lib", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "//base/security/access_token/services/accesstokenmanager:accesstoken_manager_service", "//base/security/access_token/services/accesstokenmanager/main/sa_profile:accesstoken_sa_profile_standard", ] @@ -43,6 +44,7 @@ group("accesstoken_build_module_test") { "//base/security/access_token/interfaces/innerkits/accesstoken/test:unittest", "//base/security/access_token/interfaces/innerkits/nativetoken/test:unittest", "//base/security/access_token/interfaces/innerkits/tokensync/test:unittest", + "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", "//base/security/access_token/services/accesstokenmanager/test:unittest", ] } -- Gitee From 0bc11b44a7b96f7d759a86e8e09a7ad53266d5ab Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:30:25 +0000 Subject: [PATCH 02/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20token=5Fsetproc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/.keep diff --git a/interfaces/innerkits/token_setproc/.keep b/interfaces/innerkits/token_setproc/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From bd8de83caf0eafc864717d3f83db12edfff3a3ad Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:30:45 +0000 Subject: [PATCH 03/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20include?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/include/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/include/.keep diff --git a/interfaces/innerkits/token_setproc/include/.keep b/interfaces/innerkits/token_setproc/include/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From d9d448d090efc6ee6ddbe5cb2e40986b047a4ebd Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:30:55 +0000 Subject: [PATCH 04/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20src?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/src/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/src/.keep diff --git a/interfaces/innerkits/token_setproc/src/.keep b/interfaces/innerkits/token_setproc/src/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From c6cb3d1b88b88489425a8d9a8b804d3f49fe53c7 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:31:02 +0000 Subject: [PATCH 05/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/test/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/test/.keep diff --git a/interfaces/innerkits/token_setproc/test/.keep b/interfaces/innerkits/token_setproc/test/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From e35ae3e6e8b2aa02cd31aec057cf0fba60c5c004 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:31:58 +0000 Subject: [PATCH 06/15] =?UTF-8?q?=E6=96=B0=E5=A2=9EBUILD.gn=E5=88=B0token?= =?UTF-8?q?=5Fsetproc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/BUILD.gn | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 interfaces/innerkits/token_setproc/BUILD.gn diff --git a/interfaces/innerkits/token_setproc/BUILD.gn b/interfaces/innerkits/token_setproc/BUILD.gn new file mode 100644 index 000000000..f3fd592dc --- /dev/null +++ b/interfaces/innerkits/token_setproc/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (C) 2021 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") + +################################################################ +# C, Main, source file here. +################################################################ +config("token_setproc") { + visibility = [ ":*" ] + include_dirs = [ "include" ] +} + +ohos_static_library("libtoken_setproc") { + subsystem_name = "security" + part_name = "access_token" + + output_name = "libtoken_setproc" + + public_configs = [ ":token_setproc" ] + + cflags = [ "-Wall" ] + + include_dirs = [ + "include", + "src", + ] + + sources = [ + "src/token_setproc.c", + ] + + deps = [ + + ] +} \ No newline at end of file -- Gitee From ae85d3b79ef757b76ef045cb4d364f1bc3d92b79 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:32:33 +0000 Subject: [PATCH 07/15] add token_setproc.h --- .../token_setproc/include/token_setproc.h | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 interfaces/innerkits/token_setproc/include/token_setproc.h diff --git a/interfaces/innerkits/token_setproc/include/token_setproc.h b/interfaces/innerkits/token_setproc/include/token_setproc.h new file mode 100644 index 000000000..cf9dc7dba --- /dev/null +++ b/interfaces/innerkits/token_setproc/include/token_setproc.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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. + */ + + +#ifndef TOKEN_setproc_H +#define TOKEN_setproc_H +#include + +#ifdef __cplusplus +extern "c"{ +#endif + +uint64_t GetSelfTokenID(); + +int SetSelfTokenID(uint64_t tokenID); + +uint64_t GetFirstCallerTokenID(); + +int SetFirstCallerTokenID(uint64_t tokenID); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file -- Gitee From 42547bd9610332b7229e5fb5ab274d8e388c27ec Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:33:04 +0000 Subject: [PATCH 08/15] add token_setproc.c --- .../token_setproc/src/token_setproc.c | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 interfaces/innerkits/token_setproc/src/token_setproc.c diff --git a/interfaces/innerkits/token_setproc/src/token_setproc.c b/interfaces/innerkits/token_setproc/src/token_setproc.c new file mode 100644 index 000000000..af0c0d8c2 --- /dev/null +++ b/interfaces/innerkits/token_setproc/src/token_setproc.c @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2021 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 "token_setproc.h" +#include +#include +#include +#include +#include + + + + +#define ACCESS_TOKEN_ID_IOCTL_BASE 'A' + +enum { + GET_TOKEN_ID = 1, + SET_TOKEN_ID, + GET_FTOKEN_ID, + SET_FTOKEN_ID, + ACCESS_TOKENID_MAX_NR, +}; + +#define ACCESS_TOKENID_GET_TOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE,GET_TOKEN_ID,unsigned long long) +#define ACCESS_TOKENID_SET_TOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE,SET_TOKEN_ID,unsigned long long) +#define ACCESS_TOKENID_GET_FTOKENID\ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE,GET_FTOKEN_ID,unsigned long long) +#define ACCESS_TOKENID_SET_FTOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE,SET_FTOKEN_ID,unsigned long long) + +#define ACCESS_TOKEN_OK 0 +#define ACCESS_TOKEN_ERROR (-1) + +#define INVAL_TOKEN_ID 0x0 +#define TOKEN_ID_LOWMASK 0xffffffff + +#define TOKENID_DEVNODE "/dev/access_token_id" + +uint64_t GetSelfTokenID() +{ + uint64_t token = INVAL_TOKEN_ID; + int fd = open(TOKENID_DEVNODE,O_RDWR); + if (fd < 0) { + return INVAL_TOKEN_ID; + } + int ret =ioctl(fd,ACCESS_TOKENID_GET_TOKENID,&token); + if (ret) { + close(fd); + return INVAL_TOKEN_ID; + } + + close(fd); + return token; +} + +int SetSelfTokenID(uint64_t tokenID) +{ + int fd = open(TOKENID_DEVNODE,O_RDWR); + if (fd < 0) { + return ACCESS_TOKEN_ERROR; + } + int ret = ioctl(fd,ACCESS_TOKENID_SET_TOKENID,&tokenID); + if (ret) { + close(fd); + return ACCESS_TOKEN_ERROR; + } + + close(fd); + return ACCESS_TOKEN_OK; +} + +uint64_t GetFirstCallerTokenID() +{ + uint64_t token = INVAL_TOKEN_ID; + int fd = open(TOKENID_DEVNODE,O_RDWR); + if (fd < 0) { + return INVAL_TOKEN_ID; + } + int ret = ioctl(fd,ACCESS_TOKENID_GET_FTOKENID,&token); + if (ret) { + close(fd); + return INVAL_TOKEN_ID; + } + + close(fd); + return token; +} + +int SetFirstCallerTokenID(uint64_t tokenID) +{ + int fd = open(TOKENID_DEVNODE,O_RDWR); + if (fd < 0) { + return ACCESS_TOKEN_ERROR; + } + int ret = ioctl(fd,ACCESS_TOKENID_SET_FTOKENID,&tokenID); + if (ret) { + close(fd); + return ACCESS_TOKEN_ERROR; + } + + close(fd); + return ACCESS_TOKEN_OK; +} \ No newline at end of file -- Gitee From c458318b8c2e953622733f46f353fa60efeeeb48 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:33:28 +0000 Subject: [PATCH 09/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20unittest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/test/unittest/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/test/unittest/.keep diff --git a/interfaces/innerkits/token_setproc/test/unittest/.keep b/interfaces/innerkits/token_setproc/test/unittest/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 59adc2d3dbbc602cb33230626cd7215c525bc022 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:33:52 +0000 Subject: [PATCH 10/15] add BUILD.gn --- .../innerkits/token_setproc/test/BUILD.gn | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 interfaces/innerkits/token_setproc/test/BUILD.gn diff --git a/interfaces/innerkits/token_setproc/test/BUILD.gn b/interfaces/innerkits/token_setproc/test/BUILD.gn new file mode 100644 index 000000000..50c911d84 --- /dev/null +++ b/interfaces/innerkits/token_setproc/test/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (C) 2021 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/test.gni") + +ohos_unittest("libtoken_setproc_test") { + subsystem_name = "security" + part_name = "access_token" + module_out_path = part_name + "/" + part_name + + include_dirs = [ + "//base/security/access_token/interfaces/innerkits/token_setproc/include" + ] + + sources = [ "unittest/cpp/src/tokensetproc_kit_test.cpp" ] + + cflags_cc = [ "-fexceptions" ] + + deps = [ + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", + ] +} + +group("unittest") { + testonly = true + deps = [ ":libtoken_setproc_test" ] +} \ No newline at end of file -- Gitee From 4f4f1ba16463fefdcc42796fc533be3209f57a05 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:34:04 +0000 Subject: [PATCH 11/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/test/unittest/cpp/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/test/unittest/cpp/.keep diff --git a/interfaces/innerkits/token_setproc/test/unittest/cpp/.keep b/interfaces/innerkits/token_setproc/test/unittest/cpp/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From d01c77a1fc1e99916037567f0c3ab328c81a05e3 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:34:16 +0000 Subject: [PATCH 12/15] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20src?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/token_setproc/test/unittest/cpp/src/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interfaces/innerkits/token_setproc/test/unittest/cpp/src/.keep diff --git a/interfaces/innerkits/token_setproc/test/unittest/cpp/src/.keep b/interfaces/innerkits/token_setproc/test/unittest/cpp/src/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From ff11bf4326a8661086047a734e58b0e68fe63c87 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:35:01 +0000 Subject: [PATCH 13/15] add tokensetproc_kit_test.cpp and tokensetproc_kit_test.h --- .../cpp/src/tokensetproc_kit_test.cpp | 33 +++++++++++++++++ .../unittest/cpp/src/tokensetproc_kit_test.h | 35 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.cpp create mode 100644 interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.h diff --git a/interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.cpp b/interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.cpp new file mode 100644 index 000000000..4463b0954 --- /dev/null +++ b/interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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 "tokensetproc_kit_test.h" + +#include "token_setproc.h" + +using namespace testing::ext; +using namespace OHOS::Security; + +void TokensetprocKitTest::SetUpTestCase() +{} + +void TokensetprocKitTest::TearDownTestCase() +{} + +void TokensetprocKitTest::SetUp() +{} + +void TokensetprocKitTest::TearDown() +{} \ No newline at end of file diff --git a/interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.h b/interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.h new file mode 100644 index 000000000..63a7cd567 --- /dev/null +++ b/interfaces/innerkits/token_setproc/test/unittest/cpp/src/tokensetproc_kit_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef TOKENSYNC_KIT_TEST_H +#define TOKENSYNC_KIT_TEST_H + +#include + +namespace OHOS { +namespace Security { +class TokensetprocKitTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; +} //namespace Security +} //namespace OHOS +#endif \ No newline at end of file -- Gitee From 8bcb5616abb35f6fe8fb59d51b52ad320e15b96f Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:45:05 +0000 Subject: [PATCH 14/15] update interfaces/innerkits/token_setproc/include/token_setproc.h. --- interfaces/innerkits/token_setproc/include/token_setproc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/token_setproc/include/token_setproc.h b/interfaces/innerkits/token_setproc/include/token_setproc.h index cf9dc7dba..f6bb33d2f 100644 --- a/interfaces/innerkits/token_setproc/include/token_setproc.h +++ b/interfaces/innerkits/token_setproc/include/token_setproc.h @@ -14,8 +14,8 @@ */ -#ifndef TOKEN_setproc_H -#define TOKEN_setproc_H +#ifndef TOKEN_SETPROC_H +#define TOKEN_SETPROC_H #include #ifdef __cplusplus -- Gitee From 39103c9fa61c7bd3ca5efcd0d5e149da407520f6 Mon Sep 17 00:00:00 2001 From: huadongqin Date: Wed, 12 Jan 2022 08:57:36 +0000 Subject: [PATCH 15/15] update interfaces/innerkits/token_setproc/include/token_setproc.h. --- interfaces/innerkits/token_setproc/include/token_setproc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/token_setproc/include/token_setproc.h b/interfaces/innerkits/token_setproc/include/token_setproc.h index f6bb33d2f..57c05e2af 100644 --- a/interfaces/innerkits/token_setproc/include/token_setproc.h +++ b/interfaces/innerkits/token_setproc/include/token_setproc.h @@ -19,7 +19,7 @@ #include #ifdef __cplusplus -extern "c"{ +extern "C"{ #endif uint64_t GetSelfTokenID(); -- Gitee