2005-09-30 12:33:54 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for object manager functions
|
|
|
|
*
|
|
|
|
* Copyright 2005 Robert Shearman
|
|
|
|
* Copyright 2005 Vitaliy Margolen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-09-30 12:33:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ntdll_test.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
2007-08-14 12:01:17 +02:00
|
|
|
static HANDLE (WINAPI *pCreateWaitableTimerA)(SECURITY_ATTRIBUTES*, BOOL, LPCSTR);
|
2005-11-21 16:18:10 +01:00
|
|
|
static NTSTATUS (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, LPCSTR);
|
|
|
|
static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
|
|
|
|
static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
|
2005-09-30 12:33:54 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtCreateEvent) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, BOOLEAN, BOOLEAN);
|
|
|
|
static NTSTATUS (WINAPI *pNtCreateMutant)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, BOOLEAN );
|
|
|
|
static NTSTATUS (WINAPI *pNtOpenMutant) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES );
|
2005-11-21 16:18:10 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtCreateSemaphore)( PHANDLE, ACCESS_MASK,const POBJECT_ATTRIBUTES,LONG,LONG );
|
|
|
|
static NTSTATUS (WINAPI *pNtCreateTimer) ( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, TIMER_TYPE );
|
|
|
|
static NTSTATUS (WINAPI *pNtCreateSection)( PHANDLE, ACCESS_MASK, const POBJECT_ATTRIBUTES, const PLARGE_INTEGER,
|
|
|
|
ULONG, ULONG, HANDLE );
|
2005-09-30 12:33:54 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtOpenFile) ( PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG );
|
|
|
|
static NTSTATUS (WINAPI *pNtClose) ( HANDLE );
|
|
|
|
static NTSTATUS (WINAPI *pNtCreateNamedPipeFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
|
|
|
|
ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, ULONG, PLARGE_INTEGER );
|
2005-11-21 16:18:10 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtOpenDirectoryObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
|
|
|
|
static NTSTATUS (WINAPI *pNtCreateDirectoryObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
|
|
|
|
static NTSTATUS (WINAPI *pNtOpenSymbolicLinkObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
|
|
|
|
static NTSTATUS (WINAPI *pNtCreateSymbolicLinkObject)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PUNICODE_STRING);
|
2010-06-30 16:11:55 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtQuerySymbolicLinkObject)(HANDLE,PUNICODE_STRING,PULONG);
|
2010-01-08 13:01:50 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtQueryObject)(HANDLE,OBJECT_INFORMATION_CLASS,PVOID,ULONG,PULONG);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
|
2007-03-12 16:50:54 +01:00
|
|
|
static void test_case_sensitive (void)
|
2005-09-30 12:33:54 +02:00
|
|
|
{
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
NTSTATUS status;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
HANDLE Event, Mutant, h;
|
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer1);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
|
2009-08-24 14:28:55 +02:00
|
|
|
ok(status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH,
|
|
|
|
"NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer2);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
status = pNtCreateEvent(&Event, GENERIC_ALL, &attr, FALSE, FALSE);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create Event(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer3);
|
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
|
|
|
|
status = pNtOpenMutant(&h, GENERIC_ALL, &attr);
|
2005-11-01 11:22:38 +01:00
|
|
|
ok(status == STATUS_OBJECT_TYPE_MISMATCH,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtOpenMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pNtClose(Mutant);
|
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer4);
|
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
|
|
|
|
status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
|
2009-08-24 14:28:55 +02:00
|
|
|
ok(status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_OBJECT_TYPE_MISMATCH,
|
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_NAME_COLLISION or STATUS_OBJECT_TYPE_MISMATCH got (%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
status = pNtCreateEvent(&h, GENERIC_ALL, &attr, FALSE, FALSE);
|
|
|
|
ok(status == STATUS_OBJECT_NAME_COLLISION,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateEvent should have failed with STATUS_OBJECT_NAME_COLLISION got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
attr.Attributes = 0;
|
|
|
|
status = pNtCreateMutant(&Mutant, GENERIC_ALL, &attr, FALSE);
|
2005-12-02 15:55:48 +01:00
|
|
|
ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pNtClose(Event);
|
|
|
|
}
|
|
|
|
|
2007-03-12 16:50:54 +01:00
|
|
|
static void test_namespace_pipe(void)
|
2005-09-30 12:33:54 +02:00
|
|
|
{
|
|
|
|
static const WCHAR buffer1[] = {'\\','?','?','\\','P','I','P','E','\\','t','e','s','t','\\','p','i','p','e',0};
|
|
|
|
static const WCHAR buffer2[] = {'\\','?','?','\\','P','I','P','E','\\','T','E','S','T','\\','P','I','P','E',0};
|
|
|
|
static const WCHAR buffer3[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t','\\','p','i','p','e',0};
|
|
|
|
static const WCHAR buffer4[] = {'\\','?','?','\\','p','i','p','e','\\','t','e','s','t',0};
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
HANDLE pipe, h;
|
|
|
|
|
|
|
|
timeout.QuadPart = -10000;
|
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer1);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create NamedPipe(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
|
2005-11-01 22:37:30 +01:00
|
|
|
ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer2);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
status = pNtCreateNamedPipeFile(&pipe, GENERIC_READ|GENERIC_WRITE, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|
|
|
FILE_CREATE, FILE_PIPE_FULL_DUPLEX, FALSE, FALSE, FALSE, 1, 256, 256, &timeout);
|
2005-12-05 13:09:35 +01:00
|
|
|
ok(status == STATUS_INSTANCE_NOT_AVAILABLE,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateNamedPipeFile should have failed with STATUS_INSTANCE_NOT_AVAILABLE got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
2008-11-11 21:22:35 +01:00
|
|
|
h = CreateFileA("\\\\.\\pipe\\test\\pipe", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, 0, 0 );
|
|
|
|
ok(h != INVALID_HANDLE_VALUE, "Failed to open NamedPipe (%u)\n", GetLastError());
|
2005-09-30 12:33:54 +02:00
|
|
|
pNtClose(h);
|
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer3);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
|
2008-11-11 11:39:31 +01:00
|
|
|
ok(status == STATUS_OBJECT_PATH_NOT_FOUND ||
|
|
|
|
status == STATUS_PIPE_NOT_AVAILABLE ||
|
|
|
|
status == STATUS_OBJECT_NAME_INVALID, /* vista */
|
2007-08-22 09:09:07 +02:00
|
|
|
"NtOpenFile should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pRtlInitUnicodeString(&str, buffer4);
|
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
|
|
|
|
status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
|
2008-11-11 11:39:31 +01:00
|
|
|
ok(status == STATUS_OBJECT_NAME_NOT_FOUND ||
|
|
|
|
status == STATUS_OBJECT_NAME_INVALID, /* vista */
|
2007-08-22 09:09:07 +02:00
|
|
|
"NtOpenFile should have failed with STATUS_OBJECT_NAME_NOT_FOUND got(%08x)\n", status);
|
2005-09-30 12:33:54 +02:00
|
|
|
|
|
|
|
pNtClose(pipe);
|
|
|
|
}
|
|
|
|
|
2005-11-21 16:18:10 +01:00
|
|
|
#define DIRECTORY_QUERY (0x0001)
|
|
|
|
#define SYMBOLIC_LINK_QUERY 0x0001
|
|
|
|
|
|
|
|
#define DIR_TEST_CREATE_FAILURE(h,e) \
|
|
|
|
status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr);\
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == e,"NtCreateDirectoryObject should have failed with %s got(%08x)\n", #e, status);
|
2005-11-21 16:18:10 +01:00
|
|
|
#define DIR_TEST_OPEN_FAILURE(h,e) \
|
|
|
|
status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr);\
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == e,"NtOpenDirectoryObject should have failed with %s got(%08x)\n", #e, status);
|
2005-11-21 16:18:10 +01:00
|
|
|
#define DIR_TEST_CREATE_OPEN_FAILURE(h,n,e) \
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, n);\
|
|
|
|
DIR_TEST_CREATE_FAILURE(h,e) DIR_TEST_OPEN_FAILURE(h,e)\
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
#define DIR_TEST_CREATE_SUCCESS(h) \
|
|
|
|
status = pNtCreateDirectoryObject(h, DIRECTORY_QUERY, &attr); \
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create Directory(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
#define DIR_TEST_OPEN_SUCCESS(h) \
|
|
|
|
status = pNtOpenDirectoryObject(h, DIRECTORY_QUERY, &attr); \
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to open Directory(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
#define DIR_TEST_CREATE_OPEN_SUCCESS(h,n) \
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, n);\
|
2007-04-03 14:42:34 +02:00
|
|
|
DIR_TEST_CREATE_SUCCESS(&h) pNtClose(h); DIR_TEST_OPEN_SUCCESS(&h) pNtClose(h); \
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
2008-11-11 21:22:35 +01:00
|
|
|
static BOOL is_correct_dir( HANDLE dir, const char *name )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
HANDLE h = 0;
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, name);
|
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
if (h) pNtClose( h );
|
|
|
|
return (status == STATUS_OBJECT_NAME_EXISTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return a handle to the BaseNamedObjects dir where kernel32 objects get created */
|
|
|
|
static HANDLE get_base_dir(void)
|
|
|
|
{
|
|
|
|
static const char objname[] = "om.c_get_base_dir_obj";
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
HANDLE dir, h;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
h = CreateMutexA(NULL, FALSE, objname);
|
|
|
|
ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
|
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local");
|
|
|
|
status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
if (!status && is_correct_dir( dir, objname )) goto done;
|
|
|
|
if (!status) pNtClose( dir );
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
|
|
|
|
status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
if (!status && is_correct_dir( dir, objname )) goto done;
|
|
|
|
if (!status) pNtClose( dir );
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
char name[40];
|
|
|
|
sprintf( name, "\\BaseNamedObjects\\Session\\%u", i );
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, name );
|
|
|
|
status = pNtOpenDirectoryObject(&dir, DIRECTORY_QUERY, &attr);
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
if (!status && is_correct_dir( dir, objname )) goto done;
|
|
|
|
if (!status) pNtClose( dir );
|
|
|
|
}
|
|
|
|
dir = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
pNtClose( h );
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2005-11-21 16:18:10 +01:00
|
|
|
static void test_name_collisions(void)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2005-11-21 17:27:03 +01:00
|
|
|
HANDLE dir, h, h1, h2;
|
2005-11-21 16:18:10 +01:00
|
|
|
DWORD winerr;
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_COLLISION)
|
2005-11-21 16:18:10 +01:00
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_EXISTS)
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
2005-12-02 15:55:48 +01:00
|
|
|
ok(status == STATUS_OBJECT_TYPE_MISMATCH,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\??\\PIPE\\om.c-mutant");
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
2005-12-02 15:55:48 +01:00
|
|
|
ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_OBJECT_PATH_NOT_FOUND,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
2008-11-11 21:22:35 +01:00
|
|
|
if (!(dir = get_base_dir()))
|
|
|
|
{
|
|
|
|
win_skip( "couldn't find the BaseNamedObjects dir\n" );
|
|
|
|
return;
|
|
|
|
}
|
2005-11-21 17:27:03 +01:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
|
|
|
|
InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
|
2005-11-21 16:18:10 +01:00
|
|
|
h = CreateMutexA(NULL, FALSE, "om.c-test");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE);
|
2005-11-21 17:27:03 +01:00
|
|
|
ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
h2 = CreateMutexA(NULL, FALSE, "om.c-test");
|
|
|
|
winerr = GetLastError();
|
|
|
|
ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
|
2006-10-13 23:33:02 +02:00
|
|
|
"CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(h1);
|
|
|
|
pNtClose(h2);
|
|
|
|
|
|
|
|
h = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(h != 0, "CreateEventA failed got ret=%p (%d)\n", h, GetLastError());
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE);
|
2005-11-21 17:27:03 +01:00
|
|
|
ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
|
|
|
|
winerr = GetLastError();
|
|
|
|
ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
|
2006-10-13 23:33:02 +02:00
|
|
|
"CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(h1);
|
|
|
|
pNtClose(h2);
|
|
|
|
|
|
|
|
h = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(h != 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h, GetLastError());
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2);
|
2005-11-21 17:27:03 +01:00
|
|
|
ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
|
|
|
|
winerr = GetLastError();
|
|
|
|
ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
|
2006-10-13 23:33:02 +02:00
|
|
|
"CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(h1);
|
|
|
|
pNtClose(h2);
|
|
|
|
|
2007-08-14 12:01:17 +02:00
|
|
|
h = pCreateWaitableTimerA(NULL, TRUE, "om.c-test");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h, GetLastError());
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer);
|
2005-11-21 17:27:03 +01:00
|
|
|
ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
|
2007-08-14 12:01:17 +02:00
|
|
|
h2 = pCreateWaitableTimerA(NULL, TRUE, "om.c-test");
|
2005-11-21 16:18:10 +01:00
|
|
|
winerr = GetLastError();
|
|
|
|
ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
|
2006-10-13 23:33:02 +02:00
|
|
|
"CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(h1);
|
|
|
|
pNtClose(h2);
|
|
|
|
|
|
|
|
h = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(h != 0, "CreateFileMappingA failed got ret=%p (%d)\n", h, GetLastError());
|
2005-11-21 16:18:10 +01:00
|
|
|
size.u.LowPart = 256;
|
|
|
|
size.u.HighPart = 0;
|
|
|
|
status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0);
|
2005-11-21 17:27:03 +01:00
|
|
|
ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
|
|
|
|
winerr = GetLastError();
|
|
|
|
ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
|
2006-10-13 23:33:02 +02:00
|
|
|
"CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(h1);
|
|
|
|
pNtClose(h2);
|
|
|
|
|
|
|
|
pRtlFreeUnicodeString(&str);
|
2005-11-21 17:27:03 +01:00
|
|
|
pNtClose(dir);
|
2005-11-21 16:18:10 +01:00
|
|
|
}
|
|
|
|
|
2007-03-12 16:50:54 +01:00
|
|
|
static void test_directory(void)
|
2005-11-21 16:18:10 +01:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
HANDLE dir, dir1, h;
|
2008-09-19 14:03:47 +02:00
|
|
|
BOOL is_nt4;
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
/* No name and/or no attributes */
|
|
|
|
status = pNtCreateDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
|
2008-11-11 11:39:31 +01:00
|
|
|
ok(status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtOpenDirectoryObject(NULL, DIRECTORY_QUERY, &attr);
|
2008-11-11 11:39:31 +01:00
|
|
|
ok(status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtOpenDirectoryObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
status = pNtCreateDirectoryObject(&h, DIRECTORY_QUERY, NULL);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create Directory without attributes(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(h);
|
|
|
|
status = pNtOpenDirectoryObject(&h, DIRECTORY_QUERY, NULL);
|
2005-11-29 17:21:05 +01:00
|
|
|
ok(status == STATUS_INVALID_PARAMETER,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtOpenDirectoryObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&dir)
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
/* Bad name */
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&h)
|
|
|
|
pNtClose(h);
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(dir);
|
|
|
|
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", STATUS_OBJECT_PATH_SYNTAX_BAD)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", STATUS_OBJECT_NAME_INVALID)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", STATUS_OBJECT_NAME_INVALID)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", STATUS_OBJECT_NAME_INVALID)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND)
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&h)
|
|
|
|
DIR_TEST_OPEN_SUCCESS(&dir1)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(dir1);
|
|
|
|
|
|
|
|
|
|
|
|
/* Use of root directory */
|
|
|
|
|
|
|
|
/* Can't use symlinks as a directory */
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local");
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
2007-01-09 00:39:49 +01:00
|
|
|
status = pNtOpenSymbolicLinkObject(&dir, SYMBOLIC_LINK_QUERY, &attr);
|
2008-09-19 14:03:47 +02:00
|
|
|
is_nt4 = (status == STATUS_OBJECT_NAME_NOT_FOUND); /* nt4 doesn't have Local\\ symlink */
|
|
|
|
if (!is_nt4)
|
|
|
|
{
|
2010-06-30 16:11:55 +02:00
|
|
|
WCHAR buffer[256];
|
|
|
|
ULONG len, full_len;
|
|
|
|
|
2008-09-19 14:03:47 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to open SymbolicLink(%08x)\n", status);
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
|
|
|
|
DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_TYPE_MISMATCH)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
2010-06-30 16:11:55 +02:00
|
|
|
|
|
|
|
str.Buffer = buffer;
|
|
|
|
str.MaximumLength = sizeof(buffer);
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
memset( buffer, 0xaa, sizeof(buffer) );
|
|
|
|
status = pNtQuerySymbolicLinkObject( dir, &str, &len );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtQuerySymbolicLinkObject failed %08x\n", status );
|
2010-07-09 13:09:53 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
goto error;
|
2010-06-30 16:11:55 +02:00
|
|
|
full_len = str.Length + sizeof(WCHAR);
|
|
|
|
ok( len == full_len, "bad length %u/%u\n", len, full_len );
|
2010-07-09 13:09:53 +02:00
|
|
|
if (len == full_len)
|
|
|
|
ok( buffer[len / sizeof(WCHAR) - 1] == 0, "no terminating null\n" );
|
2010-06-30 16:11:55 +02:00
|
|
|
|
|
|
|
str.MaximumLength = str.Length;
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
status = pNtQuerySymbolicLinkObject( dir, &str, &len );
|
|
|
|
ok( status == STATUS_BUFFER_TOO_SMALL, "NtQuerySymbolicLinkObject failed %08x\n", status );
|
|
|
|
ok( len == full_len, "bad length %u/%u\n", len, full_len );
|
|
|
|
|
|
|
|
str.MaximumLength = 0;
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
status = pNtQuerySymbolicLinkObject( dir, &str, &len );
|
|
|
|
ok( status == STATUS_BUFFER_TOO_SMALL, "NtQuerySymbolicLinkObject failed %08x\n", status );
|
|
|
|
ok( len == full_len, "bad length %u/%u\n", len, full_len );
|
|
|
|
|
|
|
|
str.MaximumLength = str.Length + sizeof(WCHAR);
|
|
|
|
len = 0xdeadbeef;
|
|
|
|
status = pNtQuerySymbolicLinkObject( dir, &str, &len );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtQuerySymbolicLinkObject failed %08x\n", status );
|
|
|
|
ok( len == full_len, "bad length %u/%u\n", len, full_len );
|
|
|
|
|
2010-07-09 13:09:53 +02:00
|
|
|
error:
|
2008-09-19 14:03:47 +02:00
|
|
|
pNtClose(dir);
|
|
|
|
}
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
DIR_TEST_OPEN_SUCCESS(&dir)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, NULL, 0, dir, NULL);
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_NAME_INVALID)
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
2007-04-03 14:42:34 +02:00
|
|
|
DIR_TEST_CREATE_OPEN_SUCCESS(h, "")
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\", STATUS_OBJECT_PATH_SYNTAX_BAD)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\om.c-test", STATUS_OBJECT_PATH_SYNTAX_BAD)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "\\om.c-test\\", STATUS_OBJECT_PATH_SYNTAX_BAD)
|
|
|
|
DIR_TEST_CREATE_OPEN_FAILURE(&h, "om.c-test\\", STATUS_OBJECT_PATH_NOT_FOUND)
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&dir1)
|
|
|
|
DIR_TEST_OPEN_SUCCESS(&h)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(dir1);
|
|
|
|
pNtClose(dir);
|
|
|
|
|
|
|
|
/* Nested directories */
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
DIR_TEST_OPEN_SUCCESS(&dir)
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
2005-11-29 17:21:05 +01:00
|
|
|
DIR_TEST_OPEN_FAILURE(&h, STATUS_OBJECT_PATH_SYNTAX_BAD)
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(dir);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&dir)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test\\one more level");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&h)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(h);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&h)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(h);
|
|
|
|
|
|
|
|
pNtClose(dir);
|
|
|
|
|
2008-09-19 14:03:47 +02:00
|
|
|
if (!is_nt4)
|
|
|
|
{
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Global\\om.c-test");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&dir)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\Local\\om.c-test\\one more level");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&h)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(h);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "one more level");
|
|
|
|
DIR_TEST_CREATE_SUCCESS(&dir)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(dir);
|
|
|
|
}
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
/* Create other objects using RootDirectory */
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects");
|
|
|
|
DIR_TEST_OPEN_SUCCESS(&dir)
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
|
|
|
|
2008-04-08 23:22:43 +02:00
|
|
|
/* Test invalid paths */
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\om.c-mutant");
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
2005-12-02 15:55:48 +01:00
|
|
|
ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\om.c-mutant\\");
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
2005-12-02 15:55:48 +01:00
|
|
|
ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "om.c\\-mutant");
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
2005-12-02 15:55:48 +01:00
|
|
|
ok(status == STATUS_OBJECT_PATH_NOT_FOUND,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateMutant should have failed with STATUS_OBJECT_PATH_NOT_FOUND got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-mutant");
|
|
|
|
status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create Mutant(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pNtClose(h);
|
|
|
|
|
|
|
|
pNtClose(dir);
|
|
|
|
}
|
|
|
|
|
2008-09-24 10:05:19 +02:00
|
|
|
#define SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e2) \
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, n);\
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&target, t);\
|
2008-09-22 12:14:37 +02:00
|
|
|
status = pNtCreateSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr, &target);\
|
2008-09-24 10:05:19 +02:00
|
|
|
ok(status == e || status == e2, \
|
|
|
|
"NtCreateSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
|
2008-09-22 12:14:37 +02:00
|
|
|
status = pNtOpenSymbolicLinkObject(h, SYMBOLIC_LINK_QUERY, &attr);\
|
2008-09-24 10:05:19 +02:00
|
|
|
ok(status == e || status == e2, \
|
|
|
|
"NtOpenSymbolicLinkObject should have failed with %s or %s got(%08x)\n", #e, #e2, status);\
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&target);\
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
2008-09-24 10:05:19 +02:00
|
|
|
#define SYMLNK_TEST_CREATE_OPEN_FAILURE(h,n,t,e) SYMLNK_TEST_CREATE_OPEN_FAILURE2(h,n,t,e,e)
|
|
|
|
|
2007-03-12 16:50:54 +01:00
|
|
|
static void test_symboliclink(void)
|
2005-11-21 16:18:10 +01:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str, target;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
HANDLE dir, link, h;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
|
|
|
|
/* No name and/or no attributes */
|
2009-02-17 12:46:44 +01:00
|
|
|
InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
|
2008-11-11 11:39:31 +01:00
|
|
|
SYMLNK_TEST_CREATE_OPEN_FAILURE2(NULL, "", "", STATUS_ACCESS_VIOLATION, STATUS_INVALID_PARAMETER)
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, NULL);
|
2005-11-30 19:22:57 +01:00
|
|
|
ok(status == STATUS_ACCESS_VIOLATION,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL);
|
2005-11-30 19:22:57 +01:00
|
|
|
ok(status == STATUS_INVALID_PARAMETER,
|
2006-10-13 23:33:02 +02:00
|
|
|
"NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
|
2007-01-21 21:14:35 +01:00
|
|
|
/* No attributes */
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
|
|
|
|
status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, &target);
|
2008-09-22 12:14:37 +02:00
|
|
|
ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_VIOLATION, /* nt4 */
|
|
|
|
"NtCreateSymbolicLinkObject failed(%08x)\n", status);
|
2007-01-21 21:14:35 +01:00
|
|
|
pRtlFreeUnicodeString(&target);
|
2008-09-22 12:14:37 +02:00
|
|
|
if (!status) pNtClose(h);
|
2007-01-21 21:14:35 +01:00
|
|
|
|
2005-11-21 16:18:10 +01:00
|
|
|
InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
|
2008-09-22 12:14:37 +02:00
|
|
|
status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
|
|
|
|
ok(status == STATUS_INVALID_PARAMETER ||
|
|
|
|
broken(status == STATUS_SUCCESS), /* nt4 */
|
|
|
|
"NtCreateSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
|
|
|
|
if (!status) pNtClose(h);
|
|
|
|
status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
|
|
|
|
ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
|
|
|
|
"NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
/* Bad name */
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&target, "anywhere");
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "");
|
2008-09-22 12:14:37 +02:00
|
|
|
status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
|
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
|
|
|
|
status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
|
|
|
|
ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
|
|
|
|
"NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pNtClose(link);
|
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
|
2008-09-22 12:14:37 +02:00
|
|
|
status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr, &target);
|
|
|
|
todo_wine ok(status == STATUS_OBJECT_TYPE_MISMATCH,
|
|
|
|
"NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pRtlFreeUnicodeString(&target);
|
|
|
|
|
2005-11-30 19:22:57 +01:00
|
|
|
SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD)
|
|
|
|
SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
|
|
|
|
SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
|
|
|
|
SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
|
2008-09-24 10:05:19 +02:00
|
|
|
SYMLNK_TEST_CREATE_OPEN_FAILURE2(&h, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere",
|
|
|
|
STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_PATH_NOT_FOUND)
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
|
2008-11-11 21:22:35 +01:00
|
|
|
/* Compound test */
|
|
|
|
if (!(dir = get_base_dir()))
|
2008-09-19 14:03:47 +02:00
|
|
|
{
|
2008-11-11 21:22:35 +01:00
|
|
|
win_skip( "couldn't find the BaseNamedObjects dir\n" );
|
|
|
|
return;
|
2008-09-19 14:03:47 +02:00
|
|
|
}
|
2005-11-21 16:18:10 +01:00
|
|
|
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
|
2008-09-19 14:03:47 +02:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "test-link");
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
|
2008-09-22 12:14:37 +02:00
|
|
|
status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
|
|
|
|
ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
pRtlFreeUnicodeString(&target);
|
|
|
|
|
2008-11-11 21:22:35 +01:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz(&str, "test-link\\NUL");
|
2005-11-21 16:18:10 +01:00
|
|
|
status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
|
2008-11-11 21:22:35 +01:00
|
|
|
todo_wine ok(status == STATUS_SUCCESS, "Failed to open NUL device(%08x)\n", status);
|
2005-11-21 16:18:10 +01:00
|
|
|
pRtlFreeUnicodeString(&str);
|
|
|
|
|
|
|
|
pNtClose(h);
|
|
|
|
pNtClose(link);
|
|
|
|
pNtClose(dir);
|
|
|
|
}
|
|
|
|
|
2010-01-08 13:01:50 +01:00
|
|
|
static void test_query_object(void)
|
|
|
|
{
|
|
|
|
static const WCHAR name[] = {'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',
|
|
|
|
'\\','t','e','s','t','_','e','v','e','n','t'};
|
|
|
|
HANDLE handle;
|
|
|
|
char buffer[1024];
|
|
|
|
NTSTATUS status;
|
2010-09-15 12:00:03 +02:00
|
|
|
ULONG len, expected_len;
|
2010-01-08 13:01:50 +01:00
|
|
|
UNICODE_STRING *str;
|
2010-01-08 13:16:57 +01:00
|
|
|
char dir[MAX_PATH];
|
2010-01-08 13:01:50 +01:00
|
|
|
|
|
|
|
handle = CreateEventA( NULL, FALSE, FALSE, "test_event" );
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, 0, &len );
|
|
|
|
ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
|
|
|
|
ok( len >= sizeof(UNICODE_STRING) + sizeof(name) + sizeof(WCHAR), "unexpected len %u\n", len );
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(UNICODE_STRING), &len );
|
|
|
|
ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
|
|
|
|
ok( len >= sizeof(UNICODE_STRING) + sizeof(name) + sizeof(WCHAR), "unexpected len %u\n", len );
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
|
|
|
|
ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
|
|
|
|
str = (UNICODE_STRING *)buffer;
|
|
|
|
ok( sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR) == len, "unexpected len %u\n", len );
|
|
|
|
ok( str->Length >= sizeof(name), "unexpected len %u\n", str->Length );
|
|
|
|
/* there can be a \\Sessions prefix in the name */
|
|
|
|
ok( !memcmp( str->Buffer + (str->Length - sizeof(name)) / sizeof(WCHAR), name, sizeof(name) ),
|
|
|
|
"wrong name %s\n", wine_dbgstr_w(str->Buffer) );
|
|
|
|
|
|
|
|
len -= sizeof(WCHAR);
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, len, &len );
|
|
|
|
ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQueryObject failed %x\n", status );
|
|
|
|
ok( len >= sizeof(UNICODE_STRING) + sizeof(name) + sizeof(WCHAR), "unexpected len %u\n", len );
|
|
|
|
|
|
|
|
pNtClose( handle );
|
|
|
|
|
|
|
|
handle = CreateEventA( NULL, FALSE, FALSE, NULL );
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
|
|
|
|
ok( len == sizeof(UNICODE_STRING), "unexpected len %u\n", len );
|
|
|
|
str = (UNICODE_STRING *)buffer;
|
|
|
|
ok( str->Length == 0, "unexpected len %u\n", len );
|
|
|
|
ok( str->Buffer == NULL, "unexpected ptr %p\n", str->Buffer );
|
|
|
|
pNtClose( handle );
|
2010-01-08 13:16:57 +01:00
|
|
|
|
|
|
|
GetWindowsDirectoryA( dir, MAX_PATH );
|
|
|
|
handle = CreateFileA( dir, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
|
|
|
FILE_FLAG_BACKUP_SEMANTICS, 0 );
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(buffer), &len );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtQueryObject failed %x\n", status );
|
|
|
|
ok( len > sizeof(UNICODE_STRING), "unexpected len %u\n", len );
|
|
|
|
str = (UNICODE_STRING *)buffer;
|
2010-09-15 12:00:03 +02:00
|
|
|
expected_len = sizeof(UNICODE_STRING) + str->Length + sizeof(WCHAR);
|
|
|
|
ok( len == expected_len || broken(len == expected_len - sizeof(WCHAR)), /* NT4 */
|
2010-01-08 22:29:20 +01:00
|
|
|
"unexpected len %u\n", len );
|
2010-01-08 13:16:57 +01:00
|
|
|
trace( "got %s len %u\n", wine_dbgstr_w(str->Buffer), len );
|
2010-09-15 12:00:03 +02:00
|
|
|
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, 0, &len );
|
|
|
|
ok( status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INSUFFICIENT_RESOURCES),
|
|
|
|
"NtQueryObject failed %x\n", status );
|
|
|
|
ok( len == expected_len || broken(!len || len == sizeof(UNICODE_STRING)),
|
|
|
|
"unexpected len %u\n", len );
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
status = pNtQueryObject( handle, ObjectNameInformation, buffer, sizeof(UNICODE_STRING), &len );
|
|
|
|
ok( status == STATUS_BUFFER_OVERFLOW || broken(status == STATUS_INSUFFICIENT_RESOURCES
|
|
|
|
|| status == STATUS_INFO_LENGTH_MISMATCH),
|
|
|
|
"NtQueryObject failed %x\n", status );
|
|
|
|
ok( len == expected_len || broken(!len),
|
|
|
|
"unexpected len %u\n", len );
|
|
|
|
|
2010-01-08 13:16:57 +01:00
|
|
|
pNtClose( handle );
|
2010-01-08 13:01:50 +01:00
|
|
|
}
|
|
|
|
|
2005-09-30 12:33:54 +02:00
|
|
|
START_TEST(om)
|
|
|
|
{
|
|
|
|
HMODULE hntdll = GetModuleHandleA("ntdll.dll");
|
2007-08-14 12:01:17 +02:00
|
|
|
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
|
|
|
|
|
2007-03-28 10:00:28 +02:00
|
|
|
if (!hntdll)
|
2005-09-30 12:33:54 +02:00
|
|
|
{
|
2007-03-28 10:00:28 +02:00
|
|
|
skip("not running on NT, skipping test\n");
|
|
|
|
return;
|
2005-09-30 12:33:54 +02:00
|
|
|
}
|
2007-03-28 10:00:28 +02:00
|
|
|
|
2007-08-14 12:01:17 +02:00
|
|
|
pCreateWaitableTimerA = (void *)GetProcAddress(hkernel32, "CreateWaitableTimerA");
|
|
|
|
|
2007-03-28 10:00:28 +02:00
|
|
|
pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
|
|
|
|
pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
|
|
|
|
pNtCreateEvent = (void *)GetProcAddress(hntdll, "NtCreateEvent");
|
|
|
|
pNtCreateMutant = (void *)GetProcAddress(hntdll, "NtCreateMutant");
|
|
|
|
pNtOpenMutant = (void *)GetProcAddress(hntdll, "NtOpenMutant");
|
|
|
|
pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
|
|
|
|
pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
|
|
|
|
pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
|
|
|
|
pNtCreateNamedPipeFile = (void *)GetProcAddress(hntdll, "NtCreateNamedPipeFile");
|
|
|
|
pNtOpenDirectoryObject = (void *)GetProcAddress(hntdll, "NtOpenDirectoryObject");
|
|
|
|
pNtCreateDirectoryObject= (void *)GetProcAddress(hntdll, "NtCreateDirectoryObject");
|
|
|
|
pNtOpenSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtOpenSymbolicLinkObject");
|
|
|
|
pNtCreateSymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtCreateSymbolicLinkObject");
|
2010-06-30 16:11:55 +02:00
|
|
|
pNtQuerySymbolicLinkObject = (void *)GetProcAddress(hntdll, "NtQuerySymbolicLinkObject");
|
2007-03-28 10:00:28 +02:00
|
|
|
pNtCreateSemaphore = (void *)GetProcAddress(hntdll, "NtCreateSemaphore");
|
|
|
|
pNtCreateTimer = (void *)GetProcAddress(hntdll, "NtCreateTimer");
|
|
|
|
pNtCreateSection = (void *)GetProcAddress(hntdll, "NtCreateSection");
|
2010-01-08 13:01:50 +01:00
|
|
|
pNtQueryObject = (void *)GetProcAddress(hntdll, "NtQueryObject");
|
2007-03-28 10:00:28 +02:00
|
|
|
|
|
|
|
test_case_sensitive();
|
|
|
|
test_namespace_pipe();
|
|
|
|
test_name_collisions();
|
|
|
|
test_directory();
|
|
|
|
test_symboliclink();
|
2010-01-08 13:01:50 +01:00
|
|
|
test_query_object();
|
2005-09-30 12:33:54 +02:00
|
|
|
}
|