Skip to content

Commit 3ace578

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 ## Validation Steps Performed * 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_lADOAF3p4s4AmhmQzgT6i0c Service-Version: 1.22
1 parent 8fa98f6 commit 3ace578

File tree

7 files changed

+108
-11
lines changed

7 files changed

+108
-11
lines changed

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

-5
This file was deleted.

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

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ADDALIAS
1616
ADDREF
1717
ADDSTRING
1818
ADDTOOL
19+
adml
20+
admx
1921
AFill
2022
AFX
2123
AHelper
@@ -564,6 +566,7 @@ entrypoints
564566
ENU
565567
ENUMLOGFONT
566568
ENUMLOGFONTEX
569+
EOB
567570
EOK
568571
EPres
569572
EQU
@@ -782,6 +785,7 @@ HIWORD
782785
HKCU
783786
hkey
784787
hkl
788+
HKLM
785789
hlocal
786790
hlsl
787791
HMB
@@ -1734,6 +1738,7 @@ swapchain
17341738
swapchainpanel
17351739
SWMR
17361740
SWP
1741+
swrapped
17371742
SYMED
17381743
SYNCPAINT
17391744
syscalls
@@ -2076,6 +2081,8 @@ WNDCLASSW
20762081
Wndproc
20772082
WNegative
20782083
WNull
2084+
wordi
2085+
wordiswrapped
20792086
workarea
20802087
WOutside
20812088
WOWARM
@@ -2089,6 +2096,7 @@ WPrep
20892096
WPresent
20902097
wprp
20912098
wprpi
2099+
wrappe
20922100
wregex
20932101
writeback
20942102
WRITECONSOLE

policies/WindowsTerminal.admx

+28
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>

policies/en-US/WindowsTerminal.adml

+28
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
9696
void _addOrMergeUserColorScheme(const winrt::com_ptr<implementation::ColorScheme>& colorScheme);
9797
void _executeGenerator(const IDynamicProfileGenerator& generator);
9898

99-
std::unordered_set<std::wstring_view> _ignoredNamespaces;
99+
std::unordered_set<winrt::hstring, til::transparent_hstring_hash, til::transparent_hstring_equal_to> _ignoredNamespaces;
100100
std::set<std::string> themesChangeLog;
101101
// See _getNonUserOriginProfiles().
102102
size_t _userProfileCount = 0;

src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp

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

@@ -260,7 +278,7 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings()
260278
const auto filename = fragmentExtFolder.path().filename();
261279
const auto& source = filename.native();
262280

263-
if (!_ignoredNamespaces.count(std::wstring_view{ source }) && fragmentExtFolder.is_directory())
281+
if (!_ignoredNamespaces.contains(std::wstring_view{ source }) && fragmentExtFolder.is_directory())
264282
{
265283
parseAndLayerFragmentFiles(fragmentExtFolder.path(), winrt::hstring{ source });
266284
}
@@ -295,7 +313,7 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings()
295313
for (const auto& ext : extensions)
296314
{
297315
const auto packageName = ext.Package().Id().FamilyName();
298-
if (_ignoredNamespaces.count(std::wstring_view{ packageName }))
316+
if (_ignoredNamespaces.contains(std::wstring_view{ packageName }))
299317
{
300318
continue;
301319
}
@@ -914,7 +932,7 @@ void SettingsLoader::_addOrMergeUserColorScheme(const winrt::com_ptr<implementat
914932
void SettingsLoader::_executeGenerator(const IDynamicProfileGenerator& generator)
915933
{
916934
const auto generatorNamespace = generator.GetNamespace();
917-
if (_ignoredNamespaces.count(generatorNamespace))
935+
if (_ignoredNamespaces.contains(generatorNamespace))
918936
{
919937
return;
920938
}

src/inc/til/winrt.h

+20
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)