From ba9deb60d8a1c2ed9d853b427bdec555521ca147 Mon Sep 17 00:00:00 2001 From: hunili Date: Thu, 18 Jul 2024 17:34:17 +0800 Subject: [PATCH] Modify faf interfavce error code issue: https://gitee.com/openharmony/filemanagement_user_file_service/issues/IADZDQ Signed-off-by: hunili --- .../file_access/include/file_access_helper.h | 1 + .../file_access/src/file_access_helper.cpp | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/interfaces/inner_api/file_access/include/file_access_helper.h b/interfaces/inner_api/file_access/include/file_access_helper.h index 01902b62..bb03fd19 100644 --- a/interfaces/inner_api/file_access/include/file_access_helper.h +++ b/interfaces/inner_api/file_access/include/file_access_helper.h @@ -109,6 +109,7 @@ private: int CopyOperation(Uri &sourceUri, Uri &destUri, std::vector ©Result, bool force = false); int CopyFileOperation(Uri &sourceUri, Uri &destUri, const std::string &fileName, Uri &newFileUri); int IsDirectory(Uri &uri, bool &isDir); + static bool CheckCallingPermission(const std::string &permission); sptr token_ = nullptr; std::unordered_map> cMap_; diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index b65cc040..a00e873d 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -17,6 +17,7 @@ #include +#include "accesstoken_kit.h" #include "bundle_constants.h" #include "bundle_mgr_proxy.h" #include "file_access_framework_errno.h" @@ -46,6 +47,9 @@ sptr g_destExtProxy; std::vector deviceUris(DEVICE_ROOTS.begin(), DEVICE_ROOTS.end()); +const std::string FILE_ACCESS_PERMISSION = "ohos.permission.FILE_ACCESS_MANAGER"; +const std::string BUNDLE_INFO_PERMISSION = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; + static int GetUserId() { int uid = IPCSkeleton::GetCallingUid(); @@ -935,6 +939,11 @@ int FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(std::vector extensionInfos; sptr bm = FileAccessHelper::GetBundleMgrProxy(); if (bm == nullptr) { @@ -1187,5 +1196,19 @@ int FileAccessHelper::MoveFile(Uri &sourceFile, Uri &targetParent, std::string & return ERR_OK; } + +bool FileAccessHelper::CheckCallingPermission(const std::string &permission) +{ + UserAccessTracer trace; + trace.Start("CheckCallingPermission"); + Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + int res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, permission); + if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + HILOG_ERROR("FileAccessExtStub::CheckCallingPermission have no fileAccess permission"); + return false; + } + + return true; +} } // namespace FileAccessFwk } // namespace OHOS \ No newline at end of file -- Gitee