| | 379 | static unsigned char fromhex (char c) |
| | 380 | { |
| | 381 | if ('0' <= c && c <= '9') |
| | 382 | { |
| | 383 | return c - '0'; |
| | 384 | } |
| | 385 | |
| | 386 | if ('A' <= c && c <= 'F') |
| | 387 | { |
| | 388 | return c - 'A'; |
| | 389 | } |
| | 390 | |
| | 391 | if ('a' <= c && c <= 'f') |
| | 392 | { |
| | 393 | return c - 'a'; |
| | 394 | } |
| | 395 | |
| | 396 | return 0; |
| | 397 | } |
| | 398 | |
| | 399 | static char tohex (unsigned char b) |
| | 400 | { |
| | 401 | b &= 0xF; |
| | 402 | |
| | 403 | if (b <= 9) |
| | 404 | { |
| | 405 | return b + '0'; |
| | 406 | } |
| | 407 | |
| | 408 | return 'A' + (b - 0xA); |
| | 409 | } |
| | 410 | |
| | 411 | static void decryptPassword (const char *pszCrypt, char *pszPlain) |
| | 412 | { |
| | 413 | /* A simple "decryption", character from the hex value. */ |
| | 414 | const char *s = pszCrypt; |
| | 415 | char *d = pszPlain; |
| | 416 | |
| | 417 | while (*s) |
| | 418 | { |
| | 419 | *d++ = (char)((fromhex (*s++) << 4) + fromhex (*s++)); |
| | 420 | } |
| | 421 | |
| | 422 | *d++ = 0; |
| | 423 | } |
| | 424 | |
| | 425 | static void encryptPassword (const char *pszPlain, char *pszCrypt) |
| | 426 | { |
| | 427 | /* A simple "encryption" encode each character as hex value. */ |
| | 428 | const char *s = pszPlain; |
| | 429 | char *d = pszCrypt; |
| | 430 | |
| | 431 | while (*s) |
| | 432 | { |
| | 433 | *d++ = tohex ((*s) >> 4); |
| | 434 | *d++ = tohex (*s); |
| | 435 | s++; |
| | 436 | } |
| | 437 | |
| | 438 | *d++ = 0; |
| | 439 | } |
| 431 | | } |
| | 494 | defaultPassword = 0; |
| | 495 | } |
| | 496 | |
| | 497 | t = 0, q = NULL; |
| | 498 | rc = ph->fsphQueryStringProperty (pRes->properties, "SPASSWORD", &q, &t); |
| | 499 | if ( rc == NO_ERROR |
| | 500 | && *q != '\0' |
| | 501 | && defaultPassword) |
| | 502 | { |
| | 503 | char p[1024]; |
| | 504 | p[0] = 0; |
| | 505 | |
| | 506 | decryptPassword (q, p); |
| | 507 | |
| | 508 | if (*p) |
| | 509 | { |
| | 510 | StrNCpy(pRes->srv.password, p, sizeof(pRes->srv.password) - 1); |
| | 511 | |
| | 512 | /* clear the plain password */ |
| | 513 | ph->fsphSetProperty (pRes->properties, "PASSWORD", ""); |
| | 514 | } |
| | 515 | } |
| | 516 | else |
| | 517 | { |
| | 518 | char c[1024]; |
| | 519 | encryptPassword (pRes->srv.password, c); |
| | 520 | |
| | 521 | ph->fsphSetProperty (pRes->properties, "SPASSWORD", c); |
| | 522 | |
| | 523 | // clear the plain password |
| | 524 | ph->fsphSetProperty (pRes->properties, "PASSWORD", ""); |
| | 525 | } |