ReactOS 0.4.16-dev-401-g45b008d
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
27VOID
29{
32}
33
34
35static
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
61static
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(),
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
116done:
117 if (hProcess != NULL)
119
120 if (!NT_SUCCESS(Status))
121 {
122 if (pEntry != NULL)
123 RtlFreeHeap(RtlGetProcessHeap(), 0, pEntry);
124 }
125
126 return Status;
127}
128
129
130static
133 PLSA_API_MSG pRequestMsg)
134{
136
137 TRACE("LsapRemoveNotification(%p)\n", pRequestMsg);
138
139 pEntry = LsapGetNotificationEntry(pRequestMsg);
140 if (pEntry == NULL)
141 {
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
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
187VOID
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 */
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static PLSA_NOTIFICATION_ENTRY LsapGetNotificationEntry(PLSA_API_MSG pRequestMsg)
Definition: notify.c:37
VOID LsapInitNotificationList(VOID)
Definition: notify.c:28
NTSTATUS LsapRegisterNotification(PLSA_API_MSG pRequestMsg)
Definition: notify.c:159
static LIST_ENTRY NotificationListHead
Definition: notify.c:21
struct _LSA_NOTIFICATION_ENTRY LSA_NOTIFICATION_ENTRY
static RTL_RESOURCE NotificationListLock
Definition: notify.c:22
VOID LsapNotifyPolicyChange(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass)
Definition: notify.c:188
static NTSTATUS LsapAddNotification(PLSA_API_MSG pRequestMsg)
Definition: notify.c:63
struct _LSA_NOTIFICATION_ENTRY * PLSA_NOTIFICATION_ENTRY
static NTSTATUS LsapRemoveNotification(PLSA_API_MSG pRequestMsg)
Definition: notify.c:132
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertHeadList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ FILTER_INFORMATION_CLASS InformationClass
Definition: fltkernel.h:1713
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
Status
Definition: gdiplustypes.h:25
#define PROCESS_DUP_HANDLE
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceShared(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1440
enum _POLICY_NOTIFICATION_INFORMATION_CLASS POLICY_NOTIFICATION_INFORMATION_CLASS
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:3410
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
base of all file and directory entries
Definition: entries.h:83
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PORT_MESSAGE h
Definition: lsass.h:183
LSA_POLICY_CHANGE_NOTIFY_MSG PolicyChangeNotify
Definition: lsass.h:199
Definition: notify.c:11
LIST_ENTRY Entry
Definition: notify.c:12
HANDLE MappedEventHandle
Definition: notify.c:16
POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
Definition: notify.c:13
HANDLE EventHandle
Definition: notify.c:15
CLIENT_ID ClientId
Definition: notify.c:14
struct _LSA_POLICY_CHANGE_NOTIFY_MSG::@3519::@3521 Request
CLIENT_ID ClientId
Definition: winternl.h:1751
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_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