-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathSessionModel.cpp
More file actions
77 lines (59 loc) · 2.82 KB
/
SessionModel.cpp
File metadata and controls
77 lines (59 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
SessionModel.cpp
Abstract:
This file contains the SessionModel implementation.
--*/
#include <precomp.h>
#include "SessionModel.h"
#include "UserSettings.h"
namespace wsl::windows::wslc::models {
const wchar_t* SessionOptions::GetDefaultSessionName()
{
return IsElevated() ? s_defaultAdminSessionName : s_defaultSessionName;
}
bool SessionOptions::IsDefaultSessionName(const std::wstring& sessionName)
{
// Only returns true for the default session name that matches current elevation.
return wsl::shared::string::IsEqual(sessionName, GetDefaultSessionName());
}
SessionOptions::SessionOptions()
{
m_sessionSettings.DisplayName = GetDefaultSessionName();
m_sessionSettings.StoragePath = GetStoragePath().c_str();
m_sessionSettings.CpuCount = settings::User().Get<settings::Setting::SessionCpuCount>();
m_sessionSettings.MemoryMb = settings::User().Get<settings::Setting::SessionMemoryMb>();
m_sessionSettings.BootTimeoutMs = s_defaultBootTimeoutMs;
m_sessionSettings.MaximumStorageSizeMb = settings::User().Get<settings::Setting::SessionStorageSizeMb>();
m_sessionSettings.NetworkingMode = settings::User().Get<settings::Setting::SessionNetworkingMode>();
if (settings::User().Get<settings::Setting::SessionHostFileShareMode>() == settings::HostFileShareMode::VirtioFs)
{
WI_SetFlag(m_sessionSettings.FeatureFlags, WslcFeatureFlagsVirtioFs);
}
if (settings::User().Get<settings::Setting::SessionDnsTunneling>())
{
WI_SetFlag(m_sessionSettings.FeatureFlags, WslcFeatureFlagsDnsTunneling);
}
}
bool SessionOptions::IsElevated()
{
auto token = wil::open_current_access_token(TOKEN_QUERY);
// IsTokenElevated checks if the integrity level is exactly HIGH.
// We must also check for local system because it is above HIGH.
// However, IsTokenLocalSystem() does not work correctly and fails.
// TODO: Add proper handling for system user callers.
return wsl::windows::common::security::IsTokenElevated(token.get());
}
const std::filesystem::path& SessionOptions::GetStoragePath()
{
static const std::filesystem::path basePath = []() {
return settings::User().Get<settings::Setting::SessionStoragePath>().empty()
? std::filesystem::path{wsl::windows::common::filesystem::GetLocalAppDataPath(nullptr) / SessionOptions::s_defaultStorageSubPath}
: settings::User().Get<settings::Setting::SessionStoragePath>().c_str();
}();
static const std::filesystem::path storagePathNonAdmin = basePath / std::wstring{s_defaultSessionName};
static const std::filesystem::path storagePathAdmin = basePath / std::wstring{s_defaultAdminSessionName};
return IsElevated() ? storagePathAdmin : storagePathNonAdmin;
}
} // namespace wsl::windows::wslc::models