Made some formatting changes, added some additional debug statements, and updated the project file to adjust for the new directory structure.
This commit is contained in:
		| @@ -59,7 +59,7 @@ AuthCacheEntry* | ||||
| CreateAuthTokenCacheEntry( | ||||
|    IN    const char *pCacheKey, | ||||
|    IN    const char *pGroupOrHostName, | ||||
|    IN	 CasaStatus status, | ||||
|    IN    CasaStatus status, | ||||
|    IN    unsigned char *pToken, | ||||
|    IN    int entryLifetime // seconds (0 == Lives forever) | ||||
|    ) | ||||
| @@ -75,23 +75,23 @@ CreateAuthTokenCacheEntry( | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus        	retStatus; | ||||
|    CasaStatus           retStatus; | ||||
|    SSCS_KEYCHAIN_ID_T   sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"}; | ||||
|    SSCS_SECRET_ID_T     sharedId = {27, "CASA_AUTHENTICATION_TOKENS"}; | ||||
|    uint32_t             tokenSize, entrySize, keySize; | ||||
|    AuthCacheEntry 		*pEntry = NULL; | ||||
|    unsigned char		*pKey; | ||||
|    AuthCacheEntry       *pEntry = NULL; | ||||
|    unsigned char     *pKey; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-CreateAuthTokenCacheEntry- Start\n", 0); | ||||
|  | ||||
|    if (status == CASA_STATUS_SUCCESS) | ||||
|    { | ||||
| 	  tokenSize = (uint32_t)strlen(pToken); | ||||
|       tokenSize = (uint32_t)strlen(pToken); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
| 	  tokenSize = 0; | ||||
|       tokenSize = 0; | ||||
|    } | ||||
|  | ||||
|    entrySize = tokenSize + sizeof(AuthCacheEntry); | ||||
| @@ -101,69 +101,68 @@ CreateAuthTokenCacheEntry( | ||||
|    pEntry = (AuthCacheEntry*) malloc(entrySize); | ||||
|    if (pEntry) | ||||
|    { | ||||
| 	  // Set the status | ||||
| 	  pEntry->status = status; | ||||
|  | ||||
| 	  if (pEntry->status == CASA_STATUS_SUCCESS) | ||||
| 	  { | ||||
| 		 memcpy(&pEntry->token[0], pToken, tokenSize); | ||||
| 	  } | ||||
|  | ||||
| 	  pEntry->token[tokenSize] = '\0'; | ||||
|  | ||||
| 	  // Set the time when the entry was added to the cache | ||||
| 	  pEntry->creationTime = GetTickCount(); | ||||
|  | ||||
| 	  // First determine the time when the entry is due to expire | ||||
| 	  if (entryLifetime != 0) | ||||
| 	  { | ||||
| 		 pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); | ||||
| 		 pEntry->doesNotExpire = FALSE; | ||||
| 	  } | ||||
| 	  else | ||||
| 	  { | ||||
| 		 // The entry does not expire | ||||
| 		 pEntry->expirationTime = 0; | ||||
| 		 pEntry->doesNotExpire = TRUE; | ||||
| 	  } | ||||
|  | ||||
| 	  keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2; | ||||
|  | ||||
| 	  pKey = malloc(keySize); | ||||
|  | ||||
| 	  if (pKey) | ||||
| 	  { | ||||
| 		 strncpy(pKey, pCacheKey, keySize); | ||||
| 		 strncat(pKey, "@", keySize); | ||||
| 		 strncat(pKey, pGroupOrHostName, keySize); | ||||
|  | ||||
| 		 retStatus = miCASAWriteBinaryKey( | ||||
| 						g_hCASAContext, | ||||
| 						0, | ||||
| 						&sessionKeyChain, | ||||
| 						&sharedId, | ||||
| 						pKey, | ||||
| 						keySize, | ||||
| 						(uint8_t *)pEntry, | ||||
| 						&entrySize, | ||||
| 						NULL, | ||||
| 						NULL); | ||||
|  | ||||
|  | ||||
| 		 free(pKey); | ||||
| 	  } | ||||
| 	  else | ||||
| 	  { | ||||
| 		 retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
| 									 CASA_FACILITY_AUTHTOKEN, | ||||
| 									 CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
| 	  } | ||||
|       // Set the status | ||||
|       pEntry->status = status; | ||||
|        | ||||
|       if (pEntry->status == CASA_STATUS_SUCCESS) | ||||
|       { | ||||
|          memcpy(&pEntry->token[0], pToken, tokenSize); | ||||
|       } | ||||
|        | ||||
|       pEntry->token[tokenSize] = '\0'; | ||||
|        | ||||
|       // Set the time when the entry was added to the cache | ||||
|       pEntry->creationTime = GetTickCount(); | ||||
|        | ||||
|       // First determine the time when the entry is due to expire | ||||
|       if (entryLifetime != 0) | ||||
|       { | ||||
|          pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); | ||||
|          pEntry->doesNotExpire = FALSE; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          // The entry does not expire | ||||
|          pEntry->expirationTime = 0; | ||||
|          pEntry->doesNotExpire = TRUE; | ||||
|       } | ||||
|        | ||||
|       keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2; | ||||
|        | ||||
|       pKey = malloc(keySize); | ||||
|        | ||||
|       if (pKey) | ||||
|       { | ||||
|          strncpy(pKey, pCacheKey, keySize); | ||||
|          strncat(pKey, "@", keySize); | ||||
|          strncat(pKey, pGroupOrHostName, keySize); | ||||
|        | ||||
|          retStatus = miCASAWriteBinaryKey(g_hCASAContext, | ||||
|                                           0, | ||||
|                                           &sessionKeyChain, | ||||
|                                           &sharedId, | ||||
|                                           pKey, | ||||
|                                           keySize, | ||||
|                                           (uint8_t *)pEntry, | ||||
|                                           &entrySize, | ||||
|                                           NULL, | ||||
|                                           NULL); | ||||
|        | ||||
|        | ||||
|          free(pKey); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                      CASA_FACILITY_AUTHTOKEN, | ||||
|                                      CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       } | ||||
|    } | ||||
|    else | ||||
|    { | ||||
| 	  retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
| 								  CASA_FACILITY_AUTHTOKEN, | ||||
| 								  CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-CreateAuthTokenCacheEntry- End, pEntry = %08X\n", pEntry); | ||||
| @@ -176,7 +175,7 @@ CreateAuthTokenCacheEntry( | ||||
| AuthCacheEntry* | ||||
| CreateSessionTokenCacheEntry( | ||||
|    IN    const char *pCacheKey, | ||||
|    IN	 CasaStatus status, | ||||
|    IN    CasaStatus status, | ||||
|    IN    unsigned char *pToken, | ||||
|    IN    int entryLifetime // seconds (0 == Lives forever) | ||||
|    ) | ||||
| @@ -192,22 +191,22 @@ CreateSessionTokenCacheEntry( | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus        	retStatus; | ||||
|    CasaStatus           retStatus; | ||||
|    SSCS_KEYCHAIN_ID_T   sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"}; | ||||
|    SSCS_SECRET_ID_T     sharedId = {20, "CASA_SESSION_TOKENS"}; | ||||
|    uint32_t             tokenSize, entrySize; | ||||
|    AuthCacheEntry 		*pEntry = NULL; | ||||
|    AuthCacheEntry       *pEntry = NULL; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-CreateSessionTokenCacheEntry- Start\n", 0); | ||||
|  | ||||
|    if (status == CASA_STATUS_SUCCESS) | ||||
|    { | ||||
| 	  tokenSize = (uint32_t)strlen(pToken); | ||||
|       tokenSize = (uint32_t)strlen(pToken); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
| 	  tokenSize = 0; | ||||
|       tokenSize = 0; | ||||
|    } | ||||
|  | ||||
|    entrySize = tokenSize + sizeof(AuthCacheEntry); | ||||
| @@ -217,49 +216,48 @@ CreateSessionTokenCacheEntry( | ||||
|    pEntry = (AuthCacheEntry*) malloc(entrySize); | ||||
|    if (pEntry) | ||||
|    { | ||||
| 	  // Set the status | ||||
| 	  pEntry->status = status; | ||||
|  | ||||
| 	  if (pEntry->status == CASA_STATUS_SUCCESS) | ||||
| 	  { | ||||
| 		 memcpy(&pEntry->token[0], pToken, tokenSize); | ||||
| 	  } | ||||
|  | ||||
| 	  pEntry->token[tokenSize] = '\0'; | ||||
|  | ||||
| 	  // Set the time when the entry was added to the cache | ||||
| 	  pEntry->creationTime = GetTickCount(); | ||||
|  | ||||
| 	  // First determine the time when the entry is due to expire | ||||
| 	  if (entryLifetime != 0) | ||||
| 	  { | ||||
| 		 pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); | ||||
| 		 pEntry->doesNotExpire = FALSE; | ||||
| 	  } | ||||
| 	  else | ||||
| 	  { | ||||
| 		 // The entry does not expire | ||||
| 		 pEntry->expirationTime = 0; | ||||
| 		 pEntry->doesNotExpire = TRUE; | ||||
| 	  } | ||||
|  | ||||
| 	  retStatus = miCASAWriteBinaryKey( | ||||
| 					 g_hCASAContext, | ||||
| 					 0, | ||||
| 					 &sessionKeyChain, | ||||
| 					 &sharedId, | ||||
| 					 (char *)pCacheKey, | ||||
| 					 (uint32_t)strlen(pCacheKey) + 1, | ||||
| 					 (uint8_t *)pEntry, | ||||
| 					 &entrySize, | ||||
| 					 NULL, | ||||
| 					 NULL); | ||||
|       // Set the status | ||||
|       pEntry->status = status; | ||||
|        | ||||
|       if (pEntry->status == CASA_STATUS_SUCCESS) | ||||
|       { | ||||
|          memcpy(&pEntry->token[0], pToken, tokenSize); | ||||
|       } | ||||
|        | ||||
|       pEntry->token[tokenSize] = '\0'; | ||||
|        | ||||
|       // Set the time when the entry was added to the cache | ||||
|       pEntry->creationTime = GetTickCount(); | ||||
|        | ||||
|       // First determine the time when the entry is due to expire | ||||
|       if (entryLifetime != 0) | ||||
|       { | ||||
|          pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); | ||||
|          pEntry->doesNotExpire = FALSE; | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          // The entry does not expire | ||||
|          pEntry->expirationTime = 0; | ||||
|          pEntry->doesNotExpire = TRUE; | ||||
|       } | ||||
|        | ||||
|       retStatus = miCASAWriteBinaryKey(g_hCASAContext, | ||||
|                                        0, | ||||
|                                        &sessionKeyChain, | ||||
|                                        &sharedId, | ||||
|                                        (char *)pCacheKey, | ||||
|                                        (uint32_t)strlen(pCacheKey) + 1, | ||||
|                                        (uint8_t *)pEntry, | ||||
|                                        &entrySize, | ||||
|                                        NULL, | ||||
|                                        NULL); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
| 	  retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
| 								  CASA_FACILITY_AUTHTOKEN, | ||||
| 								  CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                   CASA_FACILITY_AUTHTOKEN, | ||||
|                                   CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-CreateSessionTokenCacheEntry- End, pEntry = %08X\n", pEntry); | ||||
| @@ -380,11 +378,11 @@ FindSessionTokenEntryInCache( | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus        	retStatus; | ||||
|    CasaStatus           retStatus; | ||||
|    SSCS_KEYCHAIN_ID_T   sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"}; | ||||
|    SSCS_SECRET_ID_T     sharedId = {20, "CASA_SESSION_TOKENS"}; | ||||
|    uint32_t             valueLength, bytesRequired; | ||||
|    AuthCacheEntry 		*pEntry = NULL; | ||||
|    AuthCacheEntry       *pEntry = NULL; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-FindSessionTokenEntryInCache- Start\n", 0); | ||||
| @@ -392,64 +390,61 @@ FindSessionTokenEntryInCache( | ||||
|    valueLength = 0; | ||||
|    bytesRequired = 0; | ||||
|  | ||||
|    retStatus = miCASAReadBinaryKey( | ||||
| 				  g_hCASAContext, | ||||
| 				  0, | ||||
| 				  &sessionKeyChain, | ||||
| 				  &sharedId, | ||||
| 				  (char *)pCacheKey, | ||||
| 				  (uint32_t)strlen(pCacheKey) + 1, | ||||
| 				  NULL, | ||||
| 				  &valueLength, | ||||
| 				  NULL, | ||||
| 				  &bytesRequired, | ||||
| 				  NULL); | ||||
|    retStatus = miCASAReadBinaryKey(g_hCASAContext, | ||||
|                                    0, | ||||
|                                    &sessionKeyChain, | ||||
|                                    &sharedId, | ||||
|                                    (char *)pCacheKey, | ||||
|                                    (uint32_t)strlen(pCacheKey) + 1, | ||||
|                                    NULL, | ||||
|                                    &valueLength, | ||||
|                                    NULL, | ||||
|                                    &bytesRequired, | ||||
|                                    NULL); | ||||
|  | ||||
|    if (retStatus == NSSCS_E_ENUM_BUFF_TOO_SHORT | ||||
| 	   && bytesRequired != 0) | ||||
|        && bytesRequired != 0) | ||||
|    { | ||||
| 	  pEntry = (AuthCacheEntry*) malloc(bytesRequired); | ||||
|  | ||||
| 	  if (pEntry) | ||||
| 	  { | ||||
| 		 valueLength = bytesRequired; | ||||
| 		 bytesRequired = 0; | ||||
|  | ||||
| 		 retStatus = miCASAReadBinaryKey( | ||||
| 						g_hCASAContext, | ||||
| 						0, | ||||
| 						&sessionKeyChain, | ||||
| 						&sharedId, | ||||
| 						(char *)pCacheKey, | ||||
| 						(uint32_t)strlen(pCacheKey) + 1, | ||||
| 						(uint8_t *)pEntry, | ||||
| 						&valueLength, | ||||
| 						NULL, | ||||
| 						&bytesRequired, | ||||
| 						NULL); | ||||
|  | ||||
| 		 if (CASA_SUCCESS(retStatus)) | ||||
| 		 { | ||||
| 			if (pEntry->doesNotExpire == FALSE | ||||
| 				&& CacheEntryLifetimeExpired(pEntry->creationTime, pEntry->expirationTime)) | ||||
| 			{ | ||||
| 			   // Remove the entry ??? | ||||
| 			   //miCASARemoveBinaryKey(); | ||||
|  | ||||
| 			   retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
| 										   CASA_FACILITY_AUTHTOKEN, | ||||
| 										   CASA_STATUS_UNSUCCESSFUL); | ||||
| 			} | ||||
| 		 } | ||||
|  | ||||
| 		 if (!CASA_SUCCESS(retStatus)) | ||||
| 		 { | ||||
| 			FreeAuthCacheEntry(pEntry); | ||||
| 			pEntry = NULL; | ||||
| 		 } | ||||
| 	  } | ||||
|       pEntry = (AuthCacheEntry*) malloc(bytesRequired); | ||||
|        | ||||
|       if (pEntry) | ||||
|       { | ||||
|          valueLength = bytesRequired; | ||||
|          bytesRequired = 0; | ||||
|           | ||||
|          retStatus = miCASAReadBinaryKey(g_hCASAContext, | ||||
|                                          0, | ||||
|                                          &sessionKeyChain, | ||||
|                                          &sharedId, | ||||
|                                          (char *)pCacheKey, | ||||
|                                          (uint32_t)strlen(pCacheKey) + 1, | ||||
|                                          (uint8_t *)pEntry, | ||||
|                                          &valueLength, | ||||
|                                          NULL, | ||||
|                                          &bytesRequired, | ||||
|                                          NULL); | ||||
|          if (CASA_SUCCESS(retStatus)) | ||||
|          { | ||||
|             if (pEntry->doesNotExpire == FALSE | ||||
|                 && CacheEntryLifetimeExpired(pEntry->creationTime, pEntry->expirationTime)) | ||||
|             { | ||||
|                // Remove the entry ??? | ||||
|                //miCASARemoveBinaryKey(); | ||||
|              | ||||
|                retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                            CASA_FACILITY_AUTHTOKEN, | ||||
|                                            CASA_STATUS_UNSUCCESSFUL); | ||||
|             } | ||||
|          } | ||||
|           | ||||
|          if (!CASA_SUCCESS(retStatus)) | ||||
|          { | ||||
|             FreeAuthCacheEntry(pEntry); | ||||
|             pEntry = NULL; | ||||
|          } | ||||
|       } | ||||
|    } | ||||
| 				   | ||||
|                | ||||
|    DbgTrace(1, "-FindSessionTokenEntryInCache- End, pEntry = %08X\n", pEntry); | ||||
|  | ||||
|    return pEntry; | ||||
| @@ -473,12 +468,12 @@ FindAuthTokenEntryInCache( | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus        	retStatus; | ||||
|    CasaStatus           retStatus; | ||||
|    SSCS_KEYCHAIN_ID_T   sessionKeyChain = {26, "SSCS_SESSION_KEY_CHAIN_ID"}; | ||||
|    SSCS_SECRET_ID_T     sharedId = {27, "CASA_AUTHENTICATION_TOKENS"}; | ||||
|    uint32_t             valueLength, bytesRequired, keySize; | ||||
|    AuthCacheEntry 		*pEntry = NULL; | ||||
|    unsigned char		*pKey; | ||||
|    AuthCacheEntry       *pEntry = NULL; | ||||
|    unsigned char        *pKey; | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-FindAuthTokenEntryInCache- Start\n", 0); | ||||
| @@ -486,75 +481,71 @@ FindAuthTokenEntryInCache( | ||||
|    keySize = (uint32_t)strlen(pCacheKey) + (uint32_t)strlen(pGroupOrHostName) + 2; | ||||
|  | ||||
|    pKey = malloc(keySize); | ||||
|  | ||||
|    if (pKey) | ||||
|    { | ||||
| 	  strncpy(pKey, pCacheKey, keySize); | ||||
| 	  strncat(pKey, "@", keySize); | ||||
| 	  strncat(pKey, pGroupOrHostName, keySize); | ||||
|  | ||||
| 	  valueLength = 0; | ||||
| 	  bytesRequired = 0; | ||||
|     | ||||
| 	  retStatus = miCASAReadBinaryKey( | ||||
| 					 g_hCASAContext, | ||||
| 					 0, | ||||
| 					 &sessionKeyChain, | ||||
| 					 &sharedId, | ||||
| 					 pKey, | ||||
| 					 keySize, | ||||
| 					 NULL, | ||||
| 					 &valueLength, | ||||
| 					 NULL, | ||||
| 					 &bytesRequired, | ||||
| 					 NULL); | ||||
|     | ||||
| 	  if (retStatus == NSSCS_E_ENUM_BUFF_TOO_SHORT | ||||
| 		  && bytesRequired != 0) | ||||
| 	  { | ||||
| 		 pEntry = (AuthCacheEntry*) malloc(bytesRequired); | ||||
|     | ||||
| 		 if (pEntry) | ||||
| 		 { | ||||
| 			valueLength = bytesRequired; | ||||
| 			bytesRequired = 0; | ||||
|     | ||||
| 			retStatus = miCASAReadBinaryKey( | ||||
| 						   g_hCASAContext, | ||||
| 						   0, | ||||
| 						   &sessionKeyChain, | ||||
| 						   &sharedId, | ||||
| 						   pKey, | ||||
| 						   keySize, | ||||
| 						   (uint8_t *)pEntry, | ||||
| 						   &valueLength, | ||||
| 						   NULL, | ||||
| 						   &bytesRequired, | ||||
| 						   NULL); | ||||
|  | ||||
| 			if (CASA_SUCCESS(retStatus)) | ||||
| 			{ | ||||
| 			   if (pEntry->doesNotExpire == FALSE | ||||
| 				   && CacheEntryLifetimeExpired(pEntry->creationTime, pEntry->expirationTime)) | ||||
| 			   { | ||||
| 				  // Remove the entry ??? | ||||
| 				  //miCASARemoveBinaryKey(); | ||||
|  | ||||
| 				  retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
| 											  CASA_FACILITY_AUTHTOKEN, | ||||
| 											  CASA_STATUS_UNSUCCESSFUL); | ||||
| 			   } | ||||
| 			} | ||||
|  | ||||
| 			if (!CASA_SUCCESS(retStatus)) | ||||
| 			{ | ||||
| 			   FreeAuthCacheEntry(pEntry); | ||||
| 			   pEntry = NULL; | ||||
| 			} | ||||
| 		 } | ||||
| 	  } | ||||
|  | ||||
| 	  free(pKey); | ||||
|       strncpy(pKey, pCacheKey, keySize); | ||||
|       strncat(pKey, "@", keySize); | ||||
|       strncat(pKey, pGroupOrHostName, keySize); | ||||
|        | ||||
|       valueLength = 0; | ||||
|       bytesRequired = 0; | ||||
|        | ||||
|       retStatus = miCASAReadBinaryKey(g_hCASAContext, | ||||
|                                       0, | ||||
|                                       &sessionKeyChain, | ||||
|                                       &sharedId, | ||||
|                                       pKey, | ||||
|                                       keySize, | ||||
|                                       NULL, | ||||
|                                       &valueLength, | ||||
|                                       NULL, | ||||
|                                       &bytesRequired, | ||||
|                                       NULL); | ||||
|        | ||||
|       if (retStatus == NSSCS_E_ENUM_BUFF_TOO_SHORT | ||||
|           && bytesRequired != 0) | ||||
|       { | ||||
|          pEntry = (AuthCacheEntry*) malloc(bytesRequired); | ||||
|           | ||||
|          if (pEntry) | ||||
|          { | ||||
|             valueLength = bytesRequired; | ||||
|             bytesRequired = 0; | ||||
|              | ||||
|             retStatus = miCASAReadBinaryKey(g_hCASAContext, | ||||
|                                             0, | ||||
|                                             &sessionKeyChain, | ||||
|                                             &sharedId, | ||||
|                                             pKey, | ||||
|                                             keySize, | ||||
|                                             (uint8_t *)pEntry, | ||||
|                                             &valueLength, | ||||
|                                             NULL, | ||||
|                                             &bytesRequired, | ||||
|                                             NULL); | ||||
|             if (CASA_SUCCESS(retStatus)) | ||||
|             { | ||||
|                if (pEntry->doesNotExpire == FALSE | ||||
|                    && CacheEntryLifetimeExpired(pEntry->creationTime, pEntry->expirationTime)) | ||||
|                { | ||||
|                  // Remove the entry ??? | ||||
|                  //miCASARemoveBinaryKey(); | ||||
|              | ||||
|                  retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                              CASA_FACILITY_AUTHTOKEN, | ||||
|                                              CASA_STATUS_UNSUCCESSFUL); | ||||
|                } | ||||
|             } | ||||
|              | ||||
|             if (!CASA_SUCCESS(retStatus)) | ||||
|             { | ||||
|                FreeAuthCacheEntry(pEntry); | ||||
|                pEntry = NULL; | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|        | ||||
|       free(pKey); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-FindAuthTokenEntryInCache- End, pEntry = %08X\n", pEntry); | ||||
| @@ -578,7 +569,7 @@ InitializeAuthCache() | ||||
| // L2 | ||||
| //=======================================================================-- | ||||
| { | ||||
|    CasaStatus 			retStatus; | ||||
|    CasaStatus           retStatus; | ||||
|    SSCS_SECRETSTORE_T   ssId; | ||||
|  | ||||
|    DbgTrace(1, "-InitializeAuthCache- Start\n", 0); | ||||
| @@ -586,21 +577,18 @@ InitializeAuthCache() | ||||
|    ssId.version = NSSCS_VERSION_NUMBER; | ||||
|    strcpy((char *)ssId.ssName, (char *)SSCS_DEFAULT_SECRETSTORE_ID); | ||||
|  | ||||
|    g_hCASAContext = miCASAOpenSecretStoreCache( | ||||
| 					 &ssId, | ||||
| 					 0, | ||||
| 					 NULL); | ||||
|  | ||||
|    g_hCASAContext = miCASAOpenSecretStoreCache(&ssId, | ||||
|                                                0, | ||||
|                                                NULL); | ||||
|    if (!g_hCASAContext) | ||||
|    { | ||||
| 	  retStatus =   CasaStatusBuild( | ||||
| 					 CASA_SEVERITY_ERROR, | ||||
| 					 CASA_FACILITY_AUTHTOKEN, | ||||
| 					 CASA_STATUS_UNSUCCESSFUL); | ||||
|       retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                                  CASA_FACILITY_AUTHTOKEN, | ||||
|                                  CASA_STATUS_UNSUCCESSFUL); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
| 	  retStatus = CASA_STATUS_SUCCESS; | ||||
|       retStatus = CASA_STATUS_SUCCESS; | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-InitializeAuthCache- End, retStatus = %08X\n", retStatus); | ||||
|   | ||||
| @@ -36,7 +36,7 @@ | ||||
| 				Name="VCLinkerTool" | ||||
| 				IgnoreImportLibrary="FALSE" | ||||
| 				AdditionalOptions="/EXPORT:ObtainAuthToken" | ||||
| 				AdditionalDependencies="ws2_32.lib winhttp.lib libexpatml.lib micasa.lib" | ||||
| 				AdditionalDependencies="ws2_32.lib winhttp.lib libexpatml.lib micasa.lib shlwapi.lib" | ||||
| 				OutputFile="$(OutDir)/authtoken.dll" | ||||
| 				LinkIncremental="1" | ||||
| 				AdditionalLibraryDirectories=""\Program Files\Novell\CASA\lib";"..\..\..\..\Expat-2.0.0\StaticLibs"" | ||||
| @@ -93,7 +93,7 @@ copy $(SolutionDir)client\windows\authtoken.lib \"Program Files"\novel | ||||
| 			<Tool | ||||
| 				Name="VCLinkerTool" | ||||
| 				AdditionalOptions="/EXPORT:ObtainAuthToken" | ||||
| 				AdditionalDependencies="ws2_32.lib winhttp.lib libexpatml.lib micasa.lib" | ||||
| 				AdditionalDependencies="ws2_32.lib winhttp.lib libexpatml.lib micasa.lib shlwapi.lib" | ||||
| 				OutputFile="$(OutDir)/authtoken.dll" | ||||
| 				LinkIncremental="1" | ||||
| 				AdditionalLibraryDirectories=""\Program Files\Novell\CASA\lib";"..\..\..\Expat-2.0.0\StaticLibs"" | ||||
|   | ||||
| @@ -664,7 +664,8 @@ GetConfigInterface( | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             DbgTrace(1, "-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); | ||||
|          } | ||||
|       } | ||||
|       else | ||||
|   | ||||
| @@ -43,8 +43,8 @@ int   DebugLevel = 0; | ||||
| // | ||||
| // Operating parameter | ||||
| //  | ||||
| bool	secureRpcSetting = false; | ||||
| bool	g_bInitialized = FALSE; | ||||
| bool  secureRpcSetting = false; | ||||
| bool  g_bInitialized = FALSE; | ||||
|  | ||||
| //++======================================================================= | ||||
| static | ||||
| @@ -99,7 +99,7 @@ ObtainSessionToken( | ||||
|          } | ||||
|          else | ||||
|          { | ||||
| 			// Free the entry | ||||
|          // Free the entry | ||||
|             FreeAuthCacheEntry(pCacheEntry); | ||||
|          } | ||||
|       } | ||||
| @@ -124,9 +124,9 @@ ObtainSessionToken( | ||||
|       pCacheEntry = FindSessionTokenEntryInCache(pAuthContext->pContext); | ||||
|       if (pCacheEntry == NULL) | ||||
|       { | ||||
| 		 char  *pReqMsg = NULL; | ||||
| 		 char  *pRespMsg = NULL; | ||||
| 		 int   respLen; | ||||
|          char  *pReqMsg = NULL; | ||||
|          char  *pRespMsg = NULL; | ||||
|          int   respLen; | ||||
|  | ||||
|          // Get authentication mechanism token | ||||
|          retStatus = GetAuthMechToken(pAuthContext, &pAuthMechToken); | ||||
| @@ -140,82 +140,80 @@ ObtainSessionToken( | ||||
|             continue; | ||||
|          } | ||||
|  | ||||
| 		 // Authenticate to the ATS | ||||
| 		 pReqMsg = BuildAuthenticateMsg(pAuthContext, pAuthMechToken); | ||||
| 		 if (pReqMsg) | ||||
| 		 { | ||||
| 			// Issue rpc | ||||
| 			retStatus = Rpc(pRpcSession, | ||||
| 							"Authenticate", | ||||
| 							secureRpcSetting, | ||||
| 							pReqMsg, | ||||
| 							&pRespMsg, | ||||
| 							&respLen); | ||||
| 			if (CASA_SUCCESS(retStatus)) | ||||
| 			{ | ||||
| 			   AuthenticateResp     *pAuthenticateResp; | ||||
|        // Authenticate to the ATS | ||||
|        pReqMsg = BuildAuthenticateMsg(pAuthContext, pAuthMechToken); | ||||
|        if (pReqMsg) | ||||
|        { | ||||
|          // Issue rpc | ||||
|          retStatus = Rpc(pRpcSession, | ||||
|                          "Authenticate", | ||||
|                          secureRpcSetting, | ||||
|                          pReqMsg, | ||||
|                          &pRespMsg, | ||||
|                          &respLen); | ||||
|          if (CASA_SUCCESS(retStatus)) | ||||
|          { | ||||
|             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); | ||||
|             // 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); | ||||
|  | ||||
| 				  pAuthenticateResp->pToken = NULL; // To keep us from freeing the buffer | ||||
|               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 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 resources that may be hanging around | ||||
|          if (pRespMsg) | ||||
|             free(pRespMsg); | ||||
|  | ||||
| 			free(pReqMsg); | ||||
| 		 } | ||||
| 		 else | ||||
| 		 { | ||||
| 			DbgTrace(0, "-ObtainSessionToken- Error building Authenticate msg\n", 0); | ||||
| 			retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
| 										CASA_FACILITY_AUTHTOKEN, | ||||
| 										CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
| 		 } | ||||
|          free(pReqMsg); | ||||
|        } | ||||
|        else | ||||
|        { | ||||
|          DbgTrace(0, "-ObtainSessionToken- Error building Authenticate msg\n", 0); | ||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||
|                               CASA_FACILITY_AUTHTOKEN, | ||||
|                               CASA_STATUS_INSUFFICIENT_RESOURCES); | ||||
|        } | ||||
|  | ||||
| 		 // Add the entry to the cache if successful or if the reason that we failed | ||||
| 		 // was because the server was unavailable. | ||||
| 		 if (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE) | ||||
| 		 { | ||||
| 			pCacheEntry = CreateSessionTokenCacheEntry( | ||||
| 						   pAuthContext->pContext, | ||||
| 						   retStatus, | ||||
| 						   NULL, | ||||
| 						   DEFAULT_RETRY_LIFETIME); | ||||
|        // Add the entry to the cache if successful or if the reason that we failed | ||||
|        // was because the server was unavailable. | ||||
|        if (CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE) | ||||
|        { | ||||
|          pCacheEntry = CreateSessionTokenCacheEntry(pAuthContext->pContext, | ||||
|                                                     retStatus, | ||||
|                                                     NULL, | ||||
|                                                     DEFAULT_RETRY_LIFETIME); | ||||
|  | ||||
| 		 } | ||||
|        } | ||||
|  | ||||
| 		 // Release the cache entry if the resulting status is not successful | ||||
| 		 if (!CASA_SUCCESS(retStatus)) | ||||
| 		 { | ||||
| 			FreeAuthCacheEntry(pCacheEntry); | ||||
| 		 } | ||||
|        // 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(pAuthMechToken); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
| 		 // Free the entry | ||||
| 		 FreeAuthCacheEntry(pCacheEntry); | ||||
|        // Free the entry | ||||
|        FreeAuthCacheEntry(pCacheEntry); | ||||
|       } | ||||
|  | ||||
|       // Advance to the next entry | ||||
| @@ -290,7 +288,7 @@ ObtainAuthTokenFromServer( | ||||
|       char                 *pSessionToken = NULL; | ||||
|  | ||||
|       // Request the auth parameters associated with this service | ||||
|       pReqMsg = BuildGetAuthPolicyMsg(pServiceName, pHostName); | ||||
|       pReqMsg = BuildGetAuthPolicyMsg(pServiceName, "localhost"); // tbd - This will be changed in the future so that we can support services residing in a different host than the ATS | ||||
|       if (pReqMsg) | ||||
|       { | ||||
|          // Issue rpc | ||||
| @@ -318,7 +316,7 @@ ObtainAuthTokenFromServer( | ||||
|                   { | ||||
|                      // Request auth token for the service | ||||
|                      free(pReqMsg); | ||||
|                      pReqMsg = BuildGetAuthTokenMsg(pServiceName, pHostName, pSessionToken); | ||||
|                      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) | ||||
|                      { | ||||
|                         // Free the previous response msg buffer | ||||
| @@ -473,7 +471,7 @@ ObtainAuthToken( | ||||
|    CasaStatus        retStatus = CASA_STATUS_SUCCESS; | ||||
|    AuthCacheEntry    *pCacheEntry; | ||||
|    char              *pNormalizedHostName; | ||||
|    unsigned char	 *pToken; | ||||
|    unsigned char     *pToken; | ||||
|    HANDLE            hUserMutex = NULL; | ||||
|  | ||||
|  | ||||
| @@ -492,6 +490,10 @@ ObtainAuthToken( | ||||
|       goto exit; | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-ObtainAuthToken- ServiceName = %s\n", pServiceName); | ||||
|    DbgTrace(1, "-ObtainAuthToken- HostName = %s\n", pHostName); | ||||
|    DbgTrace(1, "-ObtainAuthToken- BufferLength = %d\n", *pAuthTokenBufLen); | ||||
|  | ||||
|    // Make sure we are initialized | ||||
|    // Obtain our synchronization mutex | ||||
|    AcquireInitializationMutex(); | ||||
| @@ -501,22 +503,22 @@ ObtainAuthToken( | ||||
|  | ||||
|    if (retStatus != CASA_STATUS_SUCCESS) | ||||
|    { | ||||
| 	  DbgTrace(0, "-ObtainAuthToken- Error creating mutex for the user\n", 0); | ||||
|      DbgTrace(0, "-ObtainAuthToken- Error creating mutex for the user\n", 0); | ||||
|       goto exit; | ||||
|    } | ||||
|  | ||||
|    if (g_bInitialized == FALSE) | ||||
|    { | ||||
| 	  retStatus = InitializeLibrary(); | ||||
|      retStatus = InitializeLibrary(); | ||||
|  | ||||
| 	  if (retStatus == CASA_STATUS_SUCCESS) | ||||
| 	  { | ||||
| 		 g_bInitialized = TRUE; | ||||
| 	  } | ||||
| 	  else | ||||
| 	  { | ||||
| 		 goto exit; | ||||
| 	  } | ||||
|      if (retStatus == CASA_STATUS_SUCCESS) | ||||
|      { | ||||
|        g_bInitialized = TRUE; | ||||
|      } | ||||
|      else | ||||
|      { | ||||
|        goto exit; | ||||
|      } | ||||
|    } | ||||
|  | ||||
|    // Release our synchronization mutex | ||||
| @@ -533,37 +535,34 @@ ObtainAuthToken( | ||||
|       pCacheEntry = FindAuthTokenEntryInCache(pServiceName, pNormalizedHostName); | ||||
|       if (pCacheEntry == NULL) | ||||
|       { | ||||
| 		 // Initialize to retry in case of failure | ||||
| 		 int   cacheEntryLifetime = DEFAULT_RETRY_LIFETIME;  | ||||
|          // Initialize to retry in case of failure | ||||
|          int   cacheEntryLifetime = DEFAULT_RETRY_LIFETIME;  | ||||
|  | ||||
| 		 // Cache entry created, now try to obtain auth token from the CASA Server | ||||
| 		 retStatus = ObtainAuthTokenFromServer(pServiceName, | ||||
| 											   pNormalizedHostName, | ||||
| 											   &pToken, | ||||
| 											   &cacheEntryLifetime); | ||||
|  | ||||
| 		 // Add the entry to the cache if successful or if the reason that we failed | ||||
| 		 // was because the server was un-available. | ||||
| 		 if (CASA_SUCCESS(retStatus) | ||||
| 			 || CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE) | ||||
| 		 { | ||||
| 			pCacheEntry = CreateAuthTokenCacheEntry( | ||||
| 						   pServiceName, | ||||
| 						   pNormalizedHostName, | ||||
| 						   retStatus, | ||||
| 						   pToken, | ||||
| 						   cacheEntryLifetime); | ||||
|  | ||||
| 			if (pCacheEntry) | ||||
| 			{ | ||||
| 			   // Release the cache entry if the resulting status is not successful | ||||
| 			   if (!CASA_SUCCESS(retStatus)) | ||||
| 			   { | ||||
| 				  FreeAuthCacheEntry(pCacheEntry); | ||||
| 			   } | ||||
| 			} | ||||
| 		 } | ||||
|          // Cache entry created, now try to obtain auth token from the CASA Server | ||||
|          retStatus = ObtainAuthTokenFromServer(pServiceName, | ||||
|                                                pNormalizedHostName, | ||||
|                                                &pToken, | ||||
|                                                &cacheEntryLifetime); | ||||
|  | ||||
|          // Add the entry to the cache if successful or if the reason that we failed | ||||
|          // was because the server was un-available. | ||||
|          if (CASA_SUCCESS(retStatus) | ||||
|              || CasaStatusCode(retStatus) == CASA_STATUS_AUTH_SERVER_UNAVAILABLE) | ||||
|          { | ||||
|             pCacheEntry = CreateAuthTokenCacheEntry(pServiceName, | ||||
|                                                     pNormalizedHostName, | ||||
|                                                     retStatus, | ||||
|                                                     pToken, | ||||
|                                                     cacheEntryLifetime); | ||||
|             if (pCacheEntry) | ||||
|             { | ||||
|                // Release the cache entry if the resulting status is not successful | ||||
|                if (!CASA_SUCCESS(retStatus)) | ||||
|                { | ||||
|                   FreeAuthCacheEntry(pCacheEntry); | ||||
|                } | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
| @@ -586,6 +585,7 @@ ObtainAuthToken( | ||||
|          if (*pAuthTokenBufLen >= tokenLen) | ||||
|          { | ||||
|             // Return the auth token to the caller | ||||
|             DbgTrace(0, "-ObtainAuthToken- Copying the token into the callers buffer\n", 0); | ||||
|             strcpy(pAuthTokenBuf, pCacheEntry->token); | ||||
|          } | ||||
|          else | ||||
| @@ -620,7 +620,7 @@ exit: | ||||
|  | ||||
|    if (hUserMutex != NULL) | ||||
|    { | ||||
| 	  DestroyUserMutex(hUserMutex); | ||||
|       DestroyUserMutex(hUserMutex); | ||||
|    } | ||||
|  | ||||
|    DbgTrace(1, "-ObtainAuthToken- End, retStatus = %08X\n", retStatus); | ||||
| @@ -677,14 +677,11 @@ InitializeLibrary(void) | ||||
|  | ||||
|    // Initialize the host name normalization | ||||
|    retStatus = InitializeHostNameNormalization(); | ||||
|  | ||||
|  | ||||
|    if (CASA_SUCCESS(retStatus)) | ||||
|    { | ||||
| 	  retStatus = InitializeAuthCache(); | ||||
|      retStatus = InitializeAuthCache(); | ||||
|    } | ||||
|  | ||||
|  | ||||
|    DbgTrace(1, "-InitializeLibrary- End, retStatus = %08X\n", retStatus); | ||||
|  | ||||
|    return retStatus; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user