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 *****************************************************************/
33 LsaDeregisterLogonProcess(HANDLE LsaHandle
)
35 LSA_API_MSG ApiMessage
;
38 DPRINT1("LsaDeregisterLogonProcess()\n");
40 ApiMessage
.ApiNumber
= LSASS_REQUEST_DEREGISTER_LOGON_PROCESS
;
41 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.DeregisterLogonProcess
);
42 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
43 ApiMessage
.h
.u2
.ZeroInit
= 0;
45 Status
= ZwRequestWaitReplyPort(LsaHandle
,
46 (PPORT_MESSAGE
)&ApiMessage
,
47 (PPORT_MESSAGE
)&ApiMessage
);
48 if (!NT_SUCCESS(Status
))
50 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status
);
54 if (!NT_SUCCESS(ApiMessage
.Status
))
56 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage
.Status
);
57 return ApiMessage
.Status
;
62 DPRINT1("LsaDeregisterLogonProcess() done (Status 0x%08lx)\n", Status
);
72 LsaConnectUntrusted(PHANDLE LsaHandle
)
74 UNICODE_STRING PortName
; // = RTL_CONSTANT_STRING(L"\\LsaAuthenticationPort");
75 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
76 LSA_CONNECTION_INFO ConnectInfo
;
77 ULONG ConnectInfoLength
= sizeof(ConnectInfo
);
80 DPRINT1("LsaConnectUntrusted(%p)\n", LsaHandle
);
82 RtlInitUnicodeString(&PortName
,
83 L
"\\LsaAuthenticationPort");
85 SecurityQos
.Length
= sizeof(SecurityQos
);
86 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
87 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
88 SecurityQos
.EffectiveOnly
= TRUE
;
90 RtlZeroMemory(&ConnectInfo
,
93 Status
= ZwConnectPort(LsaHandle
,
101 if (!NT_SUCCESS(Status
))
103 DPRINT1("ZwConnectPort failed (Status 0x%08lx)\n", Status
);
107 if (!NT_SUCCESS(ConnectInfo
.Status
))
109 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo
.Status
);
112 return ConnectInfo
.Status
;
120 LsaCallAuthenticationPackage(HANDLE LsaHandle
,
121 ULONG AuthenticationPackage
,
122 PVOID ProtocolSubmitBuffer
,
123 ULONG SubmitBufferLength
,
124 PVOID
*ProtocolReturnBuffer
,
125 PULONG ReturnBufferLength
,
126 PNTSTATUS ProtocolStatus
)
128 LSA_API_MSG ApiMessage
;
131 DPRINT1("LsaCallAuthenticationPackage()\n");
133 ApiMessage
.ApiNumber
= LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE
;
134 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.CallAuthenticationPackage
);
135 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
136 ApiMessage
.h
.u2
.ZeroInit
= 0;
138 ApiMessage
.CallAuthenticationPackage
.Request
.AuthenticationPackage
= AuthenticationPackage
;
139 ApiMessage
.CallAuthenticationPackage
.Request
.ProtocolSubmitBuffer
= ProtocolSubmitBuffer
;
140 ApiMessage
.CallAuthenticationPackage
.Request
.SubmitBufferLength
= SubmitBufferLength
;
142 Status
= ZwRequestWaitReplyPort(LsaHandle
,
143 (PPORT_MESSAGE
)&ApiMessage
,
144 (PPORT_MESSAGE
)&ApiMessage
);
145 if (!NT_SUCCESS(Status
))
147 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status
);
151 if (!NT_SUCCESS(ApiMessage
.Status
))
153 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage
.Status
);
154 return ApiMessage
.Status
;
157 *ProtocolReturnBuffer
= ApiMessage
.CallAuthenticationPackage
.Reply
.ProtocolReturnBuffer
;
158 *ReturnBufferLength
= ApiMessage
.CallAuthenticationPackage
.Reply
.ReturnBufferLength
;
159 *ProtocolStatus
= ApiMessage
.CallAuthenticationPackage
.Reply
.ProtocolStatus
;
169 LsaFreeReturnBuffer(PVOID Buffer
)
173 return ZwFreeVirtualMemory(NtCurrentProcess(),
184 LsaLookupAuthenticationPackage(HANDLE LsaHandle
,
185 PLSA_STRING PackageName
,
186 PULONG AuthenticationPackage
)
188 LSA_API_MSG ApiMessage
;
191 /* Check the package name length */
192 if (PackageName
->Length
> LSASS_MAX_PACKAGE_NAME_LENGTH
)
194 return STATUS_NAME_TOO_LONG
;
197 ApiMessage
.ApiNumber
= LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE
;
198 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.LookupAuthenticationPackage
);
199 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
200 ApiMessage
.h
.u2
.ZeroInit
= 0;
202 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
= PackageName
->Length
;
203 strncpy(ApiMessage
.LookupAuthenticationPackage
.Request
.PackageName
,
205 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
);
206 ApiMessage
.LookupAuthenticationPackage
.Request
.PackageName
[ApiMessage
.LookupAuthenticationPackage
.Request
.PackageNameLength
] = '\0';
208 Status
= ZwRequestWaitReplyPort(LsaHandle
,
209 (PPORT_MESSAGE
)&ApiMessage
,
210 (PPORT_MESSAGE
)&ApiMessage
);
211 if (!NT_SUCCESS(Status
))
216 if (!NT_SUCCESS(ApiMessage
.Status
))
218 return ApiMessage
.Status
;
221 *AuthenticationPackage
= ApiMessage
.LookupAuthenticationPackage
.Reply
.Package
;
231 LsaLogonUser(HANDLE LsaHandle
,
232 PLSA_STRING OriginName
,
233 SECURITY_LOGON_TYPE LogonType
,
234 ULONG AuthenticationPackage
,
235 PVOID AuthenticationInformation
,
236 ULONG AuthenticationInformationLength
,
237 PTOKEN_GROUPS LocalGroups
,
238 PTOKEN_SOURCE SourceContext
,
239 PVOID
*ProfileBuffer
,
240 PULONG ProfileBufferLength
,
243 PQUOTA_LIMITS Quotas
,
246 LSA_API_MSG ApiMessage
;
249 ApiMessage
.ApiNumber
= LSASS_REQUEST_LOGON_USER
;
250 ApiMessage
.h
.u1
.s1
.DataLength
= LSA_PORT_DATA_SIZE(ApiMessage
.LogonUser
);
251 ApiMessage
.h
.u1
.s1
.TotalLength
= LSA_PORT_MESSAGE_SIZE
;
252 ApiMessage
.h
.u2
.ZeroInit
= 0;
254 ApiMessage
.LogonUser
.Request
.OriginName
= *OriginName
;
255 ApiMessage
.LogonUser
.Request
.LogonType
= LogonType
;
256 ApiMessage
.LogonUser
.Request
.AuthenticationPackage
= AuthenticationPackage
;
257 ApiMessage
.LogonUser
.Request
.AuthenticationInformation
= AuthenticationInformation
;
258 ApiMessage
.LogonUser
.Request
.AuthenticationInformationLength
= AuthenticationInformationLength
;
259 ApiMessage
.LogonUser
.Request
.LocalGroups
= LocalGroups
;
260 if (LocalGroups
!= NULL
)
261 ApiMessage
.LogonUser
.Request
.LocalGroupsCount
= LocalGroups
->GroupCount
;
263 ApiMessage
.LogonUser
.Request
.LocalGroupsCount
= 0;
264 ApiMessage
.LogonUser
.Request
.SourceContext
= *SourceContext
;
266 Status
= ZwRequestWaitReplyPort(LsaHandle
,
267 (PPORT_MESSAGE
)&ApiMessage
,
268 (PPORT_MESSAGE
)&ApiMessage
);
269 if (!NT_SUCCESS(Status
))
274 if (!NT_SUCCESS(ApiMessage
.Status
))
276 return ApiMessage
.Status
;
279 *ProfileBuffer
= ApiMessage
.LogonUser
.Reply
.ProfileBuffer
;
280 *ProfileBufferLength
= ApiMessage
.LogonUser
.Reply
.ProfileBufferLength
;
281 *LogonId
= ApiMessage
.LogonUser
.Reply
.LogonId
;
282 *Token
= ApiMessage
.LogonUser
.Reply
.Token
;
283 *Quotas
= ApiMessage
.LogonUser
.Reply
.Quotas
;
284 *SubStatus
= ApiMessage
.LogonUser
.Reply
.SubStatus
;
294 LsaRegisterLogonProcess(PLSA_STRING LsaLogonProcessName
,
296 PLSA_OPERATIONAL_MODE OperationalMode
)
298 UNICODE_STRING PortName
; // = RTL_CONSTANT_STRING(L"\\LsaAuthenticationPort");
299 SECURITY_QUALITY_OF_SERVICE SecurityQos
;
300 LSA_CONNECTION_INFO ConnectInfo
;
301 ULONG ConnectInfoLength
= sizeof(ConnectInfo
);
304 DPRINT1("LsaRegisterLogonProcess()\n");
306 /* Check the logon process name length */
307 if (LsaLogonProcessName
->Length
> LSASS_MAX_LOGON_PROCESS_NAME_LENGTH
)
308 return STATUS_NAME_TOO_LONG
;
310 RtlInitUnicodeString(&PortName
,
311 L
"\\LsaAuthenticationPort");
313 SecurityQos
.Length
= sizeof(SecurityQos
);
314 SecurityQos
.ImpersonationLevel
= SecurityIdentification
;
315 SecurityQos
.ContextTrackingMode
= SECURITY_DYNAMIC_TRACKING
;
316 SecurityQos
.EffectiveOnly
= TRUE
;
318 strncpy(ConnectInfo
.LogonProcessNameBuffer
,
319 LsaLogonProcessName
->Buffer
,
320 LsaLogonProcessName
->Length
);
321 ConnectInfo
.Length
= LsaLogonProcessName
->Length
;
322 ConnectInfo
.LogonProcessNameBuffer
[ConnectInfo
.Length
] = '\0';
324 Status
= ZwConnectPort(Handle
,
332 if (!NT_SUCCESS(Status
))
334 DPRINT1("ZwConnectPort failed (Status 0x%08lx)\n", Status
);
338 DPRINT("ConnectInfo.OperationalMode: 0x%08lx\n", ConnectInfo
.OperationalMode
);
339 *OperationalMode
= ConnectInfo
.OperationalMode
;
341 if (!NT_SUCCESS(ConnectInfo
.Status
))
343 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo
.Status
);
346 return ConnectInfo
.Status
;
355 LsaEnumerateLogonSessions(PULONG LogonSessionCount
,
356 PLUID
*LogonSessionList
)
359 return STATUS_NOT_IMPLEMENTED
;
368 LsaGetLogonSessionData(PLUID LogonId
,
369 PSECURITY_LOGON_SESSION_DATA
*ppLogonSessionData
)
372 return STATUS_NOT_IMPLEMENTED
;
381 LsaRegisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
382 HANDLE NotificationEventHandle
)
385 return STATUS_NOT_IMPLEMENTED
;
394 LsaUnregisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass
,
395 HANDLE NotificationEventHandle
)
398 return STATUS_NOT_IMPLEMENTED
;