0a9e92132fbfd5ef7cb68a98cfb0edbf91faab0e
[reactos.git] / reactos / lib / secur32 / lsa.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/secur32/lsa.c
6 * PURPOSE: Client-side LSA functions
7 * UPDATE HISTORY:
8 * Created 05/08/00
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <windows.h>
14 #define NTOS_MODE_USER
15 #include <ndk/ntndk.h>
16 #include <lsass/lsass.h>
17
18 #include <ntsecapi.h>
19
20 /* GLOBALS *******************************************************************/
21
22 extern HANDLE Secur32Heap;
23
24 /* FUNCTIONS *****************************************************************/
25
26 /*
27 * @implemented
28 */
29 NTSTATUS STDCALL
30 LsaDeregisterLogonProcess(HANDLE LsaHandle)
31 {
32 LSASS_REQUEST Request;
33 LSASS_REPLY Reply;
34 NTSTATUS Status;
35
36 Request.Header.u1.s1.DataLength = 0;
37 Request.Header.u1.s1.TotalLength = sizeof(LSASS_REQUEST);
38 Request.Type = LSASS_REQUEST_DEREGISTER_LOGON_PROCESS;
39 Status = NtRequestWaitReplyPort(LsaHandle,
40 &Request.Header,
41 &Reply.Header);
42 if (!NT_SUCCESS(Status))
43 {
44 return(Status);
45 }
46
47 if (!NT_SUCCESS(Reply.Status))
48 {
49 return(Reply.Status);
50 }
51
52 return(Status);
53 }
54
55 /*
56 * @unimplemented
57 */
58 NTSTATUS STDCALL
59 LsaConnectUntrusted(PHANDLE LsaHandle)
60 {
61 return(STATUS_UNSUCCESSFUL);
62 }
63
64 /*
65 * @implemented
66 */
67 NTSTATUS STDCALL
68 LsaCallAuthenticationPackage(HANDLE LsaHandle,
69 ULONG AuthenticationPackage,
70 PVOID ProtocolSubmitBuffer,
71 ULONG SubmitBufferLength,
72 PVOID* ProtocolReturnBuffer,
73 PULONG ReturnBufferLength,
74 PNTSTATUS ProtocolStatus)
75 {
76 PLSASS_REQUEST Request;
77 PLSASS_REPLY Reply;
78 UCHAR RawRequest[MAX_MESSAGE_DATA];
79 UCHAR RawReply[MAX_MESSAGE_DATA];
80 NTSTATUS Status;
81 ULONG OutBufferSize;
82
83 Request = (PLSASS_REQUEST)RawRequest;
84 Reply = (PLSASS_REPLY)RawReply;
85
86 Request->Header.u1.s1.DataLength = sizeof(LSASS_REQUEST) + SubmitBufferLength -
87 LPC_MESSAGE_BASE_SIZE;
88 Request->Header.u1.s1.TotalLength =
89 Request->Header.u1.s1.DataLength + LPC_MESSAGE_BASE_SIZE;
90 Request->Type = LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE;
91 Request->d.CallAuthenticationPackageRequest.AuthenticationPackage =
92 AuthenticationPackage;
93 Request->d.CallAuthenticationPackageRequest.InBufferLength =
94 SubmitBufferLength;
95 memcpy(Request->d.CallAuthenticationPackageRequest.InBuffer,
96 ProtocolSubmitBuffer,
97 SubmitBufferLength);
98
99 Status = NtRequestWaitReplyPort(LsaHandle,
100 &Request->Header,
101 &Reply->Header);
102 if (!NT_SUCCESS(Status))
103 {
104 return(Status);
105 }
106
107 if (!NT_SUCCESS(Reply->Status))
108 {
109 return(Reply->Status);
110 }
111
112 OutBufferSize = Reply->d.CallAuthenticationPackageReply.OutBufferLength;
113 *ProtocolReturnBuffer = RtlAllocateHeap(Secur32Heap,
114 0,
115 OutBufferSize);
116 *ReturnBufferLength = OutBufferSize;
117 memcpy(*ProtocolReturnBuffer,
118 Reply->d.CallAuthenticationPackageReply.OutBuffer,
119 *ReturnBufferLength);
120
121 return(Status);
122 }
123
124
125 /*
126 * @implemented
127 */
128 NTSTATUS STDCALL
129 LsaFreeReturnBuffer(PVOID Buffer)
130 {
131 return(RtlFreeHeap(Secur32Heap, 0, Buffer));
132 }
133
134
135 /*
136 * @implemented
137 */
138 NTSTATUS STDCALL
139 LsaLookupAuthenticationPackage(HANDLE LsaHandle,
140 PLSA_STRING PackageName,
141 PULONG AuthenticationPackage)
142 {
143 NTSTATUS Status;
144 PLSASS_REQUEST Request;
145 UCHAR RawRequest[MAX_MESSAGE_DATA];
146 LSASS_REPLY Reply;
147
148 Request = (PLSASS_REQUEST)RawRequest;
149 Request->Header.u1.s1.DataLength = sizeof(LSASS_REQUEST) + PackageName->Length -
150 LPC_MESSAGE_BASE_SIZE;
151 Request->Header.u1.s1.TotalLength = Request->Header.u1.s1.DataLength +
152 LPC_MESSAGE_BASE_SIZE;
153 Request->Type = LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE;
154
155 Status = NtRequestWaitReplyPort(LsaHandle,
156 &Request->Header,
157 &Reply.Header);
158 if (!NT_SUCCESS(Status))
159 {
160 return(Status);
161 }
162 if (!NT_SUCCESS(Reply.Status))
163 {
164 return(Reply.Status);
165 }
166
167 *AuthenticationPackage = Reply.d.LookupAuthenticationPackageReply.Package;
168
169 return(Reply.Status);
170 }
171
172
173 /*
174 * @implemented
175 */
176 NTSTATUS STDCALL
177 LsaLogonUser(HANDLE LsaHandle,
178 PLSA_STRING OriginName,
179 SECURITY_LOGON_TYPE LogonType,
180 ULONG AuthenticationPackage,
181 PVOID AuthenticationInformation,
182 ULONG AuthenticationInformationLength,
183 PTOKEN_GROUPS LocalGroups,
184 PTOKEN_SOURCE SourceContext,
185 PVOID* ProfileBuffer,
186 PULONG ProfileBufferLength,
187 PLUID LogonId,
188 PHANDLE Token,
189 PQUOTA_LIMITS Quotas,
190 PNTSTATUS SubStatus)
191 {
192 ULONG RequestLength;
193 ULONG CurrentLength;
194 PLSASS_REQUEST Request;
195 UCHAR RawMessage[MAX_MESSAGE_DATA];
196 PLSASS_REPLY Reply;
197 UCHAR RawReply[MAX_MESSAGE_DATA];
198 NTSTATUS Status;
199
200 RequestLength = sizeof(LSASS_REQUEST) - LPC_MESSAGE_BASE_SIZE;
201 RequestLength = RequestLength + (OriginName->Length * sizeof(WCHAR));
202 RequestLength = RequestLength + AuthenticationInformationLength;
203 RequestLength = RequestLength +
204 (LocalGroups->GroupCount * sizeof(SID_AND_ATTRIBUTES));
205
206 CurrentLength = 0;
207 Request = (PLSASS_REQUEST)RawMessage;
208
209 Request->d.LogonUserRequest.OriginNameLength = OriginName->Length;
210 Request->d.LogonUserRequest.OriginName = (PWSTR)&RawMessage[CurrentLength];
211 memcpy((PWSTR)&RawMessage[CurrentLength],
212 OriginName->Buffer,
213 OriginName->Length * sizeof(WCHAR));
214 CurrentLength = CurrentLength + (OriginName->Length * sizeof(WCHAR));
215
216 Request->d.LogonUserRequest.LogonType = LogonType;
217
218 Request->d.LogonUserRequest.AuthenticationPackage =
219 AuthenticationPackage;
220
221 Request->d.LogonUserRequest.AuthenticationInformation =
222 (PVOID)&RawMessage[CurrentLength];
223 Request->d.LogonUserRequest.AuthenticationInformationLength =
224 AuthenticationInformationLength;
225 memcpy((PVOID)&RawMessage[CurrentLength],
226 AuthenticationInformation,
227 AuthenticationInformationLength);
228 CurrentLength = CurrentLength + AuthenticationInformationLength;
229
230 Request->d.LogonUserRequest.LocalGroupsCount = LocalGroups->GroupCount;
231 Request->d.LogonUserRequest.LocalGroups =
232 (PSID_AND_ATTRIBUTES)&RawMessage[CurrentLength];
233 memcpy((PSID_AND_ATTRIBUTES)&RawMessage[CurrentLength],
234 LocalGroups->Groups,
235 LocalGroups->GroupCount * sizeof(SID_AND_ATTRIBUTES));
236
237 Request->d.LogonUserRequest.SourceContext = *SourceContext;
238
239 Request->Type = LSASS_REQUEST_LOGON_USER;
240 Request->Header.u1.s1.DataLength = RequestLength - LPC_MESSAGE_BASE_SIZE;
241 Request->Header.u1.s1.TotalLength = RequestLength + LPC_MESSAGE_BASE_SIZE;
242
243 Reply = (PLSASS_REPLY)RawReply;
244
245 Status = NtRequestWaitReplyPort(LsaHandle,
246 &Request->Header,
247 &Reply->Header);
248 if (!NT_SUCCESS(Status))
249 {
250 return(Status);
251 }
252
253 *SubStatus = Reply->d.LogonUserReply.SubStatus;
254
255 if (!NT_SUCCESS(Reply->Status))
256 {
257 return(Status);
258 }
259
260 *ProfileBuffer = RtlAllocateHeap(Secur32Heap,
261 0,
262 Reply->d.LogonUserReply.ProfileBufferLength);
263 memcpy(*ProfileBuffer,
264 (PVOID)((ULONG)Reply->d.LogonUserReply.Data +
265 (ULONG)Reply->d.LogonUserReply.ProfileBuffer),
266 Reply->d.LogonUserReply.ProfileBufferLength);
267 *LogonId = Reply->d.LogonUserReply.LogonId;
268 *Token = Reply->d.LogonUserReply.Token;
269 memcpy(Quotas,
270 &Reply->d.LogonUserReply.Quotas,
271 sizeof(Reply->d.LogonUserReply.Quotas));
272
273 return(Status);
274 }
275
276
277 /*
278 * @implemented
279 */
280 NTSTATUS STDCALL
281 LsaRegisterLogonProcess(PLSA_STRING LsaLogonProcessName,
282 PHANDLE Handle,
283 PLSA_OPERATIONAL_MODE OperationalMode)
284 {
285 UNICODE_STRING Portname = RTL_CONSTANT_STRING(L"\\SeLsaCommandPort");
286 ULONG ConnectInfoLength;
287 NTSTATUS Status;
288 LSASS_REQUEST Request;
289 LSASS_REPLY Reply;
290
291 ConnectInfoLength = 0;
292 Status = NtConnectPort(Handle,
293 &Portname,
294 NULL,
295 NULL,
296 NULL,
297 NULL,
298 NULL,
299 &ConnectInfoLength);
300 if (!NT_SUCCESS(Status))
301 {
302 return(Status);
303 }
304
305 Request.Type = LSASS_REQUEST_REGISTER_LOGON_PROCESS;
306 Request.Header.u1.s1.DataLength = sizeof(LSASS_REQUEST) -
307 LPC_MESSAGE_BASE_SIZE;
308 Request.Header.u1.s1.TotalLength = sizeof(LSASS_REQUEST);
309
310 Request.d.RegisterLogonProcessRequest.Length = LsaLogonProcessName->Length;
311 memcpy(Request.d.RegisterLogonProcessRequest.LogonProcessNameBuffer,
312 LsaLogonProcessName->Buffer,
313 Request.d.RegisterLogonProcessRequest.Length);
314
315 Status = NtRequestWaitReplyPort(*Handle,
316 &Request.Header,
317 &Reply.Header);
318 if (!NT_SUCCESS(Status))
319 {
320 NtClose(*Handle);
321 *Handle = INVALID_HANDLE_VALUE;
322 return(Status);
323 }
324
325 if (!NT_SUCCESS(Reply.Status))
326 {
327 NtClose(*Handle);
328 *Handle = INVALID_HANDLE_VALUE;
329 return(Status);
330 }
331
332 *OperationalMode = Reply.d.RegisterLogonProcessReply.OperationalMode;
333
334 return(Reply.Status);
335 }
336
337 /*
338 * @unimplemented
339 */
340 NTSTATUS
341 STDCALL
342 LsaEnumerateLogonSessions(
343 PULONG LogonSessionCount,
344 PLUID * LogonSessionList
345 )
346 {
347 return(FALSE);
348 }
349
350 /*
351 * @unimplemented
352 */
353 NTSTATUS
354 STDCALL
355 LsaGetLogonSessionData(
356 PLUID LogonId,
357 PSECURITY_LOGON_SESSION_DATA * ppLogonSessionData
358 )
359 {
360 return(FALSE);
361 }
362
363 /*
364 * @unimplemented
365 */
366 NTSTATUS
367 STDCALL
368 LsaRegisterPolicyChangeNotification(
369 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
370 HANDLE NotificationEventHandle
371 )
372 {
373 return(FALSE);
374 }
375
376 /*
377 * @unimplemented
378 */
379 NTSTATUS
380 STDCALL
381 LsaUnregisterPolicyChangeNotification(
382 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
383 HANDLE NotificationEventHandle
384 )
385 {
386 return(FALSE);
387 }