Skip to content

Commit 506cee3

Browse files
committed
[NTOS:SE] Implement logon session termination notification
Note to SELF and EVERYONE: the commit implements the initial logon session termination notification implementation, the SeMarkLogonSessionForTerminationNotification function, but as it currently stands there are several other tasks to be addressed in the future in order for the logon termination notification to be fully completed. The tasks as of which are. 1. Our SepRmDereferenceLogonSession is not fully implemented, as it doesn't inform the LSA and filesystems of logon deletion notification 2. Implement two worker routines that are actually in charge of such tasks of informing LSA and FSDs 3. Perform logon deletion 4. Do further investigations and check whatever that is left to address, if any
1 parent 34d5d1d commit 506cee3

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

ntoskrnl/se/srm.c

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ SepRmDereferenceLogonSession(
814814
SepCleanupLUIDDeviceMapDirectory(LogonLuid);
815815
ObfDereferenceDeviceMap(DeviceMap);
816816
}
817+
818+
/* FIXME: Alert LSA and filesystems that a logon is about to be deleted */
817819
}
818820

819821
return STATUS_SUCCESS;
@@ -1226,16 +1228,64 @@ SeGetLogonIdDeviceMap(
12261228
return Status;
12271229
}
12281230

1229-
/*
1230-
* @unimplemented
1231+
/**
1232+
* @brief
1233+
* Marks a logon session for future termination, given its logon ID. This triggers
1234+
* a callout (the registered callback) when the logon is no longer used by anyone,
1235+
* that is, no token is still referencing the speciffied logon session.
1236+
*
1237+
* @param[in] LogonId
1238+
* The ID of the logon session.
1239+
*
1240+
* @return
1241+
* STATUS_SUCCESS if the logon session is marked for termination notification successfully,
1242+
* STATUS_NOT_FOUND if the logon session couldn't be found otherwise.
12311243
*/
12321244
NTSTATUS
12331245
NTAPI
12341246
SeMarkLogonSessionForTerminationNotification(
1235-
IN PLUID LogonId)
1247+
_In_ PLUID LogonId)
12361248
{
1237-
UNIMPLEMENTED;
1238-
return STATUS_NOT_IMPLEMENTED;
1249+
PSEP_LOGON_SESSION_REFERENCES SessionToMark;
1250+
PAGED_CODE();
1251+
1252+
DPRINT("SeMarkLogonSessionForTerminationNotification(%08lx:%08lx)\n",
1253+
LogonId->HighPart, LogonId->LowPart);
1254+
1255+
/* Acquire the database lock */
1256+
KeAcquireGuardedMutex(&SepRmDbLock);
1257+
1258+
/* Loop over the existing logon sessions */
1259+
for (SessionToMark = SepLogonSessions;
1260+
SessionToMark != NULL;
1261+
SessionToMark = SessionToMark->Next)
1262+
{
1263+
/* Does the logon with the given ID exist? */
1264+
if (RtlEqualLuid(&SessionToMark->LogonId, LogonId))
1265+
{
1266+
/* We found it */
1267+
break;
1268+
}
1269+
}
1270+
1271+
/*
1272+
* We've exhausted all the remaining logon sessions and
1273+
* couldn't find one with the provided ID.
1274+
*/
1275+
if (SessionToMark == NULL)
1276+
{
1277+
DPRINT1("SeMarkLogonSessionForTerminationNotification(): Logon session couldn't be found!\n");
1278+
KeReleaseGuardedMutex(&SepRmDbLock);
1279+
return STATUS_NOT_FOUND;
1280+
}
1281+
1282+
/* Mark the logon session for termination */
1283+
SessionToMark->Flags |= SEP_LOGON_SESSION_TERMINATION_NOTIFY;
1284+
DPRINT("SeMarkLogonSessionForTerminationNotification(): Logon session marked for termination with success!\n");
1285+
1286+
/* Release the database lock */
1287+
KeReleaseGuardedMutex(&SepRmDbLock);
1288+
return STATUS_SUCCESS;
12391289
}
12401290

12411291

sdk/include/xdk/setypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ typedef struct _SID_AND_ATTRIBUTES_HASH {
675675
#define NETWORKSERVICE_LUID {0x3e4, 0x0}
676676
#define IUSER_LUID {0x3e3, 0x0}
677677

678+
/* Logon session reference flags */
679+
680+
#define SEP_LOGON_SESSION_TERMINATION_NOTIFY 0x0001
681+
678682
typedef struct _ACE_HEADER {
679683
$UCHAR AceType;
680684
$UCHAR AceFlags;

0 commit comments

Comments
 (0)