Moved the code that obtains identity provider interfaces to its own platform independent module.
This commit is contained in:
parent
afb30e0f5f
commit
dcde5534ef
@ -28,19 +28,6 @@
|
||||
|
||||
//===[ Type definitions ]==================================================
|
||||
|
||||
//
|
||||
// Identity Token Module definition
|
||||
//
|
||||
typedef struct _IdenTokenProviderModule
|
||||
{
|
||||
LIST_ENTRY listEntry;
|
||||
char *pTypeName;
|
||||
int typeNameLen;
|
||||
void *libHandle;
|
||||
IdenTokenProviderIf *pIdenTokenProviderIf;
|
||||
|
||||
} IdenTokenProviderModule, *PIdenTokenProviderModule;
|
||||
|
||||
//
|
||||
// Platform Mutex structure
|
||||
//
|
||||
@ -60,212 +47,6 @@ typedef struct _PlatformMutex
|
||||
pthread_mutex_t g_hModuleMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
//
|
||||
// IdenTokenProviderModule list and syncronization mutex
|
||||
//
|
||||
static
|
||||
LIST_ENTRY g_IdenTokenProviderModuleListHead = {&g_IdenTokenProviderModuleListHead, &g_IdenTokenProviderModuleListHead};
|
||||
|
||||
static
|
||||
pthread_mutex_t g_IdenTokenProviderModuleMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
CasaStatus
|
||||
GetIdenTokenProviderInterface(
|
||||
IN const char *pIdenTokenTypeName,
|
||||
INOUT IdenTokenProviderIf **ppIdenTokenProviderIf)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// Environment:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
ConfigIf *pModuleConfigIf;
|
||||
|
||||
DbgTrace(2, "-GetIdenTokenProviderInterface- Start\n", 0);
|
||||
|
||||
// Get the configuration for the module
|
||||
retStatus = GetConfigInterface("/etc/opt/novell/CASA/authtoken.d/modules.d",
|
||||
pIdenTokenTypeName,
|
||||
&pModuleConfigIf);
|
||||
if (CASA_SUCCESS(retStatus)
|
||||
&& CasaStatusCode(retStatus) != CASA_STATUS_OBJECT_NOT_FOUND)
|
||||
{
|
||||
LIST_ENTRY *pListEntry;
|
||||
IdenTokenProviderModule *pIdenTokenProviderModule = NULL;
|
||||
int32_t idenTokenTypeNameLen = strlen(pIdenTokenTypeName);
|
||||
|
||||
// Gain exclusive access to our mutex
|
||||
pthread_mutex_lock(&g_IdenTokenProviderModuleMutex);
|
||||
|
||||
// Look if we already have the module in our list
|
||||
pListEntry = g_IdenTokenProviderModuleListHead.Flink;
|
||||
while (pListEntry != &g_IdenTokenProviderModuleListHead)
|
||||
{
|
||||
// Get pointer to the current entry
|
||||
pIdenTokenProviderModule = CONTAINING_RECORD(pListEntry, IdenTokenProviderModule, listEntry);
|
||||
|
||||
// Check if this is the module that we need
|
||||
if (pIdenTokenProviderModule->typeNameLen == idenTokenTypeNameLen
|
||||
&& memcmp(pIdenTokenTypeName, pIdenTokenProviderModule->pTypeName, idenTokenTypeNameLen) == 0)
|
||||
{
|
||||
// This is the module that we need, stop looking.
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is not the module that we are looking for
|
||||
pIdenTokenProviderModule = NULL;
|
||||
}
|
||||
|
||||
// Advance to the next entry
|
||||
pListEntry = pListEntry->Flink;
|
||||
}
|
||||
|
||||
// Proceed based on whether or not a module was found
|
||||
if (pIdenTokenProviderModule)
|
||||
{
|
||||
// Module found in our list, provide the caller with its IdenTokenProviderIf
|
||||
// instance after we have incremented its reference count.
|
||||
pIdenTokenProviderModule->pIdenTokenProviderIf->addReference(pIdenTokenProviderModule->pIdenTokenProviderIf);
|
||||
*ppIdenTokenProviderIf = pIdenTokenProviderModule->pIdenTokenProviderIf;
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Needed module not found in our list, create an entry.
|
||||
pIdenTokenProviderModule = malloc(sizeof(*pIdenTokenProviderModule));
|
||||
if (pIdenTokenProviderModule)
|
||||
{
|
||||
// Allocate buffer to contain the authentication type name within the module entry
|
||||
pIdenTokenProviderModule->pTypeName = malloc(idenTokenTypeNameLen + 1);
|
||||
if (pIdenTokenProviderModule->pTypeName)
|
||||
{
|
||||
char *pLibraryName;
|
||||
|
||||
// Initialize the library handle field
|
||||
pIdenTokenProviderModule->libHandle = NULL;
|
||||
|
||||
// Save the auth type name within the entry
|
||||
strcpy(pIdenTokenProviderModule->pTypeName, pIdenTokenTypeName);
|
||||
pIdenTokenProviderModule->typeNameLen = idenTokenTypeNameLen;
|
||||
|
||||
// Obtain the name of the library that we must load
|
||||
pLibraryName = pModuleConfigIf->getEntryValue(pModuleConfigIf, "LibraryName");
|
||||
if (pLibraryName)
|
||||
{
|
||||
// Load the library
|
||||
pIdenTokenProviderModule->libHandle = dlopen(pLibraryName, RTLD_LAZY);
|
||||
if (pIdenTokenProviderModule->libHandle)
|
||||
{
|
||||
PFN_GetIdenTokenProviderIfRtn pGetIdenTokenProviderIfRtn;
|
||||
|
||||
// Library has been loaded, now get a pointer to its GetIdenTokenProviderProviderInterface routine
|
||||
pGetIdenTokenProviderIfRtn = dlsym(pIdenTokenProviderModule->libHandle, GET_IDEN_TOKEN_PROVIDER_INTERFACE_RTN_SYMBOL);
|
||||
if (pGetIdenTokenProviderIfRtn)
|
||||
{
|
||||
// Now, obtain the modules IdenTokenProviderIf.
|
||||
retStatus = (pGetIdenTokenProviderIfRtn)(pModuleConfigIf, &pIdenTokenProviderModule->pIdenTokenProviderIf);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetIdenTokenProviderInterface- dlsym error = %s\n", dlerror());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_LIBRARY_LOAD_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetIdenTokenProviderInterface- dlopen error = %s\n", dlerror());
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_LIBRARY_LOAD_FAILURE);
|
||||
}
|
||||
|
||||
// Free the buffer holding the library name
|
||||
free(pLibraryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetIdenTokenProviderInterface- Library name not configured\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_CONFIGURATION_ERROR);
|
||||
}
|
||||
|
||||
// Check if we were successful at obtaining the IdenTokenProviderIf instance for the
|
||||
// module.
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// Insert the entry in the list, provide the caller with its IdenTokenProviderIf
|
||||
// instance after we have incremented its reference count.
|
||||
InsertTailList(&g_IdenTokenProviderModuleListHead, &pIdenTokenProviderModule->listEntry);
|
||||
pIdenTokenProviderModule->pIdenTokenProviderIf->addReference(pIdenTokenProviderModule->pIdenTokenProviderIf);
|
||||
*ppIdenTokenProviderIf = pIdenTokenProviderModule->pIdenTokenProviderIf;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed, free resources.
|
||||
free(pIdenTokenProviderModule->pTypeName);
|
||||
if (pIdenTokenProviderModule->libHandle)
|
||||
dlclose(pIdenTokenProviderModule->libHandle);
|
||||
free(pIdenTokenProviderModule);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetIdenTokenProviderInterface- Unable to allocate buffer\n", 0);
|
||||
|
||||
// Free buffer allocated for entry
|
||||
free(pIdenTokenProviderModule);
|
||||
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetIdenTokenProviderInterface- Unable to allocate buffer\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
}
|
||||
|
||||
// Release exclusive access to our mutex
|
||||
pthread_mutex_unlock(&g_IdenTokenProviderModuleMutex);
|
||||
|
||||
// Release config interface instance
|
||||
pModuleConfigIf->releaseReference(pModuleConfigIf);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-GetIdenTokenProviderInterface- Unable to obtain config interface\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_AUTHTOKEN,
|
||||
CASA_STATUS_CONFIGURATION_ERROR);
|
||||
}
|
||||
|
||||
DbgTrace(2, "-GetIdenTokenProviderInterface- End, retStatus = %08X\n", retStatus);
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
HANDLE
|
||||
PlatAllocMutex(void)
|
||||
@ -391,6 +172,96 @@ PlatReleaseMutex(HANDLE hMutex)
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
LIB_HANDLE
|
||||
OpenLibrary(
|
||||
IN char *pFileName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
LIB_HANDLE libHandle;
|
||||
|
||||
|
||||
DbgTrace(1, "-OpenLibrary- Start\n", 0);
|
||||
|
||||
libHandle = dlopen(pFileName, RTLD_LAZY);
|
||||
if (libHandle == NULL)
|
||||
{
|
||||
DbgTrace(0, "-OpenLibrary- Not able to load library, error = %d\n", dlerror());
|
||||
}
|
||||
|
||||
DbgTrace(1, "-OpenLibrary- End, handle = %08X\n", libHandle);
|
||||
|
||||
return libHandle;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void
|
||||
CloseLibrary(
|
||||
IN LIB_HANDLE libHandle)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
DbgTrace(1, "-CloseLibrary- Start\n", 0);
|
||||
|
||||
dlclose(libHandle);
|
||||
|
||||
DbgTrace(1, "-CloseLibrary- End\n", 0);
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
void*
|
||||
GetFunctionPtr(
|
||||
IN LIB_HANDLE libHandle,
|
||||
IN char *pFunctionName)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// Abstract:
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// L2
|
||||
//=======================================================================--
|
||||
{
|
||||
void *pFuncPtr;
|
||||
|
||||
DbgTrace(1, "-GetFunctionPtr- Start\n", 0);
|
||||
|
||||
pFuncPtr = dlsym(libHandle, pFunctionName);
|
||||
if (pFuncPtr == NULL)
|
||||
{
|
||||
DbgTrace(0, "-GetFunctionPtr- Not able to obtain func ptr, error = %d\n", dlerror());
|
||||
}
|
||||
|
||||
DbgTrace(1, "-GetFunctionPtr- End, pFuncPtr = %08X\n", pFuncPtr);
|
||||
|
||||
return pFuncPtr;
|
||||
}
|
||||
|
||||
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
//++=======================================================================
|
||||
|
@ -82,6 +82,11 @@ extern pthread_mutex_t g_hModuleMutex;
|
||||
#define AcquireModuleMutex pthread_mutex_lock(&g_hModuleMutex)
|
||||
#define ReleaseModuleMutex pthread_mutex_unlock(&g_hModuleMutex)
|
||||
|
||||
//
|
||||
// Other definitions
|
||||
//
|
||||
#define LIB_HANDLE void*
|
||||
|
||||
|
||||
//===[ Inlines functions ]===============================================
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user