From beb10b338060c6c4c95c69d897c0a8cc07ea5638 Mon Sep 17 00:00:00 2001 From: lwk <1076278852@qq.com> Date: Thu, 24 Mar 2022 19:18:42 +0800 Subject: [PATCH 1/3] fix: code review liuwenkai@huawei.com Signed-off-by: lwk <1076278852@qq.com> --- .../kitsimpl/include/coauth_callback_proxy.h | 4 ++-- .../kitsimpl/include/coauth_callback_stub.h | 4 ++-- frameworks/kitsimpl/include/coauth_proxy.h | 20 +++++++++---------- .../include/executor_callback_proxy.h | 14 ++++++------- .../kitsimpl/include/executor_callback_stub.h | 14 ++++++------- .../include/executor_messenger_proxy.h | 8 ++++---- .../kitsimpl/include/query_callback_proxy.h | 2 +- .../kitsimpl/include/query_callback_stub.h | 2 +- .../include/set_prop_callback_proxy.h | 2 +- .../kitsimpl/include/set_prop_callback_stub.h | 2 +- .../innerkits/include/executor_messenger.h | 8 ++++---- services/include/coauth_service.h | 16 +++++++-------- services/src/auth_res_manager.cpp | 2 +- 13 files changed, 49 insertions(+), 49 deletions(-) diff --git a/frameworks/kitsimpl/include/coauth_callback_proxy.h b/frameworks/kitsimpl/include/coauth_callback_proxy.h index b1f226b..a01ffbb 100644 --- a/frameworks/kitsimpl/include/coauth_callback_proxy.h +++ b/frameworks/kitsimpl/include/coauth_callback_proxy.h @@ -29,8 +29,8 @@ public: : IRemoteProxy(impl) {} ~CoAuthCallbackProxy() override = default; - virtual void OnFinish(uint32_t resultCode, std::vector &scheduleToken) override; - virtual void OnAcquireInfo(uint32_t acquire) override; + void OnFinish(uint32_t resultCode, std::vector &scheduleToken) override; + void OnAcquireInfo(uint32_t acquire) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/include/coauth_callback_stub.h b/frameworks/kitsimpl/include/coauth_callback_stub.h index b4fe33a..ea3dbe5 100644 --- a/frameworks/kitsimpl/include/coauth_callback_stub.h +++ b/frameworks/kitsimpl/include/coauth_callback_stub.h @@ -28,8 +28,8 @@ public: explicit CoAuthCallbackStub(const std::shared_ptr& impl); ~CoAuthCallbackStub() override = default; - virtual void OnFinish(uint32_t resultCode, std::vector &scheduleToken) override; - virtual void OnAcquireInfo(uint32_t acquire) override; + void OnFinish(uint32_t resultCode, std::vector &scheduleToken) override; + void OnAcquireInfo(uint32_t acquire) override; int32_t OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; diff --git a/frameworks/kitsimpl/include/coauth_proxy.h b/frameworks/kitsimpl/include/coauth_proxy.h index cf54b15..fad1ac7 100644 --- a/frameworks/kitsimpl/include/coauth_proxy.h +++ b/frameworks/kitsimpl/include/coauth_proxy.h @@ -30,16 +30,16 @@ public: : IRemoteProxy(impl) {} ~CoAuthProxy() override = default; - virtual uint64_t Register(std::shared_ptr executorInfo, - const sptr &callback) override; - virtual void QueryStatus(AuthResPool::AuthExecutor &executorInfo, - const sptr &callback) override; - virtual void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) override; - virtual int32_t Cancel(uint64_t scheduleId) override; - virtual int32_t GetExecutorProp(AuthResPool::AuthAttributes &conditions, - std::shared_ptr values) override; - virtual void SetExecutorProp(AuthResPool::AuthAttributes &conditions, - const sptr &callback) override; + uint64_t Register(std::shared_ptr executorInfo, + const sptr &callback) override; + void QueryStatus(AuthResPool::AuthExecutor &executorInfo, + const sptr &callback) override; + void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) override; + int32_t Cancel(uint64_t scheduleId) override; + int32_t GetExecutorProp(AuthResPool::AuthAttributes &conditions, + std::shared_ptr values) override; + void SetExecutorProp(AuthResPool::AuthAttributes &conditions, + const sptr &callback) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, bool isSync = true); diff --git a/frameworks/kitsimpl/include/executor_callback_proxy.h b/frameworks/kitsimpl/include/executor_callback_proxy.h index 54a3cee..94486b9 100644 --- a/frameworks/kitsimpl/include/executor_callback_proxy.h +++ b/frameworks/kitsimpl/include/executor_callback_proxy.h @@ -29,13 +29,13 @@ public: : IRemoteProxy(impl) {} ~ExecutorCallbackProxy() override = default; - virtual void OnMessengerReady(const sptr &messenger) override; - virtual int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, - std::shared_ptr commandAttrs) override; - virtual int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) override; - virtual int32_t OnSetProperty(std::shared_ptr properties) override; - virtual int32_t OnGetProperty(std::shared_ptr conditions, - std::shared_ptr values) override; + void OnMessengerReady(const sptr &messenger) override; + int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, + std::shared_ptr commandAttrs) override; + int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) override; + int32_t OnSetProperty(std::shared_ptr properties) override; + int32_t OnGetProperty(std::shared_ptr conditions, + std::shared_ptr values) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; diff --git a/frameworks/kitsimpl/include/executor_callback_stub.h b/frameworks/kitsimpl/include/executor_callback_stub.h index ceb41fc..7e7dd21 100644 --- a/frameworks/kitsimpl/include/executor_callback_stub.h +++ b/frameworks/kitsimpl/include/executor_callback_stub.h @@ -27,13 +27,13 @@ class ExecutorCallbackStub : public IRemoteStub { public: ExecutorCallbackStub(const std::shared_ptr& impl); ~ExecutorCallbackStub() override = default; - virtual void OnMessengerReady(const sptr &messenger) override; - virtual int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, - std::shared_ptr commandAttrs) override; - virtual int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) override; - virtual int32_t OnSetProperty(std::shared_ptr properties) override; - virtual int32_t OnGetProperty(std::shared_ptr conditions, - std::shared_ptr values) override; + void OnMessengerReady(const sptr &messenger) override; + int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, + std::shared_ptr commandAttrs) override; + int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) override; + int32_t OnSetProperty(std::shared_ptr properties) override; + int32_t OnGetProperty(std::shared_ptr conditions, + std::shared_ptr values) override; int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: int32_t OnMessengerReadyStub(MessageParcel& data, MessageParcel& reply); diff --git a/frameworks/kitsimpl/include/executor_messenger_proxy.h b/frameworks/kitsimpl/include/executor_messenger_proxy.h index 1968c61..7de24d1 100644 --- a/frameworks/kitsimpl/include/executor_messenger_proxy.h +++ b/frameworks/kitsimpl/include/executor_messenger_proxy.h @@ -29,10 +29,10 @@ public: : IRemoteProxy(impl) {} ~ExecutorMessengerProxy() override = default; - virtual int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, - int32_t dstType, std::shared_ptr msg) override; - virtual int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, - std::shared_ptr finalResult) override; + int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, + int32_t dstType, std::shared_ptr msg) override; + int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, + std::shared_ptr finalResult) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/include/query_callback_proxy.h b/frameworks/kitsimpl/include/query_callback_proxy.h index 0c3463e..bd89de7 100644 --- a/frameworks/kitsimpl/include/query_callback_proxy.h +++ b/frameworks/kitsimpl/include/query_callback_proxy.h @@ -28,7 +28,7 @@ public: : IRemoteProxy(impl) {} ~QueryCallbackProxy() override = default; - virtual void OnResult(uint32_t resultCode) override; + void OnResult(uint32_t resultCode) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/include/query_callback_stub.h b/frameworks/kitsimpl/include/query_callback_stub.h index 24b6d24..98c0d35 100644 --- a/frameworks/kitsimpl/include/query_callback_stub.h +++ b/frameworks/kitsimpl/include/query_callback_stub.h @@ -27,7 +27,7 @@ public: explicit QueryCallbackStub(const std::shared_ptr& impl); ~QueryCallbackStub() override = default; - virtual void OnResult(uint32_t resultCode) override; + void OnResult(uint32_t resultCode) override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; diff --git a/frameworks/kitsimpl/include/set_prop_callback_proxy.h b/frameworks/kitsimpl/include/set_prop_callback_proxy.h index a05e1e8..b772b61 100644 --- a/frameworks/kitsimpl/include/set_prop_callback_proxy.h +++ b/frameworks/kitsimpl/include/set_prop_callback_proxy.h @@ -27,7 +27,7 @@ public: explicit SetPropCallbackProxy(const sptr& impl) : IRemoteProxy(impl) {} ~SetPropCallbackProxy() override = default; - virtual void OnResult(uint32_t result, std::vector &extraInfo) override; + void OnResult(uint32_t result, std::vector &extraInfo) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/include/set_prop_callback_stub.h b/frameworks/kitsimpl/include/set_prop_callback_stub.h index 00a235d..5ac3e84 100644 --- a/frameworks/kitsimpl/include/set_prop_callback_stub.h +++ b/frameworks/kitsimpl/include/set_prop_callback_stub.h @@ -29,7 +29,7 @@ public: explicit SetPropCallbackStub(const std::shared_ptr& impl); ~SetPropCallbackStub() override = default; - virtual void OnResult(uint32_t result, std::vector &extraInfo) override; + void OnResult(uint32_t result, std::vector &extraInfo) override; int32_t OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; diff --git a/interfaces/innerkits/include/executor_messenger.h b/interfaces/innerkits/include/executor_messenger.h index 21e1712..c063787 100644 --- a/interfaces/innerkits/include/executor_messenger.h +++ b/interfaces/innerkits/include/executor_messenger.h @@ -27,10 +27,10 @@ class ExecutorMessenger : public ExecutorMessengerStub { public: ExecutorMessenger(UserIAM::CoAuth::AuthResPool*); ~ExecutorMessenger() override = default; - virtual int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, - int32_t dstType, std::shared_ptr msg) override; - virtual int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, - std::shared_ptr finalResult) override; + int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, + int32_t dstType, std::shared_ptr msg) override; + int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, + std::shared_ptr finalResult) override; private: void DeleteScheduleInfoById(uint64_t scheduleId); int32_t DoSignToken(uint64_t scheduleId, std::vector& scheduleToken, diff --git a/services/include/coauth_service.h b/services/include/coauth_service.h index f807960..8b1ab35 100644 --- a/services/include/coauth_service.h +++ b/services/include/coauth_service.h @@ -39,16 +39,16 @@ class CoAuthService : public SystemAbility, public CoAuthStub { public: DECLEAR_SYSTEM_ABILITY(CoAuthService); explicit CoAuthService(int32_t systemAbilityId, bool runOnCreate = false); - virtual ~CoAuthService() override; + ~CoAuthService() override; void OnStart() override; void OnStop() override; - virtual uint64_t Register(std::shared_ptr executorInfo, - const sptr &callback) override; - virtual void QueryStatus(ResAuthExecutor &executorInfo, const sptr &callback) override; - virtual void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) override; - virtual int32_t Cancel(uint64_t scheduleId) override; - virtual int32_t GetExecutorProp(ResAuthAttributes &conditions, std::shared_ptr values) override; - virtual void SetExecutorProp(ResAuthAttributes &conditions, const sptr &callback) override; + uint64_t Register(std::shared_ptr executorInfo, + const sptr &callback) override; + void QueryStatus(ResAuthExecutor &executorInfo, const sptr &callback) override; + void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) override; + int32_t Cancel(uint64_t scheduleId) override; + int32_t GetExecutorProp(ResAuthAttributes &conditions, std::shared_ptr values) override; + void SetExecutorProp(ResAuthAttributes &conditions, const sptr &callback) override; private: CoAuthRunningState state_ = CoAuthRunningState::STATE_STOPPED; diff --git a/services/src/auth_res_manager.cpp b/services/src/auth_res_manager.cpp index 3e4b1fb..4971541 100644 --- a/services/src/auth_res_manager.cpp +++ b/services/src/auth_res_manager.cpp @@ -86,7 +86,7 @@ void AuthResManager::QueryStatus(ResAuthExecutor &executorInfo, sptr Date: Fri, 25 Mar 2022 11:39:34 +0800 Subject: [PATCH 2/3] fix: code review liuwenkai@huawei.com Signed-off-by: lwk <1076278852@qq.com> --- common/database/src/idm_common.c | 2 +- common/database/src/idm_database.c | 2 +- .../kitsimpl/include/coauth_callback_proxy.h | 3 +-- .../kitsimpl/include/coauth_callback_stub.h | 1 + frameworks/kitsimpl/include/coauth_proxy.h | 9 +++++---- .../kitsimpl/include/executor_callback_proxy.h | 7 ++++--- .../kitsimpl/include/executor_callback_stub.h | 6 ++++-- .../kitsimpl/include/executor_messenger_proxy.h | 6 +++--- .../kitsimpl/include/executor_messenger_stub.h | 1 + frameworks/kitsimpl/include/i_coauth.h | 6 +++--- frameworks/kitsimpl/include/iexecutor_callback.h | 4 ++-- .../kitsimpl/include/iexecutor_messenger.h | 4 ++-- .../kitsimpl/include/query_callback_proxy.h | 2 -- .../kitsimpl/include/set_prop_callback_proxy.h | 2 -- .../kitsimpl/include/set_prop_callback_stub.h | 1 + .../kitsimpl/src/executor_callback_proxy.cpp | 4 ++++ interfaces/innerkits/include/auth_attributes.h | 9 ++++----- .../innerkits/include/auth_executor_registry.h | 9 +++++---- interfaces/innerkits/include/auth_message.h | 3 ++- interfaces/innerkits/include/co_auth.h | 3 ++- interfaces/innerkits/include/executor_callback.h | 4 ++-- .../innerkits/include/executor_messenger.h | 7 ++++--- interfaces/innerkits/src/auth_attributes.cpp | 1 + services/include/auth_res_manager.h | 1 + services/include/auth_res_pool.h | 2 +- services/include/call_monitor.h | 2 +- services/include/coauth_manager.h | 6 ++++-- services/include/coauth_service.h | 3 ++- services/src/auth_res_manager.cpp | 9 +++++++-- services/src/auth_res_pool.cpp | 2 +- services/src/coauth_manager.cpp | 16 +++++++++++----- 31 files changed, 81 insertions(+), 56 deletions(-) diff --git a/common/database/src/idm_common.c b/common/database/src/idm_common.c index 46690f1..22e5004 100644 --- a/common/database/src/idm_common.c +++ b/common/database/src/idm_common.c @@ -55,6 +55,7 @@ UserInfo *InitUserInfoNode(void) LOG_ERROR("userInfo malloc failed"); return NULL; } + (void)memset_s(userInfo, sizeof(UserInfo), 0, sizeof(UserInfo)); userInfo->credentialInfoList = CreateLinkedList(DestroyCredentialNode); if (userInfo->credentialInfoList == NULL) { @@ -62,7 +63,6 @@ UserInfo *InitUserInfoNode(void) Free(userInfo); return NULL; } - userInfo->enrolledInfoList = CreateLinkedList(DestroyEnrolledNode); if (userInfo->enrolledInfoList == NULL) { LOG_ERROR("create enrolledInfoList failed"); diff --git a/common/database/src/idm_database.c b/common/database/src/idm_database.c index 5dd296d..59b6cda 100644 --- a/common/database/src/idm_database.c +++ b/common/database/src/idm_database.c @@ -520,7 +520,7 @@ ResultCode AddCredentialInfo(int32_t userId, CredentialInfoHal *credentialInfo) } UserInfo *user = QueryUserInfo(userId); if (user == NULL && credentialInfo->authType == PIN_AUTH) { - ResultCode ret = AddUser(userId, credentialInfo); + ResultCode ret = AddUser(userId, credentialInfo); if (ret != RESULT_SUCCESS) { LOG_ERROR("add user failed"); } diff --git a/frameworks/kitsimpl/include/coauth_callback_proxy.h b/frameworks/kitsimpl/include/coauth_callback_proxy.h index a01ffbb..6e13cad 100644 --- a/frameworks/kitsimpl/include/coauth_callback_proxy.h +++ b/frameworks/kitsimpl/include/coauth_callback_proxy.h @@ -31,10 +31,9 @@ public: void OnFinish(uint32_t resultCode, std::vector &scheduleToken) override; void OnAcquireInfo(uint32_t acquire) override; -private: - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); private: + bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; }; } // namespace CoAuth diff --git a/frameworks/kitsimpl/include/coauth_callback_stub.h b/frameworks/kitsimpl/include/coauth_callback_stub.h index ea3dbe5..6606425 100644 --- a/frameworks/kitsimpl/include/coauth_callback_stub.h +++ b/frameworks/kitsimpl/include/coauth_callback_stub.h @@ -33,6 +33,7 @@ public: int32_t OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + private: int32_t OnFinishStub(MessageParcel &data, MessageParcel &reply); int32_t OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/include/coauth_proxy.h b/frameworks/kitsimpl/include/coauth_proxy.h index fad1ac7..769638a 100644 --- a/frameworks/kitsimpl/include/coauth_proxy.h +++ b/frameworks/kitsimpl/include/coauth_proxy.h @@ -31,15 +31,16 @@ public: ~CoAuthProxy() override = default; uint64_t Register(std::shared_ptr executorInfo, - const sptr &callback) override; + const sptr &callback) override; void QueryStatus(AuthResPool::AuthExecutor &executorInfo, - const sptr &callback) override; + const sptr &callback) override; void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) override; int32_t Cancel(uint64_t scheduleId) override; + int32_t GetExecutorProp(AuthResPool::AuthAttributes &conditions, - std::shared_ptr values) override; + std::shared_ptr values) override; void SetExecutorProp(AuthResPool::AuthAttributes &conditions, - const sptr &callback) override; + const sptr &callback) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, bool isSync = true); diff --git a/frameworks/kitsimpl/include/executor_callback_proxy.h b/frameworks/kitsimpl/include/executor_callback_proxy.h index 94486b9..b18490c 100644 --- a/frameworks/kitsimpl/include/executor_callback_proxy.h +++ b/frameworks/kitsimpl/include/executor_callback_proxy.h @@ -27,15 +27,16 @@ class ExecutorCallbackProxy : public IRemoteProxy { public: explicit ExecutorCallbackProxy(const sptr& impl) : IRemoteProxy(impl) {} - ~ExecutorCallbackProxy() override = default; + void OnMessengerReady(const sptr &messenger) override; int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, - std::shared_ptr commandAttrs) override; + std::shared_ptr commandAttrs) override; int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) override; int32_t OnSetProperty(std::shared_ptr properties) override; int32_t OnGetProperty(std::shared_ptr conditions, - std::shared_ptr values) override; + std::shared_ptr values) override; + private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; diff --git a/frameworks/kitsimpl/include/executor_callback_stub.h b/frameworks/kitsimpl/include/executor_callback_stub.h index 7e7dd21..7158d9d 100644 --- a/frameworks/kitsimpl/include/executor_callback_stub.h +++ b/frameworks/kitsimpl/include/executor_callback_stub.h @@ -27,14 +27,16 @@ class ExecutorCallbackStub : public IRemoteStub { public: ExecutorCallbackStub(const std::shared_ptr& impl); ~ExecutorCallbackStub() override = default; + void OnMessengerReady(const sptr &messenger) override; int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, - std::shared_ptr commandAttrs) override; + std::shared_ptr commandAttrs) override; int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) override; int32_t OnSetProperty(std::shared_ptr properties) override; int32_t OnGetProperty(std::shared_ptr conditions, - std::shared_ptr values) override; + std::shared_ptr values) override; int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + private: int32_t OnMessengerReadyStub(MessageParcel& data, MessageParcel& reply); int32_t OnBeginExecuteStub(MessageParcel& data, MessageParcel& reply); diff --git a/frameworks/kitsimpl/include/executor_messenger_proxy.h b/frameworks/kitsimpl/include/executor_messenger_proxy.h index 7de24d1..6a1c039 100644 --- a/frameworks/kitsimpl/include/executor_messenger_proxy.h +++ b/frameworks/kitsimpl/include/executor_messenger_proxy.h @@ -27,12 +27,12 @@ class ExecutorMessengerProxy : public IRemoteProxy { public: explicit ExecutorMessengerProxy(const sptr& impl) : IRemoteProxy(impl) {} - ~ExecutorMessengerProxy() override = default; + int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, - int32_t dstType, std::shared_ptr msg) override; + int32_t dstType, std::shared_ptr msg) override; int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, - std::shared_ptr finalResult) override; + std::shared_ptr finalResult) override; private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/include/executor_messenger_stub.h b/frameworks/kitsimpl/include/executor_messenger_stub.h index 5a30f05..8c0889b 100644 --- a/frameworks/kitsimpl/include/executor_messenger_stub.h +++ b/frameworks/kitsimpl/include/executor_messenger_stub.h @@ -29,6 +29,7 @@ public: ~ExecutorMessengerStub() override = default; int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + private: int32_t SendDataStub(MessageParcel& data, MessageParcel& reply); int32_t FinishStub(MessageParcel& data, MessageParcel& reply); diff --git a/frameworks/kitsimpl/include/i_coauth.h b/frameworks/kitsimpl/include/i_coauth.h index 2c461b2..594eb26 100644 --- a/frameworks/kitsimpl/include/i_coauth.h +++ b/frameworks/kitsimpl/include/i_coauth.h @@ -44,13 +44,13 @@ public: /* Business function */ virtual uint64_t Register(std::shared_ptr executorInfo, - const sptr &callback) = 0; + const sptr &callback) = 0; virtual void QueryStatus(AuthResPool::AuthExecutor &executorInfo, - const sptr &callback) = 0; + const sptr &callback) = 0; virtual void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) = 0; virtual int32_t Cancel(uint64_t scheduleId) = 0; virtual int32_t GetExecutorProp(AuthResPool::AuthAttributes &conditions, - std::shared_ptr values) = 0; + std::shared_ptr values) = 0; virtual void SetExecutorProp(AuthResPool::AuthAttributes &conditions, const sptr &callback) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.CoAuth.ICoAuth"); diff --git a/frameworks/kitsimpl/include/iexecutor_callback.h b/frameworks/kitsimpl/include/iexecutor_callback.h index 475eb64..317575c 100644 --- a/frameworks/kitsimpl/include/iexecutor_callback.h +++ b/frameworks/kitsimpl/include/iexecutor_callback.h @@ -27,11 +27,11 @@ class IExecutorCallback : public IRemoteBroker { public: virtual void OnMessengerReady(const sptr &messenger) = 0; virtual int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, - std::shared_ptr commandAttrs) = 0; + std::shared_ptr commandAttrs) = 0; virtual int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) = 0; virtual int32_t OnSetProperty(std::shared_ptr properties) = 0; virtual int32_t OnGetProperty(std::shared_ptr conditions, - std::shared_ptr values) = 0; + std::shared_ptr values) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.AuthResPool.ExecutorCallback"); diff --git a/frameworks/kitsimpl/include/iexecutor_messenger.h b/frameworks/kitsimpl/include/iexecutor_messenger.h index 769446d..b798b74 100644 --- a/frameworks/kitsimpl/include/iexecutor_messenger.h +++ b/frameworks/kitsimpl/include/iexecutor_messenger.h @@ -34,9 +34,9 @@ public: }; /* Business function */ virtual int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, - int32_t dstType, std::shared_ptr msg) = 0; + int32_t dstType, std::shared_ptr msg) = 0; virtual int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, - std::shared_ptr finalResult) = 0; + std::shared_ptr finalResult) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.AuthResPool.IExecutor_Messenger"); }; diff --git a/frameworks/kitsimpl/include/query_callback_proxy.h b/frameworks/kitsimpl/include/query_callback_proxy.h index bd89de7..637c543 100644 --- a/frameworks/kitsimpl/include/query_callback_proxy.h +++ b/frameworks/kitsimpl/include/query_callback_proxy.h @@ -32,8 +32,6 @@ public: private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - -private: static inline BrokerDelegator delegator_; }; } // namespace AuthResPool diff --git a/frameworks/kitsimpl/include/set_prop_callback_proxy.h b/frameworks/kitsimpl/include/set_prop_callback_proxy.h index b772b61..eeb2e49 100644 --- a/frameworks/kitsimpl/include/set_prop_callback_proxy.h +++ b/frameworks/kitsimpl/include/set_prop_callback_proxy.h @@ -31,8 +31,6 @@ public: private: bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - -private: static inline BrokerDelegator delegator_; }; } // namespace CoAuth diff --git a/frameworks/kitsimpl/include/set_prop_callback_stub.h b/frameworks/kitsimpl/include/set_prop_callback_stub.h index 5ac3e84..c3647ac 100644 --- a/frameworks/kitsimpl/include/set_prop_callback_stub.h +++ b/frameworks/kitsimpl/include/set_prop_callback_stub.h @@ -33,6 +33,7 @@ public: int32_t OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + private: int32_t OnResultStub(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/src/executor_callback_proxy.cpp b/frameworks/kitsimpl/src/executor_callback_proxy.cpp index 670a5ba..513ac3e 100644 --- a/frameworks/kitsimpl/src/executor_callback_proxy.cpp +++ b/frameworks/kitsimpl/src/executor_callback_proxy.cpp @@ -30,6 +30,10 @@ void ExecutorCallbackProxy::OnMessengerReady(const sptr &mes return; } + if (messenger.GetRefPtr() == nullptr) { + COAUTH_HILOGE(MODULE_INNERKIT, "messenger.GetRefPtr() is nullptr"); + return; + } if (!data.WriteRemoteObject(messenger.GetRefPtr()->AsObject())) { COAUTH_HILOGE(MODULE_INNERKIT, "write RemoteObject failed"); return; diff --git a/interfaces/innerkits/include/auth_attributes.h b/interfaces/innerkits/include/auth_attributes.h index 1ecfbb3..cf28426 100644 --- a/interfaces/innerkits/include/auth_attributes.h +++ b/interfaces/innerkits/include/auth_attributes.h @@ -75,15 +75,14 @@ private: std::vector GetUint64ArrayFromUint8(std::vector &data, uint32_t begin, uint32_t len); std::vector GetUint32ArrayFromUint8(std::vector &data, uint32_t begin, uint32_t len); void PackToBuffer(std::map::iterator iter, - uint32_t dataLength, uint8_t *writePointer, - std::vector &buffer); + uint32_t dataLength, uint8_t *writePointer, std::vector &buffer); void WriteDataLength(std::vector &buffer, uint8_t *writePointer, uint32_t dataLength); void UnpackTag(AuthAttributeType &tag, std::vector &buffer, - uint32_t &authDataLength, uint32_t &dataLength); + uint32_t &authDataLength, uint32_t &dataLength); void Write32Array(std::vector &uint32ArraylValue, uint8_t *writePointer, - std::vector &buffer); + std::vector &buffer); void Write64Array(std::vector &uint64ArraylValue, uint8_t *writePointer, - std::vector &buffer); + std::vector &buffer); bool CheckLengthPass(ValueType type, uint32_t currIndex, uint32_t dataLength, uint32_t bufferLength); void UnpackUint32ArrayType(std::vector &buffer, AuthAttributeType tag, uint32_t &authDataLength, uint32_t &dataLength); diff --git a/interfaces/innerkits/include/auth_executor_registry.h b/interfaces/innerkits/include/auth_executor_registry.h index d786b7b..2db3a32 100644 --- a/interfaces/innerkits/include/auth_executor_registry.h +++ b/interfaces/innerkits/include/auth_executor_registry.h @@ -27,10 +27,10 @@ class AuthExecutorRegistry : public DelayedRefSingleton { DECLARE_DELAYED_REF_SINGLETON(AuthExecutorRegistry); public: -DISALLOW_COPY_AND_MOVE(AuthExecutorRegistry); -/* InnerKit */ -uint64_t Register(std::shared_ptr executorInfo, std::shared_ptr callback); -void QueryStatus(AuthExecutor &executorInfo, std::shared_ptr callback); + DISALLOW_COPY_AND_MOVE(AuthExecutorRegistry); + /* InnerKit */ + uint64_t Register(std::shared_ptr executorInfo, std::shared_ptr callback); + void QueryStatus(AuthExecutor &executorInfo, std::shared_ptr callback); private: class AuthExecutorRegistryDeathRecipient : public IRemoteObject::DeathRecipient { @@ -42,6 +42,7 @@ private: private: DISALLOW_COPY_AND_MOVE(AuthExecutorRegistryDeathRecipient); }; + void ResetProxy(const wptr& remote); sptr GetProxy(); std::mutex mutex_; diff --git a/interfaces/innerkits/include/auth_message.h b/interfaces/innerkits/include/auth_message.h index 9836031..9857fea 100644 --- a/interfaces/innerkits/include/auth_message.h +++ b/interfaces/innerkits/include/auth_message.h @@ -27,10 +27,11 @@ namespace UserIAM { namespace AuthResPool { class AuthMessage { public: - AuthMessage(std::vector &msg); + explicit AuthMessage(std::vector &msg); ~AuthMessage(); AuthMessage* FromUint8Array(std::vector &msg); DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.AuthResPool.AuthMessage"); + private: std::vector authMessage_; }; diff --git a/interfaces/innerkits/include/co_auth.h b/interfaces/innerkits/include/co_auth.h index e4f8d4b..4a1b1fd 100644 --- a/interfaces/innerkits/include/co_auth.h +++ b/interfaces/innerkits/include/co_auth.h @@ -35,7 +35,7 @@ public: void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, std::shared_ptr callback); int32_t Cancel(uint64_t scheduleId); int32_t GetExecutorProp(AuthResPool::AuthAttributes &conditions, - std::shared_ptr values); + std::shared_ptr values); void SetExecutorProp(AuthResPool::AuthAttributes &conditions, std::shared_ptr callback); private: @@ -48,6 +48,7 @@ private: private: DISALLOW_COPY_AND_MOVE(CoAuthDeathRecipient); }; + void ResetProxy(const wptr& remote); sptr GetProxy(); std::mutex mutex_; diff --git a/interfaces/innerkits/include/executor_callback.h b/interfaces/innerkits/include/executor_callback.h index dd444ce..e0c1238 100644 --- a/interfaces/innerkits/include/executor_callback.h +++ b/interfaces/innerkits/include/executor_callback.h @@ -25,11 +25,11 @@ class ExecutorCallback { public: virtual void OnMessengerReady(const sptr &messenger) = 0; virtual int32_t OnBeginExecute(uint64_t scheduleId, std::vector &publicKey, - std::shared_ptr commandAttrs) = 0; + std::shared_ptr commandAttrs) = 0; virtual int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr consumerAttr) = 0; virtual int32_t OnSetProperty(std::shared_ptr properties) = 0; virtual int32_t OnGetProperty(std::shared_ptr conditions, - std::shared_ptr values) = 0; + std::shared_ptr values) = 0; }; } // namespace AuthResPool } // namespace UserIAM diff --git a/interfaces/innerkits/include/executor_messenger.h b/interfaces/innerkits/include/executor_messenger.h index c063787..42593dc 100644 --- a/interfaces/innerkits/include/executor_messenger.h +++ b/interfaces/innerkits/include/executor_messenger.h @@ -25,12 +25,13 @@ namespace UserIAM { namespace AuthResPool { class ExecutorMessenger : public ExecutorMessengerStub { public: - ExecutorMessenger(UserIAM::CoAuth::AuthResPool*); + explicit ExecutorMessenger(UserIAM::CoAuth::AuthResPool*); ~ExecutorMessenger() override = default; int32_t SendData(uint64_t scheduleId, uint64_t transNum, int32_t srcType, - int32_t dstType, std::shared_ptr msg) override; + int32_t dstType, std::shared_ptr msg) override; int32_t Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode, - std::shared_ptr finalResult) override; + std::shared_ptr finalResult) override; + private: void DeleteScheduleInfoById(uint64_t scheduleId); int32_t DoSignToken(uint64_t scheduleId, std::vector& scheduleToken, diff --git a/interfaces/innerkits/src/auth_attributes.cpp b/interfaces/innerkits/src/auth_attributes.cpp index d16a702..00876b8 100644 --- a/interfaces/innerkits/src/auth_attributes.cpp +++ b/interfaces/innerkits/src/auth_attributes.cpp @@ -402,6 +402,7 @@ void AuthAttributes::Write32Array(std::vector &uint32ArraylValue, uint buffer.insert(buffer.end(), writePointer, writePointer + sizeof(uint32_t)); } } + void AuthAttributes::Write64Array(std::vector &uint64ArraylValue, uint8_t *writePointer, std::vector &buffer) { diff --git a/services/include/auth_res_manager.h b/services/include/auth_res_manager.h index 7943fd2..349d56a 100644 --- a/services/include/auth_res_manager.h +++ b/services/include/auth_res_manager.h @@ -36,6 +36,7 @@ public: int32_t SaveScheduleCallback(uint64_t scheduleId, uint64_t executorNum, sptr callback); int32_t FindScheduleCallback(uint64_t scheduleId, sptr &callback); int32_t DeleteScheduleCallback(uint64_t scheduleId); + private: class ResIExecutorCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: diff --git a/services/include/auth_res_pool.h b/services/include/auth_res_pool.h index 72cf2c1..277204e 100644 --- a/services/include/auth_res_pool.h +++ b/services/include/auth_res_pool.h @@ -45,7 +45,7 @@ public: sptr callback; } ScheduleRegister; int32_t Insert(uint64_t executorID, std::shared_ptr executorInfo, - sptr callback); + sptr callback); int32_t Insert(uint64_t scheduleId, uint64_t executorNum, sptr callback); int32_t FindExecutorCallback(uint64_t executorID, sptr &callback); int32_t FindExecutorCallback(uint32_t authType, sptr &callback); diff --git a/services/include/call_monitor.h b/services/include/call_monitor.h index 0414684..329a82f 100644 --- a/services/include/call_monitor.h +++ b/services/include/call_monitor.h @@ -32,8 +32,8 @@ public: DISALLOW_COPY_AND_MOVE(CallMonitor); void MonitorCall(int64_t waitTime, uint64_t scheduleId, Callback &timeoutFun); - void MonitorRemoveCall(uint64_t scheduleId); + private: std::shared_ptr eventHandler_; }; diff --git a/services/include/coauth_manager.h b/services/include/coauth_manager.h index da549a2..73976ad 100644 --- a/services/include/coauth_manager.h +++ b/services/include/coauth_manager.h @@ -37,11 +37,12 @@ public: void CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptr callback); void TimeOut(uint64_t scheduleId); + private: void SetAuthAttributes(std::shared_ptr commandAttrs, - ScheduleInfo &scheduleInfo, AuthInfo &authInfo); + ScheduleInfo &scheduleInfo, AuthInfo &authInfo); void BeginExecute(ScheduleInfo &scheduleInfo, std::size_t executorNum, uint64_t scheduleId, - AuthInfo &authInfo, int32_t &executeRet); + AuthInfo &authInfo, int32_t &executeRet); class ResICoAuthCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: ResICoAuthCallbackDeathRecipient(uint64_t scheduleId, CoAuthManager* parent); @@ -53,6 +54,7 @@ private: CoAuthManager* parent_; DISALLOW_COPY_AND_MOVE(ResICoAuthCallbackDeathRecipient); }; + AuthResManager* coAuthResMgrPtr_; std::shared_ptr monitor_ = nullptr; }; diff --git a/services/include/coauth_service.h b/services/include/coauth_service.h index 8b1ab35..1becf24 100644 --- a/services/include/coauth_service.h +++ b/services/include/coauth_service.h @@ -40,10 +40,11 @@ public: DECLEAR_SYSTEM_ABILITY(CoAuthService); explicit CoAuthService(int32_t systemAbilityId, bool runOnCreate = false); ~CoAuthService() override; + void OnStart() override; void OnStop() override; uint64_t Register(std::shared_ptr executorInfo, - const sptr &callback) override; + const sptr &callback) override; void QueryStatus(ResAuthExecutor &executorInfo, const sptr &callback) override; void BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const sptr &callback) override; int32_t Cancel(uint64_t scheduleId) override; diff --git a/services/src/auth_res_manager.cpp b/services/src/auth_res_manager.cpp index 4971541..62ca8ec 100644 --- a/services/src/auth_res_manager.cpp +++ b/services/src/auth_res_manager.cpp @@ -54,7 +54,12 @@ uint64_t AuthResManager::Register(std::shared_ptr executorInfo, COAUTH_HILOGE(MODULE_SERVICE, "register is failure!"); return INVALID_EXECUTOR_ID; } - sptr dr = new ResIExecutorCallbackDeathRecipient(executorId, this); + sptr dr = + new (std::nothrow) ResIExecutorCallbackDeathRecipient(executorId, this); + if (dr == nullptr || callback->AsObject() == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "dr or callback->AsObject() is nullptr"); + return INVALID_EXECUTOR_ID; + } if (!callback->AsObject()->AddDeathRecipient(dr)) { COAUTH_HILOGE(MODULE_SERVICE, "add death recipient ResIExecutorCallbackDeathRecipient failed"); return INVALID_EXECUTOR_ID; @@ -65,7 +70,7 @@ uint64_t AuthResManager::Register(std::shared_ptr executorInfo, sptr messenger = new UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_); callback->OnMessengerReady(messenger); - COAUTH_HILOGD(MODULE_SERVICE, "register is successfull, exeID is XXXX%{public}04" PRIx64, executorId); + COAUTH_HILOGD(MODULE_SERVICE, "register is successful, exeID is XXXX%{public}04" PRIx64, executorId); return executorId; } diff --git a/services/src/auth_res_pool.cpp b/services/src/auth_res_pool.cpp index b4843c0..152277f 100644 --- a/services/src/auth_res_pool.cpp +++ b/services/src/auth_res_pool.cpp @@ -107,7 +107,7 @@ int32_t AuthResPool::FindScheduleCallback(uint64_t scheduleId, sptrsecond->callback; - COAUTH_HILOGI(MODULE_SERVICE, "find shedule callback success"); + COAUTH_HILOGI(MODULE_SERVICE, "find schedule callback success"); return SUCCESS; } diff --git a/services/src/coauth_manager.cpp b/services/src/coauth_manager.cpp index 55b207e..6ad8187 100644 --- a/services/src/coauth_manager.cpp +++ b/services/src/coauth_manager.cpp @@ -45,10 +45,16 @@ void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptrOnFinish(FAIL, scheduleToken); } - sptr dr = new ResICoAuthCallbackDeathRecipient(scheduleId, this); - if ((!callback->AsObject()->AddDeathRecipient(dr))) { - COAUTH_HILOGE(MODULE_SERVICE, "add death recipient ResICoAuthCallbackDeathRecipient failed"); + sptr dr = + new (std::nothrow) ResICoAuthCallbackDeathRecipient(scheduleId, this); + if (dr == nullptr || callback->AsObject() == nullptr) { + COAUTH_HILOGE(MODULE_SERVICE, "dr or callback->AsObject is nullptr"); + } else { + if (!callback->AsObject()->AddDeathRecipient(dr)) { + COAUTH_HILOGE(MODULE_SERVICE, "add death recipient ResICoAuthCallbackDeathRecipient failed"); + } } + if (coAuthResMgrPtr_ == nullptr) { COAUTH_HILOGE(MODULE_SERVICE, "coAuthResMgrPtr_ is nullptr"); return callback->OnFinish(FAIL, scheduleToken); @@ -123,10 +129,10 @@ int32_t CoAuthManager::Cancel(uint64_t scheduleId) sptr callback = nullptr; int32_t getRet = GetScheduleInfo(scheduleId, scheduleInfo); // call TA if (getRet != SUCCESS) { - COAUTH_HILOGE(MODULE_SERVICE, "get shedule info filed"); + COAUTH_HILOGE(MODULE_SERVICE, "get schedule info filed"); return FAIL; } - COAUTH_HILOGI(MODULE_SERVICE, "cancel is successfull"); + COAUTH_HILOGI(MODULE_SERVICE, "cancel is successful"); std::size_t executorNum = scheduleInfo.executors.size(); if (executorNum == 0) { COAUTH_HILOGE(MODULE_SERVICE, "executorId does not exist"); -- Gitee From 6fb0ad64ac82c4f7959712a6214aeb1e5a3ab104 Mon Sep 17 00:00:00 2001 From: lwk <1076278852@qq.com> Date: Fri, 25 Mar 2022 11:48:34 +0800 Subject: [PATCH 3/3] fix: code review liuwenkai@huawei.com Signed-off-by: lwk <1076278852@qq.com> --- common/database/src/idm_common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/database/src/idm_common.c b/common/database/src/idm_common.c index 22e5004..bf0356a 100644 --- a/common/database/src/idm_common.c +++ b/common/database/src/idm_common.c @@ -15,6 +15,8 @@ #include "idm_common.h" +#include "securec.h" + #include "adaptor_log.h" #include "adaptor_memory.h" -- Gitee