Skip to content

Commit f5b8e98

Browse files
lheckerDHowett
authored andcommitted
Add a policy for profile sources (#18009)
This adds a basic policy check for DisabledProfileSources, so that organizations can easily disable certain profiles like the Azure one. Closes #17964 * Add a policy to disable Azure under HKCU. Disabled ✅ * Add a policy to disable nothing under HKLM. Enabled ✅ (...because it overrides the HKCU setting.) (cherry picked from commit 3a06826) Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgT6i0Y Service-Version: 1.21
1 parent 90a9d15 commit f5b8e98

7 files changed

Lines changed: 109 additions & 11 deletions

File tree

.github/actions/spelling/expect/04cdb9b77d6827c0202f51acd4205b017015bfff.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/actions/spelling/expect/expect.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ ADDREF
1818
ADDSTRING
1919
ADDTOOL
2020
AFew
21+
adml
22+
admx
2123
AFill
2224
AFX
2325
AHelper
@@ -552,6 +554,7 @@ entrypoints
552554
ENU
553555
ENUMLOGFONT
554556
ENUMLOGFONTEX
557+
EOB
555558
EOK
556559
EPres
557560
EQU
@@ -768,6 +771,7 @@ HIWORD
768771
HKCU
769772
hkey
770773
hkl
774+
HKLM
771775
hlocal
772776
hlsl
773777
HMB
@@ -1711,6 +1715,7 @@ swapchain
17111715
swapchainpanel
17121716
SWMR
17131717
SWP
1718+
swrapped
17141719
SYMED
17151720
SYNCPAINT
17161721
syscalls
@@ -2059,6 +2064,8 @@ WNDCLASSW
20592064
Wndproc
20602065
WNegative
20612066
WNull
2067+
wordi
2068+
wordiswrapped
20622069
workarea
20632070
WOutside
20642071
WOWARM
@@ -2072,6 +2079,7 @@ WPrep
20722079
WPresent
20732080
wprp
20742081
wprpi
2082+
wrappe
20752083
wregex
20762084
writeback
20772085
WRITECONSOLE

policies/WindowsTerminal.admx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- (c) 2024 Microsoft Corporation -->
3+
<policyDefinitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.0" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
4+
<policyNamespaces>
5+
<target prefix="terminal" namespace="Microsoft.Policies.WindowsTerminal" />
6+
<using prefix="windows" namespace="Microsoft.Policies.Windows" />
7+
</policyNamespaces>
8+
<resources minRequiredRevision="1.0" />
9+
<supportedOn>
10+
<definitions>
11+
<definition name="SUPPORTED_WindowsTerminal_1_21" displayName="$(string.SUPPORTED_WindowsTerminal_1_21)" />
12+
</definitions>
13+
</supportedOn>
14+
<categories>
15+
<category name="WindowsTerminal" displayName="$(string.WindowsTerminal)">
16+
<parentCategory ref="windows:WindowsComponents" />
17+
</category>
18+
</categories>
19+
<policies>
20+
<policy name="DisabledProfileSources" class="Both" displayName="$(string.DisabledProfileSources)" explainText="$(string.DisabledProfileSourcesText)" presentation="$(presentation.DisabledProfileSources)" key="Software\Policies\Microsoft\Windows Terminal">
21+
<parentCategory ref="WindowsTerminal" />
22+
<supportedOn ref="SUPPORTED_WindowsTerminal_1_21" />
23+
<elements>
24+
<multiText id="DisabledProfileSources" valueName="DisabledProfileSources" required="true" />
25+
</elements>
26+
</policy>
27+
</policies>
28+
</policyDefinitions>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- (c) 2024 Microsoft Corporation -->
3+
<policyDefinitionResources xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.0" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
4+
<displayName>Windows Terminal</displayName>
5+
<description>Windows Terminal</description>
6+
<resources>
7+
<stringTable>
8+
<string id="WindowsTerminal">Windows Terminal</string>
9+
<string id="SUPPORTED_WindowsTerminal_1_21">At least Windows Terminal 1.21</string>
10+
<string id="DisabledProfileSources">Disabled Profile Sources</string>
11+
<string id="DisabledProfileSourcesText">Profiles will not be generated from any sources listed here. Source names can be arbitrary strings. Potential candidates can be found as the "source" property on profile definitions in Windows Terminal's settings.json file.
12+
13+
Common sources are:
14+
- Windows.Terminal.Azure
15+
- Windows.Terminal.PowershellCore
16+
- Windows.Terminal.Wsl
17+
18+
For instance, setting this policy to Windows.Terminal.Wsl will disable the builtin WSL integration of Windows Terminal.
19+
20+
Note: Existing profiles will disappear from Windows Terminal after adding their source to this policy.</string>
21+
</stringTable>
22+
<presentationTable>
23+
<presentation id="DisabledProfileSources">
24+
<multiTextBox refId="DisabledProfileSources">List of disabled sources (one per line)</multiTextBox>
25+
</presentation>
26+
</presentationTable>
27+
</resources>
28+
</policyDefinitionResources>

src/cascadia/TerminalSettingsModel/CascadiaSettings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
9595
void _addOrMergeUserColorScheme(const winrt::com_ptr<implementation::ColorScheme>& colorScheme);
9696
void _executeGenerator(const IDynamicProfileGenerator& generator);
9797

98-
std::unordered_set<std::wstring_view> _ignoredNamespaces;
98+
std::unordered_set<winrt::hstring, til::transparent_hstring_hash, til::transparent_hstring_equal_to> _ignoredNamespaces;
99+
std::set<std::string> themesChangeLog;
99100
// See _getNonUserOriginProfiles().
100101
size_t _userProfileCount = 0;
101102
};

src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,27 @@ SettingsLoader::SettingsLoader(const std::string_view& userJSON, const std::stri
143143
if (const auto sources = userSettings.globals->DisabledProfileSources())
144144
{
145145
_ignoredNamespaces.reserve(sources.Size());
146-
for (const auto& id : sources)
146+
for (auto&& id : sources)
147147
{
148-
_ignoredNamespaces.emplace(id);
148+
_ignoredNamespaces.emplace(std::move(id));
149+
}
150+
}
151+
152+
// Apply DisabledProfileSources policy setting. Pick whatever policy is set first.
153+
// In most cases HKCU settings take precedence over HKLM settings, but the inverse is true for policies.
154+
for (const auto key : { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER })
155+
{
156+
wchar_t buffer[512]; // "640K ought to be enough for anyone"
157+
DWORD bufferSize = sizeof(buffer);
158+
if (RegGetValueW(key, LR"(Software\Policies\Microsoft\Windows Terminal)", L"DisabledProfileSources", RRF_RT_REG_MULTI_SZ, nullptr, buffer, &bufferSize) == 0)
159+
{
160+
for (auto p = buffer; *p;)
161+
{
162+
const auto len = wcslen(p);
163+
_ignoredNamespaces.emplace(p, gsl::narrow_cast<uint32_t>(len));
164+
p += len + 1;
165+
}
166+
break;
149167
}
150168
}
151169

@@ -254,7 +272,7 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings()
254272
const auto filename = fragmentExtFolder.path().filename();
255273
const auto& source = filename.native();
256274

257-
if (!_ignoredNamespaces.count(std::wstring_view{ source }) && fragmentExtFolder.is_directory())
275+
if (!_ignoredNamespaces.contains(std::wstring_view{ source }) && fragmentExtFolder.is_directory())
258276
{
259277
parseAndLayerFragmentFiles(fragmentExtFolder.path(), winrt::hstring{ source });
260278
}
@@ -289,7 +307,7 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings()
289307
for (const auto& ext : extensions)
290308
{
291309
const auto packageName = ext.Package().Id().FamilyName();
292-
if (_ignoredNamespaces.count(std::wstring_view{ packageName }))
310+
if (_ignoredNamespaces.contains(std::wstring_view{ packageName }))
293311
{
294312
continue;
295313
}
@@ -905,7 +923,7 @@ void SettingsLoader::_addOrMergeUserColorScheme(const winrt::com_ptr<implementat
905923
void SettingsLoader::_executeGenerator(const IDynamicProfileGenerator& generator)
906924
{
907925
const auto generatorNamespace = generator.GetNamespace();
908-
if (_ignoredNamespaces.count(generatorNamespace))
926+
if (_ignoredNamespaces.contains(generatorNamespace))
909927
{
910928
return;
911929
}

src/inc/til/winrt.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,24 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
109109
// Which is just silly
110110

111111
#endif
112+
113+
struct transparent_hstring_hash
114+
{
115+
using is_transparent = void;
116+
117+
size_t operator()(const auto& hstr) const noexcept
118+
{
119+
return std::hash<std::wstring_view>{}(hstr);
120+
}
121+
};
122+
123+
struct transparent_hstring_equal_to
124+
{
125+
using is_transparent = void;
126+
127+
bool operator()(const auto& lhs, const auto& rhs) const noexcept
128+
{
129+
return lhs == rhs;
130+
}
131+
};
112132
}

0 commit comments

Comments
 (0)