3.6 Logon sessions
A logon session is the lightweight kernel bookkeeping a token references — the "login" a token belongs to. Creating and destroying them requires SeTcbPrivilege.
;
int ;
int ;
peios_session_createcreates a logon session of typelogon_type(KACS_LOGON_TYPE_*— interactive, network, service, …) foruser_sid, attributing it toauth_package.id_outis mandatory and receives the new session id, which you then pass topeios_token_builder_session. Errors:EPERM(SeTcbPrivilegemissing),EINVAL(NULLspec,id_out, or field; malformed SID; oversized spec),EFAULT(bad pointer),ENOMEM(allocation failed).peios_session_destroy_emptydestroys a session that has no live tokens — it fails rather than orphaning tokens. Clean up sessions only after every token referencing them is closed. Errors:EPERM(SeTcbPrivilegemissing),ENOENT(no such session),EBUSY(live tokens, linked-pair state, or in-flight references).
3.6.1 Listing sessions #
;
peios_logon_sessions *;
int ;
void ;
The kernel's own list of every live logon session, from /sys/kernel/security/kacs/sessions. Reading it needs BUILTIN\Administrators or SYSTEM.
peios_logon_sessions_opentakes the whole listing at once, so a walk sees one moment.NULLwitherrnoon failure:EACCES(not an administrator),ENOENT(securityfs not mounted),ENOMEM.peios_logon_sessions_nextfillsoutwith the next session and returns1, or0when there are no more. The pointers inoutstay valid until the next call.-1withEPROTOmeans a line it could not read; call again to step past it.peios_logon_sessions_closefrees the reader.
A session is listed while anything holds it, which includes a session nothing has used yet, so a listing can hold sessions with no process in them. SYSTEM's session is 999. To find a session's processes, read each process's token's auth_id (TokenStatistics) and match it.
peios_logon_sessions *s = ;
struct peios_logon_session one;
while
;
;