| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_auth_handler_ntlm.h" | 5 #include "net/http/http_auth_handler_ntlm.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 // For gethostname | 8 // For gethostname |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 #ifdef IS_BIG_ENDIAN | 206 #ifdef IS_BIG_ENDIAN |
| 207 /** | 207 /** |
| 208 * WriteUnicodeLE copies a unicode string from one buffer to another. The | 208 * WriteUnicodeLE copies a unicode string from one buffer to another. The |
| 209 * resulting unicode string is in little-endian format. The input string is | 209 * resulting unicode string is in little-endian format. The input string is |
| 210 * assumed to be in the native endianness of the local machine. It is safe | 210 * assumed to be in the native endianness of the local machine. It is safe |
| 211 * to pass the same buffer as both input and output, which is a handy way to | 211 * to pass the same buffer as both input and output, which is a handy way to |
| 212 * convert the unicode buffer to little-endian on big-endian platforms. | 212 * convert the unicode buffer to little-endian on big-endian platforms. |
| 213 */ | 213 */ |
| 214 static void* WriteUnicodeLE(void* buf, const char16* str, uint32 str_len) { | 214 static void* WriteUnicodeLE( |
| 215 void* buf, const base::char16* str, uint32 str_len) { |
| 215 // Convert input string from BE to LE. | 216 // Convert input string from BE to LE. |
| 216 uint8* cursor = static_cast<uint8*>(buf); | 217 uint8* cursor = static_cast<uint8*>(buf); |
| 217 const uint8* input = reinterpret_cast<const uint8*>(str); | 218 const uint8* input = reinterpret_cast<const uint8*>(str); |
| 218 for (uint32 i = 0; i < str_len; ++i, input += 2, cursor += 2) { | 219 for (uint32 i = 0; i < str_len; ++i, input += 2, cursor += 2) { |
| 219 // Allow for the case where |buf == str|. | 220 // Allow for the case where |buf == str|. |
| 220 uint8 temp = input[0]; | 221 uint8 temp = input[0]; |
| 221 cursor[0] = input[1]; | 222 cursor[0] = input[1]; |
| 222 cursor[1] = temp; | 223 cursor[1] = temp; |
| 223 } | 224 } |
| 224 return buf; | 225 return buf; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 uint32 domain_len, user_len, host_len; | 474 uint32 domain_len, user_len, host_len; |
| 474 | 475 |
| 475 // | 476 // |
| 476 // Get domain name. | 477 // Get domain name. |
| 477 // | 478 // |
| 478 if (unicode) { | 479 if (unicode) { |
| 479 #ifdef IS_BIG_ENDIAN | 480 #ifdef IS_BIG_ENDIAN |
| 480 ucs_domain_buf = domain; | 481 ucs_domain_buf = domain; |
| 481 domain_ptr = ucs_domain_buf.data(); | 482 domain_ptr = ucs_domain_buf.data(); |
| 482 domain_len = ucs_domain_buf.length() * 2; | 483 domain_len = ucs_domain_buf.length() * 2; |
| 483 WriteUnicodeLE(const_cast<void*>(domain_ptr), (const char16*) domain_ptr, | 484 WriteUnicodeLE(const_cast<void*>(domain_ptr), |
| 485 (const base::char16*) domain_ptr, |
| 484 ucs_domain_buf.length()); | 486 ucs_domain_buf.length()); |
| 485 #else | 487 #else |
| 486 domain_ptr = domain.data(); | 488 domain_ptr = domain.data(); |
| 487 domain_len = domain.length() * 2; | 489 domain_len = domain.length() * 2; |
| 488 #endif | 490 #endif |
| 489 } else { | 491 } else { |
| 490 oem_domain_buf = base::SysWideToNativeMB(base::UTF16ToWide(domain)); | 492 oem_domain_buf = base::SysWideToNativeMB(base::UTF16ToWide(domain)); |
| 491 domain_ptr = oem_domain_buf.data(); | 493 domain_ptr = oem_domain_buf.data(); |
| 492 domain_len = oem_domain_buf.length(); | 494 domain_len = oem_domain_buf.length(); |
| 493 } | 495 } |
| 494 | 496 |
| 495 // | 497 // |
| 496 // Get user name. | 498 // Get user name. |
| 497 // | 499 // |
| 498 if (unicode) { | 500 if (unicode) { |
| 499 #ifdef IS_BIG_ENDIAN | 501 #ifdef IS_BIG_ENDIAN |
| 500 ucs_user_buf = username; | 502 ucs_user_buf = username; |
| 501 user_ptr = ucs_user_buf.data(); | 503 user_ptr = ucs_user_buf.data(); |
| 502 user_len = ucs_user_buf.length() * 2; | 504 user_len = ucs_user_buf.length() * 2; |
| 503 WriteUnicodeLE(const_cast<void*>(user_ptr), (const char16*) user_ptr, | 505 WriteUnicodeLE(const_cast<void*>(user_ptr), (const base::char16*) user_ptr, |
| 504 ucs_user_buf.length()); | 506 ucs_user_buf.length()); |
| 505 #else | 507 #else |
| 506 user_ptr = username.data(); | 508 user_ptr = username.data(); |
| 507 user_len = username.length() * 2; | 509 user_len = username.length() * 2; |
| 508 #endif | 510 #endif |
| 509 } else { | 511 } else { |
| 510 oem_user_buf = base::SysWideToNativeMB(base::UTF16ToWide(username)); | 512 oem_user_buf = base::SysWideToNativeMB(base::UTF16ToWide(username)); |
| 511 user_ptr = oem_user_buf.data(); | 513 user_ptr = oem_user_buf.data(); |
| 512 user_len = oem_user_buf.length(); | 514 user_len = oem_user_buf.length(); |
| 513 } | 515 } |
| 514 | 516 |
| 515 // | 517 // |
| 516 // Get workstation name (use local machine's hostname). | 518 // Get workstation name (use local machine's hostname). |
| 517 // | 519 // |
| 518 if (unicode) { | 520 if (unicode) { |
| 519 // hostname is ASCII, so we can do a simple zero-pad expansion: | 521 // hostname is ASCII, so we can do a simple zero-pad expansion: |
| 520 ucs_host_buf.assign(hostname.begin(), hostname.end()); | 522 ucs_host_buf.assign(hostname.begin(), hostname.end()); |
| 521 host_ptr = ucs_host_buf.data(); | 523 host_ptr = ucs_host_buf.data(); |
| 522 host_len = ucs_host_buf.length() * 2; | 524 host_len = ucs_host_buf.length() * 2; |
| 523 #ifdef IS_BIG_ENDIAN | 525 #ifdef IS_BIG_ENDIAN |
| 524 WriteUnicodeLE(const_cast<void*>(host_ptr), (const char16*) host_ptr, | 526 WriteUnicodeLE(const_cast<void*>(host_ptr), (const base::char16*) host_ptr, |
| 525 ucs_host_buf.length()); | 527 ucs_host_buf.length()); |
| 526 #endif | 528 #endif |
| 527 } else { | 529 } else { |
| 528 host_ptr = hostname.data(); | 530 host_ptr = hostname.data(); |
| 529 host_len = hostname.length(); | 531 host_len = hostname.length(); |
| 530 } | 532 } |
| 531 | 533 |
| 532 // | 534 // |
| 533 // Now that we have generated all of the strings, we can allocate out_buf. | 535 // Now that we have generated all of the strings, we can allocate out_buf. |
| 534 // | 536 // |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // NOTE: Default credentials are not supported for the portable implementation | 723 // NOTE: Default credentials are not supported for the portable implementation |
| 722 // of NTLM. | 724 // of NTLM. |
| 723 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM); | 725 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM); |
| 724 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 726 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
| 725 return ERR_INVALID_RESPONSE; | 727 return ERR_INVALID_RESPONSE; |
| 726 handler->swap(tmp_handler); | 728 handler->swap(tmp_handler); |
| 727 return OK; | 729 return OK; |
| 728 } | 730 } |
| 729 | 731 |
| 730 } // namespace net | 732 } // namespace net |
| OLD | NEW |