quartz: Silence requests for ipin on filters.
[wine] / dlls / user32 / winstation.c
1 /*
2  * Window stations and desktops
3  *
4  * Copyright 2002 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
21 #include "ntstatus.h"
22 #define WIN32_NO_STATUS
23
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "winerror.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "wine/server.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34 #include "user_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(winstation);
37
38
39 /* callback for enumeration functions */
40 struct enum_proc_lparam
41 {
42     NAMEENUMPROCA func;
43     LPARAM        lparam;
44 };
45
46 static BOOL CALLBACK enum_names_WtoA( LPWSTR name, LPARAM lparam )
47 {
48     struct enum_proc_lparam *data = (struct enum_proc_lparam *)lparam;
49     char buffer[MAX_PATH];
50
51     if (!WideCharToMultiByte( CP_ACP, 0, name, -1, buffer, sizeof(buffer), NULL, NULL ))
52         return FALSE;
53     return data->func( buffer, data->lparam );
54 }
55
56
57 /***********************************************************************
58  *              CreateWindowStationA  (USER32.@)
59  */
60 HWINSTA WINAPI CreateWindowStationA( LPCSTR name, DWORD reserved, ACCESS_MASK access,
61                                      LPSECURITY_ATTRIBUTES sa )
62 {
63     WCHAR buffer[MAX_PATH];
64
65     if (!name) return CreateWindowStationW( NULL, reserved, access, sa );
66
67     if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
68     {
69         SetLastError( ERROR_FILENAME_EXCED_RANGE );
70         return 0;
71     }
72     return CreateWindowStationW( buffer, reserved, access, sa );
73 }
74
75
76 /***********************************************************************
77  *              CreateWindowStationW  (USER32.@)
78  */
79 HWINSTA WINAPI CreateWindowStationW( LPCWSTR name, DWORD reserved, ACCESS_MASK access,
80                                      LPSECURITY_ATTRIBUTES sa )
81 {
82     HANDLE ret;
83     DWORD len = name ? strlenW(name) : 0;
84
85     if (len >= MAX_PATH)
86     {
87         SetLastError( ERROR_FILENAME_EXCED_RANGE );
88         return 0;
89     }
90     SERVER_START_REQ( create_winstation )
91     {
92         req->flags      = 0;
93         req->access     = access;
94         req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
95                           ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
96         wine_server_add_data( req, name, len * sizeof(WCHAR) );
97         /* it doesn't seem to set last error */
98         wine_server_call( req );
99         ret = reply->handle;
100     }
101     SERVER_END_REQ;
102     return ret;
103 }
104
105
106 /******************************************************************************
107  *              OpenWindowStationA  (USER32.@)
108  */
109 HWINSTA WINAPI OpenWindowStationA( LPCSTR name, BOOL inherit, ACCESS_MASK access )
110 {
111     WCHAR buffer[MAX_PATH];
112
113     if (!name) return OpenWindowStationW( NULL, inherit, access );
114
115     if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
116     {
117         SetLastError( ERROR_FILENAME_EXCED_RANGE );
118         return 0;
119     }
120     return OpenWindowStationW( buffer, inherit, access );
121 }
122
123
124 /******************************************************************************
125  *              OpenWindowStationW  (USER32.@)
126  */
127 HWINSTA WINAPI OpenWindowStationW( LPCWSTR name, BOOL inherit, ACCESS_MASK access )
128 {
129     HANDLE ret = 0;
130     DWORD len = name ? strlenW(name) : 0;
131     if (len >= MAX_PATH)
132     {
133         SetLastError( ERROR_FILENAME_EXCED_RANGE );
134         return 0;
135     }
136     SERVER_START_REQ( open_winstation )
137     {
138         req->access     = access;
139         req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
140         wine_server_add_data( req, name, len * sizeof(WCHAR) );
141         if (!wine_server_call_err( req )) ret = reply->handle;
142     }
143     SERVER_END_REQ;
144     return ret;
145 }
146
147
148 /***********************************************************************
149  *              CloseWindowStation  (USER32.@)
150  */
151 BOOL WINAPI CloseWindowStation( HWINSTA handle )
152 {
153     BOOL ret;
154     SERVER_START_REQ( close_winstation )
155     {
156         req->handle = handle;
157         ret = !wine_server_call_err( req );
158     }
159     SERVER_END_REQ;
160     return ret;
161 }
162
163
164 /******************************************************************************
165  *              GetProcessWindowStation  (USER32.@)
166  */
167 HWINSTA WINAPI GetProcessWindowStation(void)
168 {
169     HWINSTA ret = 0;
170
171     SERVER_START_REQ( get_process_winstation )
172     {
173         if (!wine_server_call_err( req )) ret = reply->handle;
174     }
175     SERVER_END_REQ;
176     return ret;
177 }
178
179
180 /***********************************************************************
181  *              SetProcessWindowStation  (USER32.@)
182  */
183 BOOL WINAPI SetProcessWindowStation( HWINSTA handle )
184 {
185     BOOL ret;
186
187     SERVER_START_REQ( set_process_winstation )
188     {
189         req->handle = handle;
190         ret = !wine_server_call_err( req );
191     }
192     SERVER_END_REQ;
193     return ret;
194 }
195
196
197 /******************************************************************************
198  *              EnumWindowStationsA  (USER32.@)
199  */
200 BOOL WINAPI EnumWindowStationsA( WINSTAENUMPROCA func, LPARAM lparam )
201 {
202     struct enum_proc_lparam data;
203     data.func   = func;
204     data.lparam = lparam;
205     return EnumWindowStationsW( enum_names_WtoA, (LPARAM)&data );
206 }
207
208
209 /******************************************************************************
210  *              EnumWindowStationsW  (USER32.@)
211  */
212 BOOL WINAPI EnumWindowStationsW( WINSTAENUMPROCW func, LPARAM lparam )
213 {
214     unsigned int index = 0;
215     WCHAR name[MAX_PATH];
216     BOOL ret = TRUE;
217     NTSTATUS status;
218
219     while (ret)
220     {
221         SERVER_START_REQ( enum_winstation )
222         {
223             req->index = index;
224             wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
225             status = wine_server_call( req );
226             name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
227             index = reply->next;
228         }
229         SERVER_END_REQ;
230         if (status == STATUS_NO_MORE_ENTRIES)
231             break;
232         if (status)
233         {
234             SetLastError( RtlNtStatusToDosError( status ) );
235             return FALSE;
236         }
237         ret = func( name, lparam );
238     }
239     return ret;
240 }
241
242
243 /***********************************************************************
244  *              CreateDesktopA   (USER32.@)
245  */
246 HDESK WINAPI CreateDesktopA( LPCSTR name, LPCSTR device, LPDEVMODEA devmode,
247                              DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
248 {
249     WCHAR buffer[MAX_PATH];
250
251     if (device || devmode)
252     {
253         SetLastError( ERROR_INVALID_PARAMETER );
254         return 0;
255     }
256     if (!name) return CreateDesktopW( NULL, NULL, NULL, flags, access, sa );
257
258     if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
259     {
260         SetLastError( ERROR_FILENAME_EXCED_RANGE );
261         return 0;
262     }
263     return CreateDesktopW( buffer, NULL, NULL, flags, access, sa );
264 }
265
266
267 /***********************************************************************
268  *              CreateDesktopW   (USER32.@)
269  */
270 HDESK WINAPI CreateDesktopW( LPCWSTR name, LPCWSTR device, LPDEVMODEW devmode,
271                              DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
272 {
273     HANDLE ret;
274     DWORD len = name ? strlenW(name) : 0;
275
276     if (device || devmode)
277     {
278         SetLastError( ERROR_INVALID_PARAMETER );
279         return 0;
280     }
281     if (len >= MAX_PATH)
282     {
283         SetLastError( ERROR_FILENAME_EXCED_RANGE );
284         return 0;
285     }
286     SERVER_START_REQ( create_desktop )
287     {
288         req->flags      = flags;
289         req->access     = access;
290         req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
291                           ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
292         wine_server_add_data( req, name, len * sizeof(WCHAR) );
293         /* it doesn't seem to set last error */
294         wine_server_call( req );
295         ret = reply->handle;
296     }
297     SERVER_END_REQ;
298     return ret;
299 }
300
301
302 /******************************************************************************
303  *              OpenDesktopA   (USER32.@)
304  */
305 HDESK WINAPI OpenDesktopA( LPCSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
306 {
307     WCHAR buffer[MAX_PATH];
308
309     if (!name) return OpenDesktopW( NULL, flags, inherit, access );
310
311     if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
312     {
313         SetLastError( ERROR_FILENAME_EXCED_RANGE );
314         return 0;
315     }
316     return OpenDesktopW( buffer, flags, inherit, access );
317 }
318
319
320 /******************************************************************************
321  *              OpenDesktopW   (USER32.@)
322  */
323 HDESK WINAPI OpenDesktopW( LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
324 {
325     HANDLE ret = 0;
326     DWORD len = name ? strlenW(name) : 0;
327     if (len >= MAX_PATH)
328     {
329         SetLastError( ERROR_FILENAME_EXCED_RANGE );
330         return 0;
331     }
332     SERVER_START_REQ( open_desktop )
333     {
334         req->flags      = flags;
335         req->access     = access;
336         req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
337         wine_server_add_data( req, name, len * sizeof(WCHAR) );
338         if (!wine_server_call( req )) ret = reply->handle;
339     }
340     SERVER_END_REQ;
341     return ret;
342 }
343
344
345 /***********************************************************************
346  *              CloseDesktop  (USER32.@)
347  */
348 BOOL WINAPI CloseDesktop( HDESK handle )
349 {
350     BOOL ret;
351     SERVER_START_REQ( close_desktop )
352     {
353         req->handle = handle;
354         ret = !wine_server_call_err( req );
355     }
356     SERVER_END_REQ;
357     return ret;
358 }
359
360
361 /******************************************************************************
362  *              GetThreadDesktop   (USER32.@)
363  */
364 HDESK WINAPI GetThreadDesktop( DWORD thread )
365 {
366     HDESK ret = 0;
367
368     SERVER_START_REQ( get_thread_desktop )
369     {
370         req->tid = thread;
371         if (!wine_server_call_err( req )) ret = reply->handle;
372     }
373     SERVER_END_REQ;
374     return ret;
375 }
376
377
378 /******************************************************************************
379  *              SetThreadDesktop   (USER32.@)
380  */
381 BOOL WINAPI SetThreadDesktop( HDESK handle )
382 {
383     BOOL ret;
384
385     SERVER_START_REQ( set_thread_desktop )
386     {
387         req->handle = handle;
388         ret = !wine_server_call_err( req );
389     }
390     SERVER_END_REQ;
391     if (ret) get_user_thread_info()->desktop = 0;  /* reset the desktop window */
392     return ret;
393 }
394
395
396 /******************************************************************************
397  *              EnumDesktopsA   (USER32.@)
398  */
399 BOOL WINAPI EnumDesktopsA( HWINSTA winsta, DESKTOPENUMPROCA func, LPARAM lparam )
400 {
401     struct enum_proc_lparam data;
402     data.func   = func;
403     data.lparam = lparam;
404     return EnumDesktopsW( winsta, enum_names_WtoA, (LPARAM)&data );
405 }
406
407
408 /******************************************************************************
409  *              EnumDesktopsW   (USER32.@)
410  */
411 BOOL WINAPI EnumDesktopsW( HWINSTA winsta, DESKTOPENUMPROCW func, LPARAM lparam )
412 {
413     unsigned int index = 0;
414     WCHAR name[MAX_PATH];
415     BOOL ret = TRUE;
416     NTSTATUS status;
417
418     if (!winsta)
419         winsta = GetProcessWindowStation();
420
421     while (ret)
422     {
423         SERVER_START_REQ( enum_desktop )
424         {
425             req->winstation = winsta;
426             req->index      = index;
427             wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
428             status = wine_server_call( req );
429             name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
430             index = reply->next;
431         }
432         SERVER_END_REQ;
433         if (status == STATUS_NO_MORE_ENTRIES)
434             break;
435         if (status)
436         {
437             SetLastError( RtlNtStatusToDosError( status ) );
438             return FALSE;
439         }
440         ret = func(name, lparam);
441     }
442     return ret;
443 }
444
445
446 /******************************************************************************
447  *              OpenInputDesktop   (USER32.@)
448  */
449 HDESK WINAPI OpenInputDesktop( DWORD flags, BOOL inherit, ACCESS_MASK access )
450 {
451     FIXME( "(%x,%i,%x): stub\n", flags, inherit, access );
452     SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
453     return 0;
454 }
455
456
457 /***********************************************************************
458  *              GetUserObjectInformationA   (USER32.@)
459  */
460 BOOL WINAPI GetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
461 {
462     /* check for information types returning strings */
463     if (index == UOI_TYPE || index == UOI_NAME)
464     {
465         WCHAR buffer[MAX_PATH];
466         DWORD lenA;
467
468         if (!GetUserObjectInformationW( handle, index, buffer, sizeof(buffer), NULL )) return FALSE;
469         lenA = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
470         if (needed) *needed = lenA;
471         if (lenA > len)
472         {
473             SetLastError( ERROR_MORE_DATA );
474             return FALSE;
475         }
476         if (info) WideCharToMultiByte( CP_ACP, 0, buffer, -1, info, len, NULL, NULL );
477         return TRUE;
478     }
479     return GetUserObjectInformationW( handle, index, info, len, needed );
480 }
481
482
483 /***********************************************************************
484  *              GetUserObjectInformationW   (USER32.@)
485  */
486 BOOL WINAPI GetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
487 {
488     static const WCHAR desktopW[] = { 'D','e','s','k','t','o','p',0 };
489     static const WCHAR winstationW[] = { 'W','i','n','d','o','w','S','t','a','t','i','o','n',0 };
490     BOOL ret;
491
492     switch(index)
493     {
494     case UOI_FLAGS:
495         {
496             USEROBJECTFLAGS *obj_flags = info;
497             if (needed) *needed = sizeof(*obj_flags);
498             if (len < sizeof(*obj_flags))
499             {
500                 SetLastError( ERROR_BUFFER_OVERFLOW );
501                 return FALSE;
502             }
503             SERVER_START_REQ( set_user_object_info )
504             {
505                 req->handle    = handle;
506                 req->flags     = 0;
507                 ret = !wine_server_call_err( req );
508                 if (ret)
509                 {
510                     /* FIXME: inherit flag */
511                     obj_flags->dwFlags = reply->old_obj_flags;
512                 }
513             }
514             SERVER_END_REQ;
515         }
516         return ret;
517
518     case UOI_TYPE:
519         SERVER_START_REQ( set_user_object_info )
520         {
521             req->handle = handle;
522             req->flags  = 0;
523             ret = !wine_server_call_err( req );
524             if (ret)
525             {
526                 size_t size = reply->is_desktop ? sizeof(desktopW) : sizeof(winstationW);
527                 if (needed) *needed = size;
528                 if (len < size)
529                 {
530                     SetLastError( ERROR_MORE_DATA );
531                     ret = FALSE;
532                 }
533                 else memcpy( info, reply->is_desktop ? desktopW : winstationW, size );
534             }
535         }
536         SERVER_END_REQ;
537         return ret;
538
539     case UOI_NAME:
540         {
541             WCHAR buffer[MAX_PATH];
542             SERVER_START_REQ( set_user_object_info )
543             {
544                 req->handle = handle;
545                 req->flags  = 0;
546                 wine_server_set_reply( req, buffer, sizeof(buffer) - sizeof(WCHAR) );
547                 ret = !wine_server_call_err( req );
548                 if (ret)
549                 {
550                     size_t size = wine_server_reply_size( reply );
551                     buffer[size / sizeof(WCHAR)] = 0;
552                     size += sizeof(WCHAR);
553                     if (needed) *needed = size;
554                     if (len < size)
555                     {
556                         SetLastError( ERROR_MORE_DATA );
557                         ret = FALSE;
558                     }
559                     else memcpy( info, buffer, size );
560                 }
561             }
562             SERVER_END_REQ;
563         }
564         return ret;
565
566     case UOI_USER_SID:
567         FIXME( "not supported index %d\n", index );
568         /* fall through */
569     default:
570         SetLastError( ERROR_INVALID_PARAMETER );
571         return FALSE;
572     }
573 }
574
575
576 /******************************************************************************
577  *              SetUserObjectInformationA   (USER32.@)
578  */
579 BOOL WINAPI SetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len )
580 {
581     return SetUserObjectInformationW( handle, index, info, len );
582 }
583
584
585 /******************************************************************************
586  *              SetUserObjectInformationW   (USER32.@)
587  */
588 BOOL WINAPI SetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len )
589 {
590     BOOL ret;
591     const USEROBJECTFLAGS *obj_flags = info;
592
593     if (index != UOI_FLAGS || !info || len < sizeof(*obj_flags))
594     {
595         SetLastError( ERROR_INVALID_PARAMETER );
596         return FALSE;
597     }
598     /* FIXME: inherit flag */
599     SERVER_START_REQ( set_user_object_info )
600     {
601         req->handle    = handle;
602         req->flags     = SET_USER_OBJECT_FLAGS;
603         req->obj_flags = obj_flags->dwFlags;
604         ret = !wine_server_call_err( req );
605     }
606     SERVER_END_REQ;
607     return ret;
608 }
609
610
611 /***********************************************************************
612  *              GetUserObjectSecurity   (USER32.@)
613  */
614 BOOL WINAPI GetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
615                                    PSECURITY_DESCRIPTOR sid, DWORD len, LPDWORD needed )
616 {
617     FIXME( "(%p %p %p len=%d %p),stub!\n", handle, info, sid, len, needed );
618     return TRUE;
619 }
620
621 /***********************************************************************
622  *              SetUserObjectSecurity   (USER32.@)
623  */
624 BOOL WINAPI SetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
625                                    PSECURITY_DESCRIPTOR sid )
626 {
627     FIXME( "(%p,%p,%p),stub!\n", handle, info, sid );
628     return TRUE;
629 }