Made changes to deal with issues found during self-code review.

Added lock callback functionality for interfacing with OpenSSL
in a multi-threaded environment.
This commit is contained in:
Juan Carlos Luciani 2006-11-30 18:21:42 +00:00
parent a522f9d982
commit 1974ee9875
28 changed files with 1196 additions and 548 deletions

View File

@ -57,8 +57,8 @@ LIST_ENTRY g_authMechModuleListHead = {&g_authMechModuleListHead,
static static
CasaStatus CasaStatus
GetAuthTokenIf( GetAuthTokenIf(
IN const char *pAuthTypeName, IN const char *pAuthTypeName,
INOUT AuthTokenIf **ppAuthTokenIf) INOUT AuthTokenIf **ppAuthTokenIf)
// //
// Arguments: // Arguments:
// //

View File

@ -61,6 +61,10 @@ typedef struct _AuthRespParse
XML_Parser p; XML_Parser p;
int state; int state;
int elementDataProcessed; int elementDataProcessed;
char *pStatusData;
int statusDataLen;
char *pLifetimeData;
int lifetimeDataLen;
AuthenticateResp *pAuthenticateResp; AuthenticateResp *pAuthenticateResp;
CasaStatus status; CasaStatus status;
@ -218,7 +222,7 @@ AuthRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -233,7 +237,7 @@ AuthRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -248,7 +252,7 @@ AuthRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -263,7 +267,7 @@ AuthRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -278,7 +282,7 @@ AuthRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -401,6 +405,8 @@ AuthRespCharDataHandler(
// L2 // L2
//=======================================================================-- //=======================================================================--
{ {
CasaStatus status;
DbgTrace(2, "-AuthRespCharDataHandler- Start\n", 0); DbgTrace(2, "-AuthRespCharDataHandler- Start\n", 0);
// Just exit if being called to process white space // Just exit if being called to process white space
@ -423,68 +429,64 @@ AuthRespCharDataHandler(
break; break;
case AWAITING_STATUS_DATA: case AWAITING_STATUS_DATA:
case AWAITING_STATUS_ELEMENT_END:
// Set the appropriate status in the AuthenticationResp based on the // Consume the data
// returned status. status = ConsumeElementData(pAuthRespParse,
if (strncmp(HTTP_OK_STATUS_CODE, s, len) == 0) s,
len,
&pAuthRespParse->pStatusData,
&pAuthRespParse->statusDataLen);
if (CASA_SUCCESS(status))
{ {
pAuthRespParse->status = CASA_STATUS_SUCCESS; // Advanced to the next state
} pAuthRespParse->state = AWAITING_STATUS_ELEMENT_END;
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE, s, len) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_CONFIGURATION_ERROR);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR);
} }
else else
{ {
DbgTrace(0, "-AuthRespCharDataHandler- Un-expected status\n", 0); pAuthRespParse->status = status;
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, XML_StopParser(pAuthRespParse->p, XML_FALSE);
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
} }
// Advanced to the next state
pAuthRespParse->state = AWAITING_STATUS_ELEMENT_END;
break; break;
case AWAITING_LIFETIME_DATA: case AWAITING_LIFETIME_DATA:
case AWAITING_LIFETIME_ELEMENT_END:
// Convert the lifetime string to a numeric value // Consume the data
pAuthRespParse->pAuthenticateResp->tokenLifetime = dtoul(s, len); status = ConsumeElementData(pAuthRespParse,
s,
// Advanced to the next state len,
pAuthRespParse->state = AWAITING_LIFETIME_ELEMENT_END; &pAuthRespParse->pLifetimeData,
&pAuthRespParse->lifetimeDataLen);
if (CASA_SUCCESS(status))
{
// Advanced to the next state
pAuthRespParse->state = AWAITING_LIFETIME_ELEMENT_END;
}
else
{
pAuthRespParse->status = status;
XML_StopParser(pAuthRespParse->p, XML_FALSE);
}
break; break;
case AWAITING_SESSION_TOKEN_DATA: case AWAITING_SESSION_TOKEN_DATA:
case AWAITING_SESSION_TOKEN_ELEMENT_END: case AWAITING_SESSION_TOKEN_ELEMENT_END:
// Consume the data // Consume the data
pAuthRespParse->status = ConsumeElementData(pAuthRespParse, status = ConsumeElementData(pAuthRespParse,
s, s,
len, len,
&pAuthRespParse->pAuthenticateResp->pToken, &pAuthRespParse->pAuthenticateResp->pToken,
&pAuthRespParse->pAuthenticateResp->tokenLen); &pAuthRespParse->pAuthenticateResp->tokenLen);
if (CASA_SUCCESS(pAuthRespParse->status)) if (CASA_SUCCESS(status))
{ {
// Advanced to the next state // Advanced to the next state
pAuthRespParse->state = AWAITING_SESSION_TOKEN_ELEMENT_END; pAuthRespParse->state = AWAITING_SESSION_TOKEN_ELEMENT_END;
} }
else else
{ {
pAuthRespParse->status = status;
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -535,7 +537,7 @@ AuthRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespEndHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthRespEndHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -550,7 +552,7 @@ AuthRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -560,11 +562,51 @@ AuthRespEndElementHandler(
// In this state, we are only expecting the Status Element. // In this state, we are only expecting the Status Element.
if (strcmp(name, STATUS_ELEMENT_NAME) == 0) if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
{ {
// Set the appropriate status in the AuthenticationResp based on the returned status data
if (strncmp(HTTP_OK_STATUS_CODE,
pAuthRespParse->pStatusData,
pAuthRespParse->statusDataLen) == 0)
{
pAuthRespParse->status = CASA_STATUS_SUCCESS;
}
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE,
pAuthRespParse->pStatusData,
pAuthRespParse->statusDataLen) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE,
pAuthRespParse->pStatusData,
pAuthRespParse->statusDataLen) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_CONFIGURATION_ERROR);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE,
pAuthRespParse->pStatusData,
pAuthRespParse->statusDataLen) == 0)
{
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR);
}
else
{
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected status\n", 0);
pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
}
// Good, advance to the next state based on the status code. // Good, advance to the next state based on the status code.
if (CASA_SUCCESS(pAuthRespParse->status)) if (CASA_SUCCESS(pAuthRespParse->status))
{ {
// The request completed successfully // The request completed successfully
pAuthRespParse->state = AWAITING_SESSION_TOKEN_ELEMENT_START; pAuthRespParse->state = AWAITING_SESSION_TOKEN_ELEMENT_START;
} }
else else
{ {
@ -573,7 +615,7 @@ AuthRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -583,12 +625,16 @@ AuthRespEndElementHandler(
// In this state, we are only expecting the Lifetime Element. // In this state, we are only expecting the Lifetime Element.
if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0) if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0)
{ {
// Convert the lifetime string to a numeric value
pAuthRespParse->pAuthenticateResp->tokenLifetime = dtoul(pAuthRespParse->pLifetimeData,
pAuthRespParse->lifetimeDataLen);
// Good, advance to the next state. // Good, advance to the next state.
pAuthRespParse->state = AWAITING_SESSION_TOKEN_DATA; pAuthRespParse->state = AWAITING_SESSION_TOKEN_DATA;
} }
else else
{ {
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -603,7 +649,7 @@ AuthRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthRespParse->p, XML_FALSE); XML_StopParser(pAuthRespParse->p, XML_FALSE);
} }
break; break;
@ -736,6 +782,13 @@ CreateAuthenticateResp(
// Free the parser // Free the parser
XML_ParserFree(p); XML_ParserFree(p);
// Free any buffers associated with the parse
if (authRespParse.pStatusData)
free(authRespParse.pStatusData);
if (authRespParse.pLifetimeData)
free(authRespParse.pLifetimeData);
} }
else else
{ {

View File

@ -103,7 +103,7 @@ AuthPolicyStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;
@ -137,7 +137,7 @@ AuthPolicyStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-AuthPolicyStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;
@ -448,7 +448,7 @@ AuthPolicyEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;
@ -464,7 +464,7 @@ AuthPolicyEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyEndHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthPolicyEndHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;
@ -479,7 +479,7 @@ AuthPolicyEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;
@ -494,7 +494,7 @@ AuthPolicyEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;
@ -533,7 +533,7 @@ AuthPolicyEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-AuthPolicyEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pAuthPolicyParse->p, XML_FALSE); XML_StopParser(pAuthPolicyParse->p, XML_FALSE);
} }
break; break;

View File

@ -18,7 +18,8 @@
* To contact Novell about this file by physical or electronic mail, * To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com. * you may find current contact information at www.novell.com.
* *
* Author: Juan Carlos Luciani <jluciani@novell.com> * Authors: Juan Carlos Luciani <jluciani@novell.com>
* Todd Throne <tthrone@novell.com>
* *
***********************************************************************/ ***********************************************************************/
@ -113,7 +114,6 @@ CreateAuthTokenCacheEntry(
keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2; keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2;
pKey = malloc(keySize); pKey = malloc(keySize);
if (pKey) if (pKey)
{ {
strncpy(pKey, pCacheKey, keySize); strncpy(pKey, pCacheKey, keySize);

View File

@ -208,7 +208,8 @@ LowerCaseString(
// //
// Abstract: // Abstract:
// //
// Notes: // Notes: Function assumes that the caller has made sure that the destination
// string buffer has enough space to receive the resulting string.
// //
// L2 // L2
//=======================================================================-- //=======================================================================--
@ -448,7 +449,7 @@ GetConfigInterface(
//=======================================================================-- //=======================================================================--
{ {
int configFolderLen = (int) strlen(pConfigFolder); int configFolderLen = (int) strlen(pConfigFolder);
int configNameLen = (int)strlen(pConfigName); int configNameLen = (int) strlen(pConfigName);
ConfigIfInstance *pConfigIfInstance; ConfigIfInstance *pConfigIfInstance;
LIST_ENTRY *pListEntry; LIST_ENTRY *pListEntry;
CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_INFORMATIONAL, CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_INFORMATIONAL,
@ -490,7 +491,7 @@ GetConfigInterface(
char *pFilePath; char *pFilePath;
// Build a string containing the configuration file path // Build a string containing the configuration file path
pFilePath = (char*) malloc(configFolderLen + 1 + configNameLen + sizeof(".conf")); pFilePath = (char*) malloc(configFolderLen + 1 + configNameLen + sizeof(".conf") + 1);
if (pFilePath) if (pFilePath)
{ {
FILE *pConfigFile; FILE *pConfigFile;
@ -546,90 +547,100 @@ GetConfigInterface(
// Now update the instance data with the information present in the file // Now update the instance data with the information present in the file
if (fseek(pConfigFile, 0, SEEK_SET) == 0) if (fseek(pConfigFile, 0, SEEK_SET) == 0)
{ {
char line[512]; #define MAX_LINE_LEN 1024
char *pLine = (char*) malloc(MAX_LINE_LEN);
while (fgets(line, sizeof(line), pConfigFile) != NULL) if (pLine)
{ {
int lineLength; while (fgets(pLine, MAX_LINE_LEN, pConfigFile) != NULL)
RemoveWhiteSpaceFromTheEnd(line);
lineLength = (int) strlen(line);
if (lineLength != 0)
{ {
char *pKey; int lineLength;
char *pKeyEnd;
char *pValue;
ConfigKey *pConfigKey;
// Attempt to find the key RemoveWhiteSpaceFromTheEnd(pLine);
pKey = SkipWhiteSpace(line);
// Make sure that we are not dealing with an empty line or a comment lineLength = (int) strlen(pLine);
if (*pKey == '\0' || *pKey == '#') if (lineLength != 0)
continue;
// Go past the key
pKeyEnd = SkipNonWhiteSpace(pKey);
// Protect against a malformed line
if (*pKeyEnd == '\0')
{ {
DbgTrace(0, "-GetConfigInterface- Key found without value\n", 0); char *pKey;
continue; char *pKeyEnd;
} char *pValue;
ConfigKey *pConfigKey;
// Attempt to find the value // Attempt to find the key
pValue = SkipWhiteSpace(pKeyEnd); pKey = SkipWhiteSpace(pLine);
// Protect against a malformed line // Make sure that we are not dealing with an empty line or a comment
if (*pValue == '\0') if (*pKey == '\0' || *pKey == '#')
{ continue;
DbgTrace(0, "-GetConfigInterface- Key found without value\n", 0);
continue;
}
// Delineate the key // Go past the key
*pKeyEnd = '\0'; pKeyEnd = SkipNonWhiteSpace(pKey);
// Create a ConfigKey object for this key/value pair // Protect against a malformed line
pConfigKey = (ConfigKey*) malloc(sizeof(*pConfigKey)); if (*pKeyEnd == '\0')
if (pConfigKey)
{
pConfigKey->keyNameLen = (int) strlen(pKey);
pConfigKey->pKeyName = (char*) malloc(pConfigKey->keyNameLen + 1);
if (pConfigKey->pKeyName)
{ {
// Save the key name in lower case DbgTrace(0, "-GetConfigInterface- Key found without value\n", 0);
LowerCaseString(pConfigKey->pKeyName, pKey); continue;
}
pConfigKey->valueLen = (int) strlen(pValue); // Attempt to find the value
pConfigKey->pValue = (char*) malloc(pConfigKey->valueLen + 1); pValue = SkipWhiteSpace(pKeyEnd);
if (pConfigKey->pValue)
// Protect against a malformed line
if (*pValue == '\0')
{
DbgTrace(0, "-GetConfigInterface- Key found without value\n", 0);
continue;
}
// Delineate the key
*pKeyEnd = '\0';
// Create a ConfigKey object for this key/value pair
pConfigKey = (ConfigKey*) malloc(sizeof(*pConfigKey));
if (pConfigKey)
{
pConfigKey->keyNameLen = (int) strlen(pKey);
pConfigKey->pKeyName = (char*) malloc(pConfigKey->keyNameLen + 1);
if (pConfigKey->pKeyName)
{ {
strcpy(pConfigKey->pValue, pValue); // Save the key name in lower case
LowerCaseString(pConfigKey->pKeyName, pKey);
// The entry is ready, now associate it with the instance data. pConfigKey->valueLen = (int) strlen(pValue);
InsertTailList(&pConfigIfInstance->configKeyListHead, &pConfigKey->listEntry); pConfigKey->pValue = (char*) malloc(pConfigKey->valueLen + 1);
if (pConfigKey->pValue)
{
strcpy(pConfigKey->pValue, pValue);
// The entry is ready, now associate it with the instance data.
InsertTailList(&pConfigIfInstance->configKeyListHead, &pConfigKey->listEntry);
}
else
{
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
free(pConfigKey->pKeyName);
free(pConfigKey);
}
} }
else else
{ {
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0); DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
free(pConfigKey->pKeyName);
free(pConfigKey); free(pConfigKey);
} }
} }
else else
{ {
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0); DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
free(pConfigKey);
} }
} }
else
{
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
}
} }
// Free the buffer allocated for holding line strings
free(pLine);
}
else
{
DbgTrace(0, "-GetConfigInterface- Buffer allocation failure\n", 0);
} }
} }
else else
@ -667,6 +678,9 @@ GetConfigInterface(
DbgTrace(0, "-GetConfigInterface- Unable to open config file, errno = %d\n", errno); DbgTrace(0, "-GetConfigInterface- Unable to open config file, errno = %d\n", errno);
DbgTrace(0, "-GetConfigInterface- Config file unable to open = %s\n", pFilePath); DbgTrace(0, "-GetConfigInterface- Config file unable to open = %s\n", pFilePath);
} }
// Free the buffer allocated for the file path
free(pFilePath);
} }
else else
{ {
@ -682,5 +696,5 @@ GetConfigInterface(
//++======================================================================= //++=======================================================================
//++======================================================================= //++=======================================================================
//++======================================================================= //++=======================================================================

View File

@ -108,7 +108,7 @@ ObtainSessionToken(
} }
else else
{ {
// Free the entry // Free the entry
FreeAuthCacheEntry(pCacheEntry); FreeAuthCacheEntry(pCacheEntry);
} }
} }
@ -153,82 +153,82 @@ ObtainSessionToken(
continue; continue;
} }
// Authenticate to the ATS // Authenticate to the ATS
pReqMsg = BuildAuthenticateMsg(pAuthContext, pAuthMechToken); pReqMsg = BuildAuthenticateMsg(pAuthContext, pAuthMechToken);
if (pReqMsg) if (pReqMsg)
{
// Issue rpc
retStatus = Rpc(pRpcSession,
"Authenticate",
g_rpcFlags,
pReqMsg,
&pRespMsg,
&respLen);
if (CASA_SUCCESS(retStatus))
{ {
AuthenticateResp *pAuthenticateResp; // Issue rpc
retStatus = Rpc(pRpcSession,
// Create Authenticate response object "Authenticate",
retStatus = CreateAuthenticateResp(pRespMsg, respLen, &pAuthenticateResp); g_rpcFlags,
pReqMsg,
&pRespMsg,
&respLen);
if (CASA_SUCCESS(retStatus)) if (CASA_SUCCESS(retStatus))
{ {
// Return the auth token to the caller AuthenticateResp *pAuthenticateResp;
pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext,
retStatus, // Create Authenticate response object
pAuthenticateResp->pToken, retStatus = CreateAuthenticateResp(pRespMsg, respLen, &pAuthenticateResp);
pAuthenticateResp->tokenLifetime, if (CASA_SUCCESS(retStatus))
pCredStoreScope); {
// Return the auth token to the caller
pAuthenticateResp->pToken = NULL; // To keep us from freeing the buffer pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext,
retStatus,
// Free the Authenticate response object pAuthenticateResp->pToken,
RelAuthenticateResp(pAuthenticateResp); pAuthenticateResp->tokenLifetime,
pCredStoreScope);
pAuthenticateResp->pToken = NULL; // To keep us from freeing the buffer
// Free the Authenticate response object
RelAuthenticateResp(pAuthenticateResp);
}
} }
else
{
DbgTrace(0, "-ObtainSessionToken- Authenticate Rpc failure, error = %08X\n", retStatus);
}
// Free resources that may be hanging around
if (pRespMsg)
free(pRespMsg);
free(pReqMsg);
} }
else else
{ {
DbgTrace(0, "-ObtainSessionToken- Authenticate Rpc failure, error = %08X\n", retStatus); DbgTrace(0, "-ObtainSessionToken- Error building Authenticate msg\n", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
// Free resources that may be hanging around // Add the entry to the cache if successful or if the reason that we failed
if (pRespMsg) // was because the server was unavailable.
free(pRespMsg); if (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE)
{
free(pReqMsg); pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext,
} retStatus,
else NULL,
{ DEFAULT_RETRY_LIFETIME,
DbgTrace(0, "-ObtainSessionToken- Error building Authenticate msg\n", 0); pCredStoreScope);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN, }
CASA_STATUS_INSUFFICIENT_RESOURCES);
} // Release the cache entry if the resulting status is not successful
if (!CASA_SUCCESS(retStatus))
// Add the entry to the cache if successful or if the reason that we failed {
// was because the server was unavailable. FreeAuthCacheEntry(pCacheEntry);
if (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE) }
{
pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext,
retStatus,
NULL,
DEFAULT_RETRY_LIFETIME,
pCredStoreScope);
}
// Release the cache entry if the resulting status is not successful
if (!CASA_SUCCESS(retStatus))
{
FreeAuthCacheEntry(pCacheEntry);
}
// 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 else
{ {
// Free the entry // Free the entry
FreeAuthCacheEntry(pCacheEntry); FreeAuthCacheEntry(pCacheEntry);
} }
// Advance to the next entry // Advance to the next entry
@ -564,7 +564,7 @@ ObtainAuthTokenInt(
if (pCacheEntry == NULL) if (pCacheEntry == NULL)
{ {
// Initialize to retry in case of failure // Initialize to retry in case of failure
int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME; int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME;
// Cache entry created, now try to obtain auth token from the CASA Server // Cache entry created, now try to obtain auth token from the CASA Server
retStatus = ObtainAuthTokenFromServer(pServiceName, retStatus = ObtainAuthTokenFromServer(pServiceName,
@ -782,9 +782,6 @@ InitializeLibrary(void)
if (stricmp(pDisableSecureConnections, "true") == 0) if (stricmp(pDisableSecureConnections, "true") == 0)
{ {
g_rpcFlags &= ~SECURE_RPC_FLAG; g_rpcFlags &= ~SECURE_RPC_FLAG;
// Change the default ATS port to 80 from 443
g_ATSPort = 80;
} }
else if (stricmp(pDisableSecureConnections, "false") == 0) else if (stricmp(pDisableSecureConnections, "false") == 0)
{ {

View File

@ -56,6 +56,8 @@ typedef struct _GetAuthPolicyRespParse
XML_Parser p; XML_Parser p;
int state; int state;
int elementDataProcessed; int elementDataProcessed;
char *pStatusData;
int statusDataLen;
GetAuthPolicyResp *pGetAuthPolicyResp; GetAuthPolicyResp *pGetAuthPolicyResp;
CasaStatus status; CasaStatus status;
@ -199,7 +201,7 @@ GetAuthPolicyRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -214,7 +216,7 @@ GetAuthPolicyRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -229,7 +231,7 @@ GetAuthPolicyRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -244,7 +246,7 @@ GetAuthPolicyRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthPolicyRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -367,6 +369,8 @@ GetAuthPolicyRespCharDataHandler(
// L2 // L2
//=======================================================================-- //=======================================================================--
{ {
CasaStatus status;
DbgTrace(2, "-GetAuthPolicyRespCharDataHandler- Start\n", 0); DbgTrace(2, "-GetAuthPolicyRespCharDataHandler- Start\n", 0);
// Just exit if being called to process white space // Just exit if being called to process white space
@ -389,58 +393,42 @@ GetAuthPolicyRespCharDataHandler(
break; break;
case AWAITING_STATUS_DATA: case AWAITING_STATUS_DATA:
case AWAITING_STATUS_ELEMENT_END:
// Set the appropriate status in the AuthenticationResp based on the // Consume the data
// returned status. status = ConsumeElementData(pGetAuthPolicyRespParse,
if (strncmp(HTTP_OK_STATUS_CODE, s, len) == 0) s,
len,
&pGetAuthPolicyRespParse->pStatusData,
&pGetAuthPolicyRespParse->statusDataLen);
if (CASA_SUCCESS(status))
{ {
pGetAuthPolicyRespParse->status = CASA_STATUS_SUCCESS; // Advanced to the next state
} pGetAuthPolicyRespParse->state = AWAITING_STATUS_ELEMENT_END;
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE, s, len) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_NOT_CONFIGURED);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR);
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespCharDataHandler- Un-expected status\n", 0); pGetAuthPolicyRespParse->status = status;
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
} }
// Advanced to the next state
pGetAuthPolicyRespParse->state = AWAITING_STATUS_ELEMENT_END;
break; break;
case AWAITING_AUTH_POLICY_DATA: case AWAITING_AUTH_POLICY_DATA:
case AWAITING_AUTH_POLICY_ELEMENT_END: case AWAITING_AUTH_POLICY_ELEMENT_END:
pGetAuthPolicyRespParse->status = ConsumeElementData(pGetAuthPolicyRespParse, status = ConsumeElementData(pGetAuthPolicyRespParse,
s, s,
len, len,
&pGetAuthPolicyRespParse->pGetAuthPolicyResp->pPolicy, &pGetAuthPolicyRespParse->pGetAuthPolicyResp->pPolicy,
&pGetAuthPolicyRespParse->pGetAuthPolicyResp->policyLen); &pGetAuthPolicyRespParse->pGetAuthPolicyResp->policyLen);
if (CASA_SUCCESS(pGetAuthPolicyRespParse->status)) if (CASA_SUCCESS(status))
{ {
// Advanced to the next state // Advanced to the next state
pGetAuthPolicyRespParse->state = AWAITING_AUTH_POLICY_ELEMENT_END; pGetAuthPolicyRespParse->state = AWAITING_AUTH_POLICY_ELEMENT_END;
} }
else else
{ {
pGetAuthPolicyRespParse->status = status;
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -491,7 +479,7 @@ GetAuthPolicyRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespEndHandler- Un-expected end element\n", 0); DbgTrace(0, "-GetAuthPolicyRespEndHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -506,7 +494,7 @@ GetAuthPolicyRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -516,6 +504,45 @@ GetAuthPolicyRespEndElementHandler(
// In this state, we are only expecting the Status Element. // In this state, we are only expecting the Status Element.
if (strcmp(name, STATUS_ELEMENT_NAME) == 0) if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
{ {
// Set the appropriate status in the GetAuthPolicyResp based on the returned status data
if (strncmp(HTTP_OK_STATUS_CODE,
pGetAuthPolicyRespParse->pStatusData,
pGetAuthPolicyRespParse->statusDataLen) == 0)
{
pGetAuthPolicyRespParse->status = CASA_STATUS_SUCCESS;
}
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE,
pGetAuthPolicyRespParse->pStatusData,
pGetAuthPolicyRespParse->statusDataLen) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_NOT_FOUND_STATUS_CODE,
pGetAuthPolicyRespParse->pStatusData,
pGetAuthPolicyRespParse->statusDataLen) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_NOT_CONFIGURED);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE,
pGetAuthPolicyRespParse->pStatusData,
pGetAuthPolicyRespParse->statusDataLen) == 0)
{
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR);
}
else
{
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected status\n", 0);
pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
}
// Good, advance to the next state based on the status code. // Good, advance to the next state based on the status code.
if (CASA_SUCCESS(pGetAuthPolicyRespParse->status)) if (CASA_SUCCESS(pGetAuthPolicyRespParse->status))
{ {
@ -529,7 +556,7 @@ GetAuthPolicyRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -544,7 +571,7 @@ GetAuthPolicyRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthPolicyRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE); XML_StopParser(pGetAuthPolicyRespParse->p, XML_FALSE);
} }
break; break;
@ -636,7 +663,6 @@ CreateGetAuthPolicyResp(
// Set the character data handler // Set the character data handler
XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) GetAuthPolicyRespCharDataHandler); XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) GetAuthPolicyRespCharDataHandler);
// Set our user data // Set our user data
XML_SetUserData(p, &getAuthPolicyRespParse); XML_SetUserData(p, &getAuthPolicyRespParse);
@ -677,6 +703,10 @@ CreateGetAuthPolicyResp(
// Free the parser // Free the parser
XML_ParserFree(p); XML_ParserFree(p);
// Free any buffers associated with the parse
if (getAuthPolicyRespParse.pStatusData)
free(getAuthPolicyRespParse.pStatusData);
} }
else else
{ {

View File

@ -53,11 +53,15 @@
// //
typedef struct _GetAuthTokenRespParse typedef struct _GetAuthTokenRespParse
{ {
XML_Parser p; XML_Parser p;
int state; int state;
int elementDataProcessed; int elementDataProcessed;
GetAuthTokenResp *pGetAuthTokenResp; char *pStatusData;
CasaStatus status; int statusDataLen;
char *pLifetimeData;
int lifetimeDataLen;
GetAuthTokenResp *pGetAuthTokenResp;
CasaStatus status;
} GetAuthTokenRespParse, *PGetAuthTokenRespParse; } GetAuthTokenRespParse, *PGetAuthTokenRespParse;
@ -215,7 +219,7 @@ GetAuthTokenRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -230,7 +234,7 @@ GetAuthTokenRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -245,7 +249,7 @@ GetAuthTokenRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -260,7 +264,7 @@ GetAuthTokenRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -275,7 +279,7 @@ GetAuthTokenRespStartElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespStartElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -398,6 +402,8 @@ GetAuthTokenRespCharDataHandler(
// L2 // L2
//=======================================================================-- //=======================================================================--
{ {
CasaStatus status;
DbgTrace(2, "-GetAuthTokenRespCharDataHandler- Start\n", 0); DbgTrace(2, "-GetAuthTokenRespCharDataHandler- Start\n", 0);
// Just exit if being called to process white space // Just exit if being called to process white space
@ -420,62 +426,64 @@ GetAuthTokenRespCharDataHandler(
break; break;
case AWAITING_STATUS_DATA: case AWAITING_STATUS_DATA:
case AWAITING_STATUS_ELEMENT_END:
// Set the appropriate status in the AuthenticationResp based on the // Consume the data
// returned status. status = ConsumeElementData(pGetAuthTokenRespParse,
if (strncmp(HTTP_OK_STATUS_CODE, s, len) == 0) s,
len,
&pGetAuthTokenRespParse->pStatusData,
&pGetAuthTokenRespParse->statusDataLen);
if (CASA_SUCCESS(status))
{ {
pGetAuthTokenRespParse->status = CASA_STATUS_SUCCESS; // Advanced to the next state
} pGetAuthTokenRespParse->state = AWAITING_STATUS_ELEMENT_END;
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE, s, len) == 0)
{
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0)
{
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR);
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespCharDataHandler- Un-expected status\n", 0); pGetAuthTokenRespParse->status = status;
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
} }
// Advanced to the next state
pGetAuthTokenRespParse->state = AWAITING_STATUS_ELEMENT_END;
break; break;
case AWAITING_LIFETIME_DATA: case AWAITING_LIFETIME_DATA:
case AWAITING_LIFETIME_ELEMENT_END:
// Convert the lifetime string to a numeric value // Consume the data
pGetAuthTokenRespParse->pGetAuthTokenResp->tokenLifetime = dtoul(s, len); status = ConsumeElementData(pGetAuthTokenRespParse,
s,
// Advanced to the next state len,
pGetAuthTokenRespParse->state = AWAITING_LIFETIME_ELEMENT_END; &pGetAuthTokenRespParse->pLifetimeData,
&pGetAuthTokenRespParse->lifetimeDataLen);
if (CASA_SUCCESS(status))
{
// Advanced to the next state
pGetAuthTokenRespParse->state = AWAITING_LIFETIME_ELEMENT_END;
}
else
{
pGetAuthTokenRespParse->status = status;
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
}
break; break;
case AWAITING_AUTH_TOKEN_DATA: case AWAITING_AUTH_TOKEN_DATA:
case AWAITING_AUTH_TOKEN_ELEMENT_END: case AWAITING_AUTH_TOKEN_ELEMENT_END:
// Consume the data // Consume the data
pGetAuthTokenRespParse->status = ConsumeElementData(pGetAuthTokenRespParse, status = ConsumeElementData(pGetAuthTokenRespParse,
s, s,
len, len,
&pGetAuthTokenRespParse->pGetAuthTokenResp->pToken, &pGetAuthTokenRespParse->pGetAuthTokenResp->pToken,
&pGetAuthTokenRespParse->pGetAuthTokenResp->tokenLen); &pGetAuthTokenRespParse->pGetAuthTokenResp->tokenLen);
if (CASA_SUCCESS(pGetAuthTokenRespParse->status)) if (CASA_SUCCESS(status))
{ {
// Advanced to the next state // Advanced to the next state
pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_ELEMENT_END; pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_ELEMENT_END;
} }
else else
{ {
pGetAuthTokenRespParse->status = status;
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -526,7 +534,7 @@ GetAuthTokenRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespEndHandler- Un-expected end element\n", 0); DbgTrace(0, "-GetAuthTokenRespEndHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -541,7 +549,7 @@ GetAuthTokenRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected end element\n", 0); DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -551,6 +559,37 @@ GetAuthTokenRespEndElementHandler(
// In this state, we are only expecting the Status Element. // In this state, we are only expecting the Status Element.
if (strcmp(name, STATUS_ELEMENT_NAME) == 0) if (strcmp(name, STATUS_ELEMENT_NAME) == 0)
{ {
// Set the appropriate status in the GetAuthTokenResp based on the returned status data
if (strncmp(HTTP_OK_STATUS_CODE,
pGetAuthTokenRespParse->pStatusData,
pGetAuthTokenRespParse->statusDataLen) == 0)
{
pGetAuthTokenRespParse->status = CASA_STATUS_SUCCESS;
}
else if (strncmp(HTTP_UNAUTHORIZED_STATUS_CODE,
pGetAuthTokenRespParse->pStatusData,
pGetAuthTokenRespParse->statusDataLen) == 0)
{
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_AUTHENTICATION_FAILURE);
}
else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE,
pGetAuthTokenRespParse->pStatusData,
pGetAuthTokenRespParse->statusDataLen) == 0)
{
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_SERVER_ERROR);
}
else
{
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected status\n", 0);
pGetAuthTokenRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
}
// Good, advance to the next state based on the status code. // Good, advance to the next state based on the status code.
if (CASA_SUCCESS(pGetAuthTokenRespParse->status)) if (CASA_SUCCESS(pGetAuthTokenRespParse->status))
{ {
@ -564,7 +603,7 @@ GetAuthTokenRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -574,12 +613,16 @@ GetAuthTokenRespEndElementHandler(
// In this state, we are only expecting the Lifetime Element. // In this state, we are only expecting the Lifetime Element.
if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0) if (strcmp(name, LIFETIME_ELEMENT_NAME) == 0)
{ {
// Convert the lifetime string to a numeric value
pGetAuthTokenRespParse->pGetAuthTokenResp->tokenLifetime = dtoul(pGetAuthTokenRespParse->pLifetimeData,
pGetAuthTokenRespParse->lifetimeDataLen);
// Good, advance to the next state. // Good, advance to the next state.
pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_DATA; pGetAuthTokenRespParse->state = AWAITING_AUTH_TOKEN_DATA;
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -594,7 +637,7 @@ GetAuthTokenRespEndElementHandler(
} }
else else
{ {
DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected start element\n", 0); DbgTrace(0, "-GetAuthTokenRespEndElementHandler- Un-expected element\n", 0);
XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE); XML_StopParser(pGetAuthTokenRespParse->p, XML_FALSE);
} }
break; break;
@ -686,7 +729,6 @@ CreateGetAuthTokenResp(
// Set the character data handler // Set the character data handler
XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) GetAuthTokenRespCharDataHandler); XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler) GetAuthTokenRespCharDataHandler);
// Set our user data // Set our user data
XML_SetUserData(p, &getAuthTokenRespParse); XML_SetUserData(p, &getAuthTokenRespParse);
@ -727,6 +769,13 @@ CreateGetAuthTokenResp(
// Free the parser // Free the parser
XML_ParserFree(p); XML_ParserFree(p);
// Free any buffers associated with the parse
if (getAuthTokenRespParse.pStatusData)
free(getAuthTokenRespParse.pStatusData);
if (getAuthTokenRespParse.pLifetimeData)
free(getAuthTokenRespParse.pLifetimeData);
} }
else else
{ {

View File

@ -57,6 +57,7 @@ CFILES = ../authmech.c \
../util.c \ ../util.c \
../invalidcert.c \ ../invalidcert.c \
rpc.c \ rpc.c \
osslsupp.c \
platform.c platform.c
CSFILES_CSC := CSFILES_CSC :=

View File

@ -0,0 +1,323 @@
/***********************************************************************
*
* 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 ]==================================================
//===[ Function prototypes ]===============================================
//===[ Global variables ]==================================================
// Number of static locks required by OpenSSL
static
int g_numStaticLocks = 0;
// Mutex array for OpenSSL static locks
static
pthread_mutex_t *g_staticLocks = NULL;
//++=======================================================================
static void
StaticLockFunction(
IN int mode,
IN int n,
IN const char *file,
IN int line)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(2, "-StaticLockFunction- Start\n", 0);
// Verify that the lock number is within range
if (n < g_numStaticLocks
&& n >= 0)
{
// Either set or release the nth lock
if (mode & CRYPTO_LOCK)
{
// Set the lock
pthread_mutex_lock(&g_staticLocks[n]);
}
else
{
// Release the lock
pthread_mutex_unlock(&g_staticLocks[n]);
}
}
else
{
DbgTrace(2, "-StaticLockFunction- n out of range\n", 0);
}
DbgTrace(2, "-StaticLockFunction- End\n", 0);
}
//++=======================================================================
static void
DynLockFunction(
IN int mode,
IN struct CRYPTO_dynlock_value *l,
IN const char *file,
IN int line)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(2, "-DynLockFunction- Start\n", 0);
if (l)
{
// Either set or release the lock
if (mode & CRYPTO_LOCK)
{
// Set the lock
pthread_mutex_lock((pthread_mutex_t*) l);
}
else
{
// Release the lock
pthread_mutex_unlock((pthread_mutex_t*) l);
}
}
else
{
DbgTrace(2, "-DynLockFunction- Invalid parameter\n", 0);
}
DbgTrace(2, "-DynLockFunction- End\n", 0);
}
//++=======================================================================
static struct CRYPTO_dynlock_value*
CreateDynLockFunction(
IN const char *file,
IN int line)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
struct CRYPTO_dynlock_value *l;
DbgTrace(1, "-CreateDynLockFunction- Start\n", 0);
// Allocate space for the lock
l = (struct CRYPTO_dynlock_value*) malloc(sizeof(pthread_mutex_t));
if (l)
{
pthread_mutex_init((pthread_mutex_t*) l, NULL);
}
else
{
DbgTrace(0, "-CreateDynLockFunction- Buffer allocation failure\n", 0);
}
DbgTrace(1, "-CreateDynLockFunction- End, l = %0lX\n", (long) l);
return l;
}
//++=======================================================================
static void
DestroyDynLockFunction(
IN struct CRYPTO_dynlock_value *l,
IN const char *file,
IN int line)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
DbgTrace(1, "-DestroyDynLockFunction- Start, l = %0lX\n", (long) l);
if (l)
{
pthread_mutex_destroy((pthread_mutex_t*) l);
free(l);
}
DbgTrace(1, "-DestroyDynLockFunction- End\n", 0);
}
//++=======================================================================
static unsigned long
ThreadIdFunction(void)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
unsigned long threadId;
DbgTrace(2, "-ThreadIdFunction- Start\n", 0);
threadId = (unsigned long) pthread_self();
DbgTrace(2, "-ThreadIdFunction- End, id = %0lX\n", threadId);
return threadId;
}
//++=======================================================================
int
SetupOSSLSupport(void)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
int retStatus = -1;
int i;
DbgTrace(1, "-SetupOSSLSupport- Start\n", 0);
// Determine how many static locks are needed
g_numStaticLocks = CRYPTO_num_locks();
// Allocate space to hold the needed mutexes
g_staticLocks = malloc(sizeof(pthread_mutex_t) * g_numStaticLocks);
if (g_staticLocks)
{
for (i = 0; i < g_numStaticLocks; i++)
pthread_mutex_init(&g_staticLocks[i], NULL);
// Set callback functions
CRYPTO_set_id_callback(ThreadIdFunction);
CRYPTO_set_locking_callback(StaticLockFunction);
CRYPTO_set_dynlock_create_callback(CreateDynLockFunction);
CRYPTO_set_dynlock_destroy_callback(DestroyDynLockFunction);
CRYPTO_set_dynlock_lock_callback(DynLockFunction);
// Success
retStatus = 0;
}
else
{
DbgTrace(0, "-SetupOSSLSupport- Buffer allocation failure\n", 0);
}
DbgTrace(1, "-SetupOSSLSupport- End, retStatus = %0X\n", retStatus);
return retStatus;
}
//++=======================================================================
void
CleanupOSSLSupport(void)
//
// Arguments:
//
// Returns:
//
// Abstract:
//
// Notes:
//
// L2
//=======================================================================--
{
int i;
DbgTrace(1, "-CleanupOSSLSupport- Start\n", 0);
// Clear our callback functions
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
CRYPTO_set_dynlock_create_callback(NULL);
CRYPTO_set_dynlock_destroy_callback(NULL);
CRYPTO_set_dynlock_lock_callback(NULL);
// Now, cleanup the resources allocated for static locks
if (g_staticLocks)
{
for (i = 0; i < g_numStaticLocks; i++)
pthread_mutex_destroy(&g_staticLocks[i]);
free(g_staticLocks);
}
DbgTrace(1, "-CleanupOSSLSupport- End\n", 0);
}
//++=======================================================================
//++=======================================================================
//++=======================================================================

View File

@ -42,6 +42,7 @@ typedef struct _NormalizedHostNameCacheEntry
//===[ Type definitions for Local_sem ]==================================== //===[ Type definitions for Local_sem ]====================================
// //
// Notes: Most of the code for this definitions and the Local_sem_xxxx // Notes: Most of the code for this definitions and the Local_sem_xxxx
// functions was copied with minor modifications from W. Richard // functions was copied with minor modifications from W. Richard
@ -694,53 +695,65 @@ NormalizeHostName(
// Now try to resolve the normalized name // Now try to resolve the normalized name
pLookupResult = gethostbyname(pHostName); pLookupResult = gethostbyname(pHostName);
if (pLookupResult && pLookupResult->h_addrtype == AF_INET) if (pLookupResult
&& pLookupResult->h_addrtype == AF_INET
&& pLookupResult->h_length > 0
&& pLookupResult->h_addr_list[0] != NULL)
{ {
char dnsHostName[NI_MAXHOST]; char *pDnsHostName = (char*) malloc(NI_MAXHOST + 1);
if (pDnsHostName)
// Set up a sockaddr structure
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.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. // Set up a sockaddr structure
pEntry->buffLengthRequired = (int) strlen(dnsHostName) + 1; sockAddr.sin_family = AF_INET;
pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired); sockAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]);
if (pEntry->pNormalizedHostName)
// Now try to resolve the name using DNS
if (getnameinfo((const struct sockaddr*) &sockAddr,
sizeof(sockAddr),
pDnsHostName,
NI_MAXHOST,
NULL,
0,
NI_NAMEREQD) == 0)
{ {
// Copy the dns name // We resolved the address to a DNS name, use it as the normalized name.
strcpy(pEntry->pNormalizedHostName, dnsHostName); pEntry->buffLengthRequired = (int) strlen(pDnsHostName) + 1;
pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired);
if (pEntry->pNormalizedHostName)
{
// Copy the dns name
strcpy(pEntry->pNormalizedHostName, pDnsHostName);
}
else
{
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0);
}
} }
else else
{ {
DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); DbgTrace(0, "-NormalizeHostName- getnameInfo failed, error %d\n", errno);
// 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);
}
} }
// Free the buffer allocated to hold the DNS name
free(pDnsHostName);
} }
else else
{ {
DbgTrace(0, "-NormalizeHostName- getnameInfo failed, error %d\n", errno); DbgTrace(0, "-NormalizeHostName- Buffer allocation failure\n", 0);
// 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 else

View File

@ -45,6 +45,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/sem.h> #include <sys/sem.h>
#include <openssl/crypto.h>
//===[ Type definitions ]================================================== //===[ Type definitions ]==================================================

View File

@ -31,8 +31,19 @@
#define MAX_RPC_RETRIES 3 #define MAX_RPC_RETRIES 3
//===[ External prototypes ]===============================================
extern
int
SetupOSSLSupport(void);
extern
void
CleanupOSSLSupport(void);
//===[ Function prototypes ]=============================================== //===[ Function prototypes ]===============================================
//===[ Global variables ]================================================== //===[ Global variables ]==================================================
@ -307,7 +318,9 @@ InternalRpc(
// L2 // L2
//=======================================================================-- //=======================================================================--
{ {
#ifndef CASA_STATUS_INVALID_SERVER_CERTIFICATE
#define CASA_STATUS_INVALID_SERVER_CERTIFICATE CASA_STATUS_UNSUCCESSFUL // temporary until casa_status.h is updated #define CASA_STATUS_INVALID_SERVER_CERTIFICATE CASA_STATUS_UNSUCCESSFUL // temporary until casa_status.h is updated
#endif
CasaStatus retStatus; CasaStatus retStatus;
char *pPartialUrl; char *pPartialUrl;
@ -361,7 +374,6 @@ InternalRpc(
} }
pUrl = (char*) malloc(partialUrlLen + strlen(pMethod) + 1); pUrl = (char*) malloc(partialUrlLen + strlen(pMethod) + 1);
if (pUrl) if (pUrl)
{ {
strcpy(pUrl, pPartialUrl); strcpy(pUrl, pPartialUrl);
@ -465,7 +477,7 @@ InternalRpc(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(1, "-InternalRpc- End, retStatus = %d\n", retStatus); DbgTrace(1, "-InternalRpc- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -514,7 +526,7 @@ Rpc(
} while (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE } while (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE
&& retries < MAX_RPC_RETRIES); && retries < MAX_RPC_RETRIES);
DbgTrace(1, "-Rpc- End, retStatus = %d\n", retStatus); DbgTrace(1, "-Rpc- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -535,26 +547,34 @@ InitializeRpc(void)
// L2 // L2
//=======================================================================-- //=======================================================================--
{ {
CasaStatus retStatus; CasaStatus retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_AUTHTOKEN,
CASA_STATUS_UNSUCCESSFUL);
DbgTrace(1, "-InitializeRpc- Start\n", 0); DbgTrace(1, "-InitializeRpc- Start\n", 0);
// Perform libcurl initializatoin // Initialize OpenSSL support
CURLcode curlStatus = curl_global_init(CURL_GLOBAL_SSL); if (SetupOSSLSupport() == 0)
if (curlStatus != 0)
{ {
DbgTrace(0, "-InitializeRpc- Error initializing libcurl, curlStatus = %08X\n", curlStatus); // Perform libcurl initializatoin
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, CURLcode curlStatus = curl_global_init(CURL_GLOBAL_SSL);
CASA_FACILITY_AUTHTOKEN, if (curlStatus != 0)
CASA_STATUS_UNSUCCESSFUL); {
DbgTrace(0, "-InitializeRpc- Error initializing libcurl, curlStatus = %0X\n", curlStatus);
CleanupOSSLSupport();
}
else
{
// Success
retStatus = CASA_STATUS_SUCCESS;
}
} }
else else
{ {
// Success DbgTrace(0, "-InitializeRpc- OpenSSL support setup failure\n", 0);
retStatus = CASA_STATUS_SUCCESS;
} }
DbgTrace(1, "-InitializeRpc- End, retStatus = %08X\n", retStatus); DbgTrace(1, "-InitializeRpc- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }

View File

@ -75,7 +75,7 @@ AuthTokenIf_AddReference(
pAuthTokenIfInstance->refCount ++; pAuthTokenIfInstance->refCount ++;
refCount = pAuthTokenIfInstance->refCount; refCount = pAuthTokenIfInstance->refCount;
DbgTrace(2, "-AuthTokenIf_AddReference- End, refCount = %08X\n", refCount); DbgTrace(2, "-AuthTokenIf_AddReference- End, refCount = %0X\n", refCount);
return refCount; return refCount;
} }
@ -208,7 +208,7 @@ GET_AUTH_TOKEN_INTERFACE_RTN(
exit: exit:
DbgTrace(1, "-GetAuthTokenInterface- End, retStatus = %08X\n", retStatus); DbgTrace(1, "-GetAuthTokenInterface- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }

View File

@ -7,6 +7,27 @@
# # # #
####################################################### #######################################################
#
# LibraryName setting.
#
# Description: Used to specify the path to the library
# implementing the authentication mechanism.
#
LibraryName /usr/lib/CASA/authtoken/krb5mech.so LibraryName /usr/lib/CASA/authtoken/krb5mech.so
#
# DebugLevel setting.
#
# Description: Used to specify the level of logging utilized for debugging
# purposes. A level of zero being the lowest debugging level.
#
# If this parameter is not set, the client defaults
# to use a debug level of zero.
#
# Note: Debug statements can be viewed under Windows by using
# tools such as DbgView. Under Linux, debug statements are logged
# to /var/log/messages.
#
#DebugLevel 0

View File

@ -7,6 +7,26 @@
# # # #
####################################################### #######################################################
#
# LibraryName setting.
#
# Description: Used to specify the path to the library
# implementing the authentication mechanism.
#
LibraryName /usr/lib64/CASA/authtoken/krb5mech.so LibraryName /usr/lib64/CASA/authtoken/krb5mech.so
#
# DebugLevel setting.
#
# Description: Used to specify the level of logging utilized for debugging
# purposes. A level of zero being the lowest debugging level.
#
# If this parameter is not set, the client defaults
# to use a debug level of zero.
#
# Note: Debug statements can be viewed under Windows by using
# tools such as DbgView. Under Linux, debug statements are logged
# to /var/log/messages.
#
#DebugLevel 0

View File

@ -75,8 +75,11 @@ LogGssStatuses(
} }
// Trace this message // Trace this message
DbgTrace(0, "-LogGssStatuses- GSS-API error %s: ", operation); if (msg.value != NULL)
DbgTrace(0, "%s\n", (char *)msg.value); {
DbgTrace(0, "-LogGssStatuses- GSS-API error %s: ", operation);
DbgTrace(0, "%s\n", (char *)msg.value);
}
if (msg.length != 0) if (msg.length != 0)
gss_release_buffer(&gssMinStat, &msg); gss_release_buffer(&gssMinStat, &msg);
@ -102,8 +105,11 @@ LogGssStatuses(
} }
// Trace this message // Trace this message
DbgTrace(0, "-LogGssStatuses- GSS-API error %s: ", operation); if (msg.value != NULL)
DbgTrace(0, "%s\n", (char *)msg.value); {
DbgTrace(0, "-LogGssStatuses- GSS-API error %s: ", operation);
DbgTrace(0, "%s\n", (char *)msg.value);
}
if (msg.length != 0) if (msg.length != 0)
gss_release_buffer(&gssMinStat, &msg); gss_release_buffer(&gssMinStat, &msg);
@ -226,7 +232,7 @@ AuthTokenIf_GetAuthToken(
gssBuffer.length = strlen(pKrbServiceName) + 1; gssBuffer.length = strlen(pKrbServiceName) + 1;
if (strchr(pKrbServiceName, '@') != NULL) if (strchr(pKrbServiceName, '@') != NULL)
{ {
// The name is of the form "servicename@hostname" // The name is of the form "servicename@realmname"
gssMajStat = gss_import_name(&gssMinStat, gssMajStat = gss_import_name(&gssMinStat,
&gssBuffer, &gssBuffer,
(gss_OID) GSS_C_NT_HOSTBASED_SERVICE, (gss_OID) GSS_C_NT_HOSTBASED_SERVICE,
@ -290,7 +296,7 @@ AuthTokenIf_GetAuthToken(
else else
{ {
// The buffer provided is large enough, copy the data and return the actual size. // The buffer provided is large enough, copy the data and return the actual size.
memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen +1); memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen + 1);
// Success // Success
retStatus = CASA_STATUS_SUCCESS; retStatus = CASA_STATUS_SUCCESS;

View File

@ -80,7 +80,6 @@ EncodeData(
{ {
CasaStatus retStatus; CasaStatus retStatus;
int encodedSize; int encodedSize;
char *pTmp; char *pTmp;
DbgTrace(3, "-EncodeData- Start\n", 0); DbgTrace(3, "-EncodeData- Start\n", 0);
@ -141,7 +140,7 @@ EncodeData(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(3, "-EncodeData- End, retStatus = %08X\n", retStatus); DbgTrace(3, "-EncodeData- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -270,7 +269,7 @@ DecodeData(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(3, "-DecodeData- End, retStatus = %08X\n", retStatus); DbgTrace(3, "-DecodeData- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -312,7 +311,7 @@ dtoul(
} }
} }
DbgTrace(2, "-dtoul- End, result = %d\n", n); DbgTrace(2, "-dtoul- End, result = %0X\n", n);
return n; return n;
} }

View File

@ -7,6 +7,12 @@
# # # #
####################################################### #######################################################
#
# LibraryName setting.
#
# Description: Used to specify the path to the library
# implementing the authentication mechanism.
#
LibraryName \Program Files\novell\casa\lib\krb5mech.dll LibraryName \Program Files\novell\casa\lib\krb5mech.dll
# #

View File

@ -106,13 +106,23 @@ GetUserCredentials(
// There were no credentials for the realm, now try to obtain the // There were no credentials for the realm, now try to obtain the
// desktop credentials. // desktop credentials.
secretId.len = sscs_Utf8Strlen("Desktop") + 1; secretId.len = sscs_Utf8Strlen("Desktop") + 1;
sscs_Utf8Strcpy((char*) secretId.id, "Desktop"); if (secretId.len <= NSSCS_MAX_SECRET_ID_LEN)
rcode = miCASAGetCredential(0, {
&secretId, sscs_Utf8Strcpy((char*) secretId.id, "Desktop");
NULL, rcode = miCASAGetCredential(0,
&credtype, &secretId,
&credential, NULL,
(SSCS_EXT_T*) pCredStoreScope); &credtype,
&credential,
(SSCS_EXT_T*) pCredStoreScope);
}
else
{
DbgTrace(0, "-GetUserCredentials- Desktop name too long\n", 0);
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
CASA_FACILITY_PWTOKEN,
CASA_STATUS_UNSUCCESSFUL);
}
} }
} }
else else
@ -178,7 +188,7 @@ GetUserCredentials(
*ppPassword = pPassword; *ppPassword = pPassword;
} }
DbgTrace(1, "-GetUserCredentials- End, retStatus = %08X\n", retStatus); DbgTrace(1, "-GetUserCredentials- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }

View File

@ -75,7 +75,7 @@ AuthTokenIf_AddReference(
pAuthTokenIfInstance->refCount ++; pAuthTokenIfInstance->refCount ++;
refCount = pAuthTokenIfInstance->refCount; refCount = pAuthTokenIfInstance->refCount;
DbgTrace(2, "-AuthTokenIf_AddReference- End, refCount = %08X\n", refCount); DbgTrace(2, "-AuthTokenIf_AddReference- End, refCount = %0X\n", refCount);
return refCount; return refCount;
} }
@ -208,7 +208,7 @@ GET_AUTH_TOKEN_INTERFACE_RTN(
exit: exit:
DbgTrace(1, "-GetAuthTokenInterface- End, retStatus = %08X\n", retStatus); DbgTrace(1, "-GetAuthTokenInterface- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }

View File

@ -7,6 +7,25 @@
# # # #
####################################################### #######################################################
#
# LibraryName setting.
#
# Description: Used to specify the path to the library
# implementing the authentication mechanism.
#
LibraryName /usr/lib/CASA/authtoken/pwmech.so LibraryName /usr/lib/CASA/authtoken/pwmech.so
#
# DebugLevel setting.
#
# Description: Used to specify the level of logging utilized for debugging
# purposes. A level of zero being the lowest debugging level.
#
# If this parameter is not set, the client defaults
# to use a debug level of zero.
#
# Note: Debug statements can be viewed under Windows by using
# tools such as DbgView. Under Linux, debug statements are logged
# to /var/log/messages.
#
#DebugLevel 0

View File

@ -7,6 +7,25 @@
# # # #
####################################################### #######################################################
#
# LibraryName setting.
#
# Description: Used to specify the path to the library
# implementing the authentication mechanism.
#
LibraryName /usr/lib64/CASA/authtoken/pwmech.so LibraryName /usr/lib64/CASA/authtoken/pwmech.so
#
# DebugLevel setting.
#
# Description: Used to specify the level of logging utilized for debugging
# purposes. A level of zero being the lowest debugging level.
#
# If this parameter is not set, the client defaults
# to use a debug level of zero.
#
# Note: Debug statements can be viewed under Windows by using
# tools such as DbgView. Under Linux, debug statements are logged
# to /var/log/messages.
#
#DebugLevel 0

View File

@ -80,7 +80,6 @@ EncodeData(
{ {
CasaStatus retStatus; CasaStatus retStatus;
int encodedSize; int encodedSize;
char *pTmp; char *pTmp;
DbgTrace(3, "-EncodeData- Start\n", 0); DbgTrace(3, "-EncodeData- Start\n", 0);
@ -141,7 +140,7 @@ EncodeData(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(3, "-EncodeData- End, retStatus = %08X\n", retStatus); DbgTrace(3, "-EncodeData- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -270,7 +269,7 @@ DecodeData(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(3, "-DecodeData- End, retStatus = %08X\n", retStatus); DbgTrace(3, "-DecodeData- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -312,7 +311,7 @@ dtoul(
} }
} }
DbgTrace(2, "-dtoul- End, result = %d\n", n); DbgTrace(2, "-dtoul- End, result = %0X\n", n);
return n; return n;
} }

View File

@ -7,6 +7,12 @@
# # # #
####################################################### #######################################################
#
# LibraryName setting.
#
# Description: Used to specify the path to the library
# implementing the authentication mechanism.
#
LibraryName \Program Files\novell\casa\lib\pwmech.dll LibraryName \Program Files\novell\casa\lib\pwmech.dll
# #

View File

@ -124,113 +124,135 @@ EncodeData(
void NonHttpTest(void) void NonHttpTest(void)
{ {
CasaStatus retStatus; CasaStatus retStatus;
char authToken[8192]; char *pAuthToken;
int authTokenLen = sizeof(authToken); int authTokenLen = 0;
// Obtain an authentication token for the targeted service // First call to get the authentication token with no output buffer so
retStatus = ObtainAuthToken(pServiceName, pServerAddress, authToken, &authTokenLen); // that we can determine the buffer size necessary to hold the token.
if (!CASA_SUCCESS(retStatus)) retStatus = ObtainAuthToken(pServiceName, pServerAddress, NULL, &authTokenLen);
if (CasaStatusCode(retStatus) == CASA_STATUS_BUFFER_OVERFLOW)
{ {
printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus); // Allocate buffer to receive the token
} pAuthToken = (char*) malloc(authTokenLen);
else if (pAuthToken)
{
SOCKET sock;
struct sockaddr_in localAddr = {0};
struct sockaddr_in remoteAddr = {0};
struct linger linger_opt = {1, 15};
struct hostent *pLookupResult;
printf("-NonHttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
// Send the token to the server
//
// Open socket
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock != INVALID_SOCKET)
{ {
// Setup the local address structure // Now get the token
localAddr.sin_family = AF_INET; retStatus = ObtainAuthToken(pServiceName, pServerAddress, pAuthToken, &authTokenLen);
localAddr.sin_addr.s_addr = htonl(INADDR_ANY); if (!CASA_SUCCESS(retStatus))
// Bind socket
if (!bind(sock, (const struct sockaddr*) &localAddr, sizeof(struct sockaddr_in)))
{ {
// Resolve the server address printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus);
pLookupResult = gethostbyname(pServerAddress); }
if (pLookupResult) else
{
SOCKET sock;
struct sockaddr_in localAddr = {0};
struct sockaddr_in remoteAddr = {0};
struct linger linger_opt = {1, 15};
struct hostent *pLookupResult;
printf("-NonHttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
// Send the token to the server
//
// Open socket
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock != INVALID_SOCKET)
{ {
// Validate the address type returned // Setup the local address structure
if (pLookupResult->h_addrtype == AF_INET) localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
// Bind socket
if (!bind(sock, (const struct sockaddr*) &localAddr, sizeof(struct sockaddr_in)))
{ {
int numAddressesFound = 0; // Resolve the server address
pLookupResult = gethostbyname(pServerAddress);
// Determine how many addresses where returned if (pLookupResult)
while (pLookupResult->h_addr_list[numAddressesFound] != NULL)
{ {
//printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound])); // Validate the address type returned
numAddressesFound ++; if (pLookupResult->h_addrtype == AF_INET)
} {
//printf("Found %d addresses\n", numAddressesFound); int numAddressesFound = 0;
// Setup the remote address structure with the lookup results // Determine how many addresses where returned
remoteAddr.sin_family = AF_INET; while (pLookupResult->h_addr_list[numAddressesFound] != NULL)
remoteAddr.sin_port = serverPort; {
remoteAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]); // Short-cut //printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound]));
//printf("ServerAddress = %08X\n", remoteAddr.sin_addr.s_addr); numAddressesFound ++;
}
//printf("Found %d addresses\n", numAddressesFound);
// Perform connect operation // Setup the remote address structure with the lookup results
if (connect(sock, remoteAddr.sin_family = AF_INET;
(struct sockaddr*) &remoteAddr, remoteAddr.sin_port = serverPort;
sizeof(struct sockaddr_in)) == SOCKET_ERROR) remoteAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]); // Short-cut
{ //printf("ServerAddress = %08X\n", remoteAddr.sin_addr.s_addr);
printf("-NonHttpTest- Connection creation failed, error = %d\n", errno);
// Perform connect operation
if (connect(sock,
(struct sockaddr*) &remoteAddr,
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
printf("-NonHttpTest- Connection creation failed, error = %d\n", errno);
}
else
{
// Now the connection is setup, send the credentials to the server as one line.
// using our cheesy protocol followed by a hello string.
//
// Send the token to the server (including NULL terminator)
send(sock, pAuthToken, (int) strlen(pAuthToken) + 1, 0);
// Send new line
send(sock, "\n", 1, 0);
// Send "hello"
//send(sock, helloString, strlen(helloString) + 1, MSG_NOSIGNAL);
// Send new line
//send(sock, "\n", 1, 0);
// Shutdown the connection
shutdown(sock, 0);
}
}
else
{
printf("-NonHttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
}
} }
else else
{ {
// Now the connection is setup, send the credentials to the server as one line. printf("-NonHttpTest- Lookup for %s failed\n", pServerAddress);
// using our cheesy protocol followed by a hello string.
//
// Send the token to the server (including NULL terminator)
send(sock, authToken, (int) strlen(authToken) + 1, 0);
// Send new line
send(sock, "\n", 1, 0);
// Send "hello"
//send(sock, helloString, strlen(helloString) + 1, MSG_NOSIGNAL);
// Send new line
//send(sock, "\n", 1, 0);
// Shutdown the connection
shutdown(sock, 0);
} }
} }
else else
{ {
printf("-NonHttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); printf("-NonHttpTest- Unable to bind socket, error = %d", errno);
} }
// Close the socket
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char*) &linger_opt, sizeof(linger_opt));
closesocket(sock);
} }
else else
{ {
printf("-NonHttpTest- Lookup for %s failed\n", pServerAddress); printf("-NonHttpTest- Unable to open socket, error = %d\n", errno);
} }
} }
else
{ // Release the buffer allocated for the token
printf("-NonHttpTest- Unable to bind socket, error = %d", errno); free(pAuthToken);
}
// Close the socket
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char*) &linger_opt, sizeof(linger_opt));
closesocket(sock);
} }
else else
{ {
printf("-NonHttpTest- Unable to open socket, error = %d\n", errno); printf("-NonHttpTest- Failed to allocate buffer for token\n", 0);
} }
} }
else
{
printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus);
}
} }
@ -242,141 +264,162 @@ void NonHttpTest(void)
void HttpTest(void) void HttpTest(void)
{ {
CasaStatus retStatus; CasaStatus retStatus;
char authToken[4096]; char *pAuthToken;
int authTokenLen = sizeof(authToken); int authTokenLen = 0;
// Obtain an authentication token for the targeted service // First call to get the authentication token with no output buffer so
retStatus = ObtainAuthToken(pServiceName, pServerAddress, authToken, &authTokenLen); // that we can determine the buffer size necessary to hold the token.
if (!CASA_SUCCESS(retStatus)) retStatus = ObtainAuthToken(pServiceName, pServerAddress, NULL, &authTokenLen);
if (CasaStatusCode(retStatus) == CASA_STATUS_BUFFER_OVERFLOW)
{ {
printf("-HttpTest- ObtainAuthToken failed with status %d\n", retStatus); // Allocate buffer to receive the token
} pAuthToken = (char*) malloc(authTokenLen);
else if (pAuthToken)
{
SOCKET sock;
struct sockaddr_in localAddr = {0};
struct sockaddr_in remoteAddr = {0};
struct linger linger_opt = {1, 15};
struct hostent *pLookupResult;
//printf("ObtainAuthToken succedded, token = %s\n", authToken);
printf("-HttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
// Send the token to the server
// Open socket
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock != INVALID_SOCKET)
{ {
// Setup the local address structure // Now get the token
localAddr.sin_family = AF_INET; retStatus = ObtainAuthToken(pServiceName, pServerAddress, pAuthToken, &authTokenLen);
localAddr.sin_addr.s_addr = htonl(INADDR_ANY); if (!CASA_SUCCESS(retStatus))
// Bind socket
if (!bind(sock, (const struct sockaddr*) &localAddr, sizeof(struct sockaddr_in)))
{ {
// Resolve the server address printf("-HttpTest- ObtainAuthToken failed with status %0X\n", retStatus);
pLookupResult = gethostbyname(pServerAddress); }
if (pLookupResult) else
{
SOCKET sock;
struct sockaddr_in localAddr = {0};
struct sockaddr_in remoteAddr = {0};
struct linger linger_opt = {1, 15};
struct hostent *pLookupResult;
printf("-HttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
// Send the token to the server
// Open socket
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock != INVALID_SOCKET)
{ {
// Validate the address type returned // Setup the local address structure
if (pLookupResult->h_addrtype == AF_INET) localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
// Bind socket
if (!bind(sock, (const struct sockaddr*) &localAddr, sizeof(struct sockaddr_in)))
{ {
int numAddressesFound = 0; // Resolve the server address
pLookupResult = gethostbyname(pServerAddress);
// Determine how many addresses where returned if (pLookupResult)
while (pLookupResult->h_addr_list[numAddressesFound] != NULL)
{ {
//printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound])); // Validate the address type returned
numAddressesFound ++; if (pLookupResult->h_addrtype == AF_INET)
}
//printf("Found %d addresses\n", numAddressesFound);
// Setup the remote address structure with the lookup results
remoteAddr.sin_family = AF_INET;
remoteAddr.sin_port = serverPort;
remoteAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]); // Short-cut
//printf("ServerAddress = %08X\n", remoteAddr.sin_addr.s_addr);
// Perform connect operation
if (connect(sock,
(struct sockaddr*) &remoteAddr,
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
printf("-HttpTest- Connection creation failed, error = %d\n", errno);
}
else
{
char *pBasicCredentials;
char *pEncodedBasicCredentials;
int encodedLength;
char CasaPrincipal[] = "CasaPrincipal:";
char HTTPReqPart1[] = "GET /example-info HTTP/1.1\r\\nUser-Agent: CasaTestClient\r\nHost: jcstation.dnsdhcp.provo.novell.com:4096\r\nConnection: Keep-Alive\r\nAuthorization: Basic ";
// Now the connection is setup, send 1st part of HTTP request to the server.
send(sock, HTTPReqPart1, (int) strlen(HTTPReqPart1), 0);
// Now setup the HTTP Basic Credentials
pBasicCredentials = (char*) malloc(strlen(CasaPrincipal) + strlen(authToken) + 1);
if (pBasicCredentials)
{ {
memcpy(pBasicCredentials, CasaPrincipal, sizeof(CasaPrincipal)); int numAddressesFound = 0;
strcat(pBasicCredentials, authToken);
// Now Base64 encode the credentials // Determine how many addresses where returned
if (EncodeData((const void*) pBasicCredentials, while (pLookupResult->h_addr_list[numAddressesFound] != NULL)
(const int32_t) strlen(pBasicCredentials),
&pEncodedBasicCredentials,
(int32_t *) &encodedLength) == 0)
{ {
// Send the encoded credentials //printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound]));
send(sock, pEncodedBasicCredentials, encodedLength - 1, 0); numAddressesFound ++;
}
//printf("Found %d addresses\n", numAddressesFound);
// Send the rest of the header
send(sock, "\r\n\r\n", 4, 0);
// Free the buffer holding the encoded credentials // Setup the remote address structure with the lookup results
free(pEncodedBasicCredentials); remoteAddr.sin_family = AF_INET;
remoteAddr.sin_port = serverPort;
remoteAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]); // Short-cut
//printf("ServerAddress = %08X\n", remoteAddr.sin_addr.s_addr);
// Perform connect operation
if (connect(sock,
(struct sockaddr*) &remoteAddr,
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
printf("-HttpTest- Connection creation failed, error = %d\n", errno);
} }
else else
{ {
printf("-HttpTest- Error encoding credentials\n"); char *pBasicCredentials;
} char *pEncodedBasicCredentials;
int encodedLength;
char CasaPrincipal[] = "CasaPrincipal:";
char HTTPReqPart1[] = "GET /example-info HTTP/1.1\r\\nUser-Agent: CasaTestClient\r\nHost: jcstation.dnsdhcp.provo.novell.com:4096\r\nConnection: Keep-Alive\r\nAuthorization: Basic ";
// Free the buffer containing the basic credentials // Now the connection is setup, send 1st part of HTTP request to the server.
free(pBasicCredentials); send(sock, HTTPReqPart1, (int) strlen(HTTPReqPart1), 0);
// Now setup the HTTP Basic Credentials
pBasicCredentials = (char*) malloc(strlen(CasaPrincipal) + strlen(pAuthToken) + 1);
if (pBasicCredentials)
{
memcpy(pBasicCredentials, CasaPrincipal, sizeof(CasaPrincipal));
strcat(pBasicCredentials, pAuthToken);
// Now Base64 encode the credentials
if (EncodeData((const void*) pBasicCredentials,
(const int32_t) strlen(pBasicCredentials),
&pEncodedBasicCredentials,
(int32_t *) &encodedLength) == 0)
{
// Send the encoded credentials
send(sock, pEncodedBasicCredentials, encodedLength - 1, 0);
// Send the rest of the header
send(sock, "\r\n\r\n", 4, 0);
// Free the buffer holding the encoded credentials
free(pEncodedBasicCredentials);
}
else
{
printf("-HttpTest- Error encoding credentials\n");
}
// Free the buffer containing the basic credentials
free(pBasicCredentials);
}
else
{
printf("-HttpTest- Buffer allocation failure\n");
}
// Shutdown the connection
shutdown(sock, 0);
}
} }
else else
{ {
printf("-HttpTest- Buffer allocation failure\n"); printf("-HttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
} }
}
// Shutdown the connection else
shutdown(sock, 0); {
printf("-HttpTest- Lookup for %s failed\n", pServerAddress);
} }
} }
else else
{ {
printf("-HttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); printf("-HttpTest- Unable to bind socket, error = %d", errno);
} }
// Close the socket
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char*) &linger_opt, sizeof(linger_opt));
closesocket(sock);
} }
else else
{ {
printf("-HttpTest- Lookup for %s failed\n", pServerAddress); printf("-HttpTest- Unable to open socket, error = %d\n", errno);
} }
} }
else
{
printf("-HttpTest- Unable to bind socket, error = %d", errno);
}
// Close the socket // Release the buffer allocated for the token
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char*) &linger_opt, sizeof(linger_opt)); free(pAuthToken);
closesocket(sock);
} }
else else
{ {
printf("-HttpTest- Unable to open socket, error = %d\n", errno); printf("-HttpTest- Failed to allocate buffer for token\n", 0);
} }
} }
else
{
printf("-HttpTest- ObtainAuthToken failed with status %0X\n", retStatus);
}
} }

View File

@ -77,7 +77,6 @@ EncodeData(
{ {
CasaStatus retStatus; CasaStatus retStatus;
int encodedSize; int encodedSize;
char *pTmp; char *pTmp;
DbgTrace(3, "-EncodeData- Start\n", 0); DbgTrace(3, "-EncodeData- Start\n", 0);
@ -138,7 +137,7 @@ EncodeData(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(3, "-EncodeData- End, retStatus = %08X\n", retStatus); DbgTrace(3, "-EncodeData- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -267,7 +266,7 @@ DecodeData(
CASA_STATUS_INSUFFICIENT_RESOURCES); CASA_STATUS_INSUFFICIENT_RESOURCES);
} }
DbgTrace(3, "-DecodeData- End, retStatus = %08X\n", retStatus); DbgTrace(3, "-DecodeData- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }
@ -309,7 +308,7 @@ dtoul(
} }
} }
DbgTrace(2, "-dtoul- End, result = %d\n", n); DbgTrace(2, "-dtoul- End, result = %0X\n", n);
return n; return n;
} }

View File

@ -113,7 +113,7 @@ ObtainAuthTokenEx(
pAuthTokenBufLen, pAuthTokenBufLen,
pCredStoreScope); pCredStoreScope);
DbgTrace(1, "-ObtainAuthTokenEx- End, retStatus = %08X\n", retStatus); DbgTrace(1, "-ObtainAuthTokenEx- End, retStatus = %0X\n", retStatus);
return retStatus; return retStatus;
} }