Added the use of reference counts to determine when AuthCacheEntries can be deleted. This removes the problem of the entries being deleted while in use.

Also fixed some compiler warnings.
This commit is contained in:
Juan Carlos Luciani 2006-05-19 20:10:29 +00:00
parent c973e3647c
commit af1ddd2db3
8 changed files with 138 additions and 38 deletions

View File

@ -38,7 +38,7 @@
//
// Debug tracing level
//
int DebugLevel = 3;
int DebugLevel = 0;
//
// Operating parameter
@ -98,6 +98,11 @@ ObtainSessionToken(
retStatus = pCacheEntry->status;
break;
}
else
{
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
}
// Advance to the next entry
@ -196,10 +201,12 @@ ObtainSessionToken(
pCacheEntry->status = retStatus;
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
}
else
// Release the cache entry if the resulting status is not successful
if (!CASA_SUCCESS(retStatus))
{
// Free the entry
FreeAuthCacheEntry(pCacheEntry);
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
}
else
@ -213,6 +220,11 @@ ObtainSessionToken(
// Free up the buffer associated with the authentication mechanism token
free(pAuthMechToken);
}
else
{
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
// Advance to the next entry
pListEntry = pListEntry->Flink;
@ -235,6 +247,9 @@ ObtainSessionToken(
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_INSUFFICIENT_RESOURCES);
}
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
DbgTrace(1, "-ObtainSessionToken- End, retStatus = %08X\n", retStatus);
@ -247,8 +262,8 @@ ObtainSessionToken(
static
CasaStatus
ObtainAuthTokenFromServer(
IN char *pServiceName,
IN char *pHostName,
IN const char *pServiceName,
IN const char *pHostName,
INOUT char **ppAuthToken,
INOUT int *pTokenLifetime)
//
@ -514,10 +529,12 @@ ObtainAuthToken(
pCacheEntry->status = retStatus;
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
}
else
// Release the cache entry if the resulting status is not successful
if (!CASA_SUCCESS(retStatus))
{
// Free the entry
FreeAuthCacheEntry(pCacheEntry);
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
}
else
@ -530,8 +547,13 @@ ObtainAuthToken(
}
else
{
// Cache entry found, update the return status with the information saved in it.
retStatus = pCacheEntry->status;
// Cache entry found, update the return status with the information saved in it
// and release it if its status is not successful.
if (!CASA_SUCCESS(retStatus = pCacheEntry->status))
{
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
}
// Try to return auth token if we have one to return
@ -556,6 +578,9 @@ ObtainAuthToken(
// Return the token length to the caller
*pAuthTokenBufLen = tokenLen;
// Release auth cache entry reference
ReleaseAuthCacheEntry(pCacheEntry);
}
// Stop user process synchronization

View File

@ -222,19 +222,23 @@ RelGetAuthTokenResp(
extern
AuthCacheEntry*
CreateAuthCacheEntry(
IN char *pCacheKey,
IN char *pHostName);
IN const char *pCacheKey,
IN const char *pHostName);
extern
void
FreeAuthCacheEntry(
ReleaseAuthCacheEntry(
IN AuthCacheEntry *pEntry);
extern void
IncAuthCacheEntryRefCount(
IN AuthCacheEntry *pEntry);
extern
AuthCacheEntry*
FindEntryInAuthCache(
IN char *pCacheKey,
IN char *pHostName);
IN const char *pCacheKey,
IN const char *pHostName);
extern
void
@ -292,7 +296,7 @@ GetFunctionPtr(
extern
char*
NormalizeHostName(
IN char *pHostName);
IN const char *pHostName);
extern
CasaStatus
@ -345,8 +349,8 @@ DecodeData(
extern
int
dtoul(
IN char *cp,
IN int len);
IN const char *cp,
IN const int len);
//=========================================================================

View File

@ -33,7 +33,7 @@
//===[ Global variables ]==================================================
// Debug Level
int DebugLevel = 2;
int DebugLevel = 0;
// Tables for Base64 encoding and decoding
static const int8_t g_Base64[] =

View File

@ -33,7 +33,7 @@
//===[ Global variables ]==================================================
// Debug Level
int DebugLevel = 2;
int DebugLevel = 0;
// Tables for Base64 encoding and decoding
static const int8_t g_Base64[] =

View File

@ -276,8 +276,8 @@ DecodeData(
//++=======================================================================
int
dtoul(
IN char *cp,
IN int len)
IN const char *cp,
IN const int len)
//
// Arguments:
//

View File

@ -45,17 +45,21 @@
//===[ Global variables ]==================================================
// In memory auth cache list head
static
LIST_ENTRY g_authCacheListHead;
// Non-host specific key name
static
char g_allHosts[] = "AllHosts";
static
int g_cacheEntryCount = 0;
//++=======================================================================
AuthCacheEntry*
CreateAuthCacheEntry(
IN char *pCacheKeyName,
IN char *pHostName)
IN const char *pCacheKeyName,
IN const char *pHostName)
//
// Arguments:
//
@ -95,6 +99,12 @@ CreateAuthCacheEntry(
// Save the names within the entry
strcpy(pEntry->pCacheKeyName, pCacheKeyName);
strcpy(pEntry->pHostName, pHostName);
// Initialize the entries refCount
pEntry->refCount = 1;
// Increment the cache entry count
g_cacheEntryCount ++;
}
else
{
@ -131,6 +141,7 @@ CreateAuthCacheEntry(
//++=======================================================================
static
void
FreeAuthCacheEntry(
IN AuthCacheEntry *pEntry)
@ -146,7 +157,7 @@ FreeAuthCacheEntry(
// L2
//=======================================================================--
{
DbgTrace(1, "-FreeAuthCacheEntry- Start\n", 0);
DbgTrace(1, "-FreeAuthCacheEntry- Start, pEntry = %08X\n", pEntry);
// Free resources associated with the entry
if (pEntry->pToken)
@ -161,10 +172,65 @@ FreeAuthCacheEntry(
// Free the entry
free(pEntry);
// Decrement the cache entry count
g_cacheEntryCount --;
DbgTrace(1, "-FreeAuthCacheEntry- End\n", 0);
}
//++=======================================================================
void
ReleaseAuthCacheEntry(
IN AuthCacheEntry *pEntry)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(1, "-ReleaseAuthCacheEntry- Start, pEntry = %08X\n", pEntry);
// Reduce the entries reference count and free it if it goes to zero
pEntry->refCount --;
if (pEntry->refCount == 0)
FreeAuthCacheEntry(pEntry);
DbgTrace(1, "-ReleaseAuthCacheEntry- End\n", 0);
}
//++=======================================================================
void
IncAuthCacheEntryRefCount(
IN AuthCacheEntry *pEntry)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(1, "-IncAuthCacheEntryRefCount- Start, pEntry = %08X\n", pEntry);
// Increase the entries reference count
pEntry->refCount ++;
DbgTrace(1, "-IncAuthCacheEntryRefCount- End\n", 0);
}
//++=======================================================================
static
BOOL
@ -236,8 +302,8 @@ CacheEntryLifetimeExpired(
//++=======================================================================
AuthCacheEntry*
FindEntryInAuthCache(
IN char *pCacheKeyName,
IN char *pHostName)
IN const char *pCacheKeyName,
IN const char *pHostName)
//
// Arguments:
//
@ -286,9 +352,9 @@ FindEntryInAuthCache(
&& CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime))
{
// The lifetime of the entry has expired, remove it from the in-memory cache
// and free it.
// and release it.
RemoveEntryList(&pWrkEntry->listEntry);
FreeAuthCacheEntry(pWrkEntry);
ReleaseAuthCacheEntry(pWrkEntry);
}
else
{
@ -524,6 +590,13 @@ FindEntryInAuthCache(
}
}
// Increment the reference count of entry being returned
if (pEntry)
{
// Increment entries reference count since we are returning it to the caller
IncAuthCacheEntryRefCount(pEntry);
}
DbgTrace(1, "-FindEntryInAuthCache- End, pEntry = %08X\n", pEntry);
return pEntry;
@ -550,7 +623,7 @@ AddEntryToAuthCache(
LONG status;
HKEY hCASARegKey;
DbgTrace(1, "-AddEntryToAuthCache- Start\n", 0);
DbgTrace(1, "-AddEntryToAuthCache- Start, pEntry = %08X\n", pEntry);
// Set the time when the entry was added to the cache
pEntry->creationTime = GetTickCount();
@ -712,12 +785,9 @@ AddEntryToAuthCache(
// The entry was added to the cache, save it in
// our in-memory cache.
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
}
else
{
// Not able to successfully add the entry to the cache,
// free the entry.
FreeAuthCacheEntry(pEntry);
// Increment its reference count since we are keeping a reference
IncAuthCacheEntryRefCount(pEntry);
}
DbgTrace(1, "-AddEntryToAuthCache- End\n", 0);

View File

@ -301,7 +301,7 @@ GetFunctionPtr(
//++=======================================================================
char*
NormalizeHostName(
IN char *pHostName)
IN const char *pHostName)
//
// Arguments:
//

View File

@ -75,6 +75,7 @@ char printBuff[256]; \
typedef struct _AuthCacheEntry
{
LIST_ENTRY listEntry;
int refCount;
DWORD creationTime;
DWORD expirationTime;
BOOL doesNotExpire;