Signed-off-by: lwk <1076278852@qq.com>
This commit is contained in:
lwk
2022-03-15 22:14:44 +08:00
parent 8ac5fe0929
commit c805ea83b8
4 changed files with 64 additions and 40 deletions
@@ -43,7 +43,11 @@ sptr<CoAuth::ICoAuth> AuthExecutorRegistry::GetProxy()
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get coauth service");
return nullptr;
}
sptr<IRemoteObject::DeathRecipient> dr = new AuthExecutorRegistryDeathRecipient();
sptr<IRemoteObject::DeathRecipient> dr = new (std::nothrow) AuthExecutorRegistryDeathRecipient();
if (dr == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "dr is nullptr");
return nullptr;
}
if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(dr))) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to add death recipient");
return nullptr;
@@ -81,7 +85,11 @@ uint64_t AuthExecutorRegistry::Register(std::shared_ptr<AuthExecutor> executorIn
COAUTH_HILOGE(MODULE_INNERKIT, "GetProxy is nullptr");
return FAIL;
}
sptr<IExecutorCallback> iExecutorCallback = new ExecutorCallbackStub(callback);
sptr<IExecutorCallback> iExecutorCallback = new (std::nothrow) ExecutorCallbackStub(callback);
if (iExecutorCallback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "iExecutorCallback is nullptr");
return FAIL;
}
return proxy->Register(executorInfo, iExecutorCallback);
}
@@ -97,7 +105,11 @@ void AuthExecutorRegistry::QueryStatus(AuthExecutor &executorInfo, std::shared_p
COAUTH_HILOGE(MODULE_INNERKIT, "GetProxy is nullptr");
return;
}
sptr<IQueryCallback> iQueryCallback = new QueryCallbackStub(callback);
sptr<IQueryCallback> iQueryCallback = new (std::nothrow) QueryCallbackStub(callback);
if (iQueryCallback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "iQueryCallback is nullptr");
return;
}
return proxy->QueryStatus(executorInfo, iQueryCallback);
}
+11 -3
View File
@@ -44,7 +44,11 @@ sptr<ICoAuth> CoAuth::GetProxy()
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get coauth manager service");
return nullptr;
}
sptr<IRemoteObject::DeathRecipient> dr = new CoAuthDeathRecipient();
sptr<IRemoteObject::DeathRecipient> dr = new (std::nothrow) CoAuthDeathRecipient();
if (dr == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "dr is nullptr");
return nullptr;
}
if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(dr))) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to add death recipient");
return nullptr;
@@ -83,7 +87,7 @@ void CoAuth::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, std::shared_
return;
}
sptr<ICoAuthCallback> icoAuthCallback = new CoAuthCallbackStub(callback);
sptr<ICoAuthCallback> icoAuthCallback = new (std::nothrow) CoAuthCallbackStub(callback);
if (icoAuthCallback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "BeginSchedule failed, icoAuthCallback is nullptr");
return;
@@ -125,7 +129,11 @@ void CoAuth::SetExecutorProp(AuthResPool::AuthAttributes &conditions, std::share
return;
}
sptr<ISetPropCallback> iSetExecutorCallback = new SetPropCallbackStub(callback);
sptr<ISetPropCallback> iSetExecutorCallback = new (std::nothrow) SetPropCallbackStub(callback);
if (iSetExecutorCallback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "iSetExecutorCallback is nullptr");
return;
}
return proxy->SetExecutorProp(conditions, iSetExecutorCallback);
}
+32 -33
View File
@@ -23,53 +23,52 @@ namespace CoAuth {
/* Register the executor, pass in the executor information and the callback returns the executor ID. */
uint64_t AuthResManager::Register(std::shared_ptr<ResAuthExecutor> executorInfo, sptr<ResIExecutorCallback> callback)
{
int32_t result = SUCCESS;
uint64_t executorId = INVALID_EXECUTOR_ID;
if (executorInfo == nullptr || callback == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "executorInfo or callback is nullptr");
return executorId;
return INVALID_EXECUTOR_ID;
}
ExecutorInfo info;
std::vector<uint8_t> publicKey;
AuthType authType;
ExecutorSecureLevel esl;
ExecutorType exeType;
executorInfo->GetAuthType(authType);
executorInfo->GetAuthType(info.authType);
executorInfo->GetAuthAbility(info.authAbility);
executorInfo->GetExecutorSecLevel(esl);
executorInfo->GetExecutorType(exeType);
executorInfo->GetExecutorSecLevel(info.esl);
executorInfo->GetExecutorType(info.executorType);
executorInfo->GetPublicKey(publicKey);
info.authType = authType;
info.esl = esl;
info.executorType = exeType;
if (publicKey.size() > PUBLIC_KEY_LEN) {
COAUTH_HILOGE(MODULE_SERVICE, "publicKey length too long");
return executorId;
} else {
for (std::size_t i = 0; i < publicKey.size(); i++) {
info.publicKey[i] = publicKey[i];
}
return INVALID_EXECUTOR_ID;
}
result = ExecutorRegister(info, executorId);
if (result == SUCCESS) {
sptr<IRemoteObject::DeathRecipient> dr = new ResIExecutorCallbackDeathRecipient(executorId, this);
if (!callback->AsObject()->AddDeathRecipient(dr)) {
COAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient ResIExecutorCallbackDeathRecipient");
return INVALID_EXECUTOR_ID;
}
coAuthResPool_.Insert(executorId, executorInfo, callback);
COAUTH_HILOGI(MODULE_SERVICE, "register is successfull!");
// Assign messenger
sptr<UserIAM::AuthResPool::IExecutorMessenger> messenger =
new UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_);
callback->OnMessengerReady(messenger);
COAUTH_HILOGD(MODULE_SERVICE, "register is successfull,exeID is XXXX%{public}04" PRIx64, executorId);
return executorId;
for (std::size_t i = 0; i < publicKey.size(); i++) {
info.publicKey[i] = publicKey[i];
}
if (result == FAIL) {
uint64_t executorId = INVALID_EXECUTOR_ID;
int32_t result = ExecutorRegister(info, executorId);
if (result != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "register is failure!");
return INVALID_EXECUTOR_ID;
}
sptr<IRemoteObject::DeathRecipient> dr =
new (std::nothrow) ResIExecutorCallbackDeathRecipient(executorId, this);
if (dr == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "dr is nullptr");
return INVALID_EXECUTOR_ID;
}
if (!callback->AsObject()->AddDeathRecipient(dr)) {
COAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient ResIExecutorCallbackDeathRecipient");
return INVALID_EXECUTOR_ID;
}
coAuthResPool_.Insert(executorId, executorInfo, callback);
COAUTH_HILOGI(MODULE_SERVICE, "register is successfull!");
// Assign messenger
sptr<UserIAM::AuthResPool::IExecutorMessenger> messenger =
new (std::nothrow) UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_);
if (messenger == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "messenger is nullptr");
return INVALID_EXECUTOR_ID;
}
callback->OnMessengerReady(messenger);
COAUTH_HILOGD(MODULE_SERVICE, "register is successfull,exeID is XXXX%{public}04" PRIx64, executorId);
return executorId;
}
+6 -1
View File
@@ -45,7 +45,12 @@ void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptr<I
COAUTH_HILOGE(MODULE_SERVICE, "executorId does not exist.");
return callback->OnFinish(FAIL, scheduleToken);
}
sptr<IRemoteObject::DeathRecipient> dr = new ResICoAuthCallbackDeathRecipient(scheduleId, this);
sptr<IRemoteObject::DeathRecipient> dr =
new (std::noboolalpha) ResICoAuthCallbackDeathRecipient(scheduleId, this);
if (dr == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "dr is nullptr.");
return callback->OnFinish(FAIL, scheduleToken);
}
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
COAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient ResICoAuthCallbackDeathRecipient");
}