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

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


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

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

server: Make create_mutex use struct object_attributes and set the security descriptor of mutex objects.

---

 dlls/ntdll/sync.c              |   20 +++++++++++++++++---
 include/wine/server_protocol.h |    5 ++---
 server/mutex.c                 |   24 ++++++++++++++++++++----
 server/protocol.def            |    3 +--
 server/trace.c                 |    5 ++---
 5 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index 10a31d1..6fbcca8 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -415,22 +415,36 @@ NTSTATUS WINAPI NtCreateMutant(OUT HANDLE* MutantHandle,
                                IN const OBJECT_ATTRIBUTES* attr OPTIONAL,
                                IN BOOLEAN InitialOwner)
 {
-    NTSTATUS    status;
-    DWORD       len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
+    NTSTATUS status;
+    DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
+    struct security_descriptor *sd = NULL;
+    struct object_attributes objattr;
 
     if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
 
+    objattr.rootdir = attr ? attr->RootDirectory : 0;
+    objattr.sd_len = 0;
+    if (attr)
+    {
+        status = create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
+        if (status != STATUS_SUCCESS) return status;
+    }
+
     SERVER_START_REQ( create_mutex )
     {
         req->access  = access;
         req->attributes = (attr) ? attr->Attributes : 0;
-        req->rootdir = attr ? attr->RootDirectory : 0;
         req->owned   = InitialOwner;
+        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 );
         status = wine_server_call( req );
         *MutantHandle = reply->handle;
     }
     SERVER_END_REQ;
+
+    free_struct_sd( sd );
+
     return status;
 }
 
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 80ee6f6..8235948 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -914,9 +914,8 @@ struct create_mutex_request
     struct request_header __header;
     unsigned int access;
     unsigned int attributes;
-    obj_handle_t rootdir;
     int          owned;
-    /* VARARG(name,unicode_str); */
+    /* VARARG(objattr,object_attributes); */
 };
 struct create_mutex_reply
 {
@@ -4879,6 +4878,6 @@ union generic_reply
     struct set_completion_info_reply set_completion_info_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 319
+#define SERVER_PROTOCOL_VERSION 320
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/mutex.c b/server/mutex.c
index e128dfc..7064c6f 100644
--- a/server/mutex.c
+++ b/server/mutex.c
@@ -34,6 +34,7 @@
 #include "handle.h"
 #include "thread.h"
 #include "request.h"
+#include "security.h"
 
 struct mutex
 {
@@ -72,7 +73,7 @@ static const struct object_ops mutex_ops =
 
 
 static struct mutex *create_mutex( struct directory *root, const struct unicode_str *name,
-                                   unsigned int attr, int owned )
+                                   unsigned int attr, int owned, const struct security_descriptor *sd )
 {
     struct mutex *mutex;
 
@@ -85,6 +86,10 @@ static struct mutex *create_mutex( struct directory *root, const struct unicode_
             mutex->owner = NULL;
             mutex->abandoned = 0;
             if (owned) mutex_satisfied( &mutex->obj, current );
+            if (sd) default_set_sd( &mutex->obj, sd, OWNER_SECURITY_INFORMATION|
+                                                     GROUP_SECURITY_INFORMATION|
+                                                     DACL_SECURITY_INFORMATION|
+                                                     SACL_SECURITY_INFORMATION );
         }
     }
     return mutex;
@@ -191,13 +196,24 @@ DECL_HANDLER(create_mutex)
     struct mutex *mutex;
     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 ((mutex = create_mutex( root, &name, req->attributes, req->owned )))
+    if ((mutex = create_mutex( root, &name, req->attributes, req->owned, sd )))
     {
         reply->handle = alloc_handle( current->process, mutex, req->access, req->attributes );
         release_object( mutex );
diff --git a/server/protocol.def b/server/protocol.def
index b2ece5e..e486367 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -781,9 +781,8 @@ enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
 @REQ(create_mutex)
     unsigned int access;        /* wanted access rights */
     unsigned int attributes;    /* object attributes */
-    obj_handle_t rootdir;       /* root directory */
     int          owned;         /* initially owned? */
-    VARARG(name,unicode_str);   /* object name */
+    VARARG(objattr,object_attributes); /* object attributes */
 @REPLY
     obj_handle_t handle;        /* handle to the mutex */
 @END
diff --git a/server/trace.c b/server/trace.c
index dd2ef1e..377d9de 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -1191,10 +1191,9 @@ static void dump_create_mutex_request( const struct create_mutex_request *req )
 {
     fprintf( stderr, " access=%08x,", req->access );
     fprintf( stderr, " attributes=%08x,", req->attributes );
-    fprintf( stderr, " rootdir=%p,", req->rootdir );
     fprintf( stderr, " owned=%d,", req->owned );
-    fprintf( stderr, " name=" );
-    dump_varargs_unicode_str( cur_size );
+    fprintf( stderr, " objattr=" );
+    dump_varargs_object_attributes( cur_size );
 }
 
 static void dump_create_mutex_reply( const struct create_mutex_reply *req )




More information about the wine-cvs mailing list