From a5da7c3c9d9d41898a448e88f243028c358cb31a Mon Sep 17 00:00:00 2001 From: yangguangzhao Date: Thu, 28 Apr 2022 19:25:36 +0800 Subject: [PATCH] Rpc use dynamic permission Signed-off-by: yangguangzhao --- .../libdbinder/include/dbinder_service.h | 2 +- .../src/dbinder_sa_death_recipient.cpp | 15 +++++++++++++++ .../src/socket/dbinder_remote_listener.cpp | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/libdbinder/include/dbinder_service.h b/interfaces/innerkits/libdbinder/include/dbinder_service.h index 22f504b..074b863 100644 --- a/interfaces/innerkits/libdbinder/include/dbinder_service.h +++ b/interfaces/innerkits/libdbinder/include/dbinder_service.h @@ -117,6 +117,7 @@ public: bool DetachBusNameObject(IPCObjectProxy *proxy); std::string CreateDatabusName(int uid, int pid); bool DetachProxyObject(binder_uintptr_t binderObject); + std::string QueryBusNameObject(IPCObjectProxy *proxy); private: static std::shared_ptr GetRemoteListener(); @@ -157,7 +158,6 @@ private: std::string &remoteDeviceId, int pid, int uid); bool IsDeviceIdIllegal(const std::string &deviceID); bool AttachBusNameObject(IPCObjectProxy *proxy, const std::string &name); - std::string QueryBusNameObject(IPCObjectProxy *proxy); std::string GetDatabusNameByProxy(IPCObjectProxy *proxy); uint32_t GetSeqNumber(); bool RegisterRemoteProxyInner(std::u16string serviceName, binder_uintptr_t binder); diff --git a/services/dbinder/dbinder_service/src/dbinder_sa_death_recipient.cpp b/services/dbinder/dbinder_service/src/dbinder_sa_death_recipient.cpp index 028964a..a9317fd 100644 --- a/services/dbinder/dbinder_service/src/dbinder_sa_death_recipient.cpp +++ b/services/dbinder/dbinder_service/src/dbinder_sa_death_recipient.cpp @@ -16,9 +16,12 @@ #include "dbinder_sa_death_recipient.h" #include "dbinder_service.h" #include "dbinder_log.h" +#include "ISessionService.h" #include "log_tags.h" namespace OHOS { +using Communication::SoftBus::ISessionService; + #ifndef TITLE #define TITLE __PRETTY_FUNCTION__ #endif @@ -51,5 +54,17 @@ void DbinderSaDeathRecipient::OnRemoteDied(const wptr &remote) (void)dBinderService->DetachBusNameObject(proxy); (void)dBinderService->DetachProxyObject(binderObject_); + + std::shared_ptr softbusManager = ISessionService::GetInstance(); + if (softbusManager == nullptr) { + DBINDER_LOGE("fail to get softbus service"); + return; + } + std::string sessionName = dBinderService->QueryBusNameObject(proxy); + if (sessionName.empty()) { + DBINDER_LOGE("proxy sessionName not found"); + return; + } + softbusManager->RemovePermission(sessionName); } } // namespace OHOS diff --git a/services/dbinder/dbinder_service/src/socket/dbinder_remote_listener.cpp b/services/dbinder/dbinder_service/src/socket/dbinder_remote_listener.cpp index b3baa51..510196b 100644 --- a/services/dbinder/dbinder_service/src/socket/dbinder_remote_listener.cpp +++ b/services/dbinder/dbinder_service/src/socket/dbinder_remote_listener.cpp @@ -39,6 +39,13 @@ bool DBinderRemoteListener::StartListener(std::shared_ptr DBINDER_LOGE("fail to get softbus service"); return false; } + int pid = static_cast(getpid()); + int uid = static_cast(getuid()); + if (softbusManager_->GrantPermission(uid, pid, OWN_SESSION_NAME) != ERR_NONE) { + DBINDER_LOGE("fail to Grant Permission softbus name %{public}s", OWN_SESSION_NAME.c_str()); + return false; + } + int ret = softbusManager_->CreateSessionServer(OWN_SESSION_NAME, PEER_SESSION_NAME, listener); if (ret != 0) { DBINDER_LOGE("fail to create softbus server with ret = %{public}d", ret); -- GitLab