Return correct error on name collision when creating new named

objects.
Check for correct error in affected places.
This commit is contained in:
Vitaliy Margolen 2005-11-21 16:27:03 +00:00 committed by Alexandre Julliard
parent 2d41fcd864
commit 893987b871
11 changed files with 31 additions and 21 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 },

View File

@ -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;