This branch was created to contain the "native" auth_token components.
This was required because autobuild restrictions are forcing us to build the native components separate from the java components.
This commit is contained in:
		
							
								
								
									
										10
									
								
								CASA-auth-token/native/client/windows/authtoken.def
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								CASA-auth-token/native/client/windows/authtoken.def
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| LIBRARY         AUTHTOKEN | ||||
| DESCRIPTION     'CASA Authentication Token Library.' | ||||
|  | ||||
|  | ||||
| EXPORTS | ||||
| ;                DllRegisterServer   PRIVATE | ||||
| ;                DllUnregisterServer PRIVATE | ||||
| ;                DllGetClassObject   PRIVATE | ||||
|                 ObtainAuthToken     PRIVATE         | ||||
| ;               DllCanUnloadNow     PRIVATE   | ||||
							
								
								
									
										1091
									
								
								CASA-auth-token/native/client/windows/cache.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1091
									
								
								CASA-auth-token/native/client/windows/cache.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										132
									
								
								CASA-auth-token/native/client/windows/dllsup.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								CASA-auth-token/native/client/windows/dllsup.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,132 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  Copyright (C) 2006 Novell, Inc. All Rights Reserved. | ||||
|  * | ||||
|  *  This library is free software; you can redistribute it and/or | ||||
|  *  modify it under the terms of the GNU Lesser General Public | ||||
|  *  License as published by the Free Software Foundation; version 2.1 | ||||
|  *  of the License. | ||||
|  * | ||||
|  *  This library is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
|  *  Library Lesser General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Lesser General Public | ||||
|  *  License along with this library; if not, Novell, Inc. | ||||
|  *  | ||||
|  *  To contact Novell about this file by physical or electronic mail,  | ||||
|  *  you may find current contact information at www.novell.com. | ||||
|  *  | ||||
|  *  Author: Juan Carlos Luciani <jluciani@novell.com> | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
| //===[ Include files ]===================================================== | ||||
|  | ||||
| #include "internal.h" | ||||
|  | ||||
| //===[ External data ]===================================================== | ||||
|  | ||||
| //===[ Manifest constants ]================================================ | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
| UINT32 g_ulCount  = 0; | ||||
| UINT32 g_ulLock = 0; | ||||
| HANDLE g_hModule; | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| BOOL APIENTRY DllMain( | ||||
|    HANDLE hModule, | ||||
|    DWORD  ul_reason_for_call, | ||||
|    LPVOID lpReserved    | ||||
|    ) | ||||
| //=======================================================================-- | ||||
| { | ||||
|    BOOL  retStatus = TRUE; | ||||
|  | ||||
|    switch (ul_reason_for_call) | ||||
|    { | ||||
|       case DLL_PROCESS_ATTACH: | ||||
|       { | ||||
|          g_hModule = hModule; | ||||
|  | ||||
|          // Initialize the library | ||||
|          if (InitializeLibrary() != 0) | ||||
|          { | ||||
|             // Failed to initialize the library | ||||
|             OutputDebugString("CASAAUTH -DllMain- Library initialization failed\n"); | ||||
|             retStatus = FALSE; | ||||
|          } | ||||
|          break; | ||||
|       } | ||||
|  | ||||
|       case DLL_THREAD_ATTACH: | ||||
|       { | ||||
|          g_hModule = hModule; | ||||
|          break; | ||||
|       } | ||||
|  | ||||
|       case DLL_THREAD_DETACH: | ||||
|          break; | ||||
|  | ||||
|       case DLL_PROCESS_DETACH: | ||||
|       { | ||||
|          /* Don't uninitialize on windows | ||||
|          tbd | ||||
|          */ | ||||
|          break; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return retStatus; | ||||
| } | ||||
|  | ||||
| //++======================================================================= | ||||
| // | ||||
| // DllCanUnloadNow | ||||
| // | ||||
| // Synopsis | ||||
| // | ||||
| // | ||||
| STDAPI | ||||
| DllCanUnloadNow() | ||||
| // | ||||
| // Input Arguments | ||||
| // | ||||
| // Ouput Arguments | ||||
| // | ||||
| // Return Value | ||||
| //    S_OK    The DLL can be unloaded. | ||||
| //    S_FALSE The DLL cannot be unloaded now. | ||||
| // | ||||
| // Description | ||||
| //    An Exported Function. | ||||
| //    DLLs that support the OLE Component Object Model (COM) should implement | ||||
| //    and export DllCanUnloadNow. | ||||
| //    A call to DllCanUnloadNow determines whether the DLL from which it is | ||||
| //    exported is still in use. A DLL is no longer in use when it is not | ||||
| //    managing  any existing objects (the reference count on all of its objects | ||||
| //    is 0). | ||||
| //    DllCanUnloadNow returns S_FALSE if there are any existing references to | ||||
| //    objects that the DLL manages. | ||||
| // | ||||
| // Environment | ||||
| // | ||||
| // See Also | ||||
| // | ||||
| //=======================================================================-- | ||||
| { | ||||
|    // tbd | ||||
|    return ((g_ulCount == 0 && g_ulLock == 0) ? S_OK : S_FALSE); | ||||
| } | ||||
|  | ||||
| //========================================================================= | ||||
| //========================================================================= | ||||
|  | ||||
							
								
								
									
										549
									
								
								CASA-auth-token/native/client/windows/platform.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										549
									
								
								CASA-auth-token/native/client/windows/platform.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,549 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  Copyright (C) 2006 Novell, Inc. All Rights Reserved. | ||||
|  * | ||||
|  *  This library is free software; you can redistribute it and/or | ||||
|  *  modify it under the terms of the GNU Lesser General Public | ||||
|  *  License as published by the Free Software Foundation; version 2.1 | ||||
|  *  of the License. | ||||
|  * | ||||
|  *  This library is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
|  *  Library Lesser General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Lesser General Public | ||||
|  *  License along with this library; if not, Novell, Inc. | ||||
|  *  | ||||
|  *  To contact Novell about this file by physical or electronic mail,  | ||||
|  *  you may find current contact information at www.novell.com. | ||||
|  *  | ||||
|  *  Author: Juan Carlos Luciani <jluciani@novell.com> | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
| //===[ Include files ]===================================================== | ||||
|  | ||||
| #include "internal.h" | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| // | ||||
| // Normalized Host Name Cache Entry definition | ||||
| // | ||||
| typedef struct _NormalizedHostNameCacheEntry | ||||
| { | ||||
|    LIST_ENTRY  listEntry; | ||||
|    char        *pHostName; | ||||
|    char        *pNormalizedHostName; | ||||
|    int         buffLengthRequired; | ||||
|      | ||||
| } NormalizedHostNameCacheEntry, *PNormalizedHostNameCacheEntry; | ||||
|  | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
| // Global synchronization mutex for the user | ||||
| static | ||||
| HANDLE   hUserMutex; | ||||
|  | ||||
| // Normalized host name cache list head | ||||
| static | ||||
| LIST_ENTRY  normalizedHostNameCacheListHead; | ||||
|  | ||||
| // Synchronization mutex for the normalized host name cache | ||||
| static | ||||
| HANDLE   hNormalizedHostNameCacheMutex; | ||||
|  | ||||
| // Authentication mechanism configuration file folder | ||||
| char  mechConfigFolder[] = "\\Program Files\\Novell\\Casa\\Etc\\Auth\\Mechanisms"; | ||||
|  | ||||
| // Path separator | ||||
| char  pathCharString[] = "\\"; | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| CasaStatus | ||||
| CreateUserMutex(void) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus  retStatus = CASA_STATUS_SUCCESS; | ||||
|    char        *pUsername = NULL; | ||||
|    DWORD       nameLength = 0; | ||||
|  | ||||
|    DbgTrace(1, "-CreateUserMutex- Start\n", 0); | ||||
|  | ||||
|    // Get the size of the buffer required to obtain the user name | ||||
|    GetUserName(pUsername, &nameLength); | ||||
|    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) | ||||
|    { | ||||
|       // Allocate buffer to hold the user name | ||||
|       pUsername = (char*) malloc(nameLength); | ||||
|       if (pUsername) | ||||
|       { | ||||
|          // Get the name of the user | ||||
|          if (GetUserName(pUsername, &nameLength)) | ||||
|          { | ||||
|             SECURITY_ATTRIBUTES  mutexAttributes; | ||||
|             char                 mutexName[256]; | ||||
|  | ||||
|             // Now lets create a global semaphore for the | ||||
|             // user and allow its handle to be inherited. | ||||
|             mutexAttributes.nLength = sizeof(mutexAttributes); | ||||
|             mutexAttributes.lpSecurityDescriptor = NULL; | ||||
|             mutexAttributes.bInheritHandle = TRUE; | ||||
|             if (sprintf(mutexName, "Global\\CASA_Auth_Mutex_%s", pUsername) != -1) | ||||
|             { | ||||
|                hUserMutex = CreateMutex(&mutexAttributes, | ||||
|                                         FALSE, | ||||
|                                         mutexName); | ||||
|                if (hUserMutex == NULL) | ||||
|                { | ||||
|                   DbgTrace(0, "-CreateUserMutex- CreteMutex failed, error = %d\n", GetLastError()); | ||||
|                   retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                               CASA_FACILITY_AUTHTOKEN, | ||||
|                                               CASA_STATUS_UNSUCCESSFUL); | ||||
|                } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                DbgTrace(0, "-CreateUserMutex- sprintf failed, error = %d\n", GetLastError()); | ||||
|                retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_UNSUCCESSFUL); | ||||
|             } | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-CreateUserMutex- GetUserName failed, error = %d\n", GetLastError()); | ||||
|             retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                         CASA_FACILITY_AUTHTOKEN, | ||||
|                                         CASA_STATUS_UNSUCCESSFUL); | ||||
|          } | ||||
|  | ||||
|          // Free the buffer allocated to hold the user name | ||||
|          free(pUsername); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-CreateUserMutex- Buffer allocation error\n", 0); | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                      CASA_FACILITY_AUTHTOKEN, | ||||
|                                      CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-CreateUserMutex- Un-expected GetUserName error, error = %d\n", GetLastError()); | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_UNSUCCESSFUL); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-CreateUserMutex- End, retStatus\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| AcquireUserMutex(void) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    DbgTrace(2, "-AcquireUserMutex- Start\n", 0); | ||||
|  | ||||
|    WaitForSingleObject(hUserMutex, INFINITE); | ||||
|  | ||||
|    DbgTrace(2, "-AcquireUserMutex- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| ReleaseUserMutex(void) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    DbgTrace(2, "-ReleaseUserMutex- Start\n", 0); | ||||
|  | ||||
|    if (ReleaseMutex(hUserMutex) == 0) | ||||
|    { | ||||
|       DbgTrace(0, "-ReleaseUserMutex- ReleaseMutex failed, error = %d\n", GetLastError()); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(2, "-ReleaseUserMutex- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| LIB_HANDLE | ||||
| OpenLibrary( | ||||
|    IN    char *pFileName) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    LIB_HANDLE  libHandle; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-OpenLibrary- Start\n", 0); | ||||
|  | ||||
|    libHandle = LoadLibrary(pFileName); | ||||
|    if (libHandle == NULL) | ||||
|    { | ||||
|       DbgTrace(0, "-OpenLibrary- Not able to load library, error = %d\n", GetLastError()); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-OpenLibrary- End, handle = %08X\n", libHandle); | ||||
|  | ||||
|    return libHandle; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| CloseLibrary( | ||||
|    IN    LIB_HANDLE libHandle) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    DbgTrace(1, "-CloseLibrary- Start\n", 0); | ||||
|  | ||||
|    FreeLibrary(libHandle); | ||||
|  | ||||
|    DbgTrace(1, "-CloseLibrary- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void* | ||||
| GetFunctionPtr( | ||||
|    IN    LIB_HANDLE libHandle, | ||||
|    IN    char *pFunctionName) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    void  *pFuncPtr; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-GetFunctionPtr- Start\n", 0); | ||||
|  | ||||
|    pFuncPtr = GetProcAddress(libHandle, pFunctionName); | ||||
|    if (pFuncPtr == NULL) | ||||
|    { | ||||
|       DbgTrace(0, "-GetFunctionPtr- Not able to obtain func ptr, error = %d\n", GetLastError()); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-GetFunctionPtr- End, pFuncPtr = %08X\n", pFuncPtr); | ||||
|  | ||||
|    return pFuncPtr; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| char* | ||||
| NormalizeHostName( | ||||
|    IN    const char *pHostName) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    char                          *pNormalizedName = NULL; | ||||
|    LIST_ENTRY                    *pListEntry; | ||||
|    NormalizedHostNameCacheEntry  *pEntry = NULL; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-NormalizeHostName- Start\n", 0); | ||||
|  | ||||
|    // Obtain our synchronization mutex | ||||
|    WaitForSingleObject(hNormalizedHostNameCacheMutex, INFINITE); | ||||
|  | ||||
|    // First try to find an entry in the normalized host name cache | ||||
|    // for the host name provided. | ||||
|    pListEntry = normalizedHostNameCacheListHead.Flink; | ||||
|    while (pListEntry != &normalizedHostNameCacheListHead) | ||||
|    { | ||||
|       // Get pointer to the entry | ||||
|       pEntry = CONTAINING_RECORD(pListEntry, NormalizedHostNameCacheEntry, listEntry); | ||||
|  | ||||
|       // Check if the entry is for the host name | ||||
|       if (strcmp(pHostName, pEntry->pHostName) == 0) | ||||
|       { | ||||
|          // This entry corresponds to the given host name | ||||
|          break; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          // The entry does not correspond to the given host name | ||||
|          pEntry = NULL; | ||||
|       } | ||||
|  | ||||
|       // Advance to the next entry | ||||
|       pListEntry = pListEntry->Flink; | ||||
|    } | ||||
|  | ||||
|    // Check if we found an entry in our cache for the given host name | ||||
|    if (pEntry) | ||||
|    { | ||||
|       // Entry found, obtain the normalized name from it. | ||||
|       pNormalizedName = (char*) malloc(pEntry->buffLengthRequired); | ||||
|       if (pNormalizedName) | ||||
|       { | ||||
|          // Copy the normalized name onto the allocated buffer | ||||
|          strcpy(pNormalizedName, pEntry->pNormalizedHostName); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       // An entry was not found in our cache, create one. | ||||
|       pEntry = (NormalizedHostNameCacheEntry*) malloc(sizeof(NormalizedHostNameCacheEntry)); | ||||
|       if (pEntry) | ||||
|       { | ||||
|          // Zero the entry | ||||
|          memset(pEntry, 0, sizeof(*pEntry)); | ||||
|  | ||||
|          // Allocate a buffer to hold the host name in the entry | ||||
|          pEntry->pHostName = (char*) malloc(strlen(pHostName) + 1); | ||||
|          if (pEntry->pHostName) | ||||
|          { | ||||
|             struct hostent       *pLookupResult; | ||||
|             struct sockaddr_in   sockAddr = {0}; | ||||
|  | ||||
|             // Copy the host name given into the allocated buffer | ||||
|             strcpy(pEntry->pHostName, pHostName); | ||||
|  | ||||
|             // Now try to resolve the normalized name | ||||
|             pLookupResult = gethostbyname(pHostName); | ||||
|             if (pLookupResult && pLookupResult->h_addrtype == AF_INET) | ||||
|             { | ||||
|                char  dnsHostName[NI_MAXHOST]; | ||||
|  | ||||
|                // Set up a sockaddr structure | ||||
|                sockAddr.sin_family = AF_INET; | ||||
|                sockAddr.sin_addr.S_un.S_addr = *((int*) pLookupResult->h_addr_list[0]); | ||||
|  | ||||
|                // Now try to resolve the name using DNS | ||||
|                if (getnameinfo((const struct sockaddr*) &sockAddr, | ||||
|                                sizeof(sockAddr), | ||||
|                                dnsHostName, | ||||
|                                sizeof(dnsHostName), | ||||
|                                NULL, | ||||
|                                0, | ||||
|                                NI_NAMEREQD) == 0) | ||||
|                { | ||||
|                   // We resolved the address to a DNS name, use it as the normalized name. | ||||
|                   pEntry->buffLengthRequired = (int) strlen(dnsHostName) + 1; | ||||
|                   pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired); | ||||
|                   if (pEntry->pNormalizedHostName) | ||||
|                   { | ||||
|                      // Copy the dns name | ||||
|                      strcpy(pEntry->pNormalizedHostName, dnsHostName); | ||||
|                   } | ||||
|                   else | ||||
|                   { | ||||
|                      DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); | ||||
|                   } | ||||
|                } | ||||
|                else | ||||
|                { | ||||
|                   DbgTrace(0, "-NormalizeHostName- getnameInfo failed, error %d\n", WSAGetLastError()); | ||||
|  | ||||
|                   // Not able to resolve the name in DNS, just use the host name as | ||||
|                   // the normalized name. | ||||
|                   pEntry->buffLengthRequired = (int) strlen(pHostName) + 1; | ||||
|                   pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired); | ||||
|                   if (pEntry->pNormalizedHostName) | ||||
|                   { | ||||
|                      // Copy the host name | ||||
|                      strcpy(pEntry->pNormalizedHostName, pHostName); | ||||
|                   } | ||||
|                   else | ||||
|                   { | ||||
|                      DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); | ||||
|                   } | ||||
|                } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                DbgTrace(0, "-NormalizeHostName- Name resolution failed, error = %d\n", WSAGetLastError()); | ||||
|             } | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); | ||||
|  | ||||
|             // Free the space allocated for the entry | ||||
|             free(pEntry); | ||||
|          } | ||||
|  | ||||
|          // Proceed based on whether or not we normalized the name | ||||
|          if (pEntry->pNormalizedHostName) | ||||
|          { | ||||
|             // The name was normalized, save the entry in our cache. | ||||
|             InsertHeadList(&normalizedHostNameCacheListHead, &pEntry->listEntry); | ||||
|  | ||||
|             // Return the normalized name present in the entry | ||||
|             pNormalizedName = (char*) malloc(pEntry->buffLengthRequired); | ||||
|             if (pNormalizedName) | ||||
|             { | ||||
|                // Copy the normalized name onto the allocated buffer | ||||
|                strcpy(pNormalizedName, pEntry->pNormalizedHostName); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); | ||||
|             } | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             // The host name was not normalized, free allocated resources. | ||||
|             if (pEntry->pHostName) | ||||
|                free(pEntry->pHostName); | ||||
|             free(pEntry); | ||||
|          } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); | ||||
|       } | ||||
|    } | ||||
|  | ||||
|    // Release our synchronization mutex | ||||
|    if (ReleaseMutex(hNormalizedHostNameCacheMutex) == 0) | ||||
|    { | ||||
|       DbgTrace(0, "-NormalizeHostName- ReleaseMutex failed, error\n", 0); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-NormalizeHostName- End, pNormalizedName = %08X\n", pNormalizedName); | ||||
|  | ||||
|    return pNormalizedName; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| CasaStatus | ||||
| InitializeHostNameNormalization(void) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus  retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_UNSUCCESSFUL); | ||||
|    int         winsockStartupResult; | ||||
|    WSADATA     winsockData; | ||||
|  | ||||
|    DbgTrace(1, "-InitializeHostNameNormalization- Start\n", 0); | ||||
|  | ||||
|    // Initialize winsock | ||||
|    if ((winsockStartupResult = WSAStartup(MAKEWORD(2,2), &winsockData)) == 0) | ||||
|    { | ||||
|       // Initialize the cache list head | ||||
|       InitializeListHead(&normalizedHostNameCacheListHead); | ||||
|  | ||||
|       // Create a cache mutex only applicable to the current process | ||||
|       hNormalizedHostNameCacheMutex = CreateMutex(NULL, | ||||
|                                                   FALSE, | ||||
|                                                   NULL); | ||||
|       if (hNormalizedHostNameCacheMutex != NULL) | ||||
|       { | ||||
|          retStatus = CASA_STATUS_SUCCESS; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-InitializeHostNameNormalization- CreateMutex failed, error = %d\n", GetLastError()); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-InitializeHostNameNormalization- WSAStartup failed, error = %d\n", winsockStartupResult); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-InitializeHostNameNormalization- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
|  | ||||
							
								
								
									
										114
									
								
								CASA-auth-token/native/client/windows/platform.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								CASA-auth-token/native/client/windows/platform.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,114 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  Copyright (C) 2006 Novell, Inc. All Rights Reserved. | ||||
|  * | ||||
|  *  This library is free software; you can redistribute it and/or | ||||
|  *  modify it under the terms of the GNU Lesser General Public | ||||
|  *  License as published by the Free Software Foundation; version 2.1 | ||||
|  *  of the License. | ||||
|  * | ||||
|  *  This library is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
|  *  Library Lesser General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Lesser General Public | ||||
|  *  License along with this library; if not, Novell, Inc. | ||||
|  *  | ||||
|  *  To contact Novell about this file by physical or electronic mail,  | ||||
|  *  you may find current contact information at www.novell.com. | ||||
|  *  | ||||
|  *  Author: Juan Carlos Luciani <jluciani@novell.com> | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
|  | ||||
| //===[ Include files ]===================================================== | ||||
|  | ||||
| #include <winsock2.h> | ||||
| #include <windows.h> | ||||
| #include <stdio.h> | ||||
| #include <aclapi.h> | ||||
| #include <winerror.h> | ||||
| #include <ws2tcpip.h> | ||||
| #include <winhttp.h> | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| #ifndef CONTAINING_RECORD | ||||
| #define CONTAINING_RECORD(address, type, field) ((type *)(     \ | ||||
|              (char*)(address) -                                \ | ||||
|              (char*)(&((type *)0)->field))) | ||||
| #endif | ||||
|  | ||||
| // | ||||
| // DbgTrace macro define | ||||
| // | ||||
| //#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);                            \ | ||||
|    }                                                           \ | ||||
| } | ||||
|  | ||||
|  | ||||
| #define bool BOOLEAN | ||||
| #define true TRUE | ||||
| #define false FALSE | ||||
|  | ||||
| // | ||||
| // Auth Cache Entry definition | ||||
| // | ||||
| typedef struct _AuthCacheEntry | ||||
| { | ||||
|    LIST_ENTRY  listEntry; | ||||
|    int         refCount; | ||||
|    DWORD       creationTime; | ||||
|    DWORD       expirationTime; | ||||
|    BOOL        doesNotExpire; | ||||
|    char        *pHostName; | ||||
|    char        *pCacheKeyName; | ||||
|    char        *pToken; | ||||
|    int         status; | ||||
|      | ||||
| } AuthCacheEntry, *PAuthCacheEntry; | ||||
|  | ||||
| // | ||||
| // Rpc Session definition | ||||
| // | ||||
| typedef struct _RpcSession | ||||
| { | ||||
|    HINTERNET   hSession; | ||||
|    HINTERNET   hConnection; | ||||
|  | ||||
| } RpcSession, *PRpcSession; | ||||
|  | ||||
| // | ||||
| // Other definitions | ||||
| // | ||||
| #define LIB_HANDLE HMODULE | ||||
|  | ||||
|  | ||||
| //===[ Inlines functions   ]=============================================== | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global externals ]================================================== | ||||
|  | ||||
| //===[ External prototypes ]=============================================== | ||||
|  | ||||
| //========================================================================= | ||||
|  | ||||
							
								
								
									
										498
									
								
								CASA-auth-token/native/client/windows/rpc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										498
									
								
								CASA-auth-token/native/client/windows/rpc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,498 @@ | ||||
| /*********************************************************************** | ||||
|  *  | ||||
|  *  Copyright (C) 2006 Novell, Inc. All Rights Reserved. | ||||
|  * | ||||
|  *  This library is free software; you can redistribute it and/or | ||||
|  *  modify it under the terms of the GNU Lesser General Public | ||||
|  *  License as published by the Free Software Foundation; version 2.1 | ||||
|  *  of the License. | ||||
|  * | ||||
|  *  This library is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
|  *  Library Lesser General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Lesser General Public | ||||
|  *  License along with this library; if not, Novell, Inc. | ||||
|  *  | ||||
|  *  To contact Novell about this file by physical or electronic mail,  | ||||
|  *  you may find current contact information at www.novell.com. | ||||
|  *  | ||||
|  *  Author: Juan Carlos Luciani <jluciani@novell.com> | ||||
|  * | ||||
|  ***********************************************************************/ | ||||
|  | ||||
|  | ||||
| //===[ Include files ]===================================================== | ||||
|  | ||||
| #include "internal.h" | ||||
|  | ||||
| //===[ Type definitions ]================================================== | ||||
|  | ||||
| #define INITIAL_RESPONSE_DATA_BUF_SIZE 1028 | ||||
| #define INCREMENT_RESPONSE_DATA_BUF_SIZE 256 | ||||
|  | ||||
| #define MAX_RPC_RETRIES 3 | ||||
|  | ||||
| //===[ Function prototypes ]=============================================== | ||||
|  | ||||
| //===[ Global variables ]================================================== | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| CasaStatus | ||||
| CopyMultiToWideAlloc( | ||||
|    IN    char *pMulti, | ||||
|    IN    int multiSize, | ||||
|    INOUT LPWSTR *ppWide, | ||||
|    INOUT int *pWideSize) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    int      retStatus; | ||||
|    int      size, i; | ||||
|  | ||||
|  | ||||
|    DbgTrace(2, "-CopyMultiToWideAlloc- Start\n", 0); | ||||
|  | ||||
|    size = (multiSize + 1) * sizeof(WCHAR); | ||||
|  | ||||
|    if ((*ppWide = (PWCHAR) malloc(size)) != NULL) | ||||
|    { | ||||
|       for (i = 0; i < multiSize; i++) | ||||
|       { | ||||
|          *(*ppWide + i) = (unsigned char) *(pMulti + i); | ||||
|       } | ||||
|  | ||||
|       *(*ppWide + i) = L'\0'; | ||||
|  | ||||
|       if (pWideSize) | ||||
|       { | ||||
|          *pWideSize = size - sizeof(WCHAR); | ||||
|       } | ||||
|  | ||||
|       retStatus = CASA_STATUS_SUCCESS; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(2, "-CopyMultiToWideAlloc- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| RpcSession* | ||||
| OpenRpcSession( | ||||
|    IN    char *pHostName) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    RpcSession  *pSession; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-OpenRpcSession- Start\n", 0); | ||||
|  | ||||
|    // Allocate space for the session | ||||
|    pSession = (RpcSession*) malloc(sizeof(*pSession)); | ||||
|    if (pSession) | ||||
|    { | ||||
|       // Zero the session structure | ||||
|       memset(pSession, 0, sizeof(*pSession)); | ||||
|  | ||||
|       // Open a Winhttp session | ||||
|       pSession->hSession = WinHttpOpen(L"CASA Client/1.0", | ||||
|                                        WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, | ||||
|                                        WINHTTP_NO_PROXY_NAME, | ||||
|                                        WINHTTP_NO_PROXY_BYPASS, | ||||
|                                        0); | ||||
|       if (pSession->hSession) | ||||
|       { | ||||
|          LPWSTR   pWideHostName; | ||||
|          int      wideHostLen; | ||||
|  | ||||
|          // Session opened, now convert the host name to Unicode so that | ||||
|          // we can open a connection. | ||||
|          if (CopyMultiToWideAlloc(pHostName, | ||||
|                                   (int) strlen(pHostName), | ||||
|                                   &pWideHostName, | ||||
|                                   &wideHostLen) == CASA_STATUS_SUCCESS) | ||||
|          { | ||||
|             // Now open connection | ||||
|             pSession->hConnection = WinHttpConnect(pSession->hSession, | ||||
|                                                    pWideHostName, | ||||
|                                                    8080, /*INTERNET_DEFAULT_HTTP_PORT,*/ | ||||
|                                                    0); | ||||
|             if (pSession->hConnection == NULL) | ||||
|             { | ||||
|                DbgTrace(0, "-OpenRpcSession- Failed to open connection, error = %d\n", GetLastError()); | ||||
|  | ||||
|                // Free allocated resources | ||||
|                WinHttpCloseHandle(pSession->hSession); | ||||
|                free(pSession); | ||||
|                pSession = NULL; | ||||
|             } | ||||
|  | ||||
|             // Free the host name wide string buffer | ||||
|             free(pWideHostName); | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(0, "-OpenRpcSession- Error converting host name to wide string\n", 0); | ||||
|  | ||||
|             // Free allocated resources | ||||
|             WinHttpCloseHandle(pSession->hSession); | ||||
|             free(pSession); | ||||
|             pSession = NULL; | ||||
|          } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-OpenRpcSession- Failed to open session, error = %d\n", GetLastError()); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       DbgTrace(0, "-OpenRpcSession- Failed to allocate buffer for rpc session\n", 0); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(2, "-OpenRpcSession- End, pSession = %08X\n", pSession); | ||||
|  | ||||
|    return pSession; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| void | ||||
| CloseRpcSession( | ||||
|    IN    RpcSession *pSession) | ||||
| // | ||||
| //  Arguments:  | ||||
| // | ||||
| //  Returns:    | ||||
| // | ||||
| //  Abstract:   | ||||
| // | ||||
| //  Notes: | ||||
| // | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    DbgTrace(1, "-CloseRpcSession- Start\n", 0); | ||||
|  | ||||
|    // Close the connection handle | ||||
|    WinHttpCloseHandle(pSession->hConnection); | ||||
|  | ||||
|    // Close the session handle | ||||
|    WinHttpCloseHandle(pSession->hSession); | ||||
|  | ||||
|    // Free the space allocated for the session | ||||
|    free(pSession); | ||||
|  | ||||
|    DbgTrace(1, "-CloseRpcSession- End\n", 0); | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| CasaStatus | ||||
| InternalRpc( | ||||
|    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 = CASA_STATUS_SUCCESS; | ||||
|    char        rpcTarget[256]; | ||||
|    LPWSTR      pWideRpcTarget; | ||||
|    int         wideRpcTargetLen; | ||||
|    WCHAR       sendHeaders[] = L"Content-Type: text/html"; | ||||
|  | ||||
|    DbgTrace(1, "-InternalRpc- Start\n", 0); | ||||
|  | ||||
|    // Initialize output parameter | ||||
|    *ppResponseData = NULL; | ||||
|  | ||||
|    // Create rpc target string and convert it to a wide string | ||||
|    sprintf(rpcTarget, "CasaAuthTokenSvc/Rpc?method=%s", pMethod); | ||||
|    retStatus = CopyMultiToWideAlloc(rpcTarget, | ||||
|                                     (int) strlen(rpcTarget), | ||||
|                                     &pWideRpcTarget, | ||||
|                                     &wideRpcTargetLen); | ||||
|    if (CASA_SUCCESS(retStatus)) | ||||
|    { | ||||
|       HINTERNET   hRequest; | ||||
|  | ||||
|       // Open a request handle | ||||
|       hRequest = WinHttpOpenRequest(pSession->hConnection, | ||||
|                                     L"POST", | ||||
|                                     pWideRpcTarget, | ||||
|                                     NULL, | ||||
|                                     WINHTTP_NO_REFERER, | ||||
|                                     WINHTTP_DEFAULT_ACCEPT_TYPES, | ||||
|                                     secure? WINHTTP_FLAG_REFRESH | WINHTTP_FLAG_SECURE : WINHTTP_FLAG_REFRESH); | ||||
|       if (hRequest) | ||||
|       { | ||||
|          int   reqDataLen = (int) strlen(pRequestData); | ||||
|  | ||||
|          // Send the request | ||||
|          if (WinHttpSendRequest(hRequest, | ||||
|                                 sendHeaders, | ||||
|                                 -1, | ||||
|                                 pRequestData, | ||||
|                                 reqDataLen, | ||||
|                                 reqDataLen, | ||||
|                                 0)) | ||||
|          { | ||||
|             // Request sent, now await for the response. | ||||
|             if (WinHttpReceiveResponse(hRequest, NULL)) | ||||
|             { | ||||
|                WCHAR httpCompStatus[4] = {0}; | ||||
|                DWORD httpCompStatusLen = sizeof(httpCompStatus); | ||||
|  | ||||
|                // Response received, make sure that it completed successfully. | ||||
|                if (WinHttpQueryHeaders(hRequest, | ||||
|                                        WINHTTP_QUERY_STATUS_CODE, | ||||
|                                        NULL, | ||||
|                                        &httpCompStatus, | ||||
|                                        &httpCompStatusLen, | ||||
|                                        WINHTTP_NO_HEADER_INDEX)) | ||||
|                { | ||||
|                   // Check that the request completed successfully | ||||
|                   if (memcmp(httpCompStatus, L"200", sizeof(httpCompStatus)) == 0) | ||||
|                   { | ||||
|                      char  *pResponseData; | ||||
|                      int   responseDataBufSize = INITIAL_RESPONSE_DATA_BUF_SIZE;       | ||||
|                      int   responseDataRead = 0; | ||||
|  | ||||
|                      // Now read the response data, to do so we need to allocate a buffer. | ||||
|                      pResponseData = (char*) malloc(INITIAL_RESPONSE_DATA_BUF_SIZE); | ||||
|                      if (pResponseData) | ||||
|                      { | ||||
|                         char     *pCurrLocation = pResponseData; | ||||
|                         DWORD    bytesRead; | ||||
|  | ||||
|                         do | ||||
|                         { | ||||
|                            bytesRead = 0; | ||||
|                            if (WinHttpReadData(hRequest, | ||||
|                                                (LPVOID) pCurrLocation, | ||||
|                                                responseDataBufSize - responseDataRead, | ||||
|                                                &bytesRead)) | ||||
|                            { | ||||
|                               pCurrLocation += bytesRead; | ||||
|                               responseDataRead += bytesRead; | ||||
|  | ||||
|                               // Check if we need to allocate a larger buffer | ||||
|                               if (responseDataRead == responseDataBufSize) | ||||
|                               { | ||||
|                                  char  *pTmpBuf; | ||||
|  | ||||
|                                  // We need to upgrade the receive buffer | ||||
|                                  pTmpBuf = (char*) malloc(responseDataBufSize + INCREMENT_RESPONSE_DATA_BUF_SIZE); | ||||
|                                  if (pTmpBuf) | ||||
|                                  { | ||||
|                                     memcpy(pTmpBuf, pResponseData, responseDataBufSize); | ||||
|                                     free(pResponseData); | ||||
|                                     pResponseData = pTmpBuf; | ||||
|                                     pCurrLocation = pResponseData + responseDataBufSize; | ||||
|                                     responseDataBufSize += INCREMENT_RESPONSE_DATA_BUF_SIZE; | ||||
|                                  } | ||||
|                                  else | ||||
|                                  { | ||||
|                                     DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0); | ||||
|                                     retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                                                 CASA_FACILITY_AUTHTOKEN, | ||||
|                                                                 CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|                                  } | ||||
|                               } | ||||
|                            } | ||||
|                            else | ||||
|                            { | ||||
|                               DbgTrace(0, "-InternalRpc- Failed reading response data, error = %d\n", GetLastError()); | ||||
|                               retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                                           CASA_FACILITY_AUTHTOKEN, | ||||
|                                                           CASA_STATUS_UNSUCCESSFUL); | ||||
|                            } | ||||
|                         } while (CASA_SUCCESS(retStatus) | ||||
|                                  && bytesRead != 0); | ||||
|  | ||||
|                         // Check if the response data was successfully received | ||||
|                         if (CASA_SUCCESS(retStatus)) | ||||
|                         { | ||||
|                            // The response data was received, return it to the caller. | ||||
|                            *ppResponseData = pResponseData; | ||||
|                            *pResponseDataLen = responseDataRead;  | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                            // Failed to receive the response data, free the allocated buffer. | ||||
|                            free(pResponseData); | ||||
|                         } | ||||
|                      } | ||||
|                      else | ||||
|                      { | ||||
|                         DbgTrace(0, "-InternalRpc- Buffer allocation failure\n", 0); | ||||
|                         retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                                     CASA_FACILITY_AUTHTOKEN, | ||||
|                                                     CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|                      } | ||||
|                   } | ||||
|                   else | ||||
|                   { | ||||
|                      DbgTrace(0, "-InternalRpc- HTTP request did not complete successfully, status = %S\n", httpCompStatus); | ||||
|                      retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                                  CASA_FACILITY_AUTHTOKEN, | ||||
|                                                  CASA_STATUS_UNSUCCESSFUL); | ||||
|                   } | ||||
|                } | ||||
|                else | ||||
|                { | ||||
|                   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); | ||||
|                } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                DbgTrace(0, "-InternalRpc- Unable to receive response, error = %d\n", GetLastError()); | ||||
|                retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_UNSUCCESSFUL); | ||||
|             } | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             int   error = GetLastError(); | ||||
|  | ||||
|             DbgTrace(0, "-InternalRpc- Unsuccessful send http request, error = %d\n", error); | ||||
|             if (error == ERROR_WINHTTP_CANNOT_CONNECT) | ||||
|             { | ||||
|                retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_AUTH_SERVER_UNAVAILABLE); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_UNSUCCESSFUL); | ||||
|             } | ||||
|          } | ||||
|  | ||||
|          // Close the request handle | ||||
|          WinHttpCloseHandle(hRequest); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          DbgTrace(0, "-InternalRpc- Unable to open http request, error = %d\n", GetLastError()); | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                      CASA_FACILITY_AUTHTOKEN, | ||||
|                                      CASA_STATUS_UNSUCCESSFUL); | ||||
|       } | ||||
|  | ||||
|       // Free the rpc target wide string buffer | ||||
|       free(pWideRpcTarget); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       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; | ||||
| } | ||||
|  | ||||
|  | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
| //++======================================================================= | ||||
|  | ||||
		Reference in New Issue
	
	Block a user