Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1089)

Side by Side Diff: chrome/browser/password_manager/native_backend_kwallet_x.cc

Issue 2806002: Linux: refactor GNOME Keyring and KWallet integration to allow migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/password_store_kwallet.h" 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/md5.h"
11 #include "base/pickle.h" 10 #include "base/pickle.h"
12 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
13 #include "base/string_util.h" 12 #include "base/string_util.h"
14 #include "base/task.h" 13 #include "chrome/browser/chrome_thread.h"
15 14
16 using std::string; 15 using std::string;
17 using std::vector; 16 using std::vector;
18 using webkit_glue::PasswordForm; 17 using webkit_glue::PasswordForm;
19 18
20 // We could localize these strings, but then changing your locale would cause 19 // We could localize these strings, but then changing your locale would cause
21 // you to lose access to all your stored passwords. Maybe best not to do that. 20 // you to lose access to all your stored passwords. Maybe best not to do that.
22 const char* PasswordStoreKWallet::kAppId = "Chrome"; 21 const char* NativeBackendKWallet::kAppId = "Chrome";
23 const char* PasswordStoreKWallet::kKWalletFolder = "Chrome Form Data"; 22 const char* NativeBackendKWallet::kKWalletFolder = "Chrome Form Data";
24 23
25 const char* PasswordStoreKWallet::kKWalletServiceName = "org.kde.kwalletd"; 24 const char* NativeBackendKWallet::kKWalletServiceName = "org.kde.kwalletd";
26 const char* PasswordStoreKWallet::kKWalletPath = "/modules/kwalletd"; 25 const char* NativeBackendKWallet::kKWalletPath = "/modules/kwalletd";
27 const char* PasswordStoreKWallet::kKWalletInterface = "org.kde.KWallet"; 26 const char* NativeBackendKWallet::kKWalletInterface = "org.kde.KWallet";
28 const char* PasswordStoreKWallet::kKLauncherServiceName = "org.kde.klauncher"; 27 const char* NativeBackendKWallet::kKLauncherServiceName = "org.kde.klauncher";
29 const char* PasswordStoreKWallet::kKLauncherPath = "/KLauncher"; 28 const char* NativeBackendKWallet::kKLauncherPath = "/KLauncher";
30 const char* PasswordStoreKWallet::kKLauncherInterface = "org.kde.KLauncher"; 29 const char* NativeBackendKWallet::kKLauncherInterface = "org.kde.KLauncher";
31 30
32 PasswordStoreKWallet::PasswordStoreKWallet(LoginDatabase* login_db, 31 NativeBackendKWallet::NativeBackendKWallet()
33 Profile* profile,
34 WebDataService* web_data_service)
35 : error_(NULL), 32 : error_(NULL),
36 connection_(NULL), 33 connection_(NULL),
37 proxy_(NULL) { 34 proxy_(NULL) {
38 } 35 }
39 36
40 PasswordStoreKWallet::~PasswordStoreKWallet() { 37 NativeBackendKWallet::~NativeBackendKWallet() {
41 if (proxy_) { 38 if (proxy_)
42 g_object_unref(proxy_); 39 g_object_unref(proxy_);
43 }
44 } 40 }
45 41
46 bool PasswordStoreKWallet::Init() { 42 bool NativeBackendKWallet::Init() {
47 // Initialize threading in dbus-glib - it should be fine for 43 // Initialize threading in dbus-glib - it should be fine for
48 // dbus_g_thread_init to be called multiple times. 44 // dbus_g_thread_init to be called multiple times.
49 if (!g_thread_supported()) 45 if (!g_thread_supported())
50 g_thread_init(NULL); 46 g_thread_init(NULL);
51 dbus_g_thread_init(); 47 dbus_g_thread_init();
52 48
53 // Get a connection to the session bus. 49 // Get a connection to the session bus.
54 connection_ = dbus_g_bus_get(DBUS_BUS_SESSION, &error_); 50 connection_ = dbus_g_bus_get(DBUS_BUS_SESSION, &error_);
55 if (CheckError()) 51 if (CheckError())
56 return false; 52 return false;
57 53
58 if (!InitWallet()) { 54 if (!InitWallet()) {
59 // kwalletd may not be running. Try to start it and try again. 55 // kwalletd may not be running. Try to start it and try again.
60 if (!StartKWalletd() || !InitWallet()) 56 if (!StartKWalletd() || !InitWallet())
61 return false; 57 return false;
62 } 58 }
63 59
64 return true; 60 return true;
65 } 61 }
66 62
67 bool PasswordStoreKWallet::StartKWalletd() { 63 bool NativeBackendKWallet::StartKWalletd() {
68 // Sadly kwalletd doesn't use DBUS activation, so we have to make a call to 64 // Sadly kwalletd doesn't use DBUS activation, so we have to make a call to
69 // klauncher to start it. 65 // klauncher to start it.
70 DBusGProxy* klauncher_proxy = 66 DBusGProxy* klauncher_proxy =
71 dbus_g_proxy_new_for_name(connection_, kKLauncherServiceName, 67 dbus_g_proxy_new_for_name(connection_, kKLauncherServiceName,
72 kKLauncherPath, kKLauncherInterface); 68 kKLauncherPath, kKLauncherInterface);
73 69
74 char* empty_string_list = NULL; 70 char* empty_string_list = NULL;
75 int ret = 1; 71 int ret = 1;
76 char* error = NULL; 72 char* error = NULL;
77 dbus_g_proxy_call(klauncher_proxy, "start_service_by_desktop_name", &error_, 73 dbus_g_proxy_call(klauncher_proxy, "start_service_by_desktop_name", &error_,
(...skipping 15 matching lines...) Expand all
93 } 89 }
94 90
95 g_free(error); 91 g_free(error);
96 g_object_unref(klauncher_proxy); 92 g_object_unref(klauncher_proxy);
97 93
98 if (CheckError() || ret != 0) 94 if (CheckError() || ret != 0)
99 return false; 95 return false;
100 return true; 96 return true;
101 } 97 }
102 98
103 bool PasswordStoreKWallet::InitWallet() { 99 bool NativeBackendKWallet::InitWallet() {
104 // Make a proxy to KWallet. 100 // Make a proxy to KWallet.
105 proxy_ = dbus_g_proxy_new_for_name(connection_, kKWalletServiceName, 101 proxy_ = dbus_g_proxy_new_for_name(connection_, kKWalletServiceName,
106 kKWalletPath, kKWalletInterface); 102 kKWalletPath, kKWalletInterface);
107 103
108 // Check KWallet is enabled. 104 // Check KWallet is enabled.
109 gboolean is_enabled = false; 105 gboolean is_enabled = false;
110 dbus_g_proxy_call(proxy_, "isEnabled", &error_, 106 dbus_g_proxy_call(proxy_, "isEnabled", &error_,
111 G_TYPE_INVALID, 107 G_TYPE_INVALID,
112 G_TYPE_BOOLEAN, &is_enabled, 108 G_TYPE_BOOLEAN, &is_enabled,
113 G_TYPE_INVALID); 109 G_TYPE_INVALID);
114 if (CheckError() || !is_enabled) 110 if (CheckError() || !is_enabled)
115 return false; 111 return false;
116 112
117 // Get the wallet name. 113 // Get the wallet name.
118 char* wallet_name = NULL; 114 char* wallet_name = NULL;
119 dbus_g_proxy_call(proxy_, "networkWallet", &error_, 115 dbus_g_proxy_call(proxy_, "networkWallet", &error_,
120 G_TYPE_INVALID, 116 G_TYPE_INVALID,
121 G_TYPE_STRING, &wallet_name, 117 G_TYPE_STRING, &wallet_name,
122 G_TYPE_INVALID); 118 G_TYPE_INVALID);
123 if (CheckError() || !wallet_name) 119 if (CheckError() || !wallet_name)
124 return false; 120 return false;
125 121
126 wallet_name_.assign(wallet_name); 122 wallet_name_.assign(wallet_name);
127 g_free(wallet_name); 123 g_free(wallet_name);
128 124
129 return true; 125 return true;
130 } 126 }
131 127
132 void PasswordStoreKWallet::AddLoginImpl(const PasswordForm& form) { 128 bool NativeBackendKWallet::AddLogin(const PasswordForm& form) {
133 AutoLock l(kwallet_lock_);
134 int wallet_handle = WalletHandle(); 129 int wallet_handle = WalletHandle();
135 if (wallet_handle == kInvalidKWalletHandle) 130 if (wallet_handle == kInvalidKWalletHandle)
136 return; 131 return false;
137 132
138 PasswordFormList forms; 133 PasswordFormList forms;
139 GetLoginsList(&forms, form.signon_realm, wallet_handle); 134 GetLoginsList(&forms, form.signon_realm, wallet_handle);
140 135
141 forms.push_back(new PasswordForm(form)); 136 forms.push_back(new PasswordForm(form));
142 SetLoginsList(forms, form.signon_realm, wallet_handle); 137 bool ok = SetLoginsList(forms, form.signon_realm, wallet_handle);
143 138
144 STLDeleteElements(&forms); 139 STLDeleteElements(&forms);
140 return ok;
145 } 141 }
146 142
147 void PasswordStoreKWallet::UpdateLoginImpl(const PasswordForm& form) { 143 bool NativeBackendKWallet::UpdateLogin(const PasswordForm& form) {
148 AutoLock l(kwallet_lock_);
149 int wallet_handle = WalletHandle(); 144 int wallet_handle = WalletHandle();
150 if (wallet_handle == kInvalidKWalletHandle) 145 if (wallet_handle == kInvalidKWalletHandle)
151 return; 146 return false;
152 147
153 PasswordFormList forms; 148 PasswordFormList forms;
154 GetLoginsList(&forms, form.signon_realm, wallet_handle); 149 GetLoginsList(&forms, form.signon_realm, wallet_handle);
155 150
156 for (size_t i = 0; i < forms.size(); ++i) { 151 for (size_t i = 0; i < forms.size(); ++i) {
157 if (CompareForms(form, *forms[i], true)) 152 if (CompareForms(form, *forms[i], true))
158 *forms[i] = form; 153 *forms[i] = form;
159 } 154 }
160 155
161 SetLoginsList(forms, form.signon_realm, wallet_handle); 156 bool ok = SetLoginsList(forms, form.signon_realm, wallet_handle);
162 157
163 STLDeleteElements(&forms); 158 STLDeleteElements(&forms);
159 return ok;
164 } 160 }
165 161
166 void PasswordStoreKWallet::RemoveLoginImpl(const PasswordForm& form) { 162 bool NativeBackendKWallet::RemoveLogin(const PasswordForm& form) {
167 AutoLock l(kwallet_lock_);
168 int wallet_handle = WalletHandle(); 163 int wallet_handle = WalletHandle();
169 if (wallet_handle == kInvalidKWalletHandle) 164 if (wallet_handle == kInvalidKWalletHandle)
170 return; 165 return false;
171 166
172 PasswordFormList all_forms; 167 PasswordFormList all_forms;
173 GetLoginsList(&all_forms, form.signon_realm, wallet_handle); 168 GetLoginsList(&all_forms, form.signon_realm, wallet_handle);
174 169
175 PasswordFormList kept_forms; 170 PasswordFormList kept_forms;
176 kept_forms.reserve(all_forms.size()); 171 kept_forms.reserve(all_forms.size());
177 for (size_t i = 0; i < all_forms.size(); ++i) { 172 for (size_t i = 0; i < all_forms.size(); ++i) {
178 if (CompareForms(form, *all_forms[i], false)) 173 if (CompareForms(form, *all_forms[i], false))
179 delete all_forms[i]; 174 delete all_forms[i];
180 else 175 else
181 kept_forms.push_back(all_forms[i]); 176 kept_forms.push_back(all_forms[i]);
182 } 177 }
183 178
184 // Update the entry in the wallet. 179 // Update the entry in the wallet, possibly deleting it.
185 SetLoginsList(kept_forms, form.signon_realm, wallet_handle); 180 bool ok = SetLoginsList(kept_forms, form.signon_realm, wallet_handle);
181
186 STLDeleteElements(&kept_forms); 182 STLDeleteElements(&kept_forms);
183 return ok;
187 } 184 }
188 185
189 void PasswordStoreKWallet::RemoveLoginsCreatedBetweenImpl( 186 bool NativeBackendKWallet::RemoveLoginsCreatedBetween(
190 const base::Time& delete_begin, 187 const base::Time& delete_begin,
191 const base::Time& delete_end) { 188 const base::Time& delete_end) {
192 AutoLock l(kwallet_lock_);
193 int wallet_handle = WalletHandle(); 189 int wallet_handle = WalletHandle();
194 if (wallet_handle == kInvalidKWalletHandle) 190 if (wallet_handle == kInvalidKWalletHandle)
195 return; 191 return false;
196 192
197 // We could probably also use readEntryList here. 193 // We could probably also use readEntryList here.
198 char** realm_list = NULL; 194 char** realm_list = NULL;
199 dbus_g_proxy_call(proxy_, "entryList", &error_, 195 dbus_g_proxy_call(proxy_, "entryList", &error_,
200 G_TYPE_INT, wallet_handle, // handle 196 G_TYPE_INT, wallet_handle, // handle
201 G_TYPE_STRING, kKWalletFolder, // folder 197 G_TYPE_STRING, kKWalletFolder, // folder
202 G_TYPE_STRING, kAppId, // appid 198 G_TYPE_STRING, kAppId, // appid
203 G_TYPE_INVALID, 199 G_TYPE_INVALID,
204 G_TYPE_STRV, &realm_list, 200 G_TYPE_STRV, &realm_list,
205 G_TYPE_INVALID); 201 G_TYPE_INVALID);
206 if (CheckError()) 202 if (CheckError())
207 return; 203 return false;
208 204
205 bool ok = true;
209 for (char** realm = realm_list; *realm; ++realm) { 206 for (char** realm = realm_list; *realm; ++realm) {
210 GArray* byte_array = NULL; 207 GArray* byte_array = NULL;
211 dbus_g_proxy_call(proxy_, "readEntry", &error_, 208 dbus_g_proxy_call(proxy_, "readEntry", &error_,
212 G_TYPE_INT, wallet_handle, // handle 209 G_TYPE_INT, wallet_handle, // handle
213 G_TYPE_STRING, kKWalletFolder, // folder 210 G_TYPE_STRING, kKWalletFolder, // folder
214 G_TYPE_STRING, *realm, // key 211 G_TYPE_STRING, *realm, // key
215 G_TYPE_STRING, kAppId, // appid 212 G_TYPE_STRING, kAppId, // appid
216 G_TYPE_INVALID, 213 G_TYPE_INVALID,
217 DBUS_TYPE_G_UCHAR_ARRAY, &byte_array, 214 DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
218 G_TYPE_INVALID); 215 G_TYPE_INVALID);
(...skipping 11 matching lines...) Expand all
230 kept_forms.reserve(all_forms.size()); 227 kept_forms.reserve(all_forms.size());
231 for (size_t i = 0; i < all_forms.size(); ++i) { 228 for (size_t i = 0; i < all_forms.size(); ++i) {
232 if (delete_begin <= all_forms[i]->date_created && 229 if (delete_begin <= all_forms[i]->date_created &&
233 (delete_end.is_null() || all_forms[i]->date_created < delete_end)) { 230 (delete_end.is_null() || all_forms[i]->date_created < delete_end)) {
234 delete all_forms[i]; 231 delete all_forms[i];
235 } else { 232 } else {
236 kept_forms.push_back(all_forms[i]); 233 kept_forms.push_back(all_forms[i]);
237 } 234 }
238 } 235 }
239 236
240 SetLoginsList(kept_forms, signon_realm, wallet_handle); 237 if (!SetLoginsList(kept_forms, signon_realm, wallet_handle))
238 ok = false;
241 STLDeleteElements(&kept_forms); 239 STLDeleteElements(&kept_forms);
242 } 240 }
243 g_strfreev(realm_list); 241 g_strfreev(realm_list);
242 return ok;
244 } 243 }
245 244
246 void PasswordStoreKWallet::GetLoginsImpl(GetLoginsRequest* request, 245 bool NativeBackendKWallet::GetLogins(const PasswordForm& form,
247 const PasswordForm& form) { 246 PasswordFormList* forms) {
248 PasswordFormList forms;
249
250 AutoLock l(kwallet_lock_);
251 int wallet_handle = WalletHandle(); 247 int wallet_handle = WalletHandle();
252 if (wallet_handle != kInvalidKWalletHandle) 248 if (wallet_handle == kInvalidKWalletHandle)
253 GetLoginsList(&forms, form.signon_realm, wallet_handle); 249 return false;
254 250 return GetLoginsList(forms, form.signon_realm, wallet_handle);
255 NotifyConsumer(request, forms);
256 } 251 }
257 252
258 void PasswordStoreKWallet::GetAutofillableLoginsImpl( 253 bool NativeBackendKWallet::GetLoginsCreatedBetween(const base::Time& get_begin,
259 GetLoginsRequest* request) { 254 const base::Time& get_end,
260 std::vector<PasswordForm*> forms; 255 PasswordFormList* forms) {
261 FillAutofillableLogins(&forms); 256 int wallet_handle = WalletHandle();
262 NotifyConsumer(request, forms); 257 if (wallet_handle == kInvalidKWalletHandle)
258 return false;
259 return GetLoginsList(forms, get_begin, get_end, wallet_handle);
263 } 260 }
264 261
265 void PasswordStoreKWallet::GetBlacklistLoginsImpl( 262 bool NativeBackendKWallet::GetAutofillableLogins(PasswordFormList* forms) {
266 GetLoginsRequest* request) { 263 int wallet_handle = WalletHandle();
267 std::vector<PasswordForm*> forms; 264 if (wallet_handle == kInvalidKWalletHandle)
268 FillBlacklistLogins(&forms); 265 return false;
269 NotifyConsumer(request, forms); 266 return GetLoginsList(forms, true, wallet_handle);
270 } 267 }
271 268
272 bool PasswordStoreKWallet::FillAutofillableLogins( 269 bool NativeBackendKWallet::GetBlacklistLogins(PasswordFormList* forms) {
273 std::vector<PasswordForm*>* forms) { 270 int wallet_handle = WalletHandle();
274 return FillSomeLogins(true, forms); 271 if (wallet_handle == kInvalidKWalletHandle)
272 return false;
273 return GetLoginsList(forms, false, wallet_handle);
275 } 274 }
276 275
277 bool PasswordStoreKWallet::FillBlacklistLogins( 276 bool NativeBackendKWallet::GetLoginsList(PasswordFormList* forms,
278 std::vector<PasswordForm*>* forms) {
279 return FillSomeLogins(false, forms);
280 }
281
282 void PasswordStoreKWallet::GetLoginsList(PasswordFormList* forms,
283 const string& signon_realm, 277 const string& signon_realm,
284 int wallet_handle) { 278 int wallet_handle) {
285 // Is there an entry in the wallet? 279 // Is there an entry in the wallet?
286 gboolean has_entry = false; 280 gboolean has_entry = false;
287 dbus_g_proxy_call(proxy_, "hasEntry", &error_, 281 dbus_g_proxy_call(proxy_, "hasEntry", &error_,
288 G_TYPE_INT, wallet_handle, // handle 282 G_TYPE_INT, wallet_handle, // handle
289 G_TYPE_STRING, kKWalletFolder, // folder 283 G_TYPE_STRING, kKWalletFolder, // folder
290 G_TYPE_STRING, signon_realm.c_str(), // key 284 G_TYPE_STRING, signon_realm.c_str(), // key
291 G_TYPE_STRING, kAppId, // appid 285 G_TYPE_STRING, kAppId, // appid
292 G_TYPE_INVALID, 286 G_TYPE_INVALID,
293 G_TYPE_BOOLEAN, &has_entry, 287 G_TYPE_BOOLEAN, &has_entry,
294 G_TYPE_INVALID); 288 G_TYPE_INVALID);
295 289
296 if (CheckError() || !has_entry) 290 if (CheckError() || !has_entry)
297 return; 291 return false;
298 292
299 GArray* byte_array = NULL; 293 GArray* byte_array = NULL;
300 dbus_g_proxy_call(proxy_, "readEntry", &error_, 294 dbus_g_proxy_call(proxy_, "readEntry", &error_,
301 G_TYPE_INT, wallet_handle, // handle 295 G_TYPE_INT, wallet_handle, // handle
302 G_TYPE_STRING, kKWalletFolder, // folder 296 G_TYPE_STRING, kKWalletFolder, // folder
303 G_TYPE_STRING, signon_realm.c_str(), // key 297 G_TYPE_STRING, signon_realm.c_str(), // key
304 G_TYPE_STRING, kAppId, // appid 298 G_TYPE_STRING, kAppId, // appid
305 G_TYPE_INVALID, 299 G_TYPE_INVALID,
306 DBUS_TYPE_G_UCHAR_ARRAY, &byte_array, 300 DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
307 G_TYPE_INVALID); 301 G_TYPE_INVALID);
308 302
309 if (CheckError() || !byte_array || !byte_array->len) 303 if (CheckError() || !byte_array || !byte_array->len)
310 return; 304 return false;
311 305
312 Pickle pickle(byte_array->data, byte_array->len); 306 Pickle pickle(byte_array->data, byte_array->len);
313 DeserializeValue(signon_realm, pickle, forms); 307 DeserializeValue(signon_realm, pickle, forms);
314 g_array_free(byte_array, true); 308 g_array_free(byte_array, true);
309
310 return true;
315 } 311 }
316 312
317 void PasswordStoreKWallet::SetLoginsList(const PasswordFormList& forms, 313 bool NativeBackendKWallet::GetLoginsList(PasswordFormList* forms,
314 bool autofillable,
315 int wallet_handle) {
316 PasswordFormList all_forms;
317 if (!GetAllLogins(&all_forms, wallet_handle))
318 return false;
319
320 // We have to read all the entries, and then filter them here.
321 forms->reserve(forms->size() + all_forms.size());
322 for (size_t i = 0; i < all_forms.size(); ++i) {
323 if (all_forms[i]->blacklisted_by_user == !autofillable)
324 forms->push_back(all_forms[i]);
325 else
326 delete all_forms[i];
327 }
328
329 return true;
330 }
331
332 bool NativeBackendKWallet::GetLoginsList(PasswordFormList* forms,
333 const base::Time& begin,
334 const base::Time& end,
335 int wallet_handle) {
336 PasswordFormList all_forms;
337 if (!GetAllLogins(&all_forms, wallet_handle))
338 return false;
339
340 // We have to read all the entries, and then filter them here.
341 forms->reserve(forms->size() + all_forms.size());
342 for (size_t i = 0; i < all_forms.size(); ++i) {
343 if (begin <= all_forms[i]->date_created &&
344 (end.is_null() || all_forms[i]->date_created < end)) {
345 forms->push_back(all_forms[i]);
346 } else {
347 delete all_forms[i];
348 }
349 }
350
351 return true;
352 }
353
354 bool NativeBackendKWallet::GetAllLogins(PasswordFormList* forms,
355 int wallet_handle) {
356 // We could probably also use readEntryList here.
357 char** realm_list = NULL;
358 dbus_g_proxy_call(proxy_, "entryList", &error_,
359 G_TYPE_INT, wallet_handle, // handle
360 G_TYPE_STRING, kKWalletFolder, // folder
361 G_TYPE_STRING, kAppId, // appid
362 G_TYPE_INVALID,
363 G_TYPE_STRV, &realm_list,
364 G_TYPE_INVALID);
365 if (CheckError())
366 return false;
367
368 for (char** realm = realm_list; *realm; ++realm) {
369 GArray* byte_array = NULL;
370 dbus_g_proxy_call(proxy_, "readEntry", &error_,
371 G_TYPE_INT, wallet_handle, // handle
372 G_TYPE_STRING, kKWalletFolder, // folder
373 G_TYPE_STRING, *realm, // key
374 G_TYPE_STRING, kAppId, // appid
375 G_TYPE_INVALID,
376 DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
377 G_TYPE_INVALID);
378
379 if (CheckError() || !byte_array || !byte_array->len)
380 continue;
381
382 Pickle pickle(byte_array->data, byte_array->len);
383 DeserializeValue(*realm, pickle, forms);
384 g_array_free(byte_array, true);
385 }
386 g_strfreev(realm_list);
387 return true;
388 }
389
390 bool NativeBackendKWallet::SetLoginsList(const PasswordFormList& forms,
318 const string& signon_realm, 391 const string& signon_realm,
319 int wallet_handle) { 392 int wallet_handle) {
320 if (forms.empty()) { 393 if (forms.empty()) {
321 // No items left? Remove the entry from the wallet. 394 // No items left? Remove the entry from the wallet.
322 int ret = 0; 395 int ret = 0;
323 dbus_g_proxy_call(proxy_, "removeEntry", &error_, 396 dbus_g_proxy_call(proxy_, "removeEntry", &error_,
324 G_TYPE_INT, wallet_handle, // handle 397 G_TYPE_INT, wallet_handle, // handle
325 G_TYPE_STRING, kKWalletFolder, // folder 398 G_TYPE_STRING, kKWalletFolder, // folder
326 G_TYPE_STRING, signon_realm.c_str(), // key 399 G_TYPE_STRING, signon_realm.c_str(), // key
327 G_TYPE_STRING, kAppId, // appid 400 G_TYPE_STRING, kAppId, // appid
328 G_TYPE_INVALID, 401 G_TYPE_INVALID,
329 G_TYPE_INT, &ret, 402 G_TYPE_INT, &ret,
330 G_TYPE_INVALID); 403 G_TYPE_INVALID);
331 CheckError(); 404 CheckError();
332 if (ret != 0) 405 if (ret != 0)
333 LOG(ERROR) << "Bad return code " << ret << " from kwallet removeEntry"; 406 LOG(ERROR) << "Bad return code " << ret << " from kwallet removeEntry";
334 return; 407 return ret == 0;
335 } 408 }
336 409
337 Pickle value; 410 Pickle value;
338 SerializeValue(forms, &value); 411 SerializeValue(forms, &value);
339 412
340 // Convert the pickled bytes to a GByteArray. 413 // Convert the pickled bytes to a GByteArray.
341 GArray* byte_array = g_array_sized_new(false, false, sizeof(char), 414 GArray* byte_array = g_array_sized_new(false, false, sizeof(char),
342 value.size()); 415 value.size());
343 g_array_append_vals(byte_array, value.data(), value.size()); 416 g_array_append_vals(byte_array, value.data(), value.size());
344 417
345 // Make the call. 418 // Make the call.
346 int ret = 0; 419 int ret = 0;
347 dbus_g_proxy_call(proxy_, "writeEntry", &error_, 420 dbus_g_proxy_call(proxy_, "writeEntry", &error_,
348 G_TYPE_INT, wallet_handle, // handle 421 G_TYPE_INT, wallet_handle, // handle
349 G_TYPE_STRING, kKWalletFolder, // folder 422 G_TYPE_STRING, kKWalletFolder, // folder
350 G_TYPE_STRING, signon_realm.c_str(), // key 423 G_TYPE_STRING, signon_realm.c_str(), // key
351 DBUS_TYPE_G_UCHAR_ARRAY, byte_array, // value 424 DBUS_TYPE_G_UCHAR_ARRAY, byte_array, // value
352 G_TYPE_STRING, kAppId, // appid 425 G_TYPE_STRING, kAppId, // appid
353 G_TYPE_INVALID, 426 G_TYPE_INVALID,
354 G_TYPE_INT, &ret, 427 G_TYPE_INT, &ret,
355 G_TYPE_INVALID); 428 G_TYPE_INVALID);
356 g_array_free(byte_array, true); 429 g_array_free(byte_array, true);
357 430
358 CheckError(); 431 CheckError();
359 if (ret != 0) 432 if (ret != 0)
360 LOG(ERROR) << "Bad return code " << ret << " from kwallet writeEntry"; 433 LOG(ERROR) << "Bad return code " << ret << " from kwallet writeEntry";
434 return ret == 0;
361 } 435 }
362 436
363 bool PasswordStoreKWallet::FillSomeLogins(bool autofillable, 437 bool NativeBackendKWallet::CompareForms(const PasswordForm& a,
364 PasswordFormList* forms) {
365 AutoLock l(kwallet_lock_);
366 int wallet_handle = WalletHandle();
367 if (wallet_handle == kInvalidKWalletHandle)
368 return false;
369
370 // We could probably also use readEntryList here.
371 char** realm_list = NULL;
372 dbus_g_proxy_call(proxy_, "entryList", &error_,
373 G_TYPE_INT, wallet_handle, // handle
374 G_TYPE_STRING, kKWalletFolder, // folder
375 G_TYPE_STRING, kAppId, // appid
376 G_TYPE_INVALID,
377 G_TYPE_STRV, &realm_list,
378 G_TYPE_INVALID);
379 if (CheckError())
380 return false;
381
382 PasswordFormList all_forms;
383 for (char** realm = realm_list; *realm; ++realm) {
384 GArray* byte_array = NULL;
385 dbus_g_proxy_call(proxy_, "readEntry", &error_,
386 G_TYPE_INT, wallet_handle, // handle
387 G_TYPE_STRING, kKWalletFolder, // folder
388 G_TYPE_STRING, *realm, // key
389 G_TYPE_STRING, kAppId, // appid
390 G_TYPE_INVALID,
391 DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
392 G_TYPE_INVALID);
393
394 if (CheckError() || !byte_array || !byte_array->len)
395 continue;
396
397 Pickle pickle(byte_array->data, byte_array->len);
398 DeserializeValue(*realm, pickle, &all_forms);
399 g_array_free(byte_array, true);
400 }
401 g_strfreev(realm_list);
402
403 // We have to read all the entries, and then filter them here.
404 forms->reserve(forms->size() + all_forms.size());
405 for (size_t i = 0; i < all_forms.size(); ++i) {
406 if (all_forms[i]->blacklisted_by_user == !autofillable)
407 forms->push_back(all_forms[i]);
408 else
409 delete all_forms[i];
410 }
411
412 return true;
413 }
414
415 bool PasswordStoreKWallet::CompareForms(const PasswordForm& a,
416 const PasswordForm& b, 438 const PasswordForm& b,
417 bool update_check) { 439 bool update_check) {
418 // An update check doesn't care about the submit element. 440 // An update check doesn't care about the submit element.
419 if (!update_check && a.submit_element != b.submit_element) 441 if (!update_check && a.submit_element != b.submit_element)
420 return false; 442 return false;
421 return a.origin == b.origin && 443 return a.origin == b.origin &&
422 a.password_element == b.password_element && 444 a.password_element == b.password_element &&
423 a.signon_realm == b.signon_realm && 445 a.signon_realm == b.signon_realm &&
424 a.username_element == b.username_element && 446 a.username_element == b.username_element &&
425 a.username_value == b.username_value; 447 a.username_value == b.username_value;
426 } 448 }
427 449
428 void PasswordStoreKWallet::SerializeValue(const PasswordFormList& forms, 450 void NativeBackendKWallet::SerializeValue(const PasswordFormList& forms,
429 Pickle* pickle) { 451 Pickle* pickle) {
430 pickle->WriteInt(kPickleVersion); 452 pickle->WriteInt(kPickleVersion);
431 pickle->WriteSize(forms.size()); 453 pickle->WriteSize(forms.size());
432 for (PasswordFormList::const_iterator it = forms.begin() ; 454 for (PasswordFormList::const_iterator it = forms.begin() ;
433 it != forms.end() ; ++it) { 455 it != forms.end() ; ++it) {
434 const PasswordForm* form = *it; 456 const PasswordForm* form = *it;
435 pickle->WriteInt(form->scheme); 457 pickle->WriteInt(form->scheme);
436 pickle->WriteString(form->origin.spec()); 458 pickle->WriteString(form->origin.spec());
437 pickle->WriteString(form->action.spec()); 459 pickle->WriteString(form->action.spec());
438 pickle->WriteString16(form->username_element); 460 pickle->WriteString16(form->username_element);
439 pickle->WriteString16(form->username_value); 461 pickle->WriteString16(form->username_value);
440 pickle->WriteString16(form->password_element); 462 pickle->WriteString16(form->password_element);
441 pickle->WriteString16(form->password_value); 463 pickle->WriteString16(form->password_value);
442 pickle->WriteString16(form->submit_element); 464 pickle->WriteString16(form->submit_element);
443 pickle->WriteBool(form->ssl_valid); 465 pickle->WriteBool(form->ssl_valid);
444 pickle->WriteBool(form->preferred); 466 pickle->WriteBool(form->preferred);
445 pickle->WriteBool(form->blacklisted_by_user); 467 pickle->WriteBool(form->blacklisted_by_user);
446 pickle->WriteInt64(form->date_created.ToTimeT()); 468 pickle->WriteInt64(form->date_created.ToTimeT());
447 } 469 }
448 } 470 }
449 471
450 void PasswordStoreKWallet::DeserializeValue(const string& signon_realm, 472 void NativeBackendKWallet::DeserializeValue(const string& signon_realm,
451 const Pickle& pickle, 473 const Pickle& pickle,
452 PasswordFormList* forms) { 474 PasswordFormList* forms) {
453 void* iter = NULL; 475 void* iter = NULL;
454 476
455 int version = -1; 477 int version = -1;
456 pickle.ReadInt(&iter, &version); 478 pickle.ReadInt(&iter, &version);
457 if (version != kPickleVersion) { 479 if (version != kPickleVersion) {
458 // This is the only version so far, so anything else is an error. 480 // This is the only version so far, so anything else is an error.
459 return; 481 return;
460 } 482 }
(...skipping 19 matching lines...) Expand all
480 pickle.ReadBool(&iter, &form->ssl_valid); 502 pickle.ReadBool(&iter, &form->ssl_valid);
481 pickle.ReadBool(&iter, &form->preferred); 503 pickle.ReadBool(&iter, &form->preferred);
482 pickle.ReadBool(&iter, &form->blacklisted_by_user); 504 pickle.ReadBool(&iter, &form->blacklisted_by_user);
483 int64 date_created = 0; 505 int64 date_created = 0;
484 pickle.ReadInt64(&iter, &date_created); 506 pickle.ReadInt64(&iter, &date_created);
485 form->date_created = base::Time::FromTimeT(date_created); 507 form->date_created = base::Time::FromTimeT(date_created);
486 forms->push_back(form); 508 forms->push_back(form);
487 } 509 }
488 } 510 }
489 511
490 void PasswordStoreKWallet::ReadGURL(const Pickle& pickle, void** iter, 512 void NativeBackendKWallet::ReadGURL(const Pickle& pickle, void** iter,
491 GURL* url) { 513 GURL* url) {
492 string url_string; 514 string url_string;
493 pickle.ReadString(iter, &url_string); 515 pickle.ReadString(iter, &url_string);
494 *url = GURL(url_string); 516 *url = GURL(url_string);
495 } 517 }
496 518
497 bool PasswordStoreKWallet::CheckError() { 519 bool NativeBackendKWallet::CheckError() {
498 if (error_) { 520 if (error_) {
499 LOG(ERROR) << "Failed to complete KWallet call: " << error_->message; 521 LOG(ERROR) << "Failed to complete KWallet call: " << error_->message;
500 g_error_free(error_); 522 g_error_free(error_);
501 error_ = NULL; 523 error_ = NULL;
502 return true; 524 return true;
503 } 525 }
504 return false; 526 return false;
505 } 527 }
506 528
507 int PasswordStoreKWallet::WalletHandle() { 529 int NativeBackendKWallet::WalletHandle() {
530 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
508 // Open the wallet. 531 // Open the wallet.
509 int handle = kInvalidKWalletHandle; 532 int handle = kInvalidKWalletHandle;
510 dbus_g_proxy_call(proxy_, "open", &error_, 533 dbus_g_proxy_call(proxy_, "open", &error_,
511 G_TYPE_STRING, wallet_name_.c_str(), // wallet 534 G_TYPE_STRING, wallet_name_.c_str(), // wallet
512 G_TYPE_INT64, 0LL, // wid 535 G_TYPE_INT64, 0LL, // wid
513 G_TYPE_STRING, kAppId, // appid 536 G_TYPE_STRING, kAppId, // appid
514 G_TYPE_INVALID, 537 G_TYPE_INVALID,
515 G_TYPE_INT, &handle, 538 G_TYPE_INT, &handle,
516 G_TYPE_INVALID); 539 G_TYPE_INVALID);
517 if (CheckError() || handle == kInvalidKWalletHandle) 540 if (CheckError() || handle == kInvalidKWalletHandle)
(...skipping 20 matching lines...) Expand all
538 G_TYPE_STRING, kAppId, // appid 561 G_TYPE_STRING, kAppId, // appid
539 G_TYPE_INVALID, 562 G_TYPE_INVALID,
540 G_TYPE_BOOLEAN, &success, 563 G_TYPE_BOOLEAN, &success,
541 G_TYPE_INVALID); 564 G_TYPE_INVALID);
542 if (CheckError() || !success) 565 if (CheckError() || !success)
543 return kInvalidKWalletHandle; 566 return kInvalidKWalletHandle;
544 } 567 }
545 568
546 return handle; 569 return handle;
547 } 570 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/native_backend_kwallet_x.h ('k') | chrome/browser/password_manager/password_store_default.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698