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
10 /* INCLUDES ******************************************************************/
12 #include <ndk/lpctypes.h>
13 #include <ndk/lpcfuncs.h>
14 #include <ndk/rtlfuncs.h>
15 #include <psdk/ntsecapi.h>
16 #include <lsass/lsass.h>
21 /* GLOBALS *******************************************************************/
23 extern HANDLE Secur32Heap
;
25 /* FUNCTIONS *****************************************************************/
31 LsaDeregisterLogonProcess(HANDLE LsaHandle
)
33 LSASS_REQUEST Request
;
37 Request
.Header
.u1
.s1
.DataLength
= 0;
38 Request
.Header
.u1
.s1
.TotalLength
= sizeof(LSASS_REQUEST
);
39 Request
.Type
= LSASS_REQUEST_DEREGISTER_LOGON_PROCESS
;
40 Status
= ZwRequestWaitReplyPort(LsaHandle
,
43 if (!NT_SUCCESS(Status
))
48 if (!NT_SUCCESS(Reply
.Status
))
61 LsaConnectUntrusted(PHANDLE LsaHandle
)
64 return STATUS_NOT_IMPLEMENTED
;
72 LsaCallAuthenticationPackage(HANDLE LsaHandle
,
73 ULONG AuthenticationPackage
,
74 PVOID ProtocolSubmitBuffer
,
75 ULONG SubmitBufferLength
,
76 PVOID
*ProtocolReturnBuffer
,
77 PULONG ReturnBufferLength
,
78 PNTSTATUS ProtocolStatus
)
80 PLSASS_REQUEST Request
;
82 LSASS_REQUEST RawRequest
;
87 Request
= (PLSASS_REQUEST
)&RawRequest
;
88 Reply
= (PLSASS_REPLY
)&RawReply
;
90 Request
->Header
.u1
.s1
.DataLength
= sizeof(LSASS_REQUEST
) + SubmitBufferLength
-
92 Request
->Header
.u1
.s1
.TotalLength
=
93 Request
->Header
.u1
.s1
.DataLength
+ sizeof(PORT_MESSAGE
);
94 Request
->Type
= LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE
;
95 Request
->d
.CallAuthenticationPackageRequest
.AuthenticationPackage
=
96 AuthenticationPackage
;
97 Request
->d
.CallAuthenticationPackageRequest
.InBufferLength
=
99 memcpy(Request
->d
.CallAuthenticationPackageRequest
.InBuffer
,
100 ProtocolSubmitBuffer
,
103 Status
= ZwRequestWaitReplyPort(LsaHandle
,
106 if (!NT_SUCCESS(Status
))
111 if (!NT_SUCCESS(Reply
->Status
))
113 return Reply
->Status
;
116 OutBufferSize
= Reply
->d
.CallAuthenticationPackageReply
.OutBufferLength
;
117 *ProtocolReturnBuffer
= RtlAllocateHeap(Secur32Heap
,
120 *ReturnBufferLength
= OutBufferSize
;
121 memcpy(*ProtocolReturnBuffer
,
122 Reply
->d
.CallAuthenticationPackageReply
.OutBuffer
,
123 *ReturnBufferLength
);
133 LsaFreeReturnBuffer(PVOID Buffer
)
135 return RtlFreeHeap(Secur32Heap
, 0, Buffer
);
143 LsaLookupAuthenticationPackage(HANDLE LsaHandle
,
144 PLSA_STRING PackageName
,
145 PULONG AuthenticationPackage
)
148 PLSASS_REQUEST Request
;
149 LSASS_REQUEST RawRequest
;
152 Request
= (PLSASS_REQUEST
)&RawRequest
;
153 Request
->Header
.u1
.s1
.DataLength
= sizeof(LSASS_REQUEST
) + PackageName
->Length
-
154 sizeof(PORT_MESSAGE
);
155 Request
->Header
.u1
.s1
.TotalLength
= Request
->Header
.u1
.s1
.DataLength
+
156 sizeof(PORT_MESSAGE
);
157 Request
->Type
= LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE
;
159 Status
= ZwRequestWaitReplyPort(LsaHandle
,
162 if (!NT_SUCCESS(Status
))
167 if (!NT_SUCCESS(Reply
.Status
))
172 *AuthenticationPackage
= Reply
.d
.LookupAuthenticationPackageReply
.Package
;
182 LsaLogonUser(HANDLE LsaHandle
,
183 PLSA_STRING OriginName
,
184 SECURITY_LOGON_TYPE LogonType
,
185 ULONG AuthenticationPackage
,
186 PVOID AuthenticationInformation
,
187 ULONG AuthenticationInformationLength
,
188 PTOKEN_GROUPS LocalGroups
,
189 PTOKEN_SOURCE SourceContext
,
190 PVOID
*ProfileBuffer
,
191 PULONG ProfileBufferLength
,
194 PQUOTA_LIMITS Quotas
,
199 PLSASS_REQUEST Request
;
200 LSASS_REQUEST RawMessage
;
202 LSASS_REPLY RawReply
;
205 RequestLength
= sizeof(LSASS_REQUEST
) - sizeof(PORT_MESSAGE
);
206 RequestLength
= RequestLength
+ (OriginName
->Length
* sizeof(WCHAR
));
207 RequestLength
= RequestLength
+ AuthenticationInformationLength
;
208 RequestLength
= RequestLength
+
209 (LocalGroups
->GroupCount
* sizeof(SID_AND_ATTRIBUTES
));
212 Request
= (PLSASS_REQUEST
)&RawMessage
;
214 Request
->d
.LogonUserRequest
.OriginNameLength
= OriginName
->Length
;
215 Request
->d
.LogonUserRequest
.OriginName
= (PWSTR
)&RawMessage
+ CurrentLength
;
216 memcpy((PWSTR
)&RawMessage
+ CurrentLength
,
218 OriginName
->Length
* sizeof(WCHAR
));
219 CurrentLength
= CurrentLength
+ (OriginName
->Length
* sizeof(WCHAR
));
221 Request
->d
.LogonUserRequest
.LogonType
= LogonType
;
223 Request
->d
.LogonUserRequest
.AuthenticationPackage
=
224 AuthenticationPackage
;
226 Request
->d
.LogonUserRequest
.AuthenticationInformation
=
227 (PVOID
)((ULONG_PTR
)&RawMessage
+ CurrentLength
);
228 Request
->d
.LogonUserRequest
.AuthenticationInformationLength
=
229 AuthenticationInformationLength
;
230 memcpy((PVOID
)((ULONG_PTR
)&RawMessage
+ CurrentLength
),
231 AuthenticationInformation
,
232 AuthenticationInformationLength
);
233 CurrentLength
= CurrentLength
+ AuthenticationInformationLength
;
235 Request
->d
.LogonUserRequest
.LocalGroupsCount
= LocalGroups
->GroupCount
;
236 Request
->d
.LogonUserRequest
.LocalGroups
=
237 (PSID_AND_ATTRIBUTES
)&RawMessage
+ CurrentLength
;
238 memcpy((PSID_AND_ATTRIBUTES
)&RawMessage
+ CurrentLength
,
240 LocalGroups
->GroupCount
* sizeof(SID_AND_ATTRIBUTES
));
242 Request
->d
.LogonUserRequest
.SourceContext
= *SourceContext
;
244 Request
->Type
= LSASS_REQUEST_LOGON_USER
;
245 Request
->Header
.u1
.s1
.DataLength
= RequestLength
- sizeof(PORT_MESSAGE
);
246 Request
->Header
.u1
.s1
.TotalLength
= RequestLength
+ sizeof(PORT_MESSAGE
);
248 Reply
= (PLSASS_REPLY
)&RawReply
;
250 Status
= ZwRequestWaitReplyPort(LsaHandle
,
253 if (!NT_SUCCESS(Status
))
258 *SubStatus
= Reply
->d
.LogonUserReply
.SubStatus
;
260 if (!NT_SUCCESS(Reply
->Status
))
265 *ProfileBuffer
= RtlAllocateHeap(Secur32Heap
,
267 Reply
->d
.LogonUserReply
.ProfileBufferLength
);
268 memcpy(*ProfileBuffer
,
269 (PVOID
)((ULONG_PTR
)Reply
->d
.LogonUserReply
.Data
+
270 (ULONG_PTR
)Reply
->d
.LogonUserReply
.ProfileBuffer
),
271 Reply
->d
.LogonUserReply
.ProfileBufferLength
);
272 *LogonId
= Reply
->d
.LogonUserReply
.LogonId
;
273 *Token
= Reply
->d
.LogonUserReply
.Token
;
275 &Reply
->d
.LogonUserReply
.Quotas
,
276 sizeof(Reply
->d
.LogonUserReply
.Quotas
));
286 LsaRegisterLogonProcess(PLSA_STRING LsaLogonProcessName
,
288 PLSA_OPERATIONAL_MODE OperationalMode
)
290 UNICODE_STRING PortName
; // = RTL_CONSTANT_STRING(L"\\LsaAuthenticationPort");
291 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
292 ULONG ConnectInfoLength
;
294 LSASS_CONNECT_DATA ConnectInfo
;
295 // LSASS_REQUEST Request;
296 // LSASS_REPLY Reply;
298 /* Check the logon process name length */
299 if (LsaLogonProcessName
->Length
> LSASS_MAX_LOGON_PROCESS_NAME_LENGTH
)
300 return STATUS_NAME_TOO_LONG
;
302 RtlInitUnicodeString(&PortName
,
303 L
"\\LsaAuthenticationPort");
305 SecurityQos
.Length
= sizeof (SecurityQos
);
306 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
307 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
308 SecurityQos
.EffectiveOnly
= TRUE
;
310 ConnectInfoLength
= sizeof(LSASS_CONNECT_DATA
);
312 strncpy(ConnectInfo
.LogonProcessNameBuffer
,
313 LsaLogonProcessName
->Buffer
,
314 LsaLogonProcessName
->Length
);
315 ConnectInfo
.Length
= LsaLogonProcessName
->Length
;
316 ConnectInfo
.LogonProcessNameBuffer
[ConnectInfo
.Length
] = '\0';
318 Status
= ZwConnectPort(Handle
,
326 if (!NT_SUCCESS(Status
))
333 Request
.Type
= LSASS_REQUEST_REGISTER_LOGON_PROCESS
;
334 Request
.Header
.u1
.s1
.DataLength
= sizeof(LSASS_REQUEST
) -
335 sizeof(PORT_MESSAGE
);
336 Request
.Header
.u1
.s1
.TotalLength
= sizeof(LSASS_REQUEST
);
338 Request
.d
.RegisterLogonProcessRequest
.Length
= LsaLogonProcessName
->Length
;
339 memcpy(Request
.d
.RegisterLogonProcessRequest
.LogonProcessNameBuffer
,
340 LsaLogonProcessName
->Buffer
,
341 Request
.d
.RegisterLogonProcessRequest
.Length
);
343 Status
= ZwRequestWaitReplyPort(*Handle
,
346 if (!NT_SUCCESS(Status
))
353 if (!NT_SUCCESS(Reply
.Status
))
360 *OperationalMode
= Reply
.d
.RegisterLogonProcessReply
.OperationalMode
;
372 LsaEnumerateLogonSessions(PULONG LogonSessionCount
,
373 PLUID
*LogonSessionList
)
376 return STATUS_NOT_IMPLEMENTED
;
385 LsaGetLogonSessionData(PLUID LogonId
,
386 PSECURITY_LOGON_SESSION_DATA
*ppLogonSessionData
)
389 return STATUS_NOT_IMPLEMENTED
;
398 LsaRegisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
399 HANDLE NotificationEventHandle
)
402 return STATUS_NOT_IMPLEMENTED
;
411 LsaUnregisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
412 HANDLE NotificationEventHandle
)
415 return STATUS_NOT_IMPLEMENTED
;