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/mmfuncs.h>
15 #include <ndk/rtlfuncs.h>
16 #include <ndk/obfuncs.h>
17 #include <psdk/ntsecapi.h>
18 #include <lsass/lsass.h>
23 /* GLOBALS *******************************************************************/
25 extern HANDLE Secur32Heap
;
27 /* FUNCTIONS *****************************************************************/
34 LsaDeregisterLogonProcess(HANDLE LsaHandle
)
36 LSA_API_MSG ApiMessage
;
39 DPRINT("LsaDeregisterLogonProcess()\n");
41 ApiMessage
.ApiNumber
= LSASS_REQUEST_DEREGISTER_LOGON_PROCESS
;
42 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.DeregisterLogonProcess
);
43 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
44 ApiMessage
.h
.u2
.ZeroInit
= 0;
46 Status
= ZwRequestWaitReplyPort(LsaHandle
,
47 (PPORT_MESSAGE
)&ApiMessage
,
48 (PPORT_MESSAGE
)&ApiMessage
);
49 if (!NT_SUCCESS(Status
))
51 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status
);
55 if (!NT_SUCCESS(ApiMessage
.Status
))
57 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage
.Status
);
58 return ApiMessage
.Status
;
63 DPRINT("LsaDeregisterLogonProcess() done (Status 0x%08lx)\n", Status
);
74 LsaConnectUntrusted(PHANDLE LsaHandle
)
76 UNICODE_STRING PortName
; // = RTL_CONSTANT_STRING(L"\\LsaAuthenticationPort");
77 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
78 LSA_CONNECTION_INFO ConnectInfo
;
79 ULONG ConnectInfoLength
= sizeof(ConnectInfo
);
82 DPRINT("LsaConnectUntrusted(%p)\n", LsaHandle
);
84 RtlInitUnicodeString(&PortName
,
85 L
"\\LsaAuthenticationPort");
87 SecurityQos
.Length
= sizeof(SecurityQos
);
88 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
89 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
90 SecurityQos
.EffectiveOnly
= TRUE
;
92 RtlZeroMemory(&ConnectInfo
,
95 ConnectInfo
.CreateContext
= TRUE
;
97 Status
= ZwConnectPort(LsaHandle
,
105 if (!NT_SUCCESS(Status
))
107 DPRINT1("ZwConnectPort failed (Status 0x%08lx)\n", Status
);
111 if (!NT_SUCCESS(ConnectInfo
.Status
))
113 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo
.Status
);
116 return ConnectInfo
.Status
;
125 LsaCallAuthenticationPackage(HANDLE LsaHandle
,
126 ULONG AuthenticationPackage
,
127 PVOID ProtocolSubmitBuffer
,
128 ULONG SubmitBufferLength
,
129 PVOID
*ProtocolReturnBuffer
,
130 PULONG ReturnBufferLength
,
131 PNTSTATUS ProtocolStatus
)
133 LSA_API_MSG ApiMessage
;
136 DPRINT1("LsaCallAuthenticationPackage()\n");
138 ApiMessage
.ApiNumber
= LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE
;
139 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.CallAuthenticationPackage
);
140 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
141 ApiMessage
.h
.u2
.ZeroInit
= 0;
143 ApiMessage
.CallAuthenticationPackage
.Request
.AuthenticationPackage
= AuthenticationPackage
;
144 ApiMessage
.CallAuthenticationPackage
.Request
.ProtocolSubmitBuffer
= ProtocolSubmitBuffer
;
145 ApiMessage
.CallAuthenticationPackage
.Request
.SubmitBufferLength
= SubmitBufferLength
;
147 Status
= ZwRequestWaitReplyPort(LsaHandle
,
148 (PPORT_MESSAGE
)&ApiMessage
,
149 (PPORT_MESSAGE
)&ApiMessage
);
150 if (!NT_SUCCESS(Status
))
152 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status
);
156 if (!NT_SUCCESS(ApiMessage
.Status
))
158 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage
.Status
);
159 return ApiMessage
.Status
;
162 *ProtocolReturnBuffer
= ApiMessage
.CallAuthenticationPackage
.Reply
.ProtocolReturnBuffer
;
163 *ReturnBufferLength
= ApiMessage
.CallAuthenticationPackage
.Reply
.ReturnBufferLength
;
164 *ProtocolStatus
= ApiMessage
.CallAuthenticationPackage
.Reply
.ProtocolStatus
;
175 LsaFreeReturnBuffer(PVOID Buffer
)
179 return ZwFreeVirtualMemory(NtCurrentProcess(),
191 LsaLookupAuthenticationPackage(HANDLE LsaHandle
,
192 PLSA_STRING PackageName
,
193 PULONG AuthenticationPackage
)
195 LSA_API_MSG ApiMessage
;
198 /* Check the package name length */
199 if (PackageName
->Length
> LSASS_MAX_PACKAGE_NAME_LENGTH
)
201 return STATUS_NAME_TOO_LONG
;
204 ApiMessage
.ApiNumber
= LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE
;
205 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.LookupAuthenticationPackage
);
206 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
207 ApiMessage
.h
.u2
.ZeroInit
= 0;
209 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
= PackageName
->Length
;
210 strncpy(ApiMessage
.LookupAuthenticationPackage
.Request
.PackageName
,
212 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
);
213 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageName
[ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
] = '\0';
215 Status
= ZwRequestWaitReplyPort(LsaHandle
,
216 (PPORT_MESSAGE
)&ApiMessage
,
217 (PPORT_MESSAGE
)&ApiMessage
);
218 if (!NT_SUCCESS(Status
))
223 if (!NT_SUCCESS(ApiMessage
.Status
))
225 return ApiMessage
.Status
;
228 *AuthenticationPackage
= ApiMessage
.LookupAuthenticationPackage
.Reply
.Package
;
239 LsaLogonUser(HANDLE LsaHandle
,
240 PLSA_STRING OriginName
,
241 SECURITY_LOGON_TYPE LogonType
,
242 ULONG AuthenticationPackage
,
243 PVOID AuthenticationInformation
,
244 ULONG AuthenticationInformationLength
,
245 PTOKEN_GROUPS LocalGroups
,
246 PTOKEN_SOURCE SourceContext
,
247 PVOID
*ProfileBuffer
,
248 PULONG ProfileBufferLength
,
251 PQUOTA_LIMITS Quotas
,
254 LSA_API_MSG ApiMessage
;
257 ApiMessage
.ApiNumber
= LSASS_REQUEST_LOGON_USER
;
258 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.LogonUser
);
259 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
260 ApiMessage
.h
.u2
.ZeroInit
= 0;
262 ApiMessage
.LogonUser
.Request
.OriginName
= *OriginName
;
263 ApiMessage
.LogonUser
.Request
.LogonType
= LogonType
;
264 ApiMessage
.LogonUser
.Request
.AuthenticationPackage
= AuthenticationPackage
;
265 ApiMessage
.LogonUser
.Request
.AuthenticationInformation
= AuthenticationInformation
;
266 ApiMessage
.LogonUser
.Request
.AuthenticationInformationLength
= AuthenticationInformationLength
;
267 ApiMessage
.LogonUser
.Request
.LocalGroups
= LocalGroups
;
268 if (LocalGroups
!= NULL
)
269 ApiMessage
.LogonUser
.Request
.LocalGroupsCount
= LocalGroups
->GroupCount
;
271 ApiMessage
.LogonUser
.Request
.LocalGroupsCount
= 0;
272 ApiMessage
.LogonUser
.Request
.SourceContext
= *SourceContext
;
274 Status
= ZwRequestWaitReplyPort(LsaHandle
,
275 (PPORT_MESSAGE
)&ApiMessage
,
276 (PPORT_MESSAGE
)&ApiMessage
);
277 if (!NT_SUCCESS(Status
))
282 *SubStatus
= ApiMessage
.LogonUser
.Reply
.SubStatus
;
284 if (!NT_SUCCESS(ApiMessage
.Status
))
286 return ApiMessage
.Status
;
289 *ProfileBuffer
= ApiMessage
.LogonUser
.Reply
.ProfileBuffer
;
290 *ProfileBufferLength
= ApiMessage
.LogonUser
.Reply
.ProfileBufferLength
;
291 *LogonId
= ApiMessage
.LogonUser
.Reply
.LogonId
;
292 *Token
= ApiMessage
.LogonUser
.Reply
.Token
;
293 *Quotas
= ApiMessage
.LogonUser
.Reply
.Quotas
;
304 LsaRegisterLogonProcess(PLSA_STRING LsaLogonProcessName
,
306 PLSA_OPERATIONAL_MODE OperationalMode
)
308 UNICODE_STRING PortName
; // = RTL_CONSTANT_STRING(L"\\LsaAuthenticationPort");
309 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
310 LSA_CONNECTION_INFO ConnectInfo
;
311 ULONG ConnectInfoLength
= sizeof(ConnectInfo
);
314 DPRINT("LsaRegisterLogonProcess()\n");
316 /* Check the logon process name length */
317 if (LsaLogonProcessName
->Length
> LSASS_MAX_LOGON_PROCESS_NAME_LENGTH
)
318 return STATUS_NAME_TOO_LONG
;
320 RtlInitUnicodeString(&PortName
,
321 L
"\\LsaAuthenticationPort");
323 SecurityQos
.Length
= sizeof(SecurityQos
);
324 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
325 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
326 SecurityQos
.EffectiveOnly
= TRUE
;
328 strncpy(ConnectInfo
.LogonProcessNameBuffer
,
329 LsaLogonProcessName
->Buffer
,
330 LsaLogonProcessName
->Length
);
331 ConnectInfo
.Length
= LsaLogonProcessName
->Length
;
332 ConnectInfo
.LogonProcessNameBuffer
[ConnectInfo
.Length
] = '\0';
333 ConnectInfo
.CreateContext
= TRUE
;
335 Status
= ZwConnectPort(Handle
,
343 if (!NT_SUCCESS(Status
))
345 DPRINT1("ZwConnectPort failed (Status 0x%08lx)\n", Status
);
349 DPRINT("ConnectInfo.OperationalMode: 0x%08lx\n", ConnectInfo
.OperationalMode
);
350 *OperationalMode
= ConnectInfo
.OperationalMode
;
352 if (!NT_SUCCESS(ConnectInfo
.Status
))
354 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo
.Status
);
357 return ConnectInfo
.Status
;