OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
vabr (Chromium)
2016/04/28 07:53:21
nit: No (c).
cfroussios
2016/04/28 12:18:10
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/os_crypt/libsecret_loader.h" | |
6 | |
7 #include <dlfcn.h> | |
8 | |
9 #include "base/logging.h" | |
10 | |
11 typeof(&::secret_password_store_sync) | |
vabr (Chromium)
2016/04/28 07:53:20
Please use C++11 decltype instead of the non-stand
cfroussios
2016/04/28 12:18:11
Done.
| |
12 LibsecretLoader::secret_password_store_sync; | |
13 typeof(&::secret_service_search_sync) | |
14 LibsecretLoader::secret_service_search_sync; | |
15 typeof(&::secret_password_clear_sync) | |
16 LibsecretLoader::secret_password_clear_sync; | |
17 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; | |
18 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; | |
19 typeof(&::secret_item_get_attributes) | |
20 LibsecretLoader::secret_item_get_attributes; | |
21 typeof(&::secret_item_load_secret_sync) | |
22 LibsecretLoader::secret_item_load_secret_sync; | |
23 typeof(&::secret_value_unref) LibsecretLoader::secret_value_unref; | |
24 | |
25 bool LibsecretLoader::libsecret_loaded = false; | |
26 | |
27 const LibsecretLoader::FunctionInfo LibsecretLoader::functions[] = { | |
28 {"secret_password_store_sync", | |
29 reinterpret_cast<void**>(&secret_password_store_sync)}, | |
30 {"secret_service_search_sync", | |
31 reinterpret_cast<void**>(&secret_service_search_sync)}, | |
32 {"secret_password_clear_sync", | |
33 reinterpret_cast<void**>(&secret_password_clear_sync)}, | |
34 {"secret_item_get_secret", | |
35 reinterpret_cast<void**>(&secret_item_get_secret)}, | |
36 {"secret_value_get_text", reinterpret_cast<void**>(&secret_value_get_text)}, | |
37 {"secret_item_get_attributes", | |
38 reinterpret_cast<void**>(&secret_item_get_attributes)}, | |
39 {"secret_item_load_secret_sync", | |
40 reinterpret_cast<void**>(&secret_item_load_secret_sync)}, | |
41 {"secret_value_unref", reinterpret_cast<void**>(&secret_value_unref)}, | |
42 {nullptr, nullptr}}; | |
43 | |
44 bool LibsecretLoader::LoadLibsecret() { | |
vabr (Chromium)
2016/04/28 07:53:21
nit: For all static methods the convention is to a
cfroussios
2016/04/28 12:18:10
Done.
| |
45 if (libsecret_loaded) | |
46 return true; | |
47 | |
48 void* handle = dlopen("libsecret-1.so.0", RTLD_NOW | RTLD_GLOBAL); | |
49 if (!handle) { | |
50 // We wanted to use libsecret, but we couldn't load it. Warn, because | |
51 // either the user asked for this, or we autodetected it incorrectly. (Or | |
52 // the system has broken libraries, which is also good to warn about.) | |
53 LOG(WARNING) << "Could not load libsecret-1.so.0: " << dlerror(); | |
vabr (Chromium)
2016/04/28 07:53:21
LOG(WARNING) is discouraged [1]. Please replace th
cfroussios
2016/04/28 12:18:10
Done.
| |
54 return false; | |
55 } | |
56 | |
57 for (size_t i = 0; functions[i].name; ++i) { | |
vabr (Chromium)
2016/04/28 07:53:21
If you use the range-based for loop, you can get r
cfroussios
2016/04/28 12:18:10
Done.
| |
58 dlerror(); | |
59 *functions[i].pointer = dlsym(handle, functions[i].name); | |
60 const char* error = dlerror(); | |
61 if (error) { | |
62 VLOG(1) << "Unable to load symbol " << functions[i].name << ": " << error; | |
63 dlclose(handle); | |
64 return false; | |
65 } | |
66 } | |
67 | |
68 libsecret_loaded = true; | |
69 // We leak the library handle. That's OK: this function is called only once. | |
70 return true; | |
71 } | |
72 | |
OLD | NEW |