| OLD | NEW |
| 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/policy/policy_loader_win.h" | 5 #include "chrome/browser/policy/policy_loader_win.h" |
| 6 | 6 |
| 7 #include <rpc.h> // For struct GUID | 7 #include <rpc.h> // For struct GUID |
| 8 #include <shlwapi.h> // For PathIsUNC() | 8 #include <shlwapi.h> // For PathIsUNC() |
| 9 #include <userenv.h> // For GPO functions | 9 #include <userenv.h> // For GPO functions |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/sequenced_task_runner.h" | 26 #include "base/sequenced_task_runner.h" |
| 27 #include "base/stl_util.h" | 27 #include "base/stl_util.h" |
| 28 #include "base/strings/string16.h" | 28 #include "base/strings/string16.h" |
| 29 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
| 30 #include "chrome/browser/policy/policy_bundle.h" | 30 #include "chrome/browser/policy/policy_bundle.h" |
| 31 #include "chrome/browser/policy/policy_load_status.h" | 31 #include "chrome/browser/policy/policy_load_status.h" |
| 32 #include "chrome/browser/policy/policy_map.h" | 32 #include "chrome/browser/policy/policy_map.h" |
| 33 #include "chrome/browser/policy/preg_parser_win.h" | 33 #include "chrome/browser/policy/preg_parser_win.h" |
| 34 #include "chrome/browser/policy/registry_dict_win.h" | 34 #include "chrome/browser/policy/registry_dict_win.h" |
| 35 #include "components/json_schema/json_schema_constants.h" | 35 #include "components/json_schema/json_schema_constants.h" |
| 36 #include "policy/policy_constants.h" | 36 #include "components/policy/core/common/policy_namespace.h" |
| 37 #include "components/policy/core/common/schema.h" |
| 37 | 38 |
| 38 namespace schema = json_schema_constants; | 39 namespace schema = json_schema_constants; |
| 39 | 40 |
| 40 namespace policy { | 41 namespace policy { |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 const char kKeyMandatory[] = "policy"; | 45 const char kKeyMandatory[] = "policy"; |
| 45 const char kKeyRecommended[] = "recommended"; | 46 const char kKeyRecommended[] = "recommended"; |
| 46 const char kKeySchema[] = "schema"; | 47 const char kKeySchema[] = "schema"; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 policy->LoadFrom(policy_dict, level, scope); | 204 policy->LoadFrom(policy_dict, level, scope); |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace | 207 } // namespace |
| 207 | 208 |
| 208 const base::FilePath::CharType PolicyLoaderWin::kPRegFileName[] = | 209 const base::FilePath::CharType PolicyLoaderWin::kPRegFileName[] = |
| 209 FILE_PATH_LITERAL("Registry.pol"); | 210 FILE_PATH_LITERAL("Registry.pol"); |
| 210 | 211 |
| 211 PolicyLoaderWin::PolicyLoaderWin( | 212 PolicyLoaderWin::PolicyLoaderWin( |
| 212 scoped_refptr<base::SequencedTaskRunner> task_runner, | 213 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 213 const PolicyDefinitionList* policy_list, | |
| 214 const string16& chrome_policy_key, | 214 const string16& chrome_policy_key, |
| 215 AppliedGPOListProvider* gpo_provider) | 215 AppliedGPOListProvider* gpo_provider) |
| 216 : AsyncPolicyLoader(task_runner), | 216 : AsyncPolicyLoader(task_runner), |
| 217 is_initialized_(false), | 217 is_initialized_(false), |
| 218 policy_list_(policy_list), | |
| 219 chrome_policy_key_(chrome_policy_key), | 218 chrome_policy_key_(chrome_policy_key), |
| 220 gpo_provider_(gpo_provider), | 219 gpo_provider_(gpo_provider), |
| 221 user_policy_changed_event_(false, false), | 220 user_policy_changed_event_(false, false), |
| 222 machine_policy_changed_event_(false, false), | 221 machine_policy_changed_event_(false, false), |
| 223 user_policy_watcher_failed_(false), | 222 user_policy_watcher_failed_(false), |
| 224 machine_policy_watcher_failed_(false) { | 223 machine_policy_watcher_failed_(false) { |
| 225 if (!::RegisterGPNotification(user_policy_changed_event_.handle(), false)) { | 224 if (!::RegisterGPNotification(user_policy_changed_event_.handle(), false)) { |
| 226 DPLOG(WARNING) << "Failed to register user group policy notification"; | 225 DPLOG(WARNING) << "Failed to register user group policy notification"; |
| 227 user_policy_watcher_failed_ = true; | 226 user_policy_watcher_failed_ = true; |
| 228 } | 227 } |
| 229 if (!::RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { | 228 if (!::RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { |
| 230 DPLOG(WARNING) << "Failed to register machine group policy notification."; | 229 DPLOG(WARNING) << "Failed to register machine group policy notification."; |
| 231 machine_policy_watcher_failed_ = true; | 230 machine_policy_watcher_failed_ = true; |
| 232 } | 231 } |
| 233 } | 232 } |
| 234 | 233 |
| 235 PolicyLoaderWin::~PolicyLoaderWin() { | 234 PolicyLoaderWin::~PolicyLoaderWin() { |
| 236 if (!user_policy_watcher_failed_) { | 235 if (!user_policy_watcher_failed_) { |
| 237 ::UnregisterGPNotification(user_policy_changed_event_.handle()); | 236 ::UnregisterGPNotification(user_policy_changed_event_.handle()); |
| 238 user_policy_watcher_.StopWatching(); | 237 user_policy_watcher_.StopWatching(); |
| 239 } | 238 } |
| 240 if (!machine_policy_watcher_failed_) { | 239 if (!machine_policy_watcher_failed_) { |
| 241 ::UnregisterGPNotification(machine_policy_changed_event_.handle()); | 240 ::UnregisterGPNotification(machine_policy_changed_event_.handle()); |
| 242 machine_policy_watcher_.StopWatching(); | 241 machine_policy_watcher_.StopWatching(); |
| 243 } | 242 } |
| 244 } | 243 } |
| 245 | 244 |
| 246 // static | 245 // static |
| 247 scoped_ptr<PolicyLoaderWin> PolicyLoaderWin::Create( | 246 scoped_ptr<PolicyLoaderWin> PolicyLoaderWin::Create( |
| 248 scoped_refptr<base::SequencedTaskRunner> task_runner, | 247 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 249 const PolicyDefinitionList* policy_list) { | |
| 250 return make_scoped_ptr( | 248 return make_scoped_ptr( |
| 251 new PolicyLoaderWin(task_runner, policy_list, kRegistryChromePolicyKey, | 249 new PolicyLoaderWin(task_runner, |
| 250 kRegistryChromePolicyKey, |
| 252 g_win_gpo_list_provider.Pointer())); | 251 g_win_gpo_list_provider.Pointer())); |
| 253 } | 252 } |
| 254 | 253 |
| 255 void PolicyLoaderWin::InitOnBackgroundThread() { | 254 void PolicyLoaderWin::InitOnBackgroundThread() { |
| 256 is_initialized_ = true; | 255 is_initialized_ = true; |
| 257 SetupWatches(); | 256 SetupWatches(); |
| 258 } | 257 } |
| 259 | 258 |
| 260 scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() { | 259 scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() { |
| 261 // Reset the watches BEFORE reading the individual policies to avoid | 260 // Reset the watches BEFORE reading the individual policies to avoid |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 319 |
| 321 // Load 3rd-party policy. | 320 // Load 3rd-party policy. |
| 322 if (third_party_dict) | 321 if (third_party_dict) |
| 323 Load3rdPartyPolicy(third_party_dict.get(), scope, bundle.get()); | 322 Load3rdPartyPolicy(third_party_dict.get(), scope, bundle.get()); |
| 324 } | 323 } |
| 325 | 324 |
| 326 return bundle.Pass(); | 325 return bundle.Pass(); |
| 327 } | 326 } |
| 328 | 327 |
| 329 void PolicyLoaderWin::BuildChromePolicySchema() { | 328 void PolicyLoaderWin::BuildChromePolicySchema() { |
| 329 // TODO(joaodasilva): use the Schema directly instead of building this |
| 330 // DictionaryValue. |
| 330 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); | 331 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); |
| 331 for (const PolicyDefinitionList::Entry* e = policy_list_->begin; | 332 const Schema* chrome_schema = |
| 332 e != policy_list_->end; ++e) { | 333 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
| 333 const std::string schema_type = GetSchemaTypeForValueType(e->value_type); | 334 for (Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
| 335 !it.IsAtEnd(); it.Advance()) { |
| 336 const std::string schema_type = |
| 337 GetSchemaTypeForValueType(it.schema().type()); |
| 334 scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue()); | 338 scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue()); |
| 335 entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType, | 339 entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType, |
| 336 schema_type); | 340 schema_type); |
| 337 | 341 |
| 338 if (e->value_type == base::Value::TYPE_LIST) { | 342 if (it.schema().type() == base::Value::TYPE_LIST) { |
| 339 scoped_ptr<base::DictionaryValue> items_schema( | 343 scoped_ptr<base::DictionaryValue> items_schema( |
| 340 new base::DictionaryValue()); | 344 new base::DictionaryValue()); |
| 341 items_schema->SetStringWithoutPathExpansion( | 345 items_schema->SetStringWithoutPathExpansion( |
| 342 json_schema_constants::kType, json_schema_constants::kString); | 346 json_schema_constants::kType, json_schema_constants::kString); |
| 343 entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems, | 347 entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems, |
| 344 items_schema.release()); | 348 items_schema.release()); |
| 345 } | 349 } |
| 346 properties->SetWithoutPathExpansion(e->name, entry_schema.release()); | 350 properties->SetWithoutPathExpansion(it.key(), entry_schema.release()); |
| 347 } | 351 } |
| 348 chrome_policy_schema_.SetStringWithoutPathExpansion( | 352 chrome_policy_schema_.SetStringWithoutPathExpansion( |
| 349 json_schema_constants::kType, json_schema_constants::kObject); | 353 json_schema_constants::kType, json_schema_constants::kObject); |
| 350 chrome_policy_schema_.SetWithoutPathExpansion( | 354 chrome_policy_schema_.SetWithoutPathExpansion( |
| 351 json_schema_constants::kProperties, properties.release()); | 355 json_schema_constants::kProperties, properties.release()); |
| 352 } | 356 } |
| 353 | 357 |
| 354 bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file, | 358 bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file, |
| 355 RegistryDict* policy, | 359 RegistryDict* policy, |
| 356 PolicyLoadStatusSample* status) { | 360 PolicyLoadStatusSample* status) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 539 |
| 536 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { | 540 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { |
| 537 DCHECK(object == user_policy_changed_event_.handle() || | 541 DCHECK(object == user_policy_changed_event_.handle() || |
| 538 object == machine_policy_changed_event_.handle()) | 542 object == machine_policy_changed_event_.handle()) |
| 539 << "unexpected object signaled policy reload, obj = " | 543 << "unexpected object signaled policy reload, obj = " |
| 540 << std::showbase << std::hex << object; | 544 << std::showbase << std::hex << object; |
| 541 Reload(false); | 545 Reload(false); |
| 542 } | 546 } |
| 543 | 547 |
| 544 } // namespace policy | 548 } // namespace policy |
| OLD | NEW |