1 /* 2 * Copyright (c) 2025 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 #ifndef OHOS_SOFTBUS_ADAPTER_SOFTBUS_PERMISSION_CHECK_H 17 #define OHOS_SOFTBUS_ADAPTER_SOFTBUS_PERMISSION_CHECK_H 18 19 #include <string> 20 21 #include "transport/trans_type.h" 22 23 namespace OHOS { 24 namespace DistributedHardware { 25 const int32_t INVALID_USER_ID = -1; 26 struct AccountInfo { 27 int32_t userId_ = INVALID_USER_ID; 28 uint64_t tokenId_ = 0; 29 std::string accountId_; 30 std::string networkId_; 31 }; 32 33 class SoftBusPermissionCheck { 34 public: 35 static bool CheckSrcPermission(const std::string &sinkNetworkId); 36 static bool CheckSinkPermission(const AccountInfo &callerAccountInfo); 37 static bool GetLocalAccountInfo(AccountInfo &localAccountInfo); 38 static int32_t GetCurrentUserId(); 39 static bool TransCallerInfo(SocketAccessInfo *callerInfo, 40 AccountInfo &callerAccountInfo, const std::string &networkId); 41 static bool FillLocalInfo(SocketAccessInfo *localInfo); 42 static bool SetAccessInfoToSocket(const int32_t sessionId); 43 private: 44 static bool CheckSrcIsSameAccount(const std::string &sinkNetworkId, const AccountInfo &localAccountInfo); 45 static bool CheckSinkIsSameAccount(const AccountInfo &callerAccountInfo, const AccountInfo &calleeAccountInfo); 46 static bool CheckSrcAccessControl(const std::string &sinkNetworkId, const AccountInfo &localAccountInfo); 47 static bool CheckSinkAccessControl(const AccountInfo &callerAccountInfo, const AccountInfo &calleeAccountInfo); 48 static bool GetLocalNetworkId(std::string &networkId); 49 }; 50 } // namespace DistributedHardware 51 } // namespace OHOS 52 53 #endif // OHOS_SOFTBUS_ADAPTER_SOFTBUS_PERMISSION_CHECK_H