Moved all synchronization primatives to platform.c and changed the code to allocate and free the user mutex within ObtainAuthToken().

This commit is contained in:
Todd Throne 2006-06-20 23:01:51 +00:00
parent fc7f88c01d
commit 114f934ce9
4 changed files with 172 additions and 40 deletions

View File

@ -38,16 +38,12 @@
//
// Debug tracing level
//
int DebugLevel = -1;
int DebugLevel = 0;
//
// Operating parameter
//
bool secureRpcSetting = false;
// Synchronization mutex for the dll initialization
static
HANDLE g_hInitializationMutex;
bool secureRpcSetting = false;
bool g_bInitialized = FALSE;
//++=======================================================================
@ -478,6 +474,8 @@ ObtainAuthToken(
AuthCacheEntry *pCacheEntry;
char *pNormalizedHostName;
unsigned char *pToken;
HANDLE hUserMutex = NULL;
DbgTrace(1, "-ObtainAuthToken- Start\n", 0);
@ -496,10 +494,10 @@ ObtainAuthToken(
// Make sure we are initialized
// Obtain our synchronization mutex
WaitForSingleObject(g_hInitializationMutex, INFINITE);
AcquireInitializationMutex();
// Create user synchronization mutex
retStatus = CreateUserMutex();
retStatus = CreateUserMutex(&hUserMutex);
if (retStatus != CASA_STATUS_SUCCESS)
{
@ -522,17 +520,14 @@ ObtainAuthToken(
}
// Release our synchronization mutex
if (ReleaseMutex(g_hInitializationMutex) == 0)
{
DbgTrace(0, "-ObtainAuthToken- ReleaseMutex failed, error\n", 0);
}
ReleaseInitializationMutex();
// Normalize the host name
pNormalizedHostName = NormalizeHostName(pHostName);
if (pNormalizedHostName)
{
// Start user process synchronization
AcquireUserMutex();
AcquireUserMutex(hUserMutex);
// Try to find a cache entry for the service
pCacheEntry = FindAuthTokenEntryInCache(pServiceName, pNormalizedHostName);
@ -608,7 +603,7 @@ ObtainAuthToken(
}
// Stop user process synchronization
ReleaseUserMutex();
ReleaseUserMutex(hUserMutex);
// Free the space allocated for the normalized host name
free(pNormalizedHostName);
@ -623,6 +618,11 @@ ObtainAuthToken(
exit:
if (hUserMutex != NULL)
{
DestroyUserMutex(hUserMutex);
}
DbgTrace(1, "-ObtainAuthToken- End, retStatus = %08X\n", retStatus);
return retStatus;
@ -644,19 +644,11 @@ Initialize(void)
// L2
//=======================================================================--
{
int retStatus = -1;
int retStatus;
DbgTrace(1, "-InitializeLibrary- Start\n", 0);
// Create a cache mutex only applicable to the current process
g_hInitializationMutex = CreateMutex(NULL,
FALSE,
NULL);
if (g_hInitializationMutex != NULL)
{
retStatus = CASA_STATUS_SUCCESS;
}
retStatus = CreateInitializationMutex();
DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus);

View File

@ -279,15 +279,39 @@ GetConfigInterface(
extern
CasaStatus
CreateUserMutex(void);
CreateUserMutex(
HANDLE *phMutex
);
extern
void
AcquireUserMutex(void);
AcquireUserMutex(
HANDLE hMutex
);
extern
void
ReleaseUserMutex(void);
ReleaseUserMutex(
HANDLE hMutex
);
extern
void
DestroyUserMutex(
HANDLE hMutex
);
extern
CasaStatus
CreateInitializationMutex(void);
extern
void
AcquireInitializationMutex(void);
extern
void
ReleaseInitializationMutex(void);
extern
LIB_HANDLE

View File

@ -19,7 +19,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include"
AdditionalIncludeDirectories="..\..\..\CASA\include;..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"

View File

@ -45,10 +45,6 @@ typedef struct _NormalizedHostNameCacheEntry
//===[ Global variables ]==================================================
// Global synchronization mutex for the user
static
HANDLE hUserMutex;
// Normalized host name cache list head
static
LIST_ENTRY normalizedHostNameCacheListHead;
@ -60,13 +56,18 @@ HANDLE hNormalizedHostNameCacheMutex;
// Authentication mechanism configuration file folder
char mechConfigFolder[] = "\\Program Files\\Novell\\Casa\\Etc\\Auth\\Mechanisms";
// Synchronization mutex for the dll initialization
static
HANDLE g_hInitializationMutex;
// Path separator
char pathCharString[] = "\\";
//++=======================================================================
CasaStatus
CreateUserMutex(void)
CreateUserMutex(
HANDLE *phMutex
)
//
// Arguments:
//
@ -106,10 +107,10 @@ CreateUserMutex(void)
mutexAttributes.bInheritHandle = TRUE;
if (sprintf(mutexName, "Global\\CASA_Auth_Mutex_%s", pUsername) != -1)
{
hUserMutex = CreateMutex(&mutexAttributes,
*phMutex = CreateMutex(&mutexAttributes,
FALSE,
mutexName);
if (hUserMutex == NULL)
if (*phMutex == NULL)
{
DbgTrace(0, "-CreateUserMutex- CreteMutex failed, error = %d\n", GetLastError());
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
@ -160,7 +161,9 @@ CreateUserMutex(void)
//++=======================================================================
void
AcquireUserMutex(void)
AcquireUserMutex(
HANDLE hMutex
)
//
// Arguments:
//
@ -175,7 +178,7 @@ AcquireUserMutex(void)
{
DbgTrace(2, "-AcquireUserMutex- Start\n", 0);
WaitForSingleObject(hUserMutex, INFINITE);
WaitForSingleObject(hMutex, INFINITE);
DbgTrace(2, "-AcquireUserMutex- End\n", 0);
}
@ -183,7 +186,9 @@ AcquireUserMutex(void)
//++=======================================================================
void
ReleaseUserMutex(void)
ReleaseUserMutex(
HANDLE hMutex
)
//
// Arguments:
//
@ -198,7 +203,7 @@ ReleaseUserMutex(void)
{
DbgTrace(2, "-ReleaseUserMutex- Start\n", 0);
if (ReleaseMutex(hUserMutex) == 0)
if (ReleaseMutex(hMutex) == 0)
{
DbgTrace(0, "-ReleaseUserMutex- ReleaseMutex failed, error = %d\n", GetLastError());
}
@ -207,6 +212,117 @@ ReleaseUserMutex(void)
}
//++=======================================================================
void
DestroyUserMutex(
HANDLE hMutex
)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(2, "-DestroyUserMutex- Start\n", 0);
if (CloseHandle(hMutex) == 0)
{
DbgTrace(0, "-DestroyUserMutex- CloseHandle failed, error = %d\n", GetLastError());
}
DbgTrace(2, "-DestroyUserMutex- End\n", 0);
}
//++=======================================================================
CasaStatus
CreateInitializationMutex(void)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
int retStatus = -1;
DbgTrace(2, "-CreateInitializationMutex- Start\n", 0);
// Create a cache mutex only applicable to the current process
g_hInitializationMutex = CreateMutex(NULL, FALSE, NULL);
if (g_hInitializationMutex != NULL)
{
retStatus = CASA_STATUS_SUCCESS;
}
DbgTrace(2, "-CreateInitializationMutex- End\n", 0);
return retStatus;
}
//++=======================================================================
void
AcquireInitializationMutex(void)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(2, "-AcquireInitializationMutex- Start\n", 0);
WaitForSingleObject(g_hInitializationMutex, INFINITE);
DbgTrace(2, "-AcquireInitializationMutex- End\n", 0);
}
//++=======================================================================
void
ReleaseInitializationMutex(void)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(2, "-ReleaseInitializationMutex- Start\n", 0);
if (ReleaseMutex(g_hInitializationMutex) == 0)
{
DbgTrace(0, "-ReleaseInitializationMutex- ReleaseMutex failed, error\n", 0);
}
DbgTrace(2, "-ReleaseInitializationMutex- End\n", 0);
}
//++=======================================================================
LIB_HANDLE
OpenLibrary(