winstation.c 25.6 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 25 26
 */

#include "config.h"
#include "wine/port.h"

#include <stdio.h>
#include <stdarg.h>

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 43 44 45 46
#include "wine/unicode.h"


static struct list winstation_list = LIST_INIT(winstation_list);

static void winstation_dump( struct object *obj, int verbose );
47
static struct object_type *winstation_get_type( struct object *obj );
48
static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
49 50
static struct object *winstation_lookup_name( struct object *obj, struct unicode_str *name,
                                              unsigned int attr );
51
static void winstation_destroy( struct object *obj );
52
static unsigned int winstation_map_access( struct object *obj, unsigned int access );
53
static void desktop_dump( struct object *obj, int verbose );
54
static struct object_type *desktop_get_type( struct object *obj );
55
static int desktop_link_name( struct object *obj, struct object_name *name, struct object *parent );
56
static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
57
static void desktop_destroy( struct object *obj );
58
static unsigned int desktop_map_access( struct object *obj, unsigned int access );
59 60 61 62 63

static const struct object_ops winstation_ops =
{
    sizeof(struct winstation),    /* size */
    winstation_dump,              /* dump */
64
    winstation_get_type,          /* get_type */
65 66 67 68 69 70
    no_add_queue,                 /* add_queue */
    NULL,                         /* remove_queue */
    NULL,                         /* signaled */
    NULL,                         /* satisfied */
    no_signal,                    /* signal */
    no_get_fd,                    /* get_fd */
71
    winstation_map_access,        /* map_access */
72 73
    default_get_sd,               /* get_sd */
    default_set_sd,               /* set_sd */
74
    winstation_lookup_name,       /* lookup_name */
75 76
    directory_link_name,          /* link_name */
    default_unlink_name,          /* unlink_name */
77
    no_open_file,                 /* open_file */
78
    no_kernel_obj_list,           /* get_kernel_obj_list */
79
    winstation_close_handle,      /* close_handle */
80 81 82 83 84 85 86 87
    winstation_destroy            /* destroy */
};


static const struct object_ops desktop_ops =
{
    sizeof(struct desktop),       /* size */
    desktop_dump,                 /* dump */
88
    desktop_get_type,             /* get_type */
89 90 91 92 93 94
    no_add_queue,                 /* add_queue */
    NULL,                         /* remove_queue */
    NULL,                         /* signaled */
    NULL,                         /* satisfied */
    no_signal,                    /* signal */
    no_get_fd,                    /* get_fd */
95
    desktop_map_access,           /* map_access */
96 97
    default_get_sd,               /* get_sd */
    default_set_sd,               /* set_sd */
98
    no_lookup_name,               /* lookup_name */
99 100
    desktop_link_name,            /* link_name */
    default_unlink_name,          /* unlink_name */
101
    no_open_file,                 /* open_file */
102
    no_kernel_obj_list,           /* get_kernel_obj_list */
103
    desktop_close_handle,         /* close_handle */
104 105 106 107 108 109
    desktop_destroy               /* destroy */
};

#define DESKTOP_ALL_ACCESS 0x01ff

/* create a winstation object */
110
static struct winstation *create_winstation( struct object *root, const struct unicode_str *name,
111
                                             unsigned int attr, unsigned int flags )
112 113 114
{
    struct winstation *winstation;

115
    if ((winstation = create_named_object( root, &winstation_ops, name, attr, NULL )))
116
    {
117
        if (get_error() != STATUS_OBJECT_NAME_EXISTS)
118 119 120
        {
            /* initialize it if it didn't already exist */
            winstation->flags = flags;
121
            winstation->clipboard = NULL;
122
            winstation->atom_table = NULL;
123 124
            list_add_tail( &winstation_list, &winstation->entry );
            list_init( &winstation->desktops );
125 126 127 128 129
            if (!(winstation->desktop_names = create_namespace( 7 )))
            {
                release_object( winstation );
                return NULL;
            }
130
        }
131
        else clear_error();
132 133 134 135 136 137 138 139
    }
    return winstation;
}

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

140
    fprintf( stderr, "Winstation flags=%x clipboard=%p atoms=%p\n",
141
             winstation->flags, winstation->clipboard, winstation->atom_table );
142 143
}

144 145 146 147 148 149 150
static struct object_type *winstation_get_type( struct object *obj )
{
    static const WCHAR name[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n'};
    static const struct unicode_str str = { name, sizeof(name) };
    return get_object_type( &str );
}

151 152 153 154 155
static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
{
    return (process->winstation != handle);
}

156 157 158 159 160 161 162 163
static struct object *winstation_lookup_name( struct object *obj, struct unicode_str *name,
                                              unsigned int attr )
{
    struct winstation *winstation = (struct winstation *)obj;
    struct object *found;

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

164 165
    if (!name) return NULL;  /* open the winstation itself */

166 167 168 169 170 171 172 173 174 175 176 177
    if (memchrW( name->str, '\\', name->len / sizeof(WCHAR) ))  /* no backslash allowed in name */
    {
        set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
        return NULL;
    }

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

    return found;
}

178 179 180 181 182
static void winstation_destroy( struct object *obj )
{
    struct winstation *winstation = (struct winstation *)obj;

    list_remove( &winstation->entry );
183
    if (winstation->clipboard) release_object( winstation->clipboard );
184
    if (winstation->atom_table) release_object( winstation->atom_table );
185
    free( winstation->desktop_names );
186 187
}

188 189 190 191 192 193 194 195 196 197 198
static unsigned int winstation_map_access( struct object *obj, unsigned int access )
{
    if (access & GENERIC_READ)    access |= STANDARD_RIGHTS_READ | WINSTA_ENUMDESKTOPS | WINSTA_READATTRIBUTES |
                                            WINSTA_ENUMERATE | WINSTA_READSCREEN;
    if (access & GENERIC_WRITE)   access |= STANDARD_RIGHTS_WRITE | WINSTA_ACCESSCLIPBOARD | WINSTA_CREATEDESKTOP |
                                            WINSTA_WRITEATTRIBUTES;
    if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE | WINSTA_ACCESSGLOBALATOMS | WINSTA_EXITWINDOWS;
    if (access & GENERIC_ALL)     access |= STANDARD_RIGHTS_REQUIRED | WINSTA_ALL_ACCESS;
    return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
}

199
/* retrieve the process window station, checking the handle access rights */
200
struct winstation *get_process_winstation( struct process *process, unsigned int access )
201 202 203 204 205
{
    return (struct winstation *)get_handle_obj( process, process->winstation,
                                                access, &winstation_ops );
}

206
/* retrieve a pointer to a desktop object */
207
struct desktop *get_desktop_obj( struct process *process, obj_handle_t handle, unsigned int access )
208 209 210 211
{
    return (struct desktop *)get_handle_obj( process, handle, access, &desktop_ops );
}

212
/* create a desktop object */
213 214
static struct desktop *create_desktop( const struct unicode_str *name, unsigned int attr,
                                       unsigned int flags, struct winstation *winstation )
215 216 217
{
    struct desktop *desktop;

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

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

245
    fprintf( stderr, "Desktop flags=%x winstation=%p top_win=%p hooks=%p\n",
246
             desktop->flags, desktop->winstation, desktop->top_window, desktop->global_hooks );
247 248
}

249 250 251 252 253 254 255
static struct object_type *desktop_get_type( struct object *obj )
{
    static const WCHAR name[] = {'D','e','s','k','t','o','p'};
    static const struct unicode_str str = { name, sizeof(name) };
    return get_object_type( &str );
}

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
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;
    }
    if (memchrW( name->name, '\\', name->len / sizeof(WCHAR) ))  /* no backslash allowed in name */
    {
        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
    if (desktop->top_window) destroy_window( desktop->top_window );
291
    if (desktop->msg_window) destroy_window( 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 304 305 306 307 308
static unsigned int desktop_map_access( struct object *obj, unsigned int access )
{
    if (access & GENERIC_READ)    access |= STANDARD_RIGHTS_READ | DESKTOP_READOBJECTS | DESKTOP_ENUMERATE;
    if (access & GENERIC_WRITE)   access |= STANDARD_RIGHTS_WRITE | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
                                            DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
                                            DESKTOP_WRITEOBJECTS;
    if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE | DESKTOP_SWITCHDESKTOP;
    if (access & GENERIC_ALL)     access |= STANDARD_RIGHTS_REQUIRED | DESKTOP_ALL_ACCESS;
    return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
}

309 310 311 312 313 314
/* 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 );
}

315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
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 )
{
    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 ))
    {
        assert( !desktop->close_timeout );
        desktop->close_timeout = add_timeout_user( -TICKS_PER_SEC, close_desktop_timeout, desktop );
    }
}

349 350 351
/* set the process default desktop handle */
void set_process_default_desktop( struct process *process, struct desktop *desktop,
                                  obj_handle_t handle )
352
{
353 354
    struct thread *thread;
    struct desktop *old_desktop;
355

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

358 359
    if (!(old_desktop = get_desktop_obj( process, process->desktop, 0 ))) clear_error();
    process->desktop = handle;
360

361 362 363 364
    /* set desktop for threads that don't have one yet */
    LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
        if (!thread->desktop) thread->desktop = handle;

365
    if (!process->is_system && desktop != old_desktop)
366
    {
367 368
        add_desktop_user( desktop );
        if (old_desktop) remove_desktop_user( old_desktop );
369
    }
370 371

    if (old_desktop) release_object( old_desktop );
372 373
}

374 375
/* connect a process to its window station */
void connect_process_winstation( struct process *process, struct thread *parent )
376
{
377 378 379
    struct winstation *winstation = NULL;
    struct desktop *desktop = NULL;
    obj_handle_t handle;
380

381 382 383 384 385 386
    /* 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 );
    }
    else if (parent && parent->process->winstation)
387
    {
388 389 390 391 392 393
        handle = duplicate_handle( parent->process, parent->process->winstation,
                                   process, 0, 0, DUP_HANDLE_SAME_ACCESS );
        winstation = (struct winstation *)get_handle_obj( process, handle, 0, &winstation_ops );
    }
    if (!winstation) goto done;
    process->winstation = handle;
394

395 396 397 398
    if ((handle = find_inherited_handle( process, &desktop_ops )))
    {
        desktop = get_desktop_obj( process, handle, 0 );
        if (!desktop || desktop->winstation != winstation) goto done;
399
    }
400 401 402 403 404 405 406 407 408 409 410 411 412 413
    else if (parent && parent->desktop)
    {
        desktop = get_desktop_obj( parent->process, parent->desktop, 0 );
        if (!desktop || desktop->winstation != winstation) goto done;
        handle = duplicate_handle( parent->process, parent->desktop,
                                   process, 0, 0, DUP_HANDLE_SAME_ACCESS );
    }

    if (handle) set_process_default_desktop( process, desktop, handle );

done:
    if (desktop) release_object( desktop );
    if (winstation) release_object( winstation );
    clear_error();
414 415
}

416 417 418 419 420 421 422
/* 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 )))
    {
423
        remove_desktop_user( desktop );
424 425 426 427 428
        release_object( desktop );
    }
    clear_error();  /* ignore errors */
}

429 430 431 432 433 434
/* close the desktop of a given thread */
void close_thread_desktop( struct thread *thread )
{
    obj_handle_t handle = thread->desktop;

    thread->desktop = 0;
435
    if (handle) close_handle( thread->process, handle );
436 437 438 439 440 441
}

/* create a window station */
DECL_HANDLER(create_winstation)
{
    struct winstation *winstation;
442
    struct unicode_str name = get_req_unicode_str();
443
    struct object *root = NULL;
444 445

    reply->handle = 0;
446
    if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir ))) return;
447 448

    if ((winstation = create_winstation( root, &name, req->attributes, req->flags )))
449
    {
450
        reply->handle = alloc_handle( current->process, winstation, req->access, req->attributes );
451 452
        release_object( winstation );
    }
453
    if (root) release_object( root );
454 455 456 457 458
}

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

461 462
    reply->handle = open_object( current->process, req->rootdir, req->access,
                                 &winstation_ops, &name, req->attributes );
463 464 465 466 467 468 469 470 471 472 473
}


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

    reply->handle = 0;
    if ((winstation = get_process_winstation( current->process, WINSTA_CREATEDESKTOP )))
    {
511
        if ((desktop = create_desktop( &name, req->attributes, req->flags, winstation )))
512
        {
513
            reply->handle = alloc_handle( current->process, desktop, req->access, req->attributes );
514 515 516 517 518 519 520 521 522 523
            release_object( desktop );
        }
        release_object( winstation );
    }
}

/* open a handle to a desktop */
DECL_HANDLER(open_desktop)
{
    struct winstation *winstation;
524
    struct object *obj;
525
    struct unicode_str name = get_req_unicode_str();
526 527 528 529 530 531 532

    /* 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 );

533 534
    if (!winstation) return;

535
    if ((obj = open_named_object( &winstation->obj, &desktop_ops, &name, req->attributes )))
536
    {
537 538
        reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
        release_object( obj );
539
    }
540 541

    release_object( winstation );
542 543
}

544 545 546 547 548 549 550 551 552 553 554 555
/* 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 );
556
        release_object( winstation );
557 558 559 560 561 562 563 564 565 566
        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 );
}
567 568 569 570 571 572 573 574 575 576

/* 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 )))
    {
577
        if (close_handle( current->process, req->handle )) set_error( STATUS_DEVICE_BUSY );
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
        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)
{
597 598
    struct desktop *old_desktop, *new_desktop;
    struct winstation *winstation;
599

600 601 602 603
    if (!(winstation = get_process_winstation( current->process, 0 /* FIXME: access rights? */ )))
        return;

    if (!(new_desktop = get_desktop_obj( current->process, req->handle, 0 )))
604
    {
605 606
        release_object( winstation );
        return;
607
    }
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
    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? */

627 628 629
    if (!current->process->desktop)
        set_process_default_desktop( current->process, new_desktop, req->handle );

630
    if (old_desktop != new_desktop && current->queue) detach_thread_input( current );
631

632 633 634
    if (old_desktop) release_object( old_desktop );
    release_object( new_desktop );
    release_object( winstation );
635 636 637 638 639 640 641
}


/* get/set information about a user object (window station or desktop) */
DECL_HANDLER(set_user_object_info)
{
    struct object *obj;
642
    data_size_t len;
643 644 645 646 647 648 649 650

    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;
651
        if (req->flags & SET_USER_OBJECT_SET_FLAGS) desktop->flags = req->obj_flags;
652 653 654 655 656 657
    }
    else if (obj->ops == &winstation_ops)
    {
        struct winstation *winstation = (struct winstation *)obj;
        reply->is_desktop = 0;
        reply->old_obj_flags = winstation->flags;
658
        if (req->flags & SET_USER_OBJECT_SET_FLAGS) winstation->flags = req->obj_flags;
659 660 661 662 663 664 665
    }
    else
    {
        set_error( STATUS_OBJECT_TYPE_MISMATCH );
        release_object( obj );
        return;
    }
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
    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() ));
    }
690 691 692 693 694 695 696
    release_object( obj );
}


/* enumerate window stations */
DECL_HANDLER(enum_winstation)
{
697 698
    unsigned int index = 0;
    struct winstation *winsta;
699 700
    const WCHAR *name;
    data_size_t len;
701

702
    LIST_FOR_EACH_ENTRY( winsta, &winstation_list, struct winstation, entry )
703
    {
704 705 706
        unsigned int access = WINSTA_ENUMERATE;
        if (req->index > index++) continue;
        if (!check_object_access( &winsta->obj, &access )) continue;
707 708
        clear_error();
        reply->next = index;
709 710
        if ((name = get_object_name( &winsta->obj, &len )))
            set_reply_data( name, min( len, get_reply_max_size() ));
711 712 713 714 715 716 717 718 719 720 721
        return;
    }
    set_error( STATUS_NO_MORE_ENTRIES );
}


/* enumerate desktops */
DECL_HANDLER(enum_desktop)
{
    struct winstation *winstation;
    struct desktop *desktop;
722
    unsigned int index = 0;
723 724
    const WCHAR *name;
    data_size_t len;
725 726 727 728 729

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

730
    LIST_FOR_EACH_ENTRY( desktop, &winstation->desktops, struct desktop, entry )
731
    {
732 733 734 735
        unsigned int access = DESKTOP_ENUMERATE;
        if (req->index > index++) continue;
        if (!desktop->obj.name) continue;
        if (!check_object_access( &desktop->obj, &access )) continue;
736 737
        if ((name = get_object_name( &desktop->obj, &len )))
            set_reply_data( name, min( len, get_reply_max_size() ));
738 739 740 741
        release_object( winstation );
        clear_error();
        reply->next = index;
        return;
742
    }
743 744 745

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