summaryrefslogtreecommitdiffstats
path: root/sandbox/tests
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-27 19:20:42 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-27 19:20:42 +0000
commit4f1f3d0f03c79ddaace56f067cf28a27f9466b7d (patch)
treebc0bcae7b48b6e4e218d4fca358af50467893940 /sandbox/tests
parent2377f7f26715ae20f671c5fd7e7edee778c1f64f (diff)
downloadchromium_src-4f1f3d0f03c79ddaace56f067cf28a27f9466b7d.zip
chromium_src-4f1f3d0f03c79ddaace56f067cf28a27f9466b7d.tar.gz
chromium_src-4f1f3d0f03c79ddaace56f067cf28a27f9466b7d.tar.bz2
Improve handling and testing of reparse points.
BUG=28804 TEST=unit tests. Review URL: http://codereview.chromium.org/553080 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37286 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/tests')
-rw-r--r--sandbox/tests/common/controller.cc51
-rw-r--r--sandbox/tests/common/controller.h10
-rw-r--r--sandbox/tests/common/test_utils.cc72
-rw-r--r--sandbox/tests/common/test_utils.h19
4 files changed, 140 insertions, 12 deletions
diff --git a/sandbox/tests/common/controller.cc b/sandbox/tests/common/controller.cc
index 802b1b6..6e0f080 100644
--- a/sandbox/tests/common/controller.cc
+++ b/sandbox/tests/common/controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,17 +8,13 @@
#include "sandbox/src/sandbox_factory.h"
#include "sandbox/src/sandbox_utils.h"
+#include "sandbox/src/wow64.h"
namespace {
static const int kDefaultTimeout = 3000;
-} // namespace
-
-namespace sandbox {
-
-// Utility function that constructs a full path to a file inside the system32
-// folder.
+// Constructs a full path to a file inside the system32 folder.
std::wstring MakePathToSys32(const wchar_t* name, bool is_obj_man_path) {
wchar_t windows_path[MAX_PATH] = {0};
if (0 == ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH))
@@ -36,6 +32,36 @@ std::wstring MakePathToSys32(const wchar_t* name, bool is_obj_man_path) {
return full_path;
}
+// Constructs a full path to a file inside the syswow64 folder.
+std::wstring MakePathToSysWow64(const wchar_t* name, bool is_obj_man_path) {
+ wchar_t windows_path[MAX_PATH] = {0};
+ if (0 == ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH))
+ return std::wstring();
+
+ std::wstring full_path(windows_path);
+ if (full_path.empty())
+ return full_path;
+
+ if (is_obj_man_path)
+ full_path.insert(0, L"\\??\\");
+
+ full_path += L"\\SysWOW64\\";
+ full_path += name;
+ return full_path;
+}
+
+} // namespace
+
+namespace sandbox {
+
+std::wstring MakePathToSys(const wchar_t* name, bool is_obj_man_path) {
+ Wow64 current_proc(NULL, NULL);
+ if (current_proc.IsWow64())
+ return MakePathToSysWow64(name, is_obj_man_path);
+ else
+ return MakePathToSys32(name, is_obj_man_path);
+}
+
BrokerServices* GetBroker() {
static BrokerServices* broker = SandboxFactory::GetBrokerServices();
static bool is_initialized = false;
@@ -111,6 +137,17 @@ bool TestRunner::AddRuleSys32(TargetPolicy::Semantics semantics,
if (win32_path.empty())
return false;
+ if (!AddRule(TargetPolicy::SUBSYS_FILES, semantics, win32_path.c_str()))
+ return false;
+
+ Wow64 current_proc(NULL, NULL);
+ if (!current_proc.IsWow64())
+ return true;
+
+ win32_path = MakePathToSysWow64(pattern, false);
+ if (win32_path.empty())
+ return false;
+
return AddRule(TargetPolicy::SUBSYS_FILES, semantics, win32_path.c_str());
}
diff --git a/sandbox/tests/common/controller.h b/sandbox/tests/common/controller.h
index 8300846..3f1d0c2 100644
--- a/sandbox/tests/common/controller.h
+++ b/sandbox/tests/common/controller.h
@@ -1,8 +1,8 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SANDBOX_TESTS_COMMON_CONTROLLER_H__
+#ifndef SANDBOX_TESTS_COMMON_CONTROLLER_H_
#define SANDBOX_TESTS_COMMON_CONTROLLER_H__
#include <windows.h>
@@ -117,12 +117,12 @@ class TestRunner {
// Returns the broker services.
BrokerServices* GetBroker();
-// Constructs a full path to a file inside the system32 folder.
-std::wstring MakePathToSys32(const wchar_t* name, bool is_obj_man_path);
+// Constructs a full path to a file inside the system32 (or syswow64) folder.
+std::wstring MakePathToSys(const wchar_t* name, bool is_obj_man_path);
// Runs the given test on the target process.
int DispatchCall(int argc, wchar_t **argv);
} // namespace sandbox
-#endif // SANDBOX_TESTS_COMMON_CONTROLLER_H__
+#endif // SANDBOX_TESTS_COMMON_CONTROLLER_H_
diff --git a/sandbox/tests/common/test_utils.cc b/sandbox/tests/common/test_utils.cc
new file mode 100644
index 0000000..929c322
--- /dev/null
+++ b/sandbox/tests/common/test_utils.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sandbox/tests/common/test_utils.h"
+
+#include <winioctl.h>
+
+typedef struct _REPARSE_DATA_BUFFER {
+ ULONG ReparseTag;
+ USHORT ReparseDataLength;
+ USHORT Reserved;
+ union {
+ struct {
+ USHORT SubstituteNameOffset;
+ USHORT SubstituteNameLength;
+ USHORT PrintNameOffset;
+ USHORT PrintNameLength;
+ ULONG Flags;
+ WCHAR PathBuffer[1];
+ } SymbolicLinkReparseBuffer;
+ struct {
+ USHORT SubstituteNameOffset;
+ USHORT SubstituteNameLength;
+ USHORT PrintNameOffset;
+ USHORT PrintNameLength;
+ WCHAR PathBuffer[1];
+ } MountPointReparseBuffer;
+ struct {
+ UCHAR DataBuffer[1];
+ } GenericReparseBuffer;
+ };
+} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
+
+// Sets a reparse point. |source| will now point to |target|. Returns true if
+// the call succeeds, false otherwise.
+bool SetReparsePoint(HANDLE source, const wchar_t* target) {
+ USHORT size_target = static_cast<USHORT>(wcslen(target)) * sizeof(target[0]);
+
+ char buffer[2000] = {0};
+ DWORD returned;
+
+ REPARSE_DATA_BUFFER* data = reinterpret_cast<REPARSE_DATA_BUFFER*>(buffer);
+
+ data->ReparseTag = 0xa0000003;
+ memcpy(data->MountPointReparseBuffer.PathBuffer, target, size_target + 2);
+ data->MountPointReparseBuffer.SubstituteNameLength = size_target;
+ data->MountPointReparseBuffer.PrintNameOffset = size_target + 2;
+ data->ReparseDataLength = size_target + 4 + 8;
+
+ int data_size = data->ReparseDataLength + 8;
+
+ if (!DeviceIoControl(source, FSCTL_SET_REPARSE_POINT, &buffer, data_size,
+ NULL, 0, &returned, NULL)) {
+ return false;
+ }
+ return true;
+}
+
+// Delete the reparse point referenced by |source|. Returns true if the call
+// succeeds, false otherwise.
+bool DeleteReparsePoint(HANDLE source) {
+ DWORD returned;
+ REPARSE_DATA_BUFFER data = {0};
+ data.ReparseTag = 0xa0000003;
+ if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0,
+ &returned, NULL)) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/sandbox/tests/common/test_utils.h b/sandbox/tests/common/test_utils.h
new file mode 100644
index 0000000..9e17660
--- /dev/null
+++ b/sandbox/tests/common/test_utils.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SANDBOX_TESTS_COMMON_TEST_UTILS_H_
+#define SANDBOX_TESTS_COMMON_TEST_UTILS_H_
+
+#include <windows.h>
+
+// Sets a reparse point. |source| will now point to |target|. Returns true if
+// the call succeeds, false otherwise.
+bool SetReparsePoint(HANDLE source, const wchar_t* target);
+
+// Delete the reparse point referenced by |source|. Returns true if the call
+// succeeds, false otherwise.
+bool DeleteReparsePoint(HANDLE source);
+
+#endif // SANDBOX_TESTS_COMMON_TEST_UTILS_H_
+