[LSASRV][SECUR32] Implement LsaRegisterPolicyChangeNotification and LsaUnregisterPoli...
[reactos.git] / dll / win32 / lsasrv / lsasrv.c
1 /*
2 * PROJECT: Local Security Authority Server DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/lsasrv/lsasrv.c
5 * PURPOSE: Main file
6 * COPYRIGHT: Copyright 2006-2009 Eric Kohl
7 */
8
9 /* INCLUDES ****************************************************************/
10
11 #include "lsasrv.h"
12
13 /* FUNCTIONS ***************************************************************/
14
15 VOID
16 NTAPI
17 LsaIFree_LSAPR_ACCOUNT_ENUM_BUFFER(
18 IN PLSAPR_ACCOUNT_ENUM_BUFFER Ptr)
19 {
20 ULONG i;
21
22 if (Ptr == NULL)
23 return;
24
25 if (Ptr->Information != NULL)
26 {
27 for (i = 0; i < Ptr->EntriesRead; i++)
28 midl_user_free(Ptr->Information[i].Sid);
29
30 midl_user_free(Ptr->Information);
31 }
32
33 midl_user_free(Ptr);
34 }
35
36
37 VOID
38 NTAPI
39 LsaIFree_LSAPR_CR_CIPHER_VALUE(
40 IN PLSAPR_CR_CIPHER_VALUE Ptr)
41 {
42 if (Ptr != NULL)
43 midl_user_free(Ptr);
44 }
45
46
47 VOID
48 NTAPI
49 LsaIFree_LSAPR_POLICY_INFORMATION(IN POLICY_INFORMATION_CLASS InformationClass,
50 IN PLSAPR_POLICY_INFORMATION PolicyInformation)
51 {
52 if (PolicyInformation != NULL)
53 {
54 switch (InformationClass)
55 {
56 case PolicyAuditLogInformation: /* 1 */
57 break;
58
59 case PolicyAuditEventsInformation: /* 2 */
60 if (PolicyInformation->PolicyAuditEventsInfo.EventAuditingOptions != NULL)
61 midl_user_free(PolicyInformation->PolicyAuditEventsInfo.EventAuditingOptions);
62 break;
63
64 case PolicyPrimaryDomainInformation: /* 3 */
65 if (PolicyInformation->PolicyPrimaryDomInfo.Name.Buffer != NULL)
66 midl_user_free(PolicyInformation->PolicyPrimaryDomInfo.Name.Buffer);
67
68 if (PolicyInformation->PolicyPrimaryDomInfo.Sid != NULL)
69 midl_user_free(PolicyInformation->PolicyPrimaryDomInfo.Sid);
70 break;
71
72 case PolicyPdAccountInformation: /* 4 */
73 if (PolicyInformation->PolicyPdAccountInfo.Name.Buffer != NULL)
74 midl_user_free(PolicyInformation->PolicyPdAccountInfo.Name.Buffer);
75 break;
76
77 case PolicyAccountDomainInformation: /* 5 */
78 if (PolicyInformation->PolicyAccountDomainInfo.DomainName.Buffer != NULL)
79 midl_user_free(PolicyInformation->PolicyAccountDomainInfo.DomainName.Buffer);
80
81 if (PolicyInformation->PolicyAccountDomainInfo.Sid != NULL)
82 midl_user_free(PolicyInformation->PolicyAccountDomainInfo.Sid);
83 break;
84
85 case PolicyLsaServerRoleInformation: /* 6 */
86 break;
87
88 case PolicyReplicaSourceInformation: /* 7 */
89 if (PolicyInformation->PolicyReplicaSourceInfo.ReplicaSource.Buffer != NULL)
90 midl_user_free(PolicyInformation->PolicyReplicaSourceInfo.ReplicaSource.Buffer);
91
92 if (PolicyInformation->PolicyReplicaSourceInfo.ReplicaAccountName.Buffer != NULL)
93 midl_user_free(PolicyInformation->PolicyReplicaSourceInfo.ReplicaAccountName.Buffer);
94 break;
95
96 case PolicyDefaultQuotaInformation: /* 8 */
97 break;
98
99 case PolicyModificationInformation: /* 9 */
100 break;
101
102 case PolicyAuditFullSetInformation: /* 10 (0xA) */
103 break;
104
105 case PolicyAuditFullQueryInformation: /* 11 (0xB) */
106 break;
107
108 case PolicyDnsDomainInformation: /* 12 (0xC) */
109 if (PolicyInformation->PolicyDnsDomainInfo.Name.Buffer != NULL)
110 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.Name.Buffer);
111
112 if (PolicyInformation->PolicyDnsDomainInfo.DnsDomainName.Buffer != NULL)
113 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.DnsDomainName.Buffer);
114
115 if (PolicyInformation->PolicyDnsDomainInfo.DnsForestName.Buffer != NULL)
116 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.DnsForestName.Buffer);
117
118 if (PolicyInformation->PolicyDnsDomainInfo.Sid != NULL)
119 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.Sid);
120 break;
121
122 case PolicyDnsDomainInformationInt: /* 13 (0xD) */
123 if (PolicyInformation->PolicyDnsDomainInfoInt.Name.Buffer != NULL)
124 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.Name.Buffer);
125
126 if (PolicyInformation->PolicyDnsDomainInfoInt.DnsDomainName.Buffer != NULL)
127 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.DnsDomainName.Buffer);
128
129 if (PolicyInformation->PolicyDnsDomainInfoInt.DnsForestName.Buffer != NULL)
130 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.DnsForestName.Buffer);
131
132 if (PolicyInformation->PolicyDnsDomainInfoInt.Sid != NULL)
133 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.Sid);
134 break;
135
136 case PolicyLocalAccountDomainInformation: /* 14 (0xE) */
137 if (PolicyInformation->PolicyLocalAccountDomainInfo.DomainName.Buffer != NULL)
138 midl_user_free(PolicyInformation->PolicyLocalAccountDomainInfo.DomainName.Buffer);
139
140 if (PolicyInformation->PolicyLocalAccountDomainInfo.Sid != NULL)
141 midl_user_free(PolicyInformation->PolicyLocalAccountDomainInfo.Sid);
142 break;
143
144 default:
145 ERR("Invalid InformationClass: %lu\n", InformationClass);
146 break;
147 }
148
149 midl_user_free(PolicyInformation);
150 }
151 }
152
153
154 VOID
155 NTAPI
156 LsaIFree_LSAPR_PRIVILEGE_ENUM_BUFFER(
157 IN PLSAPR_PRIVILEGE_ENUM_BUFFER Ptr)
158 {
159 ULONG i;
160
161 if (Ptr != NULL)
162 {
163 if (Ptr->Privileges != NULL)
164 {
165 for (i = 0; i < Ptr->Entries; i++)
166 {
167 if (Ptr->Privileges[i].Name.Buffer != NULL)
168 midl_user_free(Ptr->Privileges[i].Name.Buffer);
169 }
170
171 midl_user_free(Ptr->Privileges);
172 }
173 }
174 }
175
176
177 VOID
178 NTAPI
179 LsaIFree_LSAPR_PRIVILEGE_SET(IN PLSAPR_PRIVILEGE_SET Ptr)
180 {
181 if (Ptr != NULL)
182 {
183 midl_user_free(Ptr);
184 }
185 }
186
187
188 VOID
189 NTAPI
190 LsaIFree_LSAPR_REFERENCED_DOMAIN_LIST(
191 IN PLSAPR_REFERENCED_DOMAIN_LIST Ptr)
192 {
193 ULONG i;
194
195 if (Ptr != NULL)
196 {
197 if (Ptr->Domains != NULL)
198 {
199 for (i = 0; i < Ptr->Entries; i++)
200 {
201 if (Ptr->Domains[i].Name.Buffer != NULL)
202 midl_user_free(Ptr->Domains[i].Name.Buffer);
203
204 if (Ptr->Domains[i].Sid != NULL)
205 midl_user_free(Ptr->Domains[i].Sid);
206 }
207
208 midl_user_free(Ptr->Domains);
209 }
210
211 midl_user_free(Ptr);
212 }
213 }
214
215
216 VOID
217 NTAPI
218 LsaIFree_LSAPR_SR_SECURITY_DESCRIPTOR(
219 IN PLSAPR_SR_SECURITY_DESCRIPTOR Ptr)
220 {
221 if (Ptr != NULL)
222 {
223 if (Ptr->SecurityDescriptor != NULL)
224 midl_user_free(Ptr->SecurityDescriptor);
225
226 midl_user_free(Ptr);
227 }
228 }
229
230
231 VOID
232 NTAPI
233 LsaIFree_LSAPR_TRANSLATED_NAMES(
234 IN PLSAPR_TRANSLATED_NAMES Ptr)
235 {
236 ULONG i;
237
238 if (Ptr != NULL)
239 {
240 if (Ptr->Names != NULL)
241 {
242 for (i = 0; i < Ptr->Entries; i++)
243 {
244 if (Ptr->Names[i].Name.Buffer != NULL)
245 midl_user_free(Ptr->Names[i].Name.Buffer);
246 }
247
248 midl_user_free(Ptr->Names);
249 }
250
251 midl_user_free(Ptr);
252 }
253 }
254
255
256 VOID
257 NTAPI
258 LsaIFree_LSAPR_TRANSLATED_SIDS(
259 IN PLSAPR_TRANSLATED_SIDS Ptr)
260 {
261 if (Ptr != NULL)
262 {
263 if (Ptr->Sids != NULL)
264 midl_user_free(Ptr->Sids);
265
266 midl_user_free(Ptr);
267 }
268 }
269
270
271 NTSTATUS WINAPI
272 LsapInitLsa(VOID)
273 {
274 NTSTATUS Status;
275 BOOLEAN PrivilegeEnabled;
276
277 TRACE("LsapInitLsa() called\n");
278
279 /* Initialize the well known SIDs */
280 LsapInitSids();
281
282 /* Initialize the SRM server */
283 Status = LsapRmInitializeServer();
284 if (!NT_SUCCESS(Status))
285 {
286 ERR("LsapRmInitializeServer() failed (Status 0x%08lx)\n", Status);
287 return Status;
288 }
289
290 /* Initialize the LSA database */
291 LsapInitDatabase();
292
293 /* Initialize logon sessions */
294 LsapInitLogonSessions();
295
296 /* Initialize the notification list */
297 LsapInitNotificationList();
298
299 /* Initialize registered authentication packages */
300 Status = LsapInitAuthPackages();
301 if (!NT_SUCCESS(Status))
302 {
303 ERR("LsapInitAuthPackages() failed (Status 0x%08lx)\n", Status);
304 return Status;
305 }
306
307 /* Enable the token creation privilege for the rest of our lifetime */
308 Status = RtlAdjustPrivilege(SE_CREATE_TOKEN_PRIVILEGE, TRUE, FALSE, &PrivilegeEnabled);
309 if (!NT_SUCCESS(Status))
310 {
311 ERR("RtlAdjustPrivilege(SE_CREATE_TOKEN_PRIVILEGE) failed, ignoring (Status 0x%08lx)\n", Status);
312 }
313
314 /* Start the authentication LPC port thread */
315 Status = StartAuthenticationPort();
316 if (!NT_SUCCESS(Status))
317 {
318 ERR("StartAuthenticationPort() failed (Status 0x%08lx)\n", Status);
319 return Status;
320 }
321
322 /* Start the RPC server */
323 Status = LsarStartRpcServer();
324 if (!NT_SUCCESS(Status))
325 {
326 ERR("LsarStartRpcServer() failed (Status 0x%08lx)\n", Status);
327 return Status;
328 }
329
330 return STATUS_SUCCESS;
331 }
332
333
334 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
335 {
336 return RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len);
337 }
338
339
340 void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
341 {
342 RtlFreeHeap(RtlGetProcessHeap(), 0, ptr);
343 }
344
345 /* EOF */