From ed268bbf9183392e21e771f64bd91c19316f8361 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 29 Jan 2016 16:23:29 +0900 Subject: [PATCH] server: Use a common helper function to implement open object calls. Signed-off-by: Alexandre Julliard --- server/completion.c | 16 ++-------------- server/directory.c | 13 ++----------- server/event.c | 26 ++++---------------------- server/handle.c | 21 +++++++++++---------- server/handle.h | 5 +++-- server/mapping.c | 14 ++------------ server/mutex.c | 14 ++------------ server/process.c | 12 ++---------- server/semaphore.c | 14 ++------------ server/symlink.c | 14 ++------------ server/timer.c | 14 ++------------ server/winstation.c | 26 ++++++++++++-------------- 12 files changed, 46 insertions(+), 143 deletions(-) diff --git a/server/completion.c b/server/completion.c index e0654766afa..ac67dd387b5 100644 --- a/server/completion.c +++ b/server/completion.c @@ -196,23 +196,11 @@ DECL_HANDLER(create_completion) /* open a completion */ DECL_HANDLER(open_completion) { - struct completion *completion; struct unicode_str name; - struct directory *root = NULL; - - reply->handle = 0; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &completion_ops, &name, req->attributes ); } diff --git a/server/directory.c b/server/directory.c index 937ab895b5e..d932a0d8708 100644 --- a/server/directory.c +++ b/server/directory.c @@ -523,19 +523,10 @@ DECL_HANDLER(create_directory) DECL_HANDLER(open_directory) { struct unicode_str name; - struct directory *dir, *root = NULL; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &directory_ops, &name, req->attributes ); } /* get a directory entry by index */ diff --git a/server/event.c b/server/event.c index 5b2bfc94dfc..0f0899b913f 100644 --- a/server/event.c +++ b/server/event.c @@ -307,20 +307,10 @@ DECL_HANDLER(create_event) DECL_HANDLER(open_event) { struct unicode_str name; - struct directory *root = NULL; - struct event *event; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &event_ops, &name, req->attributes ); } /* do an event operation */ @@ -389,16 +379,8 @@ DECL_HANDLER(create_keyed_event) DECL_HANDLER(open_keyed_event) { struct unicode_str name; - struct directory *root = NULL; - struct keyed_event *event; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &keyed_event_ops, &name, req->attributes ); } diff --git a/server/handle.c b/server/handle.c index 10ed4c695fa..ce58894ffea 100644 --- a/server/handle.c +++ b/server/handle.c @@ -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 */ -obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name, - const struct object_ops *ops, unsigned int access, unsigned int attr ) +obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access, + const struct object_ops *ops, const struct unicode_str *name, + unsigned int attributes ) { obj_handle_t handle = 0; - struct object *obj = find_object( namespace, name, attr ); - if (obj) + struct directory *root = NULL; + 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) - set_error( STATUS_OBJECT_TYPE_MISMATCH ); - else - handle = alloc_handle( current->process, obj, access, attr ); + handle = alloc_handle( current->process, obj, access, attributes ); release_object( obj ); } - else - set_error( STATUS_OBJECT_NAME_NOT_FOUND ); + if (root) release_object( root ); return handle; } diff --git a/server/handle.h b/server/handle.h index 821c4ef38ec..f1deb79fb5f 100644 --- a/server/handle.h +++ b/server/handle.h @@ -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 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 ); -extern obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name, - const struct object_ops *ops, unsigned int access, unsigned int attr ); +extern obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access, + 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 enumerate_handles( struct process *process, const struct object_ops *ops, unsigned int *index ); diff --git a/server/mapping.c b/server/mapping.c index f66f326edea..cae46d03862 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -688,20 +688,10 @@ DECL_HANDLER(create_mapping) DECL_HANDLER(open_mapping) { struct unicode_str name; - struct directory *root = NULL; - struct mapping *mapping; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &mapping_ops, &name, req->attributes ); } /* get a mapping information */ diff --git a/server/mutex.c b/server/mutex.c index fe94674e65f..1adbf427efa 100644 --- a/server/mutex.c +++ b/server/mutex.c @@ -234,20 +234,10 @@ DECL_HANDLER(create_mutex) DECL_HANDLER(open_mutex) { struct unicode_str name; - struct directory *root = NULL; - struct mutex *mutex; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &mutex_ops, &name, req->attributes ); } /* release a mutex */ diff --git a/server/process.c b/server/process.c index ec5b0fcc99e..24faea5d120 100644 --- a/server/process.c +++ b/server/process.c @@ -1561,19 +1561,11 @@ DECL_HANDLER(create_job) /* open a job object */ DECL_HANDLER(open_job) { - struct job *job; struct unicode_str name; - struct directory *root = NULL; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &job_ops, &name, req->attributes ); } /* assign a job object to a process */ diff --git a/server/semaphore.c b/server/semaphore.c index 8c594a4aa7a..993d2e373ff 100644 --- a/server/semaphore.c +++ b/server/semaphore.c @@ -202,20 +202,10 @@ DECL_HANDLER(create_semaphore) DECL_HANDLER(open_semaphore) { struct unicode_str name; - struct directory *root = NULL; - struct semaphore *sem; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &semaphore_ops, &name, req->attributes ); } /* release a semaphore */ diff --git a/server/symlink.c b/server/symlink.c index 6710133e4dd..650c5105b02 100644 --- a/server/symlink.c +++ b/server/symlink.c @@ -190,20 +190,10 @@ DECL_HANDLER(create_symlink) DECL_HANDLER(open_symlink) { struct unicode_str name; - struct directory *root = NULL; - struct symlink *symlink; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &symlink_ops, &name, req->attributes | OBJ_OPENLINK ); } /* query a symbolic link object */ diff --git a/server/timer.c b/server/timer.c index 2f6f6070e12..c492bd6a070 100644 --- a/server/timer.c +++ b/server/timer.c @@ -252,20 +252,10 @@ DECL_HANDLER(create_timer) DECL_HANDLER(open_timer) { struct unicode_str name; - struct directory *root = NULL; - struct timer *timer; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) - return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &timer_ops, &name, req->attributes ); } /* set a waitable timer */ diff --git a/server/winstation.c b/server/winstation.c index ece65c337d2..ac4506685f2 100644 --- a/server/winstation.c +++ b/server/winstation.c @@ -419,19 +419,11 @@ DECL_HANDLER(create_winstation) /* open a handle to a window station */ DECL_HANDLER(open_winstation) { - struct winstation *winstation; struct unicode_str name; - struct directory *root = NULL; get_req_unicode_str( &name ); - if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return; - - 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 ); + reply->handle = open_object( current->process, req->rootdir, req->access, + &winstation_ops, &name, req->attributes ); } @@ -494,6 +486,7 @@ DECL_HANDLER(create_desktop) DECL_HANDLER(open_desktop) { struct winstation *winstation; + struct object *obj; struct unicode_str name; get_req_unicode_str( &name ); @@ -504,12 +497,17 @@ DECL_HANDLER(open_desktop) else 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, - req->access, req->attributes ); - release_object( winstation ); + 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 ); } /* open a handle to current input desktop */