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 base::win::ScopedHandle token; | 45 HANDLE temp_handle; |
46 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_WRITE, | 46 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_WRITE, |
47 token.Receive())) { | 47 &temp_handle)) { |
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); |
51 | 52 |
52 TypedBuffer<TOKEN_MANDATORY_LABEL> mandatory_label; | 53 TypedBuffer<TOKEN_MANDATORY_LABEL> mandatory_label; |
53 DWORD length = 0; | 54 DWORD length = 0; |
54 | 55 |
55 // Get the size of the buffer needed to hold the mandatory label. | 56 // Get the size of the buffer needed to hold the mandatory label. |
56 BOOL result = GetTokenInformation(token, TokenIntegrityLevel, | 57 BOOL result = GetTokenInformation(token, TokenIntegrityLevel, |
57 mandatory_label.get(), length, &length); | 58 mandatory_label.get(), length, &length); |
58 if (!result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | 59 if (!result && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
59 // Allocate a buffer that is large enough. | 60 // Allocate a buffer that is large enough. |
60 TypedBuffer<TOKEN_MANDATORY_LABEL> buffer(length); | 61 TypedBuffer<TOKEN_MANDATORY_LABEL> buffer(length); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 224 |
224 ATL::_ATL_OBJMAP_ENTRY rdp_client_entry[] = { | 225 ATL::_ATL_OBJMAP_ENTRY rdp_client_entry[] = { |
225 OBJECT_ENTRY(__uuidof(RdpDesktopSession), RdpDesktopSession) | 226 OBJECT_ENTRY(__uuidof(RdpDesktopSession), RdpDesktopSession) |
226 }; | 227 }; |
227 | 228 |
228 ChromotingModule module(rdp_client_entry, rdp_client_entry + 1); | 229 ChromotingModule module(rdp_client_entry, rdp_client_entry + 1); |
229 return module.Run() ? kSuccessExitCode : kInitializationFailed; | 230 return module.Run() ? kSuccessExitCode : kInitializationFailed; |
230 } | 231 } |
231 | 232 |
232 } // namespace remoting | 233 } // namespace remoting |
OLD | NEW |