Bug 1442275 - Stop using PR_LoadLibrary in GSSAPI. r=mayhemer draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 25 Feb 2018 01:32:37 +0900
changeset 791081 9155cc62101da835424735c2f18f59f6cac5ddb6
parent 791080 b16cf6543c2fc4bdcb688479563a75d048451d78
child 791082 a15f5f757ce4e6b48b904914ceb6b715877c570d
push id108682
push userVYV03354@nifty.ne.jp
push dateThu, 03 May 2018 12:46:41 +0000
reviewersmayhemer
bugs1442275
milestone61.0a1
Bug 1442275 - Stop using PR_LoadLibrary in GSSAPI. r=mayhemer MozReview-Commit-ID: 756qF1thw7A
extensions/auth/nsAuthGSSAPI.cpp
--- a/extensions/auth/nsAuthGSSAPI.cpp
+++ b/extensions/auth/nsAuthGSSAPI.cpp
@@ -12,23 +12,23 @@
 // Also described here:
 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/http-sso-1.asp
 //
 //
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
-#include "prlink.h"
 #include "nsCOMPtr.h"
 #include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
 #include "nsIServiceManager.h"
 #include "nsMemory.h"
 #include "nsNativeCharsetUtils.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/SharedLibrary.h"
 #include "mozilla/Telemetry.h"
 
 #include "nsAuthGSSAPI.h"
 
 #ifdef XP_MACOSX
 #include <Kerberos/Kerberos.h>
 #endif
 
@@ -98,43 +98,46 @@ static PRLibrary* gssLibrary = nullptr;
 static PRFuncPtr KLCacheHasValidTicketsPtr;
 #define KLCacheHasValidTickets_ptr \
         ((KLCacheHasValidTickets_type)*KLCacheHasValidTicketsPtr)
 #endif
 
 static nsresult
 gssInit()
 {
+#ifdef XP_WIN
+    nsAutoString libPathU;
+    Preferences::GetString(kNegotiateAuthGssLib, libPathU);
+    NS_ConvertUTF16toUTF8 libPath(libPathU);
+#else
     nsAutoCString libPath;
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs) {
-        prefs->GetCharPref(kNegotiateAuthGssLib, libPath);
-        prefs->GetBoolPref(kNegotiateAuthNativeImp, &gssNativeImp);
-    }
+    Preferences::GetCString(kNegotiateAuthGssLib, libPath);
+#endif
+    gssNativeImp = Preferences::GetBool(kNegotiateAuthNativeImp);
 
     PRLibrary *lib = nullptr;
 
     if (!libPath.IsEmpty()) {
         LOG(("Attempting to load user specified library [%s]\n", libPath.get()));
         gssNativeImp = false;
-        lib = PR_LoadLibrary(libPath.get());
+#ifdef XP_WIN
+        lib = LoadLibraryWithFlags(libPathU.get());
+#else
+        lib = LoadLibraryWithFlags(libPath.get());
+#endif
     }
     else {
 #ifdef XP_WIN
         #ifdef _WIN64
-        static const char *kLibName = "gssapi64";
+        NS_NAMED_LITERAL_STRING(kLibName, "gssapi64.dll");
         #else
-        static const char *kLibName = "gssapi32";
+        NS_NAMED_LITERAL_STRING(kLibName, "gssapi32.dll");
         #endif
 
-        char *libName = PR_GetLibraryName(nullptr, kLibName);
-        if (libName) {
-            lib = PR_LoadLibrary(kLibName);
-            PR_FreeLibraryName(libName);
-        }
+        lib = LoadLibraryWithFlags(kLibName.get());
 #elif defined(__OpenBSD__)
         /* OpenBSD doesn't register inter-library dependencies in basesystem
          * libs therefor we need to load all the libraries gssapi depends on,
          * in the correct order and with LD_GLOBAL for GSSAPI auth to work
          * fine.
          */
 
         const char *const verLibNames[] = {