winstation.c 25.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24
 */

#include "config.h"

#include <stdio.h>
#include <stdarg.h>
25
#include <sys/types.h>
26

27 28
#include "ntstatus.h"
#define WIN32_NO_STATUS
29 30 31
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
32
#include "winternl.h"
33 34 35 36 37

#include "object.h"
#include "handle.h"
#include "request.h"
#include "process.h"
38
#include "user.h"
39
#include "file.h"
40
#include "security.h"
41

42
#define DESKTOP_ALL_ACCESS 0x01ff
43 44 45 46

static struct list winstation_list = LIST_INIT(winstation_list);

static void winstation_dump( struct object *obj, int verbose );
47
static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
48
static struct object *winstation_lookup_name( struct object *obj, struct unicode_str *name,
49
                                              unsigned int attr, struct object *root );
50 51
static void winstation_destroy( struct object *obj );
static void desktop_dump( struct object *obj, int verbose );
52
static int desktop_link_name( struct object *obj, struct object_name *name, struct object *parent );
53
static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
54 55
static void desktop_destroy( struct object *obj );

56 57 58 59 60
static const WCHAR winstation_name[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n'};

struct type_descr winstation_type =
{
    { winstation_name, sizeof(winstation_name) },   /* name */
61 62 63 64 65 66 67
    STANDARD_RIGHTS_REQUIRED | WINSTA_ALL_ACCESS,   /* valid_access */
    {                                               /* mapping */
        STANDARD_RIGHTS_READ | WINSTA_READSCREEN | WINSTA_ENUMERATE | WINSTA_READATTRIBUTES | WINSTA_ENUMDESKTOPS,
        STANDARD_RIGHTS_WRITE | WINSTA_WRITEATTRIBUTES | WINSTA_CREATEDESKTOP | WINSTA_ACCESSCLIPBOARD,
        STANDARD_RIGHTS_EXECUTE | WINSTA_EXITWINDOWS | WINSTA_ACCESSGLOBALATOMS,
        STANDARD_RIGHTS_REQUIRED | WINSTA_ALL_ACCESS
    },
68 69
};

70 71 72
static const struct object_ops winstation_ops =
{
    sizeof(struct winstation),    /* size */
73
    &winstation_type,             /* type */
74 75 76 77 78 79 80
    winstation_dump,              /* dump */
    no_add_queue,                 /* add_queue */
    NULL,                         /* remove_queue */
    NULL,                         /* signaled */
    NULL,                         /* satisfied */
    no_signal,                    /* signal */
    no_get_fd,                    /* get_fd */
81
    default_map_access,           /* map_access */
82 83
    default_get_sd,               /* get_sd */
    default_set_sd,               /* set_sd */
84
    default_get_full_name,        /* get_full_name */
85
    winstation_lookup_name,       /* lookup_name */
86 87
    directory_link_name,          /* link_name */
    default_unlink_name,          /* unlink_name */
88
    no_open_file,                 /* open_file */
89
    no_kernel_obj_list,           /* get_kernel_obj_list */
90
    winstation_close_handle,      /* close_handle */
91 92 93 94
    winstation_destroy            /* destroy */
};


95 96 97 98 99
static const WCHAR desktop_name[] = {'D','e','s','k','t','o','p'};

struct type_descr desktop_type =
{
    { desktop_name, sizeof(desktop_name) },   /* name */
100 101 102 103 104 105 106 107
    STANDARD_RIGHTS_REQUIRED | DESKTOP_ALL_ACCESS,  /* valid_access */
    {                                         /* mapping */
        STANDARD_RIGHTS_READ | DESKTOP_ENUMERATE | DESKTOP_READOBJECTS,
        STANDARD_RIGHTS_WRITE | DESKTOP_WRITEOBJECTS | DESKTOP_JOURNALPLAYBACK | DESKTOP_JOURNALRECORD
        | DESKTOP_HOOKCONTROL | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW,
        STANDARD_RIGHTS_EXECUTE | DESKTOP_SWITCHDESKTOP,
        STANDARD_RIGHTS_REQUIRED | DESKTOP_ALL_ACCESS
    },
108 109
};

110 111 112
static const struct object_ops desktop_ops =
{
    sizeof(struct desktop),       /* size */
113
    &desktop_type,                /* type */
114 115 116 117 118 119 120
    desktop_dump,                 /* dump */
    no_add_queue,                 /* add_queue */
    NULL,                         /* remove_queue */
    NULL,                         /* signaled */
    NULL,                         /* satisfied */
    no_signal,                    /* signal */
    no_get_fd,                    /* get_fd */
121
    default_map_access,           /* map_access */
122 123
    default_get_sd,               /* get_sd */
    default_set_sd,               /* set_sd */
124
    default_get_full_name,        /* get_full_name */
125
    no_lookup_name,               /* lookup_name */
126 127
    desktop_link_name,            /* link_name */
    default_unlink_name,          /* unlink_name */
128
    no_open_file,                 /* open_file */
129
    no_kernel_obj_list,           /* get_kernel_obj_list */
130
    desktop_close_handle,         /* close_handle */
131 132 133 134
    desktop_destroy               /* destroy */
};

/* create a winstation object */
135
static struct winstation *create_winstation( struct object *root, const struct unicode_str *name,
136
                                             unsigned int attr, unsigned int flags )
137 138 139
{
    struct winstation *winstation;

140
    if ((winstation = create_named_object( root, &winstation_ops, name, attr, NULL )))
141
    {
142
        if (get_error() != STATUS_OBJECT_NAME_EXISTS)
143 144 145
        {
            /* initialize it if it didn't already exist */
            winstation->flags = flags;
146
            winstation->clipboard = NULL;
147
            winstation->atom_table = NULL;
148 149
            list_add_tail( &winstation_list, &winstation->entry );
            list_init( &winstation->desktops );
150 151 152 153 154
            if (!(winstation->desktop_names = create_namespace( 7 )))
            {
                release_object( winstation );
                return NULL;
            }
155
        }
156
        else clear_error();
157 158 159 160 161 162 163 164
    }
    return winstation;
}

static void winstation_dump( struct object *obj, int verbose )
{
    struct winstation *winstation = (struct winstation *)obj;

165
    fprintf( stderr, "Winstation flags=%x clipboard=%p atoms=%p\n",
166
             winstation->flags, winstation->clipboard, winstation->atom_table );
167 168
}

169 170 171 172 173
static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
{
    return (process->winstation != handle);
}

174
static struct object *winstation_lookup_name( struct object *obj, struct unicode_str *name,
175
                                              unsigned int attr, struct object *root )
176 177 178 179 180 181
{
    struct winstation *winstation = (struct winstation *)obj;
    struct object *found;

    assert( obj->ops == &winstation_ops );

182 183
    if (!name) return NULL;  /* open the winstation itself */

184
    if (get_path_element( name->str, name->len ) < name->len)  /* no backslash allowed in name */
185 186 187 188 189 190 191 192 193 194 195
    {
        set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
        return NULL;
    }

    if ((found = find_object( winstation->desktop_names, name, attr )))
        name->len = 0;

    return found;
}

196 197 198 199 200
static void winstation_destroy( struct object *obj )
{
    struct winstation *winstation = (struct winstation *)obj;

    list_remove( &winstation->entry );
201
    if (winstation->clipboard) release_object( winstation->clipboard );
202
    if (winstation->atom_table) release_object( winstation->atom_table );
203
    free( winstation->desktop_names );
204 205 206
}

/* retrieve the process window station, checking the handle access rights */
207
struct winstation *get_process_winstation( struct process *process, unsigned int access )
208 209 210 211 212
{
    return (struct winstation *)get_handle_obj( process, process->winstation,
                                                access, &winstation_ops );
}

213
/* retrieve a pointer to a desktop object */
214
struct desktop *get_desktop_obj( struct process *process, obj_handle_t handle, unsigned int access )
215 216 217 218
{
    return (struct desktop *)get_handle_obj( process, handle, access, &desktop_ops );
}

219
/* create a desktop object */
220 221
static struct desktop *create_desktop( const struct unicode_str *name, unsigned int attr,
                                       unsigned int flags, struct winstation *winstation )
222 223 224
{
    struct desktop *desktop;

225
    if ((desktop = create_named_object( &winstation->obj, &desktop_ops, name, attr, NULL )))
226
    {
227
        if (get_error() != STATUS_OBJECT_NAME_EXISTS)
228 229 230 231
        {
            /* initialize it if it didn't already exist */
            desktop->flags = flags;
            desktop->winstation = (struct winstation *)grab_object( winstation );
232
            desktop->top_window = NULL;
233
            desktop->msg_window = NULL;
234
            desktop->global_hooks = NULL;
235
            desktop->close_timeout = NULL;
236
            desktop->foreground_input = NULL;
237
            desktop->users = 0;
238
            memset( &desktop->cursor, 0, sizeof(desktop->cursor) );
239
            memset( desktop->keystate, 0, sizeof(desktop->keystate) );
240
            list_add_tail( &winstation->desktops, &desktop->entry );
241
            list_init( &desktop->hotkeys );
242
        }
243
        else clear_error();
244 245 246 247 248 249 250 251
    }
    return desktop;
}

static void desktop_dump( struct object *obj, int verbose )
{
    struct desktop *desktop = (struct desktop *)obj;

252
    fprintf( stderr, "Desktop flags=%x winstation=%p top_win=%p hooks=%p\n",
253
             desktop->flags, desktop->winstation, desktop->top_window, desktop->global_hooks );
254 255
}

256 257 258 259 260 261 262 263 264
static int desktop_link_name( struct object *obj, struct object_name *name, struct object *parent )
{
    struct winstation *winstation = (struct winstation *)parent;

    if (parent->ops != &winstation_ops)
    {
        set_error( STATUS_OBJECT_TYPE_MISMATCH );
        return 0;
    }
265
    if (get_path_element( name->name, name->len ) < name->len)  /* no backslash allowed in name */
266 267 268 269 270 271 272 273
    {
        set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
        return 0;
    }
    namespace_add( winstation->desktop_names, name );
    return 1;
}

274
static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
275
{
276
    struct thread *thread;
277

278 279 280 281 282
    /* 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;
283 284
}

285
static void desktop_destroy( struct object *obj )
286
{
287
    struct desktop *desktop = (struct desktop *)obj;
288

289
    free_hotkeys( desktop, 0 );
290 291
    if (desktop->top_window) free_window_handle( desktop->top_window );
    if (desktop->msg_window) free_window_handle( desktop->msg_window );
292
    if (desktop->global_hooks) release_object( desktop->global_hooks );
293
    if (desktop->close_timeout) remove_timeout_user( desktop->close_timeout );
294 295
    list_remove( &desktop->entry );
    release_object( desktop->winstation );
296 297
}

298 299 300 301 302 303
/* 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 );
}

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
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 */
    post_desktop_message( desktop, WM_CLOSE, 0, 0 );  /* and signal the owner to quit */
}

/* add a user of the desktop and cancel the close timeout */
static void add_desktop_user( struct desktop *desktop )
{
    desktop->users++;
    if (desktop->close_timeout)
    {
        remove_timeout_user( desktop->close_timeout );
        desktop->close_timeout = NULL;
    }
}

/* remove a user of the desktop and start the close timeout if necessary */
static void remove_desktop_user( struct desktop *desktop )
{
327
    struct process *process;
328 329 330 331
    assert( desktop->users > 0 );
    desktop->users--;

    /* if we have one remaining user, it has to be the manager of the desktop window */
332
    if ((process = get_top_window_owner( desktop )) && desktop->users == process->running_threads && !desktop->close_timeout)
333
        desktop->close_timeout = add_timeout_user( -TICKS_PER_SEC, close_desktop_timeout, desktop );
334 335 336 337 338 339 340 341 342
}

/* set the thread default desktop handle */
void set_thread_default_desktop( struct thread *thread, struct desktop *desktop, obj_handle_t handle )
{
    if (thread->desktop) return;  /* nothing to do */

    thread->desktop = handle;
    if (!thread->process->is_system) add_desktop_user( desktop );
343 344
}

345 346 347
/* set the process default desktop handle */
void set_process_default_desktop( struct process *process, struct desktop *desktop,
                                  obj_handle_t handle )
348
{
349
    struct thread *thread;
350

351
    if (process->desktop == handle) return;  /* nothing to do */
352

353
    process->desktop = handle;
354

355 356
    /* set desktop for threads that don't have one yet */
    LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
357
        set_thread_default_desktop( thread, desktop, handle );
358 359
}

360
/* connect a process to its window station */
361 362
void connect_process_winstation( struct process *process, struct thread *parent_thread,
                                 struct process *parent_process )
363
{
364 365 366
    struct winstation *winstation = NULL;
    struct desktop *desktop = NULL;
    obj_handle_t handle;
367

368 369 370 371 372
    /* check for an inherited winstation handle (don't ask...) */
    if ((handle = find_inherited_handle( process, &winstation_ops )))
    {
        winstation = (struct winstation *)get_handle_obj( process, handle, 0, &winstation_ops );
    }
373
    else if (parent_process->winstation)
374
    {
375
        handle = duplicate_handle( parent_process, parent_process->winstation,
376
                                   process, 0, 0, DUPLICATE_SAME_ACCESS );
377 378 379 380
        winstation = (struct winstation *)get_handle_obj( process, handle, 0, &winstation_ops );
    }
    if (!winstation) goto done;
    process->winstation = handle;
381

382 383 384 385
    if ((handle = find_inherited_handle( process, &desktop_ops )))
    {
        desktop = get_desktop_obj( process, handle, 0 );
        if (!desktop || desktop->winstation != winstation) goto done;
386
    }
387
    else
388
    {
389 390 391 392 393 394 395 396 397
        if (parent_thread && parent_thread->desktop)
            handle = parent_thread->desktop;
        else if (parent_process->desktop)
            handle = parent_process->desktop;
        else
            goto done;

        desktop = get_desktop_obj( parent_process, handle, 0 );

398 399
        if (!desktop || desktop->winstation != winstation) goto done;

400
        handle = duplicate_handle( parent_process, handle, process, 0, 0, DUPLICATE_SAME_ACCESS );
401
    }
402 403 404 405 406 407
    if (handle) set_process_default_desktop( process, desktop, handle );

done:
    if (desktop) release_object( desktop );
    if (winstation) release_object( winstation );
    clear_error();
408 409
}

410 411 412
/* close the desktop of a given process */
void close_process_desktop( struct process *process )
{
413
    obj_handle_t handle;
414

415 416 417 418
    if (!(handle = process->desktop)) return;

    process->desktop = 0;
    close_handle( process, handle );
419 420
}

421 422
/* release (and eventually close) the desktop of a given thread */
void release_thread_desktop( struct thread *thread, int close )
423
{
424 425 426 427 428 429 430 431 432 433 434 435 436 437
    struct desktop *desktop;
    obj_handle_t handle;

    if (!(handle = thread->desktop)) return;

    if (!thread->process->is_system)
    {
        if (!(desktop = get_desktop_obj( thread->process, handle, 0 ))) clear_error();  /* ignore errors */
        else
        {
            remove_desktop_user( desktop );
            release_object( desktop );
        }
    }
438

439 440 441 442 443
    if (close)
    {
        thread->desktop = 0;
        close_handle( thread->process, handle );
    }
444 445 446 447 448 449
}

/* create a window station */
DECL_HANDLER(create_winstation)
{
    struct winstation *winstation;
450
    struct unicode_str name = get_req_unicode_str();
451
    struct object *root = NULL;
452 453

    reply->handle = 0;
454
    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir ))) return;
455 456

    if ((winstation = create_winstation( root, &name, req->attributes, req->flags )))
457
    {
458
        reply->handle = alloc_handle( current->process, winstation, req->access, req->attributes );
459 460
        release_object( winstation );
    }
461
    if (root) release_object( root );
462 463 464 465 466
}

/* open a handle to a window station */
DECL_HANDLER(open_winstation)
{
467
    struct unicode_str name = get_req_unicode_str();
468

469 470
    reply->handle = open_object( current->process, req->rootdir, req->access,
                                 &winstation_ops, &name, req->attributes );
471 472 473 474 475 476 477 478 479 480 481
}


/* 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 )))
    {
482
        if (close_handle( current->process, req->handle )) set_error( STATUS_ACCESS_DENIED );
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
        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;
514
    struct unicode_str name = get_req_unicode_str();
515 516

    reply->handle = 0;
517 518 519 520 521
    if (!name.len)
    {
        set_error( STATUS_INVALID_HANDLE );
        return;
    }
522 523
    if ((winstation = get_process_winstation( current->process, WINSTA_CREATEDESKTOP )))
    {
524
        if ((desktop = create_desktop( &name, req->attributes, req->flags, winstation )))
525
        {
526
            reply->handle = alloc_handle( current->process, desktop, req->access, req->attributes );
527 528 529 530 531 532 533 534 535 536
            release_object( desktop );
        }
        release_object( winstation );
    }
}

/* open a handle to a desktop */
DECL_HANDLER(open_desktop)
{
    struct winstation *winstation;
537
    struct object *obj;
538
    struct unicode_str name = get_req_unicode_str();
539 540 541 542 543 544 545

    /* FIXME: check access rights */
    if (!req->winsta)
        winstation = get_process_winstation( current->process, 0 );
    else
        winstation = (struct winstation *)get_handle_obj( current->process, req->winsta, 0, &winstation_ops );

546 547
    if (!winstation) return;

548
    if ((obj = open_named_object( &winstation->obj, &desktop_ops, &name, req->attributes )))
549
    {
550 551
        reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
        release_object( obj );
552
    }
553 554

    release_object( winstation );
555 556
}

557 558 559 560 561 562 563 564 565 566 567 568
/* open a handle to current input desktop */
DECL_HANDLER(open_input_desktop)
{
    /* FIXME: check access rights */
    struct winstation *winstation = get_process_winstation( current->process, 0 );
    struct desktop *desktop;

    if (!winstation) return;

    if (!(winstation->flags & WSF_VISIBLE))
    {
        set_error( STATUS_ILLEGAL_FUNCTION );
569
        release_object( winstation );
570 571 572 573 574 575 576 577 578 579
        return;
    }

    if ((desktop = get_desktop_obj( current->process, current->process->desktop, 0 )))
    {
        reply->handle = alloc_handle( current->process, desktop, req->access, req->attributes );
        release_object( desktop );
    }
    release_object( winstation );
}
580 581 582 583 584 585 586 587 588 589

/* 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 )))
    {
590
        if (close_handle( current->process, req->handle )) set_error( STATUS_DEVICE_BUSY );
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
        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)
{
610 611
    struct desktop *old_desktop, *new_desktop;
    struct winstation *winstation;
612

613 614 615 616
    if (!(winstation = get_process_winstation( current->process, 0 /* FIXME: access rights? */ )))
        return;

    if (!(new_desktop = get_desktop_obj( current->process, req->handle, 0 )))
617
    {
618 619
        release_object( winstation );
        return;
620
    }
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
    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
638
    {
639
        current->desktop = req->handle;  /* FIXME: should we close the old one? */
640 641 642 643 644 645
        if (!current->process->is_system && old_desktop != new_desktop)
        {
            add_desktop_user( new_desktop );
            if (old_desktop) remove_desktop_user( old_desktop );
        }
    }
646

647 648 649
    if (!current->process->desktop)
        set_process_default_desktop( current->process, new_desktop, req->handle );

650
    if (old_desktop != new_desktop && current->queue) detach_thread_input( current );
651

652 653 654
    if (old_desktop) release_object( old_desktop );
    release_object( new_desktop );
    release_object( winstation );
655 656 657 658 659 660 661
}


/* get/set information about a user object (window station or desktop) */
DECL_HANDLER(set_user_object_info)
{
    struct object *obj;
662
    data_size_t len;
663 664 665 666 667 668 669 670

    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;
671
        if (req->flags & SET_USER_OBJECT_SET_FLAGS) desktop->flags = req->obj_flags;
672 673 674 675 676 677
    }
    else if (obj->ops == &winstation_ops)
    {
        struct winstation *winstation = (struct winstation *)obj;
        reply->is_desktop = 0;
        reply->old_obj_flags = winstation->flags;
678
        if (req->flags & SET_USER_OBJECT_SET_FLAGS) winstation->flags = req->obj_flags;
679 680 681 682 683 684 685
    }
    else
    {
        set_error( STATUS_OBJECT_TYPE_MISMATCH );
        release_object( obj );
        return;
    }
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
    if (obj->ops == &desktop_ops && get_reply_max_size() && (req->flags & SET_USER_OBJECT_GET_FULL_NAME))
    {
        struct desktop *desktop = (struct desktop *)obj;
        data_size_t winstation_len, desktop_len;
        const WCHAR *winstation_name = get_object_name( &desktop->winstation->obj, &winstation_len );
        const WCHAR *desktop_name = get_object_name( obj, &desktop_len );
        WCHAR *full_name;

        if (!winstation_name) winstation_len = 0;
        if (!desktop_name) desktop_len = 0;
        len = winstation_len + desktop_len + sizeof(WCHAR);
        if ((full_name = mem_alloc( len )))
        {
            memcpy( full_name, winstation_name, winstation_len );
            full_name[winstation_len / sizeof(WCHAR)] = '\\';
            memcpy( full_name + winstation_len / sizeof(WCHAR) + 1, desktop_name, desktop_len );
            set_reply_data_ptr( full_name, min( len, get_reply_max_size() ));
        }
    }
    else
    {
        const WCHAR *name = get_object_name( obj, &len );
        if (name) set_reply_data( name, min( len, get_reply_max_size() ));
    }
710 711 712 713 714 715 716
    release_object( obj );
}


/* enumerate window stations */
DECL_HANDLER(enum_winstation)
{
717 718
    unsigned int index = 0;
    struct winstation *winsta;
719 720
    const WCHAR *name;
    data_size_t len;
721

722
    LIST_FOR_EACH_ENTRY( winsta, &winstation_list, struct winstation, entry )
723
    {
724 725
        unsigned int access = WINSTA_ENUMERATE;
        if (req->index > index++) continue;
726
        if (!check_object_access( NULL, &winsta->obj, &access )) continue;
727 728
        clear_error();
        reply->next = index;
729 730
        if ((name = get_object_name( &winsta->obj, &len )))
            set_reply_data( name, min( len, get_reply_max_size() ));
731 732 733 734 735 736 737 738 739 740 741
        return;
    }
    set_error( STATUS_NO_MORE_ENTRIES );
}


/* enumerate desktops */
DECL_HANDLER(enum_desktop)
{
    struct winstation *winstation;
    struct desktop *desktop;
742
    unsigned int index = 0;
743 744
    const WCHAR *name;
    data_size_t len;
745 746 747 748 749

    if (!(winstation = (struct winstation *)get_handle_obj( current->process, req->winstation,
                                                            WINSTA_ENUMDESKTOPS, &winstation_ops )))
        return;

750
    LIST_FOR_EACH_ENTRY( desktop, &winstation->desktops, struct desktop, entry )
751
    {
752 753 754
        unsigned int access = DESKTOP_ENUMERATE;
        if (req->index > index++) continue;
        if (!desktop->obj.name) continue;
755
        if (!check_object_access( NULL, &desktop->obj, &access )) continue;
756 757
        if ((name = get_object_name( &desktop->obj, &len )))
            set_reply_data( name, min( len, get_reply_max_size() ));
758 759 760 761
        release_object( winstation );
        clear_error();
        reply->next = index;
        return;
762
    }
763 764 765

    release_object( winstation );
    set_error( STATUS_NO_MORE_ENTRIES );
766
}