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