ReactOS  0.4.14-dev-606-g14ebc0b
session.c File Reference
#include "lsasrv.h"
Include dependency graph for session.c:

Go to the source code of this file.

Classes

struct  _LSAP_LOGON_SESSION
 

Typedefs

typedef struct _LSAP_LOGON_SESSION LSAP_LOGON_SESSION
 
typedef struct _LSAP_LOGON_SESSIONPLSAP_LOGON_SESSION
 

Functions

VOID LsapInitLogonSessions (VOID)
 
static PLSAP_LOGON_SESSION LsapGetLogonSession (IN PLUID LogonId)
 
NTSTATUS LsapSetLogonSessionData (_In_ PLUID LogonId, _In_ ULONG LogonType, _In_ PUNICODE_STRING UserName, _In_ PUNICODE_STRING LogonDomain, _In_ PSID Sid)
 
NTSTATUS NTAPI LsapCreateLogonSession (IN PLUID LogonId)
 
NTSTATUS NTAPI LsapDeleteLogonSession (IN PLUID LogonId)
 
NTSTATUS NTAPI LsapAddCredential (_In_ PLUID LogonId, _In_ ULONG AuthenticationPackage, _In_ PLSA_STRING PrimaryKeyValue, _In_ PLSA_STRING Credential)
 
NTSTATUS NTAPI LsapGetCredentials (_In_ PLUID LogonId, _In_ ULONG AuthenticationPackage, _Inout_ PULONG QueryContext, _In_ BOOLEAN RetrieveAllCredentials, _Inout_ PLSA_STRING PrimaryKeyValue, _Out_ PULONG PrimaryKeyLength, _Out_ PLSA_STRING Credentials)
 
NTSTATUS NTAPI LsapDeleteCredential (_In_ PLUID LogonId, _In_ ULONG AuthenticationPackage, _In_ PLSA_STRING PrimaryKeyValue)
 
NTSTATUS LsapEnumLogonSessions (IN OUT PLSA_API_MSG RequestMsg)
 
NTSTATUS LsapGetLogonSessionData (IN OUT PLSA_API_MSG RequestMsg)
 

Variables

LIST_ENTRY SessionListHead
 
ULONG SessionCount
 

Typedef Documentation

◆ LSAP_LOGON_SESSION

◆ PLSAP_LOGON_SESSION

Function Documentation

◆ LsapAddCredential()

NTSTATUS NTAPI LsapAddCredential ( _In_ PLUID  LogonId,
_In_ ULONG  AuthenticationPackage,
_In_ PLSA_STRING  PrimaryKeyValue,
_In_ PLSA_STRING  Credential 
)

Definition at line 214 of file session.c.

219 {
220 
221  return STATUS_SUCCESS;
222 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by LsapInitAuthPackages().

◆ LsapCreateLogonSession()

NTSTATUS NTAPI LsapCreateLogonSession ( IN PLUID  LogonId)

Definition at line 117 of file session.c.

118 {
119  PLSAP_LOGON_SESSION Session;
121 
122  TRACE("LsapCreateLogonSession(%p)\n", LogonId);
123 
124  /* Fail, if a session already exists */
127 
128  /* Allocate a new session entry */
129  Session = RtlAllocateHeap(RtlGetProcessHeap(),
131  sizeof(LSAP_LOGON_SESSION));
132  if (Session == NULL)
134 
135  /* Initialize the session entry */
136  RtlCopyLuid(&Session->LogonId, LogonId);
137 
138  TRACE("LsapCreateLogonSession(<0x%lx,0x%lx>)\n",
139  LogonId->HighPart, LogonId->LowPart);
140 
141  /* Tell ntoskrnl to create a new logon session */
143  if (!NT_SUCCESS(Status))
144  {
145  RtlFreeHeap(RtlGetProcessHeap(), 0, Session);
146  return Status;
147  }
148 
149  /* Insert the new session into the session list */
150  InsertHeadList(&SessionListHead, &Session->Entry);
151  SessionCount++;
152 
153  return STATUS_SUCCESS;
154 }
#define STATUS_LOGON_SESSION_COLLISION
Definition: ntstatus.h:483
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
static PLSAP_LOGON_SESSION LsapGetLogonSession(IN PLUID LogonId)
Definition: session.c:45
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
NTSTATUS LsapRmCreateLogonSession(PLUID LogonId)
Definition: srm.c:245
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LIST_ENTRY SessionListHead
Definition: session.c:30
Status
Definition: gdiplustypes.h:24
_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
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG SessionCount
Definition: session.c:31
LIST_ENTRY Entry
Definition: session.c:13

Referenced by LsapInitAuthPackages().

◆ LsapDeleteCredential()

NTSTATUS NTAPI LsapDeleteCredential ( _In_ PLUID  LogonId,
_In_ ULONG  AuthenticationPackage,
_In_ PLSA_STRING  PrimaryKeyValue 
)

Definition at line 243 of file session.c.

247 {
248 
249  return STATUS_SUCCESS;
250 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by LsapInitAuthPackages().

◆ LsapDeleteLogonSession()

NTSTATUS NTAPI LsapDeleteLogonSession ( IN PLUID  LogonId)

Definition at line 159 of file session.c.

160 {
161  PLSAP_LOGON_SESSION Session;
163 
164  TRACE("LsapDeleteLogonSession(%p)\n", LogonId);
165 
166  /* Fail, if the session does not exist */
167  Session = LsapGetLogonSession(LogonId);
168  if (Session == NULL)
170 
171  TRACE("LsapDeleteLogonSession(<0x%lx,0x%lx>)\n",
172  LogonId->HighPart, LogonId->LowPart);
173 
174  /* Tell ntoskrnl to delete the logon session */
176  if (!NT_SUCCESS(Status))
177  return Status;
178 
179  /* Remove the session entry from the list */
180  RemoveEntryList(&Session->Entry);
181  SessionCount--;
182 
183  /* Free the session data */
184  if (Session->Sid != NULL)
185  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->Sid);
186 
187  if (Session->UserName.Buffer != NULL)
188  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName.Buffer);
189 
190  if (Session->LogonDomain.Buffer != NULL)
191  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->LogonDomain.Buffer);
192 
193  if (Session->AuthenticationPackage.Buffer != NULL)
194  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->AuthenticationPackage.Buffer);
195 
196  if (Session->LogonServer.Buffer != NULL)
197  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->LogonServer.Buffer);
198 
199  if (Session->DnsDomainName.Buffer != NULL)
200  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->DnsDomainName.Buffer);
201 
202  if (Session->Upn.Buffer != NULL)
203  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->Upn.Buffer);
204 
205  /* Free the session entry */
206  RtlFreeHeap(RtlGetProcessHeap(), 0, Session);
207 
208  return STATUS_SUCCESS;
209 }
#define STATUS_NO_SUCH_LOGON_SESSION
Definition: ntstatus.h:317
static PLSAP_LOGON_SESSION LsapGetLogonSession(IN PLUID LogonId)
Definition: session.c:45
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
UNICODE_STRING UserName
Definition: session.c:19
UNICODE_STRING LogonServer
Definition: session.c:22
UNICODE_STRING LogonDomain
Definition: session.c:20
UNICODE_STRING AuthenticationPackage
Definition: session.c:21
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
NTSTATUS LsapRmDeleteLogonSession(PLUID LogonId)
Definition: srm.c:285
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING DnsDomainName
Definition: session.c:23
Status
Definition: gdiplustypes.h:24
UNICODE_STRING Upn
Definition: session.c:24
_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
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG SessionCount
Definition: session.c:31
LIST_ENTRY Entry
Definition: session.c:13

Referenced by LsapInitAuthPackages(), and LsapLogonUser().

◆ LsapEnumLogonSessions()

NTSTATUS LsapEnumLogonSessions ( IN OUT PLSA_API_MSG  RequestMsg)

Definition at line 254 of file session.c.

255 {
258  PLIST_ENTRY SessionEntry;
259  PLSAP_LOGON_SESSION CurrentSession;
260  PLUID SessionList;
261  ULONG i, Length;
262  SIZE_T MemSize;
263  PVOID ClientBaseAddress = NULL;
265 
266  TRACE("LsapEnumLogonSessions(%p)\n", RequestMsg);
267 
268  Length = SessionCount * sizeof(LUID);
269  SessionList = RtlAllocateHeap(RtlGetProcessHeap(),
271  Length);
272  if (SessionList == NULL)
274 
275  i = 0;
276  SessionEntry = SessionListHead.Flink;
277  while (SessionEntry != &SessionListHead)
278  {
279  CurrentSession = CONTAINING_RECORD(SessionEntry,
281  Entry);
282 
283  RtlCopyLuid(&SessionList[i],
284  &CurrentSession->LogonId);
285 
286  SessionEntry = SessionEntry->Flink;
287  i++;
288  }
289 
291  NULL,
292  0,
293  NULL,
294  NULL);
295 
299  &RequestMsg->h.ClientId);
300  if (!NT_SUCCESS(Status))
301  {
302  TRACE("NtOpenProcess() failed (Status %lx)\n", Status);
303  goto done;
304  }
305 
306  TRACE("Length: %lu\n", Length);
307 
308  MemSize = Length;
310  &ClientBaseAddress,
311  0,
312  &MemSize,
313  MEM_COMMIT,
315  if (!NT_SUCCESS(Status))
316  {
317  TRACE("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
318  goto done;
319  }
320 
321  TRACE("MemSize: %lu\n", MemSize);
322  TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
323 
325  ClientBaseAddress,
326  SessionList,
327  Length,
328  NULL);
329  if (!NT_SUCCESS(Status))
330  {
331  TRACE("NtWriteVirtualMemory() failed (Status %lx)\n", Status);
332  goto done;
333  }
334 
335  RequestMsg->EnumLogonSessions.Reply.LogonSessionCount = SessionCount;
336  RequestMsg->EnumLogonSessions.Reply.LogonSessionBuffer = ClientBaseAddress;
337 
338 done:
339  if (ProcessHandle != NULL)
341 
342  if (SessionList != NULL)
343  RtlFreeHeap(RtlGetProcessHeap(), 0, SessionList);
344 
345  return Status;
346 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
#define MEM_COMMIT
Definition: nt_native.h:1313
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1440
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _LUID LUID
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
#define PROCESS_VM_WRITE
Definition: pstypes.h:154
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
LIST_ENTRY SessionListHead
Definition: session.c:30
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4367
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define PROCESS_VM_READ
Definition: pstypes.h:153
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define PROCESS_VM_OPERATION
Definition: pstypes.h:152
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSTATUS NTAPI NtWriteVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN PVOID Buffer, IN SIZE_T NumberOfBytesToWrite, OUT PSIZE_T NumberOfBytesWritten OPTIONAL)
Definition: virtual.c:2805
ULONG SessionCount
Definition: session.c:31
base of all file and directory entries
Definition: entries.h:82
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by AuthPortThreadRoutine().

◆ LsapGetCredentials()

NTSTATUS NTAPI LsapGetCredentials ( _In_ PLUID  LogonId,
_In_ ULONG  AuthenticationPackage,
_Inout_ PULONG  QueryContext,
_In_ BOOLEAN  RetrieveAllCredentials,
_Inout_ PLSA_STRING  PrimaryKeyValue,
_Out_ PULONG  PrimaryKeyLength,
_Out_ PLSA_STRING  Credentials 
)

Definition at line 227 of file session.c.

235 {
236 
237  return STATUS_SUCCESS;
238 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by LsapInitAuthPackages().

◆ LsapGetLogonSession()

static PLSAP_LOGON_SESSION LsapGetLogonSession ( IN PLUID  LogonId)
static

Definition at line 45 of file session.c.

46 {
47  PLIST_ENTRY SessionEntry;
48  PLSAP_LOGON_SESSION CurrentSession;
49 
50  SessionEntry = SessionListHead.Flink;
51  while (SessionEntry != &SessionListHead)
52  {
53  CurrentSession = CONTAINING_RECORD(SessionEntry,
55  Entry);
56  if (RtlEqualLuid(&CurrentSession->LogonId, LogonId))
57  return CurrentSession;
58 
59  SessionEntry = SessionEntry->Flink;
60  }
61 
62  return NULL;
63 }
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:301
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY SessionListHead
Definition: session.c:30
Definition: typedefs.h:117
_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
base of all file and directory entries
Definition: entries.h:82

Referenced by LsapCreateLogonSession(), LsapDeleteLogonSession(), LsapGetLogonSessionData(), and LsapSetLogonSessionData().

◆ LsapGetLogonSessionData()

NTSTATUS LsapGetLogonSessionData ( IN OUT PLSA_API_MSG  RequestMsg)

Definition at line 350 of file session.c.

351 {
354  PLSAP_LOGON_SESSION Session;
355  PSECURITY_LOGON_SESSION_DATA LocalSessionData;
356  PVOID ClientBaseAddress = NULL;
357  ULONG TotalLength, SidLength = 0;
358  SIZE_T MemSize;
359  PUCHAR Ptr;
361 
362  TRACE("LsapGetLogonSessionData(%p)\n", RequestMsg);
363 
364  TRACE("LogonId: %lx\n", RequestMsg->GetLogonSessionData.Request.LogonId.LowPart);
365  Session = LsapGetLogonSession(&RequestMsg->GetLogonSessionData.Request.LogonId);
366  if (Session == NULL)
368 
369  /* Calculate the required buffer size */
371  Session->UserName.MaximumLength +
372  Session->LogonDomain.MaximumLength +
374  Session->LogonServer.MaximumLength +
375  Session->DnsDomainName.MaximumLength +
376  Session->Upn.MaximumLength;
377  if (Session->Sid != NULL)
378  {
379  SidLength = RtlLengthSid(Session->Sid);
380  TotalLength += SidLength;
381  }
382  TRACE("TotalLength: %lu\n", TotalLength);
383 
384  /* Allocate the buffer */
385  LocalSessionData = RtlAllocateHeap(RtlGetProcessHeap(),
387  TotalLength);
388  if (LocalSessionData == NULL)
390 
391  Ptr = (PUCHAR)((ULONG_PTR)LocalSessionData + sizeof(SECURITY_LOGON_SESSION_DATA));
392  TRACE("LocalSessionData: %p Ptr: %p\n", LocalSessionData, Ptr);
393 
394  LocalSessionData->Size = sizeof(SECURITY_LOGON_SESSION_DATA);
395 
396  /* Copy the LogonId */
397  RtlCopyLuid(&LocalSessionData->LogonId,
398  &RequestMsg->GetLogonSessionData.Request.LogonId);
399 
400  /* Copy the UserName string*/
401  LocalSessionData->UserName.Length = Session->UserName.Length;
402  LocalSessionData->UserName.MaximumLength = Session->UserName.MaximumLength;
403 
404  if (Session->UserName.MaximumLength != 0)
405  {
406  RtlCopyMemory(Ptr, Session->UserName.Buffer, Session->UserName.MaximumLength);
407  LocalSessionData->UserName.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
408 
409  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->UserName.MaximumLength);
410  }
411 
412  /* Copy the LogonDomain string */
413  LocalSessionData->LogonDomain.Length = Session->LogonDomain.Length;
414  LocalSessionData->LogonDomain.MaximumLength = Session->LogonDomain.MaximumLength;
415  if (Session->LogonDomain.MaximumLength != 0)
416  {
418  LocalSessionData->LogonDomain.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
419 
420  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->LogonDomain.MaximumLength);
421  }
422 
423  /* Copy the AuthenticationPackage string */
424  LocalSessionData->AuthenticationPackage.Length = Session->AuthenticationPackage.Length;
425  LocalSessionData->AuthenticationPackage.MaximumLength = Session->AuthenticationPackage.MaximumLength;
426  if (Session->AuthenticationPackage.MaximumLength != 0)
427  {
429  LocalSessionData->AuthenticationPackage.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
430 
432  }
433 
434  LocalSessionData->LogonType = Session->LogonType;
435  LocalSessionData->Session = 0;
436 
437  /* Sid */
438  if (Session->Sid != NULL)
439  {
440  RtlCopyMemory(Ptr, Session->Sid, SidLength);
441  LocalSessionData->Sid = (PSID)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
442 
443  Ptr = (PUCHAR)((ULONG_PTR)Ptr + SidLength);
444  }
445 
446  /* LogonTime */
447  LocalSessionData->LogonTime.QuadPart = Session->LogonTime.QuadPart;
448 
449  /* Copy the LogonServer string */
450  LocalSessionData->LogonServer.Length = Session->LogonServer.Length;
451  LocalSessionData->LogonServer.MaximumLength = Session->LogonServer.MaximumLength;
452  if (Session->LogonServer.MaximumLength != 0)
453  {
455  LocalSessionData->LogonServer.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
456 
457  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->LogonServer.MaximumLength);
458  }
459 
460  /* Copy the DnsDomainName string */
461  LocalSessionData->DnsDomainName.Length = Session->DnsDomainName.Length;
462  LocalSessionData->DnsDomainName.MaximumLength = Session->DnsDomainName.MaximumLength;
463  if (Session->DnsDomainName.MaximumLength != 0)
464  {
466  LocalSessionData->DnsDomainName.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
467 
469  }
470 
471  /* Copy the Upn string */
472  LocalSessionData->Upn.Length = Session->Upn.Length;
473  LocalSessionData->Upn.MaximumLength = Session->Upn.MaximumLength;
474  if (Session->Upn.MaximumLength != 0)
475  {
476  RtlCopyMemory(Ptr, Session->Upn.Buffer, Session->Upn.MaximumLength);
477  LocalSessionData->Upn.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
478 
479  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->Upn.MaximumLength);
480  }
481 
482 
484  NULL,
485  0,
486  NULL,
487  NULL);
488 
492  &RequestMsg->h.ClientId);
493  if (!NT_SUCCESS(Status))
494  {
495  TRACE("NtOpenProcess() failed (Status %lx)\n", Status);
496  goto done;
497  }
498 
499  MemSize = TotalLength;
501  &ClientBaseAddress,
502  0,
503  &MemSize,
504  MEM_COMMIT,
506  if (!NT_SUCCESS(Status))
507  {
508  TRACE("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
509  goto done;
510  }
511 
512  TRACE("MemSize: %lu\n", MemSize);
513  TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
514 
516  ClientBaseAddress,
517  LocalSessionData,
518  TotalLength,
519  NULL);
520  if (!NT_SUCCESS(Status))
521  {
522  TRACE("NtWriteVirtualMemory() failed (Status %lx)\n", Status);
523  goto done;
524  }
525 
526  RequestMsg->GetLogonSessionData.Reply.SessionDataBuffer = ClientBaseAddress;
527 
528 done:
529  if (ProcessHandle != NULL)
531 
532  if (LocalSessionData != NULL)
533  RtlFreeHeap(RtlGetProcessHeap(), 0, LocalSessionData);
534 
535  return Status;
536 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
struct _SECURITY_LOGON_SESSION_DATA SECURITY_LOGON_SESSION_DATA
#define STATUS_NO_SUCH_LOGON_SESSION
Definition: ntstatus.h:317
uint16_t * PWSTR
Definition: typedefs.h:54
static PLSAP_LOGON_SESSION LsapGetLogonSession(IN PLUID LogonId)
Definition: session.c:45
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
UNICODE_STRING UserName
Definition: session.c:19
UNICODE_STRING LogonServer
Definition: session.c:22
_In_ ULONG TotalLength
Definition: usbdlib.h:145
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
#define MEM_COMMIT
Definition: nt_native.h:1313
UNICODE_STRING LogonDomain
Definition: session.c:20
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1440
UNICODE_STRING AuthenticationPackage
Definition: session.c:21
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define TRACE(s)
Definition: solgame.cpp:4
#define PROCESS_VM_WRITE
Definition: pstypes.h:154
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING DnsDomainName
Definition: session.c:23
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
struct _SID * PSID
Definition: eventlog.c:35
Status
Definition: gdiplustypes.h:24
UNICODE_STRING Upn
Definition: session.c:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4367
USHORT MaximumLength
Definition: ntsecapi.h:164
LARGE_INTEGER LogonTime
Definition: session.c:17
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define PROCESS_VM_READ
Definition: pstypes.h:153
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define PROCESS_VM_OPERATION
Definition: pstypes.h:152
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSTATUS NTAPI NtWriteVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN PVOID Buffer, IN SIZE_T NumberOfBytesToWrite, OUT PSIZE_T NumberOfBytesWritten OPTIONAL)
Definition: virtual.c:2805
LSA_UNICODE_STRING UserName
Definition: ntsecapi.h:303
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by AuthPortThreadRoutine().

◆ LsapInitLogonSessions()

VOID LsapInitLogonSessions ( VOID  )

Definition at line 36 of file session.c.

37 {
39  SessionCount = 0;
40 }
LIST_ENTRY SessionListHead
Definition: session.c:30
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG SessionCount
Definition: session.c:31

Referenced by LsapInitLsa().

◆ LsapSetLogonSessionData()

NTSTATUS LsapSetLogonSessionData ( _In_ PLUID  LogonId,
_In_ ULONG  LogonType,
_In_ PUNICODE_STRING  UserName,
_In_ PUNICODE_STRING  LogonDomain,
_In_ PSID  Sid 
)

Definition at line 67 of file session.c.

73 {
74  PLSAP_LOGON_SESSION Session;
75  ULONG Length;
76 
77  TRACE("LsapSetLogonSessionData(%p)\n", LogonId);
78 
79  Session = LsapGetLogonSession(LogonId);
80  if (Session == NULL)
82 
83  TRACE("LogonType %lu\n", LogonType);
84  Session->LogonType = LogonType;
85 
86  TRACE("UserName %wZ\n", UserName);
87  Session->UserName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, UserName->MaximumLength);
88  if (Session->UserName.Buffer == NULL)
90 
91  Session->UserName.Length = UserName->Length;
92  Session->UserName.MaximumLength = UserName->MaximumLength;
93  RtlCopyMemory(Session->UserName.Buffer, UserName->Buffer, UserName->MaximumLength);
94 
95  TRACE("LogonDomain %wZ\n", LogonDomain);
96  Session->LogonDomain.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, LogonDomain->MaximumLength);
97  if (Session->LogonDomain.Buffer == NULL)
99 
100  Session->LogonDomain.Length = LogonDomain->Length;
101  Session->LogonDomain.MaximumLength = LogonDomain->MaximumLength;
102  RtlCopyMemory(Session->LogonDomain.Buffer, LogonDomain->Buffer, LogonDomain->MaximumLength);
103 
105  Session->Sid = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Length);
106  if (Session->UserName.Buffer == NULL)
108 
109  RtlCopyMemory(Session->Sid, Sid, Length);
110 
111  return STATUS_SUCCESS;
112 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_NO_SUCH_LOGON_SESSION
Definition: ntstatus.h:317
static PLSAP_LOGON_SESSION LsapGetLogonSession(IN PLUID LogonId)
Definition: session.c:45
UNICODE_STRING UserName
Definition: session.c:19
UNICODE_STRING LogonDomain
Definition: session.c:20
smooth NULL
Definition: ftsmooth.c:416
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1104
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define TRACE(s)
Definition: solgame.cpp:4
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_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 _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID LogonId
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by LsapLogonUser().

Variable Documentation

◆ SessionCount

◆ SessionListHead