xref: /reactos/dll/win32/lsasrv/lsasrv.c (revision c2c66aff)
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     HANDLE hEvent;
275     DWORD dwError;
276     NTSTATUS Status;
277 
278     TRACE("LsapInitLsa() called\n");
279 
280     /* Initialize the well known SIDs */
281     LsapInitSids();
282 
283     /* Initialize the SRM server */
284     Status = LsapRmInitializeServer();
285     if (!NT_SUCCESS(Status))
286     {
287         ERR("LsapRmInitializeServer() failed (Status 0x%08lx)\n", Status);
288         return Status;
289     }
290 
291     /* Initialize the LSA database */
292     LsapInitDatabase();
293 
294     /* Initialize logon sessions */
295     LsapInitLogonSessions();
296 
297     /* Initialize registered authentication packages */
298     Status = LsapInitAuthPackages();
299     if (!NT_SUCCESS(Status))
300     {
301         ERR("LsapInitAuthPackages() failed (Status 0x%08lx)\n", Status);
302         return Status;
303     }
304 
305     /* Start the authentication port thread */
306     Status = StartAuthenticationPort();
307     if (!NT_SUCCESS(Status))
308     {
309         ERR("StartAuthenticationPort() failed (Status 0x%08lx)\n", Status);
310         return Status;
311     }
312 
313     /* Start the RPC server */
314     LsarStartRpcServer();
315 
316     TRACE("Creating notification event!\n");
317     /* Notify the service manager */
318     hEvent = CreateEventW(NULL,
319                           TRUE,
320                           FALSE,
321                           L"LSA_RPC_SERVER_ACTIVE");
322     if (hEvent == NULL)
323     {
324         dwError = GetLastError();
325         TRACE("Failed to create the notification event (Error %lu)\n", dwError);
326 
327         if (dwError == ERROR_ALREADY_EXISTS)
328         {
329             hEvent = OpenEventW(GENERIC_WRITE,
330                                 FALSE,
331                                 L"LSA_RPC_SERVER_ACTIVE");
332             if (hEvent == NULL)
333             {
334                ERR("Could not open the notification event (Error %lu)\n", GetLastError());
335                return STATUS_UNSUCCESSFUL;
336             }
337         }
338     }
339 
340     TRACE("Set notification event!\n");
341     SetEvent(hEvent);
342 
343     /* NOTE: Do not close the event handle!!!! */
344 
345     return STATUS_SUCCESS;
346 }
347 
348 
349 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
350 {
351     return RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len);
352 }
353 
354 
355 void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
356 {
357     RtlFreeHeap(RtlGetProcessHeap(), 0, ptr);
358 }
359 
360 /* EOF */
361