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, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), | 406 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
408 user_hash, | 407 user_hash, |
409 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), | 408 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
410 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); | 409 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); |
411 } | 410 } |
412 | 411 |
413 // static | 412 // static |
414 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( | 413 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( |
415 const std::string& user_id, | 414 const std::string& user_id, |
416 const em::PolicyData* policy_data, | 415 const em::PolicyData* policy_data, |
417 const em::ChromeDeviceSettingsProto* settings) { | 416 em::ChromeDeviceSettingsProto* settings) { |
418 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); | 417 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); |
419 if (policy_data) { | 418 if (policy_data) { |
420 // Preserve management settings. | 419 // Preserve management settings. |
421 if (policy_data->has_management_mode()) | 420 if (policy_data->has_management_mode()) |
422 policy->set_management_mode(policy_data->management_mode()); | 421 policy->set_management_mode(policy_data->management_mode()); |
423 if (policy_data->has_request_token()) | 422 if (policy_data->has_request_token()) |
424 policy->set_request_token(policy_data->request_token()); | 423 policy->set_request_token(policy_data->request_token()); |
425 if (policy_data->has_device_id()) | 424 if (policy_data->has_device_id()) |
426 policy->set_device_id(policy_data->device_id()); | 425 policy->set_device_id(policy_data->device_id()); |
427 } else { | 426 } else { |
428 // If there's no previous policy data, this is the first time the device | 427 // 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. | 428 // setting is set. We set the management mode to LOCAL_OWNER initially. |
430 policy->set_management_mode(em::PolicyData::LOCAL_OWNER); | 429 policy->set_management_mode(em::PolicyData::LOCAL_OWNER); |
431 } | 430 } |
431 // Perform fixups required to ensure sensical local-owner device policy: | |
432 // 1) The owner must be in the username field, | |
433 // 2) user whitelisting must be explicitly allowed or disallowed, and | |
434 // 3) the owner user must be on the whitelist, if it's enforced. | |
435 // We can enforce the first two here, but need to check the whitelist before | |
436 // modifying it, so that will be taken care of in a separate class. | |
Mattias Nissler (ping if slow)
2015/03/18 08:36:42
stale comment
Chris Masone
2015/03/24 20:53:36
Done.
| |
437 if (policy->management_mode() == em::PolicyData::LOCAL_OWNER) | |
Mattias Nissler (ping if slow)
2015/03/18 08:36:41
I think you want to do this both for LOCAL_OWNER a
Chris Masone
2015/03/24 20:53:36
Done.
Chris Masone
2015/03/24 20:53:36
Done.
| |
438 FixupLocalOwnerPolicy(user_id, settings); | |
432 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); | 439 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); |
433 policy->set_timestamp( | 440 policy->set_timestamp( |
434 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); | 441 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
435 policy->set_username(user_id); | 442 policy->set_username(user_id); |
436 if (!settings->SerializeToString(policy->mutable_policy_value())) | 443 if (!settings->SerializeToString(policy->mutable_policy_value())) |
437 return scoped_ptr<em::PolicyData>(); | 444 return scoped_ptr<em::PolicyData>(); |
438 | 445 |
439 return policy.Pass(); | 446 return policy.Pass(); |
440 } | 447 } |
441 | 448 |
442 // static | 449 // static |
450 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy( | |
451 const std::string& user_id, | |
452 enterprise_management::ChromeDeviceSettingsProto* settings) { | |
453 if (!settings->has_allow_new_users()) | |
454 settings->mutable_allow_new_users()->set_allow_new_users(true); | |
455 | |
456 em::UserWhitelistProto* whitelist_proto = settings->mutable_user_whitelist(); | |
457 if (whitelist_proto->user_whitelist().end() == | |
458 std::find(whitelist_proto->user_whitelist().begin(), | |
459 whitelist_proto->user_whitelist().end(), user_id)) { | |
460 whitelist_proto->add_user_whitelist(user_id); | |
461 } | |
462 } | |
463 | |
464 // static | |
443 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings( | 465 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings( |
444 const std::string& path, | 466 const std::string& path, |
445 const base::Value& value, | 467 const base::Value& value, |
446 enterprise_management::ChromeDeviceSettingsProto& settings) { | 468 enterprise_management::ChromeDeviceSettingsProto& settings) { |
447 if (path == kAccountsPrefAllowNewUser) { | 469 if (path == kAccountsPrefAllowNewUser) { |
448 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users(); | 470 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users(); |
449 bool allow_value; | 471 bool allow_value; |
450 if (value.GetAsBoolean(&allow_value)) { | 472 if (value.GetAsBoolean(&allow_value)) { |
451 allow->set_allow_new_users(allow_value); | 473 allow->set_allow_new_users(allow_value); |
452 } else { | 474 } else { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 if (pending_management_settings_.request_token.empty()) | 748 if (pending_management_settings_.request_token.empty()) |
727 policy->clear_request_token(); | 749 policy->clear_request_token(); |
728 else | 750 else |
729 policy->set_request_token(pending_management_settings_.request_token); | 751 policy->set_request_token(pending_management_settings_.request_token); |
730 | 752 |
731 if (pending_management_settings_.device_id.empty()) | 753 if (pending_management_settings_.device_id.empty()) |
732 policy->clear_device_id(); | 754 policy->clear_device_id(); |
733 else | 755 else |
734 policy->set_device_id(pending_management_settings_.device_id); | 756 policy->set_device_id(pending_management_settings_.device_id); |
735 } | 757 } |
736 has_pending_management_settings_ = false; | 758 has_pending_management_settings_ = false; |
Mattias Nissler (ping if slow)
2015/03/18 08:36:41
I'd put the call to FixupLocalOwnerPolicy here, be
Chris Masone
2015/03/24 20:53:36
By this point, the policy is already assembled, so
| |
737 | 759 |
738 bool rv = AssembleAndSignPolicyAsync( | 760 bool rv = AssembleAndSignPolicyAsync( |
739 content::BrowserThread::GetBlockingPool(), policy.Pass(), | 761 content::BrowserThread::GetBlockingPool(), policy.Pass(), |
740 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned, | 762 base::Bind(&OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned, |
741 store_settings_factory_.GetWeakPtr())); | 763 store_settings_factory_.GetWeakPtr())); |
742 if (!rv) | 764 if (!rv) |
743 ReportStatusAndContinueStoring(false /* success */); | 765 ReportStatusAndContinueStoring(false /* success */); |
744 } | 766 } |
745 | 767 |
746 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned( | 768 void OwnerSettingsServiceChromeOS::OnPolicyAssembledAndSigned( |
(...skipping 25 matching lines...) Expand all Loading... | |
772 std::vector<OnManagementSettingsSetCallback> callbacks; | 794 std::vector<OnManagementSettingsSetCallback> callbacks; |
773 pending_management_settings_callbacks_.swap(callbacks); | 795 pending_management_settings_callbacks_.swap(callbacks); |
774 for (const auto& callback : callbacks) { | 796 for (const auto& callback : callbacks) { |
775 if (!callback.is_null()) | 797 if (!callback.is_null()) |
776 callback.Run(success); | 798 callback.Run(success); |
777 } | 799 } |
778 StorePendingChanges(); | 800 StorePendingChanges(); |
779 } | 801 } |
780 | 802 |
781 } // namespace chromeos | 803 } // namespace chromeos |
OLD | NEW |