OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "remoting/host/win/chromoting_module.h" | 5 #include "remoting/host/win/chromoting_module.h" |
6 | 6 |
7 #include <sddl.h> | 7 #include <sddl.h> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 SDDL_BUILTIN_ADMINISTRATORS) | 35 SDDL_BUILTIN_ADMINISTRATORS) |
36 SDDL_ACE(SDDL_ACCESS_ALLOWED, SDDL_COM_EXECUTE_LOCAL, SDDL_INTERACTIVE); | 36 SDDL_ACE(SDDL_ACCESS_ALLOWED, SDDL_COM_EXECUTE_LOCAL, SDDL_INTERACTIVE); |
37 | 37 |
38 // Holds a reference to the task runner used by the module. | 38 // Holds a reference to the task runner used by the module. |
39 base::LazyInstance<scoped_refptr<AutoThreadTaskRunner> > g_module_task_runner = | 39 base::LazyInstance<scoped_refptr<AutoThreadTaskRunner> > g_module_task_runner = |
40 LAZY_INSTANCE_INITIALIZER; | 40 LAZY_INSTANCE_INITIALIZER; |
41 | 41 |
42 // Lowers the process integrity level such that it does not exceed |max_level|. | 42 // Lowers the process integrity level such that it does not exceed |max_level|. |
43 // |max_level| is expected to be one of SECURITY_MANDATORY_XXX constants. | 43 // |max_level| is expected to be one of SECURITY_MANDATORY_XXX constants. |
44 bool LowerProcessIntegrityLevel(DWORD max_level) { | 44 bool LowerProcessIntegrityLevel(DWORD max_level) { |
45 HANDLE temp_handle; | 45 base::win::ScopedHandle token; |
46 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_WRITE, | 46 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_WRITE, |
47 &temp_handle)) { | 47 token.Receive())) { |
48 PLOG(ERROR) << "OpenProcessToken() failed"; | 48 PLOG(ERROR) << "OpenProcessToken() failed"; |
49 return false; | 49 return false; |
50 } | 50 } |
51 base::win::ScopedHandle token(temp_handle); | |
52 | 51 |
53 TypedBuffer<TOKEN_MANDATORY_LABEL> mandatory_label; | 52 TypedBuffer<TOKEN_MANDATORY_LABEL> mandatory_label; |
54 DWORD length = 0; | 53 DWORD length = 0; |
55 | 54 |
56 // Get the size of the buffer needed to hold the mandatory label. | 55 // Get the size of the buffer needed to hold the mandatory label. |
57 BOOL result = GetTokenInformation(token, TokenIntegrityLevel, | 56 BOOL result = GetTokenInformation(token, TokenIntegrityLevel, |
58 mandatory_label.get(), length, &length); | 57 mandatory_label.get(), length, &length); |
59 if (!result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | 58 if (!result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
60 // Allocate a buffer that is large enough. | 59 // Allocate a buffer that is large enough. |
61 TypedBuffer<TOKEN_MANDATORY_LABEL> buffer(length); | 60 TypedBuffer<TOKEN_MANDATORY_LABEL> buffer(length); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 223 |
225 ATL::_ATL_OBJMAP_ENTRY rdp_client_entry[] = { | 224 ATL::_ATL_OBJMAP_ENTRY rdp_client_entry[] = { |
226 OBJECT_ENTRY(__uuidof(RdpDesktopSession), RdpDesktopSession) | 225 OBJECT_ENTRY(__uuidof(RdpDesktopSession), RdpDesktopSession) |
227 }; | 226 }; |
228 | 227 |
229 ChromotingModule module(rdp_client_entry, rdp_client_entry + 1); | 228 ChromotingModule module(rdp_client_entry, rdp_client_entry + 1); |
230 return module.Run() ? kSuccessExitCode : kInitializationFailed; | 229 return module.Run() ? kSuccessExitCode : kInitializationFailed; |
231 } | 230 } |
232 | 231 |
233 } // namespace remoting | 232 } // namespace remoting |
OLD | NEW |