diff --git a/CASA-auth-token/client/library/engine.c b/CASA-auth-token/client/library/engine.c index 6f9e6981..d2a39f44 100644 --- a/CASA-auth-token/client/library/engine.c +++ b/CASA-auth-token/client/library/engine.c @@ -166,23 +166,31 @@ ObtainSessionToken( &respLen); if (CASA_SUCCESS(retStatus)) { - AuthenticateResp *pAuthenticateResp; - - // Create Authenticate response object - retStatus = CreateAuthenticateResp(pRespMsg, respLen, &pAuthenticateResp); - if (CASA_SUCCESS(retStatus)) + if (pRespMsg + && respLen != 0) { - // Return the auth token to the caller - pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext, - retStatus, - pAuthenticateResp->pToken, - pAuthenticateResp->tokenLifetime, - pCredStoreScope); - - pAuthenticateResp->pToken = NULL; // To keep us from freeing the buffer - - // Free the Authenticate response object - RelAuthenticateResp(pAuthenticateResp); + AuthenticateResp *pAuthenticateResp; + + // Create Authenticate response object + retStatus = CreateAuthenticateResp(pRespMsg, respLen, &pAuthenticateResp); + if (CASA_SUCCESS(retStatus)) + { + // Return the auth token to the caller + pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext, + retStatus, + pAuthenticateResp->pToken, + pAuthenticateResp->tokenLifetime, + pCredStoreScope); + + pAuthenticateResp->pToken = NULL; // To keep us from freeing the buffer + + // Free the Authenticate response object + RelAuthenticateResp(pAuthenticateResp); + } + } + else + { + DbgTrace(0, "-ObtainSessionToken- Did not receive Authenticate Response data\n", 0); } } else @@ -330,82 +338,98 @@ ObtainAuthTokenFromServer( &respLen); if (CASA_SUCCESS(retStatus)) { - // Create GetAuthPolicy response object - retStatus = CreateGetAuthPolicyResp(pRespMsg, respLen, &pGetAuthPolicyResp); - if (CASA_SUCCESS(retStatus)) + if (pRespMsg + && respLen != 0) { - // Create the AuthPolicy object - retStatus = CreateAuthPolicy(pGetAuthPolicyResp->pPolicy, - pGetAuthPolicyResp->policyLen, - &pAuthPolicy); + // Create GetAuthPolicy response object + retStatus = CreateGetAuthPolicyResp(pRespMsg, respLen, &pGetAuthPolicyResp); if (CASA_SUCCESS(retStatus)) { - // Now try to obtain a session token - retStatus = ObtainSessionToken(pRpcSession, - pAuthPolicy, - (g_pATSHostName != NULL) ? g_pATSHostName : pHostName, - pCredStoreScope, - &pSessionToken); + // Create the AuthPolicy object + retStatus = CreateAuthPolicy(pGetAuthPolicyResp->pPolicy, + pGetAuthPolicyResp->policyLen, + &pAuthPolicy); if (CASA_SUCCESS(retStatus)) { - // Request auth token for the service - free(pReqMsg); - pReqMsg = BuildGetAuthTokenMsg(pServiceName, "localhost", pSessionToken); // tbd - This will be changed in the future so that we can support services residing in a different host than the ATS - if (pReqMsg) + // Now try to obtain a session token + retStatus = ObtainSessionToken(pRpcSession, + pAuthPolicy, + (g_pATSHostName != NULL) ? g_pATSHostName : pHostName, + pCredStoreScope, + &pSessionToken); + if (CASA_SUCCESS(retStatus)) { - // Free the previous response msg buffer - free(pRespMsg); - pRespMsg = NULL; - - // Issue rpc - retStatus = Rpc(pRpcSession, - "GetAuthToken", - g_rpcFlags, - pReqMsg, - &pRespMsg, - &respLen); - if (CASA_SUCCESS(retStatus)) + // Request auth token for the service + free(pReqMsg); + pReqMsg = BuildGetAuthTokenMsg(pServiceName, "localhost", pSessionToken); // tbd - This will be changed in the future so that we can support services residing in a different host than the ATS + if (pReqMsg) { - // Create GetAuthPolicy response object - retStatus = CreateGetAuthTokenResp(pRespMsg, respLen, &pGetAuthTokenResp); + // Free the previous response msg buffer + free(pRespMsg); + pRespMsg = NULL; + + // Issue rpc + retStatus = Rpc(pRpcSession, + "GetAuthToken", + g_rpcFlags, + pReqMsg, + &pRespMsg, + &respLen); if (CASA_SUCCESS(retStatus)) { - // Return the auth token to the caller - *ppAuthToken = pGetAuthTokenResp->pToken; - pGetAuthTokenResp->pToken = NULL; // To keep us from freeing the buffer - *pTokenLifetime = pGetAuthTokenResp->tokenLifetime; + if (pRespMsg + && respLen != 0) + { + // Create GetAuthPolicy response object + retStatus = CreateGetAuthTokenResp(pRespMsg, respLen, &pGetAuthTokenResp); + if (CASA_SUCCESS(retStatus)) + { + // Return the auth token to the caller + *ppAuthToken = pGetAuthTokenResp->pToken; + pGetAuthTokenResp->pToken = NULL; // To keep us from freeing the buffer + *pTokenLifetime = pGetAuthTokenResp->tokenLifetime; + } + else + { + DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create GetAuthTokenResp object, error = %08X\n", retStatus); + } + } + else + { + DbgTrace(0, "-ObtainAuthTokenFromServer- Did not receive GetAuthToken Response data\n", 0); + } } else { - DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create GetAuthTokenResp object, error = %08X\n", retStatus); + DbgTrace(0, "-ObtainAuthTokenFromServer- GetAuthToken Rpc failure, error = %08X\n", retStatus); } } else { - DbgTrace(0, "-ObtainAuthTokenFromServer- GetAuthToken Rpc failure, error = %08X\n", retStatus); + DbgTrace(0, "-ObtainAuthTokenFromServer- Error building GetAuthToken msg\n", 0); + retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, + CASA_FACILITY_AUTHTOKEN, + CASA_STATUS_INSUFFICIENT_RESOURCES); } } else { - DbgTrace(0, "-ObtainAuthTokenFromServer- Error building GetAuthToken msg\n", 0); - retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, - CASA_FACILITY_AUTHTOKEN, - CASA_STATUS_INSUFFICIENT_RESOURCES); + DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to obtain session token, error = %08X\n", retStatus); } } else { - DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to obtain session token, error = %08X\n", retStatus); + DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create AuthPolicy object, error = %08X\n", retStatus); } } else { - DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create AuthPolicy object, error = %08X\n", retStatus); + DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create GetAuthPolicyResp object, error = %08X\n", retStatus); } } else { - DbgTrace(0, "-ObtainAuthTokenFromServer- Failed to create GetAuthPolicyResp object, error = %08X\n", retStatus); + DbgTrace(0, "-ObtainAuthTokenFromServer- Did not receive GetAuthPolicy Response data\n", 0); } } else