Rob Shearman : server: Make create_semaphore use struct object_attributes and set the security descriptor of semaphore objects .

Alexandre Julliard julliard at winehq.org
Fri Oct 26 08:34:40 CDT 2007


Module: wine
Branch: master
Commit: b0e5fb4384163324fb81dda800557408745aa718
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b0e5fb4384163324fb81dda800557408745aa718

Author: Rob Shearman <rob at codeweavers.com>
Date:   Thu Oct 25 15:42:53 2007 +0100

server: Make create_semaphore use struct object_attributes and set the security descriptor of semaphore objects.

---

 dlls/ntdll/sync.c              |   16 +++++++++++++++-
 include/wine/server_protocol.h |    5 ++---
 server/protocol.def            |    3 +--
 server/semaphore.c             |   24 ++++++++++++++++++++----
 server/trace.c                 |    5 ++---
 5 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index b2b3069..10a31d1 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -144,23 +144,37 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
 {
     DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
     NTSTATUS ret;
+    struct object_attributes objattr;
+    struct security_descriptor *sd = NULL;
 
     if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
         return STATUS_INVALID_PARAMETER;
     if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
 
+    objattr.rootdir =  attr ? attr->RootDirectory : 0;
+    objattr.sd_len = 0;
+    if (attr)
+    {
+        ret = create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        if (ret != STATUS_SUCCESS) return ret;
+    }
+
     SERVER_START_REQ( create_semaphore )
     {
         req->access  = access;
         req->attributes = (attr) ? attr->Attributes : 0;
-        req->rootdir = attr ? attr->RootDirectory : 0;
         req->initial = InitialCount;
         req->max     = MaximumCount;
+        wine_server_add_data( req, &objattr, sizeof(objattr) );
+        if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
         if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
         ret = wine_server_call( req );
         *SemaphoreHandle = reply->handle;
     }
     SERVER_END_REQ;
+
+    free_struct_sd( sd );
+
     return ret;
 }
 
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 312d822..80ee6f6 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -960,10 +960,9 @@ struct create_semaphore_request
     struct request_header __header;
     unsigned int access;
     unsigned int attributes;
-    obj_handle_t rootdir;
     unsigned int initial;
     unsigned int max;
-    /* VARARG(name,unicode_str); */
+    /* VARARG(objattr,object_attributes); */
 };
 struct create_semaphore_reply
 {
@@ -4880,6 +4879,6 @@ union generic_reply
     struct set_completion_info_reply set_completion_info_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 318
+#define SERVER_PROTOCOL_VERSION 319
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/protocol.def b/server/protocol.def
index 41f71ca..b2ece5e 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -812,10 +812,9 @@ enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
 @REQ(create_semaphore)
     unsigned int access;        /* wanted access rights */
     unsigned int attributes;    /* object attributes */
-    obj_handle_t rootdir;       /* root directory */
     unsigned int initial;       /* initial count */
     unsigned int max;           /* maximum count */
-    VARARG(name,unicode_str);   /* object name */
+    VARARG(objattr,object_attributes); /* object attributes */
 @REPLY
     obj_handle_t handle;        /* handle to the semaphore */
 @END
diff --git a/server/semaphore.c b/server/semaphore.c
index af651e9..a8318cd 100644
--- a/server/semaphore.c
+++ b/server/semaphore.c
@@ -34,6 +34,7 @@
 #include "handle.h"
 #include "thread.h"
 #include "request.h"
+#include "security.h"
 
 struct semaphore
 {
@@ -69,7 +70,8 @@ static const struct object_ops semaphore_ops =
 
 
 static struct semaphore *create_semaphore( struct directory *root, const struct unicode_str *name,
-                                           unsigned int attr, unsigned int initial, unsigned int max )
+                                           unsigned int attr, unsigned int initial, unsigned int max,
+                                           const struct security_descriptor *sd )
 {
     struct semaphore *sem;
 
@@ -85,6 +87,10 @@ static struct semaphore *create_semaphore( struct directory *root, const struct
             /* initialize it if it didn't already exist */
             sem->count = initial;
             sem->max   = max;
+            if (sd) default_set_sd( &sem->obj, sd, OWNER_SECURITY_INFORMATION|
+                                                   GROUP_SECURITY_INFORMATION|
+                                                   DACL_SECURITY_INFORMATION|
+                                                   SACL_SECURITY_INFORMATION );
         }
     }
     return sem;
@@ -165,13 +171,23 @@ DECL_HANDLER(create_semaphore)
     struct semaphore *sem;
     struct unicode_str name;
     struct directory *root = NULL;
+    const struct object_attributes *objattr = get_req_data();
+    const struct security_descriptor *sd;
 
     reply->handle = 0;
-    get_req_unicode_str( &name );
-    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
+
+    if (!objattr_is_valid( objattr, get_req_data_size() ))
+        return;
+
+    sd = objattr->sd_len ? (const struct security_descriptor *)(objattr + 1) : NULL;
+
+    /* get unicode string */
+    name.len = ((get_req_data_size() - sizeof(*objattr) - objattr->sd_len) / sizeof(WCHAR)) * sizeof(WCHAR);
+    name.str = (const WCHAR *)get_req_data() + (sizeof(*objattr) + objattr->sd_len) / sizeof(WCHAR);
+    if (objattr->rootdir && !(root = get_directory_obj( current->process, objattr->rootdir, 0 )))
         return;
 
-    if ((sem = create_semaphore( root, &name, req->attributes, req->initial, req->max )))
+    if ((sem = create_semaphore( root, &name, req->attributes, req->initial, req->max, sd )))
     {
         reply->handle = alloc_handle( current->process, sem, req->access, req->attributes );
         release_object( sem );
diff --git a/server/trace.c b/server/trace.c
index 4abdb55..dd2ef1e 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -1230,11 +1230,10 @@ static void dump_create_semaphore_request( const struct create_semaphore_request
 {
     fprintf( stderr, " access=%08x,", req->access );
     fprintf( stderr, " attributes=%08x,", req->attributes );
-    fprintf( stderr, " rootdir=%p,", req->rootdir );
     fprintf( stderr, " initial=%08x,", req->initial );
     fprintf( stderr, " max=%08x,", req->max );
-    fprintf( stderr, " name=" );
-    dump_varargs_unicode_str( cur_size );
+    fprintf( stderr, " objattr=" );
+    dump_varargs_object_attributes( cur_size );
 }
 
 static void dump_create_semaphore_reply( const struct create_semaphore_reply *req )




More information about the wine-cvs mailing list