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
);
47 static NTSTATUS (WINAPI
*pNtQuerySymbolicLinkObject
)(HANDLE
,PUNICODE_STRING
,PULONG
);
48 static NTSTATUS (WINAPI
*pNtQueryObject
)(HANDLE
,OBJECT_INFORMATION_CLASS
,PVOID
,ULONG
,PULONG
);
51 static void test_case_sensitive (void)
53 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};
54 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};
55 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};
56 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};
58 OBJECT_ATTRIBUTES attr
;
60 HANDLE Event
, Mutant
, h
;
62 pRtlInitUnicodeString(&str
, buffer1
);
63 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
64 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
65 ok(status
== STATUS_SUCCESS
, "Failed to create Mutant(%08x)\n", status
);
67 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
68 ok(status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
69 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status
);
71 pRtlInitUnicodeString(&str
, buffer2
);
72 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
73 status
= pNtCreateEvent(&Event
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
74 ok(status
== STATUS_SUCCESS
, "Failed to create Event(%08x)\n", status
);
76 pRtlInitUnicodeString(&str
, buffer3
);
77 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
78 status
= pNtOpenMutant(&h
, GENERIC_ALL
, &attr
);
79 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
80 "NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
84 pRtlInitUnicodeString(&str
, buffer4
);
85 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
86 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
87 ok(status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_OBJECT_TYPE_MISMATCH
,
88 "NtCreateMutant should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status
);
90 status
= pNtCreateEvent(&h
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
91 ok(status
== STATUS_OBJECT_NAME_COLLISION
,
92 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08x)\n", status
);
95 status
= pNtCreateMutant(&Mutant
, GENERIC_ALL
, &attr
, FALSE
);
96 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
,
97 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
102 static void test_namespace_pipe(void)
104 static const WCHAR buffer1
[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0};
105 static const WCHAR buffer2
[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0};
106 static const WCHAR buffer3
[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0};
107 static const WCHAR buffer4
[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0};
108 OBJECT_ATTRIBUTES attr
;
110 IO_STATUS_BLOCK iosb
;
112 LARGE_INTEGER timeout
;
115 timeout
.QuadPart
= -10000;
117 pRtlInitUnicodeString(&str
, buffer1
);
118 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
119 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
120 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
121 ok(status
== STATUS_SUCCESS
, "Failed to create NamedPipe(%08x)\n", status
);
123 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
124 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
125 ok(status
== STATUS_INSTANCE_NOT_AVAILABLE
,
126 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status
);
128 pRtlInitUnicodeString(&str
, buffer2
);
129 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
130 status
= pNtCreateNamedPipeFile(&pipe
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
131 FILE_CREATE
, FILE_PIPE_FULL_DUPLEX
, FALSE
, FALSE
, FALSE
, 1, 256, 256, &timeout
);
132 ok(status
== STATUS_INSTANCE_NOT_AVAILABLE
,
133 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status
);
135 h
= CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
136 OPEN_EXISTING
, 0, 0 );
137 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open NamedPipe (%u)\n", GetLastError());
140 pRtlInitUnicodeString(&str
, buffer3
);
141 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
142 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
143 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
||
144 status
== STATUS_PIPE_NOT_AVAILABLE
||
145 status
== STATUS_OBJECT_NAME_INVALID
, /* vista */
146 "NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
148 pRtlInitUnicodeString(&str
, buffer4
);
149 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
150 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
151 ok(status
== STATUS_OBJECT_NAME_NOT_FOUND
||
152 status
== STATUS_OBJECT_NAME_INVALID
, /* vista */
153 "NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status
);
158 #define DIRECTORY_QUERY (0x0001)
159 #define SYMBOLIC_LINK_QUERY 0x0001
161 #define DIR_TEST_CREATE_FAILURE(h,e) \
162 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr);\
163 ok(status == e,"NtCreateDirectoryObject should have failed with %s got(%08x)\n", #e, status);
164 #define DIR_TEST_OPEN_FAILURE(h,e) \
165 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr);\
166 ok(status == e,"NtOpenDirectoryObject should have failed with %s got(%08x)\n", #e, status);
167 #define DIR_TEST_CREATE_OPEN_FAILURE(h,n,e) \
168 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
169 DIR_TEST_CREATE_FAILURE(h,e) DIR_TEST_OPEN_FAILURE(h,e)\
170 pRtlFreeUnicodeString(&str);
172 #define DIR_TEST_CREATE_SUCCESS(h) \
173 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr); \
174 ok(status == STATUS_SUCCESS, "Failed to create Directory(%08x)\n", status);
175 #define DIR_TEST_OPEN_SUCCESS(h) \
176 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr); \
177 ok(status == STATUS_SUCCESS, "Failed to open Directory(%08x)\n", status);
178 #define DIR_TEST_CREATE_OPEN_SUCCESS(h,n) \
179 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
180 DIR_TEST_CREATE_SUCCESS(&h) pNtClose(h); DIR_TEST_OPEN_SUCCESS(&h) pNtClose(h); \
181 pRtlFreeUnicodeString(&str);
183 static BOOL
is_correct_dir( HANDLE dir
, const char *name
)
187 OBJECT_ATTRIBUTES attr
;
190 pRtlCreateUnicodeStringFromAsciiz(&str
, name
);
191 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, dir
, NULL
);
192 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
193 pRtlFreeUnicodeString(&str
);
194 if (h
) pNtClose( h
);
195 return (status
== STATUS_OBJECT_NAME_EXISTS
);
198 /* return a handle to the BaseNamedObjects dir where kernel32 objects get created */
199 static HANDLE
get_base_dir(void)
201 static const char objname
[] = "om.c_get_base_dir_obj";
204 OBJECT_ATTRIBUTES attr
;
208 h
= CreateMutexA(NULL
, FALSE
, objname
);
209 ok(h
!= 0, "CreateMutexA failed got ret=%p (%d)\n", h
, GetLastError());
210 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, 0, NULL
);
212 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local");
213 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
214 pRtlFreeUnicodeString(&str
);
215 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
216 if (!status
) pNtClose( dir
);
218 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
219 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
220 pRtlFreeUnicodeString(&str
);
221 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
222 if (!status
) pNtClose( dir
);
224 for (i
= 0; i
< 20; i
++)
227 sprintf( name
, "\\BaseNamedObjects\\Session\\%u", i
);
228 pRtlCreateUnicodeStringFromAsciiz(&str
, name
);
229 status
= pNtOpenDirectoryObject(&dir
, DIRECTORY_QUERY
, &attr
);
230 pRtlFreeUnicodeString(&str
);
231 if (!status
&& is_correct_dir( dir
, objname
)) goto done
;
232 if (!status
) pNtClose( dir
);
241 static void test_name_collisions(void)
245 OBJECT_ATTRIBUTES attr
;
246 HANDLE dir
, h
, h1
, h2
;
250 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
251 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
252 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_NAME_COLLISION
)
253 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, 0, NULL
);
255 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_NAME_EXISTS
)
257 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
258 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
259 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
260 pRtlFreeUnicodeString(&str
);
262 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\??\\PIPE\\om.c-mutant");
263 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
264 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
|| status
== STATUS_OBJECT_PATH_NOT_FOUND
,
265 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
266 pRtlFreeUnicodeString(&str
);
268 if (!(dir
= get_base_dir()))
270 win_skip( "couldn't find the BaseNamedObjects dir\n" );
273 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-test");
274 InitializeObjectAttributes(&attr
, &str
, OBJ_OPENIF
, dir
, NULL
);
275 h
= CreateMutexA(NULL
, FALSE
, "om.c-test");
276 ok(h
!= 0, "CreateMutexA failed got ret=%p (%d)\n", h
, GetLastError());
277 status
= pNtCreateMutant(&h1
, GENERIC_ALL
, &attr
, FALSE
);
278 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
279 "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
280 h2
= CreateMutexA(NULL
, FALSE
, "om.c-test");
281 winerr
= GetLastError();
282 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
283 "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
288 h
= CreateEventA(NULL
, FALSE
, FALSE
, "om.c-test");
289 ok(h
!= 0, "CreateEventA failed got ret=%p (%d)\n", h
, GetLastError());
290 status
= pNtCreateEvent(&h1
, GENERIC_ALL
, &attr
, FALSE
, FALSE
);
291 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
292 "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
293 h2
= CreateEventA(NULL
, FALSE
, FALSE
, "om.c-test");
294 winerr
= GetLastError();
295 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
296 "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
301 h
= CreateSemaphoreA(NULL
, 1, 2, "om.c-test");
302 ok(h
!= 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h
, GetLastError());
303 status
= pNtCreateSemaphore(&h1
, GENERIC_ALL
, &attr
, 1, 2);
304 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
305 "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
306 h2
= CreateSemaphoreA(NULL
, 1, 2, "om.c-test");
307 winerr
= GetLastError();
308 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
309 "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
314 h
= pCreateWaitableTimerA(NULL
, TRUE
, "om.c-test");
315 ok(h
!= 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h
, GetLastError());
316 status
= pNtCreateTimer(&h1
, GENERIC_ALL
, &attr
, NotificationTimer
);
317 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
318 "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
319 h2
= pCreateWaitableTimerA(NULL
, TRUE
, "om.c-test");
320 winerr
= GetLastError();
321 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
322 "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
327 h
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 256, "om.c-test");
328 ok(h
!= 0, "CreateFileMappingA failed got ret=%p (%d)\n", h
, GetLastError());
329 size
.u
.LowPart
= 256;
331 status
= pNtCreateSection(&h1
, SECTION_MAP_WRITE
, &attr
, &size
, PAGE_READWRITE
, SEC_COMMIT
, 0);
332 ok(status
== STATUS_OBJECT_NAME_EXISTS
&& h1
!= NULL
,
333 "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status
);
334 h2
= CreateFileMappingA(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, 256, "om.c-test");
335 winerr
= GetLastError();
336 ok(h2
!= 0 && winerr
== ERROR_ALREADY_EXISTS
,
337 "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2
, winerr
);
342 pRtlFreeUnicodeString(&str
);
346 static void test_directory(void)
350 OBJECT_ATTRIBUTES attr
;
354 /* No name and/or no attributes */
355 status
= pNtCreateDirectoryObject(NULL
, DIRECTORY_QUERY
, &attr
);
356 ok(status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
,
357 "NtCreateDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
358 status
= pNtOpenDirectoryObject(NULL
, DIRECTORY_QUERY
, &attr
);
359 ok(status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
,
360 "NtOpenDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
362 status
= pNtCreateDirectoryObject(&h
, DIRECTORY_QUERY
, NULL
);
363 ok(status
== STATUS_SUCCESS
, "Failed to create Directory without attributes(%08x)\n", status
);
365 status
= pNtOpenDirectoryObject(&h
, DIRECTORY_QUERY
, NULL
);
366 ok(status
== STATUS_INVALID_PARAMETER
,
367 "NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
369 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
370 DIR_TEST_CREATE_SUCCESS(&dir
)
371 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
374 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
376 pRtlCreateUnicodeStringFromAsciiz(&str
, "");
377 DIR_TEST_CREATE_SUCCESS(&h
)
379 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
380 pRtlFreeUnicodeString(&str
);
383 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD
)
384 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID
)
385 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID
)
386 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID
)
387 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND
)
389 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test");
390 DIR_TEST_CREATE_SUCCESS(&h
)
391 DIR_TEST_OPEN_SUCCESS(&dir1
)
392 pRtlFreeUnicodeString(&str
);
397 /* Use of root directory */
399 /* Can't use symlinks as a directory */
400 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local");
401 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
402 status
= pNtOpenSymbolicLinkObject(&dir
, SYMBOLIC_LINK_QUERY
, &attr
);
403 is_nt4
= (status
== STATUS_OBJECT_NAME_NOT_FOUND
); /* nt4 doesn't have Local\\ symlink */
409 ok(status
== STATUS_SUCCESS
, "Failed to open SymbolicLink(%08x)\n", status
);
410 pRtlFreeUnicodeString(&str
);
411 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
412 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
413 DIR_TEST_CREATE_FAILURE(&h
, STATUS_OBJECT_TYPE_MISMATCH
)
414 pRtlFreeUnicodeString(&str
);
417 str
.MaximumLength
= sizeof(buffer
);
419 memset( buffer
, 0xaa, sizeof(buffer
) );
420 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
421 ok( status
== STATUS_SUCCESS
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
422 full_len
= str
.Length
+ sizeof(WCHAR
);
423 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
424 ok( buffer
[len
/ sizeof(WCHAR
) - 1] == 0, "no terminating null\n" );
426 str
.MaximumLength
= str
.Length
;
428 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
429 ok( status
== STATUS_BUFFER_TOO_SMALL
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
430 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
432 str
.MaximumLength
= 0;
434 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
435 ok( status
== STATUS_BUFFER_TOO_SMALL
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
436 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
438 str
.MaximumLength
= str
.Length
+ sizeof(WCHAR
);
440 status
= pNtQuerySymbolicLinkObject( dir
, &str
, &len
);
441 ok( status
== STATUS_SUCCESS
, "NtQuerySymbolicLinkObject failed %08x\n", status
);
442 ok( len
== full_len
, "bad length %u/%u\n", len
, full_len
);
447 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
448 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
449 DIR_TEST_OPEN_SUCCESS(&dir
)
450 pRtlFreeUnicodeString(&str
);
452 InitializeObjectAttributes(&attr
, NULL
, 0, dir
, NULL
);
453 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_NAME_INVALID
)
455 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
456 DIR_TEST_CREATE_OPEN_SUCCESS(h
, "")
457 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\", STATUS_OBJECT_PATH_SYNTAX_BAD
)
458 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD
)
459 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD
)
460 DIR_TEST_CREATE_OPEN_FAILURE(&h
, "om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND
)
462 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-test");
463 DIR_TEST_CREATE_SUCCESS(&dir1
)
464 DIR_TEST_OPEN_SUCCESS(&h
)
465 pRtlFreeUnicodeString(&str
);
471 /* Nested directories */
472 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
473 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
474 DIR_TEST_OPEN_SUCCESS(&dir
)
475 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
476 DIR_TEST_OPEN_FAILURE(&h
, STATUS_OBJECT_PATH_SYNTAX_BAD
)
477 pRtlFreeUnicodeString(&str
);
480 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
481 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test");
482 DIR_TEST_CREATE_SUCCESS(&dir
)
483 pRtlFreeUnicodeString(&str
);
484 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\om.c-test\\one more level");
485 DIR_TEST_CREATE_SUCCESS(&h
)
486 pRtlFreeUnicodeString(&str
);
488 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
489 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
490 DIR_TEST_CREATE_SUCCESS(&h
)
491 pRtlFreeUnicodeString(&str
);
498 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
499 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Global\\om.c-test");
500 DIR_TEST_CREATE_SUCCESS(&dir
)
501 pRtlFreeUnicodeString(&str
);
502 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
503 DIR_TEST_CREATE_SUCCESS(&h
)
504 pRtlFreeUnicodeString(&str
);
506 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
507 pRtlCreateUnicodeStringFromAsciiz(&str
, "one more level");
508 DIR_TEST_CREATE_SUCCESS(&dir
)
509 pRtlFreeUnicodeString(&str
);
514 /* Create other objects using RootDirectory */
516 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
517 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\BaseNamedObjects");
518 DIR_TEST_OPEN_SUCCESS(&dir
)
519 pRtlFreeUnicodeString(&str
);
520 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
522 /* Test invalid paths */
523 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\om.c-mutant");
524 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
525 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
526 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
527 pRtlFreeUnicodeString(&str
);
528 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\om.c-mutant\\");
529 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
530 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
531 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
532 pRtlFreeUnicodeString(&str
);
534 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c\\-mutant");
535 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
536 ok(status
== STATUS_OBJECT_PATH_NOT_FOUND
,
537 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status
);
538 pRtlFreeUnicodeString(&str
);
540 pRtlCreateUnicodeStringFromAsciiz(&str
, "om.c-mutant");
541 status
= pNtCreateMutant(&h
, GENERIC_ALL
, &attr
, FALSE
);
542 ok(status
== STATUS_SUCCESS
, "Failed to create Mutant(%08x)\n", status
);
543 pRtlFreeUnicodeString(&str
);
549 #define SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e2) \
550 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
551 pRtlCreateUnicodeStringFromAsciiz(&target, t);\
552 status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target);\
553 ok(status == e || status == e2, \
554 "NtCreateSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
555 status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr);\
556 ok(status == e || status == e2, \
557 "NtOpenSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
558 pRtlFreeUnicodeString(&target);\
559 pRtlFreeUnicodeString(&str);
561 #define SYMLNK_TEST_CREATE_OPEN_FAILURE(h,n,t,e) SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e)
563 static void test_symboliclink(void)
566 UNICODE_STRING str
, target
;
567 OBJECT_ATTRIBUTES attr
;
569 IO_STATUS_BLOCK iosb
;
571 /* No name and/or no attributes */
572 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
573 SYMLNK_TEST_CREATE_OPEN_FAILURE2(NULL
, "", "", STATUS_ACCESS_VIOLATION
, STATUS_INVALID_PARAMETER
)
575 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
, NULL
);
576 ok(status
== STATUS_ACCESS_VIOLATION
,
577 "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status
);
578 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
);
579 ok(status
== STATUS_INVALID_PARAMETER
,
580 "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
583 pRtlCreateUnicodeStringFromAsciiz(&target
, "\\DosDevices");
584 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, NULL
, &target
);
585 ok(status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_VIOLATION
, /* nt4 */
586 "NtCreateSymbolicLinkObject failed(%08x)\n", status
);
587 pRtlFreeUnicodeString(&target
);
588 if (!status
) pNtClose(h
);
590 InitializeObjectAttributes(&attr
, NULL
, 0, 0, NULL
);
591 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
592 ok(status
== STATUS_INVALID_PARAMETER
||
593 broken(status
== STATUS_SUCCESS
), /* nt4 */
594 "NtCreateSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status
);
595 if (!status
) pNtClose(h
);
596 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
);
597 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
598 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
601 pRtlCreateUnicodeStringFromAsciiz(&target
, "anywhere");
602 InitializeObjectAttributes(&attr
, &str
, 0, 0, NULL
);
604 pRtlCreateUnicodeStringFromAsciiz(&str
, "");
605 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
606 ok(status
== STATUS_SUCCESS
, "Failed to create SymbolicLink(%08x)\n", status
);
607 status
= pNtOpenSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
);
608 ok(status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
609 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status
);
611 pRtlFreeUnicodeString(&str
);
613 pRtlCreateUnicodeStringFromAsciiz(&str
, "\\");
614 status
= pNtCreateSymbolicLinkObject(&h
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
615 todo_wine
ok(status
== STATUS_OBJECT_TYPE_MISMATCH
,
616 "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status
);
617 pRtlFreeUnicodeString(&str
);
618 pRtlFreeUnicodeString(&target
);
620 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD
)
621 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
622 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
623 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h
, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID
)
624 SYMLNK_TEST_CREATE_OPEN_FAILURE2(&h
, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere",
625 STATUS_OBJECT_NAME_INVALID
, STATUS_OBJECT_PATH_NOT_FOUND
)
629 if (!(dir
= get_base_dir()))
631 win_skip( "couldn't find the BaseNamedObjects dir\n" );
635 InitializeObjectAttributes(&attr
, &str
, 0, dir
, NULL
);
636 pRtlCreateUnicodeStringFromAsciiz(&str
, "test-link");
637 pRtlCreateUnicodeStringFromAsciiz(&target
, "\\DosDevices");
638 status
= pNtCreateSymbolicLinkObject(&link
, SYMBOLIC_LINK_QUERY
, &attr
, &target
);
639 ok(status
== STATUS_SUCCESS
, "Failed to create SymbolicLink(%08x)\n", status
);
640 pRtlFreeUnicodeString(&str
);
641 pRtlFreeUnicodeString(&target
);
643 pRtlCreateUnicodeStringFromAsciiz(&str
, "test-link\\NUL");
644 status
= pNtOpenFile(&h
, GENERIC_READ
, &attr
, &iosb
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
);
645 todo_wine
ok(status
== STATUS_SUCCESS
, "Failed to open NUL device(%08x)\n", status
);
646 pRtlFreeUnicodeString(&str
);
653 static void test_query_object(void)
655 static const WCHAR name
[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',
656 '\\','t','e','s','t','_','e','v','e','n','t'};
664 handle
= CreateEventA( NULL
, FALSE
, FALSE
, "test_event" );
667 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, 0, &len
);
668 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
669 ok( len
>= sizeof(UNICODE_STRING
) + sizeof(name
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
672 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(UNICODE_STRING
), &len
);
673 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
674 ok( len
>= sizeof(UNICODE_STRING
) + sizeof(name
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
677 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(buffer
), &len
);
678 ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
679 ok( len
> sizeof(UNICODE_STRING
), "unexpected len %u\n", len
);
680 str
= (UNICODE_STRING
*)buffer
;
681 ok( sizeof(UNICODE_STRING
) + str
->Length
+ sizeof(WCHAR
) == len
, "unexpected len %u\n", len
);
682 ok( str
->Length
>= sizeof(name
), "unexpected len %u\n", str
->Length
);
683 /* there can be a \\Sessions prefix in the name */
684 ok( !memcmp( str
->Buffer
+ (str
->Length
- sizeof(name
)) / sizeof(WCHAR
), name
, sizeof(name
) ),
685 "wrong name %s\n", wine_dbgstr_w(str
->Buffer
) );
687 len
-= sizeof(WCHAR
);
688 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, len
, &len
);
689 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryObject failed %x\n", status
);
690 ok( len
>= sizeof(UNICODE_STRING
) + sizeof(name
) + sizeof(WCHAR
), "unexpected len %u\n", len
);
694 handle
= CreateEventA( NULL
, FALSE
, FALSE
, NULL
);
696 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(buffer
), &len
);
697 ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
698 ok( len
== sizeof(UNICODE_STRING
), "unexpected len %u\n", len
);
699 str
= (UNICODE_STRING
*)buffer
;
700 ok( str
->Length
== 0, "unexpected len %u\n", len
);
701 ok( str
->Buffer
== NULL
, "unexpected ptr %p\n", str
->Buffer
);
704 GetWindowsDirectoryA( dir
, MAX_PATH
);
705 handle
= CreateFileA( dir
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
706 FILE_FLAG_BACKUP_SEMANTICS
, 0 );
708 status
= pNtQueryObject( handle
, ObjectNameInformation
, buffer
, sizeof(buffer
), &len
);
709 ok( status
== STATUS_SUCCESS
, "NtQueryObject failed %x\n", status
);
710 ok( len
> sizeof(UNICODE_STRING
), "unexpected len %u\n", len
);
711 str
= (UNICODE_STRING
*)buffer
;
712 ok( sizeof(UNICODE_STRING
) + str
->Length
+ sizeof(WCHAR
) == len
||
713 broken(sizeof(UNICODE_STRING
) + str
->Length
== len
), /* NT4 */
714 "unexpected len %u\n", len
);
715 trace( "got %s len %u\n", wine_dbgstr_w(str
->Buffer
), len
);
721 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
722 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
726 skip("not running on NT, skipping test\n");
730 pCreateWaitableTimerA
= (void *)GetProcAddress(hkernel32
, "CreateWaitableTimerA");
732 pRtlCreateUnicodeStringFromAsciiz
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeStringFromAsciiz");
733 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
734 pNtCreateEvent
= (void *)GetProcAddress(hntdll
, "NtCreateEvent");
735 pNtCreateMutant
= (void *)GetProcAddress(hntdll
, "NtCreateMutant");
736 pNtOpenMutant
= (void *)GetProcAddress(hntdll
, "NtOpenMutant");
737 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
738 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
739 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
740 pNtCreateNamedPipeFile
= (void *)GetProcAddress(hntdll
, "NtCreateNamedPipeFile");
741 pNtOpenDirectoryObject
= (void *)GetProcAddress(hntdll
, "NtOpenDirectoryObject");
742 pNtCreateDirectoryObject
= (void *)GetProcAddress(hntdll
, "NtCreateDirectoryObject");
743 pNtOpenSymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtOpenSymbolicLinkObject");
744 pNtCreateSymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtCreateSymbolicLinkObject");
745 pNtQuerySymbolicLinkObject
= (void *)GetProcAddress(hntdll
, "NtQuerySymbolicLinkObject");
746 pNtCreateSemaphore
= (void *)GetProcAddress(hntdll
, "NtCreateSemaphore");
747 pNtCreateTimer
= (void *)GetProcAddress(hntdll
, "NtCreateTimer");
748 pNtCreateSection
= (void *)GetProcAddress(hntdll
, "NtCreateSection");
749 pNtQueryObject
= (void *)GetProcAddress(hntdll
, "NtQueryObject");
751 test_case_sensitive();
752 test_namespace_pipe();
753 test_name_collisions();