| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/ownership/owner_settings_service_chromeos.h" | 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 7 #include <string> | 8 #include <string> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 17 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chrome/browser/chromeos/settings/device_settings_provider.h" | 20 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
| 21 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 21 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
| 24 #include "chromeos/tpm/tpm_token_loader.h" | 24 #include "chromeos/tpm/tpm_token_loader.h" |
| 25 #include "components/ownership/owner_key_util.h" | 25 #include "components/ownership/owner_key_util.h" |
| 26 #include "components/user_manager/user.h" | 26 #include "components/user_manager/user.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return false; | 167 return false; |
| 168 | 168 |
| 169 case policy::MANAGEMENT_MODE_CONSUMER_MANAGED: | 169 case policy::MANAGEMENT_MODE_CONSUMER_MANAGED: |
| 170 // For consumer management unenrollment. | 170 // For consumer management unenrollment. |
| 171 return new_mode == policy::MANAGEMENT_MODE_LOCAL_OWNER; | 171 return new_mode == policy::MANAGEMENT_MODE_LOCAL_OWNER; |
| 172 } | 172 } |
| 173 | 173 |
| 174 NOTREACHED(); | 174 NOTREACHED(); |
| 175 return false; | 175 return false; |
| 176 } | 176 } |
| 177 | |
| 178 } // namespace | 177 } // namespace |
| 179 | 178 |
| 180 OwnerSettingsServiceChromeOS::ManagementSettings::ManagementSettings() { | 179 OwnerSettingsServiceChromeOS::ManagementSettings::ManagementSettings() { |
| 181 } | 180 } |
| 182 | 181 |
| 183 OwnerSettingsServiceChromeOS::ManagementSettings::~ManagementSettings() { | 182 OwnerSettingsServiceChromeOS::ManagementSettings::~ManagementSettings() { |
| 184 } | 183 } |
| 185 | 184 |
| 186 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( | 185 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( |
| 187 DeviceSettingsService* device_settings_service, | 186 DeviceSettingsService* device_settings_service, |
| 188 Profile* profile, | 187 Profile* profile, |
| 189 const scoped_refptr<OwnerKeyUtil>& owner_key_util) | 188 const scoped_refptr<OwnerKeyUtil>& owner_key_util) |
| 190 : ownership::OwnerSettingsService(owner_key_util), | 189 : ownership::OwnerSettingsService(owner_key_util), |
| 191 device_settings_service_(device_settings_service), | 190 device_settings_service_(device_settings_service), |
| 192 profile_(profile), | 191 profile_(profile), |
| 193 waiting_for_profile_creation_(true), | 192 waiting_for_profile_creation_(true), |
| 194 waiting_for_tpm_token_(true), | 193 waiting_for_tpm_token_(true), |
| 194 has_pending_fixups_(false), |
| 195 has_pending_management_settings_(false), | 195 has_pending_management_settings_(false), |
| 196 weak_factory_(this), | 196 weak_factory_(this), |
| 197 store_settings_factory_(this) { | 197 store_settings_factory_(this) { |
| 198 if (TPMTokenLoader::IsInitialized()) { | 198 if (TPMTokenLoader::IsInitialized()) { |
| 199 TPMTokenLoader::TPMTokenStatus tpm_token_status = | 199 TPMTokenLoader::TPMTokenStatus tpm_token_status = |
| 200 TPMTokenLoader::Get()->IsTPMTokenEnabled( | 200 TPMTokenLoader::Get()->IsTPMTokenEnabled( |
| 201 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, | 201 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, |
| 202 weak_factory_.GetWeakPtr())); | 202 weak_factory_.GetWeakPtr())); |
| 203 waiting_for_tpm_token_ = | 203 waiting_for_tpm_token_ = |
| 204 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED; | 204 tpm_token_status == TPMTokenLoader::TPM_TOKEN_STATUS_UNDETERMINED; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), | 407 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
| 408 user_hash, | 408 user_hash, |
| 409 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), | 409 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
| 410 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); | 410 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); |
| 411 } | 411 } |
| 412 | 412 |
| 413 // static | 413 // static |
| 414 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( | 414 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( |
| 415 const std::string& user_id, | 415 const std::string& user_id, |
| 416 const em::PolicyData* policy_data, | 416 const em::PolicyData* policy_data, |
| 417 const em::ChromeDeviceSettingsProto* settings) { | 417 bool apply_pending_management_settings, |
| 418 const ManagementSettings& pending_management_settings, |
| 419 em::ChromeDeviceSettingsProto* settings) { |
| 418 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); | 420 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); |
| 419 if (policy_data) { | 421 if (policy_data) { |
| 420 // Preserve management settings. | 422 // Preserve management settings. |
| 421 if (policy_data->has_management_mode()) | 423 if (policy_data->has_management_mode()) |
| 422 policy->set_management_mode(policy_data->management_mode()); | 424 policy->set_management_mode(policy_data->management_mode()); |
| 423 if (policy_data->has_request_token()) | 425 if (policy_data->has_request_token()) |
| 424 policy->set_request_token(policy_data->request_token()); | 426 policy->set_request_token(policy_data->request_token()); |
| 425 if (policy_data->has_device_id()) | 427 if (policy_data->has_device_id()) |
| 426 policy->set_device_id(policy_data->device_id()); | 428 policy->set_device_id(policy_data->device_id()); |
| 427 } else { | 429 } else { |
| 428 // If there's no previous policy data, this is the first time the device | 430 // If there's no previous policy data, this is the first time the device |
| 429 // setting is set. We set the management mode to LOCAL_OWNER initially. | 431 // setting is set. We set the management mode to LOCAL_OWNER initially. |
| 430 policy->set_management_mode(em::PolicyData::LOCAL_OWNER); | 432 policy->set_management_mode(em::PolicyData::LOCAL_OWNER); |
| 431 } | 433 } |
| 434 if (apply_pending_management_settings) { |
| 435 policy::SetManagementMode(*policy, |
| 436 pending_management_settings.management_mode); |
| 437 |
| 438 if (pending_management_settings.request_token.empty()) |
| 439 policy->clear_request_token(); |
| 440 else |
| 441 policy->set_request_token(pending_management_settings.request_token); |
| 442 |
| 443 if (pending_management_settings.device_id.empty()) |
| 444 policy->clear_device_id(); |
| 445 else |
| 446 policy->set_device_id(pending_management_settings.device_id); |
| 447 } |
| 432 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); | 448 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); |
| 433 policy->set_timestamp( | 449 policy->set_timestamp( |
| 434 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); | 450 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
| 435 policy->set_username(user_id); | 451 policy->set_username(user_id); |
| 452 if (policy_data->management_mode() == em::PolicyData::LOCAL_OWNER || |
| 453 policy_data->management_mode() == em::PolicyData::CONSUMER_MANAGED) { |
| 454 FixupLocalOwnerPolicy(user_id, settings); |
| 455 } |
| 436 if (!settings->SerializeToString(policy->mutable_policy_value())) | 456 if (!settings->SerializeToString(policy->mutable_policy_value())) |
| 437 return scoped_ptr<em::PolicyData>(); | 457 return scoped_ptr<em::PolicyData>(); |
| 438 | 458 |
| 439 return policy.Pass(); | 459 return policy.Pass(); |
| 440 } | 460 } |
| 441 | 461 |
| 442 // static | 462 // static |
| 463 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy( |
| 464 const std::string& user_id, |
| 465 enterprise_management::ChromeDeviceSettingsProto* settings) { |
| 466 if (!settings->has_allow_new_users()) |
| 467 settings->mutable_allow_new_users()->set_allow_new_users(true); |
| 468 |
| 469 em::UserWhitelistProto* whitelist_proto = settings->mutable_user_whitelist(); |
| 470 if (whitelist_proto->user_whitelist().end() == |
| 471 std::find(whitelist_proto->user_whitelist().begin(), |
| 472 whitelist_proto->user_whitelist().end(), user_id)) { |
| 473 whitelist_proto->add_user_whitelist(user_id); |
| 474 } |
| 475 } |
| 476 |
| 477 // static |
| 443 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings( | 478 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings( |
| 444 const std::string& path, | 479 const std::string& path, |
| 445 const base::Value& value, | 480 const base::Value& value, |
| 446 enterprise_management::ChromeDeviceSettingsProto& settings) { | 481 enterprise_management::ChromeDeviceSettingsProto& settings) { |
| 447 if (path == kAccountsPrefAllowNewUser) { | 482 if (path == kAccountsPrefAllowNewUser) { |
| 448 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users(); | 483 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users(); |
| 449 bool allow_value; | 484 bool allow_value; |
| 450 if (value.GetAsBoolean(&allow_value)) { | 485 if (value.GetAsBoolean(&allow_value)) { |
| 451 allow->set_allow_new_users(allow_value); | 486 allow->set_allow_new_users(allow_value); |
| 452 } else { | 487 } else { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { | 702 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { |
| 668 DCHECK(thread_checker_.CalledOnValidThread()); | 703 DCHECK(thread_checker_.CalledOnValidThread()); |
| 669 | 704 |
| 670 const user_manager::User* user = | 705 const user_manager::User* user = |
| 671 ProfileHelper::Get()->GetUserByProfile(profile_); | 706 ProfileHelper::Get()->GetUserByProfile(profile_); |
| 672 user_id_ = user ? user->GetUserID() : std::string(); | 707 user_id_ = user ? user->GetUserID() : std::string(); |
| 673 | 708 |
| 674 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); | 709 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); |
| 675 if (is_owner && device_settings_service_) | 710 if (is_owner && device_settings_service_) |
| 676 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); | 711 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); |
| 712 |
| 713 has_pending_fixups_ = true; |
| 677 } | 714 } |
| 678 | 715 |
| 679 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< | 716 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< |
| 680 void(const scoped_refptr<PublicKey>& public_key, | 717 void(const scoped_refptr<PublicKey>& public_key, |
| 681 const scoped_refptr<PrivateKey>& private_key)>& callback) { | 718 const scoped_refptr<PrivateKey>& private_key)>& callback) { |
| 682 DCHECK(thread_checker_.CalledOnValidThread()); | 719 DCHECK(thread_checker_.CalledOnValidThread()); |
| 683 | 720 |
| 684 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) | 721 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) |
| 685 return; | 722 return; |
| 686 scoped_refptr<base::TaskRunner> task_runner = | 723 scoped_refptr<base::TaskRunner> task_runner = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 709 device_settings_service_->device_settings()) { | 746 device_settings_service_->device_settings()) { |
| 710 settings = *device_settings_service_->device_settings(); | 747 settings = *device_settings_service_->device_settings(); |
| 711 } else { | 748 } else { |
| 712 return; | 749 return; |
| 713 } | 750 } |
| 714 | 751 |
| 715 for (const auto& change : pending_changes_) | 752 for (const auto& change : pending_changes_) |
| 716 UpdateDeviceSettings(change.first, *change.second, settings); | 753 UpdateDeviceSettings(change.first, *change.second, settings); |
| 717 pending_changes_.clear(); | 754 pending_changes_.clear(); |
| 718 | 755 |
| 719 scoped_ptr<em::PolicyData> policy = AssemblePolicy( | 756 scoped_ptr<em::PolicyData> policy = |
| 720 user_id_, device_settings_service_->policy_data(), &settings); | 757 AssemblePolicy(user_id_, device_settings_service_->policy_data(), |
| 721 | 758 has_pending_management_settings_, |
| 722 if (has_pending_management_settings_) { | 759 pending_management_settings_, &settings); |
| 723 policy::SetManagementMode(*policy, | 760 has_pending_fixups_ = false; |
| 724 pending_management_settings_.management_mode); | |
| 725 | |
| 726 if (pending_management_settings_.request_token.empty()) | |
| 727 policy->clear_request_token(); | |
| 728 else | |
| 729 policy->set_request_token(pending_management_settings_.request_token); | |
| 730 | |
| 731 if (pending_management_settings_.device_id.empty()) | |
| 732 policy->clear_device_id(); | |
| 733 else | |
| 734 policy->set_device_id(pending_management_settings_.device_id); | |
| 735 } | |
| 736 has_pending_management_settings_ = false; | 761 has_pending_management_settings_ = false; |
| 737 | 762 |
| 738 bool rv = AssembleAndSignPolicyAsync( | 763 bool rv = AssembleAndSignPolicyAsync( |
| 739 content::BrowserThread::GetBlockingPool(), policy.Pass(), | 764 content::BrowserThread::GetBlockingPool(), policy.Pass(), |
| 740 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned, | 765 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned, |
| 741 store_settings_factory_.GetWeakPtr())); | 766 store_settings_factory_.GetWeakPtr())); |
| 742 if (!rv) | 767 if (!rv) |
| 743 ReportStatusAndContinueStoring(false /* success */); | 768 ReportStatusAndContinueStoring(false /* success */); |
| 744 } | 769 } |
| 745 | 770 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 772 std::vector<OnManagementSettingsSetCallback> callbacks; | 797 std::vector<OnManagementSettingsSetCallback> callbacks; |
| 773 pending_management_settings_callbacks_.swap(callbacks); | 798 pending_management_settings_callbacks_.swap(callbacks); |
| 774 for (const auto& callback : callbacks) { | 799 for (const auto& callback : callbacks) { |
| 775 if (!callback.is_null()) | 800 if (!callback.is_null()) |
| 776 callback.Run(success); | 801 callback.Run(success); |
| 777 } | 802 } |
| 778 StorePendingChanges(); | 803 StorePendingChanges(); |
| 779 } | 804 } |
| 780 | 805 |
| 781 } // namespace chromeos | 806 } // namespace chromeos |
| OLD | NEW |