ReactOS 0.4.15-dev-6669-g8227c5d
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 ok_eq_hex(value, expected) ok((value) == (expected), #value " = 0x%lx, expected 0x%lx\n", value, expected)
11#define ok_eq_pointer(value, expected) ok((value) == (expected), #value " = %p, expected %p\n", value, expected)
12
13#define EXPECT_IN_SAME_DIR (WCHAR*)0xdead
14
16
18{
23};
24
25struct test_data Tests[] =
26{
27 /* Not redirected file */
28 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"somefilesomefile", NULL},
29 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"ntdll.dll", NULL},
30 /* Files redirected with sxs */
31 {__LINE__, STATUS_SUCCESS, L"GDIPLUS", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
32 {__LINE__, STATUS_SUCCESS, L"GDIPLUS.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
33 {__LINE__, STATUS_SUCCESS, L"COMCTL32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
34 {__LINE__, STATUS_SUCCESS, L"comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
35 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
36 /* Files not redirected with sxs */
37 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"MSVCR90.DLL", NULL},
38 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\windows\\system32\\MSVCR90.DLL", NULL},
39 /* Files defined in the manifest, one exists, one doesn't */
40 {__LINE__, STATUS_SUCCESS, L"deptest.dll", EXPECT_IN_SAME_DIR},
41 {__LINE__, STATUS_SUCCESS, L"adllfile.dll", EXPECT_IN_SAME_DIR},
42 /* A file that exists in the same dir but isn't mentioned in the manifest */
43 {__LINE__, STATUS_SUCCESS, L"fil1.txt", EXPECT_IN_SAME_DIR},
44 /* This is a weird case; the source doesn't exist but does get redirected */
45 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\gdiplus.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
46 /* But redirecting gdiplus from a different directory doesn't work */
47 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\GDIPLUS.DLL", NULL},
48 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\comctl32.DLL", NULL},
49 /* Redirection based on .local */
50 {__LINE__, STATUS_SUCCESS, L"test", EXPECT_IN_SAME_DIR},
51 {__LINE__, STATUS_SUCCESS, L"test.dll", EXPECT_IN_SAME_DIR},
52 {__LINE__, STATUS_SUCCESS, L"c:\\test.dll", EXPECT_IN_SAME_DIR},
53 /* known dlls are also covered */
54 {__LINE__, STATUS_SUCCESS, L"shell32", EXPECT_IN_SAME_DIR},
55 {__LINE__, STATUS_SUCCESS, L"shell32.dll", EXPECT_IN_SAME_DIR},
56 {__LINE__, STATUS_SUCCESS, L"c:\\shell32.dll", EXPECT_IN_SAME_DIR}
57};
58
60{
61 ACTCTXW ActCtx = {sizeof(ACTCTX)};
62 HANDLE h;
64
65 ok (GetModuleFileNameW(NULL, buffer, MAX_PATH), "GetModuleFileName failed\n");
66 separator = wcsrchr(buffer, L'\\');
67 if (separator)
69
70 ActCtx.lpSource = buffer;
71
72 SetLastError(0xdeaddead);
74 ok_(__FILE__, line)(h != INVALID_HANDLE_VALUE, "CreateActCtx failed for %S\n", FileName);
75 // In win10 last error is unchanged and in win2k3 it is ERROR_BAD_EXE_FORMAT
76 ok_(__FILE__, line)(GetLastError() == ERROR_BAD_EXE_FORMAT || GetLastError() == 0xdeaddead, "Wrong last error %lu\n", GetLastError());
77
78 return h;
79}
80
82{
83 WCHAR SystemDir[MAX_PATH];
84 WCHAR TestPath[MAX_PATH];
85 WCHAR ParameterBuffer[MAX_PATH];
88 int i;
89
90 GetSystemDirectoryW(SystemDir, MAX_PATH);
92 separator = wcsrchr(TestPath, L'\\');
93 separator++;
94 *separator = 0;
95
96 for (i = 0; i < _countof(Tests); i ++)
97 {
98 UNICODE_STRING OriginalName, DynamicString;
100
101 if (memcmp(Tests[i].Param, L"c:\\windows\\system32", 38) == 0)
102 {
103 wcscpy(ParameterBuffer, SystemDir);
104 wcscat(ParameterBuffer, &Tests[i].Param[19]);
105 }
106 else
107 {
108 wcscpy(ParameterBuffer, Tests[i].Param);
109 }
110
111 RtlInitUnicodeString(&OriginalName, ParameterBuffer);
112 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
113
115 &OriginalName,
116 &DotDll,
117 NULL,
119 &StringUsed,
120 NULL,
121 NULL,
122 NULL);
123 ok(Status == Tests[i].ExpectedStatus, "%d: Status 0x%lx, expected 0x%lx\n", Tests[i].testline, Status, Tests[i].ExpectedStatus);
124
126 {
127 ok(0, "%d: Expected a returned string\n", Tests[i].testline);
128 }
129
131 {
133 {
134 ok(wcsstr(DynamicString.Buffer, TestPath) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, TestPath, DynamicString.Buffer);
135 }
136 else
137 {
139 ok(wcsstr(DynamicString.Buffer, Tests[i].ExpectedSubString) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, Tests[i].ExpectedSubString, DynamicString.Buffer);
140 }
141 }
142 }
143}
144
146{
151
152 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
154 NULL,
155 NULL,
156 NULL,
158 &StringUsed,
159 NULL,
160 NULL,
161 NULL);
163
164 RtlInitEmptyUnicodeString(&Param, NULL, 0);
165 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
167 &Param,
168 NULL,
169 NULL,
171 &StringUsed,
172 NULL,
173 NULL,
174 NULL);
176
177 /* Tests for NULL termination of OriginalName */
178 Param.MaximumLength = Param.Length = 12 * sizeof(WCHAR);
179 Param.Buffer = L"comctl32.dllcrapcrap";
180 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
182 &Param,
183 NULL,
184 NULL,
186 &StringUsed,
187 NULL,
188 NULL,
189 NULL);
190 ok(Status ==STATUS_SUCCESS, "\n");
191
192 /* Tests for the Extension parameter */
193 RtlInitUnicodeString(&Param, L"comctl32.dll");
194 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
196 &Param,
197 NULL,
198 NULL,
200 &StringUsed,
201 NULL,
202 NULL,
203 NULL);
204 ok(Status ==STATUS_SUCCESS, "\n");
205
206 RtlInitUnicodeString(&Param, L"comctl32");
207 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
209 &Param,
210 NULL,
211 NULL,
213 &StringUsed,
214 NULL,
215 NULL,
216 NULL);
218
219 RtlInitUnicodeString(&Param, L"comctl32");
220 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
222 &Param,
223 &DotDll,
224 NULL,
226 &StringUsed,
227 NULL,
228 NULL,
229 NULL);
230 ok(Status ==STATUS_SUCCESS, "\n");
231
232 /* Tests for the DynamicString parameter */
233 RtlInitUnicodeString(&Param, L"comctl32.dll");
234 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
236 &Param,
237 NULL,
238 NULL,
240 &StringUsed,
241 NULL,
242 NULL,
243 NULL);
244 ok(Status ==STATUS_SUCCESS, "\n");
245 ok(DynamicString.Length >0 , "\n");
249 else
250 ok(DynamicString.Buffer != NULL, "Expected non NULL buffer\n");
251 ok(StringUsed == &DynamicString, "\n");
252
253 /* Tests for the StaticString parameter */
254 wcscpy(buffer, L"comctl32.dll");
256 StaticString.Length = sizeof(L"comctl32.dll");
260 &Param,
261 NULL,
263 NULL,
264 &StringUsed,
265 NULL,
266 NULL,
267 NULL);
269
270 wcscpy(buffer, L"comctl32.dll");
272 StaticString.Length = sizeof(L"comctl32.dll");
276 NULL,
278 NULL,
279 &StringUsed,
280 NULL,
281 NULL,
282 NULL);
284
285 RtlInitUnicodeString(&Param, L"comctl32.dll");
286 RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
288 &Param,
289 NULL,
291 NULL,
292 &StringUsed,
293 NULL,
294 NULL,
295 NULL);
296 ok(Status ==STATUS_SUCCESS, "\n");
297 ok(StaticString.Length >0 , "\n");
298 ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
300 ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer) * sizeof(WCHAR) , StaticString.Length);
301 else
302 ok(StaticString.Length != 0, "Expected non 0 lenght\n");
303 ok(StringUsed == &StaticString, "\n");
304
305 RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
307 &Param,
308 NULL,
310 NULL,
311 &StringUsed,
312 NULL,
313 NULL,
314 NULL);
315 ok(Status == STATUS_BUFFER_TOO_SMALL, "0x%lx\n", Status);
316
317 RtlInitUnicodeString(&Param, L"comctl32.dll");
318 RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
319 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
321 &Param,
322 NULL,
325 &StringUsed,
326 NULL,
327 NULL,
328 NULL);
329 ok(Status ==STATUS_SUCCESS, "\n");
330 ok(StaticString.Length >0 , "\n");
331 ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
333 ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer) * sizeof(WCHAR) , StaticString.Length);
334 else
335 ok(StaticString.Length != 0, "Expected non 0 lenght\n");
336 ok(DynamicString.Buffer == NULL, "\n");
337 ok(DynamicString.Length == 0, "\n");
338 ok(DynamicString.MaximumLength == 0, "\n");
339 ok(StringUsed == &StaticString, "\n");
340
341 /* Test a small buffer and a dynamic buffer */
342 RtlInitUnicodeString(&Param, L"comctl32.dll");
343 RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
344 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
345 StaticString.Buffer[0] = 1;
347 &Param,
348 NULL,
351 &StringUsed,
352 NULL,
353 NULL,
354 NULL);
355 ok(Status ==STATUS_SUCCESS, "\n");
356 ok(StaticString.Buffer == buffer, "\n");
357 ok(StaticString.Length == 0 , "%d\n", StaticString.Length);
358 ok(StaticString.Buffer[0] == 0, "\n");
360 ok(DynamicString.Length >0 , "\n");
364 else
365 ok(DynamicString.Length != 0, "Expected non 0 lenght\n");
366
367 ok(StringUsed == &DynamicString, "\n");
368}
369
371{
372 int argc;
373 char **test_argv;
375 if (argc >= 3)
376 {
377 HANDLE h = _CreateActCtxFromFile(L"ntdlltest.manifest", __LINE__);
378 BOOL bactivated = FALSE;
380
381 if (h != INVALID_HANDLE_VALUE)
382 bactivated = ActivateActCtx(h, &cookie);
383
385 TestBuffers();
386
387 if (bactivated)
389 }
390 else
391 {
392 WCHAR TestPath[MAX_PATH];
394 STARTUPINFOW si = { sizeof(si) };
396 BOOL created;
397
398 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
399 separator = wcsrchr(TestPath, L'\\');
400 separator++;
401 wcscpy(separator, L"testdata\\ntdll_apitest.exe RtlDosApplyFileIsolationRedirection_Ustr DoTest");
402
403 created = CreateProcessW(NULL, TestPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
404 ok(created, "Expected CreateProcess to succeed\n");
405 if (created)
406 {
408 CloseHandle(pi.hThread);
409 CloseHandle(pi.hProcess);
410 }
411 }
412}
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:821
#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