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 #include "remoting/host/elevated_controller_win.h" | 5 #include "remoting/host/elevated_controller_win.h" |
6 | 6 |
7 #include <sddl.h> | 7 #include <sddl.h> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/stringize_macros.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
18 #include "remoting/host/branding.h" | 19 #include "remoting/host/branding.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // The host configuration file name. | 23 // The host configuration file name. |
23 const FilePath::CharType kConfigFileName[] = FILE_PATH_LITERAL("host.json"); | 24 const FilePath::CharType kConfigFileName[] = FILE_PATH_LITERAL("host.json"); |
24 | 25 |
25 // The extension for the temporary file. | 26 // The extension for the temporary file. |
26 const FilePath::CharType kTempFileExtension[] = FILE_PATH_LITERAL("json~"); | 27 const FilePath::CharType kTempFileExtension[] = FILE_PATH_LITERAL("json~"); |
27 | 28 |
28 // The host configuration file security descriptor that enables full access to | 29 // The host configuration file security descriptor that enables full access to |
29 // Local System and built-in administrators only. | 30 // Local System and built-in administrators only. |
30 const char kConfigFileSecurityDescriptor[] = | 31 const char16 kConfigFileSecurityDescriptor[] = |
31 "O:BA" "G:BA" "D:(A;;GA;;;SY)(A;;GA;;;BA)"; | 32 TO_L_STRING("O:BAG:BAD:(A;;GA;;;SY)(A;;GA;;;BA)"); |
32 | 33 |
33 // The maximum size of the configuration file. "1MB ought to be enough" for any | 34 // The maximum size of the configuration file. "1MB ought to be enough" for any |
34 // reasonable configuration we will ever need. 1MB is low enough to make | 35 // reasonable configuration we will ever need. 1MB is low enough to make |
35 // the probability of out of memory situation fairly low. OOM is still possible | 36 // the probability of out of memory situation fairly low. OOM is still possible |
36 // and we will crash if it occurs. | 37 // and we will crash if it occurs. |
37 const size_t kMaxConfigFileSize = 1024 * 1024; | 38 const size_t kMaxConfigFileSize = 1024 * 1024; |
38 | 39 |
39 // ReadConfig() filters the configuration file stripping all variables except of | 40 // ReadConfig() filters the configuration file stripping all variables except of |
40 // the following two. | 41 // the following two. |
41 const char kHostId[] = "host_id"; | 42 const char kHostId[] = "host_id"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 if (length > kMaxConfigFileSize) { | 96 if (length > kMaxConfigFileSize) { |
96 return E_FAIL; | 97 return E_FAIL; |
97 } | 98 } |
98 | 99 |
99 // Create a security descriptor for the configuration file. | 100 // Create a security descriptor for the configuration file. |
100 SECURITY_ATTRIBUTES security_attributes; | 101 SECURITY_ATTRIBUTES security_attributes; |
101 security_attributes.nLength = sizeof(security_attributes); | 102 security_attributes.nLength = sizeof(security_attributes); |
102 security_attributes.bInheritHandle = FALSE; | 103 security_attributes.bInheritHandle = FALSE; |
103 | 104 |
104 ULONG security_descriptor_length = 0; | 105 ULONG security_descriptor_length = 0; |
105 if (!ConvertStringSecurityDescriptorToSecurityDescriptorA( | 106 if (!ConvertStringSecurityDescriptorToSecurityDescriptorW( |
106 kConfigFileSecurityDescriptor, | 107 kConfigFileSecurityDescriptor, |
107 SDDL_REVISION_1, | 108 SDDL_REVISION_1, |
108 reinterpret_cast<PSECURITY_DESCRIPTOR*>( | 109 reinterpret_cast<PSECURITY_DESCRIPTOR*>( |
109 &security_attributes.lpSecurityDescriptor), | 110 &security_attributes.lpSecurityDescriptor), |
110 &security_descriptor_length)) { | 111 &security_descriptor_length)) { |
111 DWORD error = GetLastError(); | 112 DWORD error = GetLastError(); |
112 LOG_GETLASTERROR(ERROR) << | 113 LOG_GETLASTERROR(ERROR) << |
113 "Failed to create a security descriptor for the configuration file"; | 114 "Failed to create a security descriptor for the configuration file"; |
114 return HRESULT_FROM_WIN32(error); | 115 return HRESULT_FROM_WIN32(error); |
115 } | 116 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 error = GetLastError(); | 316 error = GetLastError(); |
316 LOG_GETLASTERROR(ERROR) | 317 LOG_GETLASTERROR(ERROR) |
317 << "Failed to connect to the service control manager"; | 318 << "Failed to connect to the service control manager"; |
318 | 319 |
319 return HRESULT_FROM_WIN32(error); | 320 return HRESULT_FROM_WIN32(error); |
320 } | 321 } |
321 | 322 |
322 DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS | | 323 DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS | |
323 SERVICE_START | SERVICE_STOP; | 324 SERVICE_START | SERVICE_STOP; |
324 ScopedScHandle service( | 325 ScopedScHandle service( |
325 ::OpenServiceW(scmanager, UTF8ToUTF16(kWindowsServiceName).c_str(), | 326 ::OpenServiceW(scmanager, kWindowsServiceName, desired_access)); |
326 desired_access)); | |
327 if (!service.IsValid()) { | 327 if (!service.IsValid()) { |
328 error = GetLastError(); | 328 error = GetLastError(); |
329 LOG_GETLASTERROR(ERROR) | 329 LOG_GETLASTERROR(ERROR) |
330 << "Failed to open to the '" << kWindowsServiceName << "' service"; | 330 << "Failed to open to the '" << kWindowsServiceName << "' service"; |
331 | 331 |
332 return HRESULT_FROM_WIN32(error); | 332 return HRESULT_FROM_WIN32(error); |
333 } | 333 } |
334 | 334 |
335 service_out->Set(service.Take()); | 335 service_out->Set(service.Take()); |
336 return S_OK; | 336 return S_OK; |
337 } | 337 } |
338 | 338 |
339 } // namespace remoting | 339 } // namespace remoting |
OLD | NEW |