winstation.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * Server-side window stations and desktops handling
  3. *
  4. * Copyright (C) 2002, 2005 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * 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. #include "config.h"
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. #include <sys/types.h>
  24. #include "ntstatus.h"
  25. #define WIN32_NO_STATUS
  26. #include "windef.h"
  27. #include "winbase.h"
  28. #include "winuser.h"
  29. #include "winternl.h"
  30. #include "ntuser.h"
  31. #include "object.h"
  32. #include "handle.h"
  33. #include "request.h"
  34. #include "process.h"
  35. #include "user.h"
  36. #include "file.h"
  37. #include "security.h"
  38. #define DESKTOP_ALL_ACCESS 0x01ff
  39. static struct list winstation_list = LIST_INIT(winstation_list);
  40. static void winstation_dump( struct object *obj, int verbose );
  41. static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
  42. static struct object *winstation_lookup_name( struct object *obj, struct unicode_str *name,
  43. unsigned int attr, struct object *root );
  44. static void winstation_destroy( struct object *obj );
  45. static void desktop_dump( struct object *obj, int verbose );
  46. static int desktop_link_name( struct object *obj, struct object_name *name, struct object *parent );
  47. static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
  48. static void desktop_destroy( struct object *obj );
  49. static const WCHAR winstation_name[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n'};
  50. struct type_descr winstation_type =
  51. {
  52. { winstation_name, sizeof(winstation_name) }, /* name */
  53. STANDARD_RIGHTS_REQUIRED | WINSTA_ALL_ACCESS, /* valid_access */
  54. { /* mapping */
  55. STANDARD_RIGHTS_READ | WINSTA_READSCREEN | WINSTA_ENUMERATE | WINSTA_READATTRIBUTES | WINSTA_ENUMDESKTOPS,
  56. STANDARD_RIGHTS_WRITE | WINSTA_WRITEATTRIBUTES | WINSTA_CREATEDESKTOP | WINSTA_ACCESSCLIPBOARD,
  57. STANDARD_RIGHTS_EXECUTE | WINSTA_EXITWINDOWS | WINSTA_ACCESSGLOBALATOMS,
  58. STANDARD_RIGHTS_REQUIRED | WINSTA_ALL_ACCESS
  59. },
  60. };
  61. static const struct object_ops winstation_ops =
  62. {
  63. sizeof(struct winstation), /* size */
  64. &winstation_type, /* type */
  65. winstation_dump, /* dump */
  66. no_add_queue, /* add_queue */
  67. NULL, /* remove_queue */
  68. NULL, /* signaled */
  69. NULL, /* satisfied */
  70. no_signal, /* signal */
  71. no_get_fd, /* get_fd */
  72. default_map_access, /* map_access */
  73. default_get_sd, /* get_sd */
  74. default_set_sd, /* set_sd */
  75. default_get_full_name, /* get_full_name */
  76. winstation_lookup_name, /* lookup_name */
  77. directory_link_name, /* link_name */
  78. default_unlink_name, /* unlink_name */
  79. no_open_file, /* open_file */
  80. no_kernel_obj_list, /* get_kernel_obj_list */
  81. no_get_fast_sync, /* get_fast_sync */
  82. winstation_close_handle, /* close_handle */
  83. winstation_destroy /* destroy */
  84. };
  85. static const WCHAR desktop_name[] = {'D','e','s','k','t','o','p'};
  86. struct type_descr desktop_type =
  87. {
  88. { desktop_name, sizeof(desktop_name) }, /* name */
  89. STANDARD_RIGHTS_REQUIRED | DESKTOP_ALL_ACCESS, /* valid_access */
  90. { /* mapping */
  91. STANDARD_RIGHTS_READ | DESKTOP_ENUMERATE | DESKTOP_READOBJECTS,
  92. STANDARD_RIGHTS_WRITE | DESKTOP_WRITEOBJECTS | DESKTOP_JOURNALPLAYBACK | DESKTOP_JOURNALRECORD
  93. | DESKTOP_HOOKCONTROL | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW,
  94. STANDARD_RIGHTS_EXECUTE | DESKTOP_SWITCHDESKTOP,
  95. STANDARD_RIGHTS_REQUIRED | DESKTOP_ALL_ACCESS
  96. },
  97. };
  98. static const struct object_ops desktop_ops =
  99. {
  100. sizeof(struct desktop), /* size */
  101. &desktop_type, /* type */
  102. desktop_dump, /* dump */
  103. no_add_queue, /* add_queue */
  104. NULL, /* remove_queue */
  105. NULL, /* signaled */
  106. NULL, /* satisfied */
  107. no_signal, /* signal */
  108. no_get_fd, /* get_fd */
  109. default_map_access, /* map_access */
  110. default_get_sd, /* get_sd */
  111. default_set_sd, /* set_sd */
  112. default_get_full_name, /* get_full_name */
  113. no_lookup_name, /* lookup_name */
  114. desktop_link_name, /* link_name */
  115. default_unlink_name, /* unlink_name */
  116. no_open_file, /* open_file */
  117. no_kernel_obj_list, /* get_kernel_obj_list */
  118. no_get_fast_sync, /* get_fast_sync */
  119. desktop_close_handle, /* close_handle */
  120. desktop_destroy /* destroy */
  121. };
  122. /* create a winstation object */
  123. static struct winstation *create_winstation( struct object *root, const struct unicode_str *name,
  124. unsigned int attr, unsigned int flags )
  125. {
  126. struct winstation *winstation;
  127. if ((winstation = create_named_object( root, &winstation_ops, name, attr, NULL )))
  128. {
  129. if (get_error() != STATUS_OBJECT_NAME_EXISTS)
  130. {
  131. /* initialize it if it didn't already exist */
  132. winstation->flags = flags;
  133. winstation->clipboard = NULL;
  134. winstation->atom_table = NULL;
  135. list_add_tail( &winstation_list, &winstation->entry );
  136. list_init( &winstation->desktops );
  137. if (!(winstation->desktop_names = create_namespace( 7 )))
  138. {
  139. release_object( winstation );
  140. return NULL;
  141. }
  142. }
  143. else clear_error();
  144. }
  145. return winstation;
  146. }
  147. static void winstation_dump( struct object *obj, int verbose )
  148. {
  149. struct winstation *winstation = (struct winstation *)obj;
  150. fprintf( stderr, "Winstation flags=%x clipboard=%p atoms=%p\n",
  151. winstation->flags, winstation->clipboard, winstation->atom_table );
  152. }
  153. static int winstation_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
  154. {
  155. return (process->winstation != handle);
  156. }
  157. static struct object *winstation_lookup_name( struct object *obj, struct unicode_str *name,
  158. unsigned int attr, struct object *root )
  159. {
  160. struct winstation *winstation = (struct winstation *)obj;
  161. struct object *found;
  162. assert( obj->ops == &winstation_ops );
  163. if (!name) return NULL; /* open the winstation itself */
  164. if (get_path_element( name->str, name->len ) < name->len) /* no backslash allowed in name */
  165. {
  166. set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
  167. return NULL;
  168. }
  169. if ((found = find_object( winstation->desktop_names, name, attr )))
  170. name->len = 0;
  171. return found;
  172. }
  173. static void winstation_destroy( struct object *obj )
  174. {
  175. struct winstation *winstation = (struct winstation *)obj;
  176. list_remove( &winstation->entry );
  177. if (winstation->clipboard) release_object( winstation->clipboard );
  178. if (winstation->atom_table) release_object( winstation->atom_table );
  179. free( winstation->desktop_names );
  180. }
  181. /* retrieve the process window station, checking the handle access rights */
  182. struct winstation *get_process_winstation( struct process *process, unsigned int access )
  183. {
  184. return (struct winstation *)get_handle_obj( process, process->winstation,
  185. access, &winstation_ops );
  186. }
  187. /* retrieve a pointer to a desktop object */
  188. struct desktop *get_desktop_obj( struct process *process, obj_handle_t handle, unsigned int access )
  189. {
  190. return (struct desktop *)get_handle_obj( process, handle, access, &desktop_ops );
  191. }
  192. /* create a desktop object */
  193. static struct desktop *create_desktop( const struct unicode_str *name, unsigned int attr,
  194. unsigned int flags, struct winstation *winstation )
  195. {
  196. struct desktop *desktop;
  197. if ((desktop = create_named_object( &winstation->obj, &desktop_ops, name, attr, NULL )))
  198. {
  199. if (get_error() != STATUS_OBJECT_NAME_EXISTS)
  200. {
  201. /* initialize it if it didn't already exist */
  202. desktop->flags = flags;
  203. desktop->winstation = (struct winstation *)grab_object( winstation );
  204. desktop->top_window = NULL;
  205. desktop->msg_window = NULL;
  206. desktop->global_hooks = NULL;
  207. desktop->close_timeout = NULL;
  208. desktop->foreground_input = NULL;
  209. desktop->users = 0;
  210. memset( &desktop->cursor, 0, sizeof(desktop->cursor) );
  211. memset( desktop->keystate, 0, sizeof(desktop->keystate) );
  212. list_add_tail( &winstation->desktops, &desktop->entry );
  213. list_init( &desktop->hotkeys );
  214. }
  215. else
  216. {
  217. desktop->flags |= (flags & DF_WINE_CREATE_DESKTOP);
  218. clear_error();
  219. }
  220. }
  221. return desktop;
  222. }
  223. static void desktop_dump( struct object *obj, int verbose )
  224. {
  225. struct desktop *desktop = (struct desktop *)obj;
  226. fprintf( stderr, "Desktop flags=%x winstation=%p top_win=%p hooks=%p\n",
  227. desktop->flags, desktop->winstation, desktop->top_window, desktop->global_hooks );
  228. }
  229. static int desktop_link_name( struct object *obj, struct object_name *name, struct object *parent )
  230. {
  231. struct winstation *winstation = (struct winstation *)parent;
  232. if (parent->ops != &winstation_ops)
  233. {
  234. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  235. return 0;
  236. }
  237. if (get_path_element( name->name, name->len ) < name->len) /* no backslash allowed in name */
  238. {
  239. set_error( STATUS_OBJECT_PATH_SYNTAX_BAD );
  240. return 0;
  241. }
  242. namespace_add( winstation->desktop_names, name );
  243. return 1;
  244. }
  245. static int desktop_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
  246. {
  247. struct thread *thread;
  248. /* check if the handle is currently used by the process or one of its threads */
  249. if (process->desktop == handle) return 0;
  250. LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
  251. if (thread->desktop == handle) return 0;
  252. return 1;
  253. }
  254. static void desktop_destroy( struct object *obj )
  255. {
  256. struct desktop *desktop = (struct desktop *)obj;
  257. free_hotkeys( desktop, 0 );
  258. if (desktop->top_window) free_window_handle( desktop->top_window );
  259. if (desktop->msg_window) free_window_handle( desktop->msg_window );
  260. if (desktop->global_hooks) release_object( desktop->global_hooks );
  261. if (desktop->close_timeout) remove_timeout_user( desktop->close_timeout );
  262. list_remove( &desktop->entry );
  263. release_object( desktop->winstation );
  264. }
  265. /* retrieve the thread desktop, checking the handle access rights */
  266. struct desktop *get_thread_desktop( struct thread *thread, unsigned int access )
  267. {
  268. return get_desktop_obj( thread->process, thread->desktop, access );
  269. }
  270. static void close_desktop_timeout( void *private )
  271. {
  272. struct desktop *desktop = private;
  273. desktop->close_timeout = NULL;
  274. unlink_named_object( &desktop->obj ); /* make sure no other process can open it */
  275. post_desktop_message( desktop, WM_CLOSE, 0, 0 ); /* and signal the owner to quit */
  276. }
  277. /* add a user of the desktop and cancel the close timeout */
  278. static void add_desktop_user( struct desktop *desktop )
  279. {
  280. desktop->users++;
  281. if (desktop->close_timeout)
  282. {
  283. remove_timeout_user( desktop->close_timeout );
  284. desktop->close_timeout = NULL;
  285. }
  286. }
  287. /* remove a user of the desktop and start the close timeout if necessary */
  288. static void remove_desktop_user( struct desktop *desktop )
  289. {
  290. struct process *process;
  291. assert( desktop->users > 0 );
  292. desktop->users--;
  293. /* if we have one remaining user, it has to be the manager of the desktop window */
  294. if ((process = get_top_window_owner( desktop )) && desktop->users == process->running_threads && !desktop->close_timeout)
  295. desktop->close_timeout = add_timeout_user( -TICKS_PER_SEC, close_desktop_timeout, desktop );
  296. }
  297. /* set the thread default desktop handle */
  298. void set_thread_default_desktop( struct thread *thread, struct desktop *desktop, obj_handle_t handle )
  299. {
  300. if (thread->desktop) return; /* nothing to do */
  301. thread->desktop = handle;
  302. if (!thread->process->is_system) add_desktop_user( desktop );
  303. }
  304. /* set the process default desktop handle */
  305. void set_process_default_desktop( struct process *process, struct desktop *desktop,
  306. obj_handle_t handle )
  307. {
  308. struct thread *thread;
  309. if (process->desktop == handle) return; /* nothing to do */
  310. process->desktop = handle;
  311. /* set desktop for threads that don't have one yet */
  312. LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
  313. set_thread_default_desktop( thread, desktop, handle );
  314. }
  315. /* connect a process to its window station */
  316. void connect_process_winstation( struct process *process, struct thread *parent_thread,
  317. struct process *parent_process )
  318. {
  319. struct winstation *winstation = NULL;
  320. struct desktop *desktop = NULL;
  321. obj_handle_t handle;
  322. /* check for an inherited winstation handle (don't ask...) */
  323. if ((handle = find_inherited_handle( process, &winstation_ops )))
  324. {
  325. winstation = (struct winstation *)get_handle_obj( process, handle, 0, &winstation_ops );
  326. }
  327. else if (parent_process->winstation)
  328. {
  329. handle = duplicate_handle( parent_process, parent_process->winstation,
  330. process, 0, 0, DUPLICATE_SAME_ACCESS );
  331. winstation = (struct winstation *)get_handle_obj( process, handle, 0, &winstation_ops );
  332. }
  333. if (!winstation) goto done;
  334. process->winstation = handle;
  335. if ((handle = find_inherited_handle( process, &desktop_ops )))
  336. {
  337. desktop = get_desktop_obj( process, handle, 0 );
  338. if (!desktop || desktop->winstation != winstation) goto done;
  339. }
  340. else
  341. {
  342. if (parent_thread && parent_thread->desktop)
  343. handle = parent_thread->desktop;
  344. else if (parent_process->desktop)
  345. handle = parent_process->desktop;
  346. else
  347. goto done;
  348. desktop = get_desktop_obj( parent_process, handle, 0 );
  349. if (!desktop || desktop->winstation != winstation) goto done;
  350. handle = duplicate_handle( parent_process, handle, process, 0, 0, DUPLICATE_SAME_ACCESS );
  351. }
  352. if (handle) set_process_default_desktop( process, desktop, handle );
  353. done:
  354. if (desktop) release_object( desktop );
  355. if (winstation) release_object( winstation );
  356. clear_error();
  357. }
  358. /* close the desktop of a given process */
  359. void close_process_desktop( struct process *process )
  360. {
  361. obj_handle_t handle;
  362. if (!(handle = process->desktop)) return;
  363. process->desktop = 0;
  364. close_handle( process, handle );
  365. }
  366. /* release (and eventually close) the desktop of a given thread */
  367. void release_thread_desktop( struct thread *thread, int close )
  368. {
  369. struct desktop *desktop;
  370. obj_handle_t handle;
  371. if (!(handle = thread->desktop)) return;
  372. if (!thread->process->is_system)
  373. {
  374. if (!(desktop = get_desktop_obj( thread->process, handle, 0 ))) clear_error(); /* ignore errors */
  375. else
  376. {
  377. remove_desktop_user( desktop );
  378. release_object( desktop );
  379. }
  380. }
  381. if (close)
  382. {
  383. thread->desktop = 0;
  384. close_handle( thread->process, handle );
  385. }
  386. }
  387. /* create a window station */
  388. DECL_HANDLER(create_winstation)
  389. {
  390. struct winstation *winstation;
  391. struct unicode_str name = get_req_unicode_str();
  392. struct object *root = NULL;
  393. reply->handle = 0;
  394. if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir ))) return;
  395. if ((winstation = create_winstation( root, &name, req->attributes, req->flags )))
  396. {
  397. reply->handle = alloc_handle( current->process, winstation, req->access, req->attributes );
  398. release_object( winstation );
  399. }
  400. if (root) release_object( root );
  401. }
  402. /* open a handle to a window station */
  403. DECL_HANDLER(open_winstation)
  404. {
  405. struct unicode_str name = get_req_unicode_str();
  406. reply->handle = open_object( current->process, req->rootdir, req->access,
  407. &winstation_ops, &name, req->attributes );
  408. }
  409. /* close a window station */
  410. DECL_HANDLER(close_winstation)
  411. {
  412. struct winstation *winstation;
  413. if ((winstation = (struct winstation *)get_handle_obj( current->process, req->handle,
  414. 0, &winstation_ops )))
  415. {
  416. if (close_handle( current->process, req->handle )) set_error( STATUS_ACCESS_DENIED );
  417. release_object( winstation );
  418. }
  419. }
  420. /* get the process current window station */
  421. DECL_HANDLER(get_process_winstation)
  422. {
  423. reply->handle = current->process->winstation;
  424. }
  425. /* set the process current window station */
  426. DECL_HANDLER(set_process_winstation)
  427. {
  428. struct winstation *winstation;
  429. if ((winstation = (struct winstation *)get_handle_obj( current->process, req->handle,
  430. 0, &winstation_ops )))
  431. {
  432. /* FIXME: should we close the old one? */
  433. current->process->winstation = req->handle;
  434. release_object( winstation );
  435. }
  436. }
  437. /* create a desktop */
  438. DECL_HANDLER(create_desktop)
  439. {
  440. struct desktop *desktop;
  441. struct winstation *winstation;
  442. struct unicode_str name = get_req_unicode_str();
  443. reply->handle = 0;
  444. if (!name.len)
  445. {
  446. set_error( STATUS_INVALID_HANDLE );
  447. return;
  448. }
  449. if ((winstation = get_process_winstation( current->process, WINSTA_CREATEDESKTOP )))
  450. {
  451. if ((desktop = create_desktop( &name, req->attributes, req->flags, winstation )))
  452. {
  453. reply->handle = alloc_handle( current->process, desktop, req->access, req->attributes );
  454. release_object( desktop );
  455. }
  456. release_object( winstation );
  457. }
  458. }
  459. /* open a handle to a desktop */
  460. DECL_HANDLER(open_desktop)
  461. {
  462. struct winstation *winstation;
  463. struct object *obj;
  464. struct unicode_str name = get_req_unicode_str();
  465. /* FIXME: check access rights */
  466. if (!req->winsta)
  467. winstation = get_process_winstation( current->process, 0 );
  468. else
  469. winstation = (struct winstation *)get_handle_obj( current->process, req->winsta, 0, &winstation_ops );
  470. if (!winstation) return;
  471. if ((obj = open_named_object( &winstation->obj, &desktop_ops, &name, req->attributes )))
  472. {
  473. reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
  474. release_object( obj );
  475. }
  476. release_object( winstation );
  477. }
  478. /* open a handle to current input desktop */
  479. DECL_HANDLER(open_input_desktop)
  480. {
  481. /* FIXME: check access rights */
  482. struct winstation *winstation = get_process_winstation( current->process, 0 );
  483. struct desktop *desktop;
  484. if (!winstation) return;
  485. if (!(winstation->flags & WSF_VISIBLE))
  486. {
  487. set_error( STATUS_ILLEGAL_FUNCTION );
  488. release_object( winstation );
  489. return;
  490. }
  491. if ((desktop = get_desktop_obj( current->process, current->process->desktop, 0 )))
  492. {
  493. reply->handle = alloc_handle( current->process, desktop, req->access, req->attributes );
  494. release_object( desktop );
  495. }
  496. release_object( winstation );
  497. }
  498. /* close a desktop */
  499. DECL_HANDLER(close_desktop)
  500. {
  501. struct desktop *desktop;
  502. /* make sure it is a desktop handle */
  503. if ((desktop = (struct desktop *)get_handle_obj( current->process, req->handle,
  504. 0, &desktop_ops )))
  505. {
  506. if (close_handle( current->process, req->handle )) set_error( STATUS_DEVICE_BUSY );
  507. release_object( desktop );
  508. }
  509. }
  510. /* get the thread current desktop */
  511. DECL_HANDLER(get_thread_desktop)
  512. {
  513. struct thread *thread;
  514. if (!(thread = get_thread_from_id( req->tid ))) return;
  515. reply->handle = thread->desktop;
  516. release_object( thread );
  517. }
  518. /* set the thread current desktop */
  519. DECL_HANDLER(set_thread_desktop)
  520. {
  521. struct desktop *old_desktop, *new_desktop;
  522. struct winstation *winstation;
  523. if (!(winstation = get_process_winstation( current->process, 0 /* FIXME: access rights? */ )))
  524. return;
  525. if (!(new_desktop = get_desktop_obj( current->process, req->handle, 0 )))
  526. {
  527. release_object( winstation );
  528. return;
  529. }
  530. if (new_desktop->winstation != winstation)
  531. {
  532. set_error( STATUS_ACCESS_DENIED );
  533. release_object( new_desktop );
  534. release_object( winstation );
  535. return;
  536. }
  537. /* check if we are changing to a new desktop */
  538. if (!(old_desktop = get_desktop_obj( current->process, current->desktop, 0)))
  539. clear_error(); /* ignore error */
  540. /* when changing desktop, we can't have any users on the current one */
  541. if (old_desktop != new_desktop && current->desktop_users > 0)
  542. set_error( STATUS_DEVICE_BUSY );
  543. else
  544. {
  545. current->desktop = req->handle; /* FIXME: should we close the old one? */
  546. if (!current->process->is_system && old_desktop != new_desktop)
  547. {
  548. add_desktop_user( new_desktop );
  549. if (old_desktop) remove_desktop_user( old_desktop );
  550. }
  551. }
  552. if (!current->process->desktop)
  553. set_process_default_desktop( current->process, new_desktop, req->handle );
  554. if (old_desktop != new_desktop && current->queue) detach_thread_input( current );
  555. if (old_desktop) release_object( old_desktop );
  556. release_object( new_desktop );
  557. release_object( winstation );
  558. }
  559. /* get/set information about a user object (window station or desktop) */
  560. DECL_HANDLER(set_user_object_info)
  561. {
  562. struct object *obj;
  563. data_size_t len;
  564. if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
  565. if (obj->ops == &desktop_ops)
  566. {
  567. struct desktop *desktop = (struct desktop *)obj;
  568. reply->is_desktop = 1;
  569. reply->old_obj_flags = desktop->flags;
  570. if (req->flags & SET_USER_OBJECT_SET_FLAGS) desktop->flags = req->obj_flags;
  571. }
  572. else if (obj->ops == &winstation_ops)
  573. {
  574. struct winstation *winstation = (struct winstation *)obj;
  575. reply->is_desktop = 0;
  576. reply->old_obj_flags = winstation->flags;
  577. if (req->flags & SET_USER_OBJECT_SET_FLAGS) winstation->flags = req->obj_flags;
  578. }
  579. else
  580. {
  581. set_error( STATUS_OBJECT_TYPE_MISMATCH );
  582. release_object( obj );
  583. return;
  584. }
  585. if (obj->ops == &desktop_ops && get_reply_max_size() && (req->flags & SET_USER_OBJECT_GET_FULL_NAME))
  586. {
  587. struct desktop *desktop = (struct desktop *)obj;
  588. data_size_t winstation_len, desktop_len;
  589. const WCHAR *winstation_name = get_object_name( &desktop->winstation->obj, &winstation_len );
  590. const WCHAR *desktop_name = get_object_name( obj, &desktop_len );
  591. WCHAR *full_name;
  592. if (!winstation_name) winstation_len = 0;
  593. if (!desktop_name) desktop_len = 0;
  594. len = winstation_len + desktop_len + sizeof(WCHAR);
  595. if ((full_name = mem_alloc( len )))
  596. {
  597. memcpy( full_name, winstation_name, winstation_len );
  598. full_name[winstation_len / sizeof(WCHAR)] = '\\';
  599. memcpy( full_name + winstation_len / sizeof(WCHAR) + 1, desktop_name, desktop_len );
  600. set_reply_data_ptr( full_name, min( len, get_reply_max_size() ));
  601. }
  602. }
  603. else
  604. {
  605. const WCHAR *name = get_object_name( obj, &len );
  606. if (name) set_reply_data( name, min( len, get_reply_max_size() ));
  607. }
  608. release_object( obj );
  609. }
  610. /* enumerate window stations */
  611. DECL_HANDLER(enum_winstation)
  612. {
  613. unsigned int index = 0;
  614. struct winstation *winsta;
  615. const WCHAR *name;
  616. data_size_t len;
  617. LIST_FOR_EACH_ENTRY( winsta, &winstation_list, struct winstation, entry )
  618. {
  619. unsigned int access = WINSTA_ENUMERATE;
  620. if (req->index > index++) continue;
  621. if (!check_object_access( NULL, &winsta->obj, &access )) continue;
  622. clear_error();
  623. reply->next = index;
  624. if ((name = get_object_name( &winsta->obj, &len )))
  625. set_reply_data( name, min( len, get_reply_max_size() ));
  626. return;
  627. }
  628. set_error( STATUS_NO_MORE_ENTRIES );
  629. }
  630. /* enumerate desktops */
  631. DECL_HANDLER(enum_desktop)
  632. {
  633. struct winstation *winstation;
  634. struct desktop *desktop;
  635. unsigned int index = 0;
  636. const WCHAR *name;
  637. data_size_t len;
  638. if (!(winstation = (struct winstation *)get_handle_obj( current->process, req->winstation,
  639. WINSTA_ENUMDESKTOPS, &winstation_ops )))
  640. return;
  641. LIST_FOR_EACH_ENTRY( desktop, &winstation->desktops, struct desktop, entry )
  642. {
  643. unsigned int access = DESKTOP_ENUMERATE;
  644. if (req->index > index++) continue;
  645. if (!desktop->obj.name) continue;
  646. if (!check_object_access( NULL, &desktop->obj, &access )) continue;
  647. if ((name = get_object_name( &desktop->obj, &len )))
  648. set_reply_data( name, min( len, get_reply_max_size() ));
  649. release_object( winstation );
  650. clear_error();
  651. reply->next = index;
  652. return;
  653. }
  654. release_object( winstation );
  655. set_error( STATUS_NO_MORE_ENTRIES );
  656. }