ReactOS  0.4.15-dev-1070-ge1a01de
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 256 of file session.c.

261 {
262 
263  return STATUS_SUCCESS;
264 }
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by LsapInitAuthPackages().

◆ LsapCreateLogonSession()

NTSTATUS NTAPI LsapCreateLogonSession ( IN PLUID  LogonId)

Definition at line 159 of file session.c.

160 {
161  PLSAP_LOGON_SESSION Session;
163 
164  TRACE("LsapCreateLogonSession(%p)\n", LogonId);
165 
166  /* Fail, if a session already exists */
169 
170  /* Allocate a new session entry */
171  Session = RtlAllocateHeap(RtlGetProcessHeap(),
173  sizeof(LSAP_LOGON_SESSION));
174  if (Session == NULL)
176 
177  /* Initialize the session entry */
178  RtlCopyLuid(&Session->LogonId, LogonId);
179 
180  TRACE("LsapCreateLogonSession(<0x%lx,0x%lx>)\n",
181  LogonId->HighPart, LogonId->LowPart);
182 
183  /* Tell ntoskrnl to create a new logon session */
185  if (!NT_SUCCESS(Status))
186  {
187  RtlFreeHeap(RtlGetProcessHeap(), 0, Session);
188  return Status;
189  }
190 
191  /* Insert the new session into the session list */
192  InsertHeadList(&SessionListHead, &Session->Entry);
193  SessionCount++;
194 
195  return STATUS_SUCCESS;
196 }
#define STATUS_LOGON_SESSION_COLLISION
Definition: ntstatus.h:497
#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
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
Status
Definition: gdiplustypes.h:24
LIST_ENTRY SessionListHead
Definition: session.c:30
_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:134
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 285 of file session.c.

289 {
290 
291  return STATUS_SUCCESS;
292 }
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by LsapInitAuthPackages().

◆ LsapDeleteLogonSession()

NTSTATUS NTAPI LsapDeleteLogonSession ( IN PLUID  LogonId)

Definition at line 201 of file session.c.

202 {
203  PLSAP_LOGON_SESSION Session;
205 
206  TRACE("LsapDeleteLogonSession(%p)\n", LogonId);
207 
208  /* Fail, if the session does not exist */
209  Session = LsapGetLogonSession(LogonId);
210  if (Session == NULL)
212 
213  TRACE("LsapDeleteLogonSession(<0x%lx,0x%lx>)\n",
214  LogonId->HighPart, LogonId->LowPart);
215 
216  /* Tell ntoskrnl to delete the logon session */
218  if (!NT_SUCCESS(Status))
219  return Status;
220 
221  /* Remove the session entry from the list */
222  RemoveEntryList(&Session->Entry);
223  SessionCount--;
224 
225  /* Free the session data */
226  if (Session->Sid != NULL)
227  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->Sid);
228 
229  if (Session->UserName.Buffer != NULL)
230  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName.Buffer);
231 
232  if (Session->LogonDomain.Buffer != NULL)
233  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->LogonDomain.Buffer);
234 
235  if (Session->AuthenticationPackage.Buffer != NULL)
236  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->AuthenticationPackage.Buffer);
237 
238  if (Session->LogonServer.Buffer != NULL)
239  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->LogonServer.Buffer);
240 
241  if (Session->DnsDomainName.Buffer != NULL)
242  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->DnsDomainName.Buffer);
243 
244  if (Session->Upn.Buffer != NULL)
245  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->Upn.Buffer);
246 
247  /* Free the session entry */
248  RtlFreeHeap(RtlGetProcessHeap(), 0, Session);
249 
250  return STATUS_SUCCESS;
251 }
#define STATUS_NO_SUCH_LOGON_SESSION
Definition: ntstatus.h:331
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:3014
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 296 of file session.c.

297 {
300  PLIST_ENTRY SessionEntry;
301  PLSAP_LOGON_SESSION CurrentSession;
302  PLUID SessionList;
303  ULONG i, Length;
304  SIZE_T MemSize;
305  PVOID ClientBaseAddress = NULL;
307 
308  TRACE("LsapEnumLogonSessions(%p)\n", RequestMsg);
309 
310  Length = SessionCount * sizeof(LUID);
311  SessionList = RtlAllocateHeap(RtlGetProcessHeap(),
313  Length);
314  if (SessionList == NULL)
316 
317  i = 0;
318  SessionEntry = SessionListHead.Flink;
319  while (SessionEntry != &SessionListHead)
320  {
321  CurrentSession = CONTAINING_RECORD(SessionEntry,
323  Entry);
324 
325  RtlCopyLuid(&SessionList[i],
326  &CurrentSession->LogonId);
327 
328  SessionEntry = SessionEntry->Flink;
329  i++;
330  }
331 
333  NULL,
334  0,
335  NULL,
336  NULL);
337 
341  &RequestMsg->h.ClientId);
342  if (!NT_SUCCESS(Status))
343  {
344  TRACE("NtOpenProcess() failed (Status %lx)\n", Status);
345  goto done;
346  }
347 
348  TRACE("Length: %lu\n", Length);
349 
350  MemSize = Length;
352  &ClientBaseAddress,
353  0,
354  &MemSize,
355  MEM_COMMIT,
357  if (!NT_SUCCESS(Status))
358  {
359  TRACE("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
360  goto done;
361  }
362 
363  TRACE("MemSize: %lu\n", MemSize);
364  TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
365 
367  ClientBaseAddress,
368  SessionList,
369  Length,
370  NULL);
371  if (!NT_SUCCESS(Status))
372  {
373  TRACE("NtWriteVirtualMemory() failed (Status %lx)\n", Status);
374  goto done;
375  }
376 
377  RequestMsg->EnumLogonSessions.Reply.LogonSessionCount = SessionCount;
378  RequestMsg->EnumLogonSessions.Reply.LogonSessionBuffer = ClientBaseAddress;
379 
380 done:
381  if (ProcessHandle != NULL)
383 
384  if (SessionList != NULL)
385  RtlFreeHeap(RtlGetProcessHeap(), 0, SessionList);
386 
387  return Status;
388 }
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
#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:121
#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
Status
Definition: gdiplustypes.h:24
LIST_ENTRY SessionListHead
Definition: session.c:30
Definition: typedefs.h:119
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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:134
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
#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 269 of file session.c.

277 {
278 
279  return STATUS_SUCCESS;
280 }
return STATUS_SUCCESS
Definition: btrfs.c:3014

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:121
LIST_ENTRY SessionListHead
Definition: session.c:30
Definition: typedefs.h:119
_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 392 of file session.c.

393 {
396  PLSAP_LOGON_SESSION Session;
397  PSECURITY_LOGON_SESSION_DATA LocalSessionData;
398  PVOID ClientBaseAddress = NULL;
399  ULONG TotalLength, SidLength = 0;
400  SIZE_T MemSize;
401  PUCHAR Ptr;
403 
404  TRACE("LsapGetLogonSessionData(%p)\n", RequestMsg);
405 
406  TRACE("LogonId: %lx\n", RequestMsg->GetLogonSessionData.Request.LogonId.LowPart);
407  Session = LsapGetLogonSession(&RequestMsg->GetLogonSessionData.Request.LogonId);
408  if (Session == NULL)
410 
411  /* Calculate the required buffer size */
413  Session->UserName.MaximumLength +
414  Session->LogonDomain.MaximumLength +
416  Session->LogonServer.MaximumLength +
417  Session->DnsDomainName.MaximumLength +
418  Session->Upn.MaximumLength;
419  if (Session->Sid != NULL)
420  {
421  SidLength = RtlLengthSid(Session->Sid);
422  TotalLength += SidLength;
423  }
424  TRACE("TotalLength: %lu\n", TotalLength);
425 
426  /* Allocate the buffer */
427  LocalSessionData = RtlAllocateHeap(RtlGetProcessHeap(),
429  TotalLength);
430  if (LocalSessionData == NULL)
432 
433  Ptr = (PUCHAR)((ULONG_PTR)LocalSessionData + sizeof(SECURITY_LOGON_SESSION_DATA));
434  TRACE("LocalSessionData: %p Ptr: %p\n", LocalSessionData, Ptr);
435 
436  LocalSessionData->Size = sizeof(SECURITY_LOGON_SESSION_DATA);
437 
438  /* Copy the LogonId */
439  RtlCopyLuid(&LocalSessionData->LogonId,
440  &RequestMsg->GetLogonSessionData.Request.LogonId);
441 
442  /* Copy the UserName string */
443  LocalSessionData->UserName.Length = Session->UserName.Length;
444  LocalSessionData->UserName.MaximumLength = Session->UserName.MaximumLength;
445  if (Session->UserName.MaximumLength != 0)
446  {
447  RtlCopyMemory(Ptr, Session->UserName.Buffer, Session->UserName.MaximumLength);
448  LocalSessionData->UserName.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
449 
450  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->UserName.MaximumLength);
451  }
452 
453  /* Copy the LogonDomain string */
454  LocalSessionData->LogonDomain.Length = Session->LogonDomain.Length;
455  LocalSessionData->LogonDomain.MaximumLength = Session->LogonDomain.MaximumLength;
456  if (Session->LogonDomain.MaximumLength != 0)
457  {
459  LocalSessionData->LogonDomain.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
460 
461  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->LogonDomain.MaximumLength);
462  }
463 
464  /* Copy the AuthenticationPackage string */
465  LocalSessionData->AuthenticationPackage.Length = Session->AuthenticationPackage.Length;
466  LocalSessionData->AuthenticationPackage.MaximumLength = Session->AuthenticationPackage.MaximumLength;
467  if (Session->AuthenticationPackage.MaximumLength != 0)
468  {
470  LocalSessionData->AuthenticationPackage.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
471 
473  }
474 
475  LocalSessionData->LogonType = Session->LogonType;
476  LocalSessionData->Session = 0;
477 
478  /* Sid */
479  if (Session->Sid != NULL)
480  {
481  RtlCopyMemory(Ptr, Session->Sid, SidLength);
482  LocalSessionData->Sid = (PSID)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
483 
484  Ptr = (PUCHAR)((ULONG_PTR)Ptr + SidLength);
485  }
486 
487  /* LogonTime */
488  LocalSessionData->LogonTime.QuadPart = Session->LogonTime.QuadPart;
489 
490  /* Copy the LogonServer string */
491  LocalSessionData->LogonServer.Length = Session->LogonServer.Length;
492  LocalSessionData->LogonServer.MaximumLength = Session->LogonServer.MaximumLength;
493  if (Session->LogonServer.MaximumLength != 0)
494  {
496  LocalSessionData->LogonServer.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
497 
498  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->LogonServer.MaximumLength);
499  }
500 
501  /* Copy the DnsDomainName string */
502  LocalSessionData->DnsDomainName.Length = Session->DnsDomainName.Length;
503  LocalSessionData->DnsDomainName.MaximumLength = Session->DnsDomainName.MaximumLength;
504  if (Session->DnsDomainName.MaximumLength != 0)
505  {
507  LocalSessionData->DnsDomainName.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
508 
510  }
511 
512  /* Copy the Upn string */
513  LocalSessionData->Upn.Length = Session->Upn.Length;
514  LocalSessionData->Upn.MaximumLength = Session->Upn.MaximumLength;
515  if (Session->Upn.MaximumLength != 0)
516  {
517  RtlCopyMemory(Ptr, Session->Upn.Buffer, Session->Upn.MaximumLength);
518  LocalSessionData->Upn.Buffer = (PWSTR)((ULONG_PTR)Ptr - (ULONG_PTR)LocalSessionData);
519 
520  Ptr = (PUCHAR)((ULONG_PTR)Ptr + Session->Upn.MaximumLength);
521  }
522 
524  NULL,
525  0,
526  NULL,
527  NULL);
528 
532  &RequestMsg->h.ClientId);
533  if (!NT_SUCCESS(Status))
534  {
535  TRACE("NtOpenProcess() failed (Status %lx)\n", Status);
536  goto done;
537  }
538 
539  MemSize = TotalLength;
541  &ClientBaseAddress,
542  0,
543  &MemSize,
544  MEM_COMMIT,
546  if (!NT_SUCCESS(Status))
547  {
548  TRACE("NtAllocateVirtualMemory() failed (Status %lx)\n", Status);
549  goto done;
550  }
551 
552  TRACE("MemSize: %lu\n", MemSize);
553  TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
554 
556  ClientBaseAddress,
557  LocalSessionData,
558  TotalLength,
559  NULL);
560  if (!NT_SUCCESS(Status))
561  {
562  TRACE("NtWriteVirtualMemory() failed (Status %lx)\n", Status);
563  goto done;
564  }
565 
566  RequestMsg->GetLogonSessionData.Reply.SessionDataBuffer = ClientBaseAddress;
567 
568 done:
569  if (ProcessHandle != NULL)
571 
572  if (LocalSessionData != NULL)
573  RtlFreeHeap(RtlGetProcessHeap(), 0, LocalSessionData);
574 
575  return Status;
576 }
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:331
uint16_t * PWSTR
Definition: typedefs.h:56
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:158
#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:65
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:80
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:134
NTSYSAPI void WINAPI RtlCopyLuid(PLUID, const LUID *)
#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:306
LONGLONG QuadPart
Definition: typedefs.h:114
#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 {
75  PLSAP_LOGON_SESSION Session;
76  ULONG Length;
77 
78  TRACE("LsapSetLogonSessionData(%p)\n", LogonId);
79 
80  Session = LsapGetLogonSession(LogonId);
81  if (Session == NULL)
83 
84  TRACE("LogonType %lu\n", LogonType);
85  Session->LogonType = LogonType;
86 
87  Status = RtlValidateUnicodeString(0, UserName);
88  if (!NT_SUCCESS(Status))
90 
91  /* UserName is mandatory and cannot be an empty string */
92  TRACE("UserName %wZ\n", UserName);
93  Session->UserName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
95  UserName->MaximumLength);
96  if (Session->UserName.Buffer == NULL)
98 
99  Session->UserName.Length = UserName->Length;
100  Session->UserName.MaximumLength = UserName->MaximumLength;
101  RtlCopyMemory(Session->UserName.Buffer, UserName->Buffer, UserName->MaximumLength);
102 
103  Status = RtlValidateUnicodeString(0, LogonDomain);
104  if (!NT_SUCCESS(Status))
105  {
106  /* Cleanup and fail */
107  if (Session->UserName.Buffer != NULL)
108  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName.Buffer);
109 
111  }
112 
113  /* LogonDomain is optional and can be an empty string */
114  TRACE("LogonDomain %wZ\n", LogonDomain);
115  if (LogonDomain->Length)
116  {
117  Session->LogonDomain.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
119  LogonDomain->MaximumLength);
120  if (Session->LogonDomain.Buffer == NULL)
121  {
122  /* Cleanup and fail */
123  if (Session->UserName.Buffer != NULL)
124  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName.Buffer);
125 
127  }
128 
129  Session->LogonDomain.Length = LogonDomain->Length;
130  Session->LogonDomain.MaximumLength = LogonDomain->MaximumLength;
131  RtlCopyMemory(Session->LogonDomain.Buffer, LogonDomain->Buffer, LogonDomain->MaximumLength);
132  }
133  else
134  {
135  RtlInitEmptyUnicodeString(&Session->LogonDomain, NULL, 0);
136  }
137 
139  Session->Sid = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Length);
140  if (Session->Sid == NULL)
141  {
142  /* Cleanup and fail */
143  if (Session->LogonDomain.Buffer != NULL)
144  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->LogonDomain.Buffer);
145  if (Session->UserName.Buffer != NULL)
146  RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName.Buffer);
147 
149  }
150 
151  RtlCopyMemory(Session->Sid, Sid, Length);
152 
153  return STATUS_SUCCESS;
154 }
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:331
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
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 LogonDomain
Definition: session.c:20
NTSYSAPI NTSTATUS NTAPI RtlValidateUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING String)
Definition: unicode.c:2544
smooth NULL
Definition: ftsmooth.c:416
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1103
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
_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:134
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by LsapLogonUser().

Variable Documentation

◆ SessionCount

◆ SessionListHead