Chromium Code Reviews| Index: base/nss_util.cc |
| diff --git a/base/nss_util.cc b/base/nss_util.cc |
| index e4d1762baa75c572b07458bb43f3eed465edc922..3229149601abb9a42caafb06371fb455ea6c0e21 100644 |
| --- a/base/nss_util.cc |
| +++ b/base/nss_util.cc |
| @@ -18,10 +18,14 @@ |
| #include <sys/vfs.h> |
| #endif |
| +#include <vector> |
| + |
| #include "base/environment.h" |
| +#include "base/file_path.h" |
| #include "base/file_util.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| +#include "base/native_library.h" |
| #include "base/scoped_ptr.h" |
| #include "base/stringprintf.h" |
| #include "base/threading/thread_restrictions.h" |
| @@ -402,6 +406,47 @@ void DisableNSSForkCheck() { |
| env->SetVar("NSS_STRICT_NOFORK", "DISABLED"); |
| } |
| +void LoadNSSLibraries() { |
| + // Some NSS libraries are linked dynamically so load them here. |
| +#if defined(USE_NSS) |
| + // Try to search for multiple directories to load the libraries. |
| + std::vector<FilePath> paths; |
| + |
| + // Use relative path to Search PATH for the library files. |
|
wtc
2011/03/18 18:46:31
Nit: the PATH environment variable is only used fo
|
| + paths.push_back(FilePath()); |
| + |
| + // For Debian derivaties NSS libraries are located here. |
|
wtc
2011/03/18 18:46:31
Nit: NSS libraries => dynamically loaded NSS libra
|
| + paths.push_back(FilePath("/usr/lib/nss")); |
| + |
| + // A list of library files to load. |
| + std::vector<std::string> libs; |
| + libs.push_back("libsoftokn3.so"); |
| + libs.push_back("libfreebl3.so"); |
| + |
| + // For each combination of library file and path, check for existence and |
| + // then load. |
| + size_t loaded = 0; |
| + for (size_t i = 0; i < libs.size(); ++i) { |
| + for (size_t j = 0; j < paths.size(); ++j) { |
| + FilePath path = paths[j].Append(libs[i]); |
| + if (file_util::PathExists(path)) { |
| + NativeLibrary lib = base::LoadNativeLibrary(path); |
| + if (lib) { |
| + ++loaded; |
| + break; |
| + } |
| + } |
| + } |
| + } |
| + |
| + if (loaded == libs.size()) { |
| + VLOG(3) << "NSS libraries loaded."; |
| + } else { |
| + LOG(WARNING) << "Failed to load NSS libraries."; |
| + } |
| +#endif |
| +} |
| + |
| bool CheckNSSVersion(const char* version) { |
| return !!NSS_VersionCheck(version); |
| } |