OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ | |
6 #define CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 #include <userenv.h> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/files/file_path.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/strings/string16.h" | |
16 #include "base/synchronization/waitable_event.h" | |
17 #include "base/values.h" | |
18 #include "base/win/object_watcher.h" | |
19 #include "components/policy/core/common/async_policy_loader.h" | |
20 #include "components/policy/core/common/policy_types.h" | |
21 | |
22 namespace base { | |
23 class SequencedTaskRunner; | |
24 } | |
25 | |
26 namespace policy { | |
27 | |
28 class AppliedGPOListProvider; | |
29 class PolicyLoadStatusSample; | |
30 class PolicyMap; | |
31 class RegistryDict; | |
32 | |
33 // Interface for mocking out GPO enumeration in tests. | |
34 class AppliedGPOListProvider { | |
35 public: | |
36 virtual ~AppliedGPOListProvider() {} | |
37 virtual DWORD GetAppliedGPOList(DWORD flags, | |
38 LPCTSTR machine_name, | |
39 PSID sid_user, | |
40 GUID* extension_guid, | |
41 PGROUP_POLICY_OBJECT* gpo_list) = 0; | |
42 virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) = 0; | |
43 }; | |
44 | |
45 // Loads policies from the Windows registry, and watches for Group Policy | |
46 // notifications to trigger reloads. | |
47 class PolicyLoaderWin : public AsyncPolicyLoader, | |
48 public base::win::ObjectWatcher::Delegate { | |
49 public: | |
50 // The PReg file name used by GPO. | |
51 static const base::FilePath::CharType kPRegFileName[]; | |
52 | |
53 PolicyLoaderWin(scoped_refptr<base::SequencedTaskRunner> task_runner, | |
54 const string16& chrome_policy_key, | |
55 AppliedGPOListProvider* gpo_provider); | |
56 virtual ~PolicyLoaderWin(); | |
57 | |
58 // Creates a policy loader that uses the Win API to access GPO. | |
59 static scoped_ptr<PolicyLoaderWin> Create( | |
60 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
61 const string16& chrome_policy_key); | |
62 | |
63 // AsyncPolicyLoader implementation. | |
64 virtual void InitOnBackgroundThread() OVERRIDE; | |
65 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE; | |
66 | |
67 private: | |
68 // Builds the Chrome policy schema in |chrome_policy_schema_|. | |
69 void BuildChromePolicySchema(); | |
70 | |
71 // Reads Chrome Policy from a PReg file at the given path and stores the | |
72 // result in |policy|. | |
73 bool ReadPRegFile(const base::FilePath& preg_file, | |
74 RegistryDict* policy, | |
75 PolicyLoadStatusSample *status); | |
76 | |
77 // Loads and parses GPO policy in |policy_object_list| for scope |scope|. If | |
78 // successful, stores the result in |policy| and returns true. Returns false | |
79 // on failure reading the policy, indicating that policy loading should fall | |
80 // back to reading the registry. | |
81 bool LoadGPOPolicy(PolicyScope scope, | |
82 PGROUP_POLICY_OBJECT policy_object_list, | |
83 RegistryDict* policy, | |
84 PolicyLoadStatusSample *status); | |
85 | |
86 // Queries Windows for applied group policy and writes the result to |policy|. | |
87 // This is the preferred way to obtain GPO data, there are reports of abuse | |
88 // of the registry GPO keys by 3rd-party software. | |
89 bool ReadPolicyFromGPO(PolicyScope scope, | |
90 RegistryDict* policy, | |
91 PolicyLoadStatusSample *status); | |
92 | |
93 // Parses Chrome policy from |gpo_dict| for the given |scope| and |level| and | |
94 // merges it into |chrome_policy_map|. | |
95 void LoadChromePolicy(const RegistryDict* gpo_dict, | |
96 PolicyLevel level, | |
97 PolicyScope scope, | |
98 PolicyMap* chrome_policy_map); | |
99 | |
100 // Loads 3rd-party policy from |gpo_dict| and merges it into |bundle|. | |
101 void Load3rdPartyPolicy(const RegistryDict* gpo_dict, | |
102 PolicyScope scope, | |
103 PolicyBundle* bundle); | |
104 | |
105 // Installs the watchers for the Group Policy update events. | |
106 void SetupWatches(); | |
107 | |
108 // ObjectWatcher::Delegate overrides: | |
109 virtual void OnObjectSignaled(HANDLE object) OVERRIDE; | |
110 | |
111 bool is_initialized_; | |
112 const string16 chrome_policy_key_; | |
113 class AppliedGPOListProvider* gpo_provider_; | |
114 base::DictionaryValue chrome_policy_schema_; | |
115 | |
116 base::WaitableEvent user_policy_changed_event_; | |
117 base::WaitableEvent machine_policy_changed_event_; | |
118 base::win::ObjectWatcher user_policy_watcher_; | |
119 base::win::ObjectWatcher machine_policy_watcher_; | |
120 bool user_policy_watcher_failed_; | |
121 bool machine_policy_watcher_failed_; | |
122 | |
123 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderWin); | |
124 }; | |
125 | |
126 } // namespace policy | |
127 | |
128 #endif // CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_ | |
OLD | NEW |