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:
parent
c973e3647c
commit
af1ddd2db3
@ -38,7 +38,7 @@
|
|||||||
//
|
//
|
||||||
// Debug tracing level
|
// Debug tracing level
|
||||||
//
|
//
|
||||||
int DebugLevel = 3;
|
int DebugLevel = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Operating parameter
|
// Operating parameter
|
||||||
@ -98,6 +98,11 @@ ObtainSessionToken(
|
|||||||
retStatus = pCacheEntry->status;
|
retStatus = pCacheEntry->status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Release auth cache entry reference
|
||||||
|
ReleaseAuthCacheEntry(pCacheEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance to the next entry
|
// Advance to the next entry
|
||||||
@ -196,10 +201,12 @@ ObtainSessionToken(
|
|||||||
pCacheEntry->status = retStatus;
|
pCacheEntry->status = retStatus;
|
||||||
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
|
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// Release the cache entry if the resulting status is not successful
|
||||||
|
if (!CASA_SUCCESS(retStatus))
|
||||||
{
|
{
|
||||||
// Free the entry
|
// Release auth cache entry reference
|
||||||
FreeAuthCacheEntry(pCacheEntry);
|
ReleaseAuthCacheEntry(pCacheEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -213,6 +220,11 @@ ObtainSessionToken(
|
|||||||
// Free up the buffer associated with the authentication mechanism token
|
// Free up the buffer associated with the authentication mechanism token
|
||||||
free(pAuthMechToken);
|
free(pAuthMechToken);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Release auth cache entry reference
|
||||||
|
ReleaseAuthCacheEntry(pCacheEntry);
|
||||||
|
}
|
||||||
|
|
||||||
// Advance to the next entry
|
// Advance to the next entry
|
||||||
pListEntry = pListEntry->Flink;
|
pListEntry = pListEntry->Flink;
|
||||||
@ -235,6 +247,9 @@ ObtainSessionToken(
|
|||||||
CASA_FACILITY_AUTHTOKEN,
|
CASA_FACILITY_AUTHTOKEN,
|
||||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Release auth cache entry reference
|
||||||
|
ReleaseAuthCacheEntry(pCacheEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
DbgTrace(1, "-ObtainSessionToken- End, retStatus = %08X\n", retStatus);
|
DbgTrace(1, "-ObtainSessionToken- End, retStatus = %08X\n", retStatus);
|
||||||
@ -247,8 +262,8 @@ ObtainSessionToken(
|
|||||||
static
|
static
|
||||||
CasaStatus
|
CasaStatus
|
||||||
ObtainAuthTokenFromServer(
|
ObtainAuthTokenFromServer(
|
||||||
IN char *pServiceName,
|
IN const char *pServiceName,
|
||||||
IN char *pHostName,
|
IN const char *pHostName,
|
||||||
INOUT char **ppAuthToken,
|
INOUT char **ppAuthToken,
|
||||||
INOUT int *pTokenLifetime)
|
INOUT int *pTokenLifetime)
|
||||||
//
|
//
|
||||||
@ -514,10 +529,12 @@ ObtainAuthToken(
|
|||||||
pCacheEntry->status = retStatus;
|
pCacheEntry->status = retStatus;
|
||||||
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
|
AddEntryToAuthCache(pCacheEntry, cacheEntryLifetime);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// Release the cache entry if the resulting status is not successful
|
||||||
|
if (!CASA_SUCCESS(retStatus))
|
||||||
{
|
{
|
||||||
// Free the entry
|
// Release auth cache entry reference
|
||||||
FreeAuthCacheEntry(pCacheEntry);
|
ReleaseAuthCacheEntry(pCacheEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -530,8 +547,13 @@ ObtainAuthToken(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Cache entry found, update the return status with the information saved in it.
|
// Cache entry found, update the return status with the information saved in it
|
||||||
retStatus = pCacheEntry->status;
|
// 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
|
// Try to return auth token if we have one to return
|
||||||
@ -556,6 +578,9 @@ ObtainAuthToken(
|
|||||||
|
|
||||||
// Return the token length to the caller
|
// Return the token length to the caller
|
||||||
*pAuthTokenBufLen = tokenLen;
|
*pAuthTokenBufLen = tokenLen;
|
||||||
|
|
||||||
|
// Release auth cache entry reference
|
||||||
|
ReleaseAuthCacheEntry(pCacheEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop user process synchronization
|
// Stop user process synchronization
|
||||||
|
@ -222,19 +222,23 @@ RelGetAuthTokenResp(
|
|||||||
extern
|
extern
|
||||||
AuthCacheEntry*
|
AuthCacheEntry*
|
||||||
CreateAuthCacheEntry(
|
CreateAuthCacheEntry(
|
||||||
IN char *pCacheKey,
|
IN const char *pCacheKey,
|
||||||
IN char *pHostName);
|
IN const char *pHostName);
|
||||||
|
|
||||||
extern
|
extern
|
||||||
void
|
void
|
||||||
FreeAuthCacheEntry(
|
ReleaseAuthCacheEntry(
|
||||||
|
IN AuthCacheEntry *pEntry);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
IncAuthCacheEntryRefCount(
|
||||||
IN AuthCacheEntry *pEntry);
|
IN AuthCacheEntry *pEntry);
|
||||||
|
|
||||||
extern
|
extern
|
||||||
AuthCacheEntry*
|
AuthCacheEntry*
|
||||||
FindEntryInAuthCache(
|
FindEntryInAuthCache(
|
||||||
IN char *pCacheKey,
|
IN const char *pCacheKey,
|
||||||
IN char *pHostName);
|
IN const char *pHostName);
|
||||||
|
|
||||||
extern
|
extern
|
||||||
void
|
void
|
||||||
@ -292,7 +296,7 @@ GetFunctionPtr(
|
|||||||
extern
|
extern
|
||||||
char*
|
char*
|
||||||
NormalizeHostName(
|
NormalizeHostName(
|
||||||
IN char *pHostName);
|
IN const char *pHostName);
|
||||||
|
|
||||||
extern
|
extern
|
||||||
CasaStatus
|
CasaStatus
|
||||||
@ -345,8 +349,8 @@ DecodeData(
|
|||||||
extern
|
extern
|
||||||
int
|
int
|
||||||
dtoul(
|
dtoul(
|
||||||
IN char *cp,
|
IN const char *cp,
|
||||||
IN int len);
|
IN const int len);
|
||||||
|
|
||||||
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
//===[ Global variables ]==================================================
|
//===[ Global variables ]==================================================
|
||||||
|
|
||||||
// Debug Level
|
// Debug Level
|
||||||
int DebugLevel = 2;
|
int DebugLevel = 0;
|
||||||
|
|
||||||
// Tables for Base64 encoding and decoding
|
// Tables for Base64 encoding and decoding
|
||||||
static const int8_t g_Base64[] =
|
static const int8_t g_Base64[] =
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
//===[ Global variables ]==================================================
|
//===[ Global variables ]==================================================
|
||||||
|
|
||||||
// Debug Level
|
// Debug Level
|
||||||
int DebugLevel = 2;
|
int DebugLevel = 0;
|
||||||
|
|
||||||
// Tables for Base64 encoding and decoding
|
// Tables for Base64 encoding and decoding
|
||||||
static const int8_t g_Base64[] =
|
static const int8_t g_Base64[] =
|
||||||
|
@ -276,8 +276,8 @@ DecodeData(
|
|||||||
//++=======================================================================
|
//++=======================================================================
|
||||||
int
|
int
|
||||||
dtoul(
|
dtoul(
|
||||||
IN char *cp,
|
IN const char *cp,
|
||||||
IN int len)
|
IN const int len)
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
|
@ -45,17 +45,21 @@
|
|||||||
//===[ Global variables ]==================================================
|
//===[ Global variables ]==================================================
|
||||||
|
|
||||||
// In memory auth cache list head
|
// In memory auth cache list head
|
||||||
|
static
|
||||||
LIST_ENTRY g_authCacheListHead;
|
LIST_ENTRY g_authCacheListHead;
|
||||||
|
|
||||||
// Non-host specific key name
|
// Non-host specific key name
|
||||||
|
static
|
||||||
char g_allHosts[] = "AllHosts";
|
char g_allHosts[] = "AllHosts";
|
||||||
|
|
||||||
|
static
|
||||||
|
int g_cacheEntryCount = 0;
|
||||||
|
|
||||||
//++=======================================================================
|
//++=======================================================================
|
||||||
AuthCacheEntry*
|
AuthCacheEntry*
|
||||||
CreateAuthCacheEntry(
|
CreateAuthCacheEntry(
|
||||||
IN char *pCacheKeyName,
|
IN const char *pCacheKeyName,
|
||||||
IN char *pHostName)
|
IN const char *pHostName)
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
@ -95,6 +99,12 @@ CreateAuthCacheEntry(
|
|||||||
// Save the names within the entry
|
// Save the names within the entry
|
||||||
strcpy(pEntry->pCacheKeyName, pCacheKeyName);
|
strcpy(pEntry->pCacheKeyName, pCacheKeyName);
|
||||||
strcpy(pEntry->pHostName, pHostName);
|
strcpy(pEntry->pHostName, pHostName);
|
||||||
|
|
||||||
|
// Initialize the entries refCount
|
||||||
|
pEntry->refCount = 1;
|
||||||
|
|
||||||
|
// Increment the cache entry count
|
||||||
|
g_cacheEntryCount ++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -131,6 +141,7 @@ CreateAuthCacheEntry(
|
|||||||
|
|
||||||
|
|
||||||
//++=======================================================================
|
//++=======================================================================
|
||||||
|
static
|
||||||
void
|
void
|
||||||
FreeAuthCacheEntry(
|
FreeAuthCacheEntry(
|
||||||
IN AuthCacheEntry *pEntry)
|
IN AuthCacheEntry *pEntry)
|
||||||
@ -146,7 +157,7 @@ FreeAuthCacheEntry(
|
|||||||
// L2
|
// L2
|
||||||
//=======================================================================--
|
//=======================================================================--
|
||||||
{
|
{
|
||||||
DbgTrace(1, "-FreeAuthCacheEntry- Start\n", 0);
|
DbgTrace(1, "-FreeAuthCacheEntry- Start, pEntry = %08X\n", pEntry);
|
||||||
|
|
||||||
// Free resources associated with the entry
|
// Free resources associated with the entry
|
||||||
if (pEntry->pToken)
|
if (pEntry->pToken)
|
||||||
@ -161,10 +172,65 @@ FreeAuthCacheEntry(
|
|||||||
// Free the entry
|
// Free the entry
|
||||||
free(pEntry);
|
free(pEntry);
|
||||||
|
|
||||||
|
// Decrement the cache entry count
|
||||||
|
g_cacheEntryCount --;
|
||||||
|
|
||||||
DbgTrace(1, "-FreeAuthCacheEntry- End\n", 0);
|
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
|
static
|
||||||
BOOL
|
BOOL
|
||||||
@ -236,8 +302,8 @@ CacheEntryLifetimeExpired(
|
|||||||
//++=======================================================================
|
//++=======================================================================
|
||||||
AuthCacheEntry*
|
AuthCacheEntry*
|
||||||
FindEntryInAuthCache(
|
FindEntryInAuthCache(
|
||||||
IN char *pCacheKeyName,
|
IN const char *pCacheKeyName,
|
||||||
IN char *pHostName)
|
IN const char *pHostName)
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
@ -286,9 +352,9 @@ FindEntryInAuthCache(
|
|||||||
&& CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime))
|
&& CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime))
|
||||||
{
|
{
|
||||||
// The lifetime of the entry has expired, remove it from the in-memory cache
|
// The lifetime of the entry has expired, remove it from the in-memory cache
|
||||||
// and free it.
|
// and release it.
|
||||||
RemoveEntryList(&pWrkEntry->listEntry);
|
RemoveEntryList(&pWrkEntry->listEntry);
|
||||||
FreeAuthCacheEntry(pWrkEntry);
|
ReleaseAuthCacheEntry(pWrkEntry);
|
||||||
}
|
}
|
||||||
else
|
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);
|
DbgTrace(1, "-FindEntryInAuthCache- End, pEntry = %08X\n", pEntry);
|
||||||
|
|
||||||
return pEntry;
|
return pEntry;
|
||||||
@ -550,7 +623,7 @@ AddEntryToAuthCache(
|
|||||||
LONG status;
|
LONG status;
|
||||||
HKEY hCASARegKey;
|
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
|
// Set the time when the entry was added to the cache
|
||||||
pEntry->creationTime = GetTickCount();
|
pEntry->creationTime = GetTickCount();
|
||||||
@ -712,12 +785,9 @@ AddEntryToAuthCache(
|
|||||||
// The entry was added to the cache, save it in
|
// The entry was added to the cache, save it in
|
||||||
// our in-memory cache.
|
// our in-memory cache.
|
||||||
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
|
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
|
||||||
}
|
|
||||||
else
|
// Increment its reference count since we are keeping a reference
|
||||||
{
|
IncAuthCacheEntryRefCount(pEntry);
|
||||||
// Not able to successfully add the entry to the cache,
|
|
||||||
// free the entry.
|
|
||||||
FreeAuthCacheEntry(pEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DbgTrace(1, "-AddEntryToAuthCache- End\n", 0);
|
DbgTrace(1, "-AddEntryToAuthCache- End\n", 0);
|
||||||
|
@ -301,7 +301,7 @@ GetFunctionPtr(
|
|||||||
//++=======================================================================
|
//++=======================================================================
|
||||||
char*
|
char*
|
||||||
NormalizeHostName(
|
NormalizeHostName(
|
||||||
IN char *pHostName)
|
IN const char *pHostName)
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
|
@ -75,6 +75,7 @@ char printBuff[256]; \
|
|||||||
typedef struct _AuthCacheEntry
|
typedef struct _AuthCacheEntry
|
||||||
{
|
{
|
||||||
LIST_ENTRY listEntry;
|
LIST_ENTRY listEntry;
|
||||||
|
int refCount;
|
||||||
DWORD creationTime;
|
DWORD creationTime;
|
||||||
DWORD expirationTime;
|
DWORD expirationTime;
|
||||||
BOOL doesNotExpire;
|
BOOL doesNotExpire;
|
||||||
|
Loading…
Reference in New Issue
Block a user