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

Side by Side Diff: chrome/browser/chromeos/device_settings_provider.cc

Issue 9466005: Make sure the device recovers from policy loss in the consumer case. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT and cleaned up the unit tests. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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/chromeos/device_settings_provider.h" 5 #include "chrome/browser/chromeos/device_settings_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/cros/cros_library.h" 16 #include "chrome/browser/chromeos/cros/cros_library.h"
17 #include "chrome/browser/chromeos/cros/network_library.h" 17 #include "chrome/browser/chromeos/cros/network_library.h"
18 #include "chrome/browser/chromeos/cros_settings.h" 18 #include "chrome/browser/chromeos/cros_settings.h"
19 #include "chrome/browser/chromeos/cros_settings_names.h" 19 #include "chrome/browser/chromeos/cros_settings_names.h"
20 #include "chrome/browser/chromeos/login/ownership_service.h" 20 #include "chrome/browser/chromeos/login/ownership_service.h"
21 #include "chrome/browser/chromeos/login/signed_settings_cache.h" 21 #include "chrome/browser/chromeos/login/signed_settings_cache.h"
22 #include "chrome/browser/chromeos/login/signed_settings_helper.h" 22 #include "chrome/browser/chromeos/login/signed_settings_helper.h"
23 #include "chrome/browser/chromeos/login/user_manager.h" 23 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/browser/policy/app_pack_updater.h" 24 #include "chrome/browser/policy/app_pack_updater.h"
25 #include "chrome/browser/policy/browser_policy_connector.h"
26 #include "chrome/browser/policy/cloud_policy_constants.h"
25 #include "chrome/browser/ui/options/options_util.h" 27 #include "chrome/browser/ui/options/options_util.h"
26 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/installer/util/google_update_settings.h" 29 #include "chrome/installer/util/google_update_settings.h"
28 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
29 31
30 using google::protobuf::RepeatedPtrField; 32 using google::protobuf::RepeatedPtrField;
31 33
32 namespace em = enterprise_management; 34 namespace em = enterprise_management;
33 35
34 namespace chromeos { 36 namespace chromeos {
35 37
36 namespace { 38 namespace {
37 39
38 // List of settings handled by the DeviceSettingsProvider. 40 // List of settings handled by the DeviceSettingsProvider.
39 const char* kKnownSettings[] = { 41 const char* kKnownSettings[] = {
40 kAccountsPrefAllowGuest, 42 kAccountsPrefAllowGuest,
41 kAccountsPrefAllowNewUser, 43 kAccountsPrefAllowNewUser,
42 kAccountsPrefEphemeralUsersEnabled, 44 kAccountsPrefEphemeralUsersEnabled,
43 kAccountsPrefShowUserNamesOnSignIn, 45 kAccountsPrefShowUserNamesOnSignIn,
44 kAccountsPrefUsers, 46 kAccountsPrefUsers,
45 kAppPack, 47 kAppPack,
46 kDeviceOwner, 48 kDeviceOwner,
47 kIdleLogoutTimeout, 49 kIdleLogoutTimeout,
48 kIdleLogoutWarningDuration, 50 kIdleLogoutWarningDuration,
51 kPolicyMissingMitigationMode,
49 kReleaseChannel, 52 kReleaseChannel,
50 kReleaseChannelDelegated, 53 kReleaseChannelDelegated,
51 kReportDeviceActivityTimes, 54 kReportDeviceActivityTimes,
52 kReportDeviceBootMode, 55 kReportDeviceBootMode,
53 kReportDeviceVersionInfo, 56 kReportDeviceVersionInfo,
54 kScreenSaverExtensionId, 57 kScreenSaverExtensionId,
55 kScreenSaverTimeout, 58 kScreenSaverTimeout,
56 kSettingProxyEverywhere, 59 kSettingProxyEverywhere,
57 kSignedDataRoamingEnabled, 60 kSignedDataRoamingEnabled,
58 kStartUpUrls, 61 kStartUpUrls,
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 if (pol.has_metrics_enabled()) 600 if (pol.has_metrics_enabled())
598 ApplyMetricsSetting(false, pol.metrics_enabled().metrics_enabled()); 601 ApplyMetricsSetting(false, pol.metrics_enabled().metrics_enabled());
599 else 602 else
600 ApplyMetricsSetting(true, false); 603 ApplyMetricsSetting(true, false);
601 // Next set the roaming setting as needed. 604 // Next set the roaming setting as needed.
602 ApplyRoamingSetting(pol.has_data_roaming_enabled() ? 605 ApplyRoamingSetting(pol.has_data_roaming_enabled() ?
603 pol.data_roaming_enabled().data_roaming_enabled() : false); 606 pol.data_roaming_enabled().data_roaming_enabled() : false);
604 } 607 }
605 608
606 bool DeviceSettingsProvider::MitigateMissingPolicy() { 609 bool DeviceSettingsProvider::MitigateMissingPolicy() {
607 // As this code runs only in exceptional cases it's fine to allow I/O here. 610 // First check if the device has been owned already and if not exit
608 base::ThreadRestrictions::ScopedAllowIO allow_io; 611 // immediately.
609 FilePath legacy_policy_file(kLegacyPolicyFile); 612 if (g_browser_process->browser_policy_connector()->GetDeviceMode() !=
610 // Check if legacy file exists but is not writable to avoid possible 613 policy::DEVICE_MODE_CONSUMER) {
611 // attack of creating this file through chronos (although this should be 614 return false;
612 // not possible in root owned location), but better be safe than sorry.
613 // TODO(pastarmovj): Remove this workaround once we have proper checking
614 // for policy corruption or when Cr48 is phased out the very latest.
615 // See: http://crosbug.com/24916.
616 if (file_util::PathExists(legacy_policy_file) &&
617 !file_util::PathIsWritable(legacy_policy_file)) {
618 // We are in pre 11 dev upgrading to post 17 version mode.
619 LOG(ERROR) << "Detected system upgraded from ChromeOS 11 or older with "
620 << "missing policies. Switching to migration policy mode "
621 << "until the owner logs in to regenerate the policy data.";
622 // In this situation we should pretend we have policy even though we
623 // don't until the owner logs in and restores the policy blob.
624 values_cache_.SetBoolean(kAccountsPrefAllowNewUser, true);
625 values_cache_.SetBoolean(kAccountsPrefAllowGuest, true);
626 trusted_ = true;
627 // Make sure we will recreate the policy once the owner logs in.
628 // Any value not in this list will be left to the default which is fine as
629 // we repopulate the whitelist with the owner and any other possible every
630 // time the user enables whitelist filtering on the UI.
631 migration_helper_->AddMigrationValue(
632 kAccountsPrefAllowNewUser, base::Value::CreateBooleanValue(true));
633 migration_helper_->MigrateValues();
634 // The last step is to pretend we loaded policy correctly and call everyone.
635 for (size_t i = 0; i < callbacks_.size(); ++i)
636 callbacks_[i].Run();
637 callbacks_.clear();
638 return true;
639 } 615 }
640 return false; 616
617 // If we are here the policy file were corrupted or missing. This can happen
618 // because we are migrating Pre R11 device to the new secure policies or there
619 // was an attempt to circumvent policy system. In this case we should populate
620 // the policy cache with "safe-mode" defaults which should allow the owner to
621 // log in but lock the device for anyone else until the policy blob has been
622 // recreated by the session manager.
623 LOG(ERROR) << "Corruption of the policy data has been detected."
624 << "Switching to \"safe-mode\" policies until the owner logs in "
625 << "to regenerate the policy data.";
626 values_cache_.SetBoolean(kAccountsPrefAllowNewUser, true);
627 values_cache_.SetBoolean(kAccountsPrefAllowGuest, true);
628 values_cache_.SetBoolean(kPolicyMissingMitigationMode, true);
629 trusted_ = true;
630 // Make sure we will recreate the policy once the owner logs in.
631 // Any value not in this list will be left to the default which is fine as
632 // we repopulate the whitelist with the owner and all other existing users
633 // every time the owner enables whitelist filtering on the UI.
634 migration_helper_->AddMigrationValue(
635 kAccountsPrefAllowNewUser, base::Value::CreateBooleanValue(true));
636 migration_helper_->MigrateValues();
637 // The last step is to pretend we loaded policy correctly and call everyone.
638 for (size_t i = 0; i < callbacks_.size(); ++i)
639 callbacks_[i].Run();
640 callbacks_.clear();
641 return true;
641 } 642 }
642 643
643 const base::Value* DeviceSettingsProvider::Get(const std::string& path) const { 644 const base::Value* DeviceSettingsProvider::Get(const std::string& path) const {
644 if (IsControlledSetting(path)) { 645 if (IsControlledSetting(path)) {
645 const base::Value* value; 646 const base::Value* value;
646 if (values_cache_.GetValue(path, &value)) 647 if (values_cache_.GetValue(path, &value))
647 return value; 648 return value;
648 } else { 649 } else {
649 NOTREACHED() << "Trying to get non cros setting."; 650 NOTREACHED() << "Trying to get non cros setting.";
650 } 651 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 trusted_ = true; 702 trusted_ = true;
702 for (size_t i = 0; i < callbacks_.size(); ++i) 703 for (size_t i = 0; i < callbacks_.size(); ++i)
703 callbacks_[i].Run(); 704 callbacks_[i].Run();
704 callbacks_.clear(); 705 callbacks_.clear();
705 // TODO(pastarmovj): Make those side effects responsibility of the 706 // TODO(pastarmovj): Make those side effects responsibility of the
706 // respective subsystems. 707 // respective subsystems.
707 ApplySideEffects(); 708 ApplySideEffects();
708 break; 709 break;
709 } 710 }
710 case SignedSettings::NOT_FOUND: 711 case SignedSettings::NOT_FOUND:
711 // Verify if we don't have to mitigate pre Chrome 12 machine here and if
712 // needed do the magic.
713 if (MitigateMissingPolicy()) 712 if (MitigateMissingPolicy())
714 break; 713 break;
715 case SignedSettings::KEY_UNAVAILABLE: { 714 case SignedSettings::KEY_UNAVAILABLE: {
716 if (ownership_status_ != OwnershipService::OWNERSHIP_TAKEN) 715 if (ownership_status_ != OwnershipService::OWNERSHIP_TAKEN)
717 NOTREACHED() << "No policies present yet, will use the temp storage."; 716 NOTREACHED() << "No policies present yet, will use the temp storage.";
718 break; 717 break;
719 } 718 }
720 case SignedSettings::BAD_SIGNATURE: 719 case SignedSettings::BAD_SIGNATURE:
721 case SignedSettings::OPERATION_FAILED: { 720 case SignedSettings::OPERATION_FAILED: {
722 LOG(ERROR) << "Failed to retrieve cros policies. Reason:" << code; 721 LOG(ERROR) << "Failed to retrieve cros policies. Reason:" << code;
723 if (retries_left_ > 0) { 722 if (retries_left_ > 0) {
724 retries_left_ -= 1; 723 retries_left_ -= 1;
725 Reload(); 724 Reload();
726 return; 725 return;
727 } 726 }
728 LOG(ERROR) << "No retries left"; 727 LOG(ERROR) << "No retries left";
729 break; 728 break;
730 } 729 }
731 } 730 }
732 } 731 }
733 732
734 } // namespace chromeos 733 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/mock_cryptohome_client.h ('k') | chrome/browser/chromeos/login/existing_user_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698