| 425 | **********************************************************************/ |
| 426 | |
| 427 | char *msDecryptStringTokens(mapObj *map, const char *in) |
| 428 | { |
| 429 | char *outbuf, *out; |
| 430 | |
| 431 | if (map == NULL) |
| 432 | { |
| 433 | msSetError(MS_MISCERR, "NULL MapObj.", "msLoadEncryptionKey()"); |
| 434 | return NULL; |
| 435 | } |
| 436 | |
| 437 | /* Start with a copy of the string. Decryption can only result in |
| 438 | * a string with the same or shorter length */ |
| 439 | if ((outbuf = (char *)malloc((strlen(in)+1)*sizeof(char))) == NULL) |
| 440 | { |
| 441 | msSetError(MS_MEMERR, NULL, "msDecryptStringTokens()"); |
| 442 | return NULL; |
| 443 | } |
| 444 | out = outbuf; |
| 445 | |
| 446 | while(*in != '\0') |
| 447 | { |
| 448 | if (*in == '{') |
| 449 | { |
| 450 | /* Possibly beginning of a token, look for closing bracket |
| 451 | ** and make sure all chars in between are valid hex encoding chars |
| 452 | */ |
| 453 | const char *pszStart, *pszEnd; |
| 454 | int valid_token = MS_FALSE; |
| 455 | |
| 456 | pszStart = in+1; |
| 457 | if ( (pszEnd = strchr(pszStart, '}')) != NULL && |
| 458 | pszEnd - pszStart > 1) |
| 459 | { |
| 460 | const char *pszTmp; |
| 461 | valid_token = MS_TRUE; |
| 462 | for(pszTmp = pszStart; pszTmp < pszEnd; pszTmp++) |
| 463 | { |
| 464 | if (!isxdigit(*pszTmp)) |
| 465 | { |
| 466 | valid_token = MS_FALSE; |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | if (valid_token) |
| 473 | { |
| 474 | /* Go ahead and decrypt the token */ |
| 475 | char *pszTmp; |
| 476 | |
| 477 | /* Make sure encryption key is loaded. We do this here instead |
| 478 | * of at the beginning of the function to avoid loading the |
| 479 | * key unless ready necessary. This is a very cheap call if |
| 480 | * the key is already loaded |
| 481 | */ |
| 482 | if (msLoadEncryptionKey(map) != MS_SUCCESS) |
| 483 | return NULL; |
| 484 |
no test coverage detected