server: Add a function to open a named object inside any parent, not only directories.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2016-02-08 16:53:31 +09:00
parent 0458a7d0e3
commit 7a5b14d456
5 changed files with 25 additions and 20 deletions

View File

@ -278,7 +278,6 @@ static void test_handles(void)
SetLastError( 0xdeadbeef );
d2 = OpenDesktopA( "", 0, TRUE, DESKTOP_ALL_ACCESS );
ok( !d2, "open mepty desktop succeeded\n" );
todo_wine
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
SetLastError( 0xdeadbeef );
@ -289,7 +288,6 @@ static void test_handles(void)
SetLastError( 0xdeadbeef );
d2 = OpenDesktopA( "foo\\bar", 0, TRUE, DESKTOP_ALL_ACCESS );
ok( !d2, "open desktop succeeded\n" );
todo_wine
ok( GetLastError() == ERROR_BAD_PATHNAME, "wrong error %u\n", GetLastError() );
d2 = CreateDesktopA( "foobar", NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL );

View File

@ -261,21 +261,7 @@ void *create_named_object_dir( struct directory *root, const struct unicode_str
void *open_object_dir( struct directory *root, const struct unicode_str *name,
unsigned int attr, const struct object_ops *ops )
{
struct unicode_str name_left;
struct object *obj;
if ((obj = find_object_dir( root, name, attr, &name_left )))
{
if (name_left.len) /* not fully parsed */
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
else if (ops && obj->ops != ops)
set_error( STATUS_OBJECT_TYPE_MISMATCH );
else
return obj;
release_object( obj );
}
return NULL;
return open_named_object( &root->obj, ops, name, attr );
}
/* retrieve an object type, creating it if needed */

View File

@ -316,6 +316,27 @@ void *create_named_object( struct object *parent, const struct object_ops *ops,
return new_obj;
}
/* open a object by name under the specified parent */
void *open_named_object( struct object *parent, const struct object_ops *ops,
const struct unicode_str *name, unsigned int attributes )
{
struct unicode_str name_left;
struct object *obj;
if ((obj = lookup_named_object( parent, name, attributes, &name_left )))
{
if (name_left.len) /* not fully parsed */
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
else if (ops && obj->ops != ops)
set_error( STATUS_OBJECT_TYPE_MISMATCH );
else
return obj;
release_object( obj );
}
return NULL;
}
/* recursive helper for dump_object_name */
static void dump_name( struct object *obj )
{

View File

@ -138,6 +138,8 @@ extern void *create_object( struct object *parent, const struct object_ops *ops,
const struct unicode_str *name );
extern void *create_named_object( struct object *parent, const struct object_ops *ops,
const struct unicode_str *name, unsigned int attributes );
extern void *open_named_object( struct object *parent, const struct object_ops *ops,
const struct unicode_str *name, unsigned int attributes );
extern void unlink_named_object( struct object *obj );
extern void make_object_static( struct object *obj );
extern struct namespace *create_namespace( unsigned int hash_size );

View File

@ -534,13 +534,11 @@ DECL_HANDLER(open_desktop)
if (!winstation) return;
if ((obj = find_object( winstation->desktop_names, &name, req->attributes )))
if ((obj = open_named_object( &winstation->obj, &desktop_ops, &name, req->attributes )))
{
assert( obj->ops == &desktop_ops );
reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
release_object( obj );
}
else set_error( STATUS_OBJECT_NAME_NOT_FOUND );
release_object( winstation );
}