Skip to content

Address WSLC policy review follow-ups from #40466#40529

Merged
benhillis merged 2 commits into
masterfrom
user/benhill/policy_followup
May 13, 2026
Merged

Address WSLC policy review follow-ups from #40466#40529
benhillis merged 2 commits into
masterfrom
user/benhill/policy_followup

Conversation

@benhillis
Copy link
Copy Markdown
Member

Follow-up to #40466 addressing OneBlue's review feedback.

Changes

  1. Refactor EnumerateRegistryAllowlist to use a new registry::EnumStringValues helper instead of hand-rolling RegQueryInfoKeyW/RegEnumValueW. The helper returns a std::map<std::wstring, std::wstring> of name→value pairs for REG_SZ/REG_EXPAND_SZ values.

  2. Introduce dedicated error codes for policy-blocked operations:

    • WSLC_E_CONTAINER_DISABLED (0x8004060C) — thrown when WSLC is disabled via group policy.
    • WSLC_E_REGISTRY_BLOCKED_BY_POLICY (0x8004060D) — thrown when a registry is blocked by the allowlist policy.

    Defined in wslc.idl (alongside other WSLC_E_* codes) and mirrored into the public wslcsdk.h SDK header, with entries in g_commonErrors and GetErrorString so the rendered Error code: line uses the symbolic name.

  3. Tighten WSLContainerDisabledCli test to verify stdout is empty and stderr matches the exact localized message + Error code: WSLC_E_CONTAINER_DISABLED line, instead of just substring-matching.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Three items @OneBlue flagged in the merged PR were tagged "follow-up";
this change addresses all of them.

1. Refactor EnumerateRegistryAllowlist to use shared registry helpers
   - Add wsl::windows::common::registry::EnumStringValues(HKEY) returning
     a name->value map for REG_SZ/REG_EXPAND_SZ values (skipping other
     types). Mirrors the suggestion to centralise the EnumValues+ReadString
     pattern used by PluginManager::LoadPlugins.
   - wslpolicies.h's EnumerateRegistryAllowlist now calls EnumStringValues
     instead of hand-rolling RegQueryInfoKeyW + RegEnumValueW. Empty-entry
     filter and fail-open catch are preserved.
   - wslpolicies.h now explicitly includes registry.hpp instead of relying
     on precomp include order.

2. Reclassify the new HRESULTs as WSLC_E_* and surface them in wslcsdk.h
   - Move WSL_E_CONTAINER_DISABLED / WSL_E_REGISTRY_BLOCKED_BY_POLICY out of
     wslservice.idl and redefine them as WSLC_E_CONTAINER_DISABLED (0x8004060C)
     and WSLC_E_REGISTRY_BLOCKED_BY_POLICY (0x8004060D) in wslc.idl alongside
     the rest of the WSLC_E_* block.
   - Mirror the definitions in wslcsdk.h so SDK consumers can reference them
     by name without depending on the generated wslservice_h.h.
   - Update the service factory, wslcsession, wslutil error-code map, and
     PolicyTests to use the new names.

3. Tighten WSLContainerDisabledCli test
   - Validate stdoutText is empty (locks down which HANDLE the disabled
     message goes to).
   - Validate stderrText equals exactly
     MessageWSLContainerDisabled() + "\r\nError code: WSLC_E_CONTAINER_DISABLED\r\n"
     using the localization helper, so the message text and the error-code
     mapping are both locked in.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 21:31
@benhillis benhillis requested a review from a team as a code owner May 13, 2026 21:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis enabled auto-merge (squash) May 13, 2026 23:10
@benhillis benhillis merged commit d89742f into master May 13, 2026
11 checks passed
@benhillis benhillis deleted the user/benhill/policy_followup branch May 13, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants