| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_gssapi_posix.h" | 5 #include "net/http/http_auth_gssapi_posix.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/singleton.h" | |
| 15 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 19 | 18 |
| 20 // These are defined for the GSSAPI library: | 19 // These are defined for the GSSAPI library: |
| 21 // Paraphrasing the comments from gssapi.h: | 20 // Paraphrasing the comments from gssapi.h: |
| 22 // "The implementation must reserve static storage for a | 21 // "The implementation must reserve static storage for a |
| 23 // gss_OID_desc object for each constant. That constant | 22 // gss_OID_desc object for each constant. That constant |
| 24 // should be initialized to point to that gss_OID_desc." | 23 // should be initialized to point to that gss_OID_desc." |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 DescribeOid(gssapi_lib, | 377 DescribeOid(gssapi_lib, |
| 379 mech_type).c_str(), | 378 mech_type).c_str(), |
| 380 ctx_flags, | 379 ctx_flags, |
| 381 locally_initiated, | 380 locally_initiated, |
| 382 open); | 381 open); |
| 383 return description; | 382 return description; |
| 384 } | 383 } |
| 385 | 384 |
| 386 } // namespace | 385 } // namespace |
| 387 | 386 |
| 388 GSSAPISharedLibrary::GSSAPISharedLibrary() | 387 GSSAPISharedLibrary::GSSAPISharedLibrary(const std::string& gssapi_library_name) |
| 389 : initialized_(false), | 388 : initialized_(false), |
| 389 gssapi_library_name_(gssapi_library_name), |
| 390 gssapi_library_(NULL), | 390 gssapi_library_(NULL), |
| 391 import_name_(NULL), | 391 import_name_(NULL), |
| 392 release_name_(NULL), | 392 release_name_(NULL), |
| 393 release_buffer_(NULL), | 393 release_buffer_(NULL), |
| 394 display_name_(NULL), | 394 display_name_(NULL), |
| 395 display_status_(NULL), | 395 display_status_(NULL), |
| 396 init_sec_context_(NULL), | 396 init_sec_context_(NULL), |
| 397 wrap_size_limit_(NULL), | 397 wrap_size_limit_(NULL), |
| 398 delete_sec_context_(NULL), | 398 delete_sec_context_(NULL), |
| 399 inquire_context_(NULL) { | 399 inquire_context_(NULL) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 415 bool GSSAPISharedLibrary::InitImpl() { | 415 bool GSSAPISharedLibrary::InitImpl() { |
| 416 DCHECK(!initialized_); | 416 DCHECK(!initialized_); |
| 417 gssapi_library_ = LoadSharedLibrary(); | 417 gssapi_library_ = LoadSharedLibrary(); |
| 418 if (gssapi_library_ == NULL) | 418 if (gssapi_library_ == NULL) |
| 419 return false; | 419 return false; |
| 420 initialized_ = true; | 420 initialized_ = true; |
| 421 return true; | 421 return true; |
| 422 } | 422 } |
| 423 | 423 |
| 424 base::NativeLibrary GSSAPISharedLibrary::LoadSharedLibrary() { | 424 base::NativeLibrary GSSAPISharedLibrary::LoadSharedLibrary() { |
| 425 static const char* kLibraryNames[] = { | 425 const char** library_names; |
| 426 size_t num_lib_names; |
| 427 const char* user_specified_library[1]; |
| 428 if (!gssapi_library_name_.empty()) { |
| 429 user_specified_library[0] = gssapi_library_name_.c_str(); |
| 430 library_names = user_specified_library; |
| 431 num_lib_names = 1; |
| 432 } else { |
| 433 static const char* kDefaultLibraryNames[] = { |
| 426 #if defined(OS_MACOSX) | 434 #if defined(OS_MACOSX) |
| 427 "libgssapi_krb5.dylib" // MIT Kerberos | 435 "libgssapi_krb5.dylib" // MIT Kerberos |
| 428 #else | 436 #else |
| 429 "libgssapi_krb5.so.2", // MIT Kerberos - FC, Suse10, Debian | 437 "libgssapi_krb5.so.2", // MIT Kerberos - FC, Suse10, Debian |
| 430 "libgssapi.so.4", // Heimdal - Suse10, MDK | 438 "libgssapi.so.4", // Heimdal - Suse10, MDK |
| 431 "libgssapi.so.1" // Heimdal - Suse9, CITI - FC, MDK, Suse10 | 439 "libgssapi.so.1" // Heimdal - Suse9, CITI - FC, MDK, Suse10 |
| 432 #endif | 440 #endif |
| 433 }; | 441 }; |
| 434 static size_t num_lib_names = arraysize(kLibraryNames); | 442 library_names = kDefaultLibraryNames; |
| 443 num_lib_names = arraysize(kDefaultLibraryNames); |
| 444 } |
| 435 | 445 |
| 436 for (size_t i = 0; i < num_lib_names; ++i) { | 446 for (size_t i = 0; i < num_lib_names; ++i) { |
| 437 const char* library_name = kLibraryNames[i]; | 447 const char* library_name = library_names[i]; |
| 438 FilePath file_path(library_name); | 448 FilePath file_path(library_name); |
| 439 base::NativeLibrary lib = base::LoadNativeLibrary(file_path); | 449 base::NativeLibrary lib = base::LoadNativeLibrary(file_path); |
| 440 if (lib) { | 450 if (lib) { |
| 441 // Only return this library if we can bind the functions we need. | 451 // Only return this library if we can bind the functions we need. |
| 442 if (BindMethods(lib)) | 452 if (BindMethods(lib)) |
| 443 return lib; | 453 return lib; |
| 444 base::UnloadNativeLibrary(lib); | 454 base::UnloadNativeLibrary(lib); |
| 445 } | 455 } |
| 446 } | 456 } |
| 447 LOG(WARNING) << "Unable to find a compatible GSSAPI library"; | 457 LOG(WARNING) << "Unable to find a compatible GSSAPI library"; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 return inquire_context_(minor_status, | 616 return inquire_context_(minor_status, |
| 607 context_handle, | 617 context_handle, |
| 608 src_name, | 618 src_name, |
| 609 targ_name, | 619 targ_name, |
| 610 lifetime_rec, | 620 lifetime_rec, |
| 611 mech_type, | 621 mech_type, |
| 612 ctx_flags, | 622 ctx_flags, |
| 613 locally_initiated, | 623 locally_initiated, |
| 614 open); | 624 open); |
| 615 } | 625 } |
| 616 GSSAPILibrary* GSSAPILibrary::GetDefault() { | |
| 617 return Singleton<GSSAPISharedLibrary>::get(); | |
| 618 } | |
| 619 | 626 |
| 620 ScopedSecurityContext::ScopedSecurityContext(GSSAPILibrary* gssapi_lib) | 627 ScopedSecurityContext::ScopedSecurityContext(GSSAPILibrary* gssapi_lib) |
| 621 : security_context_(GSS_C_NO_CONTEXT), | 628 : security_context_(GSS_C_NO_CONTEXT), |
| 622 gssapi_lib_(gssapi_lib) { | 629 gssapi_lib_(gssapi_lib) { |
| 623 DCHECK(gssapi_lib_); | 630 DCHECK(gssapi_lib_); |
| 624 } | 631 } |
| 625 | 632 |
| 626 ScopedSecurityContext::~ScopedSecurityContext() { | 633 ScopedSecurityContext::~ScopedSecurityContext() { |
| 627 if (security_context_ != GSS_C_NO_CONTEXT) { | 634 if (security_context_ != GSS_C_NO_CONTEXT) { |
| 628 gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; | 635 gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 if (rv != OK) { | 875 if (rv != OK) { |
| 869 LOG(ERROR) << "Problem initializing context. \n" | 876 LOG(ERROR) << "Problem initializing context. \n" |
| 870 << DisplayExtendedStatus(library_, major_status, minor_status) | 877 << DisplayExtendedStatus(library_, major_status, minor_status) |
| 871 << '\n' | 878 << '\n' |
| 872 << DescribeContext(library_, scoped_sec_context_.get()); | 879 << DescribeContext(library_, scoped_sec_context_.get()); |
| 873 } | 880 } |
| 874 return rv; | 881 return rv; |
| 875 } | 882 } |
| 876 | 883 |
| 877 } // namespace net | 884 } // namespace net |
| OLD | NEW |