2 * Unit test suite for object manager functions
4 * Copyright 2005 Robert Shearman
5 * Copyright 2005 Vitaliy Margolen
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "ntdll_test.h"
28 static HANDLE (WINAPI
*pCreateWaitableTimerA
)(SECURITY_ATTRIBUTES
*, BOOL
, LPCSTR
);
29 static NTSTATUS (WINAPI
*pRtlCreateUnicodeStringFromAsciiz
)(PUNICODE_STRING
, LPCSTR
);
30 static VOID (WINAPI
*pRtlInitUnicodeString
)( PUNICODE_STRING
, LPCWSTR
);
31 static VOID (WINAPI
*pRtlFreeUnicodeString
)(PUNICODE_STRING
);
32 static NTSTATUS (WINAPI
*pNtCreateEvent
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, BOOLEAN
, BOOLEAN
);
33 static NTSTATUS (WINAPI
*pNtCreateMutant
)( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, BOOLEAN
);
34 static NTSTATUS (WINAPI
*pNtOpenMutant
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
);
35 static NTSTATUS (WINAPI
*pNtCreateSemaphore
)( PHANDLE
, ACCESS_MASK
,const POBJECT_ATTRIBUTES
,LONG
,LONG
);
36 static NTSTATUS (WINAPI
*pNtCreateTimer
) ( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, TIMER_TYPE
);
37 static NTSTATUS (WINAPI
*pNtCreateSection
)( PHANDLE
, ACCESS_MASK
, const POBJECT_ATTRIBUTES
, const PLARGE_INTEGER
,
38 ULONG
, ULONG
, HANDLE
);
39 static NTSTATUS (WINAPI
*pNtOpenFile
) ( PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
, ULONG
, ULONG
);
40 static NTSTATUS (WINAPI
*pNtClose
) ( HANDLE
);
41 static NTSTATUS (WINAPI
*pNtCreateNamedPipeFile
)( PHANDLE
, ULONG
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
,
42 ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, ULONG
, PLARGE_INTEGER
);
43 static NTSTATUS (WINAPI
*pNtOpenDirectoryObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
44 static NTSTATUS (WINAPI
*pNtCreateDirectoryObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
45 static NTSTATUS (WINAPI
*pNtOpenSymbolicLinkObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
46 static NTSTATUS (WINAPI
*pNtCreateSymbolicLinkObject
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, PUNICODE_STRING
);
49 static void test_case_sensitive (void)
51 static const WCHAR buffer1
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','t','e','s','t',0};
52 static const WCHAR buffer2
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','T','e','s','t',0};
53 static const WCHAR buffer3
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s','\\','T','E','s','t',0};
54 static const WCHAR buffer4
[] = {'\\','B','A','S','E','N','a','m','e','d','O','b','j','e','c','t','s','\\','t','e','s','t',0};
56 OBJECT_ATTRIBUTES attr
;
58 HANDLE Event
, Mutant
, h
;
60 pRtlInitUnicodeString(&str
, buffer1
);
61 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
62 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
63 ok(status
== STATUS_SUCCESS
, "Failed to create Mutant(%08x)\n", status
);
65 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
66 ok(status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
67 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status
);
69 pRtlInitUnicodeString(&str
, buffer2
);
70 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
71 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
72 ok(status
== STATUS_SUCCESS
, "Failed to create Event(%08x)\n", status
);
74 pRtlInitUnicodeString(&str
, buffer3
);
75 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
76 status
= pNtOpenMutant(&h
, GENERIC_ALL
, &attr
);
77 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
78 "NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
82 pRtlInitUnicodeString(&str
, buffer4
);
83 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
84 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
85 ok(status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
86 "NtCreateMutant should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status
);
88 status
= pNtCreateEvent(&h
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
89 ok(status
== STATUS_OBJECT_NAME_COLLISION
,
90 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08x)\n", status
);
93 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
94 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
,
95 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
100 static void test_namespace_pipe(void)
102 static const WCHAR buffer1
[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0};
103 static const WCHAR buffer2
[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0};
104 static const WCHAR buffer3
[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0};
105 static const WCHAR buffer4
[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0};
106 OBJECT_ATTRIBUTES attr
;
108 IO_STATUS_BLOCK iosb
;
110 LARGE_INTEGER timeout
;
113 timeout
.QuadPart
= -10000;
115 pRtlInitUnicodeString(&str
, buffer1
);
116 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
117 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
118 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
119 ok(status
== STATUS_SUCCESS
, "Failed to create NamedPipe(%08x)\n", status
);
121 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
122 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
123 ok(status
== STATUS_INSTANCE_NOT_AVAILABLE
,
124 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status
);
126 pRtlInitUnicodeString(&str
, buffer2
);
127 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
128 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
129 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
130 ok(status
== STATUS_INSTANCE_NOT_AVAILABLE
,
131 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status
);
133 h
= CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
134 OPEN_EXISTING
, 0, 0 );
135 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open NamedPipe (%u)\n", GetLastError());
138 pRtlInitUnicodeString(&str
, buffer3
);
139 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
140 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
141 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
||
142 status
== STATUS_PIPE_NOT_AVAILABLE
||
143 status
== STATUS_OBJECT_NAME_INVALID
, /* vista */
144 "NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
146 pRtlInitUnicodeString(&str
, buffer4
);
147 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
148 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
149 ok(status
== STATUS_OBJECT_NAME_NOT_FOUND
||
150 status
== STATUS_OBJECT_NAME_INVALID
, /* vista */
151 "NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status
);
156 #define DIRECTORY_QUERY (0x0001)
157 #define SYMBOLIC_LINK_QUERY 0x0001
159 #define DIR_TEST_CREATE_FAILURE(h,e) \
160 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr);\
161 ok(status == e,"NtCreateDirectoryObject should have failed with %s got(%08x)\n", #e, status);
162 #define DIR_TEST_OPEN_FAILURE(h,e) \
163 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr);\
164 ok(status == e,"NtOpenDirectoryObject should have failed with %s got(%08x)\n", #e, status);
165 #define DIR_TEST_CREATE_OPEN_FAILURE(h,n,e) \
166 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
167 DIR_TEST_CREATE_FAILURE(h,e) DIR_TEST_OPEN_FAILURE(h,e)\
168 pRtlFreeUnicodeString(&str);
170 #define DIR_TEST_CREATE_SUCCESS(h) \
171 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr); \
172 ok(status == STATUS_SUCCESS, "Failed to create Directory(%08x)\n", status);
173 #define DIR_TEST_OPEN_SUCCESS(h) \
174 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr); \
175 ok(status == STATUS_SUCCESS, "Failed to open Directory(%08x)\n", status);
176 #define DIR_TEST_CREATE_OPEN_SUCCESS(h,n) \
177 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
178 DIR_TEST_CREATE_SUCCESS(&h) pNtClose(h); DIR_TEST_OPEN_SUCCESS(&h) pNtClose(h); \
179 pRtlFreeUnicodeString(&str);
181 static BOOL
is_correct_dir( HANDLE dir
, const char *name
)
185 OBJECT_ATTRIBUTES attr
;
188 pRtlCreateUnicodeStringFromAsciiz(&str
, name
);
189 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, dir
, NULL
);
190 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
191 pRtlFreeUnicodeString(&str
);
192 if (h
) pNtClose( h
);
193 return (status
== STATUS_OBJECT_NAME_EXISTS
);
196 /* return a handle to the BaseNamedObjects dir where kernel32 objects get created */
197 static HANDLE
get_base_dir(void)
199 static const char objname
[] = "om.c_get_base_dir_obj";
202 OBJECT_ATTRIBUTES attr
;
206 h
= CreateMutexA(NULL
, FALSE
, objname
);
207 ok(h
!= 0, "CreateMutexA failed got ret=%p (%d)\n", h
, GetLastError());
208 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, 0, NULL
);
210 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local");
211 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
212 pRtlFreeUnicodeString(&str
);
213 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
214 if (!status
) pNtClose( dir
);
216 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
217 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
218 pRtlFreeUnicodeString(&str
);
219 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
220 if (!status
) pNtClose( dir
);
222 for (i
= 0; i
< 20; i
++)
225 sprintf( name
, "\\BaseNamedObjects\\Session\\%u", i
);
226 pRtlCreateUnicodeStringFromAsciiz(&str
, name
);
227 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
228 pRtlFreeUnicodeString(&str
);
229 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
230 if (!status
) pNtClose( dir
);
239 static void test_name_collisions(void)
243 OBJECT_ATTRIBUTES attr
;
244 HANDLE dir
, h
, h1
, h2
;
248 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
249 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
250 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_NAME_COLLISION
)
251 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, 0, NULL
);
253 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_NAME_EXISTS
)
255 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
256 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
257 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
258 pRtlFreeUnicodeString(&str
);
260 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\??\\PIPE\\om.c-mutant");
261 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
262 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
|| status
== STATUS_OBJECT_PATH_NOT_FOUND
,
263 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
264 pRtlFreeUnicodeString(&str
);
266 if (!(dir
= get_base_dir()))
268 win_skip( "couldn't find the BaseNamedObjects dir\n" );
271 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-test");
272 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, dir
, NULL
);
273 h
= CreateMutexA(NULL
, FALSE
, "om.c-test");
274 ok(h
!= 0, "CreateMutexA failed got ret=%p (%d)\n", h
, GetLastError());
275 status
= pNtCreateMutant(&h1
, GENERIC_ALL
, &attr
, FALSE
);
276 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
277 "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
278 h2
= CreateMutexA(NULL
, FALSE
, "om.c-test");
279 winerr
= GetLastError();
280 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
281 "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
286 h
= CreateEventA(NULL
, FALSE
, FALSE
, "om.c-test");
287 ok(h
!= 0, "CreateEventA failed got ret=%p (%d)\n", h
, GetLastError());
288 status
= pNtCreateEvent(&h1
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
289 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
290 "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
291 h2
= CreateEventA(NULL
, FALSE
, FALSE
, "om.c-test");
292 winerr
= GetLastError();
293 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
294 "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
299 h
= CreateSemaphoreA(NULL
, 1, 2, "om.c-test");
300 ok(h
!= 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h
, GetLastError());
301 status
= pNtCreateSemaphore(&h1
, GENERIC_ALL
, &attr
, 1, 2);
302 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
303 "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
304 h2
= CreateSemaphoreA(NULL
, 1, 2, "om.c-test");
305 winerr
= GetLastError();
306 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
307 "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
312 h
= pCreateWaitableTimerA(NULL
, TRUE
, "om.c-test");
313 ok(h
!= 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h
, GetLastError());
314 status
= pNtCreateTimer(&h1
, GENERIC_ALL
, &attr
, NotificationTimer
);
315 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
316 "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
317 h2
= pCreateWaitableTimerA(NULL
, TRUE
, "om.c-test");
318 winerr
= GetLastError();
319 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
320 "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
325 h
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 256, "om.c-test");
326 ok(h
!= 0, "CreateFileMappingA failed got ret=%p (%d)\n", h
, GetLastError());
327 size
.u
.LowPart
= 256;
329 status
= pNtCreateSection(&h1
, SECTION_MAP_WRITE
, &attr
, &size
, PAGE_READWRITE
, SEC_COMMIT
, 0);
330 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
331 "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
332 h2
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 256, "om.c-test");
333 winerr
= GetLastError();
334 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
335 "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
340 pRtlFreeUnicodeString(&str
);
344 static void test_directory(void)
348 OBJECT_ATTRIBUTES attr
;
352 /* No name and/or no attributes */
353 status
= pNtCreateDirectoryObject(NULL
, DIRECTORY_QUERY
, &attr
);
354 ok(status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
,
355 "NtCreateDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
356 status
= pNtOpenDirectoryObject(NULL
, DIRECTORY_QUERY
, &attr
);
357 ok(status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
,
358 "NtOpenDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
360 status
= pNtCreateDirectoryObject(&h
, DIRECTORY_QUERY
, NULL
);
361 ok(status
== STATUS_SUCCESS
, "Failed to create Directory without attributes(%08x)\n", status
);
363 status
= pNtOpenDirectoryObject(&h
, DIRECTORY_QUERY
, NULL
);
364 ok(status
== STATUS_INVALID_PARAMETER
,
365 "NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
367 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
368 DIR_TEST_CREATE_SUCCESS(&dir
)
369 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
372 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
374 pRtlCreateUnicodeStringFromAsciiz(&str
, "");
375 DIR_TEST_CREATE_SUCCESS(&h
)
377 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
378 pRtlFreeUnicodeString(&str
);
381 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD
)
382 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID
)
383 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID
)
384 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID
)
385 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND
)
387 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test");
388 DIR_TEST_CREATE_SUCCESS(&h
)
389 DIR_TEST_OPEN_SUCCESS(&dir1
)
390 pRtlFreeUnicodeString(&str
);
395 /* Use of root directory */
397 /* Can't use symlinks as a directory */
398 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local");
399 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
400 status
= pNtOpenSymbolicLinkObject(&dir
, SYMBOLIC_LINK_QUERY
, &attr
);
401 is_nt4
= (status
== STATUS_OBJECT_NAME_NOT_FOUND
); /* nt4 doesn't have Local\\ symlink */
404 ok(status
== STATUS_SUCCESS
, "Failed to open SymbolicLink(%08x)\n", status
);
405 pRtlFreeUnicodeString(&str
);
406 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
407 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
408 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_TYPE_MISMATCH
)
409 pRtlFreeUnicodeString(&str
);
414 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
415 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
416 DIR_TEST_OPEN_SUCCESS(&dir
)
417 pRtlFreeUnicodeString(&str
);
419 InitializeObjectAttributes(&attr
, NULL
, 0, dir
, NULL
);
420 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_NAME_INVALID
)
422 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
423 DIR_TEST_CREATE_OPEN_SUCCESS(h
, "")
424 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\", STATUS_OBJECT_PATH_SYNTAX_BAD
)
425 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD
)
426 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD
)
427 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND
)
429 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-test");
430 DIR_TEST_CREATE_SUCCESS(&dir1
)
431 DIR_TEST_OPEN_SUCCESS(&h
)
432 pRtlFreeUnicodeString(&str
);
438 /* Nested directories */
439 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
440 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
441 DIR_TEST_OPEN_SUCCESS(&dir
)
442 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
443 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
444 pRtlFreeUnicodeString(&str
);
447 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
448 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test");
449 DIR_TEST_CREATE_SUCCESS(&dir
)
450 pRtlFreeUnicodeString(&str
);
451 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test\\one more level");
452 DIR_TEST_CREATE_SUCCESS(&h
)
453 pRtlFreeUnicodeString(&str
);
455 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
456 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
457 DIR_TEST_CREATE_SUCCESS(&h
)
458 pRtlFreeUnicodeString(&str
);
465 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
466 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Global\\om.c-test");
467 DIR_TEST_CREATE_SUCCESS(&dir
)
468 pRtlFreeUnicodeString(&str
);
469 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
470 DIR_TEST_CREATE_SUCCESS(&h
)
471 pRtlFreeUnicodeString(&str
);
473 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
474 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
475 DIR_TEST_CREATE_SUCCESS(&dir
)
476 pRtlFreeUnicodeString(&str
);
481 /* Create other objects using RootDirectory */
483 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
484 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
485 DIR_TEST_OPEN_SUCCESS(&dir
)
486 pRtlFreeUnicodeString(&str
);
487 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
489 /* Test invalid paths */
490 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\om.c-mutant");
491 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
492 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
493 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
494 pRtlFreeUnicodeString(&str
);
495 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\om.c-mutant\\");
496 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
497 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
498 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
499 pRtlFreeUnicodeString(&str
);
501 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c\\-mutant");
502 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
503 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
,
504 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
505 pRtlFreeUnicodeString(&str
);
507 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-mutant");
508 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
509 ok(status
== STATUS_SUCCESS
, "Failed to create Mutant(%08x)\n", status
);
510 pRtlFreeUnicodeString(&str
);
516 #define SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e2) \
517 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
518 pRtlCreateUnicodeStringFromAsciiz(&target, t);\
519 status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target);\
520 ok(status == e || status == e2, \
521 "NtCreateSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
522 status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr);\
523 ok(status == e || status == e2, \
524 "NtOpenSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
525 pRtlFreeUnicodeString(&target);\
526 pRtlFreeUnicodeString(&str);
528 #define SYMLNK_TEST_CREATE_OPEN_FAILURE(h,n,t,e) SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e)
530 static void test_symboliclink(void)
533 UNICODE_STRING str
, target
;
534 OBJECT_ATTRIBUTES attr
;
536 IO_STATUS_BLOCK iosb
;
538 /* No name and/or no attributes */
539 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
540 SYMLNK_TEST_CREATE_OPEN_FAILURE2(NULL
, "", "", STATUS_ACCESS_VIOLATION
, STATUS_INVALID_PARAMETER
)
542 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
, NULL
);
543 ok(status
== STATUS_ACCESS_VIOLATION
,
544 "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
545 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
);
546 ok(status
== STATUS_INVALID_PARAMETER
,
547 "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
550 pRtlCreateUnicodeStringFromAsciiz(&target
, "\\DosDevices");
551 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
, &target
);
552 ok(status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_VIOLATION
, /* nt4 */
553 "NtCreateSymbolicLinkObject failed(%08x)\n", status
);
554 pRtlFreeUnicodeString(&target
);
555 if (!status
) pNtClose(h
);
557 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
558 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
559 ok(status
== STATUS_INVALID_PARAMETER
||
560 broken(status
== STATUS_SUCCESS
), /* nt4 */
561 "NtCreateSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
562 if (!status
) pNtClose(h
);
563 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
);
564 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
565 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
568 pRtlCreateUnicodeStringFromAsciiz(&target
, "anywhere");
569 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
571 pRtlCreateUnicodeStringFromAsciiz(&str
, "");
572 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
573 ok(status
== STATUS_SUCCESS
, "Failed to create SymbolicLink(%08x)\n", status
);
574 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
);
575 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
576 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
578 pRtlFreeUnicodeString(&str
);
580 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
581 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
582 todo_wine
ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
583 "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
584 pRtlFreeUnicodeString(&str
);
585 pRtlFreeUnicodeString(&target
);
587 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD
)
588 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
589 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
590 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
591 SYMLNK_TEST_CREATE_OPEN_FAILURE2(&h
, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere",
592 STATUS_OBJECT_NAME_INVALID
, STATUS_OBJECT_PATH_NOT_FOUND
)
596 if (!(dir
= get_base_dir()))
598 win_skip( "couldn't find the BaseNamedObjects dir\n" );
602 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
603 pRtlCreateUnicodeStringFromAsciiz(&str
, "test-link");
604 pRtlCreateUnicodeStringFromAsciiz(&target
, "\\DosDevices");
605 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
606 ok(status
== STATUS_SUCCESS
, "Failed to create SymbolicLink(%08x)\n", status
);
607 pRtlFreeUnicodeString(&str
);
608 pRtlFreeUnicodeString(&target
);
610 pRtlCreateUnicodeStringFromAsciiz(&str
, "test-link\\NUL");
611 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
612 todo_wine
ok(status
== STATUS_SUCCESS
, "Failed to open NUL device(%08x)\n", status
);
613 pRtlFreeUnicodeString(&str
);
622 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
623 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
627 skip("not running on NT, skipping test\n");
631 pCreateWaitableTimerA
= (void *)GetProcAddress(hkernel32
, "CreateWaitableTimerA");
633 pRtlCreateUnicodeStringFromAsciiz
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeStringFromAsciiz");
634 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
635 pNtCreateEvent
= (void *)GetProcAddress(hntdll
, "NtCreateEvent");
636 pNtCreateMutant
= (void *)GetProcAddress(hntdll
, "NtCreateMutant");
637 pNtOpenMutant
= (void *)GetProcAddress(hntdll
, "NtOpenMutant");
638 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
639 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
640 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
641 pNtCreateNamedPipeFile
= (void *)GetProcAddress(hntdll
, "NtCreateNamedPipeFile");
642 pNtOpenDirectoryObject
= (void *)GetProcAddress(hntdll
, "NtOpenDirectoryObject");
643 pNtCreateDirectoryObject
= (void *)GetProcAddress(hntdll
, "NtCreateDirectoryObject");
644 pNtOpenSymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtOpenSymbolicLinkObject");
645 pNtCreateSymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtCreateSymbolicLinkObject");
646 pNtCreateSemaphore
= (void *)GetProcAddress(hntdll
, "NtCreateSemaphore");
647 pNtCreateTimer
= (void *)GetProcAddress(hntdll
, "NtCreateTimer");
648 pNtCreateSection
= (void *)GetProcAddress(hntdll
, "NtCreateSection");
650 test_case_sensitive();
651 test_namespace_pipe();
652 test_name_collisions();