Changes due to continue development. Switched to using calls to a single Servlet and telling it what method to execute. The test application was also updated to be more flexible.
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#define CASA_AUTH_CACHE_REG_KEY "CASA_Auth_Cache"
|
||||
#define CREATION_TIME_REG_VALUE "CreationTime"
|
||||
#define EXPIRATION_TIME_REG_VALUE "ExpirationTime"
|
||||
#define DOES_NOT_EXPIRE_REG_VALUE "DoesNotExpire"
|
||||
#define STATUS_REG_VALUE "Status"
|
||||
#define TOKEN_REG_VALUE "Token"
|
||||
|
||||
@@ -281,7 +282,8 @@ FindEntryInAuthCache(
|
||||
{
|
||||
// This entry is for the appropriate CacheKeyName, check if it
|
||||
// has not expired.
|
||||
if (CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime))
|
||||
if (pWrkEntry->doesNotExpire == FALSE
|
||||
&& CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime))
|
||||
{
|
||||
// The lifetime of the entry has expired, remove it from the in-memory cache
|
||||
// and free it.
|
||||
@@ -342,6 +344,7 @@ FindEntryInAuthCache(
|
||||
{
|
||||
DWORD creationTime;
|
||||
DWORD expirationTime;
|
||||
BOOL doesNotExpire;
|
||||
BOOL deleteCacheKeyNameKey = TRUE;
|
||||
DWORD variableSz;
|
||||
|
||||
@@ -368,107 +371,124 @@ FindEntryInAuthCache(
|
||||
&variableSz);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
// Check if the extry lifetime has been exceeded
|
||||
if (CacheEntryLifetimeExpired(creationTime, expirationTime) == FALSE)
|
||||
// Read the does not expire
|
||||
variableSz = sizeof(doesNotExpire);
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
EXPIRATION_TIME_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) &doesNotExpire,
|
||||
&variableSz);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
// Create a AuthCacheEntry
|
||||
pEntry = CreateAuthCacheEntry(pCacheKeyName, pHostName);
|
||||
if (pEntry)
|
||||
// Check if the extry lifetime has been exceeded
|
||||
if (doesNotExpire == TRUE
|
||||
|| CacheEntryLifetimeExpired(creationTime, expirationTime) == FALSE)
|
||||
{
|
||||
BOOL entryInitialized = FALSE;
|
||||
|
||||
// Start setting up the AuthCacheEntry
|
||||
pEntry->creationTime = creationTime;
|
||||
pEntry->expirationTime = expirationTime;
|
||||
|
||||
// Read the status
|
||||
variableSz = sizeof(pEntry->status);
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
STATUS_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) &pEntry->status,
|
||||
&variableSz);
|
||||
if (status == ERROR_SUCCESS)
|
||||
// Create a AuthCacheEntry
|
||||
pEntry = CreateAuthCacheEntry(pCacheKeyName, pHostName);
|
||||
if (pEntry)
|
||||
{
|
||||
// Check if there is also an auth token associated with
|
||||
// this entry.
|
||||
if (pEntry->status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
DWORD tokenSz = 0;
|
||||
BOOL entryInitialized = FALSE;
|
||||
|
||||
// There should be an auth token associated with this CacheKeyName,
|
||||
// first determine what size buffer to allocate for it.
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
TOKEN_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) pEntry->pToken,
|
||||
&tokenSz);
|
||||
if (status == ERROR_SUCCESS
|
||||
|| status == ERROR_MORE_DATA)
|
||||
// Start setting up the AuthCacheEntry
|
||||
pEntry->creationTime = creationTime;
|
||||
pEntry->expirationTime = expirationTime;
|
||||
pEntry->doesNotExpire = doesNotExpire;
|
||||
|
||||
// Read the status
|
||||
variableSz = sizeof(pEntry->status);
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
STATUS_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) &pEntry->status,
|
||||
&variableSz);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
// Check if there is also an auth token associated with
|
||||
// this entry.
|
||||
if (pEntry->status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
// Allocate buffer to hold the auth token
|
||||
pEntry->pToken = (char*) malloc(tokenSz);
|
||||
if (pEntry->pToken)
|
||||
DWORD tokenSz = 0;
|
||||
|
||||
// There should be an auth token associated with this CacheKeyName,
|
||||
// first determine what size buffer to allocate for it.
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
TOKEN_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) pEntry->pToken,
|
||||
&tokenSz);
|
||||
if (status == ERROR_SUCCESS
|
||||
|| status == ERROR_MORE_DATA)
|
||||
{
|
||||
// Now read token into the allocated buffer
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
TOKEN_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) pEntry->pToken,
|
||||
&tokenSz);
|
||||
if (status == ERROR_SUCCESS)
|
||||
// Allocate buffer to hold the auth token
|
||||
pEntry->pToken = (char*) malloc(tokenSz);
|
||||
if (pEntry->pToken)
|
||||
{
|
||||
// The cache entry has been properly initialized,
|
||||
// add it to the in-memory cache.
|
||||
entryInitialized = TRUE;
|
||||
deleteCacheKeyNameKey = FALSE;
|
||||
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
|
||||
// Now read token into the allocated buffer
|
||||
status = RegQueryValueExA(hCacheKeyNameRegKey,
|
||||
TOKEN_REG_VALUE,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE) pEntry->pToken,
|
||||
&tokenSz);
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
// The cache entry has been properly initialized,
|
||||
// add it to the in-memory cache.
|
||||
entryInitialized = TRUE;
|
||||
deleteCacheKeyNameKey = FALSE;
|
||||
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading token, status = %d\n", status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading token, status = %d\n", status);
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Unable to allocate buffer for token\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Unable to allocate buffer for token\n", 0);
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading token2, status = %d\n", status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading token2, status = %d\n", status);
|
||||
// There is no auth token associated with this entry
|
||||
//
|
||||
// The cache entry has been properly initialized,
|
||||
// add it to the in-memory cache.
|
||||
entryInitialized = TRUE;
|
||||
deleteCacheKeyNameKey = FALSE;
|
||||
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is no auth token associated with this entry
|
||||
//
|
||||
// The cache entry has been properly initialized,
|
||||
// add it to the in-memory cache.
|
||||
entryInitialized = TRUE;
|
||||
deleteCacheKeyNameKey = FALSE;
|
||||
InsertHeadList(&g_authCacheListHead, &pEntry->listEntry);
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading status, status = %d\n", status);
|
||||
}
|
||||
|
||||
// Free the auth cache entry if it was not successfully initialized
|
||||
if (entryInitialized == FALSE)
|
||||
{
|
||||
FreeAuthCacheEntry(pEntry);
|
||||
pEntry = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading status, status = %d\n", status);
|
||||
}
|
||||
|
||||
// Free the auth cache entry if it was not successfully initialized
|
||||
if (entryInitialized == FALSE)
|
||||
{
|
||||
FreeAuthCacheEntry(pEntry);
|
||||
pEntry = NULL;
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error creating auth cache entry\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error creating auth cache entry\n", 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-FindEntryInAuthCache- Error reading does not expire, status = %d\n", status);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -514,7 +534,7 @@ FindEntryInAuthCache(
|
||||
void
|
||||
AddEntryToAuthCache(
|
||||
IN AuthCacheEntry *pEntry,
|
||||
IN int entryLifetime) // seconds
|
||||
IN int entryLifetime) // seconds (0 == Lives forever)
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
@@ -536,7 +556,17 @@ AddEntryToAuthCache(
|
||||
pEntry->creationTime = GetTickCount();
|
||||
|
||||
// First determine the time when the entry is due to expire
|
||||
pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000);
|
||||
if (entryLifetime != 0)
|
||||
{
|
||||
pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000);
|
||||
pEntry->doesNotExpire = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The entry does not expire
|
||||
pEntry->expirationTime = 0;
|
||||
pEntry->doesNotExpire = TRUE;
|
||||
}
|
||||
|
||||
// Save the entry in our persistent cache (registry)
|
||||
//
|
||||
@@ -594,32 +624,45 @@ AddEntryToAuthCache(
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
status = RegSetValueExA(hCacheKeyNameRegKey,
|
||||
STATUS_REG_VALUE,
|
||||
DOES_NOT_EXPIRE_REG_VALUE,
|
||||
0,
|
||||
REG_DWORD,
|
||||
(LPBYTE) &pEntry->status,
|
||||
sizeof(pEntry->status));
|
||||
(LPBYTE) &pEntry->doesNotExpire,
|
||||
sizeof(pEntry->doesNotExpire));
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
// Check if there is also an auth token associated with this entry
|
||||
// this entry.
|
||||
if (pEntry->status == CASA_STATUS_SUCCESS)
|
||||
status = RegSetValueExA(hCacheKeyNameRegKey,
|
||||
STATUS_REG_VALUE,
|
||||
0,
|
||||
REG_DWORD,
|
||||
(LPBYTE) &pEntry->status,
|
||||
sizeof(pEntry->status));
|
||||
if (status == ERROR_SUCCESS)
|
||||
{
|
||||
status = RegSetValueExA(hCacheKeyNameRegKey,
|
||||
TOKEN_REG_VALUE,
|
||||
0,
|
||||
REG_SZ,
|
||||
(LPBYTE) pEntry->pToken,
|
||||
(DWORD) strlen(pEntry->pToken) + 1);
|
||||
if (status != ERROR_SUCCESS)
|
||||
// Check if there is also an auth token associated with this entry
|
||||
// this entry.
|
||||
if (pEntry->status == CASA_STATUS_SUCCESS)
|
||||
{
|
||||
DbgTrace(0, "-AddEntryToAuthCache- Error setting token, status = %d\n", status);
|
||||
status = RegSetValueExA(hCacheKeyNameRegKey,
|
||||
TOKEN_REG_VALUE,
|
||||
0,
|
||||
REG_SZ,
|
||||
(LPBYTE) pEntry->pToken,
|
||||
(DWORD) strlen(pEntry->pToken) + 1);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
DbgTrace(0, "-AddEntryToAuthCache- Error setting token, status = %d\n", status);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AddEntryToAuthCache- Error setting status, status = %d\n", status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AddEntryToAuthCache- Error setting status, status = %d\n", status);
|
||||
DbgTrace(0, "-AddEntryToAuthCache- Error setting does not expire, status = %d\n", status);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -77,6 +77,7 @@ typedef struct _AuthCacheEntry
|
||||
LIST_ENTRY listEntry;
|
||||
DWORD creationTime;
|
||||
DWORD expirationTime;
|
||||
BOOL doesNotExpire;
|
||||
char *pHostName;
|
||||
char *pCacheKeyName;
|
||||
char *pToken;
|
||||
|
||||
@@ -251,7 +251,7 @@ InternalRpc(
|
||||
*ppResponseData = NULL;
|
||||
|
||||
// Create rpc target string and convert it to a wide string
|
||||
sprintf(rpcTarget, "CasaAuthTokenSvc/%s", pMethod);
|
||||
sprintf(rpcTarget, "CasaAuthTokenSvc/Rpc?method=%s", pMethod);
|
||||
retStatus = CopyMultiToWideAlloc(rpcTarget,
|
||||
(int) strlen(rpcTarget),
|
||||
&pWideRpcTarget,
|
||||
|
||||
Reference in New Issue
Block a user