ReactOS 0.4.15-dev-6679-g945ee4b
lsa.c
Go to the documentation of this file.
1/*
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
6 * UPDATE HISTORY:
7 * Created 05/08/00
8 */
9
10/* INCLUDES ******************************************************************/
11
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>
19
20#define NDEBUG
21#include <debug.h>
22
23/* FUNCTIONS *****************************************************************/
24
25/*
26 * @implemented
27 */
32 IN PVOID ProtocolSubmitBuffer,
33 IN ULONG SubmitBufferLength,
34 OUT PVOID *ProtocolReturnBuffer,
35 OUT PULONG ReturnBufferLength,
37{
38 LSA_API_MSG ApiMessage;
40
41 DPRINT1("LsaCallAuthenticationPackage()\n");
42
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;
47
48 ApiMessage.CallAuthenticationPackage.Request.AuthenticationPackage = AuthenticationPackage;
49 ApiMessage.CallAuthenticationPackage.Request.ProtocolSubmitBuffer = ProtocolSubmitBuffer;
50 ApiMessage.CallAuthenticationPackage.Request.SubmitBufferLength = SubmitBufferLength;
51
53 (PPORT_MESSAGE)&ApiMessage,
54 (PPORT_MESSAGE)&ApiMessage);
55 if (!NT_SUCCESS(Status))
56 {
57 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
58 return Status;
59 }
60
61 if (!NT_SUCCESS(ApiMessage.Status))
62 {
63 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
64 return ApiMessage.Status;
65 }
66
67 *ProtocolReturnBuffer = ApiMessage.CallAuthenticationPackage.Reply.ProtocolReturnBuffer;
68 *ReturnBufferLength = ApiMessage.CallAuthenticationPackage.Reply.ReturnBufferLength;
69 *ProtocolStatus = ApiMessage.CallAuthenticationPackage.Reply.ProtocolStatus;
70
71 return Status;
72}
73
74
75/*
76 * @implemented
77 */
81{
82 LSA_API_MSG ApiMessage;
84
85 DPRINT("LsaDeregisterLogonProcess()\n");
86
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;
91
93 (PPORT_MESSAGE)&ApiMessage,
94 (PPORT_MESSAGE)&ApiMessage);
95 if (!NT_SUCCESS(Status))
96 {
97 DPRINT1("ZwRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
98 return Status;
99 }
100
101 if (!NT_SUCCESS(ApiMessage.Status))
102 {
103 DPRINT1("ZwRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
104 return ApiMessage.Status;
105 }
106
108
109 DPRINT("LsaDeregisterLogonProcess() done (Status 0x%08lx)\n", Status);
110
111 return Status;
112}
113
114
115/*
116 * @implemented
117 */
119NTAPI
121{
122 SIZE_T Size = 0;
123
124 return ZwFreeVirtualMemory(NtCurrentProcess(),
125 &Buffer,
126 &Size,
128}
129
130
131/*
132 * @implemented
133 */
135NTAPI
137 IN PLSA_STRING PackageName,
139{
140 LSA_API_MSG ApiMessage;
142
143 /* Check the package name length */
144 if (PackageName->Length > LSASS_MAX_PACKAGE_NAME_LENGTH)
145 {
147 }
148
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;
153
154 ApiMessage.LookupAuthenticationPackage.Request.PackageNameLength = PackageName->Length;
155 strncpy(ApiMessage.LookupAuthenticationPackage.Request.PackageName,
156 PackageName->Buffer,
157 ApiMessage.LookupAuthenticationPackage.Request.PackageNameLength);
158 ApiMessage.LookupAuthenticationPackage.Request.PackageName[ApiMessage.LookupAuthenticationPackage.Request.PackageNameLength] = ANSI_NULL;
159
161 (PPORT_MESSAGE)&ApiMessage,
162 (PPORT_MESSAGE)&ApiMessage);
163 if (!NT_SUCCESS(Status))
164 {
165 return Status;
166 }
167
168 if (!NT_SUCCESS(ApiMessage.Status))
169 {
170 return ApiMessage.Status;
171 }
172
174
175 return Status;
176}
177
178
179/*
180 * @implemented
181 */
183NTAPI
188 IN PVOID AuthenticationInformation,
198{
199 LSA_API_MSG ApiMessage;
201
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;
206
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;
215 else
216 ApiMessage.LogonUser.Request.LocalGroupsCount = 0;
217 ApiMessage.LogonUser.Request.SourceContext = *SourceContext;
218
220 (PPORT_MESSAGE)&ApiMessage,
221 (PPORT_MESSAGE)&ApiMessage);
222 if (!NT_SUCCESS(Status))
223 {
224 return Status;
225 }
226
227 *SubStatus = ApiMessage.LogonUser.Reply.SubStatus;
228
229 if (!NT_SUCCESS(ApiMessage.Status))
230 {
231 return ApiMessage.Status;
232 }
233
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;
239
240 return Status;
241}
242
243
244/*
245 * @implemented
246 */
248NTAPI
251 OUT PLSA_OPERATIONAL_MODE OperationalMode)
252{
253 SECURITY_QUALITY_OF_SERVICE SecurityQos;
254 LSA_CONNECTION_INFO ConnectInfo;
255 ULONG ConnectInfoLength = sizeof(ConnectInfo);
258 UNICODE_STRING EventName;
261
262 DPRINT("LsaRegisterLogonProcess()\n");
263
264 /* Check the logon process name length */
265 if (LogonProcessName->Length > LSASS_MAX_LOGON_PROCESS_NAME_LENGTH)
267
268 /* Wait for the LSA authentication thread */
269 RtlInitUnicodeString(&EventName,
270 L"\\SECURITY\\LSA_AUTHENTICATION_INITIALIZED");
272 &EventName,
274 NULL,
275 NULL);
279 if (!NT_SUCCESS(Status))
280 {
281 DPRINT("ZwOpenEvent failed (Status 0x%08lx)\n", Status);
282
283 Status = ZwCreateEvent(&EventHandle,
287 FALSE);
288 if (!NT_SUCCESS(Status))
289 {
290 DPRINT1("ZwCreateEvent failed (Status 0x%08lx)\n", Status);
291 return Status;
292 }
293 }
294
295 Status = ZwWaitForSingleObject(EventHandle,
296 TRUE,
297 NULL);
299 if (!NT_SUCCESS(Status))
300 {
301 DPRINT1("ZwWaitForSingleObject failed (Status 0x%08lx)\n", Status);
302 return Status;
303 }
304
305 /* Establish the connection */
307 L"\\LsaAuthenticationPort");
308
309 SecurityQos.Length = sizeof(SecurityQos);
312 SecurityQos.EffectiveOnly = TRUE;
313
315 LogonProcessName->Buffer,
316 LogonProcessName->Length);
317 ConnectInfo.Length = LogonProcessName->Length;
318 ConnectInfo.LogonProcessNameBuffer[ConnectInfo.Length] = ANSI_NULL;
319 ConnectInfo.CreateContext = TRUE;
320
322 &PortName,
323 &SecurityQos,
324 NULL,
325 NULL,
326 NULL,
327 &ConnectInfo,
328 &ConnectInfoLength);
329 if (!NT_SUCCESS(Status))
330 {
331 DPRINT1("ZwConnectPort failed (Status 0x%08lx)\n", Status);
332 return Status;
333 }
334
335 DPRINT("ConnectInfo.OperationalMode: 0x%08lx\n", ConnectInfo.OperationalMode);
336 *OperationalMode = ConnectInfo.OperationalMode;
337
338 if (!NT_SUCCESS(ConnectInfo.Status))
339 {
340 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo.Status);
341 }
342
343 return ConnectInfo.Status;
344}
static UNICODE_STRING PortName
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
HANDLE LsaHandle
Definition: wkssvc.c:41
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG AuthenticationPackage
Definition: logon.c:18
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
VOID NTAPI ProtocolStatus(NDIS_HANDLE BindingContext, NDIS_STATUS GenerelStatus, PVOID StatusBuffer, UINT StatusBufferSize)
Called by NDIS when the underlying driver has changed state.
Definition: lan.c:461
NTSYSAPI NTSTATUS NTAPI ZwRequestWaitReplyPort(_In_ HANDLE PortHandle, _Out_ PPORT_MESSAGE LpcReply, _In_ PPORT_MESSAGE LpcRequest)
NTSYSAPI NTSTATUS NTAPI ZwConnectPort(_Out_ PHANDLE PortHandle, _In_ PUNICODE_STRING PortName, _In_ PSECURITY_QUALITY_OF_SERVICE SecurityQos, _In_opt_ PPORT_VIEW ClientView, _In_opt_ PREMOTE_PORT_VIEW ServerView, _In_opt_ PULONG MaxMessageLength, _In_opt_ PVOID ConnectionInformation, _In_opt_ PULONG ConnectionInformationLength)
@ SecurityIdentification
Definition: lsa.idl:56
#define LSASS_MAX_PACKAGE_NAME_LENGTH
Definition: lsass.h:16
#define LSASS_MAX_LOGON_PROCESS_NAME_LENGTH
Definition: lsass.h:15
#define LSA_PORT_MESSAGE_SIZE
Definition: lsass.h:200
#define LSA_PORT_DATA_SIZE(c)
Definition: lsass.h:199
@ LSASS_REQUEST_LOGON_USER
Definition: lsass.h:22
@ LSASS_REQUEST_CALL_AUTHENTICATION_PACKAGE
Definition: lsass.h:20
@ LSASS_REQUEST_LOOKUP_AUTHENTICATION_PACKAGE
Definition: lsass.h:23
@ LSASS_REQUEST_DEREGISTER_LOGON_PROCESS
Definition: lsass.h:21
* PNTSTATUS
Definition: strlen.c:14
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSCALLAPI NTSTATUS NTAPI ZwOpenEvent(_Out_ PHANDLE EventHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RELEASE
Definition: nt_native.h:1316
#define ANSI_NULL
@ NotificationEvent
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE LogonType
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS LocalGroups
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE _Out_ PQUOTA_LIMITS Quotas
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE SourceContext
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE _Out_ PQUOTA_LIMITS _Out_ PNTSTATUS SubStatus
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG AuthenticationInformationLength
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID * ProfileBuffer
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG ProfileBufferLength
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID LogonId
_IRQL_requires_same_ _In_ PLSA_STRING OriginName
NTSTATUS NTAPI LsaLogonUser(HANDLE, PLSA_STRING, SECURITY_LOGON_TYPE, ULONG, PVOID, ULONG, PTOKEN_GROUPS, PTOKEN_SOURCE, PVOID *, PULONG, PLUID, PHANDLE, PQUOTA_LIMITS, PNTSTATUS)
ULONG * PLSA_OPERATIONAL_MODE
Definition: ntsecapi.h:367
NTSTATUS NTAPI LsaLookupAuthenticationPackage(HANDLE, PLSA_STRING, PULONG)
enum _SECURITY_LOGON_TYPE SECURITY_LOGON_TYPE
NTSTATUS NTAPI LsaFreeReturnBuffer(PVOID)
NTSTATUS NTAPI LsaRegisterLogonProcess(PLSA_STRING, PHANDLE, PLSA_OPERATIONAL_MODE)
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:498
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI LsaDeregisterLogonProcess(IN HANDLE LsaHandle)
Definition: lsa.c:80
NTSTATUS NTAPI LsaCallAuthenticationPackage(IN HANDLE LsaHandle, IN ULONG AuthenticationPackage, IN PVOID ProtocolSubmitBuffer, IN ULONG SubmitBufferLength, OUT PVOID *ProtocolReturnBuffer, OUT PULONG ReturnBufferLength, OUT PNTSTATUS ProtocolStatus)
Definition: lsa.c:30
#define DPRINT
Definition: sndvol32.h:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
LSA_LOGON_USER_MSG LogonUser
Definition: lsass.h:187
NTSTATUS Status
Definition: lsass.h:184
PORT_MESSAGE h
Definition: lsass.h:177
LSA_DEREGISTER_LOGON_PROCESS_MSG DeregisterLogonProcess
Definition: lsass.h:189
LSA_API_NUMBER ApiNumber
Definition: lsass.h:183
LSA_CALL_AUTHENTICATION_PACKAGE_MSG CallAuthenticationPackage
Definition: lsass.h:188
LSA_LOOKUP_AUTHENTICATION_PACKAGE_MSG LookupAuthenticationPackage
Definition: lsass.h:190
struct _LSA_CALL_AUTHENTICATION_PACKAGE_MSG::@3470::@3473 Reply
struct _LSA_CALL_AUTHENTICATION_PACKAGE_MSG::@3470::@3472 Request
BOOL CreateContext
Definition: lsass.h:37
LSA_OPERATIONAL_MODE OperationalMode
Definition: lsass.h:34
NTSTATUS Status
Definition: lsass.h:33
CHAR LogonProcessNameBuffer[LSASS_MAX_LOGON_PROCESS_NAME_LENGTH+1]
Definition: lsass.h:36
struct _LSA_LOGON_USER_MSG::@3466::@3469 Reply
struct _LSA_LOGON_USER_MSG::@3466::@3468 Request
struct _LSA_LOOKUP_AUTHENTICATION_PACKAGE_MSG::@3478::@3481 Reply
struct _LSA_LOOKUP_AUTHENTICATION_PACKAGE_MSG::@3478::@3480 Request
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103