2005-06-08 18:44:50 +00:00
|
|
|
/*
|
|
|
|
* Server-side window stations and desktops handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, 2005 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-11-28 16:32:54 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2005-06-08 18:44:50 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2005-10-27 18:30:37 +00:00
|
|
|
#include "winternl.h"
|
2005-06-08 18:44:50 +00:00
|
|
|
|
|
|
|
#include "object.h"
|
|
|
|
#include "handle.h"
|
|
|
|
#include "request.h"
|
|
|
|
#include "process.h"
|
2005-06-09 09:43:54 +00:00
|
|
|
#include "user.h"
|
2006-03-06 20:02:24 +00:00
|
|
|
#include "file.h"
|
2005-06-08 18:44:50 +00:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
|
|
|
|
static struct list winstation_list = LIST_INIT(winstation_list);
|
|
|
|
static struct winstation *interactive_winstation;
|
|
|
|
static struct namespace *winstation_namespace;
|
|
|
|
|
|
|
|
static void winstation_dump( struct object *obj, int verbose );
|
2005-06-09 15:39:52 +00:00
|
|
|
static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
|
2005-06-08 18:44:50 +00:00
|
|
|
static void winstation_destroy( struct object *obj );
|
|
|
|
static void desktop_dump( struct object *obj, int verbose );
|
2005-06-09 15:39:52 +00:00
|
|
|
static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
|
2005-06-08 18:44:50 +00:00
|
|
|
static void desktop_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops winstation_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct winstation), /* size */
|
|
|
|
winstation_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 13:57:40 +00:00
|
|
|
no_map_access, /* map_access */
|
2005-11-22 14:55:42 +00:00
|
|
|
no_lookup_name, /* lookup_name */
|
2005-06-09 15:39:52 +00:00
|
|
|
winstation_close_handle, /* close_handle */
|
2005-06-08 18:44:50 +00:00
|
|
|
winstation_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const struct object_ops desktop_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct desktop), /* size */
|
|
|
|
desktop_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 13:57:40 +00:00
|
|
|
no_map_access, /* map_access */
|
2005-11-22 14:55:42 +00:00
|
|
|
no_lookup_name, /* lookup_name */
|
2005-06-09 15:39:52 +00:00
|
|
|
desktop_close_handle, /* close_handle */
|
2005-06-08 18:44:50 +00:00
|
|
|
desktop_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DESKTOP_ALL_ACCESS 0x01ff
|
|
|
|
|
|
|
|
/* create a winstation object */
|
2005-11-21 12:05:38 +00:00
|
|
|
static struct winstation *create_winstation( const struct unicode_str *name, unsigned int attr,
|
|
|
|
unsigned int flags )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
struct winstation *winstation;
|
|
|
|
|
2005-11-01 10:22:38 +00:00
|
|
|
if (!winstation_namespace && !(winstation_namespace = create_namespace( 7 )))
|
2005-06-08 18:44:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
if (memchrW( name->str, '\\', name->len / sizeof(WCHAR) )) /* no backslash allowed in name */
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-21 12:05:38 +00:00
|
|
|
if ((winstation = create_named_object( winstation_namespace, &winstation_ops, name, attr )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-11-21 16:27:03 +00:00
|
|
|
if (get_error() != STATUS_OBJECT_NAME_EXISTS)
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
/* initialize it if it didn't already exist */
|
|
|
|
winstation->flags = flags;
|
2005-06-29 20:13:36 +00:00
|
|
|
winstation->clipboard = NULL;
|
2005-07-07 11:29:23 +00:00
|
|
|
winstation->atom_table = NULL;
|
2005-06-08 18:44:50 +00:00
|
|
|
list_add_tail( &winstation_list, &winstation->entry );
|
|
|
|
list_init( &winstation->desktops );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return winstation;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void winstation_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct winstation *winstation = (struct winstation *)obj;
|
|
|
|
|
2005-07-11 13:30:23 +00:00
|
|
|
fprintf( stderr, "Winstation flags=%x clipboard=%p atoms=%p ",
|
|
|
|
winstation->flags, winstation->clipboard, winstation->atom_table );
|
2005-06-08 18:44:50 +00:00
|
|
|
dump_object_name( &winstation->obj );
|
|
|
|
fputc( '\n', stderr );
|
|
|
|
}
|
|
|
|
|
2005-06-09 15:39:52 +00:00
|
|
|
static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
|
|
|
|
{
|
|
|
|
return (process->winstation != handle);
|
|
|
|
}
|
|
|
|
|
2005-06-08 18:44:50 +00:00
|
|
|
static void winstation_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct winstation *winstation = (struct winstation *)obj;
|
|
|
|
|
|
|
|
if (winstation == interactive_winstation) interactive_winstation = NULL;
|
|
|
|
list_remove( &winstation->entry );
|
2005-06-29 20:13:36 +00:00
|
|
|
if (winstation->clipboard) release_object( winstation->clipboard );
|
2005-07-07 11:29:23 +00:00
|
|
|
if (winstation->atom_table) release_object( winstation->atom_table );
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve the process window station, checking the handle access rights */
|
2005-06-29 20:13:36 +00:00
|
|
|
struct winstation *get_process_winstation( struct process *process, unsigned int access )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
return (struct winstation *)get_handle_obj( process, process->winstation,
|
|
|
|
access, &winstation_ops );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build the full name of a desktop object */
|
2005-11-18 16:31:18 +00:00
|
|
|
static WCHAR *build_desktop_name( const struct unicode_str *name,
|
|
|
|
struct winstation *winstation, struct unicode_str *res )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
const WCHAR *winstation_name;
|
|
|
|
WCHAR *full_name;
|
|
|
|
size_t winstation_len;
|
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
if (memchrW( name->str, '\\', name->len / sizeof(WCHAR) ))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(winstation_name = get_object_name( &winstation->obj, &winstation_len )))
|
|
|
|
winstation_len = 0;
|
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
res->len = winstation_len + name->len + sizeof(WCHAR);
|
|
|
|
if (!(full_name = mem_alloc( res->len ))) return NULL;
|
2005-06-08 18:44:50 +00:00
|
|
|
memcpy( full_name, winstation_name, winstation_len );
|
|
|
|
full_name[winstation_len / sizeof(WCHAR)] = '\\';
|
2005-11-18 16:31:18 +00:00
|
|
|
memcpy( full_name + winstation_len / sizeof(WCHAR) + 1, name->str, name->len );
|
|
|
|
res->str = full_name;
|
2005-06-08 18:44:50 +00:00
|
|
|
return full_name;
|
|
|
|
}
|
|
|
|
|
2005-06-28 19:37:52 +00:00
|
|
|
/* retrieve a pointer to a desktop object */
|
|
|
|
inline static struct desktop *get_desktop_obj( struct process *process, obj_handle_t handle,
|
|
|
|
unsigned int access )
|
|
|
|
{
|
|
|
|
return (struct desktop *)get_handle_obj( process, handle, access, &desktop_ops );
|
|
|
|
}
|
|
|
|
|
2005-06-08 18:44:50 +00:00
|
|
|
/* create a desktop object */
|
2005-11-21 12:05:38 +00:00
|
|
|
static struct desktop *create_desktop( const struct unicode_str *name, unsigned int attr,
|
|
|
|
unsigned int flags, struct winstation *winstation )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
struct desktop *desktop;
|
2005-11-18 16:31:18 +00:00
|
|
|
struct unicode_str full_str;
|
2005-06-08 18:44:50 +00:00
|
|
|
WCHAR *full_name;
|
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
if (!(full_name = build_desktop_name( name, winstation, &full_str ))) return NULL;
|
2005-06-08 18:44:50 +00:00
|
|
|
|
2005-11-21 12:05:38 +00:00
|
|
|
if ((desktop = create_named_object( winstation_namespace, &desktop_ops, &full_str, attr )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-11-21 16:27:03 +00:00
|
|
|
if (get_error() != STATUS_OBJECT_NAME_EXISTS)
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
/* initialize it if it didn't already exist */
|
|
|
|
desktop->flags = flags;
|
|
|
|
desktop->winstation = (struct winstation *)grab_object( winstation );
|
2005-07-11 13:30:23 +00:00
|
|
|
desktop->top_window = NULL;
|
2005-07-11 18:05:50 +00:00
|
|
|
desktop->global_hooks = NULL;
|
2006-03-06 20:02:24 +00:00
|
|
|
desktop->close_timeout = NULL;
|
|
|
|
desktop->users = 0;
|
2005-06-08 18:44:50 +00:00
|
|
|
list_add_tail( &winstation->desktops, &desktop->entry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free( full_name );
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void desktop_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct desktop *desktop = (struct desktop *)obj;
|
|
|
|
|
2005-07-11 18:05:50 +00:00
|
|
|
fprintf( stderr, "Desktop flags=%x winstation=%p top_win=%p hooks=%p ",
|
|
|
|
desktop->flags, desktop->winstation, desktop->top_window, desktop->global_hooks );
|
2005-06-08 18:44:50 +00:00
|
|
|
dump_object_name( &desktop->obj );
|
|
|
|
fputc( '\n', stderr );
|
|
|
|
}
|
|
|
|
|
2005-06-09 15:39:52 +00:00
|
|
|
static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-06-09 15:39:52 +00:00
|
|
|
struct thread *thread;
|
2005-06-08 18:44:50 +00:00
|
|
|
|
2005-06-09 15:39:52 +00:00
|
|
|
/* check if the handle is currently used by the process or one of its threads */
|
|
|
|
if (process->desktop == handle) return 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
|
|
|
|
if (thread->desktop == handle) return 0;
|
|
|
|
return 1;
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
2005-06-09 15:39:52 +00:00
|
|
|
static void desktop_destroy( struct object *obj )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-06-09 15:39:52 +00:00
|
|
|
struct desktop *desktop = (struct desktop *)obj;
|
2005-06-09 12:07:12 +00:00
|
|
|
|
2005-07-11 13:30:23 +00:00
|
|
|
if (desktop->top_window) destroy_window( desktop->top_window );
|
2005-07-11 18:05:50 +00:00
|
|
|
if (desktop->global_hooks) release_object( desktop->global_hooks );
|
2006-03-06 20:02:24 +00:00
|
|
|
if (desktop->close_timeout) remove_timeout_user( desktop->close_timeout );
|
2005-06-09 15:39:52 +00:00
|
|
|
list_remove( &desktop->entry );
|
|
|
|
release_object( desktop->winstation );
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
2005-07-11 10:55:53 +00:00
|
|
|
/* retrieve the thread desktop, checking the handle access rights */
|
|
|
|
struct desktop *get_thread_desktop( struct thread *thread, unsigned int access )
|
|
|
|
{
|
|
|
|
return get_desktop_obj( thread->process, thread->desktop, access );
|
|
|
|
}
|
|
|
|
|
2005-06-08 18:44:50 +00:00
|
|
|
/* connect a process to its window station */
|
2005-11-18 16:31:18 +00:00
|
|
|
void connect_process_winstation( struct process *process, const struct unicode_str *name )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
struct winstation *winstation;
|
|
|
|
|
|
|
|
if (process->winstation) return; /* already has one */
|
|
|
|
|
|
|
|
/* check for an inherited winstation handle (don't ask...) */
|
|
|
|
if ((process->winstation = find_inherited_handle( process, &winstation_ops )) != 0) return;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
2005-11-21 12:05:38 +00:00
|
|
|
winstation = create_winstation( name, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 0 );
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!interactive_winstation)
|
|
|
|
{
|
|
|
|
static const WCHAR winsta0W[] = {'W','i','n','S','t','a','0'};
|
2005-11-18 16:31:18 +00:00
|
|
|
static const struct unicode_str winsta0 = { winsta0W, sizeof(winsta0W) };
|
2005-11-21 12:05:38 +00:00
|
|
|
interactive_winstation = create_winstation( &winsta0, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 0 );
|
2005-06-08 18:44:50 +00:00
|
|
|
winstation = interactive_winstation;
|
|
|
|
}
|
|
|
|
else winstation = (struct winstation *)grab_object( interactive_winstation );
|
|
|
|
}
|
|
|
|
if (winstation)
|
|
|
|
{
|
2005-12-09 12:58:25 +00:00
|
|
|
process->winstation = alloc_handle( process, winstation, WINSTA_ALL_ACCESS, 0 );
|
2005-06-08 18:44:50 +00:00
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
clear_error(); /* ignore errors */
|
|
|
|
}
|
|
|
|
|
2005-06-09 12:07:12 +00:00
|
|
|
/* connect a process to its main desktop */
|
2005-11-18 16:31:18 +00:00
|
|
|
void connect_process_desktop( struct process *process, const struct unicode_str *name )
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
|
|
|
struct desktop *desktop;
|
|
|
|
struct winstation *winstation;
|
|
|
|
|
2005-06-09 12:07:12 +00:00
|
|
|
if (process->desktop) return; /* already has one */
|
2005-06-08 18:44:50 +00:00
|
|
|
|
|
|
|
if ((winstation = get_process_winstation( process, WINSTA_CREATEDESKTOP )))
|
|
|
|
{
|
|
|
|
static const WCHAR defaultW[] = {'D','e','f','a','u','l','t'};
|
2005-11-18 16:31:18 +00:00
|
|
|
static const struct unicode_str default_str = { defaultW, sizeof(defaultW) };
|
2005-06-08 18:44:50 +00:00
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
if (!name) name = &default_str;
|
2005-11-21 12:05:38 +00:00
|
|
|
if ((desktop = create_desktop( name, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 0, winstation )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-12-09 12:58:25 +00:00
|
|
|
process->desktop = alloc_handle( process, desktop, DESKTOP_ALL_ACCESS, 0 );
|
2006-03-06 20:02:24 +00:00
|
|
|
desktop->users++;
|
|
|
|
if (desktop->close_timeout)
|
|
|
|
{
|
|
|
|
remove_timeout_user( desktop->close_timeout );
|
|
|
|
desktop->close_timeout = NULL;
|
|
|
|
}
|
2005-06-08 18:44:50 +00:00
|
|
|
release_object( desktop );
|
|
|
|
}
|
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
clear_error(); /* ignore errors */
|
|
|
|
}
|
|
|
|
|
2006-03-06 20:02:24 +00:00
|
|
|
static void close_desktop_timeout( void *private )
|
|
|
|
{
|
|
|
|
struct desktop *desktop = private;
|
|
|
|
|
|
|
|
desktop->close_timeout = NULL;
|
|
|
|
unlink_named_object( &desktop->obj ); /* make sure no other process can open it */
|
|
|
|
close_desktop_window( desktop ); /* and signal the owner to quit */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close the desktop of a given process */
|
|
|
|
void close_process_desktop( struct process *process )
|
|
|
|
{
|
|
|
|
struct desktop *desktop;
|
|
|
|
|
|
|
|
if (process->desktop && (desktop = get_desktop_obj( process, process->desktop, 0 )))
|
|
|
|
{
|
|
|
|
assert( desktop->users > 0 );
|
|
|
|
desktop->users--;
|
|
|
|
/* if we have one remaining user, it has to be the manager of the desktop window */
|
|
|
|
if (desktop->users == 1 && get_top_window_owner( desktop ))
|
|
|
|
{
|
|
|
|
struct timeval when;
|
|
|
|
gettimeofday( &when, NULL );
|
|
|
|
add_timeout( &when, 1000 );
|
|
|
|
desktop->close_timeout = add_timeout_user( &when, close_desktop_timeout, desktop );
|
|
|
|
}
|
|
|
|
release_object( desktop );
|
|
|
|
}
|
|
|
|
clear_error(); /* ignore errors */
|
|
|
|
}
|
|
|
|
|
2005-06-08 18:44:50 +00:00
|
|
|
/* close the desktop of a given thread */
|
|
|
|
void close_thread_desktop( struct thread *thread )
|
|
|
|
{
|
|
|
|
obj_handle_t handle = thread->desktop;
|
|
|
|
|
|
|
|
thread->desktop = 0;
|
2005-06-09 15:39:52 +00:00
|
|
|
if (handle) close_handle( thread->process, handle, NULL );
|
|
|
|
clear_error(); /* ignore errors */
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create a window station */
|
|
|
|
DECL_HANDLER(create_winstation)
|
|
|
|
{
|
|
|
|
struct winstation *winstation;
|
2005-11-18 16:31:18 +00:00
|
|
|
struct unicode_str name;
|
2005-06-08 18:44:50 +00:00
|
|
|
|
|
|
|
reply->handle = 0;
|
2005-11-18 16:31:18 +00:00
|
|
|
get_req_unicode_str( &name );
|
2005-11-21 12:05:38 +00:00
|
|
|
if ((winstation = create_winstation( &name, req->attributes, req->flags )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-12-09 12:58:25 +00:00
|
|
|
reply->handle = alloc_handle( current->process, winstation, req->access, req->attributes );
|
2005-06-08 18:44:50 +00:00
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a handle to a window station */
|
|
|
|
DECL_HANDLER(open_winstation)
|
|
|
|
{
|
2005-11-18 16:31:18 +00:00
|
|
|
struct unicode_str name;
|
|
|
|
|
|
|
|
get_req_unicode_str( &name );
|
2005-06-08 18:44:50 +00:00
|
|
|
if (winstation_namespace)
|
2005-11-18 16:31:18 +00:00
|
|
|
reply->handle = open_object( winstation_namespace, &name, &winstation_ops, req->access,
|
2005-11-21 12:05:38 +00:00
|
|
|
req->attributes );
|
2005-06-08 18:44:50 +00:00
|
|
|
else
|
|
|
|
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* close a window station */
|
|
|
|
DECL_HANDLER(close_winstation)
|
|
|
|
{
|
|
|
|
struct winstation *winstation;
|
|
|
|
|
|
|
|
if ((winstation = (struct winstation *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &winstation_ops )))
|
|
|
|
{
|
2005-06-09 15:39:52 +00:00
|
|
|
if (!close_handle( current->process, req->handle, NULL )) set_error( STATUS_ACCESS_DENIED );
|
2005-06-08 18:44:50 +00:00
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the process current window station */
|
|
|
|
DECL_HANDLER(get_process_winstation)
|
|
|
|
{
|
|
|
|
reply->handle = current->process->winstation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set the process current window station */
|
|
|
|
DECL_HANDLER(set_process_winstation)
|
|
|
|
{
|
|
|
|
struct winstation *winstation;
|
|
|
|
|
|
|
|
if ((winstation = (struct winstation *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &winstation_ops )))
|
|
|
|
{
|
|
|
|
/* FIXME: should we close the old one? */
|
|
|
|
current->process->winstation = req->handle;
|
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a desktop */
|
|
|
|
DECL_HANDLER(create_desktop)
|
|
|
|
{
|
|
|
|
struct desktop *desktop;
|
|
|
|
struct winstation *winstation;
|
2005-11-18 16:31:18 +00:00
|
|
|
struct unicode_str name;
|
2005-06-08 18:44:50 +00:00
|
|
|
|
|
|
|
reply->handle = 0;
|
2005-11-18 16:31:18 +00:00
|
|
|
get_req_unicode_str( &name );
|
2005-06-08 18:44:50 +00:00
|
|
|
if ((winstation = get_process_winstation( current->process, WINSTA_CREATEDESKTOP )))
|
|
|
|
{
|
2005-11-21 12:05:38 +00:00
|
|
|
if ((desktop = create_desktop( &name, req->attributes, req->flags, winstation )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-12-09 12:58:25 +00:00
|
|
|
reply->handle = alloc_handle( current->process, desktop, req->access, req->attributes );
|
2005-06-08 18:44:50 +00:00
|
|
|
release_object( desktop );
|
|
|
|
}
|
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a handle to a desktop */
|
|
|
|
DECL_HANDLER(open_desktop)
|
|
|
|
{
|
|
|
|
struct winstation *winstation;
|
2005-11-18 16:31:18 +00:00
|
|
|
struct unicode_str name;
|
2005-06-08 18:44:50 +00:00
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
get_req_unicode_str( &name );
|
2005-06-08 18:44:50 +00:00
|
|
|
if ((winstation = get_process_winstation( current->process, 0 /* FIXME: access rights? */ )))
|
|
|
|
{
|
2005-11-18 16:31:18 +00:00
|
|
|
struct unicode_str full_str;
|
2005-06-08 18:44:50 +00:00
|
|
|
WCHAR *full_name;
|
|
|
|
|
2005-11-18 16:31:18 +00:00
|
|
|
if ((full_name = build_desktop_name( &name, winstation, &full_str )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-11-18 16:31:18 +00:00
|
|
|
reply->handle = open_object( winstation_namespace, &full_str, &desktop_ops, req->access,
|
2005-11-21 12:05:38 +00:00
|
|
|
req->attributes );
|
2005-06-08 18:44:50 +00:00
|
|
|
free( full_name );
|
|
|
|
}
|
|
|
|
release_object( winstation );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* close a desktop */
|
|
|
|
DECL_HANDLER(close_desktop)
|
|
|
|
{
|
|
|
|
struct desktop *desktop;
|
|
|
|
|
|
|
|
/* make sure it is a desktop handle */
|
|
|
|
if ((desktop = (struct desktop *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &desktop_ops )))
|
|
|
|
{
|
2005-06-09 15:39:52 +00:00
|
|
|
if (!close_handle( current->process, req->handle, NULL )) set_error( STATUS_DEVICE_BUSY );
|
2005-06-08 18:44:50 +00:00
|
|
|
release_object( desktop );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the thread current desktop */
|
|
|
|
DECL_HANDLER(get_thread_desktop)
|
|
|
|
{
|
|
|
|
struct thread *thread;
|
|
|
|
|
|
|
|
if (!(thread = get_thread_from_id( req->tid ))) return;
|
|
|
|
reply->handle = thread->desktop;
|
|
|
|
release_object( thread );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set the thread current desktop */
|
|
|
|
DECL_HANDLER(set_thread_desktop)
|
|
|
|
{
|
2005-06-28 19:37:52 +00:00
|
|
|
struct desktop *old_desktop, *new_desktop;
|
|
|
|
struct winstation *winstation;
|
2005-06-08 18:44:50 +00:00
|
|
|
|
2005-06-28 19:37:52 +00:00
|
|
|
if (!(winstation = get_process_winstation( current->process, 0 /* FIXME: access rights? */ )))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(new_desktop = get_desktop_obj( current->process, req->handle, 0 )))
|
2005-06-08 18:44:50 +00:00
|
|
|
{
|
2005-06-28 19:37:52 +00:00
|
|
|
release_object( winstation );
|
|
|
|
return;
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
2005-06-28 19:37:52 +00:00
|
|
|
if (new_desktop->winstation != winstation)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
release_object( new_desktop );
|
|
|
|
release_object( winstation );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we are changing to a new desktop */
|
|
|
|
|
|
|
|
if (!(old_desktop = get_desktop_obj( current->process, current->desktop, 0)))
|
|
|
|
clear_error(); /* ignore error */
|
|
|
|
|
|
|
|
/* when changing desktop, we can't have any users on the current one */
|
|
|
|
if (old_desktop != new_desktop && current->desktop_users > 0)
|
|
|
|
set_error( STATUS_DEVICE_BUSY );
|
|
|
|
else
|
|
|
|
current->desktop = req->handle; /* FIXME: should we close the old one? */
|
|
|
|
|
2006-03-06 14:10:59 +00:00
|
|
|
if (old_desktop != new_desktop && current->queue) detach_thread_input( current );
|
2005-07-11 13:30:23 +00:00
|
|
|
|
2005-06-28 19:37:52 +00:00
|
|
|
if (old_desktop) release_object( old_desktop );
|
|
|
|
release_object( new_desktop );
|
|
|
|
release_object( winstation );
|
2005-06-08 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get/set information about a user object (window station or desktop) */
|
|
|
|
DECL_HANDLER(set_user_object_info)
|
|
|
|
{
|
|
|
|
struct object *obj;
|
|
|
|
|
|
|
|
if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
|
|
|
|
|
|
|
|
if (obj->ops == &desktop_ops)
|
|
|
|
{
|
|
|
|
struct desktop *desktop = (struct desktop *)obj;
|
|
|
|
reply->is_desktop = 1;
|
|
|
|
reply->old_obj_flags = desktop->flags;
|
|
|
|
if (req->flags & SET_USER_OBJECT_FLAGS) desktop->flags = req->obj_flags;
|
|
|
|
}
|
|
|
|
else if (obj->ops == &winstation_ops)
|
|
|
|
{
|
|
|
|
struct winstation *winstation = (struct winstation *)obj;
|
|
|
|
reply->is_desktop = 0;
|
|
|
|
reply->old_obj_flags = winstation->flags;
|
|
|
|
if (req->flags & SET_USER_OBJECT_FLAGS) winstation->flags = req->obj_flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
|
|
|
release_object( obj );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (get_reply_max_size())
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const WCHAR *ptr, *name = get_object_name( obj, &len );
|
|
|
|
|
|
|
|
/* if there is a backslash return the part of the name after it */
|
|
|
|
if (name && (ptr = memchrW( name, '\\', len )))
|
|
|
|
{
|
2005-06-09 12:07:12 +00:00
|
|
|
len -= (ptr + 1 - name) * sizeof(WCHAR);
|
2005-06-08 18:44:50 +00:00
|
|
|
name = ptr + 1;
|
|
|
|
}
|
|
|
|
if (name) set_reply_data( name, min( len, get_reply_max_size() ));
|
|
|
|
}
|
|
|
|
release_object( obj );
|
|
|
|
}
|