[NTOSKRNL][LSASRV]
[reactos.git] / reactos / 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_POLICY_INFORMATION(IN POLICY_INFORMATION_CLASS InformationClass,
18 IN PLSAPR_POLICY_INFORMATION PolicyInformation)
19 {
20 if (PolicyInformation != NULL)
21 {
22 switch (InformationClass)
23 {
24 case PolicyAuditLogInformation: /* 1 */
25 break;
26
27 case PolicyAuditEventsInformation: /* 2 */
28 if (PolicyInformation->PolicyAuditEventsInfo.EventAuditingOptions != NULL)
29 midl_user_free(PolicyInformation->PolicyAuditEventsInfo.EventAuditingOptions);
30 break;
31
32 case PolicyPrimaryDomainInformation: /* 3 */
33 if (PolicyInformation->PolicyPrimaryDomInfo.Name.Buffer != NULL)
34 midl_user_free(PolicyInformation->PolicyPrimaryDomInfo.Name.Buffer);
35
36 if (PolicyInformation->PolicyPrimaryDomInfo.Sid != NULL)
37 midl_user_free(PolicyInformation->PolicyPrimaryDomInfo.Sid);
38 break;
39
40 case PolicyPdAccountInformation: /* 4 */
41 if (PolicyInformation->PolicyPdAccountInfo.Name.Buffer != NULL)
42 midl_user_free(PolicyInformation->PolicyPdAccountInfo.Name.Buffer);
43 break;
44
45 case PolicyAccountDomainInformation: /* 5 */
46 if (PolicyInformation->PolicyAccountDomainInfo.DomainName.Buffer != NULL)
47 midl_user_free(PolicyInformation->PolicyAccountDomainInfo.DomainName.Buffer);
48
49 if (PolicyInformation->PolicyAccountDomainInfo.Sid != NULL)
50 midl_user_free(PolicyInformation->PolicyAccountDomainInfo.Sid);
51 break;
52
53 case PolicyLsaServerRoleInformation: /* 6 */
54 break;
55
56 case PolicyReplicaSourceInformation: /* 7 */
57 if (PolicyInformation->PolicyReplicaSourceInfo.ReplicaSource.Buffer != NULL)
58 midl_user_free(PolicyInformation->PolicyReplicaSourceInfo.ReplicaSource.Buffer);
59
60 if (PolicyInformation->PolicyReplicaSourceInfo.ReplicaAccountName.Buffer != NULL)
61 midl_user_free(PolicyInformation->PolicyReplicaSourceInfo.ReplicaAccountName.Buffer);
62 break;
63
64 case PolicyDefaultQuotaInformation: /* 8 */
65 break;
66
67 case PolicyModificationInformation: /* 9 */
68 break;
69
70 case PolicyAuditFullSetInformation: /* 10 (0xA) */
71 break;
72
73 case PolicyAuditFullQueryInformation: /* 11 (0xB) */
74 break;
75
76 case PolicyDnsDomainInformation: /* 12 (0xC) */
77 if (PolicyInformation->PolicyDnsDomainInfo.Name.Buffer != NULL)
78 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.Name.Buffer);
79
80 if (PolicyInformation->PolicyDnsDomainInfo.DnsDomainName.Buffer != NULL)
81 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.DnsDomainName.Buffer);
82
83 if (PolicyInformation->PolicyDnsDomainInfo.DnsForestName.Buffer != NULL)
84 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.DnsForestName.Buffer);
85
86 if (PolicyInformation->PolicyDnsDomainInfo.Sid != NULL)
87 midl_user_free(PolicyInformation->PolicyDnsDomainInfo.Sid);
88 break;
89
90 case PolicyDnsDomainInformationInt: /* 13 (0xD) */
91 if (PolicyInformation->PolicyDnsDomainInfoInt.Name.Buffer != NULL)
92 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.Name.Buffer);
93
94 if (PolicyInformation->PolicyDnsDomainInfoInt.DnsDomainName.Buffer != NULL)
95 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.DnsDomainName.Buffer);
96
97 if (PolicyInformation->PolicyDnsDomainInfoInt.DnsForestName.Buffer != NULL)
98 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.DnsForestName.Buffer);
99
100 if (PolicyInformation->PolicyDnsDomainInfoInt.Sid != NULL)
101 midl_user_free(PolicyInformation->PolicyDnsDomainInfoInt.Sid);
102 break;
103
104 case PolicyLocalAccountDomainInformation: /* 14 (0xE) */
105 if (PolicyInformation->PolicyLocalAccountDomainInfo.DomainName.Buffer != NULL)
106 midl_user_free(PolicyInformation->PolicyLocalAccountDomainInfo.DomainName.Buffer);
107
108 if (PolicyInformation->PolicyLocalAccountDomainInfo.Sid != NULL)
109 midl_user_free(PolicyInformation->PolicyLocalAccountDomainInfo.Sid);
110 break;
111
112 default:
113 ERR("Invalid InformationClass: %lu\n", InformationClass);
114 break;
115 }
116
117 midl_user_free(PolicyInformation);
118 }
119 }
120
121
122 VOID
123 NTAPI
124 LsaIFree_LSAPR_PRIVILEGE_SET(IN PLSAPR_PRIVILEGE_SET Ptr)
125 {
126 if (Ptr != NULL)
127 {
128 midl_user_free(Ptr);
129 }
130 }
131
132
133 NTSTATUS WINAPI
134 LsapInitLsa(VOID)
135 {
136 HANDLE hEvent;
137 DWORD dwError;
138 NTSTATUS Status;
139
140 TRACE("LsapInitLsa() called\n");
141
142 /* Initialize the well known SIDs */
143 LsapInitSids();
144
145 /* Initialize the SRM server */
146 Status = LsapRmInitializeServer();
147 if (!NT_SUCCESS(Status))
148 {
149 ERR("LsapRmInitializeServer() failed (Status 0x%08lx)\n", Status);
150 return Status;
151 }
152
153 /* Initialize the LSA database */
154 LsapInitDatabase();
155
156 /* Initialize logon sessions */
157 LsapInitLogonSessions();
158
159 /* Initialize registered authentication packages */
160 Status = LsapInitAuthPackages();
161 if (!NT_SUCCESS(Status))
162 {
163 ERR("LsapInitAuthPackages() failed (Status 0x%08lx)\n", Status);
164 return Status;
165 }
166
167 /* Start the authentication port thread */
168 Status = StartAuthenticationPort();
169 if (!NT_SUCCESS(Status))
170 {
171 ERR("StartAuthenticationPort() failed (Status 0x%08lx)\n", Status);
172 return Status;
173 }
174
175 /* Start the RPC server */
176 LsarStartRpcServer();
177
178 TRACE("Creating notification event!\n");
179 /* Notify the service manager */
180 hEvent = CreateEventW(NULL,
181 TRUE,
182 FALSE,
183 L"LSA_RPC_SERVER_ACTIVE");
184 if (hEvent == NULL)
185 {
186 dwError = GetLastError();
187 TRACE("Failed to create the notication event (Error %lu)\n", dwError);
188
189 if (dwError == ERROR_ALREADY_EXISTS)
190 {
191 hEvent = OpenEventW(GENERIC_WRITE,
192 FALSE,
193 L"LSA_RPC_SERVER_ACTIVE");
194 if (hEvent == NULL)
195 {
196 ERR("Could not open the notification event (Error %lu)\n", GetLastError());
197 return STATUS_UNSUCCESSFUL;
198 }
199 }
200 }
201
202 TRACE("Set notification event!\n");
203 SetEvent(hEvent);
204
205 /* NOTE: Do not close the event handle!!!! */
206
207 return STATUS_SUCCESS;
208 }
209
210
211 NTSTATUS WINAPI
212 ServiceInit(VOID)
213 {
214 TRACE("ServiceInit() called\n");
215 return STATUS_SUCCESS;
216 }
217
218
219 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
220 {
221 return RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len);
222 }
223
224
225 void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
226 {
227 RtlFreeHeap(RtlGetProcessHeap(), 0, ptr);
228 }
229
230 /* EOF */