ReactOS 0.4.15-dev-7897-g78dc504
lsalpc.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: dll/win32/secur32/lsalpc.c
5 * PURPOSE: LSA LPC port functions
6 */
7
8/* INCLUDES ******************************************************************/
9
10#include "precomp.h"
11
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>
19
20#include <wine/debug.h>
22
23
24/* GLOBALS *******************************************************************/
25
27
28extern HANDLE Secur32Heap;
29
30
31/* FUNCTIONS *****************************************************************/
32
33VOID
35{
37}
38
39
40VOID
42{
43 if (LsaPortHandle != NULL)
44 {
47 }
48}
49
50
53{
56 LSA_CONNECTION_INFO ConnectInfo;
57 ULONG ConnectInfoLength;
59
60 TRACE("LsapOpenLsaPort()\n");
61
62 if (LsaPortHandle != NULL)
63 return STATUS_SUCCESS;
64
66 L"\\LsaAuthenticationPort");
67
68 SecurityQos.Length = sizeof(SecurityQos);
71 SecurityQos.EffectiveOnly = TRUE;
72
73 RtlZeroMemory(&ConnectInfo,
74 sizeof(ConnectInfo));
75
76 ConnectInfo.CreateContext = FALSE;
77 ConnectInfo.TrustedCaller = TRUE;
78
79 ConnectInfoLength = sizeof(LSA_CONNECTION_INFO);
81 &PortName,
82 &SecurityQos,
83 NULL,
84 NULL,
85 NULL,
86 &ConnectInfo,
87 &ConnectInfoLength);
88 if (!NT_SUCCESS(Status))
89 {
90 TRACE("NtConnectPort failed (Status 0x%08lx)\n", Status);
91 }
92
93 return Status;
94/*
95 if (!NT_SUCCESS(ConnectInfo.Status))
96 {
97 DPRINT1("ConnectInfo.Status: 0x%08lx\n", ConnectInfo.Status);
98 }
99
100 return ConnectInfo.Status;
101*/
102}
103
104
105/* PUBLIC FUNCTIONS **********************************************************/
106
107/*
108 * @implemented
109 */
111NTAPI
114{
116 SECURITY_QUALITY_OF_SERVICE SecurityQos;
117 LSA_CONNECTION_INFO ConnectInfo;
118 ULONG ConnectInfoLength = sizeof(ConnectInfo);
120 UNICODE_STRING EventName;
123
124 TRACE("LsaConnectUntrusted(%p)\n", LsaHandle);
125
126 // TODO: we may need to impersonate ourselves before, because we are untrusted!
127
128 /* Wait for the LSA authentication thread */
129 RtlInitUnicodeString(&EventName,
130 L"\\SECURITY\\LSA_AUTHENTICATION_INITIALIZED");
132 &EventName,
134 NULL,
135 NULL);
139 if (!NT_SUCCESS(Status))
140 {
141 WARN("NtOpenEvent failed (Status 0x%08lx)\n", Status);
142
147 FALSE);
148 if (!NT_SUCCESS(Status))
149 {
150 WARN("NtCreateEvent failed (Status 0x%08lx)\n", Status);
151 return Status;
152 }
153 }
154
156 TRUE,
157 NULL);
159 if (!NT_SUCCESS(Status))
160 {
161 ERR("NtWaitForSingleObject failed (Status 0x%08lx)\n", Status);
162 return Status;
163 }
164
165 /* Connect to the authentication port */
167 L"\\LsaAuthenticationPort");
168
169 SecurityQos.Length = sizeof(SecurityQos);
172 SecurityQos.EffectiveOnly = TRUE;
173
174 RtlZeroMemory(&ConnectInfo,
175 ConnectInfoLength);
176
177 ConnectInfo.CreateContext = TRUE;
178 ConnectInfo.TrustedCaller = FALSE;
179
181 &PortName,
182 &SecurityQos,
183 NULL,
184 NULL,
185 NULL,
186 &ConnectInfo,
187 &ConnectInfoLength);
188 if (!NT_SUCCESS(Status))
189 {
190 ERR("NtConnectPort failed (Status 0x%08lx)\n", Status);
191 return Status;
192 }
193
194 if (!NT_SUCCESS(ConnectInfo.Status))
195 {
196 ERR("ConnectInfo.Status: 0x%08lx\n", ConnectInfo.Status);
197 }
198
199 return ConnectInfo.Status;
200}
201
202
203/*
204 * @implemented
205 */
207NTAPI
209 PULONG LogonSessionCount,
210 PLUID *LogonSessionList)
211{
212 LSA_API_MSG ApiMessage;
214
215 TRACE("LsaEnumerateLogonSessions(%p %p)\n", LogonSessionCount, LogonSessionList);
216
218 if (!NT_SUCCESS(Status))
219 return Status;
220
222 ApiMessage.h.u1.s1.DataLength = LSA_PORT_DATA_SIZE(ApiMessage.EnumLogonSessions);
223 ApiMessage.h.u1.s1.TotalLength = LSA_PORT_MESSAGE_SIZE;
224 ApiMessage.h.u2.ZeroInit = 0;
225
227 (PPORT_MESSAGE)&ApiMessage,
228 (PPORT_MESSAGE)&ApiMessage);
229 if (!NT_SUCCESS(Status))
230 {
231 ERR("NtRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
232 return Status;
233 }
234
235 if (!NT_SUCCESS(ApiMessage.Status))
236 {
237 ERR("NtRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
238 return ApiMessage.Status;
239 }
240
241 *LogonSessionCount = ApiMessage.EnumLogonSessions.Reply.LogonSessionCount;
242 *LogonSessionList = ApiMessage.EnumLogonSessions.Reply.LogonSessionBuffer;
243
244 return Status;
245}
246
247
248/*
249 * @unimplemented
250 */
252NTAPI
255 PSECURITY_LOGON_SESSION_DATA *ppLogonSessionData)
256{
257 LSA_API_MSG ApiMessage;
260
261 TRACE("LsaGetLogonSessionData(%p %p)\n", LogonId, ppLogonSessionData);
262
264 if (!NT_SUCCESS(Status))
265 return Status;
266
268 ApiMessage.h.u1.s1.DataLength = LSA_PORT_DATA_SIZE(ApiMessage.GetLogonSessionData);
269 ApiMessage.h.u1.s1.TotalLength = LSA_PORT_MESSAGE_SIZE;
270 ApiMessage.h.u2.ZeroInit = 0;
271
272 RtlCopyLuid(&ApiMessage.GetLogonSessionData.Request.LogonId,
273 LogonId);
274
276 (PPORT_MESSAGE)&ApiMessage,
277 (PPORT_MESSAGE)&ApiMessage);
278 if (!NT_SUCCESS(Status))
279 {
280 ERR("NtRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
281 return Status;
282 }
283
284 if (!NT_SUCCESS(ApiMessage.Status))
285 {
286 ERR("NtRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
287 return ApiMessage.Status;
288 }
289
290 SessionData = ApiMessage.GetLogonSessionData.Reply.SessionDataBuffer;
291
292 TRACE("UserName: %p\n", SessionData->UserName.Buffer);
293 if (SessionData->UserName.Buffer != NULL)
294 SessionData->UserName.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->UserName.Buffer);
295
296 TRACE("LogonDomain: %p\n", SessionData->LogonDomain.Buffer);
297 if (SessionData->LogonDomain.Buffer != NULL)
298 SessionData->LogonDomain.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->LogonDomain.Buffer);
299
300 TRACE("AuthenticationPackage: %p\n", SessionData->AuthenticationPackage.Buffer);
301 if (SessionData->AuthenticationPackage.Buffer != NULL)
302 SessionData->AuthenticationPackage.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->AuthenticationPackage.Buffer);
303
304 TRACE("Sid: %p\n", SessionData->Sid);
305 if (SessionData->Sid != NULL)
306 SessionData->Sid = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->Sid);
307
308 TRACE("LogonServer: %p\n", SessionData->LogonServer.Buffer);
309 if (SessionData->LogonServer.Buffer != NULL)
310 SessionData->LogonServer.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->LogonServer.Buffer);
311
312 TRACE("DnsDomainName: %p\n", SessionData->DnsDomainName.Buffer);
313 if (SessionData->DnsDomainName.Buffer != NULL)
314 SessionData->DnsDomainName.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->DnsDomainName.Buffer);
315
316 TRACE("Upn: %p\n", SessionData->Upn.Buffer);
317 if (SessionData->Upn.Buffer != NULL)
318 SessionData->Upn.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->Upn.Buffer);
319
320 *ppLogonSessionData = SessionData;
321
322 return Status;
323}
324
325
326/*
327 * @implemented
328 */
330NTAPI
333 HANDLE NotificationEventHandle)
334{
335 LSA_API_MSG ApiMessage;
337
338 TRACE("LsaRegisterPolicyChangeNotification(%lu %p)\n",
339 InformationClass, NotificationEventHandle);
340
342 if (!NT_SUCCESS(Status))
343 return Status;
344
346 ApiMessage.h.u1.s1.DataLength = LSA_PORT_DATA_SIZE(ApiMessage.PolicyChangeNotify);
347 ApiMessage.h.u1.s1.TotalLength = LSA_PORT_MESSAGE_SIZE;
348 ApiMessage.h.u2.ZeroInit = 0;
349
350 ApiMessage.PolicyChangeNotify.Request.InformationClass = InformationClass;
351 ApiMessage.PolicyChangeNotify.Request.NotificationEventHandle = NotificationEventHandle;
352 ApiMessage.PolicyChangeNotify.Request.Register = TRUE;
353
355 (PPORT_MESSAGE)&ApiMessage,
356 (PPORT_MESSAGE)&ApiMessage);
357 if (!NT_SUCCESS(Status))
358 {
359 ERR("NtRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
360 return Status;
361 }
362
363 if (!NT_SUCCESS(ApiMessage.Status))
364 {
365 ERR("NtRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
366 return ApiMessage.Status;
367 }
368
369 return Status;
370}
371
372
373/*
374 * @implemented
375 */
377NTAPI
380 HANDLE NotificationEventHandle)
381{
382 LSA_API_MSG ApiMessage;
384
385 TRACE("LsaUnregisterPolicyChangeNotification(%lu %p)\n",
386 InformationClass, NotificationEventHandle);
387
389 if (!NT_SUCCESS(Status))
390 return Status;
391
393 ApiMessage.h.u1.s1.DataLength = LSA_PORT_DATA_SIZE(ApiMessage.PolicyChangeNotify);
394 ApiMessage.h.u1.s1.TotalLength = LSA_PORT_MESSAGE_SIZE;
395 ApiMessage.h.u2.ZeroInit = 0;
396
397 ApiMessage.PolicyChangeNotify.Request.InformationClass = InformationClass;
398 ApiMessage.PolicyChangeNotify.Request.NotificationEventHandle = NotificationEventHandle;
399 ApiMessage.PolicyChangeNotify.Request.Register = FALSE;
400
402 (PPORT_MESSAGE)&ApiMessage,
403 (PPORT_MESSAGE)&ApiMessage);
404 if (!NT_SUCCESS(Status))
405 {
406 ERR("NtRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
407 return Status;
408 }
409
410 if (!NT_SUCCESS(ApiMessage.Status))
411 {
412 ERR("NtRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
413 return ApiMessage.Status;
414 }
415
416 return Status;
417}
418
419/* EOF */
static UNICODE_STRING PortName
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
HANDLE LsaHandle
Definition: wkssvc.c:41
#define WARN(fmt,...)
Definition: debug.h:112
#define ERR(fmt,...)
Definition: debug.h:110
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
#define ULONG_PTR
Definition: config.h:101
_In_ FILTER_INFORMATION_CLASS InformationClass
Definition: fltkernel.h:1713
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
@ SecurityIdentification
Definition: lsa.idl:56
NTSTATUS NTAPI LsaConnectUntrusted(OUT PHANDLE LsaHandle)
Definition: lsalpc.c:112
NTSTATUS NTAPI LsaGetLogonSessionData(PLUID LogonId, PSECURITY_LOGON_SESSION_DATA *ppLogonSessionData)
Definition: lsalpc.c:253
NTSTATUS NTAPI LsaEnumerateLogonSessions(PULONG LogonSessionCount, PLUID *LogonSessionList)
Definition: lsalpc.c:208
NTSTATUS NTAPI LsaRegisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass, HANDLE NotificationEventHandle)
Definition: lsalpc.c:331
NTSTATUS LsapOpenLsaPort(VOID)
Definition: lsalpc.c:52
NTSTATUS NTAPI LsaUnregisterPolicyChangeNotification(POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass, HANDLE NotificationEventHandle)
Definition: lsalpc.c:378
HANDLE Secur32Heap
Definition: dllmain.c:17
VOID LsapInitLsaPort(VOID)
Definition: lsalpc.c:34
VOID LsapCloseLsaPort(VOID)
Definition: lsalpc.c:41
HANDLE LsaPortHandle
Definition: lsalpc.c:26
#define LSA_PORT_MESSAGE_SIZE
Definition: lsass.h:200
struct _LSA_CONNECTION_INFO LSA_CONNECTION_INFO
#define LSA_PORT_DATA_SIZE(c)
Definition: lsass.h:199
@ LSASS_REQUEST_ENUM_LOGON_SESSIONS
Definition: lsass.h:24
@ LSASS_REQUEST_POLICY_CHANGE_NOTIFY
Definition: lsass.h:26
@ LSASS_REQUEST_GET_LOGON_SESSION_DATA
Definition: lsass.h:25
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
@ NotificationEvent
_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
NTSTATUS NTAPI NtOpenEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: event.c:181
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
NTSTATUS NTAPI NtConnectPort(OUT PHANDLE PortHandle, IN PUNICODE_STRING PortName, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos, IN OUT PPORT_VIEW ClientView OPTIONAL, IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL, OUT PULONG MaxMessageLength OPTIONAL, IN OUT PVOID ConnectionInformation OPTIONAL, IN OUT PULONG ConnectionInformationLength OPTIONAL)
Definition: connect.c:777
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:696
enum _POLICY_NOTIFICATION_INFORMATION_CLASS POLICY_NOTIFICATION_INFORMATION_CLASS
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
LSA_ENUM_LOGON_SESSIONS_MSG EnumLogonSessions
Definition: lsass.h:191
NTSTATUS Status
Definition: lsass.h:184
PORT_MESSAGE h
Definition: lsass.h:177
LSA_POLICY_CHANGE_NOTIFY_MSG PolicyChangeNotify
Definition: lsass.h:193
LSA_GET_LOGON_SESSION_DATA_MSG GetLogonSessionData
Definition: lsass.h:192
LSA_API_NUMBER ApiNumber
Definition: lsass.h:183
BOOL CreateContext
Definition: lsass.h:37
BOOL TrustedCaller
Definition: lsass.h:38
NTSTATUS Status
Definition: lsass.h:33
struct _LSA_ENUM_LOGON_SESSIONS_MSG::@3507::@3510 Reply
struct _LSA_GET_LOGON_SESSION_DATA_MSG::@3511::@3514 Reply
struct _LSA_GET_LOGON_SESSION_DATA_MSG::@3511::@3513 Request
struct _LSA_POLICY_CHANGE_NOTIFY_MSG::@3515::@3517 Request
LSA_UNICODE_STRING Upn
Definition: ntsecapi.h:315
LSA_UNICODE_STRING DnsDomainName
Definition: ntsecapi.h:314
LSA_UNICODE_STRING LogonDomain
Definition: ntsecapi.h:307
LSA_UNICODE_STRING LogonServer
Definition: ntsecapi.h:313
LSA_UNICODE_STRING UserName
Definition: ntsecapi.h:306
LSA_UNICODE_STRING AuthenticationPackage
Definition: ntsecapi.h:308
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103
WCHAR * LPWSTR
Definition: xmlstorage.h:184