ReactOS  0.4.13-dev-687-g023794c
notify.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Winlogon
4  * FILE: base/system/winlogon/notify.c
5  * PURPOSE: Logon notifications
6  * PROGRAMMERS: Eric Kohl
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include "winlogon.h"
12 
13 /* GLOBALS ******************************************************************/
14 
15 
16 // void Event_Handler_Function_Name(PWLX_NOTIFICATION_INFO pInfo);
18 
20 {
21  "Logon",
22  "Logoff",
23  "Lock",
24  "Unlock",
25  "Startup",
26  "Shutdown",
27  "StartScreenSaver",
28  "StopScreenSaver",
29  "Disconnect",
30  "Reconnect",
31  "StartShell",
32  "PostShell"
33 };
34 
35 typedef struct _NOTIFICATION_ITEM
36 {
38 
48 
49 
51 
52 
53 /* FUNCTIONS *****************************************************************/
54 
57  HKEY hDllKey,
59  PSTR pNotification)
60 {
61  CHAR szFuncBuffer[128];
62  DWORD dwSize;
63  DWORD dwType;
64  LONG lError;
65 
66  dwSize = 128;
67  lError = RegQueryValueExA(hDllKey,
68  pNotification,
69  NULL,
70  &dwType,
71  (PBYTE)szFuncBuffer,
72  &dwSize);
73  if (lError == ERROR_SUCCESS)
74  {
75  return (PWLX_NOTIFY_HANDLER)GetProcAddress(hInstance, szFuncBuffer);
76  }
77 
78  return NULL;
79 }
80 
81 
82 static
83 VOID
85  HKEY hNotifyKey,
86  PWSTR pKeyName)
87 {
88  HKEY hDllKey = NULL;
89  PNOTIFICATION_ITEM NotificationDll = NULL;
90  LONG lError;
91  WCHAR szBuffer[80];
92  DWORD dwSize;
93  DWORD dwType;
96 
97  TRACE("LoadNotificationDll(%p %S)\n", hNotifyKey, pKeyName);
98 
99  lError = RegOpenKeyExW(hNotifyKey,
100  pKeyName,
101  0,
102  KEY_READ,
103  &hDllKey);
104  if (lError != ERROR_SUCCESS)
105  return;
106 
107  dwSize = 80 * sizeof(WCHAR);
108  lError = RegQueryValueExW(hDllKey,
109  L"DllName",
110  NULL,
111  &dwType,
112  (PBYTE)szBuffer,
113  &dwSize);
114  if (lError == ERROR_SUCCESS)
115  {
116  hInstance = LoadLibraryW(szBuffer);
117  if (hInstance == NULL)
118  return;
119 
120  NotificationDll = RtlAllocateHeap(RtlGetProcessHeap(),
122  sizeof(NOTIFICATION_ITEM));
123  if (NotificationDll == NULL)
124  {
126  return;
127  }
128 
129  NotificationDll->bEnabled = TRUE;
130  NotificationDll->dwMaxWait = 30; /* FIXME: ??? */
131  NotificationDll->hInstance = hInstance;
132 
133  dwSize = sizeof(BOOL);
134  RegQueryValueExW(hDllKey,
135  L"Asynchronous",
136  NULL,
137  &dwType,
138  (PBYTE)&NotificationDll->bAsynchronous,
139  &dwSize);
140 
141  dwSize = sizeof(BOOL);
142  RegQueryValueExW(hDllKey,
143  L"Enabled",
144  NULL,
145  &dwType,
146  (PBYTE)&NotificationDll->bEnabled,
147  &dwSize);
148 
149  dwSize = sizeof(BOOL);
150  RegQueryValueExW(hDllKey,
151  L"Impersonate",
152  NULL,
153  &dwType,
154  (PBYTE)&NotificationDll->bImpersonate,
155  &dwSize);
156 
157  dwSize = sizeof(BOOL);
158  RegQueryValueExW(hDllKey,
159  L"Safe",
160  NULL,
161  &dwType,
162  (PBYTE)&NotificationDll->bSafe,
163  &dwSize);
164 
165  dwSize = sizeof(BOOL);
166  RegQueryValueExW(hDllKey,
167  L"SmartCardLogonNotify",
168  NULL,
169  &dwType,
170  (PBYTE)&NotificationDll->bSmartCardLogon,
171  &dwSize);
172 
173  dwSize = sizeof(DWORD);
174  RegQueryValueExW(hDllKey,
175  L"MaxWait",
176  NULL,
177  &dwType,
178  (PBYTE)&NotificationDll->dwMaxWait,
179  &dwSize);
180 
181  for (i = LogonHandler; i < LastHandler; i++)
182  {
183  NotificationDll->Handler[i] = GetNotificationHandler(hDllKey, hInstance, FuncNames[i]);
184  TRACE("%s: %p\n", FuncNames[i], NotificationDll->Handler[i]);
185  }
186 
188  &NotificationDll->ListEntry);
189  }
190 
191  RegCloseKey(hDllKey);
192 }
193 
194 
195 BOOL
197 {
198  HKEY hNotifyKey = NULL;
199  LONG lError;
200  DWORD dwIndex;
201  WCHAR szKeyName[80];
202  DWORD dwKeyName;
203 
204  TRACE("InitNotifications()\n");
205 
207 
209  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify",
210  0,
212  &hNotifyKey);
213  if (lError != ERROR_SUCCESS)
214  {
215  TRACE("RegOpenKeyExW()\n");
216  return TRUE;
217  }
218 
219  dwIndex = 0;
220  for(;;)
221  {
222  dwKeyName = 80 * sizeof(WCHAR);
223  lError = RegEnumKeyExW(hNotifyKey,
224  dwIndex,
225  szKeyName,
226  &dwKeyName,
227  NULL,
228  NULL,
229  NULL,
230  NULL);
231  if (lError != ERROR_SUCCESS)
232  break;
233 
234  TRACE("Notification DLL: %S\n", szKeyName);
235  LoadNotificationDll(hNotifyKey, szKeyName);
236 
237  dwIndex++;
238  }
239 
240  RegCloseKey(hNotifyKey);
241 
242  TRACE("InitNotifications() done\n");
243 
244  return TRUE;
245 }
246 
247 
248 VOID
250  PWLSESSION pSession,
252 {
253  PLIST_ENTRY ListEntry;
254  PNOTIFICATION_ITEM NotificationDll;
256 
257  TRACE("CallNotificationDlls()\n");
258 
259  Info.Size = sizeof(WLX_NOTIFICATION_INFO);
260 
261  switch (Type)
262  {
263  case LogoffHandler:
264  case ShutdownHandler:
265  Info.Flags = 3;
266  break;
267 
268  default:
269  Info.Flags = 0;
270  break;
271  }
272 
273  Info.UserName = NULL; //UserName;
274  Info.Domain = NULL; //Domain;
275  Info.WindowStation = pSession->InteractiveWindowStationName;
276  Info.hToken = pSession->UserToken;
277 
278  switch (Type)
279  {
280  case LogonHandler:
281  case StartShellHandler:
282  Info.hDesktop = pSession->ApplicationDesktop;
283  break;
284 
286  Info.hDesktop = pSession->ApplicationDesktop;
287  break;
288 
289  default:
290  Info.hDesktop = pSession->WinlogonDesktop;
291  break;
292  }
293 
294  Info.pStatusCallback = NULL;
295 
296  ListEntry = NotificationDllListHead.Flink;
297  while (ListEntry != &NotificationDllListHead)
298  {
299 TRACE("ListEntry %p\n", ListEntry);
300 
301  NotificationDll = CONTAINING_RECORD(ListEntry,
303  ListEntry);
304 TRACE("NotificationDll: %p\n", NotificationDll);
305  if (NotificationDll != NULL && NotificationDll->bEnabled)
306  {
307 TRACE("NotificationDll->Handler: %p\n", NotificationDll->Handler[Type]);
308  if (NotificationDll->Handler[Type] != NULL)
309  NotificationDll->Handler[Type](&Info);
310  }
311 
312  ListEntry = ListEntry->Flink;
313  }
314 }
315 
316 
317 VOID
319 {
320  PLIST_ENTRY ListEntry;
321  PNOTIFICATION_ITEM NotificationDll;
322 
323  ListEntry = NotificationDllListHead.Flink;
324  while (ListEntry != &NotificationDllListHead)
325  {
326  NotificationDll = CONTAINING_RECORD(ListEntry,
328  ListEntry);
329  if (NotificationDll != NULL)
330  {
331  FreeLibrary(NotificationDll->hInstance);
332  }
333 
334  ListEntry = ListEntry->Flink;
335 
336  RemoveEntryList(&NotificationDll->ListEntry);
337 
338  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll);
339  }
340 }
341 
342 /* EOF */
struct _NOTIFICATION_ITEM NOTIFICATION_ITEM
enum _NOTIFICATION_TYPE NOTIFICATION_TYPE
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
#define TRUE
Definition: types.h:120
PWLX_NOTIFY_HANDLER Handler[LastHandler]
Definition: notify.c:46
HINSTANCE hInstance
Definition: notify.c:39
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
HDESK WinlogonDesktop
Definition: winlogon.h:224
#define KEY_READ
Definition: nt_native.h:1023
uint16_t * PWSTR
Definition: typedefs.h:54
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
char CHAR
Definition: xmlstorage.h:175
HANDLE UserToken
Definition: winlogon.h:227
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static LIST_ENTRY NotificationDllListHead
Definition: notify.c:50
BOOL bAsynchronous
Definition: notify.c:41
#define BOOL
Definition: nt_native.h:43
LIST_ENTRY ListEntry
Definition: notify.c:37
#define DWORD
Definition: nt_native.h:44
HDESK ApplicationDesktop
Definition: winlogon.h:223
struct TraceInfo Info
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOL InitNotifications(VOID)
Definition: notify.c:196
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
PWLX_NOTIFY_HANDLER GetNotificationHandler(HKEY hDllKey, HINSTANCE hInstance, PSTR pNotification)
Definition: notify.c:56
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOL bImpersonate
Definition: notify.c:43
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:405
struct _NOTIFICATION_ITEM * PNOTIFICATION_ITEM
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
static VOID LoadNotificationDll(HKEY hNotifyKey, PWSTR pKeyName)
Definition: notify.c:84
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL bSmartCardLogon
Definition: notify.c:44
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR InteractiveWindowStationName
Definition: winlogon.h:222
#define VOID
Definition: acefi.h:82
VOID CleanupNotifications(VOID)
Definition: notify.c:318
Definition: typedefs.h:117
static PSTR FuncNames[LastHandler]
Definition: notify.c:19
VOID(WINAPI * PWLX_NOTIFY_HANDLER)(PWLX_NOTIFICATION_INFO pInfo)
Definition: notify.c:17
VOID CallNotificationDlls(PWLSESSION pSession, NOTIFICATION_TYPE Type)
Definition: notify.c:249
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
DWORD dwMaxWait
Definition: notify.c:45
signed char * PSTR
Definition: retypes.h:7
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define GetProcAddress(x, y)
Definition: compat.h:410
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
struct _WLX_NOTIFICATION_INFO WLX_NOTIFICATION_INFO
BYTE * PBYTE
Definition: pedump.c:66
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019