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

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

Issue 1383303002: Use kwalletd5 in KDE 5 environments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_kwallet_x.h" 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 21 matching lines...) Expand all
32 // In case the fields in the pickle ever change, version them so we can try to 32 // In case the fields in the pickle ever change, version them so we can try to
33 // read old pickles. (Note: do not eat old pickles past the expiration date.) 33 // read old pickles. (Note: do not eat old pickles past the expiration date.)
34 const int kPickleVersion = 7; 34 const int kPickleVersion = 7;
35 35
36 // We could localize this string, but then changing your locale would cause 36 // We could localize this string, but then changing your locale would cause
37 // you to lose access to all your stored passwords. Maybe best not to do that. 37 // you to lose access to all your stored passwords. Maybe best not to do that.
38 // Name of the folder to store passwords in. 38 // Name of the folder to store passwords in.
39 const char kKWalletFolder[] = "Chrome Form Data"; 39 const char kKWalletFolder[] = "Chrome Form Data";
40 40
41 // DBus service, path, and interface names for klauncher and kwalletd. 41 // DBus service, path, and interface names for klauncher and kwalletd.
42 const char kKWalletDName[] = "kwalletd";
43 const char kKWalletD5Name[] = "kwalletd5";
42 const char kKWalletServiceName[] = "org.kde.kwalletd"; 44 const char kKWalletServiceName[] = "org.kde.kwalletd";
45 const char kKWallet5ServiceName[] = "org.kde.kwalletd5";
43 const char kKWalletPath[] = "/modules/kwalletd"; 46 const char kKWalletPath[] = "/modules/kwalletd";
47 const char kKWallet5Path[] = "/modules/kwalletd5";
44 const char kKWalletInterface[] = "org.kde.KWallet"; 48 const char kKWalletInterface[] = "org.kde.KWallet";
45 const char kKLauncherServiceName[] = "org.kde.klauncher"; 49 const char kKLauncherServiceName[] = "org.kde.klauncher";
46 const char kKLauncherPath[] = "/KLauncher"; 50 const char kKLauncherPath[] = "/KLauncher";
47 const char kKLauncherInterface[] = "org.kde.KLauncher"; 51 const char kKLauncherInterface[] = "org.kde.KLauncher";
48 52
49 // Checks a serialized list of PasswordForms for sanity. Returns true if OK. 53 // Checks a serialized list of PasswordForms for sanity. Returns true if OK.
50 // Note that |realm| is only used for generating a useful warning message. 54 // Note that |realm| is only used for generating a useful warning message.
51 bool CheckSerializedValue(const uint8_t* byte_array, 55 bool CheckSerializedValue(const uint8_t* byte_array,
52 size_t length, 56 size_t length,
53 const std::string& realm) { 57 const std::string& realm) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 second.weak_clear(); 265 second.weak_clear();
262 } 266 }
263 267
264 void UMALogDeserializationStatus(bool success) { 268 void UMALogDeserializationStatus(bool success) {
265 UMA_HISTOGRAM_BOOLEAN("PasswordManager.KWalletDeserializationStatus", 269 UMA_HISTOGRAM_BOOLEAN("PasswordManager.KWalletDeserializationStatus",
266 success); 270 success);
267 } 271 }
268 272
269 } // namespace 273 } // namespace
270 274
271 NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id) 275 NativeBackendKWallet::NativeBackendKWallet(
276 LocalProfileId id, base::nix::DesktopEnvironment desktop_env)
272 : profile_id_(id), 277 : profile_id_(id),
273 kwallet_proxy_(nullptr), 278 kwallet_proxy_(nullptr),
274 app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) { 279 app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) {
275 folder_name_ = GetProfileSpecificFolderName(); 280 folder_name_ = GetProfileSpecificFolderName();
281
282 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) {
283 dbus_service_name_ = kKWallet5ServiceName;
284 dbus_path_ = kKWallet5Path;
285 kwalletd_name_ = kKWalletD5Name;
286 } else {
287 dbus_service_name_ = kKWalletServiceName;
288 dbus_path_ = kKWalletPath;
289 kwalletd_name_ = kKWalletDName;
290 }
276 } 291 }
277 292
278 NativeBackendKWallet::~NativeBackendKWallet() { 293 NativeBackendKWallet::~NativeBackendKWallet() {
279 // This destructor is called on the thread that is destroying the Profile 294 // This destructor is called on the thread that is destroying the Profile
280 // containing the PasswordStore that owns this NativeBackend. Generally that 295 // containing the PasswordStore that owns this NativeBackend. Generally that
281 // won't be the DB thread; it will be the UI thread. So we post a message to 296 // won't be the DB thread; it will be the UI thread. So we post a message to
282 // shut it down on the DB thread, and it will be destructed afterward when the 297 // shut it down on the DB thread, and it will be destructed afterward when the
283 // scoped_refptr<dbus::Bus> goes out of scope. The NativeBackend will be 298 // scoped_refptr<dbus::Bus> goes out of scope. The NativeBackend will be
284 // destroyed before that occurs, but that's OK. 299 // destroyed before that occurs, but that's OK.
285 if (session_bus_.get()) { 300 if (session_bus_.get()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // The optional_bus parameter is given when this method is called in tests. 337 // The optional_bus parameter is given when this method is called in tests.
323 session_bus_ = optional_bus; 338 session_bus_ = optional_bus;
324 } else { 339 } else {
325 // Get a (real) connection to the session bus. 340 // Get a (real) connection to the session bus.
326 dbus::Bus::Options options; 341 dbus::Bus::Options options;
327 options.bus_type = dbus::Bus::SESSION; 342 options.bus_type = dbus::Bus::SESSION;
328 options.connection_type = dbus::Bus::PRIVATE; 343 options.connection_type = dbus::Bus::PRIVATE;
329 session_bus_ = new dbus::Bus(options); 344 session_bus_ = new dbus::Bus(options);
330 } 345 }
331 kwallet_proxy_ = 346 kwallet_proxy_ =
332 session_bus_->GetObjectProxy(kKWalletServiceName, 347 session_bus_->GetObjectProxy(dbus_service_name_,
333 dbus::ObjectPath(kKWalletPath)); 348 dbus::ObjectPath(dbus_path_));
334 // kwalletd may not be running. If we get a temporary failure initializing it, 349 // kwalletd may not be running. If we get a temporary failure initializing it,
335 // try to start it and then try again. (Note the short-circuit evaluation.) 350 // try to start it and then try again. (Note the short-circuit evaluation.)
336 const InitResult result = InitWallet(); 351 const InitResult result = InitWallet();
337 *success = (result == INIT_SUCCESS || 352 *success = (result == INIT_SUCCESS ||
338 (result == TEMPORARY_FAIL && 353 (result == TEMPORARY_FAIL &&
339 StartKWalletd() && InitWallet() == INIT_SUCCESS)); 354 StartKWalletd() && InitWallet() == INIT_SUCCESS));
340 event->Signal(); 355 event->Signal();
341 } 356 }
342 357
343 bool NativeBackendKWallet::StartKWalletd() { 358 bool NativeBackendKWallet::StartKWalletd() {
344 DCHECK_CURRENTLY_ON(BrowserThread::DB); 359 DCHECK_CURRENTLY_ON(BrowserThread::DB);
345 // Sadly kwalletd doesn't use DBus activation, so we have to make a call to 360 // Sadly kwalletd doesn't use DBus activation, so we have to make a call to
346 // klauncher to start it. 361 // klauncher to start it.
347 dbus::ObjectProxy* klauncher = 362 dbus::ObjectProxy* klauncher =
348 session_bus_->GetObjectProxy(kKLauncherServiceName, 363 session_bus_->GetObjectProxy(kKLauncherServiceName,
349 dbus::ObjectPath(kKLauncherPath)); 364 dbus::ObjectPath(kKLauncherPath));
350 365
351 dbus::MethodCall method_call(kKLauncherInterface, 366 dbus::MethodCall method_call(kKLauncherInterface,
352 "start_service_by_desktop_name"); 367 "start_service_by_desktop_name");
353 dbus::MessageWriter builder(&method_call); 368 dbus::MessageWriter builder(&method_call);
354 std::vector<std::string> empty; 369 std::vector<std::string> empty;
355 builder.AppendString("kwalletd"); // serviceName 370 builder.AppendString(kwalletd_name_); // serviceName
356 builder.AppendArrayOfStrings(empty); // urls 371 builder.AppendArrayOfStrings(empty); // urls
357 builder.AppendArrayOfStrings(empty); // envs 372 builder.AppendArrayOfStrings(empty); // envs
358 builder.AppendString(std::string()); // startup_id 373 builder.AppendString(std::string()); // startup_id
359 builder.AppendBool(false); // blind 374 builder.AppendBool(false); // blind
360 scoped_ptr<dbus::Response> response( 375 scoped_ptr<dbus::Response> response(
361 klauncher->CallMethodAndBlock( 376 klauncher->CallMethodAndBlock(
362 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 377 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
363 if (!response.get()) { 378 if (!response.get()) {
364 LOG(ERROR) << "Error contacting klauncher to start kwalletd"; 379 LOG(ERROR) << "Error contacting klauncher to start " << kwalletd_name_;
365 return false; 380 return false;
366 } 381 }
367 dbus::MessageReader reader(response.get()); 382 dbus::MessageReader reader(response.get());
368 int32_t ret = -1; 383 int32_t ret = -1;
369 std::string dbus_name; 384 std::string dbus_name;
370 std::string error; 385 std::string error;
371 int32_t pid = -1; 386 int32_t pid = -1;
372 if (!reader.PopInt32(&ret) || !reader.PopString(&dbus_name) || 387 if (!reader.PopInt32(&ret) || !reader.PopString(&dbus_name) ||
373 !reader.PopString(&error) || !reader.PopInt32(&pid)) { 388 !reader.PopString(&error) || !reader.PopInt32(&pid)) {
374 LOG(ERROR) << "Error reading response from klauncher to start kwalletd: " 389 LOG(ERROR) << "Error reading response from klauncher to start "
375 << response->ToString(); 390 << kwalletd_name_ << ": " << response->ToString();
376 return false; 391 return false;
377 } 392 }
378 if (!error.empty() || ret) { 393 if (!error.empty() || ret) {
379 LOG(ERROR) << "Error launching kwalletd: error '" << error << "' " 394 LOG(ERROR) << "Error launching " << kwalletd_name_ << ": error '" << error
380 << " (code " << ret << ")"; 395 << "' (code " << ret << ")";
381 return false; 396 return false;
382 } 397 }
383 398
384 return true; 399 return true;
385 } 400 }
386 401
387 NativeBackendKWallet::InitResult NativeBackendKWallet::InitWallet() { 402 NativeBackendKWallet::InitResult NativeBackendKWallet::InitWallet() {
388 DCHECK_CURRENTLY_ON(BrowserThread::DB); 403 DCHECK_CURRENTLY_ON(BrowserThread::DB);
389 { 404 {
390 // Check that KWallet is enabled. 405 // Check that KWallet is enabled.
391 dbus::MethodCall method_call(kKWalletInterface, "isEnabled"); 406 dbus::MethodCall method_call(kKWalletInterface, "isEnabled");
392 scoped_ptr<dbus::Response> response( 407 scoped_ptr<dbus::Response> response(
393 kwallet_proxy_->CallMethodAndBlock( 408 kwallet_proxy_->CallMethodAndBlock(
394 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 409 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
395 if (!response.get()) { 410 if (!response.get()) {
396 LOG(ERROR) << "Error contacting kwalletd (isEnabled)"; 411 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (isEnabled)";
397 return TEMPORARY_FAIL; 412 return TEMPORARY_FAIL;
398 } 413 }
399 dbus::MessageReader reader(response.get()); 414 dbus::MessageReader reader(response.get());
400 bool enabled = false; 415 bool enabled = false;
401 if (!reader.PopBool(&enabled)) { 416 if (!reader.PopBool(&enabled)) {
402 LOG(ERROR) << "Error reading response from kwalletd (isEnabled): " 417 LOG(ERROR) << "Error reading response from " << kwalletd_name_
403 << response->ToString(); 418 << " (isEnabled): " << response->ToString();
404 return PERMANENT_FAIL; 419 return PERMANENT_FAIL;
405 } 420 }
406 // Not enabled? Don't use KWallet. But also don't warn here. 421 // Not enabled? Don't use KWallet. But also don't warn here.
407 if (!enabled) { 422 if (!enabled) {
408 VLOG(1) << "kwalletd reports that KWallet is not enabled."; 423 VLOG(1) << kwalletd_name_ << " reports that KWallet is not enabled.";
409 return PERMANENT_FAIL; 424 return PERMANENT_FAIL;
410 } 425 }
411 } 426 }
412 427
413 { 428 {
414 // Get the wallet name. 429 // Get the wallet name.
415 dbus::MethodCall method_call(kKWalletInterface, "networkWallet"); 430 dbus::MethodCall method_call(kKWalletInterface, "networkWallet");
416 scoped_ptr<dbus::Response> response( 431 scoped_ptr<dbus::Response> response(
417 kwallet_proxy_->CallMethodAndBlock( 432 kwallet_proxy_->CallMethodAndBlock(
418 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 433 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
419 if (!response.get()) { 434 if (!response.get()) {
420 LOG(ERROR) << "Error contacting kwalletd (networkWallet)"; 435 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (networkWallet)";
421 return TEMPORARY_FAIL; 436 return TEMPORARY_FAIL;
422 } 437 }
423 dbus::MessageReader reader(response.get()); 438 dbus::MessageReader reader(response.get());
424 if (!reader.PopString(&wallet_name_)) { 439 if (!reader.PopString(&wallet_name_)) {
425 LOG(ERROR) << "Error reading response from kwalletd (networkWallet): " 440 LOG(ERROR) << "Error reading response from " << kwalletd_name_
426 << response->ToString(); 441 << " (networkWallet): " << response->ToString();
427 return PERMANENT_FAIL; 442 return PERMANENT_FAIL;
428 } 443 }
429 } 444 }
430 445
431 return INIT_SUCCESS; 446 return INIT_SUCCESS;
432 } 447 }
433 448
434 password_manager::PasswordStoreChangeList NativeBackendKWallet::AddLogin( 449 password_manager::PasswordStoreChangeList NativeBackendKWallet::AddLogin(
435 const PasswordForm& form) { 450 const PasswordForm& form) {
436 int wallet_handle = WalletHandle(); 451 int wallet_handle = WalletHandle();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 dbus::MethodCall method_call(kKWalletInterface, "hasEntry"); 590 dbus::MethodCall method_call(kKWalletInterface, "hasEntry");
576 dbus::MessageWriter builder(&method_call); 591 dbus::MessageWriter builder(&method_call);
577 builder.AppendInt32(wallet_handle); // handle 592 builder.AppendInt32(wallet_handle); // handle
578 builder.AppendString(folder_name_); // folder 593 builder.AppendString(folder_name_); // folder
579 builder.AppendString(signon_realm); // key 594 builder.AppendString(signon_realm); // key
580 builder.AppendString(app_name_); // appid 595 builder.AppendString(app_name_); // appid
581 scoped_ptr<dbus::Response> response( 596 scoped_ptr<dbus::Response> response(
582 kwallet_proxy_->CallMethodAndBlock( 597 kwallet_proxy_->CallMethodAndBlock(
583 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 598 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
584 if (!response.get()) { 599 if (!response.get()) {
585 LOG(ERROR) << "Error contacting kwalletd (hasEntry)"; 600 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasEntry)";
586 return false; 601 return false;
587 } 602 }
588 dbus::MessageReader reader(response.get()); 603 dbus::MessageReader reader(response.get());
589 bool has_entry = false; 604 bool has_entry = false;
590 if (!reader.PopBool(&has_entry)) { 605 if (!reader.PopBool(&has_entry)) {
591 LOG(ERROR) << "Error reading response from kwalletd (hasEntry): " 606 LOG(ERROR) << "Error reading response from " << kwalletd_name_
592 << response->ToString(); 607 << " (hasEntry): " << response->ToString();
593 return false; 608 return false;
594 } 609 }
595 if (!has_entry) { 610 if (!has_entry) {
596 // This is not an error. There just isn't a matching entry. 611 // This is not an error. There just isn't a matching entry.
597 return true; 612 return true;
598 } 613 }
599 } 614 }
600 615
601 { 616 {
602 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); 617 dbus::MethodCall method_call(kKWalletInterface, "readEntry");
603 dbus::MessageWriter builder(&method_call); 618 dbus::MessageWriter builder(&method_call);
604 builder.AppendInt32(wallet_handle); // handle 619 builder.AppendInt32(wallet_handle); // handle
605 builder.AppendString(folder_name_); // folder 620 builder.AppendString(folder_name_); // folder
606 builder.AppendString(signon_realm); // key 621 builder.AppendString(signon_realm); // key
607 builder.AppendString(app_name_); // appid 622 builder.AppendString(app_name_); // appid
608 scoped_ptr<dbus::Response> response( 623 scoped_ptr<dbus::Response> response(
609 kwallet_proxy_->CallMethodAndBlock( 624 kwallet_proxy_->CallMethodAndBlock(
610 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 625 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
611 if (!response.get()) { 626 if (!response.get()) {
612 LOG(ERROR) << "Error contacting kwalletd (readEntry)"; 627 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)";
613 return false; 628 return false;
614 } 629 }
615 dbus::MessageReader reader(response.get()); 630 dbus::MessageReader reader(response.get());
616 const uint8_t* bytes = nullptr; 631 const uint8_t* bytes = nullptr;
617 size_t length = 0; 632 size_t length = 0;
618 if (!reader.PopArrayOfBytes(&bytes, &length)) { 633 if (!reader.PopArrayOfBytes(&bytes, &length)) {
619 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " 634 LOG(ERROR) << "Error reading response from " << kwalletd_name_
620 << response->ToString(); 635 << " (readEntry): " << response->ToString();
621 return false; 636 return false;
622 } 637 }
623 if (!bytes) 638 if (!bytes)
624 return false; 639 return false;
625 if (!CheckSerializedValue(bytes, length, signon_realm)) { 640 if (!CheckSerializedValue(bytes, length, signon_realm)) {
626 // This is weird, but we choose not to call it an error. There is an 641 // This is weird, but we choose not to call it an error. There is an
627 // invalid entry somehow, but by just ignoring it, we make it easier to 642 // invalid entry somehow, but by just ignoring it, we make it easier to
628 // repair without having to delete it using kwalletmanager (that is, by 643 // repair without having to delete it using kwalletmanager (that is, by
629 // just saving a new password within this realm to overwrite it). 644 // just saving a new password within this realm to overwrite it).
630 return true; 645 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 { 707 {
693 dbus::MethodCall method_call(kKWalletInterface, "entryList"); 708 dbus::MethodCall method_call(kKWalletInterface, "entryList");
694 dbus::MessageWriter builder(&method_call); 709 dbus::MessageWriter builder(&method_call);
695 builder.AppendInt32(wallet_handle); // handle 710 builder.AppendInt32(wallet_handle); // handle
696 builder.AppendString(folder_name_); // folder 711 builder.AppendString(folder_name_); // folder
697 builder.AppendString(app_name_); // appid 712 builder.AppendString(app_name_); // appid
698 scoped_ptr<dbus::Response> response( 713 scoped_ptr<dbus::Response> response(
699 kwallet_proxy_->CallMethodAndBlock( 714 kwallet_proxy_->CallMethodAndBlock(
700 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 715 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
701 if (!response.get()) { 716 if (!response.get()) {
702 LOG(ERROR) << "Error contacting kwalletd (entryList)"; 717 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)";
703 return false; 718 return false;
704 } 719 }
705 dbus::MessageReader reader(response.get()); 720 dbus::MessageReader reader(response.get());
706 if (!reader.PopArrayOfStrings(&realm_list)) { 721 if (!reader.PopArrayOfStrings(&realm_list)) {
707 LOG(ERROR) << "Error reading response from kwalletd (entryList): " 722 LOG(ERROR) << "Error reading response from " << kwalletd_name_
708 << response->ToString(); 723 << "(entryList): " << response->ToString();
709 return false; 724 return false;
710 } 725 }
711 } 726 }
712 727
713 forms->clear(); 728 forms->clear();
714 for (const std::string& signon_realm : realm_list) { 729 for (const std::string& signon_realm : realm_list) {
715 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); 730 dbus::MethodCall method_call(kKWalletInterface, "readEntry");
716 dbus::MessageWriter builder(&method_call); 731 dbus::MessageWriter builder(&method_call);
717 builder.AppendInt32(wallet_handle); // handle 732 builder.AppendInt32(wallet_handle); // handle
718 builder.AppendString(folder_name_); // folder 733 builder.AppendString(folder_name_); // folder
719 builder.AppendString(signon_realm); // key 734 builder.AppendString(signon_realm); // key
720 builder.AppendString(app_name_); // appid 735 builder.AppendString(app_name_); // appid
721 scoped_ptr<dbus::Response> response( 736 scoped_ptr<dbus::Response> response(
722 kwallet_proxy_->CallMethodAndBlock( 737 kwallet_proxy_->CallMethodAndBlock(
723 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 738 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
724 if (!response.get()) { 739 if (!response.get()) {
725 LOG(ERROR) << "Error contacting kwalletd (readEntry)"; 740 LOG(ERROR) << "Error contacting " << kwalletd_name_ << "(readEntry)";
726 return false; 741 return false;
727 } 742 }
728 dbus::MessageReader reader(response.get()); 743 dbus::MessageReader reader(response.get());
729 const uint8_t* bytes = nullptr; 744 const uint8_t* bytes = nullptr;
730 size_t length = 0; 745 size_t length = 0;
731 if (!reader.PopArrayOfBytes(&bytes, &length)) { 746 if (!reader.PopArrayOfBytes(&bytes, &length)) {
732 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " 747 LOG(ERROR) << "Error reading response from " << kwalletd_name_
733 << response->ToString(); 748 << " (readEntry): " << response->ToString();
734 return false; 749 return false;
735 } 750 }
736 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm)) 751 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm))
737 continue; 752 continue;
738 753
739 // Can't we all just agree on whether bytes are signed or not? Please? 754 // Can't we all just agree on whether bytes are signed or not? Please?
740 base::Pickle pickle(reinterpret_cast<const char*>(bytes), length); 755 base::Pickle pickle(reinterpret_cast<const char*>(bytes), length);
741 AppendSecondToFirst(forms, DeserializeValue(signon_realm, pickle)); 756 AppendSecondToFirst(forms, DeserializeValue(signon_realm, pickle));
742 } 757 }
743 return true; 758 return true;
744 } 759 }
745 760
746 bool NativeBackendKWallet::SetLoginsList( 761 bool NativeBackendKWallet::SetLoginsList(
747 const std::vector<autofill::PasswordForm*>& forms, 762 const std::vector<autofill::PasswordForm*>& forms,
748 const std::string& signon_realm, 763 const std::string& signon_realm,
749 int wallet_handle) { 764 int wallet_handle) {
750 if (forms.empty()) { 765 if (forms.empty()) {
751 // No items left? Remove the entry from the wallet. 766 // No items left? Remove the entry from the wallet.
752 dbus::MethodCall method_call(kKWalletInterface, "removeEntry"); 767 dbus::MethodCall method_call(kKWalletInterface, "removeEntry");
753 dbus::MessageWriter builder(&method_call); 768 dbus::MessageWriter builder(&method_call);
754 builder.AppendInt32(wallet_handle); // handle 769 builder.AppendInt32(wallet_handle); // handle
755 builder.AppendString(folder_name_); // folder 770 builder.AppendString(folder_name_); // folder
756 builder.AppendString(signon_realm); // key 771 builder.AppendString(signon_realm); // key
757 builder.AppendString(app_name_); // appid 772 builder.AppendString(app_name_); // appid
758 scoped_ptr<dbus::Response> response( 773 scoped_ptr<dbus::Response> response(
759 kwallet_proxy_->CallMethodAndBlock( 774 kwallet_proxy_->CallMethodAndBlock(
760 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 775 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
761 if (!response.get()) { 776 if (!response.get()) {
762 LOG(ERROR) << "Error contacting kwalletd (removeEntry)"; 777 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (removeEntry)";
763 return kInvalidKWalletHandle; 778 return kInvalidKWalletHandle;
764 } 779 }
765 dbus::MessageReader reader(response.get()); 780 dbus::MessageReader reader(response.get());
766 int ret = 0; 781 int ret = 0;
767 if (!reader.PopInt32(&ret)) { 782 if (!reader.PopInt32(&ret)) {
768 LOG(ERROR) << "Error reading response from kwalletd (removeEntry): " 783 LOG(ERROR) << "Error reading response from " << kwalletd_name_
769 << response->ToString(); 784 << " (removeEntry): " << response->ToString();
770 return false; 785 return false;
771 } 786 }
772 if (ret != 0) 787 if (ret != 0)
773 LOG(ERROR) << "Bad return code " << ret << " from KWallet removeEntry"; 788 LOG(ERROR) << "Bad return code " << ret << " from KWallet removeEntry";
774 return ret == 0; 789 return ret == 0;
775 } 790 }
776 791
777 base::Pickle value; 792 base::Pickle value;
778 SerializeValue(forms, &value); 793 SerializeValue(forms, &value);
779 794
780 dbus::MethodCall method_call(kKWalletInterface, "writeEntry"); 795 dbus::MethodCall method_call(kKWalletInterface, "writeEntry");
781 dbus::MessageWriter builder(&method_call); 796 dbus::MessageWriter builder(&method_call);
782 builder.AppendInt32(wallet_handle); // handle 797 builder.AppendInt32(wallet_handle); // handle
783 builder.AppendString(folder_name_); // folder 798 builder.AppendString(folder_name_); // folder
784 builder.AppendString(signon_realm); // key 799 builder.AppendString(signon_realm); // key
785 builder.AppendArrayOfBytes(static_cast<const uint8_t*>(value.data()), 800 builder.AppendArrayOfBytes(static_cast<const uint8_t*>(value.data()),
786 value.size()); // value 801 value.size()); // value
787 builder.AppendString(app_name_); // appid 802 builder.AppendString(app_name_); // appid
788 scoped_ptr<dbus::Response> response( 803 scoped_ptr<dbus::Response> response(
789 kwallet_proxy_->CallMethodAndBlock( 804 kwallet_proxy_->CallMethodAndBlock(
790 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 805 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
791 if (!response.get()) { 806 if (!response.get()) {
792 LOG(ERROR) << "Error contacting kwalletd (writeEntry)"; 807 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (writeEntry)";
793 return kInvalidKWalletHandle; 808 return kInvalidKWalletHandle;
794 } 809 }
795 dbus::MessageReader reader(response.get()); 810 dbus::MessageReader reader(response.get());
796 int ret = 0; 811 int ret = 0;
797 if (!reader.PopInt32(&ret)) { 812 if (!reader.PopInt32(&ret)) {
798 LOG(ERROR) << "Error reading response from kwalletd (writeEntry): " 813 LOG(ERROR) << "Error reading response from " << kwalletd_name_
799 << response->ToString(); 814 << " (writeEntry): " << response->ToString();
800 return false; 815 return false;
801 } 816 }
802 if (ret != 0) 817 if (ret != 0)
803 LOG(ERROR) << "Bad return code " << ret << " from KWallet writeEntry"; 818 LOG(ERROR) << "Bad return code " << ret << " from KWallet writeEntry";
804 return ret == 0; 819 return ret == 0;
805 } 820 }
806 821
807 bool NativeBackendKWallet::RemoveLoginsBetween( 822 bool NativeBackendKWallet::RemoveLoginsBetween(
808 base::Time delete_begin, 823 base::Time delete_begin,
809 base::Time delete_end, 824 base::Time delete_end,
810 TimestampToCompare date_to_compare, 825 TimestampToCompare date_to_compare,
811 password_manager::PasswordStoreChangeList* changes) { 826 password_manager::PasswordStoreChangeList* changes) {
812 DCHECK(changes); 827 DCHECK(changes);
813 changes->clear(); 828 changes->clear();
814 int wallet_handle = WalletHandle(); 829 int wallet_handle = WalletHandle();
815 if (wallet_handle == kInvalidKWalletHandle) 830 if (wallet_handle == kInvalidKWalletHandle)
816 return false; 831 return false;
817 832
818 // We could probably also use readEntryList here. 833 // We could probably also use readEntryList here.
819 std::vector<std::string> realm_list; 834 std::vector<std::string> realm_list;
820 { 835 {
821 dbus::MethodCall method_call(kKWalletInterface, "entryList"); 836 dbus::MethodCall method_call(kKWalletInterface, "entryList");
822 dbus::MessageWriter builder(&method_call); 837 dbus::MessageWriter builder(&method_call);
823 builder.AppendInt32(wallet_handle); // handle 838 builder.AppendInt32(wallet_handle); // handle
824 builder.AppendString(folder_name_); // folder 839 builder.AppendString(folder_name_); // folder
825 builder.AppendString(app_name_); // appid 840 builder.AppendString(app_name_); // appid
826 scoped_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 841 scoped_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
827 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 842 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
828 if (!response.get()) { 843 if (!response.get()) {
829 LOG(ERROR) << "Error contacting kwalletd (entryList)"; 844 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)";
830 return false; 845 return false;
831 } 846 }
832 dbus::MessageReader reader(response.get()); 847 dbus::MessageReader reader(response.get());
833 dbus::MessageReader array(response.get()); 848 dbus::MessageReader array(response.get());
834 if (!reader.PopArray(&array)) { 849 if (!reader.PopArray(&array)) {
835 LOG(ERROR) << "Error reading response from kwalletd (entryList): " 850 LOG(ERROR) << "Error reading response from " << kwalletd_name_
836 << response->ToString(); 851 << " (entryList): " << response->ToString();
837 return false; 852 return false;
838 } 853 }
839 while (array.HasMoreData()) { 854 while (array.HasMoreData()) {
840 std::string realm; 855 std::string realm;
841 if (!array.PopString(&realm)) { 856 if (!array.PopString(&realm)) {
842 LOG(ERROR) << "Error reading response from kwalletd (entryList): " 857 LOG(ERROR) << "Error reading response from " << kwalletd_name_
843 << response->ToString(); 858 << " (entryList): " << response->ToString();
844 return false; 859 return false;
845 } 860 }
846 realm_list.push_back(realm); 861 realm_list.push_back(realm);
847 } 862 }
848 } 863 }
849 864
850 bool ok = true; 865 bool ok = true;
851 for (size_t i = 0; i < realm_list.size(); ++i) { 866 for (size_t i = 0; i < realm_list.size(); ++i) {
852 const std::string& signon_realm = realm_list[i]; 867 const std::string& signon_realm = realm_list[i];
853 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); 868 dbus::MethodCall method_call(kKWalletInterface, "readEntry");
854 dbus::MessageWriter builder(&method_call); 869 dbus::MessageWriter builder(&method_call);
855 builder.AppendInt32(wallet_handle); // handle 870 builder.AppendInt32(wallet_handle); // handle
856 builder.AppendString(folder_name_); // folder 871 builder.AppendString(folder_name_); // folder
857 builder.AppendString(signon_realm); // key 872 builder.AppendString(signon_realm); // key
858 builder.AppendString(app_name_); // appid 873 builder.AppendString(app_name_); // appid
859 scoped_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 874 scoped_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
860 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 875 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
861 if (!response.get()) { 876 if (!response.get()) {
862 LOG(ERROR) << "Error contacting kwalletd (readEntry)"; 877 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)";
863 continue; 878 continue;
864 } 879 }
865 dbus::MessageReader reader(response.get()); 880 dbus::MessageReader reader(response.get());
866 const uint8_t* bytes = nullptr; 881 const uint8_t* bytes = nullptr;
867 size_t length = 0; 882 size_t length = 0;
868 if (!reader.PopArrayOfBytes(&bytes, &length)) { 883 if (!reader.PopArrayOfBytes(&bytes, &length)) {
869 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " 884 LOG(ERROR) << "Error reading response from " << kwalletd_name_
870 << response->ToString(); 885 << " (readEntry): " << response->ToString();
871 continue; 886 continue;
872 } 887 }
873 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm)) 888 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm))
874 continue; 889 continue;
875 890
876 // Can't we all just agree on whether bytes are signed or not? Please? 891 // Can't we all just agree on whether bytes are signed or not? Please?
877 base::Pickle pickle(reinterpret_cast<const char*>(bytes), length); 892 base::Pickle pickle(reinterpret_cast<const char*>(bytes), length);
878 ScopedVector<autofill::PasswordForm> all_forms = 893 ScopedVector<autofill::PasswordForm> all_forms =
879 DeserializeValue(signon_realm, pickle); 894 DeserializeValue(signon_realm, pickle);
880 895
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 { 965 {
951 dbus::MethodCall method_call(kKWalletInterface, "open"); 966 dbus::MethodCall method_call(kKWalletInterface, "open");
952 dbus::MessageWriter builder(&method_call); 967 dbus::MessageWriter builder(&method_call);
953 builder.AppendString(wallet_name_); // wallet 968 builder.AppendString(wallet_name_); // wallet
954 builder.AppendInt64(0); // wid 969 builder.AppendInt64(0); // wid
955 builder.AppendString(app_name_); // appid 970 builder.AppendString(app_name_); // appid
956 scoped_ptr<dbus::Response> response( 971 scoped_ptr<dbus::Response> response(
957 kwallet_proxy_->CallMethodAndBlock( 972 kwallet_proxy_->CallMethodAndBlock(
958 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 973 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
959 if (!response.get()) { 974 if (!response.get()) {
960 LOG(ERROR) << "Error contacting kwalletd (open)"; 975 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (open)";
961 return kInvalidKWalletHandle; 976 return kInvalidKWalletHandle;
962 } 977 }
963 dbus::MessageReader reader(response.get()); 978 dbus::MessageReader reader(response.get());
964 if (!reader.PopInt32(&handle)) { 979 if (!reader.PopInt32(&handle)) {
965 LOG(ERROR) << "Error reading response from kwalletd (open): " 980 LOG(ERROR) << "Error reading response from " << kwalletd_name_
966 << response->ToString(); 981 << " (open): " << response->ToString();
967 return kInvalidKWalletHandle; 982 return kInvalidKWalletHandle;
968 } 983 }
969 if (handle == kInvalidKWalletHandle) { 984 if (handle == kInvalidKWalletHandle) {
970 LOG(ERROR) << "Error obtaining KWallet handle"; 985 LOG(ERROR) << "Error obtaining KWallet handle";
971 return kInvalidKWalletHandle; 986 return kInvalidKWalletHandle;
972 } 987 }
973 } 988 }
974 989
975 // Check if our folder exists. 990 // Check if our folder exists.
976 bool has_folder = false; 991 bool has_folder = false;
977 { 992 {
978 dbus::MethodCall method_call(kKWalletInterface, "hasFolder"); 993 dbus::MethodCall method_call(kKWalletInterface, "hasFolder");
979 dbus::MessageWriter builder(&method_call); 994 dbus::MessageWriter builder(&method_call);
980 builder.AppendInt32(handle); // handle 995 builder.AppendInt32(handle); // handle
981 builder.AppendString(folder_name_); // folder 996 builder.AppendString(folder_name_); // folder
982 builder.AppendString(app_name_); // appid 997 builder.AppendString(app_name_); // appid
983 scoped_ptr<dbus::Response> response( 998 scoped_ptr<dbus::Response> response(
984 kwallet_proxy_->CallMethodAndBlock( 999 kwallet_proxy_->CallMethodAndBlock(
985 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 1000 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
986 if (!response.get()) { 1001 if (!response.get()) {
987 LOG(ERROR) << "Error contacting kwalletd (hasFolder)"; 1002 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasFolder)";
988 return kInvalidKWalletHandle; 1003 return kInvalidKWalletHandle;
989 } 1004 }
990 dbus::MessageReader reader(response.get()); 1005 dbus::MessageReader reader(response.get());
991 if (!reader.PopBool(&has_folder)) { 1006 if (!reader.PopBool(&has_folder)) {
992 LOG(ERROR) << "Error reading response from kwalletd (hasFolder): " 1007 LOG(ERROR) << "Error reading response from " << kwalletd_name_
993 << response->ToString(); 1008 << " (hasFolder): " << response->ToString();
994 return kInvalidKWalletHandle; 1009 return kInvalidKWalletHandle;
995 } 1010 }
996 } 1011 }
997 1012
998 // Create it if it didn't. 1013 // Create it if it didn't.
999 if (!has_folder) { 1014 if (!has_folder) {
1000 dbus::MethodCall method_call(kKWalletInterface, "createFolder"); 1015 dbus::MethodCall method_call(kKWalletInterface, "createFolder");
1001 dbus::MessageWriter builder(&method_call); 1016 dbus::MessageWriter builder(&method_call);
1002 builder.AppendInt32(handle); // handle 1017 builder.AppendInt32(handle); // handle
1003 builder.AppendString(folder_name_); // folder 1018 builder.AppendString(folder_name_); // folder
1004 builder.AppendString(app_name_); // appid 1019 builder.AppendString(app_name_); // appid
1005 scoped_ptr<dbus::Response> response( 1020 scoped_ptr<dbus::Response> response(
1006 kwallet_proxy_->CallMethodAndBlock( 1021 kwallet_proxy_->CallMethodAndBlock(
1007 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 1022 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
1008 if (!response.get()) { 1023 if (!response.get()) {
1009 LOG(ERROR) << "Error contacting kwalletd (createFolder)"; 1024 LOG(ERROR) << "Error contacting << " << kwalletd_name_
1025 << " (createFolder)";
1010 return kInvalidKWalletHandle; 1026 return kInvalidKWalletHandle;
1011 } 1027 }
1012 dbus::MessageReader reader(response.get()); 1028 dbus::MessageReader reader(response.get());
1013 bool success = false; 1029 bool success = false;
1014 if (!reader.PopBool(&success)) { 1030 if (!reader.PopBool(&success)) {
1015 LOG(ERROR) << "Error reading response from kwalletd (createFolder): " 1031 LOG(ERROR) << "Error reading response from " << kwalletd_name_
1016 << response->ToString(); 1032 << " (createFolder): " << response->ToString();
1017 return kInvalidKWalletHandle; 1033 return kInvalidKWalletHandle;
1018 } 1034 }
1019 if (!success) { 1035 if (!success) {
1020 LOG(ERROR) << "Error creating KWallet folder"; 1036 LOG(ERROR) << "Error creating KWallet folder";
1021 return kInvalidKWalletHandle; 1037 return kInvalidKWalletHandle;
1022 } 1038 }
1023 } 1039 }
1024 1040
1025 return handle; 1041 return handle;
1026 } 1042 }
1027 1043
1028 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { 1044 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const {
1029 // Originally, the folder name was always just "Chrome Form Data". 1045 // Originally, the folder name was always just "Chrome Form Data".
1030 // Now we use it to distinguish passwords for different profiles. 1046 // Now we use it to distinguish passwords for different profiles.
1031 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); 1047 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_);
1032 } 1048 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698