summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer/firefox_importer_utils.cc
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 15:59:18 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 15:59:18 +0000
commitde0e72d3150fdbea9b8d9071c44b07917ce67d62 (patch)
tree86e58f88c32374dcf6b05d2990c03a0ad357d397 /chrome/browser/importer/firefox_importer_utils.cc
parentc8b58a46e4f97791f81500006e464a94d68c8c12 (diff)
downloadchromium_src-de0e72d3150fdbea9b8d9071c44b07917ce67d62.zip
chromium_src-de0e72d3150fdbea9b8d9071c44b07917ce67d62.tar.gz
chromium_src-de0e72d3150fdbea9b8d9071c44b07917ce67d62.tar.bz2
Linux: Import passwords from Firefox.
BUG=11191 TEST=Try importing password from Firefox on Linux and it should work (though they are not accessible in UI yet). Review URL: http://codereview.chromium.org/119267 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17943 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer/firefox_importer_utils.cc')
-rw-r--r--chrome/browser/importer/firefox_importer_utils.cc94
1 files changed, 51 insertions, 43 deletions
diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc
index afe484e..6bda867 100644
--- a/chrome/browser/importer/firefox_importer_utils.cc
+++ b/chrome/browser/importer/firefox_importer_utils.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -24,19 +24,6 @@
namespace {
-#if defined(OS_WIN)
-// NOTE: Keep these in order since we need test all those paths according
-// to priority. For example. One machine has multiple users. One non-admin
-// user installs Firefox 2, which causes there is a Firefox2 entry under HKCU.
-// One admin user installs Firefox 3, which causes there is a Firefox 3 entry
-// under HKLM. So when the non-admin user log in, we should deal with Firefox 2
-// related data instead of Firefox 3.
-static const HKEY kFireFoxRegistryPaths[] = {
- HKEY_CURRENT_USER,
- HKEY_LOCAL_MACHINE
-};
-#endif
-
// FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from
// the search URL when importing search engines.
class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter {
@@ -84,6 +71,17 @@ class SetDllDirectoryCaller {
} // namespace
#if defined(OS_WIN)
+// NOTE: Keep these in order since we need test all those paths according
+// to priority. For example. One machine has multiple users. One non-admin
+// user installs Firefox 2, which causes there is a Firefox2 entry under HKCU.
+// One admin user installs Firefox 3, which causes there is a Firefox 3 entry
+// under HKLM. So when the non-admin user log in, we should deal with Firefox 2
+// related data instead of Firefox 3.
+static const HKEY kFireFoxRegistryPaths[] = {
+ HKEY_CURRENT_USER,
+ HKEY_LOCAL_MACHINE
+};
+
int GetCurrentFirefoxMajorVersionFromRegistry() {
TCHAR ver_buffer[128];
DWORD ver_buffer_length = sizeof(ver_buffer);
@@ -454,9 +452,7 @@ NSSDecryptor::NSSDecryptor()
PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL),
PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL),
PL_ArenaFinish(NULL), PR_Cleanup(NULL),
-#if defined(OS_WIN)
nss3_dll_(NULL), softokn3_dll_(NULL),
-#endif
is_nss_initialized_(false) {
}
@@ -514,30 +510,48 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,
return false;
}
}
-
- // NSPR DLLs are already loaded now.
HMODULE plds4_dll = GetModuleHandle(kPLDS4Library);
HMODULE nspr4_dll = GetModuleHandle(kNSPR4Library);
+#elif defined(OS_LINUX)
+ nss3_dll_ = base::LoadNativeLibrary(FilePath("libnss3.so"));
+ if (nss3_dll_ == NULL)
+ return false;
+ base::NativeLibrary plds4_dll = base::LoadNativeLibrary(
+ FilePath("libplds4.so"));
+ base::NativeLibrary nspr4_dll = base::LoadNativeLibrary(
+ FilePath("libnspr4.so"));
+#else
+ // TODO(port): Check on MAC
+ NOTIMPLEMENTED();
+ return false;
+#endif
+
+ // NSPR DLLs are already loaded now.
if (plds4_dll == NULL || nspr4_dll == NULL) {
Free();
return false;
}
// Gets the function address.
- NSS_Init = (NSSInitFunc)GetProcAddress(nss3_dll_, "NSS_Init");
- NSS_Shutdown = (NSSShutdownFunc)GetProcAddress(nss3_dll_, "NSS_Shutdown");
+ NSS_Init = (NSSInitFunc)
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "NSS_Init");
+ NSS_Shutdown = (NSSShutdownFunc)
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "NSS_Shutdown");
PK11_GetInternalKeySlot = (PK11GetInternalKeySlotFunc)
- GetProcAddress(nss3_dll_, "PK11_GetInternalKeySlot");
- PK11_FreeSlot = (PK11FreeSlotFunc)GetProcAddress(nss3_dll_, "PK11_FreeSlot");
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_,
+ "PK11_GetInternalKeySlot");
+ PK11_FreeSlot = (PK11FreeSlotFunc)
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11_FreeSlot");
PK11_Authenticate = (PK11AuthenticateFunc)
- GetProcAddress(nss3_dll_, "PK11_Authenticate");
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11_Authenticate");
PK11SDR_Decrypt = (PK11SDRDecryptFunc)
- GetProcAddress(nss3_dll_, "PK11SDR_Decrypt");
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "PK11SDR_Decrypt");
SECITEM_FreeItem = (SECITEMFreeItemFunc)
- GetProcAddress(nss3_dll_, "SECITEM_FreeItem");
+ base::GetFunctionPointerFromNativeLibrary(nss3_dll_, "SECITEM_FreeItem");
PL_ArenaFinish = (PLArenaFinishFunc)
- GetProcAddress(plds4_dll, "PL_ArenaFinish");
- PR_Cleanup = (PRCleanupFunc)GetProcAddress(nspr4_dll, "PR_Cleanup");
+ base::GetFunctionPointerFromNativeLibrary(plds4_dll, "PL_ArenaFinish");
+ PR_Cleanup = (PRCleanupFunc)
+ base::GetFunctionPointerFromNativeLibrary(nspr4_dll, "PR_Cleanup");
if (NSS_Init == NULL || NSS_Shutdown == NULL ||
PK11_GetInternalKeySlot == NULL || PK11_FreeSlot == NULL ||
@@ -556,11 +570,6 @@ bool NSSDecryptor::Init(const std::wstring& dll_path,
is_nss_initialized_ = true;
return true;
-#else
- // TODO(port): Load NSS.
- NOTIMPLEMENTED();
- return false;
-#endif
}
void NSSDecryptor::Free() {
@@ -570,13 +579,11 @@ void NSSDecryptor::Free() {
PR_Cleanup();
is_nss_initialized_ = false;
}
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
if (softokn3_dll_ != NULL)
- FreeLibrary(softokn3_dll_);
- softokn3_dll_ = NULL;
+ base::UnloadNativeLibrary(softokn3_dll_);
if (nss3_dll_ != NULL)
- FreeLibrary(nss3_dll_);
- nss3_dll_ = NULL;
+ base::UnloadNativeLibrary(nss3_dll_);
#endif
NSS_Init = NULL;
NSS_Shutdown = NULL;
@@ -587,6 +594,8 @@ void NSSDecryptor::Free() {
SECITEM_FreeItem = NULL;
PL_ArenaFinish = NULL;
PR_Cleanup = NULL;
+ nss3_dll_ = NULL;
+ softokn3_dll_ = NULL;
}
// This method is based on some Firefox code in
@@ -630,20 +639,19 @@ void NSSDecryptor::Free() {
* ***** END LICENSE BLOCK ***** */
std::wstring NSSDecryptor::Decrypt(const std::string& crypt) const {
-#if defined(OS_WIN)
- // Do nothing if NSS is not loaded.
- if (!nss3_dll_)
- return std::wstring();
-#else
+#if !defined(OS_WIN) && !defined(OS_LINUX)
// TODO(port): Load nss3.
NOTIMPLEMENTED();
return std::wstring();
#endif
- std::string plain;
+ // Do nothing if NSS is not loaded.
+ if (!nss3_dll_)
+ return std::wstring();
// The old style password is encoded in base64. They are identified
// by a leading '~'. Otherwise, we should decrypt the text.
+ std::string plain;
if (crypt[0] != '~') {
std::string decoded_data;
net::Base64Decode(crypt, &decoded_data);