diff --git a/frameworks/domain_account/src/domain_account_client.cpp b/frameworks/domain_account/src/domain_account_client.cpp index 0974315f1..c5977f346 100644 --- a/frameworks/domain_account/src/domain_account_client.cpp +++ b/frameworks/domain_account/src/domain_account_client.cpp @@ -362,6 +362,7 @@ ErrCode DomainAccountClient::GetAccountServerConfig(const DomainAccountInfo &inf void DomainAccountClient::RestoreListenerRecords() { + std::lock_guard lock(recordMutex_); if (listenerManager_ == nullptr) { ACCOUNT_LOGI("listenerManager_ is nullptr"); return; diff --git a/services/accountmgr/include/domain_account/inner_domain_account_manager.h b/services/accountmgr/include/domain_account/inner_domain_account_manager.h index 396a96e2b..34d3e811d 100644 --- a/services/accountmgr/include/domain_account/inner_domain_account_manager.h +++ b/services/accountmgr/include/domain_account/inner_domain_account_manager.h @@ -35,7 +35,7 @@ class InnerDomainAccountManager { public: static InnerDomainAccountManager &GetInstance(); ErrCode RegisterPlugin(const sptr &plugin); - void UnregisterPlugin(); + ErrCode UnregisterPlugin(); ErrCode Auth(const DomainAccountInfo &info, const std::vector &password, const sptr &callback); ErrCode AuthUser(int32_t userId, const std::vector &password, diff --git a/services/accountmgr/src/domain_account/domain_account_manager_service.cpp b/services/accountmgr/src/domain_account/domain_account_manager_service.cpp index d7398b0ae..f27261377 100644 --- a/services/accountmgr/src/domain_account/domain_account_manager_service.cpp +++ b/services/accountmgr/src/domain_account/domain_account_manager_service.cpp @@ -39,8 +39,7 @@ ErrCode DomainAccountManagerService::RegisterPlugin(const sptr authResult(DomainAuthResult::Unmarshalling(parcel)); if (authResult == nullptr) { ACCOUNT_LOGE("authResult is nullptr"); - return; + return callback_->OnResult(ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR, resultParcel); } if ((errCode == ERR_OK) && (userId_ != 0)) { InnerDomainAccountManager::GetInstance().InsertTokenToMap(userId_, (*authResult).token); @@ -137,16 +142,12 @@ void InnerDomainAuthCallback::OnResult(const int32_t errCode, Parcel &parcel) } (void)memset_s(authResult->token.data(), authResult->token.size(), 0, authResult->token.size()); authResult->token.clear(); - Parcel resultParcel; + if (!(*authResult).Marshalling(resultParcel)) { ACCOUNT_LOGE("authResult Marshalling failed"); - return; + return callback_->OnResult(ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR, resultParcel); } AccountInfoReport::ReportSecurityInfo("", userId_, ReportEvent::EVENT_LOGIN, errCode); - if (callback_ == nullptr) { - ACCOUNT_LOGI("callback_ is nullptr"); - return; - } return callback_->OnResult(errCode, resultParcel); } @@ -172,15 +173,21 @@ ErrCode InnerDomainAccountManager::RegisterPlugin(const sptr lock(mutex_); + if (callingUid_ != IPCSkeleton::GetCallingUid()) { + ACCOUNT_LOGE("Failed to check callingUid, register callingUid=%{public}d, unregister callingUid=%{public}d.", + callingUid_, IPCSkeleton::GetCallingUid()); + return ERR_ACCOUNT_COMMON_PERMISSION_DENIED; + } if ((plugin_ != nullptr) && (plugin_->AsObject() != nullptr)) { plugin_->AsObject()->RemoveDeathRecipient(deathRecipient_); } plugin_ = nullptr; callingUid_ = -1; deathRecipient_ = nullptr; + return ERR_OK; } ErrCode InnerDomainAccountManager::StartAuth(const sptr &plugin, const DomainAccountInfo &info, @@ -1789,7 +1796,7 @@ ErrCode InnerDomainAccountManager::UpdateAccountInfo( } } } - + // update local info return IInnerOsAccountManager::GetInstance().UpdateAccountInfoByDomainAccountInfo( userId, newDomainAccountInfo); diff --git a/services/accountmgr/src/osaccount/os_account_interface.cpp b/services/accountmgr/src/osaccount/os_account_interface.cpp index 0430cf0b2..393071f9d 100644 --- a/services/accountmgr/src/osaccount/os_account_interface.cpp +++ b/services/accountmgr/src/osaccount/os_account_interface.cpp @@ -214,22 +214,20 @@ ErrCode OsAccountInterface::SendToIDMAccountDelete(OsAccountInfo &osAccountInfo) } // wait callback - struct tm startTime = {0}; - struct tm nowTime = {0}; - OHOS::GetSystemCurrentTime(&startTime); - OHOS::GetSystemCurrentTime(&nowTime); - while (OHOS::GetSecondsBetween(startTime, nowTime) < Constants::TIME_WAIT_TIME_OUT && - !callback->isCalled_) { - std::this_thread::sleep_for(std::chrono::milliseconds(Constants::WAIT_ONE_TIME)); - OHOS::GetSystemCurrentTime(&nowTime); - } - if (!callback->isCalled_) { - ACCOUNT_LOGE("idm did not call back! timeout!"); - ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_REMOVE, -1, - "UserIDM erase user timeout"); - FinishTraceAdapter(); - return ERR_OK; // do not return fail + { + std::unique_lock lck(callback->mutex_); + if (!callback->isCalled_) { + callback->onResultCondition_.wait_for(lck, std::chrono::seconds(Constants::TIME_WAIT_TIME_OUT)); + } + if (!callback->isCalled_) { + ACCOUNT_LOGE("idm did not call back! timeout!"); + ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_REMOVE, -1, + "UserIDM erase user timeout"); + FinishTraceAdapter(); + return ERR_OK; // do not return fail + } } + ACCOUNT_LOGI("send to idm account delete and get callback succeed!"); FinishTraceAdapter(); return ERR_OK;