server: Use a common helper function to implement open object calls.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Alexandre Julliard 2016-01-29 16:23:29 +09:00
parent 38f9a788c4
commit ed268bbf91
12 changed files with 46 additions and 143 deletions

View File

@ -196,23 +196,11 @@ DECL_HANDLER(create_completion)
/* open a completion */ /* open a completion */
DECL_HANDLER(open_completion) DECL_HANDLER(open_completion)
{ {
struct completion *completion;
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
reply->handle = 0;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &completion_ops, &name, req->attributes );
if ( (completion = open_object_dir( root, &name, req->attributes, &completion_ops )) != NULL )
{
reply->handle = alloc_handle( current->process, completion, req->access, req->attributes );
release_object( completion );
}
if (root) release_object( root );
} }

View File

@ -523,19 +523,10 @@ DECL_HANDLER(create_directory)
DECL_HANDLER(open_directory) DECL_HANDLER(open_directory)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *dir, *root = NULL;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &directory_ops, &name, req->attributes );
if ((dir = open_object_dir( root, &name, req->attributes, &directory_ops )))
{
reply->handle = alloc_handle( current->process, &dir->obj, req->access, req->attributes );
release_object( dir );
}
if (root) release_object( root );
} }
/* get a directory entry by index */ /* get a directory entry by index */

View File

@ -307,20 +307,10 @@ DECL_HANDLER(create_event)
DECL_HANDLER(open_event) DECL_HANDLER(open_event)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct event *event;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &event_ops, &name, req->attributes );
if ((event = open_object_dir( root, &name, req->attributes, &event_ops )))
{
reply->handle = alloc_handle( current->process, &event->obj, req->access, req->attributes );
release_object( event );
}
if (root) release_object( root );
} }
/* do an event operation */ /* do an event operation */
@ -389,16 +379,8 @@ DECL_HANDLER(create_keyed_event)
DECL_HANDLER(open_keyed_event) DECL_HANDLER(open_keyed_event)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct keyed_event *event;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return; reply->handle = open_object( current->process, req->rootdir, req->access,
&keyed_event_ops, &name, req->attributes );
if ((event = open_object_dir( root, &name, req->attributes, &keyed_event_ops )))
{
reply->handle = alloc_handle( current->process, &event->obj, req->access, req->attributes );
release_object( event );
}
if (root) release_object( root );
} }

View File

@ -571,21 +571,22 @@ obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, str
} }
/* open a new handle to an existing object */ /* open a new handle to an existing object */
obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name, obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access,
const struct object_ops *ops, unsigned int access, unsigned int attr ) const struct object_ops *ops, const struct unicode_str *name,
unsigned int attributes )
{ {
obj_handle_t handle = 0; obj_handle_t handle = 0;
struct object *obj = find_object( namespace, name, attr ); struct directory *root = NULL;
if (obj) struct object *obj;
if (parent && !(root = get_directory_obj( current->process, parent, 0 ))) return 0;
if ((obj = open_object_dir( root, name, attributes, ops )))
{ {
if (ops && obj->ops != ops) handle = alloc_handle( current->process, obj, access, attributes );
set_error( STATUS_OBJECT_TYPE_MISMATCH );
else
handle = alloc_handle( current->process, obj, access, attr );
release_object( obj ); release_object( obj );
} }
else if (root) release_object( root );
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
return handle; return handle;
} }

View File

@ -44,8 +44,9 @@ extern struct object *get_handle_obj( struct process *process, obj_handle_t hand
extern unsigned int get_handle_access( struct process *process, obj_handle_t handle ); extern unsigned int get_handle_access( struct process *process, obj_handle_t handle );
extern obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, struct process *dst, extern obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, struct process *dst,
unsigned int access, unsigned int attr, unsigned int options ); unsigned int access, unsigned int attr, unsigned int options );
extern obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name, extern obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access,
const struct object_ops *ops, unsigned int access, unsigned int attr ); const struct object_ops *ops, const struct unicode_str *name,
unsigned int attr );
extern obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops ); extern obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops );
extern obj_handle_t enumerate_handles( struct process *process, const struct object_ops *ops, extern obj_handle_t enumerate_handles( struct process *process, const struct object_ops *ops,
unsigned int *index ); unsigned int *index );

View File

@ -688,20 +688,10 @@ DECL_HANDLER(create_mapping)
DECL_HANDLER(open_mapping) DECL_HANDLER(open_mapping)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct mapping *mapping;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &mapping_ops, &name, req->attributes );
if ((mapping = open_object_dir( root, &name, req->attributes, &mapping_ops )))
{
reply->handle = alloc_handle( current->process, &mapping->obj, req->access, req->attributes );
release_object( mapping );
}
if (root) release_object( root );
} }
/* get a mapping information */ /* get a mapping information */

View File

@ -234,20 +234,10 @@ DECL_HANDLER(create_mutex)
DECL_HANDLER(open_mutex) DECL_HANDLER(open_mutex)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct mutex *mutex;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &mutex_ops, &name, req->attributes );
if ((mutex = open_object_dir( root, &name, req->attributes, &mutex_ops )))
{
reply->handle = alloc_handle( current->process, &mutex->obj, req->access, req->attributes );
release_object( mutex );
}
if (root) release_object( root );
} }
/* release a mutex */ /* release a mutex */

View File

@ -1561,19 +1561,11 @@ DECL_HANDLER(create_job)
/* open a job object */ /* open a job object */
DECL_HANDLER(open_job) DECL_HANDLER(open_job)
{ {
struct job *job;
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return; reply->handle = open_object( current->process, req->rootdir, req->access,
&job_ops, &name, req->attributes );
if ((job = open_object_dir( root, &name, req->attributes, &job_ops )))
{
reply->handle = alloc_handle( current->process, &job->obj, req->access, req->attributes );
release_object( job );
}
if (root) release_object( root );
} }
/* assign a job object to a process */ /* assign a job object to a process */

View File

@ -202,20 +202,10 @@ DECL_HANDLER(create_semaphore)
DECL_HANDLER(open_semaphore) DECL_HANDLER(open_semaphore)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct semaphore *sem;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &semaphore_ops, &name, req->attributes );
if ((sem = open_object_dir( root, &name, req->attributes, &semaphore_ops )))
{
reply->handle = alloc_handle( current->process, &sem->obj, req->access, req->attributes );
release_object( sem );
}
if (root) release_object( root );
} }
/* release a semaphore */ /* release a semaphore */

View File

@ -190,20 +190,10 @@ DECL_HANDLER(create_symlink)
DECL_HANDLER(open_symlink) DECL_HANDLER(open_symlink)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct symlink *symlink;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &symlink_ops, &name, req->attributes | OBJ_OPENLINK );
if ((symlink = open_object_dir( root, &name, req->attributes | OBJ_OPENLINK, &symlink_ops )))
{
reply->handle = alloc_handle( current->process, &symlink->obj, req->access, req->attributes );
release_object( symlink );
}
if (root) release_object( root );
} }
/* query a symbolic link object */ /* query a symbolic link object */

View File

@ -252,20 +252,10 @@ DECL_HANDLER(create_timer)
DECL_HANDLER(open_timer) DECL_HANDLER(open_timer)
{ {
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
struct timer *timer;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) reply->handle = open_object( current->process, req->rootdir, req->access,
return; &timer_ops, &name, req->attributes );
if ((timer = open_object_dir( root, &name, req->attributes, &timer_ops )))
{
reply->handle = alloc_handle( current->process, &timer->obj, req->access, req->attributes );
release_object( timer );
}
if (root) release_object( root );
} }
/* set a waitable timer */ /* set a waitable timer */

View File

@ -419,19 +419,11 @@ DECL_HANDLER(create_winstation)
/* open a handle to a window station */ /* open a handle to a window station */
DECL_HANDLER(open_winstation) DECL_HANDLER(open_winstation)
{ {
struct winstation *winstation;
struct unicode_str name; struct unicode_str name;
struct directory *root = NULL;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return; reply->handle = open_object( current->process, req->rootdir, req->access,
&winstation_ops, &name, req->attributes );
if ((winstation = open_object_dir( root, &name, req->attributes, &winstation_ops )))
{
reply->handle = alloc_handle( current->process, &winstation->obj, req->access, req->attributes );
release_object( winstation );
}
if (root) release_object( root );
} }
@ -494,6 +486,7 @@ DECL_HANDLER(create_desktop)
DECL_HANDLER(open_desktop) DECL_HANDLER(open_desktop)
{ {
struct winstation *winstation; struct winstation *winstation;
struct object *obj;
struct unicode_str name; struct unicode_str name;
get_req_unicode_str( &name ); get_req_unicode_str( &name );
@ -504,12 +497,17 @@ DECL_HANDLER(open_desktop)
else else
winstation = (struct winstation *)get_handle_obj( current->process, req->winsta, 0, &winstation_ops ); winstation = (struct winstation *)get_handle_obj( current->process, req->winsta, 0, &winstation_ops );
if (winstation) if (!winstation) return;
if ((obj = find_object( winstation->desktop_names, &name, req->attributes )))
{ {
reply->handle = open_object( winstation->desktop_names, &name, &desktop_ops, assert( obj->ops == &desktop_ops );
req->access, req->attributes ); reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
release_object( winstation ); release_object( obj );
} }
else set_error( STATUS_OBJECT_NAME_NOT_FOUND );
release_object( winstation );
} }
/* open a handle to current input desktop */ /* open a handle to current input desktop */