1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "permission_adapter.h" 17 18 #include "accesstoken_kit.h" 19 #include "ipc_skeleton.h" 20 21 #include "device_auth_defines.h" 22 #include "hc_log.h" 23 24 using namespace OHOS; 25 using namespace OHOS::Security::AccessToken; 26 CheckPermission(void)27int32_t CheckPermission(void) 28 { 29 AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); 30 ATokenTypeEnum tokenType = AccessTokenKit::GetTokenType(tokenId); 31 if (tokenType == TOKEN_NATIVE) { 32 NativeTokenInfo findInfo; 33 if (AccessTokenKit::GetNativeTokenInfo(tokenId, findInfo) != 0) { 34 LOGE("GetNativeTokenInfo failed!"); 35 return HC_ERROR; 36 } 37 if (findInfo.apl == APL_SYSTEM_CORE) { 38 LOGI("Check permission(APL3=SYSTEM_CORE) success!"); 39 return HC_SUCCESS; 40 } else { 41 LOGE("Check permission(APL3=SYSTEM_CORE) failed! APL: %d", findInfo.apl); 42 return HC_ERROR; 43 } 44 } else { 45 LOGE("Invalid token type: %d", tokenType); 46 return HC_ERROR; 47 } 48 }