server: Fix returned error when creating an existing symlink.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55839
This commit is contained in:
Alexandre Julliard 2023-10-30 13:32:46 +01:00
parent 0f88c7c31f
commit afb16d3ee2
2 changed files with 28 additions and 7 deletions

View file

@ -1408,8 +1408,14 @@ static void test_symboliclink(void)
pNtClose(link); pNtClose(link);
RtlInitUnicodeString(&str, L"\\"); RtlInitUnicodeString(&str, L"\\");
attr.Attributes = OBJ_OPENIF;
status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr, &target); status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr, &target);
todo_wine ok(status == STATUS_OBJECT_TYPE_MISMATCH, ok(status == STATUS_OBJECT_TYPE_MISMATCH,
"NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08lx)\n", status);
attr.Attributes = 0;
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(%08lx)\n", status); "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08lx)\n", status);
RtlInitUnicodeString( &target, L"->Somewhere"); RtlInitUnicodeString( &target, L"->Somewhere");
@ -1480,6 +1486,16 @@ static void test_symboliclink(void)
ok(status == STATUS_SUCCESS, "Got unexpected status %#lx.\n", status); ok(status == STATUS_SUCCESS, "Got unexpected status %#lx.\n", status);
pNtClose(h); pNtClose(h);
attr.Attributes = OBJ_OPENIF;
status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
ok(status == STATUS_SUCCESS || broken( status == STATUS_OBJECT_NAME_EXISTS ), /* <= win10 1507 */
"Got unexpected status %#lx.\n", status);
pNtClose(h);
attr.Attributes = 0;
status = pNtCreateSymbolicLinkObject( &h, SYMBOLIC_LINK_QUERY, &attr, &target );
ok(status == STATUS_OBJECT_NAME_COLLISION, "Got unexpected status %#lx.\n", status);
pNtClose(h);
InitializeObjectAttributes(&attr, &str, 0, 0, NULL); InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\om.c-test\\" ); RtlInitUnicodeString( &str, L"\\BaseNamedObjects\\om.c-test\\" );
status = NtCreateFile(&h, GENERIC_READ | SYNCHRONIZE, &attr, &iosb, NULL, 0, status = NtCreateFile(&h, GENERIC_READ | SYNCHRONIZE, &attr, &iosb, NULL, 0,

View file

@ -155,13 +155,18 @@ struct object *create_symlink( struct object *root, const struct unicode_str *na
set_error( STATUS_INVALID_PARAMETER ); set_error( STATUS_INVALID_PARAMETER );
return NULL; return NULL;
} }
if (!(symlink = create_named_object( root, &symlink_ops, name, attr, sd ))) return NULL; if (!(symlink = create_named_object( root, &symlink_ops, name, attr | OBJ_OPENLINK, sd ))) return NULL;
if (get_error() != STATUS_OBJECT_NAME_EXISTS && !(symlink->target = memdup( target->str, target->len ))) if (get_error() != STATUS_OBJECT_NAME_EXISTS)
{
symlink->len = target->len;
if (!(symlink->target = memdup( target->str, target->len )))
{ {
release_object( symlink ); release_object( symlink );
return NULL; return NULL;
} }
symlink->len = target->len; }
else clear_error();
return &symlink->obj; return &symlink->obj;
} }