xref: /reactos/base/system/winlogon/winlogon.h (revision 1dfba2a6)
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 2003 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 /* COPYRIGHT:       See COPYING in the top level directory
20  * PROJECT:         ReactOS winlogon
21  * FILE:            base/system/winlogon/winlogon.h
22  * PURPOSE:         Winlogon
23  * PROGRAMMER:
24  */
25 
26 #ifndef __WINLOGON_MAIN_H__
27 #define __WINLOGON_MAIN_H__
28 
29 #define USE_GETLASTINPUTINFO
30 
31 
32 #include <stdarg.h>
33 
34 /* PSDK/NDK Headers */
35 #define WIN32_NO_STATUS
36 #include <windef.h>
37 #include <winbase.h>
38 #include <wingdi.h>
39 #include <winuser.h>
40 #include <winreg.h>
41 #include <winwlx.h>
42 #include <ndk/rtlfuncs.h>
43 #include <ndk/exfuncs.h>
44 #include <ndk/kefuncs.h>
45 #include <strsafe.h>
46 
47 /* PSEH for SEH Support */
48 #include <pseh/pseh2.h>
49 
50 #include <reactos/undocuser.h>
51 #include <reactos/undocmpr.h>
52 
53 BOOL
54 WINAPI
55 SetWindowStationUser(
56     IN HWINSTA hWindowStation,
57     IN PLUID pluid,
58     IN PSID psid OPTIONAL,
59     IN DWORD size);
60 
61 #include <wine/debug.h>
62 WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
63 
64 #include "resource.h"
65 
66 typedef BOOL (WINAPI * PFWLXNEGOTIATE)  (DWORD, DWORD *);
67 typedef BOOL (WINAPI * PFWLXINITIALIZE) (LPWSTR, HANDLE, PVOID, PVOID, PVOID *);
68 typedef VOID (WINAPI * PFWLXDISPLAYSASNOTICE) (PVOID);
69 typedef int  (WINAPI * PFWLXLOGGEDOUTSAS) (PVOID, DWORD, PLUID, PSID, PDWORD,
70                                            PHANDLE, PWLX_MPR_NOTIFY_INFO,
71                                            PVOID *);
72 typedef BOOL (WINAPI * PFWLXACTIVATEUSERSHELL) (PVOID, PWSTR, PWSTR, PVOID);
73 typedef int  (WINAPI * PFWLXLOGGEDONSAS) (PVOID, DWORD, PVOID);
74 typedef VOID (WINAPI * PFWLXDISPLAYLOCKEDNOTICE) (PVOID);
75 typedef int  (WINAPI * PFWLXWKSTALOCKEDSAS) (PVOID, DWORD);
76 typedef BOOL (WINAPI * PFWLXISLOCKOK) (PVOID);
77 typedef BOOL (WINAPI * PFWLXISLOGOFFOK) (PVOID);
78 typedef VOID (WINAPI * PFWLXLOGOFF) (PVOID);
79 typedef VOID (WINAPI * PFWLXSHUTDOWN) (PVOID, DWORD);
80 
81 /* version 1.1 */
82 
83 typedef BOOL (WINAPI * PFWLXSCREENSAVERNOTIFY) (PVOID, BOOL *);
84 typedef BOOL (WINAPI * PFWLXSTARTAPPLICATION) (PVOID, PWSTR, PVOID, PWSTR);
85 
86 /* version 1.3 */
87 
88 typedef BOOL (WINAPI * PFWLXNETWORKPROVIDERLOAD) (PVOID, PWLX_MPR_NOTIFY_INFO);
89 typedef BOOL (WINAPI * PFWLXDISPLAYSTATUSMESSAGE) (PVOID, HDESK, DWORD, PWSTR, PWSTR);
90 typedef BOOL (WINAPI * PFWLXGETSTATUSMESSAGE) (PVOID, DWORD *, PWSTR, DWORD);
91 typedef BOOL (WINAPI * PFWLXREMOVESTATUSMESSAGE) (PVOID);
92 
93 typedef struct _GINAFUNCTIONS
94 {
95     /* Functions always available for a valid GINA */
96     PFWLXNEGOTIATE            WlxNegotiate; /* optional */
97     PFWLXINITIALIZE           WlxInitialize;
98 
99     /* Functions available if WlxVersion >= WLX_VERSION_1_0 (MS Windows 3.5.0) */
100     PFWLXDISPLAYSASNOTICE     WlxDisplaySASNotice;
101     PFWLXLOGGEDOUTSAS         WlxLoggedOutSAS;
102     PFWLXACTIVATEUSERSHELL    WlxActivateUserShell;
103     PFWLXLOGGEDONSAS          WlxLoggedOnSAS;
104     PFWLXDISPLAYLOCKEDNOTICE  WlxDisplayLockedNotice;
105     PFWLXWKSTALOCKEDSAS       WlxWkstaLockedSAS;
106     PFWLXISLOCKOK             WlxIsLockOk;
107     PFWLXISLOGOFFOK           WlxIsLogoffOk;
108     PFWLXLOGOFF               WlxLogoff;
109     PFWLXSHUTDOWN             WlxShutdown;
110 
111     /* Functions available if WlxVersion >= WLX_VERSION_1_1 (MS Windows 3.5.1) */
112     PFWLXSCREENSAVERNOTIFY    WlxScreenSaverNotify; /* optional */
113     PFWLXSTARTAPPLICATION     WlxStartApplication; /* optional */
114 
115     /* Functions available if WlxVersion >= WLX_VERSION_1_2 (MS Windows NT 4.0) */
116 
117     /* Functions available if WlxVersion >= WLX_VERSION_1_3 (MS Windows 2000) */
118     PFWLXNETWORKPROVIDERLOAD  WlxNetworkProviderLoad; /* not called ATM */
119     PFWLXDISPLAYSTATUSMESSAGE WlxDisplayStatusMessage;
120     PFWLXGETSTATUSMESSAGE     WlxGetStatusMessage; /* doesn't need to be called */
121     PFWLXREMOVESTATUSMESSAGE  WlxRemoveStatusMessage;
122 
123     /* Functions available if WlxVersion >= WLX_VERSION_1_4 (MS Windows XP) */
124 } GINAFUNCTIONS, *PGINAFUNCTIONS;
125 
126 typedef struct _GINAINSTANCE
127 {
128     HMODULE hDllInstance;
129     GINAFUNCTIONS Functions;
130     PVOID Context;
131     DWORD Version;
132     BOOL UseCtrlAltDelete;
133 } GINAINSTANCE, *PGINAINSTANCE;
134 
135 
136 /*
137  * The picture Microsoft is trying to paint here
138  * (http://msdn.microsoft.com/en-us/library/windows/desktop/aa380547%28v=vs.85%29.aspx)
139  * about the Winlogon states is a little too simple.
140  *
141  * The real picture should look more like this:
142  *
143  * STATE_INIT
144  *    Initial state. Required for session initialization. After initialization,
145  *    the state will automatically change to STATE_LOGGED_OFF.
146  *
147  * STATE_LOGGED_OFF
148  *    User is logged off. Winlogon shows the "Press Ctrl-Alt-Del for logon"
149  *    dialog. The state changes to STATE_LOGGED_OFF_SAS when the user presses
150  *    "Ctrl-Alt-Del". If DisableCAD is true, the state will automatically
151  *    change to STATE_LOGGED_OFF_SAS without showing the dialog.
152  *
153  * STATE_LOGGED_OFF_SAS
154  *    State shows the logon dialog. Entering the right credentials and pressing
155  *    "OK" changes the state to STATE_LOGGED_ON. Pressing "Cancel" or a timeout
156  *    changes the state back to STATE_LOGGED_OFF.
157  *
158  * STATE_LOGGED_ON
159  *    User is logged on. Winlogon does not show any dialog. Pressing
160  *    "Ctrl-Alt-Del" changes the state to STATE_LOGGED_ON_SAS and user
161  *    inactivity changes the state to STATE_SCREENSAVER.
162  *
163  * STATE_LOGGED_ON_SAS
164  *    Winlogon shows the security dialog. Pressing "Cancel" or "Task Manager"
165  *    or a timeout change the state back to STATE_LOGGED_ON. Pressing "Change
166  *    Password" does not change the state, because the security dialog is still
167  *    visible behind the change password dialog. Pressing "Log off" changes the
168  *    state to STATE_LOGGING_OFF. Pressing "Lock Computer" changes the state to
169  *    STATE_LOCKED. Pressing "Shutdown" changes the state to
170  *    STATE_SHUTTING_DOWN.
171  *
172  * STATE_LOCKED
173  *    Winlogon shows the locked message dialog. When the user presses "Ctrl-
174  *    Alt-Del" the state changes to STATE_LOCKED_SAS. If DisableCAD is true,
175  *    the state will automatically change to STATE_LOCKED_SAS without showing
176  *    the dialog.
177  *
178  * STATE_LOCKED_SAS
179  *    Winlogon shows the unlock dialog. Pressing "Cancel" or a timeout will
180  *    change the state back to STATE_LOCKED. Entering the right credentials and
181  *    pressing "OK" unlocks the computer and changes the state to
182  *    STATE_LOGGED_ON.
183  *
184  * STATE_LOGGING_OFF
185  *    Winlogon shows the logoff dialog. Pressing "Cancel" or a timeout changes
186  *    the state back to STATE_LOGGED_ON_SAS. Pressing "OK" logs off the user
187  *    and changes the state to STATE_LOGGED_OFF.
188  *
189  * STATE_SHUTTING_DOWN
190  *    Winlogon shows the shutdown dialog. Pressing "Cancel" or a timeout will
191  *    change the state back to STATE_LOGGED_ON_SAS. Pressing "OK" will change
192  *    the state to STATE_SHUT_DOWN.
193  *
194  * STATE_SHUT_DOWN
195  *    Terminates Winlogon and initiates shut-down.
196  *
197  * STATE_SCREENSAVER
198  *    Winlogon runs the screen saver. Upon user activity, the screensaver
199  *    terminates and the state changes back to STATE_LOGGED_ON if the secure
200  *    screen saver option is off. Otherwise, the state changes to STATE_LOCKED.
201  */
202 typedef enum _LOGON_STATE
203 {
204     STATE_INIT,
205     STATE_LOGGED_OFF,
206     STATE_LOGGED_OFF_SAS,
207     STATE_LOGGED_ON,
208     STATE_LOGGED_ON_SAS,
209     STATE_LOCKED,
210     STATE_LOCKED_SAS,
211     STATE_LOGGING_OFF,     // not used yet
212     STATE_SHUTTING_DOWN,   // not used yet
213     STATE_SHUT_DOWN,       // not used yet
214     STATE_SCREENSAVER      // not used yet
215 } LOGON_STATE, *PLOGON_STATE;
216 
217 #define LockWorkstation(Session)
218 #define UnlockWorkstation(Session)
219 
220 typedef struct _WLSESSION
221 {
222     GINAINSTANCE Gina;
223     DWORD SASAction;
224     BOOL SuppressStatus;
225     BOOL TaskManHotkey;
226     HWND SASWindow;
227     HWINSTA InteractiveWindowStation;
228     LPWSTR InteractiveWindowStationName;
229     HDESK ApplicationDesktop;
230     HDESK WinlogonDesktop;
231     HDESK ScreenSaverDesktop;
232     LUID LogonId;
233     HANDLE UserToken;
234     HANDLE hProfileInfo;
235     LOGON_STATE LogonState;
236     DWORD DialogTimeout; /* Timeout for dialog boxes, in seconds */
237     LARGE_INTEGER LastLogon;
238 
239     /* Screen-saver informations */
240 #ifndef USE_GETLASTINPUTINFO
241     HHOOK KeyboardHook;
242     HHOOK MouseHook;
243 #endif
244     HANDLE hEndOfScreenSaverThread;
245     HANDLE hScreenSaverParametersChanged;
246     HANDLE hUserActivity;
247     HANDLE hEndOfScreenSaver;
248 #ifndef USE_GETLASTINPUTINFO
249     DWORD LastActivity;
250 #endif
251 
252     /* Logon informations */
253     DWORD Options;
254     WLX_MPR_NOTIFY_INFO MprNotifyInfo;
255     WLX_PROFILE_V2_0 *Profile;
256 } WLSESSION, *PWLSESSION;
257 
258 typedef enum _NOTIFICATION_TYPE
259 {
260     LogonHandler,
261     LogoffHandler,
262     LockHandler,
263     UnlockHandler,
264     StartupHandler,
265     ShutdownHandler,
266     StartScreenSaverHandler,
267     StopScreenSaverHandler,
268     DisconnectHandler,
269     ReconnectHandler,
270     StartShellHandler,
271     PostShellHandler,
272     LastHandler
273 } NOTIFICATION_TYPE, *PNOTIFICATION_TYPE;
274 
275 extern HINSTANCE hAppInstance;
276 extern PWLSESSION WLSession;
277 
278 #define WLX_SHUTTINGDOWN(Status) \
279   (((Status) == WLX_SAS_ACTION_SHUTDOWN) || \
280    ((Status) == WLX_SAS_ACTION_SHUTDOWN_POWER_OFF) || \
281    ((Status) == WLX_SAS_ACTION_SHUTDOWN_REBOOT) \
282   )
283 
284 #define WLX_SUSPENDING(Status) \
285   (((Status) == WLX_SAS_ACTION_SHUTDOWN_SLEEP) || \
286    ((Status) == WLX_SAS_ACTION_SHUTDOWN_SLEEP2) || \
287    ((Status) == WLX_SAS_ACTION_SHUTDOWN_HIBERNATE) \
288   )
289 
290 FORCEINLINE
291 VOID
SetLogonTimestamp(_Inout_ PWLSESSION Session)292 SetLogonTimestamp(
293     _Inout_ PWLSESSION Session)
294 {
295     NtQuerySystemTime(&Session->LastLogon);
296 }
297 
298 FORCEINLINE
299 BOOL
IsFirstLogon(_In_ PWLSESSION Session)300 IsFirstLogon(
301     _In_ PWLSESSION Session)
302 {
303     /* The WLSESSION::LastLogon is initialized to 0 so this is OK */
304     return (Session->LastLogon.QuadPart == 0);
305 }
306 
307 /* environment.c */
308 BOOL
309 CreateUserEnvironment(IN PWLSESSION Session);
310 
311 /* notify.c */
312 BOOL
313 InitNotifications(VOID);
314 
315 VOID
316 CleanupNotifications(VOID);
317 
318 VOID
319 CallNotificationDlls(
320     PWLSESSION pSession,
321     NOTIFICATION_TYPE Type);
322 
323 /* rpcserver.c */
324 BOOL
325 StartRpcServer(VOID);
326 
327 /* sas.c */
328 extern LUID LuidNone;
329 
330 BOOL
331 SetDefaultLanguage(IN PWLSESSION Session);
332 
333 NTSTATUS
334 HandleShutdown(IN OUT PWLSESSION Session,
335                IN DWORD wlxAction);
336 
337 BOOL
338 InitializeSAS(IN OUT PWLSESSION Session);
339 
340 /* screensaver.c */
341 BOOL
342 InitializeScreenSaver(IN OUT PWLSESSION Session);
343 
344 VOID
345 StartScreenSaver(IN PWLSESSION Session);
346 
347 /* security.c */
348 PSECURITY_DESCRIPTOR
349 ConvertToSelfRelative(
350     _In_ PSECURITY_DESCRIPTOR AbsoluteSd);
351 
352 BOOL
353 CreateWinstaSecurity(
354     _Out_ PSECURITY_DESCRIPTOR *WinstaSd);
355 
356 BOOL
357 CreateApplicationDesktopSecurity(
358     _Out_ PSECURITY_DESCRIPTOR *ApplicationDesktopSd);
359 
360 BOOL
361 CreateWinlogonDesktopSecurity(
362     _Out_ PSECURITY_DESCRIPTOR *WinlogonDesktopSd);
363 
364 BOOL
365 CreateScreenSaverSecurity(
366     _Out_ PSECURITY_DESCRIPTOR *ScreenSaverDesktopSd);
367 
368 BOOL
369 AllowWinstaAccessToUser(
370     _In_ HWINSTA WinSta,
371     _In_ PSID LogonSid);
372 
373 BOOL
374 AllowDesktopAccessToUser(
375     _In_ HDESK Desktop,
376     _In_ PSID LogonSid);
377 
378 BOOL
379 AllowAccessOnSession(
380     _In_ PWLSESSION Session);
381 
382 /* setup.c */
383 DWORD
384 GetSetupType(VOID);
385 
386 BOOL
387 RunSetup(VOID);
388 
389 /* shutdown.h */
390 DWORD
391 TerminateSystemShutdown(VOID);
392 
393 DWORD
394 StartSystemShutdown(
395     IN PUNICODE_STRING pMessage,
396     IN ULONG dwTimeout,
397     IN BOOLEAN bForceAppsClosed,
398     IN BOOLEAN bRebootAfterShutdown,
399     IN ULONG dwReason);
400 
401 /* winlogon.c */
402 BOOL
403 PlaySoundRoutine(IN LPCWSTR FileName,
404                  IN UINT Logon,
405                  IN UINT Flags);
406 
407 BOOL
408 DisplayStatusMessage(IN PWLSESSION Session,
409                      IN HDESK hDesktop,
410                      IN UINT ResourceId);
411 
412 BOOL
413 RemoveStatusMessage(IN PWLSESSION Session);
414 
415 /* wlx.c */
416 VOID
417 InitDialogListHead(VOID);
418 
419 VOID
420 CloseAllDialogWindows(VOID);
421 
422 BOOL
423 GinaInit(IN OUT PWLSESSION Session);
424 
425 BOOL
426 CreateWindowStationAndDesktops(
427     _Inout_ PWLSESSION Session);
428 
429 
430 VOID WINAPI WlxUseCtrlAltDel(HANDLE hWlx);
431 VOID WINAPI WlxSetContextPointer(HANDLE hWlx, PVOID pWlxContext);
432 VOID WINAPI WlxSasNotify(HANDLE hWlx, DWORD dwSasType);
433 BOOL WINAPI WlxSetTimeout(HANDLE hWlx, DWORD Timeout);
434 int WINAPI WlxAssignShellProtection(HANDLE hWlx, HANDLE hToken, HANDLE hProcess, HANDLE hThread);
435 int WINAPI WlxMessageBox(HANDLE hWlx, HWND hwndOwner, LPWSTR lpszText, LPWSTR lpszTitle, UINT fuStyle);
436 int WINAPI WlxDialogBox(HANDLE hWlx, HANDLE hInst, LPWSTR lpszTemplate, HWND hwndOwner, DLGPROC dlgprc);
437 int WINAPI WlxDialogBoxParam(HANDLE hWlx, HANDLE hInst, LPWSTR lpszTemplate, HWND hwndOwner, DLGPROC dlgprc, LPARAM dwInitParam);
438 int WINAPI WlxDialogBoxIndirect(HANDLE hWlx, HANDLE hInst, LPCDLGTEMPLATE hDialogTemplate, HWND hwndOwner, DLGPROC dlgprc);
439 int WINAPI WlxDialogBoxIndirectParam(HANDLE hWlx, HANDLE hInst, LPCDLGTEMPLATE hDialogTemplate, HWND hwndOwner, DLGPROC dlgprc, LPARAM dwInitParam);
440 int WINAPI WlxSwitchDesktopToUser(HANDLE hWlx);
441 int WINAPI WlxSwitchDesktopToWinlogon(HANDLE hWlx);
442 int WINAPI WlxChangePasswordNotify(HANDLE hWlx, PWLX_MPR_NOTIFY_INFO pMprInfo, DWORD dwChangeInfo);
443 BOOL WINAPI WlxGetSourceDesktop(HANDLE hWlx, PWLX_DESKTOP* ppDesktop);
444 BOOL WINAPI WlxSetReturnDesktop(HANDLE hWlx, PWLX_DESKTOP pDesktop);
445 BOOL WINAPI WlxCreateUserDesktop(HANDLE hWlx, HANDLE hToken, DWORD Flags, PWSTR pszDesktopName, PWLX_DESKTOP* ppDesktop);
446 int WINAPI WlxChangePasswordNotifyEx(HANDLE hWlx, PWLX_MPR_NOTIFY_INFO pMprInfo, DWORD dwChangeInfo, PWSTR ProviderName, PVOID Reserved);
447 BOOL WINAPI WlxCloseUserDesktop(HANDLE hWlx, PWLX_DESKTOP pDesktop, HANDLE hToken);
448 BOOL WINAPI WlxSetOption(HANDLE hWlx, DWORD Option, ULONG_PTR Value, ULONG_PTR* OldValue);
449 BOOL WINAPI WlxGetOption(HANDLE hWlx, DWORD Option, ULONG_PTR* Value);
450 VOID WINAPI WlxWin31Migrate(HANDLE hWlx);
451 BOOL WINAPI WlxQueryClientCredentials(PWLX_CLIENT_CREDENTIALS_INFO_V1_0 pCred);
452 BOOL WINAPI WlxQueryInetConnectorCredentials(PWLX_CLIENT_CREDENTIALS_INFO_V1_0 pCred);
453 DWORD WINAPI WlxQueryConsoleSwitchCredentials(PWLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0 pCred);
454 BOOL WINAPI WlxQueryTsLogonCredentials(PWLX_CLIENT_CREDENTIALS_INFO_V2_0 pCred);
455 BOOL WINAPI WlxDisconnect(VOID);
456 DWORD WINAPI WlxQueryTerminalServicesData(HANDLE hWlx, PWLX_TERMINAL_SERVICES_DATA pTSData, WCHAR* UserName, WCHAR* Domain);
457 
458 #endif /* __WINLOGON_MAIN_H__ */
459