48f09c7ecf13b26bb39cb0eb097ef207f5d22e1d
[reactos.git] / dll / win32 / lsasrv / notify.c
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
10 typedef struct _LSA_NOTIFICATION_ENTRY
11 {
12 LIST_ENTRY Entry;
13 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass;
14 HANDLE EventHandle;
15 } LSA_NOTIFICATION_ENTRY, *PLSA_NOTIFICATION_ENTRY;
16
17 /* GLOBALS *****************************************************************/
18
19 static LIST_ENTRY NotificationListHead;
20 static RTL_RESOURCE NotificationListLock;
21
22
23 /* FUNCTIONS ***************************************************************/
24
25 VOID
26 LsapInitNotificationList(VOID)
27 {
28 InitializeListHead(&NotificationListHead);
29 RtlInitializeResource(&NotificationListLock);
30 }
31
32
33 static
34 PLSA_NOTIFICATION_ENTRY
35 LsapGetNotificationEntryByHandle(
36 HANDLE EventHandle)
37 {
38 PLIST_ENTRY NotificationEntry;
39 PLSA_NOTIFICATION_ENTRY CurrentNotification;
40
41 NotificationEntry = NotificationListHead.Flink;
42 while (NotificationEntry != &NotificationListHead)
43 {
44 CurrentNotification = CONTAINING_RECORD(NotificationEntry, LSA_NOTIFICATION_ENTRY, Entry);
45
46 if (CurrentNotification->EventHandle == EventHandle)
47 return CurrentNotification;
48
49 NotificationEntry = NotificationEntry->Flink;
50 }
51
52 return NULL;
53 }
54
55
56 NTSTATUS
57 LsapRegisterNotification(
58 PLSA_API_MSG pRequestMsg)
59 {
60 PLSA_NOTIFICATION_ENTRY pEntry;
61 NTSTATUS Status = STATUS_SUCCESS;
62
63 FIXME("LsapRegisterNotification(%p)\n", pRequestMsg);
64
65 /* Acquire the notification list lock exclusively */
66 RtlAcquireResourceExclusive(&NotificationListLock, TRUE);
67
68 if (pRequestMsg->PolicyChangeNotify.Request.Register)
69 {
70 pEntry = RtlAllocateHeap(RtlGetProcessHeap(),
71 HEAP_ZERO_MEMORY,
72 sizeof(LSA_NOTIFICATION_ENTRY));
73 if (pEntry == NULL)
74 {
75 Status = STATUS_INSUFFICIENT_RESOURCES;
76 goto done;
77 }
78
79 pEntry->InformationClass = pRequestMsg->PolicyChangeNotify.Request.InformationClass;
80 pEntry->EventHandle = pRequestMsg->PolicyChangeNotify.Request.NotificationEventHandle;
81
82 InsertHeadList(&NotificationListHead,
83 &pEntry->Entry);
84 }
85 else
86 {
87 pEntry = LsapGetNotificationEntryByHandle(pRequestMsg->PolicyChangeNotify.Request.NotificationEventHandle);
88 if (pEntry)
89 {
90 RemoveEntryList(&pEntry->Entry);
91 RtlFreeHeap(RtlGetProcessHeap(), 0, pEntry);
92 }
93 }
94
95 done:
96 /* Release the notification list lock */
97 RtlReleaseResource(&NotificationListLock);
98
99 return Status;
100 }
101
102 /* EOF */