OLD | NEW |
---|---|
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "chrome/browser/password_manager/native_backend_libsecret.h" | 5 #include "chrome/browser/password_manager/native_backend_libsecret.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 | 17 |
18 using autofill::PasswordForm; | 18 using autofill::PasswordForm; |
19 using base::UTF8ToUTF16; | 19 using base::UTF8ToUTF16; |
20 using base::UTF16ToUTF8; | 20 using base::UTF16ToUTF8; |
21 | 21 |
22 namespace { | |
23 char empty_string[] = ""; | |
vabr (Chromium)
2015/01/29 14:23:13
const char kEmptyString[] = "";
dvadym
2015/01/29 14:27:57
Done.
| |
24 } | |
25 | |
22 typeof(&::secret_password_store_sync) | 26 typeof(&::secret_password_store_sync) |
23 LibsecretLoader::secret_password_store_sync; | 27 LibsecretLoader::secret_password_store_sync; |
24 typeof(&::secret_service_search_sync) | 28 typeof(&::secret_service_search_sync) |
25 LibsecretLoader::secret_service_search_sync; | 29 LibsecretLoader::secret_service_search_sync; |
26 typeof(&::secret_password_clear_sync) | 30 typeof(&::secret_password_clear_sync) |
27 LibsecretLoader::secret_password_clear_sync; | 31 LibsecretLoader::secret_password_clear_sync; |
28 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; | 32 typeof(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; |
29 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; | 33 typeof(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; |
30 typeof(&::secret_item_get_attributes) | 34 typeof(&::secret_item_get_attributes) |
31 LibsecretLoader::secret_item_get_attributes; | 35 LibsecretLoader::secret_item_get_attributes; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 117 {"date_synced", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
114 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 118 {"display_name", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
115 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 119 {"avatar_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
116 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 120 {"federation_url", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
117 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, | 121 {"is_zero_click", SECRET_SCHEMA_ATTRIBUTE_INTEGER}, |
118 // This field is always "chrome-profile_id" so that we can search for it. | 122 // This field is always "chrome-profile_id" so that we can search for it. |
119 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, | 123 {"application", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
120 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; | 124 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; |
121 | 125 |
122 char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) { | 126 char* GetStringFromAttributes(GHashTable* attrs, const char* keyname) { |
123 return static_cast<char*>(g_hash_table_lookup(attrs, keyname)); | 127 gpointer value = g_hash_table_lookup(attrs, keyname); |
128 return value ? static_cast<char*>(value) : empty_string; | |
124 } | 129 } |
125 | 130 |
126 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { | 131 uint32_t GetUintFromAttributes(GHashTable* attrs, const char* keyname) { |
127 char* value = static_cast<char*>(g_hash_table_lookup(attrs, keyname)); | 132 gpointer value = g_hash_table_lookup(attrs, keyname); |
133 if (!value) | |
134 return uint32_t(); | |
128 uint32_t result; | 135 uint32_t result; |
129 bool value_ok = base::StringToUint(value, &result); | 136 bool value_ok = base::StringToUint(static_cast<char*>(value), &result); |
130 DCHECK(value_ok); | 137 DCHECK(value_ok); |
131 return result; | 138 return result; |
132 } | 139 } |
133 | 140 |
134 // Convert the attributes into a new PasswordForm. | 141 // Convert the attributes into a new PasswordForm. |
135 // Note: does *not* get the actual password, as that is not a key attribute! | 142 // Note: does *not* get the actual password, as that is not a key attribute! |
136 // Returns nullptr if the attributes are for the wrong application. | 143 // Returns nullptr if the attributes are for the wrong application. |
137 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) { | 144 scoped_ptr<PasswordForm> FormOutOfAttributes(GHashTable* attrs) { |
138 base::StringPiece app_value = GetStringFromAttributes(attrs, "application"); | 145 base::StringPiece app_value = GetStringFromAttributes(attrs, "application"); |
139 if (!app_value.starts_with(kLibsecretAppString)) | 146 if (!app_value.starts_with(kLibsecretAppString)) |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 return true; | 589 return true; |
583 } | 590 } |
584 | 591 |
585 std::string NativeBackendLibsecret::GetProfileSpecificAppString( | 592 std::string NativeBackendLibsecret::GetProfileSpecificAppString( |
586 LocalProfileId id) { | 593 LocalProfileId id) { |
587 // Originally, the application string was always just "chrome" and used only | 594 // Originally, the application string was always just "chrome" and used only |
588 // so that we had *something* to search for since GNOME Keyring won't search | 595 // so that we had *something* to search for since GNOME Keyring won't search |
589 // for nothing. Now we use it to distinguish passwords for different profiles. | 596 // for nothing. Now we use it to distinguish passwords for different profiles. |
590 return base::StringPrintf("%s-%d", kLibsecretAppString, id); | 597 return base::StringPrintf("%s-%d", kLibsecretAppString, id); |
591 } | 598 } |
OLD | NEW |