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 #ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ | 5 #ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ |
6 #define CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ | 6 #define CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ |
7 | 7 |
8 #include <userenv.h> | |
9 #include <windows.h> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
8 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/values.h" | |
9 #include "base/win/object_watcher.h" | 15 #include "base/win/object_watcher.h" |
10 #include "chrome/browser/policy/async_policy_loader.h" | 16 #include "chrome/browser/policy/async_policy_loader.h" |
17 #include "chrome/browser/policy/policy_types.h" | |
18 | |
19 namespace base { | |
20 class FilePath; | |
21 } | |
11 | 22 |
12 namespace policy { | 23 namespace policy { |
13 | 24 |
25 class AppliedGPOListProvider; | |
26 class PolicyMap; | |
14 struct PolicyDefinitionList; | 27 struct PolicyDefinitionList; |
15 class PolicyMap; | 28 |
29 // Interface for mocking out GPO enumeration in tests. | |
30 class AppliedGPOListProvider { | |
31 public: | |
32 virtual ~AppliedGPOListProvider() {} | |
33 virtual DWORD GetAppliedGPOList(DWORD flags, | |
34 LPCTSTR machine_name, | |
35 PSID sid_user, | |
36 GUID* extension_guid, | |
37 PGROUP_POLICY_OBJECT* gpo_list) = 0; | |
38 virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) = 0; | |
39 }; | |
16 | 40 |
17 // Loads policies from the Windows registry, and watches for Group Policy | 41 // Loads policies from the Windows registry, and watches for Group Policy |
18 // notifications to trigger reloads. | 42 // notifications to trigger reloads. |
19 class PolicyLoaderWin : public AsyncPolicyLoader, | 43 class PolicyLoaderWin : public AsyncPolicyLoader, |
20 public base::win::ObjectWatcher::Delegate { | 44 public base::win::ObjectWatcher::Delegate { |
21 public: | 45 public: |
22 explicit PolicyLoaderWin(const PolicyDefinitionList* policy_list); | 46 explicit PolicyLoaderWin(const PolicyDefinitionList* policy_list, |
47 const string16& chrome_policy_key, | |
48 AppliedGPOListProvider* gpo_provider); | |
23 virtual ~PolicyLoaderWin(); | 49 virtual ~PolicyLoaderWin(); |
24 | 50 |
51 // Creates a policy loader that uses the Win API to access GPO. | |
52 static scoped_ptr<PolicyLoaderWin> Create( | |
53 const PolicyDefinitionList* policy_list); | |
54 | |
25 // AsyncPolicyLoader implementation. | 55 // AsyncPolicyLoader implementation. |
26 virtual void InitOnFile() OVERRIDE; | 56 virtual void InitOnFile() OVERRIDE; |
27 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE; | 57 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE; |
28 | 58 |
29 private: | 59 private: |
30 void LoadChromePolicy(PolicyMap* chrome_policies); | 60 // Builds the Chrome policy schema in |chrome_policy_schema_|. |
31 void Load3rdPartyPolicies(PolicyBundle* bundle); | 61 void BuildChromePolicySchema(); |
62 | |
63 // Reads Chrome Policy from a PReg file at the given path and stores the | |
64 // result in |policy|. | |
65 bool ReadPRegFile(const base::FilePath& preg_file, | |
66 base::DictionaryValue* policy); | |
67 | |
68 // Loads and parses GPO policy in |policy_object_list| for scope |scope|. If | |
69 // successful, stores the result in |policy| and returns true. Returns false | |
70 // on failure reading the policy, indicating that policy loading should fall | |
71 // back to reading the registry. | |
72 bool LoadGPOPolicy(PolicyScope scope, | |
73 PGROUP_POLICY_OBJECT policy_object_list, | |
74 base::DictionaryValue* policy); | |
75 | |
76 // Queries Windows for applied group policy and writes the result to |policy|. | |
77 // This is the preferred way to obtain GPO data, there are reports of abuse | |
78 // of the registry GPO keys by 3rd-party software. | |
79 bool ReadPolicyFromGPO(PolicyScope scope, base::DictionaryValue* policy); | |
Joao da Silva
2013/04/10 12:32:12
Seems a bit arbitrary that methods are used to rea
Mattias Nissler (ping if slow)
2013/04/10 13:20:25
It is not entirely arbitrary, the GPO functions ne
| |
80 | |
81 // Parses Chrome policy from |gpo_dict| for the given |scope| and |level| and | |
82 // merges it into |chrome_policy_map|. | |
83 void LoadChromePolicy(const base::DictionaryValue* gpo_dict, | |
84 PolicyLevel level, | |
85 PolicyScope scope, | |
86 PolicyMap* chrome_policy_map); | |
87 | |
88 // Loads 3rd-party policy from |gpo_dict| and merges it into |bundle|. | |
89 void Load3rdPartyPolicy(const base::DictionaryValue* gpo_dict, | |
90 PolicyScope scope, | |
91 PolicyBundle* bundle); | |
32 | 92 |
33 // Installs the watchers for the Group Policy update events. | 93 // Installs the watchers for the Group Policy update events. |
34 void SetupWatches(); | 94 void SetupWatches(); |
35 | 95 |
36 // ObjectWatcher::Delegate overrides: | 96 // ObjectWatcher::Delegate overrides: |
37 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | 97 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; |
38 | 98 |
39 bool is_initialized_; | 99 bool is_initialized_; |
40 const PolicyDefinitionList* policy_list_; | 100 const PolicyDefinitionList* policy_list_; |
101 const string16 chrome_policy_key_; | |
102 class AppliedGPOListProvider* gpo_provider_; | |
103 base::DictionaryValue chrome_policy_schema_; | |
41 | 104 |
42 base::WaitableEvent user_policy_changed_event_; | 105 base::WaitableEvent user_policy_changed_event_; |
43 base::WaitableEvent machine_policy_changed_event_; | 106 base::WaitableEvent machine_policy_changed_event_; |
44 base::win::ObjectWatcher user_policy_watcher_; | 107 base::win::ObjectWatcher user_policy_watcher_; |
45 base::win::ObjectWatcher machine_policy_watcher_; | 108 base::win::ObjectWatcher machine_policy_watcher_; |
46 bool user_policy_watcher_failed_; | 109 bool user_policy_watcher_failed_; |
47 bool machine_policy_watcher_failed_; | 110 bool machine_policy_watcher_failed_; |
48 | 111 |
49 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderWin); | 112 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderWin); |
50 }; | 113 }; |
51 | 114 |
52 // Constants shared with tests. | |
53 namespace registry_constants { | |
54 // Path separator for registry keys. | |
55 extern const wchar_t kPathSep[]; | |
56 // Registry key within Chrome's key that contains 3rd party policy. | |
57 extern const wchar_t kThirdParty[]; | |
58 // Registry key within an extension's namespace that contains mandatory | |
59 // policy. | |
60 extern const wchar_t kMandatory[]; | |
61 // Registry key within an extension's namespace that contains recommended | |
62 // policy. | |
63 extern const wchar_t kRecommended[]; | |
64 // Registry key within an extension's namespace that contains the policy | |
65 // schema. | |
66 extern const wchar_t kSchema[]; | |
67 } // namespace registry_constants | |
68 | |
69 } // namespace policy | 115 } // namespace policy |
70 | 116 |
71 #endif // CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ | 117 #endif // CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ |
OLD | NEW |