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:
		| @@ -38,16 +38,12 @@ | |||||||
| // | // | ||||||
| // Debug tracing level | // Debug tracing level | ||||||
| //  | //  | ||||||
| int   DebugLevel = -1; | int   DebugLevel = 0; | ||||||
|  |  | ||||||
| // | // | ||||||
| // Operating parameter | // Operating parameter | ||||||
| //  | //  | ||||||
| bool  secureRpcSetting = false; | bool	secureRpcSetting = false; | ||||||
|  |  | ||||||
| // Synchronization mutex for the dll initialization |  | ||||||
| static |  | ||||||
| HANDLE  g_hInitializationMutex; |  | ||||||
| bool	g_bInitialized = FALSE; | bool	g_bInitialized = FALSE; | ||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| @@ -478,6 +474,8 @@ ObtainAuthToken( | |||||||
|    AuthCacheEntry    *pCacheEntry; |    AuthCacheEntry    *pCacheEntry; | ||||||
|    char              *pNormalizedHostName; |    char              *pNormalizedHostName; | ||||||
|    unsigned char	 *pToken; |    unsigned char	 *pToken; | ||||||
|  |    HANDLE            hUserMutex = NULL; | ||||||
|  |  | ||||||
|  |  | ||||||
|    DbgTrace(1, "-ObtainAuthToken- Start\n", 0); |    DbgTrace(1, "-ObtainAuthToken- Start\n", 0); | ||||||
|  |  | ||||||
| @@ -496,10 +494,10 @@ ObtainAuthToken( | |||||||
|  |  | ||||||
|    // Make sure we are initialized |    // Make sure we are initialized | ||||||
|    // Obtain our synchronization mutex |    // Obtain our synchronization mutex | ||||||
|    WaitForSingleObject(g_hInitializationMutex, INFINITE); |    AcquireInitializationMutex(); | ||||||
|  |  | ||||||
|    // Create user synchronization mutex |    // Create user synchronization mutex | ||||||
|    retStatus = CreateUserMutex(); |    retStatus = CreateUserMutex(&hUserMutex); | ||||||
|  |  | ||||||
|    if (retStatus != CASA_STATUS_SUCCESS) |    if (retStatus != CASA_STATUS_SUCCESS) | ||||||
|    { |    { | ||||||
| @@ -522,17 +520,14 @@ ObtainAuthToken( | |||||||
|    } |    } | ||||||
|  |  | ||||||
|    // Release our synchronization mutex |    // Release our synchronization mutex | ||||||
|    if (ReleaseMutex(g_hInitializationMutex) == 0) |    ReleaseInitializationMutex(); | ||||||
|    { |  | ||||||
| 	  DbgTrace(0, "-ObtainAuthToken- ReleaseMutex failed, error\n", 0); |  | ||||||
|    } |  | ||||||
|  |  | ||||||
|    // Normalize the host name |    // Normalize the host name | ||||||
|    pNormalizedHostName = NormalizeHostName(pHostName); |    pNormalizedHostName = NormalizeHostName(pHostName); | ||||||
|    if (pNormalizedHostName) |    if (pNormalizedHostName) | ||||||
|    { |    { | ||||||
|       // Start user process synchronization |       // Start user process synchronization | ||||||
|       AcquireUserMutex(); |       AcquireUserMutex(hUserMutex); | ||||||
|  |  | ||||||
|       // Try to find a cache entry for the service |       // Try to find a cache entry for the service | ||||||
|       pCacheEntry = FindAuthTokenEntryInCache(pServiceName, pNormalizedHostName); |       pCacheEntry = FindAuthTokenEntryInCache(pServiceName, pNormalizedHostName); | ||||||
| @@ -608,7 +603,7 @@ ObtainAuthToken( | |||||||
|       } |       } | ||||||
|  |  | ||||||
|       // Stop user process synchronization |       // Stop user process synchronization | ||||||
|       ReleaseUserMutex(); |       ReleaseUserMutex(hUserMutex); | ||||||
|  |  | ||||||
|       // Free the space allocated for the normalized host name |       // Free the space allocated for the normalized host name | ||||||
|       free(pNormalizedHostName); |       free(pNormalizedHostName); | ||||||
| @@ -623,6 +618,11 @@ ObtainAuthToken( | |||||||
|  |  | ||||||
| exit: | exit: | ||||||
|  |  | ||||||
|  |    if (hUserMutex != NULL) | ||||||
|  |    { | ||||||
|  | 	  DestroyUserMutex(hUserMutex); | ||||||
|  |    } | ||||||
|  |  | ||||||
|    DbgTrace(1, "-ObtainAuthToken- End, retStatus = %08X\n", retStatus); |    DbgTrace(1, "-ObtainAuthToken- End, retStatus = %08X\n", retStatus); | ||||||
|  |  | ||||||
|    return retStatus; |    return retStatus; | ||||||
| @@ -644,19 +644,11 @@ Initialize(void) | |||||||
| // L2 | // L2 | ||||||
| //=======================================================================-- | //=======================================================================-- | ||||||
| { | { | ||||||
|    int   retStatus = -1; |    int   retStatus; | ||||||
|  |  | ||||||
|    DbgTrace(1, "-InitializeLibrary- Start\n", 0); |    DbgTrace(1, "-InitializeLibrary- Start\n", 0); | ||||||
|  |  | ||||||
|    // Create a cache mutex only applicable to the current process |    retStatus = CreateInitializationMutex(); | ||||||
|    g_hInitializationMutex = CreateMutex(NULL, |  | ||||||
| 										FALSE, |  | ||||||
| 										NULL); |  | ||||||
|  |  | ||||||
|    if (g_hInitializationMutex != NULL) |  | ||||||
|    { |  | ||||||
| 	  retStatus = CASA_STATUS_SUCCESS; |  | ||||||
|    } |  | ||||||
|  |  | ||||||
|    DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus); |    DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -279,15 +279,39 @@ GetConfigInterface( | |||||||
|  |  | ||||||
| extern | extern | ||||||
| CasaStatus | CasaStatus | ||||||
| CreateUserMutex(void); | CreateUserMutex( | ||||||
|  |    HANDLE *phMutex | ||||||
|  |    ); | ||||||
|  |  | ||||||
| extern | extern | ||||||
| void | void | ||||||
| AcquireUserMutex(void); | AcquireUserMutex( | ||||||
|  |    HANDLE hMutex | ||||||
|  |    ); | ||||||
|  |  | ||||||
| extern | extern | ||||||
| void | void | ||||||
| ReleaseUserMutex(void); | ReleaseUserMutex( | ||||||
|  |    HANDLE hMutex | ||||||
|  |    ); | ||||||
|  |  | ||||||
|  | extern | ||||||
|  | void | ||||||
|  | DestroyUserMutex( | ||||||
|  |    HANDLE hMutex | ||||||
|  |    ); | ||||||
|  |  | ||||||
|  | extern | ||||||
|  | CasaStatus | ||||||
|  | CreateInitializationMutex(void); | ||||||
|  |  | ||||||
|  | extern | ||||||
|  | void | ||||||
|  | AcquireInitializationMutex(void); | ||||||
|  |  | ||||||
|  | extern | ||||||
|  | void | ||||||
|  | ReleaseInitializationMutex(void); | ||||||
|  |  | ||||||
| extern | extern | ||||||
| LIB_HANDLE | LIB_HANDLE | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ | |||||||
| 			<Tool | 			<Tool | ||||||
| 				Name="VCCLCompilerTool" | 				Name="VCCLCompilerTool" | ||||||
| 				Optimization="0" | 				Optimization="0" | ||||||
| 				AdditionalIncludeDirectories="..\..\..\include" | 				AdditionalIncludeDirectories="..\..\..\CASA\include;..\..\include" | ||||||
| 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" | 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" | ||||||
| 				MinimalRebuild="TRUE" | 				MinimalRebuild="TRUE" | ||||||
| 				BasicRuntimeChecks="3" | 				BasicRuntimeChecks="3" | ||||||
|   | |||||||
| @@ -45,10 +45,6 @@ typedef struct _NormalizedHostNameCacheEntry | |||||||
|  |  | ||||||
| //===[ Global variables ]================================================== | //===[ Global variables ]================================================== | ||||||
|  |  | ||||||
| // Global synchronization mutex for the user |  | ||||||
| static |  | ||||||
| HANDLE   hUserMutex; |  | ||||||
|  |  | ||||||
| // Normalized host name cache list head | // Normalized host name cache list head | ||||||
| static | static | ||||||
| LIST_ENTRY  normalizedHostNameCacheListHead; | LIST_ENTRY  normalizedHostNameCacheListHead; | ||||||
| @@ -60,13 +56,18 @@ HANDLE   hNormalizedHostNameCacheMutex; | |||||||
| // Authentication mechanism configuration file folder | // Authentication mechanism configuration file folder | ||||||
| char  mechConfigFolder[] = "\\Program Files\\Novell\\Casa\\Etc\\Auth\\Mechanisms"; | char  mechConfigFolder[] = "\\Program Files\\Novell\\Casa\\Etc\\Auth\\Mechanisms"; | ||||||
|  |  | ||||||
|  | // Synchronization mutex for the dll initialization | ||||||
|  | static | ||||||
|  | HANDLE  g_hInitializationMutex; | ||||||
|  |  | ||||||
| // Path separator | // Path separator | ||||||
| char  pathCharString[] = "\\"; | char  pathCharString[] = "\\"; | ||||||
|  |  | ||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| CasaStatus | CasaStatus | ||||||
| CreateUserMutex(void) | CreateUserMutex( | ||||||
|  |    HANDLE *phMutex | ||||||
|  |    ) | ||||||
| // | // | ||||||
| //  Arguments:  | //  Arguments:  | ||||||
| // | // | ||||||
| @@ -106,10 +107,10 @@ CreateUserMutex(void) | |||||||
|             mutexAttributes.bInheritHandle = TRUE; |             mutexAttributes.bInheritHandle = TRUE; | ||||||
|             if (sprintf(mutexName, "Global\\CASA_Auth_Mutex_%s", pUsername) != -1) |             if (sprintf(mutexName, "Global\\CASA_Auth_Mutex_%s", pUsername) != -1) | ||||||
|             { |             { | ||||||
|                hUserMutex = CreateMutex(&mutexAttributes, |                *phMutex = CreateMutex(&mutexAttributes, | ||||||
|                                         FALSE, |                                         FALSE, | ||||||
|                                         mutexName); |                                         mutexName); | ||||||
|                if (hUserMutex == NULL) |                if (*phMutex == NULL) | ||||||
|                { |                { | ||||||
|                   DbgTrace(0, "-CreateUserMutex- CreteMutex failed, error = %d\n", GetLastError()); |                   DbgTrace(0, "-CreateUserMutex- CreteMutex failed, error = %d\n", GetLastError()); | ||||||
|                   retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, |                   retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||||
| @@ -160,7 +161,9 @@ CreateUserMutex(void) | |||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| void | void | ||||||
| AcquireUserMutex(void) | AcquireUserMutex( | ||||||
|  |    HANDLE hMutex | ||||||
|  |    ) | ||||||
| // | // | ||||||
| //  Arguments:  | //  Arguments:  | ||||||
| // | // | ||||||
| @@ -175,7 +178,7 @@ AcquireUserMutex(void) | |||||||
| { | { | ||||||
|    DbgTrace(2, "-AcquireUserMutex- Start\n", 0); |    DbgTrace(2, "-AcquireUserMutex- Start\n", 0); | ||||||
|  |  | ||||||
|    WaitForSingleObject(hUserMutex, INFINITE); |    WaitForSingleObject(hMutex, INFINITE); | ||||||
|  |  | ||||||
|    DbgTrace(2, "-AcquireUserMutex- End\n", 0); |    DbgTrace(2, "-AcquireUserMutex- End\n", 0); | ||||||
| } | } | ||||||
| @@ -183,7 +186,9 @@ AcquireUserMutex(void) | |||||||
|  |  | ||||||
| //++======================================================================= | //++======================================================================= | ||||||
| void | void | ||||||
| ReleaseUserMutex(void) | ReleaseUserMutex( | ||||||
|  |    HANDLE hMutex | ||||||
|  |    ) | ||||||
| // | // | ||||||
| //  Arguments:  | //  Arguments:  | ||||||
| // | // | ||||||
| @@ -198,7 +203,7 @@ ReleaseUserMutex(void) | |||||||
| { | { | ||||||
|    DbgTrace(2, "-ReleaseUserMutex- Start\n", 0); |    DbgTrace(2, "-ReleaseUserMutex- Start\n", 0); | ||||||
|  |  | ||||||
|    if (ReleaseMutex(hUserMutex) == 0) |    if (ReleaseMutex(hMutex) == 0) | ||||||
|    { |    { | ||||||
|       DbgTrace(0, "-ReleaseUserMutex- ReleaseMutex failed, error = %d\n", GetLastError()); |       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 | LIB_HANDLE | ||||||
| OpenLibrary( | OpenLibrary( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user