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

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 on ToT and cleaned up comments and unrelated changes. 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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (pol.has_metrics_enabled()) 598 if (pol.has_metrics_enabled())
596 ApplyMetricsSetting(false, pol.metrics_enabled().metrics_enabled()); 599 ApplyMetricsSetting(false, pol.metrics_enabled().metrics_enabled());
597 else 600 else
598 ApplyMetricsSetting(true, false); 601 ApplyMetricsSetting(true, false);
599 // Next set the roaming setting as needed. 602 // Next set the roaming setting as needed.
600 ApplyRoamingSetting(pol.has_data_roaming_enabled() ? 603 ApplyRoamingSetting(pol.has_data_roaming_enabled() ?
601 pol.data_roaming_enabled().data_roaming_enabled() : false); 604 pol.data_roaming_enabled().data_roaming_enabled() : false);
602 } 605 }
603 606
604 bool DeviceSettingsProvider::MitigateMissingPolicy() { 607 bool DeviceSettingsProvider::MitigateMissingPolicy() {
605 // As this code runs only in exceptional cases it's fine to allow I/O here. 608 // First check if the device has been owned already and if not exit
606 base::ThreadRestrictions::ScopedAllowIO allow_io; 609 // immediately.
607 FilePath legacy_policy_file(kLegacyPolicyFile); 610 if (g_browser_process->browser_policy_connector()->GetDeviceMode() !=
608 // Check if legacy file exists but is not writable to avoid possible 611 policy::DEVICE_MODE_CONSUMER) {
609 // attack of creating this file through chronos (although this should be 612 return false;
610 // not possible in root owned location), but better be safe than sorry.
611 // TODO(pastarmovj): Remove this workaround once we have proper checking
612 // for policy corruption or when Cr48 is phased out the very latest.
613 // See: http://crosbug.com/24916.
614 if (file_util::PathExists(legacy_policy_file) &&
615 !file_util::PathIsWritable(legacy_policy_file)) {
616 // We are in pre 11 dev upgrading to post 17 version mode.
617 LOG(ERROR) << "Detected system upgraded from ChromeOS 11 or older with "
618 << "missing policies. Switching to migration policy mode "
619 << "until the owner logs in to regenerate the policy data.";
620 // In this situation we should pretend we have policy even though we
621 // don't until the owner logs in and restores the policy blob.
622 values_cache_.SetBoolean(kAccountsPrefAllowNewUser, true);
623 values_cache_.SetBoolean(kAccountsPrefAllowGuest, true);
624 trusted_ = true;
625 // Make sure we will recreate the policy once the owner logs in.
626 // Any value not in this list will be left to the default which is fine as
627 // we repopulate the whitelist with the owner and any other possible every
628 // time the user enables whitelist filtering on the UI.
629 migration_helper_->AddMigrationValue(
630 kAccountsPrefAllowNewUser, base::Value::CreateBooleanValue(true));
631 migration_helper_->MigrateValues();
632 // The last step is to pretend we loaded policy correctly and call everyone.
633 for (size_t i = 0; i < callbacks_.size(); ++i)
634 callbacks_[i].Run();
635 callbacks_.clear();
636 return true;
637 } 613 }
638 return false; 614
615 // If we are here the policy file were corrupted or missing. This can happen
616 // because we are migrating Pre R11 device to the new secure policies or there
617 // was an attempt to circumvent policy system. In this case we should populate
618 // the policy cache with "safe-mode" defaults which should allow the owner to
619 // log in but lock the device for anyone else until the policy blob has been
620 // recreated by the session manager.
621 LOG(ERROR) << "Corruption of the policy data has been detected."
622 << "Switching to \"safe-mode\" policies until the owner logs in "
623 << "to regenerate the policy data.";
624 values_cache_.SetBoolean(kAccountsPrefAllowNewUser, true);
625 values_cache_.SetBoolean(kAccountsPrefAllowGuest, true);
626 values_cache_.SetBoolean(kPolicyMissingMitigationMode, true);
627 trusted_ = true;
628 // Make sure we will recreate the policy once the owner logs in.
629 // Any value not in this list will be left to the default which is fine as
630 // we repopulate the whitelist with the owner and all other existing users
631 // every time the owner enables whitelist filtering on the UI.
632 migration_helper_->AddMigrationValue(
633 kAccountsPrefAllowNewUser, base::Value::CreateBooleanValue(true));
634 migration_helper_->MigrateValues();
635 // The last step is to pretend we loaded policy correctly and call everyone.
636 for (size_t i = 0; i < callbacks_.size(); ++i)
637 callbacks_[i].Run();
638 callbacks_.clear();
639 return true;
639 } 640 }
640 641
641 const base::Value* DeviceSettingsProvider::Get(const std::string& path) const { 642 const base::Value* DeviceSettingsProvider::Get(const std::string& path) const {
642 if (IsControlledSetting(path)) { 643 if (IsControlledSetting(path)) {
643 const base::Value* value; 644 const base::Value* value;
644 if (values_cache_.GetValue(path, &value)) 645 if (values_cache_.GetValue(path, &value))
645 return value; 646 return value;
646 } else { 647 } else {
647 NOTREACHED() << "Trying to get non cros setting."; 648 NOTREACHED() << "Trying to get non cros setting.";
648 } 649 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 trusted_ = true; 700 trusted_ = true;
700 for (size_t i = 0; i < callbacks_.size(); ++i) 701 for (size_t i = 0; i < callbacks_.size(); ++i)
701 callbacks_[i].Run(); 702 callbacks_[i].Run();
702 callbacks_.clear(); 703 callbacks_.clear();
703 // TODO(pastarmovj): Make those side effects responsibility of the 704 // TODO(pastarmovj): Make those side effects responsibility of the
704 // respective subsystems. 705 // respective subsystems.
705 ApplySideEffects(); 706 ApplySideEffects();
706 break; 707 break;
707 } 708 }
708 case SignedSettings::NOT_FOUND: 709 case SignedSettings::NOT_FOUND:
709 // Verify if we don't have to mitigate pre Chrome 12 machine here and if
710 // needed do the magic.
711 if (MitigateMissingPolicy()) 710 if (MitigateMissingPolicy())
712 break; 711 break;
713 case SignedSettings::KEY_UNAVAILABLE: { 712 case SignedSettings::KEY_UNAVAILABLE: {
714 if (ownership_status_ != OwnershipService::OWNERSHIP_TAKEN) 713 if (ownership_status_ != OwnershipService::OWNERSHIP_TAKEN)
715 NOTREACHED() << "No policies present yet, will use the temp storage."; 714 NOTREACHED() << "No policies present yet, will use the temp storage.";
716 break; 715 break;
717 } 716 }
718 case SignedSettings::BAD_SIGNATURE: 717 case SignedSettings::BAD_SIGNATURE:
719 case SignedSettings::OPERATION_FAILED: { 718 case SignedSettings::OPERATION_FAILED: {
720 LOG(ERROR) << "Failed to retrieve cros policies. Reason:" << code; 719 LOG(ERROR) << "Failed to retrieve cros policies. Reason:" << code;
721 if (retries_left_ > 0) { 720 if (retries_left_ > 0) {
722 retries_left_ -= 1; 721 retries_left_ -= 1;
723 Reload(); 722 Reload();
724 return; 723 return;
725 } 724 }
726 LOG(ERROR) << "No retries left"; 725 LOG(ERROR) << "No retries left";
727 break; 726 break;
728 } 727 }
729 } 728 }
730 } 729 }
731 730
732 } // namespace chromeos 731 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698