OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/os_crypt/libsecret_util_posix.h" | 5 #include "components/os_crypt/libsecret_util_posix.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <utility> | |
vabr (Chromium)
2016/05/13 15:10:18
What is this used for?
cfroussios
2016/05/13 17:09:12
Done.
| |
8 | 9 |
10 #include "base/base64.h" | |
vabr (Chromium)
2016/05/13 15:10:18
And what is this used for?
cfroussios
2016/05/13 17:09:12
Done.
| |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
11 | 13 |
14 // | |
15 // LibsecretLoader | |
16 // | |
17 | |
12 decltype( | 18 decltype( |
13 &::secret_password_store_sync) LibsecretLoader::secret_password_store_sync; | 19 &::secret_password_store_sync) LibsecretLoader::secret_password_store_sync; |
14 decltype( | 20 decltype( |
15 &::secret_service_search_sync) LibsecretLoader::secret_service_search_sync; | 21 &::secret_service_search_sync) LibsecretLoader::secret_service_search_sync; |
16 decltype( | 22 decltype( |
17 &::secret_password_clear_sync) LibsecretLoader::secret_password_clear_sync; | 23 &::secret_password_clear_sync) LibsecretLoader::secret_password_clear_sync; |
18 decltype(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; | 24 decltype(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; |
19 decltype(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; | 25 decltype(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; |
20 decltype( | 26 decltype( |
21 &::secret_item_get_attributes) LibsecretLoader::secret_item_get_attributes; | 27 &::secret_item_get_attributes) LibsecretLoader::secret_item_get_attributes; |
22 decltype(&::secret_item_load_secret_sync) | 28 decltype(&::secret_item_load_secret_sync) |
23 LibsecretLoader::secret_item_load_secret_sync; | 29 LibsecretLoader::secret_item_load_secret_sync; |
24 decltype(&::secret_value_unref) LibsecretLoader::secret_value_unref; | 30 decltype(&::secret_value_unref) LibsecretLoader::secret_value_unref; |
31 decltype( | |
32 &::secret_service_lookup_sync) LibsecretLoader::secret_service_lookup_sync; | |
25 | 33 |
26 bool LibsecretLoader::libsecret_loaded_ = false; | 34 bool LibsecretLoader::libsecret_loaded_ = false; |
27 | 35 |
28 const LibsecretLoader::FunctionInfo LibsecretLoader::kFunctions[] = { | 36 const LibsecretLoader::FunctionInfo LibsecretLoader::kFunctions[] = { |
29 {"secret_password_store_sync", | |
30 reinterpret_cast<void**>(&secret_password_store_sync)}, | |
31 {"secret_service_search_sync", | |
32 reinterpret_cast<void**>(&secret_service_search_sync)}, | |
33 {"secret_password_clear_sync", | |
34 reinterpret_cast<void**>(&secret_password_clear_sync)}, | |
35 {"secret_item_get_secret", | 37 {"secret_item_get_secret", |
36 reinterpret_cast<void**>(&secret_item_get_secret)}, | 38 reinterpret_cast<void**>(&secret_item_get_secret)}, |
37 {"secret_value_get_text", reinterpret_cast<void**>(&secret_value_get_text)}, | |
38 {"secret_item_get_attributes", | 39 {"secret_item_get_attributes", |
39 reinterpret_cast<void**>(&secret_item_get_attributes)}, | 40 reinterpret_cast<void**>(&secret_item_get_attributes)}, |
40 {"secret_item_load_secret_sync", | 41 {"secret_item_load_secret_sync", |
41 reinterpret_cast<void**>(&secret_item_load_secret_sync)}, | 42 reinterpret_cast<void**>(&secret_item_load_secret_sync)}, |
42 {"secret_value_unref", reinterpret_cast<void**>(&secret_value_unref)}}; | 43 {"secret_password_clear_sync", |
44 reinterpret_cast<void**>(&secret_password_clear_sync)}, | |
45 {"secret_password_store_sync", | |
46 reinterpret_cast<void**>(&secret_password_store_sync)}, | |
47 {"secret_service_lookup_sync", | |
48 reinterpret_cast<void**>(&secret_service_lookup_sync)}, | |
49 {"secret_service_search_sync", | |
50 reinterpret_cast<void**>(&secret_service_search_sync)}, | |
51 {"secret_value_get_text", reinterpret_cast<void**>(&secret_value_get_text)}, | |
52 {"secret_value_unref", reinterpret_cast<void**>(&secret_value_unref)}, | |
53 }; | |
43 | 54 |
44 // static | 55 // static |
45 bool LibsecretLoader::EnsureLibsecretLoaded() { | 56 bool LibsecretLoader::EnsureLibsecretLoaded() { |
46 return LoadLibsecret() && LibsecretIsAvailable(); | 57 return LoadLibsecret() && LibsecretIsAvailable(); |
47 } | 58 } |
48 | 59 |
49 // static | 60 // static |
50 bool LibsecretLoader::LoadLibsecret() { | 61 bool LibsecretLoader::LoadLibsecret() { |
51 if (libsecret_loaded_) | 62 if (libsecret_loaded_) |
52 return true; | 63 return true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 &error); | 111 &error); |
101 bool success = (error == nullptr); | 112 bool success = (error == nullptr); |
102 if (error) | 113 if (error) |
103 g_error_free(error); | 114 g_error_free(error); |
104 if (found) | 115 if (found) |
105 g_list_free(found); | 116 g_list_free(found); |
106 | 117 |
107 return success; | 118 return success; |
108 } | 119 } |
109 | 120 |
121 // | |
122 // LibsecretAttributesBuilder | |
123 // | |
124 | |
110 LibsecretAttributesBuilder::LibsecretAttributesBuilder() { | 125 LibsecretAttributesBuilder::LibsecretAttributesBuilder() { |
111 attrs_ = g_hash_table_new_full(g_str_hash, g_str_equal, | 126 attrs_ = g_hash_table_new_full(g_str_hash, g_str_equal, |
112 nullptr, // no deleter for keys | 127 nullptr, // no deleter for keys |
113 nullptr); // no deleter for values | 128 nullptr); // no deleter for values |
114 } | 129 } |
115 | 130 |
116 LibsecretAttributesBuilder::~LibsecretAttributesBuilder() { | 131 LibsecretAttributesBuilder::~LibsecretAttributesBuilder() { |
117 g_hash_table_destroy(attrs_); | 132 g_hash_table_destroy(attrs_); |
118 } | 133 } |
119 | 134 |
120 void LibsecretAttributesBuilder::Append(const std::string& name, | 135 void LibsecretAttributesBuilder::Append(const std::string& name, |
121 const std::string& value) { | 136 const std::string& value) { |
122 name_values_.push_back(name); | 137 name_values_.push_back(name); |
123 gpointer name_str = | 138 gpointer name_str = |
124 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 139 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
125 name_values_.push_back(value); | 140 name_values_.push_back(value); |
126 gpointer value_str = | 141 gpointer value_str = |
127 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 142 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
128 g_hash_table_insert(attrs_, name_str, value_str); | 143 g_hash_table_insert(attrs_, name_str, value_str); |
129 } | 144 } |
130 | 145 |
131 void LibsecretAttributesBuilder::Append(const std::string& name, | 146 void LibsecretAttributesBuilder::Append(const std::string& name, |
132 int64_t value) { | 147 int64_t value) { |
133 Append(name, base::Int64ToString(value)); | 148 Append(name, base::Int64ToString(value)); |
134 } | 149 } |
OLD | NEW |