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
11 /* INCLUDES ******************************************************************/
14 #define NTOS_MODE_USER
15 #include <ndk/ntndk.h>
16 #include <lsass/lsass.h>
20 /* GLOBALS *******************************************************************/
22 extern HANDLE Secur32Heap
;
24 /* FUNCTIONS *****************************************************************/
30 LsaDeregisterLogonProcess(HANDLE LsaHandle
)
32 LSASS_REQUEST Request
;
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
,
42 if (!NT_SUCCESS(Status
))
47 if (!NT_SUCCESS(Reply
.Status
))
59 LsaConnectUntrusted(PHANDLE LsaHandle
)
61 return(STATUS_UNSUCCESSFUL
);
68 LsaCallAuthenticationPackage(HANDLE LsaHandle
,
69 ULONG AuthenticationPackage
,
70 PVOID ProtocolSubmitBuffer
,
71 ULONG SubmitBufferLength
,
72 PVOID
* ProtocolReturnBuffer
,
73 PULONG ReturnBufferLength
,
74 PNTSTATUS ProtocolStatus
)
76 PLSASS_REQUEST Request
;
78 UCHAR RawRequest
[MAX_MESSAGE_DATA
];
79 UCHAR RawReply
[MAX_MESSAGE_DATA
];
83 Request
= (PLSASS_REQUEST
)RawRequest
;
84 Reply
= (PLSASS_REPLY
)RawReply
;
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
=
95 memcpy(Request
->d
.CallAuthenticationPackageRequest
.InBuffer
,
99 Status
= NtRequestWaitReplyPort(LsaHandle
,
102 if (!NT_SUCCESS(Status
))
107 if (!NT_SUCCESS(Reply
->Status
))
109 return(Reply
->Status
);
112 OutBufferSize
= Reply
->d
.CallAuthenticationPackageReply
.OutBufferLength
;
113 *ProtocolReturnBuffer
= RtlAllocateHeap(Secur32Heap
,
116 *ReturnBufferLength
= OutBufferSize
;
117 memcpy(*ProtocolReturnBuffer
,
118 Reply
->d
.CallAuthenticationPackageReply
.OutBuffer
,
119 *ReturnBufferLength
);
129 LsaFreeReturnBuffer(PVOID Buffer
)
131 return(RtlFreeHeap(Secur32Heap
, 0, Buffer
));
139 LsaLookupAuthenticationPackage(HANDLE LsaHandle
,
140 PLSA_STRING PackageName
,
141 PULONG AuthenticationPackage
)
144 PLSASS_REQUEST Request
;
145 UCHAR RawRequest
[MAX_MESSAGE_DATA
];
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
;
155 Status
= NtRequestWaitReplyPort(LsaHandle
,
158 if (!NT_SUCCESS(Status
))
162 if (!NT_SUCCESS(Reply
.Status
))
164 return(Reply
.Status
);
167 *AuthenticationPackage
= Reply
.d
.LookupAuthenticationPackageReply
.Package
;
169 return(Reply
.Status
);
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
,
189 PQUOTA_LIMITS Quotas
,
194 PLSASS_REQUEST Request
;
195 UCHAR RawMessage
[MAX_MESSAGE_DATA
];
197 UCHAR RawReply
[MAX_MESSAGE_DATA
];
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
));
207 Request
= (PLSASS_REQUEST
)RawMessage
;
209 Request
->d
.LogonUserRequest
.OriginNameLength
= OriginName
->Length
;
210 Request
->d
.LogonUserRequest
.OriginName
= (PWSTR
)&RawMessage
[CurrentLength
];
211 memcpy((PWSTR
)&RawMessage
[CurrentLength
],
213 OriginName
->Length
* sizeof(WCHAR
));
214 CurrentLength
= CurrentLength
+ (OriginName
->Length
* sizeof(WCHAR
));
216 Request
->d
.LogonUserRequest
.LogonType
= LogonType
;
218 Request
->d
.LogonUserRequest
.AuthenticationPackage
=
219 AuthenticationPackage
;
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
;
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
],
235 LocalGroups
->GroupCount
* sizeof(SID_AND_ATTRIBUTES
));
237 Request
->d
.LogonUserRequest
.SourceContext
= *SourceContext
;
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
;
243 Reply
= (PLSASS_REPLY
)RawReply
;
245 Status
= NtRequestWaitReplyPort(LsaHandle
,
248 if (!NT_SUCCESS(Status
))
253 *SubStatus
= Reply
->d
.LogonUserReply
.SubStatus
;
255 if (!NT_SUCCESS(Reply
->Status
))
260 *ProfileBuffer
= RtlAllocateHeap(Secur32Heap
,
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
;
270 &Reply
->d
.LogonUserReply
.Quotas
,
271 sizeof(Reply
->d
.LogonUserReply
.Quotas
));
281 LsaRegisterLogonProcess(PLSA_STRING LsaLogonProcessName
,
283 PLSA_OPERATIONAL_MODE OperationalMode
)
285 UNICODE_STRING Portname
= RTL_CONSTANT_STRING(L
"\\SeLsaCommandPort");
286 ULONG ConnectInfoLength
;
288 LSASS_REQUEST Request
;
291 ConnectInfoLength
= 0;
292 Status
= NtConnectPort(Handle
,
300 if (!NT_SUCCESS(Status
))
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
);
310 Request
.d
.RegisterLogonProcessRequest
.Length
= LsaLogonProcessName
->Length
;
311 memcpy(Request
.d
.RegisterLogonProcessRequest
.LogonProcessNameBuffer
,
312 LsaLogonProcessName
->Buffer
,
313 Request
.d
.RegisterLogonProcessRequest
.Length
);
315 Status
= NtRequestWaitReplyPort(*Handle
,
318 if (!NT_SUCCESS(Status
))
321 *Handle
= INVALID_HANDLE_VALUE
;
325 if (!NT_SUCCESS(Reply
.Status
))
328 *Handle
= INVALID_HANDLE_VALUE
;
332 *OperationalMode
= Reply
.d
.RegisterLogonProcessReply
.OperationalMode
;
334 return(Reply
.Status
);
342 LsaEnumerateLogonSessions(
343 PULONG LogonSessionCount
,
344 PLUID
* LogonSessionList
355 LsaGetLogonSessionData(
357 PSECURITY_LOGON_SESSION_DATA
* ppLogonSessionData
368 LsaRegisterPolicyChangeNotification(
369 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
370 HANDLE NotificationEventHandle
381 LsaUnregisterPolicyChangeNotification(
382 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
383 HANDLE NotificationEventHandle