| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | Security.cpp |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains user security function definitions. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #include "precomp.h" |
| 16 | #include "LxssSecurity.h" |
| 17 | |
| 18 | using namespace Microsoft::WRL; |
| 19 | |
| 20 | void Security::InitializeInstanceJob(_In_ HANDLE jobHandle) |
| 21 | { |
| 22 | // Set the job limit flags. |
| 23 | // |
| 24 | // N.B. The kill on close flag is required to convert the job to a silo. |
| 25 | JOBOBJECT_EXTENDED_LIMIT_INFORMATION limitInfo = {}; |
| 26 | limitInfo.BasicLimitInformation.LimitFlags = (JOB_OBJECT_LIMIT_BREAKAWAY_OK | JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE); |
| 27 | THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject(jobHandle, JobObjectExtendedLimitInformation, &limitInfo, sizeof(limitInfo))); |
| 28 | |
| 29 | // Turn on timer-virtualization for this job. |
| 30 | BOOLEAN enableTimerVirtualization = TRUE; |
| 31 | THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject( |
| 32 | jobHandle, JobObjectTimerVirtualizationInformation, &enableTimerVirtualization, sizeof(enableTimerVirtualization))); |
| 33 | |
| 34 | // Convert the job to a silo. This allows processes from multiple sessions |
| 35 | // in the same job object. |
| 36 | THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject(jobHandle, JobObjectCreateSilo, nullptr, 0)); |
| 37 | } |
| 38 | |
| 39 | bool Security::IsTokenLocalAdministrator(_In_ HANDLE token) |
| 40 | { |
| 41 | auto [sid, buffer] = |
| 42 | wsl::windows::common::security::CreateSid(SECURITY_NT_AUTHORITY, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS); |
| 43 | |
| 44 | BOOL member{}; |
| 45 | THROW_IF_WIN32_BOOL_FALSE(::CheckTokenMembership(token, sid, &member)); |
| 46 | |
| 47 | return member; |
| 48 | } |