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 ******************************************************************/
15 #define NTOS_MODE_USER
16 #include <ndk/ntndk.h>
17 #include <lsass/lsass.h>
19 /* GLOBALS *******************************************************************/
21 extern HANDLE Secur32Heap
;
23 /* FUNCTIONS *****************************************************************/
29 LsaDeregisterLogonProcess(HANDLE LsaHandle
)
31 LSASS_REQUEST Request
;
35 Request
.Header
.DataSize
= 0;
36 Request
.Header
.MessageSize
= sizeof(LSASS_REQUEST
);
37 Request
.Type
= LSASS_REQUEST_DEREGISTER_LOGON_PROCESS
;
38 Status
= NtRequestWaitReplyPort(LsaHandle
,
41 if (!NT_SUCCESS(Status
))
46 if (!NT_SUCCESS(Reply
.Status
))
58 LsaConnectUntrusted(PHANDLE LsaHandle
)
60 return(STATUS_UNSUCCESSFUL
);
67 LsaCallAuthenticationPackage(HANDLE LsaHandle
,
68 ULONG AuthenticationPackage
,
69 PVOID ProtocolSubmitBuffer
,
70 ULONG SubmitBufferLength
,
71 PVOID
* ProtocolReturnBuffer
,
72 PULONG ReturnBufferLength
,
73 PNTSTATUS ProtocolStatus
)
75 PLSASS_REQUEST Request
;
77 UCHAR RawRequest
[MAX_MESSAGE_DATA
];
78 UCHAR RawReply
[MAX_MESSAGE_DATA
];
82 Request
= (PLSASS_REQUEST
)RawRequest
;
83 Reply
= (PLSASS_REPLY
)RawReply
;
85 Request
->Header
.DataSize
= sizeof(LSASS_REQUEST
) + SubmitBufferLength
-
86 LPC_MESSAGE_BASE_SIZE
;
87 Request
->Header
.MessageSize
=
88 Request
->Header
.DataSize
+ LPC_MESSAGE_BASE_SIZE
;
89 Request
->Type
= LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE
;
90 Request
->d
.CallAuthenticationPackageRequest
.AuthenticationPackage
=
91 AuthenticationPackage
;
92 Request
->d
.CallAuthenticationPackageRequest
.InBufferLength
=
94 memcpy(Request
->d
.CallAuthenticationPackageRequest
.InBuffer
,
98 Status
= NtRequestWaitReplyPort(LsaHandle
,
101 if (!NT_SUCCESS(Status
))
106 if (!NT_SUCCESS(Reply
->Status
))
108 return(Reply
->Status
);
111 OutBufferSize
= Reply
->d
.CallAuthenticationPackageReply
.OutBufferLength
;
112 *ProtocolReturnBuffer
= RtlAllocateHeap(Secur32Heap
,
115 *ReturnBufferLength
= OutBufferSize
;
116 memcpy(*ProtocolReturnBuffer
,
117 Reply
->d
.CallAuthenticationPackageReply
.OutBuffer
,
118 *ReturnBufferLength
);
128 LsaFreeReturnBuffer(PVOID Buffer
)
130 return(RtlFreeHeap(Secur32Heap
, 0, Buffer
));
138 LsaLookupAuthenticationPackage(HANDLE LsaHandle
,
139 PLSA_STRING PackageName
,
140 PULONG AuthenticationPackage
)
143 PLSASS_REQUEST Request
;
144 UCHAR RawRequest
[MAX_MESSAGE_DATA
];
147 Request
= (PLSASS_REQUEST
)RawRequest
;
148 Request
->Header
.DataSize
= sizeof(LSASS_REQUEST
) + PackageName
->Length
-
149 LPC_MESSAGE_BASE_SIZE
;
150 Request
->Header
.MessageSize
= Request
->Header
.DataSize
+
151 LPC_MESSAGE_BASE_SIZE
;
152 Request
->Type
= LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE
;
154 Status
= NtRequestWaitReplyPort(LsaHandle
,
157 if (!NT_SUCCESS(Status
))
161 if (!NT_SUCCESS(Reply
.Status
))
163 return(Reply
.Status
);
166 *AuthenticationPackage
= Reply
.d
.LookupAuthenticationPackageReply
.Package
;
168 return(Reply
.Status
);
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
,
188 PQUOTA_LIMITS Quotas
,
193 PLSASS_REQUEST Request
;
194 UCHAR RawMessage
[MAX_MESSAGE_DATA
];
196 UCHAR RawReply
[MAX_MESSAGE_DATA
];
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
));
206 Request
= (PLSASS_REQUEST
)RawMessage
;
208 Request
->d
.LogonUserRequest
.OriginNameLength
= OriginName
->Length
;
209 Request
->d
.LogonUserRequest
.OriginName
= (PWSTR
)&RawMessage
[CurrentLength
];
210 memcpy((PWSTR
)&RawMessage
[CurrentLength
],
212 OriginName
->Length
* sizeof(WCHAR
));
213 CurrentLength
= CurrentLength
+ (OriginName
->Length
* sizeof(WCHAR
));
215 Request
->d
.LogonUserRequest
.LogonType
= LogonType
;
217 Request
->d
.LogonUserRequest
.AuthenticationPackage
=
218 AuthenticationPackage
;
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
;
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
],
234 LocalGroups
->GroupCount
* sizeof(SID_AND_ATTRIBUTES
));
236 Request
->d
.LogonUserRequest
.SourceContext
= *SourceContext
;
238 Request
->Type
= LSASS_REQUEST_LOGON_USER
;
239 Request
->Header
.DataSize
= RequestLength
- LPC_MESSAGE_BASE_SIZE
;
240 Request
->Header
.MessageSize
= RequestLength
+ LPC_MESSAGE_BASE_SIZE
;
242 Reply
= (PLSASS_REPLY
)RawReply
;
244 Status
= NtRequestWaitReplyPort(LsaHandle
,
247 if (!NT_SUCCESS(Status
))
252 *SubStatus
= Reply
->d
.LogonUserReply
.SubStatus
;
254 if (!NT_SUCCESS(Reply
->Status
))
259 *ProfileBuffer
= RtlAllocateHeap(Secur32Heap
,
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
;
269 &Reply
->d
.LogonUserReply
.Quotas
,
270 sizeof(Reply
->d
.LogonUserReply
.Quotas
));
280 LsaRegisterLogonProcess(PLSA_STRING LsaLogonProcessName
,
282 PLSA_OPERATIONAL_MODE OperationalMode
)
284 UNICODE_STRING Portname
= RTL_CONSTANT_STRING(L
"\\SeLsaCommandPort");
285 ULONG ConnectInfoLength
;
287 LSASS_REQUEST Request
;
290 ConnectInfoLength
= 0;
291 Status
= NtConnectPort(Handle
,
299 if (!NT_SUCCESS(Status
))
304 Request
.Type
= LSASS_REQUEST_REGISTER_LOGON_PROCESS
;
305 Request
.Header
.DataSize
= sizeof(LSASS_REQUEST
) -
306 LPC_MESSAGE_BASE_SIZE
;
307 Request
.Header
.MessageSize
= sizeof(LSASS_REQUEST
);
309 Request
.d
.RegisterLogonProcessRequest
.Length
= LsaLogonProcessName
->Length
;
310 memcpy(Request
.d
.RegisterLogonProcessRequest
.LogonProcessNameBuffer
,
311 LsaLogonProcessName
->Buffer
,
312 Request
.d
.RegisterLogonProcessRequest
.Length
);
314 Status
= NtRequestWaitReplyPort(*Handle
,
317 if (!NT_SUCCESS(Status
))
320 *Handle
= INVALID_HANDLE_VALUE
;
324 if (!NT_SUCCESS(Reply
.Status
))
327 *Handle
= INVALID_HANDLE_VALUE
;
331 *OperationalMode
= Reply
.d
.RegisterLogonProcessReply
.OperationalMode
;
333 return(Reply
.Status
);
341 LsaEnumerateLogonSessions(
342 PULONG LogonSessionCount
,
343 PLUID
* LogonSessionList
354 LsaGetLogonSessionData(
356 PSECURITY_LOGON_SESSION_DATA
* ppLogonSessionData
367 LsaRegisterPolicyChangeNotification(
368 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
369 HANDLE NotificationEventHandle
380 LsaUnregisterPolicyChangeNotification(
381 POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
382 HANDLE NotificationEventHandle