From 3f76e165ad734fb3e7b2496bd77b2981a2e5d6e7 Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Fri, 28 Apr 2006 18:59:15 +0000 Subject: [PATCH] Changes due to continued development effort. --- auth_token/client/win32/cache.c | 46 ++++++++++----- auth_token/client/win32/platform.h | 30 ++++++---- auth_token/client/win32/platutils.c | 39 +++++++------ auth_token/client/win32/rpc.c | 90 +++++++++++++++++++++++------ 4 files changed, 146 insertions(+), 59 deletions(-) diff --git a/auth_token/client/win32/cache.c b/auth_token/client/win32/cache.c index ea8e565d..d718b9fa 100644 --- a/auth_token/client/win32/cache.c +++ b/auth_token/client/win32/cache.c @@ -44,7 +44,10 @@ //===[ Global variables ]================================================== // In memory auth cache list head -LIST_ENTRY authCacheListHead; +LIST_ENTRY g_authCacheListHead; + +// Non-host specific key name +char g_allHosts[] = "AllHosts"; //++======================================================================= @@ -61,13 +64,19 @@ CreateAuthCacheEntry( // // Notes: // -// L1 +// L2 //=======================================================================-- { AuthCacheEntry *pEntry; DbgTrace(1, "-CreateAuthCacheEntry- Start\n", 0); + // Use allHosts if a host name was not specified + if (pHostName == NULL) + { + pHostName = g_allHosts; + } + // Allocate space for the entry pEntry = (AuthCacheEntry*) malloc(sizeof(*pEntry)); if (pEntry) @@ -133,7 +142,7 @@ FreeAuthCacheEntry( // // Notes: // -// L1 +// L2 //=======================================================================-- { DbgTrace(1, "-FreeAuthCacheEntry- Start\n", 0); @@ -170,7 +179,7 @@ CacheEntryLifetimeExpired( // // Notes: // -// L1 +// L2 //=======================================================================-- { DWORD currentTime = GetTickCount(); @@ -237,7 +246,7 @@ FindEntryInAuthCache( // // Notes: // -// L1 +// L2 //=======================================================================-- { AuthCacheEntry *pEntry = NULL; @@ -248,9 +257,15 @@ FindEntryInAuthCache( // Examine the cache, if entry found then check if it has expired // in which case we would want to remove it from the cache. + // Use allHosts if a host name was not specified + if (pHostName == NULL) + { + pHostName = g_allHosts; + } + // First look through the entries in our in-memory cache - pListEntry = authCacheListHead.Flink; - while (pListEntry != &authCacheListHead) + pListEntry = g_authCacheListHead.Flink; + while (pListEntry != &g_authCacheListHead) { AuthCacheEntry *pWrkEntry; @@ -410,7 +425,7 @@ FindEntryInAuthCache( // add it to the in-memory cache. entryInitialized = TRUE; deleteCacheKeyNameKey = FALSE; - InsertHeadList(&authCacheListHead, &pEntry->listEntry); + InsertHeadList(&g_authCacheListHead, &pEntry->listEntry); } else { @@ -435,7 +450,7 @@ FindEntryInAuthCache( // add it to the in-memory cache. entryInitialized = TRUE; deleteCacheKeyNameKey = FALSE; - InsertHeadList(&authCacheListHead, &pEntry->listEntry); + InsertHeadList(&g_authCacheListHead, &pEntry->listEntry); } } else @@ -509,7 +524,7 @@ AddEntryToAuthCache( // // Notes: // -// L1 +// L2 //=======================================================================-- { LONG status; @@ -653,7 +668,7 @@ AddEntryToAuthCache( { // The entry was added to the cache, save it in // our in-memory cache. - InsertHeadList(&authCacheListHead, &pEntry->listEntry); + InsertHeadList(&g_authCacheListHead, &pEntry->listEntry); } else { @@ -678,7 +693,7 @@ InitializeAuthCache(void) // // Notes: // -// L1 +// L2 //=======================================================================-- { CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, @@ -690,7 +705,7 @@ InitializeAuthCache(void) DbgTrace(1, "-InitializeAuthCache- Start\n", 0); // Initialize the cache list head - InitializeListHead(&authCacheListHead); + InitializeListHead(&g_authCacheListHead); // Lets create the CASA Auth Cache registry key in the // user's hive and limit access to it. @@ -873,3 +888,8 @@ InitializeAuthCache(void) return retStatus; } + +//++======================================================================= +//++======================================================================= +//++======================================================================= + diff --git a/auth_token/client/win32/platform.h b/auth_token/client/win32/platform.h index 25d60544..50059975 100644 --- a/auth_token/client/win32/platform.h +++ b/auth_token/client/win32/platform.h @@ -44,18 +44,24 @@ // // DbgTrace macro define // -#define DbgTrace(LEVEL, X, Y) { \ -char printBuff[256]; \ - if (LEVEL == 0) \ - { \ - _snprintf(printBuff, sizeof(printBuff), X, Y); \ - printf("AuthToken %s", printBuff); \ - } \ - else if (DebugLevel >= LEVEL) \ - { \ - _snprintf(printBuff, sizeof(printBuff), X, Y); \ - printf("AuthToken %s", printBuff); \ - } \ +//#define DbgTrace(LEVEL, X, Y) { \ +//char printBuff[256]; \ +// if (LEVEL == 0 || DebugLevel >= LEVEL) \ +// { \ +// _snprintf(printBuff, sizeof(printBuff), X, Y); \ +// printf("AuthToken %s", printBuff); \ +// } \ +//} +#define DbgTrace(LEVEL, X, Y) { \ +char formatBuff[128]; \ +char printBuff[256]; \ + if (LEVEL == 0 || DebugLevel >= LEVEL) \ + { \ + strcpy(formatBuff, "AuthToken "); \ + strncat(formatBuff, X, sizeof(formatBuff) - 10); \ + _snprintf(printBuff, sizeof(printBuff), formatBuff, Y); \ + OutputDebugString(printBuff); \ + } \ } diff --git a/auth_token/client/win32/platutils.c b/auth_token/client/win32/platutils.c index 1a6abb4d..7ffc0fb3 100644 --- a/auth_token/client/win32/platutils.c +++ b/auth_token/client/win32/platutils.c @@ -76,7 +76,7 @@ CreateUserMutex(void) // // Notes: // -// L1 +// L2 //=======================================================================-- { CasaStatus retStatus = CASA_STATUS_SUCCESS; @@ -99,8 +99,6 @@ CreateUserMutex(void) SECURITY_ATTRIBUTES mutexAttributes; char mutexName[256]; - //printf("\nUsername is %s", pUsername); - // Now lets create a global semaphore for the // user and allow its handle to be inherited. mutexAttributes.nLength = sizeof(mutexAttributes); @@ -162,7 +160,7 @@ CreateUserMutex(void) //++======================================================================= void -LockUserMutex(void) +AcquireUserMutex(void) // // Arguments: // @@ -172,20 +170,20 @@ LockUserMutex(void) // // Notes: // -// L1 +// L2 //=======================================================================-- { - DbgTrace(2, "-LockUserMutex- Start\n", 0); + DbgTrace(2, "-AcquireUserMutex- Start\n", 0); WaitForSingleObject(hUserMutex, INFINITE); - DbgTrace(2, "-LockUserMutex- End\n", 0); + DbgTrace(2, "-AcquireUserMutex- End\n", 0); } //++======================================================================= void -FreeUserMutex(void) +ReleaseUserMutex(void) // // Arguments: // @@ -195,17 +193,17 @@ FreeUserMutex(void) // // Notes: // -// L1 +// L2 //=======================================================================-- { - DbgTrace(2, "-FreeUserMutex- Start\n", 0); + DbgTrace(2, "-ReleaseUserMutex- Start\n", 0); if (ReleaseMutex(hUserMutex) == 0) { - DbgTrace(0, "-FreeUserMutex- ReleaseMutex failed, error = %d\n", GetLastError()); + DbgTrace(0, "-ReleaseUserMutex- ReleaseMutex failed, error = %d\n", GetLastError()); } - DbgTrace(2, "-FreeUserMutex- End\n", 0); + DbgTrace(2, "-ReleaseUserMutex- End\n", 0); } @@ -222,7 +220,7 @@ OpenLibrary( // // Notes: // -// L0 +// L2 //=======================================================================-- { LIB_HANDLE libHandle; @@ -255,7 +253,7 @@ CloseLibrary( // // Notes: // -// L0 +// L2 //=======================================================================-- { DbgTrace(1, "-CloseLibrary- Start\n", 0); @@ -280,11 +278,12 @@ GetFunctionPtr( // // Notes: // -// L0 +// L2 //=======================================================================-- { void *pFuncPtr; + DbgTrace(1, "-GetFunctionPtr- Start\n", 0); pFuncPtr = GetProcAddress(libHandle, pFunctionName); @@ -312,13 +311,14 @@ NormalizeHostName( // // Notes: // -// L1 +// L2 //=======================================================================-- { char *pNormalizedName = NULL; LIST_ENTRY *pListEntry; NormalizedHostNameCacheEntry *pEntry = NULL; + DbgTrace(1, "-NormalizeHostName- Start\n", 0); // Obtain our synchronization mutex @@ -502,7 +502,7 @@ InitializeHostNameNormalization(void) // // Notes: // -// L1 +// L2 //=======================================================================-- { CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, @@ -542,3 +542,8 @@ InitializeHostNameNormalization(void) return retStatus; } + +//++======================================================================= +//++======================================================================= +//++======================================================================= + diff --git a/auth_token/client/win32/rpc.c b/auth_token/client/win32/rpc.c index d64fc029..6e067076 100644 --- a/auth_token/client/win32/rpc.c +++ b/auth_token/client/win32/rpc.c @@ -32,6 +32,8 @@ #define INITIAL_RESPONSE_DATA_BUF_SIZE 1028 #define INCREMENT_RESPONSE_DATA_BUF_SIZE 256 +#define MAX_RPC_RETRIES 3 + //===[ Function prototypes ]=============================================== //===[ Global variables ]================================================== @@ -54,12 +56,13 @@ CopyMultiToWideAlloc( // // Notes: // -// L0 +// L2 //=======================================================================-- { int retStatus; int size, i; + DbgTrace(2, "-CopyMultiToWideAlloc- Start\n", 0); size = (multiSize + 1) * sizeof(WCHAR); @@ -106,11 +109,12 @@ OpenRpcSession( // // Notes: // -// L0 +// L2 //=======================================================================-- { RpcSession *pSession; + DbgTrace(1, "-OpenRpcSession- Start\n", 0); // Allocate space for the session @@ -195,7 +199,7 @@ CloseRpcSession( // // Notes: // -// L0 +// L2 //=======================================================================-- { DbgTrace(1, "-CloseRpcSession- Start\n", 0); @@ -214,8 +218,9 @@ CloseRpcSession( //++======================================================================= +static CasaStatus -Rpc( +InternalRpc( IN RpcSession *pSession, IN char *pMethod, IN bool secure, @@ -231,7 +236,7 @@ Rpc( // // Notes: // -// L0 +// L2 //=======================================================================-- { CasaStatus retStatus = CASA_STATUS_SUCCESS; @@ -240,7 +245,7 @@ Rpc( int wideRpcTargetLen; WCHAR sendHeaders[] = L"Content-Type: text/html"; - DbgTrace(1, "-Rpc- Start\n", 0); + DbgTrace(1, "-InternalRpc- Start\n", 0); // Initialize output parameter *ppResponseData = NULL; @@ -255,8 +260,6 @@ Rpc( { HINTERNET hRequest; - // tbd - Add retry capability - // Open a request handle hRequest = WinHttpOpenRequest(pSession->hConnection, L"POST", @@ -334,7 +337,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Buffer allocation failure\n", 0); + DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_INSUFFICIENT_RESOURCES); @@ -343,7 +346,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Failed reading response data, error = %d\n", GetLastError()); + DbgTrace(0, "-InternalRpc- Failed reading response data, error = %d\n", GetLastError()); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_UNSUCCESSFUL); @@ -366,7 +369,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Buffer allocation failure\n", 0); + DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_INSUFFICIENT_RESOURCES); @@ -374,7 +377,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- HTTP request did not complete successfully, status = %S\n", httpCompStatus); + DbgTrace(0, "-InternalRpc- HTTP request did not complete successfully, status = %S\n", httpCompStatus); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_UNSUCCESSFUL); @@ -382,7 +385,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Unable to obtain http request completion status, error = %d\n", GetLastError()); + DbgTrace(0, "-InternalRpc- Unable to obtain http request completion status, error = %d\n", GetLastError()); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_UNSUCCESSFUL); @@ -390,7 +393,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Unable to receive response, error = %d\n", GetLastError()); + DbgTrace(0, "-InternalRpc- Unable to receive response, error = %d\n", GetLastError()); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_UNSUCCESSFUL); @@ -400,7 +403,7 @@ Rpc( { int error = GetLastError(); - DbgTrace(0, "-Rpc- Unsuccessful send http request, error = %d\n", error); + DbgTrace(0, "-InternalRpc- Unsuccessful send http request, error = %d\n", error); if (error == ERROR_WINHTTP_CANNOT_CONNECT) { retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, @@ -420,7 +423,7 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Unable to open http request, error = %d\n", GetLastError()); + DbgTrace(0, "-InternalRpc- Unable to open http request, error = %d\n", GetLastError()); retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CASA_FACILITY_AUTHTOKEN, CASA_STATUS_UNSUCCESSFUL); @@ -431,12 +434,65 @@ Rpc( } else { - DbgTrace(0, "-Rpc- Error converting method name to wide string\n", 0); + DbgTrace(0, "-InternalRpc- Error converting method name to wide string\n", 0); } + DbgTrace(1, "-InternalRpc- End, retStatus = %d\n", retStatus); + + return retStatus; +} + + +//++======================================================================= +CasaStatus +Rpc( + IN RpcSession *pSession, + IN char *pMethod, + IN bool secure, + IN char *pRequestData, + INOUT char **ppResponseData, + INOUT int *pResponseDataLen) +// +// Arguments: +// +// Returns: +// +// Abstract: +// +// Notes: +// +// L2 +//=======================================================================-- +{ + CasaStatus retStatus; + int retries = 0; + + DbgTrace(1, "-Rpc- Start\n", 0); + + // Retry the RPC as needed + do + { + // Issue the RPC + retStatus = InternalRpc(pSession, + pMethod, + secure, + pRequestData, + ppResponseData, + pResponseDataLen); + + // Account for this try + retries ++; + + } while (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE + && retries < MAX_RPC_RETRIES); + DbgTrace(1, "-Rpc- End, retStatus = %d\n", retStatus); return retStatus; } +//++======================================================================= +//++======================================================================= +//++======================================================================= +