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/exfuncs.h>
13 #include <ndk/lpctypes.h>
14 #include <ndk/lpcfuncs.h>
15 #include <ndk/mmfuncs.h>
16 #include <ndk/rtlfuncs.h>
17 #include <ndk/obfuncs.h>
18 #include <lsass/lsass.h>
23 /* FUNCTIONS *****************************************************************/
30 LsaCallAuthenticationPackage(IN HANDLE LsaHandle
,
31 IN ULONG AuthenticationPackage
,
32 IN PVOID ProtocolSubmitBuffer
,
33 IN ULONG SubmitBufferLength
,
34 OUT PVOID
*ProtocolReturnBuffer
,
35 OUT PULONG ReturnBufferLength
,
36 OUT PNTSTATUS ProtocolStatus
)
38 LSA_API_MSG ApiMessage
;
41 DPRINT1("LsaCallAuthenticationPackage()\n");
43 ApiMessage
.ApiNumber
= LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE
;
44 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.CallAuthenticationPackage
);
45 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
46 ApiMessage
.h
.u2
.ZeroInit
= 0;
48 ApiMessage
.CallAuthenticationPackage
.Request
.AuthenticationPackage
= AuthenticationPackage
;
49 ApiMessage
.CallAuthenticationPackage
.Request
.ProtocolSubmitBuffer
= ProtocolSubmitBuffer
;
50 ApiMessage
.CallAuthenticationPackage
.Request
.SubmitBufferLength
= SubmitBufferLength
;
52 Status
= ZwRequestWaitReplyPort(LsaHandle
,
53 (PPORT_MESSAGE
)&ApiMessage
,
54 (PPORT_MESSAGE
)&ApiMessage
);
55 if (!NT_SUCCESS(Status
))
57 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status
);
61 if (!NT_SUCCESS(ApiMessage
.Status
))
63 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage
.Status
);
64 return ApiMessage
.Status
;
67 *ProtocolReturnBuffer
= ApiMessage
.CallAuthenticationPackage
.Reply
.ProtocolReturnBuffer
;
68 *ReturnBufferLength
= ApiMessage
.CallAuthenticationPackage
.Reply
.ReturnBufferLength
;
69 *ProtocolStatus
= ApiMessage
.CallAuthenticationPackage
.Reply
.ProtocolStatus
;
80 LsaDeregisterLogonProcess(IN HANDLE LsaHandle
)
82 LSA_API_MSG ApiMessage
;
85 DPRINT("LsaDeregisterLogonProcess()\n");
87 ApiMessage
.ApiNumber
= LSASS_REQUEST_DEREGISTER_LOGON_PROCESS
;
88 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.DeregisterLogonProcess
);
89 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
90 ApiMessage
.h
.u2
.ZeroInit
= 0;
92 Status
= ZwRequestWaitReplyPort(LsaHandle
,
93 (PPORT_MESSAGE
)&ApiMessage
,
94 (PPORT_MESSAGE
)&ApiMessage
);
95 if (!NT_SUCCESS(Status
))
97 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status
);
101 if (!NT_SUCCESS(ApiMessage
.Status
))
103 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage
.Status
);
104 return ApiMessage
.Status
;
109 DPRINT("LsaDeregisterLogonProcess() done (Status 0x%08lx)\n", Status
);
120 LsaFreeReturnBuffer(IN PVOID Buffer
)
124 return ZwFreeVirtualMemory(NtCurrentProcess(),
136 LsaLookupAuthenticationPackage(IN HANDLE LsaHandle
,
137 IN PLSA_STRING PackageName
,
138 OUT PULONG AuthenticationPackage
)
140 LSA_API_MSG ApiMessage
;
143 /* Check the package name length */
144 if (PackageName
->Length
> LSASS_MAX_PACKAGE_NAME_LENGTH
)
146 return STATUS_NAME_TOO_LONG
;
149 ApiMessage
.ApiNumber
= LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE
;
150 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.LookupAuthenticationPackage
);
151 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
152 ApiMessage
.h
.u2
.ZeroInit
= 0;
154 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
= PackageName
->Length
;
155 strncpy(ApiMessage
.LookupAuthenticationPackage
.Request
.PackageName
,
157 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
);
158 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageName
[ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
] = ANSI_NULL
;
160 Status
= ZwRequestWaitReplyPort(LsaHandle
,
161 (PPORT_MESSAGE
)&ApiMessage
,
162 (PPORT_MESSAGE
)&ApiMessage
);
163 if (!NT_SUCCESS(Status
))
168 if (!NT_SUCCESS(ApiMessage
.Status
))
170 return ApiMessage
.Status
;
173 *AuthenticationPackage
= ApiMessage
.LookupAuthenticationPackage
.Reply
.Package
;
184 LsaLogonUser(IN HANDLE LsaHandle
,
185 IN PLSA_STRING OriginName
,
186 IN SECURITY_LOGON_TYPE LogonType
,
187 IN ULONG AuthenticationPackage
,
188 IN PVOID AuthenticationInformation
,
189 IN ULONG AuthenticationInformationLength
,
190 IN PTOKEN_GROUPS LocalGroups OPTIONAL
,
191 IN PTOKEN_SOURCE SourceContext
,
192 OUT PVOID
*ProfileBuffer
,
193 OUT PULONG ProfileBufferLength
,
196 OUT PQUOTA_LIMITS Quotas
,
197 OUT PNTSTATUS SubStatus
)
199 LSA_API_MSG ApiMessage
;
202 ApiMessage
.ApiNumber
= LSASS_REQUEST_LOGON_USER
;
203 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.LogonUser
);
204 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
205 ApiMessage
.h
.u2
.ZeroInit
= 0;
207 ApiMessage
.LogonUser
.Request
.OriginName
= *OriginName
;
208 ApiMessage
.LogonUser
.Request
.LogonType
= LogonType
;
209 ApiMessage
.LogonUser
.Request
.AuthenticationPackage
= AuthenticationPackage
;
210 ApiMessage
.LogonUser
.Request
.AuthenticationInformation
= AuthenticationInformation
;
211 ApiMessage
.LogonUser
.Request
.AuthenticationInformationLength
= AuthenticationInformationLength
;
212 ApiMessage
.LogonUser
.Request
.LocalGroups
= LocalGroups
;
213 if (LocalGroups
!= NULL
)
214 ApiMessage
.LogonUser
.Request
.LocalGroupsCount
= LocalGroups
->GroupCount
;
216 ApiMessage
.LogonUser
.Request
.LocalGroupsCount
= 0;
217 ApiMessage
.LogonUser
.Request
.SourceContext
= *SourceContext
;
219 Status
= ZwRequestWaitReplyPort(LsaHandle
,
220 (PPORT_MESSAGE
)&ApiMessage
,
221 (PPORT_MESSAGE
)&ApiMessage
);
222 if (!NT_SUCCESS(Status
))
227 *SubStatus
= ApiMessage
.LogonUser
.Reply
.SubStatus
;
229 if (!NT_SUCCESS(ApiMessage
.Status
))
231 return ApiMessage
.Status
;
234 *ProfileBuffer
= ApiMessage
.LogonUser
.Reply
.ProfileBuffer
;
235 *ProfileBufferLength
= ApiMessage
.LogonUser
.Reply
.ProfileBufferLength
;
236 *LogonId
= ApiMessage
.LogonUser
.Reply
.LogonId
;
237 *Token
= ApiMessage
.LogonUser
.Reply
.Token
;
238 *Quotas
= ApiMessage
.LogonUser
.Reply
.Quotas
;
249 LsaRegisterLogonProcess(IN PLSA_STRING LogonProcessName
,
250 OUT PHANDLE LsaHandle
,
251 OUT PLSA_OPERATIONAL_MODE OperationalMode
)
253 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
254 LSA_CONNECTION_INFO ConnectInfo
;
255 ULONG ConnectInfoLength
= sizeof(ConnectInfo
);
256 UNICODE_STRING PortName
;
257 OBJECT_ATTRIBUTES ObjectAttributes
;
258 UNICODE_STRING EventName
;
262 DPRINT("LsaRegisterLogonProcess()\n");
264 /* Check the logon process name length */
265 if (LogonProcessName
->Length
> LSASS_MAX_LOGON_PROCESS_NAME_LENGTH
)
266 return STATUS_NAME_TOO_LONG
;
268 /* Wait for the LSA authentication thread */
269 RtlInitUnicodeString(&EventName
,
270 L
"\\SECURITY\\LSA_AUTHENTICATION_INITIALIZED");
271 InitializeObjectAttributes(&ObjectAttributes
,
273 OBJ_CASE_INSENSITIVE
| OBJ_PERMANENT
,
276 Status
= ZwOpenEvent(&EventHandle
,
279 if (!NT_SUCCESS(Status
))
281 DPRINT
"NtOpenEvent failed (Status 0x%08lx)\n", Status
);
283 Status
= ZwCreateEvent(&EventHandle
,
288 if (!NT_SUCCESS(Status
))
290 DPRINT1("NtCreateEvent failed (Status 0x%08lx)\n", Status
);
295 Status
= ZwWaitForSingleObject(EventHandle
,
298 ZwClose(EventHandle
);
299 if (!NT_SUCCESS(Status
))
301 DPRINT1("NtWaitForSingleObject failed (Status 0x%08lx)\n", Status
);
305 /* Establish the connection */
306 RtlInitUnicodeString(&PortName
,
307 L
"\\LsaAuthenticationPort");
309 SecurityQos
.Length
= sizeof(SecurityQos
);
310 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
311 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
312 SecurityQos
.EffectiveOnly
= TRUE
;
314 strncpy(ConnectInfo
.LogonProcessNameBuffer
,
315 LogonProcessName
->Buffer
,
316 LogonProcessName
->Length
);
317 ConnectInfo
.Length
= LogonProcessName
->Length
;
318 ConnectInfo
.LogonProcessNameBuffer
[ConnectInfo
.Length
] = ANSI_NULL
;
319 ConnectInfo
.CreateContext
= TRUE
;
321 Status
= ZwConnectPort(LsaHandle
,
329 if (!NT_SUCCESS(Status
))
331 DPRINT1("ZwConnectPort failed (Status 0x%08lx)\n", Status
);
335 DPRINT("ConnectInfo.OperationalMode: 0x%08lx\n", ConnectInfo
.OperationalMode
);
336 *OperationalMode
= ConnectInfo
.OperationalMode
;
338 if (!NT_SUCCESS(ConnectInfo
.Status
))
340 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo
.Status
);
343 return ConnectInfo
.Status
;