Index: components/os_crypt/libsecret_loader.cc |
diff --git a/components/os_crypt/libsecret_loader.cc b/components/os_crypt/libsecret_loader.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..84ad9a6cfaf95671b6ce877e91c35158d39d4a0a |
--- /dev/null |
+++ b/components/os_crypt/libsecret_loader.cc |
@@ -0,0 +1,73 @@ |
+// Copyright 2016 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. |
+ |
+#include "components/os_crypt/libsecret_loader.h" |
+ |
+#include <dlfcn.h> |
+ |
+#include "base/logging.h" |
+ |
+decltype(&::secret_password_store_sync) |
+ LibsecretLoader::secret_password_store_sync; |
+decltype(&::secret_service_search_sync) |
+ LibsecretLoader::secret_service_search_sync; |
+decltype(&::secret_password_clear_sync) |
+ LibsecretLoader::secret_password_clear_sync; |
+decltype(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; |
+decltype(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; |
+decltype(&::secret_item_get_attributes) |
+ LibsecretLoader::secret_item_get_attributes; |
+decltype(&::secret_item_load_secret_sync) |
+ LibsecretLoader::secret_item_load_secret_sync; |
+decltype(&::secret_value_unref) LibsecretLoader::secret_value_unref; |
+ |
+bool LibsecretLoader::libsecret_loaded = false; |
+ |
+const LibsecretLoader::FunctionInfo LibsecretLoader::functions[] = { |
+ {"secret_password_store_sync", |
+ reinterpret_cast<void**>(&secret_password_store_sync)}, |
+ {"secret_service_search_sync", |
+ reinterpret_cast<void**>(&secret_service_search_sync)}, |
+ {"secret_password_clear_sync", |
+ reinterpret_cast<void**>(&secret_password_clear_sync)}, |
+ {"secret_item_get_secret", |
+ reinterpret_cast<void**>(&secret_item_get_secret)}, |
+ {"secret_value_get_text", reinterpret_cast<void**>(&secret_value_get_text)}, |
+ {"secret_item_get_attributes", |
+ reinterpret_cast<void**>(&secret_item_get_attributes)}, |
+ {"secret_item_load_secret_sync", |
+ reinterpret_cast<void**>(&secret_item_load_secret_sync)}, |
+ {"secret_value_unref", reinterpret_cast<void**>(&secret_value_unref)}}; |
+ |
+//static |
vabr (Chromium)
2016/04/28 12:44:25
nit: The style requires a space between the "//" a
cfroussios
2016/04/28 14:33:43
Done.
|
+bool LibsecretLoader::LoadLibsecret() { |
+ if (libsecret_loaded) |
+ return true; |
+ |
+ void* handle = dlopen("libsecret-1.so.0", RTLD_NOW | RTLD_GLOBAL); |
+ if (!handle) { |
+ // We wanted to use libsecret, but we couldn't load it. Warn, because |
+ // either the user asked for this, or we autodetected it incorrectly. (Or |
+ // the system has broken libraries, which is also good to warn about.) |
+ // TODO(crbug.com/607435) |
vabr (Chromium)
2016/04/28 12:44:25
nit: Please also add the TODO message itself, like
cfroussios
2016/04/28 14:33:43
Done.
|
+ VLOG(1) << "Could not load libsecret-1.so.0: " << dlerror(); |
+ return false; |
+ } |
+ |
+ for (const auto& function : functions) { |
+ dlerror(); |
+ *function.pointer = dlsym(handle, function.name); |
+ const char* error = dlerror(); |
+ if (error) { |
+ VLOG(1) << "Unable to load symbol " << function.name << ": " << error; |
+ dlclose(handle); |
+ return false; |
+ } |
+ } |
+ |
+ libsecret_loaded = true; |
+ // We leak the library handle. That's OK: this function is called only once. |
+ return true; |
+} |
+ |