Changes due to continue development. Switched to using calls to a single Servlet and telling it what method to execute. The test application was also updated to be more flexible.
This commit is contained in:
		| @@ -99,6 +99,7 @@ BuildAuthenticateMsg( | |||||||
|    * <?xml version="1.0" encoding="ISO-8859-1"?> |    * <?xml version="1.0" encoding="ISO-8859-1"?> | ||||||
|    * <auth_req> |    * <auth_req> | ||||||
|    * <realm>realm value</realm> |    * <realm>realm value</realm> | ||||||
|  |    * <mechanism>mechanism id value</mechanism> | ||||||
|    * <auth_mech_token>authentication mechanism token data</auth_mech_token> |    * <auth_mech_token>authentication mechanism token data</auth_mech_token> | ||||||
|    * </auth_req> |    * </auth_req> | ||||||
|    * |    * | ||||||
| @@ -118,6 +119,13 @@ BuildAuthenticateMsg( | |||||||
|                 + strlen(REALM_ELEMENT_NAME) |                 + strlen(REALM_ELEMENT_NAME) | ||||||
|                 + 3  // >crlf |                 + 3  // >crlf | ||||||
|                 + 1  // < |                 + 1  // < | ||||||
|  |                 + strlen(MECHANISM_ELEMENT_NAME) | ||||||
|  |                 + 1  // > | ||||||
|  |                 + strlen(pAuthContext->pMechanism) | ||||||
|  |                 + 2  // </ | ||||||
|  |                 + strlen(MECHANISM_ELEMENT_NAME) | ||||||
|  |                 + 3  // >crlf | ||||||
|  |                 + 1  // < | ||||||
|                 + strlen(AUTH_MECH_TOKEN_ELEMENT_NAME) |                 + strlen(AUTH_MECH_TOKEN_ELEMENT_NAME) | ||||||
|                 + 1  // > |                 + 1  // > | ||||||
|                 + strlen(pAuthMechToken) |                 + strlen(pAuthMechToken) | ||||||
| @@ -147,6 +155,13 @@ BuildAuthenticateMsg( | |||||||
|       strcat(pMsg, REALM_ELEMENT_NAME); |       strcat(pMsg, REALM_ELEMENT_NAME); | ||||||
|       strcat(pMsg, ">\r\n"); |       strcat(pMsg, ">\r\n"); | ||||||
|       strcat(pMsg, "<"); |       strcat(pMsg, "<"); | ||||||
|  |       strcat(pMsg, MECHANISM_ELEMENT_NAME); | ||||||
|  |       strcat(pMsg, ">"); | ||||||
|  |       strcat(pMsg, pAuthContext->pMechanism); | ||||||
|  |       strcat(pMsg, "</"); | ||||||
|  |       strcat(pMsg, MECHANISM_ELEMENT_NAME); | ||||||
|  |       strcat(pMsg, ">\r\n"); | ||||||
|  |       strcat(pMsg, "<"); | ||||||
|       strcat(pMsg, AUTH_MECH_TOKEN_ELEMENT_NAME); |       strcat(pMsg, AUTH_MECH_TOKEN_ELEMENT_NAME); | ||||||
|       strcat(pMsg, ">"); |       strcat(pMsg, ">"); | ||||||
|       strcat(pMsg, pAuthMechToken); |       strcat(pMsg, pAuthMechToken); | ||||||
| @@ -422,6 +437,12 @@ AuthRespCharDataHandler( | |||||||
|                                                      CASA_FACILITY_AUTHTOKEN, |                                                      CASA_FACILITY_AUTHTOKEN, | ||||||
|                                                      CASA_STATUS_AUTHENTICATION_FAILURE); |                                                      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) |          else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0) | ||||||
|          { |          { | ||||||
|             pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, |             pAuthRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||||
|   | |||||||
| @@ -40,7 +40,13 @@ | |||||||
|         "Entry" |         "Entry" | ||||||
|         { |         { | ||||||
|         "MsmKey" = "8:_71C343EBC4935F8914C3145115EDEC4A" |         "MsmKey" = "8:_71C343EBC4935F8914C3145115EDEC4A" | ||||||
|         "OwnerKey" = "8:_A6E7F30D430741F79B780AA6B1B8D3D3" |         "OwnerKey" = "8:_7462FCD02DE146CFA809BCDC9FCFA3CC" | ||||||
|  |         "MsmSig" = "8:_UNDEFINED" | ||||||
|  |         } | ||||||
|  |         "Entry" | ||||||
|  |         { | ||||||
|  |         "MsmKey" = "8:_7462FCD02DE146CFA809BCDC9FCFA3CC" | ||||||
|  |         "OwnerKey" = "8:_UNDEFINED" | ||||||
|         "MsmSig" = "8:_UNDEFINED" |         "MsmSig" = "8:_UNDEFINED" | ||||||
|         } |         } | ||||||
|         "Entry" |         "Entry" | ||||||
| @@ -63,14 +69,14 @@ | |||||||
|         } |         } | ||||||
|         "Entry" |         "Entry" | ||||||
|         { |         { | ||||||
|         "MsmKey" = "8:_A6E7F30D430741F79B780AA6B1B8D3D3" |         "MsmKey" = "8:_AD11D4F6DDB74221806A3D1AB47BDC41" | ||||||
|         "OwnerKey" = "8:_UNDEFINED" |         "OwnerKey" = "8:_UNDEFINED" | ||||||
|         "MsmSig" = "8:_UNDEFINED" |         "MsmSig" = "8:_UNDEFINED" | ||||||
|         } |         } | ||||||
|         "Entry" |         "Entry" | ||||||
|         { |         { | ||||||
|         "MsmKey" = "8:_AD11D4F6DDB74221806A3D1AB47BDC41" |         "MsmKey" = "8:_FE85A5D48B5A23F3077871E9FD2378DE" | ||||||
|         "OwnerKey" = "8:_UNDEFINED" |         "OwnerKey" = "8:_0C0B5ECE6E9C47F1A1F13B58141B5DC8" | ||||||
|         "MsmSig" = "8:_UNDEFINED" |         "MsmSig" = "8:_UNDEFINED" | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -198,7 +204,7 @@ | |||||||
|             "SharedLegacy" = "11:FALSE" |             "SharedLegacy" = "11:FALSE" | ||||||
|             "PackageAs" = "3:1" |             "PackageAs" = "3:1" | ||||||
|             "Register" = "3:1" |             "Register" = "3:1" | ||||||
|             "Exclude" = "11:TRUE" |             "Exclude" = "11:FALSE" | ||||||
|             "IsDependency" = "11:TRUE" |             "IsDependency" = "11:TRUE" | ||||||
|             "IsolateTo" = "8:" |             "IsolateTo" = "8:" | ||||||
|             } |             } | ||||||
| @@ -262,6 +268,26 @@ | |||||||
|             "IsDependency" = "11:TRUE" |             "IsDependency" = "11:TRUE" | ||||||
|             "IsolateTo" = "8:" |             "IsolateTo" = "8:" | ||||||
|             } |             } | ||||||
|  |             "{A582A373-4685-4296-BEFE-614B80A702C3}:_FE85A5D48B5A23F3077871E9FD2378DE" | ||||||
|  |             { | ||||||
|  |             "SourcePath" = "8:WINHTTP.dll" | ||||||
|  |             "TargetName" = "8:WINHTTP.dll" | ||||||
|  |             "Tag" = "8:" | ||||||
|  |             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" | ||||||
|  |             "Condition" = "8:" | ||||||
|  |             "Transitive" = "11:FALSE" | ||||||
|  |             "Vital" = "11:TRUE" | ||||||
|  |             "ReadOnly" = "11:FALSE" | ||||||
|  |             "Hidden" = "11:FALSE" | ||||||
|  |             "System" = "11:FALSE" | ||||||
|  |             "Permanent" = "11:FALSE" | ||||||
|  |             "SharedLegacy" = "11:FALSE" | ||||||
|  |             "PackageAs" = "3:1" | ||||||
|  |             "Register" = "3:1" | ||||||
|  |             "Exclude" = "11:TRUE" | ||||||
|  |             "IsDependency" = "11:TRUE" | ||||||
|  |             "IsolateTo" = "8:" | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         "FileType" |         "FileType" | ||||||
|         { |         { | ||||||
| @@ -393,7 +419,7 @@ | |||||||
|         { |         { | ||||||
|             "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_0C0B5ECE6E9C47F1A1F13B58141B5DC8" |             "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_0C0B5ECE6E9C47F1A1F13B58141B5DC8" | ||||||
|             { |             { | ||||||
|             "SourcePath" = "8:..\\windows\\release\\authtoken.dll" |             "SourcePath" = "8:..\\windows\\Release\\authtoken.dll" | ||||||
|             "TargetName" = "8:" |             "TargetName" = "8:" | ||||||
|             "Tag" = "8:" |             "Tag" = "8:" | ||||||
|             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" |             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" | ||||||
| @@ -419,9 +445,9 @@ | |||||||
|                 { |                 { | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_A6E7F30D430741F79B780AA6B1B8D3D3" |             "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_7462FCD02DE146CFA809BCDC9FCFA3CC" | ||||||
|             { |             { | ||||||
|             "SourcePath" = "8:..\\mechanisms\\pwd\\windows\\release\\pwmech.dll" |             "SourcePath" = "8:..\\mechanisms\\pwd\\windows\\Release\\pwmech.dll" | ||||||
|             "TargetName" = "8:" |             "TargetName" = "8:" | ||||||
|             "Tag" = "8:" |             "Tag" = "8:" | ||||||
|             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" |             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" | ||||||
| @@ -449,7 +475,7 @@ | |||||||
|             } |             } | ||||||
|             "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_AD11D4F6DDB74221806A3D1AB47BDC41" |             "{8062640A-2EEE-46E9-AB67-688E9A886E9F}:_AD11D4F6DDB74221806A3D1AB47BDC41" | ||||||
|             { |             { | ||||||
|             "SourcePath" = "8:..\\mechanisms\\krb5\\windows\\release\\krb5mech.dll" |             "SourcePath" = "8:..\\mechanisms\\krb5\\windows\\Release\\krb5mech.dll" | ||||||
|             "TargetName" = "8:" |             "TargetName" = "8:" | ||||||
|             "Tag" = "8:" |             "Tag" = "8:" | ||||||
|             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" |             "Folder" = "8:_01897726E7804A3B875B67A1C2692147" | ||||||
|   | |||||||
| @@ -38,7 +38,7 @@ | |||||||
| // | // | ||||||
| // Debug tracing level | // Debug tracing level | ||||||
| //  | //  | ||||||
| int   DebugLevel = 0; | int   DebugLevel = 3; | ||||||
|  |  | ||||||
| // | // | ||||||
| // Operating parameter | // Operating parameter | ||||||
| @@ -147,7 +147,7 @@ ObtainSessionToken( | |||||||
|             { |             { | ||||||
|                // Issue rpc |                // Issue rpc | ||||||
|                retStatus = Rpc(pRpcSession, |                retStatus = Rpc(pRpcSession, | ||||||
|                                pAuthContext->pMechanism, |                                "Authenticate", | ||||||
|                                secureRpcSetting, |                                secureRpcSetting, | ||||||
|                                pReqMsg, |                                pReqMsg, | ||||||
|                                &pRespMsg, |                                &pRespMsg, | ||||||
| @@ -422,15 +422,21 @@ ObtainAuthTokenFromServer( | |||||||
| //++======================================================================= | //++======================================================================= | ||||||
| CasaStatus SSCS_CALL | CasaStatus SSCS_CALL | ||||||
| ObtainAuthToken( | ObtainAuthToken( | ||||||
|    IN    const char *pServiceAtHostName, |    IN    const char *pServiceName, | ||||||
|  |    IN    const char *pHostName, | ||||||
|    INOUT char *pAuthTokenBuf, |    INOUT char *pAuthTokenBuf, | ||||||
|    INOUT int *pAuthTokenBufLen) |    INOUT int *pAuthTokenBufLen) | ||||||
| // | // | ||||||
| //  Arguments:  | //  Arguments:  | ||||||
| //    pServiceAtHostName - | //    pServiceName - | ||||||
| //       Pointer to NULL terminated string that contains the | //       Pointer to NULL terminated string that contains the | ||||||
| //       service@host name to which the client is trying to | //       name of the service to which the client is trying to | ||||||
| //       authenticate. Note that the host portion of the name | //       authenticate. | ||||||
|  | //                | ||||||
|  | //    pHostName - | ||||||
|  | //       Pointer to NULL terminated string that contains the | ||||||
|  | //       name of the host where resides the service to which the | ||||||
|  | //       client is trying to authenticate. Note that the name | ||||||
| //       can either be a DNS name or a dotted IP address. | //       can either be a DNS name or a dotted IP address. | ||||||
| //                | //                | ||||||
| //    pAuthTokenBuf - | //    pAuthTokenBuf - | ||||||
| @@ -459,12 +465,14 @@ ObtainAuthToken( | |||||||
| //=======================================================================-- | //=======================================================================-- | ||||||
| { | { | ||||||
|    CasaStatus        retStatus = CASA_STATUS_SUCCESS; |    CasaStatus        retStatus = CASA_STATUS_SUCCESS; | ||||||
|    char        *pParseString; |    AuthCacheEntry    *pCacheEntry; | ||||||
|  |    char              *pNormalizedHostName; | ||||||
|  |  | ||||||
|    DbgTrace(1, "-ObtainAuthToken- Start\n", 0); |    DbgTrace(1, "-ObtainAuthToken- Start\n", 0); | ||||||
|  |  | ||||||
|    // Verify the input parameters |    // Verify the input parameters | ||||||
|    if (pServiceAtHostName == NULL |    if (pServiceName == NULL | ||||||
|  |       || pHostName == NULL | ||||||
|       || pAuthTokenBufLen == NULL |       || pAuthTokenBufLen == NULL | ||||||
|       || (*pAuthTokenBufLen != 0 && pAuthTokenBuf == NULL)) |       || (*pAuthTokenBufLen != 0 && pAuthTokenBuf == NULL)) | ||||||
|    { |    { | ||||||
| @@ -475,29 +483,6 @@ ObtainAuthToken( | |||||||
|       goto exit; |       goto exit; | ||||||
|    } |    } | ||||||
|  |  | ||||||
|    // Allocate space to copy the service name string |  | ||||||
|    pParseString = (char*) malloc(strlen(pServiceAtHostName) + 1); |  | ||||||
|    if (pParseString) |  | ||||||
|    { |  | ||||||
|       char  *pServiceName, *pHostName; |  | ||||||
|  |  | ||||||
|       // Space allocated, now copy the string onto it |  | ||||||
|       // and parse it into its components. |  | ||||||
|       strcpy(pParseString, pServiceAtHostName); |  | ||||||
|       pServiceName = strtok(pParseString, "@"); |  | ||||||
|       pHostName = strtok(NULL, "@"); |  | ||||||
|       if (pHostName == NULL) |  | ||||||
|       { |  | ||||||
|          DbgTrace(0, "-ObtainAuthToken- Missing host name\n", 0); |  | ||||||
|          retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR, |  | ||||||
|                                      CASA_FACILITY_AUTHTOKEN, |  | ||||||
|                                      CASA_STATUS_INVALID_PARAMETER); |  | ||||||
|       } |  | ||||||
|       else |  | ||||||
|       { |  | ||||||
|          AuthCacheEntry *pCacheEntry; |  | ||||||
|          char           *pNormalizedHostName; |  | ||||||
|  |  | ||||||
|    // Normalize the host name |    // Normalize the host name | ||||||
|    pNormalizedHostName = NormalizeHostName(pHostName); |    pNormalizedHostName = NormalizeHostName(pHostName); | ||||||
|    if (pNormalizedHostName) |    if (pNormalizedHostName) | ||||||
| @@ -586,15 +571,6 @@ ObtainAuthToken( | |||||||
|                                   CASA_FACILITY_AUTHTOKEN, |                                   CASA_FACILITY_AUTHTOKEN, | ||||||
|                                   CASA_STATUS_UNSUCCESSFUL); |                                   CASA_STATUS_UNSUCCESSFUL); | ||||||
|    } |    } | ||||||
|       } |  | ||||||
|  |  | ||||||
|       // Free allocated space |  | ||||||
|       free(pParseString); |  | ||||||
|    } |  | ||||||
|    else |  | ||||||
|    { |  | ||||||
|       DbgTrace(0, "-ObtainAuthToken- Buffer allocation error\n", 0); |  | ||||||
|    } |  | ||||||
|  |  | ||||||
| exit: | exit: | ||||||
|  |  | ||||||
|   | |||||||
| @@ -403,6 +403,12 @@ GetAuthPolicyRespCharDataHandler( | |||||||
|                                                               CASA_FACILITY_AUTHTOKEN, |                                                               CASA_FACILITY_AUTHTOKEN, | ||||||
|                                                               CASA_STATUS_AUTHENTICATION_FAILURE); |                                                               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) |          else if (strncmp(HTTP_SERVER_ERROR_STATUS_CODE, s, len) == 0) | ||||||
|          { |          { | ||||||
|             pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, |             pGetAuthPolicyRespParse->status = CasaStatusBuild(CASA_SEVERITY_ERROR, | ||||||
|   | |||||||
| @@ -25,148 +25,50 @@ | |||||||
| #include <windows.h> | #include <windows.h> | ||||||
| #include "casa_c_authtoken.h" | #include "casa_c_authtoken.h" | ||||||
|  |  | ||||||
|  | // Globals | ||||||
|  | char usageString[] = "usage: test -a serverAddress -p serverPort [-h]\n"; | ||||||
|  |  | ||||||
| int main(int argc, char* argv[]) | char     *pServerAddress = NULL; | ||||||
| { | int      serverPort = 0; | ||||||
|    int   retStatus; | BOOLEAN  execHttpTest = FALSE; | ||||||
|    char  authToken[4096]; |  | ||||||
|    int   authTokenLen = sizeof(authToken); |  | ||||||
|  |  | ||||||
|    // Now lets obtain a token for our service |  | ||||||
|    retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen); |  | ||||||
|    if (retStatus) |  | ||||||
|       printf("ObtainAuthToken failed with status %d\n", retStatus); |  | ||||||
|    else |  | ||||||
|    { |  | ||||||
|       char                 serverAddr[] = "137.65.132.44"; |  | ||||||
|       char                 *pServerAddress = serverAddr; |  | ||||||
| //      int                  serverPort = htons(4444); |  | ||||||
|       int                  serverPort = 27008; |  | ||||||
|       SOCKET               sock; |  | ||||||
|       struct sockaddr_in   localAddr = {0}; |  | ||||||
|       struct sockaddr_in   remoteAddr = {0}; |  | ||||||
|       struct linger        linger_opt = {1, 15}; |  | ||||||
|       struct hostent       *pLookupResult; |  | ||||||
|       int                  winsockStartupResult; |  | ||||||
|       WSADATA              winsockData; |  | ||||||
|  |  | ||||||
|       //printf("ObtainAuthToken succedded, token = %s\n", authToken); |  | ||||||
|       printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen); |  | ||||||
|  |  | ||||||
|       // Send the token to the server |  | ||||||
|       // |  | ||||||
|       // First initialize winsock |  | ||||||
|       if ((winsockStartupResult = WSAStartup(MAKEWORD(2,2), &winsockData)) == 0) |  | ||||||
|       { |  | ||||||
|          // Open socket |  | ||||||
|          sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |  | ||||||
|          if (sock != INVALID_SOCKET) |  | ||||||
|          { |  | ||||||
|             // Setup the local address structure |  | ||||||
|             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))) |  | ||||||
|             { |  | ||||||
|                // Resolve the server address |  | ||||||
|                pLookupResult = gethostbyname(pServerAddress); |  | ||||||
|                if (pLookupResult) |  | ||||||
|                { |  | ||||||
|                   // Validate the address type returned |  | ||||||
|                   if (pLookupResult->h_addrtype == AF_INET) |  | ||||||
|                   { |  | ||||||
|                      int   numAddressesFound = 0; |  | ||||||
|  |  | ||||||
|                      // Determine how many addresses where returned |  | ||||||
|                      while (pLookupResult->h_addr_list[numAddressesFound] != NULL) |  | ||||||
|                      { |  | ||||||
|                         //printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound])); |  | ||||||
|                         numAddressesFound ++; |  | ||||||
|                      } |  | ||||||
|                      //printf("Found %d addresses\n", numAddressesFound); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|                      // Setup the remote address structure with the lookup results | /*********************************************************************** | ||||||
|                      remoteAddr.sin_family = AF_INET; |  * | ||||||
|                      remoteAddr.sin_port = serverPort; |  * dtoul() | ||||||
|                      remoteAddr.sin_addr.s_addr = *((int*) pLookupResult->h_addr_list[0]); // Short-cut |  * | ||||||
|                      //printf("ServerAddress = %08X\n", remoteAddr.sin_addr.s_addr); |  ***********************************************************************/ | ||||||
|  | int | ||||||
|                      // Perform connect operation | dtoul( | ||||||
|                      if (connect(sock, |    IN    char *cp, | ||||||
|                                  (struct sockaddr*) &remoteAddr, |    IN    int len) | ||||||
|                                  sizeof(struct sockaddr_in)) == SOCKET_ERROR) |  | ||||||
| { | { | ||||||
|                         printf("main()- Connection creation failed, error = %d\n", WSAGetLastError()); |    int   n = 0; | ||||||
|  |    int   i; | ||||||
|  |  | ||||||
|  |    for (i = 0; i < len; i++, cp++) | ||||||
|  |    { | ||||||
|  |       // Verify that we are dealing with a valid digit | ||||||
|  |       if (*cp >= '0' && *cp <= '9') | ||||||
|  |       { | ||||||
|  |          n = 10 * n + (*cp - '0'); | ||||||
|       } |       } | ||||||
|       else |       else | ||||||
|       { |       { | ||||||
|                         // Now the connection is setup, send the credentials to the server as one line. |          printf("-dtoul- Found invalid digit\n"); | ||||||
|                         // using our cheesy protocol followed by a hello string. |          break; | ||||||
|  |  | ||||||
|                         // Send the username to the server (including NULL terminator) |  | ||||||
|                         //send(sock, userName, userNameBufLen, 0); |  | ||||||
|  |  | ||||||
|                         // Send new line |  | ||||||
|                         //send(sock, "\n", 1, MSG_NOSIGNAL); |  | ||||||
|  |  | ||||||
|                         // 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 |  | ||||||
|                   { |  | ||||||
|                      printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); |  | ||||||
|                   } |  | ||||||
|                } |  | ||||||
|                else |  | ||||||
|                { |  | ||||||
|                   printf("main()- Lookup for %s failed\n", pServerAddress); |  | ||||||
|                } |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                printf("main()- 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 |  | ||||||
|          { |  | ||||||
|             printf("main()- Unable to open socket, error = %d\n", errno); |  | ||||||
|          } |  | ||||||
|  |  | ||||||
|          // Close winsock |  | ||||||
|          WSACleanup(); |  | ||||||
|       } |  | ||||||
|       else |  | ||||||
|       { |  | ||||||
|          printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult); |  | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|        |        | ||||||
|    printf("Enter to exit application\n"); |    return n; | ||||||
|    getchar(); |  | ||||||
|    return 0; |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /* | /*********************************************************************** | ||||||
|  |  * | ||||||
|  |  * EncodeData() | ||||||
|  |  * | ||||||
|  |  ***********************************************************************/ | ||||||
| int | int | ||||||
| EncodeData( | EncodeData( | ||||||
|    IN    const void *pData, |    IN    const void *pData, | ||||||
| @@ -174,7 +76,7 @@ EncodeData( | |||||||
|    INOUT char **ppEncodedData, |    INOUT char **ppEncodedData, | ||||||
|    INOUT int32_t *pEncodedDataLen) |    INOUT int32_t *pEncodedDataLen) | ||||||
| { | { | ||||||
|    int8_t  g_Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |    int8_t      base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||||||
|    int         retStatus; |    int         retStatus; | ||||||
|    int         encodedSize; |    int         encodedSize; | ||||||
|  |  | ||||||
| @@ -196,26 +98,26 @@ EncodeData( | |||||||
|       // Perform the encoding |       // Perform the encoding | ||||||
|       for (i = 0; i < dataLen - 2; i += 3) |       for (i = 0; i < dataLen - 2; i += 3) | ||||||
|       { |       { | ||||||
|           *pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F]; |           *pOut++ = base64[(pIn[i] >> 2) & 0x3F]; | ||||||
|           *pOut++ = g_Base64[((pIn[i] & 0x3) << 4) | |           *pOut++ = base64[((pIn[i] & 0x3) << 4) | | ||||||
|                           ((int32_t)(pIn[i + 1] & 0xF0) >> 4)]; |                           ((int32_t)(pIn[i + 1] & 0xF0) >> 4)]; | ||||||
|           *pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2) | |           *pOut++ = base64[((pIn[i + 1] & 0xF) << 2) | | ||||||
|                           ((int32_t)(pIn[i + 2] & 0xC0) >> 6)]; |                           ((int32_t)(pIn[i + 2] & 0xC0) >> 6)]; | ||||||
|           *pOut++ = g_Base64[pIn[i + 2] & 0x3F]; |           *pOut++ = base64[pIn[i + 2] & 0x3F]; | ||||||
|       } |       } | ||||||
|       if (i < dataLen) |       if (i < dataLen) | ||||||
|       { |       { | ||||||
|           *pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F]; |           *pOut++ = base64[(pIn[i] >> 2) & 0x3F]; | ||||||
|           if (i == (dataLen - 1)) |           if (i == (dataLen - 1)) | ||||||
|           { |           { | ||||||
|               *pOut++ = g_Base64[((pIn[i] & 0x3) << 4)]; |               *pOut++ = base64[((pIn[i] & 0x3) << 4)]; | ||||||
|               *pOut++ = '='; |               *pOut++ = '='; | ||||||
|           } |           } | ||||||
|           else |           else | ||||||
|           { |           { | ||||||
|               *pOut++ = g_Base64[((pIn[i] & 0x3) << 4) | |               *pOut++ = base64[((pIn[i] & 0x3) << 4) | | ||||||
|                               ((int32_t)(pIn[i + 1] & 0xF0) >> 4)]; |                               ((int32_t)(pIn[i + 1] & 0xF0) >> 4)]; | ||||||
|               *pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2)]; |               *pOut++ = base64[((pIn[i + 1] & 0xF) << 2)]; | ||||||
|           } |           } | ||||||
|           *pOut++ = '='; |           *pOut++ = '='; | ||||||
|       } |       } | ||||||
| @@ -230,7 +132,6 @@ EncodeData( | |||||||
|    else |    else | ||||||
|    { |    { | ||||||
|       printf("-EncodeData- Buffer allocation failure\n"); |       printf("-EncodeData- Buffer allocation failure\n"); | ||||||
|  |  | ||||||
|       retStatus = -1; |       retStatus = -1; | ||||||
|    } |    } | ||||||
|  |  | ||||||
| @@ -238,22 +139,156 @@ EncodeData( | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| int main(int argc, char* argv[]) | /*********************************************************************** | ||||||
|  |  * | ||||||
|  |  * NonHttpTest() | ||||||
|  |  * | ||||||
|  |  ***********************************************************************/ | ||||||
|  | void NonHttpTest(void) | ||||||
| { | { | ||||||
|    int   retStatus; |    CasaStatus  retStatus; | ||||||
|    char        authToken[4096]; |    char        authToken[4096]; | ||||||
|    int         authTokenLen = sizeof(authToken); |    int         authTokenLen = sizeof(authToken); | ||||||
|  |  | ||||||
|    // Now lets obtain a token for our service |    // Obtain an authentication token for the testService | ||||||
|    retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen); |    retStatus = ObtainAuthToken("testService", pServerAddress, authToken, &authTokenLen); | ||||||
|    if (retStatus) |    if (!CASA_SUCCESS(retStatus)) | ||||||
|       printf("ObtainAuthToken failed with status %d\n", retStatus); |    { | ||||||
|  |       printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus); | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       SOCKET               sock; | ||||||
|  |       struct sockaddr_in   localAddr = {0}; | ||||||
|  |       struct sockaddr_in   remoteAddr = {0}; | ||||||
|  |       struct linger        linger_opt = {1, 15}; | ||||||
|  |       struct hostent       *pLookupResult; | ||||||
|  |       int                  winsockStartupResult; | ||||||
|  |       WSADATA              winsockData; | ||||||
|  |  | ||||||
|  |       printf("-NonHttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen); | ||||||
|  |  | ||||||
|  |       // Send the token to the server | ||||||
|  |       // | ||||||
|  |       // First initialize winsock | ||||||
|  |       if ((winsockStartupResult = WSAStartup(MAKEWORD(2,2), &winsockData)) == 0) | ||||||
|  |       { | ||||||
|  |          // Open socket | ||||||
|  |          sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | ||||||
|  |          if (sock != INVALID_SOCKET) | ||||||
|  |          { | ||||||
|  |             // Setup the local address structure | ||||||
|  |             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))) | ||||||
|  |             { | ||||||
|  |                // Resolve the server address | ||||||
|  |                pLookupResult = gethostbyname(pServerAddress); | ||||||
|  |                if (pLookupResult) | ||||||
|  |                { | ||||||
|  |                   // Validate the address type returned | ||||||
|  |                   if (pLookupResult->h_addrtype == AF_INET) | ||||||
|  |                   { | ||||||
|  |                      int   numAddressesFound = 0; | ||||||
|  |  | ||||||
|  |                      // Determine how many addresses where returned | ||||||
|  |                      while (pLookupResult->h_addr_list[numAddressesFound] != NULL) | ||||||
|  |                      { | ||||||
|  |                         //printf("ServerAddress = %08X\n", *((int*) pLookupResult->h_addr_list[numAddressesFound])); | ||||||
|  |                         numAddressesFound ++; | ||||||
|  |                      } | ||||||
|  |                      //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("-NonHttpTest- Connection creation failed, error = %d\n", WSAGetLastError()); | ||||||
|  |                      } | ||||||
|  |                      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, 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 | ||||||
|  |                   { | ||||||
|  |                      printf("-NonHttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); | ||||||
|  |                   } | ||||||
|  |                } | ||||||
|  |                else | ||||||
|  |                { | ||||||
|  |                   printf("-NonHttpTest- Lookup for %s failed\n", pServerAddress); | ||||||
|  |                } | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                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 | ||||||
|  |          { | ||||||
|  |             printf("-NonHttpTest- Unable to open socket, error = %d\n", errno); | ||||||
|  |          } | ||||||
|  |  | ||||||
|  |          // Close winsock | ||||||
|  |          WSACleanup(); | ||||||
|  |       } | ||||||
|  |       else | ||||||
|  |       { | ||||||
|  |          printf("-NonHttpTest- WSAStartup failed, error = %d\n", winsockStartupResult); | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /*********************************************************************** | ||||||
|  |  * | ||||||
|  |  * HttpTest() | ||||||
|  |  * | ||||||
|  |  ***********************************************************************/ | ||||||
|  | void HttpTest(void) | ||||||
|  | { | ||||||
|  |    CasaStatus  retStatus; | ||||||
|  |    char        authToken[4096]; | ||||||
|  |    int         authTokenLen = sizeof(authToken); | ||||||
|  |  | ||||||
|  |    // Obtain an authentication token for the testService | ||||||
|  |    retStatus = ObtainAuthToken("testService", pServerAddress, authToken, &authTokenLen); | ||||||
|  |    if (!CASA_SUCCESS(retStatus)) | ||||||
|  |    { | ||||||
|  |       printf("-HttpTest- ObtainAuthToken failed with status %d\n", retStatus); | ||||||
|  |    } | ||||||
|    else |    else | ||||||
|    { |    { | ||||||
|       char                 serverAddr[] = "137.65.132.44"; |  | ||||||
|       char                 *pServerAddress = serverAddr; |  | ||||||
| //      int                  serverPort = htons(4444); |  | ||||||
|       int                  serverPort = htons(4096); |  | ||||||
|       SOCKET               sock; |       SOCKET               sock; | ||||||
|       struct sockaddr_in   localAddr = {0}; |       struct sockaddr_in   localAddr = {0}; | ||||||
|       struct sockaddr_in   remoteAddr = {0}; |       struct sockaddr_in   remoteAddr = {0}; | ||||||
| @@ -263,7 +298,7 @@ int main(int argc, char* argv[]) | |||||||
|       WSADATA              winsockData; |       WSADATA              winsockData; | ||||||
|  |  | ||||||
|       //printf("ObtainAuthToken succedded, token = %s\n", authToken); |       //printf("ObtainAuthToken succedded, token = %s\n", authToken); | ||||||
|       printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen); |       printf("-HttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen); | ||||||
|  |  | ||||||
|       // Send the token to the server |       // Send the token to the server | ||||||
|       // |       // | ||||||
| @@ -310,7 +345,7 @@ int main(int argc, char* argv[]) | |||||||
|                                  (struct sockaddr*) &remoteAddr, |                                  (struct sockaddr*) &remoteAddr, | ||||||
|                                  sizeof(struct sockaddr_in)) == SOCKET_ERROR) |                                  sizeof(struct sockaddr_in)) == SOCKET_ERROR) | ||||||
|                      { |                      { | ||||||
|                         printf("main()- Connection creation failed, error = %d\n", WSAGetLastError()); |                         printf("-HttpTest- Connection creation failed, error = %d\n", WSAGetLastError()); | ||||||
|                      } |                      } | ||||||
|                      else |                      else | ||||||
|                      { |                      { | ||||||
| @@ -346,7 +381,7 @@ int main(int argc, char* argv[]) | |||||||
|                            } |                            } | ||||||
|                            else |                            else | ||||||
|                            { |                            { | ||||||
|                               printf("Error encoding credentials\n"); |                               printf("-HttpTest- Error encoding credentials\n"); | ||||||
|                            } |                            } | ||||||
|  |  | ||||||
|                            // Free the buffer containing the basic credentials |                            // Free the buffer containing the basic credentials | ||||||
| @@ -354,7 +389,7 @@ int main(int argc, char* argv[]) | |||||||
|                         } |                         } | ||||||
|                         else |                         else | ||||||
|                         { |                         { | ||||||
|                            printf("Buffer allocation failure\n"); |                            printf("-HttpTest- Buffer allocation failure\n"); | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         // Shutdown the connection |                         // Shutdown the connection | ||||||
| @@ -363,17 +398,17 @@ int main(int argc, char* argv[]) | |||||||
|                   } |                   } | ||||||
|                   else |                   else | ||||||
|                   { |                   { | ||||||
|                      printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); |                      printf("-HttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype); | ||||||
|                   } |                   } | ||||||
|                } |                } | ||||||
|                else |                else | ||||||
|                { |                { | ||||||
|                   printf("main()- Lookup for %s failed\n", pServerAddress); |                   printf("-HttpTest- Lookup for %s failed\n", pServerAddress); | ||||||
|                } |                } | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                printf("main()- Unable to bind socket, error = %d", errno); |                printf("-HttpTest- Unable to bind socket, error = %d", errno); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // Close the socket |             // Close the socket | ||||||
| @@ -382,7 +417,7 @@ int main(int argc, char* argv[]) | |||||||
|          } |          } | ||||||
|          else |          else | ||||||
|          { |          { | ||||||
|             printf("main()- Unable to open socket, error = %d\n", errno); |             printf("-HttpTest- Unable to open socket, error = %d\n", errno); | ||||||
|          } |          } | ||||||
|  |  | ||||||
|          // Close winsock |          // Close winsock | ||||||
| @@ -390,12 +425,89 @@ int main(int argc, char* argv[]) | |||||||
|       } |       } | ||||||
|       else |       else | ||||||
|       { |       { | ||||||
|          printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult); |          printf("-HttpTest- WSAStartup failed, error = %d\n", winsockStartupResult); | ||||||
|  |       } | ||||||
|    } |    } | ||||||
| } | } | ||||||
|  |  | ||||||
|    printf("Enter to exit application\n"); |  | ||||||
|    getchar(); | /*********************************************************************** | ||||||
|  |  * | ||||||
|  |  * main() | ||||||
|  |  * | ||||||
|  |  ***********************************************************************/ | ||||||
|  | int main(int argc, char* argv[]) | ||||||
|  | { | ||||||
|  |    // Process input parameters | ||||||
|  |    int i = 1; | ||||||
|  |    while(argv[i] != NULL) | ||||||
|  |    { | ||||||
|  |       if (stricmp(argv[i], "-a") == 0) | ||||||
|  |       { | ||||||
|  |          // Server Address option, the next argument should | ||||||
|  |          // contain the address. | ||||||
|  |          i++; | ||||||
|  |          if (argv[i] != NULL) | ||||||
|  |          { | ||||||
|  |             pServerAddress = argv[i]; | ||||||
|  |          } | ||||||
|  |          else | ||||||
|  |          { | ||||||
|  |             printf(usageString); | ||||||
|  |             return -1; | ||||||
|  |          } | ||||||
|  |       } | ||||||
|  |       else if (stricmp(argv[i], "-p") == 0) | ||||||
|  |       { | ||||||
|  |          // Server port option, the next argument should | ||||||
|  |          // contain the port. | ||||||
|  |          i++; | ||||||
|  |          if (argv[i] != NULL) | ||||||
|  |          { | ||||||
|  |             serverPort = htons(dtoul(argv[i], strlen(argv[i]))); | ||||||
|  |          } | ||||||
|  |          else | ||||||
|  |          { | ||||||
|  |             printf(usageString); | ||||||
|  |             return -1; | ||||||
|  |          } | ||||||
|  |       } | ||||||
|  |       else if (stricmp(argv[i], "-h") == 0) | ||||||
|  |       { | ||||||
|  |          // Perform http test option | ||||||
|  |          execHttpTest = TRUE; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       // Advance to the next argument | ||||||
|  |       i++; | ||||||
|  |    } | ||||||
|  |  | ||||||
|  |    // Verify that the server address and port were specified | ||||||
|  |    if (pServerAddress && serverPort != 0) | ||||||
|  |    { | ||||||
|  |       // Repeat the test when indicated | ||||||
|  |       printf("Press 'Enter' to run test or 'n + Enter' to stop.\n"); | ||||||
|  |       while(getchar() != 'n') | ||||||
|  |       { | ||||||
|  |          // Execute the appropriate test | ||||||
|  |          if (execHttpTest) | ||||||
|  |          { | ||||||
|  |             HttpTest(); | ||||||
|  |          } | ||||||
|  |          else | ||||||
|  |          { | ||||||
|  |             NonHttpTest(); | ||||||
|  |          } | ||||||
|  |          printf("Press 'Enter' to run test or 'n + Enter' to stop.\n"); | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       printf(usageString); | ||||||
|  |       return -1; | ||||||
|  |    } | ||||||
|  |  | ||||||
|    return 0; |    return 0; | ||||||
| } | } | ||||||
| */ |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -35,7 +35,7 @@ | |||||||
| 				AdditionalDependencies="authtoken.lib ws2_32.lib" | 				AdditionalDependencies="authtoken.lib ws2_32.lib" | ||||||
| 				OutputFile="$(OutDir)/test.exe" | 				OutputFile="$(OutDir)/test.exe" | ||||||
| 				LinkIncremental="2" | 				LinkIncremental="2" | ||||||
| 				AdditionalLibraryDirectories="..\..\client\win32\Debug" | 				AdditionalLibraryDirectories=""C:\Program Files\novell\CASA\lib"" | ||||||
| 				GenerateDebugInformation="TRUE" | 				GenerateDebugInformation="TRUE" | ||||||
| 				ProgramDatabaseFile="$(OutDir)/test.pdb" | 				ProgramDatabaseFile="$(OutDir)/test.pdb" | ||||||
| 				SubSystem="1" | 				SubSystem="1" | ||||||
| @@ -44,7 +44,7 @@ | |||||||
| 				Name="VCMIDLTool"/> | 				Name="VCMIDLTool"/> | ||||||
| 			<Tool | 			<Tool | ||||||
| 				Name="VCPostBuildEventTool" | 				Name="VCPostBuildEventTool" | ||||||
| 				CommandLine="copy ..\win32\debug\authtoken.dll debug\authtoken.dll"/> | 				CommandLine="copy ..\windows\debug\authtoken.dll debug\authtoken.dll"/> | ||||||
| 			<Tool | 			<Tool | ||||||
| 				Name="VCPreBuildEventTool"/> | 				Name="VCPreBuildEventTool"/> | ||||||
| 			<Tool | 			<Tool | ||||||
|   | |||||||
| @@ -35,6 +35,7 @@ | |||||||
| #define CASA_AUTH_CACHE_REG_KEY     "CASA_Auth_Cache" | #define CASA_AUTH_CACHE_REG_KEY     "CASA_Auth_Cache" | ||||||
| #define CREATION_TIME_REG_VALUE     "CreationTime" | #define CREATION_TIME_REG_VALUE     "CreationTime" | ||||||
| #define EXPIRATION_TIME_REG_VALUE   "ExpirationTime" | #define EXPIRATION_TIME_REG_VALUE   "ExpirationTime" | ||||||
|  | #define DOES_NOT_EXPIRE_REG_VALUE   "DoesNotExpire" | ||||||
| #define STATUS_REG_VALUE            "Status" | #define STATUS_REG_VALUE            "Status" | ||||||
| #define TOKEN_REG_VALUE             "Token" | #define TOKEN_REG_VALUE             "Token" | ||||||
|  |  | ||||||
| @@ -281,7 +282,8 @@ FindEntryInAuthCache( | |||||||
|          { |          { | ||||||
|             // This entry is for the appropriate CacheKeyName, check if it |             // This entry is for the appropriate CacheKeyName, check if it | ||||||
|             // has not expired. |             // has not expired. | ||||||
|             if (CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime)) |             if (pWrkEntry->doesNotExpire == FALSE | ||||||
|  |                 && CacheEntryLifetimeExpired(pWrkEntry->creationTime, pWrkEntry->expirationTime)) | ||||||
|             { |             { | ||||||
|                // The lifetime of the entry has expired, remove it from the in-memory cache |                // The lifetime of the entry has expired, remove it from the in-memory cache | ||||||
|                // and free it. |                // and free it. | ||||||
| @@ -342,6 +344,7 @@ FindEntryInAuthCache( | |||||||
|             { |             { | ||||||
|                DWORD creationTime; |                DWORD creationTime; | ||||||
|                DWORD expirationTime; |                DWORD expirationTime; | ||||||
|  |                BOOL  doesNotExpire; | ||||||
|                BOOL  deleteCacheKeyNameKey = TRUE; |                BOOL  deleteCacheKeyNameKey = TRUE; | ||||||
|                DWORD variableSz; |                DWORD variableSz; | ||||||
|  |  | ||||||
| @@ -367,9 +370,20 @@ FindEntryInAuthCache( | |||||||
|                                             (LPBYTE) &expirationTime, |                                             (LPBYTE) &expirationTime, | ||||||
|                                             &variableSz); |                                             &variableSz); | ||||||
|                   if (status == ERROR_SUCCESS) |                   if (status == ERROR_SUCCESS) | ||||||
|  |                   { | ||||||
|  |                      // Read the does not expire | ||||||
|  |                      variableSz = sizeof(doesNotExpire); | ||||||
|  |                      status = RegQueryValueExA(hCacheKeyNameRegKey, | ||||||
|  |                                                EXPIRATION_TIME_REG_VALUE, | ||||||
|  |                                                NULL, | ||||||
|  |                                                NULL, | ||||||
|  |                                                (LPBYTE) &doesNotExpire, | ||||||
|  |                                                &variableSz); | ||||||
|  |                      if (status == ERROR_SUCCESS) | ||||||
|                      { |                      { | ||||||
|                         // Check if the extry lifetime has been exceeded |                         // Check if the extry lifetime has been exceeded | ||||||
|                      if (CacheEntryLifetimeExpired(creationTime, expirationTime) == FALSE) |                         if (doesNotExpire == TRUE | ||||||
|  |                             || CacheEntryLifetimeExpired(creationTime, expirationTime) == FALSE) | ||||||
|                         { |                         { | ||||||
|                            // Create a AuthCacheEntry |                            // Create a AuthCacheEntry | ||||||
|                            pEntry = CreateAuthCacheEntry(pCacheKeyName, pHostName); |                            pEntry = CreateAuthCacheEntry(pCacheKeyName, pHostName); | ||||||
| @@ -380,6 +394,7 @@ FindEntryInAuthCache( | |||||||
|                               // Start setting up the AuthCacheEntry |                               // Start setting up the AuthCacheEntry | ||||||
|                               pEntry->creationTime = creationTime; |                               pEntry->creationTime = creationTime; | ||||||
|                               pEntry->expirationTime = expirationTime; |                               pEntry->expirationTime = expirationTime; | ||||||
|  |                               pEntry->doesNotExpire = doesNotExpire; | ||||||
|  |  | ||||||
|                               // Read the status |                               // Read the status | ||||||
|                               variableSz = sizeof(pEntry->status); |                               variableSz = sizeof(pEntry->status); | ||||||
| @@ -472,6 +487,11 @@ FindEntryInAuthCache( | |||||||
|                         } |                         } | ||||||
|                      } |                      } | ||||||
|                      else |                      else | ||||||
|  |                      { | ||||||
|  |                         DbgTrace(0, "-FindEntryInAuthCache- Error reading does not expire, status = %d\n", status); | ||||||
|  |                      } | ||||||
|  |                   } | ||||||
|  |                   else | ||||||
|                   { |                   { | ||||||
|                      DbgTrace(0, "-FindEntryInAuthCache- Error reading expiration time, status = %d\n", status); |                      DbgTrace(0, "-FindEntryInAuthCache- Error reading expiration time, status = %d\n", status); | ||||||
|                   } |                   } | ||||||
| @@ -514,7 +534,7 @@ FindEntryInAuthCache( | |||||||
| void | void | ||||||
| AddEntryToAuthCache( | AddEntryToAuthCache( | ||||||
|    IN    AuthCacheEntry *pEntry, |    IN    AuthCacheEntry *pEntry, | ||||||
|    IN    int entryLifetime) // seconds |    IN    int entryLifetime) // seconds (0 == Lives forever) | ||||||
| // | // | ||||||
| //  Arguments:  | //  Arguments:  | ||||||
| // | // | ||||||
| @@ -536,7 +556,17 @@ AddEntryToAuthCache( | |||||||
|    pEntry->creationTime = GetTickCount(); |    pEntry->creationTime = GetTickCount(); | ||||||
|  |  | ||||||
|    // First determine the time when the entry is due to expire |    // First determine the time when the entry is due to expire | ||||||
|  |    if (entryLifetime != 0) | ||||||
|  |    { | ||||||
|       pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); |       pEntry->expirationTime = pEntry->creationTime + (entryLifetime * 1000); | ||||||
|  |       pEntry->doesNotExpire = FALSE; | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       // The entry does not expire | ||||||
|  |       pEntry->expirationTime = 0; | ||||||
|  |       pEntry->doesNotExpire = TRUE; | ||||||
|  |    } | ||||||
|  |  | ||||||
|    // Save the entry in our persistent cache (registry) |    // Save the entry in our persistent cache (registry) | ||||||
|    // |    // | ||||||
| @@ -592,6 +622,14 @@ AddEntryToAuthCache( | |||||||
|                                        (LPBYTE) &pEntry->expirationTime, |                                        (LPBYTE) &pEntry->expirationTime, | ||||||
|                                        sizeof(pEntry->expirationTime)); |                                        sizeof(pEntry->expirationTime)); | ||||||
|                if (status == ERROR_SUCCESS) |                if (status == ERROR_SUCCESS) | ||||||
|  |                { | ||||||
|  |                   status = RegSetValueExA(hCacheKeyNameRegKey, | ||||||
|  |                                           DOES_NOT_EXPIRE_REG_VALUE, | ||||||
|  |                                           0, | ||||||
|  |                                           REG_DWORD, | ||||||
|  |                                           (LPBYTE) &pEntry->doesNotExpire, | ||||||
|  |                                           sizeof(pEntry->doesNotExpire)); | ||||||
|  |                   if (status == ERROR_SUCCESS) | ||||||
|                   { |                   { | ||||||
|                      status = RegSetValueExA(hCacheKeyNameRegKey, |                      status = RegSetValueExA(hCacheKeyNameRegKey, | ||||||
|                                              STATUS_REG_VALUE, |                                              STATUS_REG_VALUE, | ||||||
| @@ -623,6 +661,11 @@ AddEntryToAuthCache( | |||||||
|                      } |                      } | ||||||
|                   } |                   } | ||||||
|                   else |                   else | ||||||
|  |                   { | ||||||
|  |                      DbgTrace(0, "-AddEntryToAuthCache- Error setting does not expire, status = %d\n", status); | ||||||
|  |                   } | ||||||
|  |                } | ||||||
|  |                else | ||||||
|                { |                { | ||||||
|                   DbgTrace(0, "-AddEntryToAuthCache- Error setting expiration time, status = %d\n", status); |                   DbgTrace(0, "-AddEntryToAuthCache- Error setting expiration time, status = %d\n", status); | ||||||
|                } |                } | ||||||
|   | |||||||
| @@ -77,6 +77,7 @@ typedef struct _AuthCacheEntry | |||||||
|    LIST_ENTRY  listEntry; |    LIST_ENTRY  listEntry; | ||||||
|    DWORD       creationTime; |    DWORD       creationTime; | ||||||
|    DWORD       expirationTime; |    DWORD       expirationTime; | ||||||
|  |    BOOL        doesNotExpire; | ||||||
|    char        *pHostName; |    char        *pHostName; | ||||||
|    char        *pCacheKeyName; |    char        *pCacheKeyName; | ||||||
|    char        *pToken; |    char        *pToken; | ||||||
|   | |||||||
| @@ -251,7 +251,7 @@ InternalRpc( | |||||||
|    *ppResponseData = NULL; |    *ppResponseData = NULL; | ||||||
|  |  | ||||||
|    // Create rpc target string and convert it to a wide string |    // Create rpc target string and convert it to a wide string | ||||||
|    sprintf(rpcTarget, "CasaAuthTokenSvc/%s", pMethod); |    sprintf(rpcTarget, "CasaAuthTokenSvc/Rpc?method=%s", pMethod); | ||||||
|    retStatus = CopyMultiToWideAlloc(rpcTarget, |    retStatus = CopyMultiToWideAlloc(rpcTarget, | ||||||
|                                     (int) strlen(rpcTarget), |                                     (int) strlen(rpcTarget), | ||||||
|                                     &pWideRpcTarget, |                                     &pWideRpcTarget, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user