📄 addmgr.c
字号:
/*------------------------------------------------------------------------------
*Name: cssm_UpdateModuleRecord
*
*Description:
* This function is called by Register and Deregister services.
* It either adds the input FunctionTable to or removes the existing
* function table from the attached module list node associated with
* the input GUID.
*
*Parameters:
* GUID (input) - GUID of the addin whose function table is to be modified
* FunctionTable (input) - if NULL, this parameter indicates that the
* function table should be removed from the addin node.
* if not NULL, this function table should be copied
* into the addin node
*
*Returns:
* CSSM_OK - if the registration or deregistration was successful
* CSSM_FAIL - if the inputs are invalid or memory allocation fails
*
*----------------------------------------------------------------------------*/
#define ALL_SERVICES_MASK (CSSM_SERVICE_CSP | CSSM_SERVICE_DL | CSSM_SERVICE_CL | CSSM_SERVICE_TP | CSSM_SERVICE_VL)
CSSM_RETURN cssm_UpdateModuleRecord (
const CSSM_GUID_PTR GUID,
const CSSM_REGISTRATION_INFO_PTR FunctionTable)
{
cssm_ATTACHED_MODULE_NODE_PTR ModuleInfo;
CSSM_MODULE_FUNCS_PTR Src, Dest;
uint32 i,j, size;
//
// BUGBUG Init'd size to 0 to avoid warning 4
size = 0;
/* Get the node for the module being registered or deregistered */
if ((ModuleInfo = cssm_GetModuleRecordByGUID(GUID)) == NULL) {
CSSM_SetError (&CssmGUID, CSSM_INVALID_GUID);
return CSSM_FAIL;
}
/* If Deregistering, */
/* Free the memory associated with the callback function ptrs and return */
if (NULL == FunctionTable) {
if (ModuleInfo->AddInJT) {
CSSM_REGISTRATION_INFO_PTR Callback = ModuleInfo->AddInJT;
for (i = 0; i < Callback->NumberOfServiceTables; i++)
cssm_free(Callback->Services[i].FunctionTable.ServiceFuncs, 0);
cssm_free (Callback->Services, 0);
cssm_free (Callback, 0);
ModuleInfo->AddInJT = NULL;
}
return CSSM_OK;
}
/*
* If Registering,
*/
/* Validate that this module is not already registered */
if (ModuleInfo->AddInJT != NULL) {
CSSM_SetError (&CssmGUID, CSSM_ADDIN_ALREADY_REGISTERED);
return CSSM_FAIL;
}
/* Validate that this FunctionTable contains at least 1 service */
/* and does not include any unknown services */
if (!FunctionTable->NumberOfServiceTables || !FunctionTable->Services ||
((FunctionTable->ServiceSummary & ~ALL_SERVICES_MASK) != 0))
{
CSSM_SetError (&CssmGUID, CSSM_INVALID_SERVICE_MASK);
return CSSM_FAIL;
}
/* Validate that each service table is a known service type */
/* and that it contains a callback function table */
for (i=0; i <FunctionTable->NumberOfServiceTables ; i++)
{
if (!FunctionTable->Services[i].FunctionTable.ServiceFuncs ||
((FunctionTable->Services[i].ServiceType & ~ALL_SERVICES_MASK) != 0))
{
CSSM_SetError (&CssmGUID, CSSM_INVALID_SERVICE_MASK);
return CSSM_FAIL;
}
}
/* Allocate and copy the Registration Info */
ModuleInfo->AddInJT = cssm_malloc(sizeof(CSSM_REGISTRATION_INFO), 0);
if (!ModuleInfo->AddInJT) {
CSSM_SetError (&CssmGUID, CSSM_MEMORY_ERROR);
return CSSM_FAIL;
}
*ModuleInfo->AddInJT = *FunctionTable;
/* Allocate memory for the new Services */
ModuleInfo->AddInJT->Services =
cssm_calloc(FunctionTable->NumberOfServiceTables,
sizeof(CSSM_MODULE_FUNCS), 0);
if (!ModuleInfo->AddInJT->Services) {
cssm_free(ModuleInfo->AddInJT, 0);
ModuleInfo->AddInJT = NULL;
CSSM_SetError (&CssmGUID, CSSM_MEMORY_ERROR);
return CSSM_FAIL;
}
/* Allocate and copy the callback function table for each service */
Src = FunctionTable->Services;
Dest = ModuleInfo->AddInJT->Services;
for (i=0; i<FunctionTable->NumberOfServiceTables; i++, Src++, Dest++) {
Dest->ServiceType = Src->ServiceType;
switch (Src->ServiceType) {
case CSSM_SERVICE_TP :
size = sizeof (CSSM_SPI_TP_FUNCS);
break;
case CSSM_SERVICE_CSP :
size = sizeof (CSSM_SPI_CSP_FUNCS);
break;
case CSSM_SERVICE_CL :
size = sizeof (CSSM_SPI_CL_FUNCS);
break;
case CSSM_SERVICE_DL :
size = sizeof (CSSM_SPI_DL_FUNCS);
break;
case CSSM_SERVICE_VL :
size = sizeof (CSSM_SPI_VL_FUNCS);
break;
}
Dest->FunctionTable.ServiceFuncs = cssm_malloc (size, 0);
if (!Dest->FunctionTable.ServiceFuncs) {
CSSM_REGISTRATION_INFO_PTR Callback = ModuleInfo->AddInJT;
for (j=0; j < i; j++)
cssm_free(Callback->Services[j].FunctionTable.ServiceFuncs, 0);
cssm_free(Callback->Services, 0);
cssm_free(Callback, 0);
ModuleInfo->AddInJT = NULL;
CSSM_SetError (&CssmGUID, CSSM_MEMORY_ERROR);
return CSSM_FAIL;
}
cssm_memcpy(Dest->FunctionTable.ServiceFuncs,
Src->FunctionTable.ServiceFuncs, size);
}
return CSSM_OK;
}
/*------------------------------------------------------------------------------
*Name: cssm_RemoveModuleRecord
*
*Description:
* Deletes the node associated with this add-in module.
*
*Parameters:
* GUID - guid of the add-in module
*
*Returns:
* CSSM_FAIL - unable to delete the add-in record
* CSSM_OK - add-in record is removed
*
*----------------------------------------------------------------------------*/
CSSM_RETURN cssm_RemoveModuleRecord (const CSSM_GUID_PTR GUID)
{
cssm_ATTACHED_MODULE_NODE_PTR ModuleInfo,
PreviousModuleInfo = NULL;
cssm_ATTACH_INFO_NODE_PTR HandleInfo,
NextHandleInfo;
uint32 i;
/* Iterate through the list looking for the node with the input GUID */
ModuleInfo = ModuleListHead;
while (ModuleInfo) {
/* If not found, proceed to the next node */
if (cssm_memcmp (GUID, &ModuleInfo->GUID, sizeof(CssmGUID)) != 0) {
PreviousModuleInfo = ModuleInfo;
ModuleInfo = ModuleInfo->Next;
} else { /* If found, */
/* Remove it from the list */
if (!PreviousModuleInfo)
ModuleListHead = ModuleInfo->Next;
else
PreviousModuleInfo->Next = ModuleInfo->Next;
/* Free the attach information for every attach */
HandleInfo = ModuleInfo->AttachInfo;
while (HandleInfo) {
NextHandleInfo = HandleInfo->Next;
cssm_free (HandleInfo, 0);
HandleInfo = NextHandleInfo;
}
/* Free the addin function tables */
if (ModuleInfo->AddInJT) {
CSSM_REGISTRATION_INFO_PTR Callback = ModuleInfo->AddInJT;
for (i=0; i < Callback->NumberOfServiceTables; i++)
cssm_free(Callback->Services[i].FunctionTable.ServiceFuncs, 0);
cssm_free(Callback->Services, 0);
cssm_free(Callback, 0);
}
/* Free the node */
cssm_free (ModuleInfo, 0);
return CSSM_OK;
}
}
/* No node was found for the input GUID */
CSSM_SetError (&CssmGUID, CSSM_INVALID_GUID);
return CSSM_FAIL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -