[REACTOS]
[reactos.git] / rostests / winetests / ntdll / om.c
1 /*
2 * Unit test suite for object manager functions
3 *
4 * Copyright 2005 Robert Shearman
5 * Copyright 2005 Vitaliy Margolen
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "ntdll_test.h"
23 #include "winternl.h"
24 #include "stdio.h"
25 #include "winnt.h"
26 #include "stdlib.h"
27
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);
49 static NTSTATUS (WINAPI *pNtReleaseSemaphore)(HANDLE handle, ULONG count, PULONG previous);
50
51
52 static void test_case_sensitive (void)
53 {
54 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};
55 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};
56 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};
57 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 NTSTATUS status;
59 OBJECT_ATTRIBUTES attr;
60 UNICODE_STRING str;
61 HANDLE Event, Mutant, h;
62
63 pRtlInitUnicodeString(&str, buffer1);
64 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
65 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
66 ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status);
67
68 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
69 ok(status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH,
70 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status);
71
72 pRtlInitUnicodeString(&str, buffer2);
73 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
74 status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
75 ok(status == STATUS_SUCCESS, "Failed to create Event(%08x)\n", status);
76
77 pRtlInitUnicodeString(&str, buffer3);
78 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
79 status = pNtOpenMutant(&h, GENERIC_ALL, &attr);
80 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
81 "NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
82
83 pNtClose(Mutant);
84
85 pRtlInitUnicodeString(&str, buffer4);
86 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
87 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
88 ok(status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH,
89 "NtCreateMutant should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status);
90
91 status = pNtCreateEvent(&h, GENERIC_ALL, &attr, FALSE, FALSE);
92 ok(status == STATUS_OBJECT_NAME_COLLISION,
93 "NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08x)\n", status);
94
95 attr.Attributes = 0;
96 status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
97 ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
98 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
99
100 pNtClose(Event);
101 }
102
103 static void test_namespace_pipe(void)
104 {
105 static const WCHAR buffer1[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0};
106 static const WCHAR buffer2[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0};
107 static const WCHAR buffer3[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0};
108 static const WCHAR buffer4[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0};
109 OBJECT_ATTRIBUTES attr;
110 UNICODE_STRING str;
111 IO_STATUS_BLOCK iosb;
112 NTSTATUS status;
113 LARGE_INTEGER timeout;
114 HANDLE pipe, h;
115
116 timeout.QuadPart = -10000;
117
118 pRtlInitUnicodeString(&str, buffer1);
119 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
120 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
121 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
122 ok(status == STATUS_SUCCESS, "Failed to create NamedPipe(%08x)\n", status);
123
124 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
125 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
126 ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
127 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status);
128
129 pRtlInitUnicodeString(&str, buffer2);
130 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
131 status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
132 FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
133 ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
134 "NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status);
135
136 h = CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
137 OPEN_EXISTING, 0, 0 );
138 ok(h != INVALID_HANDLE_VALUE, "Failed to open NamedPipe (%u)\n", GetLastError());
139 pNtClose(h);
140
141 pRtlInitUnicodeString(&str, buffer3);
142 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
143 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
144 ok(status == STATUS_OBJECT_PATH_NOT_FOUND ||
145 status == STATUS_PIPE_NOT_AVAILABLE ||
146 status == STATUS_OBJECT_NAME_INVALID || /* vista */
147 status == STATUS_OBJECT_NAME_NOT_FOUND, /* win8 */
148 "NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
149
150 pRtlInitUnicodeString(&str, buffer4);
151 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
152 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
153 ok(status == STATUS_OBJECT_NAME_NOT_FOUND ||
154 status == STATUS_OBJECT_NAME_INVALID, /* vista */
155 "NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status);
156
157 pNtClose(pipe);
158 }
159
160 #define DIRECTORY_QUERY (0x0001)
161 #define SYMBOLIC_LINK_QUERY 0x0001
162
163 #define DIR_TEST_CREATE_FAILURE(h,e) \
164 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr);\
165 ok(status == e,"NtCreateDirectoryObject should have failed with %s got(%08x)\n", #e, status);
166 #define DIR_TEST_OPEN_FAILURE(h,e) \
167 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr);\
168 ok(status == e,"NtOpenDirectoryObject should have failed with %s got(%08x)\n", #e, status);
169 #define DIR_TEST_CREATE_OPEN_FAILURE(h,n,e) \
170 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
171 DIR_TEST_CREATE_FAILURE(h,e) DIR_TEST_OPEN_FAILURE(h,e)\
172 pRtlFreeUnicodeString(&str);
173
174 #define DIR_TEST_CREATE_SUCCESS(h) \
175 status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr); \
176 ok(status == STATUS_SUCCESS, "Failed to create Directory(%08x)\n", status);
177 #define DIR_TEST_OPEN_SUCCESS(h) \
178 status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr); \
179 ok(status == STATUS_SUCCESS, "Failed to open Directory(%08x)\n", status);
180 #define DIR_TEST_CREATE_OPEN_SUCCESS(h,n) \
181 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
182 DIR_TEST_CREATE_SUCCESS(&h) pNtClose(h); DIR_TEST_OPEN_SUCCESS(&h) pNtClose(h); \
183 pRtlFreeUnicodeString(&str);
184
185 static BOOL is_correct_dir( HANDLE dir, const char *name )
186 {
187 NTSTATUS status;
188 UNICODE_STRING str;
189 OBJECT_ATTRIBUTES attr;
190 HANDLE h = 0;
191
192 pRtlCreateUnicodeStringFromAsciiz(&str, name);
193 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
194 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
195 pRtlFreeUnicodeString(&str);
196 if (h) pNtClose( h );
197 return (status == STATUS_OBJECT_NAME_EXISTS);
198 }
199
200 /* return a handle to the BaseNamedObjects dir where kernel32 objects get created */
201 static HANDLE get_base_dir(void)
202 {
203 static const char objname[] = "om.c_get_base_dir_obj";
204 NTSTATUS status;
205 UNICODE_STRING str;
206 OBJECT_ATTRIBUTES attr;
207 HANDLE dir, h;
208 unsigned int i;
209
210 h = CreateMutexA(NULL, FALSE, objname);
211 ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
212 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
213
214 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local");
215 status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
216 pRtlFreeUnicodeString(&str);
217 if (!status && is_correct_dir( dir, objname )) goto done;
218 if (!status) pNtClose( dir );
219
220 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
221 status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
222 pRtlFreeUnicodeString(&str);
223 if (!status && is_correct_dir( dir, objname )) goto done;
224 if (!status) pNtClose( dir );
225
226 for (i = 0; i < 20; i++)
227 {
228 char name[40];
229 sprintf( name, "\\BaseNamedObjects\\Session\\%u", i );
230 pRtlCreateUnicodeStringFromAsciiz(&str, name );
231 status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
232 pRtlFreeUnicodeString(&str);
233 if (!status && is_correct_dir( dir, objname )) goto done;
234 if (!status) pNtClose( dir );
235 }
236 dir = 0;
237
238 done:
239 pNtClose( h );
240 return dir;
241 }
242
243 static void test_name_collisions(void)
244 {
245 NTSTATUS status;
246 UNICODE_STRING str;
247 OBJECT_ATTRIBUTES attr;
248 HANDLE dir, h, h1, h2;
249 DWORD winerr;
250 LARGE_INTEGER size;
251
252 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
253 pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
254 DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_COLLISION)
255 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
256
257 DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_EXISTS)
258 pNtClose(h);
259 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
260 ok(status == STATUS_OBJECT_TYPE_MISMATCH,
261 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
262 pRtlFreeUnicodeString(&str);
263
264 pRtlCreateUnicodeStringFromAsciiz(&str, "\\??\\PIPE\\om.c-mutant");
265 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
266 ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_OBJECT_PATH_NOT_FOUND,
267 "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
268 pRtlFreeUnicodeString(&str);
269
270 if (!(dir = get_base_dir()))
271 {
272 win_skip( "couldn't find the BaseNamedObjects dir\n" );
273 return;
274 }
275 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
276 InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
277 h = CreateMutexA(NULL, FALSE, "om.c-test");
278 ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
279 status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE);
280 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
281 "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
282 h2 = CreateMutexA(NULL, FALSE, "om.c-test");
283 winerr = GetLastError();
284 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
285 "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
286 pNtClose(h);
287 pNtClose(h1);
288 pNtClose(h2);
289
290 h = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
291 ok(h != 0, "CreateEventA failed got ret=%p (%d)\n", h, GetLastError());
292 status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE);
293 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
294 "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
295 h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
296 winerr = GetLastError();
297 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
298 "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
299 pNtClose(h);
300 pNtClose(h1);
301 pNtClose(h2);
302
303 h = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
304 ok(h != 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h, GetLastError());
305 status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2);
306 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
307 "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
308 h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
309 winerr = GetLastError();
310 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
311 "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
312 pNtClose(h);
313 pNtClose(h1);
314 pNtClose(h2);
315
316 h = pCreateWaitableTimerA(NULL, TRUE, "om.c-test");
317 ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h, GetLastError());
318 status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer);
319 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
320 "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
321 h2 = pCreateWaitableTimerA(NULL, TRUE, "om.c-test");
322 winerr = GetLastError();
323 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
324 "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
325 pNtClose(h);
326 pNtClose(h1);
327 pNtClose(h2);
328
329 h = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
330 ok(h != 0, "CreateFileMappingA failed got ret=%p (%d)\n", h, GetLastError());
331 size.u.LowPart = 256;
332 size.u.HighPart = 0;
333 status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0);
334 ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
335 "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
336 h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
337 winerr = GetLastError();
338 ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
339 "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
340 pNtClose(h);
341 pNtClose(h1);
342 pNtClose(h2);
343
344 pRtlFreeUnicodeString(&str);
345 pNtClose(dir);
346 }
347
348 static void test_directory(void)
349 {
350 NTSTATUS status;
351 UNICODE_STRING str;
352 OBJECT_ATTRIBUTES attr;
353 HANDLE dir, dir1, h;
354 BOOL is_nt4;
355
356 /* No name and/or no attributes */
357 status = pNtCreateDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
358 ok(status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER,
359 "NtCreateDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
360 status = pNtOpenDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
361 ok(status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER,
362 "NtOpenDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
363
364 status = pNtCreateDirectoryObject(&h, DIRECTORY_QUERY, NULL);
365 ok(status == STATUS_SUCCESS, "Failed to create Directory without attributes(%08x)\n", status);
366 pNtClose(h);
367 status = pNtOpenDirectoryObject(&h, DIRECTORY_QUERY, NULL);
368 ok(status == STATUS_INVALID_PARAMETER,
369 "NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
370
371 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
372 DIR_TEST_CREATE_SUCCESS(&dir)
373 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
374
375 /* Bad name */
376 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
377
378 pRtlCreateUnicodeStringFromAsciiz(&str, "");
379 DIR_TEST_CREATE_SUCCESS(&h)
380 pNtClose(h);
381 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
382 pRtlFreeUnicodeString(&str);
383 pNtClose(dir);
384
385 DIR_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD)
386 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID)
387 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID)
388 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID)
389 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND)
390
391 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test");
392 DIR_TEST_CREATE_SUCCESS(&h)
393 DIR_TEST_OPEN_SUCCESS(&dir1)
394 pRtlFreeUnicodeString(&str);
395 pNtClose(h);
396 pNtClose(dir1);
397
398
399 /* Use of root directory */
400
401 /* Can't use symlinks as a directory */
402 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local");
403 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
404 status = pNtOpenSymbolicLinkObject(&dir, SYMBOLIC_LINK_QUERY, &attr);
405 is_nt4 = (status == STATUS_OBJECT_NAME_NOT_FOUND); /* nt4 doesn't have Local\\ symlink */
406 if (!is_nt4)
407 {
408 WCHAR buffer[256];
409 ULONG len, full_len;
410
411 ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08x)\n", status);
412 pRtlFreeUnicodeString(&str);
413 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
414 pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
415 DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_TYPE_MISMATCH)
416 pRtlFreeUnicodeString(&str);
417
418 str.Buffer = buffer;
419 str.MaximumLength = sizeof(buffer);
420 len = 0xdeadbeef;
421 memset( buffer, 0xaa, sizeof(buffer) );
422 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
423 ok( status == STATUS_SUCCESS, "NtQuerySymbolicLinkObject failed %08x\n", status );
424 if (status != STATUS_SUCCESS)
425 goto error;
426 full_len = str.Length + sizeof(WCHAR);
427 ok( len == full_len, "bad length %u/%u\n", len, full_len );
428 if (len == full_len)
429 ok( buffer[len / sizeof(WCHAR) - 1] == 0, "no terminating null\n" );
430
431 str.MaximumLength = str.Length;
432 len = 0xdeadbeef;
433 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
434 ok( status == STATUS_BUFFER_TOO_SMALL, "NtQuerySymbolicLinkObject failed %08x\n", status );
435 ok( len == full_len, "bad length %u/%u\n", len, full_len );
436
437 str.MaximumLength = 0;
438 len = 0xdeadbeef;
439 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
440 ok( status == STATUS_BUFFER_TOO_SMALL, "NtQuerySymbolicLinkObject failed %08x\n", status );
441 ok( len == full_len, "bad length %u/%u\n", len, full_len );
442
443 str.MaximumLength = str.Length + sizeof(WCHAR);
444 len = 0xdeadbeef;
445 status = pNtQuerySymbolicLinkObject( dir, &str, &len );
446 ok( status == STATUS_SUCCESS, "NtQuerySymbolicLinkObject failed %08x\n", status );
447 ok( len == full_len, "bad length %u/%u\n", len, full_len );
448
449 error:
450 pNtClose(dir);
451 }
452
453 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
454 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
455 DIR_TEST_OPEN_SUCCESS(&dir)
456 pRtlFreeUnicodeString(&str);
457
458 InitializeObjectAttributes(&attr, NULL, 0, dir, NULL);
459 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_NAME_INVALID)
460
461 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
462 DIR_TEST_CREATE_OPEN_SUCCESS(h, "")
463 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\", STATUS_OBJECT_PATH_SYNTAX_BAD)
464 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD)
465 DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD)
466 DIR_TEST_CREATE_OPEN_FAILURE(&h, "om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND)
467
468 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
469 DIR_TEST_CREATE_SUCCESS(&dir1)
470 DIR_TEST_OPEN_SUCCESS(&h)
471 pRtlFreeUnicodeString(&str);
472
473 pNtClose(h);
474 pNtClose(dir1);
475 pNtClose(dir);
476
477 /* Nested directories */
478 pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
479 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
480 DIR_TEST_OPEN_SUCCESS(&dir)
481 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
482 DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
483 pRtlFreeUnicodeString(&str);
484 pNtClose(dir);
485
486 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
487 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test");
488 DIR_TEST_CREATE_SUCCESS(&dir)
489 pRtlFreeUnicodeString(&str);
490 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test\\one more level");
491 DIR_TEST_CREATE_SUCCESS(&h)
492 pRtlFreeUnicodeString(&str);
493 pNtClose(h);
494 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
495 pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
496 DIR_TEST_CREATE_SUCCESS(&h)
497 pRtlFreeUnicodeString(&str);
498 pNtClose(h);
499
500 pNtClose(dir);
501
502 if (!is_nt4)
503 {
504 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
505 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Global\\om.c-test");
506 DIR_TEST_CREATE_SUCCESS(&dir)
507 pRtlFreeUnicodeString(&str);
508 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
509 DIR_TEST_CREATE_SUCCESS(&h)
510 pRtlFreeUnicodeString(&str);
511 pNtClose(h);
512 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
513 pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
514 DIR_TEST_CREATE_SUCCESS(&dir)
515 pRtlFreeUnicodeString(&str);
516 pNtClose(h);
517 pNtClose(dir);
518 }
519
520 /* Create other objects using RootDirectory */
521
522 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
523 pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
524 DIR_TEST_OPEN_SUCCESS(&dir)
525 pRtlFreeUnicodeString(&str);
526 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
527
528 /* Test invalid paths */
529 pRtlCreateUnicodeStringFromAsciiz(&str, "\\om.c-mutant");
530 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
531 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
532 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
533 pRtlFreeUnicodeString(&str);
534 pRtlCreateUnicodeStringFromAsciiz(&str, "\\om.c-mutant\\");
535 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
536 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
537 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
538 pRtlFreeUnicodeString(&str);
539
540 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c\\-mutant");
541 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
542 ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
543 "NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
544 pRtlFreeUnicodeString(&str);
545
546 pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-mutant");
547 status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
548 ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status);
549 pRtlFreeUnicodeString(&str);
550 pNtClose(h);
551
552 pNtClose(dir);
553 }
554
555 #define SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e2) \
556 pRtlCreateUnicodeStringFromAsciiz(&str, n);\
557 pRtlCreateUnicodeStringFromAsciiz(&target, t);\
558 status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target);\
559 ok(status == e || status == e2, \
560 "NtCreateSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
561 status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr);\
562 ok(status == e || status == e2, \
563 "NtOpenSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
564 pRtlFreeUnicodeString(&target);\
565 pRtlFreeUnicodeString(&str);
566
567 #define SYMLNK_TEST_CREATE_OPEN_FAILURE(h,n,t,e) SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e)
568
569 static void test_symboliclink(void)
570 {
571 NTSTATUS status;
572 UNICODE_STRING str, target;
573 OBJECT_ATTRIBUTES attr;
574 HANDLE dir, link, h;
575 IO_STATUS_BLOCK iosb;
576
577 /* No name and/or no attributes */
578 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
579 SYMLNK_TEST_CREATE_OPEN_FAILURE2(NULL, "", "", STATUS_ACCESS_VIOLATION, STATUS_INVALID_PARAMETER)
580
581 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, NULL);
582 ok(status == STATUS_ACCESS_VIOLATION,
583 "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
584 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL);
585 ok(status == STATUS_INVALID_PARAMETER,
586 "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
587
588 /* No attributes */
589 pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
590 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, &target);
591 ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_VIOLATION, /* nt4 */
592 "NtCreateSymbolicLinkObject failed(%08x)\n", status);
593 pRtlFreeUnicodeString(&target);
594 if (!status) pNtClose(h);
595
596 InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
597 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
598 ok(status == STATUS_INVALID_PARAMETER ||
599 broken(status == STATUS_SUCCESS), /* nt4 */
600 "NtCreateSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
601 if (!status) pNtClose(h);
602 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
603 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
604 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
605
606 /* Bad name */
607 pRtlCreateUnicodeStringFromAsciiz(&target, "anywhere");
608 InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
609
610 pRtlCreateUnicodeStringFromAsciiz(&str, "");
611 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
612 ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
613 status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
614 ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
615 "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
616 pNtClose(link);
617 pRtlFreeUnicodeString(&str);
618
619 pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
620 status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr, &target);
621 todo_wine ok(status == STATUS_OBJECT_TYPE_MISMATCH,
622 "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
623 pRtlFreeUnicodeString(&str);
624 pRtlFreeUnicodeString(&target);
625
626 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD)
627 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
628 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
629 SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
630 SYMLNK_TEST_CREATE_OPEN_FAILURE2(&h, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere",
631 STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_PATH_NOT_FOUND)
632
633
634 /* Compound test */
635 if (!(dir = get_base_dir()))
636 {
637 win_skip( "couldn't find the BaseNamedObjects dir\n" );
638 return;
639 }
640
641 InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
642 pRtlCreateUnicodeStringFromAsciiz(&str, "test-link");
643 pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
644 status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
645 ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
646 pRtlFreeUnicodeString(&str);
647 pRtlFreeUnicodeString(&target);
648
649 pRtlCreateUnicodeStringFromAsciiz(&str, "test-link\\NUL");
650 status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
651 todo_wine ok(status == STATUS_SUCCESS, "Failed to open NUL device(%08x)\n", status);
652 pRtlFreeUnicodeString(&str);
653
654 pNtClose(h);
655 pNtClose(link);
656 pNtClose(dir);
657 }
658
659 static void test_query_object(void)
660 {
661 static const WCHAR name[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',
662 '\\','t','e','s','t','_','e','v','e','n','t'};
663 static const WCHAR type_event[] = {'E','v','e','n','t'};
664 static const WCHAR type_file[] = {'F','i','l','e'};
665 HANDLE handle;
666 char buffer[1024];
667 NTSTATUS status;
668 ULONG len, expected_len;
669 UNICODE_STRING *str;
670 char dir[MAX_PATH];
671
672 handle = CreateEventA( NULL, FALSE, FALSE, "test_event" );
673
674 len = 0;
675 status = pNtQueryObject( handle, ObjectNameInformation, buffer, 0, &len );
676 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
677 ok( len >= sizeof(UNICODE_STRING) + sizeof(name) + sizeof(WCHAR), "unexpected len %u\n", len );
678
679 len = 0;
680 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, 0, &len );
681 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
682 todo_wine ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + sizeof(type_event) + sizeof(WCHAR), "unexpected len %u\n", len );
683
684 len = 0;
685 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(UNICODE_STRING), &len );
686 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
687 ok( len >= sizeof(UNICODE_STRING) + sizeof(name) + sizeof(WCHAR), "unexpected len %u\n", len );
688
689 len = 0;
690 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, sizeof(OBJECT_TYPE_INFORMATION), &len );
691 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
692 todo_wine ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + sizeof(type_event) + sizeof(WCHAR), "unexpected len %u\n", len );
693
694 len = 0;
695 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
696 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
697 ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
698 str = (UNICODE_STRING *)buffer;
699 ok( sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR) == len, "unexpected len %u\n", len );
700 ok( str->Length >= sizeof(name), "unexpected len %u\n", str->Length );
701 /* there can be a \\Sessions prefix in the name */
702 ok( !memcmp( str->Buffer + (str->Length - sizeof(name)) / sizeof(WCHAR), name, sizeof(name) ),
703 "wrong name %s\n", wine_dbgstr_w(str->Buffer) );
704
705 len -= sizeof(WCHAR);
706 status = pNtQueryObject( handle, ObjectNameInformation, buffer, len, &len );
707 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
708 ok( len >= sizeof(UNICODE_STRING) + sizeof(name) + sizeof(WCHAR), "unexpected len %u\n", len );
709
710 len = 0;
711 memset( buffer, 0, sizeof(buffer) );
712 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, sizeof(buffer), &len );
713 todo_wine ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
714 todo_wine ok( len > sizeof(OBJECT_TYPE_INFORMATION), "unexpected len %u\n", len );
715 str = (UNICODE_STRING *)buffer;
716 todo_wine ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + str->Length + sizeof(WCHAR), "unexpected len %u\n", len );
717 todo_wine ok( str->Buffer && !memcmp( str->Buffer, type_event, sizeof(type_file) ),
718 "wrong/bad type name %s (%p)\n", wine_dbgstr_w(str->Buffer), str->Buffer );
719
720 len -= sizeof(WCHAR);
721 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, len, &len );
722 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
723 todo_wine ok( len >= sizeof(OBJECT_TYPE_INFORMATION) + sizeof(type_event) + sizeof(WCHAR), "unexpected len %u\n", len );
724
725 pNtClose( handle );
726
727 handle = CreateEventA( NULL, FALSE, FALSE, NULL );
728 len = 0;
729 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
730 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
731 ok( len == sizeof(UNICODE_STRING), "unexpected len %u\n", len );
732 str = (UNICODE_STRING *)buffer;
733 ok( str->Length == 0, "unexpected len %u\n", len );
734 ok( str->Buffer == NULL, "unexpected ptr %p\n", str->Buffer );
735 pNtClose( handle );
736
737 GetWindowsDirectoryA( dir, MAX_PATH );
738 handle = CreateFileA( dir, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
739 FILE_FLAG_BACKUP_SEMANTICS, 0 );
740 len = 0;
741 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
742 ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
743 ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
744 str = (UNICODE_STRING *)buffer;
745 expected_len = sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR);
746 ok( len == expected_len || broken(len == expected_len - sizeof(WCHAR)), /* NT4 */
747 "unexpected len %u\n", len );
748 trace( "got %s len %u\n", wine_dbgstr_w(str->Buffer), len );
749
750 len = 0;
751 status = pNtQueryObject( handle, ObjectNameInformation, buffer, 0, &len );
752 ok( status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INSUFFICIENT_RESOURCES),
753 "NtQueryObject failed %x\n", status );
754 ok( len == expected_len || broken(!len || len == sizeof(UNICODE_STRING)),
755 "unexpected len %u\n", len );
756
757 len = 0;
758 status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(UNICODE_STRING), &len );
759 ok( status == STATUS_BUFFER_OVERFLOW || broken(status == STATUS_INSUFFICIENT_RESOURCES
760 || status == STATUS_INFO_LENGTH_MISMATCH),
761 "NtQueryObject failed %x\n", status );
762 ok( len == expected_len || broken(!len),
763 "unexpected len %u\n", len );
764
765 len = 0;
766 memset( buffer, 0, sizeof(buffer) );
767 status = pNtQueryObject( handle, ObjectTypeInformation, buffer, sizeof(buffer), &len );
768 todo_wine ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
769 todo_wine ok( len > sizeof(OBJECT_TYPE_INFORMATION), "unexpected len %u\n", len );
770 str = (UNICODE_STRING *)buffer;
771 expected_len = sizeof(OBJECT_TYPE_INFORMATION) + str->Length + sizeof(WCHAR);
772 todo_wine ok( len >= expected_len, "unexpected len %u\n", len );
773 todo_wine ok( str->Buffer && !memcmp( str->Buffer, type_file, sizeof(type_file) ),
774 "wrong/bad type name %s (%p)\n", wine_dbgstr_w(str->Buffer), str->Buffer );
775
776 pNtClose( handle );
777 }
778
779 static void test_type_mismatch(void)
780 {
781 HANDLE h;
782 NTSTATUS res;
783 OBJECT_ATTRIBUTES attr;
784
785 attr.Length = sizeof(attr);
786 attr.RootDirectory = 0;
787 attr.ObjectName = NULL;
788 attr.Attributes = 0;
789 attr.SecurityDescriptor = NULL;
790 attr.SecurityQualityOfService = NULL;
791
792 res = pNtCreateEvent( &h, 0, &attr, 0, 0 );
793 ok(!res, "can't create event: %x\n", res);
794
795 res = pNtReleaseSemaphore( h, 30, NULL );
796 ok(res == STATUS_OBJECT_TYPE_MISMATCH, "expected 0xc0000024, got %x\n", res);
797
798 pNtClose( h );
799 }
800
801 START_TEST(om)
802 {
803 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
804 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
805
806 if (!hntdll)
807 {
808 skip("not running on NT, skipping test\n");
809 return;
810 }
811
812 pCreateWaitableTimerA = (void *)GetProcAddress(hkernel32, "CreateWaitableTimerA");
813
814 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
815 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
816 pNtCreateEvent = (void *)GetProcAddress(hntdll, "NtCreateEvent");
817 pNtCreateMutant = (void *)GetProcAddress(hntdll, "NtCreateMutant");
818 pNtOpenMutant = (void *)GetProcAddress(hntdll, "NtOpenMutant");
819 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
820 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
821 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
822 pNtCreateNamedPipeFile = (void *)GetProcAddress(hntdll, "NtCreateNamedPipeFile");
823 pNtOpenDirectoryObject = (void *)GetProcAddress(hntdll, "NtOpenDirectoryObject");
824 pNtCreateDirectoryObject= (void *)GetProcAddress(hntdll, "NtCreateDirectoryObject");
825 pNtOpenSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtOpenSymbolicLinkObject");
826 pNtCreateSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtCreateSymbolicLinkObject");
827 pNtQuerySymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtQuerySymbolicLinkObject");
828 pNtCreateSemaphore = (void *)GetProcAddress(hntdll, "NtCreateSemaphore");
829 pNtCreateTimer = (void *)GetProcAddress(hntdll, "NtCreateTimer");
830 pNtCreateSection = (void *)GetProcAddress(hntdll, "NtCreateSection");
831 pNtQueryObject = (void *)GetProcAddress(hntdll, "NtQueryObject");
832 pNtReleaseSemaphore = (void *)GetProcAddress(hntdll, "NtReleaseSemaphore");
833
834 test_case_sensitive();
835 test_namespace_pipe();
836 test_name_collisions();
837 test_directory();
838 test_symboliclink();
839 test_query_object();
840 test_type_mismatch();
841 }