ReactOS 0.4.15-dev-7928-g68a8619
RtlDosApplyFileIsolationRedirection_Ustr.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlDosApplyFileIsolationRedirection_Ustr
5 * PROGRAMMER: Giannis Adamopoulos
6 */
7
8#include "precomp.h"
9
10#define EXPECT_IN_SAME_DIR (WCHAR*)0xdead
11
13
15{
20};
21
22struct test_data Tests[] =
23{
24 /* Not redirected file */
25 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"somefilesomefile", NULL},
26 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"ntdll.dll", NULL},
27 /* Files redirected with sxs */
28 {__LINE__, STATUS_SUCCESS, L"GDIPLUS", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
29 {__LINE__, STATUS_SUCCESS, L"GDIPLUS.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
30 {__LINE__, STATUS_SUCCESS, L"COMCTL32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
31 {__LINE__, STATUS_SUCCESS, L"comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
32 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
33 /* Files not redirected with sxs */
34 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"MSVCR90.DLL", NULL},
35 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\windows\\system32\\MSVCR90.DLL", NULL},
36 /* Files defined in the manifest, one exists, one doesn't */
37 {__LINE__, STATUS_SUCCESS, L"deptest.dll", EXPECT_IN_SAME_DIR},
38 {__LINE__, STATUS_SUCCESS, L"adllfile.dll", EXPECT_IN_SAME_DIR},
39 /* A file that exists in the same dir but isn't mentioned in the manifest */
40 {__LINE__, STATUS_SUCCESS, L"fil1.txt", EXPECT_IN_SAME_DIR},
41 /* This is a weird case; the source doesn't exist but does get redirected */
42 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\gdiplus.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
43 /* But redirecting gdiplus from a different directory doesn't work */
44 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\GDIPLUS.DLL", NULL},
45 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\comctl32.DLL", NULL},
46 /* Redirection based on .local */
47 {__LINE__, STATUS_SUCCESS, L"test", EXPECT_IN_SAME_DIR},
48 {__LINE__, STATUS_SUCCESS, L"test.dll", EXPECT_IN_SAME_DIR},
49 {__LINE__, STATUS_SUCCESS, L"c:\\test.dll", EXPECT_IN_SAME_DIR},
50 /* known dlls are also covered */
51 {__LINE__, STATUS_SUCCESS, L"shell32", EXPECT_IN_SAME_DIR},
52 {__LINE__, STATUS_SUCCESS, L"shell32.dll", EXPECT_IN_SAME_DIR},
53 {__LINE__, STATUS_SUCCESS, L"c:\\shell32.dll", EXPECT_IN_SAME_DIR}
54};
55
57{
58 ACTCTXW ActCtx = {sizeof(ACTCTX)};
59 HANDLE h;
61
62 ok (GetModuleFileNameW(NULL, buffer, MAX_PATH), "GetModuleFileName failed\n");
63 separator = wcsrchr(buffer, L'\\');
64 if (separator)
66
67 ActCtx.lpSource = buffer;
68
69 SetLastError(0xdeaddead);
71 ok_(__FILE__, line)(h != INVALID_HANDLE_VALUE, "CreateActCtx failed for %S\n", FileName);
72 // In win10 last error is unchanged and in win2k3 it is ERROR_BAD_EXE_FORMAT
73 ok_(__FILE__, line)(GetLastError() == ERROR_BAD_EXE_FORMAT || GetLastError() == 0xdeaddead, "Wrong last error %lu\n", GetLastError());
74
75 return h;
76}
77
79{
80 WCHAR SystemDir[MAX_PATH];
81 WCHAR TestPath[MAX_PATH];
82 WCHAR ParameterBuffer[MAX_PATH];
85 int i;
86
87 GetSystemDirectoryW(SystemDir, MAX_PATH);
89 separator = wcsrchr(TestPath, L'\\');
90 separator++;
91 *separator = 0;
92
93 for (i = 0; i < _countof(Tests); i ++)
94 {
95 UNICODE_STRING OriginalName, DynamicString;
97
98 if (memcmp(Tests[i].Param, L"c:\\windows\\system32", 38) == 0)
99 {
100 wcscpy(ParameterBuffer, SystemDir);
101 wcscat(ParameterBuffer, &Tests[i].Param[19]);
102 }
103 else
104 {
105 wcscpy(ParameterBuffer, Tests[i].Param);
106 }
107
108 RtlInitUnicodeString(&OriginalName, ParameterBuffer);
109 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
110
112 &OriginalName,
113 &DotDll,
114 NULL,
116 &StringUsed,
117 NULL,
118 NULL,
119 NULL);
120 ok(Status == Tests[i].ExpectedStatus, "%d: Status 0x%lx, expected 0x%lx\n", Tests[i].testline, Status, Tests[i].ExpectedStatus);
121
123 {
124 ok(0, "%d: Expected a returned string\n", Tests[i].testline);
125 }
126
128 {
130 {
131 ok(wcsstr(DynamicString.Buffer, TestPath) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, TestPath, DynamicString.Buffer);
132 }
133 else
134 {
136 ok(wcsstr(DynamicString.Buffer, Tests[i].ExpectedSubString) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, Tests[i].ExpectedSubString, DynamicString.Buffer);
137 }
138 }
139 }
140}
141
143{
148
149 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
151 NULL,
152 NULL,
153 NULL,
155 &StringUsed,
156 NULL,
157 NULL,
158 NULL);
160
161 RtlInitEmptyUnicodeString(&Param, NULL, 0);
162 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
164 &Param,
165 NULL,
166 NULL,
168 &StringUsed,
169 NULL,
170 NULL,
171 NULL);
173
174 /* Tests for NULL termination of OriginalName */
175 Param.MaximumLength = Param.Length = 12 * sizeof(WCHAR);
176 Param.Buffer = L"comctl32.dllcrapcrap";
177 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
179 &Param,
180 NULL,
181 NULL,
183 &StringUsed,
184 NULL,
185 NULL,
186 NULL);
187 ok(Status ==STATUS_SUCCESS, "\n");
188
189 /* Tests for the Extension parameter */
190 RtlInitUnicodeString(&Param, L"comctl32.dll");
191 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
193 &Param,
194 NULL,
195 NULL,
197 &StringUsed,
198 NULL,
199 NULL,
200 NULL);
201 ok(Status ==STATUS_SUCCESS, "\n");
202
203 RtlInitUnicodeString(&Param, L"comctl32");
204 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
206 &Param,
207 NULL,
208 NULL,
210 &StringUsed,
211 NULL,
212 NULL,
213 NULL);
215
216 RtlInitUnicodeString(&Param, L"comctl32");
217 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
219 &Param,
220 &DotDll,
221 NULL,
223 &StringUsed,
224 NULL,
225 NULL,
226 NULL);
227 ok(Status ==STATUS_SUCCESS, "\n");
228
229 /* Tests for the DynamicString parameter */
230 RtlInitUnicodeString(&Param, L"comctl32.dll");
231 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
233 &Param,
234 NULL,
235 NULL,
237 &StringUsed,
238 NULL,
239 NULL,
240 NULL);
241 ok(Status ==STATUS_SUCCESS, "\n");
242 ok(DynamicString.Length >0 , "\n");
246 else
247 ok(DynamicString.Buffer != NULL, "Expected non NULL buffer\n");
248 ok(StringUsed == &DynamicString, "\n");
249
250 /* Tests for the StaticString parameter */
251 wcscpy(buffer, L"comctl32.dll");
253 StaticString.Length = sizeof(L"comctl32.dll");
257 &Param,
258 NULL,
260 NULL,
261 &StringUsed,
262 NULL,
263 NULL,
264 NULL);
266
267 wcscpy(buffer, L"comctl32.dll");
269 StaticString.Length = sizeof(L"comctl32.dll");
273 NULL,
275 NULL,
276 &StringUsed,
277 NULL,
278 NULL,
279 NULL);
281
282 RtlInitUnicodeString(&Param, L"comctl32.dll");
283 RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
285 &Param,
286 NULL,
288 NULL,
289 &StringUsed,
290 NULL,
291 NULL,
292 NULL);
293 ok(Status ==STATUS_SUCCESS, "\n");
294 ok(StaticString.Length >0 , "\n");
295 ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
297 ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer) * sizeof(WCHAR) , StaticString.Length);
298 else
299 ok(StaticString.Length != 0, "Expected non 0 lenght\n");
300 ok(StringUsed == &StaticString, "\n");
301
302 RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
304 &Param,
305 NULL,
307 NULL,
308 &StringUsed,
309 NULL,
310 NULL,
311 NULL);
312 ok(Status == STATUS_BUFFER_TOO_SMALL, "0x%lx\n", Status);
313
314 RtlInitUnicodeString(&Param, L"comctl32.dll");
315 RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
316 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
318 &Param,
319 NULL,
322 &StringUsed,
323 NULL,
324 NULL,
325 NULL);
326 ok(Status ==STATUS_SUCCESS, "\n");
327 ok(StaticString.Length >0 , "\n");
328 ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
330 ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer) * sizeof(WCHAR) , StaticString.Length);
331 else
332 ok(StaticString.Length != 0, "Expected non 0 lenght\n");
333 ok(DynamicString.Buffer == NULL, "\n");
334 ok(DynamicString.Length == 0, "\n");
335 ok(DynamicString.MaximumLength == 0, "\n");
336 ok(StringUsed == &StaticString, "\n");
337
338 /* Test a small buffer and a dynamic buffer */
339 RtlInitUnicodeString(&Param, L"comctl32.dll");
340 RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
341 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
342 StaticString.Buffer[0] = 1;
344 &Param,
345 NULL,
348 &StringUsed,
349 NULL,
350 NULL,
351 NULL);
352 ok(Status ==STATUS_SUCCESS, "\n");
353 ok(StaticString.Buffer == buffer, "\n");
354 ok(StaticString.Length == 0 , "%d\n", StaticString.Length);
355 ok(StaticString.Buffer[0] == 0, "\n");
357 ok(DynamicString.Length >0 , "\n");
361 else
362 ok(DynamicString.Length != 0, "Expected non 0 lenght\n");
363
364 ok(StringUsed == &DynamicString, "\n");
365}
366
368{
369 int argc;
370 char **test_argv;
372 if (argc >= 3)
373 {
374 HANDLE h = _CreateActCtxFromFile(L"ntdlltest.manifest", __LINE__);
375 BOOL bactivated = FALSE;
377
378 if (h != INVALID_HANDLE_VALUE)
379 bactivated = ActivateActCtx(h, &cookie);
380
382 TestBuffers();
383
384 if (bactivated)
386 }
387 else
388 {
389 WCHAR TestPath[MAX_PATH];
391 STARTUPINFOW si = { sizeof(si) };
393 BOOL created;
394
395 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
396 separator = wcsrchr(TestPath, L'\\');
397 separator++;
398 wcscpy(separator, L"testdata\\ntdll_apitest.exe RtlDosApplyFileIsolationRedirection_Ustr DoTest");
399
400 created = CreateProcessW(NULL, TestPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
401 ok(created, "Expected CreateProcess to succeed\n");
402 if (created)
403 {
405 CloseHandle(pi.hThread);
406 CloseHandle(pi.hProcess);
407 }
408 }
409}
struct test_data Tests[]
HANDLE _CreateActCtxFromFile(LPCWSTR FileName, int line)
IN PUNICODE_STRING StaticString
IN PUNICODE_STRING IN PUNICODE_STRING DynamicString
IN PUNICODE_STRING IN PUNICODE_STRING IN PUNICODE_STRING * StringUsed
static int argc
Definition: ServiceArgs.c:12
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlDosApplyFileIsolationRedirection_Ustr(IN ULONG Flags, IN PUNICODE_STRING OriginalName, IN PUNICODE_STRING Extension, IN OUT PUNICODE_STRING StaticString, IN OUT PUNICODE_STRING DynamicString, IN OUT PUNICODE_STRING *NewName, IN PULONG NewFlags, IN PSIZE_T FileNameSize, IN PSIZE_T RequiredLength)
Definition: libsupp.c:818
#define CloseHandle
Definition: compat.h:739
#define wcsrchr
Definition: compat.h:16
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
static const WCHAR separator[]
Definition: asmname.c:65
BOOL WINAPI DeactivateActCtx(IN DWORD dwFlags, IN ULONG_PTR ulCookie)
Definition: actctx.c:268
BOOL WINAPI ActivateActCtx(IN HANDLE hActCtx, OUT PULONG_PTR ulCookie)
Definition: actctx.c:237
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4592
HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
Definition: actctx.c:104
struct _FileName FileName
Definition: fatprocs.h:896
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
NTSYSAPI NTSTATUS WINAPI RtlDowncaseUnicodeString(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN)
_In_ PCWSTR _Out_ PVOID * ActCtx
Definition: ldrtypes.h:247
static refpint_t pi[]
Definition: server.c:96
static char ** test_argv
Definition: cursoricon.c:296
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SXS_KEY_NOT_FOUND
Definition: ntstatus.h:1389
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
int winetest_get_mainargs(char ***pargv)
void winetest_wait_child_process(HANDLE process)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define _countof(array)
Definition: sndvol32.h:68
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: cookie.c:34
Definition: parser.c:49
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_BAD_EXE_FORMAT
Definition: winerror.h:251
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185