diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-12 21:36:50 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-12 21:36:50 +0000 |
commit | 5672e5d87b9ae60c2141f2fcb5042bf66f54b25b (patch) | |
tree | ff57ae68cf35c20f409e235ec736619067eb69aa /sandbox/win/src | |
parent | 6fd90742ff35fc08ce8241279f420cab44b713d3 (diff) | |
download | chromium_src-5672e5d87b9ae60c2141f2fcb5042bf66f54b25b.zip chromium_src-5672e5d87b9ae60c2141f2fcb5042bf66f54b25b.tar.gz chromium_src-5672e5d87b9ae60c2141f2fcb5042bf66f54b25b.tar.bz2 |
Replace wstring with string16 in sandbox
BUG=
R=cpu@chromium.org
Review URL: https://codereview.chromium.org/113173002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/win/src')
44 files changed, 192 insertions, 163 deletions
diff --git a/sandbox/win/src/Wow64.cc b/sandbox/win/src/Wow64.cc index a710d75..b11026b 100644 --- a/sandbox/win/src/Wow64.cc +++ b/sandbox/win/src/Wow64.cc @@ -142,13 +142,13 @@ bool Wow64::RunWowHelper(void* buffer) { // Get the path to the helper (beside the exe). wchar_t prog_name[MAX_PATH]; GetModuleFileNameW(NULL, prog_name, MAX_PATH); - std::wstring path(prog_name); + base::string16 path(prog_name); size_t name_pos = path.find_last_of(L"\\"); - if (std::wstring::npos == name_pos) + if (base::string16::npos == name_pos) return false; path.resize(name_pos + 1); - std::wstringstream command; + std::basic_stringstream<base::char16> command; command << std::hex << std::showbase << L"\"" << path << L"wow_helper.exe\" " << child_->ProcessId() << " " << bit_cast<ULONG>(buffer); diff --git a/sandbox/win/src/crosscall_server.cc b/sandbox/win/src/crosscall_server.cc index fea8553..ab8b421 100644 --- a/sandbox/win/src/crosscall_server.cc +++ b/sandbox/win/src/crosscall_server.cc @@ -237,7 +237,7 @@ bool CrossCallParamsEx::GetParameterVoidPtr(uint32 index, void** param) { // Covers the common case of reading a string. Note that the string is not // scanned for invalid characters. -bool CrossCallParamsEx::GetParameterStr(uint32 index, std::wstring* string) { +bool CrossCallParamsEx::GetParameterStr(uint32 index, base::string16* string) { uint32 size = 0; ArgType type; void* start = GetRawParameter(index, &size, &type); diff --git a/sandbox/win/src/crosscall_server.h b/sandbox/win/src/crosscall_server.h index 2a39507..e754006 100644 --- a/sandbox/win/src/crosscall_server.h +++ b/sandbox/win/src/crosscall_server.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" #include "base/callback.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_params.h" // This is the IPC server interface for CrossCall: The IPC for the Sandbox @@ -112,7 +113,7 @@ class CrossCallParamsEx : public CrossCallParams { // Gets a parameter that is a string. Returns false if the parameter does not // exist. - bool GetParameterStr(uint32 index, std::wstring* string); + bool GetParameterStr(uint32 index, base::string16* string); // Gets a parameter that is an in/out buffer. Returns false is the parameter // does not exist or if the size of the actual parameter is not equal to the diff --git a/sandbox/win/src/file_policy_test.cc b/sandbox/win/src/file_policy_test.cc index 85aea0b..adda1a5 100644 --- a/sandbox/win/src/file_policy_test.cc +++ b/sandbox/win/src/file_policy_test.cc @@ -62,7 +62,7 @@ SBOX_TESTS_COMMAND int File_Win32Create(int argc, wchar_t **argv) { SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; } - std::wstring full_path = MakePathToSys(argv[0], false); + base::string16 full_path = MakePathToSys(argv[0], false); if (full_path.empty()) { return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; } @@ -94,7 +94,7 @@ SBOX_TESTS_COMMAND int File_CreateSys32(int argc, wchar_t **argv) { if (argc != 1) return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; - std::wstring file(argv[0]); + base::string16 file(argv[0]); if (0 != _wcsnicmp(file.c_str(), kNTObjManPrefix, kNTObjManPrefixLen)) file = MakePathToSys(argv[0], true); @@ -132,7 +132,7 @@ SBOX_TESTS_COMMAND int File_OpenSys32(int argc, wchar_t **argv) { if (argc != 1) return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; - std::wstring file = MakePathToSys(argv[0], true); + base::string16 file = MakePathToSys(argv[0], true); UNICODE_STRING object_name; RtlInitUnicodeString(&object_name, file.c_str()); @@ -156,7 +156,7 @@ SBOX_TESTS_COMMAND int File_OpenSys32(int argc, wchar_t **argv) { } SBOX_TESTS_COMMAND int File_GetDiskSpace(int argc, wchar_t **argv) { - std::wstring sys_path = MakePathToSys(L"", false); + base::string16 sys_path = MakePathToSys(L"", false); if (sys_path.empty()) { return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; } @@ -212,7 +212,7 @@ SBOX_TESTS_COMMAND int File_QueryAttributes(int argc, wchar_t **argv) { bool expect_directory = (L'd' == argv[1][0]); UNICODE_STRING object_name; - std::wstring file = MakePathToSys(argv[0], true); + base::string16 file = MakePathToSys(argv[0], true); RtlInitUnicodeString(&object_name, file.c_str()); OBJECT_ATTRIBUTES obj_attributes = {0}; @@ -265,8 +265,8 @@ TEST(FilePolicyTest, AllowNtCreateCalc) { } TEST(FilePolicyTest, AllowNtCreateWithNativePath) { - std::wstring calc = MakePathToSys(L"calc.exe", false); - std::wstring nt_path; + base::string16 calc = MakePathToSys(L"calc.exe", false); + base::string16 nt_path; ASSERT_TRUE(GetNtPathFromWin32Path(calc, &nt_path)); TestRunner runner; runner.AddFsRule(TargetPolicy::FILES_ALLOW_READONLY, nt_path.c_str()); @@ -533,9 +533,9 @@ TEST(FilePolicyTest, DISABLED_TestReparsePoint) { ASSERT_TRUE(::CreateDirectory(temp_file_name, NULL)); // Create a temporary file in the subfolder. - std::wstring subfolder = temp_file_name; - std::wstring temp_file_title = subfolder.substr(subfolder.rfind(L"\\") + 1); - std::wstring temp_file = subfolder + L"\\file_" + temp_file_title; + base::string16 subfolder = temp_file_name; + base::string16 temp_file_title = subfolder.substr(subfolder.rfind(L"\\") + 1); + base::string16 temp_file = subfolder + L"\\file_" + temp_file_title; HANDLE file = ::CreateFile(temp_file.c_str(), FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, @@ -544,8 +544,8 @@ TEST(FilePolicyTest, DISABLED_TestReparsePoint) { ASSERT_TRUE(::CloseHandle(file)); // Create a temporary file in the temp directory. - std::wstring temp_dir = temp_directory; - std::wstring temp_file_in_temp = temp_dir + L"file_" + temp_file_title; + base::string16 temp_dir = temp_directory; + base::string16 temp_file_in_temp = temp_dir + L"file_" + temp_file_title; file = ::CreateFile(temp_file_in_temp.c_str(), FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL); @@ -553,12 +553,12 @@ TEST(FilePolicyTest, DISABLED_TestReparsePoint) { ASSERT_TRUE(::CloseHandle(file)); // Give write access to the temp directory. - std::wstring temp_dir_wildcard = temp_dir + L"*"; + base::string16 temp_dir_wildcard = temp_dir + L"*"; EXPECT_TRUE(runner.AddFsRule(TargetPolicy::FILES_ALLOW_ANY, temp_dir_wildcard.c_str())); // Prepare the command to execute. - std::wstring command_write; + base::string16 command_write; command_write += L"File_Create Write \""; command_write += temp_file; command_write += L"\""; @@ -573,7 +573,7 @@ TEST(FilePolicyTest, DISABLED_TestReparsePoint) { OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); EXPECT_TRUE(INVALID_HANDLE_VALUE != dir); - std::wstring temp_dir_nt; + base::string16 temp_dir_nt; temp_dir_nt += L"\\??\\"; temp_dir_nt += temp_dir; EXPECT_TRUE(SetReparsePoint(dir, temp_dir_nt.c_str())); diff --git a/sandbox/win/src/filesystem_dispatcher.cc b/sandbox/win/src/filesystem_dispatcher.cc index 22240ff..275122be 100644 --- a/sandbox/win/src/filesystem_dispatcher.cc +++ b/sandbox/win/src/filesystem_dispatcher.cc @@ -83,7 +83,7 @@ bool FilesystemDispatcher::SetupService(InterceptionManager* manager, } bool FilesystemDispatcher::NtCreateFile( - IPCInfo* ipc, std::wstring* name, DWORD attributes, DWORD desired_access, + IPCInfo* ipc, base::string16* name, DWORD attributes, DWORD desired_access, DWORD file_attributes, DWORD share_access, DWORD create_disposition, DWORD create_options) { if (!PreProcessName(*name, name)) { @@ -126,7 +126,7 @@ bool FilesystemDispatcher::NtCreateFile( } bool FilesystemDispatcher::NtOpenFile( - IPCInfo* ipc, std::wstring* name, DWORD attributes, DWORD desired_access, + IPCInfo* ipc, base::string16* name, DWORD attributes, DWORD desired_access, DWORD share_access, DWORD open_options) { if (!PreProcessName(*name, name)) { // The path requested might contain a reparse point. @@ -166,7 +166,7 @@ bool FilesystemDispatcher::NtOpenFile( } bool FilesystemDispatcher::NtQueryAttributesFile( - IPCInfo* ipc, std::wstring* name, DWORD attributes, CountedBuffer* info) { + IPCInfo* ipc, base::string16* name, DWORD attributes, CountedBuffer* info) { if (sizeof(FILE_BASIC_INFORMATION) != info->Size()) return false; @@ -204,7 +204,7 @@ bool FilesystemDispatcher::NtQueryAttributesFile( } bool FilesystemDispatcher::NtQueryFullAttributesFile( - IPCInfo* ipc, std::wstring* name, DWORD attributes, CountedBuffer* info) { + IPCInfo* ipc, base::string16* name, DWORD attributes, CountedBuffer* info) { if (sizeof(FILE_NETWORK_OPEN_INFORMATION) != info->Size()) return false; @@ -257,7 +257,7 @@ bool FilesystemDispatcher::NtSetInformationFile( if (!IsSupportedRenameCall(rename_info, length, info_class)) return false; - std::wstring name; + base::string16 name; name.assign(rename_info->FileName, rename_info->FileNameLength / sizeof(rename_info->FileName[0])); if (!PreProcessName(name, &name)) { diff --git a/sandbox/win/src/filesystem_dispatcher.h b/sandbox/win/src/filesystem_dispatcher.h index b0d9a7a..257e4f7 100644 --- a/sandbox/win/src/filesystem_dispatcher.h +++ b/sandbox/win/src/filesystem_dispatcher.h @@ -6,6 +6,7 @@ #define SANDBOX_SRC_FILESYSTEM_DISPATCHER_H__ #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/sandbox_policy_base.h" @@ -22,29 +23,31 @@ class FilesystemDispatcher : public Dispatcher { private: // Processes IPC requests coming from calls to NtCreateFile in the target. - bool NtCreateFile(IPCInfo* ipc, std::wstring* name, DWORD attributes, + bool NtCreateFile(IPCInfo* ipc, base::string16* name, DWORD attributes, DWORD desired_access, DWORD file_attributes, DWORD share_access, DWORD create_disposition, DWORD create_options); // Processes IPC requests coming from calls to NtOpenFile in the target. - bool NtOpenFile(IPCInfo* ipc, std::wstring* name, DWORD attributes, + bool NtOpenFile(IPCInfo* ipc, base::string16* name, DWORD attributes, DWORD desired_access, DWORD share_access, DWORD create_options); // Processes IPC requests coming from calls to NtQueryAttributesFile in the // target. - bool NtQueryAttributesFile(IPCInfo* ipc, std::wstring* name, DWORD attributes, + bool NtQueryAttributesFile(IPCInfo* ipc, base::string16* name, + DWORD attributes, CountedBuffer* info); // Processes IPC requests coming from calls to NtQueryFullAttributesFile in // the target. - bool NtQueryFullAttributesFile(IPCInfo* ipc, std::wstring* name, + bool NtQueryFullAttributesFile(IPCInfo* ipc, base::string16* name, DWORD attributes, CountedBuffer* info); // Processes IPC requests coming from calls to NtSetInformationFile with the // rename information class. - bool NtSetInformationFile(IPCInfo* ipc, HANDLE handle, CountedBuffer* status, + bool NtSetInformationFile(IPCInfo* ipc, HANDLE handle, + CountedBuffer* status, CountedBuffer* info, DWORD length, DWORD info_class); diff --git a/sandbox/win/src/filesystem_policy.cc b/sandbox/win/src/filesystem_policy.cc index 02707b0..331b9fb 100644 --- a/sandbox/win/src/filesystem_policy.cc +++ b/sandbox/win/src/filesystem_policy.cc @@ -61,7 +61,7 @@ namespace sandbox { bool FileSystemPolicy::GenerateRules(const wchar_t* name, TargetPolicy::Semantics semantics, LowLevelPolicy* policy) { - std::wstring mod_name(name); + base::string16 mod_name(name); if (mod_name.empty()) { return false; } @@ -229,7 +229,7 @@ bool FileSystemPolicy::SetInitialRules(LowLevelPolicy* policy) { bool FileSystemPolicy::CreateFileAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, uint32 desired_access, uint32 file_attributes, @@ -260,7 +260,7 @@ bool FileSystemPolicy::CreateFileAction(EvalResult eval_result, bool FileSystemPolicy::OpenFileAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, uint32 desired_access, uint32 share_access, @@ -292,7 +292,7 @@ bool FileSystemPolicy::OpenFileAction(EvalResult eval_result, bool FileSystemPolicy::QueryAttributesFileAction( EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, FILE_BASIC_INFORMATION* file_info, NTSTATUS* nt_status) { @@ -317,7 +317,7 @@ bool FileSystemPolicy::QueryAttributesFileAction( bool FileSystemPolicy::QueryFullAttributesFileAction( EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, FILE_NETWORK_OPEN_INFORMATION* file_info, NTSTATUS* nt_status) { @@ -372,7 +372,7 @@ bool FileSystemPolicy::SetInformationFileAction( return true; } -bool PreProcessName(const std::wstring& path, std::wstring* new_path) { +bool PreProcessName(const base::string16& path, base::string16* new_path) { ConvertToLongPath(path, new_path); bool reparsed = false; diff --git a/sandbox/win/src/filesystem_policy.h b/sandbox/win/src/filesystem_policy.h index bcedb63..68dffec 100644 --- a/sandbox/win/src/filesystem_policy.h +++ b/sandbox/win/src/filesystem_policy.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/nt_internals.h" #include "sandbox/win/src/policy_low_level.h" @@ -39,7 +40,7 @@ class FileSystemPolicy { // 'file' : The target file or directory. static bool CreateFileAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, uint32 desired_access, uint32 file_attributes, @@ -57,7 +58,7 @@ class FileSystemPolicy { // 'file' : The target file or directory. static bool OpenFileAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, uint32 desired_access, uint32 share_access, @@ -70,7 +71,7 @@ class FileSystemPolicy { // API that is compatible with the IPC-received parameters. static bool QueryAttributesFileAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, FILE_BASIC_INFORMATION* file_info, NTSTATUS* nt_status); @@ -80,7 +81,7 @@ class FileSystemPolicy { static bool QueryFullAttributesFileAction( EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &file, + const base::string16 &file, uint32 attributes, FILE_NETWORK_OPEN_INFORMATION* file_info, NTSTATUS* nt_status); @@ -100,7 +101,7 @@ class FileSystemPolicy { // Expands the path and check if it's a reparse point. Returns false if // we cannot determine or if there is an unexpected error. In that case // the path cannot be trusted. -bool PreProcessName(const std::wstring& path, std::wstring* new_path); +bool PreProcessName(const base::string16& path, base::string16* new_path); } // namespace sandbox diff --git a/sandbox/win/src/handle_policy_test.cc b/sandbox/win/src/handle_policy_test.cc index 11e888a..99b1717 100644 --- a/sandbox/win/src/handle_policy_test.cc +++ b/sandbox/win/src/handle_policy_test.cc @@ -54,8 +54,8 @@ TEST(HandlePolicyTest, DuplicateHandle) { EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"Handle_WaitProcess 30000")); // First test that we fail to open the event. - std::wstring cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", - target.process_id()); + base::string16 cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", + target.process_id()); EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); // Now successfully open the event after adding a duplicate handle rule. @@ -76,8 +76,8 @@ TEST(HandlePolicyTest, DuplicatePeerHandle) { EXPECT_EQ(SBOX_TEST_SUCCEEDED, target.RunTest(L"Handle_WaitProcess 30000")); // First test that we fail to open the event. - std::wstring cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", - target.process_id()); + base::string16 cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", + target.process_id()); EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); // Now successfully open the event after adding a duplicate handle rule. @@ -92,7 +92,7 @@ TEST(HandlePolicyTest, DuplicateBrokerHandle) { TestRunner runner; // First test that we fail to open the event. - std::wstring cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", + base::string16 cmd_line = base::StringPrintf(L"Handle_DuplicateEvent %d", ::GetCurrentProcessId()); EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(cmd_line.c_str())); diff --git a/sandbox/win/src/interception.cc b/sandbox/win/src/interception.cc index 8c897a1..dde5857 100644 --- a/sandbox/win/src/interception.cc +++ b/sandbox/win/src/interception.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" +#include "base/strings/string16.h" #include "base/win/pe_image.h" #include "base/win/windows_version.h" #include "sandbox/win/src/interception_internal.h" @@ -141,7 +142,7 @@ bool InterceptionManager::InitializeInterceptions() { } size_t InterceptionManager::GetBufferSize() const { - std::set<std::wstring> dlls; + std::set<base::string16> dlls; size_t buffer_bytes = 0; std::list<InterceptionData>::const_iterator it = interceptions_.begin(); @@ -202,7 +203,7 @@ bool InterceptionManager::SetupConfigBuffer(void* buffer, size_t buffer_bytes) { continue; } - const std::wstring dll = it->dll; + const base::string16 dll = it->dll; if (!SetupDllInfo(*it, &buffer, &buffer_bytes)) return false; @@ -355,7 +356,7 @@ bool InterceptionManager::IsInterceptionPerformedByChild( if (data.type >= INTERCEPTION_LAST) return false; - std::wstring ntdll(kNtdllName); + base::string16 ntdll(kNtdllName); if (ntdll == data.dll) return false; // ntdll has to be intercepted from the parent @@ -493,7 +494,7 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, std::list<InterceptionData>::iterator it = interceptions_.begin(); for (; it != interceptions_.end(); ++it) { - const std::wstring ntdll(kNtdllName); + const base::string16 ntdll(kNtdllName); if (it->dll != ntdll) break; diff --git a/sandbox/win/src/interception.h b/sandbox/win/src/interception.h index c73b597..739c816 100644 --- a/sandbox/win/src/interception.h +++ b/sandbox/win/src/interception.h @@ -14,6 +14,7 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" +#include "base/strings/string16.h" #include "sandbox/win/src/sandbox_types.h" namespace sandbox { @@ -135,7 +136,7 @@ class InterceptionManager { struct InterceptionData { InterceptionType type; // Interception type. InterceptorId id; // Interceptor id. - std::wstring dll; // Name of dll to intercept. + base::string16 dll; // Name of dll to intercept. std::string function; // Name of function to intercept. std::string interceptor; // Name of interceptor function. const void* interceptor_address; // Interceptor's entry point. diff --git a/sandbox/win/src/ipc_unittest.cc b/sandbox/win/src/ipc_unittest.cc index daca7bb..53b870c 100644 --- a/sandbox/win/src/ipc_unittest.cc +++ b/sandbox/win/src/ipc_unittest.cc @@ -160,7 +160,7 @@ TEST(IPCTest, CrossCallStrPacking) { CrossCallReturn answer; uint32 tag1 = 666; const wchar_t text[] = L"98765 - 43210"; - std::wstring copied_text; + base::string16 copied_text; CrossCallParamsEx* actual_params; CrossCall(client, tag1, text, &answer); @@ -204,7 +204,7 @@ TEST(IPCTest, CrossCallStrPacking) { EXPECT_STREQ(text, copied_text.c_str()); param_size = 1; - std::wstring copied_text_p0, copied_text_p2; + base::string16 copied_text_p0, copied_text_p2; const wchar_t text2[] = L"AeFG"; CrossCall(client, tag1, text2, null_text, text, &answer); diff --git a/sandbox/win/src/named_pipe_dispatcher.cc b/sandbox/win/src/named_pipe_dispatcher.cc index c3f9851..54b3162 100644 --- a/sandbox/win/src/named_pipe_dispatcher.cc +++ b/sandbox/win/src/named_pipe_dispatcher.cc @@ -40,7 +40,7 @@ bool NamedPipeDispatcher::SetupService(InterceptionManager* manager, } bool NamedPipeDispatcher::CreateNamedPipe( - IPCInfo* ipc, std::wstring* name, DWORD open_mode, DWORD pipe_mode, + IPCInfo* ipc, base::string16* name, DWORD open_mode, DWORD pipe_mode, DWORD max_instances, DWORD out_buffer_size, DWORD in_buffer_size, DWORD default_timeout) { const wchar_t* pipe_name = name->c_str(); diff --git a/sandbox/win/src/named_pipe_dispatcher.h b/sandbox/win/src/named_pipe_dispatcher.h index 0d03b2e..0707284 100644 --- a/sandbox/win/src/named_pipe_dispatcher.h +++ b/sandbox/win/src/named_pipe_dispatcher.h @@ -6,6 +6,7 @@ #define SANDBOX_SRC_NAMED_PIPE_DISPATCHER_H__ #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/sandbox_policy_base.h" @@ -23,7 +24,7 @@ class NamedPipeDispatcher : public Dispatcher { private: // Processes IPC requests coming from calls to CreateNamedPipeW() in the // target. - bool CreateNamedPipe(IPCInfo* ipc, std::wstring* name, DWORD open_mode, + bool CreateNamedPipe(IPCInfo* ipc, base::string16* name, DWORD open_mode, DWORD pipe_mode, DWORD max_instances, DWORD out_buffer_size, DWORD in_buffer_size, DWORD default_timeout); diff --git a/sandbox/win/src/named_pipe_policy.cc b/sandbox/win/src/named_pipe_policy.cc index 0f620b1..eee719e 100644 --- a/sandbox/win/src/named_pipe_policy.cc +++ b/sandbox/win/src/named_pipe_policy.cc @@ -60,7 +60,7 @@ bool NamedPipePolicy::GenerateRules(const wchar_t* name, DWORD NamedPipePolicy::CreateNamedPipeAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &name, + const base::string16 &name, DWORD open_mode, DWORD pipe_mode, DWORD max_instances, DWORD out_buffer_size, diff --git a/sandbox/win/src/named_pipe_policy.h b/sandbox/win/src/named_pipe_policy.h index 1ba07b8..c904aa3 100644 --- a/sandbox/win/src/named_pipe_policy.h +++ b/sandbox/win/src/named_pipe_policy.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/policy_low_level.h" #include "sandbox/win/src/sandbox_policy.h" @@ -31,7 +32,7 @@ class NamedPipePolicy { // Processes a 'CreateNamedPipeW()' request from the target. static DWORD CreateNamedPipeAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &name, + const base::string16 &name, DWORD open_mode, DWORD pipe_mode, DWORD max_instances, DWORD out_buffer_size, diff --git a/sandbox/win/src/policy_low_level.cc b/sandbox/win/src/policy_low_level.cc index 686caa1..b6331b9 100644 --- a/sandbox/win/src/policy_low_level.cc +++ b/sandbox/win/src/policy_low_level.cc @@ -151,7 +151,7 @@ PolicyRule::PolicyRule(const PolicyRule& other) { bool PolicyRule::GenStringOpcode(RuleType rule_type, StringMatchOptions match_opts, uint16 parameter, int state, bool last_call, - int* skip_count, std::wstring* fragment) { + int* skip_count, base::string16* fragment) { // The last opcode must: // 1) Always clear the context. @@ -226,7 +226,7 @@ bool PolicyRule::AddStringMatch(RuleType rule_type, int16 parameter, uint32 last_char = kLastCharIsNone; int state = PENDING_NONE; int skip_count = 0; // counts how many '?' we have seen in a row. - std::wstring fragment; // accumulates the non-wildcard part of the string. + base::string16 fragment; // accumulates the non-wildcard part. while (L'\0' != *current_char) { switch (*current_char) { diff --git a/sandbox/win/src/policy_low_level.h b/sandbox/win/src/policy_low_level.h index 025a133..ca8b36f 100644 --- a/sandbox/win/src/policy_low_level.h +++ b/sandbox/win/src/policy_low_level.h @@ -8,6 +8,7 @@ #include <list> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/ipc_tags.h" #include "sandbox/win/src/policy_engine_params.h" #include "sandbox/win/src/policy_engine_opcodes.h" @@ -163,7 +164,7 @@ class PolicyRule { // in AddStringMatch. bool GenStringOpcode(RuleType rule_type, StringMatchOptions match_opts, uint16 parameter, int state, bool last_call, - int* skip_count, std::wstring* fragment); + int* skip_count, base::string16* fragment); // Loop over all generated opcodes and copy them to increasing memory // addresses from opcode_start and copy the extra data (strings usually) into diff --git a/sandbox/win/src/policy_target_test.cc b/sandbox/win/src/policy_target_test.cc index 1e29df2..dba670a 100644 --- a/sandbox/win/src/policy_target_test.cc +++ b/sandbox/win/src/policy_target_test.cc @@ -229,7 +229,7 @@ TEST(PolicyTargetTest, DesktopPolicy) { wchar_t prog_name[MAX_PATH]; GetModuleFileNameW(NULL, prog_name, MAX_PATH); - std::wstring arguments(L"\""); + base::string16 arguments(L"\""); arguments += prog_name; arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. @@ -256,7 +256,7 @@ TEST(PolicyTargetTest, DesktopPolicy) { EXPECT_NE(::GetThreadDesktop(target.thread_id()), ::GetThreadDesktop(::GetCurrentThreadId())); - std::wstring desktop_name = policy->GetAlternateDesktop(); + base::string16 desktop_name = policy->GetAlternateDesktop(); HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE); EXPECT_TRUE(NULL != desk); EXPECT_TRUE(::CloseDesktop(desk)); @@ -292,7 +292,7 @@ TEST(PolicyTargetTest, WinstaPolicy) { wchar_t prog_name[MAX_PATH]; GetModuleFileNameW(NULL, prog_name, MAX_PATH); - std::wstring arguments(L"\""); + base::string16 arguments(L"\""); arguments += prog_name; arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. @@ -319,11 +319,11 @@ TEST(PolicyTargetTest, WinstaPolicy) { EXPECT_NE(::GetThreadDesktop(target.thread_id()), ::GetThreadDesktop(::GetCurrentThreadId())); - std::wstring desktop_name = policy->GetAlternateDesktop(); + base::string16 desktop_name = policy->GetAlternateDesktop(); ASSERT_FALSE(desktop_name.empty()); // Make sure there is a backslash, for the window station name. - EXPECT_NE(desktop_name.find_first_of(L'\\'), std::wstring::npos); + EXPECT_NE(desktop_name.find_first_of(L'\\'), base::string16::npos); // Isolate the desktop name. desktop_name = desktop_name.substr(desktop_name.find_first_of(L'\\') + 1); diff --git a/sandbox/win/src/process_thread_dispatcher.cc b/sandbox/win/src/process_thread_dispatcher.cc index 4525b83..39b4132 100644 --- a/sandbox/win/src/process_thread_dispatcher.cc +++ b/sandbox/win/src/process_thread_dispatcher.cc @@ -29,20 +29,20 @@ namespace { // "c:\program files\test param" will first try to launch c:\program.exe then // c:\program files\test.exe. We don't do that, we stop after at the first // space when there is no quotes. -std::wstring GetPathFromCmdLine(const std::wstring &cmd_line) { - std::wstring exe_name; +base::string16 GetPathFromCmdLine(const base::string16 &cmd_line) { + base::string16 exe_name; // Check if it starts with '"'. if (cmd_line[0] == L'\"') { // Find the position of the second '"', this terminates the path. - std::wstring::size_type pos = cmd_line.find(L'\"', 1); - if (std::wstring::npos == pos) + base::string16::size_type pos = cmd_line.find(L'\"', 1); + if (base::string16::npos == pos) return cmd_line; exe_name = cmd_line.substr(1, pos - 1); } else { // There is no '"', that means that the appname is terminated at the // first space. - std::wstring::size_type pos = cmd_line.find(L' '); - if (std::wstring::npos == pos) { + base::string16::size_type pos = cmd_line.find(L' '); + if (base::string16::npos == pos) { // There is no space, the cmd_line contains only the app_name exe_name = cmd_line; } else { @@ -55,7 +55,7 @@ std::wstring GetPathFromCmdLine(const std::wstring &cmd_line) { // Returns true is the path in parameter is relative. False if it's // absolute. -bool IsPathRelative(const std::wstring &path) { +bool IsPathRelative(const base::string16 &path) { // A path is Relative if it's not a UNC path beginnning with \\ or a // path beginning with a drive. (i.e. X:\) if (path.find(L"\\\\") == 0 || path.find(L":\\") == 1) @@ -64,8 +64,8 @@ bool IsPathRelative(const std::wstring &path) { } // Converts a relative path to an absolute path. -bool ConvertToAbsolutePath(const std::wstring& child_current_directory, - bool use_env_path, std::wstring *path) { +bool ConvertToAbsolutePath(const base::string16& child_current_directory, + bool use_env_path, base::string16 *path) { wchar_t file_buffer[MAX_PATH]; wchar_t *file_part = NULL; @@ -201,15 +201,15 @@ bool ThreadProcessDispatcher::NtOpenProcessTokenEx(IPCInfo* ipc, HANDLE process, return true; } -bool ThreadProcessDispatcher::CreateProcessW(IPCInfo* ipc, std::wstring* name, - std::wstring* cmd_line, - std::wstring* cur_dir, +bool ThreadProcessDispatcher::CreateProcessW(IPCInfo* ipc, base::string16* name, + base::string16* cmd_line, + base::string16* cur_dir, CountedBuffer* info) { if (sizeof(PROCESS_INFORMATION) != info->Size()) return false; // Check if there is an application name. - std::wstring exe_name; + base::string16 exe_name; if (!name->empty()) exe_name = *name; else diff --git a/sandbox/win/src/process_thread_dispatcher.h b/sandbox/win/src/process_thread_dispatcher.h index 1cc5743..fba2754 100644 --- a/sandbox/win/src/process_thread_dispatcher.h +++ b/sandbox/win/src/process_thread_dispatcher.h @@ -6,6 +6,7 @@ #define SANDBOX_SRC_PROCESS_THREAD_DISPATCHER_H_ #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/sandbox_policy_base.h" @@ -35,8 +36,11 @@ class ThreadProcessDispatcher : public Dispatcher { DWORD attributes); // Processes IPC requests coming from calls to CreateProcessW() in the target. - bool CreateProcessW(IPCInfo* ipc, std::wstring* name, std::wstring* cmd_line, - std::wstring* cur_dir, CountedBuffer* info); + bool CreateProcessW(IPCInfo* ipc, + base::string16* name, + base::string16* cmd_line, + base::string16* cur_dir, + CountedBuffer* info); PolicyBase* policy_base_; DISALLOW_COPY_AND_ASSIGN(ThreadProcessDispatcher); diff --git a/sandbox/win/src/process_thread_policy.cc b/sandbox/win/src/process_thread_policy.cc index 9493b9e..85a2f97 100644 --- a/sandbox/win/src/process_thread_policy.cc +++ b/sandbox/win/src/process_thread_policy.cc @@ -217,8 +217,8 @@ NTSTATUS ProcessPolicy::OpenProcessTokenExAction(const ClientInfo& client_info, DWORD ProcessPolicy::CreateProcessWAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &app_name, - const std::wstring &command_line, + const base::string16 &app_name, + const base::string16 &command_line, PROCESS_INFORMATION* process_info) { // The only action supported is ASK_BROKER which means create the process. if (GIVE_ALLACCESS != eval_result && GIVE_READONLY != eval_result) { diff --git a/sandbox/win/src/process_thread_policy.h b/sandbox/win/src/process_thread_policy.h index c35c52b5..2871dca 100644 --- a/sandbox/win/src/process_thread_policy.h +++ b/sandbox/win/src/process_thread_policy.h @@ -10,6 +10,7 @@ #include "sandbox/win/src/policy_low_level.h" #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/sandbox_policy.h" @@ -71,8 +72,8 @@ class ProcessPolicy { // 'command_line' : The command line passed to the created process. static DWORD CreateProcessWAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &app_name, - const std::wstring &command_line, + const base::string16 &app_name, + const base::string16 &command_line, PROCESS_INFORMATION* process_info); }; diff --git a/sandbox/win/src/registry_dispatcher.cc b/sandbox/win/src/registry_dispatcher.cc index f4dc5f5..2a92497 100644 --- a/sandbox/win/src/registry_dispatcher.cc +++ b/sandbox/win/src/registry_dispatcher.cc @@ -20,8 +20,8 @@ namespace { // Builds a path using the root directory and the name. -bool GetCompletePath(HANDLE root, const std::wstring& name, - std::wstring* complete_name) { +bool GetCompletePath(HANDLE root, const base::string16& name, + base::string16* complete_name) { if (root) { if (!sandbox::GetPathFromHandle(root, complete_name)) return false; @@ -72,10 +72,10 @@ bool RegistryDispatcher::SetupService(InterceptionManager* manager, } bool RegistryDispatcher::NtCreateKey( - IPCInfo* ipc, std::wstring* name, DWORD attributes, HANDLE root, + IPCInfo* ipc, base::string16* name, DWORD attributes, HANDLE root, DWORD desired_access, DWORD title_index, DWORD create_options) { base::win::ScopedHandle root_handle; - std::wstring real_path = *name; + base::string16 real_path = *name; // If there is a root directory, we need to duplicate the handle to make // it valid in this process. @@ -117,11 +117,11 @@ bool RegistryDispatcher::NtCreateKey( return true; } -bool RegistryDispatcher::NtOpenKey(IPCInfo* ipc, std::wstring* name, +bool RegistryDispatcher::NtOpenKey(IPCInfo* ipc, base::string16* name, DWORD attributes, HANDLE root, DWORD desired_access) { base::win::ScopedHandle root_handle; - std::wstring real_path = *name; + base::string16 real_path = *name; // If there is a root directory, we need to duplicate the handle to make // it valid in this process. diff --git a/sandbox/win/src/registry_dispatcher.h b/sandbox/win/src/registry_dispatcher.h index 782a070..39f5f54 100644 --- a/sandbox/win/src/registry_dispatcher.h +++ b/sandbox/win/src/registry_dispatcher.h @@ -6,6 +6,7 @@ #define SANDBOX_SRC_REGISTRY_DISPATCHER_H_ #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/sandbox_policy_base.h" @@ -22,12 +23,12 @@ class RegistryDispatcher : public Dispatcher { private: // Processes IPC requests coming from calls to NtCreateKey in the target. - bool NtCreateKey(IPCInfo* ipc, std::wstring* name, DWORD attributes, + bool NtCreateKey(IPCInfo* ipc, base::string16* name, DWORD attributes, HANDLE root, DWORD desired_access, DWORD title_index, DWORD create_options); // Processes IPC requests coming from calls to NtOpenKey in the target. - bool NtOpenKey(IPCInfo* ipc, std::wstring* name, DWORD attributes, + bool NtOpenKey(IPCInfo* ipc, base::string16* name, DWORD attributes, HANDLE root, DWORD desired_access); PolicyBase* policy_base_; diff --git a/sandbox/win/src/registry_policy.cc b/sandbox/win/src/registry_policy.cc index 37e6ddb..632525a 100644 --- a/sandbox/win/src/registry_policy.cc +++ b/sandbox/win/src/registry_policy.cc @@ -117,7 +117,7 @@ namespace sandbox { bool RegistryPolicy::GenerateRules(const wchar_t* name, TargetPolicy::Semantics semantics, LowLevelPolicy* policy) { - std::wstring resovled_name(name); + base::string16 resovled_name(name); if (resovled_name.empty()) { return false; } @@ -166,7 +166,7 @@ bool RegistryPolicy::GenerateRules(const wchar_t* name, bool RegistryPolicy::CreateKeyAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &key, + const base::string16 &key, uint32 attributes, HANDLE root_directory, uint32 desired_access, @@ -200,7 +200,7 @@ bool RegistryPolicy::CreateKeyAction(EvalResult eval_result, bool RegistryPolicy::OpenKeyAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &key, + const base::string16 &key, uint32 attributes, HANDLE root_directory, uint32 desired_access, diff --git a/sandbox/win/src/registry_policy.h b/sandbox/win/src/registry_policy.h index 8badde2..69af841 100644 --- a/sandbox/win/src/registry_policy.h +++ b/sandbox/win/src/registry_policy.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/nt_internals.h" #include "sandbox/win/src/policy_low_level.h" @@ -30,7 +31,7 @@ class RegistryPolicy { // API that is compatible with the IPC-received parameters. static bool CreateKeyAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &key, + const base::string16 &key, uint32 attributes, HANDLE root_directory, uint32 desired_access, @@ -44,7 +45,7 @@ class RegistryPolicy { // API that is compatible with the IPC-received parameters. static bool OpenKeyAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &key, + const base::string16 &key, uint32 attributes, HANDLE root_directory, uint32 desired_access, diff --git a/sandbox/win/src/restricted_token.cc b/sandbox/win/src/restricted_token.cc index 6948d8a..64973e9 100644 --- a/sandbox/win/src/restricted_token.cc +++ b/sandbox/win/src/restricted_token.cc @@ -277,7 +277,7 @@ unsigned RestrictedToken::AddUserSidForDenyOnly() { } unsigned RestrictedToken::DeleteAllPrivileges( - const std::vector<std::wstring> *exceptions) { + const std::vector<base::string16> *exceptions) { DCHECK(init_); if (!init_) return ERROR_NO_TOKEN; diff --git a/sandbox/win/src/restricted_token.h b/sandbox/win/src/restricted_token.h index 4327856..6d8e550 100644 --- a/sandbox/win/src/restricted_token.h +++ b/sandbox/win/src/restricted_token.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/restricted_token_utils.h" #include "sandbox/win/src/security_level.h" #include "sandbox/win/src/sid.h" @@ -119,11 +120,11 @@ class RestrictedToken { // the error. // // Sample usage: - // std::vector<std::wstring> privilege_exceptions; + // std::vector<base::string16> privilege_exceptions; // privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); // restricted_token.DeleteAllPrivileges(&privilege_exceptions); unsigned DeleteAllPrivileges( - const std::vector<std::wstring> *exceptions); + const std::vector<base::string16> *exceptions); // Adds a privilege to the list of privileges to remove in the restricted // token. diff --git a/sandbox/win/src/restricted_token_unittest.cc b/sandbox/win/src/restricted_token_unittest.cc index 4948ad1..480106e 100644 --- a/sandbox/win/src/restricted_token_unittest.cc +++ b/sandbox/win/src/restricted_token_unittest.cc @@ -353,7 +353,7 @@ TEST(RestrictedTokenTest, DeleteAllPrivilegesException) { RestrictedToken token; HANDLE token_handle = NULL; - std::vector<std::wstring> exceptions; + std::vector<base::string16> exceptions; exceptions.push_back(SE_CHANGE_NOTIFY_NAME); ASSERT_EQ(ERROR_SUCCESS, token.Init(NULL)); diff --git a/sandbox/win/src/restricted_token_utils.cc b/sandbox/win/src/restricted_token_utils.cc index f30a8a6..f3b1859 100644 --- a/sandbox/win/src/restricted_token_utils.cc +++ b/sandbox/win/src/restricted_token_utils.cc @@ -29,7 +29,7 @@ DWORD CreateRestrictedToken(HANDLE *token_handle, RestrictedToken restricted_token; restricted_token.Init(NULL); // Initialized with the current process token - std::vector<std::wstring> privilege_exceptions; + std::vector<base::string16> privilege_exceptions; std::vector<Sid> sid_exceptions; bool deny_sids = true; @@ -237,7 +237,7 @@ DWORD SetObjectIntegrityLabel(HANDLE handle, SE_OBJECT_TYPE type, const wchar_t* ace_access, const wchar_t* integrity_level_sid) { // Build the SDDL string for the label. - std::wstring sddl = L"S:("; // SDDL for a SACL. + base::string16 sddl = L"S:("; // SDDL for a SACL. sddl += SDDL_MANDATORY_LABEL; // Ace Type is "Mandatory Label". sddl += L";;"; // No Ace Flags. sddl += ace_access; // Add the ACE access. diff --git a/sandbox/win/src/sandbox_policy.h b/sandbox/win/src/sandbox_policy.h index 733356a..a9f1245 100644 --- a/sandbox/win/src/sandbox_policy.h +++ b/sandbox/win/src/sandbox_policy.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/security_level.h" @@ -129,7 +130,7 @@ class TargetPolicy { // Returns the name of the alternate desktop used. If an alternate window // station is specified, the name is prepended by the window station name, // followed by a backslash. - virtual std::wstring GetAlternateDesktop() const = 0; + virtual base::string16 GetAlternateDesktop() const = 0; // Precreates the desktop and window station, if any. virtual ResultCode CreateAlternateDesktop(bool alternate_winstation) = 0; diff --git a/sandbox/win/src/sandbox_utils.cc b/sandbox/win/src/sandbox_utils.cc index 9c561c9..8631a7c 100644 --- a/sandbox/win/src/sandbox_utils.cc +++ b/sandbox/win/src/sandbox_utils.cc @@ -19,7 +19,7 @@ bool IsXPSP2OrLater() { (base::win::OSInfo::GetInstance()->service_pack().major >= 2)); } -void InitObjectAttribs(const std::wstring& name, +void InitObjectAttribs(const base::string16& name, ULONG attributes, HANDLE root, OBJECT_ATTRIBUTES* obj_attr, diff --git a/sandbox/win/src/sandbox_utils.h b/sandbox/win/src/sandbox_utils.h index 9a90675..3043597 100644 --- a/sandbox/win/src/sandbox_utils.h +++ b/sandbox/win/src/sandbox_utils.h @@ -9,6 +9,7 @@ #include <string> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/nt_internals.h" namespace sandbox { @@ -16,7 +17,7 @@ namespace sandbox { // Returns true if the current OS is Windows XP SP2 or later. bool IsXPSP2OrLater(); -void InitObjectAttribs(const std::wstring& name, +void InitObjectAttribs(const base::string16& name, ULONG attributes, HANDLE root, OBJECT_ATTRIBUTES* obj_attr, diff --git a/sandbox/win/src/sharedmem_ipc_server.cc b/sandbox/win/src/sharedmem_ipc_server.cc index e2a30c72..bf8761e 100644 --- a/sandbox/win/src/sharedmem_ipc_server.cc +++ b/sandbox/win/src/sharedmem_ipc_server.cc @@ -131,7 +131,7 @@ void ReleaseArgs(const IPCParams* ipc_params, void* args[kMaxIpcParams]) { for (size_t i = 0; i < kMaxIpcParams; i++) { switch (ipc_params->args[i]) { case WCHAR_TYPE: { - delete reinterpret_cast<std::wstring*>(args[i]); + delete reinterpret_cast<base::string16*>(args[i]); args[i] = NULL; break; } @@ -159,7 +159,7 @@ bool GetArgs(CrossCallParamsEx* params, IPCParams* ipc_params, ipc_params->args[i] = type; switch (type) { case WCHAR_TYPE: { - scoped_ptr<std::wstring> data(new std::wstring); + scoped_ptr<base::string16> data(new base::string16); if (!params->GetParameterStr(i, data.get())) { args[i] = 0; ReleaseArgs(ipc_params, args); diff --git a/sandbox/win/src/sync_dispatcher.cc b/sandbox/win/src/sync_dispatcher.cc index 3769fc6..d4b36d5 100644 --- a/sandbox/win/src/sync_dispatcher.cc +++ b/sandbox/win/src/sync_dispatcher.cc @@ -43,7 +43,7 @@ bool SyncDispatcher::SetupService(InterceptionManager* manager, return false; } -bool SyncDispatcher::CreateEvent(IPCInfo* ipc, std::wstring* name, +bool SyncDispatcher::CreateEvent(IPCInfo* ipc, base::string16* name, DWORD event_type, DWORD initial_state) { const wchar_t* event_name = name->c_str(); CountedParameterSet<NameBased> params; @@ -61,7 +61,7 @@ bool SyncDispatcher::CreateEvent(IPCInfo* ipc, std::wstring* name, return true; } -bool SyncDispatcher::OpenEvent(IPCInfo* ipc, std::wstring* name, +bool SyncDispatcher::OpenEvent(IPCInfo* ipc, base::string16* name, DWORD desired_access) { const wchar_t* event_name = name->c_str(); diff --git a/sandbox/win/src/sync_dispatcher.h b/sandbox/win/src/sync_dispatcher.h index 1d1b978..db44ba4 100644 --- a/sandbox/win/src/sync_dispatcher.h +++ b/sandbox/win/src/sync_dispatcher.h @@ -6,6 +6,7 @@ #define SANDBOX_SRC_SYNC_DISPATCHER_H_ #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/sandbox_policy_base.h" @@ -22,11 +23,11 @@ class SyncDispatcher : public Dispatcher { private: // Processes IPC requests coming from calls to CreateEvent in the target. - bool CreateEvent(IPCInfo* ipc, std::wstring* name, DWORD event_type, + bool CreateEvent(IPCInfo* ipc, base::string16* name, DWORD event_type, DWORD initial_state); // Processes IPC requests coming from calls to OpenEvent in the target. - bool OpenEvent(IPCInfo* ipc, std::wstring* name, DWORD desired_access); + bool OpenEvent(IPCInfo* ipc, base::string16* name, DWORD desired_access); PolicyBase* policy_base_; DISALLOW_COPY_AND_ASSIGN(SyncDispatcher); diff --git a/sandbox/win/src/sync_policy.cc b/sandbox/win/src/sync_policy.cc index e3b6530..7b18fe7 100644 --- a/sandbox/win/src/sync_policy.cc +++ b/sandbox/win/src/sync_policy.cc @@ -21,9 +21,9 @@ namespace sandbox { // Provides functionality to resolve a symbolic link within the object // directory passed in. -NTSTATUS ResolveSymbolicLink(const std::wstring& directory_name, - const std::wstring& name, - std::wstring* target) { +NTSTATUS ResolveSymbolicLink(const base::string16& directory_name, + const base::string16& name, + base::string16* target) { NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL; ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject); @@ -107,7 +107,7 @@ NTSTATUS GetBaseNamedObjectsDirectory(HANDLE* directory) { DWORD session_id = 0; ProcessIdToSessionId(::GetCurrentProcessId(), &session_id); - std::wstring base_named_objects_path; + base::string16 base_named_objects_path; NTSTATUS status = ResolveSymbolicLink(L"\\Sessions\\BNOLINKS", base::StringPrintf(L"%d", session_id), @@ -133,7 +133,7 @@ NTSTATUS GetBaseNamedObjectsDirectory(HANDLE* directory) { bool SyncPolicy::GenerateRules(const wchar_t* name, TargetPolicy::Semantics semantics, LowLevelPolicy* policy) { - std::wstring mod_name(name); + base::string16 mod_name(name); if (mod_name.empty()) { return false; } @@ -178,7 +178,7 @@ bool SyncPolicy::GenerateRules(const wchar_t* name, DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &event_name, + const base::string16 &event_name, uint32 event_type, uint32 initial_state, HANDLE *handle) { @@ -216,7 +216,7 @@ DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, DWORD SyncPolicy::OpenEventAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &event_name, + const base::string16 &event_name, uint32 desired_access, HANDLE *handle) { NtOpenEventFunction NtOpenEvent = NULL; diff --git a/sandbox/win/src/sync_policy.h b/sandbox/win/src/sync_policy.h index 93aef64..4383998 100644 --- a/sandbox/win/src/sync_policy.h +++ b/sandbox/win/src/sync_policy.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/strings/string16.h" #include "sandbox/win/src/crosscall_server.h" #include "sandbox/win/src/nt_internals.h" #include "sandbox/win/src/policy_low_level.h" @@ -34,13 +35,13 @@ class SyncPolicy { // eval_result is the desired policy action to accomplish. static DWORD CreateEventAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &event_name, + const base::string16 &event_name, uint32 event_type, uint32 initial_state, HANDLE *handle); static DWORD OpenEventAction(EvalResult eval_result, const ClientInfo& client_info, - const std::wstring &event_name, + const base::string16 &event_name, uint32 desired_access, HANDLE *handle); }; diff --git a/sandbox/win/src/win_utils.cc b/sandbox/win/src/win_utils.cc index cb366a6..53a12a4 100644 --- a/sandbox/win/src/win_utils.cc +++ b/sandbox/win/src/win_utils.cc @@ -33,7 +33,7 @@ const KnownReservedKey kKnownKey[] = { }; // Returns true if the provided path points to a pipe. -bool IsPipe(const std::wstring& path) { +bool IsPipe(const base::string16& path) { size_t start = 0; if (0 == path.compare(0, sandbox::kNTPrefixLen, sandbox::kNTPrefix)) start = sandbox::kNTPrefixLen; @@ -46,7 +46,7 @@ bool IsPipe(const std::wstring& path) { namespace sandbox { -HKEY GetReservedKeyFromName(const std::wstring& name) { +HKEY GetReservedKeyFromName(const base::string16& name) { for (size_t i = 0; i < arraysize(kKnownKey); ++i) { if (name == kKnownKey[i].name) return kKnownKey[i].key; @@ -55,7 +55,7 @@ HKEY GetReservedKeyFromName(const std::wstring& name) { return NULL; } -bool ResolveRegistryName(std::wstring name, std::wstring* resolved_name) { +bool ResolveRegistryName(base::string16 name, base::string16* resolved_name) { for (size_t i = 0; i < arraysize(kKnownKey); ++i) { if (name.find(kKnownKey[i].name) == 0) { HKEY key; @@ -79,8 +79,8 @@ bool ResolveRegistryName(std::wstring name, std::wstring* resolved_name) { return false; } -DWORD IsReparsePoint(const std::wstring& full_path, bool* result) { - std::wstring path = full_path; +DWORD IsReparsePoint(const base::string16& full_path, bool* result) { + base::string16 path = full_path; // Remove the nt prefix. if (0 == path.compare(0, kNTPrefixLen, kNTPrefix)) @@ -92,7 +92,7 @@ DWORD IsReparsePoint(const std::wstring& full_path, bool* result) { return ERROR_SUCCESS; } - std::wstring::size_type last_pos = std::wstring::npos; + base::string16::size_type last_pos = base::string16::npos; do { path = path.substr(0, last_pos); @@ -114,7 +114,7 @@ DWORD IsReparsePoint(const std::wstring& full_path, bool* result) { } last_pos = path.rfind(L'\\'); - } while (last_pos != std::wstring::npos); + } while (last_pos != base::string16::npos); *result = false; return ERROR_SUCCESS; @@ -123,14 +123,14 @@ DWORD IsReparsePoint(const std::wstring& full_path, bool* result) { // We get a |full_path| of the form \??\c:\some\foo\bar, and the name that // we'll get from |handle| will be \device\harddiskvolume1\some\foo\bar. bool SameObject(HANDLE handle, const wchar_t* full_path) { - std::wstring path(full_path); + base::string16 path(full_path); DCHECK_NT(!path.empty()); // Check if it's a pipe. if (IsPipe(path)) return true; - std::wstring actual_path; + base::string16 actual_path; if (!GetPathFromHandle(handle, &actual_path)) return false; @@ -145,7 +145,7 @@ bool SameObject(HANDLE handle, const wchar_t* full_path) { // Look for the drive letter. size_t colon_pos = path.find(L':'); - if (colon_pos == 0 || colon_pos == std::wstring::npos) + if (colon_pos == 0 || colon_pos == base::string16::npos) return false; // Only one character for the drive. @@ -180,11 +180,11 @@ bool SameObject(HANDLE handle, const wchar_t* full_path) { return true; } -bool ConvertToLongPath(const std::wstring& short_path, - std::wstring* long_path) { +bool ConvertToLongPath(const base::string16& short_path, + base::string16* long_path) { // Check if the path is a NT path. bool is_nt_path = false; - std::wstring path = short_path; + base::string16 path = short_path; if (0 == path.compare(0, kNTPrefixLen, kNTPrefix)) { path = path.substr(kNTPrefixLen); is_nt_path = true; @@ -206,12 +206,12 @@ bool ConvertToLongPath(const std::wstring& short_path, ERROR_PATH_NOT_FOUND == last_error || ERROR_INVALID_NAME == last_error)) { // The file does not exist, but maybe a sub path needs to be expanded. - std::wstring::size_type last_slash = path.rfind(L'\\'); - if (std::wstring::npos == last_slash) + base::string16::size_type last_slash = path.rfind(L'\\'); + if (base::string16::npos == last_slash) return false; - std::wstring begin = path.substr(0, last_slash); - std::wstring end = path.substr(last_slash); + base::string16 begin = path.substr(0, last_slash); + base::string16 end = path.substr(last_slash); if (!ConvertToLongPath(begin, &begin)) return false; @@ -236,7 +236,7 @@ bool ConvertToLongPath(const std::wstring& short_path, return false; } -bool GetPathFromHandle(HANDLE handle, std::wstring* path) { +bool GetPathFromHandle(HANDLE handle, base::string16* path) { NtQueryObjectFunction NtQueryObject = NULL; ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); @@ -265,7 +265,8 @@ bool GetPathFromHandle(HANDLE handle, std::wstring* path) { return true; } -bool GetNtPathFromWin32Path(const std::wstring& path, std::wstring* nt_path) { +bool GetNtPathFromWin32Path(const base::string16& path, + base::string16* nt_path) { HANDLE file = ::CreateFileW(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); diff --git a/sandbox/win/src/win_utils.h b/sandbox/win/src/win_utils.h index a80bb81..9b58d1d 100644 --- a/sandbox/win/src/win_utils.h +++ b/sandbox/win/src/win_utils.h @@ -7,7 +7,9 @@ #include <windows.h> #include <string> + #include "base/basictypes.h" +#include "base/strings/string16.h" namespace sandbox { @@ -65,35 +67,37 @@ class SingletonBase { // Convert a short path (C:\path~1 or \\??\\c:\path~1) to the long version of // the path. If the path is not a valid filesystem path, the function returns // false and the output parameter is not modified. -bool ConvertToLongPath(const std::wstring& short_path, std::wstring* long_path); +bool ConvertToLongPath(const base::string16& short_path, + base::string16* long_path); // Sets result to true if the path contains a reparse point. The return value // is ERROR_SUCCESS when the function succeeds or the appropriate error code // when the function fails. // This function is not smart. It looks for each element in the path and // returns true if any of them is a reparse point. -DWORD IsReparsePoint(const std::wstring& full_path, bool* result); +DWORD IsReparsePoint(const base::string16& full_path, bool* result); // Returns true if the handle corresponds to the object pointed by this path. bool SameObject(HANDLE handle, const wchar_t* full_path); // Resolves a handle to an nt path. Returns true if the handle can be resolved. -bool GetPathFromHandle(HANDLE handle, std::wstring* path); +bool GetPathFromHandle(HANDLE handle, base::string16* path); // Resolves a win32 path to an nt path using GetPathFromHandle. The path must // exist. Returs true if the translation was succesful. -bool GetNtPathFromWin32Path(const std::wstring& path, std::wstring* nt_path); +bool GetNtPathFromWin32Path(const base::string16& path, + base::string16* nt_path); // Translates a reserved key name to its handle. // For example "HKEY_LOCAL_MACHINE" returns HKEY_LOCAL_MACHINE. // Returns NULL if the name does not represent any reserved key name. -HKEY GetReservedKeyFromName(const std::wstring& name); +HKEY GetReservedKeyFromName(const base::string16& name); // Resolves a user-readable registry path to a system-readable registry path. // For example, HKEY_LOCAL_MACHINE\\Software\\microsoft is translated to // \\registry\\machine\\software\\microsoft. Returns false if the path // cannot be resolved. -bool ResolveRegistryName(std::wstring name, std::wstring* resolved_name); +bool ResolveRegistryName(base::string16 name, base::string16* resolved_name); // Writes |length| bytes from the provided |buffer| into the address space of // |child_process|, at the specified |address|, preserving the original write diff --git a/sandbox/win/src/win_utils_unittest.cc b/sandbox/win/src/win_utils_unittest.cc index 7265316..3736654 100644 --- a/sandbox/win/src/win_utils_unittest.cc +++ b/sandbox/win/src/win_utils_unittest.cc @@ -27,10 +27,10 @@ TEST(WinUtils, IsReparsePoint) { EXPECT_FALSE(result); // We have to fix Bug 32224 to pass this test. - std::wstring not_found = std::wstring(my_folder) + L"\\foo\\bar"; + base::string16 not_found = base::string16(my_folder) + L"\\foo\\bar"; // EXPECT_EQ(ERROR_PATH_NOT_FOUND, IsReparsePoint(not_found, &result)); - std::wstring new_file = std::wstring(my_folder) + L"\\foo"; + base::string16 new_file = base::string16(my_folder) + L"\\foo"; EXPECT_EQ(ERROR_SUCCESS, IsReparsePoint(new_file, &result)); EXPECT_FALSE(result); @@ -40,7 +40,7 @@ TEST(WinUtils, IsReparsePoint) { OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); EXPECT_NE(INVALID_HANDLE_VALUE, dir); - std::wstring temp_dir_nt = std::wstring(L"\\??\\") + temp_directory; + base::string16 temp_dir_nt = base::string16(L"\\??\\") + temp_directory; EXPECT_TRUE(SetReparsePoint(dir, temp_dir_nt.c_str())); EXPECT_EQ(ERROR_SUCCESS, IsReparsePoint(new_file, &result)); @@ -64,16 +64,17 @@ TEST(WinUtils, SameObject) { ASSERT_TRUE(::DeleteFile(my_folder)); ASSERT_TRUE(::CreateDirectory(my_folder, NULL)); - std::wstring folder(my_folder); - std::wstring file_name = folder + L"\\foo.txt"; + base::string16 folder(my_folder); + base::string16 file_name = folder + L"\\foo.txt"; const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; base::win::ScopedHandle file(CreateFile( file_name.c_str(), GENERIC_WRITE, kSharing, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL)); EXPECT_TRUE(file.IsValid()); - std::wstring file_name_nt1 = std::wstring(L"\\??\\") + file_name; - std::wstring file_name_nt2 = std::wstring(L"\\??\\") + folder + L"\\FOO.txT"; + base::string16 file_name_nt1 = base::string16(L"\\??\\") + file_name; + base::string16 file_name_nt2 = + base::string16(L"\\??\\") + folder + L"\\FOO.txT"; EXPECT_TRUE(SameObject(file.Get(), file_name_nt1.c_str())); EXPECT_TRUE(SameObject(file.Get(), file_name_nt2.c_str())); diff --git a/sandbox/win/src/window.cc b/sandbox/win/src/window.cc index d8de967..d21858a 100644 --- a/sandbox/win/src/window.cc +++ b/sandbox/win/src/window.cc @@ -53,7 +53,7 @@ ResultCode CreateAltWindowStation(HWINSTA* winsta) { } ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop) { - std::wstring desktop_name = L"sbox_alternate_desktop_"; + base::string16 desktop_name = L"sbox_alternate_desktop_"; // Append the current PID to the desktop name. wchar_t buffer[16]; @@ -100,14 +100,14 @@ ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop) { return SBOX_ERROR_CANNOT_CREATE_DESKTOP; } -std::wstring GetWindowObjectName(HANDLE handle) { +base::string16 GetWindowObjectName(HANDLE handle) { // Get the size of the name. DWORD size = 0; ::GetUserObjectInformation(handle, UOI_NAME, NULL, 0, &size); if (!size) { NOTREACHED(); - return std::wstring(); + return base::string16(); } // Create the buffer that will hold the name. @@ -117,19 +117,19 @@ std::wstring GetWindowObjectName(HANDLE handle) { if (!::GetUserObjectInformation(handle, UOI_NAME, name_buffer.get(), size, &size)) { NOTREACHED(); - return std::wstring(); + return base::string16(); } - return std::wstring(name_buffer.get()); + return base::string16(name_buffer.get()); } -std::wstring GetFullDesktopName(HWINSTA winsta, HDESK desktop) { +base::string16 GetFullDesktopName(HWINSTA winsta, HDESK desktop) { if (!desktop) { NOTREACHED(); - return std::wstring(); + return base::string16(); } - std::wstring name; + base::string16 name; if (winsta) { name = GetWindowObjectName(winsta); name += L'\\'; diff --git a/sandbox/win/src/window.h b/sandbox/win/src/window.h index e8233e7..62fe7c4 100644 --- a/sandbox/win/src/window.h +++ b/sandbox/win/src/window.h @@ -8,6 +8,7 @@ #include <windows.h> #include <string> +#include "base/strings/string16.h" #include "sandbox/win/src/sandbox_types.h" namespace sandbox { @@ -26,13 +27,13 @@ namespace sandbox { ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop); // Returns the name of a desktop or a window station. - std::wstring GetWindowObjectName(HANDLE handle); + base::string16 GetWindowObjectName(HANDLE handle); // Returns the name of the desktop referenced by |desktop|. If a window // station is specified, the name is prepended with the window station name, // followed by a backslash. This name can be used as the lpDesktop parameter // to CreateProcess. - std::wstring GetFullDesktopName(HWINSTA winsta, HDESK desktop); + base::string16 GetFullDesktopName(HWINSTA winsta, HDESK desktop); } // namespace sandbox |