server: Create window stations objects in a standard directory.
authorAlexandre Julliard <julliard@winehq.org>
Wed, 20 Jan 2016 13:02:03 +0000 (22:02 +0900)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 20 Jan 2016 13:02:03 +0000 (22:02 +0900)
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
dlls/user32/winstation.c
include/wine/server_protocol.h
server/directory.c
server/protocol.def
server/request.h
server/trace.c
server/winstation.c

index ae1d6adcb4376f63c8f0185a189dd712e1141640..4e431b552e3a689f1fa8e4385139c38afcc96e03 100644 (file)
@@ -28,6 +28,8 @@
 #include "winerror.h"
 #include "wingdi.h"
 #include "winuser.h"
+#include "winternl.h"
+#include "ddk/wdm.h"
 #include "wine/server.h"
 #include "wine/unicode.h"
 #include "wine/debug.h"
@@ -53,6 +55,27 @@ static BOOL CALLBACK enum_names_WtoA( LPWSTR name, LPARAM lparam )
     return data->func( buffer, data->lparam );
 }
 
+/* return a handle to the directory where window station objects are created */
+static HANDLE get_winstations_dir_handle(void)
+{
+    static HANDLE handle = NULL;
+    static const WCHAR basenameW[] = {'\\','W','i','n','d','o','w','s','\\',
+                                      'W','i','n','d','o','w','S','t','a','t','i','o','n','s',0};
+    UNICODE_STRING str;
+    OBJECT_ATTRIBUTES attr;
+
+    if (!handle)
+    {
+        HANDLE dir;
+
+        RtlInitUnicodeString( &str, basenameW );
+        InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
+        NtOpenDirectoryObject( &dir, DIRECTORY_CREATE_OBJECT | DIRECTORY_TRAVERSE, &attr );
+        if (InterlockedCompareExchangePointer( &handle, dir, 0 ) != 0) /* someone beat us here */
+            CloseHandle( dir );
+    }
+    return handle;
+}
 
 /***********************************************************************
  *              CreateWindowStationA  (USER32.@)
@@ -93,6 +116,7 @@ HWINSTA WINAPI CreateWindowStationW( LPCWSTR name, DWORD reserved, ACCESS_MASK a
         req->access     = access;
         req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
                           ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
+        req->rootdir    = wine_server_obj_handle( get_winstations_dir_handle() );
         wine_server_add_data( req, name, len * sizeof(WCHAR) );
         /* it doesn't seem to set last error */
         wine_server_call( req );
@@ -137,6 +161,7 @@ HWINSTA WINAPI OpenWindowStationW( LPCWSTR name, BOOL inherit, ACCESS_MASK acces
     {
         req->access     = access;
         req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
+        req->rootdir    = wine_server_obj_handle( get_winstations_dir_handle() );
         wine_server_add_data( req, name, len * sizeof(WCHAR) );
         if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->handle );
     }
index 753f8e35b126cec485703f92c02234c0dcd05e16..61e6d3f0362c71e6e0084055bb4bd91053c48bc0 100644 (file)
@@ -3795,7 +3795,9 @@ struct create_winstation_request
     unsigned int flags;
     unsigned int access;
     unsigned int attributes;
+    obj_handle_t rootdir;
     /* VARARG(name,unicode_str); */
+    char __pad_28[4];
 };
 struct create_winstation_reply
 {
@@ -3811,8 +3813,8 @@ struct open_winstation_request
     struct request_header __header;
     unsigned int access;
     unsigned int attributes;
+    obj_handle_t rootdir;
     /* VARARG(name,unicode_str); */
-    char __pad_20[4];
 };
 struct open_winstation_reply
 {
@@ -6155,6 +6157,6 @@ union generic_reply
     struct terminate_job_reply terminate_job_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 499
+#define SERVER_PROTOCOL_VERSION 500
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
index 05dddeceaecf100834ff85ef7f5285921ae067ca..9369e78c4f4b2f1901478f64d62dcb74bcb51286 100644 (file)
@@ -380,6 +380,8 @@ void init_directories(void)
     static const WCHAR dir_objtypeW[] = {'O','b','j','e','c','t','T','y','p','e','s'};
     static const WCHAR dir_sessionsW[] = {'S','e','s','s','i','o','n','s'};
     static const WCHAR dir_kernelW[] = {'K','e','r','n','e','l','O','b','j','e','c','t','s'};
+    static const WCHAR dir_windowsW[] = {'W','i','n','d','o','w','s'};
+    static const WCHAR dir_winstationsW[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n','s'};
     static const struct unicode_str dir_global_str = {dir_globalW, sizeof(dir_globalW)};
     static const struct unicode_str dir_driver_str = {dir_driverW, sizeof(dir_driverW)};
     static const struct unicode_str dir_device_str = {dir_deviceW, sizeof(dir_deviceW)};
@@ -390,6 +392,8 @@ void init_directories(void)
     static const struct unicode_str dir_objtype_str = {dir_objtypeW, sizeof(dir_objtypeW)};
     static const struct unicode_str dir_sessions_str = {dir_sessionsW, sizeof(dir_sessionsW)};
     static const struct unicode_str dir_kernel_str = {dir_kernelW, sizeof(dir_kernelW)};
+    static const struct unicode_str dir_windows_str = {dir_windowsW, sizeof(dir_windowsW)};
+    static const struct unicode_str dir_winstations_str = {dir_winstationsW, sizeof(dir_winstationsW)};
 
     /* symlinks */
     static const WCHAR link_dosdevW[] = {'D','o','s','D','e','v','i','c','e','s'};
@@ -438,7 +442,7 @@ void init_directories(void)
     };
     static const struct unicode_str keyed_event_crit_sect_str = {keyed_event_crit_sectW, sizeof(keyed_event_crit_sectW)};
 
-    struct directory *dir_driver, *dir_device, *dir_global, *dir_basenamed, *dir_sessions, *dir_kernel;
+    struct directory *dir_driver, *dir_device, *dir_global, *dir_basenamed, *dir_sessions, *dir_kernel, *dir_windows, *dir_winstation;
     struct symlink *link_dosdev, *link_global1, *link_global2, *link_local, *link_nul, *link_pipe, *link_mailslot, *link_0, *link_session;
     struct keyed_event *keyed_event;
     unsigned int i;
@@ -449,9 +453,12 @@ void init_directories(void)
     dir_objtype    = create_directory( root_directory, &dir_objtype_str, 0, HASH_SIZE, NULL );
     dir_sessions   = create_directory( root_directory, &dir_sessions_str, 0, HASH_SIZE, NULL );
     dir_kernel     = create_directory( root_directory, &dir_kernel_str, 0, HASH_SIZE, NULL );
+    dir_windows    = create_directory( root_directory, &dir_windows_str, 0, HASH_SIZE, NULL );
+    dir_winstation = create_directory( dir_windows, &dir_winstations_str, 0, HASH_SIZE, NULL );
     make_object_static( &root_directory->obj );
     make_object_static( &dir_driver->obj );
     make_object_static( &dir_objtype->obj );
+    make_object_static( &dir_winstation->obj );
 
     dir_global     = create_directory( NULL, &dir_global_str, 0, HASH_SIZE, NULL );
     /* use a larger hash table for this one since it can contain a lot of objects */
@@ -497,6 +504,7 @@ void init_directories(void)
     release_object( dir_basenamed );
     release_object( dir_sessions );
     release_object( dir_kernel );
+    release_object( dir_windows );
 }
 
 /* create a directory object */
index 08c5bc16df04cce92d33166e5d9d493ca2e7e052..2819382413a3e8b12b50d0f3932ee2ad4d4f1b6c 100644 (file)
@@ -2719,6 +2719,7 @@ enum coords_relative
     unsigned int flags;           /* window station flags */
     unsigned int access;          /* wanted access rights */
     unsigned int attributes;      /* object attributes */
+    obj_handle_t rootdir;         /* root directory */
     VARARG(name,unicode_str);     /* object name */
 @REPLY
     obj_handle_t handle;          /* handle to the window station */
@@ -2729,6 +2730,7 @@ enum coords_relative
 @REQ(open_winstation)
     unsigned int access;          /* wanted access rights */
     unsigned int attributes;      /* object attributes */
+    obj_handle_t rootdir;         /* root directory */
     VARARG(name,unicode_str);     /* object name */
 @REPLY
     obj_handle_t handle;          /* handle to the window station */
index d21a539ec62da3db1d7ac416e9c9b322b6738448..8e53e39d1c31f92ad4b2753014aa694d7f1db1d9 100644 (file)
@@ -1766,11 +1766,13 @@ C_ASSERT( sizeof(struct get_window_properties_reply) == 16 );
 C_ASSERT( FIELD_OFFSET(struct create_winstation_request, flags) == 12 );
 C_ASSERT( FIELD_OFFSET(struct create_winstation_request, access) == 16 );
 C_ASSERT( FIELD_OFFSET(struct create_winstation_request, attributes) == 20 );
-C_ASSERT( sizeof(struct create_winstation_request) == 24 );
+C_ASSERT( FIELD_OFFSET(struct create_winstation_request, rootdir) == 24 );
+C_ASSERT( sizeof(struct create_winstation_request) == 32 );
 C_ASSERT( FIELD_OFFSET(struct create_winstation_reply, handle) == 8 );
 C_ASSERT( sizeof(struct create_winstation_reply) == 16 );
 C_ASSERT( FIELD_OFFSET(struct open_winstation_request, access) == 12 );
 C_ASSERT( FIELD_OFFSET(struct open_winstation_request, attributes) == 16 );
+C_ASSERT( FIELD_OFFSET(struct open_winstation_request, rootdir) == 20 );
 C_ASSERT( sizeof(struct open_winstation_request) == 24 );
 C_ASSERT( FIELD_OFFSET(struct open_winstation_reply, handle) == 8 );
 C_ASSERT( sizeof(struct open_winstation_reply) == 16 );
index 84ed113dcd2d716d80eb472e0b0b17c42bdaea26..1b6389444bdb3d5e635dbb6e9985a466d37de222 100644 (file)
@@ -3245,6 +3245,7 @@ static void dump_create_winstation_request( const struct create_winstation_reque
     fprintf( stderr, " flags=%08x", req->flags );
     fprintf( stderr, ", access=%08x", req->access );
     fprintf( stderr, ", attributes=%08x", req->attributes );
+    fprintf( stderr, ", rootdir=%04x", req->rootdir );
     dump_varargs_unicode_str( ", name=", cur_size );
 }
 
@@ -3257,6 +3258,7 @@ static void dump_open_winstation_request( const struct open_winstation_request *
 {
     fprintf( stderr, " access=%08x", req->access );
     fprintf( stderr, ", attributes=%08x", req->attributes );
+    fprintf( stderr, ", rootdir=%04x", req->rootdir );
     dump_varargs_unicode_str( ", name=", cur_size );
 }
 
index 50161844aafd1f220df7d956a36fa1ff532a3659..33e121fc84779bd9e011cee3bb0ebed7071919d1 100644 (file)
@@ -99,8 +99,8 @@ static const struct object_ops desktop_ops =
 #define DESKTOP_ALL_ACCESS 0x01ff
 
 /* create a winstation object */
-static struct winstation *create_winstation( const struct unicode_str *name, unsigned int attr,
-                                             unsigned int flags )
+static struct winstation *create_winstation( struct directory *root, const struct unicode_str *name,
+                                             unsigned int attr, unsigned int flags )
 {
     struct winstation *winstation;
 
@@ -113,7 +113,7 @@ static struct winstation *create_winstation( const struct unicode_str *name, uns
         return NULL;
     }
 
-    if ((winstation = create_named_object( winstation_namespace, &winstation_ops, name, attr )))
+    if ((winstation = create_named_object_dir( root, name, attr, &winstation_ops )))
     {
         if (get_error() != STATUS_OBJECT_NAME_EXISTS)
         {
@@ -443,27 +443,36 @@ DECL_HANDLER(create_winstation)
 {
     struct winstation *winstation;
     struct unicode_str name;
+    struct directory *root = NULL;
 
     reply->handle = 0;
     get_req_unicode_str( &name );
-    if ((winstation = create_winstation( &name, req->attributes, req->flags )))
+    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return;
+
+    if ((winstation = create_winstation( root, &name, req->attributes, req->flags )))
     {
         reply->handle = alloc_handle( current->process, winstation, req->access, req->attributes );
         release_object( winstation );
     }
+    if (root) release_object( root );
 }
 
 /* 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 (winstation_namespace)
-        reply->handle = open_object( winstation_namespace, &name, &winstation_ops, req->access,
-                                     req->attributes );
-    else
-        set_error( STATUS_OBJECT_NAME_NOT_FOUND );
+    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 );
 }