[win32k] Handle invalid palette index by using the first palette entry
[reactos.git] / reactos / lib / lsalib / lsa.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/lsalib/lsa.c
5 * PURPOSE: Client-side LSA functions
6 * UPDATE HISTORY:
7 * Created 05/08/00
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <ndk/ntndk.h>
13 #include <psdk/ntsecapi.h>
14 #include <lsass/lsass.h>
15
16 #define NDEBUG
17 #include <debug.h>
18
19 /* GLOBALS *******************************************************************/
20
21 extern HANDLE Secur32Heap;
22
23 /* FUNCTIONS *****************************************************************/
24
25 /*
26 * @implemented
27 */
28 NTSTATUS WINAPI
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 WINAPI
58 LsaConnectUntrusted(PHANDLE LsaHandle)
59 {
60 UNIMPLEMENTED;
61 return STATUS_UNSUCCESSFUL;
62 }
63
64 /*
65 * @implemented
66 */
67 NTSTATUS WINAPI
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 LSASS_REQUEST RawRequest;
79 LSASS_REPLY RawReply;
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 sizeof(PORT_MESSAGE);
88 Request->Header.u1.s1.TotalLength =
89 Request->Header.u1.s1.DataLength + sizeof(PORT_MESSAGE);
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 WINAPI
129 LsaFreeReturnBuffer(PVOID Buffer)
130 {
131 return(RtlFreeHeap(Secur32Heap, 0, Buffer));
132 }
133
134
135 /*
136 * @implemented
137 */
138 NTSTATUS WINAPI
139 LsaLookupAuthenticationPackage(HANDLE LsaHandle,
140 PLSA_STRING PackageName,
141 PULONG AuthenticationPackage)
142 {
143 NTSTATUS Status;
144 PLSASS_REQUEST Request;
145 LSASS_REQUEST RawRequest;
146 LSASS_REPLY Reply;
147
148 Request = (PLSASS_REQUEST)&RawRequest;
149 Request->Header.u1.s1.DataLength = sizeof(LSASS_REQUEST) + PackageName->Length -
150 sizeof(PORT_MESSAGE);
151 Request->Header.u1.s1.TotalLength = Request->Header.u1.s1.DataLength +
152 sizeof(PORT_MESSAGE);
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 WINAPI
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 LSASS_REQUEST RawMessage;
196 PLSASS_REPLY Reply;
197 LSASS_REPLY RawReply;
198 NTSTATUS Status;
199
200 RequestLength = sizeof(LSASS_REQUEST) - sizeof(PORT_MESSAGE);
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)((ULONG_PTR)&RawMessage + CurrentLength);
223 Request->d.LogonUserRequest.AuthenticationInformationLength =
224 AuthenticationInformationLength;
225 memcpy((PVOID)((ULONG_PTR)&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 - sizeof(PORT_MESSAGE);
241 Request->Header.u1.s1.TotalLength = RequestLength + sizeof(PORT_MESSAGE);
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 WINAPI
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 sizeof(PORT_MESSAGE);
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 = NULL;
322 return(Status);
323 }
324
325 if (!NT_SUCCESS(Reply.Status))
326 {
327 NtClose(*Handle);
328 *Handle = NULL;
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 WINAPI
342 LsaEnumerateLogonSessions(
343 PULONG LogonSessionCount,
344 PLUID * LogonSessionList
345 )
346 {
347 UNIMPLEMENTED;
348 return FALSE;
349 }
350
351 /*
352 * @unimplemented
353 */
354 NTSTATUS
355 WINAPI
356 LsaGetLogonSessionData(
357 PLUID LogonId,
358 PSECURITY_LOGON_SESSION_DATA * ppLogonSessionData
359 )
360 {
361 UNIMPLEMENTED;
362 return FALSE;
363 }
364
365 /*
366 * @unimplemented
367 */
368 NTSTATUS
369 WINAPI
370 LsaRegisterPolicyChangeNotification(
371 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
372 HANDLE NotificationEventHandle
373 )
374 {
375 UNIMPLEMENTED;
376 return FALSE;
377 }
378
379 /*
380 * @unimplemented
381 */
382 NTSTATUS
383 WINAPI
384 LsaUnregisterPolicyChangeNotification(
385 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
386 HANDLE NotificationEventHandle
387 )
388 {
389 UNIMPLEMENTED;
390 return FALSE;
391 }