ReactOS 0.4.17-dev-806-gffa4164
srm.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for srm.c:

Go to the source code of this file.

Classes

struct  _SEP_LOGON_SESSION_TERMINATED_NOTIFICATION
 
struct  _SEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT
 

Macros

#define NDEBUG
 
#define POLICY_AUDIT_EVENT_TYPE_COUNT   9
 
#define MAX_LOGON_SESSION_LISTS_IN_ARRAY   16
 

Typedefs

typedef struct _SEP_LOGON_SESSION_TERMINATED_NOTIFICATION SEP_LOGON_SESSION_TERMINATED_NOTIFICATION
 
typedef struct _SEP_LOGON_SESSION_TERMINATED_NOTIFICATIONPSEP_LOGON_SESSION_TERMINATED_NOTIFICATION
 
typedef struct _SEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT SEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT
 
typedef struct _SEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXTPSEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT
 

Functions

VOID NTAPI SepRmCommandServerThread (_In_ PVOID StartContext)
 Manages the SRM server API commands, that is, receiving such API command messages from the user mode side of the security standpoint, the LSASS.
 
static NTSTATUS SepCleanupLUIDDeviceMapDirectory (_In_ PLUID LogonLuid)
 Cleans the DOS device map directory of a logon session.
 
static NTSTATUS SepRmCreateLogonSession (_In_ PLUID LogonLuid)
 Creates a logon session. The security reference monitoring (SRM) module of Executive uses this as an internal kernel data for respective logon sessions management within the kernel, as in form of a SEP_LOGON_SESSION_REFERENCES data structure.
 
 _Function_class_ (WORKER_THREAD_ROUTINE)
 Main SRM worker that deploys notification to every registered filesystem that is interested for logon session termination notify.
 
static VOID SepRmNotifyTerminatedLogonSession (_In_ PSEP_LOGON_SESSION_REFERENCES Session)
 Alerts every registered filesystem of an impeding logon termination that is about to occur soon.
 
NTSTATUS NTAPI SepRegQueryHelper (_In_ PCWSTR KeyName, _In_ PCWSTR ValueName, _In_ ULONG ValueType, _In_ ULONG DataLength, _Out_ PVOID ValueData)
 A private registry helper that returns the desired value data based on the specifics requested by the caller.
 
BOOLEAN NTAPI SeRmInitPhase0 (VOID)
 Manages the phase 0 initialization of the security reference monitoring module of the kernel.
 
BOOLEAN NTAPI SeRmInitPhase1 (VOID)
 Manages the phase 1 initialization of the security reference monitoring module of the kernel.
 
static VOID SepAdtInitializeBounds (VOID)
 Initializes the local security authority audit bounds.
 
static NTSTATUS SepRmSetAuditEvent (_Inout_ PSEP_RM_API_MESSAGE Message)
 Sets an audit event for future security auditing monitoring.
 
NTSTATUS NTAPI SepRmInsertLogonSessionIntoToken (_Inout_ PTOKEN Token)
 Inserts a logon session into an access token specified by the caller.
 
NTSTATUS NTAPI SepRmRemoveLogonSessionFromToken (_Inout_ PTOKEN Token)
 Removes a logon session from an access token.
 
static NTSTATUS SepRmDeleteLogonSession (_In_ PLUID LogonLuid)
 Deletes a logon session from the logon sessions database.
 
NTSTATUS SepRmReferenceLogonSession (_In_ PLUID LogonLuid)
 References a logon session.
 
NTSTATUS SepRmDereferenceLogonSession (_In_ PLUID LogonLuid)
 De-references a logon session. If the session has a reference count of 0 by the time the function has de-referenced the logon, that means the session is no longer used and can be safely deleted from the logon sessions database. Whoever registered for logon termination notification (typically filesystems) gets alerted of this fact.
 
BOOLEAN NTAPI SepRmCommandServerThreadInit (VOID)
 Main SRM server thread initialization function. It deals with security manager and LSASS port connection, thus thereby allowing communication between the kernel side (the SRM) and user mode side (the LSASS) of the security world of the operating system.
 
NTSTATUS NTAPI SeGetLogonIdDeviceMap (_In_ PLUID LogonId, _Out_ PDEVICE_MAP *DeviceMap)
 Retrieves the DOS device map from a logon session.
 
NTSTATUS NTAPI SeMarkLogonSessionForTerminationNotification (_In_ PLUID LogonId)
 Marks a logon session for termination notification, given its logon ID. This triggers a callout (that is registered by a filesystem) when the logon is no longer used by anyone that is, no token is still referencing the speciffied logon session.
 
NTSTATUS NTAPI SeRegisterLogonSessionTerminatedRoutine (_In_ PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine)
 Registers a callback that will be called once a logon session terminates. This is typically registered by a filesystem, of which it receives a notification from the kernel once the logon session of interest is terminated through this callback.
 
NTSTATUS NTAPI SeUnregisterLogonSessionTerminatedRoutine (_In_ PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine)
 Un-registers a callback routine, previously registered by SeRegisterLogonSessionTerminatedRoutine function.
 

Variables

LUID SeSystemAuthenticationId
 
LUID SeAnonymousAuthenticationId
 
HANDLE SeRmCommandPort
 
HANDLE SeLsaInitEvent
 
PVOID SepCommandPortViewBase
 
PVOID SepCommandPortViewRemoteBase
 
ULONG_PTR SepCommandPortViewBaseOffset
 
static HANDLE SepRmCommandMessagePort
 
BOOLEAN SepAdtAuditingEnabled
 
ULONG SepAdtMinListLength = 0x2000
 
ULONG SepAdtMaxListLength = 0x3000
 
UCHAR SeAuditingState [POLICY_AUDIT_EVENT_TYPE_COUNT]
 
KGUARDED_MUTEX SepRmDbLock
 
PSEP_LOGON_SESSION_TERMINATED_NOTIFICATION SepLogonNotifications = NULL
 
static PSEP_LOGON_SESSION_REFERENCES _SepLogonSessions [MAX_LOGON_SESSION_LISTS_IN_ARRAY] = {NULL}
 
PSEP_LOGON_SESSION_REFERENCES *const SepLogonSessions = _SepLogonSessions
 

Macro Definition Documentation

◆ MAX_LOGON_SESSION_LISTS_IN_ARRAY

#define MAX_LOGON_SESSION_LISTS_IN_ARRAY   16

Definition at line 79 of file srm.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file srm.c.

◆ POLICY_AUDIT_EVENT_TYPE_COUNT

#define POLICY_AUDIT_EVENT_TYPE_COUNT   9

Definition at line 65 of file srm.c.

Typedef Documentation

◆ PSEP_LOGON_SESSION_TERMINATED_NOTIFICATION

◆ PSEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT

◆ SEP_LOGON_SESSION_TERMINATED_NOTIFICATION

◆ SEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT

Function Documentation

◆ _Function_class_()

_Function_class_ ( WORKER_THREAD_ROUTINE  )

Main SRM worker that deploys notification to every registered filesystem that is interested for logon session termination notify.

Parameters
[in]ParameterA pointer to the session notify dispatch buffer containing the logon session ID of interest, provided by the method who inquired us to notify every registered filesystem.

Definition at line 95 of file srm.c.

100{
103 PAGED_CODE();
104
106
110 {
111 Notification->CallbackRoutine(&SessionNotify->LogonId);
112 }
113
116}
#define PAGED_CODE()
#define NULL
Definition: types.h:112
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
KGUARDED_MUTEX SepRmDbLock
Definition: srm.c:68
struct _SEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT * PSEP_LOGON_SESSION_TERMINATED_NOTIFY_CONTEXT
PSEP_LOGON_SESSION_TERMINATED_NOTIFICATION SepLogonNotifications
Definition: srm.c:69
#define TAG_LOGON_TERMINATED
Definition: tag.h:170
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:115
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

◆ SeGetLogonIdDeviceMap()

NTSTATUS NTAPI SeGetLogonIdDeviceMap ( _In_ PLUID  LogonId,
_Out_ PDEVICE_MAP DeviceMap 
)

Retrieves the DOS device map from a logon session.

Parameters
[in]LogonIdA valid logon session ID.
[out]DeviceMapThe returned device map buffer from the logon session.
Returns
Returns STATUS_SUCCESS if the device map could be gathered from the logon session. STATUS_INVALID_PARAMETER is returned if one of the parameters aren't initialized (that is, the caller has submitted a NULL pointer variable). STATUS_NO_SUCH_LOGON_SESSION is returned if no such session could be found. A failure NTSTATUS code is returned otherwise.

Definition at line 1462 of file srm.c.

1465{
1467 WCHAR Buffer[63];
1468 PDEVICE_MAP LocalMap;
1469 HANDLE DirectoryHandle, LinkHandle;
1471 PSEP_LOGON_SESSION_REFERENCES CurrentSession;
1472 UNICODE_STRING DirectoryName, LinkName, TargetName;
1473
1474 PAGED_CODE();
1475
1476 if (LogonId == NULL ||
1477 DeviceMap == NULL)
1478 {
1480 }
1481
1482 /* Acquire the database lock */
1484
1485 /* Retrieve the hash bucket and loop over it */
1486 for (CurrentSession = SepLogonSessions[LogonId->LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
1487 CurrentSession != NULL;
1488 CurrentSession = CurrentSession->Next)
1489 {
1490 /* Check if the LUID matches the provided one */
1491 if (RtlEqualLuid(&CurrentSession->LogonId, LogonId))
1492 {
1493 break;
1494 }
1495 }
1496
1497 /* No session found, fail */
1498 if (CurrentSession == NULL)
1499 {
1500 /* Release the database lock */
1502
1504 }
1505
1506 /* The found session has a device map, return it! */
1507 if (CurrentSession->pDeviceMap != NULL)
1508 {
1509 *DeviceMap = CurrentSession->pDeviceMap;
1510
1511 /* Release the database lock */
1513
1514 return STATUS_SUCCESS;
1515 }
1516
1517 /* At that point, we'll setup a new device map for the session */
1518 LocalMap = NULL;
1519
1520 /* Reference the session so that it doesn't go away */
1521 CurrentSession->ReferenceCount += 1;
1522
1523 /* Release the database lock */
1525
1526 /* Create our object directory given the LUID */
1528 sizeof(Buffer) / sizeof(WCHAR),
1529 L"\\Sessions\\0\\DosDevices\\%08x-%08x",
1530 LogonId->HighPart,
1531 LogonId->LowPart);
1532 RtlInitUnicodeString(&DirectoryName, Buffer);
1533
1535 &DirectoryName,
1537 NULL,
1538 NULL);
1542 if (NT_SUCCESS(Status))
1543 {
1544 /* Create the associated device map */
1546 if (NT_SUCCESS(Status))
1547 {
1548 /* Make Global point to \Global?? in the directory */
1549 RtlInitUnicodeString(&LinkName, L"Global");
1550 RtlInitUnicodeString(&TargetName, L"\\Global??");
1551
1553 &LinkName,
1556 NULL);
1557 Status = ZwCreateSymbolicLinkObject(&LinkHandle,
1560 &TargetName);
1561 if (!NT_SUCCESS(Status))
1562 {
1563 ObfDereferenceDeviceMap(LocalMap);
1564 }
1565 else
1566 {
1567 ZwClose(LinkHandle);
1568 }
1569 }
1570
1572 }
1573
1574 /* Acquire the database lock */
1576
1577 /* If we succeed... */
1578 if (NT_SUCCESS(Status))
1579 {
1580 /* The session now has a device map? We raced with someone else */
1581 if (CurrentSession->pDeviceMap != NULL)
1582 {
1583 /* Give up on our new device map */
1584 ObfDereferenceDeviceMap(LocalMap);
1585 }
1586 /* Otherwise use our newly allocated device map */
1587 else
1588 {
1589 CurrentSession->pDeviceMap = LocalMap;
1590 }
1591
1592 /* Return the device map */
1593 *DeviceMap = CurrentSession->pDeviceMap;
1594 }
1595 /* Zero output */
1596 else
1597 {
1598 *DeviceMap = NULL;
1599 }
1600
1601 /* Release the database lock */
1603
1604 /* We're done with the session */
1605 SepRmDereferenceLogonSession(&CurrentSession->LogonId);
1606
1607 return Status;
1608}
static HANDLE DirectoryHandle
Definition: ObType.cpp:48
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_ACRTIMP int __cdecl _snwprintf(wchar_t *, size_t, const wchar_t *,...)
Definition: wcs.c:1498
#define L(x)
Definition: resources.c:13
Status
Definition: gdiplustypes.h:24
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI ZwCreateSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ PUNICODE_STRING Name)
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1270
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1262
_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
PSEP_LOGON_SESSION_REFERENCES *const SepLogonSessions
Definition: srm.c:81
NTSTATUS SepRmDereferenceLogonSession(_In_ PLUID LogonLuid)
De-references a logon session. If the session has a reference count of 0 by the time the function has...
Definition: srm.c:1122
#define MAX_LOGON_SESSION_LISTS_IN_ARRAY
Definition: srm.c:79
#define STATUS_NO_SUCH_LOGON_SESSION
Definition: ntstatus.h:425
NTSTATUS NTAPI ObSetDirectoryDeviceMap(OUT PDEVICE_MAP *DeviceMap, IN HANDLE DirectoryHandle)
Definition: devicemap.c:149
VOID FASTCALL ObfDereferenceDeviceMap(IN PDEVICE_MAP DeviceMap)
Definition: devicemap.c:477
short WCHAR
Definition: pedump.c:58
static PCWSTR TargetName
Definition: ping.c:67
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _SEP_LOGON_SESSION_REFERENCES * Next
Definition: setypes.h:169
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:304

Referenced by ObpReferenceDeviceMap(), and ObpSetCurrentProcessDeviceMap().

◆ SeMarkLogonSessionForTerminationNotification()

NTSTATUS NTAPI SeMarkLogonSessionForTerminationNotification ( _In_ PLUID  LogonId)

Marks a logon session for termination notification, given its logon ID. This triggers a callout (that is registered by a filesystem) when the logon is no longer used by anyone that is, no token is still referencing the speciffied logon session.

Parameters
[in]LogonIdThe ID of the logon session.
Returns
STATUS_SUCCESS if the logon session is marked for termination notification successfully, STATUS_NOT_FOUND if the logon session couldn't be found otherwise.

Definition at line 1625 of file srm.c.

1627{
1628 PSEP_LOGON_SESSION_REFERENCES SessionToMark;
1629 PAGED_CODE();
1630
1631 DPRINT("SeMarkLogonSessionForTerminationNotification(%08lx:%08lx)\n",
1632 LogonId->HighPart, LogonId->LowPart);
1633
1634 /* Acquire the database lock */
1636
1637 /* Retrieve the hash bucket and loop over it */
1638 for (SessionToMark = SepLogonSessions[LogonId->LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
1639 SessionToMark != NULL;
1640 SessionToMark = SessionToMark->Next)
1641 {
1642 /* Does the logon with the given ID exist? */
1643 if (RtlEqualLuid(&SessionToMark->LogonId, LogonId))
1644 {
1645 /* We found it */
1646 break;
1647 }
1648 }
1649
1650 /*
1651 * We've exhausted all the remaining logon sessions and
1652 * couldn't find one with the provided ID.
1653 */
1654 if (SessionToMark == NULL)
1655 {
1656 DPRINT1("SeMarkLogonSessionForTerminationNotification(): Logon session couldn't be found!\n");
1658 return STATUS_NOT_FOUND;
1659 }
1660
1661 /* Mark the logon session for termination notification */
1663 DPRINT("SeMarkLogonSessionForTerminationNotification(): Logon session [%08x-%08x] marked for termination notification with success!\n",
1664 LogonId->HighPart, LogonId->LowPart);
1665
1666 /* Release the database lock */
1668 return STATUS_SUCCESS;
1669}
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define DPRINT
Definition: sndvol32.h:73
#define SEP_LOGON_SESSION_TERMINATION_NOTIFY
Definition: setypes.h:708

Referenced by LogonMarkTermination().

◆ SepAdtInitializeBounds()

static VOID SepAdtInitializeBounds ( VOID  )
static

Initializes the local security authority audit bounds.

Returns
Nothing.

Definition at line 373 of file srm.c.

374{
375 struct
376 {
377 ULONG MaxLength;
378 ULONG MinLength;
379 } ListBounds;
381 PAGED_CODE();
382
383 Status = SepRegQueryHelper(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa",
384 L"Bounds",
386 sizeof(ListBounds),
387 &ListBounds);
388 if (!NT_SUCCESS(Status))
389 {
390 /* No registry values, so keep hardcoded defaults */
391 return;
392 }
393
394 /* Check if the bounds are valid */
395 if ((ListBounds.MaxLength < ListBounds.MinLength) ||
396 (ListBounds.MinLength < 16) ||
397 (ListBounds.MaxLength - ListBounds.MinLength < 16))
398 {
399 DPRINT1("ListBounds invalid: %lu, %lu\n", ListBounds.MinLength, ListBounds.MaxLength);
400 return;
401 }
402
403 /* Set the new bounds globally */
404 SepAdtMinListLength = ListBounds.MinLength;
405 SepAdtMaxListLength = ListBounds.MaxLength;
406}
#define REG_BINARY
Definition: nt_native.h:1499
NTSTATUS NTAPI SepRegQueryHelper(_In_ PCWSTR KeyName, _In_ PCWSTR ValueName, _In_ ULONG ValueType, _In_ ULONG DataLength, _Out_ PVOID ValueData)
A private registry helper that returns the desired value data based on the specifics requested by the...
Definition: srm.c:192
ULONG SepAdtMinListLength
Definition: srm.c:62
ULONG SepAdtMaxListLength
Definition: srm.c:63
uint32_t ULONG
Definition: typedefs.h:59

Referenced by SepRmSetAuditEvent().

◆ SepCleanupLUIDDeviceMapDirectory()

static NTSTATUS SepCleanupLUIDDeviceMapDirectory ( _In_ PLUID  LogonLuid)
static

Cleans the DOS device map directory of a logon session.

Parameters
[in]LogonLuidA logon session ID where its DOS device map directory is to be cleaned.
Returns
Returns STATUS_SUCCESS if the device map directory has been successfully cleaned from the logon session. STATUS_INVALID_PARAMETER is returned if the caller hasn't submitted any logon ID. STATUS_NO_MEMORY is returned if buffer allocation for links has failed. A failure NTSTATUS code is returned otherwise.

Definition at line 864 of file srm.c.

866{
867 BOOLEAN UseCurrentProc;
869 WCHAR Buffer[63];
870 UNICODE_STRING DirectoryName;
873 HANDLE DirectoryHandle, LinkHandle;
874 PHANDLE LinksBuffer;
875 POBJECT_DIRECTORY_INFORMATION DirectoryInfo;
876 ULONG LinksCount, LinksSize, DirInfoLength, ReturnLength, Context, CurrentLinks, i;
878
879 PAGED_CODE();
880
881 /* We need a logon LUID */
882 if (LogonLuid == NULL)
883 {
885 }
886
887 /* Use current process */
888 UseCurrentProc = ObReferenceObjectSafe(PsGetCurrentProcess());
889 if (UseCurrentProc)
890 {
892 }
893 /* Unless it's gone, then use system process */
894 else
895 {
897 }
898
899 /* Initialize our directory name */
901 sizeof(Buffer) / sizeof(WCHAR),
902 L"\\Sessions\\0\\DosDevices\\%08x-%08x",
903 LogonLuid->HighPart,
904 LogonLuid->LowPart);
905 RtlInitUnicodeString(&DirectoryName, Buffer);
906
907 /* And open it */
909 &DirectoryName,
911 NULL,
912 NULL);
916 if (!NT_SUCCESS(Status))
917 {
918 if (!UseCurrentProc)
919 {
921 }
922
923 return Status;
924 }
925
926 /* Some initialization needed for browsing all our links... */
927 Context = 0;
928 DirectoryInfo = NULL;
929 DirInfoLength = 0;
930 /* In our buffer, we'll store at max 100 HANDLE */
931 LinksCount = 100;
932 CurrentLinks = 0;
933 /* Which gives a certain size */
934 LinksSize = LinksCount * sizeof(HANDLE);
935
936 /*
937 * This label is hit if we need to store more than a hundred
938 * of links. In that case, we jump here after having cleaned
939 * and deleted previous buffer.
940 * All handles have been already closed
941 */
942AllocateLinksAgain:
943 LinksBuffer = ExAllocatePoolWithTag(PagedPool,
944 LinksSize,
946 if (LinksBuffer == NULL)
947 {
948 /*
949 * Failure path: no need to clear handles:
950 * already closed and the buffer is already gone
951 */
953
954 /*
955 * On the first round, DirectoryInfo is NULL,
956 * if we grow LinksBuffer, it has been allocated
957 */
958 if (DirectoryInfo != NULL)
959 {
960 ExFreePoolWithTag(DirectoryInfo, TAG_SE_DIR_BUFFER);
961 }
962
963 if (!UseCurrentProc)
964 {
966 }
967
968 return STATUS_NO_MEMORY;
969 }
970
971 /*
972 * We always restart scan, but on the first loop
973 * if we couldn't fit everything in our buffer,
974 * then, we continue scan.
975 * But we restart if link buffer was too small
976 */
977 for (RestartScan = TRUE; ; RestartScan = FALSE)
978 {
979 /*
980 * Loop until our buffer is big enough to store
981 * one entry
982 */
983 while (TRUE)
984 {
985 Status = ZwQueryDirectoryObject(DirectoryHandle,
986 DirectoryInfo,
987 DirInfoLength,
988 TRUE,
990 &Context,
991 &ReturnLength);
992 /* Only handle buffer growth in that loop */
994 {
995 break;
996 }
997
998 /* Get output length as new length */
999 DirInfoLength = ReturnLength;
1000 /* Delete old buffer if any */
1001 if (DirectoryInfo != NULL)
1002 {
1003 ExFreePoolWithTag(DirectoryInfo, 'bDeS');
1004 }
1005
1006 /* And reallocate a bigger one */
1007 DirectoryInfo = ExAllocatePoolWithTag(PagedPool,
1008 DirInfoLength,
1010 /* Fail if we cannot allocate */
1011 if (DirectoryInfo == NULL)
1012 {
1014 break;
1015 }
1016 }
1017
1018 /* If querying the entry failed, quit */
1019 if (!NT_SUCCESS(Status))
1020 {
1021 break;
1022 }
1023
1024 /* We only look for symbolic links, the rest, we ignore */
1025 if (wcscmp(DirectoryInfo->TypeName.Buffer, L"SymbolicLink"))
1026 {
1027 continue;
1028 }
1029
1030 /* If our link buffer is out of space, reallocate */
1031 if (CurrentLinks >= LinksCount)
1032 {
1033 /* First, close the links */
1034 for (i = 0; i < CurrentLinks; ++i)
1035 {
1036 ZwClose(LinksBuffer[i]);
1037 }
1038
1039 /* Allow 20 more HANDLEs */
1040 LinksCount += 20;
1041 CurrentLinks = 0;
1043 LinksSize = LinksCount * sizeof(HANDLE);
1044
1045 /* And reloop again */
1046 goto AllocateLinksAgain;
1047 }
1048
1049 /* Open the found link */
1051 &DirectoryInfo->Name,
1054 NULL);
1055 if (NT_SUCCESS(ZwOpenSymbolicLinkObject(&LinkHandle,
1058 {
1059 /* If we cannot make it temporary, just close the link handle */
1060 if (!NT_SUCCESS(ZwMakeTemporaryObject(LinkHandle)))
1061 {
1062 ZwClose(LinkHandle);
1063 }
1064 /* Otherwise, store it to defer deletion */
1065 else
1066 {
1067 LinksBuffer[CurrentLinks] = LinkHandle;
1068 ++CurrentLinks;
1069 }
1070 }
1071 }
1072
1073 /* No more entries means we handled all links, that's not a failure */
1075 {
1077 }
1078
1079 /* Close all the links we stored, this will like cause their deletion */
1080 for (i = 0; i < CurrentLinks; ++i)
1081 {
1082 ZwClose(LinksBuffer[i]);
1083 }
1084 /* And free our links buffer */
1086
1087 /* Free our directory info buffer - it might be NULL if we failed realloc */
1088 if (DirectoryInfo != NULL)
1089 {
1090 ExFreePoolWithTag(DirectoryInfo, TAG_SE_DIR_BUFFER);
1091 }
1092
1093 /* Close our session directory */
1095
1096 /* And detach from system */
1097 if (!UseCurrentProc)
1098 {
1100 }
1101
1102 return Status;
1103}
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
unsigned char BOOLEAN
Definition: actypes.h:127
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ BOOLEAN _In_ ULONG _In_opt_ PULONG _In_ BOOLEAN RestartScan
Definition: fltkernel.h:2299
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
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwOpenDirectoryObject(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwMakeTemporaryObject(_In_ HANDLE Handle)
#define DIRECTORY_QUERY
Definition: nt_native.h:1257
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1769
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:285
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:22
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:704
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:756
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PVOID Context
Definition: storport.h:2269
KPROCESS Pcb
Definition: pstypes.h:1399
UNICODE_STRING TypeName
Definition: obtypes.h:254
#define TAG_SE_DIR_BUFFER
Definition: tag.h:162
#define TAG_SE_HANDLES_TAB
Definition: tag.h:161
PVOID HANDLE
Definition: typedefs.h:73
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
KAPC_STATE
Definition: ketypes.h:1727
#define ObDereferenceObject
Definition: obfuncs.h:203
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by SepRmDeleteLogonSession(), and SepRmDereferenceLogonSession().

◆ SepRegQueryHelper()

NTSTATUS NTAPI SepRegQueryHelper ( _In_ PCWSTR  KeyName,
_In_ PCWSTR  ValueName,
_In_ ULONG  ValueType,
_In_ ULONG  DataLength,
_Out_ PVOID  ValueData 
)

A private registry helper that returns the desired value data based on the specifics requested by the caller.

Parameters
[in]KeyNameName of the key.
[in]ValueNameName of the registry value.
[in]ValueTypeThe type of the registry value.
[in]DataLengthThe data length, in bytes, representing the size of the registry value.
[out]ValueDataThe requested value data provided by the function.
Returns
Returns STATUS_SUCCESS if the operations have completed successfully, otherwise a failure NTSTATUS code is returned.

Definition at line 192 of file srm.c.

198{
199 UNICODE_STRING ValueNameString;
200 UNICODE_STRING KeyNameString;
204 struct
205 {
207 UCHAR Buffer[64];
208 } KeyValueInformation;
209 NTSTATUS Status, CloseStatus;
210 PAGED_CODE();
211
212 RtlInitUnicodeString(&KeyNameString, KeyName);
214 &KeyNameString,
216 NULL,
217 NULL);
218
220 if (!NT_SUCCESS(Status))
221 {
222 return Status;
223 }
224
225 RtlInitUnicodeString(&ValueNameString, ValueName);
226 Status = ZwQueryValueKey(KeyHandle,
227 &ValueNameString,
229 &KeyValueInformation.Partial,
230 sizeof(KeyValueInformation),
231 &ResultLength);
232 if (!NT_SUCCESS(Status))
233 {
234 goto Cleanup;
235 }
236
237 if ((KeyValueInformation.Partial.Type != ValueType) ||
238 (KeyValueInformation.Partial.DataLength != DataLength))
239 {
241 goto Cleanup;
242 }
243
244 if (ValueType == REG_BINARY)
245 {
246 RtlCopyMemory(ValueData, KeyValueInformation.Partial.Data, DataLength);
247 }
248 else if (ValueType == REG_DWORD)
249 {
250 *(PULONG)ValueData = *(PULONG)KeyValueInformation.Partial.Data;
251 }
252 else
253 {
255 }
256
257Cleanup:
258 CloseStatus = ZwClose(KeyHandle);
259 ASSERT(NT_SUCCESS( CloseStatus ));
260
261 return Status;
262}
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: d3dkmdt.h:46
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG DataLength
Definition: dispmprt.h:233
static const WCHAR Cleanup[]
Definition: register.c:80
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
#define REG_DWORD
Definition: sdbapi.c:615
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

Referenced by SepAdtInitializeBounds(), and SepImpersonateAnonymousToken().

◆ SepRmCommandServerThread()

VOID NTAPI SepRmCommandServerThread ( _In_ PVOID  StartContext)

Manages the SRM server API commands, that is, receiving such API command messages from the user mode side of the security standpoint, the LSASS.

Returns
Nothing.

Definition at line 1341 of file srm.c.

1343{
1346 HANDLE DummyPortHandle;
1348
1349 /* Initialize the server thread */
1351 {
1352 DPRINT1("Security: Terminating Rm Command Server Thread\n");
1353 return;
1354 }
1355
1356 /* No reply yet */
1358
1359 /* Start looping */
1360 while (TRUE)
1361 {
1362 /* Wait for a message */
1364 NULL,
1366 &Message.Header);
1367 if (!NT_SUCCESS(Status))
1368 {
1369 DPRINT1("Failed to get message: 0x%lx\n", Status);
1371 continue;
1372 }
1373
1374 /* Check if this is a connection request */
1375 if (Message.Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
1376 {
1377 /* Reject connection request */
1378 ZwAcceptConnectPort(&DummyPortHandle,
1379 NULL,
1380 &Message.Header,
1381 FALSE,
1382 NULL,
1383 NULL);
1384
1385 /* Start over */
1387 continue;
1388 }
1389
1390 /* Check if the port died */
1391 if ((Message.Header.u2.s2.Type == LPC_PORT_CLOSED) ||
1392 (Message.Header.u2.s2.Type == LPC_CLIENT_DIED))
1393 {
1394 /* LSASS is dead, so let's quit as well */
1395 break;
1396 }
1397
1398 /* Check if this is an actual request */
1399 if (Message.Header.u2.s2.Type != LPC_REQUEST)
1400 {
1401 DPRINT1("SepRmCommandServerThread: unexpected message type: 0x%x\n",
1402 Message.Header.u2.s2.Type);
1403
1404 /* Restart without replying */
1406 continue;
1407 }
1408
1409 ReplyMessage = &Message.Header;
1410
1411 switch (Message.ApiNumber)
1412 {
1413 case RmAuditSetCommand:
1415 break;
1416
1418 Status = SepRmCreateLogonSession(&Message.u.LogonLuid);
1419 break;
1420
1422 Status = SepRmDeleteLogonSession(&Message.u.LogonLuid);
1423 break;
1424
1425 default:
1426 DPRINT1("SepRmDispatchRequest: invalid API number: 0x%lx\n",
1427 Message.ApiNumber);
1429 }
1430
1431 Message.u.ResultStatus = Status;
1432 }
1433
1434 /* Close the port handles */
1437}
HANDLE SeRmCommandPort
Definition: srm.c:18
static const WCHAR Message[]
Definition: register.c:74
NTSYSAPI NTSTATUS NTAPI ZwReplyWaitReceivePort(_In_ HANDLE PortHandle, _Out_opt_ PVOID *PortContext, _In_opt_ PPORT_MESSAGE ReplyMessage, _Out_ PPORT_MESSAGE ReceiveMessage)
NTSYSAPI NTSTATUS NTAPI ZwAcceptConnectPort(_Out_ PHANDLE PortHandle, _In_opt_ PVOID PortContext, _In_ PPORT_MESSAGE ConnectionRequest, _In_ BOOLEAN AcceptConnection, _In_opt_ PPORT_VIEW ServerView, _In_opt_ PREMOTE_PORT_VIEW ClientView)
#define LPC_CLIENT_DIED
Definition: port.c:98
#define LPC_REQUEST
Definition: port.c:93
#define LPC_CONNECTION_REQUEST
Definition: port.c:102
#define LPC_PORT_CLOSED
Definition: port.c:97
#define KernelMode
Definition: asm.h:38
static NTSTATUS SepRmDeleteLogonSession(_In_ PLUID LogonLuid)
Deletes a logon session from the logon sessions database.
Definition: srm.c:697
static HANDLE SepRmCommandMessagePort
Definition: srm.c:59
static NTSTATUS SepRmCreateLogonSession(_In_ PLUID LogonLuid)
Creates a logon session. The security reference monitoring (SRM) module of Executive uses this as an ...
Definition: srm.c:612
BOOLEAN NTAPI SepRmCommandServerThreadInit(VOID)
Main SRM server thread initialization function. It deals with security manager and LSASS port connect...
Definition: srm.c:1190
static NTSTATUS SepRmSetAuditEvent(_Inout_ PSEP_RM_API_MESSAGE Message)
Sets an audit event for future security auditing monitoring.
Definition: srm.c:422
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3406
@ RmDeleteLogonSession
Definition: srmp.h:8
@ RmAuditSetCommand
Definition: srmp.h:6
@ RmCreateLogonSession
Definition: srmp.h:7
BOOL WINAPI ReplyMessage(_In_ LRESULT)

Referenced by SeRmInitPhase1().

◆ SepRmCommandServerThreadInit()

BOOLEAN NTAPI SepRmCommandServerThreadInit ( VOID  )

Main SRM server thread initialization function. It deals with security manager and LSASS port connection, thus thereby allowing communication between the kernel side (the SRM) and user mode side (the LSASS) of the security world of the operating system.

Returns
Returns TRUE if command server connection between SRM and LSASS has succeeded, FALSE otherwise.

Definition at line 1190 of file srm.c.

1191{
1192 SECURITY_QUALITY_OF_SERVICE SecurityQos;
1195 REMOTE_PORT_VIEW RemotePortView;
1196 PORT_VIEW PortView;
1197 LARGE_INTEGER SectionSize;
1198 HANDLE SectionHandle;
1199 HANDLE PortHandle;
1202
1203 SectionHandle = NULL;
1204 PortHandle = NULL;
1205
1206 /* Assume success */
1207 Result = TRUE;
1208
1209 /* Wait until LSASS is ready */
1211 if (!NT_SUCCESS(Status))
1212 {
1213 DPRINT1("Security Rm Init: Waiting for LSA Init Event failed 0x%lx\n", Status);
1214 goto Cleanup;
1215 }
1216
1217 /* We don't need this event anymore */
1219
1220 /* Initialize the connection message */
1221 Message.Header.u1.s1.TotalLength = sizeof(Message);
1222 Message.Header.u1.s1.DataLength = 0;
1223
1224 /* Only LSASS can connect, so handle the connection right now */
1226 if (!NT_SUCCESS(Status))
1227 {
1228 DPRINT1("Security Rm Init: Listen to Command Port failed 0x%lx\n", Status);
1229 goto Cleanup;
1230 }
1231
1232 /* Set the Port View structure length */
1233 RemotePortView.Length = sizeof(RemotePortView);
1234
1235 /* Accept the connection */
1237 NULL,
1238 &Message.Header,
1239 TRUE,
1240 NULL,
1241 &RemotePortView);
1242 if (!NT_SUCCESS(Status))
1243 {
1244 DPRINT1("Security Rm Init: Accept Connect to Command Port failed 0x%lx\n", Status);
1245 goto Cleanup;
1246 }
1247
1248 /* Complete the connection */
1250 if (!NT_SUCCESS(Status))
1251 {
1252 DPRINT1("Security Rm Init: Complete Connect to Command Port failed 0x%lx\n", Status);
1253 goto Cleanup;
1254 }
1255
1256 /* Create a section for messages */
1257 SectionSize.QuadPart = PAGE_SIZE;
1258 Status = ZwCreateSection(&SectionHandle,
1260 NULL,
1261 &SectionSize,
1263 SEC_COMMIT,
1264 NULL);
1265 if (!NT_SUCCESS(Status))
1266 {
1267 DPRINT1("Security Rm Init: Create Memory Section for LSA port failed: 0x%lx\n", Status);
1268 goto Cleanup;
1269 }
1270
1271 /* Setup the PORT_VIEW structure */
1272 PortView.Length = sizeof(PortView);
1273 PortView.SectionHandle = SectionHandle;
1274 PortView.SectionOffset = 0;
1275 PortView.ViewSize = SectionSize.LowPart;
1276 PortView.ViewBase = NULL;
1277 PortView.ViewRemoteBase = NULL;
1278
1279 /* Setup security QOS */
1280 SecurityQos.Length = sizeof(SecurityQos);
1283 SecurityQos.EffectiveOnly = TRUE;
1284
1285 /* Connect to LSASS */
1286 RtlInitUnicodeString(&PortName, L"\\SeLsaCommandPort");
1287 Status = ZwConnectPort(&PortHandle,
1288 &PortName,
1289 &SecurityQos,
1290 &PortView,
1291 NULL,
1292 0,
1293 0,
1294 0);
1295 if (!NT_SUCCESS(Status))
1296 {
1297 DPRINT1("Security Rm Init: Connect to LSA Port failed 0x%lx\n", Status);
1298 goto Cleanup;
1299 }
1300
1301 /* Remember section base and view offset */
1306
1307 DPRINT("SepRmCommandServerThreadInit: done\n");
1308
1309Cleanup:
1310 /* Check for failure */
1311 if (!NT_SUCCESS(Status))
1312 {
1313 if (PortHandle != NULL)
1314 {
1315 ObCloseHandle(PortHandle, KernelMode);
1316 }
1317
1318 Result = FALSE;
1319 }
1320
1321 /* Did we create a section? */
1322 if (SectionHandle != NULL)
1323 {
1324 ObCloseHandle(SectionHandle, KernelMode);
1325 }
1326
1327 return Result;
1328}
static UNICODE_STRING PortName
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SIZE
Definition: env_spec_w32.h:49
NTSYSAPI NTSTATUS NTAPI ZwWaitForSingleObject(_In_ HANDLE Handle, _In_ BOOLEAN Alertable, _In_opt_ PLARGE_INTEGER Timeout)
NTSYSAPI NTSTATUS NTAPI ZwListenPort(_In_ HANDLE PortHandle, _In_ PPORT_MESSAGE ConnectionRequest)
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)
NTSYSAPI NTSTATUS NTAPI ZwCompleteConnectPort(_In_ HANDLE PortHandle)
@ SecurityImpersonation
Definition: lsa.idl:57
#define SEC_COMMIT
Definition: mmtypes.h:100
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1296
HANDLE SeLsaInitEvent
Definition: srm.c:53
PVOID SepCommandPortViewBase
Definition: srm.c:55
PVOID SepCommandPortViewRemoteBase
Definition: srm.c:56
ULONG_PTR SepCommandPortViewBaseOffset
Definition: srm.c:57
LPC_PVOID ViewBase
LPC_HANDLE SectionHandle
LPC_PVOID ViewRemoteBase
ULONG SectionOffset
LPC_SIZE_T ViewSize
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103

Referenced by SepRmCommandServerThread().

◆ SepRmCreateLogonSession()

static NTSTATUS SepRmCreateLogonSession ( _In_ PLUID  LogonLuid)
static

Creates a logon session. The security reference monitoring (SRM) module of Executive uses this as an internal kernel data for respective logon sessions management within the kernel, as in form of a SEP_LOGON_SESSION_REFERENCES data structure.

Parameters
[in]LogonLuidA logon ID represented as a LUID. This LUID is used to create our logon session and add it to the sessions database.
Returns
Returns STATUS_SUCCESS if the logon has been created successfully. STATUS_LOGON_SESSION_EXISTS is returned if a logon session with the pointed logon ID in the call already exists. STATUS_INSUFFICIENT_RESOURCES is returned if logon session allocation has failed because of lack of memory pool resources.

Definition at line 612 of file srm.c.

614{
615 PSEP_LOGON_SESSION_REFERENCES *LogonSession, CurrentSession, NewSession;
617 PAGED_CODE();
618
619 DPRINT("SepRmCreateLogonSession(%08lx:%08lx)\n",
620 LogonLuid->HighPart, LogonLuid->LowPart);
621
622 /* Allocate a new session structure */
623 NewSession = ExAllocatePoolWithTag(PagedPool,
626 if (NewSession == NULL)
627 {
629 }
630
631 /* Initialize it */
632 NewSession->LogonId = *LogonLuid;
633 NewSession->ReferenceCount = 0;
634 NewSession->Flags = 0;
635 NewSession->pDeviceMap = NULL;
636 InitializeListHead(&NewSession->TokenList);
637
638 /* Acquire the database lock */
640
641 /*
642 * Cache the previous session from the hash bucket, the newly created
643 * session will keep hold of the previous session and the hash bucket
644 * gets a new assigned session.
645 */
646 LogonSession = &SepLogonSessions[LogonLuid->LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
647
648 /* Loop all existing sessions */
649 for (CurrentSession = *LogonSession;
650 CurrentSession != NULL;
651 CurrentSession = CurrentSession->Next)
652 {
653 /* Check if the LUID matches the new one */
654 if (RtlEqualLuid(&CurrentSession->LogonId, LogonLuid))
655 {
657 goto Leave;
658 }
659 }
660
661 /* Insert the new session */
662 NewSession->Next = *LogonSession;
663 *LogonSession = NewSession;
664
666
667Leave:
668 /* Release the database lock */
670
671 if (!NT_SUCCESS(Status))
672 {
674 }
675
676 return Status;
677}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_LOGON_SESSION_EXISTS
Definition: ntstatus.h:568
#define TAG_LOGON_SESSION
Definition: tag.h:165

Referenced by SepRmCommandServerThread(), and SeRmInitPhase0().

◆ SepRmDeleteLogonSession()

static NTSTATUS SepRmDeleteLogonSession ( _In_ PLUID  LogonLuid)
static

Deletes a logon session from the logon sessions database.

Parameters
[in]LogonLuidA logon ID represented as a LUID. This LUID is used to point the exact logon session saved within the database.
Returns
STATUS_SUCCESS is returned if the logon session has been deleted successfully. STATUS_NO_SUCH_LOGON_SESSION is returned if the logon session with the submitted LUID doesn't exist. STATUS_BAD_LOGON_SESSION_STATE is returned if the logon session is still in use and we're not allowed to delete it, or if a system or anonymous session is submitted and we're not allowed to delete them as they're internal parts of the system. Otherwise a failure NTSTATUS code is returned.

Definition at line 697 of file srm.c.

699{
700 PSEP_LOGON_SESSION_REFERENCES SessionToDelete, *LogonSession;
702 PAGED_CODE();
703
704 DPRINT("SepRmDeleteLogonSession(%08lx:%08lx)\n",
705 LogonLuid->HighPart, LogonLuid->LowPart);
706
707 /* Acquire the database lock */
709
710 /* Retrieve the hash bucket, the database will have this session pulled away down below */
711 LogonSession = &SepLogonSessions[LogonLuid->LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
712
713 /* Loop over the existing logon sessions */
714 for (SessionToDelete = *LogonSession;
715 SessionToDelete != NULL;
716 SessionToDelete = SessionToDelete->Next)
717 {
718 /*
719 * Does the actual logon session exist in the
720 * saved logon sessions database with the LUID
721 * provided?
722 */
723 if (RtlEqualLuid(&SessionToDelete->LogonId, LogonLuid))
724 {
725 /* Did the caller supply one of these internal sessions? */
726 if (RtlEqualLuid(&SessionToDelete->LogonId, &SeSystemAuthenticationId) ||
728 {
729 /* These logons are critical stuff, we can't delete them */
730 DPRINT1("SepRmDeleteLogonSession(): We're not allowed to delete anonymous/system sessions!\n");
732 goto Leave;
733 }
734 else
735 {
736 /* We found the logon as exactly as we wanted, break the loop */
737 break;
738 }
739 }
740 }
741
742 /*
743 * If we reach this then that means we've exhausted all the logon
744 * sessions and couldn't find one with the desired LUID.
745 */
746 if (SessionToDelete == NULL)
747 {
748 DPRINT1("SepRmDeleteLogonSession(): The logon session with this LUID doesn't exist!\n");
750 goto Leave;
751 }
752
753 /* Is somebody still using this logon session? */
754 if (SessionToDelete->ReferenceCount != 0)
755 {
756 /* The logon session is still in use, we cannot delete it... */
757 DPRINT1("SepRmDeleteLogonSession(): The logon session is still in use!\n");
759 goto Leave;
760 }
761
762 /* If we have a LUID device map, clean it */
763 if (SessionToDelete->pDeviceMap != NULL)
764 {
766 if (!NT_SUCCESS(Status))
767 {
768 /*
769 * We had one job on cleaning the device map directory
770 * of the logon session but we failed, quit...
771 */
772 DPRINT1("SepRmDeleteLogonSession(): Failed to clean the LUID device map directory of the logon (Status: 0x%lx)\n", Status);
773 goto Leave;
774 }
775
776 /* And dereference the device map of the logon */
777 ObfDereferenceDeviceMap(SessionToDelete->pDeviceMap);
778 }
779
780 /* Unlink the session from the bucket list */
781 *LogonSession = SessionToDelete->Next;
782
783 /* If we're here then we've deleted the logon session successfully */
784 DPRINT("SepRmDeleteLogonSession(): Logon session deleted with success!\n");
786 ExFreePoolWithTag(SessionToDelete, TAG_LOGON_SESSION);
787
788Leave:
789 /* Release the database lock */
791 return Status;
792}
LUID SeSystemAuthenticationId
Definition: token.c:20
static NTSTATUS SepCleanupLUIDDeviceMapDirectory(_In_ PLUID LogonLuid)
Cleans the DOS device map directory of a logon session.
Definition: srm.c:864
LUID SeAnonymousAuthenticationId
Definition: token.c:21
#define STATUS_BAD_LOGON_SESSION_STATE
Definition: ntstatus.h:590

Referenced by SepRmCommandServerThread().

◆ SepRmDereferenceLogonSession()

NTSTATUS SepRmDereferenceLogonSession ( _In_ PLUID  LogonLuid)

De-references a logon session. If the session has a reference count of 0 by the time the function has de-referenced the logon, that means the session is no longer used and can be safely deleted from the logon sessions database. Whoever registered for logon termination notification (typically filesystems) gets alerted of this fact.

Parameters
[in]LogonLuidA logon session ID to de-reference.
Returns
Returns STATUS_SUCCESS if the logon session has been de-referenced without issues. STATUS_NO_SUCH_LOGON_SESSION is returned if no such logon exists otherwise.

Definition at line 1122 of file srm.c.

1124{
1125 ULONG RefCount;
1126 PDEVICE_MAP DeviceMap;
1127 PSEP_LOGON_SESSION_REFERENCES CurrentSession;
1128
1129 DPRINT("SepRmDereferenceLogonSession(%08lx:%08lx)\n",
1130 LogonLuid->HighPart, LogonLuid->LowPart);
1131
1132 /* Acquire the database lock */
1134
1135 /* Retrieve the hash bucket and walk over it */
1136 for (CurrentSession = SepLogonSessions[LogonLuid->LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
1137 CurrentSession != NULL;
1138 CurrentSession = CurrentSession->Next)
1139 {
1140 /* Check if the LUID matches the new one */
1141 if (RtlEqualLuid(&CurrentSession->LogonId, LogonLuid))
1142 {
1143 /* Dereference the session */
1144 RefCount = --CurrentSession->ReferenceCount;
1145 DPRINT("ReferenceCount: %lu\n", CurrentSession->ReferenceCount);
1146
1147 /* Release the database lock */
1149
1150 /* We're done with the session */
1151 if (RefCount == 0)
1152 {
1153 /* Get rid of the LUID device map */
1154 DeviceMap = CurrentSession->pDeviceMap;
1155 if (DeviceMap != NULL)
1156 {
1157 CurrentSession->pDeviceMap = NULL;
1159 ObfDereferenceDeviceMap(DeviceMap);
1160 }
1161
1162 /* Alert filesystems that a logon session is about to be deleted */
1163 SepRmNotifyTerminatedLogonSession(CurrentSession);
1164 }
1165
1166 return STATUS_SUCCESS;
1167 }
1168 }
1169
1170 /* Release the database lock */
1172
1174}
static VOID SepRmNotifyTerminatedLogonSession(_In_ PSEP_LOGON_SESSION_REFERENCES Session)
Alerts every registered filesystem of an impeding logon termination that is about to occur soon.
Definition: srm.c:135

Referenced by SeGetLogonIdDeviceMap().

◆ SepRmInsertLogonSessionIntoToken()

NTSTATUS NTAPI SepRmInsertLogonSessionIntoToken ( _Inout_ PTOKEN  Token)

Inserts a logon session into an access token specified by the caller.

Parameters
[in,out]TokenAn access token where the logon session is about to be inserted in.
Returns
STATUS_SUCCESS is returned if the logon session has been inserted into the token successfully. STATUS_NO_SUCH_LOGON_SESSION is returned when no logon session has been found with the matching ID of the token and as such we've failed to add the logon session to the token. STATUS_INSUFFICIENT_RESOURCES is returned if memory pool allocation for the new session has failed.

Definition at line 466 of file srm.c.

468{
470 PAGED_CODE();
471
472 /* Ensure that our token is not some plain garbage */
473 ASSERT(Token);
474
475 /* Acquire the database lock */
477
478 /* Retrieve the hash bucket and loop over it */
479 for (LogonSession = SepLogonSessions[Token->AuthenticationId.LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
480 LogonSession != NULL;
481 LogonSession = LogonSession->Next)
482 {
483 /*
484 * The insertion of a logon session into the token has to be done
485 * only IF the authentication ID of the token matches with the ID
486 * of the logon itself.
487 */
488 if (RtlEqualLuid(&LogonSession->LogonId, &Token->AuthenticationId))
489 {
490 break;
491 }
492 }
493
494 /* If we reach this then we cannot proceed further */
495 if (LogonSession == NULL)
496 {
497 DPRINT1("SepRmInsertLogonSessionIntoToken(): Couldn't insert the logon session into the specific access token!\n");
500 }
501
502 /*
503 * Allocate the session that we are going
504 * to insert it to the token.
505 */
506 Token->LogonSession = ExAllocatePoolWithTag(PagedPool,
509 if (Token->LogonSession == NULL)
510 {
511 DPRINT1("SepRmInsertLogonSessionIntoToken(): Couldn't allocate new logon session into the memory pool!\n");
514 }
515
516 /*
517 * Begin copying the logon session references data from the
518 * session whose ID matches with the token authentication ID to
519 * the new session we've allocated blocks of pool memory for it.
520 */
521 Token->LogonSession->Next = LogonSession->Next;
522 Token->LogonSession->LogonId = LogonSession->LogonId;
523 Token->LogonSession->ReferenceCount = LogonSession->ReferenceCount;
524 Token->LogonSession->Flags = LogonSession->Flags;
525 Token->LogonSession->pDeviceMap = LogonSession->pDeviceMap;
526 InsertHeadList(&LogonSession->TokenList, &Token->LogonSession->TokenList);
527
528 /* Release the database lock and we're done */
530 return STATUS_SUCCESS;
531}
#define InsertHeadList(ListHead, Entry)

Referenced by SepCreateToken(), SepDuplicateToken(), and SepPerformTokenFiltering().

◆ SepRmNotifyTerminatedLogonSession()

static VOID SepRmNotifyTerminatedLogonSession ( _In_ PSEP_LOGON_SESSION_REFERENCES  Session)
static

Alerts every registered filesystem of an impeding logon termination that is about to occur soon.

Parameters
[in]SessionA pointer to the logon session that is about to be terminated, of which the interested filesystems get acknowledged of this fact with a notification.
Remarks
Logon session termination can occur when a thread may die as the process gets cleaned up. So service this operation with a Executive worker thread.

Definition at line 135 of file srm.c.

137{
139
140 /* No filesystem has taken interest for this logon session */
141 if (!(Session->Flags & SEP_LOGON_SESSION_TERMINATION_NOTIFY))
142 {
143 DPRINT("No filesystem cares to be notified for this [%08x-%08x] logon ID, bail out!\n",
144 Session->LogonId.HighPart, Session->LogonId.LowPart);
145 return;
146 }
147
148 SessionNotify = ExAllocatePoolZero(NonPagedPool,
149 sizeof(*SessionNotify),
151 if (SessionNotify == NULL)
152 {
153 DPRINT1("Failed to allocate memory pool to hold the logon session termination notify work item!\n");
154 return;
155 }
156
157 /* Setup the worker thread and deploy it immediately as soon as possible */
158 ExInitializeWorkItem(&SessionNotify->NotifyWorkItem,
159 SepRmNotifyFsCallbacksWorker,
160 SessionNotify);
161
162 SessionNotify->LogonId = Session->LogonId;
164}
#define NonPagedPool
Definition: env_spec_w32.h:307
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:727
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ CriticalWorkQueue
Definition: extypes.h:189

Referenced by SepRmDereferenceLogonSession().

◆ SepRmReferenceLogonSession()

NTSTATUS SepRmReferenceLogonSession ( _In_ PLUID  LogonLuid)

References a logon session.

Parameters
[in]LogonLuidA valid LUID that points to the logon session in the database that we're going to reference it.
Returns
Returns STATUS_SUCCESS if the logon has been referenced. STATUS_NO_SUCH_LOGON_SESSION is returned if the session couldn't be found otherwise.

Definition at line 808 of file srm.c.

810{
811 PSEP_LOGON_SESSION_REFERENCES CurrentSession;
812
813 PAGED_CODE();
814
815 DPRINT("SepRmReferenceLogonSession(%08lx:%08lx)\n",
816 LogonLuid->HighPart, LogonLuid->LowPart);
817
818 /* Acquire the database lock */
820
821 /* Retrieve the hash bucket and loop over it */
822 for (CurrentSession = SepLogonSessions[LogonLuid->LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
823 CurrentSession != NULL;
824 CurrentSession = CurrentSession->Next)
825 {
826 /* Check if the LUID matches the new one */
827 if (RtlEqualLuid(&CurrentSession->LogonId, LogonLuid))
828 {
829 /* Reference the session */
830 ++CurrentSession->ReferenceCount;
831 DPRINT("ReferenceCount: %lu\n", CurrentSession->ReferenceCount);
832
833 /* Release the database lock */
835
836 return STATUS_SUCCESS;
837 }
838 }
839
840 /* Release the database lock */
842
844}

◆ SepRmRemoveLogonSessionFromToken()

NTSTATUS NTAPI SepRmRemoveLogonSessionFromToken ( _Inout_ PTOKEN  Token)

Removes a logon session from an access token.

Parameters
[in,out]TokenAn access token whose logon session is to be removed from it.
Returns
STATUS_SUCCESS is returned if the logon session has been removed from the token successfully. STATUS_NO_SUCH_LOGON_SESSION is returned when no logon session has been found with the matching ID of the token and as such we've failed to remove the logon session from the token.

Definition at line 548 of file srm.c.

550{
552 PAGED_CODE();
553
554 /* Ensure that our token is not some plain garbage */
555 ASSERT(Token);
556
557 /* Acquire the database lock */
559
560 /* Retrieve the hash bucket and loop over it */
561 for (LogonSession = SepLogonSessions[Token->AuthenticationId.LowPart % MAX_LOGON_SESSION_LISTS_IN_ARRAY];
562 LogonSession != NULL;
563 LogonSession = LogonSession->Next)
564 {
565 /*
566 * Remove the logon session only when the IDs of the token and the
567 * logon match.
568 */
569 if (RtlEqualLuid(&LogonSession->LogonId, &Token->AuthenticationId))
570 {
571 break;
572 }
573 }
574
575 /* They don't match */
576 if (LogonSession == NULL)
577 {
578 DPRINT1("SepRmRemoveLogonSessionFromToken(): Couldn't remove the logon session from the access token!\n");
581 }
582
583 /* Now it's time to delete the logon session from the token */
584 RemoveEntryList(&Token->LogonSession->TokenList);
586
587 /* Release the database lock and we're done */
589 return STATUS_SUCCESS;
590}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by NtSetInformationToken(), and SepDeleteToken().

◆ SepRmSetAuditEvent()

static NTSTATUS SepRmSetAuditEvent ( _Inout_ PSEP_RM_API_MESSAGE  Message)
static

Sets an audit event for future security auditing monitoring.

Parameters
[in,out]MessageThe reference monitoring API message. It is used to determine if the right API message number is provided, RmAuditSetCommand in this case.
Returns
Returns STATUS_SUCCESS.

Definition at line 422 of file srm.c.

424{
425 ULONG i;
426 PAGED_CODE();
427
428 /* First re-initialize the bounds from the registry */
430
431 /* Make sure we have the right message and clear */
432 ASSERT(Message->ApiNumber == RmAuditSetCommand);
433 Message->ApiNumber = 0;
434
435 /* Store the enable flag in the global variable */
436 SepAdtAuditingEnabled = Message->u.SetAuditEvent.Enabled;
437
438 /* Loop all audit event types */
439 for (i = 0; i < POLICY_AUDIT_EVENT_TYPE_COUNT; i++)
440 {
441 /* Save the provided flags in the global array */
442 SeAuditingState[i] = (UCHAR)Message->u.SetAuditEvent.Flags[i];
443 }
444
445 return STATUS_SUCCESS;
446}
UCHAR SeAuditingState[POLICY_AUDIT_EVENT_TYPE_COUNT]
Definition: srm.c:66
BOOLEAN SepAdtAuditingEnabled
Definition: srm.c:61
#define POLICY_AUDIT_EVENT_TYPE_COUNT
Definition: srm.c:65
static VOID SepAdtInitializeBounds(VOID)
Initializes the local security authority audit bounds.
Definition: srm.c:373

Referenced by SepRmCommandServerThread().

◆ SeRegisterLogonSessionTerminatedRoutine()

NTSTATUS NTAPI SeRegisterLogonSessionTerminatedRoutine ( _In_ PSE_LOGON_SESSION_TERMINATED_ROUTINE  CallbackRoutine)

Registers a callback that will be called once a logon session terminates. This is typically registered by a filesystem, of which it receives a notification from the kernel once the logon session of interest is terminated through this callback.

Parameters
[in]CallbackRoutineCallback routine address.
Returns
Returns STATUS_SUCCESS if the callback routine was registered successfully. STATUS_INVALID_PARAMETER is returned if the caller did not provide a callback routine. STATUS_INSUFFICIENT_RESOURCES is returned if the callback notification data couldn't be allocated because of lack of memory pool resources.

Definition at line 1690 of file srm.c.

1692{
1694 PAGED_CODE();
1695
1696 /* Fail, if we don not have a callback routine */
1697 if (CallbackRoutine == NULL)
1699
1700 /* Allocate a new notification item */
1704 if (Notification == NULL)
1706
1707 /* Acquire the database lock */
1709
1710 /* Set the callback routine */
1711 Notification->CallbackRoutine = CallbackRoutine;
1712
1713 /* Insert the new notification item into the list */
1716
1717 /* Release the database lock */
1719
1720 return STATUS_SUCCESS;
1721}
_Must_inspect_result_ _In_ PFLT_GET_OPERATION_STATUS_CALLBACK CallbackRoutine
Definition: fltkernel.h:1035
#define TAG_LOGON_NOTIFICATION
Definition: tag.h:166

◆ SeRmInitPhase0()

BOOLEAN NTAPI SeRmInitPhase0 ( VOID  )

Manages the phase 0 initialization of the security reference monitoring module of the kernel.

Returns
Returns TRUE when phase 0 initialization has completed without problems, FALSE otherwise.

Definition at line 275 of file srm.c.

276{
278
279 /* Initialize the database lock */
281
282 /* Create the system logon session */
285 {
286 return FALSE;
287 }
288
289 /* Create the anonymous logon session */
292 {
293 return FALSE;
294 }
295
296 return TRUE;
297}
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3304

Referenced by SepInitializationPhase0().

◆ SeRmInitPhase1()

BOOLEAN NTAPI SeRmInitPhase1 ( VOID  )

Manages the phase 1 initialization of the security reference monitoring module of the kernel.

Returns
Returns TRUE when phase 1 initialization has completed without problems, FALSE otherwise.

Definition at line 310 of file srm.c.

311{
314 HANDLE ThreadHandle;
316
317 /* Create the SeRm command port */
318 RtlInitUnicodeString(&Name, L"\\SeRmCommandPort");
322 sizeof(ULONG),
324 2 * PAGE_SIZE);
325 if (!NT_SUCCESS(Status))
326 {
327 DPRINT1("Security: Rm Command Port creation failed: 0x%lx\n", Status);
328 return FALSE;
329 }
330
331 /* Create SeLsaInitEvent */
332 RtlInitUnicodeString(&Name, L"\\SeLsaInitEvent");
334 Status = ZwCreateEvent(&SeLsaInitEvent,
338 FALSE);
339 if (!NT_VERIFY((NT_SUCCESS(Status))))
340 {
341 DPRINT1("Security: LSA Init Event creation failed: 0x%lx\n", Status);
342 return FALSE;
343 }
344
345 /* Create the SeRm server thread */
346 Status = PsCreateSystemThread(&ThreadHandle,
348 NULL,
349 NULL,
350 NULL,
352 NULL);
353 if (!NT_SUCCESS(Status))
354 {
355 DPRINT1("Security: Rm Command Server Thread creation failed: 0x%lx\n", Status);
356 return FALSE;
357 }
358
359 ObCloseHandle(ThreadHandle, KernelMode);
360
361 return TRUE;
362}
LPWSTR Name
Definition: desk.c:124
NTSYSAPI NTSTATUS NTAPI ZwCreatePort(_Out_ PHANDLE PortHandle, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ ULONG MaxConnectionInfoLength, _In_ ULONG MaxMessageLength, _In_ ULONG MaxPoolUsage)
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1342
#define GENERIC_WRITE
Definition: nt_native.h:90
@ NotificationEvent
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
VOID NTAPI SepRmCommandServerThread(_In_ PVOID StartContext)
Manages the SRM server API commands, that is, receiving such API command messages from the user mode ...
Definition: srm.c:1341
#define PORT_MAXIMUM_MESSAGE_LENGTH
Definition: iotypes.h:2029

Referenced by Phase1InitializationDiscard().

◆ SeUnregisterLogonSessionTerminatedRoutine()

NTSTATUS NTAPI SeUnregisterLogonSessionTerminatedRoutine ( _In_ PSE_LOGON_SESSION_TERMINATED_ROUTINE  CallbackRoutine)

Un-registers a callback routine, previously registered by SeRegisterLogonSessionTerminatedRoutine function.

Parameters
[in]CallbackRoutineCallback routine address to un-register.
Returns
Returns STATUS_SUCCESS if the callback routine was un-registered successfully. STATUS_INVALID_PARAMETER is returned if the caller did not provide a callback routine. STATUS_NOT_FOUND is returned if the callback notification item couldn't be found.

Definition at line 1739 of file srm.c.

1741{
1744 PAGED_CODE();
1745
1746 /* Fail, if we don not have a callback routine */
1747 if (CallbackRoutine == NULL)
1749
1750 /* Acquire the database lock */
1752
1753 /* Loop all registered notification items */
1754 for (Current = SepLogonNotifications;
1755 Current != NULL;
1756 Current = Current->Next)
1757 {
1758 /* Check if the callback routine matches the provided one */
1759 if (Current->CallbackRoutine == CallbackRoutine)
1760 break;
1761
1762 Previous = Current;
1763 }
1764
1765 if (Current == NULL)
1766 {
1768 }
1769 else
1770 {
1771 /* Remove the current notification item from the list */
1772 if (Previous == NULL)
1773 SepLogonNotifications = Current->Next;
1774 else
1775 Previous->Next = Current->Next;
1776
1777 /* Free the current notification item */
1778 ExFreePoolWithTag(Current,
1780
1782 }
1783
1784 /* Release the database lock */
1786
1787 return Status;
1788}
struct _SEP_LOGON_SESSION_TERMINATED_NOTIFICATION * Next
Definition: srm.c:21
PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine
Definition: srm.c:22

Variable Documentation

◆ _SepLogonSessions

Definition at line 80 of file srm.c.

◆ SeAnonymousAuthenticationId

◆ SeAuditingState

Definition at line 66 of file srm.c.

Referenced by SepRmSetAuditEvent().

◆ SeLsaInitEvent

HANDLE SeLsaInitEvent

Definition at line 53 of file srm.c.

Referenced by SepRmCommandServerThreadInit(), and SeRmInitPhase1().

◆ SepAdtAuditingEnabled

BOOLEAN SepAdtAuditingEnabled

Definition at line 61 of file srm.c.

Referenced by SepRmSetAuditEvent().

◆ SepAdtMaxListLength

ULONG SepAdtMaxListLength = 0x3000

Definition at line 63 of file srm.c.

Referenced by SepAdtInitializeBounds().

◆ SepAdtMinListLength

ULONG SepAdtMinListLength = 0x2000

Definition at line 62 of file srm.c.

Referenced by SepAdtInitializeBounds().

◆ SepCommandPortViewBase

PVOID SepCommandPortViewBase

Definition at line 55 of file srm.c.

Referenced by SepRmCommandServerThreadInit().

◆ SepCommandPortViewBaseOffset

ULONG_PTR SepCommandPortViewBaseOffset

Definition at line 57 of file srm.c.

Referenced by SepRmCommandServerThreadInit().

◆ SepCommandPortViewRemoteBase

PVOID SepCommandPortViewRemoteBase

Definition at line 56 of file srm.c.

Referenced by SepRmCommandServerThreadInit().

◆ SepLogonNotifications

◆ SepLogonSessions

◆ SepRmCommandMessagePort

HANDLE SepRmCommandMessagePort
static

Definition at line 59 of file srm.c.

Referenced by SepRmCommandServerThread(), and SepRmCommandServerThreadInit().

◆ SepRmDbLock

◆ SeRmCommandPort

HANDLE SeRmCommandPort

Definition at line 52 of file srm.c.

◆ SeSystemAuthenticationId

LUID SeSystemAuthenticationId
extern

Definition at line 20 of file token.c.

Referenced by SepCreateSystemProcessToken(), SepRmDeleteLogonSession(), and SeRmInitPhase0().