Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: sandbox/win/tests/common/controller.cc

Issue 109843003: Replace wstring with string16 in sandbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/win/tests/common/controller.h ('k') | sandbox/win/tests/validation_tests/commands.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sandbox/win/tests/common/controller.h" 5 #include "sandbox/win/tests/common/controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
12 #include "sandbox/win/src/sandbox_factory.h" 12 #include "sandbox/win/src/sandbox_factory.h"
13 13
14 namespace { 14 namespace {
15 15
16 static const int kDefaultTimeout = 60000; 16 static const int kDefaultTimeout = 60000;
17 17
18 // Constructs a full path to a file inside the system32 folder. 18 // Constructs a full path to a file inside the system32 folder.
19 std::wstring MakePathToSys32(const wchar_t* name, bool is_obj_man_path) { 19 base::string16 MakePathToSys32(const wchar_t* name, bool is_obj_man_path) {
20 wchar_t windows_path[MAX_PATH] = {0}; 20 wchar_t windows_path[MAX_PATH] = {0};
21 if (0 == ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH)) 21 if (0 == ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH))
22 return std::wstring(); 22 return base::string16();
23 23
24 std::wstring full_path(windows_path); 24 base::string16 full_path(windows_path);
25 if (full_path.empty()) 25 if (full_path.empty())
26 return full_path; 26 return full_path;
27 27
28 if (is_obj_man_path) 28 if (is_obj_man_path)
29 full_path.insert(0, L"\\??\\"); 29 full_path.insert(0, L"\\??\\");
30 30
31 full_path += L"\\system32\\"; 31 full_path += L"\\system32\\";
32 full_path += name; 32 full_path += name;
33 return full_path; 33 return full_path;
34 } 34 }
35 35
36 // Constructs a full path to a file inside the syswow64 folder. 36 // Constructs a full path to a file inside the syswow64 folder.
37 std::wstring MakePathToSysWow64(const wchar_t* name, bool is_obj_man_path) { 37 base::string16 MakePathToSysWow64(const wchar_t* name, bool is_obj_man_path) {
38 wchar_t windows_path[MAX_PATH] = {0}; 38 wchar_t windows_path[MAX_PATH] = {0};
39 if (0 == ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH)) 39 if (0 == ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH))
40 return std::wstring(); 40 return base::string16();
41 41
42 std::wstring full_path(windows_path); 42 base::string16 full_path(windows_path);
43 if (full_path.empty()) 43 if (full_path.empty())
44 return full_path; 44 return full_path;
45 45
46 if (is_obj_man_path) 46 if (is_obj_man_path)
47 full_path.insert(0, L"\\??\\"); 47 full_path.insert(0, L"\\??\\");
48 48
49 full_path += L"\\SysWOW64\\"; 49 full_path += L"\\SysWOW64\\";
50 full_path += name; 50 full_path += name;
51 return full_path; 51 return full_path;
52 } 52 }
53 53
54 bool IsProcessRunning(HANDLE process) { 54 bool IsProcessRunning(HANDLE process) {
55 DWORD exit_code = 0; 55 DWORD exit_code = 0;
56 if (::GetExitCodeProcess(process, &exit_code)) 56 if (::GetExitCodeProcess(process, &exit_code))
57 return exit_code == STILL_ACTIVE; 57 return exit_code == STILL_ACTIVE;
58 return false; 58 return false;
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 namespace sandbox { 63 namespace sandbox {
64 64
65 std::wstring MakePathToSys(const wchar_t* name, bool is_obj_man_path) { 65 base::string16 MakePathToSys(const wchar_t* name, bool is_obj_man_path) {
66 return (base::win::OSInfo::GetInstance()->wow64_status() == 66 return (base::win::OSInfo::GetInstance()->wow64_status() ==
67 base::win::OSInfo::WOW64_ENABLED) ? 67 base::win::OSInfo::WOW64_ENABLED) ?
68 MakePathToSysWow64(name, is_obj_man_path) : 68 MakePathToSysWow64(name, is_obj_man_path) :
69 MakePathToSys32(name, is_obj_man_path); 69 MakePathToSys32(name, is_obj_man_path);
70 } 70 }
71 71
72 BrokerServices* GetBroker() { 72 BrokerServices* GetBroker() {
73 static BrokerServices* broker = SandboxFactory::GetBrokerServices(); 73 static BrokerServices* broker = SandboxFactory::GetBrokerServices();
74 static bool is_initialized = false; 74 static bool is_initialized = false;
75 75
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return false; 143 return false;
144 144
145 return (SBOX_ALL_OK == policy_->AddRule(subsystem, semantics, pattern)); 145 return (SBOX_ALL_OK == policy_->AddRule(subsystem, semantics, pattern));
146 } 146 }
147 147
148 bool TestRunner::AddRuleSys32(TargetPolicy::Semantics semantics, 148 bool TestRunner::AddRuleSys32(TargetPolicy::Semantics semantics,
149 const wchar_t* pattern) { 149 const wchar_t* pattern) {
150 if (!is_init_) 150 if (!is_init_)
151 return false; 151 return false;
152 152
153 std::wstring win32_path = MakePathToSys32(pattern, false); 153 base::string16 win32_path = MakePathToSys32(pattern, false);
154 if (win32_path.empty()) 154 if (win32_path.empty())
155 return false; 155 return false;
156 156
157 if (!AddRule(TargetPolicy::SUBSYS_FILES, semantics, win32_path.c_str())) 157 if (!AddRule(TargetPolicy::SUBSYS_FILES, semantics, win32_path.c_str()))
158 return false; 158 return false;
159 159
160 if (base::win::OSInfo::GetInstance()->wow64_status() != 160 if (base::win::OSInfo::GetInstance()->wow64_status() !=
161 base::win::OSInfo::WOW64_ENABLED) 161 base::win::OSInfo::WOW64_ENABLED)
162 return true; 162 return true;
163 163
(...skipping 12 matching lines...) Expand all
176 return AddRule(TargetPolicy::SUBSYS_FILES, semantics, pattern); 176 return AddRule(TargetPolicy::SUBSYS_FILES, semantics, pattern);
177 } 177 }
178 178
179 int TestRunner::RunTest(const wchar_t* command) { 179 int TestRunner::RunTest(const wchar_t* command) {
180 if (MAX_STATE > 10) 180 if (MAX_STATE > 10)
181 return SBOX_TEST_INVALID_PARAMETER; 181 return SBOX_TEST_INVALID_PARAMETER;
182 182
183 wchar_t state_number[2]; 183 wchar_t state_number[2];
184 state_number[0] = L'0' + state_; 184 state_number[0] = L'0' + state_;
185 state_number[1] = L'\0'; 185 state_number[1] = L'\0';
186 std::wstring full_command(state_number); 186 base::string16 full_command(state_number);
187 full_command += L" "; 187 full_command += L" ";
188 full_command += command; 188 full_command += command;
189 189
190 return InternalRunTest(full_command.c_str()); 190 return InternalRunTest(full_command.c_str());
191 } 191 }
192 192
193 int TestRunner::InternalRunTest(const wchar_t* command) { 193 int TestRunner::InternalRunTest(const wchar_t* command) {
194 if (!is_init_) 194 if (!is_init_)
195 return SBOX_TEST_FAILED_TO_RUN_TEST; 195 return SBOX_TEST_FAILED_TO_RUN_TEST;
196 196
197 // For simplicity TestRunner supports only one process per instance. 197 // For simplicity TestRunner supports only one process per instance.
198 if (target_process_) { 198 if (target_process_) {
199 if (IsProcessRunning(target_process_)) 199 if (IsProcessRunning(target_process_))
200 return SBOX_TEST_FAILED_TO_RUN_TEST; 200 return SBOX_TEST_FAILED_TO_RUN_TEST;
201 target_process_.Close(); 201 target_process_.Close();
202 target_process_id_ = 0; 202 target_process_id_ = 0;
203 } 203 }
204 204
205 // Get the path to the sandboxed process. 205 // Get the path to the sandboxed process.
206 wchar_t prog_name[MAX_PATH]; 206 wchar_t prog_name[MAX_PATH];
207 GetModuleFileNameW(NULL, prog_name, MAX_PATH); 207 GetModuleFileNameW(NULL, prog_name, MAX_PATH);
208 208
209 // Launch the sandboxed process. 209 // Launch the sandboxed process.
210 ResultCode result = SBOX_ALL_OK; 210 ResultCode result = SBOX_ALL_OK;
211 PROCESS_INFORMATION target = {0}; 211 PROCESS_INFORMATION target = {0};
212 212
213 std::wstring arguments(L"\""); 213 base::string16 arguments(L"\"");
214 arguments += prog_name; 214 arguments += prog_name;
215 arguments += L"\" -child"; 215 arguments += L"\" -child";
216 arguments += no_sandbox_ ? L"-no-sandbox " : L" "; 216 arguments += no_sandbox_ ? L"-no-sandbox " : L" ";
217 arguments += command; 217 arguments += command;
218 218
219 if (no_sandbox_) { 219 if (no_sandbox_) {
220 STARTUPINFO startup_info = {sizeof(STARTUPINFO)}; 220 STARTUPINFO startup_info = {sizeof(STARTUPINFO)};
221 if (!::CreateProcessW(prog_name, &arguments[0], NULL, NULL, FALSE, 0, 221 if (!::CreateProcessW(prog_name, &arguments[0], NULL, NULL, FALSE, 0,
222 NULL, NULL, &startup_info, &target)) { 222 NULL, NULL, &startup_info, &target)) {
223 return SBOX_ERROR_GENERIC; 223 return SBOX_ERROR_GENERIC;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 327
328 target->LowerToken(); 328 target->LowerToken();
329 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) { 329 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) {
330 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 330 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
331 } 331 }
332 332
333 return command(argc - 4, argv + 4); 333 return command(argc - 4, argv + 4);
334 } 334 }
335 335
336 } // namespace sandbox 336 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/tests/common/controller.h ('k') | sandbox/win/tests/validation_tests/commands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698