| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 << "(" << count << "; realm: " << signon_realm << ")"; | 161 << "(" << count << "; realm: " << signon_realm << ")"; |
| 162 } | 162 } |
| 163 return false; | 163 return false; |
| 164 } | 164 } |
| 165 | 165 |
| 166 // We'll swap |converted_forms| with |*forms| on success, to make sure we | 166 // We'll swap |converted_forms| with |*forms| on success, to make sure we |
| 167 // don't return partial results on failure. | 167 // don't return partial results on failure. |
| 168 ScopedVector<autofill::PasswordForm> converted_forms; | 168 ScopedVector<autofill::PasswordForm> converted_forms; |
| 169 converted_forms.reserve(count); | 169 converted_forms.reserve(count); |
| 170 for (size_t i = 0; i < count; ++i) { | 170 for (size_t i = 0; i < count; ++i) { |
| 171 scoped_ptr<PasswordForm> form(new PasswordForm()); | 171 std::unique_ptr<PasswordForm> form(new PasswordForm()); |
| 172 form->signon_realm.assign(signon_realm); | 172 form->signon_realm.assign(signon_realm); |
| 173 | 173 |
| 174 int scheme = 0; | 174 int scheme = 0; |
| 175 int64_t date_created = 0; | 175 int64_t date_created = 0; |
| 176 int type = 0; | 176 int type = 0; |
| 177 int generation_upload_status = 0; | 177 int generation_upload_status = 0; |
| 178 // Note that these will be read back in the order listed due to | 178 // Note that these will be read back in the order listed due to |
| 179 // short-circuit evaluation. This is important. | 179 // short-circuit evaluation. This is important. |
| 180 if (!iter.ReadInt(&scheme) || | 180 if (!iter.ReadInt(&scheme) || |
| 181 !ReadGURL(&iter, warn_only, &form->origin) || | 181 !ReadGURL(&iter, warn_only, &form->origin) || |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 395 |
| 396 dbus::MethodCall method_call(kKLauncherInterface, | 396 dbus::MethodCall method_call(kKLauncherInterface, |
| 397 "start_service_by_desktop_name"); | 397 "start_service_by_desktop_name"); |
| 398 dbus::MessageWriter builder(&method_call); | 398 dbus::MessageWriter builder(&method_call); |
| 399 std::vector<std::string> empty; | 399 std::vector<std::string> empty; |
| 400 builder.AppendString(kwalletd_name_); // serviceName | 400 builder.AppendString(kwalletd_name_); // serviceName |
| 401 builder.AppendArrayOfStrings(empty); // urls | 401 builder.AppendArrayOfStrings(empty); // urls |
| 402 builder.AppendArrayOfStrings(empty); // envs | 402 builder.AppendArrayOfStrings(empty); // envs |
| 403 builder.AppendString(std::string()); // startup_id | 403 builder.AppendString(std::string()); // startup_id |
| 404 builder.AppendBool(false); // blind | 404 builder.AppendBool(false); // blind |
| 405 scoped_ptr<dbus::Response> response( | 405 std::unique_ptr<dbus::Response> response(klauncher->CallMethodAndBlock( |
| 406 klauncher->CallMethodAndBlock( | 406 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 407 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 408 if (!response.get()) { | 407 if (!response.get()) { |
| 409 LOG(ERROR) << "Error contacting klauncher to start " << kwalletd_name_; | 408 LOG(ERROR) << "Error contacting klauncher to start " << kwalletd_name_; |
| 410 return false; | 409 return false; |
| 411 } | 410 } |
| 412 dbus::MessageReader reader(response.get()); | 411 dbus::MessageReader reader(response.get()); |
| 413 int32_t ret = -1; | 412 int32_t ret = -1; |
| 414 std::string dbus_name; | 413 std::string dbus_name; |
| 415 std::string error; | 414 std::string error; |
| 416 int32_t pid = -1; | 415 int32_t pid = -1; |
| 417 if (!reader.PopInt32(&ret) || !reader.PopString(&dbus_name) || | 416 if (!reader.PopInt32(&ret) || !reader.PopString(&dbus_name) || |
| 418 !reader.PopString(&error) || !reader.PopInt32(&pid)) { | 417 !reader.PopString(&error) || !reader.PopInt32(&pid)) { |
| 419 LOG(ERROR) << "Error reading response from klauncher to start " | 418 LOG(ERROR) << "Error reading response from klauncher to start " |
| 420 << kwalletd_name_ << ": " << response->ToString(); | 419 << kwalletd_name_ << ": " << response->ToString(); |
| 421 return false; | 420 return false; |
| 422 } | 421 } |
| 423 if (!error.empty() || ret) { | 422 if (!error.empty() || ret) { |
| 424 LOG(ERROR) << "Error launching " << kwalletd_name_ << ": error '" << error | 423 LOG(ERROR) << "Error launching " << kwalletd_name_ << ": error '" << error |
| 425 << "' (code " << ret << ")"; | 424 << "' (code " << ret << ")"; |
| 426 return false; | 425 return false; |
| 427 } | 426 } |
| 428 | 427 |
| 429 return true; | 428 return true; |
| 430 } | 429 } |
| 431 | 430 |
| 432 NativeBackendKWallet::InitResult NativeBackendKWallet::InitWallet() { | 431 NativeBackendKWallet::InitResult NativeBackendKWallet::InitWallet() { |
| 433 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 432 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 434 { | 433 { |
| 435 // Check that KWallet is enabled. | 434 // Check that KWallet is enabled. |
| 436 dbus::MethodCall method_call(kKWalletInterface, "isEnabled"); | 435 dbus::MethodCall method_call(kKWalletInterface, "isEnabled"); |
| 437 scoped_ptr<dbus::Response> response( | 436 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 438 kwallet_proxy_->CallMethodAndBlock( | 437 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 439 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 440 if (!response.get()) { | 438 if (!response.get()) { |
| 441 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (isEnabled)"; | 439 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (isEnabled)"; |
| 442 return TEMPORARY_FAIL; | 440 return TEMPORARY_FAIL; |
| 443 } | 441 } |
| 444 dbus::MessageReader reader(response.get()); | 442 dbus::MessageReader reader(response.get()); |
| 445 bool enabled = false; | 443 bool enabled = false; |
| 446 if (!reader.PopBool(&enabled)) { | 444 if (!reader.PopBool(&enabled)) { |
| 447 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 445 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 448 << " (isEnabled): " << response->ToString(); | 446 << " (isEnabled): " << response->ToString(); |
| 449 return PERMANENT_FAIL; | 447 return PERMANENT_FAIL; |
| 450 } | 448 } |
| 451 // Not enabled? Don't use KWallet. But also don't warn here. | 449 // Not enabled? Don't use KWallet. But also don't warn here. |
| 452 if (!enabled) { | 450 if (!enabled) { |
| 453 VLOG(1) << kwalletd_name_ << " reports that KWallet is not enabled."; | 451 VLOG(1) << kwalletd_name_ << " reports that KWallet is not enabled."; |
| 454 return PERMANENT_FAIL; | 452 return PERMANENT_FAIL; |
| 455 } | 453 } |
| 456 } | 454 } |
| 457 | 455 |
| 458 { | 456 { |
| 459 // Get the wallet name. | 457 // Get the wallet name. |
| 460 dbus::MethodCall method_call(kKWalletInterface, "networkWallet"); | 458 dbus::MethodCall method_call(kKWalletInterface, "networkWallet"); |
| 461 scoped_ptr<dbus::Response> response( | 459 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 462 kwallet_proxy_->CallMethodAndBlock( | 460 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 463 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 464 if (!response.get()) { | 461 if (!response.get()) { |
| 465 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (networkWallet)"; | 462 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (networkWallet)"; |
| 466 return TEMPORARY_FAIL; | 463 return TEMPORARY_FAIL; |
| 467 } | 464 } |
| 468 dbus::MessageReader reader(response.get()); | 465 dbus::MessageReader reader(response.get()); |
| 469 if (!reader.PopString(&wallet_name_)) { | 466 if (!reader.PopString(&wallet_name_)) { |
| 470 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 467 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 471 << " (networkWallet): " << response->ToString(); | 468 << " (networkWallet): " << response->ToString(); |
| 472 return PERMANENT_FAIL; | 469 return PERMANENT_FAIL; |
| 473 } | 470 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 ScopedVector<autofill::PasswordForm>* forms) { | 637 ScopedVector<autofill::PasswordForm>* forms) { |
| 641 forms->clear(); | 638 forms->clear(); |
| 642 // Is there an entry in the wallet? | 639 // Is there an entry in the wallet? |
| 643 { | 640 { |
| 644 dbus::MethodCall method_call(kKWalletInterface, "hasEntry"); | 641 dbus::MethodCall method_call(kKWalletInterface, "hasEntry"); |
| 645 dbus::MessageWriter builder(&method_call); | 642 dbus::MessageWriter builder(&method_call); |
| 646 builder.AppendInt32(wallet_handle); // handle | 643 builder.AppendInt32(wallet_handle); // handle |
| 647 builder.AppendString(folder_name_); // folder | 644 builder.AppendString(folder_name_); // folder |
| 648 builder.AppendString(signon_realm); // key | 645 builder.AppendString(signon_realm); // key |
| 649 builder.AppendString(app_name_); // appid | 646 builder.AppendString(app_name_); // appid |
| 650 scoped_ptr<dbus::Response> response( | 647 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 651 kwallet_proxy_->CallMethodAndBlock( | 648 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 652 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 653 if (!response.get()) { | 649 if (!response.get()) { |
| 654 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasEntry)"; | 650 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasEntry)"; |
| 655 return false; | 651 return false; |
| 656 } | 652 } |
| 657 dbus::MessageReader reader(response.get()); | 653 dbus::MessageReader reader(response.get()); |
| 658 bool has_entry = false; | 654 bool has_entry = false; |
| 659 if (!reader.PopBool(&has_entry)) { | 655 if (!reader.PopBool(&has_entry)) { |
| 660 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 656 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 661 << " (hasEntry): " << response->ToString(); | 657 << " (hasEntry): " << response->ToString(); |
| 662 return false; | 658 return false; |
| 663 } | 659 } |
| 664 if (!has_entry) { | 660 if (!has_entry) { |
| 665 // This is not an error. There just isn't a matching entry. | 661 // This is not an error. There just isn't a matching entry. |
| 666 return true; | 662 return true; |
| 667 } | 663 } |
| 668 } | 664 } |
| 669 | 665 |
| 670 { | 666 { |
| 671 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); | 667 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); |
| 672 dbus::MessageWriter builder(&method_call); | 668 dbus::MessageWriter builder(&method_call); |
| 673 builder.AppendInt32(wallet_handle); // handle | 669 builder.AppendInt32(wallet_handle); // handle |
| 674 builder.AppendString(folder_name_); // folder | 670 builder.AppendString(folder_name_); // folder |
| 675 builder.AppendString(signon_realm); // key | 671 builder.AppendString(signon_realm); // key |
| 676 builder.AppendString(app_name_); // appid | 672 builder.AppendString(app_name_); // appid |
| 677 scoped_ptr<dbus::Response> response( | 673 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 678 kwallet_proxy_->CallMethodAndBlock( | 674 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 679 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 680 if (!response.get()) { | 675 if (!response.get()) { |
| 681 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)"; | 676 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)"; |
| 682 return false; | 677 return false; |
| 683 } | 678 } |
| 684 dbus::MessageReader reader(response.get()); | 679 dbus::MessageReader reader(response.get()); |
| 685 const uint8_t* bytes = nullptr; | 680 const uint8_t* bytes = nullptr; |
| 686 size_t length = 0; | 681 size_t length = 0; |
| 687 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 682 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 688 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 683 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 689 << " (readEntry): " << response->ToString(); | 684 << " (readEntry): " << response->ToString(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 int wallet_handle, | 752 int wallet_handle, |
| 758 ScopedVector<autofill::PasswordForm>* forms) { | 753 ScopedVector<autofill::PasswordForm>* forms) { |
| 759 // We could probably also use readEntryList here. | 754 // We could probably also use readEntryList here. |
| 760 std::vector<std::string> realm_list; | 755 std::vector<std::string> realm_list; |
| 761 { | 756 { |
| 762 dbus::MethodCall method_call(kKWalletInterface, "entryList"); | 757 dbus::MethodCall method_call(kKWalletInterface, "entryList"); |
| 763 dbus::MessageWriter builder(&method_call); | 758 dbus::MessageWriter builder(&method_call); |
| 764 builder.AppendInt32(wallet_handle); // handle | 759 builder.AppendInt32(wallet_handle); // handle |
| 765 builder.AppendString(folder_name_); // folder | 760 builder.AppendString(folder_name_); // folder |
| 766 builder.AppendString(app_name_); // appid | 761 builder.AppendString(app_name_); // appid |
| 767 scoped_ptr<dbus::Response> response( | 762 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 768 kwallet_proxy_->CallMethodAndBlock( | 763 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 769 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 770 if (!response.get()) { | 764 if (!response.get()) { |
| 771 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)"; | 765 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)"; |
| 772 return false; | 766 return false; |
| 773 } | 767 } |
| 774 dbus::MessageReader reader(response.get()); | 768 dbus::MessageReader reader(response.get()); |
| 775 if (!reader.PopArrayOfStrings(&realm_list)) { | 769 if (!reader.PopArrayOfStrings(&realm_list)) { |
| 776 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 770 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 777 << "(entryList): " << response->ToString(); | 771 << "(entryList): " << response->ToString(); |
| 778 return false; | 772 return false; |
| 779 } | 773 } |
| 780 } | 774 } |
| 781 | 775 |
| 782 forms->clear(); | 776 forms->clear(); |
| 783 for (const std::string& signon_realm : realm_list) { | 777 for (const std::string& signon_realm : realm_list) { |
| 784 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); | 778 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); |
| 785 dbus::MessageWriter builder(&method_call); | 779 dbus::MessageWriter builder(&method_call); |
| 786 builder.AppendInt32(wallet_handle); // handle | 780 builder.AppendInt32(wallet_handle); // handle |
| 787 builder.AppendString(folder_name_); // folder | 781 builder.AppendString(folder_name_); // folder |
| 788 builder.AppendString(signon_realm); // key | 782 builder.AppendString(signon_realm); // key |
| 789 builder.AppendString(app_name_); // appid | 783 builder.AppendString(app_name_); // appid |
| 790 scoped_ptr<dbus::Response> response( | 784 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 791 kwallet_proxy_->CallMethodAndBlock( | 785 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 792 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 793 if (!response.get()) { | 786 if (!response.get()) { |
| 794 LOG(ERROR) << "Error contacting " << kwalletd_name_ << "(readEntry)"; | 787 LOG(ERROR) << "Error contacting " << kwalletd_name_ << "(readEntry)"; |
| 795 return false; | 788 return false; |
| 796 } | 789 } |
| 797 dbus::MessageReader reader(response.get()); | 790 dbus::MessageReader reader(response.get()); |
| 798 const uint8_t* bytes = nullptr; | 791 const uint8_t* bytes = nullptr; |
| 799 size_t length = 0; | 792 size_t length = 0; |
| 800 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 793 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 801 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 794 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 802 << " (readEntry): " << response->ToString(); | 795 << " (readEntry): " << response->ToString(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 817 const std::string& signon_realm, | 810 const std::string& signon_realm, |
| 818 int wallet_handle) { | 811 int wallet_handle) { |
| 819 if (forms.empty()) { | 812 if (forms.empty()) { |
| 820 // No items left? Remove the entry from the wallet. | 813 // No items left? Remove the entry from the wallet. |
| 821 dbus::MethodCall method_call(kKWalletInterface, "removeEntry"); | 814 dbus::MethodCall method_call(kKWalletInterface, "removeEntry"); |
| 822 dbus::MessageWriter builder(&method_call); | 815 dbus::MessageWriter builder(&method_call); |
| 823 builder.AppendInt32(wallet_handle); // handle | 816 builder.AppendInt32(wallet_handle); // handle |
| 824 builder.AppendString(folder_name_); // folder | 817 builder.AppendString(folder_name_); // folder |
| 825 builder.AppendString(signon_realm); // key | 818 builder.AppendString(signon_realm); // key |
| 826 builder.AppendString(app_name_); // appid | 819 builder.AppendString(app_name_); // appid |
| 827 scoped_ptr<dbus::Response> response( | 820 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 828 kwallet_proxy_->CallMethodAndBlock( | 821 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 829 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 830 if (!response.get()) { | 822 if (!response.get()) { |
| 831 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (removeEntry)"; | 823 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (removeEntry)"; |
| 832 return kInvalidKWalletHandle; | 824 return kInvalidKWalletHandle; |
| 833 } | 825 } |
| 834 dbus::MessageReader reader(response.get()); | 826 dbus::MessageReader reader(response.get()); |
| 835 int ret = 0; | 827 int ret = 0; |
| 836 if (!reader.PopInt32(&ret)) { | 828 if (!reader.PopInt32(&ret)) { |
| 837 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 829 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 838 << " (removeEntry): " << response->ToString(); | 830 << " (removeEntry): " << response->ToString(); |
| 839 return false; | 831 return false; |
| 840 } | 832 } |
| 841 if (ret != 0) | 833 if (ret != 0) |
| 842 LOG(ERROR) << "Bad return code " << ret << " from KWallet removeEntry"; | 834 LOG(ERROR) << "Bad return code " << ret << " from KWallet removeEntry"; |
| 843 return ret == 0; | 835 return ret == 0; |
| 844 } | 836 } |
| 845 | 837 |
| 846 base::Pickle value; | 838 base::Pickle value; |
| 847 SerializeValue(forms, &value); | 839 SerializeValue(forms, &value); |
| 848 | 840 |
| 849 dbus::MethodCall method_call(kKWalletInterface, "writeEntry"); | 841 dbus::MethodCall method_call(kKWalletInterface, "writeEntry"); |
| 850 dbus::MessageWriter builder(&method_call); | 842 dbus::MessageWriter builder(&method_call); |
| 851 builder.AppendInt32(wallet_handle); // handle | 843 builder.AppendInt32(wallet_handle); // handle |
| 852 builder.AppendString(folder_name_); // folder | 844 builder.AppendString(folder_name_); // folder |
| 853 builder.AppendString(signon_realm); // key | 845 builder.AppendString(signon_realm); // key |
| 854 builder.AppendArrayOfBytes(static_cast<const uint8_t*>(value.data()), | 846 builder.AppendArrayOfBytes(static_cast<const uint8_t*>(value.data()), |
| 855 value.size()); // value | 847 value.size()); // value |
| 856 builder.AppendString(app_name_); // appid | 848 builder.AppendString(app_name_); // appid |
| 857 scoped_ptr<dbus::Response> response( | 849 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 858 kwallet_proxy_->CallMethodAndBlock( | 850 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 859 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 860 if (!response.get()) { | 851 if (!response.get()) { |
| 861 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (writeEntry)"; | 852 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (writeEntry)"; |
| 862 return kInvalidKWalletHandle; | 853 return kInvalidKWalletHandle; |
| 863 } | 854 } |
| 864 dbus::MessageReader reader(response.get()); | 855 dbus::MessageReader reader(response.get()); |
| 865 int ret = 0; | 856 int ret = 0; |
| 866 if (!reader.PopInt32(&ret)) { | 857 if (!reader.PopInt32(&ret)) { |
| 867 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 858 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 868 << " (writeEntry): " << response->ToString(); | 859 << " (writeEntry): " << response->ToString(); |
| 869 return false; | 860 return false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 885 return false; | 876 return false; |
| 886 | 877 |
| 887 // We could probably also use readEntryList here. | 878 // We could probably also use readEntryList here. |
| 888 std::vector<std::string> realm_list; | 879 std::vector<std::string> realm_list; |
| 889 { | 880 { |
| 890 dbus::MethodCall method_call(kKWalletInterface, "entryList"); | 881 dbus::MethodCall method_call(kKWalletInterface, "entryList"); |
| 891 dbus::MessageWriter builder(&method_call); | 882 dbus::MessageWriter builder(&method_call); |
| 892 builder.AppendInt32(wallet_handle); // handle | 883 builder.AppendInt32(wallet_handle); // handle |
| 893 builder.AppendString(folder_name_); // folder | 884 builder.AppendString(folder_name_); // folder |
| 894 builder.AppendString(app_name_); // appid | 885 builder.AppendString(app_name_); // appid |
| 895 scoped_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( | 886 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 896 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | 887 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 897 if (!response.get()) { | 888 if (!response.get()) { |
| 898 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)"; | 889 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)"; |
| 899 return false; | 890 return false; |
| 900 } | 891 } |
| 901 dbus::MessageReader reader(response.get()); | 892 dbus::MessageReader reader(response.get()); |
| 902 dbus::MessageReader array(response.get()); | 893 dbus::MessageReader array(response.get()); |
| 903 if (!reader.PopArray(&array)) { | 894 if (!reader.PopArray(&array)) { |
| 904 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 895 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 905 << " (entryList): " << response->ToString(); | 896 << " (entryList): " << response->ToString(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 918 | 909 |
| 919 bool ok = true; | 910 bool ok = true; |
| 920 for (size_t i = 0; i < realm_list.size(); ++i) { | 911 for (size_t i = 0; i < realm_list.size(); ++i) { |
| 921 const std::string& signon_realm = realm_list[i]; | 912 const std::string& signon_realm = realm_list[i]; |
| 922 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); | 913 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); |
| 923 dbus::MessageWriter builder(&method_call); | 914 dbus::MessageWriter builder(&method_call); |
| 924 builder.AppendInt32(wallet_handle); // handle | 915 builder.AppendInt32(wallet_handle); // handle |
| 925 builder.AppendString(folder_name_); // folder | 916 builder.AppendString(folder_name_); // folder |
| 926 builder.AppendString(signon_realm); // key | 917 builder.AppendString(signon_realm); // key |
| 927 builder.AppendString(app_name_); // appid | 918 builder.AppendString(app_name_); // appid |
| 928 scoped_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( | 919 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 929 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | 920 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 930 if (!response.get()) { | 921 if (!response.get()) { |
| 931 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)"; | 922 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)"; |
| 932 continue; | 923 continue; |
| 933 } | 924 } |
| 934 dbus::MessageReader reader(response.get()); | 925 dbus::MessageReader reader(response.get()); |
| 935 const uint8_t* bytes = nullptr; | 926 const uint8_t* bytes = nullptr; |
| 936 size_t length = 0; | 927 size_t length = 0; |
| 937 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 928 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 938 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 929 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 1006 |
| 1016 // Open the wallet. | 1007 // Open the wallet. |
| 1017 // TODO(mdm): Are we leaking these handles? Find out. | 1008 // TODO(mdm): Are we leaking these handles? Find out. |
| 1018 int32_t handle = kInvalidKWalletHandle; | 1009 int32_t handle = kInvalidKWalletHandle; |
| 1019 { | 1010 { |
| 1020 dbus::MethodCall method_call(kKWalletInterface, "open"); | 1011 dbus::MethodCall method_call(kKWalletInterface, "open"); |
| 1021 dbus::MessageWriter builder(&method_call); | 1012 dbus::MessageWriter builder(&method_call); |
| 1022 builder.AppendString(wallet_name_); // wallet | 1013 builder.AppendString(wallet_name_); // wallet |
| 1023 builder.AppendInt64(0); // wid | 1014 builder.AppendInt64(0); // wid |
| 1024 builder.AppendString(app_name_); // appid | 1015 builder.AppendString(app_name_); // appid |
| 1025 scoped_ptr<dbus::Response> response( | 1016 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 1026 kwallet_proxy_->CallMethodAndBlock( | 1017 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 1027 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 1028 if (!response.get()) { | 1018 if (!response.get()) { |
| 1029 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (open)"; | 1019 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (open)"; |
| 1030 return kInvalidKWalletHandle; | 1020 return kInvalidKWalletHandle; |
| 1031 } | 1021 } |
| 1032 dbus::MessageReader reader(response.get()); | 1022 dbus::MessageReader reader(response.get()); |
| 1033 if (!reader.PopInt32(&handle)) { | 1023 if (!reader.PopInt32(&handle)) { |
| 1034 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 1024 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 1035 << " (open): " << response->ToString(); | 1025 << " (open): " << response->ToString(); |
| 1036 return kInvalidKWalletHandle; | 1026 return kInvalidKWalletHandle; |
| 1037 } | 1027 } |
| 1038 if (handle == kInvalidKWalletHandle) { | 1028 if (handle == kInvalidKWalletHandle) { |
| 1039 LOG(ERROR) << "Error obtaining KWallet handle"; | 1029 LOG(ERROR) << "Error obtaining KWallet handle"; |
| 1040 return kInvalidKWalletHandle; | 1030 return kInvalidKWalletHandle; |
| 1041 } | 1031 } |
| 1042 } | 1032 } |
| 1043 | 1033 |
| 1044 // Check if our folder exists. | 1034 // Check if our folder exists. |
| 1045 bool has_folder = false; | 1035 bool has_folder = false; |
| 1046 { | 1036 { |
| 1047 dbus::MethodCall method_call(kKWalletInterface, "hasFolder"); | 1037 dbus::MethodCall method_call(kKWalletInterface, "hasFolder"); |
| 1048 dbus::MessageWriter builder(&method_call); | 1038 dbus::MessageWriter builder(&method_call); |
| 1049 builder.AppendInt32(handle); // handle | 1039 builder.AppendInt32(handle); // handle |
| 1050 builder.AppendString(folder_name_); // folder | 1040 builder.AppendString(folder_name_); // folder |
| 1051 builder.AppendString(app_name_); // appid | 1041 builder.AppendString(app_name_); // appid |
| 1052 scoped_ptr<dbus::Response> response( | 1042 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 1053 kwallet_proxy_->CallMethodAndBlock( | 1043 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 1054 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 1055 if (!response.get()) { | 1044 if (!response.get()) { |
| 1056 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasFolder)"; | 1045 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasFolder)"; |
| 1057 return kInvalidKWalletHandle; | 1046 return kInvalidKWalletHandle; |
| 1058 } | 1047 } |
| 1059 dbus::MessageReader reader(response.get()); | 1048 dbus::MessageReader reader(response.get()); |
| 1060 if (!reader.PopBool(&has_folder)) { | 1049 if (!reader.PopBool(&has_folder)) { |
| 1061 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 1050 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 1062 << " (hasFolder): " << response->ToString(); | 1051 << " (hasFolder): " << response->ToString(); |
| 1063 return kInvalidKWalletHandle; | 1052 return kInvalidKWalletHandle; |
| 1064 } | 1053 } |
| 1065 } | 1054 } |
| 1066 | 1055 |
| 1067 // Create it if it didn't. | 1056 // Create it if it didn't. |
| 1068 if (!has_folder) { | 1057 if (!has_folder) { |
| 1069 dbus::MethodCall method_call(kKWalletInterface, "createFolder"); | 1058 dbus::MethodCall method_call(kKWalletInterface, "createFolder"); |
| 1070 dbus::MessageWriter builder(&method_call); | 1059 dbus::MessageWriter builder(&method_call); |
| 1071 builder.AppendInt32(handle); // handle | 1060 builder.AppendInt32(handle); // handle |
| 1072 builder.AppendString(folder_name_); // folder | 1061 builder.AppendString(folder_name_); // folder |
| 1073 builder.AppendString(app_name_); // appid | 1062 builder.AppendString(app_name_); // appid |
| 1074 scoped_ptr<dbus::Response> response( | 1063 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( |
| 1075 kwallet_proxy_->CallMethodAndBlock( | 1064 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 1076 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | |
| 1077 if (!response.get()) { | 1065 if (!response.get()) { |
| 1078 LOG(ERROR) << "Error contacting << " << kwalletd_name_ | 1066 LOG(ERROR) << "Error contacting << " << kwalletd_name_ |
| 1079 << " (createFolder)"; | 1067 << " (createFolder)"; |
| 1080 return kInvalidKWalletHandle; | 1068 return kInvalidKWalletHandle; |
| 1081 } | 1069 } |
| 1082 dbus::MessageReader reader(response.get()); | 1070 dbus::MessageReader reader(response.get()); |
| 1083 bool success = false; | 1071 bool success = false; |
| 1084 if (!reader.PopBool(&success)) { | 1072 if (!reader.PopBool(&success)) { |
| 1085 LOG(ERROR) << "Error reading response from " << kwalletd_name_ | 1073 LOG(ERROR) << "Error reading response from " << kwalletd_name_ |
| 1086 << " (createFolder): " << response->ToString(); | 1074 << " (createFolder): " << response->ToString(); |
| 1087 return kInvalidKWalletHandle; | 1075 return kInvalidKWalletHandle; |
| 1088 } | 1076 } |
| 1089 if (!success) { | 1077 if (!success) { |
| 1090 LOG(ERROR) << "Error creating KWallet folder"; | 1078 LOG(ERROR) << "Error creating KWallet folder"; |
| 1091 return kInvalidKWalletHandle; | 1079 return kInvalidKWalletHandle; |
| 1092 } | 1080 } |
| 1093 } | 1081 } |
| 1094 | 1082 |
| 1095 return handle; | 1083 return handle; |
| 1096 } | 1084 } |
| 1097 | 1085 |
| 1098 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { | 1086 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { |
| 1099 // Originally, the folder name was always just "Chrome Form Data". | 1087 // Originally, the folder name was always just "Chrome Form Data". |
| 1100 // Now we use it to distinguish passwords for different profiles. | 1088 // Now we use it to distinguish passwords for different profiles. |
| 1101 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); | 1089 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); |
| 1102 } | 1090 } |
| OLD | NEW |