OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/policy/device_policy_cache.h" | 5 #include "chrome/browser/policy/device_policy_cache.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/chromeos/cros_settings_names.h" | 12 #include "chrome/browser/chromeos/cros_settings_names.h" |
13 #include "chrome/browser/chromeos/login/ownership_service.h" | 13 #include "chrome/browser/chromeos/login/ownership_service.h" |
14 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | 14 #include "chrome/browser/chromeos/login/signed_settings_helper.h" |
15 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 15 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
16 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 16 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
17 #include "chrome/browser/policy/device_policy_identity_strategy.h" | 17 #include "chrome/browser/policy/device_policy_identity_strategy.h" |
18 #include "chrome/browser/policy/enterprise_install_attributes.h" | |
18 #include "chrome/browser/policy/policy_map.h" | 19 #include "chrome/browser/policy/policy_map.h" |
19 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 20 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
20 #include "chrome/browser/policy/proto/device_management_constants.h" | 21 #include "chrome/browser/policy/proto/device_management_constants.h" |
21 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 22 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
22 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
23 #include "policy/configuration_policy_type.h" | 24 #include "policy/configuration_policy_type.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Stores policy, updates the owner key if required and reports the status | 28 // Stores policy, updates the owner key if required and reports the status |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 } | 103 } |
103 | 104 |
104 return Value::CreateIntegerValue(static_cast<int>(value)); | 105 return Value::CreateIntegerValue(static_cast<int>(value)); |
105 } | 106 } |
106 | 107 |
107 } // namespace | 108 } // namespace |
108 | 109 |
109 namespace policy { | 110 namespace policy { |
110 | 111 |
111 DevicePolicyCache::DevicePolicyCache( | 112 DevicePolicyCache::DevicePolicyCache( |
112 DevicePolicyIdentityStrategy* identity_strategy) | 113 DevicePolicyIdentityStrategy* identity_strategy, |
114 EnterpriseInstallAttributes* install_attributes) | |
113 : identity_strategy_(identity_strategy), | 115 : identity_strategy_(identity_strategy), |
116 install_attributes_(install_attributes), | |
114 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), | 117 signed_settings_helper_(chromeos::SignedSettingsHelper::Get()), |
115 starting_up_(true), | 118 starting_up_(true), |
116 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 119 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
120 // Do an opportunistic check with immutable attributes at startup. | |
121 install_attributes_->IsEnterpriseDevice(); | |
pastarmovj
2011/04/17 15:20:46
I can imagine this will fail most of the time unti
Mattias Nissler (ping if slow)
2011/04/18 09:56:35
I guess it's not worth the effort, let's just drop
| |
117 } | 122 } |
118 | 123 |
119 DevicePolicyCache::DevicePolicyCache( | 124 DevicePolicyCache::DevicePolicyCache( |
120 DevicePolicyIdentityStrategy* identity_strategy, | 125 DevicePolicyIdentityStrategy* identity_strategy, |
126 EnterpriseInstallAttributes* install_attributes, | |
121 chromeos::SignedSettingsHelper* signed_settings_helper) | 127 chromeos::SignedSettingsHelper* signed_settings_helper) |
122 : identity_strategy_(identity_strategy), | 128 : identity_strategy_(identity_strategy), |
129 install_attributes_(install_attributes), | |
123 signed_settings_helper_(signed_settings_helper), | 130 signed_settings_helper_(signed_settings_helper), |
124 starting_up_(true), | 131 starting_up_(true), |
125 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 132 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
126 } | 133 } |
127 | 134 |
128 DevicePolicyCache::~DevicePolicyCache() { | 135 DevicePolicyCache::~DevicePolicyCache() { |
129 signed_settings_helper_->CancelCallback(this); | 136 signed_settings_helper_->CancelCallback(this); |
130 } | 137 } |
131 | 138 |
132 void DevicePolicyCache::Load() { | 139 void DevicePolicyCache::Load() { |
133 signed_settings_helper_->StartRetrievePolicyOp(this); | 140 signed_settings_helper_->StartRetrievePolicyOp(this); |
134 } | 141 } |
135 | 142 |
136 void DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { | 143 void DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { |
137 DCHECK(!starting_up_); | 144 DCHECK(!starting_up_); |
145 | |
146 // Make sure we have an enterprise device. | |
147 std::string registration_user(install_attributes_->GetRegistrationUser()); | |
148 if (registration_user.empty()) { | |
149 LOG(WARNING) << "Refusing to accept policy on non-enterprise device."; | |
150 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | |
151 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | |
152 return; | |
153 } | |
154 | |
155 // Check the user this policy is for against the device-locked name. | |
156 em::PolicyData policy_data; | |
157 if (!policy_data.ParseFromString(policy.policy_data())) { | |
158 LOG(WARNING) << "Invalid policy protobuf"; | |
159 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | |
160 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | |
161 return; | |
162 } | |
163 | |
164 if (registration_user != policy_data.username()) { | |
165 LOG(WARNING) << "Refusing policy blob for " << policy_data.username() | |
166 << " which doesn't match " << registration_user; | |
167 InformNotifier(CloudPolicySubsystem::LOCAL_ERROR, | |
168 CloudPolicySubsystem::POLICY_LOCAL_ERROR); | |
169 return; | |
170 } | |
171 | |
138 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); | 172 set_last_policy_refresh_time(base::Time::NowFromSystemTime()); |
139 | 173 |
140 // Start a store operation. | 174 // Start a store operation. |
141 new StorePolicyOperation(signed_settings_helper_, | 175 new StorePolicyOperation(signed_settings_helper_, |
142 policy, | 176 policy, |
143 callback_factory_.NewCallback( | 177 callback_factory_.NewCallback( |
144 &DevicePolicyCache::PolicyStoreOpCompleted)); | 178 &DevicePolicyCache::PolicyStoreOpCompleted)); |
145 } | 179 } |
146 | 180 |
147 void DevicePolicyCache::SetUnmanaged() { | 181 void DevicePolicyCache::SetUnmanaged() { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 const em::DevicePolicyRefreshRateProto container = | 275 const em::DevicePolicyRefreshRateProto container = |
242 policy.policy_refresh_rate(); | 276 policy.policy_refresh_rate(); |
243 if (container.has_policy_refresh_rate()) { | 277 if (container.has_policy_refresh_rate()) { |
244 mandatory->Set(kPolicyPolicyRefreshRate, | 278 mandatory->Set(kPolicyPolicyRefreshRate, |
245 DecodeIntegerValue(container.policy_refresh_rate())); | 279 DecodeIntegerValue(container.policy_refresh_rate())); |
246 } | 280 } |
247 } | 281 } |
248 } | 282 } |
249 | 283 |
250 } // namespace policy | 284 } // namespace policy |
OLD | NEW |