Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / sandbox / win / src / sandbox_policy_base.h
blob587d7934d3b24dc57a75788a9b4d26a48c9e2b4b
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
3 // found in the LICENSE file.
5 #ifndef SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_
6 #define SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_
8 #include <windows.h>
10 #include <list>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/strings/string16.h"
16 #include "sandbox/win/src/crosscall_server.h"
17 #include "sandbox/win/src/handle_closer.h"
18 #include "sandbox/win/src/ipc_tags.h"
19 #include "sandbox/win/src/policy_engine_opcodes.h"
20 #include "sandbox/win/src/policy_engine_params.h"
21 #include "sandbox/win/src/sandbox_policy.h"
22 #include "sandbox/win/src/win_utils.h"
24 namespace sandbox {
26 class AppContainerAttributes;
27 class LowLevelPolicy;
28 class TargetProcess;
29 struct PolicyGlobal;
31 // We act as a policy dispatcher, implementing the handler for the "ping" IPC,
32 // so we have to provide the appropriate handler on the OnMessageReady method.
33 // There is a static_cast for the handler, and the compiler only performs the
34 // cast if the first base class is Dispatcher.
35 class PolicyBase : public Dispatcher, public TargetPolicy {
36 public:
37 PolicyBase();
39 // TargetPolicy:
40 void AddRef() override;
41 void Release() override;
42 ResultCode SetTokenLevel(TokenLevel initial, TokenLevel lockdown) override;
43 TokenLevel GetInitialTokenLevel() const override;
44 TokenLevel GetLockdownTokenLevel() const override;
45 ResultCode SetJobLevel(JobLevel job_level, uint32 ui_exceptions) override;
46 ResultCode SetJobMemoryLimit(size_t memory_limit) override;
47 ResultCode SetAlternateDesktop(bool alternate_winstation) override;
48 base::string16 GetAlternateDesktop() const override;
49 ResultCode CreateAlternateDesktop(bool alternate_winstation) override;
50 void DestroyAlternateDesktop() override;
51 ResultCode SetIntegrityLevel(IntegrityLevel integrity_level) override;
52 IntegrityLevel GetIntegrityLevel() const override;
53 ResultCode SetDelayedIntegrityLevel(IntegrityLevel integrity_level) override;
54 ResultCode SetAppContainer(const wchar_t* sid) override;
55 ResultCode SetCapability(const wchar_t* sid) override;
56 ResultCode SetLowBox(const wchar_t* sid) override;
57 ResultCode SetProcessMitigations(MitigationFlags flags) override;
58 MitigationFlags GetProcessMitigations() override;
59 ResultCode SetDelayedProcessMitigations(MitigationFlags flags) override;
60 MitigationFlags GetDelayedProcessMitigations() const override;
61 void SetStrictInterceptions() override;
62 ResultCode SetStdoutHandle(HANDLE handle) override;
63 ResultCode SetStderrHandle(HANDLE handle) override;
64 ResultCode AddRule(SubSystem subsystem,
65 Semantics semantics,
66 const wchar_t* pattern) override;
67 ResultCode AddDllToUnload(const wchar_t* dll_name) override;
68 ResultCode AddKernelObjectToClose(const base::char16* handle_type,
69 const base::char16* handle_name) override;
71 // Dispatcher:
72 Dispatcher* OnMessageReady(IPCParams* ipc,
73 CallbackGeneric* callback) override;
74 bool SetupService(InterceptionManager* manager, int service) override;
76 // Creates a Job object with the level specified in a previous call to
77 // SetJobLevel().
78 ResultCode MakeJobObject(HANDLE* job);
80 // Creates the two tokens with the levels specified in a previous call to
81 // SetTokenLevel().
82 ResultCode MakeTokens(HANDLE* initial, HANDLE* lockdown);
84 const AppContainerAttributes* GetAppContainer() const;
86 const PSID GetLowBoxSid() const;
88 // Adds a target process to the internal list of targets. Internally a
89 // call to TargetProcess::Init() is issued.
90 bool AddTarget(TargetProcess* target);
92 // Called when there are no more active processes in a Job.
93 // Removes a Job object associated with this policy and the target associated
94 // with the job.
95 bool OnJobEmpty(HANDLE job);
97 EvalResult EvalPolicy(int service, CountedParameterSetBase* params);
99 HANDLE GetStdoutHandle();
100 HANDLE GetStderrHandle();
102 private:
103 ~PolicyBase() override;
105 // Test IPC providers.
106 bool Ping(IPCInfo* ipc, void* cookie);
108 // Returns a dispatcher from ipc_targets_.
109 Dispatcher* GetDispatcher(int ipc_tag);
111 // Sets up interceptions for a new target.
112 bool SetupAllInterceptions(TargetProcess* target);
114 // Sets up the handle closer for a new target.
115 bool SetupHandleCloser(TargetProcess* target);
117 ResultCode AddRuleInternal(SubSystem subsystem,
118 Semantics semantics,
119 const wchar_t* pattern);
121 // This lock synchronizes operations on the targets_ collection.
122 CRITICAL_SECTION lock_;
123 // Maintains the list of target process associated with this policy.
124 // The policy takes ownership of them.
125 typedef std::list<TargetProcess*> TargetSet;
126 TargetSet targets_;
127 // Standard object-lifetime reference counter.
128 volatile LONG ref_count;
129 // The user-defined global policy settings.
130 TokenLevel lockdown_level_;
131 TokenLevel initial_level_;
132 JobLevel job_level_;
133 uint32 ui_exceptions_;
134 size_t memory_limit_;
135 bool use_alternate_desktop_;
136 bool use_alternate_winstation_;
137 // Helps the file system policy initialization.
138 bool file_system_init_;
139 bool relaxed_interceptions_;
140 HANDLE stdout_handle_;
141 HANDLE stderr_handle_;
142 IntegrityLevel integrity_level_;
143 IntegrityLevel delayed_integrity_level_;
144 MitigationFlags mitigations_;
145 MitigationFlags delayed_mitigations_;
146 // The array of objects that will answer IPC calls.
147 Dispatcher* ipc_targets_[IPC_LAST_TAG];
148 // Object in charge of generating the low level policy.
149 LowLevelPolicy* policy_maker_;
150 // Memory structure that stores the low level policy.
151 PolicyGlobal* policy_;
152 // The list of dlls to unload in the target process.
153 std::vector<base::string16> blacklisted_dlls_;
154 // This is a map of handle-types to names that we need to close in the
155 // target process. A null set means we need to close all handles of the
156 // given type.
157 HandleCloser handle_closer_;
158 std::vector<base::string16> capabilities_;
159 scoped_ptr<AppContainerAttributes> appcontainer_list_;
160 PSID lowbox_sid_;
162 static HDESK alternate_desktop_handle_;
163 static HWINSTA alternate_winstation_handle_;
164 static IntegrityLevel alternate_desktop_integrity_level_label_;
166 DISALLOW_COPY_AND_ASSIGN(PolicyBase);
169 } // namespace sandbox
171 #endif // SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_