Skip to content

Commit

Permalink
move CheckAdmin to anonymous namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Nov 29, 2023
1 parent 58ab5b2 commit d640325
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
41 changes: 24 additions & 17 deletions src/app/clusters/icd-management-server/icd-management-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ class IcdManagementFabricDelegate : public FabricTable::Delegate
IcdManagementFabricDelegate gFabricDelegate;
IcdManagementAttributeAccess gAttribute;

/**
* @brief Function checks if the client as admin permissions to the cluster in the commandPath
*
* @param[out] isClientAdmin True : Client has admin permissions
* False : Client does not have admin permissions
* If an error ocurs, isClientAdmin is not changed
* @return CHIP_ERROR
*/
CHIP_ERROR CheckAdmin(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, bool & isClientAdmin)
{
RequestPath requestPath{ .cluster = commandPath.mClusterId, .endpoint = commandPath.mEndpointId };
CHIP_ERROR err = GetAccessControl().Check(commandObj->GetSubjectDescriptor(), requestPath, Privilege::kAdminister);
if (CHIP_NO_ERROR == err)
{
isClientAdmin = true;
}
else if (CHIP_ERROR_ACCESS_DENIED == err)
{
isClientAdmin = false;
err = CHIP_NO_ERROR;
}
return err;
}

} // namespace

/*
Expand Down Expand Up @@ -322,23 +346,6 @@ void ICDManagementServer::TriggerICDMTableUpdatedEvent()
ICDNotifier::GetInstance().BroadcastICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
}

CHIP_ERROR ICDManagementServer::CheckAdmin(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
bool & isClientAdmin)
{
RequestPath requestPath{ .cluster = commandPath.mClusterId, .endpoint = commandPath.mEndpointId };
CHIP_ERROR err = GetAccessControl().Check(commandObj->GetSubjectDescriptor(), requestPath, Privilege::kAdminister);
if (CHIP_NO_ERROR == err)
{
isClientAdmin = true;
}
else if (CHIP_ERROR_ACCESS_DENIED == err)
{
isClientAdmin = false;
err = CHIP_NO_ERROR;
}
return err;
}

void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore,
ICDConfigurationData & icdConfigurationData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class ICDManagementServer
*/
void TriggerICDMTableUpdatedEvent();

CHIP_ERROR CheckAdmin(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
bool & isClientAdmin);

static chip::PersistentStorageDelegate * mStorage;
static chip::Crypto::SymmetricKeystore * mSymmetricKeystore;
static chip::ICDConfigurationData * mICDConfigurationData;
Expand Down

0 comments on commit d640325

Please sign in to comment.