diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c index d503c0261c1..c0a4921f163 100644 --- a/dlls/ntdll/tests/om.c +++ b/dlls/ntdll/tests/om.c @@ -179,7 +179,7 @@ static void test_name_collisions(void) NTSTATUS status; UNICODE_STRING str; OBJECT_ATTRIBUTES attr; - HANDLE h, h1, h2; + HANDLE dir, h, h1, h2; DWORD winerr; LARGE_INTEGER size; @@ -204,12 +204,15 @@ static void test_name_collisions(void) pRtlFreeUnicodeString(&str); - pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects\\om.c-test"); - + pRtlCreateUnicodeStringFromAsciiz(&str, "\\BaseNamedObjects"); + DIR_TEST_OPEN_SUCCESS(&dir) + pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test"); + InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL); + h = CreateMutexA(NULL, FALSE, "om.c-test"); ok(h != 0, "CreateMutexA failed got ret=%p (%ld)\n", h, GetLastError()); status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE); - todo_wine ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, + ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status); h2 = CreateMutexA(NULL, FALSE, "om.c-test"); winerr = GetLastError(); @@ -222,7 +225,7 @@ static void test_name_collisions(void) h = CreateEventA(NULL, FALSE, FALSE, "om.c-test"); ok(h != 0, "CreateEventA failed got ret=%p (%ld)\n", h, GetLastError()); status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE); - todo_wine ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, + ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status); h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test"); winerr = GetLastError(); @@ -235,7 +238,7 @@ static void test_name_collisions(void) h = CreateSemaphoreA(NULL, 1, 2, "om.c-test"); ok(h != 0, "CreateSemaphoreA failed got ret=%p (%ld)\n", h, GetLastError()); status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2); - todo_wine ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, + ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status); h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test"); winerr = GetLastError(); @@ -248,7 +251,7 @@ static void test_name_collisions(void) h = CreateWaitableTimerA(NULL, TRUE, "om.c-test"); ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%ld)\n", h, GetLastError()); status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer); - todo_wine ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, + ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status); h2 = CreateWaitableTimerA(NULL, TRUE, "om.c-test"); winerr = GetLastError(); @@ -263,7 +266,7 @@ static void test_name_collisions(void) size.u.LowPart = 256; size.u.HighPart = 0; status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0); - todo_wine ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, + ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08lx)\n", status); h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test"); winerr = GetLastError(); @@ -274,6 +277,7 @@ static void test_name_collisions(void) pNtClose(h2); pRtlFreeUnicodeString(&str); + pNtClose(dir); } void test_directory(void) diff --git a/server/event.c b/server/event.c index 2778f0fd063..c00f7d070ae 100644 --- a/server/event.c +++ b/server/event.c @@ -66,7 +66,7 @@ struct event *create_event( const struct unicode_str *name, unsigned int attr, if ((event = create_named_object( sync_namespace, &event_ops, name, attr ))) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ event->manual_reset = manual_reset; diff --git a/server/mailslot.c b/server/mailslot.c index d421a9d2942..38e0172c313 100644 --- a/server/mailslot.c +++ b/server/mailslot.c @@ -230,7 +230,7 @@ static struct mailslot *create_mailslot( const struct unicode_str *name, unsigne return NULL; /* it already exists - there can only be one mailslot to read from */ - if (get_error() == STATUS_OBJECT_NAME_COLLISION) + if (get_error() == STATUS_OBJECT_NAME_EXISTS) { release_object( mailslot ); return NULL; diff --git a/server/mapping.c b/server/mapping.c index 314620b485e..2825ef682a3 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -280,7 +280,7 @@ static struct object *create_mapping( const struct unicode_str *name, unsigned i if (!(mapping = create_named_object( sync_namespace, &mapping_ops, name, attr ))) return NULL; - if (get_error() == STATUS_OBJECT_NAME_COLLISION) + if (get_error() == STATUS_OBJECT_NAME_EXISTS) return &mapping->obj; /* Nothing else to do */ mapping->header_size = 0; diff --git a/server/mutex.c b/server/mutex.c index 3d887fb51a9..09186ca15c3 100644 --- a/server/mutex.c +++ b/server/mutex.c @@ -68,7 +68,7 @@ static struct mutex *create_mutex( const struct unicode_str *name, unsigned int if ((mutex = create_named_object( sync_namespace, &mutex_ops, name, attr ))) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ mutex->count = 0; diff --git a/server/named_pipe.c b/server/named_pipe.c index ef9ee3b9dcb..3664f2b427c 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -444,10 +444,10 @@ static struct named_pipe *create_named_pipe( const struct unicode_str *name, uns { struct named_pipe *pipe; - pipe = create_named_object( sync_namespace, &named_pipe_ops, name, attr ); + pipe = create_named_object( sync_namespace, &named_pipe_ops, name, attr | OBJ_OPENIF ); if (pipe) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ pipe->instances = 0; @@ -552,7 +552,7 @@ DECL_HANDLER(create_named_pipe) get_req_unicode_str( &name ); if (!(pipe = create_named_pipe( &name, req->attributes ))) return; - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { pipe->insize = req->insize; pipe->outsize = req->outsize; diff --git a/server/object.c b/server/object.c index 0fb9bc6a6e0..8886dcdf406 100644 --- a/server/object.c +++ b/server/object.c @@ -166,12 +166,17 @@ void *create_named_object( struct namespace *namespace, const struct object_ops if ((obj = find_object( namespace, name, attributes ))) { - if (obj->ops != ops) + if (attributes & OBJ_OPENIF && obj->ops == ops) + set_error( STATUS_OBJECT_NAME_EXISTS ); + else { release_object( obj ); obj = NULL; + if (attributes & OBJ_OPENIF) + set_error( STATUS_OBJECT_TYPE_MISMATCH ); + else + set_error( STATUS_OBJECT_NAME_COLLISION ); } - set_error( STATUS_OBJECT_NAME_COLLISION ); return obj; } if (!(name_ptr = alloc_name( name ))) return NULL; diff --git a/server/semaphore.c b/server/semaphore.c index fa0e8b1f219..86c61858fee 100644 --- a/server/semaphore.c +++ b/server/semaphore.c @@ -71,7 +71,7 @@ static struct semaphore *create_semaphore( const struct unicode_str *name, unsig } if ((sem = create_named_object( sync_namespace, &semaphore_ops, name, attr ))) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ sem->count = initial; diff --git a/server/timer.c b/server/timer.c index f87ac2dcb45..9f7ff6b0e58 100644 --- a/server/timer.c +++ b/server/timer.c @@ -75,7 +75,7 @@ static struct timer *create_timer( const struct unicode_str *name, unsigned int if ((timer = create_named_object( sync_namespace, &timer_ops, name, attr ))) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ timer->manual = manual; diff --git a/server/trace.c b/server/trace.c index d3899978e48..36cf305d114 100644 --- a/server/trace.c +++ b/server/trace.c @@ -3763,6 +3763,7 @@ static const struct { "NO_SUCH_FILE", STATUS_NO_SUCH_FILE }, { "NO_TOKEN", STATUS_NO_TOKEN }, { "OBJECT_NAME_COLLISION", STATUS_OBJECT_NAME_COLLISION }, + { "OBJECT_NAME_EXISTS", STATUS_OBJECT_NAME_EXISTS }, { "OBJECT_NAME_INVALID", STATUS_OBJECT_NAME_INVALID }, { "OBJECT_NAME_NOT_FOUND", STATUS_OBJECT_NAME_NOT_FOUND }, { "OBJECT_PATH_INVALID", STATUS_OBJECT_PATH_INVALID }, diff --git a/server/winstation.c b/server/winstation.c index 642bf787c99..fd5e71b3a8c 100644 --- a/server/winstation.c +++ b/server/winstation.c @@ -96,7 +96,7 @@ static struct winstation *create_winstation( const struct unicode_str *name, uns if ((winstation = create_named_object( winstation_namespace, &winstation_ops, name, attr ))) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ winstation->flags = flags; @@ -186,7 +186,7 @@ static struct desktop *create_desktop( const struct unicode_str *name, unsigned if ((desktop = create_named_object( winstation_namespace, &desktop_ops, &full_str, attr ))) { - if (get_error() != STATUS_OBJECT_NAME_COLLISION) + if (get_error() != STATUS_OBJECT_NAME_EXISTS) { /* initialize it if it didn't already exist */ desktop->flags = flags;