diff --git a/CASA-auth-token/client/engine.c b/CASA-auth-token/client/engine.c index 7306ddc7..8ecfc68f 100644 --- a/CASA-auth-token/client/engine.c +++ b/CASA-auth-token/client/engine.c @@ -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); diff --git a/CASA-auth-token/client/internal.h b/CASA-auth-token/client/internal.h index 769b5a27..c4588c96 100644 --- a/CASA-auth-token/client/internal.h +++ b/CASA-auth-token/client/internal.h @@ -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 diff --git a/CASA-auth-token/client/test/test.vcproj b/CASA-auth-token/client/test/test.vcproj index f513e4f0..1dda8c43 100644 --- a/CASA-auth-token/client/test/test.vcproj +++ b/CASA-auth-token/client/test/test.vcproj @@ -19,7 +19,7 @@