Feat: Windows, and an option to skip firewall rules (#17107)

* feat(windows): make installer firewall rules optional

Support FIREWALLRULES=0/1 in MSI and EXE installers, preserve the saved choice across maintenance and upgrades, and retain unconditional uninstall cleanup.

Persist MSI maintenance overrides with rollback and test EXE option resolution and command generation.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): keep firewall setup failures non-fatal

Restore infallible EXE script generation, warn and use the enabled default when option resolution fails, and continue after persistence errors. Use the existing non-blocking return policy for MSI firewall persistence and rollback actions.

Add regression coverage for invalid input and a failed registry command without changing valid FIREWALLRULES=0/1 behavior.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): support Y/N firewall installer options

Accept Y/y and N/n alongside 1 and 0 for FIREWALLRULES in MSI and EXE installers. Normalize MSI values before action conditions and registry writes to preserve canonical settings across upgrades.

Extend regression coverage for alias normalization and explicit overrides while retaining non-blocking failure handling.

Signed-off-by: fufesou <linlong1266@gmail.com>

* refactor(windows): simplify installer firewall option

Signed-off-by: fufesou <linlong1266@gmail.com>

* refactor(windows): retain legacy firewall installer flow

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(msi): default unknown firewall values to enabled

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): accept case-insensitive firewall option names

Keep the MSI registry search consistent with existing options and document the direct machine-hive alternative.

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou authored and GitHub committed 2026-11-19 18:03:34 +08:00
1 parent 0d1cc89828
commit 742e507ca6
3 files changed
+63 -2

No files matched your search

+26
View File
@@ -3,6 +3,31 @@
<?include ../Includes.wxi?>
<Fragment>
<Property Id="FIREWALLRULES" Secure="yes" />
<Property Id="PREVIOUSFIREWALLRULES" Secure="yes">
<!-- For this per-machine MSI, Root="HKLM" Key="Software\Classes\$(var.RegKeyRoot)" reads the machine-stored value directly.
Keep Root="HKCR" Key="$(var.RegKeyRoot)" for consistency with existing shortcut/printer searches.
https://learn.microsoft.com/en-us/windows/win32/msi/registry-table -->
<RegistrySearch Id="FirewallRulesSearch" Root="HKCR" Key="$(var.RegKeyRoot)" Name="FIREWALLRULES" Type="raw" />
</Property>
<SetProperty Action="SetSavedFirewallRulesValue" Id="FIREWALLRULES" Value="[PREVIOUSFIREWALLRULES]" After="AppSearch" Sequence="first" Condition="NOT FIREWALLRULES AND PREVIOUSFIREWALLRULES" />
<SetProperty Action="NormalizeFirewallRulesEnabled" Id="FIREWALLRULES" Value="1" After="SetSavedFirewallRulesValue" Sequence="first" Condition="NOT (FIREWALLRULES = &quot;0&quot; OR FIREWALLRULES ~= &quot;N&quot;)" />
<SetProperty Action="NormalizeFirewallRulesDisabled" Id="FIREWALLRULES" Value="0" After="NormalizeFirewallRulesEnabled" Sequence="first" Condition="FIREWALLRULES ~= &quot;N&quot;" />
<!-- Maintenance may leave the registry component unchanged; persist the resolved choice explicitly. -->
<CustomAction Id="PersistFirewallRulesEnabled" Directory="System64Folder" ExeCommand='"[System64Folder]reg.exe" add "HKLM\Software\Classes\$(var.RegKeyRoot)" /v FIREWALLRULES /t REG_SZ /d 1 /f' Execute="deferred" Impersonate="no" Return="ignore" />
<CustomAction Id="PersistFirewallRulesDisabled" Directory="System64Folder" ExeCommand='"[System64Folder]reg.exe" add "HKLM\Software\Classes\$(var.RegKeyRoot)" /v FIREWALLRULES /t REG_SZ /d 0 /f' Execute="deferred" Impersonate="no" Return="ignore" />
<CustomAction Id="RollbackFirewallRulesEnabled" Directory="System64Folder" ExeCommand='"[System64Folder]reg.exe" add "HKLM\Software\Classes\$(var.RegKeyRoot)" /v FIREWALLRULES /t REG_SZ /d 1 /f' Execute="rollback" Impersonate="no" Return="ignore" />
<CustomAction Id="RollbackFirewallRulesDisabled" Directory="System64Folder" ExeCommand='"[System64Folder]reg.exe" add "HKLM\Software\Classes\$(var.RegKeyRoot)" /v FIREWALLRULES /t REG_SZ /d 0 /f' Execute="rollback" Impersonate="no" Return="ignore" />
<CustomAction Id="RollbackFirewallRulesAbsent" Directory="System64Folder" ExeCommand='"[System64Folder]reg.exe" delete "HKLM\Software\Classes\$(var.RegKeyRoot)" /v FIREWALLRULES /f' Execute="rollback" Impersonate="no" Return="ignore" />
<InstallExecuteSequence>
<Custom Action="RollbackFirewallRulesAbsent" After="WriteRegistryValues" Condition="Installed AND NOT REMOVE AND NOT PREVIOUSFIREWALLRULES AND (FIREWALLRULES = 0 OR FIREWALLRULES = 1)" />
<Custom Action="RollbackFirewallRulesDisabled" After="RollbackFirewallRulesAbsent" Condition="Installed AND NOT REMOVE AND PREVIOUSFIREWALLRULES = 0 AND (FIREWALLRULES = 0 OR FIREWALLRULES = 1)" />
<Custom Action="RollbackFirewallRulesEnabled" After="RollbackFirewallRulesDisabled" Condition="Installed AND NOT REMOVE AND PREVIOUSFIREWALLRULES = 1 AND (FIREWALLRULES = 0 OR FIREWALLRULES = 1)" />
<Custom Action="PersistFirewallRulesEnabled" After="RollbackFirewallRulesEnabled" Condition="Installed AND NOT REMOVE AND FIREWALLRULES = 1" />
<Custom Action="PersistFirewallRulesDisabled" After="PersistFirewallRulesEnabled" Condition="Installed AND NOT REMOVE AND FIREWALLRULES = 0" />
</InstallExecuteSequence>
<!-- Regs for shortcuts are defined in "Fragments/ShortcutProperties.wxs" -->
<!-- Component that persists the property values to the registry so they are available during an upgrade/modify -->
<Property Id="CURRENT_SHARE_RDP" Secure="yes">
@@ -26,6 +51,7 @@
<Component Id="Product.Registry.InstallFolder" Guid="3196EDA7-9AEF-4705-A0C8-E3F3ECCCB153">
<RegistryKey Root="HKCR" Key="$(var.RegKeyRoot)">
<RegistryValue Type="string" Name="INSTALLFOLDER" Value="[INSTALLFOLDER_INNER]" />
<RegistryValue Type="string" Name="FIREWALLRULES" Value="[FIREWALLRULES]" />
</RegistryKey>
</Component>
+2 -2
View File
@@ -79,8 +79,8 @@
<!--Workaround of "fire:FirewallException". If Outbound="Yes" or Outbound="true", the following error occurs.-->
<!--ExecFirewallExceptions: Error 0x80070057: failed to add app to the authorized apps list-->
<Custom Action="AddFirewallRules" Before="InstallFinalize" Condition="NOT (Installed AND REMOVE AND NOT UPGRADINGPRODUCTCODE)"/>
<Custom Action="AddFirewallRules.SetParam" Before="AddFirewallRules" Condition="NOT (Installed AND REMOVE AND NOT UPGRADINGPRODUCTCODE)"/>
<Custom Action="AddFirewallRules" Before="InstallFinalize" Condition="FIREWALLRULES = 1 AND NOT (Installed AND REMOVE AND NOT UPGRADINGPRODUCTCODE)"/>
<Custom Action="AddFirewallRules.SetParam" Before="AddFirewallRules" Condition="FIREWALLRULES = 1 AND NOT (Installed AND REMOVE AND NOT UPGRADINGPRODUCTCODE)"/>
<Custom Action="AddRegSoftwareSASGeneration" Before="InstallFinalize" Condition="NOT (Installed AND REMOVE AND NOT UPGRADINGPRODUCTCODE) AND (NOT CC_CONNECTION_TYPE=&quot;outgoing&quot;)"/>