diff --git a/common/adaptor/src/adaptor_algorithm.c b/common/adaptor/src/adaptor_algorithm.c index f5c584c395fbeea1dba8e147444d7313df89f7f9..56cf25203d4f60684cb902b99ca924b5ad8806ce 100644 --- a/common/adaptor/src/adaptor_algorithm.c +++ b/common/adaptor/src/adaptor_algorithm.c @@ -38,13 +38,13 @@ static KeyPair *CreateEd25519KeyPair() LOG_ERROR("no memory for key pair"); return NULL; } - keyPair->pubKey = CreateBuffer(ED25519_FIX_PUBKEY_BUFFER_SIZE); + keyPair->pubKey = CreateBufferBySize(ED25519_FIX_PUBKEY_BUFFER_SIZE); if (keyPair->pubKey == NULL) { LOG_ERROR("no memory for public key"); Free(keyPair); return NULL; } - keyPair->priKey = CreateBuffer(ED25519_FIX_PRIKEY_BUFFER_SIZE); + keyPair->priKey = CreateBufferBySize(ED25519_FIX_PRIKEY_BUFFER_SIZE); if (keyPair->priKey == NULL) { LOG_ERROR("no memory for private key"); DestoryBuffer(keyPair->pubKey); @@ -156,7 +156,7 @@ int32_t Ed25519Sign(const KeyPair *keyPair, const Buffer *data, Buffer **sign) LOG_ERROR("init sign failed"); goto EXIT; } - *sign = CreateBuffer(ED25519_FIX_SIGN_BUFFER_SIZE); + *sign = CreateBufferBySize(ED25519_FIX_SIGN_BUFFER_SIZE); if (!IsBufferValid(*sign)) { LOG_ERROR("create buffer failed"); goto EXIT; @@ -241,7 +241,7 @@ int32_t HmacSha256(const Buffer *hmacKey, const Buffer *data, Buffer **hmac) LOG_ERROR("no algo"); return RESULT_GENERAL_ERROR; } - *hmac = CreateBuffer(SHA256_DIGEST_SIZE); + *hmac = CreateBufferBySize(SHA256_DIGEST_SIZE); if (*hmac == NULL) { LOG_ERROR("create buffer failed"); return RESULT_NO_MEMORY; diff --git a/common/adaptor/src/file_operator.c b/common/adaptor/src/file_operator.c index dc13184359266806d8c5740b9cea7ee78ca79073..1a6396827837d23c22cb4c17f32716ad98efbb18 100644 --- a/common/adaptor/src/file_operator.c +++ b/common/adaptor/src/file_operator.c @@ -35,7 +35,7 @@ static bool IsFileExist(const char *fileName) static int32_t ReadFile(const char *fileName, uint8_t *buf, uint32_t len) { - if ((fileName == NULL) || (buf == NULL) || (len == 0) || (len > SIZE_MAX)) { + if ((fileName == NULL) || (buf == NULL) || (len == 0)) { LOG_ERROR("get bad params"); return RESULT_BAD_PARAM; } @@ -57,7 +57,7 @@ static int32_t ReadFile(const char *fileName, uint8_t *buf, uint32_t len) static int32_t WriteFile(const char *fileName, const uint8_t *buf, uint32_t len) { - if ((fileName == NULL) || (buf == NULL) || (len == 0) || (len > SIZE_MAX)) { + if ((fileName == NULL) || (buf == NULL) || (len == 0)) { LOG_ERROR("get bad params"); return RESULT_BAD_PARAM; } diff --git a/common/common/inc/buffer.h b/common/common/inc/buffer.h index c6ed33c55f137f6e1f13c29b0369f481da703f10..486770ef92f7ca89537e1933d2535498d7aa7191 100644 --- a/common/common/inc/buffer.h +++ b/common/common/inc/buffer.h @@ -27,7 +27,7 @@ typedef struct { } Buffer; bool IsBufferValid(const Buffer *buffer); -Buffer *CreateBuffer(const uint32_t size); +Buffer *CreateBufferBySize(const uint32_t size); void DestoryBuffer(Buffer *buffer); Buffer *CopyBuffer(const Buffer *buffer); bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2); diff --git a/common/common/src/buffer.c b/common/common/src/buffer.c index 4ef1803c8487f5f7cf564760c27ad1f60f1e688d..33d187bc21143eec77aceb418a2452482ffd6397 100644 --- a/common/common/src/buffer.c +++ b/common/common/src/buffer.c @@ -42,7 +42,7 @@ bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size) return true; } -Buffer *CreateBuffer(const uint32_t size) +Buffer *CreateBufferBySize(const uint32_t size) { if ((size == 0) || (size > MAX_BUFFER_SIZE)) { LOG_ERROR("invalid param, size: %u", size); @@ -109,7 +109,7 @@ void DestoryBuffer(Buffer *buffer) if (buffer != NULL) { if (buffer->buf != NULL) { if (memset_s(buffer->buf, buffer->maxSize, 0, buffer->maxSize) != EOK) { - LOG_ERROR("meset failed"); + LOG_ERROR("memset_s failed"); } Free(buffer->buf); buffer->buf = NULL; @@ -127,7 +127,7 @@ Buffer *CopyBuffer(const Buffer *buffer) return NULL; } - Buffer *copyBuffer = CreateBuffer(buffer->maxSize); + Buffer *copyBuffer = CreateBufferBySize(buffer->maxSize); if (copyBuffer == NULL) { LOG_ERROR("create buffer failed"); return NULL; diff --git a/common/common/src/tlv_wrapper.c b/common/common/src/tlv_wrapper.c index f032180caa1a88a0bb81d0ed988a1f284010c09a..ef0082db840241fe133e6b47b8b7a9fbf6d1647d 100644 --- a/common/common/src/tlv_wrapper.c +++ b/common/common/src/tlv_wrapper.c @@ -92,7 +92,7 @@ int32_t ParseTlvWrapper(const uint8_t *buffer, uint32_t bufferSize, TlvListNode LOG_ERROR("bufferSize = %{public}u, offset = %{public}u", bufferSize, offset); return OPERA_FAIL; } - int32_t type = Ntohl(*(int32_t *)(buffer + offset)); + int32_t type = (int32_t)Ntohl(*(int32_t *)(buffer + offset)); offset += sizeof(int32_t); uint32_t length = Ntohl(*(int32_t *)(buffer + offset)); offset += sizeof(int32_t); diff --git a/common/database/src/idm_common.c b/common/database/src/idm_common.c index 46690f1bbc2c24562dedff3866ed14a61d97aa33..bf0356a3bd54fbc2c21cb1ebc1dc1f4713a0f4eb 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" @@ -55,6 +57,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 +65,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 5dd296dab6f5f3083d857887da8a961aee65a1da..37dc6882d13b318dbb129b3aa76a3531a380604c 100644 --- a/common/database/src/idm_database.c +++ b/common/database/src/idm_database.c @@ -161,7 +161,7 @@ ResultCode DeleteUserInfo(int32_t userId, CredentialInfoHal **credentialInfos, u } UserInfo *user = QueryUserInfo(userId); if (!IsUserInfoValid(user)) { - LOG_ERROR("can't find this user1"); + LOG_ERROR("can't find this user"); return RESULT_NOT_FOUND; } ResultCode ret = GetAllCredentialInfoFromUser(user, credentialInfos, num); @@ -450,7 +450,7 @@ static ResultCode AddCredentialToUser(UserInfo *user, CredentialInfoHal *credent ret = GenerateDeduplicateUint64(credentialList, &credentialInfo->credentialId, IsCredentialIdDuplicate); if (ret != RESULT_SUCCESS) { - LOG_ERROR("GenerateValidCredentialId failed"); + LOG_ERROR("GenerateDeduplicateUint64 failed"); return ret; } CredentialInfoHal *credential = Malloc(sizeof(CredentialInfoHal)); @@ -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"); } @@ -709,7 +709,7 @@ ResultCode QueryCredentialFromExecutor(uint32_t authType, CredentialInfoHal **cr if (credentialQuery != NULL) { (*num)++; if (*num <= preApplyNum) { - *credentialInfos[*num - 1] = *credentialQuery; + (*credentialInfos)[*num - 1] = *credentialQuery; temp = temp->next; continue; } @@ -731,7 +731,7 @@ ResultCode QueryCredentialFromExecutor(uint32_t authType, CredentialInfoHal **cr } Free(*credentialInfos); *credentialInfos = credentialsTemp; - *credentialInfos[*num - 1] = *credentialQuery; + (*credentialInfos)[*num - 1] = *credentialQuery; } temp = temp->next; } diff --git a/common/database/src/idm_file_manager.c b/common/database/src/idm_file_manager.c index a65278a958cf102e60e383e82681c7d697c1c878..a51c019bf81970a44ee06143b4aaec3dbc681a36 100644 --- a/common/database/src/idm_file_manager.c +++ b/common/database/src/idm_file_manager.c @@ -181,7 +181,7 @@ ResultCode UpdateFileInfo(LinkedList *userInfoList) LOG_ERROR("userInfo list is null"); return RESULT_BAD_PARAM; } - Buffer *parcel = CreateBuffer(PRE_APPLY_LEN); + Buffer *parcel = CreateBufferBySize(PRE_APPLY_LEN); if (parcel == NULL) { LOG_ERROR("parcel is null"); return RESULT_BAD_PARAM; @@ -212,6 +212,7 @@ ResultCode UpdateFileInfo(LinkedList *userInfoList) ret = RESULT_GENERAL_ERROR; goto EXIT; } + temp = temp->next; } FileOperator *fileOperator = GetFileOperator(DEFAULT_FILE_OPERATOR); @@ -350,7 +351,7 @@ static Buffer *ReadFileInfo() LOG_ERROR("open file failed"); return NULL; } - Buffer *parcel = CreateBuffer(fileSize); + Buffer *parcel = CreateBufferBySize(fileSize); if (parcel == NULL) { LOG_ERROR("parcel create failed"); return NULL; diff --git a/common/hal_sdk/useriam_common.cpp b/common/hal_sdk/useriam_common.cpp index b05dbf1e92156aaf2d2bdc22bca2cadce4585451..bc824c08139b9b734797467bc6dc7dea406460a0 100644 --- a/common/hal_sdk/useriam_common.cpp +++ b/common/hal_sdk/useriam_common.cpp @@ -31,16 +31,11 @@ extern "C" { namespace OHOS { namespace UserIAM { namespace Common { -static const char *IDM_USER_FOLDER = "/data/useriam"; static bool g_isInitUserIAM = false; int32_t Init() { GlobalLock(); - LOG_INFO("check useriam folder exist or init it"); - if (IDM_USER_FOLDER && access(IDM_USER_FOLDER, 0) == -1) { - mkdir(IDM_USER_FOLDER, S_IRWXU); - } if (InitUserAuthContextList() != RESULT_SUCCESS) { LOG_ERROR("init user auth failed"); goto FAIL; diff --git a/common/hal_sdk/useridm_interface.cpp b/common/hal_sdk/useridm_interface.cpp index 26ccf1e33cb43e681b1e9bfc533a9e7de6516252..6ce22e0168fd6f8ee133dfe83df0363271b75fd2 100644 --- a/common/hal_sdk/useridm_interface.cpp +++ b/common/hal_sdk/useridm_interface.cpp @@ -37,7 +37,7 @@ int32_t OpenSession(int32_t userId, uint64_t &challenge) { GlobalLock(); int32_t ret = OpenEditSession(userId, &challenge); - LOG_INFO("challenge is %{public}llu", challenge); + LOG_INFO("challenge is %{public}llu", (unsigned long long)challenge); GlobalUnLock(); return ret; } @@ -141,7 +141,7 @@ int32_t QueryCredential(int32_t userId, uint32_t authType, std::vector &credentia return ret; } RefreshValidTokenTime(); - for (int i = 0; i < num; i++) { + for (uint32_t i = 0; i < num; i++) { CredentialInfo credentialInfo; if (memcpy_s(&credentialInfo, sizeof(CredentialInfo), &credentialInfoHals[i], sizeof(CredentialInfoHal)) != EOK) { diff --git a/common/idm/src/idm_session.c b/common/idm/src/idm_session.c index cb788b404ae35d9d3a5124f628aafc7c45c169ae..38d1f59367b4711d8127d67130c3f3ebf5cf98b4 100644 --- a/common/idm/src/idm_session.c +++ b/common/idm/src/idm_session.c @@ -183,8 +183,9 @@ bool IsSessionTimeout(void) } uint64_t currentTime = GetSystemTime(); if (currentTime < g_session->time || currentTime - g_session->time > SESSION_VALIDITY_PERIOD) { - LOG_ERROR("timeout, %{public}llu, %{public}llu", currentTime, g_session->time); + LOG_ERROR("timeout, %{public}llu, %{public}llu", + (unsigned long long)currentTime, (unsigned long long)g_session->time); return true; } return false; -} \ No newline at end of file +} diff --git a/common/key_mgr/src/token_key.c b/common/key_mgr/src/token_key.c index 65af0123719565da42e6c8c4d85ed1fc50ff5bc6..8cc4f7e31146a4101b0b8eab9b5902b355d18c21 100644 --- a/common/key_mgr/src/token_key.c +++ b/common/key_mgr/src/token_key.c @@ -37,7 +37,7 @@ ResultCode InitTokenKey(void) if (g_tokenKey != NULL) { return RESULT_SUCCESS; } - g_tokenKey = CreateBuffer(SHA256_KEY_LEN); + g_tokenKey = CreateBufferBySize(SHA256_KEY_LEN); if (g_tokenKey == NULL) { LOG_ERROR("g_tokenKey: create buffer failed"); return RESULT_NO_MEMORY; diff --git a/common/user_auth/src/user_auth_funcs.c b/common/user_auth/src/user_auth_funcs.c index f62396b407d9d06d422828908c344bf26f8c5e33..5b2e4c703c13315e22d0653bfce2719fd75e53a1 100644 --- a/common/user_auth/src/user_auth_funcs.c +++ b/common/user_auth/src/user_auth_funcs.c @@ -110,7 +110,7 @@ int32_t RequestAuthResultFunc(uint64_t contextId, const Buffer *scheduleToken, U (void)memset_s(authToken, sizeof(UserAuthTokenHal), 0, sizeof(UserAuthTokenHal)); } } else { - authToken->authResult = scheduleTokenStruct.scheduleResult; + authToken->authResult = (int32_t)scheduleTokenStruct.scheduleResult; } DestoryContext(userAuthContext); return ret; diff --git a/frameworks/kitsimpl/include/coauth_callback_proxy.h b/frameworks/kitsimpl/include/coauth_callback_proxy.h index b1f226b54aa7ce11a24fd9107b7501df0b63bf8f..6e13cade4fa4a63e37b1e5f371ee4dd58d3adaf0 100644 --- a/frameworks/kitsimpl/include/coauth_callback_proxy.h +++ b/frameworks/kitsimpl/include/coauth_callback_proxy.h @@ -29,12 +29,11 @@ public: : IRemoteProxy(impl) {} ~CoAuthCallbackProxy() override = default; - virtual void OnFinish(uint32_t resultCode, std::vector &scheduleToken) override; - virtual void OnAcquireInfo(uint32_t acquire) override; -private: - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); + 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); 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 b4fe33a8dacfbf3c02e92b909a34632e3ea8e0c0..660642507e6ac0971b6641cbf42c370f9a9e2757 100644 --- a/frameworks/kitsimpl/include/coauth_callback_stub.h +++ b/frameworks/kitsimpl/include/coauth_callback_stub.h @@ -28,11 +28,12 @@ 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; + 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 cf54b153b7f4f7163d104d62dcf21cacf57bed5e..769638a6752c487d13e806465797ddc1471d2811 100644 --- a/frameworks/kitsimpl/include/coauth_proxy.h +++ b/frameworks/kitsimpl/include/coauth_proxy.h @@ -30,16 +30,17 @@ 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 54a3ceed2b4fe2dfddbad912fc0d74471da7a7d1..b18490c576ae6ab5bd27ddda29bc2e614ab11d41 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; - 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 ceb41fc6d4a4f8e9890ba3532d058da6dbceced1..aea7f34865914b7829b1315ee9f44696f1a2e209 100644 --- a/frameworks/kitsimpl/include/executor_callback_stub.h +++ b/frameworks/kitsimpl/include/executor_callback_stub.h @@ -25,16 +25,18 @@ namespace UserIAM { namespace AuthResPool { class ExecutorCallbackStub : public IRemoteStub { public: - ExecutorCallbackStub(const std::shared_ptr& impl); + explicit 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); 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 1968c61a388972aa07db9798accd85af54ebbafd..6a1c039f5788066dfe8c5443ad9304c836ef4744 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; - 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/executor_messenger_stub.h b/frameworks/kitsimpl/include/executor_messenger_stub.h index 5a30f05305d5850958efd7bac3a40041d839c8bf..8c0889bf468f6c8557ac1b86d31f8273a2a25eaa 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 2c461b2b7bc87d7e8b2e0919057e99efd5850169..594eb2690f7868dea53e28900ba0a82d771b2ad8 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 475eb649c4484d6aa5a4d5388cf704ce1a73f152..317575c105db1140b9447afd10b29662639d0c05 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 769446d524c17d4e30362c3643808061b91b4ad0..b798b74b51f5f7b4ba9c6092cca959650f982950 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 0c3463e5206cec6f046fc2242684854260d0181b..637c543b61fc4d03becfc25a4d319442ff0d9f76 100644 --- a/frameworks/kitsimpl/include/query_callback_proxy.h +++ b/frameworks/kitsimpl/include/query_callback_proxy.h @@ -28,12 +28,10 @@ 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); - -private: static inline BrokerDelegator delegator_; }; } // namespace AuthResPool diff --git a/frameworks/kitsimpl/include/query_callback_stub.h b/frameworks/kitsimpl/include/query_callback_stub.h index 24b6d24b4eaa3155e273fbe8aa94cb07c035462b..98c0d35d212e0fc7313241f6acdce1d73d3dcef2 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 a05e1e85c36dbf87232324de296077ab4d172f96..eeb2e490fd0100ac1226edcaee6a6e1416a8a602 100644 --- a/frameworks/kitsimpl/include/set_prop_callback_proxy.h +++ b/frameworks/kitsimpl/include/set_prop_callback_proxy.h @@ -27,12 +27,10 @@ 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); - -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 00a235d3200c210c153d48365dbdd00ede3c11d5..c3647ac7ccdaece21dc001bd68bb618c3de58c85 100644 --- a/frameworks/kitsimpl/include/set_prop_callback_stub.h +++ b/frameworks/kitsimpl/include/set_prop_callback_stub.h @@ -29,10 +29,11 @@ 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; + private: int32_t OnResultStub(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/kitsimpl/src/coauth_proxy.cpp b/frameworks/kitsimpl/src/coauth_proxy.cpp index 1eede8e67a19848f9064e6250fc9dfdcd1c03379..337ec875826a5ff9ad5f212f1ff82e666599436d 100644 --- a/frameworks/kitsimpl/src/coauth_proxy.cpp +++ b/frameworks/kitsimpl/src/coauth_proxy.cpp @@ -144,13 +144,13 @@ void CoAuthProxy::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const s uint64_t callerUid; authInfo.GetCallerUid(callerUid); data.WriteUint64(callerUid); - COAUTH_HILOGD(MODULE_INNERKIT, "write callerUid: %{public}" PRIu64, callerUid); + COAUTH_HILOGD(MODULE_INNERKIT, "write callerUid: 0xXXXX%{public}" PRIx64, MASK & callerUid); if (!data.WriteUint64(scheduleId)) { COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed"); return; } - COAUTH_HILOGD(MODULE_INNERKIT, "write scheduleId: %{public}" PRIu64, scheduleId); + COAUTH_HILOGD(MODULE_INNERKIT, "write scheduleId: 0xXXXX%{public}" PRIx64, MASK & scheduleId); if (!data.WriteRemoteObject(callback->AsObject())) { COAUTH_HILOGE(MODULE_INNERKIT, "write callback failed"); diff --git a/frameworks/kitsimpl/src/executor_callback_proxy.cpp b/frameworks/kitsimpl/src/executor_callback_proxy.cpp index 670a5ba25560fea761419f06693e87032b7907d6..513ac3eb0923e7cab3125e8022f6a62bedfd2568 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 1ecfbb3a62263a3fe0c97236402062253cc0adf6..cf284264e6e8821b994b2a28ecb188c2cf3446e7 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 d786b7bd27feaba1bd5ba2b13989c98c33ac7c64..2db3a3225bf128b6019537bdc39f4801fd8c6d3f 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 98360316f481ec79730a789fecea7495b430be6a..9857feadfb56385b6bc0a58c3d242691420c279b 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 e4f8d4bf95f1da13ae55ef093faf6129ca7f7dca..4a1b1fdd65601a701afabd3a5f234b85d2873c6d 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 dd444cecadf27ed5e762b413fd473a25a04c9ecf..e0c12385c56b43b5bf37e5c26ad1e47bb33364cc 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 21e1712e43d9a7d6a130ff3084b7874c854fb62b..42593dcdcfeb1584e9935fa4a11c6bce1a5d1b54 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; - 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/interfaces/innerkits/src/auth_attributes.cpp b/interfaces/innerkits/src/auth_attributes.cpp index d16a702eca82658cd0f90b9bba22c9e0c351d4f8..4bf09827bd41fd245e2dc5aa423648369cb27d2e 100644 --- a/interfaces/innerkits/src/auth_attributes.cpp +++ b/interfaces/innerkits/src/auth_attributes.cpp @@ -14,7 +14,6 @@ */ #include "auth_attributes.h" -#include namespace OHOS { namespace UserIAM { @@ -334,7 +333,6 @@ std::vector AuthAttributes::GetUint32ArrayFromUint8(std::vector AuthAttributes::GetUint64ArrayFromUint8(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/sa_profile/BUILD.gn b/sa_profile/BUILD.gn index b30e741f3fd830731d4db3cd45a6de24d9695bd0..d4aacf2b62030a433b6e3b6ab28f6e5140a19469 100644 --- a/sa_profile/BUILD.gn +++ b/sa_profile/BUILD.gn @@ -22,8 +22,9 @@ ohos_prebuilt_etc("useriam.init") { if (use_musl) { source = "useriam.cfg" } else { - source = "useriam.rc" + source = "useriam_sys.cfg" } + relative_install_dir = "init" part_name = "auth_executor_mgr" subsystem_name = "useriam" diff --git a/sa_profile/useriam.cfg b/sa_profile/useriam.cfg index e1e673c5d77175ea9e65f09b24e0ff8a79794f5d..f7eac7a3e14090f1abbba3aeed51528907e98c80 100644 --- a/sa_profile/useriam.cfg +++ b/sa_profile/useriam.cfg @@ -1,10 +1,20 @@ { + "jobs" : [{ + "name" : "service:useriam", + "cmds" : [ + "mkdir /data/useriam/ 0700 useriam useriam" + ] + } + ], "services" : [{ "name" : "useriam", "path" : ["/system/bin/sa_main", "/system/profile/useriam.xml"], - "uid" : "system", - "gid" : ["system", "shell"], - "secon" : "u:r:useriam:s0" + "uid" : "useriam", + "gid" : ["useriam", "shell"], + "secon" : "u:r:useriam:s0", + "jobs" : { + "on-start" : "service:useriam" + } } ] } diff --git a/sa_profile/useriam.rc b/sa_profile/useriam.rc deleted file mode 100644 index 293c6458945e0346b2336e72027587f33e6a8df5..0000000000000000000000000000000000000000 --- a/sa_profile/useriam.rc +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -service useriam /system/bin/sa_main /system/profile/useriam.xml - class z_core - user system - group system shell - seclabel u:r:useriam:s0 \ No newline at end of file diff --git a/sa_profile/useriam_sys.cfg b/sa_profile/useriam_sys.cfg new file mode 100644 index 0000000000000000000000000000000000000000..cc5fbb69709e43e40a48c27dee9f4103a6c6c77b --- /dev/null +++ b/sa_profile/useriam_sys.cfg @@ -0,0 +1,20 @@ +{ + "jobs" : [{ + "name" : "service:useriam", + "cmds" : [ + "mkdir /data/useriam/ 0700 system system" + ] + } + ], + "services" : [{ + "name" : "useriam", + "path" : ["/system/bin/sa_main", "/system/profile/useriam.xml"], + "uid" : "system", + "gid" : ["system", "shell"], + "secon" : "u:r:useriam:s0", + "jobs" : { + "on-start" : "servi23232323ce:useriam" + } + } + ] +} diff --git a/services/include/auth_res_manager.h b/services/include/auth_res_manager.h index 7943fd2f35949da8cabb0e392f0f62b490c77c33..349d56ad60240385dc3a1b2367e7ae7e4edb2d26 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 72cf2c1798df41039539cfbea5150b82cae626a6..277204e65348ce362dc38518f420ffe8315a2db4 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 04146840c615e2a20192c6cc206b89f3b9fdc2c6..329a82fc7021b62c031635bf5f1c0fff48728237 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 da549a29aba5df97539f1e9d559d9e4834674bdd..73976ada9fb57cce726666d2793a790e34f6ad76 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 f807960baf63a8501f5d56656ade74de57853677..1becf24c5ad298b2cfcb9384c3a49f65367db6e5 100644 --- a/services/include/coauth_service.h +++ b/services/include/coauth_service.h @@ -39,16 +39,17 @@ 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 3e4b1fbe64ae310d776ce4aa3577478241f245cf..d0e6d3170dcf04d1c4254a14b6647b822aa63923 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 successfull, exeID is 0xXXXX%{public}04" PRIx64, MASK & executorId); return executorId; } @@ -86,7 +91,7 @@ void AuthResManager::QueryStatus(ResAuthExecutor &executorInfo, 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/call_monitor.cpp b/services/src/call_monitor.cpp index eba46450e98e331b5051b2336427eff4bf9d0381..9cc04f759156fcc3b537ba186dd28cf1d9a6ec1b 100644 --- a/services/src/call_monitor.cpp +++ b/services/src/call_monitor.cpp @@ -14,6 +14,9 @@ */ #include "call_monitor.h" + +#include + #include "inner_event.h" #include "event_runner.h" @@ -40,7 +43,8 @@ void CallMonitor::MonitorCall(int64_t waitTime, uint64_t scheduleId, Callback &t return; } std::string name = std::to_string(scheduleId); - COAUTH_HILOGI(MODULE_SERVICE, "CallMonitor MonitorCall is called, name is %{public}s", name.c_str()); + COAUTH_HILOGI(MODULE_SERVICE, + "CallMonitor MonitorCall is called, name is 0xXXXX%{public}04" PRIx64, MASK & scheduleId); eventHandler_->PostHighPriorityTask(timeoutFun, name, waitTime); } @@ -51,7 +55,8 @@ void CallMonitor::MonitorRemoveCall(uint64_t scheduleId) return; } std::string name = std::to_string(scheduleId); - COAUTH_HILOGI(MODULE_SERVICE, "CallMonitor MonitorRemoveCall is called, name is %{public}s", name.c_str()); + COAUTH_HILOGI(MODULE_SERVICE, + "CallMonitor MonitorRemoveCall is called, name is 0xXXXX%{public}04" PRIx64, MASK & scheduleId); eventHandler_->RemoveTask(name); } } // namespace PinAuth diff --git a/services/src/coauth_manager.cpp b/services/src/coauth_manager.cpp index 55b207ea1656db25c92b1e8e59a70ceefa957c73..6ad818725f0a68dcc785468bf06119681a7963a3 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"); diff --git a/services/src/coauth_service.cpp b/services/src/coauth_service.cpp index 85237a063bfc3c621deb1e5fb3ccb697bbf90f53..3095f9b2812ba6cdfeb7b648d391e2bcb1b6c897 100644 --- a/services/src/coauth_service.cpp +++ b/services/src/coauth_service.cpp @@ -106,7 +106,7 @@ uint64_t CoAuthService::Register(std::shared_ptr executorInfo, } uint64_t exeID = authResMgr_.Register(executorInfo, callback); - COAUTH_HILOGD(MODULE_SERVICE, "exeID is XXXX%{public}4" PRIx64, exeID); + COAUTH_HILOGD(MODULE_SERVICE, "exeID is 0xXXXX%{public}04" PRIx64, MASK & exeID); return exeID; } diff --git a/services/src/coauth_stub.cpp b/services/src/coauth_stub.cpp index 24882100b6e8eea9e98e69498be4b6f944edd92c..04abc976c69c91e6b709a602de37c6ed4fa408f6 100644 --- a/services/src/coauth_stub.cpp +++ b/services/src/coauth_stub.cpp @@ -118,10 +118,10 @@ int32_t CoAuthStub::BeginScheduleStub(MessageParcel& data, MessageParcel& reply) authInfo.SetPkgName(GetPkgName); uint64_t GetCallerUid = data.ReadUint64(); authInfo.SetCallerUid(GetCallerUid); - COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64,GetCallerUid:%{public}" PRIu64, GetCallerUid); + COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64,GetCallerUid:0xXXXX%{public}04" PRIx64, MASK & GetCallerUid); uint64_t scheduleId = data.ReadUint64(); - COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64,scheduleId:%{public}" PRIu64, scheduleId); + COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64,scheduleId:0xXXXX%{public}04" PRIx64, MASK & scheduleId); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { @@ -139,7 +139,7 @@ int32_t CoAuthStub::CancelStub(MessageParcel& data, MessageParcel& reply) COAUTH_HILOGI(MODULE_SERVICE, "CoAuthStub: CancelStub start"); uint64_t scheduleId = data.ReadUint64(); - COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64 scheduleId:%{public}" PRIu64, scheduleId); + COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64 scheduleId:0xXXXX%{public}04" PRIx64, MASK & scheduleId); int ret = Cancel(scheduleId); if (!reply.WriteInt32(ret)) { diff --git a/utils/native/include/coauth_hilog_wrapper.h b/utils/native/include/coauth_hilog_wrapper.h index 9524fa785689c7d90a9052b92007f05764bc6faa..32ac3ff6ec2cfee3d681dddd2e851fdd2078d1cd 100644 --- a/utils/native/include/coauth_hilog_wrapper.h +++ b/utils/native/include/coauth_hilog_wrapper.h @@ -16,8 +16,6 @@ #ifndef COAUTH_HILOG_WRAPPER_H #define COAUTH_HILOG_WRAPPER_H -#define CONFIG_HILOG -#ifdef CONFIG_HILOG #include "hilog/log.h" namespace OHOS { namespace UserIAM { @@ -78,17 +76,9 @@ static constexpr OHOS::HiviewDFX::HiLogLabel COAUTH_LABEL[COAUTH_MODULE_BUTT] = #define COAUTH_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) #define COAUTH_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) #define COAUTH_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) + +constexpr uint64_t MASK = 0x0000FFFF; } // namespace UserIAM } // namespace OHOS -#else - -#define COAUTH_HILOGF(...) -#define COAUTH_HILOGE(...) -#define COAUTH_HILOGW(...) -#define COAUTH_HILOGI(...) -#define COAUTH_HILOGD(...) - -#endif // CONFIG_HILOG - #endif // COAUTH_HILOG_WRAPPER_H