ReactOS  0.4.14-dev-604-gcfdd483
notify.c File Reference
#include "winlogon.h"
Include dependency graph for notify.c:

Go to the source code of this file.

Classes

struct  _NOTIFICATION_ITEM
 

Typedefs

typedef VOID(WINAPIPWLX_NOTIFY_HANDLER) (PWLX_NOTIFICATION_INFO pInfo)
 
typedef struct _NOTIFICATION_ITEM NOTIFICATION_ITEM
 
typedef struct _NOTIFICATION_ITEMPNOTIFICATION_ITEM
 

Functions

static VOID AddNotificationDll (HKEY hNotifyKey, PWSTR pszKeyName)
 
BOOL InitNotifications (VOID)
 
static VOID CallNotificationDll (HKEY hNotifyKey, PNOTIFICATION_ITEM NotificationDll, NOTIFICATION_TYPE Type, PWLX_NOTIFICATION_INFO pInfo)
 
VOID CallNotificationDlls (PWLSESSION pSession, NOTIFICATION_TYPE Type)
 
VOID CleanupNotifications (VOID)
 

Variables

static PSTR FuncNames [LastHandler]
 
static LIST_ENTRY NotificationDllListHead
 

Typedef Documentation

◆ NOTIFICATION_ITEM

◆ PNOTIFICATION_ITEM

◆ PWLX_NOTIFY_HANDLER

typedef VOID(WINAPI * PWLX_NOTIFY_HANDLER) (PWLX_NOTIFICATION_INFO pInfo)

Definition at line 17 of file notify.c.

Function Documentation

◆ AddNotificationDll()

static VOID AddNotificationDll ( HKEY  hNotifyKey,
PWSTR  pszKeyName 
)
static

Definition at line 56 of file notify.c.

59 {
60  HKEY hDllKey = NULL;
61  PNOTIFICATION_ITEM NotificationDll = NULL;
62  DWORD dwSize, dwType;
63  DWORD dwError;
64 
65  TRACE("AddNotificationDll(%p %S)\n", hNotifyKey, pszKeyName);
66 
67  dwError = RegOpenKeyExW(hNotifyKey,
68  pszKeyName,
69  0,
70  KEY_READ,
71  &hDllKey);
72  if (dwError != ERROR_SUCCESS)
73  return;
74 
75  NotificationDll = RtlAllocateHeap(RtlGetProcessHeap(),
77  sizeof(NOTIFICATION_ITEM));
78  if (NotificationDll == NULL)
79  {
80  dwError = ERROR_OUTOFMEMORY;
81  goto done;
82  }
83 
84  NotificationDll->pszKeyName = RtlAllocateHeap(RtlGetProcessHeap(),
86  (wcslen(pszKeyName) + 1) * sizeof(WCHAR));
87  if (NotificationDll->pszKeyName == NULL)
88  {
89  dwError = ERROR_OUTOFMEMORY;
90  goto done;
91  }
92 
93  wcscpy(NotificationDll->pszKeyName, pszKeyName);
94 
95  dwSize = 0;
96  RegQueryValueExW(hDllKey,
97  L"DllName",
98  NULL,
99  &dwType,
100  NULL,
101  &dwSize);
102  if (dwSize == 0)
103  {
104  dwError = ERROR_FILE_NOT_FOUND;
105  goto done;
106  }
107 
108  NotificationDll->pszDllName = RtlAllocateHeap(RtlGetProcessHeap(),
110  dwSize);
111  if (NotificationDll->pszDllName == NULL)
112  {
113  dwError = ERROR_OUTOFMEMORY;
114  goto done;
115  }
116 
117  dwError = RegQueryValueExW(hDllKey,
118  L"DllName",
119  NULL,
120  &dwType,
121  (PBYTE)NotificationDll->pszDllName,
122  &dwSize);
123  if (dwError != ERROR_SUCCESS)
124  goto done;
125 
126  NotificationDll->bEnabled = TRUE;
127  NotificationDll->dwMaxWait = 30; /* FIXME: ??? */
128 
129  dwSize = sizeof(BOOL);
130  RegQueryValueExW(hDllKey,
131  L"Asynchronous",
132  NULL,
133  &dwType,
134  (PBYTE)&NotificationDll->bAsynchronous,
135  &dwSize);
136 
137  dwSize = sizeof(BOOL);
138  RegQueryValueExW(hDllKey,
139  L"Enabled",
140  NULL,
141  &dwType,
142  (PBYTE)&NotificationDll->bEnabled,
143  &dwSize);
144 
145  dwSize = sizeof(BOOL);
146  RegQueryValueExW(hDllKey,
147  L"Impersonate",
148  NULL,
149  &dwType,
150  (PBYTE)&NotificationDll->bImpersonate,
151  &dwSize);
152 
153  dwSize = sizeof(BOOL);
154  RegQueryValueExW(hDllKey,
155  L"Safe",
156  NULL,
157  &dwType,
158  (PBYTE)&NotificationDll->bSafe,
159  &dwSize);
160 
161  dwSize = sizeof(BOOL);
162  RegQueryValueExW(hDllKey,
163  L"SmartCardLogonNotify",
164  NULL,
165  &dwType,
166  (PBYTE)&NotificationDll->bSmartCardLogon,
167  &dwSize);
168 
169  dwSize = sizeof(DWORD);
170  RegQueryValueExW(hDllKey,
171  L"MaxWait",
172  NULL,
173  &dwType,
174  (PBYTE)&NotificationDll->dwMaxWait,
175  &dwSize);
176 
178  &NotificationDll->ListEntry);
179 
180 done:
181  if (dwError != ERROR_SUCCESS)
182  {
183  if (NotificationDll != NULL)
184  {
185  if (NotificationDll->pszKeyName != NULL)
186  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll->pszKeyName);
187 
188  if (NotificationDll->pszDllName != NULL)
189  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll->pszDllName);
190 
191  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll);
192  }
193  }
194 
195  RegCloseKey(hDllKey);
196 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
PWSTR pszKeyName
Definition: notify.c:38
#define KEY_READ
Definition: nt_native.h:1023
PWSTR pszDllName
Definition: notify.c:39
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static LIST_ENTRY NotificationDllListHead
Definition: notify.c:49
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOL bImpersonate
Definition: notify.c:43
#define TRACE(s)
Definition: solgame.cpp:4
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
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL bSmartCardLogon
Definition: notify.c:44
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
DWORD dwMaxWait
Definition: notify.c:45
#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
BYTE * PBYTE
Definition: pedump.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by InitNotifications().

◆ CallNotificationDll()

static VOID CallNotificationDll ( HKEY  hNotifyKey,
PNOTIFICATION_ITEM  NotificationDll,
NOTIFICATION_TYPE  Type,
PWLX_NOTIFICATION_INFO  pInfo 
)
static

Definition at line 254 of file notify.c.

259 {
260  HKEY hDllKey = NULL;
261  HMODULE hModule = NULL;
262  CHAR szFuncBuffer[128];
263  DWORD dwSize;
264  DWORD dwType;
265  DWORD dwError;
266  PWLX_NOTIFY_HANDLER pNotifyHandler;
267 
268  dwError = RegOpenKeyExW(hNotifyKey,
269  NotificationDll->pszKeyName,
270  0,
271  KEY_READ,
272  &hDllKey);
273  if (dwError != ERROR_SUCCESS)
274  {
275  TRACE("RegOpenKeyExW()\n");
276  return;
277  }
278 
279  dwSize = sizeof(szFuncBuffer);
280  dwError = RegQueryValueExA(hDllKey,
281  FuncNames[Type],
282  NULL,
283  &dwType,
284  (PBYTE)szFuncBuffer,
285  &dwSize);
286  if (dwError == ERROR_SUCCESS)
287  {
288  hModule = LoadLibraryW(NotificationDll->pszDllName);
289  if (hModule != NULL)
290  {
291  pNotifyHandler = (PWLX_NOTIFY_HANDLER)GetProcAddress(hModule, szFuncBuffer);
292  if (pNotifyHandler != NULL)
293  pNotifyHandler(pInfo);
294 
296  }
297  }
298 
299  RegCloseKey(hDllKey);
300 }
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
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
PWSTR pszKeyName
Definition: notify.c:38
#define KEY_READ
Definition: nt_native.h:1023
PWSTR pszDllName
Definition: notify.c:39
char CHAR
Definition: xmlstorage.h:175
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define LoadLibraryW(x)
Definition: compat.h:412
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:413
unsigned long DWORD
Definition: ntddk_ex.h:95
static PSTR FuncNames[LastHandler]
Definition: notify.c:19
VOID(WINAPI * PWLX_NOTIFY_HANDLER)(PWLX_NOTIFICATION_INFO pInfo)
Definition: notify.c:17
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define GetProcAddress(x, y)
Definition: compat.h:418
BYTE * PBYTE
Definition: pedump.c:66
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
HMODULE hModule
Definition: animate.c:44

Referenced by CallNotificationDlls().

◆ CallNotificationDlls()

VOID CallNotificationDlls ( PWLSESSION  pSession,
NOTIFICATION_TYPE  Type 
)

Definition at line 304 of file notify.c.

307 {
308  PLIST_ENTRY ListEntry;
309  PNOTIFICATION_ITEM NotificationDll;
311  HKEY hNotifyKey = NULL;
312  DWORD dwError;
313 
314  TRACE("CallNotificationDlls()\n");
315 
317  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify",
318  0,
320  &hNotifyKey);
321  if (dwError != ERROR_SUCCESS)
322  {
323  TRACE("RegOpenKeyExW()\n");
324  return;
325  }
326 
327  Info.Size = sizeof(WLX_NOTIFICATION_INFO);
328 
329  switch (Type)
330  {
331  case LogoffHandler:
332  case ShutdownHandler:
333  Info.Flags = 3;
334  break;
335 
336  default:
337  Info.Flags = 0;
338  break;
339  }
340 
341  Info.UserName = NULL; //UserName;
342  Info.Domain = NULL; //Domain;
343  Info.WindowStation = pSession->InteractiveWindowStationName;
344  Info.hToken = pSession->UserToken;
345 
346  switch (Type)
347  {
348  case LogonHandler:
349  case StartShellHandler:
350  Info.hDesktop = pSession->ApplicationDesktop;
351  break;
352 
354  Info.hDesktop = pSession->ApplicationDesktop;
355  break;
356 
357  default:
358  Info.hDesktop = pSession->WinlogonDesktop;
359  break;
360  }
361 
362  Info.pStatusCallback = NULL;
363 
364  ListEntry = NotificationDllListHead.Flink;
365  while (ListEntry != &NotificationDllListHead)
366  {
367 TRACE("ListEntry %p\n", ListEntry);
368 
369  NotificationDll = CONTAINING_RECORD(ListEntry,
371  ListEntry);
372 TRACE("NotificationDll: %p\n", NotificationDll);
373  if (NotificationDll != NULL && NotificationDll->bEnabled)
374  CallNotificationDll(hNotifyKey, NotificationDll, Type, &Info);
375 
376  ListEntry = ListEntry->Flink;
377  }
378 
379  RegCloseKey(hNotifyKey);
380 }
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
HANDLE UserToken
Definition: winlogon.h:227
static LIST_ENTRY NotificationDllListHead
Definition: notify.c:49
HDESK ApplicationDesktop
Definition: winlogon.h:223
struct TraceInfo Info
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR InteractiveWindowStationName
Definition: winlogon.h:222
Definition: typedefs.h:117
static VOID CallNotificationDll(HKEY hNotifyKey, PNOTIFICATION_ITEM NotificationDll, NOTIFICATION_TYPE Type, PWLX_NOTIFICATION_INFO pInfo)
Definition: notify.c:254
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
struct _WLX_NOTIFICATION_INFO WLX_NOTIFICATION_INFO
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019

Referenced by DoGenericAction(), HandleLogoff(), HandleLogon(), HandleShutdown(), StartScreenSaver(), and WinMain().

◆ CleanupNotifications()

VOID CleanupNotifications ( VOID  )

Definition at line 384 of file notify.c.

385 {
386  PLIST_ENTRY ListEntry;
387  PNOTIFICATION_ITEM NotificationDll;
388 
389  ListEntry = NotificationDllListHead.Flink;
390  while (ListEntry != &NotificationDllListHead)
391  {
392  NotificationDll = CONTAINING_RECORD(ListEntry,
394  ListEntry);
395  if (NotificationDll != NULL)
396  {
397  if (NotificationDll->pszKeyName != NULL)
398  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll->pszKeyName);
399 
400  if (NotificationDll->pszDllName != NULL)
401  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll->pszDllName);
402  }
403 
404  ListEntry = ListEntry->Flink;
405 
406  RemoveEntryList(&NotificationDll->ListEntry);
407 
408  RtlFreeHeap(RtlGetProcessHeap(), 0, NotificationDll);
409  }
410 }
PWSTR pszKeyName
Definition: notify.c:38
PWSTR pszDllName
Definition: notify.c:39
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static LIST_ENTRY NotificationDllListHead
Definition: notify.c:49
LIST_ENTRY ListEntry
Definition: notify.c:37
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117

Referenced by WinMain().

◆ InitNotifications()

BOOL InitNotifications ( VOID  )

Definition at line 200 of file notify.c.

201 {
202  HKEY hNotifyKey = NULL;
203  LONG lError;
204  DWORD dwIndex;
205  WCHAR szKeyName[80];
206  DWORD dwKeyName;
207 
208  TRACE("InitNotifications()\n");
209 
211 
213  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify",
214  0,
216  &hNotifyKey);
217  if (lError != ERROR_SUCCESS)
218  {
219  TRACE("RegOpenKeyExW()\n");
220  return TRUE;
221  }
222 
223  dwIndex = 0;
224  for(;;)
225  {
226  dwKeyName = 80 * sizeof(WCHAR);
227  lError = RegEnumKeyExW(hNotifyKey,
228  dwIndex,
229  szKeyName,
230  &dwKeyName,
231  NULL,
232  NULL,
233  NULL,
234  NULL);
235  if (lError != ERROR_SUCCESS)
236  break;
237 
238  TRACE("Notification DLL: %S\n", szKeyName);
239  AddNotificationDll(hNotifyKey, szKeyName);
240 
241  dwIndex++;
242  }
243 
244  RegCloseKey(hNotifyKey);
245 
246  TRACE("InitNotifications() done\n");
247 
248  return TRUE;
249 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
static LIST_ENTRY NotificationDllListHead
Definition: notify.c:49
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
static VOID AddNotificationDll(HKEY hNotifyKey, PWSTR pszKeyName)
Definition: notify.c:56
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
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
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019

Referenced by WinMain().

Variable Documentation

◆ FuncNames

PSTR FuncNames[LastHandler]
static
Initial value:
=
{
"Logon",
"Logoff",
"Lock",
"Unlock",
"Startup",
"Shutdown",
"StartScreenSaver",
"StopScreenSaver",
"Disconnect",
"Reconnect",
"StartShell",
"PostShell"
}

Definition at line 19 of file notify.c.

Referenced by CallNotificationDll().

◆ NotificationDllListHead

LIST_ENTRY NotificationDllListHead
static