ReactOS  0.4.15-dev-3203-gacde1e0
notify.c
Go to the documentation of this file.
1 /*
2  * PROJECT: Local Security Authority Server DLL
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: LSA policy change notifications
5  * COPYRIGHT: Eric Kohl 2018
6  */
7 
8 #include "lsasrv.h"
9 
11 {
18 
19 /* GLOBALS *****************************************************************/
20 
23 
24 
25 /* FUNCTIONS ***************************************************************/
26 
27 VOID
29 {
32 }
33 
34 
35 static
38  PLSA_API_MSG pRequestMsg)
39 {
41  PLSA_NOTIFICATION_ENTRY CurrentNotification;
42 
45  {
47 
48  if ((CurrentNotification->ClientId.UniqueProcess == pRequestMsg->h.ClientId.UniqueProcess) &&
49  (CurrentNotification->ClientId.UniqueThread == pRequestMsg->h.ClientId.UniqueThread) &&
50  (CurrentNotification->InformationClass == pRequestMsg->PolicyChangeNotify.Request.InformationClass) &&
51  (CurrentNotification->EventHandle == pRequestMsg->PolicyChangeNotify.Request.NotificationEventHandle))
52  return CurrentNotification;
53 
55  }
56 
57  return NULL;
58 }
59 
60 
61 static
64  PLSA_API_MSG pRequestMsg)
65 {
69 
70  TRACE("LsapAddNotification(%p)\n", pRequestMsg);
71 
72  /* Allocate a new notification list entry */
73  pEntry = RtlAllocateHeap(RtlGetProcessHeap(),
75  sizeof(LSA_NOTIFICATION_ENTRY));
76  if (pEntry == NULL)
77  {
79  goto done;
80  }
81 
82  /* Copy the notification data */
83  pEntry->InformationClass = pRequestMsg->PolicyChangeNotify.Request.InformationClass;
84  pEntry->EventHandle = pRequestMsg->PolicyChangeNotify.Request.NotificationEventHandle;
85  pEntry->ClientId = pRequestMsg->h.ClientId;
86 
87  /* Open the client process */
90  NULL,
91  pEntry->ClientId.UniqueProcess);
92  if (!NT_SUCCESS(Status))
93  {
94  ERR("NtOpenProcess() failed (Status 0x%08lx)\n", Status);
95  goto done;
96  }
97 
98  /* Duplicate the event handle into the current process */
100  pEntry->EventHandle,
102  &pEntry->MappedEventHandle,
103  0,
104  0,
106  if (!NT_SUCCESS(Status))
107  {
108  ERR("NtDuplicateObject() failed (Status 0x%08lx)\n", Status);
109  goto done;
110  }
111 
112  /* Insert the new entry into the notification list */
114  &pEntry->Entry);
115 
116 done:
117  if (hProcess != NULL)
118  NtClose(hProcess);
119 
120  if (!NT_SUCCESS(Status))
121  {
122  if (pEntry != NULL)
123  RtlFreeHeap(RtlGetProcessHeap(), 0, pEntry);
124  }
125 
126  return Status;
127 }
128 
129 
130 static
131 NTSTATUS
133  PLSA_API_MSG pRequestMsg)
134 {
136 
137  TRACE("LsapRemoveNotification(%p)\n", pRequestMsg);
138 
139  pEntry = LsapGetNotificationEntry(pRequestMsg);
140  if (pEntry == NULL)
141  {
142  return STATUS_INVALID_HANDLE;
143  }
144 
145  /* Remove the notification entry from the notification list */
146  RemoveEntryList(&pEntry->Entry);
147 
148  /* Close the mapped event handle */
149  NtClose(pEntry->MappedEventHandle);
150 
151  /* Release the notification entry */
152  RtlFreeHeap(RtlGetProcessHeap(), 0, pEntry);
153 
154  return STATUS_SUCCESS;
155 }
156 
157 
158 NTSTATUS
160  PLSA_API_MSG pRequestMsg)
161 {
163 
164  TRACE("LsapRegisterNotification(%p)\n", pRequestMsg);
165 
166  /* Acquire the notification list lock exclusively */
168 
169  if (pRequestMsg->PolicyChangeNotify.Request.Register)
170  {
171  /* Register the notification event */
172  Status = LsapAddNotification(pRequestMsg);
173  }
174  else
175  {
176  /* Unregister the notification event */
177  Status = LsapRemoveNotification(pRequestMsg);
178  }
179 
180  /* Release the notification list lock */
182 
183  return Status;
184 }
185 
186 
187 VOID
190 {
192  PLSA_NOTIFICATION_ENTRY CurrentNotification;
193 
194  TRACE("LsapNotifyPolicyChange(%lu)\n", InformationClass);
195 
196  /* Acquire the notification list lock shared */
198 
201  {
203 
204  if (CurrentNotification->InformationClass == InformationClass)
205  {
206  TRACE("Notify event %p\n", CurrentNotification->MappedEventHandle);
207  NtSetEvent(CurrentNotification->MappedEventHandle, NULL);
208  }
209 
211  }
212 
213  /* Release the notification list lock */
215 }
216 
217 /* EOF */
static NTSTATUS LsapAddNotification(PLSA_API_MSG pRequestMsg)
Definition: notify.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID LsapInitNotificationList(VOID)
Definition: notify.c:28
#define TRUE
Definition: types.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceShared(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
struct _LSA_POLICY_CHANGE_NOTIFY_MSG::@3423::@3425 Request
LSA_POLICY_CHANGE_NOTIFY_MSG PolicyChangeNotify
Definition: lsass.h:193
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
static NTSTATUS LsapRemoveNotification(PLSA_API_MSG pRequestMsg)
Definition: notify.c:132
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
Definition: notify.c:13
struct _LSA_NOTIFICATION_ENTRY LSA_NOTIFICATION_ENTRY
PORT_MESSAGE h
Definition: lsass.h:177
HANDLE UniqueProcess
Definition: compat.h:684
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1440
static RTL_RESOURCE NotificationListLock
Definition: notify.c:22
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
CLIENT_ID ClientId
Definition: notify.c:14
HANDLE MappedEventHandle
Definition: notify.c:16
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
_In_ ULONG _In_opt_ PVOID _In_ PDRIVER_OBJECT _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE _Inout_opt_ __drv_aliasesMem PVOID _Outptr_result_nullonfailure_ _At_ * NotificationEntry(return==0, __drv_allocatesMem(Mem))) PVOID *NotificationEntry
#define DUPLICATE_SAME_ACCESS
Definition: notify.c:10
#define PROCESS_DUP_HANDLE
enum _POLICY_NOTIFICATION_INFORMATION_CLASS POLICY_NOTIFICATION_INFORMATION_CLASS
HANDLE EventHandle
Definition: notify.c:15
static LIST_ENTRY NotificationListHead
Definition: notify.c:21
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
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
HANDLE UniqueThread
Definition: compat.h:685
Definition: typedefs.h:119
static PLSA_NOTIFICATION_ENTRY LsapGetNotificationEntry(PLSA_API_MSG pRequestMsg)
Definition: notify.c:37
#define ERR(fmt,...)
Definition: debug.h:110
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID LsapNotifyPolicyChange(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass)
Definition: notify.c:188
#define NULL
Definition: types.h:112
CLIENT_ID ClientId
Definition: winternl.h:1751
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NTSTATUS LsapRegisterNotification(PLSA_API_MSG pRequestMsg)
Definition: notify.c:159
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3406
LIST_ENTRY Entry
Definition: notify.c:12
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ FILTER_INFORMATION_CLASS InformationClass
Definition: fltkernel.h:1713
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
struct _LSA_NOTIFICATION_ENTRY * PLSA_NOTIFICATION_ENTRY
base of all file and directory entries
Definition: entries.h:82
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)