From 0458a7d0e3f4fb293a1e5160a6868fda1d065330 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 8 Feb 2016 14:10:18 +0900 Subject: [PATCH] server: Use the lookup_name operation when creating a named object. Signed-off-by: Alexandre Julliard --- server/directory.c | 31 +------------------------------ server/object.c | 24 ++++++++++++++---------- server/object.h | 2 +- server/winstation.c | 2 +- 4 files changed, 17 insertions(+), 42 deletions(-) diff --git a/server/directory.c b/server/directory.c index cba3a353140..9b85ac7e12d 100644 --- a/server/directory.c +++ b/server/directory.c @@ -254,36 +254,7 @@ struct object *find_object_dir( struct directory *root, const struct unicode_str void *create_named_object_dir( struct directory *root, const struct unicode_str *name, unsigned int attributes, const struct object_ops *ops ) { - struct object *obj, *new_obj = NULL; - struct unicode_str new_name; - - if (!name || !name->len) - { - if ((new_obj = alloc_object( ops ))) clear_error(); - return new_obj; - } - - if (!(obj = find_object_dir( root, name, attributes, &new_name ))) return NULL; - if (!new_name.len) - { - 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 ); - } - return obj; - } - - if ((new_obj = create_object( obj, ops, &new_name ))) clear_error(); - - release_object( obj ); - return new_obj; + return create_named_object( &root->obj, ops, name, attributes ); } /* open a new handle to an existing object */ diff --git a/server/object.c b/server/object.c index 297a5b32104..c8e799b472b 100644 --- a/server/object.c +++ b/server/object.c @@ -282,18 +282,20 @@ void *create_object( struct object *parent, const struct object_ops *ops, const return obj; } -void *create_named_object( struct object *parent, struct namespace *namespace, const struct object_ops *ops, +/* create an object as named child under the specified parent */ +void *create_named_object( struct object *parent, const struct object_ops *ops, const struct unicode_str *name, unsigned int attributes ) { - struct object *obj; + struct object *obj, *new_obj; + struct unicode_str new_name; - if (!name || !name->len) - { - if ((obj = alloc_object( ops ))) clear_error(); - return obj; - } + clear_error(); - if ((obj = find_object( namespace, name, attributes ))) + if (!name || !name->len) return alloc_object( ops ); + + if (!(obj = lookup_named_object( parent, name, attributes, &new_name ))) return NULL; + + if (!new_name.len) { if (attributes & OBJ_OPENIF && obj->ops == ops) set_error( STATUS_OBJECT_NAME_EXISTS ); @@ -308,8 +310,10 @@ void *create_named_object( struct object *parent, struct namespace *namespace, c } return obj; } - if ((obj = create_object( parent, ops, name ))) clear_error(); - return obj; + + new_obj = create_object( obj, ops, &new_name ); + release_object( obj ); + return new_obj; } /* recursive helper for dump_object_name */ diff --git a/server/object.h b/server/object.h index 90112d707d2..287015e7c60 100644 --- a/server/object.h +++ b/server/object.h @@ -136,7 +136,7 @@ extern struct object *lookup_named_object( struct object *root, const struct uni unsigned int attr, struct unicode_str *name_left ); 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, struct namespace *namespace, const struct object_ops *ops, +extern void *create_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 ); diff --git a/server/winstation.c b/server/winstation.c index dbfece01da5..4131a8291c3 100644 --- a/server/winstation.c +++ b/server/winstation.c @@ -217,7 +217,7 @@ static struct desktop *create_desktop( const struct unicode_str *name, unsigned { struct desktop *desktop; - if ((desktop = create_named_object( &winstation->obj, winstation->desktop_names, &desktop_ops, name, attr ))) + if ((desktop = create_named_object( &winstation->obj, &desktop_ops, name, attr ))) { if (get_error() != STATUS_OBJECT_NAME_EXISTS) {