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