Bug 712579 - Load nssckbi from the location of nss3. r=kaie
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 27 Dec 2011 18:11:17 +0100
changeset 85479 345863ffe8c8c9f04e1b1ace6ea628073f29cd23
parent 85478 4202e19f36e29ed8f9d95fe5747cf352b1209d6d
child 85480 2a6cac678c94d9fe78c11b837b270e3304fc2df7
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaie
bugs712579
milestone12.0a1
Bug 712579 - Load nssckbi from the location of nss3. r=kaie
security/manager/ssl/src/Makefile.in
security/manager/ssl/src/nsNSSComponent.cpp
--- a/security/manager/ssl/src/Makefile.in
+++ b/security/manager/ssl/src/Makefile.in
@@ -110,16 +110,20 @@ ifdef MOZ_XUL
 CPPSRCS += nsCertTree.cpp
 endif
 
 CSRCS += md4.c
 
 
 EXTRA_DEPS = $(NSS_DEP_LIBS)
 
-DEFINES += -DNSS_ENABLE_ECC
+DEFINES += \
+  -DNSS_ENABLE_ECC \
+  -DDLL_PREFIX=\"$(DLL_PREFIX)\" \
+  -DDLL_SUFFIX=\"$(DLL_SUFFIX)\" \
+  $(NULL)
 
 # Use local includes because they are inserted before INCLUDES
 # so that Mozilla's nss.h is used, not glibc's
 LOCAL_INCLUDES += $(NSS_CFLAGS)
 
 include $(topsrcdir)/config/rules.mk
 
--- a/security/manager/ssl/src/nsNSSComponent.cpp
+++ b/security/manager/ssl/src/nsNSSComponent.cpp
@@ -823,17 +823,20 @@ nsNSSComponent::InstallLoadableRoots()
   nsAutoString modName;
   rv = GetPIPNSSBundleString("RootCertModuleName", modName);
   if (NS_FAILED(rv)) return;
 
   nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
   if (!directoryService)
     return;
 
+  static const char nss_lib[] = "nss3";
   const char *possible_ckbi_locations[] = {
+    nss_lib, // This special value means: search for ckbi in the directory
+             // where nss3 is.
     NS_XPCOM_CURRENT_PROCESS_DIR,
     NS_GRE_DIR,
     0 // This special value means: 
       //   search for ckbi in the directories on the shared
       //   library/DLL search path
   };
 
   for (size_t il = 0; il < sizeof(possible_ckbi_locations)/sizeof(const char*); ++il) {
@@ -841,19 +844,40 @@ nsNSSComponent::InstallLoadableRoots()
     char *fullLibraryPath = nsnull;
 
     if (!possible_ckbi_locations[il])
     {
       fullLibraryPath = PR_GetLibraryName(nsnull, "nssckbi");
     }
     else
     {
-      directoryService->Get( possible_ckbi_locations[il],
-                             NS_GET_IID(nsILocalFile), 
-                             getter_AddRefs(mozFile));
+      if (possible_ckbi_locations[il] == nss_lib) {
+        // Get the location of the nss3 library.
+        char *nss_path = PR_GetLibraryFilePathname(DLL_PREFIX "nss3" DLL_SUFFIX,
+                                                   (PRFuncPtr) NSS_Initialize);
+        if (!nss_path) {
+          continue;
+        }
+        // Get the directory containing the nss3 library.
+        nsCOMPtr<nsILocalFile> nssLib(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
+        if (NS_SUCCEEDED(rv)) {
+          rv = nssLib->InitWithNativePath(nsDependentCString(nss_path));
+        }
+        PR_Free(nss_path);
+        if (NS_SUCCEEDED(rv)) {
+          nsCOMPtr<nsIFile> file;
+          if (NS_SUCCEEDED(nssLib->GetParent(getter_AddRefs(file)))) {
+            mozFile = do_QueryInterface(file);
+          }
+        }
+      } else {
+        directoryService->Get( possible_ckbi_locations[il],
+                               NS_GET_IID(nsILocalFile), 
+                               getter_AddRefs(mozFile));
+      }
   
       if (!mozFile) {
         continue;
       }
 
       nsCAutoString processDir;
       mozFile->GetNativePath(processDir);
       fullLibraryPath = PR_GetLibraryName(processDir.get(), "nssckbi");